@eigong/effekseer-webgpu-runtime 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -55,6 +55,10 @@ import { getEffekseerWebGPURuntimeUrls } from '@eigong/effekseer-webgpu-runtime'
55
55
  const urls = getEffekseerWebGPURuntimeUrls()
56
56
  ```
57
57
 
58
+ ## API Reference
59
+
60
+ La referencia breve de la API pública está en [API.md](./API.md).
61
+
58
62
  ## License
59
63
 
60
64
  This package redistributes Effekseer runtime files under the MIT License.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eigong/effekseer-webgpu-runtime",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Redistributable Effekseer WebGPU runtime assets with MIT license notice",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -1 +1 @@
1
- const e=(()=>{let e={},t={},r=null,n=!1,a=!1,s=null,i=null,o="",f=0,c=[];const l=e=>e instanceof ArrayBuffer?e:ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):null,u=e=>{if("string"!=typeof e||0===e.length)return"";const t=e.replace(/\\/g,"/").split("/"),r=[];for(let e=0;e<t.length;e++){const n=t[e];n&&"."!==n&&(".."!==n?r.push(n):r.length>0&&r.pop())}let n=r.join("/");for(;n.startsWith("/");)n=n.slice(1);return n.replace(/[A-Z]/g,e=>e.toLowerCase())},d="EFWGPKG2",p="__efwgpk__/main_effect_path.txt",h=new Uint8Array([69,102,107,87,103,46,87,101,98,71,80,85,46,67,84,82]);let g=0,m=null;const b=(()=>{const e=new Uint32Array(256);for(let t=0;t<256;t++){let r=t;for(let e=0;e<8;e++)r=1&r?3988292384^r>>>1:r>>>1;e[t]=r>>>0}return e})(),w=e=>{if(!(e instanceof Uint8Array))return 0;let t=4294967295;for(let r=0;r<e.length;r++){const n=255&(t^e[r]);t=t>>>8^b[n]}return~t>>>0},E=async(e,t)=>{const r=await(async()=>{if(m)return m;if(!globalThis.crypto||!globalThis.crypto.subtle||"function"!=typeof globalThis.crypto.subtle.importKey)throw new Error("Web Crypto AES-CTR is required for encrypted efkwgpk payloads");return m=globalThis.crypto.subtle.importKey("raw",h,"AES-CTR",!1,["decrypt"]),m})();return globalThis.crypto.subtle.decrypt({name:"AES-CTR",counter:t,length:128},r,e)},y=e=>String(e||"").replace(/\\/g,"/").split("?")[0].split("#")[0],S=e=>{const t=l(e);if(!t||t.byteLength<8)return"";const r=new Uint8Array(t,0,8);return String.fromCharCode(...r)},v=e=>{const t=new Map,r=e?e.byteLength:0,n=(e=>{const t=e?e.byteLength:0;if(!e||t<64)return null;const r=new DataView(e);if(S(e)!==d)return null;const n=r.getUint32(8,!0),a=r.getUint32(12,!0),s=r.getUint32(16,!0),i=r.getUint32(20,!0),o=r.getUint32(24,!0),f=r.getUint32(28,!0),c=r.getUint32(32,!0),l=r.getUint32(36,!0),u=r.getUint32(40,!0),p=r.getUint32(44,!0),h=r.getUint32(48,!0),g=r.getUint32(52,!0),m=2===s?64:3===s?80:0;if(0===m||n!==m||48!==o)return null;let b=null;if(4&a){if(s<3||t<80)return null;if(b=new Uint8Array(e.slice(56,72)),16!==b.byteLength)return null}return{headerSize:n,globalFlags:a,formatRevision:s,entryCount:i,entryStride:o,entriesOffset:f,stringPoolOffset:c,stringPoolSize:l,payloadOffset:u,payloadSize:p,tocCrc:h,payloadCrc:g,payloadNonce:b,payloadEncrypted:!!(4&a)}})(e);if(!n)return t;const a=new DataView(e),{headerSize:s,entryCount:i,entryStride:o,entriesOffset:f,stringPoolOffset:c,stringPoolSize:l,payloadOffset:p,payloadSize:h,tocCrc:g,payloadCrc:m}=n,b=BigInt(i)*BigInt(o);if(b>BigInt(r))return t;const E=Number(b);if(!P(f,E,r))return t;if(!P(c,l,r))return t;if(!P(p,h,r))return t;const y=c+l,v=p+h,x=new Uint8Array(e,0,s).slice();x.fill(0,48,56);const _=new Uint8Array(s+E+l);if(_.set(x,0),_.set(new Uint8Array(e,f,E),s),_.set(new Uint8Array(e,c,l),s+E),w(_)!==g>>>0)return t;const k=new Uint8Array(e,p,h);if(w(k)!==m>>>0)return t;const C=new TextDecoder("utf-8");for(let n=0;n<i;n++){const s=f+n*o,i=a.getUint32(s+8,!0),l=a.getUint32(s+12,!0),d=a.getUint32(s+16,!0),h=a.getUint32(s+20,!0),g=a.getUint32(s+24,!0),m=a.getUint32(s+28,!0),b=a.getUint32(s+32,!0),w=a.getUint32(s+36,!0);if(!P(i,l,r))continue;if(i<c||i+l>y)continue;if(!P(h,g,r))continue;if(h<p||h+g>v)continue;let E="";try{E=C.decode(new Uint8Array(e,i,l))}catch{continue}const S=u(E);if(!S)continue;const x={index:n,path:E,normalizedPath:S,flags:d,payloadOffset:h,packedSize:g,rawSize:m,packedCrc:b,rawCrc:w},_=t.get(S);_?_.push(x):t.set(S,[x])}return t._efwgpkMeta={payloadOffset:p,payloadSize:h,payloadEncrypted:n.payloadEncrypted,payloadNonce:n.payloadNonce,decryptedPayloadPromise:null},t},x=async e=>{const t=globalThis.fflate;if(t&&"function"==typeof t.unzlibSync){const r=t.unzlibSync(new Uint8Array(e));return l(r)}if("function"!=typeof DecompressionStream)throw new Error("No zlib inflate backend available for efkwgpk payload");const r=new DecompressionStream("deflate"),n=r.writable.getWriter();await n.write(e),await n.close();return await new Response(r.readable).arrayBuffer()},_=async(e,t,r)=>{const n=t&&t._efwgpkMeta?t._efwgpkMeta:null;if(!n||!n.payloadEncrypted)return new Uint8Array(e,r.payloadOffset,r.packedSize);if(!n.decryptedPayloadPromise){const t=new Uint8Array(e,n.payloadOffset,n.payloadSize);n.decryptedPayloadPromise=E(t,n.payloadNonce).then(e=>new Uint8Array(e))}const a=await n.decryptedPayloadPromise,s=r.payloadOffset-n.payloadOffset;return s<0||s+r.packedSize>a.byteLength?null:a.subarray(s,s+r.packedSize)},k=async(e,t,r)=>{const n=u(r);if(!n||!e||!t||0===t.size)return null;const a=t.get(n);if(!a||0===a.length)return null;for(let r=0;r<a.length;r++){const n=a[r];if(!P(n.payloadOffset,n.packedSize,e.byteLength))continue;const s=await _(e,t,n);if(s&&w(s)===n.packedCrc>>>0){if(0===n.flags&&n.packedSize===n.rawSize){const e=s.slice();if(w(e)!==n.rawCrc>>>0)continue;return e.buffer}if(1===n.flags){const e=await x(s);if(!e||e.byteLength!==n.rawSize)continue;if(w(new Uint8Array(e))!==n.rawCrc>>>0)continue;return e}}}return null},C=e=>e&&Number.isFinite(e.payloadOffset)&&Number.isFinite(e.packedSize)&&Number.isFinite(e.rawSize)&&Number.isFinite(e.flags)?`${e.flags}:${e.payloadOffset}:${e.packedSize}:${e.rawSize}`:"",M=(e,t,r)=>{const n=u(r);if(!n||!e||!t||0===t.size)return null;const a=t.get(n);if(!a||0===a.length)return null;for(let t=0;t<a.length;t++){const r=a[t];if(P(r.payloadOffset,r.packedSize,e.byteLength)){if(0===r.flags&&r.packedSize===r.rawSize)return r;if(1===r.flags)return r}}return null},P=(e,t,r)=>!!(Number.isFinite(e)&&Number.isFinite(t)&&Number.isFinite(r))&&(!(e<0||t<0||r<0)&&(!(e>r)&&t<=r-e)),R=(e,t,r)=>{const n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=()=>{const a=0|n.status;a>=200&&a<300||0===a?t(n.response):r&&r("not found",e)},n.onerror=()=>{r&&r("not found",e)},n.send(null)},U=e=>{try{const t=new XMLHttpRequest;t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null);const r=0|t.status;if(r>=200&&r<300||0===r)return t.response}catch{}return null},A=e=>{"function"==typeof e&&("function"==typeof queueMicrotask?queueMicrotask(e):Promise.resolve().then(e))},L=(e,t)=>{const r=String(e||"").replace(/\\/g,"/");const n=Number(t);return`${r}::${Number.isFinite(n)?n:1}`},D=e=>{e&&e.context&&e._cacheKey&&e.context._effectCache&&e.context._effectCache.get(e._cacheKey)===e&&e.context._effectCache.delete(e._cacheKey)},I=e=>e?{id:e.id,path:e.path,scale:e.scale,enabled:e.enabled,status:e.status,effect:"loaded"===e.status?e.effect:null,errorMessage:e.errorMessage,errorPath:e.errorPath,loadPromise:e.loadPromise,activeHandles:new Set(e.activeHandles),ownedResourceAliases:e.ownedResourceAliases.slice()}:null,F=(e,t,r)=>{if(e&&("function"==typeof t&&(e.isLoaded?A(()=>t()):e._loadFailed||e._onloadListeners.push(t)),"function"==typeof r))if(e._loadFailed){const t=e._loadErrorMessage||"failed to load effect",n=e._loadErrorPath||"";A(()=>r(t,n))}else e.isLoaded||e._onerrorListeners.push(r)},T=(e,t,r="")=>{if(!e||e._loadFailed)return;e._loadFailed=!0,e._loadErrorMessage=String(t||"failed to load effect"),e._loadErrorPath=String(r||""),D(e);const n=e._onerrorListeners.slice();e._onloadListeners.length=0,e._onerrorListeners.length=0;for(let t=0;t<n.length;t++){const r=n[t];A(()=>r(e._loadErrorMessage,e._loadErrorPath))}};let O=(e,t,r)=>{R(e,t,r)};const z={ptr:0,capacity:0},B=(t,r)=>{const n=t instanceof Float32Array?t:new Float32Array(t);if(n.length<=0)return void r(0);const a=((s=n.length)<=z.capacity&&0!==z.ptr||(0!==z.ptr&&(e._free(z.ptr),z.ptr=0,z.capacity=0),z.ptr=e._malloc(4*s),z.capacity=s),z.ptr);var s;e.HEAPF32.set(n,a>>2),r(a)},j=Object.freeze({rgba8unorm:22,"rgba8unorm-srgb":23,bgra8unorm:27,"bgra8unorm-srgb":28,rgba16float:40,depth24plus:46,"depth24plus-stencil8":47,depth32float:48}),W=(Object.freeze(Object.fromEntries(Object.entries(j).map(([e,t])=>[t,e]))),e=>{if("number"==typeof e&&Number.isFinite(e))return 0|e;if("string"!=typeof e)return null;const t=e.trim().toLowerCase();return t&&Object.prototype.hasOwnProperty.call(j,t)?j[t]:null}),H=async i=>{if(n)return;if(a)return void await new Promise((e,t)=>{c.push(r=>r?e():t(new Error("Runtime initialization failed.")))});if(a=!0,"undefined"==typeof effekseer_webgpu_native)throw a=!1,new Error("effekseer_webgpu_native is not loaded.");const o={};"string"==typeof i&&i.length>0&&(o.locateFile=e=>e.endsWith(".wasm")?i:e),s&&(o.preinitializedWebGPUDevice=s);const f=effekseer_webgpu_native(o);e=f instanceof Promise?await f:f,!s&&e?.preinitializedWebGPUDevice&&(s=e.preinitializedWebGPUDevice),s&&(e.preinitializedWebGPUDevice=s),(()=>{t={InitInternal:e.cwrap("EffekseerInitInternal","number",["number","number","string","number","number"]),InitExternal:e.cwrap("EffekseerInitExternal","number",["number","number","number","number"]),Init:e.cwrap("EffekseerInit","number",["number","number","string","number","number","number"]),Terminate:e.cwrap("EffekseerTerminate","void",["number"]),Update:e.cwrap("EffekseerUpdate","void",["number","number"]),BeginUpdate:e.cwrap("EffekseerBeginUpdate","void",["number"]),EndUpdate:e.cwrap("EffekseerEndUpdate","void",["number"]),UpdateHandle:e.cwrap("EffekseerUpdateHandle","void",["number","number","number"]),Draw:e.cwrap("EffekseerDraw","void",["number"]),DrawExternal:e.cwrap("EffekseerDrawExternal","void",["number"]),BeginDraw:e.cwrap("EffekseerBeginDraw","void",["number"]),EndDraw:e.cwrap("EffekseerEndDraw","void",["number"]),DrawHandle:e.cwrap("EffekseerDrawHandle","void",["number","number"]),SetProjectionMatrix:e.cwrap("EffekseerSetProjectionMatrix","void",["number","number"]),SetProjectionPerspective:e.cwrap("EffekseerSetProjectionPerspective","void",["number","number","number","number","number"]),SetProjectionOrthographic:e.cwrap("EffekseerSetProjectionOrthographic","void",["number","number","number","number","number"]),SetCameraMatrix:e.cwrap("EffekseerSetCameraMatrix","void",["number","number"]),SetCameraLookAt:e.cwrap("EffekseerSetCameraLookAt","void",["number","number","number","number","number","number","number","number","number","number"]),LoadEffect:e.cwrap("EffekseerLoadEffect","number",["number","number","number","number"]),ReleaseEffect:e.cwrap("EffekseerReleaseEffect","void",["number","number"]),ReloadResources:e.cwrap("EffekseerReloadResources","void",["number","number","number","number"]),StopAllEffects:e.cwrap("EffekseerStopAllEffects","void",["number"]),PlayEffect:e.cwrap("EffekseerPlayEffect","number",["number","number","number","number","number"]),StopEffect:e.cwrap("EffekseerStopEffect","void",["number","number"]),StopRoot:e.cwrap("EffekseerStopRoot","void",["number","number"]),Exists:e.cwrap("EffekseerExists","number",["number","number"]),SetFrame:e.cwrap("EffekseerSetFrame","void",["number","number","number"]),SetLocation:e.cwrap("EffekseerSetLocation","void",["number","number","number","number","number"]),SetRotation:e.cwrap("EffekseerSetRotation","void",["number","number","number","number","number"]),SetScale:e.cwrap("EffekseerSetScale","void",["number","number","number","number","number"]),SetMatrix:e.cwrap("EffekseerSetMatrix","void",["number","number","number"]),SetAllColor:e.cwrap("EffekseerSetAllColor","void",["number","number","number","number","number","number"]),SetTargetLocation:e.cwrap("EffekseerSetTargetLocation","void",["number","number","number","number","number"]),GetDynamicInput:e.cwrap("EffekseerGetDynamicInput","number",["number","number","number"]),SetDynamicInput:e.cwrap("EffekseerSetDynamicInput","void",["number","number","number","number"]),SendTrigger:e.cwrap("EffekseerSendTrigger","void",["number","number","number"]),SetPaused:e.cwrap("EffekseerSetPaused","void",["number","number","number"]),SetShown:e.cwrap("EffekseerSetShown","void",["number","number","number"]),SetSpeed:e.cwrap("EffekseerSetSpeed","void",["number","number","number"]),SetRandomSeed:e.cwrap("EffekseerSetRandomSeed","void",["number","number","number"]),SetCompositeMode:e.cwrap("EffekseerSetCompositeMode","void",["number","number"]),GetRestInstancesCount:e.cwrap("EffekseerGetRestInstancesCount","number",["number"]),DrawExternalBack:e.cwrap("EffekseerDrawExternalBack","void",["number"]),DrawExternalFront:e.cwrap("EffekseerDrawExternalFront","void",["number"]),IsVertexArrayObjectSupported:e.cwrap("EffekseerIsVertexArrayObjectSupported","number",["number"]),SetRestorationOfStatesFlag:e.cwrap("EffekseerSetRestorationOfStatesFlag","void",["number","number"]),CaptureBackground:e.cwrap("EffekseerCaptureBackground","void",["number","number","number","number","number"]),ResetBackground:e.cwrap("EffekseerResetBackground","void",["number"]),SetDepthTexture:e.cwrap("EffekseerSetDepthTexture","void",["number","number"]),SetBackgroundTexture:e.cwrap("EffekseerSetBackgroundTexture","void",["number","number"])},e.resourcesMap={},e._loadBinary=(t,n)=>{const a=r;if(!a)return null;let s=a.resources.find(e=>e.path===t);if(s)return s.isLoaded?s.buffer:null;s={path:t,isLoaded:!1,buffer:null,isRequired:!!n},a.resources.push(s);const i=e=>String(e||"").replace(/\\/g,"/"),o=e=>{const t=i(e);let r=t.startsWith("/")||/^[a-zA-Z]+:\/\//.test(t)?t:(a.baseDir||"")+t;return a.redirect&&(r=a.redirect(r)),r},f=(e=>{const t=i(e),r=[],n=new Set,a=e=>{e&&!n.has(e)&&(n.add(e),r.push(e))},s=e=>{if(!e||e.includes("/"))return;const t=e.toLowerCase();(t.endsWith(".png")||t.endsWith(".jpg")||t.endsWith(".jpeg")||t.endsWith(".dds"))&&a(`Texture/${e}`),(t.endsWith(".efkmodel")||t.endsWith(".mqo"))&&a(`Model/${e}`)},o=t.indexOf("/");if(o>0){const e=t.slice(0,o).toLowerCase();(e.endsWith(".efk")||e.endsWith(".efkefc")||e.endsWith(".efkproj"))&&a(t.slice(o+1))}a(t),s(t);let f=t.indexOf("/");for(;f>=0;){const e=t.slice(f+1);a(e),s(e),f=t.indexOf("/",f+1)}return r})(t);if(a.syncResourceLoad){for(let r=0;r<f.length;r++){const n=f[r],a=o(n),i=e.resourcesMap[a]||e.resourcesMap[n]||e.resourcesMap[t];if(null!=i)return s.buffer=i,s.isLoaded=!0,i;const c=U(a);if(null!=c)return s.buffer=c,s.isLoaded=!0,e.resourcesMap[a]=c,e.resourcesMap[n]=c,c}return s.buffer=null,s.isLoaded=!0,null}for(let r=0;r<f.length;r++){const n=f[r],i=o(n),c=e.resourcesMap[i]||e.resourcesMap[n]||e.resourcesMap[t];if(null!=c)return s.buffer=c,s.isLoaded=!0,Promise.resolve().then(()=>a._update()),null}let c=0;const l=()=>{if(c>=f.length)return s.buffer=null,s.isLoaded=!0,void a._update();const e=f[c++],t=o(e);O(t,e=>{if(null!=e)return s.buffer=e,s.isLoaded=!0,void a._update();l()},()=>{l()})};return l(),null},n=!0,a=!1;const s=c;c=[],s.forEach(e=>e(!0))})()};class V{constructor(e){this.context=e,this.nativeptr=0,this.baseDir="",this.syncResourceLoad=!1,this.isLoaded=!1,this.scale=1,this.resources=[],this.mainBuffer=null,this.onload=null,this.onerror=null,this._onloadListeners=[],this._onerrorListeners=[],this._loadFailed=!1,this._loadErrorMessage="",this._loadErrorPath="",this._cacheKey="",this.redirect=null,this.packageOnly=!1,this._ownedResourceAliases=[],this._managedRefIds=new Set}_load(n){const a=l(n);if(!a)return void T(this,"invalid data","");r=this,this.mainBuffer=a;const s=e._malloc(a.byteLength);e.HEAPU8.set(new Uint8Array(a),s),this.nativeptr=t.LoadEffect(this.context.nativeptr,s,a.byteLength,this.scale),e._free(s),r=null,this._update()}_reload(){if(!this.mainBuffer||!this.nativeptr)return;r=this;const n=e._malloc(this.mainBuffer.byteLength);e.HEAPU8.set(new Uint8Array(this.mainBuffer),n),t.ReloadResources(this.context.nativeptr,this.nativeptr,n,this.mainBuffer.byteLength),e._free(n),r=null}_update(){let e=!1;const t=[];for(let r=0;r<this.resources.length;r++){const n=this.resources[r];if(!n.isLoaded){e=!0;break}n.isRequired&&null==n.buffer&&t.push(n.path)}if(e)return;t.length>0&&console.warn(`[EffekseerWebGPU] missing required resources ignored: ${t.join(", ")}`);const r=0!==this.nativeptr;if(!r){const e=t.length>0?`failed to load effect. missing resources: ${t.join(", ")}`:"failed to load effect";return void T(this,e,this.baseDir||"")}r&&this.resources.length>0&&this._reload(),!this.isLoaded&&r&&(this.isLoaded=!0,(e=>{if(!e)return;const t=e._onloadListeners.slice();e._onloadListeners.length=0,e._onerrorListeners.length=0;for(let e=0;e<t.length;e++){const r=t[e];A(()=>r())}})(this))}}const G=(t,r,n,a,s,i,o,f=null)=>{const c=f||new V(t);c.scale=a,c._ownedResourceAliases=[],F(c,s,i);const l=v(r);if(0===l.size)return T(c,"invalid data. expected efkwgpk package",n||""),c;const d=(()=>{if("string"!=typeof n||0===n.length)return"";const e=y(n),t=e.lastIndexOf("/");return t>=0?e.slice(0,t+1):""})(),h=d.toLowerCase(),m=`efwgpk://${++g}/`,b=new Map;return c.baseDir=d,c.syncResourceLoad=!0,c.packageOnly=!0,c.redirect=e=>{const t=y(e),r=[];h&&t.toLowerCase().startsWith(h)&&r.push(t.slice(d.length)),r.push(t);for(let e=0;e<r.length;e++){const t=u(r[e]);if(!t)continue;const n=b.get(t);if(n)return n}return e},(async()=>{try{const t=await(async(e,t)=>{const r=await k(e,t,p);if(r)try{const e=new TextDecoder("utf-8").decode(new Uint8Array(r)).replace(/\0+$/,""),t=u(e);if(t)return t}catch{}for(const[e,r]of t.entries())if(e.endsWith(".efkwg")&&r&&r.length>0)return e;return""})(r,l);if(!t)throw new Error("main effect path not found in efkwgpk package");const a=await k(r,l,t),s=String.fromCharCode(...new Uint8Array(a||new ArrayBuffer(0),0,Math.min(4,a?a.byteLength:0)));if(!a||"EFWG"!==s&&"SKFE"!==s)throw new Error("main effect inside efkwgpk is not a valid .efkwg");const i=new Map,o=new Map;for(const[n]of l.entries()){if(n===t||n===u(p))continue;const a=M(r,l,n);if(!a)continue;const s=C(a);if(!s)continue;let f=i.get(s);if(!f){let t=o.get(s);if(void 0===t&&(t=await k(r,l,n),o.set(s,t||null)),!t)continue;f=`${m}__payload/${i.size}`,e.resourcesMap[f]=t,i.set(s,f)}b.set(n,f)}c._ownedResourceAliases=Array.from(i.values()),c._load(a),c.nativeptr||T(c,"failed to load effect from efkwgpk package",n||t)}catch(e){T(c,e&&e.message?e.message:"failed to load effect from efkwgpk package",n||"")}})(),c};class N{constructor(e,t){this.context=e,this.native=t}stop(){t.StopEffect(this.context.nativeptr,this.native)}stopRoot(){t.StopRoot(this.context.nativeptr,this.native)}get exists(){return!!t.Exists(this.context.nativeptr,this.native)}setFrame(e){t.SetFrame(this.context.nativeptr,this.native,e)}setLocation(e,r,n){t.SetLocation(this.context.nativeptr,this.native,e,r,n)}setRotation(e,r,n){t.SetRotation(this.context.nativeptr,this.native,e,r,n)}setScale(e,r,n){t.SetScale(this.context.nativeptr,this.native,e,r,n)}setAllColor(e,r,n,a){t.SetAllColor(this.context.nativeptr,this.native,e,r,n,a)}setTargetLocation(e,r,n){t.SetTargetLocation(this.context.nativeptr,this.native,e,r,n)}getDynamicInput(e){return t.GetDynamicInput(this.context.nativeptr,this.native,e)}setDynamicInput(e,r){t.SetDynamicInput(this.context.nativeptr,this.native,e,r)}sendTrigger(e){t.SendTrigger(this.context.nativeptr,this.native,e)}setPaused(e){t.SetPaused(this.context.nativeptr,this.native,e?1:0)}setShown(e){t.SetShown(this.context.nativeptr,this.native,e?1:0)}setSpeed(e){t.SetSpeed(this.context.nativeptr,this.native,e)}setRandomSeed(e){t.SetRandomSeed(this.context.nativeptr,this.native,e)}setMatrix(e){B(e,e=>t.SetMatrix(this.context.nativeptr,this.native,e))}}class ${constructor(){this.nativeptr=0,this._effectCache=new Map,this._registeredEffects=new Map,this._registeredEffectStates=new Map,this.fixedUpdateStepFrames=1,this.fixedUpdateMaxSubsteps=4,this.fixedUpdateAccumulator=0,this.externalRenderPassEnabled=!1}_normalizeManagedEffectDescriptor(e,t){const r=String(e||"").trim();if(!r)throw new Error("registerEffects() requires non-empty effect ids.");let n=null;if("string"==typeof t)n={path:t};else{if(!t||"object"!=typeof t||Array.isArray(t))throw new Error(`registerEffects() entry "${r}" must be a string path or config object.`);n=t}const a=String(n.path||"").trim();if(!a)throw new Error(`registerEffects() entry "${r}" requires a non-empty path.`);const s=Number(n.scale);return{id:r,path:a,scale:Number.isFinite(s)?s:1,enabled:!1!==n.enabled}}_createManagedEffectState(e){return{id:e.id,path:e.path,scale:e.scale,enabled:e.enabled,status:"unloaded",effect:null,errorMessage:"",errorPath:"",loadPromise:null,activeHandles:new Set,ownedResourceAliases:[],_generation:0,_loadingEffect:null}}_resolveManagedEffectIds(e,t=!1){if(null==e){const e=[];for(const[r,n]of this._registeredEffectStates.entries())t&&!n.enabled||e.push(r);return e}const r=Array.isArray(e)?e:[e],n=[],a=new Set;for(let e=0;e<r.length;e++){const t=String(r[e]||"").trim();t&&!a.has(t)&&(a.add(t),n.push(t))}return n}_registerManagedEffectReference(e,t){e&&(e._managedRefIds instanceof Set||(e._managedRefIds=new Set),e._managedRefIds.add(t))}_releaseManagedEffectReference(e,t){e&&e._managedRefIds instanceof Set&&e._managedRefIds.delete(t)}_releaseManagedEffectIfUnused(r){if(!r)return;const n=r._managedRefIds instanceof Set?r._managedRefIds:null;n&&n.size>0||(D(r),(t=>{if(t&&e.resourcesMap)for(let r=0;r<t.length;r++){const n=t[r];"string"==typeof n&&0!==n.length&&delete e.resourcesMap[n]}})(r._ownedResourceAliases),r._ownedResourceAliases=[],this.nativeptr&&r.nativeptr&&(t.ReleaseEffect(this.nativeptr,r.nativeptr),r.nativeptr=0))}_stopManagedHandles(e){if(e){for(const t of e.activeHandles)try{t?.stopRoot?.()}catch{}e.activeHandles.clear()}}_cleanupManagedHandles(){for(const e of this._registeredEffectStates.values())if(e&&0!==e.activeHandles.size)for(const t of Array.from(e.activeHandles))t&&!1!==t.exists||e.activeHandles.delete(t)}_resetManagedEffectStateToUnloaded(e){e&&(e.effect=null,e.status="unloaded",e.errorMessage="",e.errorPath="",e.loadPromise=null,e.ownedResourceAliases=[],e._loadingEffect=null)}_loadRegisteredEffectState(e){if(!e||!this.nativeptr)return Promise.resolve(null);const t=this._registeredEffects.get(e.id);if(!t)return Promise.resolve(null);const r=e._generation+1;e._generation=r,e.status="loading",e.errorMessage="",e.errorPath="",e.effect=null,e.ownedResourceAliases=[],e._loadingEffect=null;const n=new Promise(n=>{let a=!1,s=null;const i=s=>{if(a)return;a=!0;return this._registeredEffectStates.get(e.id)!==e||e._generation!==r?(this._releaseManagedEffectIfUnused(s),void n(null)):(e._loadingEffect=null,e.loadPromise=null,s&&s.isLoaded?(e.effect=s,e.status="loaded",e.errorMessage="",e.errorPath="",e.ownedResourceAliases=Array.isArray(s._ownedResourceAliases)?s._ownedResourceAliases.slice():[],void n(s)):(e.status="failed",e.errorMessage="failed to load effect",e.errorPath=t.path,void n(null)))},o=(i,o="")=>{if(a)return;a=!0,s&&this._releaseManagedEffectReference(s,e.id);if(this._registeredEffectStates.get(e.id)!==e||e._generation!==r)return s&&this._releaseManagedEffectIfUnused(s),void n(null);e._loadingEffect=null,e.loadPromise=null,e.effect=null,e.status="failed",e.errorMessage=String(i||"failed to load effect"),e.errorPath=String(o||t.path||""),e.ownedResourceAliases=[],s&&this._releaseManagedEffectIfUnused(s),n(null)};try{s=this.loadEffect(t.path,t.scale,()=>i(s),(e,t)=>o(e,t))}catch(e){return void o(e&&e.message?e.message:"failed to load effect",t.path)}e._loadingEffect=s,s?(this._registerManagedEffectReference(s,e.id),s.isLoaded?i(s):s._loadFailed&&o(s._loadErrorMessage,s._loadErrorPath)):o("failed to create effect",t.path)});return e.loadPromise=n,n}_prepareInitSettings(e={},t=!1){const r=e.instanceMaxCount||4e3,n=e.squareMaxCount||1e4,a=!1!==e.linearColorSpace?1:0,s=e.compositeWithBackground?1:0;return this.externalRenderPassEnabled=t,this.fixedUpdateAccumulator=0,{instanceMaxCount:r,squareMaxCount:n,linearColorSpace:a,compositeWithBackground:s}}_finishContextInit(e={}){return this.nativeptr&&e.effects&&(this.registerEffects(e.effects),this.preloadEffects()),!!this.nativeptr}init(e,r={}){if(!0===r.externalRenderPass)return this.initExternal(r);let n="#canvas";"string"==typeof e?n=e.startsWith("#")?e:`#${e}`:"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement&&(e.id||(f+=1,e.id=`effekseer_webgpu_canvas_${f}`),n=`#${e.id}`);const a=this._prepareInitSettings(r,!1);return this.nativeptr=t.InitInternal(a.instanceMaxCount,a.squareMaxCount,n,a.linearColorSpace,a.compositeWithBackground),this._finishContextInit(r)}initExternal(e={}){const r=this._prepareInitSettings(e,!0);return this.nativeptr=t.InitExternal(r.instanceMaxCount,r.squareMaxCount,r.linearColorSpace,r.compositeWithBackground),this._finishContextInit(e)}update(e=1){const r=Number(e);if(!Number.isFinite(r)||r<=0)return void this._cleanupManagedHandles();this.fixedUpdateAccumulator+=r;let n=0;for(;this.fixedUpdateAccumulator>=this.fixedUpdateStepFrames&&n<this.fixedUpdateMaxSubsteps;)t.Update(this.nativeptr,this.fixedUpdateStepFrames),this.fixedUpdateAccumulator-=this.fixedUpdateStepFrames,n++;n>=this.fixedUpdateMaxSubsteps&&this.fixedUpdateAccumulator>=this.fixedUpdateStepFrames&&(this.fixedUpdateAccumulator=0),this._cleanupManagedHandles()}beginUpdate(){t.BeginUpdate(this.nativeptr)}endUpdate(){t.EndUpdate(this.nativeptr)}updateHandle(e,r=1){t.UpdateHandle(this.nativeptr,e.native,r)}draw(){this.externalRenderPassEnabled||t.Draw(this.nativeptr)}drawExternal(r,n=null,a="all"){if(!r)return;const s=W(n&&n.colorFormat),i=(()=>{const e=W(n&&n.depthFormat);return null===e?0:e})(),o=(e=>{const t=Number(e);return!Number.isFinite(t)||t<=0?1:Math.max(1,Math.floor(t))})(n&&n.sampleCount),f=(e,t)=>!!e&&Object.prototype.hasOwnProperty.call(e,t),c=f(n,"depthTextureView")||f(n,"importDepthTextureView"),l=f(n,"backgroundTextureView")||f(n,"importBackgroundTextureView"),u=c?f(n,"depthTextureView")?n.depthTextureView:n.importDepthTextureView:null,d=l?f(n,"backgroundTextureView")?n.backgroundTextureView:n.importBackgroundTextureView:null,p=c?e.__effekseerDepthTextureView:null,h=l?e.__effekseerBackgroundTextureView:null;e.__effekseerExternalRenderPass=r,e.__effekseerExternalPassColorFormat=s,e.__effekseerExternalPassDepthFormat=i,e.__effekseerExternalPassSampleCount=o,c&&(e.__effekseerDepthTextureView=u||null),l&&(e.__effekseerBackgroundTextureView=d||null);const g="back"===a?"back":"front"===a?"front":"all";try{"back"===g?t.DrawExternalBack(this.nativeptr):"front"===g?t.DrawExternalFront(this.nativeptr):t.DrawExternal(this.nativeptr)}finally{c&&(e.__effekseerDepthTextureView=p||null),l&&(e.__effekseerBackgroundTextureView=h||null),e.__effekseerExternalRenderPass=null,e.__effekseerExternalPassColorFormat=null,e.__effekseerExternalPassDepthFormat=null,e.__effekseerExternalPassSampleCount=null}}beginDraw(){t.BeginDraw(this.nativeptr)}endDraw(){t.EndDraw(this.nativeptr)}drawHandle(e){t.DrawHandle(this.nativeptr,e.native)}setProjectionMatrix(e){B(e,e=>t.SetProjectionMatrix(this.nativeptr,e))}setProjectionPerspective(e,r,n,a){t.SetProjectionPerspective(this.nativeptr,e,r,n,a)}setProjectionOrthographic(e,r,n,a){t.SetProjectionOrthographic(this.nativeptr,e,r,n,a)}setCameraMatrix(e){B(e,e=>t.SetCameraMatrix(this.nativeptr,e))}setCameraLookAt(e,r,n,a,s,i,o,f,c){t.SetCameraLookAt(this.nativeptr,e,r,n,a,s,i,o,f,c)}setCameraLookAtFromVector(e,t,r={x:0,y:1,z:0}){this.setCameraLookAt(e.x,e.y,e.z,t.x,t.y,t.z,r.x,r.y,r.z)}setCompositeMode(e){t.SetCompositeMode(this.nativeptr,e?1:0)}loadEffect(e,t=1,r,n,a){const s="function"==typeof t?1:t,i="function"==typeof t?t:r,o="function"==typeof t?r:n,f=a;let c=null;if("string"==typeof e&&null==f){c=L(e,s);const t=this._effectCache.get(c);if(t)return F(t,i,o),t}const u=new V(this);u.scale=s,u.redirect=f,u._cacheKey=c||"",F(u,i,o),c&&this._effectCache.set(c,u);const p=(e,t="")=>(T(u,e,t),u);if("string"==typeof e)return"string"==typeof(h=e)&&0!==h.length&&h.replace(/\\/g,"/").split("?")[0].split("#")[0].toLowerCase().endsWith(".efkwg")?(R(e,t=>{const r=l(t);if(!r)return void p("failed to fetch efkwg effect",e);const n=e.replace(/\\/g,"/").split("?")[0].split("#")[0],a=n.lastIndexOf("/");u.baseDir=a>=0?n.slice(0,a+1):"",u.syncResourceLoad=!1,u._load(r),u.nativeptr||p("failed to load efkwg effect",e)},()=>{p("failed to fetch efkwg effect",e)}),u):(e=>"string"==typeof e&&0!==e.length&&y(e).toLowerCase().endsWith(".efkwgpk"))(e)?(R(e,t=>{const r=l(t);r?G(this,r,e,s,null,null,0,u):p("failed to fetch efkwgpk package",e)},()=>{p("failed to fetch efkwgpk package",e)}),u):p("unsupported effect format. expected .efkwg or .efkwgpk",e);var h;const g=l(e);if(!g)return p("invalid data. expected efkwg or efkwgpk bytes","");if(S(g)===d)return G(this,g,"",s,null,null,0,u);const m=String.fromCharCode(...new Uint8Array(g,0,Math.min(4,g.byteLength)));return"EFWG"===m||"SKFE"===m?(u._load(g),u.nativeptr?u:p("failed to load efkwg effect","")):p("invalid data. expected efkwg or efkwgpk bytes","")}loadEffectPackage(e,t,r=1,n,a){let s=r,i=n,o=a;return"function"==typeof r&&(s=1,i=r,o=n),this.loadEffect(e,s,i,o)}registerEffects(e){if(!e||"object"!=typeof e||Array.isArray(e))throw new Error("registerEffects() expects an object map of effect ids to paths/configs.");const t=[];for(const[r,n]of Object.entries(e)){if(this._registeredEffects.has(r))throw new Error(`registerEffects() duplicate id "${r}".`);t.push(this._normalizeManagedEffectDescriptor(r,n))}for(let e=0;e<t.length;e++){const r=t[e];if(this._registeredEffects.has(r.id))throw new Error(`registerEffects() duplicate id "${r.id}".`)}for(let e=0;e<t.length;e++){const r=t[e];this._registeredEffects.set(r.id,r),this._registeredEffectStates.set(r.id,this._createManagedEffectState(r))}if(this.nativeptr)for(let e=0;e<t.length;e++){const r=t[e];r.enabled&&this.preloadEffects([r.id])}}preloadEffects(e){const t=this._resolveManagedEffectIds(e,null==e);return Promise.all(t.map(async e=>{const t=this._registeredEffectStates.get(e);return t?"loaded"===t.status&&t.effect?.isLoaded?[e,t.effect]:"loading"===t.status&&t.loadPromise?[e,await t.loadPromise]:[e,await this._loadRegisteredEffectState(t)]:[e,null]})).then(e=>new Map(e))}reloadEffects(e){const t=this._resolveManagedEffectIds(e,null==e);return this.unloadEffects(t),this.preloadEffects(t)}unloadEffects(e){const t=this._resolveManagedEffectIds(e);for(let e=0;e<t.length;e++){const r=t[e],n=this._registeredEffectStates.get(r);if(!n)continue;n._generation+=1,this._stopManagedHandles(n);const a=n._loadingEffect;a&&(this._releaseManagedEffectReference(a,r),this._releaseManagedEffectIfUnused(a));const s=n.effect;s&&(this._releaseManagedEffectReference(s,r),this._releaseManagedEffectIfUnused(s)),this._resetManagedEffectStateToUnloaded(n)}}unregisterEffects(e){const t=this._resolveManagedEffectIds(e);this.unloadEffects(t);for(let e=0;e<t.length;e++){const r=t[e];this._registeredEffects.delete(r),this._registeredEffectStates.delete(r)}}getEffect(e){const t=this._registeredEffectStates.get(String(e||""));return"loaded"===t?.status&&t.effect?.isLoaded?t.effect:null}getEffectState(e){return I(this._registeredEffectStates.get(String(e||"")))}getEffectStates(){return Array.from(this._registeredEffectStates.values(),e=>I(e))}whenEffectsReady(e){return this.preloadEffects(e)}playEffect(e,t=0,r=0,n=0){const a=this._registeredEffectStates.get(String(e||""));if(!a||"loaded"!==a.status||!a.effect?.isLoaded)return null;const s=this.play(a.effect,t,r,n);return s&&a.activeHandles.add(s),s}releaseEffect(e){e&&e.nativeptr&&(D(e),t.ReleaseEffect(this.nativeptr,e.nativeptr),e.nativeptr=0)}play(e,r=0,n=0,a=0){if(!e||!e.isLoaded)return null;const s=t.PlayEffect(this.nativeptr,e.nativeptr,r,n,a);return s>=0?new N(this,s):null}stopAll(){t.StopAllEffects(this.nativeptr)}setResourceLoader(e){O=e}getRestInstancesCount(){return t.GetRestInstancesCount(this.nativeptr)}isVertexArrayObjectSupported(){return!!t.IsVertexArrayObjectSupported(this.nativeptr)}setRestorationOfStatesFlag(e){t.SetRestorationOfStatesFlag(this.nativeptr,e?1:0)}captureBackground(e,r,n,a){t.CaptureBackground(this.nativeptr,e,r,n,a)}resetBackground(){t.ResetBackground(this.nativeptr)}}return new class{async initRuntime(e,t,r){try{await H(e),t&&t()}catch(e){a=!1,n=!1,c=[],r?r(e):console.error(e)}}createContext(){return n?new $:null}releaseContext(e){e&&e.nativeptr&&(e.unloadEffects?.(),t.Terminate(e.nativeptr),e.nativeptr=0,e._effectCache?.clear?.(),e._registeredEffects?.clear?.(),e._registeredEffectStates?.clear?.())}setImageCrossOrigin(e){o=e}setWebGPUDevice(e){if(n||a)throw new Error("setWebGPUDevice() must be called before initRuntime().");if(null==e)return i=null,void(s=null);if("object"!=typeof e||"function"!=typeof e.createCommandEncoder||!e.queue)throw new Error("setWebGPUDevice() expects a valid GPUDevice.");i=e,s=e}setRendererWorkingColorSpace(e){return((e=null)=>{const t=e;return!(!t||!t.ColorManagement)&&"workingColorSpace"in t.ColorManagement&&void 0!==t.LinearSRGBColorSpace&&(t.ColorManagement.workingColorSpace=t.LinearSRGBColorSpace,!0)})(e)}getWebGPUDevice(){return s||(e?e.preinitializedWebGPUDevice:null)||null}init(e,t){return this.defaultContext?.nativeptr&&this.releaseContext(this.defaultContext),this.defaultContext=new $,this.defaultContext.init(e,t)}update(e){this.defaultContext.update(e)}beginUpdate(){this.defaultContext.beginUpdate()}endUpdate(){this.defaultContext.endUpdate()}updateHandle(e,t){this.defaultContext.updateHandle(e,t)}draw(){this.defaultContext.draw()}drawExternal(e,t,r="all"){this.defaultContext.drawExternal(e,t,r)}beginDraw(){this.defaultContext.beginDraw()}endDraw(){this.defaultContext.endDraw()}drawHandle(e){this.defaultContext.drawHandle(e)}setProjectionMatrix(e){this.defaultContext.setProjectionMatrix(e)}setProjectionPerspective(e,t,r,n){this.defaultContext.setProjectionPerspective(e,t,r,n)}setProjectionOrthographic(e,t,r,n){this.defaultContext.setProjectionOrthographic(e,t,r,n)}setCameraMatrix(e){this.defaultContext.setCameraMatrix(e)}setCameraLookAt(e,t,r,n,a,s,i,o,f){this.defaultContext.setCameraLookAt(e,t,r,n,a,s,i,o,f)}setCameraLookAtFromVector(e,t,r){this.defaultContext.setCameraLookAtFromVector(e,t,r)}setCompositeMode(e){this.defaultContext.setCompositeMode(e)}loadEffect(e,t,r,n,a){return this.defaultContext.loadEffect(e,t,r,n,a)}loadEffectPackage(e,t,r,n,a){return this.defaultContext.loadEffectPackage(e,t,r,n,a)}registerEffects(e){this.defaultContext.registerEffects(e)}preloadEffects(e){return this.defaultContext.preloadEffects(e)}reloadEffects(e){return this.defaultContext.reloadEffects(e)}unloadEffects(e){this.defaultContext.unloadEffects(e)}unregisterEffects(e){this.defaultContext.unregisterEffects(e)}getEffect(e){return this.defaultContext.getEffect(e)}getEffectState(e){return this.defaultContext.getEffectState(e)}getEffectStates(){return this.defaultContext.getEffectStates()}whenEffectsReady(e){return this.defaultContext.whenEffectsReady(e)}playEffect(e,t,r,n){return this.defaultContext.playEffect(e,t,r,n)}releaseEffect(e){this.defaultContext.releaseEffect(e)}play(e,t,r,n){return this.defaultContext.play(e,t,r,n)}stopAll(){this.defaultContext.stopAll()}setResourceLoader(e){this.defaultContext.setResourceLoader(e)}getRestInstancesCount(){return this.defaultContext.getRestInstancesCount()}isVertexArrayObjectSupported(){return this.defaultContext.isVertexArrayObjectSupported()}}})();"undefined"!=typeof globalThis&&(globalThis.effekseer=e),"undefined"!=typeof exports&&(exports=e);
1
+ const e=(()=>{let e={},t={},r=null,n=!1,a=!1,s=null,i=null,o="",f=0,c=[],l=!0,u=0,d=0,p=null;const h=()=>{n&&"function"==typeof t.SetLogEnabled&&t.SetLogEnabled(l&&0===u?1:0)},g=()=>{p||"undefined"==typeof console||"function"!=typeof console.warn||(p=console.warn.bind(console),console.warn=(...e)=>{const t=e[0];d>0&&"string"==typeof t&&t.startsWith("[EffekseerWebGPU] Missing required asset:")||p(...e)}),d+=1,u+=1,h()},m=e=>e instanceof ArrayBuffer?e:ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):null,b=e=>{if("string"!=typeof e||0===e.length)return"";const t=e.replace(/\\/g,"/").split("/"),r=[];for(let e=0;e<t.length;e++){const n=t[e];n&&"."!==n&&(".."!==n?r.push(n):r.length>0&&r.pop())}let n=r.join("/");for(;n.startsWith("/");)n=n.slice(1);return n.replace(/[A-Z]/g,e=>e.toLowerCase())},w="EFWGPKG2",E="__efwgpk__/main_effect_path.txt",y=new Uint8Array([69,102,107,87,103,46,87,101,98,71,80,85,46,67,84,82]);let S=0,v=null;const _=(()=>{const e=new Uint32Array(256);for(let t=0;t<256;t++){let r=t;for(let e=0;e<8;e++)r=1&r?3988292384^r>>>1:r>>>1;e[t]=r>>>0}return e})(),x=e=>{if(!(e instanceof Uint8Array))return 0;let t=4294967295;for(let r=0;r<e.length;r++){const n=255&(t^e[r]);t=t>>>8^_[n]}return~t>>>0},k=async(e,t)=>{const r=await(async()=>{if(v)return v;if(!globalThis.crypto||!globalThis.crypto.subtle||"function"!=typeof globalThis.crypto.subtle.importKey)throw new Error("Web Crypto AES-CTR is required for encrypted efkwgpk payloads");return v=globalThis.crypto.subtle.importKey("raw",y,"AES-CTR",!1,["decrypt"]),v})();return globalThis.crypto.subtle.decrypt({name:"AES-CTR",counter:t,length:128},r,e)},C=e=>String(e||"").replace(/\\/g,"/").split("?")[0].split("#")[0],M=e=>{const t=m(e);if(!t||t.byteLength<8)return"";const r=new Uint8Array(t,0,8);return String.fromCharCode(...r)},R=e=>{const t=new Map,r=e?e.byteLength:0,n=(e=>{const t=e?e.byteLength:0;if(!e||t<64)return null;const r=new DataView(e);if(M(e)!==w)return null;const n=r.getUint32(8,!0),a=r.getUint32(12,!0),s=r.getUint32(16,!0),i=r.getUint32(20,!0),o=r.getUint32(24,!0),f=r.getUint32(28,!0),c=r.getUint32(32,!0),l=r.getUint32(36,!0),u=r.getUint32(40,!0),d=r.getUint32(44,!0),p=r.getUint32(48,!0),h=r.getUint32(52,!0),g=2===s?64:3===s?80:0;if(0===g||n!==g||48!==o)return null;let m=null;if(4&a){if(s<3||t<80)return null;if(m=new Uint8Array(e.slice(56,72)),16!==m.byteLength)return null}return{headerSize:n,globalFlags:a,formatRevision:s,entryCount:i,entryStride:o,entriesOffset:f,stringPoolOffset:c,stringPoolSize:l,payloadOffset:u,payloadSize:d,tocCrc:p,payloadCrc:h,payloadNonce:m,payloadEncrypted:!!(4&a)}})(e);if(!n)return t;const a=new DataView(e),{headerSize:s,entryCount:i,entryStride:o,entriesOffset:f,stringPoolOffset:c,stringPoolSize:l,payloadOffset:u,payloadSize:d,tocCrc:p,payloadCrc:h}=n,g=BigInt(i)*BigInt(o);if(g>BigInt(r))return t;const m=Number(g);if(!I(f,m,r))return t;if(!I(c,l,r))return t;if(!I(u,d,r))return t;const E=c+l,y=u+d,S=new Uint8Array(e,0,s).slice();S.fill(0,48,56);const v=new Uint8Array(s+m+l);if(v.set(S,0),v.set(new Uint8Array(e,f,m),s),v.set(new Uint8Array(e,c,l),s+m),x(v)!==p>>>0)return t;const _=new Uint8Array(e,u,d);if(x(_)!==h>>>0)return t;const k=new TextDecoder("utf-8");for(let n=0;n<i;n++){const s=f+n*o,i=a.getUint32(s+8,!0),l=a.getUint32(s+12,!0),d=a.getUint32(s+16,!0),p=a.getUint32(s+20,!0),h=a.getUint32(s+24,!0),g=a.getUint32(s+28,!0),m=a.getUint32(s+32,!0),w=a.getUint32(s+36,!0);if(!I(i,l,r))continue;if(i<c||i+l>E)continue;if(!I(p,h,r))continue;if(p<u||p+h>y)continue;let S="";try{S=k.decode(new Uint8Array(e,i,l))}catch{continue}const v=b(S);if(!v)continue;const _={index:n,path:S,normalizedPath:v,flags:d,payloadOffset:p,packedSize:h,rawSize:g,packedCrc:m,rawCrc:w},x=t.get(v);x?x.push(_):t.set(v,[_])}return t._efwgpkMeta={payloadOffset:u,payloadSize:d,payloadEncrypted:n.payloadEncrypted,payloadNonce:n.payloadNonce,decryptedPayloadPromise:null},t},P=async e=>{const t=globalThis.fflate;if(t&&"function"==typeof t.unzlibSync){const r=t.unzlibSync(new Uint8Array(e));return m(r)}if("function"!=typeof DecompressionStream)throw new Error("No zlib inflate backend available for efkwgpk payload");const r=new DecompressionStream("deflate"),n=r.writable.getWriter();await n.write(e),await n.close();return await new Response(r.readable).arrayBuffer()},L=async(e,t,r)=>{const n=t&&t._efwgpkMeta?t._efwgpkMeta:null;if(!n||!n.payloadEncrypted)return new Uint8Array(e,r.payloadOffset,r.packedSize);if(!n.decryptedPayloadPromise){const t=new Uint8Array(e,n.payloadOffset,n.payloadSize);n.decryptedPayloadPromise=k(t,n.payloadNonce).then(e=>new Uint8Array(e))}const a=await n.decryptedPayloadPromise,s=r.payloadOffset-n.payloadOffset;return s<0||s+r.packedSize>a.byteLength?null:a.subarray(s,s+r.packedSize)},A=async(e,t,r)=>{const n=b(r);if(!n||!e||!t||0===t.size)return null;const a=t.get(n);if(!a||0===a.length)return null;for(let r=0;r<a.length;r++){const n=a[r];if(!I(n.payloadOffset,n.packedSize,e.byteLength))continue;const s=await L(e,t,n);if(s&&x(s)===n.packedCrc>>>0){if(0===n.flags&&n.packedSize===n.rawSize){const e=s.slice();if(x(e)!==n.rawCrc>>>0)continue;return e.buffer}if(1===n.flags){const e=await P(s);if(!e||e.byteLength!==n.rawSize)continue;if(x(new Uint8Array(e))!==n.rawCrc>>>0)continue;return e}}}return null},U=e=>e&&Number.isFinite(e.payloadOffset)&&Number.isFinite(e.packedSize)&&Number.isFinite(e.rawSize)&&Number.isFinite(e.flags)?`${e.flags}:${e.payloadOffset}:${e.packedSize}:${e.rawSize}`:"",D=(e,t,r)=>{const n=b(r);if(!n||!e||!t||0===t.size)return null;const a=t.get(n);if(!a||0===a.length)return null;for(let t=0;t<a.length;t++){const r=a[t];if(I(r.payloadOffset,r.packedSize,e.byteLength)){if(0===r.flags&&r.packedSize===r.rawSize)return r;if(1===r.flags)return r}}return null},I=(e,t,r)=>!!(Number.isFinite(e)&&Number.isFinite(t)&&Number.isFinite(r))&&(!(e<0||t<0||r<0)&&(!(e>r)&&t<=r-e)),F=(e,t,r)=>{const n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=()=>{const a=0|n.status;a>=200&&a<300||0===a?t(n.response):r&&r("not found",e)},n.onerror=()=>{r&&r("not found",e)},n.send(null)},T=e=>{try{const t=new XMLHttpRequest;t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null);const r=0|t.status;if(r>=200&&r<300||0===r)return t.response}catch{}return null},O=e=>{"function"==typeof e&&("function"==typeof queueMicrotask?queueMicrotask(e):Promise.resolve().then(e))},z=(e,t)=>{const r=String(e||"").replace(/\\/g,"/");const n=Number(t);return`${r}::${Number.isFinite(n)?n:1}`},B=e=>{e&&e.context&&e._cacheKey&&e.context._effectCache&&e.context._effectCache.get(e._cacheKey)===e&&e.context._effectCache.delete(e._cacheKey)},j=e=>e?{id:e.id,path:e.path,scale:e.scale,enabled:e.enabled,status:e.status,effect:"loaded"===e.status?e.effect:null,errorMessage:e.errorMessage,errorPath:e.errorPath,loadPromise:e.loadPromise,activeHandles:new Set(e.activeHandles),ownedResourceAliases:e.ownedResourceAliases.slice()}:null,W=(e,t,r)=>{if(e&&("function"==typeof t&&(e.isLoaded?O(()=>t()):e._loadFailed||e._onloadListeners.push(t)),"function"==typeof r))if(e._loadFailed){const t=e._loadErrorMessage||"failed to load effect",n=e._loadErrorPath||"";O(()=>r(t,n))}else e.isLoaded||e._onerrorListeners.push(r)},H=(e,t,r="")=>{if(!e||e._loadFailed)return;e._loadFailed=!0,e._loadErrorMessage=String(t||"failed to load effect"),e._loadErrorPath=String(r||""),B(e);const n=e._onerrorListeners.slice();e._onloadListeners.length=0,e._onerrorListeners.length=0;for(let t=0;t<n.length;t++){const r=n[t];O(()=>r(e._loadErrorMessage,e._loadErrorPath))}};let V=(e,t,r)=>{F(e,t,r)};const G={ptr:0,capacity:0},N=(t,r)=>{const n=t instanceof Float32Array?t:new Float32Array(t);if(n.length<=0)return void r(0);const a=((s=n.length)<=G.capacity&&0!==G.ptr||(0!==G.ptr&&(e._free(G.ptr),G.ptr=0,G.capacity=0),G.ptr=e._malloc(4*s),G.capacity=s),G.ptr);var s;e.HEAPF32.set(n,a>>2),r(a)},$=Object.freeze({rgba8unorm:22,"rgba8unorm-srgb":23,bgra8unorm:27,"bgra8unorm-srgb":28,rgba16float:40,depth24plus:46,"depth24plus-stencil8":47,depth32float:48}),q=(Object.freeze(Object.fromEntries(Object.entries($).map(([e,t])=>[t,e]))),e=>{if("number"==typeof e&&Number.isFinite(e))return 0|e;if("string"!=typeof e)return null;const t=e.trim().toLowerCase();return t&&Object.prototype.hasOwnProperty.call($,t)?$[t]:null}),K=async i=>{if(n)return;if(a)return void await new Promise((e,t)=>{c.push(r=>r?e():t(new Error("Runtime initialization failed.")))});if(a=!0,"undefined"==typeof effekseer_webgpu_native)throw a=!1,new Error("effekseer_webgpu_native is not loaded.");const o={};"string"==typeof i&&i.length>0&&(o.locateFile=e=>e.endsWith(".wasm")?i:e),s&&(o.preinitializedWebGPUDevice=s);const f=effekseer_webgpu_native(o);e=f instanceof Promise?await f:f,!s&&e?.preinitializedWebGPUDevice&&(s=e.preinitializedWebGPUDevice),s&&(e.preinitializedWebGPUDevice=s),(()=>{t={InitInternal:e.cwrap("EffekseerInitInternal","number",["number","number","string","number","number"]),InitExternal:e.cwrap("EffekseerInitExternal","number",["number","number","number","number"]),Init:e.cwrap("EffekseerInit","number",["number","number","string","number","number","number"]),Terminate:e.cwrap("EffekseerTerminate","void",["number"]),Update:e.cwrap("EffekseerUpdate","void",["number","number"]),BeginUpdate:e.cwrap("EffekseerBeginUpdate","void",["number"]),EndUpdate:e.cwrap("EffekseerEndUpdate","void",["number"]),UpdateHandle:e.cwrap("EffekseerUpdateHandle","void",["number","number","number"]),Draw:e.cwrap("EffekseerDraw","void",["number"]),DrawExternal:e.cwrap("EffekseerDrawExternal","void",["number"]),BeginDraw:e.cwrap("EffekseerBeginDraw","void",["number"]),EndDraw:e.cwrap("EffekseerEndDraw","void",["number"]),DrawHandle:e.cwrap("EffekseerDrawHandle","void",["number","number"]),SetProjectionMatrix:e.cwrap("EffekseerSetProjectionMatrix","void",["number","number"]),SetProjectionPerspective:e.cwrap("EffekseerSetProjectionPerspective","void",["number","number","number","number","number"]),SetProjectionOrthographic:e.cwrap("EffekseerSetProjectionOrthographic","void",["number","number","number","number","number"]),SetCameraMatrix:e.cwrap("EffekseerSetCameraMatrix","void",["number","number"]),SetCameraLookAt:e.cwrap("EffekseerSetCameraLookAt","void",["number","number","number","number","number","number","number","number","number","number"]),LoadEffect:e.cwrap("EffekseerLoadEffect","number",["number","number","number","number"]),ReleaseEffect:e.cwrap("EffekseerReleaseEffect","void",["number","number"]),ReloadResources:e.cwrap("EffekseerReloadResources","void",["number","number","number","number"]),StopAllEffects:e.cwrap("EffekseerStopAllEffects","void",["number"]),PlayEffect:e.cwrap("EffekseerPlayEffect","number",["number","number","number","number","number"]),StopEffect:e.cwrap("EffekseerStopEffect","void",["number","number"]),StopRoot:e.cwrap("EffekseerStopRoot","void",["number","number"]),Exists:e.cwrap("EffekseerExists","number",["number","number"]),SetFrame:e.cwrap("EffekseerSetFrame","void",["number","number","number"]),SetLocation:e.cwrap("EffekseerSetLocation","void",["number","number","number","number","number"]),SetRotation:e.cwrap("EffekseerSetRotation","void",["number","number","number","number","number"]),SetScale:e.cwrap("EffekseerSetScale","void",["number","number","number","number","number"]),SetMatrix:e.cwrap("EffekseerSetMatrix","void",["number","number","number"]),SetAllColor:e.cwrap("EffekseerSetAllColor","void",["number","number","number","number","number","number"]),SetTargetLocation:e.cwrap("EffekseerSetTargetLocation","void",["number","number","number","number","number"]),GetDynamicInput:e.cwrap("EffekseerGetDynamicInput","number",["number","number","number"]),SetDynamicInput:e.cwrap("EffekseerSetDynamicInput","void",["number","number","number","number"]),SendTrigger:e.cwrap("EffekseerSendTrigger","void",["number","number","number"]),SetPaused:e.cwrap("EffekseerSetPaused","void",["number","number","number"]),SetShown:e.cwrap("EffekseerSetShown","void",["number","number","number"]),SetSpeed:e.cwrap("EffekseerSetSpeed","void",["number","number","number"]),SetRandomSeed:e.cwrap("EffekseerSetRandomSeed","void",["number","number","number"]),SetCompositeMode:e.cwrap("EffekseerSetCompositeMode","void",["number","number"]),GetRestInstancesCount:e.cwrap("EffekseerGetRestInstancesCount","number",["number"]),DrawExternalBack:e.cwrap("EffekseerDrawExternalBack","void",["number"]),DrawExternalFront:e.cwrap("EffekseerDrawExternalFront","void",["number"]),IsVertexArrayObjectSupported:e.cwrap("EffekseerIsVertexArrayObjectSupported","number",["number"]),SetRestorationOfStatesFlag:e.cwrap("EffekseerSetRestorationOfStatesFlag","void",["number","number"]),CaptureBackground:e.cwrap("EffekseerCaptureBackground","void",["number","number","number","number","number"]),ResetBackground:e.cwrap("EffekseerResetBackground","void",["number"]),SetLogEnabled:e.cwrap("EffekseerSetLogEnabled","void",["number"]),SetDepthTexture:e.cwrap("EffekseerSetDepthTexture","void",["number","number"]),SetBackgroundTexture:e.cwrap("EffekseerSetBackgroundTexture","void",["number","number"])},e.resourcesMap={},e._loadBinary=(t,n)=>{const a=r;if(!a)return null;let s=a.resources.find(e=>e.path===t);if(s)return s.isLoaded?s.buffer:null;s={path:t,isLoaded:!1,buffer:null,isRequired:!!n},a.resources.push(s);const i=e=>String(e||"").replace(/\\/g,"/"),o=e=>{const t=i(e);let r=t.startsWith("/")||/^[a-zA-Z]+:\/\//.test(t)?t:(a.baseDir||"")+t;return a.redirect&&(r=a.redirect(r)),r},f=(e=>{const t=i(e),r=[],n=new Set,a=e=>{e&&!n.has(e)&&(n.add(e),r.push(e))},s=e=>{if(!e||e.includes("/"))return;const t=e.toLowerCase();(t.endsWith(".png")||t.endsWith(".jpg")||t.endsWith(".jpeg")||t.endsWith(".dds"))&&a(`Texture/${e}`),(t.endsWith(".efkmodel")||t.endsWith(".mqo"))&&a(`Model/${e}`)},o=t.indexOf("/");if(o>0){const e=t.slice(0,o).toLowerCase();(e.endsWith(".efk")||e.endsWith(".efkefc")||e.endsWith(".efkproj"))&&a(t.slice(o+1))}a(t),s(t);let f=t.indexOf("/");for(;f>=0;){const e=t.slice(f+1);a(e),s(e),f=t.indexOf("/",f+1)}return r})(t);if(a.syncResourceLoad){for(let r=0;r<f.length;r++){const n=f[r],a=o(n),i=e.resourcesMap[a]||e.resourcesMap[n]||e.resourcesMap[t];if(null!=i)return s.buffer=i,s.isLoaded=!0,i;const c=T(a);if(null!=c)return s.buffer=c,s.isLoaded=!0,e.resourcesMap[a]=c,e.resourcesMap[n]=c,c}return s.buffer=null,s.isLoaded=!0,null}for(let r=0;r<f.length;r++){const n=f[r],i=o(n),c=e.resourcesMap[i]||e.resourcesMap[n]||e.resourcesMap[t];if(null!=c)return s.buffer=c,s.isLoaded=!0,Promise.resolve().then(()=>a._update()),null}let c=0;const l=()=>{if(c>=f.length)return s.buffer=null,s.isLoaded=!0,void a._update();const e=f[c++],t=o(e);V(t,e=>{if(null!=e)return s.buffer=e,s.isLoaded=!0,void a._update();l()},()=>{l()})};return l(),null},n=!0,a=!1,h();const s=c;c=[],s.forEach(e=>e(!0))})()};class X{constructor(e){this.context=e,this.nativeptr=0,this.baseDir="",this.syncResourceLoad=!1,this.isLoaded=!1,this.scale=1,this.resources=[],this.mainBuffer=null,this.onload=null,this.onerror=null,this._onloadListeners=[],this._onerrorListeners=[],this._loadFailed=!1,this._loadErrorMessage="",this._loadErrorPath="",this._cacheKey="",this.redirect=null,this.packageOnly=!1,this._ownedResourceAliases=[],this._managedRefIds=new Set,this._asyncResourceLogSuppressed=!1}_beginAsyncResourceLogSuppression(){this._asyncResourceLogSuppressed||(this._asyncResourceLogSuppressed=!0,g())}_endAsyncResourceLogSuppression(){this._asyncResourceLogSuppressed&&(this._asyncResourceLogSuppressed=!1,d>0&&(d-=1),u>0&&(u-=1),h())}_load(n){const a=m(n);if(!a)return void H(this,"invalid data","");this.syncResourceLoad||this._beginAsyncResourceLogSuppression(),r=this,this.mainBuffer=a;const s=e._malloc(a.byteLength);e.HEAPU8.set(new Uint8Array(a),s),this.nativeptr=t.LoadEffect(this.context.nativeptr,s,a.byteLength,this.scale),e._free(s),r=null,this._update()}_reload(){if(!this.mainBuffer||!this.nativeptr)return;r=this;const n=e._malloc(this.mainBuffer.byteLength);e.HEAPU8.set(new Uint8Array(this.mainBuffer),n),t.ReloadResources(this.context.nativeptr,this.nativeptr,n,this.mainBuffer.byteLength),e._free(n),r=null}_update(){let e=!1;const t=[];for(let r=0;r<this.resources.length;r++){const n=this.resources[r];if(!n.isLoaded){e=!0;break}n.isRequired&&null==n.buffer&&t.push(n.path)}if(e)return;this._endAsyncResourceLogSuppression(),t.length>0&&console.warn(`[EffekseerWebGPU] missing required resources ignored: ${t.join(", ")}`);const r=0!==this.nativeptr;if(!r){const e=t.length>0?`failed to load effect. missing resources: ${t.join(", ")}`:"failed to load effect";return void H(this,e,this.baseDir||"")}r&&this.resources.length>0&&this._reload(),!this.isLoaded&&r&&(this.isLoaded=!0,(e=>{if(!e)return;const t=e._onloadListeners.slice();e._onloadListeners.length=0,e._onerrorListeners.length=0;for(let e=0;e<t.length;e++){const r=t[e];O(()=>r())}})(this))}}const Z=(t,r,n,a,s,i,o,f=null)=>{const c=f||new X(t);c.scale=a,c._ownedResourceAliases=[],W(c,s,i);const l=R(r);if(0===l.size)return H(c,"invalid data. expected efkwgpk package",n||""),c;const u=(()=>{if("string"!=typeof n||0===n.length)return"";const e=C(n),t=e.lastIndexOf("/");return t>=0?e.slice(0,t+1):""})(),d=u.toLowerCase(),p=`efwgpk://${++S}/`,h=new Map;return c.baseDir=u,c.syncResourceLoad=!0,c.packageOnly=!0,c.redirect=e=>{const t=C(e),r=[];d&&t.toLowerCase().startsWith(d)&&r.push(t.slice(u.length)),r.push(t);for(let e=0;e<r.length;e++){const t=b(r[e]);if(!t)continue;const n=h.get(t);if(n)return n}return e},(async()=>{try{const t=await(async(e,t)=>{const r=await A(e,t,E);if(r)try{const e=new TextDecoder("utf-8").decode(new Uint8Array(r)).replace(/\0+$/,""),t=b(e);if(t)return t}catch{}for(const[e,r]of t.entries())if(e.endsWith(".efkwg")&&r&&r.length>0)return e;return""})(r,l);if(!t)throw new Error("main effect path not found in efkwgpk package");const a=await A(r,l,t),s=String.fromCharCode(...new Uint8Array(a||new ArrayBuffer(0),0,Math.min(4,a?a.byteLength:0)));if(!a||"EFWG"!==s&&"SKFE"!==s)throw new Error("main effect inside efkwgpk is not a valid .efkwg");const i=new Map,o=new Map;for(const[n]of l.entries()){if(n===t||n===b(E))continue;const a=D(r,l,n);if(!a)continue;const s=U(a);if(!s)continue;let f=i.get(s);if(!f){let t=o.get(s);if(void 0===t&&(t=await A(r,l,n),o.set(s,t||null)),!t)continue;f=`${p}__payload/${i.size}`,e.resourcesMap[f]=t,i.set(s,f)}h.set(n,f)}c._ownedResourceAliases=Array.from(i.values()),c._load(a),c.nativeptr||H(c,"failed to load effect from efkwgpk package",n||t)}catch(e){H(c,e&&e.message?e.message:"failed to load effect from efkwgpk package",n||"")}})(),c};class J{constructor(e,t){this.context=e,this.native=t}stop(){t.StopEffect(this.context.nativeptr,this.native)}stopRoot(){t.StopRoot(this.context.nativeptr,this.native)}get exists(){return!!t.Exists(this.context.nativeptr,this.native)}setFrame(e){t.SetFrame(this.context.nativeptr,this.native,e)}setLocation(e,r,n){t.SetLocation(this.context.nativeptr,this.native,e,r,n)}setRotation(e,r,n){t.SetRotation(this.context.nativeptr,this.native,e,r,n)}setScale(e,r,n){t.SetScale(this.context.nativeptr,this.native,e,r,n)}setAllColor(e,r,n,a){t.SetAllColor(this.context.nativeptr,this.native,e,r,n,a)}setTargetLocation(e,r,n){t.SetTargetLocation(this.context.nativeptr,this.native,e,r,n)}getDynamicInput(e){return t.GetDynamicInput(this.context.nativeptr,this.native,e)}setDynamicInput(e,r){t.SetDynamicInput(this.context.nativeptr,this.native,e,r)}sendTrigger(e){t.SendTrigger(this.context.nativeptr,this.native,e)}setPaused(e){t.SetPaused(this.context.nativeptr,this.native,e?1:0)}setShown(e){t.SetShown(this.context.nativeptr,this.native,e?1:0)}setSpeed(e){t.SetSpeed(this.context.nativeptr,this.native,e)}setRandomSeed(e){t.SetRandomSeed(this.context.nativeptr,this.native,e)}setMatrix(e){N(e,e=>t.SetMatrix(this.context.nativeptr,this.native,e))}}class Q{constructor(){this.nativeptr=0,this._effectCache=new Map,this._registeredEffects=new Map,this._registeredEffectStates=new Map,this.fixedUpdateStepFrames=1,this.fixedUpdateMaxSubsteps=4,this.fixedUpdateAccumulator=0,this.externalRenderPassEnabled=!1}_normalizeManagedEffectDescriptor(e,t){const r=String(e||"").trim();if(!r)throw new Error("registerEffects() requires non-empty effect ids.");let n=null;if("string"==typeof t)n={path:t};else{if(!t||"object"!=typeof t||Array.isArray(t))throw new Error(`registerEffects() entry "${r}" must be a string path or config object.`);n=t}const a=String(n.path||"").trim();if(!a)throw new Error(`registerEffects() entry "${r}" requires a non-empty path.`);const s=Number(n.scale);return{id:r,path:a,scale:Number.isFinite(s)?s:1,enabled:!1!==n.enabled}}_createManagedEffectState(e){return{id:e.id,path:e.path,scale:e.scale,enabled:e.enabled,status:"unloaded",effect:null,errorMessage:"",errorPath:"",loadPromise:null,activeHandles:new Set,ownedResourceAliases:[],_generation:0,_loadingEffect:null}}_resolveManagedEffectIds(e,t=!1){if(null==e){const e=[];for(const[r,n]of this._registeredEffectStates.entries())t&&!n.enabled||e.push(r);return e}const r=Array.isArray(e)?e:[e],n=[],a=new Set;for(let e=0;e<r.length;e++){const t=String(r[e]||"").trim();t&&!a.has(t)&&(a.add(t),n.push(t))}return n}_registerManagedEffectReference(e,t){e&&(e._managedRefIds instanceof Set||(e._managedRefIds=new Set),e._managedRefIds.add(t))}_releaseManagedEffectReference(e,t){e&&e._managedRefIds instanceof Set&&e._managedRefIds.delete(t)}_releaseManagedEffectIfUnused(r){if(!r)return;const n=r._managedRefIds instanceof Set?r._managedRefIds:null;n&&n.size>0||(B(r),(t=>{if(t&&e.resourcesMap)for(let r=0;r<t.length;r++){const n=t[r];"string"==typeof n&&0!==n.length&&delete e.resourcesMap[n]}})(r._ownedResourceAliases),r._ownedResourceAliases=[],r._endAsyncResourceLogSuppression?.(),this.nativeptr&&r.nativeptr&&(t.ReleaseEffect(this.nativeptr,r.nativeptr),r.nativeptr=0))}_stopManagedHandles(e){if(e){for(const t of e.activeHandles)try{t?.stopRoot?.()}catch{}e.activeHandles.clear()}}_cleanupManagedHandles(){for(const e of this._registeredEffectStates.values())if(e&&0!==e.activeHandles.size)for(const t of Array.from(e.activeHandles))t&&!1!==t.exists||e.activeHandles.delete(t)}_resetManagedEffectStateToUnloaded(e){e&&(e.effect=null,e.status="unloaded",e.errorMessage="",e.errorPath="",e.loadPromise=null,e.ownedResourceAliases=[],e._loadingEffect=null)}_loadRegisteredEffectState(e){if(!e||!this.nativeptr)return Promise.resolve(null);const t=this._registeredEffects.get(e.id);if(!t)return Promise.resolve(null);const r=e._generation+1;e._generation=r,e.status="loading",e.errorMessage="",e.errorPath="",e.effect=null,e.ownedResourceAliases=[],e._loadingEffect=null;const n=new Promise(n=>{let a=!1,s=null;const i=s=>{if(a)return;a=!0;return this._registeredEffectStates.get(e.id)!==e||e._generation!==r?(this._releaseManagedEffectIfUnused(s),void n(null)):(e._loadingEffect=null,e.loadPromise=null,s&&s.isLoaded?(e.effect=s,e.status="loaded",e.errorMessage="",e.errorPath="",e.ownedResourceAliases=Array.isArray(s._ownedResourceAliases)?s._ownedResourceAliases.slice():[],void n(s)):(e.status="failed",e.errorMessage="failed to load effect",e.errorPath=t.path,void n(null)))},o=(i,o="")=>{if(a)return;a=!0,s&&this._releaseManagedEffectReference(s,e.id);if(this._registeredEffectStates.get(e.id)!==e||e._generation!==r)return s&&this._releaseManagedEffectIfUnused(s),void n(null);e._loadingEffect=null,e.loadPromise=null,e.effect=null,e.status="failed",e.errorMessage=String(i||"failed to load effect"),e.errorPath=String(o||t.path||""),e.ownedResourceAliases=[],s&&this._releaseManagedEffectIfUnused(s),n(null)};try{s=this.loadEffect(t.path,t.scale,()=>i(s),(e,t)=>o(e,t))}catch(e){return void o(e&&e.message?e.message:"failed to load effect",t.path)}e._loadingEffect=s,s?(this._registerManagedEffectReference(s,e.id),s.isLoaded?i(s):s._loadFailed&&o(s._loadErrorMessage,s._loadErrorPath)):o("failed to create effect",t.path)});return e.loadPromise=n,n}_prepareInitSettings(e={},t=!1){const r=e.instanceMaxCount||4e3,n=e.squareMaxCount||1e4,a=!1!==e.linearColorSpace?1:0,s=e.compositeWithBackground?1:0;return this.externalRenderPassEnabled=t,this.fixedUpdateAccumulator=0,{instanceMaxCount:r,squareMaxCount:n,linearColorSpace:a,compositeWithBackground:s}}_finishContextInit(e={}){return this.nativeptr&&e.effects&&(this.registerEffects(e.effects),this.preloadEffects()),!!this.nativeptr}init(e,r={}){if(!0===r.externalRenderPass)return this.initExternal(r);let n="#canvas";"string"==typeof e?n=e.startsWith("#")?e:`#${e}`:"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement&&(e.id||(f+=1,e.id=`effekseer_webgpu_canvas_${f}`),n=`#${e.id}`);const a=this._prepareInitSettings(r,!1);return this.nativeptr=t.InitInternal(a.instanceMaxCount,a.squareMaxCount,n,a.linearColorSpace,a.compositeWithBackground),this._finishContextInit(r)}initExternal(e={}){const r=this._prepareInitSettings(e,!0);return this.nativeptr=t.InitExternal(r.instanceMaxCount,r.squareMaxCount,r.linearColorSpace,r.compositeWithBackground),this._finishContextInit(e)}update(e=1){const r=Number(e);if(!Number.isFinite(r)||r<=0)return void this._cleanupManagedHandles();this.fixedUpdateAccumulator+=r;let n=0;for(;this.fixedUpdateAccumulator>=this.fixedUpdateStepFrames&&n<this.fixedUpdateMaxSubsteps;)t.Update(this.nativeptr,this.fixedUpdateStepFrames),this.fixedUpdateAccumulator-=this.fixedUpdateStepFrames,n++;n>=this.fixedUpdateMaxSubsteps&&this.fixedUpdateAccumulator>=this.fixedUpdateStepFrames&&(this.fixedUpdateAccumulator=0),this._cleanupManagedHandles()}beginUpdate(){t.BeginUpdate(this.nativeptr)}endUpdate(){t.EndUpdate(this.nativeptr)}updateHandle(e,r=1){t.UpdateHandle(this.nativeptr,e.native,r)}draw(){this.externalRenderPassEnabled||t.Draw(this.nativeptr)}drawExternal(r,n=null,a="all"){if(!r)return;const s=q(n&&n.colorFormat),i=(()=>{const e=q(n&&n.depthFormat);return null===e?0:e})(),o=(e=>{const t=Number(e);return!Number.isFinite(t)||t<=0?1:Math.max(1,Math.floor(t))})(n&&n.sampleCount),f=(e,t)=>!!e&&Object.prototype.hasOwnProperty.call(e,t),c=f(n,"depthTextureView")||f(n,"importDepthTextureView"),l=f(n,"backgroundTextureView")||f(n,"importBackgroundTextureView"),u=c?f(n,"depthTextureView")?n.depthTextureView:n.importDepthTextureView:null,d=l?f(n,"backgroundTextureView")?n.backgroundTextureView:n.importBackgroundTextureView:null,p=c?e.__effekseerDepthTextureView:null,h=l?e.__effekseerBackgroundTextureView:null;e.__effekseerExternalRenderPass=r,e.__effekseerExternalPassColorFormat=s,e.__effekseerExternalPassDepthFormat=i,e.__effekseerExternalPassSampleCount=o,c&&(e.__effekseerDepthTextureView=u||null),l&&(e.__effekseerBackgroundTextureView=d||null);const g="back"===a?"back":"front"===a?"front":"all";try{"back"===g?t.DrawExternalBack(this.nativeptr):"front"===g?t.DrawExternalFront(this.nativeptr):t.DrawExternal(this.nativeptr)}finally{c&&(e.__effekseerDepthTextureView=p||null),l&&(e.__effekseerBackgroundTextureView=h||null),e.__effekseerExternalRenderPass=null,e.__effekseerExternalPassColorFormat=null,e.__effekseerExternalPassDepthFormat=null,e.__effekseerExternalPassSampleCount=null}}beginDraw(){t.BeginDraw(this.nativeptr)}endDraw(){t.EndDraw(this.nativeptr)}drawHandle(e){t.DrawHandle(this.nativeptr,e.native)}setProjectionMatrix(e){N(e,e=>t.SetProjectionMatrix(this.nativeptr,e))}setProjectionPerspective(e,r,n,a){t.SetProjectionPerspective(this.nativeptr,e,r,n,a)}setProjectionOrthographic(e,r,n,a){t.SetProjectionOrthographic(this.nativeptr,e,r,n,a)}setCameraMatrix(e){N(e,e=>t.SetCameraMatrix(this.nativeptr,e))}setCameraLookAt(e,r,n,a,s,i,o,f,c){t.SetCameraLookAt(this.nativeptr,e,r,n,a,s,i,o,f,c)}setCameraLookAtFromVector(e,t,r={x:0,y:1,z:0}){this.setCameraLookAt(e.x,e.y,e.z,t.x,t.y,t.z,r.x,r.y,r.z)}setCompositeMode(e){t.SetCompositeMode(this.nativeptr,e?1:0)}loadEffect(e,t=1,r,n,a){const s="function"==typeof t?1:t,i="function"==typeof t?t:r,o="function"==typeof t?r:n,f=a;let c=null;if("string"==typeof e&&null==f){c=z(e,s);const t=this._effectCache.get(c);if(t)return W(t,i,o),t}const l=new X(this);l.scale=s,l.redirect=f,l._cacheKey=c||"",W(l,i,o),c&&this._effectCache.set(c,l);const u=(e,t="")=>(H(l,e,t),l);if("string"==typeof e)return"string"==typeof(d=e)&&0!==d.length&&d.replace(/\\/g,"/").split("?")[0].split("#")[0].toLowerCase().endsWith(".efkwg")?(F(e,t=>{const r=m(t);if(!r)return void u("failed to fetch efkwg effect",e);const n=e.replace(/\\/g,"/").split("?")[0].split("#")[0],a=n.lastIndexOf("/");l.baseDir=a>=0?n.slice(0,a+1):"",l.syncResourceLoad=!1,l._load(r),l.nativeptr||u("failed to load efkwg effect",e)},()=>{u("failed to fetch efkwg effect",e)}),l):(e=>"string"==typeof e&&0!==e.length&&C(e).toLowerCase().endsWith(".efkwgpk"))(e)?(F(e,t=>{const r=m(t);r?Z(this,r,e,s,null,null,0,l):u("failed to fetch efkwgpk package",e)},()=>{u("failed to fetch efkwgpk package",e)}),l):u("unsupported effect format. expected .efkwg or .efkwgpk",e);var d;const p=m(e);if(!p)return u("invalid data. expected efkwg or efkwgpk bytes","");if(M(p)===w)return Z(this,p,"",s,null,null,0,l);const h=String.fromCharCode(...new Uint8Array(p,0,Math.min(4,p.byteLength)));return"EFWG"===h||"SKFE"===h?(l._load(p),l.nativeptr?l:u("failed to load efkwg effect","")):u("invalid data. expected efkwg or efkwgpk bytes","")}loadEffectPackage(e,t,r=1,n,a){let s=r,i=n,o=a;return"function"==typeof r&&(s=1,i=r,o=n),this.loadEffect(e,s,i,o)}registerEffects(e){if(!e||"object"!=typeof e||Array.isArray(e))throw new Error("registerEffects() expects an object map of effect ids to paths/configs.");const t=[];for(const[r,n]of Object.entries(e)){if(this._registeredEffects.has(r))throw new Error(`registerEffects() duplicate id "${r}".`);t.push(this._normalizeManagedEffectDescriptor(r,n))}for(let e=0;e<t.length;e++){const r=t[e];if(this._registeredEffects.has(r.id))throw new Error(`registerEffects() duplicate id "${r.id}".`)}for(let e=0;e<t.length;e++){const r=t[e];this._registeredEffects.set(r.id,r),this._registeredEffectStates.set(r.id,this._createManagedEffectState(r))}if(this.nativeptr)for(let e=0;e<t.length;e++){const r=t[e];r.enabled&&this.preloadEffects([r.id])}}preloadEffects(e){const t=this._resolveManagedEffectIds(e,null==e);return Promise.all(t.map(async e=>{const t=this._registeredEffectStates.get(e);return t?"loaded"===t.status&&t.effect?.isLoaded?[e,t.effect]:"loading"===t.status&&t.loadPromise?[e,await t.loadPromise]:[e,await this._loadRegisteredEffectState(t)]:[e,null]})).then(e=>new Map(e))}reloadEffects(e){const t=this._resolveManagedEffectIds(e,null==e);return this.unloadEffects(t),this.preloadEffects(t)}unloadEffects(e){const t=this._resolveManagedEffectIds(e);for(let e=0;e<t.length;e++){const r=t[e],n=this._registeredEffectStates.get(r);if(!n)continue;n._generation+=1,this._stopManagedHandles(n);const a=n._loadingEffect;a&&(this._releaseManagedEffectReference(a,r),this._releaseManagedEffectIfUnused(a));const s=n.effect;s&&(this._releaseManagedEffectReference(s,r),this._releaseManagedEffectIfUnused(s)),this._resetManagedEffectStateToUnloaded(n)}}unregisterEffects(e){const t=this._resolveManagedEffectIds(e);this.unloadEffects(t);for(let e=0;e<t.length;e++){const r=t[e];this._registeredEffects.delete(r),this._registeredEffectStates.delete(r)}}getEffect(e){const t=this._registeredEffectStates.get(String(e||""));return"loaded"===t?.status&&t.effect?.isLoaded?t.effect:null}getEffectState(e){return j(this._registeredEffectStates.get(String(e||"")))}getEffectStates(){return Array.from(this._registeredEffectStates.values(),e=>j(e))}whenEffectsReady(e){return this.preloadEffects(e)}playEffect(e,t=0,r=0,n=0){const a=this._registeredEffectStates.get(String(e||""));if(!a||"loaded"!==a.status||!a.effect?.isLoaded)return null;const s=this.play(a.effect,t,r,n);return s&&a.activeHandles.add(s),s}releaseEffect(e){e&&e.nativeptr&&(e._endAsyncResourceLogSuppression?.(),B(e),t.ReleaseEffect(this.nativeptr,e.nativeptr),e.nativeptr=0)}play(e,r=0,n=0,a=0){if(!e||!e.isLoaded)return null;const s=t.PlayEffect(this.nativeptr,e.nativeptr,r,n,a);return s>=0?new J(this,s):null}stopAll(){t.StopAllEffects(this.nativeptr)}setResourceLoader(e){V=e}getRestInstancesCount(){return t.GetRestInstancesCount(this.nativeptr)}isVertexArrayObjectSupported(){return!!t.IsVertexArrayObjectSupported(this.nativeptr)}setRestorationOfStatesFlag(e){t.SetRestorationOfStatesFlag(this.nativeptr,e?1:0)}captureBackground(e,r,n,a){t.CaptureBackground(this.nativeptr,e,r,n,a)}resetBackground(){t.ResetBackground(this.nativeptr)}}return new class{async initRuntime(e,t,r){try{await K(e),t&&t()}catch(e){a=!1,n=!1,c=[],r?r(e):console.error(e)}}createContext(){return n?new Q:null}releaseContext(e){e&&e.nativeptr&&(e.unloadEffects?.(),t.Terminate(e.nativeptr),e.nativeptr=0,e._effectCache?.clear?.(),e._registeredEffects?.clear?.(),e._registeredEffectStates?.clear?.())}setLogEnabled(e){l=!!e,h()}setImageCrossOrigin(e){o=e}setWebGPUDevice(e){if(n||a)throw new Error("setWebGPUDevice() must be called before initRuntime().");if(null==e)return i=null,void(s=null);if("object"!=typeof e||"function"!=typeof e.createCommandEncoder||!e.queue)throw new Error("setWebGPUDevice() expects a valid GPUDevice.");i=e,s=e}setRendererWorkingColorSpace(e){return((e=null)=>{const t=e;return!(!t||!t.ColorManagement)&&"workingColorSpace"in t.ColorManagement&&void 0!==t.LinearSRGBColorSpace&&(t.ColorManagement.workingColorSpace=t.LinearSRGBColorSpace,!0)})(e)}getWebGPUDevice(){return s||(e?e.preinitializedWebGPUDevice:null)||null}init(e,t){return this.defaultContext?.nativeptr&&this.releaseContext(this.defaultContext),this.defaultContext=new Q,this.defaultContext.init(e,t)}update(e){this.defaultContext.update(e)}beginUpdate(){this.defaultContext.beginUpdate()}endUpdate(){this.defaultContext.endUpdate()}updateHandle(e,t){this.defaultContext.updateHandle(e,t)}draw(){this.defaultContext.draw()}drawExternal(e,t,r="all"){this.defaultContext.drawExternal(e,t,r)}beginDraw(){this.defaultContext.beginDraw()}endDraw(){this.defaultContext.endDraw()}drawHandle(e){this.defaultContext.drawHandle(e)}setProjectionMatrix(e){this.defaultContext.setProjectionMatrix(e)}setProjectionPerspective(e,t,r,n){this.defaultContext.setProjectionPerspective(e,t,r,n)}setProjectionOrthographic(e,t,r,n){this.defaultContext.setProjectionOrthographic(e,t,r,n)}setCameraMatrix(e){this.defaultContext.setCameraMatrix(e)}setCameraLookAt(e,t,r,n,a,s,i,o,f){this.defaultContext.setCameraLookAt(e,t,r,n,a,s,i,o,f)}setCameraLookAtFromVector(e,t,r){this.defaultContext.setCameraLookAtFromVector(e,t,r)}setCompositeMode(e){this.defaultContext.setCompositeMode(e)}loadEffect(e,t,r,n,a){return this.defaultContext.loadEffect(e,t,r,n,a)}loadEffectPackage(e,t,r,n,a){return this.defaultContext.loadEffectPackage(e,t,r,n,a)}registerEffects(e){this.defaultContext.registerEffects(e)}preloadEffects(e){return this.defaultContext.preloadEffects(e)}reloadEffects(e){return this.defaultContext.reloadEffects(e)}unloadEffects(e){this.defaultContext.unloadEffects(e)}unregisterEffects(e){this.defaultContext.unregisterEffects(e)}getEffect(e){return this.defaultContext.getEffect(e)}getEffectState(e){return this.defaultContext.getEffectState(e)}getEffectStates(){return this.defaultContext.getEffectStates()}whenEffectsReady(e){return this.defaultContext.whenEffectsReady(e)}playEffect(e,t,r,n){return this.defaultContext.playEffect(e,t,r,n)}releaseEffect(e){this.defaultContext.releaseEffect(e)}play(e,t,r,n){return this.defaultContext.play(e,t,r,n)}stopAll(){this.defaultContext.stopAll()}setResourceLoader(e){this.defaultContext.setResourceLoader(e)}getRestInstancesCount(){return this.defaultContext.getRestInstancesCount()}isVertexArrayObjectSupported(){return this.defaultContext.isVertexArrayObjectSupported()}}})();"undefined"!=typeof globalThis&&(globalThis.effekseer=e),"undefined"!=typeof exports&&(exports=e);
@@ -9,6 +9,54 @@ const effekseer = (() => {
9
9
  let imageCrossOrigin = "";
10
10
  let contextId = 0;
11
11
  let onRuntimeReadyQueue = [];
12
+ let requestedLogEnabled = true;
13
+ let pendingAsyncEffectResourceLoads = 0;
14
+ let suppressedMissingAssetWarningDepth = 0;
15
+ let originalConsoleWarn = null;
16
+
17
+ const MISSING_REQUIRED_ASSET_WARNING_PREFIX = "[EffekseerWebGPU] Missing required asset:";
18
+
19
+ const installConsoleWarnInterceptor = () => {
20
+ if (originalConsoleWarn || typeof console === "undefined" || typeof console.warn !== "function") {
21
+ return;
22
+ }
23
+ originalConsoleWarn = console.warn.bind(console);
24
+ console.warn = (...args) => {
25
+ const first = args[0];
26
+ if (
27
+ suppressedMissingAssetWarningDepth > 0 &&
28
+ typeof first === "string" &&
29
+ first.startsWith(MISSING_REQUIRED_ASSET_WARNING_PREFIX)
30
+ ) {
31
+ return;
32
+ }
33
+ originalConsoleWarn(...args);
34
+ };
35
+ };
36
+
37
+ const syncCoreLogEnabled = () => {
38
+ if (!runtimeInitialized || typeof Core.SetLogEnabled !== "function") {
39
+ return;
40
+ }
41
+ Core.SetLogEnabled(requestedLogEnabled && pendingAsyncEffectResourceLoads === 0 ? 1 : 0);
42
+ };
43
+
44
+ const beginAsyncEffectResourceLoad = () => {
45
+ installConsoleWarnInterceptor();
46
+ suppressedMissingAssetWarningDepth += 1;
47
+ pendingAsyncEffectResourceLoads += 1;
48
+ syncCoreLogEnabled();
49
+ };
50
+
51
+ const endAsyncEffectResourceLoad = () => {
52
+ if (suppressedMissingAssetWarningDepth > 0) {
53
+ suppressedMissingAssetWarningDepth -= 1;
54
+ }
55
+ if (pendingAsyncEffectResourceLoads > 0) {
56
+ pendingAsyncEffectResourceLoads -= 1;
57
+ }
58
+ syncCoreLogEnabled();
59
+ };
12
60
 
13
61
  const toArrayBuffer = (data) => {
14
62
  if (data instanceof ArrayBuffer) {
@@ -1014,6 +1062,7 @@ const effekseer = (() => {
1014
1062
 
1015
1063
  runtimeInitialized = true;
1016
1064
  runtimeInitializing = false;
1065
+ syncCoreLogEnabled();
1017
1066
  const callbacks = onRuntimeReadyQueue;
1018
1067
  onRuntimeReadyQueue = [];
1019
1068
  callbacks.forEach((cb) => cb(true));
@@ -1084,6 +1133,23 @@ const effekseer = (() => {
1084
1133
  this.packageOnly = false;
1085
1134
  this._ownedResourceAliases = [];
1086
1135
  this._managedRefIds = new Set();
1136
+ this._asyncResourceLogSuppressed = false;
1137
+ }
1138
+
1139
+ _beginAsyncResourceLogSuppression() {
1140
+ if (this._asyncResourceLogSuppressed) {
1141
+ return;
1142
+ }
1143
+ this._asyncResourceLogSuppressed = true;
1144
+ beginAsyncEffectResourceLoad();
1145
+ }
1146
+
1147
+ _endAsyncResourceLogSuppression() {
1148
+ if (!this._asyncResourceLogSuppressed) {
1149
+ return;
1150
+ }
1151
+ this._asyncResourceLogSuppressed = false;
1152
+ endAsyncEffectResourceLoad();
1087
1153
  }
1088
1154
 
1089
1155
  _load(buffer) {
@@ -1093,6 +1159,10 @@ const effekseer = (() => {
1093
1159
  return;
1094
1160
  }
1095
1161
 
1162
+ if (!this.syncResourceLoad) {
1163
+ this._beginAsyncResourceLogSuppression();
1164
+ }
1165
+
1096
1166
  loadingEffect = this;
1097
1167
  this.mainBuffer = ab;
1098
1168
  const memptr = Module._malloc(ab.byteLength);
@@ -1135,6 +1205,8 @@ const effekseer = (() => {
1135
1205
  return;
1136
1206
  }
1137
1207
 
1208
+ this._endAsyncResourceLogSuppression();
1209
+
1138
1210
  if (missingRequiredResources.length > 0) {
1139
1211
  console.warn(
1140
1212
  `[EffekseerWebGPU] missing required resources ignored: ${missingRequiredResources.join(", ")}`
@@ -1412,6 +1484,7 @@ const effekseer = (() => {
1412
1484
  clearCachedEffectReference(effect);
1413
1485
  clearOwnedResourceAliases(effect._ownedResourceAliases);
1414
1486
  effect._ownedResourceAliases = [];
1487
+ effect._endAsyncResourceLogSuppression?.();
1415
1488
 
1416
1489
  if (this.nativeptr && effect.nativeptr) {
1417
1490
  Core.ReleaseEffect(this.nativeptr, effect.nativeptr);
@@ -2009,6 +2082,7 @@ const effekseer = (() => {
2009
2082
  if (!effect || !effect.nativeptr) {
2010
2083
  return;
2011
2084
  }
2085
+ effect._endAsyncResourceLogSuppression?.();
2012
2086
  clearCachedEffectReference(effect);
2013
2087
  Core.ReleaseEffect(this.nativeptr, effect.nativeptr);
2014
2088
  effect.nativeptr = 0;
@@ -2120,10 +2194,8 @@ const effekseer = (() => {
2120
2194
  }
2121
2195
 
2122
2196
  setLogEnabled(flag) {
2123
- if (!runtimeInitialized) {
2124
- return;
2125
- }
2126
- Core.SetLogEnabled(flag ? 1 : 0);
2197
+ requestedLogEnabled = !!flag;
2198
+ syncCoreLogEnabled();
2127
2199
  }
2128
2200
 
2129
2201
  setImageCrossOrigin(crossOrigin) {