e.order-t.order);for(const t of e)n+=` ${t.injection}\n`}i.footer&&(n+=` ${i.footer}`),n+="}\n"}return n}function gr(e){const t={vertex:{},fragment:{}};for(const n of e){let e,r;"string"!=typeof n?(e=n,r=e.hook):(e={},r=n),r=r.trim();const[i,s]=r.split(":"),o=r.replace(/\(.+/,""),a=Object.assign(e,{signature:s});switch(i){case"vs":t.vertex[o]=a;break;case"fs":t.fragment[o]=a;break;default:throw new Error(i)}}return t}function mr(e,t="unnamed"){const n=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(e);return n?n[1]:t}function _r(e){let t=100;const n=e.match(/[^\s]+/g);if(n&&n.length>=2&&"#version"===n[0]){const e=parseInt(n[1],10);Number.isFinite(e)&&(t=e)}if(100!==t&&300!==t)throw new Error(`Invalid GLSL version ${t}`);return t}const br=`\n\n${tr}\n`;function vr(e,t){var n;const{source:r,stage:i,modules:s,hookFunctions:o=[],inject:a={},log:A}=t;Xn("string"==typeof r,"shader source must be a string");const l=r;let c="";const u=gr(o),h={},d={},f={};for(const g in a){const e="string"==typeof a[g]?{injection:a[g],order:0}:a[g],t=/^(v|f)s:(#)?([\w-]+)$/.exec(g);if(t){const n=t[2],r=t[3];n?"decl"===r?d[g]=[e]:f[g]=[e]:h[g]=[e]}else f[g]=[e]}const p=s;for(const g of p){A&&or(g,l,A),c+=xr(g,"wgsl");const e=(null==(n=g.injections)?void 0:n[i])||{};for(const t in e){const n=/^(v|f)s:#([\w-]+)$/.exec(t);if(n){const r="decl"===n[2]?d:f;r[t]=r[t]||[],r[t].push(e[t])}else h[t]=h[t]||[],h[t].push(e[t])}}return c+=br,c=ir(c,i,d),c+=pr(u[i],h),c+=l,c=ir(c,i,f),c}function yr(e,t){var n;const{source:r,stage:i,language:s="glsl",modules:o,defines:a={},hookFunctions:A=[],inject:l={},prologue:c=!0,log:u}=t;Xn("string"==typeof r,"shader source must be a string");const h="glsl"===s?function(e){return{name:mr(e,void 0),language:"glsl",version:_r(e)}}(r).version:-1,d=e.shaderLanguageVersion,f=100===h?"#version 100":"#version 300 es",p=r.split("\n").slice(1).join("\n"),g={};o.forEach(e=>{Object.assign(g,e.defines)}),Object.assign(g,a);let m="";switch(s){case"wgsl":break;case"glsl":m=c?`${f}\n\n// ----- PROLOGUE -------------------------\n#define SHADER_TYPE_${i.toUpperCase()}\n\n${function(e){switch(null==e?void 0:e.gpu.toLowerCase()){case"apple":return"#define APPLE_GPU\n// Apple optimizes away the calculation necessary for emulated fp64\n#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1\n#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1\n// Intel GPU doesn't have full 32 bits precision in same cases, causes overflow\n#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1\n";case"nvidia":return"#define NVIDIA_GPU\n// Nvidia optimizes away the calculation necessary for emulated fp64\n#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1\n";case"intel":return"#define INTEL_GPU\n// Intel optimizes away the calculation necessary for emulated fp64\n#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1\n// Intel's built-in 'tan' function doesn't have acceptable precision\n#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1\n// Intel GPU doesn't have full 32 bits precision in same cases, causes overflow\n#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1\n";case"amd":return"#define AMD_GPU\n";default:return"#define DEFAULT_GPU\n// Prevent driver from optimizing away the calculation necessary for emulated fp64\n#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1\n// Headless Chrome's software shader 'tan' function doesn't have acceptable precision\n#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1\n// If the GPU doesn't have full 32 bits precision, will causes overflow\n#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1\n"}}(e)}\n${"fragment"===i?"precision highp float;\n":""}\n\n// ----- APPLICATION DEFINES -------------------------\n\n${function(e={}){let t="";for(const n in e){const r=e[n];(r||Number.isFinite(r))&&(t+=`#define ${n.toUpperCase()} ${e[n]}\n`)}return t}(g)}\n\n`:`${f}\n`}const _=gr(A),b={},v={},y={};for(const w in l){const e="string"==typeof l[w]?{injection:l[w],order:0}:l[w],t=/^(v|f)s:(#)?([\w-]+)$/.exec(w);if(t){const n=t[2],r=t[3];n?"decl"===r?v[w]=[e]:y[w]=[e]:b[w]=[e]}else y[w]=[e]}for(const w of o){u&&or(w,p,u),m+=xr(w,i);const e=(null==(n=w.instance)?void 0:n.normalizedInjections[i])||{};for(const t in e){const n=/^(v|f)s:#([\w-]+)$/.exec(t);if(n){const r="decl"===n[2]?v:y;r[t]=r[t]||[],r[t].push(e[t])}else b[t]=b[t]||[],b[t].push(e[t])}}return m+="// ----- MAIN SHADER SOURCE -------------------------",m+=br,m=ir(m,i,v),m+=pr(_[i],b),m+=p,m=ir(m,i,y),"glsl"===s&&h!==d&&(m=function(e,t){var n;if(300!==Number((null==(n=e.match(/^#version[ \t]+(\d+)/m))?void 0:n[1])||100))throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");switch(t){case"vertex":return dr(e,ur);case"fragment":return dr(e,hr);default:throw new Error(t)}}(m,i)),m.trim()}function wr(e){return function(t){var n;const r={};for(const i of e){const e=null==(n=i.getUniforms)?void 0:n.call(i,t,r);Object.assign(r,e)}return r}}function xr(e,t){let n;switch(t){case"vertex":n=e.vs||"";break;case"fragment":n=e.fs||"";break;case"wgsl":n=e.source||"";break;default:Xn(!1)}if(!e.name)throw new Error("Shader module must have a name");const r=e.name.toUpperCase().replace(/[^0-9a-z]/gi,"_");let i=`// ----- MODULE ${e.name} ---------------\n\n`;return"wgsl"!==t&&(i+=`#define MODULE_${r}\n`),i+=`${n}\n`,i}const Er=/^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/,Tr=/^\s*\#\s*endif\s*$/,Sr=class e{constructor(){r(this,"_hookFunctions",[]),r(this,"_defaultModules",[])}static getDefaultShaderAssembler(){return e.defaultShaderAssembler=e.defaultShaderAssembler||new e,e.defaultShaderAssembler}addDefaultModule(e){this._defaultModules.find(t=>t.name===("string"==typeof e?e:e.name))||this._defaultModules.push(e)}removeDefaultModule(e){const t="string"==typeof e?e:e.name;this._defaultModules=this._defaultModules.filter(e=>e.name!==t)}addShaderHook(e,t){t&&(e=Object.assign(t,{hook:e})),this._hookFunctions.push(e)}assembleWGSLShader(e){const t=this._getModuleList(e.modules),n=this._hookFunctions,{source:r,getUniforms:i}=function(e){const t=Ar(e.modules||[]);return{source:vr(e.platformInfo,{...e,source:e.source,stage:"vertex",modules:t}),getUniforms:wr(t)}}({...e,source:e.source,modules:t,hookFunctions:n}),s="wgsl"===e.platformInfo.shaderLanguage?function(e){const t=e.split("\n"),n=[];let r=!0,i=null;for(const s of t){const e=s.match(Er),t=s.match(Tr);e?(i=e[1],r=Boolean(null==void 0?void 0:undefined[i])):t?r=!0:r&&n.push(s)}return n.join("\n")}(r):r;return{source:s,getUniforms:i,modules:t}}assembleGLSLShaderPair(e){const t=this._getModuleList(e.modules),n=this._hookFunctions,r=function(e){const{vs:t,fs:n}=e,r=Ar(e.modules||[]);return{vs:yr(e.platformInfo,{...e,source:t,stage:"vertex",modules:r}),fs:yr(e.platformInfo,{...e,source:n,stage:"fragment",modules:r}),getUniforms:wr(r)}}({...e,vs:e.vs,fs:e.fs,modules:t,hookFunctions:n});return{...r,modules:t}}_getModuleList(e=[]){const t=new Array(this._defaultModules.length+e.length),n={};let r=0;for(let i=0,s=this._defaultModules.length;it===e[4]);if(!n)throw new Error(t.name);return n[0]}function Ur(e){const[,,,,t]=jr[e];return t}const jr={uint8:["uint8","u32",1,!1,Uint8Array],sint8:["sint8","i32",1,!1,Int8Array],unorm8:["uint8","f32",1,!0,Uint8Array],snorm8:["sint8","f32",1,!0,Int8Array],uint16:["uint16","u32",2,!1,Uint16Array],sint16:["sint16","i32",2,!1,Int16Array],unorm16:["uint16","u32",2,!0,Uint16Array],snorm16:["sint16","i32",2,!0,Int16Array],float16:["float16","f16",2,!1,Uint16Array],float32:["float32","f32",4,!1,Float32Array],uint32:["uint32","u32",4,!1,Uint32Array],sint32:["sint32","i32",4,!1,Int32Array]};function Gr(e){let t;e.endsWith("-webgl")&&(e.replace("-webgl",""),t=!0);const[n,r]=e.split("x"),i=n,s=r?parseInt(r):1,o=Dr(i),a={type:i,components:s,byteLength:o.byteLength*s,integer:o.integer,signed:o.signed,normalized:o.normalized};return t&&(a.webglOnly=!0),a}function zr(e,t,n){if(!t||t>4)throw new Error(`size ${t}`);const r=t;return function(e,t,n){const r=n?function(e){const t=e;switch(t){case"uint8":return"unorm8";case"sint8":return"snorm8";case"uint16":return"unorm16";case"sint16":return"snorm16";default:return t}}(e):e;switch(r){case"unorm8":return 1===t?"unorm8":3===t?"unorm8x3-webgl":`${r}x${t}`;case"snorm8":case"uint8":case"sint8":case"uint16":case"sint16":case"unorm16":case"snorm16":case"float16":if(1===t||3===t)throw new Error(`size: ${t}`);return`${r}x${t}`;default:return 1===t?r:`${r}x${t}`}}(Fr(e),r,n)}const Vr="texture-compression-bc",Wr="texture-compression-astc",Hr="texture-compression-etc2",$r="texture-compression-pvrtc-webgl",Xr="texture-compression-atc-webgl",Qr="float32-renderable-webgl",Yr="float16-renderable-webgl",qr="snorm8-renderable-webgl",Kr="norm16-renderable-webgl",Zr="snorm16-renderable-webgl",Jr="float32-filterable",ei="float16-filterable-webgl";function ti(e){const t=ni[e];if(!t)throw new Error(`Unsupported texture format ${e}`);return t}const ni={r8unorm:{},rg8unorm:{},"rgb8unorm-webgl":{},rgba8unorm:{},"rgba8unorm-srgb":{},r8snorm:{render:qr},rg8snorm:{render:qr},"rgb8snorm-webgl":{},rgba8snorm:{render:qr},r8uint:{},rg8uint:{},rgba8uint:{},r8sint:{},rg8sint:{},rgba8sint:{},bgra8unorm:{},"bgra8unorm-srgb":{},r16unorm:{f:Kr},rg16unorm:{render:Kr},"rgb16unorm-webgl":{f:Kr},rgba16unorm:{render:Kr},r16snorm:{f:Zr},rg16snorm:{render:Zr},"rgb16snorm-webgl":{f:Kr},rgba16snorm:{render:Zr},r16uint:{},rg16uint:{},rgba16uint:{},r16sint:{},rg16sint:{},rgba16sint:{},r16float:{render:Yr,filter:"float16-filterable-webgl"},rg16float:{render:Yr,filter:ei},rgba16float:{render:Yr,filter:ei},r32uint:{},rg32uint:{},rgba32uint:{},r32sint:{},rg32sint:{},rgba32sint:{},r32float:{render:Qr,filter:Jr},rg32float:{render:!1,filter:Jr},"rgb32float-webgl":{render:Qr,filter:Jr},rgba32float:{render:Qr,filter:Jr},"rgba4unorm-webgl":{channels:"rgba",bitsPerChannel:[4,4,4,4],packed:!0},"rgb565unorm-webgl":{channels:"rgb",bitsPerChannel:[5,6,5,0],packed:!0},"rgb5a1unorm-webgl":{channels:"rgba",bitsPerChannel:[5,5,5,1],packed:!0},rgb9e5ufloat:{channels:"rgb",packed:!0,render:"rgb9e5ufloat-renderable-webgl"},rg11b10ufloat:{channels:"rgb",bitsPerChannel:[11,11,10,0],packed:!0,p:1,render:Qr},rgb10a2unorm:{channels:"rgba",bitsPerChannel:[10,10,10,2],packed:!0,p:1},rgb10a2uint:{channels:"rgba",bitsPerChannel:[10,10,10,2],packed:!0,p:1},stencil8:{attachment:"stencil",bitsPerChannel:[8,0,0,0],dataType:"uint8"},depth16unorm:{attachment:"depth",bitsPerChannel:[16,0,0,0],dataType:"uint16"},depth24plus:{attachment:"depth",bitsPerChannel:[24,0,0,0],dataType:"uint32"},depth32float:{attachment:"depth",bitsPerChannel:[32,0,0,0],dataType:"float32"},"depth24plus-stencil8":{attachment:"depth-stencil",bitsPerChannel:[24,8,0,0],packed:!0},"depth32float-stencil8":{attachment:"depth-stencil",bitsPerChannel:[32,8,0,0],packed:!0},"bc1-rgb-unorm-webgl":{f:Vr},"bc1-rgb-unorm-srgb-webgl":{f:Vr},"bc1-rgba-unorm":{f:Vr},"bc1-rgba-unorm-srgb":{f:Vr},"bc2-rgba-unorm":{f:Vr},"bc2-rgba-unorm-srgb":{f:Vr},"bc3-rgba-unorm":{f:Vr},"bc3-rgba-unorm-srgb":{f:Vr},"bc4-r-unorm":{f:Vr},"bc4-r-snorm":{f:Vr},"bc5-rg-unorm":{f:Vr},"bc5-rg-snorm":{f:Vr},"bc6h-rgb-ufloat":{f:Vr},"bc6h-rgb-float":{f:Vr},"bc7-rgba-unorm":{f:Vr},"bc7-rgba-unorm-srgb":{f:Vr},"etc2-rgb8unorm":{f:Hr},"etc2-rgb8unorm-srgb":{f:Hr},"etc2-rgb8a1unorm":{f:Hr},"etc2-rgb8a1unorm-srgb":{f:Hr},"etc2-rgba8unorm":{f:Hr},"etc2-rgba8unorm-srgb":{f:Hr},"eac-r11unorm":{f:Hr},"eac-r11snorm":{f:Hr},"eac-rg11unorm":{f:Hr},"eac-rg11snorm":{f:Hr},"astc-4x4-unorm":{f:Wr},"astc-4x4-unorm-srgb":{f:Wr},"astc-5x4-unorm":{f:Wr},"astc-5x4-unorm-srgb":{f:Wr},"astc-5x5-unorm":{f:Wr},"astc-5x5-unorm-srgb":{f:Wr},"astc-6x5-unorm":{f:Wr},"astc-6x5-unorm-srgb":{f:Wr},"astc-6x6-unorm":{f:Wr},"astc-6x6-unorm-srgb":{f:Wr},"astc-8x5-unorm":{f:Wr},"astc-8x5-unorm-srgb":{f:Wr},"astc-8x6-unorm":{f:Wr},"astc-8x6-unorm-srgb":{f:Wr},"astc-8x8-unorm":{f:Wr},"astc-8x8-unorm-srgb":{f:Wr},"astc-10x5-unorm":{f:Wr},"astc-10x5-unorm-srgb":{f:Wr},"astc-10x6-unorm":{f:Wr},"astc-10x6-unorm-srgb":{f:Wr},"astc-10x8-unorm":{f:Wr},"astc-10x8-unorm-srgb":{f:Wr},"astc-10x10-unorm":{f:Wr},"astc-10x10-unorm-srgb":{f:Wr},"astc-12x10-unorm":{f:Wr},"astc-12x10-unorm-srgb":{f:Wr},"astc-12x12-unorm":{f:Wr},"astc-12x12-unorm-srgb":{f:Wr},"pvrtc-rgb4unorm-webgl":{f:$r},"pvrtc-rgba4unorm-webgl":{f:$r},"pvrtc-rbg2unorm-webgl":{f:$r},"pvrtc-rgba2unorm-webgl":{f:$r},"etc1-rbg-unorm-webgl":{f:"texture-compression-etc1-webgl"},"atc-rgb-unorm-webgl":{f:Xr},"atc-rgba-unorm-webgl":{f:Xr},"atc-rgbai-unorm-webgl":{f:Xr}},ri=["bc1","bc2","bc3","bc4","bc5","bc6","bc7","etc1","etc2","eac","atc","astc","pvrtc"],ii=/^(r|rg|rgb|rgba|bgra)([0-9]*)([a-z]*)(-srgb)?(-webgl)?$/,si=new class{getInfo(e){return oi(e)}isColor(e){return e.startsWith("rgba")||e.startsWith("bgra")||e.startsWith("rgb")}isDepthStencil(e){return e.startsWith("depth")||e.startsWith("stencil")}isCompressed(e){return ri.some(t=>e.startsWith(t))}getCapabilities(e){const t=ti(e),n={format:e,create:t.f??!0,render:t.render??!0,filter:t.filter??!0,blend:t.blend??!0,store:t.store??!0},r=oi(e),i=e.startsWith("depth")||e.startsWith("stencil"),s=null==r?void 0:r.signed,o=null==r?void 0:r.integer,a=null==r?void 0:r.webgl;return n.render&&(n.render=!s),n.filter&&(n.filter=!(i||s||o||a)),n}};function oi(e){let t=function(e){var t;const n=ti(e),r=n.bytesPerPixel||1,i=n.bitsPerChannel||[8,8,8,8];delete n.bitsPerChannel,delete n.bytesPerPixel,delete n.f,delete n.render,delete n.filter,delete n.blend,delete n.store;return{...n,format:e,attachment:n.attachment||"color",channels:n.channels||"r",components:n.components||(null==(t=n.channels)?void 0:t.length)||1,bytesPerPixel:r,bitsPerChannel:i,dataType:n.dataType||"uint8",srgb:n.srgb??!1,packed:n.packed??!1,webgl:n.webgl??!1,integer:n.integer??!1,signed:n.signed??!1,normalized:n.normalized??!1,compressed:n.compressed??!1}}(e);if(si.isCompressed(e)){t.channels="rgb",t.components=3,t.bytesPerPixel=1,t.srgb=!1,t.compressed=!0;const n=function(e){const t=/.*-(\d+)x(\d+)-.*/.exec(e);if(t){const[,e,n]=t;return{blockWidth:Number(e),blockHeight:Number(n)}}return null}(e);n&&(t.blockWidth=n.blockWidth,t.blockHeight=n.blockHeight)}const n=ii.exec(e);if(n){const[,r,i,s,o,a]=n,A=Dr(`${s}${i}`),l=8*A.byteLength,c=r.length,u=[l,c>=2?l:0,c>=3?l:0,c>=4?l:0];t={format:e,attachment:t.attachment,dataType:A.signedType,components:c,channels:r,integer:A.integer,signed:A.signed,normalized:A.normalized,bitsPerChannel:u,bytesPerPixel:A.byteLength*r.length,packed:t.packed,srgb:t.srgb},"-webgl"===a&&(t.webgl=!0),"-srgb"===o&&(t.srgb=!0)}return e.endsWith("-webgl")&&(t.webgl=!0),e.endsWith("-srgb")&&(t.srgb=!0),t}class ai{}class Ai{constructor(e=[],t){r(this,"features"),r(this,"disabledFeatures"),this.features=new Set(e),this.disabledFeatures=t||{}}*[Symbol.iterator](){yield*this.features}has(e){var t;return!(null==(t=this.disabledFeatures)?void 0:t[e])&&this.features.has(e)}}const li=class e{constructor(t){r(this,"id"),r(this,"props"),r(this,"userData",{}),r(this,"statsManager",Rr),r(this,"timestamp",0),r(this,"_reused",!1),r(this,"_lumaData",{}),r(this,"_textureCaps",{}),this.props={...e.defaultProps,...t},this.id=this.props.id||Mr(this[Symbol.toStringTag].toLowerCase())}get[Symbol.toStringTag](){return"Device"}toString(){return`Device(${this.id})`}getVertexFormatInfo(e){return Gr(e)}isVertexFormatSupported(e){return!0}getTextureFormatInfo(e){return si.getInfo(e)}getTextureFormatCapabilities(e){let t=this._textureCaps[e];if(!t){const n=this._getDeviceTextureFormatCapabilities(e);t=this._getDeviceSpecificTextureFormatCapabilities(n),this._textureCaps[e]=t}return t}getMipLevelCount(e,t,n=1){const r=Math.max(e,t,n);return 1+Math.floor(Math.log2(r))}isExternalImage(e){return function(e){return"undefined"!=typeof ImageData&&e instanceof ImageData||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLVideoElement&&e instanceof HTMLVideoElement||"undefined"!=typeof VideoFrame&&e instanceof VideoFrame||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas}(e)}getExternalImageSize(e){return function(e){if("undefined"!=typeof ImageData&&e instanceof ImageData||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas)return{width:e.width,height:e.height};if("undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement)return{width:e.naturalWidth,height:e.naturalHeight};if("undefined"!=typeof HTMLVideoElement&&e instanceof HTMLVideoElement)return{width:e.videoWidth,height:e.videoHeight};if("undefined"!=typeof VideoFrame&&e instanceof VideoFrame)return{width:e.displayWidth,height:e.displayHeight};throw new Error("Unknown image type")}(e)}isTextureFormatSupported(e){return this.getTextureFormatCapabilities(e).create}isTextureFormatFilterable(e){return this.getTextureFormatCapabilities(e).filter}isTextureFormatRenderable(e){return this.getTextureFormatCapabilities(e).render}isTextureFormatCompressed(e){return si.isCompressed(e)}pushDebugGroup(e){this.commandEncoder.pushDebugGroup(e)}popDebugGroup(){var e;null==(e=this.commandEncoder)||e.popDebugGroup()}insertDebugMarker(e){var t;null==(t=this.commandEncoder)||t.insertDebugMarker(e)}loseDevice(){return!1}incrementTimestamp(){return this.timestamp++}reportError(e,t,...n){return this.props.onError(e,t)?()=>{}:Pr.error(e.message,t,...n)}debug(){if(this.props.debug);else{const e="'Type luma.log.set({debug: true}) in console to enable debug breakpoints',\nor create a device with the 'debug: true' prop.";Pr.once(0,e)()}}getDefaultCanvasContext(){if(!this.canvasContext)throw new Error("Device has no default CanvasContext. See props.createCanvasContext");return this.canvasContext}beginRenderPass(e){return this.commandEncoder.beginRenderPass(e)}beginComputePass(e){return this.commandEncoder.beginComputePass(e)}getCanvasContext(){return this.getDefaultCanvasContext()}readPixelsToArrayWebGL(e,t){throw new Error("not implemented")}readPixelsToBufferWebGL(e,t){throw new Error("not implemented")}setParametersWebGL(e){throw new Error("not implemented")}getParametersWebGL(e){throw new Error("not implemented")}withParametersWebGL(e,t){throw new Error("not implemented")}clearWebGL(e){throw new Error("not implemented")}resetWebGL(){throw new Error("not implemented")}static _getCanvasContextProps(e){return!0===e.createCanvasContext?{}:e.createCanvasContext}_getDeviceTextureFormatCapabilities(e){const t=si.getCapabilities(e),n=e=>("string"==typeof e?this.features.has(e):e)??!0,r=n(t.create);return{format:e,create:r,render:r&&n(t.render),filter:r&&n(t.filter),blend:r&&n(t.blend),store:r&&n(t.store)}}_normalizeBufferProps(e){(e instanceof ArrayBuffer||ArrayBuffer.isView(e))&&(e={data:e});const t={...e};if((e.usage||0)&Br.INDEX&&(e.indexType||(e.data instanceof Uint32Array?t.indexType="uint32":e.data instanceof Uint16Array&&(t.indexType="uint16")),!t.indexType))throw new Error("indices buffer content must be of type uint16 or uint32");return t}};r(li,"defaultProps",{id:null,powerPreference:"high-performance",failIfMajorPerformanceCaveat:!1,createCanvasContext:void 0,webgl:{},onError:(e,t)=>{},onResize:(e,t)=>{const[n,r]=e.getDevicePixelSize();Pr.log(1,`${e} resized => ${n}x${r}px`)()},onPositionChange:(e,t)=>{const[n,r]=e.getPosition();Pr.log(1,`${e} repositioned => ${n},${r}`)()},onVisibilityChange:e=>Pr.log(1,`${e} Visibility changed ${e.isVisible}`)(),onDevicePixelRatioChange:(e,t)=>Pr.log(1,`${e} DPR changed ${t.oldRatio} => ${e.devicePixelRatio}`)(),debug:Pr.get("debug")||void 0,debugShaders:Pr.get("debug-shaders")||void 0,debugFramebuffers:Boolean(Pr.get("debug-framebuffers")),debugFactories:Boolean(Pr.get("debug-factories")),debugWebGL:Boolean(Pr.get("debug-webgl")),debugSpectorJS:void 0,debugSpectorJSUrl:void 0,_reuseDevices:!1,_requestMaxLimits:!0,_cacheShaders:!1,_cachePipelines:!1,_cacheDestroyPolicy:"unused",_initializeFeatures:!0,_disabledFeatures:{"compilation-status-async-webgl":!0},_handle:void 0});let ci=li;const ui="No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.",hi=class e{constructor(){if(r(this,"stats",Rr),r(this,"log",Pr),r(this,"VERSION","9.2.5"),r(this,"spector"),r(this,"preregisteredAdapters",new Map),globalThis.luma){if(globalThis.luma.VERSION!==this.VERSION)throw Pr.error(`Found luma.gl ${globalThis.luma.VERSION} while initialzing ${this.VERSION}`)(),Pr.error("'yarn why @luma.gl/core' can help identify the source of the conflict")(),new Error("luma.gl - multiple versions detected: see console log");Pr.error("This version of luma.gl has already been initialized")()}Pr.log(1,`${this.VERSION} - set luma.log.level=1 (or higher) to trace rendering`)(),globalThis.luma=this}async createDevice(t={}){const n={...e.defaultProps,...t},r=this.selectAdapter(n.type,n.adapters);if(!r)throw new Error(ui);return n.waitForPageLoad&&await r.pageLoaded,await r.create(n)}async attachDevice(e,t){var n;const r=this._getTypeFromHandle(e,t.adapters),i=r&&this.selectAdapter(r,t.adapters);if(!i)throw new Error(ui);return await(null==(n=null==i?void 0:i.attach)?void 0:n.call(i,e,t))}registerAdapters(e){for(const t of e)this.preregisteredAdapters.set(t.type,t)}getSupportedAdapters(e=[]){const t=this._getAdapterMap(e);return Array.from(t).map(([,e])=>e).filter(e=>{var t;return null==(t=e.isSupported)?void 0:t.call(e)}).map(e=>e.type)}getBestAvailableAdapterType(e=[]){var t,n;const r=["webgpu","webgl","null"],i=this._getAdapterMap(e);for(const s of r)if(null==(n=null==(t=i.get(s))?void 0:t.isSupported)?void 0:n.call(t))return s;return null}selectAdapter(e,t=[]){let n=e;"best-available"===e&&(n=this.getBestAvailableAdapterType(t));const r=this._getAdapterMap(t);return n&&r.get(n)||null}enforceWebGL2(e=!0,t=[]){var n;const r=this._getAdapterMap(t).get("webgl");r||Pr.warn("enforceWebGL2: webgl adapter not found")(),null==(n=null==r?void 0:r.enforceWebGL2)||n.call(r,e)}setDefaultDeviceProps(t){Object.assign(e.defaultProps,t)}_getAdapterMap(e=[]){const t=new Map(this.preregisteredAdapters);for(const n of e)t.set(n.type,n);return t}_getTypeFromHandle(e,t=[]){return e instanceof WebGL2RenderingContext?"webgl":"undefined"!=typeof GPUDevice&&e instanceof GPUDevice||(null==e?void 0:e.queue)?"webgpu":null===e?"null":(e instanceof WebGLRenderingContext?Pr.warn("WebGL1 is not supported",e)():Pr.warn("Unknown handle type",e)(),null)}};r(hi,"defaultProps",{...ci.defaultProps,type:"best-available",adapters:void 0,waitForPageLoad:!0});const di=new hi;class fi{get pageLoaded(){return mi||(mi=gi()||"undefined"==typeof window?Promise.resolve():new Promise(e=>window.addEventListener("load",()=>e()))),mi}}const pi=Ue()&&"undefined"!=typeof document,gi=()=>pi&&"complete"===document.readyState;let mi=null;const _i=class e{constructor(t){var n,i;if(r(this,"id"),r(this,"props"),r(this,"canvas"),r(this,"htmlCanvas"),r(this,"offscreenCanvas"),r(this,"type"),r(this,"initialized"),r(this,"isInitialized",!1),r(this,"isVisible",!0),r(this,"cssWidth"),r(this,"cssHeight"),r(this,"devicePixelRatio"),r(this,"devicePixelWidth"),r(this,"devicePixelHeight"),r(this,"drawingBufferWidth"),r(this,"drawingBufferHeight"),r(this,"_initializedResolvers",function(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}()),r(this,"_resizeObserver"),r(this,"_intersectionObserver"),r(this,"_position"),r(this,"destroyed",!1),this.props={...e.defaultProps,...t},t=this.props,this.initialized=this._initializedResolvers.promise,Ue()?t.canvas?"string"==typeof t.canvas?this.canvas=function(e){const t=document.getElementById(e);if(!bi.isHTMLCanvas(t))throw new Error("Object is not a canvas element");return t}(t.canvas):this.canvas=t.canvas:this.canvas=function(e){const{width:t,height:n}=e,r=document.createElement("canvas");r.id=Mr("lumagl-auto-created-canvas"),r.width=t||1,r.height=n||1,r.style.width=Number.isFinite(t)?`${t}px`:"100%",r.style.height=Number.isFinite(n)?`${n}px`:"100%",(null==e?void 0:e.visible)||(r.style.visibility="hidden");const i=function(e){if("string"==typeof e){const t=document.getElementById(e);if(!t)throw new Error(`${e} is not an HTML element`);return t}return e||document.body}((null==e?void 0:e.container)||null);return i.insertBefore(r,i.firstChild),r}(t):this.canvas={width:t.width||1,height:t.height||1},e.isHTMLCanvas(this.canvas)?(this.id=t.id||this.canvas.id,this.type="html-canvas",this.htmlCanvas=this.canvas):e.isOffscreenCanvas(this.canvas)?(this.id=t.id||"offscreen-canvas",this.type="offscreen-canvas",this.offscreenCanvas=this.canvas):(this.id=t.id||"node-canvas-context",this.type="node"),this.cssWidth=(null==(n=this.htmlCanvas)?void 0:n.clientWidth)||this.canvas.width,this.cssHeight=(null==(i=this.htmlCanvas)?void 0:i.clientHeight)||this.canvas.height,this.devicePixelWidth=this.canvas.width,this.devicePixelHeight=this.canvas.height,this.drawingBufferWidth=this.canvas.width,this.drawingBufferHeight=this.canvas.height,this.devicePixelRatio=globalThis.devicePixelRatio||1,this._position=[0,0],e.isHTMLCanvas(this.canvas)){this._intersectionObserver=new IntersectionObserver(e=>this._handleIntersection(e)),this._intersectionObserver.observe(this.canvas),this._resizeObserver=new ResizeObserver(e=>this._handleResize(e));try{this._resizeObserver.observe(this.canvas,{box:"device-pixel-content-box"})}catch{this._resizeObserver.observe(this.canvas,{box:"content-box"})}setTimeout(()=>this._observeDevicePixelRatio(),0),this.props.trackPosition&&this._trackPosition()}}static isHTMLCanvas(e){return"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement}static isOffscreenCanvas(e){return"undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas}toString(){return`${this[Symbol.toStringTag]}(${this.id})`}destroy(){this.destroyed=!0}setProps(e){return"useDevicePixels"in e&&(this.props.useDevicePixels=e.useDevicePixels||!1,this._updateDrawingBufferSize()),this}getCSSSize(){return[this.cssWidth,this.cssHeight]}getPosition(){return this._position}getDevicePixelSize(){return[this.devicePixelWidth,this.devicePixelHeight]}getDrawingBufferSize(){return[this.drawingBufferWidth,this.drawingBufferHeight]}getMaxDrawingBufferSize(){const e=this.device.limits.maxTextureDimension2D;return[e,e]}setDrawingBufferSize(e,t){this.canvas.width=e,this.canvas.height=t,this.drawingBufferWidth=e,this.drawingBufferHeight=t}getDevicePixelRatio(){return"undefined"!=typeof window&&window.devicePixelRatio||1}cssToDevicePixels(e,t=!0){const n=this.cssToDeviceRatio(),[r,i]=this.getDrawingBufferSize();return function(e,t,n,r,i){const s=e,o=vi(s[0],t,n);let a=yi(s[1],t,r,i),A=vi(s[0]+1,t,n);const l=A===n-1?A:A-1;let c;return A=yi(s[1]+1,t,r,i),i?(A=0===A?A:A+1,c=a,a=A):c=A===r-1?A:A-1,{x:o,y:a,width:Math.max(l-o+1,1),height:Math.max(c-a+1,1)}}(e,n,r,i,t)}getPixelSize(){return this.getDevicePixelSize()}getAspect(){const[e,t]=this.getDevicePixelSize();return e/t}cssToDeviceRatio(){try{const[e]=this.getDrawingBufferSize(),[t]=this.getCSSSize();return t?e/t:1}catch{return 1}}resize(e){this.setDrawingBufferSize(e.width,e.height)}_setAutoCreatedCanvasId(e){var t;"lumagl-auto-created-canvas"===(null==(t=this.htmlCanvas)?void 0:t.id)&&(this.htmlCanvas.id=e)}_handleIntersection(e){const t=e.find(e=>e.target===this.canvas);if(!t)return;const n=t.isIntersecting;this.isVisible!==n&&(this.isVisible=n,this.device.props.onVisibilityChange(this))}_handleResize(e){var t,n;const r=e.find(e=>e.target===this.canvas);if(!r)return;this.cssWidth=r.contentBoxSize[0].inlineSize,this.cssHeight=r.contentBoxSize[0].blockSize;const i=this.getDevicePixelSize(),s=(null==(t=r.devicePixelContentBoxSize)?void 0:t[0].inlineSize)||r.contentBoxSize[0].inlineSize*devicePixelRatio,o=(null==(n=r.devicePixelContentBoxSize)?void 0:n[0].blockSize)||r.contentBoxSize[0].blockSize*devicePixelRatio,[a,A]=this.getMaxDrawingBufferSize();this.devicePixelWidth=Math.max(1,Math.min(s,a)),this.devicePixelHeight=Math.max(1,Math.min(o,A)),this._updateDrawingBufferSize(),this.device.props.onResize(this,{oldPixelSize:i})}_updateDrawingBufferSize(){if(this.props.autoResize){if("number"==typeof this.props.useDevicePixels){const e=this.props.useDevicePixels;this.setDrawingBufferSize(this.cssWidth*e,this.cssHeight*e)}else this.props.useDevicePixels?this.setDrawingBufferSize(this.devicePixelWidth,this.devicePixelHeight):this.setDrawingBufferSize(this.cssWidth,this.cssHeight);this._updateDevice()}this._initializedResolvers.resolve(),this.isInitialized=!0,this.updatePosition()}_observeDevicePixelRatio(){const e=this.devicePixelRatio;this.devicePixelRatio=window.devicePixelRatio,this.updatePosition(),this.device.props.onDevicePixelRatioChange(this,{oldRatio:e}),matchMedia(`(resolution: ${this.devicePixelRatio}dppx)`).addEventListener("change",()=>this._observeDevicePixelRatio(),{once:!0})}_trackPosition(e=100){const t=setInterval(()=>{this.destroyed?clearInterval(t):this.updatePosition()},e)}updatePosition(){var e,t,n;const r=null==(e=this.htmlCanvas)?void 0:e.getBoundingClientRect();if(r){const e=[r.left,r.top];if(this._position??(this._position=e),e[0]!==this._position[0]||e[1]!==this._position[1]){const r=this._position;this._position=e,null==(n=(t=this.device.props).onPositionChange)||n.call(t,this,{oldPosition:r})}}}};r(_i,"defaultProps",{id:void 0,canvas:null,width:800,height:600,useDevicePixels:!0,autoResize:!0,container:null,visible:!0,alphaMode:"opaque",colorSpace:"srgb",trackPosition:!1});let bi=_i;function vi(e,t,n){return Math.min(Math.round(e*t),n-1)}function yi(e,t,n,r){return r?Math.max(0,n-1-Math.round(e*t)):Math.min(Math.round(e*t),n-1)}const wi=class e extends Lr{get[Symbol.toStringTag](){return"Sampler"}constructor(t,n){super(t,n=e.normalizeProps(t,n),e.defaultProps)}static normalizeProps(e,t){return t}};r(wi,"defaultProps",{...Lr.defaultProps,type:"color-sampler",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",addressModeW:"clamp-to-edge",magFilter:"nearest",minFilter:"nearest",mipmapFilter:"none",lodMinClamp:0,lodMaxClamp:32,compare:"less-equal",maxAnisotropy:1});let xi=wi;const Ei={"1d":"1d","2d":"2d","2d-array":"2d",cube:"2d","cube-array":"2d","3d":"3d"},Ti=class e extends Lr{constructor(t,n){if(super(t,n=e.normalizeProps(t,n),e.defaultProps),r(this,"dimension"),r(this,"baseDimension"),r(this,"format"),r(this,"width"),r(this,"height"),r(this,"depth"),r(this,"mipLevels"),r(this,"updateTimestamp"),this.dimension=this.props.dimension,this.baseDimension=Ei[this.dimension],this.format=this.props.format,this.width=this.props.width,this.height=this.props.height,this.depth=this.props.depth,this.mipLevels=this.props.mipLevels,void 0===this.props.width||void 0===this.props.height)if(t.isExternalImage(n.data)){const e=t.getExternalImageSize(n.data);this.width=(null==e?void 0:e.width)||1,this.height=(null==e?void 0:e.height)||1}else this.width=1,this.height=1,void 0!==this.props.width&&void 0!==this.props.height||Pr.warn(`${this} created with undefined width or height. This is deprecated. Use AsyncTexture instead.`)();this.updateTimestamp=t.incrementTimestamp()}get[Symbol.toStringTag](){return"Texture"}toString(){return`Texture(${this.id},${this.format},${this.width}x${this.height})`}setSampler(e){this.sampler=e instanceof xi?e:this.device.createSampler(e)}clone(e){return this.device.createTexture({...this.props,...e})}static normalizeProps(e,t){const n={...t},{width:r,height:i}=n;return"number"==typeof r&&(n.width=Math.max(1,Math.ceil(r))),"number"==typeof i&&(n.height=Math.max(1,Math.ceil(i))),n}_initializeData(e){this.device.isExternalImage(e)?this.copyExternalImage({image:e,width:this.width,height:this.height,depth:this.depth,mipLevel:0,x:0,y:0,z:0,aspect:"all",colorSpace:"srgb",premultipliedAlpha:!1,flipY:!1}):e&&this.copyImageData({data:e,mipLevel:0,x:0,y:0,z:0,aspect:"all"})}_normalizeCopyImageDataOptions(t){const{width:n,height:r,depth:i}=this,s={...e.defaultCopyDataOptions,width:n,height:r,depth:i,...t},o=this.device.getTextureFormatInfo(this.format);if(!t.bytesPerRow&&!o.bytesPerPixel)throw new Error(`bytesPerRow must be provided for texture format ${this.format}`);return s.bytesPerRow=t.bytesPerRow||n*(o.bytesPerPixel||4),s.rowsPerImage=t.rowsPerImage||r,s}_normalizeCopyExternalImageOptions(t){const n=this.device.getExternalImageSize(t.image),r={...e.defaultCopyExternalImageOptions,...n,...t};return r.width=Math.min(r.width,this.width-r.x),r.height=Math.min(r.height,this.height-r.y),r}};r(Ti,"SAMPLE",4),r(Ti,"STORAGE",8),r(Ti,"RENDER",16),r(Ti,"COPY_SRC",1),r(Ti,"COPY_DST",2),r(Ti,"TEXTURE",4),r(Ti,"RENDER_ATTACHMENT",16),r(Ti,"defaultProps",{...Lr.defaultProps,data:null,dimension:"2d",format:"rgba8unorm",usage:Ti.TEXTURE|Ti.RENDER_ATTACHMENT|Ti.COPY_DST,width:void 0,height:void 0,depth:1,mipLevels:1,samples:void 0,sampler:{},view:void 0}),r(Ti,"defaultCopyDataOptions",{data:void 0,byteOffset:0,bytesPerRow:void 0,rowsPerImage:void 0,mipLevel:0,x:0,y:0,z:0,aspect:"all"}),r(Ti,"defaultCopyExternalImageOptions",{image:void 0,sourceX:0,sourceY:0,width:void 0,height:void 0,depth:1,mipLevel:0,x:0,y:0,z:0,aspect:"all",colorSpace:"srgb",premultipliedAlpha:!1,flipY:!1});let Si=Ti;const Ci=class e extends Lr{get[Symbol.toStringTag](){return"TextureView"}constructor(t,n){super(t,n,e.defaultProps)}};r(Ci,"defaultProps",{...Lr.defaultProps,format:void 0,dimension:void 0,aspect:"all",baseMipLevel:0,mipLevelCount:void 0,baseArrayLayer:0,arrayLayerCount:void 0});let ki=Ci;function Ri(e,t,n,r){if(null==r?void 0:r.inlineSource){const r=function(e,t){let n="";for(let r=t-2;r<=t;r++){const i=e[r-1];void 0!==i&&(n+=Pi(i,t,undefined))}return n}(t,n);return`\n${r}${e.linePos>0?`${" ".repeat(e.linePos+5)}^^^\n`:""}${e.type.toUpperCase()}: ${e.message}\n\n`}const i="error"===e.type?"red":"#8B4000";return(null==r?void 0:r.html)?` ${e.type.toUpperCase()}: ${e.message}
`:`${e.type.toUpperCase()}: ${e.message}`}function Pi(e,t,n){const r=(null==n?void 0:n.html)?e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'"):e;return`${function(e){let t="";for(let n=e.length;n<4;++n)t+=" ";return t+e}(String(t))}: ${r}${(null==n?void 0:n.html)?"
":"\n"}`}const Ii=class e extends Lr{constructor(t,n){super(t,{id:Li(n={...n,debugShaders:n.debugShaders||t.props.debugShaders||"errors"}),...n},e.defaultProps),r(this,"stage"),r(this,"source"),r(this,"compilationStatus","pending"),this.stage=this.props.stage,this.source=this.props.source}get[Symbol.toStringTag](){return"Shader"}getCompilationInfoSync(){return null}getTranslatedSource(){return null}async debugShader(){const e=this.props.debugShaders;switch(e){case"never":return;case"errors":if("success"===this.compilationStatus)return}const t=await this.getCompilationInfo();"warnings"===e&&0===(null==t?void 0:t.length)||this._displayShaderLog(t,this.id)}_displayShaderLog(e,t){var n;if("undefined"==typeof document||!(null==document?void 0:document.createElement))return;const r=t,i=`${this.stage} shader "${r}"`;let s=function(e,t,n){let r="";const i=t.split(/\r?\n/),s=e.slice().sort((e,t)=>e.lineNum-t.lineNum);switch((null==n?void 0:n.showSourceCode)||"no"){case"all":let t=0;for(let e=1;e<=i.length;e++)for(r+=Pi(i[e-1],e,n);s.length>t&&s[t].lineNum===e;){const e=s[t++];r+=Ri(e,i,e.lineNum,{...n,inlineSource:!1})}for(;s.length>t;)r+=Ri(s[t++],[],0,{...n,inlineSource:!1});return r;case"issues":case"no":for(const s of e)r+=Ri(s,i,s.lineNum,{inlineSource:"no"!==(null==n?void 0:n.showSourceCode)});return r}}(e,this.source,{showSourceCode:"all",html:!0});const o=this.getTranslatedSource();o&&(s+=`
Translated Source
${o}`);const a=document.createElement("Button");a.innerHTML=`\nCompilation error in ${i}
\n\n${s}\n`,a.style.top="10px",a.style.left="10px",a.style.position="absolute",a.style.zIndex="9999",a.style.width="100%",a.style.textAlign="left",document.body.appendChild(a),null==(n=document.getElementsByClassName("luma-compiler-log-error")[0])||n.scrollIntoView(),a.onclick=()=>{const e=`data:text/plain,${encodeURIComponent(this.source)}`;navigator.clipboard.writeText(e)}}};r(Ii,"defaultProps",{...Lr.defaultProps,language:"auto",stage:void 0,source:"",sourceMap:null,entryPoint:"main",debugShaders:void 0});let Mi=Ii;function Li(e){return function(e,t="unnamed"){const n=/#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/.exec(e);return n?n[1]:t}(e.source)||e.id||Mr(`unnamed ${e.stage}-shader`)}const Ni=class e extends Lr{constructor(t,n={}){super(t,n,e.defaultProps),r(this,"width"),r(this,"height"),this.width=this.props.width,this.height=this.props.height}get[Symbol.toStringTag](){return"Framebuffer"}clone(e){const t=this.colorAttachments.map(t=>t.texture.clone(e)),n=this.depthStencilAttachment&&this.depthStencilAttachment.texture.clone(e);return this.device.createFramebuffer({...this.props,colorAttachments:t,depthStencilAttachment:n})}resize(e){let t=!e;if(e){const[n,r]=Array.isArray(e)?e:[e.width,e.height];t=t||r!==this.height||n!==this.width,this.width=n,this.height=r}t&&(Pr.log(2,`Resizing framebuffer ${this.id} to ${this.width}x${this.height}`)(),this.resizeAttachments(this.width,this.height))}autoCreateAttachmentTextures(){if(0===this.props.colorAttachments.length&&!this.props.depthStencilAttachment)throw new Error("Framebuffer has noattachments");this.colorAttachments=this.props.colorAttachments.map((e,t)=>{if("string"==typeof e){const n=this.createColorTexture(e,t);return this.attachResource(n),n.view}return e instanceof Si?e.view:e});const e=this.props.depthStencilAttachment;if(e)if("string"==typeof e){const t=this.createDepthStencilTexture(e);this.attachResource(t),this.depthStencilAttachment=t.view}else this.depthStencilAttachment=e instanceof Si?e.view:e}createColorTexture(e,t){return this.device.createTexture({id:`${this.id}-color-attachment-${t}`,usage:Si.RENDER_ATTACHMENT,format:e,width:this.width,height:this.height,sampler:{magFilter:"linear",minFilter:"linear"}})}createDepthStencilTexture(e){return this.device.createTexture({id:`${this.id}-depth-stencil-attachment`,usage:Si.RENDER_ATTACHMENT,format:e,width:this.width,height:this.height})}resizeAttachments(e,t){for(let n=0;n":["f32",2],"vec3":["f32",3],"vec4":["f32",4],f16:["f16",1],"vec2":["f16",2],"vec3":["f16",3],"vec4":["f16",4],i32:["i32",1],"vec2":["i32",2],"vec3":["i32",3],"vec4":["i32",4],u32:["u32",1],"vec2":["u32",2],"vec3":["u32",3],"vec4":["u32",4]},Yi={f32:{type:"f32",components:1},f16:{type:"f16",components:1},i32:{type:"i32",components:1},u32:{type:"u32",components:1},"vec2":{type:"f32",components:2},"vec3":{type:"f32",components:3},"vec4":{type:"f32",components:4},"vec2":{type:"f16",components:2},"vec3":{type:"f16",components:3},"vec4":{type:"f16",components:4},"vec2":{type:"i32",components:2},"vec3":{type:"i32",components:3},"vec4":{type:"i32",components:4},"vec2":{type:"u32",components:2},"vec3":{type:"u32",components:3},"vec4":{type:"u32",components:4},"mat2x2":{type:"f32",components:4},"mat2x3":{type:"f32",components:6},"mat2x4":{type:"f32",components:8},"mat3x2":{type:"f32",components:6},"mat3x3":{type:"f32",components:9},"mat3x4":{type:"f32",components:12},"mat4x2":{type:"f32",components:8},"mat4x3":{type:"f32",components:12},"mat4x4":{type:"f32",components:16},"mat2x2":{type:"f16",components:4},"mat2x3":{type:"f16",components:6},"mat2x4":{type:"f16",components:8},"mat3x2":{type:"f16",components:6},"mat3x3":{type:"f16",components:9},"mat3x4":{type:"f16",components:12},"mat4x2":{type:"f16",components:8},"mat4x3":{type:"f16",components:12},"mat4x4":{type:"f16",components:16},"mat2x2":{type:"i32",components:4},"mat2x3":{type:"i32",components:6},"mat2x4":{type:"i32",components:8},"mat3x2":{type:"i32",components:6},"mat3x3":{type:"i32",components:9},"mat3x4":{type:"i32",components:12},"mat4x2":{type:"i32",components:8},"mat4x3":{type:"i32",components:12},"mat4x4":{type:"i32",components:16},"mat2x2":{type:"u32",components:4},"mat2x3":{type:"u32",components:6},"mat2x4":{type:"u32",components:8},"mat3x2":{type:"u32",components:6},"mat3x3":{type:"u32",components:9},"mat3x4":{type:"u32",components:12},"mat4x2":{type:"u32",components:8},"mat4x3":{type:"u32",components:12},"mat4x4":{type:"u32",components:16}};function qi(e,t){const n={};for(const r of e.attributes){const i=Ki(e,t,r.name);i&&(n[r.name]=i)}return n}function Ki(e,t,n){const r=function(e,t){const n=e.attributes.find(e=>e.name===t);return n||Pr.warn(`shader layout attribute "${t}" not present in shader`),n||null}(e,n),i=function(e,t){!function(e){for(const t of e)(t.attributes&&t.format||!t.attributes&&!t.format)&&Pr.warn(`BufferLayout ${name} must have either 'attributes' or 'format' field`)}(e);let n=function(e,t){for(const n of e)if(n.format&&n.name===t)return{attributeName:n.name,bufferName:t,stepMode:n.stepMode,vertexFormat:n.format,byteOffset:0,byteStride:n.byteStride||0};return null}(e,t);return n||(n=function(e,t){var n;for(const r of e){let e=r.byteStride;if("number"!=typeof r.byteStride)for(const t of r.attributes||[])e+=Gr(t.format).byteLength;const i=null==(n=r.attributes)?void 0:n.find(e=>e.attribute===t);if(i)return{attributeName:i.attribute,bufferName:r.name,stepMode:r.stepMode,vertexFormat:i.format,byteOffset:i.byteOffset,byteStride:e}}return null}(e,t),n||(Pr.warn(`layout for attribute "${t}" not present in buffer layout`),null))}(t,n);if(!r)return null;const s=function(e){const[t,n]=Qi[e];return{primitiveType:t,components:n,byteLength:Xi[t]*n,integer:"i32"===t||"u32"===t,signed:"u32"!==t}}(r.type),o=function(e){let t;switch(e.primitiveType){case"f32":t="float32";break;case"i32":t="sint32";break;case"u32":t="uint32";break;case"f16":return e.components<=2?"float16x2":"float16x4"}return 1===e.components?t:`${t}x${e.components}`}(s),a=(null==i?void 0:i.vertexFormat)||o,A=Gr(a);return{attributeName:(null==i?void 0:i.attributeName)||r.name,bufferName:(null==i?void 0:i.bufferName)||r.name,location:r.location,shaderType:r.type,primitiveType:s.primitiveType,shaderComponents:s.components,vertexFormat:a,bufferDataType:A.type,bufferComponents:A.components,normalized:A.normalized,integer:s.integer,stepMode:(null==i?void 0:i.stepMode)||r.stepMode||"vertex",byteOffset:(null==i?void 0:i.byteOffset)||0,byteStride:(null==i?void 0:i.byteStride)||0}}const Zi=class e extends Lr{constructor(t,n){super(t,n,e.defaultProps),r(this,"maxVertexAttributes"),r(this,"attributeInfos"),r(this,"indexBuffer",null),r(this,"attributes"),this.maxVertexAttributes=t.limits.maxVertexAttributes,this.attributes=new Array(this.maxVertexAttributes).fill(null),this.attributeInfos=function(e,t,n=16){const r=qi(e,t),i=new Array(n).fill(null);for(const s of Object.values(r))i[s.location]=s;return i}(n.shaderLayout,n.bufferLayout,this.maxVertexAttributes)}get[Symbol.toStringTag](){return"VertexArray"}setConstantWebGL(e,t){this.device.reportError(new Error("constant attributes not supported"),this)()}};r(Zi,"defaultProps",{...Lr.defaultProps,shaderLayout:void 0,bufferLayout:[]});let Ji=Zi;const es=class e extends Lr{get[Symbol.toStringTag](){return"TransformFeedback"}constructor(t,n){super(t,n,e.defaultProps)}};r(es,"defaultProps",{...Lr.defaultProps,layout:void 0,buffers:{}});let ts=es;const ns=class e extends Lr{get[Symbol.toStringTag](){return"QuerySet"}constructor(t,n){super(t,n,e.defaultProps)}};r(ns,"defaultProps",{...Lr.defaultProps,type:void 0,count:void 0});let rs,is=ns;function ss(e){return(!rs||rs.byteLength"uniform"===t.type&&t.name===(null==e?void 0:e.name));if(!n)throw new Error(null==e?void 0:e.name);const r=n;for(const e of r.uniforms||[])this.bindingLayout[e.name]=e}}setUniforms(e){for(const[t,n]of Object.entries(e))this._setUniform(t,n),this.needsRedraw||this.setNeedsRedraw(`${this.name}.${t}=${n}`)}setNeedsRedraw(e){this.needsRedraw=this.needsRedraw||e}getAllUniforms(){return this.modifiedUniforms={},this.needsRedraw=!1,this.uniforms||{}}_setUniform(e,t){var n;(function(e,t){if(e!==t)return!1;const n=e,r=t;if(!os(n))return!1;if(os(r)&&n.length===r.length)for(let i=0;i`}}class fs extends cs{constructor(e,t,n){super(e,n),this.format=t}get isPointer(){return!0}getTypeName(){return`&${this.format.getTypeName()}`}}class ps extends cs{constructor(e,t,n,r){super(e,n),this.format=t,this.access=r}get isTemplate(){return!0}getTypeName(){let e=this.name;if(null!==this.format){if("vec2"===e||"vec3"===e||"vec4"===e||"mat2x2"===e||"mat2x3"===e||"mat2x4"===e||"mat3x2"===e||"mat3x3"===e||"mat3x4"===e||"mat4x2"===e||"mat4x3"===e||"mat4x4"===e){if("f32"===this.format.name)return e+="f",e;if("i32"===this.format.name)return e+="i",e;if("u32"===this.format.name)return e+="u",e;if("bool"===this.format.name)return e+="b",e;if("f16"===this.format.name)return e+="h",e}e+=`<${this.format.name}>`}else if("vec2"===e||"vec3"===e||"vec4"===e)return e;return e}}var gs,ms;(ms=gs||(gs={}))[ms.Uniform=0]="Uniform",ms[ms.Storage=1]="Storage",ms[ms.Texture=2]="Texture",ms[ms.Sampler=3]="Sampler",ms[ms.StorageTexture=4]="StorageTexture";class _s{constructor(e,t,n,r,i,s,o){this.name=e,this.type=t,this.group=n,this.binding=r,this.attributes=i,this.resourceType=s,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}}class bs{constructor(e,t){this.name=e,this.type=t}}class vs{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r,this.interpolation=null}}class ys{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r}}class ws{constructor(e,t,n,r){this.name=e,this.type=t,this.attributes=n,this.id=r}}class xs{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n}}class Es{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}}class Ts{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}}function Ss(e){var t=(32768&e)>>15,n=(31744&e)>>10,r=1023&e;return 0==n?(t?-1:1)*Math.pow(2,-14)*(r/Math.pow(2,10)):31==n?r?NaN:1/0*(t?-1:1):(t?-1:1)*Math.pow(2,n-15)*(1+r/Math.pow(2,10))}const Cs=new Float32Array(1),ks=new Int32Array(Cs.buffer),Rs=new Uint16Array(1);function Ps(e){Cs[0]=e;const t=ks[0],n=t>>31&1;let r=t>>23&255,i=8388607&t;if(255===r)return Rs[0]=n<<15|31744|(0!==i?512:0),Rs[0];if(0===r){if(0===i)return Rs[0]=n<<15,Rs[0];i|=8388608;let e=113;for(;!(8388608&i);)i<<=1,e--;return r=127-e,i&=8388607,r>0?(i=(i>>126-r)+(i>>127-r&1),Rs[0]=n<<15|r<<10|i>>13,Rs[0]):(Rs[0]=n<<15,Rs[0])}return r=r-127+15,r>=31?(Rs[0]=n<<15|31744,Rs[0]):r<=0?r<-10?(Rs[0]=n<<15,Rs[0]):(i=(8388608|i)>>1-r,Rs[0]=n<<15|i>>13,Rs[0]):(i>>=13,Rs[0]=n<<15|r<<10|i,Rs[0])}const Is=new Uint32Array(1),Ms=new Float32Array(Is.buffer,0,1);function Ls(e){const t=112+(e>>6&31)<<23|(63&e)<<17;return Is[0]=t,Ms[0]}function Ns(e,t,n,r){const i=[0,0,0,0];for(let s=0;s{e.increment="++",e.decrement="--"})(Ks||(Ks={})),(e=>{e.parse=function(t){const n=t;if("parse"==n)throw new Error("Invalid value for IncrementOperator");return e[n]}})(Ks||(Ks={}));class to extends Gs{constructor(e,t){super(),this.operator=e,this.variable=t}get astNodeType(){return"increment"}search(e){this.variable.search(e)}}(e=>{e.assign="=",e.addAssign="+=",e.subtractAssin="-=",e.multiplyAssign="*=",e.divideAssign="/=",e.moduloAssign="%=",e.andAssign="&=",e.orAssign="|=",e.xorAssign="^=",e.shiftLeftAssign="<<=",e.shiftRightAssign=">>="})(Zs||(Zs={})),(Zs||(Zs={})).parse=function(e){const t=e;if("parse"==t)throw new Error("Invalid value for AssignOperator");return t};class no extends Gs{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)}}class ro extends Gs{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"call"}isBuiltin(){return js.has(this.name)}search(e){for(const t of this.args)t.search(e);e(this)}}class io extends Gs{constructor(e,t){super(),this.body=e,this.continuing=t}get astNodeType(){return"loop"}search(e){var t;this.searchBlock(this.body,e),null===(t=this.continuing)||void 0===t||t.search(e)}}class so extends Gs{constructor(e,t){super(),this.condition=e,this.cases=t}get astNodeType(){return"switch"}search(e){e(this);for(const t of this.cases)t.search(e)}}class oo extends Gs{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)}}class ao extends Gs{constructor(e){super(),this.value=e}get astNodeType(){return"return"}search(e){var t;null===(t=this.value)||void 0===t||t.search(e)}}class Ao extends Gs{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}}class lo extends Gs{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}}class co extends Gs{constructor(e,t){super(),this.severity=e,this.rule=t}get astNodeType(){return"diagnostic"}}class uo extends Gs{constructor(e,t){super(),this.name=e,this.type=t}get astNodeType(){return"alias"}}class ho extends Gs{constructor(){super()}get astNodeType(){return"discard"}}class fo extends Gs{constructor(){super(),this.condition=null,this.loopId=-1}get astNodeType(){return"break"}}class po extends Gs{constructor(){super(),this.loopId=-1}get astNodeType(){return"continue"}}class go extends Gs{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("f32"===t.name)return t;for(let n=1;n`}else if("vec2"===e||"vec3"===e||"vec4"===e)return e;return e}}bo.vec2f=new bo("vec2",go.f32,null),bo.vec3f=new bo("vec3",go.f32,null),bo.vec4f=new bo("vec4",go.f32,null),bo.vec2i=new bo("vec2",go.i32,null),bo.vec3i=new bo("vec3",go.i32,null),bo.vec4i=new bo("vec4",go.i32,null),bo.vec2u=new bo("vec2",go.u32,null),bo.vec3u=new bo("vec3",go.u32,null),bo.vec4u=new bo("vec4",go.u32,null),bo.vec2h=new bo("vec2",go.f16,null),bo.vec3h=new bo("vec3",go.f16,null),bo.vec4h=new bo("vec4",go.f16,null),bo.vec2b=new bo("vec2",go.bool,null),bo.vec3b=new bo("vec3",go.bool,null),bo.vec4b=new bo("vec4",go.bool,null),bo.mat2x2f=new bo("mat2x2",go.f32,null),bo.mat2x3f=new bo("mat2x3",go.f32,null),bo.mat2x4f=new bo("mat2x4",go.f32,null),bo.mat3x2f=new bo("mat3x2",go.f32,null),bo.mat3x3f=new bo("mat3x3",go.f32,null),bo.mat3x4f=new bo("mat3x4",go.f32,null),bo.mat4x2f=new bo("mat4x2",go.f32,null),bo.mat4x3f=new bo("mat4x3",go.f32,null),bo.mat4x4f=new bo("mat4x4",go.f32,null),bo.mat2x2h=new bo("mat2x2",go.f16,null),bo.mat2x3h=new bo("mat2x3",go.f16,null),bo.mat2x4h=new bo("mat2x4",go.f16,null),bo.mat3x2h=new bo("mat3x2",go.f16,null),bo.mat3x3h=new bo("mat3x3",go.f16,null),bo.mat3x4h=new bo("mat3x4",go.f16,null),bo.mat4x2h=new bo("mat4x2",go.f16,null),bo.mat4x3h=new bo("mat4x3",go.f16,null),bo.mat4x4h=new bo("mat4x4",go.f16,null),bo.mat2x2i=new bo("mat2x2",go.i32,null),bo.mat2x3i=new bo("mat2x3",go.i32,null),bo.mat2x4i=new bo("mat2x4",go.i32,null),bo.mat3x2i=new bo("mat3x2",go.i32,null),bo.mat3x3i=new bo("mat3x3",go.i32,null),bo.mat3x4i=new bo("mat3x4",go.i32,null),bo.mat4x2i=new bo("mat4x2",go.i32,null),bo.mat4x3i=new bo("mat4x3",go.i32,null),bo.mat4x4i=new bo("mat4x4",go.i32,null),bo.mat2x2u=new bo("mat2x2",go.u32,null),bo.mat2x3u=new bo("mat2x3",go.u32,null),bo.mat2x4u=new bo("mat2x4",go.u32,null),bo.mat3x2u=new bo("mat3x2",go.u32,null),bo.mat3x3u=new bo("mat3x3",go.u32,null),bo.mat3x4u=new bo("mat3x4",go.u32,null),bo.mat4x2u=new bo("mat4x2",go.u32,null),bo.mat4x3u=new bo("mat4x3",go.u32,null),bo.mat4x4u=new bo("mat4x4",go.u32,null);class vo extends go{constructor(e,t,n,r){super(e),this.storage=t,this.type=n,this.access=r}get astNodeType(){return"pointer"}}class yo extends go{constructor(e,t,n,r){super(e),this.attributes=t,this.format=n,this.count=r}get astNodeType(){return"array"}get isArray(){return!0}}class wo extends go{constructor(e,t,n){super(e),this.format=t,this.access=n}get astNodeType(){return"sampler"}}class xo extends Os{constructor(){super(),this.postfix=null}}class Eo extends xo{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}constEvaluateString(){return this.value}}class To extends xo{constructor(e,t){super(),this.type=e,this.args=t}get astNodeType(){return"createExpr"}search(e){if(e(this),this.args)for(const t of this.args)t.search(e)}constEvaluate(e,t){return t&&(t[0]=this.type),e.evalExpression(this,e.context)}}class So extends xo{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 js.has(this.name)}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){for(const t of this.args)t.search(e);e(this)}}class Co extends xo{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)}}class ko extends xo{constructor(e,t){super(),this.name=e,this.initializer=t}get astNodeType(){return"constExpr"}constEvaluate(e,t){if(this.initializer){const t=e.evalExpression(this.initializer,e.context);return null!==t&&this.postfix?t.getSubData(e,this.postfix,e.context):t}return null}search(e){this.initializer.search(e)}}class Ro extends xo{constructor(e,t){super(),this.value=e,this.type=t}get astNodeType(){return"literalExpr"}constEvaluate(e,t){return void 0!==t&&(t[0]=this.type),this.value}get isScalar(){return this.value instanceof $o}get isVector(){return this.value instanceof Qo||this.value instanceof Yo}get scalarValue(){return this.value instanceof $o?this.value.value:0}get vectorValue(){return this.value instanceof Qo||this.value instanceof Yo?this.value.data:new Float32Array(0)}}class Po extends xo{constructor(e,t){super(),this.type=e,this.value=t}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}}class Io extends xo{constructor(e){super(),this.index=e}search(e){this.index.search(e)}}class Mo extends xo{constructor(){super()}}class Lo extends Mo{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)}}class No extends Mo{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:"f32"===e.name||"f32"===t.name?go.f32:"u32"===e.name||"u32"===t.name?go.u32:go.i32}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.left.search(e),this.right.search(e)}}class Bo extends Os{constructor(e){super(),this.body=e}search(e){e(this),this.searchBlock(this.body,e)}}class Do extends xo{constructor(){super()}get astNodeType(){return"default"}}class Oo extends Bo{constructor(e,t){super(t),this.selectors=e}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}}class Fo extends Bo{constructor(e){super(e)}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}}class Uo extends Os{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"argument"}}class jo extends Os{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)}}class Go extends Os{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"member"}}class zo extends Os{constructor(e,t){super(),this.name=e,this.value=t}get astNodeType(){return"attribute"}}class Vo{constructor(e,t){this.parent=null,this.typeInfo=e,this.parent=t,this.id=Vo._id++}clone(){throw`Clone: Not implemented for ${this.constructor.name}`}setDataValue(e,t,n,r){}getSubData(e,t,n){return null}toString(){return`<${this.typeInfo.getTypeName()}>`}}Vo._id=0;class Wo extends Vo{constructor(){super(new cs("void",null),null)}toString(){return"void"}}Wo.void=new Wo;class Ho extends Vo{constructor(e){super(new fs("pointer",e.typeInfo,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}toString(){return`&${this.reference.toString()}`}}class $o extends Vo{constructor(e,t,n=null){super(t,n),e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array?this.data=e:"x32"===this.typeInfo.name?e-Math.floor(e)!==0?this.data=new Float32Array([e]):this.data=e>=0?new Uint32Array([e]):new Int32Array([e]):"i32"===this.typeInfo.name||"bool"===this.typeInfo.name?this.data=new Int32Array([e]):"u32"===this.typeInfo.name?this.data=new Uint32Array([e]):("f32"===this.typeInfo.name||"f16"===this.typeInfo.name)&&(this.data=new Float32Array([e]))}clone(){if(this.data instanceof Float32Array)return new $o(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new $o(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new $o(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;if(!(t instanceof $o))return;let i=t.data[0];"i32"===this.typeInfo.name||"u32"===this.typeInfo.name?i=Math.floor(i):"bool"===this.typeInfo.name&&(i=i?1:0),this.data[0]=i}getSubData(e,t,n){return t?null:this}toString(){return`${this.value}`}}function Xo(e,t,n){const r=t.length;return 2===r?"f32"===n?new Qo(new Float32Array(t),e.getTypeInfo("vec2f")):"i32"===n||"bool"===n?new Qo(new Int32Array(t),e.getTypeInfo("vec2i")):"u32"===n?new Qo(new Uint32Array(t),e.getTypeInfo("vec2u")):"f16"===n?new Qo(new Float32Array(t),e.getTypeInfo("vec2h")):null:3===r?"f32"===n?new Qo(new Float32Array(t),e.getTypeInfo("vec3f")):"i32"===n||"bool"===n?new Qo(new Int32Array(t),e.getTypeInfo("vec3i")):"u32"===n?new Qo(new Uint32Array(t),e.getTypeInfo("vec3u")):"f16"===n?new Qo(new Float32Array(t),e.getTypeInfo("vec3h")):null:4===r?"f32"===n?new Qo(new Float32Array(t),e.getTypeInfo("vec4f")):"i32"===n||"bool"===n?new Qo(new Int32Array(t),e.getTypeInfo("vec4i")):"u32"===n?new Qo(new Uint32Array(t),e.getTypeInfo("vec4u")):"f16"===n?new Qo(new Float32Array(t),e.getTypeInfo("vec4h")):null:null}class Qo extends Vo{constructor(e,t,n=null){if(super(t,n),e instanceof Float32Array||e instanceof Uint32Array||e instanceof Int32Array)this.data=e;else{const t=this.typeInfo.name;"vec2f"===t||"vec3f"===t||"vec4f"===t?this.data=new Float32Array(e):"vec2i"===t||"vec3i"===t||"vec4i"===t?this.data=new Int32Array(e):"vec2u"===t||"vec3u"===t||"vec4u"===t?this.data=new Uint32Array(e):"vec2h"===t||"vec3h"===t||"vec4h"===t?this.data=new Float32Array(e):"vec2b"===t||"vec3b"===t||"vec4b"===t?this.data=new Int32Array(e):("vec2"===t||"vec3"===t||"vec4"===t)&&(this.data=new Float32Array(e))}}clone(){if(this.data instanceof Float32Array)return new Qo(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new Qo(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new Qo(new Uint32Array(this.data),this.typeInfo,null);throw"VectorData: Invalid data type"}setDataValue(e,t,n,r){n instanceof Eo||t instanceof Qo&&(this.data=t.data)}getSubData(e,t,n){if(null===t)return this;let r=e.getTypeInfo("f32");if(this.typeInfo instanceof ps)r=this.typeInfo.format||r;else{const t=this.typeInfo.name;"vec2f"===t||"vec3f"===t||"vec4f"===t?r=e.getTypeInfo("f32"):"vec2i"===t||"vec3i"===t||"vec4i"===t?r=e.getTypeInfo("i32"):"vec2b"===t||"vec3b"===t||"vec4b"===t?r=e.getTypeInfo("bool"):"vec2u"===t||"vec3u"===t||"vec4u"===t?r=e.getTypeInfo("u32"):("vec2h"===t||"vec3h"===t||"vec4h"===t)&&(r=e.getTypeInfo("f16"))}let i=this;for(;null!==t&&null!==i;){if(t instanceof Io){const s=t.index;let o=-1;if(s instanceof Ro){if(!(s.value instanceof $o))return null;o=s.value.value}else{const t=e.evalExpression(s,n);if(!(t instanceof $o))return null;o=t.value}if(o<0||o>=i.data.length)return null;if(i.data instanceof Float32Array){const e=new Float32Array(i.data.buffer,i.data.byteOffset+4*o,1);return new $o(e,r)}if(i.data instanceof Int32Array){const e=new Int32Array(i.data.buffer,i.data.byteOffset+4*o,1);return new $o(e,r)}if(i.data instanceof Uint32Array){const e=new Uint32Array(i.data.buffer,i.data.byteOffset+4*o,1);return new $o(e,r)}throw"GetSubData: Invalid data type"}if(!(t instanceof Eo))return null;{const n=t.value.toLowerCase();if(1===n.length){let e=0;if("x"===n||"r"===n)e=0;else if("y"===n||"g"===n)e=1;else if("z"===n||"b"===n)e=2;else{if("w"!==n&&"a"!==n)return null;e=3}if(this.data instanceof Float32Array){let t=new Float32Array(this.data.buffer,this.data.byteOffset+4*e,1);return new $o(t,r,this)}if(this.data instanceof Int32Array){let t=new Int32Array(this.data.buffer,this.data.byteOffset+4*e,1);return new $o(t,r,this)}if(this.data instanceof Uint32Array){let t=new Uint32Array(this.data.buffer,this.data.byteOffset+4*e,1);return new $o(t,r,this)}}const s=[];for(const e of n)"x"===e||"r"===e?s.push(this.data[0]):"y"===e||"g"===e?s.push(this.data[1]):"z"===e||"b"===e?s.push(this.data[2]):("w"===e||"a"===e)&&s.push(this.data[3]);i=Xo(e,s,r.name)}t=t.postfix}return i}toString(){let e=`${this.data[0]}`;for(let t=1;t=this.data.length)return null;const o=r.endsWith("h")?"h":"f";let a;if("mat2x2"===r||"mat2x2f"===r||"mat2x2h"===r||"mat3x2"===r||"mat3x2f"===r||"mat3x2h"===r||"mat4x2"===r||"mat4x2f"===r||"mat4x2h"===r)a=new Qo(new Float32Array(this.data.buffer,this.data.byteOffset+2*s*4,2),e.getTypeInfo(`vec2${o}`));else if("mat2x3"===r||"mat2x3f"===r||"mat2x3h"===r||"mat3x3"===r||"mat3x3f"===r||"mat3x3h"===r||"mat4x3"===r||"mat4x3f"===r||"mat4x3h"===r)a=new Qo(new Float32Array(this.data.buffer,this.data.byteOffset+3*s*4,3),e.getTypeInfo(`vec3${o}`));else{if("mat2x4"!==r&&"mat2x4f"!==r&&"mat2x4h"!==r&&"mat3x4"!==r&&"mat3x4f"!==r&&"mat3x4h"!==r&&"mat4x4"!==r&&"mat4x4f"!==r&&"mat4x4h"!==r)return null;a=new Qo(new Float32Array(this.data.buffer,this.data.byteOffset+4*s*4,4),e.getTypeInfo(`vec4${o}`))}return t.postfix?a.getSubData(e,t.postfix,n):a}return null}toString(){let e=`${this.data[0]}`;for(let t=1;t"!==s&&"x32"!==s)if("u32"!==s&&"atomic"!==s)if("bool"!==s){if("vec2f"===s||"vec2h"===s){const e=new Float32Array(this.buffer,r,2);return void(t instanceof Qo?(e[0]=t.data[0],e[1]=t.data[1]):(e[0]=t[0],e[1]=t[1]))}if("vec3f"===s||"vec3h"===s){const e=new Float32Array(this.buffer,r,3);return void(t instanceof Qo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2]):(e[0]=t[0],e[1]=t[1],e[2]=t[2]))}if("vec4f"===s||"vec4h"===s){const e=new Float32Array(this.buffer,r,4);return void(t instanceof Qo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3]))}if("vec2i"===s){const e=new Int32Array(this.buffer,r,2);return void(t instanceof Qo?(e[0]=t.data[0],e[1]=t.data[1]):(e[0]=t[0],e[1]=t[1]))}if("vec3i"===s){const e=new Int32Array(this.buffer,r,3);return void(t instanceof Qo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2]):(e[0]=t[0],e[1]=t[1],e[2]=t[2]))}if("vec4i"===s){const e=new Int32Array(this.buffer,r,4);return void(t instanceof Qo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3]))}if("vec2u"===s){const e=new Uint32Array(this.buffer,r,2);return void(t instanceof Qo?(e[0]=t.data[0],e[1]=t.data[1]):(e[0]=t[0],e[1]=t[1]))}if("vec3u"===s){const e=new Uint32Array(this.buffer,r,3);return void(t instanceof Qo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2]):(e[0]=t[0],e[1]=t[1],e[2]=t[2]))}if("vec4u"===s){const e=new Uint32Array(this.buffer,r,4);return void(t instanceof Qo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3]))}if("vec2b"===s){const e=new Uint32Array(this.buffer,r,2);return void(t instanceof Qo?(e[0]=t.data[0],e[1]=t.data[1]):(e[0]=t[0],e[1]=t[1]))}if("vec3b"===s){const e=new Uint32Array(this.buffer,r,3);return void(t instanceof Qo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2]):(e[0]=t[0],e[1]=t[1],e[2]=t[2]))}if("vec4b"===s){const e=new Uint32Array(this.buffer,r,4);return void(t instanceof Qo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3]))}if("mat2x2f"===s||"mat2x2h"===s){const e=new Float32Array(this.buffer,r,4);return void(t instanceof Yo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3]))}if("mat2x3f"===s||"mat2x3h"===s){const e=new Float32Array(this.buffer,r,6);return void(t instanceof Yo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3],e[4]=t.data[4],e[5]=t.data[5]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5]))}if("mat2x4f"===s||"mat2x4h"===s){const e=new Float32Array(this.buffer,r,8);return void(t instanceof Yo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3],e[4]=t.data[4],e[5]=t.data[5],e[6]=t.data[6],e[7]=t.data[7]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7]))}if("mat3x2f"===s||"mat3x2h"===s){const e=new Float32Array(this.buffer,r,6);return void(t instanceof Yo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3],e[4]=t.data[4],e[5]=t.data[5]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5]))}if("mat3x3f"===s||"mat3x3h"===s){const e=new Float32Array(this.buffer,r,9);return void(t instanceof Yo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3],e[4]=t.data[4],e[5]=t.data[5],e[6]=t.data[6],e[7]=t.data[7],e[8]=t.data[8]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8]))}if("mat3x4f"===s||"mat3x4h"===s){const e=new Float32Array(this.buffer,r,12);return void(t instanceof Yo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3],e[4]=t.data[4],e[5]=t.data[5],e[6]=t.data[6],e[7]=t.data[7],e[8]=t.data[8],e[9]=t.data[9],e[10]=t.data[10],e[11]=t.data[11]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11]))}if("mat4x2f"===s||"mat4x2h"===s){const e=new Float32Array(this.buffer,r,8);return void(t instanceof Yo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3],e[4]=t.data[4],e[5]=t.data[5],e[6]=t.data[6],e[7]=t.data[7]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7]))}if("mat4x3f"===s||"mat4x3h"===s){const e=new Float32Array(this.buffer,r,12);return void(t instanceof Yo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3],e[4]=t.data[4],e[5]=t.data[5],e[6]=t.data[6],e[7]=t.data[7],e[8]=t.data[8],e[9]=t.data[9],e[10]=t.data[10],e[11]=t.data[11]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11]))}if("mat4x4f"===s||"mat4x4h"===s){const e=new Float32Array(this.buffer,r,16);return void(t instanceof Yo?(e[0]=t.data[0],e[1]=t.data[1],e[2]=t.data[2],e[3]=t.data[3],e[4]=t.data[4],e[5]=t.data[5],e[6]=t.data[6],e[7]=t.data[7],e[8]=t.data[8],e[9]=t.data[9],e[10]=t.data[10],e[11]=t.data[11],e[12]=t.data[12],e[13]=t.data[13],e[14]=t.data[14],e[15]=t.data[15]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]))}if(t instanceof qo&&n===t.typeInfo)return void new Uint8Array(this.buffer,r,t.buffer.byteLength).set(new Uint8Array(t.buffer))}else t instanceof $o&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof $o&&(new Uint32Array(this.buffer,r,1)[0]=t.value);else t instanceof $o&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof $o&&(new Float32Array(this.buffer,r,1)[0]=t.value)}getSubData(e,t,n){var r,i;if(null===t)return this;let s=this.offset,o=this.typeInfo;for(;t;){if(t instanceof Io){const r=t.index,i=r instanceof xo?e.evalExpression(r,n):r;let a=0;if(i instanceof $o?a=i.value:"number"==typeof i&&(a=i),o instanceof ds)s+=a*o.stride,o=o.format;else{const t=o.getTypeName();("mat4x4"===t||"mat4x4f"===t||"mat4x4h"===t)&&(s+=16*a,o=e.getTypeInfo("vec4f"))}}else{if(!(t instanceof Eo))return null;{const n=t.value;if(o instanceof hs){let e=!1;for(const t of o.members)if(t.name===n){s+=t.offset,o=t.type,e=!0;break}if(!e)return null}else if(o instanceof cs){const t=o.getTypeName();if("vec2f"===t||"vec3f"===t||"vec4f"===t||"vec2i"===t||"vec3i"===t||"vec4i"===t||"vec2u"===t||"vec3u"===t||"vec4u"===t||"vec2b"===t||"vec3b"===t||"vec4b"===t||"vec2h"===t||"vec3h"===t||"vec4h"===t||"vec2"===t||"vec3"===t||"vec4"===t){if(n.length>0&&n.length<5){let r="f";const i=[];for(let o=0;o=this.buffer.byteLength)return null;const e=new Float32Array(this.buffer,s,3);i.push(e[A])}else if("vec4f"===t)i.push(new Float32Array(this.buffer,s,4)[A]);else if("vec2i"===t)r="i",i.push(new Int32Array(this.buffer,s,2)[A]);else if("vec3i"===t)r="i",i.push(new Int32Array(this.buffer,s,3)[A]);else if("vec4i"===t)r="i",i.push(new Int32Array(this.buffer,s,4)[A]);else if("vec2u"===t){r="u";const e=new Uint32Array(this.buffer,s,2);i.push(e[A])}else"vec3u"===t?(r="u",i.push(new Uint32Array(this.buffer,s,3)[A])):"vec4u"===t&&(r="u",i.push(new Uint32Array(this.buffer,s,4)[A]))}return 2===i.length?o=e.getTypeInfo(`vec2${r}`):3===i.length?o=e.getTypeInfo(`vec3${r}`):4===i.length&&(o=e.getTypeInfo(`vec4${r}`)),new Qo(i,o,null)}return null}return null}}}t=t.postfix}const a=o.getTypeName();return"f32"===a?new $o(new Float32Array(this.buffer,s,1),o,this):"i32"===a?new $o(new Int32Array(this.buffer,s,1),o,this):"u32"===a?new $o(new Uint32Array(this.buffer,s,1),o,this):"vec2f"===a?new Qo(new Float32Array(this.buffer,s,2),o,this):"vec3f"===a?new Qo(new Float32Array(this.buffer,s,3),o,this):"vec4f"===a?new Qo(new Float32Array(this.buffer,s,4),o,this):"vec2i"===a?new Qo(new Int32Array(this.buffer,s,2),o,this):"vec3i"===a?new Qo(new Int32Array(this.buffer,s,3),o,this):"vec4i"===a?new Qo(new Int32Array(this.buffer,s,4),o,this):"vec2u"===a?new Qo(new Uint32Array(this.buffer,s,2),o,this):"vec3u"===a?new Qo(new Uint32Array(this.buffer,s,3),o,this):"vec4u"===a?new Qo(new Uint32Array(this.buffer,s,4),o,this):o instanceof ps&&"atomic"===o.name?"u32"===(null===(r=o.format)||void 0===r?void 0:r.name)?new $o(new Uint32Array(this.buffer,s,1)[0],o.format,this):"i32"===(null===(i=o.format)||void 0===i?void 0:i.name)?new $o(new Int32Array(this.buffer,s,1)[0],o.format,this):null:new qo(this.buffer,o,s,this)}toString(){let e="";if(this.typeInfo instanceof ds)if("f32"===this.typeInfo.format.name){const t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n0?null!==(e=n[0])&&void 0!==e?e:0:n instanceof Object&&null!==(t=n.width)&&void 0!==t?t:0}get height(){var e,t;const n=this.descriptor.size;return n instanceof Array&&n.length>1?null!==(e=n[1])&&void 0!==e?e:0:n instanceof Object&&null!==(t=n.height)&&void 0!==t?t:0}get depthOrArrayLayers(){var e,t;const n=this.descriptor.size;return n instanceof Array&&n.length>2?null!==(e=n[2])&&void 0!==e?e:0:n instanceof Object&&null!==(t=n.depthOrArrayLayers)&&void 0!==t?t:0}get format(){var e;return this.descriptor&&null!==(e=this.descriptor.format)&&void 0!==e?e:"rgba8unorm"}get sampleCount(){var e;return this.descriptor&&null!==(e=this.descriptor.sampleCount)&&void 0!==e?e:1}get mipLevelCount(){var e;return this.descriptor&&null!==(e=this.descriptor.mipLevelCount)&&void 0!==e?e:1}get dimension(){var e;return this.descriptor&&null!==(e=this.descriptor.dimension)&&void 0!==e?e:"2d"}getMipLevelSize(e){if(e>=this.mipLevelCount)return[0,0,0];const t=[this.width,this.height,this.depthOrArrayLayers];for(let n=0;n>e);return t}get texelByteSize(){const e=this.format,t=Ds[e];return t?t.isDepthStencil?4:t.bytesPerBlock:0}get bytesPerRow(){return this.width*this.texelByteSize}get isDepthStencil(){const e=this.format,t=Ds[e];return!!t&&t.isDepthStencil}getGpuSize(){const e=this.format,t=Ds[e],n=this.width;if(!e||n<=0||!t)return-1;const r=this.height,i=this.depthOrArrayLayers,s=this.dimension;return n/t.blockWidth*("1d"===s?1:r/t.blockHeight)*t.bytesPerBlock*i}getPixel(e,t,n=0,r=0){const i=this.texelByteSize,s=this.bytesPerRow,o=this.height,a=this.data[r];return function(e,t,n,r,i,s,o,a,A){const l=r*(o>>=i)*(s>>=i)+n*o+t*a;switch(A){case"r8unorm":return[Ns(e,l,"8unorm",1)[0]];case"r8snorm":return[Ns(e,l,"8snorm",1)[0]];case"r8uint":return[Ns(e,l,"8uint",1)[0]];case"r8sint":return[Ns(e,l,"8sint",1)[0]];case"rg8unorm":{const t=Ns(e,l,"8unorm",2);return[t[0],t[1]]}case"rg8snorm":{const t=Ns(e,l,"8snorm",2);return[t[0],t[1]]}case"rg8uint":{const t=Ns(e,l,"8uint",2);return[t[0],t[1]]}case"rg8sint":{const t=Ns(e,l,"8sint",2);return[t[0],t[1]]}case"rgba8unorm-srgb":case"rgba8unorm":{const t=Ns(e,l,"8unorm",4);return[t[0],t[1],t[2],t[3]]}case"rgba8snorm":{const t=Ns(e,l,"8snorm",4);return[t[0],t[1],t[2],t[3]]}case"rgba8uint":{const t=Ns(e,l,"8uint",4);return[t[0],t[1],t[2],t[3]]}case"rgba8sint":{const t=Ns(e,l,"8sint",4);return[t[0],t[1],t[2],t[3]]}case"bgra8unorm-srgb":case"bgra8unorm":{const t=Ns(e,l,"8unorm",4);return[t[2],t[1],t[0],t[3]]}case"r16uint":return[Ns(e,l,"16uint",1)[0]];case"r16sint":return[Ns(e,l,"16sint",1)[0]];case"r16float":return[Ns(e,l,"16float",1)[0]];case"rg16uint":{const t=Ns(e,l,"16uint",2);return[t[0],t[1]]}case"rg16sint":{const t=Ns(e,l,"16sint",2);return[t[0],t[1]]}case"rg16float":{const t=Ns(e,l,"16float",2);return[t[0],t[1]]}case"rgba16uint":{const t=Ns(e,l,"16uint",4);return[t[0],t[1],t[2],t[3]]}case"rgba16sint":{const t=Ns(e,l,"16sint",4);return[t[0],t[1],t[2],t[3]]}case"rgba16float":{const t=Ns(e,l,"16float",4);return[t[0],t[1],t[2],t[3]]}case"r32uint":return[Ns(e,l,"32uint",1)[0]];case"r32sint":return[Ns(e,l,"32sint",1)[0]];case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return[Ns(e,l,"32float",1)[0]];case"rg32uint":{const t=Ns(e,l,"32uint",2);return[t[0],t[1]]}case"rg32sint":{const t=Ns(e,l,"32sint",2);return[t[0],t[1]]}case"rg32float":{const t=Ns(e,l,"32float",2);return[t[0],t[1]]}case"rgba32uint":{const t=Ns(e,l,"32uint",4);return[t[0],t[1],t[2],t[3]]}case"rgba32sint":{const t=Ns(e,l,"32sint",4);return[t[0],t[1],t[2],t[3]]}case"rgba32float":{const t=Ns(e,l,"32float",4);return[t[0],t[1],t[2],t[3]]}case"rg11b10ufloat":{const t=new Uint32Array(e.buffer,l,1)[0],n=(4192256&t)>>11,r=(4290772992&t)>>22;return[Ls(2047&t),Ls(n),function(e){const t=112+(e>>5&31)<<23|(31&e)<<18;return Is[0]=t,Ms[0]}(r),1]}}return null}(new Uint8Array(a),e,t,n,r,o,s,i,this.format)}setPixel(e,t,n,r,i){const s=this.texelByteSize,o=this.bytesPerRow,a=this.height,A=this.data[r];!function(e,t,n,r,i,s,o,a,A,l){const c=r*(o>>=i)*(s>>=i)+n*o+t*a;switch(A){case"r8unorm":return void Bs(e,c,"8unorm",1,l);case"r8snorm":return void Bs(e,c,"8snorm",1,l);case"r8uint":return void Bs(e,c,"8uint",1,l);case"r8sint":return void Bs(e,c,"8sint",1,l);case"rg8unorm":return void Bs(e,c,"8unorm",2,l);case"rg8snorm":return void Bs(e,c,"8snorm",2,l);case"rg8uint":return void Bs(e,c,"8uint",2,l);case"rg8sint":return void Bs(e,c,"8sint",2,l);case"rgba8unorm-srgb":case"rgba8unorm":case"bgra8unorm-srgb":case"bgra8unorm":return void Bs(e,c,"8unorm",4,l);case"rgba8snorm":return void Bs(e,c,"8snorm",4,l);case"rgba8uint":return void Bs(e,c,"8uint",4,l);case"rgba8sint":return void Bs(e,c,"8sint",4,l);case"r16uint":return void Bs(e,c,"16uint",1,l);case"r16sint":return void Bs(e,c,"16sint",1,l);case"r16float":return void Bs(e,c,"16float",1,l);case"rg16uint":return void Bs(e,c,"16uint",2,l);case"rg16sint":return void Bs(e,c,"16sint",2,l);case"rg16float":return void Bs(e,c,"16float",2,l);case"rgba16uint":return void Bs(e,c,"16uint",4,l);case"rgba16sint":return void Bs(e,c,"16sint",4,l);case"rgba16float":return void Bs(e,c,"16float",4,l);case"r32uint":return void Bs(e,c,"32uint",1,l);case"r32sint":return void Bs(e,c,"32sint",1,l);case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return void Bs(e,c,"32float",1,l);case"rg32uint":return void Bs(e,c,"32uint",2,l);case"rg32sint":return void Bs(e,c,"32sint",2,l);case"rg32float":return void Bs(e,c,"32float",2,l);case"rgba32uint":return void Bs(e,c,"32uint",4,l);case"rgba32sint":return void Bs(e,c,"32sint",4,l);case"rgba32float":Bs(e,c,"32float",4,l)}}(new Uint8Array(A),e,t,n,r,a,o,s,this.format,i)}}(e=>{e[e.token=0]="token",e[e.keyword=1]="keyword",e[e.reserved=2]="reserved"})(eo||(eo={}));class Zo{constructor(e,t,n){this.name=e,this.type=t,this.rule=n}toString(){return this.name}}class Jo{}Js=Jo,Jo.none=new Zo("",eo.reserved,""),Jo.eof=new Zo("EOF",eo.token,""),Jo.reserved={asm:new Zo("asm",eo.reserved,"asm"),bf16:new Zo("bf16",eo.reserved,"bf16"),do:new Zo("do",eo.reserved,"do"),enum:new Zo("enum",eo.reserved,"enum"),f16:new Zo("f16",eo.reserved,"f16"),f64:new Zo("f64",eo.reserved,"f64"),handle:new Zo("handle",eo.reserved,"handle"),i8:new Zo("i8",eo.reserved,"i8"),i16:new Zo("i16",eo.reserved,"i16"),i64:new Zo("i64",eo.reserved,"i64"),mat:new Zo("mat",eo.reserved,"mat"),premerge:new Zo("premerge",eo.reserved,"premerge"),regardless:new Zo("regardless",eo.reserved,"regardless"),typedef:new Zo("typedef",eo.reserved,"typedef"),u8:new Zo("u8",eo.reserved,"u8"),u16:new Zo("u16",eo.reserved,"u16"),u64:new Zo("u64",eo.reserved,"u64"),unless:new Zo("unless",eo.reserved,"unless"),using:new Zo("using",eo.reserved,"using"),vec:new Zo("vec",eo.reserved,"vec"),void:new Zo("void",eo.reserved,"void")},Jo.keywords={array:new Zo("array",eo.keyword,"array"),atomic:new Zo("atomic",eo.keyword,"atomic"),bool:new Zo("bool",eo.keyword,"bool"),f32:new Zo("f32",eo.keyword,"f32"),i32:new Zo("i32",eo.keyword,"i32"),mat2x2:new Zo("mat2x2",eo.keyword,"mat2x2"),mat2x3:new Zo("mat2x3",eo.keyword,"mat2x3"),mat2x4:new Zo("mat2x4",eo.keyword,"mat2x4"),mat3x2:new Zo("mat3x2",eo.keyword,"mat3x2"),mat3x3:new Zo("mat3x3",eo.keyword,"mat3x3"),mat3x4:new Zo("mat3x4",eo.keyword,"mat3x4"),mat4x2:new Zo("mat4x2",eo.keyword,"mat4x2"),mat4x3:new Zo("mat4x3",eo.keyword,"mat4x3"),mat4x4:new Zo("mat4x4",eo.keyword,"mat4x4"),ptr:new Zo("ptr",eo.keyword,"ptr"),sampler:new Zo("sampler",eo.keyword,"sampler"),sampler_comparison:new Zo("sampler_comparison",eo.keyword,"sampler_comparison"),struct:new Zo("struct",eo.keyword,"struct"),texture_1d:new Zo("texture_1d",eo.keyword,"texture_1d"),texture_2d:new Zo("texture_2d",eo.keyword,"texture_2d"),texture_2d_array:new Zo("texture_2d_array",eo.keyword,"texture_2d_array"),texture_3d:new Zo("texture_3d",eo.keyword,"texture_3d"),texture_cube:new Zo("texture_cube",eo.keyword,"texture_cube"),texture_cube_array:new Zo("texture_cube_array",eo.keyword,"texture_cube_array"),texture_multisampled_2d:new Zo("texture_multisampled_2d",eo.keyword,"texture_multisampled_2d"),texture_storage_1d:new Zo("texture_storage_1d",eo.keyword,"texture_storage_1d"),texture_storage_2d:new Zo("texture_storage_2d",eo.keyword,"texture_storage_2d"),texture_storage_2d_array:new Zo("texture_storage_2d_array",eo.keyword,"texture_storage_2d_array"),texture_storage_3d:new Zo("texture_storage_3d",eo.keyword,"texture_storage_3d"),texture_depth_2d:new Zo("texture_depth_2d",eo.keyword,"texture_depth_2d"),texture_depth_2d_array:new Zo("texture_depth_2d_array",eo.keyword,"texture_depth_2d_array"),texture_depth_cube:new Zo("texture_depth_cube",eo.keyword,"texture_depth_cube"),texture_depth_cube_array:new Zo("texture_depth_cube_array",eo.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new Zo("texture_depth_multisampled_2d",eo.keyword,"texture_depth_multisampled_2d"),texture_external:new Zo("texture_external",eo.keyword,"texture_external"),u32:new Zo("u32",eo.keyword,"u32"),vec2:new Zo("vec2",eo.keyword,"vec2"),vec3:new Zo("vec3",eo.keyword,"vec3"),vec4:new Zo("vec4",eo.keyword,"vec4"),bitcast:new Zo("bitcast",eo.keyword,"bitcast"),block:new Zo("block",eo.keyword,"block"),break:new Zo("break",eo.keyword,"break"),case:new Zo("case",eo.keyword,"case"),continue:new Zo("continue",eo.keyword,"continue"),continuing:new Zo("continuing",eo.keyword,"continuing"),default:new Zo("default",eo.keyword,"default"),diagnostic:new Zo("diagnostic",eo.keyword,"diagnostic"),discard:new Zo("discard",eo.keyword,"discard"),else:new Zo("else",eo.keyword,"else"),enable:new Zo("enable",eo.keyword,"enable"),fallthrough:new Zo("fallthrough",eo.keyword,"fallthrough"),false:new Zo("false",eo.keyword,"false"),fn:new Zo("fn",eo.keyword,"fn"),for:new Zo("for",eo.keyword,"for"),function:new Zo("function",eo.keyword,"function"),if:new Zo("if",eo.keyword,"if"),let:new Zo("let",eo.keyword,"let"),const:new Zo("const",eo.keyword,"const"),loop:new Zo("loop",eo.keyword,"loop"),while:new Zo("while",eo.keyword,"while"),private:new Zo("private",eo.keyword,"private"),read:new Zo("read",eo.keyword,"read"),read_write:new Zo("read_write",eo.keyword,"read_write"),return:new Zo("return",eo.keyword,"return"),requires:new Zo("requires",eo.keyword,"requires"),storage:new Zo("storage",eo.keyword,"storage"),switch:new Zo("switch",eo.keyword,"switch"),true:new Zo("true",eo.keyword,"true"),alias:new Zo("alias",eo.keyword,"alias"),type:new Zo("type",eo.keyword,"type"),uniform:new Zo("uniform",eo.keyword,"uniform"),var:new Zo("var",eo.keyword,"var"),override:new Zo("override",eo.keyword,"override"),workgroup:new Zo("workgroup",eo.keyword,"workgroup"),write:new Zo("write",eo.keyword,"write"),r8unorm:new Zo("r8unorm",eo.keyword,"r8unorm"),r8snorm:new Zo("r8snorm",eo.keyword,"r8snorm"),r8uint:new Zo("r8uint",eo.keyword,"r8uint"),r8sint:new Zo("r8sint",eo.keyword,"r8sint"),r16uint:new Zo("r16uint",eo.keyword,"r16uint"),r16sint:new Zo("r16sint",eo.keyword,"r16sint"),r16float:new Zo("r16float",eo.keyword,"r16float"),rg8unorm:new Zo("rg8unorm",eo.keyword,"rg8unorm"),rg8snorm:new Zo("rg8snorm",eo.keyword,"rg8snorm"),rg8uint:new Zo("rg8uint",eo.keyword,"rg8uint"),rg8sint:new Zo("rg8sint",eo.keyword,"rg8sint"),r32uint:new Zo("r32uint",eo.keyword,"r32uint"),r32sint:new Zo("r32sint",eo.keyword,"r32sint"),r32float:new Zo("r32float",eo.keyword,"r32float"),rg16uint:new Zo("rg16uint",eo.keyword,"rg16uint"),rg16sint:new Zo("rg16sint",eo.keyword,"rg16sint"),rg16float:new Zo("rg16float",eo.keyword,"rg16float"),rgba8unorm:new Zo("rgba8unorm",eo.keyword,"rgba8unorm"),rgba8unorm_srgb:new Zo("rgba8unorm_srgb",eo.keyword,"rgba8unorm_srgb"),rgba8snorm:new Zo("rgba8snorm",eo.keyword,"rgba8snorm"),rgba8uint:new Zo("rgba8uint",eo.keyword,"rgba8uint"),rgba8sint:new Zo("rgba8sint",eo.keyword,"rgba8sint"),bgra8unorm:new Zo("bgra8unorm",eo.keyword,"bgra8unorm"),bgra8unorm_srgb:new Zo("bgra8unorm_srgb",eo.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new Zo("rgb10a2unorm",eo.keyword,"rgb10a2unorm"),rg11b10float:new Zo("rg11b10float",eo.keyword,"rg11b10float"),rg32uint:new Zo("rg32uint",eo.keyword,"rg32uint"),rg32sint:new Zo("rg32sint",eo.keyword,"rg32sint"),rg32float:new Zo("rg32float",eo.keyword,"rg32float"),rgba16uint:new Zo("rgba16uint",eo.keyword,"rgba16uint"),rgba16sint:new Zo("rgba16sint",eo.keyword,"rgba16sint"),rgba16float:new Zo("rgba16float",eo.keyword,"rgba16float"),rgba32uint:new Zo("rgba32uint",eo.keyword,"rgba32uint"),rgba32sint:new Zo("rgba32sint",eo.keyword,"rgba32sint"),rgba32float:new Zo("rgba32float",eo.keyword,"rgba32float"),static_assert:new Zo("static_assert",eo.keyword,"static_assert")},Jo.tokens={decimal_float_literal:new Zo("decimal_float_literal",eo.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 Zo("hex_float_literal",eo.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 Zo("int_literal",eo.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new Zo("uint_literal",eo.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),name:new Zo("name",eo.token,/([_\p{XID_Start}][\p{XID_Continue}]+)|([\p{XID_Start}])/u),ident:new Zo("ident",eo.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new Zo("and",eo.token,"&"),and_and:new Zo("and_and",eo.token,"&&"),arrow:new Zo("arrow ",eo.token,"->"),attr:new Zo("attr",eo.token,"@"),forward_slash:new Zo("forward_slash",eo.token,"/"),bang:new Zo("bang",eo.token,"!"),bracket_left:new Zo("bracket_left",eo.token,"["),bracket_right:new Zo("bracket_right",eo.token,"]"),brace_left:new Zo("brace_left",eo.token,"{"),brace_right:new Zo("brace_right",eo.token,"}"),colon:new Zo("colon",eo.token,":"),comma:new Zo("comma",eo.token,","),equal:new Zo("equal",eo.token,"="),equal_equal:new Zo("equal_equal",eo.token,"=="),not_equal:new Zo("not_equal",eo.token,"!="),greater_than:new Zo("greater_than",eo.token,">"),greater_than_equal:new Zo("greater_than_equal",eo.token,">="),shift_right:new Zo("shift_right",eo.token,">>"),less_than:new Zo("less_than",eo.token,"<"),less_than_equal:new Zo("less_than_equal",eo.token,"<="),shift_left:new Zo("shift_left",eo.token,"<<"),modulo:new Zo("modulo",eo.token,"%"),minus:new Zo("minus",eo.token,"-"),minus_minus:new Zo("minus_minus",eo.token,"--"),period:new Zo("period",eo.token,"."),plus:new Zo("plus",eo.token,"+"),plus_plus:new Zo("plus_plus",eo.token,"++"),or:new Zo("or",eo.token,"|"),or_or:new Zo("or_or",eo.token,"||"),paren_left:new Zo("paren_left",eo.token,"("),paren_right:new Zo("paren_right",eo.token,")"),semicolon:new Zo("semicolon",eo.token,";"),star:new Zo("star",eo.token,"*"),tilde:new Zo("tilde",eo.token,"~"),underscore:new Zo("underscore",eo.token,"_"),xor:new Zo("xor",eo.token,"^"),plus_equal:new Zo("plus_equal",eo.token,"+="),minus_equal:new Zo("minus_equal",eo.token,"-="),times_equal:new Zo("times_equal",eo.token,"*="),division_equal:new Zo("division_equal",eo.token,"/="),modulo_equal:new Zo("modulo_equal",eo.token,"%="),and_equal:new Zo("and_equal",eo.token,"&="),or_equal:new Zo("or_equal",eo.token,"|="),xor_equal:new Zo("xor_equal",eo.token,"^="),shift_right_equal:new Zo("shift_right_equal",eo.token,">>="),shift_left_equal:new Zo("shift_left_equal",eo.token,"<<=")},Jo.simpleTokens={"@":Js.tokens.attr,"{":Js.tokens.brace_left,"}":Js.tokens.brace_right,":":Js.tokens.colon,",":Js.tokens.comma,"(":Js.tokens.paren_left,")":Js.tokens.paren_right,";":Js.tokens.semicolon},Jo.literalTokens={"&":Js.tokens.and,"&&":Js.tokens.and_and,"->":Js.tokens.arrow,"/":Js.tokens.forward_slash,"!":Js.tokens.bang,"[":Js.tokens.bracket_left,"]":Js.tokens.bracket_right,"=":Js.tokens.equal,"==":Js.tokens.equal_equal,"!=":Js.tokens.not_equal,">":Js.tokens.greater_than,">=":Js.tokens.greater_than_equal,">>":Js.tokens.shift_right,"<":Js.tokens.less_than,"<=":Js.tokens.less_than_equal,"<<":Js.tokens.shift_left,"%":Js.tokens.modulo,"-":Js.tokens.minus,"--":Js.tokens.minus_minus,".":Js.tokens.period,"+":Js.tokens.plus,"++":Js.tokens.plus_plus,"|":Js.tokens.or,"||":Js.tokens.or_or,"*":Js.tokens.star,"~":Js.tokens.tilde,_:Js.tokens.underscore,"^":Js.tokens.xor,"+=":Js.tokens.plus_equal,"-=":Js.tokens.minus_equal,"*=":Js.tokens.times_equal,"/=":Js.tokens.division_equal,"%=":Js.tokens.modulo_equal,"&=":Js.tokens.and_equal,"|=":Js.tokens.or_equal,"^=":Js.tokens.xor_equal,">>=":Js.tokens.shift_right_equal,"<<=":Js.tokens.shift_left_equal},Jo.regexTokens={decimal_float_literal:Js.tokens.decimal_float_literal,hex_float_literal:Js.tokens.hex_float_literal,int_literal:Js.tokens.int_literal,uint_literal:Js.tokens.uint_literal,ident:Js.tokens.ident},Jo.storage_class=[Js.keywords.function,Js.keywords.private,Js.keywords.workgroup,Js.keywords.uniform,Js.keywords.storage],Jo.access_mode=[Js.keywords.read,Js.keywords.write,Js.keywords.read_write],Jo.sampler_type=[Js.keywords.sampler,Js.keywords.sampler_comparison],Jo.sampled_texture_type=[Js.keywords.texture_1d,Js.keywords.texture_2d,Js.keywords.texture_2d_array,Js.keywords.texture_3d,Js.keywords.texture_cube,Js.keywords.texture_cube_array],Jo.multisampled_texture_type=[Js.keywords.texture_multisampled_2d],Jo.storage_texture_type=[Js.keywords.texture_storage_1d,Js.keywords.texture_storage_2d,Js.keywords.texture_storage_2d_array,Js.keywords.texture_storage_3d],Jo.depth_texture_type=[Js.keywords.texture_depth_2d,Js.keywords.texture_depth_2d_array,Js.keywords.texture_depth_cube,Js.keywords.texture_depth_cube_array,Js.keywords.texture_depth_multisampled_2d],Jo.texture_external_type=[Js.keywords.texture_external],Jo.any_texture_type=[...Js.sampled_texture_type,...Js.multisampled_texture_type,...Js.storage_texture_type,...Js.depth_texture_type,...Js.texture_external_type],Jo.texel_format=[Js.keywords.r8unorm,Js.keywords.r8snorm,Js.keywords.r8uint,Js.keywords.r8sint,Js.keywords.r16uint,Js.keywords.r16sint,Js.keywords.r16float,Js.keywords.rg8unorm,Js.keywords.rg8snorm,Js.keywords.rg8uint,Js.keywords.rg8sint,Js.keywords.r32uint,Js.keywords.r32sint,Js.keywords.r32float,Js.keywords.rg16uint,Js.keywords.rg16sint,Js.keywords.rg16float,Js.keywords.rgba8unorm,Js.keywords.rgba8unorm_srgb,Js.keywords.rgba8snorm,Js.keywords.rgba8uint,Js.keywords.rgba8sint,Js.keywords.bgra8unorm,Js.keywords.bgra8unorm_srgb,Js.keywords.rgb10a2unorm,Js.keywords.rg11b10float,Js.keywords.rg32uint,Js.keywords.rg32sint,Js.keywords.rg32float,Js.keywords.rgba16uint,Js.keywords.rgba16sint,Js.keywords.rgba16float,Js.keywords.rgba32uint,Js.keywords.rgba32sint,Js.keywords.rgba32float],Jo.const_literal=[Js.tokens.int_literal,Js.tokens.uint_literal,Js.tokens.decimal_float_literal,Js.tokens.hex_float_literal,Js.keywords.true,Js.keywords.false],Jo.literal_or_ident=[Js.tokens.ident,Js.tokens.int_literal,Js.tokens.uint_literal,Js.tokens.decimal_float_literal,Js.tokens.hex_float_literal,Js.tokens.name],Jo.element_count_expression=[Js.tokens.int_literal,Js.tokens.uint_literal,Js.tokens.ident],Jo.template_types=[Js.keywords.vec2,Js.keywords.vec3,Js.keywords.vec4,Js.keywords.mat2x2,Js.keywords.mat2x3,Js.keywords.mat2x4,Js.keywords.mat3x2,Js.keywords.mat3x3,Js.keywords.mat3x4,Js.keywords.mat4x2,Js.keywords.mat4x3,Js.keywords.mat4x4,Js.keywords.atomic,Js.keywords.bitcast,...Js.any_texture_type],Jo.attribute_name=[Js.tokens.ident,Js.keywords.block,Js.keywords.diagnostic],Jo.assignment_operators=[Js.tokens.equal,Js.tokens.plus_equal,Js.tokens.minus_equal,Js.tokens.times_equal,Js.tokens.division_equal,Js.tokens.modulo_equal,Js.tokens.and_equal,Js.tokens.or_equal,Js.tokens.xor_equal,Js.tokens.shift_right_equal,Js.tokens.shift_left_equal],Jo.increment_operators=[Js.tokens.plus_plus,Js.tokens.minus_minus];class ea{constructor(e,t,n,r,i){this.type=e,this.lexeme=t,this.line=n,this.start=r,this.end=i}toString(){return this.lexeme}isTemplateType(){return-1!=Jo.template_types.indexOf(this.type)}isArrayType(){return this.type==Jo.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}}class ta{constructor(e){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=null!=e?e:""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new ea(Jo.eof,"",this._line,this._current,this._current)),this._tokens}scanToken(){let e=this._advance();if("\n"==e)return this._line++,!0;if(this._isWhitespace(e))return!0;if("/"==e){if("/"==this._peekAhead()){for(;"\n"!=e;){if(this._isAtEnd())return!0;e=this._advance()}return this._line++,!0}if("*"==this._peekAhead()){this._advance();let t=1;for(;t>0;){if(this._isAtEnd())return!0;if(e=this._advance(),"\n"==e)this._line++;else if("*"==e){if("/"==this._peekAhead()&&(this._advance(),t--,0==t))return!0}else"/"==e&&"*"==this._peekAhead()&&(this._advance(),t++)}return!0}}const t=Jo.simpleTokens[e];if(t)return this._addToken(t),!0;let n=Jo.none;const r=this._isAlpha(e),i="_"===e;if(this._isAlphaNumeric(e)){let t=this._peekAhead();for(;this._isAlphaNumeric(t);)e+=this._advance(),t=this._peekAhead()}if(r){const t=Jo.keywords[e];if(t)return this._addToken(t),!0}if(r||i)return this._addToken(Jo.tokens.ident),!0;for(;;){let t=this._findType(e);const r=this._peekAhead();if("-"==e&&this._tokens.length>0){if("="==r)return this._current++,e+=r,this._addToken(Jo.tokens.minus_equal),!0;if("-"==r)return this._current++,e+=r,this._addToken(Jo.tokens.minus_minus),!0;const n=this._tokens.length-1;if((-1!=Jo.literal_or_ident.indexOf(this._tokens[n].type)||this._tokens[n].type==Jo.tokens.paren_right)&&">"!=r)return this._addToken(t),!0}if(">"==e&&(">"==r||"="==r)){let e=!1,n=this._tokens.length-1;for(let t=0;t<5&&n>=0&&-1===Jo.assignment_operators.indexOf(this._tokens[n].type);++t,--n)if(this._tokens[n].type===Jo.tokens.less_than){n>0&&this._tokens[n-1].isArrayOrTemplateType()&&(e=!0);break}if(e)return this._addToken(t),!0}if(t===Jo.none){let r=e,i=0;const s=2;for(let e=0;e=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&&"\n"!==e&&"\r"!==e&&"\t"!==e&&"\0"!==e}_isNumeric(e){return e>="0"&&e<="9"}_isAlphaNumeric(e){return this._isAlpha(e)||this._isNumeric(e)||"_"===e}_isWhitespace(e){return" "==e||"\t"==e||"\r"==e}_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){const t=this._source.substring(this._start,this._current);this._tokens.push(new ea(e,t,this._line,this._start,this._current))}}function na(e){return Array.isArray(e)||(null==e?void 0:e.buffer)instanceof ArrayBuffer}const ra=new Float32Array(1),ia=new Uint32Array(ra.buffer),sa=new Uint32Array(ra.buffer),oa=new Int32Array(1),aa=new Float32Array(oa.buffer),Aa=new Uint32Array(oa.buffer),la=new Uint32Array(1),ca=new Float32Array(la.buffer),ua=new Int32Array(la.buffer);function ha(e,t,n){if(t===n)return e;if("f32"===t){if("i32"===n||"x32"===n)return ra[0]=e,ia[0];if("u32"===n)return ra[0]=e,sa[0]}else if("i32"===t||"x32"===t){if("f32"===n)return oa[0]=e,aa[0];if("u32"===n)return oa[0]=e,Aa[0]}else if("u32"===t){if("f32"===n)return la[0]=e,ca[0];if("i32"===n||"x32"===n)return la[0]=e,ua[0]}return e}class da{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}}class fa{constructor(e,t){this.align=e,this.size=t}}class pa{constructor(){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new Ts,this.functions=[],this._types=new Map,this._functions=new Map}_isStorageTexture(e){return"texture_storage_1d"==e.name||"texture_storage_2d"==e.name||"texture_storage_2d_array"==e.name||"texture_storage_3d"==e.name}updateAST(e){for(const t of e)t instanceof zs&&this._functions.set(t.name,new da(t));for(const t of e)if(t instanceof _o){const e=this.getTypeInfo(t,null);e instanceof hs&&this.structs.push(e)}for(const t of e)if(t instanceof uo)this.aliases.push(this._getAliasInfo(t));else{if(t instanceof Qs){const e=t,n=this._getAttributeNum(e.attributes,"id",0),r=null!=e.type?this.getTypeInfo(e.type,e.attributes):null;this.overrides.push(new ws(e.name,r,e.attributes,n));continue}if(this._isUniformVar(t)){const e=t,n=this._getAttributeNum(e.attributes,"group",0),r=this._getAttributeNum(e.attributes,"binding",0),i=this.getTypeInfo(e.type,e.attributes),s=new _s(e.name,i,n,r,e.attributes,gs.Uniform,e.access);s.access||(s.access="read"),this.uniforms.push(s);continue}if(this._isStorageVar(t)){const e=t,n=this._getAttributeNum(e.attributes,"group",0),r=this._getAttributeNum(e.attributes,"binding",0),i=this.getTypeInfo(e.type,e.attributes),s=this._isStorageTexture(i),o=new _s(e.name,i,n,r,e.attributes,s?gs.StorageTexture:gs.Storage,e.access);o.access||(o.access="read"),this.storage.push(o);continue}if(this._isTextureVar(t)){const e=t,n=this._getAttributeNum(e.attributes,"group",0),r=this._getAttributeNum(e.attributes,"binding",0),i=this.getTypeInfo(e.type,e.attributes),s=this._isStorageTexture(i),o=new _s(e.name,i,n,r,e.attributes,s?gs.StorageTexture:gs.Texture,e.access);o.access||(o.access="read"),s?this.storage.push(o):this.textures.push(o);continue}if(this._isSamplerVar(t)){const e=t,n=this._getAttributeNum(e.attributes,"group",0),r=this._getAttributeNum(e.attributes,"binding",0),i=this.getTypeInfo(e.type,e.attributes),s=new _s(e.name,i,n,r,e.attributes,gs.Sampler,e.access);this.samplers.push(s);continue}}for(const t of e)if(t instanceof zs){const e=this._getAttribute(t,"vertex"),n=this._getAttribute(t,"fragment"),r=this._getAttribute(t,"compute"),i=e||n||r,s=new Es(t.name,null==i?void 0:i.name,t.attributes);s.attributes=t.attributes,s.startLine=t.startLine,s.endLine=t.endLine,this.functions.push(s),this._functions.get(t.name).info=s,i&&(this._functions.get(t.name).inUse=!0,s.inUse=!0,s.resources=this._findResources(t,!!i),s.inputs=this._getInputs(t.args),s.outputs=this._getOutputs(t.returnType),this.entry[i.name].push(s)),s.arguments=t.args.map(e=>new xs(e.name,this.getTypeInfo(e.type,e.attributes),e.attributes)),s.returnType=t.returnType?this.getTypeInfo(t.returnType,t.attributes):null;continue}for(const t of this._functions.values())t.info&&(t.info.inUse=t.inUse,this._addCalls(t.node,t.info.calls));for(const t of this._functions.values())t.node.search(e=>{var n,r,i;if(e instanceof zo){if(e.value)if(na(e.value))for(const s of e.value)for(const e of this.overrides)s===e.name&&(null===(n=t.info)||void 0===n||n.overrides.push(e));else for(const s of this.overrides)e.value===s.name&&(null===(r=t.info)||void 0===r||r.overrides.push(s))}else if(e instanceof Co)for(const s of this.overrides)e.name===s.name&&(null===(i=t.info)||void 0===i||i.overrides.push(s))});for(const t of this.uniforms)this._markStructsInUse(t.type);for(const t of this.storage)this._markStructsInUse(t.type)}getFunctionInfo(e){for(const t of this.functions)if(t.name==e)return t;return null}getStructInfo(e){for(const t of this.structs)if(t.name==e)return t;return null}getOverrideInfo(e){for(const 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(const 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{const t=this._getAlias(e.name);t&&this._markStructsInUse(t)}}_addCalls(e,t){var n;for(const r of e.calls){const e=null===(n=this._functions.get(r.name))||void 0===n?void 0:n.info;e&&t.add(e)}}findResource(e,t,n){if(n){for(const r of this.entry.compute)if(r.name===n)for(const n of r.resources)if(n.group==e&&n.binding==t)return n;for(const r of this.entry.vertex)if(r.name===n)for(const n of r.resources)if(n.group==e&&n.binding==t)return n;for(const r of this.entry.fragment)if(r.name===n)for(const n of r.resources)if(n.group==e&&n.binding==t)return n}for(const r of this.uniforms)if(r.group==e&&r.binding==t)return r;for(const r of this.storage)if(r.group==e&&r.binding==t)return r;for(const r of this.textures)if(r.group==e&&r.binding==t)return r;for(const r of this.samplers)if(r.group==e&&r.binding==t)return r;return null}_findResource(e){for(const t of this.uniforms)if(t.name==e)return t;for(const t of this.storage)if(t.name==e)return t;for(const t of this.textures)if(t.name==e)return t;for(const t of this.samplers)if(t.name==e)return t;return null}_markStructsFromAST(e){const t=this.getTypeInfo(e,null);this._markStructsInUse(t)}_findResources(e,t){const n=[],r=this,i=[];return e.search(s=>{if(s instanceof Fs)i.push({});else if(s instanceof Us)i.pop();else if(s instanceof Xs){const e=s;t&&null!==e.type&&this._markStructsFromAST(e.type),i.length>0&&(i[i.length-1][e.name]=e)}else if(s instanceof To){const e=s;t&&null!==e.type&&this._markStructsFromAST(e.type)}else if(s instanceof Ys){const e=s;t&&null!==e.type&&this._markStructsFromAST(e.type),i.length>0&&(i[i.length-1][e.name]=e)}else if(s instanceof Co){const e=s;if(i.length>0&&i[i.length-1][e.name])return;const t=r._findResource(e.name);t&&n.push(t)}else if(s instanceof So){const i=s,o=r._functions.get(i.name);o&&(t&&(o.inUse=!0),e.calls.add(o.node),null===o.resources&&(o.resources=r._findResources(o.node,t)),n.push(...o.resources))}else if(s instanceof ro){const i=s,o=r._functions.get(i.name);o&&(t&&(o.inUse=!0),e.calls.add(o.node),null===o.resources&&(o.resources=r._findResources(o.node,t)),n.push(...o.resources))}}),[...new Map(n.map(e=>[e.name,e])).values()]}getBindGroups(){const e=[];function t(t,n){t>=e.length&&(e.length=t+1),void 0===e[t]&&(e[t]=[]),n>=e[t].length&&(e[t].length=n+1)}for(const n of this.uniforms)t(n.group,n.binding),e[n.group][n.binding]=n;for(const n of this.storage)t(n.group,n.binding),e[n.group][n.binding]=n;for(const n of this.textures)t(n.group,n.binding),e[n.group][n.binding]=n;for(const n of this.samplers)t(n.group,n.binding),e[n.group][n.binding]=n;return e}_getOutputs(e,t=void 0){if(void 0===t&&(t=[]),e instanceof _o)this._getStructOutputs(e,t);else{const n=this._getOutputInfo(e);null!==n&&t.push(n)}return t}_getStructOutputs(e,t){for(const n of e.members)if(n.type instanceof _o)this._getStructOutputs(n.type,t);else{const e=this._getAttribute(n,"location")||this._getAttribute(n,"builtin");if(null!==e){const r=this.getTypeInfo(n.type,n.type.attributes),i=this._parseInt(e.value),s=new ys(n.name,r,e.name,i);t.push(s)}}}_getOutputInfo(e){const t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(null!==t){const n=this.getTypeInfo(e,e.attributes),r=this._parseInt(t.value);return new ys("",n,t.name,r)}return null}_getInputs(e,t=void 0){void 0===t&&(t=[]);for(const n of e)if(n.type instanceof _o)this._getStructInputs(n.type,t);else{const e=this._getInputInfo(n);null!==e&&t.push(e)}return t}_getStructInputs(e,t){for(const n of e.members)if(n.type instanceof _o)this._getStructInputs(n.type,t);else{const e=this._getInputInfo(n);null!==e&&t.push(e)}}_getInputInfo(e){const t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(null!==t){const n=this._getAttribute(e,"interpolation"),r=this.getTypeInfo(e.type,e.attributes),i=this._parseInt(t.value),s=new vs(e.name,r,t.name,i);return null!==n&&(s.interpolation=this._parseString(n.value)),s}return null}_parseString(e){return e instanceof Array&&(e=e[0]),e}_parseInt(e){e instanceof Array&&(e=e[0]);const t=parseInt(e);return isNaN(t)?e:t}_getAlias(e){for(const t of this.aliases)if(t.name==e)return t.type;return null}_getAliasInfo(e){return new bs(e.name,this.getTypeInfo(e.type,null))}getTypeInfoByName(e){for(const t of this.structs)if(t.name==e)return t;for(const 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 vo){const n=e.type?this.getTypeInfo(e.type,e.attributes):null,r=new fs(e.name,n,t);return this._types.set(e,r),this._updateTypeInfo(r),r}if(e instanceof yo){const n=e,r=n.format?this.getTypeInfo(n.format,n.attributes):null,i=new ds(n.name,t);return i.format=r,i.count=n.count,this._types.set(e,i),this._updateTypeInfo(i),i}if(e instanceof _o){const n=e,r=new hs(n.name,t);r.startLine=n.startLine,r.endLine=n.endLine;for(const e of n.members){const t=this.getTypeInfo(e.type,e.attributes);r.members.push(new us(e.name,t,e.attributes))}return this._types.set(e,r),this._updateTypeInfo(r),r}if(e instanceof wo){const n=e,r=n.format instanceof go,i=n.format?r?this.getTypeInfo(n.format,null):new cs(n.format,null):null,s=new ps(n.name,i,t,n.access);return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof bo){const n=e,r=n.format?this.getTypeInfo(n.format,null):null,i=new ps(n.name,r,t,n.access);return this._types.set(e,i),this._updateTypeInfo(i),i}const n=new cs(e.name,t);return this._types.set(e,n),this._updateTypeInfo(n),n}_updateTypeInfo(e){var t,n,r;const i=this._getTypeSize(e);if(e.size=null!==(t=null==i?void 0:i.size)&&void 0!==t?t:0,e instanceof ds&&e.format){const t=this._getTypeSize(e.format);e.stride=Math.max(null!==(n=null==t?void 0:t.size)&&void 0!==n?n:0,null!==(r=null==t?void 0:t.align)&&void 0!==r?r:0),this._updateTypeInfo(e.format)}e instanceof fs&&this._updateTypeInfo(e.format),e instanceof hs&&this._updateStructInfo(e)}_updateStructInfo(e){var t;let n=0,r=0,i=0,s=0;for(let o=0,a=e.members.length;oe.name),pa._samplerTypes=Jo.sampler_type.map(e=>e.name);let ga=0;class ma{constructor(e,t,n){this.id=ga++,this.name=e,this.value=t,this.node=n}clone(){return new ma(this.name,this.value,this.node)}}class _a{constructor(e){this.id=ga++,this.name=e.name,this.node=e}clone(){return new _a(this.node)}}class ba{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName="",this.id=ga++,e&&(this.parent=e,this.currentFunctionName=e.currentFunctionName)}getVariable(e){var t;return this.variables.has(e)?null!==(t=this.variables.get(e))&&void 0!==t?t:null:this.parent?this.parent.getVariable(e):null}getFunction(e){var t;return this.functions.has(e)?null!==(t=this.functions.get(e))&&void 0!==t?t:null:this.parent?this.parent.getFunction(e):null}createVariable(e,t,n){this.variables.set(e,new ma(e,t,null!=n?n:null))}setVariable(e,t,n){const r=this.getVariable(e);null!==r?r.value=t:this.createVariable(e,t,n)}getVariableValue(e){var t;const n=this.getVariable(e);return null!==(t=null==n?void 0:n.value)&&void 0!==t?t:null}clone(){return new ba(this)}}class va{evalExpression(e,t){return null}getTypeInfo(e){return null}getVariableName(e,t){return""}}class ya{constructor(e){this.exec=e}getTypeInfo(e){return this.exec.getTypeInfo(e)}All(e,t){const n=this.exec.evalExpression(e.args[0],t);let r=!0;if(n instanceof Qo)return n.data.forEach(e=>{e||(r=!1)}),new $o(r?1:0,this.getTypeInfo("bool"));throw new Error(`All() expects a vector argument. Line ${e.line}`)}Any(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo){const e=n.data.some(e=>e);return new $o(e?1:0,this.getTypeInfo("bool"))}throw new Error(`Any() expects a vector argument. Line ${e.line}`)}Select(e,t){const n=this.exec.evalExpression(e.args[2],t);if(!(n instanceof $o))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 Lo&&(n=n.right);const r=this.exec.evalExpression(n,t);if(r instanceof qo&&0===r.typeInfo.size){const e=r.typeInfo,t=r.buffer.byteLength/e.stride;return new $o(t,this.getTypeInfo("u32"))}return new $o(r.typeInfo.size,this.getTypeInfo("u32"))}Abs(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.abs(e)),n.typeInfo);const r=n;return new $o(Math.abs(r.value),r.typeInfo)}Acos(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.acos(e)),n.typeInfo);const r=n;return new $o(Math.acos(r.value),n.typeInfo)}Acosh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.acosh(e)),n.typeInfo);const r=n;return new $o(Math.acosh(r.value),n.typeInfo)}Asin(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.asin(e)),n.typeInfo);const r=n;return new $o(Math.asin(r.value),n.typeInfo)}Asinh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.asinh(e)),n.typeInfo);const r=n;return new $o(Math.asinh(r.value),n.typeInfo)}Atan(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.atan(e)),n.typeInfo);const r=n;return new $o(Math.atan(r.value),n.typeInfo)}Atanh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.atanh(e)),n.typeInfo);const r=n;return new $o(Math.atanh(r.value),n.typeInfo)}Atan2(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof Qo&&r instanceof Qo)return new Qo(n.data.map((e,t)=>Math.atan2(e,r.data[t])),n.typeInfo);const i=n,s=r;return new $o(Math.atan2(i.value,s.value),n.typeInfo)}Ceil(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.ceil(e)),n.typeInfo);const r=n;return new $o(Math.ceil(r.value),n.typeInfo)}_clamp(e,t,n){return Math.min(Math.max(e,t),n)}Clamp(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),i=this.exec.evalExpression(e.args[2],t);if(n instanceof Qo&&r instanceof Qo&&i instanceof Qo)return new Qo(n.data.map((e,t)=>this._clamp(e,r.data[t],i.data[t])),n.typeInfo);const s=n,o=r,a=i;return new $o(this._clamp(s.value,o.value,a.value),n.typeInfo)}Cos(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.cos(e)),n.typeInfo);const r=n;return new $o(Math.cos(r.value),n.typeInfo)}Cosh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.cosh(e)),n.typeInfo);const r=n;return new $o(Math.cos(r.value),n.typeInfo)}CountLeadingZeros(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.clz32(e)),n.typeInfo);const r=n;return new $o(Math.clz32(r.value),n.typeInfo)}_countOneBits(e){let t=0;for(;0!==e;)1&e&&t++,e>>=1;return t}CountOneBits(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>this._countOneBits(e)),n.typeInfo);const r=n;return new $o(this._countOneBits(r.value),n.typeInfo)}_countTrailingZeros(e){if(0===e)return 32;let t=0;for(;!(1&e);)e>>=1,t++;return t}CountTrailingZeros(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>this._countTrailingZeros(e)),n.typeInfo);const r=n;return new $o(this._countTrailingZeros(r.value),n.typeInfo)}Cross(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof Qo&&r instanceof Qo){if(3!==n.data.length||3!==r.data.length)return null;const e=n.data,t=r.data;return new Qo([e[1]*t[2]-t[1]*e[2],e[2]*t[0]-t[2]*e[0],e[0]*t[1]-t[0]*e[1]],n.typeInfo)}return null}Degrees(e,t){const n=this.exec.evalExpression(e.args[0],t),r=180/Math.PI;return n instanceof Qo?new Qo(n.data.map(e=>e*r),n.typeInfo):new $o(n.value*r,this.getTypeInfo("f32"))}Determinant(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Yo){const e=n.data,t=n.typeInfo.getTypeName(),r=t.endsWith("h")?this.getTypeInfo("f16"):this.getTypeInfo("f32");if("mat2x2"===t||"mat2x2f"===t||"mat2x2h"===t)return new $o(e[0]*e[3]-e[1]*e[2],r);if("mat2x3"===t||"mat2x3f"===t||"mat2x3h"===t)return new $o(e[0]*(e[4]*e[8]-e[5]*e[7])-e[1]*(e[3]*e[8]-e[5]*e[6])+e[2]*(e[3]*e[7]-e[4]*e[6]),r);if("mat2x4"===t||"mat2x4f"===t||"mat2x4h"===t);else if("mat3x2"===t||"mat3x2f"===t||"mat3x2h"===t);else if("mat3x3"===t||"mat3x3f"===t||"mat3x3h"===t)return new $o(e[0]*(e[4]*e[8]-e[5]*e[7])-e[1]*(e[3]*e[8]-e[5]*e[6])+e[2]*(e[3]*e[7]-e[4]*e[6]),r)}return null}Distance(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof Qo&&r instanceof Qo){let e=0;for(let t=0;tMath.exp(e)),n.typeInfo);const r=n;return new $o(Math.exp(r.value),n.typeInfo)}Exp2(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.pow(2,e)),n.typeInfo);const r=n;return new $o(Math.pow(2,r.value),n.typeInfo)}ExtractBits(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),i=this.exec.evalExpression(e.args[2],t);if("u32"!==r.typeInfo.name&&"x32"!==r.typeInfo.name)return null;if("u32"!==i.typeInfo.name&&"x32"!==i.typeInfo.name)return null;const s=r.value,o=i.value;if(n instanceof Qo)return new Qo(n.data.map(e=>e>>s&(1<>s&(1<-e),n.typeInfo)}return null}_firstLeadingBit(e){return 0===e?-1:31-Math.clz32(e)}FirstLeadingBit(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>this._firstLeadingBit(e)),n.typeInfo);const r=n;return new $o(this._firstLeadingBit(r.value),n.typeInfo)}_firstTrailingBit(e){return 0===e?-1:Math.log2(e&-e)}FirstTrailingBit(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>this._firstTrailingBit(e)),n.typeInfo);const r=n;return new $o(this._firstTrailingBit(r.value),n.typeInfo)}Floor(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.floor(e)),n.typeInfo);const r=n;return new $o(Math.floor(r.value),n.typeInfo)}Fma(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),i=this.exec.evalExpression(e.args[2],t);if(n instanceof Qo&&r instanceof Qo&&i instanceof Qo)return n.data.length!==r.data.length||n.data.length!==i.data.length?null:new Qo(n.data.map((e,t)=>e*r.data[t]+i.data[t]),n.typeInfo);const s=n,o=r,a=i;return new $o(s.value*o.value+a.value,s.typeInfo)}Fract(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>e-Math.floor(e)),n.typeInfo);const r=n;return new $o(r.value-Math.floor(r.value),n.typeInfo)}Frexp(e,t){return null}InsertBits(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),i=this.exec.evalExpression(e.args[2],t),s=this.exec.evalExpression(e.args[3],t);if("u32"!==i.typeInfo.name&&"x32"!==i.typeInfo.name)return null;const o=i.value,a=(1<e&A|r.data[t]<1/Math.sqrt(e)),n.typeInfo);const r=n;return new $o(1/Math.sqrt(r.value),n.typeInfo)}Ldexp(e,t){return null}Length(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo){let e=0;return n.data.forEach(t=>{e+=t*t}),new $o(Math.sqrt(e),this.getTypeInfo("f32"))}const r=n;return new $o(Math.abs(r.value),n.typeInfo)}Log(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.log(e)),n.typeInfo);const r=n;return new $o(Math.log(r.value),n.typeInfo)}Log2(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.log2(e)),n.typeInfo);const r=n;return new $o(Math.log2(r.value),n.typeInfo)}Max(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof Qo&&r instanceof Qo)return new Qo(n.data.map((e,t)=>Math.max(e,r.data[t])),n.typeInfo);const i=n,s=r;return new $o(Math.max(i.value,s.value),n.typeInfo)}Min(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof Qo&&r instanceof Qo)return new Qo(n.data.map((e,t)=>Math.min(e,r.data[t])),n.typeInfo);const i=n,s=r;return new $o(Math.min(i.value,s.value),n.typeInfo)}Mix(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),i=this.exec.evalExpression(e.args[2],t);if(n instanceof Qo&&r instanceof Qo&&i instanceof Qo)return new Qo(n.data.map((e,t)=>n.data[t]*(1-i.data[t])+r.data[t]*i.data[t]),n.typeInfo);const s=r,o=i;return new $o(n.value*(1-o.value)+s.value*o.value,n.typeInfo)}Modf(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof Qo&&r instanceof Qo)return new Qo(n.data.map((e,t)=>e%r.data[t]),n.typeInfo);const i=r;return new $o(n.value%i.value,n.typeInfo)}Normalize(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo){const r=this.Length(e,t).value;return new Qo(n.data.map(e=>e/r),n.typeInfo)}return null}Pow(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof Qo&&r instanceof Qo)return new Qo(n.data.map((e,t)=>Math.pow(e,r.data[t])),n.typeInfo);const i=n,s=r;return new $o(Math.pow(i.value,s.value),n.typeInfo)}QuantizeToF16(e,t){const n=this.exec.evalExpression(e.args[0],t);return n instanceof Qo?new Qo(n.data.map(e=>e),n.typeInfo):new $o(n.value,n.typeInfo)}Radians(e,t){const n=this.exec.evalExpression(e.args[0],t);return n instanceof Qo?new Qo(n.data.map(e=>e*Math.PI/180),n.typeInfo):new $o(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 Qo&&r instanceof Qo){const e=this._dot(n.data,r.data);return new Qo(n.data.map((t,n)=>t-2*e*r.data[n]),n.typeInfo)}return null}Refract(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),i=this.exec.evalExpression(e.args[2],t);if(n instanceof Qo&&r instanceof Qo&&i instanceof $o){const e=this._dot(r.data,n.data);return new Qo(n.data.map((t,n)=>{const s=1-i.value*i.value*(1-e*e);if(s<0)return 0;const o=Math.sqrt(s);return i.value*t-(i.value*e+o)*r.data[n]}),n.typeInfo)}return null}ReverseBits(e,t){return null}Round(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.round(e)),n.typeInfo);const r=n;return new $o(Math.round(r.value),n.typeInfo)}Saturate(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.min(Math.max(e,0),1)),n.typeInfo);const r=n;return new $o(Math.min(Math.max(r.value,0),1),n.typeInfo)}Sign(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.sign(e)),n.typeInfo);const r=n;return new $o(Math.sign(r.value),n.typeInfo)}Sin(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.sin(e)),n.typeInfo);const r=n;return new $o(Math.sin(r.value),n.typeInfo)}Sinh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.sinh(e)),n.typeInfo);const r=n;return new $o(Math.sinh(r.value),n.typeInfo)}_smoothstep(e,t,n){const r=Math.min(Math.max((n-e)/(t-e),0),1);return r*r*(3-2*r)}SmoothStep(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),i=this.exec.evalExpression(e.args[2],t);if(i instanceof Qo&&n instanceof Qo&&r instanceof Qo)return new Qo(i.data.map((e,t)=>this._smoothstep(n.data[t],r.data[t],e)),i.typeInfo);const s=n,o=r,a=i;return new $o(this._smoothstep(s.value,o.value,a.value),i.typeInfo)}Sqrt(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.sqrt(e)),n.typeInfo);const r=n;return new $o(Math.sqrt(r.value),n.typeInfo)}Step(e,t){const n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(r instanceof Qo&&n instanceof Qo)return new Qo(r.data.map((e,t)=>eMath.tan(e)),n.typeInfo);const r=n;return new $o(Math.tan(r.value),n.typeInfo)}Tanh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.tanh(e)),n.typeInfo);const r=n;return new $o(Math.tanh(r.value),n.typeInfo)}_getTransposeType(e){const t=e.getTypeName();return"mat2x2f"===t||"mat2x2h"===t?e:"mat2x3f"===t?this.getTypeInfo("mat3x2f"):"mat2x3h"===t?this.getTypeInfo("mat3x2h"):"mat2x4f"===t?this.getTypeInfo("mat4x2f"):"mat2x4h"===t?this.getTypeInfo("mat4x2h"):"mat3x2f"===t?this.getTypeInfo("mat2x3f"):"mat3x2h"===t?this.getTypeInfo("mat2x3h"):"mat3x3f"===t||"mat3x3h"===t?e:"mat3x4f"===t?this.getTypeInfo("mat4x3f"):"mat3x4h"===t?this.getTypeInfo("mat4x3h"):"mat4x2f"===t?this.getTypeInfo("mat2x4f"):"mat4x2h"===t?this.getTypeInfo("mat2x4h"):"mat4x3f"===t?this.getTypeInfo("mat3x4f"):"mat4x3h"===t?this.getTypeInfo("mat3x4h"):e}Transpose(e,t){const n=this.exec.evalExpression(e.args[0],t);if(!(n instanceof Yo))return null;const r=this._getTransposeType(n.typeInfo);if("mat2x2"===n.typeInfo.name||"mat2x2f"===n.typeInfo.name||"mat2x2h"===n.typeInfo.name){const e=n.data;return new Yo([e[0],e[2],e[1],e[3]],r)}if("mat2x3"===n.typeInfo.name||"mat2x3f"===n.typeInfo.name||"mat2x3h"===n.typeInfo.name){const e=n.data;return new Yo([e[0],e[3],e[6],e[1],e[4],e[7]],r)}if("mat2x4"===n.typeInfo.name||"mat2x4f"===n.typeInfo.name||"mat2x4h"===n.typeInfo.name){const e=n.data;return new Yo([e[0],e[4],e[8],e[12],e[1],e[5],e[9],e[13]],r)}if("mat3x2"===n.typeInfo.name||"mat3x2f"===n.typeInfo.name||"mat3x2h"===n.typeInfo.name){const e=n.data;return new Yo([e[0],e[3],e[1],e[4],e[2],e[5]],r)}if("mat3x3"===n.typeInfo.name||"mat3x3f"===n.typeInfo.name||"mat3x3h"===n.typeInfo.name){const e=n.data;return new Yo([e[0],e[3],e[6],e[1],e[4],e[7],e[2],e[5],e[8]],r)}if("mat3x4"===n.typeInfo.name||"mat3x4f"===n.typeInfo.name||"mat3x4h"===n.typeInfo.name){const e=n.data;return new Yo([e[0],e[4],e[8],e[12],e[1],e[5],e[9],e[13],e[2],e[6],e[10],e[14]],r)}if("mat4x2"===n.typeInfo.name||"mat4x2f"===n.typeInfo.name||"mat4x2h"===n.typeInfo.name){const e=n.data;return new Yo([e[0],e[4],e[1],e[5],e[2],e[6]],r)}if("mat4x3"===n.typeInfo.name||"mat4x3f"===n.typeInfo.name||"mat4x3h"===n.typeInfo.name){const e=n.data;return new Yo([e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]],r)}if("mat4x4"===n.typeInfo.name||"mat4x4f"===n.typeInfo.name||"mat4x4h"===n.typeInfo.name){const e=n.data;return new Yo([e[0],e[4],e[8],e[12],e[1],e[5],e[9],e[13],e[2],e[6],e[10],e[14],e[3],e[7],e[11],e[15]],r)}return null}Trunc(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Qo)return new Qo(n.data.map(e=>Math.trunc(e)),n.typeInfo);const r=n;return new $o(Math.trunc(r.value),n.typeInfo)}Dpdx(e,t){return null}DpdxCoarse(e,t){return null}DpdxFine(e,t){return null}Dpdy(e,t){return null}DpdyCoarse(e,t){return null}DpdyFine(e,t){return null}Fwidth(e,t){return null}FwidthCoarse(e,t){return null}FwidthFine(e,t){return null}TextureDimensions(e,t){const n=e.args[0],r=e.args.length>1?this.exec.evalExpression(e.args[1],t).value:0;if(n instanceof Co){const e=n.name,i=t.getVariableValue(e);if(i instanceof Ko){if(r<0||r>=i.mipLevelCount)return null;const e=i.getMipLevelSize(r),t=i.dimension;return"1d"===t?new $o(e[0],this.getTypeInfo("u32")):"3d"===t?new Qo(e,this.getTypeInfo("vec3u")):"2d"===t?new Qo(e.slice(0,2),this.getTypeInfo("vec2u")):null}return null}return null}TextureGather(e,t){return null}TextureGatherCompare(e,t){return null}TextureLoad(e,t){const n=e.args[0],r=this.exec.evalExpression(e.args[1],t),i=e.args.length>2?this.exec.evalExpression(e.args[2],t).value:0;if(!(r instanceof Qo)||2!==r.data.length)return null;if(n instanceof Co){const e=n.name,s=t.getVariableValue(e);if(s instanceof Ko){const e=Math.floor(r.data[0]),t=Math.floor(r.data[1]);if(e<0||e>=s.width||t<0||t>=s.height)return null;const n=s.getPixel(e,t,0,i);return null===n?null:new Qo(n,this.getTypeInfo("vec4f"))}return null}return null}TextureNumLayers(e,t){const n=e.args[0];if(n instanceof Co){const e=n.name,r=t.getVariableValue(e);return r instanceof Ko?new $o(r.depthOrArrayLayers,this.getTypeInfo("u32")):null}return null}TextureNumLevels(e,t){const n=e.args[0];if(n instanceof Co){const e=n.name,r=t.getVariableValue(e);return r instanceof Ko?new $o(r.mipLevelCount,this.getTypeInfo("u32")):null}return null}TextureNumSamples(e,t){const n=e.args[0];if(n instanceof Co){const e=n.name,r=t.getVariableValue(e);return r instanceof Ko?new $o(r.sampleCount,this.getTypeInfo("u32")):null}return null}TextureSample(e,t){return null}TextureSampleBias(e,t){return null}TextureSampleCompare(e,t){return null}TextureSampleCompareLevel(e,t){return null}TextureSampleGrad(e,t){return null}TextureSampleLevel(e,t){return null}TextureSampleBaseClampToEdge(e,t){return null}TextureStore(e,t){const n=e.args[0],r=this.exec.evalExpression(e.args[1],t),i=4===e.args.length?this.exec.evalExpression(e.args[2],t).value:0,s=4===e.args.length?this.exec.evalExpression(e.args[3],t).data:this.exec.evalExpression(e.args[2],t).data;if(4!==s.length)return null;if(!(r instanceof Qo)||2!==r.data.length)return null;if(n instanceof Co){const e=n.name,o=t.getVariableValue(e);if(o instanceof Ko){const e=o.getMipLevelSize(0),t=Math.floor(r.data[0]),n=Math.floor(r.data[1]);return t<0||t>=e[0]||n<0||n>=e[1]||o.setPixel(t,n,0,i,Array.from(s)),null}return null}return null}AtomicLoad(e,t){let n=e.args[0];n instanceof Lo&&(n=n.right);const 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 Lo&&(n=n.right);const r=this.exec.getVariableName(n,t),i=t.getVariable(r);let s=e.args[1];const o=this.exec.evalExpression(s,t),a=i.value.getSubData(this.exec,n.postfix,t);return a instanceof $o&&o instanceof $o&&(a.value=o.value),i.value instanceof qo&&i.value.setDataValue(this.exec,a,n.postfix,t),null}AtomicAdd(e,t){let n=e.args[0];n instanceof Lo&&(n=n.right);const r=this.exec.getVariableName(n,t),i=t.getVariable(r);let s=e.args[1];const o=this.exec.evalExpression(s,t),a=i.value.getSubData(this.exec,n.postfix,t),A=new $o(a.value,a.typeInfo);return a instanceof $o&&o instanceof $o&&(a.value+=o.value),i.value instanceof qo&&i.value.setDataValue(this.exec,a,n.postfix,t),A}AtomicSub(e,t){let n=e.args[0];n instanceof Lo&&(n=n.right);const r=this.exec.getVariableName(n,t),i=t.getVariable(r);let s=e.args[1];const o=this.exec.evalExpression(s,t),a=i.value.getSubData(this.exec,n.postfix,t),A=new $o(a.value,a.typeInfo);return a instanceof $o&&o instanceof $o&&(a.value-=o.value),i.value instanceof qo&&i.value.setDataValue(this.exec,a,n.postfix,t),A}AtomicMax(e,t){let n=e.args[0];n instanceof Lo&&(n=n.right);const r=this.exec.getVariableName(n,t),i=t.getVariable(r);let s=e.args[1];const o=this.exec.evalExpression(s,t),a=i.value.getSubData(this.exec,n.postfix,t),A=new $o(a.value,a.typeInfo);return a instanceof $o&&o instanceof $o&&(a.value=Math.max(a.value,o.value)),i.value instanceof qo&&i.value.setDataValue(this.exec,a,n.postfix,t),A}AtomicMin(e,t){let n=e.args[0];n instanceof Lo&&(n=n.right);const r=this.exec.getVariableName(n,t),i=t.getVariable(r);let s=e.args[1];const o=this.exec.evalExpression(s,t),a=i.value.getSubData(this.exec,n.postfix,t),A=new $o(a.value,a.typeInfo);return a instanceof $o&&o instanceof $o&&(a.value=Math.min(a.value,o.value)),i.value instanceof qo&&i.value.setDataValue(this.exec,a,n.postfix,t),A}AtomicAnd(e,t){let n=e.args[0];n instanceof Lo&&(n=n.right);const r=this.exec.getVariableName(n,t),i=t.getVariable(r);let s=e.args[1];const o=this.exec.evalExpression(s,t),a=i.value.getSubData(this.exec,n.postfix,t),A=new $o(a.value,a.typeInfo);return a instanceof $o&&o instanceof $o&&(a.value=a.value&o.value),i.value instanceof qo&&i.value.setDataValue(this.exec,a,n.postfix,t),A}AtomicOr(e,t){let n=e.args[0];n instanceof Lo&&(n=n.right);const r=this.exec.getVariableName(n,t),i=t.getVariable(r);let s=e.args[1];const o=this.exec.evalExpression(s,t),a=i.value.getSubData(this.exec,n.postfix,t),A=new $o(a.value,a.typeInfo);return a instanceof $o&&o instanceof $o&&(a.value=a.value|o.value),i.value instanceof qo&&i.value.setDataValue(this.exec,a,n.postfix,t),A}AtomicXor(e,t){let n=e.args[0];n instanceof Lo&&(n=n.right);const r=this.exec.getVariableName(n,t),i=t.getVariable(r);let s=e.args[1];const o=this.exec.evalExpression(s,t),a=i.value.getSubData(this.exec,n.postfix,t),A=new $o(a.value,a.typeInfo);return a instanceof $o&&o instanceof $o&&(a.value=a.value^o.value),i.value instanceof qo&&i.value.setDataValue(this.exec,a,n.postfix,t),A}AtomicExchange(e,t){let n=e.args[0];n instanceof Lo&&(n=n.right);const r=this.exec.getVariableName(n,t),i=t.getVariable(r);let s=e.args[1];const o=this.exec.evalExpression(s,t),a=i.value.getSubData(this.exec,n.postfix,t),A=new $o(a.value,a.typeInfo);return a instanceof $o&&o instanceof $o&&(a.value=o.value),i.value instanceof qo&&i.value.setDataValue(this.exec,a,n.postfix,t),A}AtomicCompareExchangeWeak(e,t){return null}Pack4x8snorm(e,t){return null}Pack4x8unorm(e,t){return null}Pack4xI8(e,t){return null}Pack4xU8(e,t){return null}Pack4x8Clamp(e,t){return null}Pack4xU8Clamp(e,t){return null}Pack2x16snorm(e,t){return null}Pack2x16unorm(e,t){return null}Pack2x16float(e,t){return null}Unpack4x8snorm(e,t){return null}Unpack4x8unorm(e,t){return null}Unpack4xI8(e,t){return null}Unpack4xU8(e,t){return null}Unpack2x16snorm(e,t){return null}Unpack2x16unorm(e,t){return null}Unpack2x16float(e,t){return 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 null}SubgroupExclusiveAdd(e,t){return null}SubgroupInclusiveAdd(e,t){return null}SubgroupAll(e,t){return null}SubgroupAnd(e,t){return null}SubgroupAny(e,t){return null}SubgroupBallot(e,t){return null}SubgroupBroadcast(e,t){return null}SubgroupBroadcastFirst(e,t){return null}SubgroupElect(e,t){return null}SubgroupMax(e,t){return null}SubgroupMin(e,t){return null}SubgroupMul(e,t){return null}SubgroupExclusiveMul(e,t){return null}SubgroupInclusiveMul(e,t){return null}SubgroupOr(e,t){return null}SubgroupShuffle(e,t){return null}SubgroupShuffleDown(e,t){return null}SubgroupShuffleUp(e,t){return null}SubgroupShuffleXor(e,t){return null}SubgroupXor(e,t){return null}QuadBroadcast(e,t){return null}QuadSwapDiagonal(e,t){return null}QuadSwapX(e,t){return null}QuadSwapY(e,t){return null}}const wa={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},xa={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]};class Ea extends va{constructor(e,t){var n;super(),this.ast=null!=e?e:[],this.reflection=new pa,this.reflection.updateAST(this.ast),this.context=null!==(n=null==t?void 0:t.clone())&&void 0!==n?n:new ba,this.builtins=new ya(this),this.typeInfo={bool:this.getTypeInfo(go.bool),i32:this.getTypeInfo(go.i32),u32:this.getTypeInfo(go.u32),f32:this.getTypeInfo(go.f32),f16:this.getTypeInfo(go.f16),vec2f:this.getTypeInfo(bo.vec2f),vec2u:this.getTypeInfo(bo.vec2u),vec2i:this.getTypeInfo(bo.vec2i),vec2h:this.getTypeInfo(bo.vec2h),vec3f:this.getTypeInfo(bo.vec3f),vec3u:this.getTypeInfo(bo.vec3u),vec3i:this.getTypeInfo(bo.vec3i),vec3h:this.getTypeInfo(bo.vec3h),vec4f:this.getTypeInfo(bo.vec4f),vec4u:this.getTypeInfo(bo.vec4u),vec4i:this.getTypeInfo(bo.vec4i),vec4h:this.getTypeInfo(bo.vec4h),mat2x2f:this.getTypeInfo(bo.mat2x2f),mat2x3f:this.getTypeInfo(bo.mat2x3f),mat2x4f:this.getTypeInfo(bo.mat2x4f),mat3x2f:this.getTypeInfo(bo.mat3x2f),mat3x3f:this.getTypeInfo(bo.mat3x3f),mat3x4f:this.getTypeInfo(bo.mat3x4f),mat4x2f:this.getTypeInfo(bo.mat4x2f),mat4x3f:this.getTypeInfo(bo.mat4x3f),mat4x4f:this.getTypeInfo(bo.mat4x4f)}}getVariableValue(e){var t,n;const r=null!==(n=null===(t=this.context.getVariable(e))||void 0===t?void 0:t.value)&&void 0!==n?n:null;if(null===r)return null;if(r instanceof $o)return r.value;if(r instanceof Qo)return Array.from(r.data);if(r instanceof Yo)return Array.from(r.data);if(r instanceof qo&&r.typeInfo instanceof ds){if("u32"===r.typeInfo.format.name)return Array.from(new Uint32Array(r.buffer,r.offset,r.typeInfo.count));if("i32"===r.typeInfo.format.name)return Array.from(new Int32Array(r.buffer,r.offset,r.typeInfo.count));if("f32"===r.typeInfo.format.name)return Array.from(new Float32Array(r.buffer,r.offset,r.typeInfo.count))}return null}execute(e){(e=null!=e?e:{}).constants&&this._setOverrides(e.constants,this.context),this._execStatements(this.ast,this.context)}dispatchWorkgroups(e,t,n,r){const i=this.context.clone();(r=null!=r?r:{}).constants&&this._setOverrides(r.constants,i),this._execStatements(this.ast,i);const s=i.getFunction(e);if(!s)return;if("number"==typeof t)t=[t,1,1];else{if(0===t.length)return;1===t.length?t=[t[0],1,1]:2===t.length?t=[t[0],t[1],1]:t.length>3&&(t=[t[0],t[1],t[2]])}const o=t[0],a=t[1],A=t[2],l=this.getTypeInfo("vec3u");i.setVariable("@num_workgroups",new Qo(t,l));const c=this.reflection.getFunctionInfo(e);for(const u in n)for(const e in n[u]){const t=n[u][e];i.variables.forEach(n=>{var r;const i=n.node;if(null==i?void 0:i.attributes){let s=null,o=null;for(const e of i.attributes)"binding"===e.name?s=e.value:"group"===e.name&&(o=e.value);if(e==s&&u==o){let s=!1;for(const t of c.resources)if(t.name===n.name&&t.group===parseInt(u)&&t.binding===parseInt(e)){s=!0;break}if(s)if(void 0!==t.texture&&void 0!==t.descriptor){const e=new Ko(t.texture,this.getTypeInfo(i.type),t.descriptor,null!==(r=t.texture.view)&&void 0!==r?r:null);n.value=e}else void 0!==t.uniform?n.value=new qo(t.uniform,this.getTypeInfo(i.type)):n.value=new qo(t,this.getTypeInfo(i.type))}}})}for(let u=0;u0){const e=n.getVariableValue(l.value[0]);r[0]=e instanceof $o?e.value:parseInt(l.value[0])}if(l.value.length>1){const e=n.getVariableValue(l.value[1]);r[1]=e instanceof $o?e.value:parseInt(l.value[1])}if(l.value.length>2){const e=n.getVariableValue(l.value[2]);r[2]=e instanceof $o?e.value:parseInt(l.value[2])}}const i=this.getTypeInfo("vec3u"),s=this.getTypeInfo("u32");n.setVariable("@workgroup_size",new Qo(r,i));const o=r[0],a=r[1],A=r[2];for(let l=0,c=0;l",i=null;if(e.variable instanceof Lo){const n=this._getVariableData(e.variable,t),r=this.evalExpression(e.value,t),i=e.operator;if("="===i){if(n instanceof $o||n instanceof Qo||n instanceof Yo){if(r instanceof $o||r instanceof Qo||r instanceof Yo&&n.data.length===r.data.length)return void n.data.set(r.data)}else if(n instanceof qo&&r instanceof qo&&n.buffer.byteLength-n.offset>=r.buffer.byteLength-r.offset)return void(n.buffer.byteLength%4==0?new Uint32Array(n.buffer,n.offset,n.typeInfo.size/4).set(new Uint32Array(r.buffer,r.offset,r.typeInfo.size/4)):new Uint8Array(n.buffer,n.offset,n.typeInfo.size).set(new Uint8Array(r.buffer,r.offset,r.typeInfo.size)));return null}if("+="===i)return(n instanceof $o||n instanceof Qo||n instanceof Yo)&&(r instanceof $o||r instanceof Qo||r instanceof Yo)?void n.data.set(r.data.map((e,t)=>n.data[t]+e)):void 0;if("-="===i)return(n instanceof $o||n instanceof Qo||n instanceof Yo)&&(r instanceof $o||r instanceof Qo||r instanceof Yo)?void n.data.set(r.data.map((e,t)=>n.data[t]-e)):void 0}if(e.variable instanceof Lo){if("*"===e.variable.operator){r=this.getVariableName(e.variable.right,t);const i=t.getVariable(r);if(!(i&&i.value instanceof Ho))return;n=i.value.reference;let s=e.variable.postfix;if(!s){let t=e.variable.right;for(;t instanceof Lo;){if(t.postfix){s=t.postfix;break}t=t.right}}s&&(n=n.getSubData(this,s,t))}}else{i=e.variable.postfix,r=this.getVariableName(e.variable,t);const s=t.getVariable(r);if(null===s)return;n=s.value}if(n instanceof Ho&&(n=n.reference),null===n)return;const s=this.evalExpression(e.value,t),o=e.operator;if("="!==o){const e=n.getSubData(this,i,t);if(e instanceof Qo&&s instanceof $o){const t=e.data,n=s.value;if("+="===o)for(let e=0;e>="===o)for(let e=0;e>=n}else if(e instanceof Qo&&s instanceof Qo){const t=e.data,n=s.data;if(t.length!==n.length)return;if("+="===o)for(let e=0;e>="===o)for(let e=0;e>=n[e]}else{if(!(e instanceof $o&&s instanceof $o))return;"+="===o?e.value+=s.value:"-="===o?e.value-=s.value:"*="===o?e.value*=s.value:"/="===o?e.value/=s.value:"%="===o?e.value%=s.value:"&="===o?e.value&=s.value:"|="===o?e.value|=s.value:"^="===o?e.value^=s.value:"<<="===o?e.value<<=s.value:">>="===o&&(e.value>>=s.value)}return void(n instanceof qo&&n.setDataValue(this,e,i,t))}if(n instanceof qo)n.setDataValue(this,s,i,t);else if(i){if(!(n instanceof Qo||n instanceof Yo))return;if(i instanceof Io){const e=this.evalExpression(i.index,t).value;if(n instanceof Qo){if(!(s instanceof $o))return;n.data[e]=s.value}else{if(!(n instanceof Yo))return;{const e=this.evalExpression(i.index,t).value;if(e<0)return;if(!(s instanceof Qo))return;{const t=n.typeInfo.getTypeName();if("mat2x2"===t||"mat2x2f"===t||"mat2x2h"===t){if(!(e<2&&2===s.data.length))return;n.data[2*e]=s.data[0],n.data[2*e+1]=s.data[1]}else if("mat2x3"===t||"mat2x3f"===t||"mat2x3h"===t){if(!(e<2&&3===s.data.length))return;n.data[3*e]=s.data[0],n.data[3*e+1]=s.data[1],n.data[3*e+2]=s.data[2]}else if("mat2x4"===t||"mat2x4f"===t||"mat2x4h"===t){if(!(e<2&&4===s.data.length))return;n.data[4*e]=s.data[0],n.data[4*e+1]=s.data[1],n.data[4*e+2]=s.data[2],n.data[4*e+3]=s.data[3]}else if("mat3x2"===t||"mat3x2f"===t||"mat3x2h"===t){if(!(e<3&&2===s.data.length))return;n.data[2*e]=s.data[0],n.data[2*e+1]=s.data[1]}else if("mat3x3"===t||"mat3x3f"===t||"mat3x3h"===t){if(!(e<3&&3===s.data.length))return;n.data[3*e]=s.data[0],n.data[3*e+1]=s.data[1],n.data[3*e+2]=s.data[2]}else if("mat3x4"===t||"mat3x4f"===t||"mat3x4h"===t){if(!(e<3&&4===s.data.length))return;n.data[4*e]=s.data[0],n.data[4*e+1]=s.data[1],n.data[4*e+2]=s.data[2],n.data[4*e+3]=s.data[3]}else if("mat4x2"===t||"mat4x2f"===t||"mat4x2h"===t){if(!(e<4&&2===s.data.length))return;n.data[2*e]=s.data[0],n.data[2*e+1]=s.data[1]}else if("mat4x3"===t||"mat4x3f"===t||"mat4x3h"===t){if(!(e<4&&3===s.data.length))return;n.data[3*e]=s.data[0],n.data[3*e+1]=s.data[1],n.data[3*e+2]=s.data[2]}else{if("mat4x4"!==t&&"mat4x4f"!==t&&"mat4x4h"!==t)return;if(!(e<4&&4===s.data.length))return;n.data[4*e]=s.data[0],n.data[4*e+1]=s.data[1],n.data[4*e+2]=s.data[2],n.data[4*e+3]=s.data[3]}}}}}else if(i instanceof Eo){const e=i.value;if(!(n instanceof Qo))return;if(s instanceof $o){if(e.length>1)return;if("x"===e)n.data[0]=s.value;else if("y"===e){if(n.data.length<2)return;n.data[1]=s.value}else if("z"===e){if(n.data.length<3)return;n.data[2]=s.value}else if("w"===e){if(n.data.length<4)return;n.data[3]=s.value}}else{if(!(s instanceof Qo))return;if(e.length!==s.data.length)return;for(let t=0;t+e);return new Qo(e,n.typeInfo)}const e=r,t=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new $o(+e,t)}case"-":{if(na(r)){const e=r.map((e,t)=>-e);return new Qo(e,n.typeInfo)}const e=r,t=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new $o(-e,t)}case"!":{if(na(r)){const e=r.map((e,t)=>e?0:1);return new Qo(e,n.typeInfo)}const e=r,t=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new $o(e?0:1,t)}case"~":{if(na(r)){const e=r.map((e,t)=>~e);return new Qo(e,n.typeInfo)}const e=r,t=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new $o(~e,t)}}return null}_evalBinaryOp(e,t){const n=this.evalExpression(e.left,t),r=this.evalExpression(e.right,t),i=n instanceof $o?n.value:n instanceof Qo||n instanceof Yo?Array.from(n.data):null,s=r instanceof $o?r.value:r instanceof Qo||r instanceof Yo?Array.from(r.data):null;switch(e.operator){case"+":{if(na(i)&&na(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e+t[n]);return new Qo(r,n.typeInfo)}if(na(i)){const e=s,t=i.map((t,n)=>t+e);return new Qo(t,n.typeInfo)}if(na(s)){const e=i,t=s.map((t,n)=>e+t);return new Qo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new $o(e+t,o)}case"-":{if(na(i)&&na(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e-t[n]);return new Qo(r,n.typeInfo)}if(na(i)){const e=s,t=i.map((t,n)=>t-e);return new Qo(t,n.typeInfo)}if(na(s)){const e=i,t=s.map((t,n)=>e-t);return new Qo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new $o(e-t,o)}case"*":{if(na(i)&&na(s)){const e=i,t=s;if(n instanceof Yo&&r instanceof Yo){const i=function(e,t,n,r){if(void 0===xa[t.name]||void 0===xa[r.name])return null;const i=xa[t.name][0],s=xa[t.name][1],o=xa[r.name][0];if(i!==xa[r.name][1])return null;const a=new Array(o*s);for(let A=0;Ae*t[n]);return new Qo(r,n.typeInfo)}}if(na(i)){const e=s,t=i.map((t,n)=>t*e);return n instanceof Yo?new Yo(t,n.typeInfo):new Qo(t,n.typeInfo)}if(na(s)){const e=i,t=s.map((t,n)=>e*t);return r instanceof Yo?new Yo(t,r.typeInfo):new Qo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new $o(e*t,o)}case"%":{if(na(i)&&na(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e%t[n]);return new Qo(r,n.typeInfo)}if(na(i)){const e=s,t=i.map((t,n)=>t%e);return new Qo(t,n.typeInfo)}if(na(s)){const e=i,t=s.map((t,n)=>e%t);return new Qo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new $o(e%t,o)}case"/":{if(na(i)&&na(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e/t[n]);return new Qo(r,n.typeInfo)}if(na(i)){const e=s,t=i.map((t,n)=>t/e);return new Qo(t,n.typeInfo)}if(na(s)){const e=i,t=s.map((t,n)=>e/t);return new Qo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new $o(e/t,o)}case"&":{if(na(i)&&na(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e&t[n]);return new Qo(r,n.typeInfo)}if(na(i)){const e=s,t=i.map((t,n)=>t&e);return new Qo(t,n.typeInfo)}if(na(s)){const e=i,t=s.map((t,n)=>e&t);return new Qo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new $o(e&t,o)}case"|":{if(na(i)&&na(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e|t[n]);return new Qo(r,n.typeInfo)}if(na(i)){const e=s,t=i.map((t,n)=>t|e);return new Qo(t,n.typeInfo)}if(na(s)){const e=i,t=s.map((t,n)=>e|t);return new Qo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new $o(e|t,o)}case"^":{if(na(i)&&na(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e^t[n]);return new Qo(r,n.typeInfo)}if(na(i)){const e=s,t=i.map((t,n)=>t^e);return new Qo(t,n.typeInfo)}if(na(s)){const e=i,t=s.map((t,n)=>e^t);return new Qo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new $o(e^t,o)}case"<<":{if(na(i)&&na(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e<t<e<>":{if(na(i)&&na(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e>>t[n]);return new Qo(r,n.typeInfo)}if(na(i)){const e=s,t=i.map((t,n)=>t>>e);return new Qo(t,n.typeInfo)}if(na(s)){const e=i,t=s.map((t,n)=>e>>t);return new Qo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new $o(e>>t,o)}case">":if(na(i)&&na(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e>t[n]?1:0);return new Qo(r,n.typeInfo)}if(na(i)){const e=s,t=i.map((t,n)=>t>e?1:0);return new Qo(t,n.typeInfo)}if(na(s)){const e=i,t=s.map((t,n)=>e>t?1:0);return new Qo(t,r.typeInfo)}return new $o(i>s?1:0,this.getTypeInfo("bool"));case"<":if(na(i)&&na(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>etee===t[n]?1:0);return new Qo(r,n.typeInfo)}if(na(i)){const e=s,t=i.map((t,n)=>t==e?1:0);return new Qo(t,n.typeInfo)}if(na(s)){const e=i,t=s.map((t,n)=>e==t?1:0);return new Qo(t,r.typeInfo)}return new $o(i===s?1:0,this.getTypeInfo("bool"));case"!=":if(na(i)&&na(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e!==t[n]?1:0);return new Qo(r,n.typeInfo)}if(na(i)){const e=s,t=i.map((t,n)=>t!==e?1:0);return new Qo(t,n.typeInfo)}if(na(s)){const e=i,t=s.map((t,n)=>e!==t?1:0);return new Qo(t,r.typeInfo)}return new $o(i!==s?1:0,this.getTypeInfo("bool"));case">=":if(na(i)&&na(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e>=t[n]?1:0);return new Qo(r,n.typeInfo)}if(na(i)){const e=s,t=i.map((t,n)=>t>=e?1:0);return new Qo(t,n.typeInfo)}if(na(s)){const e=i,t=s.map((t,n)=>e>=t?1:0);return new Qo(t,r.typeInfo)}return new $o(i>=s?1:0,this.getTypeInfo("bool"));case"<=":if(na(i)&&na(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e<=t[n]?1:0);return new Qo(r,n.typeInfo)}if(na(i)){const e=s,t=i.map((t,n)=>t<=e?1:0);return new Qo(t,n.typeInfo)}if(na(s)){const e=i,t=s.map((t,n)=>e<=t?1:0);return new Qo(t,r.typeInfo)}return new $o(i<=s?1:0,this.getTypeInfo("bool"));case"&&":if(na(i)&&na(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e&&t[n]?1:0);return new Qo(r,n.typeInfo)}if(na(i)){const e=s,t=i.map((t,n)=>t&&e?1:0);return new Qo(t,n.typeInfo)}if(na(s)){const e=i,t=s.map((t,n)=>e&&t?1:0);return new Qo(t,r.typeInfo)}return new $o(i&&s?1:0,this.getTypeInfo("bool"));case"||":if(na(i)&&na(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e||t[n]?1:0);return new Qo(r,n.typeInfo)}if(na(i)){const e=s,t=i.map((t,n)=>t||e?1:0);return new Qo(t,n.typeInfo)}if(na(s)){const e=i,t=s.map((t,n)=>e||t?1:0);return new Qo(t,r.typeInfo)}return new $o(i||s?1:0,this.getTypeInfo("bool"))}return null}_evalCall(e,t){if(null!==e.cachedReturnValue)return e.cachedReturnValue;const n=t.clone();n.currentFunctionName=e.name;const r=t.getFunction(e.name);if(!r)return e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)?this._evalCreate(e,t):null;for(let i=0;ii?s.slice(0,i):s,n).getSubData(this,e.postfix,t)}_callConstructorMatrix(e,t){const n=this.getTypeInfo(e.type),r=e.type.getTypeName(),i=xa[r];if(void 0===i)return null;const s=[];if(e instanceof Ro)if(e.isVector){const t=e.vectorValue;for(const e of t)s.push(e)}else s.push(e.scalarValue);else if(e.args)for(const o of e.args){const e=this.evalExpression(o,t);e instanceof Qo?s.push(...e.data):e instanceof $o?s.push(e.value):e instanceof Yo&&s.push(...e.data)}if(n instanceof ps&&null===n.format&&(n.format=this.getTypeInfo("f32")),0===s.length){const r=new Array(i[2]).fill(0);return new Yo(r,n).getSubData(this,e.postfix,t)}return s.length!==i[2]?null:new Yo(s,n).getSubData(this,e.postfix,t)}}Ea._breakObj=new Vo(new cs("BREAK",null),null),Ea._continueObj=new Vo(new cs("CONTINUE",null),null),Ea._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);class Ta{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}}class Sa{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new Ta,this._exec=new Ea,this._forwardTypeCount=0}parse(e){this._initialize(e),this._deferArrayCountEval.length=0;const t=[];for(;!this._isAtEnd();){const e=this._global_decl_or_directive();if(!e)break;t.push(e)}if(this._deferArrayCountEval.length>0){for(const e of this._deferArrayCountEval){const t=e.arrayType,r=e.countNode;if(r instanceof Co){const e=r.name,i=this._context.constants.get(e);if(i)try{const e=i.constEvaluate(this._exec);t.count=e}catch(n){}}}this._deferArrayCountEval.length=0}if(this._forwardTypeCount>0)for(const r of t)r.search(e=>{e instanceof Go||e instanceof vo?e.type=this._forwardType(e.type):e instanceof yo?e.format=this._forwardType(e.format):e instanceof Xs||e instanceof Ys||e instanceof qs?e.type=this._forwardType(e.type):e instanceof zs?e.returnType=this._forwardType(e.returnType):e instanceof Uo&&(e.type=this._forwardType(e.type))});return t}_forwardType(e){if(e instanceof mo){const t=this._getType(e.name);if(t)return t}else e instanceof vo?e.type=this._forwardType(e.type):e instanceof yo&&(e.format=this._forwardType(e.format));return e}_initialize(e){if(e)if("string"==typeof e){const t=new ta(e);this._tokens=t.scanTokens()}else this._tokens=e;else this._tokens=[];this._current=0}_updateNode(e,t){return e.line=null!=t?t:this._currentLine,e}_error(e,t){return{token:e,message:t,toString:()=>`${t}`}}_isAtEnd(){return this._current>=this._tokens.length||this._peek().type==Jo.eof}_match(e){if(e instanceof Zo)return!!this._check(e)&&(this._advance(),!0);for(let t=0,n=e.length;t0){const e=this._currentLoop[this._currentLoop.length-1];t.loopId=e.id}e=t,this._check(Jo.keywords.if)&&(this._advance(),t.condition=this._optional_paren_expression())}else if(this._match(Jo.keywords.continue)){const t=this._updateNode(new po);if(!(this._currentLoop.length>0))throw this._error(this._peek(),`Continue statement must be inside a loop. Line: ${t.line}`);{const e=this._currentLoop[this._currentLoop.length-1];t.loopId=e.id}e=t}else e=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement();return null!=e&&this._consume(Jo.tokens.semicolon,"Expected ';' after statement."),e}_static_assert_statement(){if(!this._match(Jo.keywords.static_assert))return null;const e=this._currentLine,t=this._optional_paren_expression();return this._updateNode(new Vs(t),e)}_while_statement(){if(!this._match(Jo.keywords.while))return null;const e=this._updateNode(new Ws(null,null));return this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(Jo.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_continuing_statement(){const e=this._currentLoop.length>0?this._currentLoop[this._currentLoop.length-1].id:-1;if(!this._match(Jo.keywords.continuing))return null;const t=this._currentLine,n=this._compound_statement();return this._updateNode(new Hs(n,e),t)}_for_statement(){if(!this._match(Jo.keywords.for))return null;this._consume(Jo.tokens.paren_left,"Expected '('.");const e=this._updateNode(new $s(null,null,null,null));return this._currentLoop.push(e),e.init=this._check(Jo.tokens.semicolon)?null:this._for_init(),this._consume(Jo.tokens.semicolon,"Expected ';'."),e.condition=this._check(Jo.tokens.semicolon)?null:this._short_circuit_or_expression(),this._consume(Jo.tokens.semicolon,"Expected ';'."),e.increment=this._check(Jo.tokens.paren_right)?null:this._for_increment(),this._consume(Jo.tokens.paren_right,"Expected ')'."),this._check(Jo.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(Jo.keywords.var)){const e=this._variable_decl();if(null===e)throw this._error(this._peek(),"Variable declaration expected.");let t=null;return this._match(Jo.tokens.equal)&&(t=this._short_circuit_or_expression()),this._updateNode(new Xs(e.name,e.type,e.storage,e.access,t),e.line)}if(this._match(Jo.keywords.let)){const e=this._currentLine,t=this._consume(Jo.tokens.name,"Expected name for let.").toString();let n=null;if(this._match(Jo.tokens.colon)){const e=this._attribute();n=this._type_decl(),null!=n&&(n.attributes=e)}this._consume(Jo.tokens.equal,"Expected '=' for let.");const r=this._short_circuit_or_expression();return this._updateNode(new Ys(t,n,null,null,r),e)}if(this._match(Jo.keywords.const)){const e=this._currentLine,t=this._consume(Jo.tokens.name,"Expected name for const.").toString();let n=null;if(this._match(Jo.tokens.colon)){const e=this._attribute();n=this._type_decl(),null!=n&&(n.attributes=e)}this._consume(Jo.tokens.equal,"Expected '=' for const.");const r=this._short_circuit_or_expression();return null===n&&r instanceof Ro&&(n=r.type),this._updateNode(new qs(t,n,null,null,r),e)}return null}_increment_decrement_statement(){const e=this._current,t=this._unary_expression();if(null==t)return null;if(!this._check(Jo.increment_operators))return this._current=e,null;const n=this._consume(Jo.increment_operators,"Expected increment operator");return this._updateNode(new to(n.type===Jo.tokens.plus_plus?Ks.increment:Ks.decrement,t))}_assignment_statement(){let e=null;const t=this._currentLine;if(this._check(Jo.tokens.brace_right))return null;let n=this._match(Jo.tokens.underscore);if(n||(e=this._unary_expression()),!n&&null==e)return null;const r=this._consume(Jo.assignment_operators,"Expected assignment operator."),i=this._short_circuit_or_expression();return this._updateNode(new no(Zs.parse(r.lexeme),e,i),t)}_func_call_statement(){if(!this._check(Jo.tokens.ident))return null;const e=this._currentLine,t=this._current,n=this._consume(Jo.tokens.ident,"Expected function name."),r=this._argument_expression_list();return null===r?(this._current=t,null):this._updateNode(new ro(n.lexeme,r),e)}_loop_statement(){if(!this._match(Jo.keywords.loop))return null;this._check(Jo.tokens.attr)&&this._attribute(),this._consume(Jo.tokens.brace_left,"Expected '{' for loop.");const e=this._updateNode(new io([],null));this._currentLoop.push(e);let t=this._statement();for(;null!==t;){if(Array.isArray(t))for(let n of t)e.body.push(n);else e.body.push(t);if(t instanceof Hs){e.continuing=t;break}t=this._statement()}return this._currentLoop.pop(),this._consume(Jo.tokens.brace_right,"Expected '}' for loop."),e}_switch_statement(){if(!this._match(Jo.keywords.switch))return null;const e=this._updateNode(new so(null,[]));if(this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(Jo.tokens.attr)&&this._attribute(),this._consume(Jo.tokens.brace_left,"Expected '{' for switch."),e.cases=this._switch_body(),null==e.cases||0==e.cases.length)throw this._error(this._previous(),"Expected 'case' or 'default'.");return this._consume(Jo.tokens.brace_right,"Expected '}' for switch."),this._currentLoop.pop(),e}_switch_body(){const e=[];let t=!1;for(;this._check([Jo.keywords.default,Jo.keywords.case]);){if(this._match(Jo.keywords.case)){const n=this._case_selectors();for(const e of n)if(e instanceof Do){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");t=!0;break}this._match(Jo.tokens.colon),this._check(Jo.tokens.attr)&&this._attribute(),this._consume(Jo.tokens.brace_left,"Exected '{' for switch case.");const r=this._case_body();this._consume(Jo.tokens.brace_right,"Exected '}' for switch case."),e.push(this._updateNode(new Oo(n,r)))}if(this._match(Jo.keywords.default)){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");this._match(Jo.tokens.colon),this._check(Jo.tokens.attr)&&this._attribute(),this._consume(Jo.tokens.brace_left,"Exected '{' for switch default.");const n=this._case_body();this._consume(Jo.tokens.brace_right,"Exected '}' for switch default."),e.push(this._updateNode(new Fo(n)))}}return e}_case_selectors(){const e=[];for(this._match(Jo.keywords.default)?e.push(this._updateNode(new Do)):e.push(this._shift_expression());this._match(Jo.tokens.comma);)this._match(Jo.keywords.default)?e.push(this._updateNode(new Do)):e.push(this._shift_expression());return e}_case_body(){if(this._match(Jo.keywords.fallthrough))return this._consume(Jo.tokens.semicolon,"Expected ';'"),[];let e=this._statement();if(null==e)return[];e instanceof Array||(e=[e]);const t=this._case_body();return 0==t.length?e:[...e,t[0]]}_if_statement(){if(!this._match(Jo.keywords.if))return null;const e=this._currentLine,t=this._optional_paren_expression();this._check(Jo.tokens.attr)&&this._attribute();const n=this._compound_statement();let r=[];this._match_elseif()&&(this._check(Jo.tokens.attr)&&this._attribute(),r=this._elseif_statement(r));let i=null;return this._match(Jo.keywords.else)&&(this._check(Jo.tokens.attr)&&this._attribute(),i=this._compound_statement()),this._updateNode(new oo(t,n,r,i),e)}_match_elseif(){return this._tokens[this._current].type===Jo.keywords.else&&this._tokens[this._current+1].type===Jo.keywords.if&&(this._advance(),this._advance(),!0)}_elseif_statement(e=[]){const t=this._optional_paren_expression(),n=this._compound_statement();return e.push(this._updateNode(new jo(t,n))),this._match_elseif()&&(this._check(Jo.tokens.attr)&&this._attribute(),this._elseif_statement(e)),e}_return_statement(){if(!this._match(Jo.keywords.return))return null;const e=this._short_circuit_or_expression();return this._updateNode(new ao(e))}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(Jo.tokens.or_or);)e=this._updateNode(new No(this._previous().toString(),e,this._short_circuit_and_expr()));return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(Jo.tokens.and_and);)e=this._updateNode(new No(this._previous().toString(),e,this._inclusive_or_expression()));return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(Jo.tokens.or);)e=this._updateNode(new No(this._previous().toString(),e,this._exclusive_or_expression()));return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(Jo.tokens.xor);)e=this._updateNode(new No(this._previous().toString(),e,this._and_expression()));return e}_and_expression(){let e=this._equality_expression();for(;this._match(Jo.tokens.and);)e=this._updateNode(new No(this._previous().toString(),e,this._equality_expression()));return e}_equality_expression(){const e=this._relational_expression();return this._match([Jo.tokens.equal_equal,Jo.tokens.not_equal])?this._updateNode(new No(this._previous().toString(),e,this._relational_expression())):e}_relational_expression(){let e=this._shift_expression();for(;this._match([Jo.tokens.less_than,Jo.tokens.greater_than,Jo.tokens.less_than_equal,Jo.tokens.greater_than_equal]);)e=this._updateNode(new No(this._previous().toString(),e,this._shift_expression()));return e}_shift_expression(){let e=this._additive_expression();for(;this._match([Jo.tokens.shift_left,Jo.tokens.shift_right]);)e=this._updateNode(new No(this._previous().toString(),e,this._additive_expression()));return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([Jo.tokens.plus,Jo.tokens.minus]);)e=this._updateNode(new No(this._previous().toString(),e,this._multiplicative_expression()));return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([Jo.tokens.star,Jo.tokens.forward_slash,Jo.tokens.modulo]);)e=this._updateNode(new No(this._previous().toString(),e,this._unary_expression()));return e}_unary_expression(){return this._match([Jo.tokens.minus,Jo.tokens.bang,Jo.tokens.tilde,Jo.tokens.star,Jo.tokens.and])?this._updateNode(new Lo(this._previous().toString(),this._unary_expression())):this._singular_expression()}_singular_expression(){const e=this._primary_expression(),t=this._postfix_expression();return t&&(e.postfix=t),e}_postfix_expression(){if(this._match(Jo.tokens.bracket_left)){const e=this._short_circuit_or_expression();this._consume(Jo.tokens.bracket_right,"Expected ']'.");const t=this._updateNode(new Io(e)),n=this._postfix_expression();return n&&(t.postfix=n),t}if(this._match(Jo.tokens.period)){const e=this._consume(Jo.tokens.name,"Expected member name."),t=this._postfix_expression(),n=this._updateNode(new Eo(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){const t=this._getStruct(e);if(null!==t)return t;switch(e){case"void":return go.void;case"bool":return go.bool;case"i32":return go.i32;case"u32":return go.u32;case"f32":return go.f32;case"f16":return go.f16;case"vec2f":return bo.vec2f;case"vec3f":return bo.vec3f;case"vec4f":return bo.vec4f;case"vec2i":return bo.vec2i;case"vec3i":return bo.vec3i;case"vec4i":return bo.vec4i;case"vec2u":return bo.vec2u;case"vec3u":return bo.vec3u;case"vec4u":return bo.vec4u;case"vec2h":return bo.vec2h;case"vec3h":return bo.vec3h;case"vec4h":return bo.vec4h;case"mat2x2f":return bo.mat2x2f;case"mat2x3f":return bo.mat2x3f;case"mat2x4f":return bo.mat2x4f;case"mat3x2f":return bo.mat3x2f;case"mat3x3f":return bo.mat3x3f;case"mat3x4f":return bo.mat3x4f;case"mat4x2f":return bo.mat4x2f;case"mat4x3f":return bo.mat4x3f;case"mat4x4f":return bo.mat4x4f;case"mat2x2h":return bo.mat2x2h;case"mat2x3h":return bo.mat2x3h;case"mat2x4h":return bo.mat2x4h;case"mat3x2h":return bo.mat3x2h;case"mat3x3h":return bo.mat3x3h;case"mat3x4h":return bo.mat3x4h;case"mat4x2h":return bo.mat4x2h;case"mat4x3h":return bo.mat4x3h;case"mat4x4h":return bo.mat4x4h;case"mat2x2i":return bo.mat2x2i;case"mat2x3i":return bo.mat2x3i;case"mat2x4i":return bo.mat2x4i;case"mat3x2i":return bo.mat3x2i;case"mat3x3i":return bo.mat3x3i;case"mat3x4i":return bo.mat3x4i;case"mat4x2i":return bo.mat4x2i;case"mat4x3i":return bo.mat4x3i;case"mat4x4i":return bo.mat4x4i;case"mat2x2u":return bo.mat2x2u;case"mat2x3u":return bo.mat2x3u;case"mat2x4u":return bo.mat2x4u;case"mat3x2u":return bo.mat3x2u;case"mat3x3u":return bo.mat3x3u;case"mat3x4u":return bo.mat3x4u;case"mat4x2u":return bo.mat4x2u;case"mat4x3u":return bo.mat4x3u;case"mat4x4u":return bo.mat4x4u}return null}_validateTypeRange(e,t){if("i32"===t.name){if(e<-2147483648||e>2147483647)throw this._error(this._previous(),`Value out of range for i32: ${e}. Line: ${this._currentLine}.`)}else if("u32"===t.name&&(e<0||e>4294967295))throw this._error(this._previous(),`Value out of range for u32: ${e}. Line: ${this._currentLine}.`)}_primary_expression(){if(this._match(Jo.tokens.ident)){const e=this._previous().toString();if(this._check(Jo.tokens.paren_left)){const t=this._argument_expression_list(),n=this._getType(e);return null!==n?this._updateNode(new To(n,t)):this._updateNode(new So(e,t))}if(this._context.constants.has(e)){const t=this._context.constants.get(e);return this._updateNode(new ko(e,t.value))}return this._updateNode(new Co(e))}if(this._match(Jo.tokens.int_literal)){const e=this._previous().toString();let t=e.endsWith("i")||e.endsWith("i")?go.i32:e.endsWith("u")||e.endsWith("U")?go.u32:go.x32;const n=parseInt(e);return this._validateTypeRange(n,t),this._updateNode(new Ro(new $o(n,this._exec.getTypeInfo(t)),t))}if(this._match(Jo.tokens.uint_literal)){const e=parseInt(this._previous().toString());return this._validateTypeRange(e,go.u32),this._updateNode(new Ro(new $o(e,this._exec.getTypeInfo(go.u32)),go.u32))}if(this._match([Jo.tokens.decimal_float_literal,Jo.tokens.hex_float_literal])){let e=this._previous().toString(),t=e.endsWith("h");t&&(e=e.substring(0,e.length-1));const n=parseFloat(e);this._validateTypeRange(n,t?go.f16:go.f32);const r=t?go.f16:go.f32;return this._updateNode(new Ro(new $o(n,this._exec.getTypeInfo(r)),r))}if(this._match([Jo.keywords.true,Jo.keywords.false])){let e=this._previous().toString()===Jo.keywords.true.rule;return this._updateNode(new Ro(new $o(e?1:0,this._exec.getTypeInfo(go.bool)),go.bool))}if(this._check(Jo.tokens.paren_left))return this._paren_expression();if(this._match(Jo.keywords.bitcast)){this._consume(Jo.tokens.less_than,"Expected '<'.");const e=this._type_decl();this._consume(Jo.tokens.greater_than,"Expected '>'.");const t=this._paren_expression();return this._updateNode(new Po(e,t))}const e=this._type_decl(),t=this._argument_expression_list();return this._updateNode(new To(e,t))}_argument_expression_list(){if(!this._match(Jo.tokens.paren_left))return null;const e=[];do{if(this._check(Jo.tokens.paren_right))break;const t=this._short_circuit_or_expression();e.push(t)}while(this._match(Jo.tokens.comma));return this._consume(Jo.tokens.paren_right,"Expected ')' for agument list"),e}_optional_paren_expression(){this._match(Jo.tokens.paren_left);const e=this._short_circuit_or_expression();return this._match(Jo.tokens.paren_right),e}_paren_expression(){this._consume(Jo.tokens.paren_left,"Expected '('.");const e=this._short_circuit_or_expression();return this._consume(Jo.tokens.paren_right,"Expected ')'."),e}_struct_decl(){if(!this._match(Jo.keywords.struct))return null;const e=this._currentLine,t=this._consume(Jo.tokens.ident,"Expected name for struct.").toString();this._consume(Jo.tokens.brace_left,"Expected '{' for struct body.");const n=[];for(;!this._check(Jo.tokens.brace_right);){const e=this._attribute(),t=this._consume(Jo.tokens.name,"Expected variable name.").toString();this._consume(Jo.tokens.colon,"Expected ':' for struct member type.");const r=this._attribute(),i=this._type_decl();null!=i&&(i.attributes=r),this._check(Jo.tokens.brace_right)?this._match(Jo.tokens.comma):this._consume(Jo.tokens.comma,"Expected ',' for struct member."),n.push(this._updateNode(new Go(t,i,e)))}this._consume(Jo.tokens.brace_right,"Expected '}' after struct body.");const r=this._currentLine,i=this._updateNode(new _o(t,n,e,r),e);return this._context.structs.set(t,i),i}_global_variable_decl(){const e=this._variable_decl();if(!e)return null;if(this._match(Jo.tokens.equal)){const t=this._const_expression();e.value=t}if(null!==e.type&&e.value instanceof Ro){if("x32"!==e.value.type.name&&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 null===e.type&&e.value instanceof Ro&&(e.type="x32"===e.value.type.name?go.i32:e.value.type,e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type));return e}_override_variable_decl(){const e=this._override_decl();return e&&this._match(Jo.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){var e;if(!this._match(Jo.keywords.const))return null;const t=this._consume(Jo.tokens.name,"Expected variable name"),n=this._currentLine;let r=null;if(this._match(Jo.tokens.colon)){const e=this._attribute();r=this._type_decl(),null!=r&&(r.attributes=e)}let i=null;this._consume(Jo.tokens.equal,"const declarations require an assignment");const s=this._short_circuit_or_expression();try{let e=[go.f32],n=s.constEvaluate(this._exec,e);n instanceof $o&&this._validateTypeRange(n.value,e[0]),e[0]instanceof bo&&null===e[0].format&&n.typeInfo instanceof ps&&null!==n.typeInfo.format&&("f16"===n.typeInfo.format.name?e[0].format=go.f16:"f32"===n.typeInfo.format.name?e[0].format=go.f32:"i32"===n.typeInfo.format.name?e[0].format=go.i32:"u32"===n.typeInfo.format.name?e[0].format=go.u32:"bool"===n.typeInfo.format.name&&(e[0].format=go.bool)),i=this._updateNode(new Ro(n,e[0])),this._exec.context.setVariable(t.toString(),n)}catch(a){i=s}if(null!==r&&i instanceof Ro){if("x32"!==i.type.name&&r.getTypeName()!==i.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${i.type.name} to ${r.name}. Line:${this._currentLine}`);i.type=r,i.isScalar&&this._validateTypeRange(i.scalarValue,i.type)}else null===r&&i instanceof Ro&&(r=null!==(e=null==i?void 0:i.type)&&void 0!==e?e:go.f32,r===go.x32&&(r=go.i32));const o=this._updateNode(new qs(t.toString(),r,"","",i),n);return this._context.constants.set(o.name,o),o}_global_let_decl(){if(!this._match(Jo.keywords.let))return null;const e=this._currentLine,t=this._consume(Jo.tokens.name,"Expected variable name");let n=null;if(this._match(Jo.tokens.colon)){const e=this._attribute();n=this._type_decl(),null!=n&&(n.attributes=e)}let r=null;if(this._match(Jo.tokens.equal)&&(r=this._const_expression()),null!==n&&r instanceof Ro){if("x32"!==r.type.name&&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 null===n&&r instanceof Ro&&(n="x32"===r.type.name?go.i32:r.type);return r instanceof Ro&&r.isScalar&&this._validateTypeRange(r.scalarValue,n),this._updateNode(new Ys(t.toString(),n,"","",r),e)}_const_expression(){return this._short_circuit_or_expression()}_variable_decl(){if(!this._match(Jo.keywords.var))return null;const e=this._currentLine;let t="",n="";this._match(Jo.tokens.less_than)&&(t=this._consume(Jo.storage_class,"Expected storage_class.").toString(),this._match(Jo.tokens.comma)&&(n=this._consume(Jo.access_mode,"Expected access_mode.").toString()),this._consume(Jo.tokens.greater_than,"Expected '>'."));const r=this._consume(Jo.tokens.name,"Expected variable name");let i=null;if(this._match(Jo.tokens.colon)){const e=this._attribute();i=this._type_decl(),null!=i&&(i.attributes=e)}return this._updateNode(new Xs(r.toString(),i,t,n,null),e)}_override_decl(){if(!this._match(Jo.keywords.override))return null;const e=this._consume(Jo.tokens.name,"Expected variable name");let t=null;if(this._match(Jo.tokens.colon)){const e=this._attribute();t=this._type_decl(),null!=t&&(t.attributes=e)}return this._updateNode(new Qs(e.toString(),t,null))}_diagnostic(){this._consume(Jo.tokens.paren_left,"Expected '('");const e=this._consume(Jo.tokens.ident,"Expected severity control name.");this._consume(Jo.tokens.comma,"Expected ','");let t=this._consume(Jo.tokens.ident,"Expected diagnostic rule name.").toString();return this._match(Jo.tokens.period)&&(t+=`.${this._consume(Jo.tokens.ident,"Expected diagnostic message.").toString()}`),this._consume(Jo.tokens.paren_right,"Expected ')'"),this._updateNode(new co(e.toString(),t))}_enable_directive(){const e=this._consume(Jo.tokens.ident,"identity expected.");return this._updateNode(new Ao(e.toString()))}_requires_directive(){const e=[this._consume(Jo.tokens.ident,"identity expected.").toString()];for(;this._match(Jo.tokens.comma);){const t=this._consume(Jo.tokens.ident,"identity expected.");e.push(t.toString())}return this._updateNode(new lo(e))}_type_alias(){const e=this._consume(Jo.tokens.ident,"identity expected.");this._consume(Jo.tokens.equal,"Expected '=' for type alias.");let t=this._type_decl();if(null===t)throw this._error(this._peek(),"Expected Type for Alias.");this._context.aliases.has(t.name)&&(t=this._context.aliases.get(t.name).type);const n=this._updateNode(new uo(e.toString(),t));return this._context.aliases.set(n.name,n),n}_type_decl(){if(this._check([Jo.tokens.ident,...Jo.texel_format,Jo.keywords.bool,Jo.keywords.f32,Jo.keywords.i32,Jo.keywords.u32])){const e=this._advance().toString();if(this._context.structs.has(e))return this._context.structs.get(e);if(this._context.aliases.has(e))return this._context.aliases.get(e).type;if(!this._getType(e)){const t=this._updateNode(new mo(e));return this._forwardTypeCount++,t}return this._updateNode(new go(e))}let e=this._texture_sampler_types();if(e)return e;if(this._check(Jo.template_types)){let e=this._advance().toString(),t=null,n=null;return this._match(Jo.tokens.less_than)&&(t=this._type_decl(),n=null,this._match(Jo.tokens.comma)&&(n=this._consume(Jo.access_mode,"Expected access_mode for pointer").toString()),this._consume(Jo.tokens.greater_than,"Expected '>' for type.")),this._updateNode(new bo(e,t,n))}if(this._match(Jo.keywords.ptr)){let e=this._previous().toString();this._consume(Jo.tokens.less_than,"Expected '<' for pointer.");const t=this._consume(Jo.storage_class,"Expected storage_class for pointer");this._consume(Jo.tokens.comma,"Expected ',' for pointer.");const n=this._type_decl();let r=null;return this._match(Jo.tokens.comma)&&(r=this._consume(Jo.access_mode,"Expected access_mode for pointer").toString()),this._consume(Jo.tokens.greater_than,"Expected '>' for pointer."),this._updateNode(new vo(e,t.toString(),n,r))}const t=this._attribute();if(this._match(Jo.keywords.array)){let e=null,r=-1;const i=this._previous();let s=null;if(this._match(Jo.tokens.less_than)){e=this._type_decl(),this._context.aliases.has(e.name)&&(e=this._context.aliases.get(e.name).type);let t="";if(this._match(Jo.tokens.comma)){s=this._shift_expression();try{t=s.constEvaluate(this._exec).toString(),s=null}catch(n){t="1"}}this._consume(Jo.tokens.greater_than,"Expected '>' for array."),r=t?parseInt(t):0}const o=this._updateNode(new yo(i.toString(),t,e,r));return s&&this._deferArrayCountEval.push({arrayType:o,countNode:s}),o}return null}_texture_sampler_types(){if(this._match(Jo.sampler_type))return this._updateNode(new wo(this._previous().toString(),null,null));if(this._match(Jo.depth_texture_type))return this._updateNode(new wo(this._previous().toString(),null,null));if(this._match(Jo.sampled_texture_type)||this._match(Jo.multisampled_texture_type)){const e=this._previous();this._consume(Jo.tokens.less_than,"Expected '<' for sampler type.");const t=this._type_decl();return this._consume(Jo.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new wo(e.toString(),t,null))}if(this._match(Jo.storage_texture_type)){const e=this._previous();this._consume(Jo.tokens.less_than,"Expected '<' for sampler type.");const t=this._consume(Jo.texel_format,"Invalid texel format.").toString();this._consume(Jo.tokens.comma,"Expected ',' after texel format.");const n=this._consume(Jo.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(Jo.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new wo(e.toString(),t,n))}return null}_attribute(){let e=[];for(;this._match(Jo.tokens.attr);){const t=this._consume(Jo.attribute_name,"Expected attribute name"),n=this._updateNode(new zo(t.toString(),null));if(this._match(Jo.tokens.paren_left)){if(n.value=this._consume(Jo.literal_or_ident,"Expected attribute value").toString(),this._check(Jo.tokens.comma)){this._advance();do{const e=this._consume(Jo.literal_or_ident,"Expected attribute value").toString();n.value instanceof Array||(n.value=[n.value]),n.value.push(e)}while(this._match(Jo.tokens.comma))}this._consume(Jo.tokens.paren_right,"Expected ')'")}e.push(n)}return 0==e.length?null:e}}class Ca extends pa{constructor(e){super(),e&&this.update(e)}update(e){const t=(new Sa).parse(e);this.updateAST(t)}}function ka(e){return(null==e?void 0:e.format)?`${e.name}<${e.format.name}>`:e.name}globalThis.mathgl=globalThis.mathgl||{config:{EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1}};const Ra=globalThis.mathgl.config;function Pa(e,{precision:t=Ra.precision}={}){return e=function(e){return Math.round(e/Ra.EPSILON)*Ra.EPSILON}(e),`${parseFloat(e.toPrecision(t))}`}function Ia(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Ma(e,t,n){return function(e,t,n){if(Ia(e)){const r=e;n=n||function(e){return e.clone?e.clone():new Array(e.length)}(r);for(let i=0;iMath.max(t,Math.min(n,e)))}function La(e,t,n){return Ia(e)?e.map((e,r)=>La(e,t[r],n)):n*t+(1-n)*e}function Na(e,t,n){const r=Ra.EPSILON;try{if(e===t)return!0;if(Ia(e)&&Ia(t)){if(e.length!==t.length)return!1;for(let n=0;n0?", ":"")+Pa(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=0&&e=0&&e2*Math.PI)throw Error("expected radians")}function mA(e,t=[],n=0){const r=Math.fround(e),i=e-r;return t[n]=r,t[n+1]=i,t}const _A={name:"fp64arithmetic",vs:"\nuniform fp64arithmeticUniforms {\n uniform float ONE;\n} fp64;\n\n/*\nAbout LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n\nThe purpose of this workaround is to prevent shader compilers from\noptimizing away necessary arithmetic operations by swapping their sequences\nor transform the equation to some 'equivalent' form.\n\nThe method is to multiply an artifical variable, ONE, which will be known to\nthe compiler to be 1 only at runtime. The whole expression is then represented\nas a polynomial with respective to ONE. In the coefficients of all terms, only one a\nand one b should appear\n\nerr = (a + b) * ONE^6 - a * ONE^5 - (a + b) * ONE^4 + a * ONE^3 - b - (a + b) * ONE^2 + a * ONE\n*/\n\n// Divide float number to high and low floats to extend fraction bits\nvec2 split(float a) {\n const float SPLIT = 4097.0;\n float t = a * SPLIT;\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n float a_hi = t * fp64.ONE - (t - a);\n float a_lo = a * fp64.ONE - a_hi;\n#else\n float a_hi = t - (t - a);\n float a_lo = a - a_hi;\n#endif\n return vec2(a_hi, a_lo);\n}\n\n// Divide float number again when high float uses too many fraction bits\nvec2 split2(vec2 a) {\n vec2 b = split(a.x);\n b.y += a.y;\n return b;\n}\n\n// Special sum operation when a > b\nvec2 quickTwoSum(float a, float b) {\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n float sum = (a + b) * fp64.ONE;\n float err = b - (sum - a) * fp64.ONE;\n#else\n float sum = a + b;\n float err = b - (sum - a);\n#endif\n return vec2(sum, err);\n}\n\n// General sum operation\nvec2 twoSum(float a, float b) {\n float s = (a + b);\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n float v = (s * fp64.ONE - a) * fp64.ONE;\n float err = (a - (s - v) * fp64.ONE) * fp64.ONE * fp64.ONE * fp64.ONE + (b - v);\n#else\n float v = s - a;\n float err = (a - (s - v)) + (b - v);\n#endif\n return vec2(s, err);\n}\n\nvec2 twoSub(float a, float b) {\n float s = (a - b);\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n float v = (s * fp64.ONE - a) * fp64.ONE;\n float err = (a - (s - v) * fp64.ONE) * fp64.ONE * fp64.ONE * fp64.ONE - (b + v);\n#else\n float v = s - a;\n float err = (a - (s - v)) - (b + v);\n#endif\n return vec2(s, err);\n}\n\nvec2 twoSqr(float a) {\n float prod = a * a;\n vec2 a_fp64 = split(a);\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n float err = ((a_fp64.x * a_fp64.x - prod) * fp64.ONE + 2.0 * a_fp64.x *\n a_fp64.y * fp64.ONE * fp64.ONE) + a_fp64.y * a_fp64.y * fp64.ONE * fp64.ONE * fp64.ONE;\n#else\n float err = ((a_fp64.x * a_fp64.x - prod) + 2.0 * a_fp64.x * a_fp64.y) + a_fp64.y * a_fp64.y;\n#endif\n return vec2(prod, err);\n}\n\nvec2 twoProd(float a, float b) {\n float prod = a * b;\n vec2 a_fp64 = split(a);\n vec2 b_fp64 = split(b);\n float err = ((a_fp64.x * b_fp64.x - prod) + a_fp64.x * b_fp64.y +\n a_fp64.y * b_fp64.x) + a_fp64.y * b_fp64.y;\n return vec2(prod, err);\n}\n\nvec2 sum_fp64(vec2 a, vec2 b) {\n vec2 s, t;\n s = twoSum(a.x, b.x);\n t = twoSum(a.y, b.y);\n s.y += t.x;\n s = quickTwoSum(s.x, s.y);\n s.y += t.y;\n s = quickTwoSum(s.x, s.y);\n return s;\n}\n\nvec2 sub_fp64(vec2 a, vec2 b) {\n vec2 s, t;\n s = twoSub(a.x, b.x);\n t = twoSub(a.y, b.y);\n s.y += t.x;\n s = quickTwoSum(s.x, s.y);\n s.y += t.y;\n s = quickTwoSum(s.x, s.y);\n return s;\n}\n\nvec2 mul_fp64(vec2 a, vec2 b) {\n vec2 prod = twoProd(a.x, b.x);\n // y component is for the error\n prod.y += a.x * b.y;\n#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)\n prod = split2(prod);\n#endif\n prod = quickTwoSum(prod.x, prod.y);\n prod.y += a.y * b.x;\n#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)\n prod = split2(prod);\n#endif\n prod = quickTwoSum(prod.x, prod.y);\n return prod;\n}\n\nvec2 div_fp64(vec2 a, vec2 b) {\n float xn = 1.0 / b.x;\n#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)\n vec2 yn = mul_fp64(a, vec2(xn, 0));\n#else\n vec2 yn = a * xn;\n#endif\n float diff = (sub_fp64(a, mul_fp64(b, yn))).x;\n vec2 prod = twoProd(xn, diff);\n return sum_fp64(yn, prod);\n}\n\nvec2 sqrt_fp64(vec2 a) {\n if (a.x == 0.0 && a.y == 0.0) return vec2(0.0, 0.0);\n if (a.x < 0.0) return vec2(0.0 / 0.0, 0.0 / 0.0);\n\n float x = 1.0 / sqrt(a.x);\n float yn = a.x * x;\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n vec2 yn_sqr = twoSqr(yn) * fp64.ONE;\n#else\n vec2 yn_sqr = twoSqr(yn);\n#endif\n float diff = sub_fp64(a, yn_sqr).x;\n vec2 prod = twoProd(x * 0.5, diff);\n#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)\n return sum_fp64(split(yn), prod);\n#else\n return sum_fp64(vec2(yn, 0.0), prod);\n#endif\n}\n",defaultUniforms:{ONE:1},uniformTypes:{ONE:"f32"},fp64ify:mA,fp64LowPart:function(e){return e-Math.fround(e)},fp64ifyMatrix4:function(e){const t=new Float32Array(32);for(let n=0;n<4;++n)for(let r=0;r<4;++r){const i=4*n+r;mA(e[4*r+n],t,2*i)}return t}},bA={props:{},uniforms:{},name:"picking",uniformTypes:{isActive:"f32",isAttribute:"f32",isHighlightActive:"f32",useFloatColors:"f32",highlightedObjectColor:"vec3",highlightColor:"vec4"},defaultUniforms:{isActive:!1,isAttribute:!1,isHighlightActive:!1,useFloatColors:!0,highlightedObjectColor:[0,0,0],highlightColor:[0,1,1,1]},vs:"uniform pickingUniforms {\n float isActive;\n float isAttribute;\n float isHighlightActive;\n float useFloatColors;\n vec3 highlightedObjectColor;\n vec4 highlightColor;\n} picking;\n\nout vec4 picking_vRGBcolor_Avalid;\n\n// Normalize unsigned byte color to 0-1 range\nvec3 picking_normalizeColor(vec3 color) {\n return picking.useFloatColors > 0.5 ? color : color / 255.0;\n}\n\n// Normalize unsigned byte color to 0-1 range\nvec4 picking_normalizeColor(vec4 color) {\n return picking.useFloatColors > 0.5 ? color : color / 255.0;\n}\n\nbool picking_isColorZero(vec3 color) {\n return dot(color, vec3(1.0)) < 0.00001;\n}\n\nbool picking_isColorValid(vec3 color) {\n return dot(color, vec3(1.0)) > 0.00001;\n}\n\n// Check if this vertex is highlighted \nbool isVertexHighlighted(vec3 vertexColor) {\n vec3 highlightedObjectColor = picking_normalizeColor(picking.highlightedObjectColor);\n return\n bool(picking.isHighlightActive) && picking_isColorZero(abs(vertexColor - highlightedObjectColor));\n}\n\n// Set the current picking color\nvoid picking_setPickingColor(vec3 pickingColor) {\n pickingColor = picking_normalizeColor(pickingColor);\n\n if (bool(picking.isActive)) {\n // Use alpha as the validity flag. If pickingColor is [0, 0, 0] fragment is non-pickable\n picking_vRGBcolor_Avalid.a = float(picking_isColorValid(pickingColor));\n\n if (!bool(picking.isAttribute)) {\n // Stores the picking color so that the fragment shader can render it during picking\n picking_vRGBcolor_Avalid.rgb = pickingColor;\n }\n } else {\n // Do the comparison with selected item color in vertex shader as it should mean fewer compares\n picking_vRGBcolor_Avalid.a = float(isVertexHighlighted(pickingColor));\n }\n}\n\nvoid picking_setPickingAttribute(float value) {\n if (bool(picking.isAttribute)) {\n picking_vRGBcolor_Avalid.r = value;\n }\n}\n\nvoid picking_setPickingAttribute(vec2 value) {\n if (bool(picking.isAttribute)) {\n picking_vRGBcolor_Avalid.rg = value;\n }\n}\n\nvoid picking_setPickingAttribute(vec3 value) {\n if (bool(picking.isAttribute)) {\n picking_vRGBcolor_Avalid.rgb = value;\n }\n}\n",fs:"uniform pickingUniforms {\n float isActive;\n float isAttribute;\n float isHighlightActive;\n float useFloatColors;\n vec3 highlightedObjectColor;\n vec4 highlightColor;\n} picking;\n\nin vec4 picking_vRGBcolor_Avalid;\n\n/*\n * Returns highlight color if this item is selected.\n */\nvec4 picking_filterHighlightColor(vec4 color) {\n // If we are still picking, we don't highlight\n if (picking.isActive > 0.5) {\n return color;\n }\n\n bool selected = bool(picking_vRGBcolor_Avalid.a);\n\n if (selected) {\n // Blend in highlight color based on its alpha value\n float highLightAlpha = picking.highlightColor.a;\n float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);\n float highLightRatio = highLightAlpha / blendedAlpha;\n\n vec3 blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);\n return vec4(blendedRGB, blendedAlpha);\n } else {\n return color;\n }\n}\n\n/*\n * Returns picking color if picking enabled else unmodified argument.\n */\nvec4 picking_filterPickingColor(vec4 color) {\n if (bool(picking.isActive)) {\n if (picking_vRGBcolor_Avalid.a == 0.0) {\n discard;\n }\n return picking_vRGBcolor_Avalid;\n }\n return color;\n}\n\n/*\n * Returns picking color if picking is enabled if not\n * highlight color if this item is selected, otherwise unmodified argument.\n */\nvec4 picking_filterColor(vec4 color) {\n vec4 highlightColor = picking_filterHighlightColor(color);\n return picking_filterPickingColor(highlightColor);\n}\n",getUniforms:function(e={},t){const n={};if(void 0===e.highlightedObjectColor);else if(null===e.highlightedObjectColor)n.isHighlightActive=!1;else{n.isHighlightActive=!0;const t=e.highlightedObjectColor.slice(0,3);n.highlightedObjectColor=t}if(e.highlightColor){const t=Array.from(e.highlightColor,e=>e/255);Number.isFinite(t[3])||(t[3]=1),n.highlightColor=t}return void 0!==e.isActive&&(n.isActive=Boolean(e.isActive),n.isAttribute=Boolean(e.isAttribute)),void 0!==e.useFloatColors&&(n.useFloatColors=Boolean(e.useFloatColors)),n}},vA="precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int lightType;\n\n int directionalLightCount;\n int pointLightCount;\n\n vec3 ambientColor;\n\n vec3 lightColor0;\n vec3 lightPosition0;\n vec3 lightDirection0;\n vec3 lightAttenuation0;\n\n vec3 lightColor1;\n vec3 lightPosition1;\n vec3 lightDirection1;\n vec3 lightAttenuation1;\n\n vec3 lightColor2;\n vec3 lightPosition2;\n vec3 lightDirection2;\n vec3 lightAttenuation2;\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n switch (index) {\n case 0:\n return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);\n case 1:\n return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);\n case 2:\n default: \n return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);\n }\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n switch (index) {\n case 0:\n return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);\n case 1:\n return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);\n case 2:\n default: \n return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);\n }\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";var yA,wA;(wA=yA||(yA={}))[wA.POINT=0]="POINT",wA[wA.DIRECTIONAL=1]="DIRECTIONAL";const xA={props:{},uniforms:{},name:"lighting",defines:{},uniformTypes:{enabled:"i32",lightType:"i32",directionalLightCount:"i32",pointLightCount:"i32",ambientColor:"vec3",lightColor0:"vec3",lightPosition0:"vec3",lightDirection0:"vec3",lightAttenuation0:"vec3",lightColor1:"vec3",lightPosition1:"vec3",lightDirection1:"vec3",lightAttenuation1:"vec3",lightColor2:"vec3",lightPosition2:"vec3",lightDirection2:"vec3",lightAttenuation2:"vec3"},defaultUniforms:{enabled:1,lightType:yA.POINT,directionalLightCount:0,pointLightCount:0,ambientColor:[.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:"// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n color: vec3,\n};\n\nstruct PointLight {\n color: vec3,\n position: vec3,\n attenuation: vec3, // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n color: vec3,\n direction: vec3,\n};\n\nstruct lightingUniforms {\n enabled: i32,\n pointLightCount: i32,\n directionalLightCount: i32,\n\n ambientColor: vec3,\n\n // TODO - support multiple lights by uncommenting arrays below\n lightType: i32,\n lightColor: vec3,\n lightDirection: vec3,\n lightPosition: vec3,\n lightAttenuation: vec3,\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n};\n\n// Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls)\n@binding(1) @group(0) var lighting : lightingUniforms;\n\nfn lighting_getPointLight(index: i32) -> PointLight {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nfn lighting_getDirectionalLight(index: i32) -> DirectionalLight {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n",vs:vA,fs:vA,getUniforms:function(e,t={}){if(!(e=e?{...e}:e))return{...xA.defaultUniforms};e.lights&&(e={...e,...TA(e.lights),lights:void 0});const{ambientLight:n,pointLights:r,directionalLights:i}=e||{};if(!(n||r&&r.length>0||i&&i.length>0))return{...xA.defaultUniforms,enabled:0};const s={...xA.defaultUniforms,...t,...EA({ambientLight:n,pointLights:r,directionalLights:i})};return void 0!==e.enabled&&(s.enabled=e.enabled?1:0),s}};function EA({ambientLight:e,pointLights:t=[],directionalLights:n=[]}){const r={};r.ambientColor=SA(e);let i=0;for(const s of t){r.lightType=yA.POINT;const e=i;r[`lightColor${e}`]=SA(s),r[`lightPosition${e}`]=s.position,r[`lightAttenuation${e}`]=s.attenuation||[1,0,0],i++}for(const s of n){r.lightType=yA.DIRECTIONAL;const e=i;r[`lightColor${e}`]=SA(s),r[`lightDirection${e}`]=s.direction,i++}return i>5&&Pr.warn("MAX_LIGHTS exceeded")(),r.directionalLightCount=n.length,r.pointLightCount=t.length,r}function TA(e){var t,n;const r={pointLights:[],directionalLights:[]};for(const i of e||[])switch(i.type){case"ambient":r.ambientLight=i;break;case"directional":null==(t=r.directionalLights)||t.push(i);break;case"point":null==(n=r.pointLights)||n.push(i)}return r}function SA(e={}){const{color:t=[0,0,0],intensity:n=1}=e;return t.map(e=>e*n/255)}const CA="uniform phongMaterialUniforms {\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n",kA="#define MAX_LIGHTS 3\n\nuniform phongMaterialUniforms {\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n\nvec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {\n vec3 halfway_direction = normalize(light_direction + view_direction);\n float lambertian = dot(light_direction, normal_worldspace);\n float specular = 0.0;\n if (lambertian > 0.0) {\n float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);\n specular = pow(specular_angle, material.shininess);\n }\n lambertian = max(lambertian, 0.0);\n return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;\n}\n\nvec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {\n vec3 lightColor = surfaceColor;\n\n if (lighting.enabled == 0) {\n return lightColor;\n }\n\n vec3 view_direction = normalize(cameraPosition - position_worldspace);\n lightColor = material.ambient * surfaceColor * lighting.ambientColor;\n\n for (int i = 0; i < lighting.pointLightCount; i++) {\n PointLight pointLight = lighting_getPointLight(i);\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);\n }\n\n int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);\n for (int i = lighting.pointLightCount; i < totalLights; i++) {\n DirectionalLight directionalLight = lighting_getDirectionalLight(i);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n \n return lightColor;\n}\n",RA="struct phongMaterialUniforms {\n ambient: f32,\n diffuse: f32,\n shininess: f32,\n specularColor: vec3,\n};\n\n@binding(2) @group(0) var phongMaterial : phongMaterialUniforms;\n\nfn lighting_getLightColor(surfaceColor: vec3, light_direction: vec3, view_direction: vec3, normal_worldspace: vec3, color: vec3) -> vec3 {\n let halfway_direction: vec3 = normalize(light_direction + view_direction);\n var lambertian: f32 = dot(light_direction, normal_worldspace);\n var specular: f32 = 0.0;\n if (lambertian > 0.0) {\n let specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);\n specular = pow(specular_angle, phongMaterial.shininess);\n }\n lambertian = max(lambertian, 0.0);\n return (lambertian * phongMaterial.diffuse * surfaceColor + specular * phongMaterial.specularColor) * color;\n}\n\nfn lighting_getLightColor2(surfaceColor: vec3, cameraPosition: vec3, position_worldspace: vec3, normal_worldspace: vec3) -> vec3 {\n var lightColor: vec3 = surfaceColor;\n\n if (lighting.enabled == 0) {\n return lightColor;\n }\n\n let view_direction: vec3 = normalize(cameraPosition - position_worldspace);\n lightColor = phongMaterial.ambient * surfaceColor * lighting.ambientColor;\n\n if (lighting.lightType == 0) {\n let pointLight: PointLight = lighting_getPointLight(0);\n let light_position_worldspace: vec3 = pointLight.position;\n let light_direction: vec3 = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n } else if (lighting.lightType == 1) {\n var directionalLight: DirectionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n \n return lightColor;\n /*\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= lighting.pointLightCount) {\n break;\n }\n PointLight pointLight = lighting.pointLight[i];\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n }\n\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= lighting.directionalLightCount) {\n break;\n }\n DirectionalLight directionalLight = lighting.directionalLight[i];\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n */\n}\n\nfn lighting_getSpecularLightColor(cameraPosition: vec3, position_worldspace: vec3, normal_worldspace: vec3) -> vec3{\n var lightColor = vec3(0, 0, 0);\n let surfaceColor = vec3(0, 0, 0);\n\n if (lighting.enabled == 0) {\n let view_direction = normalize(cameraPosition - position_worldspace);\n\n switch (lighting.lightType) {\n case 0, default: {\n let pointLight: PointLight = lighting_getPointLight(0);\n let light_position_worldspace: vec3 = pointLight.position;\n let light_direction: vec3 = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n }\n case 1: {\n let directionalLight: DirectionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n }\n }\n return lightColor;\n}\n",PA={props:{},name:"gouraudMaterial",vs:kA.replace("phongMaterial","gouraudMaterial"),fs:CA.replace("phongMaterial","gouraudMaterial"),source:RA.replaceAll("phongMaterial","gouraudMaterial"),defines:{LIGHTING_VERTEX:!0},dependencies:[xA],uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(e){const t={...e};return t.specularColor&&(t.specularColor=t.specularColor.map(e=>e/255)),{...PA.defaultUniforms,...t}}},IA={name:"phongMaterial",dependencies:[xA],source:RA,vs:CA,fs:kA,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(e){const t={...e};return t.specularColor&&(t.specularColor=t.specularColor.map(e=>e/255)),{...IA.defaultUniforms,...t}}},MA="uniform layerUniforms {\n uniform float opacity;\n} layer;\n",LA={name:"layer",vs:MA,fs:MA,getUniforms:e=>({opacity:Math.pow(e.opacity,1/2.2)}),uniformTypes:{opacity:"f32"}},NA="#define SMOOTH_EDGE_RADIUS 0.5",BA={name:"geometry",source:"const SMOOTH_EDGE_RADIUS: f32 = 0.5;\n\nstruct VertexGeometry {\n position: vec4,\n worldPosition: vec3,\n worldPositionAlt: vec3,\n normal: vec3,\n uv: vec2,\n pickingColor: vec3,\n};\n\nvar geometry_: VertexGeometry = VertexGeometry(\n vec4(0.0, 0.0, 1.0, 0.0),\n vec3(0.0, 0.0, 0.0),\n vec3(0.0, 0.0, 0.0),\n vec3(0.0, 0.0, 0.0),\n vec2(0.0, 0.0),\n vec3(0.0, 0.0, 0.0)\n);\n\nstruct FragmentGeometry {\n uv: vec2,\n};\n\nvar fragmentGeometry: FragmentGeometry;\n\nfn smoothedge(edge: f32, x: f32) -> f32 {\n return smoothstep(edge - SMOOTH_EDGE_RADIUS, edge + SMOOTH_EDGE_RADIUS, x);\n}\n",vs:`${NA}\n\nstruct VertexGeometry {\n vec4 position;\n vec3 worldPosition;\n vec3 worldPositionAlt;\n vec3 normal;\n vec2 uv;\n vec3 pickingColor;\n} geometry = VertexGeometry(\n vec4(0.0, 0.0, 1.0, 0.0),\n vec3(0.0),\n vec3(0.0),\n vec3(0.0),\n vec2(0.0),\n vec3(0.0)\n);\n`,fs:`${NA}\n\nstruct FragmentGeometry {\n vec2 uv;\n} geometry;\n\nfloat smoothedge(float edge, float x) {\n return smoothstep(edge - SMOOTH_EDGE_RADIUS, edge + SMOOTH_EDGE_RADIUS, x);\n}\n`};var DA,OA,FA,UA,jA,GA;(OA=DA||(DA={}))[OA.Start=1]="Start",OA[OA.Move=2]="Move",OA[OA.End=4]="End",OA[OA.Cancel=8]="Cancel",(UA=FA||(FA={}))[UA.None=0]="None",UA[UA.Left=1]="Left",UA[UA.Right=2]="Right",UA[UA.Up=4]="Up",UA[UA.Down=8]="Down",UA[UA.Horizontal=3]="Horizontal",UA[UA.Vertical=12]="Vertical",UA[UA.All=15]="All",(GA=jA||(jA={}))[GA.Possible=1]="Possible",GA[GA.Began=2]="Began",GA[GA.Changed=4]="Changed",GA[GA.Ended=8]="Ended",GA[GA.Recognized=8]="Recognized",GA[GA.Cancelled=16]="Cancelled",GA[GA.Failed=32]="Failed";const zA="manipulation",VA="none",WA="pan-x",HA="pan-y";class $A{constructor(e,t){this.actions="",this.manager=e,this.set(t)}set(e){"compute"===e&&(e=this.compute()),this.manager.element&&(this.manager.element.style.touchAction=e,this.actions=e)}update(){this.set(this.manager.options.touchAction)}compute(){let e=[];for(const t of this.manager.recognizers)t.options.enable&&(e=e.concat(t.getTouchAction()));return function(e){if(e.includes(VA))return VA;const t=e.includes(WA),n=e.includes(HA);return t&&n?VA:t||n?t?WA:HA:e.includes(zA)?zA:"auto"}(e.join(" "))}}function XA(e){return e.trim().split(/\s+/g)}function QA(e,t,n){if(e)for(const r of XA(t))e.addEventListener(r,n,!1)}function YA(e,t,n){if(e)for(const r of XA(t))e.removeEventListener(r,n,!1)}function qA(e){return(e.ownerDocument||e).defaultView}function KA(e){const t=e.length;if(1===t)return{x:Math.round(e[0].clientX),y:Math.round(e[0].clientY)};let n=0,r=0,i=0;for(;i=Math.abs(t)?e<0?FA.Left:FA.Right:t<0?FA.Up:FA.Down}function rl(e,t,n){return{x:t/e||0,y:n/e||0}}let il=class{constructor(e){this.evEl="",this.evWin="",this.evTarget="",this.domHandler=e=>{this.manager.options.enable&&this.handler(e)},this.manager=e,this.element=e.element,this.target=e.options.inputTarget||e.element}callback(e,t){!function(e,t,n){const r=n.pointers.length,i=n.changedPointers.length,s=t&DA.Start&&r-i===0,o=t&(DA.End|DA.Cancel)&&r-i===0;n.isFirst=Boolean(s),n.isFinal=Boolean(o),s&&(e.session={}),n.eventType=t;const a=function(e,t){const{session:n}=e,{pointers:r}=t,{length:i}=r;n.firstInput||(n.firstInput=ZA(t)),i>1&&!n.firstMultiple?n.firstMultiple=ZA(t):1===i&&(n.firstMultiple=!1);const{firstInput:s,firstMultiple:o}=n,a=o?o.center:s.center,A=t.center=KA(r);t.timeStamp=Date.now(),t.deltaTime=t.timeStamp-s.timeStamp,t.angle=function(e,t){const n=t.x-e.x,r=t.y-e.y;return 180*Math.atan2(r,n)/Math.PI}(a,A),t.distance=JA(a,A);const{deltaX:l,deltaY:c}=function(e,t){const n=t.center;let r=e.offsetDelta,i=e.prevDelta;const s=e.prevInput;return t.eventType!==DA.Start&&(null==s?void 0:s.eventType)!==DA.End||(i=e.prevDelta={x:(null==s?void 0:s.deltaX)||0,y:(null==s?void 0:s.deltaY)||0},r=e.offsetDelta={x:n.x,y:n.y}),{deltaX:i.x+(n.x-r.x),deltaY:i.y+(n.y-r.y)}}(n,t);t.deltaX=l,t.deltaY=c,t.offsetDirection=nl(t.deltaX,t.deltaY);const u=rl(t.deltaTime,t.deltaX,t.deltaY);var h,d;t.overallVelocityX=u.x,t.overallVelocityY=u.y,t.overallVelocity=Math.abs(u.x)>Math.abs(u.y)?u.x:u.y,t.scale=o?(h=o.pointers,el((d=r)[0],d[1])/el(h[0],h[1])):1,t.rotation=o?function(e,t){return tl(t[1],t[0])-tl(e[1],e[0])}(o.pointers,r):0,t.maxPointers=n.prevInput?t.pointers.length>n.prevInput.maxPointers?t.pointers.length:n.prevInput.maxPointers:t.pointers.length;let f=e.element;return function(e,t){let n=e;for(;n;){if(n===t)return!0;n=n.parentNode}return!1}(t.srcEvent.target,f)&&(f=t.srcEvent.target),t.target=f,function(e,t){const n=e.lastInterval||t,r=t.timeStamp-n.timeStamp;let i,s,o,a;if(t.eventType!==DA.Cancel&&(r>25||void 0===n.velocity)){const A=t.deltaX-n.deltaX,l=t.deltaY-n.deltaY,c=rl(r,A,l);s=c.x,o=c.y,i=Math.abs(c.x)>Math.abs(c.y)?c.x:c.y,a=nl(A,l),e.lastInterval=t}else i=n.velocity,s=n.velocityX,o=n.velocityY,a=n.direction;t.velocity=i,t.velocityX=s,t.velocityY=o,t.direction=a}(n,t),t}(e,n);e.emit("hammer.input",a),e.recognize(a),e.session.prevInput=a}(this.manager,e,t)}init(){QA(this.element,this.evEl,this.domHandler),QA(this.target,this.evTarget,this.domHandler),QA(qA(this.element),this.evWin,this.domHandler)}destroy(){YA(this.element,this.evEl,this.domHandler),YA(this.target,this.evTarget,this.domHandler),YA(qA(this.element),this.evWin,this.domHandler)}};const sl={pointerdown:DA.Start,pointermove:DA.Move,pointerup:DA.End,pointercancel:DA.Cancel,pointerout:DA.Cancel};class ol extends il{constructor(e){super(e),this.evEl="pointerdown",this.evWin="pointermove pointerup pointercancel",this.store=this.manager.session.pointerEvents=[],this.init()}handler(e){const{store:t}=this;let n=!1;const r=sl[e.type],i=e.pointerType,s="touch"===i;let o=t.findIndex(t=>t.pointerId===e.pointerId);r&DA.Start&&(e.buttons||s)?o<0&&(t.push(e),o=t.length-1):r&(DA.End|DA.Cancel)&&(n=!0),o<0||(t[o]=e,this.callback(r,{pointers:t,changedPointers:[e],eventType:r,pointerType:i,srcEvent:e}),n&&t.splice(o,1))}}const al=["","webkit","Moz","MS","ms","o"];function Al(e,t){const n=t[0].toUpperCase()+t.slice(1);for(const r of al){const i=r?r+n:t;if(i in e)return i}}const ll={touchAction:"compute",enable:!0,inputTarget:null,cssProps:{userSelect:"none",userDrag:"none",touchCallout:"none",tapHighlightColor:"rgba(0,0,0,0)"}};class cl{constructor(e,t){this.options={...ll,...t,cssProps:{...ll.cssProps,...t.cssProps},inputTarget:t.inputTarget||e},this.handlers={},this.session={},this.recognizers=[],this.oldCssProps={},this.element=e,this.input=new ol(this),this.touchAction=new $A(this,this.options.touchAction),this.toggleCssProps(!0)}set(e){return Object.assign(this.options,e),e.touchAction&&this.touchAction.update(),e.inputTarget&&(this.input.destroy(),this.input.target=e.inputTarget,this.input.init()),this}stop(e){this.session.stopped=e?2:1}recognize(e){const{session:t}=this;if(t.stopped)return;let n;this.session.prevented&&e.srcEvent.preventDefault();const{recognizers:r}=this;let{curRecognizer:i}=t;(!i||i&&i.state&jA.Recognized)&&(i=t.curRecognizer=null);let s=0;for(;s-1&&this.requireFail.splice(e,1)}return this}hasRequireFailures(){return Boolean(this.requireFail.find(e=>e.options.enable))}canRecognizeWith(e){return Boolean(this.simultaneous[e.id])}emit(e){if(!e)return;const{state:t}=this;t=jA.Ended&&this.manager.emit(this.options.event+hl(t),e)}tryEmit(e){this.canEmit()?this.emit(e):this.state=jA.Failed}canEmit(){let e=0;for(;e{this.state=jA.Recognized,this.tryEmit(this._input)},t.interval),jA.Began):jA.Recognized}return jA.Failed}failTimeout(){return this._timer=setTimeout(()=>{this.state=jA.Failed},this.options.interval),jA.Failed}reset(){clearTimeout(this._timer)}emit(e){this.state===jA.Recognized&&(e.tapCount=this.count,this.manager.emit(this.options.event,e))}}const gl=["","start","move","end","cancel","up","down","left","right"];class ml extends fl{constructor(e={}){super({enable:!0,pointers:1,event:"pan",threshold:10,direction:FA.All,...e}),this.pX=null,this.pY=null}getTouchAction(){const{options:{direction:e}}=this,t=[];return e&FA.Horizontal&&t.push(HA),e&FA.Vertical&&t.push(WA),t}getEventNames(){return gl.map(e=>this.options.event+e)}directionTest(e){const{options:t}=this;let n=!0,{distance:r}=e,{direction:i}=e;const s=e.deltaX,o=e.deltaY;return i&t.direction||(t.direction&FA.Horizontal?(i=0===s?FA.None:s<0?FA.Left:FA.Right,n=s!==this.pX,r=Math.abs(e.deltaX)):(i=0===o?FA.None:o<0?FA.Up:FA.Down,n=o!==this.pY,r=Math.abs(e.deltaY))),e.direction=i,n&&r>t.threshold&&Boolean(i&t.direction)}attrTest(e){return super.attrTest(e)&&(Boolean(this.state&jA.Began)||!(this.state&jA.Began)&&this.directionTest(e))}emit(e){this.pX=e.deltaX,this.pY=e.deltaY;const t=FA[e.direction].toLowerCase();t&&(e.additionalEvent=this.options.event+t),super.emit(e)}}const _l=["","start","move","end","cancel","in","out"];class bl{constructor(e,t,n){this.element=e,this.callback=t,this.options=n}}const vl=-1!==("undefined"!=typeof navigator&&navigator.userAgent?navigator.userAgent.toLowerCase():"").indexOf("firefox"),yl=4.000244140625;class wl extends bl{constructor(e,t,n){super(e,t,{enable:!0,...n}),this.handleEvent=e=>{if(!this.options.enable)return;let t=e.deltaY;globalThis.WheelEvent&&(vl&&e.deltaMode===globalThis.WheelEvent.DOM_DELTA_PIXEL&&(t/=globalThis.devicePixelRatio),e.deltaMode===globalThis.WheelEvent.DOM_DELTA_LINE&&(t*=40)),0!==t&&t%yl===0&&(t=Math.floor(t/yl)),e.shiftKey&&t&&(t*=.25),this.callback({type:"wheel",center:{x:e.clientX,y:e.clientY},delta:-t,srcEvent:e,pointerType:"mouse",target:e.target})},e.addEventListener("wheel",this.handleEvent,{passive:!1})}destroy(){this.element.removeEventListener("wheel",this.handleEvent)}enableEventType(e,t){"wheel"===e&&(this.options.enable=t)}}const xl=["mousedown","mousemove","mouseup","mouseover","mouseout","mouseleave"];class El extends bl{constructor(e,t,n){super(e,t,{enable:!0,...n}),this.handleEvent=e=>{this.handleOverEvent(e),this.handleOutEvent(e),this.handleEnterEvent(e),this.handleLeaveEvent(e),this.handleMoveEvent(e)},this.pressed=!1;const{enable:r}=this.options;this.enableMoveEvent=r,this.enableLeaveEvent=r,this.enableEnterEvent=r,this.enableOutEvent=r,this.enableOverEvent=r,xl.forEach(t=>e.addEventListener(t,this.handleEvent))}destroy(){xl.forEach(e=>this.element.removeEventListener(e,this.handleEvent))}enableEventType(e,t){switch(e){case"pointermove":this.enableMoveEvent=t;break;case"pointerover":this.enableOverEvent=t;break;case"pointerout":this.enableOutEvent=t;break;case"pointerenter":this.enableEnterEvent=t;break;case"pointerleave":this.enableLeaveEvent=t}}handleOverEvent(e){this.enableOverEvent&&"mouseover"===e.type&&this._emit("pointerover",e)}handleOutEvent(e){this.enableOutEvent&&"mouseout"===e.type&&this._emit("pointerout",e)}handleEnterEvent(e){this.enableEnterEvent&&"mouseenter"===e.type&&this._emit("pointerenter",e)}handleLeaveEvent(e){this.enableLeaveEvent&&"mouseleave"===e.type&&this._emit("pointerleave",e)}handleMoveEvent(e){if(this.enableMoveEvent)switch(e.type){case"mousedown":e.button>=0&&(this.pressed=!0);break;case"mousemove":0===e.buttons&&(this.pressed=!1),this.pressed||this._emit("pointermove",e);break;case"mouseup":this.pressed=!1}}_emit(e,t){this.callback({type:e,center:{x:t.clientX,y:t.clientY},srcEvent:t,pointerType:"mouse",target:t.target})}}const Tl=["keydown","keyup"];class Sl extends bl{constructor(e,t,n){super(e,t,{enable:!0,tabIndex:0,...n}),this.handleEvent=e=>{const t=e.target||e.srcElement;"INPUT"===t.tagName&&"text"===t.type||"TEXTAREA"===t.tagName||(this.enableDownEvent&&"keydown"===e.type&&this.callback({type:"keydown",srcEvent:e,key:e.key,target:e.target}),this.enableUpEvent&&"keyup"===e.type&&this.callback({type:"keyup",srcEvent:e,key:e.key,target:e.target}))},this.enableDownEvent=this.options.enable,this.enableUpEvent=this.options.enable,e.tabIndex=this.options.tabIndex,e.style.outline="none",Tl.forEach(t=>e.addEventListener(t,this.handleEvent))}destroy(){Tl.forEach(e=>this.element.removeEventListener(e,this.handleEvent))}enableEventType(e,t){"keydown"===e&&(this.enableDownEvent=t),"keyup"===e&&(this.enableUpEvent=t)}}class Cl extends bl{constructor(e,t,n){super(e,t,n),this.handleEvent=e=>{this.options.enable&&this.callback({type:"contextmenu",center:{x:e.clientX,y:e.clientY},srcEvent:e,pointerType:"mouse",target:e.target})},e.addEventListener("contextmenu",this.handleEvent)}destroy(){this.element.removeEventListener("contextmenu",this.handleEvent)}enableEventType(e,t){"contextmenu"===e&&(this.options.enable=t)}}const kl={pointerdown:1,pointermove:2,pointerup:4,mousedown:1,mousemove:2,mouseup:4};function Rl(e){const t=kl[e.srcEvent.type];if(!t)return null;const{buttons:n,button:r}=e.srcEvent;let i=!1,s=!1,o=!1;return 2===t?(i=Boolean(1&n),s=Boolean(4&n),o=Boolean(2&n)):(i=0===r,s=1===r,o=2===r),{leftButton:i,middleButton:s,rightButton:o}}function Pl(e,t){const n=e.center;if(!n)return null;const r=t.getBoundingClientRect(),i=r.width/t.offsetWidth||1,s=r.height/t.offsetHeight||1;return{center:n,offsetCenter:{x:(n.x-r.left-t.clientLeft)/i,y:(n.y-r.top-t.clientTop)/s}}}const Il={srcElement:"root",priority:0};class Ml{constructor(e,t){this.handleEvent=e=>{if(this.isEmpty())return;const t=this._normalizeEvent(e);let n=e.srcEvent.target;for(;n&&n!==t.rootElement;){if(this._emit(t,n),t.handled)return;n=n.parentNode}this._emit(t,"root")},this.eventManager=e,this.recognizerName=t,this.handlers=[],this.handlersByElement=new Map,this._active=!1}isEmpty(){return!this._active}add(e,t,n,r=!1,i=!1){const{handlers:s,handlersByElement:o}=this,a={...Il,...n};let A=o.get(a.srcElement);A||(A=[],o.set(a.srcElement,A));const l={type:e,handler:t,srcElement:a.srcElement,priority:a.priority};r&&(l.once=!0),i&&(l.passive=!0),s.push(l),this._active=this._active||!l.passive;let c=A.length-1;for(;c>=0&&!(A[c].priority>=l.priority);)c--;A.splice(c+1,0,l)}remove(e,t){const{handlers:n,handlersByElement:r}=this;for(let i=n.length-1;i>=0;i--){const s=n[i];if(s.type===e&&s.handler===t){n.splice(i,1);const e=r.get(s.srcElement);e.splice(e.indexOf(s),1),0===e.length&&r.delete(s.srcElement)}}this._active=n.some(e=>!e.passive)}_emit(e,t){const n=this.handlersByElement.get(t);if(n){let t=!1;const r=()=>{e.handled=!0},i=()=>{e.handled=!0,t=!0},s=[];for(let o=0;o{e.srcEvent.preventDefault()},stopImmediatePropagation:null,stopPropagation:null,handled:!1,rootElement:t}}}function Ll(e){if("recognizer"in e)return e;let t;const n=Array.isArray(e)?[...e]:[e];return t="function"==typeof n[0]?new(n.shift())(n.shift()||{}):n.shift(),{recognizer:t,recognizeWith:"string"==typeof n[0]?[n[0]]:n[0],requireFailure:"string"==typeof n[1]?[n[1]]:n[1]}}class Nl{constructor(e=null,t={}){if(this._onBasicInput=e=>{this.manager.emit(e.srcEvent.type,e)},this._onOtherEvent=e=>{this.manager.emit(e.type,e)},this.options={recognizers:[],events:{},touchAction:"compute",tabIndex:0,cssProps:{},...t},this.events=new Map,this.element=e,e){this.manager=new cl(e,this.options);for(const e of this.options.recognizers){const{recognizer:t,recognizeWith:n,requireFailure:r}=Ll(e);this.manager.add(t),n&&t.recognizeWith(n),r&&t.requireFailure(r)}this.manager.on("hammer.input",this._onBasicInput),this.wheelInput=new wl(e,this._onOtherEvent,{enable:!1}),this.moveInput=new El(e,this._onOtherEvent,{enable:!1}),this.keyInput=new Sl(e,this._onOtherEvent,{enable:!1,tabIndex:t.tabIndex}),this.contextmenuInput=new Cl(e,this._onOtherEvent,{enable:!1}),this.on(this.options.events)}}getElement(){return this.element}destroy(){this.element&&(this.wheelInput.destroy(),this.moveInput.destroy(),this.keyInput.destroy(),this.contextmenuInput.destroy(),this.manager.destroy())}on(e,t,n){this._addEventHandler(e,t,n,!1)}once(e,t,n){this._addEventHandler(e,t,n,!0)}watch(e,t,n){this._addEventHandler(e,t,n,!1,!0)}off(e,t){this._removeEventHandler(e,t)}_toggleRecognizer(e,t){var n,r,i,s;const{manager:o}=this;if(!o)return;const a=o.get(e);a&&(a.set({enable:t}),o.touchAction.update()),null==(n=this.wheelInput)||n.enableEventType(e,t),null==(r=this.moveInput)||r.enableEventType(e,t),null==(i=this.keyInput)||i.enableEventType(e,t),null==(s=this.contextmenuInput)||s.enableEventType(e,t)}_addEventHandler(e,t,n,r,i){if("string"!=typeof e){n=t;for(const[t,s]of Object.entries(e))this._addEventHandler(t,s,n,r,i);return}const{manager:s,events:o}=this;if(!s)return;let a=o.get(e);if(!a){const t=this._getRecognizerName(e)||e;a=new Ml(this,t),o.set(e,a),s&&s.on(e,a.handleEvent)}a.add(e,t,n,r,i),a.isEmpty()||this._toggleRecognizer(a.recognizerName,!0)}_removeEventHandler(e,t){if("string"!=typeof e){for(const[t,n]of Object.entries(e))this._removeEventHandler(t,n);return}const{events:n}=this,r=n.get(e);if(r&&(r.remove(e,t),r.isEmpty())){const{recognizerName:e}=r;let t=!1;for(const r of n.values())if(r.recognizerName===e&&!r.isEmpty()){t=!0;break}t||this._toggleRecognizer(e,!1)}}_getRecognizerName(e){var t;return null==(t=this.manager.recognizers.find(t=>t.getEventNames().includes(e)))?void 0:t.options.event}}const Bl={DEFAULT:-1,LNGLAT:1,METER_OFFSETS:2,LNGLAT_OFFSETS:3,CARTESIAN:0};Object.defineProperty(Bl,"IDENTITY",{get:()=>(Gn.deprecated("COORDINATE_SYSTEM.IDENTITY","COORDINATE_SYSTEM.CARTESIAN")(),0)});const Dl={WEB_MERCATOR:1,GLOBE:2,WEB_MERCATOR_AUTO_OFFSET:4,IDENTITY:0},Ol={common:0,meters:1,pixels:2},Fl={click:"onClick",dblclick:"onClick",panstart:"onDragStart",panmove:"onDrag",panend:"onDragEnd"},Ul={multipan:[ml,{threshold:10,direction:FA.Vertical,pointers:2}],pinch:[class extends fl{constructor(e={}){super({enable:!0,event:"pinch",threshold:0,pointers:2,...e})}getTouchAction(){return[VA]}getEventNames(){return _l.map(e=>this.options.event+e)}attrTest(e){return super.attrTest(e)&&(Math.abs(e.scale-1)>this.options.threshold||Boolean(this.state&jA.Began))}emit(e){if(1!==e.scale){const t=e.scale<1?"in":"out";e.additionalEvent=this.options.event+t}super.emit(e)}},{},null,["multipan"]],pan:[ml,{threshold:1},["pinch"],["multipan"]],dblclick:[pl,{event:"dblclick",taps:2}],click:[pl,{event:"click"},null,["dblclick"]]};function jl(e,t){if(e===t)return!0;if(Array.isArray(e)){const n=e.length;if(!t||t.length!==n)return!1;for(let r=0;r{for(const i in r)if(!jl(r[i],n[i])){t=e(r),n=r;break}return t}}const zl=[0,0,0,0],Vl=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0],Wl=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],Hl=[0,0,0],$l=[0,0,0],Xl=Gl(function({viewport:e,devicePixelRatio:t,coordinateSystem:n,coordinateOrigin:r}){const{projectionCenter:i,viewProjectionMatrix:s,originCommon:o,cameraPosCommon:a,shaderCoordinateOrigin:A,geospatialOrigin:l}=function(e,t,n){const{viewMatrixUncentered:r,projectionMatrix:i}=e;let{viewMatrix:s,viewProjectionMatrix:o}=e,a=zl,A=zl,l=e.cameraPosition;const{geospatialOrigin:c,shaderCoordinateOrigin:u,offsetMode:h}=Ql(e,t,n);return h&&(A=e.projectPosition(c||u),l=[l[0]-A[0],l[1]-A[1],l[2]-A[2]],A[3]=1,a=sA([],A,o),s=r||s,o=Ja([],i,s),o=Ja([],o,Vl)),{viewMatrix:s,viewProjectionMatrix:o,projectionCenter:a,originCommon:A,cameraPosCommon:l,shaderCoordinateOrigin:u,geospatialOrigin:c}}(e,n,r),c=e.getDistanceScales(),u=[e.width*t,e.height*t],h=sA([],[0,0,-e.focalDistance,1],e.projectionMatrix)[3]||1,d={coordinateSystem:n,projectionMode:e.projectionMode,coordinateOrigin:A,commonOrigin:o.slice(0,3),center:i,pseudoMeters:Boolean(e._pseudoMeters),viewportSize:u,devicePixelRatio:t,focalDistance:h,commonUnitsPerMeter:c.unitsPerMeter,commonUnitsPerWorldUnit:c.unitsPerMeter,commonUnitsPerWorldUnit2:Hl,scale:e.scale,wrapLongitude:!1,viewProjectionMatrix:s,modelMatrix:Wl,cameraPosition:a};if(l){const t=e.getDistanceScales(l);switch(n){case Bl.METER_OFFSETS:d.commonUnitsPerWorldUnit=t.unitsPerMeter,d.commonUnitsPerWorldUnit2=t.unitsPerMeter2;break;case Bl.LNGLAT:case Bl.LNGLAT_OFFSETS:e._pseudoMeters||(d.commonUnitsPerMeter=t.unitsPerMeter),d.commonUnitsPerWorldUnit=t.unitsPerDegree,d.commonUnitsPerWorldUnit2=t.unitsPerDegree2;break;case Bl.CARTESIAN:d.commonUnitsPerWorldUnit=[1,1,t.unitsPerMeter[2]],d.commonUnitsPerWorldUnit2=[0,0,t.unitsPerMeter2[2]]}}return d});function Ql(e,t,n=$l){n.length<3&&(n=[n[0],n[1],0]);let r,i=n,s=!0;switch(r=t===Bl.LNGLAT_OFFSETS||t===Bl.METER_OFFSETS?n:e.isGeospatial?[Math.fround(e.longitude),Math.fround(e.latitude),0]:null,e.projectionMode){case Dl.WEB_MERCATOR:t!==Bl.LNGLAT&&t!==Bl.CARTESIAN||(r=[0,0,0],s=!1);break;case Dl.WEB_MERCATOR_AUTO_OFFSET:t===Bl.LNGLAT?i=r:t===Bl.CARTESIAN&&(i=[Math.fround(e.center[0]),Math.fround(e.center[1]),0],r=e.unprojectPosition(i),i[0]-=n[0],i[1]-=n[1],i[2]-=n[2]);break;case Dl.IDENTITY:i=e.position.map(Math.fround),i[2]=i[2]||0;break;case Dl.GLOBE:s=!1,r=null;break;default:s=!1}return{geospatialOrigin:r,shaderCoordinateOrigin:i,offsetMode:s}}const Yl=`${Object.keys(Bl).map(e=>`const COORDINATE_SYSTEM_${e}: i32 = ${Bl[e]};`).join("")}\n${Object.keys(Dl).map(e=>`const PROJECTION_MODE_${e}: i32 = ${Dl[e]};`).join("")}\n${Object.keys(Ol).map(e=>`const UNIT_${e.toUpperCase()}: i32 = ${Ol[e]};`).join("")}\n\nconst TILE_SIZE: f32 = 512.0;\nconst PI: f32 = 3.1415926536;\nconst WORLD_SCALE: f32 = TILE_SIZE / (PI * 2.0);\nconst ZERO_64_LOW: vec3 = vec3(0.0, 0.0, 0.0);\nconst EARTH_RADIUS: f32 = 6370972.0; // meters\nconst GLOBE_RADIUS: f32 = 256.0;\n\n// -----------------------------------------------------------------------------\n// Uniform block (converted from GLSL uniform block)\n// -----------------------------------------------------------------------------\nstruct ProjectUniforms {\n wrapLongitude: i32,\n coordinateSystem: i32,\n commonUnitsPerMeter: vec3,\n projectionMode: i32,\n scale: f32,\n commonUnitsPerWorldUnit: vec3,\n commonUnitsPerWorldUnit2: vec3,\n center: vec4,\n modelMatrix: mat4x4,\n viewProjectionMatrix: mat4x4,\n viewportSize: vec2,\n devicePixelRatio: f32,\n focalDistance: f32,\n cameraPosition: vec3,\n coordinateOrigin: vec3,\n commonOrigin: vec3,\n pseudoMeters: i32,\n};\n\n@group(0) @binding(0)\nvar project: ProjectUniforms;\n\n// -----------------------------------------------------------------------------\n// Geometry data\n// (In your GLSL code, "geometry" was assumed to be available globally. In WGSL,\n// you might supply this via vertex attributes or a uniform. Here we define a\n// uniform struct for demonstration.)\n// -----------------------------------------------------------------------------\n\n// Structure to carry additional geometry data used by deck.gl filters.\nstruct Geometry {\n worldPosition: vec3,\n worldPositionAlt: vec3,\n position: vec4,\n normal: vec3,\n uv: vec2,\n pickingColor: vec3,\n};\n\n// @group(0) @binding(1)\nvar geometry: Geometry;\n\n\n// -----------------------------------------------------------------------------\n// Functions\n// -----------------------------------------------------------------------------\n\n// Returns an adjustment factor for commonUnitsPerMeter\nfn _project_size_at_latitude(lat: f32) -> f32 {\n let y = clamp(lat, -89.9, 89.9);\n return 1.0 / cos(radians(y));\n}\n\n// Overloaded version: scales a value in meters at a given latitude.\nfn _project_size_at_latitude_m(meters: f32, lat: f32) -> f32 {\n return meters * project.commonUnitsPerMeter.z * _project_size_at_latitude(lat);\n}\n\n// Computes a non-linear scale factor based on geometry.\n// (Note: This function relies on "geometry" being provided.)\nfn project_size() -> f32 {\n if (project.projectionMode == PROJECTION_MODE_WEB_MERCATOR &&\n project.coordinateSystem == COORDINATE_SYSTEM_LNGLAT &&\n project.pseudoMeters == 0) {\n if (geometry.position.w == 0.0) {\n return _project_size_at_latitude(geometry.worldPosition.y);\n }\n let y: f32 = geometry.position.y / TILE_SIZE * 2.0 - 1.0;\n let y2 = y * y;\n let y4 = y2 * y2;\n let y6 = y4 * y2;\n return 1.0 + 4.9348 * y2 + 4.0587 * y4 + 1.5642 * y6;\n }\n return 1.0;\n}\n\n// Overloads to scale offsets (meters to world units)\nfn project_size_float(meters: f32) -> f32 {\n return meters * project.commonUnitsPerMeter.z * project_size();\n}\n\nfn project_size_vec2(meters: vec2) -> vec2 {\n return meters * project.commonUnitsPerMeter.xy * project_size();\n}\n\nfn project_size_vec3(meters: vec3) -> vec3 {\n return meters * project.commonUnitsPerMeter * project_size();\n}\n\nfn project_size_vec4(meters: vec4) -> vec4 {\n return vec4(meters.xyz * project.commonUnitsPerMeter, meters.w);\n}\n\n// Returns a rotation matrix aligning the z‑axis with the given up vector.\nfn project_get_orientation_matrix(up: vec3) -> mat3x3 {\n let uz = normalize(up);\n let ux = select(\n vec3(1.0, 0.0, 0.0),\n normalize(vec3(uz.y, -uz.x, 0.0)),\n abs(uz.z) == 1.0\n );\n let uy = cross(uz, ux);\n return mat3x3(ux, uy, uz);\n}\n\n// Since WGSL does not support "out" parameters, we return a struct.\nstruct RotationResult {\n needsRotation: bool,\n transform: mat3x3,\n};\n\nfn project_needs_rotation(commonPosition: vec3) -> RotationResult {\n if (project.projectionMode == PROJECTION_MODE_GLOBE) {\n return RotationResult(true, project_get_orientation_matrix(commonPosition));\n } else {\n return RotationResult(false, mat3x3()); // identity alternative if needed\n };\n}\n\n// Projects a normal vector from the current coordinate system to world space.\nfn project_normal(vector: vec3) -> vec3 {\n let normal_modelspace = project.modelMatrix * vec4(vector, 0.0);\n var n = normalize(normal_modelspace.xyz * project.commonUnitsPerMeter);\n let rotResult = project_needs_rotation(geometry.position.xyz);\n if (rotResult.needsRotation) {\n n = rotResult.transform * n;\n }\n return n;\n}\n\n// Applies a scale offset based on y-offset (dy)\nfn project_offset_(offset: vec4) -> vec4 {\n let dy: f32 = offset.y;\n let commonUnitsPerWorldUnit = project.commonUnitsPerWorldUnit + project.commonUnitsPerWorldUnit2 * dy;\n return vec4(offset.xyz * commonUnitsPerWorldUnit, offset.w);\n}\n\n// Projects lng/lat coordinates to a unit tile [0,1]\nfn project_mercator_(lnglat: vec2) -> vec2 {\n var x = lnglat.x;\n if (project.wrapLongitude != 0) {\n x = ((x + 180.0) % 360.0) - 180.0;\n }\n let y = clamp(lnglat.y, -89.9, 89.9);\n return vec2(\n radians(x) + PI,\n PI + log(tan(PI * 0.25 + radians(y) * 0.5))\n ) * WORLD_SCALE;\n}\n\n// Projects lng/lat/z coordinates for a globe projection.\nfn project_globe_(lnglatz: vec3) -> vec3 {\n let lambda = radians(lnglatz.x);\n let phi = radians(lnglatz.y);\n let cosPhi = cos(phi);\n let D = (lnglatz.z / EARTH_RADIUS + 1.0) * GLOBE_RADIUS;\n return vec3(\n sin(lambda) * cosPhi,\n -cos(lambda) * cosPhi,\n sin(phi)\n ) * D;\n}\n\n// Projects positions (with an optional 64-bit low part) from the input\n// coordinate system to the common space.\nfn project_position_vec4_f64(position: vec4, position64Low: vec3) -> vec4 {\n var position_world = project.modelMatrix * position;\n\n // Work around for a Mac+NVIDIA bug:\n if (project.projectionMode == PROJECTION_MODE_WEB_MERCATOR) {\n if (project.coordinateSystem == COORDINATE_SYSTEM_LNGLAT) {\n return vec4(\n project_mercator_(position_world.xy),\n _project_size_at_latitude_m(position_world.z, position_world.y),\n position_world.w\n );\n }\n if (project.coordinateSystem == COORDINATE_SYSTEM_CARTESIAN) {\n position_world = vec4f(position_world.xyz + project.coordinateOrigin, position_world.w);\n }\n }\n if (project.projectionMode == PROJECTION_MODE_GLOBE) {\n if (project.coordinateSystem == COORDINATE_SYSTEM_LNGLAT) {\n return vec4(\n project_globe_(position_world.xyz),\n position_world.w\n );\n }\n }\n if (project.projectionMode == PROJECTION_MODE_WEB_MERCATOR_AUTO_OFFSET) {\n if (project.coordinateSystem == COORDINATE_SYSTEM_LNGLAT) {\n if (abs(position_world.y - project.coordinateOrigin.y) > 0.25) {\n return vec4(\n project_mercator_(position_world.xy) - project.commonOrigin.xy,\n project_size_float(position_world.z),\n position_world.w\n );\n }\n }\n }\n if (project.projectionMode == PROJECTION_MODE_IDENTITY ||\n (project.projectionMode == PROJECTION_MODE_WEB_MERCATOR_AUTO_OFFSET &&\n (project.coordinateSystem == COORDINATE_SYSTEM_LNGLAT ||\n project.coordinateSystem == COORDINATE_SYSTEM_CARTESIAN))) {\n position_world = vec4f(position_world.xyz - project.coordinateOrigin, position_world.w);\n }\n\n return project_offset_(position_world) +\n project_offset_(project.modelMatrix * vec4(position64Low, 0.0));\n}\n\n// Overloaded versions for different input types.\nfn project_position_vec4_f32(position: vec4) -> vec4 {\n return project_position_vec4_f64(position, ZERO_64_LOW);\n}\n\nfn project_position_vec3_f64(position: vec3, position64Low: vec3) -> vec3 {\n let projected_position = project_position_vec4_f64(vec4(position, 1.0), position64Low);\n return projected_position.xyz;\n}\n\nfn project_position_vec3_f32(position: vec3) -> vec3 {\n let projected_position = project_position_vec4_f64(vec4(position, 1.0), ZERO_64_LOW);\n return projected_position.xyz;\n}\n\nfn project_position_vec2_f32(position: vec2) -> vec2 {\n let projected_position = project_position_vec4_f64(vec4(position, 0.0, 1.0), ZERO_64_LOW);\n return projected_position.xy;\n}\n\n// Transforms a common space position to clip space.\nfn project_common_position_to_clipspace_with_projection(position: vec4, viewProjectionMatrix: mat4x4, center: vec4