@luma.gl/shadertools 9.1.5 → 9.1.7
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/dist/dist.dev.js +5908 -3435
- package/dist/dist.min.js +72 -71
- package/dist/index.cjs +38 -37
- package/dist/index.cjs.map +3 -3
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +2 -0
- package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.js +1 -1
- package/dist/modules/lighting/lights/lighting.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +4 -4
- package/package.json +3 -3
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +2 -0
- package/src/modules/lighting/lights/lighting-uniforms-wgsl.ts +1 -1
- package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +4 -4
package/dist/dist.min.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
5
|
else if (typeof exports === 'object') exports['luma'] = factory();
|
|
6
6
|
else root['luma'] = factory();})(globalThis, function () {
|
|
7
|
-
"use strict";var __exports__=(()=>{var
|
|
7
|
+
"use strict";var __exports__=(()=>{var Ss=Object.create;var Ve=Object.defineProperty;var As=Object.getOwnPropertyDescriptor;var Ls=Object.getOwnPropertyNames;var Ts=Object.getPrototypeOf,Es=Object.prototype.hasOwnProperty;var Ms=(i,e,t)=>e in i?Ve(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var Cs=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),Ns=(i,e)=>{for(var t in e)Ve(i,t,{get:e[t],enumerable:!0})},at=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ls(e))!Es.call(i,r)&&r!==t&&Ve(i,r,{get:()=>e[r],enumerable:!(n=As(e,r))||n.enumerable});return i},ct=(i,e,t)=>(at(i,e,"default"),t&&at(t,e,"default")),Jt=(i,e,t)=>(t=i!=null?Ss(Ts(i)):{},at(e||!i||!i.__esModule?Ve(t,"default",{value:i,enumerable:!0}):t,i)),Os=i=>at(Ve({},"__esModule",{value:!0}),i);var Hn=(i,e,t)=>(Ms(i,typeof e!="symbol"?e+"":e,t),t);var lt=Cs((so,Gn)=>{Gn.exports=globalThis.luma});var ot={};Ns(ot,{ShaderAssembler:()=>Ge,_getDependencyGraph:()=>He,_resolveModules:()=>nr,assembleGLSLShaderPair:()=>ht,capitalize:()=>ve,checkShaderModuleDeprecations:()=>ze,combineInjects:()=>er,convertToVec4:()=>on,dirlight:()=>Fn,dirlight1:()=>xs,fp32:()=>ns,fp64:()=>is,fp64LowPart:()=>rt,fp64arithmetic:()=>Pn,fp64ify:()=>Fe,fp64ifyMatrix4:()=>st,fromHalfFloat:()=>Jr,generateShaderForModule:()=>_r,geometry1:()=>ds,getPassthroughFS:()=>hr,getQualifierDetails:()=>fr,getShaderInfo:()=>ft,getShaderLayoutFromWGSL:()=>Sr,getShaderModuleDependencies:()=>We,getShaderModuleSource:()=>pt,getShaderModuleUniforms:()=>tr,gouraudLighting:()=>bs,gouraudMaterial:()=>Bn,initializeShaderModule:()=>ut,initializeShaderModules:()=>le,lighting:()=>ce,lights1:()=>Ae,pbr:()=>Is,pbrMaterial:()=>ms,phongLighting:()=>ys,phongMaterial:()=>Vn,picking:()=>os,preprocess:()=>mt,project1:()=>Qt,random:()=>ts,toHalfFloat:()=>Qr,typeToChannelCount:()=>mr,typeToChannelSuffix:()=>pr});ct(ot,Jt(lt(),1));function de(i,e){if(!i)throw new Error(e||"shadertools: assertion failed.")}var en={number:{type:"number",validate(i,e){return Number.isFinite(i)&&typeof e=="object"&&(e.max===void 0||i<=e.max)&&(e.min===void 0||i>=e.min)}},array:{type:"array",validate(i,e){return Array.isArray(i)||ArrayBuffer.isView(i)}}};function jn(i){let e={};for(let[t,n]of Object.entries(i))e[t]=Ps(n);return e}function Xn(i,e,t){let n={};for(let[r,s]of Object.entries(e))i&&r in i&&!s.private?(s.validate&&de(s.validate(i[r],s),`${t}: invalid ${r}`),n[r]=i[r]):n[r]=s.value;return n}function Ps(i){let e=qn(i);if(e!=="object")return{value:i,...en[e],type:e};if(typeof i=="object")return i?i.type!==void 0?{...i,...en[i.type],type:i.type}:i.value===void 0?{type:"object",value:i}:(e=qn(i.value),{...i,...en[e],type:e}):{type:"object",value:null};throw new Error("props")}function qn(i){return Array.isArray(i)||ArrayBuffer.isView(i)?"array":typeof i}var Yn=`#ifdef MODULE_LOGDEPTH
|
|
8
8
|
logdepth_adjustPosition(gl_Position);
|
|
9
9
|
#endif
|
|
10
|
-
`,
|
|
10
|
+
`,Kn=`#ifdef MODULE_MATERIAL
|
|
11
11
|
fragColor = material_filterColor(fragColor);
|
|
12
12
|
#endif
|
|
13
13
|
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
#ifdef MODULE_LOGDEPTH
|
|
28
28
|
logdepth_setFragDepth();
|
|
29
29
|
#endif
|
|
30
|
-
`;var
|
|
30
|
+
`;var Rs={vertex:Yn,fragment:Kn},Zn=/void\s+main\s*\([^)]*\)\s*\{\n?/,Qn=/}\n?[^{}]*$/,tn=[],$e="__LUMA_INJECT_DECLARATIONS__";function Jn(i){let e={vertex:{},fragment:{}};for(let t in i){let n=i[t],r=Ds(t);typeof n=="string"&&(n={order:0,injection:n}),e[r][t]=n}return e}function Ds(i){let e=i.slice(0,2);switch(e){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(e)}}function Ue(i,e,t,n=!1){let r=e==="vertex";for(let s in t){let a=t[s];a.sort((c,l)=>c.order-l.order),tn.length=a.length;for(let c=0,l=a.length;c<l;++c)tn[c]=a[c].injection;let o=`${tn.join(`
|
|
31
31
|
`)}
|
|
32
|
-
`;switch(s){case"vs:#decl":
|
|
33
|
-
${n
|
|
32
|
+
`;switch(s){case"vs:#decl":r&&(i=i.replace($e,o));break;case"vs:#main-start":r&&(i=i.replace(Zn,c=>c+o));break;case"vs:#main-end":r&&(i=i.replace(Qn,c=>o+c));break;case"fs:#decl":r||(i=i.replace($e,o));break;case"fs:#main-start":r||(i=i.replace(Zn,c=>c+o));break;case"fs:#main-end":r||(i=i.replace(Qn,c=>o+c));break;default:i=i.replace(s,c=>c+o)}}return i=i.replace($e,""),n&&(i=i.replace(/\}\s*$/,s=>s+Rs[e])),i}function er(i){let e={};return de(Array.isArray(i)&&i.length>1),i.forEach(t=>{for(let n in t)e[n]=e[n]?`${e[n]}
|
|
33
|
+
${t[n]}`:t[n]}),e}function le(i){i.map(e=>ut(e))}function ut(i){if(i.instance)return;le(i.dependencies||[]);let{propTypes:e={},deprecations:t=[],inject:n={}}=i,r={normalizedInjections:Jn(n),parsedDeprecations:Fs(t)};e&&(r.propValidators=jn(e)),i.instance=r;let s={};e&&(s=Object.entries(e).reduce((a,[o,c])=>{let l=c?.value;return l&&(a[o]=l),a},{})),i.defaultUniforms={...i.defaultUniforms,...s}}function tr(i,e,t){ut(i);let n=t||{...i.defaultUniforms};return e&&i.getUniforms?i.getUniforms(e,n):Xn(e,i.instance?.propValidators,i.name)}function ze(i,e,t){i.deprecations?.forEach(n=>{n.regex?.test(e)&&(n.deprecated?t.deprecated(n.old,n.new)():t.removed(n.old,n.new)())})}function Fs(i){return i.forEach(e=>{switch(e.type){case"function":e.regex=new RegExp(`\\b${e.old}\\(`);break;default:e.regex=new RegExp(`${e.type} ${e.old};`)}}),i}function We(i){le(i);let e={},t={};He({modules:i,level:0,moduleMap:e,moduleDepth:t});let n=Object.keys(t).sort((r,s)=>t[s]-t[r]).map(r=>e[r]);return le(n),n}function He(i){let{modules:e,level:t,moduleMap:n,moduleDepth:r}=i;if(t>=5)throw new Error("Possible loop in shader dependency graph");for(let s of e)n[s.name]=s,(r[s.name]===void 0||r[s.name]<t)&&(r[s.name]=t);for(let s of e)s.dependencies&&He({modules:s.dependencies,level:t+1,moduleMap:n,moduleDepth:r})}function Bs(i){le(i);let e={},t={};return He({modules:i,level:0,moduleMap:e,moduleDepth:t}),i=Object.keys(t).sort((n,r)=>t[r]-t[n]).map(n=>e[n]),le(i),i}function nr(i){return Bs(i)}function rr(i){switch(i?.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
|
|
34
34
|
// Apple optimizes away the calculation necessary for emulated fp64
|
|
35
35
|
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
36
36
|
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
@@ -54,57 +54,58 @@ ${n[r]}`:n[r]}),e}function q(t){t.map(e=>Te(e))}function Te(t){if(t.instance)ret
|
|
|
54
54
|
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
55
55
|
// If the GPU doesn't have full 32 bits precision, will causes overflow
|
|
56
56
|
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
|
|
57
|
-
`}}function
|
|
58
|
-
`],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],
|
|
59
|
-
`,
|
|
60
|
-
`}
|
|
61
|
-
`}return
|
|
62
|
-
|
|
63
|
-
${
|
|
64
|
-
`,
|
|
65
|
-
`;function
|
|
57
|
+
`}}function ir(i,e){if(Number(i.match(/^#version[ \t]+(\d+)/m)?.[1]||100)!==300)throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");switch(e){case"vertex":return i=sr(i,Vs),i;case"fragment":return i=sr(i,$s),i;default:throw new Error(e)}}var or=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
|
|
58
|
+
`],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],Vs=[...or,[nn("attribute"),"in $1"],[nn("varying"),"out $1"]],$s=[...or,[nn("varying"),"in $1"]];function sr(i,e){for(let[t,n]of e)i=i.replace(t,n);return i}function nn(i){return new RegExp(`\\b${i}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function rn(i,e){let t="";for(let n in i){let r=i[n];if(t+=`void ${r.signature} {
|
|
59
|
+
`,r.header&&(t+=` ${r.header}`),e[n]){let s=e[n];s.sort((a,o)=>a.order-o.order);for(let a of s)t+=` ${a.injection}
|
|
60
|
+
`}r.footer&&(t+=` ${r.footer}`),t+=`}
|
|
61
|
+
`}return t}function sn(i){let e={vertex:{},fragment:{}};for(let t of i){let n,r;typeof t!="string"?(n=t,r=n.hook):(n={},r=t),r=r.trim();let[s,a]=r.split(":"),o=r.replace(/\(.+/,""),c=Object.assign(n,{signature:a});switch(s){case"vs":e.vertex[o]=c;break;case"fs":e.fragment[o]=c;break;default:throw new Error(s)}}return e}function ft(i,e){return{name:Us(i,e),language:"glsl",version:zs(i)}}function Us(i,e="unnamed"){let n=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(i);return n?n[1]:e}function zs(i){let e=100,t=i.match(/[^\s]+/g);if(t&&t.length>=2&&t[0]==="#version"){let n=parseInt(t[1],10);Number.isFinite(n)&&(e=n)}if(e!==100&&e!==300)throw new Error(`Invalid GLSL version ${e}`);return e}var cr=`
|
|
62
|
+
|
|
63
|
+
${$e}
|
|
64
|
+
`,Ws=`precision highp float;
|
|
65
|
+
`;function lr(i){let e=We(i.modules||[]);return{source:Hs(i.platformInfo,{...i,source:i.source,stage:"vertex",modules:e}),getUniforms:ur(e)}}function ht(i){let{vs:e,fs:t}=i,n=We(i.modules||[]);return{vs:ar(i.platformInfo,{...i,source:e,stage:"vertex",modules:n}),fs:ar(i.platformInfo,{...i,source:t,stage:"fragment",modules:n}),getUniforms:ur(n)}}function Hs(i,e){let{source:t,stage:n,modules:r,hookFunctions:s=[],inject:a={},log:o}=e;de(typeof t=="string","shader source must be a string");let c=t,l="",u=sn(s),f={},_={},b={};for(let L in a){let S=typeof a[L]=="string"?{injection:a[L],order:0}:a[L],E=/^(v|f)s:(#)?([\w-]+)$/.exec(L);if(E){let T=E[2],k=E[3];T?k==="decl"?_[L]=[S]:b[L]=[S]:f[L]=[S]}else b[L]=[S]}let w=r;for(let L of w){o&&ze(L,c,o);let S=pt(L,"wgsl");l+=S;let E=L.injections?.[n]||{};for(let T in E){let k=/^(v|f)s:#([\w-]+)$/.exec(T);if(k){let C=k[2]==="decl"?_:b;C[T]=C[T]||[],C[T].push(E[T])}else f[T]=f[T]||[],f[T].push(E[T])}}return l+=cr,l=Ue(l,n,_),l+=rn(u[n],f),l+=c,l=Ue(l,n,b),l}function ar(i,e){let{id:t,source:n,stage:r,language:s="glsl",modules:a,defines:o={},hookFunctions:c=[],inject:l={},prologue:u=!0,log:f}=e;de(typeof n=="string","shader source must be a string");let _=s==="glsl"?ft(n).version:-1,b=i.shaderLanguageVersion,w=_===100?"#version 100":"#version 300 es",S=n.split(`
|
|
66
66
|
`).slice(1).join(`
|
|
67
|
-
`),
|
|
67
|
+
`),E={};a.forEach(O=>{Object.assign(E,O.defines)}),Object.assign(E,o);let T="";switch(s){case"wgsl":break;case"glsl":T=u?`${w}
|
|
68
68
|
|
|
69
69
|
// ----- PROLOGUE -------------------------
|
|
70
|
-
${
|
|
71
|
-
${`#define SHADER_TYPE_${
|
|
70
|
+
${Gs({id:t,source:n,stage:r})}
|
|
71
|
+
${`#define SHADER_TYPE_${r.toUpperCase()}`}
|
|
72
72
|
|
|
73
|
-
${
|
|
74
|
-
${
|
|
73
|
+
${rr(i)}
|
|
74
|
+
${r==="fragment"?Ws:""}
|
|
75
75
|
|
|
76
76
|
// ----- APPLICATION DEFINES -------------------------
|
|
77
77
|
|
|
78
|
-
${
|
|
78
|
+
${qs(E)}
|
|
79
79
|
|
|
80
|
-
`:`${
|
|
81
|
-
`;break}let
|
|
82
|
-
#define SHADER_NAME ${e}_${
|
|
83
|
-
`)}return e}function
|
|
80
|
+
`:`${w}
|
|
81
|
+
`;break}let k=sn(c),I={},C={},M={};for(let O in l){let V=typeof l[O]=="string"?{injection:l[O],order:0}:l[O],F=/^(v|f)s:(#)?([\w-]+)$/.exec(O);if(F){let D=F[2],W=F[3];D?W==="decl"?C[O]=[V]:M[O]=[V]:I[O]=[V]}else M[O]=[V]}for(let O of a){f&&ze(O,S,f);let V=pt(O,r);T+=V;let F=O.instance?.normalizedInjections[r]||{};for(let D in F){let W=/^(v|f)s:#([\w-]+)$/.exec(D);if(W){let j=W[2]==="decl"?C:M;j[D]=j[D]||[],j[D].push(F[D])}else I[D]=I[D]||[],I[D].push(F[D])}}return T+="// ----- MAIN SHADER SOURCE -------------------------",T+=cr,T=Ue(T,r,C),T+=rn(k[r],I),T+=S,T=Ue(T,r,M),s==="glsl"&&_!==b&&(T=ir(T,r)),T.trim()}function ur(i){return function(t){let n={};for(let r of i){let s=r.getUniforms?.(t,n);Object.assign(n,s)}return n}}function Gs(i){let{id:e,source:t,stage:n}=i;return e&&t.indexOf("SHADER_NAME")===-1?`
|
|
82
|
+
#define SHADER_NAME ${e}_${n}`:""}function qs(i={}){let e="";for(let t in i){let n=i[t];(n||Number.isFinite(n))&&(e+=`#define ${t.toUpperCase()} ${i[t]}
|
|
83
|
+
`)}return e}function pt(i,e){let t;switch(e){case"vertex":t=i.vs||"";break;case"fragment":t=i.fs||"";break;case"wgsl":t=i.source||"";break;default:de(!1)}if(!i.name)throw new Error("Shader module must have a name");let n=i.name.toUpperCase().replace(/[^0-9a-z]/gi,"_"),r=`// ----- MODULE ${i.name} ---------------
|
|
84
84
|
|
|
85
|
-
`;return e!=="wgsl"&&(
|
|
86
|
-
`),
|
|
87
|
-
`,
|
|
88
|
-
`),
|
|
89
|
-
`)}var
|
|
85
|
+
`;return e!=="wgsl"&&(r+=`#define MODULE_${n}
|
|
86
|
+
`),r+=`${t}
|
|
87
|
+
`,r}var js=/^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/,Xs=/^\s*\#\s*endif\s*$/;function mt(i,e){let t=i.split(`
|
|
88
|
+
`),n=[],r=!0,s=null;for(let a of t){let o=a.match(js),c=a.match(Xs);o?(s=o[1],r=Boolean(e?.defines?.[s])):c?r=!0:r&&n.push(a)}return n.join(`
|
|
89
|
+
`)}var Le=class{_hookFunctions=[];_defaultModules=[];static getDefaultShaderAssembler(){return Le.defaultShaderAssembler=Le.defaultShaderAssembler||new Le,Le.defaultShaderAssembler}addDefaultModule(e){this._defaultModules.find(t=>t.name===(typeof e=="string"?e:e.name))||this._defaultModules.push(e)}removeDefaultModule(e){let t=typeof e=="string"?e:e.name;this._defaultModules=this._defaultModules.filter(n=>n.name!==t)}addShaderHook(e,t){t&&(e=Object.assign(t,{hook:e})),this._hookFunctions.push(e)}assembleWGSLShader(e){let t=this._getModuleList(e.modules),n=this._hookFunctions,{source:r,getUniforms:s}=lr({...e,source:e.source,modules:t,hookFunctions:n});return{source:e.platformInfo.shaderLanguage==="wgsl"?mt(r):r,getUniforms:s,modules:t}}assembleGLSLShaderPair(e){let t=this._getModuleList(e.modules),n=this._hookFunctions;return{...ht({...e,vs:e.vs,fs:e.fs,modules:t,hookFunctions:n}),modules:t}}_getModuleList(e=[]){let t=new Array(this._defaultModules.length+e.length),n={},r=0;for(let s=0,a=this._defaultModules.length;s<a;++s){let o=this._defaultModules[s],c=o.name;t[r++]=o,n[c]=!0}for(let s=0,a=e.length;s<a;++s){let o=e[s],c=o.name;n[c]||(t[r++]=o,n[c]=!0)}return t.length=r,le(t),t}},Ge=Le;Hn(Ge,"defaultShaderAssembler");var Ys=`out vec4 transform_output;
|
|
90
90
|
void main() {
|
|
91
91
|
transform_output = vec4(0);
|
|
92
|
-
}`,
|
|
93
|
-
${
|
|
94
|
-
in ${
|
|
95
|
-
out vec4 ${
|
|
92
|
+
}`,Ks=`#version 300 es
|
|
93
|
+
${Ys}`;function fr(i,e){e=Array.isArray(e)?e:[e];let t=i.replace(/^\s+/,"").split(/\s+/),[n,r,s]=t;if(!e.includes(n)||!r||!s)return null;let a=s.split(";")[0];return{qualifier:n,type:r,name:a}}function hr(i){let{input:e,inputChannels:t,output:n}=i||{};if(!e)return Ks;if(!t)throw new Error("inputChannels");let r=Zs(t),s=on(e,t);return`#version 300 es
|
|
94
|
+
in ${r} ${e};
|
|
95
|
+
out vec4 ${n};
|
|
96
96
|
void main() {
|
|
97
|
-
${
|
|
98
|
-
}`}function
|
|
99
|
-
`)}function
|
|
100
|
-
`)}function Vn(t,e){switch(e.shaderLanguage){case"glsl":return Gn(t,e);case"wgsl":return qn(t,e)}}var jn=lt(Pe(),1);var mt=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},B=class{constructor(){}get isAstNode(){return!0}get astNodeType(){return""}evaluate(e){throw new Error("Cannot evaluate node")}evaluateString(e){return this.evaluate(e).toString()}search(e){}searchBlock(e,n){if(e){n(oe.instance);for(let r of e)r instanceof Array?this.searchBlock(r,n):r.search(n);n(ae.instance)}}},oe=class extends B{};oe.instance=new oe;var ae=class extends B{};ae.instance=new ae;var E=class extends B{constructor(){super()}},ye=class extends E{constructor(e,n,r,i,s,a){super(),this.calls=new Set,this.name=e,this.args=n,this.returnType=r,this.body=i,this.startLine=s,this.endLine=a}get astNodeType(){return"function"}search(e){this.searchBlock(this.body,e)}},gt=class extends E{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}},vt=class extends E{constructor(e,n){super(),this.condition=e,this.body=n}get astNodeType(){return"while"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},xt=class extends E{constructor(e){super(),this.body=e}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}},bt=class extends E{constructor(e,n,r,i){super(),this.init=e,this.condition=n,this.increment=r,this.body=i}get astNodeType(){return"for"}search(e){var n,r,i;(n=this.init)===null||n===void 0||n.search(e),(r=this.condition)===null||r===void 0||r.search(e),(i=this.increment)===null||i===void 0||i.search(e),this.searchBlock(this.body,e)}},H=class extends E{constructor(e,n,r,i,s){super(),this.name=e,this.type=n,this.storage=r,this.access=i,this.value=s}get astNodeType(){return"var"}search(e){var n;e(this),(n=this.value)===null||n===void 0||n.search(e)}},De=class extends E{constructor(e,n,r){super(),this.name=e,this.type=n,this.value=r}get astNodeType(){return"override"}search(e){var n;(n=this.value)===null||n===void 0||n.search(e)}},we=class extends E{constructor(e,n,r,i,s){super(),this.name=e,this.type=n,this.storage=r,this.access=i,this.value=s}get astNodeType(){return"let"}search(e){var n;e(this),(n=this.value)===null||n===void 0||n.search(e)}},ze=class extends E{constructor(e,n,r,i,s){super(),this.name=e,this.type=n,this.storage=r,this.access=i,this.value=s}get astNodeType(){return"const"}evaluate(e){return this.value.evaluate(e)}search(e){var n;e(this),(n=this.value)===null||n===void 0||n.search(e)}},ce;(function(t){t.increment="++",t.decrement="--"})(ce||(ce={}));(function(t){function e(n){let r=n;if(r=="parse")throw new Error("Invalid value for IncrementOperator");return t[r]}t.parse=e})(ce||(ce={}));var yt=class extends E{constructor(e,n){super(),this.operator=e,this.variable=n}get astNodeType(){return"increment"}search(e){this.variable.search(e)}},ke;(function(t){t.assign="=",t.addAssign="+=",t.subtractAssin="-=",t.multiplyAssign="*=",t.divideAssign="/=",t.moduloAssign="%=",t.andAssign="&=",t.orAssign="|=",t.xorAssign="^=",t.shiftLeftAssign="<<=",t.shiftRightAssign=">>="})(ke||(ke={}));(function(t){function e(n){let r=n;if(r=="parse")throw new Error("Invalid value for AssignOperator");return r}t.parse=e})(ke||(ke={}));var wt=class extends E{constructor(e,n,r){super(),this.operator=e,this.variable=n,this.value=r}get astNodeType(){return"assign"}search(e){this.variable.search(e),this.value.search(e)}},Ue=class extends E{constructor(e,n){super(),this.name=e,this.args=n}get astNodeType(){return"call"}search(e){for(let n of this.args)n.search(e);e(this)}},kt=class extends E{constructor(e,n){super(),this.body=e,this.continuing=n}get astNodeType(){return"loop"}},Lt=class extends E{constructor(e,n){super(),this.condition=e,this.body=n}get astNodeType(){return"body"}},At=class extends E{constructor(e,n,r,i){super(),this.condition=e,this.body=n,this.elseif=r,this.else=i}get astNodeType(){return"if"}search(e){this.condition.search(e),this.searchBlock(this.body,e),this.searchBlock(this.elseif,e),this.searchBlock(this.else,e)}},Mt=class extends E{constructor(e){super(),this.value=e}get astNodeType(){return"return"}search(e){var n;(n=this.value)===null||n===void 0||n.search(e)}},St=class extends E{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}},Et=class extends E{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}},It=class extends E{constructor(e,n){super(),this.severity=e,this.rule=n}get astNodeType(){return"diagnostic"}},Be=class extends E{constructor(e,n){super(),this.name=e,this.type=n}get astNodeType(){return"alias"}},Nt=class extends E{constructor(){super()}get astNodeType(){return"discard"}},Pt=class extends E{constructor(){super()}get astNodeType(){return"break"}},Tt=class extends E{constructor(){super()}get astNodeType(){return"continue"}},j=class extends E{constructor(e){super(),this.name=e}get astNodeType(){return"type"}get isStruct(){return!1}get isArray(){return!1}},V=class extends j{constructor(e,n,r,i){super(e),this.members=n,this.startLine=r,this.endLine=i}get astNodeType(){return"struct"}get isStruct(){return!0}getMemberIndex(e){for(let n=0;n<this.members.length;n++)if(this.members[n].name==e)return n;return-1}},Ge=class extends j{constructor(e,n,r){super(e),this.format=n,this.access=r}get astNodeType(){return"template"}},Rt=class extends j{constructor(e,n,r,i){super(e),this.storage=n,this.type=r,this.access=i}get astNodeType(){return"pointer"}},qe=class extends j{constructor(e,n,r,i){super(e),this.attributes=n,this.format=r,this.count=i}get astNodeType(){return"array"}get isArray(){return!0}},J=class extends j{constructor(e,n,r){super(e),this.format=n,this.access=r}get astNodeType(){return"sampler"}},F=class extends B{constructor(){super()}},Ve=class extends F{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}evaluateString(){return this.value}},K=class extends F{constructor(e,n){super(),this.type=e,this.args=n}get astNodeType(){return"createExpr"}search(e){e(this);for(let n of this.args)n.search(e)}},He=class extends F{constructor(e,n){super(),this.name=e,this.args=n}get astNodeType(){return"callExpr"}evaluate(e){switch(this.name){case"abs":return Math.abs(this.args[0].evaluate(e));case"acos":return Math.acos(this.args[0].evaluate(e));case"acosh":return Math.acosh(this.args[0].evaluate(e));case"asin":return Math.asin(this.args[0].evaluate(e));case"asinh":return Math.asinh(this.args[0].evaluate(e));case"atan":return Math.atan(this.args[0].evaluate(e));case"atan2":return Math.atan2(this.args[0].evaluate(e),this.args[1].evaluate(e));case"atanh":return Math.atanh(this.args[0].evaluate(e));case"ceil":return Math.ceil(this.args[0].evaluate(e));case"clamp":return Math.min(Math.max(this.args[0].evaluate(e),this.args[1].evaluate(e)),this.args[2].evaluate(e));case"cos":return Math.cos(this.args[0].evaluate(e));case"degrees":return this.args[0].evaluate(e)*180/Math.PI;case"distance":return Math.sqrt(Math.pow(this.args[0].evaluate(e)-this.args[1].evaluate(e),2));case"dot":case"exp":return Math.exp(this.args[0].evaluate(e));case"exp2":return Math.pow(2,this.args[0].evaluate(e));case"floor":return Math.floor(this.args[0].evaluate(e));case"fma":return this.args[0].evaluate(e)*this.args[1].evaluate(e)+this.args[2].evaluate(e);case"fract":return this.args[0].evaluate(e)-Math.floor(this.args[0].evaluate(e));case"inverseSqrt":return 1/Math.sqrt(this.args[0].evaluate(e));case"log":return Math.log(this.args[0].evaluate(e));case"log2":return Math.log2(this.args[0].evaluate(e));case"max":return Math.max(this.args[0].evaluate(e),this.args[1].evaluate(e));case"min":return Math.min(this.args[0].evaluate(e),this.args[1].evaluate(e));case"mix":return this.args[0].evaluate(e)*(1-this.args[2].evaluate(e))+this.args[1].evaluate(e)*this.args[2].evaluate(e);case"modf":return this.args[0].evaluate(e)-Math.floor(this.args[0].evaluate(e));case"pow":return Math.pow(this.args[0].evaluate(e),this.args[1].evaluate(e));case"radians":return this.args[0].evaluate(e)*Math.PI/180;case"round":return Math.round(this.args[0].evaluate(e));case"sign":return Math.sign(this.args[0].evaluate(e));case"sin":return Math.sin(this.args[0].evaluate(e));case"sinh":return Math.sinh(this.args[0].evaluate(e));case"saturate":return Math.min(Math.max(this.args[0].evaluate(e),0),1);case"smoothstep":return this.args[0].evaluate(e)*this.args[0].evaluate(e)*(3-2*this.args[0].evaluate(e));case"sqrt":return Math.sqrt(this.args[0].evaluate(e));case"step":return this.args[0].evaluate(e)<this.args[1].evaluate(e)?0:1;case"tan":return Math.tan(this.args[0].evaluate(e));case"tanh":return Math.tanh(this.args[0].evaluate(e));case"trunc":return Math.trunc(this.args[0].evaluate(e));default:throw new Error("Non const function: "+this.name)}}search(e){for(let n of this.args)n.search(e);e(this)}},Le=class extends F{constructor(e){super(),this.name=e}get astNodeType(){return"varExpr"}search(e){e(this),this.postfix&&this.postfix.search(e)}evaluate(e){let n=e.constants.get(this.name);if(!n)throw new Error("Cannot evaluate node");return n.evaluate(e)}},je=class extends F{constructor(e,n){super(),this.name=e,this.initializer=n}get astNodeType(){return"constExpr"}evaluate(e){var n,r;if(this.initializer instanceof K){let i=(n=this.postfix)===null||n===void 0?void 0:n.evaluateString(e),s=(r=this.initializer.type)===null||r===void 0?void 0:r.name,a=e.structs.get(s),c=a?.getMemberIndex(i);if(c!=-1)return this.initializer.args[c].evaluate(e);console.log(c)}return this.initializer.evaluate(e)}search(e){this.initializer.search(e)}},We=class extends F{constructor(e){super(),this.value=e}get astNodeType(){return"literalExpr"}evaluate(){return this.value}},Ot=class extends F{constructor(e,n){super(),this.type=e,this.value=n}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}},Ct=class extends F{constructor(e,n){super(),this.type=e,this.args=n}get astNodeType(){return"typecastExpr"}evaluate(e){return this.args[0].evaluate(e)}search(e){this.searchBlock(this.args,e)}},$e=class extends F{constructor(e){super(),this.contents=e}get astNodeType(){return"groupExpr"}evaluate(e){return this.contents[0].evaluate(e)}search(e){this.searchBlock(this.contents,e)}},Ft=class extends F{constructor(e){super(),this.index=e}search(e){this.index.search(e)}},Ye=class extends F{constructor(){super()}},Dt=class extends Ye{constructor(e,n){super(),this.operator=e,this.right=n}get astNodeType(){return"unaryOp"}evaluate(e){switch(this.operator){case"+":return this.right.evaluate(e);case"-":return-this.right.evaluate(e);case"!":return this.right.evaluate(e)?0:1;case"~":return~this.right.evaluate(e);default:throw new Error("Unknown unary operator: "+this.operator)}}search(e){this.right.search(e)}},z=class extends Ye{constructor(e,n,r){super(),this.operator=e,this.left=n,this.right=r}get astNodeType(){return"binaryOp"}evaluate(e){switch(this.operator){case"+":return this.left.evaluate(e)+this.right.evaluate(e);case"-":return this.left.evaluate(e)-this.right.evaluate(e);case"*":return this.left.evaluate(e)*this.right.evaluate(e);case"/":return this.left.evaluate(e)/this.right.evaluate(e);case"%":return this.left.evaluate(e)%this.right.evaluate(e);case"==":return this.left.evaluate(e)==this.right.evaluate(e)?1:0;case"!=":return this.left.evaluate(e)!=this.right.evaluate(e)?1:0;case"<":return this.left.evaluate(e)<this.right.evaluate(e)?1:0;case">":return this.left.evaluate(e)>this.right.evaluate(e)?1:0;case"<=":return this.left.evaluate(e)<=this.right.evaluate(e)?1:0;case">=":return this.left.evaluate(e)>=this.right.evaluate(e)?1:0;case"&&":return this.left.evaluate(e)&&this.right.evaluate(e)?1:0;case"||":return this.left.evaluate(e)||this.right.evaluate(e)?1:0;default:throw new Error(`Unknown operator ${this.operator}`)}}search(e){this.left.search(e),this.right.search(e)}},Ke=class extends B{constructor(){super()}},zt=class extends Ke{constructor(e,n){super(),this.selector=e,this.body=n}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}},Ut=class extends Ke{constructor(e){super(),this.body=e}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}},Bt=class extends B{constructor(e,n,r){super(),this.name=e,this.type=n,this.attributes=r}get astNodeType(){return"argument"}},Gt=class extends B{constructor(e,n){super(),this.condition=e,this.body=n}get astNodeType(){return"elseif"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},qt=class extends B{constructor(e,n,r){super(),this.name=e,this.type=n,this.attributes=r}get astNodeType(){return"member"}},Vt=class extends B{constructor(e,n){super(),this.name=e,this.value=n}get astNodeType(){return"attribute"}},u,f;(function(t){t[t.token=0]="token",t[t.keyword=1]="keyword",t[t.reserved=2]="reserved"})(f||(f={}));var l=class{constructor(e,n,r){this.name=e,this.type=n,this.rule=r}toString(){return this.name}},o=class{};u=o;o.none=new l("",f.reserved,"");o.eof=new l("EOF",f.token,"");o.reserved={asm:new l("asm",f.reserved,"asm"),bf16:new l("bf16",f.reserved,"bf16"),do:new l("do",f.reserved,"do"),enum:new l("enum",f.reserved,"enum"),f16:new l("f16",f.reserved,"f16"),f64:new l("f64",f.reserved,"f64"),handle:new l("handle",f.reserved,"handle"),i8:new l("i8",f.reserved,"i8"),i16:new l("i16",f.reserved,"i16"),i64:new l("i64",f.reserved,"i64"),mat:new l("mat",f.reserved,"mat"),premerge:new l("premerge",f.reserved,"premerge"),regardless:new l("regardless",f.reserved,"regardless"),typedef:new l("typedef",f.reserved,"typedef"),u8:new l("u8",f.reserved,"u8"),u16:new l("u16",f.reserved,"u16"),u64:new l("u64",f.reserved,"u64"),unless:new l("unless",f.reserved,"unless"),using:new l("using",f.reserved,"using"),vec:new l("vec",f.reserved,"vec"),void:new l("void",f.reserved,"void")};o.keywords={array:new l("array",f.keyword,"array"),atomic:new l("atomic",f.keyword,"atomic"),bool:new l("bool",f.keyword,"bool"),f32:new l("f32",f.keyword,"f32"),i32:new l("i32",f.keyword,"i32"),mat2x2:new l("mat2x2",f.keyword,"mat2x2"),mat2x3:new l("mat2x3",f.keyword,"mat2x3"),mat2x4:new l("mat2x4",f.keyword,"mat2x4"),mat3x2:new l("mat3x2",f.keyword,"mat3x2"),mat3x3:new l("mat3x3",f.keyword,"mat3x3"),mat3x4:new l("mat3x4",f.keyword,"mat3x4"),mat4x2:new l("mat4x2",f.keyword,"mat4x2"),mat4x3:new l("mat4x3",f.keyword,"mat4x3"),mat4x4:new l("mat4x4",f.keyword,"mat4x4"),ptr:new l("ptr",f.keyword,"ptr"),sampler:new l("sampler",f.keyword,"sampler"),sampler_comparison:new l("sampler_comparison",f.keyword,"sampler_comparison"),struct:new l("struct",f.keyword,"struct"),texture_1d:new l("texture_1d",f.keyword,"texture_1d"),texture_2d:new l("texture_2d",f.keyword,"texture_2d"),texture_2d_array:new l("texture_2d_array",f.keyword,"texture_2d_array"),texture_3d:new l("texture_3d",f.keyword,"texture_3d"),texture_cube:new l("texture_cube",f.keyword,"texture_cube"),texture_cube_array:new l("texture_cube_array",f.keyword,"texture_cube_array"),texture_multisampled_2d:new l("texture_multisampled_2d",f.keyword,"texture_multisampled_2d"),texture_storage_1d:new l("texture_storage_1d",f.keyword,"texture_storage_1d"),texture_storage_2d:new l("texture_storage_2d",f.keyword,"texture_storage_2d"),texture_storage_2d_array:new l("texture_storage_2d_array",f.keyword,"texture_storage_2d_array"),texture_storage_3d:new l("texture_storage_3d",f.keyword,"texture_storage_3d"),texture_depth_2d:new l("texture_depth_2d",f.keyword,"texture_depth_2d"),texture_depth_2d_array:new l("texture_depth_2d_array",f.keyword,"texture_depth_2d_array"),texture_depth_cube:new l("texture_depth_cube",f.keyword,"texture_depth_cube"),texture_depth_cube_array:new l("texture_depth_cube_array",f.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new l("texture_depth_multisampled_2d",f.keyword,"texture_depth_multisampled_2d"),texture_external:new l("texture_external",f.keyword,"texture_external"),u32:new l("u32",f.keyword,"u32"),vec2:new l("vec2",f.keyword,"vec2"),vec3:new l("vec3",f.keyword,"vec3"),vec4:new l("vec4",f.keyword,"vec4"),bitcast:new l("bitcast",f.keyword,"bitcast"),block:new l("block",f.keyword,"block"),break:new l("break",f.keyword,"break"),case:new l("case",f.keyword,"case"),continue:new l("continue",f.keyword,"continue"),continuing:new l("continuing",f.keyword,"continuing"),default:new l("default",f.keyword,"default"),diagnostic:new l("diagnostic",f.keyword,"diagnostic"),discard:new l("discard",f.keyword,"discard"),else:new l("else",f.keyword,"else"),enable:new l("enable",f.keyword,"enable"),fallthrough:new l("fallthrough",f.keyword,"fallthrough"),false:new l("false",f.keyword,"false"),fn:new l("fn",f.keyword,"fn"),for:new l("for",f.keyword,"for"),function:new l("function",f.keyword,"function"),if:new l("if",f.keyword,"if"),let:new l("let",f.keyword,"let"),const:new l("const",f.keyword,"const"),loop:new l("loop",f.keyword,"loop"),while:new l("while",f.keyword,"while"),private:new l("private",f.keyword,"private"),read:new l("read",f.keyword,"read"),read_write:new l("read_write",f.keyword,"read_write"),return:new l("return",f.keyword,"return"),requires:new l("requires",f.keyword,"requires"),storage:new l("storage",f.keyword,"storage"),switch:new l("switch",f.keyword,"switch"),true:new l("true",f.keyword,"true"),alias:new l("alias",f.keyword,"alias"),type:new l("type",f.keyword,"type"),uniform:new l("uniform",f.keyword,"uniform"),var:new l("var",f.keyword,"var"),override:new l("override",f.keyword,"override"),workgroup:new l("workgroup",f.keyword,"workgroup"),write:new l("write",f.keyword,"write"),r8unorm:new l("r8unorm",f.keyword,"r8unorm"),r8snorm:new l("r8snorm",f.keyword,"r8snorm"),r8uint:new l("r8uint",f.keyword,"r8uint"),r8sint:new l("r8sint",f.keyword,"r8sint"),r16uint:new l("r16uint",f.keyword,"r16uint"),r16sint:new l("r16sint",f.keyword,"r16sint"),r16float:new l("r16float",f.keyword,"r16float"),rg8unorm:new l("rg8unorm",f.keyword,"rg8unorm"),rg8snorm:new l("rg8snorm",f.keyword,"rg8snorm"),rg8uint:new l("rg8uint",f.keyword,"rg8uint"),rg8sint:new l("rg8sint",f.keyword,"rg8sint"),r32uint:new l("r32uint",f.keyword,"r32uint"),r32sint:new l("r32sint",f.keyword,"r32sint"),r32float:new l("r32float",f.keyword,"r32float"),rg16uint:new l("rg16uint",f.keyword,"rg16uint"),rg16sint:new l("rg16sint",f.keyword,"rg16sint"),rg16float:new l("rg16float",f.keyword,"rg16float"),rgba8unorm:new l("rgba8unorm",f.keyword,"rgba8unorm"),rgba8unorm_srgb:new l("rgba8unorm_srgb",f.keyword,"rgba8unorm_srgb"),rgba8snorm:new l("rgba8snorm",f.keyword,"rgba8snorm"),rgba8uint:new l("rgba8uint",f.keyword,"rgba8uint"),rgba8sint:new l("rgba8sint",f.keyword,"rgba8sint"),bgra8unorm:new l("bgra8unorm",f.keyword,"bgra8unorm"),bgra8unorm_srgb:new l("bgra8unorm_srgb",f.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new l("rgb10a2unorm",f.keyword,"rgb10a2unorm"),rg11b10float:new l("rg11b10float",f.keyword,"rg11b10float"),rg32uint:new l("rg32uint",f.keyword,"rg32uint"),rg32sint:new l("rg32sint",f.keyword,"rg32sint"),rg32float:new l("rg32float",f.keyword,"rg32float"),rgba16uint:new l("rgba16uint",f.keyword,"rgba16uint"),rgba16sint:new l("rgba16sint",f.keyword,"rgba16sint"),rgba16float:new l("rgba16float",f.keyword,"rgba16float"),rgba32uint:new l("rgba32uint",f.keyword,"rgba32uint"),rgba32sint:new l("rgba32sint",f.keyword,"rgba32sint"),rgba32float:new l("rgba32float",f.keyword,"rgba32float"),static_assert:new l("static_assert",f.keyword,"static_assert")};o.tokens={decimal_float_literal:new l("decimal_float_literal",f.token,/((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?f?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+f?)|([0-9]+f)/),hex_float_literal:new l("hex_float_literal",f.token,/-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+f?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+f?))/),int_literal:new l("int_literal",f.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new l("uint_literal",f.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),ident:new l("ident",f.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new l("and",f.token,"&"),and_and:new l("and_and",f.token,"&&"),arrow:new l("arrow ",f.token,"->"),attr:new l("attr",f.token,"@"),forward_slash:new l("forward_slash",f.token,"/"),bang:new l("bang",f.token,"!"),bracket_left:new l("bracket_left",f.token,"["),bracket_right:new l("bracket_right",f.token,"]"),brace_left:new l("brace_left",f.token,"{"),brace_right:new l("brace_right",f.token,"}"),colon:new l("colon",f.token,":"),comma:new l("comma",f.token,","),equal:new l("equal",f.token,"="),equal_equal:new l("equal_equal",f.token,"=="),not_equal:new l("not_equal",f.token,"!="),greater_than:new l("greater_than",f.token,">"),greater_than_equal:new l("greater_than_equal",f.token,">="),shift_right:new l("shift_right",f.token,">>"),less_than:new l("less_than",f.token,"<"),less_than_equal:new l("less_than_equal",f.token,"<="),shift_left:new l("shift_left",f.token,"<<"),modulo:new l("modulo",f.token,"%"),minus:new l("minus",f.token,"-"),minus_minus:new l("minus_minus",f.token,"--"),period:new l("period",f.token,"."),plus:new l("plus",f.token,"+"),plus_plus:new l("plus_plus",f.token,"++"),or:new l("or",f.token,"|"),or_or:new l("or_or",f.token,"||"),paren_left:new l("paren_left",f.token,"("),paren_right:new l("paren_right",f.token,")"),semicolon:new l("semicolon",f.token,";"),star:new l("star",f.token,"*"),tilde:new l("tilde",f.token,"~"),underscore:new l("underscore",f.token,"_"),xor:new l("xor",f.token,"^"),plus_equal:new l("plus_equal",f.token,"+="),minus_equal:new l("minus_equal",f.token,"-="),times_equal:new l("times_equal",f.token,"*="),division_equal:new l("division_equal",f.token,"/="),modulo_equal:new l("modulo_equal",f.token,"%="),and_equal:new l("and_equal",f.token,"&="),or_equal:new l("or_equal",f.token,"|="),xor_equal:new l("xor_equal",f.token,"^="),shift_right_equal:new l("shift_right_equal",f.token,">>="),shift_left_equal:new l("shift_left_equal",f.token,"<<=")};o.simpleTokens={"@":u.tokens.attr,"{":u.tokens.brace_left,"}":u.tokens.brace_right,":":u.tokens.colon,",":u.tokens.comma,"(":u.tokens.paren_left,")":u.tokens.paren_right,";":u.tokens.semicolon};o.literalTokens={"&":u.tokens.and,"&&":u.tokens.and_and,"->":u.tokens.arrow,"/":u.tokens.forward_slash,"!":u.tokens.bang,"[":u.tokens.bracket_left,"]":u.tokens.bracket_right,"=":u.tokens.equal,"==":u.tokens.equal_equal,"!=":u.tokens.not_equal,">":u.tokens.greater_than,">=":u.tokens.greater_than_equal,">>":u.tokens.shift_right,"<":u.tokens.less_than,"<=":u.tokens.less_than_equal,"<<":u.tokens.shift_left,"%":u.tokens.modulo,"-":u.tokens.minus,"--":u.tokens.minus_minus,".":u.tokens.period,"+":u.tokens.plus,"++":u.tokens.plus_plus,"|":u.tokens.or,"||":u.tokens.or_or,"*":u.tokens.star,"~":u.tokens.tilde,_:u.tokens.underscore,"^":u.tokens.xor,"+=":u.tokens.plus_equal,"-=":u.tokens.minus_equal,"*=":u.tokens.times_equal,"/=":u.tokens.division_equal,"%=":u.tokens.modulo_equal,"&=":u.tokens.and_equal,"|=":u.tokens.or_equal,"^=":u.tokens.xor_equal,">>=":u.tokens.shift_right_equal,"<<=":u.tokens.shift_left_equal};o.regexTokens={decimal_float_literal:u.tokens.decimal_float_literal,hex_float_literal:u.tokens.hex_float_literal,int_literal:u.tokens.int_literal,uint_literal:u.tokens.uint_literal,ident:u.tokens.ident};o.storage_class=[u.keywords.function,u.keywords.private,u.keywords.workgroup,u.keywords.uniform,u.keywords.storage];o.access_mode=[u.keywords.read,u.keywords.write,u.keywords.read_write];o.sampler_type=[u.keywords.sampler,u.keywords.sampler_comparison];o.sampled_texture_type=[u.keywords.texture_1d,u.keywords.texture_2d,u.keywords.texture_2d_array,u.keywords.texture_3d,u.keywords.texture_cube,u.keywords.texture_cube_array];o.multisampled_texture_type=[u.keywords.texture_multisampled_2d];o.storage_texture_type=[u.keywords.texture_storage_1d,u.keywords.texture_storage_2d,u.keywords.texture_storage_2d_array,u.keywords.texture_storage_3d];o.depth_texture_type=[u.keywords.texture_depth_2d,u.keywords.texture_depth_2d_array,u.keywords.texture_depth_cube,u.keywords.texture_depth_cube_array,u.keywords.texture_depth_multisampled_2d];o.texture_external_type=[u.keywords.texture_external];o.any_texture_type=[...u.sampled_texture_type,...u.multisampled_texture_type,...u.storage_texture_type,...u.depth_texture_type,...u.texture_external_type];o.texel_format=[u.keywords.r8unorm,u.keywords.r8snorm,u.keywords.r8uint,u.keywords.r8sint,u.keywords.r16uint,u.keywords.r16sint,u.keywords.r16float,u.keywords.rg8unorm,u.keywords.rg8snorm,u.keywords.rg8uint,u.keywords.rg8sint,u.keywords.r32uint,u.keywords.r32sint,u.keywords.r32float,u.keywords.rg16uint,u.keywords.rg16sint,u.keywords.rg16float,u.keywords.rgba8unorm,u.keywords.rgba8unorm_srgb,u.keywords.rgba8snorm,u.keywords.rgba8uint,u.keywords.rgba8sint,u.keywords.bgra8unorm,u.keywords.bgra8unorm_srgb,u.keywords.rgb10a2unorm,u.keywords.rg11b10float,u.keywords.rg32uint,u.keywords.rg32sint,u.keywords.rg32float,u.keywords.rgba16uint,u.keywords.rgba16sint,u.keywords.rgba16float,u.keywords.rgba32uint,u.keywords.rgba32sint,u.keywords.rgba32float];o.const_literal=[u.tokens.int_literal,u.tokens.uint_literal,u.tokens.decimal_float_literal,u.tokens.hex_float_literal,u.keywords.true,u.keywords.false];o.literal_or_ident=[u.tokens.ident,u.tokens.int_literal,u.tokens.uint_literal,u.tokens.decimal_float_literal,u.tokens.hex_float_literal];o.element_count_expression=[u.tokens.int_literal,u.tokens.uint_literal,u.tokens.ident];o.template_types=[u.keywords.vec2,u.keywords.vec3,u.keywords.vec4,u.keywords.mat2x2,u.keywords.mat2x3,u.keywords.mat2x4,u.keywords.mat3x2,u.keywords.mat3x3,u.keywords.mat3x4,u.keywords.mat4x2,u.keywords.mat4x3,u.keywords.mat4x4,u.keywords.atomic,u.keywords.bitcast,...u.any_texture_type];o.attribute_name=[u.tokens.ident,u.keywords.block,u.keywords.diagnostic];o.assignment_operators=[u.tokens.equal,u.tokens.plus_equal,u.tokens.minus_equal,u.tokens.times_equal,u.tokens.division_equal,u.tokens.modulo_equal,u.tokens.and_equal,u.tokens.or_equal,u.tokens.xor_equal,u.tokens.shift_right_equal,u.tokens.shift_left_equal];o.increment_operators=[u.tokens.plus_plus,u.tokens.minus_minus];var Xe=class{constructor(e,n,r){this.type=e,this.lexeme=n,this.line=r}toString(){return this.lexeme}isTemplateType(){return o.template_types.indexOf(this.type)!=-1}isArrayType(){return this.type==o.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}},Ht=class{constructor(e){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=e??""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new Xe(o.eof,"",this._line)),this._tokens}scanToken(){let e=this._advance();if(e==`
|
|
97
|
+
${n} = ${s};
|
|
98
|
+
}`}function pr(i){switch(i){case"float":return"x";case"vec2":return"xy";case"vec3":return"xyz";case"vec4":return"xyzw";default:throw new Error(i)}}function mr(i){switch(i){case"float":return 1;case"vec2":return 2;case"vec3":return 3;case"vec4":return 4;default:throw new Error(i)}}function Zs(i){switch(i){case 1:return"float";case 2:return"vec2";case 3:return"vec3";case 4:return"vec4";default:throw new Error(`invalid channels: ${i}`)}}function on(i,e){switch(e){case 1:return`vec4(${i}, 0.0, 0.0, 1.0)`;case 2:return`vec4(${i}, 0.0, 1.0)`;case 3:return`vec4(${i}, 1.0)`;case 4:return i;default:throw new Error(`invalid channels: ${e}`)}}function ve(i){return typeof i=="string"?i.charAt(0).toUpperCase()+i.slice(1):i}function dr(i,e){return Qs(i,e)}function Qs(i,e){let t=[];switch(e.uniforms){case"scoped-interface-blocks":case"unscoped-interface-blocks":t.push(`uniform ${ve(i.name)} {`);break;case"uniforms":}for(let[n,r]of Object.entries(i.uniformTypes||{})){let s=Js(r);switch(e.uniforms){case"scoped-interface-blocks":t.push(` ${s} ${n};`);break;case"unscoped-interface-blocks":t.push(` ${s} ${i.name}_${n};`);break;case"uniforms":t.push(`uniform ${s} ${i.name}_${n};`)}}switch(e.uniforms){case"scoped-interface-blocks":t.push(`} ${i.name};`);break;case"unscoped-interface-blocks":t.push("};");break;case"uniforms":}return t.push(""),t.join(`
|
|
99
|
+
`)}function Js(i){return{f32:"float",i32:"int",u32:"uint","vec2<f32>":"vec2","vec3<f32>":"vec3","vec4<f32>":"vec4","vec2<i32>":"ivec2","vec3<i32>":"ivec3","vec4<i32>":"ivec4","vec2<u32>":"uvec2","vec3<u32>":"uvec3","vec4<u32>":"uvec4","mat2x2<f32>":"mat2","mat2x3<f32>":"mat2x3","mat2x4<f32>":"mat2x4","mat3x2<f32>":"mat3x2","mat3x3<f32>":"mat3","mat3x4<f32>":"mat3x4","mat4x2<f32>":"mat4x2","mat4x3<f32>":"mat4x3","mat4x4<f32>":"mat4"}[i]}function gr(i,e){return ei(i,e)}function ei(i,e){let t=[];t.push(`struct ${ve(i.name)} {`);for(let[n,r]of Object.entries(i?.uniformTypes||{})){let s=r;t.push(` ${n} : ${s};`)}return t.push("};"),t.push(`var<uniform> ${i.name} : ${ve(i.name)};`),t.join(`
|
|
100
|
+
`)}function _r(i,e){switch(e.shaderLanguage){case"glsl":return dr(i,e);case"wgsl":return gr(i,e)}}var Ir=Jt(lt(),1);var Z=class{constructor(e,t){this.name=e,this.attributes=t,this.size=0}get isArray(){return!1}get isStruct(){return!1}get isTemplate(){return!1}getTypeName(){return this.name}},dt=class{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n,this.offset=0,this.size=0}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray||this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},ue=class extends Z{constructor(e,t){super(e,t),this.members=[],this.align=0,this.startLine=-1,this.endLine=-1,this.inUse=!1}get isStruct(){return!0}},fe=class extends Z{constructor(e,t){super(e,t),this.count=0,this.stride=0}get isArray(){return!0}},he=class extends Z{constructor(e,t,n,r){super(e,n),this.format=t,this.access=r}get isTemplate(){return!0}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}},ge;(i=>{i[i.Uniform=0]="Uniform",i[i.Storage=1]="Storage",i[i.Texture=2]="Texture",i[i.Sampler=3]="Sampler",i[i.StorageTexture=4]="StorageTexture"})(ge||(ge={}));var Te=class{constructor(e,t,n,r,s,a,o){this.name=e,this.type=t,this.group=n,this.binding=r,this.attributes=s,this.resourceType=a,this.access=o}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get size(){return this.type.size}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray||this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},ln=class{constructor(e,t){this.name=e,this.type=t}},un=class{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r,this.interpolation=null}},gt=class{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r}},fn=class{constructor(e,t,n,r){this.name=e,this.type=t,this.attributes=n,this.id=r}},hn=class{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n}},pn=class{constructor(e,t=null,n){this.stage=null,this.inputs=[],this.outputs=[],this.arguments=[],this.returnType=null,this.resources=[],this.overrides=[],this.startLine=-1,this.endLine=-1,this.inUse=!1,this.calls=new Set,this.name=e,this.stage=t,this.attributes=n}},mn=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}},br=new Float32Array(1),ti=new Int32Array(br.buffer),q=new Uint16Array(1);function ni(i){br[0]=i;let e=ti[0],t=e>>31&1,n=e>>23&255,r=8388607&e;if(n===255)return q[0]=t<<15|31744|(r!==0?512:0),q[0];if(n===0){if(r===0)return q[0]=t<<15,q[0];r|=8388608;let s=113;for(;!(8388608&r);)r<<=1,s--;return n=127-s,r&=8388607,n>0?(r=(r>>126-n)+(r>>127-n&1),q[0]=t<<15|n<<10|r>>13,q[0]):(q[0]=t<<15,q[0])}return n=n-127+15,n>=31?(q[0]=t<<15|31744,q[0]):n<=0?n<-10?(q[0]=t<<15,q[0]):(r=(8388608|r)>>1-n,q[0]=t<<15|r>>13,q[0]):(r>>=13,q[0]=t<<15|n<<10|r,q[0])}var An=new Uint32Array(1),yr=new Float32Array(An.buffer,0,1);function xr(i){let e=112+(i>>6&31)<<23|(63&i)<<17;return An[0]=e,yr[0]}function ri(i,e,t,n,r,s,a,o,c){let l=n*(a>>=r)*(s>>=r)+t*a+e*o;switch(c){case"r8unorm":return[P(i,l,"8unorm",1)[0]];case"r8snorm":return[P(i,l,"8snorm",1)[0]];case"r8uint":return[P(i,l,"8uint",1)[0]];case"r8sint":return[P(i,l,"8sint",1)[0]];case"rg8unorm":{let u=P(i,l,"8unorm",2);return[u[0],u[1]]}case"rg8snorm":{let u=P(i,l,"8snorm",2);return[u[0],u[1]]}case"rg8uint":{let u=P(i,l,"8uint",2);return[u[0],u[1]]}case"rg8sint":{let u=P(i,l,"8sint",2);return[u[0],u[1]]}case"rgba8unorm-srgb":case"rgba8unorm":{let u=P(i,l,"8unorm",4);return[u[0],u[1],u[2],u[3]]}case"rgba8snorm":{let u=P(i,l,"8snorm",4);return[u[0],u[1],u[2],u[3]]}case"rgba8uint":{let u=P(i,l,"8uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba8sint":{let u=P(i,l,"8sint",4);return[u[0],u[1],u[2],u[3]]}case"bgra8unorm-srgb":case"bgra8unorm":{let u=P(i,l,"8unorm",4);return[u[2],u[1],u[0],u[3]]}case"r16uint":return[P(i,l,"16uint",1)[0]];case"r16sint":return[P(i,l,"16sint",1)[0]];case"r16float":return[P(i,l,"16float",1)[0]];case"rg16uint":{let u=P(i,l,"16uint",2);return[u[0],u[1]]}case"rg16sint":{let u=P(i,l,"16sint",2);return[u[0],u[1]]}case"rg16float":{let u=P(i,l,"16float",2);return[u[0],u[1]]}case"rgba16uint":{let u=P(i,l,"16uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba16sint":{let u=P(i,l,"16sint",4);return[u[0],u[1],u[2],u[3]]}case"rgba16float":{let u=P(i,l,"16float",4);return[u[0],u[1],u[2],u[3]]}case"r32uint":return[P(i,l,"32uint",1)[0]];case"r32sint":return[P(i,l,"32sint",1)[0]];case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return[P(i,l,"32float",1)[0]];case"rg32uint":{let u=P(i,l,"32uint",2);return[u[0],u[1]]}case"rg32sint":{let u=P(i,l,"32sint",2);return[u[0],u[1]]}case"rg32float":{let u=P(i,l,"32float",2);return[u[0],u[1]]}case"rgba32uint":{let u=P(i,l,"32uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba32sint":{let u=P(i,l,"32sint",4);return[u[0],u[1],u[2],u[3]]}case"rgba32float":{let u=P(i,l,"32float",4);return[u[0],u[1],u[2],u[3]]}case"rg11b10ufloat":{let u=new Uint32Array(i.buffer,l,1)[0],f=(4192256&u)>>11,_=(4290772992&u)>>22;return[xr(2047&u),xr(f),function(b){let w=112+(b>>5&31)<<23|(31&b)<<18;return An[0]=w,yr[0]}(_),1]}}return null}function P(i,e,t,n){let r=[0,0,0,0];for(let l=0;l<n;++l)switch(t){case"8unorm":r[l]=i[e]/255,e++;break;case"8snorm":r[l]=i[e]/255*2-1,e++;break;case"8uint":r[l]=i[e],e++;break;case"8sint":r[l]=i[e]-127,e++;break;case"16uint":r[l]=i[e]|i[e+1]<<8,e+=2;break;case"16sint":r[l]=(i[e]|i[e+1]<<8)-32768,e+=2;break;case"16float":r[l]=(s=i[e]|i[e+1]<<8,a=void 0,o=void 0,c=void 0,a=(32768&s)>>15,c=1023&s,(o=(31744&s)>>10)==0?(a?-1:1)*Math.pow(2,-14)*(c/Math.pow(2,10)):o==31?c?NaN:1/0*(a?-1:1):(a?-1:1)*Math.pow(2,o-15)*(1+c/Math.pow(2,10))),e+=2;break;case"32uint":case"32sint":r[l]=i[e]|i[e+1]<<8|i[e+2]<<16|i[e+3]<<24,e+=4;break;case"32float":r[l]=new Float32Array(i.buffer,e,1)[0],e+=4}var s,a,o,c;return r}function R(i,e,t,n,r){for(let s=0;s<n;++s)switch(t){case"8unorm":i[e]=255*r[s],e++;break;case"8snorm":i[e]=.5*(r[s]+1)*255,e++;break;case"8uint":i[e]=r[s],e++;break;case"8sint":i[e]=r[s]+127,e++;break;case"16uint":new Uint16Array(i.buffer,e,1)[0]=r[s],e+=2;break;case"16sint":new Int16Array(i.buffer,e,1)[0]=r[s],e+=2;break;case"16float":{let a=ni(r[s]);new Uint16Array(i.buffer,e,1)[0]=a,e+=2;break}case"32uint":new Uint32Array(i.buffer,e,1)[0]=r[s],e+=4;break;case"32sint":new Int32Array(i.buffer,e,1)[0]=r[s],e+=4;break;case"32float":new Float32Array(i.buffer,e,1)[0]=r[s],e+=4}return r}var an={r8unorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8snorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8uint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8sint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg8unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8snorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"rgba8unorm-srgb":{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8snorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},bgra8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"bgra8unorm-srgb":{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r16uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16float:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg16uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba16uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r32uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg32uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba32uint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32sint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32float:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rg11b10ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},stencil8:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!1,hasStencil:!0,channels:1},depth16unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},depth24plus:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,depthOnlyFormat:"depth32float",channels:1},"depth24plus-stencil8":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,depthOnlyFormat:"depth32float",channels:1},depth32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},"depth32float-stencil8":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,stencilOnlyFormat:"depth32float",channels:1},rgb9e5ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"bc1-rgba-unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc1-rgba-unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc2-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc2-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc3-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc3-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc4-r-unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},"bc4-r-snorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},"bc5-rg-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},"bc5-rg-snorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},"bc6h-rgb-ufloat":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc6h-rgb-float":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc7-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc7-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8a1unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8a1unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgba8unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgba8unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"eac-r11unorm":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},"eac-r11snorm":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},"eac-rg11unorm":{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},"eac-rg11snorm":{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},"astc-4x4-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"astc-4x4-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"astc-5x4-unorm":{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},"astc-5x4-unorm-srgb":{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},"astc-5x5-unorm":{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},"astc-5x5-unorm-srgb":{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},"astc-6x5-unorm":{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},"astc-6x5-unorm-srgb":{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},"astc-6x6-unorm":{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},"astc-6x6-unorm-srgb":{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},"astc-8x5-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},"astc-8x5-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},"astc-8x6-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},"astc-8x6-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},"astc-8x8-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},"astc-8x8-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},"astc-10x5-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},"astc-10x5-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},"astc-10x6-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},"astc-10x6-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},"astc-10x8-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},"astc-10x8-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},"astc-10x10-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},"astc-10x10-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},"astc-12x10-unorm":{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},"astc-12x10-unorm-srgb":{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},"astc-12x12-unorm":{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4},"astc-12x12-unorm-srgb":{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4}},Q=class{constructor(){this.id=Q._id++,this.line=0}get isAstNode(){return!0}get astNodeType(){return""}search(e){e(this)}searchBlock(e,t){if(e){t(Oe.instance);for(let n of e)n instanceof Array?this.searchBlock(n,t):n.search(t);t(Pe.instance)}}constEvaluate(e,t){throw new Error("Cannot evaluate node")}constEvaluateString(e){return this.constEvaluate(e).toString()}};Q._id=0;var Oe=class extends Q{};Oe.instance=new Oe;var Pe=class extends Q{};Pe.instance=new Pe;var wr=new Set(["all","all","any","select","arrayLength","abs","acos","acosh","asin","asinh","atan","atanh","atan2","ceil","clamp","cos","cosh","countLeadingZeros","countOneBits","countTrailingZeros","cross","degrees","determinant","distance","dot","dot4U8Packed","dot4I8Packed","exp","exp2","extractBits","faceForward","firstLeadingBit","firstTrailingBit","floor","fma","fract","frexp","insertBits","inverseSqrt","ldexp","length","log","log2","max","min","mix","modf","normalize","pow","quantizeToF16","radians","reflect","refract","reverseBits","round","saturate","sign","sin","sinh","smoothStep","sqrt","step","tan","tanh","transpose","trunc","dpdx","dpdxCoarse","dpdxFine","dpdy","dpdyCoarse","dpdyFine","fwidth","fwidthCoarse","fwidthFine","textureDimensions","textureGather","textureGatherCompare","textureLoad","textureNumLayers","textureNumLevels","textureNumSamples","textureSample","textureSampleBias","textureSampleCompare","textureSampleCompareLevel","textureSampleGrad","textureSampleLevel","textureSampleBaseClampToEdge","textureStore","atomicLoad","atomicStore","atomicAdd","atomicSub","atomicMax","atomicMin","atomicAnd","atomicOr","atomicXor","atomicExchange","atomicCompareExchangeWeak","pack4x8snorm","pack4x8unorm","pack4xI8","pack4xU8","pack4x8Clamp","pack4xU8Clamp","pack2x16snorm","pack2x16unorm","pack2x16float","unpack4x8snorm","unpack4x8unorm","unpack4xI8","unpack4xU8","unpack2x16snorm","unpack2x16unorm","unpack2x16float","storageBarrier","textureBarrier","workgroupBarrier","workgroupUniformLoad","subgroupAdd","subgroupExclusiveAdd","subgroupInclusiveAdd","subgroupAll","subgroupAnd","subgroupAny","subgroupBallot","subgroupBroadcast","subgroupBroadcastFirst","subgroupElect","subgroupMax","subgroupMin","subgroupMul","subgroupExclusiveMul","subgroupInclusiveMul","subgroupOr","subgroupShuffle","subgroupShuffleDown","subgroupShuffleUp","subgroupShuffleXor","subgroupXor","quadBroadcast","quadSwapDiagonal","quadSwapX","quadSwapY"]),B=class extends Q{constructor(){super()}},ke=class extends B{constructor(e,t,n,r,s,a){super(),this.calls=new Set,this.name=e,this.args=t,this.returnType=n,this.body=r,this.startLine=s,this.endLine=a}get astNodeType(){return"function"}search(e){if(this.attributes)for(let t of this.attributes)e(t);e(this);for(let t of this.args)e(t);this.searchBlock(this.body,e)}},dn=class extends B{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}},_t=class extends B{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"while"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},Xe=class extends B{constructor(e,t){super(),this.body=e,this.loopId=t}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}},xt=class extends B{constructor(e,t,n,r){super(),this.init=e,this.condition=t,this.increment=n,this.body=r}get astNodeType(){return"for"}search(e){var t,n,r;(t=this.init)===null||t===void 0||t.search(e),(n=this.condition)===null||n===void 0||n.search(e),(r=this.increment)===null||r===void 0||r.search(e),this.searchBlock(this.body,e)}},ae=class extends B{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=r,this.value=s}get astNodeType(){return"var"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},Ye=class extends B{constructor(e,t,n){super(),this.attributes=null,this.name=e,this.type=t,this.value=n}get astNodeType(){return"override"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}},ye=class extends B{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=r,this.value=s}get astNodeType(){return"let"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},Ce=class extends B{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=r,this.value=s}get astNodeType(){return"const"}constEvaluate(e,t){return this.value.constEvaluate(e,t)}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},Ee,qe,v,g;(i=>{i.increment="++",i.decrement="--"})(Ee||(Ee={})),(i=>{i.parse=function(e){let t=e;if(t=="parse")throw new Error("Invalid value for IncrementOperator");return i[t]}})(Ee||(Ee={}));var vt=class extends B{constructor(e,t){super(),this.operator=e,this.variable=t}get astNodeType(){return"increment"}search(e){this.variable.search(e)}};(i=>{i.assign="=",i.addAssign="+=",i.subtractAssin="-=",i.multiplyAssign="*=",i.divideAssign="/=",i.moduloAssign="%=",i.andAssign="&=",i.orAssign="|=",i.xorAssign="^=",i.shiftLeftAssign="<<=",i.shiftRightAssign=">>="})(qe||(qe={})),(i=>{i.parse=function(e){let t=e;if(t=="parse")throw new Error("Invalid value for AssignOperator");return t}})(qe||(qe={}));var bt=class extends B{constructor(e,t,n){super(),this.operator=e,this.variable=t,this.value=n}get astNodeType(){return"assign"}search(e){this.variable.search(e),this.value.search(e)}},Ke=class extends B{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"call"}isBuiltin(){return wr.has(this.name)}search(e){for(let t of this.args)t.search(e);e(this)}},yt=class extends B{constructor(e,t){super(),this.body=e,this.continuing=t}get astNodeType(){return"loop"}},wt=class extends B{constructor(e,t){super(),this.condition=e,this.cases=t}get astNodeType(){return"switch"}},kt=class extends B{constructor(e,t,n,r){super(),this.condition=e,this.body=t,this.elseif=n,this.else=r}get astNodeType(){return"if"}search(e){this.condition.search(e),this.searchBlock(this.body,e),this.searchBlock(this.elseif,e),this.searchBlock(this.else,e)}},It=class extends B{constructor(e){super(),this.value=e}get astNodeType(){return"return"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}},gn=class extends B{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}},_n=class extends B{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}},St=class extends B{constructor(e,t){super(),this.severity=e,this.rule=t}get astNodeType(){return"diagnostic"}},Ze=class extends B{constructor(e,t){super(),this.name=e,this.type=t}get astNodeType(){return"alias"}},xn=class extends B{constructor(){super()}get astNodeType(){return"discard"}},At=class extends B{constructor(){super(),this.condition=null,this.loopId=-1}get astNodeType(){return"break"}},Lt=class extends B{constructor(){super(),this.loopId=-1}get astNodeType(){return"continue"}},y=class extends B{constructor(e){super(),this.attributes=null,this.name=e}get astNodeType(){return"type"}get isStruct(){return!1}get isArray(){return!1}static maxFormatType(e){let t=e[0];if(t.name==="f32")return t;for(let n=1;n<e.length;++n){let r=y._priority.get(t.name);y._priority.get(e[n].name)<r&&(t=e[n])}return t.name==="x32"?y.i32:t}getTypeName(){return this.name}};y.x32=new y("x32"),y.f32=new y("f32"),y.i32=new y("i32"),y.u32=new y("u32"),y.f16=new y("f16"),y.bool=new y("bool"),y.void=new y("void"),y._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);var Tt=class extends y{constructor(e){super(e)}},ie=class extends y{constructor(e,t,n,r){super(e),this.members=t,this.startLine=n,this.endLine=r}get astNodeType(){return"struct"}get isStruct(){return!0}getMemberIndex(e){for(let t=0;t<this.members.length;t++)if(this.members[t].name==e)return t;return-1}search(e){for(let t of this.members)e(t)}},x=class extends y{constructor(e,t,n){super(e),this.format=t,this.access=n}get astNodeType(){return"template"}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}};x.vec2f=new x("vec2",y.f32,null),x.vec3f=new x("vec3",y.f32,null),x.vec4f=new x("vec4",y.f32,null),x.vec2i=new x("vec2",y.i32,null),x.vec3i=new x("vec3",y.i32,null),x.vec4i=new x("vec4",y.i32,null),x.vec2u=new x("vec2",y.u32,null),x.vec3u=new x("vec3",y.u32,null),x.vec4u=new x("vec4",y.u32,null),x.vec2h=new x("vec2",y.f16,null),x.vec3h=new x("vec3",y.f16,null),x.vec4h=new x("vec4",y.f16,null),x.vec2b=new x("vec2",y.bool,null),x.vec3b=new x("vec3",y.bool,null),x.vec4b=new x("vec4",y.bool,null),x.mat2x2f=new x("mat2x2",y.f32,null),x.mat2x3f=new x("mat2x3",y.f32,null),x.mat2x4f=new x("mat2x4",y.f32,null),x.mat3x2f=new x("mat3x2",y.f32,null),x.mat3x3f=new x("mat3x3",y.f32,null),x.mat3x4f=new x("mat3x4",y.f32,null),x.mat4x2f=new x("mat4x2",y.f32,null),x.mat4x3f=new x("mat4x3",y.f32,null),x.mat4x4f=new x("mat4x4",y.f32,null),x.mat2x2h=new x("mat2x2",y.f16,null),x.mat2x3h=new x("mat2x3",y.f16,null),x.mat2x4h=new x("mat2x4",y.f16,null),x.mat3x2h=new x("mat3x2",y.f16,null),x.mat3x3h=new x("mat3x3",y.f16,null),x.mat3x4h=new x("mat3x4",y.f16,null),x.mat4x2h=new x("mat4x2",y.f16,null),x.mat4x3h=new x("mat4x3",y.f16,null),x.mat4x4h=new x("mat4x4",y.f16,null),x.mat2x2i=new x("mat2x2",y.i32,null),x.mat2x3i=new x("mat2x3",y.i32,null),x.mat2x4i=new x("mat2x4",y.i32,null),x.mat3x2i=new x("mat3x2",y.i32,null),x.mat3x3i=new x("mat3x3",y.i32,null),x.mat3x4i=new x("mat3x4",y.i32,null),x.mat4x2i=new x("mat4x2",y.i32,null),x.mat4x3i=new x("mat4x3",y.i32,null),x.mat4x4i=new x("mat4x4",y.i32,null),x.mat2x2u=new x("mat2x2",y.u32,null),x.mat2x3u=new x("mat2x3",y.u32,null),x.mat2x4u=new x("mat2x4",y.u32,null),x.mat3x2u=new x("mat3x2",y.u32,null),x.mat3x3u=new x("mat3x3",y.u32,null),x.mat3x4u=new x("mat3x4",y.u32,null),x.mat4x2u=new x("mat4x2",y.u32,null),x.mat4x3u=new x("mat4x3",y.u32,null),x.mat4x4u=new x("mat4x4",y.u32,null);var je=class extends y{constructor(e,t,n,r){super(e),this.storage=t,this.type=n,this.access=r}get astNodeType(){return"pointer"}},we=class extends y{constructor(e,t,n,r){super(e),this.attributes=t,this.format=n,this.count=r}get astNodeType(){return"array"}get isArray(){return!0}},be=class extends y{constructor(e,t,n){super(e),this.format=t,this.access=n}get astNodeType(){return"sampler"}},se=class extends Q{constructor(){super(),this.postfix=null}},pe=class extends se{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}constEvaluateString(){return this.value}},ne=class extends se{constructor(e,t){super(),this.type=e,this.args=t}get astNodeType(){return"createExpr"}search(e){if(e(this),this.args)for(let t of this.args)t.search(e)}constEvaluate(e,t){return t&&(t[0]=this.type),e.evalExpression(this,e.context)}},Qe=class extends se{constructor(e,t){super(),this.cachedReturnValue=null,this.name=e,this.args=t}get astNodeType(){return"callExpr"}setCachedReturnValue(e){this.cachedReturnValue=e}get isBuiltin(){return wr.has(this.name)}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){for(let t of this.args)t.search(e);e(this)}},Y=class extends se{constructor(e){super(),this.name=e}get astNodeType(){return"varExpr"}search(e){e(this),this.postfix&&this.postfix.search(e)}constEvaluate(e,t){return e.evalExpression(this,e.context)}},Et=class extends se{constructor(e,t){super(),this.name=e,this.initializer=t}get astNodeType(){return"constExpr"}constEvaluate(e,t){if(this.initializer){let n=e.evalExpression(this.initializer,e.context);return n!==null&&this.postfix?n.getSubData(e,this.postfix,e.context):n}return null}search(e){this.initializer.search(e)}},H=class extends se{constructor(e,t){super(),this.value=e,this.type=t}get astNodeType(){return"literalExpr"}constEvaluate(e,t){return t!==void 0&&(t[0]=this.type),this.value}get isScalar(){return this.value instanceof m}get isVector(){return this.value instanceof p||this.value instanceof N}get scalarValue(){return this.value instanceof m?this.value.value:(console.error("Value is not scalar."),0)}get vectorValue(){return this.value instanceof p||this.value instanceof N?this.value.data:(console.error("Value is not a vector or matrix."),new Float32Array(0))}},Mt=class extends se{constructor(e,t){super(),this.type=e,this.value=t}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}};var xe=class extends se{constructor(e){super(),this.index=e}search(e){this.index.search(e)}},Ct=class extends se{constructor(){super()}},z=class extends Ct{constructor(e,t){super(),this.operator=e,this.right=t}get astNodeType(){return"unaryOp"}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.right.search(e)}},ee=class extends Ct{constructor(e,t,n){super(),this.operator=e,this.left=t,this.right=n}get astNodeType(){return"binaryOp"}_getPromotedType(e,t){return e.name===t.name?e:e.name==="f32"||t.name==="f32"?y.f32:e.name==="u32"||t.name==="u32"?y.u32:y.i32}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.left.search(e),this.right.search(e)}},Nt=class extends Q{constructor(e){super(),this.body=e}},Ne=class extends se{constructor(){super()}get astNodeType(){return"default"}},Ot=class extends Nt{constructor(e,t){super(t),this.selectors=e}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}},Pt=class extends Nt{constructor(e){super(e)}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}},Rt=class extends Q{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"argument"}},vn=class extends Q{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"elseif"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},Dt=class extends Q{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"member"}},Ft=class extends Q{constructor(e,t){super(),this.name=e,this.value=t}get astNodeType(){return"attribute"}},J=class{constructor(e,t){this.parent=null,this.typeInfo=e,this.parent=t,this.id=J._id++}clone(){throw`Clone: Not implemented for ${this.constructor.name}`}setDataValue(e,t,n,r){console.error(`SetDataValue: Not implemented for ${this.constructor.name}`)}getSubData(e,t,n){return console.error(`GetDataValue: Not implemented for ${this.constructor.name}`),null}toString(){return`<${this.typeInfo.name}>`}};J._id=0;var Je=class extends J{constructor(){super(new Z("void",null),null)}toString(){return"void"}};Je.void=new Je;var _e=class extends J{constructor(e){super(new Z("pointer",null),null),this.reference=e}clone(){return this}setDataValue(e,t,n,r){this.reference.setDataValue(e,t,n,r)}getSubData(e,t,n){return t?this.reference.getSubData(e,t,n):this}},m=class extends J{constructor(e,t,n=null){super(t,n),e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array?this.data=e:this.typeInfo.name==="x32"?e-Math.floor(e)!=0?this.data=new Float32Array([e]):this.data=e>=0?new Uint32Array([e]):new Int32Array([e]):this.typeInfo.name==="i32"||this.typeInfo.name==="bool"?this.data=new Int32Array([e]):this.typeInfo.name==="u32"?this.data=new Uint32Array([e]):this.typeInfo.name==="f32"||this.typeInfo.name==="f16"?this.data=new Float32Array([e]):console.error("ScalarData2: Invalid type",t)}clone(){if(this.data instanceof Float32Array)return new m(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new m(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new m(new Uint32Array(this.data),this.typeInfo,null);throw"ScalarData: Invalid data type"}get value(){return this.data[0]}set value(e){this.data[0]=e}setDataValue(e,t,n,r){if(n)return void console.error("SetDataValue: Scalar data does not support postfix",n);if(!(t instanceof m))return void console.error("SetDataValue: Invalid value",t);let s=t.data[0];this.typeInfo.name==="i32"||this.typeInfo.name==="u32"?s=Math.floor(s):this.typeInfo.name==="bool"&&(s=s?1:0),this.data[0]=s}getSubData(e,t,n){return t?(console.error("getSubData: Scalar data does not support postfix",t),null):this}toString(){return`${this.value}`}};function si(i,e,t){let n=e.length;return n===2?t==="f32"?new p(new Float32Array(e),i.getTypeInfo("vec2f")):t==="i32"||t==="bool"?new p(new Int32Array(e),i.getTypeInfo("vec2i")):t==="u32"?new p(new Uint32Array(e),i.getTypeInfo("vec2u")):t==="f16"?new p(new Float32Array(e),i.getTypeInfo("vec2h")):(console.error(`getSubData: Unknown format ${t}`),null):n===3?t==="f32"?new p(new Float32Array(e),i.getTypeInfo("vec3f")):t==="i32"||t==="bool"?new p(new Int32Array(e),i.getTypeInfo("vec3i")):t==="u32"?new p(new Uint32Array(e),i.getTypeInfo("vec3u")):t==="f16"?new p(new Float32Array(e),i.getTypeInfo("vec3h")):(console.error(`getSubData: Unknown format ${t}`),null):n===4?t==="f32"?new p(new Float32Array(e),i.getTypeInfo("vec4f")):t==="i32"||t==="bool"?new p(new Int32Array(e),i.getTypeInfo("vec4i")):t==="u32"?new p(new Uint32Array(e),i.getTypeInfo("vec4u")):t==="f16"?new p(new Float32Array(e),i.getTypeInfo("vec4h")):(console.error(`getSubData: Unknown format ${t}`),null):(console.error(`getSubData: Invalid vector size ${e.length}`),null)}var p=class extends J{constructor(e,t,n=null){if(super(t,n),e instanceof Float32Array||e instanceof Uint32Array||e instanceof Int32Array)this.data=e;else{let r=this.typeInfo.name;r==="vec2f"||r==="vec3f"||r==="vec4f"?this.data=new Float32Array(e):r==="vec2i"||r==="vec3i"||r==="vec4i"?this.data=new Int32Array(e):r==="vec2u"||r==="vec3u"||r==="vec4u"?this.data=new Uint32Array(e):r==="vec2h"||r==="vec3h"||r==="vec4h"?this.data=new Float32Array(e):r==="vec2b"||r==="vec3b"||r==="vec4b"?this.data=new Int32Array(e):r==="vec2"||r==="vec3"||r==="vec4"?this.data=new Float32Array(e):console.error(`VectorData: Invalid type ${r}`)}}clone(){if(this.data instanceof Float32Array)return new p(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new p(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new p(new Uint32Array(this.data),this.typeInfo,null);throw"VectorData: Invalid data type"}setDataValue(e,t,n,r){n instanceof pe?console.error("TODO: Set vector postfix"):t instanceof p?this.data=t.data:console.error("SetDataValue: Invalid value",t)}getSubData(e,t,n){if(t===null)return this;let r=e.getTypeInfo("f32");if(this.typeInfo instanceof he)r=this.typeInfo.format||r;else{let a=this.typeInfo.name;a==="vec2f"||a==="vec3f"||a==="vec4f"?r=e.getTypeInfo("f32"):a==="vec2i"||a==="vec3i"||a==="vec4i"?r=e.getTypeInfo("i32"):a==="vec2b"||a==="vec3b"||a==="vec4b"?r=e.getTypeInfo("bool"):a==="vec2u"||a==="vec3u"||a==="vec4u"?r=e.getTypeInfo("u32"):a==="vec2h"||a==="vec3h"||a==="vec4h"?r=e.getTypeInfo("f16"):console.error(`GetSubData: Unknown type ${a}`)}let s=this;for(;t!==null&&s!==null;){if(t instanceof xe){let a=t.index,o=-1;if(a instanceof H){if(!(a.value instanceof m))return console.error(`GetSubData: Invalid array index ${a.value}`),null;o=a.value.value}else{let c=e.evalExpression(a,n);if(!(c instanceof m))return console.error("GetSubData: Unknown index type",a),null;o=c.value}if(o<0||o>=s.data.length)return console.error("GetSubData: Index out of range",o),null;if(s.data instanceof Float32Array){let c=new Float32Array(s.data.buffer,s.data.byteOffset+4*o,1);return new m(c,r)}if(s.data instanceof Int32Array){let c=new Int32Array(s.data.buffer,s.data.byteOffset+4*o,1);return new m(c,r)}if(s.data instanceof Uint32Array){let c=new Uint32Array(s.data.buffer,s.data.byteOffset+4*o,1);return new m(c,r)}throw"GetSubData: Invalid data type"}if(!(t instanceof pe))return console.error("GetSubData: Unknown postfix",t),null;{let a=t.value.toLowerCase();if(a.length===1){let c=0;if(a==="x"||a==="r")c=0;else if(a==="y"||a==="g")c=1;else if(a==="z"||a==="b")c=2;else{if(a!=="w"&&a!=="a")return console.error(`GetSubData: Unknown member ${a}`),null;c=3}if(this.data instanceof Float32Array){let l=new Float32Array(this.data.buffer,this.data.byteOffset+4*c,1);return new m(l,r,this)}if(this.data instanceof Int32Array){let l=new Int32Array(this.data.buffer,this.data.byteOffset+4*c,1);return new m(l,r,this)}if(this.data instanceof Uint32Array){let l=new Uint32Array(this.data.buffer,this.data.byteOffset+4*c,1);return new m(l,r,this)}}let o=[];for(let c of a)c==="x"||c==="r"?o.push(this.data[0]):c==="y"||c==="g"?o.push(this.data[1]):c==="z"||c==="b"?o.push(this.data[2]):c==="w"||c==="a"?o.push(this.data[3]):console.error(`GetDataValue: Unknown member ${c}`);s=si(e,o,r.name)}t=t.postfix}return s}toString(){let e=`${this.data[0]}`;for(let t=1;t<this.data.length;++t)e+=`, ${this.data[t]}`;return e}},N=class extends J{constructor(e,t,n=null){super(t,n),e instanceof Float32Array?this.data=e:this.data=new Float32Array(e)}clone(){return new N(new Float32Array(this.data),this.typeInfo,null)}setDataValue(e,t,n,r){n instanceof pe?console.error("TODO: Set matrix postfix"):t instanceof N?this.data=t.data:console.error("SetDataValue: Invalid value",t)}getSubData(e,t,n){if(t===null)return this;let r=this.typeInfo.name;if(e.getTypeInfo("f32"),this.typeInfo instanceof he)this.typeInfo.format;else if(r.endsWith("f"))e.getTypeInfo("f32");else if(r.endsWith("i"))e.getTypeInfo("i32");else if(r.endsWith("u"))e.getTypeInfo("u32");else{if(!r.endsWith("h"))return console.error(`GetDataValue: Unknown type ${r}`),null;e.getTypeInfo("f16")}if(t instanceof xe){let s=t.index,a=-1;if(s instanceof H){if(!(s.value instanceof m))return console.error(`GetDataValue: Invalid array index ${s.value}`),null;a=s.value.value}else{let l=e.evalExpression(s,n);if(!(l instanceof m))return console.error("GetDataValue: Unknown index type",s),null;a=l.value}if(a<0||a>=this.data.length)return console.error("GetDataValue: Index out of range",a),null;let o=r.endsWith("h")?"h":"f",c;if(r==="mat2x2"||r==="mat2x2f"||r==="mat2x2h"||r==="mat3x2"||r==="mat3x2f"||r==="mat3x2h"||r==="mat4x2"||r==="mat4x2f"||r==="mat4x2h")c=new p(new Float32Array(this.data.buffer,this.data.byteOffset+2*a*4,2),e.getTypeInfo(`vec2${o}`));else if(r==="mat2x3"||r==="mat2x3f"||r==="mat2x3h"||r==="mat3x3"||r==="mat3x3f"||r==="mat3x3h"||r==="mat4x3"||r==="mat4x3f"||r==="mat4x3h")c=new p(new Float32Array(this.data.buffer,this.data.byteOffset+3*a*4,3),e.getTypeInfo(`vec3${o}`));else{if(r!=="mat2x4"&&r!=="mat2x4f"&&r!=="mat2x4h"&&r!=="mat3x4"&&r!=="mat3x4f"&&r!=="mat3x4h"&&r!=="mat4x4"&&r!=="mat4x4f"&&r!=="mat4x4h")return console.error(`GetDataValue: Unknown type ${r}`),null;c=new p(new Float32Array(this.data.buffer,this.data.byteOffset+4*a*4,4),e.getTypeInfo(`vec4${o}`))}return t.postfix?c.getSubData(e,t.postfix,n):c}return console.error("GetDataValue: Invalid postfix",t),null}toString(){let e=`${this.data[0]}`;for(let t=1;t<this.data.length;++t)e+=`, ${this.data[t]}`;return e}},U=class extends J{constructor(e,t,n=0,r=null){super(t,r),this.buffer=e instanceof ArrayBuffer?e:e.buffer,this.offset=n}clone(){let e=new Uint8Array(new Uint8Array(this.buffer,this.offset,this.typeInfo.size));return new U(e.buffer,this.typeInfo,0,null)}setDataValue(e,t,n,r){if(t===null)return void console.log("setDataValue: NULL data.");let s=this.offset,a=this.typeInfo;for(;n;){if(n instanceof xe)if(a instanceof fe){let o=n.index;if(o instanceof H){if(!(o.value instanceof m))return void console.error(`SetDataValue: Invalid index type ${o.value}`);s+=o.value.value*a.stride}else{let c=e.evalExpression(o,r);if(!(c instanceof m))return void console.error("SetDataValue: Unknown index type",o);s+=c.value*a.stride}a=a.format}else console.error(`SetDataValue: Type ${a.getTypeName()} is not an array`);else{if(!(n instanceof pe))return void console.error("SetDataValue: Unknown postfix type",n);{let o=n.value;if(a instanceof ue){let c=!1;for(let l of a.members)if(l.name===o){s+=l.offset,a=l.type,c=!0;break}if(!c)return void console.error(`SetDataValue: Member ${o} not found`)}else if(a instanceof Z){let c=a.getTypeName(),l=0;if(o==="x"||o==="r")l=0;else if(o==="y"||o==="g")l=1;else if(o==="z"||o==="b")l=2;else{if(o!=="w"&&o!=="a")return void console.error(`SetDataValue: Unknown member ${o}`);l=3}if(!(t instanceof m))return void console.error("SetDataValue: Invalid value",t);let u=t.value;return c==="vec2f"?void(new Float32Array(this.buffer,s,2)[l]=u):c==="vec3f"?void(new Float32Array(this.buffer,s,3)[l]=u):c==="vec4f"?void(new Float32Array(this.buffer,s,4)[l]=u):c==="vec2i"?void(new Int32Array(this.buffer,s,2)[l]=u):c==="vec3i"?void(new Int32Array(this.buffer,s,3)[l]=u):c==="vec4i"?void(new Int32Array(this.buffer,s,4)[l]=u):c==="vec2u"?void(new Uint32Array(this.buffer,s,2)[l]=u):c==="vec3u"?void(new Uint32Array(this.buffer,s,3)[l]=u):c==="vec4u"?void(new Uint32Array(this.buffer,s,4)[l]=u):void console.error(`SetDataValue: Type ${c} is not a struct`)}}}n=n.postfix}this.setData(e,t,a,s,r)}setData(e,t,n,r,s){let a=n.getTypeName();if(a!=="f32"&&a!=="f16")if(a!=="i32"&&a!=="atomic<i32>"&&a!=="x32")if(a!=="u32"&&a!=="atomic<u32>")if(a!=="bool")if(a!=="vec2f"&&a!=="vec2h")if(a!=="vec3f"&&a!=="vec3h")if(a!=="vec4f"&&a!=="vec4h")if(a!=="vec2i")if(a!=="vec3i")if(a!=="vec4i")if(a!=="vec2u")if(a!=="vec3u")if(a!=="vec4u")if(a!=="vec2b")if(a!=="vec3b")if(a!=="vec4b")if(a!=="mat2x2f"&&a!=="mat2x2h")if(a!=="mat2x3f"&&a!=="mat2x3h")if(a!=="mat2x4f"&&a!=="mat2x4h")if(a!=="mat3x2f"&&a!=="mat3x2h")if(a!=="mat3x3f"&&a!=="mat3x3h")if(a!=="mat3x4f"&&a!=="mat3x4h")if(a!=="mat4x2f"&&a!=="mat4x2h")if(a!=="mat4x3f"&&a!=="mat4x3h")if(a!=="mat4x4f"&&a!=="mat4x4h")if(t instanceof U){if(n===t.typeInfo)return void new Uint8Array(this.buffer,r,t.buffer.byteLength).set(new Uint8Array(t.buffer));console.error("SetDataValue: Type mismatch",a,t.typeInfo.getTypeName())}else console.error(`SetData: Unknown type ${a}`);else{let o=new Float32Array(this.buffer,r,16);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7],o[8]=t.data[8],o[9]=t.data[9],o[10]=t.data[10],o[11]=t.data[11],o[12]=t.data[12],o[13]=t.data[13],o[14]=t.data[14],o[15]=t.data[15]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[8]=t[8],o[9]=t[9],o[10]=t[10],o[11]=t[11],o[12]=t[12],o[13]=t[13],o[14]=t[14],o[15]=t[15])}else{let o=new Float32Array(this.buffer,r,12);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7],o[8]=t.data[8],o[9]=t.data[9],o[10]=t.data[10],o[11]=t.data[11]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[8]=t[8],o[9]=t[9],o[10]=t[10],o[11]=t[11])}else{let o=new Float32Array(this.buffer,r,8);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7])}else{let o=new Float32Array(this.buffer,r,12);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7],o[8]=t.data[8],o[9]=t.data[9],o[10]=t.data[10],o[11]=t.data[11]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[8]=t[8],o[9]=t[9],o[10]=t[10],o[11]=t[11])}else{let o=new Float32Array(this.buffer,r,9);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7],o[8]=t.data[8]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[8]=t[8])}else{let o=new Float32Array(this.buffer,r,6);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5])}else{let o=new Float32Array(this.buffer,r,8);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7])}else{let o=new Float32Array(this.buffer,r,6);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5])}else{let o=new Float32Array(this.buffer,r,4);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Uint32Array(this.buffer,r,4);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Uint32Array(this.buffer,r,3);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2]):(o[0]=t[0],o[1]=t[1],o[2]=t[2])}else{let o=new Uint32Array(this.buffer,r,2);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1]):(o[0]=t[0],o[1]=t[1])}else{let o=new Uint32Array(this.buffer,r,4);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Uint32Array(this.buffer,r,3);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2]):(o[0]=t[0],o[1]=t[1],o[2]=t[2])}else{let o=new Uint32Array(this.buffer,r,2);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1]):(o[0]=t[0],o[1]=t[1])}else{let o=new Int32Array(this.buffer,r,4);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Int32Array(this.buffer,r,3);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2]):(o[0]=t[0],o[1]=t[1],o[2]=t[2])}else{let o=new Int32Array(this.buffer,r,2);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1]):(o[0]=t[0],o[1]=t[1])}else{let o=new Float32Array(this.buffer,r,4);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Float32Array(this.buffer,r,3);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2]):(o[0]=t[0],o[1]=t[1],o[2]=t[2])}else{let o=new Float32Array(this.buffer,r,2);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1]):(o[0]=t[0],o[1]=t[1])}else t instanceof m&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof m&&(new Uint32Array(this.buffer,r,1)[0]=t.value);else t instanceof m&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof m&&(new Float32Array(this.buffer,r,1)[0]=t.value)}getSubData(e,t,n){var r,s,a;if(t===null)return this;let o=this.offset,c=this.typeInfo;for(;t;){if(t instanceof xe){let u=t.index,f=e.evalExpression(u,n),_=0;if(f instanceof m?_=f.value:console.error("GetDataValue: Invalid index type",u),c instanceof fe)o+=_*c.stride,c=c.format;else{let b=c.getTypeName();b==="mat4x4"||b==="mat4x4f"||b==="mat4x4h"?(o+=16*_,c=e.getTypeInfo("vec4f")):console.error(`getDataValue: Type ${c.getTypeName()} is not an array`)}}else{if(!(t instanceof pe))return console.error("GetDataValue: Unknown postfix type",t),null;{let u=t.value;if(c instanceof ue){let f=!1;for(let _ of c.members)if(_.name===u){o+=_.offset,c=_.type,f=!0;break}if(!f)return console.error(`GetDataValue: Member ${u} not found`),null}else if(c instanceof Z){let f=c.getTypeName();if(f==="vec2f"||f==="vec3f"||f==="vec4f"||f==="vec2i"||f==="vec3i"||f==="vec4i"||f==="vec2u"||f==="vec3u"||f==="vec4u"||f==="vec2b"||f==="vec3b"||f==="vec4b"||f==="vec2h"||f==="vec3h"||f==="vec4h"||f==="vec2"||f==="vec3"||f==="vec4"){if(u.length>0&&u.length<5){let _="f",b=[];for(let w=0;w<u.length;++w){let L=u[w].toLowerCase(),S=0;if(L==="x"||L==="r")S=0;else if(L==="y"||L==="g")S=1;else if(L==="z"||L==="b")S=2;else{if(L!=="w"&&L!=="a")return console.error(`Unknown member ${u}`),null;S=3}if(u.length===1){if(f.endsWith("f"))return this.buffer.byteLength<o+4*S+4?(console.log("Insufficient buffer data"),null):new m(new Float32Array(this.buffer,o+4*S,1),e.getTypeInfo("f32"),this);if(f.endsWith("h"))return new m(new Float32Array(this.buffer,o+4*S,1),e.getTypeInfo("f16"),this);if(f.endsWith("i"))return new m(new Int32Array(this.buffer,o+4*S,1),e.getTypeInfo("i32"),this);if(f.endsWith("b"))return new m(new Int32Array(this.buffer,o+4*S,1),e.getTypeInfo("bool"),this);if(f.endsWith("u"))return new m(new Uint32Array(this.buffer,o+4*S,1),e.getTypeInfo("i32"),this)}if(f==="vec2f")b.push(new Float32Array(this.buffer,o,2)[S]);else if(f==="vec3f"){if(o+12>=this.buffer.byteLength)return console.log("Insufficient buffer data"),null;let E=new Float32Array(this.buffer,o,3);b.push(E[S])}else if(f==="vec4f")b.push(new Float32Array(this.buffer,o,4)[S]);else if(f==="vec2i")_="i",b.push(new Int32Array(this.buffer,o,2)[S]);else if(f==="vec3i")_="i",b.push(new Int32Array(this.buffer,o,3)[S]);else if(f==="vec4i")_="i",b.push(new Int32Array(this.buffer,o,4)[S]);else if(f==="vec2u"){_="u";let E=new Uint32Array(this.buffer,o,2);b.push(E[S])}else f==="vec3u"?(_="u",b.push(new Uint32Array(this.buffer,o,3)[S])):f==="vec4u"&&(_="u",b.push(new Uint32Array(this.buffer,o,4)[S]))}return b.length===2?c=e.getTypeInfo(`vec2${_}`):b.length===3?c=e.getTypeInfo(`vec3${_}`):b.length===4?c=e.getTypeInfo(`vec4${_}`):console.error(`GetDataValue: Invalid vector length ${b.length}`),new p(b,c,null)}return console.error(`GetDataValue: Unknown member ${u}`),null}return console.error(`GetDataValue: Type ${f} is not a struct`),null}}}t=t.postfix}let l=c.getTypeName();return l==="f32"?new m(new Float32Array(this.buffer,o,1),c,this):l==="i32"?new m(new Int32Array(this.buffer,o,1),c,this):l==="u32"?new m(new Uint32Array(this.buffer,o,1),c,this):l==="vec2f"?new p(new Float32Array(this.buffer,o,2),c,this):l==="vec3f"?new p(new Float32Array(this.buffer,o,3),c,this):l==="vec4f"?new p(new Float32Array(this.buffer,o,4),c,this):l==="vec2i"?new p(new Int32Array(this.buffer,o,2),c,this):l==="vec3i"?new p(new Int32Array(this.buffer,o,3),c,this):l==="vec4i"?new p(new Int32Array(this.buffer,o,4),c,this):l==="vec2u"?new p(new Uint32Array(this.buffer,o,2),c,this):l==="vec3u"?new p(new Uint32Array(this.buffer,o,3),c,this):l==="vec4u"?new p(new Uint32Array(this.buffer,o,4),c,this):c instanceof he&&c.name==="atomic"?((r=c.format)===null||r===void 0?void 0:r.name)==="u32"?new m(new Uint32Array(this.buffer,o,1)[0],c.format,this):((s=c.format)===null||s===void 0?void 0:s.name)==="i32"?new m(new Int32Array(this.buffer,o,1)[0],c.format,this):(console.error(`GetDataValue: Invalid atomic format ${(a=c.format)===null||a===void 0?void 0:a.name}`),null):new U(this.buffer,c,o,this)}toString(){let e="";if(this.typeInfo instanceof fe)if(this.typeInfo.format.name==="f32"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="i32"){let t=new Int32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="u32"){let t=new Uint32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="vec2f"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}]`;for(let n=1;n<t.length/2;++n)e+=`, [${t[2*n]}, ${t[2*n+1]}]`}else if(this.typeInfo.format.name==="vec3f"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}, ${t[2]}]`;for(let n=4;n<t.length;n+=4)e+=`, [${t[n]}, ${t[n+1]}, ${t[n+2]}]`}else if(this.typeInfo.format.name==="vec4f"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}, ${t[2]}, ${t[3]}]`;for(let n=4;n<t.length;n+=4)e+=`, [${t[n]}, ${t[n+1]}, ${t[n+2]}, ${t[n+3]}]`}else e="[...]";else this.typeInfo instanceof ue?e+="{...}":e="[...]";return e}},oe=class extends J{constructor(e,t,n,r){super(t,null),this.data=e,this.descriptor=n,this.view=r}clone(){return new oe(this.data,this.typeInfo,this.descriptor,this.view)}get width(){var e,t;let n=this.descriptor.size;return n instanceof Array&&n.length>0?(e=n[0])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.width)!==null&&t!==void 0?t:0}get height(){var e,t;let n=this.descriptor.size;return n instanceof Array&&n.length>1?(e=n[1])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.height)!==null&&t!==void 0?t:0}get depthOrArrayLayers(){var e,t;let n=this.descriptor.size;return n instanceof Array&&n.length>2?(e=n[2])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.depthOrArrayLayers)!==null&&t!==void 0?t:0}get format(){var e;return this.descriptor&&(e=this.descriptor.format)!==null&&e!==void 0?e:"rgba8unorm"}get sampleCount(){var e;return this.descriptor&&(e=this.descriptor.sampleCount)!==null&&e!==void 0?e:1}get mipLevelCount(){var e;return this.descriptor&&(e=this.descriptor.mipLevelCount)!==null&&e!==void 0?e:1}get dimension(){var e;return this.descriptor&&(e=this.descriptor.dimension)!==null&&e!==void 0?e:"2d"}getMipLevelSize(e){if(e>=this.mipLevelCount)return[0,0,0];let t=[this.width,this.height,this.depthOrArrayLayers];for(let n=0;n<t.length;++n)t[n]=Math.max(1,t[n]>>e);return t}get texelByteSize(){let e=this.format,t=an[e];return t?t.isDepthStencil?4:t.bytesPerBlock:0}get bytesPerRow(){return this.width*this.texelByteSize}get isDepthStencil(){let e=this.format,t=an[e];return!!t&&t.isDepthStencil}getGpuSize(){let e=this.format,t=an[e],n=this.width;if(!e||n<=0||!t)return-1;let r=this.height,s=this.depthOrArrayLayers,a=this.dimension;return n/t.blockWidth*(a==="1d"?1:r/t.blockHeight)*t.bytesPerBlock*s}getPixel(e,t,n=0,r=0){let s=this.texelByteSize,a=this.bytesPerRow,o=this.height,c=this.data[r];return ri(new Uint8Array(c),e,t,n,r,o,a,s,this.format)}setPixel(e,t,n,r,s){let a=this.texelByteSize,o=this.bytesPerRow,c=this.height,l=this.data[r];(function(u,f,_,b,w,L,S,E,T,k){let I=b*(S>>=w)*(L>>=w)+_*S+f*E;switch(T){case"r8unorm":return void R(u,I,"8unorm",1,k);case"r8snorm":return void R(u,I,"8snorm",1,k);case"r8uint":return void R(u,I,"8uint",1,k);case"r8sint":return void R(u,I,"8sint",1,k);case"rg8unorm":return void R(u,I,"8unorm",2,k);case"rg8snorm":return void R(u,I,"8snorm",2,k);case"rg8uint":return void R(u,I,"8uint",2,k);case"rg8sint":return void R(u,I,"8sint",2,k);case"rgba8unorm-srgb":case"rgba8unorm":case"bgra8unorm-srgb":case"bgra8unorm":return void R(u,I,"8unorm",4,k);case"rgba8snorm":return void R(u,I,"8snorm",4,k);case"rgba8uint":return void R(u,I,"8uint",4,k);case"rgba8sint":return void R(u,I,"8sint",4,k);case"r16uint":return void R(u,I,"16uint",1,k);case"r16sint":return void R(u,I,"16sint",1,k);case"r16float":return void R(u,I,"16float",1,k);case"rg16uint":return void R(u,I,"16uint",2,k);case"rg16sint":return void R(u,I,"16sint",2,k);case"rg16float":return void R(u,I,"16float",2,k);case"rgba16uint":return void R(u,I,"16uint",4,k);case"rgba16sint":return void R(u,I,"16sint",4,k);case"rgba16float":return void R(u,I,"16float",4,k);case"r32uint":return void R(u,I,"32uint",1,k);case"r32sint":return void R(u,I,"32sint",1,k);case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return void R(u,I,"32float",1,k);case"rg32uint":return void R(u,I,"32uint",2,k);case"rg32sint":return void R(u,I,"32sint",2,k);case"rg32float":return void R(u,I,"32float",2,k);case"rgba32uint":return void R(u,I,"32uint",4,k);case"rgba32sint":return void R(u,I,"32sint",4,k);case"rgba32float":return void R(u,I,"32float",4,k);case"rg11b10ufloat":console.error("TODO: rg11b10ufloat not supported for writing")}})(new Uint8Array(l),e,t,n,r,c,o,a,this.format,s)}};(i=>{i[i.token=0]="token",i[i.keyword=1]="keyword",i[i.reserved=2]="reserved"})(g||(g={}));var d=class{constructor(e,t,n){this.name=e,this.type=t,this.rule=n}toString(){return this.name}},h=class{};v=h,h.none=new d("",g.reserved,""),h.eof=new d("EOF",g.token,""),h.reserved={asm:new d("asm",g.reserved,"asm"),bf16:new d("bf16",g.reserved,"bf16"),do:new d("do",g.reserved,"do"),enum:new d("enum",g.reserved,"enum"),f16:new d("f16",g.reserved,"f16"),f64:new d("f64",g.reserved,"f64"),handle:new d("handle",g.reserved,"handle"),i8:new d("i8",g.reserved,"i8"),i16:new d("i16",g.reserved,"i16"),i64:new d("i64",g.reserved,"i64"),mat:new d("mat",g.reserved,"mat"),premerge:new d("premerge",g.reserved,"premerge"),regardless:new d("regardless",g.reserved,"regardless"),typedef:new d("typedef",g.reserved,"typedef"),u8:new d("u8",g.reserved,"u8"),u16:new d("u16",g.reserved,"u16"),u64:new d("u64",g.reserved,"u64"),unless:new d("unless",g.reserved,"unless"),using:new d("using",g.reserved,"using"),vec:new d("vec",g.reserved,"vec"),void:new d("void",g.reserved,"void")},h.keywords={array:new d("array",g.keyword,"array"),atomic:new d("atomic",g.keyword,"atomic"),bool:new d("bool",g.keyword,"bool"),f32:new d("f32",g.keyword,"f32"),i32:new d("i32",g.keyword,"i32"),mat2x2:new d("mat2x2",g.keyword,"mat2x2"),mat2x3:new d("mat2x3",g.keyword,"mat2x3"),mat2x4:new d("mat2x4",g.keyword,"mat2x4"),mat3x2:new d("mat3x2",g.keyword,"mat3x2"),mat3x3:new d("mat3x3",g.keyword,"mat3x3"),mat3x4:new d("mat3x4",g.keyword,"mat3x4"),mat4x2:new d("mat4x2",g.keyword,"mat4x2"),mat4x3:new d("mat4x3",g.keyword,"mat4x3"),mat4x4:new d("mat4x4",g.keyword,"mat4x4"),ptr:new d("ptr",g.keyword,"ptr"),sampler:new d("sampler",g.keyword,"sampler"),sampler_comparison:new d("sampler_comparison",g.keyword,"sampler_comparison"),struct:new d("struct",g.keyword,"struct"),texture_1d:new d("texture_1d",g.keyword,"texture_1d"),texture_2d:new d("texture_2d",g.keyword,"texture_2d"),texture_2d_array:new d("texture_2d_array",g.keyword,"texture_2d_array"),texture_3d:new d("texture_3d",g.keyword,"texture_3d"),texture_cube:new d("texture_cube",g.keyword,"texture_cube"),texture_cube_array:new d("texture_cube_array",g.keyword,"texture_cube_array"),texture_multisampled_2d:new d("texture_multisampled_2d",g.keyword,"texture_multisampled_2d"),texture_storage_1d:new d("texture_storage_1d",g.keyword,"texture_storage_1d"),texture_storage_2d:new d("texture_storage_2d",g.keyword,"texture_storage_2d"),texture_storage_2d_array:new d("texture_storage_2d_array",g.keyword,"texture_storage_2d_array"),texture_storage_3d:new d("texture_storage_3d",g.keyword,"texture_storage_3d"),texture_depth_2d:new d("texture_depth_2d",g.keyword,"texture_depth_2d"),texture_depth_2d_array:new d("texture_depth_2d_array",g.keyword,"texture_depth_2d_array"),texture_depth_cube:new d("texture_depth_cube",g.keyword,"texture_depth_cube"),texture_depth_cube_array:new d("texture_depth_cube_array",g.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new d("texture_depth_multisampled_2d",g.keyword,"texture_depth_multisampled_2d"),texture_external:new d("texture_external",g.keyword,"texture_external"),u32:new d("u32",g.keyword,"u32"),vec2:new d("vec2",g.keyword,"vec2"),vec3:new d("vec3",g.keyword,"vec3"),vec4:new d("vec4",g.keyword,"vec4"),bitcast:new d("bitcast",g.keyword,"bitcast"),block:new d("block",g.keyword,"block"),break:new d("break",g.keyword,"break"),case:new d("case",g.keyword,"case"),continue:new d("continue",g.keyword,"continue"),continuing:new d("continuing",g.keyword,"continuing"),default:new d("default",g.keyword,"default"),diagnostic:new d("diagnostic",g.keyword,"diagnostic"),discard:new d("discard",g.keyword,"discard"),else:new d("else",g.keyword,"else"),enable:new d("enable",g.keyword,"enable"),fallthrough:new d("fallthrough",g.keyword,"fallthrough"),false:new d("false",g.keyword,"false"),fn:new d("fn",g.keyword,"fn"),for:new d("for",g.keyword,"for"),function:new d("function",g.keyword,"function"),if:new d("if",g.keyword,"if"),let:new d("let",g.keyword,"let"),const:new d("const",g.keyword,"const"),loop:new d("loop",g.keyword,"loop"),while:new d("while",g.keyword,"while"),private:new d("private",g.keyword,"private"),read:new d("read",g.keyword,"read"),read_write:new d("read_write",g.keyword,"read_write"),return:new d("return",g.keyword,"return"),requires:new d("requires",g.keyword,"requires"),storage:new d("storage",g.keyword,"storage"),switch:new d("switch",g.keyword,"switch"),true:new d("true",g.keyword,"true"),alias:new d("alias",g.keyword,"alias"),type:new d("type",g.keyword,"type"),uniform:new d("uniform",g.keyword,"uniform"),var:new d("var",g.keyword,"var"),override:new d("override",g.keyword,"override"),workgroup:new d("workgroup",g.keyword,"workgroup"),write:new d("write",g.keyword,"write"),r8unorm:new d("r8unorm",g.keyword,"r8unorm"),r8snorm:new d("r8snorm",g.keyword,"r8snorm"),r8uint:new d("r8uint",g.keyword,"r8uint"),r8sint:new d("r8sint",g.keyword,"r8sint"),r16uint:new d("r16uint",g.keyword,"r16uint"),r16sint:new d("r16sint",g.keyword,"r16sint"),r16float:new d("r16float",g.keyword,"r16float"),rg8unorm:new d("rg8unorm",g.keyword,"rg8unorm"),rg8snorm:new d("rg8snorm",g.keyword,"rg8snorm"),rg8uint:new d("rg8uint",g.keyword,"rg8uint"),rg8sint:new d("rg8sint",g.keyword,"rg8sint"),r32uint:new d("r32uint",g.keyword,"r32uint"),r32sint:new d("r32sint",g.keyword,"r32sint"),r32float:new d("r32float",g.keyword,"r32float"),rg16uint:new d("rg16uint",g.keyword,"rg16uint"),rg16sint:new d("rg16sint",g.keyword,"rg16sint"),rg16float:new d("rg16float",g.keyword,"rg16float"),rgba8unorm:new d("rgba8unorm",g.keyword,"rgba8unorm"),rgba8unorm_srgb:new d("rgba8unorm_srgb",g.keyword,"rgba8unorm_srgb"),rgba8snorm:new d("rgba8snorm",g.keyword,"rgba8snorm"),rgba8uint:new d("rgba8uint",g.keyword,"rgba8uint"),rgba8sint:new d("rgba8sint",g.keyword,"rgba8sint"),bgra8unorm:new d("bgra8unorm",g.keyword,"bgra8unorm"),bgra8unorm_srgb:new d("bgra8unorm_srgb",g.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new d("rgb10a2unorm",g.keyword,"rgb10a2unorm"),rg11b10float:new d("rg11b10float",g.keyword,"rg11b10float"),rg32uint:new d("rg32uint",g.keyword,"rg32uint"),rg32sint:new d("rg32sint",g.keyword,"rg32sint"),rg32float:new d("rg32float",g.keyword,"rg32float"),rgba16uint:new d("rgba16uint",g.keyword,"rgba16uint"),rgba16sint:new d("rgba16sint",g.keyword,"rgba16sint"),rgba16float:new d("rgba16float",g.keyword,"rgba16float"),rgba32uint:new d("rgba32uint",g.keyword,"rgba32uint"),rgba32sint:new d("rgba32sint",g.keyword,"rgba32sint"),rgba32float:new d("rgba32float",g.keyword,"rgba32float"),static_assert:new d("static_assert",g.keyword,"static_assert")},h.tokens={decimal_float_literal:new d("decimal_float_literal",g.token,/((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?[fh]?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+[fh]?)|(-?[0-9]+[fh])/),hex_float_literal:new d("hex_float_literal",g.token,/-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+[fh]?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+[fh]?))/),int_literal:new d("int_literal",g.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new d("uint_literal",g.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),name:new d("name",g.token,/([_\p{XID_Start}][\p{XID_Continue}]+)|([\p{XID_Start}])/u),ident:new d("ident",g.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new d("and",g.token,"&"),and_and:new d("and_and",g.token,"&&"),arrow:new d("arrow ",g.token,"->"),attr:new d("attr",g.token,"@"),forward_slash:new d("forward_slash",g.token,"/"),bang:new d("bang",g.token,"!"),bracket_left:new d("bracket_left",g.token,"["),bracket_right:new d("bracket_right",g.token,"]"),brace_left:new d("brace_left",g.token,"{"),brace_right:new d("brace_right",g.token,"}"),colon:new d("colon",g.token,":"),comma:new d("comma",g.token,","),equal:new d("equal",g.token,"="),equal_equal:new d("equal_equal",g.token,"=="),not_equal:new d("not_equal",g.token,"!="),greater_than:new d("greater_than",g.token,">"),greater_than_equal:new d("greater_than_equal",g.token,">="),shift_right:new d("shift_right",g.token,">>"),less_than:new d("less_than",g.token,"<"),less_than_equal:new d("less_than_equal",g.token,"<="),shift_left:new d("shift_left",g.token,"<<"),modulo:new d("modulo",g.token,"%"),minus:new d("minus",g.token,"-"),minus_minus:new d("minus_minus",g.token,"--"),period:new d("period",g.token,"."),plus:new d("plus",g.token,"+"),plus_plus:new d("plus_plus",g.token,"++"),or:new d("or",g.token,"|"),or_or:new d("or_or",g.token,"||"),paren_left:new d("paren_left",g.token,"("),paren_right:new d("paren_right",g.token,")"),semicolon:new d("semicolon",g.token,";"),star:new d("star",g.token,"*"),tilde:new d("tilde",g.token,"~"),underscore:new d("underscore",g.token,"_"),xor:new d("xor",g.token,"^"),plus_equal:new d("plus_equal",g.token,"+="),minus_equal:new d("minus_equal",g.token,"-="),times_equal:new d("times_equal",g.token,"*="),division_equal:new d("division_equal",g.token,"/="),modulo_equal:new d("modulo_equal",g.token,"%="),and_equal:new d("and_equal",g.token,"&="),or_equal:new d("or_equal",g.token,"|="),xor_equal:new d("xor_equal",g.token,"^="),shift_right_equal:new d("shift_right_equal",g.token,">>="),shift_left_equal:new d("shift_left_equal",g.token,"<<=")},h.simpleTokens={"@":v.tokens.attr,"{":v.tokens.brace_left,"}":v.tokens.brace_right,":":v.tokens.colon,",":v.tokens.comma,"(":v.tokens.paren_left,")":v.tokens.paren_right,";":v.tokens.semicolon},h.literalTokens={"&":v.tokens.and,"&&":v.tokens.and_and,"->":v.tokens.arrow,"/":v.tokens.forward_slash,"!":v.tokens.bang,"[":v.tokens.bracket_left,"]":v.tokens.bracket_right,"=":v.tokens.equal,"==":v.tokens.equal_equal,"!=":v.tokens.not_equal,">":v.tokens.greater_than,">=":v.tokens.greater_than_equal,">>":v.tokens.shift_right,"<":v.tokens.less_than,"<=":v.tokens.less_than_equal,"<<":v.tokens.shift_left,"%":v.tokens.modulo,"-":v.tokens.minus,"--":v.tokens.minus_minus,".":v.tokens.period,"+":v.tokens.plus,"++":v.tokens.plus_plus,"|":v.tokens.or,"||":v.tokens.or_or,"*":v.tokens.star,"~":v.tokens.tilde,_:v.tokens.underscore,"^":v.tokens.xor,"+=":v.tokens.plus_equal,"-=":v.tokens.minus_equal,"*=":v.tokens.times_equal,"/=":v.tokens.division_equal,"%=":v.tokens.modulo_equal,"&=":v.tokens.and_equal,"|=":v.tokens.or_equal,"^=":v.tokens.xor_equal,">>=":v.tokens.shift_right_equal,"<<=":v.tokens.shift_left_equal},h.regexTokens={decimal_float_literal:v.tokens.decimal_float_literal,hex_float_literal:v.tokens.hex_float_literal,int_literal:v.tokens.int_literal,uint_literal:v.tokens.uint_literal,ident:v.tokens.ident},h.storage_class=[v.keywords.function,v.keywords.private,v.keywords.workgroup,v.keywords.uniform,v.keywords.storage],h.access_mode=[v.keywords.read,v.keywords.write,v.keywords.read_write],h.sampler_type=[v.keywords.sampler,v.keywords.sampler_comparison],h.sampled_texture_type=[v.keywords.texture_1d,v.keywords.texture_2d,v.keywords.texture_2d_array,v.keywords.texture_3d,v.keywords.texture_cube,v.keywords.texture_cube_array],h.multisampled_texture_type=[v.keywords.texture_multisampled_2d],h.storage_texture_type=[v.keywords.texture_storage_1d,v.keywords.texture_storage_2d,v.keywords.texture_storage_2d_array,v.keywords.texture_storage_3d],h.depth_texture_type=[v.keywords.texture_depth_2d,v.keywords.texture_depth_2d_array,v.keywords.texture_depth_cube,v.keywords.texture_depth_cube_array,v.keywords.texture_depth_multisampled_2d],h.texture_external_type=[v.keywords.texture_external],h.any_texture_type=[...v.sampled_texture_type,...v.multisampled_texture_type,...v.storage_texture_type,...v.depth_texture_type,...v.texture_external_type],h.texel_format=[v.keywords.r8unorm,v.keywords.r8snorm,v.keywords.r8uint,v.keywords.r8sint,v.keywords.r16uint,v.keywords.r16sint,v.keywords.r16float,v.keywords.rg8unorm,v.keywords.rg8snorm,v.keywords.rg8uint,v.keywords.rg8sint,v.keywords.r32uint,v.keywords.r32sint,v.keywords.r32float,v.keywords.rg16uint,v.keywords.rg16sint,v.keywords.rg16float,v.keywords.rgba8unorm,v.keywords.rgba8unorm_srgb,v.keywords.rgba8snorm,v.keywords.rgba8uint,v.keywords.rgba8sint,v.keywords.bgra8unorm,v.keywords.bgra8unorm_srgb,v.keywords.rgb10a2unorm,v.keywords.rg11b10float,v.keywords.rg32uint,v.keywords.rg32sint,v.keywords.rg32float,v.keywords.rgba16uint,v.keywords.rgba16sint,v.keywords.rgba16float,v.keywords.rgba32uint,v.keywords.rgba32sint,v.keywords.rgba32float],h.const_literal=[v.tokens.int_literal,v.tokens.uint_literal,v.tokens.decimal_float_literal,v.tokens.hex_float_literal,v.keywords.true,v.keywords.false],h.literal_or_ident=[v.tokens.ident,v.tokens.int_literal,v.tokens.uint_literal,v.tokens.decimal_float_literal,v.tokens.hex_float_literal,v.tokens.name],h.element_count_expression=[v.tokens.int_literal,v.tokens.uint_literal,v.tokens.ident],h.template_types=[v.keywords.vec2,v.keywords.vec3,v.keywords.vec4,v.keywords.mat2x2,v.keywords.mat2x3,v.keywords.mat2x4,v.keywords.mat3x2,v.keywords.mat3x3,v.keywords.mat3x4,v.keywords.mat4x2,v.keywords.mat4x3,v.keywords.mat4x4,v.keywords.atomic,v.keywords.bitcast,...v.any_texture_type],h.attribute_name=[v.tokens.ident,v.keywords.block,v.keywords.diagnostic],h.assignment_operators=[v.tokens.equal,v.tokens.plus_equal,v.tokens.minus_equal,v.tokens.times_equal,v.tokens.division_equal,v.tokens.modulo_equal,v.tokens.and_equal,v.tokens.or_equal,v.tokens.xor_equal,v.tokens.shift_right_equal,v.tokens.shift_left_equal],h.increment_operators=[v.tokens.plus_plus,v.tokens.minus_minus];var Bt=class{constructor(e,t,n,r,s){this.type=e,this.lexeme=t,this.line=n,this.start=r,this.end=s}toString(){return this.lexeme}isTemplateType(){return h.template_types.indexOf(this.type)!=-1}isArrayType(){return this.type==h.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}},bn=class{constructor(e){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=e??""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new Bt(h.eof,"",this._line,this._current,this._current)),this._tokens}scanToken(){let e=this._advance();if(e==`
|
|
101
101
|
`)return this._line++,!0;if(this._isWhitespace(e))return!0;if(e=="/"){if(this._peekAhead()=="/"){for(;e!=`
|
|
102
|
-
`;){if(this._isAtEnd())return!0;e=this._advance()}return this._line++,!0}
|
|
103
|
-
`)this._line++;else if(e=="*"){if(this._peekAhead()=="/"&&(this._advance(),a--,a==0))return!0}else e=="/"&&this._peekAhead()=="*"&&(this._advance(),a++)}return!0}}let n=o.simpleTokens[e];if(n)return this._addToken(n),!0;let r=o.none,i=this._isAlpha(e),s=e==="_";if(this._isAlphaNumeric(e)){let a=this._peekAhead();for(;this._isAlphaNumeric(a);)e+=this._advance(),a=this._peekAhead()}if(i){let a=o.keywords[e];if(a)return this._addToken(a),!0}if(i||s)return this._addToken(o.tokens.ident),!0;for(;;){let a=this._findType(e),c=this._peekAhead();if(e==">"&&(c==">"||c=="=")){let h=!1,_=this._tokens.length-1;for(let p=0;p<5&&_>=0;++p,--_)if(this._tokens[_].type===o.tokens.less_than){_>0&&this._tokens[_-1].isArrayOrTemplateType()&&(h=!0);break}if(h)return this._addToken(a),!0}if(a===o.none){let h=e,_=0,p=2;for(let d=0;d<p;++d)if(h+=this._peekAhead(d),a=this._findType(h),a!==o.none){_=d;break}if(a===o.none)return r===o.none?!1:(this._current--,this._addToken(r),!0);e=h,this._current+=_+1}if(r=a,this._isAtEnd())break;e+=this._advance()}return r===o.none?!1:(this._addToken(r),!0)}_findType(e){for(let r in o.regexTokens){let i=o.regexTokens[r];if(this._match(e,i.rule))return i}let n=o.literalTokens[e];return n||o.none}_match(e,n){let r=n.exec(e);return r&&r.index==0&&r[0]==e}_isAtEnd(){return this._current>=this._source.length}_isAlpha(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"}_isAlphaNumeric(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"||e=="_"||e>="0"&&e<="9"}_isWhitespace(e){return e==" "||e==" "||e=="\r"}_advance(e=0){let n=this._source[this._current];return e=e||0,e++,this._current+=e,n}_peekAhead(e=0){return e=e||0,this._current+e>=this._source.length?"\0":this._source[this._current+e]}_addToken(e){let n=this._source.substring(this._start,this._current);this._tokens.push(new Xe(e,n,this._line))}},jt=class{constructor(){this._tokens=[],this._current=0,this._currentLine=0,this._context=new mt,this._deferArrayCountEval=[]}parse(e){this._initialize(e),this._deferArrayCountEval.length=0;let n=[];for(;!this._isAtEnd();){let r=this._global_decl_or_directive();if(!r)break;n.push(r)}if(this._deferArrayCountEval.length>0){for(let r of this._deferArrayCountEval){let i=r.arrayType,s=r.countNode;if(s instanceof Le){let c=s.name,h=this._context.constants.get(c);if(h)try{let _=h.evaluate(this._context);i.count=_}catch{}}}this._deferArrayCountEval.length=0}return n}_initialize(e){if(e)if(typeof e=="string"){let n=new Ht(e);this._tokens=n.scanTokens()}else this._tokens=e;else this._tokens=[];this._current=0}_error(e,n){return{token:e,message:n,toString:function(){return`${n}`}}}_isAtEnd(){return this._current>=this._tokens.length||this._peek().type==o.eof}_match(e){if(e instanceof l)return this._check(e)?(this._advance(),!0):!1;for(let n=0,r=e.length;n<r;++n){let i=e[n];if(this._check(i))return this._advance(),!0}return!1}_consume(e,n){if(this._check(e))return this._advance();throw this._error(this._peek(),n)}_check(e){if(this._isAtEnd())return!1;let n=this._peek();if(e instanceof Array){let r=n.type;return e.indexOf(r)!=-1}return n.type==e}_advance(){var e,n;return this._currentLine=(n=(e=this._peek())===null||e===void 0?void 0:e.line)!==null&&n!==void 0?n:-1,this._isAtEnd()||this._current++,this._previous()}_peek(){return this._tokens[this._current]}_previous(){return this._tokens[this._current-1]}_global_decl_or_directive(){for(;this._match(o.tokens.semicolon)&&!this._isAtEnd(););if(this._match(o.keywords.alias)){let n=this._type_alias();return this._consume(o.tokens.semicolon,"Expected ';'"),n}if(this._match(o.keywords.diagnostic)){let n=this._diagnostic();return this._consume(o.tokens.semicolon,"Expected ';'"),n}if(this._match(o.keywords.requires)){let n=this._requires_directive();return this._consume(o.tokens.semicolon,"Expected ';'"),n}if(this._match(o.keywords.enable)){let n=this._enable_directive();return this._consume(o.tokens.semicolon,"Expected ';'"),n}let e=this._attribute();if(this._check(o.keywords.var)){let n=this._global_variable_decl();return n!=null&&(n.attributes=e),this._consume(o.tokens.semicolon,"Expected ';'."),n}if(this._check(o.keywords.override)){let n=this._override_variable_decl();return n!=null&&(n.attributes=e),this._consume(o.tokens.semicolon,"Expected ';'."),n}if(this._check(o.keywords.let)){let n=this._global_let_decl();return n!=null&&(n.attributes=e),this._consume(o.tokens.semicolon,"Expected ';'."),n}if(this._check(o.keywords.const)){let n=this._global_const_decl();return n!=null&&(n.attributes=e),this._consume(o.tokens.semicolon,"Expected ';'."),n}if(this._check(o.keywords.struct)){let n=this._struct_decl();return n!=null&&(n.attributes=e),n}if(this._check(o.keywords.fn)){let n=this._function_decl();return n!=null&&(n.attributes=e),n}return null}_function_decl(){if(!this._match(o.keywords.fn))return null;let e=this._currentLine,n=this._consume(o.tokens.ident,"Expected function name.").toString();this._consume(o.tokens.paren_left,"Expected '(' for function arguments.");let r=[];if(!this._check(o.tokens.paren_right))do{if(this._check(o.tokens.paren_right))break;let c=this._attribute(),h=this._consume(o.tokens.ident,"Expected argument name.").toString();this._consume(o.tokens.colon,"Expected ':' for argument type.");let _=this._attribute(),p=this._type_decl();p!=null&&(p.attributes=_,r.push(new Bt(h,p,c)))}while(this._match(o.tokens.comma));this._consume(o.tokens.paren_right,"Expected ')' after function arguments.");let i=null;if(this._match(o.tokens.arrow)){let c=this._attribute();i=this._type_decl(),i!=null&&(i.attributes=c)}let s=this._compound_statement(),a=this._currentLine;return new ye(n,r,i,s,e,a)}_compound_statement(){let e=[];for(this._consume(o.tokens.brace_left,"Expected '{' for block.");!this._check(o.tokens.brace_right);){let n=this._statement();n!==null&&e.push(n)}return this._consume(o.tokens.brace_right,"Expected '}' for block."),e}_statement(){for(;this._match(o.tokens.semicolon)&&!this._isAtEnd(););if(this._check(o.tokens.attr)&&this._attribute(),this._check(o.keywords.if))return this._if_statement();if(this._check(o.keywords.switch))return this._switch_statement();if(this._check(o.keywords.loop))return this._loop_statement();if(this._check(o.keywords.for))return this._for_statement();if(this._check(o.keywords.while))return this._while_statement();if(this._check(o.keywords.continuing))return this._continuing_statement();if(this._check(o.keywords.static_assert))return this._static_assert_statement();if(this._check(o.tokens.brace_left))return this._compound_statement();let e=null;return this._check(o.keywords.return)?e=this._return_statement():this._check([o.keywords.var,o.keywords.let,o.keywords.const])?e=this._variable_statement():this._match(o.keywords.discard)?e=new Nt:this._match(o.keywords.break)?e=new Pt:this._match(o.keywords.continue)?e=new Tt:e=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement(),e!=null&&this._consume(o.tokens.semicolon,"Expected ';' after statement."),e}_static_assert_statement(){if(!this._match(o.keywords.static_assert))return null;let e=this._optional_paren_expression();return new gt(e)}_while_statement(){if(!this._match(o.keywords.while))return null;let e=this._optional_paren_expression();this._check(o.tokens.attr)&&this._attribute();let n=this._compound_statement();return new vt(e,n)}_continuing_statement(){if(!this._match(o.keywords.continuing))return null;let e=this._compound_statement();return new xt(e)}_for_statement(){if(!this._match(o.keywords.for))return null;this._consume(o.tokens.paren_left,"Expected '('.");let e=this._check(o.tokens.semicolon)?null:this._for_init();this._consume(o.tokens.semicolon,"Expected ';'.");let n=this._check(o.tokens.semicolon)?null:this._short_circuit_or_expression();this._consume(o.tokens.semicolon,"Expected ';'.");let r=this._check(o.tokens.paren_right)?null:this._for_increment();this._consume(o.tokens.paren_right,"Expected ')'."),this._check(o.tokens.attr)&&this._attribute();let i=this._compound_statement();return new bt(e,n,r,i)}_for_init(){return this._variable_statement()||this._func_call_statement()||this._assignment_statement()}_for_increment(){return this._func_call_statement()||this._increment_decrement_statement()||this._assignment_statement()}_variable_statement(){if(this._check(o.keywords.var)){let e=this._variable_decl();if(e===null)throw this._error(this._peek(),"Variable declaration expected.");let n=null;return this._match(o.tokens.equal)&&(n=this._short_circuit_or_expression()),new H(e.name,e.type,e.storage,e.access,n)}if(this._match(o.keywords.let)){let e=this._consume(o.tokens.ident,"Expected name for let.").toString(),n=null;if(this._match(o.tokens.colon)){let i=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=i)}this._consume(o.tokens.equal,"Expected '=' for let.");let r=this._short_circuit_or_expression();return new we(e,n,null,null,r)}if(this._match(o.keywords.const)){let e=this._consume(o.tokens.ident,"Expected name for const.").toString(),n=null;if(this._match(o.tokens.colon)){let i=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=i)}this._consume(o.tokens.equal,"Expected '=' for const.");let r=this._short_circuit_or_expression();return new ze(e,n,null,null,r)}return null}_increment_decrement_statement(){let e=this._current,n=this._unary_expression();if(n==null)return null;if(!this._check(o.increment_operators))return this._current=e,null;let r=this._consume(o.increment_operators,"Expected increment operator");return new yt(r.type===o.tokens.plus_plus?ce.increment:ce.decrement,n)}_assignment_statement(){let e=null;if(this._check(o.tokens.brace_right))return null;let n=this._match(o.tokens.underscore);if(n||(e=this._unary_expression()),!n&&e==null)return null;let r=this._consume(o.assignment_operators,"Expected assignment operator."),i=this._short_circuit_or_expression();return new wt(ke.parse(r.lexeme),e,i)}_func_call_statement(){if(!this._check(o.tokens.ident))return null;let e=this._current,n=this._consume(o.tokens.ident,"Expected function name."),r=this._argument_expression_list();return r===null?(this._current=e,null):new Ue(n.lexeme,r)}_loop_statement(){if(!this._match(o.keywords.loop))return null;this._check(o.tokens.attr)&&this._attribute(),this._consume(o.tokens.brace_left,"Expected '{' for loop.");let e=[],n=this._statement();for(;n!==null;){if(Array.isArray(n))for(let i of n)e.push(i);else e.push(n);n=this._statement()}let r=null;return this._match(o.keywords.continuing)&&(r=this._compound_statement()),this._consume(o.tokens.brace_right,"Expected '}' for loop."),new kt(e,r)}_switch_statement(){if(!this._match(o.keywords.switch))return null;let e=this._optional_paren_expression();this._check(o.tokens.attr)&&this._attribute(),this._consume(o.tokens.brace_left,"Expected '{' for switch.");let n=this._switch_body();if(n==null||n.length==0)throw this._error(this._previous(),"Expected 'case' or 'default'.");return this._consume(o.tokens.brace_right,"Expected '}' for switch."),new Lt(e,n)}_switch_body(){let e=[];if(this._match(o.keywords.case)){let n=this._case_selectors();this._match(o.tokens.colon),this._check(o.tokens.attr)&&this._attribute(),this._consume(o.tokens.brace_left,"Exected '{' for switch case.");let r=this._case_body();this._consume(o.tokens.brace_right,"Exected '}' for switch case."),e.push(new zt(n,r))}if(this._match(o.keywords.default)){this._match(o.tokens.colon),this._check(o.tokens.attr)&&this._attribute(),this._consume(o.tokens.brace_left,"Exected '{' for switch default.");let n=this._case_body();this._consume(o.tokens.brace_right,"Exected '}' for switch default."),e.push(new Ut(n))}if(this._check([o.keywords.default,o.keywords.case])){let n=this._switch_body();e.push(n[0])}return e}_case_selectors(){let e=[this._shift_expression()];for(;this._match(o.tokens.comma);)e.push(this._shift_expression());return e}_case_body(){if(this._match(o.keywords.fallthrough))return this._consume(o.tokens.semicolon,"Expected ';'"),[];let e=this._statement();if(e==null)return[];e instanceof Array||(e=[e]);let n=this._case_body();return n.length==0?e:[...e,n[0]]}_if_statement(){if(!this._match(o.keywords.if))return null;let e=this._optional_paren_expression();this._check(o.tokens.attr)&&this._attribute();let n=this._compound_statement(),r=[];this._match_elseif()&&(this._check(o.tokens.attr)&&this._attribute(),r=this._elseif_statement(r));let i=null;return this._match(o.keywords.else)&&(this._check(o.tokens.attr)&&this._attribute(),i=this._compound_statement()),new At(e,n,r,i)}_match_elseif(){return this._tokens[this._current].type===o.keywords.else&&this._tokens[this._current+1].type===o.keywords.if?(this._advance(),this._advance(),!0):!1}_elseif_statement(e=[]){let n=this._optional_paren_expression(),r=this._compound_statement();return e.push(new Gt(n,r)),this._match_elseif()&&(this._check(o.tokens.attr)&&this._attribute(),this._elseif_statement(e)),e}_return_statement(){if(!this._match(o.keywords.return))return null;let e=this._short_circuit_or_expression();return new Mt(e)}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(o.tokens.or_or);)e=new z(this._previous().toString(),e,this._short_circuit_and_expr());return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(o.tokens.and_and);)e=new z(this._previous().toString(),e,this._inclusive_or_expression());return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(o.tokens.or);)e=new z(this._previous().toString(),e,this._exclusive_or_expression());return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(o.tokens.xor);)e=new z(this._previous().toString(),e,this._and_expression());return e}_and_expression(){let e=this._equality_expression();for(;this._match(o.tokens.and);)e=new z(this._previous().toString(),e,this._equality_expression());return e}_equality_expression(){let e=this._relational_expression();return this._match([o.tokens.equal_equal,o.tokens.not_equal])?new z(this._previous().toString(),e,this._relational_expression()):e}_relational_expression(){let e=this._shift_expression();for(;this._match([o.tokens.less_than,o.tokens.greater_than,o.tokens.less_than_equal,o.tokens.greater_than_equal]);)e=new z(this._previous().toString(),e,this._shift_expression());return e}_shift_expression(){let e=this._additive_expression();for(;this._match([o.tokens.shift_left,o.tokens.shift_right]);)e=new z(this._previous().toString(),e,this._additive_expression());return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([o.tokens.plus,o.tokens.minus]);)e=new z(this._previous().toString(),e,this._multiplicative_expression());return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([o.tokens.star,o.tokens.forward_slash,o.tokens.modulo]);)e=new z(this._previous().toString(),e,this._unary_expression());return e}_unary_expression(){return this._match([o.tokens.minus,o.tokens.bang,o.tokens.tilde,o.tokens.star,o.tokens.and])?new Dt(this._previous().toString(),this._unary_expression()):this._singular_expression()}_singular_expression(){let e=this._primary_expression(),n=this._postfix_expression();return n&&(e.postfix=n),e}_postfix_expression(){if(this._match(o.tokens.bracket_left)){let e=this._short_circuit_or_expression();this._consume(o.tokens.bracket_right,"Expected ']'.");let n=new Ft(e),r=this._postfix_expression();return r&&(n.postfix=r),n}if(this._match(o.tokens.period)){let e=this._consume(o.tokens.ident,"Expected member name."),n=this._postfix_expression(),r=new Ve(e.lexeme);return n&&(r.postfix=n),r}return null}_getStruct(e){return this._context.aliases.has(e)?this._context.aliases.get(e).type:this._context.structs.has(e)?this._context.structs.get(e):null}_primary_expression(){if(this._match(o.tokens.ident)){let r=this._previous().toString();if(this._check(o.tokens.paren_left)){let i=this._argument_expression_list(),s=this._getStruct(r);return s!=null?new K(s,i):new He(r,i)}if(this._context.constants.has(r)){let i=this._context.constants.get(r);return new je(r,i.value)}return new Le(r)}if(this._match(o.const_literal))return new We(parseFloat(this._previous().toString()));if(this._check(o.tokens.paren_left))return this._paren_expression();if(this._match(o.keywords.bitcast)){this._consume(o.tokens.less_than,"Expected '<'.");let r=this._type_decl();this._consume(o.tokens.greater_than,"Expected '>'.");let i=this._paren_expression();return new Ot(r,i)}let e=this._type_decl(),n=this._argument_expression_list();return new Ct(e,n)}_argument_expression_list(){if(!this._match(o.tokens.paren_left))return null;let e=[];do{if(this._check(o.tokens.paren_right))break;let n=this._short_circuit_or_expression();e.push(n)}while(this._match(o.tokens.comma));return this._consume(o.tokens.paren_right,"Expected ')' for agument list"),e}_optional_paren_expression(){this._match(o.tokens.paren_left);let e=this._short_circuit_or_expression();return this._match(o.tokens.paren_right),new $e([e])}_paren_expression(){this._consume(o.tokens.paren_left,"Expected '('.");let e=this._short_circuit_or_expression();return this._consume(o.tokens.paren_right,"Expected ')'."),new $e([e])}_struct_decl(){if(!this._match(o.keywords.struct))return null;let e=this._currentLine,n=this._consume(o.tokens.ident,"Expected name for struct.").toString();this._consume(o.tokens.brace_left,"Expected '{' for struct body.");let r=[];for(;!this._check(o.tokens.brace_right);){let a=this._attribute(),c=this._consume(o.tokens.ident,"Expected variable name.").toString();this._consume(o.tokens.colon,"Expected ':' for struct member type.");let h=this._attribute(),_=this._type_decl();_!=null&&(_.attributes=h),this._check(o.tokens.brace_right)?this._match(o.tokens.comma):this._consume(o.tokens.comma,"Expected ',' for struct member."),r.push(new qt(c,_,a))}this._consume(o.tokens.brace_right,"Expected '}' after struct body.");let i=this._currentLine,s=new V(n,r,e,i);return this._context.structs.set(n,s),s}_global_variable_decl(){let e=this._variable_decl();return e&&this._match(o.tokens.equal)&&(e.value=this._const_expression()),e}_override_variable_decl(){let e=this._override_decl();return e&&this._match(o.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){if(!this._match(o.keywords.const))return null;let e=this._consume(o.tokens.ident,"Expected variable name"),n=null;if(this._match(o.tokens.colon)){let s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}let r=null;if(this._match(o.tokens.equal)){let s=this._short_circuit_or_expression();if(s instanceof K)r=s;else if(s instanceof je&&s.initializer instanceof K)r=s.initializer;else try{let a=s.evaluate(this._context);r=new We(a)}catch{r=s}}let i=new ze(e.toString(),n,"","",r);return this._context.constants.set(i.name,i),i}_global_let_decl(){if(!this._match(o.keywords.let))return null;let e=this._consume(o.tokens.ident,"Expected variable name"),n=null;if(this._match(o.tokens.colon)){let i=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=i)}let r=null;return this._match(o.tokens.equal)&&(r=this._const_expression()),new we(e.toString(),n,"","",r)}_const_expression(){if(this._match(o.const_literal))return new Ve(this._previous().toString());let e=this._type_decl();this._consume(o.tokens.paren_left,"Expected '('.");let n=[];for(;!this._check(o.tokens.paren_right)&&(n.push(this._const_expression()),!!this._check(o.tokens.comma));)this._advance();return this._consume(o.tokens.paren_right,"Expected ')'."),new K(e,n)}_variable_decl(){if(!this._match(o.keywords.var))return null;let e="",n="";this._match(o.tokens.less_than)&&(e=this._consume(o.storage_class,"Expected storage_class.").toString(),this._match(o.tokens.comma)&&(n=this._consume(o.access_mode,"Expected access_mode.").toString()),this._consume(o.tokens.greater_than,"Expected '>'."));let r=this._consume(o.tokens.ident,"Expected variable name"),i=null;if(this._match(o.tokens.colon)){let s=this._attribute();i=this._type_decl(),i!=null&&(i.attributes=s)}return new H(r.toString(),i,e,n,null)}_override_decl(){if(!this._match(o.keywords.override))return null;let e=this._consume(o.tokens.ident,"Expected variable name"),n=null;if(this._match(o.tokens.colon)){let r=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=r)}return new De(e.toString(),n,null)}_diagnostic(){this._consume(o.tokens.paren_left,"Expected '('");let e=this._consume(o.tokens.ident,"Expected severity control name.");this._consume(o.tokens.comma,"Expected ','");let n=this._consume(o.tokens.ident,"Expected diagnostic rule name.");return this._consume(o.tokens.paren_right,"Expected ')'"),new It(e.toString(),n.toString())}_enable_directive(){let e=this._consume(o.tokens.ident,"identity expected.");return new St(e.toString())}_requires_directive(){let e=[this._consume(o.tokens.ident,"identity expected.").toString()];for(;this._match(o.tokens.comma);){let n=this._consume(o.tokens.ident,"identity expected.");e.push(n.toString())}return new Et(e)}_type_alias(){let e=this._consume(o.tokens.ident,"identity expected.");this._consume(o.tokens.equal,"Expected '=' for type alias.");let n=this._type_decl();if(n===null)throw this._error(this._peek(),"Expected Type for Alias.");this._context.aliases.has(n.name)&&(n=this._context.aliases.get(n.name).type);let r=new Be(e.toString(),n);return this._context.aliases.set(r.name,r),r}_type_decl(){if(this._check([o.tokens.ident,...o.texel_format,o.keywords.bool,o.keywords.f32,o.keywords.i32,o.keywords.u32])){let r=this._advance(),i=r.toString();return this._context.structs.has(i)?this._context.structs.get(i):this._context.aliases.has(i)?this._context.aliases.get(i).type:new j(r.toString())}let e=this._texture_sampler_types();if(e)return e;if(this._check(o.template_types)){let r=this._advance().toString(),i=null,s=null;return this._match(o.tokens.less_than)&&(i=this._type_decl(),s=null,this._match(o.tokens.comma)&&(s=this._consume(o.access_mode,"Expected access_mode for pointer").toString()),this._consume(o.tokens.greater_than,"Expected '>' for type.")),new Ge(r,i,s)}if(this._match(o.keywords.ptr)){let r=this._previous().toString();this._consume(o.tokens.less_than,"Expected '<' for pointer.");let i=this._consume(o.storage_class,"Expected storage_class for pointer");this._consume(o.tokens.comma,"Expected ',' for pointer.");let s=this._type_decl(),a=null;return this._match(o.tokens.comma)&&(a=this._consume(o.access_mode,"Expected access_mode for pointer").toString()),this._consume(o.tokens.greater_than,"Expected '>' for pointer."),new Rt(r,i.toString(),s,a)}let n=this._attribute();if(this._match(o.keywords.array)){let r=null,i=-1,s=this._previous(),a=null;if(this._match(o.tokens.less_than)){r=this._type_decl(),this._context.aliases.has(r.name)&&(r=this._context.aliases.get(r.name).type);let h="";if(this._match(o.tokens.comma)){a=this._shift_expression();try{h=a.evaluate(this._context).toString(),a=null}catch{h="1"}}this._consume(o.tokens.greater_than,"Expected '>' for array."),i=h?parseInt(h):0}let c=new qe(s.toString(),n,r,i);return a&&this._deferArrayCountEval.push({arrayType:c,countNode:a}),c}return null}_texture_sampler_types(){if(this._match(o.sampler_type))return new J(this._previous().toString(),null,null);if(this._match(o.depth_texture_type))return new J(this._previous().toString(),null,null);if(this._match(o.sampled_texture_type)||this._match(o.multisampled_texture_type)){let e=this._previous();this._consume(o.tokens.less_than,"Expected '<' for sampler type.");let n=this._type_decl();return this._consume(o.tokens.greater_than,"Expected '>' for sampler type."),new J(e.toString(),n,null)}if(this._match(o.storage_texture_type)){let e=this._previous();this._consume(o.tokens.less_than,"Expected '<' for sampler type.");let n=this._consume(o.texel_format,"Invalid texel format.").toString();this._consume(o.tokens.comma,"Expected ',' after texel format.");let r=this._consume(o.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(o.tokens.greater_than,"Expected '>' for sampler type."),new J(e.toString(),n,r)}return null}_attribute(){let e=[];for(;this._match(o.tokens.attr);){let n=this._consume(o.attribute_name,"Expected attribute name"),r=new Vt(n.toString(),null);if(this._match(o.tokens.paren_left)){if(r.value=this._consume(o.literal_or_ident,"Expected attribute value").toString(),this._check(o.tokens.comma)){this._advance();do{let i=this._consume(o.literal_or_ident,"Expected attribute value").toString();r.value instanceof Array||(r.value=[r.value]),r.value.push(i)}while(this._match(o.tokens.comma))}this._consume(o.tokens.paren_right,"Expected ')'")}e.push(r)}return e.length==0?null:e}},X=class{constructor(e,n){this.name=e,this.attributes=n,this.size=0}get isArray(){return!1}get isStruct(){return!1}get isTemplate(){return!1}},Ze=class{constructor(e,n,r){this.name=e,this.type=n,this.attributes=r,this.offset=0,this.size=0}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray?this.type.format:this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},re=class extends X{constructor(e,n){super(e,n),this.members=[],this.align=0,this.startLine=-1,this.endLine=-1,this.inUse=!1}get isStruct(){return!0}},be=class extends X{constructor(e,n){super(e,n),this.count=0,this.stride=0}get isArray(){return!0}},Je=class extends X{constructor(e,n,r,i){super(e,r),this.format=n,this.access=i}get isTemplate(){return!0}},Y;(function(t){t[t.Uniform=0]="Uniform",t[t.Storage=1]="Storage",t[t.Texture=2]="Texture",t[t.Sampler=3]="Sampler",t[t.StorageTexture=4]="StorageTexture"})(Y||(Y={}));var ie=class{constructor(e,n,r,i,s,a,c){this.name=e,this.type=n,this.group=r,this.binding=i,this.attributes=s,this.resourceType=a,this.access=c}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get size(){return this.type.size}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray?this.type.format:this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},Wt=class{constructor(e,n){this.name=e,this.type=n}},se=class{constructor(e,n){this.align=e,this.size=n}},$t=class{constructor(e,n,r,i){this.name=e,this.type=n,this.locationType=r,this.location=i,this.interpolation=null}},Qe=class{constructor(e,n,r,i){this.name=e,this.type=n,this.locationType=r,this.location=i}},Yt=class{constructor(e,n=null){this.stage=null,this.inputs=[],this.outputs=[],this.resources=[],this.startLine=-1,this.endLine=-1,this.inUse=!1,this.calls=new Set,this.name=e,this.stage=n}},Kt=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}},Xt=class{constructor(e,n,r,i){this.name=e,this.type=n,this.attributes=r,this.id=i}},Zt=class{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}},U=class{constructor(e){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new Kt,this.functions=[],this._types=new Map,this._functions=new Map,e&&this.update(e)}_isStorageTexture(e){return e.name=="texture_storage_1d"||e.name=="texture_storage_2d"||e.name=="texture_storage_2d_array"||e.name=="texture_storage_3d"}update(e){let r=new jt().parse(e);for(let i of r)i instanceof ye&&this._functions.set(i.name,new Zt(i));for(let i of r)if(i instanceof V){let s=this._getTypeInfo(i,null);s instanceof re&&this.structs.push(s)}for(let i of r){if(i instanceof Be){this.aliases.push(this._getAliasInfo(i));continue}if(i instanceof De){let s=i,a=this._getAttributeNum(s.attributes,"id",0),c=s.type!=null?this._getTypeInfo(s.type,s.attributes):null;this.overrides.push(new Xt(s.name,c,s.attributes,a));continue}if(this._isUniformVar(i)){let s=i,a=this._getAttributeNum(s.attributes,"group",0),c=this._getAttributeNum(s.attributes,"binding",0),h=this._getTypeInfo(s.type,s.attributes),_=new ie(s.name,h,a,c,s.attributes,Y.Uniform,s.access);this.uniforms.push(_);continue}if(this._isStorageVar(i)){let s=i,a=this._getAttributeNum(s.attributes,"group",0),c=this._getAttributeNum(s.attributes,"binding",0),h=this._getTypeInfo(s.type,s.attributes),_=this._isStorageTexture(h),p=new ie(s.name,h,a,c,s.attributes,_?Y.StorageTexture:Y.Storage,s.access);this.storage.push(p);continue}if(this._isTextureVar(i)){let s=i,a=this._getAttributeNum(s.attributes,"group",0),c=this._getAttributeNum(s.attributes,"binding",0),h=this._getTypeInfo(s.type,s.attributes),_=this._isStorageTexture(h),p=new ie(s.name,h,a,c,s.attributes,_?Y.StorageTexture:Y.Texture,s.access);_?this.storage.push(p):this.textures.push(p);continue}if(this._isSamplerVar(i)){let s=i,a=this._getAttributeNum(s.attributes,"group",0),c=this._getAttributeNum(s.attributes,"binding",0),h=this._getTypeInfo(s.type,s.attributes),_=new ie(s.name,h,a,c,s.attributes,Y.Sampler,s.access);this.samplers.push(_);continue}if(i instanceof ye){let s=this._getAttribute(i,"vertex"),a=this._getAttribute(i,"fragment"),c=this._getAttribute(i,"compute"),h=s||a||c,_=new Yt(i.name,h?.name);_.startLine=i.startLine,_.endLine=i.endLine,this.functions.push(_),this._functions.get(i.name).info=_,h&&(this._functions.get(i.name).inUse=!0,_.inUse=!0,_.resources=this._findResources(i,!!h),_.inputs=this._getInputs(i.args),_.outputs=this._getOutputs(i.returnType),this.entry[h.name].push(_));continue}}for(let i of this._functions.values())i.info&&(i.info.inUse=i.inUse,this._addCalls(i.node,i.info.calls));for(let i of this.uniforms)this._markStructsInUse(i.type);for(let i of this.storage)this._markStructsInUse(i.type)}_markStructsInUse(e){if(e.isStruct){e.inUse=!0;for(let n of e.members)this._markStructsInUse(n.type)}else if(e.isArray)this._markStructsInUse(e.format);else if(e.isTemplate)this._markStructsInUse(e.format);else{let n=this._getAlias(e.name);n&&this._markStructsInUse(n)}}_addCalls(e,n){var r;for(let i of e.calls){let s=(r=this._functions.get(i.name))===null||r===void 0?void 0:r.info;s&&n.add(s)}}findResource(e,n){for(let r of this.uniforms)if(r.group==e&&r.binding==n)return r;for(let r of this.storage)if(r.group==e&&r.binding==n)return r;for(let r of this.textures)if(r.group==e&&r.binding==n)return r;for(let r of this.samplers)if(r.group==e&&r.binding==n)return r;return null}_findResource(e){for(let n of this.uniforms)if(n.name==e)return n;for(let n of this.storage)if(n.name==e)return n;for(let n of this.textures)if(n.name==e)return n;for(let n of this.samplers)if(n.name==e)return n;return null}_markStructsFromAST(e){let n=this._getTypeInfo(e,null);this._markStructsInUse(n)}_findResources(e,n){let r=[],i=this,s=[];return e.search(a=>{if(a instanceof oe)s.push({});else if(a instanceof ae)s.pop();else if(a instanceof H){let c=a;n&&c.type!==null&&this._markStructsFromAST(c.type),s.length>0&&(s[s.length-1][c.name]=c)}else if(a instanceof K){let c=a;n&&c.type!==null&&this._markStructsFromAST(c.type)}else if(a instanceof we){let c=a;n&&c.type!==null&&this._markStructsFromAST(c.type),s.length>0&&(s[s.length-1][c.name]=c)}else if(a instanceof Le){let c=a;if(s.length>0&&s[s.length-1][c.name])return;let h=i._findResource(c.name);h&&r.push(h)}else if(a instanceof He){let c=a,h=i._functions.get(c.name);h&&(n&&(h.inUse=!0),e.calls.add(h.node),h.resources===null&&(h.resources=i._findResources(h.node,n)),r.push(...h.resources))}else if(a instanceof Ue){let c=a,h=i._functions.get(c.name);h&&(n&&(h.inUse=!0),e.calls.add(h.node),h.resources===null&&(h.resources=i._findResources(h.node,n)),r.push(...h.resources))}}),[...new Map(r.map(a=>[a.name,a])).values()]}getBindGroups(){let e=[];function n(r,i){r>=e.length&&(e.length=r+1),e[r]===void 0&&(e[r]=[]),i>=e[r].length&&(e[r].length=i+1)}for(let r of this.uniforms){n(r.group,r.binding);let i=e[r.group];i[r.binding]=r}for(let r of this.storage){n(r.group,r.binding);let i=e[r.group];i[r.binding]=r}for(let r of this.textures){n(r.group,r.binding);let i=e[r.group];i[r.binding]=r}for(let r of this.samplers){n(r.group,r.binding);let i=e[r.group];i[r.binding]=r}return e}_getOutputs(e,n=void 0){if(n===void 0&&(n=[]),e instanceof V)this._getStructOutputs(e,n);else{let r=this._getOutputInfo(e);r!==null&&n.push(r)}return n}_getStructOutputs(e,n){for(let r of e.members)if(r.type instanceof V)this._getStructOutputs(r.type,n);else{let i=this._getAttribute(r,"location")||this._getAttribute(r,"builtin");if(i!==null){let s=this._getTypeInfo(r.type,r.type.attributes),a=this._parseInt(i.value),c=new Qe(r.name,s,i.name,a);n.push(c)}}}_getOutputInfo(e){let n=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(n!==null){let r=this._getTypeInfo(e,e.attributes),i=this._parseInt(n.value);return new Qe("",r,n.name,i)}return null}_getInputs(e,n=void 0){n===void 0&&(n=[]);for(let r of e)if(r.type instanceof V)this._getStructInputs(r.type,n);else{let i=this._getInputInfo(r);i!==null&&n.push(i)}return n}_getStructInputs(e,n){for(let r of e.members)if(r.type instanceof V)this._getStructInputs(r.type,n);else{let i=this._getInputInfo(r);i!==null&&n.push(i)}}_getInputInfo(e){let n=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(n!==null){let r=this._getAttribute(e,"interpolation"),i=this._getTypeInfo(e.type,e.attributes),s=this._parseInt(n.value),a=new $t(e.name,i,n.name,s);return r!==null&&(a.interpolation=this._parseString(r.value)),a}return null}_parseString(e){return e instanceof Array&&(e=e[0]),e}_parseInt(e){e instanceof Array&&(e=e[0]);let n=parseInt(e);return isNaN(n)?e:n}_getAlias(e){for(let n of this.aliases)if(n.name==e)return n.type;return null}_getAliasInfo(e){return new Wt(e.name,this._getTypeInfo(e.type,null))}_getTypeInfo(e,n){if(this._types.has(e))return this._types.get(e);if(e instanceof qe){let i=e,s=this._getTypeInfo(i.format,i.attributes),a=new be(i.name,n);return a.format=s,a.count=i.count,this._types.set(e,a),this._updateTypeInfo(a),a}if(e instanceof V){let i=e,s=new re(i.name,n);s.startLine=i.startLine,s.endLine=i.endLine;for(let a of i.members){let c=this._getTypeInfo(a.type,a.attributes);s.members.push(new Ze(a.name,c,a.attributes))}return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof J){let i=e,s=i.format instanceof j,a=i.format?s?this._getTypeInfo(i.format,null):new X(i.format,null):null,c=new Je(i.name,a,n,i.access);return this._types.set(e,c),this._updateTypeInfo(c),c}if(e instanceof Ge){let i=e,s=i.format?this._getTypeInfo(i.format,null):null,a=new Je(i.name,s,n,i.access);return this._types.set(e,a),this._updateTypeInfo(a),a}let r=new X(e.name,n);return this._types.set(e,r),this._updateTypeInfo(r),r}_updateTypeInfo(e){var n,r;let i=this._getTypeSize(e);if(e.size=(n=i?.size)!==null&&n!==void 0?n:0,e instanceof be){let s=this._getTypeSize(e.format);e.stride=(r=s?.size)!==null&&r!==void 0?r:0,this._updateTypeInfo(e.format)}e instanceof re&&this._updateStructInfo(e)}_updateStructInfo(e){var n;let r=0,i=0,s=0,a=0;for(let c=0,h=e.members.length;c<h;++c){let _=e.members[c],p=this._getTypeSize(_);if(!p)continue;(n=this._getAlias(_.type.name))!==null&&n!==void 0||_.type;let d=p.align,m=p.size;r=this._roundUp(d,r+i),i=m,s=r,a=Math.max(a,d),_.offset=r,_.size=m,this._updateTypeInfo(_.type)}e.size=this._roundUp(a,s+i),e.align=a}_getTypeSize(e){var n;if(e==null)return null;let r=this._getAttributeNum(e.attributes,"size",0),i=this._getAttributeNum(e.attributes,"align",0);if(e instanceof Ze&&(e=e.type),e instanceof X){let s=this._getAlias(e.name);s!==null&&(e=s)}{let s=U._typeInfo[e.name];if(s!==void 0){let a=e.format==="f16"?2:1;return new se(Math.max(i,s.align/a),Math.max(r,s.size/a))}}{let s=U._typeInfo[e.name.substring(0,e.name.length-1)];if(s){let a=e.name[e.name.length-1]==="h"?2:1;return new se(Math.max(i,s.align/a),Math.max(r,s.size/a))}}if(e instanceof be){let s=e,a=8,c=8,h=this._getTypeSize(s.format);h!==null&&(c=h.size,a=h.align);let _=s.count,p=this._getAttributeNum((n=e?.attributes)!==null&&n!==void 0?n:null,"stride",this._roundUp(a,c));return c=_*p,r&&(c=r),new se(Math.max(i,a),Math.max(r,c))}if(e instanceof re){let s=0,a=0,c=0,h=0,_=0;for(let p of e.members){let d=this._getTypeSize(p.type);d!==null&&(s=Math.max(d.align,s),c=this._roundUp(d.align,c+h),h=d.size,_=c)}return a=this._roundUp(s,_+h),new se(Math.max(i,s),Math.max(r,a))}return null}_isUniformVar(e){return e instanceof H&&e.storage=="uniform"}_isStorageVar(e){return e instanceof H&&e.storage=="storage"}_isTextureVar(e){return e instanceof H&&e.type!==null&&U._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof H&&e.type!==null&&U._samplerTypes.indexOf(e.type.name)!=-1}_getAttribute(e,n){let r=e;if(!r||!r.attributes)return null;let i=r.attributes;for(let s of i)if(s.name==n)return s;return null}_getAttributeNum(e,n,r){if(e===null)return r;for(let i of e)if(i.name==n){let s=i!==null&&i.value!==null?i.value:r;return s instanceof Array&&(s=s[0]),typeof s=="number"?s:typeof s=="string"?parseInt(s):r}return r}_roundUp(e,n){return Math.ceil(n/e)*e}};U._typeInfo={f16:{align:2,size:2},i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},atomic:{align:4,size:4},vec2:{align:8,size:8},vec3:{align:16,size:12},vec4:{align:16,size:16},mat2x2:{align:8,size:16},mat3x2:{align:8,size:24},mat4x2:{align:8,size:32},mat2x3:{align:16,size:32},mat3x3:{align:16,size:48},mat4x3:{align:16,size:64},mat2x4:{align:16,size:32},mat3x4:{align:16,size:48},mat4x4:{align:16,size:64}};U._textureTypes=o.any_texture_type.map(t=>t.name);U._samplerTypes=o.sampler_type.map(t=>t.name);function Wn(t){let e={attributes:[],bindings:[]},n;try{n=ki(t)}catch(s){return jn.log.error(s.message)(),e}for(let s of n.uniforms){let a=[];for(let c of s.type?.members||[])a.push({name:c.name,type:Hn(c.type)});e.bindings.push({type:"uniform",name:s.name,group:s.group,location:s.binding,members:a})}for(let s of n.textures)e.bindings.push({type:"texture",name:s.name,group:s.group,location:s.binding});for(let s of n.samplers)e.bindings.push({type:"sampler",name:s.name,group:s.group,location:s.binding});let r=n.entry.vertex[0],i=r?.inputs.length||0;for(let s=0;s<i;s++){let a=r.inputs[s];if(a.locationType==="location"){let c=Hn(a.type);e.attributes.push({name:a.name,location:Number(a.location),type:c})}}return e}function Hn(t){return t.format?`${t.name}<${t.format.name}>`:t.name}function ki(t){try{return new U(t)}catch(e){if(e instanceof Error)throw e;let n="WGSL parse error";throw typeof e=="object"&&e?.message&&(n+=`: ${e.message} `),typeof e=="object"&&e?.token&&(n+=e.token.line||""),new Error(n,{cause:e})}}var oo=1/Math.PI*180,ao=1/180*Math.PI,Li={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Li}};var C=globalThis.mathgl.config;function Jt(t,{precision:e=C.precision}={}){return t=Ai(t),`${parseFloat(t.toPrecision(e))}`}function le(t){return Array.isArray(t)||ArrayBuffer.isView(t)&&!(t instanceof DataView)}function Qt(t,e,n){return Si(t,r=>Math.max(e,Math.min(n,r)))}function et(t,e,n){let r=C.EPSILON;n&&(C.EPSILON=n);try{if(t===e)return!0;if(le(t)&&le(e)){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!et(t[i],e[i]))return!1;return!0}return t&&t.equals?t.equals(e):e&&e.equals?e.equals(t):typeof t=="number"&&typeof e=="number"?Math.abs(t-e)<=C.EPSILON*Math.max(1,Math.abs(t),Math.abs(e)):!1}finally{C.EPSILON=r}}function Ai(t){return Math.round(t/C.EPSILON)*C.EPSILON}function Mi(t){return t.clone?t.clone():new Array(t.length)}function Si(t,e,n){if(le(t)){let r=t;n=n||Mi(r);for(let i=0;i<n.length&&i<r.length;++i){let s=typeof t=="number"?t:t[i];n[i]=e(s,i,n)}return n}return e(t)}var tt=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(e,n=0){for(let r=0;r<this.ELEMENTS;++r)this[r]=e[r+n];return this.check()}toArray(e=[],n=0){for(let r=0;r<this.ELEMENTS;++r)e[n+r]=this[r];return e}toObject(e){return e}from(e){return Array.isArray(e)?this.copy(e):this.fromObject(e)}to(e){return e===this?this:le(e)?this.toArray(e):this.toObject(e)}toTarget(e){return e?this.to(e):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(C)}formatString(e){let n="";for(let r=0;r<this.ELEMENTS;++r)n+=(r>0?", ":"")+Jt(this[r],e);return`${e.printTypes?this.constructor.name:""}[${n}]`}equals(e){if(!e||this.length!==e.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(!et(this[n],e[n]))return!1;return!0}exactEquals(e){if(!e||this.length!==e.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(this[n]!==e[n])return!1;return!0}negate(){for(let e=0;e<this.ELEMENTS;++e)this[e]=-this[e];return this.check()}lerp(e,n,r){if(r===void 0)return this.lerp(this,e,n);for(let i=0;i<this.ELEMENTS;++i){let s=e[i],a=typeof n=="number"?n:n[i];this[i]=s+r*(a-s)}return this.check()}min(e){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(e[n],this[n]);return this.check()}max(e){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.max(e[n],this[n]);return this.check()}clamp(e,n){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],e[r]),n[r]);return this.check()}add(...e){for(let n of e)for(let r=0;r<this.ELEMENTS;++r)this[r]+=n[r];return this.check()}subtract(...e){for(let n of e)for(let r=0;r<this.ELEMENTS;++r)this[r]-=n[r];return this.check()}scale(e){if(typeof e=="number")for(let n=0;n<this.ELEMENTS;++n)this[n]*=e;else for(let n=0;n<this.ELEMENTS&&n<e.length;++n)this[n]*=e[n];return this.check()}multiplyByScalar(e){for(let n=0;n<this.ELEMENTS;++n)this[n]*=e;return this.check()}check(){if(C.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let e=this.length===this.ELEMENTS;for(let n=0;n<this.ELEMENTS;++n)e=e&&Number.isFinite(this[n]);return e}sub(e){return this.subtract(e)}setScalar(e){for(let n=0;n<this.ELEMENTS;++n)this[n]=e;return this.check()}addScalar(e){for(let n=0;n<this.ELEMENTS;++n)this[n]+=e;return this.check()}subScalar(e){return this.addScalar(-e)}multiplyScalar(e){for(let n=0;n<this.ELEMENTS;++n)this[n]*=e;return this.check()}divideScalar(e){return this.multiplyByScalar(1/e)}clampScalar(e,n){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],e),n);return this.check()}get elements(){return this}};function Ei(t,e){if(t.length!==e)return!1;for(let n=0;n<t.length;++n)if(!Number.isFinite(t[n]))return!1;return!0}function $n(t){if(!Number.isFinite(t))throw new Error(`Invalid number ${JSON.stringify(t)}`);return t}function nt(t,e,n=""){if(C.debug&&!Ei(t,e))throw new Error(`math.gl: ${n} some fields set to invalid numbers'`);return t}var W=typeof Float32Array<"u"?Float32Array:Array;var _o=Math.PI/180;function Ii(){let t=new W(2);return W!=Float32Array&&(t[0]=0,t[1]=0),t}function Xn(t,e,n){let r=e[0],i=e[1];return t[0]=n[0]*r+n[4]*i+n[12],t[1]=n[1]*r+n[5]*i+n[13],t}var po=function(){let t=Ii();return function(e,n,r,i,s,a){let c,h;for(n||(n=2),r||(r=0),i?h=Math.min(i*n+r,e.length):h=e.length,c=r;c<h;c+=n)t[0]=e[c],t[1]=e[c+1],s(t,t,a),e[c]=t[0],e[c+1]=t[1];return e}}();function Zn(t,e,n){let r=e[0],i=e[1],s=n[3]*r+n[7]*i||1;return t[0]=(n[0]*r+n[4]*i)/s,t[1]=(n[1]*r+n[5]*i)/s,t}function Jn(t,e,n){let r=e[0],i=e[1],s=e[2],a=n[3]*r+n[7]*i+n[11]*s||1;return t[0]=(n[0]*r+n[4]*i+n[8]*s)/a,t[1]=(n[1]*r+n[5]*i+n[9]*s)/a,t[2]=(n[2]*r+n[6]*i+n[10]*s)/a,t}function Ni(){let t=new W(3);return W!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function Qn(t,e,n){let r=e[0],i=e[1],s=e[2],a=n[3]*r+n[7]*i+n[11]*s+n[15];return a=a||1,t[0]=(n[0]*r+n[4]*i+n[8]*s+n[12])/a,t[1]=(n[1]*r+n[5]*i+n[9]*s+n[13])/a,t[2]=(n[2]*r+n[6]*i+n[10]*s+n[14])/a,t}var vo=function(){let t=Ni();return function(e,n,r,i,s,a){let c,h;for(n||(n=3),r||(r=0),i?h=Math.min(i*n+r,e.length):h=e.length,c=r;c<h;c+=n)t[0]=e[c],t[1]=e[c+1],t[2]=e[c+2],s(t,t,a),e[c]=t[0],e[c+1]=t[1],e[c+2]=t[2];return e}}();var rt=class extends tt{toString(){let e="[";if(C.printRowMajor){e+="row-major:";for(let n=0;n<this.RANK;++n)for(let r=0;r<this.RANK;++r)e+=` ${this[r*this.RANK+n]}`}else{e+="column-major:";for(let n=0;n<this.ELEMENTS;++n)e+=` ${this[n]}`}return e+="]",e}getElementIndex(e,n){return n*this.RANK+e}getElement(e,n){return this[n*this.RANK+e]}setElement(e,n,r){return this[n*this.RANK+e]=$n(r),this}getColumn(e,n=new Array(this.RANK).fill(-0)){let r=e*this.RANK;for(let i=0;i<this.RANK;++i)n[i]=this[r+i];return n}setColumn(e,n){let r=e*this.RANK;for(let i=0;i<this.RANK;++i)this[r+i]=n[i];return this}};function Pi(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function er(t,e){if(t===e){let n=e[1],r=e[2],i=e[3],s=e[6],a=e[7],c=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=n,t[6]=e[9],t[7]=e[13],t[8]=r,t[9]=s,t[11]=e[14],t[12]=i,t[13]=a,t[14]=c}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function tr(t,e){let n=e[0],r=e[1],i=e[2],s=e[3],a=e[4],c=e[5],h=e[6],_=e[7],p=e[8],d=e[9],m=e[10],v=e[11],L=e[12],g=e[13],b=e[14],A=e[15],x=n*c-r*a,w=n*h-i*a,k=n*_-s*a,y=r*h-i*c,M=r*_-s*c,S=i*_-s*h,T=p*g-d*L,P=p*b-m*L,I=p*A-v*L,R=d*b-m*g,D=d*A-v*g,O=m*A-v*b,N=x*O-w*D+k*R+y*I-M*P+S*T;return N?(N=1/N,t[0]=(c*O-h*D+_*R)*N,t[1]=(i*D-r*O-s*R)*N,t[2]=(g*S-b*M+A*y)*N,t[3]=(m*M-d*S-v*y)*N,t[4]=(h*I-a*O-_*P)*N,t[5]=(n*O-i*I+s*P)*N,t[6]=(b*k-L*S-A*w)*N,t[7]=(p*S-m*k+v*w)*N,t[8]=(a*D-c*I+_*T)*N,t[9]=(r*I-n*D-s*T)*N,t[10]=(L*M-g*k+A*x)*N,t[11]=(d*k-p*M-v*x)*N,t[12]=(c*P-a*R-h*T)*N,t[13]=(n*R-r*P+i*T)*N,t[14]=(g*w-L*y-b*x)*N,t[15]=(p*y-d*w+m*x)*N,t):null}function nr(t){let e=t[0],n=t[1],r=t[2],i=t[3],s=t[4],a=t[5],c=t[6],h=t[7],_=t[8],p=t[9],d=t[10],m=t[11],v=t[12],L=t[13],g=t[14],b=t[15],A=e*a-n*s,x=e*c-r*s,w=n*c-r*a,k=_*L-p*v,y=_*g-d*v,M=p*g-d*L,S=e*M-n*y+r*k,T=s*M-a*y+c*k,P=_*w-p*x+d*A,I=v*w-L*x+g*A;return h*S-i*T+b*P-m*I}function tn(t,e,n){let r=e[0],i=e[1],s=e[2],a=e[3],c=e[4],h=e[5],_=e[6],p=e[7],d=e[8],m=e[9],v=e[10],L=e[11],g=e[12],b=e[13],A=e[14],x=e[15],w=n[0],k=n[1],y=n[2],M=n[3];return t[0]=w*r+k*c+y*d+M*g,t[1]=w*i+k*h+y*m+M*b,t[2]=w*s+k*_+y*v+M*A,t[3]=w*a+k*p+y*L+M*x,w=n[4],k=n[5],y=n[6],M=n[7],t[4]=w*r+k*c+y*d+M*g,t[5]=w*i+k*h+y*m+M*b,t[6]=w*s+k*_+y*v+M*A,t[7]=w*a+k*p+y*L+M*x,w=n[8],k=n[9],y=n[10],M=n[11],t[8]=w*r+k*c+y*d+M*g,t[9]=w*i+k*h+y*m+M*b,t[10]=w*s+k*_+y*v+M*A,t[11]=w*a+k*p+y*L+M*x,w=n[12],k=n[13],y=n[14],M=n[15],t[12]=w*r+k*c+y*d+M*g,t[13]=w*i+k*h+y*m+M*b,t[14]=w*s+k*_+y*v+M*A,t[15]=w*a+k*p+y*L+M*x,t}function rr(t,e,n){let r=n[0],i=n[1],s=n[2],a,c,h,_,p,d,m,v,L,g,b,A;return e===t?(t[12]=e[0]*r+e[4]*i+e[8]*s+e[12],t[13]=e[1]*r+e[5]*i+e[9]*s+e[13],t[14]=e[2]*r+e[6]*i+e[10]*s+e[14],t[15]=e[3]*r+e[7]*i+e[11]*s+e[15]):(a=e[0],c=e[1],h=e[2],_=e[3],p=e[4],d=e[5],m=e[6],v=e[7],L=e[8],g=e[9],b=e[10],A=e[11],t[0]=a,t[1]=c,t[2]=h,t[3]=_,t[4]=p,t[5]=d,t[6]=m,t[7]=v,t[8]=L,t[9]=g,t[10]=b,t[11]=A,t[12]=a*r+p*i+L*s+e[12],t[13]=c*r+d*i+g*s+e[13],t[14]=h*r+m*i+b*s+e[14],t[15]=_*r+v*i+A*s+e[15]),t}function ir(t,e,n){let r=n[0],i=n[1],s=n[2];return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*s,t[9]=e[9]*s,t[10]=e[10]*s,t[11]=e[11]*s,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function sr(t,e,n,r){let i=r[0],s=r[1],a=r[2],c=Math.sqrt(i*i+s*s+a*a),h,_,p,d,m,v,L,g,b,A,x,w,k,y,M,S,T,P,I,R,D,O,N,ue;return c<1e-6?null:(c=1/c,i*=c,s*=c,a*=c,_=Math.sin(n),h=Math.cos(n),p=1-h,d=e[0],m=e[1],v=e[2],L=e[3],g=e[4],b=e[5],A=e[6],x=e[7],w=e[8],k=e[9],y=e[10],M=e[11],S=i*i*p+h,T=s*i*p+a*_,P=a*i*p-s*_,I=i*s*p-a*_,R=s*s*p+h,D=a*s*p+i*_,O=i*a*p+s*_,N=s*a*p-i*_,ue=a*a*p+h,t[0]=d*S+g*T+w*P,t[1]=m*S+b*T+k*P,t[2]=v*S+A*T+y*P,t[3]=L*S+x*T+M*P,t[4]=d*I+g*R+w*D,t[5]=m*I+b*R+k*D,t[6]=v*I+A*R+y*D,t[7]=L*I+x*R+M*D,t[8]=d*O+g*N+w*ue,t[9]=m*O+b*N+k*ue,t[10]=v*O+A*N+y*ue,t[11]=L*O+x*N+M*ue,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function or(t,e,n){let r=Math.sin(n),i=Math.cos(n),s=e[4],a=e[5],c=e[6],h=e[7],_=e[8],p=e[9],d=e[10],m=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=s*i+_*r,t[5]=a*i+p*r,t[6]=c*i+d*r,t[7]=h*i+m*r,t[8]=_*i-s*r,t[9]=p*i-a*r,t[10]=d*i-c*r,t[11]=m*i-h*r,t}function ar(t,e,n){let r=Math.sin(n),i=Math.cos(n),s=e[0],a=e[1],c=e[2],h=e[3],_=e[8],p=e[9],d=e[10],m=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=s*i-_*r,t[1]=a*i-p*r,t[2]=c*i-d*r,t[3]=h*i-m*r,t[8]=s*r+_*i,t[9]=a*r+p*i,t[10]=c*r+d*i,t[11]=h*r+m*i,t}function cr(t,e,n){let r=Math.sin(n),i=Math.cos(n),s=e[0],a=e[1],c=e[2],h=e[3],_=e[4],p=e[5],d=e[6],m=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=s*i+_*r,t[1]=a*i+p*r,t[2]=c*i+d*r,t[3]=h*i+m*r,t[4]=_*i-s*r,t[5]=p*i-a*r,t[6]=d*i-c*r,t[7]=m*i-h*r,t}function lr(t,e){let n=e[0],r=e[1],i=e[2],s=e[3],a=n+n,c=r+r,h=i+i,_=n*a,p=r*a,d=r*c,m=i*a,v=i*c,L=i*h,g=s*a,b=s*c,A=s*h;return t[0]=1-d-L,t[1]=p+A,t[2]=m-b,t[3]=0,t[4]=p-A,t[5]=1-_-L,t[6]=v+g,t[7]=0,t[8]=m+b,t[9]=v-g,t[10]=1-_-d,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function fr(t,e,n,r,i,s,a){let c=1/(n-e),h=1/(i-r),_=1/(s-a);return t[0]=s*2*c,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=s*2*h,t[6]=0,t[7]=0,t[8]=(n+e)*c,t[9]=(i+r)*h,t[10]=(a+s)*_,t[11]=-1,t[12]=0,t[13]=0,t[14]=a*s*2*_,t[15]=0,t}function Ti(t,e,n,r,i){let s=1/Math.tan(e/2);if(t[0]=s/n,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=s,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==1/0){let a=1/(r-i);t[10]=(i+r)*a,t[14]=2*i*r*a}else t[10]=-1,t[14]=-2*r;return t}var hr=Ti;function Ri(t,e,n,r,i,s,a){let c=1/(e-n),h=1/(r-i),_=1/(s-a);return t[0]=-2*c,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*h,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*_,t[11]=0,t[12]=(e+n)*c,t[13]=(i+r)*h,t[14]=(a+s)*_,t[15]=1,t}var ur=Ri;function _r(t,e,n,r){let i,s,a,c,h,_,p,d,m,v,L=e[0],g=e[1],b=e[2],A=r[0],x=r[1],w=r[2],k=n[0],y=n[1],M=n[2];return Math.abs(L-k)<1e-6&&Math.abs(g-y)<1e-6&&Math.abs(b-M)<1e-6?Pi(t):(d=L-k,m=g-y,v=b-M,i=1/Math.sqrt(d*d+m*m+v*v),d*=i,m*=i,v*=i,s=x*v-w*m,a=w*d-A*v,c=A*m-x*d,i=Math.sqrt(s*s+a*a+c*c),i?(i=1/i,s*=i,a*=i,c*=i):(s=0,a=0,c=0),h=m*c-v*a,_=v*s-d*c,p=d*a-m*s,i=Math.sqrt(h*h+_*_+p*p),i?(i=1/i,h*=i,_*=i,p*=i):(h=0,_=0,p=0),t[0]=s,t[1]=h,t[2]=d,t[3]=0,t[4]=a,t[5]=_,t[6]=m,t[7]=0,t[8]=c,t[9]=p,t[10]=v,t[11]=0,t[12]=-(s*L+a*g+c*b),t[13]=-(h*L+_*g+p*b),t[14]=-(d*L+m*g+v*b),t[15]=1,t)}function Oi(){let t=new W(4);return W!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t}function pr(t,e,n){let r=e[0],i=e[1],s=e[2],a=e[3];return t[0]=n[0]*r+n[4]*i+n[8]*s+n[12]*a,t[1]=n[1]*r+n[5]*i+n[9]*s+n[13]*a,t[2]=n[2]*r+n[6]*i+n[10]*s+n[14]*a,t[3]=n[3]*r+n[7]*i+n[11]*s+n[15]*a,t}var Ao=function(){let t=Oi();return function(e,n,r,i,s,a){let c,h;for(n||(n=4),r||(r=0),i?h=Math.min(i*n+r,e.length):h=e.length,c=r;c<h;c+=n)t[0]=e[c],t[1]=e[c+1],t[2]=e[c+2],t[3]=e[c+3],s(t,t,a),e[c]=t[0],e[c+1]=t[1],e[c+2]=t[2],e[c+3]=t[3];return e}}();var sn;(function(t){t[t.COL0ROW0=0]="COL0ROW0",t[t.COL0ROW1=1]="COL0ROW1",t[t.COL0ROW2=2]="COL0ROW2",t[t.COL0ROW3=3]="COL0ROW3",t[t.COL1ROW0=4]="COL1ROW0",t[t.COL1ROW1=5]="COL1ROW1",t[t.COL1ROW2=6]="COL1ROW2",t[t.COL1ROW3=7]="COL1ROW3",t[t.COL2ROW0=8]="COL2ROW0",t[t.COL2ROW1=9]="COL2ROW1",t[t.COL2ROW2=10]="COL2ROW2",t[t.COL2ROW3=11]="COL2ROW3",t[t.COL3ROW0=12]="COL3ROW0",t[t.COL3ROW1=13]="COL3ROW1",t[t.COL3ROW2=14]="COL3ROW2",t[t.COL3ROW3=15]="COL3ROW3"})(sn||(sn={}));var Ci=45*Math.PI/180,Fi=1,nn=.1,rn=500,Di=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),Q=class extends rt{static get IDENTITY(){return Ui()}static get ZERO(){return zi()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return sn}constructor(e){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(e)?this.copy(e):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this[9]=e[9],this[10]=e[10],this[11]=e[11],this[12]=e[12],this[13]=e[13],this[14]=e[14],this[15]=e[15],this.check()}set(e,n,r,i,s,a,c,h,_,p,d,m,v,L,g,b){return this[0]=e,this[1]=n,this[2]=r,this[3]=i,this[4]=s,this[5]=a,this[6]=c,this[7]=h,this[8]=_,this[9]=p,this[10]=d,this[11]=m,this[12]=v,this[13]=L,this[14]=g,this[15]=b,this.check()}setRowMajor(e,n,r,i,s,a,c,h,_,p,d,m,v,L,g,b){return this[0]=e,this[1]=s,this[2]=_,this[3]=v,this[4]=n,this[5]=a,this[6]=p,this[7]=L,this[8]=r,this[9]=c,this[10]=d,this[11]=g,this[12]=i,this[13]=h,this[14]=m,this[15]=b,this.check()}toRowMajor(e){return e[0]=this[0],e[1]=this[4],e[2]=this[8],e[3]=this[12],e[4]=this[1],e[5]=this[5],e[6]=this[9],e[7]=this[13],e[8]=this[2],e[9]=this[6],e[10]=this[10],e[11]=this[14],e[12]=this[3],e[13]=this[7],e[14]=this[11],e[15]=this[15],e}identity(){return this.copy(Di)}fromObject(e){return this.check()}fromQuaternion(e){return lr(this,e),this.check()}frustum(e){let{left:n,right:r,bottom:i,top:s,near:a=nn,far:c=rn}=e;return c===1/0?Bi(this,n,r,i,s,a):fr(this,n,r,i,s,a,c),this.check()}lookAt(e){let{eye:n,center:r=[0,0,0],up:i=[0,1,0]}=e;return _r(this,n,r,i),this.check()}ortho(e){let{left:n,right:r,bottom:i,top:s,near:a=nn,far:c=rn}=e;return ur(this,n,r,i,s,a,c),this.check()}orthographic(e){let{fovy:n=Ci,aspect:r=Fi,focalDistance:i=1,near:s=nn,far:a=rn}=e;dr(n);let c=n/2,h=i*Math.tan(c),_=h*r;return this.ortho({left:-_,right:_,bottom:-h,top:h,near:s,far:a})}perspective(e){let{fovy:n=45*Math.PI/180,aspect:r=1,near:i=.1,far:s=500}=e;return dr(n),hr(this,n,r,i,s),this.check()}determinant(){return nr(this)}getScale(e=[-0,-0,-0]){return e[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),e[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),e[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),e}getTranslation(e=[-0,-0,-0]){return e[0]=this[12],e[1]=this[13],e[2]=this[14],e}getRotation(e,n){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let r=this.getScale(n),i=1/r[0],s=1/r[1],a=1/r[2];return e[0]=this[0]*i,e[1]=this[1]*s,e[2]=this[2]*a,e[3]=0,e[4]=this[4]*i,e[5]=this[5]*s,e[6]=this[6]*a,e[7]=0,e[8]=this[8]*i,e[9]=this[9]*s,e[10]=this[10]*a,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}getRotationMatrix3(e,n){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let r=this.getScale(n),i=1/r[0],s=1/r[1],a=1/r[2];return e[0]=this[0]*i,e[1]=this[1]*s,e[2]=this[2]*a,e[3]=this[4]*i,e[4]=this[5]*s,e[5]=this[6]*a,e[6]=this[8]*i,e[7]=this[9]*s,e[8]=this[10]*a,e}transpose(){return er(this,this),this.check()}invert(){return tr(this,this),this.check()}multiplyLeft(e){return tn(this,e,this),this.check()}multiplyRight(e){return tn(this,this,e),this.check()}rotateX(e){return or(this,this,e),this.check()}rotateY(e){return ar(this,this,e),this.check()}rotateZ(e){return cr(this,this,e),this.check()}rotateXYZ(e){return this.rotateX(e[0]).rotateY(e[1]).rotateZ(e[2])}rotateAxis(e,n){return sr(this,this,e,n),this.check()}scale(e){return ir(this,this,Array.isArray(e)?e:[e,e,e]),this.check()}translate(e){return rr(this,this,e),this.check()}transform(e,n){return e.length===4?(n=pr(n||[-0,-0,-0,-0],e,this),nt(n,4),n):this.transformAsPoint(e,n)}transformAsPoint(e,n){let{length:r}=e,i;switch(r){case 2:i=Xn(n||[-0,-0],e,this);break;case 3:i=Qn(n||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return nt(i,e.length),i}transformAsVector(e,n){let r;switch(e.length){case 2:r=Zn(n||[-0,-0],e,this);break;case 3:r=Jn(n||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return nt(r,e.length),r}transformPoint(e,n){return this.transformAsPoint(e,n)}transformVector(e,n){return this.transformAsPoint(e,n)}transformDirection(e,n){return this.transformAsVector(e,n)}makeRotationX(e){return this.identity().rotateX(e)}makeTranslation(e,n,r){return this.identity().translate([e,n,r])}},it,st;function zi(){return it||(it=new Q([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(it)),it}function Ui(){return st||(st=new Q,Object.freeze(st)),st}function dr(t){if(t>Math.PI*2)throw Error("expected radians")}function Bi(t,e,n,r,i,s){let a=2*s/(n-e),c=2*s/(i-r),h=(n+e)/(n-e),_=(i+r)/(i-r),p=-1,d=-1,m=-2*s;return t[0]=a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=c,t[6]=0,t[7]=0,t[8]=h,t[9]=_,t[10]=p,t[11]=d,t[12]=0,t[13]=0,t[14]=m,t[15]=0,t}var ee=null,mr=new ArrayBuffer(4),gr=new Float32Array(mr),vr=new Uint32Array(mr);function xr(t){ee||=yr(),t=Qt(t,-65504,65504),gr[0]=t;let e=vr[0],n=e>>23&511;return ee.baseTable[n]+((e&8388607)>>ee.shiftTable[n])}function br(t){ee||=yr();let e=t>>10;return vr[0]=ee.mantissaTable[ee.offsetTable[e]+(t&1023)]+ee.exponentTable[e],gr[0]}function yr(){let t=new Uint32Array(512),e=new Uint32Array(512);for(let s=0;s<256;++s){let a=s-127;a<-27?(t[s]=0,t[s|256]=32768,e[s]=24,e[s|256]=24):a<-14?(t[s]=1024>>-a-14,t[s|256]=1024>>-a-14|32768,e[s]=-a-1,e[s|256]=-a-1):a<=15?(t[s]=a+15<<10,t[s|256]=a+15<<10|32768,e[s]=13,e[s|256]=13):a<128?(t[s]=31744,t[s|256]=64512,e[s]=24,e[s|256]=24):(t[s]=31744,t[s|256]=64512,e[s]=13,e[s|256]=13)}let n=new Uint32Array(2048),r=new Uint32Array(64),i=new Uint32Array(64);for(let s=1;s<1024;++s){let a=s<<13,c=0;for(;!(a&8388608);)a<<=1,c-=8388608;a&=-8388609,c+=947912704,n[s]=a|c}for(let s=1024;s<2048;++s)n[s]=939524096+(s-1024<<13);for(let s=1;s<31;++s)r[s]=s<<23;r[31]=1199570944,r[32]=2147483648;for(let s=33;s<63;++s)r[s]=2147483648+(s-32<<23);r[63]=3347054592;for(let s=1;s<64;++s)s!==32&&(i[s]=1024);return{baseTable:t,shiftTable:e,mantissaTable:n,exponentTable:r,offsetTable:i}}function he(t,e=[],n=0){let r=Math.fround(t),i=t-r;return e[n]=r,e[n+1]=i,e}function Ae(t){return t-Math.fround(t)}function Me(t){let e=new Float32Array(32);for(let n=0;n<4;++n)for(let r=0;r<4;++r){let i=n*4+r;he(t[r*4+n],e,i*2)}return e}var Gi=`float random(vec3 scale, float seed) {
|
|
102
|
+
`;){if(this._isAtEnd())return!0;e=this._advance()}return this._line++,!0}if(this._peekAhead()=="*"){this._advance();let a=1;for(;a>0;){if(this._isAtEnd())return!0;if(e=this._advance(),e==`
|
|
103
|
+
`)this._line++;else if(e=="*"){if(this._peekAhead()=="/"&&(this._advance(),a--,a==0))return!0}else e=="/"&&this._peekAhead()=="*"&&(this._advance(),a++)}return!0}}let t=h.simpleTokens[e];if(t)return this._addToken(t),!0;let n=h.none,r=this._isAlpha(e),s=e==="_";if(this._isAlphaNumeric(e)){let a=this._peekAhead();for(;this._isAlphaNumeric(a);)e+=this._advance(),a=this._peekAhead()}if(r){let a=h.keywords[e];if(a)return this._addToken(a),!0}if(r||s)return this._addToken(h.tokens.ident),!0;for(;;){let a=this._findType(e),o=this._peekAhead();if(e=="-"&&this._tokens.length>0){if(o=="=")return this._current++,e+=o,this._addToken(h.tokens.minus_equal),!0;if(o=="-")return this._current++,e+=o,this._addToken(h.tokens.minus_minus),!0;let c=this._tokens.length-1;if((h.literal_or_ident.indexOf(this._tokens[c].type)!=-1||this._tokens[c].type==h.tokens.paren_right)&&o!=">")return this._addToken(a),!0}if(e==">"&&(o==">"||o=="=")){let c=!1,l=this._tokens.length-1;for(let u=0;u<5&&l>=0&&h.assignment_operators.indexOf(this._tokens[l].type)===-1;++u,--l)if(this._tokens[l].type===h.tokens.less_than){l>0&&this._tokens[l-1].isArrayOrTemplateType()&&(c=!0);break}if(c)return this._addToken(a),!0}if(a===h.none){let c=e,l=0,u=2;for(let f=0;f<u;++f)if(c+=this._peekAhead(f),a=this._findType(c),a!==h.none){l=f;break}if(a===h.none)return n!==h.none&&(this._current--,this._addToken(n),!0);e=c,this._current+=l+1}if(n=a,this._isAtEnd())break;e+=this._advance()}return n!==h.none&&(this._addToken(n),!0)}_findType(e){for(let n in h.regexTokens){let r=h.regexTokens[n];if(this._match(e,r.rule))return r}return h.literalTokens[e]||h.none}_match(e,t){let n=t.exec(e);return n&&n.index==0&&n[0]==e}_isAtEnd(){return this._current>=this._source.length}_isAlpha(e){return!this._isNumeric(e)&&!this._isWhitespace(e)&&e!=="_"&&e!=="."&&e!=="("&&e!==")"&&e!=="["&&e!=="]"&&e!=="{"&&e!=="}"&&e!==","&&e!==";"&&e!==":"&&e!=="="&&e!=="!"&&e!=="<"&&e!==">"&&e!=="+"&&e!=="-"&&e!=="*"&&e!=="/"&&e!=="%"&&e!=="&"&&e!=="|"&&e!=="^"&&e!=="~"&&e!=="@"&&e!=="#"&&e!=="?"&&e!=="'"&&e!=="`"&&e!=='"'&&e!=="\\"&&e!==`
|
|
104
|
+
`&&e!=="\r"&&e!==" "&&e!=="\0"}_isNumeric(e){return e>="0"&&e<="9"}_isAlphaNumeric(e){return this._isAlpha(e)||this._isNumeric(e)||e==="_"}_isWhitespace(e){return e==" "||e==" "||e=="\r"}_advance(e=0){let t=this._source[this._current];return e=e||0,e++,this._current+=e,t}_peekAhead(e=0){return e=e||0,this._current+e>=this._source.length?"\0":this._source[this._current+e]}_addToken(e){let t=this._source.substring(this._start,this._current);this._tokens.push(new Bt(e,t,this._line,this._start,this._current))}};function A(i){return Array.isArray(i)||i?.buffer instanceof ArrayBuffer}var Vt=new Float32Array(1),ii=new Uint32Array(Vt.buffer),oi=new Uint32Array(Vt.buffer),$t=new Int32Array(1),ai=new Float32Array($t.buffer),ci=new Uint32Array($t.buffer),Ut=new Uint32Array(1),li=new Float32Array(Ut.buffer),ui=new Int32Array(Ut.buffer);function vr(i,e,t){if(e===t)return i;if(e==="f32"){if(t==="i32"||t==="x32")return Vt[0]=i,ii[0];if(t==="u32")return Vt[0]=i,oi[0]}else if(e==="i32"||e==="x32"){if(t==="f32")return $t[0]=i,ai[0];if(t==="u32")return $t[0]=i,ci[0]}else if(e==="u32"){if(t==="f32")return Ut[0]=i,li[0];if(t==="i32"||t==="x32")return Ut[0]=i,ui[0]}return console.error(`Unsupported cast from ${e} to ${t}`),i}var yn=class{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}},Me=class{constructor(e,t){this.align=e,this.size=t}},re=class{constructor(){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new mn,this.functions=[],this._types=new Map,this._functions=new Map}_isStorageTexture(e){return e.name=="texture_storage_1d"||e.name=="texture_storage_2d"||e.name=="texture_storage_2d_array"||e.name=="texture_storage_3d"}updateAST(e){for(let t of e)t instanceof ke&&this._functions.set(t.name,new yn(t));for(let t of e)if(t instanceof ie){let n=this.getTypeInfo(t,null);n instanceof ue&&this.structs.push(n)}for(let t of e)if(t instanceof Ze)this.aliases.push(this._getAliasInfo(t));else if(t instanceof Ye){let n=t,r=this._getAttributeNum(n.attributes,"id",0),s=n.type!=null?this.getTypeInfo(n.type,n.attributes):null;this.overrides.push(new fn(n.name,s,n.attributes,r))}else if(this._isUniformVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),o=new Te(n.name,a,r,s,n.attributes,ge.Uniform,n.access);o.access||(o.access="read"),this.uniforms.push(o)}else if(this._isStorageVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),o=this._isStorageTexture(a),c=new Te(n.name,a,r,s,n.attributes,o?ge.StorageTexture:ge.Storage,n.access);c.access||(c.access="read"),this.storage.push(c)}else if(this._isTextureVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),o=this._isStorageTexture(a),c=new Te(n.name,a,r,s,n.attributes,o?ge.StorageTexture:ge.Texture,n.access);c.access||(c.access="read"),o?this.storage.push(c):this.textures.push(c)}else if(this._isSamplerVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),o=new Te(n.name,a,r,s,n.attributes,ge.Sampler,n.access);this.samplers.push(o)}else if(t instanceof ke){let n=this._getAttribute(t,"vertex"),r=this._getAttribute(t,"fragment"),s=this._getAttribute(t,"compute"),a=n||r||s,o=new pn(t.name,a?.name,t.attributes);o.attributes=t.attributes,o.startLine=t.startLine,o.endLine=t.endLine,this.functions.push(o),this._functions.get(t.name).info=o,a&&(this._functions.get(t.name).inUse=!0,o.inUse=!0,o.resources=this._findResources(t,!!a),o.inputs=this._getInputs(t.args),o.outputs=this._getOutputs(t.returnType),this.entry[a.name].push(o)),o.arguments=t.args.map(c=>new hn(c.name,this.getTypeInfo(c.type,c.attributes),c.attributes)),o.returnType=t.returnType?this.getTypeInfo(t.returnType,t.attributes):null}for(let t of this._functions.values())t.info&&(t.info.inUse=t.inUse,this._addCalls(t.node,t.info.calls));for(let t of this._functions.values())t.node.search(n=>{var r,s,a;if(n instanceof Ft){if(n.value)if(A(n.value))for(let o of n.value)for(let c of this.overrides)o===c.name&&((r=t.info)===null||r===void 0||r.overrides.push(c));else for(let o of this.overrides)n.value===o.name&&((s=t.info)===null||s===void 0||s.overrides.push(o))}else if(n instanceof Y)for(let o of this.overrides)n.name===o.name&&((a=t.info)===null||a===void 0||a.overrides.push(o))});for(let t of this.uniforms)this._markStructsInUse(t.type);for(let t of this.storage)this._markStructsInUse(t.type)}getStructInfo(e){for(let t of this.structs)if(t.name==e)return t;return null}getOverrideInfo(e){for(let t of this.overrides)if(t.name==e)return t;return null}_markStructsInUse(e){if(e)if(e.isStruct){if(e.inUse=!0,e.members)for(let t of e.members)this._markStructsInUse(t.type)}else if(e.isArray)this._markStructsInUse(e.format);else if(e.isTemplate)e.format&&this._markStructsInUse(e.format);else{let t=this._getAlias(e.name);t&&this._markStructsInUse(t)}}_addCalls(e,t){var n;for(let r of e.calls){let s=(n=this._functions.get(r.name))===null||n===void 0?void 0:n.info;s&&t.add(s)}}findResource(e,t,n){if(n){for(let r of this.entry.compute)if(r.name===n){for(let s of r.resources)if(s.group==e&&s.binding==t)return s}for(let r of this.entry.vertex)if(r.name===n){for(let s of r.resources)if(s.group==e&&s.binding==t)return s}for(let r of this.entry.fragment)if(r.name===n){for(let s of r.resources)if(s.group==e&&s.binding==t)return s}}for(let r of this.uniforms)if(r.group==e&&r.binding==t)return r;for(let r of this.storage)if(r.group==e&&r.binding==t)return r;for(let r of this.textures)if(r.group==e&&r.binding==t)return r;for(let r of this.samplers)if(r.group==e&&r.binding==t)return r;return null}_findResource(e){for(let t of this.uniforms)if(t.name==e)return t;for(let t of this.storage)if(t.name==e)return t;for(let t of this.textures)if(t.name==e)return t;for(let t of this.samplers)if(t.name==e)return t;return null}_markStructsFromAST(e){let t=this.getTypeInfo(e,null);this._markStructsInUse(t)}_findResources(e,t){let n=[],r=this,s=[];return e.search(a=>{if(a instanceof Oe)s.push({});else if(a instanceof Pe)s.pop();else if(a instanceof ae){let o=a;t&&o.type!==null&&this._markStructsFromAST(o.type),s.length>0&&(s[s.length-1][o.name]=o)}else if(a instanceof ne){let o=a;t&&o.type!==null&&this._markStructsFromAST(o.type)}else if(a instanceof ye){let o=a;t&&o.type!==null&&this._markStructsFromAST(o.type),s.length>0&&(s[s.length-1][o.name]=o)}else if(a instanceof Y){let o=a;if(s.length>0&&s[s.length-1][o.name])return;let c=r._findResource(o.name);c&&n.push(c)}else if(a instanceof Qe){let o=a,c=r._functions.get(o.name);c&&(t&&(c.inUse=!0),e.calls.add(c.node),c.resources===null&&(c.resources=r._findResources(c.node,t)),n.push(...c.resources))}else if(a instanceof Ke){let o=a,c=r._functions.get(o.name);c&&(t&&(c.inUse=!0),e.calls.add(c.node),c.resources===null&&(c.resources=r._findResources(c.node,t)),n.push(...c.resources))}}),[...new Map(n.map(a=>[a.name,a])).values()]}getBindGroups(){let e=[];function t(n,r){n>=e.length&&(e.length=n+1),e[n]===void 0&&(e[n]=[]),r>=e[n].length&&(e[n].length=r+1)}for(let n of this.uniforms)t(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.storage)t(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.textures)t(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.samplers)t(n.group,n.binding),e[n.group][n.binding]=n;return e}_getOutputs(e,t=void 0){if(t===void 0&&(t=[]),e instanceof ie)this._getStructOutputs(e,t);else{let n=this._getOutputInfo(e);n!==null&&t.push(n)}return t}_getStructOutputs(e,t){for(let n of e.members)if(n.type instanceof ie)this._getStructOutputs(n.type,t);else{let r=this._getAttribute(n,"location")||this._getAttribute(n,"builtin");if(r!==null){let s=this.getTypeInfo(n.type,n.type.attributes),a=this._parseInt(r.value),o=new gt(n.name,s,r.name,a);t.push(o)}}}_getOutputInfo(e){let t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){let n=this.getTypeInfo(e,e.attributes),r=this._parseInt(t.value);return new gt("",n,t.name,r)}return null}_getInputs(e,t=void 0){t===void 0&&(t=[]);for(let n of e)if(n.type instanceof ie)this._getStructInputs(n.type,t);else{let r=this._getInputInfo(n);r!==null&&t.push(r)}return t}_getStructInputs(e,t){for(let n of e.members)if(n.type instanceof ie)this._getStructInputs(n.type,t);else{let r=this._getInputInfo(n);r!==null&&t.push(r)}}_getInputInfo(e){let t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){let n=this._getAttribute(e,"interpolation"),r=this.getTypeInfo(e.type,e.attributes),s=this._parseInt(t.value),a=new un(e.name,r,t.name,s);return n!==null&&(a.interpolation=this._parseString(n.value)),a}return null}_parseString(e){return e instanceof Array&&(e=e[0]),e}_parseInt(e){e instanceof Array&&(e=e[0]);let t=parseInt(e);return isNaN(t)?e:t}_getAlias(e){for(let t of this.aliases)if(t.name==e)return t.type;return null}_getAliasInfo(e){return new ln(e.name,this.getTypeInfo(e.type,null))}getTypeInfoByName(e){for(let t of this.structs)if(t.name==e)return t;for(let t of this.aliases)if(t.name==e)return t.type;return null}getTypeInfo(e,t=null){if(this._types.has(e))return this._types.get(e);if(e instanceof we){let r=e,s=r.format?this.getTypeInfo(r.format,r.attributes):null,a=new fe(r.name,t);return a.format=s,a.count=r.count,this._types.set(e,a),this._updateTypeInfo(a),a}if(e instanceof ie){let r=e,s=new ue(r.name,t);s.startLine=r.startLine,s.endLine=r.endLine;for(let a of r.members){let o=this.getTypeInfo(a.type,a.attributes);s.members.push(new dt(a.name,o,a.attributes))}return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof be){let r=e,s=r.format instanceof y,a=r.format?s?this.getTypeInfo(r.format,null):new Z(r.format,null):null,o=new he(r.name,a,t,r.access);return this._types.set(e,o),this._updateTypeInfo(o),o}if(e instanceof x){let r=e,s=r.format?this.getTypeInfo(r.format,null):null,a=new he(r.name,s,t,r.access);return this._types.set(e,a),this._updateTypeInfo(a),a}let n=new Z(e.name,t);return this._types.set(e,n),this._updateTypeInfo(n),n}_updateTypeInfo(e){var t,n,r;let s=this._getTypeSize(e);if(e.size=(t=s?.size)!==null&&t!==void 0?t:0,e instanceof fe&&e.format){let a=this._getTypeSize(e.format);e.stride=Math.max((n=a?.size)!==null&&n!==void 0?n:0,(r=a?.align)!==null&&r!==void 0?r:0),this._updateTypeInfo(e.format)}e instanceof ue&&this._updateStructInfo(e)}_updateStructInfo(e){var t;let n=0,r=0,s=0,a=0;for(let o=0,c=e.members.length;o<c;++o){let l=e.members[o],u=this._getTypeSize(l);if(!u)continue;(t=this._getAlias(l.type.name))!==null&&t!==void 0||l.type;let f=u.align,_=u.size;n=this._roundUp(f,n+r),r=_,s=n,a=Math.max(a,f),l.offset=n,l.size=_,this._updateTypeInfo(l.type)}e.size=this._roundUp(a,s+r),e.align=a}_getTypeSize(e){var t,n;if(e==null)return null;let r=this._getAttributeNum(e.attributes,"size",0),s=this._getAttributeNum(e.attributes,"align",0);if(e instanceof dt&&(e=e.type),e instanceof Z){let a=this._getAlias(e.name);a!==null&&(e=a)}{let a=re._typeInfo[e.name];if(a!==void 0){let o=((t=e.format)===null||t===void 0?void 0:t.name)==="f16"?2:1;return new Me(Math.max(s,a.align/o),Math.max(r,a.size/o))}}{let a=re._typeInfo[e.name.substring(0,e.name.length-1)];if(a){let o=e.name[e.name.length-1]==="h"?2:1;return new Me(Math.max(s,a.align/o),Math.max(r,a.size/o))}}if(e instanceof fe){let a=e,o=8,c=8,l=this._getTypeSize(a.format);return l!==null&&(c=l.size,o=l.align),c=a.count*this._getAttributeNum((n=e?.attributes)!==null&&n!==void 0?n:null,"stride",this._roundUp(o,c)),r&&(c=r),new Me(Math.max(s,o),Math.max(r,c))}if(e instanceof ue){let a=0,o=0,c=0,l=0,u=0;for(let f of e.members){let _=this._getTypeSize(f.type);_!==null&&(a=Math.max(_.align,a),c=this._roundUp(_.align,c+l),l=_.size,u=c)}return o=this._roundUp(a,u+l),new Me(Math.max(s,a),Math.max(r,o))}return null}_isUniformVar(e){return e instanceof ae&&e.storage=="uniform"}_isStorageVar(e){return e instanceof ae&&e.storage=="storage"}_isTextureVar(e){return e instanceof ae&&e.type!==null&&re._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof ae&&e.type!==null&&re._samplerTypes.indexOf(e.type.name)!=-1}_getAttribute(e,t){let n=e;if(!n||!n.attributes)return null;let r=n.attributes;for(let s of r)if(s.name==t)return s;return null}_getAttributeNum(e,t,n){if(e===null)return n;for(let r of e)if(r.name==t){let s=r!==null&&r.value!==null?r.value:n;return s instanceof Array&&(s=s[0]),typeof s=="number"?s:typeof s=="string"?parseInt(s):n}return n}_roundUp(e,t){return Math.ceil(t/e)*e}};re._typeInfo={f16:{align:2,size:2},i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},atomic:{align:4,size:4},vec2:{align:8,size:8},vec3:{align:16,size:12},vec4:{align:16,size:16},mat2x2:{align:8,size:16},mat3x2:{align:8,size:24},mat4x2:{align:8,size:32},mat2x3:{align:16,size:32},mat3x3:{align:16,size:48},mat4x3:{align:16,size:64},mat2x4:{align:16,size:32},mat3x4:{align:16,size:48},mat4x4:{align:16,size:64}},re._textureTypes=h.any_texture_type.map(i=>i.name),re._samplerTypes=h.sampler_type.map(i=>i.name);var et=class{constructor(e,t,n){this.name=e,this.value=t,this.node=n}clone(){return new et(this.name,this.value,this.node)}},tt=class{constructor(e){this.name=e.name,this.node=e}clone(){return new tt(this.node)}},nt=class{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName="",e&&(this.parent=e,this.currentFunctionName=e.currentFunctionName)}getVariable(e){var t;return this.variables.has(e)?(t=this.variables.get(e))!==null&&t!==void 0?t:null:this.parent?this.parent.getVariable(e):null}getFunction(e){var t;return this.functions.has(e)?(t=this.functions.get(e))!==null&&t!==void 0?t:null:this.parent?this.parent.getFunction(e):null}createVariable(e,t,n){this.variables.set(e,new et(e,t,n??null))}setVariable(e,t,n){let r=this.getVariable(e);r!==null?r.value=t:this.createVariable(e,t,n)}getVariableValue(e){var t;let n=this.getVariable(e);return(t=n?.value)!==null&&t!==void 0?t:null}clone(){return new nt(this)}},wn=class{evalExpression(e,t){return null}getTypeInfo(e){return null}getVariableName(e,t){return""}},kn=class{constructor(e){this.exec=e}getTypeInfo(e){return this.exec.getTypeInfo(e)}All(e,t){let n=this.exec.evalExpression(e.args[0],t),r=!0;if(n instanceof p)return n.data.forEach(s=>{s||(r=!1)}),new m(r?1:0,this.getTypeInfo("bool"));throw new Error(`All() expects a vector argument. Line ${e.line}`)}Any(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p){let r=n.data.some(s=>s);return new m(r?1:0,this.getTypeInfo("bool"))}throw new Error(`Any() expects a vector argument. Line ${e.line}`)}Select(e,t){let n=this.exec.evalExpression(e.args[2],t);if(!(n instanceof m))throw new Error(`Select() expects a bool condition. Line ${e.line}`);return n.value?this.exec.evalExpression(e.args[1],t):this.exec.evalExpression(e.args[0],t)}ArrayLength(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.evalExpression(n,t);if(r instanceof U&&r.typeInfo.size===0){let s=r.typeInfo,a=r.buffer.byteLength/s.stride;return new m(a,this.getTypeInfo("u32"))}return new m(r.typeInfo.size,this.getTypeInfo("u32"))}Abs(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.abs(s)),n.typeInfo);let r=n;return new m(Math.abs(r.value),r.typeInfo)}Acos(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.acos(s)),n.typeInfo);let r=n;return new m(Math.acos(r.value),n.typeInfo)}Acosh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.acosh(s)),n.typeInfo);let r=n;return new m(Math.acosh(r.value),n.typeInfo)}Asin(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.asin(s)),n.typeInfo);let r=n;return new m(Math.asin(r.value),n.typeInfo)}Asinh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.asinh(s)),n.typeInfo);let r=n;return new m(Math.asinh(r.value),n.typeInfo)}Atan(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.atan(s)),n.typeInfo);let r=n;return new m(Math.atan(r.value),n.typeInfo)}Atanh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.atanh(s)),n.typeInfo);let r=n;return new m(Math.atanh(r.value),n.typeInfo)}Atan2(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((o,c)=>Math.atan2(o,r.data[c])),n.typeInfo);let s=n,a=r;return new m(Math.atan2(s.value,a.value),n.typeInfo)}Ceil(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.ceil(s)),n.typeInfo);let r=n;return new m(Math.ceil(r.value),n.typeInfo)}_clamp(e,t,n){return Math.min(Math.max(e,t),n)}Clamp(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p)return new p(n.data.map((l,u)=>this._clamp(l,r.data[u],s.data[u])),n.typeInfo);let a=n,o=r,c=s;return new m(this._clamp(a.value,o.value,c.value),n.typeInfo)}Cos(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.cos(s)),n.typeInfo);let r=n;return new m(Math.cos(r.value),n.typeInfo)}Cosh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.cosh(s)),n.typeInfo);let r=n;return new m(Math.cos(r.value),n.typeInfo)}CountLeadingZeros(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.clz32(s)),n.typeInfo);let r=n;return new m(Math.clz32(r.value),n.typeInfo)}_countOneBits(e){let t=0;for(;e!==0;)1&e&&t++,e>>=1;return t}CountOneBits(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._countOneBits(s)),n.typeInfo);let r=n;return new m(this._countOneBits(r.value),n.typeInfo)}_countTrailingZeros(e){if(e===0)return 32;let t=0;for(;!(1&e);)e>>=1,t++;return t}CountTrailingZeros(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._countTrailingZeros(s)),n.typeInfo);let r=n;return new m(this._countTrailingZeros(r.value),n.typeInfo)}Cross(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p){if(n.data.length!==3||r.data.length!==3)return console.error(`Cross() expects 3D vectors. Line ${e.line}`),null;let s=n.data,a=r.data;return new p([s[1]*a[2]-a[1]*s[2],s[2]*a[0]-a[2]*s[0],s[0]*a[1]-a[0]*s[1]],n.typeInfo)}return console.error(`Cross() expects vector arguments. Line ${e.line}`),null}Degrees(e,t){let n=this.exec.evalExpression(e.args[0],t),r=180/Math.PI;return n instanceof p?new p(n.data.map(s=>s*r),n.typeInfo):new m(n.value*r,this.getTypeInfo("f32"))}Determinant(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof N){let r=n.data,s=n.typeInfo.getTypeName(),a=s.endsWith("h")?this.getTypeInfo("f16"):this.getTypeInfo("f32");if(s==="mat2x2"||s==="mat2x2f"||s==="mat2x2h")return new m(r[0]*r[3]-r[1]*r[2],a);if(s==="mat2x3"||s==="mat2x3f"||s==="mat2x3h")return new m(r[0]*(r[4]*r[8]-r[5]*r[7])-r[1]*(r[3]*r[8]-r[5]*r[6])+r[2]*(r[3]*r[7]-r[4]*r[6]),a);if(s==="mat2x4"||s==="mat2x4f"||s==="mat2x4h")console.error(`TODO: Determinant for ${s}`);else if(s==="mat3x2"||s==="mat3x2f"||s==="mat3x2h")console.error(`TODO: Determinant for ${s}`);else{if(s==="mat3x3"||s==="mat3x3f"||s==="mat3x3h")return new m(r[0]*(r[4]*r[8]-r[5]*r[7])-r[1]*(r[3]*r[8]-r[5]*r[6])+r[2]*(r[3]*r[7]-r[4]*r[6]),a);s==="mat3x4"||s==="mat3x4f"||s==="mat3x4h"||s==="mat4x2"||s==="mat4x2f"||s==="mat4x2h"||s==="mat4x3"||s==="mat4x3f"||s==="mat4x3h"?console.error(`TODO: Determinant for ${s}`):s!=="mat4x4"&&s!=="mat4x4f"&&s!=="mat4x4h"||console.error(`TODO: Determinant for ${s}`)}}return console.error(`Determinant expects a matrix argument. Line ${e.line}`),null}Distance(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p){let o=0;for(let c=0;c<n.data.length;++c)o+=(n.data[c]-r.data[c])*(n.data[c]-r.data[c]);return new m(Math.sqrt(o),this.getTypeInfo("f32"))}let s=n,a=r;return new m(Math.abs(s.value-a.value),n.typeInfo)}_dot(e,t){let n=0;for(let r=0;r<e.length;++r)n+=t[r]*e[r];return n}Dot(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);return n instanceof p&&r instanceof p?new m(this._dot(n.data,r.data),this.getTypeInfo("f32")):(console.error(`Dot() expects vector arguments. Line ${e.line}`),null)}Dot4U8Packed(e,t){return console.error(`TODO: dot4U8Packed. Line ${e.line}`),null}Dot4I8Packed(e,t){return console.error(`TODO: dot4I8Packed. Line ${e.line}`),null}Exp(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.exp(s)),n.typeInfo);let r=n;return new m(Math.exp(r.value),n.typeInfo)}Exp2(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.pow(2,s)),n.typeInfo);let r=n;return new m(Math.pow(2,r.value),n.typeInfo)}ExtractBits(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(r.typeInfo.name!=="u32"&&r.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 offset argument. Line ${e.line}`),null;if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 count argument. Line ${e.line}`),null;let a=r.value,o=s.value;if(n instanceof p)return new p(n.data.map(l=>l>>a&(1<<o)-1),n.typeInfo);if(n.typeInfo.name!=="i32"&&n.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 argument. Line ${e.line}`),null;let c=n.value;return new m(c>>a&(1<<o)-1,this.getTypeInfo("i32"))}FaceForward(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p){let a=this._dot(r.data,s.data);return new p(a<0?Array.from(n.data):n.data.map(o=>-o),n.typeInfo)}return console.error(`FaceForward() expects vector arguments. Line ${e.line}`),null}_firstLeadingBit(e){return e===0?-1:31-Math.clz32(e)}FirstLeadingBit(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._firstLeadingBit(s)),n.typeInfo);let r=n;return new m(this._firstLeadingBit(r.value),n.typeInfo)}_firstTrailingBit(e){return e===0?-1:Math.log2(e&-e)}FirstTrailingBit(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._firstTrailingBit(s)),n.typeInfo);let r=n;return new m(this._firstTrailingBit(r.value),n.typeInfo)}Floor(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.floor(s)),n.typeInfo);let r=n;return new m(Math.floor(r.value),n.typeInfo)}Fma(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p)return n.data.length!==r.data.length||n.data.length!==s.data.length?(console.error(`Fma() expects vectors of the same length. Line ${e.line}`),null):new p(n.data.map((l,u)=>l*r.data[u]+s.data[u]),n.typeInfo);let a=n,o=r,c=s;return new m(a.value*o.value+c.value,a.typeInfo)}Fract(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>s-Math.floor(s)),n.typeInfo);let r=n;return new m(r.value-Math.floor(r.value),n.typeInfo)}Frexp(e,t){return console.error(`TODO: frexp. Line ${e.line}`),null}InsertBits(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t),a=this.exec.evalExpression(e.args[3],t);if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`InsertBits() expects an i32 offset argument. Line ${e.line}`),null;let o=s.value,c=(1<<a.value)-1<<o,l=~c;if(n instanceof p&&r instanceof p)return new p(n.data.map((_,b)=>_&l|r.data[b]<<o&c),n.typeInfo);let u=n.value,f=r.value;return new m(u&l|f<<o&c,n.typeInfo)}InverseSqrt(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>1/Math.sqrt(s)),n.typeInfo);let r=n;return new m(1/Math.sqrt(r.value),n.typeInfo)}Ldexp(e,t){return console.error(`TODO: ldexp. Line ${e.line}`),null}Length(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p){let s=0;return n.data.forEach(a=>{s+=a*a}),new m(Math.sqrt(s),this.getTypeInfo("f32"))}let r=n;return new m(Math.abs(r.value),n.typeInfo)}Log(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.log(s)),n.typeInfo);let r=n;return new m(Math.log(r.value),n.typeInfo)}Log2(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.log2(s)),n.typeInfo);let r=n;return new m(Math.log2(r.value),n.typeInfo)}Max(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((o,c)=>Math.max(o,r.data[c])),n.typeInfo);let s=n,a=r;return new m(Math.max(s.value,a.value),n.typeInfo)}Min(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((o,c)=>Math.min(o,r.data[c])),n.typeInfo);let s=n,a=r;return new m(Math.min(s.value,a.value),n.typeInfo)}Mix(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p)return new p(n.data.map((c,l)=>n.data[l]*(1-s.data[l])+r.data[l]*s.data[l]),n.typeInfo);let a=r,o=s;return new m(n.value*(1-o.value)+a.value*o.value,n.typeInfo)}Modf(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((a,o)=>a%r.data[o]),n.typeInfo);let s=r;return new m(n.value%s.value,n.typeInfo)}Normalize(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p){let r=this.Length(e,t).value;return new p(n.data.map(s=>s/r),n.typeInfo)}return console.error(`Normalize() expects a vector argument. Line ${e.line}`),null}Pow(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((o,c)=>Math.pow(o,r.data[c])),n.typeInfo);let s=n,a=r;return new m(Math.pow(s.value,a.value),n.typeInfo)}QuantizeToF16(e,t){let n=this.exec.evalExpression(e.args[0],t);return n instanceof p?new p(n.data.map(r=>r),n.typeInfo):new m(n.value,n.typeInfo)}Radians(e,t){let n=this.exec.evalExpression(e.args[0],t);return n instanceof p?new p(n.data.map(r=>r*Math.PI/180),n.typeInfo):new m(n.value*Math.PI/180,this.getTypeInfo("f32"))}Reflect(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p){let s=this._dot(n.data,r.data);return new p(n.data.map((a,o)=>a-2*s*r.data[o]),n.typeInfo)}return console.error(`Reflect() expects vector arguments. Line ${e.line}`),null}Refract(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof m){let a=this._dot(r.data,n.data);return new p(n.data.map((o,c)=>{let l=1-s.value*s.value*(1-a*a);if(l<0)return 0;let u=Math.sqrt(l);return s.value*o-(s.value*a+u)*r.data[c]}),n.typeInfo)}return console.error(`Refract() expects vector arguments and a scalar argument. Line ${e.line}`),null}ReverseBits(e,t){return console.error(`TODO: reverseBits. Line ${e.line}`),null}Round(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.round(s)),n.typeInfo);let r=n;return new m(Math.round(r.value),n.typeInfo)}Saturate(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.min(Math.max(s,0),1)),n.typeInfo);let r=n;return new m(Math.min(Math.max(r.value,0),1),n.typeInfo)}Sign(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sign(s)),n.typeInfo);let r=n;return new m(Math.sign(r.value),n.typeInfo)}Sin(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sin(s)),n.typeInfo);let r=n;return new m(Math.sin(r.value),n.typeInfo)}Sinh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sinh(s)),n.typeInfo);let r=n;return new m(Math.sinh(r.value),n.typeInfo)}_smoothstep(e,t,n){let r=Math.min(Math.max((n-e)/(t-e),0),1);return r*r*(3-2*r)}SmoothStep(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(s instanceof p&&n instanceof p&&r instanceof p)return new p(s.data.map((l,u)=>this._smoothstep(n.data[u],r.data[u],l)),s.typeInfo);let a=n,o=r,c=s;return new m(this._smoothstep(a.value,o.value,c.value),s.typeInfo)}Sqrt(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sqrt(s)),n.typeInfo);let r=n;return new m(Math.sqrt(r.value),n.typeInfo)}Step(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(r instanceof p&&n instanceof p)return new p(r.data.map((a,o)=>a<n.data[o]?0:1),r.typeInfo);let s=n;return new m(r.value<s.value?0:1,s.typeInfo)}Tan(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.tan(s)),n.typeInfo);let r=n;return new m(Math.tan(r.value),n.typeInfo)}Tanh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.tanh(s)),n.typeInfo);let r=n;return new m(Math.tanh(r.value),n.typeInfo)}_getTransposeType(e){let t=e.getTypeName();return t==="mat2x2f"||t==="mat2x2h"?e:t==="mat2x3f"?this.getTypeInfo("mat3x2f"):t==="mat2x3h"?this.getTypeInfo("mat3x2h"):t==="mat2x4f"?this.getTypeInfo("mat4x2f"):t==="mat2x4h"?this.getTypeInfo("mat4x2h"):t==="mat3x2f"?this.getTypeInfo("mat2x3f"):t==="mat3x2h"?this.getTypeInfo("mat2x3h"):t==="mat3x3f"||t==="mat3x3h"?e:t==="mat3x4f"?this.getTypeInfo("mat4x3f"):t==="mat3x4h"?this.getTypeInfo("mat4x3h"):t==="mat4x2f"?this.getTypeInfo("mat2x4f"):t==="mat4x2h"?this.getTypeInfo("mat2x4h"):t==="mat4x3f"?this.getTypeInfo("mat3x4f"):t==="mat4x3h"?this.getTypeInfo("mat3x4h"):(t==="mat4x4f"||t==="mat4x4h"||console.error(`Invalid matrix type ${t}`),e)}Transpose(e,t){let n=this.exec.evalExpression(e.args[0],t);if(!(n instanceof N))return console.error(`Transpose() expects a matrix argument. Line ${e.line}`),null;let r=this._getTransposeType(n.typeInfo);if(n.typeInfo.name==="mat2x2"||n.typeInfo.name==="mat2x2f"||n.typeInfo.name==="mat2x2h"){let s=n.data;return new N([s[0],s[2],s[1],s[3]],r)}if(n.typeInfo.name==="mat2x3"||n.typeInfo.name==="mat2x3f"||n.typeInfo.name==="mat2x3h"){let s=n.data;return new N([s[0],s[3],s[6],s[1],s[4],s[7]],r)}if(n.typeInfo.name==="mat2x4"||n.typeInfo.name==="mat2x4f"||n.typeInfo.name==="mat2x4h"){let s=n.data;return new N([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13]],r)}if(n.typeInfo.name==="mat3x2"||n.typeInfo.name==="mat3x2f"||n.typeInfo.name==="mat3x2h"){let s=n.data;return new N([s[0],s[3],s[1],s[4],s[2],s[5]],r)}if(n.typeInfo.name==="mat3x3"||n.typeInfo.name==="mat3x3f"||n.typeInfo.name==="mat3x3h"){let s=n.data;return new N([s[0],s[3],s[6],s[1],s[4],s[7],s[2],s[5],s[8]],r)}if(n.typeInfo.name==="mat3x4"||n.typeInfo.name==="mat3x4f"||n.typeInfo.name==="mat3x4h"){let s=n.data;return new N([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14]],r)}if(n.typeInfo.name==="mat4x2"||n.typeInfo.name==="mat4x2f"||n.typeInfo.name==="mat4x2h"){let s=n.data;return new N([s[0],s[4],s[1],s[5],s[2],s[6]],r)}if(n.typeInfo.name==="mat4x3"||n.typeInfo.name==="mat4x3f"||n.typeInfo.name==="mat4x3h"){let s=n.data;return new N([s[0],s[4],s[8],s[1],s[5],s[9],s[2],s[6],s[10]],r)}if(n.typeInfo.name==="mat4x4"||n.typeInfo.name==="mat4x4f"||n.typeInfo.name==="mat4x4h"){let s=n.data;return new N([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14],s[3],s[7],s[11],s[15]],r)}return console.error(`Invalid matrix type ${n.typeInfo.name}`),null}Trunc(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.trunc(s)),n.typeInfo);let r=n;return new m(Math.trunc(r.value),n.typeInfo)}Dpdx(e,t){return console.error(`TODO: dpdx. Line ${e.line}`),null}DpdxCoarse(e,t){return console.error(`TODO: dpdxCoarse. Line ${e.line}`),null}DpdxFine(e,t){return console.error("TODO: dpdxFine"),null}Dpdy(e,t){return console.error("TODO: dpdy"),null}DpdyCoarse(e,t){return console.error("TODO: dpdyCoarse"),null}DpdyFine(e,t){return console.error("TODO: dpdyFine"),null}Fwidth(e,t){return console.error("TODO: fwidth"),null}FwidthCoarse(e,t){return console.error("TODO: fwidthCoarse"),null}FwidthFine(e,t){return console.error("TODO: fwidthFine"),null}TextureDimensions(e,t){let n=e.args[0],r=e.args.length>1?this.exec.evalExpression(e.args[1],t).value:0;if(n instanceof Y){let s=n.name,a=t.getVariableValue(s);if(a instanceof oe){if(r<0||r>=a.mipLevelCount)return console.error(`Invalid mip level for textureDimensions. Line ${e.line}`),null;let o=a.getMipLevelSize(r),c=a.dimension;return c==="1d"?new m(o[0],this.getTypeInfo("u32")):c==="3d"?new p(o,this.getTypeInfo("vec3u")):c==="2d"?new p(o.slice(0,2),this.getTypeInfo("vec2u")):(console.error(`Invalid texture dimension ${c} not found. Line ${e.line}`),null)}return console.error(`Texture ${s} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureDimensions. Line ${e.line}`),null}TextureGather(e,t){return console.error("TODO: textureGather"),null}TextureGatherCompare(e,t){return console.error("TODO: textureGatherCompare"),null}TextureLoad(e,t){let n=e.args[0],r=this.exec.evalExpression(e.args[1],t),s=e.args.length>2?this.exec.evalExpression(e.args[2],t).value:0;if(!(r instanceof p)||r.data.length!==2)return console.error(`Invalid UV argument for textureLoad. Line ${e.line}`),null;if(n instanceof Y){let a=n.name,o=t.getVariableValue(a);if(o instanceof oe){let c=Math.floor(r.data[0]),l=Math.floor(r.data[1]);if(c<0||c>=o.width||l<0||l>=o.height)return console.error(`Texture ${a} out of bounds. Line ${e.line}`),null;let u=o.getPixel(c,l,0,s);return u===null?(console.error(`Invalid texture format for textureLoad. Line ${e.line}`),null):new p(u,this.getTypeInfo("vec4f"))}return console.error(`Texture ${a} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureLoad. Line ${e.line}`),null}TextureNumLayers(e,t){let n=e.args[0];if(n instanceof Y){let r=n.name,s=t.getVariableValue(r);return s instanceof oe?new m(s.depthOrArrayLayers,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLayers. Line ${e.line}`),null}TextureNumLevels(e,t){let n=e.args[0];if(n instanceof Y){let r=n.name,s=t.getVariableValue(r);return s instanceof oe?new m(s.mipLevelCount,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLevels. Line ${e.line}`),null}TextureNumSamples(e,t){let n=e.args[0];if(n instanceof Y){let r=n.name,s=t.getVariableValue(r);return s instanceof oe?new m(s.sampleCount,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumSamples. Line ${e.line}`),null}TextureSample(e,t){return console.error("TODO: textureSample"),null}TextureSampleBias(e,t){return console.error("TODO: textureSampleBias"),null}TextureSampleCompare(e,t){return console.error("TODO: textureSampleCompare"),null}TextureSampleCompareLevel(e,t){return console.error("TODO: textureSampleCompareLevel"),null}TextureSampleGrad(e,t){return console.error("TODO: textureSampleGrad"),null}TextureSampleLevel(e,t){return console.error("TODO: textureSampleLevel"),null}TextureSampleBaseClampToEdge(e,t){return console.error("TODO: textureSampleBaseClampToEdge"),null}TextureStore(e,t){let n=e.args[0],r=this.exec.evalExpression(e.args[1],t),s=e.args.length===4?this.exec.evalExpression(e.args[2],t).value:0,a=e.args.length===4?this.exec.evalExpression(e.args[3],t).data:this.exec.evalExpression(e.args[2],t).data;if(a.length!==4)return console.error(`Invalid value argument for textureStore. Line ${e.line}`),null;if(!(r instanceof p)||r.data.length!==2)return console.error(`Invalid UV argument for textureStore. Line ${e.line}`),null;if(n instanceof Y){let o=n.name,c=t.getVariableValue(o);if(c instanceof oe){let l=c.getMipLevelSize(0),u=Math.floor(r.data[0]),f=Math.floor(r.data[1]);return u<0||u>=l[0]||f<0||f>=l[1]?(console.error(`Texture ${o} out of bounds. Line ${e.line}`),null):(c.setPixel(u,f,0,s,Array.from(a)),null)}return console.error(`Texture ${o} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureStore. Line ${e.line}`),null}AtomicLoad(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t);return t.getVariable(r).value.getSubData(this.exec,n.postfix,t)}AtomicStore(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t);return c instanceof m&&o instanceof m&&(c.value=o.value),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),null}AtomicAdd(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t),l=new m(c.value,c.typeInfo);return c instanceof m&&o instanceof m&&(c.value+=o.value),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),l}AtomicSub(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t),l=new m(c.value,c.typeInfo);return c instanceof m&&o instanceof m&&(c.value-=o.value),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),l}AtomicMax(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t),l=new m(c.value,c.typeInfo);return c instanceof m&&o instanceof m&&(c.value=Math.max(c.value,o.value)),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),l}AtomicMin(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t),l=new m(c.value,c.typeInfo);return c instanceof m&&o instanceof m&&(c.value=Math.min(c.value,o.value)),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),l}AtomicAnd(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t),l=new m(c.value,c.typeInfo);return c instanceof m&&o instanceof m&&(c.value=c.value&o.value),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),l}AtomicOr(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t),l=new m(c.value,c.typeInfo);return c instanceof m&&o instanceof m&&(c.value=c.value|o.value),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),l}AtomicXor(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t),l=new m(c.value,c.typeInfo);return c instanceof m&&o instanceof m&&(c.value=c.value^o.value),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),l}AtomicExchange(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t),l=new m(c.value,c.typeInfo);return c instanceof m&&o instanceof m&&(c.value=o.value),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),l}AtomicCompareExchangeWeak(e,t){return console.error("TODO: atomicCompareExchangeWeak"),null}Pack4x8snorm(e,t){return console.error("TODO: pack4x8snorm"),null}Pack4x8unorm(e,t){return console.error("TODO: pack4x8unorm"),null}Pack4xI8(e,t){return console.error("TODO: pack4xI8"),null}Pack4xU8(e,t){return console.error("TODO: pack4xU8"),null}Pack4x8Clamp(e,t){return console.error("TODO: pack4x8Clamp"),null}Pack4xU8Clamp(e,t){return console.error("TODO: pack4xU8Clamp"),null}Pack2x16snorm(e,t){return console.error("TODO: pack2x16snorm"),null}Pack2x16unorm(e,t){return console.error("TODO: pack2x16unorm"),null}Pack2x16float(e,t){return console.error("TODO: pack2x16float"),null}Unpack4x8snorm(e,t){return console.error("TODO: unpack4x8snorm"),null}Unpack4x8unorm(e,t){return console.error("TODO: unpack4x8unorm"),null}Unpack4xI8(e,t){return console.error("TODO: unpack4xI8"),null}Unpack4xU8(e,t){return console.error("TODO: unpack4xU8"),null}Unpack2x16snorm(e,t){return console.error("TODO: unpack2x16snorm"),null}Unpack2x16unorm(e,t){return console.error("TODO: unpack2x16unorm"),null}Unpack2x16float(e,t){return console.error("TODO: unpack2x16float"),null}StorageBarrier(e,t){return null}TextureBarrier(e,t){return null}WorkgroupBarrier(e,t){return null}WorkgroupUniformLoad(e,t){return null}SubgroupAdd(e,t){return console.error("TODO: subgroupAdd"),null}SubgroupExclusiveAdd(e,t){return console.error("TODO: subgroupExclusiveAdd"),null}SubgroupInclusiveAdd(e,t){return console.error("TODO: subgroupInclusiveAdd"),null}SubgroupAll(e,t){return console.error("TODO: subgroupAll"),null}SubgroupAnd(e,t){return console.error("TODO: subgroupAnd"),null}SubgroupAny(e,t){return console.error("TODO: subgroupAny"),null}SubgroupBallot(e,t){return console.error("TODO: subgroupBallot"),null}SubgroupBroadcast(e,t){return console.error("TODO: subgroupBroadcast"),null}SubgroupBroadcastFirst(e,t){return console.error("TODO: subgroupBroadcastFirst"),null}SubgroupElect(e,t){return console.error("TODO: subgroupElect"),null}SubgroupMax(e,t){return console.error("TODO: subgroupMax"),null}SubgroupMin(e,t){return console.error("TODO: subgroupMin"),null}SubgroupMul(e,t){return console.error("TODO: subgroupMul"),null}SubgroupExclusiveMul(e,t){return console.error("TODO: subgroupExclusiveMul"),null}SubgroupInclusiveMul(e,t){return console.error("TODO: subgroupInclusiveMul"),null}SubgroupOr(e,t){return console.error("TODO: subgroupOr"),null}SubgroupShuffle(e,t){return console.error("TODO: subgroupShuffle"),null}SubgroupShuffleDown(e,t){return console.error("TODO: subgroupShuffleDown"),null}SubgroupShuffleUp(e,t){return console.error("TODO: subgroupShuffleUp"),null}SubgroupShuffleXor(e,t){return console.error("TODO: subgroupShuffleXor"),null}SubgroupXor(e,t){return console.error("TODO: subgroupXor"),null}QuadBroadcast(e,t){return console.error("TODO: quadBroadcast"),null}QuadSwapDiagonal(e,t){return console.error("TODO: quadSwapDiagonal"),null}QuadSwapX(e,t){return console.error("TODO: quadSwapX"),null}QuadSwapY(e,t){return console.error("TODO: quadSwapY"),null}},cn={vec2:2,vec2f:2,vec2i:2,vec2u:2,vec2b:2,vec2h:2,vec3:3,vec3f:3,vec3i:3,vec3u:3,vec3b:3,vec3h:3,vec4:4,vec4f:4,vec4i:4,vec4u:4,vec4b:4,vec4h:4},X={mat2x2:[2,2,4],mat2x2f:[2,2,4],mat2x2h:[2,2,4],mat2x3:[2,3,6],mat2x3f:[2,3,6],mat2x3h:[2,3,6],mat2x4:[2,4,8],mat2x4f:[2,4,8],mat2x4h:[2,4,8],mat3x2:[3,2,6],mat3x2f:[3,2,6],mat3x2h:[3,2,6],mat3x3:[3,3,9],mat3x3f:[3,3,9],mat3x3h:[3,3,9],mat3x4:[3,4,12],mat3x4f:[3,4,12],mat3x4h:[3,4,12],mat4x2:[4,2,8],mat4x2f:[4,2,8],mat4x2h:[4,2,8],mat4x3:[4,3,12],mat4x3f:[4,3,12],mat4x3h:[4,3,12],mat4x4:[4,4,16],mat4x4f:[4,4,16],mat4x4h:[4,4,16]},G=class extends wn{constructor(e,t){var n;super(),this.ast=e??[],this.reflection=new re,this.reflection.updateAST(this.ast),this.context=(n=t?.clone())!==null&&n!==void 0?n:new nt,this.builtins=new kn(this),this.typeInfo={bool:this.getTypeInfo(y.bool),i32:this.getTypeInfo(y.i32),u32:this.getTypeInfo(y.u32),f32:this.getTypeInfo(y.f32),f16:this.getTypeInfo(y.f16),vec2f:this.getTypeInfo(x.vec2f),vec2u:this.getTypeInfo(x.vec2u),vec2i:this.getTypeInfo(x.vec2i),vec2h:this.getTypeInfo(x.vec2h),vec3f:this.getTypeInfo(x.vec3f),vec3u:this.getTypeInfo(x.vec3u),vec3i:this.getTypeInfo(x.vec3i),vec3h:this.getTypeInfo(x.vec3h),vec4f:this.getTypeInfo(x.vec4f),vec4u:this.getTypeInfo(x.vec4u),vec4i:this.getTypeInfo(x.vec4i),vec4h:this.getTypeInfo(x.vec4h),mat2x2f:this.getTypeInfo(x.mat2x2f),mat2x3f:this.getTypeInfo(x.mat2x3f),mat2x4f:this.getTypeInfo(x.mat2x4f),mat3x2f:this.getTypeInfo(x.mat3x2f),mat3x3f:this.getTypeInfo(x.mat3x3f),mat3x4f:this.getTypeInfo(x.mat3x4f),mat4x2f:this.getTypeInfo(x.mat4x2f),mat4x3f:this.getTypeInfo(x.mat4x3f),mat4x4f:this.getTypeInfo(x.mat4x4f)}}getVariableValue(e){var t,n;let r=(n=(t=this.context.getVariable(e))===null||t===void 0?void 0:t.value)!==null&&n!==void 0?n:null;if(r===null)return null;if(r instanceof m)return r.value;if(r instanceof p||r instanceof N)return Array.from(r.data);if(r instanceof U&&r.typeInfo instanceof fe){if(r.typeInfo.format.name==="u32")return Array.from(new Uint32Array(r.buffer,r.offset,r.typeInfo.count));if(r.typeInfo.format.name==="i32")return Array.from(new Int32Array(r.buffer,r.offset,r.typeInfo.count));if(r.typeInfo.format.name==="f32")return Array.from(new Float32Array(r.buffer,r.offset,r.typeInfo.count))}return console.error(`Unsupported return variable type ${r.typeInfo.name}`),null}execute(e){(e=e??{}).constants&&this._setOverrides(e.constants,this.context),this._execStatements(this.ast,this.context)}dispatchWorkgroups(e,t,n,r){let s=this.context.clone();(r=r??{}).constants&&this._setOverrides(r.constants,s),this._execStatements(this.ast,s);let a=s.getFunction(e);if(!a)return void console.error(`Function ${e} not found`);if(typeof t=="number")t=[t,1,1];else{if(t.length===0)return void console.error("Invalid dispatch count");t.length===1?t=[t[0],1,1]:t.length===2?t=[t[0],t[1],1]:t.length>3&&(t=[t[0],t[1],t[2]])}let o=t[0],c=t[1],l=t[2],u=this.getTypeInfo("vec3u");s.setVariable("@num_workgroups",new p(t,u));for(let f in n)for(let _ in n[f]){let b=n[f][_];s.variables.forEach(w=>{var L;let S=w.node;if(S?.attributes){let E=null,T=null;for(let k of S.attributes)k.name==="binding"?E=k.value:k.name==="group"&&(T=k.value);if(_==E&&f==T)if(b.texture!==void 0&&b.descriptor!==void 0){let k=new oe(b.texture,this.getTypeInfo(S.type),b.descriptor,(L=b.texture.view)!==null&&L!==void 0?L:null);w.value=k}else b.uniform!==void 0?w.value=new U(b.uniform,this.getTypeInfo(S.type)):w.value=new U(b,this.getTypeInfo(S.type))}})}for(let f=0;f<l;++f)for(let _=0;_<c;++_)for(let b=0;b<o;++b)s.setVariable("@workgroup_id",new p([b,_,f],this.getTypeInfo("vec3u"))),this._dispatchWorkgroup(a,[b,_,f],s)}execStatement(e,t){if(e instanceof It)return this.evalExpression(e.value,t);if(e instanceof At){if(e.condition){let n=this.evalExpression(e.condition,t);if(!(n instanceof m))throw new Error("Invalid break-if condition");if(!n.value)return null}return G._breakObj}if(e instanceof Lt)return G._continueObj;if(e instanceof ye)this._let(e,t);else if(e instanceof ae)this._var(e,t);else if(e instanceof Ce)this._const(e,t);else if(e instanceof ke)this._function(e,t);else{if(e instanceof kt)return this._if(e,t);if(e instanceof wt)return this._switch(e,t);if(e instanceof xt)return this._for(e,t);if(e instanceof _t)return this._while(e,t);if(e instanceof yt)return this._loop(e,t);if(e instanceof Xe){let n=t.clone();return n.currentFunctionName=t.currentFunctionName,this._execStatements(e.body,n)}if(e instanceof bt)this._assign(e,t);else if(e instanceof vt)this._increment(e,t);else{if(e instanceof ie)return null;if(e instanceof Ye){let n=e.name;t.getVariable(n)===null&&t.setVariable(n,new m(0,this.getTypeInfo("u32")))}else if(e instanceof Ke)this._call(e,t);else{if(e instanceof St||e instanceof Ze)return null;console.error("Invalid statement type.",e,`Line ${e.line}`)}}}return null}evalExpression(e,t){return e instanceof ee?this._evalBinaryOp(e,t):e instanceof H?this._evalLiteral(e,t):e instanceof Y?this._evalVariable(e,t):e instanceof Qe?this._evalCall(e,t):e instanceof ne?this._evalCreate(e,t):e instanceof Et?this._evalConst(e,t):e instanceof Mt?this._evalBitcast(e,t):e instanceof z?this._evalUnaryOp(e,t):(console.error("Invalid expression type",e,`Line ${e.line}`),null)}getTypeInfo(e){var t;if(e instanceof y){let r=this.reflection.getTypeInfo(e);if(r!==null)return r}let n=(t=this.typeInfo[e])!==null&&t!==void 0?t:null;return n!==null||(n=this.reflection.getTypeInfoByName(e)),n}_setOverrides(e,t){for(let n in e){let r=e[n],s=this.reflection.getOverrideInfo(n);s!==null?(s.type===null&&(s.type=this.getTypeInfo("u32")),s.type.name==="u32"||s.type.name==="i32"||s.type.name==="f32"||s.type.name==="f16"?t.setVariable(n,new m(r,s.type)):s.type.name==="bool"?t.setVariable(n,new m(r?1:0,s.type)):s.type.name==="vec2"||s.type.name==="vec3"||s.type.name==="vec4"||s.type.name==="vec2f"||s.type.name==="vec3f"||s.type.name==="vec4f"||s.type.name==="vec2i"||s.type.name==="vec3i"||s.type.name==="vec4i"||s.type.name==="vec2u"||s.type.name==="vec3u"||s.type.name==="vec4u"||s.type.name==="vec2h"||s.type.name==="vec3h"||s.type.name==="vec4h"?t.setVariable(n,new p(r,s.type)):console.error(`Invalid constant type for ${n}`)):console.error(`Override ${n} does not exist in the shader.`)}}_dispatchWorkgroup(e,t,n){let r=[1,1,1];for(let u of e.node.attributes)if(u.name==="workgroup_size"){if(u.value.length>0){let f=n.getVariableValue(u.value[0]);r[0]=f instanceof m?f.value:parseInt(u.value[0])}if(u.value.length>1){let f=n.getVariableValue(u.value[1]);r[1]=f instanceof m?f.value:parseInt(u.value[1])}if(u.value.length>2){let f=n.getVariableValue(u.value[2]);r[2]=f instanceof m?f.value:parseInt(u.value[2])}}let s=this.getTypeInfo("vec3u"),a=this.getTypeInfo("u32");n.setVariable("@workgroup_size",new p(r,s));let o=r[0],c=r[1],l=r[2];for(let u=0,f=0;u<l;++u)for(let _=0;_<c;++_)for(let b=0;b<o;++b,++f){let w=[b,_,u],L=[b+t[0]*r[0],_+t[1]*r[1],u+t[2]*r[2]];n.setVariable("@local_invocation_id",new p(w,s)),n.setVariable("@global_invocation_id",new p(L,s)),n.setVariable("@local_invocation_index",new m(f,a)),this._dispatchExec(e,n)}}_dispatchExec(e,t){for(let n of e.node.args)for(let r of n.attributes)if(r.name==="builtin"){let s=`@${r.value}`,a=t.getVariable(s);a!==void 0&&t.variables.set(n.name,a)}this._execStatements(e.node.body,t)}getVariableName(e,t){for(;e instanceof z;)e=e.right;return e instanceof Y?e.name:(console.error("Unknown variable type",e,"Line",e.line),null)}_execStatements(e,t){for(let n of e){if(n instanceof Array){let s=t.clone(),a=this._execStatements(n,s);if(a)return a;continue}let r=this.execStatement(n,t);if(r)return r}return null}_call(e,t){let n=t.clone();n.currentFunctionName=e.name;let r=t.getFunction(e.name);if(r){for(let s=0;s<r.node.args.length;++s){let a=r.node.args[s],o=this.evalExpression(e.args[s],n);n.setVariable(a.name,o,a)}this._execStatements(r.node.body,n)}else e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)&&this._evalCreate(e,t)}_increment(e,t){let n=this.getVariableName(e.variable,t),r=t.getVariable(n);r?e.operator==="++"?r.value instanceof m?r.value.value++:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):e.operator==="--"?r.value instanceof m?r.value.value--:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):console.error(`Unknown increment operator ${e.operator}. Line ${e.line}`):console.error(`Variable ${n} not found. Line ${e.line}`)}_getVariableData(e,t){if(e instanceof Y){let n=this.getVariableName(e,t),r=t.getVariable(n);return r===null?(console.error(`Variable ${n} not found. Line ${e.line}`),null):r.value.getSubData(this,e.postfix,t)}if(e instanceof z){if(e.operator==="*"){let n=this._getVariableData(e.right,t);return n instanceof _e?n.reference.getSubData(this,e.postfix,t):(console.error(`Variable ${e.right} is not a pointer. Line ${e.line}`),null)}if(e.operator==="&"){let n=this._getVariableData(e.right,t);return new _e(n)}}return null}_assign(e,t){let n=null,r="<var>",s=null;if(e.variable instanceof z){let c=this._getVariableData(e.variable,t),l=this.evalExpression(e.value,t),u=e.operator;if(u==="="){if(c instanceof m||c instanceof p||c instanceof N){if(l instanceof m||l instanceof p||l instanceof N&&c.data.length===l.data.length)return void c.data.set(l.data);console.error(`Invalid assignment. Line ${e.line}`)}else if(c instanceof U&&l instanceof U&&c.buffer.byteLength-c.offset>=l.buffer.byteLength-l.offset)return void(c.buffer.byteLength%4==0?new Uint32Array(c.buffer,c.offset,c.typeInfo.size/4).set(new Uint32Array(l.buffer,l.offset,l.typeInfo.size/4)):new Uint8Array(c.buffer,c.offset,c.typeInfo.size).set(new Uint8Array(l.buffer,l.offset,l.typeInfo.size)));return console.error(`Invalid assignment. Line ${e.line}`),null}if(u==="+=")return c instanceof m||c instanceof p||c instanceof N?l instanceof m||l instanceof p||l instanceof N?void c.data.set(l.data.map((f,_)=>c.data[_]+f)):void console.error(`Invalid assignment . Line ${e.line}`):void console.error(`Invalid assignment. Line ${e.line}`);if(u==="-=")return(c instanceof m||c instanceof p||c instanceof N)&&(l instanceof m||l instanceof p||l instanceof N)?void c.data.set(l.data.map((f,_)=>c.data[_]-f)):void console.error(`Invalid assignment. Line ${e.line}`)}if(e.variable instanceof z){if(e.variable.operator==="*"){r=this.getVariableName(e.variable.right,t);let c=t.getVariable(r);if(!(c&&c.value instanceof _e))return void console.error(`Variable ${r} is not a pointer. Line ${e.line}`);n=c.value.reference;let l=e.variable.postfix;if(!l){let u=e.variable.right;for(;u instanceof z;){if(u.postfix){l=u.postfix;break}u=u.right}}l&&(n=n.getSubData(this,l,t))}}else{s=e.variable.postfix,r=this.getVariableName(e.variable,t);let c=t.getVariable(r);if(c===null)return void console.error(`Variable ${r} not found. Line ${e.line}`);n=c.value}if(n instanceof _e&&(n=n.reference),n===null)return void console.error(`Variable ${r} not found. Line ${e.line}`);let a=this.evalExpression(e.value,t),o=e.operator;if(o==="=")if(n instanceof U)n.setDataValue(this,a,s,t);else if(s){if(!(n instanceof p||n instanceof N))return void console.error(`Variable ${r} is not a vector or matrix. Line ${e.line}`);if(s instanceof xe){let c=this.evalExpression(s.index,t).value;if(n instanceof p){if(!(a instanceof m))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[c]=a.value}else{if(!(n instanceof N))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{let l=this.evalExpression(s.index,t).value;if(l<0)return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(a instanceof p))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{let u=n.typeInfo.getTypeName();if(u==="mat2x2"||u==="mat2x2f"||u==="mat2x2h"){if(!(l<2&&a.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*l]=a.data[0],n.data[2*l+1]=a.data[1]}else if(u==="mat2x3"||u==="mat2x3f"||u==="mat2x3h"){if(!(l<2&&a.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*l]=a.data[0],n.data[3*l+1]=a.data[1],n.data[3*l+2]=a.data[2]}else if(u==="mat2x4"||u==="mat2x4f"||u==="mat2x4h"){if(!(l<2&&a.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*l]=a.data[0],n.data[4*l+1]=a.data[1],n.data[4*l+2]=a.data[2],n.data[4*l+3]=a.data[3]}else if(u==="mat3x2"||u==="mat3x2f"||u==="mat3x2h"){if(!(l<3&&a.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*l]=a.data[0],n.data[2*l+1]=a.data[1]}else if(u==="mat3x3"||u==="mat3x3f"||u==="mat3x3h"){if(!(l<3&&a.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*l]=a.data[0],n.data[3*l+1]=a.data[1],n.data[3*l+2]=a.data[2]}else if(u==="mat3x4"||u==="mat3x4f"||u==="mat3x4h"){if(!(l<3&&a.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*l]=a.data[0],n.data[4*l+1]=a.data[1],n.data[4*l+2]=a.data[2],n.data[4*l+3]=a.data[3]}else if(u==="mat4x2"||u==="mat4x2f"||u==="mat4x2h"){if(!(l<4&&a.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*l]=a.data[0],n.data[2*l+1]=a.data[1]}else if(u==="mat4x3"||u==="mat4x3f"||u==="mat4x3h"){if(!(l<4&&a.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*l]=a.data[0],n.data[3*l+1]=a.data[1],n.data[3*l+2]=a.data[2]}else{if(u!=="mat4x4"&&u!=="mat4x4f"&&u!=="mat4x4h")return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(l<4&&a.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*l]=a.data[0],n.data[4*l+1]=a.data[1],n.data[4*l+2]=a.data[2],n.data[4*l+3]=a.data[3]}}}}}else if(s instanceof pe){let c=s.value;if(!(n instanceof p))return void console.error(`Invalid assignment to ${c}. Variable ${r} is not a vector. Line ${e.line}`);if(a instanceof m){if(c.length>1)return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);if(c==="x")n.data[0]=a.value;else if(c==="y"){if(n.data.length<2)return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);n.data[1]=a.value}else if(c==="z"){if(n.data.length<3)return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);n.data[2]=a.value}else if(c==="w"){if(n.data.length<4)return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);n.data[3]=a.value}}else{if(!(a instanceof p))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(c.length!==a.data.length)return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);for(let l=0;l<c.length;++l){let u=c[l];if(u==="x"||u==="r")n.data[0]=a.data[l];else if(u==="y"||u==="g"){if(a.data.length<2)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);n.data[1]=a.data[l]}else if(u==="z"||u==="b"){if(a.data.length<3)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);n.data[2]=a.data[l]}else{if(u!=="w"&&u!=="a")return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);if(a.data.length<4)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);n.data[3]=a.data[l]}}}}}else n instanceof m&&a instanceof m?n.value=a.value:n instanceof p&&a instanceof p||n instanceof N&&a instanceof N?n.data.set(a.data):console.error(`Invalid assignment to ${r}. Line ${e.line}`);else{let c=n.getSubData(this,s,t);if(c instanceof p&&a instanceof m){let l=c.data,u=a.value;if(o==="+=")for(let f=0;f<l.length;++f)l[f]+=u;else if(o==="-=")for(let f=0;f<l.length;++f)l[f]-=u;else if(o==="*=")for(let f=0;f<l.length;++f)l[f]*=u;else if(o==="/=")for(let f=0;f<l.length;++f)l[f]/=u;else if(o==="%=")for(let f=0;f<l.length;++f)l[f]%=u;else if(o==="&=")for(let f=0;f<l.length;++f)l[f]&=u;else if(o==="|=")for(let f=0;f<l.length;++f)l[f]|=u;else if(o==="^=")for(let f=0;f<l.length;++f)l[f]^=u;else if(o==="<<=")for(let f=0;f<l.length;++f)l[f]<<=u;else if(o===">>=")for(let f=0;f<l.length;++f)l[f]>>=u;else console.error(`Invalid operator ${o}. Line ${e.line}`)}else if(c instanceof p&&a instanceof p){let l=c.data,u=a.data;if(l.length!==u.length)return void console.error(`Vector length mismatch. Line ${e.line}`);if(o==="+=")for(let f=0;f<l.length;++f)l[f]+=u[f];else if(o==="-=")for(let f=0;f<l.length;++f)l[f]-=u[f];else if(o==="*=")for(let f=0;f<l.length;++f)l[f]*=u[f];else if(o==="/=")for(let f=0;f<l.length;++f)l[f]/=u[f];else if(o==="%=")for(let f=0;f<l.length;++f)l[f]%=u[f];else if(o==="&=")for(let f=0;f<l.length;++f)l[f]&=u[f];else if(o==="|=")for(let f=0;f<l.length;++f)l[f]|=u[f];else if(o==="^=")for(let f=0;f<l.length;++f)l[f]^=u[f];else if(o==="<<=")for(let f=0;f<l.length;++f)l[f]<<=u[f];else if(o===">>=")for(let f=0;f<l.length;++f)l[f]>>=u[f];else console.error(`Invalid operator ${o}. Line ${e.line}`)}else{if(!(c instanceof m&&a instanceof m))return void console.error(`Invalid type for ${e.operator} operator. Line ${e.line}`);o==="+="?c.value+=a.value:o==="-="?c.value-=a.value:o==="*="?c.value*=a.value:o==="/="?c.value/=a.value:o==="%="?c.value%=a.value:o==="&="?c.value&=a.value:o==="|="?c.value|=a.value:o==="^="?c.value^=a.value:o==="<<="?c.value<<=a.value:o===">>="?c.value>>=a.value:console.error(`Invalid operator ${o}. Line ${e.line}`)}n instanceof U&&n.setDataValue(this,c,s,t)}}_function(e,t){let n=new tt(e);t.functions.set(e.name,n)}_const(e,t){let n=null;e.value!==null&&(n=this.evalExpression(e.value,t)),t.createVariable(e.name,n,e)}_let(e,t){let n=null;if(e.value!==null){if(n=this.evalExpression(e.value,t),n===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof z||(n=n.clone())}else{let r=e.type.name;if(r==="f32"||r==="i32"||r==="u32"||r==="bool"||r==="f16"||r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2b"||r==="vec3b"||r==="vec4b"||r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"||r==="array"){let s=new ne(e.type,[]);n=this._evalCreate(s,t)}}t.createVariable(e.name,n,e)}_var(e,t){let n=null;if(e.value!==null){if(n=this.evalExpression(e.value,t),n===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof z||(n=n.clone())}else{if(e.type===null)return void console.error(`Variable ${e.name} has no type. Line ${e.line}`);let r=e.type.name;if(r==="f32"||r==="i32"||r==="u32"||r==="bool"||r==="f16"||r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2b"||r==="vec3b"||r==="vec4b"||r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"||e.type instanceof we||e.type instanceof ie||e.type instanceof x){let s=new ne(e.type,[]);n=this._evalCreate(s,t)}}t.createVariable(e.name,n,e)}_switch(e,t){t=t.clone();let n=this.evalExpression(e.condition,t);if(!(n instanceof m))return console.error(`Invalid if condition. Line ${e.line}`),null;let r=null;for(let s of e.cases)if(s instanceof Ot)for(let a of s.selectors){if(a instanceof Ne){r=s;continue}let o=this.evalExpression(a,t);if(!(o instanceof m))return console.error(`Invalid case selector. Line ${e.line}`),null;if(o.value===n.value)return this._execStatements(s.body,t)}else s instanceof Pt&&(r=s);return r?this._execStatements(r.body,t):null}_if(e,t){t=t.clone();let n=this.evalExpression(e.condition,t);if(!(n instanceof m))return console.error(`Invalid if condition. Line ${e.line}`),null;if(n.value)return this._execStatements(e.body,t);for(let r of e.elseif){let s=this.evalExpression(r.condition,t);if(!(s instanceof m))return console.error(`Invalid if condition. Line ${e.line}`),null;if(s.value)return this._execStatements(r.body,t)}return e.else?this._execStatements(e.else,t):null}_getScalarValue(e){return e instanceof m?e.value:(console.error("Expected scalar value.",e),0)}_for(e,t){for(t=t.clone(),this.execStatement(e.init,t);this._getScalarValue(this.evalExpression(e.condition,t));){let n=this._execStatements(e.body,t);if(n===G._breakObj)break;if(n!==null&&n!==G._continueObj)return n;this.execStatement(e.increment,t)}return null}_loop(e,t){for(t=t.clone();;){let n=this._execStatements(e.body,t);if(n===G._breakObj)break;if(n===G._continueObj){if(e.continuing&&this._execStatements(e.continuing.body,t)===G._breakObj)break}else if(n!==null)return n}return null}_while(e,t){for(t=t.clone();this._getScalarValue(this.evalExpression(e.condition,t));){let n=this._execStatements(e.body,t);if(n===G._breakObj)break;if(n!==G._continueObj&&n!==null)return n}return null}_evalBitcast(e,t){let n=this.evalExpression(e.value,t),r=e.type;if(n instanceof m){let s=vr(n.value,n.typeInfo.name,r.name);return new m(s,this.getTypeInfo(r))}if(n instanceof p){let s=n.typeInfo.getTypeName(),a="";if(s.endsWith("f"))a="f32";else if(s.endsWith("i"))a="i32";else if(s.endsWith("u"))a="u32";else if(s.endsWith("b"))a="bool";else{if(!s.endsWith("h"))return console.error(`Unknown vector type ${s}. Line ${e.line}`),null;a="f16"}let o=r.getTypeName(),c="";if(o.endsWith("f"))c="f32";else if(o.endsWith("i"))c="i32";else if(o.endsWith("u"))c="u32";else if(o.endsWith("b"))c="bool";else{if(!o.endsWith("h"))return console.error(`Unknown vector type ${c}. Line ${e.line}`),null;c="f16"}let l=function(u,f,_){if(f===_)return u;let b=new Array(u.length);for(let w=0;w<u.length;w++)b[w]=vr(u[w],f,_);return b}(Array.from(n.data),a,c);return new p(l,this.getTypeInfo(r))}return console.error(`TODO: bitcast for ${n.typeInfo.name}. Line ${e.line}`),null}_evalConst(e,t){return t.getVariableValue(e.name).clone().getSubData(this,e.postfix,t)}_evalCreate(e,t){var n;if(e instanceof ne){if(e.type===null)return Je.void;switch(e.type.getTypeName()){case"bool":case"i32":case"u32":case"f32":case"f16":return this._callConstructorValue(e,t);case"vec2":case"vec3":case"vec4":case"vec2f":case"vec3f":case"vec4f":case"vec2h":case"vec3h":case"vec4h":case"vec2i":case"vec3i":case"vec4i":case"vec2u":case"vec3u":case"vec4u":case"vec2b":case"vec3b":case"vec4b":return this._callConstructorVec(e,t);case"mat2x2":case"mat2x2f":case"mat2x2h":case"mat2x3":case"mat2x3f":case"mat2x3h":case"mat2x4":case"mat2x4f":case"mat2x4h":case"mat3x2":case"mat3x2f":case"mat3x2h":case"mat3x3":case"mat3x3f":case"mat3x3h":case"mat3x4":case"mat3x4f":case"mat3x4h":case"mat4x2":case"mat4x2f":case"mat4x2h":case"mat4x3":case"mat4x3f":case"mat4x3h":case"mat4x4":case"mat4x4f":case"mat4x4h":return this._callConstructorMatrix(e,t)}}let r=e instanceof ne?e.type.name:e.name,s=e instanceof ne?this.getTypeInfo(e.type):this.getTypeInfo(e.name);if(s===null)return console.error(`Unknown type ${r}. Line ${e.line}`),null;if(s.size===0)return null;let a=new U(new ArrayBuffer(s.size),s,0);if(s instanceof ue){if(e.args)for(let o=0;o<e.args.length;++o){let c=s.members[o],l=e.args[o],u=this.evalExpression(l,t);a.setData(this,u,c.type,c.offset,t)}}else if(s instanceof fe){let o=0;if(e.args)for(let c=0;c<e.args.length;++c){let l=e.args[c],u=this.evalExpression(l,t);s.format===null&&(((n=u.typeInfo)===null||n===void 0?void 0:n.name)==="x32"?s.format=this.getTypeInfo("i32"):s.format=u.typeInfo),a.setData(this,u,s.format,o,t),o+=s.stride}}else console.error(`Unknown type "${r}". Line ${e.line}`);return e instanceof ne?a.getSubData(this,e.postfix,t):a}_evalLiteral(e,t){let n=this.getTypeInfo(e.type),r=n.name;return r==="x32"||r==="u32"||r==="f32"||r==="f16"||r==="i32"||r==="bool"?new m(e.scalarValue,n):r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"?this._callConstructorVec(e,t):r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"?this._callConstructorMatrix(e,t):e.value}_evalVariable(e,t){let n=t.getVariableValue(e.name);return n===null?n:n.getSubData(this,e.postfix,t)}_maxFormatTypeInfo(e){let t=e[0];if(t.name==="f32")return t;for(let n=1;n<e.length;++n){let r=G._priority.get(t.name);G._priority.get(e[n].name)<r&&(t=e[n])}return t.name==="x32"?this.getTypeInfo("i32"):t}_evalUnaryOp(e,t){let n=this.evalExpression(e.right,t);if(e.operator==="&")return new _e(n);if(e.operator==="*")return n instanceof _e?n.reference.getSubData(this,e.postfix,t):(console.error(`Invalid dereference. Line ${e.line}`),null);let r=n instanceof m?n.value:n instanceof p?Array.from(n.data):null;switch(e.operator){case"+":{if(A(r)){let o=r.map((c,l)=>+c);return new p(o,n.typeInfo)}let s=r,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new m(+s,a)}case"-":{if(A(r)){let o=r.map((c,l)=>-c);return new p(o,n.typeInfo)}let s=r,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new m(-s,a)}case"!":{if(A(r)){let o=r.map((c,l)=>c?0:1);return new p(o,n.typeInfo)}let s=r,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new m(s?0:1,a)}case"~":{if(A(r)){let o=r.map((c,l)=>~c);return new p(o,n.typeInfo)}let s=r,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new m(~s,a)}}return console.error(`Invalid unary operator ${e.operator}. Line ${e.line}`),null}_evalBinaryOp(e,t){let n=this.evalExpression(e.left,t),r=this.evalExpression(e.right,t),s=n instanceof m?n.value:n instanceof p||n instanceof N?Array.from(n.data):null,a=r instanceof m?r.value:r instanceof p||r instanceof N?Array.from(r.data):null;switch(e.operator){case"+":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b+f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_+u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u+_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o+c,l)}case"-":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b-f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_-u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u-_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o-c,l)}case"*":{if(A(s)&&A(a)){let u=s,f=a;if(n instanceof N&&r instanceof N){let _=function(S,E,T,k){if(X[E.name]===void 0||X[k.name]===void 0)return null;let I=X[E.name][0],C=X[E.name][1],M=X[k.name][0];if(I!==X[k.name][1])return null;let O=new Array(M*C);for(let V=0;V<C;V++)for(let F=0;F<M;F++){let D=0;for(let W=0;W<I;W++)D+=S[W*C+V]*T[F*I+W];O[V*M+F]=D}return O}(u,n.typeInfo,f,r.typeInfo);if(_===null)return console.error(`Matrix multiplication failed. Line ${e.line}.`),null;let b=X[r.typeInfo.name][0],w=X[n.typeInfo.name][1],L=this.getTypeInfo(`mat${b}x${w}f`);return new N(_,L)}if(n instanceof N&&r instanceof p){let _=function(b,w,L,S){if(X[w.name]===void 0||cn[S.name]===void 0)return null;let E=X[w.name][0],T=X[w.name][1];if(E!==L.length)return null;let k=new Array(T);for(let I=0;I<T;I++){let C=0;for(let M=0;M<E;M++)C+=b[M*T+I]*L[M];k[I]=C}return k}(u,n.typeInfo,f,r.typeInfo);return _===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new p(_,r.typeInfo)}if(n instanceof p&&r instanceof N){let _=function(b,w,L,S){if(cn[w.name]===void 0||X[S.name]===void 0)return null;let E=X[S.name][0],T=X[S.name][1];if(T!==b.length)return null;let k=[];for(let I=0;I<E;I++){let C=0;for(let M=0;M<T;M++)C+=b[M]*L[M*E+I];k[I]=C}return k}(u,n.typeInfo,f,r.typeInfo);return _===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new p(_,n.typeInfo)}{if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b*f[w]);return new p(_,n.typeInfo)}}if(A(s)){let u=a,f=s.map((_,b)=>_*u);return n instanceof N?new N(f,n.typeInfo):new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u*_);return r instanceof N?new N(f,r.typeInfo):new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o*c,l)}case"%":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b%f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_%u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u%_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o%c,l)}case"/":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b/f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_/u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u/_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o/c,l)}case"&":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b&f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_&u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u&_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o&c,l)}case"|":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b|f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_|u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u|_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o|c,l)}case"^":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b^f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_^u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u^_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o^c,l)}case"<<":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b<<f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_<<u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u<<_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o<<c,l)}case">>":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b>>f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_>>u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u>>_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o>>c,l)}case">":if(A(s)&&A(a)){let o=s,c=a;if(o.length!==c.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=o.map((u,f)=>u>c[f]?1:0);return new p(l,n.typeInfo)}if(A(s)){let o=a,c=s.map((l,u)=>l>o?1:0);return new p(c,n.typeInfo)}if(A(a)){let o=s,c=a.map((l,u)=>o>l?1:0);return new p(c,r.typeInfo)}return new m(s>a?1:0,this.getTypeInfo("bool"));case"<":if(A(s)&&A(a)){let o=s,c=a;if(o.length!==c.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=o.map((u,f)=>u<c[f]?1:0);return new p(l,n.typeInfo)}if(A(s)){let o=a,c=s.map((l,u)=>l<o?1:0);return new p(c,n.typeInfo)}if(A(a)){let o=s,c=a.map((l,u)=>o<l?1:0);return new p(c,r.typeInfo)}return new m(s<a?1:0,this.getTypeInfo("bool"));case"==":if(A(s)&&A(a)){let o=s,c=a;if(o.length!==c.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=o.map((u,f)=>u===c[f]?1:0);return new p(l,n.typeInfo)}if(A(s)){let o=a,c=s.map((l,u)=>l==o?1:0);return new p(c,n.typeInfo)}if(A(a)){let o=s,c=a.map((l,u)=>o==l?1:0);return new p(c,r.typeInfo)}return new m(s===a?1:0,this.getTypeInfo("bool"));case"!=":if(A(s)&&A(a)){let o=s,c=a;if(o.length!==c.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=o.map((u,f)=>u!==c[f]?1:0);return new p(l,n.typeInfo)}if(A(s)){let o=a,c=s.map((l,u)=>l!==o?1:0);return new p(c,n.typeInfo)}if(A(a)){let o=s,c=a.map((l,u)=>o!==l?1:0);return new p(c,r.typeInfo)}return new m(s!==a?1:0,this.getTypeInfo("bool"));case">=":if(A(s)&&A(a)){let o=s,c=a;if(o.length!==c.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=o.map((u,f)=>u>=c[f]?1:0);return new p(l,n.typeInfo)}if(A(s)){let o=a,c=s.map((l,u)=>l>=o?1:0);return new p(c,n.typeInfo)}if(A(a)){let o=s,c=a.map((l,u)=>o>=l?1:0);return new p(c,r.typeInfo)}return new m(s>=a?1:0,this.getTypeInfo("bool"));case"<=":if(A(s)&&A(a)){let o=s,c=a;if(o.length!==c.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=o.map((u,f)=>u<=c[f]?1:0);return new p(l,n.typeInfo)}if(A(s)){let o=a,c=s.map((l,u)=>l<=o?1:0);return new p(c,n.typeInfo)}if(A(a)){let o=s,c=a.map((l,u)=>o<=l?1:0);return new p(c,r.typeInfo)}return new m(s<=a?1:0,this.getTypeInfo("bool"));case"&&":if(A(s)&&A(a)){let o=s,c=a;if(o.length!==c.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=o.map((u,f)=>u&&c[f]?1:0);return new p(l,n.typeInfo)}if(A(s)){let o=a,c=s.map((l,u)=>l&&o?1:0);return new p(c,n.typeInfo)}if(A(a)){let o=s,c=a.map((l,u)=>o&&l?1:0);return new p(c,r.typeInfo)}return new m(s&&a?1:0,this.getTypeInfo("bool"));case"||":if(A(s)&&A(a)){let o=s,c=a;if(o.length!==c.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=o.map((u,f)=>u||c[f]?1:0);return new p(l,n.typeInfo)}if(A(s)){let o=a,c=s.map((l,u)=>l||o?1:0);return new p(c,n.typeInfo)}if(A(a)){let o=s,c=a.map((l,u)=>o||l?1:0);return new p(c,r.typeInfo)}return new m(s||a?1:0,this.getTypeInfo("bool"))}return console.error(`Unknown operator ${e.operator}. Line ${e.line}`),null}_evalCall(e,t){if(e.cachedReturnValue!==null)return e.cachedReturnValue;let n=t.clone();n.currentFunctionName=e.name;let r=t.getFunction(e.name);if(!r)return e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)?this._evalCreate(e,t):(console.error(`Unknown function "${e.name}". Line ${e.line}`),null);for(let s=0;s<r.node.args.length;++s){let a=r.node.args[s],o=this.evalExpression(e.args[s],n);n.createVariable(a.name,o,a)}return this._execStatements(r.node.body,n)}_callBuiltinFunction(e,t){switch(e.name){case"all":return this.builtins.All(e,t);case"any":return this.builtins.Any(e,t);case"select":return this.builtins.Select(e,t);case"arrayLength":return this.builtins.ArrayLength(e,t);case"abs":return this.builtins.Abs(e,t);case"acos":return this.builtins.Acos(e,t);case"acosh":return this.builtins.Acosh(e,t);case"asin":return this.builtins.Asin(e,t);case"asinh":return this.builtins.Asinh(e,t);case"atan":return this.builtins.Atan(e,t);case"atanh":return this.builtins.Atanh(e,t);case"atan2":return this.builtins.Atan2(e,t);case"ceil":return this.builtins.Ceil(e,t);case"clamp":return this.builtins.Clamp(e,t);case"cos":return this.builtins.Cos(e,t);case"cosh":return this.builtins.Cosh(e,t);case"countLeadingZeros":return this.builtins.CountLeadingZeros(e,t);case"countOneBits":return this.builtins.CountOneBits(e,t);case"countTrailingZeros":return this.builtins.CountTrailingZeros(e,t);case"cross":return this.builtins.Cross(e,t);case"degrees":return this.builtins.Degrees(e,t);case"determinant":return this.builtins.Determinant(e,t);case"distance":return this.builtins.Distance(e,t);case"dot":return this.builtins.Dot(e,t);case"dot4U8Packed":return this.builtins.Dot4U8Packed(e,t);case"dot4I8Packed":return this.builtins.Dot4I8Packed(e,t);case"exp":return this.builtins.Exp(e,t);case"exp2":return this.builtins.Exp2(e,t);case"extractBits":return this.builtins.ExtractBits(e,t);case"faceForward":return this.builtins.FaceForward(e,t);case"firstLeadingBit":return this.builtins.FirstLeadingBit(e,t);case"firstTrailingBit":return this.builtins.FirstTrailingBit(e,t);case"floor":return this.builtins.Floor(e,t);case"fma":return this.builtins.Fma(e,t);case"fract":return this.builtins.Fract(e,t);case"frexp":return this.builtins.Frexp(e,t);case"insertBits":return this.builtins.InsertBits(e,t);case"inverseSqrt":return this.builtins.InverseSqrt(e,t);case"ldexp":return this.builtins.Ldexp(e,t);case"length":return this.builtins.Length(e,t);case"log":return this.builtins.Log(e,t);case"log2":return this.builtins.Log2(e,t);case"max":return this.builtins.Max(e,t);case"min":return this.builtins.Min(e,t);case"mix":return this.builtins.Mix(e,t);case"modf":return this.builtins.Modf(e,t);case"normalize":return this.builtins.Normalize(e,t);case"pow":return this.builtins.Pow(e,t);case"quantizeToF16":return this.builtins.QuantizeToF16(e,t);case"radians":return this.builtins.Radians(e,t);case"reflect":return this.builtins.Reflect(e,t);case"refract":return this.builtins.Refract(e,t);case"reverseBits":return this.builtins.ReverseBits(e,t);case"round":return this.builtins.Round(e,t);case"saturate":return this.builtins.Saturate(e,t);case"sign":return this.builtins.Sign(e,t);case"sin":return this.builtins.Sin(e,t);case"sinh":return this.builtins.Sinh(e,t);case"smoothStep":return this.builtins.SmoothStep(e,t);case"sqrt":return this.builtins.Sqrt(e,t);case"step":return this.builtins.Step(e,t);case"tan":return this.builtins.Tan(e,t);case"tanh":return this.builtins.Tanh(e,t);case"transpose":return this.builtins.Transpose(e,t);case"trunc":return this.builtins.Trunc(e,t);case"dpdx":return this.builtins.Dpdx(e,t);case"dpdxCoarse":return this.builtins.DpdxCoarse(e,t);case"dpdxFine":return this.builtins.DpdxFine(e,t);case"dpdy":return this.builtins.Dpdy(e,t);case"dpdyCoarse":return this.builtins.DpdyCoarse(e,t);case"dpdyFine":return this.builtins.DpdyFine(e,t);case"fwidth":return this.builtins.Fwidth(e,t);case"fwidthCoarse":return this.builtins.FwidthCoarse(e,t);case"fwidthFine":return this.builtins.FwidthFine(e,t);case"textureDimensions":return this.builtins.TextureDimensions(e,t);case"textureGather":return this.builtins.TextureGather(e,t);case"textureGatherCompare":return this.builtins.TextureGatherCompare(e,t);case"textureLoad":return this.builtins.TextureLoad(e,t);case"textureNumLayers":return this.builtins.TextureNumLayers(e,t);case"textureNumLevels":return this.builtins.TextureNumLevels(e,t);case"textureNumSamples":return this.builtins.TextureNumSamples(e,t);case"textureSample":return this.builtins.TextureSample(e,t);case"textureSampleBias":return this.builtins.TextureSampleBias(e,t);case"textureSampleCompare":return this.builtins.TextureSampleCompare(e,t);case"textureSampleCompareLevel":return this.builtins.TextureSampleCompareLevel(e,t);case"textureSampleGrad":return this.builtins.TextureSampleGrad(e,t);case"textureSampleLevel":return this.builtins.TextureSampleLevel(e,t);case"textureSampleBaseClampToEdge":return this.builtins.TextureSampleBaseClampToEdge(e,t);case"textureStore":return this.builtins.TextureStore(e,t);case"atomicLoad":return this.builtins.AtomicLoad(e,t);case"atomicStore":return this.builtins.AtomicStore(e,t);case"atomicAdd":return this.builtins.AtomicAdd(e,t);case"atomicSub":return this.builtins.AtomicSub(e,t);case"atomicMax":return this.builtins.AtomicMax(e,t);case"atomicMin":return this.builtins.AtomicMin(e,t);case"atomicAnd":return this.builtins.AtomicAnd(e,t);case"atomicOr":return this.builtins.AtomicOr(e,t);case"atomicXor":return this.builtins.AtomicXor(e,t);case"atomicExchange":return this.builtins.AtomicExchange(e,t);case"atomicCompareExchangeWeak":return this.builtins.AtomicCompareExchangeWeak(e,t);case"pack4x8snorm":return this.builtins.Pack4x8snorm(e,t);case"pack4x8unorm":return this.builtins.Pack4x8unorm(e,t);case"pack4xI8":return this.builtins.Pack4xI8(e,t);case"pack4xU8":return this.builtins.Pack4xU8(e,t);case"pack4x8Clamp":return this.builtins.Pack4x8Clamp(e,t);case"pack4xU8Clamp":return this.builtins.Pack4xU8Clamp(e,t);case"pack2x16snorm":return this.builtins.Pack2x16snorm(e,t);case"pack2x16unorm":return this.builtins.Pack2x16unorm(e,t);case"pack2x16float":return this.builtins.Pack2x16float(e,t);case"unpack4x8snorm":return this.builtins.Unpack4x8snorm(e,t);case"unpack4x8unorm":return this.builtins.Unpack4x8unorm(e,t);case"unpack4xI8":return this.builtins.Unpack4xI8(e,t);case"unpack4xU8":return this.builtins.Unpack4xU8(e,t);case"unpack2x16snorm":return this.builtins.Unpack2x16snorm(e,t);case"unpack2x16unorm":return this.builtins.Unpack2x16unorm(e,t);case"unpack2x16float":return this.builtins.Unpack2x16float(e,t);case"storageBarrier":return this.builtins.StorageBarrier(e,t);case"textureBarrier":return this.builtins.TextureBarrier(e,t);case"workgroupBarrier":return this.builtins.WorkgroupBarrier(e,t);case"workgroupUniformLoad":return this.builtins.WorkgroupUniformLoad(e,t);case"subgroupAdd":return this.builtins.SubgroupAdd(e,t);case"subgroupExclusiveAdd":return this.builtins.SubgroupExclusiveAdd(e,t);case"subgroupInclusiveAdd":return this.builtins.SubgroupInclusiveAdd(e,t);case"subgroupAll":return this.builtins.SubgroupAll(e,t);case"subgroupAnd":return this.builtins.SubgroupAnd(e,t);case"subgroupAny":return this.builtins.SubgroupAny(e,t);case"subgroupBallot":return this.builtins.SubgroupBallot(e,t);case"subgroupBroadcast":return this.builtins.SubgroupBroadcast(e,t);case"subgroupBroadcastFirst":return this.builtins.SubgroupBroadcastFirst(e,t);case"subgroupElect":return this.builtins.SubgroupElect(e,t);case"subgroupMax":return this.builtins.SubgroupMax(e,t);case"subgroupMin":return this.builtins.SubgroupMin(e,t);case"subgroupMul":return this.builtins.SubgroupMul(e,t);case"subgroupExclusiveMul":return this.builtins.SubgroupExclusiveMul(e,t);case"subgroupInclusiveMul":return this.builtins.SubgroupInclusiveMul(e,t);case"subgroupOr":return this.builtins.SubgroupOr(e,t);case"subgroupShuffle":return this.builtins.SubgroupShuffle(e,t);case"subgroupShuffleDown":return this.builtins.SubgroupShuffleDown(e,t);case"subgroupShuffleUp":return this.builtins.SubgroupShuffleUp(e,t);case"subgroupShuffleXor":return this.builtins.SubgroupShuffleXor(e,t);case"subgroupXor":return this.builtins.SubgroupXor(e,t);case"quadBroadcast":return this.builtins.QuadBroadcast(e,t);case"quadSwapDiagonal":return this.builtins.QuadSwapDiagonal(e,t);case"quadSwapX":return this.builtins.QuadSwapX(e,t);case"quadSwapY":return this.builtins.QuadSwapY(e,t)}let n=t.getFunction(e.name);if(n){let r=t.clone();for(let s=0;s<n.node.args.length;++s){let a=n.node.args[s],o=this.evalExpression(e.args[s],r);r.setVariable(a.name,o,a)}return this._execStatements(n.node.body,r)}return null}_callConstructorValue(e,t){if(!e.args||e.args.length===0)return new m(0,this.getTypeInfo(e.type));let n=this.evalExpression(e.args[0],t);return n.typeInfo=this.getTypeInfo(e.type),n.getSubData(this,e.postfix,t).clone()}_callConstructorVec(e,t){let n=this.getTypeInfo(e.type),r=e.type.getTypeName(),s=cn[r];if(s===void 0)return console.error(`Invalid vec constructor ${r}. Line ${e.line}`),null;let a=[];if(e instanceof H)if(e.isVector){let o=e.vectorValue;for(let c of o)a.push(c)}else a.push(e.scalarValue);else if(e.args)for(let o of e.args){let c=this.evalExpression(o,t);if(c instanceof p){let l=c.data;for(let u=0;u<l.length;++u){let f=l[u];a.push(f)}}else if(c instanceof m){let l=c.value;a.push(l)}}if(e.type instanceof x&&e.type.format===null&&(e.type.format=x.f32),a.length===0){let o=new Array(s).fill(0);return new p(o,n).getSubData(this,e.postfix,t)}if(a.length===1)for(;a.length<s;)a.push(a[0]);return a.length<s?(console.error(`Invalid vec constructor. Line ${e.line}`),null):new p(a.length>s?a.slice(0,s):a,n).getSubData(this,e.postfix,t)}_callConstructorMatrix(e,t){let n=this.getTypeInfo(e.type),r=e.type.getTypeName(),s=X[r];if(s===void 0)return console.error(`Invalid matrix constructor ${r}. Line ${e.line}`),null;let a=[];if(e instanceof H)if(e.isVector){let o=e.vectorValue;for(let c of o)a.push(c)}else a.push(e.scalarValue);else if(e.args)for(let o of e.args){let c=this.evalExpression(o,t);c instanceof p?a.push(...c.data):c instanceof m?a.push(c.value):c instanceof N&&a.push(...c.data)}if(n instanceof he&&n.format===null&&(n.format=this.getTypeInfo("f32")),a.length===0){let o=new Array(s[2]).fill(0);return new N(o,n).getSubData(this,e.postfix,t)}return a.length!==s[2]?(console.error(`Invalid matrix constructor. Line ${e.line}`),null):new N(a,n).getSubData(this,e.postfix,t)}};G._breakObj=new J(new Z("BREAK",null),null),G._continueObj=new J(new Z("CONTINUE",null),null),G._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);var In=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},Sn=class{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new In,this._exec=new G,this._forwardTypeCount=0}parse(e){this._initialize(e),this._deferArrayCountEval.length=0;let t=[];for(;!this._isAtEnd();){let n=this._global_decl_or_directive();if(!n)break;t.push(n)}if(this._deferArrayCountEval.length>0){for(let n of this._deferArrayCountEval){let r=n.arrayType,s=n.countNode;if(s instanceof Y){let a=s.name,o=this._context.constants.get(a);if(o)try{let c=o.constEvaluate(this._exec);r.count=c}catch{}}}this._deferArrayCountEval.length=0}if(this._forwardTypeCount>0)for(let n of t)n.search(r=>{r instanceof Dt||r instanceof je?r.type=this._forwardType(r.type):r instanceof we?r.format=this._forwardType(r.format):r instanceof ae||r instanceof ye||r instanceof Ce?r.type=this._forwardType(r.type):r instanceof ke?r.returnType=this._forwardType(r.returnType):r instanceof Rt&&(r.type=this._forwardType(r.type))});return t}_forwardType(e){if(e instanceof Tt){let t=this._getType(e.name);if(t)return t}else e instanceof je?e.type=this._forwardType(e.type):e instanceof we&&(e.format=this._forwardType(e.format));return e}_initialize(e){if(e)if(typeof e=="string"){let t=new bn(e);this._tokens=t.scanTokens()}else this._tokens=e;else this._tokens=[];this._current=0}_updateNode(e,t){return e.line=t??this._currentLine,e}_error(e,t){return{token:e,message:t,toString:()=>`${t}`}}_isAtEnd(){return this._current>=this._tokens.length||this._peek().type==h.eof}_match(e){if(e instanceof d)return!!this._check(e)&&(this._advance(),!0);for(let t=0,n=e.length;t<n;++t){let r=e[t];if(this._check(r))return this._advance(),!0}return!1}_consume(e,t){if(this._check(e))return this._advance();throw this._error(this._peek(),`${t}. Line:${this._currentLine}`)}_check(e){if(this._isAtEnd())return!1;let t=this._peek();if(e instanceof Array){let n=t.type,r=!1;for(let s of e){if(n===s)return!0;s===h.tokens.name&&(r=!0)}if(r){let s=h.tokens.name.rule.exec(t.lexeme);if(s&&s.index==0&&s[0]==t.lexeme)return!0}return!1}if(t.type===e)return!0;if(e===h.tokens.name){let n=h.tokens.name.rule.exec(t.lexeme);return n&&n.index==0&&n[0]==t.lexeme}return!1}_advance(){var e,t;return this._currentLine=(t=(e=this._peek())===null||e===void 0?void 0:e.line)!==null&&t!==void 0?t:-1,this._isAtEnd()||this._current++,this._previous()}_peek(){return this._tokens[this._current]}_previous(){return this._tokens[this._current-1]}_global_decl_or_directive(){for(;this._match(h.tokens.semicolon)&&!this._isAtEnd(););if(this._match(h.keywords.alias)){let t=this._type_alias();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(h.keywords.diagnostic)){let t=this._diagnostic();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(h.keywords.requires)){let t=this._requires_directive();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(h.keywords.enable)){let t=this._enable_directive();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}let e=this._attribute();if(this._check(h.keywords.var)){let t=this._global_variable_decl();return t!=null&&(t.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(h.keywords.override)){let t=this._override_variable_decl();return t!=null&&(t.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(h.keywords.let)){let t=this._global_let_decl();return t!=null&&(t.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(h.keywords.const)){let t=this._global_const_decl();return t!=null&&(t.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(h.keywords.struct)){let t=this._struct_decl();return t!=null&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}if(this._check(h.keywords.fn)){let t=this._function_decl();return t!=null&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}return null}_function_decl(){if(!this._match(h.keywords.fn))return null;let e=this._currentLine,t=this._consume(h.tokens.ident,"Expected function name.").toString();this._consume(h.tokens.paren_left,"Expected '(' for function arguments.");let n=[];if(!this._check(h.tokens.paren_right))do{if(this._check(h.tokens.paren_right))break;let o=this._attribute(),c=this._consume(h.tokens.name,"Expected argument name.").toString();this._consume(h.tokens.colon,"Expected ':' for argument type.");let l=this._attribute(),u=this._type_decl();u!=null&&(u.attributes=l,n.push(this._updateNode(new Rt(c,u,o))))}while(this._match(h.tokens.comma));this._consume(h.tokens.paren_right,"Expected ')' after function arguments.");let r=null;if(this._match(h.tokens.arrow)){let o=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=o)}let s=this._compound_statement(),a=this._currentLine;return this._updateNode(new ke(t,n,r,s,e,a),e)}_compound_statement(){let e=[];for(this._consume(h.tokens.brace_left,"Expected '{' for block.");!this._check(h.tokens.brace_right);){let t=this._statement();t!==null&&e.push(t)}return this._consume(h.tokens.brace_right,"Expected '}' for block."),e}_statement(){for(;this._match(h.tokens.semicolon)&&!this._isAtEnd(););if(this._check(h.tokens.attr)&&this._attribute(),this._check(h.keywords.if))return this._if_statement();if(this._check(h.keywords.switch))return this._switch_statement();if(this._check(h.keywords.loop))return this._loop_statement();if(this._check(h.keywords.for))return this._for_statement();if(this._check(h.keywords.while))return this._while_statement();if(this._check(h.keywords.continuing))return this._continuing_statement();if(this._check(h.keywords.static_assert))return this._static_assert_statement();if(this._check(h.tokens.brace_left))return this._compound_statement();let e=null;if(this._check(h.keywords.return))e=this._return_statement();else if(this._check([h.keywords.var,h.keywords.let,h.keywords.const]))e=this._variable_statement();else if(this._match(h.keywords.discard))e=this._updateNode(new xn);else if(this._match(h.keywords.break)){let t=this._updateNode(new At);if(this._currentLoop.length>0){let n=this._currentLoop[this._currentLoop.length-1];t.loopId=n.id}e=t,this._check(h.keywords.if)&&(this._advance(),t.condition=this._optional_paren_expression())}else if(this._match(h.keywords.continue)){let t=this._updateNode(new Lt);if(!(this._currentLoop.length>0))throw this._error(this._peek(),`Continue statement must be inside a loop. Line: ${t.line}`);{let n=this._currentLoop[this._currentLoop.length-1];t.loopId=n.id}e=t}else e=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement();return e!=null&&this._consume(h.tokens.semicolon,"Expected ';' after statement."),e}_static_assert_statement(){if(!this._match(h.keywords.static_assert))return null;let e=this._currentLine,t=this._optional_paren_expression();return this._updateNode(new dn(t),e)}_while_statement(){if(!this._match(h.keywords.while))return null;let e=this._updateNode(new _t(null,null));return this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(h.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_continuing_statement(){let e=this._currentLoop.length>0?this._currentLoop[this._currentLoop.length-1].id:-1;if(!this._match(h.keywords.continuing))return null;let t=this._currentLine,n=this._compound_statement();return this._updateNode(new Xe(n,e),t)}_for_statement(){if(!this._match(h.keywords.for))return null;this._consume(h.tokens.paren_left,"Expected '('.");let e=this._updateNode(new xt(null,null,null,null));return this._currentLoop.push(e),e.init=this._check(h.tokens.semicolon)?null:this._for_init(),this._consume(h.tokens.semicolon,"Expected ';'."),e.condition=this._check(h.tokens.semicolon)?null:this._short_circuit_or_expression(),this._consume(h.tokens.semicolon,"Expected ';'."),e.increment=this._check(h.tokens.paren_right)?null:this._for_increment(),this._consume(h.tokens.paren_right,"Expected ')'."),this._check(h.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_for_init(){return this._variable_statement()||this._func_call_statement()||this._assignment_statement()}_for_increment(){return this._func_call_statement()||this._increment_decrement_statement()||this._assignment_statement()}_variable_statement(){if(this._check(h.keywords.var)){let e=this._variable_decl();if(e===null)throw this._error(this._peek(),"Variable declaration expected.");let t=null;return this._match(h.tokens.equal)&&(t=this._short_circuit_or_expression()),this._updateNode(new ae(e.name,e.type,e.storage,e.access,t),e.line)}if(this._match(h.keywords.let)){let e=this._currentLine,t=this._consume(h.tokens.name,"Expected name for let.").toString(),n=null;if(this._match(h.tokens.colon)){let s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}this._consume(h.tokens.equal,"Expected '=' for let.");let r=this._short_circuit_or_expression();return this._updateNode(new ye(t,n,null,null,r),e)}if(this._match(h.keywords.const)){let e=this._currentLine,t=this._consume(h.tokens.name,"Expected name for const.").toString(),n=null;if(this._match(h.tokens.colon)){let s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}this._consume(h.tokens.equal,"Expected '=' for const.");let r=this._short_circuit_or_expression();return n===null&&r instanceof H&&(n=r.type),this._updateNode(new Ce(t,n,null,null,r),e)}return null}_increment_decrement_statement(){let e=this._current,t=this._unary_expression();if(t==null)return null;if(!this._check(h.increment_operators))return this._current=e,null;let n=this._consume(h.increment_operators,"Expected increment operator");return this._updateNode(new vt(n.type===h.tokens.plus_plus?Ee.increment:Ee.decrement,t))}_assignment_statement(){let e=null,t=this._currentLine;if(this._check(h.tokens.brace_right))return null;let n=this._match(h.tokens.underscore);if(n||(e=this._unary_expression()),!n&&e==null)return null;let r=this._consume(h.assignment_operators,"Expected assignment operator."),s=this._short_circuit_or_expression();return this._updateNode(new bt(qe.parse(r.lexeme),e,s),t)}_func_call_statement(){if(!this._check(h.tokens.ident))return null;let e=this._currentLine,t=this._current,n=this._consume(h.tokens.ident,"Expected function name."),r=this._argument_expression_list();return r===null?(this._current=t,null):this._updateNode(new Ke(n.lexeme,r),e)}_loop_statement(){if(!this._match(h.keywords.loop))return null;this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Expected '{' for loop.");let e=this._updateNode(new yt([],null));this._currentLoop.push(e);let t=this._statement();for(;t!==null;){if(Array.isArray(t))for(let n of t)e.body.push(n);else e.body.push(t);if(t instanceof Xe){e.continuing=t;break}t=this._statement()}return this._currentLoop.pop(),this._consume(h.tokens.brace_right,"Expected '}' for loop."),e}_switch_statement(){if(!this._match(h.keywords.switch))return null;let e=this._updateNode(new wt(null,[]));if(this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Expected '{' for switch."),e.cases=this._switch_body(),e.cases==null||e.cases.length==0)throw this._error(this._previous(),"Expected 'case' or 'default'.");return this._consume(h.tokens.brace_right,"Expected '}' for switch."),this._currentLoop.pop(),e}_switch_body(){let e=[],t=!1;for(;this._check([h.keywords.default,h.keywords.case]);){if(this._match(h.keywords.case)){let n=this._case_selectors();for(let s of n)if(s instanceof Ne){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");t=!0;break}this._match(h.tokens.colon),this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Exected '{' for switch case.");let r=this._case_body();this._consume(h.tokens.brace_right,"Exected '}' for switch case."),e.push(this._updateNode(new Ot(n,r)))}if(this._match(h.keywords.default)){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");this._match(h.tokens.colon),this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Exected '{' for switch default.");let n=this._case_body();this._consume(h.tokens.brace_right,"Exected '}' for switch default."),e.push(this._updateNode(new Pt(n)))}}return e}_case_selectors(){let e=[];for(this._match(h.keywords.default)?e.push(this._updateNode(new Ne)):e.push(this._shift_expression());this._match(h.tokens.comma);)this._match(h.keywords.default)?e.push(this._updateNode(new Ne)):e.push(this._shift_expression());return e}_case_body(){if(this._match(h.keywords.fallthrough))return this._consume(h.tokens.semicolon,"Expected ';'"),[];let e=this._statement();if(e==null)return[];e instanceof Array||(e=[e]);let t=this._case_body();return t.length==0?e:[...e,t[0]]}_if_statement(){if(!this._match(h.keywords.if))return null;let e=this._currentLine,t=this._optional_paren_expression();this._check(h.tokens.attr)&&this._attribute();let n=this._compound_statement(),r=[];this._match_elseif()&&(this._check(h.tokens.attr)&&this._attribute(),r=this._elseif_statement(r));let s=null;return this._match(h.keywords.else)&&(this._check(h.tokens.attr)&&this._attribute(),s=this._compound_statement()),this._updateNode(new kt(t,n,r,s),e)}_match_elseif(){return this._tokens[this._current].type===h.keywords.else&&this._tokens[this._current+1].type===h.keywords.if&&(this._advance(),this._advance(),!0)}_elseif_statement(e=[]){let t=this._optional_paren_expression(),n=this._compound_statement();return e.push(this._updateNode(new vn(t,n))),this._match_elseif()&&(this._check(h.tokens.attr)&&this._attribute(),this._elseif_statement(e)),e}_return_statement(){if(!this._match(h.keywords.return))return null;let e=this._short_circuit_or_expression();return this._updateNode(new It(e))}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(h.tokens.or_or);)e=this._updateNode(new ee(this._previous().toString(),e,this._short_circuit_and_expr()));return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(h.tokens.and_and);)e=this._updateNode(new ee(this._previous().toString(),e,this._inclusive_or_expression()));return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(h.tokens.or);)e=this._updateNode(new ee(this._previous().toString(),e,this._exclusive_or_expression()));return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(h.tokens.xor);)e=this._updateNode(new ee(this._previous().toString(),e,this._and_expression()));return e}_and_expression(){let e=this._equality_expression();for(;this._match(h.tokens.and);)e=this._updateNode(new ee(this._previous().toString(),e,this._equality_expression()));return e}_equality_expression(){let e=this._relational_expression();return this._match([h.tokens.equal_equal,h.tokens.not_equal])?this._updateNode(new ee(this._previous().toString(),e,this._relational_expression())):e}_relational_expression(){let e=this._shift_expression();for(;this._match([h.tokens.less_than,h.tokens.greater_than,h.tokens.less_than_equal,h.tokens.greater_than_equal]);)e=this._updateNode(new ee(this._previous().toString(),e,this._shift_expression()));return e}_shift_expression(){let e=this._additive_expression();for(;this._match([h.tokens.shift_left,h.tokens.shift_right]);)e=this._updateNode(new ee(this._previous().toString(),e,this._additive_expression()));return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([h.tokens.plus,h.tokens.minus]);)e=this._updateNode(new ee(this._previous().toString(),e,this._multiplicative_expression()));return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([h.tokens.star,h.tokens.forward_slash,h.tokens.modulo]);)e=this._updateNode(new ee(this._previous().toString(),e,this._unary_expression()));return e}_unary_expression(){return this._match([h.tokens.minus,h.tokens.bang,h.tokens.tilde,h.tokens.star,h.tokens.and])?this._updateNode(new z(this._previous().toString(),this._unary_expression())):this._singular_expression()}_singular_expression(){let e=this._primary_expression(),t=this._postfix_expression();return t&&(e.postfix=t),e}_postfix_expression(){if(this._match(h.tokens.bracket_left)){let e=this._short_circuit_or_expression();this._consume(h.tokens.bracket_right,"Expected ']'.");let t=this._updateNode(new xe(e)),n=this._postfix_expression();return n&&(t.postfix=n),t}if(this._match(h.tokens.period)){let e=this._consume(h.tokens.name,"Expected member name."),t=this._postfix_expression(),n=this._updateNode(new pe(e.lexeme));return t&&(n.postfix=t),n}return null}_getStruct(e){return this._context.aliases.has(e)?this._context.aliases.get(e).type:this._context.structs.has(e)?this._context.structs.get(e):null}_getType(e){let t=this._getStruct(e);if(t!==null)return t;switch(e){case"void":return y.void;case"bool":return y.bool;case"i32":return y.i32;case"u32":return y.u32;case"f32":return y.f32;case"f16":return y.f16;case"vec2f":return x.vec2f;case"vec3f":return x.vec3f;case"vec4f":return x.vec4f;case"vec2i":return x.vec2i;case"vec3i":return x.vec3i;case"vec4i":return x.vec4i;case"vec2u":return x.vec2u;case"vec3u":return x.vec3u;case"vec4u":return x.vec4u;case"vec2h":return x.vec2h;case"vec3h":return x.vec3h;case"vec4h":return x.vec4h;case"mat2x2f":return x.mat2x2f;case"mat2x3f":return x.mat2x3f;case"mat2x4f":return x.mat2x4f;case"mat3x2f":return x.mat3x2f;case"mat3x3f":return x.mat3x3f;case"mat3x4f":return x.mat3x4f;case"mat4x2f":return x.mat4x2f;case"mat4x3f":return x.mat4x3f;case"mat4x4f":return x.mat4x4f;case"mat2x2h":return x.mat2x2h;case"mat2x3h":return x.mat2x3h;case"mat2x4h":return x.mat2x4h;case"mat3x2h":return x.mat3x2h;case"mat3x3h":return x.mat3x3h;case"mat3x4h":return x.mat3x4h;case"mat4x2h":return x.mat4x2h;case"mat4x3h":return x.mat4x3h;case"mat4x4h":return x.mat4x4h;case"mat2x2i":return x.mat2x2i;case"mat2x3i":return x.mat2x3i;case"mat2x4i":return x.mat2x4i;case"mat3x2i":return x.mat3x2i;case"mat3x3i":return x.mat3x3i;case"mat3x4i":return x.mat3x4i;case"mat4x2i":return x.mat4x2i;case"mat4x3i":return x.mat4x3i;case"mat4x4i":return x.mat4x4i;case"mat2x2u":return x.mat2x2u;case"mat2x3u":return x.mat2x3u;case"mat2x4u":return x.mat2x4u;case"mat3x2u":return x.mat3x2u;case"mat3x3u":return x.mat3x3u;case"mat3x4u":return x.mat3x4u;case"mat4x2u":return x.mat4x2u;case"mat4x3u":return x.mat4x3u;case"mat4x4u":return x.mat4x4u}return null}_validateTypeRange(e,t){if(t.name==="i32"){if(e<-2147483648||e>2147483647)throw this._error(this._previous(),`Value out of range for i32: ${e}. Line: ${this._currentLine}.`)}else if(t.name==="u32"&&(e<0||e>4294967295))throw this._error(this._previous(),`Value out of range for u32: ${e}. Line: ${this._currentLine}.`)}_primary_expression(){if(this._match(h.tokens.ident)){let n=this._previous().toString();if(this._check(h.tokens.paren_left)){let r=this._argument_expression_list(),s=this._getType(n);return s!==null?this._updateNode(new ne(s,r)):this._updateNode(new Qe(n,r))}if(this._context.constants.has(n)){let r=this._context.constants.get(n);return this._updateNode(new Et(n,r.value))}return this._updateNode(new Y(n))}if(this._match(h.tokens.int_literal)){let n=this._previous().toString(),r=n.endsWith("i")||n.endsWith("i")?y.i32:n.endsWith("u")||n.endsWith("U")?y.u32:y.x32,s=parseInt(n);return this._validateTypeRange(s,r),this._updateNode(new H(new m(s,this._exec.getTypeInfo(r)),r))}if(this._match(h.tokens.uint_literal)){let n=parseInt(this._previous().toString());return this._validateTypeRange(n,y.u32),this._updateNode(new H(new m(n,this._exec.getTypeInfo(y.u32)),y.u32))}if(this._match([h.tokens.decimal_float_literal,h.tokens.hex_float_literal])){let n=this._previous().toString(),r=n.endsWith("h");r&&(n=n.substring(0,n.length-1));let s=parseFloat(n);this._validateTypeRange(s,r?y.f16:y.f32);let a=r?y.f16:y.f32;return this._updateNode(new H(new m(s,this._exec.getTypeInfo(a)),a))}if(this._match([h.keywords.true,h.keywords.false])){let n=this._previous().toString()===h.keywords.true.rule;return this._updateNode(new H(new m(n?1:0,this._exec.getTypeInfo(y.bool)),y.bool))}if(this._check(h.tokens.paren_left))return this._paren_expression();if(this._match(h.keywords.bitcast)){this._consume(h.tokens.less_than,"Expected '<'.");let n=this._type_decl();this._consume(h.tokens.greater_than,"Expected '>'.");let r=this._paren_expression();return this._updateNode(new Mt(n,r))}let e=this._type_decl(),t=this._argument_expression_list();return this._updateNode(new ne(e,t))}_argument_expression_list(){if(!this._match(h.tokens.paren_left))return null;let e=[];do{if(this._check(h.tokens.paren_right))break;let t=this._short_circuit_or_expression();e.push(t)}while(this._match(h.tokens.comma));return this._consume(h.tokens.paren_right,"Expected ')' for agument list"),e}_optional_paren_expression(){this._match(h.tokens.paren_left);let e=this._short_circuit_or_expression();return this._match(h.tokens.paren_right),e}_paren_expression(){this._consume(h.tokens.paren_left,"Expected '('.");let e=this._short_circuit_or_expression();return this._consume(h.tokens.paren_right,"Expected ')'."),e}_struct_decl(){if(!this._match(h.keywords.struct))return null;let e=this._currentLine,t=this._consume(h.tokens.ident,"Expected name for struct.").toString();this._consume(h.tokens.brace_left,"Expected '{' for struct body.");let n=[];for(;!this._check(h.tokens.brace_right);){let a=this._attribute(),o=this._consume(h.tokens.name,"Expected variable name.").toString();this._consume(h.tokens.colon,"Expected ':' for struct member type.");let c=this._attribute(),l=this._type_decl();l!=null&&(l.attributes=c),this._check(h.tokens.brace_right)?this._match(h.tokens.comma):this._consume(h.tokens.comma,"Expected ',' for struct member."),n.push(this._updateNode(new Dt(o,l,a)))}this._consume(h.tokens.brace_right,"Expected '}' after struct body.");let r=this._currentLine,s=this._updateNode(new ie(t,n,e,r),e);return this._context.structs.set(t,s),s}_global_variable_decl(){let e=this._variable_decl();if(!e)return null;if(this._match(h.tokens.equal)){let t=this._const_expression();e.value=t}if(e.type!==null&&e.value instanceof H){if(e.value.type.name!=="x32"&&e.type.getTypeName()!==e.value.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${e.value.type.name} to ${e.type.name}. Line:${this._currentLine}`);e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type),e.value.type=e.type}else e.type===null&&e.value instanceof H&&(e.type=e.value.type.name==="x32"?y.i32:e.value.type,e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type));return e}_override_variable_decl(){let e=this._override_decl();return e&&this._match(h.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){var e;if(!this._match(h.keywords.const))return null;let t=this._consume(h.tokens.name,"Expected variable name"),n=this._currentLine,r=null;if(this._match(h.tokens.colon)){let c=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=c)}let s=null;this._consume(h.tokens.equal,"const declarations require an assignment");let a=this._short_circuit_or_expression();try{let c=[y.f32],l=a.constEvaluate(this._exec,c);l instanceof m&&this._validateTypeRange(l.value,c[0]),c[0]instanceof x&&c[0].format===null&&l.typeInfo instanceof he&&l.typeInfo.format!==null&&(l.typeInfo.format.name==="f16"?c[0].format=y.f16:l.typeInfo.format.name==="f32"?c[0].format=y.f32:l.typeInfo.format.name==="i32"?c[0].format=y.i32:l.typeInfo.format.name==="u32"?c[0].format=y.u32:l.typeInfo.format.name==="bool"?c[0].format=y.bool:console.error(`TODO: impelement template format type ${l.typeInfo.format.name}`)),s=this._updateNode(new H(l,c[0])),this._exec.context.setVariable(t.toString(),l)}catch{s=a}if(r!==null&&s instanceof H){if(s.type.name!=="x32"&&r.getTypeName()!==s.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${s.type.name} to ${r.name}. Line:${this._currentLine}`);s.type=r,s.isScalar&&this._validateTypeRange(s.scalarValue,s.type)}else r===null&&s instanceof H&&(r=(e=s?.type)!==null&&e!==void 0?e:y.f32,r===y.x32&&(r=y.i32));let o=this._updateNode(new Ce(t.toString(),r,"","",s),n);return this._context.constants.set(o.name,o),o}_global_let_decl(){if(!this._match(h.keywords.let))return null;let e=this._currentLine,t=this._consume(h.tokens.name,"Expected variable name"),n=null;if(this._match(h.tokens.colon)){let s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}let r=null;if(this._match(h.tokens.equal)&&(r=this._const_expression()),n!==null&&r instanceof H){if(r.type.name!=="x32"&&n.getTypeName()!==r.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${r.type.name} to ${n.name}. Line:${this._currentLine}`);r.type=n}else n===null&&r instanceof H&&(n=r.type.name==="x32"?y.i32:r.type);return r instanceof H&&r.isScalar&&this._validateTypeRange(r.scalarValue,n),this._updateNode(new ye(t.toString(),n,"","",r),e)}_const_expression(){return this._short_circuit_or_expression()}_variable_decl(){if(!this._match(h.keywords.var))return null;let e=this._currentLine,t="",n="";this._match(h.tokens.less_than)&&(t=this._consume(h.storage_class,"Expected storage_class.").toString(),this._match(h.tokens.comma)&&(n=this._consume(h.access_mode,"Expected access_mode.").toString()),this._consume(h.tokens.greater_than,"Expected '>'."));let r=this._consume(h.tokens.name,"Expected variable name"),s=null;if(this._match(h.tokens.colon)){let a=this._attribute();s=this._type_decl(),s!=null&&(s.attributes=a)}return this._updateNode(new ae(r.toString(),s,t,n,null),e)}_override_decl(){if(!this._match(h.keywords.override))return null;let e=this._consume(h.tokens.name,"Expected variable name"),t=null;if(this._match(h.tokens.colon)){let n=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=n)}return this._updateNode(new Ye(e.toString(),t,null))}_diagnostic(){this._consume(h.tokens.paren_left,"Expected '('");let e=this._consume(h.tokens.ident,"Expected severity control name.");this._consume(h.tokens.comma,"Expected ','");let t=this._consume(h.tokens.ident,"Expected diagnostic rule name.").toString();return this._match(h.tokens.period)&&(t+=`.${this._consume(h.tokens.ident,"Expected diagnostic message.").toString()}`),this._consume(h.tokens.paren_right,"Expected ')'"),this._updateNode(new St(e.toString(),t))}_enable_directive(){let e=this._consume(h.tokens.ident,"identity expected.");return this._updateNode(new gn(e.toString()))}_requires_directive(){let e=[this._consume(h.tokens.ident,"identity expected.").toString()];for(;this._match(h.tokens.comma);){let t=this._consume(h.tokens.ident,"identity expected.");e.push(t.toString())}return this._updateNode(new _n(e))}_type_alias(){let e=this._consume(h.tokens.ident,"identity expected.");this._consume(h.tokens.equal,"Expected '=' for type alias.");let t=this._type_decl();if(t===null)throw this._error(this._peek(),"Expected Type for Alias.");this._context.aliases.has(t.name)&&(t=this._context.aliases.get(t.name).type);let n=this._updateNode(new Ze(e.toString(),t));return this._context.aliases.set(n.name,n),n}_type_decl(){if(this._check([h.tokens.ident,...h.texel_format,h.keywords.bool,h.keywords.f32,h.keywords.i32,h.keywords.u32])){let n=this._advance().toString();if(this._context.structs.has(n))return this._context.structs.get(n);if(this._context.aliases.has(n))return this._context.aliases.get(n).type;if(!this._getType(n)){let r=this._updateNode(new Tt(n));return this._forwardTypeCount++,r}return this._updateNode(new y(n))}let e=this._texture_sampler_types();if(e)return e;if(this._check(h.template_types)){let n=this._advance().toString(),r=null,s=null;return this._match(h.tokens.less_than)&&(r=this._type_decl(),s=null,this._match(h.tokens.comma)&&(s=this._consume(h.access_mode,"Expected access_mode for pointer").toString()),this._consume(h.tokens.greater_than,"Expected '>' for type.")),this._updateNode(new x(n,r,s))}if(this._match(h.keywords.ptr)){let n=this._previous().toString();this._consume(h.tokens.less_than,"Expected '<' for pointer.");let r=this._consume(h.storage_class,"Expected storage_class for pointer");this._consume(h.tokens.comma,"Expected ',' for pointer.");let s=this._type_decl(),a=null;return this._match(h.tokens.comma)&&(a=this._consume(h.access_mode,"Expected access_mode for pointer").toString()),this._consume(h.tokens.greater_than,"Expected '>' for pointer."),this._updateNode(new je(n,r.toString(),s,a))}let t=this._attribute();if(this._match(h.keywords.array)){let n=null,r=-1,s=this._previous(),a=null;if(this._match(h.tokens.less_than)){n=this._type_decl(),this._context.aliases.has(n.name)&&(n=this._context.aliases.get(n.name).type);let c="";if(this._match(h.tokens.comma)){a=this._shift_expression();try{c=a.constEvaluate(this._exec).toString(),a=null}catch{c="1"}}this._consume(h.tokens.greater_than,"Expected '>' for array."),r=c?parseInt(c):0}let o=this._updateNode(new we(s.toString(),t,n,r));return a&&this._deferArrayCountEval.push({arrayType:o,countNode:a}),o}return null}_texture_sampler_types(){if(this._match(h.sampler_type))return this._updateNode(new be(this._previous().toString(),null,null));if(this._match(h.depth_texture_type))return this._updateNode(new be(this._previous().toString(),null,null));if(this._match(h.sampled_texture_type)||this._match(h.multisampled_texture_type)){let e=this._previous();this._consume(h.tokens.less_than,"Expected '<' for sampler type.");let t=this._type_decl();return this._consume(h.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new be(e.toString(),t,null))}if(this._match(h.storage_texture_type)){let e=this._previous();this._consume(h.tokens.less_than,"Expected '<' for sampler type.");let t=this._consume(h.texel_format,"Invalid texel format.").toString();this._consume(h.tokens.comma,"Expected ',' after texel format.");let n=this._consume(h.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(h.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new be(e.toString(),t,n))}return null}_attribute(){let e=[];for(;this._match(h.tokens.attr);){let t=this._consume(h.attribute_name,"Expected attribute name"),n=this._updateNode(new Ft(t.toString(),null));if(this._match(h.tokens.paren_left)){if(n.value=this._consume(h.literal_or_ident,"Expected attribute value").toString(),this._check(h.tokens.comma)){this._advance();do{let r=this._consume(h.literal_or_ident,"Expected attribute value").toString();n.value instanceof Array||(n.value=[n.value]),n.value.push(r)}while(this._match(h.tokens.comma))}this._consume(h.tokens.paren_right,"Expected ')'")}e.push(n)}return e.length==0?null:e}},zt=class extends re{constructor(e){super(),e&&this.update(e)}update(e){let t=new Sn().parse(e);this.updateAST(t)}};function Sr(i){let e={attributes:[],bindings:[]},t;try{t=fi(i)}catch(s){return Ir.log.error(s.message)(),e}for(let s of t.uniforms){let a=[];for(let o of s.type?.members||[])a.push({name:o.name,type:kr(o.type)});e.bindings.push({type:"uniform",name:s.name,group:s.group,location:s.binding,members:a})}for(let s of t.textures)e.bindings.push({type:"texture",name:s.name,group:s.group,location:s.binding});for(let s of t.samplers)e.bindings.push({type:"sampler",name:s.name,group:s.group,location:s.binding});let n=t.entry.vertex[0],r=n?.inputs.length||0;for(let s=0;s<r;s++){let a=n.inputs[s];if(a.locationType==="location"){let o=kr(a.type);e.attributes.push({name:a.name,location:Number(a.location),type:o})}}return e}function kr(i){return i.format?`${i.name}<${i.format.name}>`:i.name}function fi(i){try{return new zt(i)}catch(e){if(e instanceof Error)throw e;let t="WGSL parse error";throw typeof e=="object"&&e?.message&&(t+=`: ${e.message} `),typeof e=="object"&&e?.token&&(t+=e.token.line||""),new Error(t,{cause:e})}}var Yo=1/Math.PI*180,Ko=1/180*Math.PI,hi={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...hi}};var K=globalThis.mathgl.config;function Ln(i,{precision:e=K.precision}={}){return i=pi(i),`${parseFloat(i.toPrecision(e))}`}function Re(i){return Array.isArray(i)||ArrayBuffer.isView(i)&&!(i instanceof DataView)}function Tn(i,e,t){return di(i,n=>Math.max(e,Math.min(t,n)))}function Wt(i,e,t){let n=K.EPSILON;t&&(K.EPSILON=t);try{if(i===e)return!0;if(Re(i)&&Re(e)){if(i.length!==e.length)return!1;for(let r=0;r<i.length;++r)if(!Wt(i[r],e[r]))return!1;return!0}return i&&i.equals?i.equals(e):e&&e.equals?e.equals(i):typeof i=="number"&&typeof e=="number"?Math.abs(i-e)<=K.EPSILON*Math.max(1,Math.abs(i),Math.abs(e)):!1}finally{K.EPSILON=n}}function pi(i){return Math.round(i/K.EPSILON)*K.EPSILON}function mi(i){return i.clone?i.clone():new Array(i.length)}function di(i,e,t){if(Re(i)){let n=i;t=t||mi(n);for(let r=0;r<t.length&&r<n.length;++r){let s=typeof i=="number"?i:i[r];t[r]=e(s,r,t)}return t}return e(i)}var Ht=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(e,t=0){for(let n=0;n<this.ELEMENTS;++n)this[n]=e[n+t];return this.check()}toArray(e=[],t=0){for(let n=0;n<this.ELEMENTS;++n)e[t+n]=this[n];return e}toObject(e){return e}from(e){return Array.isArray(e)?this.copy(e):this.fromObject(e)}to(e){return e===this?this:Re(e)?this.toArray(e):this.toObject(e)}toTarget(e){return e?this.to(e):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(K)}formatString(e){let t="";for(let n=0;n<this.ELEMENTS;++n)t+=(n>0?", ":"")+Ln(this[n],e);return`${e.printTypes?this.constructor.name:""}[${t}]`}equals(e){if(!e||this.length!==e.length)return!1;for(let t=0;t<this.ELEMENTS;++t)if(!Wt(this[t],e[t]))return!1;return!0}exactEquals(e){if(!e||this.length!==e.length)return!1;for(let t=0;t<this.ELEMENTS;++t)if(this[t]!==e[t])return!1;return!0}negate(){for(let e=0;e<this.ELEMENTS;++e)this[e]=-this[e];return this.check()}lerp(e,t,n){if(n===void 0)return this.lerp(this,e,t);for(let r=0;r<this.ELEMENTS;++r){let s=e[r],a=typeof t=="number"?t:t[r];this[r]=s+n*(a-s)}return this.check()}min(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=Math.min(e[t],this[t]);return this.check()}max(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=Math.max(e[t],this[t]);return this.check()}clamp(e,t){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],e[n]),t[n]);return this.check()}add(...e){for(let t of e)for(let n=0;n<this.ELEMENTS;++n)this[n]+=t[n];return this.check()}subtract(...e){for(let t of e)for(let n=0;n<this.ELEMENTS;++n)this[n]-=t[n];return this.check()}scale(e){if(typeof e=="number")for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;else for(let t=0;t<this.ELEMENTS&&t<e.length;++t)this[t]*=e[t];return this.check()}multiplyByScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;return this.check()}check(){if(K.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let e=this.length===this.ELEMENTS;for(let t=0;t<this.ELEMENTS;++t)e=e&&Number.isFinite(this[t]);return e}sub(e){return this.subtract(e)}setScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=e;return this.check()}addScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]+=e;return this.check()}subScalar(e){return this.addScalar(-e)}multiplyScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;return this.check()}divideScalar(e){return this.multiplyByScalar(1/e)}clampScalar(e,t){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],e),t);return this.check()}get elements(){return this}};function gi(i,e){if(i.length!==e)return!1;for(let t=0;t<i.length;++t)if(!Number.isFinite(i[t]))return!1;return!0}function Ar(i){if(!Number.isFinite(i))throw new Error(`Invalid number ${JSON.stringify(i)}`);return i}function Gt(i,e,t=""){if(K.debug&&!gi(i,e))throw new Error(`math.gl: ${t} some fields set to invalid numbers'`);return i}var me=typeof Float32Array<"u"?Float32Array:Array;var na=Math.PI/180;function _i(){let i=new me(2);return me!=Float32Array&&(i[0]=0,i[1]=0),i}function Er(i,e,t){let n=e[0],r=e[1];return i[0]=t[0]*n+t[4]*r+t[12],i[1]=t[1]*n+t[5]*r+t[13],i}var ra=function(){let i=_i();return function(e,t,n,r,s,a){let o,c;for(t||(t=2),n||(n=0),r?c=Math.min(r*t+n,e.length):c=e.length,o=n;o<c;o+=t)i[0]=e[o],i[1]=e[o+1],s(i,i,a),e[o]=i[0],e[o+1]=i[1];return e}}();function Mr(i,e,t){let n=e[0],r=e[1],s=t[3]*n+t[7]*r||1;return i[0]=(t[0]*n+t[4]*r)/s,i[1]=(t[1]*n+t[5]*r)/s,i}function Cr(i,e,t){let n=e[0],r=e[1],s=e[2],a=t[3]*n+t[7]*r+t[11]*s||1;return i[0]=(t[0]*n+t[4]*r+t[8]*s)/a,i[1]=(t[1]*n+t[5]*r+t[9]*s)/a,i[2]=(t[2]*n+t[6]*r+t[10]*s)/a,i}function xi(){let i=new me(3);return me!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0),i}function Nr(i,e,t){let n=e[0],r=e[1],s=e[2],a=t[3]*n+t[7]*r+t[11]*s+t[15];return a=a||1,i[0]=(t[0]*n+t[4]*r+t[8]*s+t[12])/a,i[1]=(t[1]*n+t[5]*r+t[9]*s+t[13])/a,i[2]=(t[2]*n+t[6]*r+t[10]*s+t[14])/a,i}var oa=function(){let i=xi();return function(e,t,n,r,s,a){let o,c;for(t||(t=3),n||(n=0),r?c=Math.min(r*t+n,e.length):c=e.length,o=n;o<c;o+=t)i[0]=e[o],i[1]=e[o+1],i[2]=e[o+2],s(i,i,a),e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2];return e}}();var qt=class extends Ht{toString(){let e="[";if(K.printRowMajor){e+="row-major:";for(let t=0;t<this.RANK;++t)for(let n=0;n<this.RANK;++n)e+=` ${this[n*this.RANK+t]}`}else{e+="column-major:";for(let t=0;t<this.ELEMENTS;++t)e+=` ${this[t]}`}return e+="]",e}getElementIndex(e,t){return t*this.RANK+e}getElement(e,t){return this[t*this.RANK+e]}setElement(e,t,n){return this[t*this.RANK+e]=Ar(n),this}getColumn(e,t=new Array(this.RANK).fill(-0)){let n=e*this.RANK;for(let r=0;r<this.RANK;++r)t[r]=this[n+r];return t}setColumn(e,t){let n=e*this.RANK;for(let r=0;r<this.RANK;++r)this[n+r]=t[r];return this}};function vi(i){return i[0]=1,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=1,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[10]=1,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i}function Or(i,e){if(i===e){let t=e[1],n=e[2],r=e[3],s=e[6],a=e[7],o=e[11];i[1]=e[4],i[2]=e[8],i[3]=e[12],i[4]=t,i[6]=e[9],i[7]=e[13],i[8]=n,i[9]=s,i[11]=e[14],i[12]=r,i[13]=a,i[14]=o}else i[0]=e[0],i[1]=e[4],i[2]=e[8],i[3]=e[12],i[4]=e[1],i[5]=e[5],i[6]=e[9],i[7]=e[13],i[8]=e[2],i[9]=e[6],i[10]=e[10],i[11]=e[14],i[12]=e[3],i[13]=e[7],i[14]=e[11],i[15]=e[15];return i}function Pr(i,e){let t=e[0],n=e[1],r=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8],f=e[9],_=e[10],b=e[11],w=e[12],L=e[13],S=e[14],E=e[15],T=t*o-n*a,k=t*c-r*a,I=t*l-s*a,C=n*c-r*o,M=n*l-s*o,O=r*l-s*c,V=u*L-f*w,F=u*S-_*w,D=u*E-b*w,W=f*S-_*L,te=f*E-b*L,j=_*E-b*S,$=T*j-k*te+I*W+C*D-M*F+O*V;return $?($=1/$,i[0]=(o*j-c*te+l*W)*$,i[1]=(r*te-n*j-s*W)*$,i[2]=(L*O-S*M+E*C)*$,i[3]=(_*M-f*O-b*C)*$,i[4]=(c*D-a*j-l*F)*$,i[5]=(t*j-r*D+s*F)*$,i[6]=(S*I-w*O-E*k)*$,i[7]=(u*O-_*I+b*k)*$,i[8]=(a*te-o*D+l*V)*$,i[9]=(n*D-t*te-s*V)*$,i[10]=(w*M-L*I+E*T)*$,i[11]=(f*I-u*M-b*T)*$,i[12]=(o*F-a*W-c*V)*$,i[13]=(t*W-n*F+r*V)*$,i[14]=(L*k-w*C-S*T)*$,i[15]=(u*C-f*k+_*T)*$,i):null}function Rr(i){let e=i[0],t=i[1],n=i[2],r=i[3],s=i[4],a=i[5],o=i[6],c=i[7],l=i[8],u=i[9],f=i[10],_=i[11],b=i[12],w=i[13],L=i[14],S=i[15],E=e*a-t*s,T=e*o-n*s,k=t*o-n*a,I=l*w-u*b,C=l*L-f*b,M=u*L-f*w,O=e*M-t*C+n*I,V=s*M-a*C+o*I,F=l*k-u*T+f*E,D=b*k-w*T+L*E;return c*O-r*V+S*F-_*D}function Mn(i,e,t){let n=e[0],r=e[1],s=e[2],a=e[3],o=e[4],c=e[5],l=e[6],u=e[7],f=e[8],_=e[9],b=e[10],w=e[11],L=e[12],S=e[13],E=e[14],T=e[15],k=t[0],I=t[1],C=t[2],M=t[3];return i[0]=k*n+I*o+C*f+M*L,i[1]=k*r+I*c+C*_+M*S,i[2]=k*s+I*l+C*b+M*E,i[3]=k*a+I*u+C*w+M*T,k=t[4],I=t[5],C=t[6],M=t[7],i[4]=k*n+I*o+C*f+M*L,i[5]=k*r+I*c+C*_+M*S,i[6]=k*s+I*l+C*b+M*E,i[7]=k*a+I*u+C*w+M*T,k=t[8],I=t[9],C=t[10],M=t[11],i[8]=k*n+I*o+C*f+M*L,i[9]=k*r+I*c+C*_+M*S,i[10]=k*s+I*l+C*b+M*E,i[11]=k*a+I*u+C*w+M*T,k=t[12],I=t[13],C=t[14],M=t[15],i[12]=k*n+I*o+C*f+M*L,i[13]=k*r+I*c+C*_+M*S,i[14]=k*s+I*l+C*b+M*E,i[15]=k*a+I*u+C*w+M*T,i}function Dr(i,e,t){let n=t[0],r=t[1],s=t[2],a,o,c,l,u,f,_,b,w,L,S,E;return e===i?(i[12]=e[0]*n+e[4]*r+e[8]*s+e[12],i[13]=e[1]*n+e[5]*r+e[9]*s+e[13],i[14]=e[2]*n+e[6]*r+e[10]*s+e[14],i[15]=e[3]*n+e[7]*r+e[11]*s+e[15]):(a=e[0],o=e[1],c=e[2],l=e[3],u=e[4],f=e[5],_=e[6],b=e[7],w=e[8],L=e[9],S=e[10],E=e[11],i[0]=a,i[1]=o,i[2]=c,i[3]=l,i[4]=u,i[5]=f,i[6]=_,i[7]=b,i[8]=w,i[9]=L,i[10]=S,i[11]=E,i[12]=a*n+u*r+w*s+e[12],i[13]=o*n+f*r+L*s+e[13],i[14]=c*n+_*r+S*s+e[14],i[15]=l*n+b*r+E*s+e[15]),i}function Fr(i,e,t){let n=t[0],r=t[1],s=t[2];return i[0]=e[0]*n,i[1]=e[1]*n,i[2]=e[2]*n,i[3]=e[3]*n,i[4]=e[4]*r,i[5]=e[5]*r,i[6]=e[6]*r,i[7]=e[7]*r,i[8]=e[8]*s,i[9]=e[9]*s,i[10]=e[10]*s,i[11]=e[11]*s,i[12]=e[12],i[13]=e[13],i[14]=e[14],i[15]=e[15],i}function Br(i,e,t,n){let r=n[0],s=n[1],a=n[2],o=Math.sqrt(r*r+s*s+a*a),c,l,u,f,_,b,w,L,S,E,T,k,I,C,M,O,V,F,D,W,te,j,$,Be;return o<1e-6?null:(o=1/o,r*=o,s*=o,a*=o,l=Math.sin(t),c=Math.cos(t),u=1-c,f=e[0],_=e[1],b=e[2],w=e[3],L=e[4],S=e[5],E=e[6],T=e[7],k=e[8],I=e[9],C=e[10],M=e[11],O=r*r*u+c,V=s*r*u+a*l,F=a*r*u-s*l,D=r*s*u-a*l,W=s*s*u+c,te=a*s*u+r*l,j=r*a*u+s*l,$=s*a*u-r*l,Be=a*a*u+c,i[0]=f*O+L*V+k*F,i[1]=_*O+S*V+I*F,i[2]=b*O+E*V+C*F,i[3]=w*O+T*V+M*F,i[4]=f*D+L*W+k*te,i[5]=_*D+S*W+I*te,i[6]=b*D+E*W+C*te,i[7]=w*D+T*W+M*te,i[8]=f*j+L*$+k*Be,i[9]=_*j+S*$+I*Be,i[10]=b*j+E*$+C*Be,i[11]=w*j+T*$+M*Be,e!==i&&(i[12]=e[12],i[13]=e[13],i[14]=e[14],i[15]=e[15]),i)}function Vr(i,e,t){let n=Math.sin(t),r=Math.cos(t),s=e[4],a=e[5],o=e[6],c=e[7],l=e[8],u=e[9],f=e[10],_=e[11];return e!==i&&(i[0]=e[0],i[1]=e[1],i[2]=e[2],i[3]=e[3],i[12]=e[12],i[13]=e[13],i[14]=e[14],i[15]=e[15]),i[4]=s*r+l*n,i[5]=a*r+u*n,i[6]=o*r+f*n,i[7]=c*r+_*n,i[8]=l*r-s*n,i[9]=u*r-a*n,i[10]=f*r-o*n,i[11]=_*r-c*n,i}function $r(i,e,t){let n=Math.sin(t),r=Math.cos(t),s=e[0],a=e[1],o=e[2],c=e[3],l=e[8],u=e[9],f=e[10],_=e[11];return e!==i&&(i[4]=e[4],i[5]=e[5],i[6]=e[6],i[7]=e[7],i[12]=e[12],i[13]=e[13],i[14]=e[14],i[15]=e[15]),i[0]=s*r-l*n,i[1]=a*r-u*n,i[2]=o*r-f*n,i[3]=c*r-_*n,i[8]=s*n+l*r,i[9]=a*n+u*r,i[10]=o*n+f*r,i[11]=c*n+_*r,i}function Ur(i,e,t){let n=Math.sin(t),r=Math.cos(t),s=e[0],a=e[1],o=e[2],c=e[3],l=e[4],u=e[5],f=e[6],_=e[7];return e!==i&&(i[8]=e[8],i[9]=e[9],i[10]=e[10],i[11]=e[11],i[12]=e[12],i[13]=e[13],i[14]=e[14],i[15]=e[15]),i[0]=s*r+l*n,i[1]=a*r+u*n,i[2]=o*r+f*n,i[3]=c*r+_*n,i[4]=l*r-s*n,i[5]=u*r-a*n,i[6]=f*r-o*n,i[7]=_*r-c*n,i}function zr(i,e){let t=e[0],n=e[1],r=e[2],s=e[3],a=t+t,o=n+n,c=r+r,l=t*a,u=n*a,f=n*o,_=r*a,b=r*o,w=r*c,L=s*a,S=s*o,E=s*c;return i[0]=1-f-w,i[1]=u+E,i[2]=_-S,i[3]=0,i[4]=u-E,i[5]=1-l-w,i[6]=b+L,i[7]=0,i[8]=_+S,i[9]=b-L,i[10]=1-l-f,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i}function Wr(i,e,t,n,r,s,a){let o=1/(t-e),c=1/(r-n),l=1/(s-a);return i[0]=s*2*o,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=s*2*c,i[6]=0,i[7]=0,i[8]=(t+e)*o,i[9]=(r+n)*c,i[10]=(a+s)*l,i[11]=-1,i[12]=0,i[13]=0,i[14]=a*s*2*l,i[15]=0,i}function bi(i,e,t,n,r){let s=1/Math.tan(e/2);if(i[0]=s/t,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=s,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[11]=-1,i[12]=0,i[13]=0,i[15]=0,r!=null&&r!==1/0){let a=1/(n-r);i[10]=(r+n)*a,i[14]=2*r*n*a}else i[10]=-1,i[14]=-2*n;return i}var Hr=bi;function yi(i,e,t,n,r,s,a){let o=1/(e-t),c=1/(n-r),l=1/(s-a);return i[0]=-2*o,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=-2*c,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[10]=2*l,i[11]=0,i[12]=(e+t)*o,i[13]=(r+n)*c,i[14]=(a+s)*l,i[15]=1,i}var Gr=yi;function qr(i,e,t,n){let r,s,a,o,c,l,u,f,_,b,w=e[0],L=e[1],S=e[2],E=n[0],T=n[1],k=n[2],I=t[0],C=t[1],M=t[2];return Math.abs(w-I)<1e-6&&Math.abs(L-C)<1e-6&&Math.abs(S-M)<1e-6?vi(i):(f=w-I,_=L-C,b=S-M,r=1/Math.sqrt(f*f+_*_+b*b),f*=r,_*=r,b*=r,s=T*b-k*_,a=k*f-E*b,o=E*_-T*f,r=Math.sqrt(s*s+a*a+o*o),r?(r=1/r,s*=r,a*=r,o*=r):(s=0,a=0,o=0),c=_*o-b*a,l=b*s-f*o,u=f*a-_*s,r=Math.sqrt(c*c+l*l+u*u),r?(r=1/r,c*=r,l*=r,u*=r):(c=0,l=0,u=0),i[0]=s,i[1]=c,i[2]=f,i[3]=0,i[4]=a,i[5]=l,i[6]=_,i[7]=0,i[8]=o,i[9]=u,i[10]=b,i[11]=0,i[12]=-(s*w+a*L+o*S),i[13]=-(c*w+l*L+u*S),i[14]=-(f*w+_*L+b*S),i[15]=1,i)}function wi(){let i=new me(4);return me!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0,i[3]=0),i}function jr(i,e,t){let n=e[0],r=e[1],s=e[2],a=e[3];return i[0]=t[0]*n+t[4]*r+t[8]*s+t[12]*a,i[1]=t[1]*n+t[5]*r+t[9]*s+t[13]*a,i[2]=t[2]*n+t[6]*r+t[10]*s+t[14]*a,i[3]=t[3]*n+t[7]*r+t[11]*s+t[15]*a,i}var pa=function(){let i=wi();return function(e,t,n,r,s,a){let o,c;for(t||(t=4),n||(n=0),r?c=Math.min(r*t+n,e.length):c=e.length,o=n;o<c;o+=t)i[0]=e[o],i[1]=e[o+1],i[2]=e[o+2],i[3]=e[o+3],s(i,i,a),e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3];return e}}();var On;(function(i){i[i.COL0ROW0=0]="COL0ROW0",i[i.COL0ROW1=1]="COL0ROW1",i[i.COL0ROW2=2]="COL0ROW2",i[i.COL0ROW3=3]="COL0ROW3",i[i.COL1ROW0=4]="COL1ROW0",i[i.COL1ROW1=5]="COL1ROW1",i[i.COL1ROW2=6]="COL1ROW2",i[i.COL1ROW3=7]="COL1ROW3",i[i.COL2ROW0=8]="COL2ROW0",i[i.COL2ROW1=9]="COL2ROW1",i[i.COL2ROW2=10]="COL2ROW2",i[i.COL2ROW3=11]="COL2ROW3",i[i.COL3ROW0=12]="COL3ROW0",i[i.COL3ROW1=13]="COL3ROW1",i[i.COL3ROW2=14]="COL3ROW2",i[i.COL3ROW3=15]="COL3ROW3"})(On||(On={}));var ki=45*Math.PI/180,Ii=1,Cn=.1,Nn=500,Si=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),Ie=class extends qt{static get IDENTITY(){return Li()}static get ZERO(){return Ai()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return On}constructor(e){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(e)?this.copy(e):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this[9]=e[9],this[10]=e[10],this[11]=e[11],this[12]=e[12],this[13]=e[13],this[14]=e[14],this[15]=e[15],this.check()}set(e,t,n,r,s,a,o,c,l,u,f,_,b,w,L,S){return this[0]=e,this[1]=t,this[2]=n,this[3]=r,this[4]=s,this[5]=a,this[6]=o,this[7]=c,this[8]=l,this[9]=u,this[10]=f,this[11]=_,this[12]=b,this[13]=w,this[14]=L,this[15]=S,this.check()}setRowMajor(e,t,n,r,s,a,o,c,l,u,f,_,b,w,L,S){return this[0]=e,this[1]=s,this[2]=l,this[3]=b,this[4]=t,this[5]=a,this[6]=u,this[7]=w,this[8]=n,this[9]=o,this[10]=f,this[11]=L,this[12]=r,this[13]=c,this[14]=_,this[15]=S,this.check()}toRowMajor(e){return e[0]=this[0],e[1]=this[4],e[2]=this[8],e[3]=this[12],e[4]=this[1],e[5]=this[5],e[6]=this[9],e[7]=this[13],e[8]=this[2],e[9]=this[6],e[10]=this[10],e[11]=this[14],e[12]=this[3],e[13]=this[7],e[14]=this[11],e[15]=this[15],e}identity(){return this.copy(Si)}fromObject(e){return this.check()}fromQuaternion(e){return zr(this,e),this.check()}frustum(e){let{left:t,right:n,bottom:r,top:s,near:a=Cn,far:o=Nn}=e;return o===1/0?Ti(this,t,n,r,s,a):Wr(this,t,n,r,s,a,o),this.check()}lookAt(e){let{eye:t,center:n=[0,0,0],up:r=[0,1,0]}=e;return qr(this,t,n,r),this.check()}ortho(e){let{left:t,right:n,bottom:r,top:s,near:a=Cn,far:o=Nn}=e;return Gr(this,t,n,r,s,a,o),this.check()}orthographic(e){let{fovy:t=ki,aspect:n=Ii,focalDistance:r=1,near:s=Cn,far:a=Nn}=e;Xr(t);let o=t/2,c=r*Math.tan(o),l=c*n;return this.ortho({left:-l,right:l,bottom:-c,top:c,near:s,far:a})}perspective(e){let{fovy:t=45*Math.PI/180,aspect:n=1,near:r=.1,far:s=500}=e;return Xr(t),Hr(this,t,n,r,s),this.check()}determinant(){return Rr(this)}getScale(e=[-0,-0,-0]){return e[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),e[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),e[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),e}getTranslation(e=[-0,-0,-0]){return e[0]=this[12],e[1]=this[13],e[2]=this[14],e}getRotation(e,t){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],t=t||[-0,-0,-0];let n=this.getScale(t),r=1/n[0],s=1/n[1],a=1/n[2];return e[0]=this[0]*r,e[1]=this[1]*s,e[2]=this[2]*a,e[3]=0,e[4]=this[4]*r,e[5]=this[5]*s,e[6]=this[6]*a,e[7]=0,e[8]=this[8]*r,e[9]=this[9]*s,e[10]=this[10]*a,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}getRotationMatrix3(e,t){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0],t=t||[-0,-0,-0];let n=this.getScale(t),r=1/n[0],s=1/n[1],a=1/n[2];return e[0]=this[0]*r,e[1]=this[1]*s,e[2]=this[2]*a,e[3]=this[4]*r,e[4]=this[5]*s,e[5]=this[6]*a,e[6]=this[8]*r,e[7]=this[9]*s,e[8]=this[10]*a,e}transpose(){return Or(this,this),this.check()}invert(){return Pr(this,this),this.check()}multiplyLeft(e){return Mn(this,e,this),this.check()}multiplyRight(e){return Mn(this,this,e),this.check()}rotateX(e){return Vr(this,this,e),this.check()}rotateY(e){return $r(this,this,e),this.check()}rotateZ(e){return Ur(this,this,e),this.check()}rotateXYZ(e){return this.rotateX(e[0]).rotateY(e[1]).rotateZ(e[2])}rotateAxis(e,t){return Br(this,this,e,t),this.check()}scale(e){return Fr(this,this,Array.isArray(e)?e:[e,e,e]),this.check()}translate(e){return Dr(this,this,e),this.check()}transform(e,t){return e.length===4?(t=jr(t||[-0,-0,-0,-0],e,this),Gt(t,4),t):this.transformAsPoint(e,t)}transformAsPoint(e,t){let{length:n}=e,r;switch(n){case 2:r=Er(t||[-0,-0],e,this);break;case 3:r=Nr(t||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return Gt(r,e.length),r}transformAsVector(e,t){let n;switch(e.length){case 2:n=Mr(t||[-0,-0],e,this);break;case 3:n=Cr(t||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return Gt(n,e.length),n}transformPoint(e,t){return this.transformAsPoint(e,t)}transformVector(e,t){return this.transformAsPoint(e,t)}transformDirection(e,t){return this.transformAsVector(e,t)}makeRotationX(e){return this.identity().rotateX(e)}makeTranslation(e,t,n){return this.identity().translate([e,t,n])}},jt,Xt;function Ai(){return jt||(jt=new Ie([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(jt)),jt}function Li(){return Xt||(Xt=new Ie,Object.freeze(Xt)),Xt}function Xr(i){if(i>Math.PI*2)throw Error("expected radians")}function Ti(i,e,t,n,r,s){let a=2*s/(t-e),o=2*s/(r-n),c=(t+e)/(t-e),l=(r+n)/(r-n),u=-1,f=-1,_=-2*s;return i[0]=a,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=o,i[6]=0,i[7]=0,i[8]=c,i[9]=l,i[10]=u,i[11]=f,i[12]=0,i[13]=0,i[14]=_,i[15]=0,i}var Se=null,Yr=new ArrayBuffer(4),Kr=new Float32Array(Yr),Zr=new Uint32Array(Yr);function Qr(i){Se||=es(),i=Tn(i,-65504,65504),Kr[0]=i;let e=Zr[0],t=e>>23&511;return Se.baseTable[t]+((e&8388607)>>Se.shiftTable[t])}function Jr(i){Se||=es();let e=i>>10;return Zr[0]=Se.mantissaTable[Se.offsetTable[e]+(i&1023)]+Se.exponentTable[e],Kr[0]}function es(){let i=new Uint32Array(512),e=new Uint32Array(512);for(let s=0;s<256;++s){let a=s-127;a<-27?(i[s]=0,i[s|256]=32768,e[s]=24,e[s|256]=24):a<-14?(i[s]=1024>>-a-14,i[s|256]=1024>>-a-14|32768,e[s]=-a-1,e[s|256]=-a-1):a<=15?(i[s]=a+15<<10,i[s|256]=a+15<<10|32768,e[s]=13,e[s|256]=13):a<128?(i[s]=31744,i[s|256]=64512,e[s]=24,e[s|256]=24):(i[s]=31744,i[s|256]=64512,e[s]=13,e[s|256]=13)}let t=new Uint32Array(2048),n=new Uint32Array(64),r=new Uint32Array(64);for(let s=1;s<1024;++s){let a=s<<13,o=0;for(;!(a&8388608);)a<<=1,o-=8388608;a&=-8388609,o+=947912704,t[s]=a|o}for(let s=1024;s<2048;++s)t[s]=939524096+(s-1024<<13);for(let s=1;s<31;++s)n[s]=s<<23;n[31]=1199570944,n[32]=2147483648;for(let s=33;s<63;++s)n[s]=2147483648+(s-32<<23);n[63]=3347054592;for(let s=1;s<64;++s)s!==32&&(r[s]=1024);return{baseTable:i,shiftTable:e,mantissaTable:t,exponentTable:n,offsetTable:r}}function Fe(i,e=[],t=0){let n=Math.fround(i),r=i-n;return e[t]=n,e[t+1]=r,e}function rt(i){return i-Math.fround(i)}function st(i){let e=new Float32Array(32);for(let t=0;t<4;++t)for(let n=0;n<4;++n){let r=t*4+n;Fe(i[n*4+t],e,r*2)}return e}var Ei=`float random(vec3 scale, float seed) {
|
|
104
105
|
/* use the fragment position for a different seed per-pixel */
|
|
105
106
|
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
|
|
106
107
|
}
|
|
107
|
-
`,
|
|
108
|
+
`,ts={name:"random",fs:Ei};var Mi=`#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
|
|
108
109
|
|
|
109
110
|
// All these functions are for substituting tan() function from Intel GPU only
|
|
110
111
|
const float TWO_PI = 6.2831854820251465;
|
|
@@ -254,7 +255,7 @@ float tan_fp32(float a) {
|
|
|
254
255
|
return tan(a);
|
|
255
256
|
#endif
|
|
256
257
|
}
|
|
257
|
-
`,
|
|
258
|
+
`,ns={name:"fp32",vs:Mi};var rs=`
|
|
258
259
|
uniform fp64arithmeticUniforms {
|
|
259
260
|
uniform float ONE;
|
|
260
261
|
} fp64;
|
|
@@ -422,7 +423,7 @@ vec2 sqrt_fp64(vec2 a) {
|
|
|
422
423
|
return sum_fp64(vec2(yn, 0.0), prod);
|
|
423
424
|
#endif
|
|
424
425
|
}
|
|
425
|
-
`;var
|
|
426
|
+
`;var ss=`const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
|
|
426
427
|
const vec2 LOG2_FP64 = vec2(0.6931471824645996e+00, -1.9046542121259336e-09);
|
|
427
428
|
const vec2 PI_FP64 = vec2(3.1415927410125732, -8.742278012618954e-8);
|
|
428
429
|
const vec2 TWO_PI_FP64 = vec2(6.2831854820251465, -1.7484556025237907e-7);
|
|
@@ -1091,7 +1092,7 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
|
|
|
1091
1092
|
vec4_dot_fp64(a, tmp, out_val[i]);
|
|
1092
1093
|
}
|
|
1093
1094
|
}
|
|
1094
|
-
`;var
|
|
1095
|
+
`;var Ci={ONE:1},Pn={name:"fp64arithmetic",vs:rs,defaultUniforms:Ci,uniformTypes:{ONE:"f32"},fp64ify:Fe,fp64LowPart:rt,fp64ifyMatrix4:st},is={name:"fp64",vs:ss,dependencies:[Pn],fp64ify:Fe,fp64LowPart:rt,fp64ifyMatrix4:st};var Ni=[0,1,1,1],Oi=`uniform pickingUniforms {
|
|
1095
1096
|
float isActive;
|
|
1096
1097
|
float isAttribute;
|
|
1097
1098
|
float isHighlightActive;
|
|
@@ -1162,7 +1163,7 @@ void picking_setPickingAttribute(vec3 value) {
|
|
|
1162
1163
|
picking_vRGBcolor_Avalid.rgb = value;
|
|
1163
1164
|
}
|
|
1164
1165
|
}
|
|
1165
|
-
`,
|
|
1166
|
+
`,Pi=`uniform pickingUniforms {
|
|
1166
1167
|
float isActive;
|
|
1167
1168
|
float isAttribute;
|
|
1168
1169
|
float isHighlightActive;
|
|
@@ -1218,7 +1219,7 @@ vec4 picking_filterColor(vec4 color) {
|
|
|
1218
1219
|
vec4 highlightColor = picking_filterHighlightColor(color);
|
|
1219
1220
|
return picking_filterPickingColor(highlightColor);
|
|
1220
1221
|
}
|
|
1221
|
-
`,
|
|
1222
|
+
`,os={props:{},uniforms:{},name:"picking",uniformTypes:{isActive:"f32",isAttribute:"f32",isHighlightActive:"f32",useFloatColors:"f32",highlightedObjectColor:"vec3<f32>",highlightColor:"vec4<f32>"},defaultUniforms:{isActive:!1,isAttribute:!1,isHighlightActive:!1,useFloatColors:!0,highlightedObjectColor:[0,0,0],highlightColor:Ni},vs:Oi,fs:Pi,getUniforms:Ri};function Ri(i={},e){let t={};if(i.highlightedObjectColor!==void 0)if(i.highlightedObjectColor===null)t.isHighlightActive=!1;else{t.isHighlightActive=!0;let n=i.highlightedObjectColor.slice(0,3);t.highlightedObjectColor=n}if(i.highlightColor){let n=Array.from(i.highlightColor,r=>r/255);Number.isFinite(n[3])||(n[3]=1),t.highlightColor=n}return i.isActive!==void 0&&(t.isActive=Boolean(i.isActive),t.isAttribute=Boolean(i.isAttribute)),i.useFloatColors!==void 0&&(t.useFloatColors=Boolean(i.useFloatColors)),t}var cs=Jt(lt(),1);var Rn=`precision highp int;
|
|
1222
1223
|
|
|
1223
1224
|
// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
1224
1225
|
struct AmbientLight {
|
|
@@ -1292,7 +1293,7 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
|
1292
1293
|
}
|
|
1293
1294
|
|
|
1294
1295
|
// #endif
|
|
1295
|
-
`;var
|
|
1296
|
+
`;var as=`// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
1296
1297
|
struct AmbientLight {
|
|
1297
1298
|
color: vec3<f32>,
|
|
1298
1299
|
};
|
|
@@ -1310,7 +1311,7 @@ struct DirectionalLight {
|
|
|
1310
1311
|
|
|
1311
1312
|
struct lightingUniforms {
|
|
1312
1313
|
enabled: i32,
|
|
1313
|
-
|
|
1314
|
+
pointLightCount: i32,
|
|
1314
1315
|
directionalLightCount: i32,
|
|
1315
1316
|
|
|
1316
1317
|
ambientColor: vec3<f32>,
|
|
@@ -1343,7 +1344,7 @@ fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
|
|
|
1343
1344
|
+ pointLight.attenuation.y * distance
|
|
1344
1345
|
+ pointLight.attenuation.z * distance * distance;
|
|
1345
1346
|
}
|
|
1346
|
-
`;var
|
|
1347
|
+
`;var ls=3,Di=255,it;(function(i){i[i.POINT=0]="POINT",i[i.DIRECTIONAL=1]="DIRECTIONAL"})(it||(it={}));var ce={props:{},uniforms:{},name:"lighting",defines:{MAX_LIGHTS:ls},uniformTypes:{enabled:"i32",lightType:"i32",directionalLightCount:"i32",pointLightCount:"i32",ambientLightColor:"vec3<f32>",lightColor0:"vec3<f32>",lightPosition0:"vec3<f32>",lightDirection0:"vec3<f32>",lightAttenuation0:"vec3<f32>",lightColor1:"vec3<f32>",lightPosition1:"vec3<f32>",lightDirection1:"vec3<f32>",lightAttenuation1:"vec3<f32>",lightColor2:"vec3<f32>",lightPosition2:"vec3<f32>",lightDirection2:"vec3<f32>",lightAttenuation2:"vec3<f32>"},defaultUniforms:{enabled:1,lightType:it.POINT,directionalLightCount:0,pointLightCount:0,ambientLightColor:[.1,.1,.1],lightColor0:[1,1,1],lightPosition0:[1,1,2],lightDirection0:[1,1,1],lightAttenuation0:[1,0,0],lightColor1:[1,1,1],lightPosition1:[1,1,2],lightDirection1:[1,1,1],lightAttenuation1:[1,0,0],lightColor2:[1,1,1],lightPosition2:[1,1,2],lightDirection2:[1,1,1],lightAttenuation2:[1,0,0]},source:as,vs:Rn,fs:Rn,getUniforms:Fi};function Fi(i,e={}){if(i=i&&{...i},!i)return{...ce.defaultUniforms};i.lights&&(i={...i,...Vi(i.lights),lights:void 0});let{ambientLight:t,pointLights:n,directionalLights:r}=i||{};if(!(t||n&&n.length>0||r&&r.length>0))return{...ce.defaultUniforms,enabled:0};let a={...ce.defaultUniforms,...e,...Bi({ambientLight:t,pointLights:n,directionalLights:r})};return i.enabled!==void 0&&(a.enabled=i.enabled?1:0),a}function Bi({ambientLight:i,pointLights:e=[],directionalLights:t=[]}){let n={};n.ambientLightColor=Dn(i);let r=0;for(let s of e){n.lightType=it.POINT;let a=r;n[`lightColor${a}`]=Dn(s),n[`lightPosition${a}`]=s.position,n[`lightAttenuation${a}`]=s.attenuation||[1,0,0],r++}for(let s of t){n.lightType=it.DIRECTIONAL;let a=r;n[`lightColor${a}`]=Dn(s),n[`lightDirection${a}`]=s.direction,r++}return r>ls&&cs.log.warn("MAX_LIGHTS exceeded")(),n.directionalLightCount=t.length,n.pointLightCount=e.length,n}function Vi(i){let e={pointLights:[],directionalLights:[]};for(let t of i||[])switch(t.type){case"ambient":e.ambientLight=t;break;case"directional":e.directionalLights?.push(t);break;case"point":e.pointLights?.push(t);break;default:}return e}function Dn(i={}){let{color:e=[0,0,0],intensity:t=1}=i;return e.map(n=>n*t/Di)}var $i=`
|
|
1347
1348
|
struct dirlightUniforms {
|
|
1348
1349
|
lightDirection: vec3<f32>,
|
|
1349
1350
|
};
|
|
@@ -1369,12 +1370,12 @@ fn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {
|
|
|
1369
1370
|
let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));
|
|
1370
1371
|
return vec4<f32>(color.rgb * d, color.a);
|
|
1371
1372
|
}
|
|
1372
|
-
`,
|
|
1373
|
+
`,Ui=`out vec3 dirlight_vNormal;
|
|
1373
1374
|
|
|
1374
1375
|
void dirlight_setNormal(vec3 normal) {
|
|
1375
1376
|
dirlight_vNormal = normalize(normal);
|
|
1376
1377
|
}
|
|
1377
|
-
`,
|
|
1378
|
+
`,zi=`uniform dirlightUniforms {
|
|
1378
1379
|
vec3 lightDirection;
|
|
1379
1380
|
} dirlight;
|
|
1380
1381
|
|
|
@@ -1385,13 +1386,13 @@ vec4 dirlight_filterColor(vec4 color) {
|
|
|
1385
1386
|
float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));
|
|
1386
1387
|
return vec4(color.rgb * d, color.a);
|
|
1387
1388
|
}
|
|
1388
|
-
`,
|
|
1389
|
+
`,Fn={props:{},uniforms:{},name:"dirlight",dependencies:[],source:$i,vs:Ui,fs:zi,uniformTypes:{lightDirection:"vec3<f32>"},defaultUniforms:{lightDirection:[1,1,2]},getUniforms:Wi};function Wi(i=Fn.defaultUniforms){let e={};return i.lightDirection&&(e.dirlight_uLightDirection=i.lightDirection),e}var Yt=`uniform phongMaterialUniforms {
|
|
1389
1390
|
uniform float ambient;
|
|
1390
1391
|
uniform float diffuse;
|
|
1391
1392
|
uniform float shininess;
|
|
1392
1393
|
uniform vec3 specularColor;
|
|
1393
1394
|
} material;
|
|
1394
|
-
`,
|
|
1395
|
+
`,Kt=`uniform phongMaterialUniforms {
|
|
1395
1396
|
uniform float ambient;
|
|
1396
1397
|
uniform float diffuse;
|
|
1397
1398
|
uniform float shininess;
|
|
@@ -1436,14 +1437,14 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
|
|
|
1436
1437
|
|
|
1437
1438
|
return lightColor;
|
|
1438
1439
|
}
|
|
1439
|
-
`;var
|
|
1440
|
+
`;var Zt=`struct phongMaterialUniforms {
|
|
1440
1441
|
ambient: f32,
|
|
1441
1442
|
diffuse: f32,
|
|
1442
1443
|
shininess: f32,
|
|
1443
1444
|
specularColor: vec3<f32>,
|
|
1444
1445
|
};
|
|
1445
1446
|
|
|
1446
|
-
@binding(2) @group(0) var<uniform>
|
|
1447
|
+
@binding(2) @group(0) var<uniform> phongMaterial : phongMaterialUniforms;
|
|
1447
1448
|
|
|
1448
1449
|
fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, view_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {
|
|
1449
1450
|
let halfway_direction: vec3<f32> = normalize(light_direction + view_direction);
|
|
@@ -1451,10 +1452,10 @@ fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, v
|
|
|
1451
1452
|
var specular: f32 = 0.0;
|
|
1452
1453
|
if (lambertian > 0.0) {
|
|
1453
1454
|
let specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
|
|
1454
|
-
specular = pow(specular_angle,
|
|
1455
|
+
specular = pow(specular_angle, phongMaterial.shininess);
|
|
1455
1456
|
}
|
|
1456
1457
|
lambertian = max(lambertian, 0.0);
|
|
1457
|
-
return (lambertian *
|
|
1458
|
+
return (lambertian * phongMaterial.diffuse * surfaceColor + specular * phongMaterial.specularColor) * color;
|
|
1458
1459
|
}
|
|
1459
1460
|
|
|
1460
1461
|
fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {
|
|
@@ -1465,7 +1466,7 @@ fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, p
|
|
|
1465
1466
|
}
|
|
1466
1467
|
|
|
1467
1468
|
let view_direction: vec3<f32> = normalize(cameraPosition - position_worldspace);
|
|
1468
|
-
lightColor =
|
|
1469
|
+
lightColor = phongMaterial.ambient * surfaceColor * lighting.ambientColor;
|
|
1469
1470
|
|
|
1470
1471
|
if (lighting.lightType == 0) {
|
|
1471
1472
|
let pointLight: PointLight = lighting_getPointLight(0);
|
|
@@ -1521,7 +1522,7 @@ fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace
|
|
|
1521
1522
|
}
|
|
1522
1523
|
return lightColor;
|
|
1523
1524
|
}
|
|
1524
|
-
`;var
|
|
1525
|
+
`;var Bn={props:{},name:"gouraudMaterial",vs:Kt.replace("phongMaterial","gouraudMaterial"),fs:Yt.replace("phongMaterial","gouraudMaterial"),source:Zt.replaceAll("phongMaterial","gouraudMaterial"),defines:{LIGHTING_VERTEX:1},dependencies:[ce],uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(i){let e={...i};return e.specularColor&&(e.specularColor=e.specularColor.map(t=>t/255)),{...Bn.defaultUniforms,...e}}};var Vn={name:"phongMaterial",dependencies:[ce],source:Zt,vs:Yt,fs:Kt,defines:{LIGHTING_FRAGMENT:1},uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(i){let e={...i};return e.specularColor&&(e.specularColor=e.specularColor.map(t=>t/255)),{...Vn.defaultUniforms,...e}}};var us=`out vec3 pbr_vPosition;
|
|
1525
1526
|
out vec2 pbr_vUV;
|
|
1526
1527
|
|
|
1527
1528
|
#ifdef HAS_NORMALS
|
|
@@ -1554,7 +1555,7 @@ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, ve
|
|
|
1554
1555
|
pbr_vUV = vec2(0.,0.);
|
|
1555
1556
|
#endif
|
|
1556
1557
|
}
|
|
1557
|
-
`;var
|
|
1558
|
+
`;var fs=`precision highp float;
|
|
1558
1559
|
|
|
1559
1560
|
uniform pbrMaterialUniforms {
|
|
1560
1561
|
// Material is unlit
|
|
@@ -1955,13 +1956,13 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
1955
1956
|
|
|
1956
1957
|
return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
|
|
1957
1958
|
}
|
|
1958
|
-
`;var
|
|
1959
|
+
`;var hs=`uniform pbrProjectionUniforms {
|
|
1959
1960
|
mat4 modelViewProjectionMatrix;
|
|
1960
1961
|
mat4 modelMatrix;
|
|
1961
1962
|
mat4 normalMatrix;
|
|
1962
1963
|
vec3 camera;
|
|
1963
1964
|
} pbrProjection;
|
|
1964
|
-
`,
|
|
1965
|
+
`,ps={name:"pbrProjection",vs:hs,fs:hs,getUniforms:i=>i,uniformTypes:{modelViewProjectionMatrix:"mat4x4<f32>",modelMatrix:"mat4x4<f32>",normalMatrix:"mat4x4<f32>",camera:"vec3<i32>"}};var ms={props:{},uniforms:{},name:"pbrMaterial",dependencies:[ce,ps],vs:us,fs,defines:{LIGHTING_FRAGMENT:1},getUniforms:i=>i,uniformTypes:{unlit:"i32",baseColorMapEnabled:"i32",baseColorFactor:"vec4<f32>",normalMapEnabled:"i32",normalScale:"f32",emissiveMapEnabled:"i32",emissiveFactor:"vec3<f32>",metallicRoughnessValues:"vec2<f32>",metallicRoughnessMapEnabled:"i32",occlusionMapEnabled:"i32",occlusionStrength:"f32",alphaCutoffEnabled:"i32",alphaCutoff:"f32",IBLenabled:"i32",scaleIBLAmbient:"vec2<f32>",scaleDiffBaseMR:"vec4<f32>",scaleFGDSpec:"vec4<f32>"}};var Hi=`varying vec4 geometry_vPosition;
|
|
1965
1966
|
varying vec3 geometry_vNormal;
|
|
1966
1967
|
|
|
1967
1968
|
void geometry_setNormal(vec3 normal) {
|
|
@@ -1975,7 +1976,7 @@ void geometry_setPosition(vec4 position) {
|
|
|
1975
1976
|
void geometry_setPosition(vec3 position) {
|
|
1976
1977
|
geometry_vPosition = vec4(position, 1.);
|
|
1977
1978
|
}
|
|
1978
|
-
`,
|
|
1979
|
+
`,Gi=`varying vec4 geometry_vPosition;
|
|
1979
1980
|
varying vec3 geometry_vNormal;
|
|
1980
1981
|
|
|
1981
1982
|
vec4 geometry_getPosition() {
|
|
@@ -1985,7 +1986,7 @@ vec4 geometry_getPosition() {
|
|
|
1985
1986
|
vec3 geometry_getNormal() {
|
|
1986
1987
|
return geometry_vNormal;
|
|
1987
1988
|
}
|
|
1988
|
-
`,
|
|
1989
|
+
`,ds={name:"geometry",vs:Hi,fs:Gi};var $n=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],qi={modelMatrix:$n,viewMatrix:$n,projectionMatrix:$n,cameraPositionWorld:[0,0,0]};function ji(i=qi,e={}){let t={};return i.modelMatrix!==void 0&&(t.modelMatrix=i.modelMatrix),i.viewMatrix!==void 0&&(t.viewMatrix=i.viewMatrix),i.projectionMatrix!==void 0&&(t.projectionMatrix=i.projectionMatrix),i.cameraPositionWorld!==void 0&&(t.cameraPositionWorld=i.cameraPositionWorld),i.projectionMatrix!==void 0&&i.viewMatrix!==void 0&&(t.viewProjectionMatrix=new Ie(i.projectionMatrix).multiplyRight(i.viewMatrix)),t}var gs=`varying vec4 project_vPositionWorld;
|
|
1989
1990
|
varying vec3 project_vNormalWorld;
|
|
1990
1991
|
|
|
1991
1992
|
vec4 project_getPosition_World() {
|
|
@@ -1995,7 +1996,7 @@ vec4 project_getPosition_World() {
|
|
|
1995
1996
|
vec3 project_getNormal_World() {
|
|
1996
1997
|
return project_vNormalWorld;
|
|
1997
1998
|
}
|
|
1998
|
-
`,
|
|
1999
|
+
`,Xi=`${gs}
|
|
1999
2000
|
|
|
2000
2001
|
// Unprefixed uniforms
|
|
2001
2002
|
uniform mat4 modelMatrix;
|
|
@@ -2048,8 +2049,8 @@ vec4 project_view_to_clipspace(vec3 position) {
|
|
|
2048
2049
|
vec4 project_to_clipspace(vec3 position) {
|
|
2049
2050
|
return viewProjectionMatrix * vec4(position, 1.);
|
|
2050
2051
|
}
|
|
2051
|
-
`,
|
|
2052
|
-
${
|
|
2052
|
+
`,Yi=`
|
|
2053
|
+
${gs}`,Qt={name:"project",getUniforms:ji,vs:Xi,fs:Yi};var Un=`#if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
2053
2054
|
|
|
2054
2055
|
struct AmbientLight {
|
|
2055
2056
|
vec3 color;
|
|
@@ -2083,7 +2084,7 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
|
2083
2084
|
}
|
|
2084
2085
|
|
|
2085
2086
|
#endif
|
|
2086
|
-
`;var
|
|
2087
|
+
`;var Ki={lightSources:{}};function zn(i={}){let{color:e=[0,0,0],intensity:t=1}=i;return e.map(n=>n*t/255)}function Zi({ambientLight:i,pointLights:e=[],directionalLights:t=[]}){let n={};return i?n["lighting_uAmbientLight.color"]=zn(i):n["lighting_uAmbientLight.color"]=[0,0,0],e.forEach((r,s)=>{n[`lighting_uPointLight[${s}].color`]=zn(r),n[`lighting_uPointLight[${s}].position`]=r.position,n[`lighting_uPointLight[${s}].attenuation`]=r.attenuation||[1,0,0]}),n.lighting_uPointLightCount=e.length,t.forEach((r,s)=>{n[`lighting_uDirectionalLight[${s}].color`]=zn(r),n[`lighting_uDirectionalLight[${s}].direction`]=r.direction}),n.lighting_uDirectionalLightCount=t.length,n}function _s(i=Ki){if("lightSources"in i){let{ambientLight:e,pointLights:t,directionalLights:n}=i.lightSources||{};return e||t&&t.length>0||n&&n.length>0?Object.assign({},Zi({ambientLight:e,pointLights:t,directionalLights:n}),{lighting_uEnabled:!0}):{lighting_uEnabled:!1}}if("lights"in i){let e={pointLights:[],directionalLights:[]};for(let t of i.lights||[])switch(t.type){case"ambient":e.ambientLight=t;break;case"directional":e.directionalLights?.push(t);break;case"point":e.pointLights?.push(t);break;default:}return _s({lightSources:e})}return{}}var Ae={name:"lights",vs:Un,fs:Un,getUniforms:_s,defines:{MAX_LIGHTS:3}};var Qi={lightDirection:new Float32Array([1,1,2])};function Ji(i=Qi){let e={};return i.lightDirection&&(e.dirlight_uLightDirection=i.lightDirection),e}var eo=`uniform vec3 dirlight_uLightDirection;
|
|
2087
2088
|
|
|
2088
2089
|
/*
|
|
2089
2090
|
* Returns color attenuated by angle from light source
|
|
@@ -2093,7 +2094,7 @@ vec4 dirlight_filterColor(vec4 color) {
|
|
|
2093
2094
|
float d = abs(dot(normalize(normal), normalize(dirlight_uLightDirection)));
|
|
2094
2095
|
return vec4(color.rgb * d, color.a);
|
|
2095
2096
|
}
|
|
2096
|
-
`,
|
|
2097
|
+
`,xs={name:"dirlight",fs:eo,getUniforms:Ji,dependencies:[Qt]};var Wn=`
|
|
2097
2098
|
uniform float lighting_uAmbient;
|
|
2098
2099
|
uniform float lighting_uDiffuse;
|
|
2099
2100
|
uniform float lighting_uShininess;
|
|
@@ -2166,7 +2167,7 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
|
|
|
2166
2167
|
}
|
|
2167
2168
|
return lightColor;
|
|
2168
2169
|
}
|
|
2169
|
-
`;var
|
|
2170
|
+
`;var to={};function no(i){let{ambient:e=.35,diffuse:t=.6,shininess:n=32,specularColor:r=[30,30,30]}=i;return{lighting_uAmbient:e,lighting_uDiffuse:t,lighting_uShininess:n,lighting_uSpecularColor:r.map(s=>s/255)}}function vs(i=to){if(!("material"in i))return{};let{material:e}=i;return e?no(e):{lighting_uEnabled:!1}}var bs={name:"gouraud-lighting",dependencies:[Ae],vs:Wn,defines:{LIGHTING_VERTEX:1},getUniforms:vs},ys={name:"phong-lighting",dependencies:[Ae],fs:Wn,defines:{LIGHTING_FRAGMENT:1},getUniforms:vs};var ws=`uniform mat4 u_MVPMatrix;
|
|
2170
2171
|
uniform mat4 u_ModelMatrix;
|
|
2171
2172
|
uniform mat4 u_NormalMatrix;
|
|
2172
2173
|
|
|
@@ -2203,7 +2204,7 @@ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, ve
|
|
|
2203
2204
|
pbr_vUV = vec2(0.,0.);
|
|
2204
2205
|
#endif
|
|
2205
2206
|
}
|
|
2206
|
-
`;var
|
|
2207
|
+
`;var ks=`precision highp float;
|
|
2207
2208
|
|
|
2208
2209
|
uniform bool pbr_uUnlit;
|
|
2209
2210
|
|
|
@@ -2584,6 +2585,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
2584
2585
|
|
|
2585
2586
|
return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
|
|
2586
2587
|
}
|
|
2587
|
-
`;var
|
|
2588
|
+
`;var Is={name:"pbr",vs:ws,fs:ks,defines:{LIGHTING_FRAGMENT:1},dependencies:[Ae],getUniforms:i=>i};return Os(ot);})();
|
|
2588
2589
|
return __exports__;
|
|
2589
2590
|
});
|