@pexip/media-processor 22.2.0 → 22.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +34 -0
  3. package/api-docs/README.mdx +37 -0
  4. package/api-docs/interfaces/ProcessorEvent.mdx +1 -0
  5. package/api-docs/interfaces/ProcessorOptions.mdx +10 -9
  6. package/api-docs/interfaces/ProcessorUpdateOptions.mdx +10 -9
  7. package/api-docs/interfaces/SegmenterOptions.mdx +7 -6
  8. package/api-docs/interfaces/TensorMetadata.mdx +11 -0
  9. package/api-docs/type-aliases/TensorLayout.mdx +3 -0
  10. package/api-docs/variables/getTensorMetadata.mdx +14 -0
  11. package/dist/common/backends/canvas2d/postprocessor.d.ts +30 -0
  12. package/dist/common/backends/canvas2d/postprocessor.js +88 -0
  13. package/dist/common/backends/canvas2d/preprocessor.d.ts +56 -0
  14. package/dist/common/backends/canvas2d/preprocessor.js +139 -0
  15. package/dist/common/backends/webgpu/renderer.js +1 -0
  16. package/dist/common/backends/webgpu/webgpuUtils.d.ts +35 -0
  17. package/dist/common/backends/webgpu/webgpuUtils.js +84 -2
  18. package/dist/common/inferencer.d.ts +12 -3
  19. package/dist/common/inferencer.js +60 -14
  20. package/dist/common/tsconfig.tsbuildinfo +1 -1
  21. package/dist/common/types/processor.d.ts +1 -0
  22. package/dist/common/types/segmentation.d.ts +8 -0
  23. package/dist/common/utils.d.ts +12 -0
  24. package/dist/common/utils.js +43 -0
  25. package/dist/main/tsconfig.tsbuildinfo +1 -1
  26. package/dist/main/video/segmenter.d.ts +4 -2
  27. package/dist/main/video/segmenter.js +36 -11
  28. package/dist/main/video/video.js +10 -0
  29. package/dist/workers/mediaWorker.js +23 -23
  30. package/dist/workers/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +3 -3
@@ -1,18 +1,18 @@
1
- var Pr=typeof self<"u"?self:{};function $c(t,e){t=t.split(".");var r,n=Pr;for((t[0]in n)||n.execScript===void 0||n.execScript("var "+t[0]);t.length&&(r=t.shift());)t.length||e===void 0?n=n[r]&&n[r]!==Object.prototype[r]?n[r]:n[r]={}:n[r]=e}function Fr(){throw Error("Invalid UTF8")}function Su(t,e){return e=String.fromCharCode.apply(null,e),t==null?e:t+e}var us,Xo,od=typeof TextDecoder<"u",ad,id=typeof TextEncoder<"u";function zc(t){if(id)t=(ad||(ad=new TextEncoder)).encode(t);else{let r=0,n=new Uint8Array(3*t.length);for(let s=0;s<t.length;s++){var e=t.charCodeAt(s);if(e<128)n[r++]=e;else{if(e<2048)n[r++]=e>>6|192;else{if(e>=55296&&e<=57343){if(e<=56319&&s<t.length){let o=t.charCodeAt(++s);if(o>=56320&&o<=57343){e=1024*(e-55296)+o-56320+65536,n[r++]=e>>18|240,n[r++]=e>>12&63|128,n[r++]=e>>6&63|128,n[r++]=63&e|128;continue}s--}e=65533}n[r++]=e>>12|224,n[r++]=e>>6&63|128}n[r++]=63&e|128}}t=r===n.length?n:n.subarray(0,r)}return t}var Ra,vs;e:{for(jo=["CLOSURE_FLAGS"],cs=Pr,ls=0;ls<jo.length;ls++)if((cs=cs[jo[ls]])==null){vs=null;break e}vs=cs}var jo,cs,ls,Gn,Cu=vs&&vs[610401301];Ra=Cu!=null&&Cu;var Fu=Pr.navigator;function aa(t){return!!Ra&&!!Gn&&Gn.brands.some((({brand:e})=>e&&e.indexOf(t)!=-1))}function vt(t){var e;return(e=Pr.navigator)&&(e=e.userAgent)||(e=""),e.indexOf(t)!=-1}function dr(){return!!Ra&&!!Gn&&Gn.brands.length>0}function Yo(){return dr()?aa("Chromium"):(vt("Chrome")||vt("CriOS"))&&!(!dr()&&vt("Edge"))||vt("Silk")}function Ia(t){return Ia[" "](t),t}Gn=Fu&&Fu.userAgentData||null,Ia[" "]=function(){};var ud=!dr()&&(vt("Trident")||vt("MSIE"));!vt("Android")||Yo(),Yo(),vt("Safari")&&(Yo()||!dr()&&vt("Coast")||!dr()&&vt("Opera")||!dr()&&vt("Edge")||(dr()?aa("Microsoft Edge"):vt("Edg/"))||dr()&&aa("Opera"));var Hc={},Ln=null;function cd(t){let e=t.length,r=3*e/4;r%3?r=Math.floor(r):"=.".indexOf(t[e-1])!=-1&&(r="=.".indexOf(t[e-2])!=-1?r-2:r-1);let n=new Uint8Array(r),s=0;return(function(o,a){function i(l){for(;u<o.length;){let c=o.charAt(u++),f=Ln[c];if(f!=null)return f;if(!/^[\s\xa0]*$/.test(c))throw Error("Unknown base64 encoding at char: "+c)}return l}Xc();let u=0;for(;;){let l=i(-1),c=i(0),f=i(64),d=i(64);if(d===64&&l===-1)break;a(l<<2|c>>4),f!=64&&(a(c<<4&240|f>>2),d!=64&&a(f<<6&192|d))}})(t,(function(o){n[s++]=o})),s!==r?n.subarray(0,s):n}function Xc(){if(!Ln){Ln={};var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"];for(let r=0;r<5;r++){let n=t.concat(e[r].split(""));Hc[r]=n;for(let s=0;s<n.length;s++){let o=n[s];Ln[o]===void 0&&(Ln[o]=s)}}}}var jc=typeof Uint8Array<"u",Yc=!ud&&typeof btoa=="function";function Uu(t){if(!Yc){var e;e===void 0&&(e=0),Xc(),e=Hc[e];var r=Array(Math.floor(t.length/3)),n=e[64]||"";let u=0,l=0;for(;u<t.length-2;u+=3){var s=t[u],o=t[u+1],a=t[u+2],i=e[s>>2];s=e[(3&s)<<4|o>>4],o=e[(15&o)<<2|a>>6],a=e[63&a],r[l++]=i+s+o+a}switch(i=0,a=n,t.length-u){case 2:a=e[(15&(i=t[u+1]))<<2]||n;case 1:t=t[u],r[l]=e[t>>2]+e[(3&t)<<4|i>>4]+a+n}return r.join("")}for(e="",r=0,n=t.length-10240;r<n;)e+=String.fromCharCode.apply(null,t.subarray(r,r+=10240));return e+=String.fromCharCode.apply(null,r?t.subarray(r):t),btoa(e)}var Bu=/[-_.]/g,ld={"-":"+",_:"/",".":"="};function fd(t){return ld[t]||""}function qc(t){if(!Yc)return cd(t);Bu.test(t)&&(t=t.replace(Bu,fd)),t=atob(t);let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}function Hn(t){return jc&&t!=null&&t instanceof Uint8Array}var Jr={};function Or(){return hd||(hd=new nr(null,Jr))}function Sa(t){Kc(Jr);var e=t.g;return(e=e==null||Hn(e)?e:typeof e=="string"?qc(e):null)==null?e:t.g=e}var nr=class{h(){return new Uint8Array(Sa(this)||0)}constructor(t,e){if(Kc(e),this.g=t,t!=null&&t.length===0)throw Error("ByteString should be constructed with non-empty values")}},hd,dd;function Kc(t){if(t!==Jr)throw Error("illegal external caller")}function Zc(t,e){t.__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity=e}function Jc(){let t=Error();Zc(t,"incident"),(function(e){Pr.setTimeout((()=>{throw e}),0)})(t)}function ia(t){return Zc(t=Error(t),"warning"),t}function Ca(){return typeof BigInt=="function"}function ct(t){return Array.prototype.slice.call(t)}var an=typeof Symbol=="function"&&typeof Symbol()=="symbol";function Us(t){return typeof Symbol=="function"&&typeof Symbol()=="symbol"?Symbol():t}var Xn=Us(),Lu=Us("0di"),qo=Us("2ex"),Sn=Us("1oa"),Bs=an?(t,e)=>{t[Xn]|=e}:(t,e)=>{t.G!==void 0?t.G|=e:Object.defineProperties(t,{G:{value:e,configurable:!0,writable:!0,enumerable:!1}})},ua=an?(t,e)=>{t[Xn]&=~e}:(t,e)=>{t.G!==void 0&&(t.G&=~e)},Se=an?t=>0|t[Xn]:t=>0|t.G,oe=an?t=>t[Xn]:t=>t.G,Be=an?(t,e)=>{t[Xn]=e}:(t,e)=>{t.G!==void 0?t.G=e:Object.defineProperties(t,{G:{value:e,configurable:!0,writable:!0,enumerable:!1}})};function un(t){return Bs(t,34),t}function md(t,e){Be(e,-30975&(0|t))}function ca(t,e){Be(e,-30941&(34|t))}var Fa,jn={},Qc={};function Pu(t){return!(!t||typeof t!="object"||t.Ia!==Qc)}function Ua(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)&&t.constructor===Object}function Ba(t,e){if(t!=null){if(typeof t=="string")t=t?new nr(t,Jr):Or();else if(t.constructor!==nr)if(Hn(t))t=t.length?new nr(new Uint8Array(t),Jr):Or();else{if(!e)throw Error();t=void 0}}return t}function ws(t){return!(!Array.isArray(t)||t.length)&&!!(1&Se(t))}var Ou=[];function Tr(t){if(2&t)throw Error()}Be(Ou,55),Fa=Object.freeze(Ou);var Ts=class t{constructor(e,r,n){this.l=0,this.g=e,this.h=r,this.m=n}next(){if(this.l<this.g.length){let e=this.g[this.l++];return{done:!1,value:this.h?this.h.call(this.m,e):e}}return{done:!0,value:void 0}}[Symbol.iterator](){return new t(this.g,this.h,this.m)}},pr;function el(t,e){(e=pr?e[pr]:void 0)&&(t[pr]=ct(e))}var pd=Object.freeze({});function Ls(t){return t.Pa=!0,t}var gd=Ls((t=>typeof t=="number")),Du=Ls((t=>typeof t=="string")),xd=Ls((t=>typeof t=="boolean")),Ps=typeof Pr.BigInt=="function"&&typeof Pr.BigInt(0)=="bigint",la=Ls((t=>Ps?t>=_d&&t<=vd:t[0]==="-"?Mu(t,yd):Mu(t,bd))),yd=Number.MIN_SAFE_INTEGER.toString(),_d=Ps?BigInt(Number.MIN_SAFE_INTEGER):void 0,bd=Number.MAX_SAFE_INTEGER.toString(),vd=Ps?BigInt(Number.MAX_SAFE_INTEGER):void 0;function Mu(t,e){if(t.length>e.length)return!1;if(t.length<e.length||t===e)return!0;for(let r=0;r<t.length;r++){let n=t[r],s=e[r];if(n>s)return!1;if(n<s)return!0}}var wd=typeof Uint8Array.prototype.slice=="function",tl,ie=0,ve=0;function Nu(t){let e=t>>>0;ie=e,ve=(t-e)/4294967296>>>0}function Qr(t){if(t<0){Nu(-t);let[e,r]=Da(ie,ve);ie=e>>>0,ve=r>>>0}else Nu(t)}function La(t){let e=tl||(tl=new DataView(new ArrayBuffer(8)));e.setFloat32(0,+t,!0),ve=0,ie=e.getUint32(0,!0)}function Pa(t,e){let r=4294967296*e+(t>>>0);return Number.isSafeInteger(r)?r:Vn(t,e)}function Oa(t,e){let r=2147483648&e;return r&&(e=~e>>>0,(t=1+~t>>>0)==0&&(e=e+1>>>0)),typeof(t=Pa(t,e))=="number"?r?-t:t:r?"-"+t:t}function Vn(t,e){if(t>>>=0,(e>>>=0)<=2097151)var r=""+(4294967296*e+t);else Ca()?r=""+(BigInt(e)<<BigInt(32)|BigInt(t)):(t=(16777215&t)+6777216*(r=16777215&(t>>>24|e<<8))+6710656*(e=e>>16&65535),r+=8147497*e,e*=2,t>=1e7&&(r+=t/1e7>>>0,t%=1e7),r>=1e7&&(e+=r/1e7>>>0,r%=1e7),r=e+Gu(r)+Gu(t));return r}function Gu(t){return t=String(t),"0000000".slice(t.length)+t}function Os(t){if(t.length<16)Qr(Number(t));else if(Ca())t=BigInt(t),ie=Number(t&BigInt(4294967295))>>>0,ve=Number(t>>BigInt(32)&BigInt(4294967295));else{let e=+(t[0]==="-");ve=ie=0;let r=t.length;for(let n=e,s=(r-e)%6+e;s<=r;n=s,s+=6){let o=Number(t.slice(n,s));ve*=1e6,ie=1e6*ie+o,ie>=4294967296&&(ve+=Math.trunc(ie/4294967296),ve>>>=0,ie>>>=0)}if(e){let[n,s]=Da(ie,ve);ie=n,ve=s}}}function Da(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function kr(t){return t==null||typeof t=="number"?t:t==="NaN"||t==="Infinity"||t==="-Infinity"?Number(t):void 0}function rl(t){return t==null||typeof t=="boolean"?t:typeof t=="number"?!!t:void 0}var Td=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function Ds(t){let e=typeof t;switch(e){case"bigint":return!0;case"number":return Number.isFinite(t)}return e==="string"&&Td.test(t)}function cn(t){if(t==null)return t;if(typeof t=="string"){if(!t)return;t=+t}return typeof t=="number"&&Number.isFinite(t)?0|t:void 0}function nl(t){if(t==null)return t;if(typeof t=="string"){if(!t)return;t=+t}return typeof t=="number"&&Number.isFinite(t)?t>>>0:void 0}function Vu(t){return t[0]!=="-"&&(t.length<20||t.length===20&&Number(t.substring(0,6))<184467)}function Ma(t){return t=Math.trunc(t),Number.isSafeInteger(t)||(Qr(t),t=Oa(ie,ve)),t}function Na(t){var e=Math.trunc(Number(t));if(Number.isSafeInteger(e))return String(e);if((e=t.indexOf("."))!==-1&&(t=t.substring(0,e)),!(t[0]==="-"?t.length<20||t.length===20&&Number(t.substring(0,7))>-922337:t.length<19||t.length===19&&Number(t.substring(0,6))<922337))if(Os(t),t=ie,2147483648&(e=ve))if(Ca())t=""+(BigInt(0|e)<<BigInt(32)|BigInt(t>>>0));else{let[r,n]=Da(t,e);t="-"+Vn(r,n)}else t=Vn(t,e);return t}function ks(t){return t==null?t:typeof t=="bigint"?(la(t)?t=Number(t):(t=BigInt.asIntN(64,t),t=la(t)?Number(t):String(t)),t):Ds(t)?typeof t=="number"?Ma(t):Na(t):void 0}function kd(t){if(t==null)return t;var e=typeof t;if(e==="bigint")return String(BigInt.asUintN(64,t));if(Ds(t)){if(e==="string")return e=Math.trunc(Number(t)),Number.isSafeInteger(e)&&e>=0?t=String(e):((e=t.indexOf("."))!==-1&&(t=t.substring(0,e)),Vu(t)||(Os(t),t=Vn(ie,ve))),t;if(e==="number")return(t=Math.trunc(t))>=0&&Number.isSafeInteger(t)?t:(function(r){if(r<0){Qr(r);var n=Vn(ie,ve);return r=Number(n),Number.isSafeInteger(r)?r:n}return Vu(n=String(r))?n:(Qr(r),Pa(ie,ve))})(t)}}function sl(t){if(typeof t!="string")throw Error();return t}function ln(t){if(t!=null&&typeof t!="string")throw Error();return t}function gr(t){return t==null||typeof t=="string"?t:void 0}function Ga(t,e,r,n){if(t!=null&&typeof t=="object"&&t.X===jn)return t;if(!Array.isArray(t))return r?2&n?(t=e[Lu])?e=t:(un((t=new e).u),e=e[Lu]=t):e=new e:e=void 0,e;let s=r=Se(t);return s===0&&(s|=32&n),s|=2&n,s!==r&&Be(t,s),new e(t)}function Ed(t,e,r){if(e)e:{if(!Ds(e=t))throw ia("int64");switch(typeof e){case"string":e=Na(e);break e;case"bigint":if(t=e=BigInt.asIntN(64,e),Du(t)){if(!/^\s*(?:-?[1-9]\d*|0)?\s*$/.test(t))throw Error(String(t))}else if(gd(t)&&!Number.isSafeInteger(t))throw Error(String(t));e=Ps?BigInt(e):xd(e)?e?"1":"0":Du(e)?e.trim()||"0":String(e);break e;default:e=Ma(e)}}else e=ks(t);return typeof(r=(t=e)==null?r?0:void 0:t)=="string"&&(e=+r,Number.isSafeInteger(e))?e:r}function ol(t){var e;return Cn===void 0&&(Cn=typeof Proxy=="function"?Wu(Proxy):null),(e=!Cn)||(Fn===void 0&&(Fn=typeof WeakMap=="function"?Wu(WeakMap):null),e=!Fn),e?t:(e=en?.get(t))?e:Math.random()>.01?t:((function(r){if(Ko===void 0){let n=new Cn([],{});Ko=Array.prototype.concat.call([],n).length===1}Ko&&typeof Symbol=="function"&&Symbol.isConcatSpreadable&&(r[Symbol.isConcatSpreadable]=!0)})(t),(function(r,n){(en||(en=new Fn)).set(r,n),(al||(al=new Fn)).set(n,r)})(t,e=new Cn(t,{set:(r,n,s)=>(Jc(),r[n]=s,!0)})),e)}var en,al,Cn,Fn,Ko,Es,il,Ad;function Wu(t){try{return t.toString().indexOf("[native code]")!==-1?t:null}catch{return null}}function xr(t,e,r){return t=ul(t,e[0],e[1],r?1:2),e!==il&&r&&Bs(t,16384),t}function ul(t,e,r,n){if(n=n??0,t==null&&(t=Es),Es=void 0,t==null){var s=96;r?(t=[r],s|=512):t=[],e&&(s=-33521665&s|(1023&e)<<15)}else{if(!Array.isArray(t))throw Error("narr");if(2048&(s=Se(t)))throw Error("farr");if(64&s)return t;if(n===1||n===2||(s|=64),r&&(s|=512,r!==t[0]))throw Error("mid");e:{if(n=(r=t).length){let o=n-1;if(Ua(r[o])){if((e=o-(+!!(512&(s|=256))-1))>=1024)throw Error("pvtlmt");s=-33521665&s|(1023&e)<<15;break e}}if(e){if((e=Math.max(e,n-(+!!(512&s)-1)))>1024)throw Error("spvt");s=-33521665&s|(1023&e)<<15}}}return Be(t,s),t}var Rd={},Id=(function(){try{return Ia(new class extends Map{constructor(){super()}}),!1}catch{return!0}})(),On=class{constructor(){this.g=new Map}get(e){return this.g.get(e)}set(e,r){return this.g.set(e,r),this.size=this.g.size,this}delete(e){return e=this.g.delete(e),this.size=this.g.size,e}clear(){this.g.clear(),this.size=this.g.size}has(e){return this.g.has(e)}entries(){return this.g.entries()}keys(){return this.g.keys()}values(){return this.g.values()}forEach(e,r){return this.g.forEach(e,r)}[Symbol.iterator](){return this.entries()}},Sd=Id?(Object.setPrototypeOf(On.prototype,Map.prototype),Object.defineProperties(On.prototype,{size:{value:0,configurable:!0,enumerable:!0,writable:!0}}),On):class extends Map{constructor(){super()}};function $u(t){return t}function Zo(t){if(2&t.M)throw Error("Cannot mutate an immutable Map")}var Tt=class extends Sd{constructor(t,e,r=$u,n=$u){super();let s=Se(t);s|=64,Be(t,s),this.M=s,this.T=e,this.S=r,this.Z=this.T?Cd:n;for(let o=0;o<t.length;o++){let a=t[o],i=r(a[0],!1,!0),u=a[1];e?u===void 0&&(u=null):u=n(a[1],!1,!0,void 0,void 0,s),super.set(i,u)}}oa(t=zu){if(this.size!==0)return this.Y(t)}Y(t=zu){let e=[],r=super.entries();for(var n;!(n=r.next()).done;)(n=n.value)[0]=t(n[0]),n[1]=t(n[1]),e.push(n);return e}clear(){Zo(this),super.clear()}delete(t){return Zo(this),super.delete(this.S(t,!0,!1))}entries(){var t=this.na();return new Ts(t,Fd,this)}keys(){return this.Ha()}values(){var t=this.na();return new Ts(t,Tt.prototype.get,this)}forEach(t,e){super.forEach(((r,n)=>{t.call(e,this.get(n),n,this)}))}set(t,e){return Zo(this),(t=this.S(t,!0,!1))==null?this:e==null?(super.delete(t),this):super.set(t,this.Z(e,!0,!0,this.T,!1,this.M))}Na(t){let e=this.S(t[0],!1,!0);t=t[1],t=this.T?t===void 0?null:t:this.Z(t,!1,!0,void 0,!1,this.M),super.set(e,t)}has(t){return super.has(this.S(t,!1,!1))}get(t){t=this.S(t,!1,!1);let e=super.get(t);if(e!==void 0){var r=this.T;return r?((r=this.Z(e,!1,!0,r,this.sa,this.M))!==e&&super.set(t,r),r):e}}na(){return Array.from(super.keys())}Ha(){return super.keys()}[Symbol.iterator](){return this.entries()}};function Cd(t,e,r,n,s,o){return t=Ga(t,n,r,o),s&&(t=Ns(t)),t}function zu(t){return t}function Fd(t){return[t,this.get(t)]}var Ud;function Hu(){return Ud||(Ud=new Tt(un([]),void 0,void 0,void 0,Rd))}function Va(t,e,r,n,s){if(t!=null){if(Array.isArray(t))t=ws(t)?void 0:s&&2&Se(t)?t:Ms(t,e,r,n!==void 0,s);else if(Ua(t)){let o={};for(let a in t)o[a]=Va(t[a],e,r,n,s);t=o}else t=e(t,n);return t}}function Ms(t,e,r,n,s){let o=n||r?Se(t):0;n=n?!!(32&o):void 0;let a=ct(t);for(let i=0;i<a.length;i++)a[i]=Va(a[i],e,r,n,s);return r&&(el(a,t),r(o,a)),a}function Bd(t){return Va(t,Wa,void 0,void 0,!1)}function Wa(t){return t.X===jn?t.toJSON():t instanceof Tt?t.oa(Bd):(function(e){switch(typeof e){case"number":return isFinite(e)?e:String(e);case"bigint":return la(e)?Number(e):String(e);case"boolean":return e?1:0;case"object":if(e)if(Array.isArray(e)){if(ws(e))return}else{if(Hn(e))return Uu(e);if(e instanceof nr){let r=e.g;return r==null?"":typeof r=="string"?r:e.g=Uu(r)}if(e instanceof Tt)return e.oa()}}return e})(t)}function fa(t,e,r=ca){if(t!=null){if(jc&&t instanceof Uint8Array)return e?t:new Uint8Array(t);if(Array.isArray(t)){var n=Se(t);return 2&n?t:(e&&(e=n===0||!!(32&n)&&!(64&n||!(16&n))),e?(Be(t,-12293&(34|n)),t):Ms(t,fa,4&n?ca:r,!0,!0))}return t.X===jn?(r=t.u,t=2&(n=oe(r))?t:$a(t,r,n,!0)):t instanceof Tt&&!(2&t.M)&&(r=un(t.Y(fa)),t=new Tt(r,t.T,t.S,t.Z)),t}}function $a(t,e,r,n){return t=t.constructor,Es=e=cl(e,r,n),e=new t(e),Es=void 0,e}function cl(t,e,r){let n=r||2&e?ca:md,s=!!(32&e);return t=(function(o,a,i){let u=ct(o);var l=u.length;let c=256&a?u[l-1]:void 0;for(l+=c?-1:0,a=512&a?1:0;a<l;a++)u[a]=i(u[a]);if(c){a=u[a]={};for(let f in c)a[f]=i(c[f])}return el(u,o),u})(t,e,(o=>fa(o,s,n))),Bs(t,32|(r?2:0)),t}function Ns(t){let e=t.u,r=oe(e);return 2&r?$a(t,e,r,!1):t}function _r(t,e){return ir(t=t.u,oe(t),e)}function Xu(t,e,r,n){if(!((e=n+(+!!(512&e)-1))<0||e>=t.length||e>=r))return t[e]}function ir(t,e,r,n){if(r===-1)return null;let s=e>>15&1023||536870912;if(!(r>=s)){var o=t.length;return n&&256&e&&(n=t[o-1][r])!=null?(Xu(t,e,s,r)&&qo!=null&&((e=(t=dd??(dd={}))[qo]||0)>=4||(t[qo]=e+1,Jc())),n):Xu(t,e,s,r)}return 256&e?t[t.length-1][r]:void 0}function ue(t,e,r){let n=t.u,s=oe(n);return Tr(s),ye(n,s,e,r),t}function ye(t,e,r,n){let s=e>>15&1023||536870912;if(r>=s){let o,a=e;if(256&e)o=t[t.length-1];else{if(n==null)return a;o=t[s+(+!!(512&e)-1)]={},a|=256}return o[r]=n,r<s&&(t[r+(+!!(512&e)-1)]=void 0),a!==e&&Be(t,a),a}return t[r+(+!!(512&e)-1)]=n,256&e&&r in(t=t[t.length-1])&&delete t[r],e}function ps(t,e){t=t.u;let r=oe(t),n=ir(t,r,e),s=kr(n);return s!=null&&s!==n&&ye(t,r,e,s),s}function ll(t){t=t.u;let e=oe(t),r=ir(t,e,1),n=Ba(r,!0);return n!=null&&n!==r&&ye(t,e,1,n),n}function Ur(){return pd===void 0?2:4}function Br(t,e,r,n,s){let o=t.u,a=2&(t=oe(o))?1:n;s=!!s,n=za(o,t,e);var i=Se(n);if(!(4&i)){4&i&&(n=ct(n),i=sr(i,t),t=ye(o,t,e,n));let l=0,c=0;for(;l<n.length;l++){let f=r(n[l]);f!=null&&(n[c++]=f)}c<l&&(n.length=c),i=-4097&(20|(i=Ha(i,t))),Be(n,i&=-8193),2&i&&Object.freeze(n)}let u;return a===1||a===4&&32&i?Ut(i)||(s=i,(i|=2)!==s&&Be(n,i),Object.freeze(n)):(r=a===5&&(!!(32&i)||Ut(i)||!!en?.get(n)),(a===2||r)&&Ut(i)&&(n=ct(n),i=yr(i=sr(i,t),t,s),Be(n,i),t=ye(o,t,e,n)),Ut(i)||(e=i,(i=yr(i,t,s))!==e&&Be(n,i)),r?u=ol(n):a!==2||s||en?.delete(n)),u||n}function za(t,e,r,n){return t=ir(t,e,r,n),Array.isArray(t)?t:Fa}function Ha(t,e){return t===0&&(t=sr(t,e)),1|t}function Ut(t){return!!(2&t)&&!!(4&t)||!!(2048&t)}function fl(t){t=ct(t);for(let e=0;e<t.length;e++){let r=t[e]=ct(t[e]);Array.isArray(r[1])&&(r[1]=un(r[1]))}return t}function ha(t,e,r,n){t=t.u;let s=oe(t);Tr(s),ye(t,s,e,(n==="0"?Number(r)===0:r===n)?void 0:r)}function fn(t,e,r,n,s){Tr(e);var o=!(!(64&e)&&16384&e);let a=(s=za(t,e,r,s))!==Fa;if(o||!a){let i=o=a?Se(s):0;(!a||2&i||Ut(i)||4&i&&!(32&i))&&(s=ct(s),i=sr(i,e),e=ye(t,e,r,s)),i=-13&Ha(i,e),i=yr(n?-17&i:16|i,e,!0),i!==o&&Be(s,i)}return s}function Jo(t,e){var r=ef;return ja(Xa(t=t.u),t,oe(t),r)===e?e:-1}function Xa(t){if(an)return t[Sn]??(t[Sn]=new Map);if(Sn in t)return t[Sn];let e=new Map;return Object.defineProperty(t,Sn,{value:e}),e}function hl(t,e,r,n){let s=Xa(t),o=ja(s,t,e,r);return o!==n&&(o&&(e=ye(t,e,o)),s.set(r,n)),e}function ja(t,e,r,n){let s=t.get(n);if(s!=null)return s;s=0;for(let o=0;o<n.length;o++){let a=n[o];ir(e,r,a)!=null&&(s!==0&&(r=ye(e,r,s)),s=a)}return t.set(n,s),s}function Ya(t,e,r,n){let s,o=oe(t);if((n=ir(t,o,r,n))!=null&&n.X===jn)return(e=Ns(n))!==n&&ye(t,o,r,e),e.u;if(Array.isArray(n)){let a=Se(n);s=2&a?xr(cl(n,a,!1),e,!0):64&a?n:xr(s,e,!0)}else s=xr(void 0,e,!0);return s!==n&&ye(t,o,r,s),s}function dl(t,e,r,n){t=t.u;let s=oe(t);return(e=Ga(n=ir(t,s,r,n),e,!1,s))!==n&&e!=null&&ye(t,s,r,e),e}function q(t,e,r,n=!1){if((e=dl(t,e,r,n))==null)return e;if(t=t.u,!(2&(n=oe(t)))){let s=Ns(e);s!==e&&ye(t,n,r,e=s)}return e}function ml(t,e,r,n,s,o,a){t=t.u;var i=!!(2&e);s=i?1:s,o=!!o,a&&(a=!i),i=za(t,e,n);var u=Se(i),l=!!(4&u);if(!l){var c=i,f=e;let p=!!(2&(u=Ha(u,e)));p&&(f|=2);let T=!p,A=!0,E=0,I=0;for(;E<c.length;E++){let _=Ga(c[E],r,!1,f);if(_ instanceof r){if(!p){let v=!!(2&Se(_.u));T&&(T=!v),A&&(A=v)}c[I++]=_}}I<E&&(c.length=I),u|=4,u=A?16|u:-17&u,Be(c,u=T?8|u:-9&u),p&&Object.freeze(c)}if(a&&!(8&u||!i.length&&(s===1||s===4&&32&u))){for(Ut(u)&&(i=ct(i),u=sr(u,e),e=ye(t,e,n,i)),r=i,a=u,c=0;c<r.length;c++)(u=r[c])!==(f=Ns(u))&&(r[c]=f);a|=8,a=r.length?-17&a:16|a,Be(r,a),u=a}let d;return s===1||s===4&&32&u?Ut(u)||(e=u,(u|=!i.length||16&u&&(!l||32&u)?2:2048)!==e&&Be(i,u),Object.freeze(i)):(l=s===5&&(!!(32&u)||Ut(u)||!!en?.get(i)),(s===2||l)&&Ut(u)&&(i=ct(i),u=yr(u=sr(u,e),e,o),Be(i,u),e=ye(t,e,n,i)),Ut(u)||(n=u,(u=yr(u,e,o))!==n&&Be(i,u)),l?d=ol(i):s!==2||o||en?.delete(i)),d||i}function or(t,e,r){let n=oe(t.u);return ml(t,n,e,r,Ur(),!1,!(2&n))}function z(t,e,r,n){return n==null&&(n=void 0),ue(t,r,n)}function Dn(t,e,r,n){n==null&&(n=void 0);e:{t=t.u;let s=oe(t);if(Tr(s),n==null){let o=Xa(t);if(ja(o,t,s,r)!==e)break e;o.set(r,0)}else s=hl(t,s,r,e);ye(t,s,e,n)}}function sr(t,e){return-2049&(t=32|(2&e?2|t:-3&t))}function yr(t,e,r){return 32&e&&r||(t&=-33),t}function As(t,e,r,n){let s=oe(t.u);Tr(s),t=ml(t,s,r,e,2,!0),n=n??new r,t.push(n),2&Se(n.u)?ua(t,8):ua(t,16)}function Bt(t,e){return t??e}function wt(t,e){return cn(_r(t,e))}function Ie(t,e){return Bt(ps(t,e),0)}function jt(t,e){return Bt(gr(_r(t,e)),"")}function Wn(t,e,r){if(r!=null&&typeof r!="boolean")throw t=typeof r,Error(`Expected boolean but got ${t!="object"?t:r?Array.isArray(r)?"array":t:"null"}: ${r}`);ue(t,e,r)}function Yt(t,e,r){if(r!=null){if(typeof r!="number"||!Number.isFinite(r))throw ia("int32");r|=0}ue(t,e,r)}function W(t,e,r){if(r!=null&&typeof r!="number")throw Error(`Value of float/double field must be a number, found ${typeof r}: ${r}`);ue(t,e,r)}function Rs(t,e,r){{let a=t.u,i=oe(a);if(Tr(i),r==null)ye(a,i,e);else{r=al?.get(r)||r;var n=t=Se(r),s=Ut(t),o=s||Object.isFrozen(r);for(s||(t=0),o||(r=ct(r),n=0,t=yr(t=sr(t,i),i,!0),o=!1),t|=21,s=0;s<r.length;s++){let u=r[s],l=sl(u);Object.is(u,l)||(o&&(r=ct(r),n=0,t=yr(t=sr(t,i),i,!0),o=!1),r[s]=l)}t!==n&&(o&&(r=ct(r),t=yr(t=sr(t,i),i,!0)),Be(r,t)),ye(a,i,e,r)}}}function Gs(t,e,r){Tr(oe(t.u)),Br(t,e,gr,2,!0).push(sl(r))}function pl(t,e){return Error(`Invalid wire type: ${t} (at position ${e})`)}function qa(){return Error("Failed to read varint, encoding is invalid.")}function gl(t,e){return Error(`Tried to read past the end of the data ${e} > ${t}`)}function Ka(t){if(typeof t=="string")return{buffer:qc(t),O:!1};if(Array.isArray(t))return{buffer:new Uint8Array(t),O:!1};if(t.constructor===Uint8Array)return{buffer:t,O:!1};if(t.constructor===ArrayBuffer)return{buffer:new Uint8Array(t),O:!1};if(t.constructor===nr)return{buffer:Sa(t)||new Uint8Array(0),O:!0};if(t instanceof Uint8Array)return{buffer:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),O:!1};throw Error("Type not convertible to a Uint8Array, expected a Uint8Array, an ArrayBuffer, a base64 encoded string, a ByteString or an Array of numbers")}function Za(t,e){let r,n=0,s=0,o=0,a=t.h,i=t.g;do r=a[i++],n|=(127&r)<<o,o+=7;while(o<32&&128&r);for(o>32&&(s|=(127&r)>>4),o=3;o<32&&128&r;o+=7)r=a[i++],s|=(127&r)<<o;if(Lr(t,i),r<128)return e(n>>>0,s>>>0);throw qa()}function Ja(t){let e=0,r=t.g,n=r+10,s=t.h;for(;r<n;){let o=s[r++];if(e|=o,(128&o)==0)return Lr(t,r),!!(127&e)}throw qa()}function br(t){let e=t.h,r=t.g,n=e[r++],s=127&n;if(128&n&&(n=e[r++],s|=(127&n)<<7,128&n&&(n=e[r++],s|=(127&n)<<14,128&n&&(n=e[r++],s|=(127&n)<<21,128&n&&(n=e[r++],s|=n<<28,128&n&&128&e[r++]&&128&e[r++]&&128&e[r++]&&128&e[r++]&&128&e[r++])))))throw qa();return Lr(t,r),s}function ar(t){return br(t)>>>0}function da(t){var e=t.h;let r=t.g,n=e[r],s=e[r+1],o=e[r+2];return e=e[r+3],Lr(t,t.g+4),(n<<0|s<<8|o<<16|e<<24)>>>0}function ma(t){var e=da(t);t=2*(e>>31)+1;let r=e>>>23&255;return e&=8388607,r==255?e?NaN:t*(1/0):r==0?1401298464324817e-60*t*e:t*Math.pow(2,r-150)*(e+8388608)}function Ld(t){return br(t)}function Qo(t,e,{ca:r=!1}={}){t.ca=r,e&&(e=Ka(e),t.h=e.buffer,t.m=e.O,t.j=0,t.l=t.h.length,t.g=t.j)}function Lr(t,e){if(t.g=e,e>t.l)throw gl(t.l,e)}function xl(t,e){if(e<0)throw Error(`Tried to read a negative byte length: ${e}`);let r=t.g,n=r+e;if(n>t.l)throw gl(e,t.l-r);return t.g=n,r}function yl(t,e){if(e==0)return Or();var r=xl(t,e);return t.ca&&t.m?r=t.h.subarray(r,r+e):(t=t.h,r=r===(e=r+e)?new Uint8Array(0):wd?t.slice(r,e):new Uint8Array(t.subarray(r,e))),r.length==0?Or():new nr(r,Jr)}Tt.prototype.toJSON=void 0,Tt.prototype.Ia=Qc;var ju=[];function _l(t){var e=t.g;if(e.g==e.l)return!1;t.l=t.g.g;var r=ar(t.g);if(e=r>>>3,!((r&=7)>=0&&r<=5))throw pl(r,t.l);if(e<1)throw Error(`Invalid field number: ${e} (at position ${t.l})`);return t.m=e,t.h=r,!0}function gs(t){switch(t.h){case 0:t.h!=0?gs(t):Ja(t.g);break;case 1:Lr(t=t.g,t.g+8);break;case 2:if(t.h!=2)gs(t);else{var e=ar(t.g);Lr(t=t.g,t.g+e)}break;case 5:Lr(t=t.g,t.g+4);break;case 3:for(e=t.m;;){if(!_l(t))throw Error("Unmatched start-group tag: stream EOF");if(t.h==4){if(t.m!=e)throw Error("Unmatched end-group tag");break}gs(t)}break;default:throw pl(t.h,t.l)}}function Yn(t,e,r){let n=t.g.l,s=ar(t.g),o=t.g.g+s,a=o-n;if(a<=0&&(t.g.l=o,r(e,t,void 0,void 0,void 0),a=o-t.g.g),a)throw Error(`Message parsing ended unexpectedly. Expected to read ${s} bytes, instead read ${s-a} bytes, either the data ended unexpectedly or the message misreported its own length`);return t.g.g=o,t.g.l=n,e}function Qa(t){var e=ar(t.g),r=xl(t=t.g,e);if(t=t.h,od){var n,s=t;(n=Xo)||(n=Xo=new TextDecoder("utf-8",{fatal:!0})),e=r+e,s=r===0&&e===s.length?s:s.subarray(r,e);try{var o=n.decode(s)}catch(i){if(us===void 0){try{n.decode(new Uint8Array([128]))}catch{}try{n.decode(new Uint8Array([97])),us=!0}catch{us=!1}}throw!us&&(Xo=void 0),i}}else{e=(o=r)+e,r=[];let i,u=null;for(;o<e;){var a=t[o++];a<128?r.push(a):a<224?o>=e?Fr():(i=t[o++],a<194||(192&i)!=128?(o--,Fr()):r.push((31&a)<<6|63&i)):a<240?o>=e-1?Fr():(i=t[o++],(192&i)!=128||a===224&&i<160||a===237&&i>=160||(192&(n=t[o++]))!=128?(o--,Fr()):r.push((15&a)<<12|(63&i)<<6|63&n)):a<=244?o>=e-2?Fr():(i=t[o++],(192&i)!=128||i-144+(a<<28)>>30!=0||(192&(n=t[o++]))!=128||(192&(s=t[o++]))!=128?(o--,Fr()):(a=(7&a)<<18|(63&i)<<12|(63&n)<<6|63&s,a-=65536,r.push(55296+(a>>10&1023),56320+(1023&a)))):Fr(),r.length>=8192&&(u=Su(u,r),r.length=0)}o=Su(u,r)}return o}function bl(t){let e=ar(t.g);return yl(t.g,e)}function Vs(t,e,r){var n=ar(t.g);for(n=t.g.g+n;t.g.g<n;)r.push(e(t.g))}var fs=[],Is;function Pt(t,e,r){e.g?e.m(t,e.g,e.h,r,!0):e.m(t,e.h,r,!0)}var V=class{constructor(t,e){this.u=ul(t,e)}toJSON(){return vl(this)}l(){var t=pm;return t.g?t.l(this,t.g,t.h,!0):t.l(this,t.h,t.defaultValue,!0)}clone(){let t=this.u;return $a(this,t,oe(t),!1)}O(){return!!(2&Se(this.u))}};function vl(t){t=t.u,t=Is?t:Ms(t,Wa,void 0,void 0,!1);{var e=!Is;let l=t.length;if(l){var r=t[l-1],n=Ua(r);n?l--:r=void 0;var s=t;if(n){e:{var o,a=r,i=!1;if(a)for(let c in a)isNaN(+c)?(o??(o={}))[c]=a[c]:(n=a[c],Array.isArray(n)&&(ws(n)||Pu(n)&&n.size===0)&&(n=null),n==null&&(i=!0),n!=null&&((o??(o={}))[c]=n));if(i||(o=a),o)for(let c in o){i=o;break e}i=null}a=i==null?r!=null:i!==r}for(;l>0&&((o=s[l-1])==null||ws(o)||Pu(o)&&o.size===0);l--)var u=!0;(s!==t||a||u)&&(e?(u||a||i)&&(s.length=l):s=Array.prototype.slice.call(s,0,l),i&&s.push(i)),u=s}else u=t}return u}function Yu(t){return t?/^\d+$/.test(t)?(Os(t),new pa(ie,ve)):null:Pd||(Pd=new pa(0,0))}V.prototype.X=jn,V.prototype.toString=function(){try{return Is=!0,vl(this).toString()}finally{Is=!1}};var pa=class{constructor(t,e){this.h=t>>>0,this.g=e>>>0}},Pd;function qu(t){return t?/^-?\d+$/.test(t)?(Os(t),new ga(ie,ve)):null:Od||(Od=new ga(0,0))}var ga=class{constructor(t,e){this.h=t>>>0,this.g=e>>>0}},Od;function qr(t,e,r){for(;r>0||e>127;)t.g.push(127&e|128),e=(e>>>7|r<<25)>>>0,r>>>=7;t.g.push(e)}function hn(t,e){for(;e>127;)t.g.push(127&e|128),e>>>=7;t.g.push(e)}function Ws(t,e){if(e>=0)hn(t,e);else{for(let r=0;r<9;r++)t.g.push(127&e|128),e>>=7;t.g.push(1)}}function $n(t,e){t.g.push(e>>>0&255),t.g.push(e>>>8&255),t.g.push(e>>>16&255),t.g.push(e>>>24&255)}function tn(t,e){e.length!==0&&(t.l.push(e),t.h+=e.length)}function ft(t,e,r){hn(t.g,8*e+r)}function ei(t,e){return ft(t,e,2),e=t.g.end(),tn(t,e),e.push(t.h),e}function ti(t,e){var r=e.pop();for(r=t.h+t.g.length()-r;r>127;)e.push(127&r|128),r>>>=7,t.h++;e.push(r),t.h++}function $s(t,e,r){ft(t,e,2),hn(t.g,r.length),tn(t,t.g.end()),tn(t,r)}function Ss(t,e,r,n){r!=null&&(e=ei(t,e),n(r,t),ti(t,e))}function Ot(){let t=class{constructor(){throw Error()}};return Object.setPrototypeOf(t,t.prototype),t}var ri=Ot(),wl=Ot(),ni=Ot(),si=Ot(),Tl=Ot(),kl=Ot(),oi=Ot(),El=Ot(),Al=Ot(),dn=class{constructor(t,e,r){this.g=t,this.h=e,t=ri,this.l=!!t&&r===t||!1}};function zs(t,e){return new dn(t,e,ri)}function Rl(t,e,r,n,s){Ss(t,r,Fl(e,n),s)}var Dd=zs((function(t,e,r,n,s){return t.h===2&&(Yn(t,Ya(e,n,r),s),!0)}),Rl),Md=zs((function(t,e,r,n,s){return t.h===2&&(Yn(t,Ya(e,n,r,!0),s),!0)}),Rl),Hs=Symbol(),ai=Symbol(),Ku=Symbol(),Zu=Symbol(),Il,Sl;function Dr(t,e,r,n){var s=n[t];if(s)return s;(s={}).W=(function(f){switch(typeof f){case"boolean":return il||(il=[0,void 0,!0]);case"number":return f>0?void 0:f===0?Ad||(Ad=[0,void 0]):[-f,void 0];case"string":return[0,f];case"object":return f}})(n[0]);var o=n[1];let a=1;o&&o.constructor===Object&&(s.ha=o,typeof(o=n[++a])=="function"&&(s.ma=!0,Il??(Il=o),Sl??(Sl=n[a+1]),o=n[a+=2]));let i={};for(;o&&Array.isArray(o)&&o.length&&typeof o[0]=="number"&&o[0]>0;){for(var u=0;u<o.length;u++)i[o[u]]=o;o=n[++a]}for(u=1;o!==void 0;){let f;typeof o=="number"&&(u+=o,o=n[++a]);var l=void 0;if(o instanceof dn?f=o:(f=Dd,a--),f?.l){o=n[++a],l=n;var c=a;typeof o=="function"&&(o=o(),l[c]=o),l=o}for(c=u+1,typeof(o=n[++a])=="number"&&o<0&&(c-=o,o=n[++a]);u<c;u++){let d=i[u];l?r(s,u,f,l,d):e(s,u,f,d)}}return n[t]=s}function Cl(t){return Array.isArray(t)?t[0]instanceof dn?t:[Md,t]:[t,void 0]}function Fl(t,e){return t instanceof V?t.u:Array.isArray(t)?xr(t,e,!1):void 0}function ii(t,e,r,n){let s=r.g;t[e]=n?(o,a,i)=>s(o,a,i,n):s}function ui(t,e,r,n,s){let o=r.g,a,i;t[e]=(u,l,c)=>o(u,l,c,i||(i=Dr(ai,ii,ui,n).W),a||(a=ci(n)),s)}function ci(t){let e=t[Ku];if(e!=null)return e;let r=Dr(ai,ii,ui,t);return e=r.ma?(n,s)=>Il(n,s,r):(n,s)=>{let o=oe(n);for(;_l(s)&&s.h!=4;){var a=s.m,i=r[a];if(i==null){var u=r.ha;u&&(u=u[a])&&(u=Nd(u))!=null&&(i=r[a]=u)}i!=null&&i(s,n,a)||(a=(i=s).l,gs(i),i.ga?i=void 0:(u=i.g.g-a,i.g.g=a,i=yl(i.g,u)),a=n,i&&(pr||(pr=Symbol()),(u=a[pr])?u.push(i):a[pr]=[i]))}return 16384&o&&un(n),!0},t[Ku]=e}function Nd(t){let e=(t=Cl(t))[0].g;if(t=t[1]){let r=ci(t),n=Dr(ai,ii,ui,t).W;return(s,o,a)=>e(s,o,a,n,r)}return e}function Xs(t,e,r){t[e]=r.h}function js(t,e,r,n){let s,o,a=r.h;t[e]=(i,u,l)=>a(i,u,l,o||(o=Dr(Hs,Xs,js,n).W),s||(s=Ul(n)))}function Ul(t){let e=t[Zu];if(!e){let r=Dr(Hs,Xs,js,t);e=(n,s)=>Bl(n,s,r),t[Zu]=e}return e}function Bl(t,e,r){for(var n=Se(t),s=+!!(512&n)-1,o=t.length,a=512&n?1:0,i=o+(256&n?-1:0);a<i;a++){let u=t[a];if(u==null)continue;let l=a-s,c=Ju(r,l);c&&c(e,u,l)}if(256&n){n=t[o-1];for(let u in n)s=+u,Number.isNaN(s)||(o=n[s])!=null&&(i=Ju(r,s))&&i(e,o,s)}if(t=pr?t[pr]:void 0)for(tn(e,e.g.end()),r=0;r<t.length;r++)tn(e,Sa(t[r])||new Uint8Array(0))}function Ju(t,e){var r=t[e];if(r)return r;if((r=t.ha)&&(r=r[e])){var n=(r=Cl(r))[0].h;if(r=r[1]){let s=Ul(r),o=Dr(Hs,Xs,js,r).W;r=t.ma?Sl(o,s):(a,i,u)=>n(a,i,u,o,s)}else r=n;return t[e]=r}}function mn(t,e){if(Array.isArray(e)){var r=Se(e);if(4&r)return e;for(var n=0,s=0;n<e.length;n++){let o=t(e[n]);o!=null&&(e[s++]=o)}return s<n&&(e.length=s),Be(e,-12289&(5|r)),2&r&&Object.freeze(e),e}}function Je(t,e,r){return new dn(t,e,r)}function pn(t,e,r){return new dn(t,e,r)}function Qe(t,e,r){ye(t,oe(t),e,r)}var Gd=zs((function(t,e,r,n,s){return t.h===2&&(t=Yn(t,xr([void 0,void 0],n,!0),s),Tr(n=oe(e)),(s=ir(e,n,r))instanceof Tt?(2&s.M)!=0?((s=s.Y()).push(t),ye(e,n,r,s)):s.Na(t):Array.isArray(s)?(2&Se(s)&&ye(e,n,r,s=fl(s)),s.push(t)):ye(e,n,r,[t]),!0)}),(function(t,e,r,n,s){if(e instanceof Tt)e.forEach(((o,a)=>{Ss(t,r,xr([a,o],n,!1),s)}));else if(Array.isArray(e))for(let o=0;o<e.length;o++){let a=e[o];Array.isArray(a)&&Ss(t,r,xr(a,n,!1),s)}}));function Ll(t,e,r){if(e=(function(n){if(n==null)return n;let s=typeof n;if(s==="bigint")return String(BigInt.asIntN(64,n));if(Ds(n)){if(s==="string")return Na(n);if(s==="number")return Ma(n)}})(e),e!=null&&(typeof e=="string"&&qu(e),e!=null))switch(ft(t,r,0),typeof e){case"number":t=t.g,Qr(e),qr(t,ie,ve);break;case"bigint":r=BigInt.asUintN(64,e),r=new ga(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),qr(t.g,r.h,r.g);break;default:r=qu(e),qr(t.g,r.h,r.g)}}function Pl(t,e,r){(e=cn(e))!=null&&e!=null&&(ft(t,r,0),Ws(t.g,e))}function Ol(t,e,r){(e=rl(e))!=null&&(ft(t,r,0),t.g.g.push(e?1:0))}function Dl(t,e,r){(e=gr(e))!=null&&$s(t,r,zc(e))}function Ml(t,e,r,n,s){Ss(t,r,Fl(e,n),s)}function Nl(t,e,r){(e=e==null||typeof e=="string"||Hn(e)||e instanceof nr?e:void 0)!=null&&$s(t,r,Ka(e).buffer)}function Gl(t,e,r){return(t.h===5||t.h===2)&&(e=fn(e,oe(e),r,!1,!1),t.h==2?Vs(t,ma,e):e.push(ma(t.g)),!0)}var tr=Je((function(t,e,r){if(t.h!==1)return!1;var n=t.g;t=da(n);let s=da(n);n=2*(s>>31)+1;let o=s>>>20&2047;return t=4294967296*(1048575&s)+t,Qe(e,r,o==2047?t?NaN:n*(1/0):o==0?5e-324*n*t:n*Math.pow(2,o-1075)*(t+4503599627370496)),!0}),(function(t,e,r){(e=kr(e))!=null&&(ft(t,r,1),t=t.g,(r=tl||(tl=new DataView(new ArrayBuffer(8)))).setFloat64(0,+e,!0),ie=r.getUint32(0,!0),ve=r.getUint32(4,!0),$n(t,ie),$n(t,ve))}),Ot()),De=Je((function(t,e,r){return t.h===5&&(Qe(e,r,ma(t.g)),!0)}),(function(t,e,r){(e=kr(e))!=null&&(ft(t,r,5),t=t.g,La(e),$n(t,ie))}),oi),Vd=pn(Gl,(function(t,e,r){if((e=mn(kr,e))!=null)for(let a=0;a<e.length;a++){var n=t,s=r,o=e[a];o!=null&&(ft(n,s,5),n=n.g,La(o),$n(n,ie))}}),oi),li=pn(Gl,(function(t,e,r){if((e=mn(kr,e))!=null&&e.length){ft(t,r,2),hn(t.g,4*e.length);for(let n=0;n<e.length;n++)r=t.g,La(e[n]),$n(r,ie)}}),oi),vr=Je((function(t,e,r){return t.h===0&&(Qe(e,r,Za(t.g,Oa)),!0)}),Ll,kl),ea=Je((function(t,e,r){return t.h===0&&(Qe(e,r,(t=Za(t.g,Oa))===0?void 0:t),!0)}),Ll,kl),Wd=Je((function(t,e,r){return t.h===0&&(Qe(e,r,Za(t.g,Pa)),!0)}),(function(t,e,r){if((e=kd(e))!=null&&(typeof e=="string"&&Yu(e),e!=null))switch(ft(t,r,0),typeof e){case"number":t=t.g,Qr(e),qr(t,ie,ve);break;case"bigint":r=BigInt.asUintN(64,e),r=new pa(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),qr(t.g,r.h,r.g);break;default:r=Yu(e),qr(t.g,r.h,r.g)}}),Ot()),we=Je((function(t,e,r){return t.h===0&&(Qe(e,r,br(t.g)),!0)}),Pl,si),Ys=pn((function(t,e,r){return(t.h===0||t.h===2)&&(e=fn(e,oe(e),r,!1,!1),t.h==2?Vs(t,br,e):e.push(br(t.g)),!0)}),(function(t,e,r){if((e=mn(cn,e))!=null&&e.length){r=ei(t,r);for(let n=0;n<e.length;n++)Ws(t.g,e[n]);ti(t,r)}}),si),Yr=Je((function(t,e,r){return t.h===0&&(Qe(e,r,(t=br(t.g))===0?void 0:t),!0)}),Pl,si),xe=Je((function(t,e,r){return t.h===0&&(Qe(e,r,Ja(t.g)),!0)}),Ol,wl),Kr=Je((function(t,e,r){return t.h===0&&(Qe(e,r,(t=Ja(t.g))===!1?void 0:t),!0)}),Ol,wl),je=pn((function(t,e,r){return t.h===2&&(t=Qa(t),fn(e,oe(e),r,!1).push(t),!0)}),(function(t,e,r){if((e=mn(gr,e))!=null)for(let a=0;a<e.length;a++){var n=t,s=r,o=e[a];o!=null&&$s(n,s,zc(o))}}),ni),mr=Je((function(t,e,r){return t.h===2&&(Qe(e,r,(t=Qa(t))===""?void 0:t),!0)}),Dl,ni),re=Je((function(t,e,r){return t.h===2&&(Qe(e,r,Qa(t)),!0)}),Dl,ni),Oe=(function(t,e,r=ri){return new dn(t,e,r)})((function(t,e,r,n,s){return t.h===2&&(n=xr(void 0,n,!0),fn(e,oe(e),r,!0).push(n),Yn(t,n,s),!0)}),(function(t,e,r,n,s){if(Array.isArray(e))for(let o=0;o<e.length;o++)Ml(t,e[o],r,n,s)})),se=zs((function(t,e,r,n,s,o){return t.h===2&&(hl(e,Se(e),o,r),Yn(t,e=Ya(e,n,r),s),!0)}),Ml),Vl=Je((function(t,e,r){return t.h===2&&(Qe(e,r,bl(t)),!0)}),Nl,El),$d=pn((function(t,e,r){return(t.h===0||t.h===2)&&(e=fn(e,oe(e),r,!1,!1),t.h==2?Vs(t,ar,e):e.push(ar(t.g)),!0)}),(function(t,e,r){if((e=mn(nl,e))!=null)for(let a=0;a<e.length;a++){var n=t,s=r,o=e[a];o!=null&&(ft(n,s,0),hn(n.g,o))}}),Tl),zd=Je((function(t,e,r){return t.h===0&&(Qe(e,r,(t=ar(t.g))===0?void 0:t),!0)}),(function(t,e,r){(e=nl(e))!=null&&e!=null&&(ft(t,r,0),hn(t.g,e))}),Tl),Lt=Je((function(t,e,r){return t.h===0&&(Qe(e,r,br(t.g)),!0)}),(function(t,e,r){(e=cn(e))!=null&&(e=parseInt(e,10),ft(t,r,0),Ws(t.g,e))}),Al),xa=class{constructor(e,r){this.h=e,this.g=r,this.l=q,this.m=z,this.defaultValue=void 0}};function Dt(t,e){return new xa(t,e)}function Er(t,e){return(r,n)=>{if(fs.length){let o=fs.pop();o.o(n),Qo(o.g,r,n),r=o}else r=new class{constructor(o,a){if(ju.length){let i=ju.pop();Qo(i,o,a),o=i}else o=new class{constructor(i,u){this.h=null,this.m=!1,this.g=this.l=this.j=0,Qo(this,i,u)}clear(){this.h=null,this.m=!1,this.g=this.l=this.j=0,this.ca=!1}}(o,a);this.g=o,this.l=this.g.g,this.h=this.m=-1,this.o(a)}o({ga:o=!1}={}){this.ga=o}}(r,n);try{let o=new t,a=o.u;ci(e)(a,r);var s=o}finally{r.g.clear(),r.m=-1,r.h=-1,fs.length<100&&fs.push(r)}return s}}function qs(t){return function(){let e=new class{constructor(){this.l=[],this.h=0,this.g=new class{constructor(){this.g=[]}length(){return this.g.length}end(){let a=this.g;return this.g=[],a}}}};Bl(this.u,e,Dr(Hs,Xs,js,t)),tn(e,e.g.end());let r=new Uint8Array(e.h),n=e.l,s=n.length,o=0;for(let a=0;a<s;a++){let i=n[a];r.set(i,o),o+=i.length}return e.l=[r],r}}var Qu=class extends V{constructor(t){super(t)}},ec=[0,mr,Je((function(t,e,r){return t.h===2&&(Qe(e,r,(t=bl(t))===Or()?void 0:t),!0)}),(function(t,e,r){if(e!=null){if(e instanceof V){let n=e.Qa;return void(n&&(e=n(e),e!=null&&$s(t,r,Ka(e).buffer)))}if(Array.isArray(e))return}Nl(t,e,r)}),El)],ta,tc=globalThis.trustedTypes;function rc(t){ta===void 0&&(ta=(function(){let r=null;if(!tc)return r;try{let n=s=>s;r=tc.createPolicy("goog#html",{createHTML:n,createScript:n,createScriptURL:n})}catch{}return r})());var e=ta;return new class{constructor(r){this.g=r}toString(){return this.g+""}}(e?e.createScriptURL(t):t)}function Hd(t,...e){if(e.length===0)return rc(t[0]);let r=t[0];for(let n=0;n<e.length;n++)r+=encodeURIComponent(e[n])+t[n+1];return rc(r)}var Wl=[0,we,Lt,xe,-1,Ys,Lt,-1],Xd=class extends V{constructor(){super()}},$l=[0,xe,re,xe,Lt,-1,pn((function(t,e,r){return(t.h===0||t.h===2)&&(e=fn(e,oe(e),r,!1,!1),t.h==2?Vs(t,Ld,e):e.push(br(t.g)),!0)}),(function(t,e,r){if((e=mn(cn,e))!=null&&e.length){r=ei(t,r);for(let n=0;n<e.length;n++)Ws(t.g,e[n]);ti(t,r)}}),Al),re,-1,[0,xe,-1],Lt,xe,-1],zl=[0,re,-2],nc=class extends V{constructor(){super()}},Hl=[0],Xl=[0,we,xe,1,xe,-3],lt=class extends V{constructor(t){super(t,2)}},Le={};Le[336783863]=[0,re,xe,-1,we,[0,[1,2,3,4,5,6,7],se,Hl,se,$l,se,zl,se,Xl,se,Wl,se,[0,re,-2],se,[0,re,Lt]],[0,re],xe,[0,[1,3],[2,4],se,[0,Ys],-1,se,[0,je],-1,Oe,[0,re,-1]],re];var sc=[0,ea,-1,Kr,-3,ea,Ys,mr,Yr,ea,-1,Kr,Yr,Kr,-2,mr];function ht(t,e){ha(t,2,ln(e),"")}function ce(t,e){Gs(t,3,e)}function Y(t,e){Gs(t,4,e)}var Ze=class extends V{constructor(t){super(t,500)}o(t){return z(this,0,7,t)}},Mn=[-1,{}],oc=[0,re,1,Mn],ac=[0,re,je,Mn];function dt(t,e){As(t,1,Ze,e)}function de(t,e){Gs(t,10,e)}function J(t,e){Gs(t,15,e)}var nt=class extends V{constructor(t){super(t,500)}o(t){return z(this,0,1001,t)}},jl=[-500,Oe,[-500,mr,-1,je,-3,[-2,Le,xe],Oe,ec,Yr,-1,oc,ac,Oe,[0,mr,Kr],mr,sc,Yr,je,987,je],4,Oe,[-500,re,-1,[-1,{}],998,re],Oe,[-500,re,je,-1,[-2,{},xe],997,je,-1],Yr,Oe,[-500,re,je,Mn,998,je],je,Yr,oc,ac,Oe,[0,mr,-1,Mn],je,-2,sc,mr,-1,Kr,[0,Kr,zd],978,Mn,Oe,ec];nt.prototype.g=qs(jl);var jd=Er(nt,jl),Yd=class extends V{constructor(t){super(t)}},Yl=class extends V{constructor(t){super(t)}g(){return or(this,Yd,1)}},ql=[0,Oe,[0,we,De,re,-1]],Ks=Er(Yl,ql),qd=class extends V{constructor(t){super(t)}},Kd=class extends V{constructor(t){super(t)}},ra=class extends V{constructor(t){super(t)}h(){return q(this,qd,2)}g(){return or(this,Kd,5)}},Kl=Er(class extends V{constructor(t){super(t)}},[0,je,Ys,li,[0,Lt,[0,we,-3],[0,De,-3],[0,we,-1,[0,Oe,[0,we,-2]]],Oe,[0,De,-1,re,De]],re,-1,vr,Oe,[0,we,De],je,vr]),Zl=class extends V{constructor(t){super(t)}},Zr=Er(class extends V{constructor(t){super(t)}},[0,Oe,[0,De,-4]]),Jl=class extends V{constructor(t){super(t)}},qn=Er(class extends V{constructor(t){super(t)}},[0,Oe,[0,De,-4]]),Zd=class extends V{constructor(t){super(t)}},Jd=[0,we,-1,li,Lt],Ql=class extends V{constructor(){super()}};Ql.prototype.g=qs([0,De,-4,vr]);var Qd=class extends V{constructor(t){super(t)}},em=Er(class extends V{constructor(t){super(t)}},[0,Oe,[0,1,we,re,ql],vr]),ic=class extends V{constructor(t){super(t)}},tm=class extends V{constructor(t){super(t)}pa(){let t=ll(this);return t??Or()}},rm=class extends V{constructor(t){super(t)}},ef=[1,2],nm=Er(class extends V{constructor(t){super(t)}},[0,Oe,[0,ef,se,[0,li],se,[0,Vl],we,re],vr]),fi=class extends V{constructor(t){super(t)}},tf=[0,re,we,De,je,-1],uc=class extends V{constructor(t){super(t)}},sm=[0,xe,-1],cc=class extends V{constructor(t){super(t)}},xs=[1,2,3,4,5],Cs=class extends V{constructor(t){super(t)}g(){return ll(this)!=null}h(){return gr(_r(this,2))!=null}},ge=class extends V{constructor(t){super(t)}g(){return rl(_r(this,2))??!1}},rf=[0,Vl,re,[0,we,vr,-1],[0,Wd,vr]],Ce=[0,rf,xe,[0,xs,se,Xl,se,$l,se,Wl,se,Hl,se,zl],Lt],Zs=class extends V{constructor(t){super(t)}},hi=[0,Ce,De,-1,we],om=Dt(502141897,Zs);Le[502141897]=hi;var am=Er(class extends V{constructor(t){super(t)}},[0,[0,Lt,-1,Vd,$d],Jd]),nf=class extends V{constructor(t){super(t)}},sf=class extends V{constructor(t){super(t)}},di=[0,Ce,De,[0,Ce],xe],of=[0,Ce,hi,di,De,[0,[0,rf]]],im=Dt(508968150,sf);Le[508968150]=of,Le[508968149]=di;var af=class extends V{constructor(t){super(t)}},um=Dt(513916220,af);Le[513916220]=[0,Ce,of,we];var Xr=class extends V{constructor(t){super(t)}h(){return q(this,fi,2)}g(){ue(this,2)}},uf=[0,Ce,tf];Le[478825465]=uf;var cm=class extends V{constructor(t){super(t)}},cf=class extends V{constructor(t){super(t)}},mi=class extends V{constructor(t){super(t)}},pi=class extends V{constructor(t){super(t)}},lf=class extends V{constructor(t){super(t)}},lc=[0,Ce,[0,Ce],uf,-1],ff=[0,Ce,De,we],gi=[0,Ce,De],hf=[0,Ce,ff,gi,De],lm=Dt(479097054,lf);Le[479097054]=[0,Ce,hf,lc],Le[463370452]=lc,Le[464864288]=ff;var fm=Dt(462713202,pi);Le[462713202]=hf,Le[474472470]=gi;var hm=class extends V{constructor(t){super(t)}},df=class extends V{constructor(t){super(t)}},mf=class extends V{constructor(t){super(t)}},pf=class extends V{constructor(){super()}},xi=[0,Ce,De,-1,we],ya=[0,Ce,De,xe];pf.prototype.g=qs([0,Ce,gi,[0,Ce],hi,di,xi,ya]);var gf=class extends V{constructor(t){super(t)}},dm=Dt(456383383,gf);Le[456383383]=[0,Ce,tf];var xf=class extends V{constructor(t){super(t)}},mm=Dt(476348187,xf);Le[476348187]=[0,Ce,sm];var yf=class extends V{constructor(t){super(t)}},fc=class extends V{constructor(t){super(t)}},_f=[0,Lt,-1],pm=Dt(458105876,class extends V{constructor(t){super(t)}g(){var t=this.u;let e=oe(t),r=2&e;return t=(function(n,s,o){var a=fc;let i=2&s,u=!1;if(o==null){if(i)return Hu();o=[]}else if(o.constructor===Tt){if((2&o.M)==0||i)return o;o=o.Y()}else Array.isArray(o)?u=!!(2&Se(o)):o=[];if(i){if(!o.length)return Hu();u||(u=!0,un(o))}else u&&(u=!1,o=fl(o));return u||(64&Se(o)?ua(o,32):32&s&&Bs(o,32)),ye(n,s,2,a=new Tt(o,a,Ed,void 0)),a})(t,e,ir(t,e,2)),!r&&fc&&(t.sa=!0),t}});Le[458105876]=[0,_f,Gd,[!0,vr,[0,re,-1,je]]];var yi=class extends V{constructor(t){super(t)}},bf=Dt(458105758,yi);Le[458105758]=[0,Ce,re,_f];var vf=class extends V{constructor(t){super(t)}},gm=Dt(443442058,vf);Le[443442058]=[0,Ce,re,we,De,je,-1],Le[514774813]=xi;var wf=class extends V{constructor(t){super(t)}},xm=Dt(516587230,wf);function _a(t,e){return e=e?e.clone():new fi,t.displayNamesLocale!==void 0?ue(e,1,ln(t.displayNamesLocale)):t.displayNamesLocale===void 0&&ue(e,1),t.maxResults!==void 0?Yt(e,2,t.maxResults):"maxResults"in t&&ue(e,2),t.scoreThreshold!==void 0?W(e,3,t.scoreThreshold):"scoreThreshold"in t&&ue(e,3),t.categoryAllowlist!==void 0?Rs(e,4,t.categoryAllowlist):"categoryAllowlist"in t&&ue(e,4),t.categoryDenylist!==void 0?Rs(e,5,t.categoryDenylist):"categoryDenylist"in t&&ue(e,5),e}function _i(t,e=-1,r=""){return{categories:t.map((n=>({index:Bt(wt(n,1),0)??-1,score:Ie(n,2)??0,categoryName:jt(n,3)??"",displayName:jt(n,4)??""}))),headIndex:e,headName:r}}function Tf(t){var e=Br(t,3,kr,Ur()),r=Br(t,2,cn,Ur()),n=Br(t,1,gr,Ur()),s=Br(t,9,gr,Ur());let o={categories:[],keypoints:[]};for(let a=0;a<e.length;a++)o.categories.push({score:e[a],index:r[a]??-1,categoryName:n[a]??"",displayName:s[a]??""});if((e=q(t,ra,4)?.h())&&(o.boundingBox={originX:wt(e,1)??0,originY:wt(e,2)??0,width:wt(e,3)??0,height:wt(e,4)??0,angle:0}),q(t,ra,4)?.g().length)for(let a of q(t,ra,4).g())o.keypoints.push({x:ps(a,1)??0,y:ps(a,2)??0,score:ps(a,4)??0,label:gr(_r(a,3))??""});return o}function Js(t){let e=[];for(let r of or(t,Jl,1))e.push({x:Ie(r,1)??0,y:Ie(r,2)??0,z:Ie(r,3)??0,visibility:Ie(r,4)??0});return e}function Nn(t){let e=[];for(let r of or(t,Zl,1))e.push({x:Ie(r,1)??0,y:Ie(r,2)??0,z:Ie(r,3)??0,visibility:Ie(r,4)??0});return e}function hc(t){return Array.from(t,(e=>e>127?e-256:e))}function dc(t,e){if(t.length!==e.length)throw Error(`Cannot compute cosine similarity between embeddings of different sizes (${t.length} vs. ${e.length}).`);let r=0,n=0,s=0;for(let o=0;o<t.length;o++)r+=t[o]*e[o],n+=t[o]*t[o],s+=e[o]*e[o];if(n<=0||s<=0)throw Error("Cannot compute cosine similarity on embedding with 0 norm.");return r/Math.sqrt(n*s)}var hs;Le[516587230]=[0,Ce,xi,ya,De],Le[518928384]=ya;var ym=new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]);async function kf(){if(hs===void 0)try{await WebAssembly.instantiate(ym),hs=!0}catch{hs=!1}return hs}async function Un(t,e=Hd``){let r=await kf()?"wasm_internal":"wasm_nosimd_internal";return{wasmLoaderPath:`${e}/${t}_${r}.js`,wasmBinaryPath:`${e}/${t}_${r}.wasm`}}var hr=class{};function Ef(){var t=navigator;return typeof OffscreenCanvas<"u"&&(!(function(e=navigator){return(e=e.userAgent).includes("Safari")&&!e.includes("Chrome")})(t)||!!((t=t.userAgent.match(/Version\/([\d]+).*Safari/))&&t.length>=1&&Number(t[1])>=17))}async function mc(t){if(typeof importScripts!="function"){let e=document.createElement("script");return e.src=t.toString(),e.crossOrigin="anonymous",new Promise(((r,n)=>{e.addEventListener("load",(()=>{r()}),!1),e.addEventListener("error",(s=>{n(s)}),!1),document.body.appendChild(e)}))}importScripts(t.toString())}function Af(t){return t.videoWidth!==void 0?[t.videoWidth,t.videoHeight]:t.naturalWidth!==void 0?[t.naturalWidth,t.naturalHeight]:t.displayWidth!==void 0?[t.displayWidth,t.displayHeight]:[t.width,t.height]}function $(t,e,r){t.m||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target"),r(e=t.i.stringToNewUTF8(e)),t.i._free(e)}function pc(t,e,r){if(!t.i.canvas)throw Error("No OpenGL canvas configured.");if(r?t.i._bindTextureToStream(r):t.i._bindTextureToCanvas(),!(r=t.i.canvas.getContext("webgl2")||t.i.canvas.getContext("webgl")))throw Error("Failed to obtain WebGL context from the provided canvas. `getContext()` should only be invoked with `webgl` or `webgl2`.");t.i.gpuOriginForWebTexturesIsBottomLeft&&r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!0),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,e),t.i.gpuOriginForWebTexturesIsBottomLeft&&r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1);let[n,s]=Af(e);return!t.l||n===t.i.canvas.width&&s===t.i.canvas.height||(t.i.canvas.width=n,t.i.canvas.height=s),[n,s]}function gc(t,e,r){t.m||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target");let n=new Uint32Array(e.length);for(let s=0;s<e.length;s++)n[s]=t.i.stringToNewUTF8(e[s]);e=t.i._malloc(4*n.length),t.i.HEAPU32.set(n,e>>2),r(e);for(let s of n)t.i._free(s);t.i._free(e)}function $t(t,e,r){t.i.simpleListeners=t.i.simpleListeners||{},t.i.simpleListeners[e]=r}function fr(t,e,r){let n=[];t.i.simpleListeners=t.i.simpleListeners||{},t.i.simpleListeners[e]=(s,o,a)=>{o?(r(n,a),n=[]):n.push(s)}}hr.forVisionTasks=function(t){return Un("vision",t)},hr.forTextTasks=function(t){return Un("text",t)},hr.forGenAiExperimentalTasks=function(t){return Un("genai_experimental",t)},hr.forGenAiTasks=function(t){return Un("genai",t)},hr.forAudioTasks=function(t){return Un("audio",t)},hr.isSimdSupported=function(){return kf()};async function _m(t,e,r,n){return t=await(async(s,o,a,i,u)=>{if(o&&await mc(o),!self.ModuleFactory||a&&(await mc(a),!self.ModuleFactory))throw Error("ModuleFactory not set.");return self.Module&&u&&((o=self.Module).locateFile=u.locateFile,u.mainScriptUrlOrBlob&&(o.mainScriptUrlOrBlob=u.mainScriptUrlOrBlob)),u=await self.ModuleFactory(self.Module||u),self.ModuleFactory=self.Module=void 0,new s(u,i)})(t,r.wasmLoaderPath,r.assetLoaderPath,e,{locateFile:s=>s.endsWith(".wasm")?r.wasmBinaryPath.toString():r.assetBinaryPath&&s.endsWith(".data")?r.assetBinaryPath.toString():s}),await t.o(n),t}function na(t,e){let r=q(t.baseOptions,Cs,1)||new Cs;typeof e=="string"?(ue(r,2,ln(e)),ue(r,1)):e instanceof Uint8Array&&(ue(r,1,Ba(e,!1)),ue(r,2)),z(t.baseOptions,0,1,r)}function xc(t){try{let e=t.H.length;if(e===1)throw Error(t.H[0].message);if(e>1)throw Error("Encountered multiple errors: "+t.H.map((r=>r.message)).join(", "))}finally{t.H=[]}}function G(t,e){t.B=Math.max(t.B,e)}function Qs(t,e){t.A=new Ze,ht(t.A,"PassThroughCalculator"),ce(t.A,"free_memory"),Y(t.A,"free_memory_unused_out"),de(e,"free_memory"),dt(e,t.A)}function rn(t,e){ce(t.A,e),Y(t.A,e+"_unused_out")}function eo(t){t.g.addBoolToStream(!0,"free_memory",t.B)}var ys=class{constructor(t){this.g=t,this.H=[],this.B=0,this.g.setAutoRenderToScreen(!1)}l(t,e=!0){if(e){let r=t.baseOptions||{};if(t.baseOptions?.modelAssetBuffer&&t.baseOptions?.modelAssetPath)throw Error("Cannot set both baseOptions.modelAssetPath and baseOptions.modelAssetBuffer");if(!(q(this.baseOptions,Cs,1)?.g()||q(this.baseOptions,Cs,1)?.h()||t.baseOptions?.modelAssetBuffer||t.baseOptions?.modelAssetPath))throw Error("Either baseOptions.modelAssetPath or baseOptions.modelAssetBuffer must be set");if((function(n,s){let o=q(n.baseOptions,cc,3);if(!o){var a=o=new cc,i=new nc;Dn(a,4,xs,i)}"delegate"in s&&(s.delegate==="GPU"?(s=o,a=new Xd,Dn(s,2,xs,a)):(s=o,a=new nc,Dn(s,4,xs,a))),z(n.baseOptions,0,3,o)})(this,r),r.modelAssetPath)return fetch(r.modelAssetPath.toString()).then((n=>{if(n.ok)return n.arrayBuffer();throw Error(`Failed to fetch model: ${r.modelAssetPath} (${n.status})`)})).then((n=>{try{this.g.i.FS_unlink("/model.dat")}catch{}this.g.i.FS_createDataFile("/","model.dat",new Uint8Array(n),!0,!1,!1),na(this,"/model.dat"),this.m(),this.J()}));if(r.modelAssetBuffer instanceof Uint8Array)na(this,r.modelAssetBuffer);else if(r.modelAssetBuffer)return(async function(n){let s=[];for(var o=0;;){let{done:a,value:i}=await n.read();if(a)break;s.push(i),o+=i.length}if(s.length===0)return new Uint8Array(0);if(s.length===1)return s[0];n=new Uint8Array(o),o=0;for(let a of s)n.set(a,o),o+=a.length;return n})(r.modelAssetBuffer).then((n=>{na(this,n),this.m(),this.J()}))}return this.m(),this.J(),Promise.resolve()}J(){}ea(){let t;if(this.g.ea((e=>{t=jd(e)})),!t)throw Error("Failed to retrieve CalculatorGraphConfig");return t}setGraph(t,e){this.g.attachErrorListener(((r,n)=>{this.H.push(Error(n))})),this.g.La(),this.g.setGraph(t,e),this.A=void 0,xc(this)}finishProcessing(){this.g.finishProcessing(),xc(this)}close(){this.A=void 0,this.g.closeGraph()}};function Ke(t,e){if(!t)throw Error(`Unable to obtain required WebGL resource: ${e}`);return t}ys.prototype.close=ys.prototype.close,$c("TaskRunner",ys);var ba=class{constructor(e,r,n,s){this.g=e,this.h=r,this.m=n,this.l=s}bind(){this.g.bindVertexArray(this.h)}close(){this.g.deleteVertexArray(this.h),this.g.deleteBuffer(this.m),this.g.deleteBuffer(this.l)}};function yc(t,e,r){let n=t.g;if(r=Ke(n.createShader(r),"Failed to create WebGL shader"),n.shaderSource(r,e),n.compileShader(r),!n.getShaderParameter(r,n.COMPILE_STATUS))throw Error(`Could not compile WebGL shader: ${n.getShaderInfoLog(r)}`);return n.attachShader(t.h,r),r}function _c(t,e){let r=t.g,n=Ke(r.createVertexArray(),"Failed to create vertex array");r.bindVertexArray(n);let s=Ke(r.createBuffer(),"Failed to create buffer");r.bindBuffer(r.ARRAY_BUFFER,s),r.enableVertexAttribArray(t.P),r.vertexAttribPointer(t.P,2,r.FLOAT,!1,0,0),r.bufferData(r.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,1,1,-1]),r.STATIC_DRAW);let o=Ke(r.createBuffer(),"Failed to create buffer");return r.bindBuffer(r.ARRAY_BUFFER,o),r.enableVertexAttribArray(t.J),r.vertexAttribPointer(t.J,2,r.FLOAT,!1,0,0),r.bufferData(r.ARRAY_BUFFER,new Float32Array(e?[0,1,0,0,1,0,1,1]:[0,0,0,1,1,1,1,0]),r.STATIC_DRAW),r.bindBuffer(r.ARRAY_BUFFER,null),r.bindVertexArray(null),new ba(r,n,s,o)}function bi(t,e){if(t.g){if(e!==t.g)throw Error("Cannot change GL context once initialized")}else t.g=e}function Kn(t,e,r,n){return bi(t,e),t.h||(t.m(),t.C()),r?(t.s||(t.s=_c(t,!0)),r=t.s):(t.v||(t.v=_c(t,!1)),r=t.v),e.useProgram(t.h),r.bind(),t.l(),t=n(),r.g.bindVertexArray(null),t}function wr(t,e,r){return bi(t,e),t=Ke(e.createTexture(),"Failed to create texture"),e.bindTexture(e.TEXTURE_2D,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,r??e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,r??e.LINEAR),e.bindTexture(e.TEXTURE_2D,null),t}function to(t,e,r){bi(t,e),t.A||(t.A=Ke(e.createFramebuffer(),"Failed to create framebuffe.")),e.bindFramebuffer(e.FRAMEBUFFER,t.A),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,r,0)}function vi(t){t.g?.bindFramebuffer(t.g.FRAMEBUFFER,null)}var gn=class{H(){return`
1
+ var rp=Object.defineProperty;var np=(t,e,r)=>e in t?rp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Le=(t,e,r)=>np(t,typeof e!="symbol"?e+"":e,r);var $r=typeof self<"u"?self:{};function bl(t,e){t=t.split(".");var r,n=$r;for((t[0]in n)||n.execScript===void 0||n.execScript("var "+t[0]);t.length&&(r=t.shift());)t.length||e===void 0?n=n[r]&&n[r]!==Object.prototype[r]?n[r]:n[r]={}:n[r]=e}function Nr(){throw Error("Invalid UTF8")}function ac(t,e){return e=String.fromCharCode.apply(null,e),t==null?e:t+e}var Rs,ma,sp=typeof TextDecoder<"u",op,ap=typeof TextEncoder<"u";function vl(t){if(ap)t=(op||(op=new TextEncoder)).encode(t);else{let r=0,n=new Uint8Array(3*t.length);for(let s=0;s<t.length;s++){var e=t.charCodeAt(s);if(e<128)n[r++]=e;else{if(e<2048)n[r++]=e>>6|192;else{if(e>=55296&&e<=57343){if(e<=56319&&s<t.length){let o=t.charCodeAt(++s);if(o>=56320&&o<=57343){e=1024*(e-55296)+o-56320+65536,n[r++]=e>>18|240,n[r++]=e>>12&63|128,n[r++]=e>>6&63|128,n[r++]=63&e|128;continue}s--}e=65533}n[r++]=e>>12|224,n[r++]=e>>6&63|128}n[r++]=63&e|128}}t=r===n.length?n:n.subarray(0,r)}return t}var Ka,Gs;e:{for(ga=["CLOSURE_FLAGS"],Is=$r,Ss=0;Ss<ga.length;Ss++)if((Is=Is[ga[Ss]])==null){Gs=null;break e}Gs=Is}var ga,Is,Ss,Kn,ic=Gs&&Gs[610401301];Ka=ic!=null&&ic;var uc=$r.navigator;function Sa(t){return!!Ka&&!!Kn&&Kn.brands.some((({brand:e})=>e&&e.indexOf(t)!=-1))}function Rt(t){var e;return(e=$r.navigator)&&(e=e.userAgent)||(e=""),e.indexOf(t)!=-1}function br(){return!!Ka&&!!Kn&&Kn.brands.length>0}function ya(){return br()?Sa("Chromium"):(Rt("Chrome")||Rt("CriOS"))&&!(!br()&&Rt("Edge"))||Rt("Silk")}function Za(t){return Za[" "](t),t}Kn=uc&&uc.userAgentData||null,Za[" "]=function(){};var ip=!br()&&(Rt("Trident")||Rt("MSIE"));!Rt("Android")||ya(),ya(),Rt("Safari")&&(ya()||!br()&&Rt("Coast")||!br()&&Rt("Opera")||!br()&&Rt("Edge")||(br()?Sa("Microsoft Edge"):Rt("Edg/"))||br()&&Sa("Opera"));var wl={},zn=null;function up(t){let e=t.length,r=3*e/4;r%3?r=Math.floor(r):"=.".indexOf(t[e-1])!=-1&&(r="=.".indexOf(t[e-2])!=-1?r-2:r-1);let n=new Uint8Array(r),s=0;return(function(o,a){function i(l){for(;u<o.length;){let c=o.charAt(u++),f=zn[c];if(f!=null)return f;if(!/^[\s\xa0]*$/.test(c))throw Error("Unknown base64 encoding at char: "+c)}return l}Tl();let u=0;for(;;){let l=i(-1),c=i(0),f=i(64),d=i(64);if(d===64&&l===-1)break;a(l<<2|c>>4),f!=64&&(a(c<<4&240|f>>2),d!=64&&a(f<<6&192|d))}})(t,(function(o){n[s++]=o})),s!==r?n.subarray(0,s):n}function Tl(){if(!zn){zn={};var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"];for(let r=0;r<5;r++){let n=t.concat(e[r].split(""));wl[r]=n;for(let s=0;s<n.length;s++){let o=n[s];zn[o]===void 0&&(zn[o]=s)}}}}var kl=typeof Uint8Array<"u",El=!ip&&typeof btoa=="function";function cc(t){if(!El){var e;e===void 0&&(e=0),Tl(),e=wl[e];var r=Array(Math.floor(t.length/3)),n=e[64]||"";let u=0,l=0;for(;u<t.length-2;u+=3){var s=t[u],o=t[u+1],a=t[u+2],i=e[s>>2];s=e[(3&s)<<4|o>>4],o=e[(15&o)<<2|a>>6],a=e[63&a],r[l++]=i+s+o+a}switch(i=0,a=n,t.length-u){case 2:a=e[(15&(i=t[u+1]))<<2]||n;case 1:t=t[u],r[l]=e[t>>2]+e[(3&t)<<4|i>>4]+a+n}return r.join("")}for(e="",r=0,n=t.length-10240;r<n;)e+=String.fromCharCode.apply(null,t.subarray(r,r+=10240));return e+=String.fromCharCode.apply(null,r?t.subarray(r):t),btoa(e)}var lc=/[-_.]/g,cp={"-":"+",_:"/",".":"="};function lp(t){return cp[t]||""}function Al(t){if(!El)return up(t);lc.test(t)&&(t=t.replace(lc,lp)),t=atob(t);let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}function ts(t){return kl&&t!=null&&t instanceof Uint8Array}var cn={};function zr(){return fp||(fp=new lr(null,cn))}function Ja(t){Rl(cn);var e=t.g;return(e=e==null||ts(e)?e:typeof e=="string"?Al(e):null)==null?e:t.g=e}var lr=class{h(){return new Uint8Array(Ja(this)||0)}constructor(t,e){if(Rl(e),this.g=t,t!=null&&t.length===0)throw Error("ByteString should be constructed with non-empty values")}},fp,dp;function Rl(t){if(t!==cn)throw Error("illegal external caller")}function Il(t,e){t.__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity=e}function Sl(){let t=Error();Il(t,"incident"),(function(e){$r.setTimeout((()=>{throw e}),0)})(t)}function Ca(t){return Il(t=Error(t),"warning"),t}function Qa(){return typeof BigInt=="function"}function pt(t){return Array.prototype.slice.call(t)}var yn=typeof Symbol=="function"&&typeof Symbol()=="symbol";function Zs(t){return typeof Symbol=="function"&&typeof Symbol()=="symbol"?Symbol():t}var rs=Zs(),fc=Zs("0di"),xa=Zs("2ex"),Nn=Zs("1oa"),Js=yn?(t,e)=>{t[rs]|=e}:(t,e)=>{t.G!==void 0?t.G|=e:Object.defineProperties(t,{G:{value:e,configurable:!0,writable:!0,enumerable:!1}})},Ba=yn?(t,e)=>{t[rs]&=~e}:(t,e)=>{t.G!==void 0&&(t.G&=~e)},Be=yn?t=>0|t[rs]:t=>0|t.G,oe=yn?t=>t[rs]:t=>t.G,Oe=yn?(t,e)=>{t[rs]=e}:(t,e)=>{t.G!==void 0?t.G=e:Object.defineProperties(t,{G:{value:e,configurable:!0,writable:!0,enumerable:!1}})};function xn(t){return Js(t,34),t}function hp(t,e){Oe(e,-30975&(0|t))}function Ua(t,e){Oe(e,-30941&(34|t))}var ei,ns={},Cl={};function dc(t){return!(!t||typeof t!="object"||t.Ia!==Cl)}function ti(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)&&t.constructor===Object}function ri(t,e){if(t!=null){if(typeof t=="string")t=t?new lr(t,cn):zr();else if(t.constructor!==lr)if(ts(t))t=t.length?new lr(new Uint8Array(t),cn):zr();else{if(!e)throw Error();t=void 0}}return t}function Vs(t){return!(!Array.isArray(t)||t.length)&&!!(1&Be(t))}var hc=[];function Cr(t){if(2&t)throw Error()}Oe(hc,55),ei=Object.freeze(hc);var Ws=class t{constructor(e,r,n){this.l=0,this.g=e,this.h=r,this.m=n}next(){if(this.l<this.g.length){let e=this.g[this.l++];return{done:!1,value:this.h?this.h.call(this.m,e):e}}return{done:!0,value:void 0}}[Symbol.iterator](){return new t(this.g,this.h,this.m)}},wr;function Bl(t,e){(e=wr?e[wr]:void 0)&&(t[wr]=pt(e))}var pp=Object.freeze({});function Qs(t){return t.Pa=!0,t}var mp=Qs((t=>typeof t=="number")),pc=Qs((t=>typeof t=="string")),gp=Qs((t=>typeof t=="boolean")),eo=typeof $r.BigInt=="function"&&typeof $r.BigInt(0)=="bigint",Fa=Qs((t=>eo?t>=xp&&t<=bp:t[0]==="-"?mc(t,yp):mc(t,_p))),yp=Number.MIN_SAFE_INTEGER.toString(),xp=eo?BigInt(Number.MIN_SAFE_INTEGER):void 0,_p=Number.MAX_SAFE_INTEGER.toString(),bp=eo?BigInt(Number.MAX_SAFE_INTEGER):void 0;function mc(t,e){if(t.length>e.length)return!1;if(t.length<e.length||t===e)return!0;for(let r=0;r<t.length;r++){let n=t[r],s=e[r];if(n>s)return!1;if(n<s)return!0}}var vp=typeof Uint8Array.prototype.slice=="function",Ul,ie=0,Te=0;function gc(t){let e=t>>>0;ie=e,Te=(t-e)/4294967296>>>0}function ln(t){if(t<0){gc(-t);let[e,r]=ai(ie,Te);ie=e>>>0,Te=r>>>0}else gc(t)}function ni(t){let e=Ul||(Ul=new DataView(new ArrayBuffer(8)));e.setFloat32(0,+t,!0),Te=0,ie=e.getUint32(0,!0)}function si(t,e){let r=4294967296*e+(t>>>0);return Number.isSafeInteger(r)?r:Zn(t,e)}function oi(t,e){let r=2147483648&e;return r&&(e=~e>>>0,(t=1+~t>>>0)==0&&(e=e+1>>>0)),typeof(t=si(t,e))=="number"?r?-t:t:r?"-"+t:t}function Zn(t,e){if(t>>>=0,(e>>>=0)<=2097151)var r=""+(4294967296*e+t);else Qa()?r=""+(BigInt(e)<<BigInt(32)|BigInt(t)):(t=(16777215&t)+6777216*(r=16777215&(t>>>24|e<<8))+6710656*(e=e>>16&65535),r+=8147497*e,e*=2,t>=1e7&&(r+=t/1e7>>>0,t%=1e7),r>=1e7&&(e+=r/1e7>>>0,r%=1e7),r=e+yc(r)+yc(t));return r}function yc(t){return t=String(t),"0000000".slice(t.length)+t}function to(t){if(t.length<16)ln(Number(t));else if(Qa())t=BigInt(t),ie=Number(t&BigInt(4294967295))>>>0,Te=Number(t>>BigInt(32)&BigInt(4294967295));else{let e=+(t[0]==="-");Te=ie=0;let r=t.length;for(let n=e,s=(r-e)%6+e;s<=r;n=s,s+=6){let o=Number(t.slice(n,s));Te*=1e6,ie=1e6*ie+o,ie>=4294967296&&(Te+=Math.trunc(ie/4294967296),Te>>>=0,ie>>>=0)}if(e){let[n,s]=ai(ie,Te);ie=n,Te=s}}}function ai(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function Br(t){return t==null||typeof t=="number"?t:t==="NaN"||t==="Infinity"||t==="-Infinity"?Number(t):void 0}function Fl(t){return t==null||typeof t=="boolean"?t:typeof t=="number"?!!t:void 0}var wp=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function ro(t){let e=typeof t;switch(e){case"bigint":return!0;case"number":return Number.isFinite(t)}return e==="string"&&wp.test(t)}function _n(t){if(t==null)return t;if(typeof t=="string"){if(!t)return;t=+t}return typeof t=="number"&&Number.isFinite(t)?0|t:void 0}function Pl(t){if(t==null)return t;if(typeof t=="string"){if(!t)return;t=+t}return typeof t=="number"&&Number.isFinite(t)?t>>>0:void 0}function xc(t){return t[0]!=="-"&&(t.length<20||t.length===20&&Number(t.substring(0,6))<184467)}function ii(t){return t=Math.trunc(t),Number.isSafeInteger(t)||(ln(t),t=oi(ie,Te)),t}function ui(t){var e=Math.trunc(Number(t));if(Number.isSafeInteger(e))return String(e);if((e=t.indexOf("."))!==-1&&(t=t.substring(0,e)),!(t[0]==="-"?t.length<20||t.length===20&&Number(t.substring(0,7))>-922337:t.length<19||t.length===19&&Number(t.substring(0,6))<922337))if(to(t),t=ie,2147483648&(e=Te))if(Qa())t=""+(BigInt(0|e)<<BigInt(32)|BigInt(t>>>0));else{let[r,n]=ai(t,e);t="-"+Zn(r,n)}else t=Zn(t,e);return t}function $s(t){return t==null?t:typeof t=="bigint"?(Fa(t)?t=Number(t):(t=BigInt.asIntN(64,t),t=Fa(t)?Number(t):String(t)),t):ro(t)?typeof t=="number"?ii(t):ui(t):void 0}function Tp(t){if(t==null)return t;var e=typeof t;if(e==="bigint")return String(BigInt.asUintN(64,t));if(ro(t)){if(e==="string")return e=Math.trunc(Number(t)),Number.isSafeInteger(e)&&e>=0?t=String(e):((e=t.indexOf("."))!==-1&&(t=t.substring(0,e)),xc(t)||(to(t),t=Zn(ie,Te))),t;if(e==="number")return(t=Math.trunc(t))>=0&&Number.isSafeInteger(t)?t:(function(r){if(r<0){ln(r);var n=Zn(ie,Te);return r=Number(n),Number.isSafeInteger(r)?r:n}return xc(n=String(r))?n:(ln(r),si(ie,Te))})(t)}}function Ll(t){if(typeof t!="string")throw Error();return t}function bn(t){if(t!=null&&typeof t!="string")throw Error();return t}function Tr(t){return t==null||typeof t=="string"?t:void 0}function ci(t,e,r,n){if(t!=null&&typeof t=="object"&&t.X===ns)return t;if(!Array.isArray(t))return r?2&n?(t=e[fc])?e=t:(xn((t=new e).u),e=e[fc]=t):e=new e:e=void 0,e;let s=r=Be(t);return s===0&&(s|=32&n),s|=2&n,s!==r&&Oe(t,s),new e(t)}function kp(t,e,r){if(e)e:{if(!ro(e=t))throw Ca("int64");switch(typeof e){case"string":e=ui(e);break e;case"bigint":if(t=e=BigInt.asIntN(64,e),pc(t)){if(!/^\s*(?:-?[1-9]\d*|0)?\s*$/.test(t))throw Error(String(t))}else if(mp(t)&&!Number.isSafeInteger(t))throw Error(String(t));e=eo?BigInt(e):gp(e)?e?"1":"0":pc(e)?e.trim()||"0":String(e);break e;default:e=ii(e)}}else e=$s(t);return typeof(r=(t=e)==null?r?0:void 0:t)=="string"&&(e=+r,Number.isSafeInteger(e))?e:r}function Ol(t){var e;return Gn===void 0&&(Gn=typeof Proxy=="function"?_c(Proxy):null),(e=!Gn)||(Vn===void 0&&(Vn=typeof WeakMap=="function"?_c(WeakMap):null),e=!Vn),e?t:(e=fn?.get(t))?e:Math.random()>.01?t:((function(r){if(_a===void 0){let n=new Gn([],{});_a=Array.prototype.concat.call([],n).length===1}_a&&typeof Symbol=="function"&&Symbol.isConcatSpreadable&&(r[Symbol.isConcatSpreadable]=!0)})(t),(function(r,n){(fn||(fn=new Vn)).set(r,n),(Dl||(Dl=new Vn)).set(n,r)})(t,e=new Gn(t,{set:(r,n,s)=>(Sl(),r[n]=s,!0)})),e)}var fn,Dl,Gn,Vn,_a,zs,Ml,Ep;function _c(t){try{return t.toString().indexOf("[native code]")!==-1?t:null}catch{return null}}function kr(t,e,r){return t=Nl(t,e[0],e[1],r?1:2),e!==Ml&&r&&Js(t,16384),t}function Nl(t,e,r,n){if(n=n??0,t==null&&(t=zs),zs=void 0,t==null){var s=96;r?(t=[r],s|=512):t=[],e&&(s=-33521665&s|(1023&e)<<15)}else{if(!Array.isArray(t))throw Error("narr");if(2048&(s=Be(t)))throw Error("farr");if(64&s)return t;if(n===1||n===2||(s|=64),r&&(s|=512,r!==t[0]))throw Error("mid");e:{if(n=(r=t).length){let o=n-1;if(ti(r[o])){if((e=o-(+!!(512&(s|=256))-1))>=1024)throw Error("pvtlmt");s=-33521665&s|(1023&e)<<15;break e}}if(e){if((e=Math.max(e,n-(+!!(512&s)-1)))>1024)throw Error("spvt");s=-33521665&s|(1023&e)<<15}}}return Oe(t,s),t}var Ap={},Rp=(function(){try{return Za(new class extends Map{constructor(){super()}}),!1}catch{return!0}})(),jn=class{constructor(){this.g=new Map}get(e){return this.g.get(e)}set(e,r){return this.g.set(e,r),this.size=this.g.size,this}delete(e){return e=this.g.delete(e),this.size=this.g.size,e}clear(){this.g.clear(),this.size=this.g.size}has(e){return this.g.has(e)}entries(){return this.g.entries()}keys(){return this.g.keys()}values(){return this.g.values()}forEach(e,r){return this.g.forEach(e,r)}[Symbol.iterator](){return this.entries()}},Ip=Rp?(Object.setPrototypeOf(jn.prototype,Map.prototype),Object.defineProperties(jn.prototype,{size:{value:0,configurable:!0,enumerable:!0,writable:!0}}),jn):class extends Map{constructor(){super()}};function bc(t){return t}function ba(t){if(2&t.M)throw Error("Cannot mutate an immutable Map")}var St=class extends Ip{constructor(t,e,r=bc,n=bc){super();let s=Be(t);s|=64,Oe(t,s),this.M=s,this.T=e,this.S=r,this.Z=this.T?Sp:n;for(let o=0;o<t.length;o++){let a=t[o],i=r(a[0],!1,!0),u=a[1];e?u===void 0&&(u=null):u=n(a[1],!1,!0,void 0,void 0,s),super.set(i,u)}}oa(t=vc){if(this.size!==0)return this.Y(t)}Y(t=vc){let e=[],r=super.entries();for(var n;!(n=r.next()).done;)(n=n.value)[0]=t(n[0]),n[1]=t(n[1]),e.push(n);return e}clear(){ba(this),super.clear()}delete(t){return ba(this),super.delete(this.S(t,!0,!1))}entries(){var t=this.na();return new Ws(t,Cp,this)}keys(){return this.Ha()}values(){var t=this.na();return new Ws(t,St.prototype.get,this)}forEach(t,e){super.forEach(((r,n)=>{t.call(e,this.get(n),n,this)}))}set(t,e){return ba(this),(t=this.S(t,!0,!1))==null?this:e==null?(super.delete(t),this):super.set(t,this.Z(e,!0,!0,this.T,!1,this.M))}Na(t){let e=this.S(t[0],!1,!0);t=t[1],t=this.T?t===void 0?null:t:this.Z(t,!1,!0,void 0,!1,this.M),super.set(e,t)}has(t){return super.has(this.S(t,!1,!1))}get(t){t=this.S(t,!1,!1);let e=super.get(t);if(e!==void 0){var r=this.T;return r?((r=this.Z(e,!1,!0,r,this.sa,this.M))!==e&&super.set(t,r),r):e}}na(){return Array.from(super.keys())}Ha(){return super.keys()}[Symbol.iterator](){return this.entries()}};function Sp(t,e,r,n,s,o){return t=ci(t,n,r,o),s&&(t=so(t)),t}function vc(t){return t}function Cp(t){return[t,this.get(t)]}var Bp;function wc(){return Bp||(Bp=new St(xn([]),void 0,void 0,void 0,Ap))}function li(t,e,r,n,s){if(t!=null){if(Array.isArray(t))t=Vs(t)?void 0:s&&2&Be(t)?t:no(t,e,r,n!==void 0,s);else if(ti(t)){let o={};for(let a in t)o[a]=li(t[a],e,r,n,s);t=o}else t=e(t,n);return t}}function no(t,e,r,n,s){let o=n||r?Be(t):0;n=n?!!(32&o):void 0;let a=pt(t);for(let i=0;i<a.length;i++)a[i]=li(a[i],e,r,n,s);return r&&(Bl(a,t),r(o,a)),a}function Up(t){return li(t,fi,void 0,void 0,!1)}function fi(t){return t.X===ns?t.toJSON():t instanceof St?t.oa(Up):(function(e){switch(typeof e){case"number":return isFinite(e)?e:String(e);case"bigint":return Fa(e)?Number(e):String(e);case"boolean":return e?1:0;case"object":if(e)if(Array.isArray(e)){if(Vs(e))return}else{if(ts(e))return cc(e);if(e instanceof lr){let r=e.g;return r==null?"":typeof r=="string"?r:e.g=cc(r)}if(e instanceof St)return e.oa()}}return e})(t)}function Pa(t,e,r=Ua){if(t!=null){if(kl&&t instanceof Uint8Array)return e?t:new Uint8Array(t);if(Array.isArray(t)){var n=Be(t);return 2&n?t:(e&&(e=n===0||!!(32&n)&&!(64&n||!(16&n))),e?(Oe(t,-12293&(34|n)),t):no(t,Pa,4&n?Ua:r,!0,!0))}return t.X===ns?(r=t.u,t=2&(n=oe(r))?t:di(t,r,n,!0)):t instanceof St&&!(2&t.M)&&(r=xn(t.Y(Pa)),t=new St(r,t.T,t.S,t.Z)),t}}function di(t,e,r,n){return t=t.constructor,zs=e=Gl(e,r,n),e=new t(e),zs=void 0,e}function Gl(t,e,r){let n=r||2&e?Ua:hp,s=!!(32&e);return t=(function(o,a,i){let u=pt(o);var l=u.length;let c=256&a?u[l-1]:void 0;for(l+=c?-1:0,a=512&a?1:0;a<l;a++)u[a]=i(u[a]);if(c){a=u[a]={};for(let f in c)a[f]=i(c[f])}return Bl(u,o),u})(t,e,(o=>Pa(o,s,n))),Js(t,32|(r?2:0)),t}function so(t){let e=t.u,r=oe(e);return 2&r?di(t,e,r,!1):t}function Ar(t,e){return pr(t=t.u,oe(t),e)}function Tc(t,e,r,n){if(!((e=n+(+!!(512&e)-1))<0||e>=t.length||e>=r))return t[e]}function pr(t,e,r,n){if(r===-1)return null;let s=e>>15&1023||536870912;if(!(r>=s)){var o=t.length;return n&&256&e&&(n=t[o-1][r])!=null?(Tc(t,e,s,r)&&xa!=null&&((e=(t=dp??(dp={}))[xa]||0)>=4||(t[xa]=e+1,Sl())),n):Tc(t,e,s,r)}return 256&e?t[t.length-1][r]:void 0}function ue(t,e,r){let n=t.u,s=oe(n);return Cr(s),_e(n,s,e,r),t}function _e(t,e,r,n){let s=e>>15&1023||536870912;if(r>=s){let o,a=e;if(256&e)o=t[t.length-1];else{if(n==null)return a;o=t[s+(+!!(512&e)-1)]={},a|=256}return o[r]=n,r<s&&(t[r+(+!!(512&e)-1)]=void 0),a!==e&&Oe(t,a),a}return t[r+(+!!(512&e)-1)]=n,256&e&&r in(t=t[t.length-1])&&delete t[r],e}function Ps(t,e){t=t.u;let r=oe(t),n=pr(t,r,e),s=Br(n);return s!=null&&s!==n&&_e(t,r,e,s),s}function Vl(t){t=t.u;let e=oe(t),r=pr(t,e,1),n=ri(r,!0);return n!=null&&n!==r&&_e(t,e,1,n),n}function Gr(){return pp===void 0?2:4}function Vr(t,e,r,n,s){let o=t.u,a=2&(t=oe(o))?1:n;s=!!s,n=hi(o,t,e);var i=Be(n);if(!(4&i)){4&i&&(n=pt(n),i=fr(i,t),t=_e(o,t,e,n));let l=0,c=0;for(;l<n.length;l++){let f=r(n[l]);f!=null&&(n[c++]=f)}c<l&&(n.length=c),i=-4097&(20|(i=pi(i,t))),Oe(n,i&=-8193),2&i&&Object.freeze(n)}let u;return a===1||a===4&&32&i?Nt(i)||(s=i,(i|=2)!==s&&Oe(n,i),Object.freeze(n)):(r=a===5&&(!!(32&i)||Nt(i)||!!fn?.get(n)),(a===2||r)&&Nt(i)&&(n=pt(n),i=Er(i=fr(i,t),t,s),Oe(n,i),t=_e(o,t,e,n)),Nt(i)||(e=i,(i=Er(i,t,s))!==e&&Oe(n,i)),r?u=Ol(n):a!==2||s||fn?.delete(n)),u||n}function hi(t,e,r,n){return t=pr(t,e,r,n),Array.isArray(t)?t:ei}function pi(t,e){return t===0&&(t=fr(t,e)),1|t}function Nt(t){return!!(2&t)&&!!(4&t)||!!(2048&t)}function Wl(t){t=pt(t);for(let e=0;e<t.length;e++){let r=t[e]=pt(t[e]);Array.isArray(r[1])&&(r[1]=xn(r[1]))}return t}function La(t,e,r,n){t=t.u;let s=oe(t);Cr(s),_e(t,s,e,(n==="0"?Number(r)===0:r===n)?void 0:r)}function vn(t,e,r,n,s){Cr(e);var o=!(!(64&e)&&16384&e);let a=(s=hi(t,e,r,s))!==ei;if(o||!a){let i=o=a?Be(s):0;(!a||2&i||Nt(i)||4&i&&!(32&i))&&(s=pt(s),i=fr(i,e),e=_e(t,e,r,s)),i=-13&pi(i,e),i=Er(n?-17&i:16|i,e,!0),i!==o&&Oe(s,i)}return s}function va(t,e){var r=Uf;return gi(mi(t=t.u),t,oe(t),r)===e?e:-1}function mi(t){if(yn)return t[Nn]??(t[Nn]=new Map);if(Nn in t)return t[Nn];let e=new Map;return Object.defineProperty(t,Nn,{value:e}),e}function $l(t,e,r,n){let s=mi(t),o=gi(s,t,e,r);return o!==n&&(o&&(e=_e(t,e,o)),s.set(r,n)),e}function gi(t,e,r,n){let s=t.get(n);if(s!=null)return s;s=0;for(let o=0;o<n.length;o++){let a=n[o];pr(e,r,a)!=null&&(s!==0&&(r=_e(e,r,s)),s=a)}return t.set(n,s),s}function yi(t,e,r,n){let s,o=oe(t);if((n=pr(t,o,r,n))!=null&&n.X===ns)return(e=so(n))!==n&&_e(t,o,r,e),e.u;if(Array.isArray(n)){let a=Be(n);s=2&a?kr(Gl(n,a,!1),e,!0):64&a?n:kr(s,e,!0)}else s=kr(void 0,e,!0);return s!==n&&_e(t,o,r,s),s}function zl(t,e,r,n){t=t.u;let s=oe(t);return(e=ci(n=pr(t,s,r,n),e,!1,s))!==n&&e!=null&&_e(t,s,r,e),e}function q(t,e,r,n=!1){if((e=zl(t,e,r,n))==null)return e;if(t=t.u,!(2&(n=oe(t)))){let s=so(e);s!==e&&_e(t,n,r,e=s)}return e}function Hl(t,e,r,n,s,o,a){t=t.u;var i=!!(2&e);s=i?1:s,o=!!o,a&&(a=!i),i=hi(t,e,n);var u=Be(i),l=!!(4&u);if(!l){var c=i,f=e;let p=!!(2&(u=pi(u,e)));p&&(f|=2);let b=!p,E=!0,A=0,I=0;for(;A<c.length;A++){let _=ci(c[A],r,!1,f);if(_ instanceof r){if(!p){let T=!!(2&Be(_.u));b&&(b=!T),E&&(E=T)}c[I++]=_}}I<A&&(c.length=I),u|=4,u=E?16|u:-17&u,Oe(c,u=b?8|u:-9&u),p&&Object.freeze(c)}if(a&&!(8&u||!i.length&&(s===1||s===4&&32&u))){for(Nt(u)&&(i=pt(i),u=fr(u,e),e=_e(t,e,n,i)),r=i,a=u,c=0;c<r.length;c++)(u=r[c])!==(f=so(u))&&(r[c]=f);a|=8,a=r.length?-17&a:16|a,Oe(r,a),u=a}let d;return s===1||s===4&&32&u?Nt(u)||(e=u,(u|=!i.length||16&u&&(!l||32&u)?2:2048)!==e&&Oe(i,u),Object.freeze(i)):(l=s===5&&(!!(32&u)||Nt(u)||!!fn?.get(i)),(s===2||l)&&Nt(u)&&(i=pt(i),u=Er(u=fr(u,e),e,o),Oe(i,u),e=_e(t,e,n,i)),Nt(u)||(n=u,(u=Er(u,e,o))!==n&&Oe(i,u)),l?d=Ol(i):s!==2||o||fn?.delete(i)),d||i}function dr(t,e,r){let n=oe(t.u);return Hl(t,n,e,r,Gr(),!1,!(2&n))}function z(t,e,r,n){return n==null&&(n=void 0),ue(t,r,n)}function Xn(t,e,r,n){n==null&&(n=void 0);e:{t=t.u;let s=oe(t);if(Cr(s),n==null){let o=mi(t);if(gi(o,t,s,r)!==e)break e;o.set(r,0)}else s=$l(t,s,r,e);_e(t,s,e,n)}}function fr(t,e){return-2049&(t=32|(2&e?2|t:-3&t))}function Er(t,e,r){return 32&e&&r||(t&=-33),t}function Hs(t,e,r,n){let s=oe(t.u);Cr(s),t=Hl(t,s,r,e,2,!0),n=n??new r,t.push(n),2&Be(n.u)?Ba(t,8):Ba(t,16)}function Gt(t,e){return t??e}function It(t,e){return _n(Ar(t,e))}function Ce(t,e){return Gt(Ps(t,e),0)}function tr(t,e){return Gt(Tr(Ar(t,e)),"")}function Jn(t,e,r){if(r!=null&&typeof r!="boolean")throw t=typeof r,Error(`Expected boolean but got ${t!="object"?t:r?Array.isArray(r)?"array":t:"null"}: ${r}`);ue(t,e,r)}function rr(t,e,r){if(r!=null){if(typeof r!="number"||!Number.isFinite(r))throw Ca("int32");r|=0}ue(t,e,r)}function W(t,e,r){if(r!=null&&typeof r!="number")throw Error(`Value of float/double field must be a number, found ${typeof r}: ${r}`);ue(t,e,r)}function js(t,e,r){{let a=t.u,i=oe(a);if(Cr(i),r==null)_e(a,i,e);else{r=Dl?.get(r)||r;var n=t=Be(r),s=Nt(t),o=s||Object.isFrozen(r);for(s||(t=0),o||(r=pt(r),n=0,t=Er(t=fr(t,i),i,!0),o=!1),t|=21,s=0;s<r.length;s++){let u=r[s],l=Ll(u);Object.is(u,l)||(o&&(r=pt(r),n=0,t=Er(t=fr(t,i),i,!0),o=!1),r[s]=l)}t!==n&&(o&&(r=pt(r),t=Er(t=fr(t,i),i,!0)),Oe(r,t)),_e(a,i,e,r)}}}function oo(t,e,r){Cr(oe(t.u)),Vr(t,e,Tr,2,!0).push(Ll(r))}function jl(t,e){return Error(`Invalid wire type: ${t} (at position ${e})`)}function xi(){return Error("Failed to read varint, encoding is invalid.")}function Xl(t,e){return Error(`Tried to read past the end of the data ${e} > ${t}`)}function _i(t){if(typeof t=="string")return{buffer:Al(t),O:!1};if(Array.isArray(t))return{buffer:new Uint8Array(t),O:!1};if(t.constructor===Uint8Array)return{buffer:t,O:!1};if(t.constructor===ArrayBuffer)return{buffer:new Uint8Array(t),O:!1};if(t.constructor===lr)return{buffer:Ja(t)||new Uint8Array(0),O:!0};if(t instanceof Uint8Array)return{buffer:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),O:!1};throw Error("Type not convertible to a Uint8Array, expected a Uint8Array, an ArrayBuffer, a base64 encoded string, a ByteString or an Array of numbers")}function bi(t,e){let r,n=0,s=0,o=0,a=t.h,i=t.g;do r=a[i++],n|=(127&r)<<o,o+=7;while(o<32&&128&r);for(o>32&&(s|=(127&r)>>4),o=3;o<32&&128&r;o+=7)r=a[i++],s|=(127&r)<<o;if(Wr(t,i),r<128)return e(n>>>0,s>>>0);throw xi()}function vi(t){let e=0,r=t.g,n=r+10,s=t.h;for(;r<n;){let o=s[r++];if(e|=o,(128&o)==0)return Wr(t,r),!!(127&e)}throw xi()}function Rr(t){let e=t.h,r=t.g,n=e[r++],s=127&n;if(128&n&&(n=e[r++],s|=(127&n)<<7,128&n&&(n=e[r++],s|=(127&n)<<14,128&n&&(n=e[r++],s|=(127&n)<<21,128&n&&(n=e[r++],s|=n<<28,128&n&&128&e[r++]&&128&e[r++]&&128&e[r++]&&128&e[r++]&&128&e[r++])))))throw xi();return Wr(t,r),s}function hr(t){return Rr(t)>>>0}function Oa(t){var e=t.h;let r=t.g,n=e[r],s=e[r+1],o=e[r+2];return e=e[r+3],Wr(t,t.g+4),(n<<0|s<<8|o<<16|e<<24)>>>0}function Da(t){var e=Oa(t);t=2*(e>>31)+1;let r=e>>>23&255;return e&=8388607,r==255?e?NaN:t*(1/0):r==0?1401298464324817e-60*t*e:t*Math.pow(2,r-150)*(e+8388608)}function Fp(t){return Rr(t)}function wa(t,e,{ca:r=!1}={}){t.ca=r,e&&(e=_i(e),t.h=e.buffer,t.m=e.O,t.j=0,t.l=t.h.length,t.g=t.j)}function Wr(t,e){if(t.g=e,e>t.l)throw Xl(t.l,e)}function Yl(t,e){if(e<0)throw Error(`Tried to read a negative byte length: ${e}`);let r=t.g,n=r+e;if(n>t.l)throw Xl(e,t.l-r);return t.g=n,r}function ql(t,e){if(e==0)return zr();var r=Yl(t,e);return t.ca&&t.m?r=t.h.subarray(r,r+e):(t=t.h,r=r===(e=r+e)?new Uint8Array(0):vp?t.slice(r,e):new Uint8Array(t.subarray(r,e))),r.length==0?zr():new lr(r,cn)}St.prototype.toJSON=void 0,St.prototype.Ia=Cl;var kc=[];function Kl(t){var e=t.g;if(e.g==e.l)return!1;t.l=t.g.g;var r=hr(t.g);if(e=r>>>3,!((r&=7)>=0&&r<=5))throw jl(r,t.l);if(e<1)throw Error(`Invalid field number: ${e} (at position ${t.l})`);return t.m=e,t.h=r,!0}function Ls(t){switch(t.h){case 0:t.h!=0?Ls(t):vi(t.g);break;case 1:Wr(t=t.g,t.g+8);break;case 2:if(t.h!=2)Ls(t);else{var e=hr(t.g);Wr(t=t.g,t.g+e)}break;case 5:Wr(t=t.g,t.g+4);break;case 3:for(e=t.m;;){if(!Kl(t))throw Error("Unmatched start-group tag: stream EOF");if(t.h==4){if(t.m!=e)throw Error("Unmatched end-group tag");break}Ls(t)}break;default:throw jl(t.h,t.l)}}function ss(t,e,r){let n=t.g.l,s=hr(t.g),o=t.g.g+s,a=o-n;if(a<=0&&(t.g.l=o,r(e,t,void 0,void 0,void 0),a=o-t.g.g),a)throw Error(`Message parsing ended unexpectedly. Expected to read ${s} bytes, instead read ${s-a} bytes, either the data ended unexpectedly or the message misreported its own length`);return t.g.g=o,t.g.l=n,e}function wi(t){var e=hr(t.g),r=Yl(t=t.g,e);if(t=t.h,sp){var n,s=t;(n=ma)||(n=ma=new TextDecoder("utf-8",{fatal:!0})),e=r+e,s=r===0&&e===s.length?s:s.subarray(r,e);try{var o=n.decode(s)}catch(i){if(Rs===void 0){try{n.decode(new Uint8Array([128]))}catch{}try{n.decode(new Uint8Array([97])),Rs=!0}catch{Rs=!1}}throw!Rs&&(ma=void 0),i}}else{e=(o=r)+e,r=[];let i,u=null;for(;o<e;){var a=t[o++];a<128?r.push(a):a<224?o>=e?Nr():(i=t[o++],a<194||(192&i)!=128?(o--,Nr()):r.push((31&a)<<6|63&i)):a<240?o>=e-1?Nr():(i=t[o++],(192&i)!=128||a===224&&i<160||a===237&&i>=160||(192&(n=t[o++]))!=128?(o--,Nr()):r.push((15&a)<<12|(63&i)<<6|63&n)):a<=244?o>=e-2?Nr():(i=t[o++],(192&i)!=128||i-144+(a<<28)>>30!=0||(192&(n=t[o++]))!=128||(192&(s=t[o++]))!=128?(o--,Nr()):(a=(7&a)<<18|(63&i)<<12|(63&n)<<6|63&s,a-=65536,r.push(55296+(a>>10&1023),56320+(1023&a)))):Nr(),r.length>=8192&&(u=ac(u,r),r.length=0)}o=ac(u,r)}return o}function Zl(t){let e=hr(t.g);return ql(t.g,e)}function ao(t,e,r){var n=hr(t.g);for(n=t.g.g+n;t.g.g<n;)r.push(e(t.g))}var Cs=[],Xs;function Wt(t,e,r){e.g?e.m(t,e.g,e.h,r,!0):e.m(t,e.h,r,!0)}var V=class{constructor(t,e){this.u=Nl(t,e)}toJSON(){return Jl(this)}l(){var t=pm;return t.g?t.l(this,t.g,t.h,!0):t.l(this,t.h,t.defaultValue,!0)}clone(){let t=this.u;return di(this,t,oe(t),!1)}O(){return!!(2&Be(this.u))}};function Jl(t){t=t.u,t=Xs?t:no(t,fi,void 0,void 0,!1);{var e=!Xs;let l=t.length;if(l){var r=t[l-1],n=ti(r);n?l--:r=void 0;var s=t;if(n){e:{var o,a=r,i=!1;if(a)for(let c in a)isNaN(+c)?(o??(o={}))[c]=a[c]:(n=a[c],Array.isArray(n)&&(Vs(n)||dc(n)&&n.size===0)&&(n=null),n==null&&(i=!0),n!=null&&((o??(o={}))[c]=n));if(i||(o=a),o)for(let c in o){i=o;break e}i=null}a=i==null?r!=null:i!==r}for(;l>0&&((o=s[l-1])==null||Vs(o)||dc(o)&&o.size===0);l--)var u=!0;(s!==t||a||u)&&(e?(u||a||i)&&(s.length=l):s=Array.prototype.slice.call(s,0,l),i&&s.push(i)),u=s}else u=t}return u}function Ec(t){return t?/^\d+$/.test(t)?(to(t),new Ma(ie,Te)):null:Pp||(Pp=new Ma(0,0))}V.prototype.X=ns,V.prototype.toString=function(){try{return Xs=!0,Jl(this).toString()}finally{Xs=!1}};var Ma=class{constructor(t,e){this.h=t>>>0,this.g=e>>>0}},Pp;function Ac(t){return t?/^-?\d+$/.test(t)?(to(t),new Na(ie,Te)):null:Lp||(Lp=new Na(0,0))}var Na=class{constructor(t,e){this.h=t>>>0,this.g=e>>>0}},Lp;function on(t,e,r){for(;r>0||e>127;)t.g.push(127&e|128),e=(e>>>7|r<<25)>>>0,r>>>=7;t.g.push(e)}function wn(t,e){for(;e>127;)t.g.push(127&e|128),e>>>=7;t.g.push(e)}function io(t,e){if(e>=0)wn(t,e);else{for(let r=0;r<9;r++)t.g.push(127&e|128),e>>=7;t.g.push(1)}}function Qn(t,e){t.g.push(e>>>0&255),t.g.push(e>>>8&255),t.g.push(e>>>16&255),t.g.push(e>>>24&255)}function dn(t,e){e.length!==0&&(t.l.push(e),t.h+=e.length)}function gt(t,e,r){wn(t.g,8*e+r)}function Ti(t,e){return gt(t,e,2),e=t.g.end(),dn(t,e),e.push(t.h),e}function ki(t,e){var r=e.pop();for(r=t.h+t.g.length()-r;r>127;)e.push(127&r|128),r>>>=7,t.h++;e.push(r),t.h++}function uo(t,e,r){gt(t,e,2),wn(t.g,r.length),dn(t,t.g.end()),dn(t,r)}function Ys(t,e,r,n){r!=null&&(e=Ti(t,e),n(r,t),ki(t,e))}function $t(){let t=class{constructor(){throw Error()}};return Object.setPrototypeOf(t,t.prototype),t}var Ei=$t(),Ql=$t(),Ai=$t(),Ri=$t(),ef=$t(),tf=$t(),Ii=$t(),rf=$t(),nf=$t(),Tn=class{constructor(t,e,r){this.g=t,this.h=e,t=Ei,this.l=!!t&&r===t||!1}};function co(t,e){return new Tn(t,e,Ei)}function sf(t,e,r,n,s){Ys(t,r,cf(e,n),s)}var Op=co((function(t,e,r,n,s){return t.h===2&&(ss(t,yi(e,n,r),s),!0)}),sf),Dp=co((function(t,e,r,n,s){return t.h===2&&(ss(t,yi(e,n,r,!0),s),!0)}),sf),lo=Symbol(),Si=Symbol(),Rc=Symbol(),Ic=Symbol(),of,af;function Hr(t,e,r,n){var s=n[t];if(s)return s;(s={}).W=(function(f){switch(typeof f){case"boolean":return Ml||(Ml=[0,void 0,!0]);case"number":return f>0?void 0:f===0?Ep||(Ep=[0,void 0]):[-f,void 0];case"string":return[0,f];case"object":return f}})(n[0]);var o=n[1];let a=1;o&&o.constructor===Object&&(s.ha=o,typeof(o=n[++a])=="function"&&(s.ma=!0,of??(of=o),af??(af=n[a+1]),o=n[a+=2]));let i={};for(;o&&Array.isArray(o)&&o.length&&typeof o[0]=="number"&&o[0]>0;){for(var u=0;u<o.length;u++)i[o[u]]=o;o=n[++a]}for(u=1;o!==void 0;){let f;typeof o=="number"&&(u+=o,o=n[++a]);var l=void 0;if(o instanceof Tn?f=o:(f=Op,a--),f?.l){o=n[++a],l=n;var c=a;typeof o=="function"&&(o=o(),l[c]=o),l=o}for(c=u+1,typeof(o=n[++a])=="number"&&o<0&&(c-=o,o=n[++a]);u<c;u++){let d=i[u];l?r(s,u,f,l,d):e(s,u,f,d)}}return n[t]=s}function uf(t){return Array.isArray(t)?t[0]instanceof Tn?t:[Dp,t]:[t,void 0]}function cf(t,e){return t instanceof V?t.u:Array.isArray(t)?kr(t,e,!1):void 0}function Ci(t,e,r,n){let s=r.g;t[e]=n?(o,a,i)=>s(o,a,i,n):s}function Bi(t,e,r,n,s){let o=r.g,a,i;t[e]=(u,l,c)=>o(u,l,c,i||(i=Hr(Si,Ci,Bi,n).W),a||(a=Ui(n)),s)}function Ui(t){let e=t[Rc];if(e!=null)return e;let r=Hr(Si,Ci,Bi,t);return e=r.ma?(n,s)=>of(n,s,r):(n,s)=>{let o=oe(n);for(;Kl(s)&&s.h!=4;){var a=s.m,i=r[a];if(i==null){var u=r.ha;u&&(u=u[a])&&(u=Mp(u))!=null&&(i=r[a]=u)}i!=null&&i(s,n,a)||(a=(i=s).l,Ls(i),i.ga?i=void 0:(u=i.g.g-a,i.g.g=a,i=ql(i.g,u)),a=n,i&&(wr||(wr=Symbol()),(u=a[wr])?u.push(i):a[wr]=[i]))}return 16384&o&&xn(n),!0},t[Rc]=e}function Mp(t){let e=(t=uf(t))[0].g;if(t=t[1]){let r=Ui(t),n=Hr(Si,Ci,Bi,t).W;return(s,o,a)=>e(s,o,a,n,r)}return e}function fo(t,e,r){t[e]=r.h}function ho(t,e,r,n){let s,o,a=r.h;t[e]=(i,u,l)=>a(i,u,l,o||(o=Hr(lo,fo,ho,n).W),s||(s=lf(n)))}function lf(t){let e=t[Ic];if(!e){let r=Hr(lo,fo,ho,t);e=(n,s)=>ff(n,s,r),t[Ic]=e}return e}function ff(t,e,r){for(var n=Be(t),s=+!!(512&n)-1,o=t.length,a=512&n?1:0,i=o+(256&n?-1:0);a<i;a++){let u=t[a];if(u==null)continue;let l=a-s,c=Sc(r,l);c&&c(e,u,l)}if(256&n){n=t[o-1];for(let u in n)s=+u,Number.isNaN(s)||(o=n[s])!=null&&(i=Sc(r,s))&&i(e,o,s)}if(t=wr?t[wr]:void 0)for(dn(e,e.g.end()),r=0;r<t.length;r++)dn(e,Ja(t[r])||new Uint8Array(0))}function Sc(t,e){var r=t[e];if(r)return r;if((r=t.ha)&&(r=r[e])){var n=(r=uf(r))[0].h;if(r=r[1]){let s=lf(r),o=Hr(lo,fo,ho,r).W;r=t.ma?af(o,s):(a,i,u)=>n(a,i,u,o,s)}else r=n;return t[e]=r}}function kn(t,e){if(Array.isArray(e)){var r=Be(e);if(4&r)return e;for(var n=0,s=0;n<e.length;n++){let o=t(e[n]);o!=null&&(e[s++]=o)}return s<n&&(e.length=s),Oe(e,-12289&(5|r)),2&r&&Object.freeze(e),e}}function tt(t,e,r){return new Tn(t,e,r)}function En(t,e,r){return new Tn(t,e,r)}function rt(t,e,r){_e(t,oe(t),e,r)}var Np=co((function(t,e,r,n,s){return t.h===2&&(t=ss(t,kr([void 0,void 0],n,!0),s),Cr(n=oe(e)),(s=pr(e,n,r))instanceof St?(2&s.M)!=0?((s=s.Y()).push(t),_e(e,n,r,s)):s.Na(t):Array.isArray(s)?(2&Be(s)&&_e(e,n,r,s=Wl(s)),s.push(t)):_e(e,n,r,[t]),!0)}),(function(t,e,r,n,s){if(e instanceof St)e.forEach(((o,a)=>{Ys(t,r,kr([a,o],n,!1),s)}));else if(Array.isArray(e))for(let o=0;o<e.length;o++){let a=e[o];Array.isArray(a)&&Ys(t,r,kr(a,n,!1),s)}}));function df(t,e,r){if(e=(function(n){if(n==null)return n;let s=typeof n;if(s==="bigint")return String(BigInt.asIntN(64,n));if(ro(n)){if(s==="string")return ui(n);if(s==="number")return ii(n)}})(e),e!=null&&(typeof e=="string"&&Ac(e),e!=null))switch(gt(t,r,0),typeof e){case"number":t=t.g,ln(e),on(t,ie,Te);break;case"bigint":r=BigInt.asUintN(64,e),r=new Na(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),on(t.g,r.h,r.g);break;default:r=Ac(e),on(t.g,r.h,r.g)}}function hf(t,e,r){(e=_n(e))!=null&&e!=null&&(gt(t,r,0),io(t.g,e))}function pf(t,e,r){(e=Fl(e))!=null&&(gt(t,r,0),t.g.g.push(e?1:0))}function mf(t,e,r){(e=Tr(e))!=null&&uo(t,r,vl(e))}function gf(t,e,r,n,s){Ys(t,r,cf(e,n),s)}function yf(t,e,r){(e=e==null||typeof e=="string"||ts(e)||e instanceof lr?e:void 0)!=null&&uo(t,r,_i(e).buffer)}function xf(t,e,r){return(t.h===5||t.h===2)&&(e=vn(e,oe(e),r,!1,!1),t.h==2?ao(t,Da,e):e.push(Da(t.g)),!0)}var ur=tt((function(t,e,r){if(t.h!==1)return!1;var n=t.g;t=Oa(n);let s=Oa(n);n=2*(s>>31)+1;let o=s>>>20&2047;return t=4294967296*(1048575&s)+t,rt(e,r,o==2047?t?NaN:n*(1/0):o==0?5e-324*n*t:n*Math.pow(2,o-1075)*(t+4503599627370496)),!0}),(function(t,e,r){(e=Br(e))!=null&&(gt(t,r,1),t=t.g,(r=Ul||(Ul=new DataView(new ArrayBuffer(8)))).setFloat64(0,+e,!0),ie=r.getUint32(0,!0),Te=r.getUint32(4,!0),Qn(t,ie),Qn(t,Te))}),$t()),Ge=tt((function(t,e,r){return t.h===5&&(rt(e,r,Da(t.g)),!0)}),(function(t,e,r){(e=Br(e))!=null&&(gt(t,r,5),t=t.g,ni(e),Qn(t,ie))}),Ii),Gp=En(xf,(function(t,e,r){if((e=kn(Br,e))!=null)for(let a=0;a<e.length;a++){var n=t,s=r,o=e[a];o!=null&&(gt(n,s,5),n=n.g,ni(o),Qn(n,ie))}}),Ii),Fi=En(xf,(function(t,e,r){if((e=kn(Br,e))!=null&&e.length){gt(t,r,2),wn(t.g,4*e.length);for(let n=0;n<e.length;n++)r=t.g,ni(e[n]),Qn(r,ie)}}),Ii),Ir=tt((function(t,e,r){return t.h===0&&(rt(e,r,bi(t.g,oi)),!0)}),df,tf),Ta=tt((function(t,e,r){return t.h===0&&(rt(e,r,(t=bi(t.g,oi))===0?void 0:t),!0)}),df,tf),Vp=tt((function(t,e,r){return t.h===0&&(rt(e,r,bi(t.g,si)),!0)}),(function(t,e,r){if((e=Tp(e))!=null&&(typeof e=="string"&&Ec(e),e!=null))switch(gt(t,r,0),typeof e){case"number":t=t.g,ln(e),on(t,ie,Te);break;case"bigint":r=BigInt.asUintN(64,e),r=new Ma(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),on(t.g,r.h,r.g);break;default:r=Ec(e),on(t.g,r.h,r.g)}}),$t()),ke=tt((function(t,e,r){return t.h===0&&(rt(e,r,Rr(t.g)),!0)}),hf,Ri),po=En((function(t,e,r){return(t.h===0||t.h===2)&&(e=vn(e,oe(e),r,!1,!1),t.h==2?ao(t,Rr,e):e.push(Rr(t.g)),!0)}),(function(t,e,r){if((e=kn(_n,e))!=null&&e.length){r=Ti(t,r);for(let n=0;n<e.length;n++)io(t.g,e[n]);ki(t,r)}}),Ri),sn=tt((function(t,e,r){return t.h===0&&(rt(e,r,(t=Rr(t.g))===0?void 0:t),!0)}),hf,Ri),xe=tt((function(t,e,r){return t.h===0&&(rt(e,r,vi(t.g)),!0)}),pf,Ql),an=tt((function(t,e,r){return t.h===0&&(rt(e,r,(t=vi(t.g))===!1?void 0:t),!0)}),pf,Ql),Ke=En((function(t,e,r){return t.h===2&&(t=wi(t),vn(e,oe(e),r,!1).push(t),!0)}),(function(t,e,r){if((e=kn(Tr,e))!=null)for(let a=0;a<e.length;a++){var n=t,s=r,o=e[a];o!=null&&uo(n,s,vl(o))}}),Ai),vr=tt((function(t,e,r){return t.h===2&&(rt(e,r,(t=wi(t))===""?void 0:t),!0)}),mf,Ai),re=tt((function(t,e,r){return t.h===2&&(rt(e,r,wi(t)),!0)}),mf,Ai),Ne=(function(t,e,r=Ei){return new Tn(t,e,r)})((function(t,e,r,n,s){return t.h===2&&(n=kr(void 0,n,!0),vn(e,oe(e),r,!0).push(n),ss(t,n,s),!0)}),(function(t,e,r,n,s){if(Array.isArray(e))for(let o=0;o<e.length;o++)gf(t,e[o],r,n,s)})),se=co((function(t,e,r,n,s,o){return t.h===2&&($l(e,Be(e),o,r),ss(t,e=yi(e,n,r),s),!0)}),gf),_f=tt((function(t,e,r){return t.h===2&&(rt(e,r,Zl(t)),!0)}),yf,rf),Wp=En((function(t,e,r){return(t.h===0||t.h===2)&&(e=vn(e,oe(e),r,!1,!1),t.h==2?ao(t,hr,e):e.push(hr(t.g)),!0)}),(function(t,e,r){if((e=kn(Pl,e))!=null)for(let a=0;a<e.length;a++){var n=t,s=r,o=e[a];o!=null&&(gt(n,s,0),wn(n.g,o))}}),ef),$p=tt((function(t,e,r){return t.h===0&&(rt(e,r,(t=hr(t.g))===0?void 0:t),!0)}),(function(t,e,r){(e=Pl(e))!=null&&e!=null&&(gt(t,r,0),wn(t.g,e))}),ef),Vt=tt((function(t,e,r){return t.h===0&&(rt(e,r,Rr(t.g)),!0)}),(function(t,e,r){(e=_n(e))!=null&&(e=parseInt(e,10),gt(t,r,0),io(t.g,e))}),nf),Ga=class{constructor(e,r){this.h=e,this.g=r,this.l=q,this.m=z,this.defaultValue=void 0}};function zt(t,e){return new Ga(t,e)}function Ur(t,e){return(r,n)=>{if(Cs.length){let o=Cs.pop();o.o(n),wa(o.g,r,n),r=o}else r=new class{constructor(o,a){if(kc.length){let i=kc.pop();wa(i,o,a),o=i}else o=new class{constructor(i,u){this.h=null,this.m=!1,this.g=this.l=this.j=0,wa(this,i,u)}clear(){this.h=null,this.m=!1,this.g=this.l=this.j=0,this.ca=!1}}(o,a);this.g=o,this.l=this.g.g,this.h=this.m=-1,this.o(a)}o({ga:o=!1}={}){this.ga=o}}(r,n);try{let o=new t,a=o.u;Ui(e)(a,r);var s=o}finally{r.g.clear(),r.m=-1,r.h=-1,Cs.length<100&&Cs.push(r)}return s}}function mo(t){return function(){let e=new class{constructor(){this.l=[],this.h=0,this.g=new class{constructor(){this.g=[]}length(){return this.g.length}end(){let a=this.g;return this.g=[],a}}}};ff(this.u,e,Hr(lo,fo,ho,t)),dn(e,e.g.end());let r=new Uint8Array(e.h),n=e.l,s=n.length,o=0;for(let a=0;a<s;a++){let i=n[a];r.set(i,o),o+=i.length}return e.l=[r],r}}var Cc=class extends V{constructor(t){super(t)}},Bc=[0,vr,tt((function(t,e,r){return t.h===2&&(rt(e,r,(t=Zl(t))===zr()?void 0:t),!0)}),(function(t,e,r){if(e!=null){if(e instanceof V){let n=e.Qa;return void(n&&(e=n(e),e!=null&&uo(t,r,_i(e).buffer)))}if(Array.isArray(e))return}yf(t,e,r)}),rf)],ka,Uc=globalThis.trustedTypes;function Fc(t){ka===void 0&&(ka=(function(){let r=null;if(!Uc)return r;try{let n=s=>s;r=Uc.createPolicy("goog#html",{createHTML:n,createScript:n,createScriptURL:n})}catch{}return r})());var e=ka;return new class{constructor(r){this.g=r}toString(){return this.g+""}}(e?e.createScriptURL(t):t)}function zp(t,...e){if(e.length===0)return Fc(t[0]);let r=t[0];for(let n=0;n<e.length;n++)r+=encodeURIComponent(e[n])+t[n+1];return Fc(r)}var bf=[0,ke,Vt,xe,-1,po,Vt,-1],Hp=class extends V{constructor(){super()}},vf=[0,xe,re,xe,Vt,-1,En((function(t,e,r){return(t.h===0||t.h===2)&&(e=vn(e,oe(e),r,!1,!1),t.h==2?ao(t,Fp,e):e.push(Rr(t.g)),!0)}),(function(t,e,r){if((e=kn(_n,e))!=null&&e.length){r=Ti(t,r);for(let n=0;n<e.length;n++)io(t.g,e[n]);ki(t,r)}}),nf),re,-1,[0,xe,-1],Vt,xe,-1],wf=[0,re,-2],Pc=class extends V{constructor(){super()}},Tf=[0],kf=[0,ke,xe,1,xe,-3],mt=class extends V{constructor(t){super(t,2)}},De={};De[336783863]=[0,re,xe,-1,ke,[0,[1,2,3,4,5,6,7],se,Tf,se,vf,se,wf,se,kf,se,bf,se,[0,re,-2],se,[0,re,Vt]],[0,re],xe,[0,[1,3],[2,4],se,[0,po],-1,se,[0,Ke],-1,Ne,[0,re,-1]],re];var Lc=[0,Ta,-1,an,-3,Ta,po,vr,sn,Ta,-1,an,sn,an,-2,vr];function yt(t,e){La(t,2,bn(e),"")}function ce(t,e){oo(t,3,e)}function Y(t,e){oo(t,4,e)}var et=class extends V{constructor(t){super(t,500)}o(t){return z(this,0,7,t)}},Yn=[-1,{}],Oc=[0,re,1,Yn],Dc=[0,re,Ke,Yn];function xt(t,e){Hs(t,1,et,e)}function pe(t,e){oo(t,10,e)}function J(t,e){oo(t,15,e)}var at=class extends V{constructor(t){super(t,500)}o(t){return z(this,0,1001,t)}},Ef=[-500,Ne,[-500,vr,-1,Ke,-3,[-2,De,xe],Ne,Bc,sn,-1,Oc,Dc,Ne,[0,vr,an],vr,Lc,sn,Ke,987,Ke],4,Ne,[-500,re,-1,[-1,{}],998,re],Ne,[-500,re,Ke,-1,[-2,{},xe],997,Ke,-1],sn,Ne,[-500,re,Ke,Yn,998,Ke],Ke,sn,Oc,Dc,Ne,[0,vr,-1,Yn],Ke,-2,Lc,vr,-1,an,[0,an,$p],978,Yn,Ne,Bc];at.prototype.g=mo(Ef);var jp=Ur(at,Ef),Xp=class extends V{constructor(t){super(t)}},Af=class extends V{constructor(t){super(t)}g(){return dr(this,Xp,1)}},Rf=[0,Ne,[0,ke,Ge,re,-1]],go=Ur(Af,Rf),Yp=class extends V{constructor(t){super(t)}},qp=class extends V{constructor(t){super(t)}},Ea=class extends V{constructor(t){super(t)}h(){return q(this,Yp,2)}g(){return dr(this,qp,5)}},If=Ur(class extends V{constructor(t){super(t)}},[0,Ke,po,Fi,[0,Vt,[0,ke,-3],[0,Ge,-3],[0,ke,-1,[0,Ne,[0,ke,-2]]],Ne,[0,Ge,-1,re,Ge]],re,-1,Ir,Ne,[0,ke,Ge],Ke,Ir]),Sf=class extends V{constructor(t){super(t)}},un=Ur(class extends V{constructor(t){super(t)}},[0,Ne,[0,Ge,-4]]),Cf=class extends V{constructor(t){super(t)}},os=Ur(class extends V{constructor(t){super(t)}},[0,Ne,[0,Ge,-4]]),Kp=class extends V{constructor(t){super(t)}},Zp=[0,ke,-1,Fi,Vt],Bf=class extends V{constructor(){super()}};Bf.prototype.g=mo([0,Ge,-4,Ir]);var Jp=class extends V{constructor(t){super(t)}},Qp=Ur(class extends V{constructor(t){super(t)}},[0,Ne,[0,1,ke,re,Rf],Ir]),Mc=class extends V{constructor(t){super(t)}},em=class extends V{constructor(t){super(t)}pa(){let t=Vl(this);return t??zr()}},tm=class extends V{constructor(t){super(t)}},Uf=[1,2],rm=Ur(class extends V{constructor(t){super(t)}},[0,Ne,[0,Uf,se,[0,Fi],se,[0,_f],ke,re],Ir]),Pi=class extends V{constructor(t){super(t)}},Ff=[0,re,ke,Ge,Ke,-1],Nc=class extends V{constructor(t){super(t)}},nm=[0,xe,-1],Gc=class extends V{constructor(t){super(t)}},Os=[1,2,3,4,5],qs=class extends V{constructor(t){super(t)}g(){return Vl(this)!=null}h(){return Tr(Ar(this,2))!=null}},ye=class extends V{constructor(t){super(t)}g(){return Fl(Ar(this,2))??!1}},Pf=[0,_f,re,[0,ke,Ir,-1],[0,Vp,Ir]],Ue=[0,Pf,xe,[0,Os,se,kf,se,vf,se,bf,se,Tf,se,wf],Vt],yo=class extends V{constructor(t){super(t)}},Li=[0,Ue,Ge,-1,ke],sm=zt(502141897,yo);De[502141897]=Li;var om=Ur(class extends V{constructor(t){super(t)}},[0,[0,Vt,-1,Gp,Wp],Zp]),Lf=class extends V{constructor(t){super(t)}},Of=class extends V{constructor(t){super(t)}},Oi=[0,Ue,Ge,[0,Ue],xe],Df=[0,Ue,Li,Oi,Ge,[0,[0,Pf]]],am=zt(508968150,Of);De[508968150]=Df,De[508968149]=Oi;var Mf=class extends V{constructor(t){super(t)}},im=zt(513916220,Mf);De[513916220]=[0,Ue,Df,ke];var rn=class extends V{constructor(t){super(t)}h(){return q(this,Pi,2)}g(){ue(this,2)}},Nf=[0,Ue,Ff];De[478825465]=Nf;var um=class extends V{constructor(t){super(t)}},Gf=class extends V{constructor(t){super(t)}},Di=class extends V{constructor(t){super(t)}},Mi=class extends V{constructor(t){super(t)}},Vf=class extends V{constructor(t){super(t)}},Vc=[0,Ue,[0,Ue],Nf,-1],Wf=[0,Ue,Ge,ke],Ni=[0,Ue,Ge],$f=[0,Ue,Wf,Ni,Ge],cm=zt(479097054,Vf);De[479097054]=[0,Ue,$f,Vc],De[463370452]=Vc,De[464864288]=Wf;var lm=zt(462713202,Mi);De[462713202]=$f,De[474472470]=Ni;var fm=class extends V{constructor(t){super(t)}},zf=class extends V{constructor(t){super(t)}},Hf=class extends V{constructor(t){super(t)}},jf=class extends V{constructor(){super()}},Gi=[0,Ue,Ge,-1,ke],Va=[0,Ue,Ge,xe];jf.prototype.g=mo([0,Ue,Ni,[0,Ue],Li,Oi,Gi,Va]);var Xf=class extends V{constructor(t){super(t)}},dm=zt(456383383,Xf);De[456383383]=[0,Ue,Ff];var Yf=class extends V{constructor(t){super(t)}},hm=zt(476348187,Yf);De[476348187]=[0,Ue,nm];var qf=class extends V{constructor(t){super(t)}},Wc=class extends V{constructor(t){super(t)}},Kf=[0,Vt,-1],pm=zt(458105876,class extends V{constructor(t){super(t)}g(){var t=this.u;let e=oe(t),r=2&e;return t=(function(n,s,o){var a=Wc;let i=2&s,u=!1;if(o==null){if(i)return wc();o=[]}else if(o.constructor===St){if((2&o.M)==0||i)return o;o=o.Y()}else Array.isArray(o)?u=!!(2&Be(o)):o=[];if(i){if(!o.length)return wc();u||(u=!0,xn(o))}else u&&(u=!1,o=Wl(o));return u||(64&Be(o)?Ba(o,32):32&s&&Js(o,32)),_e(n,s,2,a=new St(o,a,kp,void 0)),a})(t,e,pr(t,e,2)),!r&&Wc&&(t.sa=!0),t}});De[458105876]=[0,Kf,Np,[!0,Ir,[0,re,-1,Ke]]];var Vi=class extends V{constructor(t){super(t)}},Zf=zt(458105758,Vi);De[458105758]=[0,Ue,re,Kf];var Jf=class extends V{constructor(t){super(t)}},mm=zt(443442058,Jf);De[443442058]=[0,Ue,re,ke,Ge,Ke,-1],De[514774813]=Gi;var Qf=class extends V{constructor(t){super(t)}},gm=zt(516587230,Qf);function Wa(t,e){return e=e?e.clone():new Pi,t.displayNamesLocale!==void 0?ue(e,1,bn(t.displayNamesLocale)):t.displayNamesLocale===void 0&&ue(e,1),t.maxResults!==void 0?rr(e,2,t.maxResults):"maxResults"in t&&ue(e,2),t.scoreThreshold!==void 0?W(e,3,t.scoreThreshold):"scoreThreshold"in t&&ue(e,3),t.categoryAllowlist!==void 0?js(e,4,t.categoryAllowlist):"categoryAllowlist"in t&&ue(e,4),t.categoryDenylist!==void 0?js(e,5,t.categoryDenylist):"categoryDenylist"in t&&ue(e,5),e}function Wi(t,e=-1,r=""){return{categories:t.map((n=>({index:Gt(It(n,1),0)??-1,score:Ce(n,2)??0,categoryName:tr(n,3)??"",displayName:tr(n,4)??""}))),headIndex:e,headName:r}}function ed(t){var e=Vr(t,3,Br,Gr()),r=Vr(t,2,_n,Gr()),n=Vr(t,1,Tr,Gr()),s=Vr(t,9,Tr,Gr());let o={categories:[],keypoints:[]};for(let a=0;a<e.length;a++)o.categories.push({score:e[a],index:r[a]??-1,categoryName:n[a]??"",displayName:s[a]??""});if((e=q(t,Ea,4)?.h())&&(o.boundingBox={originX:It(e,1)??0,originY:It(e,2)??0,width:It(e,3)??0,height:It(e,4)??0,angle:0}),q(t,Ea,4)?.g().length)for(let a of q(t,Ea,4).g())o.keypoints.push({x:Ps(a,1)??0,y:Ps(a,2)??0,score:Ps(a,4)??0,label:Tr(Ar(a,3))??""});return o}function xo(t){let e=[];for(let r of dr(t,Cf,1))e.push({x:Ce(r,1)??0,y:Ce(r,2)??0,z:Ce(r,3)??0,visibility:Ce(r,4)??0});return e}function qn(t){let e=[];for(let r of dr(t,Sf,1))e.push({x:Ce(r,1)??0,y:Ce(r,2)??0,z:Ce(r,3)??0,visibility:Ce(r,4)??0});return e}function $c(t){return Array.from(t,(e=>e>127?e-256:e))}function zc(t,e){if(t.length!==e.length)throw Error(`Cannot compute cosine similarity between embeddings of different sizes (${t.length} vs. ${e.length}).`);let r=0,n=0,s=0;for(let o=0;o<t.length;o++)r+=t[o]*e[o],n+=t[o]*t[o],s+=e[o]*e[o];if(n<=0||s<=0)throw Error("Cannot compute cosine similarity on embedding with 0 norm.");return r/Math.sqrt(n*s)}var Bs;De[516587230]=[0,Ue,Gi,Va,Ge],De[518928384]=Va;var ym=new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]);async function td(){if(Bs===void 0)try{await WebAssembly.instantiate(ym),Bs=!0}catch{Bs=!1}return Bs}async function Wn(t,e=zp``){let r=await td()?"wasm_internal":"wasm_nosimd_internal";return{wasmLoaderPath:`${e}/${t}_${r}.js`,wasmBinaryPath:`${e}/${t}_${r}.wasm`}}var _r=class{};function rd(){var t=navigator;return typeof OffscreenCanvas<"u"&&(!(function(e=navigator){return(e=e.userAgent).includes("Safari")&&!e.includes("Chrome")})(t)||!!((t=t.userAgent.match(/Version\/([\d]+).*Safari/))&&t.length>=1&&Number(t[1])>=17))}async function Hc(t){if(typeof importScripts!="function"){let e=document.createElement("script");return e.src=t.toString(),e.crossOrigin="anonymous",new Promise(((r,n)=>{e.addEventListener("load",(()=>{r()}),!1),e.addEventListener("error",(s=>{n(s)}),!1),document.body.appendChild(e)}))}importScripts(t.toString())}function nd(t){return t.videoWidth!==void 0?[t.videoWidth,t.videoHeight]:t.naturalWidth!==void 0?[t.naturalWidth,t.naturalHeight]:t.displayWidth!==void 0?[t.displayWidth,t.displayHeight]:[t.width,t.height]}function $(t,e,r){t.m||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target"),r(e=t.i.stringToNewUTF8(e)),t.i._free(e)}function jc(t,e,r){if(!t.i.canvas)throw Error("No OpenGL canvas configured.");if(r?t.i._bindTextureToStream(r):t.i._bindTextureToCanvas(),!(r=t.i.canvas.getContext("webgl2")||t.i.canvas.getContext("webgl")))throw Error("Failed to obtain WebGL context from the provided canvas. `getContext()` should only be invoked with `webgl` or `webgl2`.");t.i.gpuOriginForWebTexturesIsBottomLeft&&r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!0),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,e),t.i.gpuOriginForWebTexturesIsBottomLeft&&r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1);let[n,s]=nd(e);return!t.l||n===t.i.canvas.width&&s===t.i.canvas.height||(t.i.canvas.width=n,t.i.canvas.height=s),[n,s]}function Xc(t,e,r){t.m||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target");let n=new Uint32Array(e.length);for(let s=0;s<e.length;s++)n[s]=t.i.stringToNewUTF8(e[s]);e=t.i._malloc(4*n.length),t.i.HEAPU32.set(n,e>>2),r(e);for(let s of n)t.i._free(s);t.i._free(e)}function Zt(t,e,r){t.i.simpleListeners=t.i.simpleListeners||{},t.i.simpleListeners[e]=r}function xr(t,e,r){let n=[];t.i.simpleListeners=t.i.simpleListeners||{},t.i.simpleListeners[e]=(s,o,a)=>{o?(r(n,a),n=[]):n.push(s)}}_r.forVisionTasks=function(t){return Wn("vision",t)},_r.forTextTasks=function(t){return Wn("text",t)},_r.forGenAiExperimentalTasks=function(t){return Wn("genai_experimental",t)},_r.forGenAiTasks=function(t){return Wn("genai",t)},_r.forAudioTasks=function(t){return Wn("audio",t)},_r.isSimdSupported=function(){return td()};async function xm(t,e,r,n){return t=await(async(s,o,a,i,u)=>{if(o&&await Hc(o),!self.ModuleFactory||a&&(await Hc(a),!self.ModuleFactory))throw Error("ModuleFactory not set.");return self.Module&&u&&((o=self.Module).locateFile=u.locateFile,u.mainScriptUrlOrBlob&&(o.mainScriptUrlOrBlob=u.mainScriptUrlOrBlob)),u=await self.ModuleFactory(self.Module||u),self.ModuleFactory=self.Module=void 0,new s(u,i)})(t,r.wasmLoaderPath,r.assetLoaderPath,e,{locateFile:s=>s.endsWith(".wasm")?r.wasmBinaryPath.toString():r.assetBinaryPath&&s.endsWith(".data")?r.assetBinaryPath.toString():s}),await t.o(n),t}function Aa(t,e){let r=q(t.baseOptions,qs,1)||new qs;typeof e=="string"?(ue(r,2,bn(e)),ue(r,1)):e instanceof Uint8Array&&(ue(r,1,ri(e,!1)),ue(r,2)),z(t.baseOptions,0,1,r)}function Yc(t){try{let e=t.H.length;if(e===1)throw Error(t.H[0].message);if(e>1)throw Error("Encountered multiple errors: "+t.H.map((r=>r.message)).join(", "))}finally{t.H=[]}}function G(t,e){t.B=Math.max(t.B,e)}function _o(t,e){t.A=new et,yt(t.A,"PassThroughCalculator"),ce(t.A,"free_memory"),Y(t.A,"free_memory_unused_out"),pe(e,"free_memory"),xt(e,t.A)}function hn(t,e){ce(t.A,e),Y(t.A,e+"_unused_out")}function bo(t){t.g.addBoolToStream(!0,"free_memory",t.B)}var Ds=class{constructor(t){this.g=t,this.H=[],this.B=0,this.g.setAutoRenderToScreen(!1)}l(t,e=!0){if(e){let r=t.baseOptions||{};if(t.baseOptions?.modelAssetBuffer&&t.baseOptions?.modelAssetPath)throw Error("Cannot set both baseOptions.modelAssetPath and baseOptions.modelAssetBuffer");if(!(q(this.baseOptions,qs,1)?.g()||q(this.baseOptions,qs,1)?.h()||t.baseOptions?.modelAssetBuffer||t.baseOptions?.modelAssetPath))throw Error("Either baseOptions.modelAssetPath or baseOptions.modelAssetBuffer must be set");if((function(n,s){let o=q(n.baseOptions,Gc,3);if(!o){var a=o=new Gc,i=new Pc;Xn(a,4,Os,i)}"delegate"in s&&(s.delegate==="GPU"?(s=o,a=new Hp,Xn(s,2,Os,a)):(s=o,a=new Pc,Xn(s,4,Os,a))),z(n.baseOptions,0,3,o)})(this,r),r.modelAssetPath)return fetch(r.modelAssetPath.toString()).then((n=>{if(n.ok)return n.arrayBuffer();throw Error(`Failed to fetch model: ${r.modelAssetPath} (${n.status})`)})).then((n=>{try{this.g.i.FS_unlink("/model.dat")}catch{}this.g.i.FS_createDataFile("/","model.dat",new Uint8Array(n),!0,!1,!1),Aa(this,"/model.dat"),this.m(),this.J()}));if(r.modelAssetBuffer instanceof Uint8Array)Aa(this,r.modelAssetBuffer);else if(r.modelAssetBuffer)return(async function(n){let s=[];for(var o=0;;){let{done:a,value:i}=await n.read();if(a)break;s.push(i),o+=i.length}if(s.length===0)return new Uint8Array(0);if(s.length===1)return s[0];n=new Uint8Array(o),o=0;for(let a of s)n.set(a,o),o+=a.length;return n})(r.modelAssetBuffer).then((n=>{Aa(this,n),this.m(),this.J()}))}return this.m(),this.J(),Promise.resolve()}J(){}ea(){let t;if(this.g.ea((e=>{t=jp(e)})),!t)throw Error("Failed to retrieve CalculatorGraphConfig");return t}setGraph(t,e){this.g.attachErrorListener(((r,n)=>{this.H.push(Error(n))})),this.g.La(),this.g.setGraph(t,e),this.A=void 0,Yc(this)}finishProcessing(){this.g.finishProcessing(),Yc(this)}close(){this.A=void 0,this.g.closeGraph()}};function Qe(t,e){if(!t)throw Error(`Unable to obtain required WebGL resource: ${e}`);return t}Ds.prototype.close=Ds.prototype.close,bl("TaskRunner",Ds);var $a=class{constructor(e,r,n,s){this.g=e,this.h=r,this.m=n,this.l=s}bind(){this.g.bindVertexArray(this.h)}close(){this.g.deleteVertexArray(this.h),this.g.deleteBuffer(this.m),this.g.deleteBuffer(this.l)}};function qc(t,e,r){let n=t.g;if(r=Qe(n.createShader(r),"Failed to create WebGL shader"),n.shaderSource(r,e),n.compileShader(r),!n.getShaderParameter(r,n.COMPILE_STATUS))throw Error(`Could not compile WebGL shader: ${n.getShaderInfoLog(r)}`);return n.attachShader(t.h,r),r}function Kc(t,e){let r=t.g,n=Qe(r.createVertexArray(),"Failed to create vertex array");r.bindVertexArray(n);let s=Qe(r.createBuffer(),"Failed to create buffer");r.bindBuffer(r.ARRAY_BUFFER,s),r.enableVertexAttribArray(t.P),r.vertexAttribPointer(t.P,2,r.FLOAT,!1,0,0),r.bufferData(r.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,1,1,-1]),r.STATIC_DRAW);let o=Qe(r.createBuffer(),"Failed to create buffer");return r.bindBuffer(r.ARRAY_BUFFER,o),r.enableVertexAttribArray(t.J),r.vertexAttribPointer(t.J,2,r.FLOAT,!1,0,0),r.bufferData(r.ARRAY_BUFFER,new Float32Array(e?[0,1,0,0,1,0,1,1]:[0,0,0,1,1,1,1,0]),r.STATIC_DRAW),r.bindBuffer(r.ARRAY_BUFFER,null),r.bindVertexArray(null),new $a(r,n,s,o)}function $i(t,e){if(t.g){if(e!==t.g)throw Error("Cannot change GL context once initialized")}else t.g=e}function as(t,e,r,n){return $i(t,e),t.h||(t.m(),t.C()),r?(t.s||(t.s=Kc(t,!0)),r=t.s):(t.v||(t.v=Kc(t,!1)),r=t.v),e.useProgram(t.h),r.bind(),t.l(),t=n(),r.g.bindVertexArray(null),t}function Sr(t,e,r){return $i(t,e),t=Qe(e.createTexture(),"Failed to create texture"),e.bindTexture(e.TEXTURE_2D,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,r??e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,r??e.LINEAR),e.bindTexture(e.TEXTURE_2D,null),t}function vo(t,e,r){$i(t,e),t.A||(t.A=Qe(e.createFramebuffer(),"Failed to create framebuffe.")),e.bindFramebuffer(e.FRAMEBUFFER,t.A),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,r,0)}function zi(t){t.g?.bindFramebuffer(t.g.FRAMEBUFFER,null)}var An=class{H(){return`
2
2
  precision mediump float;
3
3
  varying vec2 vTex;
4
4
  uniform sampler2D inputTexture;
5
5
  void main() {
6
6
  gl_FragColor = texture2D(inputTexture, vTex);
7
7
  }
8
- `}m(){let t=this.g;if(this.h=Ke(t.createProgram(),"Failed to create WebGL program"),this.ba=yc(this,`
8
+ `}m(){let t=this.g;if(this.h=Qe(t.createProgram(),"Failed to create WebGL program"),this.ba=qc(this,`
9
9
  attribute vec2 aVertex;
10
10
  attribute vec2 aTex;
11
11
  varying vec2 vTex;
12
12
  void main(void) {
13
13
  gl_Position = vec4(aVertex, 0.0, 1.0);
14
14
  vTex = aTex;
15
- }`,t.VERTEX_SHADER),this.aa=yc(this,this.H(),t.FRAGMENT_SHADER),t.linkProgram(this.h),!t.getProgramParameter(this.h,t.LINK_STATUS))throw Error(`Error during program linking: ${t.getProgramInfoLog(this.h)}`);this.P=t.getAttribLocation(this.h,"aVertex"),this.J=t.getAttribLocation(this.h,"aTex")}C(){}l(){}close(){if(this.h){let t=this.g;t.deleteProgram(this.h),t.deleteShader(this.ba),t.deleteShader(this.aa)}this.A&&this.g.deleteFramebuffer(this.A),this.v&&this.v.close(),this.s&&this.s.close()}},bm=class extends gn{H(){return`
15
+ }`,t.VERTEX_SHADER),this.aa=qc(this,this.H(),t.FRAGMENT_SHADER),t.linkProgram(this.h),!t.getProgramParameter(this.h,t.LINK_STATUS))throw Error(`Error during program linking: ${t.getProgramInfoLog(this.h)}`);this.P=t.getAttribLocation(this.h,"aVertex"),this.J=t.getAttribLocation(this.h,"aTex")}C(){}l(){}close(){if(this.h){let t=this.g;t.deleteProgram(this.h),t.deleteShader(this.ba),t.deleteShader(this.aa)}this.A&&this.g.deleteFramebuffer(this.A),this.v&&this.v.close(),this.s&&this.s.close()}},_m=class extends An{H(){return`
16
16
  precision mediump float;
17
17
  uniform sampler2D backgroundTexture;
18
18
  uniform sampler2D maskTexture;
@@ -24,7 +24,7 @@ var Pr=typeof self<"u"?self:{};function $c(t,e){t=t.split(".");var r,n=Pr;for((t
24
24
  vec4 categoryColor = texture2D(colorMappingTexture, vec2(category, 0.0));
25
25
  gl_FragColor = mix(backgroundColor, categoryColor, categoryColor.a);
26
26
  }
27
- `}C(){let t=this.g;t.activeTexture(t.TEXTURE1),this.B=wr(this,t,t.LINEAR),t.activeTexture(t.TEXTURE2),this.j=wr(this,t,t.NEAREST)}m(){super.m();let t=this.g;this.L=Ke(t.getUniformLocation(this.h,"backgroundTexture"),"Uniform location"),this.U=Ke(t.getUniformLocation(this.h,"colorMappingTexture"),"Uniform location"),this.K=Ke(t.getUniformLocation(this.h,"maskTexture"),"Uniform location")}l(){super.l();let t=this.g;t.uniform1i(this.K,0),t.uniform1i(this.L,1),t.uniform1i(this.U,2)}close(){this.B&&this.g.deleteTexture(this.B),this.j&&this.g.deleteTexture(this.j),super.close()}},vm=class extends gn{H(){return`
27
+ `}C(){let t=this.g;t.activeTexture(t.TEXTURE1),this.B=Sr(this,t,t.LINEAR),t.activeTexture(t.TEXTURE2),this.j=Sr(this,t,t.NEAREST)}m(){super.m();let t=this.g;this.L=Qe(t.getUniformLocation(this.h,"backgroundTexture"),"Uniform location"),this.U=Qe(t.getUniformLocation(this.h,"colorMappingTexture"),"Uniform location"),this.K=Qe(t.getUniformLocation(this.h,"maskTexture"),"Uniform location")}l(){super.l();let t=this.g;t.uniform1i(this.K,0),t.uniform1i(this.L,1),t.uniform1i(this.U,2)}close(){this.B&&this.g.deleteTexture(this.B),this.j&&this.g.deleteTexture(this.j),super.close()}},bm=class extends An{H(){return`
28
28
  precision mediump float;
29
29
  uniform sampler2D maskTexture;
30
30
  uniform sampler2D defaultTexture;
@@ -38,38 +38,38 @@ var Pr=typeof self<"u"?self:{};function $c(t,e){t=t.split(".");var r,n=Pr;for((t
38
38
  overlayColor = mix(defaultColor, overlayColor, overlayColor.a);
39
39
  gl_FragColor = mix(defaultColor, overlayColor, confidence);
40
40
  }
41
- `}C(){let t=this.g;t.activeTexture(t.TEXTURE1),this.j=wr(this,t),t.activeTexture(t.TEXTURE2),this.B=wr(this,t)}m(){super.m();let t=this.g;this.K=Ke(t.getUniformLocation(this.h,"defaultTexture"),"Uniform location"),this.L=Ke(t.getUniformLocation(this.h,"overlayTexture"),"Uniform location"),this.I=Ke(t.getUniformLocation(this.h,"maskTexture"),"Uniform location")}l(){super.l();let t=this.g;t.uniform1i(this.I,0),t.uniform1i(this.K,1),t.uniform1i(this.L,2)}close(){this.j&&this.g.deleteTexture(this.j),this.B&&this.g.deleteTexture(this.B),super.close()}};function rr(t,e){switch(e){case 0:return t.g.find((r=>r instanceof Uint8Array));case 1:return t.g.find((r=>r instanceof Float32Array));case 2:return t.g.find((r=>typeof WebGLTexture<"u"&&r instanceof WebGLTexture));default:throw Error(`Type is not supported: ${e}`)}}function va(t){var e=rr(t,1);if(!e){if(e=rr(t,0))e=new Float32Array(e).map((n=>n/255));else{e=new Float32Array(t.width*t.height);let n=nn(t);var r=wi(t);if(to(r,n,Rf(t)),"iPad Simulator;iPhone Simulator;iPod Simulator;iPad;iPhone;iPod".split(";").includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"document"in self&&"ontouchend"in self.document){r=new Float32Array(t.width*t.height*4),n.readPixels(0,0,t.width,t.height,n.RGBA,n.FLOAT,r);for(let s=0,o=0;s<e.length;++s,o+=4)e[s]=r[o]}else n.readPixels(0,0,t.width,t.height,n.RED,n.FLOAT,e)}t.g.push(e)}return e}function Rf(t){let e=rr(t,2);if(!e){let r=nn(t);e=Sf(t);let n=va(t),s=If(t);r.texImage2D(r.TEXTURE_2D,0,s,t.width,t.height,0,r.RED,r.FLOAT,n),wa(t)}return e}function nn(t){if(!t.canvas)throw Error("Conversion to different image formats require that a canvas is passed when initializing the image.");return t.h||(t.h=Ke(t.canvas.getContext("webgl2"),"You cannot use a canvas that is already bound to a different type of rendering context.")),t.h}function If(t){if(t=nn(t),!ds)if(t.getExtension("EXT_color_buffer_float")&&t.getExtension("OES_texture_float_linear")&&t.getExtension("EXT_float_blend"))ds=t.R32F;else{if(!t.getExtension("EXT_color_buffer_half_float"))throw Error("GPU does not fully support 4-channel float32 or float16 formats");ds=t.R16F}return ds}function wi(t){return t.l||(t.l=new gn),t.l}function Sf(t){let e=nn(t);e.viewport(0,0,t.width,t.height),e.activeTexture(e.TEXTURE0);let r=rr(t,2);return r||(r=wr(wi(t),e,t.m?e.LINEAR:e.NEAREST),t.g.push(r),t.j=!0),e.bindTexture(e.TEXTURE_2D,r),r}function wa(t){t.h.bindTexture(t.h.TEXTURE_2D,null)}var ds,Pe=class{constructor(t,e,r,n,s,o,a){this.g=t,this.m=e,this.j=r,this.canvas=n,this.l=s,this.width=o,this.height=a,this.j&&--bc===0&&console.error("You seem to be creating MPMask instances without invoking .close(). This leaks resources.")}Ga(){return!!rr(this,0)}ka(){return!!rr(this,1)}R(){return!!rr(this,2)}ja(){return(e=rr(t=this,0))||(e=va(t),e=new Uint8Array(e.map((r=>255*r))),t.g.push(e)),e;var t,e}ia(){return va(this)}N(){return Rf(this)}clone(){let t=[];for(let e of this.g){let r;if(e instanceof Uint8Array)r=new Uint8Array(e);else if(e instanceof Float32Array)r=new Float32Array(e);else{if(!(e instanceof WebGLTexture))throw Error(`Type is not supported: ${e}`);{let n=nn(this),s=wi(this);n.activeTexture(n.TEXTURE1),r=wr(s,n,this.m?n.LINEAR:n.NEAREST),n.bindTexture(n.TEXTURE_2D,r);let o=If(this);n.texImage2D(n.TEXTURE_2D,0,o,this.width,this.height,0,n.RED,n.FLOAT,null),n.bindTexture(n.TEXTURE_2D,null),to(s,n,r),Kn(s,n,!1,(()=>{Sf(this),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.drawArrays(n.TRIANGLE_FAN,0,4),wa(this)})),vi(s),wa(this)}}t.push(r)}return new Pe(t,this.m,this.R(),this.canvas,this.l,this.width,this.height)}close(){this.j&&nn(this).deleteTexture(rr(this,2)),bc=-1}};Pe.prototype.close=Pe.prototype.close,Pe.prototype.clone=Pe.prototype.clone,Pe.prototype.getAsWebGLTexture=Pe.prototype.N,Pe.prototype.getAsFloat32Array=Pe.prototype.ia,Pe.prototype.getAsUint8Array=Pe.prototype.ja,Pe.prototype.hasWebGLTexture=Pe.prototype.R,Pe.prototype.hasFloat32Array=Pe.prototype.ka,Pe.prototype.hasUint8Array=Pe.prototype.Ga;var bc=250,wm={color:"white",lineWidth:4,radius:6};function sa(t){return{...wm,fillColor:(t=t||{}).color,...t}}function er(t,e){return t instanceof Function?t(e):t}function vc(t,e,r){return Math.max(Math.min(e,r),Math.min(Math.max(e,r),t))}function Bn(t){if(!t.l)throw Error("CPU rendering requested but CanvasRenderingContext2D not provided.");return t.l}function zn(t){if(!t.j)throw Error("GPU rendering requested but WebGL2RenderingContext not provided.");return t.j}function wc(t,e,r){if(e.R())r(e.N());else{let n=e.ka()?e.ia():e.ja();t.m=t.m??new gn;let s=zn(t);r((t=new Pe([n],e.m,!1,s.canvas,t.m,e.width,e.height)).N()),t.close()}}function Tc(t,e,r,n){let s=(function(i){return i.g||(i.g=new bm),i.g})(t),o=zn(t),a=Array.isArray(r)?new ImageData(new Uint8ClampedArray(r),1,1):r;Kn(s,o,!0,(()=>{(function(u,l,c,f){let d=u.g;if(d.activeTexture(d.TEXTURE0),d.bindTexture(d.TEXTURE_2D,l),d.activeTexture(d.TEXTURE1),d.bindTexture(d.TEXTURE_2D,u.B),d.texImage2D(d.TEXTURE_2D,0,d.RGBA,d.RGBA,d.UNSIGNED_BYTE,c),u.I&&(function(p,T){if(p!==T)return!1;p=p.entries(),T=T.entries();for(let[E,I]of p){p=E;let _=I;var A=T.next();if(A.done)return!1;let[v,R]=A.value;if(A=R,p!==v||_[0]!==A[0]||_[1]!==A[1]||_[2]!==A[2]||_[3]!==A[3])return!1}return!!T.next().done})(u.I,f))d.activeTexture(d.TEXTURE2),d.bindTexture(d.TEXTURE_2D,u.j);else{u.I=f;let p=Array(1024).fill(0);f.forEach(((T,A)=>{if(T.length!==4)throw Error(`Color at index ${A} is not a four-channel value.`);p[4*A]=T[0],p[4*A+1]=T[1],p[4*A+2]=T[2],p[4*A+3]=T[3]})),d.activeTexture(d.TEXTURE2),d.bindTexture(d.TEXTURE_2D,u.j),d.texImage2D(d.TEXTURE_2D,0,d.RGBA,256,1,0,d.RGBA,d.UNSIGNED_BYTE,new Uint8Array(p))}})(s,e,a,n),o.clearColor(0,0,0,0),o.clear(o.COLOR_BUFFER_BIT),o.drawArrays(o.TRIANGLE_FAN,0,4);let i=s.g;i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,null),i.activeTexture(i.TEXTURE1),i.bindTexture(i.TEXTURE_2D,null),i.activeTexture(i.TEXTURE2),i.bindTexture(i.TEXTURE_2D,null)}))}function kc(t,e,r,n){let s=zn(t),o=(function(u){return u.h||(u.h=new vm),u.h})(t),a=Array.isArray(r)?new ImageData(new Uint8ClampedArray(r),1,1):r,i=Array.isArray(n)?new ImageData(new Uint8ClampedArray(n),1,1):n;Kn(o,s,!0,(()=>{var u=o.g;u.activeTexture(u.TEXTURE0),u.bindTexture(u.TEXTURE_2D,e),u.activeTexture(u.TEXTURE1),u.bindTexture(u.TEXTURE_2D,o.j),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,u.RGBA,u.UNSIGNED_BYTE,a),u.activeTexture(u.TEXTURE2),u.bindTexture(u.TEXTURE_2D,o.B),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,u.RGBA,u.UNSIGNED_BYTE,i),s.clearColor(0,0,0,0),s.clear(s.COLOR_BUFFER_BIT),s.drawArrays(s.TRIANGLE_FAN,0,4),s.bindTexture(s.TEXTURE_2D,null),(u=o.g).activeTexture(u.TEXTURE0),u.bindTexture(u.TEXTURE_2D,null),u.activeTexture(u.TEXTURE1),u.bindTexture(u.TEXTURE_2D,null),u.activeTexture(u.TEXTURE2),u.bindTexture(u.TEXTURE_2D,null)}))}var qe=class{constructor(t,e){t instanceof CanvasRenderingContext2D||t instanceof OffscreenCanvasRenderingContext2D?(this.l=t,this.j=e):this.j=t}za(t,e){if(t){var r=Bn(this);e=sa(e),r.save();var n=r.canvas,s=0;for(let o of t)r.fillStyle=er(e.fillColor,{index:s,from:o}),r.strokeStyle=er(e.color,{index:s,from:o}),r.lineWidth=er(e.lineWidth,{index:s,from:o}),(t=new Path2D).arc(o.x*n.width,o.y*n.height,er(e.radius,{index:s,from:o}),0,2*Math.PI),r.fill(t),r.stroke(t),++s;r.restore()}}ya(t,e,r){if(t&&e){var n=Bn(this);r=sa(r),n.save();var s=n.canvas,o=0;for(let a of e){n.beginPath(),e=t[a.start];let i=t[a.end];e&&i&&(n.strokeStyle=er(r.color,{index:o,from:e,to:i}),n.lineWidth=er(r.lineWidth,{index:o,from:e,to:i}),n.moveTo(e.x*s.width,e.y*s.height),n.lineTo(i.x*s.width,i.y*s.height)),++o,n.stroke()}n.restore()}}va(t,e){let r=Bn(this);e=sa(e),r.save(),r.beginPath(),r.lineWidth=er(e.lineWidth,{}),r.strokeStyle=er(e.color,{}),r.fillStyle=er(e.fillColor,{}),r.moveTo(t.originX,t.originY),r.lineTo(t.originX+t.width,t.originY),r.lineTo(t.originX+t.width,t.originY+t.height),r.lineTo(t.originX,t.originY+t.height),r.lineTo(t.originX,t.originY),r.stroke(),r.fill(),r.restore()}wa(t,e,r=[0,0,0,255]){this.l?(function(n,s,o,a){let i=zn(n);wc(n,s,(u=>{Tc(n,u,o,a),(u=Bn(n)).drawImage(i.canvas,0,0,u.canvas.width,u.canvas.height)}))})(this,t,r,e):Tc(this,t.N(),r,e)}xa(t,e,r){this.l?(function(n,s,o,a){let i=zn(n);wc(n,s,(u=>{kc(n,u,o,a),(u=Bn(n)).drawImage(i.canvas,0,0,u.canvas.width,u.canvas.height)}))})(this,t,e,r):kc(this,t.N(),e,r)}close(){this.g?.close(),this.g=void 0,this.h?.close(),this.h=void 0,this.m?.close(),this.m=void 0}};function Xt(t,e){switch(e){case 0:return t.g.find((r=>r instanceof ImageData));case 1:return t.g.find((r=>typeof ImageBitmap<"u"&&r instanceof ImageBitmap));case 2:return t.g.find((r=>typeof WebGLTexture<"u"&&r instanceof WebGLTexture));default:throw Error(`Type is not supported: ${e}`)}}function Cf(t){var e=Xt(t,0);if(!e){e=sn(t);let r=ro(t),n=new Uint8Array(t.width*t.height*4);to(r,e,_s(t)),e.readPixels(0,0,t.width,t.height,e.RGBA,e.UNSIGNED_BYTE,n),vi(r),e=new ImageData(new Uint8ClampedArray(n.buffer),t.width,t.height),t.g.push(e)}return e}function _s(t){let e=Xt(t,2);if(!e){let r=sn(t);e=bs(t);let n=Xt(t,1)||Cf(t);r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,n),Pn(t)}return e}function sn(t){if(!t.canvas)throw Error("Conversion to different image formats require that a canvas is passed when iniitializing the image.");return t.h||(t.h=Ke(t.canvas.getContext("webgl2"),"You cannot use a canvas that is already bound to a different type of rendering context.")),t.h}function ro(t){return t.l||(t.l=new gn),t.l}function bs(t){let e=sn(t);e.viewport(0,0,t.width,t.height),e.activeTexture(e.TEXTURE0);let r=Xt(t,2);return r||(r=wr(ro(t),e),t.g.push(r),t.m=!0),e.bindTexture(e.TEXTURE_2D,r),r}function Pn(t){t.h.bindTexture(t.h.TEXTURE_2D,null)}function Ec(t){let e=sn(t);return Kn(ro(t),e,!0,(()=>(function(r,n){let s=r.canvas;if(s.width===r.width&&s.height===r.height)return n();let o=s.width,a=s.height;return s.width=r.width,s.height=r.height,r=n(),s.width=o,s.height=a,r})(t,(()=>{if(e.bindFramebuffer(e.FRAMEBUFFER,null),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),e.drawArrays(e.TRIANGLE_FAN,0,4),!(t.canvas instanceof OffscreenCanvas))throw Error("Conversion to ImageBitmap requires that the MediaPipe Tasks is initialized with an OffscreenCanvas");return t.canvas.transferToImageBitmap()}))))}qe.prototype.close=qe.prototype.close,qe.prototype.drawConfidenceMask=qe.prototype.xa,qe.prototype.drawCategoryMask=qe.prototype.wa,qe.prototype.drawBoundingBox=qe.prototype.va,qe.prototype.drawConnectors=qe.prototype.ya,qe.prototype.drawLandmarks=qe.prototype.za,qe.lerp=function(t,e,r,n,s){return vc(n*(1-(t-e)/(r-e))+s*(1-(r-t)/(r-e)),n,s)},qe.clamp=vc,$c("DrawingUtils",qe);var Ne=class{constructor(t,e,r,n,s,o,a){this.g=t,this.j=e,this.m=r,this.canvas=n,this.l=s,this.width=o,this.height=a,(this.j||this.m)&&--Ac===0&&console.error("You seem to be creating MPImage instances without invoking .close(). This leaks resources.")}Fa(){return!!Xt(this,0)}la(){return!!Xt(this,1)}R(){return!!Xt(this,2)}Da(){return Cf(this)}Ca(){var t=Xt(this,1);return t||(_s(this),bs(this),t=Ec(this),Pn(this),this.g.push(t),this.j=!0),t}N(){return _s(this)}clone(){let t=[];for(let e of this.g){let r;if(e instanceof ImageData)r=new ImageData(e.data,this.width,this.height);else if(e instanceof WebGLTexture){let n=sn(this),s=ro(this);n.activeTexture(n.TEXTURE1),r=wr(s,n),n.bindTexture(n.TEXTURE_2D,r),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,this.width,this.height,0,n.RGBA,n.UNSIGNED_BYTE,null),n.bindTexture(n.TEXTURE_2D,null),to(s,n,r),Kn(s,n,!1,(()=>{bs(this),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.drawArrays(n.TRIANGLE_FAN,0,4),Pn(this)})),vi(s),Pn(this)}else{if(!(e instanceof ImageBitmap))throw Error(`Type is not supported: ${e}`);_s(this),bs(this),r=Ec(this),Pn(this)}t.push(r)}return new Ne(t,this.la(),this.R(),this.canvas,this.l,this.width,this.height)}close(){this.j&&Xt(this,1).close(),this.m&&sn(this).deleteTexture(Xt(this,2)),Ac=-1}};Ne.prototype.close=Ne.prototype.close,Ne.prototype.clone=Ne.prototype.clone,Ne.prototype.getAsWebGLTexture=Ne.prototype.N,Ne.prototype.getAsImageBitmap=Ne.prototype.Ca,Ne.prototype.getAsImageData=Ne.prototype.Da,Ne.prototype.hasWebGLTexture=Ne.prototype.R,Ne.prototype.hasImageBitmap=Ne.prototype.la,Ne.prototype.hasImageData=Ne.prototype.Fa;var Ac=250;function Mt(...t){return t.map((([e,r])=>({start:e,end:r})))}var Tm=(function(t){return class extends t{La(){this.i._registerModelResourcesGraphService()}}})((Rc=class{constructor(t,e){this.l=!0,this.i=t,this.g=null,this.h=0,this.m=typeof this.i._addIntToInputStream=="function",e!==void 0?this.i.canvas=e:Ef()?this.i.canvas=new OffscreenCanvas(1,1):(console.warn("OffscreenCanvas not supported and GraphRunner constructor glCanvas parameter is undefined. Creating backup canvas."),this.i.canvas=document.createElement("canvas"))}async initializeGraph(t){let e=await(await fetch(t)).arrayBuffer();t=!(t.endsWith(".pbtxt")||t.endsWith(".textproto")),this.setGraph(new Uint8Array(e),t)}setGraphFromString(t){this.setGraph(new TextEncoder().encode(t),!1)}setGraph(t,e){let r=t.length,n=this.i._malloc(r);this.i.HEAPU8.set(t,n),e?this.i._changeBinaryGraph(r,n):this.i._changeTextGraph(r,n),this.i._free(n)}configureAudio(t,e,r,n,s){this.i._configureAudio||console.warn('Attempting to use configureAudio without support for input audio. Is build dep ":gl_graph_runner_audio" missing?'),$(this,n||"input_audio",(o=>{$(this,s=s||"audio_header",(a=>{this.i._configureAudio(o,a,t,e??0,r)}))}))}setAutoResizeCanvas(t){this.l=t}setAutoRenderToScreen(t){this.i._setAutoRenderToScreen(t)}setGpuBufferVerticalFlip(t){this.i.gpuOriginForWebTexturesIsBottomLeft=t}ea(t){$t(this,"__graph_config__",(e=>{t(e)})),$(this,"__graph_config__",(e=>{this.i._getGraphConfig(e,void 0)})),delete this.i.simpleListeners.__graph_config__}attachErrorListener(t){this.i.errorListener=t}attachEmptyPacketListener(t,e){this.i.emptyPacketListeners=this.i.emptyPacketListeners||{},this.i.emptyPacketListeners[t]=e}addAudioToStream(t,e,r){this.addAudioToStreamWithShape(t,0,0,e,r)}addAudioToStreamWithShape(t,e,r,n,s){let o=4*t.length;this.h!==o&&(this.g&&this.i._free(this.g),this.g=this.i._malloc(o),this.h=o),this.i.HEAPF32.set(t,this.g/4),$(this,n,(a=>{this.i._addAudioToInputStream(this.g,e,r,a,s)}))}addGpuBufferToStream(t,e,r){$(this,e,(n=>{let[s,o]=pc(this,t,n);this.i._addBoundTextureToStream(n,s,o,r)}))}addBoolToStream(t,e,r){$(this,e,(n=>{this.i._addBoolToInputStream(t,n,r)}))}addDoubleToStream(t,e,r){$(this,e,(n=>{this.i._addDoubleToInputStream(t,n,r)}))}addFloatToStream(t,e,r){$(this,e,(n=>{this.i._addFloatToInputStream(t,n,r)}))}addIntToStream(t,e,r){$(this,e,(n=>{this.i._addIntToInputStream(t,n,r)}))}addUintToStream(t,e,r){$(this,e,(n=>{this.i._addUintToInputStream(t,n,r)}))}addStringToStream(t,e,r){$(this,e,(n=>{$(this,t,(s=>{this.i._addStringToInputStream(s,n,r)}))}))}addStringRecordToStream(t,e,r){$(this,e,(n=>{gc(this,Object.keys(t),(s=>{gc(this,Object.values(t),(o=>{this.i._addFlatHashMapToInputStream(s,o,Object.keys(t).length,n,r)}))}))}))}addProtoToStream(t,e,r,n){$(this,r,(s=>{$(this,e,(o=>{let a=this.i._malloc(t.length);this.i.HEAPU8.set(t,a),this.i._addProtoToInputStream(a,t.length,o,s,n),this.i._free(a)}))}))}addEmptyPacketToStream(t,e){$(this,t,(r=>{this.i._addEmptyPacketToInputStream(r,e)}))}addBoolVectorToStream(t,e,r){$(this,e,(n=>{let s=this.i._allocateBoolVector(t.length);if(!s)throw Error("Unable to allocate new bool vector on heap.");for(let o of t)this.i._addBoolVectorEntry(s,o);this.i._addBoolVectorToInputStream(s,n,r)}))}addDoubleVectorToStream(t,e,r){$(this,e,(n=>{let s=this.i._allocateDoubleVector(t.length);if(!s)throw Error("Unable to allocate new double vector on heap.");for(let o of t)this.i._addDoubleVectorEntry(s,o);this.i._addDoubleVectorToInputStream(s,n,r)}))}addFloatVectorToStream(t,e,r){$(this,e,(n=>{let s=this.i._allocateFloatVector(t.length);if(!s)throw Error("Unable to allocate new float vector on heap.");for(let o of t)this.i._addFloatVectorEntry(s,o);this.i._addFloatVectorToInputStream(s,n,r)}))}addIntVectorToStream(t,e,r){$(this,e,(n=>{let s=this.i._allocateIntVector(t.length);if(!s)throw Error("Unable to allocate new int vector on heap.");for(let o of t)this.i._addIntVectorEntry(s,o);this.i._addIntVectorToInputStream(s,n,r)}))}addUintVectorToStream(t,e,r){$(this,e,(n=>{let s=this.i._allocateUintVector(t.length);if(!s)throw Error("Unable to allocate new unsigned int vector on heap.");for(let o of t)this.i._addUintVectorEntry(s,o);this.i._addUintVectorToInputStream(s,n,r)}))}addStringVectorToStream(t,e,r){$(this,e,(n=>{let s=this.i._allocateStringVector(t.length);if(!s)throw Error("Unable to allocate new string vector on heap.");for(let o of t)$(this,o,(a=>{this.i._addStringVectorEntry(s,a)}));this.i._addStringVectorToInputStream(s,n,r)}))}addBoolToInputSidePacket(t,e){$(this,e,(r=>{this.i._addBoolToInputSidePacket(t,r)}))}addDoubleToInputSidePacket(t,e){$(this,e,(r=>{this.i._addDoubleToInputSidePacket(t,r)}))}addFloatToInputSidePacket(t,e){$(this,e,(r=>{this.i._addFloatToInputSidePacket(t,r)}))}addIntToInputSidePacket(t,e){$(this,e,(r=>{this.i._addIntToInputSidePacket(t,r)}))}addUintToInputSidePacket(t,e){$(this,e,(r=>{this.i._addUintToInputSidePacket(t,r)}))}addStringToInputSidePacket(t,e){$(this,e,(r=>{$(this,t,(n=>{this.i._addStringToInputSidePacket(n,r)}))}))}addProtoToInputSidePacket(t,e,r){$(this,r,(n=>{$(this,e,(s=>{let o=this.i._malloc(t.length);this.i.HEAPU8.set(t,o),this.i._addProtoToInputSidePacket(o,t.length,s,n),this.i._free(o)}))}))}addBoolVectorToInputSidePacket(t,e){$(this,e,(r=>{let n=this.i._allocateBoolVector(t.length);if(!n)throw Error("Unable to allocate new bool vector on heap.");for(let s of t)this.i._addBoolVectorEntry(n,s);this.i._addBoolVectorToInputSidePacket(n,r)}))}addDoubleVectorToInputSidePacket(t,e){$(this,e,(r=>{let n=this.i._allocateDoubleVector(t.length);if(!n)throw Error("Unable to allocate new double vector on heap.");for(let s of t)this.i._addDoubleVectorEntry(n,s);this.i._addDoubleVectorToInputSidePacket(n,r)}))}addFloatVectorToInputSidePacket(t,e){$(this,e,(r=>{let n=this.i._allocateFloatVector(t.length);if(!n)throw Error("Unable to allocate new float vector on heap.");for(let s of t)this.i._addFloatVectorEntry(n,s);this.i._addFloatVectorToInputSidePacket(n,r)}))}addIntVectorToInputSidePacket(t,e){$(this,e,(r=>{let n=this.i._allocateIntVector(t.length);if(!n)throw Error("Unable to allocate new int vector on heap.");for(let s of t)this.i._addIntVectorEntry(n,s);this.i._addIntVectorToInputSidePacket(n,r)}))}addUintVectorToInputSidePacket(t,e){$(this,e,(r=>{let n=this.i._allocateUintVector(t.length);if(!n)throw Error("Unable to allocate new unsigned int vector on heap.");for(let s of t)this.i._addUintVectorEntry(n,s);this.i._addUintVectorToInputSidePacket(n,r)}))}addStringVectorToInputSidePacket(t,e){$(this,e,(r=>{let n=this.i._allocateStringVector(t.length);if(!n)throw Error("Unable to allocate new string vector on heap.");for(let s of t)$(this,s,(o=>{this.i._addStringVectorEntry(n,o)}));this.i._addStringVectorToInputSidePacket(n,r)}))}attachBoolListener(t,e){$t(this,t,e),$(this,t,(r=>{this.i._attachBoolListener(r)}))}attachBoolVectorListener(t,e){fr(this,t,e),$(this,t,(r=>{this.i._attachBoolVectorListener(r)}))}attachIntListener(t,e){$t(this,t,e),$(this,t,(r=>{this.i._attachIntListener(r)}))}attachIntVectorListener(t,e){fr(this,t,e),$(this,t,(r=>{this.i._attachIntVectorListener(r)}))}attachUintListener(t,e){$t(this,t,e),$(this,t,(r=>{this.i._attachUintListener(r)}))}attachUintVectorListener(t,e){fr(this,t,e),$(this,t,(r=>{this.i._attachUintVectorListener(r)}))}attachDoubleListener(t,e){$t(this,t,e),$(this,t,(r=>{this.i._attachDoubleListener(r)}))}attachDoubleVectorListener(t,e){fr(this,t,e),$(this,t,(r=>{this.i._attachDoubleVectorListener(r)}))}attachFloatListener(t,e){$t(this,t,e),$(this,t,(r=>{this.i._attachFloatListener(r)}))}attachFloatVectorListener(t,e){fr(this,t,e),$(this,t,(r=>{this.i._attachFloatVectorListener(r)}))}attachStringListener(t,e){$t(this,t,e),$(this,t,(r=>{this.i._attachStringListener(r)}))}attachStringVectorListener(t,e){fr(this,t,e),$(this,t,(r=>{this.i._attachStringVectorListener(r)}))}attachProtoListener(t,e,r){$t(this,t,e),$(this,t,(n=>{this.i._attachProtoListener(n,r||!1)}))}attachProtoVectorListener(t,e,r){fr(this,t,e),$(this,t,(n=>{this.i._attachProtoVectorListener(n,r||!1)}))}attachAudioListener(t,e,r){this.i._attachAudioListener||console.warn('Attempting to use attachAudioListener without support for output audio. Is build dep ":gl_graph_runner_audio_out" missing?'),$t(this,t,((n,s)=>{n=new Float32Array(n.buffer,n.byteOffset,n.length/4),e(n,s)})),$(this,t,(n=>{this.i._attachAudioListener(n,r||!1)}))}finishProcessing(){this.i._waitUntilIdle()}closeGraph(){this.i._closeGraph(),this.i.simpleListeners=void 0,this.i.emptyPacketListeners=void 0}},class extends Rc{get fa(){return this.i}ra(t,e,r){$(this,e,(n=>{let[s,o]=pc(this,t,n);this.fa._addBoundTextureAsImageToStream(n,s,o,r)}))}V(t,e){$t(this,t,e),$(this,t,(r=>{this.fa._attachImageListener(r)}))}da(t,e){fr(this,t,e),$(this,t,(r=>{this.fa._attachImageVectorListener(r)}))}})),Rc,kt=class extends Tm{};async function j(t,e,r){return(async function(n,s,o,a){return _m(n,s,o,a)})(t,r.canvas??(Ef()?void 0:document.createElement("canvas")),e,r)}function Ff(t,e,r,n){if(t.U){let o=new Ql;if(r?.regionOfInterest){if(!t.qa)throw Error("This task doesn't support region-of-interest.");var s=r.regionOfInterest;if(s.left>=s.right||s.top>=s.bottom)throw Error("Expected RectF with left < right and top < bottom.");if(s.left<0||s.top<0||s.right>1||s.bottom>1)throw Error("Expected RectF values to be in [0,1].");W(o,1,(s.left+s.right)/2),W(o,2,(s.top+s.bottom)/2),W(o,4,s.right-s.left),W(o,3,s.bottom-s.top)}else W(o,1,.5),W(o,2,.5),W(o,4,1),W(o,3,1);if(r?.rotationDegrees){if(r?.rotationDegrees%90!=0)throw Error("Expected rotation to be a multiple of 90\xB0.");if(W(o,5,-Math.PI*r.rotationDegrees/180),r?.rotationDegrees%180!=0){let[a,i]=Af(e);r=Ie(o,3)*i/a,s=Ie(o,4)*a/i,W(o,4,r),W(o,3,s)}}t.g.addProtoToStream(o.g(),"mediapipe.NormalizedRect",t.U,n)}t.g.ra(e,t.ba,n??performance.now()),t.finishProcessing()}function Et(t,e,r){if(t.baseOptions?.g())throw Error("Task is not initialized with image mode. 'runningMode' must be set to 'IMAGE'.");Ff(t,e,r,t.B+1)}function qt(t,e,r,n){if(!t.baseOptions?.g())throw Error("Task is not initialized with video mode. 'runningMode' must be set to 'VIDEO'.");Ff(t,e,r,n)}function on(t,e,r,n){var s=e.data;let o=e.width,a=o*(e=e.height);if((s instanceof Uint8Array||s instanceof Float32Array)&&s.length!==a)throw Error("Unsupported channel count: "+s.length/a);return t=new Pe([s],r,!1,t.g.i.canvas,t.P,o,e),n?t.clone():t}var rt=class extends ys{constructor(t,e,r,n){super(t),this.g=t,this.ba=e,this.U=r,this.qa=n,this.P=new gn}l(t,e=!0){if("runningMode"in t&&Wn(this.baseOptions,2,!!t.runningMode&&t.runningMode!=="IMAGE"),t.canvas!==void 0&&this.g.i.canvas!==t.canvas)throw Error("You must create a new task to reset the canvas.");return super.l(t,e)}close(){this.P.close(),super.close()}};rt.prototype.close=rt.prototype.close;var yt=class extends rt{constructor(t,e){super(new kt(t,e),"image_in","norm_rect_in",!1),this.j={detections:[]},z(t=this.h=new Zs,0,1,e=new ge),W(this.h,2,.5),W(this.h,3,.3)}get baseOptions(){return q(this.h,ge,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){return"minDetectionConfidence"in t&&W(this.h,2,t.minDetectionConfidence??.5),"minSuppressionThreshold"in t&&W(this.h,3,t.minSuppressionThreshold??.3),this.l(t)}D(t,e){return this.j={detections:[]},Et(this,t,e),this.j}F(t,e,r){return this.j={detections:[]},qt(this,t,r,e),this.j}m(){var t=new nt;de(t,"image_in"),de(t,"norm_rect_in"),J(t,"detections");let e=new lt;Pt(e,om,this.h);let r=new Ze;ht(r,"mediapipe.tasks.vision.face_detector.FaceDetectorGraph"),ce(r,"IMAGE:image_in"),ce(r,"NORM_RECT:norm_rect_in"),Y(r,"DETECTIONS:detections"),r.o(e),dt(t,r),this.g.attachProtoVectorListener("detections",((n,s)=>{for(let o of n)n=Kl(o),this.j.detections.push(Tf(n));G(this,s)})),this.g.attachEmptyPacketListener("detections",(n=>{G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};yt.prototype.detectForVideo=yt.prototype.F,yt.prototype.detect=yt.prototype.D,yt.prototype.setOptions=yt.prototype.o,yt.createFromModelPath=async function(t,e){return j(yt,t,{baseOptions:{modelAssetPath:e}})},yt.createFromModelBuffer=function(t,e){return j(yt,t,{baseOptions:{modelAssetBuffer:e}})},yt.createFromOptions=function(t,e){return j(yt,t,e)};var Ti=Mt([61,146],[146,91],[91,181],[181,84],[84,17],[17,314],[314,405],[405,321],[321,375],[375,291],[61,185],[185,40],[40,39],[39,37],[37,0],[0,267],[267,269],[269,270],[270,409],[409,291],[78,95],[95,88],[88,178],[178,87],[87,14],[14,317],[317,402],[402,318],[318,324],[324,308],[78,191],[191,80],[80,81],[81,82],[82,13],[13,312],[312,311],[311,310],[310,415],[415,308]),ki=Mt([263,249],[249,390],[390,373],[373,374],[374,380],[380,381],[381,382],[382,362],[263,466],[466,388],[388,387],[387,386],[386,385],[385,384],[384,398],[398,362]),Ei=Mt([276,283],[283,282],[282,295],[295,285],[300,293],[293,334],[334,296],[296,336]),Uf=Mt([474,475],[475,476],[476,477],[477,474]),Ai=Mt([33,7],[7,163],[163,144],[144,145],[145,153],[153,154],[154,155],[155,133],[33,246],[246,161],[161,160],[160,159],[159,158],[158,157],[157,173],[173,133]),Ri=Mt([46,53],[53,52],[52,65],[65,55],[70,63],[63,105],[105,66],[66,107]),Bf=Mt([469,470],[470,471],[471,472],[472,469]),Ii=Mt([10,338],[338,297],[297,332],[332,284],[284,251],[251,389],[389,356],[356,454],[454,323],[323,361],[361,288],[288,397],[397,365],[365,379],[379,378],[378,400],[400,377],[377,152],[152,148],[148,176],[176,149],[149,150],[150,136],[136,172],[172,58],[58,132],[132,93],[93,234],[234,127],[127,162],[162,21],[21,54],[54,103],[103,67],[67,109],[109,10]),Lf=[...Ti,...ki,...Ei,...Ai,...Ri,...Ii],Pf=Mt([127,34],[34,139],[139,127],[11,0],[0,37],[37,11],[232,231],[231,120],[120,232],[72,37],[37,39],[39,72],[128,121],[121,47],[47,128],[232,121],[121,128],[128,232],[104,69],[69,67],[67,104],[175,171],[171,148],[148,175],[118,50],[50,101],[101,118],[73,39],[39,40],[40,73],[9,151],[151,108],[108,9],[48,115],[115,131],[131,48],[194,204],[204,211],[211,194],[74,40],[40,185],[185,74],[80,42],[42,183],[183,80],[40,92],[92,186],[186,40],[230,229],[229,118],[118,230],[202,212],[212,214],[214,202],[83,18],[18,17],[17,83],[76,61],[61,146],[146,76],[160,29],[29,30],[30,160],[56,157],[157,173],[173,56],[106,204],[204,194],[194,106],[135,214],[214,192],[192,135],[203,165],[165,98],[98,203],[21,71],[71,68],[68,21],[51,45],[45,4],[4,51],[144,24],[24,23],[23,144],[77,146],[146,91],[91,77],[205,50],[50,187],[187,205],[201,200],[200,18],[18,201],[91,106],[106,182],[182,91],[90,91],[91,181],[181,90],[85,84],[84,17],[17,85],[206,203],[203,36],[36,206],[148,171],[171,140],[140,148],[92,40],[40,39],[39,92],[193,189],[189,244],[244,193],[159,158],[158,28],[28,159],[247,246],[246,161],[161,247],[236,3],[3,196],[196,236],[54,68],[68,104],[104,54],[193,168],[168,8],[8,193],[117,228],[228,31],[31,117],[189,193],[193,55],[55,189],[98,97],[97,99],[99,98],[126,47],[47,100],[100,126],[166,79],[79,218],[218,166],[155,154],[154,26],[26,155],[209,49],[49,131],[131,209],[135,136],[136,150],[150,135],[47,126],[126,217],[217,47],[223,52],[52,53],[53,223],[45,51],[51,134],[134,45],[211,170],[170,140],[140,211],[67,69],[69,108],[108,67],[43,106],[106,91],[91,43],[230,119],[119,120],[120,230],[226,130],[130,247],[247,226],[63,53],[53,52],[52,63],[238,20],[20,242],[242,238],[46,70],[70,156],[156,46],[78,62],[62,96],[96,78],[46,53],[53,63],[63,46],[143,34],[34,227],[227,143],[123,117],[117,111],[111,123],[44,125],[125,19],[19,44],[236,134],[134,51],[51,236],[216,206],[206,205],[205,216],[154,153],[153,22],[22,154],[39,37],[37,167],[167,39],[200,201],[201,208],[208,200],[36,142],[142,100],[100,36],[57,212],[212,202],[202,57],[20,60],[60,99],[99,20],[28,158],[158,157],[157,28],[35,226],[226,113],[113,35],[160,159],[159,27],[27,160],[204,202],[202,210],[210,204],[113,225],[225,46],[46,113],[43,202],[202,204],[204,43],[62,76],[76,77],[77,62],[137,123],[123,116],[116,137],[41,38],[38,72],[72,41],[203,129],[129,142],[142,203],[64,98],[98,240],[240,64],[49,102],[102,64],[64,49],[41,73],[73,74],[74,41],[212,216],[216,207],[207,212],[42,74],[74,184],[184,42],[169,170],[170,211],[211,169],[170,149],[149,176],[176,170],[105,66],[66,69],[69,105],[122,6],[6,168],[168,122],[123,147],[147,187],[187,123],[96,77],[77,90],[90,96],[65,55],[55,107],[107,65],[89,90],[90,180],[180,89],[101,100],[100,120],[120,101],[63,105],[105,104],[104,63],[93,137],[137,227],[227,93],[15,86],[86,85],[85,15],[129,102],[102,49],[49,129],[14,87],[87,86],[86,14],[55,8],[8,9],[9,55],[100,47],[47,121],[121,100],[145,23],[23,22],[22,145],[88,89],[89,179],[179,88],[6,122],[122,196],[196,6],[88,95],[95,96],[96,88],[138,172],[172,136],[136,138],[215,58],[58,172],[172,215],[115,48],[48,219],[219,115],[42,80],[80,81],[81,42],[195,3],[3,51],[51,195],[43,146],[146,61],[61,43],[171,175],[175,199],[199,171],[81,82],[82,38],[38,81],[53,46],[46,225],[225,53],[144,163],[163,110],[110,144],[52,65],[65,66],[66,52],[229,228],[228,117],[117,229],[34,127],[127,234],[234,34],[107,108],[108,69],[69,107],[109,108],[108,151],[151,109],[48,64],[64,235],[235,48],[62,78],[78,191],[191,62],[129,209],[209,126],[126,129],[111,35],[35,143],[143,111],[117,123],[123,50],[50,117],[222,65],[65,52],[52,222],[19,125],[125,141],[141,19],[221,55],[55,65],[65,221],[3,195],[195,197],[197,3],[25,7],[7,33],[33,25],[220,237],[237,44],[44,220],[70,71],[71,139],[139,70],[122,193],[193,245],[245,122],[247,130],[130,33],[33,247],[71,21],[21,162],[162,71],[170,169],[169,150],[150,170],[188,174],[174,196],[196,188],[216,186],[186,92],[92,216],[2,97],[97,167],[167,2],[141,125],[125,241],[241,141],[164,167],[167,37],[37,164],[72,38],[38,12],[12,72],[38,82],[82,13],[13,38],[63,68],[68,71],[71,63],[226,35],[35,111],[111,226],[101,50],[50,205],[205,101],[206,92],[92,165],[165,206],[209,198],[198,217],[217,209],[165,167],[167,97],[97,165],[220,115],[115,218],[218,220],[133,112],[112,243],[243,133],[239,238],[238,241],[241,239],[214,135],[135,169],[169,214],[190,173],[173,133],[133,190],[171,208],[208,32],[32,171],[125,44],[44,237],[237,125],[86,87],[87,178],[178,86],[85,86],[86,179],[179,85],[84,85],[85,180],[180,84],[83,84],[84,181],[181,83],[201,83],[83,182],[182,201],[137,93],[93,132],[132,137],[76,62],[62,183],[183,76],[61,76],[76,184],[184,61],[57,61],[61,185],[185,57],[212,57],[57,186],[186,212],[214,207],[207,187],[187,214],[34,143],[143,156],[156,34],[79,239],[239,237],[237,79],[123,137],[137,177],[177,123],[44,1],[1,4],[4,44],[201,194],[194,32],[32,201],[64,102],[102,129],[129,64],[213,215],[215,138],[138,213],[59,166],[166,219],[219,59],[242,99],[99,97],[97,242],[2,94],[94,141],[141,2],[75,59],[59,235],[235,75],[24,110],[110,228],[228,24],[25,130],[130,226],[226,25],[23,24],[24,229],[229,23],[22,23],[23,230],[230,22],[26,22],[22,231],[231,26],[112,26],[26,232],[232,112],[189,190],[190,243],[243,189],[221,56],[56,190],[190,221],[28,56],[56,221],[221,28],[27,28],[28,222],[222,27],[29,27],[27,223],[223,29],[30,29],[29,224],[224,30],[247,30],[30,225],[225,247],[238,79],[79,20],[20,238],[166,59],[59,75],[75,166],[60,75],[75,240],[240,60],[147,177],[177,215],[215,147],[20,79],[79,166],[166,20],[187,147],[147,213],[213,187],[112,233],[233,244],[244,112],[233,128],[128,245],[245,233],[128,114],[114,188],[188,128],[114,217],[217,174],[174,114],[131,115],[115,220],[220,131],[217,198],[198,236],[236,217],[198,131],[131,134],[134,198],[177,132],[132,58],[58,177],[143,35],[35,124],[124,143],[110,163],[163,7],[7,110],[228,110],[110,25],[25,228],[356,389],[389,368],[368,356],[11,302],[302,267],[267,11],[452,350],[350,349],[349,452],[302,303],[303,269],[269,302],[357,343],[343,277],[277,357],[452,453],[453,357],[357,452],[333,332],[332,297],[297,333],[175,152],[152,377],[377,175],[347,348],[348,330],[330,347],[303,304],[304,270],[270,303],[9,336],[336,337],[337,9],[278,279],[279,360],[360,278],[418,262],[262,431],[431,418],[304,408],[408,409],[409,304],[310,415],[415,407],[407,310],[270,409],[409,410],[410,270],[450,348],[348,347],[347,450],[422,430],[430,434],[434,422],[313,314],[314,17],[17,313],[306,307],[307,375],[375,306],[387,388],[388,260],[260,387],[286,414],[414,398],[398,286],[335,406],[406,418],[418,335],[364,367],[367,416],[416,364],[423,358],[358,327],[327,423],[251,284],[284,298],[298,251],[281,5],[5,4],[4,281],[373,374],[374,253],[253,373],[307,320],[320,321],[321,307],[425,427],[427,411],[411,425],[421,313],[313,18],[18,421],[321,405],[405,406],[406,321],[320,404],[404,405],[405,320],[315,16],[16,17],[17,315],[426,425],[425,266],[266,426],[377,400],[400,369],[369,377],[322,391],[391,269],[269,322],[417,465],[465,464],[464,417],[386,257],[257,258],[258,386],[466,260],[260,388],[388,466],[456,399],[399,419],[419,456],[284,332],[332,333],[333,284],[417,285],[285,8],[8,417],[346,340],[340,261],[261,346],[413,441],[441,285],[285,413],[327,460],[460,328],[328,327],[355,371],[371,329],[329,355],[392,439],[439,438],[438,392],[382,341],[341,256],[256,382],[429,420],[420,360],[360,429],[364,394],[394,379],[379,364],[277,343],[343,437],[437,277],[443,444],[444,283],[283,443],[275,440],[440,363],[363,275],[431,262],[262,369],[369,431],[297,338],[338,337],[337,297],[273,375],[375,321],[321,273],[450,451],[451,349],[349,450],[446,342],[342,467],[467,446],[293,334],[334,282],[282,293],[458,461],[461,462],[462,458],[276,353],[353,383],[383,276],[308,324],[324,325],[325,308],[276,300],[300,293],[293,276],[372,345],[345,447],[447,372],[352,345],[345,340],[340,352],[274,1],[1,19],[19,274],[456,248],[248,281],[281,456],[436,427],[427,425],[425,436],[381,256],[256,252],[252,381],[269,391],[391,393],[393,269],[200,199],[199,428],[428,200],[266,330],[330,329],[329,266],[287,273],[273,422],[422,287],[250,462],[462,328],[328,250],[258,286],[286,384],[384,258],[265,353],[353,342],[342,265],[387,259],[259,257],[257,387],[424,431],[431,430],[430,424],[342,353],[353,276],[276,342],[273,335],[335,424],[424,273],[292,325],[325,307],[307,292],[366,447],[447,345],[345,366],[271,303],[303,302],[302,271],[423,266],[266,371],[371,423],[294,455],[455,460],[460,294],[279,278],[278,294],[294,279],[271,272],[272,304],[304,271],[432,434],[434,427],[427,432],[272,407],[407,408],[408,272],[394,430],[430,431],[431,394],[395,369],[369,400],[400,395],[334,333],[333,299],[299,334],[351,417],[417,168],[168,351],[352,280],[280,411],[411,352],[325,319],[319,320],[320,325],[295,296],[296,336],[336,295],[319,403],[403,404],[404,319],[330,348],[348,349],[349,330],[293,298],[298,333],[333,293],[323,454],[454,447],[447,323],[15,16],[16,315],[315,15],[358,429],[429,279],[279,358],[14,15],[15,316],[316,14],[285,336],[336,9],[9,285],[329,349],[349,350],[350,329],[374,380],[380,252],[252,374],[318,402],[402,403],[403,318],[6,197],[197,419],[419,6],[318,319],[319,325],[325,318],[367,364],[364,365],[365,367],[435,367],[367,397],[397,435],[344,438],[438,439],[439,344],[272,271],[271,311],[311,272],[195,5],[5,281],[281,195],[273,287],[287,291],[291,273],[396,428],[428,199],[199,396],[311,271],[271,268],[268,311],[283,444],[444,445],[445,283],[373,254],[254,339],[339,373],[282,334],[334,296],[296,282],[449,347],[347,346],[346,449],[264,447],[447,454],[454,264],[336,296],[296,299],[299,336],[338,10],[10,151],[151,338],[278,439],[439,455],[455,278],[292,407],[407,415],[415,292],[358,371],[371,355],[355,358],[340,345],[345,372],[372,340],[346,347],[347,280],[280,346],[442,443],[443,282],[282,442],[19,94],[94,370],[370,19],[441,442],[442,295],[295,441],[248,419],[419,197],[197,248],[263,255],[255,359],[359,263],[440,275],[275,274],[274,440],[300,383],[383,368],[368,300],[351,412],[412,465],[465,351],[263,467],[467,466],[466,263],[301,368],[368,389],[389,301],[395,378],[378,379],[379,395],[412,351],[351,419],[419,412],[436,426],[426,322],[322,436],[2,164],[164,393],[393,2],[370,462],[462,461],[461,370],[164,0],[0,267],[267,164],[302,11],[11,12],[12,302],[268,12],[12,13],[13,268],[293,300],[300,301],[301,293],[446,261],[261,340],[340,446],[330,266],[266,425],[425,330],[426,423],[423,391],[391,426],[429,355],[355,437],[437,429],[391,327],[327,326],[326,391],[440,457],[457,438],[438,440],[341,382],[382,362],[362,341],[459,457],[457,461],[461,459],[434,430],[430,394],[394,434],[414,463],[463,362],[362,414],[396,369],[369,262],[262,396],[354,461],[461,457],[457,354],[316,403],[403,402],[402,316],[315,404],[404,403],[403,315],[314,405],[405,404],[404,314],[313,406],[406,405],[405,313],[421,418],[418,406],[406,421],[366,401],[401,361],[361,366],[306,408],[408,407],[407,306],[291,409],[409,408],[408,291],[287,410],[410,409],[409,287],[432,436],[436,410],[410,432],[434,416],[416,411],[411,434],[264,368],[368,383],[383,264],[309,438],[438,457],[457,309],[352,376],[376,401],[401,352],[274,275],[275,4],[4,274],[421,428],[428,262],[262,421],[294,327],[327,358],[358,294],[433,416],[416,367],[367,433],[289,455],[455,439],[439,289],[462,370],[370,326],[326,462],[2,326],[326,370],[370,2],[305,460],[460,455],[455,305],[254,449],[449,448],[448,254],[255,261],[261,446],[446,255],[253,450],[450,449],[449,253],[252,451],[451,450],[450,252],[256,452],[452,451],[451,256],[341,453],[453,452],[452,341],[413,464],[464,463],[463,413],[441,413],[413,414],[414,441],[258,442],[442,441],[441,258],[257,443],[443,442],[442,257],[259,444],[444,443],[443,259],[260,445],[445,444],[444,260],[467,342],[342,445],[445,467],[459,458],[458,250],[250,459],[289,392],[392,290],[290,289],[290,328],[328,460],[460,290],[376,433],[433,435],[435,376],[250,290],[290,392],[392,250],[411,416],[416,433],[433,411],[341,463],[463,464],[464,341],[453,464],[464,465],[465,453],[357,465],[465,412],[412,357],[343,412],[412,399],[399,343],[360,363],[363,440],[440,360],[437,399],[399,456],[456,437],[420,456],[456,363],[363,420],[401,435],[435,288],[288,401],[372,383],[383,353],[353,372],[339,255],[255,249],[249,339],[448,261],[261,255],[255,448],[133,243],[243,190],[190,133],[133,155],[155,112],[112,133],[33,246],[246,247],[247,33],[33,130],[130,25],[25,33],[398,384],[384,286],[286,398],[362,398],[398,414],[414,362],[362,463],[463,341],[341,362],[263,359],[359,467],[467,263],[263,249],[249,255],[255,263],[466,467],[467,260],[260,466],[75,60],[60,166],[166,75],[238,239],[239,79],[79,238],[162,127],[127,139],[139,162],[72,11],[11,37],[37,72],[121,232],[232,120],[120,121],[73,72],[72,39],[39,73],[114,128],[128,47],[47,114],[233,232],[232,128],[128,233],[103,104],[104,67],[67,103],[152,175],[175,148],[148,152],[119,118],[118,101],[101,119],[74,73],[73,40],[40,74],[107,9],[9,108],[108,107],[49,48],[48,131],[131,49],[32,194],[194,211],[211,32],[184,74],[74,185],[185,184],[191,80],[80,183],[183,191],[185,40],[40,186],[186,185],[119,230],[230,118],[118,119],[210,202],[202,214],[214,210],[84,83],[83,17],[17,84],[77,76],[76,146],[146,77],[161,160],[160,30],[30,161],[190,56],[56,173],[173,190],[182,106],[106,194],[194,182],[138,135],[135,192],[192,138],[129,203],[203,98],[98,129],[54,21],[21,68],[68,54],[5,51],[51,4],[4,5],[145,144],[144,23],[23,145],[90,77],[77,91],[91,90],[207,205],[205,187],[187,207],[83,201],[201,18],[18,83],[181,91],[91,182],[182,181],[180,90],[90,181],[181,180],[16,85],[85,17],[17,16],[205,206],[206,36],[36,205],[176,148],[148,140],[140,176],[165,92],[92,39],[39,165],[245,193],[193,244],[244,245],[27,159],[159,28],[28,27],[30,247],[247,161],[161,30],[174,236],[236,196],[196,174],[103,54],[54,104],[104,103],[55,193],[193,8],[8,55],[111,117],[117,31],[31,111],[221,189],[189,55],[55,221],[240,98],[98,99],[99,240],[142,126],[126,100],[100,142],[219,166],[166,218],[218,219],[112,155],[155,26],[26,112],[198,209],[209,131],[131,198],[169,135],[135,150],[150,169],[114,47],[47,217],[217,114],[224,223],[223,53],[53,224],[220,45],[45,134],[134,220],[32,211],[211,140],[140,32],[109,67],[67,108],[108,109],[146,43],[43,91],[91,146],[231,230],[230,120],[120,231],[113,226],[226,247],[247,113],[105,63],[63,52],[52,105],[241,238],[238,242],[242,241],[124,46],[46,156],[156,124],[95,78],[78,96],[96,95],[70,46],[46,63],[63,70],[116,143],[143,227],[227,116],[116,123],[123,111],[111,116],[1,44],[44,19],[19,1],[3,236],[236,51],[51,3],[207,216],[216,205],[205,207],[26,154],[154,22],[22,26],[165,39],[39,167],[167,165],[199,200],[200,208],[208,199],[101,36],[36,100],[100,101],[43,57],[57,202],[202,43],[242,20],[20,99],[99,242],[56,28],[28,157],[157,56],[124,35],[35,113],[113,124],[29,160],[160,27],[27,29],[211,204],[204,210],[210,211],[124,113],[113,46],[46,124],[106,43],[43,204],[204,106],[96,62],[62,77],[77,96],[227,137],[137,116],[116,227],[73,41],[41,72],[72,73],[36,203],[203,142],[142,36],[235,64],[64,240],[240,235],[48,49],[49,64],[64,48],[42,41],[41,74],[74,42],[214,212],[212,207],[207,214],[183,42],[42,184],[184,183],[210,169],[169,211],[211,210],[140,170],[170,176],[176,140],[104,105],[105,69],[69,104],[193,122],[122,168],[168,193],[50,123],[123,187],[187,50],[89,96],[96,90],[90,89],[66,65],[65,107],[107,66],[179,89],[89,180],[180,179],[119,101],[101,120],[120,119],[68,63],[63,104],[104,68],[234,93],[93,227],[227,234],[16,15],[15,85],[85,16],[209,129],[129,49],[49,209],[15,14],[14,86],[86,15],[107,55],[55,9],[9,107],[120,100],[100,121],[121,120],[153,145],[145,22],[22,153],[178,88],[88,179],[179,178],[197,6],[6,196],[196,197],[89,88],[88,96],[96,89],[135,138],[138,136],[136,135],[138,215],[215,172],[172,138],[218,115],[115,219],[219,218],[41,42],[42,81],[81,41],[5,195],[195,51],[51,5],[57,43],[43,61],[61,57],[208,171],[171,199],[199,208],[41,81],[81,38],[38,41],[224,53],[53,225],[225,224],[24,144],[144,110],[110,24],[105,52],[52,66],[66,105],[118,229],[229,117],[117,118],[227,34],[34,234],[234,227],[66,107],[107,69],[69,66],[10,109],[109,151],[151,10],[219,48],[48,235],[235,219],[183,62],[62,191],[191,183],[142,129],[129,126],[126,142],[116,111],[111,143],[143,116],[118,117],[117,50],[50,118],[223,222],[222,52],[52,223],[94,19],[19,141],[141,94],[222,221],[221,65],[65,222],[196,3],[3,197],[197,196],[45,220],[220,44],[44,45],[156,70],[70,139],[139,156],[188,122],[122,245],[245,188],[139,71],[71,162],[162,139],[149,170],[170,150],[150,149],[122,188],[188,196],[196,122],[206,216],[216,92],[92,206],[164,2],[2,167],[167,164],[242,141],[141,241],[241,242],[0,164],[164,37],[37,0],[11,72],[72,12],[12,11],[12,38],[38,13],[13,12],[70,63],[63,71],[71,70],[31,226],[226,111],[111,31],[36,101],[101,205],[205,36],[203,206],[206,165],[165,203],[126,209],[209,217],[217,126],[98,165],[165,97],[97,98],[237,220],[220,218],[218,237],[237,239],[239,241],[241,237],[210,214],[214,169],[169,210],[140,171],[171,32],[32,140],[241,125],[125,237],[237,241],[179,86],[86,178],[178,179],[180,85],[85,179],[179,180],[181,84],[84,180],[180,181],[182,83],[83,181],[181,182],[194,201],[201,182],[182,194],[177,137],[137,132],[132,177],[184,76],[76,183],[183,184],[185,61],[61,184],[184,185],[186,57],[57,185],[185,186],[216,212],[212,186],[186,216],[192,214],[214,187],[187,192],[139,34],[34,156],[156,139],[218,79],[79,237],[237,218],[147,123],[123,177],[177,147],[45,44],[44,4],[4,45],[208,201],[201,32],[32,208],[98,64],[64,129],[129,98],[192,213],[213,138],[138,192],[235,59],[59,219],[219,235],[141,242],[242,97],[97,141],[97,2],[2,141],[141,97],[240,75],[75,235],[235,240],[229,24],[24,228],[228,229],[31,25],[25,226],[226,31],[230,23],[23,229],[229,230],[231,22],[22,230],[230,231],[232,26],[26,231],[231,232],[233,112],[112,232],[232,233],[244,189],[189,243],[243,244],[189,221],[221,190],[190,189],[222,28],[28,221],[221,222],[223,27],[27,222],[222,223],[224,29],[29,223],[223,224],[225,30],[30,224],[224,225],[113,247],[247,225],[225,113],[99,60],[60,240],[240,99],[213,147],[147,215],[215,213],[60,20],[20,166],[166,60],[192,187],[187,213],[213,192],[243,112],[112,244],[244,243],[244,233],[233,245],[245,244],[245,128],[128,188],[188,245],[188,114],[114,174],[174,188],[134,131],[131,220],[220,134],[174,217],[217,236],[236,174],[236,198],[198,134],[134,236],[215,177],[177,58],[58,215],[156,143],[143,124],[124,156],[25,110],[110,7],[7,25],[31,228],[228,25],[25,31],[264,356],[356,368],[368,264],[0,11],[11,267],[267,0],[451,452],[452,349],[349,451],[267,302],[302,269],[269,267],[350,357],[357,277],[277,350],[350,452],[452,357],[357,350],[299,333],[333,297],[297,299],[396,175],[175,377],[377,396],[280,347],[347,330],[330,280],[269,303],[303,270],[270,269],[151,9],[9,337],[337,151],[344,278],[278,360],[360,344],[424,418],[418,431],[431,424],[270,304],[304,409],[409,270],[272,310],[310,407],[407,272],[322,270],[270,410],[410,322],[449,450],[450,347],[347,449],[432,422],[422,434],[434,432],[18,313],[313,17],[17,18],[291,306],[306,375],[375,291],[259,387],[387,260],[260,259],[424,335],[335,418],[418,424],[434,364],[364,416],[416,434],[391,423],[423,327],[327,391],[301,251],[251,298],[298,301],[275,281],[281,4],[4,275],[254,373],[373,253],[253,254],[375,307],[307,321],[321,375],[280,425],[425,411],[411,280],[200,421],[421,18],[18,200],[335,321],[321,406],[406,335],[321,320],[320,405],[405,321],[314,315],[315,17],[17,314],[423,426],[426,266],[266,423],[396,377],[377,369],[369,396],[270,322],[322,269],[269,270],[413,417],[417,464],[464,413],[385,386],[386,258],[258,385],[248,456],[456,419],[419,248],[298,284],[284,333],[333,298],[168,417],[417,8],[8,168],[448,346],[346,261],[261,448],[417,413],[413,285],[285,417],[326,327],[327,328],[328,326],[277,355],[355,329],[329,277],[309,392],[392,438],[438,309],[381,382],[382,256],[256,381],[279,429],[429,360],[360,279],[365,364],[364,379],[379,365],[355,277],[277,437],[437,355],[282,443],[443,283],[283,282],[281,275],[275,363],[363,281],[395,431],[431,369],[369,395],[299,297],[297,337],[337,299],[335,273],[273,321],[321,335],[348,450],[450,349],[349,348],[359,446],[446,467],[467,359],[283,293],[293,282],[282,283],[250,458],[458,462],[462,250],[300,276],[276,383],[383,300],[292,308],[308,325],[325,292],[283,276],[276,293],[293,283],[264,372],[372,447],[447,264],[346,352],[352,340],[340,346],[354,274],[274,19],[19,354],[363,456],[456,281],[281,363],[426,436],[436,425],[425,426],[380,381],[381,252],[252,380],[267,269],[269,393],[393,267],[421,200],[200,428],[428,421],[371,266],[266,329],[329,371],[432,287],[287,422],[422,432],[290,250],[250,328],[328,290],[385,258],[258,384],[384,385],[446,265],[265,342],[342,446],[386,387],[387,257],[257,386],[422,424],[424,430],[430,422],[445,342],[342,276],[276,445],[422,273],[273,424],[424,422],[306,292],[292,307],[307,306],[352,366],[366,345],[345,352],[268,271],[271,302],[302,268],[358,423],[423,371],[371,358],[327,294],[294,460],[460,327],[331,279],[279,294],[294,331],[303,271],[271,304],[304,303],[436,432],[432,427],[427,436],[304,272],[272,408],[408,304],[395,394],[394,431],[431,395],[378,395],[395,400],[400,378],[296,334],[334,299],[299,296],[6,351],[351,168],[168,6],[376,352],[352,411],[411,376],[307,325],[325,320],[320,307],[285,295],[295,336],[336,285],[320,319],[319,404],[404,320],[329,330],[330,349],[349,329],[334,293],[293,333],[333,334],[366,323],[323,447],[447,366],[316,15],[15,315],[315,316],[331,358],[358,279],[279,331],[317,14],[14,316],[316,317],[8,285],[285,9],[9,8],[277,329],[329,350],[350,277],[253,374],[374,252],[252,253],[319,318],[318,403],[403,319],[351,6],[6,419],[419,351],[324,318],[318,325],[325,324],[397,367],[367,365],[365,397],[288,435],[435,397],[397,288],[278,344],[344,439],[439,278],[310,272],[272,311],[311,310],[248,195],[195,281],[281,248],[375,273],[273,291],[291,375],[175,396],[396,199],[199,175],[312,311],[311,268],[268,312],[276,283],[283,445],[445,276],[390,373],[373,339],[339,390],[295,282],[282,296],[296,295],[448,449],[449,346],[346,448],[356,264],[264,454],[454,356],[337,336],[336,299],[299,337],[337,338],[338,151],[151,337],[294,278],[278,455],[455,294],[308,292],[292,415],[415,308],[429,358],[358,355],[355,429],[265,340],[340,372],[372,265],[352,346],[346,280],[280,352],[295,442],[442,282],[282,295],[354,19],[19,370],[370,354],[285,441],[441,295],[295,285],[195,248],[248,197],[197,195],[457,440],[440,274],[274,457],[301,300],[300,368],[368,301],[417,351],[351,465],[465,417],[251,301],[301,389],[389,251],[394,395],[395,379],[379,394],[399,412],[412,419],[419,399],[410,436],[436,322],[322,410],[326,2],[2,393],[393,326],[354,370],[370,461],[461,354],[393,164],[164,267],[267,393],[268,302],[302,12],[12,268],[312,268],[268,13],[13,312],[298,293],[293,301],[301,298],[265,446],[446,340],[340,265],[280,330],[330,425],[425,280],[322,426],[426,391],[391,322],[420,429],[429,437],[437,420],[393,391],[391,326],[326,393],[344,440],[440,438],[438,344],[458,459],[459,461],[461,458],[364,434],[434,394],[394,364],[428,396],[396,262],[262,428],[274,354],[354,457],[457,274],[317,316],[316,402],[402,317],[316,315],[315,403],[403,316],[315,314],[314,404],[404,315],[314,313],[313,405],[405,314],[313,421],[421,406],[406,313],[323,366],[366,361],[361,323],[292,306],[306,407],[407,292],[306,291],[291,408],[408,306],[291,287],[287,409],[409,291],[287,432],[432,410],[410,287],[427,434],[434,411],[411,427],[372,264],[264,383],[383,372],[459,309],[309,457],[457,459],[366,352],[352,401],[401,366],[1,274],[274,4],[4,1],[418,421],[421,262],[262,418],[331,294],[294,358],[358,331],[435,433],[433,367],[367,435],[392,289],[289,439],[439,392],[328,462],[462,326],[326,328],[94,2],[2,370],[370,94],[289,305],[305,455],[455,289],[339,254],[254,448],[448,339],[359,255],[255,446],[446,359],[254,253],[253,449],[449,254],[253,252],[252,450],[450,253],[252,256],[256,451],[451,252],[256,341],[341,452],[452,256],[414,413],[413,463],[463,414],[286,441],[441,414],[414,286],[286,258],[258,441],[441,286],[258,257],[257,442],[442,258],[257,259],[259,443],[443,257],[259,260],[260,444],[444,259],[260,467],[467,445],[445,260],[309,459],[459,250],[250,309],[305,289],[289,290],[290,305],[305,290],[290,460],[460,305],[401,376],[376,435],[435,401],[309,250],[250,392],[392,309],[376,411],[411,433],[433,376],[453,341],[341,464],[464,453],[357,453],[453,465],[465,357],[343,357],[357,412],[412,343],[437,343],[343,399],[399,437],[344,360],[360,440],[440,344],[420,437],[437,456],[456,420],[360,420],[420,363],[363,360],[361,401],[401,288],[288,361],[265,372],[372,353],[353,265],[390,339],[339,249],[249,390],[339,448],[448,255],[255,339]);function Ic(t){t.j={faceLandmarks:[],faceBlendshapes:[],facialTransformationMatrixes:[]}}var be=class extends rt{constructor(t,e){super(new kt(t,e),"image_in","norm_rect",!1),this.j={faceLandmarks:[],faceBlendshapes:[],facialTransformationMatrixes:[]},this.outputFacialTransformationMatrixes=this.outputFaceBlendshapes=!1,z(t=this.h=new sf,0,1,e=new ge),this.v=new nf,z(this.h,0,3,this.v),this.s=new Zs,z(this.h,0,2,this.s),Yt(this.s,4,1),W(this.s,2,.5),W(this.v,2,.5),W(this.h,4,.5)}get baseOptions(){return q(this.h,ge,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){return"numFaces"in t&&Yt(this.s,4,t.numFaces??1),"minFaceDetectionConfidence"in t&&W(this.s,2,t.minFaceDetectionConfidence??.5),"minTrackingConfidence"in t&&W(this.h,4,t.minTrackingConfidence??.5),"minFacePresenceConfidence"in t&&W(this.v,2,t.minFacePresenceConfidence??.5),"outputFaceBlendshapes"in t&&(this.outputFaceBlendshapes=!!t.outputFaceBlendshapes),"outputFacialTransformationMatrixes"in t&&(this.outputFacialTransformationMatrixes=!!t.outputFacialTransformationMatrixes),this.l(t)}D(t,e){return Ic(this),Et(this,t,e),this.j}F(t,e,r){return Ic(this),qt(this,t,r,e),this.j}m(){var t=new nt;de(t,"image_in"),de(t,"norm_rect"),J(t,"face_landmarks");let e=new lt;Pt(e,im,this.h);let r=new Ze;ht(r,"mediapipe.tasks.vision.face_landmarker.FaceLandmarkerGraph"),ce(r,"IMAGE:image_in"),ce(r,"NORM_RECT:norm_rect"),Y(r,"NORM_LANDMARKS:face_landmarks"),r.o(e),dt(t,r),this.g.attachProtoVectorListener("face_landmarks",((n,s)=>{for(let o of n)n=qn(o),this.j.faceLandmarks.push(Js(n));G(this,s)})),this.g.attachEmptyPacketListener("face_landmarks",(n=>{G(this,n)})),this.outputFaceBlendshapes&&(J(t,"blendshapes"),Y(r,"BLENDSHAPES:blendshapes"),this.g.attachProtoVectorListener("blendshapes",((n,s)=>{if(this.outputFaceBlendshapes)for(let o of n)n=Ks(o),this.j.faceBlendshapes.push(_i(n.g()??[]));G(this,s)})),this.g.attachEmptyPacketListener("blendshapes",(n=>{G(this,n)}))),this.outputFacialTransformationMatrixes&&(J(t,"face_geometry"),Y(r,"FACE_GEOMETRY:face_geometry"),this.g.attachProtoVectorListener("face_geometry",((n,s)=>{if(this.outputFacialTransformationMatrixes)for(let o of n)(n=q(am(o),Zd,2))&&this.j.facialTransformationMatrixes.push({rows:Bt(wt(n,1),0)??0,columns:Bt(wt(n,2),0)??0,data:Br(n,3,kr,Ur()).slice()??[]});G(this,s)})),this.g.attachEmptyPacketListener("face_geometry",(n=>{G(this,n)}))),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};be.prototype.detectForVideo=be.prototype.F,be.prototype.detect=be.prototype.D,be.prototype.setOptions=be.prototype.o,be.createFromModelPath=function(t,e){return j(be,t,{baseOptions:{modelAssetPath:e}})},be.createFromModelBuffer=function(t,e){return j(be,t,{baseOptions:{modelAssetBuffer:e}})},be.createFromOptions=function(t,e){return j(be,t,e)},be.FACE_LANDMARKS_LIPS=Ti,be.FACE_LANDMARKS_LEFT_EYE=ki,be.FACE_LANDMARKS_LEFT_EYEBROW=Ei,be.FACE_LANDMARKS_LEFT_IRIS=Uf,be.FACE_LANDMARKS_RIGHT_EYE=Ai,be.FACE_LANDMARKS_RIGHT_EYEBROW=Ri,be.FACE_LANDMARKS_RIGHT_IRIS=Bf,be.FACE_LANDMARKS_FACE_OVAL=Ii,be.FACE_LANDMARKS_CONTOURS=Lf,be.FACE_LANDMARKS_TESSELATION=Pf;var zt=class extends rt{constructor(t,e){super(new kt(t,e),"image_in","norm_rect",!0),z(t=this.j=new af,0,1,e=new ge)}get baseOptions(){return q(this.j,ge,1)}set baseOptions(t){z(this.j,0,1,t)}o(t){return super.l(t)}Oa(t,e,r){let n=typeof e!="function"?e:{};if(this.h=typeof e=="function"?e:r,Et(this,t,n??{}),!this.h)return this.s}m(){var t=new nt;de(t,"image_in"),de(t,"norm_rect"),J(t,"stylized_image");let e=new lt;Pt(e,um,this.j);let r=new Ze;ht(r,"mediapipe.tasks.vision.face_stylizer.FaceStylizerGraph"),ce(r,"IMAGE:image_in"),ce(r,"NORM_RECT:norm_rect"),Y(r,"STYLIZED_IMAGE:stylized_image"),r.o(e),dt(t,r),this.g.V("stylized_image",((n,s)=>{var o=!this.h,a=n.data,i=n.width;let u=i*(n=n.height);if(a instanceof Uint8Array)if(a.length===3*u){let l=new Uint8ClampedArray(4*u);for(let c=0;c<u;++c)l[4*c]=a[3*c],l[4*c+1]=a[3*c+1],l[4*c+2]=a[3*c+2],l[4*c+3]=255;a=new ImageData(l,i,n)}else{if(a.length!==4*u)throw Error("Unsupported channel count: "+a.length/u);a=new ImageData(new Uint8ClampedArray(a.buffer,a.byteOffset,a.length),i,n)}else if(!(a instanceof WebGLTexture))throw Error(`Unsupported format: ${a.constructor.name}`);i=new Ne([a],!1,!1,this.g.i.canvas,this.P,i,n),this.s=o=o?i.clone():i,this.h&&this.h(o),G(this,s)})),this.g.attachEmptyPacketListener("stylized_image",(n=>{this.s=null,this.h&&this.h(null),G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};zt.prototype.stylize=zt.prototype.Oa,zt.prototype.setOptions=zt.prototype.o,zt.createFromModelPath=function(t,e){return j(zt,t,{baseOptions:{modelAssetPath:e}})},zt.createFromModelBuffer=function(t,e){return j(zt,t,{baseOptions:{modelAssetBuffer:e}})},zt.createFromOptions=function(t,e){return j(zt,t,e)};var Si=Mt([0,1],[1,2],[2,3],[3,4],[0,5],[5,6],[6,7],[7,8],[5,9],[9,10],[10,11],[11,12],[9,13],[13,14],[14,15],[15,16],[13,17],[0,17],[17,18],[18,19],[19,20]);function Sc(t){t.gestures=[],t.landmarks=[],t.worldLandmarks=[],t.handedness=[]}function Cc(t){return t.gestures.length===0?{gestures:[],landmarks:[],worldLandmarks:[],handedness:[],handednesses:[]}:{gestures:t.gestures,landmarks:t.landmarks,worldLandmarks:t.worldLandmarks,handedness:t.handedness,handednesses:t.handedness}}function Fc(t,e=!0){let r=[];for(let s of t){var n=Ks(s);t=[];for(let o of n.g())n=e&&wt(o,1)!=null?Bt(wt(o,1),0):-1,t.push({score:Ie(o,2)??0,index:n,categoryName:jt(o,3)??"",displayName:jt(o,4)??""});r.push(t)}return r}var ot=class extends rt{constructor(t,e){super(new kt(t,e),"image_in","norm_rect",!1),this.gestures=[],this.landmarks=[],this.worldLandmarks=[],this.handedness=[],z(t=this.j=new lf,0,1,e=new ge),this.s=new pi,z(this.j,0,2,this.s),this.C=new mi,z(this.s,0,3,this.C),this.v=new cf,z(this.s,0,2,this.v),this.h=new cm,z(this.j,0,3,this.h),W(this.v,2,.5),W(this.s,4,.5),W(this.C,2,.5)}get baseOptions(){return q(this.j,ge,1)}set baseOptions(t){z(this.j,0,1,t)}o(t){if(Yt(this.v,3,t.numHands??1),"minHandDetectionConfidence"in t&&W(this.v,2,t.minHandDetectionConfidence??.5),"minTrackingConfidence"in t&&W(this.s,4,t.minTrackingConfidence??.5),"minHandPresenceConfidence"in t&&W(this.C,2,t.minHandPresenceConfidence??.5),t.cannedGesturesClassifierOptions){var e=new Xr,r=e,n=_a(t.cannedGesturesClassifierOptions,q(this.h,Xr,3)?.h());z(r,0,2,n),z(this.h,0,3,e)}else t.cannedGesturesClassifierOptions===void 0&&q(this.h,Xr,3)?.g();return t.customGesturesClassifierOptions?(z(r=e=new Xr,0,2,n=_a(t.customGesturesClassifierOptions,q(this.h,Xr,4)?.h())),z(this.h,0,4,e)):t.customGesturesClassifierOptions===void 0&&q(this.h,Xr,4)?.g(),this.l(t)}Ja(t,e){return Sc(this),Et(this,t,e),Cc(this)}Ka(t,e,r){return Sc(this),qt(this,t,r,e),Cc(this)}m(){var t=new nt;de(t,"image_in"),de(t,"norm_rect"),J(t,"hand_gestures"),J(t,"hand_landmarks"),J(t,"world_hand_landmarks"),J(t,"handedness");let e=new lt;Pt(e,lm,this.j);let r=new Ze;ht(r,"mediapipe.tasks.vision.gesture_recognizer.GestureRecognizerGraph"),ce(r,"IMAGE:image_in"),ce(r,"NORM_RECT:norm_rect"),Y(r,"HAND_GESTURES:hand_gestures"),Y(r,"LANDMARKS:hand_landmarks"),Y(r,"WORLD_LANDMARKS:world_hand_landmarks"),Y(r,"HANDEDNESS:handedness"),r.o(e),dt(t,r),this.g.attachProtoVectorListener("hand_landmarks",((n,s)=>{for(let o of n){n=qn(o);let a=[];for(let i of or(n,Jl,1))a.push({x:Ie(i,1)??0,y:Ie(i,2)??0,z:Ie(i,3)??0,visibility:Ie(i,4)??0});this.landmarks.push(a)}G(this,s)})),this.g.attachEmptyPacketListener("hand_landmarks",(n=>{G(this,n)})),this.g.attachProtoVectorListener("world_hand_landmarks",((n,s)=>{for(let o of n){n=Zr(o);let a=[];for(let i of or(n,Zl,1))a.push({x:Ie(i,1)??0,y:Ie(i,2)??0,z:Ie(i,3)??0,visibility:Ie(i,4)??0});this.worldLandmarks.push(a)}G(this,s)})),this.g.attachEmptyPacketListener("world_hand_landmarks",(n=>{G(this,n)})),this.g.attachProtoVectorListener("hand_gestures",((n,s)=>{this.gestures.push(...Fc(n,!1)),G(this,s)})),this.g.attachEmptyPacketListener("hand_gestures",(n=>{G(this,n)})),this.g.attachProtoVectorListener("handedness",((n,s)=>{this.handedness.push(...Fc(n)),G(this,s)})),this.g.attachEmptyPacketListener("handedness",(n=>{G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};function Uc(t){return{landmarks:t.landmarks,worldLandmarks:t.worldLandmarks,handednesses:t.handedness,handedness:t.handedness}}ot.prototype.recognizeForVideo=ot.prototype.Ka,ot.prototype.recognize=ot.prototype.Ja,ot.prototype.setOptions=ot.prototype.o,ot.createFromModelPath=function(t,e){return j(ot,t,{baseOptions:{modelAssetPath:e}})},ot.createFromModelBuffer=function(t,e){return j(ot,t,{baseOptions:{modelAssetBuffer:e}})},ot.createFromOptions=function(t,e){return j(ot,t,e)},ot.HAND_CONNECTIONS=Si;var at=class extends rt{constructor(t,e){super(new kt(t,e),"image_in","norm_rect",!1),this.landmarks=[],this.worldLandmarks=[],this.handedness=[],z(t=this.h=new pi,0,1,e=new ge),this.s=new mi,z(this.h,0,3,this.s),this.j=new cf,z(this.h,0,2,this.j),Yt(this.j,3,1),W(this.j,2,.5),W(this.s,2,.5),W(this.h,4,.5)}get baseOptions(){return q(this.h,ge,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){return"numHands"in t&&Yt(this.j,3,t.numHands??1),"minHandDetectionConfidence"in t&&W(this.j,2,t.minHandDetectionConfidence??.5),"minTrackingConfidence"in t&&W(this.h,4,t.minTrackingConfidence??.5),"minHandPresenceConfidence"in t&&W(this.s,2,t.minHandPresenceConfidence??.5),this.l(t)}D(t,e){return this.landmarks=[],this.worldLandmarks=[],this.handedness=[],Et(this,t,e),Uc(this)}F(t,e,r){return this.landmarks=[],this.worldLandmarks=[],this.handedness=[],qt(this,t,r,e),Uc(this)}m(){var t=new nt;de(t,"image_in"),de(t,"norm_rect"),J(t,"hand_landmarks"),J(t,"world_hand_landmarks"),J(t,"handedness");let e=new lt;Pt(e,fm,this.h);let r=new Ze;ht(r,"mediapipe.tasks.vision.hand_landmarker.HandLandmarkerGraph"),ce(r,"IMAGE:image_in"),ce(r,"NORM_RECT:norm_rect"),Y(r,"LANDMARKS:hand_landmarks"),Y(r,"WORLD_LANDMARKS:world_hand_landmarks"),Y(r,"HANDEDNESS:handedness"),r.o(e),dt(t,r),this.g.attachProtoVectorListener("hand_landmarks",((n,s)=>{for(let o of n)n=qn(o),this.landmarks.push(Js(n));G(this,s)})),this.g.attachEmptyPacketListener("hand_landmarks",(n=>{G(this,n)})),this.g.attachProtoVectorListener("world_hand_landmarks",((n,s)=>{for(let o of n)n=Zr(o),this.worldLandmarks.push(Nn(n));G(this,s)})),this.g.attachEmptyPacketListener("world_hand_landmarks",(n=>{G(this,n)})),this.g.attachProtoVectorListener("handedness",((n,s)=>{var o=this.handedness,a=o.push;let i=[];for(let u of n){n=Ks(u);let l=[];for(let c of n.g())l.push({score:Ie(c,2)??0,index:Bt(wt(c,1),0)??-1,categoryName:jt(c,3)??"",displayName:jt(c,4)??""});i.push(l)}a.call(o,...i),G(this,s)})),this.g.attachEmptyPacketListener("handedness",(n=>{G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};at.prototype.detectForVideo=at.prototype.F,at.prototype.detect=at.prototype.D,at.prototype.setOptions=at.prototype.o,at.createFromModelPath=function(t,e){return j(at,t,{baseOptions:{modelAssetPath:e}})},at.createFromModelBuffer=function(t,e){return j(at,t,{baseOptions:{modelAssetBuffer:e}})},at.createFromOptions=function(t,e){return j(at,t,e)},at.HAND_CONNECTIONS=Si;var Of=Mt([0,1],[1,2],[2,3],[3,7],[0,4],[4,5],[5,6],[6,8],[9,10],[11,12],[11,13],[13,15],[15,17],[15,19],[15,21],[17,19],[12,14],[14,16],[16,18],[16,20],[16,22],[18,20],[11,23],[12,24],[23,24],[23,25],[24,26],[25,27],[26,28],[27,29],[28,30],[29,31],[30,32],[27,31],[28,32]);function Bc(t){t.h={faceLandmarks:[],faceBlendshapes:[],poseLandmarks:[],poseWorldLandmarks:[],poseSegmentationMasks:[],leftHandLandmarks:[],leftHandWorldLandmarks:[],rightHandLandmarks:[],rightHandWorldLandmarks:[]}}function Lc(t){try{if(!t.C)return t.h;t.C(t.h)}finally{eo(t)}}function ms(t,e){t=qn(t),e.push(Js(t))}var pe=class extends rt{constructor(t,e){super(new kt(t,e),"input_frames_image",null,!1),this.h={faceLandmarks:[],faceBlendshapes:[],poseLandmarks:[],poseWorldLandmarks:[],poseSegmentationMasks:[],leftHandLandmarks:[],leftHandWorldLandmarks:[],rightHandLandmarks:[],rightHandWorldLandmarks:[]},this.outputPoseSegmentationMasks=this.outputFaceBlendshapes=!1,z(t=this.j=new pf,0,1,e=new ge),this.K=new mi,z(this.j,0,2,this.K),this.aa=new hm,z(this.j,0,3,this.aa),this.s=new Zs,z(this.j,0,4,this.s),this.I=new nf,z(this.j,0,5,this.I),this.v=new df,z(this.j,0,6,this.v),this.L=new mf,z(this.j,0,7,this.L),W(this.s,2,.5),W(this.s,3,.3),W(this.I,2,.5),W(this.v,2,.5),W(this.v,3,.3),W(this.L,2,.5),W(this.K,2,.5)}get baseOptions(){return q(this.j,ge,1)}set baseOptions(t){z(this.j,0,1,t)}o(t){return"minFaceDetectionConfidence"in t&&W(this.s,2,t.minFaceDetectionConfidence??.5),"minFaceSuppressionThreshold"in t&&W(this.s,3,t.minFaceSuppressionThreshold??.3),"minFacePresenceConfidence"in t&&W(this.I,2,t.minFacePresenceConfidence??.5),"outputFaceBlendshapes"in t&&(this.outputFaceBlendshapes=!!t.outputFaceBlendshapes),"minPoseDetectionConfidence"in t&&W(this.v,2,t.minPoseDetectionConfidence??.5),"minPoseSuppressionThreshold"in t&&W(this.v,3,t.minPoseSuppressionThreshold??.3),"minPosePresenceConfidence"in t&&W(this.L,2,t.minPosePresenceConfidence??.5),"outputPoseSegmentationMasks"in t&&(this.outputPoseSegmentationMasks=!!t.outputPoseSegmentationMasks),"minHandLandmarksConfidence"in t&&W(this.K,2,t.minHandLandmarksConfidence??.5),this.l(t)}D(t,e,r){let n=typeof e!="function"?e:{};return this.C=typeof e=="function"?e:r,Bc(this),Et(this,t,n),Lc(this)}F(t,e,r,n){let s=typeof r!="function"?r:{};return this.C=typeof r=="function"?r:n,Bc(this),qt(this,t,s,e),Lc(this)}m(){var t=new nt;de(t,"input_frames_image"),J(t,"pose_landmarks"),J(t,"pose_world_landmarks"),J(t,"face_landmarks"),J(t,"left_hand_landmarks"),J(t,"left_hand_world_landmarks"),J(t,"right_hand_landmarks"),J(t,"right_hand_world_landmarks");let e=new lt,r=new Qu;ha(r,1,ln("type.googleapis.com/mediapipe.tasks.vision.holistic_landmarker.proto.HolisticLandmarkerGraphOptions"),""),(function(s,o){if(o!=null)if(Array.isArray(o))ue(s,2,Ms(o,Wa,void 0,void 0,!1));else{if(!(typeof o=="string"||o instanceof nr||Hn(o)))throw Error("invalid value in Any.value field: "+o+" expected a ByteString, a base64 encoded string, a Uint8Array or a jspb array");ha(s,2,Ba(o,!1),Or())}})(r,this.j.g());let n=new Ze;ht(n,"mediapipe.tasks.vision.holistic_landmarker.HolisticLandmarkerGraph"),As(n,8,Qu,r),ce(n,"IMAGE:input_frames_image"),Y(n,"POSE_LANDMARKS:pose_landmarks"),Y(n,"POSE_WORLD_LANDMARKS:pose_world_landmarks"),Y(n,"FACE_LANDMARKS:face_landmarks"),Y(n,"LEFT_HAND_LANDMARKS:left_hand_landmarks"),Y(n,"LEFT_HAND_WORLD_LANDMARKS:left_hand_world_landmarks"),Y(n,"RIGHT_HAND_LANDMARKS:right_hand_landmarks"),Y(n,"RIGHT_HAND_WORLD_LANDMARKS:right_hand_world_landmarks"),n.o(e),dt(t,n),Qs(this,t),this.g.attachProtoListener("pose_landmarks",((s,o)=>{ms(s,this.h.poseLandmarks),G(this,o)})),this.g.attachEmptyPacketListener("pose_landmarks",(s=>{G(this,s)})),this.g.attachProtoListener("pose_world_landmarks",((s,o)=>{var a=this.h.poseWorldLandmarks;s=Zr(s),a.push(Nn(s)),G(this,o)})),this.g.attachEmptyPacketListener("pose_world_landmarks",(s=>{G(this,s)})),this.outputPoseSegmentationMasks&&(Y(n,"POSE_SEGMENTATION_MASK:pose_segmentation_mask"),rn(this,"pose_segmentation_mask"),this.g.V("pose_segmentation_mask",((s,o)=>{this.h.poseSegmentationMasks=[on(this,s,!0,!this.C)],G(this,o)})),this.g.attachEmptyPacketListener("pose_segmentation_mask",(s=>{this.h.poseSegmentationMasks=[],G(this,s)}))),this.g.attachProtoListener("face_landmarks",((s,o)=>{ms(s,this.h.faceLandmarks),G(this,o)})),this.g.attachEmptyPacketListener("face_landmarks",(s=>{G(this,s)})),this.outputFaceBlendshapes&&(J(t,"extra_blendshapes"),Y(n,"FACE_BLENDSHAPES:extra_blendshapes"),this.g.attachProtoListener("extra_blendshapes",((s,o)=>{var a=this.h.faceBlendshapes;this.outputFaceBlendshapes&&(s=Ks(s),a.push(_i(s.g()??[]))),G(this,o)})),this.g.attachEmptyPacketListener("extra_blendshapes",(s=>{G(this,s)}))),this.g.attachProtoListener("left_hand_landmarks",((s,o)=>{ms(s,this.h.leftHandLandmarks),G(this,o)})),this.g.attachEmptyPacketListener("left_hand_landmarks",(s=>{G(this,s)})),this.g.attachProtoListener("left_hand_world_landmarks",((s,o)=>{var a=this.h.leftHandWorldLandmarks;s=Zr(s),a.push(Nn(s)),G(this,o)})),this.g.attachEmptyPacketListener("left_hand_world_landmarks",(s=>{G(this,s)})),this.g.attachProtoListener("right_hand_landmarks",((s,o)=>{ms(s,this.h.rightHandLandmarks),G(this,o)})),this.g.attachEmptyPacketListener("right_hand_landmarks",(s=>{G(this,s)})),this.g.attachProtoListener("right_hand_world_landmarks",((s,o)=>{var a=this.h.rightHandWorldLandmarks;s=Zr(s),a.push(Nn(s)),G(this,o)})),this.g.attachEmptyPacketListener("right_hand_world_landmarks",(s=>{G(this,s)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};pe.prototype.detectForVideo=pe.prototype.F,pe.prototype.detect=pe.prototype.D,pe.prototype.setOptions=pe.prototype.o,pe.createFromModelPath=function(t,e){return j(pe,t,{baseOptions:{modelAssetPath:e}})},pe.createFromModelBuffer=function(t,e){return j(pe,t,{baseOptions:{modelAssetBuffer:e}})},pe.createFromOptions=function(t,e){return j(pe,t,e)},pe.HAND_CONNECTIONS=Si,pe.POSE_CONNECTIONS=Of,pe.FACE_LANDMARKS_LIPS=Ti,pe.FACE_LANDMARKS_LEFT_EYE=ki,pe.FACE_LANDMARKS_LEFT_EYEBROW=Ei,pe.FACE_LANDMARKS_LEFT_IRIS=Uf,pe.FACE_LANDMARKS_RIGHT_EYE=Ai,pe.FACE_LANDMARKS_RIGHT_EYEBROW=Ri,pe.FACE_LANDMARKS_RIGHT_IRIS=Bf,pe.FACE_LANDMARKS_FACE_OVAL=Ii,pe.FACE_LANDMARKS_CONTOURS=Lf,pe.FACE_LANDMARKS_TESSELATION=Pf;var _t=class extends rt{constructor(t,e){super(new kt(t,e),"input_image","norm_rect",!0),this.j={classifications:[]},z(t=this.h=new gf,0,1,e=new ge)}get baseOptions(){return q(this.h,ge,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){return z(this.h,0,2,_a(t,q(this.h,fi,2))),this.l(t)}ta(t,e){return this.j={classifications:[]},Et(this,t,e),this.j}ua(t,e,r){return this.j={classifications:[]},qt(this,t,r,e),this.j}m(){var t=new nt;de(t,"input_image"),de(t,"norm_rect"),J(t,"classifications");let e=new lt;Pt(e,dm,this.h);let r=new Ze;ht(r,"mediapipe.tasks.vision.image_classifier.ImageClassifierGraph"),ce(r,"IMAGE:input_image"),ce(r,"NORM_RECT:norm_rect"),Y(r,"CLASSIFICATIONS:classifications"),r.o(e),dt(t,r),this.g.attachProtoListener("classifications",((n,s)=>{this.j=(function(o){let a={classifications:or(o,Qd,1).map((i=>_i(q(i,Yl,4)?.g()??[],Bt(wt(i,2),0),jt(i,3))))};return ks(_r(o,2))!=null&&(a.timestampMs=Bt(ks(_r(o,2)),0)),a})(em(n)),G(this,s)})),this.g.attachEmptyPacketListener("classifications",(n=>{G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};_t.prototype.classifyForVideo=_t.prototype.ua,_t.prototype.classify=_t.prototype.ta,_t.prototype.setOptions=_t.prototype.o,_t.createFromModelPath=function(t,e){return j(_t,t,{baseOptions:{modelAssetPath:e}})},_t.createFromModelBuffer=function(t,e){return j(_t,t,{baseOptions:{modelAssetBuffer:e}})},_t.createFromOptions=function(t,e){return j(_t,t,e)};var it=class extends rt{constructor(t,e){super(new kt(t,e),"image_in","norm_rect",!0),this.h=new xf,this.embeddings={embeddings:[]},z(t=this.h,0,1,e=new ge)}get baseOptions(){return q(this.h,ge,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){var e=this.h,r=q(this.h,uc,2);return r=r?r.clone():new uc,t.l2Normalize!==void 0?Wn(r,1,t.l2Normalize):"l2Normalize"in t&&ue(r,1),t.quantize!==void 0?Wn(r,2,t.quantize):"quantize"in t&&ue(r,2),z(e,0,2,r),this.l(t)}Aa(t,e){return Et(this,t,e),this.embeddings}Ba(t,e,r){return qt(this,t,r,e),this.embeddings}m(){var t=new nt;de(t,"image_in"),de(t,"norm_rect"),J(t,"embeddings_out");let e=new lt;Pt(e,mm,this.h);let r=new Ze;ht(r,"mediapipe.tasks.vision.image_embedder.ImageEmbedderGraph"),ce(r,"IMAGE:image_in"),ce(r,"NORM_RECT:norm_rect"),Y(r,"EMBEDDINGS:embeddings_out"),r.o(e),dt(t,r),this.g.attachProtoListener("embeddings_out",((n,s)=>{n=nm(n),this.embeddings=(function(o){return{embeddings:or(o,rm,1).map((a=>{let i={headIndex:Bt(wt(a,3),0)??-1,headName:jt(a,4)??""};if(dl(a,ic,Jo(a,1))!==void 0)a=Br(a=q(a,ic,Jo(a,1)),1,kr,Ur()),i.floatEmbedding=a.slice();else{let u=new Uint8Array(0);i.quantizedEmbedding=q(a,tm,Jo(a,2))?.pa()?.h()??u}return i})),timestampMs:Bt(ks(_r(o,2)),0)}})(n),G(this,s)})),this.g.attachEmptyPacketListener("embeddings_out",(n=>{G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};it.cosineSimilarity=function(t,e){if(t.floatEmbedding&&e.floatEmbedding)t=dc(t.floatEmbedding,e.floatEmbedding);else{if(!t.quantizedEmbedding||!e.quantizedEmbedding)throw Error("Cannot compute cosine similarity between quantized and float embeddings.");t=dc(hc(t.quantizedEmbedding),hc(e.quantizedEmbedding))}return t},it.prototype.embedForVideo=it.prototype.Ba,it.prototype.embed=it.prototype.Aa,it.prototype.setOptions=it.prototype.o,it.createFromModelPath=function(t,e){return j(it,t,{baseOptions:{modelAssetPath:e}})},it.createFromModelBuffer=function(t,e){return j(it,t,{baseOptions:{modelAssetBuffer:e}})},it.createFromOptions=function(t,e){return j(it,t,e)};var Ta=class{constructor(t,e,r){this.confidenceMasks=t,this.categoryMask=e,this.qualityScores=r}close(){this.confidenceMasks?.forEach((t=>{t.close()})),this.categoryMask?.close()}};function Pc(t){t.categoryMask=void 0,t.confidenceMasks=void 0,t.qualityScores=void 0}function Oc(t){try{let e=new Ta(t.confidenceMasks,t.categoryMask,t.qualityScores);if(!t.j)return e;t.j(e)}finally{eo(t)}}Ta.prototype.close=Ta.prototype.close;var Xe=class extends rt{constructor(t,e){super(new kt(t,e),"image_in","norm_rect",!1),this.s=[],this.outputCategoryMask=!1,this.outputConfidenceMasks=!0,this.h=new yi,this.v=new yf,z(this.h,0,3,this.v),z(t=this.h,0,1,e=new ge)}get baseOptions(){return q(this.h,ge,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){return t.displayNamesLocale!==void 0?ue(this.h,2,ln(t.displayNamesLocale)):"displayNamesLocale"in t&&ue(this.h,2),"outputCategoryMask"in t&&(this.outputCategoryMask=t.outputCategoryMask??!1),"outputConfidenceMasks"in t&&(this.outputConfidenceMasks=t.outputConfidenceMasks??!0),super.l(t)}J(){(function(t){let e=or(t.ea(),Ze,1).filter((r=>jt(r,1).includes("mediapipe.tasks.TensorsToSegmentationCalculator")));if(t.s=[],e.length>1)throw Error("The graph has more than one mediapipe.tasks.TensorsToSegmentationCalculator.");e.length===1&&(q(e[0],lt,7)?.l()?.g()??new Map).forEach(((r,n)=>{t.s[Number(n)]=jt(r,1)}))})(this)}segment(t,e,r){let n=typeof e!="function"?e:{};return this.j=typeof e=="function"?e:r,Pc(this),Et(this,t,n),Oc(this)}Ma(t,e,r,n){let s=typeof r!="function"?r:{};return this.j=typeof r=="function"?r:n,Pc(this),qt(this,t,s,e),Oc(this)}Ea(){return this.s}m(){var t=new nt;de(t,"image_in"),de(t,"norm_rect");let e=new lt;Pt(e,bf,this.h);let r=new Ze;ht(r,"mediapipe.tasks.vision.image_segmenter.ImageSegmenterGraph"),ce(r,"IMAGE:image_in"),ce(r,"NORM_RECT:norm_rect"),r.o(e),dt(t,r),Qs(this,t),this.outputConfidenceMasks&&(J(t,"confidence_masks"),Y(r,"CONFIDENCE_MASKS:confidence_masks"),rn(this,"confidence_masks"),this.g.da("confidence_masks",((n,s)=>{this.confidenceMasks=n.map((o=>on(this,o,!0,!this.j))),G(this,s)})),this.g.attachEmptyPacketListener("confidence_masks",(n=>{this.confidenceMasks=[],G(this,n)}))),this.outputCategoryMask&&(J(t,"category_mask"),Y(r,"CATEGORY_MASK:category_mask"),rn(this,"category_mask"),this.g.V("category_mask",((n,s)=>{this.categoryMask=on(this,n,!1,!this.j),G(this,s)})),this.g.attachEmptyPacketListener("category_mask",(n=>{this.categoryMask=void 0,G(this,n)}))),J(t,"quality_scores"),Y(r,"QUALITY_SCORES:quality_scores"),this.g.attachFloatVectorListener("quality_scores",((n,s)=>{this.qualityScores=n,G(this,s)})),this.g.attachEmptyPacketListener("quality_scores",(n=>{this.categoryMask=void 0,G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};Xe.prototype.getLabels=Xe.prototype.Ea,Xe.prototype.segmentForVideo=Xe.prototype.Ma,Xe.prototype.segment=Xe.prototype.segment,Xe.prototype.setOptions=Xe.prototype.o,Xe.createFromModelPath=function(t,e){return j(Xe,t,{baseOptions:{modelAssetPath:e}})},Xe.createFromModelBuffer=function(t,e){return j(Xe,t,{baseOptions:{modelAssetBuffer:e}})},Xe.createFromOptions=function(t,e){return j(Xe,t,e)};var ka=class{constructor(t,e,r){this.confidenceMasks=t,this.categoryMask=e,this.qualityScores=r}close(){this.confidenceMasks?.forEach((t=>{t.close()})),this.categoryMask?.close()}};ka.prototype.close=ka.prototype.close;var km=class extends V{constructor(t){super(t)}},jr=[0,we,-2],Fs=[0,tr,-3,xe,tr,-1],Dc=[0,Fs],Mc=[0,Fs,we,-1],oa=class extends V{constructor(t){super(t)}},Nc=[0,tr,-1,xe],Em=class extends V{constructor(){super()}},Gc=class extends V{constructor(t){super(t)}},Ea=[1,2,3,4,5,6,7,8,9,10,14,15],Df=class extends V{constructor(){super()}};Df.prototype.g=qs([0,Oe,[0,Ea,se,Fs,se,[0,Fs,jr],se,Dc,se,[0,Dc,jr],se,Nc,se,[0,tr,-3,xe,Lt],se,[0,tr,-3,xe],se,[0,re,tr,-2,xe,we,xe,-1,2,tr,jr],se,Mc,se,[0,Mc,jr],tr,jr,re,se,[0,tr,-3,xe,jr,-1],se,[0,Oe,Nc]],re,[0,re,we,-1,xe]]);var Ht=class extends rt{constructor(t,e){super(new kt(t,e),"image_in","norm_rect_in",!1),this.outputCategoryMask=!1,this.outputConfidenceMasks=!0,this.h=new yi,this.s=new yf,z(this.h,0,3,this.s),z(t=this.h,0,1,e=new ge)}get baseOptions(){return q(this.h,ge,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){return"outputCategoryMask"in t&&(this.outputCategoryMask=t.outputCategoryMask??!1),"outputConfidenceMasks"in t&&(this.outputConfidenceMasks=t.outputConfidenceMasks??!0),super.l(t)}segment(t,e,r,n){let s=typeof r!="function"?r:{};this.j=typeof r=="function"?r:n,this.qualityScores=this.categoryMask=this.confidenceMasks=void 0,r=this.B+1,n=new Df;let o=new Gc;var a=new km;if(Yt(a,1,255),z(o,0,12,a),e.keypoint&&e.scribble)throw Error("Cannot provide both keypoint and scribble.");if(e.keypoint){var i=new oa;Wn(i,3,!0),W(i,1,e.keypoint.x),W(i,2,e.keypoint.y),Dn(o,5,Ea,i)}else{if(!e.scribble)throw Error("Must provide either a keypoint or a scribble.");for(i of(a=new Em,e.scribble))Wn(e=new oa,3,!0),W(e,1,i.x),W(e,2,i.y),As(a,1,oa,e);Dn(o,15,Ea,a)}As(n,1,Gc,o),this.g.addProtoToStream(n.g(),"drishti.RenderData","roi_in",r),Et(this,t,s);e:{try{let l=new ka(this.confidenceMasks,this.categoryMask,this.qualityScores);if(!this.j){var u=l;break e}this.j(l)}finally{eo(this)}u=void 0}return u}m(){var t=new nt;de(t,"image_in"),de(t,"roi_in"),de(t,"norm_rect_in");let e=new lt;Pt(e,bf,this.h);let r=new Ze;ht(r,"mediapipe.tasks.vision.interactive_segmenter.InteractiveSegmenterGraph"),ce(r,"IMAGE:image_in"),ce(r,"ROI:roi_in"),ce(r,"NORM_RECT:norm_rect_in"),r.o(e),dt(t,r),Qs(this,t),this.outputConfidenceMasks&&(J(t,"confidence_masks"),Y(r,"CONFIDENCE_MASKS:confidence_masks"),rn(this,"confidence_masks"),this.g.da("confidence_masks",((n,s)=>{this.confidenceMasks=n.map((o=>on(this,o,!0,!this.j))),G(this,s)})),this.g.attachEmptyPacketListener("confidence_masks",(n=>{this.confidenceMasks=[],G(this,n)}))),this.outputCategoryMask&&(J(t,"category_mask"),Y(r,"CATEGORY_MASK:category_mask"),rn(this,"category_mask"),this.g.V("category_mask",((n,s)=>{this.categoryMask=on(this,n,!1,!this.j),G(this,s)})),this.g.attachEmptyPacketListener("category_mask",(n=>{this.categoryMask=void 0,G(this,n)}))),J(t,"quality_scores"),Y(r,"QUALITY_SCORES:quality_scores"),this.g.attachFloatVectorListener("quality_scores",((n,s)=>{this.qualityScores=n,G(this,s)})),this.g.attachEmptyPacketListener("quality_scores",(n=>{this.categoryMask=void 0,G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};Ht.prototype.segment=Ht.prototype.segment,Ht.prototype.setOptions=Ht.prototype.o,Ht.createFromModelPath=function(t,e){return j(Ht,t,{baseOptions:{modelAssetPath:e}})},Ht.createFromModelBuffer=function(t,e){return j(Ht,t,{baseOptions:{modelAssetBuffer:e}})},Ht.createFromOptions=function(t,e){return j(Ht,t,e)};var bt=class extends rt{constructor(t,e){super(new kt(t,e),"input_frame_gpu","norm_rect",!1),this.j={detections:[]},z(t=this.h=new vf,0,1,e=new ge)}get baseOptions(){return q(this.h,ge,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){return t.displayNamesLocale!==void 0?ue(this.h,2,ln(t.displayNamesLocale)):"displayNamesLocale"in t&&ue(this.h,2),t.maxResults!==void 0?Yt(this.h,3,t.maxResults):"maxResults"in t&&ue(this.h,3),t.scoreThreshold!==void 0?W(this.h,4,t.scoreThreshold):"scoreThreshold"in t&&ue(this.h,4),t.categoryAllowlist!==void 0?Rs(this.h,5,t.categoryAllowlist):"categoryAllowlist"in t&&ue(this.h,5),t.categoryDenylist!==void 0?Rs(this.h,6,t.categoryDenylist):"categoryDenylist"in t&&ue(this.h,6),this.l(t)}D(t,e){return this.j={detections:[]},Et(this,t,e),this.j}F(t,e,r){return this.j={detections:[]},qt(this,t,r,e),this.j}m(){var t=new nt;de(t,"input_frame_gpu"),de(t,"norm_rect"),J(t,"detections");let e=new lt;Pt(e,gm,this.h);let r=new Ze;ht(r,"mediapipe.tasks.vision.ObjectDetectorGraph"),ce(r,"IMAGE:input_frame_gpu"),ce(r,"NORM_RECT:norm_rect"),Y(r,"DETECTIONS:detections"),r.o(e),dt(t,r),this.g.attachProtoVectorListener("detections",((n,s)=>{for(let o of n)n=Kl(o),this.j.detections.push(Tf(n));G(this,s)})),this.g.attachEmptyPacketListener("detections",(n=>{G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};bt.prototype.detectForVideo=bt.prototype.F,bt.prototype.detect=bt.prototype.D,bt.prototype.setOptions=bt.prototype.o,bt.createFromModelPath=async function(t,e){return j(bt,t,{baseOptions:{modelAssetPath:e}})},bt.createFromModelBuffer=function(t,e){return j(bt,t,{baseOptions:{modelAssetBuffer:e}})},bt.createFromOptions=function(t,e){return j(bt,t,e)};var Aa=class{constructor(t,e,r){this.landmarks=t,this.worldLandmarks=e,this.segmentationMasks=r}close(){this.segmentationMasks?.forEach((t=>{t.close()}))}};function Vc(t){t.landmarks=[],t.worldLandmarks=[],t.segmentationMasks=void 0}function Wc(t){try{let e=new Aa(t.landmarks,t.worldLandmarks,t.segmentationMasks);if(!t.s)return e;t.s(e)}finally{eo(t)}}Aa.prototype.close=Aa.prototype.close;var ut=class extends rt{constructor(t,e){super(new kt(t,e),"image_in","norm_rect",!1),this.landmarks=[],this.worldLandmarks=[],this.outputSegmentationMasks=!1,z(t=this.h=new wf,0,1,e=new ge),this.v=new mf,z(this.h,0,3,this.v),this.j=new df,z(this.h,0,2,this.j),Yt(this.j,4,1),W(this.j,2,.5),W(this.v,2,.5),W(this.h,4,.5)}get baseOptions(){return q(this.h,ge,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){return"numPoses"in t&&Yt(this.j,4,t.numPoses??1),"minPoseDetectionConfidence"in t&&W(this.j,2,t.minPoseDetectionConfidence??.5),"minTrackingConfidence"in t&&W(this.h,4,t.minTrackingConfidence??.5),"minPosePresenceConfidence"in t&&W(this.v,2,t.minPosePresenceConfidence??.5),"outputSegmentationMasks"in t&&(this.outputSegmentationMasks=t.outputSegmentationMasks??!1),this.l(t)}D(t,e,r){let n=typeof e!="function"?e:{};return this.s=typeof e=="function"?e:r,Vc(this),Et(this,t,n),Wc(this)}F(t,e,r,n){let s=typeof r!="function"?r:{};return this.s=typeof r=="function"?r:n,Vc(this),qt(this,t,s,e),Wc(this)}m(){var t=new nt;de(t,"image_in"),de(t,"norm_rect"),J(t,"normalized_landmarks"),J(t,"world_landmarks"),J(t,"segmentation_masks");let e=new lt;Pt(e,xm,this.h);let r=new Ze;ht(r,"mediapipe.tasks.vision.pose_landmarker.PoseLandmarkerGraph"),ce(r,"IMAGE:image_in"),ce(r,"NORM_RECT:norm_rect"),Y(r,"NORM_LANDMARKS:normalized_landmarks"),Y(r,"WORLD_LANDMARKS:world_landmarks"),r.o(e),dt(t,r),Qs(this,t),this.g.attachProtoVectorListener("normalized_landmarks",((n,s)=>{this.landmarks=[];for(let o of n)n=qn(o),this.landmarks.push(Js(n));G(this,s)})),this.g.attachEmptyPacketListener("normalized_landmarks",(n=>{this.landmarks=[],G(this,n)})),this.g.attachProtoVectorListener("world_landmarks",((n,s)=>{this.worldLandmarks=[];for(let o of n)n=Zr(o),this.worldLandmarks.push(Nn(n));G(this,s)})),this.g.attachEmptyPacketListener("world_landmarks",(n=>{this.worldLandmarks=[],G(this,n)})),this.outputSegmentationMasks&&(Y(r,"SEGMENTATION_MASK:segmentation_masks"),rn(this,"segmentation_masks"),this.g.da("segmentation_masks",((n,s)=>{this.segmentationMasks=n.map((o=>on(this,o,!0,!this.s))),G(this,s)})),this.g.attachEmptyPacketListener("segmentation_masks",(n=>{this.segmentationMasks=[],G(this,n)}))),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};ut.prototype.detectForVideo=ut.prototype.F,ut.prototype.detect=ut.prototype.D,ut.prototype.setOptions=ut.prototype.o,ut.createFromModelPath=function(t,e){return j(ut,t,{baseOptions:{modelAssetPath:e}})},ut.createFromModelBuffer=function(t,e){return j(ut,t,{baseOptions:{modelAssetBuffer:e}})},ut.createFromOptions=function(t,e){return j(ut,t,e)},ut.POSE_CONNECTIONS=Of;var Nf=(t,e)=>{let r={},n={},s={};for(let o of Object.keys(t))Object.prototype.hasOwnProperty.call(t,o)&&(Object.prototype.hasOwnProperty.call(e,o)?Ci(t[o],e[o])||(s[o]={old:t[o],new:e[o]}):n[o]=t[o]);for(let o of Object.keys(e))Object.prototype.hasOwnProperty.call(e,o)&&!Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=e[o]);return{added:r,removed:n,changed:s}},Ci=(t,e)=>{if(Object.is(t,e))return!0;if(typeof t!="object"||typeof e!="object"||t===null||e===null)return!1;let r=Array.isArray(t),n=Array.isArray(e);if(r!==n)return!1;if(r){let i=t,u=e;if(i.length!==u.length)return!1;for(let l=0;l<i.length;l++)if(!Ci(i[l],u[l]))return!1;return!0}if(!Mf(t)||!Mf(e))return!1;let s=t,o=e,a=Object.keys(s);if(a.length!==Object.keys(o).length)return!1;for(let i=0;i<a.length;i++){let u=a[i];if(!u||!Object.prototype.hasOwnProperty.call(o,u)||!Ci(s[u],o[u]))return!1}return!0},Mf=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&Object.getPrototypeOf(t)===Object.prototype;var Am="utils/memoize/noValue",hg=Symbol(Am);var Fi=t=>t;var Ui=(t,...e)=>{let r=e.reduce((n,s)=>o=>s(n(o)),Fi);return(...n)=>r(t(...n))};var Rm=t=>`(${t})`;var Gf=t=>Rm(`?:${t}`),Im=t=>`${Gf(t)}?`,Sm=t=>`${Gf(t)}*`;var Cm=t=>`^${t}`,Fm=t=>`${t}$`,Um=t=>typeof t=="function",Bm=t=>e=>Um(e)?e(t):e;var Lm=()=>t=>t,no=(t,e=Lm)=>r=>n=>Ui(Bm(n),e(n),t)(r);var yg=no(t=>Im(t)),_g=no(t=>Sm(t));var bg=no(t=>Cm(t)),vg=no(t=>Fm(t));var F=(t,e="AssertError")=>{if(!t)throw new Error(e,{cause:t});return t};var Vf=[.5,.42],Ar=432,Rr=768,Bi=[.2,.8],Wf=5,so=2,Te={Closed:"closed",Closing:"closing",Destroyed:"destroyed",Destroying:"destroying",Error:"Error",Idle:"idle",New:"new",Opened:"opened",Opening:"opening",Processing:"processing",Updated:"updated",Updating:"updating"},$f={None:"none",Blur:"blur",Overlay:"overlay"},zf={WebGL:"webgl",WebGPU:"webgpu",Canvas2D:"canvas2d"},M={ContextCreationError:"ContextCreationError",ContextLost:"ContextLost",ContextRestored:"ContextRestored",Error:"Error",ProcessorRestarted:"ProcessorRestarted",SamplingError:"SamplingError"};var Om=t=>!!(typeof t=="string"&&Object.values(M).includes(t)),oo=t=>Om(t)?t:M.Error,ao=t=>t instanceof Error?t.message:String(t),io=t=>{let e=new Set(Object.keys(t));return r=>{for(let n in r)e.has(n)&&typeof t[n]==typeof r[n]&&(t[n]=r[n])}},Dm="ImageFetchError",Mm=t=>t?t.toLowerCase().startsWith("image/"):!1,Hf=t=>{let e=new Map(t),r=new Set,n=async(a,i)=>{let u=await fetch(a,{signal:i});if(u.ok&&Mm(u.headers.get("content-type"))){let l=await u.blob();return await createImageBitmap(l)}},s=async(a,i)=>{let u=e.get(a);if(!u){if(r.has(a))return null;r.add(a);try{let l=await n(a,i);if(l)return e.set(a,l),l}catch(l){if(l instanceof Error){if(l.name!=="AbortError")throw new Error(Dm,{cause:l});return}throw l}finally{r.delete(a)}}return u},o=a=>(e.get(a)?.close(),e.delete(a));return{tryFetchingImage:s,setImage:(a,i)=>{e.has(a)&&o(a),e.set(a,i)},getImage:a=>e.get(a)??null,removeImage:o,clear:()=>{for(let a of e.values())a.close();e.clear()}}},At=(t,e)=>r=>Math.min(Math.max(r,t),e);var Xf=(t,e,r,n)=>{if(!t||!e||!r||!n||t*n===r*e)return{sx:0,sy:0,sw:t,sh:e,dx:0,dy:0,dw:r,dh:n};let s=t/e,o=r/n;if(s>o){let l=Math.ceil(t*o)/s,c=Math.abs(t-l);return{sx:Math.ceil(c/2),sy:0,sw:l,sh:e,dx:0,dy:0,dw:r,dh:n}}let a=Math.ceil(e*s)/o,i=Math.abs(e-a);return{sx:0,sy:Math.ceil(i/2),sw:t,sh:a,dx:0,dy:0,dw:r,dh:n}},xn=t=>{let e={};return new Proxy(e,{get(r,n,s){return r[n]||(r[n]=t[n]?.(e)),Reflect.get(r,n,s)}})},jf=(t,e,r)=>{let n=a=>{a.preventDefault(),r?.(),e.contextLost(a.statusMessage)},s=a=>{e.contextRestored(a.statusMessage)},o=a=>{e.contextCreationError(a.statusMessage)};return t.addEventListener("webglcontextlost",n),t.addEventListener("webglcontextrestored",s),t.addEventListener("webglcontextcreationerror",o),()=>{t.removeEventListener("webglcontextlost",n),t.removeEventListener("webglcontextrestored",s),t.removeEventListener("webglcontextcreationerror",o)}};function Yf(t,e){let r=0,n=0;for(let s=0;s<t.length;s++){let o=t[s]>=128,a=e[s]>=128;o&&a&&r++,(o||a)&&n++}return n?r/n:0}function qf(t,e,r,n){let s=1,o=[0];function a(l){return o[l]===void 0?l:(o[l]!==l&&(o[l]=a(o[l])),o[l])}function i(l,c){!l||!c||(l=a(l),c=a(c),l!==c&&(o[c]=l))}for(let l=0;l<n;l++)for(let c=0;c<r;c++){let f=l*r+c;if(t[f]<128){e[f]=0;continue}let d=c>0?e[f-1]:0,p=l>0?e[f-r]:0,T=c>0&&l>0?e[f-r-1]:0,A=c<r-1&&l>0?e[f-r+1]:0,E=d||p||T||A;E||(E=s++,o[E]=E),e[f]=E,d&&d!==E&&i(E,d),p&&p!==E&&i(E,p),T&&T!==E&&i(E,T),A&&A!==E&&i(E,A)}for(let l=0;l<e.length;l++){let c=e[l];e[l]=c?a(c):0}let u=new Map;for(let l=0;l<n;l++)for(let c=0;c<r;c++){let f=e[l*r+c];if(!f)continue;let d=u.get(f)??{sumX:0,sumY:0,count:0,minX:r,minY:n,maxX:-1,maxY:-1};d.sumX+=c,d.sumY+=l,d.count++,c<d.minX&&(d.minX=c),c>d.maxX&&(d.maxX=c),l<d.minY&&(d.minY=l),l>d.maxY&&(d.maxY=l),u.set(f,d)}return u}function Kf(t,e,r,n,s){let o=t.count,a=t.maxY-t.minY+1,i=t.sumX/t.count,u=t.sumY/t.count,l=(i-r.centerX)**2+(u-r.centerY)**2,c=1-Math.min(1,Math.sqrt(l)/Math.max(n,s)),f=o/(n*s),d=a/s;return r.iou*e+r.area*f+r.height*d+r.center*c}var Zf=()=>{try{let t=new OffscreenCanvas(1,1);return!!("WebGL2RenderingContext"in globalThis&&t.getContext("webgl2",{premultipliedAlpha:!1,powerPreference:"high-performance"}))}catch{return!1}};var ou=(t,e)=>((t+e-1)/e|0)*e;function Nm(t){return Object.keys(t)}function Gm(t,e){return new Array(t).fill(0).map((r,n)=>e(n))}var Jf=t=>ArrayBuffer.isView(t)&&!(t instanceof DataView),nh=t=>t,K=nh({i32:{numElements:1,align:4,size:4,type:"i32",View:Int32Array},u32:{numElements:1,align:4,size:4,type:"u32",View:Uint32Array},f32:{numElements:1,align:4,size:4,type:"f32",View:Float32Array},f16:{numElements:1,align:2,size:2,type:"u16",View:Uint16Array},vec2f:{numElements:2,align:8,size:8,type:"f32",View:Float32Array},vec2i:{numElements:2,align:8,size:8,type:"i32",View:Int32Array},vec2u:{numElements:2,align:8,size:8,type:"u32",View:Uint32Array},vec2h:{numElements:2,align:4,size:4,type:"u16",View:Uint16Array},vec3i:{numElements:3,align:16,size:12,type:"i32",View:Int32Array},vec3u:{numElements:3,align:16,size:12,type:"u32",View:Uint32Array},vec3f:{numElements:3,align:16,size:12,type:"f32",View:Float32Array},vec3h:{numElements:3,align:8,size:6,type:"u16",View:Uint16Array},vec4i:{numElements:4,align:16,size:16,type:"i32",View:Int32Array},vec4u:{numElements:4,align:16,size:16,type:"u32",View:Uint32Array},vec4f:{numElements:4,align:16,size:16,type:"f32",View:Float32Array},vec4h:{numElements:4,align:8,size:8,type:"u16",View:Uint16Array},mat2x2f:{numElements:4,align:8,size:16,type:"f32",View:Float32Array},mat2x2h:{numElements:4,align:4,size:8,type:"u16",View:Uint16Array},mat3x2f:{numElements:6,align:8,size:24,type:"f32",View:Float32Array},mat3x2h:{numElements:6,align:4,size:12,type:"u16",View:Uint16Array},mat4x2f:{numElements:8,align:8,size:32,type:"f32",View:Float32Array},mat4x2h:{numElements:8,align:4,size:16,type:"u16",View:Uint16Array},mat2x3f:{numElements:8,align:16,size:32,pad:[3,1],type:"f32",View:Float32Array},mat2x3h:{numElements:8,align:8,size:16,pad:[3,1],type:"u16",View:Uint16Array},mat3x3f:{numElements:12,align:16,size:48,pad:[3,1],type:"f32",View:Float32Array},mat3x3h:{numElements:12,align:8,size:24,pad:[3,1],type:"u16",View:Uint16Array},mat4x3f:{numElements:16,align:16,size:64,pad:[3,1],type:"f32",View:Float32Array},mat4x3h:{numElements:16,align:8,size:32,pad:[3,1],type:"u16",View:Uint16Array},mat2x4f:{numElements:8,align:16,size:32,type:"f32",View:Float32Array},mat2x4h:{numElements:8,align:8,size:16,type:"u16",View:Uint16Array},mat3x4f:{numElements:12,align:16,size:48,pad:[3,1],type:"f32",View:Float32Array},mat3x4h:{numElements:12,align:8,size:24,pad:[3,1],type:"u16",View:Uint16Array},mat4x4f:{numElements:16,align:16,size:64,type:"f32",View:Float32Array},mat4x4h:{numElements:16,align:8,size:32,type:"u16",View:Uint16Array},bool:{numElements:0,align:1,size:0,type:"bool",View:Uint32Array}}),En=nh({...K,"atomic<i32>":K.i32,"atomic<u32>":K.u32,"vec2<i32>":K.vec2i,"vec2<u32>":K.vec2u,"vec2<f32>":K.vec2f,"vec2<f16>":K.vec2h,"vec3<i32>":K.vec3i,"vec3<u32>":K.vec3u,"vec3<f32>":K.vec3f,"vec3<f16>":K.vec3h,"vec4<i32>":K.vec4i,"vec4<u32>":K.vec4u,"vec4<f32>":K.vec4f,"vec4<f16>":K.vec4h,"mat2x2<f32>":K.mat2x2f,"mat2x2<f16>":K.mat2x2h,"mat3x2<f32>":K.mat3x2f,"mat3x2<f16>":K.mat3x2h,"mat4x2<f32>":K.mat4x2f,"mat4x2<f16>":K.mat4x2h,"mat2x3<f32>":K.mat2x3f,"mat2x3<f16>":K.mat2x3h,"mat3x3<f32>":K.mat3x3f,"mat3x3<f16>":K.mat3x3h,"mat4x3<f32>":K.mat4x3f,"mat4x3<f16>":K.mat4x3h,"mat2x4<f32>":K.mat2x4f,"mat2x4<f16>":K.mat2x4h,"mat3x4<f32>":K.mat3x4f,"mat3x4<f16>":K.mat3x4h,"mat4x4<f32>":K.mat4x4f,"mat4x4<f16>":K.mat4x4h}),Vm=Nm(En);function Wm(t=[],e){let r=new Set;for(let n of Vm){let s=En[n];r.has(s)||(r.add(s),s.flatten=t.includes(n)?e:!e)}}Wm();function $m(t){let e=t;if(e.elementType)return e.size;{let n=t,s=e.numElements||1;if(n.fields)return t.size*s;{let o=t,{align:a}=En[o.type];return s>1?ou(t.size,a)*s:t.size}}}function Qf(t,e,r,n){let{size:s,type:o}=t;try{let{View:a,align:i,size:u}=En[o],l=n!==void 0,c=l?ou(s,i):u,f=c/a.BYTES_PER_ELEMENT,d=l?n===0?(e.byteLength-r)/c:n:1;return new a(e,r,f*d)}catch{throw new Error(`unknown type: ${o}`)}}function zm(t){return!t.fields&&!t.elementType}function Hm(t,e,r){let n=r||0,s=e||new ArrayBuffer($m(t)),o=(a,i)=>{let u=a,l=u.elementType;if(l){if(zm(l)&&En[l.type].flatten)return Qf(l,s,i,u.numElements);{let{size:c}=sh(a),f=u.numElements===0?(s.byteLength-i)/c:u.numElements;return Gm(f,d=>o(l,i+c*d))}}else{if(typeof a=="string")throw Error("unreachable");{let c=a.fields;if(c){let f={};for(let[d,{type:p,offset:T}]of Object.entries(c))f[d]=o(p,i+T);return f}else return Qf(a,s,i)}}};return{views:o(t,n),arrayBuffer:s}}function Mi(t,e){if(t!==void 0)if(Jf(e)){let r=e;if(r.length===1&&typeof t=="number")r[0]=t;else if(Array.isArray(t[0])||Jf(t[0])){let n=t[0].length,s=n===3?4:n;for(let o=0;o<t.length;++o){let a=o*s;r.set(t[o],a)}}else r.set(t)}else if(Array.isArray(e)){let r=e;t.forEach((n,s)=>{Mi(n,r[s])})}else{let r=e;for(let[n,s]of Object.entries(t)){let o=r[n];o&&Mi(s,o)}}}function xt(t,e,r=0){let n=t,s=n.group===void 0?t:n.typeDefinition,o=Hm(s,e,r);return{...o,set(a){Mi(a,o.views)}}}function Ni(t){let r=t.elementType;if(r)return Ni(r);let s=t.fields;if(s)return Object.values(s).reduce((i,{type:u})=>Math.max(i,Ni(u)),0);let{type:o}=t,{align:a}=En[o];return a}function sh(t){let r=t.elementType;if(r){let o=r.size,a=Ni(r);return{unalignedSize:o,align:a,size:ou(o,a)}}let s=t.fields;if(s){let o=Object.values(s).pop();if(o.type.size===0)return sh(o.type)}return{size:0,unalignedSize:0,align:1}}var st=class{constructor(e,r){this.name=e,this.attributes=r,this.size=0}get isArray(){return!1}get isStruct(){return!1}get isTemplate(){return!1}get isPointer(){return!1}getTypeName(){return this.name}},uo=class{constructor(e,r,n){this.name=e,this.type=r,this.attributes=n,this.offset=0,this.size=0}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray||this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},Kt=class extends st{constructor(e,r){super(e,r),this.members=[],this.align=0,this.startLine=-1,this.endLine=-1,this.inUse=!1}get isStruct(){return!0}},Zt=class extends st{constructor(e,r){super(e,r),this.count=0,this.stride=0}get isArray(){return!0}getTypeName(){return`array<${this.format.getTypeName()}, ${this.count}>`}},Jn=class extends st{constructor(e,r,n){super(e,n),this.format=r}get isPointer(){return!0}getTypeName(){return`&${this.format.getTypeName()}`}},cr=class extends st{constructor(e,r,n,s){super(e,n),this.format=r,this.access=s}get isTemplate(){return!0}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}},Ae;(t=>{t[t.Uniform=0]="Uniform",t[t.Storage=1]="Storage",t[t.Immediate=2]="Immediate",t[t.Texture=3]="Texture",t[t.Sampler=4]="Sampler",t[t.StorageTexture=5]="StorageTexture"})(Ae||(Ae={}));var Nr=class{constructor(e,r,n,s,o,a,i){this.relations=null,this.name=e,this.type=r,this.group=n,this.binding=s,this.attributes=o,this.resourceType=a,this.access=i}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}},Gi=class{constructor(e,r){this.name=e,this.type=r}},Vi=class{constructor(e,r,n,s){this.name=e,this.type=r,this.locationType=n,this.location=s,this.interpolation=null}},co=class{constructor(e,r,n,s){this.name=e,this.type=r,this.locationType=n,this.location=s}},Wi=class{constructor(e,r,n,s){this.name=e,this.type=r,this.attributes=n,this.id=s}},$i=class{constructor(e,r,n){this.name=e,this.type=r,this.attributes=n}},zi=class{constructor(e,r=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=r,this.attributes=n}},Hi=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}};function Xm(t){var e=(32768&t)>>15,r=(31744&t)>>10,n=1023&t;return r==0?(e?-1:1)*Math.pow(2,-14)*(n/Math.pow(2,10)):r==31?n?NaN:1/0*(e?-1:1):(e?-1:1)*Math.pow(2,r-15)*(1+n/Math.pow(2,10))}var oh=new Float32Array(1),jm=new Int32Array(oh.buffer),Ye=new Uint16Array(1);function Ym(t){oh[0]=t;let e=jm[0],r=e>>31&1,n=e>>23&255,s=8388607&e;if(n===255)return Ye[0]=r<<15|31744|(s!==0?512:0),Ye[0];if(n===0){if(s===0)return Ye[0]=r<<15,Ye[0];s|=8388608;let o=113;for(;!(8388608&s);)s<<=1,o--;return n=127-o,s&=8388607,n>0?(s=(s>>126-n)+(s>>127-n&1),Ye[0]=r<<15|n<<10|s>>13,Ye[0]):(Ye[0]=r<<15,Ye[0])}return n=n-127+15,n>=31?(Ye[0]=r<<15|31744,Ye[0]):n<=0?n<-10?(Ye[0]=r<<15,Ye[0]):(s=(8388608|s)>>1-n,Ye[0]=r<<15|s>>13,Ye[0]):(s>>=13,Ye[0]=r<<15|n<<10|s,Ye[0])}var au=new Uint32Array(1),ah=new Float32Array(au.buffer,0,1);function eh(t){let e=112+(t>>6&31)<<23|(63&t)<<17;return au[0]=e,ah[0]}function qm(t,e,r,n,s,o,a,i,u){let l=n*(a>>=s)*(o>>=s)+r*a+e*i;switch(u){case"r8unorm":return[ee(t,l,"8unorm",1)[0]];case"r8snorm":return[ee(t,l,"8snorm",1)[0]];case"r8uint":return[ee(t,l,"8uint",1)[0]];case"r8sint":return[ee(t,l,"8sint",1)[0]];case"rg8unorm":{let c=ee(t,l,"8unorm",2);return[c[0],c[1]]}case"rg8snorm":{let c=ee(t,l,"8snorm",2);return[c[0],c[1]]}case"rg8uint":{let c=ee(t,l,"8uint",2);return[c[0],c[1]]}case"rg8sint":{let c=ee(t,l,"8sint",2);return[c[0],c[1]]}case"rgba8unorm-srgb":case"rgba8unorm":{let c=ee(t,l,"8unorm",4);return[c[0],c[1],c[2],c[3]]}case"rgba8snorm":{let c=ee(t,l,"8snorm",4);return[c[0],c[1],c[2],c[3]]}case"rgba8uint":{let c=ee(t,l,"8uint",4);return[c[0],c[1],c[2],c[3]]}case"rgba8sint":{let c=ee(t,l,"8sint",4);return[c[0],c[1],c[2],c[3]]}case"bgra8unorm-srgb":case"bgra8unorm":{let c=ee(t,l,"8unorm",4);return[c[2],c[1],c[0],c[3]]}case"r16uint":return[ee(t,l,"16uint",1)[0]];case"r16sint":return[ee(t,l,"16sint",1)[0]];case"r16float":return[ee(t,l,"16float",1)[0]];case"rg16uint":{let c=ee(t,l,"16uint",2);return[c[0],c[1]]}case"rg16sint":{let c=ee(t,l,"16sint",2);return[c[0],c[1]]}case"rg16float":{let c=ee(t,l,"16float",2);return[c[0],c[1]]}case"rgba16uint":{let c=ee(t,l,"16uint",4);return[c[0],c[1],c[2],c[3]]}case"rgba16sint":{let c=ee(t,l,"16sint",4);return[c[0],c[1],c[2],c[3]]}case"rgba16float":{let c=ee(t,l,"16float",4);return[c[0],c[1],c[2],c[3]]}case"r32uint":return[ee(t,l,"32uint",1)[0]];case"r32sint":return[ee(t,l,"32sint",1)[0]];case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return[ee(t,l,"32float",1)[0]];case"rg32uint":{let c=ee(t,l,"32uint",2);return[c[0],c[1]]}case"rg32sint":{let c=ee(t,l,"32sint",2);return[c[0],c[1]]}case"rg32float":{let c=ee(t,l,"32float",2);return[c[0],c[1]]}case"rgba32uint":{let c=ee(t,l,"32uint",4);return[c[0],c[1],c[2],c[3]]}case"rgba32sint":{let c=ee(t,l,"32sint",4);return[c[0],c[1],c[2],c[3]]}case"rgba32float":{let c=ee(t,l,"32float",4);return[c[0],c[1],c[2],c[3]]}case"rg11b10ufloat":{let c=new Uint32Array(t.buffer,l,1)[0],f=(4192256&c)>>11,d=(4290772992&c)>>22;return[eh(2047&c),eh(f),(function(p){let T=112+(p>>5&31)<<23|(31&p)<<18;return au[0]=T,ah[0]})(d),1]}}return null}function ee(t,e,r,n){let s=[0,0,0,0];for(let o=0;o<n;++o)switch(r){case"8unorm":s[o]=t[e]/255,e++;break;case"8snorm":s[o]=t[e]/255*2-1,e++;break;case"8uint":s[o]=t[e],e++;break;case"8sint":s[o]=t[e]-127,e++;break;case"16uint":s[o]=t[e]|t[e+1]<<8,e+=2;break;case"16sint":s[o]=(t[e]|t[e+1]<<8)-32768,e+=2;break;case"16float":s[o]=Xm(t[e]|t[e+1]<<8),e+=2;break;case"32uint":case"32sint":s[o]=t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24,e+=4;break;case"32float":s[o]=new Float32Array(t.buffer,e,1)[0],e+=4}return s}function te(t,e,r,n,s){for(let o=0;o<n;++o)switch(r){case"8unorm":t[e]=255*s[o],e++;break;case"8snorm":t[e]=.5*(s[o]+1)*255,e++;break;case"8uint":t[e]=s[o],e++;break;case"8sint":t[e]=s[o]+127,e++;break;case"16uint":new Uint16Array(t.buffer,e,1)[0]=s[o],e+=2;break;case"16sint":new Int16Array(t.buffer,e,1)[0]=s[o],e+=2;break;case"16float":{let a=Ym(s[o]);new Uint16Array(t.buffer,e,1)[0]=a,e+=2;break}case"32uint":new Uint32Array(t.buffer,e,1)[0]=s[o],e+=4;break;case"32sint":new Int32Array(t.buffer,e,1)[0]=s[o],e+=4;break;case"32float":new Float32Array(t.buffer,e,1)[0]=s[o],e+=4}return s}var Li={r8unorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8snorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8uint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8sint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg8unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8snorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"rgba8unorm-srgb":{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8snorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},bgra8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"bgra8unorm-srgb":{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r16uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16float:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg16uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba16uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r32uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg32uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba32uint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32sint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32float:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rg11b10ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},stencil8:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!1,hasStencil:!0,channels:1},depth16unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},depth24plus:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,depthOnlyFormat:"depth32float",channels:1},"depth24plus-stencil8":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,depthOnlyFormat:"depth32float",channels:1},depth32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},"depth32float-stencil8":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,stencilOnlyFormat:"depth32float",channels:1},rgb9e5ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"bc1-rgba-unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc1-rgba-unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc2-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc2-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc3-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc3-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc4-r-unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},"bc4-r-snorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},"bc5-rg-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},"bc5-rg-snorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},"bc6h-rgb-ufloat":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc6h-rgb-float":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc7-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc7-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8a1unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8a1unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgba8unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgba8unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"eac-r11unorm":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},"eac-r11snorm":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},"eac-rg11unorm":{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},"eac-rg11snorm":{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},"astc-4x4-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"astc-4x4-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"astc-5x4-unorm":{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},"astc-5x4-unorm-srgb":{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},"astc-5x5-unorm":{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},"astc-5x5-unorm-srgb":{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},"astc-6x5-unorm":{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},"astc-6x5-unorm-srgb":{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},"astc-6x6-unorm":{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},"astc-6x6-unorm-srgb":{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},"astc-8x5-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},"astc-8x5-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},"astc-8x6-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},"astc-8x6-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},"astc-8x8-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},"astc-8x8-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},"astc-10x5-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},"astc-10x5-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},"astc-10x6-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},"astc-10x6-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},"astc-10x8-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},"astc-10x8-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},"astc-10x10-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},"astc-10x10-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},"astc-12x10-unorm":{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},"astc-12x10-unorm-srgb":{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},"astc-12x12-unorm":{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4},"astc-12x12-unorm-srgb":{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4}},St=class t{constructor(){this.id=t._id++,this.line=0}get isAstNode(){return!0}get astNodeType(){return""}search(e){e(this)}searchBlock(e,r){if(e){r(Tn.instance);for(let n of e)n instanceof Array?this.searchBlock(n,r):n.search(r);r(kn.instance)}}constEvaluate(e,r){throw new Error("Cannot evaluate node")}constEvaluateString(e){var r,n;return(n=(r=this.constEvaluate(e))===null||r===void 0?void 0:r.toString())!==null&&n!==void 0?n:""}};St._id=0;var Tn=class extends St{};Tn.instance=new Tn;var kn=class extends St{};kn.instance=new kn;var ih=new Set(["all","any","select","arrayLength","abs","acos","acosh","asin","asinh","atan","atanh","atan2","ceil","clamp","cos","cosh","countLeadingZeros","countOneBits","countTrailingZeros","cross","degrees","determinant","distance","dot","dot4U8Packed","dot4I8Packed","exp","exp2","extractBits","faceForward","firstLeadingBit","firstTrailingBit","floor","fma","fract","frexp","insertBits","inverseSqrt","ldexp","length","log","log2","max","min","mix","modf","normalize","pow","quantizeToF16","radians","reflect","refract","reverseBits","round","saturate","sign","sin","sinh","smoothstep","sqrt","step","tan","tanh","transpose","trunc","dpdx","dpdxCoarse","dpdxFine","dpdy","dpdyCoarse","dpdyFine","fwidth","fwidthCoarse","fwidthFine","textureDimensions","textureGather","textureGatherCompare","textureLoad","textureNumLayers","textureNumLevels","textureNumSamples","textureSample","textureSampleBias","textureSampleCompare","textureSampleCompareLevel","textureSampleGrad","textureSampleLevel","textureSampleBaseClampToEdge","textureStore","atomicLoad","atomicStore","atomicAdd","atomicSub","atomicMax","atomicMin","atomicAnd","atomicOr","atomicXor","atomicExchange","atomicCompareExchangeWeak","pack4x8snorm","pack4x8unorm","pack4xI8","pack4xU8","pack4x8Clamp","pack4xU8Clamp","pack2x16snorm","pack2x16unorm","pack2x16float","unpack4x8snorm","unpack4x8unorm","unpack4xI8","unpack4xU8","unpack2x16snorm","unpack2x16unorm","unpack2x16float","storageBarrier","textureBarrier","workgroupBarrier","workgroupUniformLoad","subgroupAdd","subgroupExclusiveAdd","subgroupInclusiveAdd","subgroupAll","subgroupAnd","subgroupAny","subgroupBallot","subgroupBroadcast","subgroupBroadcastFirst","subgroupElect","subgroupMax","subgroupMin","subgroupMul","subgroupExclusiveMul","subgroupInclusiveMul","subgroupOr","subgroupShuffle","subgroupShuffleDown","subgroupShuffleUp","subgroupShuffleXor","subgroupXor","quadBroadcast","quadSwapDiagonal","quadSwapX","quadSwapY"]),le=class extends St{},zr=class extends le{constructor(e,r,n,s,o,a){super(),this.calls=new Set,this.name=e,this.args=r,this.returnType=n,this.body=s,this.startLine=o,this.endLine=a}get astNodeType(){return"function"}search(e){if(this.attributes)for(let r of this.attributes)e(r);e(this);for(let r of this.args)e(r);this.searchBlock(this.body,e)}},lo=class extends le{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}},fo=class extends le{constructor(e,r){super(),this.condition=e,this.body=r}get astNodeType(){return"while"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},Qn=class extends le{constructor(e,r){super(),this.body=e,this.loopId=r}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}},ho=class extends le{constructor(e,r,n,s){super(),this.init=e,this.condition=r,this.increment=n,this.body=s}get astNodeType(){return"for"}search(e){var r,n,s;(r=this.init)===null||r===void 0||r.search(e),(n=this.condition)===null||n===void 0||n.search(e),(s=this.increment)===null||s===void 0||s.search(e),this.searchBlock(this.body,e)}},It=class extends le{constructor(e,r,n,s,o){super(),this.attributes=null,this.name=e,this.type=r,this.storage=n,this.access=s,this.value=o}get astNodeType(){return"var"}search(e){var r;e(this),(r=this.value)===null||r===void 0||r.search(e)}},es=class extends le{constructor(e,r,n){super(),this.attributes=null,this.name=e,this.type=r,this.value=n}get astNodeType(){return"override"}search(e){var r;(r=this.value)===null||r===void 0||r.search(e)}},Vr=class extends le{constructor(e,r,n,s,o){super(),this.attributes=null,this.name=e,this.type=r,this.storage=n,this.access=s,this.value=o}get astNodeType(){return"let"}search(e){var r;e(this),(r=this.value)===null||r===void 0||r.search(e)}},bn=class extends le{constructor(e,r,n,s,o){super(),this.attributes=null,this.name=e,this.type=r,this.storage=n,this.access=s,this.value=o}get astNodeType(){return"const"}constEvaluate(e,r){return this.value.constEvaluate(e,r)}search(e){var r;e(this),(r=this.value)===null||r===void 0||r.search(e)}},yn,Zn,w,x;(t=>{t.increment="++",t.decrement="--"})(yn||(yn={})),(t=>{t.parse=function(e){let r=e;if(r==="parse")throw new Error("Invalid value for IncrementOperator");return t[r]}})(yn||(yn={}));var mo=class extends le{constructor(e,r){super(),this.operator=e,this.variable=r}get astNodeType(){return"increment"}search(e){this.variable.search(e)}};(t=>{t.assign="=",t.addAssign="+=",t.subtractAssign="-=",t.multiplyAssign="*=",t.divideAssign="/=",t.moduloAssign="%=",t.andAssign="&=",t.orAssign="|=",t.xorAssign="^=",t.shiftLeftAssign="<<=",t.shiftRightAssign=">>="})(Zn||(Zn={})),(t=>{t.parse=function(e){let r=e;if(r==="parse")throw new Error("Invalid value for AssignOperator");return r}})(Zn||(Zn={}));var po=class extends le{constructor(e,r,n){super(),this.operator=e,this.variable=r,this.value=n}get astNodeType(){return"assign"}search(e){this.variable.search(e),this.value.search(e)}},ts=class extends le{constructor(e,r){super(),this.name=e,this.args=r}get astNodeType(){return"call"}isBuiltin(){return ih.has(this.name)}search(e){for(let r of this.args)r.search(e);e(this)}},go=class extends le{constructor(e,r){super(),this.body=e,this.continuing=r}get astNodeType(){return"loop"}search(e){var r;this.searchBlock(this.body,e),(r=this.continuing)===null||r===void 0||r.search(e)}},xo=class extends le{constructor(e,r){super(),this.condition=e,this.cases=r}get astNodeType(){return"switch"}search(e){e(this);for(let r of this.cases)r.search(e)}},yo=class extends le{constructor(e,r,n,s){super(),this.condition=e,this.body=r,this.elseif=n,this.else=s}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)}},_o=class extends le{constructor(e){super(),this.value=e}get astNodeType(){return"return"}search(e){var r;(r=this.value)===null||r===void 0||r.search(e)}},Xi=class extends le{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}},ji=class extends le{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}},bo=class extends le{constructor(e,r){super(),this.severity=e,this.rule=r}get astNodeType(){return"diagnostic"}},rs=class extends le{constructor(e,r){super(),this.name=e,this.type=r}get astNodeType(){return"alias"}},Yi=class extends le{get astNodeType(){return"discard"}},vo=class extends le{constructor(){super(...arguments),this.condition=null,this.loopId=-1}get astNodeType(){return"break"}},wo=class extends le{constructor(){super(...arguments),this.loopId=-1}get astNodeType(){return"continue"}},S=class t extends le{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 r=e[0];if(r.name==="f32")return r;for(let n=1;n<e.length;++n){let s=t._priority.get(r.name);t._priority.get(e[n].name)<s&&(r=e[n])}return r.name==="x32"?t.i32:r}getTypeName(){return this.name}};S.x32=new S("x32"),S.f32=new S("f32"),S.i32=new S("i32"),S.u32=new S("u32"),S.f16=new S("f16"),S.bool=new S("bool"),S.void=new S("void"),S._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);var To=class extends S{constructor(e){super(e)}},Nt=class extends S{constructor(e,r,n,s){super(e),this.members=r,this.startLine=n,this.endLine=s}get astNodeType(){return"struct"}get isStruct(){return!0}getMemberIndex(e){for(let r=0;r<this.members.length;r++)if(this.members[r].name===e)return r;return-1}search(e){for(let r of this.members)e(r)}},b=class extends S{constructor(e,r,n){super(e),this.format=r,this.access=n}get astNodeType(){return"template"}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}};b.vec2f=new b("vec2",S.f32,null),b.vec3f=new b("vec3",S.f32,null),b.vec4f=new b("vec4",S.f32,null),b.vec2i=new b("vec2",S.i32,null),b.vec3i=new b("vec3",S.i32,null),b.vec4i=new b("vec4",S.i32,null),b.vec2u=new b("vec2",S.u32,null),b.vec3u=new b("vec3",S.u32,null),b.vec4u=new b("vec4",S.u32,null),b.vec2h=new b("vec2",S.f16,null),b.vec3h=new b("vec3",S.f16,null),b.vec4h=new b("vec4",S.f16,null),b.vec2b=new b("vec2",S.bool,null),b.vec3b=new b("vec3",S.bool,null),b.vec4b=new b("vec4",S.bool,null),b.mat2x2f=new b("mat2x2",S.f32,null),b.mat2x3f=new b("mat2x3",S.f32,null),b.mat2x4f=new b("mat2x4",S.f32,null),b.mat3x2f=new b("mat3x2",S.f32,null),b.mat3x3f=new b("mat3x3",S.f32,null),b.mat3x4f=new b("mat3x4",S.f32,null),b.mat4x2f=new b("mat4x2",S.f32,null),b.mat4x3f=new b("mat4x3",S.f32,null),b.mat4x4f=new b("mat4x4",S.f32,null),b.mat2x2h=new b("mat2x2",S.f16,null),b.mat2x3h=new b("mat2x3",S.f16,null),b.mat2x4h=new b("mat2x4",S.f16,null),b.mat3x2h=new b("mat3x2",S.f16,null),b.mat3x3h=new b("mat3x3",S.f16,null),b.mat3x4h=new b("mat3x4",S.f16,null),b.mat4x2h=new b("mat4x2",S.f16,null),b.mat4x3h=new b("mat4x3",S.f16,null),b.mat4x4h=new b("mat4x4",S.f16,null),b.mat2x2i=new b("mat2x2",S.i32,null),b.mat2x3i=new b("mat2x3",S.i32,null),b.mat2x4i=new b("mat2x4",S.i32,null),b.mat3x2i=new b("mat3x2",S.i32,null),b.mat3x3i=new b("mat3x3",S.i32,null),b.mat3x4i=new b("mat3x4",S.i32,null),b.mat4x2i=new b("mat4x2",S.i32,null),b.mat4x3i=new b("mat4x3",S.i32,null),b.mat4x4i=new b("mat4x4",S.i32,null),b.mat2x2u=new b("mat2x2",S.u32,null),b.mat2x3u=new b("mat2x3",S.u32,null),b.mat2x4u=new b("mat2x4",S.u32,null),b.mat3x2u=new b("mat3x2",S.u32,null),b.mat3x3u=new b("mat3x3",S.u32,null),b.mat3x4u=new b("mat3x4",S.u32,null),b.mat4x2u=new b("mat4x2",S.u32,null),b.mat4x3u=new b("mat4x3",S.u32,null),b.mat4x4u=new b("mat4x4",S.u32,null);var vn=class extends S{constructor(e,r,n,s){super(e),this.storage=r,this.type=n,this.access=s}get astNodeType(){return"pointer"}},Wr=class extends S{constructor(e,r,n,s){super(e),this.attributes=r,this.format=n,this.count=s}get astNodeType(){return"array"}get isArray(){return!0}},Gr=class extends S{constructor(e,r,n){super(e),this.format=r,this.access=n}get astNodeType(){return"sampler"}},gt=class extends St{constructor(){super(),this.postfix=null,this.hasParen=!1}},lr=class extends gt{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}constEvaluateString(){return this.value}},Rt=class extends gt{constructor(e,r){super(),this.type=e,this.args=r}get astNodeType(){return"createExpr"}search(e){if(e(this),this.args)for(let r of this.args)r.search(e)}constEvaluate(e,r){return r&&(r[0]=this.type),e.evalExpression(this,e.context)}},ns=class extends gt{constructor(e,r){super(),this.cachedReturnValue=null,this.name=e,this.args=r}get astNodeType(){return"callExpr"}setCachedReturnValue(e){this.cachedReturnValue=e}get isBuiltin(){return ih.has(this.name)}constEvaluate(e,r){return e.evalExpression(this,e.context)}search(e){for(let r of this.args)r.search(e);e(this)}},$e=class extends gt{constructor(e){super(),this.name=e}get astNodeType(){return"varExpr"}search(e){e(this),this.postfix&&this.postfix.search(e)}constEvaluate(e,r){return e.evalExpression(this,e.context)}},ko=class extends gt{constructor(e,r){super(),this.name=e,this.initializer=r}get astNodeType(){return"constExpr"}constEvaluate(e,r){let n=e.evalExpression(this.initializer,e.context);return n!==null&&this.postfix?n.getSubData(e,this.postfix,e.context):n}search(e){this.initializer.search(e)}},Fe=class extends gt{constructor(e,r){super(),this.value=e,this.type=r}get astNodeType(){return"literalExpr"}constEvaluate(e,r){return r!==void 0&&(r[0]=this.type),this.value}get isScalar(){return this.value instanceof y}get isVector(){return this.value instanceof m||this.value instanceof H}get scalarValue(){return this.value instanceof y?this.value.value:(console.error("Value is not scalar."),0)}get vectorValue(){return this.value instanceof m||this.value instanceof H?this.value.data:(console.error("Value is not a vector or matrix."),new Float32Array(0))}},Eo=class extends gt{constructor(e,r){super(),this.type=e,this.value=r}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}},Sr=class extends gt{constructor(e){super(),this.index=e}search(e){this.index.search(e)}},Ao=class extends gt{constructor(){super()}},ke=class extends Ao{constructor(e,r){super(),this.operator=e,this.right=r}get astNodeType(){return"unaryOp"}constEvaluate(e,r){return e.evalExpression(this,e.context)}search(e){this.right.search(e)}},mt=class extends Ao{constructor(e,r,n){super(),this.operator=e,this.left=r,this.right=n}get astNodeType(){return"binaryOp"}_getPromotedType(e,r){return e.name===r.name?e:e.name==="f32"||r.name==="f32"?S.f32:e.name==="u32"||r.name==="u32"?S.u32:S.i32}constEvaluate(e,r){return e.evalExpression(this,e.context)}search(e){this.left.search(e),this.right.search(e)}},Ro=class extends St{constructor(e){super(),this.body=e}search(e){e(this),this.searchBlock(this.body,e)}},wn=class extends gt{get astNodeType(){return"default"}},Io=class extends Ro{constructor(e,r){super(r),this.selectors=e}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}},So=class extends Ro{constructor(e){super(e)}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}},Co=class extends St{constructor(e,r,n){super(),this.name=e,this.type=r,this.attributes=n}get astNodeType(){return"argument"}},qi=class extends St{constructor(e,r){super(),this.condition=e,this.body=r}get astNodeType(){return"elseif"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},Fo=class extends St{constructor(e,r,n){super(),this.name=e,this.type=r,this.attributes=n}get astNodeType(){return"member"}},Uo=class extends St{constructor(e,r){super(),this.name=e,this.value=r}get astNodeType(){return"attribute"}},Gt=class t{constructor(e,r){this.parent=null,this.typeInfo=e,this.parent=r,this.id=t._id++}setDataValue(e,r,n,s){console.error(`SetDataValue: Not implemented for ${this.constructor.name}`)}getSubData(e,r,n){return console.error(`GetDataValue: Not implemented for ${this.constructor.name}`),null}toString(){return`<${this.typeInfo.getTypeName()}>`}};Gt._id=0;var Bo=class extends Gt{constructor(e,r){super(e,r)}clone(){return this}toString(){return this.typeInfo.name}},ss=class extends Gt{constructor(){super(new st("void",null),null)}clone(){return this}toString(){return"void"}};ss.void=new ss;var Ir=class extends Gt{constructor(e){super(new Jn("pointer",e.typeInfo,null),null),this.reference=e}clone(){return this}setDataValue(e,r,n,s){this.reference.setDataValue(e,r,n,s)}getSubData(e,r,n){return r?this.reference.getSubData(e,r,n):this}toString(){return`&${this.reference.toString()}`}},y=class t extends Gt{constructor(e,r,n=null){super(r,n),e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array?this.data=e:this.typeInfo.name==="x32"?e-Math.floor(e)!==0?this.data=new Float32Array([e]):this.data=e>=0?new Uint32Array([e]):new Int32Array([e]):this.typeInfo.name==="i32"||this.typeInfo.name==="bool"?this.data=new Int32Array([e]):this.typeInfo.name==="u32"?this.data=new Uint32Array([e]):this.typeInfo.name==="f32"||this.typeInfo.name==="f16"?this.data=new Float32Array([e]):console.error("ScalarData2: Invalid type",r)}clone(){if(this.data instanceof Float32Array)return new t(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new t(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new t(new Uint32Array(this.data),this.typeInfo,null);throw new Error("ScalarData: Invalid data type")}get value(){return this.data[0]}set value(e){this.data[0]=e}setDataValue(e,r,n,s){if(n)return void console.error("SetDataValue: Scalar data does not support postfix",n);if(!(r instanceof t))return void console.error("SetDataValue: Invalid value",r);let o=r.data[0];this.typeInfo.name==="i32"||this.typeInfo.name==="u32"?o=Math.floor(o):this.typeInfo.name==="bool"&&(o=o?1:0),this.data[0]=o}getSubData(e,r,n){return r?(console.error("getSubData: Scalar data does not support postfix",r),null):this}toString(){return`${this.value}`}};function Km(t,e,r){let n=e.length;return n===2?r==="f32"?new m(new Float32Array(e),t.getTypeInfo("vec2f")):r==="i32"||r==="bool"?new m(new Int32Array(e),t.getTypeInfo("vec2i")):r==="u32"?new m(new Uint32Array(e),t.getTypeInfo("vec2u")):r==="f16"?new m(new Float32Array(e),t.getTypeInfo("vec2h")):(console.error(`getSubData: Unknown format ${r}`),null):n===3?r==="f32"?new m(new Float32Array(e),t.getTypeInfo("vec3f")):r==="i32"||r==="bool"?new m(new Int32Array(e),t.getTypeInfo("vec3i")):r==="u32"?new m(new Uint32Array(e),t.getTypeInfo("vec3u")):r==="f16"?new m(new Float32Array(e),t.getTypeInfo("vec3h")):(console.error(`getSubData: Unknown format ${r}`),null):n===4?r==="f32"?new m(new Float32Array(e),t.getTypeInfo("vec4f")):r==="i32"||r==="bool"?new m(new Int32Array(e),t.getTypeInfo("vec4i")):r==="u32"?new m(new Uint32Array(e),t.getTypeInfo("vec4u")):r==="f16"?new m(new Float32Array(e),t.getTypeInfo("vec4h")):(console.error(`getSubData: Unknown format ${r}`),null):(console.error(`getSubData: Invalid vector size ${e.length}`),null)}var m=class t extends Gt{constructor(e,r,n=null){if(super(r,n),e instanceof Float32Array||e instanceof Uint32Array||e instanceof Int32Array)this.data=e;else{let s=this.typeInfo.name;s==="vec2f"||s==="vec3f"||s==="vec4f"?this.data=new Float32Array(e):s==="vec2i"||s==="vec3i"||s==="vec4i"?this.data=new Int32Array(e):s==="vec2u"||s==="vec3u"||s==="vec4u"?this.data=new Uint32Array(e):s==="vec2h"||s==="vec3h"||s==="vec4h"?this.data=new Float32Array(e):s==="vec2b"||s==="vec3b"||s==="vec4b"?this.data=new Int32Array(e):s==="vec2"||s==="vec3"||s==="vec4"?this.data=new Float32Array(e):console.error(`VectorData: Invalid type ${s}`)}}clone(){if(this.data instanceof Float32Array)return new t(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new t(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new t(new Uint32Array(this.data),this.typeInfo,null);throw new Error("VectorData: Invalid data type")}setDataValue(e,r,n,s){n instanceof lr?console.error("TODO: Set vector postfix"):r instanceof t?this.data=r.data:console.error("SetDataValue: Invalid value",r)}getSubData(e,r,n){if(r===null)return this;let s=e.getTypeInfo("f32");if(this.typeInfo instanceof cr)s=this.typeInfo.format||s;else{let a=this.typeInfo.name;a==="vec2f"||a==="vec3f"||a==="vec4f"?s=e.getTypeInfo("f32"):a==="vec2i"||a==="vec3i"||a==="vec4i"?s=e.getTypeInfo("i32"):a==="vec2b"||a==="vec3b"||a==="vec4b"?s=e.getTypeInfo("bool"):a==="vec2u"||a==="vec3u"||a==="vec4u"?s=e.getTypeInfo("u32"):a==="vec2h"||a==="vec3h"||a==="vec4h"?s=e.getTypeInfo("f16"):console.error(`GetSubData: Unknown type ${a}`)}let o=this;for(;r!==null&&o!==null;){if(r instanceof Sr){let a=r.index,i=-1;if(a instanceof Fe){if(!(a.value instanceof y))return console.error(`GetSubData: Invalid array index ${a.value}`),null;i=a.value.value}else{let u=e.evalExpression(a,n);if(!(u instanceof y))return console.error("GetSubData: Unknown index type",a),null;i=u.value}if(i<0||i>=o.data.length)return console.error("GetSubData: Index out of range",i),null;if(o.data instanceof Float32Array){let u=new Float32Array(o.data.buffer,o.data.byteOffset+4*i,1);return new y(u,s)}if(o.data instanceof Int32Array){let u=new Int32Array(o.data.buffer,o.data.byteOffset+4*i,1);return new y(u,s)}if(o.data instanceof Uint32Array){let u=new Uint32Array(o.data.buffer,o.data.byteOffset+4*i,1);return new y(u,s)}throw new Error("GetSubData: Invalid data type")}if(!(r instanceof lr))return console.error("GetSubData: Unknown postfix",r),null;{let a=r.value.toLowerCase();if(a.length===1){let u=0;if(a==="x"||a==="r")u=0;else if(a==="y"||a==="g")u=1;else if(a==="z"||a==="b")u=2;else{if(a!=="w"&&a!=="a")return console.error(`GetSubData: Unknown member ${a}`),null;u=3}if(this.data instanceof Float32Array){let l=new Float32Array(this.data.buffer,this.data.byteOffset+4*u,1);return new y(l,s,this)}if(this.data instanceof Int32Array){let l=new Int32Array(this.data.buffer,this.data.byteOffset+4*u,1);return new y(l,s,this)}if(this.data instanceof Uint32Array){let l=new Uint32Array(this.data.buffer,this.data.byteOffset+4*u,1);return new y(l,s,this)}}let i=[];for(let u of a)u==="x"||u==="r"?i.push(this.data[0]):u==="y"||u==="g"?i.push(this.data[1]):u==="z"||u==="b"?i.push(this.data[2]):u==="w"||u==="a"?i.push(this.data[3]):console.error(`GetDataValue: Unknown member ${u}`);o=Km(e,i,s.name)}r=r.postfix}return o}toString(){let e=`${this.data[0]}`;for(let r=1;r<this.data.length;++r)e+=`, ${this.data[r]}`;return e}},H=class t extends Gt{constructor(e,r,n=null){super(r,n),e instanceof Float32Array?this.data=e:this.data=new Float32Array(e)}clone(){return new t(new Float32Array(this.data),this.typeInfo,null)}setDataValue(e,r,n,s){n instanceof lr?console.error("TODO: Set matrix postfix"):r instanceof t?this.data=r.data:console.error("SetDataValue: Invalid value",r)}getSubData(e,r,n){if(r===null)return this;let s=this.typeInfo.name;if(e.getTypeInfo("f32"),this.typeInfo instanceof cr)this.typeInfo.format;else if(s.endsWith("f"))e.getTypeInfo("f32");else if(s.endsWith("i"))e.getTypeInfo("i32");else if(s.endsWith("u"))e.getTypeInfo("u32");else{if(!s.endsWith("h"))return console.error(`GetDataValue: Unknown type ${s}`),null;e.getTypeInfo("f16")}if(r instanceof Sr){let o=r.index,a=-1;if(o instanceof Fe){if(!(o.value instanceof y))return console.error(`GetDataValue: Invalid array index ${o.value}`),null;a=o.value.value}else{let l=e.evalExpression(o,n);if(!(l instanceof y))return console.error("GetDataValue: Unknown index type",o),null;a=l.value}if(a<0||a>=this.data.length)return console.error("GetDataValue: Index out of range",a),null;let i=s.endsWith("h")?"h":"f",u;if(s==="mat2x2"||s==="mat2x2f"||s==="mat2x2h"||s==="mat3x2"||s==="mat3x2f"||s==="mat3x2h"||s==="mat4x2"||s==="mat4x2f"||s==="mat4x2h")u=new m(new Float32Array(this.data.buffer,this.data.byteOffset+2*a*4,2),e.getTypeInfo(`vec2${i}`));else if(s==="mat2x3"||s==="mat2x3f"||s==="mat2x3h"||s==="mat3x3"||s==="mat3x3f"||s==="mat3x3h"||s==="mat4x3"||s==="mat4x3f"||s==="mat4x3h")u=new m(new Float32Array(this.data.buffer,this.data.byteOffset+3*a*4,3),e.getTypeInfo(`vec3${i}`));else{if(s!=="mat2x4"&&s!=="mat2x4f"&&s!=="mat2x4h"&&s!=="mat3x4"&&s!=="mat3x4f"&&s!=="mat3x4h"&&s!=="mat4x4"&&s!=="mat4x4f"&&s!=="mat4x4h")return console.error(`GetDataValue: Unknown type ${s}`),null;u=new m(new Float32Array(this.data.buffer,this.data.byteOffset+4*a*4,4),e.getTypeInfo(`vec4${i}`))}return r.postfix?u.getSubData(e,r.postfix,n):u}return console.error("GetDataValue: Invalid postfix",r),null}toString(){let e=`${this.data[0]}`;for(let r=1;r<this.data.length;++r)e+=`, ${this.data[r]}`;return e}},Ee=class t extends Gt{constructor(e,r,n=0,s=null){super(r,s),this.buffer=e instanceof ArrayBuffer?e:e.buffer,this.offset=n}clone(){let e=new Uint8Array(new Uint8Array(this.buffer,this.offset,this.typeInfo.size));return new t(e.buffer,this.typeInfo,0,null)}setDataValue(e,r,n,s){if(r===null)return void console.log("setDataValue: NULL data.");let o=this.offset,a=this.typeInfo;for(;n;){if(n instanceof Sr)if(a instanceof Zt){let i=n.index;if(i instanceof Fe){if(!(i.value instanceof y))return void console.error(`SetDataValue: Invalid index type ${i.value}`);o+=i.value.value*a.stride}else{let u=e.evalExpression(i,s);if(!(u instanceof y))return void console.error("SetDataValue: Unknown index type",i);o+=u.value*a.stride}a=a.format}else console.error(`SetDataValue: Type ${a.getTypeName()} is not an array`);else{if(!(n instanceof lr))return void console.error("SetDataValue: Unknown postfix type",n);{let i=n.value;if(a instanceof Kt){let u=!1;for(let l of a.members)if(l.name===i){o+=l.offset,a=l.type,u=!0;break}if(!u)return void console.error(`SetDataValue: Member ${i} not found`)}else if(a instanceof st){let u=a.getTypeName(),l=0;if(i==="x"||i==="r")l=0;else if(i==="y"||i==="g")l=1;else if(i==="z"||i==="b")l=2;else{if(i!=="w"&&i!=="a")return void console.error(`SetDataValue: Unknown member ${i}`);l=3}if(!(r instanceof y))return void console.error("SetDataValue: Invalid value",r);let c=r.value;return u==="vec2f"?void(new Float32Array(this.buffer,o,2)[l]=c):u==="vec3f"?void(new Float32Array(this.buffer,o,3)[l]=c):u==="vec4f"?void(new Float32Array(this.buffer,o,4)[l]=c):u==="vec2i"?void(new Int32Array(this.buffer,o,2)[l]=c):u==="vec3i"?void(new Int32Array(this.buffer,o,3)[l]=c):u==="vec4i"?void(new Int32Array(this.buffer,o,4)[l]=c):u==="vec2u"?void(new Uint32Array(this.buffer,o,2)[l]=c):u==="vec3u"?void(new Uint32Array(this.buffer,o,3)[l]=c):u==="vec4u"?void(new Uint32Array(this.buffer,o,4)[l]=c):void console.error(`SetDataValue: Type ${u} is not a struct`)}}}n=n.postfix}this.setData(e,r,a,o,s)}setData(e,r,n,s,o){let a=n.getTypeName();if(a!=="f32"&&a!=="f16")if(a!=="i32"&&a!=="atomic<i32>"&&a!=="x32")if(a!=="u32"&&a!=="atomic<u32>")if(a!=="bool"){if(a==="vec2f"||a==="vec2h"){let i=new Float32Array(this.buffer,s,2);return void(r instanceof m?(i[0]=r.data[0],i[1]=r.data[1]):(i[0]=r[0],i[1]=r[1]))}if(a==="vec3f"||a==="vec3h"){let i=new Float32Array(this.buffer,s,3);return void(r instanceof m?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2]):(i[0]=r[0],i[1]=r[1],i[2]=r[2]))}if(a==="vec4f"||a==="vec4h"){let i=new Float32Array(this.buffer,s,4);return void(r instanceof m?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3]))}if(a==="vec2i"){let i=new Int32Array(this.buffer,s,2);return void(r instanceof m?(i[0]=r.data[0],i[1]=r.data[1]):(i[0]=r[0],i[1]=r[1]))}if(a==="vec3i"){let i=new Int32Array(this.buffer,s,3);return void(r instanceof m?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2]):(i[0]=r[0],i[1]=r[1],i[2]=r[2]))}if(a==="vec4i"){let i=new Int32Array(this.buffer,s,4);return void(r instanceof m?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3]))}if(a==="vec2u"){let i=new Uint32Array(this.buffer,s,2);return void(r instanceof m?(i[0]=r.data[0],i[1]=r.data[1]):(i[0]=r[0],i[1]=r[1]))}if(a==="vec3u"){let i=new Uint32Array(this.buffer,s,3);return void(r instanceof m?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2]):(i[0]=r[0],i[1]=r[1],i[2]=r[2]))}if(a==="vec4u"){let i=new Uint32Array(this.buffer,s,4);return void(r instanceof m?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3]))}if(a==="vec2b"){let i=new Uint32Array(this.buffer,s,2);return void(r instanceof m?(i[0]=r.data[0],i[1]=r.data[1]):(i[0]=r[0],i[1]=r[1]))}if(a==="vec3b"){let i=new Uint32Array(this.buffer,s,3);return void(r instanceof m?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2]):(i[0]=r[0],i[1]=r[1],i[2]=r[2]))}if(a==="vec4b"){let i=new Uint32Array(this.buffer,s,4);return void(r instanceof m?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3]))}if(a==="mat2x2f"||a==="mat2x2h"){let i=new Float32Array(this.buffer,s,4);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3]))}if(a==="mat2x3f"||a==="mat2x3h"){let i=new Float32Array(this.buffer,s,6);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3],i[4]=r.data[4],i[5]=r.data[5]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],i[4]=r[4],i[5]=r[5]))}if(a==="mat2x4f"||a==="mat2x4h"){let i=new Float32Array(this.buffer,s,8);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3],i[4]=r.data[4],i[5]=r.data[5],i[6]=r.data[6],i[7]=r.data[7]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],i[4]=r[4],i[5]=r[5],i[6]=r[6],i[7]=r[7]))}if(a==="mat3x2f"||a==="mat3x2h"){let i=new Float32Array(this.buffer,s,6);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3],i[4]=r.data[4],i[5]=r.data[5]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],i[4]=r[4],i[5]=r[5]))}if(a==="mat3x3f"||a==="mat3x3h"){let i=new Float32Array(this.buffer,s,9);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3],i[4]=r.data[4],i[5]=r.data[5],i[6]=r.data[6],i[7]=r.data[7],i[8]=r.data[8]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],i[4]=r[4],i[5]=r[5],i[6]=r[6],i[7]=r[7],i[8]=r[8]))}if(a==="mat3x4f"||a==="mat3x4h"){let i=new Float32Array(this.buffer,s,12);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3],i[4]=r.data[4],i[5]=r.data[5],i[6]=r.data[6],i[7]=r.data[7],i[8]=r.data[8],i[9]=r.data[9],i[10]=r.data[10],i[11]=r.data[11]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],i[4]=r[4],i[5]=r[5],i[6]=r[6],i[7]=r[7],i[8]=r[8],i[9]=r[9],i[10]=r[10],i[11]=r[11]))}if(a==="mat4x2f"||a==="mat4x2h"){let i=new Float32Array(this.buffer,s,8);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3],i[4]=r.data[4],i[5]=r.data[5],i[6]=r.data[6],i[7]=r.data[7]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],i[4]=r[4],i[5]=r[5],i[6]=r[6],i[7]=r[7]))}if(a==="mat4x3f"||a==="mat4x3h"){let i=new Float32Array(this.buffer,s,12);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3],i[4]=r.data[4],i[5]=r.data[5],i[6]=r.data[6],i[7]=r.data[7],i[8]=r.data[8],i[9]=r.data[9],i[10]=r.data[10],i[11]=r.data[11]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],i[4]=r[4],i[5]=r[5],i[6]=r[6],i[7]=r[7],i[8]=r[8],i[9]=r[9],i[10]=r[10],i[11]=r[11]))}if(a==="mat4x4f"||a==="mat4x4h"){let i=new Float32Array(this.buffer,s,16);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3],i[4]=r.data[4],i[5]=r.data[5],i[6]=r.data[6],i[7]=r.data[7],i[8]=r.data[8],i[9]=r.data[9],i[10]=r.data[10],i[11]=r.data[11],i[12]=r.data[12],i[13]=r.data[13],i[14]=r.data[14],i[15]=r.data[15]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],i[4]=r[4],i[5]=r[5],i[6]=r[6],i[7]=r[7],i[8]=r[8],i[9]=r[9],i[10]=r[10],i[11]=r[11],i[12]=r[12],i[13]=r[13],i[14]=r[14],i[15]=r[15]))}if(r instanceof t){if(n===r.typeInfo)return void new Uint8Array(this.buffer,s,r.buffer.byteLength).set(new Uint8Array(r.buffer));console.error("SetDataValue: Type mismatch",a,r.typeInfo.getTypeName())}else console.error(`SetData: Unknown type ${a}`)}else r instanceof y&&(new Int32Array(this.buffer,s,1)[0]=r.value);else r instanceof y&&(new Uint32Array(this.buffer,s,1)[0]=r.value);else r instanceof y&&(new Int32Array(this.buffer,s,1)[0]=r.value);else r instanceof y&&(new Float32Array(this.buffer,s,1)[0]=r.value)}getSubData(e,r,n){var s,o,a;if(r===null)return this;let i=this.offset,u=this.typeInfo;for(;r;){if(r instanceof Sr){let c=r.index,f=c instanceof gt?e.evalExpression(c,n):c,d=0;if(f instanceof y?d=f.value:typeof f=="number"?d=f:console.error("GetDataValue: Invalid index type",c),u instanceof Zt)i+=d*u.stride,u=u.format;else{let p=u.getTypeName();p==="mat4x4"||p==="mat4x4f"||p==="mat4x4h"?(i+=16*d,u=e.getTypeInfo("vec4f")):p==="mat4x3"||p==="mat4x3f"||p==="mat4x3h"?(i+=12*d,u=e.getTypeInfo("vec3f")):p==="mat4x2"||p==="mat4x2f"||p==="mat4x2h"?(i+=8*d,u=e.getTypeInfo("vec2f")):p==="mat3x4"||p==="mat3x4f"||p==="mat3x4h"?(i+=12*d,u=e.getTypeInfo("vec4f")):p==="mat3x3"||p==="mat3x3f"||p==="mat3x3h"?(i+=9*d,u=e.getTypeInfo("vec3f")):p==="mat3x2"||p==="mat3x2f"||p==="mat3x2h"?(i+=6*d,u=e.getTypeInfo("vec2f")):p==="mat2x4"||p==="mat2x4f"||p==="mat2x4h"?(i+=8*d,u=e.getTypeInfo("vec4f")):p==="mat2x3"||p==="mat2x3f"||p==="mat2x3h"?(i+=6*d,u=e.getTypeInfo("vec3f")):p==="mat2x2"||p==="mat2x2f"||p==="mat2x2h"?(i+=4*d,u=e.getTypeInfo("vec2f")):p==="vec2f"||p==="vec3f"||p==="vec4f"?(i+=4*d,u=e.getTypeInfo("f32")):p==="vec2h"||p==="vec3h"||p==="vec4h"?(i+=2*d,u=e.getTypeInfo("f16")):p==="vec2b"||p==="vec3b"||p==="vec4b"?(i+=1*d,u=e.getTypeInfo("bool")):p==="vec2i"||p==="vec3i"||p==="vec4i"?(i+=4*d,u=e.getTypeInfo("i32")):p==="vec2u"||p==="vec3u"||p==="vec4u"?(i+=4*d,u=e.getTypeInfo("u32")):console.error(`getDataValue: Type ${u.getTypeName()} is not an array`)}}else{if(!(r instanceof lr))return console.error("GetDataValue: Unknown postfix type",r),null;{let c=r.value;if(u instanceof Kt){let f=!1;for(let d of u.members)if(d.name===c){i+=d.offset,u=d.type,f=!0;break}if(!f)return console.error(`GetDataValue: Member ${c} not found`),null}else if(u instanceof st){let f=u.getTypeName();if(f==="vec2f"||f==="vec3f"||f==="vec4f"||f==="vec2i"||f==="vec3i"||f==="vec4i"||f==="vec2u"||f==="vec3u"||f==="vec4u"||f==="vec2b"||f==="vec3b"||f==="vec4b"||f==="vec2h"||f==="vec3h"||f==="vec4h"||f==="vec2"||f==="vec3"||f==="vec4"){if(c.length>0&&c.length<5){let d="f",p=[];for(let T=0;T<c.length;++T){let A=c[T].toLowerCase(),E=0;if(A==="x"||A==="r")E=0;else if(A==="y"||A==="g")E=1;else if(A==="z"||A==="b")E=2;else{if(A!=="w"&&A!=="a")return console.error(`Unknown member ${c}`),null;E=3}if(c.length===1){if(f.endsWith("f"))return this.buffer.byteLength<i+4*E+4?(console.log("Insufficient buffer data"),null):new y(new Float32Array(this.buffer,i+4*E,1),e.getTypeInfo("f32"),this);if(f.endsWith("h"))return new y(new Float32Array(this.buffer,i+4*E,1),e.getTypeInfo("f16"),this);if(f.endsWith("i"))return new y(new Int32Array(this.buffer,i+4*E,1),e.getTypeInfo("i32"),this);if(f.endsWith("b"))return new y(new Int32Array(this.buffer,i+4*E,1),e.getTypeInfo("bool"),this);if(f.endsWith("u"))return new y(new Uint32Array(this.buffer,i+4*E,1),e.getTypeInfo("i32"),this)}if(f==="vec2f")p.push(new Float32Array(this.buffer,i,2)[E]);else if(f==="vec3f"){if(i+12>=this.buffer.byteLength)return console.log("Insufficient buffer data"),null;let I=new Float32Array(this.buffer,i,3);p.push(I[E])}else if(f==="vec4f")p.push(new Float32Array(this.buffer,i,4)[E]);else if(f==="vec2i")d="i",p.push(new Int32Array(this.buffer,i,2)[E]);else if(f==="vec3i")d="i",p.push(new Int32Array(this.buffer,i,3)[E]);else if(f==="vec4i")d="i",p.push(new Int32Array(this.buffer,i,4)[E]);else if(f==="vec2u"){d="u";let I=new Uint32Array(this.buffer,i,2);p.push(I[E])}else f==="vec3u"?(d="u",p.push(new Uint32Array(this.buffer,i,3)[E])):f==="vec4u"&&(d="u",p.push(new Uint32Array(this.buffer,i,4)[E]))}return p.length===2?u=e.getTypeInfo(`vec2${d}`):p.length===3?u=e.getTypeInfo(`vec3${d}`):p.length===4?u=e.getTypeInfo(`vec4${d}`):console.error(`GetDataValue: Invalid vector length ${p.length}`),new m(p,u,null)}return console.error(`GetDataValue: Unknown member ${c}`),null}return console.error(`GetDataValue: Type ${f} is not a struct`),null}}}r=r.postfix}let l=u.getTypeName();return l==="f32"?new y(new Float32Array(this.buffer,i,1),u,this):l==="i32"?new y(new Int32Array(this.buffer,i,1),u,this):l==="u32"?new y(new Uint32Array(this.buffer,i,1),u,this):l==="vec2f"?new m(new Float32Array(this.buffer,i,2),u,this):l==="vec3f"?new m(new Float32Array(this.buffer,i,3),u,this):l==="vec4f"?new m(new Float32Array(this.buffer,i,4),u,this):l==="vec2i"?new m(new Int32Array(this.buffer,i,2),u,this):l==="vec3i"?new m(new Int32Array(this.buffer,i,3),u,this):l==="vec4i"?new m(new Int32Array(this.buffer,i,4),u,this):l==="vec2u"?new m(new Uint32Array(this.buffer,i,2),u,this):l==="vec3u"?new m(new Uint32Array(this.buffer,i,3),u,this):l==="vec4u"?new m(new Uint32Array(this.buffer,i,4),u,this):u instanceof cr&&u.name==="atomic"?((s=u.format)===null||s===void 0?void 0:s.name)==="u32"?new y(new Uint32Array(this.buffer,i,1)[0],u.format,this):((o=u.format)===null||o===void 0?void 0:o.name)==="i32"?new y(new Int32Array(this.buffer,i,1)[0],u.format,this):(console.error(`GetDataValue: Invalid atomic format ${(a=u.format)===null||a===void 0?void 0:a.name}`),null):new t(this.buffer,u,i,this)}toArray(){let e=this.typeInfo.getTypeName();return e==="f32"||e==="f16"?new Float32Array(this.buffer,this.offset,1):e==="i32"||e==="atomic<i32>"||e==="x32"?new Int32Array(this.buffer,this.offset,1):e==="u32"||e==="atomic<u32>"?new Uint32Array(this.buffer,this.offset,1):e==="bool"?new Int32Array(this.buffer,this.offset,1):e==="vec2f"||e==="vec2h"?new Float32Array(this.buffer,this.offset,2):e==="vec3f"||e==="vec3h"?new Float32Array(this.buffer,this.offset,3):e==="vec4f"||e==="vec4h"?new Float32Array(this.buffer,this.offset,4):e==="vec2i"?new Int32Array(this.buffer,this.offset,2):e==="vec3i"?new Int32Array(this.buffer,this.offset,3):e==="vec4i"?new Int32Array(this.buffer,this.offset,4):e==="vec2u"?new Uint32Array(this.buffer,this.offset,2):e==="vec3u"?new Uint32Array(this.buffer,this.offset,3):e==="vec4u"?new Uint32Array(this.buffer,this.offset,4):e==="vec2b"?new Uint32Array(this.buffer,this.offset,2):e==="vec3b"?new Uint32Array(this.buffer,this.offset,3):e==="vec4b"?new Uint32Array(this.buffer,this.offset,4):e==="mat2x2f"||e==="mat2x2h"?new Float32Array(this.buffer,this.offset,4):e==="mat2x3f"||e==="mat2x3h"?new Float32Array(this.buffer,this.offset,6):e==="mat2x4f"||e==="mat2x4h"?new Float32Array(this.buffer,this.offset,8):e==="mat3x2f"||e==="mat3x2h"?new Float32Array(this.buffer,this.offset,6):e==="mat3x3f"||e==="mat3x3h"?new Float32Array(this.buffer,this.offset,9):e==="mat3x4f"||e==="mat3x4h"?new Float32Array(this.buffer,this.offset,12):e==="mat4x2f"||e==="mat4x2h"?new Float32Array(this.buffer,this.offset,8):e==="mat4x3f"||e==="mat4x3h"?new Float32Array(this.buffer,this.offset,12):e==="mat4x4f"||e==="mat4x4h"?new Float32Array(this.buffer,this.offset,16):null}toString(){let e="";if(this.typeInfo instanceof Zt)if(this.typeInfo.format.name==="f32"){let r=new Float32Array(this.buffer,this.offset);e=`[${r[0]}`;for(let n=1;n<r.length;++n)e+=`, ${r[n]}`}else if(this.typeInfo.format.name==="i32"){let r=new Int32Array(this.buffer,this.offset);e=`[${r[0]}`;for(let n=1;n<r.length;++n)e+=`, ${r[n]}`}else if(this.typeInfo.format.name==="u32"){let r=new Uint32Array(this.buffer,this.offset);e=`[${r[0]}`;for(let n=1;n<r.length;++n)e+=`, ${r[n]}`}else if(this.typeInfo.format.name==="vec2f"){let r=new Float32Array(this.buffer,this.offset);e=`[${r[0]}, ${r[1]}]`;for(let n=1;n<r.length/2;++n)e+=`, [${r[2*n]}, ${r[2*n+1]}]`}else if(this.typeInfo.format.name==="vec3f"){let r=new Float32Array(this.buffer,this.offset);e=`[${r[0]}, ${r[1]}, ${r[2]}]`;for(let n=4;n<r.length;n+=4)e+=`, [${r[n]}, ${r[n+1]}, ${r[n+2]}]`}else if(this.typeInfo.format.name==="vec4f"){let r=new Float32Array(this.buffer,this.offset);e=`[${r[0]}, ${r[1]}, ${r[2]}, ${r[3]}]`;for(let n=4;n<r.length;n+=4)e+=`, [${r[n]}, ${r[n+1]}, ${r[n+2]}, ${r[n+3]}]`}else e="[...]";else this.typeInfo instanceof Kt?e+="{...}":e="[...]";return e}},ur=class t extends Gt{constructor(e,r,n,s){super(r,null),this.data=e,this.descriptor=n,this.view=s}clone(){return new t(this.data,this.typeInfo,this.descriptor,this.view)}get width(){var e,r;let n=this.descriptor.size;return n instanceof Array&&n.length>0?(e=n[0])!==null&&e!==void 0?e:0:n instanceof Object&&(r=n.width)!==null&&r!==void 0?r:0}get height(){var e,r;let n=this.descriptor.size;return n instanceof Array&&n.length>1?(e=n[1])!==null&&e!==void 0?e:0:n instanceof Object&&(r=n.height)!==null&&r!==void 0?r:0}get depthOrArrayLayers(){var e,r;let n=this.descriptor.size;return n instanceof Array&&n.length>2?(e=n[2])!==null&&e!==void 0?e:0:n instanceof Object&&(r=n.depthOrArrayLayers)!==null&&r!==void 0?r:0}get format(){var e;return this.descriptor&&(e=this.descriptor.format)!==null&&e!==void 0?e:"rgba8unorm"}get sampleCount(){var e;return this.descriptor&&(e=this.descriptor.sampleCount)!==null&&e!==void 0?e:1}get mipLevelCount(){var e;return this.descriptor&&(e=this.descriptor.mipLevelCount)!==null&&e!==void 0?e:1}get dimension(){var e;return this.descriptor&&(e=this.descriptor.dimension)!==null&&e!==void 0?e:"2d"}getMipLevelSize(e){if(e>=this.mipLevelCount)return[0,0,0];let r=[this.width,this.height,this.depthOrArrayLayers];for(let n=0;n<r.length;++n)r[n]=Math.max(1,r[n]>>e);return r}get texelByteSize(){let e=this.format,r=Li[e];return r?r.isDepthStencil?4:r.bytesPerBlock:0}get bytesPerRow(){return this.width*this.texelByteSize}get isDepthStencil(){let e=this.format,r=Li[e];return!!r&&r.isDepthStencil}getGpuSize(){let e=this.format,r=Li[e],n=this.width;if(!e||n<=0||!r)return-1;let s=this.height,o=this.depthOrArrayLayers,a=this.dimension;return n/r.blockWidth*(a==="1d"?1:s/r.blockHeight)*r.bytesPerBlock*o}getPixel(e,r,n=0,s=0){let o=this.texelByteSize,a=this.bytesPerRow,i=this.height,u=this.data[s];return qm(new Uint8Array(u),e,r,n,s,i,a,o,this.format)}setPixel(e,r,n,s,o){let a=this.texelByteSize,i=this.bytesPerRow,u=this.height,l=this.data[s];(function(c,f,d,p,T,A,E,I,_,v){let R=p*(E>>=T)*(A>>=T)+d*E+f*I;switch(_){case"r8unorm":return void te(c,R,"8unorm",1,v);case"r8snorm":return void te(c,R,"8snorm",1,v);case"r8uint":return void te(c,R,"8uint",1,v);case"r8sint":return void te(c,R,"8sint",1,v);case"rg8unorm":return void te(c,R,"8unorm",2,v);case"rg8snorm":return void te(c,R,"8snorm",2,v);case"rg8uint":return void te(c,R,"8uint",2,v);case"rg8sint":return void te(c,R,"8sint",2,v);case"rgba8unorm-srgb":case"rgba8unorm":case"bgra8unorm-srgb":case"bgra8unorm":return void te(c,R,"8unorm",4,v);case"rgba8snorm":return void te(c,R,"8snorm",4,v);case"rgba8uint":return void te(c,R,"8uint",4,v);case"rgba8sint":return void te(c,R,"8sint",4,v);case"r16uint":return void te(c,R,"16uint",1,v);case"r16sint":return void te(c,R,"16sint",1,v);case"r16float":return void te(c,R,"16float",1,v);case"rg16uint":return void te(c,R,"16uint",2,v);case"rg16sint":return void te(c,R,"16sint",2,v);case"rg16float":return void te(c,R,"16float",2,v);case"rgba16uint":return void te(c,R,"16uint",4,v);case"rgba16sint":return void te(c,R,"16sint",4,v);case"rgba16float":return void te(c,R,"16float",4,v);case"r32uint":return void te(c,R,"32uint",1,v);case"r32sint":return void te(c,R,"32sint",1,v);case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return void te(c,R,"32float",1,v);case"rg32uint":return void te(c,R,"32uint",2,v);case"rg32sint":return void te(c,R,"32sint",2,v);case"rg32float":return void te(c,R,"32float",2,v);case"rgba32uint":return void te(c,R,"32uint",4,v);case"rgba32sint":return void te(c,R,"32sint",4,v);case"rgba32float":return void te(c,R,"32float",4,v);case"rg11b10ufloat":console.error("TODO: rg11b10ufloat not supported for writing")}})(new Uint8Array(l),e,r,n,s,u,i,a,this.format,o)}};(t=>{t[t.token=0]="token",t[t.keyword=1]="keyword",t[t.reserved=2]="reserved"})(x||(x={}));var g=class{constructor(e,r,n){this.name=e,this.type=r,this.rule=n}toString(){return this.name}},h=class{};w=h,h.none=new g("",x.reserved,""),h.eof=new g("EOF",x.token,""),h.reserved={asm:new g("asm",x.reserved,"asm"),bf16:new g("bf16",x.reserved,"bf16"),do:new g("do",x.reserved,"do"),enum:new g("enum",x.reserved,"enum"),f16:new g("f16",x.reserved,"f16"),f64:new g("f64",x.reserved,"f64"),handle:new g("handle",x.reserved,"handle"),i8:new g("i8",x.reserved,"i8"),i16:new g("i16",x.reserved,"i16"),i64:new g("i64",x.reserved,"i64"),mat:new g("mat",x.reserved,"mat"),premerge:new g("premerge",x.reserved,"premerge"),regardless:new g("regardless",x.reserved,"regardless"),typedef:new g("typedef",x.reserved,"typedef"),u8:new g("u8",x.reserved,"u8"),u16:new g("u16",x.reserved,"u16"),u64:new g("u64",x.reserved,"u64"),unless:new g("unless",x.reserved,"unless"),using:new g("using",x.reserved,"using"),vec:new g("vec",x.reserved,"vec"),void:new g("void",x.reserved,"void")},h.keywords={array:new g("array",x.keyword,"array"),atomic:new g("atomic",x.keyword,"atomic"),bool:new g("bool",x.keyword,"bool"),f32:new g("f32",x.keyword,"f32"),i32:new g("i32",x.keyword,"i32"),mat2x2:new g("mat2x2",x.keyword,"mat2x2"),mat2x3:new g("mat2x3",x.keyword,"mat2x3"),mat2x4:new g("mat2x4",x.keyword,"mat2x4"),mat3x2:new g("mat3x2",x.keyword,"mat3x2"),mat3x3:new g("mat3x3",x.keyword,"mat3x3"),mat3x4:new g("mat3x4",x.keyword,"mat3x4"),mat4x2:new g("mat4x2",x.keyword,"mat4x2"),mat4x3:new g("mat4x3",x.keyword,"mat4x3"),mat4x4:new g("mat4x4",x.keyword,"mat4x4"),ptr:new g("ptr",x.keyword,"ptr"),sampler:new g("sampler",x.keyword,"sampler"),sampler_comparison:new g("sampler_comparison",x.keyword,"sampler_comparison"),struct:new g("struct",x.keyword,"struct"),texture_1d:new g("texture_1d",x.keyword,"texture_1d"),texture_2d:new g("texture_2d",x.keyword,"texture_2d"),texture_2d_array:new g("texture_2d_array",x.keyword,"texture_2d_array"),texture_3d:new g("texture_3d",x.keyword,"texture_3d"),texture_cube:new g("texture_cube",x.keyword,"texture_cube"),texture_cube_array:new g("texture_cube_array",x.keyword,"texture_cube_array"),texture_multisampled_2d:new g("texture_multisampled_2d",x.keyword,"texture_multisampled_2d"),texture_storage_1d:new g("texture_storage_1d",x.keyword,"texture_storage_1d"),texture_storage_2d:new g("texture_storage_2d",x.keyword,"texture_storage_2d"),texture_storage_2d_array:new g("texture_storage_2d_array",x.keyword,"texture_storage_2d_array"),texture_storage_3d:new g("texture_storage_3d",x.keyword,"texture_storage_3d"),texture_depth_2d:new g("texture_depth_2d",x.keyword,"texture_depth_2d"),texture_depth_2d_array:new g("texture_depth_2d_array",x.keyword,"texture_depth_2d_array"),texture_depth_cube:new g("texture_depth_cube",x.keyword,"texture_depth_cube"),texture_depth_cube_array:new g("texture_depth_cube_array",x.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new g("texture_depth_multisampled_2d",x.keyword,"texture_depth_multisampled_2d"),texture_external:new g("texture_external",x.keyword,"texture_external"),u32:new g("u32",x.keyword,"u32"),vec2:new g("vec2",x.keyword,"vec2"),vec3:new g("vec3",x.keyword,"vec3"),vec4:new g("vec4",x.keyword,"vec4"),bitcast:new g("bitcast",x.keyword,"bitcast"),block:new g("block",x.keyword,"block"),break:new g("break",x.keyword,"break"),case:new g("case",x.keyword,"case"),continue:new g("continue",x.keyword,"continue"),continuing:new g("continuing",x.keyword,"continuing"),default:new g("default",x.keyword,"default"),diagnostic:new g("diagnostic",x.keyword,"diagnostic"),discard:new g("discard",x.keyword,"discard"),else:new g("else",x.keyword,"else"),enable:new g("enable",x.keyword,"enable"),fallthrough:new g("fallthrough",x.keyword,"fallthrough"),false:new g("false",x.keyword,"false"),fn:new g("fn",x.keyword,"fn"),for:new g("for",x.keyword,"for"),function:new g("function",x.keyword,"function"),if:new g("if",x.keyword,"if"),let:new g("let",x.keyword,"let"),const:new g("const",x.keyword,"const"),loop:new g("loop",x.keyword,"loop"),while:new g("while",x.keyword,"while"),private:new g("private",x.keyword,"private"),read:new g("read",x.keyword,"read"),read_write:new g("read_write",x.keyword,"read_write"),return:new g("return",x.keyword,"return"),requires:new g("requires",x.keyword,"requires"),storage:new g("storage",x.keyword,"storage"),immediate:new g("immediate",x.keyword,"immediate"),switch:new g("switch",x.keyword,"switch"),true:new g("true",x.keyword,"true"),alias:new g("alias",x.keyword,"alias"),type:new g("type",x.keyword,"type"),uniform:new g("uniform",x.keyword,"uniform"),var:new g("var",x.keyword,"var"),override:new g("override",x.keyword,"override"),workgroup:new g("workgroup",x.keyword,"workgroup"),write:new g("write",x.keyword,"write"),r8unorm:new g("r8unorm",x.keyword,"r8unorm"),r8snorm:new g("r8snorm",x.keyword,"r8snorm"),r8uint:new g("r8uint",x.keyword,"r8uint"),r8sint:new g("r8sint",x.keyword,"r8sint"),r16uint:new g("r16uint",x.keyword,"r16uint"),r16sint:new g("r16sint",x.keyword,"r16sint"),r16float:new g("r16float",x.keyword,"r16float"),rg8unorm:new g("rg8unorm",x.keyword,"rg8unorm"),rg8snorm:new g("rg8snorm",x.keyword,"rg8snorm"),rg8uint:new g("rg8uint",x.keyword,"rg8uint"),rg8sint:new g("rg8sint",x.keyword,"rg8sint"),r32uint:new g("r32uint",x.keyword,"r32uint"),r32sint:new g("r32sint",x.keyword,"r32sint"),r32float:new g("r32float",x.keyword,"r32float"),rg16uint:new g("rg16uint",x.keyword,"rg16uint"),rg16sint:new g("rg16sint",x.keyword,"rg16sint"),rg16float:new g("rg16float",x.keyword,"rg16float"),rgba8unorm:new g("rgba8unorm",x.keyword,"rgba8unorm"),rgba8unorm_srgb:new g("rgba8unorm_srgb",x.keyword,"rgba8unorm_srgb"),rgba8snorm:new g("rgba8snorm",x.keyword,"rgba8snorm"),rgba8uint:new g("rgba8uint",x.keyword,"rgba8uint"),rgba8sint:new g("rgba8sint",x.keyword,"rgba8sint"),bgra8unorm:new g("bgra8unorm",x.keyword,"bgra8unorm"),bgra8unorm_srgb:new g("bgra8unorm_srgb",x.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new g("rgb10a2unorm",x.keyword,"rgb10a2unorm"),rg11b10float:new g("rg11b10float",x.keyword,"rg11b10float"),rg32uint:new g("rg32uint",x.keyword,"rg32uint"),rg32sint:new g("rg32sint",x.keyword,"rg32sint"),rg32float:new g("rg32float",x.keyword,"rg32float"),rgba16uint:new g("rgba16uint",x.keyword,"rgba16uint"),rgba16sint:new g("rgba16sint",x.keyword,"rgba16sint"),rgba16float:new g("rgba16float",x.keyword,"rgba16float"),rgba32uint:new g("rgba32uint",x.keyword,"rgba32uint"),rgba32sint:new g("rgba32sint",x.keyword,"rgba32sint"),rgba32float:new g("rgba32float",x.keyword,"rgba32float"),static_assert:new g("static_assert",x.keyword,"static_assert"),const_assert:new g("const_assert",x.keyword,"const_assert")},h.tokens={decimal_float_literal:new g("decimal_float_literal",x.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 g("hex_float_literal",x.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 g("int_literal",x.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new g("uint_literal",x.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),name:new g("name",x.token,/([_\p{XID_Start}][\p{XID_Continue}]+)|([\p{XID_Start}])/u),ident:new g("ident",x.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new g("and",x.token,"&"),and_and:new g("and_and",x.token,"&&"),arrow:new g("arrow ",x.token,"->"),attr:new g("attr",x.token,"@"),forward_slash:new g("forward_slash",x.token,"/"),bang:new g("bang",x.token,"!"),bracket_left:new g("bracket_left",x.token,"["),bracket_right:new g("bracket_right",x.token,"]"),brace_left:new g("brace_left",x.token,"{"),brace_right:new g("brace_right",x.token,"}"),colon:new g("colon",x.token,":"),comma:new g("comma",x.token,","),equal:new g("equal",x.token,"="),equal_equal:new g("equal_equal",x.token,"=="),not_equal:new g("not_equal",x.token,"!="),greater_than:new g("greater_than",x.token,">"),greater_than_equal:new g("greater_than_equal",x.token,">="),shift_right:new g("shift_right",x.token,">>"),less_than:new g("less_than",x.token,"<"),less_than_equal:new g("less_than_equal",x.token,"<="),shift_left:new g("shift_left",x.token,"<<"),modulo:new g("modulo",x.token,"%"),minus:new g("minus",x.token,"-"),minus_minus:new g("minus_minus",x.token,"--"),period:new g("period",x.token,"."),plus:new g("plus",x.token,"+"),plus_plus:new g("plus_plus",x.token,"++"),or:new g("or",x.token,"|"),or_or:new g("or_or",x.token,"||"),paren_left:new g("paren_left",x.token,"("),paren_right:new g("paren_right",x.token,")"),semicolon:new g("semicolon",x.token,";"),star:new g("star",x.token,"*"),tilde:new g("tilde",x.token,"~"),underscore:new g("underscore",x.token,"_"),xor:new g("xor",x.token,"^"),plus_equal:new g("plus_equal",x.token,"+="),minus_equal:new g("minus_equal",x.token,"-="),times_equal:new g("times_equal",x.token,"*="),division_equal:new g("division_equal",x.token,"/="),modulo_equal:new g("modulo_equal",x.token,"%="),and_equal:new g("and_equal",x.token,"&="),or_equal:new g("or_equal",x.token,"|="),xor_equal:new g("xor_equal",x.token,"^="),shift_right_equal:new g("shift_right_equal",x.token,">>="),shift_left_equal:new g("shift_left_equal",x.token,"<<=")},h.simpleTokens={"@":w.tokens.attr,"{":w.tokens.brace_left,"}":w.tokens.brace_right,":":w.tokens.colon,",":w.tokens.comma,"(":w.tokens.paren_left,")":w.tokens.paren_right,";":w.tokens.semicolon},h.literalTokens={"&":w.tokens.and,"&&":w.tokens.and_and,"->":w.tokens.arrow,"/":w.tokens.forward_slash,"!":w.tokens.bang,"[":w.tokens.bracket_left,"]":w.tokens.bracket_right,"=":w.tokens.equal,"==":w.tokens.equal_equal,"!=":w.tokens.not_equal,">":w.tokens.greater_than,">=":w.tokens.greater_than_equal,">>":w.tokens.shift_right,"<":w.tokens.less_than,"<=":w.tokens.less_than_equal,"<<":w.tokens.shift_left,"%":w.tokens.modulo,"-":w.tokens.minus,"--":w.tokens.minus_minus,".":w.tokens.period,"+":w.tokens.plus,"++":w.tokens.plus_plus,"|":w.tokens.or,"||":w.tokens.or_or,"*":w.tokens.star,"~":w.tokens.tilde,_:w.tokens.underscore,"^":w.tokens.xor,"+=":w.tokens.plus_equal,"-=":w.tokens.minus_equal,"*=":w.tokens.times_equal,"/=":w.tokens.division_equal,"%=":w.tokens.modulo_equal,"&=":w.tokens.and_equal,"|=":w.tokens.or_equal,"^=":w.tokens.xor_equal,">>=":w.tokens.shift_right_equal,"<<=":w.tokens.shift_left_equal},h.regexTokens={decimal_float_literal:w.tokens.decimal_float_literal,hex_float_literal:w.tokens.hex_float_literal,int_literal:w.tokens.int_literal,uint_literal:w.tokens.uint_literal,ident:w.tokens.ident},h.storage_class=[w.keywords.function,w.keywords.private,w.keywords.workgroup,w.keywords.uniform,w.keywords.storage,w.keywords.immediate],h.access_mode=[w.keywords.read,w.keywords.write,w.keywords.read_write],h.sampler_type=[w.keywords.sampler,w.keywords.sampler_comparison],h.sampled_texture_type=[w.keywords.texture_1d,w.keywords.texture_2d,w.keywords.texture_2d_array,w.keywords.texture_3d,w.keywords.texture_cube,w.keywords.texture_cube_array],h.multisampled_texture_type=[w.keywords.texture_multisampled_2d],h.storage_texture_type=[w.keywords.texture_storage_1d,w.keywords.texture_storage_2d,w.keywords.texture_storage_2d_array,w.keywords.texture_storage_3d],h.depth_texture_type=[w.keywords.texture_depth_2d,w.keywords.texture_depth_2d_array,w.keywords.texture_depth_cube,w.keywords.texture_depth_cube_array,w.keywords.texture_depth_multisampled_2d],h.texture_external_type=[w.keywords.texture_external],h.any_texture_type=[...w.sampled_texture_type,...w.multisampled_texture_type,...w.storage_texture_type,...w.depth_texture_type,...w.texture_external_type],h.texel_format=[w.keywords.r8unorm,w.keywords.r8snorm,w.keywords.r8uint,w.keywords.r8sint,w.keywords.r16uint,w.keywords.r16sint,w.keywords.r16float,w.keywords.rg8unorm,w.keywords.rg8snorm,w.keywords.rg8uint,w.keywords.rg8sint,w.keywords.r32uint,w.keywords.r32sint,w.keywords.r32float,w.keywords.rg16uint,w.keywords.rg16sint,w.keywords.rg16float,w.keywords.rgba8unorm,w.keywords.rgba8unorm_srgb,w.keywords.rgba8snorm,w.keywords.rgba8uint,w.keywords.rgba8sint,w.keywords.bgra8unorm,w.keywords.bgra8unorm_srgb,w.keywords.rgb10a2unorm,w.keywords.rg11b10float,w.keywords.rg32uint,w.keywords.rg32sint,w.keywords.rg32float,w.keywords.rgba16uint,w.keywords.rgba16sint,w.keywords.rgba16float,w.keywords.rgba32uint,w.keywords.rgba32sint,w.keywords.rgba32float],h.const_literal=[w.tokens.int_literal,w.tokens.uint_literal,w.tokens.decimal_float_literal,w.tokens.hex_float_literal,w.keywords.true,w.keywords.false],h.literal_or_ident=[w.tokens.ident,w.tokens.int_literal,w.tokens.uint_literal,w.tokens.decimal_float_literal,w.tokens.hex_float_literal,w.tokens.name],h.element_count_expression=[w.tokens.int_literal,w.tokens.uint_literal,w.tokens.ident],h.template_types=[w.keywords.vec2,w.keywords.vec3,w.keywords.vec4,w.keywords.mat2x2,w.keywords.mat2x3,w.keywords.mat2x4,w.keywords.mat3x2,w.keywords.mat3x3,w.keywords.mat3x4,w.keywords.mat4x2,w.keywords.mat4x3,w.keywords.mat4x4,w.keywords.atomic,w.keywords.bitcast,...w.any_texture_type],h.attribute_name=[w.tokens.ident,w.keywords.block,w.keywords.diagnostic],h.assignment_operators=[w.tokens.equal,w.tokens.plus_equal,w.tokens.minus_equal,w.tokens.times_equal,w.tokens.division_equal,w.tokens.modulo_equal,w.tokens.and_equal,w.tokens.or_equal,w.tokens.xor_equal,w.tokens.shift_right_equal,w.tokens.shift_left_equal],h.increment_operators=[w.tokens.plus_plus,w.tokens.minus_minus];var Lo=class{constructor(e,r,n,s,o){this.type=e,this.lexeme=r,this.line=n,this.start=s,this.end=o}toString(){return this.lexeme}isTemplateType(){return h.template_types.includes(this.type)}isArrayType(){return this.type===h.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}},Po=class t{constructor(e){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=e??""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new Lo(h.eof,"",this._line,this._current,this._current)),this._tokens}scanToken(){let e=this._advance();if(e==`
41
+ `}C(){let t=this.g;t.activeTexture(t.TEXTURE1),this.j=Sr(this,t),t.activeTexture(t.TEXTURE2),this.B=Sr(this,t)}m(){super.m();let t=this.g;this.K=Qe(t.getUniformLocation(this.h,"defaultTexture"),"Uniform location"),this.L=Qe(t.getUniformLocation(this.h,"overlayTexture"),"Uniform location"),this.I=Qe(t.getUniformLocation(this.h,"maskTexture"),"Uniform location")}l(){super.l();let t=this.g;t.uniform1i(this.I,0),t.uniform1i(this.K,1),t.uniform1i(this.L,2)}close(){this.j&&this.g.deleteTexture(this.j),this.B&&this.g.deleteTexture(this.B),super.close()}};function cr(t,e){switch(e){case 0:return t.g.find((r=>r instanceof Uint8Array));case 1:return t.g.find((r=>r instanceof Float32Array));case 2:return t.g.find((r=>typeof WebGLTexture<"u"&&r instanceof WebGLTexture));default:throw Error(`Type is not supported: ${e}`)}}function za(t){var e=cr(t,1);if(!e){if(e=cr(t,0))e=new Float32Array(e).map((n=>n/255));else{e=new Float32Array(t.width*t.height);let n=pn(t);var r=Hi(t);if(vo(r,n,sd(t)),"iPad Simulator;iPhone Simulator;iPod Simulator;iPad;iPhone;iPod".split(";").includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"document"in self&&"ontouchend"in self.document){r=new Float32Array(t.width*t.height*4),n.readPixels(0,0,t.width,t.height,n.RGBA,n.FLOAT,r);for(let s=0,o=0;s<e.length;++s,o+=4)e[s]=r[o]}else n.readPixels(0,0,t.width,t.height,n.RED,n.FLOAT,e)}t.g.push(e)}return e}function sd(t){let e=cr(t,2);if(!e){let r=pn(t);e=ad(t);let n=za(t),s=od(t);r.texImage2D(r.TEXTURE_2D,0,s,t.width,t.height,0,r.RED,r.FLOAT,n),Ha(t)}return e}function pn(t){if(!t.canvas)throw Error("Conversion to different image formats require that a canvas is passed when initializing the image.");return t.h||(t.h=Qe(t.canvas.getContext("webgl2"),"You cannot use a canvas that is already bound to a different type of rendering context.")),t.h}function od(t){if(t=pn(t),!Us)if(t.getExtension("EXT_color_buffer_float")&&t.getExtension("OES_texture_float_linear")&&t.getExtension("EXT_float_blend"))Us=t.R32F;else{if(!t.getExtension("EXT_color_buffer_half_float"))throw Error("GPU does not fully support 4-channel float32 or float16 formats");Us=t.R16F}return Us}function Hi(t){return t.l||(t.l=new An),t.l}function ad(t){let e=pn(t);e.viewport(0,0,t.width,t.height),e.activeTexture(e.TEXTURE0);let r=cr(t,2);return r||(r=Sr(Hi(t),e,t.m?e.LINEAR:e.NEAREST),t.g.push(r),t.j=!0),e.bindTexture(e.TEXTURE_2D,r),r}function Ha(t){t.h.bindTexture(t.h.TEXTURE_2D,null)}var Us,Me=class{constructor(t,e,r,n,s,o,a){this.g=t,this.m=e,this.j=r,this.canvas=n,this.l=s,this.width=o,this.height=a,this.j&&--Zc===0&&console.error("You seem to be creating MPMask instances without invoking .close(). This leaks resources.")}Ga(){return!!cr(this,0)}ka(){return!!cr(this,1)}R(){return!!cr(this,2)}ja(){return(e=cr(t=this,0))||(e=za(t),e=new Uint8Array(e.map((r=>255*r))),t.g.push(e)),e;var t,e}ia(){return za(this)}N(){return sd(this)}clone(){let t=[];for(let e of this.g){let r;if(e instanceof Uint8Array)r=new Uint8Array(e);else if(e instanceof Float32Array)r=new Float32Array(e);else{if(!(e instanceof WebGLTexture))throw Error(`Type is not supported: ${e}`);{let n=pn(this),s=Hi(this);n.activeTexture(n.TEXTURE1),r=Sr(s,n,this.m?n.LINEAR:n.NEAREST),n.bindTexture(n.TEXTURE_2D,r);let o=od(this);n.texImage2D(n.TEXTURE_2D,0,o,this.width,this.height,0,n.RED,n.FLOAT,null),n.bindTexture(n.TEXTURE_2D,null),vo(s,n,r),as(s,n,!1,(()=>{ad(this),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.drawArrays(n.TRIANGLE_FAN,0,4),Ha(this)})),zi(s),Ha(this)}}t.push(r)}return new Me(t,this.m,this.R(),this.canvas,this.l,this.width,this.height)}close(){this.j&&pn(this).deleteTexture(cr(this,2)),Zc=-1}};Me.prototype.close=Me.prototype.close,Me.prototype.clone=Me.prototype.clone,Me.prototype.getAsWebGLTexture=Me.prototype.N,Me.prototype.getAsFloat32Array=Me.prototype.ia,Me.prototype.getAsUint8Array=Me.prototype.ja,Me.prototype.hasWebGLTexture=Me.prototype.R,Me.prototype.hasFloat32Array=Me.prototype.ka,Me.prototype.hasUint8Array=Me.prototype.Ga;var Zc=250,vm={color:"white",lineWidth:4,radius:6};function Ra(t){return{...vm,fillColor:(t=t||{}).color,...t}}function ir(t,e){return t instanceof Function?t(e):t}function Jc(t,e,r){return Math.max(Math.min(e,r),Math.min(Math.max(e,r),t))}function $n(t){if(!t.l)throw Error("CPU rendering requested but CanvasRenderingContext2D not provided.");return t.l}function es(t){if(!t.j)throw Error("GPU rendering requested but WebGL2RenderingContext not provided.");return t.j}function Qc(t,e,r){if(e.R())r(e.N());else{let n=e.ka()?e.ia():e.ja();t.m=t.m??new An;let s=es(t);r((t=new Me([n],e.m,!1,s.canvas,t.m,e.width,e.height)).N()),t.close()}}function el(t,e,r,n){let s=(function(i){return i.g||(i.g=new _m),i.g})(t),o=es(t),a=Array.isArray(r)?new ImageData(new Uint8ClampedArray(r),1,1):r;as(s,o,!0,(()=>{(function(u,l,c,f){let d=u.g;if(d.activeTexture(d.TEXTURE0),d.bindTexture(d.TEXTURE_2D,l),d.activeTexture(d.TEXTURE1),d.bindTexture(d.TEXTURE_2D,u.B),d.texImage2D(d.TEXTURE_2D,0,d.RGBA,d.RGBA,d.UNSIGNED_BYTE,c),u.I&&(function(p,b){if(p!==b)return!1;p=p.entries(),b=b.entries();for(let[A,I]of p){p=A;let _=I;var E=b.next();if(E.done)return!1;let[T,R]=E.value;if(E=R,p!==T||_[0]!==E[0]||_[1]!==E[1]||_[2]!==E[2]||_[3]!==E[3])return!1}return!!b.next().done})(u.I,f))d.activeTexture(d.TEXTURE2),d.bindTexture(d.TEXTURE_2D,u.j);else{u.I=f;let p=Array(1024).fill(0);f.forEach(((b,E)=>{if(b.length!==4)throw Error(`Color at index ${E} is not a four-channel value.`);p[4*E]=b[0],p[4*E+1]=b[1],p[4*E+2]=b[2],p[4*E+3]=b[3]})),d.activeTexture(d.TEXTURE2),d.bindTexture(d.TEXTURE_2D,u.j),d.texImage2D(d.TEXTURE_2D,0,d.RGBA,256,1,0,d.RGBA,d.UNSIGNED_BYTE,new Uint8Array(p))}})(s,e,a,n),o.clearColor(0,0,0,0),o.clear(o.COLOR_BUFFER_BIT),o.drawArrays(o.TRIANGLE_FAN,0,4);let i=s.g;i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,null),i.activeTexture(i.TEXTURE1),i.bindTexture(i.TEXTURE_2D,null),i.activeTexture(i.TEXTURE2),i.bindTexture(i.TEXTURE_2D,null)}))}function tl(t,e,r,n){let s=es(t),o=(function(u){return u.h||(u.h=new bm),u.h})(t),a=Array.isArray(r)?new ImageData(new Uint8ClampedArray(r),1,1):r,i=Array.isArray(n)?new ImageData(new Uint8ClampedArray(n),1,1):n;as(o,s,!0,(()=>{var u=o.g;u.activeTexture(u.TEXTURE0),u.bindTexture(u.TEXTURE_2D,e),u.activeTexture(u.TEXTURE1),u.bindTexture(u.TEXTURE_2D,o.j),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,u.RGBA,u.UNSIGNED_BYTE,a),u.activeTexture(u.TEXTURE2),u.bindTexture(u.TEXTURE_2D,o.B),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,u.RGBA,u.UNSIGNED_BYTE,i),s.clearColor(0,0,0,0),s.clear(s.COLOR_BUFFER_BIT),s.drawArrays(s.TRIANGLE_FAN,0,4),s.bindTexture(s.TEXTURE_2D,null),(u=o.g).activeTexture(u.TEXTURE0),u.bindTexture(u.TEXTURE_2D,null),u.activeTexture(u.TEXTURE1),u.bindTexture(u.TEXTURE_2D,null),u.activeTexture(u.TEXTURE2),u.bindTexture(u.TEXTURE_2D,null)}))}var Je=class{constructor(t,e){t instanceof CanvasRenderingContext2D||t instanceof OffscreenCanvasRenderingContext2D?(this.l=t,this.j=e):this.j=t}za(t,e){if(t){var r=$n(this);e=Ra(e),r.save();var n=r.canvas,s=0;for(let o of t)r.fillStyle=ir(e.fillColor,{index:s,from:o}),r.strokeStyle=ir(e.color,{index:s,from:o}),r.lineWidth=ir(e.lineWidth,{index:s,from:o}),(t=new Path2D).arc(o.x*n.width,o.y*n.height,ir(e.radius,{index:s,from:o}),0,2*Math.PI),r.fill(t),r.stroke(t),++s;r.restore()}}ya(t,e,r){if(t&&e){var n=$n(this);r=Ra(r),n.save();var s=n.canvas,o=0;for(let a of e){n.beginPath(),e=t[a.start];let i=t[a.end];e&&i&&(n.strokeStyle=ir(r.color,{index:o,from:e,to:i}),n.lineWidth=ir(r.lineWidth,{index:o,from:e,to:i}),n.moveTo(e.x*s.width,e.y*s.height),n.lineTo(i.x*s.width,i.y*s.height)),++o,n.stroke()}n.restore()}}va(t,e){let r=$n(this);e=Ra(e),r.save(),r.beginPath(),r.lineWidth=ir(e.lineWidth,{}),r.strokeStyle=ir(e.color,{}),r.fillStyle=ir(e.fillColor,{}),r.moveTo(t.originX,t.originY),r.lineTo(t.originX+t.width,t.originY),r.lineTo(t.originX+t.width,t.originY+t.height),r.lineTo(t.originX,t.originY+t.height),r.lineTo(t.originX,t.originY),r.stroke(),r.fill(),r.restore()}wa(t,e,r=[0,0,0,255]){this.l?(function(n,s,o,a){let i=es(n);Qc(n,s,(u=>{el(n,u,o,a),(u=$n(n)).drawImage(i.canvas,0,0,u.canvas.width,u.canvas.height)}))})(this,t,r,e):el(this,t.N(),r,e)}xa(t,e,r){this.l?(function(n,s,o,a){let i=es(n);Qc(n,s,(u=>{tl(n,u,o,a),(u=$n(n)).drawImage(i.canvas,0,0,u.canvas.width,u.canvas.height)}))})(this,t,e,r):tl(this,t.N(),e,r)}close(){this.g?.close(),this.g=void 0,this.h?.close(),this.h=void 0,this.m?.close(),this.m=void 0}};function er(t,e){switch(e){case 0:return t.g.find((r=>r instanceof ImageData));case 1:return t.g.find((r=>typeof ImageBitmap<"u"&&r instanceof ImageBitmap));case 2:return t.g.find((r=>typeof WebGLTexture<"u"&&r instanceof WebGLTexture));default:throw Error(`Type is not supported: ${e}`)}}function id(t){var e=er(t,0);if(!e){e=mn(t);let r=wo(t),n=new Uint8Array(t.width*t.height*4);vo(r,e,Ms(t)),e.readPixels(0,0,t.width,t.height,e.RGBA,e.UNSIGNED_BYTE,n),zi(r),e=new ImageData(new Uint8ClampedArray(n.buffer),t.width,t.height),t.g.push(e)}return e}function Ms(t){let e=er(t,2);if(!e){let r=mn(t);e=Ns(t);let n=er(t,1)||id(t);r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,n),Hn(t)}return e}function mn(t){if(!t.canvas)throw Error("Conversion to different image formats require that a canvas is passed when iniitializing the image.");return t.h||(t.h=Qe(t.canvas.getContext("webgl2"),"You cannot use a canvas that is already bound to a different type of rendering context.")),t.h}function wo(t){return t.l||(t.l=new An),t.l}function Ns(t){let e=mn(t);e.viewport(0,0,t.width,t.height),e.activeTexture(e.TEXTURE0);let r=er(t,2);return r||(r=Sr(wo(t),e),t.g.push(r),t.m=!0),e.bindTexture(e.TEXTURE_2D,r),r}function Hn(t){t.h.bindTexture(t.h.TEXTURE_2D,null)}function rl(t){let e=mn(t);return as(wo(t),e,!0,(()=>(function(r,n){let s=r.canvas;if(s.width===r.width&&s.height===r.height)return n();let o=s.width,a=s.height;return s.width=r.width,s.height=r.height,r=n(),s.width=o,s.height=a,r})(t,(()=>{if(e.bindFramebuffer(e.FRAMEBUFFER,null),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),e.drawArrays(e.TRIANGLE_FAN,0,4),!(t.canvas instanceof OffscreenCanvas))throw Error("Conversion to ImageBitmap requires that the MediaPipe Tasks is initialized with an OffscreenCanvas");return t.canvas.transferToImageBitmap()}))))}Je.prototype.close=Je.prototype.close,Je.prototype.drawConfidenceMask=Je.prototype.xa,Je.prototype.drawCategoryMask=Je.prototype.wa,Je.prototype.drawBoundingBox=Je.prototype.va,Je.prototype.drawConnectors=Je.prototype.ya,Je.prototype.drawLandmarks=Je.prototype.za,Je.lerp=function(t,e,r,n,s){return Jc(n*(1-(t-e)/(r-e))+s*(1-(r-t)/(r-e)),n,s)},Je.clamp=Jc,bl("DrawingUtils",Je);var Ve=class{constructor(t,e,r,n,s,o,a){this.g=t,this.j=e,this.m=r,this.canvas=n,this.l=s,this.width=o,this.height=a,(this.j||this.m)&&--nl===0&&console.error("You seem to be creating MPImage instances without invoking .close(). This leaks resources.")}Fa(){return!!er(this,0)}la(){return!!er(this,1)}R(){return!!er(this,2)}Da(){return id(this)}Ca(){var t=er(this,1);return t||(Ms(this),Ns(this),t=rl(this),Hn(this),this.g.push(t),this.j=!0),t}N(){return Ms(this)}clone(){let t=[];for(let e of this.g){let r;if(e instanceof ImageData)r=new ImageData(e.data,this.width,this.height);else if(e instanceof WebGLTexture){let n=mn(this),s=wo(this);n.activeTexture(n.TEXTURE1),r=Sr(s,n),n.bindTexture(n.TEXTURE_2D,r),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,this.width,this.height,0,n.RGBA,n.UNSIGNED_BYTE,null),n.bindTexture(n.TEXTURE_2D,null),vo(s,n,r),as(s,n,!1,(()=>{Ns(this),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.drawArrays(n.TRIANGLE_FAN,0,4),Hn(this)})),zi(s),Hn(this)}else{if(!(e instanceof ImageBitmap))throw Error(`Type is not supported: ${e}`);Ms(this),Ns(this),r=rl(this),Hn(this)}t.push(r)}return new Ve(t,this.la(),this.R(),this.canvas,this.l,this.width,this.height)}close(){this.j&&er(this,1).close(),this.m&&mn(this).deleteTexture(er(this,2)),nl=-1}};Ve.prototype.close=Ve.prototype.close,Ve.prototype.clone=Ve.prototype.clone,Ve.prototype.getAsWebGLTexture=Ve.prototype.N,Ve.prototype.getAsImageBitmap=Ve.prototype.Ca,Ve.prototype.getAsImageData=Ve.prototype.Da,Ve.prototype.hasWebGLTexture=Ve.prototype.R,Ve.prototype.hasImageBitmap=Ve.prototype.la,Ve.prototype.hasImageData=Ve.prototype.Fa;var nl=250;function Ht(...t){return t.map((([e,r])=>({start:e,end:r})))}var wm=(function(t){return class extends t{La(){this.i._registerModelResourcesGraphService()}}})((sl=class{constructor(t,e){this.l=!0,this.i=t,this.g=null,this.h=0,this.m=typeof this.i._addIntToInputStream=="function",e!==void 0?this.i.canvas=e:rd()?this.i.canvas=new OffscreenCanvas(1,1):(console.warn("OffscreenCanvas not supported and GraphRunner constructor glCanvas parameter is undefined. Creating backup canvas."),this.i.canvas=document.createElement("canvas"))}async initializeGraph(t){let e=await(await fetch(t)).arrayBuffer();t=!(t.endsWith(".pbtxt")||t.endsWith(".textproto")),this.setGraph(new Uint8Array(e),t)}setGraphFromString(t){this.setGraph(new TextEncoder().encode(t),!1)}setGraph(t,e){let r=t.length,n=this.i._malloc(r);this.i.HEAPU8.set(t,n),e?this.i._changeBinaryGraph(r,n):this.i._changeTextGraph(r,n),this.i._free(n)}configureAudio(t,e,r,n,s){this.i._configureAudio||console.warn('Attempting to use configureAudio without support for input audio. Is build dep ":gl_graph_runner_audio" missing?'),$(this,n||"input_audio",(o=>{$(this,s=s||"audio_header",(a=>{this.i._configureAudio(o,a,t,e??0,r)}))}))}setAutoResizeCanvas(t){this.l=t}setAutoRenderToScreen(t){this.i._setAutoRenderToScreen(t)}setGpuBufferVerticalFlip(t){this.i.gpuOriginForWebTexturesIsBottomLeft=t}ea(t){Zt(this,"__graph_config__",(e=>{t(e)})),$(this,"__graph_config__",(e=>{this.i._getGraphConfig(e,void 0)})),delete this.i.simpleListeners.__graph_config__}attachErrorListener(t){this.i.errorListener=t}attachEmptyPacketListener(t,e){this.i.emptyPacketListeners=this.i.emptyPacketListeners||{},this.i.emptyPacketListeners[t]=e}addAudioToStream(t,e,r){this.addAudioToStreamWithShape(t,0,0,e,r)}addAudioToStreamWithShape(t,e,r,n,s){let o=4*t.length;this.h!==o&&(this.g&&this.i._free(this.g),this.g=this.i._malloc(o),this.h=o),this.i.HEAPF32.set(t,this.g/4),$(this,n,(a=>{this.i._addAudioToInputStream(this.g,e,r,a,s)}))}addGpuBufferToStream(t,e,r){$(this,e,(n=>{let[s,o]=jc(this,t,n);this.i._addBoundTextureToStream(n,s,o,r)}))}addBoolToStream(t,e,r){$(this,e,(n=>{this.i._addBoolToInputStream(t,n,r)}))}addDoubleToStream(t,e,r){$(this,e,(n=>{this.i._addDoubleToInputStream(t,n,r)}))}addFloatToStream(t,e,r){$(this,e,(n=>{this.i._addFloatToInputStream(t,n,r)}))}addIntToStream(t,e,r){$(this,e,(n=>{this.i._addIntToInputStream(t,n,r)}))}addUintToStream(t,e,r){$(this,e,(n=>{this.i._addUintToInputStream(t,n,r)}))}addStringToStream(t,e,r){$(this,e,(n=>{$(this,t,(s=>{this.i._addStringToInputStream(s,n,r)}))}))}addStringRecordToStream(t,e,r){$(this,e,(n=>{Xc(this,Object.keys(t),(s=>{Xc(this,Object.values(t),(o=>{this.i._addFlatHashMapToInputStream(s,o,Object.keys(t).length,n,r)}))}))}))}addProtoToStream(t,e,r,n){$(this,r,(s=>{$(this,e,(o=>{let a=this.i._malloc(t.length);this.i.HEAPU8.set(t,a),this.i._addProtoToInputStream(a,t.length,o,s,n),this.i._free(a)}))}))}addEmptyPacketToStream(t,e){$(this,t,(r=>{this.i._addEmptyPacketToInputStream(r,e)}))}addBoolVectorToStream(t,e,r){$(this,e,(n=>{let s=this.i._allocateBoolVector(t.length);if(!s)throw Error("Unable to allocate new bool vector on heap.");for(let o of t)this.i._addBoolVectorEntry(s,o);this.i._addBoolVectorToInputStream(s,n,r)}))}addDoubleVectorToStream(t,e,r){$(this,e,(n=>{let s=this.i._allocateDoubleVector(t.length);if(!s)throw Error("Unable to allocate new double vector on heap.");for(let o of t)this.i._addDoubleVectorEntry(s,o);this.i._addDoubleVectorToInputStream(s,n,r)}))}addFloatVectorToStream(t,e,r){$(this,e,(n=>{let s=this.i._allocateFloatVector(t.length);if(!s)throw Error("Unable to allocate new float vector on heap.");for(let o of t)this.i._addFloatVectorEntry(s,o);this.i._addFloatVectorToInputStream(s,n,r)}))}addIntVectorToStream(t,e,r){$(this,e,(n=>{let s=this.i._allocateIntVector(t.length);if(!s)throw Error("Unable to allocate new int vector on heap.");for(let o of t)this.i._addIntVectorEntry(s,o);this.i._addIntVectorToInputStream(s,n,r)}))}addUintVectorToStream(t,e,r){$(this,e,(n=>{let s=this.i._allocateUintVector(t.length);if(!s)throw Error("Unable to allocate new unsigned int vector on heap.");for(let o of t)this.i._addUintVectorEntry(s,o);this.i._addUintVectorToInputStream(s,n,r)}))}addStringVectorToStream(t,e,r){$(this,e,(n=>{let s=this.i._allocateStringVector(t.length);if(!s)throw Error("Unable to allocate new string vector on heap.");for(let o of t)$(this,o,(a=>{this.i._addStringVectorEntry(s,a)}));this.i._addStringVectorToInputStream(s,n,r)}))}addBoolToInputSidePacket(t,e){$(this,e,(r=>{this.i._addBoolToInputSidePacket(t,r)}))}addDoubleToInputSidePacket(t,e){$(this,e,(r=>{this.i._addDoubleToInputSidePacket(t,r)}))}addFloatToInputSidePacket(t,e){$(this,e,(r=>{this.i._addFloatToInputSidePacket(t,r)}))}addIntToInputSidePacket(t,e){$(this,e,(r=>{this.i._addIntToInputSidePacket(t,r)}))}addUintToInputSidePacket(t,e){$(this,e,(r=>{this.i._addUintToInputSidePacket(t,r)}))}addStringToInputSidePacket(t,e){$(this,e,(r=>{$(this,t,(n=>{this.i._addStringToInputSidePacket(n,r)}))}))}addProtoToInputSidePacket(t,e,r){$(this,r,(n=>{$(this,e,(s=>{let o=this.i._malloc(t.length);this.i.HEAPU8.set(t,o),this.i._addProtoToInputSidePacket(o,t.length,s,n),this.i._free(o)}))}))}addBoolVectorToInputSidePacket(t,e){$(this,e,(r=>{let n=this.i._allocateBoolVector(t.length);if(!n)throw Error("Unable to allocate new bool vector on heap.");for(let s of t)this.i._addBoolVectorEntry(n,s);this.i._addBoolVectorToInputSidePacket(n,r)}))}addDoubleVectorToInputSidePacket(t,e){$(this,e,(r=>{let n=this.i._allocateDoubleVector(t.length);if(!n)throw Error("Unable to allocate new double vector on heap.");for(let s of t)this.i._addDoubleVectorEntry(n,s);this.i._addDoubleVectorToInputSidePacket(n,r)}))}addFloatVectorToInputSidePacket(t,e){$(this,e,(r=>{let n=this.i._allocateFloatVector(t.length);if(!n)throw Error("Unable to allocate new float vector on heap.");for(let s of t)this.i._addFloatVectorEntry(n,s);this.i._addFloatVectorToInputSidePacket(n,r)}))}addIntVectorToInputSidePacket(t,e){$(this,e,(r=>{let n=this.i._allocateIntVector(t.length);if(!n)throw Error("Unable to allocate new int vector on heap.");for(let s of t)this.i._addIntVectorEntry(n,s);this.i._addIntVectorToInputSidePacket(n,r)}))}addUintVectorToInputSidePacket(t,e){$(this,e,(r=>{let n=this.i._allocateUintVector(t.length);if(!n)throw Error("Unable to allocate new unsigned int vector on heap.");for(let s of t)this.i._addUintVectorEntry(n,s);this.i._addUintVectorToInputSidePacket(n,r)}))}addStringVectorToInputSidePacket(t,e){$(this,e,(r=>{let n=this.i._allocateStringVector(t.length);if(!n)throw Error("Unable to allocate new string vector on heap.");for(let s of t)$(this,s,(o=>{this.i._addStringVectorEntry(n,o)}));this.i._addStringVectorToInputSidePacket(n,r)}))}attachBoolListener(t,e){Zt(this,t,e),$(this,t,(r=>{this.i._attachBoolListener(r)}))}attachBoolVectorListener(t,e){xr(this,t,e),$(this,t,(r=>{this.i._attachBoolVectorListener(r)}))}attachIntListener(t,e){Zt(this,t,e),$(this,t,(r=>{this.i._attachIntListener(r)}))}attachIntVectorListener(t,e){xr(this,t,e),$(this,t,(r=>{this.i._attachIntVectorListener(r)}))}attachUintListener(t,e){Zt(this,t,e),$(this,t,(r=>{this.i._attachUintListener(r)}))}attachUintVectorListener(t,e){xr(this,t,e),$(this,t,(r=>{this.i._attachUintVectorListener(r)}))}attachDoubleListener(t,e){Zt(this,t,e),$(this,t,(r=>{this.i._attachDoubleListener(r)}))}attachDoubleVectorListener(t,e){xr(this,t,e),$(this,t,(r=>{this.i._attachDoubleVectorListener(r)}))}attachFloatListener(t,e){Zt(this,t,e),$(this,t,(r=>{this.i._attachFloatListener(r)}))}attachFloatVectorListener(t,e){xr(this,t,e),$(this,t,(r=>{this.i._attachFloatVectorListener(r)}))}attachStringListener(t,e){Zt(this,t,e),$(this,t,(r=>{this.i._attachStringListener(r)}))}attachStringVectorListener(t,e){xr(this,t,e),$(this,t,(r=>{this.i._attachStringVectorListener(r)}))}attachProtoListener(t,e,r){Zt(this,t,e),$(this,t,(n=>{this.i._attachProtoListener(n,r||!1)}))}attachProtoVectorListener(t,e,r){xr(this,t,e),$(this,t,(n=>{this.i._attachProtoVectorListener(n,r||!1)}))}attachAudioListener(t,e,r){this.i._attachAudioListener||console.warn('Attempting to use attachAudioListener without support for output audio. Is build dep ":gl_graph_runner_audio_out" missing?'),Zt(this,t,((n,s)=>{n=new Float32Array(n.buffer,n.byteOffset,n.length/4),e(n,s)})),$(this,t,(n=>{this.i._attachAudioListener(n,r||!1)}))}finishProcessing(){this.i._waitUntilIdle()}closeGraph(){this.i._closeGraph(),this.i.simpleListeners=void 0,this.i.emptyPacketListeners=void 0}},class extends sl{get fa(){return this.i}ra(t,e,r){$(this,e,(n=>{let[s,o]=jc(this,t,n);this.fa._addBoundTextureAsImageToStream(n,s,o,r)}))}V(t,e){Zt(this,t,e),$(this,t,(r=>{this.fa._attachImageListener(r)}))}da(t,e){xr(this,t,e),$(this,t,(r=>{this.fa._attachImageVectorListener(r)}))}})),sl,Ct=class extends wm{};async function X(t,e,r){return(async function(n,s,o,a){return xm(n,s,o,a)})(t,r.canvas??(rd()?void 0:document.createElement("canvas")),e,r)}function ud(t,e,r,n){if(t.U){let o=new Bf;if(r?.regionOfInterest){if(!t.qa)throw Error("This task doesn't support region-of-interest.");var s=r.regionOfInterest;if(s.left>=s.right||s.top>=s.bottom)throw Error("Expected RectF with left < right and top < bottom.");if(s.left<0||s.top<0||s.right>1||s.bottom>1)throw Error("Expected RectF values to be in [0,1].");W(o,1,(s.left+s.right)/2),W(o,2,(s.top+s.bottom)/2),W(o,4,s.right-s.left),W(o,3,s.bottom-s.top)}else W(o,1,.5),W(o,2,.5),W(o,4,1),W(o,3,1);if(r?.rotationDegrees){if(r?.rotationDegrees%90!=0)throw Error("Expected rotation to be a multiple of 90\xB0.");if(W(o,5,-Math.PI*r.rotationDegrees/180),r?.rotationDegrees%180!=0){let[a,i]=nd(e);r=Ce(o,3)*i/a,s=Ce(o,4)*a/i,W(o,4,r),W(o,3,s)}}t.g.addProtoToStream(o.g(),"mediapipe.NormalizedRect",t.U,n)}t.g.ra(e,t.ba,n??performance.now()),t.finishProcessing()}function Bt(t,e,r){if(t.baseOptions?.g())throw Error("Task is not initialized with image mode. 'runningMode' must be set to 'IMAGE'.");ud(t,e,r,t.B+1)}function nr(t,e,r,n){if(!t.baseOptions?.g())throw Error("Task is not initialized with video mode. 'runningMode' must be set to 'VIDEO'.");ud(t,e,r,n)}function gn(t,e,r,n){var s=e.data;let o=e.width,a=o*(e=e.height);if((s instanceof Uint8Array||s instanceof Float32Array)&&s.length!==a)throw Error("Unsupported channel count: "+s.length/a);return t=new Me([s],r,!1,t.g.i.canvas,t.P,o,e),n?t.clone():t}var ot=class extends Ds{constructor(t,e,r,n){super(t),this.g=t,this.ba=e,this.U=r,this.qa=n,this.P=new An}l(t,e=!0){if("runningMode"in t&&Jn(this.baseOptions,2,!!t.runningMode&&t.runningMode!=="IMAGE"),t.canvas!==void 0&&this.g.i.canvas!==t.canvas)throw Error("You must create a new task to reset the canvas.");return super.l(t,e)}close(){this.P.close(),super.close()}};ot.prototype.close=ot.prototype.close;var kt=class extends ot{constructor(t,e){super(new Ct(t,e),"image_in","norm_rect_in",!1),this.j={detections:[]},z(t=this.h=new yo,0,1,e=new ye),W(this.h,2,.5),W(this.h,3,.3)}get baseOptions(){return q(this.h,ye,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){return"minDetectionConfidence"in t&&W(this.h,2,t.minDetectionConfidence??.5),"minSuppressionThreshold"in t&&W(this.h,3,t.minSuppressionThreshold??.3),this.l(t)}D(t,e){return this.j={detections:[]},Bt(this,t,e),this.j}F(t,e,r){return this.j={detections:[]},nr(this,t,r,e),this.j}m(){var t=new at;pe(t,"image_in"),pe(t,"norm_rect_in"),J(t,"detections");let e=new mt;Wt(e,sm,this.h);let r=new et;yt(r,"mediapipe.tasks.vision.face_detector.FaceDetectorGraph"),ce(r,"IMAGE:image_in"),ce(r,"NORM_RECT:norm_rect_in"),Y(r,"DETECTIONS:detections"),r.o(e),xt(t,r),this.g.attachProtoVectorListener("detections",((n,s)=>{for(let o of n)n=If(o),this.j.detections.push(ed(n));G(this,s)})),this.g.attachEmptyPacketListener("detections",(n=>{G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};kt.prototype.detectForVideo=kt.prototype.F,kt.prototype.detect=kt.prototype.D,kt.prototype.setOptions=kt.prototype.o,kt.createFromModelPath=async function(t,e){return X(kt,t,{baseOptions:{modelAssetPath:e}})},kt.createFromModelBuffer=function(t,e){return X(kt,t,{baseOptions:{modelAssetBuffer:e}})},kt.createFromOptions=function(t,e){return X(kt,t,e)};var ji=Ht([61,146],[146,91],[91,181],[181,84],[84,17],[17,314],[314,405],[405,321],[321,375],[375,291],[61,185],[185,40],[40,39],[39,37],[37,0],[0,267],[267,269],[269,270],[270,409],[409,291],[78,95],[95,88],[88,178],[178,87],[87,14],[14,317],[317,402],[402,318],[318,324],[324,308],[78,191],[191,80],[80,81],[81,82],[82,13],[13,312],[312,311],[311,310],[310,415],[415,308]),Xi=Ht([263,249],[249,390],[390,373],[373,374],[374,380],[380,381],[381,382],[382,362],[263,466],[466,388],[388,387],[387,386],[386,385],[385,384],[384,398],[398,362]),Yi=Ht([276,283],[283,282],[282,295],[295,285],[300,293],[293,334],[334,296],[296,336]),cd=Ht([474,475],[475,476],[476,477],[477,474]),qi=Ht([33,7],[7,163],[163,144],[144,145],[145,153],[153,154],[154,155],[155,133],[33,246],[246,161],[161,160],[160,159],[159,158],[158,157],[157,173],[173,133]),Ki=Ht([46,53],[53,52],[52,65],[65,55],[70,63],[63,105],[105,66],[66,107]),ld=Ht([469,470],[470,471],[471,472],[472,469]),Zi=Ht([10,338],[338,297],[297,332],[332,284],[284,251],[251,389],[389,356],[356,454],[454,323],[323,361],[361,288],[288,397],[397,365],[365,379],[379,378],[378,400],[400,377],[377,152],[152,148],[148,176],[176,149],[149,150],[150,136],[136,172],[172,58],[58,132],[132,93],[93,234],[234,127],[127,162],[162,21],[21,54],[54,103],[103,67],[67,109],[109,10]),fd=[...ji,...Xi,...Yi,...qi,...Ki,...Zi],dd=Ht([127,34],[34,139],[139,127],[11,0],[0,37],[37,11],[232,231],[231,120],[120,232],[72,37],[37,39],[39,72],[128,121],[121,47],[47,128],[232,121],[121,128],[128,232],[104,69],[69,67],[67,104],[175,171],[171,148],[148,175],[118,50],[50,101],[101,118],[73,39],[39,40],[40,73],[9,151],[151,108],[108,9],[48,115],[115,131],[131,48],[194,204],[204,211],[211,194],[74,40],[40,185],[185,74],[80,42],[42,183],[183,80],[40,92],[92,186],[186,40],[230,229],[229,118],[118,230],[202,212],[212,214],[214,202],[83,18],[18,17],[17,83],[76,61],[61,146],[146,76],[160,29],[29,30],[30,160],[56,157],[157,173],[173,56],[106,204],[204,194],[194,106],[135,214],[214,192],[192,135],[203,165],[165,98],[98,203],[21,71],[71,68],[68,21],[51,45],[45,4],[4,51],[144,24],[24,23],[23,144],[77,146],[146,91],[91,77],[205,50],[50,187],[187,205],[201,200],[200,18],[18,201],[91,106],[106,182],[182,91],[90,91],[91,181],[181,90],[85,84],[84,17],[17,85],[206,203],[203,36],[36,206],[148,171],[171,140],[140,148],[92,40],[40,39],[39,92],[193,189],[189,244],[244,193],[159,158],[158,28],[28,159],[247,246],[246,161],[161,247],[236,3],[3,196],[196,236],[54,68],[68,104],[104,54],[193,168],[168,8],[8,193],[117,228],[228,31],[31,117],[189,193],[193,55],[55,189],[98,97],[97,99],[99,98],[126,47],[47,100],[100,126],[166,79],[79,218],[218,166],[155,154],[154,26],[26,155],[209,49],[49,131],[131,209],[135,136],[136,150],[150,135],[47,126],[126,217],[217,47],[223,52],[52,53],[53,223],[45,51],[51,134],[134,45],[211,170],[170,140],[140,211],[67,69],[69,108],[108,67],[43,106],[106,91],[91,43],[230,119],[119,120],[120,230],[226,130],[130,247],[247,226],[63,53],[53,52],[52,63],[238,20],[20,242],[242,238],[46,70],[70,156],[156,46],[78,62],[62,96],[96,78],[46,53],[53,63],[63,46],[143,34],[34,227],[227,143],[123,117],[117,111],[111,123],[44,125],[125,19],[19,44],[236,134],[134,51],[51,236],[216,206],[206,205],[205,216],[154,153],[153,22],[22,154],[39,37],[37,167],[167,39],[200,201],[201,208],[208,200],[36,142],[142,100],[100,36],[57,212],[212,202],[202,57],[20,60],[60,99],[99,20],[28,158],[158,157],[157,28],[35,226],[226,113],[113,35],[160,159],[159,27],[27,160],[204,202],[202,210],[210,204],[113,225],[225,46],[46,113],[43,202],[202,204],[204,43],[62,76],[76,77],[77,62],[137,123],[123,116],[116,137],[41,38],[38,72],[72,41],[203,129],[129,142],[142,203],[64,98],[98,240],[240,64],[49,102],[102,64],[64,49],[41,73],[73,74],[74,41],[212,216],[216,207],[207,212],[42,74],[74,184],[184,42],[169,170],[170,211],[211,169],[170,149],[149,176],[176,170],[105,66],[66,69],[69,105],[122,6],[6,168],[168,122],[123,147],[147,187],[187,123],[96,77],[77,90],[90,96],[65,55],[55,107],[107,65],[89,90],[90,180],[180,89],[101,100],[100,120],[120,101],[63,105],[105,104],[104,63],[93,137],[137,227],[227,93],[15,86],[86,85],[85,15],[129,102],[102,49],[49,129],[14,87],[87,86],[86,14],[55,8],[8,9],[9,55],[100,47],[47,121],[121,100],[145,23],[23,22],[22,145],[88,89],[89,179],[179,88],[6,122],[122,196],[196,6],[88,95],[95,96],[96,88],[138,172],[172,136],[136,138],[215,58],[58,172],[172,215],[115,48],[48,219],[219,115],[42,80],[80,81],[81,42],[195,3],[3,51],[51,195],[43,146],[146,61],[61,43],[171,175],[175,199],[199,171],[81,82],[82,38],[38,81],[53,46],[46,225],[225,53],[144,163],[163,110],[110,144],[52,65],[65,66],[66,52],[229,228],[228,117],[117,229],[34,127],[127,234],[234,34],[107,108],[108,69],[69,107],[109,108],[108,151],[151,109],[48,64],[64,235],[235,48],[62,78],[78,191],[191,62],[129,209],[209,126],[126,129],[111,35],[35,143],[143,111],[117,123],[123,50],[50,117],[222,65],[65,52],[52,222],[19,125],[125,141],[141,19],[221,55],[55,65],[65,221],[3,195],[195,197],[197,3],[25,7],[7,33],[33,25],[220,237],[237,44],[44,220],[70,71],[71,139],[139,70],[122,193],[193,245],[245,122],[247,130],[130,33],[33,247],[71,21],[21,162],[162,71],[170,169],[169,150],[150,170],[188,174],[174,196],[196,188],[216,186],[186,92],[92,216],[2,97],[97,167],[167,2],[141,125],[125,241],[241,141],[164,167],[167,37],[37,164],[72,38],[38,12],[12,72],[38,82],[82,13],[13,38],[63,68],[68,71],[71,63],[226,35],[35,111],[111,226],[101,50],[50,205],[205,101],[206,92],[92,165],[165,206],[209,198],[198,217],[217,209],[165,167],[167,97],[97,165],[220,115],[115,218],[218,220],[133,112],[112,243],[243,133],[239,238],[238,241],[241,239],[214,135],[135,169],[169,214],[190,173],[173,133],[133,190],[171,208],[208,32],[32,171],[125,44],[44,237],[237,125],[86,87],[87,178],[178,86],[85,86],[86,179],[179,85],[84,85],[85,180],[180,84],[83,84],[84,181],[181,83],[201,83],[83,182],[182,201],[137,93],[93,132],[132,137],[76,62],[62,183],[183,76],[61,76],[76,184],[184,61],[57,61],[61,185],[185,57],[212,57],[57,186],[186,212],[214,207],[207,187],[187,214],[34,143],[143,156],[156,34],[79,239],[239,237],[237,79],[123,137],[137,177],[177,123],[44,1],[1,4],[4,44],[201,194],[194,32],[32,201],[64,102],[102,129],[129,64],[213,215],[215,138],[138,213],[59,166],[166,219],[219,59],[242,99],[99,97],[97,242],[2,94],[94,141],[141,2],[75,59],[59,235],[235,75],[24,110],[110,228],[228,24],[25,130],[130,226],[226,25],[23,24],[24,229],[229,23],[22,23],[23,230],[230,22],[26,22],[22,231],[231,26],[112,26],[26,232],[232,112],[189,190],[190,243],[243,189],[221,56],[56,190],[190,221],[28,56],[56,221],[221,28],[27,28],[28,222],[222,27],[29,27],[27,223],[223,29],[30,29],[29,224],[224,30],[247,30],[30,225],[225,247],[238,79],[79,20],[20,238],[166,59],[59,75],[75,166],[60,75],[75,240],[240,60],[147,177],[177,215],[215,147],[20,79],[79,166],[166,20],[187,147],[147,213],[213,187],[112,233],[233,244],[244,112],[233,128],[128,245],[245,233],[128,114],[114,188],[188,128],[114,217],[217,174],[174,114],[131,115],[115,220],[220,131],[217,198],[198,236],[236,217],[198,131],[131,134],[134,198],[177,132],[132,58],[58,177],[143,35],[35,124],[124,143],[110,163],[163,7],[7,110],[228,110],[110,25],[25,228],[356,389],[389,368],[368,356],[11,302],[302,267],[267,11],[452,350],[350,349],[349,452],[302,303],[303,269],[269,302],[357,343],[343,277],[277,357],[452,453],[453,357],[357,452],[333,332],[332,297],[297,333],[175,152],[152,377],[377,175],[347,348],[348,330],[330,347],[303,304],[304,270],[270,303],[9,336],[336,337],[337,9],[278,279],[279,360],[360,278],[418,262],[262,431],[431,418],[304,408],[408,409],[409,304],[310,415],[415,407],[407,310],[270,409],[409,410],[410,270],[450,348],[348,347],[347,450],[422,430],[430,434],[434,422],[313,314],[314,17],[17,313],[306,307],[307,375],[375,306],[387,388],[388,260],[260,387],[286,414],[414,398],[398,286],[335,406],[406,418],[418,335],[364,367],[367,416],[416,364],[423,358],[358,327],[327,423],[251,284],[284,298],[298,251],[281,5],[5,4],[4,281],[373,374],[374,253],[253,373],[307,320],[320,321],[321,307],[425,427],[427,411],[411,425],[421,313],[313,18],[18,421],[321,405],[405,406],[406,321],[320,404],[404,405],[405,320],[315,16],[16,17],[17,315],[426,425],[425,266],[266,426],[377,400],[400,369],[369,377],[322,391],[391,269],[269,322],[417,465],[465,464],[464,417],[386,257],[257,258],[258,386],[466,260],[260,388],[388,466],[456,399],[399,419],[419,456],[284,332],[332,333],[333,284],[417,285],[285,8],[8,417],[346,340],[340,261],[261,346],[413,441],[441,285],[285,413],[327,460],[460,328],[328,327],[355,371],[371,329],[329,355],[392,439],[439,438],[438,392],[382,341],[341,256],[256,382],[429,420],[420,360],[360,429],[364,394],[394,379],[379,364],[277,343],[343,437],[437,277],[443,444],[444,283],[283,443],[275,440],[440,363],[363,275],[431,262],[262,369],[369,431],[297,338],[338,337],[337,297],[273,375],[375,321],[321,273],[450,451],[451,349],[349,450],[446,342],[342,467],[467,446],[293,334],[334,282],[282,293],[458,461],[461,462],[462,458],[276,353],[353,383],[383,276],[308,324],[324,325],[325,308],[276,300],[300,293],[293,276],[372,345],[345,447],[447,372],[352,345],[345,340],[340,352],[274,1],[1,19],[19,274],[456,248],[248,281],[281,456],[436,427],[427,425],[425,436],[381,256],[256,252],[252,381],[269,391],[391,393],[393,269],[200,199],[199,428],[428,200],[266,330],[330,329],[329,266],[287,273],[273,422],[422,287],[250,462],[462,328],[328,250],[258,286],[286,384],[384,258],[265,353],[353,342],[342,265],[387,259],[259,257],[257,387],[424,431],[431,430],[430,424],[342,353],[353,276],[276,342],[273,335],[335,424],[424,273],[292,325],[325,307],[307,292],[366,447],[447,345],[345,366],[271,303],[303,302],[302,271],[423,266],[266,371],[371,423],[294,455],[455,460],[460,294],[279,278],[278,294],[294,279],[271,272],[272,304],[304,271],[432,434],[434,427],[427,432],[272,407],[407,408],[408,272],[394,430],[430,431],[431,394],[395,369],[369,400],[400,395],[334,333],[333,299],[299,334],[351,417],[417,168],[168,351],[352,280],[280,411],[411,352],[325,319],[319,320],[320,325],[295,296],[296,336],[336,295],[319,403],[403,404],[404,319],[330,348],[348,349],[349,330],[293,298],[298,333],[333,293],[323,454],[454,447],[447,323],[15,16],[16,315],[315,15],[358,429],[429,279],[279,358],[14,15],[15,316],[316,14],[285,336],[336,9],[9,285],[329,349],[349,350],[350,329],[374,380],[380,252],[252,374],[318,402],[402,403],[403,318],[6,197],[197,419],[419,6],[318,319],[319,325],[325,318],[367,364],[364,365],[365,367],[435,367],[367,397],[397,435],[344,438],[438,439],[439,344],[272,271],[271,311],[311,272],[195,5],[5,281],[281,195],[273,287],[287,291],[291,273],[396,428],[428,199],[199,396],[311,271],[271,268],[268,311],[283,444],[444,445],[445,283],[373,254],[254,339],[339,373],[282,334],[334,296],[296,282],[449,347],[347,346],[346,449],[264,447],[447,454],[454,264],[336,296],[296,299],[299,336],[338,10],[10,151],[151,338],[278,439],[439,455],[455,278],[292,407],[407,415],[415,292],[358,371],[371,355],[355,358],[340,345],[345,372],[372,340],[346,347],[347,280],[280,346],[442,443],[443,282],[282,442],[19,94],[94,370],[370,19],[441,442],[442,295],[295,441],[248,419],[419,197],[197,248],[263,255],[255,359],[359,263],[440,275],[275,274],[274,440],[300,383],[383,368],[368,300],[351,412],[412,465],[465,351],[263,467],[467,466],[466,263],[301,368],[368,389],[389,301],[395,378],[378,379],[379,395],[412,351],[351,419],[419,412],[436,426],[426,322],[322,436],[2,164],[164,393],[393,2],[370,462],[462,461],[461,370],[164,0],[0,267],[267,164],[302,11],[11,12],[12,302],[268,12],[12,13],[13,268],[293,300],[300,301],[301,293],[446,261],[261,340],[340,446],[330,266],[266,425],[425,330],[426,423],[423,391],[391,426],[429,355],[355,437],[437,429],[391,327],[327,326],[326,391],[440,457],[457,438],[438,440],[341,382],[382,362],[362,341],[459,457],[457,461],[461,459],[434,430],[430,394],[394,434],[414,463],[463,362],[362,414],[396,369],[369,262],[262,396],[354,461],[461,457],[457,354],[316,403],[403,402],[402,316],[315,404],[404,403],[403,315],[314,405],[405,404],[404,314],[313,406],[406,405],[405,313],[421,418],[418,406],[406,421],[366,401],[401,361],[361,366],[306,408],[408,407],[407,306],[291,409],[409,408],[408,291],[287,410],[410,409],[409,287],[432,436],[436,410],[410,432],[434,416],[416,411],[411,434],[264,368],[368,383],[383,264],[309,438],[438,457],[457,309],[352,376],[376,401],[401,352],[274,275],[275,4],[4,274],[421,428],[428,262],[262,421],[294,327],[327,358],[358,294],[433,416],[416,367],[367,433],[289,455],[455,439],[439,289],[462,370],[370,326],[326,462],[2,326],[326,370],[370,2],[305,460],[460,455],[455,305],[254,449],[449,448],[448,254],[255,261],[261,446],[446,255],[253,450],[450,449],[449,253],[252,451],[451,450],[450,252],[256,452],[452,451],[451,256],[341,453],[453,452],[452,341],[413,464],[464,463],[463,413],[441,413],[413,414],[414,441],[258,442],[442,441],[441,258],[257,443],[443,442],[442,257],[259,444],[444,443],[443,259],[260,445],[445,444],[444,260],[467,342],[342,445],[445,467],[459,458],[458,250],[250,459],[289,392],[392,290],[290,289],[290,328],[328,460],[460,290],[376,433],[433,435],[435,376],[250,290],[290,392],[392,250],[411,416],[416,433],[433,411],[341,463],[463,464],[464,341],[453,464],[464,465],[465,453],[357,465],[465,412],[412,357],[343,412],[412,399],[399,343],[360,363],[363,440],[440,360],[437,399],[399,456],[456,437],[420,456],[456,363],[363,420],[401,435],[435,288],[288,401],[372,383],[383,353],[353,372],[339,255],[255,249],[249,339],[448,261],[261,255],[255,448],[133,243],[243,190],[190,133],[133,155],[155,112],[112,133],[33,246],[246,247],[247,33],[33,130],[130,25],[25,33],[398,384],[384,286],[286,398],[362,398],[398,414],[414,362],[362,463],[463,341],[341,362],[263,359],[359,467],[467,263],[263,249],[249,255],[255,263],[466,467],[467,260],[260,466],[75,60],[60,166],[166,75],[238,239],[239,79],[79,238],[162,127],[127,139],[139,162],[72,11],[11,37],[37,72],[121,232],[232,120],[120,121],[73,72],[72,39],[39,73],[114,128],[128,47],[47,114],[233,232],[232,128],[128,233],[103,104],[104,67],[67,103],[152,175],[175,148],[148,152],[119,118],[118,101],[101,119],[74,73],[73,40],[40,74],[107,9],[9,108],[108,107],[49,48],[48,131],[131,49],[32,194],[194,211],[211,32],[184,74],[74,185],[185,184],[191,80],[80,183],[183,191],[185,40],[40,186],[186,185],[119,230],[230,118],[118,119],[210,202],[202,214],[214,210],[84,83],[83,17],[17,84],[77,76],[76,146],[146,77],[161,160],[160,30],[30,161],[190,56],[56,173],[173,190],[182,106],[106,194],[194,182],[138,135],[135,192],[192,138],[129,203],[203,98],[98,129],[54,21],[21,68],[68,54],[5,51],[51,4],[4,5],[145,144],[144,23],[23,145],[90,77],[77,91],[91,90],[207,205],[205,187],[187,207],[83,201],[201,18],[18,83],[181,91],[91,182],[182,181],[180,90],[90,181],[181,180],[16,85],[85,17],[17,16],[205,206],[206,36],[36,205],[176,148],[148,140],[140,176],[165,92],[92,39],[39,165],[245,193],[193,244],[244,245],[27,159],[159,28],[28,27],[30,247],[247,161],[161,30],[174,236],[236,196],[196,174],[103,54],[54,104],[104,103],[55,193],[193,8],[8,55],[111,117],[117,31],[31,111],[221,189],[189,55],[55,221],[240,98],[98,99],[99,240],[142,126],[126,100],[100,142],[219,166],[166,218],[218,219],[112,155],[155,26],[26,112],[198,209],[209,131],[131,198],[169,135],[135,150],[150,169],[114,47],[47,217],[217,114],[224,223],[223,53],[53,224],[220,45],[45,134],[134,220],[32,211],[211,140],[140,32],[109,67],[67,108],[108,109],[146,43],[43,91],[91,146],[231,230],[230,120],[120,231],[113,226],[226,247],[247,113],[105,63],[63,52],[52,105],[241,238],[238,242],[242,241],[124,46],[46,156],[156,124],[95,78],[78,96],[96,95],[70,46],[46,63],[63,70],[116,143],[143,227],[227,116],[116,123],[123,111],[111,116],[1,44],[44,19],[19,1],[3,236],[236,51],[51,3],[207,216],[216,205],[205,207],[26,154],[154,22],[22,26],[165,39],[39,167],[167,165],[199,200],[200,208],[208,199],[101,36],[36,100],[100,101],[43,57],[57,202],[202,43],[242,20],[20,99],[99,242],[56,28],[28,157],[157,56],[124,35],[35,113],[113,124],[29,160],[160,27],[27,29],[211,204],[204,210],[210,211],[124,113],[113,46],[46,124],[106,43],[43,204],[204,106],[96,62],[62,77],[77,96],[227,137],[137,116],[116,227],[73,41],[41,72],[72,73],[36,203],[203,142],[142,36],[235,64],[64,240],[240,235],[48,49],[49,64],[64,48],[42,41],[41,74],[74,42],[214,212],[212,207],[207,214],[183,42],[42,184],[184,183],[210,169],[169,211],[211,210],[140,170],[170,176],[176,140],[104,105],[105,69],[69,104],[193,122],[122,168],[168,193],[50,123],[123,187],[187,50],[89,96],[96,90],[90,89],[66,65],[65,107],[107,66],[179,89],[89,180],[180,179],[119,101],[101,120],[120,119],[68,63],[63,104],[104,68],[234,93],[93,227],[227,234],[16,15],[15,85],[85,16],[209,129],[129,49],[49,209],[15,14],[14,86],[86,15],[107,55],[55,9],[9,107],[120,100],[100,121],[121,120],[153,145],[145,22],[22,153],[178,88],[88,179],[179,178],[197,6],[6,196],[196,197],[89,88],[88,96],[96,89],[135,138],[138,136],[136,135],[138,215],[215,172],[172,138],[218,115],[115,219],[219,218],[41,42],[42,81],[81,41],[5,195],[195,51],[51,5],[57,43],[43,61],[61,57],[208,171],[171,199],[199,208],[41,81],[81,38],[38,41],[224,53],[53,225],[225,224],[24,144],[144,110],[110,24],[105,52],[52,66],[66,105],[118,229],[229,117],[117,118],[227,34],[34,234],[234,227],[66,107],[107,69],[69,66],[10,109],[109,151],[151,10],[219,48],[48,235],[235,219],[183,62],[62,191],[191,183],[142,129],[129,126],[126,142],[116,111],[111,143],[143,116],[118,117],[117,50],[50,118],[223,222],[222,52],[52,223],[94,19],[19,141],[141,94],[222,221],[221,65],[65,222],[196,3],[3,197],[197,196],[45,220],[220,44],[44,45],[156,70],[70,139],[139,156],[188,122],[122,245],[245,188],[139,71],[71,162],[162,139],[149,170],[170,150],[150,149],[122,188],[188,196],[196,122],[206,216],[216,92],[92,206],[164,2],[2,167],[167,164],[242,141],[141,241],[241,242],[0,164],[164,37],[37,0],[11,72],[72,12],[12,11],[12,38],[38,13],[13,12],[70,63],[63,71],[71,70],[31,226],[226,111],[111,31],[36,101],[101,205],[205,36],[203,206],[206,165],[165,203],[126,209],[209,217],[217,126],[98,165],[165,97],[97,98],[237,220],[220,218],[218,237],[237,239],[239,241],[241,237],[210,214],[214,169],[169,210],[140,171],[171,32],[32,140],[241,125],[125,237],[237,241],[179,86],[86,178],[178,179],[180,85],[85,179],[179,180],[181,84],[84,180],[180,181],[182,83],[83,181],[181,182],[194,201],[201,182],[182,194],[177,137],[137,132],[132,177],[184,76],[76,183],[183,184],[185,61],[61,184],[184,185],[186,57],[57,185],[185,186],[216,212],[212,186],[186,216],[192,214],[214,187],[187,192],[139,34],[34,156],[156,139],[218,79],[79,237],[237,218],[147,123],[123,177],[177,147],[45,44],[44,4],[4,45],[208,201],[201,32],[32,208],[98,64],[64,129],[129,98],[192,213],[213,138],[138,192],[235,59],[59,219],[219,235],[141,242],[242,97],[97,141],[97,2],[2,141],[141,97],[240,75],[75,235],[235,240],[229,24],[24,228],[228,229],[31,25],[25,226],[226,31],[230,23],[23,229],[229,230],[231,22],[22,230],[230,231],[232,26],[26,231],[231,232],[233,112],[112,232],[232,233],[244,189],[189,243],[243,244],[189,221],[221,190],[190,189],[222,28],[28,221],[221,222],[223,27],[27,222],[222,223],[224,29],[29,223],[223,224],[225,30],[30,224],[224,225],[113,247],[247,225],[225,113],[99,60],[60,240],[240,99],[213,147],[147,215],[215,213],[60,20],[20,166],[166,60],[192,187],[187,213],[213,192],[243,112],[112,244],[244,243],[244,233],[233,245],[245,244],[245,128],[128,188],[188,245],[188,114],[114,174],[174,188],[134,131],[131,220],[220,134],[174,217],[217,236],[236,174],[236,198],[198,134],[134,236],[215,177],[177,58],[58,215],[156,143],[143,124],[124,156],[25,110],[110,7],[7,25],[31,228],[228,25],[25,31],[264,356],[356,368],[368,264],[0,11],[11,267],[267,0],[451,452],[452,349],[349,451],[267,302],[302,269],[269,267],[350,357],[357,277],[277,350],[350,452],[452,357],[357,350],[299,333],[333,297],[297,299],[396,175],[175,377],[377,396],[280,347],[347,330],[330,280],[269,303],[303,270],[270,269],[151,9],[9,337],[337,151],[344,278],[278,360],[360,344],[424,418],[418,431],[431,424],[270,304],[304,409],[409,270],[272,310],[310,407],[407,272],[322,270],[270,410],[410,322],[449,450],[450,347],[347,449],[432,422],[422,434],[434,432],[18,313],[313,17],[17,18],[291,306],[306,375],[375,291],[259,387],[387,260],[260,259],[424,335],[335,418],[418,424],[434,364],[364,416],[416,434],[391,423],[423,327],[327,391],[301,251],[251,298],[298,301],[275,281],[281,4],[4,275],[254,373],[373,253],[253,254],[375,307],[307,321],[321,375],[280,425],[425,411],[411,280],[200,421],[421,18],[18,200],[335,321],[321,406],[406,335],[321,320],[320,405],[405,321],[314,315],[315,17],[17,314],[423,426],[426,266],[266,423],[396,377],[377,369],[369,396],[270,322],[322,269],[269,270],[413,417],[417,464],[464,413],[385,386],[386,258],[258,385],[248,456],[456,419],[419,248],[298,284],[284,333],[333,298],[168,417],[417,8],[8,168],[448,346],[346,261],[261,448],[417,413],[413,285],[285,417],[326,327],[327,328],[328,326],[277,355],[355,329],[329,277],[309,392],[392,438],[438,309],[381,382],[382,256],[256,381],[279,429],[429,360],[360,279],[365,364],[364,379],[379,365],[355,277],[277,437],[437,355],[282,443],[443,283],[283,282],[281,275],[275,363],[363,281],[395,431],[431,369],[369,395],[299,297],[297,337],[337,299],[335,273],[273,321],[321,335],[348,450],[450,349],[349,348],[359,446],[446,467],[467,359],[283,293],[293,282],[282,283],[250,458],[458,462],[462,250],[300,276],[276,383],[383,300],[292,308],[308,325],[325,292],[283,276],[276,293],[293,283],[264,372],[372,447],[447,264],[346,352],[352,340],[340,346],[354,274],[274,19],[19,354],[363,456],[456,281],[281,363],[426,436],[436,425],[425,426],[380,381],[381,252],[252,380],[267,269],[269,393],[393,267],[421,200],[200,428],[428,421],[371,266],[266,329],[329,371],[432,287],[287,422],[422,432],[290,250],[250,328],[328,290],[385,258],[258,384],[384,385],[446,265],[265,342],[342,446],[386,387],[387,257],[257,386],[422,424],[424,430],[430,422],[445,342],[342,276],[276,445],[422,273],[273,424],[424,422],[306,292],[292,307],[307,306],[352,366],[366,345],[345,352],[268,271],[271,302],[302,268],[358,423],[423,371],[371,358],[327,294],[294,460],[460,327],[331,279],[279,294],[294,331],[303,271],[271,304],[304,303],[436,432],[432,427],[427,436],[304,272],[272,408],[408,304],[395,394],[394,431],[431,395],[378,395],[395,400],[400,378],[296,334],[334,299],[299,296],[6,351],[351,168],[168,6],[376,352],[352,411],[411,376],[307,325],[325,320],[320,307],[285,295],[295,336],[336,285],[320,319],[319,404],[404,320],[329,330],[330,349],[349,329],[334,293],[293,333],[333,334],[366,323],[323,447],[447,366],[316,15],[15,315],[315,316],[331,358],[358,279],[279,331],[317,14],[14,316],[316,317],[8,285],[285,9],[9,8],[277,329],[329,350],[350,277],[253,374],[374,252],[252,253],[319,318],[318,403],[403,319],[351,6],[6,419],[419,351],[324,318],[318,325],[325,324],[397,367],[367,365],[365,397],[288,435],[435,397],[397,288],[278,344],[344,439],[439,278],[310,272],[272,311],[311,310],[248,195],[195,281],[281,248],[375,273],[273,291],[291,375],[175,396],[396,199],[199,175],[312,311],[311,268],[268,312],[276,283],[283,445],[445,276],[390,373],[373,339],[339,390],[295,282],[282,296],[296,295],[448,449],[449,346],[346,448],[356,264],[264,454],[454,356],[337,336],[336,299],[299,337],[337,338],[338,151],[151,337],[294,278],[278,455],[455,294],[308,292],[292,415],[415,308],[429,358],[358,355],[355,429],[265,340],[340,372],[372,265],[352,346],[346,280],[280,352],[295,442],[442,282],[282,295],[354,19],[19,370],[370,354],[285,441],[441,295],[295,285],[195,248],[248,197],[197,195],[457,440],[440,274],[274,457],[301,300],[300,368],[368,301],[417,351],[351,465],[465,417],[251,301],[301,389],[389,251],[394,395],[395,379],[379,394],[399,412],[412,419],[419,399],[410,436],[436,322],[322,410],[326,2],[2,393],[393,326],[354,370],[370,461],[461,354],[393,164],[164,267],[267,393],[268,302],[302,12],[12,268],[312,268],[268,13],[13,312],[298,293],[293,301],[301,298],[265,446],[446,340],[340,265],[280,330],[330,425],[425,280],[322,426],[426,391],[391,322],[420,429],[429,437],[437,420],[393,391],[391,326],[326,393],[344,440],[440,438],[438,344],[458,459],[459,461],[461,458],[364,434],[434,394],[394,364],[428,396],[396,262],[262,428],[274,354],[354,457],[457,274],[317,316],[316,402],[402,317],[316,315],[315,403],[403,316],[315,314],[314,404],[404,315],[314,313],[313,405],[405,314],[313,421],[421,406],[406,313],[323,366],[366,361],[361,323],[292,306],[306,407],[407,292],[306,291],[291,408],[408,306],[291,287],[287,409],[409,291],[287,432],[432,410],[410,287],[427,434],[434,411],[411,427],[372,264],[264,383],[383,372],[459,309],[309,457],[457,459],[366,352],[352,401],[401,366],[1,274],[274,4],[4,1],[418,421],[421,262],[262,418],[331,294],[294,358],[358,331],[435,433],[433,367],[367,435],[392,289],[289,439],[439,392],[328,462],[462,326],[326,328],[94,2],[2,370],[370,94],[289,305],[305,455],[455,289],[339,254],[254,448],[448,339],[359,255],[255,446],[446,359],[254,253],[253,449],[449,254],[253,252],[252,450],[450,253],[252,256],[256,451],[451,252],[256,341],[341,452],[452,256],[414,413],[413,463],[463,414],[286,441],[441,414],[414,286],[286,258],[258,441],[441,286],[258,257],[257,442],[442,258],[257,259],[259,443],[443,257],[259,260],[260,444],[444,259],[260,467],[467,445],[445,260],[309,459],[459,250],[250,309],[305,289],[289,290],[290,305],[305,290],[290,460],[460,305],[401,376],[376,435],[435,401],[309,250],[250,392],[392,309],[376,411],[411,433],[433,376],[453,341],[341,464],[464,453],[357,453],[453,465],[465,357],[343,357],[357,412],[412,343],[437,343],[343,399],[399,437],[344,360],[360,440],[440,344],[420,437],[437,456],[456,420],[360,420],[420,363],[363,360],[361,401],[401,288],[288,361],[265,372],[372,353],[353,265],[390,339],[339,249],[249,390],[339,448],[448,255],[255,339]);function ol(t){t.j={faceLandmarks:[],faceBlendshapes:[],facialTransformationMatrixes:[]}}var we=class extends ot{constructor(t,e){super(new Ct(t,e),"image_in","norm_rect",!1),this.j={faceLandmarks:[],faceBlendshapes:[],facialTransformationMatrixes:[]},this.outputFacialTransformationMatrixes=this.outputFaceBlendshapes=!1,z(t=this.h=new Of,0,1,e=new ye),this.v=new Lf,z(this.h,0,3,this.v),this.s=new yo,z(this.h,0,2,this.s),rr(this.s,4,1),W(this.s,2,.5),W(this.v,2,.5),W(this.h,4,.5)}get baseOptions(){return q(this.h,ye,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){return"numFaces"in t&&rr(this.s,4,t.numFaces??1),"minFaceDetectionConfidence"in t&&W(this.s,2,t.minFaceDetectionConfidence??.5),"minTrackingConfidence"in t&&W(this.h,4,t.minTrackingConfidence??.5),"minFacePresenceConfidence"in t&&W(this.v,2,t.minFacePresenceConfidence??.5),"outputFaceBlendshapes"in t&&(this.outputFaceBlendshapes=!!t.outputFaceBlendshapes),"outputFacialTransformationMatrixes"in t&&(this.outputFacialTransformationMatrixes=!!t.outputFacialTransformationMatrixes),this.l(t)}D(t,e){return ol(this),Bt(this,t,e),this.j}F(t,e,r){return ol(this),nr(this,t,r,e),this.j}m(){var t=new at;pe(t,"image_in"),pe(t,"norm_rect"),J(t,"face_landmarks");let e=new mt;Wt(e,am,this.h);let r=new et;yt(r,"mediapipe.tasks.vision.face_landmarker.FaceLandmarkerGraph"),ce(r,"IMAGE:image_in"),ce(r,"NORM_RECT:norm_rect"),Y(r,"NORM_LANDMARKS:face_landmarks"),r.o(e),xt(t,r),this.g.attachProtoVectorListener("face_landmarks",((n,s)=>{for(let o of n)n=os(o),this.j.faceLandmarks.push(xo(n));G(this,s)})),this.g.attachEmptyPacketListener("face_landmarks",(n=>{G(this,n)})),this.outputFaceBlendshapes&&(J(t,"blendshapes"),Y(r,"BLENDSHAPES:blendshapes"),this.g.attachProtoVectorListener("blendshapes",((n,s)=>{if(this.outputFaceBlendshapes)for(let o of n)n=go(o),this.j.faceBlendshapes.push(Wi(n.g()??[]));G(this,s)})),this.g.attachEmptyPacketListener("blendshapes",(n=>{G(this,n)}))),this.outputFacialTransformationMatrixes&&(J(t,"face_geometry"),Y(r,"FACE_GEOMETRY:face_geometry"),this.g.attachProtoVectorListener("face_geometry",((n,s)=>{if(this.outputFacialTransformationMatrixes)for(let o of n)(n=q(om(o),Kp,2))&&this.j.facialTransformationMatrixes.push({rows:Gt(It(n,1),0)??0,columns:Gt(It(n,2),0)??0,data:Vr(n,3,Br,Gr()).slice()??[]});G(this,s)})),this.g.attachEmptyPacketListener("face_geometry",(n=>{G(this,n)}))),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};we.prototype.detectForVideo=we.prototype.F,we.prototype.detect=we.prototype.D,we.prototype.setOptions=we.prototype.o,we.createFromModelPath=function(t,e){return X(we,t,{baseOptions:{modelAssetPath:e}})},we.createFromModelBuffer=function(t,e){return X(we,t,{baseOptions:{modelAssetBuffer:e}})},we.createFromOptions=function(t,e){return X(we,t,e)},we.FACE_LANDMARKS_LIPS=ji,we.FACE_LANDMARKS_LEFT_EYE=Xi,we.FACE_LANDMARKS_LEFT_EYEBROW=Yi,we.FACE_LANDMARKS_LEFT_IRIS=cd,we.FACE_LANDMARKS_RIGHT_EYE=qi,we.FACE_LANDMARKS_RIGHT_EYEBROW=Ki,we.FACE_LANDMARKS_RIGHT_IRIS=ld,we.FACE_LANDMARKS_FACE_OVAL=Zi,we.FACE_LANDMARKS_CONTOURS=fd,we.FACE_LANDMARKS_TESSELATION=dd;var Jt=class extends ot{constructor(t,e){super(new Ct(t,e),"image_in","norm_rect",!0),z(t=this.j=new Mf,0,1,e=new ye)}get baseOptions(){return q(this.j,ye,1)}set baseOptions(t){z(this.j,0,1,t)}o(t){return super.l(t)}Oa(t,e,r){let n=typeof e!="function"?e:{};if(this.h=typeof e=="function"?e:r,Bt(this,t,n??{}),!this.h)return this.s}m(){var t=new at;pe(t,"image_in"),pe(t,"norm_rect"),J(t,"stylized_image");let e=new mt;Wt(e,im,this.j);let r=new et;yt(r,"mediapipe.tasks.vision.face_stylizer.FaceStylizerGraph"),ce(r,"IMAGE:image_in"),ce(r,"NORM_RECT:norm_rect"),Y(r,"STYLIZED_IMAGE:stylized_image"),r.o(e),xt(t,r),this.g.V("stylized_image",((n,s)=>{var o=!this.h,a=n.data,i=n.width;let u=i*(n=n.height);if(a instanceof Uint8Array)if(a.length===3*u){let l=new Uint8ClampedArray(4*u);for(let c=0;c<u;++c)l[4*c]=a[3*c],l[4*c+1]=a[3*c+1],l[4*c+2]=a[3*c+2],l[4*c+3]=255;a=new ImageData(l,i,n)}else{if(a.length!==4*u)throw Error("Unsupported channel count: "+a.length/u);a=new ImageData(new Uint8ClampedArray(a.buffer,a.byteOffset,a.length),i,n)}else if(!(a instanceof WebGLTexture))throw Error(`Unsupported format: ${a.constructor.name}`);i=new Ve([a],!1,!1,this.g.i.canvas,this.P,i,n),this.s=o=o?i.clone():i,this.h&&this.h(o),G(this,s)})),this.g.attachEmptyPacketListener("stylized_image",(n=>{this.s=null,this.h&&this.h(null),G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};Jt.prototype.stylize=Jt.prototype.Oa,Jt.prototype.setOptions=Jt.prototype.o,Jt.createFromModelPath=function(t,e){return X(Jt,t,{baseOptions:{modelAssetPath:e}})},Jt.createFromModelBuffer=function(t,e){return X(Jt,t,{baseOptions:{modelAssetBuffer:e}})},Jt.createFromOptions=function(t,e){return X(Jt,t,e)};var Ji=Ht([0,1],[1,2],[2,3],[3,4],[0,5],[5,6],[6,7],[7,8],[5,9],[9,10],[10,11],[11,12],[9,13],[13,14],[14,15],[15,16],[13,17],[0,17],[17,18],[18,19],[19,20]);function al(t){t.gestures=[],t.landmarks=[],t.worldLandmarks=[],t.handedness=[]}function il(t){return t.gestures.length===0?{gestures:[],landmarks:[],worldLandmarks:[],handedness:[],handednesses:[]}:{gestures:t.gestures,landmarks:t.landmarks,worldLandmarks:t.worldLandmarks,handedness:t.handedness,handednesses:t.handedness}}function ul(t,e=!0){let r=[];for(let s of t){var n=go(s);t=[];for(let o of n.g())n=e&&It(o,1)!=null?Gt(It(o,1),0):-1,t.push({score:Ce(o,2)??0,index:n,categoryName:tr(o,3)??"",displayName:tr(o,4)??""});r.push(t)}return r}var lt=class extends ot{constructor(t,e){super(new Ct(t,e),"image_in","norm_rect",!1),this.gestures=[],this.landmarks=[],this.worldLandmarks=[],this.handedness=[],z(t=this.j=new Vf,0,1,e=new ye),this.s=new Mi,z(this.j,0,2,this.s),this.C=new Di,z(this.s,0,3,this.C),this.v=new Gf,z(this.s,0,2,this.v),this.h=new um,z(this.j,0,3,this.h),W(this.v,2,.5),W(this.s,4,.5),W(this.C,2,.5)}get baseOptions(){return q(this.j,ye,1)}set baseOptions(t){z(this.j,0,1,t)}o(t){if(rr(this.v,3,t.numHands??1),"minHandDetectionConfidence"in t&&W(this.v,2,t.minHandDetectionConfidence??.5),"minTrackingConfidence"in t&&W(this.s,4,t.minTrackingConfidence??.5),"minHandPresenceConfidence"in t&&W(this.C,2,t.minHandPresenceConfidence??.5),t.cannedGesturesClassifierOptions){var e=new rn,r=e,n=Wa(t.cannedGesturesClassifierOptions,q(this.h,rn,3)?.h());z(r,0,2,n),z(this.h,0,3,e)}else t.cannedGesturesClassifierOptions===void 0&&q(this.h,rn,3)?.g();return t.customGesturesClassifierOptions?(z(r=e=new rn,0,2,n=Wa(t.customGesturesClassifierOptions,q(this.h,rn,4)?.h())),z(this.h,0,4,e)):t.customGesturesClassifierOptions===void 0&&q(this.h,rn,4)?.g(),this.l(t)}Ja(t,e){return al(this),Bt(this,t,e),il(this)}Ka(t,e,r){return al(this),nr(this,t,r,e),il(this)}m(){var t=new at;pe(t,"image_in"),pe(t,"norm_rect"),J(t,"hand_gestures"),J(t,"hand_landmarks"),J(t,"world_hand_landmarks"),J(t,"handedness");let e=new mt;Wt(e,cm,this.j);let r=new et;yt(r,"mediapipe.tasks.vision.gesture_recognizer.GestureRecognizerGraph"),ce(r,"IMAGE:image_in"),ce(r,"NORM_RECT:norm_rect"),Y(r,"HAND_GESTURES:hand_gestures"),Y(r,"LANDMARKS:hand_landmarks"),Y(r,"WORLD_LANDMARKS:world_hand_landmarks"),Y(r,"HANDEDNESS:handedness"),r.o(e),xt(t,r),this.g.attachProtoVectorListener("hand_landmarks",((n,s)=>{for(let o of n){n=os(o);let a=[];for(let i of dr(n,Cf,1))a.push({x:Ce(i,1)??0,y:Ce(i,2)??0,z:Ce(i,3)??0,visibility:Ce(i,4)??0});this.landmarks.push(a)}G(this,s)})),this.g.attachEmptyPacketListener("hand_landmarks",(n=>{G(this,n)})),this.g.attachProtoVectorListener("world_hand_landmarks",((n,s)=>{for(let o of n){n=un(o);let a=[];for(let i of dr(n,Sf,1))a.push({x:Ce(i,1)??0,y:Ce(i,2)??0,z:Ce(i,3)??0,visibility:Ce(i,4)??0});this.worldLandmarks.push(a)}G(this,s)})),this.g.attachEmptyPacketListener("world_hand_landmarks",(n=>{G(this,n)})),this.g.attachProtoVectorListener("hand_gestures",((n,s)=>{this.gestures.push(...ul(n,!1)),G(this,s)})),this.g.attachEmptyPacketListener("hand_gestures",(n=>{G(this,n)})),this.g.attachProtoVectorListener("handedness",((n,s)=>{this.handedness.push(...ul(n)),G(this,s)})),this.g.attachEmptyPacketListener("handedness",(n=>{G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};function cl(t){return{landmarks:t.landmarks,worldLandmarks:t.worldLandmarks,handednesses:t.handedness,handedness:t.handedness}}lt.prototype.recognizeForVideo=lt.prototype.Ka,lt.prototype.recognize=lt.prototype.Ja,lt.prototype.setOptions=lt.prototype.o,lt.createFromModelPath=function(t,e){return X(lt,t,{baseOptions:{modelAssetPath:e}})},lt.createFromModelBuffer=function(t,e){return X(lt,t,{baseOptions:{modelAssetBuffer:e}})},lt.createFromOptions=function(t,e){return X(lt,t,e)},lt.HAND_CONNECTIONS=Ji;var ft=class extends ot{constructor(t,e){super(new Ct(t,e),"image_in","norm_rect",!1),this.landmarks=[],this.worldLandmarks=[],this.handedness=[],z(t=this.h=new Mi,0,1,e=new ye),this.s=new Di,z(this.h,0,3,this.s),this.j=new Gf,z(this.h,0,2,this.j),rr(this.j,3,1),W(this.j,2,.5),W(this.s,2,.5),W(this.h,4,.5)}get baseOptions(){return q(this.h,ye,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){return"numHands"in t&&rr(this.j,3,t.numHands??1),"minHandDetectionConfidence"in t&&W(this.j,2,t.minHandDetectionConfidence??.5),"minTrackingConfidence"in t&&W(this.h,4,t.minTrackingConfidence??.5),"minHandPresenceConfidence"in t&&W(this.s,2,t.minHandPresenceConfidence??.5),this.l(t)}D(t,e){return this.landmarks=[],this.worldLandmarks=[],this.handedness=[],Bt(this,t,e),cl(this)}F(t,e,r){return this.landmarks=[],this.worldLandmarks=[],this.handedness=[],nr(this,t,r,e),cl(this)}m(){var t=new at;pe(t,"image_in"),pe(t,"norm_rect"),J(t,"hand_landmarks"),J(t,"world_hand_landmarks"),J(t,"handedness");let e=new mt;Wt(e,lm,this.h);let r=new et;yt(r,"mediapipe.tasks.vision.hand_landmarker.HandLandmarkerGraph"),ce(r,"IMAGE:image_in"),ce(r,"NORM_RECT:norm_rect"),Y(r,"LANDMARKS:hand_landmarks"),Y(r,"WORLD_LANDMARKS:world_hand_landmarks"),Y(r,"HANDEDNESS:handedness"),r.o(e),xt(t,r),this.g.attachProtoVectorListener("hand_landmarks",((n,s)=>{for(let o of n)n=os(o),this.landmarks.push(xo(n));G(this,s)})),this.g.attachEmptyPacketListener("hand_landmarks",(n=>{G(this,n)})),this.g.attachProtoVectorListener("world_hand_landmarks",((n,s)=>{for(let o of n)n=un(o),this.worldLandmarks.push(qn(n));G(this,s)})),this.g.attachEmptyPacketListener("world_hand_landmarks",(n=>{G(this,n)})),this.g.attachProtoVectorListener("handedness",((n,s)=>{var o=this.handedness,a=o.push;let i=[];for(let u of n){n=go(u);let l=[];for(let c of n.g())l.push({score:Ce(c,2)??0,index:Gt(It(c,1),0)??-1,categoryName:tr(c,3)??"",displayName:tr(c,4)??""});i.push(l)}a.call(o,...i),G(this,s)})),this.g.attachEmptyPacketListener("handedness",(n=>{G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};ft.prototype.detectForVideo=ft.prototype.F,ft.prototype.detect=ft.prototype.D,ft.prototype.setOptions=ft.prototype.o,ft.createFromModelPath=function(t,e){return X(ft,t,{baseOptions:{modelAssetPath:e}})},ft.createFromModelBuffer=function(t,e){return X(ft,t,{baseOptions:{modelAssetBuffer:e}})},ft.createFromOptions=function(t,e){return X(ft,t,e)},ft.HAND_CONNECTIONS=Ji;var hd=Ht([0,1],[1,2],[2,3],[3,7],[0,4],[4,5],[5,6],[6,8],[9,10],[11,12],[11,13],[13,15],[15,17],[15,19],[15,21],[17,19],[12,14],[14,16],[16,18],[16,20],[16,22],[18,20],[11,23],[12,24],[23,24],[23,25],[24,26],[25,27],[26,28],[27,29],[28,30],[29,31],[30,32],[27,31],[28,32]);function ll(t){t.h={faceLandmarks:[],faceBlendshapes:[],poseLandmarks:[],poseWorldLandmarks:[],poseSegmentationMasks:[],leftHandLandmarks:[],leftHandWorldLandmarks:[],rightHandLandmarks:[],rightHandWorldLandmarks:[]}}function fl(t){try{if(!t.C)return t.h;t.C(t.h)}finally{bo(t)}}function Fs(t,e){t=os(t),e.push(xo(t))}var ge=class extends ot{constructor(t,e){super(new Ct(t,e),"input_frames_image",null,!1),this.h={faceLandmarks:[],faceBlendshapes:[],poseLandmarks:[],poseWorldLandmarks:[],poseSegmentationMasks:[],leftHandLandmarks:[],leftHandWorldLandmarks:[],rightHandLandmarks:[],rightHandWorldLandmarks:[]},this.outputPoseSegmentationMasks=this.outputFaceBlendshapes=!1,z(t=this.j=new jf,0,1,e=new ye),this.K=new Di,z(this.j,0,2,this.K),this.aa=new fm,z(this.j,0,3,this.aa),this.s=new yo,z(this.j,0,4,this.s),this.I=new Lf,z(this.j,0,5,this.I),this.v=new zf,z(this.j,0,6,this.v),this.L=new Hf,z(this.j,0,7,this.L),W(this.s,2,.5),W(this.s,3,.3),W(this.I,2,.5),W(this.v,2,.5),W(this.v,3,.3),W(this.L,2,.5),W(this.K,2,.5)}get baseOptions(){return q(this.j,ye,1)}set baseOptions(t){z(this.j,0,1,t)}o(t){return"minFaceDetectionConfidence"in t&&W(this.s,2,t.minFaceDetectionConfidence??.5),"minFaceSuppressionThreshold"in t&&W(this.s,3,t.minFaceSuppressionThreshold??.3),"minFacePresenceConfidence"in t&&W(this.I,2,t.minFacePresenceConfidence??.5),"outputFaceBlendshapes"in t&&(this.outputFaceBlendshapes=!!t.outputFaceBlendshapes),"minPoseDetectionConfidence"in t&&W(this.v,2,t.minPoseDetectionConfidence??.5),"minPoseSuppressionThreshold"in t&&W(this.v,3,t.minPoseSuppressionThreshold??.3),"minPosePresenceConfidence"in t&&W(this.L,2,t.minPosePresenceConfidence??.5),"outputPoseSegmentationMasks"in t&&(this.outputPoseSegmentationMasks=!!t.outputPoseSegmentationMasks),"minHandLandmarksConfidence"in t&&W(this.K,2,t.minHandLandmarksConfidence??.5),this.l(t)}D(t,e,r){let n=typeof e!="function"?e:{};return this.C=typeof e=="function"?e:r,ll(this),Bt(this,t,n),fl(this)}F(t,e,r,n){let s=typeof r!="function"?r:{};return this.C=typeof r=="function"?r:n,ll(this),nr(this,t,s,e),fl(this)}m(){var t=new at;pe(t,"input_frames_image"),J(t,"pose_landmarks"),J(t,"pose_world_landmarks"),J(t,"face_landmarks"),J(t,"left_hand_landmarks"),J(t,"left_hand_world_landmarks"),J(t,"right_hand_landmarks"),J(t,"right_hand_world_landmarks");let e=new mt,r=new Cc;La(r,1,bn("type.googleapis.com/mediapipe.tasks.vision.holistic_landmarker.proto.HolisticLandmarkerGraphOptions"),""),(function(s,o){if(o!=null)if(Array.isArray(o))ue(s,2,no(o,fi,void 0,void 0,!1));else{if(!(typeof o=="string"||o instanceof lr||ts(o)))throw Error("invalid value in Any.value field: "+o+" expected a ByteString, a base64 encoded string, a Uint8Array or a jspb array");La(s,2,ri(o,!1),zr())}})(r,this.j.g());let n=new et;yt(n,"mediapipe.tasks.vision.holistic_landmarker.HolisticLandmarkerGraph"),Hs(n,8,Cc,r),ce(n,"IMAGE:input_frames_image"),Y(n,"POSE_LANDMARKS:pose_landmarks"),Y(n,"POSE_WORLD_LANDMARKS:pose_world_landmarks"),Y(n,"FACE_LANDMARKS:face_landmarks"),Y(n,"LEFT_HAND_LANDMARKS:left_hand_landmarks"),Y(n,"LEFT_HAND_WORLD_LANDMARKS:left_hand_world_landmarks"),Y(n,"RIGHT_HAND_LANDMARKS:right_hand_landmarks"),Y(n,"RIGHT_HAND_WORLD_LANDMARKS:right_hand_world_landmarks"),n.o(e),xt(t,n),_o(this,t),this.g.attachProtoListener("pose_landmarks",((s,o)=>{Fs(s,this.h.poseLandmarks),G(this,o)})),this.g.attachEmptyPacketListener("pose_landmarks",(s=>{G(this,s)})),this.g.attachProtoListener("pose_world_landmarks",((s,o)=>{var a=this.h.poseWorldLandmarks;s=un(s),a.push(qn(s)),G(this,o)})),this.g.attachEmptyPacketListener("pose_world_landmarks",(s=>{G(this,s)})),this.outputPoseSegmentationMasks&&(Y(n,"POSE_SEGMENTATION_MASK:pose_segmentation_mask"),hn(this,"pose_segmentation_mask"),this.g.V("pose_segmentation_mask",((s,o)=>{this.h.poseSegmentationMasks=[gn(this,s,!0,!this.C)],G(this,o)})),this.g.attachEmptyPacketListener("pose_segmentation_mask",(s=>{this.h.poseSegmentationMasks=[],G(this,s)}))),this.g.attachProtoListener("face_landmarks",((s,o)=>{Fs(s,this.h.faceLandmarks),G(this,o)})),this.g.attachEmptyPacketListener("face_landmarks",(s=>{G(this,s)})),this.outputFaceBlendshapes&&(J(t,"extra_blendshapes"),Y(n,"FACE_BLENDSHAPES:extra_blendshapes"),this.g.attachProtoListener("extra_blendshapes",((s,o)=>{var a=this.h.faceBlendshapes;this.outputFaceBlendshapes&&(s=go(s),a.push(Wi(s.g()??[]))),G(this,o)})),this.g.attachEmptyPacketListener("extra_blendshapes",(s=>{G(this,s)}))),this.g.attachProtoListener("left_hand_landmarks",((s,o)=>{Fs(s,this.h.leftHandLandmarks),G(this,o)})),this.g.attachEmptyPacketListener("left_hand_landmarks",(s=>{G(this,s)})),this.g.attachProtoListener("left_hand_world_landmarks",((s,o)=>{var a=this.h.leftHandWorldLandmarks;s=un(s),a.push(qn(s)),G(this,o)})),this.g.attachEmptyPacketListener("left_hand_world_landmarks",(s=>{G(this,s)})),this.g.attachProtoListener("right_hand_landmarks",((s,o)=>{Fs(s,this.h.rightHandLandmarks),G(this,o)})),this.g.attachEmptyPacketListener("right_hand_landmarks",(s=>{G(this,s)})),this.g.attachProtoListener("right_hand_world_landmarks",((s,o)=>{var a=this.h.rightHandWorldLandmarks;s=un(s),a.push(qn(s)),G(this,o)})),this.g.attachEmptyPacketListener("right_hand_world_landmarks",(s=>{G(this,s)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};ge.prototype.detectForVideo=ge.prototype.F,ge.prototype.detect=ge.prototype.D,ge.prototype.setOptions=ge.prototype.o,ge.createFromModelPath=function(t,e){return X(ge,t,{baseOptions:{modelAssetPath:e}})},ge.createFromModelBuffer=function(t,e){return X(ge,t,{baseOptions:{modelAssetBuffer:e}})},ge.createFromOptions=function(t,e){return X(ge,t,e)},ge.HAND_CONNECTIONS=Ji,ge.POSE_CONNECTIONS=hd,ge.FACE_LANDMARKS_LIPS=ji,ge.FACE_LANDMARKS_LEFT_EYE=Xi,ge.FACE_LANDMARKS_LEFT_EYEBROW=Yi,ge.FACE_LANDMARKS_LEFT_IRIS=cd,ge.FACE_LANDMARKS_RIGHT_EYE=qi,ge.FACE_LANDMARKS_RIGHT_EYEBROW=Ki,ge.FACE_LANDMARKS_RIGHT_IRIS=ld,ge.FACE_LANDMARKS_FACE_OVAL=Zi,ge.FACE_LANDMARKS_CONTOURS=fd,ge.FACE_LANDMARKS_TESSELATION=dd;var Et=class extends ot{constructor(t,e){super(new Ct(t,e),"input_image","norm_rect",!0),this.j={classifications:[]},z(t=this.h=new Xf,0,1,e=new ye)}get baseOptions(){return q(this.h,ye,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){return z(this.h,0,2,Wa(t,q(this.h,Pi,2))),this.l(t)}ta(t,e){return this.j={classifications:[]},Bt(this,t,e),this.j}ua(t,e,r){return this.j={classifications:[]},nr(this,t,r,e),this.j}m(){var t=new at;pe(t,"input_image"),pe(t,"norm_rect"),J(t,"classifications");let e=new mt;Wt(e,dm,this.h);let r=new et;yt(r,"mediapipe.tasks.vision.image_classifier.ImageClassifierGraph"),ce(r,"IMAGE:input_image"),ce(r,"NORM_RECT:norm_rect"),Y(r,"CLASSIFICATIONS:classifications"),r.o(e),xt(t,r),this.g.attachProtoListener("classifications",((n,s)=>{this.j=(function(o){let a={classifications:dr(o,Jp,1).map((i=>Wi(q(i,Af,4)?.g()??[],Gt(It(i,2),0),tr(i,3))))};return $s(Ar(o,2))!=null&&(a.timestampMs=Gt($s(Ar(o,2)),0)),a})(Qp(n)),G(this,s)})),this.g.attachEmptyPacketListener("classifications",(n=>{G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};Et.prototype.classifyForVideo=Et.prototype.ua,Et.prototype.classify=Et.prototype.ta,Et.prototype.setOptions=Et.prototype.o,Et.createFromModelPath=function(t,e){return X(Et,t,{baseOptions:{modelAssetPath:e}})},Et.createFromModelBuffer=function(t,e){return X(Et,t,{baseOptions:{modelAssetBuffer:e}})},Et.createFromOptions=function(t,e){return X(Et,t,e)};var dt=class extends ot{constructor(t,e){super(new Ct(t,e),"image_in","norm_rect",!0),this.h=new Yf,this.embeddings={embeddings:[]},z(t=this.h,0,1,e=new ye)}get baseOptions(){return q(this.h,ye,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){var e=this.h,r=q(this.h,Nc,2);return r=r?r.clone():new Nc,t.l2Normalize!==void 0?Jn(r,1,t.l2Normalize):"l2Normalize"in t&&ue(r,1),t.quantize!==void 0?Jn(r,2,t.quantize):"quantize"in t&&ue(r,2),z(e,0,2,r),this.l(t)}Aa(t,e){return Bt(this,t,e),this.embeddings}Ba(t,e,r){return nr(this,t,r,e),this.embeddings}m(){var t=new at;pe(t,"image_in"),pe(t,"norm_rect"),J(t,"embeddings_out");let e=new mt;Wt(e,hm,this.h);let r=new et;yt(r,"mediapipe.tasks.vision.image_embedder.ImageEmbedderGraph"),ce(r,"IMAGE:image_in"),ce(r,"NORM_RECT:norm_rect"),Y(r,"EMBEDDINGS:embeddings_out"),r.o(e),xt(t,r),this.g.attachProtoListener("embeddings_out",((n,s)=>{n=rm(n),this.embeddings=(function(o){return{embeddings:dr(o,tm,1).map((a=>{let i={headIndex:Gt(It(a,3),0)??-1,headName:tr(a,4)??""};if(zl(a,Mc,va(a,1))!==void 0)a=Vr(a=q(a,Mc,va(a,1)),1,Br,Gr()),i.floatEmbedding=a.slice();else{let u=new Uint8Array(0);i.quantizedEmbedding=q(a,em,va(a,2))?.pa()?.h()??u}return i})),timestampMs:Gt($s(Ar(o,2)),0)}})(n),G(this,s)})),this.g.attachEmptyPacketListener("embeddings_out",(n=>{G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};dt.cosineSimilarity=function(t,e){if(t.floatEmbedding&&e.floatEmbedding)t=zc(t.floatEmbedding,e.floatEmbedding);else{if(!t.quantizedEmbedding||!e.quantizedEmbedding)throw Error("Cannot compute cosine similarity between quantized and float embeddings.");t=zc($c(t.quantizedEmbedding),$c(e.quantizedEmbedding))}return t},dt.prototype.embedForVideo=dt.prototype.Ba,dt.prototype.embed=dt.prototype.Aa,dt.prototype.setOptions=dt.prototype.o,dt.createFromModelPath=function(t,e){return X(dt,t,{baseOptions:{modelAssetPath:e}})},dt.createFromModelBuffer=function(t,e){return X(dt,t,{baseOptions:{modelAssetBuffer:e}})},dt.createFromOptions=function(t,e){return X(dt,t,e)};var ja=class{constructor(t,e,r){this.confidenceMasks=t,this.categoryMask=e,this.qualityScores=r}close(){this.confidenceMasks?.forEach((t=>{t.close()})),this.categoryMask?.close()}};function dl(t){t.categoryMask=void 0,t.confidenceMasks=void 0,t.qualityScores=void 0}function hl(t){try{let e=new ja(t.confidenceMasks,t.categoryMask,t.qualityScores);if(!t.j)return e;t.j(e)}finally{bo(t)}}ja.prototype.close=ja.prototype.close;var qe=class extends ot{constructor(t,e){super(new Ct(t,e),"image_in","norm_rect",!1),this.s=[],this.outputCategoryMask=!1,this.outputConfidenceMasks=!0,this.h=new Vi,this.v=new qf,z(this.h,0,3,this.v),z(t=this.h,0,1,e=new ye)}get baseOptions(){return q(this.h,ye,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){return t.displayNamesLocale!==void 0?ue(this.h,2,bn(t.displayNamesLocale)):"displayNamesLocale"in t&&ue(this.h,2),"outputCategoryMask"in t&&(this.outputCategoryMask=t.outputCategoryMask??!1),"outputConfidenceMasks"in t&&(this.outputConfidenceMasks=t.outputConfidenceMasks??!0),super.l(t)}J(){(function(t){let e=dr(t.ea(),et,1).filter((r=>tr(r,1).includes("mediapipe.tasks.TensorsToSegmentationCalculator")));if(t.s=[],e.length>1)throw Error("The graph has more than one mediapipe.tasks.TensorsToSegmentationCalculator.");e.length===1&&(q(e[0],mt,7)?.l()?.g()??new Map).forEach(((r,n)=>{t.s[Number(n)]=tr(r,1)}))})(this)}segment(t,e,r){let n=typeof e!="function"?e:{};return this.j=typeof e=="function"?e:r,dl(this),Bt(this,t,n),hl(this)}Ma(t,e,r,n){let s=typeof r!="function"?r:{};return this.j=typeof r=="function"?r:n,dl(this),nr(this,t,s,e),hl(this)}Ea(){return this.s}m(){var t=new at;pe(t,"image_in"),pe(t,"norm_rect");let e=new mt;Wt(e,Zf,this.h);let r=new et;yt(r,"mediapipe.tasks.vision.image_segmenter.ImageSegmenterGraph"),ce(r,"IMAGE:image_in"),ce(r,"NORM_RECT:norm_rect"),r.o(e),xt(t,r),_o(this,t),this.outputConfidenceMasks&&(J(t,"confidence_masks"),Y(r,"CONFIDENCE_MASKS:confidence_masks"),hn(this,"confidence_masks"),this.g.da("confidence_masks",((n,s)=>{this.confidenceMasks=n.map((o=>gn(this,o,!0,!this.j))),G(this,s)})),this.g.attachEmptyPacketListener("confidence_masks",(n=>{this.confidenceMasks=[],G(this,n)}))),this.outputCategoryMask&&(J(t,"category_mask"),Y(r,"CATEGORY_MASK:category_mask"),hn(this,"category_mask"),this.g.V("category_mask",((n,s)=>{this.categoryMask=gn(this,n,!1,!this.j),G(this,s)})),this.g.attachEmptyPacketListener("category_mask",(n=>{this.categoryMask=void 0,G(this,n)}))),J(t,"quality_scores"),Y(r,"QUALITY_SCORES:quality_scores"),this.g.attachFloatVectorListener("quality_scores",((n,s)=>{this.qualityScores=n,G(this,s)})),this.g.attachEmptyPacketListener("quality_scores",(n=>{this.categoryMask=void 0,G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};qe.prototype.getLabels=qe.prototype.Ea,qe.prototype.segmentForVideo=qe.prototype.Ma,qe.prototype.segment=qe.prototype.segment,qe.prototype.setOptions=qe.prototype.o,qe.createFromModelPath=function(t,e){return X(qe,t,{baseOptions:{modelAssetPath:e}})},qe.createFromModelBuffer=function(t,e){return X(qe,t,{baseOptions:{modelAssetBuffer:e}})},qe.createFromOptions=function(t,e){return X(qe,t,e)};var Xa=class{constructor(t,e,r){this.confidenceMasks=t,this.categoryMask=e,this.qualityScores=r}close(){this.confidenceMasks?.forEach((t=>{t.close()})),this.categoryMask?.close()}};Xa.prototype.close=Xa.prototype.close;var Tm=class extends V{constructor(t){super(t)}},nn=[0,ke,-2],Ks=[0,ur,-3,xe,ur,-1],pl=[0,Ks],ml=[0,Ks,ke,-1],Ia=class extends V{constructor(t){super(t)}},gl=[0,ur,-1,xe],km=class extends V{constructor(){super()}},yl=class extends V{constructor(t){super(t)}},Ya=[1,2,3,4,5,6,7,8,9,10,14,15],pd=class extends V{constructor(){super()}};pd.prototype.g=mo([0,Ne,[0,Ya,se,Ks,se,[0,Ks,nn],se,pl,se,[0,pl,nn],se,gl,se,[0,ur,-3,xe,Vt],se,[0,ur,-3,xe],se,[0,re,ur,-2,xe,ke,xe,-1,2,ur,nn],se,ml,se,[0,ml,nn],ur,nn,re,se,[0,ur,-3,xe,nn,-1],se,[0,Ne,gl]],re,[0,re,ke,-1,xe]]);var Qt=class extends ot{constructor(t,e){super(new Ct(t,e),"image_in","norm_rect_in",!1),this.outputCategoryMask=!1,this.outputConfidenceMasks=!0,this.h=new Vi,this.s=new qf,z(this.h,0,3,this.s),z(t=this.h,0,1,e=new ye)}get baseOptions(){return q(this.h,ye,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){return"outputCategoryMask"in t&&(this.outputCategoryMask=t.outputCategoryMask??!1),"outputConfidenceMasks"in t&&(this.outputConfidenceMasks=t.outputConfidenceMasks??!0),super.l(t)}segment(t,e,r,n){let s=typeof r!="function"?r:{};this.j=typeof r=="function"?r:n,this.qualityScores=this.categoryMask=this.confidenceMasks=void 0,r=this.B+1,n=new pd;let o=new yl;var a=new Tm;if(rr(a,1,255),z(o,0,12,a),e.keypoint&&e.scribble)throw Error("Cannot provide both keypoint and scribble.");if(e.keypoint){var i=new Ia;Jn(i,3,!0),W(i,1,e.keypoint.x),W(i,2,e.keypoint.y),Xn(o,5,Ya,i)}else{if(!e.scribble)throw Error("Must provide either a keypoint or a scribble.");for(i of(a=new km,e.scribble))Jn(e=new Ia,3,!0),W(e,1,i.x),W(e,2,i.y),Hs(a,1,Ia,e);Xn(o,15,Ya,a)}Hs(n,1,yl,o),this.g.addProtoToStream(n.g(),"drishti.RenderData","roi_in",r),Bt(this,t,s);e:{try{let l=new Xa(this.confidenceMasks,this.categoryMask,this.qualityScores);if(!this.j){var u=l;break e}this.j(l)}finally{bo(this)}u=void 0}return u}m(){var t=new at;pe(t,"image_in"),pe(t,"roi_in"),pe(t,"norm_rect_in");let e=new mt;Wt(e,Zf,this.h);let r=new et;yt(r,"mediapipe.tasks.vision.interactive_segmenter.InteractiveSegmenterGraph"),ce(r,"IMAGE:image_in"),ce(r,"ROI:roi_in"),ce(r,"NORM_RECT:norm_rect_in"),r.o(e),xt(t,r),_o(this,t),this.outputConfidenceMasks&&(J(t,"confidence_masks"),Y(r,"CONFIDENCE_MASKS:confidence_masks"),hn(this,"confidence_masks"),this.g.da("confidence_masks",((n,s)=>{this.confidenceMasks=n.map((o=>gn(this,o,!0,!this.j))),G(this,s)})),this.g.attachEmptyPacketListener("confidence_masks",(n=>{this.confidenceMasks=[],G(this,n)}))),this.outputCategoryMask&&(J(t,"category_mask"),Y(r,"CATEGORY_MASK:category_mask"),hn(this,"category_mask"),this.g.V("category_mask",((n,s)=>{this.categoryMask=gn(this,n,!1,!this.j),G(this,s)})),this.g.attachEmptyPacketListener("category_mask",(n=>{this.categoryMask=void 0,G(this,n)}))),J(t,"quality_scores"),Y(r,"QUALITY_SCORES:quality_scores"),this.g.attachFloatVectorListener("quality_scores",((n,s)=>{this.qualityScores=n,G(this,s)})),this.g.attachEmptyPacketListener("quality_scores",(n=>{this.categoryMask=void 0,G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};Qt.prototype.segment=Qt.prototype.segment,Qt.prototype.setOptions=Qt.prototype.o,Qt.createFromModelPath=function(t,e){return X(Qt,t,{baseOptions:{modelAssetPath:e}})},Qt.createFromModelBuffer=function(t,e){return X(Qt,t,{baseOptions:{modelAssetBuffer:e}})},Qt.createFromOptions=function(t,e){return X(Qt,t,e)};var At=class extends ot{constructor(t,e){super(new Ct(t,e),"input_frame_gpu","norm_rect",!1),this.j={detections:[]},z(t=this.h=new Jf,0,1,e=new ye)}get baseOptions(){return q(this.h,ye,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){return t.displayNamesLocale!==void 0?ue(this.h,2,bn(t.displayNamesLocale)):"displayNamesLocale"in t&&ue(this.h,2),t.maxResults!==void 0?rr(this.h,3,t.maxResults):"maxResults"in t&&ue(this.h,3),t.scoreThreshold!==void 0?W(this.h,4,t.scoreThreshold):"scoreThreshold"in t&&ue(this.h,4),t.categoryAllowlist!==void 0?js(this.h,5,t.categoryAllowlist):"categoryAllowlist"in t&&ue(this.h,5),t.categoryDenylist!==void 0?js(this.h,6,t.categoryDenylist):"categoryDenylist"in t&&ue(this.h,6),this.l(t)}D(t,e){return this.j={detections:[]},Bt(this,t,e),this.j}F(t,e,r){return this.j={detections:[]},nr(this,t,r,e),this.j}m(){var t=new at;pe(t,"input_frame_gpu"),pe(t,"norm_rect"),J(t,"detections");let e=new mt;Wt(e,mm,this.h);let r=new et;yt(r,"mediapipe.tasks.vision.ObjectDetectorGraph"),ce(r,"IMAGE:input_frame_gpu"),ce(r,"NORM_RECT:norm_rect"),Y(r,"DETECTIONS:detections"),r.o(e),xt(t,r),this.g.attachProtoVectorListener("detections",((n,s)=>{for(let o of n)n=If(o),this.j.detections.push(ed(n));G(this,s)})),this.g.attachEmptyPacketListener("detections",(n=>{G(this,n)})),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};At.prototype.detectForVideo=At.prototype.F,At.prototype.detect=At.prototype.D,At.prototype.setOptions=At.prototype.o,At.createFromModelPath=async function(t,e){return X(At,t,{baseOptions:{modelAssetPath:e}})},At.createFromModelBuffer=function(t,e){return X(At,t,{baseOptions:{modelAssetBuffer:e}})},At.createFromOptions=function(t,e){return X(At,t,e)};var qa=class{constructor(t,e,r){this.landmarks=t,this.worldLandmarks=e,this.segmentationMasks=r}close(){this.segmentationMasks?.forEach((t=>{t.close()}))}};function xl(t){t.landmarks=[],t.worldLandmarks=[],t.segmentationMasks=void 0}function _l(t){try{let e=new qa(t.landmarks,t.worldLandmarks,t.segmentationMasks);if(!t.s)return e;t.s(e)}finally{bo(t)}}qa.prototype.close=qa.prototype.close;var ht=class extends ot{constructor(t,e){super(new Ct(t,e),"image_in","norm_rect",!1),this.landmarks=[],this.worldLandmarks=[],this.outputSegmentationMasks=!1,z(t=this.h=new Qf,0,1,e=new ye),this.v=new Hf,z(this.h,0,3,this.v),this.j=new zf,z(this.h,0,2,this.j),rr(this.j,4,1),W(this.j,2,.5),W(this.v,2,.5),W(this.h,4,.5)}get baseOptions(){return q(this.h,ye,1)}set baseOptions(t){z(this.h,0,1,t)}o(t){return"numPoses"in t&&rr(this.j,4,t.numPoses??1),"minPoseDetectionConfidence"in t&&W(this.j,2,t.minPoseDetectionConfidence??.5),"minTrackingConfidence"in t&&W(this.h,4,t.minTrackingConfidence??.5),"minPosePresenceConfidence"in t&&W(this.v,2,t.minPosePresenceConfidence??.5),"outputSegmentationMasks"in t&&(this.outputSegmentationMasks=t.outputSegmentationMasks??!1),this.l(t)}D(t,e,r){let n=typeof e!="function"?e:{};return this.s=typeof e=="function"?e:r,xl(this),Bt(this,t,n),_l(this)}F(t,e,r,n){let s=typeof r!="function"?r:{};return this.s=typeof r=="function"?r:n,xl(this),nr(this,t,s,e),_l(this)}m(){var t=new at;pe(t,"image_in"),pe(t,"norm_rect"),J(t,"normalized_landmarks"),J(t,"world_landmarks"),J(t,"segmentation_masks");let e=new mt;Wt(e,gm,this.h);let r=new et;yt(r,"mediapipe.tasks.vision.pose_landmarker.PoseLandmarkerGraph"),ce(r,"IMAGE:image_in"),ce(r,"NORM_RECT:norm_rect"),Y(r,"NORM_LANDMARKS:normalized_landmarks"),Y(r,"WORLD_LANDMARKS:world_landmarks"),r.o(e),xt(t,r),_o(this,t),this.g.attachProtoVectorListener("normalized_landmarks",((n,s)=>{this.landmarks=[];for(let o of n)n=os(o),this.landmarks.push(xo(n));G(this,s)})),this.g.attachEmptyPacketListener("normalized_landmarks",(n=>{this.landmarks=[],G(this,n)})),this.g.attachProtoVectorListener("world_landmarks",((n,s)=>{this.worldLandmarks=[];for(let o of n)n=un(o),this.worldLandmarks.push(qn(n));G(this,s)})),this.g.attachEmptyPacketListener("world_landmarks",(n=>{this.worldLandmarks=[],G(this,n)})),this.outputSegmentationMasks&&(Y(r,"SEGMENTATION_MASK:segmentation_masks"),hn(this,"segmentation_masks"),this.g.da("segmentation_masks",((n,s)=>{this.segmentationMasks=n.map((o=>gn(this,o,!0,!this.s))),G(this,s)})),this.g.attachEmptyPacketListener("segmentation_masks",(n=>{this.segmentationMasks=[],G(this,n)}))),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};ht.prototype.detectForVideo=ht.prototype.F,ht.prototype.detect=ht.prototype.D,ht.prototype.setOptions=ht.prototype.o,ht.createFromModelPath=function(t,e){return X(ht,t,{baseOptions:{modelAssetPath:e}})},ht.createFromModelBuffer=function(t,e){return X(ht,t,{baseOptions:{modelAssetBuffer:e}})},ht.createFromOptions=function(t,e){return X(ht,t,e)},ht.POSE_CONNECTIONS=hd;var gd=(t,e)=>{let r={},n={},s={};for(let o of Object.keys(t))Object.prototype.hasOwnProperty.call(t,o)&&(Object.prototype.hasOwnProperty.call(e,o)?Qi(t[o],e[o])||(s[o]={old:t[o],new:e[o]}):n[o]=t[o]);for(let o of Object.keys(e))Object.prototype.hasOwnProperty.call(e,o)&&!Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=e[o]);return{added:r,removed:n,changed:s}},Qi=(t,e)=>{if(Object.is(t,e))return!0;if(typeof t!="object"||typeof e!="object"||t===null||e===null)return!1;let r=Array.isArray(t),n=Array.isArray(e);if(r!==n)return!1;if(r){let i=t,u=e;if(i.length!==u.length)return!1;for(let l=0;l<i.length;l++)if(!Qi(i[l],u[l]))return!1;return!0}if(!md(t)||!md(e))return!1;let s=t,o=e,a=Object.keys(s);if(a.length!==Object.keys(o).length)return!1;for(let i=0;i<a.length;i++){let u=a[i];if(!u||!Object.prototype.hasOwnProperty.call(o,u)||!Qi(s[u],o[u]))return!1}return!0},md=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&Object.getPrototypeOf(t)===Object.prototype;var Em="utils/memoize/noValue",ty=Symbol(Em);var eu=t=>t;var tu=(t,...e)=>{let r=e.reduce((n,s)=>o=>s(n(o)),eu);return(...n)=>r(t(...n))};var Am=t=>`(${t})`;var yd=t=>Am(`?:${t}`),Rm=t=>`${yd(t)}?`,Im=t=>`${yd(t)}*`;var Sm=t=>`^${t}`,Cm=t=>`${t}$`,Bm=t=>typeof t=="function",Um=t=>e=>Bm(e)?e(t):e;var Fm=()=>t=>t,To=(t,e=Fm)=>r=>n=>tu(Um(n),e(n),t)(r);var iy=To(t=>Rm(t)),uy=To(t=>Im(t));var cy=To(t=>Sm(t)),ly=To(t=>Cm(t));var gy=new TextEncoder,yy=new TextDecoder;var C=(t,e="AssertError")=>{if(!t)throw new Error(e,{cause:t});return t};var xd=[.5,.42],Fr=432,Pr=768,ru=[.2,.8],_d=5,ko=2,le={Closed:"closed",Closing:"closing",Destroyed:"destroyed",Destroying:"destroying",Error:"Error",Idle:"idle",New:"new",Opened:"opened",Opening:"opening",Processing:"processing",Updated:"updated",Updating:"updating"},bd={None:"none",Blur:"blur",Overlay:"overlay"},vd={WebGL:"webgl",WebGPU:"webgpu",Canvas2D:"canvas2d"},M={ContextCreationError:"ContextCreationError",ContextLost:"ContextLost",ContextRestored:"ContextRestored",Error:"Error",ProcessorRestarted:"ProcessorRestarted",SamplingError:"SamplingError"};var Lm=t=>!!(typeof t=="string"&&Object.values(M).includes(t)),is=t=>Lm(t)?t:M.Error,us=t=>t instanceof Error?t.message:String(t),Eo=t=>{let e=new Set(Object.keys(t));return r=>{for(let n in r)e.has(n)&&typeof t[n]==typeof r[n]&&(t[n]=r[n])}},Om="ImageFetchError",Dm=t=>t?t.toLowerCase().startsWith("image/"):!1,wd=t=>{let e=new Map(t),r=new Set,n=async(a,i)=>{let u=await fetch(a,{signal:i});if(u.ok&&Dm(u.headers.get("content-type"))){let l=await u.blob();return await createImageBitmap(l)}},s=async(a,i)=>{let u=e.get(a);if(!u){if(r.has(a))return null;r.add(a);try{let l=await n(a,i);if(l)return e.set(a,l),l}catch(l){if(l instanceof Error){if(l.name!=="AbortError")throw new Error(Om,{cause:l});return}throw l}finally{r.delete(a)}}return u},o=a=>(e.get(a)?.close(),e.delete(a));return{tryFetchingImage:s,setImage:(a,i)=>{e.has(a)&&o(a),e.set(a,i)},getImage:a=>e.get(a)??null,removeImage:o,clear:()=>{for(let a of e.values())a.close();e.clear()}}},Ut=(t,e)=>r=>Math.min(Math.max(r,t),e);var Ao=(t,e,r,n)=>{if(!t||!e||!r||!n||t*n===r*e)return{sx:0,sy:0,sw:t,sh:e,dx:0,dy:0,dw:r,dh:n};let s=t/e,o=r/n;if(s>o){let l=Math.ceil(t*o)/s,c=Math.abs(t-l);return{sx:Math.ceil(c/2),sy:0,sw:l,sh:e,dx:0,dy:0,dw:r,dh:n}}let a=Math.ceil(e*s)/o,i=Math.abs(e-a);return{sx:0,sy:Math.ceil(i/2),sw:t,sh:a,dx:0,dy:0,dw:r,dh:n}},Rn=t=>{let e={};return new Proxy(e,{get(r,n,s){return r[n]||(r[n]=t[n]?.(e)),Reflect.get(r,n,s)}})},Td=(t,e,r)=>{let n=a=>{a.preventDefault(),r?.(),e.contextLost(a.statusMessage)},s=a=>{e.contextRestored(a.statusMessage)},o=a=>{e.contextCreationError(a.statusMessage)};return t.addEventListener("webglcontextlost",n),t.addEventListener("webglcontextrestored",s),t.addEventListener("webglcontextcreationerror",o),()=>{t.removeEventListener("webglcontextlost",n),t.removeEventListener("webglcontextrestored",s),t.removeEventListener("webglcontextcreationerror",o)}};function kd(t,e){let r=0,n=0;for(let s=0;s<t.length;s++){let o=t[s]>=128,a=e[s]>=128;o&&a&&r++,(o||a)&&n++}return n?r/n:0}function Ed(t,e,r,n){let s=1,o=[0];function a(l){return o[l]===void 0?l:(o[l]!==l&&(o[l]=a(o[l])),o[l])}function i(l,c){!l||!c||(l=a(l),c=a(c),l!==c&&(o[c]=l))}for(let l=0;l<n;l++)for(let c=0;c<r;c++){let f=l*r+c;if(t[f]<128){e[f]=0;continue}let d=c>0?e[f-1]:0,p=l>0?e[f-r]:0,b=c>0&&l>0?e[f-r-1]:0,E=c<r-1&&l>0?e[f-r+1]:0,A=d||p||b||E;A||(A=s++,o[A]=A),e[f]=A,d&&d!==A&&i(A,d),p&&p!==A&&i(A,p),b&&b!==A&&i(A,b),E&&E!==A&&i(A,E)}for(let l=0;l<e.length;l++){let c=e[l];e[l]=c?a(c):0}let u=new Map;for(let l=0;l<n;l++)for(let c=0;c<r;c++){let f=e[l*r+c];if(!f)continue;let d=u.get(f)??{sumX:0,sumY:0,count:0,minX:r,minY:n,maxX:-1,maxY:-1};d.sumX+=c,d.sumY+=l,d.count++,c<d.minX&&(d.minX=c),c>d.maxX&&(d.maxX=c),l<d.minY&&(d.minY=l),l>d.maxY&&(d.maxY=l),u.set(f,d)}return u}function Ad(t,e,r,n,s){let o=t.count,a=t.maxY-t.minY+1,i=t.sumX/t.count,u=t.sumY/t.count,l=(i-r.centerX)**2+(u-r.centerY)**2,c=1-Math.min(1,Math.sqrt(l)/Math.max(n,s)),f=o/(n*s),d=a/s;return r.iou*e+r.area*f+r.height*d+r.center*c}var Rd=()=>{try{let t=new OffscreenCanvas(1,1);return!!("WebGL2RenderingContext"in globalThis&&t.getContext("webgl2",{premultipliedAlpha:!1,powerPreference:"high-performance"}))}catch{return!1}},Mm=new Set(["float32","uint8"]),cs=(t,e=[3])=>{let r=Array.from(t.shape);if(r.length!==4||r[0]!==1)throw new Error(`Unsupported shape: [${r.join(", ")}]`);if(!Mm.has(t.dtype))throw new Error(`Unsupported input data type: ${t.dtype}`);let n=e.includes(r[3]??0),s=e.includes(r[1]??0);if(!n&&!s)throw new Error(e.length===1&&e[0]===3?"The tensor must contain three RGB channels":`Unsupported tensor channel count: [${e.join(", ")}] expected`);let o=r[n?1:2]??0,a=r[n?2:3]??0;if(a<=0||o<=0)throw new Error("The tensor dimensions must be positive");return{name:t.name,shape:r,width:a,height:o,layout:n?"nhwc":"nchw",channels:r[n?3:1]??0,dtype:t.dtype}};var Iu=(t,e)=>((t+e-1)/e|0)*e;function Nm(t){return Object.keys(t)}function Gm(t,e){return new Array(t).fill(0).map((r,n)=>e(n))}var Id=t=>ArrayBuffer.isView(t)&&!(t instanceof DataView),Fd=t=>t,K=Fd({i32:{numElements:1,align:4,size:4,type:"i32",View:Int32Array},u32:{numElements:1,align:4,size:4,type:"u32",View:Uint32Array},f32:{numElements:1,align:4,size:4,type:"f32",View:Float32Array},f16:{numElements:1,align:2,size:2,type:"u16",View:Uint16Array},vec2f:{numElements:2,align:8,size:8,type:"f32",View:Float32Array},vec2i:{numElements:2,align:8,size:8,type:"i32",View:Int32Array},vec2u:{numElements:2,align:8,size:8,type:"u32",View:Uint32Array},vec2h:{numElements:2,align:4,size:4,type:"u16",View:Uint16Array},vec3i:{numElements:3,align:16,size:12,type:"i32",View:Int32Array},vec3u:{numElements:3,align:16,size:12,type:"u32",View:Uint32Array},vec3f:{numElements:3,align:16,size:12,type:"f32",View:Float32Array},vec3h:{numElements:3,align:8,size:6,type:"u16",View:Uint16Array},vec4i:{numElements:4,align:16,size:16,type:"i32",View:Int32Array},vec4u:{numElements:4,align:16,size:16,type:"u32",View:Uint32Array},vec4f:{numElements:4,align:16,size:16,type:"f32",View:Float32Array},vec4h:{numElements:4,align:8,size:8,type:"u16",View:Uint16Array},mat2x2f:{numElements:4,align:8,size:16,type:"f32",View:Float32Array},mat2x2h:{numElements:4,align:4,size:8,type:"u16",View:Uint16Array},mat3x2f:{numElements:6,align:8,size:24,type:"f32",View:Float32Array},mat3x2h:{numElements:6,align:4,size:12,type:"u16",View:Uint16Array},mat4x2f:{numElements:8,align:8,size:32,type:"f32",View:Float32Array},mat4x2h:{numElements:8,align:4,size:16,type:"u16",View:Uint16Array},mat2x3f:{numElements:8,align:16,size:32,pad:[3,1],type:"f32",View:Float32Array},mat2x3h:{numElements:8,align:8,size:16,pad:[3,1],type:"u16",View:Uint16Array},mat3x3f:{numElements:12,align:16,size:48,pad:[3,1],type:"f32",View:Float32Array},mat3x3h:{numElements:12,align:8,size:24,pad:[3,1],type:"u16",View:Uint16Array},mat4x3f:{numElements:16,align:16,size:64,pad:[3,1],type:"f32",View:Float32Array},mat4x3h:{numElements:16,align:8,size:32,pad:[3,1],type:"u16",View:Uint16Array},mat2x4f:{numElements:8,align:16,size:32,type:"f32",View:Float32Array},mat2x4h:{numElements:8,align:8,size:16,type:"u16",View:Uint16Array},mat3x4f:{numElements:12,align:16,size:48,pad:[3,1],type:"f32",View:Float32Array},mat3x4h:{numElements:12,align:8,size:24,pad:[3,1],type:"u16",View:Uint16Array},mat4x4f:{numElements:16,align:16,size:64,type:"f32",View:Float32Array},mat4x4h:{numElements:16,align:8,size:32,type:"u16",View:Uint16Array},bool:{numElements:0,align:1,size:0,type:"bool",View:Uint32Array}}),Ln=Fd({...K,"atomic<i32>":K.i32,"atomic<u32>":K.u32,"vec2<i32>":K.vec2i,"vec2<u32>":K.vec2u,"vec2<f32>":K.vec2f,"vec2<f16>":K.vec2h,"vec3<i32>":K.vec3i,"vec3<u32>":K.vec3u,"vec3<f32>":K.vec3f,"vec3<f16>":K.vec3h,"vec4<i32>":K.vec4i,"vec4<u32>":K.vec4u,"vec4<f32>":K.vec4f,"vec4<f16>":K.vec4h,"mat2x2<f32>":K.mat2x2f,"mat2x2<f16>":K.mat2x2h,"mat3x2<f32>":K.mat3x2f,"mat3x2<f16>":K.mat3x2h,"mat4x2<f32>":K.mat4x2f,"mat4x2<f16>":K.mat4x2h,"mat2x3<f32>":K.mat2x3f,"mat2x3<f16>":K.mat2x3h,"mat3x3<f32>":K.mat3x3f,"mat3x3<f16>":K.mat3x3h,"mat4x3<f32>":K.mat4x3f,"mat4x3<f16>":K.mat4x3h,"mat2x4<f32>":K.mat2x4f,"mat2x4<f16>":K.mat2x4h,"mat3x4<f32>":K.mat3x4f,"mat3x4<f16>":K.mat3x4h,"mat4x4<f32>":K.mat4x4f,"mat4x4<f16>":K.mat4x4h}),Vm=Nm(Ln);function Wm(t=[],e){let r=new Set;for(let n of Vm){let s=Ln[n];r.has(s)||(r.add(s),s.flatten=t.includes(n)?e:!e)}}Wm();function $m(t){let e=t;if(e.elementType)return e.size;{let n=t,s=e.numElements||1;if(n.fields)return t.size*s;{let o=t,{align:a}=Ln[o.type];return s>1?Iu(t.size,a)*s:t.size}}}function Sd(t,e,r,n){let{size:s,type:o}=t;try{let{View:a,align:i,size:u}=Ln[o],l=n!==void 0,c=l?Iu(s,i):u,f=c/a.BYTES_PER_ELEMENT,d=l?n===0?(e.byteLength-r)/c:n:1;return new a(e,r,f*d)}catch{throw new Error(`unknown type: ${o}`)}}function zm(t){return!t.fields&&!t.elementType}function Hm(t,e,r){let n=r||0,s=e||new ArrayBuffer($m(t)),o=(a,i)=>{let u=a,l=u.elementType;if(l){if(zm(l)&&Ln[l.type].flatten)return Sd(l,s,i,u.numElements);{let{size:c}=Pd(a),f=u.numElements===0?(s.byteLength-i)/c:u.numElements;return Gm(f,d=>o(l,i+c*d))}}else{if(typeof a=="string")throw Error("unreachable");{let c=a.fields;if(c){let f={};for(let[d,{type:p,offset:b}]of Object.entries(c))f[d]=o(p,i+b);return f}else return Sd(a,s,i)}}};return{views:o(t,n),arrayBuffer:s}}function iu(t,e){if(t!==void 0)if(Id(e)){let r=e;if(r.length===1&&typeof t=="number")r[0]=t;else if(Array.isArray(t[0])||Id(t[0])){let n=t[0].length,s=n===3?4:n;for(let o=0;o<t.length;++o){let a=o*s;r.set(t[o],a)}}else r.set(t)}else if(Array.isArray(e)){let r=e;t.forEach((n,s)=>{iu(n,r[s])})}else{let r=e;for(let[n,s]of Object.entries(t)){let o=r[n];o&&iu(s,o)}}}function wt(t,e,r=0){let n=t,s=n.group===void 0?t:n.typeDefinition,o=Hm(s,e,r);return{...o,set(a){iu(a,o.views)}}}function uu(t){let r=t.elementType;if(r)return uu(r);let s=t.fields;if(s)return Object.values(s).reduce((i,{type:u})=>Math.max(i,uu(u)),0);let{type:o}=t,{align:a}=Ln[o];return a}function Pd(t){let r=t.elementType;if(r){let o=r.size,a=uu(r);return{unalignedSize:o,align:a,size:Iu(o,a)}}let s=t.fields;if(s){let o=Object.values(s).pop();if(o.type.size===0)return Pd(o.type)}return{size:0,unalignedSize:0,align:1}}var it=class{constructor(e,r){this.name=e,this.attributes=r,this.size=0}get isArray(){return!1}get isStruct(){return!1}get isTemplate(){return!1}get isPointer(){return!1}getTypeName(){return this.name}},Ro=class{constructor(e,r,n){this.name=e,this.type=r,this.attributes=n,this.offset=0,this.size=0}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray||this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},sr=class extends it{constructor(e,r){super(e,r),this.members=[],this.align=0,this.startLine=-1,this.endLine=-1,this.inUse=!1}get isStruct(){return!0}},or=class extends it{constructor(e,r){super(e,r),this.count=0,this.stride=0}get isArray(){return!0}getTypeName(){return`array<${this.format.getTypeName()}, ${this.count}>`}},fs=class extends it{constructor(e,r,n){super(e,n),this.format=r}get isPointer(){return!0}getTypeName(){return`&${this.format.getTypeName()}`}},gr=class extends it{constructor(e,r,n,s){super(e,n),this.format=r,this.access=s}get isTemplate(){return!0}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}},Re;(t=>{t[t.Uniform=0]="Uniform",t[t.Storage=1]="Storage",t[t.Immediate=2]="Immediate",t[t.Texture=3]="Texture",t[t.Sampler=4]="Sampler",t[t.StorageTexture=5]="StorageTexture"})(Re||(Re={}));var Xr=class{constructor(e,r,n,s,o,a,i){this.relations=null,this.name=e,this.type=r,this.group=n,this.binding=s,this.attributes=o,this.resourceType=a,this.access=i}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}},cu=class{constructor(e,r){this.name=e,this.type=r}},lu=class{constructor(e,r,n,s){this.name=e,this.type=r,this.locationType=n,this.location=s,this.interpolation=null}},Io=class{constructor(e,r,n,s){this.name=e,this.type=r,this.locationType=n,this.location=s}},fu=class{constructor(e,r,n,s){this.name=e,this.type=r,this.attributes=n,this.id=s}},du=class{constructor(e,r,n){this.name=e,this.type=r,this.attributes=n}},hu=class{constructor(e,r=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=r,this.attributes=n}},pu=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}};function jm(t){var e=(32768&t)>>15,r=(31744&t)>>10,n=1023&t;return r==0?(e?-1:1)*Math.pow(2,-14)*(n/Math.pow(2,10)):r==31?n?NaN:1/0*(e?-1:1):(e?-1:1)*Math.pow(2,r-15)*(1+n/Math.pow(2,10))}var Ld=new Float32Array(1),Xm=new Int32Array(Ld.buffer),Ze=new Uint16Array(1);function Ym(t){Ld[0]=t;let e=Xm[0],r=e>>31&1,n=e>>23&255,s=8388607&e;if(n===255)return Ze[0]=r<<15|31744|(s!==0?512:0),Ze[0];if(n===0){if(s===0)return Ze[0]=r<<15,Ze[0];s|=8388608;let o=113;for(;!(8388608&s);)s<<=1,o--;return n=127-o,s&=8388607,n>0?(s=(s>>126-n)+(s>>127-n&1),Ze[0]=r<<15|n<<10|s>>13,Ze[0]):(Ze[0]=r<<15,Ze[0])}return n=n-127+15,n>=31?(Ze[0]=r<<15|31744,Ze[0]):n<=0?n<-10?(Ze[0]=r<<15,Ze[0]):(s=(8388608|s)>>1-n,Ze[0]=r<<15|s>>13,Ze[0]):(s>>=13,Ze[0]=r<<15|n<<10|s,Ze[0])}var Su=new Uint32Array(1),Od=new Float32Array(Su.buffer,0,1);function Cd(t){let e=112+(t>>6&31)<<23|(63&t)<<17;return Su[0]=e,Od[0]}function qm(t,e,r,n,s,o,a,i,u){let l=n*(a>>=s)*(o>>=s)+r*a+e*i;switch(u){case"r8unorm":return[ee(t,l,"8unorm",1)[0]];case"r8snorm":return[ee(t,l,"8snorm",1)[0]];case"r8uint":return[ee(t,l,"8uint",1)[0]];case"r8sint":return[ee(t,l,"8sint",1)[0]];case"rg8unorm":{let c=ee(t,l,"8unorm",2);return[c[0],c[1]]}case"rg8snorm":{let c=ee(t,l,"8snorm",2);return[c[0],c[1]]}case"rg8uint":{let c=ee(t,l,"8uint",2);return[c[0],c[1]]}case"rg8sint":{let c=ee(t,l,"8sint",2);return[c[0],c[1]]}case"rgba8unorm-srgb":case"rgba8unorm":{let c=ee(t,l,"8unorm",4);return[c[0],c[1],c[2],c[3]]}case"rgba8snorm":{let c=ee(t,l,"8snorm",4);return[c[0],c[1],c[2],c[3]]}case"rgba8uint":{let c=ee(t,l,"8uint",4);return[c[0],c[1],c[2],c[3]]}case"rgba8sint":{let c=ee(t,l,"8sint",4);return[c[0],c[1],c[2],c[3]]}case"bgra8unorm-srgb":case"bgra8unorm":{let c=ee(t,l,"8unorm",4);return[c[2],c[1],c[0],c[3]]}case"r16uint":return[ee(t,l,"16uint",1)[0]];case"r16sint":return[ee(t,l,"16sint",1)[0]];case"r16float":return[ee(t,l,"16float",1)[0]];case"rg16uint":{let c=ee(t,l,"16uint",2);return[c[0],c[1]]}case"rg16sint":{let c=ee(t,l,"16sint",2);return[c[0],c[1]]}case"rg16float":{let c=ee(t,l,"16float",2);return[c[0],c[1]]}case"rgba16uint":{let c=ee(t,l,"16uint",4);return[c[0],c[1],c[2],c[3]]}case"rgba16sint":{let c=ee(t,l,"16sint",4);return[c[0],c[1],c[2],c[3]]}case"rgba16float":{let c=ee(t,l,"16float",4);return[c[0],c[1],c[2],c[3]]}case"r32uint":return[ee(t,l,"32uint",1)[0]];case"r32sint":return[ee(t,l,"32sint",1)[0]];case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return[ee(t,l,"32float",1)[0]];case"rg32uint":{let c=ee(t,l,"32uint",2);return[c[0],c[1]]}case"rg32sint":{let c=ee(t,l,"32sint",2);return[c[0],c[1]]}case"rg32float":{let c=ee(t,l,"32float",2);return[c[0],c[1]]}case"rgba32uint":{let c=ee(t,l,"32uint",4);return[c[0],c[1],c[2],c[3]]}case"rgba32sint":{let c=ee(t,l,"32sint",4);return[c[0],c[1],c[2],c[3]]}case"rgba32float":{let c=ee(t,l,"32float",4);return[c[0],c[1],c[2],c[3]]}case"rg11b10ufloat":{let c=new Uint32Array(t.buffer,l,1)[0],f=(4192256&c)>>11,d=(4290772992&c)>>22;return[Cd(2047&c),Cd(f),(function(p){let b=112+(p>>5&31)<<23|(31&p)<<18;return Su[0]=b,Od[0]})(d),1]}}return null}function ee(t,e,r,n){let s=[0,0,0,0];for(let o=0;o<n;++o)switch(r){case"8unorm":s[o]=t[e]/255,e++;break;case"8snorm":s[o]=t[e]/255*2-1,e++;break;case"8uint":s[o]=t[e],e++;break;case"8sint":s[o]=t[e]-127,e++;break;case"16uint":s[o]=t[e]|t[e+1]<<8,e+=2;break;case"16sint":s[o]=(t[e]|t[e+1]<<8)-32768,e+=2;break;case"16float":s[o]=jm(t[e]|t[e+1]<<8),e+=2;break;case"32uint":case"32sint":s[o]=t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24,e+=4;break;case"32float":s[o]=new Float32Array(t.buffer,e,1)[0],e+=4}return s}function te(t,e,r,n,s){for(let o=0;o<n;++o)switch(r){case"8unorm":t[e]=255*s[o],e++;break;case"8snorm":t[e]=.5*(s[o]+1)*255,e++;break;case"8uint":t[e]=s[o],e++;break;case"8sint":t[e]=s[o]+127,e++;break;case"16uint":new Uint16Array(t.buffer,e,1)[0]=s[o],e+=2;break;case"16sint":new Int16Array(t.buffer,e,1)[0]=s[o],e+=2;break;case"16float":{let a=Ym(s[o]);new Uint16Array(t.buffer,e,1)[0]=a,e+=2;break}case"32uint":new Uint32Array(t.buffer,e,1)[0]=s[o],e+=4;break;case"32sint":new Int32Array(t.buffer,e,1)[0]=s[o],e+=4;break;case"32float":new Float32Array(t.buffer,e,1)[0]=s[o],e+=4}return s}var nu={r8unorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8snorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8uint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8sint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg8unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8snorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"rgba8unorm-srgb":{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8snorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},bgra8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"bgra8unorm-srgb":{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r16uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16float:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg16uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba16uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r32uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg32uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba32uint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32sint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32float:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rg11b10ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},stencil8:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!1,hasStencil:!0,channels:1},depth16unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},depth24plus:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,depthOnlyFormat:"depth32float",channels:1},"depth24plus-stencil8":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,depthOnlyFormat:"depth32float",channels:1},depth32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},"depth32float-stencil8":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,stencilOnlyFormat:"depth32float",channels:1},rgb9e5ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"bc1-rgba-unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc1-rgba-unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc2-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc2-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc3-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc3-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc4-r-unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},"bc4-r-snorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},"bc5-rg-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},"bc5-rg-snorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},"bc6h-rgb-ufloat":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc6h-rgb-float":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc7-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc7-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8a1unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8a1unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgba8unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgba8unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"eac-r11unorm":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},"eac-r11snorm":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},"eac-rg11unorm":{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},"eac-rg11snorm":{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},"astc-4x4-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"astc-4x4-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"astc-5x4-unorm":{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},"astc-5x4-unorm-srgb":{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},"astc-5x5-unorm":{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},"astc-5x5-unorm-srgb":{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},"astc-6x5-unorm":{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},"astc-6x5-unorm-srgb":{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},"astc-6x6-unorm":{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},"astc-6x6-unorm-srgb":{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},"astc-8x5-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},"astc-8x5-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},"astc-8x6-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},"astc-8x6-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},"astc-8x8-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},"astc-8x8-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},"astc-10x5-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},"astc-10x5-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},"astc-10x6-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},"astc-10x6-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},"astc-10x8-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},"astc-10x8-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},"astc-10x10-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},"astc-10x10-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},"astc-12x10-unorm":{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},"astc-12x10-unorm-srgb":{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},"astc-12x12-unorm":{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4},"astc-12x12-unorm-srgb":{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4}},Lt=class t{constructor(){this.id=t._id++,this.line=0}get isAstNode(){return!0}get astNodeType(){return""}search(e){e(this)}searchBlock(e,r){if(e){r(Fn.instance);for(let n of e)n instanceof Array?this.searchBlock(n,r):n.search(r);r(Pn.instance)}}constEvaluate(e,r){throw new Error("Cannot evaluate node")}constEvaluateString(e){var r,n;return(n=(r=this.constEvaluate(e))===null||r===void 0?void 0:r.toString())!==null&&n!==void 0?n:""}};Lt._id=0;var Fn=class extends Lt{};Fn.instance=new Fn;var Pn=class extends Lt{};Pn.instance=new Pn;var Dd=new Set(["all","any","select","arrayLength","abs","acos","acosh","asin","asinh","atan","atanh","atan2","ceil","clamp","cos","cosh","countLeadingZeros","countOneBits","countTrailingZeros","cross","degrees","determinant","distance","dot","dot4U8Packed","dot4I8Packed","exp","exp2","extractBits","faceForward","firstLeadingBit","firstTrailingBit","floor","fma","fract","frexp","insertBits","inverseSqrt","ldexp","length","log","log2","max","min","mix","modf","normalize","pow","quantizeToF16","radians","reflect","refract","reverseBits","round","saturate","sign","sin","sinh","smoothstep","sqrt","step","tan","tanh","transpose","trunc","dpdx","dpdxCoarse","dpdxFine","dpdy","dpdyCoarse","dpdyFine","fwidth","fwidthCoarse","fwidthFine","textureDimensions","textureGather","textureGatherCompare","textureLoad","textureNumLayers","textureNumLevels","textureNumSamples","textureSample","textureSampleBias","textureSampleCompare","textureSampleCompareLevel","textureSampleGrad","textureSampleLevel","textureSampleBaseClampToEdge","textureStore","atomicLoad","atomicStore","atomicAdd","atomicSub","atomicMax","atomicMin","atomicAnd","atomicOr","atomicXor","atomicExchange","atomicCompareExchangeWeak","pack4x8snorm","pack4x8unorm","pack4xI8","pack4xU8","pack4x8Clamp","pack4xU8Clamp","pack2x16snorm","pack2x16unorm","pack2x16float","unpack4x8snorm","unpack4x8unorm","unpack4xI8","unpack4xU8","unpack2x16snorm","unpack2x16unorm","unpack2x16float","storageBarrier","textureBarrier","workgroupBarrier","workgroupUniformLoad","subgroupAdd","subgroupExclusiveAdd","subgroupInclusiveAdd","subgroupAll","subgroupAnd","subgroupAny","subgroupBallot","subgroupBroadcast","subgroupBroadcastFirst","subgroupElect","subgroupMax","subgroupMin","subgroupMul","subgroupExclusiveMul","subgroupInclusiveMul","subgroupOr","subgroupShuffle","subgroupShuffleDown","subgroupShuffleUp","subgroupShuffleXor","subgroupXor","quadBroadcast","quadSwapDiagonal","quadSwapX","quadSwapY"]),fe=class extends Lt{},Jr=class extends fe{constructor(e,r,n,s,o,a){super(),this.calls=new Set,this.name=e,this.args=r,this.returnType=n,this.body=s,this.startLine=o,this.endLine=a}get astNodeType(){return"function"}search(e){if(this.attributes)for(let r of this.attributes)e(r);e(this);for(let r of this.args)e(r);this.searchBlock(this.body,e)}},So=class extends fe{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}},Co=class extends fe{constructor(e,r){super(),this.condition=e,this.body=r}get astNodeType(){return"while"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},ds=class extends fe{constructor(e,r){super(),this.body=e,this.loopId=r}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}},Bo=class extends fe{constructor(e,r,n,s){super(),this.init=e,this.condition=r,this.increment=n,this.body=s}get astNodeType(){return"for"}search(e){var r,n,s;(r=this.init)===null||r===void 0||r.search(e),(n=this.condition)===null||n===void 0||n.search(e),(s=this.increment)===null||s===void 0||s.search(e),this.searchBlock(this.body,e)}},Pt=class extends fe{constructor(e,r,n,s,o){super(),this.attributes=null,this.name=e,this.type=r,this.storage=n,this.access=s,this.value=o}get astNodeType(){return"var"}search(e){var r;e(this),(r=this.value)===null||r===void 0||r.search(e)}},hs=class extends fe{constructor(e,r,n){super(),this.attributes=null,this.name=e,this.type=r,this.value=n}get astNodeType(){return"override"}search(e){var r;(r=this.value)===null||r===void 0||r.search(e)}},qr=class extends fe{constructor(e,r,n,s,o){super(),this.attributes=null,this.name=e,this.type=r,this.storage=n,this.access=s,this.value=o}get astNodeType(){return"let"}search(e){var r;e(this),(r=this.value)===null||r===void 0||r.search(e)}},Cn=class extends fe{constructor(e,r,n,s,o){super(),this.attributes=null,this.name=e,this.type=r,this.storage=n,this.access=s,this.value=o}get astNodeType(){return"const"}constEvaluate(e,r){return this.value.constEvaluate(e,r)}search(e){var r;e(this),(r=this.value)===null||r===void 0||r.search(e)}},In,ls,k,x;(t=>{t.increment="++",t.decrement="--"})(In||(In={})),(t=>{t.parse=function(e){let r=e;if(r==="parse")throw new Error("Invalid value for IncrementOperator");return t[r]}})(In||(In={}));var Uo=class extends fe{constructor(e,r){super(),this.operator=e,this.variable=r}get astNodeType(){return"increment"}search(e){this.variable.search(e)}};(t=>{t.assign="=",t.addAssign="+=",t.subtractAssign="-=",t.multiplyAssign="*=",t.divideAssign="/=",t.moduloAssign="%=",t.andAssign="&=",t.orAssign="|=",t.xorAssign="^=",t.shiftLeftAssign="<<=",t.shiftRightAssign=">>="})(ls||(ls={})),(t=>{t.parse=function(e){let r=e;if(r==="parse")throw new Error("Invalid value for AssignOperator");return r}})(ls||(ls={}));var Fo=class extends fe{constructor(e,r,n){super(),this.operator=e,this.variable=r,this.value=n}get astNodeType(){return"assign"}search(e){this.variable.search(e),this.value.search(e)}},ps=class extends fe{constructor(e,r){super(),this.name=e,this.args=r}get astNodeType(){return"call"}isBuiltin(){return Dd.has(this.name)}search(e){for(let r of this.args)r.search(e);e(this)}},Po=class extends fe{constructor(e,r){super(),this.body=e,this.continuing=r}get astNodeType(){return"loop"}search(e){var r;this.searchBlock(this.body,e),(r=this.continuing)===null||r===void 0||r.search(e)}},Lo=class extends fe{constructor(e,r){super(),this.condition=e,this.cases=r}get astNodeType(){return"switch"}search(e){e(this);for(let r of this.cases)r.search(e)}},Oo=class extends fe{constructor(e,r,n,s){super(),this.condition=e,this.body=r,this.elseif=n,this.else=s}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)}},Do=class extends fe{constructor(e){super(),this.value=e}get astNodeType(){return"return"}search(e){var r;(r=this.value)===null||r===void 0||r.search(e)}},mu=class extends fe{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}},gu=class extends fe{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}},Mo=class extends fe{constructor(e,r){super(),this.severity=e,this.rule=r}get astNodeType(){return"diagnostic"}},ms=class extends fe{constructor(e,r){super(),this.name=e,this.type=r}get astNodeType(){return"alias"}},yu=class extends fe{get astNodeType(){return"discard"}},No=class extends fe{constructor(){super(...arguments),this.condition=null,this.loopId=-1}get astNodeType(){return"break"}},Go=class extends fe{constructor(){super(...arguments),this.loopId=-1}get astNodeType(){return"continue"}},S=class t extends fe{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 r=e[0];if(r.name==="f32")return r;for(let n=1;n<e.length;++n){let s=t._priority.get(r.name);t._priority.get(e[n].name)<s&&(r=e[n])}return r.name==="x32"?t.i32:r}getTypeName(){return this.name}};S.x32=new S("x32"),S.f32=new S("f32"),S.i32=new S("i32"),S.u32=new S("u32"),S.f16=new S("f16"),S.bool=new S("bool"),S.void=new S("void"),S._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);var Vo=class extends S{constructor(e){super(e)}},jt=class extends S{constructor(e,r,n,s){super(e),this.members=r,this.startLine=n,this.endLine=s}get astNodeType(){return"struct"}get isStruct(){return!0}getMemberIndex(e){for(let r=0;r<this.members.length;r++)if(this.members[r].name===e)return r;return-1}search(e){for(let r of this.members)e(r)}},w=class extends S{constructor(e,r,n){super(e),this.format=r,this.access=n}get astNodeType(){return"template"}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}};w.vec2f=new w("vec2",S.f32,null),w.vec3f=new w("vec3",S.f32,null),w.vec4f=new w("vec4",S.f32,null),w.vec2i=new w("vec2",S.i32,null),w.vec3i=new w("vec3",S.i32,null),w.vec4i=new w("vec4",S.i32,null),w.vec2u=new w("vec2",S.u32,null),w.vec3u=new w("vec3",S.u32,null),w.vec4u=new w("vec4",S.u32,null),w.vec2h=new w("vec2",S.f16,null),w.vec3h=new w("vec3",S.f16,null),w.vec4h=new w("vec4",S.f16,null),w.vec2b=new w("vec2",S.bool,null),w.vec3b=new w("vec3",S.bool,null),w.vec4b=new w("vec4",S.bool,null),w.mat2x2f=new w("mat2x2",S.f32,null),w.mat2x3f=new w("mat2x3",S.f32,null),w.mat2x4f=new w("mat2x4",S.f32,null),w.mat3x2f=new w("mat3x2",S.f32,null),w.mat3x3f=new w("mat3x3",S.f32,null),w.mat3x4f=new w("mat3x4",S.f32,null),w.mat4x2f=new w("mat4x2",S.f32,null),w.mat4x3f=new w("mat4x3",S.f32,null),w.mat4x4f=new w("mat4x4",S.f32,null),w.mat2x2h=new w("mat2x2",S.f16,null),w.mat2x3h=new w("mat2x3",S.f16,null),w.mat2x4h=new w("mat2x4",S.f16,null),w.mat3x2h=new w("mat3x2",S.f16,null),w.mat3x3h=new w("mat3x3",S.f16,null),w.mat3x4h=new w("mat3x4",S.f16,null),w.mat4x2h=new w("mat4x2",S.f16,null),w.mat4x3h=new w("mat4x3",S.f16,null),w.mat4x4h=new w("mat4x4",S.f16,null),w.mat2x2i=new w("mat2x2",S.i32,null),w.mat2x3i=new w("mat2x3",S.i32,null),w.mat2x4i=new w("mat2x4",S.i32,null),w.mat3x2i=new w("mat3x2",S.i32,null),w.mat3x3i=new w("mat3x3",S.i32,null),w.mat3x4i=new w("mat3x4",S.i32,null),w.mat4x2i=new w("mat4x2",S.i32,null),w.mat4x3i=new w("mat4x3",S.i32,null),w.mat4x4i=new w("mat4x4",S.i32,null),w.mat2x2u=new w("mat2x2",S.u32,null),w.mat2x3u=new w("mat2x3",S.u32,null),w.mat2x4u=new w("mat2x4",S.u32,null),w.mat3x2u=new w("mat3x2",S.u32,null),w.mat3x3u=new w("mat3x3",S.u32,null),w.mat3x4u=new w("mat3x4",S.u32,null),w.mat4x2u=new w("mat4x2",S.u32,null),w.mat4x3u=new w("mat4x3",S.u32,null),w.mat4x4u=new w("mat4x4",S.u32,null);var Bn=class extends S{constructor(e,r,n,s){super(e),this.storage=r,this.type=n,this.access=s}get astNodeType(){return"pointer"}},Kr=class extends S{constructor(e,r,n,s){super(e),this.attributes=r,this.format=n,this.count=s}get astNodeType(){return"array"}get isArray(){return!0}},Yr=class extends S{constructor(e,r,n){super(e),this.format=r,this.access=n}get astNodeType(){return"sampler"}},vt=class extends Lt{constructor(){super(),this.postfix=null,this.hasParen=!1}},yr=class extends vt{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}constEvaluateString(){return this.value}},Ft=class extends vt{constructor(e,r){super(),this.type=e,this.args=r}get astNodeType(){return"createExpr"}search(e){if(e(this),this.args)for(let r of this.args)r.search(e)}constEvaluate(e,r){return r&&(r[0]=this.type),e.evalExpression(this,e.context)}},gs=class extends vt{constructor(e,r){super(),this.cachedReturnValue=null,this.name=e,this.args=r}get astNodeType(){return"callExpr"}setCachedReturnValue(e){this.cachedReturnValue=e}get isBuiltin(){return Dd.has(this.name)}constEvaluate(e,r){return e.evalExpression(this,e.context)}search(e){for(let r of this.args)r.search(e);e(this)}},He=class extends vt{constructor(e){super(),this.name=e}get astNodeType(){return"varExpr"}search(e){e(this),this.postfix&&this.postfix.search(e)}constEvaluate(e,r){return e.evalExpression(this,e.context)}},Wo=class extends vt{constructor(e,r){super(),this.name=e,this.initializer=r}get astNodeType(){return"constExpr"}constEvaluate(e,r){let n=e.evalExpression(this.initializer,e.context);return n!==null&&this.postfix?n.getSubData(e,this.postfix,e.context):n}search(e){this.initializer.search(e)}},Fe=class extends vt{constructor(e,r){super(),this.value=e,this.type=r}get astNodeType(){return"literalExpr"}constEvaluate(e,r){return r!==void 0&&(r[0]=this.type),this.value}get isScalar(){return this.value instanceof v}get isVector(){return this.value instanceof g||this.value instanceof H}get scalarValue(){return this.value instanceof v?this.value.value:(console.error("Value is not scalar."),0)}get vectorValue(){return this.value instanceof g||this.value instanceof H?this.value.data:(console.error("Value is not a vector or matrix."),new Float32Array(0))}},$o=class extends vt{constructor(e,r){super(),this.type=e,this.value=r}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}},Or=class extends vt{constructor(e){super(),this.index=e}search(e){this.index.search(e)}},zo=class extends vt{constructor(){super()}},Ee=class extends zo{constructor(e,r){super(),this.operator=e,this.right=r}get astNodeType(){return"unaryOp"}constEvaluate(e,r){return e.evalExpression(this,e.context)}search(e){this.right.search(e)}},_t=class extends zo{constructor(e,r,n){super(),this.operator=e,this.left=r,this.right=n}get astNodeType(){return"binaryOp"}_getPromotedType(e,r){return e.name===r.name?e:e.name==="f32"||r.name==="f32"?S.f32:e.name==="u32"||r.name==="u32"?S.u32:S.i32}constEvaluate(e,r){return e.evalExpression(this,e.context)}search(e){this.left.search(e),this.right.search(e)}},Ho=class extends Lt{constructor(e){super(),this.body=e}search(e){e(this),this.searchBlock(this.body,e)}},Un=class extends vt{get astNodeType(){return"default"}},jo=class extends Ho{constructor(e,r){super(r),this.selectors=e}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}},Xo=class extends Ho{constructor(e){super(e)}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}},Yo=class extends Lt{constructor(e,r,n){super(),this.name=e,this.type=r,this.attributes=n}get astNodeType(){return"argument"}},xu=class extends Lt{constructor(e,r){super(),this.condition=e,this.body=r}get astNodeType(){return"elseif"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},qo=class extends Lt{constructor(e,r,n){super(),this.name=e,this.type=r,this.attributes=n}get astNodeType(){return"member"}},Ko=class extends Lt{constructor(e,r){super(),this.name=e,this.value=r}get astNodeType(){return"attribute"}},Xt=class t{constructor(e,r){this.parent=null,this.typeInfo=e,this.parent=r,this.id=t._id++}setDataValue(e,r,n,s){console.error(`SetDataValue: Not implemented for ${this.constructor.name}`)}getSubData(e,r,n){return console.error(`GetDataValue: Not implemented for ${this.constructor.name}`),null}toString(){return`<${this.typeInfo.getTypeName()}>`}};Xt._id=0;var Zo=class extends Xt{constructor(e,r){super(e,r)}clone(){return this}toString(){return this.typeInfo.name}},ys=class extends Xt{constructor(){super(new it("void",null),null)}clone(){return this}toString(){return"void"}};ys.void=new ys;var Lr=class extends Xt{constructor(e){super(new fs("pointer",e.typeInfo,null),null),this.reference=e}clone(){return this}setDataValue(e,r,n,s){this.reference.setDataValue(e,r,n,s)}getSubData(e,r,n){return r?this.reference.getSubData(e,r,n):this}toString(){return`&${this.reference.toString()}`}},v=class t extends Xt{constructor(e,r,n=null){super(r,n),e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array?this.data=e:this.typeInfo.name==="x32"?e-Math.floor(e)!==0?this.data=new Float32Array([e]):this.data=e>=0?new Uint32Array([e]):new Int32Array([e]):this.typeInfo.name==="i32"||this.typeInfo.name==="bool"?this.data=new Int32Array([e]):this.typeInfo.name==="u32"?this.data=new Uint32Array([e]):this.typeInfo.name==="f32"||this.typeInfo.name==="f16"?this.data=new Float32Array([e]):console.error("ScalarData2: Invalid type",r)}clone(){if(this.data instanceof Float32Array)return new t(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new t(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new t(new Uint32Array(this.data),this.typeInfo,null);throw new Error("ScalarData: Invalid data type")}get value(){return this.data[0]}set value(e){this.data[0]=e}setDataValue(e,r,n,s){if(n)return void console.error("SetDataValue: Scalar data does not support postfix",n);if(!(r instanceof t))return void console.error("SetDataValue: Invalid value",r);let o=r.data[0];this.typeInfo.name==="i32"||this.typeInfo.name==="u32"?o=Math.floor(o):this.typeInfo.name==="bool"&&(o=o?1:0),this.data[0]=o}getSubData(e,r,n){return r?(console.error("getSubData: Scalar data does not support postfix",r),null):this}toString(){return`${this.value}`}};function Km(t,e,r){let n=e.length;return n===2?r==="f32"?new g(new Float32Array(e),t.getTypeInfo("vec2f")):r==="i32"||r==="bool"?new g(new Int32Array(e),t.getTypeInfo("vec2i")):r==="u32"?new g(new Uint32Array(e),t.getTypeInfo("vec2u")):r==="f16"?new g(new Float32Array(e),t.getTypeInfo("vec2h")):(console.error(`getSubData: Unknown format ${r}`),null):n===3?r==="f32"?new g(new Float32Array(e),t.getTypeInfo("vec3f")):r==="i32"||r==="bool"?new g(new Int32Array(e),t.getTypeInfo("vec3i")):r==="u32"?new g(new Uint32Array(e),t.getTypeInfo("vec3u")):r==="f16"?new g(new Float32Array(e),t.getTypeInfo("vec3h")):(console.error(`getSubData: Unknown format ${r}`),null):n===4?r==="f32"?new g(new Float32Array(e),t.getTypeInfo("vec4f")):r==="i32"||r==="bool"?new g(new Int32Array(e),t.getTypeInfo("vec4i")):r==="u32"?new g(new Uint32Array(e),t.getTypeInfo("vec4u")):r==="f16"?new g(new Float32Array(e),t.getTypeInfo("vec4h")):(console.error(`getSubData: Unknown format ${r}`),null):(console.error(`getSubData: Invalid vector size ${e.length}`),null)}var g=class t extends Xt{constructor(e,r,n=null){if(super(r,n),e instanceof Float32Array||e instanceof Uint32Array||e instanceof Int32Array)this.data=e;else{let s=this.typeInfo.name;s==="vec2f"||s==="vec3f"||s==="vec4f"?this.data=new Float32Array(e):s==="vec2i"||s==="vec3i"||s==="vec4i"?this.data=new Int32Array(e):s==="vec2u"||s==="vec3u"||s==="vec4u"?this.data=new Uint32Array(e):s==="vec2h"||s==="vec3h"||s==="vec4h"?this.data=new Float32Array(e):s==="vec2b"||s==="vec3b"||s==="vec4b"?this.data=new Int32Array(e):s==="vec2"||s==="vec3"||s==="vec4"?this.data=new Float32Array(e):console.error(`VectorData: Invalid type ${s}`)}}clone(){if(this.data instanceof Float32Array)return new t(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new t(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new t(new Uint32Array(this.data),this.typeInfo,null);throw new Error("VectorData: Invalid data type")}setDataValue(e,r,n,s){n instanceof yr?console.error("TODO: Set vector postfix"):r instanceof t?this.data=r.data:console.error("SetDataValue: Invalid value",r)}getSubData(e,r,n){if(r===null)return this;let s=e.getTypeInfo("f32");if(this.typeInfo instanceof gr)s=this.typeInfo.format||s;else{let a=this.typeInfo.name;a==="vec2f"||a==="vec3f"||a==="vec4f"?s=e.getTypeInfo("f32"):a==="vec2i"||a==="vec3i"||a==="vec4i"?s=e.getTypeInfo("i32"):a==="vec2b"||a==="vec3b"||a==="vec4b"?s=e.getTypeInfo("bool"):a==="vec2u"||a==="vec3u"||a==="vec4u"?s=e.getTypeInfo("u32"):a==="vec2h"||a==="vec3h"||a==="vec4h"?s=e.getTypeInfo("f16"):console.error(`GetSubData: Unknown type ${a}`)}let o=this;for(;r!==null&&o!==null;){if(r instanceof Or){let a=r.index,i=-1;if(a instanceof Fe){if(!(a.value instanceof v))return console.error(`GetSubData: Invalid array index ${a.value}`),null;i=a.value.value}else{let u=e.evalExpression(a,n);if(!(u instanceof v))return console.error("GetSubData: Unknown index type",a),null;i=u.value}if(i<0||i>=o.data.length)return console.error("GetSubData: Index out of range",i),null;if(o.data instanceof Float32Array){let u=new Float32Array(o.data.buffer,o.data.byteOffset+4*i,1);return new v(u,s)}if(o.data instanceof Int32Array){let u=new Int32Array(o.data.buffer,o.data.byteOffset+4*i,1);return new v(u,s)}if(o.data instanceof Uint32Array){let u=new Uint32Array(o.data.buffer,o.data.byteOffset+4*i,1);return new v(u,s)}throw new Error("GetSubData: Invalid data type")}if(!(r instanceof yr))return console.error("GetSubData: Unknown postfix",r),null;{let a=r.value.toLowerCase();if(a.length===1){let u=0;if(a==="x"||a==="r")u=0;else if(a==="y"||a==="g")u=1;else if(a==="z"||a==="b")u=2;else{if(a!=="w"&&a!=="a")return console.error(`GetSubData: Unknown member ${a}`),null;u=3}if(this.data instanceof Float32Array){let l=new Float32Array(this.data.buffer,this.data.byteOffset+4*u,1);return new v(l,s,this)}if(this.data instanceof Int32Array){let l=new Int32Array(this.data.buffer,this.data.byteOffset+4*u,1);return new v(l,s,this)}if(this.data instanceof Uint32Array){let l=new Uint32Array(this.data.buffer,this.data.byteOffset+4*u,1);return new v(l,s,this)}}let i=[];for(let u of a)u==="x"||u==="r"?i.push(this.data[0]):u==="y"||u==="g"?i.push(this.data[1]):u==="z"||u==="b"?i.push(this.data[2]):u==="w"||u==="a"?i.push(this.data[3]):console.error(`GetDataValue: Unknown member ${u}`);o=Km(e,i,s.name)}r=r.postfix}return o}toString(){let e=`${this.data[0]}`;for(let r=1;r<this.data.length;++r)e+=`, ${this.data[r]}`;return e}},H=class t extends Xt{constructor(e,r,n=null){super(r,n),e instanceof Float32Array?this.data=e:this.data=new Float32Array(e)}clone(){return new t(new Float32Array(this.data),this.typeInfo,null)}setDataValue(e,r,n,s){n instanceof yr?console.error("TODO: Set matrix postfix"):r instanceof t?this.data=r.data:console.error("SetDataValue: Invalid value",r)}getSubData(e,r,n){if(r===null)return this;let s=this.typeInfo.name;if(e.getTypeInfo("f32"),this.typeInfo instanceof gr)this.typeInfo.format;else if(s.endsWith("f"))e.getTypeInfo("f32");else if(s.endsWith("i"))e.getTypeInfo("i32");else if(s.endsWith("u"))e.getTypeInfo("u32");else{if(!s.endsWith("h"))return console.error(`GetDataValue: Unknown type ${s}`),null;e.getTypeInfo("f16")}if(r instanceof Or){let o=r.index,a=-1;if(o instanceof Fe){if(!(o.value instanceof v))return console.error(`GetDataValue: Invalid array index ${o.value}`),null;a=o.value.value}else{let l=e.evalExpression(o,n);if(!(l instanceof v))return console.error("GetDataValue: Unknown index type",o),null;a=l.value}if(a<0||a>=this.data.length)return console.error("GetDataValue: Index out of range",a),null;let i=s.endsWith("h")?"h":"f",u;if(s==="mat2x2"||s==="mat2x2f"||s==="mat2x2h"||s==="mat3x2"||s==="mat3x2f"||s==="mat3x2h"||s==="mat4x2"||s==="mat4x2f"||s==="mat4x2h")u=new g(new Float32Array(this.data.buffer,this.data.byteOffset+2*a*4,2),e.getTypeInfo(`vec2${i}`));else if(s==="mat2x3"||s==="mat2x3f"||s==="mat2x3h"||s==="mat3x3"||s==="mat3x3f"||s==="mat3x3h"||s==="mat4x3"||s==="mat4x3f"||s==="mat4x3h")u=new g(new Float32Array(this.data.buffer,this.data.byteOffset+3*a*4,3),e.getTypeInfo(`vec3${i}`));else{if(s!=="mat2x4"&&s!=="mat2x4f"&&s!=="mat2x4h"&&s!=="mat3x4"&&s!=="mat3x4f"&&s!=="mat3x4h"&&s!=="mat4x4"&&s!=="mat4x4f"&&s!=="mat4x4h")return console.error(`GetDataValue: Unknown type ${s}`),null;u=new g(new Float32Array(this.data.buffer,this.data.byteOffset+4*a*4,4),e.getTypeInfo(`vec4${i}`))}return r.postfix?u.getSubData(e,r.postfix,n):u}return console.error("GetDataValue: Invalid postfix",r),null}toString(){let e=`${this.data[0]}`;for(let r=1;r<this.data.length;++r)e+=`, ${this.data[r]}`;return e}},Ae=class t extends Xt{constructor(e,r,n=0,s=null){super(r,s),this.buffer=e instanceof ArrayBuffer?e:e.buffer,this.offset=n}clone(){let e=new Uint8Array(new Uint8Array(this.buffer,this.offset,this.typeInfo.size));return new t(e.buffer,this.typeInfo,0,null)}setDataValue(e,r,n,s){if(r===null)return void console.log("setDataValue: NULL data.");let o=this.offset,a=this.typeInfo;for(;n;){if(n instanceof Or)if(a instanceof or){let i=n.index;if(i instanceof Fe){if(!(i.value instanceof v))return void console.error(`SetDataValue: Invalid index type ${i.value}`);o+=i.value.value*a.stride}else{let u=e.evalExpression(i,s);if(!(u instanceof v))return void console.error("SetDataValue: Unknown index type",i);o+=u.value*a.stride}a=a.format}else console.error(`SetDataValue: Type ${a.getTypeName()} is not an array`);else{if(!(n instanceof yr))return void console.error("SetDataValue: Unknown postfix type",n);{let i=n.value;if(a instanceof sr){let u=!1;for(let l of a.members)if(l.name===i){o+=l.offset,a=l.type,u=!0;break}if(!u)return void console.error(`SetDataValue: Member ${i} not found`)}else if(a instanceof it){let u=a.getTypeName(),l=0;if(i==="x"||i==="r")l=0;else if(i==="y"||i==="g")l=1;else if(i==="z"||i==="b")l=2;else{if(i!=="w"&&i!=="a")return void console.error(`SetDataValue: Unknown member ${i}`);l=3}if(!(r instanceof v))return void console.error("SetDataValue: Invalid value",r);let c=r.value;return u==="vec2f"?void(new Float32Array(this.buffer,o,2)[l]=c):u==="vec3f"?void(new Float32Array(this.buffer,o,3)[l]=c):u==="vec4f"?void(new Float32Array(this.buffer,o,4)[l]=c):u==="vec2i"?void(new Int32Array(this.buffer,o,2)[l]=c):u==="vec3i"?void(new Int32Array(this.buffer,o,3)[l]=c):u==="vec4i"?void(new Int32Array(this.buffer,o,4)[l]=c):u==="vec2u"?void(new Uint32Array(this.buffer,o,2)[l]=c):u==="vec3u"?void(new Uint32Array(this.buffer,o,3)[l]=c):u==="vec4u"?void(new Uint32Array(this.buffer,o,4)[l]=c):void console.error(`SetDataValue: Type ${u} is not a struct`)}}}n=n.postfix}this.setData(e,r,a,o,s)}setData(e,r,n,s,o){let a=n.getTypeName();if(a!=="f32"&&a!=="f16")if(a!=="i32"&&a!=="atomic<i32>"&&a!=="x32")if(a!=="u32"&&a!=="atomic<u32>")if(a!=="bool"){if(a==="vec2f"||a==="vec2h"){let i=new Float32Array(this.buffer,s,2);return void(r instanceof g?(i[0]=r.data[0],i[1]=r.data[1]):(i[0]=r[0],i[1]=r[1]))}if(a==="vec3f"||a==="vec3h"){let i=new Float32Array(this.buffer,s,3);return void(r instanceof g?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2]):(i[0]=r[0],i[1]=r[1],i[2]=r[2]))}if(a==="vec4f"||a==="vec4h"){let i=new Float32Array(this.buffer,s,4);return void(r instanceof g?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3]))}if(a==="vec2i"){let i=new Int32Array(this.buffer,s,2);return void(r instanceof g?(i[0]=r.data[0],i[1]=r.data[1]):(i[0]=r[0],i[1]=r[1]))}if(a==="vec3i"){let i=new Int32Array(this.buffer,s,3);return void(r instanceof g?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2]):(i[0]=r[0],i[1]=r[1],i[2]=r[2]))}if(a==="vec4i"){let i=new Int32Array(this.buffer,s,4);return void(r instanceof g?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3]))}if(a==="vec2u"){let i=new Uint32Array(this.buffer,s,2);return void(r instanceof g?(i[0]=r.data[0],i[1]=r.data[1]):(i[0]=r[0],i[1]=r[1]))}if(a==="vec3u"){let i=new Uint32Array(this.buffer,s,3);return void(r instanceof g?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2]):(i[0]=r[0],i[1]=r[1],i[2]=r[2]))}if(a==="vec4u"){let i=new Uint32Array(this.buffer,s,4);return void(r instanceof g?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3]))}if(a==="vec2b"){let i=new Uint32Array(this.buffer,s,2);return void(r instanceof g?(i[0]=r.data[0],i[1]=r.data[1]):(i[0]=r[0],i[1]=r[1]))}if(a==="vec3b"){let i=new Uint32Array(this.buffer,s,3);return void(r instanceof g?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2]):(i[0]=r[0],i[1]=r[1],i[2]=r[2]))}if(a==="vec4b"){let i=new Uint32Array(this.buffer,s,4);return void(r instanceof g?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3]))}if(a==="mat2x2f"||a==="mat2x2h"){let i=new Float32Array(this.buffer,s,4);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3]))}if(a==="mat2x3f"||a==="mat2x3h"){let i=new Float32Array(this.buffer,s,6);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3],i[4]=r.data[4],i[5]=r.data[5]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],i[4]=r[4],i[5]=r[5]))}if(a==="mat2x4f"||a==="mat2x4h"){let i=new Float32Array(this.buffer,s,8);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3],i[4]=r.data[4],i[5]=r.data[5],i[6]=r.data[6],i[7]=r.data[7]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],i[4]=r[4],i[5]=r[5],i[6]=r[6],i[7]=r[7]))}if(a==="mat3x2f"||a==="mat3x2h"){let i=new Float32Array(this.buffer,s,6);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3],i[4]=r.data[4],i[5]=r.data[5]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],i[4]=r[4],i[5]=r[5]))}if(a==="mat3x3f"||a==="mat3x3h"){let i=new Float32Array(this.buffer,s,9);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3],i[4]=r.data[4],i[5]=r.data[5],i[6]=r.data[6],i[7]=r.data[7],i[8]=r.data[8]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],i[4]=r[4],i[5]=r[5],i[6]=r[6],i[7]=r[7],i[8]=r[8]))}if(a==="mat3x4f"||a==="mat3x4h"){let i=new Float32Array(this.buffer,s,12);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3],i[4]=r.data[4],i[5]=r.data[5],i[6]=r.data[6],i[7]=r.data[7],i[8]=r.data[8],i[9]=r.data[9],i[10]=r.data[10],i[11]=r.data[11]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],i[4]=r[4],i[5]=r[5],i[6]=r[6],i[7]=r[7],i[8]=r[8],i[9]=r[9],i[10]=r[10],i[11]=r[11]))}if(a==="mat4x2f"||a==="mat4x2h"){let i=new Float32Array(this.buffer,s,8);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3],i[4]=r.data[4],i[5]=r.data[5],i[6]=r.data[6],i[7]=r.data[7]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],i[4]=r[4],i[5]=r[5],i[6]=r[6],i[7]=r[7]))}if(a==="mat4x3f"||a==="mat4x3h"){let i=new Float32Array(this.buffer,s,12);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3],i[4]=r.data[4],i[5]=r.data[5],i[6]=r.data[6],i[7]=r.data[7],i[8]=r.data[8],i[9]=r.data[9],i[10]=r.data[10],i[11]=r.data[11]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],i[4]=r[4],i[5]=r[5],i[6]=r[6],i[7]=r[7],i[8]=r[8],i[9]=r[9],i[10]=r[10],i[11]=r[11]))}if(a==="mat4x4f"||a==="mat4x4h"){let i=new Float32Array(this.buffer,s,16);return void(r instanceof H?(i[0]=r.data[0],i[1]=r.data[1],i[2]=r.data[2],i[3]=r.data[3],i[4]=r.data[4],i[5]=r.data[5],i[6]=r.data[6],i[7]=r.data[7],i[8]=r.data[8],i[9]=r.data[9],i[10]=r.data[10],i[11]=r.data[11],i[12]=r.data[12],i[13]=r.data[13],i[14]=r.data[14],i[15]=r.data[15]):(i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],i[4]=r[4],i[5]=r[5],i[6]=r[6],i[7]=r[7],i[8]=r[8],i[9]=r[9],i[10]=r[10],i[11]=r[11],i[12]=r[12],i[13]=r[13],i[14]=r[14],i[15]=r[15]))}if(r instanceof t){if(n===r.typeInfo)return void new Uint8Array(this.buffer,s,r.buffer.byteLength).set(new Uint8Array(r.buffer));console.error("SetDataValue: Type mismatch",a,r.typeInfo.getTypeName())}else console.error(`SetData: Unknown type ${a}`)}else r instanceof v&&(new Int32Array(this.buffer,s,1)[0]=r.value);else r instanceof v&&(new Uint32Array(this.buffer,s,1)[0]=r.value);else r instanceof v&&(new Int32Array(this.buffer,s,1)[0]=r.value);else r instanceof v&&(new Float32Array(this.buffer,s,1)[0]=r.value)}getSubData(e,r,n){var s,o,a;if(r===null)return this;let i=this.offset,u=this.typeInfo;for(;r;){if(r instanceof Or){let c=r.index,f=c instanceof vt?e.evalExpression(c,n):c,d=0;if(f instanceof v?d=f.value:typeof f=="number"?d=f:console.error("GetDataValue: Invalid index type",c),u instanceof or)i+=d*u.stride,u=u.format;else{let p=u.getTypeName();p==="mat4x4"||p==="mat4x4f"||p==="mat4x4h"?(i+=16*d,u=e.getTypeInfo("vec4f")):p==="mat4x3"||p==="mat4x3f"||p==="mat4x3h"?(i+=12*d,u=e.getTypeInfo("vec3f")):p==="mat4x2"||p==="mat4x2f"||p==="mat4x2h"?(i+=8*d,u=e.getTypeInfo("vec2f")):p==="mat3x4"||p==="mat3x4f"||p==="mat3x4h"?(i+=12*d,u=e.getTypeInfo("vec4f")):p==="mat3x3"||p==="mat3x3f"||p==="mat3x3h"?(i+=9*d,u=e.getTypeInfo("vec3f")):p==="mat3x2"||p==="mat3x2f"||p==="mat3x2h"?(i+=6*d,u=e.getTypeInfo("vec2f")):p==="mat2x4"||p==="mat2x4f"||p==="mat2x4h"?(i+=8*d,u=e.getTypeInfo("vec4f")):p==="mat2x3"||p==="mat2x3f"||p==="mat2x3h"?(i+=6*d,u=e.getTypeInfo("vec3f")):p==="mat2x2"||p==="mat2x2f"||p==="mat2x2h"?(i+=4*d,u=e.getTypeInfo("vec2f")):p==="vec2f"||p==="vec3f"||p==="vec4f"?(i+=4*d,u=e.getTypeInfo("f32")):p==="vec2h"||p==="vec3h"||p==="vec4h"?(i+=2*d,u=e.getTypeInfo("f16")):p==="vec2b"||p==="vec3b"||p==="vec4b"?(i+=1*d,u=e.getTypeInfo("bool")):p==="vec2i"||p==="vec3i"||p==="vec4i"?(i+=4*d,u=e.getTypeInfo("i32")):p==="vec2u"||p==="vec3u"||p==="vec4u"?(i+=4*d,u=e.getTypeInfo("u32")):console.error(`getDataValue: Type ${u.getTypeName()} is not an array`)}}else{if(!(r instanceof yr))return console.error("GetDataValue: Unknown postfix type",r),null;{let c=r.value;if(u instanceof sr){let f=!1;for(let d of u.members)if(d.name===c){i+=d.offset,u=d.type,f=!0;break}if(!f)return console.error(`GetDataValue: Member ${c} not found`),null}else if(u instanceof it){let f=u.getTypeName();if(f==="vec2f"||f==="vec3f"||f==="vec4f"||f==="vec2i"||f==="vec3i"||f==="vec4i"||f==="vec2u"||f==="vec3u"||f==="vec4u"||f==="vec2b"||f==="vec3b"||f==="vec4b"||f==="vec2h"||f==="vec3h"||f==="vec4h"||f==="vec2"||f==="vec3"||f==="vec4"){if(c.length>0&&c.length<5){let d="f",p=[];for(let b=0;b<c.length;++b){let E=c[b].toLowerCase(),A=0;if(E==="x"||E==="r")A=0;else if(E==="y"||E==="g")A=1;else if(E==="z"||E==="b")A=2;else{if(E!=="w"&&E!=="a")return console.error(`Unknown member ${c}`),null;A=3}if(c.length===1){if(f.endsWith("f"))return this.buffer.byteLength<i+4*A+4?(console.log("Insufficient buffer data"),null):new v(new Float32Array(this.buffer,i+4*A,1),e.getTypeInfo("f32"),this);if(f.endsWith("h"))return new v(new Float32Array(this.buffer,i+4*A,1),e.getTypeInfo("f16"),this);if(f.endsWith("i"))return new v(new Int32Array(this.buffer,i+4*A,1),e.getTypeInfo("i32"),this);if(f.endsWith("b"))return new v(new Int32Array(this.buffer,i+4*A,1),e.getTypeInfo("bool"),this);if(f.endsWith("u"))return new v(new Uint32Array(this.buffer,i+4*A,1),e.getTypeInfo("i32"),this)}if(f==="vec2f")p.push(new Float32Array(this.buffer,i,2)[A]);else if(f==="vec3f"){if(i+12>=this.buffer.byteLength)return console.log("Insufficient buffer data"),null;let I=new Float32Array(this.buffer,i,3);p.push(I[A])}else if(f==="vec4f")p.push(new Float32Array(this.buffer,i,4)[A]);else if(f==="vec2i")d="i",p.push(new Int32Array(this.buffer,i,2)[A]);else if(f==="vec3i")d="i",p.push(new Int32Array(this.buffer,i,3)[A]);else if(f==="vec4i")d="i",p.push(new Int32Array(this.buffer,i,4)[A]);else if(f==="vec2u"){d="u";let I=new Uint32Array(this.buffer,i,2);p.push(I[A])}else f==="vec3u"?(d="u",p.push(new Uint32Array(this.buffer,i,3)[A])):f==="vec4u"&&(d="u",p.push(new Uint32Array(this.buffer,i,4)[A]))}return p.length===2?u=e.getTypeInfo(`vec2${d}`):p.length===3?u=e.getTypeInfo(`vec3${d}`):p.length===4?u=e.getTypeInfo(`vec4${d}`):console.error(`GetDataValue: Invalid vector length ${p.length}`),new g(p,u,null)}return console.error(`GetDataValue: Unknown member ${c}`),null}return console.error(`GetDataValue: Type ${f} is not a struct`),null}}}r=r.postfix}let l=u.getTypeName();return l==="f32"?new v(new Float32Array(this.buffer,i,1),u,this):l==="i32"?new v(new Int32Array(this.buffer,i,1),u,this):l==="u32"?new v(new Uint32Array(this.buffer,i,1),u,this):l==="vec2f"?new g(new Float32Array(this.buffer,i,2),u,this):l==="vec3f"?new g(new Float32Array(this.buffer,i,3),u,this):l==="vec4f"?new g(new Float32Array(this.buffer,i,4),u,this):l==="vec2i"?new g(new Int32Array(this.buffer,i,2),u,this):l==="vec3i"?new g(new Int32Array(this.buffer,i,3),u,this):l==="vec4i"?new g(new Int32Array(this.buffer,i,4),u,this):l==="vec2u"?new g(new Uint32Array(this.buffer,i,2),u,this):l==="vec3u"?new g(new Uint32Array(this.buffer,i,3),u,this):l==="vec4u"?new g(new Uint32Array(this.buffer,i,4),u,this):u instanceof gr&&u.name==="atomic"?((s=u.format)===null||s===void 0?void 0:s.name)==="u32"?new v(new Uint32Array(this.buffer,i,1)[0],u.format,this):((o=u.format)===null||o===void 0?void 0:o.name)==="i32"?new v(new Int32Array(this.buffer,i,1)[0],u.format,this):(console.error(`GetDataValue: Invalid atomic format ${(a=u.format)===null||a===void 0?void 0:a.name}`),null):new t(this.buffer,u,i,this)}toArray(){let e=this.typeInfo.getTypeName();return e==="f32"||e==="f16"?new Float32Array(this.buffer,this.offset,1):e==="i32"||e==="atomic<i32>"||e==="x32"?new Int32Array(this.buffer,this.offset,1):e==="u32"||e==="atomic<u32>"?new Uint32Array(this.buffer,this.offset,1):e==="bool"?new Int32Array(this.buffer,this.offset,1):e==="vec2f"||e==="vec2h"?new Float32Array(this.buffer,this.offset,2):e==="vec3f"||e==="vec3h"?new Float32Array(this.buffer,this.offset,3):e==="vec4f"||e==="vec4h"?new Float32Array(this.buffer,this.offset,4):e==="vec2i"?new Int32Array(this.buffer,this.offset,2):e==="vec3i"?new Int32Array(this.buffer,this.offset,3):e==="vec4i"?new Int32Array(this.buffer,this.offset,4):e==="vec2u"?new Uint32Array(this.buffer,this.offset,2):e==="vec3u"?new Uint32Array(this.buffer,this.offset,3):e==="vec4u"?new Uint32Array(this.buffer,this.offset,4):e==="vec2b"?new Uint32Array(this.buffer,this.offset,2):e==="vec3b"?new Uint32Array(this.buffer,this.offset,3):e==="vec4b"?new Uint32Array(this.buffer,this.offset,4):e==="mat2x2f"||e==="mat2x2h"?new Float32Array(this.buffer,this.offset,4):e==="mat2x3f"||e==="mat2x3h"?new Float32Array(this.buffer,this.offset,6):e==="mat2x4f"||e==="mat2x4h"?new Float32Array(this.buffer,this.offset,8):e==="mat3x2f"||e==="mat3x2h"?new Float32Array(this.buffer,this.offset,6):e==="mat3x3f"||e==="mat3x3h"?new Float32Array(this.buffer,this.offset,9):e==="mat3x4f"||e==="mat3x4h"?new Float32Array(this.buffer,this.offset,12):e==="mat4x2f"||e==="mat4x2h"?new Float32Array(this.buffer,this.offset,8):e==="mat4x3f"||e==="mat4x3h"?new Float32Array(this.buffer,this.offset,12):e==="mat4x4f"||e==="mat4x4h"?new Float32Array(this.buffer,this.offset,16):null}toString(){let e="";if(this.typeInfo instanceof or)if(this.typeInfo.format.name==="f32"){let r=new Float32Array(this.buffer,this.offset);e=`[${r[0]}`;for(let n=1;n<r.length;++n)e+=`, ${r[n]}`}else if(this.typeInfo.format.name==="i32"){let r=new Int32Array(this.buffer,this.offset);e=`[${r[0]}`;for(let n=1;n<r.length;++n)e+=`, ${r[n]}`}else if(this.typeInfo.format.name==="u32"){let r=new Uint32Array(this.buffer,this.offset);e=`[${r[0]}`;for(let n=1;n<r.length;++n)e+=`, ${r[n]}`}else if(this.typeInfo.format.name==="vec2f"){let r=new Float32Array(this.buffer,this.offset);e=`[${r[0]}, ${r[1]}]`;for(let n=1;n<r.length/2;++n)e+=`, [${r[2*n]}, ${r[2*n+1]}]`}else if(this.typeInfo.format.name==="vec3f"){let r=new Float32Array(this.buffer,this.offset);e=`[${r[0]}, ${r[1]}, ${r[2]}]`;for(let n=4;n<r.length;n+=4)e+=`, [${r[n]}, ${r[n+1]}, ${r[n+2]}]`}else if(this.typeInfo.format.name==="vec4f"){let r=new Float32Array(this.buffer,this.offset);e=`[${r[0]}, ${r[1]}, ${r[2]}, ${r[3]}]`;for(let n=4;n<r.length;n+=4)e+=`, [${r[n]}, ${r[n+1]}, ${r[n+2]}, ${r[n+3]}]`}else e="[...]";else this.typeInfo instanceof sr?e+="{...}":e="[...]";return e}},mr=class t extends Xt{constructor(e,r,n,s){super(r,null),this.data=e,this.descriptor=n,this.view=s}clone(){return new t(this.data,this.typeInfo,this.descriptor,this.view)}get width(){var e,r;let n=this.descriptor.size;return n instanceof Array&&n.length>0?(e=n[0])!==null&&e!==void 0?e:0:n instanceof Object&&(r=n.width)!==null&&r!==void 0?r:0}get height(){var e,r;let n=this.descriptor.size;return n instanceof Array&&n.length>1?(e=n[1])!==null&&e!==void 0?e:0:n instanceof Object&&(r=n.height)!==null&&r!==void 0?r:0}get depthOrArrayLayers(){var e,r;let n=this.descriptor.size;return n instanceof Array&&n.length>2?(e=n[2])!==null&&e!==void 0?e:0:n instanceof Object&&(r=n.depthOrArrayLayers)!==null&&r!==void 0?r:0}get format(){var e;return this.descriptor&&(e=this.descriptor.format)!==null&&e!==void 0?e:"rgba8unorm"}get sampleCount(){var e;return this.descriptor&&(e=this.descriptor.sampleCount)!==null&&e!==void 0?e:1}get mipLevelCount(){var e;return this.descriptor&&(e=this.descriptor.mipLevelCount)!==null&&e!==void 0?e:1}get dimension(){var e;return this.descriptor&&(e=this.descriptor.dimension)!==null&&e!==void 0?e:"2d"}getMipLevelSize(e){if(e>=this.mipLevelCount)return[0,0,0];let r=[this.width,this.height,this.depthOrArrayLayers];for(let n=0;n<r.length;++n)r[n]=Math.max(1,r[n]>>e);return r}get texelByteSize(){let e=this.format,r=nu[e];return r?r.isDepthStencil?4:r.bytesPerBlock:0}get bytesPerRow(){return this.width*this.texelByteSize}get isDepthStencil(){let e=this.format,r=nu[e];return!!r&&r.isDepthStencil}getGpuSize(){let e=this.format,r=nu[e],n=this.width;if(!e||n<=0||!r)return-1;let s=this.height,o=this.depthOrArrayLayers,a=this.dimension;return n/r.blockWidth*(a==="1d"?1:s/r.blockHeight)*r.bytesPerBlock*o}getPixel(e,r,n=0,s=0){let o=this.texelByteSize,a=this.bytesPerRow,i=this.height,u=this.data[s];return qm(new Uint8Array(u),e,r,n,s,i,a,o,this.format)}setPixel(e,r,n,s,o){let a=this.texelByteSize,i=this.bytesPerRow,u=this.height,l=this.data[s];(function(c,f,d,p,b,E,A,I,_,T){let R=p*(A>>=b)*(E>>=b)+d*A+f*I;switch(_){case"r8unorm":return void te(c,R,"8unorm",1,T);case"r8snorm":return void te(c,R,"8snorm",1,T);case"r8uint":return void te(c,R,"8uint",1,T);case"r8sint":return void te(c,R,"8sint",1,T);case"rg8unorm":return void te(c,R,"8unorm",2,T);case"rg8snorm":return void te(c,R,"8snorm",2,T);case"rg8uint":return void te(c,R,"8uint",2,T);case"rg8sint":return void te(c,R,"8sint",2,T);case"rgba8unorm-srgb":case"rgba8unorm":case"bgra8unorm-srgb":case"bgra8unorm":return void te(c,R,"8unorm",4,T);case"rgba8snorm":return void te(c,R,"8snorm",4,T);case"rgba8uint":return void te(c,R,"8uint",4,T);case"rgba8sint":return void te(c,R,"8sint",4,T);case"r16uint":return void te(c,R,"16uint",1,T);case"r16sint":return void te(c,R,"16sint",1,T);case"r16float":return void te(c,R,"16float",1,T);case"rg16uint":return void te(c,R,"16uint",2,T);case"rg16sint":return void te(c,R,"16sint",2,T);case"rg16float":return void te(c,R,"16float",2,T);case"rgba16uint":return void te(c,R,"16uint",4,T);case"rgba16sint":return void te(c,R,"16sint",4,T);case"rgba16float":return void te(c,R,"16float",4,T);case"r32uint":return void te(c,R,"32uint",1,T);case"r32sint":return void te(c,R,"32sint",1,T);case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return void te(c,R,"32float",1,T);case"rg32uint":return void te(c,R,"32uint",2,T);case"rg32sint":return void te(c,R,"32sint",2,T);case"rg32float":return void te(c,R,"32float",2,T);case"rgba32uint":return void te(c,R,"32uint",4,T);case"rgba32sint":return void te(c,R,"32sint",4,T);case"rgba32float":return void te(c,R,"32float",4,T);case"rg11b10ufloat":console.error("TODO: rg11b10ufloat not supported for writing")}})(new Uint8Array(l),e,r,n,s,u,i,a,this.format,o)}};(t=>{t[t.token=0]="token",t[t.keyword=1]="keyword",t[t.reserved=2]="reserved"})(x||(x={}));var y=class{constructor(e,r,n){this.name=e,this.type=r,this.rule=n}toString(){return this.name}},h=class{};k=h,h.none=new y("",x.reserved,""),h.eof=new y("EOF",x.token,""),h.reserved={asm:new y("asm",x.reserved,"asm"),bf16:new y("bf16",x.reserved,"bf16"),do:new y("do",x.reserved,"do"),enum:new y("enum",x.reserved,"enum"),f16:new y("f16",x.reserved,"f16"),f64:new y("f64",x.reserved,"f64"),handle:new y("handle",x.reserved,"handle"),i8:new y("i8",x.reserved,"i8"),i16:new y("i16",x.reserved,"i16"),i64:new y("i64",x.reserved,"i64"),mat:new y("mat",x.reserved,"mat"),premerge:new y("premerge",x.reserved,"premerge"),regardless:new y("regardless",x.reserved,"regardless"),typedef:new y("typedef",x.reserved,"typedef"),u8:new y("u8",x.reserved,"u8"),u16:new y("u16",x.reserved,"u16"),u64:new y("u64",x.reserved,"u64"),unless:new y("unless",x.reserved,"unless"),using:new y("using",x.reserved,"using"),vec:new y("vec",x.reserved,"vec"),void:new y("void",x.reserved,"void")},h.keywords={array:new y("array",x.keyword,"array"),atomic:new y("atomic",x.keyword,"atomic"),bool:new y("bool",x.keyword,"bool"),f32:new y("f32",x.keyword,"f32"),i32:new y("i32",x.keyword,"i32"),mat2x2:new y("mat2x2",x.keyword,"mat2x2"),mat2x3:new y("mat2x3",x.keyword,"mat2x3"),mat2x4:new y("mat2x4",x.keyword,"mat2x4"),mat3x2:new y("mat3x2",x.keyword,"mat3x2"),mat3x3:new y("mat3x3",x.keyword,"mat3x3"),mat3x4:new y("mat3x4",x.keyword,"mat3x4"),mat4x2:new y("mat4x2",x.keyword,"mat4x2"),mat4x3:new y("mat4x3",x.keyword,"mat4x3"),mat4x4:new y("mat4x4",x.keyword,"mat4x4"),ptr:new y("ptr",x.keyword,"ptr"),sampler:new y("sampler",x.keyword,"sampler"),sampler_comparison:new y("sampler_comparison",x.keyword,"sampler_comparison"),struct:new y("struct",x.keyword,"struct"),texture_1d:new y("texture_1d",x.keyword,"texture_1d"),texture_2d:new y("texture_2d",x.keyword,"texture_2d"),texture_2d_array:new y("texture_2d_array",x.keyword,"texture_2d_array"),texture_3d:new y("texture_3d",x.keyword,"texture_3d"),texture_cube:new y("texture_cube",x.keyword,"texture_cube"),texture_cube_array:new y("texture_cube_array",x.keyword,"texture_cube_array"),texture_multisampled_2d:new y("texture_multisampled_2d",x.keyword,"texture_multisampled_2d"),texture_storage_1d:new y("texture_storage_1d",x.keyword,"texture_storage_1d"),texture_storage_2d:new y("texture_storage_2d",x.keyword,"texture_storage_2d"),texture_storage_2d_array:new y("texture_storage_2d_array",x.keyword,"texture_storage_2d_array"),texture_storage_3d:new y("texture_storage_3d",x.keyword,"texture_storage_3d"),texture_depth_2d:new y("texture_depth_2d",x.keyword,"texture_depth_2d"),texture_depth_2d_array:new y("texture_depth_2d_array",x.keyword,"texture_depth_2d_array"),texture_depth_cube:new y("texture_depth_cube",x.keyword,"texture_depth_cube"),texture_depth_cube_array:new y("texture_depth_cube_array",x.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new y("texture_depth_multisampled_2d",x.keyword,"texture_depth_multisampled_2d"),texture_external:new y("texture_external",x.keyword,"texture_external"),u32:new y("u32",x.keyword,"u32"),vec2:new y("vec2",x.keyword,"vec2"),vec3:new y("vec3",x.keyword,"vec3"),vec4:new y("vec4",x.keyword,"vec4"),bitcast:new y("bitcast",x.keyword,"bitcast"),block:new y("block",x.keyword,"block"),break:new y("break",x.keyword,"break"),case:new y("case",x.keyword,"case"),continue:new y("continue",x.keyword,"continue"),continuing:new y("continuing",x.keyword,"continuing"),default:new y("default",x.keyword,"default"),diagnostic:new y("diagnostic",x.keyword,"diagnostic"),discard:new y("discard",x.keyword,"discard"),else:new y("else",x.keyword,"else"),enable:new y("enable",x.keyword,"enable"),fallthrough:new y("fallthrough",x.keyword,"fallthrough"),false:new y("false",x.keyword,"false"),fn:new y("fn",x.keyword,"fn"),for:new y("for",x.keyword,"for"),function:new y("function",x.keyword,"function"),if:new y("if",x.keyword,"if"),let:new y("let",x.keyword,"let"),const:new y("const",x.keyword,"const"),loop:new y("loop",x.keyword,"loop"),while:new y("while",x.keyword,"while"),private:new y("private",x.keyword,"private"),read:new y("read",x.keyword,"read"),read_write:new y("read_write",x.keyword,"read_write"),return:new y("return",x.keyword,"return"),requires:new y("requires",x.keyword,"requires"),storage:new y("storage",x.keyword,"storage"),immediate:new y("immediate",x.keyword,"immediate"),switch:new y("switch",x.keyword,"switch"),true:new y("true",x.keyword,"true"),alias:new y("alias",x.keyword,"alias"),type:new y("type",x.keyword,"type"),uniform:new y("uniform",x.keyword,"uniform"),var:new y("var",x.keyword,"var"),override:new y("override",x.keyword,"override"),workgroup:new y("workgroup",x.keyword,"workgroup"),write:new y("write",x.keyword,"write"),r8unorm:new y("r8unorm",x.keyword,"r8unorm"),r8snorm:new y("r8snorm",x.keyword,"r8snorm"),r8uint:new y("r8uint",x.keyword,"r8uint"),r8sint:new y("r8sint",x.keyword,"r8sint"),r16uint:new y("r16uint",x.keyword,"r16uint"),r16sint:new y("r16sint",x.keyword,"r16sint"),r16float:new y("r16float",x.keyword,"r16float"),rg8unorm:new y("rg8unorm",x.keyword,"rg8unorm"),rg8snorm:new y("rg8snorm",x.keyword,"rg8snorm"),rg8uint:new y("rg8uint",x.keyword,"rg8uint"),rg8sint:new y("rg8sint",x.keyword,"rg8sint"),r32uint:new y("r32uint",x.keyword,"r32uint"),r32sint:new y("r32sint",x.keyword,"r32sint"),r32float:new y("r32float",x.keyword,"r32float"),rg16uint:new y("rg16uint",x.keyword,"rg16uint"),rg16sint:new y("rg16sint",x.keyword,"rg16sint"),rg16float:new y("rg16float",x.keyword,"rg16float"),rgba8unorm:new y("rgba8unorm",x.keyword,"rgba8unorm"),rgba8unorm_srgb:new y("rgba8unorm_srgb",x.keyword,"rgba8unorm_srgb"),rgba8snorm:new y("rgba8snorm",x.keyword,"rgba8snorm"),rgba8uint:new y("rgba8uint",x.keyword,"rgba8uint"),rgba8sint:new y("rgba8sint",x.keyword,"rgba8sint"),bgra8unorm:new y("bgra8unorm",x.keyword,"bgra8unorm"),bgra8unorm_srgb:new y("bgra8unorm_srgb",x.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new y("rgb10a2unorm",x.keyword,"rgb10a2unorm"),rg11b10float:new y("rg11b10float",x.keyword,"rg11b10float"),rg32uint:new y("rg32uint",x.keyword,"rg32uint"),rg32sint:new y("rg32sint",x.keyword,"rg32sint"),rg32float:new y("rg32float",x.keyword,"rg32float"),rgba16uint:new y("rgba16uint",x.keyword,"rgba16uint"),rgba16sint:new y("rgba16sint",x.keyword,"rgba16sint"),rgba16float:new y("rgba16float",x.keyword,"rgba16float"),rgba32uint:new y("rgba32uint",x.keyword,"rgba32uint"),rgba32sint:new y("rgba32sint",x.keyword,"rgba32sint"),rgba32float:new y("rgba32float",x.keyword,"rgba32float"),static_assert:new y("static_assert",x.keyword,"static_assert"),const_assert:new y("const_assert",x.keyword,"const_assert")},h.tokens={decimal_float_literal:new y("decimal_float_literal",x.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 y("hex_float_literal",x.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 y("int_literal",x.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new y("uint_literal",x.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),name:new y("name",x.token,/([_\p{XID_Start}][\p{XID_Continue}]+)|([\p{XID_Start}])/u),ident:new y("ident",x.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new y("and",x.token,"&"),and_and:new y("and_and",x.token,"&&"),arrow:new y("arrow ",x.token,"->"),attr:new y("attr",x.token,"@"),forward_slash:new y("forward_slash",x.token,"/"),bang:new y("bang",x.token,"!"),bracket_left:new y("bracket_left",x.token,"["),bracket_right:new y("bracket_right",x.token,"]"),brace_left:new y("brace_left",x.token,"{"),brace_right:new y("brace_right",x.token,"}"),colon:new y("colon",x.token,":"),comma:new y("comma",x.token,","),equal:new y("equal",x.token,"="),equal_equal:new y("equal_equal",x.token,"=="),not_equal:new y("not_equal",x.token,"!="),greater_than:new y("greater_than",x.token,">"),greater_than_equal:new y("greater_than_equal",x.token,">="),shift_right:new y("shift_right",x.token,">>"),less_than:new y("less_than",x.token,"<"),less_than_equal:new y("less_than_equal",x.token,"<="),shift_left:new y("shift_left",x.token,"<<"),modulo:new y("modulo",x.token,"%"),minus:new y("minus",x.token,"-"),minus_minus:new y("minus_minus",x.token,"--"),period:new y("period",x.token,"."),plus:new y("plus",x.token,"+"),plus_plus:new y("plus_plus",x.token,"++"),or:new y("or",x.token,"|"),or_or:new y("or_or",x.token,"||"),paren_left:new y("paren_left",x.token,"("),paren_right:new y("paren_right",x.token,")"),semicolon:new y("semicolon",x.token,";"),star:new y("star",x.token,"*"),tilde:new y("tilde",x.token,"~"),underscore:new y("underscore",x.token,"_"),xor:new y("xor",x.token,"^"),plus_equal:new y("plus_equal",x.token,"+="),minus_equal:new y("minus_equal",x.token,"-="),times_equal:new y("times_equal",x.token,"*="),division_equal:new y("division_equal",x.token,"/="),modulo_equal:new y("modulo_equal",x.token,"%="),and_equal:new y("and_equal",x.token,"&="),or_equal:new y("or_equal",x.token,"|="),xor_equal:new y("xor_equal",x.token,"^="),shift_right_equal:new y("shift_right_equal",x.token,">>="),shift_left_equal:new y("shift_left_equal",x.token,"<<=")},h.simpleTokens={"@":k.tokens.attr,"{":k.tokens.brace_left,"}":k.tokens.brace_right,":":k.tokens.colon,",":k.tokens.comma,"(":k.tokens.paren_left,")":k.tokens.paren_right,";":k.tokens.semicolon},h.literalTokens={"&":k.tokens.and,"&&":k.tokens.and_and,"->":k.tokens.arrow,"/":k.tokens.forward_slash,"!":k.tokens.bang,"[":k.tokens.bracket_left,"]":k.tokens.bracket_right,"=":k.tokens.equal,"==":k.tokens.equal_equal,"!=":k.tokens.not_equal,">":k.tokens.greater_than,">=":k.tokens.greater_than_equal,">>":k.tokens.shift_right,"<":k.tokens.less_than,"<=":k.tokens.less_than_equal,"<<":k.tokens.shift_left,"%":k.tokens.modulo,"-":k.tokens.minus,"--":k.tokens.minus_minus,".":k.tokens.period,"+":k.tokens.plus,"++":k.tokens.plus_plus,"|":k.tokens.or,"||":k.tokens.or_or,"*":k.tokens.star,"~":k.tokens.tilde,_:k.tokens.underscore,"^":k.tokens.xor,"+=":k.tokens.plus_equal,"-=":k.tokens.minus_equal,"*=":k.tokens.times_equal,"/=":k.tokens.division_equal,"%=":k.tokens.modulo_equal,"&=":k.tokens.and_equal,"|=":k.tokens.or_equal,"^=":k.tokens.xor_equal,">>=":k.tokens.shift_right_equal,"<<=":k.tokens.shift_left_equal},h.regexTokens={decimal_float_literal:k.tokens.decimal_float_literal,hex_float_literal:k.tokens.hex_float_literal,int_literal:k.tokens.int_literal,uint_literal:k.tokens.uint_literal,ident:k.tokens.ident},h.storage_class=[k.keywords.function,k.keywords.private,k.keywords.workgroup,k.keywords.uniform,k.keywords.storage,k.keywords.immediate],h.access_mode=[k.keywords.read,k.keywords.write,k.keywords.read_write],h.sampler_type=[k.keywords.sampler,k.keywords.sampler_comparison],h.sampled_texture_type=[k.keywords.texture_1d,k.keywords.texture_2d,k.keywords.texture_2d_array,k.keywords.texture_3d,k.keywords.texture_cube,k.keywords.texture_cube_array],h.multisampled_texture_type=[k.keywords.texture_multisampled_2d],h.storage_texture_type=[k.keywords.texture_storage_1d,k.keywords.texture_storage_2d,k.keywords.texture_storage_2d_array,k.keywords.texture_storage_3d],h.depth_texture_type=[k.keywords.texture_depth_2d,k.keywords.texture_depth_2d_array,k.keywords.texture_depth_cube,k.keywords.texture_depth_cube_array,k.keywords.texture_depth_multisampled_2d],h.texture_external_type=[k.keywords.texture_external],h.any_texture_type=[...k.sampled_texture_type,...k.multisampled_texture_type,...k.storage_texture_type,...k.depth_texture_type,...k.texture_external_type],h.texel_format=[k.keywords.r8unorm,k.keywords.r8snorm,k.keywords.r8uint,k.keywords.r8sint,k.keywords.r16uint,k.keywords.r16sint,k.keywords.r16float,k.keywords.rg8unorm,k.keywords.rg8snorm,k.keywords.rg8uint,k.keywords.rg8sint,k.keywords.r32uint,k.keywords.r32sint,k.keywords.r32float,k.keywords.rg16uint,k.keywords.rg16sint,k.keywords.rg16float,k.keywords.rgba8unorm,k.keywords.rgba8unorm_srgb,k.keywords.rgba8snorm,k.keywords.rgba8uint,k.keywords.rgba8sint,k.keywords.bgra8unorm,k.keywords.bgra8unorm_srgb,k.keywords.rgb10a2unorm,k.keywords.rg11b10float,k.keywords.rg32uint,k.keywords.rg32sint,k.keywords.rg32float,k.keywords.rgba16uint,k.keywords.rgba16sint,k.keywords.rgba16float,k.keywords.rgba32uint,k.keywords.rgba32sint,k.keywords.rgba32float],h.const_literal=[k.tokens.int_literal,k.tokens.uint_literal,k.tokens.decimal_float_literal,k.tokens.hex_float_literal,k.keywords.true,k.keywords.false],h.literal_or_ident=[k.tokens.ident,k.tokens.int_literal,k.tokens.uint_literal,k.tokens.decimal_float_literal,k.tokens.hex_float_literal,k.tokens.name],h.element_count_expression=[k.tokens.int_literal,k.tokens.uint_literal,k.tokens.ident],h.template_types=[k.keywords.vec2,k.keywords.vec3,k.keywords.vec4,k.keywords.mat2x2,k.keywords.mat2x3,k.keywords.mat2x4,k.keywords.mat3x2,k.keywords.mat3x3,k.keywords.mat3x4,k.keywords.mat4x2,k.keywords.mat4x3,k.keywords.mat4x4,k.keywords.atomic,k.keywords.bitcast,...k.any_texture_type],h.attribute_name=[k.tokens.ident,k.keywords.block,k.keywords.diagnostic],h.assignment_operators=[k.tokens.equal,k.tokens.plus_equal,k.tokens.minus_equal,k.tokens.times_equal,k.tokens.division_equal,k.tokens.modulo_equal,k.tokens.and_equal,k.tokens.or_equal,k.tokens.xor_equal,k.tokens.shift_right_equal,k.tokens.shift_left_equal],h.increment_operators=[k.tokens.plus_plus,k.tokens.minus_minus];var Jo=class{constructor(e,r,n,s,o){this.type=e,this.lexeme=r,this.line=n,this.start=s,this.end=o}toString(){return this.lexeme}isTemplateType(){return h.template_types.includes(this.type)}isArrayType(){return this.type===h.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}},Qo=class t{constructor(e){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=e??""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new Jo(h.eof,"",this._line,this._current,this._current)),this._tokens}scanToken(){let e=this._advance();if(e==`
42
42
  `)return this._line++,!0;if(this._isWhitespace(e))return!0;if(e=="/"){if(this._peekAhead()=="/"){for(;e!=`
43
43
  `;){if(this._isAtEnd())return!0;e=this._advance()}return this._line++,!0}if(this._peekAhead()=="*"){this._advance();let a=1;for(;a>0;){if(this._isAtEnd())return!0;if(e=this._advance(),e==`
44
- `)this._line++;else if(e=="*"){if(this._peekAhead()=="/"&&(this._advance(),a--,a==0))return!0}else e=="/"&&this._peekAhead()=="*"&&(this._advance(),a++)}return!0}}let r=h.simpleTokens[e];if(r)return this._addToken(r),!0;let n=h.none,s=this._isAlpha(e),o=e==="_";if(this._isAlphaNumeric(e)){let a=this._peekAhead();for(;this._isAlphaNumeric(a);)e+=this._advance(),a=this._peekAhead()}if(s){let a=h.keywords[e];if(a)return this._addToken(a),!0}if(s||o)return this._addToken(h.tokens.ident),!0;for(;;){let a=this._findType(e),i=this._peekAhead();if(e=="-"&&this._tokens.length>0){if(i=="=")return this._current++,e+=i,this._addToken(h.tokens.minus_equal),!0;if(i=="-")return this._current++,e+=i,this._addToken(h.tokens.minus_minus),!0;let u=this._tokens.length-1;if((h.literal_or_ident.includes(this._tokens[u].type)||this._tokens[u].type==h.tokens.paren_right)&&i!=">")return this._addToken(a),!0}if(e==">"&&(i==">"||i=="=")){let u=!1,l=this._tokens.length-1;for(let c=0;c<5&&l>=0&&!h.assignment_operators.includes(this._tokens[l].type);++c,--l)if(this._tokens[l].type===h.tokens.less_than){l>0&&this._tokens[l-1].isArrayOrTemplateType()&&(u=!0);break}if(u)return this._addToken(a),!0}if(a===h.none){let u=e,l=0,c=2;for(let f=0;f<c;++f)if(u+=this._peekAhead(f),a=this._findType(u),a!==h.none){l=f;break}if(a===h.none)return n!==h.none&&(this._current--,this._addToken(n),!0);e=u,this._current+=l+1}if(n=a,this._isAtEnd())break;e+=this._advance()}return n!==h.none&&(this._addToken(n),!0)}_findType(e){for(let n in h.regexTokens){let s=h.regexTokens[n];if(this._match(e,s.rule))return s}return h.literalTokens[e]||h.none}_match(e,r){let n=r.exec(e);return n&&n.index==0&&n[0]==e}_isAtEnd(){return this._current>=this._source.length}_isAlpha(e){return!this._isNumeric(e)&&!this._isWhitespace(e)&&e!=="_"&&!t._operators.has(e)}_isNumeric(e){return e>="0"&&e<="9"}_isAlphaNumeric(e){return this._isAlpha(e)||this._isNumeric(e)||e==="_"}_isWhitespace(e){return e==" "||e==" "||e=="\r"}_advance(e=0){let r=this._source[this._current];return this._current+=e+1,r??"\0"}_peekAhead(e=0){return this._current+e>=this._source.length?"\0":this._source[this._current+e]}_addToken(e){let r=this._source.substring(this._start,this._current);this._tokens.push(new Lo(e,r,this._line,this._start,this._current))}};function P(t){return Array.isArray(t)||t?.buffer instanceof ArrayBuffer}Po._operators=new Set([".","(",")","[","]","{","}",",",";",":","=","!","<",">","+","-","*","/","%","&","|","^","~","@","#","?","'","`",'"',"\\",`
45
- `,"\r"," ","\0"]);var Oo=new Float32Array(1),Zm=new Uint32Array(Oo.buffer),Jm=new Uint32Array(Oo.buffer),Do=new Int32Array(1),Qm=new Float32Array(Do.buffer),ep=new Uint32Array(Do.buffer),Mo=new Uint32Array(1),tp=new Float32Array(Mo.buffer),rp=new Int32Array(Mo.buffer);function th(t,e,r){if(e===r)return t;if(e==="f32"){if(r==="i32"||r==="x32")return Oo[0]=t,Zm[0];if(r==="u32")return Oo[0]=t,Jm[0]}else if(e==="i32"||e==="x32"){if(r==="f32")return Do[0]=t,Qm[0];if(r==="u32")return Do[0]=t,ep[0]}else if(e==="u32"){if(r==="f32")return Mo[0]=t,tp[0];if(r==="i32"||r==="x32")return Mo[0]=t,rp[0]}return console.error(`Unsupported cast from ${e} to ${r}`),t}var Ki=class{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}},_n=class{constructor(e,r){this.align=e,this.size=r}},$r=class t{constructor(){this.uniforms=[],this.storage=[],this.immediates=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new Hi,this.functions=[],this._types=new Map,this._functions=new Map}_isStorageTexture(e){return e.name=="texture_storage_1d"||e.name=="texture_storage_2d"||e.name=="texture_storage_2d_array"||e.name=="texture_storage_3d"}updateAST(e){for(let r of e)r instanceof zr&&this._functions.set(r.name,new Ki(r));for(let r of e)if(r instanceof Nt){let n=this.getTypeInfo(r,null);n instanceof Kt&&this.structs.push(n)}for(let r of e)if(r instanceof rs)this.aliases.push(this._getAliasInfo(r));else{if(r instanceof es){let n=r,s=this._getAttributeNum(n.attributes,"id",0),o=n.type!=null?this.getTypeInfo(n.type,n.attributes):null;this.overrides.push(new Wi(n.name,o,n.attributes,s));continue}if(this._isUniformVar(r)){let n=r,s=this._getAttributeNum(n.attributes,"group",0),o=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=new Nr(n.name,a,s,o,n.attributes,Ae.Uniform,n.access);i.access||(i.access="read"),this.uniforms.push(i);continue}if(this._isImmediateVar(r)){let n=r,s=this._getAttributeNum(n.attributes,"group",0),o=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=new Nr(n.name,a,s,o,n.attributes,Ae.Immediate,n.access);i.access||(i.access="read"),this.immediates.push(i);continue}if(this._isStorageVar(r)){let n=r,s=this._getAttributeNum(n.attributes,"group",0),o=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=this._isStorageTexture(a),u=new Nr(n.name,a,s,o,n.attributes,i?Ae.StorageTexture:Ae.Storage,n.access);u.access||(u.access="read"),this.storage.push(u);continue}if(this._isTextureVar(r)){let n=r,s=this._getAttributeNum(n.attributes,"group",0),o=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=this._isStorageTexture(a),u=i?a.access:n.access,l=new Nr(n.name,a,s,o,n.attributes,i?Ae.StorageTexture:Ae.Texture,u||n.access);l.access||(l.access="read"),i?this.storage.push(l):this.textures.push(l);continue}if(this._isSamplerVar(r)){let n=r,s=this._getAttributeNum(n.attributes,"group",0),o=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=new Nr(n.name,a,s,o,n.attributes,Ae.Sampler,n.access);this.samplers.push(i);continue}}for(let r of e)if(r instanceof zr){let n=this._getAttribute(r,"vertex"),s=this._getAttribute(r,"fragment"),o=this._getAttribute(r,"compute"),a=n||s||o,i=new zi(r.name,a?.name,r.attributes);i.attributes=r.attributes,i.startLine=r.startLine,i.endLine=r.endLine,this.functions.push(i),this._functions.get(r.name).info=i,a&&(this._functions.get(r.name).inUse=!0,i.inUse=!0,i.inputs=this._getInputs(r.args),i.outputs=this._getOutputs(r.returnType),this.entry[a.name].push(i)),i.resources=this._findResources(r,!!a),i.arguments=r.args.map(u=>new $i(u.name,this.getTypeInfo(u.type,u.attributes),u.attributes)),i.returnType=r.returnType?this.getTypeInfo(r.returnType,r.attributes):null;continue}for(let r of this._functions.values())r.info&&(r.info.inUse=r.inUse,this._addCalls(r.node,r.info.calls));for(let r of this._functions.values())r.node.search(n=>{var s,o,a;if(n instanceof Uo){if(n.value)if(P(n.value))for(let i of n.value)for(let u of this.overrides)i===u.name&&((s=r.info)===null||s===void 0||s.overrides.push(u));else for(let i of this.overrides)n.value===i.name&&((o=r.info)===null||o===void 0||o.overrides.push(i))}else if(n instanceof $e)for(let i of this.overrides)n.name===i.name&&((a=r.info)===null||a===void 0||a.overrides.push(i))});for(let r of this.uniforms)this._markStructsInUse(r.type);for(let r of this.storage)this._markStructsInUse(r.type)}getFunctionInfo(e){for(let r of this.functions)if(r.name==e)return r;return null}getStructInfo(e){for(let r of this.structs)if(r.name==e)return r;return null}getOverrideInfo(e){for(let r of this.overrides)if(r.name==e)return r;return null}_markStructsInUse(e){if(e)if(e.isStruct){if(e.inUse=!0,e.members)for(let r of e.members)this._markStructsInUse(r.type)}else if(e.isArray)this._markStructsInUse(e.format);else if(e.isTemplate)e.format&&this._markStructsInUse(e.format);else{let r=this._getAlias(e.name);r&&this._markStructsInUse(r)}}_addCalls(e,r){var n;for(let s of e.calls){let o=(n=this._functions.get(s.name))===null||n===void 0?void 0:n.info;o&&r.add(o)}}findResource(e,r,n){if(n){for(let s of this.entry.compute)if(s.name===n){for(let o of s.resources)if(o.group==e&&o.binding==r)return o}for(let s of this.entry.vertex)if(s.name===n){for(let o of s.resources)if(o.group==e&&o.binding==r)return o}for(let s of this.entry.fragment)if(s.name===n){for(let o of s.resources)if(o.group==e&&o.binding==r)return o}}for(let s of this.uniforms)if(s.group==e&&s.binding==r)return s;for(let s of this.storage)if(s.group==e&&s.binding==r)return s;for(let s of this.textures)if(s.group==e&&s.binding==r)return s;for(let s of this.samplers)if(s.group==e&&s.binding==r)return s;return null}_findResource(e){for(let r of this.uniforms)if(r.name==e)return r;for(let r of this.storage)if(r.name==e)return r;for(let r of this.textures)if(r.name==e)return r;for(let r of this.samplers)if(r.name==e)return r;return null}_markStructsFromAST(e){let r=this.getTypeInfo(e,null);this._markStructsInUse(r)}_findResources(e,r){let n=[],s=this,o=[];return e.search(a=>{if(a instanceof Tn)o.push({});else if(a instanceof kn)o.pop();else if(a instanceof It){let i=a;r&&i.type!==null&&this._markStructsFromAST(i.type),o.length>0&&(o[o.length-1][i.name]=i)}else if(a instanceof Rt){let i=a;r&&i.type!==null&&this._markStructsFromAST(i.type)}else if(a instanceof Vr){let i=a;r&&i.type!==null&&this._markStructsFromAST(i.type),o.length>0&&(o[o.length-1][i.name]=i)}else if(a instanceof $e){let i=a;if(o.length>0&&o[o.length-1][i.name])return;let u=s._findResource(i.name);u&&n.push(u)}else if(a instanceof ns){let i=a,u=s._functions.get(i.name);if(u&&(r&&(u.inUse=!0),e.calls.add(u.node),u.resources=s._findResources(u.node,r),n.push(...u.resources)),i.name==="textureSample"&&i.args.length>=2){let l=i.args[0],c=null;if(l instanceof $e){let p=s._findResource(l.name);p&&p.resourceType===Ae.Texture&&(c=p)}let f=i.args[1],d=null;if(f instanceof $e){let p=s._findResource(f.name);p&&p.resourceType===Ae.Sampler&&(d=p)}c&&d&&(c.relations===null&&(c.relations=[]),c.relations.push(d),d.relations===null&&(d.relations=[]),d.relations.push(c))}}else if(a instanceof ts){let i=a,u=s._functions.get(i.name);u&&(r&&(u.inUse=!0),e.calls.add(u.node),u.resources=s._findResources(u.node,r),n.push(...u.resources))}}),[...new Map(n.map(a=>[a.name,a])).values()]}getBindGroups(){let e=[];function r(n,s){n>=e.length&&(e.length=n+1),e[n]===void 0&&(e[n]=[]),s>=e[n].length&&(e[n].length=s+1)}for(let n of this.uniforms)r(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.storage)r(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.textures)r(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.samplers)r(n.group,n.binding),e[n.group][n.binding]=n;return e}_getOutputs(e,r=void 0){if(r===void 0&&(r=[]),e instanceof Nt)this._getStructOutputs(e,r);else{let n=this._getOutputInfo(e);n!==null&&r.push(n)}return r}_getStructOutputs(e,r){for(let n of e.members)if(n.type instanceof Nt)this._getStructOutputs(n.type,r);else{let s=this._getAttribute(n,"location")||this._getAttribute(n,"builtin");if(s!==null){let o=this.getTypeInfo(n.type,n.type.attributes),a=this._parseInt(s.value),i=new co(n.name,o,s.name,a);r.push(i)}}}_getOutputInfo(e){let r=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(r!==null){let n=this.getTypeInfo(e,e.attributes),s=this._parseInt(r.value);return new co("",n,r.name,s)}return null}_getInputs(e,r=void 0){r===void 0&&(r=[]);for(let n of e)if(n.type instanceof Nt)this._getStructInputs(n.type,r);else{let s=this._getInputInfo(n);s!==null&&r.push(s)}return r}_getStructInputs(e,r){for(let n of e.members)if(n.type instanceof Nt)this._getStructInputs(n.type,r);else{let s=this._getInputInfo(n);s!==null&&r.push(s)}}_getInputInfo(e){let r=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(r!==null){let n=this._getAttribute(e,"interpolation"),s=this.getTypeInfo(e.type,e.attributes),o=this._parseInt(r.value),a=new Vi(e.name,s,r.name,o);return n!==null&&(a.interpolation=this._parseString(n.value)),a}return null}_parseString(e){return e instanceof Array&&(e=e[0]),e}_parseInt(e){e instanceof Array&&(e=e[0]);let r=parseInt(e);return isNaN(r)?e:r}_getAlias(e){for(let r of this.aliases)if(r.name==e)return r.type;return null}_getAliasInfo(e){return new Gi(e.name,this.getTypeInfo(e.type,null))}getTypeInfoByName(e){for(let r of this.structs)if(r.name==e)return r;for(let r of this.aliases)if(r.name==e)return r.type;return null}getTypeInfo(e,r=null){if(this._types.has(e))return this._types.get(e);if(e instanceof vn){let s=e.type?this.getTypeInfo(e.type,e.attributes):null,o=new Jn(e.name,s,r);return this._types.set(e,o),this._updateTypeInfo(o),o}if(e instanceof Wr){let s=e,o=s.format?this.getTypeInfo(s.format,s.attributes):null,a=new Zt(s.name,r);return a.format=o,a.count=s.count,this._types.set(e,a),this._updateTypeInfo(a),a}if(e instanceof Nt){let s=e,o=new Kt(s.name,r);o.startLine=s.startLine,o.endLine=s.endLine;for(let a of s.members){let i=this.getTypeInfo(a.type,a.attributes);o.members.push(new uo(a.name,i,a.attributes))}return this._types.set(e,o),this._updateTypeInfo(o),o}if(e instanceof Gr){let s=e,o=s.format instanceof S,a=s.format?o?this.getTypeInfo(s.format,null):new st(s.format,null):null,i=new cr(s.name,a,r,s.access);return this._types.set(e,i),this._updateTypeInfo(i),i}if(e instanceof b){let s=e,o=s.format?this.getTypeInfo(s.format,null):null,a=new cr(s.name,o,r,s.access);return this._types.set(e,a),this._updateTypeInfo(a),a}let n=new st(e.name,r);return this._types.set(e,n),this._updateTypeInfo(n),n}_updateTypeInfo(e){var r,n,s;let o=this._getTypeSize(e);if(e.size=(r=o?.size)!==null&&r!==void 0?r:0,e instanceof Zt&&e.format){let a=this._getTypeSize(e.format);e.stride=Math.max((n=a?.size)!==null&&n!==void 0?n:0,(s=a?.align)!==null&&s!==void 0?s:0),this._updateTypeInfo(e.format)}e instanceof Jn&&this._updateTypeInfo(e.format),e instanceof Kt&&this._updateStructInfo(e)}_updateStructInfo(e){var r;let n=0,s=0,o=0,a=0;for(let i=0,u=e.members.length;i<u;++i){let l=e.members[i],c=this._getTypeSize(l);if(!c)continue;(r=this._getAlias(l.type.name))!==null&&r!==void 0||l.type;let f=c.align,d=c.size;n=this._roundUp(f,n+s),s=d,o=n,a=Math.max(a,f),l.offset=n,l.size=d,this._updateTypeInfo(l.type)}e.size=this._roundUp(a,o+s),e.align=a}_getTypeSize(e){var r,n;if(e==null)return null;let s=this._getAttributeNum(e.attributes,"size",0),o=this._getAttributeNum(e.attributes,"align",0);if(e instanceof uo&&(e=e.type),e instanceof st){let a=this._getAlias(e.name);a!==null&&(e=a)}{let a=t._typeInfo[e.name];if(a!==void 0){let i=((r=e.format)===null||r===void 0?void 0:r.name)==="f16"?2:1;return new _n(Math.max(o,a.align/i),Math.max(s,a.size/i))}}{let a=t._typeInfo[e.name.substring(0,e.name.length-1)];if(a){let i=e.name[e.name.length-1]==="h"?2:1;return new _n(Math.max(o,a.align/i),Math.max(s,a.size/i))}}if(e instanceof Zt){let a=e,i=8,u=8,l=this._getTypeSize(a.format);return l!==null&&(u=l.size,i=l.align),u=a.count*this._getAttributeNum((n=e?.attributes)!==null&&n!==void 0?n:null,"stride",this._roundUp(i,u)),s&&(u=s),new _n(Math.max(o,i),Math.max(s,u))}if(e instanceof Kt){let a=0,i=0,u=0,l=0,c=0;for(let f of e.members){let d=this._getTypeSize(f.type);d!==null&&(a=Math.max(d.align,a),u=this._roundUp(d.align,u+l),l=d.size,c=u)}return i=this._roundUp(a,c+l),new _n(Math.max(o,a),Math.max(s,i))}return null}_isUniformVar(e){return e instanceof It&&e.storage=="uniform"}_isImmediateVar(e){return e instanceof It&&e.storage=="immediate"}_isStorageVar(e){return e instanceof It&&e.storage=="storage"}_isTextureVar(e){return e instanceof It&&e.type!==null&&t._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof It&&e.type!==null&&t._samplerTypes.indexOf(e.type.name)!=-1}_getAttribute(e,r){let n=e;if(!n||!n.attributes)return null;let s=n.attributes;for(let o of s)if(o.name==r)return o;return null}_getAttributeNum(e,r,n){if(e===null)return n;for(let s of e)if(s.name==r){let o=s!==null&&s.value!==null?s.value:n;return o instanceof Array&&(o=o[0]),typeof o=="number"?o:typeof o=="string"?parseInt(o):n}return n}_roundUp(e,r){return Math.ceil(r/e)*e}};$r._typeInfo={f16:{align:2,size:2},i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},atomic:{align:4,size:4},vec2:{align:8,size:8},vec3:{align:16,size:12},vec4:{align:16,size:16},mat2x2:{align:8,size:16},mat3x2:{align:8,size:24},mat4x2:{align:8,size:32},mat2x3:{align:16,size:32},mat3x3:{align:16,size:48},mat4x3:{align:16,size:64},mat2x4:{align:16,size:32},mat3x4:{align:16,size:48},mat4x4:{align:16,size:64}},$r._textureTypes=h.any_texture_type.map(t=>t.name),$r._samplerTypes=h.sampler_type.map(t=>t.name);var iu=0,Zi=class t{constructor(e,r,n){this.id=iu++,this.name=e,this.value=r,this.node=n}clone(){return new t(this.name,this.value,this.node)}},Ji=class t{constructor(e){this.id=iu++,this.name=e.name,this.node=e}clone(){return new t(this.node)}},Qi=class t{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName="",this.id=iu++,e&&(this.parent=e,this.currentFunctionName=e.currentFunctionName)}getVariable(e){var r;return this.variables.has(e)?(r=this.variables.get(e))!==null&&r!==void 0?r:null:this.parent?this.parent.getVariable(e):null}getFunction(e){var r;return this.functions.has(e)?(r=this.functions.get(e))!==null&&r!==void 0?r:null:this.parent?this.parent.getFunction(e):null}createVariable(e,r,n){this.variables.set(e,new Zi(e,r,n??null))}setVariable(e,r,n){let s=this.getVariable(e);s!==null?s.value=r:this.createVariable(e,r,n)}getVariableValue(e){var r;let n=this.getVariable(e);return(r=n?.value)!==null&&r!==void 0?r:null}clone(){return new t(this)}},eu=class{evalExpression(e,r){return null}getTypeInfo(e){return null}getVariableName(e,r){return""}},tu=class{constructor(e){this.exec=e}getTypeInfo(e){return this.exec.getTypeInfo(e)}All(e,r){let n=this.exec.evalExpression(e.args[0],r),s=!0;if(n instanceof m)return n.data.forEach(o=>{o||(s=!1)}),new y(s?1:0,this.getTypeInfo("bool"));throw new Error(`All() expects a vector argument. Line ${e.line}`)}Any(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m){let s=n.data.some(o=>o);return new y(s?1:0,this.getTypeInfo("bool"))}throw new Error(`Any() expects a vector argument. Line ${e.line}`)}Select(e,r){let n=this.exec.evalExpression(e.args[2],r);if(!(n instanceof y))throw new Error(`Select() expects a bool condition. Line ${e.line}`);return n.value?this.exec.evalExpression(e.args[1],r):this.exec.evalExpression(e.args[0],r)}ArrayLength(e,r){let n=e.args[0];n instanceof ke&&(n=n.right);let s=this.exec.evalExpression(n,r);if(s instanceof Ee&&s.typeInfo.size===0){let o=s.typeInfo,a=s.buffer.byteLength/o.stride;return new y(a,this.getTypeInfo("u32"))}return new y(s.typeInfo.size,this.getTypeInfo("u32"))}Abs(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.abs(o)),n.typeInfo);let s=n;return new y(Math.abs(s.value),s.typeInfo)}Acos(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.acos(o)),n.typeInfo);let s=n;return new y(Math.acos(s.value),n.typeInfo)}Acosh(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.acosh(o)),n.typeInfo);let s=n;return new y(Math.acosh(s.value),n.typeInfo)}Asin(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.asin(o)),n.typeInfo);let s=n;return new y(Math.asin(s.value),n.typeInfo)}Asinh(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.asinh(o)),n.typeInfo);let s=n;return new y(Math.asinh(s.value),n.typeInfo)}Atan(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.atan(o)),n.typeInfo);let s=n;return new y(Math.atan(s.value),n.typeInfo)}Atanh(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.atanh(o)),n.typeInfo);let s=n;return new y(Math.atanh(s.value),n.typeInfo)}Atan2(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(n instanceof m&&s instanceof m)return new m(n.data.map((i,u)=>Math.atan2(i,s.data[u])),n.typeInfo);let o=n,a=s;return new y(Math.atan2(o.value,a.value),n.typeInfo)}Ceil(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.ceil(o)),n.typeInfo);let s=n;return new y(Math.ceil(s.value),n.typeInfo)}_clamp(e,r,n){return Math.min(Math.max(e,r),n)}Clamp(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r),o=this.exec.evalExpression(e.args[2],r);if(n instanceof m&&s instanceof m&&o instanceof m)return new m(n.data.map((l,c)=>this._clamp(l,s.data[c],o.data[c])),n.typeInfo);let a=n,i=s,u=o;return new y(this._clamp(a.value,i.value,u.value),n.typeInfo)}Cos(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.cos(o)),n.typeInfo);let s=n;return new y(Math.cos(s.value),n.typeInfo)}Cosh(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.cosh(o)),n.typeInfo);let s=n;return new y(Math.cos(s.value),n.typeInfo)}CountLeadingZeros(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.clz32(o)),n.typeInfo);let s=n;return new y(Math.clz32(s.value),n.typeInfo)}_countOneBits(e){let r=0;for(;e!==0;)1&e&&r++,e>>=1;return r}CountOneBits(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>this._countOneBits(o)),n.typeInfo);let s=n;return new y(this._countOneBits(s.value),n.typeInfo)}_countTrailingZeros(e){if(e===0)return 32;let r=0;for(;!(1&e);)e>>=1,r++;return r}CountTrailingZeros(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>this._countTrailingZeros(o)),n.typeInfo);let s=n;return new y(this._countTrailingZeros(s.value),n.typeInfo)}Cross(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(n instanceof m&&s instanceof m){if(n.data.length!==3||s.data.length!==3)return console.error(`Cross() expects 3D vectors. Line ${e.line}`),null;let o=n.data,a=s.data;return new m([o[1]*a[2]-a[1]*o[2],o[2]*a[0]-a[2]*o[0],o[0]*a[1]-a[0]*o[1]],n.typeInfo)}return console.error(`Cross() expects vector arguments. Line ${e.line}`),null}Degrees(e,r){let n=this.exec.evalExpression(e.args[0],r),s=180/Math.PI;return n instanceof m?new m(n.data.map(o=>o*s),n.typeInfo):new y(n.value*s,this.getTypeInfo("f32"))}Determinant(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof H){let s=n.data,o=n.typeInfo.getTypeName(),a=o.endsWith("h")?this.getTypeInfo("f16"):this.getTypeInfo("f32");if(o==="mat2x2"||o==="mat2x2f"||o==="mat2x2h")return new y(s[0]*s[3]-s[1]*s[2],a);if(o==="mat2x3"||o==="mat2x3f"||o==="mat2x3h")return new y(s[0]*(s[4]*s[8]-s[5]*s[7])-s[1]*(s[3]*s[8]-s[5]*s[6])+s[2]*(s[3]*s[7]-s[4]*s[6]),a);if(o==="mat2x4"||o==="mat2x4f"||o==="mat2x4h")console.error(`TODO: Determinant for ${o}`);else if(o==="mat3x2"||o==="mat3x2f"||o==="mat3x2h")console.error(`TODO: Determinant for ${o}`);else{if(o==="mat3x3"||o==="mat3x3f"||o==="mat3x3h")return new y(s[0]*(s[4]*s[8]-s[5]*s[7])-s[1]*(s[3]*s[8]-s[5]*s[6])+s[2]*(s[3]*s[7]-s[4]*s[6]),a);o==="mat3x4"||o==="mat3x4f"||o==="mat3x4h"||o==="mat4x2"||o==="mat4x2f"||o==="mat4x2h"||o==="mat4x3"||o==="mat4x3f"||o==="mat4x3h"?console.error(`TODO: Determinant for ${o}`):o!=="mat4x4"&&o!=="mat4x4f"&&o!=="mat4x4h"||console.error(`TODO: Determinant for ${o}`)}}return console.error(`Determinant expects a matrix argument. Line ${e.line}`),null}Distance(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(n instanceof m&&s instanceof m){let i=0;for(let u=0;u<n.data.length;++u)i+=(n.data[u]-s.data[u])*(n.data[u]-s.data[u]);return new y(Math.sqrt(i),this.getTypeInfo("f32"))}let o=n,a=s;return new y(Math.abs(o.value-a.value),n.typeInfo)}_dot(e,r){let n=0;for(let s=0;s<e.length;++s)n+=r[s]*e[s];return n}Dot(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);return n instanceof m&&s instanceof m?new y(this._dot(n.data,s.data),this.getTypeInfo("f32")):(console.error(`Dot() expects vector arguments. Line ${e.line}`),null)}Dot4U8Packed(e,r){return console.error(`TODO: dot4U8Packed. Line ${e.line}`),null}Dot4I8Packed(e,r){return console.error(`TODO: dot4I8Packed. Line ${e.line}`),null}Exp(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.exp(o)),n.typeInfo);let s=n;return new y(Math.exp(s.value),n.typeInfo)}Exp2(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.pow(2,o)),n.typeInfo);let s=n;return new y(Math.pow(2,s.value),n.typeInfo)}ExtractBits(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r),o=this.exec.evalExpression(e.args[2],r);if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 offset argument. Line ${e.line}`),null;if(o.typeInfo.name!=="u32"&&o.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 count argument. Line ${e.line}`),null;let a=s.value,i=o.value;if(n instanceof m)return new m(n.data.map(l=>l>>a&(1<<i)-1),n.typeInfo);if(n.typeInfo.name!=="i32"&&n.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 argument. Line ${e.line}`),null;let u=n.value;return new y(u>>a&(1<<i)-1,this.getTypeInfo("i32"))}FaceForward(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r),o=this.exec.evalExpression(e.args[2],r);if(n instanceof m&&s instanceof m&&o instanceof m){let a=this._dot(s.data,o.data);return new m(a<0?Array.from(n.data):n.data.map(i=>-i),n.typeInfo)}return console.error(`FaceForward() expects vector arguments. Line ${e.line}`),null}_firstLeadingBit(e){return e===0?-1:31-Math.clz32(e)}FirstLeadingBit(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>this._firstLeadingBit(o)),n.typeInfo);let s=n;return new y(this._firstLeadingBit(s.value),n.typeInfo)}_firstTrailingBit(e){return e===0?-1:Math.log2(e&-e)}FirstTrailingBit(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>this._firstTrailingBit(o)),n.typeInfo);let s=n;return new y(this._firstTrailingBit(s.value),n.typeInfo)}Floor(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.floor(o)),n.typeInfo);let s=n;return new y(Math.floor(s.value),n.typeInfo)}Fma(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r),o=this.exec.evalExpression(e.args[2],r);if(n instanceof m&&s instanceof m&&o instanceof m)return n.data.length!==s.data.length||n.data.length!==o.data.length?(console.error(`Fma() expects vectors of the same length. Line ${e.line}`),null):new m(n.data.map((l,c)=>l*s.data[c]+o.data[c]),n.typeInfo);let a=n,i=s,u=o;return new y(a.value*i.value+u.value,a.typeInfo)}Fract(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>o-Math.floor(o)),n.typeInfo);let s=n;return new y(s.value-Math.floor(s.value),n.typeInfo)}Frexp(e,r){return console.error(`TODO: frexp. Line ${e.line}`),null}InsertBits(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r),o=this.exec.evalExpression(e.args[2],r),a=this.exec.evalExpression(e.args[3],r);if(o.typeInfo.name!=="u32"&&o.typeInfo.name!=="x32")return console.error(`InsertBits() expects an i32 offset argument. Line ${e.line}`),null;let i=o.value,u=(1<<a.value)-1<<i,l=~u;if(n instanceof m&&s instanceof m)return new m(n.data.map((d,p)=>d&l|s.data[p]<<i&u),n.typeInfo);let c=n.value,f=s.value;return new y(c&l|f<<i&u,n.typeInfo)}InverseSqrt(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>1/Math.sqrt(o)),n.typeInfo);let s=n;return new y(1/Math.sqrt(s.value),n.typeInfo)}Ldexp(e,r){return console.error(`TODO: ldexp. Line ${e.line}`),null}Length(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m){let o=0;return n.data.forEach(a=>{o+=a*a}),new y(Math.sqrt(o),this.getTypeInfo("f32"))}let s=n;return new y(Math.abs(s.value),n.typeInfo)}Log(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.log(o)),n.typeInfo);let s=n;return new y(Math.log(s.value),n.typeInfo)}Log2(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.log2(o)),n.typeInfo);let s=n;return new y(Math.log2(s.value),n.typeInfo)}Max(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(n instanceof m&&s instanceof m)return new m(n.data.map((i,u)=>Math.max(i,s.data[u])),n.typeInfo);let o=n,a=s;return new y(Math.max(o.value,a.value),n.typeInfo)}Min(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(n instanceof m&&s instanceof m)return new m(n.data.map((i,u)=>Math.min(i,s.data[u])),n.typeInfo);let o=n,a=s;return new y(Math.min(o.value,a.value),n.typeInfo)}Mix(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r),o=this.exec.evalExpression(e.args[2],r);if(n instanceof m&&s instanceof m&&o instanceof m)return new m(n.data.map((u,l)=>n.data[l]*(1-o.data[l])+s.data[l]*o.data[l]),n.typeInfo);let a=s,i=o;return new y(n.value*(1-i.value)+a.value*i.value,n.typeInfo)}Modf(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(n instanceof m&&s instanceof m)return new m(n.data.map((a,i)=>a%s.data[i]),n.typeInfo);let o=s;return new y(n.value%o.value,n.typeInfo)}Normalize(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m){let s=this.Length(e,r).value;return new m(n.data.map(o=>o/s),n.typeInfo)}return console.error(`Normalize() expects a vector argument. Line ${e.line}`),null}Pow(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(n instanceof m&&s instanceof m)return new m(n.data.map((i,u)=>Math.pow(i,s.data[u])),n.typeInfo);let o=n,a=s;return new y(Math.pow(o.value,a.value),n.typeInfo)}QuantizeToF16(e,r){let n=this.exec.evalExpression(e.args[0],r);return n instanceof m?new m(n.data.map(s=>s),n.typeInfo):new y(n.value,n.typeInfo)}Radians(e,r){let n=this.exec.evalExpression(e.args[0],r);return n instanceof m?new m(n.data.map(s=>s*Math.PI/180),n.typeInfo):new y(n.value*Math.PI/180,this.getTypeInfo("f32"))}Reflect(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(n instanceof m&&s instanceof m){let o=this._dot(n.data,s.data);return new m(n.data.map((a,i)=>a-2*o*s.data[i]),n.typeInfo)}return console.error(`Reflect() expects vector arguments. Line ${e.line}`),null}Refract(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r),o=this.exec.evalExpression(e.args[2],r);if(n instanceof m&&s instanceof m&&o instanceof y){let a=this._dot(s.data,n.data);return new m(n.data.map((i,u)=>{let l=1-o.value*o.value*(1-a*a);if(l<0)return 0;let c=Math.sqrt(l);return o.value*i-(o.value*a+c)*s.data[u]}),n.typeInfo)}return console.error(`Refract() expects vector arguments and a scalar argument. Line ${e.line}`),null}ReverseBits(e,r){return console.error(`TODO: reverseBits. Line ${e.line}`),null}Round(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.round(o)),n.typeInfo);let s=n;return new y(Math.round(s.value),n.typeInfo)}Saturate(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.min(Math.max(o,0),1)),n.typeInfo);let s=n;return new y(Math.min(Math.max(s.value,0),1),n.typeInfo)}Sign(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.sign(o)),n.typeInfo);let s=n;return new y(Math.sign(s.value),n.typeInfo)}Sin(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.sin(o)),n.typeInfo);let s=n;return new y(Math.sin(s.value),n.typeInfo)}Sinh(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.sinh(o)),n.typeInfo);let s=n;return new y(Math.sinh(s.value),n.typeInfo)}_smoothstep(e,r,n){let s=Math.min(Math.max((n-e)/(r-e),0),1);return s*s*(3-2*s)}SmoothStep(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r),o=this.exec.evalExpression(e.args[2],r);if(o instanceof m&&n instanceof m&&s instanceof m)return new m(o.data.map((l,c)=>this._smoothstep(n.data[c],s.data[c],l)),o.typeInfo);let a=n,i=s,u=o;return new y(this._smoothstep(a.value,i.value,u.value),o.typeInfo)}Sqrt(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.sqrt(o)),n.typeInfo);let s=n;return new y(Math.sqrt(s.value),n.typeInfo)}Step(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(s instanceof m&&n instanceof m)return new m(s.data.map((a,i)=>a<n.data[i]?0:1),s.typeInfo);let o=n;return new y(s.value<o.value?0:1,o.typeInfo)}Tan(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.tan(o)),n.typeInfo);let s=n;return new y(Math.tan(s.value),n.typeInfo)}Tanh(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.tanh(o)),n.typeInfo);let s=n;return new y(Math.tanh(s.value),n.typeInfo)}_getTransposeType(e){let r=e.getTypeName();return r==="mat2x2f"||r==="mat2x2h"?e:r==="mat2x3f"?this.getTypeInfo("mat3x2f"):r==="mat2x3h"?this.getTypeInfo("mat3x2h"):r==="mat2x4f"?this.getTypeInfo("mat4x2f"):r==="mat2x4h"?this.getTypeInfo("mat4x2h"):r==="mat3x2f"?this.getTypeInfo("mat2x3f"):r==="mat3x2h"?this.getTypeInfo("mat2x3h"):r==="mat3x3f"||r==="mat3x3h"?e:r==="mat3x4f"?this.getTypeInfo("mat4x3f"):r==="mat3x4h"?this.getTypeInfo("mat4x3h"):r==="mat4x2f"?this.getTypeInfo("mat2x4f"):r==="mat4x2h"?this.getTypeInfo("mat2x4h"):r==="mat4x3f"?this.getTypeInfo("mat3x4f"):r==="mat4x3h"?this.getTypeInfo("mat3x4h"):(r==="mat4x4f"||r==="mat4x4h"||console.error(`Invalid matrix type ${r}`),e)}Transpose(e,r){let n=this.exec.evalExpression(e.args[0],r);if(!(n instanceof H))return console.error(`Transpose() expects a matrix argument. Line ${e.line}`),null;let s=this._getTransposeType(n.typeInfo);if(n.typeInfo.name==="mat2x2"||n.typeInfo.name==="mat2x2f"||n.typeInfo.name==="mat2x2h"){let o=n.data;return new H([o[0],o[2],o[1],o[3]],s)}if(n.typeInfo.name==="mat2x3"||n.typeInfo.name==="mat2x3f"||n.typeInfo.name==="mat2x3h"){let o=n.data;return new H([o[0],o[3],o[6],o[1],o[4],o[7]],s)}if(n.typeInfo.name==="mat2x4"||n.typeInfo.name==="mat2x4f"||n.typeInfo.name==="mat2x4h"){let o=n.data;return new H([o[0],o[4],o[8],o[12],o[1],o[5],o[9],o[13]],s)}if(n.typeInfo.name==="mat3x2"||n.typeInfo.name==="mat3x2f"||n.typeInfo.name==="mat3x2h"){let o=n.data;return new H([o[0],o[3],o[1],o[4],o[2],o[5]],s)}if(n.typeInfo.name==="mat3x3"||n.typeInfo.name==="mat3x3f"||n.typeInfo.name==="mat3x3h"){let o=n.data;return new H([o[0],o[3],o[6],o[1],o[4],o[7],o[2],o[5],o[8]],s)}if(n.typeInfo.name==="mat3x4"||n.typeInfo.name==="mat3x4f"||n.typeInfo.name==="mat3x4h"){let o=n.data;return new H([o[0],o[4],o[8],o[12],o[1],o[5],o[9],o[13],o[2],o[6],o[10],o[14]],s)}if(n.typeInfo.name==="mat4x2"||n.typeInfo.name==="mat4x2f"||n.typeInfo.name==="mat4x2h"){let o=n.data;return new H([o[0],o[4],o[1],o[5],o[2],o[6]],s)}if(n.typeInfo.name==="mat4x3"||n.typeInfo.name==="mat4x3f"||n.typeInfo.name==="mat4x3h"){let o=n.data;return new H([o[0],o[4],o[8],o[1],o[5],o[9],o[2],o[6],o[10]],s)}if(n.typeInfo.name==="mat4x4"||n.typeInfo.name==="mat4x4f"||n.typeInfo.name==="mat4x4h"){let o=n.data;return new H([o[0],o[4],o[8],o[12],o[1],o[5],o[9],o[13],o[2],o[6],o[10],o[14],o[3],o[7],o[11],o[15]],s)}return console.error(`Invalid matrix type ${n.typeInfo.name}`),null}Trunc(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof m)return new m(n.data.map(o=>Math.trunc(o)),n.typeInfo);let s=n;return new y(Math.trunc(s.value),n.typeInfo)}Dpdx(e,r){return console.error(`TODO: dpdx. Line ${e.line}`),null}DpdxCoarse(e,r){return console.error(`TODO: dpdxCoarse. Line ${e.line}`),null}DpdxFine(e,r){return console.error("TODO: dpdxFine"),null}Dpdy(e,r){return console.error("TODO: dpdy"),null}DpdyCoarse(e,r){return console.error("TODO: dpdyCoarse"),null}DpdyFine(e,r){return console.error("TODO: dpdyFine"),null}Fwidth(e,r){return console.error("TODO: fwidth"),null}FwidthCoarse(e,r){return console.error("TODO: fwidthCoarse"),null}FwidthFine(e,r){return console.error("TODO: fwidthFine"),null}TextureDimensions(e,r){let n=e.args[0],s=e.args.length>1?this.exec.evalExpression(e.args[1],r).value:0;if(n instanceof $e){let o=n.name,a=r.getVariableValue(o);if(a instanceof ur){if(s<0||s>=a.mipLevelCount)return console.error(`Invalid mip level for textureDimensions. Line ${e.line}`),null;let i=a.getMipLevelSize(s),u=a.dimension;return u==="1d"?new y(i[0],this.getTypeInfo("u32")):u==="3d"?new m(i,this.getTypeInfo("vec3u")):u==="2d"?new m(i.slice(0,2),this.getTypeInfo("vec2u")):(console.error(`Invalid texture dimension ${u} not found. Line ${e.line}`),null)}return console.error(`Texture ${o} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureDimensions. Line ${e.line}`),null}TextureGather(e,r){return console.error("TODO: textureGather"),null}TextureGatherCompare(e,r){return console.error("TODO: textureGatherCompare"),null}TextureLoad(e,r){let n=e.args[0],s=this.exec.evalExpression(e.args[1],r);if(!(s instanceof m)||s.data.length!==2)return console.error(`Invalid UV argument for textureLoad. Line ${e.line}`),null;if(n instanceof $e){let o=n.name,a=r.getVariableValue(o);if(a instanceof ur){let i=0,u=0;["texture_storage_2d_array","texture_2d_array","texture_depth_2d_array"].indexOf(a.typeInfo.name)>-1&&(i=this.exec.evalExpression(e.args[2],r).value),["texture_1d","texture_2d","texture_depth_2d","texture_3d"].indexOf(a.typeInfo.name)>-1&&(u=this.exec.evalExpression(e.args[2],r).value),["texture_2d_array","texture_depth_2d_array"].indexOf(a.typeInfo.name)>-1&&(u=this.exec.evalExpression(e.args[3],r).value);let l=Math.floor(s.data[0]),c=Math.floor(s.data[1]),f=Math.floor(i),d=Math.floor(u);if(l<0||l>=a.width||c<0||c>=a.height)return console.error(`Texture ${o} out of bounds. Line ${e.line}`),null;let p=a.getPixel(l,c,f,d);return p===null?(console.error(`Invalid texture format for textureLoad. Line ${e.line}`),null):new m(p,this.getTypeInfo("vec4f"))}return console.error(`Texture ${o} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureLoad. Line ${e.line}`),null}TextureNumLayers(e,r){let n=e.args[0];if(n instanceof $e){let s=n.name,o=r.getVariableValue(s);return o instanceof ur?new y(o.depthOrArrayLayers,this.getTypeInfo("u32")):(console.error(`Texture ${s} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLayers. Line ${e.line}`),null}TextureNumLevels(e,r){let n=e.args[0];if(n instanceof $e){let s=n.name,o=r.getVariableValue(s);return o instanceof ur?new y(o.mipLevelCount,this.getTypeInfo("u32")):(console.error(`Texture ${s} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLevels. Line ${e.line}`),null}TextureNumSamples(e,r){let n=e.args[0];if(n instanceof $e){let s=n.name,o=r.getVariableValue(s);return o instanceof ur?new y(o.sampleCount,this.getTypeInfo("u32")):(console.error(`Texture ${s} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumSamples. Line ${e.line}`),null}TextureSample(e,r){return console.error("TODO: textureSample"),null}TextureSampleBias(e,r){return console.error("TODO: textureSampleBias"),null}TextureSampleCompare(e,r){return console.error("TODO: textureSampleCompare"),null}TextureSampleCompareLevel(e,r){return console.error("TODO: textureSampleCompareLevel"),null}TextureSampleGrad(e,r){return console.error("TODO: textureSampleGrad"),null}TextureSampleLevel(e,r){return console.error("TODO: textureSampleLevel"),null}TextureSampleBaseClampToEdge(e,r){return console.error("TODO: textureSampleBaseClampToEdge"),null}TextureStore(e,r){let n=e.args[0],s=this.exec.evalExpression(e.args[1],r),o=e.args.length===4?this.exec.evalExpression(e.args[2],r).value:0,a=e.args.length===4?this.exec.evalExpression(e.args[3],r).data:this.exec.evalExpression(e.args[2],r).data;if(a.length!==4)return console.error(`Invalid value argument for textureStore. Line ${e.line}`),null;if(!(s instanceof m)||s.data.length!==2)return console.error(`Invalid UV argument for textureStore. Line ${e.line}`),null;if(n instanceof $e){let i=n.name,u=r.getVariableValue(i);if(u instanceof ur){let l=u.getMipLevelSize(0),c=Math.floor(s.data[0]),f=Math.floor(s.data[1]);return c<0||c>=l[0]||f<0||f>=l[1]?(console.error(`Texture ${i} out of bounds. Line ${e.line}`),null):(u.setPixel(c,f,0,o,Array.from(a)),null)}return console.error(`Texture ${i} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureStore. Line ${e.line}`),null}AtomicLoad(e,r){let n=e.args[0];n instanceof ke&&(n=n.right);let s=this.exec.getVariableName(n,r);return r.getVariable(s).value.getSubData(this.exec,n.postfix,r)}AtomicStore(e,r){let n=e.args[0];n instanceof ke&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r);return u instanceof y&&i instanceof y&&(u.value=i.value),o.value instanceof Ee&&o.value.setDataValue(this.exec,u,n.postfix,r),null}AtomicAdd(e,r){let n=e.args[0];n instanceof ke&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r),l=new y(u.value,u.typeInfo);return u instanceof y&&i instanceof y&&(u.value+=i.value),o.value instanceof Ee&&o.value.setDataValue(this.exec,u,n.postfix,r),l}AtomicSub(e,r){let n=e.args[0];n instanceof ke&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r),l=new y(u.value,u.typeInfo);return u instanceof y&&i instanceof y&&(u.value-=i.value),o.value instanceof Ee&&o.value.setDataValue(this.exec,u,n.postfix,r),l}AtomicMax(e,r){let n=e.args[0];n instanceof ke&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r),l=new y(u.value,u.typeInfo);return u instanceof y&&i instanceof y&&(u.value=Math.max(u.value,i.value)),o.value instanceof Ee&&o.value.setDataValue(this.exec,u,n.postfix,r),l}AtomicMin(e,r){let n=e.args[0];n instanceof ke&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r),l=new y(u.value,u.typeInfo);return u instanceof y&&i instanceof y&&(u.value=Math.min(u.value,i.value)),o.value instanceof Ee&&o.value.setDataValue(this.exec,u,n.postfix,r),l}AtomicAnd(e,r){let n=e.args[0];n instanceof ke&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r),l=new y(u.value,u.typeInfo);return u instanceof y&&i instanceof y&&(u.value=u.value&i.value),o.value instanceof Ee&&o.value.setDataValue(this.exec,u,n.postfix,r),l}AtomicOr(e,r){let n=e.args[0];n instanceof ke&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r),l=new y(u.value,u.typeInfo);return u instanceof y&&i instanceof y&&(u.value=u.value|i.value),o.value instanceof Ee&&o.value.setDataValue(this.exec,u,n.postfix,r),l}AtomicXor(e,r){let n=e.args[0];n instanceof ke&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r),l=new y(u.value,u.typeInfo);return u instanceof y&&i instanceof y&&(u.value=u.value^i.value),o.value instanceof Ee&&o.value.setDataValue(this.exec,u,n.postfix,r),l}AtomicExchange(e,r){let n=e.args[0];n instanceof ke&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r),l=new y(u.value,u.typeInfo);return u instanceof y&&i instanceof y&&(u.value=i.value),o.value instanceof Ee&&o.value.setDataValue(this.exec,u,n.postfix,r),l}AtomicCompareExchangeWeak(e,r){return console.error("TODO: atomicCompareExchangeWeak"),null}Pack4x8snorm(e,r){return console.error("TODO: pack4x8snorm"),null}Pack4x8unorm(e,r){return console.error("TODO: pack4x8unorm"),null}Pack4xI8(e,r){return console.error("TODO: pack4xI8"),null}Pack4xU8(e,r){return console.error("TODO: pack4xU8"),null}Pack4x8Clamp(e,r){return console.error("TODO: pack4x8Clamp"),null}Pack4xU8Clamp(e,r){return console.error("TODO: pack4xU8Clamp"),null}Pack2x16snorm(e,r){return console.error("TODO: pack2x16snorm"),null}Pack2x16unorm(e,r){return console.error("TODO: pack2x16unorm"),null}Pack2x16float(e,r){return console.error("TODO: pack2x16float"),null}Unpack4x8snorm(e,r){return console.error("TODO: unpack4x8snorm"),null}Unpack4x8unorm(e,r){return console.error("TODO: unpack4x8unorm"),null}Unpack4xI8(e,r){return console.error("TODO: unpack4xI8"),null}Unpack4xU8(e,r){return console.error("TODO: unpack4xU8"),null}Unpack2x16snorm(e,r){return console.error("TODO: unpack2x16snorm"),null}Unpack2x16unorm(e,r){return console.error("TODO: unpack2x16unorm"),null}Unpack2x16float(e,r){return console.error("TODO: unpack2x16float"),null}StorageBarrier(e,r){return null}TextureBarrier(e,r){return null}WorkgroupBarrier(e,r){return null}WorkgroupUniformLoad(e,r){return null}SubgroupAdd(e,r){return console.error("TODO: subgroupAdd"),null}SubgroupExclusiveAdd(e,r){return console.error("TODO: subgroupExclusiveAdd"),null}SubgroupInclusiveAdd(e,r){return console.error("TODO: subgroupInclusiveAdd"),null}SubgroupAll(e,r){return console.error("TODO: subgroupAll"),null}SubgroupAnd(e,r){return console.error("TODO: subgroupAnd"),null}SubgroupAny(e,r){return console.error("TODO: subgroupAny"),null}SubgroupBallot(e,r){return console.error("TODO: subgroupBallot"),null}SubgroupBroadcast(e,r){return console.error("TODO: subgroupBroadcast"),null}SubgroupBroadcastFirst(e,r){return console.error("TODO: subgroupBroadcastFirst"),null}SubgroupElect(e,r){return console.error("TODO: subgroupElect"),null}SubgroupMax(e,r){return console.error("TODO: subgroupMax"),null}SubgroupMin(e,r){return console.error("TODO: subgroupMin"),null}SubgroupMul(e,r){return console.error("TODO: subgroupMul"),null}SubgroupExclusiveMul(e,r){return console.error("TODO: subgroupExclusiveMul"),null}SubgroupInclusiveMul(e,r){return console.error("TODO: subgroupInclusiveMul"),null}SubgroupOr(e,r){return console.error("TODO: subgroupOr"),null}SubgroupShuffle(e,r){return console.error("TODO: subgroupShuffle"),null}SubgroupShuffleDown(e,r){return console.error("TODO: subgroupShuffleDown"),null}SubgroupShuffleUp(e,r){return console.error("TODO: subgroupShuffleUp"),null}SubgroupShuffleXor(e,r){return console.error("TODO: subgroupShuffleXor"),null}SubgroupXor(e,r){return console.error("TODO: subgroupXor"),null}QuadBroadcast(e,r){return console.error("TODO: quadBroadcast"),null}QuadSwapDiagonal(e,r){return console.error("TODO: quadSwapDiagonal"),null}QuadSwapX(e,r){return console.error("TODO: quadSwapX"),null}QuadSwapY(e,r){return console.error("TODO: quadSwapY"),null}},Pi={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},et={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]},pt=class t extends eu{constructor(e,r){var n;super(),this.ast=e??[],this.reflection=new $r,this.reflection.updateAST(this.ast),this.context=(n=r?.clone())!==null&&n!==void 0?n:new Qi,this.builtins=new tu(this),this.typeInfo={bool:this.getTypeInfo(S.bool),i32:this.getTypeInfo(S.i32),u32:this.getTypeInfo(S.u32),f32:this.getTypeInfo(S.f32),f16:this.getTypeInfo(S.f16),vec2f:this.getTypeInfo(b.vec2f),vec2u:this.getTypeInfo(b.vec2u),vec2i:this.getTypeInfo(b.vec2i),vec2h:this.getTypeInfo(b.vec2h),vec3f:this.getTypeInfo(b.vec3f),vec3u:this.getTypeInfo(b.vec3u),vec3i:this.getTypeInfo(b.vec3i),vec3h:this.getTypeInfo(b.vec3h),vec4f:this.getTypeInfo(b.vec4f),vec4u:this.getTypeInfo(b.vec4u),vec4i:this.getTypeInfo(b.vec4i),vec4h:this.getTypeInfo(b.vec4h),mat2x2f:this.getTypeInfo(b.mat2x2f),mat2x3f:this.getTypeInfo(b.mat2x3f),mat2x4f:this.getTypeInfo(b.mat2x4f),mat3x2f:this.getTypeInfo(b.mat3x2f),mat3x3f:this.getTypeInfo(b.mat3x3f),mat3x4f:this.getTypeInfo(b.mat3x4f),mat4x2f:this.getTypeInfo(b.mat4x2f),mat4x3f:this.getTypeInfo(b.mat4x3f),mat4x4f:this.getTypeInfo(b.mat4x4f)}}getVariableValue(e){var r,n;let s=(n=(r=this.context.getVariable(e))===null||r===void 0?void 0:r.value)!==null&&n!==void 0?n:null;if(s===null)return null;if(s instanceof y)return s.value;if(s instanceof m||s instanceof H)return Array.from(s.data);if(s instanceof Ee&&s.typeInfo instanceof Zt){if(s.typeInfo.format.name==="u32")return Array.from(new Uint32Array(s.buffer,s.offset,s.typeInfo.count));if(s.typeInfo.format.name==="i32")return Array.from(new Int32Array(s.buffer,s.offset,s.typeInfo.count));if(s.typeInfo.format.name==="f32")return Array.from(new Float32Array(s.buffer,s.offset,s.typeInfo.count))}return console.error(`Unsupported return variable type ${s.typeInfo.name}`),null}execute(e){(e=e??{}).constants&&this._setOverrides(e.constants,this.context),this._execStatements(this.ast,this.context)}dispatchWorkgroups(e,r,n,s){let o=this.context.clone();(s=s??{}).constants&&this._setOverrides(s.constants,o),this._execStatements(this.ast,o);let a=o.getFunction(e);if(!a)return void console.error(`Function ${e} not found`);if(typeof r=="number")r=[r,1,1];else{if(r.length===0)return void console.error("Invalid dispatch count");r.length===1?r=[r[0],1,1]:r.length===2?r=[r[0],r[1],1]:r.length>3&&(r=[r[0],r[1],r[2]])}let i=r[0],u=r[1],l=r[2],c=this.getTypeInfo("vec3u");o.setVariable("@num_workgroups",new m(r,c));let f=this.reflection.getFunctionInfo(e);f===null&&console.error(`Function ${e} not found in reflection data`);for(let d in n)for(let p in n[d]){let T=n[d][p];o.variables.forEach(A=>{var E;let I=A.node;if(I?.attributes){let _=null,v=null;for(let R of I.attributes)R.name==="binding"?_=R.value:R.name==="group"&&(v=R.value);if(p===_&&d===v){let R=!1;for(let U of f.resources)if(U.name===A.name&&U.group===parseInt(d)&&U.binding===parseInt(p)){R=!0;break}if(R)if(T.texture!==void 0&&T.descriptor!==void 0){let U=new ur(T.texture,this.getTypeInfo(I.type),T.descriptor,(E=T.texture.view)!==null&&E!==void 0?E:null);A.value=U}else T.uniform!==void 0?A.value=new Ee(T.uniform,this.getTypeInfo(I.type)):A.value=new Ee(T,this.getTypeInfo(I.type))}}})}for(let d=0;d<l;++d)for(let p=0;p<u;++p)for(let T=0;T<i;++T)o.setVariable("@workgroup_id",new m([T,p,d],this.getTypeInfo("vec3u"))),this._dispatchWorkgroup(a,[T,p,d],o)}execStatement(e,r){if(e instanceof _o)return this.evalExpression(e.value,r);if(e instanceof vo){if(e.condition){let n=this.evalExpression(e.condition,r);if(!(n instanceof y))throw new Error("Invalid break-if condition");if(!n.value)return null}return t._breakObj}if(e instanceof wo)return t._continueObj;if(e instanceof Vr)this._let(e,r);else if(e instanceof It)this._var(e,r);else if(e instanceof bn)this._const(e,r);else if(e instanceof es)this._override(e,r);else if(e instanceof zr)this._function(e,r);else{if(e instanceof yo)return this._if(e,r);if(e instanceof xo)return this._switch(e,r);if(e instanceof ho)return this._for(e,r);if(e instanceof fo)return this._while(e,r);if(e instanceof go)return this._loop(e,r);if(e instanceof Qn){let n=r.clone();return n.currentFunctionName=r.currentFunctionName,this._execStatements(e.body,n)}if(e instanceof po)this._assign(e,r);else if(e instanceof mo)this._increment(e,r);else{if(e instanceof Nt)return null;if(e instanceof ts)this._call(e,r);else{if(e instanceof bo||e instanceof rs)return null;console.error("Invalid statement type.",e,`Line ${e.line}`)}}}return null}evalExpression(e,r){return e instanceof mt?this._evalBinaryOp(e,r):e instanceof Fe?this._evalLiteral(e,r):e instanceof $e?this._evalVariable(e,r):e instanceof ns?this._evalCall(e,r):e instanceof Rt?this._evalCreate(e,r):e instanceof ko?this._evalConst(e,r):e instanceof Eo?this._evalBitcast(e,r):e instanceof ke?this._evalUnaryOp(e,r):(console.error("Invalid expression type",e,`Line ${e.line}`),null)}getTypeInfo(e){var r;if(e instanceof S){let s=this.reflection.getTypeInfo(e);if(s!==null)return s}let n=(r=this.typeInfo[e])!==null&&r!==void 0?r:null;return n!==null||(n=this.reflection.getTypeInfoByName(e)),n}_setOverrides(e,r){for(let n in e){let s=e[n],o=this.reflection.getOverrideInfo(n);o!==null?(o.type===null&&(o.type=this.getTypeInfo("u32")),t._numericScalarTypes.has(o.type.name)?r.setVariable(n,new y(s,o.type)):t._vectorTypes.has(o.type.name)?r.setVariable(n,new m(s,o.type)):console.error(`Invalid constant type for ${n}`)):console.error(`Override ${n} does not exist in the shader.`)}}_dispatchWorkgroup(e,r,n){let s=[1,1,1];for(let c of e.node.attributes)if(c.name==="workgroup_size"){if(c.value.length>0){let f=n.getVariableValue(c.value[0]);s[0]=f instanceof y?f.value:parseInt(c.value[0])}if(c.value.length>1){let f=n.getVariableValue(c.value[1]);s[1]=f instanceof y?f.value:parseInt(c.value[1])}if(c.value.length>2){let f=n.getVariableValue(c.value[2]);s[2]=f instanceof y?f.value:parseInt(c.value[2])}}let o=this.getTypeInfo("vec3u"),a=this.getTypeInfo("u32");n.setVariable("@workgroup_size",new m(s,o));let i=s[0],u=s[1],l=s[2];for(let c=0,f=0;c<l;++c)for(let d=0;d<u;++d)for(let p=0;p<i;++p,++f){let T=[p,d,c],A=[p+r[0]*s[0],d+r[1]*s[1],c+r[2]*s[2]];n.setVariable("@local_invocation_id",new m(T,o)),n.setVariable("@global_invocation_id",new m(A,o)),n.setVariable("@local_invocation_index",new y(f,a)),this._dispatchExec(e,n)}}_dispatchExec(e,r){for(let n of e.node.args)for(let s of n.attributes)if(s.name==="builtin"){let o=`@${s.value}`,a=r.getVariable(o);a!==void 0&&r.variables.set(n.name,a)}this._execStatements(e.node.body,r)}getVariableName(e,r){for(;e instanceof ke;)e=e.right;return e instanceof $e?e.name:(console.error("Unknown variable type",e,"Line",e.line),null)}_execStatements(e,r){for(let n of e){if(Array.isArray(n)){let o=r.clone(),a=this._execStatements(n,o);if(a)return a;continue}let s=this.execStatement(n,r);if(s)return s}return null}_call(e,r){let n=r.clone();n.currentFunctionName=e.name;let s=r.getFunction(e.name);if(s){for(let o=0;o<s.node.args.length;++o){let a=s.node.args[o],i=this.evalExpression(e.args[o],n);n.setVariable(a.name,i,a)}this._execStatements(s.node.body,n)}else e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)&&this._evalCreate(e,r)}_increment(e,r){let n=this.getVariableName(e.variable,r),s=r.getVariable(n);s?e.operator==="++"?s.value instanceof y?s.value.value++:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):e.operator==="--"?s.value instanceof y?s.value.value--:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):console.error(`Unknown increment operator ${e.operator}. Line ${e.line}`):console.error(`Variable ${n} not found. Line ${e.line}`)}_getVariableData(e,r){if(e instanceof $e){let n=this.getVariableName(e,r),s=r.getVariable(n);return s===null?(console.error(`Variable ${n} not found. Line ${e.line}`),null):s.value.getSubData(this,e.postfix,r)}if(e instanceof ke){if(e.operator==="*"){let n=this._getVariableData(e.right,r);return n instanceof Ir?n.reference.getSubData(this,e.postfix,r):(console.error(`Variable ${e.right} is not a pointer. Line ${e.line}`),null)}if(e.operator==="&"){let n=this._getVariableData(e.right,r);return new Ir(n)}}return null}_assign(e,r){let n=null,s="<var>",o=null;if(e.variable instanceof ke){let u=this._getVariableData(e.variable,r),l=this.evalExpression(e.value,r),c=e.operator;if(c==="="){if(u instanceof y||u instanceof m||u instanceof H){if(l instanceof y||l instanceof m||l instanceof H&&u.data.length===l.data.length)return void u.data.set(l.data);console.error(`Invalid assignment. Line ${e.line}`)}else if(u instanceof Ee&&l instanceof Ee&&u.buffer.byteLength-u.offset>=l.buffer.byteLength-l.offset)return void(u.buffer.byteLength%4==0?new Uint32Array(u.buffer,u.offset,u.typeInfo.size/4).set(new Uint32Array(l.buffer,l.offset,l.typeInfo.size/4)):new Uint8Array(u.buffer,u.offset,u.typeInfo.size).set(new Uint8Array(l.buffer,l.offset,l.typeInfo.size)));return console.error(`Invalid assignment. Line ${e.line}`),null}if(c==="+=")return u instanceof y||u instanceof m||u instanceof H?l instanceof y||l instanceof m||l instanceof H?void u.data.set(l.data.map((f,d)=>u.data[d]+f)):void console.error(`Invalid assignment . Line ${e.line}`):void console.error(`Invalid assignment. Line ${e.line}`);if(c==="-=")return(u instanceof y||u instanceof m||u instanceof H)&&(l instanceof y||l instanceof m||l instanceof H)?void u.data.set(l.data.map((f,d)=>u.data[d]-f)):void console.error(`Invalid assignment. Line ${e.line}`)}if(e.variable instanceof ke){if(e.variable.operator==="*"){s=this.getVariableName(e.variable.right,r);let u=r.getVariable(s);if(!(u&&u.value instanceof Ir))return void console.error(`Variable ${s} is not a pointer. Line ${e.line}`);n=u.value.reference;let l=e.variable.postfix;if(!l){let c=e.variable.right;for(;c instanceof ke;){if(c.postfix){l=c.postfix;break}c=c.right}}l&&(n=n.getSubData(this,l,r))}}else{o=e.variable.postfix,s=this.getVariableName(e.variable,r);let u=r.getVariable(s);if(u===null)return void console.error(`Variable ${s} not found. Line ${e.line}`);n=u.value}if(n instanceof Ir&&(n=n.reference),n===null)return void console.error(`Variable ${s} not found. Line ${e.line}`);let a=this.evalExpression(e.value,r),i=e.operator;if(i!=="="){let u=n.getSubData(this,o,r);if(u instanceof m&&a instanceof y){let l=u.data,c=a.value;if(i==="+=")for(let f=0;f<l.length;++f)l[f]+=c;else if(i==="-=")for(let f=0;f<l.length;++f)l[f]-=c;else if(i==="*=")for(let f=0;f<l.length;++f)l[f]*=c;else if(i==="/=")for(let f=0;f<l.length;++f)l[f]/=c;else if(i==="%=")for(let f=0;f<l.length;++f)l[f]%=c;else if(i==="&=")for(let f=0;f<l.length;++f)l[f]&=c;else if(i==="|=")for(let f=0;f<l.length;++f)l[f]|=c;else if(i==="^=")for(let f=0;f<l.length;++f)l[f]^=c;else if(i==="<<=")for(let f=0;f<l.length;++f)l[f]<<=c;else if(i===">>=")for(let f=0;f<l.length;++f)l[f]>>=c;else console.error(`Invalid operator ${i}. Line ${e.line}`)}else if(u instanceof m&&a instanceof m){let l=u.data,c=a.data;if(l.length!==c.length)return void console.error(`Vector length mismatch. Line ${e.line}`);if(i==="+=")for(let f=0;f<l.length;++f)l[f]+=c[f];else if(i==="-=")for(let f=0;f<l.length;++f)l[f]-=c[f];else if(i==="*=")for(let f=0;f<l.length;++f)l[f]*=c[f];else if(i==="/=")for(let f=0;f<l.length;++f)l[f]/=c[f];else if(i==="%=")for(let f=0;f<l.length;++f)l[f]%=c[f];else if(i==="&=")for(let f=0;f<l.length;++f)l[f]&=c[f];else if(i==="|=")for(let f=0;f<l.length;++f)l[f]|=c[f];else if(i==="^=")for(let f=0;f<l.length;++f)l[f]^=c[f];else if(i==="<<=")for(let f=0;f<l.length;++f)l[f]<<=c[f];else if(i===">>=")for(let f=0;f<l.length;++f)l[f]>>=c[f];else console.error(`Invalid operator ${i}. Line ${e.line}`)}else{if(!(u instanceof y&&a instanceof y))return void console.error(`Invalid type for ${e.operator} operator. Line ${e.line}`);i==="+="?u.value+=a.value:i==="-="?u.value-=a.value:i==="*="?u.value*=a.value:i==="/="?u.value/=a.value:i==="%="?u.value%=a.value:i==="&="?u.value&=a.value:i==="|="?u.value|=a.value:i==="^="?u.value^=a.value:i==="<<="?u.value<<=a.value:i===">>="?u.value>>=a.value:console.error(`Invalid operator ${i}. Line ${e.line}`)}return void(n instanceof Ee&&n.setDataValue(this,u,o,r))}if(n instanceof Ee)n.setDataValue(this,a,o,r);else if(o){if(!(n instanceof m||n instanceof H))return void console.error(`Variable ${s} is not a vector or matrix. Line ${e.line}`);if(o instanceof Sr){let u=this.evalExpression(o.index,r).value;if(n instanceof m){if(!(a instanceof y))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[u]=a.value}else{if(!(n instanceof H))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);{let l=this.evalExpression(o.index,r).value;if(l<0)return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);if(!(a instanceof m))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);{let c=n.typeInfo.getTypeName();if(c==="mat2x2"||c==="mat2x2f"||c==="mat2x2h"){if(!(l<2&&a.data.length===2))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[2*l]=a.data[0],n.data[2*l+1]=a.data[1]}else if(c==="mat2x3"||c==="mat2x3f"||c==="mat2x3h"){if(!(l<2&&a.data.length===3))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[3*l]=a.data[0],n.data[3*l+1]=a.data[1],n.data[3*l+2]=a.data[2]}else if(c==="mat2x4"||c==="mat2x4f"||c==="mat2x4h"){if(!(l<2&&a.data.length===4))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[4*l]=a.data[0],n.data[4*l+1]=a.data[1],n.data[4*l+2]=a.data[2],n.data[4*l+3]=a.data[3]}else if(c==="mat3x2"||c==="mat3x2f"||c==="mat3x2h"){if(!(l<3&&a.data.length===2))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[2*l]=a.data[0],n.data[2*l+1]=a.data[1]}else if(c==="mat3x3"||c==="mat3x3f"||c==="mat3x3h"){if(!(l<3&&a.data.length===3))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[3*l]=a.data[0],n.data[3*l+1]=a.data[1],n.data[3*l+2]=a.data[2]}else if(c==="mat3x4"||c==="mat3x4f"||c==="mat3x4h"){if(!(l<3&&a.data.length===4))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[4*l]=a.data[0],n.data[4*l+1]=a.data[1],n.data[4*l+2]=a.data[2],n.data[4*l+3]=a.data[3]}else if(c==="mat4x2"||c==="mat4x2f"||c==="mat4x2h"){if(!(l<4&&a.data.length===2))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[2*l]=a.data[0],n.data[2*l+1]=a.data[1]}else if(c==="mat4x3"||c==="mat4x3f"||c==="mat4x3h"){if(!(l<4&&a.data.length===3))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[3*l]=a.data[0],n.data[3*l+1]=a.data[1],n.data[3*l+2]=a.data[2]}else{if(c!=="mat4x4"&&c!=="mat4x4f"&&c!=="mat4x4h")return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);if(!(l<4&&a.data.length===4))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[4*l]=a.data[0],n.data[4*l+1]=a.data[1],n.data[4*l+2]=a.data[2],n.data[4*l+3]=a.data[3]}}}}}else if(o instanceof lr){let u=o.value;if(!(n instanceof m))return void console.error(`Invalid assignment to ${u}. Variable ${s} is not a vector. Line ${e.line}`);if(a instanceof y){if(u.length>1)return void console.error(`Invalid assignment to ${u} for variable ${s}. Line ${e.line}`);if(u==="x")n.data[0]=a.value;else if(u==="y"){if(n.data.length<2)return void console.error(`Invalid assignment to ${u} for variable ${s}. Line ${e.line}`);n.data[1]=a.value}else if(u==="z"){if(n.data.length<3)return void console.error(`Invalid assignment to ${u} for variable ${s}. Line ${e.line}`);n.data[2]=a.value}else if(u==="w"){if(n.data.length<4)return void console.error(`Invalid assignment to ${u} for variable ${s}. Line ${e.line}`);n.data[3]=a.value}}else{if(!(a instanceof m))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);if(u.length!==a.data.length)return void console.error(`Invalid assignment to ${u} for variable ${s}. Line ${e.line}`);for(let l=0;l<u.length;++l){let c=u[l];if(c==="x"||c==="r")n.data[0]=a.data[l];else if(c==="y"||c==="g"){if(a.data.length<2)return void console.error(`Invalid assignment to ${c} for variable ${s}. Line ${e.line}`);n.data[1]=a.data[l]}else if(c==="z"||c==="b"){if(a.data.length<3)return void console.error(`Invalid assignment to ${c} for variable ${s}. Line ${e.line}`);n.data[2]=a.data[l]}else{if(c!=="w"&&c!=="a")return void console.error(`Invalid assignment to ${c} for variable ${s}. Line ${e.line}`);if(a.data.length<4)return void console.error(`Invalid assignment to ${c} for variable ${s}. Line ${e.line}`);n.data[3]=a.data[l]}}}}}else n instanceof y&&a instanceof y?n.value=a.value:n instanceof m&&a instanceof m||n instanceof H&&a instanceof H?n.data.set(a.data):console.error(`Invalid assignment to ${s}. Line ${e.line}`)}_function(e,r){let n=new Ji(e);r.functions.set(e.name,n)}_const(e,r){let n=null;e.value!==null&&(n=this.evalExpression(e.value,r)),r.createVariable(e.name,n,e)}_override(e,r){let n=r.getVariable(e.name);if(n===null||n.value===null){let s=null;e.value!==null&&(s=this.evalExpression(e.value,r)),r.createVariable(e.name,s,e)}}_let(e,r){let n=null;if(e.value!==null){if(n=this.evalExpression(e.value,r),n===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof ke||(n=n.clone())}else{let s=e.type.name;if(t._defaultableTypes.has(s)){let o=new Rt(e.type,[]);n=this._evalCreate(o,r)}}r.createVariable(e.name,n,e)}_var(e,r){let n=null;if(e.value!==null){if(n=this.evalExpression(e.value,r),n===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof ke||(n=n.clone())}else{if(e.type===null)return void console.error(`Variable ${e.name} has no type. Line ${e.line}`);let s=e.type.name;if(t._defaultableTypes.has(s)||e.type instanceof Wr||e.type instanceof Nt||e.type instanceof b){let o=new Rt(e.type,[]);n=this._evalCreate(o,r)}}r.createVariable(e.name,n,e)}_switch(e,r){r=r.clone();let n=this.evalExpression(e.condition,r);if(!(n instanceof y))return console.error(`Invalid if condition. Line ${e.line}`),null;let s=null;for(let o of e.cases)if(o instanceof Io)for(let a of o.selectors){if(a instanceof wn){s=o;continue}let i=this.evalExpression(a,r);if(!(i instanceof y))return console.error(`Invalid case selector. Line ${e.line}`),null;if(i.value===n.value)return this._execStatements(o.body,r)}else o instanceof So&&(s=o);return s?this._execStatements(s.body,r):null}_if(e,r){r=r.clone();let n=this.evalExpression(e.condition,r);if(!(n instanceof y))return console.error(`Invalid if condition. Line ${e.line}`),null;if(n.value)return this._execStatements(e.body,r);for(let s of e.elseif){let o=this.evalExpression(s.condition,r);if(!(o instanceof y))return console.error(`Invalid if condition. Line ${e.line}`),null;if(o.value)return this._execStatements(s.body,r)}return e.else?this._execStatements(e.else,r):null}_getScalarValue(e){return e instanceof y?e.value:(console.error("Expected scalar value.",e),0)}_for(e,r){for(r=r.clone(),this.execStatement(e.init,r);this._getScalarValue(this.evalExpression(e.condition,r));){let n=this._execStatements(e.body,r);if(n===t._breakObj)break;if(n!==null&&n!==t._continueObj)return n;this.execStatement(e.increment,r)}return null}_loop(e,r){for(r=r.clone();;){let n=this._execStatements(e.body,r);if(n===t._breakObj)break;if(n===t._continueObj){if(e.continuing&&this._execStatements(e.continuing.body,r)===t._breakObj)break}else if(n!==null)return n}return null}_while(e,r){for(r=r.clone();this._getScalarValue(this.evalExpression(e.condition,r));){let n=this._execStatements(e.body,r);if(n===t._breakObj)break;if(n!==t._continueObj&&n!==null)return n}return null}_evalBitcast(e,r){let n=this.evalExpression(e.value,r),s=e.type;if(n instanceof y){let o=th(n.value,n.typeInfo.name,s.name);return new y(o,this.getTypeInfo(s))}if(n instanceof m){let o=n.typeInfo.getTypeName(),a="";if(o.endsWith("f"))a="f32";else if(o.endsWith("i"))a="i32";else if(o.endsWith("u"))a="u32";else if(o.endsWith("b"))a="bool";else{if(!o.endsWith("h"))return console.error(`Unknown vector type ${o}. Line ${e.line}`),null;a="f16"}let i=s.getTypeName(),u="";if(i.endsWith("f"))u="f32";else if(i.endsWith("i"))u="i32";else if(i.endsWith("u"))u="u32";else if(i.endsWith("b"))u="bool";else{if(!i.endsWith("h"))return console.error(`Unknown vector type ${u}. Line ${e.line}`),null;u="f16"}let l=(function(c,f,d){if(f===d)return c;let p=new Array(c.length);for(let T=0;T<c.length;T++)p[T]=th(c[T],f,d);return p})(Array.from(n.data),a,u);return new m(l,this.getTypeInfo(s))}return console.error(`TODO: bitcast for ${n.typeInfo.name}. Line ${e.line}`),null}_evalConst(e,r){return r.getVariableValue(e.name).clone().getSubData(this,e.postfix,r)}_evalCreate(e,r){var n;if(e instanceof Rt){if(e.type===null)return ss.void;switch(e.type.getTypeName()){case"bool":case"i32":case"u32":case"f32":case"f16":return this._callConstructorValue(e,r);case"vec2":case"vec3":case"vec4":case"vec2f":case"vec3f":case"vec4f":case"vec2h":case"vec3h":case"vec4h":case"vec2i":case"vec3i":case"vec4i":case"vec2u":case"vec3u":case"vec4u":case"vec2b":case"vec3b":case"vec4b":return this._callConstructorVec(e,r);case"mat2x2":case"mat2x2f":case"mat2x2h":case"mat2x3":case"mat2x3f":case"mat2x3h":case"mat2x4":case"mat2x4f":case"mat2x4h":case"mat3x2":case"mat3x2f":case"mat3x2h":case"mat3x3":case"mat3x3f":case"mat3x3h":case"mat3x4":case"mat3x4f":case"mat3x4h":case"mat4x2":case"mat4x2f":case"mat4x2h":case"mat4x3":case"mat4x3f":case"mat4x3h":case"mat4x4":case"mat4x4f":case"mat4x4h":return this._callConstructorMatrix(e,r)}}let s=e instanceof Rt?e.type.name:e.name,o=e instanceof Rt?this.getTypeInfo(e.type):this.getTypeInfo(e.name);if(o===null)return console.error(`Unknown type ${s}. Line ${e.line}`),null;if(o.size===0)return null;let a=new Ee(new ArrayBuffer(o.size),o,0);if(o instanceof Kt){if(e.args)for(let i=0;i<e.args.length;++i){let u=o.members[i],l=e.args[i],c=this.evalExpression(l,r);a.setData(this,c,u.type,u.offset,r)}}else if(o instanceof Zt){let i=0;if(e.args)for(let u=0;u<e.args.length;++u){let l=e.args[u],c=this.evalExpression(l,r);o.format===null&&(((n=c.typeInfo)===null||n===void 0?void 0:n.name)==="x32"?o.format=this.getTypeInfo("i32"):o.format=c.typeInfo),a.setData(this,c,o.format,i,r),i+=o.stride}}else console.error(`Unknown type "${s}". Line ${e.line}`);return e instanceof Rt?a.getSubData(this,e.postfix,r):a}_evalLiteral(e,r){let n=this.getTypeInfo(e.type),s=n.name;return s==="x32"||s==="u32"||s==="f32"||s==="f16"||s==="i32"||s==="bool"?new y(e.scalarValue,n):s==="vec2"||s==="vec3"||s==="vec4"||s==="vec2f"||s==="vec3f"||s==="vec4f"||s==="vec2h"||s==="vec3h"||s==="vec4h"||s==="vec2i"||s==="vec3i"||s==="vec4i"||s==="vec2u"||s==="vec3u"||s==="vec4u"?this._callConstructorVec(e,r):s==="mat2x2"||s==="mat2x3"||s==="mat2x4"||s==="mat3x2"||s==="mat3x3"||s==="mat3x4"||s==="mat4x2"||s==="mat4x3"||s==="mat4x4"||s==="mat2x2f"||s==="mat2x3f"||s==="mat2x4f"||s==="mat3x2f"||s==="mat3x3f"||s==="mat3x4f"||s==="mat4x2f"||s==="mat4x3f"||s==="mat4x4f"||s==="mat2x2h"||s==="mat2x3h"||s==="mat2x4h"||s==="mat3x2h"||s==="mat3x3h"||s==="mat3x4h"||s==="mat4x2h"||s==="mat4x3h"||s==="mat4x4h"?this._callConstructorMatrix(e,r):e.value}_evalVariable(e,r){let n=r.getVariableValue(e.name);return n===null?n:n.getSubData(this,e.postfix,r)}_maxFormatTypeInfo(e){let r=e[0];if(r.name==="f32")return r;for(let n=1;n<e.length;++n){let s=t._priority.get(r.name);t._priority.get(e[n].name)<s&&(r=e[n])}return r.name==="x32"?this.getTypeInfo("i32"):r}_evalUnaryOp(e,r){let n=this.evalExpression(e.right,r);if(e.operator==="&")return new Ir(n);if(e.operator==="*")return n instanceof Ir?n.reference.getSubData(this,e.postfix,r):(console.error(`Invalid dereference. Line ${e.line}`),null);let s=n instanceof y?n.value:n instanceof m?Array.from(n.data):null;switch(e.operator){case"+":{if(P(s)){let i=s.map((u,l)=>+u);return new m(i,n.typeInfo)}let o=s,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new y(+o,a)}case"-":{if(P(s)){let i=s.map((u,l)=>-u);return new m(i,n.typeInfo)}let o=s,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new y(-o,a)}case"!":{if(P(s)){let i=s.map((u,l)=>u?0:1);return new m(i,n.typeInfo)}let o=s,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new y(o?0:1,a)}case"~":{if(P(s)){let i=s.map((u,l)=>~u);return new m(i,n.typeInfo)}let o=s,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new y(~o,a)}}return console.error(`Invalid unary operator ${e.operator}. Line ${e.line}`),null}_isMatrixType(e){return e.typeInfo.getTypeName().startsWith("mat")}_isVectorType(e){return e.typeInfo.getTypeName().startsWith("vec")}_evalBinaryOp(e,r){let n=this.evalExpression(e.left,r),s=this.evalExpression(e.right,r),o=n instanceof y?n.value:n instanceof m||n instanceof H?Array.from(n.data):n instanceof Ee?n.toArray():null,a=s instanceof y?s.value:s instanceof m||s instanceof H?Array.from(s.data):s instanceof Ee?s.toArray():null;switch(e.operator){case"+":{if(P(o)&&P(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,T)=>p+f[T]);return new m(d,n.typeInfo)}if(P(o)){let c=a,f=o.map((d,p)=>d+c);return new m(f,n.typeInfo)}if(P(a)){let c=o,f=a.map((d,p)=>c+d);return new m(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(i+u,l)}case"-":{if(P(o)&&P(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,T)=>p-f[T]);return new m(d,n.typeInfo)}if(P(o)){let c=a,f=o.map((d,p)=>d-c);return new m(f,n.typeInfo)}if(P(a)){let c=o,f=a.map((d,p)=>c-d);return new m(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(i-u,l)}case"*":{if(P(o)&&P(a)){let c=o,f=a;if(this._isMatrixType(n)&&this._isMatrixType(s)){let d=(function(E,I,_,v){if(et[I.name]===void 0||et[v.name]===void 0)return null;let R=et[I.name][0],U=et[I.name][1],C=et[v.name][0];if(R!==et[v.name][1])return null;let O=new Array(C*U);for(let L=0;L<U;L++)for(let B=0;B<C;B++){let N=0;for(let D=0;D<R;D++)N+=E[D*U+L]*_[B*R+D];O[L*C+B]=N}return O})(c,n.typeInfo,f,s.typeInfo);if(d===null)return console.error(`Matrix multiplication failed. Line ${e.line}.`),null;let p=et[s.typeInfo.name][0],T=et[n.typeInfo.name][1],A=this.getTypeInfo(`mat${p}x${T}f`);return new H(d,A)}if(this._isMatrixType(n)&&this._isVectorType(s)){let d=(function(p,T,A,E){if(et[T.name]===void 0||Pi[E.name]===void 0)return null;let I=et[T.name][0],_=et[T.name][1];if(I!==A.length)return null;let v=new Array(_);for(let R=0;R<_;R++){let U=0;for(let C=0;C<I;C++)U+=p[C*_+R]*A[C];v[R]=U}return v})(c,n.typeInfo,f,s.typeInfo);return d===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new m(d,s.typeInfo)}if(this._isVectorType(n)&&this._isMatrixType(s)){let d=(function(p,T,A,E){if(Pi[T.name]===void 0||et[E.name]===void 0)return null;let I=et[E.name][0],_=et[E.name][1];if(_!==p.length)return null;let v=[];for(let R=0;R<I;R++){let U=0;for(let C=0;C<_;C++)U+=p[C]*A[C*I+R];v[R]=U}return v})(c,n.typeInfo,f,s.typeInfo);return d===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new m(d,n.typeInfo)}{if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,T)=>p*f[T]);return new m(d,n.typeInfo)}}if(P(o)){let c=a,f=o.map((d,p)=>d*c);return this._isMatrixType(n)?new H(f,n.typeInfo):new m(f,n.typeInfo)}if(P(a)){let c=o,f=a.map((d,p)=>c*d);return s instanceof H?new H(f,s.typeInfo):new m(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(i*u,l)}case"%":{if(P(o)&&P(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,T)=>p%f[T]);return new m(d,n.typeInfo)}if(P(o)){let c=a,f=o.map((d,p)=>d%c);return new m(f,n.typeInfo)}if(P(a)){let c=o,f=a.map((d,p)=>c%d);return new m(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(i%u,l)}case"/":{if(P(o)&&P(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,T)=>p/f[T]);return new m(d,n.typeInfo)}if(P(o)){let c=a,f=o.map((d,p)=>d/c);return new m(f,n.typeInfo)}if(P(a)){let c=o,f=a.map((d,p)=>c/d);return new m(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(i/u,l)}case"&":{if(P(o)&&P(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,T)=>p&f[T]);return new m(d,n.typeInfo)}if(P(o)){let c=a,f=o.map((d,p)=>d&c);return new m(f,n.typeInfo)}if(P(a)){let c=o,f=a.map((d,p)=>c&d);return new m(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(i&u,l)}case"|":{if(P(o)&&P(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,T)=>p|f[T]);return new m(d,n.typeInfo)}if(P(o)){let c=a,f=o.map((d,p)=>d|c);return new m(f,n.typeInfo)}if(P(a)){let c=o,f=a.map((d,p)=>c|d);return new m(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(i|u,l)}case"^":{if(P(o)&&P(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,T)=>p^f[T]);return new m(d,n.typeInfo)}if(P(o)){let c=a,f=o.map((d,p)=>d^c);return new m(f,n.typeInfo)}if(P(a)){let c=o,f=a.map((d,p)=>c^d);return new m(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(i^u,l)}case"<<":{if(P(o)&&P(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,T)=>p<<f[T]);return new m(d,n.typeInfo)}if(P(o)){let c=a,f=o.map((d,p)=>d<<c);return new m(f,n.typeInfo)}if(P(a)){let c=o,f=a.map((d,p)=>c<<d);return new m(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(i<<u,l)}case">>":{if(P(o)&&P(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,T)=>p>>f[T]);return new m(d,n.typeInfo)}if(P(o)){let c=a,f=o.map((d,p)=>d>>c);return new m(f,n.typeInfo)}if(P(a)){let c=o,f=a.map((d,p)=>c>>d);return new m(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(i>>u,l)}case">":if(P(o)&&P(a)){let i=o,u=a;if(i.length!==u.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c>u[f]?1:0);return new m(l,n.typeInfo)}if(P(o)){let i=a,u=o.map((l,c)=>l>i?1:0);return new m(u,n.typeInfo)}if(P(a)){let i=o,u=a.map((l,c)=>i>l?1:0);return new m(u,s.typeInfo)}return new y(o>a?1:0,this.getTypeInfo("bool"));case"<":if(P(o)&&P(a)){let i=o,u=a;if(i.length!==u.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c<u[f]?1:0);return new m(l,n.typeInfo)}if(P(o)){let i=a,u=o.map((l,c)=>l<i?1:0);return new m(u,n.typeInfo)}if(P(a)){let i=o,u=a.map((l,c)=>i<l?1:0);return new m(u,s.typeInfo)}return new y(o<a?1:0,this.getTypeInfo("bool"));case"==":if(P(o)&&P(a)){let i=o,u=a;if(i.length!==u.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c===u[f]?1:0);return new m(l,n.typeInfo)}if(P(o)){let i=a,u=o.map((l,c)=>l===i?1:0);return new m(u,n.typeInfo)}if(P(a)){let i=o,u=a.map((l,c)=>i===l?1:0);return new m(u,s.typeInfo)}return new y(o===a?1:0,this.getTypeInfo("bool"));case"!=":if(P(o)&&P(a)){let i=o,u=a;if(i.length!==u.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c!==u[f]?1:0);return new m(l,n.typeInfo)}if(P(o)){let i=a,u=o.map((l,c)=>l!==i?1:0);return new m(u,n.typeInfo)}if(P(a)){let i=o,u=a.map((l,c)=>i!==l?1:0);return new m(u,s.typeInfo)}return new y(o!==a?1:0,this.getTypeInfo("bool"));case">=":if(P(o)&&P(a)){let i=o,u=a;if(i.length!==u.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c>=u[f]?1:0);return new m(l,n.typeInfo)}if(P(o)){let i=a,u=o.map((l,c)=>l>=i?1:0);return new m(u,n.typeInfo)}if(P(a)){let i=o,u=a.map((l,c)=>i>=l?1:0);return new m(u,s.typeInfo)}return new y(o>=a?1:0,this.getTypeInfo("bool"));case"<=":if(P(o)&&P(a)){let i=o,u=a;if(i.length!==u.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c<=u[f]?1:0);return new m(l,n.typeInfo)}if(P(o)){let i=a,u=o.map((l,c)=>l<=i?1:0);return new m(u,n.typeInfo)}if(P(a)){let i=o,u=a.map((l,c)=>i<=l?1:0);return new m(u,s.typeInfo)}return new y(o<=a?1:0,this.getTypeInfo("bool"));case"&&":if(P(o)&&P(a)){let i=o,u=a;if(i.length!==u.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c&&u[f]?1:0);return new m(l,n.typeInfo)}if(P(o)){let i=a,u=o.map((l,c)=>l&&i?1:0);return new m(u,n.typeInfo)}if(P(a)){let i=o,u=a.map((l,c)=>i&&l?1:0);return new m(u,s.typeInfo)}return new y(o&&a?1:0,this.getTypeInfo("bool"));case"||":if(P(o)&&P(a)){let i=o,u=a;if(i.length!==u.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c||u[f]?1:0);return new m(l,n.typeInfo)}if(P(o)){let i=a,u=o.map((l,c)=>l||i?1:0);return new m(u,n.typeInfo)}if(P(a)){let i=o,u=a.map((l,c)=>i||l?1:0);return new m(u,s.typeInfo)}return new y(o||a?1:0,this.getTypeInfo("bool"))}return console.error(`Unknown operator ${e.operator}. Line ${e.line}`),null}_evalCall(e,r){if(e.cachedReturnValue!==null)return e.cachedReturnValue;let n=r.clone();n.currentFunctionName=e.name;let s=r.getFunction(e.name);if(!s)return e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)?this._evalCreate(e,r):(console.error(`Unknown function "${e.name}". Line ${e.line}`),null);for(let o=0;o<s.node.args.length;++o){let a=s.node.args[o],i=this.evalExpression(e.args[o],n);n.createVariable(a.name,i,a)}return this._execStatements(s.node.body,n)}_callBuiltinFunction(e,r){switch(e.name){case"all":return this.builtins.All(e,r);case"any":return this.builtins.Any(e,r);case"select":return this.builtins.Select(e,r);case"arrayLength":return this.builtins.ArrayLength(e,r);case"abs":return this.builtins.Abs(e,r);case"acos":return this.builtins.Acos(e,r);case"acosh":return this.builtins.Acosh(e,r);case"asin":return this.builtins.Asin(e,r);case"asinh":return this.builtins.Asinh(e,r);case"atan":return this.builtins.Atan(e,r);case"atanh":return this.builtins.Atanh(e,r);case"atan2":return this.builtins.Atan2(e,r);case"ceil":return this.builtins.Ceil(e,r);case"clamp":return this.builtins.Clamp(e,r);case"cos":return this.builtins.Cos(e,r);case"cosh":return this.builtins.Cosh(e,r);case"countLeadingZeros":return this.builtins.CountLeadingZeros(e,r);case"countOneBits":return this.builtins.CountOneBits(e,r);case"countTrailingZeros":return this.builtins.CountTrailingZeros(e,r);case"cross":return this.builtins.Cross(e,r);case"degrees":return this.builtins.Degrees(e,r);case"determinant":return this.builtins.Determinant(e,r);case"distance":return this.builtins.Distance(e,r);case"dot":return this.builtins.Dot(e,r);case"dot4U8Packed":return this.builtins.Dot4U8Packed(e,r);case"dot4I8Packed":return this.builtins.Dot4I8Packed(e,r);case"exp":return this.builtins.Exp(e,r);case"exp2":return this.builtins.Exp2(e,r);case"extractBits":return this.builtins.ExtractBits(e,r);case"faceForward":return this.builtins.FaceForward(e,r);case"firstLeadingBit":return this.builtins.FirstLeadingBit(e,r);case"firstTrailingBit":return this.builtins.FirstTrailingBit(e,r);case"floor":return this.builtins.Floor(e,r);case"fma":return this.builtins.Fma(e,r);case"fract":return this.builtins.Fract(e,r);case"frexp":return this.builtins.Frexp(e,r);case"insertBits":return this.builtins.InsertBits(e,r);case"inverseSqrt":return this.builtins.InverseSqrt(e,r);case"ldexp":return this.builtins.Ldexp(e,r);case"length":return this.builtins.Length(e,r);case"log":return this.builtins.Log(e,r);case"log2":return this.builtins.Log2(e,r);case"max":return this.builtins.Max(e,r);case"min":return this.builtins.Min(e,r);case"mix":return this.builtins.Mix(e,r);case"modf":return this.builtins.Modf(e,r);case"normalize":return this.builtins.Normalize(e,r);case"pow":return this.builtins.Pow(e,r);case"quantizeToF16":return this.builtins.QuantizeToF16(e,r);case"radians":return this.builtins.Radians(e,r);case"reflect":return this.builtins.Reflect(e,r);case"refract":return this.builtins.Refract(e,r);case"reverseBits":return this.builtins.ReverseBits(e,r);case"round":return this.builtins.Round(e,r);case"saturate":return this.builtins.Saturate(e,r);case"sign":return this.builtins.Sign(e,r);case"sin":return this.builtins.Sin(e,r);case"sinh":return this.builtins.Sinh(e,r);case"smoothstep":return this.builtins.SmoothStep(e,r);case"sqrt":return this.builtins.Sqrt(e,r);case"step":return this.builtins.Step(e,r);case"tan":return this.builtins.Tan(e,r);case"tanh":return this.builtins.Tanh(e,r);case"transpose":return this.builtins.Transpose(e,r);case"trunc":return this.builtins.Trunc(e,r);case"dpdx":return this.builtins.Dpdx(e,r);case"dpdxCoarse":return this.builtins.DpdxCoarse(e,r);case"dpdxFine":return this.builtins.DpdxFine(e,r);case"dpdy":return this.builtins.Dpdy(e,r);case"dpdyCoarse":return this.builtins.DpdyCoarse(e,r);case"dpdyFine":return this.builtins.DpdyFine(e,r);case"fwidth":return this.builtins.Fwidth(e,r);case"fwidthCoarse":return this.builtins.FwidthCoarse(e,r);case"fwidthFine":return this.builtins.FwidthFine(e,r);case"textureDimensions":return this.builtins.TextureDimensions(e,r);case"textureGather":return this.builtins.TextureGather(e,r);case"textureGatherCompare":return this.builtins.TextureGatherCompare(e,r);case"textureLoad":return this.builtins.TextureLoad(e,r);case"textureNumLayers":return this.builtins.TextureNumLayers(e,r);case"textureNumLevels":return this.builtins.TextureNumLevels(e,r);case"textureNumSamples":return this.builtins.TextureNumSamples(e,r);case"textureSample":return this.builtins.TextureSample(e,r);case"textureSampleBias":return this.builtins.TextureSampleBias(e,r);case"textureSampleCompare":return this.builtins.TextureSampleCompare(e,r);case"textureSampleCompareLevel":return this.builtins.TextureSampleCompareLevel(e,r);case"textureSampleGrad":return this.builtins.TextureSampleGrad(e,r);case"textureSampleLevel":return this.builtins.TextureSampleLevel(e,r);case"textureSampleBaseClampToEdge":return this.builtins.TextureSampleBaseClampToEdge(e,r);case"textureStore":return this.builtins.TextureStore(e,r);case"atomicLoad":return this.builtins.AtomicLoad(e,r);case"atomicStore":return this.builtins.AtomicStore(e,r);case"atomicAdd":return this.builtins.AtomicAdd(e,r);case"atomicSub":return this.builtins.AtomicSub(e,r);case"atomicMax":return this.builtins.AtomicMax(e,r);case"atomicMin":return this.builtins.AtomicMin(e,r);case"atomicAnd":return this.builtins.AtomicAnd(e,r);case"atomicOr":return this.builtins.AtomicOr(e,r);case"atomicXor":return this.builtins.AtomicXor(e,r);case"atomicExchange":return this.builtins.AtomicExchange(e,r);case"atomicCompareExchangeWeak":return this.builtins.AtomicCompareExchangeWeak(e,r);case"pack4x8snorm":return this.builtins.Pack4x8snorm(e,r);case"pack4x8unorm":return this.builtins.Pack4x8unorm(e,r);case"pack4xI8":return this.builtins.Pack4xI8(e,r);case"pack4xU8":return this.builtins.Pack4xU8(e,r);case"pack4x8Clamp":return this.builtins.Pack4x8Clamp(e,r);case"pack4xU8Clamp":return this.builtins.Pack4xU8Clamp(e,r);case"pack2x16snorm":return this.builtins.Pack2x16snorm(e,r);case"pack2x16unorm":return this.builtins.Pack2x16unorm(e,r);case"pack2x16float":return this.builtins.Pack2x16float(e,r);case"unpack4x8snorm":return this.builtins.Unpack4x8snorm(e,r);case"unpack4x8unorm":return this.builtins.Unpack4x8unorm(e,r);case"unpack4xI8":return this.builtins.Unpack4xI8(e,r);case"unpack4xU8":return this.builtins.Unpack4xU8(e,r);case"unpack2x16snorm":return this.builtins.Unpack2x16snorm(e,r);case"unpack2x16unorm":return this.builtins.Unpack2x16unorm(e,r);case"unpack2x16float":return this.builtins.Unpack2x16float(e,r);case"storageBarrier":return this.builtins.StorageBarrier(e,r);case"textureBarrier":return this.builtins.TextureBarrier(e,r);case"workgroupBarrier":return this.builtins.WorkgroupBarrier(e,r);case"workgroupUniformLoad":return this.builtins.WorkgroupUniformLoad(e,r);case"subgroupAdd":return this.builtins.SubgroupAdd(e,r);case"subgroupExclusiveAdd":return this.builtins.SubgroupExclusiveAdd(e,r);case"subgroupInclusiveAdd":return this.builtins.SubgroupInclusiveAdd(e,r);case"subgroupAll":return this.builtins.SubgroupAll(e,r);case"subgroupAnd":return this.builtins.SubgroupAnd(e,r);case"subgroupAny":return this.builtins.SubgroupAny(e,r);case"subgroupBallot":return this.builtins.SubgroupBallot(e,r);case"subgroupBroadcast":return this.builtins.SubgroupBroadcast(e,r);case"subgroupBroadcastFirst":return this.builtins.SubgroupBroadcastFirst(e,r);case"subgroupElect":return this.builtins.SubgroupElect(e,r);case"subgroupMax":return this.builtins.SubgroupMax(e,r);case"subgroupMin":return this.builtins.SubgroupMin(e,r);case"subgroupMul":return this.builtins.SubgroupMul(e,r);case"subgroupExclusiveMul":return this.builtins.SubgroupExclusiveMul(e,r);case"subgroupInclusiveMul":return this.builtins.SubgroupInclusiveMul(e,r);case"subgroupOr":return this.builtins.SubgroupOr(e,r);case"subgroupShuffle":return this.builtins.SubgroupShuffle(e,r);case"subgroupShuffleDown":return this.builtins.SubgroupShuffleDown(e,r);case"subgroupShuffleUp":return this.builtins.SubgroupShuffleUp(e,r);case"subgroupShuffleXor":return this.builtins.SubgroupShuffleXor(e,r);case"subgroupXor":return this.builtins.SubgroupXor(e,r);case"quadBroadcast":return this.builtins.QuadBroadcast(e,r);case"quadSwapDiagonal":return this.builtins.QuadSwapDiagonal(e,r);case"quadSwapX":return this.builtins.QuadSwapX(e,r);case"quadSwapY":return this.builtins.QuadSwapY(e,r)}let n=r.getFunction(e.name);if(n){let s=r.clone();for(let o=0;o<n.node.args.length;++o){let a=n.node.args[o],i=this.evalExpression(e.args[o],s);s.setVariable(a.name,i,a)}return this._execStatements(n.node.body,s)}return null}_callConstructorValue(e,r){if(!e.args||e.args.length===0)return new y(0,this.getTypeInfo(e.type));let n=this.evalExpression(e.args[0],r);return n.typeInfo=this.getTypeInfo(e.type),n.getSubData(this,e.postfix,r).clone()}_callConstructorVec(e,r){let n=this.getTypeInfo(e.type),s=e.type.getTypeName(),o=Pi[s];if(o===void 0)return console.error(`Invalid vec constructor ${s}. Line ${e.line}`),null;let a=[];if(e instanceof Fe)if(e.isVector){let i=e.vectorValue;for(let u of i)a.push(u)}else a.push(e.scalarValue);else if(e.args)for(let i of e.args){let u=this.evalExpression(i,r);if(u instanceof m){let l=u.data;for(let c=0;c<l.length;++c){let f=l[c];a.push(f)}}else if(u instanceof y){let l=u.value;a.push(l)}}if(e.type instanceof b&&e.type.format===null&&(e.type.format=b.f32),a.length===0){let i=new Array(o).fill(0);return new m(i,n).getSubData(this,e.postfix,r)}if(a.length===1)for(;a.length<o;)a.push(a[0]);return a.length<o?(console.error(`Invalid vec constructor. Line ${e.line}`),null):new m(a.length>o?a.slice(0,o):a,n).getSubData(this,e.postfix,r)}_callConstructorMatrix(e,r){let n=this.getTypeInfo(e.type),s=e.type.getTypeName(),o=et[s];if(o===void 0)return console.error(`Invalid matrix constructor ${s}. Line ${e.line}`),null;let a=[];if(e instanceof Fe)if(e.isVector){let i=e.vectorValue;for(let u of i)a.push(u)}else a.push(e.scalarValue);else if(e.args)for(let i of e.args){let u=this.evalExpression(i,r);u instanceof m?a.push(...u.data):u instanceof y?a.push(u.value):u instanceof H&&a.push(...u.data)}if(n instanceof cr&&n.format===null&&(n.format=this.getTypeInfo("f32")),a.length===0){let i=new Array(o[2]).fill(0);return new H(i,n).getSubData(this,e.postfix,r)}return a.length!==o[2]?(console.error(`Invalid matrix constructor. Line ${e.line}`),null):new H(a,n).getSubData(this,e.postfix,r)}};pt._numericScalarTypes=new Set(["f32","i32","u32","bool","f16"]),pt._vectorTypes=new Set(["vec2","vec3","vec4","vec2f","vec3f","vec4f","vec2i","vec3i","vec4i","vec2u","vec3u","vec4u","vec2h","vec3h","vec4h","vec2b","vec3b","vec4b"]),pt._matrixTypes=new Set(["mat2x2","mat2x3","mat2x4","mat3x2","mat3x3","mat3x4","mat4x2","mat4x3","mat4x4","mat2x2f","mat2x3f","mat2x4f","mat3x2f","mat3x3f","mat3x4f","mat4x2f","mat4x3f","mat4x4f","mat2x2h","mat2x3h","mat2x4h","mat3x2h","mat3x3h","mat3x4h","mat4x2h","mat4x3h","mat4x4h"]),pt._defaultableTypes=new Set([...pt._numericScalarTypes,...pt._vectorTypes,...pt._matrixTypes,"array"]),pt._breakObj=new Bo(new st("BREAK",null),null),pt._continueObj=new Bo(new st("CONTINUE",null),null),pt._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);var ru=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},nu=class{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new ru,this._exec=new pt,this._forwardTypeCount=0}parse(e){this._initialize(e),this._deferArrayCountEval.length=0;let r=[];for(;!this._isAtEnd();){let n=this._global_decl_or_directive();if(!n)break;r.push(n)}if(this._deferArrayCountEval.length>0){for(let n of this._deferArrayCountEval){let s=n.arrayType,o=n.countNode;if(o instanceof $e){let a=o.name,i=this._context.constants.get(a);if(i)try{let u=i.constEvaluate(this._exec);s.count=u}catch{}}}this._deferArrayCountEval.length=0}if(this._forwardTypeCount>0)for(let n of r)n.search(s=>{s instanceof Fo||s instanceof vn?s.type=this._forwardType(s.type):s instanceof Wr?s.format=this._forwardType(s.format):s instanceof It||s instanceof Vr||s instanceof bn?s.type=this._forwardType(s.type):s instanceof zr?s.returnType=this._forwardType(s.returnType):s instanceof Co&&(s.type=this._forwardType(s.type))});return r}_forwardType(e){if(e instanceof To){let r=this._getType(e.name);if(r)return r}else e instanceof vn?e.type=this._forwardType(e.type):e instanceof Wr&&(e.format=this._forwardType(e.format));return e}_initialize(e){if(e)if(typeof e=="string"){let r=new Po(e);this._tokens=r.scanTokens()}else this._tokens=e;else this._tokens=[];this._current=0}_updateNode(e,r){return e.line=r??this._currentLine,e}_error(e,r){return new Error(`${r}. Line: ${e.line}`)}_isAtEnd(){return this._current>=this._tokens.length||this._peek().type===h.eof}_match(e){if(e instanceof g)return!!this._check(e)&&(this._advance(),!0);for(let r=0,n=e.length;r<n;++r){let s=e[r];if(this._check(s))return this._advance(),!0}return!1}_consume(e,r){if(this._check(e))return this._advance();throw this._error(this._peek(),r)}_check(e){if(this._isAtEnd())return!1;let r=this._peek();if(Array.isArray(e)){let n=r.type,s=!1;for(let o of e){if(n===o)return!0;o===h.tokens.name&&(s=!0)}if(s){let o=h.tokens.name.rule.exec(r.lexeme);if(o&&o.index===0&&o[0]===r.lexeme)return!0}return!1}if(r.type===e)return!0;if(e===h.tokens.name){let n=h.tokens.name.rule.exec(r.lexeme);return n&&n.index===0&&n[0]===r.lexeme}return!1}_advance(){var e,r;return this._currentLine=(r=(e=this._peek())===null||e===void 0?void 0:e.line)!==null&&r!==void 0?r:-1,this._isAtEnd()||this._current++,this._previous()}_peek(){return this._tokens[this._current]}_previous(){return this._tokens[this._current-1]}_global_decl_or_directive(){for(;this._match(h.tokens.semicolon)&&!this._isAtEnd(););if(this._match(h.keywords.const_assert)){let r=this._global_assert();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([r]),r}if(this._match(h.keywords.alias)){let r=this._type_alias();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([r]),r}if(this._match(h.keywords.diagnostic)){let r=this._diagnostic();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([r]),r}if(this._match(h.keywords.requires)){let r=this._requires_directive();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([r]),r}if(this._match(h.keywords.enable)){let r=this._enable_directive();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([r]),r}let e=this._attribute();if(this._check(h.keywords.var)){let r=this._global_variable_decl();return r!=null&&(r.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([r]),r}if(this._check(h.keywords.override)){let r=this._override_variable_decl();return r!=null&&(r.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([r]),r}if(this._check(h.keywords.let)){let r=this._global_let_decl();return r!=null&&(r.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([r]),r}if(this._check(h.keywords.const)){let r=this._global_const_decl();return r!=null&&(r.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([r]),r}if(this._check(h.keywords.struct)){let r=this._struct_decl();return r!=null&&(r.attributes=e),this._exec.reflection.updateAST([r]),r}if(this._check(h.keywords.fn)){let r=this._function_decl();return r!=null&&(r.attributes=e),this._exec.reflection.updateAST([r]),r}return null}_function_decl(){if(!this._match(h.keywords.fn))return null;let e=this._currentLine,r=this._consume(h.tokens.ident,"Expected function name.").toString();this._consume(h.tokens.paren_left,"Expected '(' for function arguments.");let n=[];if(!this._check(h.tokens.paren_right))do{if(this._check(h.tokens.paren_right))break;let i=this._attribute(),u=this._consume(h.tokens.name,"Expected argument name.").toString();this._consume(h.tokens.colon,"Expected ':' for argument type.");let l=this._attribute(),c=this._type_decl();c!=null&&(c.attributes=l,n.push(this._updateNode(new Co(u,c,i))))}while(this._match(h.tokens.comma));this._consume(h.tokens.paren_right,"Expected ')' after function arguments.");let s=null;if(this._match(h.tokens.arrow)){let i=this._attribute();s=this._type_decl(),s!=null&&(s.attributes=i)}let o=this._compound_statement(),a=this._currentLine;return this._updateNode(new zr(r,n,s,o,e,a),e)}_compound_statement(){let e=[];for(this._consume(h.tokens.brace_left,"Expected '{' for block.");!this._check(h.tokens.brace_right);){let r=this._statement();r!==null&&e.push(r)}return this._consume(h.tokens.brace_right,"Expected '}' for block."),e}_statement(){for(;this._match(h.tokens.semicolon)&&!this._isAtEnd(););if(this._check(h.tokens.attr)&&this._attribute(),this._check(h.keywords.if))return this._if_statement();if(this._check(h.keywords.switch))return this._switch_statement();if(this._check(h.keywords.loop))return this._loop_statement();if(this._check(h.keywords.for))return this._for_statement();if(this._check(h.keywords.while))return this._while_statement();if(this._check(h.keywords.continuing))return this._continuing_statement();if(this._check(h.keywords.static_assert))return this._static_assert_statement();if(this._check(h.tokens.brace_left))return this._compound_statement();let e=null;if(this._check(h.keywords.return))e=this._return_statement();else if(this._check([h.keywords.var,h.keywords.let,h.keywords.const]))e=this._variable_statement();else if(this._match(h.keywords.discard))e=this._updateNode(new Yi);else if(this._match(h.keywords.break)){let r=this._updateNode(new vo);if(this._currentLoop.length>0){let n=this._currentLoop[this._currentLoop.length-1];r.loopId=n.id}e=r,this._check(h.keywords.if)&&(this._advance(),r.condition=this._optional_paren_expression())}else if(this._match(h.keywords.continue)){let r=this._updateNode(new wo);if(!(this._currentLoop.length>0))throw this._error(this._peek(),"Continue statement must be inside a loop");{let n=this._currentLoop[this._currentLoop.length-1];r.loopId=n.id}e=r}else e=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement();return e!=null&&this._consume(h.tokens.semicolon,"Expected ';' after statement."),e}_static_assert_statement(){if(!this._match(h.keywords.static_assert))return null;let e=this._currentLine,r=this._optional_paren_expression();return this._updateNode(new lo(r),e)}_global_assert(){let e=this._currentLine,r=this._short_circuit_or_expression();return this._updateNode(new lo(r),e)}_while_statement(){if(!this._match(h.keywords.while))return null;let e=this._updateNode(new fo(null,null));return this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(h.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_continuing_statement(){let e=this._currentLoop.length>0?this._currentLoop[this._currentLoop.length-1].id:-1;if(!this._match(h.keywords.continuing))return null;let r=this._currentLine,n=this._compound_statement();return this._updateNode(new Qn(n,e),r)}_for_statement(){if(!this._match(h.keywords.for))return null;this._consume(h.tokens.paren_left,"Expected '('.");let e=this._updateNode(new ho(null,null,null,null));return this._currentLoop.push(e),e.init=this._check(h.tokens.semicolon)?null:this._for_init(),this._consume(h.tokens.semicolon,"Expected ';'."),e.condition=this._check(h.tokens.semicolon)?null:this._short_circuit_or_expression(),this._consume(h.tokens.semicolon,"Expected ';'."),e.increment=this._check(h.tokens.paren_right)?null:this._for_increment(),this._consume(h.tokens.paren_right,"Expected ')'."),this._check(h.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_for_init(){return this._variable_statement()||this._func_call_statement()||this._assignment_statement()}_for_increment(){return this._func_call_statement()||this._increment_decrement_statement()||this._assignment_statement()}_variable_statement(){if(this._check(h.keywords.var)){let e=this._variable_decl();if(e===null)throw this._error(this._peek(),"Variable declaration expected.");let r=null;return this._match(h.tokens.equal)&&(r=this._short_circuit_or_expression()),this._updateNode(new It(e.name,e.type,e.storage,e.access,r),e.line)}if(this._match(h.keywords.let)){let e=this._currentLine,r=this._consume(h.tokens.name,"Expected name for let.").toString(),n=null;if(this._match(h.tokens.colon)){let o=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=o)}this._consume(h.tokens.equal,"Expected '=' for let.");let s=this._short_circuit_or_expression();return this._updateNode(new Vr(r,n,null,null,s),e)}if(this._match(h.keywords.const)){let e=this._currentLine,r=this._consume(h.tokens.name,"Expected name for const.").toString(),n=null;if(this._match(h.tokens.colon)){let o=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=o)}this._consume(h.tokens.equal,"Expected '=' for const.");let s=this._short_circuit_or_expression();return n===null&&s instanceof Fe&&(n=s.type),this._updateNode(new bn(r,n,null,null,s),e)}return null}_increment_decrement_statement(){let e=this._current,r=this._unary_expression();if(r===null)return null;if(!this._check(h.increment_operators))return this._current=e,null;let n=this._consume(h.increment_operators,"Expected increment operator");return this._updateNode(new mo(n.type===h.tokens.plus_plus?yn.increment:yn.decrement,r))}_assignment_statement(){let e=null,r=this._currentLine;if(this._check(h.tokens.brace_right))return null;let n=this._match(h.tokens.underscore);if(n||(e=this._unary_expression()),!n&&e===null)return null;let s=this._consume(h.assignment_operators,"Expected assignment operator."),o=this._short_circuit_or_expression();return this._updateNode(new po(Zn.parse(s.lexeme),e,o),r)}_func_call_statement(){if(!this._check(h.tokens.ident))return null;let e=this._currentLine,r=this._current,n=this._consume(h.tokens.ident,"Expected function name."),s=this._argument_expression_list();return s===null?(this._current=r,null):this._updateNode(new ts(n.lexeme,s),e)}_loop_statement(){if(!this._match(h.keywords.loop))return null;this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Expected '{' for loop.");let e=this._updateNode(new go([],null));this._currentLoop.push(e);let r=this._statement();for(;r!==null;){if(Array.isArray(r))for(let n of r)e.body.push(n);else e.body.push(r);if(r instanceof Qn){e.continuing=r;break}r=this._statement()}return this._currentLoop.pop(),this._consume(h.tokens.brace_right,"Expected '}' for loop."),e}_switch_statement(){if(!this._match(h.keywords.switch))return null;let e=this._updateNode(new xo(null,[]));if(this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Expected '{' for switch."),e.cases=this._switch_body(),e.cases===null||e.cases.length===0)throw this._error(this._previous(),"Expected 'case' or 'default'.");return this._consume(h.tokens.brace_right,"Expected '}' for switch."),this._currentLoop.pop(),e}_switch_body(){let e=[],r=!1;for(;this._check([h.keywords.default,h.keywords.case]);){if(this._match(h.keywords.case)){let n=this._case_selectors();for(let o of n)if(o instanceof wn){if(r)throw this._error(this._previous(),"Multiple default cases in switch statement.");r=!0;break}this._match(h.tokens.colon),this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Exected '{' for switch case.");let s=this._case_body();this._consume(h.tokens.brace_right,"Exected '}' for switch case."),e.push(this._updateNode(new Io(n,s)))}if(this._match(h.keywords.default)){if(r)throw this._error(this._previous(),"Multiple default cases in switch statement.");this._match(h.tokens.colon),this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Exected '{' for switch default.");let n=this._case_body();this._consume(h.tokens.brace_right,"Exected '}' for switch default."),e.push(this._updateNode(new So(n)))}}return e}_case_selectors(){let e=[];for(this._match(h.keywords.default)?e.push(this._updateNode(new wn)):e.push(this._shift_expression());this._match(h.tokens.comma);)this._match(h.keywords.default)?e.push(this._updateNode(new wn)):e.push(this._shift_expression());return e}_case_body(){if(this._match(h.keywords.fallthrough))return this._consume(h.tokens.semicolon,"Expected ';'"),[];let e=this._statement();if(e===null)return[];Array.isArray(e)||(e=[e]);let r=this._case_body();return r.length===0?e:[...e,r[0]]}_if_statement(){if(!this._match(h.keywords.if))return null;let e=this._currentLine,r=this._optional_paren_expression();this._check(h.tokens.attr)&&this._attribute();let n=this._compound_statement(),s=[];this._match_elseif()&&(this._check(h.tokens.attr)&&this._attribute(),s=this._elseif_statement(s));let o=null;return this._match(h.keywords.else)&&(this._check(h.tokens.attr)&&this._attribute(),o=this._compound_statement()),this._updateNode(new yo(r,n,s,o),e)}_match_elseif(){return this._tokens[this._current].type===h.keywords.else&&this._tokens[this._current+1].type===h.keywords.if&&(this._advance(),this._advance(),!0)}_elseif_statement(e=[]){let r=this._optional_paren_expression(),n=this._compound_statement();return e.push(this._updateNode(new qi(r,n))),this._match_elseif()&&(this._check(h.tokens.attr)&&this._attribute(),this._elseif_statement(e)),e}_return_statement(){if(!this._match(h.keywords.return))return null;let e=this._short_circuit_or_expression();return this._updateNode(new _o(e))}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(h.tokens.or_or);)e=this._updateNode(new mt(this._previous().toString(),e,this._short_circuit_and_expr()));return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(h.tokens.and_and);)e=this._updateNode(new mt(this._previous().toString(),e,this._inclusive_or_expression()));return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(h.tokens.or);)e=this._updateNode(new mt(this._previous().toString(),e,this._exclusive_or_expression()));return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(h.tokens.xor);)e=this._updateNode(new mt(this._previous().toString(),e,this._and_expression()));return e}_and_expression(){let e=this._equality_expression();for(;this._match(h.tokens.and);)e=this._updateNode(new mt(this._previous().toString(),e,this._equality_expression()));return e}_equality_expression(){let e=this._relational_expression();return this._match([h.tokens.equal_equal,h.tokens.not_equal])?this._updateNode(new mt(this._previous().toString(),e,this._relational_expression())):e}_relational_expression(){let e=this._shift_expression();for(;this._match([h.tokens.less_than,h.tokens.greater_than,h.tokens.less_than_equal,h.tokens.greater_than_equal]);)e=this._updateNode(new mt(this._previous().toString(),e,this._shift_expression()));return e}_shift_expression(){let e=this._additive_expression();for(;this._match([h.tokens.shift_left,h.tokens.shift_right]);)e=this._updateNode(new mt(this._previous().toString(),e,this._additive_expression()));return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([h.tokens.plus,h.tokens.minus]);)e=this._updateNode(new mt(this._previous().toString(),e,this._multiplicative_expression()));return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([h.tokens.star,h.tokens.forward_slash,h.tokens.modulo]);)e=this._updateNode(new mt(this._previous().toString(),e,this._unary_expression()));return e}_unary_expression(){return this._match([h.tokens.minus,h.tokens.bang,h.tokens.tilde,h.tokens.star,h.tokens.and])?this._updateNode(new ke(this._previous().toString(),this._unary_expression())):this._singular_expression()}_singular_expression(){let e=this._primary_expression(),r=this._postfix_expression();return r&&(e.postfix=r),e}_postfix_expression(){if(this._match(h.tokens.bracket_left)){let e=this._short_circuit_or_expression();this._consume(h.tokens.bracket_right,"Expected ']'.");let r=this._updateNode(new Sr(e)),n=this._postfix_expression();return n&&(r.postfix=n),r}if(this._match(h.tokens.period)){let e=this._consume(h.tokens.name,"Expected member name."),r=this._postfix_expression(),n=this._updateNode(new lr(e.lexeme));return r&&(n.postfix=r),n}return null}_getStruct(e){var r;if(this._context.aliases.has(e)){let n=(r=this._context.aliases.get(e))===null||r===void 0?void 0:r.type;return n??null}if(this._context.structs.has(e)){let n=this._context.structs.get(e);return n??null}return null}_getType(e){let r=this._getStruct(e);if(r!==null)return r;switch(e){case"void":return S.void;case"bool":return S.bool;case"i32":return S.i32;case"u32":return S.u32;case"f32":return S.f32;case"f16":return S.f16;case"vec2f":return b.vec2f;case"vec3f":return b.vec3f;case"vec4f":return b.vec4f;case"vec2i":return b.vec2i;case"vec3i":return b.vec3i;case"vec4i":return b.vec4i;case"vec2u":return b.vec2u;case"vec3u":return b.vec3u;case"vec4u":return b.vec4u;case"vec2h":return b.vec2h;case"vec3h":return b.vec3h;case"vec4h":return b.vec4h;case"mat2x2f":return b.mat2x2f;case"mat2x3f":return b.mat2x3f;case"mat2x4f":return b.mat2x4f;case"mat3x2f":return b.mat3x2f;case"mat3x3f":return b.mat3x3f;case"mat3x4f":return b.mat3x4f;case"mat4x2f":return b.mat4x2f;case"mat4x3f":return b.mat4x3f;case"mat4x4f":return b.mat4x4f;case"mat2x2h":return b.mat2x2h;case"mat2x3h":return b.mat2x3h;case"mat2x4h":return b.mat2x4h;case"mat3x2h":return b.mat3x2h;case"mat3x3h":return b.mat3x3h;case"mat3x4h":return b.mat3x4h;case"mat4x2h":return b.mat4x2h;case"mat4x3h":return b.mat4x3h;case"mat4x4h":return b.mat4x4h;case"mat2x2i":return b.mat2x2i;case"mat2x3i":return b.mat2x3i;case"mat2x4i":return b.mat2x4i;case"mat3x2i":return b.mat3x2i;case"mat3x3i":return b.mat3x3i;case"mat3x4i":return b.mat3x4i;case"mat4x2i":return b.mat4x2i;case"mat4x3i":return b.mat4x3i;case"mat4x4i":return b.mat4x4i;case"mat2x2u":return b.mat2x2u;case"mat2x3u":return b.mat2x3u;case"mat2x4u":return b.mat2x4u;case"mat3x2u":return b.mat3x2u;case"mat3x3u":return b.mat3x3u;case"mat3x4u":return b.mat3x4u;case"mat4x2u":return b.mat4x2u;case"mat4x3u":return b.mat4x3u;case"mat4x4u":return b.mat4x4u}return null}_validateTypeRange(e,r){if(r.name==="i32"){if(e<-2147483648||e>2147483647)throw this._error(this._previous(),`Value out of range for i32: ${e}`)}else if(r.name==="u32"&&(e<0||e>4294967295))throw this._error(this._previous(),`Value out of range for u32: ${e}`)}_primary_expression(){if(this._match(h.tokens.ident)){let n=this._previous().toString();if(this._check(h.tokens.paren_left)){let s=this._argument_expression_list(),o=this._getType(n);return o!==null?this._updateNode(new Rt(o,s)):this._updateNode(new ns(n,s))}if(this._context.constants.has(n)){let s=this._context.constants.get(n);if(s)return this._updateNode(new ko(n,s.value))}return this._updateNode(new $e(n))}if(this._match(h.tokens.int_literal)){let n=this._previous().toString(),s=n.endsWith("i")||n.endsWith("i")?S.i32:n.endsWith("u")||n.endsWith("U")?S.u32:S.x32,o=parseInt(n);return this._validateTypeRange(o,s),this._updateNode(new Fe(new y(o,this._exec.getTypeInfo(s)),s))}if(this._match(h.tokens.uint_literal)){let n=parseInt(this._previous().toString());return this._validateTypeRange(n,S.u32),this._updateNode(new Fe(new y(n,this._exec.getTypeInfo(S.u32)),S.u32))}if(this._match([h.tokens.decimal_float_literal,h.tokens.hex_float_literal])){let n=this._previous().toString(),s=n.endsWith("h");s&&(n=n.substring(0,n.length-1));let o=parseFloat(n);this._validateTypeRange(o,s?S.f16:S.f32);let a=s?S.f16:S.f32;return this._updateNode(new Fe(new y(o,this._exec.getTypeInfo(a)),a))}if(this._match([h.keywords.true,h.keywords.false])){let n=this._previous().toString()===h.keywords.true.rule;return this._updateNode(new Fe(new y(n?1:0,this._exec.getTypeInfo(S.bool)),S.bool))}if(this._check(h.tokens.paren_left))return this._paren_expression();if(this._match(h.keywords.bitcast)){this._consume(h.tokens.less_than,"Expected '<'.");let n=this._type_decl();this._consume(h.tokens.greater_than,"Expected '>'.");let s=this._paren_expression();return this._updateNode(new Eo(n,s))}let e=this._type_decl(),r=this._argument_expression_list();return this._updateNode(new Rt(e,r))}_argument_expression_list(){if(!this._match(h.tokens.paren_left))return null;let e=[];do{if(this._check(h.tokens.paren_right))break;let r=this._short_circuit_or_expression();e.push(r)}while(this._match(h.tokens.comma));return this._consume(h.tokens.paren_right,"Expected ')' for argument list"),e}_optional_paren_expression(){let e=this._match(h.tokens.paren_left),r=this._short_circuit_or_expression();return r.hasParen=e,e&&this._consume(h.tokens.paren_right,"Expected ')'."),r}_paren_expression(){this._consume(h.tokens.paren_left,"Expected '('.");let e=this._short_circuit_or_expression();return this._consume(h.tokens.paren_right,"Expected ')'."),e.hasParen=!0,e}_struct_decl(){if(!this._match(h.keywords.struct))return null;let e=this._currentLine,r=this._consume(h.tokens.ident,"Expected name for struct.").toString();this._consume(h.tokens.brace_left,"Expected '{' for struct body.");let n=[];for(;!this._check(h.tokens.brace_right);){let a=this._attribute(),i=this._consume(h.tokens.name,"Expected variable name.").toString();this._consume(h.tokens.colon,"Expected ':' for struct member type.");let u=this._attribute(),l=this._type_decl();l!=null&&(l.attributes=u),this._check(h.tokens.brace_right)?this._match(h.tokens.comma):this._consume(h.tokens.comma,"Expected ',' for struct member."),n.push(this._updateNode(new Fo(i,l,a)))}this._consume(h.tokens.brace_right,"Expected '}' after struct body.");let s=this._currentLine,o=this._updateNode(new Nt(r,n,e,s),e);return this._context.structs.set(r,o),o}_global_variable_decl(){let e=this._variable_decl();if(!e)return null;if(this._match(h.tokens.equal)){let r=this._const_expression();e.value=r}if(e.type!==null&&e.value instanceof Fe){if(e.value.type.name!=="x32"&&e.type.getTypeName()!==e.value.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${e.value.type.name} to ${e.type.name}`);e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type),e.value.type=e.type}else e.type===null&&e.value instanceof Fe&&(e.type=e.value.type.name==="x32"?S.i32:e.value.type,e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type));return e}_override_variable_decl(){let e=this._override_decl();return e&&this._match(h.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){var e;if(!this._match(h.keywords.const))return null;let r=this._consume(h.tokens.name,"Expected variable name"),n=this._currentLine,s=null;if(this._match(h.tokens.colon)){let u=this._attribute();s=this._type_decl(),s!=null&&(s.attributes=u)}let o=null;this._consume(h.tokens.equal,"const declarations require an assignment");let a=this._short_circuit_or_expression();try{let u=[S.f32],l=a.constEvaluate(this._exec,u);l instanceof y&&this._validateTypeRange(l.value,u[0]),u[0]instanceof b&&u[0].format===null&&l.typeInfo instanceof cr&&l.typeInfo.format!==null&&(l.typeInfo.format.name==="f16"?u[0].format=S.f16:l.typeInfo.format.name==="f32"?u[0].format=S.f32:l.typeInfo.format.name==="i32"?u[0].format=S.i32:l.typeInfo.format.name==="u32"?u[0].format=S.u32:l.typeInfo.format.name==="bool"?u[0].format=S.bool:console.error(`TODO: implement template format type ${l.typeInfo.format.name}`)),o=this._updateNode(new Fe(l,u[0])),this._exec.context.setVariable(r.toString(),l)}catch{o=a}if(s!==null&&o instanceof Fe){if(o.type.name!=="x32"&&s.getTypeName()!==o.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${o.type.name} to ${s.name}`);o.type=s,o.isScalar&&this._validateTypeRange(o.scalarValue,o.type)}else s===null&&o instanceof Fe&&(s=(e=o?.type)!==null&&e!==void 0?e:S.f32,s===S.x32&&(s=S.i32));let i=this._updateNode(new bn(r.toString(),s,"","",o),n);return this._context.constants.set(i.name,i),i}_global_let_decl(){if(!this._match(h.keywords.let))return null;let e=this._currentLine,r=this._consume(h.tokens.name,"Expected variable name"),n=null;if(this._match(h.tokens.colon)){let o=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=o)}let s=null;if(this._match(h.tokens.equal)&&(s=this._const_expression()),n!==null&&s instanceof Fe){if(s.type.name!=="x32"&&n.getTypeName()!==s.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${s.type.name} to ${n.name}`);s.type=n}else n===null&&s instanceof Fe&&(n=s.type.name==="x32"?S.i32:s.type);return s instanceof Fe&&s.isScalar&&this._validateTypeRange(s.scalarValue,n),this._updateNode(new Vr(r.toString(),n,"","",s),e)}_const_expression(){return this._short_circuit_or_expression()}_variable_decl(){if(!this._match(h.keywords.var))return null;let e=this._currentLine,r="",n="";this._match(h.tokens.less_than)&&(r=this._consume(h.storage_class,"Expected storage_class.").toString(),this._match(h.tokens.comma)&&(n=this._consume(h.access_mode,"Expected access_mode.").toString()),this._consume(h.tokens.greater_than,"Expected '>'."));let s=this._consume(h.tokens.name,"Expected variable name"),o=null;if(this._match(h.tokens.colon)){let a=this._attribute();o=this._type_decl(),o!=null&&(o.attributes=a)}return this._updateNode(new It(s.toString(),o,r,n,null),e)}_override_decl(){if(!this._match(h.keywords.override))return null;let e=this._consume(h.tokens.name,"Expected variable name"),r=null;if(this._match(h.tokens.colon)){let n=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=n)}return this._updateNode(new es(e.toString(),r,null))}_diagnostic(){this._consume(h.tokens.paren_left,"Expected '('");let e=this._consume(h.tokens.ident,"Expected severity control name.");this._consume(h.tokens.comma,"Expected ','");let r=this._consume(h.tokens.ident,"Expected diagnostic rule name.").toString();return this._match(h.tokens.period)&&(r+=`.${this._consume(h.tokens.ident,"Expected diagnostic message.").toString()}`),this._consume(h.tokens.paren_right,"Expected ')'"),this._updateNode(new bo(e.toString(),r))}_enable_directive(){let e=this._consume(h.tokens.ident,"identity expected.");return this._updateNode(new Xi(e.toString()))}_requires_directive(){let e=[this._consume(h.tokens.ident,"identity expected.").toString()];for(;this._match(h.tokens.comma);){let r=this._consume(h.tokens.ident,"identity expected.");e.push(r.toString())}return this._updateNode(new ji(e))}_type_alias(){let e=this._consume(h.tokens.ident,"identity expected.");this._consume(h.tokens.equal,"Expected '=' for type alias.");let r=this._type_decl();if(r===null)throw this._error(this._peek(),"Expected Type for Alias.");this._context.aliases.has(r.name)&&(r=this._context.aliases.get(r.name).type);let n=this._updateNode(new rs(e.toString(),r));return this._context.aliases.set(n.name,n),n}_type_decl(){var e,r,n;if(this._check([h.tokens.ident,...h.texel_format,h.keywords.bool,h.keywords.f32,h.keywords.i32,h.keywords.u32])){let a=this._advance().toString();if(this._context.structs.has(a))return(e=this._context.structs.get(a))!==null&&e!==void 0?e:null;if(this._context.aliases.has(a))return(n=(r=this._context.aliases.get(a))===null||r===void 0?void 0:r.type)!==null&&n!==void 0?n:null;if(!this._getType(a)){let i=this._updateNode(new To(a));return this._forwardTypeCount++,i}return this._updateNode(new S(a))}let s=this._texture_sampler_types();if(s)return s;if(this._check(h.template_types)){let a=this._advance().toString(),i=null,u=null;return this._match(h.tokens.less_than)&&(i=this._type_decl(),u=null,this._match(h.tokens.comma)&&(u=this._consume(h.access_mode,"Expected access_mode for pointer").toString()),this._consume(h.tokens.greater_than,"Expected '>' for type.")),this._updateNode(new b(a,i,u))}if(this._match(h.keywords.ptr)){let a=this._previous().toString();this._consume(h.tokens.less_than,"Expected '<' for pointer.");let i=this._consume(h.storage_class,"Expected storage_class for pointer");this._consume(h.tokens.comma,"Expected ',' for pointer.");let u=this._type_decl(),l=null;return this._match(h.tokens.comma)&&(l=this._consume(h.access_mode,"Expected access_mode for pointer").toString()),this._consume(h.tokens.greater_than,"Expected '>' for pointer."),this._updateNode(new vn(a,i.toString(),u,l))}let o=this._attribute();if(this._match(h.keywords.array)){let a=null,i=-1,u=this._previous(),l=null;if(this._match(h.tokens.less_than)){a=this._type_decl(),this._context.aliases.has(a.name)&&(a=this._context.aliases.get(a.name).type);let f="";if(this._match(h.tokens.comma)){l=this._shift_expression();try{f=l.constEvaluate(this._exec).toString(),l=null}catch{f="1"}}this._consume(h.tokens.greater_than,"Expected '>' for array."),i=f?parseInt(f):0}let c=this._updateNode(new Wr(u.toString(),o,a,i));return l&&this._deferArrayCountEval.push({arrayType:c,countNode:l}),c}return null}_texture_sampler_types(){if(this._match(h.sampler_type))return this._updateNode(new Gr(this._previous().toString(),null,null));if(this._match(h.depth_texture_type))return this._updateNode(new Gr(this._previous().toString(),null,null));if(this._match(h.sampled_texture_type)||this._match(h.multisampled_texture_type)){let e=this._previous();this._consume(h.tokens.less_than,"Expected '<' for sampler type.");let r=this._type_decl();return this._consume(h.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new Gr(e.toString(),r,null))}if(this._match(h.storage_texture_type)){let e=this._previous();this._consume(h.tokens.less_than,"Expected '<' for sampler type.");let r=this._consume(h.texel_format,"Invalid texel format.").toString();this._consume(h.tokens.comma,"Expected ',' after texel format.");let n=this._consume(h.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(h.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new Gr(e.toString(),r,n))}return null}_attribute(){let e=[];for(;this._match(h.tokens.attr);){let r=this._consume(h.attribute_name,"Expected attribute name"),n=this._updateNode(new Uo(r.toString(),null));if(this._match(h.tokens.paren_left)){if(n.value=this._consume(h.literal_or_ident,"Expected attribute value").toString(),this._check(h.tokens.comma)){this._advance();do{let s=this._consume(h.literal_or_ident,"Expected attribute value").toString();Array.isArray(n.value)||(n.value=[n.value]),n.value.push(s)}while(this._match(h.tokens.comma))}this._consume(h.tokens.paren_right,"Expected ')'")}e.push(n)}return e.length===0?null:e}},su=class extends $r{constructor(e){super(),e!==void 0&&this.update(e)}update(e){let r=new nu().parse(e);this.updateAST(r)}};function Mr(t,e){return Object.fromEntries(e.map(r=>{let n=ip(t,r,0);return[r.name,{typeDefinition:n,group:r.group,binding:r.binding,size:n.size}]}))}function uh(t,e,r){return{fields:Object.fromEntries(e.members.map(s=>[s.name,{offset:s.offset,type:uu(t,s.type,0)}])),size:e.size,offset:r}}function np(t){if(t.name.includes("depth"))return"depth";switch(t.format?.name){case"f32":return"float";case"i32":return"sint";case"u32":return"uint";default:throw new Error("unknown texture sample type")}}function rh(t){return t.name.includes("2d_array")?"2d-array":t.name.includes("cube_array")?"cube-array":t.name.includes("3d")?"3d":t.name.includes("1d")?"1d":t.name.includes("cube")?"cube":"2d"}function sp(t){switch(t.access){case"read":return"read-only";case"write":return"write-only";case"read_write":return"read-write";default:throw new Error("unknonw storage texture access")}}function op(t){return t.name.endsWith("_comparison")?"comparison":"filtering"}function ap(t,e){let{binding:r,access:n,type:s}=t;switch(t.resourceType){case Ae.Uniform:return{binding:r,visibility:e,buffer:{...t.size&&{minBindingSize:t.size}}};case Ae.Storage:return{binding:r,visibility:e,buffer:{type:n===""||n==="read"?"read-only-storage":"storage",...t.size&&{minBindingSize:t.size}}};case Ae.Texture:{if(s.name==="texture_external")return{binding:r,visibility:e,externalTexture:{}};let o=s.name.includes("multisampled");return{binding:r,visibility:e,texture:{sampleType:np(s),viewDimension:rh(s),multisampled:o}}}case Ae.Sampler:return{binding:r,visibility:e,sampler:{type:op(s)}};case Ae.StorageTexture:return{binding:r,visibility:e,storageTexture:{access:sp(s),format:s.format.name,viewDimension:rh(s)}};default:throw new Error("unknown resource type")}}function Oi(t,e){let r={};for(let n of t)r[n.name]={stage:e,resources:n.resources.map(s=>{let{name:o,group:a}=s;return{name:o,group:a,entry:ap(s,e)}})};return r}function Ct(t){let e=new su(t),r=Object.fromEntries(e.structs.map(f=>[f.name,uh(e,f,0)])),n=Mr(e,e.uniforms),s=Mr(e,e.immediates),o=Mr(e,e.storage.filter(f=>f.resourceType===Ae.Storage)),a=Mr(e,e.storage.filter(f=>f.resourceType===Ae.StorageTexture)),i=Mr(e,e.textures.filter(f=>f.type.name!=="texture_external")),u=Mr(e,e.textures.filter(f=>f.type.name==="texture_external")),l=Mr(e,e.samplers),c={...Oi(e.entry.vertex,GPUShaderStage.VERTEX),...Oi(e.entry.fragment,GPUShaderStage.FRAGMENT),...Oi(e.entry.compute,GPUShaderStage.COMPUTE)};return{externalTextures:u,immediates:s,samplers:l,structs:r,storages:o,storageTextures:a,textures:i,uniforms:n,entryPoints:c}}function Di(t,e=""){if(!t)throw new Error(e)}function ip(t,e,r){switch(e.resourceType){case Ae.Immediate:case Ae.Uniform:case Ae.Storage:case Ae.StorageTexture:return uu(t,e.type,r);default:return{size:0,type:e.type.name}}}function uu(t,e,r){if(e.isArray){Di(!e.isStruct,"struct array is invalid"),Di(!e.isStruct,"template array is invalid");let n=e;return{size:n.size,elementType:uu(t,n.format,r),numElements:n.count}}else{if(e.isStruct)return Di(!e.isTemplate,"template struct is invalid"),uh(t,e,r);{let n=e,s=e.isTemplate?`${n.name}<${n.format.name}>`:e.name;return{size:e.size,type:s}}}}var up=new Map([[Int8Array,{formats:["sint8","snorm8"],defaultForType:1}],[Uint8Array,{formats:["uint8","unorm8"],defaultForType:1}],[Int16Array,{formats:["sint16","snorm16"],defaultForType:1}],[Uint16Array,{formats:["uint16","unorm16"],defaultForType:1}],[Int32Array,{formats:["sint32","snorm32"],defaultForType:0}],[Uint32Array,{formats:["uint32","unorm32"],defaultForType:0}],[Float16Array,{formats:["float16","float16"],defaultForType:0}],[Float32Array,{formats:["float32","float32"],defaultForType:0}]]),R0=new Map([...up.entries()].map(([t,{formats:[e,r]}])=>[[e,t],[r,t]]).flat());var cu=t=>t.features.has("texture-formats-tier1"),lu=t=>t.features.has("shader-f16"),ch=async t=>{let e=[];return cu(t)&&e.push("texture-formats-tier1"),lu(t)&&e.push("shader-f16"),await t?.requestDevice({requiredFeatures:e})};function lh(t,e,r=GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT){try{return t.createTexture({size:[4,4,1],format:e,usage:r}).destroy(),!0}catch{return!1}}var cp=/const WORKGROUP_SIZE_X(\s*)=(\s*)\d+u*;/,lp=/const WORKGROUP_SIZE_Y(\s*)=(\s*)\d+u*;/,Hr=(t,{workgroupSizeX:e,workgroupSizeY:r})=>t.replace(cp,`const WORKGROUP_SIZE_X$1=$2${e}u;`).replace(lp,`const WORKGROUP_SIZE_Y$1=$2${r}u;`),fp=/texture_storage_2d<\w+,(\s*)write>/,Jt=(t,e)=>t.replace(fp,`texture_storage_2d<${e},$1write>`),hp=/alias float(\s*)=(\s*)f32;/,os=t=>t.replace(hp,"enable f16;alias float$1=$2f16;");var fh="struct Params{outWidth:u32,outHeight:u32,}@group(0)@binding(0)var inSampler:sampler;@group(0)@binding(1)var inTexture:texture_2d<f32>;@group(0)@binding(2)var outTexture:texture_storage_2d<rgba8unorm,write>;@group(0)@binding(3)var<uniform> params:Params;const WORKGROUP_SIZE_X=16u;const WORKGROUP_SIZE_Y=16u;@compute @workgroup_size(WORKGROUP_SIZE_X,WORKGROUP_SIZE_Y,1)fn main(@builtin(global_invocation_id)gid:vec3u){if gid.x>=params.outWidth||gid.y>=params.outHeight{return;}let uv=(vec2f(gid.xy)+0.5)/vec2f(f32(params.outWidth),f32(params.outHeight));let color=textureSampleLevel(inTexture,inSampler,uv,0.0);textureStore(outTexture,gid.xy,color);}";var Cr=(t,e,r,n,s,o)=>{let a=Jt(fh,s),i=16,u=16,l=Math.ceil(r/i),c=Math.ceil(n/u);a=Hr(a,{workgroupSizeX:i,workgroupSizeY:u});let f=Ct(a),d=xt(f.uniforms.params),p=t.createBuffer({size:d.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});d.set({outWidth:r,outHeight:n}),t.queue.writeBuffer(p,0,d.arrayBuffer);let T=t.createShaderModule({label:`Resize shader module to ${r}x${n} with ${s} & ${o}`,code:a}),A=t.createComputePipeline({layout:"auto",label:`Resize shader pipeline to ${r}x${n} with ${s} & ${o}`,compute:{module:T}}),E=t.createTexture({label:`Resize out texture to ${r}x${n} with ${s} & ${o}`,format:s,size:[r,n],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.STORAGE_BINDING}),I=E.createView(),_=t.createSampler({magFilter:o,minFilter:o,addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}),v=null,R=null;return{render(U,C){return F(!e(),M.ContextLost),C!==R&&(v=t.createBindGroup({layout:A.getBindGroupLayout(0),entries:[{binding:0,resource:_},{binding:1,resource:C.createView()},{binding:2,resource:I},{binding:3,resource:{buffer:p}}]}),R=C),U.setPipeline(A),U.setBindGroup(0,v),U.dispatchWorkgroups(l,c),E},release(){p.destroy(),E.destroy(),v=null,R=null}}};var No=(t,e,r,n,s,o)=>{let a=new Map,i=Cr(t,e,n,s,r,o),u=(l,c)=>{let f=`${l}x${c}`,d=a.get(f);return d||(d=t.createTexture({label:"Video Frame to Texture",format:"rgba8unorm",size:[l,c],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC|GPUTextureUsage.RENDER_ATTACHMENT}),a.set(f,d)),d};return{render:(l,c)=>{F(!e(),M.ContextLost);let f=l instanceof VideoFrame?l.displayWidth:l.width,d=l instanceof VideoFrame?l.displayHeight:l.height,p=u(f,d);return t.queue.copyExternalImageToTexture({source:l,flipY:!1},{texture:p},{width:f,height:d}),i.render(c,p)},release:()=>{for(let l of a.values())l.destroy();a.clear(),i.release()}}};var fu="alias float=f32;struct Thresholds{background:float,foreground:float,}@group(0)@binding(0)var linearSampler:sampler;@group(0)@binding(1)var nearestSampler:sampler;@group(0)@binding(2)var<uniform> thresholds:Thresholds;@group(1)@binding(0)var bgTexture:texture_2d<f32>;@group(1)@binding(1)var personTexture:texture_2d<f32>;@group(1)@binding(2)var maskTexture:texture_2d<f32>;struct VertexOutput{@builtin(position)Position:vec4f,@location(0)fragUV:vec2f,}@vertex fn vert_main(@builtin(vertex_index)VertexIndex:u32)->VertexOutput{const pos=array(vec2(1.0,1.0),vec2(1.0,-1.0),vec2(-1.0,-1.0),vec2(1.0,1.0),vec2(-1.0,-1.0),vec2(-1.0,1.0),);const uv=array(vec2(1.0,0.0),vec2(1.0,1.0),vec2(0.0,1.0),vec2(1.0,0.0),vec2(0.0,1.0),vec2(0.0,0.0),);var output:VertexOutput;output.Position=vec4(pos[VertexIndex],0.0,1.0);output.fragUV=uv[VertexIndex];return output;}@fragment fn frag_main(@location(0)fragUV:vec2f)->@location(0)vec4f{let bg=textureSample(bgTexture,linearSampler,fragUV);let person=textureSample(personTexture,linearSampler,fragUV);let mask=textureSample(maskTexture,nearestSampler,fragUV);let alpha=smoothstep(thresholds.background,thresholds.foreground,mask.r);return mix(bg,person,alpha);}";var hh=(t,e,r,n)=>{let s=t.getContext("webgpu");if(!s)throw Error("WebGPU not supported on the canvas.");s.configure({device:e,format:r,alphaMode:"premultiplied"});let o=Ct(fu),a=xt(o.uniforms.thresholds),i=e.createShaderModule({label:"blender shader",code:fu}),u=e.createRenderPipeline({label:"blender pipeline",layout:"auto",vertex:{module:i},fragment:{module:i,targets:[{format:r}]}}),l=e.createSampler({addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",magFilter:"linear",minFilter:"linear"}),c=e.createSampler({addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",magFilter:"nearest",minFilter:"nearest"}),f=e.createBuffer({size:a.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),d=C=>{a.set({background:C.backgroundThreshold,foreground:C.foregroundThreshold}),e.queue.writeBuffer(f,0,a.arrayBuffer)},p={loadOp:"load",storeOp:"store"},T={label:"blender renderPass",colorAttachments:[p]},A=e.createBindGroup({layout:u.getBindGroupLayout(0),entries:[{binding:0,resource:l},{binding:1,resource:c},{binding:2,resource:{buffer:f}}]}),E=null,I=null,_=null,v=null,R=-1,U=-1;return{render:(C,{foreground:O,background:L,mask:B},N)=>{F(!n(),M.ContextLost),p.view=s.getCurrentTexture().createView(),_===L&&v===O&&I===B||(E=e.createBindGroup({layout:u.getBindGroupLayout(1),entries:[{binding:0,resource:L.createView()},{binding:1,resource:O.createView()},{binding:2,resource:B.createView()}]}),_=L,v=O,I=B),R===N.backgroundThreshold&&U===N.foregroundThreshold||(d(N),R=N.backgroundThreshold,U=N.foregroundThreshold);let D=C.beginRenderPass(T);D.setPipeline(u),D.setBindGroup(0,A),D.setBindGroup(1,E),D.draw(6),D.end()},release:()=>{f.destroy(),R=-1,U=-1}}};var dh="struct VertexOutput{@builtin(position)position:vec4f,@location(0)uv:vec2f,};@vertex fn vs_main(@builtin(vertex_index)vertex_index:u32)->VertexOutput{var out:VertexOutput;let x=f32((vertex_index<<1u)&2u);let y=f32(vertex_index&2u);out.position=vec4f(x*2.0-1.0,1.0-y*2.0,0.0,1.0);out.uv=vec2f(x,y);return out;}@group(0)@binding(0)var u_sampler:sampler;@group(0)@binding(1)var u_frame:texture_2d<f32>;@fragment fn downsample_fs(in:VertexOutput)->@location(0)vec4f{let src_size=vec2f(textureDimensions(u_frame));let halfpixel=0.5/src_size;let uv=in.uv;var sum=textureSample(u_frame,u_sampler,uv)*4.0;sum+=textureSample(u_frame,u_sampler,uv+halfpixel);sum+=textureSample(u_frame,u_sampler,uv-halfpixel);sum+=textureSample(u_frame,u_sampler,uv+vec2f(halfpixel.x,-halfpixel.y));sum+=textureSample(u_frame,u_sampler,uv+vec2f(-halfpixel.x,halfpixel.y));return sum*0.125;}@fragment fn upsample_fs(in:VertexOutput)->@location(0)vec4f{let src_size=vec2f(textureDimensions(u_frame));let halfpixel=0.5/src_size;let uv=in.uv;let double_half=halfpixel*2.0;var sum=textureSample(u_frame,u_sampler,uv+vec2f(-double_half.x,0.0));sum+=textureSample(u_frame,u_sampler,uv+vec2f(double_half.x,0.0));sum+=textureSample(u_frame,u_sampler,uv+vec2f(0.0,double_half.y));sum+=textureSample(u_frame,u_sampler,uv+vec2f(0.0,-double_half.y));sum+=textureSample(u_frame,u_sampler,uv+vec2f(-halfpixel.x,halfpixel.y))*2.0;sum+=textureSample(u_frame,u_sampler,uv+vec2f(halfpixel.x,halfpixel.y))*2.0;sum+=textureSample(u_frame,u_sampler,uv+vec2f(halfpixel.x,-halfpixel.y))*2.0;sum+=textureSample(u_frame,u_sampler,uv+vec2f(-halfpixel.x,-halfpixel.y))*2.0;return sum*0.08333333333;}";var as=9,dp=At(1,as),hu=(t,e,r,n,s)=>{let o=t.createShaderModule({label:"dual blur compute shader",code:dh}),a=t.createRenderPipeline({label:"dual blur downsample compute pipeline",layout:"auto",vertex:{module:o,entryPoint:"vs_main"},fragment:{module:o,targets:[{format:n}],entryPoint:"downsample_fs"}}),i=t.createRenderPipeline({label:"dual blur upsample compute pipeline",layout:"auto",vertex:{module:o,entryPoint:"vs_main"},fragment:{module:o,targets:[{format:n}],entryPoint:"upsample_fs"}}),u=t.createSampler({magFilter:"linear",minFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}),l=[];for(let I=0;I<as;I++){let _=Math.max(Math.trunc(e/2**I),1),v=Math.max(Math.trunc(r/2**I),1),R=t.createTexture({label:`dual filter blur texture level ${I}`,format:n,size:[_,v],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.RENDER_ATTACHMENT});l.push({texture:R,view:R.createView(),width:_,height:v})}let c=[],f=[];for(let I=2;I<as;I++){let _=l[I-1],v=l[I];F(_),F(v),c.push(t.createBindGroup({layout:a.getBindGroupLayout(0),entries:[{binding:0,resource:u},{binding:1,resource:_.view}]})),f.push({label:`downsample render pass ${I}`,colorAttachments:[{loadOp:"load",storeOp:"store",view:v.view}]})}let d=[],p=[];for(let I=as-2;I>=0;I--){let _=l[I+1],v=l[I];F(_),F(v),d.push(t.createBindGroup({layout:i.getBindGroupLayout(0),entries:[{binding:0,resource:u},{binding:1,resource:_.view}]})),p.push({label:`upsample render pass ${I}`,colorAttachments:[{loadOp:"load",storeOp:"store",view:v.view}]})}let T=null,A=null,E=null;return{render:(I,_,v)=>{if(F(!s(),M.ContextLost),!v)return _;let R=dp(v+1),U=l[1];F(U),_!==T&&(A=t.createBindGroup({layout:a.getBindGroupLayout(0),entries:[{binding:0,resource:u},{binding:1,resource:_.createView()}]}),E={label:"downsample render pass 0",colorAttachments:[{loadOp:"load",storeOp:"store",view:U.view}]},T=_),F(E);let C=I.beginRenderPass(E);C.setPipeline(a),C.setBindGroup(0,A),C.draw(3),C.end();for(let B=2;B<R;B++){let N=l[B];F(N);let D=c[B-2],X=f[B-2];F(D),F(X);let ne=I.beginRenderPass(X);ne.setPipeline(a),ne.setBindGroup(0,D),ne.draw(3),ne.end()}let O=as-1-(R-1);for(let B=O;B<d.length;B++){let N=d[B],D=p[B];F(N),F(D);let X=I.beginRenderPass(D);X.setPipeline(i),X.setBindGroup(0,N),X.draw(3),X.end()}let L=l[0];return F(L),L.texture},release:()=>{for(let I of l)I.texture.destroy();l.length=0,c.length=0,f.length=0,d.length=0,p.length=0,T=null,A=null,E=null}}};var mh="alias float=f32;alias texture_storage=texture_storage_2d<rgba16float,write>;struct Params{maskCombineRatio:f32,}@group(0)@binding(0)var outputTex:texture_storage;@group(0)@binding(1)var<uniform> params:Params;@group(1)@binding(0)var mask:texture_2d<f32>;@group(1)@binding(1)var prevMask:texture_2d<f32>;const WORKGROUP_SIZE_X=16u;const WORKGROUP_SIZE_Y=16u;fn smoothingMask(prevMask:texture_2d<f32>,mask:texture_2d<f32>,uv:vec2<u32>,ratio:f32)->float{let prevMaskValue=float(textureLoad(prevMask,uv,0u).r);let currMaskValue=float(textureLoad(mask,uv,0u).r);let c1=float(5.68842);let c2=float(-0.748699);let c3=float(-57.8051);let c4=float(291.309);let c5=float(-624.717);let t=currMaskValue-0.5;let x=t*t;let uncertainty=1.0-min(1.0,x*(c1+x*(c2+x*(c3+x*(c4+x*c5)))));return currMaskValue+(prevMaskValue-currMaskValue)*(uncertainty*float(ratio));}@compute @workgroup_size(WORKGROUP_SIZE_X,WORKGROUP_SIZE_Y,1)fn main(@builtin(global_invocation_id)gid:vec3u){let dims=textureDimensions(mask,0);if gid.x>=dims.x||gid.y>=dims.y{return;}let uv=vec2u(gid.xy);let alpha=smoothingMask(prevMask,mask,uv,params.maskCombineRatio);textureStore(outputTex,uv,vec4f(f32(alpha),0.0,0.0,1.0));}";var du=(t,e,r,n,s,o)=>{let u=Math.ceil(n/16),l=Math.ceil(s/16),c=Hr(mh,{workgroupSizeX:16,workgroupSizeY:16});c=Jt(c,r),o&&(c=os(c));let f=t.createTexture({label:"Smoothed Mask Texture",format:r,size:[n,s],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.COPY_SRC}),d=Ct(c),p=xt(d.uniforms.params),T=t.createBuffer({size:p.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),A=O=>{p.set({maskCombineRatio:O.maskCombineRatio}),t.queue.writeBuffer(T,0,p.arrayBuffer)},E=t.createShaderModule({label:"smoothing mask compute",code:c}),I=t.createComputePipeline({label:"smoothing mask pipeline",layout:"auto",compute:{module:E}}),_=t.createBindGroup({layout:I.getBindGroupLayout(0),entries:[{binding:0,resource:f.createView()},{binding:1,resource:{buffer:T}}]}),v=null,R=null,U=null,C=-1;return{render:(O,L,B,N)=>{F(!e(),M.ContextLost),L===v&&B===R||(U=t.createBindGroup({layout:I.getBindGroupLayout(1),entries:[{binding:0,resource:L.createView()},{binding:1,resource:B.createView()}]}),v=L,R=B),C!==N.maskCombineRatio&&(A(N),C=N.maskCombineRatio);let D=O.beginComputePass({label:"smoothing mask compute pass"});return D.setPipeline(I),D.setBindGroup(0,_),D.setBindGroup(1,U),D.dispatchWorkgroups(u,l),D.end(),f},release:()=>{f.destroy(),T.destroy(),v=null,R=null,U=null,C=-1}}};var ph=(t,e)=>{let r=new Map,n=(s,o,a,i)=>{let u=`${s}x${o}x${a}-${i}`,l=r.get(u);return l||(l=t.createTexture({size:{width:s,height:o,depthOrArrayLayers:a},format:i,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST}),r.set(u,l)),l};return{render:(s,o)=>{F(!e(),M.ContextLost);let a=n(o.width,o.height,o.depthOrArrayLayers,o.format);return s.copyTextureToTexture({texture:o},{texture:a},{width:a.width,height:a.height,depthOrArrayLayers:a.depthOrArrayLayers}),a},release:()=>{for(let s of r.values())s.destroy();r.clear()}}};var mu="struct Params{sigmaSpace:f32,sigmaRangeLo:f32,sigmaRangeHi:f32,backgroundThreshold:f32,foregroundThreshold:f32,texelWidth:f32,texelHeight:f32,width:u32,height:u32,}@group(0)@binding(0)var inputTex:texture_2d<f32>;@group(0)@binding(1)var guideTex:texture_2d<f32>;@group(1)@binding(0)var<uniform> params:Params;@group(1)@binding(1)var outputTex:texture_storage_2d<rgba16float,write>;const MAX_RADIUS:u32=24u;const FOREGROUND_BIAS:f32=1.3;const EDGE_THRESHOLD:f32=0.08;const SPARSITY_FACTOR:f32=0.66;const TILE_W:u32=32u;const TILE_ROWS:u32=4u;var<workgroup> tile_mask:array<array<f32,80>,4>;var<workgroup> tile_guide_lum:array<array<f32,80>,4>;fn gaussian_sqr(dist2:f32,sigma2:f32)->f32{return exp(-0.5*dist2/max(sigma2,1e-6));}fn luminance(c:vec3f)->f32{return dot(c,vec3f(0.299,0.587,0.114));}@compute @workgroup_size(TILE_W,TILE_ROWS,1)fn main(@builtin(global_invocation_id)gid:vec3u,@builtin(local_invocation_id)lid:vec3u,@builtin(workgroup_id)wg_id:vec3u,){let x=i32(gid.x);let y=i32(gid.y);let lx=i32(lid.x);let ly=i32(lid.y);let radius=min(i32(floor(params.sigmaSpace+0.5)),i32(MAX_RADIUS));let w=i32(params.width);let h=i32(params.height);let tile_base_x=i32(wg_id.x)*i32(TILE_W);let shared_center=lx+radius;let gx_center=clamp(tile_base_x+lx,0,w-1);let gy=clamp(y,0,h-1);tile_mask[ly][shared_center]=textureLoad(inputTex,vec2i(gx_center,gy),0).r;tile_guide_lum[ly][shared_center]=luminance(textureLoad(guideTex,vec2i(gx_center,gy),0).rgb);if lx<radius{let halo_x=clamp(tile_base_x+lx-radius,0,w-1);tile_mask[ly][lx]=textureLoad(inputTex,vec2i(halo_x,gy),0).r;tile_guide_lum[ly][lx]=luminance(textureLoad(guideTex,vec2i(halo_x,gy),0).rgb);}if lx>=i32(TILE_W)-radius{let shared_right=shared_center+radius;let halo_x=clamp(tile_base_x+lx+radius,0,w-1);tile_mask[ly][shared_right]=textureLoad(inputTex,vec2i(halo_x,gy),0).r;tile_guide_lum[ly][shared_right]=luminance(textureLoad(guideTex,vec2i(halo_x,gy),0).rgb);}workgroupBarrier();if x>=w||y>=h{return;}let center_mask=tile_mask[ly][shared_center];let center_lum=tile_guide_lum[ly][shared_center];let t=smoothstep(params.backgroundThreshold,params.foregroundThreshold,center_mask);let sigma_color=mix(params.sigmaRangeLo,params.sigmaRangeHi,t);let sigma_texel=params.texelWidth*params.sigmaSpace;let sigma_texel2=sigma_texel*sigma_texel;let sigma_color2=sigma_color*sigma_color;let sparsity=max(1.0,sqrt(params.sigmaSpace)*SPARSITY_FACTOR);let step_i=max(1,i32(floor(sparsity+0.5)));let offset_i=select(0,step_i/2,step_i>1);let fg_w=mix(1.0,FOREGROUND_BIAS,center_mask);var acc:f32=0.0;var total_weight:f32=0.0;for(var offset=-radius;offset<=radius;offset=offset+1){let sparsitySkip=((offset+offset_i)% step_i)!=0;if sparsitySkip{continue;}let idx=shared_center+offset;let neighbor_mask=tile_mask[ly][idx];let neighbor_lum=tile_guide_lum[ly][idx];let dx=f32(offset)*params.texelWidth;let space_weight=gaussian_sqr(dx*dx,sigma_texel2);let dL=abs(neighbor_lum-center_lum);if dL>EDGE_THRESHOLD{continue;}let color_weight=gaussian_sqr(dL*dL,sigma_color2);let w_sample=space_weight*color_weight*fg_w;total_weight=total_weight+w_sample;acc=acc+w_sample*neighbor_mask;}let result=acc/max(total_weight,1e-6);textureStore(outputTex,gid.xy,vec4f(result,0.0,0.0,1.0));}";var gh="struct Params{sigmaSpace:f32,sigmaRangeLo:f32,sigmaRangeHi:f32,backgroundThreshold:f32,foregroundThreshold:f32,texelWidth:f32,texelHeight:f32,width:u32,height:u32,}@group(0)@binding(0)var inputTex:texture_2d<f32>;@group(0)@binding(1)var guideTex:texture_2d<f32>;@group(1)@binding(0)var<uniform> params:Params;@group(1)@binding(1)var outputTex:texture_storage_2d<rgba16float,write>;const MAX_RADIUS:u32=24u;const FOREGROUND_BIAS:f32=1.3;const EDGE_THRESHOLD:f32=0.08;const SPARSITY_FACTOR:f32=0.66;const TILE_COLS:u32=4u;const TILE_H:u32=32u;var<workgroup> tile_mask:array<array<f32,80>,4>;var<workgroup> tile_guide_lum:array<array<f32,80>,4>;fn gaussian_sqr(dist2:f32,sigma2:f32)->f32{return exp(-0.5*dist2/max(sigma2,1e-6));}fn luminance(c:vec3f)->f32{return dot(c,vec3f(0.299,0.587,0.114));}@compute @workgroup_size(TILE_COLS,TILE_H,1)fn main(@builtin(global_invocation_id)gid:vec3u,@builtin(local_invocation_id)lid:vec3u,@builtin(workgroup_id)wg_id:vec3u,){let x=i32(gid.x);let y=i32(gid.y);let lx=i32(lid.x);let ly=i32(lid.y);let radius=min(i32(floor(params.sigmaSpace+0.5)),i32(MAX_RADIUS));let w=i32(params.width);let h=i32(params.height);let tile_base_y=i32(wg_id.y)*i32(TILE_H);let shared_center=ly+radius;let gx=clamp(x,0,w-1);let gy_center=clamp(tile_base_y+ly,0,h-1);tile_mask[lx][shared_center]=textureLoad(inputTex,vec2i(gx,gy_center),0).r;tile_guide_lum[lx][shared_center]=luminance(textureLoad(guideTex,vec2i(gx,gy_center),0).rgb);if ly<radius{let halo_y=clamp(tile_base_y+ly-radius,0,h-1);tile_mask[lx][ly]=textureLoad(inputTex,vec2i(gx,halo_y),0).r;tile_guide_lum[lx][ly]=luminance(textureLoad(guideTex,vec2i(gx,halo_y),0).rgb);}if ly>=i32(TILE_H)-radius{let shared_bottom=shared_center+radius;let halo_y=clamp(tile_base_y+ly+radius,0,h-1);tile_mask[lx][shared_bottom]=textureLoad(inputTex,vec2i(gx,halo_y),0).r;tile_guide_lum[lx][shared_bottom]=luminance(textureLoad(guideTex,vec2i(gx,halo_y),0).rgb);}workgroupBarrier();if x>=w||y>=h{return;}let center_mask=tile_mask[lx][shared_center];let center_lum=tile_guide_lum[lx][shared_center];let t=smoothstep(params.backgroundThreshold,params.foregroundThreshold,center_mask);let sigma_color=mix(params.sigmaRangeLo,params.sigmaRangeHi,t);let sigma_texel=params.texelHeight*params.sigmaSpace;let sigma_texel2=sigma_texel*sigma_texel;let sigma_color2=sigma_color*sigma_color;let sparsity=max(1.0,sqrt(params.sigmaSpace)*SPARSITY_FACTOR);let step_i=max(1,i32(floor(sparsity+0.5)));let offset_i=select(0,step_i/2,step_i>1);let fg_w=mix(1.0,FOREGROUND_BIAS,center_mask);var acc:f32=0.0;var total_weight:f32=0.0;for(var offset=-radius;offset<=radius;offset=offset+1){let sparsitySkip=((offset+offset_i)% step_i)!=0;if sparsitySkip{continue;}let idx=shared_center+offset;let neighbor_mask=tile_mask[lx][idx];let neighbor_lum=tile_guide_lum[lx][idx];let dy=f32(offset)*params.texelHeight;let space_weight=gaussian_sqr(dy*dy,sigma_texel2);let dL=abs(neighbor_lum-center_lum);if dL>EDGE_THRESHOLD{continue;}let color_weight=gaussian_sqr(dL*dL,sigma_color2);let w_sample=space_weight*color_weight*fg_w;total_weight=total_weight+w_sample;acc=acc+w_sample*neighbor_mask;}let result=acc/max(total_weight,1e-6);textureStore(outputTex,gid.xy,vec4f(result,0.0,0.0,1.0));}";var pu=(t,e,r,n,s,o)=>{let c=e.createTexture({label:"Joint Bilateral Filtered temporary mask texture",format:o,size:[n,s],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.STORAGE_BINDING}),f=e.createTexture({label:"Joint Bilateral Filtered Mask Texture",format:o,size:[n,s],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.STORAGE_BINDING}),d=Ct(mu),p=xt(d.uniforms.params),T=e.createBuffer({size:p.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),A=n/t.width,E=1/n,I=1/s;p.set({width:n,height:s,texelWidth:E,texelHeight:I});let _=He=>{p.set({...He,sigmaSpace:He.sigmaSpace*A}),e.queue.writeBuffer(T,0,p.arrayBuffer)},v=Jt(mu,o),R=Jt(gh,o),U=e.createShaderModule({label:"joint bilateral filter horizontal compute",code:v}),C=e.createShaderModule({label:"joint bilateral filter vertical compute",code:R}),O=e.createComputePipeline({label:"joint bilateral filter horizontal pipeline",layout:"auto",compute:{module:U}}),L=e.createComputePipeline({label:"joint bilateral filter vertical pipeline",layout:"auto",compute:{module:C}}),B=e.createBindGroup({layout:O.getBindGroupLayout(1),entries:[{binding:0,resource:{buffer:T}},{binding:1,resource:c.createView()}]}),N=e.createBindGroup({layout:L.getBindGroupLayout(1),entries:[{binding:0,resource:{buffer:T}},{binding:1,resource:f.createView()}]}),D=(He,Q,We,Ue,is,nd,sd)=>{let In=Q.beginComputePass({label:He});In.setPipeline(We),In.setBindGroup(0,Ue),In.setBindGroup(1,is),In.dispatchWorkgroups(nd,sd),In.end()},X=Math.ceil(n/32),ne=Math.ceil(s/4),Re=Math.ceil(n/4),Ge=Math.ceil(s/32),me=null,tt=null,ze=null,Wt=null,Ve={sigmaSpace:-1,sigmaRangeLo:-1,sigmaRangeHi:-1,backgroundThreshold:-1,foregroundThreshold:-1};return{render:(He,Q,We,Ue)=>(F(!r(),M.ContextLost),Ve.sigmaSpace===Ue.sigmaSpace&&Ve.sigmaRangeLo===Ue.sigmaRangeLo&&Ve.sigmaRangeHi===Ue.sigmaRangeHi&&Ve.backgroundThreshold===Ue.backgroundThreshold&&Ve.foregroundThreshold===Ue.foregroundThreshold||(_(Ue),Ve.sigmaSpace=Ue.sigmaSpace,Ve.sigmaRangeLo=Ue.sigmaRangeLo,Ve.sigmaRangeHi=Ue.sigmaRangeHi,Ve.backgroundThreshold=Ue.backgroundThreshold,Ve.foregroundThreshold=Ue.foregroundThreshold),(me!==Q||tt!==We)&&(ze=e.createBindGroup({layout:O.getBindGroupLayout(0),entries:[{binding:0,resource:Q.createView()},{binding:1,resource:We.createView()}]}),me=Q),D("Joint Bilateral Filter Horizontal pass",He,O,ze,B,X,ne),tt!==We&&(Wt=e.createBindGroup({layout:L.getBindGroupLayout(0),entries:[{binding:0,resource:c.createView()},{binding:1,resource:We.createView()}]}),tt=We),D("Joint Bilateral Filter Vertical pass",He,L,Wt,N,Re,Ge),f),release:()=>{c.destroy(),f.destroy(),T.destroy(),me=null,tt=null,ze=null,Wt=null}}};var xh="alias float=f32;struct TentParams{radius:u32,width:u32,height:u32,}@group(0)@binding(0)var inputTex:texture_2d<f32>;@group(0)@binding(1)var outputTex:texture_storage_2d<rgba16float,write>;@group(0)@binding(2)var<uniform> params:TentParams;const WORKGROUP_SIZE_X=16u;const WORKGROUP_SIZE_Y=16u;@compute @workgroup_size(WORKGROUP_SIZE_X,WORKGROUP_SIZE_Y,1)fn main(@builtin(global_invocation_id)gid:vec3u){if gid.x>=params.width||gid.y>=params.height{return;}let r=i32(params.radius);if r==0{let m=textureLoad(inputTex,gid.xy,0).r;textureStore(outputTex,gid.xy,vec4f(m,0.0,0.0,1.0));return;}var sumW:float=0.0;var acc:float=0.0;for(var i=-r;i<=r;i=i+1){let w=float(r+1-abs(i));let sx=clamp(i32(gid.x)+i,0,i32(params.width)-1);let m=textureLoad(inputTex,vec2u(u32(sx),gid.y),0).r;acc+=w*float(m);sumW+=w;}let result=acc/max(sumW,1e-6);textureStore(outputTex,gid.xy,vec4f(f32(result),0.0,0.0,1.0));}";var yh="alias float=f32;struct TentParams{radius:u32,width:u32,height:u32,}@group(0)@binding(0)var inputTex:texture_2d<f32>;@group(0)@binding(1)var outputTex:texture_storage_2d<rgba16float,write>;@group(0)@binding(2)var<uniform> params:TentParams;const WORKGROUP_SIZE_X=16u;const WORKGROUP_SIZE_Y=16u;@compute @workgroup_size(WORKGROUP_SIZE_X,WORKGROUP_SIZE_Y,1)fn main(@builtin(global_invocation_id)gid:vec3u){if gid.x>=params.width||gid.y>=params.height{return;}let r=i32(params.radius);if r==0{let m=textureLoad(inputTex,gid.xy,0).r;textureStore(outputTex,gid.xy,vec4f(m,0.0,0.0,1.0));return;}var sumW:float=0.0;var acc:float=0.0;for(var i=-r;i<=r;i=i+1){let w=float(r+1-abs(i));let sy=clamp(i32(gid.y)+i,0,i32(params.height)-1);let m=textureLoad(inputTex,vec2u(gid.x,u32(sy)),0).r;acc+=w*float(m);sumW+=w;}let result=acc/max(sumW,1e-6);textureStore(outputTex,gid.xy,vec4f(f32(result),0.0,0.0,1.0));}";var mp=At(0,9),_h=(t,e,r,n,s,o)=>{let u=Math.ceil(r/16),l=Math.ceil(n/16),c=Jt(xh,s);c=Hr(c,{workgroupSizeX:16,workgroupSizeY:16});let f=Jt(yh,s);f=Hr(f,{workgroupSizeX:16,workgroupSizeY:16}),o&&(c=os(c),f=os(f));let d=Ct(c),p=xt(d.uniforms.params),T=t.createBuffer({size:p.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});p.set({width:r,height:n});let A=D=>{p.set({radius:D}),t.queue.writeBuffer(T,0,p.arrayBuffer)},E=t.createTexture({label:`Tent Blur intermediate texture ${r}x${n} ${s}`,format:s,size:[r,n],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.STORAGE_BINDING}),I=E.createView(),_=t.createTexture({label:`Tent Blur output texture ${r}x${n} ${s}`,format:s,size:[r,n],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.STORAGE_BINDING}),v=t.createShaderModule({label:`Tent Blur horizontal compute ${r}x${n} ${s}`,code:c}),R=t.createShaderModule({label:`Tent Blur vertical compute ${r}x${n} ${s}`,code:f}),U=t.createComputePipeline({label:`Tent Blur horizontal pipeline ${r}x${n} ${s}`,layout:"auto",compute:{module:v}}),C=t.createComputePipeline({label:`Tent Blur vertical pipeline ${r}x${n} ${s}`,layout:"auto",compute:{module:R}}),O=t.createBindGroup({layout:C.getBindGroupLayout(0),entries:[{binding:0,resource:I},{binding:1,resource:_.createView()},{binding:2,resource:{buffer:T}}]}),L=null,B=null,N=-1;return{render(D,X,ne){F(!e(),M.ContextLost);let Re=mp(ne.edgeBlurAmount);N!==Re&&(A(Re),N=Re),L!==X&&(B=t.createBindGroup({layout:U.getBindGroupLayout(0),entries:[{binding:0,resource:X.createView()},{binding:1,resource:I},{binding:2,resource:{buffer:T}}]}),L=X);let Ge=D.beginComputePass({label:"Tent Blur H pass"});Ge.setPipeline(U),Ge.setBindGroup(0,B),Ge.dispatchWorkgroups(u,l),Ge.end();let me=D.beginComputePass({label:"Tent Blur V pass"});return me.setPipeline(C),me.setBindGroup(0,O),me.dispatchWorkgroups(u,l),me.end(),_},release(){E.destroy(),_.destroy(),T.destroy(),L=null,B=null,N=-1}}};var gu="alias float=f32;struct StaticParams{background:float,foreground:float,lightWrap:float,lightWrapTightness:float,lightWrapEdgeBand:float,width:u32,height:u32,}struct DynamicParams{time:float,parity:float,}@group(0)@binding(0)var linearSampler:sampler;@group(0)@binding(1)var nearestSampler:sampler;@group(0)@binding(2)var<uniform> sparams:StaticParams;@group(0)@binding(3)var<uniform> dparams:DynamicParams;@group(1)@binding(0)var foregroundTexture:texture_2d<f32>;@group(1)@binding(1)var backgroundTexture:texture_2d<f32>;@group(1)@binding(2)var maskTexture:texture_2d<f32>;@group(1)@binding(3)var blurredBackgroundTexture:texture_2d<f32>;struct VertexOutput{@builtin(position)Position:vec4f,@location(0)fragUV:vec2f,}fn rgb2yuv(rgb:vec3f)->vec3f{let Y=dot(rgb,vec3f(0.299,0.587,0.114));let U=dot(rgb,vec3f(-0.168736,-0.331264,0.5));let V=dot(rgb,vec3f(0.5,-0.418688,-0.081312));return vec3f(Y,U,V);}fn yuv2rgb(yuv:vec3f)->vec3f{let Y=yuv.x;let U=yuv.y;let V=yuv.z;return vec3f(Y+1.402*V,Y-0.344136*U-0.714136*V,Y+1.772*U);}fn hash12(p:vec2f)->f32{let p3=fract(vec3f(p.xyx)*0.1031);let p4=p3+dot(p3,p3.yzx+33.33);return fract((p4.x+p4.y)*p4.z);}const NOISE_LUMA=2.0f/255.0f;@vertex fn vert_main(@builtin(vertex_index)VertexIndex:u32)->VertexOutput{const pos=array(vec2(1.0,1.0),vec2(1.0,-1.0),vec2(-1.0,-1.0),vec2(1.0,1.0),vec2(-1.0,-1.0),vec2(-1.0,1.0),);const uv=array(vec2(1.0,0.0),vec2(1.0,1.0),vec2(0.0,1.0),vec2(1.0,0.0),vec2(0.0,1.0),vec2(0.0,0.0),);var output:VertexOutput;output.Position=vec4(pos[VertexIndex],0.0,1.0);output.fragUV=uv[VertexIndex];return output;}@fragment fn frag_main(@location(0)fragUV:vec2f)->@location(0)vec4f{let bg=textureSample(backgroundTexture,linearSampler,fragUV).rgb;let fg=textureSample(foregroundTexture,linearSampler,fragUV).rgb;let mask=textureSample(maskTexture,nearestSampler,fragUV).r;let blurBg=textureSample(blurredBackgroundTexture,linearSampler,fragUV).rgb;let bgT=f32(sparams.background);let fgT=f32(sparams.foreground);let lightWrap=f32(sparams.lightWrap);let edgeBand=f32(sparams.lightWrapEdgeBand);let tightness=f32(sparams.lightWrapTightness);let maskFg=smoothstep(bgT,fgT,mask);let edgeBg=smoothstep(bgT,bgT+edgeBand,mask);let edgeFg=1.0-smoothstep(fgT-edgeBand,fgT,mask);let edgeBgTight=pow(edgeBg,tightness);let edgeFgTight=pow(edgeFg,tightness);let maskBg=1.0-maskFg;let pixelCoord=floor(fragUV*vec2f(f32(sparams.width),f32(sparams.height)));let noiseY=(hash12(pixelCoord+vec2f(f32(dparams.time),0.0))-0.5)*NOISE_LUMA*f32(dparams.parity);let noiseWeight=clamp(maskBg+edgeBgTight*maskFg,0.0,1.0);var bgYUV=rgb2yuv(bg);bgYUV.x=clamp(bgYUV.x+noiseY*f32(noiseWeight),0.0,1.0);let bgNoisy=yuv2rgb(bgYUV);let bgSmooth=mix(bgNoisy,blurBg,lightWrap*edgeBgTight);let wrapColor=mix(fg,blurBg,lightWrap);let fgSmooth=mix(fg,wrapColor,edgeFgTight);let composite=mix(bgSmooth,fgSmooth,maskFg);return vec4f(composite,1.0);}";var bh=(t,e,r,n)=>{let s=t.getContext("webgpu");if(!s)throw Error("WebGPU not supported on the canvas.");s.configure({device:e,format:r,alphaMode:"premultiplied"});let o=Ct(gu),a=xt(o.uniforms.sparams),i=xt(o.uniforms.dparams),u=e.createShaderModule({label:"replace shader",code:gu}),l=e.createRenderPipeline({label:"replace pipeline",layout:"auto",vertex:{module:u},fragment:{module:u,targets:[{format:r}]}}),c=e.createSampler({addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",magFilter:"linear",minFilter:"linear"}),f=e.createSampler({addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",magFilter:"nearest",minFilter:"nearest"}),d=e.createBuffer({size:a.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),p=e.createBuffer({size:i.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),T=me=>{a.set({background:me.backgroundThreshold,foreground:me.foregroundThreshold,lightWrap:me.lightWrapIntensity,lightWrapTightness:me.lightWrapTightness,lightWrapEdgeBand:me.lightWrapEdgeBand,width:me.width,height:me.height}),e.queue.writeBuffer(d,0,a.arrayBuffer)},A=({time:me,parity:tt})=>{i.set({time:me,parity:tt}),e.queue.writeBuffer(p,0,i.arrayBuffer)},E={loadOp:"load",storeOp:"store"},I={label:"replace renderPass",colorAttachments:[E]},_=e.createBindGroup({layout:l.getBindGroupLayout(0),entries:[{binding:0,resource:c},{binding:1,resource:f},{binding:2,resource:{buffer:d}},{binding:3,resource:{buffer:p}}]}),v=null,R=null,U=null,C=null,O=null,L=-1,B=-1,N=-1,D=-1,X=-1,ne=-1,Re=-1,Ge=-1;return{render:(me,{foreground:tt,background:ze,blurBackground:Wt,mask:Ve,timestamp:He},Q)=>{F(!n(),M.ContextLost),E.view=s.getCurrentTexture().createView(),U===ze&&C===tt&&R===Ve&&O===Wt||(v=e.createBindGroup({layout:l.getBindGroupLayout(1),entries:[{binding:0,resource:tt.createView()},{binding:1,resource:ze.createView()},{binding:2,resource:Ve.createView()},{binding:3,resource:Wt.createView()}]}),C=tt,U=ze,R=Ve,O=Wt),L===Q.backgroundThreshold&&B===Q.foregroundThreshold&&N===Q.lightWrapIntensity&&D===Q.lightWrapTightness&&X===Q.lightWrapEdgeBand&&ne===ze.width&&Re===ze.height||(T({backgroundThreshold:Q.backgroundThreshold,foregroundThreshold:Q.foregroundThreshold,lightWrapIntensity:Q.lightWrapIntensity,lightWrapTightness:Q.lightWrapTightness,lightWrapEdgeBand:Q.lightWrapEdgeBand,width:ze.width,height:ze.height}),L=Q.backgroundThreshold,B=Q.foregroundThreshold,N=Q.lightWrapIntensity,D=Q.lightWrapTightness,X=Q.lightWrapEdgeBand,ne=ze.width,Re=ze.height),Ge=-Ge,A({time:He*1e-6%1024,parity:Ge});let We=me.beginRenderPass(I);We.setPipeline(l),We.setBindGroup(0,_),We.setBindGroup(1,v),We.draw(6),We.end()},release:()=>{d.destroy(),p.destroy(),L=-1,B=-1,N=-1,D=-1,X=-1,ne=-1,Re=-1,O=null,U=null,C=null,R=null,v=null}}};var vh=(t,e,r=new OffscreenCanvas(Rr,Ar))=>{let n=Math.trunc(r.width/2),s=Math.trunc(r.height/2),o=Math.trunc(r.width/4),a=Math.trunc(r.height/4),i="rgba8unorm",u={edgeBlurRenderer:()=>(F(c.device),_h(c.device,A,r.width,r.height,c.maskFormat,c.supportF16)),videoFrameRenderer:()=>(F(c.device),No(c.device,A,i,r.width,r.height,"linear")),maskRenderer:()=>(F(c.device),No(c.device,A,c.maskFormat,r.width,r.height,"nearest")),maskDownsampler2:()=>(F(c.device),Cr(c.device,A,n,s,c.maskFormat,"nearest")),maskDownsampler4:()=>(F(c.device),Cr(c.device,A,o,a,c.maskFormat,"nearest")),maskUpsampler:()=>(F(c.device),Cr(c.device,A,r.width,r.height,c.maskFormat,"nearest")),frameDownsampler2:()=>(F(c.device),Cr(c.device,A,n,s,i,"linear")),frameDownsampler4:()=>(F(c.device),Cr(c.device,A,o,a,i,"linear")),backgroundImageRenderer:()=>(F(c.device),No(c.device,A,i,r.width,r.height,"linear")),blendRenderer:()=>(F(c.device),hh(r,c.device,c.presentationFormat,A)),blurRenderer:()=>(F(c.device),hu(c.device,r.width,r.height,i,A)),jointBilateralFilterRenderer2:()=>(F(c.device),pu(r,c.device,A,n,s,c.maskFormat)),jointBilateralFilterRenderer4:()=>(F(c.device),pu(r,c.device,A,o,a,c.maskFormat)),maskSmoothingRenderer2:()=>(F(c.device),du(c.device,A,c.maskFormat,n,s,c.supportF16)),maskSmoothingRenderer4:()=>(F(c.device),du(c.device,A,c.maskFormat,o,a,c.supportF16)),prevMaskRenderer:()=>(F(c.device),ph(c.device,A)),strongMaskBlurRenderer:()=>(F(c.device),hu(c.device,r.width,r.height,c.maskFormat,A)),replaceRenderer:()=>(F(c.device),bh(r,c.device,c.presentationFormat,A)),release:E=>()=>{for(let I of Object.keys(E))I!=="release"&&E[I]?.release()}},l=xn(u),c={canvas:r,presentationFormat:"rgba8unorm",supportR16FloatTextureStorage:!1,maskFormat:"rgba16float",supportF16:!1,backend:"webgpu",deviceLost:!1,get videoFrameRenderer(){return l.videoFrameRenderer},get edgeBlurRenderer(){return l.edgeBlurRenderer},get maskRenderer(){return l.maskRenderer},get maskDownsampler2(){return l.maskDownsampler2},get maskDownsampler4(){return l.maskDownsampler4},get maskUpsampler(){return l.maskUpsampler},get frameDownsampler2(){return l.frameDownsampler2},get frameDownsampler4(){return l.frameDownsampler4},get blendRenderer(){return l.blendRenderer},get blurRenderer(){return l.blurRenderer},get backgroundImageRenderer(){return l.backgroundImageRenderer},get maskSmoothingRenderer2(){return l.maskSmoothingRenderer2},get maskSmoothingRenderer4(){return l.maskSmoothingRenderer4},get prevMaskRenderer(){return l.prevMaskRenderer},get jointBilateralFilterRenderer2(){return l.jointBilateralFilterRenderer2},get jointBilateralFilterRenderer4(){return l.jointBilateralFilterRenderer4},get strongMaskBlurRenderer(){return l.strongMaskBlurRenderer},get replaceRenderer(){return l.replaceRenderer}},f=io(c),d=async()=>{if(!navigator.gpu)throw Error("WebGPU not supported.");c.presentationFormat=navigator.gpu.getPreferredCanvasFormat(),c.device=await ch(t),c.supportR16FloatTextureStorage=cu(t)&&lh(c.device,"r16float"),c.supportR16FloatTextureStorage&&(c.maskFormat="r16float"),c.supportF16=lu(t),c.device.lost.then(E=>{E.reason!=="destroyed"&&(c.deviceLost=!0,e.contextLost(E.message),e.contextRestored(E.message))})},p=(E,I,_)=>{_&&f(_),F(c.device);let v=c.device.createCommandEncoder({label:"Renderer Encoder"}),R=v.beginComputePass({label:"frame upload pass"}),U=c.videoFrameRenderer.render(I,R),C=c.maskRenderer.render(E,R);R.end();let O,L;if(_.downSampleFactor===4){let B=v.beginComputePass({label:"downsample pass"}),N=c.maskDownsampler4.render(B,C),D=c.frameDownsampler4.render(B,U);B.end();let X=c.jointBilateralFilterRenderer4.render(v,N,D,_);O=c.maskSmoothingRenderer4.render(v,X,c.prevMask4??X,_);let ne=v.beginComputePass({label:"upsample pass"}),Re=c.maskUpsampler.render(ne,O);ne.end(),L=c.strongMaskBlurRenderer.render(v,Re,so)}else{let B=v.beginComputePass({label:"downsample pass"}),N=c.maskDownsampler2.render(B,C),D=c.frameDownsampler2.render(B,U);B.end();let X=c.jointBilateralFilterRenderer2.render(v,N,D,_);O=c.maskSmoothingRenderer2.render(v,X,c.prevMask2??X,_);let ne=v.beginComputePass({label:"upsample pass"}),Re=c.maskUpsampler.render(ne,O);ne.end(),L=c.edgeBlurRenderer.render(v,Re,_)}if(_.effects==="blur"){let B=c.blurRenderer.render(v,U,_.backgroundBlurAmount);c.blendRenderer.render(v,{foreground:U,background:B,mask:L},_)}else if(_.effects==="overlay"&&_.backgroundImage){let B=v.beginComputePass({label:"background image upload pass"}),N=c.backgroundImageRenderer.render(_.backgroundImage,B);B.end();let D=c.blurRenderer.render(v,N,_.backgroundBlurAmount);c.replaceRenderer.render(v,{foreground:U,background:N,mask:L,blurBackground:D,timestamp:I.timestamp},_)}_.downSampleFactor===4?c.prevMask4=c.prevMaskRenderer.render(v,O):c.prevMask2=c.prevMaskRenderer.render(v,O),c.device.queue.submit([v.finish()])},T=()=>{l.release(),c.deviceLost=!1,c.prevMask2=void 0,c.prevMask4=void 0,c.presentationFormat="rgba8unorm",c.supportR16FloatTextureStorage=!1,c.maskFormat="rgba16float",l=xn(u)},A=()=>c.deviceLost;return{init:d,render:p,release:T,isContextLost:A}};var Z={projection:(t,e,r=-1)=>[2/t,0,0,0,2/e*r,0,-1,1*-r,1],translation:(t,e)=>[1,0,0,0,1,0,t,e,1],rotation:t=>{let e=Math.cos(t),r=Math.sin(t);return[e,-r,0,r,e,0,0,0,1]},scaling:(t,e)=>[t,0,0,0,e,0,0,0,1],multiply:(t,e)=>{let r=t[0],n=t[1],s=t[2],o=t[3],a=t[4],i=t[5],u=t[6],l=t[7],c=t[8],f=e[0],d=e[1],p=e[2],T=e[3],A=e[4],E=e[5],I=e[6],_=e[7],v=e[8];return[f*r+d*o+p*u,f*n+d*a+p*l,f*s+d*i+p*c,T*r+A*o+E*u,T*n+A*a+E*l,T*s+A*i+E*c,I*r+_*o+v*u,I*n+_*a+v*l,I*s+_*i+v*c]},translate:(t,e,r)=>Z.multiply(t,Z.translation(e,r)),rotate:(t,e)=>Z.multiply(t,Z.rotation(e)),scale:(t,e,r)=>Z.multiply(t,Z.scaling(e,r))};var Go={VertexShader:WebGLRenderingContext.VERTEX_SHADER,FragmentShader:WebGLRenderingContext.FRAGMENT_SHADER},xu={[Go.VertexShader]:"VertexShader",[Go.FragmentShader]:"FragmentShader"},pp=t=>typeof t=="string"?t.startsWith("#version 300 es"):!1,wh=t=>{if(!pp(t))throw new Error("Expecting GLSL ES 3.00 shader source")},gp=/ERROR:\s*\d+:(\d+)/gi;function Ah(t,e="",r=0){let n=[...e.matchAll(gp)],s=new Map(n.map((o,a)=>{if(!o[1]||o.index===void 0)return[0,e];let i=Number.parseInt(o[1],10),u=n[a+1],l=u?u.index:e.length,c=e.substring(o.index,l);return[i-1,c]}));return t.split(`
44
+ `)this._line++;else if(e=="*"){if(this._peekAhead()=="/"&&(this._advance(),a--,a==0))return!0}else e=="/"&&this._peekAhead()=="*"&&(this._advance(),a++)}return!0}}let r=h.simpleTokens[e];if(r)return this._addToken(r),!0;let n=h.none,s=this._isAlpha(e),o=e==="_";if(this._isAlphaNumeric(e)){let a=this._peekAhead();for(;this._isAlphaNumeric(a);)e+=this._advance(),a=this._peekAhead()}if(s){let a=h.keywords[e];if(a)return this._addToken(a),!0}if(s||o)return this._addToken(h.tokens.ident),!0;for(;;){let a=this._findType(e),i=this._peekAhead();if(e=="-"&&this._tokens.length>0){if(i=="=")return this._current++,e+=i,this._addToken(h.tokens.minus_equal),!0;if(i=="-")return this._current++,e+=i,this._addToken(h.tokens.minus_minus),!0;let u=this._tokens.length-1;if((h.literal_or_ident.includes(this._tokens[u].type)||this._tokens[u].type==h.tokens.paren_right)&&i!=">")return this._addToken(a),!0}if(e==">"&&(i==">"||i=="=")){let u=!1,l=this._tokens.length-1;for(let c=0;c<5&&l>=0&&!h.assignment_operators.includes(this._tokens[l].type);++c,--l)if(this._tokens[l].type===h.tokens.less_than){l>0&&this._tokens[l-1].isArrayOrTemplateType()&&(u=!0);break}if(u)return this._addToken(a),!0}if(a===h.none){let u=e,l=0,c=2;for(let f=0;f<c;++f)if(u+=this._peekAhead(f),a=this._findType(u),a!==h.none){l=f;break}if(a===h.none)return n!==h.none&&(this._current--,this._addToken(n),!0);e=u,this._current+=l+1}if(n=a,this._isAtEnd())break;e+=this._advance()}return n!==h.none&&(this._addToken(n),!0)}_findType(e){for(let n in h.regexTokens){let s=h.regexTokens[n];if(this._match(e,s.rule))return s}return h.literalTokens[e]||h.none}_match(e,r){let n=r.exec(e);return n&&n.index==0&&n[0]==e}_isAtEnd(){return this._current>=this._source.length}_isAlpha(e){return!this._isNumeric(e)&&!this._isWhitespace(e)&&e!=="_"&&!t._operators.has(e)}_isNumeric(e){return e>="0"&&e<="9"}_isAlphaNumeric(e){return this._isAlpha(e)||this._isNumeric(e)||e==="_"}_isWhitespace(e){return e==" "||e==" "||e=="\r"}_advance(e=0){let r=this._source[this._current];return this._current+=e+1,r??"\0"}_peekAhead(e=0){return this._current+e>=this._source.length?"\0":this._source[this._current+e]}_addToken(e){let r=this._source.substring(this._start,this._current);this._tokens.push(new Jo(e,r,this._line,this._start,this._current))}};function L(t){return Array.isArray(t)||t?.buffer instanceof ArrayBuffer}Qo._operators=new Set([".","(",")","[","]","{","}",",",";",":","=","!","<",">","+","-","*","/","%","&","|","^","~","@","#","?","'","`",'"',"\\",`
45
+ `,"\r"," ","\0"]);var ea=new Float32Array(1),Zm=new Uint32Array(ea.buffer),Jm=new Uint32Array(ea.buffer),ta=new Int32Array(1),Qm=new Float32Array(ta.buffer),e2=new Uint32Array(ta.buffer),ra=new Uint32Array(1),t2=new Float32Array(ra.buffer),r2=new Int32Array(ra.buffer);function Bd(t,e,r){if(e===r)return t;if(e==="f32"){if(r==="i32"||r==="x32")return ea[0]=t,Zm[0];if(r==="u32")return ea[0]=t,Jm[0]}else if(e==="i32"||e==="x32"){if(r==="f32")return ta[0]=t,Qm[0];if(r==="u32")return ta[0]=t,e2[0]}else if(e==="u32"){if(r==="f32")return ra[0]=t,t2[0];if(r==="i32"||r==="x32")return ra[0]=t,r2[0]}return console.error(`Unsupported cast from ${e} to ${r}`),t}var _u=class{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}},Sn=class{constructor(e,r){this.align=e,this.size=r}},Zr=class t{constructor(){this.uniforms=[],this.storage=[],this.immediates=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new pu,this.functions=[],this._types=new Map,this._functions=new Map}_isStorageTexture(e){return e.name=="texture_storage_1d"||e.name=="texture_storage_2d"||e.name=="texture_storage_2d_array"||e.name=="texture_storage_3d"}updateAST(e){for(let r of e)r instanceof Jr&&this._functions.set(r.name,new _u(r));for(let r of e)if(r instanceof jt){let n=this.getTypeInfo(r,null);n instanceof sr&&this.structs.push(n)}for(let r of e)if(r instanceof ms)this.aliases.push(this._getAliasInfo(r));else{if(r instanceof hs){let n=r,s=this._getAttributeNum(n.attributes,"id",0),o=n.type!=null?this.getTypeInfo(n.type,n.attributes):null;this.overrides.push(new fu(n.name,o,n.attributes,s));continue}if(this._isUniformVar(r)){let n=r,s=this._getAttributeNum(n.attributes,"group",0),o=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=new Xr(n.name,a,s,o,n.attributes,Re.Uniform,n.access);i.access||(i.access="read"),this.uniforms.push(i);continue}if(this._isImmediateVar(r)){let n=r,s=this._getAttributeNum(n.attributes,"group",0),o=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=new Xr(n.name,a,s,o,n.attributes,Re.Immediate,n.access);i.access||(i.access="read"),this.immediates.push(i);continue}if(this._isStorageVar(r)){let n=r,s=this._getAttributeNum(n.attributes,"group",0),o=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=this._isStorageTexture(a),u=new Xr(n.name,a,s,o,n.attributes,i?Re.StorageTexture:Re.Storage,n.access);u.access||(u.access="read"),this.storage.push(u);continue}if(this._isTextureVar(r)){let n=r,s=this._getAttributeNum(n.attributes,"group",0),o=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=this._isStorageTexture(a),u=i?a.access:n.access,l=new Xr(n.name,a,s,o,n.attributes,i?Re.StorageTexture:Re.Texture,u||n.access);l.access||(l.access="read"),i?this.storage.push(l):this.textures.push(l);continue}if(this._isSamplerVar(r)){let n=r,s=this._getAttributeNum(n.attributes,"group",0),o=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=new Xr(n.name,a,s,o,n.attributes,Re.Sampler,n.access);this.samplers.push(i);continue}}for(let r of e)if(r instanceof Jr){let n=this._getAttribute(r,"vertex"),s=this._getAttribute(r,"fragment"),o=this._getAttribute(r,"compute"),a=n||s||o,i=new hu(r.name,a?.name,r.attributes);i.attributes=r.attributes,i.startLine=r.startLine,i.endLine=r.endLine,this.functions.push(i),this._functions.get(r.name).info=i,a&&(this._functions.get(r.name).inUse=!0,i.inUse=!0,i.inputs=this._getInputs(r.args),i.outputs=this._getOutputs(r.returnType),this.entry[a.name].push(i)),i.resources=this._findResources(r,!!a),i.arguments=r.args.map(u=>new du(u.name,this.getTypeInfo(u.type,u.attributes),u.attributes)),i.returnType=r.returnType?this.getTypeInfo(r.returnType,r.attributes):null;continue}for(let r of this._functions.values())r.info&&(r.info.inUse=r.inUse,this._addCalls(r.node,r.info.calls));for(let r of this._functions.values())r.node.search(n=>{var s,o,a;if(n instanceof Ko){if(n.value)if(L(n.value))for(let i of n.value)for(let u of this.overrides)i===u.name&&((s=r.info)===null||s===void 0||s.overrides.push(u));else for(let i of this.overrides)n.value===i.name&&((o=r.info)===null||o===void 0||o.overrides.push(i))}else if(n instanceof He)for(let i of this.overrides)n.name===i.name&&((a=r.info)===null||a===void 0||a.overrides.push(i))});for(let r of this.uniforms)this._markStructsInUse(r.type);for(let r of this.storage)this._markStructsInUse(r.type)}getFunctionInfo(e){for(let r of this.functions)if(r.name==e)return r;return null}getStructInfo(e){for(let r of this.structs)if(r.name==e)return r;return null}getOverrideInfo(e){for(let r of this.overrides)if(r.name==e)return r;return null}_markStructsInUse(e){if(e)if(e.isStruct){if(e.inUse=!0,e.members)for(let r of e.members)this._markStructsInUse(r.type)}else if(e.isArray)this._markStructsInUse(e.format);else if(e.isTemplate)e.format&&this._markStructsInUse(e.format);else{let r=this._getAlias(e.name);r&&this._markStructsInUse(r)}}_addCalls(e,r){var n;for(let s of e.calls){let o=(n=this._functions.get(s.name))===null||n===void 0?void 0:n.info;o&&r.add(o)}}findResource(e,r,n){if(n){for(let s of this.entry.compute)if(s.name===n){for(let o of s.resources)if(o.group==e&&o.binding==r)return o}for(let s of this.entry.vertex)if(s.name===n){for(let o of s.resources)if(o.group==e&&o.binding==r)return o}for(let s of this.entry.fragment)if(s.name===n){for(let o of s.resources)if(o.group==e&&o.binding==r)return o}}for(let s of this.uniforms)if(s.group==e&&s.binding==r)return s;for(let s of this.storage)if(s.group==e&&s.binding==r)return s;for(let s of this.textures)if(s.group==e&&s.binding==r)return s;for(let s of this.samplers)if(s.group==e&&s.binding==r)return s;return null}_findResource(e){for(let r of this.uniforms)if(r.name==e)return r;for(let r of this.storage)if(r.name==e)return r;for(let r of this.textures)if(r.name==e)return r;for(let r of this.samplers)if(r.name==e)return r;return null}_markStructsFromAST(e){let r=this.getTypeInfo(e,null);this._markStructsInUse(r)}_findResources(e,r){let n=[],s=this,o=[];return e.search(a=>{if(a instanceof Fn)o.push({});else if(a instanceof Pn)o.pop();else if(a instanceof Pt){let i=a;r&&i.type!==null&&this._markStructsFromAST(i.type),o.length>0&&(o[o.length-1][i.name]=i)}else if(a instanceof Ft){let i=a;r&&i.type!==null&&this._markStructsFromAST(i.type)}else if(a instanceof qr){let i=a;r&&i.type!==null&&this._markStructsFromAST(i.type),o.length>0&&(o[o.length-1][i.name]=i)}else if(a instanceof He){let i=a;if(o.length>0&&o[o.length-1][i.name])return;let u=s._findResource(i.name);u&&n.push(u)}else if(a instanceof gs){let i=a,u=s._functions.get(i.name);if(u&&(r&&(u.inUse=!0),e.calls.add(u.node),u.resources=s._findResources(u.node,r),n.push(...u.resources)),i.name==="textureSample"&&i.args.length>=2){let l=i.args[0],c=null;if(l instanceof He){let p=s._findResource(l.name);p&&p.resourceType===Re.Texture&&(c=p)}let f=i.args[1],d=null;if(f instanceof He){let p=s._findResource(f.name);p&&p.resourceType===Re.Sampler&&(d=p)}c&&d&&(c.relations===null&&(c.relations=[]),c.relations.push(d),d.relations===null&&(d.relations=[]),d.relations.push(c))}}else if(a instanceof ps){let i=a,u=s._functions.get(i.name);u&&(r&&(u.inUse=!0),e.calls.add(u.node),u.resources=s._findResources(u.node,r),n.push(...u.resources))}}),[...new Map(n.map(a=>[a.name,a])).values()]}getBindGroups(){let e=[];function r(n,s){n>=e.length&&(e.length=n+1),e[n]===void 0&&(e[n]=[]),s>=e[n].length&&(e[n].length=s+1)}for(let n of this.uniforms)r(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.storage)r(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.textures)r(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.samplers)r(n.group,n.binding),e[n.group][n.binding]=n;return e}_getOutputs(e,r=void 0){if(r===void 0&&(r=[]),e instanceof jt)this._getStructOutputs(e,r);else{let n=this._getOutputInfo(e);n!==null&&r.push(n)}return r}_getStructOutputs(e,r){for(let n of e.members)if(n.type instanceof jt)this._getStructOutputs(n.type,r);else{let s=this._getAttribute(n,"location")||this._getAttribute(n,"builtin");if(s!==null){let o=this.getTypeInfo(n.type,n.type.attributes),a=this._parseInt(s.value),i=new Io(n.name,o,s.name,a);r.push(i)}}}_getOutputInfo(e){let r=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(r!==null){let n=this.getTypeInfo(e,e.attributes),s=this._parseInt(r.value);return new Io("",n,r.name,s)}return null}_getInputs(e,r=void 0){r===void 0&&(r=[]);for(let n of e)if(n.type instanceof jt)this._getStructInputs(n.type,r);else{let s=this._getInputInfo(n);s!==null&&r.push(s)}return r}_getStructInputs(e,r){for(let n of e.members)if(n.type instanceof jt)this._getStructInputs(n.type,r);else{let s=this._getInputInfo(n);s!==null&&r.push(s)}}_getInputInfo(e){let r=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(r!==null){let n=this._getAttribute(e,"interpolation"),s=this.getTypeInfo(e.type,e.attributes),o=this._parseInt(r.value),a=new lu(e.name,s,r.name,o);return n!==null&&(a.interpolation=this._parseString(n.value)),a}return null}_parseString(e){return e instanceof Array&&(e=e[0]),e}_parseInt(e){e instanceof Array&&(e=e[0]);let r=parseInt(e);return isNaN(r)?e:r}_getAlias(e){for(let r of this.aliases)if(r.name==e)return r.type;return null}_getAliasInfo(e){return new cu(e.name,this.getTypeInfo(e.type,null))}getTypeInfoByName(e){for(let r of this.structs)if(r.name==e)return r;for(let r of this.aliases)if(r.name==e)return r.type;return null}getTypeInfo(e,r=null){if(this._types.has(e))return this._types.get(e);if(e instanceof Bn){let s=e.type?this.getTypeInfo(e.type,e.attributes):null,o=new fs(e.name,s,r);return this._types.set(e,o),this._updateTypeInfo(o),o}if(e instanceof Kr){let s=e,o=s.format?this.getTypeInfo(s.format,s.attributes):null,a=new or(s.name,r);return a.format=o,a.count=s.count,this._types.set(e,a),this._updateTypeInfo(a),a}if(e instanceof jt){let s=e,o=new sr(s.name,r);o.startLine=s.startLine,o.endLine=s.endLine;for(let a of s.members){let i=this.getTypeInfo(a.type,a.attributes);o.members.push(new Ro(a.name,i,a.attributes))}return this._types.set(e,o),this._updateTypeInfo(o),o}if(e instanceof Yr){let s=e,o=s.format instanceof S,a=s.format?o?this.getTypeInfo(s.format,null):new it(s.format,null):null,i=new gr(s.name,a,r,s.access);return this._types.set(e,i),this._updateTypeInfo(i),i}if(e instanceof w){let s=e,o=s.format?this.getTypeInfo(s.format,null):null,a=new gr(s.name,o,r,s.access);return this._types.set(e,a),this._updateTypeInfo(a),a}let n=new it(e.name,r);return this._types.set(e,n),this._updateTypeInfo(n),n}_updateTypeInfo(e){var r,n,s;let o=this._getTypeSize(e);if(e.size=(r=o?.size)!==null&&r!==void 0?r:0,e instanceof or&&e.format){let a=this._getTypeSize(e.format);e.stride=Math.max((n=a?.size)!==null&&n!==void 0?n:0,(s=a?.align)!==null&&s!==void 0?s:0),this._updateTypeInfo(e.format)}e instanceof fs&&this._updateTypeInfo(e.format),e instanceof sr&&this._updateStructInfo(e)}_updateStructInfo(e){var r;let n=0,s=0,o=0,a=0;for(let i=0,u=e.members.length;i<u;++i){let l=e.members[i],c=this._getTypeSize(l);if(!c)continue;(r=this._getAlias(l.type.name))!==null&&r!==void 0||l.type;let f=c.align,d=c.size;n=this._roundUp(f,n+s),s=d,o=n,a=Math.max(a,f),l.offset=n,l.size=d,this._updateTypeInfo(l.type)}e.size=this._roundUp(a,o+s),e.align=a}_getTypeSize(e){var r,n;if(e==null)return null;let s=this._getAttributeNum(e.attributes,"size",0),o=this._getAttributeNum(e.attributes,"align",0);if(e instanceof Ro&&(e=e.type),e instanceof it){let a=this._getAlias(e.name);a!==null&&(e=a)}{let a=t._typeInfo[e.name];if(a!==void 0){let i=((r=e.format)===null||r===void 0?void 0:r.name)==="f16"?2:1;return new Sn(Math.max(o,a.align/i),Math.max(s,a.size/i))}}{let a=t._typeInfo[e.name.substring(0,e.name.length-1)];if(a){let i=e.name[e.name.length-1]==="h"?2:1;return new Sn(Math.max(o,a.align/i),Math.max(s,a.size/i))}}if(e instanceof or){let a=e,i=8,u=8,l=this._getTypeSize(a.format);return l!==null&&(u=l.size,i=l.align),u=a.count*this._getAttributeNum((n=e?.attributes)!==null&&n!==void 0?n:null,"stride",this._roundUp(i,u)),s&&(u=s),new Sn(Math.max(o,i),Math.max(s,u))}if(e instanceof sr){let a=0,i=0,u=0,l=0,c=0;for(let f of e.members){let d=this._getTypeSize(f.type);d!==null&&(a=Math.max(d.align,a),u=this._roundUp(d.align,u+l),l=d.size,c=u)}return i=this._roundUp(a,c+l),new Sn(Math.max(o,a),Math.max(s,i))}return null}_isUniformVar(e){return e instanceof Pt&&e.storage=="uniform"}_isImmediateVar(e){return e instanceof Pt&&e.storage=="immediate"}_isStorageVar(e){return e instanceof Pt&&e.storage=="storage"}_isTextureVar(e){return e instanceof Pt&&e.type!==null&&t._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof Pt&&e.type!==null&&t._samplerTypes.indexOf(e.type.name)!=-1}_getAttribute(e,r){let n=e;if(!n||!n.attributes)return null;let s=n.attributes;for(let o of s)if(o.name==r)return o;return null}_getAttributeNum(e,r,n){if(e===null)return n;for(let s of e)if(s.name==r){let o=s!==null&&s.value!==null?s.value:n;return o instanceof Array&&(o=o[0]),typeof o=="number"?o:typeof o=="string"?parseInt(o):n}return n}_roundUp(e,r){return Math.ceil(r/e)*e}};Zr._typeInfo={f16:{align:2,size:2},i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},atomic:{align:4,size:4},vec2:{align:8,size:8},vec3:{align:16,size:12},vec4:{align:16,size:16},mat2x2:{align:8,size:16},mat3x2:{align:8,size:24},mat4x2:{align:8,size:32},mat2x3:{align:16,size:32},mat3x3:{align:16,size:48},mat4x3:{align:16,size:64},mat2x4:{align:16,size:32},mat3x4:{align:16,size:48},mat4x4:{align:16,size:64}},Zr._textureTypes=h.any_texture_type.map(t=>t.name),Zr._samplerTypes=h.sampler_type.map(t=>t.name);var Cu=0,bu=class t{constructor(e,r,n){this.id=Cu++,this.name=e,this.value=r,this.node=n}clone(){return new t(this.name,this.value,this.node)}},vu=class t{constructor(e){this.id=Cu++,this.name=e.name,this.node=e}clone(){return new t(this.node)}},wu=class t{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName="",this.id=Cu++,e&&(this.parent=e,this.currentFunctionName=e.currentFunctionName)}getVariable(e){var r;return this.variables.has(e)?(r=this.variables.get(e))!==null&&r!==void 0?r:null:this.parent?this.parent.getVariable(e):null}getFunction(e){var r;return this.functions.has(e)?(r=this.functions.get(e))!==null&&r!==void 0?r:null:this.parent?this.parent.getFunction(e):null}createVariable(e,r,n){this.variables.set(e,new bu(e,r,n??null))}setVariable(e,r,n){let s=this.getVariable(e);s!==null?s.value=r:this.createVariable(e,r,n)}getVariableValue(e){var r;let n=this.getVariable(e);return(r=n?.value)!==null&&r!==void 0?r:null}clone(){return new t(this)}},Tu=class{evalExpression(e,r){return null}getTypeInfo(e){return null}getVariableName(e,r){return""}},ku=class{constructor(e){this.exec=e}getTypeInfo(e){return this.exec.getTypeInfo(e)}All(e,r){let n=this.exec.evalExpression(e.args[0],r),s=!0;if(n instanceof g)return n.data.forEach(o=>{o||(s=!1)}),new v(s?1:0,this.getTypeInfo("bool"));throw new Error(`All() expects a vector argument. Line ${e.line}`)}Any(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g){let s=n.data.some(o=>o);return new v(s?1:0,this.getTypeInfo("bool"))}throw new Error(`Any() expects a vector argument. Line ${e.line}`)}Select(e,r){let n=this.exec.evalExpression(e.args[2],r);if(!(n instanceof v))throw new Error(`Select() expects a bool condition. Line ${e.line}`);return n.value?this.exec.evalExpression(e.args[1],r):this.exec.evalExpression(e.args[0],r)}ArrayLength(e,r){let n=e.args[0];n instanceof Ee&&(n=n.right);let s=this.exec.evalExpression(n,r);if(s instanceof Ae&&s.typeInfo.size===0){let o=s.typeInfo,a=s.buffer.byteLength/o.stride;return new v(a,this.getTypeInfo("u32"))}return new v(s.typeInfo.size,this.getTypeInfo("u32"))}Abs(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.abs(o)),n.typeInfo);let s=n;return new v(Math.abs(s.value),s.typeInfo)}Acos(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.acos(o)),n.typeInfo);let s=n;return new v(Math.acos(s.value),n.typeInfo)}Acosh(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.acosh(o)),n.typeInfo);let s=n;return new v(Math.acosh(s.value),n.typeInfo)}Asin(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.asin(o)),n.typeInfo);let s=n;return new v(Math.asin(s.value),n.typeInfo)}Asinh(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.asinh(o)),n.typeInfo);let s=n;return new v(Math.asinh(s.value),n.typeInfo)}Atan(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.atan(o)),n.typeInfo);let s=n;return new v(Math.atan(s.value),n.typeInfo)}Atanh(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.atanh(o)),n.typeInfo);let s=n;return new v(Math.atanh(s.value),n.typeInfo)}Atan2(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(n instanceof g&&s instanceof g)return new g(n.data.map((i,u)=>Math.atan2(i,s.data[u])),n.typeInfo);let o=n,a=s;return new v(Math.atan2(o.value,a.value),n.typeInfo)}Ceil(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.ceil(o)),n.typeInfo);let s=n;return new v(Math.ceil(s.value),n.typeInfo)}_clamp(e,r,n){return Math.min(Math.max(e,r),n)}Clamp(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r),o=this.exec.evalExpression(e.args[2],r);if(n instanceof g&&s instanceof g&&o instanceof g)return new g(n.data.map((l,c)=>this._clamp(l,s.data[c],o.data[c])),n.typeInfo);let a=n,i=s,u=o;return new v(this._clamp(a.value,i.value,u.value),n.typeInfo)}Cos(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.cos(o)),n.typeInfo);let s=n;return new v(Math.cos(s.value),n.typeInfo)}Cosh(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.cosh(o)),n.typeInfo);let s=n;return new v(Math.cos(s.value),n.typeInfo)}CountLeadingZeros(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.clz32(o)),n.typeInfo);let s=n;return new v(Math.clz32(s.value),n.typeInfo)}_countOneBits(e){let r=0;for(;e!==0;)1&e&&r++,e>>=1;return r}CountOneBits(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>this._countOneBits(o)),n.typeInfo);let s=n;return new v(this._countOneBits(s.value),n.typeInfo)}_countTrailingZeros(e){if(e===0)return 32;let r=0;for(;!(1&e);)e>>=1,r++;return r}CountTrailingZeros(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>this._countTrailingZeros(o)),n.typeInfo);let s=n;return new v(this._countTrailingZeros(s.value),n.typeInfo)}Cross(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(n instanceof g&&s instanceof g){if(n.data.length!==3||s.data.length!==3)return console.error(`Cross() expects 3D vectors. Line ${e.line}`),null;let o=n.data,a=s.data;return new g([o[1]*a[2]-a[1]*o[2],o[2]*a[0]-a[2]*o[0],o[0]*a[1]-a[0]*o[1]],n.typeInfo)}return console.error(`Cross() expects vector arguments. Line ${e.line}`),null}Degrees(e,r){let n=this.exec.evalExpression(e.args[0],r),s=180/Math.PI;return n instanceof g?new g(n.data.map(o=>o*s),n.typeInfo):new v(n.value*s,this.getTypeInfo("f32"))}Determinant(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof H){let s=n.data,o=n.typeInfo.getTypeName(),a=o.endsWith("h")?this.getTypeInfo("f16"):this.getTypeInfo("f32");if(o==="mat2x2"||o==="mat2x2f"||o==="mat2x2h")return new v(s[0]*s[3]-s[1]*s[2],a);if(o==="mat2x3"||o==="mat2x3f"||o==="mat2x3h")return new v(s[0]*(s[4]*s[8]-s[5]*s[7])-s[1]*(s[3]*s[8]-s[5]*s[6])+s[2]*(s[3]*s[7]-s[4]*s[6]),a);if(o==="mat2x4"||o==="mat2x4f"||o==="mat2x4h")console.error(`TODO: Determinant for ${o}`);else if(o==="mat3x2"||o==="mat3x2f"||o==="mat3x2h")console.error(`TODO: Determinant for ${o}`);else{if(o==="mat3x3"||o==="mat3x3f"||o==="mat3x3h")return new v(s[0]*(s[4]*s[8]-s[5]*s[7])-s[1]*(s[3]*s[8]-s[5]*s[6])+s[2]*(s[3]*s[7]-s[4]*s[6]),a);o==="mat3x4"||o==="mat3x4f"||o==="mat3x4h"||o==="mat4x2"||o==="mat4x2f"||o==="mat4x2h"||o==="mat4x3"||o==="mat4x3f"||o==="mat4x3h"?console.error(`TODO: Determinant for ${o}`):o!=="mat4x4"&&o!=="mat4x4f"&&o!=="mat4x4h"||console.error(`TODO: Determinant for ${o}`)}}return console.error(`Determinant expects a matrix argument. Line ${e.line}`),null}Distance(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(n instanceof g&&s instanceof g){let i=0;for(let u=0;u<n.data.length;++u)i+=(n.data[u]-s.data[u])*(n.data[u]-s.data[u]);return new v(Math.sqrt(i),this.getTypeInfo("f32"))}let o=n,a=s;return new v(Math.abs(o.value-a.value),n.typeInfo)}_dot(e,r){let n=0;for(let s=0;s<e.length;++s)n+=r[s]*e[s];return n}Dot(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);return n instanceof g&&s instanceof g?new v(this._dot(n.data,s.data),this.getTypeInfo("f32")):(console.error(`Dot() expects vector arguments. Line ${e.line}`),null)}Dot4U8Packed(e,r){return console.error(`TODO: dot4U8Packed. Line ${e.line}`),null}Dot4I8Packed(e,r){return console.error(`TODO: dot4I8Packed. Line ${e.line}`),null}Exp(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.exp(o)),n.typeInfo);let s=n;return new v(Math.exp(s.value),n.typeInfo)}Exp2(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.pow(2,o)),n.typeInfo);let s=n;return new v(Math.pow(2,s.value),n.typeInfo)}ExtractBits(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r),o=this.exec.evalExpression(e.args[2],r);if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 offset argument. Line ${e.line}`),null;if(o.typeInfo.name!=="u32"&&o.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 count argument. Line ${e.line}`),null;let a=s.value,i=o.value;if(n instanceof g)return new g(n.data.map(l=>l>>a&(1<<i)-1),n.typeInfo);if(n.typeInfo.name!=="i32"&&n.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 argument. Line ${e.line}`),null;let u=n.value;return new v(u>>a&(1<<i)-1,this.getTypeInfo("i32"))}FaceForward(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r),o=this.exec.evalExpression(e.args[2],r);if(n instanceof g&&s instanceof g&&o instanceof g){let a=this._dot(s.data,o.data);return new g(a<0?Array.from(n.data):n.data.map(i=>-i),n.typeInfo)}return console.error(`FaceForward() expects vector arguments. Line ${e.line}`),null}_firstLeadingBit(e){return e===0?-1:31-Math.clz32(e)}FirstLeadingBit(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>this._firstLeadingBit(o)),n.typeInfo);let s=n;return new v(this._firstLeadingBit(s.value),n.typeInfo)}_firstTrailingBit(e){return e===0?-1:Math.log2(e&-e)}FirstTrailingBit(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>this._firstTrailingBit(o)),n.typeInfo);let s=n;return new v(this._firstTrailingBit(s.value),n.typeInfo)}Floor(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.floor(o)),n.typeInfo);let s=n;return new v(Math.floor(s.value),n.typeInfo)}Fma(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r),o=this.exec.evalExpression(e.args[2],r);if(n instanceof g&&s instanceof g&&o instanceof g)return n.data.length!==s.data.length||n.data.length!==o.data.length?(console.error(`Fma() expects vectors of the same length. Line ${e.line}`),null):new g(n.data.map((l,c)=>l*s.data[c]+o.data[c]),n.typeInfo);let a=n,i=s,u=o;return new v(a.value*i.value+u.value,a.typeInfo)}Fract(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>o-Math.floor(o)),n.typeInfo);let s=n;return new v(s.value-Math.floor(s.value),n.typeInfo)}Frexp(e,r){return console.error(`TODO: frexp. Line ${e.line}`),null}InsertBits(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r),o=this.exec.evalExpression(e.args[2],r),a=this.exec.evalExpression(e.args[3],r);if(o.typeInfo.name!=="u32"&&o.typeInfo.name!=="x32")return console.error(`InsertBits() expects an i32 offset argument. Line ${e.line}`),null;let i=o.value,u=(1<<a.value)-1<<i,l=~u;if(n instanceof g&&s instanceof g)return new g(n.data.map((d,p)=>d&l|s.data[p]<<i&u),n.typeInfo);let c=n.value,f=s.value;return new v(c&l|f<<i&u,n.typeInfo)}InverseSqrt(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>1/Math.sqrt(o)),n.typeInfo);let s=n;return new v(1/Math.sqrt(s.value),n.typeInfo)}Ldexp(e,r){return console.error(`TODO: ldexp. Line ${e.line}`),null}Length(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g){let o=0;return n.data.forEach(a=>{o+=a*a}),new v(Math.sqrt(o),this.getTypeInfo("f32"))}let s=n;return new v(Math.abs(s.value),n.typeInfo)}Log(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.log(o)),n.typeInfo);let s=n;return new v(Math.log(s.value),n.typeInfo)}Log2(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.log2(o)),n.typeInfo);let s=n;return new v(Math.log2(s.value),n.typeInfo)}Max(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(n instanceof g&&s instanceof g)return new g(n.data.map((i,u)=>Math.max(i,s.data[u])),n.typeInfo);let o=n,a=s;return new v(Math.max(o.value,a.value),n.typeInfo)}Min(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(n instanceof g&&s instanceof g)return new g(n.data.map((i,u)=>Math.min(i,s.data[u])),n.typeInfo);let o=n,a=s;return new v(Math.min(o.value,a.value),n.typeInfo)}Mix(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r),o=this.exec.evalExpression(e.args[2],r);if(n instanceof g&&s instanceof g&&o instanceof g)return new g(n.data.map((u,l)=>n.data[l]*(1-o.data[l])+s.data[l]*o.data[l]),n.typeInfo);let a=s,i=o;return new v(n.value*(1-i.value)+a.value*i.value,n.typeInfo)}Modf(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(n instanceof g&&s instanceof g)return new g(n.data.map((a,i)=>a%s.data[i]),n.typeInfo);let o=s;return new v(n.value%o.value,n.typeInfo)}Normalize(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g){let s=this.Length(e,r).value;return new g(n.data.map(o=>o/s),n.typeInfo)}return console.error(`Normalize() expects a vector argument. Line ${e.line}`),null}Pow(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(n instanceof g&&s instanceof g)return new g(n.data.map((i,u)=>Math.pow(i,s.data[u])),n.typeInfo);let o=n,a=s;return new v(Math.pow(o.value,a.value),n.typeInfo)}QuantizeToF16(e,r){let n=this.exec.evalExpression(e.args[0],r);return n instanceof g?new g(n.data.map(s=>s),n.typeInfo):new v(n.value,n.typeInfo)}Radians(e,r){let n=this.exec.evalExpression(e.args[0],r);return n instanceof g?new g(n.data.map(s=>s*Math.PI/180),n.typeInfo):new v(n.value*Math.PI/180,this.getTypeInfo("f32"))}Reflect(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(n instanceof g&&s instanceof g){let o=this._dot(n.data,s.data);return new g(n.data.map((a,i)=>a-2*o*s.data[i]),n.typeInfo)}return console.error(`Reflect() expects vector arguments. Line ${e.line}`),null}Refract(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r),o=this.exec.evalExpression(e.args[2],r);if(n instanceof g&&s instanceof g&&o instanceof v){let a=this._dot(s.data,n.data);return new g(n.data.map((i,u)=>{let l=1-o.value*o.value*(1-a*a);if(l<0)return 0;let c=Math.sqrt(l);return o.value*i-(o.value*a+c)*s.data[u]}),n.typeInfo)}return console.error(`Refract() expects vector arguments and a scalar argument. Line ${e.line}`),null}ReverseBits(e,r){return console.error(`TODO: reverseBits. Line ${e.line}`),null}Round(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.round(o)),n.typeInfo);let s=n;return new v(Math.round(s.value),n.typeInfo)}Saturate(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.min(Math.max(o,0),1)),n.typeInfo);let s=n;return new v(Math.min(Math.max(s.value,0),1),n.typeInfo)}Sign(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.sign(o)),n.typeInfo);let s=n;return new v(Math.sign(s.value),n.typeInfo)}Sin(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.sin(o)),n.typeInfo);let s=n;return new v(Math.sin(s.value),n.typeInfo)}Sinh(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.sinh(o)),n.typeInfo);let s=n;return new v(Math.sinh(s.value),n.typeInfo)}_smoothstep(e,r,n){let s=Math.min(Math.max((n-e)/(r-e),0),1);return s*s*(3-2*s)}SmoothStep(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r),o=this.exec.evalExpression(e.args[2],r);if(o instanceof g&&n instanceof g&&s instanceof g)return new g(o.data.map((l,c)=>this._smoothstep(n.data[c],s.data[c],l)),o.typeInfo);let a=n,i=s,u=o;return new v(this._smoothstep(a.value,i.value,u.value),o.typeInfo)}Sqrt(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.sqrt(o)),n.typeInfo);let s=n;return new v(Math.sqrt(s.value),n.typeInfo)}Step(e,r){let n=this.exec.evalExpression(e.args[0],r),s=this.exec.evalExpression(e.args[1],r);if(s instanceof g&&n instanceof g)return new g(s.data.map((a,i)=>a<n.data[i]?0:1),s.typeInfo);let o=n;return new v(s.value<o.value?0:1,o.typeInfo)}Tan(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.tan(o)),n.typeInfo);let s=n;return new v(Math.tan(s.value),n.typeInfo)}Tanh(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.tanh(o)),n.typeInfo);let s=n;return new v(Math.tanh(s.value),n.typeInfo)}_getTransposeType(e){let r=e.getTypeName();return r==="mat2x2f"||r==="mat2x2h"?e:r==="mat2x3f"?this.getTypeInfo("mat3x2f"):r==="mat2x3h"?this.getTypeInfo("mat3x2h"):r==="mat2x4f"?this.getTypeInfo("mat4x2f"):r==="mat2x4h"?this.getTypeInfo("mat4x2h"):r==="mat3x2f"?this.getTypeInfo("mat2x3f"):r==="mat3x2h"?this.getTypeInfo("mat2x3h"):r==="mat3x3f"||r==="mat3x3h"?e:r==="mat3x4f"?this.getTypeInfo("mat4x3f"):r==="mat3x4h"?this.getTypeInfo("mat4x3h"):r==="mat4x2f"?this.getTypeInfo("mat2x4f"):r==="mat4x2h"?this.getTypeInfo("mat2x4h"):r==="mat4x3f"?this.getTypeInfo("mat3x4f"):r==="mat4x3h"?this.getTypeInfo("mat3x4h"):(r==="mat4x4f"||r==="mat4x4h"||console.error(`Invalid matrix type ${r}`),e)}Transpose(e,r){let n=this.exec.evalExpression(e.args[0],r);if(!(n instanceof H))return console.error(`Transpose() expects a matrix argument. Line ${e.line}`),null;let s=this._getTransposeType(n.typeInfo);if(n.typeInfo.name==="mat2x2"||n.typeInfo.name==="mat2x2f"||n.typeInfo.name==="mat2x2h"){let o=n.data;return new H([o[0],o[2],o[1],o[3]],s)}if(n.typeInfo.name==="mat2x3"||n.typeInfo.name==="mat2x3f"||n.typeInfo.name==="mat2x3h"){let o=n.data;return new H([o[0],o[3],o[6],o[1],o[4],o[7]],s)}if(n.typeInfo.name==="mat2x4"||n.typeInfo.name==="mat2x4f"||n.typeInfo.name==="mat2x4h"){let o=n.data;return new H([o[0],o[4],o[8],o[12],o[1],o[5],o[9],o[13]],s)}if(n.typeInfo.name==="mat3x2"||n.typeInfo.name==="mat3x2f"||n.typeInfo.name==="mat3x2h"){let o=n.data;return new H([o[0],o[3],o[1],o[4],o[2],o[5]],s)}if(n.typeInfo.name==="mat3x3"||n.typeInfo.name==="mat3x3f"||n.typeInfo.name==="mat3x3h"){let o=n.data;return new H([o[0],o[3],o[6],o[1],o[4],o[7],o[2],o[5],o[8]],s)}if(n.typeInfo.name==="mat3x4"||n.typeInfo.name==="mat3x4f"||n.typeInfo.name==="mat3x4h"){let o=n.data;return new H([o[0],o[4],o[8],o[12],o[1],o[5],o[9],o[13],o[2],o[6],o[10],o[14]],s)}if(n.typeInfo.name==="mat4x2"||n.typeInfo.name==="mat4x2f"||n.typeInfo.name==="mat4x2h"){let o=n.data;return new H([o[0],o[4],o[1],o[5],o[2],o[6]],s)}if(n.typeInfo.name==="mat4x3"||n.typeInfo.name==="mat4x3f"||n.typeInfo.name==="mat4x3h"){let o=n.data;return new H([o[0],o[4],o[8],o[1],o[5],o[9],o[2],o[6],o[10]],s)}if(n.typeInfo.name==="mat4x4"||n.typeInfo.name==="mat4x4f"||n.typeInfo.name==="mat4x4h"){let o=n.data;return new H([o[0],o[4],o[8],o[12],o[1],o[5],o[9],o[13],o[2],o[6],o[10],o[14],o[3],o[7],o[11],o[15]],s)}return console.error(`Invalid matrix type ${n.typeInfo.name}`),null}Trunc(e,r){let n=this.exec.evalExpression(e.args[0],r);if(n instanceof g)return new g(n.data.map(o=>Math.trunc(o)),n.typeInfo);let s=n;return new v(Math.trunc(s.value),n.typeInfo)}Dpdx(e,r){return console.error(`TODO: dpdx. Line ${e.line}`),null}DpdxCoarse(e,r){return console.error(`TODO: dpdxCoarse. Line ${e.line}`),null}DpdxFine(e,r){return console.error("TODO: dpdxFine"),null}Dpdy(e,r){return console.error("TODO: dpdy"),null}DpdyCoarse(e,r){return console.error("TODO: dpdyCoarse"),null}DpdyFine(e,r){return console.error("TODO: dpdyFine"),null}Fwidth(e,r){return console.error("TODO: fwidth"),null}FwidthCoarse(e,r){return console.error("TODO: fwidthCoarse"),null}FwidthFine(e,r){return console.error("TODO: fwidthFine"),null}TextureDimensions(e,r){let n=e.args[0],s=e.args.length>1?this.exec.evalExpression(e.args[1],r).value:0;if(n instanceof He){let o=n.name,a=r.getVariableValue(o);if(a instanceof mr){if(s<0||s>=a.mipLevelCount)return console.error(`Invalid mip level for textureDimensions. Line ${e.line}`),null;let i=a.getMipLevelSize(s),u=a.dimension;return u==="1d"?new v(i[0],this.getTypeInfo("u32")):u==="3d"?new g(i,this.getTypeInfo("vec3u")):u==="2d"?new g(i.slice(0,2),this.getTypeInfo("vec2u")):(console.error(`Invalid texture dimension ${u} not found. Line ${e.line}`),null)}return console.error(`Texture ${o} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureDimensions. Line ${e.line}`),null}TextureGather(e,r){return console.error("TODO: textureGather"),null}TextureGatherCompare(e,r){return console.error("TODO: textureGatherCompare"),null}TextureLoad(e,r){let n=e.args[0],s=this.exec.evalExpression(e.args[1],r);if(!(s instanceof g)||s.data.length!==2)return console.error(`Invalid UV argument for textureLoad. Line ${e.line}`),null;if(n instanceof He){let o=n.name,a=r.getVariableValue(o);if(a instanceof mr){let i=0,u=0;["texture_storage_2d_array","texture_2d_array","texture_depth_2d_array"].indexOf(a.typeInfo.name)>-1&&(i=this.exec.evalExpression(e.args[2],r).value),["texture_1d","texture_2d","texture_depth_2d","texture_3d"].indexOf(a.typeInfo.name)>-1&&(u=this.exec.evalExpression(e.args[2],r).value),["texture_2d_array","texture_depth_2d_array"].indexOf(a.typeInfo.name)>-1&&(u=this.exec.evalExpression(e.args[3],r).value);let l=Math.floor(s.data[0]),c=Math.floor(s.data[1]),f=Math.floor(i),d=Math.floor(u);if(l<0||l>=a.width||c<0||c>=a.height)return console.error(`Texture ${o} out of bounds. Line ${e.line}`),null;let p=a.getPixel(l,c,f,d);return p===null?(console.error(`Invalid texture format for textureLoad. Line ${e.line}`),null):new g(p,this.getTypeInfo("vec4f"))}return console.error(`Texture ${o} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureLoad. Line ${e.line}`),null}TextureNumLayers(e,r){let n=e.args[0];if(n instanceof He){let s=n.name,o=r.getVariableValue(s);return o instanceof mr?new v(o.depthOrArrayLayers,this.getTypeInfo("u32")):(console.error(`Texture ${s} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLayers. Line ${e.line}`),null}TextureNumLevels(e,r){let n=e.args[0];if(n instanceof He){let s=n.name,o=r.getVariableValue(s);return o instanceof mr?new v(o.mipLevelCount,this.getTypeInfo("u32")):(console.error(`Texture ${s} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLevels. Line ${e.line}`),null}TextureNumSamples(e,r){let n=e.args[0];if(n instanceof He){let s=n.name,o=r.getVariableValue(s);return o instanceof mr?new v(o.sampleCount,this.getTypeInfo("u32")):(console.error(`Texture ${s} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumSamples. Line ${e.line}`),null}TextureSample(e,r){return console.error("TODO: textureSample"),null}TextureSampleBias(e,r){return console.error("TODO: textureSampleBias"),null}TextureSampleCompare(e,r){return console.error("TODO: textureSampleCompare"),null}TextureSampleCompareLevel(e,r){return console.error("TODO: textureSampleCompareLevel"),null}TextureSampleGrad(e,r){return console.error("TODO: textureSampleGrad"),null}TextureSampleLevel(e,r){return console.error("TODO: textureSampleLevel"),null}TextureSampleBaseClampToEdge(e,r){return console.error("TODO: textureSampleBaseClampToEdge"),null}TextureStore(e,r){let n=e.args[0],s=this.exec.evalExpression(e.args[1],r),o=e.args.length===4?this.exec.evalExpression(e.args[2],r).value:0,a=e.args.length===4?this.exec.evalExpression(e.args[3],r).data:this.exec.evalExpression(e.args[2],r).data;if(a.length!==4)return console.error(`Invalid value argument for textureStore. Line ${e.line}`),null;if(!(s instanceof g)||s.data.length!==2)return console.error(`Invalid UV argument for textureStore. Line ${e.line}`),null;if(n instanceof He){let i=n.name,u=r.getVariableValue(i);if(u instanceof mr){let l=u.getMipLevelSize(0),c=Math.floor(s.data[0]),f=Math.floor(s.data[1]);return c<0||c>=l[0]||f<0||f>=l[1]?(console.error(`Texture ${i} out of bounds. Line ${e.line}`),null):(u.setPixel(c,f,0,o,Array.from(a)),null)}return console.error(`Texture ${i} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureStore. Line ${e.line}`),null}AtomicLoad(e,r){let n=e.args[0];n instanceof Ee&&(n=n.right);let s=this.exec.getVariableName(n,r);return r.getVariable(s).value.getSubData(this.exec,n.postfix,r)}AtomicStore(e,r){let n=e.args[0];n instanceof Ee&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r);return u instanceof v&&i instanceof v&&(u.value=i.value),o.value instanceof Ae&&o.value.setDataValue(this.exec,u,n.postfix,r),null}AtomicAdd(e,r){let n=e.args[0];n instanceof Ee&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r),l=new v(u.value,u.typeInfo);return u instanceof v&&i instanceof v&&(u.value+=i.value),o.value instanceof Ae&&o.value.setDataValue(this.exec,u,n.postfix,r),l}AtomicSub(e,r){let n=e.args[0];n instanceof Ee&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r),l=new v(u.value,u.typeInfo);return u instanceof v&&i instanceof v&&(u.value-=i.value),o.value instanceof Ae&&o.value.setDataValue(this.exec,u,n.postfix,r),l}AtomicMax(e,r){let n=e.args[0];n instanceof Ee&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r),l=new v(u.value,u.typeInfo);return u instanceof v&&i instanceof v&&(u.value=Math.max(u.value,i.value)),o.value instanceof Ae&&o.value.setDataValue(this.exec,u,n.postfix,r),l}AtomicMin(e,r){let n=e.args[0];n instanceof Ee&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r),l=new v(u.value,u.typeInfo);return u instanceof v&&i instanceof v&&(u.value=Math.min(u.value,i.value)),o.value instanceof Ae&&o.value.setDataValue(this.exec,u,n.postfix,r),l}AtomicAnd(e,r){let n=e.args[0];n instanceof Ee&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r),l=new v(u.value,u.typeInfo);return u instanceof v&&i instanceof v&&(u.value=u.value&i.value),o.value instanceof Ae&&o.value.setDataValue(this.exec,u,n.postfix,r),l}AtomicOr(e,r){let n=e.args[0];n instanceof Ee&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r),l=new v(u.value,u.typeInfo);return u instanceof v&&i instanceof v&&(u.value=u.value|i.value),o.value instanceof Ae&&o.value.setDataValue(this.exec,u,n.postfix,r),l}AtomicXor(e,r){let n=e.args[0];n instanceof Ee&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r),l=new v(u.value,u.typeInfo);return u instanceof v&&i instanceof v&&(u.value=u.value^i.value),o.value instanceof Ae&&o.value.setDataValue(this.exec,u,n.postfix,r),l}AtomicExchange(e,r){let n=e.args[0];n instanceof Ee&&(n=n.right);let s=this.exec.getVariableName(n,r),o=r.getVariable(s),a=e.args[1],i=this.exec.evalExpression(a,r),u=o.value.getSubData(this.exec,n.postfix,r),l=new v(u.value,u.typeInfo);return u instanceof v&&i instanceof v&&(u.value=i.value),o.value instanceof Ae&&o.value.setDataValue(this.exec,u,n.postfix,r),l}AtomicCompareExchangeWeak(e,r){return console.error("TODO: atomicCompareExchangeWeak"),null}Pack4x8snorm(e,r){return console.error("TODO: pack4x8snorm"),null}Pack4x8unorm(e,r){return console.error("TODO: pack4x8unorm"),null}Pack4xI8(e,r){return console.error("TODO: pack4xI8"),null}Pack4xU8(e,r){return console.error("TODO: pack4xU8"),null}Pack4x8Clamp(e,r){return console.error("TODO: pack4x8Clamp"),null}Pack4xU8Clamp(e,r){return console.error("TODO: pack4xU8Clamp"),null}Pack2x16snorm(e,r){return console.error("TODO: pack2x16snorm"),null}Pack2x16unorm(e,r){return console.error("TODO: pack2x16unorm"),null}Pack2x16float(e,r){return console.error("TODO: pack2x16float"),null}Unpack4x8snorm(e,r){return console.error("TODO: unpack4x8snorm"),null}Unpack4x8unorm(e,r){return console.error("TODO: unpack4x8unorm"),null}Unpack4xI8(e,r){return console.error("TODO: unpack4xI8"),null}Unpack4xU8(e,r){return console.error("TODO: unpack4xU8"),null}Unpack2x16snorm(e,r){return console.error("TODO: unpack2x16snorm"),null}Unpack2x16unorm(e,r){return console.error("TODO: unpack2x16unorm"),null}Unpack2x16float(e,r){return console.error("TODO: unpack2x16float"),null}StorageBarrier(e,r){return null}TextureBarrier(e,r){return null}WorkgroupBarrier(e,r){return null}WorkgroupUniformLoad(e,r){return null}SubgroupAdd(e,r){return console.error("TODO: subgroupAdd"),null}SubgroupExclusiveAdd(e,r){return console.error("TODO: subgroupExclusiveAdd"),null}SubgroupInclusiveAdd(e,r){return console.error("TODO: subgroupInclusiveAdd"),null}SubgroupAll(e,r){return console.error("TODO: subgroupAll"),null}SubgroupAnd(e,r){return console.error("TODO: subgroupAnd"),null}SubgroupAny(e,r){return console.error("TODO: subgroupAny"),null}SubgroupBallot(e,r){return console.error("TODO: subgroupBallot"),null}SubgroupBroadcast(e,r){return console.error("TODO: subgroupBroadcast"),null}SubgroupBroadcastFirst(e,r){return console.error("TODO: subgroupBroadcastFirst"),null}SubgroupElect(e,r){return console.error("TODO: subgroupElect"),null}SubgroupMax(e,r){return console.error("TODO: subgroupMax"),null}SubgroupMin(e,r){return console.error("TODO: subgroupMin"),null}SubgroupMul(e,r){return console.error("TODO: subgroupMul"),null}SubgroupExclusiveMul(e,r){return console.error("TODO: subgroupExclusiveMul"),null}SubgroupInclusiveMul(e,r){return console.error("TODO: subgroupInclusiveMul"),null}SubgroupOr(e,r){return console.error("TODO: subgroupOr"),null}SubgroupShuffle(e,r){return console.error("TODO: subgroupShuffle"),null}SubgroupShuffleDown(e,r){return console.error("TODO: subgroupShuffleDown"),null}SubgroupShuffleUp(e,r){return console.error("TODO: subgroupShuffleUp"),null}SubgroupShuffleXor(e,r){return console.error("TODO: subgroupShuffleXor"),null}SubgroupXor(e,r){return console.error("TODO: subgroupXor"),null}QuadBroadcast(e,r){return console.error("TODO: quadBroadcast"),null}QuadSwapDiagonal(e,r){return console.error("TODO: quadSwapDiagonal"),null}QuadSwapX(e,r){return console.error("TODO: quadSwapX"),null}QuadSwapY(e,r){return console.error("TODO: quadSwapY"),null}},su={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},nt={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]},bt=class t extends Tu{constructor(e,r){var n;super(),this.ast=e??[],this.reflection=new Zr,this.reflection.updateAST(this.ast),this.context=(n=r?.clone())!==null&&n!==void 0?n:new wu,this.builtins=new ku(this),this.typeInfo={bool:this.getTypeInfo(S.bool),i32:this.getTypeInfo(S.i32),u32:this.getTypeInfo(S.u32),f32:this.getTypeInfo(S.f32),f16:this.getTypeInfo(S.f16),vec2f:this.getTypeInfo(w.vec2f),vec2u:this.getTypeInfo(w.vec2u),vec2i:this.getTypeInfo(w.vec2i),vec2h:this.getTypeInfo(w.vec2h),vec3f:this.getTypeInfo(w.vec3f),vec3u:this.getTypeInfo(w.vec3u),vec3i:this.getTypeInfo(w.vec3i),vec3h:this.getTypeInfo(w.vec3h),vec4f:this.getTypeInfo(w.vec4f),vec4u:this.getTypeInfo(w.vec4u),vec4i:this.getTypeInfo(w.vec4i),vec4h:this.getTypeInfo(w.vec4h),mat2x2f:this.getTypeInfo(w.mat2x2f),mat2x3f:this.getTypeInfo(w.mat2x3f),mat2x4f:this.getTypeInfo(w.mat2x4f),mat3x2f:this.getTypeInfo(w.mat3x2f),mat3x3f:this.getTypeInfo(w.mat3x3f),mat3x4f:this.getTypeInfo(w.mat3x4f),mat4x2f:this.getTypeInfo(w.mat4x2f),mat4x3f:this.getTypeInfo(w.mat4x3f),mat4x4f:this.getTypeInfo(w.mat4x4f)}}getVariableValue(e){var r,n;let s=(n=(r=this.context.getVariable(e))===null||r===void 0?void 0:r.value)!==null&&n!==void 0?n:null;if(s===null)return null;if(s instanceof v)return s.value;if(s instanceof g||s instanceof H)return Array.from(s.data);if(s instanceof Ae&&s.typeInfo instanceof or){if(s.typeInfo.format.name==="u32")return Array.from(new Uint32Array(s.buffer,s.offset,s.typeInfo.count));if(s.typeInfo.format.name==="i32")return Array.from(new Int32Array(s.buffer,s.offset,s.typeInfo.count));if(s.typeInfo.format.name==="f32")return Array.from(new Float32Array(s.buffer,s.offset,s.typeInfo.count))}return console.error(`Unsupported return variable type ${s.typeInfo.name}`),null}execute(e){(e=e??{}).constants&&this._setOverrides(e.constants,this.context),this._execStatements(this.ast,this.context)}dispatchWorkgroups(e,r,n,s){let o=this.context.clone();(s=s??{}).constants&&this._setOverrides(s.constants,o),this._execStatements(this.ast,o);let a=o.getFunction(e);if(!a)return void console.error(`Function ${e} not found`);if(typeof r=="number")r=[r,1,1];else{if(r.length===0)return void console.error("Invalid dispatch count");r.length===1?r=[r[0],1,1]:r.length===2?r=[r[0],r[1],1]:r.length>3&&(r=[r[0],r[1],r[2]])}let i=r[0],u=r[1],l=r[2],c=this.getTypeInfo("vec3u");o.setVariable("@num_workgroups",new g(r,c));let f=this.reflection.getFunctionInfo(e);f===null&&console.error(`Function ${e} not found in reflection data`);for(let d in n)for(let p in n[d]){let b=n[d][p];o.variables.forEach(E=>{var A;let I=E.node;if(I?.attributes){let _=null,T=null;for(let R of I.attributes)R.name==="binding"?_=R.value:R.name==="group"&&(T=R.value);if(p===_&&d===T){let R=!1;for(let U of f.resources)if(U.name===E.name&&U.group===parseInt(d)&&U.binding===parseInt(p)){R=!0;break}if(R)if(b.texture!==void 0&&b.descriptor!==void 0){let U=new mr(b.texture,this.getTypeInfo(I.type),b.descriptor,(A=b.texture.view)!==null&&A!==void 0?A:null);E.value=U}else b.uniform!==void 0?E.value=new Ae(b.uniform,this.getTypeInfo(I.type)):E.value=new Ae(b,this.getTypeInfo(I.type))}}})}for(let d=0;d<l;++d)for(let p=0;p<u;++p)for(let b=0;b<i;++b)o.setVariable("@workgroup_id",new g([b,p,d],this.getTypeInfo("vec3u"))),this._dispatchWorkgroup(a,[b,p,d],o)}execStatement(e,r){if(e instanceof Do)return this.evalExpression(e.value,r);if(e instanceof No){if(e.condition){let n=this.evalExpression(e.condition,r);if(!(n instanceof v))throw new Error("Invalid break-if condition");if(!n.value)return null}return t._breakObj}if(e instanceof Go)return t._continueObj;if(e instanceof qr)this._let(e,r);else if(e instanceof Pt)this._var(e,r);else if(e instanceof Cn)this._const(e,r);else if(e instanceof hs)this._override(e,r);else if(e instanceof Jr)this._function(e,r);else{if(e instanceof Oo)return this._if(e,r);if(e instanceof Lo)return this._switch(e,r);if(e instanceof Bo)return this._for(e,r);if(e instanceof Co)return this._while(e,r);if(e instanceof Po)return this._loop(e,r);if(e instanceof ds){let n=r.clone();return n.currentFunctionName=r.currentFunctionName,this._execStatements(e.body,n)}if(e instanceof Fo)this._assign(e,r);else if(e instanceof Uo)this._increment(e,r);else{if(e instanceof jt)return null;if(e instanceof ps)this._call(e,r);else{if(e instanceof Mo||e instanceof ms)return null;console.error("Invalid statement type.",e,`Line ${e.line}`)}}}return null}evalExpression(e,r){return e instanceof _t?this._evalBinaryOp(e,r):e instanceof Fe?this._evalLiteral(e,r):e instanceof He?this._evalVariable(e,r):e instanceof gs?this._evalCall(e,r):e instanceof Ft?this._evalCreate(e,r):e instanceof Wo?this._evalConst(e,r):e instanceof $o?this._evalBitcast(e,r):e instanceof Ee?this._evalUnaryOp(e,r):(console.error("Invalid expression type",e,`Line ${e.line}`),null)}getTypeInfo(e){var r;if(e instanceof S){let s=this.reflection.getTypeInfo(e);if(s!==null)return s}let n=(r=this.typeInfo[e])!==null&&r!==void 0?r:null;return n!==null||(n=this.reflection.getTypeInfoByName(e)),n}_setOverrides(e,r){for(let n in e){let s=e[n],o=this.reflection.getOverrideInfo(n);o!==null?(o.type===null&&(o.type=this.getTypeInfo("u32")),t._numericScalarTypes.has(o.type.name)?r.setVariable(n,new v(s,o.type)):t._vectorTypes.has(o.type.name)?r.setVariable(n,new g(s,o.type)):console.error(`Invalid constant type for ${n}`)):console.error(`Override ${n} does not exist in the shader.`)}}_dispatchWorkgroup(e,r,n){let s=[1,1,1];for(let c of e.node.attributes)if(c.name==="workgroup_size"){if(c.value.length>0){let f=n.getVariableValue(c.value[0]);s[0]=f instanceof v?f.value:parseInt(c.value[0])}if(c.value.length>1){let f=n.getVariableValue(c.value[1]);s[1]=f instanceof v?f.value:parseInt(c.value[1])}if(c.value.length>2){let f=n.getVariableValue(c.value[2]);s[2]=f instanceof v?f.value:parseInt(c.value[2])}}let o=this.getTypeInfo("vec3u"),a=this.getTypeInfo("u32");n.setVariable("@workgroup_size",new g(s,o));let i=s[0],u=s[1],l=s[2];for(let c=0,f=0;c<l;++c)for(let d=0;d<u;++d)for(let p=0;p<i;++p,++f){let b=[p,d,c],E=[p+r[0]*s[0],d+r[1]*s[1],c+r[2]*s[2]];n.setVariable("@local_invocation_id",new g(b,o)),n.setVariable("@global_invocation_id",new g(E,o)),n.setVariable("@local_invocation_index",new v(f,a)),this._dispatchExec(e,n)}}_dispatchExec(e,r){for(let n of e.node.args)for(let s of n.attributes)if(s.name==="builtin"){let o=`@${s.value}`,a=r.getVariable(o);a!==void 0&&r.variables.set(n.name,a)}this._execStatements(e.node.body,r)}getVariableName(e,r){for(;e instanceof Ee;)e=e.right;return e instanceof He?e.name:(console.error("Unknown variable type",e,"Line",e.line),null)}_execStatements(e,r){for(let n of e){if(Array.isArray(n)){let o=r.clone(),a=this._execStatements(n,o);if(a)return a;continue}let s=this.execStatement(n,r);if(s)return s}return null}_call(e,r){let n=r.clone();n.currentFunctionName=e.name;let s=r.getFunction(e.name);if(s){for(let o=0;o<s.node.args.length;++o){let a=s.node.args[o],i=this.evalExpression(e.args[o],n);n.setVariable(a.name,i,a)}this._execStatements(s.node.body,n)}else e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)&&this._evalCreate(e,r)}_increment(e,r){let n=this.getVariableName(e.variable,r),s=r.getVariable(n);s?e.operator==="++"?s.value instanceof v?s.value.value++:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):e.operator==="--"?s.value instanceof v?s.value.value--:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):console.error(`Unknown increment operator ${e.operator}. Line ${e.line}`):console.error(`Variable ${n} not found. Line ${e.line}`)}_getVariableData(e,r){if(e instanceof He){let n=this.getVariableName(e,r),s=r.getVariable(n);return s===null?(console.error(`Variable ${n} not found. Line ${e.line}`),null):s.value.getSubData(this,e.postfix,r)}if(e instanceof Ee){if(e.operator==="*"){let n=this._getVariableData(e.right,r);return n instanceof Lr?n.reference.getSubData(this,e.postfix,r):(console.error(`Variable ${e.right} is not a pointer. Line ${e.line}`),null)}if(e.operator==="&"){let n=this._getVariableData(e.right,r);return new Lr(n)}}return null}_assign(e,r){let n=null,s="<var>",o=null;if(e.variable instanceof Ee){let u=this._getVariableData(e.variable,r),l=this.evalExpression(e.value,r),c=e.operator;if(c==="="){if(u instanceof v||u instanceof g||u instanceof H){if(l instanceof v||l instanceof g||l instanceof H&&u.data.length===l.data.length)return void u.data.set(l.data);console.error(`Invalid assignment. Line ${e.line}`)}else if(u instanceof Ae&&l instanceof Ae&&u.buffer.byteLength-u.offset>=l.buffer.byteLength-l.offset)return void(u.buffer.byteLength%4==0?new Uint32Array(u.buffer,u.offset,u.typeInfo.size/4).set(new Uint32Array(l.buffer,l.offset,l.typeInfo.size/4)):new Uint8Array(u.buffer,u.offset,u.typeInfo.size).set(new Uint8Array(l.buffer,l.offset,l.typeInfo.size)));return console.error(`Invalid assignment. Line ${e.line}`),null}if(c==="+=")return u instanceof v||u instanceof g||u instanceof H?l instanceof v||l instanceof g||l instanceof H?void u.data.set(l.data.map((f,d)=>u.data[d]+f)):void console.error(`Invalid assignment . Line ${e.line}`):void console.error(`Invalid assignment. Line ${e.line}`);if(c==="-=")return(u instanceof v||u instanceof g||u instanceof H)&&(l instanceof v||l instanceof g||l instanceof H)?void u.data.set(l.data.map((f,d)=>u.data[d]-f)):void console.error(`Invalid assignment. Line ${e.line}`)}if(e.variable instanceof Ee){if(e.variable.operator==="*"){s=this.getVariableName(e.variable.right,r);let u=r.getVariable(s);if(!(u&&u.value instanceof Lr))return void console.error(`Variable ${s} is not a pointer. Line ${e.line}`);n=u.value.reference;let l=e.variable.postfix;if(!l){let c=e.variable.right;for(;c instanceof Ee;){if(c.postfix){l=c.postfix;break}c=c.right}}l&&(n=n.getSubData(this,l,r))}}else{o=e.variable.postfix,s=this.getVariableName(e.variable,r);let u=r.getVariable(s);if(u===null)return void console.error(`Variable ${s} not found. Line ${e.line}`);n=u.value}if(n instanceof Lr&&(n=n.reference),n===null)return void console.error(`Variable ${s} not found. Line ${e.line}`);let a=this.evalExpression(e.value,r),i=e.operator;if(i!=="="){let u=n.getSubData(this,o,r);if(u instanceof g&&a instanceof v){let l=u.data,c=a.value;if(i==="+=")for(let f=0;f<l.length;++f)l[f]+=c;else if(i==="-=")for(let f=0;f<l.length;++f)l[f]-=c;else if(i==="*=")for(let f=0;f<l.length;++f)l[f]*=c;else if(i==="/=")for(let f=0;f<l.length;++f)l[f]/=c;else if(i==="%=")for(let f=0;f<l.length;++f)l[f]%=c;else if(i==="&=")for(let f=0;f<l.length;++f)l[f]&=c;else if(i==="|=")for(let f=0;f<l.length;++f)l[f]|=c;else if(i==="^=")for(let f=0;f<l.length;++f)l[f]^=c;else if(i==="<<=")for(let f=0;f<l.length;++f)l[f]<<=c;else if(i===">>=")for(let f=0;f<l.length;++f)l[f]>>=c;else console.error(`Invalid operator ${i}. Line ${e.line}`)}else if(u instanceof g&&a instanceof g){let l=u.data,c=a.data;if(l.length!==c.length)return void console.error(`Vector length mismatch. Line ${e.line}`);if(i==="+=")for(let f=0;f<l.length;++f)l[f]+=c[f];else if(i==="-=")for(let f=0;f<l.length;++f)l[f]-=c[f];else if(i==="*=")for(let f=0;f<l.length;++f)l[f]*=c[f];else if(i==="/=")for(let f=0;f<l.length;++f)l[f]/=c[f];else if(i==="%=")for(let f=0;f<l.length;++f)l[f]%=c[f];else if(i==="&=")for(let f=0;f<l.length;++f)l[f]&=c[f];else if(i==="|=")for(let f=0;f<l.length;++f)l[f]|=c[f];else if(i==="^=")for(let f=0;f<l.length;++f)l[f]^=c[f];else if(i==="<<=")for(let f=0;f<l.length;++f)l[f]<<=c[f];else if(i===">>=")for(let f=0;f<l.length;++f)l[f]>>=c[f];else console.error(`Invalid operator ${i}. Line ${e.line}`)}else{if(!(u instanceof v&&a instanceof v))return void console.error(`Invalid type for ${e.operator} operator. Line ${e.line}`);i==="+="?u.value+=a.value:i==="-="?u.value-=a.value:i==="*="?u.value*=a.value:i==="/="?u.value/=a.value:i==="%="?u.value%=a.value:i==="&="?u.value&=a.value:i==="|="?u.value|=a.value:i==="^="?u.value^=a.value:i==="<<="?u.value<<=a.value:i===">>="?u.value>>=a.value:console.error(`Invalid operator ${i}. Line ${e.line}`)}return void(n instanceof Ae&&n.setDataValue(this,u,o,r))}if(n instanceof Ae)n.setDataValue(this,a,o,r);else if(o){if(!(n instanceof g||n instanceof H))return void console.error(`Variable ${s} is not a vector or matrix. Line ${e.line}`);if(o instanceof Or){let u=this.evalExpression(o.index,r).value;if(n instanceof g){if(!(a instanceof v))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[u]=a.value}else{if(!(n instanceof H))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);{let l=this.evalExpression(o.index,r).value;if(l<0)return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);if(!(a instanceof g))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);{let c=n.typeInfo.getTypeName();if(c==="mat2x2"||c==="mat2x2f"||c==="mat2x2h"){if(!(l<2&&a.data.length===2))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[2*l]=a.data[0],n.data[2*l+1]=a.data[1]}else if(c==="mat2x3"||c==="mat2x3f"||c==="mat2x3h"){if(!(l<2&&a.data.length===3))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[3*l]=a.data[0],n.data[3*l+1]=a.data[1],n.data[3*l+2]=a.data[2]}else if(c==="mat2x4"||c==="mat2x4f"||c==="mat2x4h"){if(!(l<2&&a.data.length===4))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[4*l]=a.data[0],n.data[4*l+1]=a.data[1],n.data[4*l+2]=a.data[2],n.data[4*l+3]=a.data[3]}else if(c==="mat3x2"||c==="mat3x2f"||c==="mat3x2h"){if(!(l<3&&a.data.length===2))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[2*l]=a.data[0],n.data[2*l+1]=a.data[1]}else if(c==="mat3x3"||c==="mat3x3f"||c==="mat3x3h"){if(!(l<3&&a.data.length===3))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[3*l]=a.data[0],n.data[3*l+1]=a.data[1],n.data[3*l+2]=a.data[2]}else if(c==="mat3x4"||c==="mat3x4f"||c==="mat3x4h"){if(!(l<3&&a.data.length===4))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[4*l]=a.data[0],n.data[4*l+1]=a.data[1],n.data[4*l+2]=a.data[2],n.data[4*l+3]=a.data[3]}else if(c==="mat4x2"||c==="mat4x2f"||c==="mat4x2h"){if(!(l<4&&a.data.length===2))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[2*l]=a.data[0],n.data[2*l+1]=a.data[1]}else if(c==="mat4x3"||c==="mat4x3f"||c==="mat4x3h"){if(!(l<4&&a.data.length===3))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[3*l]=a.data[0],n.data[3*l+1]=a.data[1],n.data[3*l+2]=a.data[2]}else{if(c!=="mat4x4"&&c!=="mat4x4f"&&c!=="mat4x4h")return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);if(!(l<4&&a.data.length===4))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[4*l]=a.data[0],n.data[4*l+1]=a.data[1],n.data[4*l+2]=a.data[2],n.data[4*l+3]=a.data[3]}}}}}else if(o instanceof yr){let u=o.value;if(!(n instanceof g))return void console.error(`Invalid assignment to ${u}. Variable ${s} is not a vector. Line ${e.line}`);if(a instanceof v){if(u.length>1)return void console.error(`Invalid assignment to ${u} for variable ${s}. Line ${e.line}`);if(u==="x")n.data[0]=a.value;else if(u==="y"){if(n.data.length<2)return void console.error(`Invalid assignment to ${u} for variable ${s}. Line ${e.line}`);n.data[1]=a.value}else if(u==="z"){if(n.data.length<3)return void console.error(`Invalid assignment to ${u} for variable ${s}. Line ${e.line}`);n.data[2]=a.value}else if(u==="w"){if(n.data.length<4)return void console.error(`Invalid assignment to ${u} for variable ${s}. Line ${e.line}`);n.data[3]=a.value}}else{if(!(a instanceof g))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);if(u.length!==a.data.length)return void console.error(`Invalid assignment to ${u} for variable ${s}. Line ${e.line}`);for(let l=0;l<u.length;++l){let c=u[l];if(c==="x"||c==="r")n.data[0]=a.data[l];else if(c==="y"||c==="g"){if(a.data.length<2)return void console.error(`Invalid assignment to ${c} for variable ${s}. Line ${e.line}`);n.data[1]=a.data[l]}else if(c==="z"||c==="b"){if(a.data.length<3)return void console.error(`Invalid assignment to ${c} for variable ${s}. Line ${e.line}`);n.data[2]=a.data[l]}else{if(c!=="w"&&c!=="a")return void console.error(`Invalid assignment to ${c} for variable ${s}. Line ${e.line}`);if(a.data.length<4)return void console.error(`Invalid assignment to ${c} for variable ${s}. Line ${e.line}`);n.data[3]=a.data[l]}}}}}else n instanceof v&&a instanceof v?n.value=a.value:n instanceof g&&a instanceof g||n instanceof H&&a instanceof H?n.data.set(a.data):console.error(`Invalid assignment to ${s}. Line ${e.line}`)}_function(e,r){let n=new vu(e);r.functions.set(e.name,n)}_const(e,r){let n=null;e.value!==null&&(n=this.evalExpression(e.value,r)),r.createVariable(e.name,n,e)}_override(e,r){let n=r.getVariable(e.name);if(n===null||n.value===null){let s=null;e.value!==null&&(s=this.evalExpression(e.value,r)),r.createVariable(e.name,s,e)}}_let(e,r){let n=null;if(e.value!==null){if(n=this.evalExpression(e.value,r),n===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof Ee||(n=n.clone())}else{let s=e.type.name;if(t._defaultableTypes.has(s)){let o=new Ft(e.type,[]);n=this._evalCreate(o,r)}}r.createVariable(e.name,n,e)}_var(e,r){let n=null;if(e.value!==null){if(n=this.evalExpression(e.value,r),n===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof Ee||(n=n.clone())}else{if(e.type===null)return void console.error(`Variable ${e.name} has no type. Line ${e.line}`);let s=e.type.name;if(t._defaultableTypes.has(s)||e.type instanceof Kr||e.type instanceof jt||e.type instanceof w){let o=new Ft(e.type,[]);n=this._evalCreate(o,r)}}r.createVariable(e.name,n,e)}_switch(e,r){r=r.clone();let n=this.evalExpression(e.condition,r);if(!(n instanceof v))return console.error(`Invalid if condition. Line ${e.line}`),null;let s=null;for(let o of e.cases)if(o instanceof jo)for(let a of o.selectors){if(a instanceof Un){s=o;continue}let i=this.evalExpression(a,r);if(!(i instanceof v))return console.error(`Invalid case selector. Line ${e.line}`),null;if(i.value===n.value)return this._execStatements(o.body,r)}else o instanceof Xo&&(s=o);return s?this._execStatements(s.body,r):null}_if(e,r){r=r.clone();let n=this.evalExpression(e.condition,r);if(!(n instanceof v))return console.error(`Invalid if condition. Line ${e.line}`),null;if(n.value)return this._execStatements(e.body,r);for(let s of e.elseif){let o=this.evalExpression(s.condition,r);if(!(o instanceof v))return console.error(`Invalid if condition. Line ${e.line}`),null;if(o.value)return this._execStatements(s.body,r)}return e.else?this._execStatements(e.else,r):null}_getScalarValue(e){return e instanceof v?e.value:(console.error("Expected scalar value.",e),0)}_for(e,r){for(r=r.clone(),this.execStatement(e.init,r);this._getScalarValue(this.evalExpression(e.condition,r));){let n=this._execStatements(e.body,r);if(n===t._breakObj)break;if(n!==null&&n!==t._continueObj)return n;this.execStatement(e.increment,r)}return null}_loop(e,r){for(r=r.clone();;){let n=this._execStatements(e.body,r);if(n===t._breakObj)break;if(n===t._continueObj){if(e.continuing&&this._execStatements(e.continuing.body,r)===t._breakObj)break}else if(n!==null)return n}return null}_while(e,r){for(r=r.clone();this._getScalarValue(this.evalExpression(e.condition,r));){let n=this._execStatements(e.body,r);if(n===t._breakObj)break;if(n!==t._continueObj&&n!==null)return n}return null}_evalBitcast(e,r){let n=this.evalExpression(e.value,r),s=e.type;if(n instanceof v){let o=Bd(n.value,n.typeInfo.name,s.name);return new v(o,this.getTypeInfo(s))}if(n instanceof g){let o=n.typeInfo.getTypeName(),a="";if(o.endsWith("f"))a="f32";else if(o.endsWith("i"))a="i32";else if(o.endsWith("u"))a="u32";else if(o.endsWith("b"))a="bool";else{if(!o.endsWith("h"))return console.error(`Unknown vector type ${o}. Line ${e.line}`),null;a="f16"}let i=s.getTypeName(),u="";if(i.endsWith("f"))u="f32";else if(i.endsWith("i"))u="i32";else if(i.endsWith("u"))u="u32";else if(i.endsWith("b"))u="bool";else{if(!i.endsWith("h"))return console.error(`Unknown vector type ${u}. Line ${e.line}`),null;u="f16"}let l=(function(c,f,d){if(f===d)return c;let p=new Array(c.length);for(let b=0;b<c.length;b++)p[b]=Bd(c[b],f,d);return p})(Array.from(n.data),a,u);return new g(l,this.getTypeInfo(s))}return console.error(`TODO: bitcast for ${n.typeInfo.name}. Line ${e.line}`),null}_evalConst(e,r){return r.getVariableValue(e.name).clone().getSubData(this,e.postfix,r)}_evalCreate(e,r){var n;if(e instanceof Ft){if(e.type===null)return ys.void;switch(e.type.getTypeName()){case"bool":case"i32":case"u32":case"f32":case"f16":return this._callConstructorValue(e,r);case"vec2":case"vec3":case"vec4":case"vec2f":case"vec3f":case"vec4f":case"vec2h":case"vec3h":case"vec4h":case"vec2i":case"vec3i":case"vec4i":case"vec2u":case"vec3u":case"vec4u":case"vec2b":case"vec3b":case"vec4b":return this._callConstructorVec(e,r);case"mat2x2":case"mat2x2f":case"mat2x2h":case"mat2x3":case"mat2x3f":case"mat2x3h":case"mat2x4":case"mat2x4f":case"mat2x4h":case"mat3x2":case"mat3x2f":case"mat3x2h":case"mat3x3":case"mat3x3f":case"mat3x3h":case"mat3x4":case"mat3x4f":case"mat3x4h":case"mat4x2":case"mat4x2f":case"mat4x2h":case"mat4x3":case"mat4x3f":case"mat4x3h":case"mat4x4":case"mat4x4f":case"mat4x4h":return this._callConstructorMatrix(e,r)}}let s=e instanceof Ft?e.type.name:e.name,o=e instanceof Ft?this.getTypeInfo(e.type):this.getTypeInfo(e.name);if(o===null)return console.error(`Unknown type ${s}. Line ${e.line}`),null;if(o.size===0)return null;let a=new Ae(new ArrayBuffer(o.size),o,0);if(o instanceof sr){if(e.args)for(let i=0;i<e.args.length;++i){let u=o.members[i],l=e.args[i],c=this.evalExpression(l,r);a.setData(this,c,u.type,u.offset,r)}}else if(o instanceof or){let i=0;if(e.args)for(let u=0;u<e.args.length;++u){let l=e.args[u],c=this.evalExpression(l,r);o.format===null&&(((n=c.typeInfo)===null||n===void 0?void 0:n.name)==="x32"?o.format=this.getTypeInfo("i32"):o.format=c.typeInfo),a.setData(this,c,o.format,i,r),i+=o.stride}}else console.error(`Unknown type "${s}". Line ${e.line}`);return e instanceof Ft?a.getSubData(this,e.postfix,r):a}_evalLiteral(e,r){let n=this.getTypeInfo(e.type),s=n.name;return s==="x32"||s==="u32"||s==="f32"||s==="f16"||s==="i32"||s==="bool"?new v(e.scalarValue,n):s==="vec2"||s==="vec3"||s==="vec4"||s==="vec2f"||s==="vec3f"||s==="vec4f"||s==="vec2h"||s==="vec3h"||s==="vec4h"||s==="vec2i"||s==="vec3i"||s==="vec4i"||s==="vec2u"||s==="vec3u"||s==="vec4u"?this._callConstructorVec(e,r):s==="mat2x2"||s==="mat2x3"||s==="mat2x4"||s==="mat3x2"||s==="mat3x3"||s==="mat3x4"||s==="mat4x2"||s==="mat4x3"||s==="mat4x4"||s==="mat2x2f"||s==="mat2x3f"||s==="mat2x4f"||s==="mat3x2f"||s==="mat3x3f"||s==="mat3x4f"||s==="mat4x2f"||s==="mat4x3f"||s==="mat4x4f"||s==="mat2x2h"||s==="mat2x3h"||s==="mat2x4h"||s==="mat3x2h"||s==="mat3x3h"||s==="mat3x4h"||s==="mat4x2h"||s==="mat4x3h"||s==="mat4x4h"?this._callConstructorMatrix(e,r):e.value}_evalVariable(e,r){let n=r.getVariableValue(e.name);return n===null?n:n.getSubData(this,e.postfix,r)}_maxFormatTypeInfo(e){let r=e[0];if(r.name==="f32")return r;for(let n=1;n<e.length;++n){let s=t._priority.get(r.name);t._priority.get(e[n].name)<s&&(r=e[n])}return r.name==="x32"?this.getTypeInfo("i32"):r}_evalUnaryOp(e,r){let n=this.evalExpression(e.right,r);if(e.operator==="&")return new Lr(n);if(e.operator==="*")return n instanceof Lr?n.reference.getSubData(this,e.postfix,r):(console.error(`Invalid dereference. Line ${e.line}`),null);let s=n instanceof v?n.value:n instanceof g?Array.from(n.data):null;switch(e.operator){case"+":{if(L(s)){let i=s.map((u,l)=>+u);return new g(i,n.typeInfo)}let o=s,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new v(+o,a)}case"-":{if(L(s)){let i=s.map((u,l)=>-u);return new g(i,n.typeInfo)}let o=s,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new v(-o,a)}case"!":{if(L(s)){let i=s.map((u,l)=>u?0:1);return new g(i,n.typeInfo)}let o=s,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new v(o?0:1,a)}case"~":{if(L(s)){let i=s.map((u,l)=>~u);return new g(i,n.typeInfo)}let o=s,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new v(~o,a)}}return console.error(`Invalid unary operator ${e.operator}. Line ${e.line}`),null}_isMatrixType(e){return e.typeInfo.getTypeName().startsWith("mat")}_isVectorType(e){return e.typeInfo.getTypeName().startsWith("vec")}_evalBinaryOp(e,r){let n=this.evalExpression(e.left,r),s=this.evalExpression(e.right,r),o=n instanceof v?n.value:n instanceof g||n instanceof H?Array.from(n.data):n instanceof Ae?n.toArray():null,a=s instanceof v?s.value:s instanceof g||s instanceof H?Array.from(s.data):s instanceof Ae?s.toArray():null;switch(e.operator){case"+":{if(L(o)&&L(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,b)=>p+f[b]);return new g(d,n.typeInfo)}if(L(o)){let c=a,f=o.map((d,p)=>d+c);return new g(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((d,p)=>c+d);return new g(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new v(i+u,l)}case"-":{if(L(o)&&L(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,b)=>p-f[b]);return new g(d,n.typeInfo)}if(L(o)){let c=a,f=o.map((d,p)=>d-c);return new g(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((d,p)=>c-d);return new g(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new v(i-u,l)}case"*":{if(L(o)&&L(a)){let c=o,f=a;if(this._isMatrixType(n)&&this._isMatrixType(s)){let d=(function(A,I,_,T){if(nt[I.name]===void 0||nt[T.name]===void 0)return null;let R=nt[I.name][0],U=nt[I.name][1],B=nt[T.name][0];if(R!==nt[T.name][1])return null;let O=new Array(B*U);for(let P=0;P<U;P++)for(let F=0;F<B;F++){let N=0;for(let D=0;D<R;D++)N+=A[D*U+P]*_[F*R+D];O[P*B+F]=N}return O})(c,n.typeInfo,f,s.typeInfo);if(d===null)return console.error(`Matrix multiplication failed. Line ${e.line}.`),null;let p=nt[s.typeInfo.name][0],b=nt[n.typeInfo.name][1],E=this.getTypeInfo(`mat${p}x${b}f`);return new H(d,E)}if(this._isMatrixType(n)&&this._isVectorType(s)){let d=(function(p,b,E,A){if(nt[b.name]===void 0||su[A.name]===void 0)return null;let I=nt[b.name][0],_=nt[b.name][1];if(I!==E.length)return null;let T=new Array(_);for(let R=0;R<_;R++){let U=0;for(let B=0;B<I;B++)U+=p[B*_+R]*E[B];T[R]=U}return T})(c,n.typeInfo,f,s.typeInfo);return d===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new g(d,s.typeInfo)}if(this._isVectorType(n)&&this._isMatrixType(s)){let d=(function(p,b,E,A){if(su[b.name]===void 0||nt[A.name]===void 0)return null;let I=nt[A.name][0],_=nt[A.name][1];if(_!==p.length)return null;let T=[];for(let R=0;R<I;R++){let U=0;for(let B=0;B<_;B++)U+=p[B]*E[B*I+R];T[R]=U}return T})(c,n.typeInfo,f,s.typeInfo);return d===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new g(d,n.typeInfo)}{if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,b)=>p*f[b]);return new g(d,n.typeInfo)}}if(L(o)){let c=a,f=o.map((d,p)=>d*c);return this._isMatrixType(n)?new H(f,n.typeInfo):new g(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((d,p)=>c*d);return s instanceof H?new H(f,s.typeInfo):new g(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new v(i*u,l)}case"%":{if(L(o)&&L(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,b)=>p%f[b]);return new g(d,n.typeInfo)}if(L(o)){let c=a,f=o.map((d,p)=>d%c);return new g(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((d,p)=>c%d);return new g(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new v(i%u,l)}case"/":{if(L(o)&&L(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,b)=>p/f[b]);return new g(d,n.typeInfo)}if(L(o)){let c=a,f=o.map((d,p)=>d/c);return new g(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((d,p)=>c/d);return new g(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new v(i/u,l)}case"&":{if(L(o)&&L(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,b)=>p&f[b]);return new g(d,n.typeInfo)}if(L(o)){let c=a,f=o.map((d,p)=>d&c);return new g(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((d,p)=>c&d);return new g(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new v(i&u,l)}case"|":{if(L(o)&&L(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,b)=>p|f[b]);return new g(d,n.typeInfo)}if(L(o)){let c=a,f=o.map((d,p)=>d|c);return new g(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((d,p)=>c|d);return new g(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new v(i|u,l)}case"^":{if(L(o)&&L(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,b)=>p^f[b]);return new g(d,n.typeInfo)}if(L(o)){let c=a,f=o.map((d,p)=>d^c);return new g(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((d,p)=>c^d);return new g(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new v(i^u,l)}case"<<":{if(L(o)&&L(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,b)=>p<<f[b]);return new g(d,n.typeInfo)}if(L(o)){let c=a,f=o.map((d,p)=>d<<c);return new g(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((d,p)=>c<<d);return new g(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new v(i<<u,l)}case">>":{if(L(o)&&L(a)){let c=o,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let d=c.map((p,b)=>p>>f[b]);return new g(d,n.typeInfo)}if(L(o)){let c=a,f=o.map((d,p)=>d>>c);return new g(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((d,p)=>c>>d);return new g(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new v(i>>u,l)}case">":if(L(o)&&L(a)){let i=o,u=a;if(i.length!==u.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c>u[f]?1:0);return new g(l,n.typeInfo)}if(L(o)){let i=a,u=o.map((l,c)=>l>i?1:0);return new g(u,n.typeInfo)}if(L(a)){let i=o,u=a.map((l,c)=>i>l?1:0);return new g(u,s.typeInfo)}return new v(o>a?1:0,this.getTypeInfo("bool"));case"<":if(L(o)&&L(a)){let i=o,u=a;if(i.length!==u.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c<u[f]?1:0);return new g(l,n.typeInfo)}if(L(o)){let i=a,u=o.map((l,c)=>l<i?1:0);return new g(u,n.typeInfo)}if(L(a)){let i=o,u=a.map((l,c)=>i<l?1:0);return new g(u,s.typeInfo)}return new v(o<a?1:0,this.getTypeInfo("bool"));case"==":if(L(o)&&L(a)){let i=o,u=a;if(i.length!==u.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c===u[f]?1:0);return new g(l,n.typeInfo)}if(L(o)){let i=a,u=o.map((l,c)=>l===i?1:0);return new g(u,n.typeInfo)}if(L(a)){let i=o,u=a.map((l,c)=>i===l?1:0);return new g(u,s.typeInfo)}return new v(o===a?1:0,this.getTypeInfo("bool"));case"!=":if(L(o)&&L(a)){let i=o,u=a;if(i.length!==u.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c!==u[f]?1:0);return new g(l,n.typeInfo)}if(L(o)){let i=a,u=o.map((l,c)=>l!==i?1:0);return new g(u,n.typeInfo)}if(L(a)){let i=o,u=a.map((l,c)=>i!==l?1:0);return new g(u,s.typeInfo)}return new v(o!==a?1:0,this.getTypeInfo("bool"));case">=":if(L(o)&&L(a)){let i=o,u=a;if(i.length!==u.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c>=u[f]?1:0);return new g(l,n.typeInfo)}if(L(o)){let i=a,u=o.map((l,c)=>l>=i?1:0);return new g(u,n.typeInfo)}if(L(a)){let i=o,u=a.map((l,c)=>i>=l?1:0);return new g(u,s.typeInfo)}return new v(o>=a?1:0,this.getTypeInfo("bool"));case"<=":if(L(o)&&L(a)){let i=o,u=a;if(i.length!==u.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c<=u[f]?1:0);return new g(l,n.typeInfo)}if(L(o)){let i=a,u=o.map((l,c)=>l<=i?1:0);return new g(u,n.typeInfo)}if(L(a)){let i=o,u=a.map((l,c)=>i<=l?1:0);return new g(u,s.typeInfo)}return new v(o<=a?1:0,this.getTypeInfo("bool"));case"&&":if(L(o)&&L(a)){let i=o,u=a;if(i.length!==u.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c&&u[f]?1:0);return new g(l,n.typeInfo)}if(L(o)){let i=a,u=o.map((l,c)=>l&&i?1:0);return new g(u,n.typeInfo)}if(L(a)){let i=o,u=a.map((l,c)=>i&&l?1:0);return new g(u,s.typeInfo)}return new v(o&&a?1:0,this.getTypeInfo("bool"));case"||":if(L(o)&&L(a)){let i=o,u=a;if(i.length!==u.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c||u[f]?1:0);return new g(l,n.typeInfo)}if(L(o)){let i=a,u=o.map((l,c)=>l||i?1:0);return new g(u,n.typeInfo)}if(L(a)){let i=o,u=a.map((l,c)=>i||l?1:0);return new g(u,s.typeInfo)}return new v(o||a?1:0,this.getTypeInfo("bool"))}return console.error(`Unknown operator ${e.operator}. Line ${e.line}`),null}_evalCall(e,r){if(e.cachedReturnValue!==null)return e.cachedReturnValue;let n=r.clone();n.currentFunctionName=e.name;let s=r.getFunction(e.name);if(!s)return e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)?this._evalCreate(e,r):(console.error(`Unknown function "${e.name}". Line ${e.line}`),null);for(let o=0;o<s.node.args.length;++o){let a=s.node.args[o],i=this.evalExpression(e.args[o],n);n.createVariable(a.name,i,a)}return this._execStatements(s.node.body,n)}_callBuiltinFunction(e,r){switch(e.name){case"all":return this.builtins.All(e,r);case"any":return this.builtins.Any(e,r);case"select":return this.builtins.Select(e,r);case"arrayLength":return this.builtins.ArrayLength(e,r);case"abs":return this.builtins.Abs(e,r);case"acos":return this.builtins.Acos(e,r);case"acosh":return this.builtins.Acosh(e,r);case"asin":return this.builtins.Asin(e,r);case"asinh":return this.builtins.Asinh(e,r);case"atan":return this.builtins.Atan(e,r);case"atanh":return this.builtins.Atanh(e,r);case"atan2":return this.builtins.Atan2(e,r);case"ceil":return this.builtins.Ceil(e,r);case"clamp":return this.builtins.Clamp(e,r);case"cos":return this.builtins.Cos(e,r);case"cosh":return this.builtins.Cosh(e,r);case"countLeadingZeros":return this.builtins.CountLeadingZeros(e,r);case"countOneBits":return this.builtins.CountOneBits(e,r);case"countTrailingZeros":return this.builtins.CountTrailingZeros(e,r);case"cross":return this.builtins.Cross(e,r);case"degrees":return this.builtins.Degrees(e,r);case"determinant":return this.builtins.Determinant(e,r);case"distance":return this.builtins.Distance(e,r);case"dot":return this.builtins.Dot(e,r);case"dot4U8Packed":return this.builtins.Dot4U8Packed(e,r);case"dot4I8Packed":return this.builtins.Dot4I8Packed(e,r);case"exp":return this.builtins.Exp(e,r);case"exp2":return this.builtins.Exp2(e,r);case"extractBits":return this.builtins.ExtractBits(e,r);case"faceForward":return this.builtins.FaceForward(e,r);case"firstLeadingBit":return this.builtins.FirstLeadingBit(e,r);case"firstTrailingBit":return this.builtins.FirstTrailingBit(e,r);case"floor":return this.builtins.Floor(e,r);case"fma":return this.builtins.Fma(e,r);case"fract":return this.builtins.Fract(e,r);case"frexp":return this.builtins.Frexp(e,r);case"insertBits":return this.builtins.InsertBits(e,r);case"inverseSqrt":return this.builtins.InverseSqrt(e,r);case"ldexp":return this.builtins.Ldexp(e,r);case"length":return this.builtins.Length(e,r);case"log":return this.builtins.Log(e,r);case"log2":return this.builtins.Log2(e,r);case"max":return this.builtins.Max(e,r);case"min":return this.builtins.Min(e,r);case"mix":return this.builtins.Mix(e,r);case"modf":return this.builtins.Modf(e,r);case"normalize":return this.builtins.Normalize(e,r);case"pow":return this.builtins.Pow(e,r);case"quantizeToF16":return this.builtins.QuantizeToF16(e,r);case"radians":return this.builtins.Radians(e,r);case"reflect":return this.builtins.Reflect(e,r);case"refract":return this.builtins.Refract(e,r);case"reverseBits":return this.builtins.ReverseBits(e,r);case"round":return this.builtins.Round(e,r);case"saturate":return this.builtins.Saturate(e,r);case"sign":return this.builtins.Sign(e,r);case"sin":return this.builtins.Sin(e,r);case"sinh":return this.builtins.Sinh(e,r);case"smoothstep":return this.builtins.SmoothStep(e,r);case"sqrt":return this.builtins.Sqrt(e,r);case"step":return this.builtins.Step(e,r);case"tan":return this.builtins.Tan(e,r);case"tanh":return this.builtins.Tanh(e,r);case"transpose":return this.builtins.Transpose(e,r);case"trunc":return this.builtins.Trunc(e,r);case"dpdx":return this.builtins.Dpdx(e,r);case"dpdxCoarse":return this.builtins.DpdxCoarse(e,r);case"dpdxFine":return this.builtins.DpdxFine(e,r);case"dpdy":return this.builtins.Dpdy(e,r);case"dpdyCoarse":return this.builtins.DpdyCoarse(e,r);case"dpdyFine":return this.builtins.DpdyFine(e,r);case"fwidth":return this.builtins.Fwidth(e,r);case"fwidthCoarse":return this.builtins.FwidthCoarse(e,r);case"fwidthFine":return this.builtins.FwidthFine(e,r);case"textureDimensions":return this.builtins.TextureDimensions(e,r);case"textureGather":return this.builtins.TextureGather(e,r);case"textureGatherCompare":return this.builtins.TextureGatherCompare(e,r);case"textureLoad":return this.builtins.TextureLoad(e,r);case"textureNumLayers":return this.builtins.TextureNumLayers(e,r);case"textureNumLevels":return this.builtins.TextureNumLevels(e,r);case"textureNumSamples":return this.builtins.TextureNumSamples(e,r);case"textureSample":return this.builtins.TextureSample(e,r);case"textureSampleBias":return this.builtins.TextureSampleBias(e,r);case"textureSampleCompare":return this.builtins.TextureSampleCompare(e,r);case"textureSampleCompareLevel":return this.builtins.TextureSampleCompareLevel(e,r);case"textureSampleGrad":return this.builtins.TextureSampleGrad(e,r);case"textureSampleLevel":return this.builtins.TextureSampleLevel(e,r);case"textureSampleBaseClampToEdge":return this.builtins.TextureSampleBaseClampToEdge(e,r);case"textureStore":return this.builtins.TextureStore(e,r);case"atomicLoad":return this.builtins.AtomicLoad(e,r);case"atomicStore":return this.builtins.AtomicStore(e,r);case"atomicAdd":return this.builtins.AtomicAdd(e,r);case"atomicSub":return this.builtins.AtomicSub(e,r);case"atomicMax":return this.builtins.AtomicMax(e,r);case"atomicMin":return this.builtins.AtomicMin(e,r);case"atomicAnd":return this.builtins.AtomicAnd(e,r);case"atomicOr":return this.builtins.AtomicOr(e,r);case"atomicXor":return this.builtins.AtomicXor(e,r);case"atomicExchange":return this.builtins.AtomicExchange(e,r);case"atomicCompareExchangeWeak":return this.builtins.AtomicCompareExchangeWeak(e,r);case"pack4x8snorm":return this.builtins.Pack4x8snorm(e,r);case"pack4x8unorm":return this.builtins.Pack4x8unorm(e,r);case"pack4xI8":return this.builtins.Pack4xI8(e,r);case"pack4xU8":return this.builtins.Pack4xU8(e,r);case"pack4x8Clamp":return this.builtins.Pack4x8Clamp(e,r);case"pack4xU8Clamp":return this.builtins.Pack4xU8Clamp(e,r);case"pack2x16snorm":return this.builtins.Pack2x16snorm(e,r);case"pack2x16unorm":return this.builtins.Pack2x16unorm(e,r);case"pack2x16float":return this.builtins.Pack2x16float(e,r);case"unpack4x8snorm":return this.builtins.Unpack4x8snorm(e,r);case"unpack4x8unorm":return this.builtins.Unpack4x8unorm(e,r);case"unpack4xI8":return this.builtins.Unpack4xI8(e,r);case"unpack4xU8":return this.builtins.Unpack4xU8(e,r);case"unpack2x16snorm":return this.builtins.Unpack2x16snorm(e,r);case"unpack2x16unorm":return this.builtins.Unpack2x16unorm(e,r);case"unpack2x16float":return this.builtins.Unpack2x16float(e,r);case"storageBarrier":return this.builtins.StorageBarrier(e,r);case"textureBarrier":return this.builtins.TextureBarrier(e,r);case"workgroupBarrier":return this.builtins.WorkgroupBarrier(e,r);case"workgroupUniformLoad":return this.builtins.WorkgroupUniformLoad(e,r);case"subgroupAdd":return this.builtins.SubgroupAdd(e,r);case"subgroupExclusiveAdd":return this.builtins.SubgroupExclusiveAdd(e,r);case"subgroupInclusiveAdd":return this.builtins.SubgroupInclusiveAdd(e,r);case"subgroupAll":return this.builtins.SubgroupAll(e,r);case"subgroupAnd":return this.builtins.SubgroupAnd(e,r);case"subgroupAny":return this.builtins.SubgroupAny(e,r);case"subgroupBallot":return this.builtins.SubgroupBallot(e,r);case"subgroupBroadcast":return this.builtins.SubgroupBroadcast(e,r);case"subgroupBroadcastFirst":return this.builtins.SubgroupBroadcastFirst(e,r);case"subgroupElect":return this.builtins.SubgroupElect(e,r);case"subgroupMax":return this.builtins.SubgroupMax(e,r);case"subgroupMin":return this.builtins.SubgroupMin(e,r);case"subgroupMul":return this.builtins.SubgroupMul(e,r);case"subgroupExclusiveMul":return this.builtins.SubgroupExclusiveMul(e,r);case"subgroupInclusiveMul":return this.builtins.SubgroupInclusiveMul(e,r);case"subgroupOr":return this.builtins.SubgroupOr(e,r);case"subgroupShuffle":return this.builtins.SubgroupShuffle(e,r);case"subgroupShuffleDown":return this.builtins.SubgroupShuffleDown(e,r);case"subgroupShuffleUp":return this.builtins.SubgroupShuffleUp(e,r);case"subgroupShuffleXor":return this.builtins.SubgroupShuffleXor(e,r);case"subgroupXor":return this.builtins.SubgroupXor(e,r);case"quadBroadcast":return this.builtins.QuadBroadcast(e,r);case"quadSwapDiagonal":return this.builtins.QuadSwapDiagonal(e,r);case"quadSwapX":return this.builtins.QuadSwapX(e,r);case"quadSwapY":return this.builtins.QuadSwapY(e,r)}let n=r.getFunction(e.name);if(n){let s=r.clone();for(let o=0;o<n.node.args.length;++o){let a=n.node.args[o],i=this.evalExpression(e.args[o],s);s.setVariable(a.name,i,a)}return this._execStatements(n.node.body,s)}return null}_callConstructorValue(e,r){if(!e.args||e.args.length===0)return new v(0,this.getTypeInfo(e.type));let n=this.evalExpression(e.args[0],r);return n.typeInfo=this.getTypeInfo(e.type),n.getSubData(this,e.postfix,r).clone()}_callConstructorVec(e,r){let n=this.getTypeInfo(e.type),s=e.type.getTypeName(),o=su[s];if(o===void 0)return console.error(`Invalid vec constructor ${s}. Line ${e.line}`),null;let a=[];if(e instanceof Fe)if(e.isVector){let i=e.vectorValue;for(let u of i)a.push(u)}else a.push(e.scalarValue);else if(e.args)for(let i of e.args){let u=this.evalExpression(i,r);if(u instanceof g){let l=u.data;for(let c=0;c<l.length;++c){let f=l[c];a.push(f)}}else if(u instanceof v){let l=u.value;a.push(l)}}if(e.type instanceof w&&e.type.format===null&&(e.type.format=w.f32),a.length===0){let i=new Array(o).fill(0);return new g(i,n).getSubData(this,e.postfix,r)}if(a.length===1)for(;a.length<o;)a.push(a[0]);return a.length<o?(console.error(`Invalid vec constructor. Line ${e.line}`),null):new g(a.length>o?a.slice(0,o):a,n).getSubData(this,e.postfix,r)}_callConstructorMatrix(e,r){let n=this.getTypeInfo(e.type),s=e.type.getTypeName(),o=nt[s];if(o===void 0)return console.error(`Invalid matrix constructor ${s}. Line ${e.line}`),null;let a=[];if(e instanceof Fe)if(e.isVector){let i=e.vectorValue;for(let u of i)a.push(u)}else a.push(e.scalarValue);else if(e.args)for(let i of e.args){let u=this.evalExpression(i,r);u instanceof g?a.push(...u.data):u instanceof v?a.push(u.value):u instanceof H&&a.push(...u.data)}if(n instanceof gr&&n.format===null&&(n.format=this.getTypeInfo("f32")),a.length===0){let i=new Array(o[2]).fill(0);return new H(i,n).getSubData(this,e.postfix,r)}return a.length!==o[2]?(console.error(`Invalid matrix constructor. Line ${e.line}`),null):new H(a,n).getSubData(this,e.postfix,r)}};bt._numericScalarTypes=new Set(["f32","i32","u32","bool","f16"]),bt._vectorTypes=new Set(["vec2","vec3","vec4","vec2f","vec3f","vec4f","vec2i","vec3i","vec4i","vec2u","vec3u","vec4u","vec2h","vec3h","vec4h","vec2b","vec3b","vec4b"]),bt._matrixTypes=new Set(["mat2x2","mat2x3","mat2x4","mat3x2","mat3x3","mat3x4","mat4x2","mat4x3","mat4x4","mat2x2f","mat2x3f","mat2x4f","mat3x2f","mat3x3f","mat3x4f","mat4x2f","mat4x3f","mat4x4f","mat2x2h","mat2x3h","mat2x4h","mat3x2h","mat3x3h","mat3x4h","mat4x2h","mat4x3h","mat4x4h"]),bt._defaultableTypes=new Set([...bt._numericScalarTypes,...bt._vectorTypes,...bt._matrixTypes,"array"]),bt._breakObj=new Zo(new it("BREAK",null),null),bt._continueObj=new Zo(new it("CONTINUE",null),null),bt._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);var Eu=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},Au=class{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new Eu,this._exec=new bt,this._forwardTypeCount=0}parse(e){this._initialize(e),this._deferArrayCountEval.length=0;let r=[];for(;!this._isAtEnd();){let n=this._global_decl_or_directive();if(!n)break;r.push(n)}if(this._deferArrayCountEval.length>0){for(let n of this._deferArrayCountEval){let s=n.arrayType,o=n.countNode;if(o instanceof He){let a=o.name,i=this._context.constants.get(a);if(i)try{let u=i.constEvaluate(this._exec);s.count=u}catch{}}}this._deferArrayCountEval.length=0}if(this._forwardTypeCount>0)for(let n of r)n.search(s=>{s instanceof qo||s instanceof Bn?s.type=this._forwardType(s.type):s instanceof Kr?s.format=this._forwardType(s.format):s instanceof Pt||s instanceof qr||s instanceof Cn?s.type=this._forwardType(s.type):s instanceof Jr?s.returnType=this._forwardType(s.returnType):s instanceof Yo&&(s.type=this._forwardType(s.type))});return r}_forwardType(e){if(e instanceof Vo){let r=this._getType(e.name);if(r)return r}else e instanceof Bn?e.type=this._forwardType(e.type):e instanceof Kr&&(e.format=this._forwardType(e.format));return e}_initialize(e){if(e)if(typeof e=="string"){let r=new Qo(e);this._tokens=r.scanTokens()}else this._tokens=e;else this._tokens=[];this._current=0}_updateNode(e,r){return e.line=r??this._currentLine,e}_error(e,r){return new Error(`${r}. Line: ${e.line}`)}_isAtEnd(){return this._current>=this._tokens.length||this._peek().type===h.eof}_match(e){if(e instanceof y)return!!this._check(e)&&(this._advance(),!0);for(let r=0,n=e.length;r<n;++r){let s=e[r];if(this._check(s))return this._advance(),!0}return!1}_consume(e,r){if(this._check(e))return this._advance();throw this._error(this._peek(),r)}_check(e){if(this._isAtEnd())return!1;let r=this._peek();if(Array.isArray(e)){let n=r.type,s=!1;for(let o of e){if(n===o)return!0;o===h.tokens.name&&(s=!0)}if(s){let o=h.tokens.name.rule.exec(r.lexeme);if(o&&o.index===0&&o[0]===r.lexeme)return!0}return!1}if(r.type===e)return!0;if(e===h.tokens.name){let n=h.tokens.name.rule.exec(r.lexeme);return n&&n.index===0&&n[0]===r.lexeme}return!1}_advance(){var e,r;return this._currentLine=(r=(e=this._peek())===null||e===void 0?void 0:e.line)!==null&&r!==void 0?r:-1,this._isAtEnd()||this._current++,this._previous()}_peek(){return this._tokens[this._current]}_previous(){return this._tokens[this._current-1]}_global_decl_or_directive(){for(;this._match(h.tokens.semicolon)&&!this._isAtEnd(););if(this._match(h.keywords.const_assert)){let r=this._global_assert();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([r]),r}if(this._match(h.keywords.alias)){let r=this._type_alias();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([r]),r}if(this._match(h.keywords.diagnostic)){let r=this._diagnostic();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([r]),r}if(this._match(h.keywords.requires)){let r=this._requires_directive();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([r]),r}if(this._match(h.keywords.enable)){let r=this._enable_directive();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([r]),r}let e=this._attribute();if(this._check(h.keywords.var)){let r=this._global_variable_decl();return r!=null&&(r.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([r]),r}if(this._check(h.keywords.override)){let r=this._override_variable_decl();return r!=null&&(r.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([r]),r}if(this._check(h.keywords.let)){let r=this._global_let_decl();return r!=null&&(r.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([r]),r}if(this._check(h.keywords.const)){let r=this._global_const_decl();return r!=null&&(r.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([r]),r}if(this._check(h.keywords.struct)){let r=this._struct_decl();return r!=null&&(r.attributes=e),this._exec.reflection.updateAST([r]),r}if(this._check(h.keywords.fn)){let r=this._function_decl();return r!=null&&(r.attributes=e),this._exec.reflection.updateAST([r]),r}return null}_function_decl(){if(!this._match(h.keywords.fn))return null;let e=this._currentLine,r=this._consume(h.tokens.ident,"Expected function name.").toString();this._consume(h.tokens.paren_left,"Expected '(' for function arguments.");let n=[];if(!this._check(h.tokens.paren_right))do{if(this._check(h.tokens.paren_right))break;let i=this._attribute(),u=this._consume(h.tokens.name,"Expected argument name.").toString();this._consume(h.tokens.colon,"Expected ':' for argument type.");let l=this._attribute(),c=this._type_decl();c!=null&&(c.attributes=l,n.push(this._updateNode(new Yo(u,c,i))))}while(this._match(h.tokens.comma));this._consume(h.tokens.paren_right,"Expected ')' after function arguments.");let s=null;if(this._match(h.tokens.arrow)){let i=this._attribute();s=this._type_decl(),s!=null&&(s.attributes=i)}let o=this._compound_statement(),a=this._currentLine;return this._updateNode(new Jr(r,n,s,o,e,a),e)}_compound_statement(){let e=[];for(this._consume(h.tokens.brace_left,"Expected '{' for block.");!this._check(h.tokens.brace_right);){let r=this._statement();r!==null&&e.push(r)}return this._consume(h.tokens.brace_right,"Expected '}' for block."),e}_statement(){for(;this._match(h.tokens.semicolon)&&!this._isAtEnd(););if(this._check(h.tokens.attr)&&this._attribute(),this._check(h.keywords.if))return this._if_statement();if(this._check(h.keywords.switch))return this._switch_statement();if(this._check(h.keywords.loop))return this._loop_statement();if(this._check(h.keywords.for))return this._for_statement();if(this._check(h.keywords.while))return this._while_statement();if(this._check(h.keywords.continuing))return this._continuing_statement();if(this._check(h.keywords.static_assert))return this._static_assert_statement();if(this._check(h.tokens.brace_left))return this._compound_statement();let e=null;if(this._check(h.keywords.return))e=this._return_statement();else if(this._check([h.keywords.var,h.keywords.let,h.keywords.const]))e=this._variable_statement();else if(this._match(h.keywords.discard))e=this._updateNode(new yu);else if(this._match(h.keywords.break)){let r=this._updateNode(new No);if(this._currentLoop.length>0){let n=this._currentLoop[this._currentLoop.length-1];r.loopId=n.id}e=r,this._check(h.keywords.if)&&(this._advance(),r.condition=this._optional_paren_expression())}else if(this._match(h.keywords.continue)){let r=this._updateNode(new Go);if(!(this._currentLoop.length>0))throw this._error(this._peek(),"Continue statement must be inside a loop");{let n=this._currentLoop[this._currentLoop.length-1];r.loopId=n.id}e=r}else e=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement();return e!=null&&this._consume(h.tokens.semicolon,"Expected ';' after statement."),e}_static_assert_statement(){if(!this._match(h.keywords.static_assert))return null;let e=this._currentLine,r=this._optional_paren_expression();return this._updateNode(new So(r),e)}_global_assert(){let e=this._currentLine,r=this._short_circuit_or_expression();return this._updateNode(new So(r),e)}_while_statement(){if(!this._match(h.keywords.while))return null;let e=this._updateNode(new Co(null,null));return this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(h.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_continuing_statement(){let e=this._currentLoop.length>0?this._currentLoop[this._currentLoop.length-1].id:-1;if(!this._match(h.keywords.continuing))return null;let r=this._currentLine,n=this._compound_statement();return this._updateNode(new ds(n,e),r)}_for_statement(){if(!this._match(h.keywords.for))return null;this._consume(h.tokens.paren_left,"Expected '('.");let e=this._updateNode(new Bo(null,null,null,null));return this._currentLoop.push(e),e.init=this._check(h.tokens.semicolon)?null:this._for_init(),this._consume(h.tokens.semicolon,"Expected ';'."),e.condition=this._check(h.tokens.semicolon)?null:this._short_circuit_or_expression(),this._consume(h.tokens.semicolon,"Expected ';'."),e.increment=this._check(h.tokens.paren_right)?null:this._for_increment(),this._consume(h.tokens.paren_right,"Expected ')'."),this._check(h.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_for_init(){return this._variable_statement()||this._func_call_statement()||this._assignment_statement()}_for_increment(){return this._func_call_statement()||this._increment_decrement_statement()||this._assignment_statement()}_variable_statement(){if(this._check(h.keywords.var)){let e=this._variable_decl();if(e===null)throw this._error(this._peek(),"Variable declaration expected.");let r=null;return this._match(h.tokens.equal)&&(r=this._short_circuit_or_expression()),this._updateNode(new Pt(e.name,e.type,e.storage,e.access,r),e.line)}if(this._match(h.keywords.let)){let e=this._currentLine,r=this._consume(h.tokens.name,"Expected name for let.").toString(),n=null;if(this._match(h.tokens.colon)){let o=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=o)}this._consume(h.tokens.equal,"Expected '=' for let.");let s=this._short_circuit_or_expression();return this._updateNode(new qr(r,n,null,null,s),e)}if(this._match(h.keywords.const)){let e=this._currentLine,r=this._consume(h.tokens.name,"Expected name for const.").toString(),n=null;if(this._match(h.tokens.colon)){let o=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=o)}this._consume(h.tokens.equal,"Expected '=' for const.");let s=this._short_circuit_or_expression();return n===null&&s instanceof Fe&&(n=s.type),this._updateNode(new Cn(r,n,null,null,s),e)}return null}_increment_decrement_statement(){let e=this._current,r=this._unary_expression();if(r===null)return null;if(!this._check(h.increment_operators))return this._current=e,null;let n=this._consume(h.increment_operators,"Expected increment operator");return this._updateNode(new Uo(n.type===h.tokens.plus_plus?In.increment:In.decrement,r))}_assignment_statement(){let e=null,r=this._currentLine;if(this._check(h.tokens.brace_right))return null;let n=this._match(h.tokens.underscore);if(n||(e=this._unary_expression()),!n&&e===null)return null;let s=this._consume(h.assignment_operators,"Expected assignment operator."),o=this._short_circuit_or_expression();return this._updateNode(new Fo(ls.parse(s.lexeme),e,o),r)}_func_call_statement(){if(!this._check(h.tokens.ident))return null;let e=this._currentLine,r=this._current,n=this._consume(h.tokens.ident,"Expected function name."),s=this._argument_expression_list();return s===null?(this._current=r,null):this._updateNode(new ps(n.lexeme,s),e)}_loop_statement(){if(!this._match(h.keywords.loop))return null;this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Expected '{' for loop.");let e=this._updateNode(new Po([],null));this._currentLoop.push(e);let r=this._statement();for(;r!==null;){if(Array.isArray(r))for(let n of r)e.body.push(n);else e.body.push(r);if(r instanceof ds){e.continuing=r;break}r=this._statement()}return this._currentLoop.pop(),this._consume(h.tokens.brace_right,"Expected '}' for loop."),e}_switch_statement(){if(!this._match(h.keywords.switch))return null;let e=this._updateNode(new Lo(null,[]));if(this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Expected '{' for switch."),e.cases=this._switch_body(),e.cases===null||e.cases.length===0)throw this._error(this._previous(),"Expected 'case' or 'default'.");return this._consume(h.tokens.brace_right,"Expected '}' for switch."),this._currentLoop.pop(),e}_switch_body(){let e=[],r=!1;for(;this._check([h.keywords.default,h.keywords.case]);){if(this._match(h.keywords.case)){let n=this._case_selectors();for(let o of n)if(o instanceof Un){if(r)throw this._error(this._previous(),"Multiple default cases in switch statement.");r=!0;break}this._match(h.tokens.colon),this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Exected '{' for switch case.");let s=this._case_body();this._consume(h.tokens.brace_right,"Exected '}' for switch case."),e.push(this._updateNode(new jo(n,s)))}if(this._match(h.keywords.default)){if(r)throw this._error(this._previous(),"Multiple default cases in switch statement.");this._match(h.tokens.colon),this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Exected '{' for switch default.");let n=this._case_body();this._consume(h.tokens.brace_right,"Exected '}' for switch default."),e.push(this._updateNode(new Xo(n)))}}return e}_case_selectors(){let e=[];for(this._match(h.keywords.default)?e.push(this._updateNode(new Un)):e.push(this._shift_expression());this._match(h.tokens.comma);)this._match(h.keywords.default)?e.push(this._updateNode(new Un)):e.push(this._shift_expression());return e}_case_body(){if(this._match(h.keywords.fallthrough))return this._consume(h.tokens.semicolon,"Expected ';'"),[];let e=this._statement();if(e===null)return[];Array.isArray(e)||(e=[e]);let r=this._case_body();return r.length===0?e:[...e,r[0]]}_if_statement(){if(!this._match(h.keywords.if))return null;let e=this._currentLine,r=this._optional_paren_expression();this._check(h.tokens.attr)&&this._attribute();let n=this._compound_statement(),s=[];this._match_elseif()&&(this._check(h.tokens.attr)&&this._attribute(),s=this._elseif_statement(s));let o=null;return this._match(h.keywords.else)&&(this._check(h.tokens.attr)&&this._attribute(),o=this._compound_statement()),this._updateNode(new Oo(r,n,s,o),e)}_match_elseif(){return this._tokens[this._current].type===h.keywords.else&&this._tokens[this._current+1].type===h.keywords.if&&(this._advance(),this._advance(),!0)}_elseif_statement(e=[]){let r=this._optional_paren_expression(),n=this._compound_statement();return e.push(this._updateNode(new xu(r,n))),this._match_elseif()&&(this._check(h.tokens.attr)&&this._attribute(),this._elseif_statement(e)),e}_return_statement(){if(!this._match(h.keywords.return))return null;let e=this._short_circuit_or_expression();return this._updateNode(new Do(e))}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(h.tokens.or_or);)e=this._updateNode(new _t(this._previous().toString(),e,this._short_circuit_and_expr()));return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(h.tokens.and_and);)e=this._updateNode(new _t(this._previous().toString(),e,this._inclusive_or_expression()));return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(h.tokens.or);)e=this._updateNode(new _t(this._previous().toString(),e,this._exclusive_or_expression()));return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(h.tokens.xor);)e=this._updateNode(new _t(this._previous().toString(),e,this._and_expression()));return e}_and_expression(){let e=this._equality_expression();for(;this._match(h.tokens.and);)e=this._updateNode(new _t(this._previous().toString(),e,this._equality_expression()));return e}_equality_expression(){let e=this._relational_expression();return this._match([h.tokens.equal_equal,h.tokens.not_equal])?this._updateNode(new _t(this._previous().toString(),e,this._relational_expression())):e}_relational_expression(){let e=this._shift_expression();for(;this._match([h.tokens.less_than,h.tokens.greater_than,h.tokens.less_than_equal,h.tokens.greater_than_equal]);)e=this._updateNode(new _t(this._previous().toString(),e,this._shift_expression()));return e}_shift_expression(){let e=this._additive_expression();for(;this._match([h.tokens.shift_left,h.tokens.shift_right]);)e=this._updateNode(new _t(this._previous().toString(),e,this._additive_expression()));return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([h.tokens.plus,h.tokens.minus]);)e=this._updateNode(new _t(this._previous().toString(),e,this._multiplicative_expression()));return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([h.tokens.star,h.tokens.forward_slash,h.tokens.modulo]);)e=this._updateNode(new _t(this._previous().toString(),e,this._unary_expression()));return e}_unary_expression(){return this._match([h.tokens.minus,h.tokens.bang,h.tokens.tilde,h.tokens.star,h.tokens.and])?this._updateNode(new Ee(this._previous().toString(),this._unary_expression())):this._singular_expression()}_singular_expression(){let e=this._primary_expression(),r=this._postfix_expression();return r&&(e.postfix=r),e}_postfix_expression(){if(this._match(h.tokens.bracket_left)){let e=this._short_circuit_or_expression();this._consume(h.tokens.bracket_right,"Expected ']'.");let r=this._updateNode(new Or(e)),n=this._postfix_expression();return n&&(r.postfix=n),r}if(this._match(h.tokens.period)){let e=this._consume(h.tokens.name,"Expected member name."),r=this._postfix_expression(),n=this._updateNode(new yr(e.lexeme));return r&&(n.postfix=r),n}return null}_getStruct(e){var r;if(this._context.aliases.has(e)){let n=(r=this._context.aliases.get(e))===null||r===void 0?void 0:r.type;return n??null}if(this._context.structs.has(e)){let n=this._context.structs.get(e);return n??null}return null}_getType(e){let r=this._getStruct(e);if(r!==null)return r;switch(e){case"void":return S.void;case"bool":return S.bool;case"i32":return S.i32;case"u32":return S.u32;case"f32":return S.f32;case"f16":return S.f16;case"vec2f":return w.vec2f;case"vec3f":return w.vec3f;case"vec4f":return w.vec4f;case"vec2i":return w.vec2i;case"vec3i":return w.vec3i;case"vec4i":return w.vec4i;case"vec2u":return w.vec2u;case"vec3u":return w.vec3u;case"vec4u":return w.vec4u;case"vec2h":return w.vec2h;case"vec3h":return w.vec3h;case"vec4h":return w.vec4h;case"mat2x2f":return w.mat2x2f;case"mat2x3f":return w.mat2x3f;case"mat2x4f":return w.mat2x4f;case"mat3x2f":return w.mat3x2f;case"mat3x3f":return w.mat3x3f;case"mat3x4f":return w.mat3x4f;case"mat4x2f":return w.mat4x2f;case"mat4x3f":return w.mat4x3f;case"mat4x4f":return w.mat4x4f;case"mat2x2h":return w.mat2x2h;case"mat2x3h":return w.mat2x3h;case"mat2x4h":return w.mat2x4h;case"mat3x2h":return w.mat3x2h;case"mat3x3h":return w.mat3x3h;case"mat3x4h":return w.mat3x4h;case"mat4x2h":return w.mat4x2h;case"mat4x3h":return w.mat4x3h;case"mat4x4h":return w.mat4x4h;case"mat2x2i":return w.mat2x2i;case"mat2x3i":return w.mat2x3i;case"mat2x4i":return w.mat2x4i;case"mat3x2i":return w.mat3x2i;case"mat3x3i":return w.mat3x3i;case"mat3x4i":return w.mat3x4i;case"mat4x2i":return w.mat4x2i;case"mat4x3i":return w.mat4x3i;case"mat4x4i":return w.mat4x4i;case"mat2x2u":return w.mat2x2u;case"mat2x3u":return w.mat2x3u;case"mat2x4u":return w.mat2x4u;case"mat3x2u":return w.mat3x2u;case"mat3x3u":return w.mat3x3u;case"mat3x4u":return w.mat3x4u;case"mat4x2u":return w.mat4x2u;case"mat4x3u":return w.mat4x3u;case"mat4x4u":return w.mat4x4u}return null}_validateTypeRange(e,r){if(r.name==="i32"){if(e<-2147483648||e>2147483647)throw this._error(this._previous(),`Value out of range for i32: ${e}`)}else if(r.name==="u32"&&(e<0||e>4294967295))throw this._error(this._previous(),`Value out of range for u32: ${e}`)}_primary_expression(){if(this._match(h.tokens.ident)){let n=this._previous().toString();if(this._check(h.tokens.paren_left)){let s=this._argument_expression_list(),o=this._getType(n);return o!==null?this._updateNode(new Ft(o,s)):this._updateNode(new gs(n,s))}if(this._context.constants.has(n)){let s=this._context.constants.get(n);if(s)return this._updateNode(new Wo(n,s.value))}return this._updateNode(new He(n))}if(this._match(h.tokens.int_literal)){let n=this._previous().toString(),s=n.endsWith("i")||n.endsWith("i")?S.i32:n.endsWith("u")||n.endsWith("U")?S.u32:S.x32,o=parseInt(n);return this._validateTypeRange(o,s),this._updateNode(new Fe(new v(o,this._exec.getTypeInfo(s)),s))}if(this._match(h.tokens.uint_literal)){let n=parseInt(this._previous().toString());return this._validateTypeRange(n,S.u32),this._updateNode(new Fe(new v(n,this._exec.getTypeInfo(S.u32)),S.u32))}if(this._match([h.tokens.decimal_float_literal,h.tokens.hex_float_literal])){let n=this._previous().toString(),s=n.endsWith("h");s&&(n=n.substring(0,n.length-1));let o=parseFloat(n);this._validateTypeRange(o,s?S.f16:S.f32);let a=s?S.f16:S.f32;return this._updateNode(new Fe(new v(o,this._exec.getTypeInfo(a)),a))}if(this._match([h.keywords.true,h.keywords.false])){let n=this._previous().toString()===h.keywords.true.rule;return this._updateNode(new Fe(new v(n?1:0,this._exec.getTypeInfo(S.bool)),S.bool))}if(this._check(h.tokens.paren_left))return this._paren_expression();if(this._match(h.keywords.bitcast)){this._consume(h.tokens.less_than,"Expected '<'.");let n=this._type_decl();this._consume(h.tokens.greater_than,"Expected '>'.");let s=this._paren_expression();return this._updateNode(new $o(n,s))}let e=this._type_decl(),r=this._argument_expression_list();return this._updateNode(new Ft(e,r))}_argument_expression_list(){if(!this._match(h.tokens.paren_left))return null;let e=[];do{if(this._check(h.tokens.paren_right))break;let r=this._short_circuit_or_expression();e.push(r)}while(this._match(h.tokens.comma));return this._consume(h.tokens.paren_right,"Expected ')' for argument list"),e}_optional_paren_expression(){let e=this._match(h.tokens.paren_left),r=this._short_circuit_or_expression();return r.hasParen=e,e&&this._consume(h.tokens.paren_right,"Expected ')'."),r}_paren_expression(){this._consume(h.tokens.paren_left,"Expected '('.");let e=this._short_circuit_or_expression();return this._consume(h.tokens.paren_right,"Expected ')'."),e.hasParen=!0,e}_struct_decl(){if(!this._match(h.keywords.struct))return null;let e=this._currentLine,r=this._consume(h.tokens.ident,"Expected name for struct.").toString();this._consume(h.tokens.brace_left,"Expected '{' for struct body.");let n=[];for(;!this._check(h.tokens.brace_right);){let a=this._attribute(),i=this._consume(h.tokens.name,"Expected variable name.").toString();this._consume(h.tokens.colon,"Expected ':' for struct member type.");let u=this._attribute(),l=this._type_decl();l!=null&&(l.attributes=u),this._check(h.tokens.brace_right)?this._match(h.tokens.comma):this._consume(h.tokens.comma,"Expected ',' for struct member."),n.push(this._updateNode(new qo(i,l,a)))}this._consume(h.tokens.brace_right,"Expected '}' after struct body.");let s=this._currentLine,o=this._updateNode(new jt(r,n,e,s),e);return this._context.structs.set(r,o),o}_global_variable_decl(){let e=this._variable_decl();if(!e)return null;if(this._match(h.tokens.equal)){let r=this._const_expression();e.value=r}if(e.type!==null&&e.value instanceof Fe){if(e.value.type.name!=="x32"&&e.type.getTypeName()!==e.value.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${e.value.type.name} to ${e.type.name}`);e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type),e.value.type=e.type}else e.type===null&&e.value instanceof Fe&&(e.type=e.value.type.name==="x32"?S.i32:e.value.type,e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type));return e}_override_variable_decl(){let e=this._override_decl();return e&&this._match(h.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){var e;if(!this._match(h.keywords.const))return null;let r=this._consume(h.tokens.name,"Expected variable name"),n=this._currentLine,s=null;if(this._match(h.tokens.colon)){let u=this._attribute();s=this._type_decl(),s!=null&&(s.attributes=u)}let o=null;this._consume(h.tokens.equal,"const declarations require an assignment");let a=this._short_circuit_or_expression();try{let u=[S.f32],l=a.constEvaluate(this._exec,u);l instanceof v&&this._validateTypeRange(l.value,u[0]),u[0]instanceof w&&u[0].format===null&&l.typeInfo instanceof gr&&l.typeInfo.format!==null&&(l.typeInfo.format.name==="f16"?u[0].format=S.f16:l.typeInfo.format.name==="f32"?u[0].format=S.f32:l.typeInfo.format.name==="i32"?u[0].format=S.i32:l.typeInfo.format.name==="u32"?u[0].format=S.u32:l.typeInfo.format.name==="bool"?u[0].format=S.bool:console.error(`TODO: implement template format type ${l.typeInfo.format.name}`)),o=this._updateNode(new Fe(l,u[0])),this._exec.context.setVariable(r.toString(),l)}catch{o=a}if(s!==null&&o instanceof Fe){if(o.type.name!=="x32"&&s.getTypeName()!==o.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${o.type.name} to ${s.name}`);o.type=s,o.isScalar&&this._validateTypeRange(o.scalarValue,o.type)}else s===null&&o instanceof Fe&&(s=(e=o?.type)!==null&&e!==void 0?e:S.f32,s===S.x32&&(s=S.i32));let i=this._updateNode(new Cn(r.toString(),s,"","",o),n);return this._context.constants.set(i.name,i),i}_global_let_decl(){if(!this._match(h.keywords.let))return null;let e=this._currentLine,r=this._consume(h.tokens.name,"Expected variable name"),n=null;if(this._match(h.tokens.colon)){let o=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=o)}let s=null;if(this._match(h.tokens.equal)&&(s=this._const_expression()),n!==null&&s instanceof Fe){if(s.type.name!=="x32"&&n.getTypeName()!==s.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${s.type.name} to ${n.name}`);s.type=n}else n===null&&s instanceof Fe&&(n=s.type.name==="x32"?S.i32:s.type);return s instanceof Fe&&s.isScalar&&this._validateTypeRange(s.scalarValue,n),this._updateNode(new qr(r.toString(),n,"","",s),e)}_const_expression(){return this._short_circuit_or_expression()}_variable_decl(){if(!this._match(h.keywords.var))return null;let e=this._currentLine,r="",n="";this._match(h.tokens.less_than)&&(r=this._consume(h.storage_class,"Expected storage_class.").toString(),this._match(h.tokens.comma)&&(n=this._consume(h.access_mode,"Expected access_mode.").toString()),this._consume(h.tokens.greater_than,"Expected '>'."));let s=this._consume(h.tokens.name,"Expected variable name"),o=null;if(this._match(h.tokens.colon)){let a=this._attribute();o=this._type_decl(),o!=null&&(o.attributes=a)}return this._updateNode(new Pt(s.toString(),o,r,n,null),e)}_override_decl(){if(!this._match(h.keywords.override))return null;let e=this._consume(h.tokens.name,"Expected variable name"),r=null;if(this._match(h.tokens.colon)){let n=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=n)}return this._updateNode(new hs(e.toString(),r,null))}_diagnostic(){this._consume(h.tokens.paren_left,"Expected '('");let e=this._consume(h.tokens.ident,"Expected severity control name.");this._consume(h.tokens.comma,"Expected ','");let r=this._consume(h.tokens.ident,"Expected diagnostic rule name.").toString();return this._match(h.tokens.period)&&(r+=`.${this._consume(h.tokens.ident,"Expected diagnostic message.").toString()}`),this._consume(h.tokens.paren_right,"Expected ')'"),this._updateNode(new Mo(e.toString(),r))}_enable_directive(){let e=this._consume(h.tokens.ident,"identity expected.");return this._updateNode(new mu(e.toString()))}_requires_directive(){let e=[this._consume(h.tokens.ident,"identity expected.").toString()];for(;this._match(h.tokens.comma);){let r=this._consume(h.tokens.ident,"identity expected.");e.push(r.toString())}return this._updateNode(new gu(e))}_type_alias(){let e=this._consume(h.tokens.ident,"identity expected.");this._consume(h.tokens.equal,"Expected '=' for type alias.");let r=this._type_decl();if(r===null)throw this._error(this._peek(),"Expected Type for Alias.");this._context.aliases.has(r.name)&&(r=this._context.aliases.get(r.name).type);let n=this._updateNode(new ms(e.toString(),r));return this._context.aliases.set(n.name,n),n}_type_decl(){var e,r,n;if(this._check([h.tokens.ident,...h.texel_format,h.keywords.bool,h.keywords.f32,h.keywords.i32,h.keywords.u32])){let a=this._advance().toString();if(this._context.structs.has(a))return(e=this._context.structs.get(a))!==null&&e!==void 0?e:null;if(this._context.aliases.has(a))return(n=(r=this._context.aliases.get(a))===null||r===void 0?void 0:r.type)!==null&&n!==void 0?n:null;if(!this._getType(a)){let i=this._updateNode(new Vo(a));return this._forwardTypeCount++,i}return this._updateNode(new S(a))}let s=this._texture_sampler_types();if(s)return s;if(this._check(h.template_types)){let a=this._advance().toString(),i=null,u=null;return this._match(h.tokens.less_than)&&(i=this._type_decl(),u=null,this._match(h.tokens.comma)&&(u=this._consume(h.access_mode,"Expected access_mode for pointer").toString()),this._consume(h.tokens.greater_than,"Expected '>' for type.")),this._updateNode(new w(a,i,u))}if(this._match(h.keywords.ptr)){let a=this._previous().toString();this._consume(h.tokens.less_than,"Expected '<' for pointer.");let i=this._consume(h.storage_class,"Expected storage_class for pointer");this._consume(h.tokens.comma,"Expected ',' for pointer.");let u=this._type_decl(),l=null;return this._match(h.tokens.comma)&&(l=this._consume(h.access_mode,"Expected access_mode for pointer").toString()),this._consume(h.tokens.greater_than,"Expected '>' for pointer."),this._updateNode(new Bn(a,i.toString(),u,l))}let o=this._attribute();if(this._match(h.keywords.array)){let a=null,i=-1,u=this._previous(),l=null;if(this._match(h.tokens.less_than)){a=this._type_decl(),this._context.aliases.has(a.name)&&(a=this._context.aliases.get(a.name).type);let f="";if(this._match(h.tokens.comma)){l=this._shift_expression();try{f=l.constEvaluate(this._exec).toString(),l=null}catch{f="1"}}this._consume(h.tokens.greater_than,"Expected '>' for array."),i=f?parseInt(f):0}let c=this._updateNode(new Kr(u.toString(),o,a,i));return l&&this._deferArrayCountEval.push({arrayType:c,countNode:l}),c}return null}_texture_sampler_types(){if(this._match(h.sampler_type))return this._updateNode(new Yr(this._previous().toString(),null,null));if(this._match(h.depth_texture_type))return this._updateNode(new Yr(this._previous().toString(),null,null));if(this._match(h.sampled_texture_type)||this._match(h.multisampled_texture_type)){let e=this._previous();this._consume(h.tokens.less_than,"Expected '<' for sampler type.");let r=this._type_decl();return this._consume(h.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new Yr(e.toString(),r,null))}if(this._match(h.storage_texture_type)){let e=this._previous();this._consume(h.tokens.less_than,"Expected '<' for sampler type.");let r=this._consume(h.texel_format,"Invalid texel format.").toString();this._consume(h.tokens.comma,"Expected ',' after texel format.");let n=this._consume(h.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(h.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new Yr(e.toString(),r,n))}return null}_attribute(){let e=[];for(;this._match(h.tokens.attr);){let r=this._consume(h.attribute_name,"Expected attribute name"),n=this._updateNode(new Ko(r.toString(),null));if(this._match(h.tokens.paren_left)){if(n.value=this._consume(h.literal_or_ident,"Expected attribute value").toString(),this._check(h.tokens.comma)){this._advance();do{let s=this._consume(h.literal_or_ident,"Expected attribute value").toString();Array.isArray(n.value)||(n.value=[n.value]),n.value.push(s)}while(this._match(h.tokens.comma))}this._consume(h.tokens.paren_right,"Expected ')'")}e.push(n)}return e.length===0?null:e}},Ru=class extends Zr{constructor(e){super(),e!==void 0&&this.update(e)}update(e){let r=new Au().parse(e);this.updateAST(r)}};function jr(t,e){return Object.fromEntries(e.map(r=>{let n=i2(t,r,0);return[r.name,{typeDefinition:n,group:r.group,binding:r.binding,size:n.size}]}))}function Md(t,e,r){return{fields:Object.fromEntries(e.members.map(s=>[s.name,{offset:s.offset,type:Bu(t,s.type,0)}])),size:e.size,offset:r}}function n2(t){if(t.name.includes("depth"))return"depth";switch(t.format?.name){case"f32":return"float";case"i32":return"sint";case"u32":return"uint";default:throw new Error("unknown texture sample type")}}function Ud(t){return t.name.includes("2d_array")?"2d-array":t.name.includes("cube_array")?"cube-array":t.name.includes("3d")?"3d":t.name.includes("1d")?"1d":t.name.includes("cube")?"cube":"2d"}function s2(t){switch(t.access){case"read":return"read-only";case"write":return"write-only";case"read_write":return"read-write";default:throw new Error("unknonw storage texture access")}}function o2(t){return t.name.endsWith("_comparison")?"comparison":"filtering"}function a2(t,e){let{binding:r,access:n,type:s}=t;switch(t.resourceType){case Re.Uniform:return{binding:r,visibility:e,buffer:{...t.size&&{minBindingSize:t.size}}};case Re.Storage:return{binding:r,visibility:e,buffer:{type:n===""||n==="read"?"read-only-storage":"storage",...t.size&&{minBindingSize:t.size}}};case Re.Texture:{if(s.name==="texture_external")return{binding:r,visibility:e,externalTexture:{}};let o=s.name.includes("multisampled");return{binding:r,visibility:e,texture:{sampleType:n2(s),viewDimension:Ud(s),multisampled:o}}}case Re.Sampler:return{binding:r,visibility:e,sampler:{type:o2(s)}};case Re.StorageTexture:return{binding:r,visibility:e,storageTexture:{access:s2(s),format:s.format.name,viewDimension:Ud(s)}};default:throw new Error("unknown resource type")}}function ou(t,e){let r={};for(let n of t)r[n.name]={stage:e,resources:n.resources.map(s=>{let{name:o,group:a}=s;return{name:o,group:a,entry:a2(s,e)}})};return r}function Ot(t){let e=new Ru(t),r=Object.fromEntries(e.structs.map(f=>[f.name,Md(e,f,0)])),n=jr(e,e.uniforms),s=jr(e,e.immediates),o=jr(e,e.storage.filter(f=>f.resourceType===Re.Storage)),a=jr(e,e.storage.filter(f=>f.resourceType===Re.StorageTexture)),i=jr(e,e.textures.filter(f=>f.type.name!=="texture_external")),u=jr(e,e.textures.filter(f=>f.type.name==="texture_external")),l=jr(e,e.samplers),c={...ou(e.entry.vertex,GPUShaderStage.VERTEX),...ou(e.entry.fragment,GPUShaderStage.FRAGMENT),...ou(e.entry.compute,GPUShaderStage.COMPUTE)};return{externalTextures:u,immediates:s,samplers:l,structs:r,storages:o,storageTextures:a,textures:i,uniforms:n,entryPoints:c}}function au(t,e=""){if(!t)throw new Error(e)}function i2(t,e,r){switch(e.resourceType){case Re.Immediate:case Re.Uniform:case Re.Storage:case Re.StorageTexture:return Bu(t,e.type,r);default:return{size:0,type:e.type.name}}}function Bu(t,e,r){if(e.isArray){au(!e.isStruct,"struct array is invalid"),au(!e.isStruct,"template array is invalid");let n=e;return{size:n.size,elementType:Bu(t,n.format,r),numElements:n.count}}else{if(e.isStruct)return au(!e.isTemplate,"template struct is invalid"),Md(t,e,r);{let n=e,s=e.isTemplate?`${n.name}<${n.format.name}>`:e.name;return{size:e.size,type:s}}}}var u2=new Map([[Int8Array,{formats:["sint8","snorm8"],defaultForType:1}],[Uint8Array,{formats:["uint8","unorm8"],defaultForType:1}],[Int16Array,{formats:["sint16","snorm16"],defaultForType:1}],[Uint16Array,{formats:["uint16","unorm16"],defaultForType:1}],[Int32Array,{formats:["sint32","snorm32"],defaultForType:0}],[Uint32Array,{formats:["uint32","unorm32"],defaultForType:0}],[Float16Array,{formats:["float16","float16"],defaultForType:0}],[Float32Array,{formats:["float32","float32"],defaultForType:0}]]),_3=new Map([...u2.entries()].map(([t,{formats:[e,r]}])=>[[e,t],[r,t]]).flat());var Fu=t=>t.features.has("texture-formats-tier1"),Pu=t=>t.features.has("shader-f16"),Uu,On,na,Lu=0,xs=class extends Error{constructor(){super("GPU device request was invalidated"),this.name="GPUDeviceRequestInvalidatedError"}},Nd=()=>{na=void 0,On=void 0,Uu=void 0},Gd=async()=>(Uu??(Uu=navigator.gpu.requestAdapter({powerPreference:"high-performance"})),Uu),c2=async(t,e)=>{let r=[];Fu(t)&&r.push("texture-formats-tier1"),Pu(t)&&r.push("shader-f16");let n=await t.requestDevice({requiredFeatures:r});if(Lu!==e)throw n.destroy(),new xs;return na=n,n.lost.then(()=>{na===n&&Nd()}),n},Vd=async t=>{if(!On){let e=c2(t,Lu);On=e,e.catch(()=>{On===e&&(On=void 0)})}return On},Wd=()=>{Lu+=1,na?.destroy(),Nd()};function $d(t,e,r=GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT){try{return t.createTexture({size:[4,4,1],format:e,usage:r}).destroy(),!0}catch{return!1}}var l2=/const WORKGROUP_SIZE_X(\s*)=(\s*)\d+u*;/,f2=/const WORKGROUP_SIZE_Y(\s*)=(\s*)\d+u*;/,Qr=(t,{workgroupSizeX:e,workgroupSizeY:r})=>t.replace(l2,`const WORKGROUP_SIZE_X$1=$2${e}u;`).replace(f2,`const WORKGROUP_SIZE_Y$1=$2${r}u;`),d2=/texture_storage_2d<\w+,(\s*)write>/,ar=(t,e)=>t.replace(d2,`texture_storage_2d<${e},$1write>`),h2=/alias float(\s*)=(\s*)f32;/,_s=t=>t.replace(h2,"enable f16;alias float$1=$2f16;");var zd="struct Params{outWidth:u32,outHeight:u32,}@group(0)@binding(0)var inSampler:sampler;@group(0)@binding(1)var inTexture:texture_2d<f32>;@group(0)@binding(2)var outTexture:texture_storage_2d<rgba8unorm,write>;@group(0)@binding(3)var<uniform> params:Params;const WORKGROUP_SIZE_X=16u;const WORKGROUP_SIZE_Y=16u;@compute @workgroup_size(WORKGROUP_SIZE_X,WORKGROUP_SIZE_Y,1)fn main(@builtin(global_invocation_id)gid:vec3u){if gid.x>=params.outWidth||gid.y>=params.outHeight{return;}let uv=(vec2f(gid.xy)+0.5)/vec2f(f32(params.outWidth),f32(params.outHeight));let color=textureSampleLevel(inTexture,inSampler,uv,0.0);textureStore(outTexture,gid.xy,color);}";var Dr=(t,e,r,n,s,o)=>{let a=ar(zd,s),i=16,u=16,l=Math.ceil(r/i),c=Math.ceil(n/u);a=Qr(a,{workgroupSizeX:i,workgroupSizeY:u});let f=Ot(a),d=wt(f.uniforms.params),p=t.createBuffer({size:d.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});d.set({outWidth:r,outHeight:n}),t.queue.writeBuffer(p,0,d.arrayBuffer);let b=t.createShaderModule({label:`Resize shader module to ${r}x${n} with ${s} & ${o}`,code:a}),E=t.createComputePipeline({layout:"auto",label:`Resize shader pipeline to ${r}x${n} with ${s} & ${o}`,compute:{module:b}}),A=t.createTexture({label:`Resize out texture to ${r}x${n} with ${s} & ${o}`,format:s,size:[r,n],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.STORAGE_BINDING}),I=A.createView(),_=t.createSampler({magFilter:o,minFilter:o,addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}),T=null,R=null;return{render(U,B){return C(!e(),M.ContextLost),B!==R&&(T=t.createBindGroup({layout:E.getBindGroupLayout(0),entries:[{binding:0,resource:_},{binding:1,resource:B.createView()},{binding:2,resource:I},{binding:3,resource:{buffer:p}}]}),R=B),U.setPipeline(E),U.setBindGroup(0,T),U.dispatchWorkgroups(l,c),A},release(){p.destroy(),A.destroy(),T=null,R=null}}};var sa=(t,e,r,n,s,o)=>{let a=new Map,i=Dr(t,e,n,s,r,o),u=(l,c)=>{let f=`${l}x${c}`,d=a.get(f);return d||(d=t.createTexture({label:"Video Frame to Texture",format:"rgba8unorm",size:[l,c],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC|GPUTextureUsage.RENDER_ATTACHMENT}),a.set(f,d)),d};return{render:(l,c)=>{C(!e(),M.ContextLost);let f=l instanceof VideoFrame?l.displayWidth:l.width,d=l instanceof VideoFrame?l.displayHeight:l.height,p=u(f,d);return t.queue.copyExternalImageToTexture({source:l,flipY:!1},{texture:p},{width:f,height:d}),i.render(c,p)},release:()=>{for(let l of a.values())l.destroy();a.clear(),i.release()}}};var Ou="alias float=f32;struct Thresholds{background:float,foreground:float,}@group(0)@binding(0)var linearSampler:sampler;@group(0)@binding(1)var nearestSampler:sampler;@group(0)@binding(2)var<uniform> thresholds:Thresholds;@group(1)@binding(0)var bgTexture:texture_2d<f32>;@group(1)@binding(1)var personTexture:texture_2d<f32>;@group(1)@binding(2)var maskTexture:texture_2d<f32>;struct VertexOutput{@builtin(position)Position:vec4f,@location(0)fragUV:vec2f,}@vertex fn vert_main(@builtin(vertex_index)VertexIndex:u32)->VertexOutput{const pos=array(vec2(1.0,1.0),vec2(1.0,-1.0),vec2(-1.0,-1.0),vec2(1.0,1.0),vec2(-1.0,-1.0),vec2(-1.0,1.0),);const uv=array(vec2(1.0,0.0),vec2(1.0,1.0),vec2(0.0,1.0),vec2(1.0,0.0),vec2(0.0,1.0),vec2(0.0,0.0),);var output:VertexOutput;output.Position=vec4(pos[VertexIndex],0.0,1.0);output.fragUV=uv[VertexIndex];return output;}@fragment fn frag_main(@location(0)fragUV:vec2f)->@location(0)vec4f{let bg=textureSample(bgTexture,linearSampler,fragUV);let person=textureSample(personTexture,linearSampler,fragUV);let mask=textureSample(maskTexture,nearestSampler,fragUV);let alpha=smoothstep(thresholds.background,thresholds.foreground,mask.r);return mix(bg,person,alpha);}";var Hd=(t,e,r,n)=>{let s=t.getContext("webgpu");if(!s)throw Error("WebGPU not supported on the canvas.");s.configure({device:e,format:r,alphaMode:"premultiplied"});let o=Ot(Ou),a=wt(o.uniforms.thresholds),i=e.createShaderModule({label:"blender shader",code:Ou}),u=e.createRenderPipeline({label:"blender pipeline",layout:"auto",vertex:{module:i},fragment:{module:i,targets:[{format:r}]}}),l=e.createSampler({addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",magFilter:"linear",minFilter:"linear"}),c=e.createSampler({addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",magFilter:"nearest",minFilter:"nearest"}),f=e.createBuffer({size:a.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),d=B=>{a.set({background:B.backgroundThreshold,foreground:B.foregroundThreshold}),e.queue.writeBuffer(f,0,a.arrayBuffer)},p={loadOp:"load",storeOp:"store"},b={label:"blender renderPass",colorAttachments:[p]},E=e.createBindGroup({layout:u.getBindGroupLayout(0),entries:[{binding:0,resource:l},{binding:1,resource:c},{binding:2,resource:{buffer:f}}]}),A=null,I=null,_=null,T=null,R=-1,U=-1;return{render:(B,{foreground:O,background:P,mask:F},N)=>{C(!n(),M.ContextLost),p.view=s.getCurrentTexture().createView(),_===P&&T===O&&I===F||(A=e.createBindGroup({layout:u.getBindGroupLayout(1),entries:[{binding:0,resource:P.createView()},{binding:1,resource:O.createView()},{binding:2,resource:F.createView()}]}),_=P,T=O,I=F),R===N.backgroundThreshold&&U===N.foregroundThreshold||(d(N),R=N.backgroundThreshold,U=N.foregroundThreshold);let D=B.beginRenderPass(b);D.setPipeline(u),D.setBindGroup(0,E),D.setBindGroup(1,A),D.draw(6),D.end()},release:()=>{f.destroy(),R=-1,U=-1}}};var jd="struct VertexOutput{@builtin(position)position:vec4f,@location(0)uv:vec2f,};@vertex fn vs_main(@builtin(vertex_index)vertex_index:u32)->VertexOutput{var out:VertexOutput;let x=f32((vertex_index<<1u)&2u);let y=f32(vertex_index&2u);out.position=vec4f(x*2.0-1.0,1.0-y*2.0,0.0,1.0);out.uv=vec2f(x,y);return out;}@group(0)@binding(0)var u_sampler:sampler;@group(0)@binding(1)var u_frame:texture_2d<f32>;@fragment fn downsample_fs(in:VertexOutput)->@location(0)vec4f{let src_size=vec2f(textureDimensions(u_frame));let halfpixel=0.5/src_size;let uv=in.uv;var sum=textureSample(u_frame,u_sampler,uv)*4.0;sum+=textureSample(u_frame,u_sampler,uv+halfpixel);sum+=textureSample(u_frame,u_sampler,uv-halfpixel);sum+=textureSample(u_frame,u_sampler,uv+vec2f(halfpixel.x,-halfpixel.y));sum+=textureSample(u_frame,u_sampler,uv+vec2f(-halfpixel.x,halfpixel.y));return sum*0.125;}@fragment fn upsample_fs(in:VertexOutput)->@location(0)vec4f{let src_size=vec2f(textureDimensions(u_frame));let halfpixel=0.5/src_size;let uv=in.uv;let double_half=halfpixel*2.0;var sum=textureSample(u_frame,u_sampler,uv+vec2f(-double_half.x,0.0));sum+=textureSample(u_frame,u_sampler,uv+vec2f(double_half.x,0.0));sum+=textureSample(u_frame,u_sampler,uv+vec2f(0.0,double_half.y));sum+=textureSample(u_frame,u_sampler,uv+vec2f(0.0,-double_half.y));sum+=textureSample(u_frame,u_sampler,uv+vec2f(-halfpixel.x,halfpixel.y))*2.0;sum+=textureSample(u_frame,u_sampler,uv+vec2f(halfpixel.x,halfpixel.y))*2.0;sum+=textureSample(u_frame,u_sampler,uv+vec2f(halfpixel.x,-halfpixel.y))*2.0;sum+=textureSample(u_frame,u_sampler,uv+vec2f(-halfpixel.x,-halfpixel.y))*2.0;return sum*0.08333333333;}";var bs=9,p2=Ut(1,bs),Du=(t,e,r,n,s)=>{let o=t.createShaderModule({label:"dual blur compute shader",code:jd}),a=t.createRenderPipeline({label:"dual blur downsample compute pipeline",layout:"auto",vertex:{module:o,entryPoint:"vs_main"},fragment:{module:o,targets:[{format:n}],entryPoint:"downsample_fs"}}),i=t.createRenderPipeline({label:"dual blur upsample compute pipeline",layout:"auto",vertex:{module:o,entryPoint:"vs_main"},fragment:{module:o,targets:[{format:n}],entryPoint:"upsample_fs"}}),u=t.createSampler({magFilter:"linear",minFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}),l=[];for(let I=0;I<bs;I++){let _=Math.max(Math.trunc(e/2**I),1),T=Math.max(Math.trunc(r/2**I),1),R=t.createTexture({label:`dual filter blur texture level ${I}`,format:n,size:[_,T],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.RENDER_ATTACHMENT});l.push({texture:R,view:R.createView(),width:_,height:T})}let c=[],f=[];for(let I=2;I<bs;I++){let _=l[I-1],T=l[I];C(_),C(T),c.push(t.createBindGroup({layout:a.getBindGroupLayout(0),entries:[{binding:0,resource:u},{binding:1,resource:_.view}]})),f.push({label:`downsample render pass ${I}`,colorAttachments:[{loadOp:"load",storeOp:"store",view:T.view}]})}let d=[],p=[];for(let I=bs-2;I>=0;I--){let _=l[I+1],T=l[I];C(_),C(T),d.push(t.createBindGroup({layout:i.getBindGroupLayout(0),entries:[{binding:0,resource:u},{binding:1,resource:_.view}]})),p.push({label:`upsample render pass ${I}`,colorAttachments:[{loadOp:"load",storeOp:"store",view:T.view}]})}let b=null,E=null,A=null;return{render:(I,_,T)=>{if(C(!s(),M.ContextLost),!T)return _;let R=p2(T+1),U=l[1];C(U),_!==b&&(E=t.createBindGroup({layout:a.getBindGroupLayout(0),entries:[{binding:0,resource:u},{binding:1,resource:_.createView()}]}),A={label:"downsample render pass 0",colorAttachments:[{loadOp:"load",storeOp:"store",view:U.view}]},b=_),C(A);let B=I.beginRenderPass(A);B.setPipeline(a),B.setBindGroup(0,E),B.draw(3),B.end();for(let F=2;F<R;F++){let N=l[F];C(N);let D=c[F-2],j=f[F-2];C(D),C(j);let ne=I.beginRenderPass(j);ne.setPipeline(a),ne.setBindGroup(0,D),ne.draw(3),ne.end()}let O=bs-1-(R-1);for(let F=O;F<d.length;F++){let N=d[F],D=p[F];C(N),C(D);let j=I.beginRenderPass(D);j.setPipeline(i),j.setBindGroup(0,N),j.draw(3),j.end()}let P=l[0];return C(P),P.texture},release:()=>{for(let I of l)I.texture.destroy();l.length=0,c.length=0,f.length=0,d.length=0,p.length=0,b=null,E=null,A=null}}};var Xd="alias float=f32;alias texture_storage=texture_storage_2d<rgba16float,write>;struct Params{maskCombineRatio:f32,}@group(0)@binding(0)var outputTex:texture_storage;@group(0)@binding(1)var<uniform> params:Params;@group(1)@binding(0)var mask:texture_2d<f32>;@group(1)@binding(1)var prevMask:texture_2d<f32>;const WORKGROUP_SIZE_X=16u;const WORKGROUP_SIZE_Y=16u;fn smoothingMask(prevMask:texture_2d<f32>,mask:texture_2d<f32>,uv:vec2<u32>,ratio:f32)->float{let prevMaskValue=float(textureLoad(prevMask,uv,0u).r);let currMaskValue=float(textureLoad(mask,uv,0u).r);let c1=float(5.68842);let c2=float(-0.748699);let c3=float(-57.8051);let c4=float(291.309);let c5=float(-624.717);let t=currMaskValue-0.5;let x=t*t;let uncertainty=1.0-min(1.0,x*(c1+x*(c2+x*(c3+x*(c4+x*c5)))));return currMaskValue+(prevMaskValue-currMaskValue)*(uncertainty*float(ratio));}@compute @workgroup_size(WORKGROUP_SIZE_X,WORKGROUP_SIZE_Y,1)fn main(@builtin(global_invocation_id)gid:vec3u){let dims=textureDimensions(mask,0);if gid.x>=dims.x||gid.y>=dims.y{return;}let uv=vec2u(gid.xy);let alpha=smoothingMask(prevMask,mask,uv,params.maskCombineRatio);textureStore(outputTex,uv,vec4f(f32(alpha),0.0,0.0,1.0));}";var Mu=(t,e,r,n,s,o)=>{let u=Math.ceil(n/16),l=Math.ceil(s/16),c=Qr(Xd,{workgroupSizeX:16,workgroupSizeY:16});c=ar(c,r),o&&(c=_s(c));let f=t.createTexture({label:"Smoothed Mask Texture",format:r,size:[n,s],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.COPY_SRC}),d=Ot(c),p=wt(d.uniforms.params),b=t.createBuffer({size:p.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),E=O=>{p.set({maskCombineRatio:O.maskCombineRatio}),t.queue.writeBuffer(b,0,p.arrayBuffer)},A=t.createShaderModule({label:"smoothing mask compute",code:c}),I=t.createComputePipeline({label:"smoothing mask pipeline",layout:"auto",compute:{module:A}}),_=t.createBindGroup({layout:I.getBindGroupLayout(0),entries:[{binding:0,resource:f.createView()},{binding:1,resource:{buffer:b}}]}),T=null,R=null,U=null,B=-1;return{render:(O,P,F,N)=>{C(!e(),M.ContextLost),P===T&&F===R||(U=t.createBindGroup({layout:I.getBindGroupLayout(1),entries:[{binding:0,resource:P.createView()},{binding:1,resource:F.createView()}]}),T=P,R=F),B!==N.maskCombineRatio&&(E(N),B=N.maskCombineRatio);let D=O.beginComputePass({label:"smoothing mask compute pass"});return D.setPipeline(I),D.setBindGroup(0,_),D.setBindGroup(1,U),D.dispatchWorkgroups(u,l),D.end(),f},release:()=>{f.destroy(),b.destroy(),T=null,R=null,U=null,B=-1}}};var Yd=(t,e)=>{let r=new Map,n=(s,o,a,i)=>{let u=`${s}x${o}x${a}-${i}`,l=r.get(u);return l||(l=t.createTexture({size:{width:s,height:o,depthOrArrayLayers:a},format:i,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST}),r.set(u,l)),l};return{render:(s,o)=>{C(!e(),M.ContextLost);let a=n(o.width,o.height,o.depthOrArrayLayers,o.format);return s.copyTextureToTexture({texture:o},{texture:a},{width:a.width,height:a.height,depthOrArrayLayers:a.depthOrArrayLayers}),a},release:()=>{for(let s of r.values())s.destroy();r.clear()}}};var Nu="struct Params{sigmaSpace:f32,sigmaRangeLo:f32,sigmaRangeHi:f32,backgroundThreshold:f32,foregroundThreshold:f32,texelWidth:f32,texelHeight:f32,width:u32,height:u32,}@group(0)@binding(0)var inputTex:texture_2d<f32>;@group(0)@binding(1)var guideTex:texture_2d<f32>;@group(1)@binding(0)var<uniform> params:Params;@group(1)@binding(1)var outputTex:texture_storage_2d<rgba16float,write>;const MAX_RADIUS:u32=24u;const FOREGROUND_BIAS:f32=1.3;const EDGE_THRESHOLD:f32=0.08;const SPARSITY_FACTOR:f32=0.66;const TILE_W:u32=32u;const TILE_ROWS:u32=4u;var<workgroup> tile_mask:array<array<f32,80>,4>;var<workgroup> tile_guide_lum:array<array<f32,80>,4>;fn gaussian_sqr(dist2:f32,sigma2:f32)->f32{return exp(-0.5*dist2/max(sigma2,1e-6));}fn luminance(c:vec3f)->f32{return dot(c,vec3f(0.299,0.587,0.114));}@compute @workgroup_size(TILE_W,TILE_ROWS,1)fn main(@builtin(global_invocation_id)gid:vec3u,@builtin(local_invocation_id)lid:vec3u,@builtin(workgroup_id)wg_id:vec3u,){let x=i32(gid.x);let y=i32(gid.y);let lx=i32(lid.x);let ly=i32(lid.y);let radius=min(i32(floor(params.sigmaSpace+0.5)),i32(MAX_RADIUS));let w=i32(params.width);let h=i32(params.height);let tile_base_x=i32(wg_id.x)*i32(TILE_W);let shared_center=lx+radius;let gx_center=clamp(tile_base_x+lx,0,w-1);let gy=clamp(y,0,h-1);tile_mask[ly][shared_center]=textureLoad(inputTex,vec2i(gx_center,gy),0).r;tile_guide_lum[ly][shared_center]=luminance(textureLoad(guideTex,vec2i(gx_center,gy),0).rgb);if lx<radius{let halo_x=clamp(tile_base_x+lx-radius,0,w-1);tile_mask[ly][lx]=textureLoad(inputTex,vec2i(halo_x,gy),0).r;tile_guide_lum[ly][lx]=luminance(textureLoad(guideTex,vec2i(halo_x,gy),0).rgb);}if lx>=i32(TILE_W)-radius{let shared_right=shared_center+radius;let halo_x=clamp(tile_base_x+lx+radius,0,w-1);tile_mask[ly][shared_right]=textureLoad(inputTex,vec2i(halo_x,gy),0).r;tile_guide_lum[ly][shared_right]=luminance(textureLoad(guideTex,vec2i(halo_x,gy),0).rgb);}workgroupBarrier();if x>=w||y>=h{return;}let center_mask=tile_mask[ly][shared_center];let center_lum=tile_guide_lum[ly][shared_center];let t=smoothstep(params.backgroundThreshold,params.foregroundThreshold,center_mask);let sigma_color=mix(params.sigmaRangeLo,params.sigmaRangeHi,t);let sigma_texel=params.texelWidth*params.sigmaSpace;let sigma_texel2=sigma_texel*sigma_texel;let sigma_color2=sigma_color*sigma_color;let sparsity=max(1.0,sqrt(params.sigmaSpace)*SPARSITY_FACTOR);let step_i=max(1,i32(floor(sparsity+0.5)));let offset_i=select(0,step_i/2,step_i>1);let fg_w=mix(1.0,FOREGROUND_BIAS,center_mask);var acc:f32=0.0;var total_weight:f32=0.0;for(var offset=-radius;offset<=radius;offset=offset+1){let sparsitySkip=((offset+offset_i)% step_i)!=0;if sparsitySkip{continue;}let idx=shared_center+offset;let neighbor_mask=tile_mask[ly][idx];let neighbor_lum=tile_guide_lum[ly][idx];let dx=f32(offset)*params.texelWidth;let space_weight=gaussian_sqr(dx*dx,sigma_texel2);let dL=abs(neighbor_lum-center_lum);if dL>EDGE_THRESHOLD{continue;}let color_weight=gaussian_sqr(dL*dL,sigma_color2);let w_sample=space_weight*color_weight*fg_w;total_weight=total_weight+w_sample;acc=acc+w_sample*neighbor_mask;}let result=acc/max(total_weight,1e-6);textureStore(outputTex,gid.xy,vec4f(result,0.0,0.0,1.0));}";var qd="struct Params{sigmaSpace:f32,sigmaRangeLo:f32,sigmaRangeHi:f32,backgroundThreshold:f32,foregroundThreshold:f32,texelWidth:f32,texelHeight:f32,width:u32,height:u32,}@group(0)@binding(0)var inputTex:texture_2d<f32>;@group(0)@binding(1)var guideTex:texture_2d<f32>;@group(1)@binding(0)var<uniform> params:Params;@group(1)@binding(1)var outputTex:texture_storage_2d<rgba16float,write>;const MAX_RADIUS:u32=24u;const FOREGROUND_BIAS:f32=1.3;const EDGE_THRESHOLD:f32=0.08;const SPARSITY_FACTOR:f32=0.66;const TILE_COLS:u32=4u;const TILE_H:u32=32u;var<workgroup> tile_mask:array<array<f32,80>,4>;var<workgroup> tile_guide_lum:array<array<f32,80>,4>;fn gaussian_sqr(dist2:f32,sigma2:f32)->f32{return exp(-0.5*dist2/max(sigma2,1e-6));}fn luminance(c:vec3f)->f32{return dot(c,vec3f(0.299,0.587,0.114));}@compute @workgroup_size(TILE_COLS,TILE_H,1)fn main(@builtin(global_invocation_id)gid:vec3u,@builtin(local_invocation_id)lid:vec3u,@builtin(workgroup_id)wg_id:vec3u,){let x=i32(gid.x);let y=i32(gid.y);let lx=i32(lid.x);let ly=i32(lid.y);let radius=min(i32(floor(params.sigmaSpace+0.5)),i32(MAX_RADIUS));let w=i32(params.width);let h=i32(params.height);let tile_base_y=i32(wg_id.y)*i32(TILE_H);let shared_center=ly+radius;let gx=clamp(x,0,w-1);let gy_center=clamp(tile_base_y+ly,0,h-1);tile_mask[lx][shared_center]=textureLoad(inputTex,vec2i(gx,gy_center),0).r;tile_guide_lum[lx][shared_center]=luminance(textureLoad(guideTex,vec2i(gx,gy_center),0).rgb);if ly<radius{let halo_y=clamp(tile_base_y+ly-radius,0,h-1);tile_mask[lx][ly]=textureLoad(inputTex,vec2i(gx,halo_y),0).r;tile_guide_lum[lx][ly]=luminance(textureLoad(guideTex,vec2i(gx,halo_y),0).rgb);}if ly>=i32(TILE_H)-radius{let shared_bottom=shared_center+radius;let halo_y=clamp(tile_base_y+ly+radius,0,h-1);tile_mask[lx][shared_bottom]=textureLoad(inputTex,vec2i(gx,halo_y),0).r;tile_guide_lum[lx][shared_bottom]=luminance(textureLoad(guideTex,vec2i(gx,halo_y),0).rgb);}workgroupBarrier();if x>=w||y>=h{return;}let center_mask=tile_mask[lx][shared_center];let center_lum=tile_guide_lum[lx][shared_center];let t=smoothstep(params.backgroundThreshold,params.foregroundThreshold,center_mask);let sigma_color=mix(params.sigmaRangeLo,params.sigmaRangeHi,t);let sigma_texel=params.texelHeight*params.sigmaSpace;let sigma_texel2=sigma_texel*sigma_texel;let sigma_color2=sigma_color*sigma_color;let sparsity=max(1.0,sqrt(params.sigmaSpace)*SPARSITY_FACTOR);let step_i=max(1,i32(floor(sparsity+0.5)));let offset_i=select(0,step_i/2,step_i>1);let fg_w=mix(1.0,FOREGROUND_BIAS,center_mask);var acc:f32=0.0;var total_weight:f32=0.0;for(var offset=-radius;offset<=radius;offset=offset+1){let sparsitySkip=((offset+offset_i)% step_i)!=0;if sparsitySkip{continue;}let idx=shared_center+offset;let neighbor_mask=tile_mask[lx][idx];let neighbor_lum=tile_guide_lum[lx][idx];let dy=f32(offset)*params.texelHeight;let space_weight=gaussian_sqr(dy*dy,sigma_texel2);let dL=abs(neighbor_lum-center_lum);if dL>EDGE_THRESHOLD{continue;}let color_weight=gaussian_sqr(dL*dL,sigma_color2);let w_sample=space_weight*color_weight*fg_w;total_weight=total_weight+w_sample;acc=acc+w_sample*neighbor_mask;}let result=acc/max(total_weight,1e-6);textureStore(outputTex,gid.xy,vec4f(result,0.0,0.0,1.0));}";var Gu=(t,e,r,n,s,o)=>{let c=e.createTexture({label:"Joint Bilateral Filtered temporary mask texture",format:o,size:[n,s],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.STORAGE_BINDING}),f=e.createTexture({label:"Joint Bilateral Filtered Mask Texture",format:o,size:[n,s],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.STORAGE_BINDING}),d=Ot(Nu),p=wt(d.uniforms.params),b=e.createBuffer({size:p.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),E=n/t.width,A=1/n,I=1/s;p.set({width:n,height:s,texelWidth:A,texelHeight:I});let _=Ye=>{p.set({...Ye,sigmaSpace:Ye.sigmaSpace*E}),e.queue.writeBuffer(b,0,p.arrayBuffer)},T=ar(Nu,o),R=ar(qd,o),U=e.createShaderModule({label:"joint bilateral filter horizontal compute",code:T}),B=e.createShaderModule({label:"joint bilateral filter vertical compute",code:R}),O=e.createComputePipeline({label:"joint bilateral filter horizontal pipeline",layout:"auto",compute:{module:U}}),P=e.createComputePipeline({label:"joint bilateral filter vertical pipeline",layout:"auto",compute:{module:B}}),F=e.createBindGroup({layout:O.getBindGroupLayout(1),entries:[{binding:0,resource:{buffer:b}},{binding:1,resource:c.createView()}]}),N=e.createBindGroup({layout:P.getBindGroupLayout(1),entries:[{binding:0,resource:{buffer:b}},{binding:1,resource:f.createView()}]}),D=(Ye,Q,ze,Pe,As,ep,tp)=>{let Mn=Q.beginComputePass({label:Ye});Mn.setPipeline(ze),Mn.setBindGroup(0,Pe),Mn.setBindGroup(1,As),Mn.dispatchWorkgroups(ep,tp),Mn.end()},j=Math.ceil(n/32),ne=Math.ceil(s/4),Se=Math.ceil(n/4),We=Math.ceil(s/32),me=null,st=null,Xe=null,Kt=null,$e={sigmaSpace:-1,sigmaRangeLo:-1,sigmaRangeHi:-1,backgroundThreshold:-1,foregroundThreshold:-1};return{render:(Ye,Q,ze,Pe)=>(C(!r(),M.ContextLost),$e.sigmaSpace===Pe.sigmaSpace&&$e.sigmaRangeLo===Pe.sigmaRangeLo&&$e.sigmaRangeHi===Pe.sigmaRangeHi&&$e.backgroundThreshold===Pe.backgroundThreshold&&$e.foregroundThreshold===Pe.foregroundThreshold||(_(Pe),$e.sigmaSpace=Pe.sigmaSpace,$e.sigmaRangeLo=Pe.sigmaRangeLo,$e.sigmaRangeHi=Pe.sigmaRangeHi,$e.backgroundThreshold=Pe.backgroundThreshold,$e.foregroundThreshold=Pe.foregroundThreshold),(me!==Q||st!==ze)&&(Xe=e.createBindGroup({layout:O.getBindGroupLayout(0),entries:[{binding:0,resource:Q.createView()},{binding:1,resource:ze.createView()}]}),me=Q),D("Joint Bilateral Filter Horizontal pass",Ye,O,Xe,F,j,ne),st!==ze&&(Kt=e.createBindGroup({layout:P.getBindGroupLayout(0),entries:[{binding:0,resource:c.createView()},{binding:1,resource:ze.createView()}]}),st=ze),D("Joint Bilateral Filter Vertical pass",Ye,P,Kt,N,Se,We),f),release:()=>{c.destroy(),f.destroy(),b.destroy(),me=null,st=null,Xe=null,Kt=null}}};var Kd="alias float=f32;struct TentParams{radius:u32,width:u32,height:u32,}@group(0)@binding(0)var inputTex:texture_2d<f32>;@group(0)@binding(1)var outputTex:texture_storage_2d<rgba16float,write>;@group(0)@binding(2)var<uniform> params:TentParams;const WORKGROUP_SIZE_X=16u;const WORKGROUP_SIZE_Y=16u;@compute @workgroup_size(WORKGROUP_SIZE_X,WORKGROUP_SIZE_Y,1)fn main(@builtin(global_invocation_id)gid:vec3u){if gid.x>=params.width||gid.y>=params.height{return;}let r=i32(params.radius);if r==0{let m=textureLoad(inputTex,gid.xy,0).r;textureStore(outputTex,gid.xy,vec4f(m,0.0,0.0,1.0));return;}var sumW:float=0.0;var acc:float=0.0;for(var i=-r;i<=r;i=i+1){let w=float(r+1-abs(i));let sx=clamp(i32(gid.x)+i,0,i32(params.width)-1);let m=textureLoad(inputTex,vec2u(u32(sx),gid.y),0).r;acc+=w*float(m);sumW+=w;}let result=acc/max(sumW,1e-6);textureStore(outputTex,gid.xy,vec4f(f32(result),0.0,0.0,1.0));}";var Zd="alias float=f32;struct TentParams{radius:u32,width:u32,height:u32,}@group(0)@binding(0)var inputTex:texture_2d<f32>;@group(0)@binding(1)var outputTex:texture_storage_2d<rgba16float,write>;@group(0)@binding(2)var<uniform> params:TentParams;const WORKGROUP_SIZE_X=16u;const WORKGROUP_SIZE_Y=16u;@compute @workgroup_size(WORKGROUP_SIZE_X,WORKGROUP_SIZE_Y,1)fn main(@builtin(global_invocation_id)gid:vec3u){if gid.x>=params.width||gid.y>=params.height{return;}let r=i32(params.radius);if r==0{let m=textureLoad(inputTex,gid.xy,0).r;textureStore(outputTex,gid.xy,vec4f(m,0.0,0.0,1.0));return;}var sumW:float=0.0;var acc:float=0.0;for(var i=-r;i<=r;i=i+1){let w=float(r+1-abs(i));let sy=clamp(i32(gid.y)+i,0,i32(params.height)-1);let m=textureLoad(inputTex,vec2u(gid.x,u32(sy)),0).r;acc+=w*float(m);sumW+=w;}let result=acc/max(sumW,1e-6);textureStore(outputTex,gid.xy,vec4f(f32(result),0.0,0.0,1.0));}";var m2=Ut(0,9),Jd=(t,e,r,n,s,o)=>{let u=Math.ceil(r/16),l=Math.ceil(n/16),c=ar(Kd,s);c=Qr(c,{workgroupSizeX:16,workgroupSizeY:16});let f=ar(Zd,s);f=Qr(f,{workgroupSizeX:16,workgroupSizeY:16}),o&&(c=_s(c),f=_s(f));let d=Ot(c),p=wt(d.uniforms.params),b=t.createBuffer({size:p.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});p.set({width:r,height:n});let E=D=>{p.set({radius:D}),t.queue.writeBuffer(b,0,p.arrayBuffer)},A=t.createTexture({label:`Tent Blur intermediate texture ${r}x${n} ${s}`,format:s,size:[r,n],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.STORAGE_BINDING}),I=A.createView(),_=t.createTexture({label:`Tent Blur output texture ${r}x${n} ${s}`,format:s,size:[r,n],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.STORAGE_BINDING}),T=t.createShaderModule({label:`Tent Blur horizontal compute ${r}x${n} ${s}`,code:c}),R=t.createShaderModule({label:`Tent Blur vertical compute ${r}x${n} ${s}`,code:f}),U=t.createComputePipeline({label:`Tent Blur horizontal pipeline ${r}x${n} ${s}`,layout:"auto",compute:{module:T}}),B=t.createComputePipeline({label:`Tent Blur vertical pipeline ${r}x${n} ${s}`,layout:"auto",compute:{module:R}}),O=t.createBindGroup({layout:B.getBindGroupLayout(0),entries:[{binding:0,resource:I},{binding:1,resource:_.createView()},{binding:2,resource:{buffer:b}}]}),P=null,F=null,N=-1;return{render(D,j,ne){C(!e(),M.ContextLost);let Se=m2(ne.edgeBlurAmount);N!==Se&&(E(Se),N=Se),P!==j&&(F=t.createBindGroup({layout:U.getBindGroupLayout(0),entries:[{binding:0,resource:j.createView()},{binding:1,resource:I},{binding:2,resource:{buffer:b}}]}),P=j);let We=D.beginComputePass({label:"Tent Blur H pass"});We.setPipeline(U),We.setBindGroup(0,F),We.dispatchWorkgroups(u,l),We.end();let me=D.beginComputePass({label:"Tent Blur V pass"});return me.setPipeline(B),me.setBindGroup(0,O),me.dispatchWorkgroups(u,l),me.end(),_},release(){A.destroy(),_.destroy(),b.destroy(),P=null,F=null,N=-1}}};var Vu="alias float=f32;struct StaticParams{background:float,foreground:float,lightWrap:float,lightWrapTightness:float,lightWrapEdgeBand:float,width:u32,height:u32,}struct DynamicParams{time:float,parity:float,}@group(0)@binding(0)var linearSampler:sampler;@group(0)@binding(1)var nearestSampler:sampler;@group(0)@binding(2)var<uniform> sparams:StaticParams;@group(0)@binding(3)var<uniform> dparams:DynamicParams;@group(1)@binding(0)var foregroundTexture:texture_2d<f32>;@group(1)@binding(1)var backgroundTexture:texture_2d<f32>;@group(1)@binding(2)var maskTexture:texture_2d<f32>;@group(1)@binding(3)var blurredBackgroundTexture:texture_2d<f32>;struct VertexOutput{@builtin(position)Position:vec4f,@location(0)fragUV:vec2f,}fn rgb2yuv(rgb:vec3f)->vec3f{let Y=dot(rgb,vec3f(0.299,0.587,0.114));let U=dot(rgb,vec3f(-0.168736,-0.331264,0.5));let V=dot(rgb,vec3f(0.5,-0.418688,-0.081312));return vec3f(Y,U,V);}fn yuv2rgb(yuv:vec3f)->vec3f{let Y=yuv.x;let U=yuv.y;let V=yuv.z;return vec3f(Y+1.402*V,Y-0.344136*U-0.714136*V,Y+1.772*U);}fn hash12(p:vec2f)->f32{let p3=fract(vec3f(p.xyx)*0.1031);let p4=p3+dot(p3,p3.yzx+33.33);return fract((p4.x+p4.y)*p4.z);}const NOISE_LUMA=2.0f/255.0f;@vertex fn vert_main(@builtin(vertex_index)VertexIndex:u32)->VertexOutput{const pos=array(vec2(1.0,1.0),vec2(1.0,-1.0),vec2(-1.0,-1.0),vec2(1.0,1.0),vec2(-1.0,-1.0),vec2(-1.0,1.0),);const uv=array(vec2(1.0,0.0),vec2(1.0,1.0),vec2(0.0,1.0),vec2(1.0,0.0),vec2(0.0,1.0),vec2(0.0,0.0),);var output:VertexOutput;output.Position=vec4(pos[VertexIndex],0.0,1.0);output.fragUV=uv[VertexIndex];return output;}@fragment fn frag_main(@location(0)fragUV:vec2f)->@location(0)vec4f{let bg=textureSample(backgroundTexture,linearSampler,fragUV).rgb;let fg=textureSample(foregroundTexture,linearSampler,fragUV).rgb;let mask=textureSample(maskTexture,nearestSampler,fragUV).r;let blurBg=textureSample(blurredBackgroundTexture,linearSampler,fragUV).rgb;let bgT=f32(sparams.background);let fgT=f32(sparams.foreground);let lightWrap=f32(sparams.lightWrap);let edgeBand=f32(sparams.lightWrapEdgeBand);let tightness=f32(sparams.lightWrapTightness);let maskFg=smoothstep(bgT,fgT,mask);let edgeBg=smoothstep(bgT,bgT+edgeBand,mask);let edgeFg=1.0-smoothstep(fgT-edgeBand,fgT,mask);let edgeBgTight=pow(edgeBg,tightness);let edgeFgTight=pow(edgeFg,tightness);let maskBg=1.0-maskFg;let pixelCoord=floor(fragUV*vec2f(f32(sparams.width),f32(sparams.height)));let noiseY=(hash12(pixelCoord+vec2f(f32(dparams.time),0.0))-0.5)*NOISE_LUMA*f32(dparams.parity);let noiseWeight=clamp(maskBg+edgeBgTight*maskFg,0.0,1.0);var bgYUV=rgb2yuv(bg);bgYUV.x=clamp(bgYUV.x+noiseY*f32(noiseWeight),0.0,1.0);let bgNoisy=yuv2rgb(bgYUV);let bgSmooth=mix(bgNoisy,blurBg,lightWrap*edgeBgTight);let wrapColor=mix(fg,blurBg,lightWrap);let fgSmooth=mix(fg,wrapColor,edgeFgTight);let composite=mix(bgSmooth,fgSmooth,maskFg);return vec4f(composite,1.0);}";var Qd=(t,e,r,n)=>{let s=t.getContext("webgpu");if(!s)throw Error("WebGPU not supported on the canvas.");s.configure({device:e,format:r,alphaMode:"premultiplied"});let o=Ot(Vu),a=wt(o.uniforms.sparams),i=wt(o.uniforms.dparams),u=e.createShaderModule({label:"replace shader",code:Vu}),l=e.createRenderPipeline({label:"replace pipeline",layout:"auto",vertex:{module:u},fragment:{module:u,targets:[{format:r}]}}),c=e.createSampler({addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",magFilter:"linear",minFilter:"linear"}),f=e.createSampler({addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",magFilter:"nearest",minFilter:"nearest"}),d=e.createBuffer({size:a.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),p=e.createBuffer({size:i.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),b=me=>{a.set({background:me.backgroundThreshold,foreground:me.foregroundThreshold,lightWrap:me.lightWrapIntensity,lightWrapTightness:me.lightWrapTightness,lightWrapEdgeBand:me.lightWrapEdgeBand,width:me.width,height:me.height}),e.queue.writeBuffer(d,0,a.arrayBuffer)},E=({time:me,parity:st})=>{i.set({time:me,parity:st}),e.queue.writeBuffer(p,0,i.arrayBuffer)},A={loadOp:"load",storeOp:"store"},I={label:"replace renderPass",colorAttachments:[A]},_=e.createBindGroup({layout:l.getBindGroupLayout(0),entries:[{binding:0,resource:c},{binding:1,resource:f},{binding:2,resource:{buffer:d}},{binding:3,resource:{buffer:p}}]}),T=null,R=null,U=null,B=null,O=null,P=-1,F=-1,N=-1,D=-1,j=-1,ne=-1,Se=-1,We=-1;return{render:(me,{foreground:st,background:Xe,blurBackground:Kt,mask:$e,timestamp:Ye},Q)=>{C(!n(),M.ContextLost),A.view=s.getCurrentTexture().createView(),U===Xe&&B===st&&R===$e&&O===Kt||(T=e.createBindGroup({layout:l.getBindGroupLayout(1),entries:[{binding:0,resource:st.createView()},{binding:1,resource:Xe.createView()},{binding:2,resource:$e.createView()},{binding:3,resource:Kt.createView()}]}),B=st,U=Xe,R=$e,O=Kt),P===Q.backgroundThreshold&&F===Q.foregroundThreshold&&N===Q.lightWrapIntensity&&D===Q.lightWrapTightness&&j===Q.lightWrapEdgeBand&&ne===Xe.width&&Se===Xe.height||(b({backgroundThreshold:Q.backgroundThreshold,foregroundThreshold:Q.foregroundThreshold,lightWrapIntensity:Q.lightWrapIntensity,lightWrapTightness:Q.lightWrapTightness,lightWrapEdgeBand:Q.lightWrapEdgeBand,width:Xe.width,height:Xe.height}),P=Q.backgroundThreshold,F=Q.foregroundThreshold,N=Q.lightWrapIntensity,D=Q.lightWrapTightness,j=Q.lightWrapEdgeBand,ne=Xe.width,Se=Xe.height),We=-We,E({time:Ye*1e-6%1024,parity:We});let ze=me.beginRenderPass(I);ze.setPipeline(l),ze.setBindGroup(0,_),ze.setBindGroup(1,T),ze.draw(6),ze.end()},release:()=>{d.destroy(),p.destroy(),P=-1,F=-1,N=-1,D=-1,j=-1,ne=-1,Se=-1,O=null,U=null,B=null,R=null,T=null}}};var eh=(t,e,r=new OffscreenCanvas(Pr,Fr))=>{let n=Math.trunc(r.width/2),s=Math.trunc(r.height/2),o=Math.trunc(r.width/4),a=Math.trunc(r.height/4),i="rgba8unorm",u={edgeBlurRenderer:()=>(C(c.device),Jd(c.device,E,r.width,r.height,c.maskFormat,c.supportF16)),videoFrameRenderer:()=>(C(c.device),sa(c.device,E,i,r.width,r.height,"linear")),maskRenderer:()=>(C(c.device),sa(c.device,E,c.maskFormat,r.width,r.height,"nearest")),maskDownsampler2:()=>(C(c.device),Dr(c.device,E,n,s,c.maskFormat,"nearest")),maskDownsampler4:()=>(C(c.device),Dr(c.device,E,o,a,c.maskFormat,"nearest")),maskUpsampler:()=>(C(c.device),Dr(c.device,E,r.width,r.height,c.maskFormat,"nearest")),frameDownsampler2:()=>(C(c.device),Dr(c.device,E,n,s,i,"linear")),frameDownsampler4:()=>(C(c.device),Dr(c.device,E,o,a,i,"linear")),backgroundImageRenderer:()=>(C(c.device),sa(c.device,E,i,r.width,r.height,"linear")),blendRenderer:()=>(C(c.device),Hd(r,c.device,c.presentationFormat,E)),blurRenderer:()=>(C(c.device),Du(c.device,r.width,r.height,i,E)),jointBilateralFilterRenderer2:()=>(C(c.device),Gu(r,c.device,E,n,s,c.maskFormat)),jointBilateralFilterRenderer4:()=>(C(c.device),Gu(r,c.device,E,o,a,c.maskFormat)),maskSmoothingRenderer2:()=>(C(c.device),Mu(c.device,E,c.maskFormat,n,s,c.supportF16)),maskSmoothingRenderer4:()=>(C(c.device),Mu(c.device,E,c.maskFormat,o,a,c.supportF16)),prevMaskRenderer:()=>(C(c.device),Yd(c.device,E)),strongMaskBlurRenderer:()=>(C(c.device),Du(c.device,r.width,r.height,c.maskFormat,E)),replaceRenderer:()=>(C(c.device),Qd(r,c.device,c.presentationFormat,E)),release:A=>()=>{for(let I of Object.keys(A))I!=="release"&&A[I]?.release()}},l=Rn(u),c={canvas:r,presentationFormat:"rgba8unorm",supportR16FloatTextureStorage:!1,maskFormat:"rgba16float",supportF16:!1,backend:"webgpu",deviceLost:!1,get videoFrameRenderer(){return l.videoFrameRenderer},get edgeBlurRenderer(){return l.edgeBlurRenderer},get maskRenderer(){return l.maskRenderer},get maskDownsampler2(){return l.maskDownsampler2},get maskDownsampler4(){return l.maskDownsampler4},get maskUpsampler(){return l.maskUpsampler},get frameDownsampler2(){return l.frameDownsampler2},get frameDownsampler4(){return l.frameDownsampler4},get blendRenderer(){return l.blendRenderer},get blurRenderer(){return l.blurRenderer},get backgroundImageRenderer(){return l.backgroundImageRenderer},get maskSmoothingRenderer2(){return l.maskSmoothingRenderer2},get maskSmoothingRenderer4(){return l.maskSmoothingRenderer4},get prevMaskRenderer(){return l.prevMaskRenderer},get jointBilateralFilterRenderer2(){return l.jointBilateralFilterRenderer2},get jointBilateralFilterRenderer4(){return l.jointBilateralFilterRenderer4},get strongMaskBlurRenderer(){return l.strongMaskBlurRenderer},get replaceRenderer(){return l.replaceRenderer}},f=Eo(c),d=async()=>{if(!navigator.gpu)throw Error("WebGPU not supported.");c.presentationFormat=navigator.gpu.getPreferredCanvasFormat(),c.device=await Vd(t),c.supportR16FloatTextureStorage=Fu(t)&&$d(c.device,"r16float"),c.supportR16FloatTextureStorage&&(c.maskFormat="r16float"),c.supportF16=Pu(t),c.device.lost.then(A=>{A.reason!=="destroyed"&&(c.deviceLost=!0,e.contextLost(A.message),e.contextRestored(A.message))})},p=(A,I,_)=>{_&&f(_),C(c.device);let T=c.device.createCommandEncoder({label:"Renderer Encoder"}),R=T.beginComputePass({label:"frame upload pass"}),U=c.videoFrameRenderer.render(I,R),B=c.maskRenderer.render(A,R);R.end();let O,P;if(_.downSampleFactor===4){let F=T.beginComputePass({label:"downsample pass"}),N=c.maskDownsampler4.render(F,B),D=c.frameDownsampler4.render(F,U);F.end();let j=c.jointBilateralFilterRenderer4.render(T,N,D,_);O=c.maskSmoothingRenderer4.render(T,j,c.prevMask4??j,_);let ne=T.beginComputePass({label:"upsample pass"}),Se=c.maskUpsampler.render(ne,O);ne.end(),P=c.strongMaskBlurRenderer.render(T,Se,ko)}else{let F=T.beginComputePass({label:"downsample pass"}),N=c.maskDownsampler2.render(F,B),D=c.frameDownsampler2.render(F,U);F.end();let j=c.jointBilateralFilterRenderer2.render(T,N,D,_);O=c.maskSmoothingRenderer2.render(T,j,c.prevMask2??j,_);let ne=T.beginComputePass({label:"upsample pass"}),Se=c.maskUpsampler.render(ne,O);ne.end(),P=c.edgeBlurRenderer.render(T,Se,_)}if(_.effects==="blur"){let F=c.blurRenderer.render(T,U,_.backgroundBlurAmount);c.blendRenderer.render(T,{foreground:U,background:F,mask:P},_)}else if(_.effects==="overlay"&&_.backgroundImage){let F=T.beginComputePass({label:"background image upload pass"}),N=c.backgroundImageRenderer.render(_.backgroundImage,F);F.end();let D=c.blurRenderer.render(T,N,_.backgroundBlurAmount);c.replaceRenderer.render(T,{foreground:U,background:N,mask:P,blurBackground:D,timestamp:I.timestamp},_)}_.downSampleFactor===4?c.prevMask4=c.prevMaskRenderer.render(T,O):c.prevMask2=c.prevMaskRenderer.render(T,O),c.device.queue.submit([T.finish()])},b=()=>{l.release(),c.device=void 0,c.deviceLost=!1,c.prevMask2=void 0,c.prevMask4=void 0,c.presentationFormat="rgba8unorm",c.supportR16FloatTextureStorage=!1,c.maskFormat="rgba16float",l=Rn(u)},E=()=>c.deviceLost;return{init:d,render:p,release:b,isContextLost:E}};var Z={projection:(t,e,r=-1)=>[2/t,0,0,0,2/e*r,0,-1,1*-r,1],translation:(t,e)=>[1,0,0,0,1,0,t,e,1],rotation:t=>{let e=Math.cos(t),r=Math.sin(t);return[e,-r,0,r,e,0,0,0,1]},scaling:(t,e)=>[t,0,0,0,e,0,0,0,1],multiply:(t,e)=>{let r=t[0],n=t[1],s=t[2],o=t[3],a=t[4],i=t[5],u=t[6],l=t[7],c=t[8],f=e[0],d=e[1],p=e[2],b=e[3],E=e[4],A=e[5],I=e[6],_=e[7],T=e[8];return[f*r+d*o+p*u,f*n+d*a+p*l,f*s+d*i+p*c,b*r+E*o+A*u,b*n+E*a+A*l,b*s+E*i+A*c,I*r+_*o+T*u,I*n+_*a+T*l,I*s+_*i+T*c]},translate:(t,e,r)=>Z.multiply(t,Z.translation(e,r)),rotate:(t,e)=>Z.multiply(t,Z.rotation(e)),scale:(t,e,r)=>Z.multiply(t,Z.scaling(e,r))};var oa={VertexShader:WebGLRenderingContext.VERTEX_SHADER,FragmentShader:WebGLRenderingContext.FRAGMENT_SHADER},Wu={[oa.VertexShader]:"VertexShader",[oa.FragmentShader]:"FragmentShader"},g2=t=>typeof t=="string"?t.startsWith("#version 300 es"):!1,th=t=>{if(!g2(t))throw new Error("Expecting GLSL ES 3.00 shader source")},y2=/ERROR:\s*\d+:(\d+)/gi;function oh(t,e="",r=0){let n=[...e.matchAll(y2)],s=new Map(n.map((o,a)=>{if(!o[1]||o.index===void 0)return[0,e];let i=Number.parseInt(o[1],10),u=n[a+1],l=u?u.index:e.length,c=e.substring(o.index,l);return[i-1,c]}));return t.split(`
46
46
  `).map((o,a)=>{let i=s.get(a);return`${a+1+r}: ${o}${i?`
47
47
 
48
48
  ^^^ ${i}`:""}`}).join(`
49
- `)}var Th=(t,e,r)=>{let n=t.createShader(e);if(!n)throw new Error(`Unable to create ${xu[e]}`);if(t.shaderSource(n,r),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){let o=t.getShaderInfoLog(n);t.deleteShader(n);let a=`Error compiling ${xu[e]}: ${o??""}
50
- ${o?Ah(r,o):"no error message available"}`;throw new Error(a)}return n},xp=(t,e,r,n)=>{let s=t.createProgram(),o=!1;if(!s)throw new Error("Unable to create WebGL program");for(let i of e)t.attachShader(s,i);if(r?.forEach((i,u)=>{let l=n?.[u]??u;t.bindAttribLocation(s,l,i)}),t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS)){let i=t.getProgramInfoLog(s);throw t.deleteProgram(s),new Error(`Error in program linking: ${i??""}
51
- ${e.map(u=>{let l=Ah(t.getShaderSource(u)??""),c=t.getShaderParameter(u,t.SHADER_TYPE);return`${xu[c]}:
49
+ `)}var rh=(t,e,r)=>{let n=t.createShader(e);if(!n)throw new Error(`Unable to create ${Wu[e]}`);if(t.shaderSource(n,r),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){let o=t.getShaderInfoLog(n);t.deleteShader(n);let a=`Error compiling ${Wu[e]}: ${o??""}
50
+ ${o?oh(r,o):"no error message available"}`;throw new Error(a)}return n},x2=(t,e,r,n)=>{let s=t.createProgram(),o=!1;if(!s)throw new Error("Unable to create WebGL program");for(let i of e)t.attachShader(s,i);if(r?.forEach((i,u)=>{let l=n?.[u]??u;t.bindAttribLocation(s,l,i)}),t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS)){let i=t.getProgramInfoLog(s);throw t.deleteProgram(s),new Error(`Error in program linking: ${i??""}
51
+ ${e.map(u=>{let l=oh(t.getShaderSource(u)??""),c=t.getShaderParameter(u,t.SHADER_TYPE);return`${Wu[c]}:
52
52
  ${l}`}).join(`
53
- `)}`)}return[s,()=>{if(!o){o=!0;for(let i of e)t.detachShader(s,i),t.deleteShader(i);t.deleteProgram(s)}}]},yp=(t,[e,r],n,s)=>xp(t,[Th(t,Go.VertexShader,e),Th(t,Go.FragmentShader,r)],n,s),Rh=(t,e)=>{let r=t.createTexture();return t.bindTexture(t.TEXTURE_2D,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,e?t.LINEAR:t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,e?t.LINEAR:t.NEAREST),r},Vt=(t,e,r,n=!1,s=!1)=>{let o=Rh(t,n);return s?(t.texImage2D(t.TEXTURE_2D,0,t.RGBA16F,e,r,0,t.RGBA,t.HALF_FLOAT,null),t.bindFramebuffer(t.FRAMEBUFFER,null),o):(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,r,0,t.RGBA,t.UNSIGNED_BYTE,null),t.bindTexture(t.TEXTURE_2D,null),o)},_e=(t,e,r,n=!1,s=!1,o=!1)=>{let a=Rh(t,n);return s?(t.texImage2D(t.TEXTURE_2D,0,t.R16F,e,r,0,t.RED,t.HALF_FLOAT,null),t.bindFramebuffer(t.FRAMEBUFFER,null),a):o?(t.texImage2D(t.TEXTURE_2D,0,t.RGBA16F,e,r,0,t.RGBA,t.HALF_FLOAT,null),t.bindFramebuffer(t.FRAMEBUFFER,null),a):(t.texImage2D(t.TEXTURE_2D,0,t.R8,e,r,0,t.RED,t.UNSIGNED_BYTE,null),t.bindTexture(t.TEXTURE_2D,null),a)},ae=(t,e)=>{let r=t.createFramebuffer();return t.bindFramebuffer(t.FRAMEBUFFER,r),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,e,0),t.bindFramebuffer(t.FRAMEBUFFER,null),r},kh=(t,e,r,n=2,s=2)=>{let o=t.createTexture();t.bindTexture(t.TEXTURE_2D,o),t.texImage2D(t.TEXTURE_2D,0,e,n,s,0,r,t.HALF_FLOAT,null),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST);let a=ae(t,o);t.bindFramebuffer(t.FRAMEBUFFER,a);let i=t.checkFramebufferStatus(t.FRAMEBUFFER)===t.FRAMEBUFFER_COMPLETE;return t.bindFramebuffer(t.FRAMEBUFFER,null),t.deleteFramebuffer(a),t.bindTexture(t.TEXTURE_2D,null),t.deleteTexture(o),i},Eh=(t,e,r)=>Object.keys(r).reduce((n,s)=>{let a=r[s];return a&&(n[s]=a.startsWith("u_")?t.getUniformLocation(e,a):t.getAttribLocation(e,a)),n},{}),fe=(t,{attribs:e,uniforms:r,vertexSrc:n,fragmentSrc:s})=>{let o=t.getContext("webgl2",{premultipliedAlpha:!1,powerPreference:"high-performance"});F(o,M.ContextCreationError),o.enable(o.BLEND),o.blendFunc(o.SRC_ALPHA,o.ONE_MINUS_SRC_ALPHA),wh(n),wh(s);let[a,i]=yp(o,[n,s]),u=!!o.getExtension("EXT_color_buffer_float"),l=u&&kh(o,o.R16F,o.RED),c=u&&kh(o,o.RGBA16F,o.RGBA);return{gl:o,program:a,attribLocations:Eh(o,a,e),uniformLocations:Eh(o,a,r),release:i,floatSingleChannelSupported:l,floatFullChannelSupported:c}},Ih=t=>({texture:t.getAsWebGLTexture(),width:t.width,height:t.height});var he=`#version 300 es
54
- in vec2 a_position;in vec2 a_texCoord;uniform mat3 u_matrix;out vec2 v_texCoord;void main(){gl_Position=vec4((u_matrix*vec3(a_position,1)).xy,0,1);v_texCoord=a_texCoord;}`;var Sh=`#version 300 es
55
- precision mediump float;uniform sampler2D u_mask;uniform ivec2 u_size;uniform float u_threshold;in vec2 v_texCoord;out vec4 outColor;void main(){ivec2 coord=ivec2(clamp(floor(v_texCoord*vec2(u_size)),vec2(0.0),vec2(u_size)-vec2(1.0)));float curr=texelFetch(u_mask,coord,0).r;float curr_binary=step(u_threshold,curr);outColor=vec4(curr_binary,curr_binary,curr_binary,1.0);}`;var yu=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatFullChannelSupported:i,floatSingleChannelSupported:u,release:l}=fe(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",mask:"u_mask",size:"u_size",threshold:"u_threshold"},vertexSrc:he,fragmentSrc:Sh}),c=n.createVertexArray();n.bindVertexArray(c);let f=n.createBuffer();n.enableVertexAttribArray(o.position),n.bindBuffer(n.ARRAY_BUFFER,f),n.vertexAttribPointer(o.position,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW);let d=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,d),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW),n.enableVertexAttribArray(o.texCoord),n.vertexAttribPointer(o.texCoord,2,n.FLOAT,!1,0,0);let p=_e(n,e,r,!1,u,i),T=ae(n,p);return{render:(A,E)=>{F(!n.isContextLost(),M.ContextLost),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(s),n.bindVertexArray(c),n.bindFramebuffer(n.FRAMEBUFFER,T),n.viewport(0,0,e,r),n.activeTexture(n.TEXTURE0),n.uniform1i(a.mask,0),n.bindTexture(n.TEXTURE_2D,A.texture),n.uniform2i(a.size,A.width,A.height),n.uniform1f(a.threshold,E);let I=Z.projection(1,1,1);return n.uniformMatrix3fv(a.matrix,!1,I),n.drawArrays(n.TRIANGLES,0,6),n.bindBuffer(n.ARRAY_BUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,null),n.bindVertexArray(null),{texture:p,width:e,height:r}},release:()=>{n.deleteBuffer(f),n.deleteBuffer(d),n.deleteTexture(p),n.deleteFramebuffer(T),n.deleteVertexArray(c),l()}}};var Ch=`#version 300 es
56
- precision mediump float;uniform sampler2D u_mask;uniform sampler2D u_frame_foreground;uniform sampler2D u_frame_background;uniform vec2 u_confidence_thresholds;in vec2 v_texCoord;out vec4 outColor;void main(){vec4 background=texture(u_frame_background,v_texCoord);vec4 foreground=texture(u_frame_foreground,v_texCoord);float person_mask=texture(u_mask,v_texCoord).r;person_mask=smoothstep(u_confidence_thresholds.x,u_confidence_thresholds.y,person_mask);outColor=mix(background,foreground,person_mask);}`;var Fh=t=>{let{gl:e,program:r,attribLocations:n,floatFullChannelSupported:s,uniformLocations:o,release:a}=fe(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",mask:"u_mask",frameBackground:"u_frame_background",frameForeground:"u_frame_foreground",confidenceThresholds:"u_confidence_thresholds"},vertexSrc:he,fragmentSrc:Ch});e.enable(e.BLEND);let i=e.createVertexArray();e.bindVertexArray(i);let u=e.createBuffer();e.enableVertexAttribArray(n.position),e.bindBuffer(e.ARRAY_BUFFER,u),e.vertexAttribPointer(n.position,2,e.FLOAT,!1,0,0),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),e.STATIC_DRAW);let l=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,l),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),e.STATIC_DRAW),e.enableVertexAttribArray(n.texCoord),e.vertexAttribPointer(n.texCoord,2,e.FLOAT,!1,0,0);let c=Vt(e,t.width,t.height,!0,s),f=ae(e,c);return{render:({mask:d,foreground:p,background:T},A)=>{F(!e.isContextLost(),M.ContextLost),e.useProgram(r),e.bindFramebuffer(e.FRAMEBUFFER,f),e.viewport(0,0,t.width,t.height),e.bindVertexArray(i),e.uniform2f(o.confidenceThresholds,A.backgroundThreshold,A.foregroundThreshold),e.activeTexture(e.TEXTURE0),e.uniform1i(o.frameForeground,0),e.bindTexture(e.TEXTURE_2D,p.texture),e.activeTexture(e.TEXTURE1),e.uniform1i(o.frameBackground,1),e.bindTexture(e.TEXTURE_2D,T.texture),e.activeTexture(e.TEXTURE2),e.uniform1i(o.mask,2),e.bindTexture(e.TEXTURE_2D,d.texture);let E=Z.projection(1,1,1);return e.uniformMatrix3fv(o.matrix,!1,E),e.drawArrays(e.TRIANGLES,0,6),e.bindBuffer(e.ARRAY_BUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),e.bindVertexArray(null),{texture:c,width:t.width,height:t.height}},release:()=>{e.deleteBuffer(u),e.deleteBuffer(l),e.deleteTexture(c),e.deleteFramebuffer(f),e.deleteVertexArray(i),a()}}};var Uh=`#version 300 es
57
- precision mediump float;uniform sampler2D u_frame;uniform int u_downsampling;in vec2 v_texCoord;out vec4 outColor;vec4 Downsample(sampler2D image,vec2 uv,vec2 halfpixel){vec4 sum=texture(image,uv)*4.0;sum+=texture(image,uv-halfpixel.xy);sum+=texture(image,uv+halfpixel.xy);sum+=texture(image,uv+vec2(halfpixel.x,-halfpixel.y));sum+=texture(image,uv-vec2(halfpixel.x,-halfpixel.y));return sum/8.0;}vec4 Upsample(sampler2D image,vec2 uv,vec2 halfpixel){vec4 sum=texture(image,uv+vec2(-halfpixel.x*2.0,0.0));sum+=texture(image,uv+vec2(-halfpixel.x,halfpixel.y))*2.0;sum+=texture(image,uv+vec2(0.0,halfpixel.y*2.0));sum+=texture(image,uv+vec2(halfpixel.x,halfpixel.y))*2.0;sum+=texture(image,uv+vec2(halfpixel.x*2.0,0.0));sum+=texture(image,uv+vec2(halfpixel.x,-halfpixel.y))*2.0;sum+=texture(image,uv+vec2(0.0,-halfpixel.y*2.0));sum+=texture(image,uv+vec2(-halfpixel.x,-halfpixel.y))*2.0;return sum/12.0;}void main(){vec2 halfpixel=0.5/vec2(textureSize(u_frame,0));if(u_downsampling==1){outColor=Downsample(u_frame,v_texCoord,halfpixel);return;}outColor=Upsample(u_frame,v_texCoord,halfpixel);}`;var Bh=9,_p=At(1,Bh),Vo=(t,e=!1)=>{let{gl:r,program:n,attribLocations:s,uniformLocations:o,floatSingleChannelSupported:a,floatFullChannelSupported:i,release:u}=fe(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",downsampling:"u_downsampling",frame:"u_frame"},vertexSrc:he,fragmentSrc:Uh}),l=r.createVertexArray();r.bindVertexArray(l);let c=r.createBuffer();r.enableVertexAttribArray(s.position),r.bindBuffer(r.ARRAY_BUFFER,c),r.vertexAttribPointer(s.position,2,r.FLOAT,!1,0,0),r.bufferData(r.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),r.STATIC_DRAW);let f=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,f),r.bufferData(r.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),r.STATIC_DRAW),r.enableVertexAttribArray(s.texCoord),r.vertexAttribPointer(s.texCoord,2,r.FLOAT,!1,0,0);let d=(A,E,I)=>{r.bindFramebuffer(r.FRAMEBUFFER,A),r.viewport(0,0,E,I)},p=A=>{let E=Math.max(Math.trunc(t.width/2**A),1),I=Math.max(Math.trunc(t.height/2**A),1),_=e?_e(r,E,I,!0,a,i):Vt(r,E,I,!0,i),v=ae(r,_);return{texture:_,frameBuffer:v,width:E,height:I}},T=Array.from({length:Bh}).map((A,E)=>p(E));return{render:(A,E)=>{if(F(!r.isContextLost(),M.ContextLost),!E)return{texture:A.texture,width:A.width,height:A.height};r.useProgram(n),r.bindVertexArray(l),r.activeTexture(r.TEXTURE0),r.uniform1i(o.frame,0),r.bindTexture(r.TEXTURE_2D,A.texture),r.uniform1i(o.downsampling,1);let I=_p(E+1);for(let _=1;_<I;_++){let{frameBuffer:v=null,texture:R=null,width:U=t.width,height:C=t.height}=T[_]??{};d(v,U,C);let O=Z.projection(1,1,1);r.uniformMatrix3fv(o.matrix,!1,O),r.drawArrays(r.TRIANGLES,0,6);let L=r.checkFramebufferStatus(r.FRAMEBUFFER),B=r.getError();if(F(B!==r.CONTEXT_LOST_WEBGL,M.ContextLost),F(!r.isContextLost(),M.ContextLost),L!==r.FRAMEBUFFER_COMPLETE||B!==r.NO_ERROR)throw new Error(M.SamplingError,{cause:`downsampling FrameBuffer Status: ${L}`});r.bindTexture(r.TEXTURE_2D,R)}r.uniform1i(o.downsampling,0);for(let _=I-2;_>=0;_--){let{frameBuffer:v=null,texture:R=null,width:U=t.width,height:C=t.height}=T[_]??{};d(v,U,C);let O=Z.projection(1,1,1);r.uniformMatrix3fv(o.matrix,!1,O),r.drawArrays(r.TRIANGLES,0,6);let L=r.checkFramebufferStatus(r.FRAMEBUFFER),B=r.getError();if(F(B!==r.CONTEXT_LOST_WEBGL,M.ContextLost),F(!r.isContextLost(),M.ContextLost),L!==r.FRAMEBUFFER_COMPLETE||B!==r.NO_ERROR)throw new Error(M.SamplingError,{cause:`Upsampling FrameBuffer Status: ${L}`});r.bindTexture(r.TEXTURE_2D,R)}return r.bindBuffer(r.ARRAY_BUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindTexture(r.TEXTURE_2D,null),r.bindVertexArray(null),{texture:T[0]?.texture??A.texture,width:T[0]?.width??A.width,height:T[0]?.height??A.height}},release:()=>{for(let{frameBuffer:A,texture:E}of T)r.deleteTexture(E),r.deleteFramebuffer(A);r.deleteBuffer(c),r.deleteBuffer(f),r.deleteVertexArray(l),u()}}};var An=`#version 300 es
58
- precision mediump float;in vec2 v_texCoord;uniform sampler2D u_texture;out vec4 outColor;void main(){outColor=texture(u_texture,v_texCoord);}`;var Wo=t=>{let{gl:e,program:r,attribLocations:n,uniformLocations:s,release:o}=fe(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",texture:"u_texture"},vertexSrc:he,fragmentSrc:An}),a=e.createVertexArray();e.bindVertexArray(a);let i=e.createBuffer();e.enableVertexAttribArray(n.position),e.bindBuffer(e.ARRAY_BUFFER,i),e.vertexAttribPointer(n.position,2,e.FLOAT,!1,0,0),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),e.STATIC_DRAW);let u=e.createBuffer();return e.bindBuffer(e.ARRAY_BUFFER,u),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),e.STATIC_DRAW),e.enableVertexAttribArray(n.texCoord),e.vertexAttribPointer(n.texCoord,2,e.FLOAT,!1,0,0),{render:l=>{F(!e.isContextLost(),M.ContextLost),e.bindFramebuffer(e.FRAMEBUFFER,null),e.viewport(0,0,t.width,t.height),e.clearColor(0,0,0,1),e.clear(e.COLOR_BUFFER_BIT),e.useProgram(r),e.bindVertexArray(a),e.uniform1i(s.texture,0);let c=Z.projection(1,1);e.uniformMatrix3fv(s.matrix,!1,c),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,l.texture),e.drawArrays(e.TRIANGLES,0,6),e.bindBuffer(e.ARRAY_BUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),e.bindVertexArray(null)},release:()=>{e.deleteBuffer(i),e.deleteBuffer(u),e.deleteVertexArray(a),o()}}};var Ft=(t,e,r=!1,n=t.width,s=t.height,o=!0)=>{let{gl:a,program:i,attribLocations:u,uniformLocations:l,floatFullChannelSupported:c,floatSingleChannelSupported:f,release:d}=fe(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",texture:"u_texture"},vertexSrc:he,fragmentSrc:An}),p=a.createVertexArray();a.bindVertexArray(p);let T=a.createBuffer();a.enableVertexAttribArray(u.position),a.bindBuffer(a.ARRAY_BUFFER,T),a.vertexAttribPointer(u.position,2,a.FLOAT,!1,0,0),a.bufferData(a.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),a.STATIC_DRAW);let A=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,A),a.bufferData(a.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),a.STATIC_DRAW),a.enableVertexAttribArray(u.texCoord),a.vertexAttribPointer(u.texCoord,2,a.FLOAT,!1,0,0);let E=e?_e(a,n,s,r,o&&f,o&&c):Vt(a,n,s,r,o&&c),I=ae(a,E);return{render:_=>{F(!a.isContextLost(),M.ContextLost),a.bindFramebuffer(a.FRAMEBUFFER,I),a.viewport(0,0,n,s),a.clearColor(0,0,0,1),a.clear(a.COLOR_BUFFER_BIT),a.useProgram(i),a.bindVertexArray(p),a.activeTexture(a.TEXTURE0),a.uniform1i(l.texture,0),a.bindTexture(a.TEXTURE_2D,_.texture);let v=Z.projection(1,1,1);return a.uniformMatrix3fv(l.matrix,!1,v),a.drawArrays(a.TRIANGLES,0,6),a.bindBuffer(a.ARRAY_BUFFER,null),a.bindFramebuffer(a.FRAMEBUFFER,null),a.bindTexture(a.TEXTURE_2D,null),a.bindVertexArray(null),{texture:E,width:n,height:s}},release:()=>{a.deleteBuffer(T),a.deleteBuffer(A),a.deleteTexture(E),a.deleteVertexArray(p),d()}}};function Lh(t,e,r){let n=t.getContext("webgl2",{premultipliedAlpha:!1,powerPreference:"high-performance"}),s=Ft(t,!0,!1,e,r,!1);F(n,M.ContextCreationError);let o=new Int32Array(e*r),a=new Uint8Array(e*r),i=new Uint8Array(e*r),u=new Uint8Array(e*r),l=new Uint8Array(e*r),c=0,f=n.createTexture();n.bindTexture(n.TEXTURE_2D,f),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST);let d=n.createFramebuffer(),p={switchThreshold:.3,decay:.95,area:.2,height:.4,center:.2,iou:.2};return{render:(T,A)=>{let E=s.render(T);n.bindFramebuffer(n.FRAMEBUFFER,d),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,E.texture,0),n.readPixels(0,0,e,r,n.RED,n.UNSIGNED_BYTE,a),n.bindFramebuffer(n.FRAMEBUFFER,null);let I=Math.max(0,Math.min(255,Math.floor(255*A.foregroundThreshold)));for(let C=0;C<i.length;C++)i[C]=a[C]>=I?255:0;let _=-1/0,v=0,R=qf(i,o,e,r);for(let[C,O]of R.entries()){if(C===0)continue;for(let B=0;B<o.length;B++)l[B]=o[B]===C?255:0;let L=Kf(O,Yf(u,l),{...p,centerX:A.personCenter[0]*e,centerY:A.personCenter[1]*r},e,r);L>_&&(_=L,v=C)}if(_>c*(1+p.switchThreshold)||c===0){for(let C=0;C<o.length;C++)u[C]=o[C]===v?255:0;c=_}else c*=p.decay;return n.bindTexture(n.TEXTURE_2D,f),n.texImage2D(n.TEXTURE_2D,0,n.R8,e,r,0,n.RED,n.UNSIGNED_BYTE,u),n.bindTexture(n.TEXTURE_2D,null),{texture:f,width:e,height:r}},release:()=>{n.deleteTexture(f),n.deleteFramebuffer(d),s.release()}}}var Ph=`#version 300 es
59
- precision mediump float;uniform sampler2D u_mask;uniform sampler2D u_ref_mask;uniform vec2 u_texel_size;uniform vec2 u_direction;uniform int u_radius_px;const int MAX_RADIUS_PX=64;in vec2 v_texCoord;out vec4 outColor;void main(){float mx=0.0;for(int i=-MAX_RADIUS_PX;i<=MAX_RADIUS_PX;++i){if(abs(i)>u_radius_px)continue;vec2 off=u_direction*float(i)*u_texel_size;mx=max(mx,texture(u_mask,v_texCoord+off).r);}mx=min(mx,texture(u_ref_mask,v_texCoord).r);outColor=vec4(mx,mx,mx,1.0);}`;var Oh=`#version 300 es
60
- precision mediump float;uniform sampler2D u_tex_a;uniform sampler2D u_tex_b;uniform ivec2 u_size;in vec2 v_texCoord;out vec4 outColor;void main(){ivec2 iuv=ivec2(clamp(floor(v_texCoord*vec2(u_size)),vec2(0.0),vec2(u_size)-vec2(1.0)));float a=texelFetch(u_tex_a,iuv,0).r;float b=texelFetch(u_tex_b,iuv,0).r;float diff=abs(a-b);outColor=vec4(diff,diff,diff,1.0);}`;var Dh=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatSingleChannelSupported:i,floatFullChannelSupported:u,release:l}=fe(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",texA:"u_tex_a",texB:"u_tex_b",size:"u_size"},vertexSrc:he,fragmentSrc:Oh}),c=n.createVertexArray();n.bindVertexArray(c);let f=n.createBuffer();n.enableVertexAttribArray(o.position),n.bindBuffer(n.ARRAY_BUFFER,f),n.vertexAttribPointer(o.position,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW);let d=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,d),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW),n.enableVertexAttribArray(o.texCoord),n.vertexAttribPointer(o.texCoord,2,n.FLOAT,!1,0,0);let p=_e(n,e,r,!0,i,u),T=ae(n,p);return{render:(A,E)=>{F(!n.isContextLost(),M.ContextLost),F(A.width===E.width&&A.height===E.height),n.useProgram(s),n.bindVertexArray(c),n.uniform2i(a.size,A.width,A.height),n.activeTexture(n.TEXTURE0),n.uniform1i(a.texA,0),n.bindTexture(n.TEXTURE_2D,A.texture),n.activeTexture(n.TEXTURE1),n.uniform1i(a.texB,1),n.bindTexture(n.TEXTURE_2D,E.texture);let I=Z.projection(1,1,1);return n.uniformMatrix3fv(a.matrix,!1,I),n.bindFramebuffer(n.FRAMEBUFFER,T),n.viewport(0,0,e,r),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.drawArrays(n.TRIANGLES,0,6),n.bindBuffer(n.ARRAY_BUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,null),n.bindVertexArray(null),{texture:p,frameBuffer:T,width:e,height:r}},release:()=>{n.deleteBuffer(f),n.deleteBuffer(d),n.deleteTexture(p),n.deleteFramebuffer(T),n.deleteVertexArray(c),l()}}};var bp=64,vp=64,wp=At(0,vp),_u=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatSingleChannelSupported:i,floatFullChannelSupported:u,release:l}=fe(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",mask:"u_mask",maskRef:"u_ref_mask",texelSize:"u_texel_size",radiusPx:"u_radius_px",direction:"u_direction"},vertexSrc:he,fragmentSrc:Ph}),c=n.createVertexArray();n.bindVertexArray(c);let f=n.createBuffer();n.enableVertexAttribArray(o.position),n.bindBuffer(n.ARRAY_BUFFER,f),n.vertexAttribPointer(o.position,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW);let d=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,d),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW),n.enableVertexAttribArray(o.texCoord),n.vertexAttribPointer(o.texCoord,2,n.FLOAT,!1,0,0);let p=t.width/e,T=32,A=18,E=Math.max(Math.floor(e/4),T),I=Math.max(Math.floor(r/4),A),_=E===T?1e-8:1e-4,v=E*I,R=Dh(t,E,I),U=i||u,C=U?n.RGBA:n.RED,O=U?n.FLOAT:n.UNSIGNED_BYTE,L=U?new Float32Array(v*4):new Uint8Array(v),B=_e(n,e,r,!1,i,u),N=_e(n,e,r,!1,i,u),D=ae(n,B),X=ae(n,N);return{render:({mask:ne,maskRef:Re},Ge)=>{F(!n.isContextLost(),M.ContextLost);let me=D,tt=ne.texture,ze=()=>{n.useProgram(s),n.bindVertexArray(c),n.uniform1i(a.radiusPx,wp(Math.floor(Ge.morphDilateRadiusPx/p))),n.uniform2f(a.texelSize,1/ne.width,1/ne.height),n.activeTexture(n.TEXTURE1),n.uniform1i(a.maskRef,1),n.bindTexture(n.TEXTURE_2D,Re.texture);let He=Z.projection(1,1,1);n.uniformMatrix3fv(a.matrix,!1,He);for(let Q=0;Q<2;Q++)n.activeTexture(n.TEXTURE0),n.uniform1i(a.mask,0),n.bindTexture(n.TEXTURE_2D,tt),n.uniform2f(a.direction,1-Q,0+Q),n.bindFramebuffer(n.FRAMEBUFFER,me),n.viewport(0,0,e,r),n.drawArrays(n.TRIANGLES,0,6),[tt,me]=me===D?[B,X]:[N,D]};for(let He=0;He<Ge.morphPass;He++)ze();let Wt=!1,Ve=0;for(;!Wt;){ze();let He=R.render({texture:B,width:e,height:r},{texture:N,width:e,height:r});n.bindFramebuffer(n.FRAMEBUFFER,He.frameBuffer),n.readPixels(0,0,E,I,C,O,L);let Q=0,We=0;if(U){for(let Ue=0,is=0;Ue<v;++Ue,is+=4)Q+=L[is];We=Q/v}else{for(let Ue=0;Ue<v;++Ue)Q+=L[Ue];We=Q/v/255}n.bindFramebuffer(n.FRAMEBUFFER,null),(We<_||Ve>=bp)&&(Wt=!0),Ve++}return n.bindBuffer(n.ARRAY_BUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,null),n.bindVertexArray(null),{texture:tt,width:e,height:r}},release:()=>{n.deleteBuffer(f),n.deleteBuffer(d),n.deleteTexture(B),n.deleteTexture(N),n.deleteFramebuffer(D),n.deleteFramebuffer(X),n.deleteVertexArray(c),R.release(),l()}}};var Mh=`#version 300 es
53
+ `)}`)}return[s,()=>{if(!o){o=!0;for(let i of e)t.detachShader(s,i),t.deleteShader(i);t.deleteProgram(s)}}]},_2=(t,[e,r],n,s)=>x2(t,[rh(t,oa.VertexShader,e),rh(t,oa.FragmentShader,r)],n,s),ah=(t,e)=>{let r=t.createTexture();return t.bindTexture(t.TEXTURE_2D,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,e?t.LINEAR:t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,e?t.LINEAR:t.NEAREST),r},Yt=(t,e,r,n=!1,s=!1)=>{let o=ah(t,n);return s?(t.texImage2D(t.TEXTURE_2D,0,t.RGBA16F,e,r,0,t.RGBA,t.HALF_FLOAT,null),t.bindFramebuffer(t.FRAMEBUFFER,null),o):(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,r,0,t.RGBA,t.UNSIGNED_BYTE,null),t.bindTexture(t.TEXTURE_2D,null),o)},be=(t,e,r,n=!1,s=!1,o=!1)=>{let a=ah(t,n);return s?(t.texImage2D(t.TEXTURE_2D,0,t.R16F,e,r,0,t.RED,t.HALF_FLOAT,null),t.bindFramebuffer(t.FRAMEBUFFER,null),a):o?(t.texImage2D(t.TEXTURE_2D,0,t.RGBA16F,e,r,0,t.RGBA,t.HALF_FLOAT,null),t.bindFramebuffer(t.FRAMEBUFFER,null),a):(t.texImage2D(t.TEXTURE_2D,0,t.R8,e,r,0,t.RED,t.UNSIGNED_BYTE,null),t.bindTexture(t.TEXTURE_2D,null),a)},ae=(t,e)=>{let r=t.createFramebuffer();return t.bindFramebuffer(t.FRAMEBUFFER,r),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,e,0),t.bindFramebuffer(t.FRAMEBUFFER,null),r},nh=(t,e,r,n=2,s=2)=>{let o=t.createTexture();t.bindTexture(t.TEXTURE_2D,o),t.texImage2D(t.TEXTURE_2D,0,e,n,s,0,r,t.HALF_FLOAT,null),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST);let a=ae(t,o);t.bindFramebuffer(t.FRAMEBUFFER,a);let i=t.checkFramebufferStatus(t.FRAMEBUFFER)===t.FRAMEBUFFER_COMPLETE;return t.bindFramebuffer(t.FRAMEBUFFER,null),t.deleteFramebuffer(a),t.bindTexture(t.TEXTURE_2D,null),t.deleteTexture(o),i},sh=(t,e,r)=>Object.keys(r).reduce((n,s)=>{let a=r[s];return a&&(n[s]=a.startsWith("u_")?t.getUniformLocation(e,a):t.getAttribLocation(e,a)),n},{}),de=(t,{attribs:e,uniforms:r,vertexSrc:n,fragmentSrc:s})=>{let o=t.getContext("webgl2",{premultipliedAlpha:!1,powerPreference:"high-performance"});C(o,M.ContextCreationError),o.enable(o.BLEND),o.blendFunc(o.SRC_ALPHA,o.ONE_MINUS_SRC_ALPHA),th(n),th(s);let[a,i]=_2(o,[n,s]),u=!!o.getExtension("EXT_color_buffer_float"),l=u&&nh(o,o.R16F,o.RED),c=u&&nh(o,o.RGBA16F,o.RGBA);return{gl:o,program:a,attribLocations:sh(o,a,e),uniformLocations:sh(o,a,r),release:i,floatSingleChannelSupported:l,floatFullChannelSupported:c}},ih=t=>({texture:t.getAsWebGLTexture(),width:t.width,height:t.height});var he=`#version 300 es
54
+ in vec2 a_position;in vec2 a_texCoord;uniform mat3 u_matrix;out vec2 v_texCoord;void main(){gl_Position=vec4((u_matrix*vec3(a_position,1)).xy,0,1);v_texCoord=a_texCoord;}`;var uh=`#version 300 es
55
+ precision mediump float;uniform sampler2D u_mask;uniform ivec2 u_size;uniform float u_threshold;in vec2 v_texCoord;out vec4 outColor;void main(){ivec2 coord=ivec2(clamp(floor(v_texCoord*vec2(u_size)),vec2(0.0),vec2(u_size)-vec2(1.0)));float curr=texelFetch(u_mask,coord,0).r;float curr_binary=step(u_threshold,curr);outColor=vec4(curr_binary,curr_binary,curr_binary,1.0);}`;var $u=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatFullChannelSupported:i,floatSingleChannelSupported:u,release:l}=de(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",mask:"u_mask",size:"u_size",threshold:"u_threshold"},vertexSrc:he,fragmentSrc:uh}),c=n.createVertexArray();n.bindVertexArray(c);let f=n.createBuffer();n.enableVertexAttribArray(o.position),n.bindBuffer(n.ARRAY_BUFFER,f),n.vertexAttribPointer(o.position,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW);let d=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,d),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW),n.enableVertexAttribArray(o.texCoord),n.vertexAttribPointer(o.texCoord,2,n.FLOAT,!1,0,0);let p=be(n,e,r,!1,u,i),b=ae(n,p);return{render:(E,A)=>{C(!n.isContextLost(),M.ContextLost),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(s),n.bindVertexArray(c),n.bindFramebuffer(n.FRAMEBUFFER,b),n.viewport(0,0,e,r),n.activeTexture(n.TEXTURE0),n.uniform1i(a.mask,0),n.bindTexture(n.TEXTURE_2D,E.texture),n.uniform2i(a.size,E.width,E.height),n.uniform1f(a.threshold,A);let I=Z.projection(1,1,1);return n.uniformMatrix3fv(a.matrix,!1,I),n.drawArrays(n.TRIANGLES,0,6),n.bindBuffer(n.ARRAY_BUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,null),n.bindVertexArray(null),{texture:p,width:e,height:r}},release:()=>{n.deleteBuffer(f),n.deleteBuffer(d),n.deleteTexture(p),n.deleteFramebuffer(b),n.deleteVertexArray(c),l()}}};var ch=`#version 300 es
56
+ precision mediump float;uniform sampler2D u_mask;uniform sampler2D u_frame_foreground;uniform sampler2D u_frame_background;uniform vec2 u_confidence_thresholds;in vec2 v_texCoord;out vec4 outColor;void main(){vec4 background=texture(u_frame_background,v_texCoord);vec4 foreground=texture(u_frame_foreground,v_texCoord);float person_mask=texture(u_mask,v_texCoord).r;person_mask=smoothstep(u_confidence_thresholds.x,u_confidence_thresholds.y,person_mask);outColor=mix(background,foreground,person_mask);}`;var lh=t=>{let{gl:e,program:r,attribLocations:n,floatFullChannelSupported:s,uniformLocations:o,release:a}=de(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",mask:"u_mask",frameBackground:"u_frame_background",frameForeground:"u_frame_foreground",confidenceThresholds:"u_confidence_thresholds"},vertexSrc:he,fragmentSrc:ch});e.enable(e.BLEND);let i=e.createVertexArray();e.bindVertexArray(i);let u=e.createBuffer();e.enableVertexAttribArray(n.position),e.bindBuffer(e.ARRAY_BUFFER,u),e.vertexAttribPointer(n.position,2,e.FLOAT,!1,0,0),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),e.STATIC_DRAW);let l=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,l),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),e.STATIC_DRAW),e.enableVertexAttribArray(n.texCoord),e.vertexAttribPointer(n.texCoord,2,e.FLOAT,!1,0,0);let c=Yt(e,t.width,t.height,!0,s),f=ae(e,c);return{render:({mask:d,foreground:p,background:b},E)=>{C(!e.isContextLost(),M.ContextLost),e.useProgram(r),e.bindFramebuffer(e.FRAMEBUFFER,f),e.viewport(0,0,t.width,t.height),e.bindVertexArray(i),e.uniform2f(o.confidenceThresholds,E.backgroundThreshold,E.foregroundThreshold),e.activeTexture(e.TEXTURE0),e.uniform1i(o.frameForeground,0),e.bindTexture(e.TEXTURE_2D,p.texture),e.activeTexture(e.TEXTURE1),e.uniform1i(o.frameBackground,1),e.bindTexture(e.TEXTURE_2D,b.texture),e.activeTexture(e.TEXTURE2),e.uniform1i(o.mask,2),e.bindTexture(e.TEXTURE_2D,d.texture);let A=Z.projection(1,1,1);return e.uniformMatrix3fv(o.matrix,!1,A),e.drawArrays(e.TRIANGLES,0,6),e.bindBuffer(e.ARRAY_BUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),e.bindVertexArray(null),{texture:c,width:t.width,height:t.height}},release:()=>{e.deleteBuffer(u),e.deleteBuffer(l),e.deleteTexture(c),e.deleteFramebuffer(f),e.deleteVertexArray(i),a()}}};var fh=`#version 300 es
57
+ precision mediump float;uniform sampler2D u_frame;uniform int u_downsampling;in vec2 v_texCoord;out vec4 outColor;vec4 Downsample(sampler2D image,vec2 uv,vec2 halfpixel){vec4 sum=texture(image,uv)*4.0;sum+=texture(image,uv-halfpixel.xy);sum+=texture(image,uv+halfpixel.xy);sum+=texture(image,uv+vec2(halfpixel.x,-halfpixel.y));sum+=texture(image,uv-vec2(halfpixel.x,-halfpixel.y));return sum/8.0;}vec4 Upsample(sampler2D image,vec2 uv,vec2 halfpixel){vec4 sum=texture(image,uv+vec2(-halfpixel.x*2.0,0.0));sum+=texture(image,uv+vec2(-halfpixel.x,halfpixel.y))*2.0;sum+=texture(image,uv+vec2(0.0,halfpixel.y*2.0));sum+=texture(image,uv+vec2(halfpixel.x,halfpixel.y))*2.0;sum+=texture(image,uv+vec2(halfpixel.x*2.0,0.0));sum+=texture(image,uv+vec2(halfpixel.x,-halfpixel.y))*2.0;sum+=texture(image,uv+vec2(0.0,-halfpixel.y*2.0));sum+=texture(image,uv+vec2(-halfpixel.x,-halfpixel.y))*2.0;return sum/12.0;}void main(){vec2 halfpixel=0.5/vec2(textureSize(u_frame,0));if(u_downsampling==1){outColor=Downsample(u_frame,v_texCoord,halfpixel);return;}outColor=Upsample(u_frame,v_texCoord,halfpixel);}`;var dh=9,b2=Ut(1,dh),aa=(t,e=!1)=>{let{gl:r,program:n,attribLocations:s,uniformLocations:o,floatSingleChannelSupported:a,floatFullChannelSupported:i,release:u}=de(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",downsampling:"u_downsampling",frame:"u_frame"},vertexSrc:he,fragmentSrc:fh}),l=r.createVertexArray();r.bindVertexArray(l);let c=r.createBuffer();r.enableVertexAttribArray(s.position),r.bindBuffer(r.ARRAY_BUFFER,c),r.vertexAttribPointer(s.position,2,r.FLOAT,!1,0,0),r.bufferData(r.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),r.STATIC_DRAW);let f=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,f),r.bufferData(r.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),r.STATIC_DRAW),r.enableVertexAttribArray(s.texCoord),r.vertexAttribPointer(s.texCoord,2,r.FLOAT,!1,0,0);let d=(E,A,I)=>{r.bindFramebuffer(r.FRAMEBUFFER,E),r.viewport(0,0,A,I)},p=E=>{let A=Math.max(Math.trunc(t.width/2**E),1),I=Math.max(Math.trunc(t.height/2**E),1),_=e?be(r,A,I,!0,a,i):Yt(r,A,I,!0,i),T=ae(r,_);return{texture:_,frameBuffer:T,width:A,height:I}},b=Array.from({length:dh}).map((E,A)=>p(A));return{render:(E,A)=>{if(C(!r.isContextLost(),M.ContextLost),!A)return{texture:E.texture,width:E.width,height:E.height};r.useProgram(n),r.bindVertexArray(l),r.activeTexture(r.TEXTURE0),r.uniform1i(o.frame,0),r.bindTexture(r.TEXTURE_2D,E.texture),r.uniform1i(o.downsampling,1);let I=b2(A+1);for(let _=1;_<I;_++){let{frameBuffer:T=null,texture:R=null,width:U=t.width,height:B=t.height}=b[_]??{};d(T,U,B);let O=Z.projection(1,1,1);r.uniformMatrix3fv(o.matrix,!1,O),r.drawArrays(r.TRIANGLES,0,6);let P=r.checkFramebufferStatus(r.FRAMEBUFFER),F=r.getError();if(C(F!==r.CONTEXT_LOST_WEBGL,M.ContextLost),C(!r.isContextLost(),M.ContextLost),P!==r.FRAMEBUFFER_COMPLETE||F!==r.NO_ERROR)throw new Error(M.SamplingError,{cause:`downsampling FrameBuffer Status: ${P}`});r.bindTexture(r.TEXTURE_2D,R)}r.uniform1i(o.downsampling,0);for(let _=I-2;_>=0;_--){let{frameBuffer:T=null,texture:R=null,width:U=t.width,height:B=t.height}=b[_]??{};d(T,U,B);let O=Z.projection(1,1,1);r.uniformMatrix3fv(o.matrix,!1,O),r.drawArrays(r.TRIANGLES,0,6);let P=r.checkFramebufferStatus(r.FRAMEBUFFER),F=r.getError();if(C(F!==r.CONTEXT_LOST_WEBGL,M.ContextLost),C(!r.isContextLost(),M.ContextLost),P!==r.FRAMEBUFFER_COMPLETE||F!==r.NO_ERROR)throw new Error(M.SamplingError,{cause:`Upsampling FrameBuffer Status: ${P}`});r.bindTexture(r.TEXTURE_2D,R)}return r.bindBuffer(r.ARRAY_BUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindTexture(r.TEXTURE_2D,null),r.bindVertexArray(null),{texture:b[0]?.texture??E.texture,width:b[0]?.width??E.width,height:b[0]?.height??E.height}},release:()=>{for(let{frameBuffer:E,texture:A}of b)r.deleteTexture(A),r.deleteFramebuffer(E);r.deleteBuffer(c),r.deleteBuffer(f),r.deleteVertexArray(l),u()}}};var Dn=`#version 300 es
58
+ precision mediump float;in vec2 v_texCoord;uniform sampler2D u_texture;out vec4 outColor;void main(){outColor=texture(u_texture,v_texCoord);}`;var ia=t=>{let{gl:e,program:r,attribLocations:n,uniformLocations:s,release:o}=de(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",texture:"u_texture"},vertexSrc:he,fragmentSrc:Dn}),a=e.createVertexArray();e.bindVertexArray(a);let i=e.createBuffer();e.enableVertexAttribArray(n.position),e.bindBuffer(e.ARRAY_BUFFER,i),e.vertexAttribPointer(n.position,2,e.FLOAT,!1,0,0),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),e.STATIC_DRAW);let u=e.createBuffer();return e.bindBuffer(e.ARRAY_BUFFER,u),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),e.STATIC_DRAW),e.enableVertexAttribArray(n.texCoord),e.vertexAttribPointer(n.texCoord,2,e.FLOAT,!1,0,0),{render:l=>{C(!e.isContextLost(),M.ContextLost),e.bindFramebuffer(e.FRAMEBUFFER,null),e.viewport(0,0,t.width,t.height),e.clearColor(0,0,0,1),e.clear(e.COLOR_BUFFER_BIT),e.useProgram(r),e.bindVertexArray(a),e.uniform1i(s.texture,0);let c=Z.projection(1,1);e.uniformMatrix3fv(s.matrix,!1,c),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,l.texture),e.drawArrays(e.TRIANGLES,0,6),e.bindBuffer(e.ARRAY_BUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),e.bindVertexArray(null)},release:()=>{e.deleteBuffer(i),e.deleteBuffer(u),e.deleteVertexArray(a),o()}}};var Dt=(t,e,r=!1,n=t.width,s=t.height,o=!0)=>{let{gl:a,program:i,attribLocations:u,uniformLocations:l,floatFullChannelSupported:c,floatSingleChannelSupported:f,release:d}=de(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",texture:"u_texture"},vertexSrc:he,fragmentSrc:Dn}),p=a.createVertexArray();a.bindVertexArray(p);let b=a.createBuffer();a.enableVertexAttribArray(u.position),a.bindBuffer(a.ARRAY_BUFFER,b),a.vertexAttribPointer(u.position,2,a.FLOAT,!1,0,0),a.bufferData(a.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),a.STATIC_DRAW);let E=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,E),a.bufferData(a.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),a.STATIC_DRAW),a.enableVertexAttribArray(u.texCoord),a.vertexAttribPointer(u.texCoord,2,a.FLOAT,!1,0,0);let A=e?be(a,n,s,r,o&&f,o&&c):Yt(a,n,s,r,o&&c),I=ae(a,A);return{render:_=>{C(!a.isContextLost(),M.ContextLost),a.bindFramebuffer(a.FRAMEBUFFER,I),a.viewport(0,0,n,s),a.clearColor(0,0,0,1),a.clear(a.COLOR_BUFFER_BIT),a.useProgram(i),a.bindVertexArray(p),a.activeTexture(a.TEXTURE0),a.uniform1i(l.texture,0),a.bindTexture(a.TEXTURE_2D,_.texture);let T=Z.projection(1,1,1);return a.uniformMatrix3fv(l.matrix,!1,T),a.drawArrays(a.TRIANGLES,0,6),a.bindBuffer(a.ARRAY_BUFFER,null),a.bindFramebuffer(a.FRAMEBUFFER,null),a.bindTexture(a.TEXTURE_2D,null),a.bindVertexArray(null),{texture:A,width:n,height:s}},release:()=>{a.deleteBuffer(b),a.deleteBuffer(E),a.deleteTexture(A),a.deleteVertexArray(p),d()}}};function hh(t,e,r){let n=t.getContext("webgl2",{premultipliedAlpha:!1,powerPreference:"high-performance"}),s=Dt(t,!0,!1,e,r,!1);C(n,M.ContextCreationError);let o=new Int32Array(e*r),a=new Uint8Array(e*r),i=new Uint8Array(e*r),u=new Uint8Array(e*r),l=new Uint8Array(e*r),c=0,f=n.createTexture();n.bindTexture(n.TEXTURE_2D,f),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST);let d=n.createFramebuffer(),p={switchThreshold:.3,decay:.95,area:.2,height:.4,center:.2,iou:.2};return{render:(b,E)=>{let A=s.render(b);n.bindFramebuffer(n.FRAMEBUFFER,d),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,A.texture,0),n.readPixels(0,0,e,r,n.RED,n.UNSIGNED_BYTE,a),n.bindFramebuffer(n.FRAMEBUFFER,null);let I=Math.max(0,Math.min(255,Math.floor(255*E.foregroundThreshold)));for(let B=0;B<i.length;B++)i[B]=a[B]>=I?255:0;let _=-1/0,T=0,R=Ed(i,o,e,r);for(let[B,O]of R.entries()){if(B===0)continue;for(let F=0;F<o.length;F++)l[F]=o[F]===B?255:0;let P=Ad(O,kd(u,l),{...p,centerX:E.personCenter[0]*e,centerY:E.personCenter[1]*r},e,r);P>_&&(_=P,T=B)}if(_>c*(1+p.switchThreshold)||c===0){for(let B=0;B<o.length;B++)u[B]=o[B]===T?255:0;c=_}else c*=p.decay;return n.bindTexture(n.TEXTURE_2D,f),n.texImage2D(n.TEXTURE_2D,0,n.R8,e,r,0,n.RED,n.UNSIGNED_BYTE,u),n.bindTexture(n.TEXTURE_2D,null),{texture:f,width:e,height:r}},release:()=>{n.deleteTexture(f),n.deleteFramebuffer(d),s.release()}}}var ph=`#version 300 es
59
+ precision mediump float;uniform sampler2D u_mask;uniform sampler2D u_ref_mask;uniform vec2 u_texel_size;uniform vec2 u_direction;uniform int u_radius_px;const int MAX_RADIUS_PX=64;in vec2 v_texCoord;out vec4 outColor;void main(){float mx=0.0;for(int i=-MAX_RADIUS_PX;i<=MAX_RADIUS_PX;++i){if(abs(i)>u_radius_px)continue;vec2 off=u_direction*float(i)*u_texel_size;mx=max(mx,texture(u_mask,v_texCoord+off).r);}mx=min(mx,texture(u_ref_mask,v_texCoord).r);outColor=vec4(mx,mx,mx,1.0);}`;var mh=`#version 300 es
60
+ precision mediump float;uniform sampler2D u_tex_a;uniform sampler2D u_tex_b;uniform ivec2 u_size;in vec2 v_texCoord;out vec4 outColor;void main(){ivec2 iuv=ivec2(clamp(floor(v_texCoord*vec2(u_size)),vec2(0.0),vec2(u_size)-vec2(1.0)));float a=texelFetch(u_tex_a,iuv,0).r;float b=texelFetch(u_tex_b,iuv,0).r;float diff=abs(a-b);outColor=vec4(diff,diff,diff,1.0);}`;var gh=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatSingleChannelSupported:i,floatFullChannelSupported:u,release:l}=de(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",texA:"u_tex_a",texB:"u_tex_b",size:"u_size"},vertexSrc:he,fragmentSrc:mh}),c=n.createVertexArray();n.bindVertexArray(c);let f=n.createBuffer();n.enableVertexAttribArray(o.position),n.bindBuffer(n.ARRAY_BUFFER,f),n.vertexAttribPointer(o.position,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW);let d=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,d),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW),n.enableVertexAttribArray(o.texCoord),n.vertexAttribPointer(o.texCoord,2,n.FLOAT,!1,0,0);let p=be(n,e,r,!0,i,u),b=ae(n,p);return{render:(E,A)=>{C(!n.isContextLost(),M.ContextLost),C(E.width===A.width&&E.height===A.height),n.useProgram(s),n.bindVertexArray(c),n.uniform2i(a.size,E.width,E.height),n.activeTexture(n.TEXTURE0),n.uniform1i(a.texA,0),n.bindTexture(n.TEXTURE_2D,E.texture),n.activeTexture(n.TEXTURE1),n.uniform1i(a.texB,1),n.bindTexture(n.TEXTURE_2D,A.texture);let I=Z.projection(1,1,1);return n.uniformMatrix3fv(a.matrix,!1,I),n.bindFramebuffer(n.FRAMEBUFFER,b),n.viewport(0,0,e,r),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.drawArrays(n.TRIANGLES,0,6),n.bindBuffer(n.ARRAY_BUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,null),n.bindVertexArray(null),{texture:p,frameBuffer:b,width:e,height:r}},release:()=>{n.deleteBuffer(f),n.deleteBuffer(d),n.deleteTexture(p),n.deleteFramebuffer(b),n.deleteVertexArray(c),l()}}};var v2=64,w2=64,T2=Ut(0,w2),zu=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatSingleChannelSupported:i,floatFullChannelSupported:u,release:l}=de(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",mask:"u_mask",maskRef:"u_ref_mask",texelSize:"u_texel_size",radiusPx:"u_radius_px",direction:"u_direction"},vertexSrc:he,fragmentSrc:ph}),c=n.createVertexArray();n.bindVertexArray(c);let f=n.createBuffer();n.enableVertexAttribArray(o.position),n.bindBuffer(n.ARRAY_BUFFER,f),n.vertexAttribPointer(o.position,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW);let d=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,d),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW),n.enableVertexAttribArray(o.texCoord),n.vertexAttribPointer(o.texCoord,2,n.FLOAT,!1,0,0);let p=t.width/e,b=32,E=18,A=Math.max(Math.floor(e/4),b),I=Math.max(Math.floor(r/4),E),_=A===b?1e-8:1e-4,T=A*I,R=gh(t,A,I),U=i||u,B=U?n.RGBA:n.RED,O=U?n.FLOAT:n.UNSIGNED_BYTE,P=U?new Float32Array(T*4):new Uint8Array(T),F=be(n,e,r,!1,i,u),N=be(n,e,r,!1,i,u),D=ae(n,F),j=ae(n,N);return{render:({mask:ne,maskRef:Se},We)=>{C(!n.isContextLost(),M.ContextLost);let me=D,st=ne.texture,Xe=()=>{n.useProgram(s),n.bindVertexArray(c),n.uniform1i(a.radiusPx,T2(Math.floor(We.morphDilateRadiusPx/p))),n.uniform2f(a.texelSize,1/ne.width,1/ne.height),n.activeTexture(n.TEXTURE1),n.uniform1i(a.maskRef,1),n.bindTexture(n.TEXTURE_2D,Se.texture);let Ye=Z.projection(1,1,1);n.uniformMatrix3fv(a.matrix,!1,Ye);for(let Q=0;Q<2;Q++)n.activeTexture(n.TEXTURE0),n.uniform1i(a.mask,0),n.bindTexture(n.TEXTURE_2D,st),n.uniform2f(a.direction,1-Q,0+Q),n.bindFramebuffer(n.FRAMEBUFFER,me),n.viewport(0,0,e,r),n.drawArrays(n.TRIANGLES,0,6),[st,me]=me===D?[F,j]:[N,D]};for(let Ye=0;Ye<We.morphPass;Ye++)Xe();let Kt=!1,$e=0;for(;!Kt;){Xe();let Ye=R.render({texture:F,width:e,height:r},{texture:N,width:e,height:r});n.bindFramebuffer(n.FRAMEBUFFER,Ye.frameBuffer),n.readPixels(0,0,A,I,B,O,P);let Q=0,ze=0;if(U){for(let Pe=0,As=0;Pe<T;++Pe,As+=4)Q+=P[As];ze=Q/T}else{for(let Pe=0;Pe<T;++Pe)Q+=P[Pe];ze=Q/T/255}n.bindFramebuffer(n.FRAMEBUFFER,null),(ze<_||$e>=v2)&&(Kt=!0),$e++}return n.bindBuffer(n.ARRAY_BUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,null),n.bindVertexArray(null),{texture:st,width:e,height:r}},release:()=>{n.deleteBuffer(f),n.deleteBuffer(d),n.deleteTexture(F),n.deleteTexture(N),n.deleteFramebuffer(D),n.deleteFramebuffer(j),n.deleteVertexArray(c),R.release(),l()}}};var yh=`#version 300 es
61
61
  #ifdef GL_FRAGMENT_PRECISION_HIGH
62
62
  precision highp float;
63
63
  #else
64
64
  precision mediump float;
65
65
  #endif
66
- in vec2 v_texCoord;uniform sampler2D u_frame_input;uniform sampler2D u_frame_guide;uniform vec2 u_texel_size;uniform float u_sigma_space;uniform float u_sigma_range_lo;uniform float u_sigma_range_hi;uniform float u_background_threshold;uniform float u_foreground_threshold;const float kSparsityFactor=0.66;const float FOREGROUND_BIAS=1.3;const float EDGE_THRESHOLD=0.08;const int MAX_RADIUS=32;out vec4 outColor;float gaussian_sqr(float dist2,float sigma2){float denom=max(sigma2,1.0e-6);float coeff=-0.5/denom;return exp(dist2*coeff);}vec2 clamp_uv(vec2 uv){vec2 eps=vec2(1.0e-6);return clamp(uv,eps,vec2(1.0)-eps);}void main(){vec2 center_uv=v_texCoord;vec3 center_val=texture(u_frame_guide,center_uv).rgb;float center_mask=texture(u_frame_input,center_uv).r;float sparsity=max(1.0,sqrt(u_sigma_space)*kSparsityFactor);mediump vec3 new_val=vec3(0.0);mediump float total_weight=0.0;float t=smoothstep(u_background_threshold,u_foreground_threshold,center_mask);float sigma_color=mix(u_sigma_range_lo,u_sigma_range_hi,t);float sigma_texel=max(u_texel_size.x,u_texel_size.y)*u_sigma_space;float sigma_texel2=sigma_texel*sigma_texel;float sigma_color2=sigma_color*sigma_color;int radiusI=int(floor(u_sigma_space+0.5));int stepI=max(1,int(floor(sparsity+0.5)));int offsetI=(stepI>1)?(stepI/2):0;for(int iy=-MAX_RADIUS;iy<=MAX_RADIUS;++iy){if(abs(iy)>radiusI)continue;int iyAligned=(iy+offsetI);if((iyAligned % stepI)!=0)continue;float fy=float(iy)*u_texel_size.y;float row_iy2=fy*fy;for(int jx=-MAX_RADIUS;jx<=MAX_RADIUS;++jx){if(abs(jx)>radiusI)continue;int jxAligned=(jx+offsetI);if((jxAligned % stepI)!=0)continue;float fx=float(jx)*u_texel_size.x;vec2 uv=clamp_uv(center_uv+vec2(fx,fy));vec3 guide_val=texture(u_frame_guide,uv).rgb;vec3 out_val=texture(u_frame_input,uv).rgb;float dist2_uv=fx*fx+row_iy2;float space_weight=gaussian_sqr(dist2_uv,sigma_texel2);float l_center=dot(center_val,vec3(0.299,0.587,0.114));float l_guide=dot(guide_val,vec3(0.299,0.587,0.114));float dL=abs(l_guide-l_center);if(dL>EDGE_THRESHOLD){continue;}float color_weight=gaussian_sqr(dL*dL,sigma_color2);float fg_w=mix(1.0,FOREGROUND_BIAS,center_mask);float w=space_weight*color_weight*fg_w;total_weight+=w;new_val+=w*out_val;}}new_val*=1.0/max(total_weight,1.0e-6);outColor=vec4(new_val,1.0);}`;var $o=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,release:i}=fe(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{frameGuide:"u_frame_guide",frameInput:"u_frame_input",matrix:"u_matrix",texelSize:"u_texel_size",sigmaSpace:"u_sigma_space",sigmaRangeLo:"u_sigma_range_lo",sigmaRangeHi:"u_sigma_range_hi",foregroundThreshold:"u_foreground_threshold",backgroundThreshold:"u_background_threshold"},vertexSrc:he,fragmentSrc:Mh});n.enable(n.BLEND);let u=n.createVertexArray();n.bindVertexArray(u);let l=n.createBuffer();n.enableVertexAttribArray(o.position),n.bindBuffer(n.ARRAY_BUFFER,l),n.vertexAttribPointer(o.position,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW);let c=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,c),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW),n.enableVertexAttribArray(o.texCoord),n.vertexAttribPointer(o.texCoord,2,n.FLOAT,!1,0,0);let f=_e(n,e,r),d=ae(n,f),p=t.width/e;return{render:({input:T,guide:A},E)=>{F(!n.isContextLost(),M.ContextLost),F(E.foregroundThreshold>=E.backgroundThreshold,"foregroundThreshold must be >= backgroundThreshold"),n.bindFramebuffer(n.FRAMEBUFFER,d),n.viewport(0,0,e,r),n.useProgram(s),n.bindVertexArray(u),n.activeTexture(n.TEXTURE0),n.uniform1i(a.frameInput,0),n.bindTexture(n.TEXTURE_2D,T.texture),n.activeTexture(n.TEXTURE1),n.uniform1i(a.frameGuide,1),n.bindTexture(n.TEXTURE_2D,A.texture),n.uniform2f(a.texelSize,1/T.width,1/T.height),n.uniform1f(a.sigmaSpace,E.sigmaSpace/p),n.uniform1f(a.sigmaRangeLo,E.sigmaRangeLo),n.uniform1f(a.sigmaRangeHi,E.sigmaRangeHi),n.uniform1f(a.backgroundThreshold,E.backgroundThreshold),n.uniform1f(a.foregroundThreshold,E.foregroundThreshold);let I=Z.projection(1,1,1);return n.uniformMatrix3fv(a.matrix,!1,I),n.drawArrays(n.TRIANGLES,0,6),n.bindBuffer(n.ARRAY_BUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,null),n.bindVertexArray(null),{texture:f,width:e,height:r}},release:()=>{n.deleteBuffer(l),n.deleteBuffer(c),n.deleteTexture(f),n.deleteFramebuffer(d),n.deleteVertexArray(u),i()}}};var Nh=`#version 300 es
67
- precision mediump float;uniform sampler2D u_mask;uniform vec2 u_texel_size;uniform vec2 u_direction;uniform int u_radius_px;const int MAX_RADIUS_PX=64;in vec2 v_texCoord;out vec4 outColor;void main(){float mn=1.0;for(int i=-MAX_RADIUS_PX;i<=MAX_RADIUS_PX;++i){if(abs(i)>u_radius_px)continue;vec2 off=u_direction*float(i)*u_texel_size;mn=min(mn,texture(u_mask,v_texCoord+off).r);}outColor=vec4(mn,mn,mn,1.0);}`;var Tp=64,kp=At(0,Tp),bu=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatSingleChannelSupported:i,floatFullChannelSupported:u,release:l}=fe(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",mask:"u_mask",texelSize:"u_texel_size",radiusPx:"u_radius_px",direction:"u_direction"},vertexSrc:he,fragmentSrc:Nh}),c=n.createVertexArray();n.bindVertexArray(c);let f=n.createBuffer();n.enableVertexAttribArray(o.position),n.bindBuffer(n.ARRAY_BUFFER,f),n.vertexAttribPointer(o.position,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW);let d=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,d),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW),n.enableVertexAttribArray(o.texCoord),n.vertexAttribPointer(o.texCoord,2,n.FLOAT,!1,0,0);let p=_e(n,e,r,!1,i,u),T=ae(n,p),A=_e(n,e,r,!1,i,u),E=ae(n,A),I=t.width/e;return{render:({mask:_},v)=>{F(!n.isContextLost(),M.ContextLost),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(s),n.bindVertexArray(c),n.uniform2f(a.texelSize,1/_.width,1/_.height),n.uniform1i(a.radiusPx,kp(Math.floor(v.morphErodeRadiusPx/I)));let R=Z.projection(1,1,1);n.uniformMatrix3fv(a.matrix,!1,R);let U=T,C=_.texture;for(let O=0;O<v.morphPass;O++)for(let L=0;L<2;L++)n.activeTexture(n.TEXTURE0),n.uniform1i(a.mask,0),n.bindTexture(n.TEXTURE_2D,C),n.uniform2f(a.direction,1-L,0+L),n.bindFramebuffer(n.FRAMEBUFFER,U),n.viewport(0,0,_.width,_.height),n.drawArrays(n.TRIANGLES,0,6),[C,U]=U===T?[p,E]:[A,T];return n.bindBuffer(n.ARRAY_BUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,null),n.bindVertexArray(null),{texture:C,width:e,height:r}},release:()=>{n.deleteBuffer(f),n.deleteBuffer(d),n.deleteTexture(p),n.deleteTexture(A),n.deleteFramebuffer(T),n.deleteFramebuffer(E),n.deleteVertexArray(c),l()}}};var Gh=`#version 300 es
68
- precision mediump float;uniform sampler2D u_mask;uniform sampler2D u_frame_foreground;uniform sampler2D u_frame_background;uniform sampler2D u_blur_background;uniform vec2 u_confidence_thresholds;uniform float u_light_wrap;uniform float u_light_wrap_tightness;uniform float u_edge_band;uniform float u_parity;uniform float u_time;uniform vec2 u_frame_size;in vec2 v_texCoord;out vec4 outColor;const float NOISE_LUMA=2.0/255.0;float hash12(vec2 p){vec3 p3=fract(vec3(p.xyx)*0.1031);p3+=dot(p3,p3.yzx+33.33);return fract((p3.x+p3.y)*p3.z);}vec3 rgb2yuv(vec3 rgb){float Y=dot(rgb,vec3(0.299,0.587,0.114));float U=dot(rgb,vec3(-0.168736,-0.331264,0.5));float V=dot(rgb,vec3(0.5,-0.418688,-0.081312));return vec3(Y,U,V);}vec3 yuv2rgb(vec3 yuv){float Y=yuv.x,U=yuv.y,V=yuv.z;vec3 rgb;rgb.r=Y+1.402*V;rgb.g=Y-0.344136*U-0.714136*V;rgb.b=Y+1.772*U;return rgb;}void main(){vec3 background=texture(u_frame_background,v_texCoord).rgb;vec3 foreground=texture(u_frame_foreground,v_texCoord).rgb;vec3 blur_background=texture(u_blur_background,v_texCoord).rgb;float person_mask=texture(u_mask,v_texCoord).r;float bg=u_confidence_thresholds.x;float fg=u_confidence_thresholds.y;float maskFg=smoothstep(bg,fg,person_mask);float edgeBg=smoothstep(bg,bg+u_edge_band,person_mask);float edgeFg=1.0-smoothstep(fg-u_edge_band,fg,person_mask);edgeBg=pow(edgeBg,u_light_wrap_tightness);edgeFg=pow(edgeFg,u_light_wrap_tightness);float maskBg=1.0-maskFg;vec2 pixelCoord=floor(v_texCoord*u_frame_size);float noiseY=hash12(pixelCoord+vec2(u_time,0.0))-0.5;noiseY*=NOISE_LUMA*u_parity;float noiseWeight=clamp(maskBg+edgeBg*maskFg,0.0,1.0);vec3 yuv=rgb2yuv(background);yuv.x=clamp(yuv.x+noiseY*noiseWeight,0.0,1.0);background=yuv2rgb(yuv);vec3 bgSmooth=mix(background,blur_background,u_light_wrap*edgeBg);vec3 wrapColor=mix(foreground,blur_background,u_light_wrap);vec3 fgSmooth=mix(foreground,wrapColor,edgeFg);vec3 composite=mix(bgSmooth,fgSmooth,maskFg);outColor=vec4(composite,1.0);}`;var Vh=t=>{let{gl:e,program:r,attribLocations:n,floatFullChannelSupported:s,uniformLocations:o,release:a}=fe(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",frameBackground:"u_frame_background",frameForeground:"u_frame_foreground",blurBackground:"u_blur_background",mask:"u_mask",confidenceThresholds:"u_confidence_thresholds",lightWrap:"u_light_wrap",lightWrapTightness:"u_light_wrap_tightness",lightWrapEdgeBand:"u_edge_band",time:"u_time",parity:"u_parity",frameSize:"u_frame_size"},vertexSrc:he,fragmentSrc:Gh});e.enable(e.BLEND);let i=e.createVertexArray();e.bindVertexArray(i);let u=e.createBuffer();e.enableVertexAttribArray(n.position),e.bindBuffer(e.ARRAY_BUFFER,u),e.vertexAttribPointer(n.position,2,e.FLOAT,!1,0,0),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),e.STATIC_DRAW);let l=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,l),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),e.STATIC_DRAW),e.enableVertexAttribArray(n.texCoord),e.vertexAttribPointer(n.texCoord,2,e.FLOAT,!1,0,0);let c=Vt(e,t.width,t.height,!0,s),f=ae(e,c),d=-1;return{render:({mask:p,foreground:T,background:A,blurredBackground:E,timestamp:I},_)=>{F(!e.isContextLost(),M.ContextLost),e.bindFramebuffer(e.FRAMEBUFFER,f),e.viewport(0,0,t.width,t.height),e.useProgram(r),e.bindVertexArray(i),e.activeTexture(e.TEXTURE0),e.uniform1i(o.frameForeground,0),e.bindTexture(e.TEXTURE_2D,T.texture),e.activeTexture(e.TEXTURE1),e.uniform1i(o.frameBackground,1),e.bindTexture(e.TEXTURE_2D,A.texture),e.activeTexture(e.TEXTURE2),e.uniform1i(o.mask,2),e.bindTexture(e.TEXTURE_2D,p.texture),e.activeTexture(e.TEXTURE3),e.uniform1i(o.blurBackground,3),e.bindTexture(e.TEXTURE_2D,E.texture),e.uniform2f(o.confidenceThresholds,_.backgroundThreshold,_.foregroundThreshold),e.uniform1f(o.lightWrap,_.lightWrapIntensity),e.uniform1f(o.lightWrapTightness,_.lightWrapTightness),e.uniform1f(o.lightWrapEdgeBand,_.lightWrapEdgeBand),d=-d,e.uniform1f(o.parity,d),e.uniform1f(o.time,I*1e-6%1024),e.uniform2f(o.frameSize,t.width,t.height);let v=Z.projection(1,1,1);return e.uniformMatrix3fv(o.matrix,!1,v),e.drawArrays(e.TRIANGLES,0,6),e.bindBuffer(e.ARRAY_BUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),e.bindVertexArray(null),{texture:c,width:t.width,height:t.height}},release:()=>{e.deleteBuffer(u),e.deleteBuffer(l),e.deleteTexture(c),e.deleteFramebuffer(f),e.deleteVertexArray(i),a()}}};var Wh=`#version 300 es
66
+ in vec2 v_texCoord;uniform sampler2D u_frame_input;uniform sampler2D u_frame_guide;uniform vec2 u_texel_size;uniform float u_sigma_space;uniform float u_sigma_range_lo;uniform float u_sigma_range_hi;uniform float u_background_threshold;uniform float u_foreground_threshold;const float kSparsityFactor=0.66;const float FOREGROUND_BIAS=1.3;const float EDGE_THRESHOLD=0.08;const int MAX_RADIUS=32;out vec4 outColor;float gaussian_sqr(float dist2,float sigma2){float denom=max(sigma2,1.0e-6);float coeff=-0.5/denom;return exp(dist2*coeff);}vec2 clamp_uv(vec2 uv){vec2 eps=vec2(1.0e-6);return clamp(uv,eps,vec2(1.0)-eps);}void main(){vec2 center_uv=v_texCoord;vec3 center_val=texture(u_frame_guide,center_uv).rgb;float center_mask=texture(u_frame_input,center_uv).r;float sparsity=max(1.0,sqrt(u_sigma_space)*kSparsityFactor);mediump vec3 new_val=vec3(0.0);mediump float total_weight=0.0;float t=smoothstep(u_background_threshold,u_foreground_threshold,center_mask);float sigma_color=mix(u_sigma_range_lo,u_sigma_range_hi,t);float sigma_texel=max(u_texel_size.x,u_texel_size.y)*u_sigma_space;float sigma_texel2=sigma_texel*sigma_texel;float sigma_color2=sigma_color*sigma_color;int radiusI=int(floor(u_sigma_space+0.5));int stepI=max(1,int(floor(sparsity+0.5)));int offsetI=(stepI>1)?(stepI/2):0;for(int iy=-MAX_RADIUS;iy<=MAX_RADIUS;++iy){if(abs(iy)>radiusI)continue;int iyAligned=(iy+offsetI);if((iyAligned % stepI)!=0)continue;float fy=float(iy)*u_texel_size.y;float row_iy2=fy*fy;for(int jx=-MAX_RADIUS;jx<=MAX_RADIUS;++jx){if(abs(jx)>radiusI)continue;int jxAligned=(jx+offsetI);if((jxAligned % stepI)!=0)continue;float fx=float(jx)*u_texel_size.x;vec2 uv=clamp_uv(center_uv+vec2(fx,fy));vec3 guide_val=texture(u_frame_guide,uv).rgb;vec3 out_val=texture(u_frame_input,uv).rgb;float dist2_uv=fx*fx+row_iy2;float space_weight=gaussian_sqr(dist2_uv,sigma_texel2);float l_center=dot(center_val,vec3(0.299,0.587,0.114));float l_guide=dot(guide_val,vec3(0.299,0.587,0.114));float dL=abs(l_guide-l_center);if(dL>EDGE_THRESHOLD){continue;}float color_weight=gaussian_sqr(dL*dL,sigma_color2);float fg_w=mix(1.0,FOREGROUND_BIAS,center_mask);float w=space_weight*color_weight*fg_w;total_weight+=w;new_val+=w*out_val;}}new_val*=1.0/max(total_weight,1.0e-6);outColor=vec4(new_val,1.0);}`;var ua=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,release:i}=de(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{frameGuide:"u_frame_guide",frameInput:"u_frame_input",matrix:"u_matrix",texelSize:"u_texel_size",sigmaSpace:"u_sigma_space",sigmaRangeLo:"u_sigma_range_lo",sigmaRangeHi:"u_sigma_range_hi",foregroundThreshold:"u_foreground_threshold",backgroundThreshold:"u_background_threshold"},vertexSrc:he,fragmentSrc:yh});n.enable(n.BLEND);let u=n.createVertexArray();n.bindVertexArray(u);let l=n.createBuffer();n.enableVertexAttribArray(o.position),n.bindBuffer(n.ARRAY_BUFFER,l),n.vertexAttribPointer(o.position,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW);let c=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,c),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW),n.enableVertexAttribArray(o.texCoord),n.vertexAttribPointer(o.texCoord,2,n.FLOAT,!1,0,0);let f=be(n,e,r),d=ae(n,f),p=t.width/e;return{render:({input:b,guide:E},A)=>{C(!n.isContextLost(),M.ContextLost),C(A.foregroundThreshold>=A.backgroundThreshold,"foregroundThreshold must be >= backgroundThreshold"),n.bindFramebuffer(n.FRAMEBUFFER,d),n.viewport(0,0,e,r),n.useProgram(s),n.bindVertexArray(u),n.activeTexture(n.TEXTURE0),n.uniform1i(a.frameInput,0),n.bindTexture(n.TEXTURE_2D,b.texture),n.activeTexture(n.TEXTURE1),n.uniform1i(a.frameGuide,1),n.bindTexture(n.TEXTURE_2D,E.texture),n.uniform2f(a.texelSize,1/b.width,1/b.height),n.uniform1f(a.sigmaSpace,A.sigmaSpace/p),n.uniform1f(a.sigmaRangeLo,A.sigmaRangeLo),n.uniform1f(a.sigmaRangeHi,A.sigmaRangeHi),n.uniform1f(a.backgroundThreshold,A.backgroundThreshold),n.uniform1f(a.foregroundThreshold,A.foregroundThreshold);let I=Z.projection(1,1,1);return n.uniformMatrix3fv(a.matrix,!1,I),n.drawArrays(n.TRIANGLES,0,6),n.bindBuffer(n.ARRAY_BUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,null),n.bindVertexArray(null),{texture:f,width:e,height:r}},release:()=>{n.deleteBuffer(l),n.deleteBuffer(c),n.deleteTexture(f),n.deleteFramebuffer(d),n.deleteVertexArray(u),i()}}};var xh=`#version 300 es
67
+ precision mediump float;uniform sampler2D u_mask;uniform vec2 u_texel_size;uniform vec2 u_direction;uniform int u_radius_px;const int MAX_RADIUS_PX=64;in vec2 v_texCoord;out vec4 outColor;void main(){float mn=1.0;for(int i=-MAX_RADIUS_PX;i<=MAX_RADIUS_PX;++i){if(abs(i)>u_radius_px)continue;vec2 off=u_direction*float(i)*u_texel_size;mn=min(mn,texture(u_mask,v_texCoord+off).r);}outColor=vec4(mn,mn,mn,1.0);}`;var k2=64,E2=Ut(0,k2),Hu=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatSingleChannelSupported:i,floatFullChannelSupported:u,release:l}=de(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",mask:"u_mask",texelSize:"u_texel_size",radiusPx:"u_radius_px",direction:"u_direction"},vertexSrc:he,fragmentSrc:xh}),c=n.createVertexArray();n.bindVertexArray(c);let f=n.createBuffer();n.enableVertexAttribArray(o.position),n.bindBuffer(n.ARRAY_BUFFER,f),n.vertexAttribPointer(o.position,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW);let d=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,d),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW),n.enableVertexAttribArray(o.texCoord),n.vertexAttribPointer(o.texCoord,2,n.FLOAT,!1,0,0);let p=be(n,e,r,!1,i,u),b=ae(n,p),E=be(n,e,r,!1,i,u),A=ae(n,E),I=t.width/e;return{render:({mask:_},T)=>{C(!n.isContextLost(),M.ContextLost),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(s),n.bindVertexArray(c),n.uniform2f(a.texelSize,1/_.width,1/_.height),n.uniform1i(a.radiusPx,E2(Math.floor(T.morphErodeRadiusPx/I)));let R=Z.projection(1,1,1);n.uniformMatrix3fv(a.matrix,!1,R);let U=b,B=_.texture;for(let O=0;O<T.morphPass;O++)for(let P=0;P<2;P++)n.activeTexture(n.TEXTURE0),n.uniform1i(a.mask,0),n.bindTexture(n.TEXTURE_2D,B),n.uniform2f(a.direction,1-P,0+P),n.bindFramebuffer(n.FRAMEBUFFER,U),n.viewport(0,0,_.width,_.height),n.drawArrays(n.TRIANGLES,0,6),[B,U]=U===b?[p,A]:[E,b];return n.bindBuffer(n.ARRAY_BUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,null),n.bindVertexArray(null),{texture:B,width:e,height:r}},release:()=>{n.deleteBuffer(f),n.deleteBuffer(d),n.deleteTexture(p),n.deleteTexture(E),n.deleteFramebuffer(b),n.deleteFramebuffer(A),n.deleteVertexArray(c),l()}}};var _h=`#version 300 es
68
+ precision mediump float;uniform sampler2D u_mask;uniform sampler2D u_frame_foreground;uniform sampler2D u_frame_background;uniform sampler2D u_blur_background;uniform vec2 u_confidence_thresholds;uniform float u_light_wrap;uniform float u_light_wrap_tightness;uniform float u_edge_band;uniform float u_parity;uniform float u_time;uniform vec2 u_frame_size;in vec2 v_texCoord;out vec4 outColor;const float NOISE_LUMA=2.0/255.0;float hash12(vec2 p){vec3 p3=fract(vec3(p.xyx)*0.1031);p3+=dot(p3,p3.yzx+33.33);return fract((p3.x+p3.y)*p3.z);}vec3 rgb2yuv(vec3 rgb){float Y=dot(rgb,vec3(0.299,0.587,0.114));float U=dot(rgb,vec3(-0.168736,-0.331264,0.5));float V=dot(rgb,vec3(0.5,-0.418688,-0.081312));return vec3(Y,U,V);}vec3 yuv2rgb(vec3 yuv){float Y=yuv.x,U=yuv.y,V=yuv.z;vec3 rgb;rgb.r=Y+1.402*V;rgb.g=Y-0.344136*U-0.714136*V;rgb.b=Y+1.772*U;return rgb;}void main(){vec3 background=texture(u_frame_background,v_texCoord).rgb;vec3 foreground=texture(u_frame_foreground,v_texCoord).rgb;vec3 blur_background=texture(u_blur_background,v_texCoord).rgb;float person_mask=texture(u_mask,v_texCoord).r;float bg=u_confidence_thresholds.x;float fg=u_confidence_thresholds.y;float maskFg=smoothstep(bg,fg,person_mask);float edgeBg=smoothstep(bg,bg+u_edge_band,person_mask);float edgeFg=1.0-smoothstep(fg-u_edge_band,fg,person_mask);edgeBg=pow(edgeBg,u_light_wrap_tightness);edgeFg=pow(edgeFg,u_light_wrap_tightness);float maskBg=1.0-maskFg;vec2 pixelCoord=floor(v_texCoord*u_frame_size);float noiseY=hash12(pixelCoord+vec2(u_time,0.0))-0.5;noiseY*=NOISE_LUMA*u_parity;float noiseWeight=clamp(maskBg+edgeBg*maskFg,0.0,1.0);vec3 yuv=rgb2yuv(background);yuv.x=clamp(yuv.x+noiseY*noiseWeight,0.0,1.0);background=yuv2rgb(yuv);vec3 bgSmooth=mix(background,blur_background,u_light_wrap*edgeBg);vec3 wrapColor=mix(foreground,blur_background,u_light_wrap);vec3 fgSmooth=mix(foreground,wrapColor,edgeFg);vec3 composite=mix(bgSmooth,fgSmooth,maskFg);outColor=vec4(composite,1.0);}`;var bh=t=>{let{gl:e,program:r,attribLocations:n,floatFullChannelSupported:s,uniformLocations:o,release:a}=de(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",frameBackground:"u_frame_background",frameForeground:"u_frame_foreground",blurBackground:"u_blur_background",mask:"u_mask",confidenceThresholds:"u_confidence_thresholds",lightWrap:"u_light_wrap",lightWrapTightness:"u_light_wrap_tightness",lightWrapEdgeBand:"u_edge_band",time:"u_time",parity:"u_parity",frameSize:"u_frame_size"},vertexSrc:he,fragmentSrc:_h});e.enable(e.BLEND);let i=e.createVertexArray();e.bindVertexArray(i);let u=e.createBuffer();e.enableVertexAttribArray(n.position),e.bindBuffer(e.ARRAY_BUFFER,u),e.vertexAttribPointer(n.position,2,e.FLOAT,!1,0,0),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),e.STATIC_DRAW);let l=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,l),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),e.STATIC_DRAW),e.enableVertexAttribArray(n.texCoord),e.vertexAttribPointer(n.texCoord,2,e.FLOAT,!1,0,0);let c=Yt(e,t.width,t.height,!0,s),f=ae(e,c),d=-1;return{render:({mask:p,foreground:b,background:E,blurredBackground:A,timestamp:I},_)=>{C(!e.isContextLost(),M.ContextLost),e.bindFramebuffer(e.FRAMEBUFFER,f),e.viewport(0,0,t.width,t.height),e.useProgram(r),e.bindVertexArray(i),e.activeTexture(e.TEXTURE0),e.uniform1i(o.frameForeground,0),e.bindTexture(e.TEXTURE_2D,b.texture),e.activeTexture(e.TEXTURE1),e.uniform1i(o.frameBackground,1),e.bindTexture(e.TEXTURE_2D,E.texture),e.activeTexture(e.TEXTURE2),e.uniform1i(o.mask,2),e.bindTexture(e.TEXTURE_2D,p.texture),e.activeTexture(e.TEXTURE3),e.uniform1i(o.blurBackground,3),e.bindTexture(e.TEXTURE_2D,A.texture),e.uniform2f(o.confidenceThresholds,_.backgroundThreshold,_.foregroundThreshold),e.uniform1f(o.lightWrap,_.lightWrapIntensity),e.uniform1f(o.lightWrapTightness,_.lightWrapTightness),e.uniform1f(o.lightWrapEdgeBand,_.lightWrapEdgeBand),d=-d,e.uniform1f(o.parity,d),e.uniform1f(o.time,I*1e-6%1024),e.uniform2f(o.frameSize,t.width,t.height);let T=Z.projection(1,1,1);return e.uniformMatrix3fv(o.matrix,!1,T),e.drawArrays(e.TRIANGLES,0,6),e.bindBuffer(e.ARRAY_BUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),e.bindVertexArray(null),{texture:c,width:t.width,height:t.height}},release:()=>{e.deleteBuffer(u),e.deleteBuffer(l),e.deleteTexture(c),e.deleteFramebuffer(f),e.deleteVertexArray(i),a()}}};var vh=`#version 300 es
69
69
  #ifdef GL_FRAGMENT_PRECISION_HIGH
70
70
  precision highp float;
71
71
  #else
72
72
  precision mediump float;
73
73
  #endif
74
- uniform sampler2D u_mask;uniform sampler2D u_mask_prev;uniform float u_mask_combine_ratio;in vec2 v_texCoord;out vec4 outColor;float maskUncertainty(float p){const float c1=5.68842;const float c2=-0.748699;const float c3=-57.8051;const float c4=291.309;const float c5=-624.717;float t=p-0.5;float x=t*t;float uncertainty=1.0-min(1.0,x*(c1+x*(c2+x*(c3+x*(c4+x*c5)))));return uncertainty;}void main(){float current_mask=texture(u_mask,v_texCoord).r;float prev_mask=texture(u_mask_prev,v_texCoord).r;float uncertainty=maskUncertainty(current_mask);float alpha=uncertainty*u_mask_combine_ratio;float stabilized=current_mask+(prev_mask-current_mask)*alpha;outColor=vec4(stabilized,stabilized,stabilized,1.0);}`;var vu=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatFullChannelSupported:i,floatSingleChannelSupported:u,release:l}=fe(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",mask:"u_mask",prevMask:"u_mask_prev",frame:"u_frame",prevFrame:"u_frame_prev",maskCombineRatio:"u_mask_combine_ratio"},vertexSrc:he,fragmentSrc:Wh}),c=n.createVertexArray();n.bindVertexArray(c);let f=n.createBuffer();n.enableVertexAttribArray(o.position),n.bindBuffer(n.ARRAY_BUFFER,f),n.vertexAttribPointer(o.position,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW);let d=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,d),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW),n.enableVertexAttribArray(o.texCoord),n.vertexAttribPointer(o.texCoord,2,n.FLOAT,!1,0,0);let p=_e(n,e,r,!1,u,i),T=ae(n,p);return{render:({mask:A,prevMask:E},I)=>{F(!n.isContextLost(),M.ContextLost),n.bindFramebuffer(n.FRAMEBUFFER,T),n.viewport(0,0,A.width,A.height),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(s),n.bindVertexArray(c),n.activeTexture(n.TEXTURE0),n.uniform1i(a.mask,0),n.bindTexture(n.TEXTURE_2D,A.texture),n.activeTexture(n.TEXTURE1),n.uniform1i(a.prevMask,1),n.bindTexture(n.TEXTURE_2D,E.texture);let _=Z.projection(1,1,1);return n.uniformMatrix3fv(a.matrix,!1,_),n.uniform1f(a.maskCombineRatio,I.maskCombineRatio),n.drawArrays(n.TRIANGLES,0,6),n.bindBuffer(n.ARRAY_BUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,null),n.bindVertexArray(null),{texture:p,width:e,height:r}},release:()=>{n.deleteBuffer(f),n.deleteBuffer(d),n.deleteTexture(p),n.deleteFramebuffer(T),n.deleteVertexArray(c),l()}}};var $h=`#version 300 es
75
- precision mediump float;uniform sampler2D u_mask;uniform vec2 u_texel_size;uniform vec2 u_direction;uniform int u_radius_px;const int MAX_RADIUS_PX=16;in vec2 v_texCoord;out vec4 outColor;void main(){int R=clamp(u_radius_px,0,MAX_RADIUS_PX);if(R==0){float m=texture(u_mask,v_texCoord).r;outColor=vec4(m,m,m,1.0);return;}float sumW=0.0;float acc=0.0;for(int i=-MAX_RADIUS_PX;i<=MAX_RADIUS_PX;++i){if(abs(i)>R)continue;float w=float(R+1-abs(i));vec2 off=u_direction*float(i)*u_texel_size;float s=texture(u_mask,v_texCoord+off).r;acc+=w*s;sumW+=w;}float m=acc/max(sumW,1.0e-6);outColor=vec4(m,m,m,1.0);}`;var Ep=16,Ap=At(0,Ep),zh=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatSingleChannelSupported:i,floatFullChannelSupported:u,release:l}=fe(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",mask:"u_mask",texelSize:"u_texel_size",direction:"u_direction",radiusPx:"u_radius_px"},vertexSrc:he,fragmentSrc:$h}),c=n.createVertexArray();n.bindVertexArray(c);let f=n.createBuffer();n.enableVertexAttribArray(o.position),n.bindBuffer(n.ARRAY_BUFFER,f),n.vertexAttribPointer(o.position,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW);let d=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,d),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW),n.enableVertexAttribArray(o.texCoord),n.vertexAttribPointer(o.texCoord,2,n.FLOAT,!1,0,0);let p=_e(n,e,r,!1,i,u),T=ae(n,p),A=_e(n,e,r,!1,i,u),E=ae(n,A),I=t.width/e;return{render:(_,v)=>{F(!n.isContextLost(),M.ContextLost),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(s),n.bindVertexArray(c),n.uniform2f(a.texelSize,1/_.width,1/_.height),n.uniform1i(a.radiusPx,Ap(Math.floor(v/I)));let R=Z.projection(1,1,1);n.uniformMatrix3fv(a.matrix,!1,R);let U=T,C=_.texture;for(let O=0;O<2;O++)n.activeTexture(n.TEXTURE0),n.uniform1i(a.mask,0),n.bindTexture(n.TEXTURE_2D,C),n.uniform2f(a.direction,1-O,0+O),n.bindFramebuffer(n.FRAMEBUFFER,U),n.viewport(0,0,_.width,_.height),n.drawArrays(n.TRIANGLES,0,6),[C,U]=U===T?[p,E]:[A,T];return n.bindBuffer(n.ARRAY_BUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,null),n.bindVertexArray(null),{texture:C,width:e,height:r}},release:()=>{n.deleteBuffer(f),n.deleteBuffer(d),n.deleteTexture(p),n.deleteTexture(A),n.deleteFramebuffer(T),n.deleteFramebuffer(E),n.deleteVertexArray(c),l()}}};var zo=(t,e)=>{let{gl:r,program:n,attribLocations:s,uniformLocations:o,floatFullChannelSupported:a,floatSingleChannelSupported:i,release:u}=fe(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",texture:"u_texture"},vertexSrc:he,fragmentSrc:An}),l=r.createVertexArray();r.bindVertexArray(l);let c=r.createBuffer();r.enableVertexAttribArray(s.position),r.bindBuffer(r.ARRAY_BUFFER,c),r.vertexAttribPointer(s.position,2,r.FLOAT,!1,0,0),r.bufferData(r.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),r.STATIC_DRAW);let f=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,f),r.bufferData(r.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),r.STATIC_DRAW),r.enableVertexAttribArray(s.texCoord),r.vertexAttribPointer(s.texCoord,2,r.FLOAT,!1,0,0);let d=Vt(r,t.width,t.height,!0,a),p=e?_e(r,t.width,t.height,!1,i,a):Vt(r,t.width,t.height,!0,a),T=ae(r,p);return{render:A=>{F(!r.isContextLost(),M.ContextLost),r.bindFramebuffer(r.FRAMEBUFFER,T),r.viewport(0,0,t.width,t.height),r.clearColor(0,0,0,1),r.clear(r.COLOR_BUFFER_BIT),r.useProgram(n),r.bindVertexArray(l),r.uniform1i(o.texture,0);let E=Z.projection(1,1,1);return r.uniformMatrix3fv(o.matrix,!1,E),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,d),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,A),r.drawArrays(r.TRIANGLES,0,6),r.bindBuffer(r.ARRAY_BUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindTexture(r.TEXTURE_2D,null),r.bindVertexArray(null),{texture:p,width:t.width,height:t.height}},release:()=>{r.deleteBuffer(c),r.deleteBuffer(f),r.deleteTexture(d),r.deleteTexture(p),r.deleteVertexArray(l),u()}}};var Hh=(t,e=new OffscreenCanvas(Rr,Ar))=>{let r=Math.trunc(e.width/2),n=Math.trunc(e.height/2),s=Math.trunc(e.width/4),o=Math.trunc(e.height/4),a=32,i=18,u={backgroundImageRenderer:()=>zo(e,!1),blendRenderer:()=>Fh(e),blurRenderer:()=>Vo(e),canvasRenderer:()=>Wo(e),frameDownsampler2:()=>Ft(e,!1,!0,r,n),frameDownsampler4:()=>Ft(e,!1,!0,s,o),geodesicReconstructionRenderer2:()=>_u(e,r,n),geodesicReconstructionRenderer4:()=>_u(e,s,o),jointBilateralFilterRenderer2:()=>$o(e,r,n),jointBilateralFilterRenderer4:()=>$o(e,s,o),jointBilateralFilterRenderer:()=>$o(e,e.width,e.height),lightWrapBlurRenderer:()=>Vo(e),maskBlurRenderer:()=>zh(e,e.width,e.height),strongMaskBlurRenderer:()=>Vo(e),maskDownsampler2:()=>Ft(e,!0,!1,r,n),maskDownsampler4:()=>Ft(e,!0,!1,s,o),maskRenderer:()=>zo(e,!0),maskUpsampler2:()=>Ft(e,!0,!1,r,n),maskUpsampler4:()=>Ft(e,!0,!1,s,o),maskUpsampler:()=>Ft(e,!0,!1,e.width,e.height),morphErodeRenderer:()=>bu(e,r,n),morphErodeRenderer4:()=>bu(e,s,o),prevMaskRenderer2:()=>Ft(e,!0,!1,r,n),prevMaskRenderer4:()=>Ft(e,!0,!1,s,o),replaceRenderer:()=>Vh(e),selectCenterComponent:()=>Lh(e,a,i),smoothingMaskRenderer4:()=>vu(e,s,o),smoothingMaskRenderer2:()=>vu(e,r,n),binaryMaskRenderer2:()=>yu(e,r,n),binaryMaskRenderer4:()=>yu(e,s,o),videoFrameRenderer:()=>zo(e,!1),release:E=>()=>{for(let I in E)I!=="release"&&E[I]?.release()}},l=xn(u),c={canvas:e,gl:null,canvasContextEventsCleanup:()=>{},get videoFrameRenderer(){return l.videoFrameRenderer},get jointBilateralFilterRenderer(){return l.jointBilateralFilterRenderer},get jointBilateralFilterRenderer2(){return l.jointBilateralFilterRenderer2},get jointBilateralFilterRenderer4(){return l.jointBilateralFilterRenderer4},get maskRenderer(){return l.maskRenderer},get canvasRenderer(){return l.canvasRenderer},get backgroundImageRenderer(){return l.backgroundImageRenderer},get blendRenderer(){return l.blendRenderer},get replaceRenderer(){return l.replaceRenderer},get blurRenderer(){return l.blurRenderer},get lightWrapBlurRenderer(){return l.lightWrapBlurRenderer},get prevMaskRenderer2(){return l.prevMaskRenderer2},get prevMaskRenderer4(){return l.prevMaskRenderer4},get selectCenterComponent(){return l.selectCenterComponent},get smoothingMaskRenderer2(){return l.smoothingMaskRenderer2},get smoothingMaskRenderer4(){return l.smoothingMaskRenderer4},get binaryMaskRenderer2(){return l.binaryMaskRenderer2},get binaryMaskRenderer4(){return l.binaryMaskRenderer4},get morphErodeRenderer(){return l.morphErodeRenderer},get morphErodeRenderer4(){return l.morphErodeRenderer4},get maskBlurRenderer(){return l.maskBlurRenderer},get strongMaskBlurRenderer(){return l.strongMaskBlurRenderer},get maskDownsampler2(){return l.maskDownsampler2},get maskDownsampler4(){return l.maskDownsampler4},get maskUpsampler(){return l.maskUpsampler},get maskUpsampler2(){return l.maskUpsampler2},get maskUpsampler4(){return l.maskUpsampler4},get frameDownsampler2(){return l.frameDownsampler2},get frameDownsampler4(){return l.frameDownsampler4},get geodesicReconstructionRenderer2(){return l.geodesicReconstructionRenderer2},get geodesicReconstructionRenderer4(){return l.geodesicReconstructionRenderer4}},f=()=>{c.canvasContextEventsCleanup=jf(e,{contextLost:t.contextLost,contextRestored:t.contextRestored,contextCreationError:t.contextCreationError},p),c.gl=e.getContext("webgl2",{premultipliedAlpha:!1,powerPreference:"high-performance"}),F(c.gl,M.ContextCreationError)},d=(E,I,_)=>{F(!c.gl?.isContextLost(),M.ContextLost);let v=c.videoFrameRenderer.render(I),R=c.maskRenderer.render(E),U,C;switch(_.downSampleFactor){case 4:{let L=c.maskDownsampler4.render(R),B=c.frameDownsampler4.render(v),N=c.jointBilateralFilterRenderer4.render({input:L,guide:B},_);if(U=c.smoothingMaskRenderer4.render({mask:N,prevMask:c.prevMask4??N},_),_.excludeBystanders){let X=c.binaryMaskRenderer4.render(U,_.foregroundThreshold),ne=c.morphErodeRenderer4.render({mask:X},_),Re=c.selectCenterComponent.render(ne,_),Ge=c.maskUpsampler4.render(Re);U=c.geodesicReconstructionRenderer4.render({mask:Ge,maskRef:U},_)}let D=c.maskUpsampler.render(U);C=c.strongMaskBlurRenderer.render(D,so);break}default:{let L=c.maskDownsampler2.render(R),B=c.frameDownsampler2.render(v),N=c.jointBilateralFilterRenderer2.render({input:L,guide:B},_);if(U=c.smoothingMaskRenderer2.render({mask:N,prevMask:c.prevMask2??N},_),_.excludeBystanders){let X=c.binaryMaskRenderer2.render(U,_.foregroundThreshold),ne=c.morphErodeRenderer.render({mask:X},_),Re=c.selectCenterComponent.render(ne,_),Ge=c.maskUpsampler2.render(Re);U=c.geodesicReconstructionRenderer2.render({mask:Ge,maskRef:U},_)}let D=c.maskUpsampler.render(U);C=c.maskBlurRenderer.render(D,_.edgeBlurAmount);break}}let O=v;if(_.effects==="blur"&&_.backgroundBlurAmount){let L=c.blurRenderer.render(v,_.backgroundBlurAmount);O=c.blendRenderer.render({mask:C,foreground:v,background:L},_)}else if(_?.effects==="overlay"&&_.backgroundImage){let L=c.backgroundImageRenderer.render(_.backgroundImage);O=c.replaceRenderer.render({mask:C,foreground:v,background:L,blurredBackground:c.lightWrapBlurRenderer.render(L,_.lightWrapBlurAmount),timestamp:I.timestamp},_)}c.canvasRenderer.render(O),_.downSampleFactor===4?c.prevMask4=c.prevMaskRenderer4.render(U):c.prevMask2=c.prevMaskRenderer2.render(U)},p=()=>{c.canvasContextEventsCleanup(),l.release(),l=xn(u),c.prevMask2=void 0,c.prevMask4=void 0};return{init:f,render:d,release:()=>{p()},isContextLost:()=>!!c.gl?.isContextLost()}};var Xh=()=>{let t;return e=>{let r=e.getAsUint8Array();(!t||t.width!==e.width||t.height!==e.height)&&(t=new ImageData(e.width,e.height));let n=t.data;for(let s=0;s<r.length;s++)n[s*4+3]=r[s];return t}},jh=t=>{let e=Qt(t);return{render:r=>{(t.height!==r.height||t.width!==r.width)&&(t.width=r.width,t.height=r.height,e=Qt(t)),e.putImageData(r,0,0)}}},Rp={drawImageDataCanvas:"drawImageDataCanvas",maskCanvas:"maskCanvas",blurredMaskCanvas:"blurredMaskCanvas",blurredCanvas:"blurredCanvas",downScaledCanvas:"downScaledCanvas",backgroundImageCanvas:"backgroundImageCanvas",inputCanvas:"inputCanvas"},Qt=(t,e)=>{let r=t.getContext("2d",e);if(!r)throw new Error("Cannot get CanvasRenderingContext2D");return r},Ip=t=>{let e=Qt(t);e.scale(-1,1),e.translate(-t.width,0)},wu=t=>"VideoFrame"in globalThis&&t instanceof VideoFrame?{height:t.displayHeight,width:t.displayWidth}:"offsetHeight"in t&&typeof t.offsetHeight=="number"&&t.offsetHeight!==0&&"offsetWidth"in t&&typeof t.offsetWidth=="number"&&t.offsetWidth!==0?{height:t.offsetHeight,width:t.offsetWidth}:"videoHeight"in t&&typeof t.videoHeight=="number"&&t.videoHeight!==0&&"videoWidth"in t&&typeof t.videoWidth=="number"&&t.videoWidth!==0?{height:t.videoHeight,width:t.videoWidth}:"height"in t&&t.height!==0&&"width"in t&&t.width!==0?{height:t.height,width:t.width}:{height:0,width:0},Rn=(t,e)=>new OffscreenCanvas(t,e);var Sp=t=>{Qt(t).clearRect(0,0,t.width,t.height)},Yh=(t,e)=>{let r={downScaleFactor:3},n=_=>Rn(_==="downScaledCanvas"?Math.trunc(t/r.downScaleFactor):t,_==="downScaledCanvas"?Math.trunc(e/r.downScaleFactor):e),s=_=>{let v=r[_];if(!v){let R=n(_);return r[_]=R,R}return v},o=(_,v)=>{let R=s(v);return Qt(R).putImageData(_,0,0),R},a=(_,v,R,U,C,O,L,B,N,D)=>{let X=v instanceof ImageData?o(v,"drawImageDataCanvas"):v;C===void 0||O===void 0?_.drawImage(X,R,U):L===void 0||B===void 0||N===void 0||D===void 0?_.drawImage(X,R,U,C,O):_.drawImage(X,R,U,C,O,L,B,N,D)},i=(_,v,R=t,U=e,C={})=>{let{height:O,width:L}=wu(_),B=Xf(L,O,R,U),N=Qt(v,C);a(N,_,B.sx,B.sy,B.sw,B.sh,B.dx,B.dy,B.dw,B.dh)},u=(_,v)=>{let R=s(v);return i(_,R),R},l=(_,v,R)=>{_.globalCompositeOperation=R,a(_,v,0,0)},c=(_,v,R)=>{let U=Qt(_),C=0,O=5,L=1/(2*Math.PI*O*O),B=R<3?1:2;for(let N=-R;N<=R;N+=B)for(let D=-R;D<=R;D+=B){let X=L*Math.exp(-(D*D+N*N)/(2*O*O));C+=X}for(let N=-R;N<=R;N+=B)for(let D=-R;D<=R;D+=B)U.globalAlpha=L*Math.exp(-(D*D+N*N)/(2*O*O))/C*R,a(U,v,D,N);U.globalAlpha=1},f=({image:_,blurAmount:v,canvas:R,preserveOldDrawing:U=!0})=>{let{height:C,width:O}=wu(_),L=Qt(R);if(v<=0)return a(L,_,0,0,O,C);let B=s("downScaledCanvas"),N=Qt(B);U||(N.clearRect(0,0,B.width,B.height),L.clearRect(0,0,O,C)),"filter"in L?(N.filter=`blur(${v}px)`,a(N,_,0,0,O,C,0,0,B.width,B.height),a(L,B,0,0,O,C)):c(R,_,v)},d=({image:_,blurAmount:v,offscreenCanvasName:R,preserveOldDrawing:U})=>{let C=s(R);return Sp(C),v===0?i(_,C):f({image:_,blurAmount:v,canvas:C,preserveOldDrawing:U}),C},p=(_,v,R)=>{let U=_;if(!U)return s("maskCanvas");let C=d({image:U,offscreenCanvasName:"maskCanvas",blurAmount:0});return R===0?C:d({image:C,blurAmount:R,offscreenCanvasName:"blurredMaskCanvas",preserveOldDrawing:!1})},T=(_,v,R,U,C=.5,O=3,L=3,B=!1)=>{let N=d({image:R,blurAmount:O,offscreenCanvasName:"blurredCanvas"}),D=Qt(_),X=p(U,C,L);D.save(),B&&Ip(_);let{height:ne,width:Re}=wu(v);a(D,v,0,0,Re,ne),l(D,X,"destination-in"),l(D,N,"destination-over"),D.restore()};return{evaluateInput:_=>u(_,"inputCanvas"),renderImageToCanvas:i,drawBlurEffect:(_,v,R,U=.5,C=3,O=3,L=!1)=>T(_,v,v,R,U,C,O,L),drawOverlayEffect:(_,v,R,U,C=.5,O=0,L=3,B=!1)=>T(_,v,R,U,C,O,L,B),renderImageToOffScreenCanvas:u,renderImageDataToOffScreenCanvas:o,drawAndBlurImageOnOffScreenCanvas:d,reset:()=>{for(let _ in Rp){let v=_,R=r[v];R&&R instanceof OffscreenCanvas&&(r[v]=n(v))}}}};var qh=(t,e=new OffscreenCanvas(Rr,Ar))=>{let r=Yh(e.width,e.height),n=null,s=()=>{n=e.getContext("2d"),n||t.contextCreationError("Failed to create 2D rendering context")},o=(l,c,f)=>{if(!n)return;n.clearRect(0,0,e.width,e.height);let d=r.evaluateInput(c);f.effects==="blur"&&f.backgroundBlurAmount?r.drawBlurEffect(e,d,l,f.foregroundThreshold,f.backgroundBlurAmount,f.edgeBlurAmount):f?.effects==="overlay"&&f.backgroundImage&&r.drawOverlayEffect(e,d,f.backgroundImage,l,f.foregroundThreshold,0,f.edgeBlurAmount)},a=()=>{r.reset(),n=null};return{init:s,render:o,release:()=>{a()},isContextLost:()=>!n||n.isContextLost()}};var Kh=t=>typeof t=="string"?Object.values(zf).includes(t):!1;var Ho=Zf(),zp=Xh(),k={width:Rr,height:Ar,status:Te.New,stats:[],delegate:Ho?"GPU":"CPU",modelAssetPath:"",muted:!1,renderOptions:{edgeBlurAmount:4,backgroundBlurAmount:3,backgroundThreshold:.35,foregroundThreshold:.85,maskCombineRatio:.8,effects:$f.None,sigmaRangeHi:Bi[1],sigmaRangeLo:Bi[0],sigmaSpace:Wf,backgroundImageUrl:"",backgroundImage:null,backend:"webgl",personCenter:Vf,excludeBystanders:!1,morphPass:4,morphErodeRadiusPx:5,morphDilateRadiusPx:6,lightWrapIntensity:.8,lightWrapTightness:1,downSampleFactor:2,lightWrapBlurAmount:1,lightWrapEdgeBand:.25}},Au=io(k.renderOptions),Ru=()=>{k.trackEventsSubscription?.(),k.originalTrack?.stop()},Me=(t,e)=>postMessage(t,e??[]),Hp=t=>{if(k.status!==Te.Error){k.status=Te.Error;try{k.segmenter?.close()}catch(e){Me({type:"event",data:{type:M.ContextLost,message:`Failed to close segmenter ${e}`}})}k.segmenter=void 0}Me({type:"event",data:{type:M.ContextLost,message:t}})},Xp=t=>{Me({type:"event",data:{type:M.ContextRestored,message:t}})},jp=t=>{k.status!==Te.Error&&(k.status=Te.Error),Me({type:"event",data:{type:M.ContextCreationError,message:t}})},Yp=async()=>{k.renderer?.release(),k.renderer=void 0;let t=[{contextLost:Hp,contextRestored:Xp,contextCreationError:jp},k.processCanvas],e=()=>{let s=Hh(...t);return k.renderOptions.backend="webgl",s},r=()=>{let s=qh(...t);return k.renderOptions.backend="canvas2d",s};if(navigator.gpu&&k.renderOptions?.backend==="webgpu"){let s=await navigator.gpu.requestAdapter({powerPreference:"high-performance"});s?k.renderer=vh(s,...t):Ho?k.renderer=e():k.renderer=r()}else k.renderOptions?.backend!=="canvas2d"&&Ho?k.renderer=e():k.renderer=r();Me({type:"debug",data:{context:{backend:k.renderOptions.backend},message:"Init renderer"}}),await k.renderer?.init()},qp=async()=>{F(k.visionInstance),k.segmenter?.close(),Me({type:"debug",data:{context:{delegate:k.delegate,backend:k.renderOptions.backend},message:"Init segmneter"}}),k.segmenter=await Xe.createFromOptions(k.visionInstance,{outputCategoryMask:!1,outputConfidenceMasks:!0,runningMode:"VIDEO",...k.renderOptions.backend==="canvas2d"?{}:{canvas:k.segmenterCanvas},baseOptions:{modelAssetPath:k.modelAssetPath,delegate:k.delegate}})},Jh=async t=>{k.segmenterTextureToCanvas?.release(),k.segmenterTextureToCanvas=void 0,k.segmenterMaskToCanvas=void 0,k.segmenterCanvas=t,k.renderOptions.backend==="canvas2d"?k.segmenterMaskToCanvas=jh(k.segmenterCanvas):k.segmenterTextureToCanvas=Wo(k.segmenterCanvas),await qp()},Qh=async t=>{k.processCanvas=t,await Yp()},Tu=()=>{k.muted=!0,k.originalTrack&&(k.originalTrack.enabled=!1)},ku=()=>{k.muted=!1,k.originalTrack&&(k.originalTrack.enabled=!0)},Kp=t=>(t.addEventListener("mute",Tu),t.addEventListener("unmute",ku),t.addEventListener("ended",Eu),()=>{t.removeEventListener("mute",Tu),t.removeEventListener("unmute",ku),t.removeEventListener("ended",Eu)}),ed=t=>{let e={},{backgroundImage:r,...n}=k.renderOptions,s=Nf(n,t);for(let[o,a]of Object.entries(s.changed))e[o]=a.new;return e},td=t=>{t==="CPU"?k.delegate="CPU":Ho?k.delegate="GPU":k.delegate="CPU"},Zp=async(t={})=>{try{k.status=Te.Opening,t.processingWidth&&(k.width=t.processingWidth),t.processingHeight&&(k.height=t.processingHeight);let e={};t.renderOptions&&(e=ed(t.renderOptions),Au(t.renderOptions));let{basePath:r,imageSegmenterOptions:n={}}=t;if(k.modelAssetPath=n.modelAsset?.path??k.modelAssetPath,td(n.delegate),k.visionInstance=await hr.forVisionTasks(r),k.backgroundImages?.clear(),k.backgroundImages=Hf(t.backgroundImage&&[[t.backgroundImage.key,t.backgroundImage.image]]),t.renderOptions?.backgroundImageUrl&&t.backgroundImage?.key!==t.renderOptions.backgroundImageUrl){let s=await Iu(t.renderOptions.backgroundImageUrl);s&&(k.renderOptions.backgroundImage=s)}await Qh(Rn(k.width,k.height)),await Jh(Rn(k.width,k.height)),k.status=Te.Opened,Me({type:"opened",data:e})}catch(e){k.status=Te.Error;let r=ao(e);Me({type:"event",data:{type:oo(r),message:r}})}},Jp=Math.trunc(30*.8),Zh=t=>{k.stats.push(t),k.stats.length>=Jp&&(t2(),k.stats.length=0)},Qp={async transform(t,e){let r=performance.now();if(k.renderOptions.effects==="none"||k.muted){Zh({start:r,end:r}),e.enqueue(t);return}F(k.segmenter);let n;try{n=k.segmenter.segmentForVideo(t,r);let s=performance.now(),o=t.timestamp,a=n.confidenceMasks?.[0];if(a){F(k.renderer),F(k.processCanvas),F(k.segmenterCanvas),k.segmenterMaskToCanvas?k.segmenterMaskToCanvas.render(zp(a)):(F(k.segmenterTextureToCanvas),k.segmenterTextureToCanvas.render(Ih(a))),a.close(),k.renderer.render(k.segmenterCanvas,t,k.renderOptions),t.close();let i=new VideoFrame(k.processCanvas,{timestamp:o});e.enqueue(i)}else e.enqueue(t);Zh({start:r,segmentation:s,end:performance.now()})}catch(s){e.enqueue(t),s instanceof Error&&(k.status=Te.Error,Me({type:"event",data:{type:"Error",error:s}}))}finally{n?.close()}}},rd=async(t,e,r)=>t.pipeThrough(new TransformStream(Qp),{signal:r}).pipeTo(e),e2=async(t,e)=>{let r=new VideoTrackGenerator;Me({type:"processed",data:r.track},[r.track]);let{readable:n}=new MediaStreamTrackProcessor({track:t});try{await rd(n,r.writable,e)}catch(s){if(Ru(),e&&!(e.aborted&&(e.reason==="close"||!("reason"in AbortSignal.prototype))))throw s}},Iu=t=>(k.imageFetcherAbortController?.abort("close"),k.imageFetcherAbortController=new AbortController,k.backgroundImages?.tryFetchingImage(t,k.imageFetcherAbortController.signal)),t2=()=>{k.stats.length&&(Me({type:"stats",data:k.stats}),k.stats.length=0)},r2=async(t,e,r,n)=>{try{if(F(k.segmenter),F(t||e&&r),n&&Au(n),F(!k.renderer?.isContextLost(),M.ContextLost),k.renderOptions?.effects==="overlay"&&k.renderOptions.backgroundImageUrl){let s=k.backgroundImages?.getImage(k.renderOptions.backgroundImageUrl);if(s)k.renderOptions.backgroundImage=s;else{let o=await Iu(k.renderOptions.backgroundImageUrl);o&&(k.renderOptions.backgroundImage=o)}}k.status=Te.Processing,k.processingAbortController=new AbortController,k.stats.length=0,t?(Ru(),k.originalTrack=t,k.muted=!t.enabled,k.trackEventsSubscription=Kp(t),await e2(t,k.processingAbortController.signal)):(F(e&&r),Me({type:"processed"}),await rd(e,r,k.processingAbortController.signal))}catch(s){let o=ao(s);if(o==="close")return;if(s instanceof Error)return k.status=Te.Error,Me({type:"event",data:{type:oo(o),error:s,message:o,track:t}},t?[t]:[]);throw s}},n2=async({backgroundImage:t,renderOptions:e,imageSegmenterOptions:r,processingHeight:n,processingWidth:s,restart:o})=>{if(k.status!==Te.Updating)try{if(k.status=Te.Updating,t&&(k.backgroundImages?.setImage(t.key,t.image),k.renderOptions.backgroundImageUrl===t.key&&(k.renderOptions.backgroundImage=t.image)),e?.backgroundImageUrl){let l=await Iu(e.backgroundImageUrl);l&&(k.renderOptions.backgroundImage=l)}let a=o;if(n&&n!==k.height&&(k.height=n,a=!0),s&&s!==k.width&&(k.width=s,a=!0),e?.backend&&!Kh(e.backend)){k.status=Te.Error,Me({type:"event",data:{type:"Error",message:"Render backend is not webgl or webgpu"}});return}e?.effects&&e.effects!==k.renderOptions.effects&&(k.stats.length=0);let i=e?.backend&&e?.backend!==k.renderOptions.backend,u={};e&&(u=ed(e),Au(e)),r&&(k.modelAssetPath=r.modelAsset?.path??k.modelAssetPath,td(r.delegate)),(a||i)&&(await Qh(Rn(k.width,k.height)),await Jh(Rn(k.width,k.height))),k.status=Te.Updated,Me({type:"updated",data:u}),a&&Me({type:"event",data:{type:M.ProcessorRestarted}})}catch(a){k.status=Te.Error;let i=ao(a);Me({type:"event",data:{type:oo(i),message:i}})}},s2=()=>{k.status=Te.Idle,k.processingAbortController?.abort("close"),k.imageFetcherAbortController?.abort("close"),Ru(),k.processingAbortController=void 0,k.imageFetcherAbortController=void 0},Eu=()=>{k.status=Te.Closing,s2(),k.stats.length=0,k.status=Te.Closed,Me({type:"closed"})};self.addEventListener("message",t=>{switch(t.data.type){case"open":{Zp(t.data.data);break}case"update":{n2(t.data.data);break}case"process":{let{track:e,readable:r,writable:n,renderOptions:s}=t.data.data;r2(e,r,n,s);break}case"close":{Eu();break}case"mute":{t.data.data?Tu():ku();break}case"destroy":{k.status=Te.Destroying,k.renderer?.release(),k.segmenterTextureToCanvas?.release(),k.segmenter?.close(),k.backgroundImages?.clear(),k.originalTrack=void 0,k.renderer=void 0,k.segmenter=void 0,k.backgroundImages=void 0,k.trackEventsSubscription=void 0,k.status=Te.Destroyed;break}}});self.addEventListener("error",t=>{t.preventDefault(),Me({type:"event",data:{type:M.Error,message:`Uncaught Error event: ${t.error}`}})});
74
+ uniform sampler2D u_mask;uniform sampler2D u_mask_prev;uniform float u_mask_combine_ratio;in vec2 v_texCoord;out vec4 outColor;float maskUncertainty(float p){const float c1=5.68842;const float c2=-0.748699;const float c3=-57.8051;const float c4=291.309;const float c5=-624.717;float t=p-0.5;float x=t*t;float uncertainty=1.0-min(1.0,x*(c1+x*(c2+x*(c3+x*(c4+x*c5)))));return uncertainty;}void main(){float current_mask=texture(u_mask,v_texCoord).r;float prev_mask=texture(u_mask_prev,v_texCoord).r;float uncertainty=maskUncertainty(current_mask);float alpha=uncertainty*u_mask_combine_ratio;float stabilized=current_mask+(prev_mask-current_mask)*alpha;outColor=vec4(stabilized,stabilized,stabilized,1.0);}`;var ju=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatFullChannelSupported:i,floatSingleChannelSupported:u,release:l}=de(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",mask:"u_mask",prevMask:"u_mask_prev",frame:"u_frame",prevFrame:"u_frame_prev",maskCombineRatio:"u_mask_combine_ratio"},vertexSrc:he,fragmentSrc:vh}),c=n.createVertexArray();n.bindVertexArray(c);let f=n.createBuffer();n.enableVertexAttribArray(o.position),n.bindBuffer(n.ARRAY_BUFFER,f),n.vertexAttribPointer(o.position,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW);let d=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,d),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW),n.enableVertexAttribArray(o.texCoord),n.vertexAttribPointer(o.texCoord,2,n.FLOAT,!1,0,0);let p=be(n,e,r,!1,u,i),b=ae(n,p);return{render:({mask:E,prevMask:A},I)=>{C(!n.isContextLost(),M.ContextLost),n.bindFramebuffer(n.FRAMEBUFFER,b),n.viewport(0,0,E.width,E.height),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(s),n.bindVertexArray(c),n.activeTexture(n.TEXTURE0),n.uniform1i(a.mask,0),n.bindTexture(n.TEXTURE_2D,E.texture),n.activeTexture(n.TEXTURE1),n.uniform1i(a.prevMask,1),n.bindTexture(n.TEXTURE_2D,A.texture);let _=Z.projection(1,1,1);return n.uniformMatrix3fv(a.matrix,!1,_),n.uniform1f(a.maskCombineRatio,I.maskCombineRatio),n.drawArrays(n.TRIANGLES,0,6),n.bindBuffer(n.ARRAY_BUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,null),n.bindVertexArray(null),{texture:p,width:e,height:r}},release:()=>{n.deleteBuffer(f),n.deleteBuffer(d),n.deleteTexture(p),n.deleteFramebuffer(b),n.deleteVertexArray(c),l()}}};var wh=`#version 300 es
75
+ precision mediump float;uniform sampler2D u_mask;uniform vec2 u_texel_size;uniform vec2 u_direction;uniform int u_radius_px;const int MAX_RADIUS_PX=16;in vec2 v_texCoord;out vec4 outColor;void main(){int R=clamp(u_radius_px,0,MAX_RADIUS_PX);if(R==0){float m=texture(u_mask,v_texCoord).r;outColor=vec4(m,m,m,1.0);return;}float sumW=0.0;float acc=0.0;for(int i=-MAX_RADIUS_PX;i<=MAX_RADIUS_PX;++i){if(abs(i)>R)continue;float w=float(R+1-abs(i));vec2 off=u_direction*float(i)*u_texel_size;float s=texture(u_mask,v_texCoord+off).r;acc+=w*s;sumW+=w;}float m=acc/max(sumW,1.0e-6);outColor=vec4(m,m,m,1.0);}`;var A2=16,R2=Ut(0,A2),Th=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatSingleChannelSupported:i,floatFullChannelSupported:u,release:l}=de(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",mask:"u_mask",texelSize:"u_texel_size",direction:"u_direction",radiusPx:"u_radius_px"},vertexSrc:he,fragmentSrc:wh}),c=n.createVertexArray();n.bindVertexArray(c);let f=n.createBuffer();n.enableVertexAttribArray(o.position),n.bindBuffer(n.ARRAY_BUFFER,f),n.vertexAttribPointer(o.position,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW);let d=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,d),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),n.STATIC_DRAW),n.enableVertexAttribArray(o.texCoord),n.vertexAttribPointer(o.texCoord,2,n.FLOAT,!1,0,0);let p=be(n,e,r,!1,i,u),b=ae(n,p),E=be(n,e,r,!1,i,u),A=ae(n,E),I=t.width/e;return{render:(_,T)=>{C(!n.isContextLost(),M.ContextLost),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(s),n.bindVertexArray(c),n.uniform2f(a.texelSize,1/_.width,1/_.height),n.uniform1i(a.radiusPx,R2(Math.floor(T/I)));let R=Z.projection(1,1,1);n.uniformMatrix3fv(a.matrix,!1,R);let U=b,B=_.texture;for(let O=0;O<2;O++)n.activeTexture(n.TEXTURE0),n.uniform1i(a.mask,0),n.bindTexture(n.TEXTURE_2D,B),n.uniform2f(a.direction,1-O,0+O),n.bindFramebuffer(n.FRAMEBUFFER,U),n.viewport(0,0,_.width,_.height),n.drawArrays(n.TRIANGLES,0,6),[B,U]=U===b?[p,A]:[E,b];return n.bindBuffer(n.ARRAY_BUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,null),n.bindVertexArray(null),{texture:B,width:e,height:r}},release:()=>{n.deleteBuffer(f),n.deleteBuffer(d),n.deleteTexture(p),n.deleteTexture(E),n.deleteFramebuffer(b),n.deleteFramebuffer(A),n.deleteVertexArray(c),l()}}};var ca=(t,e)=>{let{gl:r,program:n,attribLocations:s,uniformLocations:o,floatFullChannelSupported:a,floatSingleChannelSupported:i,release:u}=de(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",texture:"u_texture"},vertexSrc:he,fragmentSrc:Dn}),l=r.createVertexArray();r.bindVertexArray(l);let c=r.createBuffer();r.enableVertexAttribArray(s.position),r.bindBuffer(r.ARRAY_BUFFER,c),r.vertexAttribPointer(s.position,2,r.FLOAT,!1,0,0),r.bufferData(r.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),r.STATIC_DRAW);let f=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,f),r.bufferData(r.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),r.STATIC_DRAW),r.enableVertexAttribArray(s.texCoord),r.vertexAttribPointer(s.texCoord,2,r.FLOAT,!1,0,0);let d=Yt(r,t.width,t.height,!0,a),p=e?be(r,t.width,t.height,!1,i,a):Yt(r,t.width,t.height,!0,a),b=ae(r,p);return{render:E=>{C(!r.isContextLost(),M.ContextLost),r.bindFramebuffer(r.FRAMEBUFFER,b),r.viewport(0,0,t.width,t.height),r.clearColor(0,0,0,1),r.clear(r.COLOR_BUFFER_BIT),r.useProgram(n),r.bindVertexArray(l),r.uniform1i(o.texture,0);let A=Z.projection(1,1,1);return r.uniformMatrix3fv(o.matrix,!1,A),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,d),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,E),r.drawArrays(r.TRIANGLES,0,6),r.bindBuffer(r.ARRAY_BUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindTexture(r.TEXTURE_2D,null),r.bindVertexArray(null),{texture:p,width:t.width,height:t.height}},release:()=>{r.deleteBuffer(c),r.deleteBuffer(f),r.deleteTexture(d),r.deleteTexture(p),r.deleteVertexArray(l),u()}}};var kh=(t,e=new OffscreenCanvas(Pr,Fr))=>{let r=Math.trunc(e.width/2),n=Math.trunc(e.height/2),s=Math.trunc(e.width/4),o=Math.trunc(e.height/4),a=32,i=18,u={backgroundImageRenderer:()=>ca(e,!1),blendRenderer:()=>lh(e),blurRenderer:()=>aa(e),canvasRenderer:()=>ia(e),frameDownsampler2:()=>Dt(e,!1,!0,r,n),frameDownsampler4:()=>Dt(e,!1,!0,s,o),geodesicReconstructionRenderer2:()=>zu(e,r,n),geodesicReconstructionRenderer4:()=>zu(e,s,o),jointBilateralFilterRenderer2:()=>ua(e,r,n),jointBilateralFilterRenderer4:()=>ua(e,s,o),jointBilateralFilterRenderer:()=>ua(e,e.width,e.height),lightWrapBlurRenderer:()=>aa(e),maskBlurRenderer:()=>Th(e,e.width,e.height),strongMaskBlurRenderer:()=>aa(e),maskDownsampler2:()=>Dt(e,!0,!1,r,n),maskDownsampler4:()=>Dt(e,!0,!1,s,o),maskRenderer:()=>ca(e,!0),maskUpsampler2:()=>Dt(e,!0,!1,r,n),maskUpsampler4:()=>Dt(e,!0,!1,s,o),maskUpsampler:()=>Dt(e,!0,!1,e.width,e.height),morphErodeRenderer:()=>Hu(e,r,n),morphErodeRenderer4:()=>Hu(e,s,o),prevMaskRenderer2:()=>Dt(e,!0,!1,r,n),prevMaskRenderer4:()=>Dt(e,!0,!1,s,o),replaceRenderer:()=>bh(e),selectCenterComponent:()=>hh(e,a,i),smoothingMaskRenderer4:()=>ju(e,s,o),smoothingMaskRenderer2:()=>ju(e,r,n),binaryMaskRenderer2:()=>$u(e,r,n),binaryMaskRenderer4:()=>$u(e,s,o),videoFrameRenderer:()=>ca(e,!1),release:A=>()=>{for(let I in A)I!=="release"&&A[I]?.release()}},l=Rn(u),c={canvas:e,gl:null,canvasContextEventsCleanup:()=>{},get videoFrameRenderer(){return l.videoFrameRenderer},get jointBilateralFilterRenderer(){return l.jointBilateralFilterRenderer},get jointBilateralFilterRenderer2(){return l.jointBilateralFilterRenderer2},get jointBilateralFilterRenderer4(){return l.jointBilateralFilterRenderer4},get maskRenderer(){return l.maskRenderer},get canvasRenderer(){return l.canvasRenderer},get backgroundImageRenderer(){return l.backgroundImageRenderer},get blendRenderer(){return l.blendRenderer},get replaceRenderer(){return l.replaceRenderer},get blurRenderer(){return l.blurRenderer},get lightWrapBlurRenderer(){return l.lightWrapBlurRenderer},get prevMaskRenderer2(){return l.prevMaskRenderer2},get prevMaskRenderer4(){return l.prevMaskRenderer4},get selectCenterComponent(){return l.selectCenterComponent},get smoothingMaskRenderer2(){return l.smoothingMaskRenderer2},get smoothingMaskRenderer4(){return l.smoothingMaskRenderer4},get binaryMaskRenderer2(){return l.binaryMaskRenderer2},get binaryMaskRenderer4(){return l.binaryMaskRenderer4},get morphErodeRenderer(){return l.morphErodeRenderer},get morphErodeRenderer4(){return l.morphErodeRenderer4},get maskBlurRenderer(){return l.maskBlurRenderer},get strongMaskBlurRenderer(){return l.strongMaskBlurRenderer},get maskDownsampler2(){return l.maskDownsampler2},get maskDownsampler4(){return l.maskDownsampler4},get maskUpsampler(){return l.maskUpsampler},get maskUpsampler2(){return l.maskUpsampler2},get maskUpsampler4(){return l.maskUpsampler4},get frameDownsampler2(){return l.frameDownsampler2},get frameDownsampler4(){return l.frameDownsampler4},get geodesicReconstructionRenderer2(){return l.geodesicReconstructionRenderer2},get geodesicReconstructionRenderer4(){return l.geodesicReconstructionRenderer4}},f=()=>{c.canvasContextEventsCleanup=Td(e,{contextLost:t.contextLost,contextRestored:t.contextRestored,contextCreationError:t.contextCreationError},p),c.gl=e.getContext("webgl2",{premultipliedAlpha:!1,powerPreference:"high-performance"}),C(c.gl,M.ContextCreationError)},d=(A,I,_)=>{C(!c.gl?.isContextLost(),M.ContextLost);let T=c.videoFrameRenderer.render(I),R=c.maskRenderer.render(A),U,B;switch(_.downSampleFactor){case 4:{let P=c.maskDownsampler4.render(R),F=c.frameDownsampler4.render(T),N=c.jointBilateralFilterRenderer4.render({input:P,guide:F},_);if(U=c.smoothingMaskRenderer4.render({mask:N,prevMask:c.prevMask4??N},_),_.excludeBystanders){let j=c.binaryMaskRenderer4.render(U,_.foregroundThreshold),ne=c.morphErodeRenderer4.render({mask:j},_),Se=c.selectCenterComponent.render(ne,_),We=c.maskUpsampler4.render(Se);U=c.geodesicReconstructionRenderer4.render({mask:We,maskRef:U},_)}let D=c.maskUpsampler.render(U);B=c.strongMaskBlurRenderer.render(D,ko);break}default:{let P=c.maskDownsampler2.render(R),F=c.frameDownsampler2.render(T),N=c.jointBilateralFilterRenderer2.render({input:P,guide:F},_);if(U=c.smoothingMaskRenderer2.render({mask:N,prevMask:c.prevMask2??N},_),_.excludeBystanders){let j=c.binaryMaskRenderer2.render(U,_.foregroundThreshold),ne=c.morphErodeRenderer.render({mask:j},_),Se=c.selectCenterComponent.render(ne,_),We=c.maskUpsampler2.render(Se);U=c.geodesicReconstructionRenderer2.render({mask:We,maskRef:U},_)}let D=c.maskUpsampler.render(U);B=c.maskBlurRenderer.render(D,_.edgeBlurAmount);break}}let O=T;if(_.effects==="blur"&&_.backgroundBlurAmount){let P=c.blurRenderer.render(T,_.backgroundBlurAmount);O=c.blendRenderer.render({mask:B,foreground:T,background:P},_)}else if(_?.effects==="overlay"&&_.backgroundImage){let P=c.backgroundImageRenderer.render(_.backgroundImage);O=c.replaceRenderer.render({mask:B,foreground:T,background:P,blurredBackground:c.lightWrapBlurRenderer.render(P,_.lightWrapBlurAmount),timestamp:I.timestamp},_)}c.canvasRenderer.render(O),_.downSampleFactor===4?c.prevMask4=c.prevMaskRenderer4.render(U):c.prevMask2=c.prevMaskRenderer2.render(U)},p=()=>{c.canvasContextEventsCleanup(),l.release(),l=Rn(u),c.prevMask2=void 0,c.prevMask4=void 0};return{init:f,render:d,release:()=>{p()},isContextLost:()=>!!c.gl?.isContextLost()}};var Eh=()=>{let t;return e=>{let r=e.getAsUint8Array();(!t||t.width!==e.width||t.height!==e.height)&&(t=new ImageData(e.width,e.height));let n=t.data;for(let s=0;s<r.length;s++)n[s*4+3]=r[s];return t}},Ah=t=>{let e=ut(t);return{render:r=>{(t.height!==r.height||t.width!==r.width)&&(t.width=r.width,t.height=r.height,e=ut(t)),e.putImageData(r,0,0)}}},I2={drawImageDataCanvas:"drawImageDataCanvas",maskCanvas:"maskCanvas",blurredMaskCanvas:"blurredMaskCanvas",blurredCanvas:"blurredCanvas",downScaledCanvas:"downScaledCanvas",backgroundImageCanvas:"backgroundImageCanvas",inputCanvas:"inputCanvas"},ut=(t,e)=>{let r=t.getContext("2d",e);if(!r)throw new Error("Cannot get CanvasRenderingContext2D");return r},S2=t=>{let e=ut(t);e.scale(-1,1),e.translate(-t.width,0)},vs=t=>"VideoFrame"in globalThis&&t instanceof VideoFrame?{height:t.displayHeight,width:t.displayWidth}:"offsetHeight"in t&&typeof t.offsetHeight=="number"&&t.offsetHeight!==0&&"offsetWidth"in t&&typeof t.offsetWidth=="number"&&t.offsetWidth!==0?{height:t.offsetHeight,width:t.offsetWidth}:"videoHeight"in t&&typeof t.videoHeight=="number"&&t.videoHeight!==0&&"videoWidth"in t&&typeof t.videoWidth=="number"&&t.videoWidth!==0?{height:t.videoHeight,width:t.videoWidth}:"height"in t&&t.height!==0&&"width"in t&&t.width!==0?{height:t.height,width:t.width}:{height:0,width:0},Mt=(t,e)=>new OffscreenCanvas(t,e);var C2=t=>{ut(t).clearRect(0,0,t.width,t.height)},Rh=(t,e)=>{let r={downScaleFactor:3},n=_=>Mt(_==="downScaledCanvas"?Math.trunc(t/r.downScaleFactor):t,_==="downScaledCanvas"?Math.trunc(e/r.downScaleFactor):e),s=_=>{let T=r[_];if(!T){let R=n(_);return r[_]=R,R}return T},o=(_,T)=>{let R=s(T);return ut(R).putImageData(_,0,0),R},a=(_,T,R,U,B,O,P,F,N,D)=>{let j=T instanceof ImageData?o(T,"drawImageDataCanvas"):T;B===void 0||O===void 0?_.drawImage(j,R,U):P===void 0||F===void 0||N===void 0||D===void 0?_.drawImage(j,R,U,B,O):_.drawImage(j,R,U,B,O,P,F,N,D)},i=(_,T,R=t,U=e,B={})=>{let{height:O,width:P}=vs(_),F=Ao(P,O,R,U),N=ut(T,B);a(N,_,F.sx,F.sy,F.sw,F.sh,F.dx,F.dy,F.dw,F.dh)},u=(_,T)=>{let R=s(T);return i(_,R),R},l=(_,T,R)=>{_.globalCompositeOperation=R,a(_,T,0,0)},c=(_,T,R)=>{let U=ut(_),B=0,O=5,P=1/(2*Math.PI*O*O),F=R<3?1:2;for(let N=-R;N<=R;N+=F)for(let D=-R;D<=R;D+=F){let j=P*Math.exp(-(D*D+N*N)/(2*O*O));B+=j}for(let N=-R;N<=R;N+=F)for(let D=-R;D<=R;D+=F)U.globalAlpha=P*Math.exp(-(D*D+N*N)/(2*O*O))/B*R,a(U,T,D,N);U.globalAlpha=1},f=({image:_,blurAmount:T,canvas:R,preserveOldDrawing:U=!0})=>{let{height:B,width:O}=vs(_),P=ut(R);if(T<=0)return a(P,_,0,0,O,B);let F=s("downScaledCanvas"),N=ut(F);U||(N.clearRect(0,0,F.width,F.height),P.clearRect(0,0,O,B)),"filter"in P?(N.filter=`blur(${T}px)`,a(N,_,0,0,O,B,0,0,F.width,F.height),a(P,F,0,0,O,B)):c(R,_,T)},d=({image:_,blurAmount:T,offscreenCanvasName:R,preserveOldDrawing:U})=>{let B=s(R);return C2(B),T===0?i(_,B):f({image:_,blurAmount:T,canvas:B,preserveOldDrawing:U}),B},p=(_,T,R)=>{let U=_;if(!U)return s("maskCanvas");let B=d({image:U,offscreenCanvasName:"maskCanvas",blurAmount:0});return R===0?B:d({image:B,blurAmount:R,offscreenCanvasName:"blurredMaskCanvas",preserveOldDrawing:!1})},b=(_,T,R,U,B=.5,O=3,P=3,F=!1)=>{let N=d({image:R,blurAmount:O,offscreenCanvasName:"blurredCanvas"}),D=ut(_),j=p(U,B,P);D.save(),F&&S2(_);let{height:ne,width:Se}=vs(T);a(D,T,0,0,Se,ne),l(D,j,"destination-in"),l(D,N,"destination-over"),D.restore()};return{evaluateInput:_=>u(_,"inputCanvas"),renderImageToCanvas:i,drawBlurEffect:(_,T,R,U=.5,B=3,O=3,P=!1)=>b(_,T,T,R,U,B,O,P),drawOverlayEffect:(_,T,R,U,B=.5,O=0,P=3,F=!1)=>b(_,T,R,U,B,O,P,F),renderImageToOffScreenCanvas:u,renderImageDataToOffScreenCanvas:o,drawAndBlurImageOnOffScreenCanvas:d,reset:()=>{for(let _ in I2){let T=_,R=r[T];R&&R instanceof OffscreenCanvas&&(r[T]=n(T))}}}};var Ih=(t,e=new OffscreenCanvas(Pr,Fr))=>{let r=Rh(e.width,e.height),n=null,s=()=>{n=e.getContext("2d"),n||t.contextCreationError("Failed to create 2D rendering context")},o=(l,c,f)=>{if(!n)return;n.clearRect(0,0,e.width,e.height);let d=r.evaluateInput(c);f.effects==="blur"&&f.backgroundBlurAmount?r.drawBlurEffect(e,d,l,f.foregroundThreshold,f.backgroundBlurAmount,f.edgeBlurAmount):f?.effects==="overlay"&&f.backgroundImage&&r.drawOverlayEffect(e,d,f.backgroundImage,l,f.foregroundThreshold,0,f.edgeBlurAmount)},a=()=>{r.reset(),n=null};return{init:s,render:o,release:()=>{a()},isContextLost:()=>!n||n.isContextLost()}};async function Sh(t){if(typeof importScripts=="function")importScripts(t.toString());else{let e=document.createElement("script");return e.src=t.toString(),e.crossOrigin="anonymous",new Promise((r,n)=>{e.addEventListener("load",()=>{r()},!1),e.addEventListener("error",s=>{n(s)},!1),document.body.appendChild(e)})}}var Ch=async(t,e,r,n,s)=>{if(e&&await Sh(e),!self.ModuleFactory)throw new Error("ModuleFactory not set.");if(r&&(await Sh(r),!self.ModuleFactory))throw new Error("ModuleFactory not set.");if(self.Module&&s){let a=self.Module;a.locateFile=s.locateFile,s.mainScriptUrlOrBlob&&(a.mainScriptUrlOrBlob=s.mainScriptUrlOrBlob)}let o=await self.ModuleFactory(self.Module||s);return self.ModuleFactory=self.Module=void 0,new t(o,n)};var ve={NONE:0,FLOAT32:1,INT32:2,UINT8:3,INT64:4,STRING:5,BOOL:6,INT16:7,COMPLEX64:8,INT8:9,FLOAT16:10,FLOAT64:11,COMPLEX128:12,UINT64:13,RESOURCE:14,VARIANT:15,UINT32:16,UINT16:17,INT4:18,BFLOAT16:19},Mh={[ve.NONE]:"NONE",[ve.FLOAT32]:"FLOAT32",[ve.INT32]:"INT32",[ve.UINT8]:"UINT8",[ve.INT64]:"INT64",[ve.STRING]:"STRING",[ve.BOOL]:"BOOL",[ve.INT16]:"INT16",[ve.COMPLEX64]:"COMPLEX64",[ve.INT8]:"INT8",[ve.FLOAT16]:"FLOAT16",[ve.FLOAT64]:"FLOAT64",[ve.COMPLEX128]:"COMPLEX128",[ve.UINT64]:"UINT64",[ve.RESOURCE]:"RESOURCE",[ve.VARIANT]:"VARIANT",[ve.UINT32]:"UINT32",[ve.UINT16]:"UINT16",[ve.INT4]:"INT4",[ve.BFLOAT16]:"BFLOAT16"},je={HOST_MEMORY:1,WEB_GPU_BUFFER:20,WEB_GPU_BUFFER_FP16:21,WEB_GPU_BUFFER_PACKED:26},en={[je.HOST_MEMORY]:"HOST_MEMORY",[je.WEB_GPU_BUFFER]:"WEB_GPU_BUFFER",[je.WEB_GPU_BUFFER_FP16]:"WEB_GPU_BUFFER_FP16",[je.WEB_GPU_BUFFER_PACKED]:"WEB_GPU_BUFFER_PACKED"},B2=Object.freeze([{dtype:"float32",typedArrayConstructor:Float32Array,elementType:ve.FLOAT32},{dtype:"int32",typedArrayConstructor:Int32Array,elementType:ve.INT32},{dtype:"uint8",typedArrayConstructor:Uint8Array,elementType:ve.UINT8}]);function tn(t){for(let e of B2)if(e.dtype===t||e.typedArrayConstructor===t||t instanceof e.typedArrayConstructor||e.elementType===t)return e;throw typeof t=="string"?new Error(`DType ${t} is not supported.`):t instanceof Object?new Error(`Typed array ${"name"in t?t.name:t.constructor.name} is not supported.`):new Error(`Element type ${Mh[t]??t} is not supported.`)}var U2=class extends Error{constructor(){super("LiteRT is not initialized yet. Please call loadLiteRt() and wait for its promise to resolve to load the LiteRT WASM module.")}},la=void 0,qu=void 0;function ct(){if(!la)throw new U2;return la}function Bh(){return!!la}function Nh(t){la=t}function F2(){return qu}function Gh(){return!!qu}function Yu(t){qu=t}var P2={webgpu:je.WEB_GPU_BUFFER_PACKED,wasm:je.HOST_MEMORY},L2={[je.HOST_MEMORY]:"wasm",[je.WEB_GPU_BUFFER]:"webgpu",[je.WEB_GPU_BUFFER_FP16]:"webgpu",[je.WEB_GPU_BUFFER_PACKED]:"webgpu"},O2=["shader-f16","subgroups"],Ts=class Vh{constructor(e){Le(this,"liteRtEnvironment");this.options=e,this.liteRtEnvironment=ct().liteRtWasm.LiteRtEnvironment.create(e.webGpuDevice)}static async create(e={}){let r=null;if("webGpuDevice"in e)e.webGpuDevice&&(r=e.webGpuDevice);else try{r=await D2()}catch(n){console.warn("Failed to create default WebGPU device:",n)}return new Vh({...e,webGpuDevice:r})}get webGpuDevice(){return this.options.webGpuDevice}delete(){this.liteRtEnvironment.delete()}};async function D2(){let t={powerPreference:"high-performance"},e=await navigator.gpu.requestAdapter(t);if(!e)throw new Error("No GPU adapter found.");let r={maxBufferSize:e.limits.maxBufferSize,maxStorageBufferBindingSize:e.limits.maxStorageBufferBindingSize,maxStorageBuffersPerShaderStage:e.limits.maxStorageBuffersPerShaderStage,maxTextureDimension2D:e.limits.maxTextureDimension2D},n=[];for(let s of O2)e.features.has(s)&&n.push(s);return await e.requestDevice({requiredFeatures:n,requiredLimits:r})}function ws(t){let e=new Array(t.size());for(let r=0;r<t.size();++r)e[r]=t.get(r);return t.delete(),e}function Wh(t,e){for(let r of t)e.push_back(r)}function M2(t){let e=t.shift(),r=ct().liteRtWasm;if(e instanceof r.LiteRtTensorBuffer)return{liteRtTensorBuffer:e};if(ArrayBuffer.isView(e))return{typedArray:e};if(e instanceof GPUBuffer)return{gpuBuffer:e};throw new Error(`Unknown type (${e?.constructor.name??e}) provided to create a Tensor`)}function N2(t){return Array.isArray(t[0])||t[0]instanceof Int32Array?{shape:t.shift()}:{}}function Ku(t){for(;t.length>0&&t[0]===void 0;)t.shift()}function G2(t){if(Ku(t),typeof t[0]=="string"){let e=t.shift();return{dataType:tn(e).dtype}}else return{}}function V2(t){return Ku(t),t[0]instanceof Ts?{environment:t.shift()}:{}}function W2(t){return Ku(t),t[0]instanceof Function?{onDelete:t.shift()}:{}}function $2(t){return{...M2(t),...N2(t),...G2(t),...V2(t),...W2(t)}}var Mr,qt=(Mr=class{constructor(e,r,n,s,o){Le(this,"liteRtTensorBuffer");Le(this,"type");Le(this,"environment");Le(this,"deletedInternal",!1);Le(this,"onDelete");let{typedArray:a,gpuBuffer:i,liteRtTensorBuffer:u,shape:l,dataType:c,environment:f,onDelete:d}=$2([e,r,n,s,o]);if(this.onDelete=d,this.environment=f??ct().getDefaultEnvironment(),u){if(l)throw new Error("A LiteRtTensorBuffer cannot be provided with a shape.");if(c)throw new Error("A LiteRtTensorBuffer cannot be provided with a data type.");this.liteRtTensorBuffer=u}else if(i){if(!l)throw new Error("A GPUBuffer must be provided with a shape.");if(!c)throw new Error("A GPUBuffer must be provided with a data type.");let[p,b]=H2(i,l,c,this.environment);this.liteRtTensorBuffer=p;let E=this.onDelete;this.onDelete=()=>{ct().liteRtWasm.wgpuBufferRelease(b),E?.()}}else if(a)this.liteRtTensorBuffer=j2(a,l,f);else throw new Error("No data provided to create a Tensor.");this.type=z2(this.liteRtTensorBuffer)}static fromTypedArray(e,r,n){return new Mr(e,r,n)}ensureNotDeleted(){if(this.deleted)throw new Error("Tensor is deleted and cannot be used.")}async data(){if(this.ensureNotDeleted(),this.liteRtTensorBuffer.bufferType().value===je.HOST_MEMORY)return this.toTypedArray();let e=await this.copyTo("wasm"),r=await e.data();return e.delete(),r}toTypedArray(){this.ensureNotDeleted();let e=ct().liteRtWasm;if(this.liteRtTensorBuffer.isWebGpuMemory())throw new Error("Cannot convert a Tensor with WebGPU memory to a TypedArray.");if(this.liteRtTensorBuffer.bufferType().value!==e.LiteRtTensorBufferType.HOST_MEMORY.value)throw new Error("Cannot convert a Tensor with non-host memory to a TypedArray.");if(this.liteRtTensorBuffer.size()!==this.liteRtTensorBuffer.packedSize()||this.liteRtTensorBuffer.offset()!==0)throw new Error("Tensors with strides or padding are not yet supported.");let r=this.liteRtTensorBuffer.tensorType(),n=r.elementType(),s=e.liteRtGetByteWidth(n);r.delete();let o=tn(n.value).typedArrayConstructor;if(o.BYTES_PER_ELEMENT!==s)throw new Error(`Byte width ${s} of the tensor's element type ${Mh[n.value]} does not match the expected byte width ${o.BYTES_PER_ELEMENT} of the ${o.name}.`);let a=this.liteRtTensorBuffer.lock(ct().liteRtWasm.LiteRtTensorBufferLockMode.READ);try{let i=e.HEAPU8.slice(a,a+this.liteRtTensorBuffer.packedSize());return new o(i.buffer,i.byteOffset,i.byteLength/s)}finally{this.liteRtTensorBuffer.unlock()}}getBufferType(){return this.ensureNotDeleted(),this.liteRtTensorBuffer.bufferType().value}toGpuBuffer(){this.ensureNotDeleted();let e=ct().liteRtWasm;if(!this.liteRtTensorBuffer.isWebGpuMemory())throw new Error("Cannot convert a Tensor with non-WebGPU memory to a GPUBuffer.");let r=this.liteRtTensorBuffer.bufferType().value;if(r!==e.LiteRtTensorBufferType.WEB_GPU_BUFFER.value&&r!==e.LiteRtTensorBufferType.WEB_GPU_BUFFER_FP16.value&&r!==e.LiteRtTensorBufferType.WEB_GPU_BUFFER_PACKED.value)throw new Error("Cannot convert a Tensor with host memory to a GPUBuffer.");if(this.liteRtTensorBuffer.size()!==this.liteRtTensorBuffer.packedSize()||this.liteRtTensorBuffer.offset()!==0)throw new Error("Tensors with strides or padding are not yet supported.");let n=this.liteRtTensorBuffer.getWebGpuBuffer();return e.WebGPU.getJsObject(n)}getCopyFunctionSet(e){this.ensureNotDeleted();let r=this.getBufferType(),n=Mr.copyFunctions.get(r);if(!n)throw new Error(`TensorBufferType ${en[r]??r} does not support copying or moving`);let s=typeof e=="string"?P2[e]:e;if(s==null)throw new Error(`Unknown destination '${e}' for copying or moving.`);let o=n.get(s);if(!o){let a=[...n].map(([i])=>en[i]??i);throw new Error(`TensorBufferType ${en[r]} does not support copying or moving to ${en[s]}. It supports the following TensorBufferTypes: [${a.join(", ")}].`)}return[o,s]}async copyTo(e,r){let[n,s]=this.getCopyFunctionSet(e);if(!n.copyTo)throw new Error(`Copying to ${en[s]} is not supported by this tensor.`);return n.copyTo(this,r)}async moveTo(e,r){let[n,s]=this.getCopyFunctionSet(e);if(!n.moveTo)throw new Error(`Moving to ${en[s]} is not supported by this tensor.`);return n.moveTo(this,r)}get bufferType(){return this.liteRtTensorBuffer.bufferType().value}get accelerator(){let e=L2[this.bufferType];if(e===void 0)throw new Error(`TensorBufferType ${en[this.bufferType]} has an unknown accelerator type.`);return e}get deleted(){return this.deletedInternal}delete(){this.deletedInternal||(this.deletedInternal=!0,this.liteRtTensorBuffer.delete(),this.onDelete?.())}},Le(Mr,"copyFunctions",new Map),Mr);function z2(t){let e=t.tensorType(),r=e.elementType(),n=e.layout(),s=n.dimensions();return n.delete(),e.delete(),{dtype:tn(r.value).dtype,layout:{dimensions:ws(s)}}}function H2(t,e,r,n){let o=ct().liteRtWasm,a=new o.VectorInt32;Wh(e,a);let i=o.LiteRtLayout.create(a);a.delete();let u=o.LiteRtRankedTensorType.create({value:tn(r).elementType},i);i.delete();let l=o.WebGPU.importJsBuffer(t),c=o.LiteRtTensorBuffer.createFromWebGpuBuffer(n.liteRtEnvironment,u,o.LiteRtTensorBufferType.WEB_GPU_BUFFER_PACKED,l,t.size);return u.delete(),[c,l]}function j2(t,e,r){let n=ct(),s=n.liteRtWasm;r=r??n.getDefaultEnvironment();let o=tn(t).elementType,a=new s.VectorInt32;Wh(e??[t.length],a);let i=s.LiteRtLayout.create(a);a.delete();let u=i.numElements();if(t.length!==u)throw i.delete(),new Error(`Number of elements ${t.length} of the provided TypedArray does not match the expected number of elements ${u}.`);let l=s.LiteRtRankedTensorType.create({value:o},i);i.delete();let f=t.constructor.BYTES_PER_ELEMENT*t.length,d=l.bytes();if(f!==d)throw l.delete(),new Error(`Byte length ${f} of the provided TypedArray does not match the expected buffer size ${d}.`);let p=s.LiteRtTensorBuffer.createManaged(r.liteRtEnvironment,s.LiteRtTensorBufferType.HOST_MEMORY,l,f);l.delete();let b=p.lock(s.LiteRtTensorBufferLockMode.WRITE);try{let E=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);s.HEAPU8.set(E,b)}finally{p.unlock()}return p}var X2=class{constructor(t,e,r,n){Le(this,"inputDetails");Le(this,"outputDetails");Le(this,"liteRtSimpleSignature");Le(this,"deletedInternal",!1);this.signatureIndex=t,this.liteRtModel=e,this.liteRtCompiledModel=r,this.options=n,this.liteRtSimpleSignature=e.getSignature(t);let s=ws(this.liteRtSimpleSignature.inputNames()),o=[];for(let u=0;u<s.length;u++){let l=s[u],c=e.getInputTensorType(t,u),f=r.getInputBufferRequirements(t,u);o.push(Uh(l,u,c,f))}this.inputDetails=Object.freeze(o);let a=ws(this.liteRtSimpleSignature.outputNames()),i=[];for(let u=0;u<a.length;u++){let l=a[u],c=e.getOutputTensorType(t,u),f=r.getOutputBufferRequirements(t,u);i.push(Uh(l,u,c,f))}this.outputDetails=Object.freeze(i)}get key(){return this.ensureNotDeleted(),this.liteRtSimpleSignature.key()}getInputDetails(){return this.ensureNotDeleted(),this.inputDetails}getOutputDetails(){return this.ensureNotDeleted(),this.outputDetails}async run(t){this.ensureNotDeleted();let e=this.inputsToArray(t),{inputsOnAccelerator:r,cleanup:n}=await this.ensureInputsOnAccelerator(e),s;try{s=await this.runWithArray(r)}finally{n()}return Array.isArray(t)||t instanceof qt?s:this.outputsToRecord(s)}inputsToArray(t){if(Array.isArray(t)){if(t.length!==this.inputDetails.length)throw new Error(`run() called with ${t.length} inputs, but signature expects ${this.inputDetails.length} inputs`);return t}if(t instanceof qt){if(this.inputDetails.length!==1)throw new Error(`run() called with a single tensor, but signature expects ${this.inputDetails.length} inputs`);return[t]}let e=[];for(let r of this.inputDetails){if(!(r.name in t))throw new Error(`run() called with input record that is missing input ${r.name} with index ${r.index}`);e.push(t[r.name])}return e}outputsToRecord(t){let e={};for(let r=0;r<this.outputDetails.length;r++)e[this.outputDetails[r].name]=t[r];return e}async ensureInputsOnAccelerator(t){let e=[],r=[],n=this.getInputDetails();if(t.length!==n.length)throw new Error(`ensureInputsOnAccelerator() called with ${t.length} inputs, but signature expects ${n.length} inputs`);for(let s=0;s<t.length;s++){let o=t[s],a=o.getBufferType(),i=n[s].supportedBufferTypes;if(i.size===0)throw new Error(`Tensor ${n[s].name} with index ${n[s].index} has no supported buffer types.`);if(i.has(a))r.push(o);else{let u=i.values().next().value,l=await o.copyTo(u);e.push(l),r.push(l)}}return{inputsOnAccelerator:r,cleanup:()=>{for(let s of e)s.delete()}}}async runWithArray(t){for(let r=0;r<t.length;r++){let n=t[r],s=this.liteRtModel.getInputTensorType(this.signatureIndex,r),o=this.liteRtCompiledModel.getInputBufferRequirements(this.signatureIndex,r);ct().liteRtWasm.checkTensorBufferCompatible(n.liteRtTensorBuffer,s,o),s.delete(),o.delete()}return(await this.liteRtCompiledModel.run(this.signatureIndex,t.map(r=>r.liteRtTensorBuffer))).map(r=>new qt(r,this.options.environment))}get deleted(){return this.deletedInternal}ensureNotDeleted(){if(this.deleted)throw new Error("CompiledModelSignatureRunner is deleted and cannot be used.")}delete(){this.deletedInternal||(this.deletedInternal=!0,this.liteRtSimpleSignature.delete())}};function Uh(t,e,r,n){let s=r.layout(),o=ws(s.dimensions());s.delete();let a=new Set(ws(n.supportedTypes()).map(({value:u})=>u)),i={name:t,index:e,dtype:tn(r.elementType().value).dtype,shape:new Int32Array(o),supportedBufferTypes:a};return r.delete(),n.delete(),i}var Y2=class{constructor(t,e,r,n){Le(this,"defaultSignature");Le(this,"compiledModelSignatureRunners");Le(this,"key");Le(this,"deletedInternal",!1);this.model=t,this.liteRtCompiledModel=e,this.options=r,this.onDelete=n;let s=t.liteRtModel.getNumSignatures(),o={};for(let a=0;a<s;a++){let i=new X2(a,t.liteRtModel,e,r);o[i.key]=i}this.compiledModelSignatureRunners=Object.freeze(o),this.defaultSignature=Object.values(this.signatures)[0],this.key=this.defaultSignature.key}get signatures(){return this.ensureNotDeleted(),this.compiledModelSignatureRunners}getInputDetails(){return this.ensureNotDeleted(),this.defaultSignature.getInputDetails()}getOutputDetails(){return this.ensureNotDeleted(),this.defaultSignature.getOutputDetails()}async run(t,e){this.ensureNotDeleted();let[r,n]=this.parseRunInputs(t,e);return await r.run(n)}parseRunInputs(t,e){let r,n;if(typeof t=="string"){if(r=this.signatures[t],!r)throw new Error(`No signature named ${t} found in model.`);if(!e)throw new Error(`No input provided for signature ${t}`);n=e}else r=this.defaultSignature,n=t;return[r,n]}get deleted(){return this.deletedInternal}ensureNotDeleted(){if(this.deleted)throw new Error("CompiledModel is deleted and cannot be used.")}get isFullyAccelerated(){return this.ensureNotDeleted(),this.liteRtCompiledModel.isFullyAccelerated()}delete(){if(!this.deletedInternal){this.deletedInternal=!0,this.liteRtCompiledModel.delete(),this.model.delete();for(let t of Object.values(this.compiledModelSignatureRunners))t.delete();this.onDelete()}}};async function q2(t){let e=await fetch(t);return new Uint8Array(await e.arrayBuffer())}async function K2(t){let e=0,r=new Uint8Array(1024),n=2e9;for(;;){let{done:s,value:o}=await t.read();if(o){if(r.byteLength<e+o.byteLength){if(e+o.byteLength>n)throw new Error(`Model is too large (> ${n} bytes).`);let a=new Uint8Array(Math.min(n,Math.max(r.byteLength,o.byteLength)*2));a.set(r),r=a}r.set(o,e),e+=o.byteLength}if(s)break}return r.slice(0,e)}var Z2=class{constructor(t,e){this.liteRtModel=t,this.onDelete=e}delete(){this.liteRtModel.delete(),this.onDelete()}};function J2(t={},e,r){return{environment:e,accelerator:t.accelerator??(e.webGpuDevice?"webgpu":"wasm"),cpuOptions:t.cpuOptions??{numThreads:r},gpuOptions:t.gpuOptions??{},webNNOptions:t.webNNOptions??{}}}var Q2=new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,15,1,13,0,65,1,253,15,65,2,253,15,253,128,2,11]),eg=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11]),Tt={relaxedSimd:void 0,threads:void 0,jspi:void 0,webnn:void 0};function $h(){return"Suspending"in WebAssembly}function tg(){return typeof navigator<"u"&&!!navigator.ml}async function Fh(t){try{return await WebAssembly.instantiate(t),{supported:!0}}catch(e){return{supported:!1,error:e}}}var zh={relaxedSimd:()=>(Tt.relaxedSimd===void 0&&(Tt.relaxedSimd=Fh(Q2)),Tt.relaxedSimd),threads:()=>{if(Tt.threads===void 0)try{typeof MessageChannel<"u"&&new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)),Tt.threads=Fh(eg)}catch(t){Tt.threads=Promise.resolve({supported:!1,error:t})}return Tt.threads},jspi:()=>{if(Tt.jspi===void 0){let t=$h();Tt.jspi=Promise.resolve({supported:t,error:t?void 0:new Error("JSPI is not supported")})}return Tt.jspi},webnn:()=>{if(Tt.webnn===void 0){let t=tg();Tt.webnn=Promise.resolve({supported:t,error:t?void 0:new Error("WebNN is not supported")})}return Tt.webnn}};async function rg(t){let e=zh[t]?.();if(!e)throw new Error(`Unknown feature: ${t}`);return(await e).supported}async function Ph(t){let e=zh[t]?.();if(!e)throw new Error(`Unknown feature: ${t}`);let r=await e;if(!r.supported)throw r.error}var ng=class{constructor(t){Le(this,"liteRtWasm");Le(this,"defaultEnvironment");Le(this,"objectsToDelete",new Set);this.liteRtWasm=t,this.liteRtWasm.setupLogging()}setDefaultEnvironment(t){this.defaultEnvironment=t}getDefaultEnvironment(){if(!this.defaultEnvironment)throw new Error("Default environment is not set.");return this.defaultEnvironment}setWebGpuDevice(t){let e=this.getDefaultEnvironment();this.setDefaultEnvironment(new Ts({...e.options,webGpuDevice:t}))}getWebGpuDevice(){return this.getDefaultEnvironment().webGpuDevice}_registerObjectForDeletion(t){this.objectsToDelete.add(t)}_unregisterObjectForDeletion(t){this.objectsToDelete.delete(t)}async loadAndCompile(t,e={}){let r;if(typeof t=="string"||t instanceof URL)r=await q2(t);else if(t instanceof Uint8Array)r=t;else if(t instanceof ReadableStreamDefaultReader)r=await K2(t);else throw new Error("Unsupported model type.");let n=e.environment??this.getDefaultEnvironment(),s=e.accelerator??(n.webGpuDevice?"webgpu":"wasm"),o=s==="webgpu";if(o&&!n.webGpuDevice)throw new Error("WebGPU was requested but no WebGPU device is set in the environment.");let a=J2(e,n,this.liteRtWasm.getThreadCount()),i=this.liteRtWasm._malloc(r.byteLength);this.liteRtWasm.HEAPU8.set(r,i);let u=this.liteRtWasm.loadModel(a.environment.liteRtEnvironment,i,r.byteLength),l=await this.liteRtWasm.compileModel(a.environment.liteRtEnvironment,u,a),c=new Z2(u,()=>{this.liteRtWasm._free(i)}),f=new Y2(c,l,a,()=>{this.objectsToDelete.delete(f)});if(this.objectsToDelete.add(f),(o||s==="webnn")&&!f.isFullyAccelerated)if($h())console.warn(`%c[LiteRT]%c Model not fully compiled for ${s}. Partially delegating to WASM execution.`,"background: #FFA000; color: black; font-weight: bold; padding: 2px 5px; border-radius: 3px;","font-weight: bold;");else{console.warn(`%c[LiteRT]%c Model not fully compiled for ${s} on non-JSPI browser. Falling back to WASM execution.`,"background: #D32F2F; color: white; font-weight: bold; padding: 2px 5px; border-radius: 3px;","color: #D32F2F; font-weight: bold;"),f.delete();let b={...e,accelerator:"wasm"};return this.loadAndCompile(r,b)}return f}delete(){for(let t of this.objectsToDelete)t.delete()}};function sg(t,e){if(!t)return e;if(!e)return t;let r=t.endsWith("/")?t:t+"/",n=e.startsWith("/")?e.substring(1):e;return r+n}var og="litert_wasm_internal.js",ag="litert_wasm_compat_internal.js",ig="litert_wasm_threaded_internal.js",ug="litert_wasm_jspi_internal.js";async function cg(t,e){let r=t,n=r.endsWith(".wasm")||r.endsWith(".js"),s=await rg("relaxedSimd");if(e?.threads){if(e?.jspi)throw new Error("The `threads` and `jspi` options are mutually exclusive.");if(n&&console.warn(`The \`threads\` option was specified, but the wasm path ${r} is a full file path. Whether threads are available or not will depend on the loaded file. To allow LiteRT.js to load the threaded wasm file, use a directory path instead of a full file path.`),!s)throw new Error("Threads are only supported with relaxed SIMD, and the current browser does not support relaxed SIMD.");await Ph("threads")}e?.jspi&&(n&&console.warn(`The \`jspi\` option was specified, but the wasm path ${r} is a full file path. Whether JSPI is available or not will depend on the loaded file. To allow LiteRT.js to load the JSPI wasm file, use a directory path instead of a full file path.`),await Ph("jspi"));let o=ag;s&&(e?.threads?o=ig:e?.jspi?o=ug:o=og);let a=t;if(r.endsWith(".wasm"))throw new Error("Please load the `.js` file corresponding to the `.wasm` file, or load the directory containing it.");return r.endsWith(".js")||(a=sg(t,o)),Ch(ng,a)}function Hh(t,e){if(Gh())throw new Error("LiteRT is already loading / loaded.");return Yu(cg(t,e).then(async r=>(Nh(r),r.setDefaultEnvironment(await Ts.create()),r)).catch(r=>{throw Yu(void 0),r})),F2()}function jh(){if(Gh()&&!Bh())throw new Error("LiteRT is loading and can not be unloaded or canceled until it is finished loading.");Bh()&&(ct().delete(),Nh(void 0)),Yu(void 0)}var b4=Promise.resolve();async function Lh(t,e={}){let r=e.environment??t.environment,n=ct().liteRtWasm,s=t.liteRtTensorBuffer;if(s.bufferType().value!==je.HOST_MEMORY)throw new Error("Source tensor is not in host memory. Cannot copy to host memory.");let a=s.lock(n.LiteRtTensorBufferLockMode.READ),i;try{i=n.LiteRtTensorBuffer.createManaged(r.liteRtEnvironment,n.LiteRtTensorBufferType.HOST_MEMORY,s.tensorType(),s.size());let u=i.lock(n.LiteRtTensorBufferLockMode.WRITE);try{let l=new Uint8Array(n.HEAPU8.buffer,a,s.size());n.HEAPU8.set(l,u)}finally{i.unlock()}}finally{s.unlock()}if(!i)throw new Error("Failed to create destination tensor buffer.");return new qt(i,r)}async function Oh(t,e={}){let r=e.environment??t.environment,n=r.webGpuDevice;if(!n)throw new Error("No WebGPU device is available. Did you forget to pass a destination environment that has a WebGPU device?");let s=ct().liteRtWasm,a=t.liteRtTensorBuffer.size()+3&-4,i=n.createBuffer({size:a,usage:GPUBufferUsage.MAP_WRITE|GPUBufferUsage.COPY_SRC,mappedAtCreation:!0}),u=await i.getMappedRange(),l=new Uint8Array(u),c=t.liteRtTensorBuffer.lock(s.LiteRtTensorBufferLockMode.READ);try{let p=new Uint8Array(s.HEAPU8.buffer,c,t.liteRtTensorBuffer.size());l.set(p)}finally{t.liteRtTensorBuffer.unlock()}i.unmap();let f=n.createBuffer({size:a,usage:GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST|GPUBufferUsage.STORAGE}),d=n.createCommandEncoder();return d.copyBufferToBuffer(i,0,f,0,a),n.queue.submit([d.finish()]),i.destroy(),new qt(f,t.type.layout.dimensions,t.type.dtype,r,()=>{f.destroy()})}async function Dh(t,e={}){let r=e.environment??t.environment,n=t.environment.webGpuDevice;if(!n)throw new Error("No WebGPU device is available. Does the source tensor have a WebGPU device?");let s=ct().liteRtWasm,o=t.liteRtTensorBuffer,a=o.bufferType();if(a!==s.LiteRtTensorBufferType.WEB_GPU_BUFFER_PACKED)throw new Error(`Cannot convert a tensor with a non-WebGPU buffer type ${a} to a CPU tensor.`);let i=s.WebGPU.getJsObject(o.getWebGpuBuffer()),u=o.offset(),l=o.tensorType(),c=l.layout(),f=c.numElements(),d=tn(l.elementType().value).typedArrayConstructor;c.delete(),l.delete();let p=i,b=()=>{};if(!(i.usage&GPUBufferUsage.MAP_READ)){p=n.createBuffer({size:i.size,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),b=()=>{p.destroy()};let _=n.createCommandEncoder();_.copyBufferToBuffer(i,0,p,0,i.size),n.queue.submit([_.finish()])}await p.mapAsync(GPUMapMode.READ);let E=p.getMappedRange(),A=new d(E,u,f),I=new qt(A,t.type.layout.dimensions,r);return p.unmap(),b(),I}function Xu(t){return async(e,r)=>{let n=await t(e,r);return e.delete(),n}}function lg(){qt.copyFunctions.set(je.HOST_MEMORY,new Map([[je.HOST_MEMORY,{copyTo:Lh,moveTo:Xu(Lh)}],[je.WEB_GPU_BUFFER_PACKED,{copyTo:Oh,moveTo:Xu(Oh)}]])),qt.copyFunctions.set(je.WEB_GPU_BUFFER_PACKED,new Map([[je.HOST_MEMORY,{copyTo:Dh,moveTo:Xu(Dh)}]]))}lg();var Xh=()=>{let t=new Map,e,r,n,s=!1,o=async(d,p)=>{r&&f(),r=await Hh(d,p),s=!0},a=async d=>{n?.delete(),n=await Ts.create(d)},i=async(d,p)=>{C(r,"Runtime has not been populated!"),u(d);let b=await r.loadAndCompile(d,{environment:n,...p});t.set(d,b),e=d},u=d=>{t.get(d)?.delete(),t.delete(d),e===d&&(e=void 0)},l=(d=e)=>{let p=d===void 0?void 0:t.get(d);return C(p,"Model has not been compiled!"),p};function c(d,p){return p?l(d).run(p):l().run(d)}let f=()=>{for(let d of t.values())d.delete();n?.delete(),r?.delete(),s=!1,r=void 0,n=void 0,e=void 0,t.clear(),jh()};return{init:o,prepareEnv:a,loadModel:i,unloadModel:u,release:f,run:c,get initialized(){return s},getEnvironment(){return n},get environment(){return n},getSignatures(d){return t.get(d)?.signatures},get signatures(){return e===void 0?void 0:t.get(e)?.signatures},getInputs(d){return t.get(d)?.getInputDetails()},get inputs(){return e===void 0?void 0:t.get(e)?.getInputDetails()},getOutputs(d){return t.get(d)?.getOutputDetails()},get outputs(){return e===void 0?void 0:t.get(e)?.getOutputDetails()}}};var fg=(t,e,r)=>{let n=t.length/4;if(!Number.isInteger(n)||e.length!==n*3)throw new Error("RGBA and RGB tensor buffer sizes do not match");let s=e instanceof Float32Array;for(let o=0;o<n;o++){let a=o*4;for(let i=0;i<3;i++){let u=r==="nhwc"?o*3+i:i*n+o,l=t[a+i]??0;e[u]=s?l/255:l}}return e},dg=(t,e,r,n,s=r,o=n)=>{if(t<=0||e<=0||r<=0||n<=0||s<=0||o<=0)throw new Error("Source, processing, and model dimensions must be positive");let a=Ao(t,e,s,o),i=Math.min(r/s,n/o),u=s*i,l=o*i;return{sx:a.sx,sy:a.sy,sw:a.sw,sh:a.sh,dx:(r-u)/2,dy:(n-l)/2,dw:u,dh:l}},Yh=(t,e,r)=>{let n=cs(t),s=Mt(n.width,n.height),o=ut(s,{alpha:!1}),a=new Uint8Array(n.width*n.height*4),i=n.dtype==="float32"?new Float32Array(n.width*n.height*3):new Uint8Array(n.width*n.height*3),u;return{metadata:n,process:async f=>{if(!s||!o||!a)throw new Error("The preprocessor has been released");let d=vs(f),p=dg(d.width,d.height,n.width,n.height,e??n.width,r??n.height);o.clearRect(0,0,n.width,n.height),o.drawImage(f,p.sx,p.sy,p.sw,p.sh,p.dx,p.dy,p.dw,p.dh);let b=new VideoFrame(s,{timestamp:f.timestamp??performance.now()*1e3});try{await b.copyTo(a,{format:"RGBA"})}finally{b.close()}return fg(a,i,n.layout),u?.delete(),u=new qt(i,Array.from(n.shape)),{[n.name]:u}},release:()=>{u?.delete(),u=void 0,i=new Uint8Array,a=void 0,o=void 0,s&&(s.width=0,s.height=0),s=void 0},get canvas(){return s},get pixelBuffer(){return a},get tensorStorage(){return i}}};var hg=(t,e,r)=>{let n=r.width*r.height;if(e.length!==n||t.length!==n*r.channels)throw new Error("Output tensor and mask buffer sizes do not match");let s=t instanceof Float32Array;for(let o=0;o<n;o++){let a=r.layout==="nhwc"?o*r.channels+r.channels-1:(r.channels-1)*n+o,i=t[a]??0;e[o]=s?Math.round(Math.min(1,Math.max(0,i))*255):i}return e},qh=(t,e=(n,s)=>Mt(n,s),r=(n,s)=>new ImageData(n,s))=>{let n=cs(t,[1,2]),s=e(n.width,n.height),o=ut(s),a=new Uint8ClampedArray(n.width*n.height),i=r(n.width,n.height),u=i.data;return{metadata:n,process:async f=>{if(!s||!o||!a||!u||!i)throw new Error("The output processor has been released");let d=f[n.name];if(!d)throw new Error(`Missing model output: ${n.name}`);let p=await d.data();hg(p,a,n);for(let b=0;b<a.length;b++)u[b*4+3]=a[b]??0;return o.putImageData(i,0,0),s},release:()=>{o=void 0,a=void 0,u=void 0,i=void 0,s&&(s.width=0,s.height=0),s=void 0},get canvas(){return s},get maskBuffer(){return a},get imageData(){return i}}};var Kh=t=>typeof t=="string"?Object.values(vd).includes(t):!1;var da=Rd(),Ig=Eh(),m={width:Pr,height:Fr,status:le.New,stats:[],delegate:da?"GPU":"CPU",modelAssetPath:"",visionBasePath:"/",litertjsCoreBasePath:"",muted:!1,renderOptions:{edgeBlurAmount:4,backgroundBlurAmount:3,backgroundThreshold:.35,foregroundThreshold:.85,maskCombineRatio:.8,effects:bd.None,sigmaRangeHi:ru[1],sigmaRangeLo:ru[0],sigmaSpace:_d,backgroundImageUrl:"",backgroundImage:null,backend:"webgl",personCenter:xd,excludeBystanders:!1,morphPass:4,morphErodeRadiusPx:5,morphDilateRadiusPx:6,lightWrapIntensity:.8,lightWrapTightness:1,downSampleFactor:2,lightWrapBlurAmount:1,lightWrapEdgeBand:.25}},tc=Eo(m.renderOptions),rc=()=>{m.trackEventsSubscription?.(),m.originalTrack?.stop()},Ie=(t,e)=>postMessage(t,e??[]),Sg=t=>{if(m.status!==le.Error){m.status=le.Error;try{m.segmenter?.close()}catch(e){Ie({type:"event",data:{type:M.ContextLost,message:`Failed to close segmenter ${e}`}})}m.segmenter=void 0}Ie({type:"event",data:{type:M.ContextLost,message:t}})},Cg=t=>{Ie({type:"event",data:{type:M.ContextRestored,message:t}})},Bg=t=>{m.status!==le.Error&&(m.status=le.Error),Ie({type:"event",data:{type:M.ContextCreationError,message:t}})},fa=async t=>{m.inferencer!==void 0&&(m.canvasPreprocessor?.release(),m.canvasSelfiePostprocessor?.release(),m.inferencer?.release(),m.canvasPreprocessor=void 0,m.canvasSelfiePostprocessor=void 0,m.inferencer=void 0,m.loadedModelAssetPath=void 0);let r=Xh();try{await r.init(t,{jspi:!0})}catch{try{await r.init(t,{jspi:!1})}catch(n){throw r.release(),n}}m.segmenter?.close(),m.segmenter=void 0,m.visionInstance=void 0,m.inferencer=r,m.litertjsCoreBasePath=t},Zu=async t=>{let e=await _r.forVisionTasks(t);m.canvasPreprocessor?.release(),m.canvasSelfiePostprocessor?.release(),m.inferencer?.release(),m.segmenter?.close(),m.canvasPreprocessor=void 0,m.canvasSelfiePostprocessor=void 0,m.inferencer=void 0,m.segmenter=void 0,m.loadedModelAssetPath=void 0,m.visionInstance=e,m.visionBasePath=t},Ug=async()=>{m.renderer?.release(),m.renderer=void 0;let t=[{contextLost:Sg,contextRestored:Cg,contextCreationError:Bg},m.processCanvas],e=()=>{let s=kh(...t);return m.renderOptions.backend="webgl",s},r=()=>{let s=Ih(...t);return m.renderOptions.backend="canvas2d",s},n=navigator.gpu&&m.renderOptions?.backend==="webgpu";if(m.inferencer)m.renderer=r();else if(n){let s=await Gd();s?m.renderer=eh(s,...t):da?m.renderer=e():m.renderer=r()}else m.renderOptions?.backend!=="canvas2d"&&da?m.renderer=e():m.renderer=r();Ie({type:"debug",data:{context:{backend:m.renderOptions.backend},message:"Init renderer"}});try{await m.renderer?.init()}catch(s){if(s instanceof xs&&(m.status===le.Destroying||m.status===le.Destroyed))return;throw s}},Fg=async()=>{if(m.visionInstance&&(m.segmenter?.close(),Ie({type:"debug",data:{context:{delegate:m.delegate,backend:m.renderOptions.backend},message:"Init segmneter"}}),m.segmenter=await qe.createFromOptions(m.visionInstance,{outputCategoryMask:!1,outputConfidenceMasks:!0,runningMode:"VIDEO",...m.renderOptions.backend==="canvas2d"?{}:{canvas:m.segmenterCanvas},baseOptions:{modelAssetPath:m.modelAssetPath,delegate:m.delegate}})),m.inferencer){m.loadedModelAssetPath&&(m.inferencer.unloadModel(m.loadedModelAssetPath),m.loadedModelAssetPath=void 0),m.canvasPreprocessor?.release(),m.canvasSelfiePostprocessor?.release(),m.canvasPreprocessor=void 0,m.canvasSelfiePostprocessor=void 0,await m.inferencer.loadModel(m.modelAssetPath,{accelerator:"wasm"}),m.loadedModelAssetPath=m.modelAssetPath;let t=m.inferencer.getInputs(m.modelAssetPath)?.[0];C(t,"TensorInput is undefined"),m.canvasPreprocessor=Yh(t,m.width,m.height);let e=m.inferencer.getOutputs(m.modelAssetPath)?.[0];C(e,"TensorOutput is undefined"),m.canvasSelfiePostprocessor=qh(e)}},nc=async t=>{m.segmenterTextureToCanvas?.release(),m.segmenterTextureToCanvas=void 0,m.segmenterMaskToCanvas=void 0,m.segmenterCanvas=t,m.renderOptions.backend==="canvas2d"?(m.segmenterCanvasContext="canvas2d",m.segmenterMaskToCanvas=Ah(m.segmenterCanvas)):(m.segmenterCanvasContext="webgl",m.segmenterTextureToCanvas=ia(m.segmenterCanvas)),await Fg()},sc=async t=>{m.processCanvas=t,await Ug(),m.processCanvasContext=m.renderOptions.backend},ha=(t,e)=>{switch(e){case"webgl":{t?.getContext("webgl2")?.getExtension("WEBGL_lose_context")?.loseContext();break}case"webgpu":{t?.getContext("webgpu")?.unconfigure();break}default:break}},Pg=async()=>{m.renderer?.release(),m.renderer=void 0,m.segmenterTextureToCanvas?.release(),m.segmenterTextureToCanvas=void 0,m.segmenter?.close(),m.segmenter=void 0,ha(m.processCanvas,m.processCanvasContext),ha(m.segmenterCanvas,m.segmenterCanvasContext),m.processCanvas=void 0,m.processCanvasContext=void 0,m.segmenterCanvas=void 0,m.segmenterCanvasContext=void 0,await sc(Mt(m.width,m.height)),await nc(Mt(m.width,m.height))},Ju=()=>{m.muted=!0,m.originalTrack&&(m.originalTrack.enabled=!1)},Qu=()=>{m.muted=!1,m.originalTrack&&(m.originalTrack.enabled=!0)},Lg=t=>(t.addEventListener("mute",Ju),t.addEventListener("unmute",Qu),t.addEventListener("ended",ec),()=>{t.removeEventListener("mute",Ju),t.removeEventListener("unmute",Qu),t.removeEventListener("ended",ec)}),Zh=t=>{let e={},{backgroundImage:r,...n}=m.renderOptions,s=gd(n,t);for(let[o,a]of Object.entries(s.changed))e[o]=a.new;return e},Jh=t=>{t==="CPU"?m.delegate="CPU":da?m.delegate="GPU":m.delegate="CPU"},Og=async(t={})=>{try{m.status=le.Opening,t.processingWidth&&(m.width=t.processingWidth),t.processingHeight&&(m.height=t.processingHeight);let e={};t.renderOptions&&(e=Zh(t.renderOptions),tc(t.renderOptions));let r=m.renderOptions.backend,{basePath:n,litertjsCoreBasePath:s,imageSegmenterOptions:o={}}=t;if(m.modelAssetPath=o.modelAsset?.path??m.modelAssetPath,s?await fa(s):(Jh(o.delegate),await Zu(n??m.visionBasePath)),m.backgroundImages?.clear(),m.backgroundImages=wd(t.backgroundImage&&[[t.backgroundImage.key,t.backgroundImage.image]]),t.renderOptions?.backgroundImageUrl&&t.backgroundImage?.key!==t.renderOptions.backgroundImageUrl){let a=await oc(t.renderOptions.backgroundImageUrl);a&&(m.renderOptions.backgroundImage=a)}await sc(Mt(m.width,m.height)),await nc(Mt(m.width,m.height)),r!==m.renderOptions.backend&&(e.backend=m.renderOptions.backend),m.status=le.Opened,Ie({type:"opened",data:e})}catch(e){m.status=le.Error;let r=us(e);Ie({type:"event",data:{type:is(r),message:r}})}},Dg=Math.trunc(30*.8),pa=t=>{m.stats.push(t),m.stats.length>=Dg&&(Wg(),m.stats.length=0)},Mg={async transform(t,e){let r=performance.now();if(m.renderOptions.effects==="none"||m.muted){pa({start:r,end:r}),e.enqueue(t);return}C(m.segmenter);let n;try{n=m.segmenter.segmentForVideo(t,r);let s=performance.now(),o=t.timestamp,a=n.confidenceMasks?.[0];if(a){C(m.renderer),C(m.processCanvas),C(m.segmenterCanvas),m.segmenterMaskToCanvas?m.segmenterMaskToCanvas.render(Ig(a)):(C(m.segmenterTextureToCanvas),m.segmenterTextureToCanvas.render(ih(a))),a.close(),m.renderer.render(m.segmenterCanvas,t,m.renderOptions),t.close();let i=new VideoFrame(m.processCanvas,{timestamp:o});e.enqueue(i)}else e.enqueue(t);pa({start:r,segmentation:s,end:performance.now()})}catch(s){e.enqueue(t),s instanceof Error&&(m.status=le.Error,Ie({type:"event",data:{type:"Error",error:s}}))}finally{n?.close()}}},Ng={async transform(t,e){let r=performance.now();if(m.renderOptions.effects==="none"||m.muted){pa({start:r,end:r}),e.enqueue(t);return}C(m.canvasPreprocessor),C(m.canvasSelfiePostprocessor),C(m.inferencer),C(m.renderer),C(m.processCanvas);let n=t.timestamp,s=r,o;try{let a=await m.canvasPreprocessor.process(t);o=await m.inferencer.run(m.modelAssetPath,a);let i=await m.canvasSelfiePostprocessor.process(o);s=performance.now(),m.renderer.render(i,t,m.renderOptions),t.close();let u=new VideoFrame(m.processCanvas,{timestamp:n});e.enqueue(u)}catch(a){e.enqueue(t),a instanceof Error&&(m.status=le.Error,Ie({type:"event",data:{type:"Error",error:a}}))}finally{if(pa({start:r,segmentation:s,end:performance.now()}),o)for(let a of Object.values(o))a.delete()}}},ks=Promise.resolve(),Es=Promise.resolve(),Gg={async transform(t,e){await Es;let r=m.inferencer?Ng.transform:Mg.transform;C(r);let n=Promise.resolve(r(t,e));ks=n;try{await n}finally{ks===n&&(ks=Promise.resolve())}}},Qh=async(t,e,r)=>t.pipeThrough(new TransformStream(Gg),{signal:r}).pipeTo(e),Vg=async(t,e)=>{let r=new VideoTrackGenerator;Ie({type:"processed",data:r.track},[r.track]);let{readable:n}=new MediaStreamTrackProcessor({track:t});try{await Qh(n,r.writable,e)}catch(s){if(rc(),e&&!(e.aborted&&(e.reason==="close"||!("reason"in AbortSignal.prototype))))throw s}},oc=t=>(m.imageFetcherAbortController?.abort("close"),m.imageFetcherAbortController=new AbortController,m.backgroundImages?.tryFetchingImage(t,m.imageFetcherAbortController.signal)),Wg=()=>{m.stats.length&&(Ie({type:"stats",data:m.stats}),m.stats.length=0)},$g=async(t,e,r,n)=>{try{if(C(m.inferencer||m.segmenter,"No segmenter or inferencer available"),C(t||e&&r),n&&tc(n),C(!m.renderer?.isContextLost(),M.ContextLost),m.renderOptions?.effects==="overlay"&&m.renderOptions.backgroundImageUrl){let s=m.backgroundImages?.getImage(m.renderOptions.backgroundImageUrl);if(s)m.renderOptions.backgroundImage=s;else{let o=await oc(m.renderOptions.backgroundImageUrl);o&&(m.renderOptions.backgroundImage=o)}}m.status=le.Processing,m.processingAbortController=new AbortController,m.stats.length=0,t?(rc(),m.originalTrack=t,m.muted=!t.enabled,m.trackEventsSubscription=Lg(t),await Vg(t,m.processingAbortController.signal)):(C(e&&r),Ie({type:"processed"}),await Qh(e,r,m.processingAbortController.signal))}catch(s){let o=us(s);if(o==="close")return;if(s instanceof Error)return m.status=le.Error,Ie({type:"event",data:{type:is(o),error:s,message:o,track:t}},t?[t]:[]);throw s}},zg=async({backgroundImage:t,basePath:e,renderOptions:r,imageSegmenterOptions:n,litertjsCoreBasePath:s,processingHeight:o,processingWidth:a,restart:i})=>{if(m.status===le.Updating)return;let u={delegate:m.delegate,height:m.height,litertjsCoreBasePath:m.litertjsCoreBasePath,modelAssetPath:m.modelAssetPath,renderOptions:{...m.renderOptions},usingInferencer:m.inferencer!==void 0,visionBasePath:m.visionBasePath,width:m.width},l=!1;try{if(m.status=le.Updating,t&&(m.backgroundImages?.setImage(t.key,t.image),m.renderOptions.backgroundImageUrl===t.key&&(m.renderOptions.backgroundImage=t.image)),r?.backgroundImageUrl){let b=await oc(r.backgroundImageUrl);b&&(m.renderOptions.backgroundImage=b)}let c=i;if(o&&o!==m.height&&(m.height=o,c=!0),a&&a!==m.width&&(m.width=a,c=!0),m.inferencer){let b=n?.modelAsset?.path;b&&b!==m.modelAssetPath&&(c=!0),s&&s!==m.litertjsCoreBasePath&&(l=!0,await fa(s),c=!0),n?.delegate!=="CPU"&&!s&&(l=!0,await Zu(e??m.visionBasePath),c=!0)}else s&&(l=!0,await fa(s),c=!0);if(r?.backend&&!Kh(r.backend)){m.status=le.Error,Ie({type:"event",data:{type:"Error",message:"Render backend is not webgl, webgpu, or canvas2d"}});return}r?.effects&&r.effects!==m.renderOptions.effects&&(m.stats.length=0);let f=r?.backend&&r?.backend!==m.renderOptions.backend,d={};r&&(d=Zh(r),tc(r)),n&&(m.modelAssetPath=n.modelAsset?.path??m.modelAssetPath,Jh(n.delegate));let p=m.renderOptions.backend;(c||f)&&(l=!0,await Pg()),p!==m.renderOptions.backend&&(d.backend=m.renderOptions.backend),m.status=le.Updated,Ie({type:"updated",data:d}),c&&Ie({type:"event",data:{type:M.ProcessorRestarted}})}catch(c){let f=c;if(l)try{m.width=u.width,m.height=u.height,m.modelAssetPath=u.modelAssetPath,m.delegate=u.delegate;let{backgroundImage:p,backgroundImageUrl:b}=m.renderOptions;Object.assign(m.renderOptions,u.renderOptions),m.renderOptions.backgroundImage=p,m.renderOptions.backgroundImageUrl=b,u.usingInferencer?await fa(u.litertjsCoreBasePath):await Zu(u.visionBasePath),await sc(Mt(u.width,u.height)),await nc(Mt(u.width,u.height)),m.status=le.Updated;let E=us(c);Ie({type:"event",data:{type:is(E),message:E,recoverable:!0}}),Ie({type:"updated",data:{}});return}catch(p){f=new AggregateError([c,p],"Processor update and rollback failed")}m.status=le.Error;let d=us(f);Ie({type:"event",data:{type:is(d),message:d}})}},Hg=t=>{let e=Es.then(async()=>{await ks,await zg(t)});return Es=e.catch(()=>{}),e},jg=()=>{m.status=le.Destroying,m.processingAbortController?.abort("close");let t=Es.then(async()=>{await ks,m.renderer?.release(),Wd(),m.segmenterTextureToCanvas?.release(),m.segmenter?.close(),ha(m.processCanvas,m.processCanvasContext),ha(m.segmenterCanvas,m.segmenterCanvasContext),m.canvasPreprocessor?.release(),m.canvasSelfiePostprocessor?.release(),m.inferencer?.release(),m.backgroundImages?.clear(),m.originalTrack=void 0,m.renderer=void 0,m.segmenter=void 0,m.canvasPreprocessor=void 0,m.canvasSelfiePostprocessor=void 0,m.inferencer=void 0,m.loadedModelAssetPath=void 0,m.backgroundImages=void 0,m.processCanvas=void 0,m.processCanvasContext=void 0,m.segmenterCanvas=void 0,m.segmenterCanvasContext=void 0,m.trackEventsSubscription=void 0,m.status=le.Destroyed});return Es=t.catch(()=>{}),t},Xg=()=>{m.status=le.Idle,m.processingAbortController?.abort("close"),m.imageFetcherAbortController?.abort("close"),rc(),m.processingAbortController=void 0,m.imageFetcherAbortController=void 0},ec=()=>{m.status=le.Closing,Xg(),m.stats.length=0,m.status=le.Closed,Ie({type:"closed"})};self.addEventListener("message",t=>{switch(t.data.type){case"open":{Og(t.data.data);break}case"update":{Hg(t.data.data);break}case"process":{let{track:e,readable:r,writable:n,renderOptions:s}=t.data.data;$g(e,r,n,s);break}case"close":{ec();break}case"mute":{t.data.data?Ju():Qu();break}case"destroy":{jg();break}}});self.addEventListener("error",t=>{t.preventDefault(),Ie({type:"event",data:{type:M.Error,message:`Uncaught Error event: ${t.error}`}})});