e.order-t.order);for(const t of e)n+=` ${t.injection}\n`}i.footer&&(n+=` ${i.footer}`),n+="}\n"}return n}function vr(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 yr(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 wr(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 xr=`\n\n${sr}\n`;function Er(e,t){var n;const{source:r,stage:i,modules:s,hookFunctions:o=[],inject:a={},log:A}=t;Kn("string"==typeof r,"shader source must be a string");const l=r;let c="";const u=vr(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&&cr(g,l,A),c+=Cr(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+=xr,c=Ar(c,i,d),c+=br(u[i],h),c+=l,c=Ar(c,i,f),c}function Tr(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;Kn("string"==typeof r,"shader source must be a string");const h="glsl"===s?function(e){return{name:yr(e,void 0),language:"glsl",version:wr(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 _=vr(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&&cr(w,p,u),m+=Cr(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+=xr,m=Ar(m,i,v),m+=br(_[i],b),m+=p,m=Ar(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 mr(e,pr);case"fragment":return mr(e,gr);default:throw new Error(t)}}(m,i)),m.trim()}function Sr(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 Cr(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:Kn(!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 kr=/^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/,Rr=/^\s*\#\s*endif\s*$/,Pr=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=hr(e.modules||[]);return{source:Er(e.platformInfo,{...e,source:e.source,stage:"vertex",modules:t}),getUniforms:Sr(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(kr),t=s.match(Rr);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=hr(e.modules||[]);return{vs:Tr(e.platformInfo,{...e,source:t,stage:"vertex",modules:r}),fs:Tr(e.platformInfo,{...e,source:n,stage:"fragment",modules:r}),getUniforms:Sr(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 Vr(e){const[,,,,t]=Wr[e];return t}const Wr={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 Hr(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=jr(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 $r(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}`}}(zr(e),r,n)}const Xr="texture-compression-bc",Qr="texture-compression-astc",Yr="texture-compression-etc2",qr="texture-compression-pvrtc-webgl",Kr="texture-compression-atc-webgl",Zr="float32-renderable-webgl",Jr="float16-renderable-webgl",ei="snorm8-renderable-webgl",ti="norm16-renderable-webgl",ni="snorm16-renderable-webgl",ri="float32-filterable",ii="float16-filterable-webgl";function si(e){const t=oi[e];if(!t)throw new Error(`Unsupported texture format ${e}`);return t}const oi={r8unorm:{},rg8unorm:{},"rgb8unorm-webgl":{},rgba8unorm:{},"rgba8unorm-srgb":{},r8snorm:{render:ei},rg8snorm:{render:ei},"rgb8snorm-webgl":{},rgba8snorm:{render:ei},r8uint:{},rg8uint:{},rgba8uint:{},r8sint:{},rg8sint:{},rgba8sint:{},bgra8unorm:{},"bgra8unorm-srgb":{},r16unorm:{f:ti},rg16unorm:{render:ti},"rgb16unorm-webgl":{f:ti},rgba16unorm:{render:ti},r16snorm:{f:ni},rg16snorm:{render:ni},"rgb16snorm-webgl":{f:ti},rgba16snorm:{render:ni},r16uint:{},rg16uint:{},rgba16uint:{},r16sint:{},rg16sint:{},rgba16sint:{},r16float:{render:Jr,filter:"float16-filterable-webgl"},rg16float:{render:Jr,filter:ii},rgba16float:{render:Jr,filter:ii},r32uint:{},rg32uint:{},rgba32uint:{},r32sint:{},rg32sint:{},rgba32sint:{},r32float:{render:Zr,filter:ri},rg32float:{render:!1,filter:ri},"rgb32float-webgl":{render:Zr,filter:ri},rgba32float:{render:Zr,filter:ri},"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:Zr},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:Xr},"bc1-rgb-unorm-srgb-webgl":{f:Xr},"bc1-rgba-unorm":{f:Xr},"bc1-rgba-unorm-srgb":{f:Xr},"bc2-rgba-unorm":{f:Xr},"bc2-rgba-unorm-srgb":{f:Xr},"bc3-rgba-unorm":{f:Xr},"bc3-rgba-unorm-srgb":{f:Xr},"bc4-r-unorm":{f:Xr},"bc4-r-snorm":{f:Xr},"bc5-rg-unorm":{f:Xr},"bc5-rg-snorm":{f:Xr},"bc6h-rgb-ufloat":{f:Xr},"bc6h-rgb-float":{f:Xr},"bc7-rgba-unorm":{f:Xr},"bc7-rgba-unorm-srgb":{f:Xr},"etc2-rgb8unorm":{f:Yr},"etc2-rgb8unorm-srgb":{f:Yr},"etc2-rgb8a1unorm":{f:Yr},"etc2-rgb8a1unorm-srgb":{f:Yr},"etc2-rgba8unorm":{f:Yr},"etc2-rgba8unorm-srgb":{f:Yr},"eac-r11unorm":{f:Yr},"eac-r11snorm":{f:Yr},"eac-rg11unorm":{f:Yr},"eac-rg11snorm":{f:Yr},"astc-4x4-unorm":{f:Qr},"astc-4x4-unorm-srgb":{f:Qr},"astc-5x4-unorm":{f:Qr},"astc-5x4-unorm-srgb":{f:Qr},"astc-5x5-unorm":{f:Qr},"astc-5x5-unorm-srgb":{f:Qr},"astc-6x5-unorm":{f:Qr},"astc-6x5-unorm-srgb":{f:Qr},"astc-6x6-unorm":{f:Qr},"astc-6x6-unorm-srgb":{f:Qr},"astc-8x5-unorm":{f:Qr},"astc-8x5-unorm-srgb":{f:Qr},"astc-8x6-unorm":{f:Qr},"astc-8x6-unorm-srgb":{f:Qr},"astc-8x8-unorm":{f:Qr},"astc-8x8-unorm-srgb":{f:Qr},"astc-10x5-unorm":{f:Qr},"astc-10x5-unorm-srgb":{f:Qr},"astc-10x6-unorm":{f:Qr},"astc-10x6-unorm-srgb":{f:Qr},"astc-10x8-unorm":{f:Qr},"astc-10x8-unorm-srgb":{f:Qr},"astc-10x10-unorm":{f:Qr},"astc-10x10-unorm-srgb":{f:Qr},"astc-12x10-unorm":{f:Qr},"astc-12x10-unorm-srgb":{f:Qr},"astc-12x12-unorm":{f:Qr},"astc-12x12-unorm-srgb":{f:Qr},"pvrtc-rgb4unorm-webgl":{f:qr},"pvrtc-rgba4unorm-webgl":{f:qr},"pvrtc-rbg2unorm-webgl":{f:qr},"pvrtc-rgba2unorm-webgl":{f:qr},"etc1-rbg-unorm-webgl":{f:"texture-compression-etc1-webgl"},"atc-rgb-unorm-webgl":{f:Kr},"atc-rgba-unorm-webgl":{f:Kr},"atc-rgbai-unorm-webgl":{f:Kr}},ai=["bc1","bc2","bc3","bc4","bc5","bc6","bc7","etc1","etc2","eac","atc","astc","pvrtc"],Ai=/^(r|rg|rgb|rgba|bgra)([0-9]*)([a-z]*)(-srgb)?(-webgl)?$/,li=new class{getInfo(e){return ci(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 ai.some(t=>e.startsWith(t))}getCapabilities(e){const t=si(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=ci(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 ci(e){let t=function(e){var t;const n=si(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(li.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=Ai.exec(e);if(n){const[,r,i,s,o,a]=n,A=jr(`${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 ui{}class hi{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 di=class e{constructor(t){r(this,"id"),r(this,"props"),r(this,"userData",{}),r(this,"statsManager",Lr),r(this,"timestamp",0),r(this,"_reused",!1),r(this,"_lumaData",{}),r(this,"_textureCaps",{}),this.props={...e.defaultProps,...t},this.id=this.props.id||Dr(this[Symbol.toStringTag].toLowerCase())}get[Symbol.toStringTag](){return"Device"}toString(){return`Device(${this.id})`}getVertexFormatInfo(e){return Hr(e)}isVertexFormatSupported(e){return!0}getTextureFormatInfo(e){return li.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 li.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)?()=>{}:Nr.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.";Nr.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=li.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)&Ur.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(di,"defaultProps",{id:null,powerPreference:"high-performance",failIfMajorPerformanceCaveat:!1,createCanvasContext:void 0,webgl:{},onError:(e,t)=>{},onResize:(e,t)=>{const[n,r]=e.getDevicePixelSize();Nr.log(1,`${e} resized => ${n}x${r}px`)()},onPositionChange:(e,t)=>{const[n,r]=e.getPosition();Nr.log(1,`${e} repositioned => ${n},${r}`)()},onVisibilityChange:e=>Nr.log(1,`${e} Visibility changed ${e.isVisible}`)(),onDevicePixelRatioChange:(e,t)=>Nr.log(1,`${e} DPR changed ${t.oldRatio} => ${e.devicePixelRatio}`)(),debug:Nr.get("debug")||void 0,debugShaders:Nr.get("debug-shaders")||void 0,debugFramebuffers:Boolean(Nr.get("debug-framebuffers")),debugFactories:Boolean(Nr.get("debug-factories")),debugWebGL:Boolean(Nr.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 fi=di;const pi="No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.",gi=class e{constructor(){if(r(this,"stats",Lr),r(this,"log",Nr),r(this,"VERSION","9.2.5"),r(this,"spector"),r(this,"preregisteredAdapters",new Map),globalThis.luma){if(globalThis.luma.VERSION!==this.VERSION)throw Nr.error(`Found luma.gl ${globalThis.luma.VERSION} while initialzing ${this.VERSION}`)(),Nr.error("'yarn why @luma.gl/core' can help identify the source of the conflict")(),new Error("luma.gl - multiple versions detected: see console log");Nr.error("This version of luma.gl has already been initialized")()}Nr.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(pi);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(pi);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||Nr.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?Nr.warn("WebGL1 is not supported",e)():Nr.warn("Unknown handle type",e)(),null)}};r(gi,"defaultProps",{...fi.defaultProps,type:"best-available",adapters:void 0,waitForPageLoad:!0});const mi=new gi;class _i{get pageLoaded(){return yi||(yi=vi()||"undefined"==typeof window?Promise.resolve():new Promise(e=>window.addEventListener("load",()=>e()))),yi}}const bi=Ve()&&"undefined"!=typeof document,vi=()=>bi&&"complete"===document.readyState;let yi=null;const wi=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,Ve()?t.canvas?"string"==typeof t.canvas?this.canvas=function(e){const t=document.getElementById(e);if(!xi.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=Dr("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=Ei(s[0],t,n);let a=Ti(s[1],t,r,i),A=Ei(s[0]+1,t,n);const l=A===n-1?A:A-1;let c;return A=Ti(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(wi,"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 xi=wi;function Ei(e,t,n){return Math.min(Math.round(e*t),n-1)}function Ti(e,t,n,r){return r?Math.max(0,n-1-Math.round(e*t)):Math.min(Math.round(e*t),n-1)}const Si=class e extends Or{get[Symbol.toStringTag](){return"Sampler"}constructor(t,n){super(t,n=e.normalizeProps(t,n),e.defaultProps)}static normalizeProps(e,t){return t}};r(Si,"defaultProps",{...Or.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 Ci=Si;const ki={"1d":"1d","2d":"2d","2d-array":"2d",cube:"2d","cube-array":"2d","3d":"3d"},Ri=class e extends Or{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=ki[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||Nr.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 Ci?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(Ri,"SAMPLE",4),r(Ri,"STORAGE",8),r(Ri,"RENDER",16),r(Ri,"COPY_SRC",1),r(Ri,"COPY_DST",2),r(Ri,"TEXTURE",4),r(Ri,"RENDER_ATTACHMENT",16),r(Ri,"defaultProps",{...Or.defaultProps,data:null,dimension:"2d",format:"rgba8unorm",usage:Ri.TEXTURE|Ri.RENDER_ATTACHMENT|Ri.COPY_DST,width:void 0,height:void 0,depth:1,mipLevels:1,samples:void 0,sampler:{},view:void 0}),r(Ri,"defaultCopyDataOptions",{data:void 0,byteOffset:0,bytesPerRow:void 0,rowsPerImage:void 0,mipLevel:0,x:0,y:0,z:0,aspect:"all"}),r(Ri,"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 Pi=Ri;const Ii=class e extends Or{get[Symbol.toStringTag](){return"TextureView"}constructor(t,n){super(t,n,e.defaultProps)}};r(Ii,"defaultProps",{...Or.defaultProps,format:void 0,dimension:void 0,aspect:"all",baseMipLevel:0,mipLevelCount:void 0,baseArrayLayer:0,arrayLayerCount:void 0});let Mi=Ii;function Li(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+=Ni(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 Ni(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 Bi=class e extends Or{constructor(t,n){super(t,{id:Oi(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+=Ni(i[e-1],e,n);s.length>t&&s[t].lineNum===e;){const e=s[t++];r+=Li(e,i,e.lineNum,{...n,inlineSource:!1})}for(;s.length>t;)r+=Li(s[t++],[],0,{...n,inlineSource:!1});return r;case"issues":case"no":for(const s of e)r+=Li(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(Bi,"defaultProps",{...Or.defaultProps,language:"auto",stage:void 0,source:"",sourceMap:null,entryPoint:"main",debugShaders:void 0});let Di=Bi;function Oi(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||Dr(`unnamed ${e.stage}-shader`)}const Fi=class e extends Or{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&&(Nr.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 Pi?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 Pi?e.view:e}createColorTexture(e,t){return this.device.createTexture({id:`${this.id}-color-attachment-${t}`,usage:Pi.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:Pi.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]},Ji={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 es(e,t){const n={};for(const r of e.attributes){const i=ts(e,t,r.name);i&&(n[r.name]=i)}return n}function ts(e,t,n){const r=function(e,t){const n=e.attributes.find(e=>e.name===t);return n||Nr.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)&&Nr.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+=Hr(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||(Nr.warn(`layout for attribute "${t}" not present in buffer layout`),null))}(t,n);if(!r)return null;const s=function(e){const[t,n]=Zi[e];return{primitiveType:t,components:n,byteLength:Ki[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=Hr(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 ns=class e extends Or{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=es(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(ns,"defaultProps",{...Or.defaultProps,shaderLayout:void 0,bufferLayout:[]});let rs=ns;const is=class e extends Or{get[Symbol.toStringTag](){return"TransformFeedback"}constructor(t,n){super(t,n,e.defaultProps)}};r(is,"defaultProps",{...Or.defaultProps,layout:void 0,buffers:{}});let ss=is;const os=class e extends Or{get[Symbol.toStringTag](){return"QuerySet"}constructor(t,n){super(t,n,e.defaultProps)}};r(os,"defaultProps",{...Or.defaultProps,type:void 0,count:void 0});let as,As=os;function ls(e){return(!as||as.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(!cs(n))return!1;if(cs(r)&&n.length===r.length)for(let i=0;i`}}class _s extends fs{constructor(e,t,n){super(e,n),this.format=t}get isPointer(){return!0}getTypeName(){return`&${this.format.getTypeName()}`}}class bs extends fs{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 vs,ys;(ys=vs||(vs={}))[ys.Uniform=0]="Uniform",ys[ys.Storage=1]="Storage",ys[ys.Texture=2]="Texture",ys[ys.Sampler=3]="Sampler",ys[ys.StorageTexture=4]="StorageTexture";class ws{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 xs{constructor(e,t){this.name=e,this.type=t}}class Es{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r,this.interpolation=null}}class Ts{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r}}class Ss{constructor(e,t,n,r){this.name=e,this.type=t,this.attributes=n,this.id=r}}class Cs{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n}}class ks{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 Rs{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}}function Ps(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 Is=new Float32Array(1),Ms=new Int32Array(Is.buffer),Ls=new Uint16Array(1);function Ns(e){Is[0]=e;const t=Ms[0],n=t>>31&1;let r=t>>23&255,i=8388607&t;if(255===r)return Ls[0]=n<<15|31744|(0!==i?512:0),Ls[0];if(0===r){if(0===i)return Ls[0]=n<<15,Ls[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),Ls[0]=n<<15|r<<10|i>>13,Ls[0]):(Ls[0]=n<<15,Ls[0])}return r=r-127+15,r>=31?(Ls[0]=n<<15|31744,Ls[0]):r<=0?r<-10?(Ls[0]=n<<15,Ls[0]):(i=(8388608|i)>>1-r,Ls[0]=n<<15|i>>13,Ls[0]):(i>>=13,Ls[0]=n<<15|r<<10|i,Ls[0])}const Bs=new Uint32Array(1),Ds=new Float32Array(Bs.buffer,0,1);function Os(e){const t=112+(e>>6&31)<<23|(63&e)<<17;return Bs[0]=t,Ds[0]}function Fs(e,t,n,r){const i=[0,0,0,0];for(let s=0;s{e.increment="++",e.decrement="--"})(to||(to={})),(e=>{e.parse=function(t){const n=t;if("parse"==n)throw new Error("Invalid value for IncrementOperator");return e[n]}})(to||(to={}));class so extends Hs{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=">>="})(no||(no={})),(no||(no={})).parse=function(e){const t=e;if("parse"==t)throw new Error("Invalid value for AssignOperator");return t};class oo extends Hs{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 ao extends Hs{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"call"}isBuiltin(){return Ws.has(this.name)}search(e){for(const t of this.args)t.search(e);e(this)}}class Ao extends Hs{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 lo extends Hs{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 co extends Hs{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 uo extends Hs{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 ho extends Hs{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}}class fo extends Hs{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}}class po extends Hs{constructor(e,t){super(),this.severity=e,this.rule=t}get astNodeType(){return"diagnostic"}}class go extends Hs{constructor(e,t){super(),this.name=e,this.type=t}get astNodeType(){return"alias"}}class mo extends Hs{constructor(){super()}get astNodeType(){return"discard"}}class _o extends Hs{constructor(){super(),this.condition=null,this.loopId=-1}get astNodeType(){return"break"}}class bo extends Hs{constructor(){super(),this.loopId=-1}get astNodeType(){return"continue"}}class vo extends Hs{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}}xo.vec2f=new xo("vec2",vo.f32,null),xo.vec3f=new xo("vec3",vo.f32,null),xo.vec4f=new xo("vec4",vo.f32,null),xo.vec2i=new xo("vec2",vo.i32,null),xo.vec3i=new xo("vec3",vo.i32,null),xo.vec4i=new xo("vec4",vo.i32,null),xo.vec2u=new xo("vec2",vo.u32,null),xo.vec3u=new xo("vec3",vo.u32,null),xo.vec4u=new xo("vec4",vo.u32,null),xo.vec2h=new xo("vec2",vo.f16,null),xo.vec3h=new xo("vec3",vo.f16,null),xo.vec4h=new xo("vec4",vo.f16,null),xo.vec2b=new xo("vec2",vo.bool,null),xo.vec3b=new xo("vec3",vo.bool,null),xo.vec4b=new xo("vec4",vo.bool,null),xo.mat2x2f=new xo("mat2x2",vo.f32,null),xo.mat2x3f=new xo("mat2x3",vo.f32,null),xo.mat2x4f=new xo("mat2x4",vo.f32,null),xo.mat3x2f=new xo("mat3x2",vo.f32,null),xo.mat3x3f=new xo("mat3x3",vo.f32,null),xo.mat3x4f=new xo("mat3x4",vo.f32,null),xo.mat4x2f=new xo("mat4x2",vo.f32,null),xo.mat4x3f=new xo("mat4x3",vo.f32,null),xo.mat4x4f=new xo("mat4x4",vo.f32,null),xo.mat2x2h=new xo("mat2x2",vo.f16,null),xo.mat2x3h=new xo("mat2x3",vo.f16,null),xo.mat2x4h=new xo("mat2x4",vo.f16,null),xo.mat3x2h=new xo("mat3x2",vo.f16,null),xo.mat3x3h=new xo("mat3x3",vo.f16,null),xo.mat3x4h=new xo("mat3x4",vo.f16,null),xo.mat4x2h=new xo("mat4x2",vo.f16,null),xo.mat4x3h=new xo("mat4x3",vo.f16,null),xo.mat4x4h=new xo("mat4x4",vo.f16,null),xo.mat2x2i=new xo("mat2x2",vo.i32,null),xo.mat2x3i=new xo("mat2x3",vo.i32,null),xo.mat2x4i=new xo("mat2x4",vo.i32,null),xo.mat3x2i=new xo("mat3x2",vo.i32,null),xo.mat3x3i=new xo("mat3x3",vo.i32,null),xo.mat3x4i=new xo("mat3x4",vo.i32,null),xo.mat4x2i=new xo("mat4x2",vo.i32,null),xo.mat4x3i=new xo("mat4x3",vo.i32,null),xo.mat4x4i=new xo("mat4x4",vo.i32,null),xo.mat2x2u=new xo("mat2x2",vo.u32,null),xo.mat2x3u=new xo("mat2x3",vo.u32,null),xo.mat2x4u=new xo("mat2x4",vo.u32,null),xo.mat3x2u=new xo("mat3x2",vo.u32,null),xo.mat3x3u=new xo("mat3x3",vo.u32,null),xo.mat3x4u=new xo("mat3x4",vo.u32,null),xo.mat4x2u=new xo("mat4x2",vo.u32,null),xo.mat4x3u=new xo("mat4x3",vo.u32,null),xo.mat4x4u=new xo("mat4x4",vo.u32,null);class Eo extends vo{constructor(e,t,n,r){super(e),this.storage=t,this.type=n,this.access=r}get astNodeType(){return"pointer"}}class To extends vo{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 So extends vo{constructor(e,t,n){super(e),this.format=t,this.access=n}get astNodeType(){return"sampler"}}class Co extends Gs{constructor(){super(),this.postfix=null}}class ko extends Co{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}constEvaluateString(){return this.value}}class Ro extends Co{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 Po extends Co{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 Ws.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 Io extends Co{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 Mo extends Co{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 Lo extends Co{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 qo}get isVector(){return this.value instanceof Zo||this.value instanceof Jo}get scalarValue(){return this.value instanceof qo?this.value.value:0}get vectorValue(){return this.value instanceof Zo||this.value instanceof Jo?this.value.data:new Float32Array(0)}}class No extends Co{constructor(e,t){super(),this.type=e,this.value=t}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}}class Bo extends Co{constructor(e){super(),this.index=e}search(e){this.index.search(e)}}class Do extends Co{constructor(){super()}}class Oo extends Do{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 Fo extends Do{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?vo.f32:"u32"===e.name||"u32"===t.name?vo.u32:vo.i32}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.left.search(e),this.right.search(e)}}class Uo extends Gs{constructor(e){super(),this.body=e}search(e){e(this),this.searchBlock(this.body,e)}}class jo extends Co{constructor(){super()}get astNodeType(){return"default"}}class Go extends Uo{constructor(e,t){super(t),this.selectors=e}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}}class zo extends Uo{constructor(e){super(e)}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}}class Vo extends Gs{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"argument"}}class Wo extends Gs{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 Ho extends Gs{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"member"}}class $o extends Gs{constructor(e,t){super(),this.name=e,this.value=t}get astNodeType(){return"attribute"}}class Xo{constructor(e,t){this.parent=null,this.typeInfo=e,this.parent=t,this.id=Xo._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()}>`}}Xo._id=0;class Qo extends Xo{constructor(){super(new fs("void",null),null)}toString(){return"void"}}Qo.void=new Qo;class Yo extends Xo{constructor(e){super(new _s("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 qo extends Xo{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 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"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 qo))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 Ko(e,t,n){const r=t.length;return 2===r?"f32"===n?new Zo(new Float32Array(t),e.getTypeInfo("vec2f")):"i32"===n||"bool"===n?new Zo(new Int32Array(t),e.getTypeInfo("vec2i")):"u32"===n?new Zo(new Uint32Array(t),e.getTypeInfo("vec2u")):"f16"===n?new Zo(new Float32Array(t),e.getTypeInfo("vec2h")):null:3===r?"f32"===n?new Zo(new Float32Array(t),e.getTypeInfo("vec3f")):"i32"===n||"bool"===n?new Zo(new Int32Array(t),e.getTypeInfo("vec3i")):"u32"===n?new Zo(new Uint32Array(t),e.getTypeInfo("vec3u")):"f16"===n?new Zo(new Float32Array(t),e.getTypeInfo("vec3h")):null:4===r?"f32"===n?new Zo(new Float32Array(t),e.getTypeInfo("vec4f")):"i32"===n||"bool"===n?new Zo(new Int32Array(t),e.getTypeInfo("vec4i")):"u32"===n?new Zo(new Uint32Array(t),e.getTypeInfo("vec4u")):"f16"===n?new Zo(new Float32Array(t),e.getTypeInfo("vec4h")):null:null}class Zo extends Xo{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 Zo(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new Zo(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new Zo(new Uint32Array(this.data),this.typeInfo,null);throw"VectorData: Invalid data type"}setDataValue(e,t,n,r){n instanceof ko||t instanceof Zo&&(this.data=t.data)}getSubData(e,t,n){if(null===t)return this;let r=e.getTypeInfo("f32");if(this.typeInfo instanceof bs)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 Bo){const s=t.index;let o=-1;if(s instanceof Lo){if(!(s.value instanceof qo))return null;o=s.value.value}else{const t=e.evalExpression(s,n);if(!(t instanceof qo))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 qo(e,r)}if(i.data instanceof Int32Array){const e=new Int32Array(i.data.buffer,i.data.byteOffset+4*o,1);return new qo(e,r)}if(i.data instanceof Uint32Array){const e=new Uint32Array(i.data.buffer,i.data.byteOffset+4*o,1);return new qo(e,r)}throw"GetSubData: Invalid data type"}if(!(t instanceof ko))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 qo(t,r,this)}if(this.data instanceof Int32Array){let t=new Int32Array(this.data.buffer,this.data.byteOffset+4*e,1);return new qo(t,r,this)}if(this.data instanceof Uint32Array){let t=new Uint32Array(this.data.buffer,this.data.byteOffset+4*e,1);return new qo(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=Ko(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 Zo(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 Zo(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 Zo(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 Zo?(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 Zo?(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 Zo?(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 Zo?(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 Zo?(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 Zo?(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 Zo?(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 Zo?(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 Zo?(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 Zo?(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 Zo?(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 Zo?(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 Jo?(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 Jo?(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 Jo?(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 Jo?(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 Jo?(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 Jo?(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 Jo?(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 Jo?(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 Jo?(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 ea&&n===t.typeInfo)return void new Uint8Array(this.buffer,r,t.buffer.byteLength).set(new Uint8Array(t.buffer))}else t instanceof qo&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof qo&&(new Uint32Array(this.buffer,r,1)[0]=t.value);else t instanceof qo&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof qo&&(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 Bo){const r=t.index,i=r instanceof Co?e.evalExpression(r,n):r;let a=0;if(i instanceof qo?a=i.value:"number"==typeof i&&(a=i),o instanceof ms)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 ko))return null;{const n=t.value;if(o instanceof gs){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 fs){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 Zo(i,o,null)}return null}return null}}}t=t.postfix}const a=o.getTypeName();return"f32"===a?new qo(new Float32Array(this.buffer,s,1),o,this):"i32"===a?new qo(new Int32Array(this.buffer,s,1),o,this):"u32"===a?new qo(new Uint32Array(this.buffer,s,1),o,this):"vec2f"===a?new Zo(new Float32Array(this.buffer,s,2),o,this):"vec3f"===a?new Zo(new Float32Array(this.buffer,s,3),o,this):"vec4f"===a?new Zo(new Float32Array(this.buffer,s,4),o,this):"vec2i"===a?new Zo(new Int32Array(this.buffer,s,2),o,this):"vec3i"===a?new Zo(new Int32Array(this.buffer,s,3),o,this):"vec4i"===a?new Zo(new Int32Array(this.buffer,s,4),o,this):"vec2u"===a?new Zo(new Uint32Array(this.buffer,s,2),o,this):"vec3u"===a?new Zo(new Uint32Array(this.buffer,s,3),o,this):"vec4u"===a?new Zo(new Uint32Array(this.buffer,s,4),o,this):o instanceof bs&&"atomic"===o.name?"u32"===(null===(r=o.format)||void 0===r?void 0:r.name)?new qo(new Uint32Array(this.buffer,s,1)[0],o.format,this):"i32"===(null===(i=o.format)||void 0===i?void 0:i.name)?new qo(new Int32Array(this.buffer,s,1)[0],o.format,this):null:new ea(this.buffer,o,s,this)}toString(){let e="";if(this.typeInfo instanceof ms)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=js[e];return t?t.isDepthStencil?4:t.bytesPerBlock:0}get bytesPerRow(){return this.width*this.texelByteSize}get isDepthStencil(){const e=this.format,t=js[e];return!!t&&t.isDepthStencil}getGpuSize(){const e=this.format,t=js[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[Fs(e,l,"8unorm",1)[0]];case"r8snorm":return[Fs(e,l,"8snorm",1)[0]];case"r8uint":return[Fs(e,l,"8uint",1)[0]];case"r8sint":return[Fs(e,l,"8sint",1)[0]];case"rg8unorm":{const t=Fs(e,l,"8unorm",2);return[t[0],t[1]]}case"rg8snorm":{const t=Fs(e,l,"8snorm",2);return[t[0],t[1]]}case"rg8uint":{const t=Fs(e,l,"8uint",2);return[t[0],t[1]]}case"rg8sint":{const t=Fs(e,l,"8sint",2);return[t[0],t[1]]}case"rgba8unorm-srgb":case"rgba8unorm":{const t=Fs(e,l,"8unorm",4);return[t[0],t[1],t[2],t[3]]}case"rgba8snorm":{const t=Fs(e,l,"8snorm",4);return[t[0],t[1],t[2],t[3]]}case"rgba8uint":{const t=Fs(e,l,"8uint",4);return[t[0],t[1],t[2],t[3]]}case"rgba8sint":{const t=Fs(e,l,"8sint",4);return[t[0],t[1],t[2],t[3]]}case"bgra8unorm-srgb":case"bgra8unorm":{const t=Fs(e,l,"8unorm",4);return[t[2],t[1],t[0],t[3]]}case"r16uint":return[Fs(e,l,"16uint",1)[0]];case"r16sint":return[Fs(e,l,"16sint",1)[0]];case"r16float":return[Fs(e,l,"16float",1)[0]];case"rg16uint":{const t=Fs(e,l,"16uint",2);return[t[0],t[1]]}case"rg16sint":{const t=Fs(e,l,"16sint",2);return[t[0],t[1]]}case"rg16float":{const t=Fs(e,l,"16float",2);return[t[0],t[1]]}case"rgba16uint":{const t=Fs(e,l,"16uint",4);return[t[0],t[1],t[2],t[3]]}case"rgba16sint":{const t=Fs(e,l,"16sint",4);return[t[0],t[1],t[2],t[3]]}case"rgba16float":{const t=Fs(e,l,"16float",4);return[t[0],t[1],t[2],t[3]]}case"r32uint":return[Fs(e,l,"32uint",1)[0]];case"r32sint":return[Fs(e,l,"32sint",1)[0]];case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return[Fs(e,l,"32float",1)[0]];case"rg32uint":{const t=Fs(e,l,"32uint",2);return[t[0],t[1]]}case"rg32sint":{const t=Fs(e,l,"32sint",2);return[t[0],t[1]]}case"rg32float":{const t=Fs(e,l,"32float",2);return[t[0],t[1]]}case"rgba32uint":{const t=Fs(e,l,"32uint",4);return[t[0],t[1],t[2],t[3]]}case"rgba32sint":{const t=Fs(e,l,"32sint",4);return[t[0],t[1],t[2],t[3]]}case"rgba32float":{const t=Fs(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[Os(2047&t),Os(n),function(e){const t=112+(e>>5&31)<<23|(31&e)<<18;return Bs[0]=t,Ds[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 Us(e,c,"8unorm",1,l);case"r8snorm":return void Us(e,c,"8snorm",1,l);case"r8uint":return void Us(e,c,"8uint",1,l);case"r8sint":return void Us(e,c,"8sint",1,l);case"rg8unorm":return void Us(e,c,"8unorm",2,l);case"rg8snorm":return void Us(e,c,"8snorm",2,l);case"rg8uint":return void Us(e,c,"8uint",2,l);case"rg8sint":return void Us(e,c,"8sint",2,l);case"rgba8unorm-srgb":case"rgba8unorm":case"bgra8unorm-srgb":case"bgra8unorm":return void Us(e,c,"8unorm",4,l);case"rgba8snorm":return void Us(e,c,"8snorm",4,l);case"rgba8uint":return void Us(e,c,"8uint",4,l);case"rgba8sint":return void Us(e,c,"8sint",4,l);case"r16uint":return void Us(e,c,"16uint",1,l);case"r16sint":return void Us(e,c,"16sint",1,l);case"r16float":return void Us(e,c,"16float",1,l);case"rg16uint":return void Us(e,c,"16uint",2,l);case"rg16sint":return void Us(e,c,"16sint",2,l);case"rg16float":return void Us(e,c,"16float",2,l);case"rgba16uint":return void Us(e,c,"16uint",4,l);case"rgba16sint":return void Us(e,c,"16sint",4,l);case"rgba16float":return void Us(e,c,"16float",4,l);case"r32uint":return void Us(e,c,"32uint",1,l);case"r32sint":return void Us(e,c,"32sint",1,l);case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return void Us(e,c,"32float",1,l);case"rg32uint":return void Us(e,c,"32uint",2,l);case"rg32sint":return void Us(e,c,"32sint",2,l);case"rg32float":return void Us(e,c,"32float",2,l);case"rgba32uint":return void Us(e,c,"32uint",4,l);case"rgba32sint":return void Us(e,c,"32sint",4,l);case"rgba32float":Us(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"})(io||(io={}));class na{constructor(e,t,n){this.name=e,this.type=t,this.rule=n}toString(){return this.name}}class ra{}ro=ra,ra.none=new na("",io.reserved,""),ra.eof=new na("EOF",io.token,""),ra.reserved={asm:new na("asm",io.reserved,"asm"),bf16:new na("bf16",io.reserved,"bf16"),do:new na("do",io.reserved,"do"),enum:new na("enum",io.reserved,"enum"),f16:new na("f16",io.reserved,"f16"),f64:new na("f64",io.reserved,"f64"),handle:new na("handle",io.reserved,"handle"),i8:new na("i8",io.reserved,"i8"),i16:new na("i16",io.reserved,"i16"),i64:new na("i64",io.reserved,"i64"),mat:new na("mat",io.reserved,"mat"),premerge:new na("premerge",io.reserved,"premerge"),regardless:new na("regardless",io.reserved,"regardless"),typedef:new na("typedef",io.reserved,"typedef"),u8:new na("u8",io.reserved,"u8"),u16:new na("u16",io.reserved,"u16"),u64:new na("u64",io.reserved,"u64"),unless:new na("unless",io.reserved,"unless"),using:new na("using",io.reserved,"using"),vec:new na("vec",io.reserved,"vec"),void:new na("void",io.reserved,"void")},ra.keywords={array:new na("array",io.keyword,"array"),atomic:new na("atomic",io.keyword,"atomic"),bool:new na("bool",io.keyword,"bool"),f32:new na("f32",io.keyword,"f32"),i32:new na("i32",io.keyword,"i32"),mat2x2:new na("mat2x2",io.keyword,"mat2x2"),mat2x3:new na("mat2x3",io.keyword,"mat2x3"),mat2x4:new na("mat2x4",io.keyword,"mat2x4"),mat3x2:new na("mat3x2",io.keyword,"mat3x2"),mat3x3:new na("mat3x3",io.keyword,"mat3x3"),mat3x4:new na("mat3x4",io.keyword,"mat3x4"),mat4x2:new na("mat4x2",io.keyword,"mat4x2"),mat4x3:new na("mat4x3",io.keyword,"mat4x3"),mat4x4:new na("mat4x4",io.keyword,"mat4x4"),ptr:new na("ptr",io.keyword,"ptr"),sampler:new na("sampler",io.keyword,"sampler"),sampler_comparison:new na("sampler_comparison",io.keyword,"sampler_comparison"),struct:new na("struct",io.keyword,"struct"),texture_1d:new na("texture_1d",io.keyword,"texture_1d"),texture_2d:new na("texture_2d",io.keyword,"texture_2d"),texture_2d_array:new na("texture_2d_array",io.keyword,"texture_2d_array"),texture_3d:new na("texture_3d",io.keyword,"texture_3d"),texture_cube:new na("texture_cube",io.keyword,"texture_cube"),texture_cube_array:new na("texture_cube_array",io.keyword,"texture_cube_array"),texture_multisampled_2d:new na("texture_multisampled_2d",io.keyword,"texture_multisampled_2d"),texture_storage_1d:new na("texture_storage_1d",io.keyword,"texture_storage_1d"),texture_storage_2d:new na("texture_storage_2d",io.keyword,"texture_storage_2d"),texture_storage_2d_array:new na("texture_storage_2d_array",io.keyword,"texture_storage_2d_array"),texture_storage_3d:new na("texture_storage_3d",io.keyword,"texture_storage_3d"),texture_depth_2d:new na("texture_depth_2d",io.keyword,"texture_depth_2d"),texture_depth_2d_array:new na("texture_depth_2d_array",io.keyword,"texture_depth_2d_array"),texture_depth_cube:new na("texture_depth_cube",io.keyword,"texture_depth_cube"),texture_depth_cube_array:new na("texture_depth_cube_array",io.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new na("texture_depth_multisampled_2d",io.keyword,"texture_depth_multisampled_2d"),texture_external:new na("texture_external",io.keyword,"texture_external"),u32:new na("u32",io.keyword,"u32"),vec2:new na("vec2",io.keyword,"vec2"),vec3:new na("vec3",io.keyword,"vec3"),vec4:new na("vec4",io.keyword,"vec4"),bitcast:new na("bitcast",io.keyword,"bitcast"),block:new na("block",io.keyword,"block"),break:new na("break",io.keyword,"break"),case:new na("case",io.keyword,"case"),continue:new na("continue",io.keyword,"continue"),continuing:new na("continuing",io.keyword,"continuing"),default:new na("default",io.keyword,"default"),diagnostic:new na("diagnostic",io.keyword,"diagnostic"),discard:new na("discard",io.keyword,"discard"),else:new na("else",io.keyword,"else"),enable:new na("enable",io.keyword,"enable"),fallthrough:new na("fallthrough",io.keyword,"fallthrough"),false:new na("false",io.keyword,"false"),fn:new na("fn",io.keyword,"fn"),for:new na("for",io.keyword,"for"),function:new na("function",io.keyword,"function"),if:new na("if",io.keyword,"if"),let:new na("let",io.keyword,"let"),const:new na("const",io.keyword,"const"),loop:new na("loop",io.keyword,"loop"),while:new na("while",io.keyword,"while"),private:new na("private",io.keyword,"private"),read:new na("read",io.keyword,"read"),read_write:new na("read_write",io.keyword,"read_write"),return:new na("return",io.keyword,"return"),requires:new na("requires",io.keyword,"requires"),storage:new na("storage",io.keyword,"storage"),switch:new na("switch",io.keyword,"switch"),true:new na("true",io.keyword,"true"),alias:new na("alias",io.keyword,"alias"),type:new na("type",io.keyword,"type"),uniform:new na("uniform",io.keyword,"uniform"),var:new na("var",io.keyword,"var"),override:new na("override",io.keyword,"override"),workgroup:new na("workgroup",io.keyword,"workgroup"),write:new na("write",io.keyword,"write"),r8unorm:new na("r8unorm",io.keyword,"r8unorm"),r8snorm:new na("r8snorm",io.keyword,"r8snorm"),r8uint:new na("r8uint",io.keyword,"r8uint"),r8sint:new na("r8sint",io.keyword,"r8sint"),r16uint:new na("r16uint",io.keyword,"r16uint"),r16sint:new na("r16sint",io.keyword,"r16sint"),r16float:new na("r16float",io.keyword,"r16float"),rg8unorm:new na("rg8unorm",io.keyword,"rg8unorm"),rg8snorm:new na("rg8snorm",io.keyword,"rg8snorm"),rg8uint:new na("rg8uint",io.keyword,"rg8uint"),rg8sint:new na("rg8sint",io.keyword,"rg8sint"),r32uint:new na("r32uint",io.keyword,"r32uint"),r32sint:new na("r32sint",io.keyword,"r32sint"),r32float:new na("r32float",io.keyword,"r32float"),rg16uint:new na("rg16uint",io.keyword,"rg16uint"),rg16sint:new na("rg16sint",io.keyword,"rg16sint"),rg16float:new na("rg16float",io.keyword,"rg16float"),rgba8unorm:new na("rgba8unorm",io.keyword,"rgba8unorm"),rgba8unorm_srgb:new na("rgba8unorm_srgb",io.keyword,"rgba8unorm_srgb"),rgba8snorm:new na("rgba8snorm",io.keyword,"rgba8snorm"),rgba8uint:new na("rgba8uint",io.keyword,"rgba8uint"),rgba8sint:new na("rgba8sint",io.keyword,"rgba8sint"),bgra8unorm:new na("bgra8unorm",io.keyword,"bgra8unorm"),bgra8unorm_srgb:new na("bgra8unorm_srgb",io.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new na("rgb10a2unorm",io.keyword,"rgb10a2unorm"),rg11b10float:new na("rg11b10float",io.keyword,"rg11b10float"),rg32uint:new na("rg32uint",io.keyword,"rg32uint"),rg32sint:new na("rg32sint",io.keyword,"rg32sint"),rg32float:new na("rg32float",io.keyword,"rg32float"),rgba16uint:new na("rgba16uint",io.keyword,"rgba16uint"),rgba16sint:new na("rgba16sint",io.keyword,"rgba16sint"),rgba16float:new na("rgba16float",io.keyword,"rgba16float"),rgba32uint:new na("rgba32uint",io.keyword,"rgba32uint"),rgba32sint:new na("rgba32sint",io.keyword,"rgba32sint"),rgba32float:new na("rgba32float",io.keyword,"rgba32float"),static_assert:new na("static_assert",io.keyword,"static_assert")},ra.tokens={decimal_float_literal:new na("decimal_float_literal",io.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 na("hex_float_literal",io.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 na("int_literal",io.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new na("uint_literal",io.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),name:new na("name",io.token,/([_\p{XID_Start}][\p{XID_Continue}]+)|([\p{XID_Start}])/u),ident:new na("ident",io.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new na("and",io.token,"&"),and_and:new na("and_and",io.token,"&&"),arrow:new na("arrow ",io.token,"->"),attr:new na("attr",io.token,"@"),forward_slash:new na("forward_slash",io.token,"/"),bang:new na("bang",io.token,"!"),bracket_left:new na("bracket_left",io.token,"["),bracket_right:new na("bracket_right",io.token,"]"),brace_left:new na("brace_left",io.token,"{"),brace_right:new na("brace_right",io.token,"}"),colon:new na("colon",io.token,":"),comma:new na("comma",io.token,","),equal:new na("equal",io.token,"="),equal_equal:new na("equal_equal",io.token,"=="),not_equal:new na("not_equal",io.token,"!="),greater_than:new na("greater_than",io.token,">"),greater_than_equal:new na("greater_than_equal",io.token,">="),shift_right:new na("shift_right",io.token,">>"),less_than:new na("less_than",io.token,"<"),less_than_equal:new na("less_than_equal",io.token,"<="),shift_left:new na("shift_left",io.token,"<<"),modulo:new na("modulo",io.token,"%"),minus:new na("minus",io.token,"-"),minus_minus:new na("minus_minus",io.token,"--"),period:new na("period",io.token,"."),plus:new na("plus",io.token,"+"),plus_plus:new na("plus_plus",io.token,"++"),or:new na("or",io.token,"|"),or_or:new na("or_or",io.token,"||"),paren_left:new na("paren_left",io.token,"("),paren_right:new na("paren_right",io.token,")"),semicolon:new na("semicolon",io.token,";"),star:new na("star",io.token,"*"),tilde:new na("tilde",io.token,"~"),underscore:new na("underscore",io.token,"_"),xor:new na("xor",io.token,"^"),plus_equal:new na("plus_equal",io.token,"+="),minus_equal:new na("minus_equal",io.token,"-="),times_equal:new na("times_equal",io.token,"*="),division_equal:new na("division_equal",io.token,"/="),modulo_equal:new na("modulo_equal",io.token,"%="),and_equal:new na("and_equal",io.token,"&="),or_equal:new na("or_equal",io.token,"|="),xor_equal:new na("xor_equal",io.token,"^="),shift_right_equal:new na("shift_right_equal",io.token,">>="),shift_left_equal:new na("shift_left_equal",io.token,"<<=")},ra.simpleTokens={"@":ro.tokens.attr,"{":ro.tokens.brace_left,"}":ro.tokens.brace_right,":":ro.tokens.colon,",":ro.tokens.comma,"(":ro.tokens.paren_left,")":ro.tokens.paren_right,";":ro.tokens.semicolon},ra.literalTokens={"&":ro.tokens.and,"&&":ro.tokens.and_and,"->":ro.tokens.arrow,"/":ro.tokens.forward_slash,"!":ro.tokens.bang,"[":ro.tokens.bracket_left,"]":ro.tokens.bracket_right,"=":ro.tokens.equal,"==":ro.tokens.equal_equal,"!=":ro.tokens.not_equal,">":ro.tokens.greater_than,">=":ro.tokens.greater_than_equal,">>":ro.tokens.shift_right,"<":ro.tokens.less_than,"<=":ro.tokens.less_than_equal,"<<":ro.tokens.shift_left,"%":ro.tokens.modulo,"-":ro.tokens.minus,"--":ro.tokens.minus_minus,".":ro.tokens.period,"+":ro.tokens.plus,"++":ro.tokens.plus_plus,"|":ro.tokens.or,"||":ro.tokens.or_or,"*":ro.tokens.star,"~":ro.tokens.tilde,_:ro.tokens.underscore,"^":ro.tokens.xor,"+=":ro.tokens.plus_equal,"-=":ro.tokens.minus_equal,"*=":ro.tokens.times_equal,"/=":ro.tokens.division_equal,"%=":ro.tokens.modulo_equal,"&=":ro.tokens.and_equal,"|=":ro.tokens.or_equal,"^=":ro.tokens.xor_equal,">>=":ro.tokens.shift_right_equal,"<<=":ro.tokens.shift_left_equal},ra.regexTokens={decimal_float_literal:ro.tokens.decimal_float_literal,hex_float_literal:ro.tokens.hex_float_literal,int_literal:ro.tokens.int_literal,uint_literal:ro.tokens.uint_literal,ident:ro.tokens.ident},ra.storage_class=[ro.keywords.function,ro.keywords.private,ro.keywords.workgroup,ro.keywords.uniform,ro.keywords.storage],ra.access_mode=[ro.keywords.read,ro.keywords.write,ro.keywords.read_write],ra.sampler_type=[ro.keywords.sampler,ro.keywords.sampler_comparison],ra.sampled_texture_type=[ro.keywords.texture_1d,ro.keywords.texture_2d,ro.keywords.texture_2d_array,ro.keywords.texture_3d,ro.keywords.texture_cube,ro.keywords.texture_cube_array],ra.multisampled_texture_type=[ro.keywords.texture_multisampled_2d],ra.storage_texture_type=[ro.keywords.texture_storage_1d,ro.keywords.texture_storage_2d,ro.keywords.texture_storage_2d_array,ro.keywords.texture_storage_3d],ra.depth_texture_type=[ro.keywords.texture_depth_2d,ro.keywords.texture_depth_2d_array,ro.keywords.texture_depth_cube,ro.keywords.texture_depth_cube_array,ro.keywords.texture_depth_multisampled_2d],ra.texture_external_type=[ro.keywords.texture_external],ra.any_texture_type=[...ro.sampled_texture_type,...ro.multisampled_texture_type,...ro.storage_texture_type,...ro.depth_texture_type,...ro.texture_external_type],ra.texel_format=[ro.keywords.r8unorm,ro.keywords.r8snorm,ro.keywords.r8uint,ro.keywords.r8sint,ro.keywords.r16uint,ro.keywords.r16sint,ro.keywords.r16float,ro.keywords.rg8unorm,ro.keywords.rg8snorm,ro.keywords.rg8uint,ro.keywords.rg8sint,ro.keywords.r32uint,ro.keywords.r32sint,ro.keywords.r32float,ro.keywords.rg16uint,ro.keywords.rg16sint,ro.keywords.rg16float,ro.keywords.rgba8unorm,ro.keywords.rgba8unorm_srgb,ro.keywords.rgba8snorm,ro.keywords.rgba8uint,ro.keywords.rgba8sint,ro.keywords.bgra8unorm,ro.keywords.bgra8unorm_srgb,ro.keywords.rgb10a2unorm,ro.keywords.rg11b10float,ro.keywords.rg32uint,ro.keywords.rg32sint,ro.keywords.rg32float,ro.keywords.rgba16uint,ro.keywords.rgba16sint,ro.keywords.rgba16float,ro.keywords.rgba32uint,ro.keywords.rgba32sint,ro.keywords.rgba32float],ra.const_literal=[ro.tokens.int_literal,ro.tokens.uint_literal,ro.tokens.decimal_float_literal,ro.tokens.hex_float_literal,ro.keywords.true,ro.keywords.false],ra.literal_or_ident=[ro.tokens.ident,ro.tokens.int_literal,ro.tokens.uint_literal,ro.tokens.decimal_float_literal,ro.tokens.hex_float_literal,ro.tokens.name],ra.element_count_expression=[ro.tokens.int_literal,ro.tokens.uint_literal,ro.tokens.ident],ra.template_types=[ro.keywords.vec2,ro.keywords.vec3,ro.keywords.vec4,ro.keywords.mat2x2,ro.keywords.mat2x3,ro.keywords.mat2x4,ro.keywords.mat3x2,ro.keywords.mat3x3,ro.keywords.mat3x4,ro.keywords.mat4x2,ro.keywords.mat4x3,ro.keywords.mat4x4,ro.keywords.atomic,ro.keywords.bitcast,...ro.any_texture_type],ra.attribute_name=[ro.tokens.ident,ro.keywords.block,ro.keywords.diagnostic],ra.assignment_operators=[ro.tokens.equal,ro.tokens.plus_equal,ro.tokens.minus_equal,ro.tokens.times_equal,ro.tokens.division_equal,ro.tokens.modulo_equal,ro.tokens.and_equal,ro.tokens.or_equal,ro.tokens.xor_equal,ro.tokens.shift_right_equal,ro.tokens.shift_left_equal],ra.increment_operators=[ro.tokens.plus_plus,ro.tokens.minus_minus];class ia{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!=ra.template_types.indexOf(this.type)}isArrayType(){return this.type==ra.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}}class sa{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 ia(ra.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=ra.simpleTokens[e];if(t)return this._addToken(t),!0;let n=ra.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=ra.keywords[e];if(t)return this._addToken(t),!0}if(r||i)return this._addToken(ra.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(ra.tokens.minus_equal),!0;if("-"==r)return this._current++,e+=r,this._addToken(ra.tokens.minus_minus),!0;const n=this._tokens.length-1;if((-1!=ra.literal_or_ident.indexOf(this._tokens[n].type)||this._tokens[n].type==ra.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===ra.assignment_operators.indexOf(this._tokens[n].type);++t,--n)if(this._tokens[n].type===ra.tokens.less_than){n>0&&this._tokens[n-1].isArrayOrTemplateType()&&(e=!0);break}if(e)return this._addToken(t),!0}if(t===ra.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 ia(e,t,this._line,this._start,this._current))}}function oa(e){return Array.isArray(e)||(null==e?void 0:e.buffer)instanceof ArrayBuffer}const aa=new Float32Array(1),Aa=new Uint32Array(aa.buffer),la=new Uint32Array(aa.buffer),ca=new Int32Array(1),ua=new Float32Array(ca.buffer),ha=new Uint32Array(ca.buffer),da=new Uint32Array(1),fa=new Float32Array(da.buffer),pa=new Int32Array(da.buffer);function ga(e,t,n){if(t===n)return e;if("f32"===t){if("i32"===n||"x32"===n)return aa[0]=e,Aa[0];if("u32"===n)return aa[0]=e,la[0]}else if("i32"===t||"x32"===t){if("f32"===n)return ca[0]=e,ua[0];if("u32"===n)return ca[0]=e,ha[0]}else if("u32"===t){if("f32"===n)return da[0]=e,fa[0];if("i32"===n||"x32"===n)return da[0]=e,pa[0]}return e}class ma{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}}class _a{constructor(e,t){this.align=e,this.size=t}}class ba{constructor(){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new Rs,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 $s&&this._functions.set(t.name,new ma(t));for(const t of e)if(t instanceof wo){const e=this.getTypeInfo(t,null);e instanceof gs&&this.structs.push(e)}for(const t of e)if(t instanceof go)this.aliases.push(this._getAliasInfo(t));else{if(t instanceof Zs){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 Ss(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 ws(e.name,i,n,r,e.attributes,vs.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 ws(e.name,i,n,r,e.attributes,s?vs.StorageTexture:vs.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 ws(e.name,i,n,r,e.attributes,s?vs.StorageTexture:vs.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 ws(e.name,i,n,r,e.attributes,vs.Sampler,e.access);this.samplers.push(s);continue}}for(const t of e)if(t instanceof $s){const e=this._getAttribute(t,"vertex"),n=this._getAttribute(t,"fragment"),r=this._getAttribute(t,"compute"),i=e||n||r,s=new ks(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 Cs(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 $o){if(e.value)if(oa(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 Io)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 zs)i.push({});else if(s instanceof Vs)i.pop();else if(s instanceof Ks){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 Ro){const e=s;t&&null!==e.type&&this._markStructsFromAST(e.type)}else if(s instanceof Js){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 Io){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 Po){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 ao){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 wo)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 wo)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 Ts(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 Ts("",n,t.name,r)}return null}_getInputs(e,t=void 0){void 0===t&&(t=[]);for(const n of e)if(n.type instanceof wo)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 wo)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 Es(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 xs(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 Eo){const n=e.type?this.getTypeInfo(e.type,e.attributes):null,r=new _s(e.name,n,t);return this._types.set(e,r),this._updateTypeInfo(r),r}if(e instanceof To){const n=e,r=n.format?this.getTypeInfo(n.format,n.attributes):null,i=new ms(n.name,t);return i.format=r,i.count=n.count,this._types.set(e,i),this._updateTypeInfo(i),i}if(e instanceof wo){const n=e,r=new gs(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 ps(e.name,t,e.attributes))}return this._types.set(e,r),this._updateTypeInfo(r),r}if(e instanceof So){const n=e,r=n.format instanceof vo,i=n.format?r?this.getTypeInfo(n.format,null):new fs(n.format,null):null,s=new bs(n.name,i,t,n.access);return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof xo){const n=e,r=n.format?this.getTypeInfo(n.format,null):null,i=new bs(n.name,r,t,n.access);return this._types.set(e,i),this._updateTypeInfo(i),i}const n=new fs(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 ms&&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 _s&&this._updateTypeInfo(e.format),e instanceof gs&&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),ba._samplerTypes=ra.sampler_type.map(e=>e.name);let va=0;class ya{constructor(e,t,n){this.id=va++,this.name=e,this.value=t,this.node=n}clone(){return new ya(this.name,this.value,this.node)}}class wa{constructor(e){this.id=va++,this.name=e.name,this.node=e}clone(){return new wa(this.node)}}class xa{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName="",this.id=va++,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 ya(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 xa(this)}}class Ea{evalExpression(e,t){return null}getTypeInfo(e){return null}getVariableName(e,t){return""}}class Ta{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 Zo)return n.data.forEach(e=>{e||(r=!1)}),new qo(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 Zo){const e=n.data.some(e=>e);return new qo(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 qo))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 Oo&&(n=n.right);const r=this.exec.evalExpression(n,t);if(r instanceof ea&&0===r.typeInfo.size){const e=r.typeInfo,t=r.buffer.byteLength/e.stride;return new qo(t,this.getTypeInfo("u32"))}return new qo(r.typeInfo.size,this.getTypeInfo("u32"))}Abs(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.abs(e)),n.typeInfo);const r=n;return new qo(Math.abs(r.value),r.typeInfo)}Acos(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.acos(e)),n.typeInfo);const r=n;return new qo(Math.acos(r.value),n.typeInfo)}Acosh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.acosh(e)),n.typeInfo);const r=n;return new qo(Math.acosh(r.value),n.typeInfo)}Asin(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.asin(e)),n.typeInfo);const r=n;return new qo(Math.asin(r.value),n.typeInfo)}Asinh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.asinh(e)),n.typeInfo);const r=n;return new qo(Math.asinh(r.value),n.typeInfo)}Atan(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.atan(e)),n.typeInfo);const r=n;return new qo(Math.atan(r.value),n.typeInfo)}Atanh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.atanh(e)),n.typeInfo);const r=n;return new qo(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 Zo&&r instanceof Zo)return new Zo(n.data.map((e,t)=>Math.atan2(e,r.data[t])),n.typeInfo);const i=n,s=r;return new qo(Math.atan2(i.value,s.value),n.typeInfo)}Ceil(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.ceil(e)),n.typeInfo);const r=n;return new qo(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 Zo&&r instanceof Zo&&i instanceof Zo)return new Zo(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 qo(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 Zo)return new Zo(n.data.map(e=>Math.cos(e)),n.typeInfo);const r=n;return new qo(Math.cos(r.value),n.typeInfo)}Cosh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.cosh(e)),n.typeInfo);const r=n;return new qo(Math.cos(r.value),n.typeInfo)}CountLeadingZeros(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.clz32(e)),n.typeInfo);const r=n;return new qo(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 Zo)return new Zo(n.data.map(e=>this._countOneBits(e)),n.typeInfo);const r=n;return new qo(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 Zo)return new Zo(n.data.map(e=>this._countTrailingZeros(e)),n.typeInfo);const r=n;return new qo(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 Zo&&r instanceof Zo){if(3!==n.data.length||3!==r.data.length)return null;const e=n.data,t=r.data;return new Zo([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 Zo?new Zo(n.data.map(e=>e*r),n.typeInfo):new qo(n.value*r,this.getTypeInfo("f32"))}Determinant(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Jo){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 qo(e[0]*e[3]-e[1]*e[2],r);if("mat2x3"===t||"mat2x3f"===t||"mat2x3h"===t)return new qo(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 qo(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 Zo&&r instanceof Zo){let e=0;for(let t=0;tMath.exp(e)),n.typeInfo);const r=n;return new qo(Math.exp(r.value),n.typeInfo)}Exp2(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.pow(2,e)),n.typeInfo);const r=n;return new qo(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 Zo)return new Zo(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 Zo)return new Zo(n.data.map(e=>this._firstLeadingBit(e)),n.typeInfo);const r=n;return new qo(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 Zo)return new Zo(n.data.map(e=>this._firstTrailingBit(e)),n.typeInfo);const r=n;return new qo(this._firstTrailingBit(r.value),n.typeInfo)}Floor(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.floor(e)),n.typeInfo);const r=n;return new qo(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 Zo&&r instanceof Zo&&i instanceof Zo)return n.data.length!==r.data.length||n.data.length!==i.data.length?null:new Zo(n.data.map((e,t)=>e*r.data[t]+i.data[t]),n.typeInfo);const s=n,o=r,a=i;return new qo(s.value*o.value+a.value,s.typeInfo)}Fract(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>e-Math.floor(e)),n.typeInfo);const r=n;return new qo(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 qo(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 Zo){let e=0;return n.data.forEach(t=>{e+=t*t}),new qo(Math.sqrt(e),this.getTypeInfo("f32"))}const r=n;return new qo(Math.abs(r.value),n.typeInfo)}Log(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.log(e)),n.typeInfo);const r=n;return new qo(Math.log(r.value),n.typeInfo)}Log2(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.log2(e)),n.typeInfo);const r=n;return new qo(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 Zo&&r instanceof Zo)return new Zo(n.data.map((e,t)=>Math.max(e,r.data[t])),n.typeInfo);const i=n,s=r;return new qo(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 Zo&&r instanceof Zo)return new Zo(n.data.map((e,t)=>Math.min(e,r.data[t])),n.typeInfo);const i=n,s=r;return new qo(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 Zo&&r instanceof Zo&&i instanceof Zo)return new Zo(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 qo(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 Zo&&r instanceof Zo)return new Zo(n.data.map((e,t)=>e%r.data[t]),n.typeInfo);const i=r;return new qo(n.value%i.value,n.typeInfo)}Normalize(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo){const r=this.Length(e,t).value;return new Zo(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 Zo&&r instanceof Zo)return new Zo(n.data.map((e,t)=>Math.pow(e,r.data[t])),n.typeInfo);const i=n,s=r;return new qo(Math.pow(i.value,s.value),n.typeInfo)}QuantizeToF16(e,t){const n=this.exec.evalExpression(e.args[0],t);return n instanceof Zo?new Zo(n.data.map(e=>e),n.typeInfo):new qo(n.value,n.typeInfo)}Radians(e,t){const n=this.exec.evalExpression(e.args[0],t);return n instanceof Zo?new Zo(n.data.map(e=>e*Math.PI/180),n.typeInfo):new qo(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 Zo&&r instanceof Zo){const e=this._dot(n.data,r.data);return new Zo(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 Zo&&r instanceof Zo&&i instanceof qo){const e=this._dot(r.data,n.data);return new Zo(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 Zo)return new Zo(n.data.map(e=>Math.round(e)),n.typeInfo);const r=n;return new qo(Math.round(r.value),n.typeInfo)}Saturate(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.min(Math.max(e,0),1)),n.typeInfo);const r=n;return new qo(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 Zo)return new Zo(n.data.map(e=>Math.sign(e)),n.typeInfo);const r=n;return new qo(Math.sign(r.value),n.typeInfo)}Sin(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.sin(e)),n.typeInfo);const r=n;return new qo(Math.sin(r.value),n.typeInfo)}Sinh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.sinh(e)),n.typeInfo);const r=n;return new qo(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 Zo&&n instanceof Zo&&r instanceof Zo)return new Zo(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 qo(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 Zo)return new Zo(n.data.map(e=>Math.sqrt(e)),n.typeInfo);const r=n;return new qo(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 Zo&&n instanceof Zo)return new Zo(r.data.map((e,t)=>eMath.tan(e)),n.typeInfo);const r=n;return new qo(Math.tan(r.value),n.typeInfo)}Tanh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof Zo)return new Zo(n.data.map(e=>Math.tanh(e)),n.typeInfo);const r=n;return new qo(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 Jo))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 Jo([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 Jo([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 Jo([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 Jo([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 Jo([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 Jo([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 Jo([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 Jo([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 Jo([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 Zo)return new Zo(n.data.map(e=>Math.trunc(e)),n.typeInfo);const r=n;return new qo(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 Io){const e=n.name,i=t.getVariableValue(e);if(i instanceof ta){if(r<0||r>=i.mipLevelCount)return null;const e=i.getMipLevelSize(r),t=i.dimension;return"1d"===t?new qo(e[0],this.getTypeInfo("u32")):"3d"===t?new Zo(e,this.getTypeInfo("vec3u")):"2d"===t?new Zo(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 Zo)||2!==r.data.length)return null;if(n instanceof Io){const e=n.name,s=t.getVariableValue(e);if(s instanceof ta){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 Zo(n,this.getTypeInfo("vec4f"))}return null}return null}TextureNumLayers(e,t){const n=e.args[0];if(n instanceof Io){const e=n.name,r=t.getVariableValue(e);return r instanceof ta?new qo(r.depthOrArrayLayers,this.getTypeInfo("u32")):null}return null}TextureNumLevels(e,t){const n=e.args[0];if(n instanceof Io){const e=n.name,r=t.getVariableValue(e);return r instanceof ta?new qo(r.mipLevelCount,this.getTypeInfo("u32")):null}return null}TextureNumSamples(e,t){const n=e.args[0];if(n instanceof Io){const e=n.name,r=t.getVariableValue(e);return r instanceof ta?new qo(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 Zo)||2!==r.data.length)return null;if(n instanceof Io){const e=n.name,o=t.getVariableValue(e);if(o instanceof ta){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 Oo&&(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 Oo&&(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 qo&&o instanceof qo&&(a.value=o.value),i.value instanceof ea&&i.value.setDataValue(this.exec,a,n.postfix,t),null}AtomicAdd(e,t){let n=e.args[0];n instanceof Oo&&(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 qo(a.value,a.typeInfo);return a instanceof qo&&o instanceof qo&&(a.value+=o.value),i.value instanceof ea&&i.value.setDataValue(this.exec,a,n.postfix,t),A}AtomicSub(e,t){let n=e.args[0];n instanceof Oo&&(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 qo(a.value,a.typeInfo);return a instanceof qo&&o instanceof qo&&(a.value-=o.value),i.value instanceof ea&&i.value.setDataValue(this.exec,a,n.postfix,t),A}AtomicMax(e,t){let n=e.args[0];n instanceof Oo&&(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 qo(a.value,a.typeInfo);return a instanceof qo&&o instanceof qo&&(a.value=Math.max(a.value,o.value)),i.value instanceof ea&&i.value.setDataValue(this.exec,a,n.postfix,t),A}AtomicMin(e,t){let n=e.args[0];n instanceof Oo&&(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 qo(a.value,a.typeInfo);return a instanceof qo&&o instanceof qo&&(a.value=Math.min(a.value,o.value)),i.value instanceof ea&&i.value.setDataValue(this.exec,a,n.postfix,t),A}AtomicAnd(e,t){let n=e.args[0];n instanceof Oo&&(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 qo(a.value,a.typeInfo);return a instanceof qo&&o instanceof qo&&(a.value=a.value&o.value),i.value instanceof ea&&i.value.setDataValue(this.exec,a,n.postfix,t),A}AtomicOr(e,t){let n=e.args[0];n instanceof Oo&&(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 qo(a.value,a.typeInfo);return a instanceof qo&&o instanceof qo&&(a.value=a.value|o.value),i.value instanceof ea&&i.value.setDataValue(this.exec,a,n.postfix,t),A}AtomicXor(e,t){let n=e.args[0];n instanceof Oo&&(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 qo(a.value,a.typeInfo);return a instanceof qo&&o instanceof qo&&(a.value=a.value^o.value),i.value instanceof ea&&i.value.setDataValue(this.exec,a,n.postfix,t),A}AtomicExchange(e,t){let n=e.args[0];n instanceof Oo&&(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 qo(a.value,a.typeInfo);return a instanceof qo&&o instanceof qo&&(a.value=o.value),i.value instanceof ea&&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 Sa={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},Ca={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 ka extends Ea{constructor(e,t){var n;super(),this.ast=null!=e?e:[],this.reflection=new ba,this.reflection.updateAST(this.ast),this.context=null!==(n=null==t?void 0:t.clone())&&void 0!==n?n:new xa,this.builtins=new Ta(this),this.typeInfo={bool:this.getTypeInfo(vo.bool),i32:this.getTypeInfo(vo.i32),u32:this.getTypeInfo(vo.u32),f32:this.getTypeInfo(vo.f32),f16:this.getTypeInfo(vo.f16),vec2f:this.getTypeInfo(xo.vec2f),vec2u:this.getTypeInfo(xo.vec2u),vec2i:this.getTypeInfo(xo.vec2i),vec2h:this.getTypeInfo(xo.vec2h),vec3f:this.getTypeInfo(xo.vec3f),vec3u:this.getTypeInfo(xo.vec3u),vec3i:this.getTypeInfo(xo.vec3i),vec3h:this.getTypeInfo(xo.vec3h),vec4f:this.getTypeInfo(xo.vec4f),vec4u:this.getTypeInfo(xo.vec4u),vec4i:this.getTypeInfo(xo.vec4i),vec4h:this.getTypeInfo(xo.vec4h),mat2x2f:this.getTypeInfo(xo.mat2x2f),mat2x3f:this.getTypeInfo(xo.mat2x3f),mat2x4f:this.getTypeInfo(xo.mat2x4f),mat3x2f:this.getTypeInfo(xo.mat3x2f),mat3x3f:this.getTypeInfo(xo.mat3x3f),mat3x4f:this.getTypeInfo(xo.mat3x4f),mat4x2f:this.getTypeInfo(xo.mat4x2f),mat4x3f:this.getTypeInfo(xo.mat4x3f),mat4x4f:this.getTypeInfo(xo.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 qo)return r.value;if(r instanceof Zo)return Array.from(r.data);if(r instanceof Jo)return Array.from(r.data);if(r instanceof ea&&r.typeInfo instanceof ms){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 Zo(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 ta(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 ea(t.uniform,this.getTypeInfo(i.type)):n.value=new ea(t,this.getTypeInfo(i.type))}}})}for(let u=0;u0){const e=n.getVariableValue(l.value[0]);r[0]=e instanceof qo?e.value:parseInt(l.value[0])}if(l.value.length>1){const e=n.getVariableValue(l.value[1]);r[1]=e instanceof qo?e.value:parseInt(l.value[1])}if(l.value.length>2){const e=n.getVariableValue(l.value[2]);r[2]=e instanceof qo?e.value:parseInt(l.value[2])}}const i=this.getTypeInfo("vec3u"),s=this.getTypeInfo("u32");n.setVariable("@workgroup_size",new Zo(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 Oo){const n=this._getVariableData(e.variable,t),r=this.evalExpression(e.value,t),i=e.operator;if("="===i){if(n instanceof qo||n instanceof Zo||n instanceof Jo){if(r instanceof qo||r instanceof Zo||r instanceof Jo&&n.data.length===r.data.length)return void n.data.set(r.data)}else if(n instanceof ea&&r instanceof ea&&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 qo||n instanceof Zo||n instanceof Jo)&&(r instanceof qo||r instanceof Zo||r instanceof Jo)?void n.data.set(r.data.map((e,t)=>n.data[t]+e)):void 0;if("-="===i)return(n instanceof qo||n instanceof Zo||n instanceof Jo)&&(r instanceof qo||r instanceof Zo||r instanceof Jo)?void n.data.set(r.data.map((e,t)=>n.data[t]-e)):void 0}if(e.variable instanceof Oo){if("*"===e.variable.operator){r=this.getVariableName(e.variable.right,t);const i=t.getVariable(r);if(!(i&&i.value instanceof Yo))return;n=i.value.reference;let s=e.variable.postfix;if(!s){let t=e.variable.right;for(;t instanceof Oo;){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 Yo&&(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 Zo&&s instanceof qo){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 Zo&&s instanceof Zo){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 qo&&s instanceof qo))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 ea&&n.setDataValue(this,e,i,t))}if(n instanceof ea)n.setDataValue(this,s,i,t);else if(i){if(!(n instanceof Zo||n instanceof Jo))return;if(i instanceof Bo){const e=this.evalExpression(i.index,t).value;if(n instanceof Zo){if(!(s instanceof qo))return;n.data[e]=s.value}else{if(!(n instanceof Jo))return;{const e=this.evalExpression(i.index,t).value;if(e<0)return;if(!(s instanceof Zo))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 ko){const e=i.value;if(!(n instanceof Zo))return;if(s instanceof qo){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 Zo))return;if(e.length!==s.data.length)return;for(let t=0;t+e);return new Zo(e,n.typeInfo)}const e=r,t=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new qo(+e,t)}case"-":{if(oa(r)){const e=r.map((e,t)=>-e);return new Zo(e,n.typeInfo)}const e=r,t=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new qo(-e,t)}case"!":{if(oa(r)){const e=r.map((e,t)=>e?0:1);return new Zo(e,n.typeInfo)}const e=r,t=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new qo(e?0:1,t)}case"~":{if(oa(r)){const e=r.map((e,t)=>~e);return new Zo(e,n.typeInfo)}const e=r,t=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new qo(~e,t)}}return null}_evalBinaryOp(e,t){const n=this.evalExpression(e.left,t),r=this.evalExpression(e.right,t),i=n instanceof qo?n.value:n instanceof Zo||n instanceof Jo?Array.from(n.data):null,s=r instanceof qo?r.value:r instanceof Zo||r instanceof Jo?Array.from(r.data):null;switch(e.operator){case"+":{if(oa(i)&&oa(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e+t[n]);return new Zo(r,n.typeInfo)}if(oa(i)){const e=s,t=i.map((t,n)=>t+e);return new Zo(t,n.typeInfo)}if(oa(s)){const e=i,t=s.map((t,n)=>e+t);return new Zo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new qo(e+t,o)}case"-":{if(oa(i)&&oa(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e-t[n]);return new Zo(r,n.typeInfo)}if(oa(i)){const e=s,t=i.map((t,n)=>t-e);return new Zo(t,n.typeInfo)}if(oa(s)){const e=i,t=s.map((t,n)=>e-t);return new Zo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new qo(e-t,o)}case"*":{if(oa(i)&&oa(s)){const e=i,t=s;if(n instanceof Jo&&r instanceof Jo){const i=function(e,t,n,r){if(void 0===Ca[t.name]||void 0===Ca[r.name])return null;const i=Ca[t.name][0],s=Ca[t.name][1],o=Ca[r.name][0];if(i!==Ca[r.name][1])return null;const a=new Array(o*s);for(let A=0;Ae*t[n]);return new Zo(r,n.typeInfo)}}if(oa(i)){const e=s,t=i.map((t,n)=>t*e);return n instanceof Jo?new Jo(t,n.typeInfo):new Zo(t,n.typeInfo)}if(oa(s)){const e=i,t=s.map((t,n)=>e*t);return r instanceof Jo?new Jo(t,r.typeInfo):new Zo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new qo(e*t,o)}case"%":{if(oa(i)&&oa(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e%t[n]);return new Zo(r,n.typeInfo)}if(oa(i)){const e=s,t=i.map((t,n)=>t%e);return new Zo(t,n.typeInfo)}if(oa(s)){const e=i,t=s.map((t,n)=>e%t);return new Zo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new qo(e%t,o)}case"/":{if(oa(i)&&oa(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e/t[n]);return new Zo(r,n.typeInfo)}if(oa(i)){const e=s,t=i.map((t,n)=>t/e);return new Zo(t,n.typeInfo)}if(oa(s)){const e=i,t=s.map((t,n)=>e/t);return new Zo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new qo(e/t,o)}case"&":{if(oa(i)&&oa(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e&t[n]);return new Zo(r,n.typeInfo)}if(oa(i)){const e=s,t=i.map((t,n)=>t&e);return new Zo(t,n.typeInfo)}if(oa(s)){const e=i,t=s.map((t,n)=>e&t);return new Zo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new qo(e&t,o)}case"|":{if(oa(i)&&oa(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e|t[n]);return new Zo(r,n.typeInfo)}if(oa(i)){const e=s,t=i.map((t,n)=>t|e);return new Zo(t,n.typeInfo)}if(oa(s)){const e=i,t=s.map((t,n)=>e|t);return new Zo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new qo(e|t,o)}case"^":{if(oa(i)&&oa(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e^t[n]);return new Zo(r,n.typeInfo)}if(oa(i)){const e=s,t=i.map((t,n)=>t^e);return new Zo(t,n.typeInfo)}if(oa(s)){const e=i,t=s.map((t,n)=>e^t);return new Zo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new qo(e^t,o)}case"<<":{if(oa(i)&&oa(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e<t<e<>":{if(oa(i)&&oa(s)){const e=i,t=s;if(e.length!==t.length)return null;const r=e.map((e,n)=>e>>t[n]);return new Zo(r,n.typeInfo)}if(oa(i)){const e=s,t=i.map((t,n)=>t>>e);return new Zo(t,n.typeInfo)}if(oa(s)){const e=i,t=s.map((t,n)=>e>>t);return new Zo(t,r.typeInfo)}const e=i,t=s,o=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new qo(e>>t,o)}case">":if(oa(i)&&oa(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 Zo(r,n.typeInfo)}if(oa(i)){const e=s,t=i.map((t,n)=>t>e?1:0);return new Zo(t,n.typeInfo)}if(oa(s)){const e=i,t=s.map((t,n)=>e>t?1:0);return new Zo(t,r.typeInfo)}return new qo(i>s?1:0,this.getTypeInfo("bool"));case"<":if(oa(i)&&oa(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 Zo(r,n.typeInfo)}if(oa(i)){const e=s,t=i.map((t,n)=>t==e?1:0);return new Zo(t,n.typeInfo)}if(oa(s)){const e=i,t=s.map((t,n)=>e==t?1:0);return new Zo(t,r.typeInfo)}return new qo(i===s?1:0,this.getTypeInfo("bool"));case"!=":if(oa(i)&&oa(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 Zo(r,n.typeInfo)}if(oa(i)){const e=s,t=i.map((t,n)=>t!==e?1:0);return new Zo(t,n.typeInfo)}if(oa(s)){const e=i,t=s.map((t,n)=>e!==t?1:0);return new Zo(t,r.typeInfo)}return new qo(i!==s?1:0,this.getTypeInfo("bool"));case">=":if(oa(i)&&oa(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 Zo(r,n.typeInfo)}if(oa(i)){const e=s,t=i.map((t,n)=>t>=e?1:0);return new Zo(t,n.typeInfo)}if(oa(s)){const e=i,t=s.map((t,n)=>e>=t?1:0);return new Zo(t,r.typeInfo)}return new qo(i>=s?1:0,this.getTypeInfo("bool"));case"<=":if(oa(i)&&oa(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 Zo(r,n.typeInfo)}if(oa(i)){const e=s,t=i.map((t,n)=>t<=e?1:0);return new Zo(t,n.typeInfo)}if(oa(s)){const e=i,t=s.map((t,n)=>e<=t?1:0);return new Zo(t,r.typeInfo)}return new qo(i<=s?1:0,this.getTypeInfo("bool"));case"&&":if(oa(i)&&oa(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 Zo(r,n.typeInfo)}if(oa(i)){const e=s,t=i.map((t,n)=>t&&e?1:0);return new Zo(t,n.typeInfo)}if(oa(s)){const e=i,t=s.map((t,n)=>e&&t?1:0);return new Zo(t,r.typeInfo)}return new qo(i&&s?1:0,this.getTypeInfo("bool"));case"||":if(oa(i)&&oa(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 Zo(r,n.typeInfo)}if(oa(i)){const e=s,t=i.map((t,n)=>t||e?1:0);return new Zo(t,n.typeInfo)}if(oa(s)){const e=i,t=s.map((t,n)=>e||t?1:0);return new Zo(t,r.typeInfo)}return new qo(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=Ca[r];if(void 0===i)return null;const s=[];if(e instanceof Lo)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 Zo?s.push(...e.data):e instanceof qo?s.push(e.value):e instanceof Jo&&s.push(...e.data)}if(n instanceof bs&&null===n.format&&(n.format=this.getTypeInfo("f32")),0===s.length){const r=new Array(i[2]).fill(0);return new Jo(r,n).getSubData(this,e.postfix,t)}return s.length!==i[2]?null:new Jo(s,n).getSubData(this,e.postfix,t)}}ka._breakObj=new Xo(new fs("BREAK",null),null),ka._continueObj=new Xo(new fs("CONTINUE",null),null),ka._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);class Ra{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}}class Pa{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new Ra,this._exec=new ka,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 Io){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 Ho||e instanceof Eo?e.type=this._forwardType(e.type):e instanceof To?e.format=this._forwardType(e.format):e instanceof Ks||e instanceof Js||e instanceof eo?e.type=this._forwardType(e.type):e instanceof $s?e.returnType=this._forwardType(e.returnType):e instanceof Vo&&(e.type=this._forwardType(e.type))});return t}_forwardType(e){if(e instanceof yo){const t=this._getType(e.name);if(t)return t}else e instanceof Eo?e.type=this._forwardType(e.type):e instanceof To&&(e.format=this._forwardType(e.format));return e}_initialize(e){if(e)if("string"==typeof e){const t=new sa(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==ra.eof}_match(e){if(e instanceof na)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(ra.keywords.if)&&(this._advance(),t.condition=this._optional_paren_expression())}else if(this._match(ra.keywords.continue)){const t=this._updateNode(new bo);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(ra.tokens.semicolon,"Expected ';' after statement."),e}_static_assert_statement(){if(!this._match(ra.keywords.static_assert))return null;const e=this._currentLine,t=this._optional_paren_expression();return this._updateNode(new Xs(t),e)}_while_statement(){if(!this._match(ra.keywords.while))return null;const e=this._updateNode(new Qs(null,null));return this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(ra.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(ra.keywords.continuing))return null;const t=this._currentLine,n=this._compound_statement();return this._updateNode(new Ys(n,e),t)}_for_statement(){if(!this._match(ra.keywords.for))return null;this._consume(ra.tokens.paren_left,"Expected '('.");const e=this._updateNode(new qs(null,null,null,null));return this._currentLoop.push(e),e.init=this._check(ra.tokens.semicolon)?null:this._for_init(),this._consume(ra.tokens.semicolon,"Expected ';'."),e.condition=this._check(ra.tokens.semicolon)?null:this._short_circuit_or_expression(),this._consume(ra.tokens.semicolon,"Expected ';'."),e.increment=this._check(ra.tokens.paren_right)?null:this._for_increment(),this._consume(ra.tokens.paren_right,"Expected ')'."),this._check(ra.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(ra.keywords.var)){const e=this._variable_decl();if(null===e)throw this._error(this._peek(),"Variable declaration expected.");let t=null;return this._match(ra.tokens.equal)&&(t=this._short_circuit_or_expression()),this._updateNode(new Ks(e.name,e.type,e.storage,e.access,t),e.line)}if(this._match(ra.keywords.let)){const e=this._currentLine,t=this._consume(ra.tokens.name,"Expected name for let.").toString();let n=null;if(this._match(ra.tokens.colon)){const e=this._attribute();n=this._type_decl(),null!=n&&(n.attributes=e)}this._consume(ra.tokens.equal,"Expected '=' for let.");const r=this._short_circuit_or_expression();return this._updateNode(new Js(t,n,null,null,r),e)}if(this._match(ra.keywords.const)){const e=this._currentLine,t=this._consume(ra.tokens.name,"Expected name for const.").toString();let n=null;if(this._match(ra.tokens.colon)){const e=this._attribute();n=this._type_decl(),null!=n&&(n.attributes=e)}this._consume(ra.tokens.equal,"Expected '=' for const.");const r=this._short_circuit_or_expression();return null===n&&r instanceof Lo&&(n=r.type),this._updateNode(new eo(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(ra.increment_operators))return this._current=e,null;const n=this._consume(ra.increment_operators,"Expected increment operator");return this._updateNode(new so(n.type===ra.tokens.plus_plus?to.increment:to.decrement,t))}_assignment_statement(){let e=null;const t=this._currentLine;if(this._check(ra.tokens.brace_right))return null;let n=this._match(ra.tokens.underscore);if(n||(e=this._unary_expression()),!n&&null==e)return null;const r=this._consume(ra.assignment_operators,"Expected assignment operator."),i=this._short_circuit_or_expression();return this._updateNode(new oo(no.parse(r.lexeme),e,i),t)}_func_call_statement(){if(!this._check(ra.tokens.ident))return null;const e=this._currentLine,t=this._current,n=this._consume(ra.tokens.ident,"Expected function name."),r=this._argument_expression_list();return null===r?(this._current=t,null):this._updateNode(new ao(n.lexeme,r),e)}_loop_statement(){if(!this._match(ra.keywords.loop))return null;this._check(ra.tokens.attr)&&this._attribute(),this._consume(ra.tokens.brace_left,"Expected '{' for loop.");const e=this._updateNode(new Ao([],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 Ys){e.continuing=t;break}t=this._statement()}return this._currentLoop.pop(),this._consume(ra.tokens.brace_right,"Expected '}' for loop."),e}_switch_statement(){if(!this._match(ra.keywords.switch))return null;const e=this._updateNode(new lo(null,[]));if(this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(ra.tokens.attr)&&this._attribute(),this._consume(ra.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(ra.tokens.brace_right,"Expected '}' for switch."),this._currentLoop.pop(),e}_switch_body(){const e=[];let t=!1;for(;this._check([ra.keywords.default,ra.keywords.case]);){if(this._match(ra.keywords.case)){const n=this._case_selectors();for(const e of n)if(e instanceof jo){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");t=!0;break}this._match(ra.tokens.colon),this._check(ra.tokens.attr)&&this._attribute(),this._consume(ra.tokens.brace_left,"Exected '{' for switch case.");const r=this._case_body();this._consume(ra.tokens.brace_right,"Exected '}' for switch case."),e.push(this._updateNode(new Go(n,r)))}if(this._match(ra.keywords.default)){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");this._match(ra.tokens.colon),this._check(ra.tokens.attr)&&this._attribute(),this._consume(ra.tokens.brace_left,"Exected '{' for switch default.");const n=this._case_body();this._consume(ra.tokens.brace_right,"Exected '}' for switch default."),e.push(this._updateNode(new zo(n)))}}return e}_case_selectors(){const e=[];for(this._match(ra.keywords.default)?e.push(this._updateNode(new jo)):e.push(this._shift_expression());this._match(ra.tokens.comma);)this._match(ra.keywords.default)?e.push(this._updateNode(new jo)):e.push(this._shift_expression());return e}_case_body(){if(this._match(ra.keywords.fallthrough))return this._consume(ra.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(ra.keywords.if))return null;const e=this._currentLine,t=this._optional_paren_expression();this._check(ra.tokens.attr)&&this._attribute();const n=this._compound_statement();let r=[];this._match_elseif()&&(this._check(ra.tokens.attr)&&this._attribute(),r=this._elseif_statement(r));let i=null;return this._match(ra.keywords.else)&&(this._check(ra.tokens.attr)&&this._attribute(),i=this._compound_statement()),this._updateNode(new co(t,n,r,i),e)}_match_elseif(){return this._tokens[this._current].type===ra.keywords.else&&this._tokens[this._current+1].type===ra.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 Wo(t,n))),this._match_elseif()&&(this._check(ra.tokens.attr)&&this._attribute(),this._elseif_statement(e)),e}_return_statement(){if(!this._match(ra.keywords.return))return null;const e=this._short_circuit_or_expression();return this._updateNode(new uo(e))}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(ra.tokens.or_or);)e=this._updateNode(new Fo(this._previous().toString(),e,this._short_circuit_and_expr()));return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(ra.tokens.and_and);)e=this._updateNode(new Fo(this._previous().toString(),e,this._inclusive_or_expression()));return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(ra.tokens.or);)e=this._updateNode(new Fo(this._previous().toString(),e,this._exclusive_or_expression()));return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(ra.tokens.xor);)e=this._updateNode(new Fo(this._previous().toString(),e,this._and_expression()));return e}_and_expression(){let e=this._equality_expression();for(;this._match(ra.tokens.and);)e=this._updateNode(new Fo(this._previous().toString(),e,this._equality_expression()));return e}_equality_expression(){const e=this._relational_expression();return this._match([ra.tokens.equal_equal,ra.tokens.not_equal])?this._updateNode(new Fo(this._previous().toString(),e,this._relational_expression())):e}_relational_expression(){let e=this._shift_expression();for(;this._match([ra.tokens.less_than,ra.tokens.greater_than,ra.tokens.less_than_equal,ra.tokens.greater_than_equal]);)e=this._updateNode(new Fo(this._previous().toString(),e,this._shift_expression()));return e}_shift_expression(){let e=this._additive_expression();for(;this._match([ra.tokens.shift_left,ra.tokens.shift_right]);)e=this._updateNode(new Fo(this._previous().toString(),e,this._additive_expression()));return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([ra.tokens.plus,ra.tokens.minus]);)e=this._updateNode(new Fo(this._previous().toString(),e,this._multiplicative_expression()));return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([ra.tokens.star,ra.tokens.forward_slash,ra.tokens.modulo]);)e=this._updateNode(new Fo(this._previous().toString(),e,this._unary_expression()));return e}_unary_expression(){return this._match([ra.tokens.minus,ra.tokens.bang,ra.tokens.tilde,ra.tokens.star,ra.tokens.and])?this._updateNode(new Oo(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(ra.tokens.bracket_left)){const e=this._short_circuit_or_expression();this._consume(ra.tokens.bracket_right,"Expected ']'.");const t=this._updateNode(new Bo(e)),n=this._postfix_expression();return n&&(t.postfix=n),t}if(this._match(ra.tokens.period)){const e=this._consume(ra.tokens.name,"Expected member name."),t=this._postfix_expression(),n=this._updateNode(new ko(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 vo.void;case"bool":return vo.bool;case"i32":return vo.i32;case"u32":return vo.u32;case"f32":return vo.f32;case"f16":return vo.f16;case"vec2f":return xo.vec2f;case"vec3f":return xo.vec3f;case"vec4f":return xo.vec4f;case"vec2i":return xo.vec2i;case"vec3i":return xo.vec3i;case"vec4i":return xo.vec4i;case"vec2u":return xo.vec2u;case"vec3u":return xo.vec3u;case"vec4u":return xo.vec4u;case"vec2h":return xo.vec2h;case"vec3h":return xo.vec3h;case"vec4h":return xo.vec4h;case"mat2x2f":return xo.mat2x2f;case"mat2x3f":return xo.mat2x3f;case"mat2x4f":return xo.mat2x4f;case"mat3x2f":return xo.mat3x2f;case"mat3x3f":return xo.mat3x3f;case"mat3x4f":return xo.mat3x4f;case"mat4x2f":return xo.mat4x2f;case"mat4x3f":return xo.mat4x3f;case"mat4x4f":return xo.mat4x4f;case"mat2x2h":return xo.mat2x2h;case"mat2x3h":return xo.mat2x3h;case"mat2x4h":return xo.mat2x4h;case"mat3x2h":return xo.mat3x2h;case"mat3x3h":return xo.mat3x3h;case"mat3x4h":return xo.mat3x4h;case"mat4x2h":return xo.mat4x2h;case"mat4x3h":return xo.mat4x3h;case"mat4x4h":return xo.mat4x4h;case"mat2x2i":return xo.mat2x2i;case"mat2x3i":return xo.mat2x3i;case"mat2x4i":return xo.mat2x4i;case"mat3x2i":return xo.mat3x2i;case"mat3x3i":return xo.mat3x3i;case"mat3x4i":return xo.mat3x4i;case"mat4x2i":return xo.mat4x2i;case"mat4x3i":return xo.mat4x3i;case"mat4x4i":return xo.mat4x4i;case"mat2x2u":return xo.mat2x2u;case"mat2x3u":return xo.mat2x3u;case"mat2x4u":return xo.mat2x4u;case"mat3x2u":return xo.mat3x2u;case"mat3x3u":return xo.mat3x3u;case"mat3x4u":return xo.mat3x4u;case"mat4x2u":return xo.mat4x2u;case"mat4x3u":return xo.mat4x3u;case"mat4x4u":return xo.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(ra.tokens.ident)){const e=this._previous().toString();if(this._check(ra.tokens.paren_left)){const t=this._argument_expression_list(),n=this._getType(e);return null!==n?this._updateNode(new Ro(n,t)):this._updateNode(new Po(e,t))}if(this._context.constants.has(e)){const t=this._context.constants.get(e);return this._updateNode(new Mo(e,t.value))}return this._updateNode(new Io(e))}if(this._match(ra.tokens.int_literal)){const e=this._previous().toString();let t=e.endsWith("i")||e.endsWith("i")?vo.i32:e.endsWith("u")||e.endsWith("U")?vo.u32:vo.x32;const n=parseInt(e);return this._validateTypeRange(n,t),this._updateNode(new Lo(new qo(n,this._exec.getTypeInfo(t)),t))}if(this._match(ra.tokens.uint_literal)){const e=parseInt(this._previous().toString());return this._validateTypeRange(e,vo.u32),this._updateNode(new Lo(new qo(e,this._exec.getTypeInfo(vo.u32)),vo.u32))}if(this._match([ra.tokens.decimal_float_literal,ra.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?vo.f16:vo.f32);const r=t?vo.f16:vo.f32;return this._updateNode(new Lo(new qo(n,this._exec.getTypeInfo(r)),r))}if(this._match([ra.keywords.true,ra.keywords.false])){let e=this._previous().toString()===ra.keywords.true.rule;return this._updateNode(new Lo(new qo(e?1:0,this._exec.getTypeInfo(vo.bool)),vo.bool))}if(this._check(ra.tokens.paren_left))return this._paren_expression();if(this._match(ra.keywords.bitcast)){this._consume(ra.tokens.less_than,"Expected '<'.");const e=this._type_decl();this._consume(ra.tokens.greater_than,"Expected '>'.");const t=this._paren_expression();return this._updateNode(new No(e,t))}const e=this._type_decl(),t=this._argument_expression_list();return this._updateNode(new Ro(e,t))}_argument_expression_list(){if(!this._match(ra.tokens.paren_left))return null;const e=[];do{if(this._check(ra.tokens.paren_right))break;const t=this._short_circuit_or_expression();e.push(t)}while(this._match(ra.tokens.comma));return this._consume(ra.tokens.paren_right,"Expected ')' for agument list"),e}_optional_paren_expression(){this._match(ra.tokens.paren_left);const e=this._short_circuit_or_expression();return this._match(ra.tokens.paren_right),e}_paren_expression(){this._consume(ra.tokens.paren_left,"Expected '('.");const e=this._short_circuit_or_expression();return this._consume(ra.tokens.paren_right,"Expected ')'."),e}_struct_decl(){if(!this._match(ra.keywords.struct))return null;const e=this._currentLine,t=this._consume(ra.tokens.ident,"Expected name for struct.").toString();this._consume(ra.tokens.brace_left,"Expected '{' for struct body.");const n=[];for(;!this._check(ra.tokens.brace_right);){const e=this._attribute(),t=this._consume(ra.tokens.name,"Expected variable name.").toString();this._consume(ra.tokens.colon,"Expected ':' for struct member type.");const r=this._attribute(),i=this._type_decl();null!=i&&(i.attributes=r),this._check(ra.tokens.brace_right)?this._match(ra.tokens.comma):this._consume(ra.tokens.comma,"Expected ',' for struct member."),n.push(this._updateNode(new Ho(t,i,e)))}this._consume(ra.tokens.brace_right,"Expected '}' after struct body.");const r=this._currentLine,i=this._updateNode(new wo(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(ra.tokens.equal)){const t=this._const_expression();e.value=t}if(null!==e.type&&e.value instanceof Lo){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 Lo&&(e.type="x32"===e.value.type.name?vo.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(ra.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){var e;if(!this._match(ra.keywords.const))return null;const t=this._consume(ra.tokens.name,"Expected variable name"),n=this._currentLine;let r=null;if(this._match(ra.tokens.colon)){const e=this._attribute();r=this._type_decl(),null!=r&&(r.attributes=e)}let i=null;this._consume(ra.tokens.equal,"const declarations require an assignment");const s=this._short_circuit_or_expression();try{let e=[vo.f32],n=s.constEvaluate(this._exec,e);n instanceof qo&&this._validateTypeRange(n.value,e[0]),e[0]instanceof xo&&null===e[0].format&&n.typeInfo instanceof bs&&null!==n.typeInfo.format&&("f16"===n.typeInfo.format.name?e[0].format=vo.f16:"f32"===n.typeInfo.format.name?e[0].format=vo.f32:"i32"===n.typeInfo.format.name?e[0].format=vo.i32:"u32"===n.typeInfo.format.name?e[0].format=vo.u32:"bool"===n.typeInfo.format.name&&(e[0].format=vo.bool)),i=this._updateNode(new Lo(n,e[0])),this._exec.context.setVariable(t.toString(),n)}catch(a){i=s}if(null!==r&&i instanceof Lo){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 Lo&&(r=null!==(e=null==i?void 0:i.type)&&void 0!==e?e:vo.f32,r===vo.x32&&(r=vo.i32));const o=this._updateNode(new eo(t.toString(),r,"","",i),n);return this._context.constants.set(o.name,o),o}_global_let_decl(){if(!this._match(ra.keywords.let))return null;const e=this._currentLine,t=this._consume(ra.tokens.name,"Expected variable name");let n=null;if(this._match(ra.tokens.colon)){const e=this._attribute();n=this._type_decl(),null!=n&&(n.attributes=e)}let r=null;if(this._match(ra.tokens.equal)&&(r=this._const_expression()),null!==n&&r instanceof Lo){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 Lo&&(n="x32"===r.type.name?vo.i32:r.type);return r instanceof Lo&&r.isScalar&&this._validateTypeRange(r.scalarValue,n),this._updateNode(new Js(t.toString(),n,"","",r),e)}_const_expression(){return this._short_circuit_or_expression()}_variable_decl(){if(!this._match(ra.keywords.var))return null;const e=this._currentLine;let t="",n="";this._match(ra.tokens.less_than)&&(t=this._consume(ra.storage_class,"Expected storage_class.").toString(),this._match(ra.tokens.comma)&&(n=this._consume(ra.access_mode,"Expected access_mode.").toString()),this._consume(ra.tokens.greater_than,"Expected '>'."));const r=this._consume(ra.tokens.name,"Expected variable name");let i=null;if(this._match(ra.tokens.colon)){const e=this._attribute();i=this._type_decl(),null!=i&&(i.attributes=e)}return this._updateNode(new Ks(r.toString(),i,t,n,null),e)}_override_decl(){if(!this._match(ra.keywords.override))return null;const e=this._consume(ra.tokens.name,"Expected variable name");let t=null;if(this._match(ra.tokens.colon)){const e=this._attribute();t=this._type_decl(),null!=t&&(t.attributes=e)}return this._updateNode(new Zs(e.toString(),t,null))}_diagnostic(){this._consume(ra.tokens.paren_left,"Expected '('");const e=this._consume(ra.tokens.ident,"Expected severity control name.");this._consume(ra.tokens.comma,"Expected ','");let t=this._consume(ra.tokens.ident,"Expected diagnostic rule name.").toString();return this._match(ra.tokens.period)&&(t+=`.${this._consume(ra.tokens.ident,"Expected diagnostic message.").toString()}`),this._consume(ra.tokens.paren_right,"Expected ')'"),this._updateNode(new po(e.toString(),t))}_enable_directive(){const e=this._consume(ra.tokens.ident,"identity expected.");return this._updateNode(new ho(e.toString()))}_requires_directive(){const e=[this._consume(ra.tokens.ident,"identity expected.").toString()];for(;this._match(ra.tokens.comma);){const t=this._consume(ra.tokens.ident,"identity expected.");e.push(t.toString())}return this._updateNode(new fo(e))}_type_alias(){const e=this._consume(ra.tokens.ident,"identity expected.");this._consume(ra.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 go(e.toString(),t));return this._context.aliases.set(n.name,n),n}_type_decl(){if(this._check([ra.tokens.ident,...ra.texel_format,ra.keywords.bool,ra.keywords.f32,ra.keywords.i32,ra.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 yo(e));return this._forwardTypeCount++,t}return this._updateNode(new vo(e))}let e=this._texture_sampler_types();if(e)return e;if(this._check(ra.template_types)){let e=this._advance().toString(),t=null,n=null;return this._match(ra.tokens.less_than)&&(t=this._type_decl(),n=null,this._match(ra.tokens.comma)&&(n=this._consume(ra.access_mode,"Expected access_mode for pointer").toString()),this._consume(ra.tokens.greater_than,"Expected '>' for type.")),this._updateNode(new xo(e,t,n))}if(this._match(ra.keywords.ptr)){let e=this._previous().toString();this._consume(ra.tokens.less_than,"Expected '<' for pointer.");const t=this._consume(ra.storage_class,"Expected storage_class for pointer");this._consume(ra.tokens.comma,"Expected ',' for pointer.");const n=this._type_decl();let r=null;return this._match(ra.tokens.comma)&&(r=this._consume(ra.access_mode,"Expected access_mode for pointer").toString()),this._consume(ra.tokens.greater_than,"Expected '>' for pointer."),this._updateNode(new Eo(e,t.toString(),n,r))}const t=this._attribute();if(this._match(ra.keywords.array)){let e=null,r=-1;const i=this._previous();let s=null;if(this._match(ra.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(ra.tokens.comma)){s=this._shift_expression();try{t=s.constEvaluate(this._exec).toString(),s=null}catch(n){t="1"}}this._consume(ra.tokens.greater_than,"Expected '>' for array."),r=t?parseInt(t):0}const o=this._updateNode(new To(i.toString(),t,e,r));return s&&this._deferArrayCountEval.push({arrayType:o,countNode:s}),o}return null}_texture_sampler_types(){if(this._match(ra.sampler_type))return this._updateNode(new So(this._previous().toString(),null,null));if(this._match(ra.depth_texture_type))return this._updateNode(new So(this._previous().toString(),null,null));if(this._match(ra.sampled_texture_type)||this._match(ra.multisampled_texture_type)){const e=this._previous();this._consume(ra.tokens.less_than,"Expected '<' for sampler type.");const t=this._type_decl();return this._consume(ra.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new So(e.toString(),t,null))}if(this._match(ra.storage_texture_type)){const e=this._previous();this._consume(ra.tokens.less_than,"Expected '<' for sampler type.");const t=this._consume(ra.texel_format,"Invalid texel format.").toString();this._consume(ra.tokens.comma,"Expected ',' after texel format.");const n=this._consume(ra.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(ra.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new So(e.toString(),t,n))}return null}_attribute(){let e=[];for(;this._match(ra.tokens.attr);){const t=this._consume(ra.attribute_name,"Expected attribute name"),n=this._updateNode(new $o(t.toString(),null));if(this._match(ra.tokens.paren_left)){if(n.value=this._consume(ra.literal_or_ident,"Expected attribute value").toString(),this._check(ra.tokens.comma)){this._advance();do{const e=this._consume(ra.literal_or_ident,"Expected attribute value").toString();n.value instanceof Array||(n.value=[n.value]),n.value.push(e)}while(this._match(ra.tokens.comma))}this._consume(ra.tokens.paren_right,"Expected ')'")}e.push(n)}return 0==e.length?null:e}}class Ia extends ba{constructor(e){super(),e&&this.update(e)}update(e){const t=(new Pa).parse(e);this.updateAST(t)}}function Ma(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 La=globalThis.mathgl.config;function Na(e,{precision:t=La.precision}={}){return e=function(e){return Math.round(e/La.EPSILON)*La.EPSILON}(e),`${parseFloat(e.toPrecision(t))}`}function Ba(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Da(e,t,n){return function(e,t,n){if(Ba(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 Oa(e,t,n){return Ba(e)?e.map((e,r)=>Oa(e,t[r],n)):n*t+(1-n)*e}function Fa(e,t,n){const r=La.EPSILON;try{if(e===t)return!0;if(Ba(e)&&Ba(t)){if(e.length!==t.length)return!1;for(let n=0;n0?", ":"")+Na(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 yA(e,t=[],n=0){const r=Math.fround(e),i=e-r;return t[n]=r,t[n+1]=i,t}const wA={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:yA,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;yA(e[4*r+n],t,2*i)}return t}},xA={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}},EA="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 TA,SA;(SA=TA||(TA={}))[SA.POINT=0]="POINT",SA[SA.DIRECTIONAL=1]="DIRECTIONAL";const CA={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:TA.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:EA,fs:EA,getUniforms:function(e,t={}){if(!(e=e?{...e}:e))return{...CA.defaultUniforms};e.lights&&(e={...e,...RA(e.lights),lights:void 0});const{ambientLight:n,pointLights:r,directionalLights:i}=e||{};if(!(n||r&&r.length>0||i&&i.length>0))return{...CA.defaultUniforms,enabled:0};const s={...CA.defaultUniforms,...t,...kA({ambientLight:n,pointLights:r,directionalLights:i})};return void 0!==e.enabled&&(s.enabled=e.enabled?1:0),s}};function kA({ambientLight:e,pointLights:t=[],directionalLights:n=[]}){const r={};r.ambientColor=PA(e);let i=0;for(const s of t){r.lightType=TA.POINT;const e=i;r[`lightColor${e}`]=PA(s),r[`lightPosition${e}`]=s.position,r[`lightAttenuation${e}`]=s.attenuation||[1,0,0],i++}for(const s of n){r.lightType=TA.DIRECTIONAL;const e=i;r[`lightColor${e}`]=PA(s),r[`lightDirection${e}`]=s.direction,i++}return i>5&&Nr.warn("MAX_LIGHTS exceeded")(),r.directionalLightCount=n.length,r.pointLightCount=t.length,r}function RA(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 PA(e={}){const{color:t=[0,0,0],intensity:n=1}=e;return t.map(e=>e*n/255)}const IA="uniform phongMaterialUniforms {\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n",MA="#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",LA="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",NA={props:{},name:"gouraudMaterial",vs:MA.replace("phongMaterial","gouraudMaterial"),fs:IA.replace("phongMaterial","gouraudMaterial"),source:LA.replaceAll("phongMaterial","gouraudMaterial"),defines:{LIGHTING_VERTEX:!0},dependencies:[CA],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)),{...NA.defaultUniforms,...t}}},BA={name:"phongMaterial",dependencies:[CA],source:LA,vs:IA,fs:MA,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)),{...BA.defaultUniforms,...t}}},DA="uniform layerUniforms {\n uniform float opacity;\n} layer;\n",OA={name:"layer",vs:DA,fs:DA,getUniforms:e=>({opacity:Math.pow(e.opacity,1/2.2)}),uniformTypes:{opacity:"f32"}},FA="#define SMOOTH_EDGE_RADIUS 0.5",UA={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:`${FA}\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:`${FA}\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 jA,GA,zA,VA,WA,HA;(GA=jA||(jA={}))[GA.Start=1]="Start",GA[GA.Move=2]="Move",GA[GA.End=4]="End",GA[GA.Cancel=8]="Cancel",(VA=zA||(zA={}))[VA.None=0]="None",VA[VA.Left=1]="Left",VA[VA.Right=2]="Right",VA[VA.Up=4]="Up",VA[VA.Down=8]="Down",VA[VA.Horizontal=3]="Horizontal",VA[VA.Vertical=12]="Vertical",VA[VA.All=15]="All",(HA=WA||(WA={}))[HA.Possible=1]="Possible",HA[HA.Began=2]="Began",HA[HA.Changed=4]="Changed",HA[HA.Ended=8]="Ended",HA[HA.Recognized=8]="Recognized",HA[HA.Cancelled=16]="Cancelled",HA[HA.Failed=32]="Failed";const $A="manipulation",XA="none",QA="pan-x",YA="pan-y";class qA{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(XA))return XA;const t=e.includes(QA),n=e.includes(YA);return t&&n?XA:t||n?t?QA:YA:e.includes($A)?$A:"auto"}(e.join(" "))}}function KA(e){return e.trim().split(/\s+/g)}function ZA(e,t,n){if(e)for(const r of KA(t))e.addEventListener(r,n,!1)}function JA(e,t,n){if(e)for(const r of KA(t))e.removeEventListener(r,n,!1)}function el(e){return(e.ownerDocument||e).defaultView}function tl(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?zA.Left:zA.Right:t<0?zA.Up:zA.Down}function al(e,t,n){return{x:t/e||0,y:n/e||0}}let Al=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&jA.Start&&r-i===0,o=t&(jA.End|jA.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=nl(t)),i>1&&!n.firstMultiple?n.firstMultiple=nl(t):1===i&&(n.firstMultiple=!1);const{firstInput:s,firstMultiple:o}=n,a=o?o.center:s.center,A=t.center=tl(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=rl(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!==jA.Start&&(null==s?void 0:s.eventType)!==jA.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=ol(t.deltaX,t.deltaY);const u=al(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,il((d=r)[0],d[1])/il(h[0],h[1])):1,t.rotation=o?function(e,t){return sl(t[1],t[0])-sl(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!==jA.Cancel&&(r>25||void 0===n.velocity)){const A=t.deltaX-n.deltaX,l=t.deltaY-n.deltaY,c=al(r,A,l);s=c.x,o=c.y,i=Math.abs(c.x)>Math.abs(c.y)?c.x:c.y,a=ol(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(){ZA(this.element,this.evEl,this.domHandler),ZA(this.target,this.evTarget,this.domHandler),ZA(el(this.element),this.evWin,this.domHandler)}destroy(){JA(this.element,this.evEl,this.domHandler),JA(this.target,this.evTarget,this.domHandler),JA(el(this.element),this.evWin,this.domHandler)}};const ll={pointerdown:jA.Start,pointermove:jA.Move,pointerup:jA.End,pointercancel:jA.Cancel,pointerout:jA.Cancel};class cl extends Al{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=ll[e.type],i=e.pointerType,s="touch"===i;let o=t.findIndex(t=>t.pointerId===e.pointerId);r&jA.Start&&(e.buttons||s)?o<0&&(t.push(e),o=t.length-1):r&(jA.End|jA.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 ul=["","webkit","Moz","MS","ms","o"];function hl(e,t){const n=t[0].toUpperCase()+t.slice(1);for(const r of ul){const i=r?r+n:t;if(i in e)return i}}const dl={touchAction:"compute",enable:!0,inputTarget:null,cssProps:{userSelect:"none",userDrag:"none",touchCallout:"none",tapHighlightColor:"rgba(0,0,0,0)"}};class fl{constructor(e,t){this.options={...dl,...t,cssProps:{...dl.cssProps,...t.cssProps},inputTarget:t.inputTarget||e},this.handlers={},this.session={},this.recognizers=[],this.oldCssProps={},this.element=e,this.input=new cl(this),this.touchAction=new qA(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&WA.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=WA.Ended&&this.manager.emit(this.options.event+gl(t),e)}tryEmit(e){this.canEmit()?this.emit(e):this.state=WA.Failed}canEmit(){let e=0;for(;e{this.state=WA.Recognized,this.tryEmit(this._input)},t.interval),WA.Began):WA.Recognized}return WA.Failed}failTimeout(){return this._timer=setTimeout(()=>{this.state=WA.Failed},this.options.interval),WA.Failed}reset(){clearTimeout(this._timer)}emit(e){this.state===WA.Recognized&&(e.tapCount=this.count,this.manager.emit(this.options.event,e))}}const vl=["","start","move","end","cancel","up","down","left","right"];class yl extends _l{constructor(e={}){super({enable:!0,pointers:1,event:"pan",threshold:10,direction:zA.All,...e}),this.pX=null,this.pY=null}getTouchAction(){const{options:{direction:e}}=this,t=[];return e&zA.Horizontal&&t.push(YA),e&zA.Vertical&&t.push(QA),t}getEventNames(){return vl.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&zA.Horizontal?(i=0===s?zA.None:s<0?zA.Left:zA.Right,n=s!==this.pX,r=Math.abs(e.deltaX)):(i=0===o?zA.None:o<0?zA.Up:zA.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&WA.Began)||!(this.state&WA.Began)&&this.directionTest(e))}emit(e){this.pX=e.deltaX,this.pY=e.deltaY;const t=zA[e.direction].toLowerCase();t&&(e.additionalEvent=this.options.event+t),super.emit(e)}}const wl=["","start","move","end","cancel","in","out"];class xl{constructor(e,t,n){this.element=e,this.callback=t,this.options=n}}const El=-1!==("undefined"!=typeof navigator&&navigator.userAgent?navigator.userAgent.toLowerCase():"").indexOf("firefox"),Tl=4.000244140625;class Sl extends xl{constructor(e,t,n){super(e,t,{enable:!0,...n}),this.handleEvent=e=>{if(!this.options.enable)return;let t=e.deltaY;globalThis.WheelEvent&&(El&&e.deltaMode===globalThis.WheelEvent.DOM_DELTA_PIXEL&&(t/=globalThis.devicePixelRatio),e.deltaMode===globalThis.WheelEvent.DOM_DELTA_LINE&&(t*=40)),0!==t&&t%Tl===0&&(t=Math.floor(t/Tl)),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 Cl=["mousedown","mousemove","mouseup","mouseover","mouseout","mouseleave"];class kl extends xl{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,Cl.forEach(t=>e.addEventListener(t,this.handleEvent))}destroy(){Cl.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 Rl=["keydown","keyup"];class Pl extends xl{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",Rl.forEach(t=>e.addEventListener(t,this.handleEvent))}destroy(){Rl.forEach(e=>this.element.removeEventListener(e,this.handleEvent))}enableEventType(e,t){"keydown"===e&&(this.enableDownEvent=t),"keyup"===e&&(this.enableUpEvent=t)}}class Il extends xl{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 Ml={pointerdown:1,pointermove:2,pointerup:4,mousedown:1,mousemove:2,mouseup:4};function Ll(e){const t=Ml[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 Nl(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 Bl={srcElement:"root",priority:0};class Dl{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={...Bl,...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 Ol(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 Fl{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 fl(e,this.options);for(const e of this.options.recognizers){const{recognizer:t,recognizeWith:n,requireFailure:r}=Ol(e);this.manager.add(t),n&&t.recognizeWith(n),r&&t.requireFailure(r)}this.manager.on("hammer.input",this._onBasicInput),this.wheelInput=new Sl(e,this._onOtherEvent,{enable:!1}),this.moveInput=new kl(e,this._onOtherEvent,{enable:!1}),this.keyInput=new Pl(e,this._onOtherEvent,{enable:!1,tabIndex:t.tabIndex}),this.contextmenuInput=new Il(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 Dl(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 Ul={DEFAULT:-1,LNGLAT:1,METER_OFFSETS:2,LNGLAT_OFFSETS:3,CARTESIAN:0};Object.defineProperty(Ul,"IDENTITY",{get:()=>(Hn.deprecated("COORDINATE_SYSTEM.IDENTITY","COORDINATE_SYSTEM.CARTESIAN")(),0)});const jl={WEB_MERCATOR:1,GLOBE:2,WEB_MERCATOR_AUTO_OFFSET:4,IDENTITY:0},Gl={common:0,meters:1,pixels:2},zl={click:"onClick",dblclick:"onClick",panstart:"onDragStart",panmove:"onDrag",panend:"onDragEnd"},Vl={multipan:[yl,{threshold:10,direction:zA.Vertical,pointers:2}],pinch:[class extends _l{constructor(e={}){super({enable:!0,event:"pinch",threshold:0,pointers:2,...e})}getTouchAction(){return[XA]}getEventNames(){return wl.map(e=>this.options.event+e)}attrTest(e){return super.attrTest(e)&&(Math.abs(e.scale-1)>this.options.threshold||Boolean(this.state&WA.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:[yl,{threshold:1},["pinch"],["multipan"]],dblclick:[bl,{event:"dblclick",taps:2}],click:[bl,{event:"click"},null,["dblclick"]]};function Wl(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(!Wl(r[i],n[i])){t=e(r),n=r;break}return t}}const $l=[0,0,0,0],Xl=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0],Ql=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],Yl=[0,0,0],ql=[0,0,0],Kl=Hl(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=$l,A=$l,l=e.cameraPosition;const{geospatialOrigin:c,shaderCoordinateOrigin:u,offsetMode:h}=Zl(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=lA([],A,o),s=r||s,o=rA([],i,s),o=rA([],o,Xl)),{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=lA([],[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:Yl,scale:e.scale,wrapLongitude:!1,viewProjectionMatrix:s,modelMatrix:Ql,cameraPosition:a};if(l){const t=e.getDistanceScales(l);switch(n){case Ul.METER_OFFSETS:d.commonUnitsPerWorldUnit=t.unitsPerMeter,d.commonUnitsPerWorldUnit2=t.unitsPerMeter2;break;case Ul.LNGLAT:case Ul.LNGLAT_OFFSETS:e._pseudoMeters||(d.commonUnitsPerMeter=t.unitsPerMeter),d.commonUnitsPerWorldUnit=t.unitsPerDegree,d.commonUnitsPerWorldUnit2=t.unitsPerDegree2;break;case Ul.CARTESIAN:d.commonUnitsPerWorldUnit=[1,1,t.unitsPerMeter[2]],d.commonUnitsPerWorldUnit2=[0,0,t.unitsPerMeter2[2]]}}return d});function Zl(e,t,n=ql){n.length<3&&(n=[n[0],n[1],0]);let r,i=n,s=!0;switch(r=t===Ul.LNGLAT_OFFSETS||t===Ul.METER_OFFSETS?n:e.isGeospatial?[Math.fround(e.longitude),Math.fround(e.latitude),0]:null,e.projectionMode){case jl.WEB_MERCATOR:t!==Ul.LNGLAT&&t!==Ul.CARTESIAN||(r=[0,0,0],s=!1);break;case jl.WEB_MERCATOR_AUTO_OFFSET:t===Ul.LNGLAT?i=r:t===Ul.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 jl.IDENTITY:i=e.position.map(Math.fround),i[2]=i[2]||0;break;case jl.GLOBE:s=!1,r=null;break;default:s=!1}return{geospatialOrigin:r,shaderCoordinateOrigin:i,offsetMode:s}}const Jl=`${Object.keys(Ul).map(e=>`const COORDINATE_SYSTEM_${e}: i32 = ${Ul[e]};`).join("")}\n${Object.keys(jl).map(e=>`const PROJECTION_MODE_${e}: i32 = ${jl[e]};`).join("")}\n${Object.keys(Gl).map(e=>`const UNIT_${e.toUpperCase()}: i32 = ${Gl[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