var N=Object.defineProperty;var B=(t,a,e)=>a in t?N(t,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[a]=e;var d=(t,a,e)=>(B(t,typeof a!="symbol"?a+"":a,e),e);import{eB as w,bX as S,e as R,dJ as x,aJ as H,C as T,av as A,dV as I,j as Q,u as k,x as X,aT as U,p as $,c2 as j,n as V,q as G,o as q,dY as z,dZ as W,eC as Y,dU as K,dW as J}from"./index-03b6134d.js";import"./index-0a53aaef.js";import"./postmen-9e6354af.js";function Z(t){return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}const E="galacean-local-ide-config";function ee(t,a){const e=t.trim().replace(/^["'`]+|["'`]+$/g,"").replace(/\\/g,"/").replace(/\/{2,}/g,"/").replace(/\/+$/,"");if(!e)return p("empty",e);if(/[\r\n\t]/.test(e))return p("embedded-newline",e);if(/(^|\/)[a-z][a-z0-9+.-]*:\/\//i.test(e))return p("embedded-url",e);if(e.startsWith("~"))return p("tilde",e);if(!e.startsWith("/")&&!/^[A-Za-z]:\//.test(e))return p("not-absolute",e);if(/[<>"|?*]/.test(e))return p("illegal-chars",e);const r=e.split("/").filter(Boolean);return r.includes("..")||r.includes(".")?p("parent-segment",e):a?r[r.length-1]!==a?{kind:"error",reason:"tail-mismatch",normalized:e,expectedTail:a}:{kind:"ok",normalized:e}:p("no-binding",e)}function p(t,a){return{kind:"error",reason:t,normalized:a}}function ae(t){try{const a=localStorage.getItem(E);if(!a)return null;const e=JSON.parse(a);if(!e||typeof e.workspacePath!="string"||typeof e.ide!="string")return null;if(!e.workspacePath.trim())return localStorage.removeItem(E),null;const r=ee(e.workspacePath,t??null);return r.kind==="error"&&r.reason!=="no-binding"?(localStorage.removeItem(E),null):e}catch{return null}}function te(t){const a=t.replace(/\\/g,"/");return/^[A-Za-z]:\//.test(a)?`/${a}`:a}function re(t,a){switch(t){case"vscode":return`vscode://file${a}`;case"cursor":return`cursor://file${a}`;case"webstorm":return`webstorm://open?file=${encodeURIComponent(a)}`}}function v(t,a,e="",r=""){const s=[a.replace(/[\\/]+$/,""),e,r].filter(Boolean).join("/");return re(t,te(s))}function D(t){const a=document.createElement("a");a.href=t,a.style.display="none",document.body.appendChild(a),a.click(),a.remove()}function se(t,a,e){const{ide:r,workspacePath:s}=t,n=v(r,s,a,e);if(r==="webstorm"){D(n);return}D(v(r,s,a)),setTimeout(()=>D(n),800)}async function ne(t,a,e){const r=a.projectStore.localWorkspaceSync,s=ae(r==null?void 0:r.directoryName);if(!s||!(r!=null&&r.directoryHandle)){e();return}const n=a.projectStore.id,o=w(t);if(!await r.hasSyncedFile(o)){const h=(u,M)=>R(`asset.local-workspace-sync.${u}`,M),m=S.loading(h("syncing"));try{if(!await r.syncEditorAssetsToLocal()||!await r.hasSyncedFile(o)){S.error(r.errorMessage||h("failed"),{id:m}),e();return}S.success(h("success",[r.directoryName||h("local-workspace")]),{id:m})}catch(u){S.error(u instanceof Error?u.message:h("failed"),{id:m}),e();return}}se(s,n,o)}const oe=t=>{const{type:a="esm",varName:e,namedExports:r=null,defaultExport:s=!0}=typeof t=="string"?{varName:t}:t;return{type:a,varName:e,namedExports:r,defaultExport:s}},ie=t=>`module.exports = ${t};`,le=(t,a,e)=>{const r=e?[`export default ${t};`]:[];if(a&&a.length){const s=[...new Set(a)].join(", ");r.push(`const { ${s} } = ${t};`),r.push(`export { ${s} };`)}return r.join(`
`)},de=t=>{const{type:a,varName:e,namedExports:r,defaultExport:s}=t;switch(a){case"esm":return le(e,r,s);case"cjs":return ie(e)}},f="global-externals",ce=t=>{const{modulePathFilter:a,getModuleInfo:e}=t;return{name:f,setup(r){r.onResolve({filter:a},s=>({path:s.path,namespace:f})),r.onLoad({filter:/.*/,namespace:f},s=>{const n=s.path,o=oe(e(n));return{contents:de(o)}})}}},he=t=>{const a={modulePathFilter:new RegExp(`^(?:${Object.keys(t).join("|")})$`),getModuleInfo:e=>t[e]};return ce(a)},ue=async t=>x(()=>import(t),[]);async function pe(t,a=ue){const e=URL.createObjectURL(new Blob([t],{type:"application/javascript"}));try{return await a(e)}finally{URL.revokeObjectURL(e)}}var c=(t=>(t.Default="default",t.ShaderUI="shader_ui",t.StateMachine="state_machine",t))(c||{});const C=`
    this.onPropertyChanged("isTransparent", (material, isTransparent) => {
      const shaderData = material.shaderData;
      const alphaCutoff = shaderData.getFloat("material_AlphaCutoff");
      if (isTransparent) {
        shaderData.setInt("depthWriteEnabled", 0);
        shaderData.setInt("blendEnabled", 1);
        shaderData.setInt("renderQueueType", RenderQueueType.Transparent);
        shaderData.enableMacro("MATERIAL_IS_TRANSPARENT");
      } else {
        shaderData.setInt("depthWriteEnabled", 1);
        shaderData.setInt("blendEnabled", 0);
        shaderData.setInt("renderQueueType", alphaCutoff ? RenderQueueType.AlphaTest : RenderQueueType.Opaque);
        shaderData.disableMacro("MATERIAL_IS_TRANSPARENT");
      }

      if (isTransparent) {
        shaderData.setFloat("material_ShadowCasterRenderQueue", RenderQueueType.AlphaTest);
        shaderData.setFloat("material_DepthOnlyRenderQueue", RenderQueueType.Transparent);
      } else {
        const queue = alphaCutoff ? RenderQueueType.AlphaTest : RenderQueueType.Opaque;
        shaderData.setFloat("material_ShadowCasterRenderQueue", queue);
        shaderData.setFloat("material_DepthOnlyRenderQueue", queue);
      }
    })

    this.onPropertyChanged("material_AlphaCutoff", (material, value) => {
      const shaderData = material.shaderData;
      const isTransparent = Boolean(shaderData.getFloat("isTransparent"));

      if (value) {
        shaderData.enableMacro("MATERIAL_IS_ALPHA_CUTOFF")
      } else {
        shaderData.disableMacro("MATERIAL_IS_ALPHA_CUTOFF")
      }

      const forwardQueue = isTransparent
        ? RenderQueueType.Transparent
        : value > 0 ? RenderQueueType.AlphaTest : RenderQueueType.Opaque;

      shaderData.setInt("renderQueueType", forwardQueue);
      shaderData.setFloat("material_ShadowCasterRenderQueue", value > 0 ? RenderQueueType.AlphaTest : (isTransparent ? RenderQueueType.AlphaTest : RenderQueueType.Opaque));
      shaderData.setFloat("material_DepthOnlyRenderQueue", forwardQueue);
    })

    this.onPropertyChanged("renderFace", (material, value) => {
      const shaderData = material.shaderData;
      switch (value) {
        case RenderFace.Front:
          shaderData.setInt("rasterStateCullMode", CullMode.Back);
          break;
        case RenderFace.Back:
          shaderData.setInt("rasterStateCullMode", CullMode.Front);
          break;
        case RenderFace.Double:
          shaderData.setInt("rasterStateCullMode", CullMode.Off);
          break;
      }
    })

    this.onPropertyChanged("blendMode", (material, value) => {
      const shaderData = material.shaderData;
      switch (value) {
        case BlendMode.Normal:
          shaderData.setInt("sourceColorBlendFactor", BlendFactor.SourceAlpha);
          shaderData.setInt("destinationColorBlendFactor", BlendFactor.OneMinusSourceAlpha);
          shaderData.setInt("sourceAlphaBlendFactor", BlendFactor.One);
          shaderData.setInt("destinationAlphaBlendFactor", BlendFactor.OneMinusSourceAlpha);
          break;
        case BlendMode.Additive:
          shaderData.setInt("sourceColorBlendFactor", BlendFactor.SourceAlpha);
          shaderData.setInt("destinationColorBlendFactor", BlendFactor.One);
          shaderData.setInt("sourceAlphaBlendFactor", BlendFactor.One);
          shaderData.setInt("destinationAlphaBlendFactor", BlendFactor.OneMinusSourceAlpha);
          break;
      }
    })`,Te=`import { Script } from '@galacean/engine';
/**
 * 脚本参考: https://galacean.antgroup.com/engine/docs/script/class
 */
export default class extends Script {
  /**
   * 主更新，逐帧调用。
   * @param deltaTime - 帧间隔时间
   */
  onUpdate(deltaTime: number) {}
}`,me=`import { StateMachineScript, Animator, AnimatorState } from '@galacean/engine';
/**
 * Performance can be improved by rewriting it for real use.
 */
export default class extends StateMachineScript {
  /**
   * onStateEnter is called when a transition starts and the state machine starts to evaluate this state.
   * @param animator - The animator
   * @param animatorState - The state be evaluated
   * @param layerIndex - The index of the layer where the state is located
   */
  // onStateEnter(animator: Animator, animatorState: AnimatorState, layerIndex: number): void {}

  /**
   * onStateUpdate is called on each Update frame between onStateEnter and onStateExit callbacks.
   * @param animator - The animator
   * @param animatorState - The state be evaluated
   * @param layerIndex - The index of the layer where the state is located
   */
  // onStateUpdate(animator: Animator, animatorState: AnimatorState, layerIndex: number): void {}

  /**
   * onStateExit is called when a transition ends and the state machine finishes evaluating this state.
   * @param animator - The animator
   * @param animatorState - The state be evaluated
   * @param layerIndex - The index of the layer where the state is located
   */
  // onStateExit(animator: Animator, animatorState: AnimatorState, layerIndex: number): void {}
}
`,Ae=`import { Material } from "@galacean/engine";

export default class extends ShaderUIScript {
  constructor() {
    super();

    // this.onPropertyChanged("otherProperty", (material: Material, value) => {
    //   // custom change callback
    // })

    // this.onMacroChanged('otherMacro', (material: Material, enabled, value) => {
    //   // custom change callback
    // })
  }

  override onMaterialShaderSwitched(material: Material) {}
}
`,Se=`import { Material, RenderQueueType, BlendFactor, RenderFace, CullMode, BlendMode } from "@galacean/engine";

export default class extends ShaderUIScript {
  constructor() {
    super();

    this.onPropertyChanged("material_BaseTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_BASETEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_BASETEXTURE");
      }
    })
${C}
  }
}
`,_e=`import { Material, RenderQueueType, Vector3, Vector2, Vector4, Color, BlendFactor, RenderFace, CullMode, BlendMode, RefractionMode } from "@galacean/engine";

export default class extends ShaderUIScript {
  constructor() {
    super();

    this.onPropertyChanged("material_BaseTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_BASETEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_BASETEXTURE");
      }
    })

    this.onPropertyChanged("material_RoughnessMetallicTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE");
      }
    })

    this.onPropertyChanged("anisotropy", (material: Material, value) => {
      const shaderData = material.shaderData;
      const anisotropyInfo = shaderData.getVector3("material_AnisotropyInfo");

      if (value) {
        shaderData.enableMacro("MATERIAL_ENABLE_ANISOTROPY");
      } else {
        shaderData.disableMacro("MATERIAL_ENABLE_ANISOTROPY");
      }

      anisotropyInfo.z = value;
    })

    this.onPropertyChanged("anisotropyRotation", (material: Material, value) => {
      const shaderData = material.shaderData;
      const anisotropyInfo = shaderData.getVector3("material_AnisotropyInfo");
      const rad = (Math.PI / 180) * value;

      anisotropyInfo.x = Math.cos(rad);
      anisotropyInfo.y = Math.sin(rad);
    })

    this.onPropertyChanged("material_AnisotropyTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
      }
    })

    this.onPropertyChanged("material_NormalTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_NORMALTEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_NORMALTEXTURE");
      }
    })

    this.onPropertyChanged("material_EmissiveTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_EMISSIVETEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_EMISSIVETEXTURE");
      }
    })

    this.onPropertyChanged("material_OcclusionTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_OCCLUSION_TEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_OCCLUSION_TEXTURE");
      }
    })

    this.onPropertyChanged("material_ClearCoat", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_ENABLE_CLEAR_COAT");
      } else {
        shaderData.disableMacro("MATERIAL_ENABLE_CLEAR_COAT");
      }
    })

    this.onPropertyChanged("material_ClearCoatTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_CLEAR_COAT_TEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_CLEAR_COAT_TEXTURE");
      }
    })

    this.onPropertyChanged("material_ClearCoatRoughnessTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE");
      }
    })

    this.onPropertyChanged("material_ClearCoatNormalTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE");
      }
    })

    this.onPropertyChanged("iridescence", (material: Material, value) => {
      const shaderData = material.shaderData;
      const iridescenceInfo = shaderData.getVector4("material_IridescenceInfo");
      if (value) {
        shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
      } else {
        shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
      }
      iridescenceInfo.x = value;
    })

    this.onPropertyChanged("iridescenceIOR", (material: Material, value) => {
      const shaderData = material.shaderData;
      const iridescenceInfo = shaderData.getVector4("material_IridescenceInfo");
      iridescenceInfo.y = value;
    })

    this.onPropertyChanged("iridescenceRange", (material: Material, value: Vector2) => {
      const shaderData = material.shaderData;
      const iridescenceInfo = shaderData.getVector4("material_IridescenceInfo");
      iridescenceInfo.z = value.x;
      iridescenceInfo.w = value.y;
    })

    this.onPropertyChanged("material_IridescenceTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_IRIDESCENCE_TEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_IRIDESCENCE_TEXTURE");
      }
    })

    this.onPropertyChanged("material_IridescenceThicknessTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE");
      }
    })


    this.onPropertyChanged("sheenColor", (material: Material, value: Color) => {
      const shaderData = material.shaderData;
      const sheenColor = shaderData.getColor("material_SheenColor");
      const sheenIntensity = shaderData.getFloat("sheenIntensity");

      const r = value.r * sheenIntensity;
      const g = value.g * sheenIntensity;
      const b = value.b * sheenIntensity;
      sheenColor.set(r, g, b, 1);

      const enableSheen = r + g + b > 0;
      if (enableSheen) {
        shaderData.enableMacro("MATERIAL_ENABLE_SHEEN");
      } else {
        shaderData.disableMacro("MATERIAL_ENABLE_SHEEN");
      }
    })

    this.onPropertyChanged("sheenIntensity", (material: Material, value: number) => {
      const shaderData = material.shaderData;
      const uiSheenColor = shaderData.getColor("sheenColor");
      const sheenColor = shaderData.getColor("material_SheenColor");

      sheenColor.set(value * uiSheenColor.r, value * uiSheenColor.g, value * uiSheenColor.b, 1)
    })


    this.onPropertyChanged("material_SheenTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_SHEEN_TEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_SHEEN_TEXTURE");
      }
    })

    this.onPropertyChanged("material_SheenRoughnessTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE");
      }
    })

    this.onPropertyChanged("material_Transmission", (material: Material, value) => {
      const shaderData = material.shaderData;

      if (value) {
        shaderData.enableMacro("MATERIAL_ENABLE_TRANSMISSION");
        shaderData.setInt("renderQueueType", RenderQueueType.Transparent);
      } else {
        shaderData.disableMacro("MATERIAL_ENABLE_TRANSMISSION");
        const isTransparent = Boolean(shaderData.getFloat("isTransparent"));
        if (isTransparent) {
          shaderData.setInt("renderQueueType", RenderQueueType.Transparent);
        } else if (shaderData.getFloat("material_AlphaCutoff")) {
          shaderData.setInt("renderQueueType", RenderQueueType.AlphaTest);
        } else {
          shaderData.setInt("renderQueueType", RenderQueueType.Opaque);
        }

      }
    })

    this.onPropertyChanged("material_TransmissionTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_TRANSMISSION_TEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_TRANSMISSION_TEXTURE");
      }
    })

    this.onPropertyChanged("material_Thickness", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_THICKNESS");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_THICKNESS");
      }
    })

    this.onPropertyChanged("material_ThicknessTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_THICKNESS_TEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_THICKNESS_TEXTURE");
      }
    })

    this.onPropertyChanged("isTransparent", (material: Material, isTransparent: boolean) => {
      const shaderData = material.shaderData;
      const alphaCutoff = shaderData.getFloat("material_AlphaCutoff");
      shaderData.setInt("depthWriteEnabled", isTransparent ? 0 : 1);
      shaderData.setInt("blendEnabled", isTransparent ? 1 : 0);

      if (shaderData.getFloat("material_Transmission") > 0) {
        shaderData.setInt("renderQueueType", RenderQueueType.Transparent);
      } else if (isTransparent) {
        shaderData.setInt("renderQueueType", RenderQueueType.Transparent);
        shaderData.enableMacro("MATERIAL_IS_TRANSPARENT");
      } else {
        shaderData.setInt("renderQueueType", alphaCutoff ? RenderQueueType.AlphaTest : RenderQueueType.Opaque);
        shaderData.disableMacro("MATERIAL_IS_TRANSPARENT");
      }

      if (isTransparent) {
        shaderData.setFloat("material_ShadowCasterRenderQueue", RenderQueueType.AlphaTest);
        shaderData.setFloat("material_DepthOnlyRenderQueue", RenderQueueType.Transparent);
      } else {
        const queue = alphaCutoff ? RenderQueueType.AlphaTest : RenderQueueType.Opaque;
        shaderData.setFloat("material_ShadowCasterRenderQueue", queue);
        shaderData.setFloat("material_DepthOnlyRenderQueue", queue);
      }
    })

    this.onPropertyChanged("material_AlphaCutoff", (material: Material, value: number) => {
      const shaderData = material.shaderData;
      const isTransparent = Boolean(shaderData.getFloat("isTransparent"));

      if (value) {
        shaderData.enableMacro("MATERIAL_IS_ALPHA_CUTOFF")
      } else {
        shaderData.disableMacro("MATERIAL_IS_ALPHA_CUTOFF")
      }

      const forwardQueue = shaderData.getFloat("material_Transmission") > 0
        ? RenderQueueType.Transparent
        : isTransparent
          ? RenderQueueType.Transparent
          : value > 0 ? RenderQueueType.AlphaTest : RenderQueueType.Opaque;

      shaderData.setInt("renderQueueType", forwardQueue);
      shaderData.setFloat("material_ShadowCasterRenderQueue", value > 0 ? RenderQueueType.AlphaTest : (isTransparent ? RenderQueueType.AlphaTest : RenderQueueType.Opaque));
      shaderData.setFloat("material_DepthOnlyRenderQueue", forwardQueue);
    })

    this.onPropertyChanged("renderFace", (material: Material, value: RenderFace) => {
      const shaderData = material.shaderData;
      switch (value) {
        case RenderFace.Front:
          shaderData.setInt("rasterStateCullMode", CullMode.Back);
          break;
        case RenderFace.Back:
          shaderData.setInt("rasterStateCullMode", CullMode.Front);
          break;
        case RenderFace.Double:
          shaderData.setInt("rasterStateCullMode", CullMode.Off);
          break;
      }
    })

    this.onPropertyChanged("blendMode", (material: Material, value: BlendMode) => {
      const shaderData = material.shaderData;
      switch (value) {
        case BlendMode.Normal:
          shaderData.setInt("sourceColorBlendFactor", BlendFactor.SourceAlpha);
          shaderData.setInt("destinationColorBlendFactor", BlendFactor.OneMinusSourceAlpha);
          shaderData.setInt("sourceAlphaBlendFactor", BlendFactor.One);
          shaderData.setInt("destinationAlphaBlendFactor", BlendFactor.OneMinusSourceAlpha);
          break;
        case BlendMode.Additive:
          shaderData.setInt("sourceColorBlendFactor", BlendFactor.SourceAlpha);
          shaderData.setInt("destinationColorBlendFactor", BlendFactor.One);
          shaderData.setInt("sourceAlphaBlendFactor", BlendFactor.One);
          shaderData.setInt("destinationAlphaBlendFactor", BlendFactor.OneMinusSourceAlpha);
          break;
      }
    })


    this.onPropertyChanged("refractionMode", (material: Material, value: RefractionMode) => {
      material.shaderData.enableMacro("REFRACTION_MODE", value.toString());
    })

  }

  override onMaterialShaderSwitched(material: Material) {
    const shaderData = material.shaderData;

    shaderData.disableMacro("MATERIAL_OMIT_NORMAL");
    shaderData.enableMacro("MATERIAL_NEED_WORLD_POS");
    shaderData.enableMacro("MATERIAL_NEED_TILING_OFFSET");

    // default value
    const anisotropyInfo = shaderData.getVector3("material_AnisotropyInfo");
    const iridescenceInfo = shaderData.getVector4("material_IridescenceInfo");
    const sheenColor = shaderData.getColor("material_SheenColor");
    const attenuationColor = shaderData.getColor("material_AttenuationColor");


    if (!anisotropyInfo) {
      shaderData.setVector3("material_AnisotropyInfo", new Vector3(1, 0, 0));
    } else {
      shaderData.setFloat("anisotropy", anisotropyInfo.z);
      const PI2 = Math.PI * 2;
      const rotationRad = (Math.atan2(anisotropyInfo.y, anisotropyInfo.x) + PI2) % PI2;
      shaderData.setFloat("anisotropyRotation", rotationRad * (180 / Math.PI))
    }

    if (!iridescenceInfo) {
      shaderData.setVector4("material_IridescenceInfo", new Vector4(0, 1.3, 100, 400));
    } else {
      shaderData.setFloat("iridescence", iridescenceInfo.x);
      shaderData.setFloat("iridescenceIOR", iridescenceInfo.y);
      shaderData.setVector2("iridescenceRange", new Vector2(iridescenceInfo.z, iridescenceInfo.w));
    }

    if(attenuationColor && attenuationColor.a == undefined){
      attenuationColor.a = 1;
    }

    if (!sheenColor) {
      shaderData.setColor("material_SheenColor", new Color(0, 0, 0, 1));
    } else {
      const intensity = shaderData.getFloat("sheenIntensity") ?? 1;

      if(!shaderData.getColor("sheenColor")) {
        shaderData.setColor("sheenColor", new Color());
      }
      
      shaderData.getColor("sheenColor").copyFrom(sheenColor)

      if(intensity > 0) {
        shaderData.getColor("sheenColor").scale(1 / intensity).a = 1.0;
      }
      
    }
  }
}

`,Me=`import { Material, RenderQueueType, BlendFactor, RenderFace, CullMode, BlendMode } from "@galacean/engine";

export default class extends ShaderUIScript {
  constructor() {
    super();

    this.onPropertyChanged("material_BaseTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_BASETEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_BASETEXTURE");
      }
    })

    this.onPropertyChanged("material_EmissiveTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_EMISSIVETEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_EMISSIVETEXTURE");
      }
    })

    this.onPropertyChanged("material_NormalTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_NORMALTEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_NORMALTEXTURE");
      }
    })

    this.onPropertyChanged("material_SpecularTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_SPECULAR_TEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_SPECULAR_TEXTURE");
      }
    })
${C}
  }

  override onMaterialShaderSwitched(material: Material) {
    const shaderData = material.shaderData;
    shaderData.disableMacro("MATERIAL_OMIT_NORMAL");
    shaderData.enableMacro("MATERIAL_NEED_WORLD_POS");
    shaderData.enableMacro("MATERIAL_NEED_TILING_OFFSET");
  }
}
`,Ie=`import { Material, RenderQueueType, BlendFactor, RenderFace, CullMode, BlendMode } from "@galacean/engine";

export default class extends ShaderUIScript {
  constructor() {
    super();

    this.onPropertyChanged("material_BaseTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_BASETEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_BASETEXTURE");
      }
    })

    this.onPropertyChanged("material_EmissiveTexture", (material: Material, value) => {
      const shaderData = material.shaderData;
      if (value) {
        shaderData.enableMacro("MATERIAL_HAS_EMISSIVETEXTURE");
      } else {
        shaderData.disableMacro("MATERIAL_HAS_EMISSIVETEXTURE");
      }
    })
${C}
  }
}
`,Ee=`import { Material } from "@galacean/engine";

export default class extends ShaderUIScript {
  constructor() {
    super();

    this.onPropertyChanged("sunMode", (material: Material, value: number) => {
      const shaderData = material.shaderData;
      switch (value) {
        case 0: // HighQuality
          shaderData.disableMacro("MATERIAL_SUN_SIMPLE");
          shaderData.enableMacro("MATERIAL_SUN_HIGH_QUALITY");
          break;
        case 1: // Simple
          shaderData.disableMacro("MATERIAL_SUN_HIGH_QUALITY");
          shaderData.enableMacro("MATERIAL_SUN_SIMPLE");
          break;
        case 2: // None
          shaderData.disableMacro("MATERIAL_SUN_HIGH_QUALITY");
          shaderData.disableMacro("MATERIAL_SUN_SIMPLE");
          break;
      }
    })
  }
}
`;var y=(t=>(t.Default="default",t[t.StateMachine=c.StateMachine]="StateMachine",t.UnlitUIScript="unlitUIScript",t.PbrUIScript="pbrUIScript",t.DefaultUIScript="defaultUIScript",t.BlinnPhongUIScript="blinnPhongUIScript",t.ParticleTrailUIScript="particleTrailUIScript",t.SkyProceduralUIScript="skyProceduralUIScript",t))(y||{});const P={default:Te,[y.StateMachine]:me,defaultUIScript:Ae,unlitUIScript:Se,pbrUIScript:_e,blinnPhongUIScript:Me,particleTrailUIScript:Ie,skyProceduralUIScript:Ee};class De{constructor(){d(this,"_propertyCallBacks",new Map);d(this,"_macroCallBacks",new Map)}onMaterialShaderSwitched(a){}onPropertyChanged(a,e){this._propertyCallBacks.set(a,e)}onMacroChanged(a,e){this._macroCallBacks.set(a,e)}}const fe=H(t=>{const a=t.asset,e=a.properties.map(n=>({label:n,type:T.PureDisplay,disable:!0,value:"",property:n})),r=a.macros.map(n=>({label:n,type:T.PureDisplay,disable:!0,value:"",property:n})),s=a.referencedShaderList.map(n=>({label:n.includePath,type:T.PureDisplay,disable:!0,value:"",property:n.includePath}));return A.jsxs(A.Fragment,{children:[A.jsx(I,{onModelChange:null,inspectorConfig:{property:"Watched Properties",type:T.Group,children:e},model:a},"ScriptProperties"),A.jsx(I,{onModelChange:null,inspectorConfig:{property:"Watched Macros",type:T.Group,children:r},model:a},"ScriptMacros"),A.jsx(I,{onModelChange:null,inspectorConfig:{property:"Referenced Shaders",type:T.Group,children:s},model:a},"ReferencedShaders")]})});var F=Object.defineProperty,Re=Object.getOwnPropertyDescriptor,Ce=(t,a,e)=>a in t?F(t,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[a]=e,_=(t,a,e,r)=>{for(var s=r>1?void 0:r?Re(a,e):a,n=t.length-1,o;n>=0;n--)(o=t[n])&&(s=(r?o(a,e,s):o(s))||s);return r&&s&&F(a,e,s),s},ye=(t,a,e)=>(Ce(t,typeof a!="symbol"?a+"":a,e),e);let l=class extends Q{constructor(a,e,r){super(a);d(this,"_code");d(this,"isScript",!0);d(this,"subType",c.Default);if(k(this),this.onDoubleClick=this.onDoubleClick.bind(this),r&&r.subType){if(r.subType===c.ShaderUI)return Reflect.construct(l.getScriptConstruct(c.ShaderUI),[a,e]);if(r.subType===c.StateMachine)return Reflect.construct(l.getScriptConstruct(c.StateMachine),[a,e])}return this}static registerScriptConstruct(a,e){return this.registeredScriptMap.set(a,e)}static getScriptConstruct(a){return this.registeredScriptMap.get(a)}get code(){return this._code}set code(a){this._code=a}updateCode(a){this._code=a,this._originMainFile=new File([a],this.name)}async initByMain(a){const e=await a.text();this._code=e,this.subType=this.meta.subType??c.Default}async initByCreation(a,e,r={template:y.Default}){const s=P[r.template];return this._code=s.replace("$$name",Z(this.name)),this._code}onDoubleClick(){ne(this,this.root,()=>{z(this.root.projectStore.id,this.id),W()})}getMainData(){return this._code}};ye(l,"registeredScriptMap",new Map);_([X],l.prototype,"_code",2);_([U()],l.prototype,"subType",2);_([$({type:T.Textarea,label:R("script.source.code")}),j],l.prototype,"code",1);l=_([V({type:"script",label:R("asset.script.title"),defaultName:"Script.ts",extname:"ts",dragLayer:G.Script,importMenuConfig:{type:q.Add},bundle({content:t}){return{content:new Blob([t],{type:"text/plain; charset=utf-8"})}}})],l);var ge=Object.defineProperty,be=Object.getOwnPropertyDescriptor,ve=(t,a,e,r)=>{for(var s=r>1?void 0:r?be(a,e):a,n=t.length-1,o;n>=0;n--)(o=t[n])&&(s=(r?o(a,e,s):o(s))||s);return r&&s&&ge(a,e,s),s};window.Galacean=Y;window.ShaderUIScript=De;var i;const O=(i=class extends l{constructor(){super(...arguments);d(this,"subType",c.ShaderUI);d(this,"_script");d(this,"_referencedShaderList",[])}get referencedShaderList(){return this._referencedShaderList}getMetaConfig(){let e=l.getRegisteredAssetMeta(l);return e={...e,defaultName:"ShaderUIScript.ts",customInspector:fe},e}get properties(){return Array.from(this._script._propertyCallBacks.keys())}get macros(){return Array.from(this._script._macroCallBacks.keys())}addReferencedShader(e){this._referencedShaderList.findIndex(r=>r.id===e.id)===-1&&this._referencedShaderList.push(e)}removeReferencedShader(e){const r=this._referencedShaderList.findIndex(s=>s.id===e.id);r!==-1&&this._referencedShaderList.splice(r,1)}async initByMain(e,r){const s=await e.text();await this.updateCode(s);const n=this.getRouteString();i.assetsMap.set(n,this)}initByCreation(e,r,s){return this._code=P[s.template],Promise.resolve(this.getMainData())}async updateCode(e){this._code=e,this._originMainFile=new File([e],this.name);const r=await this._compile(e),s=await pe(r.contents);this._script=new s.default}async _compile(e){await this.root.esbuildInstancePromise;const{dependencies:r,setting:s}=this.root.projectStore;return(await K.build({stdin:{contents:e,loader:"ts"},bundle:!0,format:"esm",plugins:[he({"@galacean/engine":{varName:"Galacean",type:"cjs"}}),Le(s.dependencies??r??{})]})).outputFiles[0]}async rename(e){let r=this.getRouteString();i.assetsMap.delete(r),await super.rename(e),r=this.getRouteString(),i.assetsMap.set(r,this),this._refreshShader()}afterDelete(){var r;(r=super.afterDelete)==null||r.call(this);const e=this.getRouteString();i.assetsMap.delete(e),this._refreshShader()}async moveTo(e){let r=this.getRouteString();i.assetsMap.delete(r),await this.moveViaFacade(e),r=this.getRouteString(),i.assetsMap.set(r,this),this._refreshShader()}getPropertyCallback(e){return this._script._propertyCallBacks.get(e)}getMacroCallback(e){return this._script._macroCallBacks.get(e)}onShaderChange(e){return this._script.onMaterialShaderSwitched(e)}onDoubleClick(){if(this.locked){S.error("Cannot edit internal Shader");return}super.onDoubleClick()}_refreshShader(){for(const e of this._referencedShaderList)e.reCompile()}},d(i,"assetsMap",new Map),i);ve([U()],O.prototype,"subType",2);let Ne=O;const L=new Map;function Le(t){return{name:"cdnImport",setup(a){a.onResolve({filter:/^\S/},e=>({namespace:"cdn",path:e.path})),a.onLoad({namespace:"cdn",filter:/^./},async e=>{const r=L.get(e.path);if(r)return{contents:r,loader:"js"};const s=e.path,n=t[s]??"latest",o=`https://registry.npmmirror.com/${s}/${n}/files`,h=await fetch(`${o}/package.json`);if(!h.ok)return{errors:[{text:`package not found: ${s}`}]};const m=await h.json(),u=m.browser||m.main;if(u){const M=J("/",u),g=await fetch(`${o}${M}`);if(g.ok){const b=await g.text();return L.set(s,b),{contents:b,loader:"js"}}else return{errors:[{text:`failed to import ${e.path}`}]}}})}}}export{c as E,De as S,l as a,Ne as b,y as c,he as g,pe as i,ne as l,P as t};
