@eigong/effekseer-webgpu-runtime 0.1.2 → 0.1.3

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
@@ -2,6 +2,11 @@
2
2
 
3
3
  `@eigong/effekseer-webgpu-runtime` redistributes the Effekseer WebGPU runtime files needed by browser integrations.
4
4
 
5
+ The package now separates the bridge into:
6
+
7
+ - client bridge: `effekseer.webgpu.js`
8
+ - debug/source bridge: `effekseer.webgpu.src.js`
9
+
5
10
  ## Install
6
11
 
7
12
  ```bash
@@ -13,6 +18,7 @@ npm install @eigong/effekseer-webgpu-runtime
13
18
  - `fflate.umd.js`
14
19
  - `Effekseer_WebGPU_Runtime.js`
15
20
  - `Effekseer_WebGPU_Runtime.wasm`
21
+ - `effekseer.webgpu.js`
16
22
  - `effekseer.webgpu.src.js`
17
23
 
18
24
  ## Usage
@@ -23,10 +29,23 @@ import {
23
29
  effekseerWebgpuRuntimeJsUrl,
24
30
  effekseerWebgpuRuntimeWasmUrl,
25
31
  effekseerWebgpuBridgeUrl,
32
+ effekseerWebgpuDebugBridgeUrl,
26
33
  } from '@eigong/effekseer-webgpu-runtime'
27
34
  ```
28
35
 
29
- Or resolve all four at once:
36
+ The default loader uses the client bridge:
37
+
38
+ ```js
39
+ import { loadEffekseerWebGPURuntime } from '@eigong/effekseer-webgpu-runtime'
40
+ ```
41
+
42
+ Use the debug/source bridge only when you explicitly want it:
43
+
44
+ ```js
45
+ import { loadEffekseerWebGPUDebugRuntime } from '@eigong/effekseer-webgpu-runtime/debug'
46
+ ```
47
+
48
+ Or resolve all runtime URLs at once:
30
49
 
31
50
  ```js
32
51
  import { getEffekseerWebGPURuntimeUrls } from '@eigong/effekseer-webgpu-runtime'
package/debug.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export declare const effekseerWebgpuDebugBridgeUrl: string
2
+
3
+ export declare function getEffekseerWebGPUDebugRuntimeUrls(): {
4
+ fflateUrl: string
5
+ effekseerWebgpuRuntimeJsUrl: string
6
+ effekseerWebgpuRuntimeWasmUrl: string
7
+ effekseerWebgpuBridgeUrl: string
8
+ }
9
+
10
+ export declare function loadEffekseerWebGPUDebugRuntime(): Promise<any>
package/debug.js ADDED
@@ -0,0 +1,38 @@
1
+ import {
2
+ fflateUrl,
3
+ effekseerWebgpuRuntimeJsUrl,
4
+ effekseerWebgpuRuntimeWasmUrl,
5
+ } from './index.js'
6
+
7
+ export const effekseerWebgpuDebugBridgeUrl = new URL('./runtime/effekseer.webgpu.src.js', import.meta.url).href
8
+
9
+ function loadScript(src) {
10
+ return new Promise((resolve, reject) => {
11
+ const script = document.createElement('script')
12
+ script.src = src
13
+ script.onload = () => resolve()
14
+ script.onerror = reject
15
+ document.head.appendChild(script)
16
+ })
17
+ }
18
+
19
+ export function getEffekseerWebGPUDebugRuntimeUrls() {
20
+ return {
21
+ fflateUrl,
22
+ effekseerWebgpuRuntimeJsUrl,
23
+ effekseerWebgpuRuntimeWasmUrl,
24
+ effekseerWebgpuBridgeUrl: effekseerWebgpuDebugBridgeUrl,
25
+ }
26
+ }
27
+
28
+ export async function loadEffekseerWebGPUDebugRuntime() {
29
+ await loadScript(fflateUrl)
30
+ await loadScript(effekseerWebgpuRuntimeJsUrl)
31
+ await loadScript(effekseerWebgpuDebugBridgeUrl)
32
+
33
+ if (!globalThis.effekseer) {
34
+ throw new Error('Effekseer WebGPU runtime did not initialize.')
35
+ }
36
+
37
+ return globalThis.effekseer
38
+ }
package/index.d.ts CHANGED
@@ -3,4 +3,11 @@ export declare const effekseerWebgpuRuntimeJsUrl: string
3
3
  export declare const effekseerWebgpuRuntimeWasmUrl: string
4
4
  export declare const effekseerWebgpuBridgeUrl: string
5
5
 
6
+ export declare function getEffekseerWebGPURuntimeUrls(): {
7
+ fflateUrl: string
8
+ effekseerWebgpuRuntimeJsUrl: string
9
+ effekseerWebgpuRuntimeWasmUrl: string
10
+ effekseerWebgpuBridgeUrl: string
11
+ }
12
+
6
13
  export declare function loadEffekseerWebGPURuntime(): Promise<any>
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export const fflateUrl = new URL('./runtime/fflate.umd.js', import.meta.url).href
2
2
  export const effekseerWebgpuRuntimeJsUrl = new URL('./runtime/Effekseer_WebGPU_Runtime.js', import.meta.url).href
3
3
  export const effekseerWebgpuRuntimeWasmUrl = new URL('./runtime/Effekseer_WebGPU_Runtime.wasm', import.meta.url).href
4
- export const effekseerWebgpuBridgeUrl = new URL('./runtime/effekseer.webgpu.src.js', import.meta.url).href
4
+ export const effekseerWebgpuBridgeUrl = new URL('./runtime/effekseer.webgpu.js', import.meta.url).href
5
5
 
6
6
  function loadScript(src) {
7
7
  return new Promise((resolve, reject) => {
@@ -13,10 +13,19 @@ function loadScript(src) {
13
13
  })
14
14
  }
15
15
 
16
- export async function loadEffekseerWebGPURuntime() {
16
+ function getRuntimeUrls(bridgeUrl) {
17
+ return {
18
+ fflateUrl,
19
+ effekseerWebgpuRuntimeJsUrl,
20
+ effekseerWebgpuRuntimeWasmUrl,
21
+ effekseerWebgpuBridgeUrl: bridgeUrl,
22
+ }
23
+ }
24
+
25
+ async function loadRuntime(bridgeUrl) {
17
26
  await loadScript(fflateUrl)
18
27
  await loadScript(effekseerWebgpuRuntimeJsUrl)
19
- await loadScript(effekseerWebgpuBridgeUrl)
28
+ await loadScript(bridgeUrl)
20
29
 
21
30
  if (!globalThis.effekseer) {
22
31
  throw new Error('Effekseer WebGPU runtime did not initialize.')
@@ -24,3 +33,11 @@ export async function loadEffekseerWebGPURuntime() {
24
33
 
25
34
  return globalThis.effekseer
26
35
  }
36
+
37
+ export function getEffekseerWebGPURuntimeUrls() {
38
+ return getRuntimeUrls(effekseerWebgpuBridgeUrl)
39
+ }
40
+
41
+ export async function loadEffekseerWebGPURuntime() {
42
+ return loadRuntime(effekseerWebgpuBridgeUrl)
43
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eigong/effekseer-webgpu-runtime",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Redistributable Effekseer WebGPU runtime assets with MIT license notice",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -11,14 +11,21 @@
11
11
  "types": "./index.d.ts",
12
12
  "import": "./index.js"
13
13
  },
14
+ "./debug": {
15
+ "types": "./debug.d.ts",
16
+ "import": "./debug.js"
17
+ },
14
18
  "./fflate.umd.js": "./runtime/fflate.umd.js",
15
19
  "./Effekseer_WebGPU_Runtime.js": "./runtime/Effekseer_WebGPU_Runtime.js",
16
20
  "./Effekseer_WebGPU_Runtime.wasm": "./runtime/Effekseer_WebGPU_Runtime.wasm",
21
+ "./effekseer.webgpu.js": "./runtime/effekseer.webgpu.js",
17
22
  "./effekseer.webgpu.src.js": "./runtime/effekseer.webgpu.src.js"
18
23
  },
19
24
  "files": [
20
25
  "index.js",
21
26
  "index.d.ts",
27
+ "debug.js",
28
+ "debug.d.ts",
22
29
  "runtime",
23
30
  "README.md",
24
31
  "LICENSE"
@@ -31,6 +38,13 @@
31
38
  ],
32
39
  "license": "MIT",
33
40
  "sideEffects": false,
41
+ "scripts": {
42
+ "build": "npx terser ./runtime/effekseer.webgpu.src.js --compress --mangle --comments false -o ./runtime/effekseer.webgpu.js",
43
+ "prepublishOnly": "npm run build"
44
+ },
45
+ "devDependencies": {
46
+ "terser": "^5.46.1"
47
+ },
34
48
  "publishConfig": {
35
49
  "access": "public"
36
50
  }
@@ -0,0 +1 @@
1
+ const effekseer=(()=>{let e={},t={},r=null,n=!1,a=!1,i=null,s=null,o="",f=0,l=[];const u=e=>e instanceof ArrayBuffer?e:ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):null,d=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())},c="EFWGPKG2",p="__efwgpk__/main_effect_path.txt",m=new Uint8Array([69,102,107,87,103,46,87,101,98,71,80,85,46,67,84,82]);let h=0,g=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(g)return g;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 g=globalThis.crypto.subtle.importKey("raw",m,"AES-CTR",!1,["decrypt"]),g})();return globalThis.crypto.subtle.decrypt({name:"AES-CTR",counter:t,length:128},r,e)},S=e=>String(e||"").replace(/\\/g,"/").split("?")[0].split("#")[0],v=e=>{const t=u(e);if(!t||t.byteLength<8)return"";const r=new Uint8Array(t,0,8);return String.fromCharCode(...r)},k=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(v(e)!==c)return null;const n=r.getUint32(8,!0),a=r.getUint32(12,!0),i=r.getUint32(16,!0),s=r.getUint32(20,!0),o=r.getUint32(24,!0),f=r.getUint32(28,!0),l=r.getUint32(32,!0),u=r.getUint32(36,!0),d=r.getUint32(40,!0),p=r.getUint32(44,!0),m=r.getUint32(48,!0),h=r.getUint32(52,!0),g=2===i?64:3===i?80:0;if(0===g||n!==g||48!==o)return null;let b=null;if(4&a){if(i<3||t<80)return null;if(b=new Uint8Array(e.slice(56,72)),16!==b.byteLength)return null}return{headerSize:n,globalFlags:a,formatRevision:i,entryCount:s,entryStride:o,entriesOffset:f,stringPoolOffset:l,stringPoolSize:u,payloadOffset:d,payloadSize:p,tocCrc:m,payloadCrc:h,payloadNonce:b,payloadEncrypted:!!(4&a)}})(e);if(!n)return t;const a=new DataView(e),{headerSize:i,entryCount:s,entryStride:o,entriesOffset:f,stringPoolOffset:l,stringPoolSize:u,payloadOffset:p,payloadSize:m,tocCrc:h,payloadCrc:g}=n,b=BigInt(s)*BigInt(o);if(b>BigInt(r))return t;const E=Number(b);if(!x(f,E,r))return t;if(!x(l,u,r))return t;if(!x(p,m,r))return t;const S=l+u,k=p+m,G=new Uint8Array(e,0,i).slice();G.fill(0,48,56);const y=new Uint8Array(i+E+u);if(y.set(G,0),y.set(new Uint8Array(e,f,E),i),y.set(new Uint8Array(e,l,u),i+E),w(y)!==h>>>0)return t;const C=new Uint8Array(e,p,m);if(w(C)!==g>>>0)return t;const T=new TextDecoder("utf-8");for(let n=0;n<s;n++){const i=f+n*o,s=a.getUint32(i+8,!0),u=a.getUint32(i+12,!0),c=a.getUint32(i+16,!0),m=a.getUint32(i+20,!0),h=a.getUint32(i+24,!0),g=a.getUint32(i+28,!0),b=a.getUint32(i+32,!0),w=a.getUint32(i+36,!0);if(!x(s,u,r))continue;if(s<l||s+u>S)continue;if(!x(m,h,r))continue;if(m<p||m+h>k)continue;let E="";try{E=T.decode(new Uint8Array(e,s,u))}catch{continue}const v=d(E);if(!v)continue;const G={index:n,path:E,normalizedPath:v,flags:c,payloadOffset:m,packedSize:h,rawSize:g,packedCrc:b,rawCrc:w},y=t.get(v);y?y.push(G):t.set(v,[G])}return t._efwgpkMeta={payloadOffset:p,payloadSize:m,payloadEncrypted:n.payloadEncrypted,payloadNonce:n.payloadNonce,decryptedPayloadPromise:null},t},G=async e=>{const t=globalThis.fflate;if(t&&"function"==typeof t.unzlibSync){const r=t.unzlibSync(new Uint8Array(e));return u(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()},y=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,i=r.payloadOffset-n.payloadOffset;return i<0||i+r.packedSize>a.byteLength?null:a.subarray(i,i+r.packedSize)},C=async(e,t,r)=>{const n=d(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(!x(n.payloadOffset,n.packedSize,e.byteLength))continue;const i=await y(e,t,n);if(i&&w(i)===n.packedCrc>>>0){if(0===n.flags&&n.packedSize===n.rawSize){const e=i.slice();if(w(e)!==n.rawCrc>>>0)continue;return e.buffer}if(1===n.flags){const e=await G(i);if(!e||e.byteLength!==n.rawSize)continue;if(w(new Uint8Array(e))!==n.rawCrc>>>0)continue;return e}}}return null},T=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}`:"",P=(e,t,r)=>{const n=d(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(x(r.payloadOffset,r.packedSize,e.byteLength)){if(0===r.flags&&r.packedSize===r.rawSize)return r;if(1===r.flags)return r}}return null},x=(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)},_=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},M=e=>{"function"==typeof e&&("function"==typeof queueMicrotask?queueMicrotask(e):Promise.resolve().then(e))},D=(e,t)=>{const r=String(e||"").replace(/\\/g,"/");const n=Number(t);return`${r}::${Number.isFinite(n)?n:1}`},I=e=>{e&&e.context&&e._cacheKey&&e.context._effectCache&&e.context._effectCache.get(e._cacheKey)===e&&e.context._effectCache.delete(e._cacheKey)},U=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,L=(e,t,r)=>{if(e&&("function"==typeof t&&(e.isLoaded?M(()=>t()):e._loadFailed||e._onloadListeners.push(t)),"function"==typeof r))if(e._loadFailed){const t=e._loadErrorMessage||"failed to load effect",n=e._loadErrorPath||"";M(()=>r(t,n))}else e.isLoaded||e._onerrorListeners.push(r)},A=(e,t,r="")=>{if(!e||e._loadFailed)return;e._loadFailed=!0,e._loadErrorMessage=String(t||"failed to load effect"),e._loadErrorPath=String(r||""),I(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];M(()=>r(e._loadErrorMessage,e._loadErrorPath))}};let F=(e,t,r)=>{R(e,t,r)};const B={ptr:0,capacity:0},O=(t,r)=>{const n=t instanceof Float32Array?t:new Float32Array(t);if(n.length<=0)return void r(0);const a=((i=n.length)<=B.capacity&&0!==B.ptr||(0!==B.ptr&&(e._free(B.ptr),B.ptr=0,B.capacity=0),B.ptr=e._malloc(4*i),B.capacity=i),B.ptr);var i;e.HEAPF32.set(n,a>>2),r(a)},z=Object.freeze({rgba8unorm:22,"rgba8unorm-srgb":23,bgra8unorm:27,"bgra8unorm-srgb":28,rgba16float:40,depth24plus:46,"depth24plus-stencil8":47,depth32float:48}),V=(Object.freeze(Object.fromEntries(Object.entries(z).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(z,t)?z[t]:null}),j=async s=>{if(n)return;if(a)return void await new Promise((e,t)=>{l.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 s&&s.length>0&&(o.locateFile=e=>e.endsWith(".wasm")?s:e),i&&(o.preinitializedWebGPUDevice=i);const f=effekseer_webgpu_native(o);e=f instanceof Promise?await f:f,!i&&e?.preinitializedWebGPUDevice&&(i=e.preinitializedWebGPUDevice),i&&(e.preinitializedWebGPUDevice=i),(()=>{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"]),GetUpdateTime:e.cwrap("EffekseerGetUpdateTime","number",["number"]),GetDrawTime:e.cwrap("EffekseerGetDrawTime","number",["number"]),GetDrawFlushComputeTime:e.cwrap("EffekseerGetDrawFlushComputeTime","number",["number"]),GetDrawBeginFrameTime:e.cwrap("EffekseerGetDrawBeginFrameTime","number",["number"]),GetDrawManagerTime:e.cwrap("EffekseerGetDrawManagerTime","number",["number"]),GetDrawEndFrameTime:e.cwrap("EffekseerGetDrawEndFrameTime","number",["number"]),GetDrawTotalTime:e.cwrap("EffekseerGetDrawTotalTime","number",["number"]),GetGpuTimestampSupported:e.cwrap("EffekseerGetGpuTimestampSupported","number",["number"]),GetGpuTimestampValid:e.cwrap("EffekseerGetGpuTimestampValid","number",["number"]),GetGpuTimestampEffekseerPassTime:e.cwrap("EffekseerGetGpuTimestampEffekseerPassTime","number",["number"]),GetGpuTimestampFrameTime:e.cwrap("EffekseerGetGpuTimestampFrameTime","number",["number"]),GetGpuTimestampReadPending:e.cwrap("EffekseerGetGpuTimestampReadPending","number",["number"]),GetGpuTimestampLastMapStatus:e.cwrap("EffekseerGetGpuTimestampLastMapStatus","number",["number"]),GetGpuTimestampMapState:e.cwrap("EffekseerGetGpuTimestampMapState","number",["number"]),GetGpuTimestampMapMode:e.cwrap("EffekseerGetGpuTimestampMapMode","number",["number"]),GetGpuTimestampStallRecoveries:e.cwrap("EffekseerGetGpuTimestampStallRecoveries","number",["number"]),GetRendererProfileBindGroupTime:e.cwrap("EffekseerGetRendererProfileBindGroupTime","number",["number"]),GetRendererProfileBindGroupCacheFlushCount:e.cwrap("EffekseerGetRendererProfileBindGroupCacheFlushCount","number",["number"]),GetRendererProfileBindGroupCacheHits:e.cwrap("EffekseerGetRendererProfileBindGroupCacheHits","number",["number"]),GetRendererProfileBindGroupCacheMisses:e.cwrap("EffekseerGetRendererProfileBindGroupCacheMisses","number",["number"]),GetRendererProfileBindGroupCreates:e.cwrap("EffekseerGetRendererProfileBindGroupCreates","number",["number"]),GetRendererProfilePipelineTime:e.cwrap("EffekseerGetRendererProfilePipelineTime","number",["number"]),GetRendererProfileSetStateTime:e.cwrap("EffekseerGetRendererProfileSetStateTime","number",["number"]),GetRendererProfileIssueDrawTime:e.cwrap("EffekseerGetRendererProfileIssueDrawTime","number",["number"]),GetRendererProfileDrawTotalTime:e.cwrap("EffekseerGetRendererProfileDrawTotalTime","number",["number"]),GetRendererProfileDrawSpritesCalls:e.cwrap("EffekseerGetRendererProfileDrawSpritesCalls","number",["number"]),GetRendererProfileDrawPolygonCalls:e.cwrap("EffekseerGetRendererProfileDrawPolygonCalls","number",["number"]),GetInternalStandardRendererTextureSetupTime:e.cwrap("EffekseerGetInternalStandardRendererTextureSetupTime","number",["number"]),GetInternalStandardRendererShaderSelectTime:e.cwrap("EffekseerGetInternalStandardRendererShaderSelectTime","number",["number"]),GetInternalStandardRendererVertexPackTime:e.cwrap("EffekseerGetInternalStandardRendererVertexPackTime","number",["number"]),GetInternalStandardRendererPixelPackTime:e.cwrap("EffekseerGetInternalStandardRendererPixelPackTime","number",["number"]),GetInternalStandardRendererConstantUploadTime:e.cwrap("EffekseerGetInternalStandardRendererConstantUploadTime","number",["number"]),GetInternalStandardRendererRenderStateTime:e.cwrap("EffekseerGetInternalStandardRendererRenderStateTime","number",["number"]),GetInternalStandardRendererVertexBindTime:e.cwrap("EffekseerGetInternalStandardRendererVertexBindTime","number",["number"]),GetInternalStandardRendererIndexBindTime:e.cwrap("EffekseerGetInternalStandardRendererIndexBindTime","number",["number"]),GetInternalStandardRendererLayoutTime:e.cwrap("EffekseerGetInternalStandardRendererLayoutTime","number",["number"]),GetInternalStandardRendererDrawTime:e.cwrap("EffekseerGetInternalStandardRendererDrawTime","number",["number"]),GetManagerProfileFrustumTime:e.cwrap("EffekseerGetManagerProfileFrustumTime","number",["number"]),GetManagerProfileSortTime:e.cwrap("EffekseerGetManagerProfileSortTime","number",["number"]),GetManagerProfileCanDrawTime:e.cwrap("EffekseerGetManagerProfileCanDrawTime","number",["number"]),GetManagerProfileContainerDrawTime:e.cwrap("EffekseerGetManagerProfileContainerDrawTime","number",["number"]),GetManagerProfileGpuParticleTime:e.cwrap("EffekseerGetManagerProfileGpuParticleTime","number",["number"]),GetManagerProfileDrawSetCount:e.cwrap("EffekseerGetManagerProfileDrawSetCount","number",["number"]),GetManagerProfileVisibleDrawSetCount:e.cwrap("EffekseerGetManagerProfileVisibleDrawSetCount","number",["number"]),GetManagerProfileContainersTotal:e.cwrap("EffekseerGetManagerProfileContainersTotal","number",["number"]),GetManagerProfileContainersDrawn:e.cwrap("EffekseerGetManagerProfileContainersDrawn","number",["number"]),GetManagerProfileContainersDepthCulled:e.cwrap("EffekseerGetManagerProfileContainersDepthCulled","number",["number"]),GetDrawCallCount:e.cwrap("EffekseerGetDrawCallCount","number",["number"]),GetDrawVertexCount:e.cwrap("EffekseerGetDrawVertexCount","number",["number"]),GetTotalParticleCount:e.cwrap("EffekseerGetTotalParticleCount","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 i=a.resources.find(e=>e.path===t);if(i)return i.isLoaded?i.buffer:null;i={path:t,isLoaded:!1,buffer:null,isRequired:!!n},a.resources.push(i);const s=e=>String(e||"").replace(/\\/g,"/"),o=e=>{const t=s(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=s(e),r=[],n=new Set,a=e=>{e&&!n.has(e)&&(n.add(e),r.push(e))},i=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),i(t);let f=t.indexOf("/");for(;f>=0;){const e=t.slice(f+1);a(e),i(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),s=e.resourcesMap[a]||e.resourcesMap[n]||e.resourcesMap[t];if(null!=s)return i.buffer=s,i.isLoaded=!0,s;const l=_(a);if(null!=l)return i.buffer=l,i.isLoaded=!0,e.resourcesMap[a]=l,e.resourcesMap[n]=l,l}return i.buffer=null,i.isLoaded=!0,null}for(let r=0;r<f.length;r++){const n=f[r],s=o(n),l=e.resourcesMap[s]||e.resourcesMap[n]||e.resourcesMap[t];if(null!=l)return i.buffer=l,i.isLoaded=!0,Promise.resolve().then(()=>a._update()),null}let l=0;const u=()=>{if(l>=f.length)return i.buffer=null,i.isLoaded=!0,void a._update();const e=f[l++],t=o(e);F(t,e=>{if(null!=e)return i.buffer=e,i.isLoaded=!0,void a._update();u()},()=>{u()})};return u(),null},n=!0,a=!1;const i=l;l=[],i.forEach(e=>e(!0))})()};class H{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=u(n);if(!a)return void A(this,"invalid data","");r=this,this.mainBuffer=a;const i=e._malloc(a.byteLength);e.HEAPU8.set(new Uint8Array(a),i),this.nativeptr=t.LoadEffect(this.context.nativeptr,i,a.byteLength,this.scale),e._free(i),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 A(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];M(()=>r())}})(this))}}const W=(t,r,n,a,i,s,o,f=null)=>{const l=f||new H(t);l.scale=a,l._ownedResourceAliases=[],L(l,i,s);const u=k(r);if(0===u.size)return A(l,"invalid data. expected efkwgpk package",n||""),l;const c=(()=>{if("string"!=typeof n||0===n.length)return"";const e=S(n),t=e.lastIndexOf("/");return t>=0?e.slice(0,t+1):""})(),m=c.toLowerCase(),g=`efwgpk://${++h}/`,b=new Map;return l.baseDir=c,l.syncResourceLoad=!0,l.packageOnly=!0,l.redirect=e=>{const t=S(e),r=[];m&&t.toLowerCase().startsWith(m)&&r.push(t.slice(c.length)),r.push(t);for(let e=0;e<r.length;e++){const t=d(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 C(e,t,p);if(r)try{const e=new TextDecoder("utf-8").decode(new Uint8Array(r)).replace(/\0+$/,""),t=d(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,u);if(!t)throw new Error("main effect path not found in efkwgpk package");const a=await C(r,u,t),i=String.fromCharCode(...new Uint8Array(a||new ArrayBuffer(0),0,Math.min(4,a?a.byteLength:0)));if(!a||"EFWG"!==i&&"SKFE"!==i)throw new Error("main effect inside efkwgpk is not a valid .efkwg");const s=new Map,o=new Map;for(const[n]of u.entries()){if(n===t||n===d(p))continue;const a=P(r,u,n);if(!a)continue;const i=T(a);if(!i)continue;let f=s.get(i);if(!f){let t=o.get(i);if(void 0===t&&(t=await C(r,u,n),o.set(i,t||null)),!t)continue;f=`${g}__payload/${s.size}`,e.resourcesMap[f]=t,s.set(i,f)}b.set(n,f)}l._ownedResourceAliases=Array.from(s.values()),l._load(a),l.nativeptr||A(l,"failed to load effect from efkwgpk package",n||t)}catch(e){A(l,e&&e.message?e.message:"failed to load effect from efkwgpk package",n||"")}})(),l};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){O(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 i=Number(n.scale);return{id:r,path:a,scale:Number.isFinite(i)?i: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||(I(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,i=null;const s=i=>{if(a)return;a=!0;return this._registeredEffectStates.get(e.id)!==e||e._generation!==r?(this._releaseManagedEffectIfUnused(i),void n(null)):(e._loadingEffect=null,e.loadPromise=null,i&&i.isLoaded?(e.effect=i,e.status="loaded",e.errorMessage="",e.errorPath="",e.ownedResourceAliases=Array.isArray(i._ownedResourceAliases)?i._ownedResourceAliases.slice():[],void n(i)):(e.status="failed",e.errorMessage="failed to load effect",e.errorPath=t.path,void n(null)))},o=(s,o="")=>{if(a)return;a=!0,i&&this._releaseManagedEffectReference(i,e.id);if(this._registeredEffectStates.get(e.id)!==e||e._generation!==r)return i&&this._releaseManagedEffectIfUnused(i),void n(null);e._loadingEffect=null,e.loadPromise=null,e.effect=null,e.status="failed",e.errorMessage=String(s||"failed to load effect"),e.errorPath=String(o||t.path||""),e.ownedResourceAliases=[],i&&this._releaseManagedEffectIfUnused(i),n(null)};try{i=this.loadEffect(t.path,t.scale,()=>s(i),(e,t)=>o(e,t))}catch(e){return void o(e&&e.message?e.message:"failed to load effect",t.path)}e._loadingEffect=i,i?(this._registerManagedEffectReference(i,e.id),i.isLoaded?s(i):i._loadFailed&&o(i._loadErrorMessage,i._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,i=e.compositeWithBackground?1:0;return this.externalRenderPassEnabled=t,this.fixedUpdateAccumulator=0,{instanceMaxCount:r,squareMaxCount:n,linearColorSpace:a,compositeWithBackground:i}}_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 i=V(n&&n.colorFormat),s=(()=>{const e=V(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),l=f(n,"depthTextureView")||f(n,"importDepthTextureView"),u=f(n,"backgroundTextureView")||f(n,"importBackgroundTextureView"),d=l?f(n,"depthTextureView")?n.depthTextureView:n.importDepthTextureView:null,c=u?f(n,"backgroundTextureView")?n.backgroundTextureView:n.importBackgroundTextureView:null,p=l?e.__effekseerDepthTextureView:null,m=u?e.__effekseerBackgroundTextureView:null;e.__effekseerExternalRenderPass=r,e.__effekseerExternalPassColorFormat=i,e.__effekseerExternalPassDepthFormat=s,e.__effekseerExternalPassSampleCount=o,l&&(e.__effekseerDepthTextureView=d||null),u&&(e.__effekseerBackgroundTextureView=c||null);const h="back"===a?"back":"front"===a?"front":"all";try{"back"===h?t.DrawExternalBack(this.nativeptr):"front"===h?t.DrawExternalFront(this.nativeptr):t.DrawExternal(this.nativeptr)}finally{l&&(e.__effekseerDepthTextureView=p||null),u&&(e.__effekseerBackgroundTextureView=m||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){O(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){O(e,e=>t.SetCameraMatrix(this.nativeptr,e))}setCameraLookAt(e,r,n,a,i,s,o,f,l){t.SetCameraLookAt(this.nativeptr,e,r,n,a,i,s,o,f,l)}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 i="function"==typeof t?1:t,s="function"==typeof t?t:r,o="function"==typeof t?r:n,f=a;let l=null;if("string"==typeof e&&null==f){l=D(e,i);const t=this._effectCache.get(l);if(t)return L(t,s,o),t}const d=new H(this);d.scale=i,d.redirect=f,d._cacheKey=l||"",L(d,s,o),l&&this._effectCache.set(l,d);const p=(e,t="")=>(A(d,e,t),d);if("string"==typeof e)return"string"==typeof(m=e)&&0!==m.length&&m.replace(/\\/g,"/").split("?")[0].split("#")[0].toLowerCase().endsWith(".efkwg")?(R(e,t=>{const r=u(t);if(!r)return void p("failed to fetch efkwg effect",e);const n=e.replace(/\\/g,"/").split("?")[0].split("#")[0],a=n.lastIndexOf("/");d.baseDir=a>=0?n.slice(0,a+1):"",d.syncResourceLoad=!1,d._load(r),d.nativeptr||p("failed to load efkwg effect",e)},()=>{p("failed to fetch efkwg effect",e)}),d):(e=>"string"==typeof e&&0!==e.length&&S(e).toLowerCase().endsWith(".efkwgpk"))(e)?(R(e,t=>{const r=u(t);r?W(this,r,e,i,null,null,0,d):p("failed to fetch efkwgpk package",e)},()=>{p("failed to fetch efkwgpk package",e)}),d):p("unsupported effect format. expected .efkwg or .efkwgpk",e);var m;const h=u(e);if(!h)return p("invalid data. expected efkwg or efkwgpk bytes","");if(v(h)===c)return W(this,h,"",i,null,null,0,d);const g=String.fromCharCode(...new Uint8Array(h,0,Math.min(4,h.byteLength)));return"EFWG"===g||"SKFE"===g?(d._load(h),d.nativeptr?d:p("failed to load efkwg effect","")):p("invalid data. expected efkwg or efkwgpk bytes","")}loadEffectPackage(e,t,r=1,n,a){let i=r,s=n,o=a;return"function"==typeof r&&(i=1,s=r,o=n),this.loadEffect(e,i,s,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 i=n.effect;i&&(this._releaseManagedEffectReference(i,r),this._releaseManagedEffectIfUnused(i)),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 U(this._registeredEffectStates.get(String(e||"")))}getEffectStates(){return Array.from(this._registeredEffectStates.values(),e=>U(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 i=this.play(a.effect,t,r,n);return i&&a.activeHandles.add(i),i}releaseEffect(e){e&&e.nativeptr&&(I(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 i=t.PlayEffect(this.nativeptr,e.nativeptr,r,n,a);return i>=0?new N(this,i):null}stopAll(){t.StopAllEffects(this.nativeptr)}setResourceLoader(e){F=e}getRestInstancesCount(){return t.GetRestInstancesCount(this.nativeptr)}getUpdateTime(){return t.GetUpdateTime(this.nativeptr)}getDrawTime(){return t.GetDrawTime(this.nativeptr)}getDrawFlushComputeTime(){return t.GetDrawFlushComputeTime(this.nativeptr)}getDrawBeginFrameTime(){return t.GetDrawBeginFrameTime(this.nativeptr)}getDrawManagerTime(){return t.GetDrawManagerTime(this.nativeptr)}getDrawEndFrameTime(){return t.GetDrawEndFrameTime(this.nativeptr)}getDrawTotalTime(){return t.GetDrawTotalTime(this.nativeptr)}getGpuTimestampSupported(){return!!t.GetGpuTimestampSupported(this.nativeptr)}getGpuTimestampValid(){return!!t.GetGpuTimestampValid(this.nativeptr)}getGpuTimestampEffekseerPassTime(){return t.GetGpuTimestampEffekseerPassTime(this.nativeptr)}getGpuTimestampFrameTime(){return t.GetGpuTimestampFrameTime(this.nativeptr)}getGpuTimestampReadPending(){return!!t.GetGpuTimestampReadPending(this.nativeptr)}getGpuTimestampLastMapStatus(){return t.GetGpuTimestampLastMapStatus(this.nativeptr)}getGpuTimestampMapState(){return t.GetGpuTimestampMapState(this.nativeptr)}getGpuTimestampMapMode(){return t.GetGpuTimestampMapMode(this.nativeptr)}getGpuTimestampStallRecoveries(){return t.GetGpuTimestampStallRecoveries(this.nativeptr)}getRendererProfileBindGroupTime(){return t.GetRendererProfileBindGroupTime(this.nativeptr)}getRendererProfileBindGroupCacheFlushCount(){return t.GetRendererProfileBindGroupCacheFlushCount(this.nativeptr)}getRendererProfileBindGroupCacheHits(){return t.GetRendererProfileBindGroupCacheHits(this.nativeptr)}getRendererProfileBindGroupCacheMisses(){return t.GetRendererProfileBindGroupCacheMisses(this.nativeptr)}getRendererProfileBindGroupCreates(){return t.GetRendererProfileBindGroupCreates(this.nativeptr)}getRendererProfilePipelineTime(){return t.GetRendererProfilePipelineTime(this.nativeptr)}getRendererProfileSetStateTime(){return t.GetRendererProfileSetStateTime(this.nativeptr)}getRendererProfileIssueDrawTime(){return t.GetRendererProfileIssueDrawTime(this.nativeptr)}getRendererProfileDrawTotalTime(){return t.GetRendererProfileDrawTotalTime(this.nativeptr)}getRendererProfileDrawSpritesCalls(){return t.GetRendererProfileDrawSpritesCalls(this.nativeptr)}getRendererProfileDrawPolygonCalls(){return t.GetRendererProfileDrawPolygonCalls(this.nativeptr)}getInternalStandardRendererTextureSetupTime(){return t.GetInternalStandardRendererTextureSetupTime(this.nativeptr)}getInternalStandardRendererShaderSelectTime(){return t.GetInternalStandardRendererShaderSelectTime(this.nativeptr)}getInternalStandardRendererVertexPackTime(){return t.GetInternalStandardRendererVertexPackTime(this.nativeptr)}getInternalStandardRendererPixelPackTime(){return t.GetInternalStandardRendererPixelPackTime(this.nativeptr)}getInternalStandardRendererConstantUploadTime(){return t.GetInternalStandardRendererConstantUploadTime(this.nativeptr)}getInternalStandardRendererRenderStateTime(){return t.GetInternalStandardRendererRenderStateTime(this.nativeptr)}getInternalStandardRendererVertexBindTime(){return t.GetInternalStandardRendererVertexBindTime(this.nativeptr)}getInternalStandardRendererIndexBindTime(){return t.GetInternalStandardRendererIndexBindTime(this.nativeptr)}getInternalStandardRendererLayoutTime(){return t.GetInternalStandardRendererLayoutTime(this.nativeptr)}getInternalStandardRendererDrawTime(){return t.GetInternalStandardRendererDrawTime(this.nativeptr)}getManagerProfileFrustumTime(){return t.GetManagerProfileFrustumTime(this.nativeptr)}getManagerProfileSortTime(){return t.GetManagerProfileSortTime(this.nativeptr)}getManagerProfileCanDrawTime(){return t.GetManagerProfileCanDrawTime(this.nativeptr)}getManagerProfileContainerDrawTime(){return t.GetManagerProfileContainerDrawTime(this.nativeptr)}getManagerProfileGpuParticleTime(){return t.GetManagerProfileGpuParticleTime(this.nativeptr)}getManagerProfileDrawSetCount(){return t.GetManagerProfileDrawSetCount(this.nativeptr)}getManagerProfileVisibleDrawSetCount(){return t.GetManagerProfileVisibleDrawSetCount(this.nativeptr)}getManagerProfileContainersTotal(){return t.GetManagerProfileContainersTotal(this.nativeptr)}getManagerProfileContainersDrawn(){return t.GetManagerProfileContainersDrawn(this.nativeptr)}getManagerProfileContainersDepthCulled(){return t.GetManagerProfileContainersDepthCulled(this.nativeptr)}getDrawCallCount(){return t.GetDrawCallCount(this.nativeptr)}getDrawVertexCount(){return t.GetDrawVertexCount(this.nativeptr)}getTotalParticleCount(){return t.GetTotalParticleCount(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 j(e),t&&t()}catch(e){a=!1,n=!1,l=[],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?.())}setLogEnabled(e){n&&t.SetLogEnabled(e?1:0)}setImageCrossOrigin(e){o=e}setWebGPUDevice(e){if(n||a)throw new Error("setWebGPUDevice() must be called before initRuntime().");if(null==e)return s=null,void(i=null);if("object"!=typeof e||"function"!=typeof e.createCommandEncoder||!e.queue)throw new Error("setWebGPUDevice() expects a valid GPUDevice.");s=e,i=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 i||(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,i,s,o,f){this.defaultContext.setCameraLookAt(e,t,r,n,a,i,s,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()}getUpdateTime(){return this.defaultContext.getUpdateTime()}getDrawTime(){return this.defaultContext.getDrawTime()}isVertexArrayObjectSupported(){return this.defaultContext.isVertexArrayObjectSupported()}}})();"undefined"!=typeof globalThis&&(globalThis.effekseer=effekseer),"undefined"!=typeof exports&&(exports=effekseer);