@pexip/media-processor 20.3.5 → 22.0.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.
- package/CHANGELOG.md +109 -0
- package/README.md +17 -10
- package/api-docs/README.mdx +69 -23
- package/api-docs/functions/assertMediaStreamVideoTrack.mdx +13 -0
- package/api-docs/functions/createBenchmark.mdx +17 -5
- package/api-docs/functions/createFrameCallbackRequest.mdx +8 -2
- package/api-docs/functions/createMediaStreamTrackInputProcessAdaptor.mdx +10 -0
- package/api-docs/functions/createReadWritableStreamFallbackInputProcessAdaptor.mdx +17 -0
- package/api-docs/functions/createReadWritableStreamInputProcessAdaptor.mdx +10 -0
- package/api-docs/functions/createVideoProcessor.mdx +3 -3
- package/api-docs/functions/createWindowedStats.mdx +23 -0
- package/api-docs/functions/getDefaultInputProcessAdaptor.mdx +17 -0
- package/api-docs/functions/iou.mdx +19 -0
- package/api-docs/functions/isMediaStreamVideoTrack.mdx +13 -0
- package/api-docs/functions/labelComponents.mdx +20 -0
- package/api-docs/functions/nearestPowerOfTwo.mdx +21 -0
- package/api-docs/functions/playVideo.mdx +16 -0
- package/api-docs/functions/scoreComponent.mdx +22 -0
- package/api-docs/functions/setVideoElementSrc.mdx +14 -0
- package/api-docs/interfaces/Analyzer.mdx +4 -0
- package/api-docs/interfaces/Benchmark.mdx +26 -2
- package/api-docs/interfaces/FrameTransformStats.mdx +9 -0
- package/api-docs/interfaces/Gain.mdx +4 -0
- package/api-docs/interfaces/ImageSegmenterOptions.mdx +0 -2
- package/api-docs/interfaces/InputProcessAdaptor.mdx +28 -0
- package/api-docs/interfaces/Process.mdx +8 -3
- package/api-docs/interfaces/ProcessEventMute.mdx +6 -0
- package/api-docs/interfaces/ProcessWorkerEventOpened.mdx +7 -0
- package/api-docs/interfaces/ProcessWorkerEventStats.mdx +6 -0
- package/api-docs/interfaces/ProcessWorkerEventUpdated.mdx +7 -0
- package/api-docs/interfaces/ProcessorEvent.mdx +1 -1
- package/api-docs/interfaces/ProcessorOptions.mdx +0 -1
- package/api-docs/interfaces/ProcessorProcessOptions.mdx +3 -1
- package/api-docs/interfaces/ProcessorUpdateOptions.mdx +15 -0
- package/api-docs/interfaces/ReadWritableStream.mdx +12 -0
- package/api-docs/interfaces/Renderer.mdx +2 -2
- package/api-docs/interfaces/RendererOptions.mdx +25 -12
- package/api-docs/interfaces/Segmenter.mdx +89 -10
- package/api-docs/interfaces/SegmenterOptions.mdx +0 -1
- package/api-docs/interfaces/SelectionOptions.mdx +15 -0
- package/api-docs/interfaces/Stats.mdx +11 -0
- package/api-docs/interfaces/VideoProcessor.mdx +49 -5
- package/api-docs/interfaces/Weights.mdx +12 -0
- package/api-docs/type-aliases/OptionalKeys.mdx +10 -0
- package/api-docs/type-aliases/ProcessEvents.mdx +1 -0
- package/api-docs/type-aliases/ProcessInputType.mdx +3 -1
- package/api-docs/type-aliases/ProcessWorkerEvents.mdx +6 -4
- package/api-docs/type-aliases/ProcessorWorkerEvents.mdx +1 -1
- package/api-docs/type-aliases/Struct.mdx +9 -0
- package/api-docs/variables/BACKGROUND_THRESHOLD.mdx +3 -0
- package/api-docs/variables/DOWN_SAMPLE_FACTOR.mdx +3 -0
- package/api-docs/variables/EDGE_BLUR_AMOUNT.mdx +1 -1
- package/api-docs/variables/EXCLUDE_BYSTANDERS.mdx +3 -0
- package/api-docs/variables/FOREGROUND_THRESHOLD.mdx +1 -1
- package/api-docs/variables/FRAME_RATE.mdx +1 -1
- package/api-docs/variables/ImageFetchError.mdx +3 -0
- package/api-docs/variables/LIGHT_WRAP_BLUR_AMOUNT.mdx +3 -0
- package/api-docs/variables/LIGHT_WRAP_EDGE_BAND.mdx +3 -0
- package/api-docs/variables/LIGHT_WRAP_INTENSITY.mdx +3 -0
- package/api-docs/variables/LIGHT_WRAP_TIGHTNESS.mdx +3 -0
- package/api-docs/variables/MASK_COMBINE_RATIO.mdx +1 -1
- package/api-docs/variables/MORPH_DILATE_RADIUS_PX.mdx +3 -0
- package/api-docs/variables/MORPH_ERODE_RADIUS_PX.mdx +3 -0
- package/api-docs/variables/MORPH_PASS.mdx +3 -0
- package/api-docs/variables/MediaStreamTrackTransferable.mdx +5 -0
- package/api-docs/variables/PERSON_CENTER.mdx +3 -0
- package/api-docs/variables/RENDERER_OPTIONS_STRUCT.mdx +3 -0
- package/api-docs/variables/SIGMA_RANGE.mdx +3 -0
- package/api-docs/variables/SIGMA_SPACE.mdx +3 -0
- package/api-docs/variables/STRONG_EDGE_BLUR_AMOUNT.mdx +3 -0
- package/api-docs/variables/cloneImageRecord.mdx +19 -0
- package/api-docs/variables/compareImageRecords.mdx +18 -0
- package/api-docs/variables/createRemoteImageBitmap.mdx +1 -1
- package/api-docs/variables/getCanvasRenderingContext2D.mdx +14 -0
- package/api-docs/variables/getImageSize.mdx +13 -0
- package/api-docs/variables/isRenderOptionsKey.mdx +13 -0
- package/api-docs/variables/isValidGpuAPI.mdx +13 -0
- package/dist/common/backends/webgl/binaryMask.d.ts +8 -0
- package/dist/common/backends/webgl/binaryMask.js +95 -0
- package/dist/common/backends/webgl/blender.d.ts +2 -1
- package/dist/common/backends/webgl/blender.js +18 -15
- package/dist/common/backends/webgl/blur.d.ts +1 -1
- package/dist/common/backends/webgl/blur.js +23 -16
- package/dist/common/backends/webgl/canvas.js +9 -4
- package/dist/common/backends/webgl/diffAbsMask.d.ts +10 -0
- package/dist/common/backends/webgl/diffAbsMask.js +103 -0
- package/dist/common/backends/webgl/geodesicReconstruction.d.ts +13 -0
- package/dist/common/backends/webgl/geodesicReconstruction.js +176 -0
- package/dist/common/backends/webgl/jointBilateralFilter.d.ts +12 -0
- package/dist/common/backends/webgl/jointBilateralFilter.js +108 -0
- package/dist/common/backends/webgl/morphErode.d.ts +13 -0
- package/dist/common/backends/webgl/morphErode.js +121 -0
- package/dist/common/backends/webgl/renderer.js +194 -44
- package/dist/common/backends/webgl/replace.d.ts +17 -0
- package/dist/common/backends/webgl/replace.js +126 -0
- package/dist/common/backends/webgl/selectComponent.d.ts +15 -0
- package/dist/common/backends/webgl/selectComponent.js +102 -0
- package/dist/common/backends/webgl/smoothingMask.d.ts +3 -3
- package/dist/common/backends/webgl/smoothingMask.js +22 -21
- package/dist/common/backends/webgl/tentBlur.d.ts +9 -0
- package/dist/common/backends/webgl/tentBlur.js +118 -0
- package/dist/common/backends/webgl/texture.d.ts +2 -3
- package/dist/common/backends/webgl/texture.js +21 -19
- package/dist/common/backends/webgl/textureToTexture.d.ts +1 -1
- package/dist/common/backends/webgl/textureToTexture.js +19 -16
- package/dist/common/backends/webgl/webglUtils.d.ts +7 -1
- package/dist/common/backends/webgl/webglUtils.js +72 -10
- package/dist/common/backends/webgpu/blender.d.ts +6 -1
- package/dist/common/backends/webgpu/blender.js +96 -51
- package/dist/common/backends/webgpu/constants.js +1 -1
- package/dist/common/backends/webgpu/dualFilterBlur.d.ts +2 -3
- package/dist/common/backends/webgpu/dualFilterBlur.js +146 -140
- package/dist/common/backends/webgpu/jointBilateralFilter.d.ts +7 -0
- package/dist/common/backends/webgpu/jointBilateralFilter.js +162 -0
- package/dist/common/backends/webgpu/renderer.js +205 -43
- package/dist/common/backends/webgpu/replace.d.ts +11 -0
- package/dist/common/backends/webgpu/replace.js +175 -0
- package/dist/common/backends/webgpu/resize.d.ts +4 -0
- package/dist/common/backends/webgpu/resize.js +76 -0
- package/dist/common/backends/webgpu/smoothingMask.d.ts +2 -2
- package/dist/common/backends/webgpu/smoothingMask.js +74 -40
- package/dist/common/backends/webgpu/tentBlur.d.ts +5 -0
- package/dist/common/backends/webgpu/tentBlur.js +131 -0
- package/dist/common/backends/webgpu/texture.d.ts +2 -3
- package/dist/common/backends/webgpu/texture.js +29 -20
- package/dist/common/backends/webgpu/textureToTexture.d.ts +1 -1
- package/dist/common/backends/webgpu/textureToTexture.js +28 -15
- package/dist/common/backends/webgpu/types.d.ts +2 -0
- package/dist/common/backends/webgpu/webgpuUtils.d.ts +24 -4
- package/dist/common/backends/webgpu/webgpuUtils.js +60 -11
- package/dist/common/constants.d.ts +22 -5
- package/dist/common/constants.js +23 -5
- package/dist/common/index.d.ts +2 -0
- package/dist/common/index.js +2 -0
- package/dist/common/tsconfig.tsbuildinfo +1 -1
- package/dist/common/typeGuards.d.ts +2 -0
- package/dist/common/typeGuards.js +7 -0
- package/dist/common/types/media.d.ts +5 -1
- package/dist/common/types/messageEvents.d.ts +31 -4
- package/dist/common/types/processor.d.ts +6 -4
- package/dist/common/types/render.d.ts +147 -15
- package/dist/common/types/render.js +23 -1
- package/dist/common/types/segmentation.d.ts +0 -12
- package/dist/common/types/utils.d.ts +21 -0
- package/dist/common/utils.d.ts +29 -2
- package/dist/common/utils.js +206 -10
- package/dist/main/audio.js +3 -3
- package/dist/main/benchUtils.d.ts +35 -3
- package/dist/main/benchUtils.js +149 -15
- package/dist/main/index.d.ts +1 -1
- package/dist/main/index.js +1 -1
- package/dist/main/tsconfig.tsbuildinfo +1 -1
- package/dist/main/types.d.ts +0 -6
- package/dist/main/utils.d.ts +4 -0
- package/dist/main/utils.js +31 -0
- package/dist/main/video/constants.d.ts +1 -4
- package/dist/main/video/constants.js +1 -5
- package/dist/main/video/index.d.ts +3 -4
- package/dist/main/video/index.js +3 -4
- package/dist/main/video/inputProcessAdaptor.d.ts +30 -0
- package/dist/main/video/inputProcessAdaptor.js +198 -0
- package/dist/main/video/segmenter.d.ts +35 -0
- package/dist/main/video/{segmenters/mediapipe.js → segmenter.js} +93 -53
- package/dist/main/video/typeGuards.d.ts +2 -0
- package/dist/main/video/typeGuards.js +8 -1
- package/dist/main/video/types.d.ts +36 -16
- package/dist/main/video/utils.d.ts +5 -4
- package/dist/main/video/utils.js +49 -44
- package/dist/main/video/video.d.ts +29 -7
- package/dist/main/video/video.js +323 -28
- package/dist/workers/mediaWorker.js +35 -162
- package/dist/workers/tsconfig.tsbuildinfo +1 -1
- package/dist/worklets/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -12
- package/api-docs/functions/createCanvasTransform.mdx +0 -14
- package/api-docs/functions/createVideoTrackProcessor.mdx +0 -9
- package/api-docs/functions/createVideoTrackProcessorWithFallback.mdx +0 -15
- package/api-docs/interfaces/Detector.mdx +0 -81
- package/api-docs/interfaces/SegmentationParams.mdx +0 -18
- package/api-docs/interfaces/Transform.mdx +0 -62
- package/api-docs/type-aliases/ProcessVideoTrack.mdx +0 -15
- package/api-docs/type-aliases/SegmentationTransform.mdx +0 -3
- package/dist/common/backends/webgl/shaders/blendFragmentShader.d.ts +0 -1
- package/dist/common/backends/webgl/shaders/blendFragmentShader.js +0 -21
- package/dist/common/backends/webgl/shaders/dualFilterBlurFragmentShader.d.ts +0 -1
- package/dist/common/backends/webgl/shaders/dualFilterBlurFragmentShader.js +0 -45
- package/dist/common/backends/webgl/shaders/smoothingMaskFragmentShader.d.ts +0 -1
- package/dist/common/backends/webgl/shaders/smoothingMaskFragmentShader.js +0 -57
- package/dist/common/backends/webgl/shaders/textureFragmentShader.d.ts +0 -1
- package/dist/common/backends/webgl/shaders/textureFragmentShader.js +0 -16
- package/dist/common/backends/webgl/shaders/vertexShader.d.ts +0 -1
- package/dist/common/backends/webgl/shaders/vertexShader.js +0 -19
- package/dist/main/transformer.d.ts +0 -1
- package/dist/main/transformer.js +0 -4
- package/dist/main/video/canvasTransform.d.ts +0 -17
- package/dist/main/video/canvasTransform.js +0 -253
- package/dist/main/video/segmenters/mediapipe.d.ts +0 -22
- package/dist/main/video/transformer.d.ts +0 -9
- package/dist/main/video/transformer.js +0 -68
- package/dist/main/video/videoStreamTrackProcessor.d.ts +0 -20
- package/dist/main/video/videoStreamTrackProcessor.js +0 -86
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
var It=typeof self<"u"?self:{};function za(e,t){e=e.split(".");var r,n=It;for((e[0]in n)||n.execScript===void 0||n.execScript("var "+e[0]);e.length&&(r=e.shift());)e.length||t===void 0?n=n[r]&&n[r]!==Object.prototype[r]?n[r]:n[r]={}:n[r]=t}function kt(){throw Error("Invalid UTF8")}function Fs(e,t){return t=String.fromCharCode.apply(null,t),e==null?t:e+t}var Ir,On,xu=typeof TextDecoder<"u",yu,vu=typeof TextEncoder<"u";function Ka(e){if(vu)e=(yu||(yu=new TextEncoder)).encode(e);else{let r=0,n=new Uint8Array(3*e.length);for(let o=0;o<e.length;o++){var t=e.charCodeAt(o);if(t<128)n[r++]=t;else{if(t<2048)n[r++]=t>>6|192;else{if(t>=55296&&t<=57343){if(t<=56319&&o<e.length){let s=e.charCodeAt(++o);if(s>=56320&&s<=57343){t=1024*(t-55296)+s-56320+65536,n[r++]=t>>18|240,n[r++]=t>>12&63|128,n[r++]=t>>6&63|128,n[r++]=63&t|128;continue}o--}t=65533}n[r++]=t>>12|224,n[r++]=t>>6&63|128}n[r++]=63&t|128}}e=r===n.length?n:n.subarray(0,r)}return e}var xo,Xr;e:{for(Pn=["CLOSURE_FLAGS"],Mr=It,Fr=0;Fr<Pn.length;Fr++)if((Mr=Mr[Pn[Fr]])==null){Xr=null;break e}Xr=Mr}var Pn,Mr,Fr,yr,Us=Xr&&Xr[610401301];xo=Us!=null&&Us;var Os=It.navigator;function $n(e){return!!xo&&!!yr&&yr.brands.some(({brand:t})=>t&&t.indexOf(e)!=-1)}function Ue(e){var t;return(t=It.navigator)&&(t=t.userAgent)||(t=""),t.indexOf(e)!=-1}function ft(){return!!xo&&!!yr&&yr.brands.length>0}function Bn(){return ft()?$n("Chromium"):(Ue("Chrome")||Ue("CriOS"))&&!(!ft()&&Ue("Edge"))||Ue("Silk")}function yo(e){return yo[" "](e),e}yr=Os&&Os.userAgentData||null,yo[" "]=function(){};var Eu=!ft()&&(Ue("Trident")||Ue("MSIE"));!Ue("Android")||Bn(),Bn(),Ue("Safari")&&(Bn()||!ft()&&Ue("Coast")||!ft()&&Ue("Opera")||!ft()&&Ue("Edge")||(ft()?$n("Microsoft Edge"):Ue("Edg/"))||ft()&&$n("Opera"));var $a={},dr=null;function bu(e){let t=e.length,r=3*t/4;r%3?r=Math.floor(r):"=.".indexOf(e[t-1])!=-1&&(r="=.".indexOf(e[t-2])!=-1?r-2:r-1);let n=new Uint8Array(r),o=0;return function(s,a){function i(l){for(;c<s.length;){let h=s.charAt(c++),p=dr[h];if(p!=null)return p;if(!/^[\s\xa0]*$/.test(h))throw Error("Unknown base64 encoding at char: "+h)}return l}qa();let c=0;for(;;){let l=i(-1),h=i(0),p=i(64),d=i(64);if(d===64&&l===-1)break;a(l<<2|h>>4),p!=64&&(a(h<<4&240|p>>2),d!=64&&a(p<<6&192|d))}}(e,function(s){n[o++]=s}),o!==r?n.subarray(0,o):n}function qa(){if(!dr){dr={};var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),t=["+/=","+/","-_=","-_.","-_"];for(let r=0;r<5;r++){let n=e.concat(t[r].split(""));$a[r]=n;for(let o=0;o<n.length;o++){let s=n[o];dr[s]===void 0&&(dr[s]=o)}}}}var Ja=typeof Uint8Array<"u",Qa=!Eu&&typeof btoa=="function";function Ps(e){if(!Qa){var t;t===void 0&&(t=0),qa(),t=$a[t];var r=Array(Math.floor(e.length/3)),n=t[64]||"";let c=0,l=0;for(;c<e.length-2;c+=3){var o=e[c],s=e[c+1],a=e[c+2],i=t[o>>2];o=t[(3&o)<<4|s>>4],s=t[(15&s)<<2|a>>6],a=t[63&a],r[l++]=i+o+s+a}switch(i=0,a=n,e.length-c){case 2:a=t[(15&(i=e[c+1]))<<2]||n;case 1:e=e[c],r[l]=t[e>>2]+t[(3&e)<<4|i>>4]+a+n}return r.join("")}for(t="",r=0,n=e.length-10240;r<n;)t+=String.fromCharCode.apply(null,e.subarray(r,r+=10240));return t+=String.fromCharCode.apply(null,r?e.subarray(r):e),btoa(t)}var Bs=/[-_.]/g,Tu={"-":"+",_:"/",".":"="};function _u(e){return Tu[e]||""}function Za(e){if(!Qa)return bu(e);Bs.test(e)&&(e=e.replace(Bs,_u)),e=atob(e);let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}function _r(e){return Ja&&e!=null&&e instanceof Uint8Array}var Gt={};function Mt(){return Au||(Au=new at(null,Gt))}function vo(e){ei(Gt);var t=e.g;return(t=t==null||_r(t)?t:typeof t=="string"?Za(t):null)==null?t:e.g=t}var at=class{h(){return new Uint8Array(vo(this)||0)}constructor(e,t){if(ei(t),this.g=e,e!=null&&e.length===0)throw Error("ByteString should be constructed with non-empty values")}},Au,Ru;function ei(e){if(e!==Gt)throw Error("illegal external caller")}function ti(e,t){e.__closure__error__context__984382||(e.__closure__error__context__984382={}),e.__closure__error__context__984382.severity=t}function ri(){let e=Error();ti(e,"incident"),function(t){It.setTimeout(()=>{throw t},0)}(e)}function qn(e){return ti(e=Error(e),"warning"),e}function Eo(){return typeof BigInt=="function"}function we(e){return Array.prototype.slice.call(e)}var Kt=typeof Symbol=="function"&&typeof Symbol()=="symbol";function tn(e){return typeof Symbol=="function"&&typeof Symbol()=="symbol"?Symbol():e}var Ar=tn(),Ds=tn("0di"),Dn=tn("2ex"),ir=tn("1oa"),rn=Kt?(e,t)=>{e[Ar]|=t}:(e,t)=>{e.G!==void 0?e.G|=t:Object.defineProperties(e,{G:{value:t,configurable:!0,writable:!0,enumerable:!1}})},Jn=Kt?(e,t)=>{e[Ar]&=~t}:(e,t)=>{e.G!==void 0&&(e.G&=~t)},re=Kt?e=>0|e[Ar]:e=>0|e.G,G=Kt?e=>e[Ar]:e=>e.G,oe=Kt?(e,t)=>{e[Ar]=t}:(e,t)=>{e.G!==void 0?e.G=t:Object.defineProperties(e,{G:{value:t,configurable:!0,writable:!0,enumerable:!1}})};function $t(e){return rn(e,34),e}function wu(e,t){oe(t,-30975&(0|e))}function Qn(e,t){oe(t,-30941&(34|e))}var bo,Rr={},ni={};function Ns(e){return!(!e||typeof e!="object"||e.Ia!==ni)}function To(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)&&e.constructor===Object}function _o(e,t){if(e!=null){if(typeof e=="string")e=e?new at(e,Gt):Mt();else if(e.constructor!==at)if(_r(e))e=e.length?new at(new Uint8Array(e),Gt):Mt();else{if(!t)throw Error();e=void 0}}return e}function Hr(e){return!(!Array.isArray(e)||e.length)&&!!(1&re(e))}var Gs=[];function _t(e){if(2&e)throw Error()}oe(Gs,55),bo=Object.freeze(Gs);var Yr=class e{constructor(t,r,n){this.l=0,this.g=t,this.h=r,this.m=n}next(){if(this.l<this.g.length){let t=this.g[this.l++];return{done:!1,value:this.h?this.h.call(this.m,t):t}}return{done:!0,value:void 0}}[Symbol.iterator](){return new e(this.g,this.h,this.m)}},mt;function oi(e,t){(t=mt?t[mt]:void 0)&&(e[mt]=we(t))}var ku=Object.freeze({});function nn(e){return e.Pa=!0,e}var Su=nn(e=>typeof e=="number"),Vs=nn(e=>typeof e=="string"),Cu=nn(e=>typeof e=="boolean"),on=typeof It.BigInt=="function"&&typeof It.BigInt(0)=="bigint",Zn=nn(e=>on?e>=Iu&&e<=Fu:e[0]==="-"?js(e,Lu):js(e,Mu)),Lu=Number.MIN_SAFE_INTEGER.toString(),Iu=on?BigInt(Number.MIN_SAFE_INTEGER):void 0,Mu=Number.MAX_SAFE_INTEGER.toString(),Fu=on?BigInt(Number.MAX_SAFE_INTEGER):void 0;function js(e,t){if(e.length>t.length)return!1;if(e.length<t.length||e===t)return!0;for(let r=0;r<e.length;r++){let n=e[r],o=t[r];if(n>o)return!1;if(n<o)return!0}}var Uu=typeof Uint8Array.prototype.slice=="function",si,V=0,Z=0;function Ws(e){let t=e>>>0;V=t,Z=(e-t)/4294967296>>>0}function Vt(e){if(e<0){Ws(-e);let[t,r]=ko(V,Z);V=t>>>0,Z=r>>>0}else Ws(e)}function Ao(e){let t=si||(si=new DataView(new ArrayBuffer(8)));t.setFloat32(0,+e,!0),Z=0,V=t.getUint32(0,!0)}function Ro(e,t){let r=4294967296*t+(e>>>0);return Number.isSafeInteger(r)?r:vr(e,t)}function wo(e,t){let r=2147483648&t;return r&&(t=~t>>>0,(e=1+~e>>>0)==0&&(t=t+1>>>0)),typeof(e=Ro(e,t))=="number"?r?-e:e:r?"-"+e:e}function vr(e,t){if(e>>>=0,(t>>>=0)<=2097151)var r=""+(4294967296*t+e);else Eo()?r=""+(BigInt(t)<<BigInt(32)|BigInt(e)):(e=(16777215&e)+6777216*(r=16777215&(e>>>24|t<<8))+6710656*(t=t>>16&65535),r+=8147497*t,t*=2,e>=1e7&&(r+=e/1e7>>>0,e%=1e7),r>=1e7&&(t+=r/1e7>>>0,r%=1e7),r=t+Xs(r)+Xs(e));return r}function Xs(e){return e=String(e),"0000000".slice(e.length)+e}function sn(e){if(e.length<16)Vt(Number(e));else if(Eo())e=BigInt(e),V=Number(e&BigInt(4294967295))>>>0,Z=Number(e>>BigInt(32)&BigInt(4294967295));else{let t=+(e[0]==="-");Z=V=0;let r=e.length;for(let n=t,o=(r-t)%6+t;o<=r;n=o,o+=6){let s=Number(e.slice(n,o));Z*=1e6,V=1e6*V+s,V>=4294967296&&(Z+=Math.trunc(V/4294967296),Z>>>=0,V>>>=0)}if(t){let[n,o]=ko(V,Z);V=n,Z=o}}}function ko(e,t){return t=~t,e?e=1+~e:t+=1,[e,t]}function At(e){return e==null||typeof e=="number"?e:e==="NaN"||e==="Infinity"||e==="-Infinity"?Number(e):void 0}function ai(e){return e==null||typeof e=="boolean"?e:typeof e=="number"?!!e:void 0}var Ou=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function an(e){let t=typeof e;switch(t){case"bigint":return!0;case"number":return Number.isFinite(e)}return t==="string"&&Ou.test(e)}function qt(e){if(e==null)return e;if(typeof e=="string"){if(!e)return;e=+e}return typeof e=="number"&&Number.isFinite(e)?0|e:void 0}function ii(e){if(e==null)return e;if(typeof e=="string"){if(!e)return;e=+e}return typeof e=="number"&&Number.isFinite(e)?e>>>0:void 0}function Hs(e){return e[0]!=="-"&&(e.length<20||e.length===20&&Number(e.substring(0,6))<184467)}function So(e){return e=Math.trunc(e),Number.isSafeInteger(e)||(Vt(e),e=wo(V,Z)),e}function Co(e){var t=Math.trunc(Number(e));if(Number.isSafeInteger(t))return String(t);if((t=e.indexOf("."))!==-1&&(e=e.substring(0,t)),!(e[0]==="-"?e.length<20||e.length===20&&Number(e.substring(0,7))>-922337:e.length<19||e.length===19&&Number(e.substring(0,6))<922337))if(sn(e),e=V,2147483648&(t=Z))if(Eo())e=""+(BigInt(0|t)<<BigInt(32)|BigInt(e>>>0));else{let[r,n]=ko(e,t);e="-"+vr(r,n)}else e=vr(e,t);return e}function zr(e){return e==null?e:typeof e=="bigint"?(Zn(e)?e=Number(e):(e=BigInt.asIntN(64,e),e=Zn(e)?Number(e):String(e)),e):an(e)?typeof e=="number"?So(e):Co(e):void 0}function Pu(e){if(e==null)return e;var t=typeof e;if(t==="bigint")return String(BigInt.asUintN(64,e));if(an(e)){if(t==="string")return t=Math.trunc(Number(e)),Number.isSafeInteger(t)&&t>=0?e=String(t):((t=e.indexOf("."))!==-1&&(e=e.substring(0,t)),Hs(e)||(sn(e),e=vr(V,Z))),e;if(t==="number")return(e=Math.trunc(e))>=0&&Number.isSafeInteger(e)?e:function(r){if(r<0){Vt(r);var n=vr(V,Z);return r=Number(n),Number.isSafeInteger(r)?r:n}return Hs(n=String(r))?n:(Vt(r),Ro(V,Z))}(e)}}function ci(e){if(typeof e!="string")throw Error();return e}function Jt(e){if(e!=null&&typeof e!="string")throw Error();return e}function gt(e){return e==null||typeof e=="string"?e:void 0}function Lo(e,t,r,n){if(e!=null&&typeof e=="object"&&e.X===Rr)return e;if(!Array.isArray(e))return r?2&n?(e=t[Ds])?t=e:($t((e=new t).u),t=t[Ds]=e):t=new t:t=void 0,t;let o=r=re(e);return o===0&&(o|=32&n),o|=2&n,o!==r&&oe(e,o),new t(e)}function Bu(e,t,r){if(t)e:{if(!an(t=e))throw qn("int64");switch(typeof t){case"string":t=Co(t);break e;case"bigint":if(e=t=BigInt.asIntN(64,t),Vs(e)){if(!/^\s*(?:-?[1-9]\d*|0)?\s*$/.test(e))throw Error(String(e))}else if(Su(e)&&!Number.isSafeInteger(e))throw Error(String(e));t=on?BigInt(t):Cu(t)?t?"1":"0":Vs(t)?t.trim()||"0":String(t);break e;default:t=So(t)}}else t=zr(e);return typeof(r=(e=t)==null?r?0:void 0:e)=="string"&&(t=+r,Number.isSafeInteger(t))?t:r}function ui(e){var t;return cr===void 0&&(cr=typeof Proxy=="function"?Ys(Proxy):null),(t=!cr)||(ur===void 0&&(ur=typeof WeakMap=="function"?Ys(WeakMap):null),t=!ur),t?e:(t=jt?.get(e))?t:Math.random()>.01?e:(function(r){if(Nn===void 0){let n=new cr([],{});Nn=Array.prototype.concat.call([],n).length===1}Nn&&typeof Symbol=="function"&&Symbol.isConcatSpreadable&&(r[Symbol.isConcatSpreadable]=!0)}(e),function(r,n){(jt||(jt=new ur)).set(r,n),(hi||(hi=new ur)).set(n,r)}(e,t=new cr(e,{set:(r,n,o)=>(ri(),r[n]=o,!0)})),t)}var jt,hi,cr,ur,Nn,Kr,li,Du;function Ys(e){try{return e.toString().indexOf("[native code]")!==-1?e:null}catch{return null}}function xt(e,t,r){return e=di(e,t[0],t[1],r?1:2),t!==li&&r&&rn(e,16384),e}function di(e,t,r,n){if(n=n??0,e==null&&(e=Kr),Kr=void 0,e==null){var o=96;r?(e=[r],o|=512):e=[],t&&(o=-33521665&o|(1023&t)<<15)}else{if(!Array.isArray(e))throw Error("narr");if(2048&(o=re(e)))throw Error("farr");if(64&o)return e;if(n===1||n===2||(o|=64),r&&(o|=512,r!==e[0]))throw Error("mid");e:{if(n=(r=e).length){let s=n-1;if(To(r[s])){if((t=s-(+!!(512&(o|=256))-1))>=1024)throw Error("pvtlmt");o=-33521665&o|(1023&t)<<15;break e}}if(t){if((t=Math.max(t,n-(+!!(512&o)-1)))>1024)throw Error("spvt");o=-33521665&o|(1023&t)<<15}}}return oe(e,o),e}var Nu={},Gu=function(){try{return yo(new class extends Map{constructor(){super()}}),!1}catch{return!0}}(),pr=class{constructor(){this.g=new Map}get(t){return this.g.get(t)}set(t,r){return this.g.set(t,r),this.size=this.g.size,this}delete(t){return t=this.g.delete(t),this.size=this.g.size,t}clear(){this.g.clear(),this.size=this.g.size}has(t){return this.g.has(t)}entries(){return this.g.entries()}keys(){return this.g.keys()}values(){return this.g.values()}forEach(t,r){return this.g.forEach(t,r)}[Symbol.iterator](){return this.entries()}},Vu=Gu?(Object.setPrototypeOf(pr.prototype,Map.prototype),Object.defineProperties(pr.prototype,{size:{value:0,configurable:!0,enumerable:!0,writable:!0}}),pr):class extends Map{constructor(){super()}};function zs(e){return e}function Gn(e){if(2&e.M)throw Error("Cannot mutate an immutable Map")}var Pe=class extends Vu{constructor(e,t,r=zs,n=zs){super();let o=re(e);o|=64,oe(e,o),this.M=o,this.T=t,this.S=r,this.Z=this.T?ju:n;for(let s=0;s<e.length;s++){let a=e[s],i=r(a[0],!1,!0),c=a[1];t?c===void 0&&(c=null):c=n(a[1],!1,!0,void 0,void 0,o),super.set(i,c)}}oa(e=Ks){if(this.size!==0)return this.Y(e)}Y(e=Ks){let t=[],r=super.entries();for(var n;!(n=r.next()).done;)(n=n.value)[0]=e(n[0]),n[1]=e(n[1]),t.push(n);return t}clear(){Gn(this),super.clear()}delete(e){return Gn(this),super.delete(this.S(e,!0,!1))}entries(){var e=this.na();return new Yr(e,Wu,this)}keys(){return this.Ha()}values(){var e=this.na();return new Yr(e,Pe.prototype.get,this)}forEach(e,t){super.forEach((r,n)=>{e.call(t,this.get(n),n,this)})}set(e,t){return Gn(this),(e=this.S(e,!0,!1))==null?this:t==null?(super.delete(e),this):super.set(e,this.Z(t,!0,!0,this.T,!1,this.M))}Na(e){let t=this.S(e[0],!1,!0);e=e[1],e=this.T?e===void 0?null:e:this.Z(e,!1,!0,void 0,!1,this.M),super.set(t,e)}has(e){return super.has(this.S(e,!1,!1))}get(e){e=this.S(e,!1,!1);let t=super.get(e);if(t!==void 0){var r=this.T;return r?((r=this.Z(t,!1,!0,r,this.sa,this.M))!==t&&super.set(e,r),r):t}}na(){return Array.from(super.keys())}Ha(){return super.keys()}[Symbol.iterator](){return this.entries()}};function ju(e,t,r,n,o,s){return e=Lo(e,n,r,s),o&&(e=un(e)),e}function Ks(e){return e}function Wu(e){return[e,this.get(e)]}var Xu;function $s(){return Xu||(Xu=new Pe($t([]),void 0,void 0,void 0,Nu))}function Io(e,t,r,n,o){if(e!=null){if(Array.isArray(e))e=Hr(e)?void 0:o&&2&re(e)?e:cn(e,t,r,n!==void 0,o);else if(To(e)){let s={};for(let a in e)s[a]=Io(e[a],t,r,n,o);e=s}else e=t(e,n);return e}}function cn(e,t,r,n,o){let s=n||r?re(e):0;n=n?!!(32&s):void 0;let a=we(e);for(let i=0;i<a.length;i++)a[i]=Io(a[i],t,r,n,o);return r&&(oi(a,e),r(s,a)),a}function Hu(e){return Io(e,Mo,void 0,void 0,!1)}function Mo(e){return e.X===Rr?e.toJSON():e instanceof Pe?e.oa(Hu):function(t){switch(typeof t){case"number":return isFinite(t)?t:String(t);case"bigint":return Zn(t)?Number(t):String(t);case"boolean":return t?1:0;case"object":if(t)if(Array.isArray(t)){if(Hr(t))return}else{if(_r(t))return Ps(t);if(t instanceof at){let r=t.g;return r==null?"":typeof r=="string"?r:t.g=Ps(r)}if(t instanceof Pe)return t.oa()}}return t}(e)}function eo(e,t,r=Qn){if(e!=null){if(Ja&&e instanceof Uint8Array)return t?e:new Uint8Array(e);if(Array.isArray(e)){var n=re(e);return 2&n?e:(t&&(t=n===0||!!(32&n)&&!(64&n||!(16&n))),t?(oe(e,-12293&(34|n)),e):cn(e,eo,4&n?Qn:r,!0,!0))}return e.X===Rr?(r=e.u,e=2&(n=G(r))?e:Fo(e,r,n,!0)):e instanceof Pe&&!(2&e.M)&&(r=$t(e.Y(eo)),e=new Pe(r,e.T,e.S,e.Z)),e}}function Fo(e,t,r,n){return e=e.constructor,Kr=t=fi(t,r,n),t=new e(t),Kr=void 0,t}function fi(e,t,r){let n=r||2&t?Qn:wu,o=!!(32&t);return e=function(s,a,i){let c=we(s);var l=c.length;let h=256&a?c[l-1]:void 0;for(l+=h?-1:0,a=512&a?1:0;a<l;a++)c[a]=i(c[a]);if(h){a=c[a]={};for(let p in h)a[p]=i(h[p])}return oi(c,s),c}(e,t,s=>eo(s,o,n)),rn(e,32|(r?2:0)),e}function un(e){let t=e.u,r=G(t);return 2&r?Fo(e,t,r,!1):e}function vt(e,t){return ht(e=e.u,G(e),t)}function qs(e,t,r,n){if(!((t=n+(+!!(512&t)-1))<0||t>=e.length||t>=r))return e[t]}function ht(e,t,r,n){if(r===-1)return null;let o=t>>15&1023||536870912;if(!(r>=o)){var s=e.length;return n&&256&t&&(n=e[s-1][r])!=null?(qs(e,t,o,r)&&Dn!=null&&((t=(e=Ru??(Ru={}))[Dn]||0)>=4||(e[Dn]=t+1,ri())),n):qs(e,t,o,r)}return 256&t?e[e.length-1][r]:void 0}function X(e,t,r){let n=e.u,o=G(n);return _t(o),J(n,o,t,r),e}function J(e,t,r,n){let o=t>>15&1023||536870912;if(r>=o){let s,a=t;if(256&t)s=e[e.length-1];else{if(n==null)return a;s=e[o+(+!!(512&t)-1)]={},a|=256}return s[r]=n,r<o&&(e[r+(+!!(512&t)-1)]=void 0),a!==t&&oe(e,a),a}return e[r+(+!!(512&t)-1)]=n,256&t&&r in(e=e[e.length-1])&&delete e[r],t}function Dr(e,t){e=e.u;let r=G(e),n=ht(e,r,t),o=At(n);return o!=null&&o!==n&&J(e,r,t,o),o}function pi(e){e=e.u;let t=G(e),r=ht(e,t,1),n=_o(r,!0);return n!=null&&n!==r&&J(e,t,1,n),n}function St(){return ku===void 0?2:4}function Ct(e,t,r,n,o){let s=e.u,a=2&(e=G(s))?1:n;o=!!o,n=Uo(s,e,t);var i=re(n);if(!(4&i)){4&i&&(n=we(n),i=it(i,e),e=J(s,e,t,n));let l=0,h=0;for(;l<n.length;l++){let p=r(n[l]);p!=null&&(n[h++]=p)}h<l&&(n.length=h),i=-4097&(20|(i=Oo(i,e))),oe(n,i&=-8193),2&i&&Object.freeze(n)}let c;return a===1||a===4&&32&i?Ve(i)||(o=i,(i|=2)!==o&&oe(n,i),Object.freeze(n)):(r=a===5&&(!!(32&i)||Ve(i)||!!jt?.get(n)),(a===2||r)&&Ve(i)&&(n=we(n),i=yt(i=it(i,e),e,o),oe(n,i),e=J(s,e,t,n)),Ve(i)||(t=i,(i=yt(i,e,o))!==t&&oe(n,i)),r?c=ui(n):a!==2||o||jt?.delete(n)),c||n}function Uo(e,t,r,n){return e=ht(e,t,r,n),Array.isArray(e)?e:bo}function Oo(e,t){return e===0&&(e=it(e,t)),1|e}function Ve(e){return!!(2&e)&&!!(4&e)||!!(2048&e)}function mi(e){e=we(e);for(let t=0;t<e.length;t++){let r=e[t]=we(e[t]);Array.isArray(r[1])&&(r[1]=$t(r[1]))}return e}function to(e,t,r,n){e=e.u;let o=G(e);_t(o),J(e,o,t,(n==="0"?Number(r)===0:r===n)?void 0:r)}function Qt(e,t,r,n,o){_t(t);var s=!(!(64&t)&&16384&t);let a=(o=Uo(e,t,r,o))!==bo;if(s||!a){let i=s=a?re(o):0;(!a||2&i||Ve(i)||4&i&&!(32&i))&&(o=we(o),i=it(i,t),t=J(e,t,r,o)),i=-13&Oo(i,t),i=yt(n?-17&i:16|i,t,!0),i!==s&&oe(o,i)}return o}function Vn(e,t){var r=oc;return Bo(Po(e=e.u),e,G(e),r)===t?t:-1}function Po(e){if(Kt)return e[ir]??(e[ir]=new Map);if(ir in e)return e[ir];let t=new Map;return Object.defineProperty(e,ir,{value:t}),t}function gi(e,t,r,n){let o=Po(e),s=Bo(o,e,t,r);return s!==n&&(s&&(t=J(e,t,s)),o.set(r,n)),t}function Bo(e,t,r,n){let o=e.get(n);if(o!=null)return o;o=0;for(let s=0;s<n.length;s++){let a=n[s];ht(t,r,a)!=null&&(o!==0&&(r=J(t,r,o)),o=a)}return e.set(n,o),o}function Do(e,t,r,n){let o,s=G(e);if((n=ht(e,s,r,n))!=null&&n.X===Rr)return(t=un(n))!==n&&J(e,s,r,t),t.u;if(Array.isArray(n)){let a=re(n);o=2&a?xt(fi(n,a,!1),t,!0):64&a?n:xt(o,t,!0)}else o=xt(void 0,t,!0);return o!==n&&J(e,s,r,o),o}function xi(e,t,r,n){e=e.u;let o=G(e);return(t=Lo(n=ht(e,o,r,n),t,!1,o))!==n&&t!=null&&J(e,o,r,t),t}function O(e,t,r,n=!1){if((t=xi(e,t,r,n))==null)return t;if(e=e.u,!(2&(n=G(e)))){let o=un(t);o!==t&&J(e,n,r,t=o)}return t}function yi(e,t,r,n,o,s,a){e=e.u;var i=!!(2&t);o=i?1:o,s=!!s,a&&(a=!i),i=Uo(e,t,n);var c=re(i),l=!!(4&c);if(!l){var h=i,p=t;let g=!!(2&(c=Oo(c,t)));g&&(p|=2);let A=!g,R=!0,S=0,w=0;for(;S<h.length;S++){let f=Lo(h[S],r,!1,p);if(f instanceof r){if(!g){let y=!!(2&re(f.u));A&&(A=!y),R&&(R=y)}h[w++]=f}}w<S&&(h.length=w),c|=4,c=R?16|c:-17&c,oe(h,c=A?8|c:-9&c),g&&Object.freeze(h)}if(a&&!(8&c||!i.length&&(o===1||o===4&&32&c))){for(Ve(c)&&(i=we(i),c=it(c,t),t=J(e,t,n,i)),r=i,a=c,h=0;h<r.length;h++)(c=r[h])!==(p=un(c))&&(r[h]=p);a|=8,a=r.length?-17&a:16|a,oe(r,a),c=a}let d;return o===1||o===4&&32&c?Ve(c)||(t=c,(c|=!i.length||16&c&&(!l||32&c)?2:2048)!==t&&oe(i,c),Object.freeze(i)):(l=o===5&&(!!(32&c)||Ve(c)||!!jt?.get(i)),(o===2||l)&&Ve(c)&&(i=we(i),c=yt(c=it(c,t),t,s),oe(i,c),t=J(e,t,n,i)),Ve(c)||(n=c,(c=yt(c,t,s))!==n&&oe(i,c)),l?d=ui(i):o!==2||s||jt?.delete(i)),d||i}function ct(e,t,r){let n=G(e.u);return yi(e,n,t,r,St(),!1,!(2&n))}function T(e,t,r,n){return n==null&&(n=void 0),X(e,r,n)}function mr(e,t,r,n){n==null&&(n=void 0);e:{e=e.u;let o=G(e);if(_t(o),n==null){let s=Po(e);if(Bo(s,e,o,r)!==t)break e;s.set(r,0)}else o=gi(e,o,r,t);J(e,o,t,n)}}function it(e,t){return-2049&(e=32|(2&t?2|e:-3&e))}function yt(e,t,r){return 32&t&&r||(e&=-33),e}function $r(e,t,r,n){let o=G(e.u);_t(o),e=yi(e,o,r,t,2,!0),n=n??new r,e.push(n),2&re(n.u)?Jn(e,8):Jn(e,16)}function je(e,t){return e??t}function Oe(e,t){return qt(vt(e,t))}function te(e,t){return je(Dr(e,t),0)}function et(e,t){return je(gt(vt(e,t)),"")}function Er(e,t,r){if(r!=null&&typeof r!="boolean")throw e=typeof r,Error(`Expected boolean but got ${e!="object"?e:r?Array.isArray(r)?"array":e:"null"}: ${r}`);X(e,t,r)}function tt(e,t,r){if(r!=null){if(typeof r!="number"||!Number.isFinite(r))throw qn("int32");r|=0}X(e,t,r)}function v(e,t,r){if(r!=null&&typeof r!="number")throw Error(`Value of float/double field must be a number, found ${typeof r}: ${r}`);X(e,t,r)}function qr(e,t,r){{let a=e.u,i=G(a);if(_t(i),r==null)J(a,i,t);else{r=hi?.get(r)||r;var n=e=re(r),o=Ve(e),s=o||Object.isFrozen(r);for(o||(e=0),s||(r=we(r),n=0,e=yt(e=it(e,i),i,!0),s=!1),e|=21,o=0;o<r.length;o++){let c=r[o],l=ci(c);Object.is(c,l)||(s&&(r=we(r),n=0,e=yt(e=it(e,i),i,!0),s=!1),r[o]=l)}e!==n&&(s&&(r=we(r),e=yt(e=it(e,i),i,!0)),oe(r,e)),J(a,i,t,r)}}}function hn(e,t,r){_t(G(e.u)),Ct(e,t,gt,2,!0).push(ci(r))}function vi(e,t){return Error(`Invalid wire type: ${e} (at position ${t})`)}function No(){return Error("Failed to read varint, encoding is invalid.")}function Ei(e,t){return Error(`Tried to read past the end of the data ${t} > ${e}`)}function Go(e){if(typeof e=="string")return{buffer:Za(e),O:!1};if(Array.isArray(e))return{buffer:new Uint8Array(e),O:!1};if(e.constructor===Uint8Array)return{buffer:e,O:!1};if(e.constructor===ArrayBuffer)return{buffer:new Uint8Array(e),O:!1};if(e.constructor===at)return{buffer:vo(e)||new Uint8Array(0),O:!0};if(e instanceof Uint8Array)return{buffer:new Uint8Array(e.buffer,e.byteOffset,e.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 Vo(e,t){let r,n=0,o=0,s=0,a=e.h,i=e.g;do r=a[i++],n|=(127&r)<<s,s+=7;while(s<32&&128&r);for(s>32&&(o|=(127&r)>>4),s=3;s<32&&128&r;s+=7)r=a[i++],o|=(127&r)<<s;if(Lt(e,i),r<128)return t(n>>>0,o>>>0);throw No()}function jo(e){let t=0,r=e.g,n=r+10,o=e.h;for(;r<n;){let s=o[r++];if(t|=s,(128&s)==0)return Lt(e,r),!!(127&t)}throw No()}function Et(e){let t=e.h,r=e.g,n=t[r++],o=127&n;if(128&n&&(n=t[r++],o|=(127&n)<<7,128&n&&(n=t[r++],o|=(127&n)<<14,128&n&&(n=t[r++],o|=(127&n)<<21,128&n&&(n=t[r++],o|=n<<28,128&n&&128&t[r++]&&128&t[r++]&&128&t[r++]&&128&t[r++]&&128&t[r++])))))throw No();return Lt(e,r),o}function ut(e){return Et(e)>>>0}function ro(e){var t=e.h;let r=e.g,n=t[r],o=t[r+1],s=t[r+2];return t=t[r+3],Lt(e,e.g+4),(n<<0|o<<8|s<<16|t<<24)>>>0}function no(e){var t=ro(e);e=2*(t>>31)+1;let r=t>>>23&255;return t&=8388607,r==255?t?NaN:e*(1/0):r==0?1401298464324817e-60*e*t:e*Math.pow(2,r-150)*(t+8388608)}function Yu(e){return Et(e)}function jn(e,t,{ca:r=!1}={}){e.ca=r,t&&(t=Go(t),e.h=t.buffer,e.m=t.O,e.j=0,e.l=e.h.length,e.g=e.j)}function Lt(e,t){if(e.g=t,t>e.l)throw Ei(e.l,t)}function bi(e,t){if(t<0)throw Error(`Tried to read a negative byte length: ${t}`);let r=e.g,n=r+t;if(n>e.l)throw Ei(t,e.l-r);return e.g=n,r}function Ti(e,t){if(t==0)return Mt();var r=bi(e,t);return e.ca&&e.m?r=e.h.subarray(r,r+t):(e=e.h,r=r===(t=r+t)?new Uint8Array(0):Uu?e.slice(r,t):new Uint8Array(e.subarray(r,t))),r.length==0?Mt():new at(r,Gt)}Pe.prototype.toJSON=void 0,Pe.prototype.Ia=ni;var Js=[];function _i(e){var t=e.g;if(t.g==t.l)return!1;e.l=e.g.g;var r=ut(e.g);if(t=r>>>3,!((r&=7)>=0&&r<=5))throw vi(r,e.l);if(t<1)throw Error(`Invalid field number: ${t} (at position ${e.l})`);return e.m=t,e.h=r,!0}function Nr(e){switch(e.h){case 0:e.h!=0?Nr(e):jo(e.g);break;case 1:Lt(e=e.g,e.g+8);break;case 2:if(e.h!=2)Nr(e);else{var t=ut(e.g);Lt(e=e.g,e.g+t)}break;case 5:Lt(e=e.g,e.g+4);break;case 3:for(t=e.m;;){if(!_i(e))throw Error("Unmatched start-group tag: stream EOF");if(e.h==4){if(e.m!=t)throw Error("Unmatched end-group tag");break}Nr(e)}break;default:throw vi(e.h,e.l)}}function wr(e,t,r){let n=e.g.l,o=ut(e.g),s=e.g.g+o,a=s-n;if(a<=0&&(e.g.l=s,r(t,e,void 0,void 0,void 0),a=s-e.g.g),a)throw Error(`Message parsing ended unexpectedly. Expected to read ${o} bytes, instead read ${o-a} bytes, either the data ended unexpectedly or the message misreported its own length`);return e.g.g=s,e.g.l=n,t}function Wo(e){var t=ut(e.g),r=bi(e=e.g,t);if(e=e.h,xu){var n,o=e;(n=On)||(n=On=new TextDecoder("utf-8",{fatal:!0})),t=r+t,o=r===0&&t===o.length?o:o.subarray(r,t);try{var s=n.decode(o)}catch(i){if(Ir===void 0){try{n.decode(new Uint8Array([128]))}catch{}try{n.decode(new Uint8Array([97])),Ir=!0}catch{Ir=!1}}throw!Ir&&(On=void 0),i}}else{t=(s=r)+t,r=[];let i,c=null;for(;s<t;){var a=e[s++];a<128?r.push(a):a<224?s>=t?kt():(i=e[s++],a<194||(192&i)!=128?(s--,kt()):r.push((31&a)<<6|63&i)):a<240?s>=t-1?kt():(i=e[s++],(192&i)!=128||a===224&&i<160||a===237&&i>=160||(192&(n=e[s++]))!=128?(s--,kt()):r.push((15&a)<<12|(63&i)<<6|63&n)):a<=244?s>=t-2?kt():(i=e[s++],(192&i)!=128||i-144+(a<<28)>>30!=0||(192&(n=e[s++]))!=128||(192&(o=e[s++]))!=128?(s--,kt()):(a=(7&a)<<18|(63&i)<<12|(63&n)<<6|63&o,a-=65536,r.push(55296+(a>>10&1023),56320+(1023&a)))):kt(),r.length>=8192&&(c=Fs(c,r),r.length=0)}s=Fs(c,r)}return s}function Ai(e){let t=ut(e.g);return Ti(e.g,t)}function ln(e,t,r){var n=ut(e.g);for(n=e.g.g+n;e.g.g<n;)r.push(t(e.g))}var Ur=[],Jr;function Xe(e,t,r){t.g?t.m(e,t.g,t.h,r,!0):t.m(e,t.h,r,!0)}var x=class{constructor(e,t){this.u=di(e,t)}toJSON(){return Ri(this)}l(){var e=k2;return e.g?e.l(this,e.g,e.h,!0):e.l(this,e.h,e.defaultValue,!0)}clone(){let e=this.u;return Fo(this,e,G(e),!1)}O(){return!!(2&re(this.u))}};function Ri(e){e=e.u,e=Jr?e:cn(e,Mo,void 0,void 0,!1);{var t=!Jr;let l=e.length;if(l){var r=e[l-1],n=To(r);n?l--:r=void 0;var o=e;if(n){e:{var s,a=r,i=!1;if(a)for(let h in a)isNaN(+h)?(s??(s={}))[h]=a[h]:(n=a[h],Array.isArray(n)&&(Hr(n)||Ns(n)&&n.size===0)&&(n=null),n==null&&(i=!0),n!=null&&((s??(s={}))[h]=n));if(i||(s=a),s)for(let h in s){i=s;break e}i=null}a=i==null?r!=null:i!==r}for(;l>0&&((s=o[l-1])==null||Hr(s)||Ns(s)&&s.size===0);l--)var c=!0;(o!==e||a||c)&&(t?(c||a||i)&&(o.length=l):o=Array.prototype.slice.call(o,0,l),i&&o.push(i)),c=o}else c=e}return c}function Qs(e){return e?/^\d+$/.test(e)?(sn(e),new oo(V,Z)):null:zu||(zu=new oo(0,0))}x.prototype.X=Rr,x.prototype.toString=function(){try{return Jr=!0,Ri(this).toString()}finally{Jr=!1}};var oo=class{constructor(e,t){this.h=e>>>0,this.g=t>>>0}},zu;function Zs(e){return e?/^-?\d+$/.test(e)?(sn(e),new so(V,Z)):null:Ku||(Ku=new so(0,0))}var so=class{constructor(e,t){this.h=e>>>0,this.g=t>>>0}},Ku;function Bt(e,t,r){for(;r>0||t>127;)e.g.push(127&t|128),t=(t>>>7|r<<25)>>>0,r>>>=7;e.g.push(t)}function Zt(e,t){for(;t>127;)e.g.push(127&t|128),t>>>=7;e.g.push(t)}function dn(e,t){if(t>=0)Zt(e,t);else{for(let r=0;r<9;r++)e.g.push(127&t|128),t>>=7;e.g.push(1)}}function br(e,t){e.g.push(t>>>0&255),e.g.push(t>>>8&255),e.g.push(t>>>16&255),e.g.push(t>>>24&255)}function Wt(e,t){t.length!==0&&(e.l.push(t),e.h+=t.length)}function Se(e,t,r){Zt(e.g,8*t+r)}function Xo(e,t){return Se(e,t,2),t=e.g.end(),Wt(e,t),t.push(e.h),t}function Ho(e,t){var r=t.pop();for(r=e.h+e.g.length()-r;r>127;)t.push(127&r|128),r>>>=7,e.h++;t.push(r),e.h++}function fn(e,t,r){Se(e,t,2),Zt(e.g,r.length),Wt(e,e.g.end()),Wt(e,r)}function Qr(e,t,r,n){r!=null&&(t=Xo(e,t),n(r,e),Ho(e,t))}function He(){let e=class{constructor(){throw Error()}};return Object.setPrototypeOf(e,e.prototype),e}var Yo=He(),wi=He(),zo=He(),Ko=He(),ki=He(),Si=He(),$o=He(),Ci=He(),Li=He(),er=class{constructor(e,t,r){this.g=e,this.h=t,e=Yo,this.l=!!e&&r===e||!1}};function pn(e,t){return new er(e,t,Yo)}function Ii(e,t,r,n,o){Qr(e,r,Oi(t,n),o)}var $u=pn(function(e,t,r,n,o){return e.h===2&&(wr(e,Do(t,n,r),o),!0)},Ii),qu=pn(function(e,t,r,n,o){return e.h===2&&(wr(e,Do(t,n,r,!0),o),!0)},Ii),mn=Symbol(),qo=Symbol(),ea=Symbol(),ta=Symbol(),Mi,Fi;function Ft(e,t,r,n){var o=n[e];if(o)return o;(o={}).W=function(p){switch(typeof p){case"boolean":return li||(li=[0,void 0,!0]);case"number":return p>0?void 0:p===0?Du||(Du=[0,void 0]):[-p,void 0];case"string":return[0,p];case"object":return p}}(n[0]);var s=n[1];let a=1;s&&s.constructor===Object&&(o.ha=s,typeof(s=n[++a])=="function"&&(o.ma=!0,Mi??(Mi=s),Fi??(Fi=n[a+1]),s=n[a+=2]));let i={};for(;s&&Array.isArray(s)&&s.length&&typeof s[0]=="number"&&s[0]>0;){for(var c=0;c<s.length;c++)i[s[c]]=s;s=n[++a]}for(c=1;s!==void 0;){let p;typeof s=="number"&&(c+=s,s=n[++a]);var l=void 0;if(s instanceof er?p=s:(p=$u,a--),p?.l){s=n[++a],l=n;var h=a;typeof s=="function"&&(s=s(),l[h]=s),l=s}for(h=c+1,typeof(s=n[++a])=="number"&&s<0&&(h-=s,s=n[++a]);c<h;c++){let d=i[c];l?r(o,c,p,l,d):t(o,c,p,d)}}return n[e]=o}function Ui(e){return Array.isArray(e)?e[0]instanceof er?e:[qu,e]:[e,void 0]}function Oi(e,t){return e instanceof x?e.u:Array.isArray(e)?xt(e,t,!1):void 0}function Jo(e,t,r,n){let o=r.g;e[t]=n?(s,a,i)=>o(s,a,i,n):o}function Qo(e,t,r,n,o){let s=r.g,a,i;e[t]=(c,l,h)=>s(c,l,h,i||(i=Ft(qo,Jo,Qo,n).W),a||(a=Zo(n)),o)}function Zo(e){let t=e[ea];if(t!=null)return t;let r=Ft(qo,Jo,Qo,e);return t=r.ma?(n,o)=>Mi(n,o,r):(n,o)=>{let s=G(n);for(;_i(o)&&o.h!=4;){var a=o.m,i=r[a];if(i==null){var c=r.ha;c&&(c=c[a])&&(c=Ju(c))!=null&&(i=r[a]=c)}i!=null&&i(o,n,a)||(a=(i=o).l,Nr(i),i.ga?i=void 0:(c=i.g.g-a,i.g.g=a,i=Ti(i.g,c)),a=n,i&&(mt||(mt=Symbol()),(c=a[mt])?c.push(i):a[mt]=[i]))}return 16384&s&&$t(n),!0},e[ea]=t}function Ju(e){let t=(e=Ui(e))[0].g;if(e=e[1]){let r=Zo(e),n=Ft(qo,Jo,Qo,e).W;return(o,s,a)=>t(o,s,a,n,r)}return t}function gn(e,t,r){e[t]=r.h}function xn(e,t,r,n){let o,s,a=r.h;e[t]=(i,c,l)=>a(i,c,l,s||(s=Ft(mn,gn,xn,n).W),o||(o=Pi(n)))}function Pi(e){let t=e[ta];if(!t){let r=Ft(mn,gn,xn,e);t=(n,o)=>Bi(n,o,r),e[ta]=t}return t}function Bi(e,t,r){for(var n=re(e),o=+!!(512&n)-1,s=e.length,a=512&n?1:0,i=s+(256&n?-1:0);a<i;a++){let c=e[a];if(c==null)continue;let l=a-o,h=ra(r,l);h&&h(t,c,l)}if(256&n){n=e[s-1];for(let c in n)o=+c,Number.isNaN(o)||(s=n[o])!=null&&(i=ra(r,o))&&i(t,s,o)}if(e=mt?e[mt]:void 0)for(Wt(t,t.g.end()),r=0;r<e.length;r++)Wt(t,vo(e[r])||new Uint8Array(0))}function ra(e,t){var r=e[t];if(r)return r;if((r=e.ha)&&(r=r[t])){var n=(r=Ui(r))[0].h;if(r=r[1]){let o=Pi(r),s=Ft(mn,gn,xn,r).W;r=e.ma?Fi(s,o):(a,i,c)=>n(a,i,c,s,o)}else r=n;return e[t]=r}}function tr(e,t){if(Array.isArray(t)){var r=re(t);if(4&r)return t;for(var n=0,o=0;n<t.length;n++){let s=e(t[n]);s!=null&&(t[o++]=s)}return o<n&&(t.length=o),oe(t,-12289&(5|r)),2&r&&Object.freeze(t),t}}function ye(e,t,r){return new er(e,t,r)}function rr(e,t,r){return new er(e,t,r)}function ve(e,t,r){J(e,G(e),t,r)}var Qu=pn(function(e,t,r,n,o){return e.h===2&&(e=wr(e,xt([void 0,void 0],n,!0),o),_t(n=G(t)),(o=ht(t,n,r))instanceof Pe?(2&o.M)!=0?((o=o.Y()).push(e),J(t,n,r,o)):o.Na(e):Array.isArray(o)?(2&re(o)&&J(t,n,r,o=mi(o)),o.push(e)):J(t,n,r,[e]),!0)},function(e,t,r,n,o){if(t instanceof Pe)t.forEach((s,a)=>{Qr(e,r,xt([a,s],n,!1),o)});else if(Array.isArray(t))for(let s=0;s<t.length;s++){let a=t[s];Array.isArray(a)&&Qr(e,r,xt(a,n,!1),o)}});function Di(e,t,r){if(t=function(n){if(n==null)return n;let o=typeof n;if(o==="bigint")return String(BigInt.asIntN(64,n));if(an(n)){if(o==="string")return Co(n);if(o==="number")return So(n)}}(t),t!=null&&(typeof t=="string"&&Zs(t),t!=null))switch(Se(e,r,0),typeof t){case"number":e=e.g,Vt(t),Bt(e,V,Z);break;case"bigint":r=BigInt.asUintN(64,t),r=new so(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),Bt(e.g,r.h,r.g);break;default:r=Zs(t),Bt(e.g,r.h,r.g)}}function Ni(e,t,r){(t=qt(t))!=null&&t!=null&&(Se(e,r,0),dn(e.g,t))}function Gi(e,t,r){(t=ai(t))!=null&&(Se(e,r,0),e.g.g.push(t?1:0))}function Vi(e,t,r){(t=gt(t))!=null&&fn(e,r,Ka(t))}function ji(e,t,r,n,o){Qr(e,r,Oi(t,n),o)}function Wi(e,t,r){(t=t==null||typeof t=="string"||_r(t)||t instanceof at?t:void 0)!=null&&fn(e,r,Go(t).buffer)}function Xi(e,t,r){return(e.h===5||e.h===2)&&(t=Qt(t,G(t),r,!1,!1),e.h==2?ln(e,no,t):t.push(no(e.g)),!0)}var ot=ye(function(e,t,r){if(e.h!==1)return!1;var n=e.g;e=ro(n);let o=ro(n);n=2*(o>>31)+1;let s=o>>>20&2047;return e=4294967296*(1048575&o)+e,ve(t,r,s==2047?e?NaN:n*(1/0):s==0?5e-324*n*e:n*Math.pow(2,s-1075)*(e+4503599627370496)),!0},function(e,t,r){(t=At(t))!=null&&(Se(e,r,1),e=e.g,(r=si||(si=new DataView(new ArrayBuffer(8)))).setFloat64(0,+t,!0),V=r.getUint32(0,!0),Z=r.getUint32(4,!0),br(e,V),br(e,Z))},He()),ce=ye(function(e,t,r){return e.h===5&&(ve(t,r,no(e.g)),!0)},function(e,t,r){(t=At(t))!=null&&(Se(e,r,5),e=e.g,Ao(t),br(e,V))},$o),Zu=rr(Xi,function(e,t,r){if((t=tr(At,t))!=null)for(let a=0;a<t.length;a++){var n=e,o=r,s=t[a];s!=null&&(Se(n,o,5),n=n.g,Ao(s),br(n,V))}},$o),es=rr(Xi,function(e,t,r){if((t=tr(At,t))!=null&&t.length){Se(e,r,2),Zt(e.g,4*t.length);for(let n=0;n<t.length;n++)r=e.g,Ao(t[n]),br(r,V)}},$o),bt=ye(function(e,t,r){return e.h===0&&(ve(t,r,Vo(e.g,wo)),!0)},Di,Si),Wn=ye(function(e,t,r){return e.h===0&&(ve(t,r,(e=Vo(e.g,wo))===0?void 0:e),!0)},Di,Si),e2=ye(function(e,t,r){return e.h===0&&(ve(t,r,Vo(e.g,Ro)),!0)},function(e,t,r){if((t=Pu(t))!=null&&(typeof t=="string"&&Qs(t),t!=null))switch(Se(e,r,0),typeof t){case"number":e=e.g,Vt(t),Bt(e,V,Z);break;case"bigint":r=BigInt.asUintN(64,t),r=new oo(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),Bt(e.g,r.h,r.g);break;default:r=Qs(t),Bt(e.g,r.h,r.g)}},He()),ee=ye(function(e,t,r){return e.h===0&&(ve(t,r,Et(e.g)),!0)},Ni,Ko),yn=rr(function(e,t,r){return(e.h===0||e.h===2)&&(t=Qt(t,G(t),r,!1,!1),e.h==2?ln(e,Et,t):t.push(Et(e.g)),!0)},function(e,t,r){if((t=tr(qt,t))!=null&&t.length){r=Xo(e,r);for(let n=0;n<t.length;n++)dn(e.g,t[n]);Ho(e,r)}},Ko),Pt=ye(function(e,t,r){return e.h===0&&(ve(t,r,(e=Et(e.g))===0?void 0:e),!0)},Ni,Ko),q=ye(function(e,t,r){return e.h===0&&(ve(t,r,jo(e.g)),!0)},Gi,wi),Dt=ye(function(e,t,r){return e.h===0&&(ve(t,r,(e=jo(e.g))===!1?void 0:e),!0)},Gi,wi),fe=rr(function(e,t,r){return e.h===2&&(e=Wo(e),Qt(t,G(t),r,!1).push(e),!0)},function(e,t,r){if((t=tr(gt,t))!=null)for(let a=0;a<t.length;a++){var n=e,o=r,s=t[a];s!=null&&fn(n,o,Ka(s))}},zo),pt=ye(function(e,t,r){return e.h===2&&(ve(t,r,(e=Wo(e))===""?void 0:e),!0)},Vi,zo),D=ye(function(e,t,r){return e.h===2&&(ve(t,r,Wo(e)),!0)},Vi,zo),ie=function(e,t,r=Yo){return new er(e,t,r)}(function(e,t,r,n,o){return e.h===2&&(n=xt(void 0,n,!0),Qt(t,G(t),r,!0).push(n),wr(e,n,o),!0)},function(e,t,r,n,o){if(Array.isArray(t))for(let s=0;s<t.length;s++)ji(e,t[s],r,n,o)}),N=pn(function(e,t,r,n,o,s){return e.h===2&&(gi(t,re(t),s,r),wr(e,t=Do(t,n,r),o),!0)},ji),Hi=ye(function(e,t,r){return e.h===2&&(ve(t,r,Ai(e)),!0)},Wi,Ci),t2=rr(function(e,t,r){return(e.h===0||e.h===2)&&(t=Qt(t,G(t),r,!1,!1),e.h==2?ln(e,ut,t):t.push(ut(e.g)),!0)},function(e,t,r){if((t=tr(ii,t))!=null)for(let a=0;a<t.length;a++){var n=e,o=r,s=t[a];s!=null&&(Se(n,o,0),Zt(n.g,s))}},ki),r2=ye(function(e,t,r){return e.h===0&&(ve(t,r,(e=ut(e.g))===0?void 0:e),!0)},function(e,t,r){(t=ii(t))!=null&&t!=null&&(Se(e,r,0),Zt(e.g,t))},ki),We=ye(function(e,t,r){return e.h===0&&(ve(t,r,Et(e.g)),!0)},function(e,t,r){(t=qt(t))!=null&&(t=parseInt(t,10),Se(e,r,0),dn(e.g,t))},Li),ao=class{constructor(t,r){this.h=t,this.g=r,this.l=O,this.m=T,this.defaultValue=void 0}};function Ye(e,t){return new ao(e,t)}function Rt(e,t){return(r,n)=>{if(Ur.length){let s=Ur.pop();s.o(n),jn(s.g,r,n),r=s}else r=new class{constructor(s,a){if(Js.length){let i=Js.pop();jn(i,s,a),s=i}else s=new class{constructor(i,c){this.h=null,this.m=!1,this.g=this.l=this.j=0,jn(this,i,c)}clear(){this.h=null,this.m=!1,this.g=this.l=this.j=0,this.ca=!1}}(s,a);this.g=s,this.l=this.g.g,this.h=this.m=-1,this.o(a)}o({ga:s=!1}={}){this.ga=s}}(r,n);try{let s=new e,a=s.u;Zo(t)(a,r);var o=s}finally{r.g.clear(),r.m=-1,r.h=-1,Ur.length<100&&Ur.push(r)}return o}}function vn(e){return function(){let t=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}}}};Bi(this.u,t,Ft(mn,gn,xn,e)),Wt(t,t.g.end());let r=new Uint8Array(t.h),n=t.l,o=n.length,s=0;for(let a=0;a<o;a++){let i=n[a];r.set(i,s),s+=i.length}return t.l=[r],r}}var na=class extends x{constructor(e){super(e)}},oa=[0,pt,ye(function(e,t,r){return e.h===2&&(ve(t,r,(e=Ai(e))===Mt()?void 0:e),!0)},function(e,t,r){if(t!=null){if(t instanceof x){let n=t.Qa;return void(n&&(t=n(t),t!=null&&fn(e,r,Go(t).buffer)))}if(Array.isArray(t))return}Wi(e,t,r)},Ci)],Xn,sa=globalThis.trustedTypes;function aa(e){Xn===void 0&&(Xn=function(){let r=null;if(!sa)return r;try{let n=o=>o;r=sa.createPolicy("goog#html",{createHTML:n,createScript:n,createScriptURL:n})}catch{}return r}());var t=Xn;return new class{constructor(r){this.g=r}toString(){return this.g+""}}(t?t.createScriptURL(e):e)}function n2(e,...t){if(t.length===0)return aa(e[0]);let r=e[0];for(let n=0;n<t.length;n++)r+=encodeURIComponent(t[n])+e[n+1];return aa(r)}var Yi=[0,ee,We,q,-1,yn,We,-1],o2=class extends x{constructor(){super()}},zi=[0,q,D,q,We,-1,rr(function(e,t,r){return(e.h===0||e.h===2)&&(t=Qt(t,G(t),r,!1,!1),e.h==2?ln(e,Yu,t):t.push(Et(e.g)),!0)},function(e,t,r){if((t=tr(qt,t))!=null&&t.length){r=Xo(e,r);for(let n=0;n<t.length;n++)dn(e.g,t[n]);Ho(e,r)}},Li),D,-1,[0,q,-1],We,q,-1],Ki=[0,D,-2],ia=class extends x{constructor(){super()}},$i=[0],qi=[0,ee,q,1,q,-3],ke=class extends x{constructor(e){super(e,2)}},se={};se[336783863]=[0,D,q,-1,ee,[0,[1,2,3,4,5,6,7],N,$i,N,zi,N,Ki,N,qi,N,Yi,N,[0,D,-2],N,[0,D,We]],[0,D],q,[0,[1,3],[2,4],N,[0,yn],-1,N,[0,fe],-1,ie,[0,D,-1]],D];var ca=[0,Wn,-1,Dt,-3,Wn,yn,pt,Pt,Wn,-1,Dt,Pt,Dt,-2,pt];function Ce(e,t){to(e,2,Jt(t),"")}function H(e,t){hn(e,3,t)}function F(e,t){hn(e,4,t)}var xe=class extends x{constructor(e){super(e,500)}o(e){return T(this,0,7,e)}},gr=[-1,{}],ua=[0,D,1,gr],ha=[0,D,fe,gr];function Le(e,t){$r(e,1,xe,t)}function Y(e,t){hn(e,10,t)}function P(e,t){hn(e,15,t)}var be=class extends x{constructor(e){super(e,500)}o(e){return T(this,0,1001,e)}},Ji=[-500,ie,[-500,pt,-1,fe,-3,[-2,se,q],ie,oa,Pt,-1,ua,ha,ie,[0,pt,Dt],pt,ca,Pt,fe,987,fe],4,ie,[-500,D,-1,[-1,{}],998,D],ie,[-500,D,fe,-1,[-2,{},q],997,fe,-1],Pt,ie,[-500,D,fe,gr,998,fe],fe,Pt,ua,ha,ie,[0,pt,-1,gr],fe,-2,ca,pt,-1,Dt,[0,Dt,r2],978,gr,ie,oa];be.prototype.g=vn(Ji);var s2=Rt(be,Ji),a2=class extends x{constructor(e){super(e)}},Qi=class extends x{constructor(e){super(e)}g(){return ct(this,a2,1)}},Zi=[0,ie,[0,ee,ce,D,-1]],En=Rt(Qi,Zi),i2=class extends x{constructor(e){super(e)}},c2=class extends x{constructor(e){super(e)}},Hn=class extends x{constructor(e){super(e)}h(){return O(this,i2,2)}g(){return ct(this,c2,5)}},ec=Rt(class extends x{constructor(e){super(e)}},[0,fe,yn,es,[0,We,[0,ee,-3],[0,ce,-3],[0,ee,-1,[0,ie,[0,ee,-2]]],ie,[0,ce,-1,D,ce]],D,-1,bt,ie,[0,ee,ce],fe,bt]),tc=class extends x{constructor(e){super(e)}},Nt=Rt(class extends x{constructor(e){super(e)}},[0,ie,[0,ce,-4]]),rc=class extends x{constructor(e){super(e)}},kr=Rt(class extends x{constructor(e){super(e)}},[0,ie,[0,ce,-4]]),u2=class extends x{constructor(e){super(e)}},h2=[0,ee,-1,es,We],nc=class extends x{constructor(){super()}};nc.prototype.g=vn([0,ce,-4,bt]);var l2=class extends x{constructor(e){super(e)}},d2=Rt(class extends x{constructor(e){super(e)}},[0,ie,[0,1,ee,D,Zi],bt]),la=class extends x{constructor(e){super(e)}},f2=class extends x{constructor(e){super(e)}pa(){let e=pi(this);return e??Mt()}},p2=class extends x{constructor(e){super(e)}},oc=[1,2],m2=Rt(class extends x{constructor(e){super(e)}},[0,ie,[0,oc,N,[0,es],N,[0,Hi],ee,D],bt]),ts=class extends x{constructor(e){super(e)}},sc=[0,D,ee,ce,fe,-1],da=class extends x{constructor(e){super(e)}},g2=[0,q,-1],fa=class extends x{constructor(e){super(e)}},Gr=[1,2,3,4,5],Zr=class extends x{constructor(e){super(e)}g(){return pi(this)!=null}h(){return gt(vt(this,2))!=null}},$=class extends x{constructor(e){super(e)}g(){return ai(vt(this,2))??!1}},ac=[0,Hi,D,[0,ee,bt,-1],[0,e2,bt]],ne=[0,ac,q,[0,Gr,N,qi,N,zi,N,Yi,N,$i,N,Ki],We],bn=class extends x{constructor(e){super(e)}},rs=[0,ne,ce,-1,ee],x2=Ye(502141897,bn);se[502141897]=rs;var y2=Rt(class extends x{constructor(e){super(e)}},[0,[0,We,-1,Zu,t2],h2]),ic=class extends x{constructor(e){super(e)}},cc=class extends x{constructor(e){super(e)}},ns=[0,ne,ce,[0,ne],q],uc=[0,ne,rs,ns,ce,[0,[0,ac]]],v2=Ye(508968150,cc);se[508968150]=uc,se[508968149]=ns;var hc=class extends x{constructor(e){super(e)}},E2=Ye(513916220,hc);se[513916220]=[0,ne,uc,ee];var Ut=class extends x{constructor(e){super(e)}h(){return O(this,ts,2)}g(){X(this,2)}},lc=[0,ne,sc];se[478825465]=lc;var b2=class extends x{constructor(e){super(e)}},dc=class extends x{constructor(e){super(e)}},os=class extends x{constructor(e){super(e)}},ss=class extends x{constructor(e){super(e)}},fc=class extends x{constructor(e){super(e)}},pa=[0,ne,[0,ne],lc,-1],pc=[0,ne,ce,ee],as=[0,ne,ce],mc=[0,ne,pc,as,ce],T2=Ye(479097054,fc);se[479097054]=[0,ne,mc,pa],se[463370452]=pa,se[464864288]=pc;var _2=Ye(462713202,ss);se[462713202]=mc,se[474472470]=as;var A2=class extends x{constructor(e){super(e)}},gc=class extends x{constructor(e){super(e)}},xc=class extends x{constructor(e){super(e)}},yc=class extends x{constructor(){super()}},is=[0,ne,ce,-1,ee],io=[0,ne,ce,q];yc.prototype.g=vn([0,ne,as,[0,ne],rs,ns,is,io]);var vc=class extends x{constructor(e){super(e)}},R2=Ye(456383383,vc);se[456383383]=[0,ne,sc];var Ec=class extends x{constructor(e){super(e)}},w2=Ye(476348187,Ec);se[476348187]=[0,ne,g2];var bc=class extends x{constructor(e){super(e)}},ma=class extends x{constructor(e){super(e)}},Tc=[0,We,-1],k2=Ye(458105876,class extends x{constructor(e){super(e)}g(){var e=this.u;let t=G(e),r=2&t;return e=function(n,o,s){var a=ma;let i=2&o,c=!1;if(s==null){if(i)return $s();s=[]}else if(s.constructor===Pe){if((2&s.M)==0||i)return s;s=s.Y()}else Array.isArray(s)?c=!!(2&re(s)):s=[];if(i){if(!s.length)return $s();c||(c=!0,$t(s))}else c&&(c=!1,s=mi(s));return c||(64&re(s)?Jn(s,32):32&o&&rn(s,32)),J(n,o,2,a=new Pe(s,a,Bu,void 0)),a}(e,t,ht(e,t,2)),!r&&ma&&(e.sa=!0),e}});se[458105876]=[0,Tc,Qu,[!0,bt,[0,D,-1,fe]]];var cs=class extends x{constructor(e){super(e)}},_c=Ye(458105758,cs);se[458105758]=[0,ne,D,Tc];var Ac=class extends x{constructor(e){super(e)}},S2=Ye(443442058,Ac);se[443442058]=[0,ne,D,ee,ce,fe,-1],se[514774813]=is;var Rc=class extends x{constructor(e){super(e)}},C2=Ye(516587230,Rc);function co(e,t){return t=t?t.clone():new ts,e.displayNamesLocale!==void 0?X(t,1,Jt(e.displayNamesLocale)):e.displayNamesLocale===void 0&&X(t,1),e.maxResults!==void 0?tt(t,2,e.maxResults):"maxResults"in e&&X(t,2),e.scoreThreshold!==void 0?v(t,3,e.scoreThreshold):"scoreThreshold"in e&&X(t,3),e.categoryAllowlist!==void 0?qr(t,4,e.categoryAllowlist):"categoryAllowlist"in e&&X(t,4),e.categoryDenylist!==void 0?qr(t,5,e.categoryDenylist):"categoryDenylist"in e&&X(t,5),t}function us(e,t=-1,r=""){return{categories:e.map(n=>({index:je(Oe(n,1),0)??-1,score:te(n,2)??0,categoryName:et(n,3)??"",displayName:et(n,4)??""})),headIndex:t,headName:r}}function wc(e){var t=Ct(e,3,At,St()),r=Ct(e,2,qt,St()),n=Ct(e,1,gt,St()),o=Ct(e,9,gt,St());let s={categories:[],keypoints:[]};for(let a=0;a<t.length;a++)s.categories.push({score:t[a],index:r[a]??-1,categoryName:n[a]??"",displayName:o[a]??""});if((t=O(e,Hn,4)?.h())&&(s.boundingBox={originX:Oe(t,1)??0,originY:Oe(t,2)??0,width:Oe(t,3)??0,height:Oe(t,4)??0,angle:0}),O(e,Hn,4)?.g().length)for(let a of O(e,Hn,4).g())s.keypoints.push({x:Dr(a,1)??0,y:Dr(a,2)??0,score:Dr(a,4)??0,label:gt(vt(a,3))??""});return s}function Tn(e){let t=[];for(let r of ct(e,rc,1))t.push({x:te(r,1)??0,y:te(r,2)??0,z:te(r,3)??0,visibility:te(r,4)??0});return t}function xr(e){let t=[];for(let r of ct(e,tc,1))t.push({x:te(r,1)??0,y:te(r,2)??0,z:te(r,3)??0,visibility:te(r,4)??0});return t}function ga(e){return Array.from(e,t=>t>127?t-256:t)}function xa(e,t){if(e.length!==t.length)throw Error(`Cannot compute cosine similarity between embeddings of different sizes (${e.length} vs. ${t.length}).`);let r=0,n=0,o=0;for(let s=0;s<e.length;s++)r+=e[s]*t[s],n+=e[s]*e[s],o+=t[s]*t[s];if(n<=0||o<=0)throw Error("Cannot compute cosine similarity on embedding with 0 norm.");return r/Math.sqrt(n*o)}var Or;se[516587230]=[0,ne,is,io,ce],se[518928384]=io;var L2=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 kc(){if(Or===void 0)try{await WebAssembly.instantiate(L2),Or=!0}catch{Or=!1}return Or}async function hr(e,t=n2``){let r=await kc()?"wasm_internal":"wasm_nosimd_internal";return{wasmLoaderPath:`${t}/${e}_${r}.js`,wasmBinaryPath:`${t}/${e}_${r}.wasm`}}var dt=class{};function Sc(){var e=navigator;return typeof OffscreenCanvas<"u"&&(!function(t=navigator){return(t=t.userAgent).includes("Safari")&&!t.includes("Chrome")}(e)||!!((e=e.userAgent.match(/Version\/([\d]+).*Safari/))&&e.length>=1&&Number(e[1])>=17))}async function ya(e){if(typeof importScripts!="function"){let t=document.createElement("script");return t.src=e.toString(),t.crossOrigin="anonymous",new Promise((r,n)=>{t.addEventListener("load",()=>{r()},!1),t.addEventListener("error",o=>{n(o)},!1),document.body.appendChild(t)})}importScripts(e.toString())}function Cc(e){return e.videoWidth!==void 0?[e.videoWidth,e.videoHeight]:e.naturalWidth!==void 0?[e.naturalWidth,e.naturalHeight]:e.displayWidth!==void 0?[e.displayWidth,e.displayHeight]:[e.width,e.height]}function E(e,t,r){e.m||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target"),r(t=e.i.stringToNewUTF8(t)),e.i._free(t)}function va(e,t,r){if(!e.i.canvas)throw Error("No OpenGL canvas configured.");if(r?e.i._bindTextureToStream(r):e.i._bindTextureToCanvas(),!(r=e.i.canvas.getContext("webgl2")||e.i.canvas.getContext("webgl")))throw Error("Failed to obtain WebGL context from the provided canvas. `getContext()` should only be invoked with `webgl` or `webgl2`.");e.i.gpuOriginForWebTexturesIsBottomLeft&&r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!0),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t),e.i.gpuOriginForWebTexturesIsBottomLeft&&r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1);let[n,o]=Cc(t);return!e.l||n===e.i.canvas.width&&o===e.i.canvas.height||(e.i.canvas.width=n,e.i.canvas.height=o),[n,o]}function Ea(e,t,r){e.m||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target");let n=new Uint32Array(t.length);for(let o=0;o<t.length;o++)n[o]=e.i.stringToNewUTF8(t[o]);t=e.i._malloc(4*n.length),e.i.HEAPU32.set(n,t>>2),r(t);for(let o of n)e.i._free(o);e.i._free(t)}function qe(e,t,r){e.i.simpleListeners=e.i.simpleListeners||{},e.i.simpleListeners[t]=r}function lt(e,t,r){let n=[];e.i.simpleListeners=e.i.simpleListeners||{},e.i.simpleListeners[t]=(o,s,a)=>{s?(r(n,a),n=[]):n.push(o)}}dt.forVisionTasks=function(e){return hr("vision",e)},dt.forTextTasks=function(e){return hr("text",e)},dt.forGenAiExperimentalTasks=function(e){return hr("genai_experimental",e)},dt.forGenAiTasks=function(e){return hr("genai",e)},dt.forAudioTasks=function(e){return hr("audio",e)},dt.isSimdSupported=function(){return kc()};async function I2(e,t,r,n){return e=await(async(o,s,a,i,c)=>{if(s&&await ya(s),!self.ModuleFactory||a&&(await ya(a),!self.ModuleFactory))throw Error("ModuleFactory not set.");return self.Module&&c&&((s=self.Module).locateFile=c.locateFile,c.mainScriptUrlOrBlob&&(s.mainScriptUrlOrBlob=c.mainScriptUrlOrBlob)),c=await self.ModuleFactory(self.Module||c),self.ModuleFactory=self.Module=void 0,new o(c,i)})(e,r.wasmLoaderPath,r.assetLoaderPath,t,{locateFile:o=>o.endsWith(".wasm")?r.wasmBinaryPath.toString():r.assetBinaryPath&&o.endsWith(".data")?r.assetBinaryPath.toString():o}),await e.o(n),e}function Yn(e,t){let r=O(e.baseOptions,Zr,1)||new Zr;typeof t=="string"?(X(r,2,Jt(t)),X(r,1)):t instanceof Uint8Array&&(X(r,1,_o(t,!1)),X(r,2)),T(e.baseOptions,0,1,r)}function ba(e){try{let t=e.H.length;if(t===1)throw Error(e.H[0].message);if(t>1)throw Error("Encountered multiple errors: "+e.H.map(r=>r.message).join(", "))}finally{e.H=[]}}function m(e,t){e.B=Math.max(e.B,t)}function _n(e,t){e.A=new xe,Ce(e.A,"PassThroughCalculator"),H(e.A,"free_memory"),F(e.A,"free_memory_unused_out"),Y(t,"free_memory"),Le(t,e.A)}function Xt(e,t){H(e.A,t),F(e.A,t+"_unused_out")}function An(e){e.g.addBoolToStream(!0,"free_memory",e.B)}var Vr=class{constructor(e){this.g=e,this.H=[],this.B=0,this.g.setAutoRenderToScreen(!1)}l(e,t=!0){if(t){let r=e.baseOptions||{};if(e.baseOptions?.modelAssetBuffer&&e.baseOptions?.modelAssetPath)throw Error("Cannot set both baseOptions.modelAssetPath and baseOptions.modelAssetBuffer");if(!(O(this.baseOptions,Zr,1)?.g()||O(this.baseOptions,Zr,1)?.h()||e.baseOptions?.modelAssetBuffer||e.baseOptions?.modelAssetPath))throw Error("Either baseOptions.modelAssetPath or baseOptions.modelAssetBuffer must be set");if(function(n,o){let s=O(n.baseOptions,fa,3);if(!s){var a=s=new fa,i=new ia;mr(a,4,Gr,i)}"delegate"in o&&(o.delegate==="GPU"?(o=s,a=new o2,mr(o,2,Gr,a)):(o=s,a=new ia,mr(o,4,Gr,a))),T(n.baseOptions,0,3,s)}(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),Yn(this,"/model.dat"),this.m(),this.J()});if(r.modelAssetBuffer instanceof Uint8Array)Yn(this,r.modelAssetBuffer);else if(r.modelAssetBuffer)return async function(n){let o=[];for(var s=0;;){let{done:a,value:i}=await n.read();if(a)break;o.push(i),s+=i.length}if(o.length===0)return new Uint8Array(0);if(o.length===1)return o[0];n=new Uint8Array(s),s=0;for(let a of o)n.set(a,s),s+=a.length;return n}(r.modelAssetBuffer).then(n=>{Yn(this,n),this.m(),this.J()})}return this.m(),this.J(),Promise.resolve()}J(){}ea(){let e;if(this.g.ea(t=>{e=s2(t)}),!e)throw Error("Failed to retrieve CalculatorGraphConfig");return e}setGraph(e,t){this.g.attachErrorListener((r,n)=>{this.H.push(Error(n))}),this.g.La(),this.g.setGraph(e,t),this.A=void 0,ba(this)}finishProcessing(){this.g.finishProcessing(),ba(this)}close(){this.A=void 0,this.g.closeGraph()}};function ge(e,t){if(!e)throw Error(`Unable to obtain required WebGL resource: ${t}`);return e}Vr.prototype.close=Vr.prototype.close,za("TaskRunner",Vr);var uo=class{constructor(t,r,n,o){this.g=t,this.h=r,this.m=n,this.l=o}bind(){this.g.bindVertexArray(this.h)}close(){this.g.deleteVertexArray(this.h),this.g.deleteBuffer(this.m),this.g.deleteBuffer(this.l)}};function Ta(e,t,r){let n=e.g;if(r=ge(n.createShader(r),"Failed to create WebGL shader"),n.shaderSource(r,t),n.compileShader(r),!n.getShaderParameter(r,n.COMPILE_STATUS))throw Error(`Could not compile WebGL shader: ${n.getShaderInfoLog(r)}`);return n.attachShader(e.h,r),r}function _a(e,t){let r=e.g,n=ge(r.createVertexArray(),"Failed to create vertex array");r.bindVertexArray(n);let o=ge(r.createBuffer(),"Failed to create buffer");r.bindBuffer(r.ARRAY_BUFFER,o),r.enableVertexAttribArray(e.P),r.vertexAttribPointer(e.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 s=ge(r.createBuffer(),"Failed to create buffer");return r.bindBuffer(r.ARRAY_BUFFER,s),r.enableVertexAttribArray(e.J),r.vertexAttribPointer(e.J,2,r.FLOAT,!1,0,0),r.bufferData(r.ARRAY_BUFFER,new Float32Array(t?[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 uo(r,n,o,s)}function hs(e,t){if(e.g){if(t!==e.g)throw Error("Cannot change GL context once initialized")}else e.g=t}function Sr(e,t,r,n){return hs(e,t),e.h||(e.m(),e.C()),r?(e.s||(e.s=_a(e,!0)),r=e.s):(e.v||(e.v=_a(e,!1)),r=e.v),t.useProgram(e.h),r.bind(),e.l(),e=n(),r.g.bindVertexArray(null),e}function Tt(e,t,r){return hs(e,t),e=ge(t.createTexture(),"Failed to create texture"),t.bindTexture(t.TEXTURE_2D,e),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,r??t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,r??t.LINEAR),t.bindTexture(t.TEXTURE_2D,null),e}function Rn(e,t,r){hs(e,t),e.A||(e.A=ge(t.createFramebuffer(),"Failed to create framebuffe.")),t.bindFramebuffer(t.FRAMEBUFFER,e.A),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r,0)}function ls(e){e.g?.bindFramebuffer(e.g.FRAMEBUFFER,null)}var nr=class{H(){return`
|
|
1
|
+
var Fr=typeof self<"u"?self:{};function Nc(t,e){t=t.split(".");var r,n=Fr;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 Rr(){throw Error("Invalid UTF8")}function Eu(t,e){return e=String.fromCharCode.apply(null,e),t==null?e:t+e}var is,Vo,jh=typeof TextDecoder<"u",Yh,qh=typeof TextEncoder<"u";function Gc(t){if(qh)t=(Yh||(Yh=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 wa,bs;e:{for(Wo=["CLOSURE_FLAGS"],us=Fr,cs=0;cs<Wo.length;cs++)if((us=us[Wo[cs]])==null){bs=null;break e}bs=us}var Wo,us,cs,Mn,Au=bs&&bs[610401301];wa=Au!=null&&Au;var Ru=Fr.navigator;function ta(t){return!!wa&&!!Mn&&Mn.brands.some(({brand:e})=>e&&e.indexOf(t)!=-1)}function bt(t){var e;return(e=Fr.navigator)&&(e=e.userAgent)||(e=""),e.indexOf(t)!=-1}function fr(){return!!wa&&!!Mn&&Mn.brands.length>0}function $o(){return fr()?ta("Chromium"):(bt("Chrome")||bt("CriOS"))&&!(!fr()&&bt("Edge"))||bt("Silk")}function Ta(t){return Ta[" "](t),t}Mn=Ru&&Ru.userAgentData||null,Ta[" "]=function(){};var Kh=!fr()&&(bt("Trident")||bt("MSIE"));!bt("Android")||$o(),$o(),bt("Safari")&&($o()||!fr()&&bt("Coast")||!fr()&&bt("Opera")||!fr()&&bt("Edge")||(fr()?ta("Microsoft Edge"):bt("Edg/"))||fr()&&ta("Opera"));var Vc={},Bn=null;function Zh(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=Bn[c];if(f!=null)return f;if(!/^[\s\xa0]*$/.test(c))throw Error("Unknown base64 encoding at char: "+c)}return l}Wc();let u=0;for(;;){let l=i(-1),c=i(0),f=i(64),m=i(64);if(m===64&&l===-1)break;a(l<<2|c>>4),f!=64&&(a(c<<4&240|f>>2),m!=64&&a(f<<6&192|m))}}(t,function(o){n[s++]=o}),s!==r?n.subarray(0,s):n}function Wc(){if(!Bn){Bn={};var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"];for(let r=0;r<5;r++){let n=t.concat(e[r].split(""));Vc[r]=n;for(let s=0;s<n.length;s++){let o=n[s];Bn[o]===void 0&&(Bn[o]=s)}}}}var $c=typeof Uint8Array<"u",zc=!Kh&&typeof btoa=="function";function Iu(t){if(!zc){var e;e===void 0&&(e=0),Wc(),e=Vc[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 Su=/[-_.]/g,Jh={"-":"+",_:"/",".":"="};function Qh(t){return Jh[t]||""}function Hc(t){if(!zc)return Zh(t);Su.test(t)&&(t=t.replace(Su,Qh)),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 $n(t){return $c&&t!=null&&t instanceof Uint8Array}var Xr={};function Br(){return ed||(ed=new tr(null,Xr))}function ka(t){Xc(Xr);var e=t.g;return(e=e==null||$n(e)?e:typeof e=="string"?Hc(e):null)==null?e:t.g=e}var tr=class{h(){return new Uint8Array(ka(this)||0)}constructor(t,e){if(Xc(e),this.g=t,t!=null&&t.length===0)throw Error("ByteString should be constructed with non-empty values")}},ed,td;function Xc(t){if(t!==Xr)throw Error("illegal external caller")}function jc(t,e){t.__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity=e}function Yc(){let t=Error();jc(t,"incident"),function(e){Fr.setTimeout(()=>{throw e},0)}(t)}function ra(t){return jc(t=Error(t),"warning"),t}function Ea(){return typeof BigInt=="function"}function ct(t){return Array.prototype.slice.call(t)}var en=typeof Symbol=="function"&&typeof Symbol()=="symbol";function Fs(t){return typeof Symbol=="function"&&typeof Symbol()=="symbol"?Symbol():t}var zn=Fs(),Cu=Fs("0di"),zo=Fs("2ex"),Rn=Fs("1oa"),Bs=en?(t,e)=>{t[zn]|=e}:(t,e)=>{t.G!==void 0?t.G|=e:Object.defineProperties(t,{G:{value:e,configurable:!0,writable:!0,enumerable:!1}})},na=en?(t,e)=>{t[zn]&=~e}:(t,e)=>{t.G!==void 0&&(t.G&=~e)},Re=en?t=>0|t[zn]:t=>0|t.G,oe=en?t=>t[zn]:t=>t.G,Be=en?(t,e)=>{t[zn]=e}:(t,e)=>{t.G!==void 0?t.G=e:Object.defineProperties(t,{G:{value:e,configurable:!0,writable:!0,enumerable:!1}})};function tn(t){return Bs(t,34),t}function rd(t,e){Be(e,-30975&(0|t))}function sa(t,e){Be(e,-30941&(34|t))}var Aa,Hn={},qc={};function Fu(t){return!(!t||typeof t!="object"||t.Ia!==qc)}function Ra(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)&&t.constructor===Object}function Ia(t,e){if(t!=null){if(typeof t=="string")t=t?new tr(t,Xr):Br();else if(t.constructor!==tr)if($n(t))t=t.length?new tr(new Uint8Array(t),Xr):Br();else{if(!e)throw Error();t=void 0}}return t}function vs(t){return!(!Array.isArray(t)||t.length)&&!!(1&Re(t))}var Bu=[];function vr(t){if(2&t)throw Error()}Be(Bu,55),Aa=Object.freeze(Bu);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)}},dr;function Kc(t,e){(e=dr?e[dr]:void 0)&&(t[dr]=ct(e))}var nd=Object.freeze({});function Us(t){return t.Pa=!0,t}var sd=Us(t=>typeof t=="number"),Uu=Us(t=>typeof t=="string"),od=Us(t=>typeof t=="boolean"),Ls=typeof Fr.BigInt=="function"&&typeof Fr.BigInt(0)=="bigint",oa=Us(t=>Ls?t>=id&&t<=cd:t[0]==="-"?Lu(t,ad):Lu(t,ud)),ad=Number.MIN_SAFE_INTEGER.toString(),id=Ls?BigInt(Number.MIN_SAFE_INTEGER):void 0,ud=Number.MAX_SAFE_INTEGER.toString(),cd=Ls?BigInt(Number.MAX_SAFE_INTEGER):void 0;function Lu(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 ld=typeof Uint8Array.prototype.slice=="function",Zc,ie=0,Te=0;function Pu(t){let e=t>>>0;ie=e,Te=(t-e)/4294967296>>>0}function jr(t){if(t<0){Pu(-t);let[e,r]=Ba(ie,Te);ie=e>>>0,Te=r>>>0}else Pu(t)}function Sa(t){let e=Zc||(Zc=new DataView(new ArrayBuffer(8)));e.setFloat32(0,+t,!0),Te=0,ie=e.getUint32(0,!0)}function Ca(t,e){let r=4294967296*e+(t>>>0);return Number.isSafeInteger(r)?r:Nn(t,e)}function Fa(t,e){let r=2147483648&e;return r&&(e=~e>>>0,(t=1+~t>>>0)==0&&(e=e+1>>>0)),typeof(t=Ca(t,e))=="number"?r?-t:t:r?"-"+t:t}function Nn(t,e){if(t>>>=0,(e>>>=0)<=2097151)var r=""+(4294967296*e+t);else Ea()?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+Ou(r)+Ou(t));return r}function Ou(t){return t=String(t),"0000000".slice(t.length)+t}function Ps(t){if(t.length<16)jr(Number(t));else if(Ea())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]=Ba(ie,Te);ie=n,Te=s}}}function Ba(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function wr(t){return t==null||typeof t=="number"?t:t==="NaN"||t==="Infinity"||t==="-Infinity"?Number(t):void 0}function Jc(t){return t==null||typeof t=="boolean"?t:typeof t=="number"?!!t:void 0}var fd=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function Os(t){let e=typeof t;switch(e){case"bigint":return!0;case"number":return Number.isFinite(t)}return e==="string"&&fd.test(t)}function rn(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 Qc(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 Du(t){return t[0]!=="-"&&(t.length<20||t.length===20&&Number(t.substring(0,6))<184467)}function Ua(t){return t=Math.trunc(t),Number.isSafeInteger(t)||(jr(t),t=Fa(ie,Te)),t}function La(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(Ps(t),t=ie,2147483648&(e=Te))if(Ea())t=""+(BigInt(0|e)<<BigInt(32)|BigInt(t>>>0));else{let[r,n]=Ba(t,e);t="-"+Nn(r,n)}else t=Nn(t,e);return t}function Ts(t){return t==null?t:typeof t=="bigint"?(oa(t)?t=Number(t):(t=BigInt.asIntN(64,t),t=oa(t)?Number(t):String(t)),t):Os(t)?typeof t=="number"?Ua(t):La(t):void 0}function hd(t){if(t==null)return t;var e=typeof t;if(e==="bigint")return String(BigInt.asUintN(64,t));if(Os(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)),Du(t)||(Ps(t),t=Nn(ie,Te))),t;if(e==="number")return(t=Math.trunc(t))>=0&&Number.isSafeInteger(t)?t:function(r){if(r<0){jr(r);var n=Nn(ie,Te);return r=Number(n),Number.isSafeInteger(r)?r:n}return Du(n=String(r))?n:(jr(r),Ca(ie,Te))}(t)}}function el(t){if(typeof t!="string")throw Error();return t}function nn(t){if(t!=null&&typeof t!="string")throw Error();return t}function mr(t){return t==null||typeof t=="string"?t:void 0}function Pa(t,e,r,n){if(t!=null&&typeof t=="object"&&t.X===Hn)return t;if(!Array.isArray(t))return r?2&n?(t=e[Cu])?e=t:(tn((t=new e).u),e=e[Cu]=t):e=new e:e=void 0,e;let s=r=Re(t);return s===0&&(s|=32&n),s|=2&n,s!==r&&Be(t,s),new e(t)}function dd(t,e,r){if(e)e:{if(!Os(e=t))throw ra("int64");switch(typeof e){case"string":e=La(e);break e;case"bigint":if(t=e=BigInt.asIntN(64,e),Uu(t)){if(!/^\s*(?:-?[1-9]\d*|0)?\s*$/.test(t))throw Error(String(t))}else if(sd(t)&&!Number.isSafeInteger(t))throw Error(String(t));e=Ls?BigInt(e):od(e)?e?"1":"0":Uu(e)?e.trim()||"0":String(e);break e;default:e=Ua(e)}}else e=Ts(t);return typeof(r=(t=e)==null?r?0:void 0:t)=="string"&&(e=+r,Number.isSafeInteger(e))?e:r}function tl(t){var e;return In===void 0&&(In=typeof Proxy=="function"?Mu(Proxy):null),(e=!In)||(Sn===void 0&&(Sn=typeof WeakMap=="function"?Mu(WeakMap):null),e=!Sn),e?t:(e=Yr?.get(t))?e:Math.random()>.01?t:(function(r){if(Ho===void 0){let n=new In([],{});Ho=Array.prototype.concat.call([],n).length===1}Ho&&typeof Symbol=="function"&&Symbol.isConcatSpreadable&&(r[Symbol.isConcatSpreadable]=!0)}(t),function(r,n){(Yr||(Yr=new Sn)).set(r,n),(rl||(rl=new Sn)).set(n,r)}(t,e=new In(t,{set:(r,n,s)=>(Yc(),r[n]=s,!0)})),e)}var Yr,rl,In,Sn,Ho,ks,nl,md;function Mu(t){try{return t.toString().indexOf("[native code]")!==-1?t:null}catch{return null}}function pr(t,e,r){return t=sl(t,e[0],e[1],r?1:2),e!==nl&&r&&Bs(t,16384),t}function sl(t,e,r,n){if(n=n??0,t==null&&(t=ks),ks=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=Re(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(Ra(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 pd={},gd=function(){try{return Ta(new class extends Map{constructor(){super()}}),!1}catch{return!0}}(),Ln=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()}},xd=gd?(Object.setPrototypeOf(Ln.prototype,Map.prototype),Object.defineProperties(Ln.prototype,{size:{value:0,configurable:!0,enumerable:!0,writable:!0}}),Ln):class extends Map{constructor(){super()}};function Nu(t){return t}function Xo(t){if(2&t.M)throw Error("Cannot mutate an immutable Map")}var wt=class extends xd{constructor(t,e,r=Nu,n=Nu){super();let s=Re(t);s|=64,Be(t,s),this.M=s,this.T=e,this.S=r,this.Z=this.T?yd: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=Gu){if(this.size!==0)return this.Y(t)}Y(t=Gu){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(){Xo(this),super.clear()}delete(t){return Xo(this),super.delete(this.S(t,!0,!1))}entries(){var t=this.na();return new ws(t,_d,this)}keys(){return this.Ha()}values(){var t=this.na();return new ws(t,wt.prototype.get,this)}forEach(t,e){super.forEach((r,n)=>{t.call(e,this.get(n),n,this)})}set(t,e){return Xo(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 yd(t,e,r,n,s,o){return t=Pa(t,n,r,o),s&&(t=Ms(t)),t}function Gu(t){return t}function _d(t){return[t,this.get(t)]}var bd;function Vu(){return bd||(bd=new wt(tn([]),void 0,void 0,void 0,pd))}function Oa(t,e,r,n,s){if(t!=null){if(Array.isArray(t))t=vs(t)?void 0:s&&2&Re(t)?t:Ds(t,e,r,n!==void 0,s);else if(Ra(t)){let o={};for(let a in t)o[a]=Oa(t[a],e,r,n,s);t=o}else t=e(t,n);return t}}function Ds(t,e,r,n,s){let o=n||r?Re(t):0;n=n?!!(32&o):void 0;let a=ct(t);for(let i=0;i<a.length;i++)a[i]=Oa(a[i],e,r,n,s);return r&&(Kc(a,t),r(o,a)),a}function vd(t){return Oa(t,Da,void 0,void 0,!1)}function Da(t){return t.X===Hn?t.toJSON():t instanceof wt?t.oa(vd):function(e){switch(typeof e){case"number":return isFinite(e)?e:String(e);case"bigint":return oa(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($n(e))return Iu(e);if(e instanceof tr){let r=e.g;return r==null?"":typeof r=="string"?r:e.g=Iu(r)}if(e instanceof wt)return e.oa()}}return e}(t)}function aa(t,e,r=sa){if(t!=null){if($c&&t instanceof Uint8Array)return e?t:new Uint8Array(t);if(Array.isArray(t)){var n=Re(t);return 2&n?t:(e&&(e=n===0||!!(32&n)&&!(64&n||!(16&n))),e?(Be(t,-12293&(34|n)),t):Ds(t,aa,4&n?sa:r,!0,!0))}return t.X===Hn?(r=t.u,t=2&(n=oe(r))?t:Ma(t,r,n,!0)):t instanceof wt&&!(2&t.M)&&(r=tn(t.Y(aa)),t=new wt(r,t.T,t.S,t.Z)),t}}function Ma(t,e,r,n){return t=t.constructor,ks=e=ol(e,r,n),e=new t(e),ks=void 0,e}function ol(t,e,r){let n=r||2&e?sa:rd,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 Kc(u,o),u}(t,e,o=>aa(o,s,n)),Bs(t,32|(r?2:0)),t}function Ms(t){let e=t.u,r=oe(e);return 2&r?Ma(t,e,r,!1):t}function xr(t,e){return or(t=t.u,oe(t),e)}function Wu(t,e,r,n){if(!((e=n+(+!!(512&e)-1))<0||e>=t.length||e>=r))return t[e]}function or(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?(Wu(t,e,s,r)&&zo!=null&&((e=(t=td??(td={}))[zo]||0)>=4||(t[zo]=e+1,Yc())),n):Wu(t,e,s,r)}return 256&e?t[t.length-1][r]:void 0}function ce(t,e,r){let n=t.u,s=oe(n);return vr(s),be(n,s,e,r),t}function be(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 ms(t,e){t=t.u;let r=oe(t),n=or(t,r,e),s=wr(n);return s!=null&&s!==n&&be(t,r,e,s),s}function al(t){t=t.u;let e=oe(t),r=or(t,e,1),n=Ia(r,!0);return n!=null&&n!==r&&be(t,e,1,n),n}function Ir(){return nd===void 0?2:4}function Sr(t,e,r,n,s){let o=t.u,a=2&(t=oe(o))?1:n;s=!!s,n=Na(o,t,e);var i=Re(n);if(!(4&i)){4&i&&(n=ct(n),i=rr(i,t),t=be(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=Ga(i,t))),Be(n,i&=-8193),2&i&&Object.freeze(n)}let u;return a===1||a===4&&32&i?Ft(i)||(s=i,(i|=2)!==s&&Be(n,i),Object.freeze(n)):(r=a===5&&(!!(32&i)||Ft(i)||!!Yr?.get(n)),(a===2||r)&&Ft(i)&&(n=ct(n),i=gr(i=rr(i,t),t,s),Be(n,i),t=be(o,t,e,n)),Ft(i)||(e=i,(i=gr(i,t,s))!==e&&Be(n,i)),r?u=tl(n):a!==2||s||Yr?.delete(n)),u||n}function Na(t,e,r,n){return t=or(t,e,r,n),Array.isArray(t)?t:Aa}function Ga(t,e){return t===0&&(t=rr(t,e)),1|t}function Ft(t){return!!(2&t)&&!!(4&t)||!!(2048&t)}function il(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]=tn(r[1]))}return t}function ia(t,e,r,n){t=t.u;let s=oe(t);vr(s),be(t,s,e,(n==="0"?Number(r)===0:r===n)?void 0:r)}function sn(t,e,r,n,s){vr(e);var o=!(!(64&e)&&16384&e);let a=(s=Na(t,e,r,s))!==Aa;if(o||!a){let i=o=a?Re(s):0;(!a||2&i||Ft(i)||4&i&&!(32&i))&&(s=ct(s),i=rr(i,e),e=be(t,e,r,s)),i=-13&Ga(i,e),i=gr(n?-17&i:16|i,e,!0),i!==o&&Be(s,i)}return s}function jo(t,e){var r=Kl;return Wa(Va(t=t.u),t,oe(t),r)===e?e:-1}function Va(t){if(en)return t[Rn]??(t[Rn]=new Map);if(Rn in t)return t[Rn];let e=new Map;return Object.defineProperty(t,Rn,{value:e}),e}function ul(t,e,r,n){let s=Va(t),o=Wa(s,t,e,r);return o!==n&&(o&&(e=be(t,e,o)),s.set(r,n)),e}function Wa(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];or(e,r,a)!=null&&(s!==0&&(r=be(e,r,s)),s=a)}return t.set(n,s),s}function $a(t,e,r,n){let s,o=oe(t);if((n=or(t,o,r,n))!=null&&n.X===Hn)return(e=Ms(n))!==n&&be(t,o,r,e),e.u;if(Array.isArray(n)){let a=Re(n);s=2&a?pr(ol(n,a,!1),e,!0):64&a?n:pr(s,e,!0)}else s=pr(void 0,e,!0);return s!==n&&be(t,o,r,s),s}function cl(t,e,r,n){t=t.u;let s=oe(t);return(e=Pa(n=or(t,s,r,n),e,!1,s))!==n&&e!=null&&be(t,s,r,e),e}function Y(t,e,r,n=!1){if((e=cl(t,e,r,n))==null)return e;if(t=t.u,!(2&(n=oe(t)))){let s=Ms(e);s!==e&&be(t,n,r,e=s)}return e}function ll(t,e,r,n,s,o,a){t=t.u;var i=!!(2&e);s=i?1:s,o=!!o,a&&(a=!i),i=Na(t,e,n);var u=Re(i),l=!!(4&u);if(!l){var c=i,f=e;let p=!!(2&(u=Ga(u,e)));p&&(f|=2);let w=!p,A=!0,v=0,C=0;for(;v<c.length;v++){let k=Pa(c[v],r,!1,f);if(k instanceof r){if(!p){let T=!!(2&Re(k.u));w&&(w=!T),A&&(A=T)}c[C++]=k}}C<v&&(c.length=C),u|=4,u=A?16|u:-17&u,Be(c,u=w?8|u:-9&u),p&&Object.freeze(c)}if(a&&!(8&u||!i.length&&(s===1||s===4&&32&u))){for(Ft(u)&&(i=ct(i),u=rr(u,e),e=be(t,e,n,i)),r=i,a=u,c=0;c<r.length;c++)(u=r[c])!==(f=Ms(u))&&(r[c]=f);a|=8,a=r.length?-17&a:16|a,Be(r,a),u=a}let m;return s===1||s===4&&32&u?Ft(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)||Ft(u)||!!Yr?.get(i)),(s===2||l)&&Ft(u)&&(i=ct(i),u=gr(u=rr(u,e),e,o),Be(i,u),e=be(t,e,n,i)),Ft(u)||(n=u,(u=gr(u,e,o))!==n&&Be(i,u)),l?m=tl(i):s!==2||o||Yr?.delete(i)),m||i}function nr(t,e,r){let n=oe(t.u);return ll(t,n,e,r,Ir(),!1,!(2&n))}function $(t,e,r,n){return n==null&&(n=void 0),ce(t,r,n)}function Pn(t,e,r,n){n==null&&(n=void 0);e:{t=t.u;let s=oe(t);if(vr(s),n==null){let o=Va(t);if(Wa(o,t,s,r)!==e)break e;o.set(r,0)}else s=ul(t,s,r,e);be(t,s,e,n)}}function rr(t,e){return-2049&(t=32|(2&e?2|t:-3&t))}function gr(t,e,r){return 32&e&&r||(t&=-33),t}function Es(t,e,r,n){let s=oe(t.u);vr(s),t=ll(t,s,r,e,2,!0),n=n??new r,t.push(n),2&Re(n.u)?na(t,8):na(t,16)}function Bt(t,e){return t??e}function vt(t,e){return rn(xr(t,e))}function Ae(t,e){return Bt(ms(t,e),0)}function Xt(t,e){return Bt(mr(xr(t,e)),"")}function Gn(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}`);ce(t,e,r)}function jt(t,e,r){if(r!=null){if(typeof r!="number"||!Number.isFinite(r))throw ra("int32");r|=0}ce(t,e,r)}function G(t,e,r){if(r!=null&&typeof r!="number")throw Error(`Value of float/double field must be a number, found ${typeof r}: ${r}`);ce(t,e,r)}function As(t,e,r){{let a=t.u,i=oe(a);if(vr(i),r==null)be(a,i,e);else{r=rl?.get(r)||r;var n=t=Re(r),s=Ft(t),o=s||Object.isFrozen(r);for(s||(t=0),o||(r=ct(r),n=0,t=gr(t=rr(t,i),i,!0),o=!1),t|=21,s=0;s<r.length;s++){let u=r[s],l=el(u);Object.is(u,l)||(o&&(r=ct(r),n=0,t=gr(t=rr(t,i),i,!0),o=!1),r[s]=l)}t!==n&&(o&&(r=ct(r),t=gr(t=rr(t,i),i,!0)),Be(r,t)),be(a,i,e,r)}}}function Ns(t,e,r){vr(oe(t.u)),Sr(t,e,mr,2,!0).push(el(r))}function fl(t,e){return Error(`Invalid wire type: ${t} (at position ${e})`)}function za(){return Error("Failed to read varint, encoding is invalid.")}function hl(t,e){return Error(`Tried to read past the end of the data ${e} > ${t}`)}function Ha(t){if(typeof t=="string")return{buffer:Hc(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===tr)return{buffer:ka(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 Xa(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(Cr(t,i),r<128)return e(n>>>0,s>>>0);throw za()}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 Cr(t,r),!!(127&e)}throw za()}function yr(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 za();return Cr(t,r),s}function sr(t){return yr(t)>>>0}function ua(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],Cr(t,t.g+4),(n<<0|s<<8|o<<16|e<<24)>>>0}function ca(t){var e=ua(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 wd(t){return yr(t)}function Yo(t,e,{ca:r=!1}={}){t.ca=r,e&&(e=Ha(e),t.h=e.buffer,t.m=e.O,t.j=0,t.l=t.h.length,t.g=t.j)}function Cr(t,e){if(t.g=e,e>t.l)throw hl(t.l,e)}function dl(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 hl(e,t.l-r);return t.g=n,r}function ml(t,e){if(e==0)return Br();var r=dl(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):ld?t.slice(r,e):new Uint8Array(t.subarray(r,e))),r.length==0?Br():new tr(r,Xr)}wt.prototype.toJSON=void 0,wt.prototype.Ia=qc;var $u=[];function pl(t){var e=t.g;if(e.g==e.l)return!1;t.l=t.g.g;var r=sr(t.g);if(e=r>>>3,!((r&=7)>=0&&r<=5))throw fl(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 ps(t){switch(t.h){case 0:t.h!=0?ps(t):ja(t.g);break;case 1:Cr(t=t.g,t.g+8);break;case 2:if(t.h!=2)ps(t);else{var e=sr(t.g);Cr(t=t.g,t.g+e)}break;case 5:Cr(t=t.g,t.g+4);break;case 3:for(e=t.m;;){if(!pl(t))throw Error("Unmatched start-group tag: stream EOF");if(t.h==4){if(t.m!=e)throw Error("Unmatched end-group tag");break}ps(t)}break;default:throw fl(t.h,t.l)}}function Xn(t,e,r){let n=t.g.l,s=sr(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 Ya(t){var e=sr(t.g),r=dl(t=t.g,e);if(t=t.h,jh){var n,s=t;(n=Vo)||(n=Vo=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(is===void 0){try{n.decode(new Uint8Array([128]))}catch{}try{n.decode(new Uint8Array([97])),is=!0}catch{is=!1}}throw!is&&(Vo=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?Rr():(i=t[o++],a<194||(192&i)!=128?(o--,Rr()):r.push((31&a)<<6|63&i)):a<240?o>=e-1?Rr():(i=t[o++],(192&i)!=128||a===224&&i<160||a===237&&i>=160||(192&(n=t[o++]))!=128?(o--,Rr()):r.push((15&a)<<12|(63&i)<<6|63&n)):a<=244?o>=e-2?Rr():(i=t[o++],(192&i)!=128||i-144+(a<<28)>>30!=0||(192&(n=t[o++]))!=128||(192&(s=t[o++]))!=128?(o--,Rr()):(a=(7&a)<<18|(63&i)<<12|(63&n)<<6|63&s,a-=65536,r.push(55296+(a>>10&1023),56320+(1023&a)))):Rr(),r.length>=8192&&(u=Eu(u,r),r.length=0)}o=Eu(u,r)}return o}function gl(t){let e=sr(t.g);return ml(t.g,e)}function Gs(t,e,r){var n=sr(t.g);for(n=t.g.g+n;t.g.g<n;)r.push(e(t.g))}var ls=[],Rs;function Lt(t,e,r){e.g?e.m(t,e.g,e.h,r,!0):e.m(t,e.h,r,!0)}var M=class{constructor(t,e){this.u=sl(t,e)}toJSON(){return xl(this)}l(){var t=nm;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 Ma(this,t,oe(t),!1)}O(){return!!(2&Re(this.u))}};function xl(t){t=t.u,t=Rs?t:Ds(t,Da,void 0,void 0,!1);{var e=!Rs;let l=t.length;if(l){var r=t[l-1],n=Ra(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)||Fu(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)||Fu(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 zu(t){return t?/^\d+$/.test(t)?(Ps(t),new la(ie,Te)):null:Td||(Td=new la(0,0))}M.prototype.X=Hn,M.prototype.toString=function(){try{return Rs=!0,xl(this).toString()}finally{Rs=!1}};var la=class{constructor(t,e){this.h=t>>>0,this.g=e>>>0}},Td;function Hu(t){return t?/^-?\d+$/.test(t)?(Ps(t),new fa(ie,Te)):null:kd||(kd=new fa(0,0))}var fa=class{constructor(t,e){this.h=t>>>0,this.g=e>>>0}},kd;function $r(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 on(t,e){for(;e>127;)t.g.push(127&e|128),e>>>=7;t.g.push(e)}function Vs(t,e){if(e>=0)on(t,e);else{for(let r=0;r<9;r++)t.g.push(127&e|128),e>>=7;t.g.push(1)}}function Vn(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 qr(t,e){e.length!==0&&(t.l.push(e),t.h+=e.length)}function ft(t,e,r){on(t.g,8*e+r)}function qa(t,e){return ft(t,e,2),e=t.g.end(),qr(t,e),e.push(t.h),e}function Ka(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 Ws(t,e,r){ft(t,e,2),on(t.g,r.length),qr(t,t.g.end()),qr(t,r)}function Is(t,e,r,n){r!=null&&(e=qa(t,e),n(r,t),Ka(t,e))}function Pt(){let t=class{constructor(){throw Error()}};return Object.setPrototypeOf(t,t.prototype),t}var Za=Pt(),yl=Pt(),Ja=Pt(),Qa=Pt(),_l=Pt(),bl=Pt(),ei=Pt(),vl=Pt(),wl=Pt(),an=class{constructor(t,e,r){this.g=t,this.h=e,t=Za,this.l=!!t&&r===t||!1}};function $s(t,e){return new an(t,e,Za)}function Tl(t,e,r,n,s){Is(t,r,Rl(e,n),s)}var Ed=$s(function(t,e,r,n,s){return t.h===2&&(Xn(t,$a(e,n,r),s),!0)},Tl),Ad=$s(function(t,e,r,n,s){return t.h===2&&(Xn(t,$a(e,n,r,!0),s),!0)},Tl),zs=Symbol(),ti=Symbol(),Xu=Symbol(),ju=Symbol(),kl,El;function Ur(t,e,r,n){var s=n[t];if(s)return s;(s={}).W=function(f){switch(typeof f){case"boolean":return nl||(nl=[0,void 0,!0]);case"number":return f>0?void 0:f===0?md||(md=[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,kl??(kl=o),El??(El=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 an?f=o:(f=Ed,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 m=i[u];l?r(s,u,f,l,m):e(s,u,f,m)}}return n[t]=s}function Al(t){return Array.isArray(t)?t[0]instanceof an?t:[Ad,t]:[t,void 0]}function Rl(t,e){return t instanceof M?t.u:Array.isArray(t)?pr(t,e,!1):void 0}function ri(t,e,r,n){let s=r.g;t[e]=n?(o,a,i)=>s(o,a,i,n):s}function ni(t,e,r,n,s){let o=r.g,a,i;t[e]=(u,l,c)=>o(u,l,c,i||(i=Ur(ti,ri,ni,n).W),a||(a=si(n)),s)}function si(t){let e=t[Xu];if(e!=null)return e;let r=Ur(ti,ri,ni,t);return e=r.ma?(n,s)=>kl(n,s,r):(n,s)=>{let o=oe(n);for(;pl(s)&&s.h!=4;){var a=s.m,i=r[a];if(i==null){var u=r.ha;u&&(u=u[a])&&(u=Rd(u))!=null&&(i=r[a]=u)}i!=null&&i(s,n,a)||(a=(i=s).l,ps(i),i.ga?i=void 0:(u=i.g.g-a,i.g.g=a,i=ml(i.g,u)),a=n,i&&(dr||(dr=Symbol()),(u=a[dr])?u.push(i):a[dr]=[i]))}return 16384&o&&tn(n),!0},t[Xu]=e}function Rd(t){let e=(t=Al(t))[0].g;if(t=t[1]){let r=si(t),n=Ur(ti,ri,ni,t).W;return(s,o,a)=>e(s,o,a,n,r)}return e}function Hs(t,e,r){t[e]=r.h}function Xs(t,e,r,n){let s,o,a=r.h;t[e]=(i,u,l)=>a(i,u,l,o||(o=Ur(zs,Hs,Xs,n).W),s||(s=Il(n)))}function Il(t){let e=t[ju];if(!e){let r=Ur(zs,Hs,Xs,t);e=(n,s)=>Sl(n,s,r),t[ju]=e}return e}function Sl(t,e,r){for(var n=Re(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=Yu(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=Yu(r,s))&&i(e,o,s)}if(t=dr?t[dr]:void 0)for(qr(e,e.g.end()),r=0;r<t.length;r++)qr(e,ka(t[r])||new Uint8Array(0))}function Yu(t,e){var r=t[e];if(r)return r;if((r=t.ha)&&(r=r[e])){var n=(r=Al(r))[0].h;if(r=r[1]){let s=Il(r),o=Ur(zs,Hs,Xs,r).W;r=t.ma?El(o,s):(a,i,u)=>n(a,i,u,o,s)}else r=n;return t[e]=r}}function un(t,e){if(Array.isArray(e)){var r=Re(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 Ke(t,e,r){return new an(t,e,r)}function cn(t,e,r){return new an(t,e,r)}function Ze(t,e,r){be(t,oe(t),e,r)}var Id=$s(function(t,e,r,n,s){return t.h===2&&(t=Xn(t,pr([void 0,void 0],n,!0),s),vr(n=oe(e)),(s=or(e,n,r))instanceof wt?(2&s.M)!=0?((s=s.Y()).push(t),be(e,n,r,s)):s.Na(t):Array.isArray(s)?(2&Re(s)&&be(e,n,r,s=il(s)),s.push(t)):be(e,n,r,[t]),!0)},function(t,e,r,n,s){if(e instanceof wt)e.forEach((o,a)=>{Is(t,r,pr([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)&&Is(t,r,pr(a,n,!1),s)}});function Cl(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(Os(n)){if(s==="string")return La(n);if(s==="number")return Ua(n)}}(e),e!=null&&(typeof e=="string"&&Hu(e),e!=null))switch(ft(t,r,0),typeof e){case"number":t=t.g,jr(e),$r(t,ie,Te);break;case"bigint":r=BigInt.asUintN(64,e),r=new fa(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),$r(t.g,r.h,r.g);break;default:r=Hu(e),$r(t.g,r.h,r.g)}}function Fl(t,e,r){(e=rn(e))!=null&&e!=null&&(ft(t,r,0),Vs(t.g,e))}function Bl(t,e,r){(e=Jc(e))!=null&&(ft(t,r,0),t.g.g.push(e?1:0))}function Ul(t,e,r){(e=mr(e))!=null&&Ws(t,r,Gc(e))}function Ll(t,e,r,n,s){Is(t,r,Rl(e,n),s)}function Pl(t,e,r){(e=e==null||typeof e=="string"||$n(e)||e instanceof tr?e:void 0)!=null&&Ws(t,r,Ha(e).buffer)}function Ol(t,e,r){return(t.h===5||t.h===2)&&(e=sn(e,oe(e),r,!1,!1),t.h==2?Gs(t,ca,e):e.push(ca(t.g)),!0)}var Qt=Ke(function(t,e,r){if(t.h!==1)return!1;var n=t.g;t=ua(n);let s=ua(n);n=2*(s>>31)+1;let o=s>>>20&2047;return t=4294967296*(1048575&s)+t,Ze(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=wr(e))!=null&&(ft(t,r,1),t=t.g,(r=Zc||(Zc=new DataView(new ArrayBuffer(8)))).setFloat64(0,+e,!0),ie=r.getUint32(0,!0),Te=r.getUint32(4,!0),Vn(t,ie),Vn(t,Te))},Pt()),De=Ke(function(t,e,r){return t.h===5&&(Ze(e,r,ca(t.g)),!0)},function(t,e,r){(e=wr(e))!=null&&(ft(t,r,5),t=t.g,Sa(e),Vn(t,ie))},ei),Sd=cn(Ol,function(t,e,r){if((e=un(wr,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,Sa(o),Vn(n,ie))}},ei),oi=cn(Ol,function(t,e,r){if((e=un(wr,e))!=null&&e.length){ft(t,r,2),on(t.g,4*e.length);for(let n=0;n<e.length;n++)r=t.g,Sa(e[n]),Vn(r,ie)}},ei),_r=Ke(function(t,e,r){return t.h===0&&(Ze(e,r,Xa(t.g,Fa)),!0)},Cl,bl),qo=Ke(function(t,e,r){return t.h===0&&(Ze(e,r,(t=Xa(t.g,Fa))===0?void 0:t),!0)},Cl,bl),Cd=Ke(function(t,e,r){return t.h===0&&(Ze(e,r,Xa(t.g,Ca)),!0)},function(t,e,r){if((e=hd(e))!=null&&(typeof e=="string"&&zu(e),e!=null))switch(ft(t,r,0),typeof e){case"number":t=t.g,jr(e),$r(t,ie,Te);break;case"bigint":r=BigInt.asUintN(64,e),r=new la(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),$r(t.g,r.h,r.g);break;default:r=zu(e),$r(t.g,r.h,r.g)}},Pt()),ke=Ke(function(t,e,r){return t.h===0&&(Ze(e,r,yr(t.g)),!0)},Fl,Qa),js=cn(function(t,e,r){return(t.h===0||t.h===2)&&(e=sn(e,oe(e),r,!1,!1),t.h==2?Gs(t,yr,e):e.push(yr(t.g)),!0)},function(t,e,r){if((e=un(rn,e))!=null&&e.length){r=qa(t,r);for(let n=0;n<e.length;n++)Vs(t.g,e[n]);Ka(t,r)}},Qa),Wr=Ke(function(t,e,r){return t.h===0&&(Ze(e,r,(t=yr(t.g))===0?void 0:t),!0)},Fl,Qa),_e=Ke(function(t,e,r){return t.h===0&&(Ze(e,r,ja(t.g)),!0)},Bl,yl),zr=Ke(function(t,e,r){return t.h===0&&(Ze(e,r,(t=ja(t.g))===!1?void 0:t),!0)},Bl,yl),He=cn(function(t,e,r){return t.h===2&&(t=Ya(t),sn(e,oe(e),r,!1).push(t),!0)},function(t,e,r){if((e=un(mr,e))!=null)for(let a=0;a<e.length;a++){var n=t,s=r,o=e[a];o!=null&&Ws(n,s,Gc(o))}},Ja),hr=Ke(function(t,e,r){return t.h===2&&(Ze(e,r,(t=Ya(t))===""?void 0:t),!0)},Ul,Ja),ne=Ke(function(t,e,r){return t.h===2&&(Ze(e,r,Ya(t)),!0)},Ul,Ja),Oe=function(t,e,r=Za){return new an(t,e,r)}(function(t,e,r,n,s){return t.h===2&&(n=pr(void 0,n,!0),sn(e,oe(e),r,!0).push(n),Xn(t,n,s),!0)},function(t,e,r,n,s){if(Array.isArray(e))for(let o=0;o<e.length;o++)Ll(t,e[o],r,n,s)}),se=$s(function(t,e,r,n,s,o){return t.h===2&&(ul(e,Re(e),o,r),Xn(t,e=$a(e,n,r),s),!0)},Ll),Dl=Ke(function(t,e,r){return t.h===2&&(Ze(e,r,gl(t)),!0)},Pl,vl),Fd=cn(function(t,e,r){return(t.h===0||t.h===2)&&(e=sn(e,oe(e),r,!1,!1),t.h==2?Gs(t,sr,e):e.push(sr(t.g)),!0)},function(t,e,r){if((e=un(Qc,e))!=null)for(let a=0;a<e.length;a++){var n=t,s=r,o=e[a];o!=null&&(ft(n,s,0),on(n.g,o))}},_l),Bd=Ke(function(t,e,r){return t.h===0&&(Ze(e,r,(t=sr(t.g))===0?void 0:t),!0)},function(t,e,r){(e=Qc(e))!=null&&e!=null&&(ft(t,r,0),on(t.g,e))},_l),Ut=Ke(function(t,e,r){return t.h===0&&(Ze(e,r,yr(t.g)),!0)},function(t,e,r){(e=rn(e))!=null&&(e=parseInt(e,10),ft(t,r,0),Vs(t.g,e))},wl),ha=class{constructor(e,r){this.h=e,this.g=r,this.l=Y,this.m=$,this.defaultValue=void 0}};function Ot(t,e){return new ha(t,e)}function Tr(t,e){return(r,n)=>{if(ls.length){let o=ls.pop();o.o(n),Yo(o.g,r,n),r=o}else r=new class{constructor(o,a){if($u.length){let i=$u.pop();Yo(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,Yo(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;si(e)(a,r);var s=o}finally{r.g.clear(),r.m=-1,r.h=-1,ls.length<100&&ls.push(r)}return s}}function Ys(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}}}};Sl(this.u,e,Ur(zs,Hs,Xs,t)),qr(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 M{constructor(t){super(t)}},Ku=[0,hr,Ke(function(t,e,r){return t.h===2&&(Ze(e,r,(t=gl(t))===Br()?void 0:t),!0)},function(t,e,r){if(e!=null){if(e instanceof M){let n=e.Qa;return void(n&&(e=n(e),e!=null&&Ws(t,r,Ha(e).buffer)))}if(Array.isArray(e))return}Pl(t,e,r)},vl)],Ko,Zu=globalThis.trustedTypes;function Ju(t){Ko===void 0&&(Ko=function(){let r=null;if(!Zu)return r;try{let n=s=>s;r=Zu.createPolicy("goog#html",{createHTML:n,createScript:n,createScriptURL:n})}catch{}return r}());var e=Ko;return new class{constructor(r){this.g=r}toString(){return this.g+""}}(e?e.createScriptURL(t):t)}function Ud(t,...e){if(e.length===0)return Ju(t[0]);let r=t[0];for(let n=0;n<e.length;n++)r+=encodeURIComponent(e[n])+t[n+1];return Ju(r)}var Ml=[0,ke,Ut,_e,-1,js,Ut,-1],Ld=class extends M{constructor(){super()}},Nl=[0,_e,ne,_e,Ut,-1,cn(function(t,e,r){return(t.h===0||t.h===2)&&(e=sn(e,oe(e),r,!1,!1),t.h==2?Gs(t,wd,e):e.push(yr(t.g)),!0)},function(t,e,r){if((e=un(rn,e))!=null&&e.length){r=qa(t,r);for(let n=0;n<e.length;n++)Vs(t.g,e[n]);Ka(t,r)}},wl),ne,-1,[0,_e,-1],Ut,_e,-1],Gl=[0,ne,-2],Qu=class extends M{constructor(){super()}},Vl=[0],Wl=[0,ke,_e,1,_e,-3],lt=class extends M{constructor(t){super(t,2)}},Ue={};Ue[336783863]=[0,ne,_e,-1,ke,[0,[1,2,3,4,5,6,7],se,Vl,se,Nl,se,Gl,se,Wl,se,Ml,se,[0,ne,-2],se,[0,ne,Ut]],[0,ne],_e,[0,[1,3],[2,4],se,[0,js],-1,se,[0,He],-1,Oe,[0,ne,-1]],ne];var ec=[0,qo,-1,zr,-3,qo,js,hr,Wr,qo,-1,zr,Wr,zr,-2,hr];function ht(t,e){ia(t,2,nn(e),"")}function le(t,e){Ns(t,3,e)}function j(t,e){Ns(t,4,e)}var qe=class extends M{constructor(t){super(t,500)}o(t){return $(this,0,7,t)}},On=[-1,{}],tc=[0,ne,1,On],rc=[0,ne,He,On];function dt(t,e){Es(t,1,qe,e)}function ge(t,e){Ns(t,10,e)}function Z(t,e){Ns(t,15,e)}var nt=class extends M{constructor(t){super(t,500)}o(t){return $(this,0,1001,t)}},$l=[-500,Oe,[-500,hr,-1,He,-3,[-2,Ue,_e],Oe,Ku,Wr,-1,tc,rc,Oe,[0,hr,zr],hr,ec,Wr,He,987,He],4,Oe,[-500,ne,-1,[-1,{}],998,ne],Oe,[-500,ne,He,-1,[-2,{},_e],997,He,-1],Wr,Oe,[-500,ne,He,On,998,He],He,Wr,tc,rc,Oe,[0,hr,-1,On],He,-2,ec,hr,-1,zr,[0,zr,Bd],978,On,Oe,Ku];nt.prototype.g=Ys($l);var Pd=Tr(nt,$l),Od=class extends M{constructor(t){super(t)}},zl=class extends M{constructor(t){super(t)}g(){return nr(this,Od,1)}},Hl=[0,Oe,[0,ke,De,ne,-1]],qs=Tr(zl,Hl),Dd=class extends M{constructor(t){super(t)}},Md=class extends M{constructor(t){super(t)}},Zo=class extends M{constructor(t){super(t)}h(){return Y(this,Dd,2)}g(){return nr(this,Md,5)}},Xl=Tr(class extends M{constructor(t){super(t)}},[0,He,js,oi,[0,Ut,[0,ke,-3],[0,De,-3],[0,ke,-1,[0,Oe,[0,ke,-2]]],Oe,[0,De,-1,ne,De]],ne,-1,_r,Oe,[0,ke,De],He,_r]),jl=class extends M{constructor(t){super(t)}},Hr=Tr(class extends M{constructor(t){super(t)}},[0,Oe,[0,De,-4]]),Yl=class extends M{constructor(t){super(t)}},jn=Tr(class extends M{constructor(t){super(t)}},[0,Oe,[0,De,-4]]),Nd=class extends M{constructor(t){super(t)}},Gd=[0,ke,-1,oi,Ut],ql=class extends M{constructor(){super()}};ql.prototype.g=Ys([0,De,-4,_r]);var Vd=class extends M{constructor(t){super(t)}},Wd=Tr(class extends M{constructor(t){super(t)}},[0,Oe,[0,1,ke,ne,Hl],_r]),nc=class extends M{constructor(t){super(t)}},$d=class extends M{constructor(t){super(t)}pa(){let t=al(this);return t??Br()}},zd=class extends M{constructor(t){super(t)}},Kl=[1,2],Hd=Tr(class extends M{constructor(t){super(t)}},[0,Oe,[0,Kl,se,[0,oi],se,[0,Dl],ke,ne],_r]),ai=class extends M{constructor(t){super(t)}},Zl=[0,ne,ke,De,He,-1],sc=class extends M{constructor(t){super(t)}},Xd=[0,_e,-1],oc=class extends M{constructor(t){super(t)}},gs=[1,2,3,4,5],Ss=class extends M{constructor(t){super(t)}g(){return al(this)!=null}h(){return mr(xr(this,2))!=null}},ye=class extends M{constructor(t){super(t)}g(){return Jc(xr(this,2))??!1}},Jl=[0,Dl,ne,[0,ke,_r,-1],[0,Cd,_r]],Ie=[0,Jl,_e,[0,gs,se,Wl,se,Nl,se,Ml,se,Vl,se,Gl],Ut],Ks=class extends M{constructor(t){super(t)}},ii=[0,Ie,De,-1,ke],jd=Ot(502141897,Ks);Ue[502141897]=ii;var Yd=Tr(class extends M{constructor(t){super(t)}},[0,[0,Ut,-1,Sd,Fd],Gd]),Ql=class extends M{constructor(t){super(t)}},ef=class extends M{constructor(t){super(t)}},ui=[0,Ie,De,[0,Ie],_e],tf=[0,Ie,ii,ui,De,[0,[0,Jl]]],qd=Ot(508968150,ef);Ue[508968150]=tf,Ue[508968149]=ui;var rf=class extends M{constructor(t){super(t)}},Kd=Ot(513916220,rf);Ue[513916220]=[0,Ie,tf,ke];var Gr=class extends M{constructor(t){super(t)}h(){return Y(this,ai,2)}g(){ce(this,2)}},nf=[0,Ie,Zl];Ue[478825465]=nf;var Zd=class extends M{constructor(t){super(t)}},sf=class extends M{constructor(t){super(t)}},ci=class extends M{constructor(t){super(t)}},li=class extends M{constructor(t){super(t)}},of=class extends M{constructor(t){super(t)}},ac=[0,Ie,[0,Ie],nf,-1],af=[0,Ie,De,ke],fi=[0,Ie,De],uf=[0,Ie,af,fi,De],Jd=Ot(479097054,of);Ue[479097054]=[0,Ie,uf,ac],Ue[463370452]=ac,Ue[464864288]=af;var Qd=Ot(462713202,li);Ue[462713202]=uf,Ue[474472470]=fi;var em=class extends M{constructor(t){super(t)}},cf=class extends M{constructor(t){super(t)}},lf=class extends M{constructor(t){super(t)}},ff=class extends M{constructor(){super()}},hi=[0,Ie,De,-1,ke],da=[0,Ie,De,_e];ff.prototype.g=Ys([0,Ie,fi,[0,Ie],ii,ui,hi,da]);var hf=class extends M{constructor(t){super(t)}},tm=Ot(456383383,hf);Ue[456383383]=[0,Ie,Zl];var df=class extends M{constructor(t){super(t)}},rm=Ot(476348187,df);Ue[476348187]=[0,Ie,Xd];var mf=class extends M{constructor(t){super(t)}},ic=class extends M{constructor(t){super(t)}},pf=[0,Ut,-1],nm=Ot(458105876,class extends M{constructor(t){super(t)}g(){var t=this.u;let e=oe(t),r=2&e;return t=function(n,s,o){var a=ic;let i=2&s,u=!1;if(o==null){if(i)return Vu();o=[]}else if(o.constructor===wt){if((2&o.M)==0||i)return o;o=o.Y()}else Array.isArray(o)?u=!!(2&Re(o)):o=[];if(i){if(!o.length)return Vu();u||(u=!0,tn(o))}else u&&(u=!1,o=il(o));return u||(64&Re(o)?na(o,32):32&s&&Bs(o,32)),be(n,s,2,a=new wt(o,a,dd,void 0)),a}(t,e,or(t,e,2)),!r&&ic&&(t.sa=!0),t}});Ue[458105876]=[0,pf,Id,[!0,_r,[0,ne,-1,He]]];var di=class extends M{constructor(t){super(t)}},gf=Ot(458105758,di);Ue[458105758]=[0,Ie,ne,pf];var xf=class extends M{constructor(t){super(t)}},sm=Ot(443442058,xf);Ue[443442058]=[0,Ie,ne,ke,De,He,-1],Ue[514774813]=hi;var yf=class extends M{constructor(t){super(t)}},om=Ot(516587230,yf);function ma(t,e){return e=e?e.clone():new ai,t.displayNamesLocale!==void 0?ce(e,1,nn(t.displayNamesLocale)):t.displayNamesLocale===void 0&&ce(e,1),t.maxResults!==void 0?jt(e,2,t.maxResults):"maxResults"in t&&ce(e,2),t.scoreThreshold!==void 0?G(e,3,t.scoreThreshold):"scoreThreshold"in t&&ce(e,3),t.categoryAllowlist!==void 0?As(e,4,t.categoryAllowlist):"categoryAllowlist"in t&&ce(e,4),t.categoryDenylist!==void 0?As(e,5,t.categoryDenylist):"categoryDenylist"in t&&ce(e,5),e}function mi(t,e=-1,r=""){return{categories:t.map(n=>({index:Bt(vt(n,1),0)??-1,score:Ae(n,2)??0,categoryName:Xt(n,3)??"",displayName:Xt(n,4)??""})),headIndex:e,headName:r}}function _f(t){var e=Sr(t,3,wr,Ir()),r=Sr(t,2,rn,Ir()),n=Sr(t,1,mr,Ir()),s=Sr(t,9,mr,Ir());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=Y(t,Zo,4)?.h())&&(o.boundingBox={originX:vt(e,1)??0,originY:vt(e,2)??0,width:vt(e,3)??0,height:vt(e,4)??0,angle:0}),Y(t,Zo,4)?.g().length)for(let a of Y(t,Zo,4).g())o.keypoints.push({x:ms(a,1)??0,y:ms(a,2)??0,score:ms(a,4)??0,label:mr(xr(a,3))??""});return o}function Zs(t){let e=[];for(let r of nr(t,Yl,1))e.push({x:Ae(r,1)??0,y:Ae(r,2)??0,z:Ae(r,3)??0,visibility:Ae(r,4)??0});return e}function Dn(t){let e=[];for(let r of nr(t,jl,1))e.push({x:Ae(r,1)??0,y:Ae(r,2)??0,z:Ae(r,3)??0,visibility:Ae(r,4)??0});return e}function uc(t){return Array.from(t,e=>e>127?e-256:e)}function cc(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 fs;Ue[516587230]=[0,Ie,hi,da,De],Ue[518928384]=da;var am=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 bf(){if(fs===void 0)try{await WebAssembly.instantiate(am),fs=!0}catch{fs=!1}return fs}async function Cn(t,e=Ud``){let r=await bf()?"wasm_internal":"wasm_nosimd_internal";return{wasmLoaderPath:`${e}/${t}_${r}.js`,wasmBinaryPath:`${e}/${t}_${r}.wasm`}}var lr=class{};function vf(){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 lc(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 wf(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 W(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 fc(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]=wf(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 hc(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 Wt(t,e,r){t.i.simpleListeners=t.i.simpleListeners||{},t.i.simpleListeners[e]=r}function cr(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)}}lr.forVisionTasks=function(t){return Cn("vision",t)},lr.forTextTasks=function(t){return Cn("text",t)},lr.forGenAiExperimentalTasks=function(t){return Cn("genai_experimental",t)},lr.forGenAiTasks=function(t){return Cn("genai",t)},lr.forAudioTasks=function(t){return Cn("audio",t)},lr.isSimdSupported=function(){return bf()};async function im(t,e,r,n){return t=await(async(s,o,a,i,u)=>{if(o&&await lc(o),!self.ModuleFactory||a&&(await lc(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 Jo(t,e){let r=Y(t.baseOptions,Ss,1)||new Ss;typeof e=="string"?(ce(r,2,nn(e)),ce(r,1)):e instanceof Uint8Array&&(ce(r,1,Ia(e,!1)),ce(r,2)),$(t.baseOptions,0,1,r)}function dc(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 D(t,e){t.B=Math.max(t.B,e)}function Js(t,e){t.A=new qe,ht(t.A,"PassThroughCalculator"),le(t.A,"free_memory"),j(t.A,"free_memory_unused_out"),ge(e,"free_memory"),dt(e,t.A)}function Kr(t,e){le(t.A,e),j(t.A,e+"_unused_out")}function Qs(t){t.g.addBoolToStream(!0,"free_memory",t.B)}var xs=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(!(Y(this.baseOptions,Ss,1)?.g()||Y(this.baseOptions,Ss,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=Y(n.baseOptions,oc,3);if(!o){var a=o=new oc,i=new Qu;Pn(a,4,gs,i)}"delegate"in s&&(s.delegate==="GPU"?(s=o,a=new Ld,Pn(s,2,gs,a)):(s=o,a=new Qu,Pn(s,4,gs,a))),$(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),Jo(this,"/model.dat"),this.m(),this.J()});if(r.modelAssetBuffer instanceof Uint8Array)Jo(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=>{Jo(this,n),this.m(),this.J()})}return this.m(),this.J(),Promise.resolve()}J(){}ea(){let t;if(this.g.ea(e=>{t=Pd(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,dc(this)}finishProcessing(){this.g.finishProcessing(),dc(this)}close(){this.A=void 0,this.g.closeGraph()}};function Ye(t,e){if(!t)throw Error(`Unable to obtain required WebGL resource: ${e}`);return t}xs.prototype.close=xs.prototype.close,Nc("TaskRunner",xs);var pa=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 mc(t,e,r){let n=t.g;if(r=Ye(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 pc(t,e){let r=t.g,n=Ye(r.createVertexArray(),"Failed to create vertex array");r.bindVertexArray(n);let s=Ye(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=Ye(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 pa(r,n,s,o)}function pi(t,e){if(t.g){if(e!==t.g)throw Error("Cannot change GL context once initialized")}else t.g=e}function Yn(t,e,r,n){return pi(t,e),t.h||(t.m(),t.C()),r?(t.s||(t.s=pc(t,!0)),r=t.s):(t.v||(t.v=pc(t,!1)),r=t.v),e.useProgram(t.h),r.bind(),t.l(),t=n(),r.g.bindVertexArray(null),t}function br(t,e,r){return pi(t,e),t=Ye(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 eo(t,e,r){pi(t,e),t.A||(t.A=Ye(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 gi(t){t.g?.bindFramebuffer(t.g.FRAMEBUFFER,null)}var ln=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
|
|
8
|
+
`}m(){let t=this.g;if(this.h=Ye(t.createProgram(),"Failed to create WebGL program"),this.ba=mc(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
|
-
}`,
|
|
15
|
+
}`,t.VERTEX_SHADER),this.aa=mc(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()}},um=class extends ln{H(){return`
|
|
16
16
|
precision mediump float;
|
|
17
17
|
uniform sampler2D backgroundTexture;
|
|
18
18
|
uniform sampler2D maskTexture;
|
|
@@ -24,7 +24,7 @@ var It=typeof self<"u"?self:{};function za(e,t){e=e.split(".");var r,n=It;for((e
|
|
|
24
24
|
vec4 categoryColor = texture2D(colorMappingTexture, vec2(category, 0.0));
|
|
25
25
|
gl_FragColor = mix(backgroundColor, categoryColor, categoryColor.a);
|
|
26
26
|
}
|
|
27
|
-
`}C(){let
|
|
27
|
+
`}C(){let t=this.g;t.activeTexture(t.TEXTURE1),this.B=br(this,t,t.LINEAR),t.activeTexture(t.TEXTURE2),this.j=br(this,t,t.NEAREST)}m(){super.m();let t=this.g;this.L=Ye(t.getUniformLocation(this.h,"backgroundTexture"),"Uniform location"),this.U=Ye(t.getUniformLocation(this.h,"colorMappingTexture"),"Uniform location"),this.K=Ye(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()}},cm=class extends ln{H(){return`
|
|
28
28
|
precision mediump float;
|
|
29
29
|
uniform sampler2D maskTexture;
|
|
30
30
|
uniform sampler2D defaultTexture;
|
|
@@ -38,165 +38,38 @@ var It=typeof self<"u"?self:{};function za(e,t){e=e.split(".");var r,n=It;for((e
|
|
|
38
38
|
overlayColor = mix(defaultColor, overlayColor, overlayColor.a);
|
|
39
39
|
gl_FragColor = mix(defaultColor, overlayColor, confidence);
|
|
40
40
|
}
|
|
41
|
-
`}C(){let e=this.g;e.activeTexture(e.TEXTURE1),this.j=Tt(this,e),e.activeTexture(e.TEXTURE2),this.B=Tt(this,e)}m(){super.m();let e=this.g;this.K=ge(e.getUniformLocation(this.h,"defaultTexture"),"Uniform location"),this.L=ge(e.getUniformLocation(this.h,"overlayTexture"),"Uniform location"),this.I=ge(e.getUniformLocation(this.h,"maskTexture"),"Uniform location")}l(){super.l();let e=this.g;e.uniform1i(this.I,0),e.uniform1i(this.K,1),e.uniform1i(this.L,2)}close(){this.j&&this.g.deleteTexture(this.j),this.B&&this.g.deleteTexture(this.B),super.close()}};function st(e,t){switch(t){case 0:return e.g.find(r=>r instanceof Uint8Array);case 1:return e.g.find(r=>r instanceof Float32Array);case 2:return e.g.find(r=>typeof WebGLTexture<"u"&&r instanceof WebGLTexture);default:throw Error(`Type is not supported: ${t}`)}}function ho(e){var t=st(e,1);if(!t){if(t=st(e,0))t=new Float32Array(t).map(n=>n/255);else{t=new Float32Array(e.width*e.height);let n=Ht(e);var r=ds(e);if(Rn(r,n,Lc(e)),"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(e.width*e.height*4),n.readPixels(0,0,e.width,e.height,n.RGBA,n.FLOAT,r);for(let o=0,s=0;o<t.length;++o,s+=4)t[o]=r[s]}else n.readPixels(0,0,e.width,e.height,n.RED,n.FLOAT,t)}e.g.push(t)}return t}function Lc(e){let t=st(e,2);if(!t){let r=Ht(e);t=Mc(e);let n=ho(e),o=Ic(e);r.texImage2D(r.TEXTURE_2D,0,o,e.width,e.height,0,r.RED,r.FLOAT,n),lo(e)}return t}function Ht(e){if(!e.canvas)throw Error("Conversion to different image formats require that a canvas is passed when initializing the image.");return e.h||(e.h=ge(e.canvas.getContext("webgl2"),"You cannot use a canvas that is already bound to a different type of rendering context.")),e.h}function Ic(e){if(e=Ht(e),!Pr)if(e.getExtension("EXT_color_buffer_float")&&e.getExtension("OES_texture_float_linear")&&e.getExtension("EXT_float_blend"))Pr=e.R32F;else{if(!e.getExtension("EXT_color_buffer_half_float"))throw Error("GPU does not fully support 4-channel float32 or float16 formats");Pr=e.R16F}return Pr}function ds(e){return e.l||(e.l=new nr),e.l}function Mc(e){let t=Ht(e);t.viewport(0,0,e.width,e.height),t.activeTexture(t.TEXTURE0);let r=st(e,2);return r||(r=Tt(ds(e),t,e.m?t.LINEAR:t.NEAREST),e.g.push(r),e.j=!0),t.bindTexture(t.TEXTURE_2D,r),r}function lo(e){e.h.bindTexture(e.h.TEXTURE_2D,null)}var Pr,ae=class{constructor(e,t,r,n,o,s,a){this.g=e,this.m=t,this.j=r,this.canvas=n,this.l=o,this.width=s,this.height=a,this.j&&--Aa===0&&console.error("You seem to be creating MPMask instances without invoking .close(). This leaks resources.")}Ga(){return!!st(this,0)}ka(){return!!st(this,1)}R(){return!!st(this,2)}ja(){return(t=st(e=this,0))||(t=ho(e),t=new Uint8Array(t.map(r=>255*r)),e.g.push(t)),t;var e,t}ia(){return ho(this)}N(){return Lc(this)}clone(){let e=[];for(let t of this.g){let r;if(t instanceof Uint8Array)r=new Uint8Array(t);else if(t instanceof Float32Array)r=new Float32Array(t);else{if(!(t instanceof WebGLTexture))throw Error(`Type is not supported: ${t}`);{let n=Ht(this),o=ds(this);n.activeTexture(n.TEXTURE1),r=Tt(o,n,this.m?n.LINEAR:n.NEAREST),n.bindTexture(n.TEXTURE_2D,r);let s=Ic(this);n.texImage2D(n.TEXTURE_2D,0,s,this.width,this.height,0,n.RED,n.FLOAT,null),n.bindTexture(n.TEXTURE_2D,null),Rn(o,n,r),Sr(o,n,!1,()=>{Mc(this),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.drawArrays(n.TRIANGLE_FAN,0,4),lo(this)}),ls(o),lo(this)}}e.push(r)}return new ae(e,this.m,this.R(),this.canvas,this.l,this.width,this.height)}close(){this.j&&Ht(this).deleteTexture(st(this,2)),Aa=-1}};ae.prototype.close=ae.prototype.close,ae.prototype.clone=ae.prototype.clone,ae.prototype.getAsWebGLTexture=ae.prototype.N,ae.prototype.getAsFloat32Array=ae.prototype.ia,ae.prototype.getAsUint8Array=ae.prototype.ja,ae.prototype.hasWebGLTexture=ae.prototype.R,ae.prototype.hasFloat32Array=ae.prototype.ka,ae.prototype.hasUint8Array=ae.prototype.Ga;var Aa=250,U2={color:"white",lineWidth:4,radius:6};function zn(e){return{...U2,fillColor:(e=e||{}).color,...e}}function nt(e,t){return e instanceof Function?e(t):e}function Ra(e,t,r){return Math.max(Math.min(t,r),Math.min(Math.max(t,r),e))}function lr(e){if(!e.l)throw Error("CPU rendering requested but CanvasRenderingContext2D not provided.");return e.l}function Tr(e){if(!e.j)throw Error("GPU rendering requested but WebGL2RenderingContext not provided.");return e.j}function wa(e,t,r){if(t.R())r(t.N());else{let n=t.ka()?t.ia():t.ja();e.m=e.m??new nr;let o=Tr(e);r((e=new ae([n],t.m,!1,o.canvas,e.m,t.width,t.height)).N()),e.close()}}function ka(e,t,r,n){let o=function(i){return i.g||(i.g=new M2),i.g}(e),s=Tr(e),a=Array.isArray(r)?new ImageData(new Uint8ClampedArray(r),1,1):r;Sr(o,s,!0,()=>{(function(c,l,h,p){let d=c.g;if(d.activeTexture(d.TEXTURE0),d.bindTexture(d.TEXTURE_2D,l),d.activeTexture(d.TEXTURE1),d.bindTexture(d.TEXTURE_2D,c.B),d.texImage2D(d.TEXTURE_2D,0,d.RGBA,d.RGBA,d.UNSIGNED_BYTE,h),c.I&&function(g,A){if(g!==A)return!1;g=g.entries(),A=A.entries();for(let[S,w]of g){g=S;let f=w;var R=A.next();if(R.done)return!1;let[y,b]=R.value;if(R=b,g!==y||f[0]!==R[0]||f[1]!==R[1]||f[2]!==R[2]||f[3]!==R[3])return!1}return!!A.next().done}(c.I,p))d.activeTexture(d.TEXTURE2),d.bindTexture(d.TEXTURE_2D,c.j);else{c.I=p;let g=Array(1024).fill(0);p.forEach((A,R)=>{if(A.length!==4)throw Error(`Color at index ${R} is not a four-channel value.`);g[4*R]=A[0],g[4*R+1]=A[1],g[4*R+2]=A[2],g[4*R+3]=A[3]}),d.activeTexture(d.TEXTURE2),d.bindTexture(d.TEXTURE_2D,c.j),d.texImage2D(d.TEXTURE_2D,0,d.RGBA,256,1,0,d.RGBA,d.UNSIGNED_BYTE,new Uint8Array(g))}})(o,t,a,n),s.clearColor(0,0,0,0),s.clear(s.COLOR_BUFFER_BIT),s.drawArrays(s.TRIANGLE_FAN,0,4);let i=o.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 Sa(e,t,r,n){let o=Tr(e),s=function(c){return c.h||(c.h=new F2),c.h}(e),a=Array.isArray(r)?new ImageData(new Uint8ClampedArray(r),1,1):r,i=Array.isArray(n)?new ImageData(new Uint8ClampedArray(n),1,1):n;Sr(s,o,!0,()=>{var c=s.g;c.activeTexture(c.TEXTURE0),c.bindTexture(c.TEXTURE_2D,t),c.activeTexture(c.TEXTURE1),c.bindTexture(c.TEXTURE_2D,s.j),c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,a),c.activeTexture(c.TEXTURE2),c.bindTexture(c.TEXTURE_2D,s.B),c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,i),o.clearColor(0,0,0,0),o.clear(o.COLOR_BUFFER_BIT),o.drawArrays(o.TRIANGLE_FAN,0,4),o.bindTexture(o.TEXTURE_2D,null),(c=s.g).activeTexture(c.TEXTURE0),c.bindTexture(c.TEXTURE_2D,null),c.activeTexture(c.TEXTURE1),c.bindTexture(c.TEXTURE_2D,null),c.activeTexture(c.TEXTURE2),c.bindTexture(c.TEXTURE_2D,null)})}var me=class{constructor(e,t){e instanceof CanvasRenderingContext2D||e instanceof OffscreenCanvasRenderingContext2D?(this.l=e,this.j=t):this.j=e}za(e,t){if(e){var r=lr(this);t=zn(t),r.save();var n=r.canvas,o=0;for(let s of e)r.fillStyle=nt(t.fillColor,{index:o,from:s}),r.strokeStyle=nt(t.color,{index:o,from:s}),r.lineWidth=nt(t.lineWidth,{index:o,from:s}),(e=new Path2D).arc(s.x*n.width,s.y*n.height,nt(t.radius,{index:o,from:s}),0,2*Math.PI),r.fill(e),r.stroke(e),++o;r.restore()}}ya(e,t,r){if(e&&t){var n=lr(this);r=zn(r),n.save();var o=n.canvas,s=0;for(let a of t){n.beginPath(),t=e[a.start];let i=e[a.end];t&&i&&(n.strokeStyle=nt(r.color,{index:s,from:t,to:i}),n.lineWidth=nt(r.lineWidth,{index:s,from:t,to:i}),n.moveTo(t.x*o.width,t.y*o.height),n.lineTo(i.x*o.width,i.y*o.height)),++s,n.stroke()}n.restore()}}va(e,t){let r=lr(this);t=zn(t),r.save(),r.beginPath(),r.lineWidth=nt(t.lineWidth,{}),r.strokeStyle=nt(t.color,{}),r.fillStyle=nt(t.fillColor,{}),r.moveTo(e.originX,e.originY),r.lineTo(e.originX+e.width,e.originY),r.lineTo(e.originX+e.width,e.originY+e.height),r.lineTo(e.originX,e.originY+e.height),r.lineTo(e.originX,e.originY),r.stroke(),r.fill(),r.restore()}wa(e,t,r=[0,0,0,255]){this.l?function(n,o,s,a){let i=Tr(n);wa(n,o,c=>{ka(n,c,s,a),(c=lr(n)).drawImage(i.canvas,0,0,c.canvas.width,c.canvas.height)})}(this,e,r,t):ka(this,e.N(),r,t)}xa(e,t,r){this.l?function(n,o,s,a){let i=Tr(n);wa(n,o,c=>{Sa(n,c,s,a),(c=lr(n)).drawImage(i.canvas,0,0,c.canvas.width,c.canvas.height)})}(this,e,t,r):Sa(this,e.N(),t,r)}close(){this.g?.close(),this.g=void 0,this.h?.close(),this.h=void 0,this.m?.close(),this.m=void 0}};function Ze(e,t){switch(t){case 0:return e.g.find(r=>r instanceof ImageData);case 1:return e.g.find(r=>typeof ImageBitmap<"u"&&r instanceof ImageBitmap);case 2:return e.g.find(r=>typeof WebGLTexture<"u"&&r instanceof WebGLTexture);default:throw Error(`Type is not supported: ${t}`)}}function Fc(e){var t=Ze(e,0);if(!t){t=Yt(e);let r=wn(e),n=new Uint8Array(e.width*e.height*4);Rn(r,t,jr(e)),t.readPixels(0,0,e.width,e.height,t.RGBA,t.UNSIGNED_BYTE,n),ls(r),t=new ImageData(new Uint8ClampedArray(n.buffer),e.width,e.height),e.g.push(t)}return t}function jr(e){let t=Ze(e,2);if(!t){let r=Yt(e);t=Wr(e);let n=Ze(e,1)||Fc(e);r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,n),fr(e)}return t}function Yt(e){if(!e.canvas)throw Error("Conversion to different image formats require that a canvas is passed when iniitializing the image.");return e.h||(e.h=ge(e.canvas.getContext("webgl2"),"You cannot use a canvas that is already bound to a different type of rendering context.")),e.h}function wn(e){return e.l||(e.l=new nr),e.l}function Wr(e){let t=Yt(e);t.viewport(0,0,e.width,e.height),t.activeTexture(t.TEXTURE0);let r=Ze(e,2);return r||(r=Tt(wn(e),t),e.g.push(r),e.m=!0),t.bindTexture(t.TEXTURE_2D,r),r}function fr(e){e.h.bindTexture(e.h.TEXTURE_2D,null)}function Ca(e){let t=Yt(e);return Sr(wn(e),t,!0,()=>function(r,n){let o=r.canvas;if(o.width===r.width&&o.height===r.height)return n();let s=o.width,a=o.height;return o.width=r.width,o.height=r.height,r=n(),o.width=s,o.height=a,r}(e,()=>{if(t.bindFramebuffer(t.FRAMEBUFFER,null),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.drawArrays(t.TRIANGLE_FAN,0,4),!(e.canvas instanceof OffscreenCanvas))throw Error("Conversion to ImageBitmap requires that the MediaPipe Tasks is initialized with an OffscreenCanvas");return e.canvas.transferToImageBitmap()}))}me.prototype.close=me.prototype.close,me.prototype.drawConfidenceMask=me.prototype.xa,me.prototype.drawCategoryMask=me.prototype.wa,me.prototype.drawBoundingBox=me.prototype.va,me.prototype.drawConnectors=me.prototype.ya,me.prototype.drawLandmarks=me.prototype.za,me.lerp=function(e,t,r,n,o){return Ra(n*(1-(e-t)/(r-t))+o*(1-(r-e)/(r-t)),n,o)},me.clamp=Ra,za("DrawingUtils",me);var he=class{constructor(e,t,r,n,o,s,a){this.g=e,this.j=t,this.m=r,this.canvas=n,this.l=o,this.width=s,this.height=a,(this.j||this.m)&&--La===0&&console.error("You seem to be creating MPImage instances without invoking .close(). This leaks resources.")}Fa(){return!!Ze(this,0)}la(){return!!Ze(this,1)}R(){return!!Ze(this,2)}Da(){return Fc(this)}Ca(){var e=Ze(this,1);return e||(jr(this),Wr(this),e=Ca(this),fr(this),this.g.push(e),this.j=!0),e}N(){return jr(this)}clone(){let e=[];for(let t of this.g){let r;if(t instanceof ImageData)r=new ImageData(t.data,this.width,this.height);else if(t instanceof WebGLTexture){let n=Yt(this),o=wn(this);n.activeTexture(n.TEXTURE1),r=Tt(o,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),Rn(o,n,r),Sr(o,n,!1,()=>{Wr(this),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.drawArrays(n.TRIANGLE_FAN,0,4),fr(this)}),ls(o),fr(this)}else{if(!(t instanceof ImageBitmap))throw Error(`Type is not supported: ${t}`);jr(this),Wr(this),r=Ca(this),fr(this)}e.push(r)}return new he(e,this.la(),this.R(),this.canvas,this.l,this.width,this.height)}close(){this.j&&Ze(this,1).close(),this.m&&Yt(this).deleteTexture(Ze(this,2)),La=-1}};he.prototype.close=he.prototype.close,he.prototype.clone=he.prototype.clone,he.prototype.getAsWebGLTexture=he.prototype.N,he.prototype.getAsImageBitmap=he.prototype.Ca,he.prototype.getAsImageData=he.prototype.Da,he.prototype.hasWebGLTexture=he.prototype.R,he.prototype.hasImageBitmap=he.prototype.la,he.prototype.hasImageData=he.prototype.Fa;var La=250;function ze(...e){return e.map(([t,r])=>({start:t,end:r}))}var O2=function(e){return class extends e{La(){this.i._registerModelResourcesGraphService()}}}((Ia=class{constructor(e,t){this.l=!0,this.i=e,this.g=null,this.h=0,this.m=typeof this.i._addIntToInputStream=="function",t!==void 0?this.i.canvas=t:Sc()?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(e){let t=await(await fetch(e)).arrayBuffer();e=!(e.endsWith(".pbtxt")||e.endsWith(".textproto")),this.setGraph(new Uint8Array(t),e)}setGraphFromString(e){this.setGraph(new TextEncoder().encode(e),!1)}setGraph(e,t){let r=e.length,n=this.i._malloc(r);this.i.HEAPU8.set(e,n),t?this.i._changeBinaryGraph(r,n):this.i._changeTextGraph(r,n),this.i._free(n)}configureAudio(e,t,r,n,o){this.i._configureAudio||console.warn('Attempting to use configureAudio without support for input audio. Is build dep ":gl_graph_runner_audio" missing?'),E(this,n||"input_audio",s=>{E(this,o=o||"audio_header",a=>{this.i._configureAudio(s,a,e,t??0,r)})})}setAutoResizeCanvas(e){this.l=e}setAutoRenderToScreen(e){this.i._setAutoRenderToScreen(e)}setGpuBufferVerticalFlip(e){this.i.gpuOriginForWebTexturesIsBottomLeft=e}ea(e){qe(this,"__graph_config__",t=>{e(t)}),E(this,"__graph_config__",t=>{this.i._getGraphConfig(t,void 0)}),delete this.i.simpleListeners.__graph_config__}attachErrorListener(e){this.i.errorListener=e}attachEmptyPacketListener(e,t){this.i.emptyPacketListeners=this.i.emptyPacketListeners||{},this.i.emptyPacketListeners[e]=t}addAudioToStream(e,t,r){this.addAudioToStreamWithShape(e,0,0,t,r)}addAudioToStreamWithShape(e,t,r,n,o){let s=4*e.length;this.h!==s&&(this.g&&this.i._free(this.g),this.g=this.i._malloc(s),this.h=s),this.i.HEAPF32.set(e,this.g/4),E(this,n,a=>{this.i._addAudioToInputStream(this.g,t,r,a,o)})}addGpuBufferToStream(e,t,r){E(this,t,n=>{let[o,s]=va(this,e,n);this.i._addBoundTextureToStream(n,o,s,r)})}addBoolToStream(e,t,r){E(this,t,n=>{this.i._addBoolToInputStream(e,n,r)})}addDoubleToStream(e,t,r){E(this,t,n=>{this.i._addDoubleToInputStream(e,n,r)})}addFloatToStream(e,t,r){E(this,t,n=>{this.i._addFloatToInputStream(e,n,r)})}addIntToStream(e,t,r){E(this,t,n=>{this.i._addIntToInputStream(e,n,r)})}addUintToStream(e,t,r){E(this,t,n=>{this.i._addUintToInputStream(e,n,r)})}addStringToStream(e,t,r){E(this,t,n=>{E(this,e,o=>{this.i._addStringToInputStream(o,n,r)})})}addStringRecordToStream(e,t,r){E(this,t,n=>{Ea(this,Object.keys(e),o=>{Ea(this,Object.values(e),s=>{this.i._addFlatHashMapToInputStream(o,s,Object.keys(e).length,n,r)})})})}addProtoToStream(e,t,r,n){E(this,r,o=>{E(this,t,s=>{let a=this.i._malloc(e.length);this.i.HEAPU8.set(e,a),this.i._addProtoToInputStream(a,e.length,s,o,n),this.i._free(a)})})}addEmptyPacketToStream(e,t){E(this,e,r=>{this.i._addEmptyPacketToInputStream(r,t)})}addBoolVectorToStream(e,t,r){E(this,t,n=>{let o=this.i._allocateBoolVector(e.length);if(!o)throw Error("Unable to allocate new bool vector on heap.");for(let s of e)this.i._addBoolVectorEntry(o,s);this.i._addBoolVectorToInputStream(o,n,r)})}addDoubleVectorToStream(e,t,r){E(this,t,n=>{let o=this.i._allocateDoubleVector(e.length);if(!o)throw Error("Unable to allocate new double vector on heap.");for(let s of e)this.i._addDoubleVectorEntry(o,s);this.i._addDoubleVectorToInputStream(o,n,r)})}addFloatVectorToStream(e,t,r){E(this,t,n=>{let o=this.i._allocateFloatVector(e.length);if(!o)throw Error("Unable to allocate new float vector on heap.");for(let s of e)this.i._addFloatVectorEntry(o,s);this.i._addFloatVectorToInputStream(o,n,r)})}addIntVectorToStream(e,t,r){E(this,t,n=>{let o=this.i._allocateIntVector(e.length);if(!o)throw Error("Unable to allocate new int vector on heap.");for(let s of e)this.i._addIntVectorEntry(o,s);this.i._addIntVectorToInputStream(o,n,r)})}addUintVectorToStream(e,t,r){E(this,t,n=>{let o=this.i._allocateUintVector(e.length);if(!o)throw Error("Unable to allocate new unsigned int vector on heap.");for(let s of e)this.i._addUintVectorEntry(o,s);this.i._addUintVectorToInputStream(o,n,r)})}addStringVectorToStream(e,t,r){E(this,t,n=>{let o=this.i._allocateStringVector(e.length);if(!o)throw Error("Unable to allocate new string vector on heap.");for(let s of e)E(this,s,a=>{this.i._addStringVectorEntry(o,a)});this.i._addStringVectorToInputStream(o,n,r)})}addBoolToInputSidePacket(e,t){E(this,t,r=>{this.i._addBoolToInputSidePacket(e,r)})}addDoubleToInputSidePacket(e,t){E(this,t,r=>{this.i._addDoubleToInputSidePacket(e,r)})}addFloatToInputSidePacket(e,t){E(this,t,r=>{this.i._addFloatToInputSidePacket(e,r)})}addIntToInputSidePacket(e,t){E(this,t,r=>{this.i._addIntToInputSidePacket(e,r)})}addUintToInputSidePacket(e,t){E(this,t,r=>{this.i._addUintToInputSidePacket(e,r)})}addStringToInputSidePacket(e,t){E(this,t,r=>{E(this,e,n=>{this.i._addStringToInputSidePacket(n,r)})})}addProtoToInputSidePacket(e,t,r){E(this,r,n=>{E(this,t,o=>{let s=this.i._malloc(e.length);this.i.HEAPU8.set(e,s),this.i._addProtoToInputSidePacket(s,e.length,o,n),this.i._free(s)})})}addBoolVectorToInputSidePacket(e,t){E(this,t,r=>{let n=this.i._allocateBoolVector(e.length);if(!n)throw Error("Unable to allocate new bool vector on heap.");for(let o of e)this.i._addBoolVectorEntry(n,o);this.i._addBoolVectorToInputSidePacket(n,r)})}addDoubleVectorToInputSidePacket(e,t){E(this,t,r=>{let n=this.i._allocateDoubleVector(e.length);if(!n)throw Error("Unable to allocate new double vector on heap.");for(let o of e)this.i._addDoubleVectorEntry(n,o);this.i._addDoubleVectorToInputSidePacket(n,r)})}addFloatVectorToInputSidePacket(e,t){E(this,t,r=>{let n=this.i._allocateFloatVector(e.length);if(!n)throw Error("Unable to allocate new float vector on heap.");for(let o of e)this.i._addFloatVectorEntry(n,o);this.i._addFloatVectorToInputSidePacket(n,r)})}addIntVectorToInputSidePacket(e,t){E(this,t,r=>{let n=this.i._allocateIntVector(e.length);if(!n)throw Error("Unable to allocate new int vector on heap.");for(let o of e)this.i._addIntVectorEntry(n,o);this.i._addIntVectorToInputSidePacket(n,r)})}addUintVectorToInputSidePacket(e,t){E(this,t,r=>{let n=this.i._allocateUintVector(e.length);if(!n)throw Error("Unable to allocate new unsigned int vector on heap.");for(let o of e)this.i._addUintVectorEntry(n,o);this.i._addUintVectorToInputSidePacket(n,r)})}addStringVectorToInputSidePacket(e,t){E(this,t,r=>{let n=this.i._allocateStringVector(e.length);if(!n)throw Error("Unable to allocate new string vector on heap.");for(let o of e)E(this,o,s=>{this.i._addStringVectorEntry(n,s)});this.i._addStringVectorToInputSidePacket(n,r)})}attachBoolListener(e,t){qe(this,e,t),E(this,e,r=>{this.i._attachBoolListener(r)})}attachBoolVectorListener(e,t){lt(this,e,t),E(this,e,r=>{this.i._attachBoolVectorListener(r)})}attachIntListener(e,t){qe(this,e,t),E(this,e,r=>{this.i._attachIntListener(r)})}attachIntVectorListener(e,t){lt(this,e,t),E(this,e,r=>{this.i._attachIntVectorListener(r)})}attachUintListener(e,t){qe(this,e,t),E(this,e,r=>{this.i._attachUintListener(r)})}attachUintVectorListener(e,t){lt(this,e,t),E(this,e,r=>{this.i._attachUintVectorListener(r)})}attachDoubleListener(e,t){qe(this,e,t),E(this,e,r=>{this.i._attachDoubleListener(r)})}attachDoubleVectorListener(e,t){lt(this,e,t),E(this,e,r=>{this.i._attachDoubleVectorListener(r)})}attachFloatListener(e,t){qe(this,e,t),E(this,e,r=>{this.i._attachFloatListener(r)})}attachFloatVectorListener(e,t){lt(this,e,t),E(this,e,r=>{this.i._attachFloatVectorListener(r)})}attachStringListener(e,t){qe(this,e,t),E(this,e,r=>{this.i._attachStringListener(r)})}attachStringVectorListener(e,t){lt(this,e,t),E(this,e,r=>{this.i._attachStringVectorListener(r)})}attachProtoListener(e,t,r){qe(this,e,t),E(this,e,n=>{this.i._attachProtoListener(n,r||!1)})}attachProtoVectorListener(e,t,r){lt(this,e,t),E(this,e,n=>{this.i._attachProtoVectorListener(n,r||!1)})}attachAudioListener(e,t,r){this.i._attachAudioListener||console.warn('Attempting to use attachAudioListener without support for output audio. Is build dep ":gl_graph_runner_audio_out" missing?'),qe(this,e,(n,o)=>{n=new Float32Array(n.buffer,n.byteOffset,n.length/4),t(n,o)}),E(this,e,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 Ia{get fa(){return this.i}ra(e,t,r){E(this,t,n=>{let[o,s]=va(this,e,n);this.fa._addBoundTextureAsImageToStream(n,o,s,r)})}V(e,t){qe(this,e,t),E(this,e,r=>{this.fa._attachImageListener(r)})}da(e,t){lt(this,e,t),E(this,e,r=>{this.fa._attachImageVectorListener(r)})}})),Ia,Be=class extends O2{};async function M(e,t,r){return async function(n,o,s,a){return I2(n,o,s,a)}(e,r.canvas??(Sc()?void 0:document.createElement("canvas")),t,r)}function Uc(e,t,r,n){if(e.U){let s=new nc;if(r?.regionOfInterest){if(!e.qa)throw Error("This task doesn't support region-of-interest.");var o=r.regionOfInterest;if(o.left>=o.right||o.top>=o.bottom)throw Error("Expected RectF with left < right and top < bottom.");if(o.left<0||o.top<0||o.right>1||o.bottom>1)throw Error("Expected RectF values to be in [0,1].");v(s,1,(o.left+o.right)/2),v(s,2,(o.top+o.bottom)/2),v(s,4,o.right-o.left),v(s,3,o.bottom-o.top)}else v(s,1,.5),v(s,2,.5),v(s,4,1),v(s,3,1);if(r?.rotationDegrees){if(r?.rotationDegrees%90!=0)throw Error("Expected rotation to be a multiple of 90\xB0.");if(v(s,5,-Math.PI*r.rotationDegrees/180),r?.rotationDegrees%180!=0){let[a,i]=Cc(t);r=te(s,3)*i/a,o=te(s,4)*a/i,v(s,4,r),v(s,3,o)}}e.g.addProtoToStream(s.g(),"mediapipe.NormalizedRect",e.U,n)}e.g.ra(t,e.ba,n??performance.now()),e.finishProcessing()}function De(e,t,r){if(e.baseOptions?.g())throw Error("Task is not initialized with image mode. 'runningMode' must be set to 'IMAGE'.");Uc(e,t,r,e.B+1)}function rt(e,t,r,n){if(!e.baseOptions?.g())throw Error("Task is not initialized with video mode. 'runningMode' must be set to 'VIDEO'.");Uc(e,t,r,n)}function zt(e,t,r,n){var o=t.data;let s=t.width,a=s*(t=t.height);if((o instanceof Uint8Array||o instanceof Float32Array)&&o.length!==a)throw Error("Unsupported channel count: "+o.length/a);return e=new ae([o],r,!1,e.g.i.canvas,e.P,s,t),n?e.clone():e}var Ee=class extends Vr{constructor(e,t,r,n){super(e),this.g=e,this.ba=t,this.U=r,this.qa=n,this.P=new nr}l(e,t=!0){if("runningMode"in e&&Er(this.baseOptions,2,!!e.runningMode&&e.runningMode!=="IMAGE"),e.canvas!==void 0&&this.g.i.canvas!==e.canvas)throw Error("You must create a new task to reset the canvas.");return super.l(e,t)}close(){this.P.close(),super.close()}};Ee.prototype.close=Ee.prototype.close;var Ie=class extends Ee{constructor(e,t){super(new Be(e,t),"image_in","norm_rect_in",!1),this.j={detections:[]},T(e=this.h=new bn,0,1,t=new $),v(this.h,2,.5),v(this.h,3,.3)}get baseOptions(){return O(this.h,$,1)}set baseOptions(e){T(this.h,0,1,e)}o(e){return"minDetectionConfidence"in e&&v(this.h,2,e.minDetectionConfidence??.5),"minSuppressionThreshold"in e&&v(this.h,3,e.minSuppressionThreshold??.3),this.l(e)}D(e,t){return this.j={detections:[]},De(this,e,t),this.j}F(e,t,r){return this.j={detections:[]},rt(this,e,r,t),this.j}m(){var e=new be;Y(e,"image_in"),Y(e,"norm_rect_in"),P(e,"detections");let t=new ke;Xe(t,x2,this.h);let r=new xe;Ce(r,"mediapipe.tasks.vision.face_detector.FaceDetectorGraph"),H(r,"IMAGE:image_in"),H(r,"NORM_RECT:norm_rect_in"),F(r,"DETECTIONS:detections"),r.o(t),Le(e,r),this.g.attachProtoVectorListener("detections",(n,o)=>{for(let s of n)n=ec(s),this.j.detections.push(wc(n));m(this,o)}),this.g.attachEmptyPacketListener("detections",n=>{m(this,n)}),e=e.g(),this.setGraph(new Uint8Array(e),!0)}};Ie.prototype.detectForVideo=Ie.prototype.F,Ie.prototype.detect=Ie.prototype.D,Ie.prototype.setOptions=Ie.prototype.o,Ie.createFromModelPath=async function(e,t){return M(Ie,e,{baseOptions:{modelAssetPath:t}})},Ie.createFromModelBuffer=function(e,t){return M(Ie,e,{baseOptions:{modelAssetBuffer:t}})},Ie.createFromOptions=function(e,t){return M(Ie,e,t)};var fs=ze([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]),ps=ze([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]),ms=ze([276,283],[283,282],[282,295],[295,285],[300,293],[293,334],[334,296],[296,336]),Oc=ze([474,475],[475,476],[476,477],[477,474]),gs=ze([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]),xs=ze([46,53],[53,52],[52,65],[65,55],[70,63],[63,105],[105,66],[66,107]),Pc=ze([469,470],[470,471],[471,472],[472,469]),ys=ze([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]),Bc=[...fs,...ps,...ms,...gs,...xs,...ys],Dc=ze([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 Ma(e){e.j={faceLandmarks:[],faceBlendshapes:[],facialTransformationMatrixes:[]}}var Q=class extends Ee{constructor(e,t){super(new Be(e,t),"image_in","norm_rect",!1),this.j={faceLandmarks:[],faceBlendshapes:[],facialTransformationMatrixes:[]},this.outputFacialTransformationMatrixes=this.outputFaceBlendshapes=!1,T(e=this.h=new cc,0,1,t=new $),this.v=new ic,T(this.h,0,3,this.v),this.s=new bn,T(this.h,0,2,this.s),tt(this.s,4,1),v(this.s,2,.5),v(this.v,2,.5),v(this.h,4,.5)}get baseOptions(){return O(this.h,$,1)}set baseOptions(e){T(this.h,0,1,e)}o(e){return"numFaces"in e&&tt(this.s,4,e.numFaces??1),"minFaceDetectionConfidence"in e&&v(this.s,2,e.minFaceDetectionConfidence??.5),"minTrackingConfidence"in e&&v(this.h,4,e.minTrackingConfidence??.5),"minFacePresenceConfidence"in e&&v(this.v,2,e.minFacePresenceConfidence??.5),"outputFaceBlendshapes"in e&&(this.outputFaceBlendshapes=!!e.outputFaceBlendshapes),"outputFacialTransformationMatrixes"in e&&(this.outputFacialTransformationMatrixes=!!e.outputFacialTransformationMatrixes),this.l(e)}D(e,t){return Ma(this),De(this,e,t),this.j}F(e,t,r){return Ma(this),rt(this,e,r,t),this.j}m(){var e=new be;Y(e,"image_in"),Y(e,"norm_rect"),P(e,"face_landmarks");let t=new ke;Xe(t,v2,this.h);let r=new xe;Ce(r,"mediapipe.tasks.vision.face_landmarker.FaceLandmarkerGraph"),H(r,"IMAGE:image_in"),H(r,"NORM_RECT:norm_rect"),F(r,"NORM_LANDMARKS:face_landmarks"),r.o(t),Le(e,r),this.g.attachProtoVectorListener("face_landmarks",(n,o)=>{for(let s of n)n=kr(s),this.j.faceLandmarks.push(Tn(n));m(this,o)}),this.g.attachEmptyPacketListener("face_landmarks",n=>{m(this,n)}),this.outputFaceBlendshapes&&(P(e,"blendshapes"),F(r,"BLENDSHAPES:blendshapes"),this.g.attachProtoVectorListener("blendshapes",(n,o)=>{if(this.outputFaceBlendshapes)for(let s of n)n=En(s),this.j.faceBlendshapes.push(us(n.g()??[]));m(this,o)}),this.g.attachEmptyPacketListener("blendshapes",n=>{m(this,n)})),this.outputFacialTransformationMatrixes&&(P(e,"face_geometry"),F(r,"FACE_GEOMETRY:face_geometry"),this.g.attachProtoVectorListener("face_geometry",(n,o)=>{if(this.outputFacialTransformationMatrixes)for(let s of n)(n=O(y2(s),u2,2))&&this.j.facialTransformationMatrixes.push({rows:je(Oe(n,1),0)??0,columns:je(Oe(n,2),0)??0,data:Ct(n,3,At,St()).slice()??[]});m(this,o)}),this.g.attachEmptyPacketListener("face_geometry",n=>{m(this,n)})),e=e.g(),this.setGraph(new Uint8Array(e),!0)}};Q.prototype.detectForVideo=Q.prototype.F,Q.prototype.detect=Q.prototype.D,Q.prototype.setOptions=Q.prototype.o,Q.createFromModelPath=function(e,t){return M(Q,e,{baseOptions:{modelAssetPath:t}})},Q.createFromModelBuffer=function(e,t){return M(Q,e,{baseOptions:{modelAssetBuffer:t}})},Q.createFromOptions=function(e,t){return M(Q,e,t)},Q.FACE_LANDMARKS_LIPS=fs,Q.FACE_LANDMARKS_LEFT_EYE=ps,Q.FACE_LANDMARKS_LEFT_EYEBROW=ms,Q.FACE_LANDMARKS_LEFT_IRIS=Oc,Q.FACE_LANDMARKS_RIGHT_EYE=gs,Q.FACE_LANDMARKS_RIGHT_EYEBROW=xs,Q.FACE_LANDMARKS_RIGHT_IRIS=Pc,Q.FACE_LANDMARKS_FACE_OVAL=ys,Q.FACE_LANDMARKS_CONTOURS=Bc,Q.FACE_LANDMARKS_TESSELATION=Dc;var Je=class extends Ee{constructor(e,t){super(new Be(e,t),"image_in","norm_rect",!0),T(e=this.j=new hc,0,1,t=new $)}get baseOptions(){return O(this.j,$,1)}set baseOptions(e){T(this.j,0,1,e)}o(e){return super.l(e)}Oa(e,t,r){let n=typeof t!="function"?t:{};if(this.h=typeof t=="function"?t:r,De(this,e,n??{}),!this.h)return this.s}m(){var e=new be;Y(e,"image_in"),Y(e,"norm_rect"),P(e,"stylized_image");let t=new ke;Xe(t,E2,this.j);let r=new xe;Ce(r,"mediapipe.tasks.vision.face_stylizer.FaceStylizerGraph"),H(r,"IMAGE:image_in"),H(r,"NORM_RECT:norm_rect"),F(r,"STYLIZED_IMAGE:stylized_image"),r.o(t),Le(e,r),this.g.V("stylized_image",(n,o)=>{var s=!this.h,a=n.data,i=n.width;let c=i*(n=n.height);if(a instanceof Uint8Array)if(a.length===3*c){let l=new Uint8ClampedArray(4*c);for(let h=0;h<c;++h)l[4*h]=a[3*h],l[4*h+1]=a[3*h+1],l[4*h+2]=a[3*h+2],l[4*h+3]=255;a=new ImageData(l,i,n)}else{if(a.length!==4*c)throw Error("Unsupported channel count: "+a.length/c);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 he([a],!1,!1,this.g.i.canvas,this.P,i,n),this.s=s=s?i.clone():i,this.h&&this.h(s),m(this,o)}),this.g.attachEmptyPacketListener("stylized_image",n=>{this.s=null,this.h&&this.h(null),m(this,n)}),e=e.g(),this.setGraph(new Uint8Array(e),!0)}};Je.prototype.stylize=Je.prototype.Oa,Je.prototype.setOptions=Je.prototype.o,Je.createFromModelPath=function(e,t){return M(Je,e,{baseOptions:{modelAssetPath:t}})},Je.createFromModelBuffer=function(e,t){return M(Je,e,{baseOptions:{modelAssetBuffer:t}})},Je.createFromOptions=function(e,t){return M(Je,e,t)};var vs=ze([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 Fa(e){e.gestures=[],e.landmarks=[],e.worldLandmarks=[],e.handedness=[]}function Ua(e){return e.gestures.length===0?{gestures:[],landmarks:[],worldLandmarks:[],handedness:[],handednesses:[]}:{gestures:e.gestures,landmarks:e.landmarks,worldLandmarks:e.worldLandmarks,handedness:e.handedness,handednesses:e.handedness}}function Oa(e,t=!0){let r=[];for(let o of e){var n=En(o);e=[];for(let s of n.g())n=t&&Oe(s,1)!=null?je(Oe(s,1),0):-1,e.push({score:te(s,2)??0,index:n,categoryName:et(s,3)??"",displayName:et(s,4)??""});r.push(e)}return r}var Te=class extends Ee{constructor(e,t){super(new Be(e,t),"image_in","norm_rect",!1),this.gestures=[],this.landmarks=[],this.worldLandmarks=[],this.handedness=[],T(e=this.j=new fc,0,1,t=new $),this.s=new ss,T(this.j,0,2,this.s),this.C=new os,T(this.s,0,3,this.C),this.v=new dc,T(this.s,0,2,this.v),this.h=new b2,T(this.j,0,3,this.h),v(this.v,2,.5),v(this.s,4,.5),v(this.C,2,.5)}get baseOptions(){return O(this.j,$,1)}set baseOptions(e){T(this.j,0,1,e)}o(e){if(tt(this.v,3,e.numHands??1),"minHandDetectionConfidence"in e&&v(this.v,2,e.minHandDetectionConfidence??.5),"minTrackingConfidence"in e&&v(this.s,4,e.minTrackingConfidence??.5),"minHandPresenceConfidence"in e&&v(this.C,2,e.minHandPresenceConfidence??.5),e.cannedGesturesClassifierOptions){var t=new Ut,r=t,n=co(e.cannedGesturesClassifierOptions,O(this.h,Ut,3)?.h());T(r,0,2,n),T(this.h,0,3,t)}else e.cannedGesturesClassifierOptions===void 0&&O(this.h,Ut,3)?.g();return e.customGesturesClassifierOptions?(T(r=t=new Ut,0,2,n=co(e.customGesturesClassifierOptions,O(this.h,Ut,4)?.h())),T(this.h,0,4,t)):e.customGesturesClassifierOptions===void 0&&O(this.h,Ut,4)?.g(),this.l(e)}Ja(e,t){return Fa(this),De(this,e,t),Ua(this)}Ka(e,t,r){return Fa(this),rt(this,e,r,t),Ua(this)}m(){var e=new be;Y(e,"image_in"),Y(e,"norm_rect"),P(e,"hand_gestures"),P(e,"hand_landmarks"),P(e,"world_hand_landmarks"),P(e,"handedness");let t=new ke;Xe(t,T2,this.j);let r=new xe;Ce(r,"mediapipe.tasks.vision.gesture_recognizer.GestureRecognizerGraph"),H(r,"IMAGE:image_in"),H(r,"NORM_RECT:norm_rect"),F(r,"HAND_GESTURES:hand_gestures"),F(r,"LANDMARKS:hand_landmarks"),F(r,"WORLD_LANDMARKS:world_hand_landmarks"),F(r,"HANDEDNESS:handedness"),r.o(t),Le(e,r),this.g.attachProtoVectorListener("hand_landmarks",(n,o)=>{for(let s of n){n=kr(s);let a=[];for(let i of ct(n,rc,1))a.push({x:te(i,1)??0,y:te(i,2)??0,z:te(i,3)??0,visibility:te(i,4)??0});this.landmarks.push(a)}m(this,o)}),this.g.attachEmptyPacketListener("hand_landmarks",n=>{m(this,n)}),this.g.attachProtoVectorListener("world_hand_landmarks",(n,o)=>{for(let s of n){n=Nt(s);let a=[];for(let i of ct(n,tc,1))a.push({x:te(i,1)??0,y:te(i,2)??0,z:te(i,3)??0,visibility:te(i,4)??0});this.worldLandmarks.push(a)}m(this,o)}),this.g.attachEmptyPacketListener("world_hand_landmarks",n=>{m(this,n)}),this.g.attachProtoVectorListener("hand_gestures",(n,o)=>{this.gestures.push(...Oa(n,!1)),m(this,o)}),this.g.attachEmptyPacketListener("hand_gestures",n=>{m(this,n)}),this.g.attachProtoVectorListener("handedness",(n,o)=>{this.handedness.push(...Oa(n)),m(this,o)}),this.g.attachEmptyPacketListener("handedness",n=>{m(this,n)}),e=e.g(),this.setGraph(new Uint8Array(e),!0)}};function Pa(e){return{landmarks:e.landmarks,worldLandmarks:e.worldLandmarks,handednesses:e.handedness,handedness:e.handedness}}Te.prototype.recognizeForVideo=Te.prototype.Ka,Te.prototype.recognize=Te.prototype.Ja,Te.prototype.setOptions=Te.prototype.o,Te.createFromModelPath=function(e,t){return M(Te,e,{baseOptions:{modelAssetPath:t}})},Te.createFromModelBuffer=function(e,t){return M(Te,e,{baseOptions:{modelAssetBuffer:t}})},Te.createFromOptions=function(e,t){return M(Te,e,t)},Te.HAND_CONNECTIONS=vs;var _e=class extends Ee{constructor(e,t){super(new Be(e,t),"image_in","norm_rect",!1),this.landmarks=[],this.worldLandmarks=[],this.handedness=[],T(e=this.h=new ss,0,1,t=new $),this.s=new os,T(this.h,0,3,this.s),this.j=new dc,T(this.h,0,2,this.j),tt(this.j,3,1),v(this.j,2,.5),v(this.s,2,.5),v(this.h,4,.5)}get baseOptions(){return O(this.h,$,1)}set baseOptions(e){T(this.h,0,1,e)}o(e){return"numHands"in e&&tt(this.j,3,e.numHands??1),"minHandDetectionConfidence"in e&&v(this.j,2,e.minHandDetectionConfidence??.5),"minTrackingConfidence"in e&&v(this.h,4,e.minTrackingConfidence??.5),"minHandPresenceConfidence"in e&&v(this.s,2,e.minHandPresenceConfidence??.5),this.l(e)}D(e,t){return this.landmarks=[],this.worldLandmarks=[],this.handedness=[],De(this,e,t),Pa(this)}F(e,t,r){return this.landmarks=[],this.worldLandmarks=[],this.handedness=[],rt(this,e,r,t),Pa(this)}m(){var e=new be;Y(e,"image_in"),Y(e,"norm_rect"),P(e,"hand_landmarks"),P(e,"world_hand_landmarks"),P(e,"handedness");let t=new ke;Xe(t,_2,this.h);let r=new xe;Ce(r,"mediapipe.tasks.vision.hand_landmarker.HandLandmarkerGraph"),H(r,"IMAGE:image_in"),H(r,"NORM_RECT:norm_rect"),F(r,"LANDMARKS:hand_landmarks"),F(r,"WORLD_LANDMARKS:world_hand_landmarks"),F(r,"HANDEDNESS:handedness"),r.o(t),Le(e,r),this.g.attachProtoVectorListener("hand_landmarks",(n,o)=>{for(let s of n)n=kr(s),this.landmarks.push(Tn(n));m(this,o)}),this.g.attachEmptyPacketListener("hand_landmarks",n=>{m(this,n)}),this.g.attachProtoVectorListener("world_hand_landmarks",(n,o)=>{for(let s of n)n=Nt(s),this.worldLandmarks.push(xr(n));m(this,o)}),this.g.attachEmptyPacketListener("world_hand_landmarks",n=>{m(this,n)}),this.g.attachProtoVectorListener("handedness",(n,o)=>{var s=this.handedness,a=s.push;let i=[];for(let c of n){n=En(c);let l=[];for(let h of n.g())l.push({score:te(h,2)??0,index:je(Oe(h,1),0)??-1,categoryName:et(h,3)??"",displayName:et(h,4)??""});i.push(l)}a.call(s,...i),m(this,o)}),this.g.attachEmptyPacketListener("handedness",n=>{m(this,n)}),e=e.g(),this.setGraph(new Uint8Array(e),!0)}};_e.prototype.detectForVideo=_e.prototype.F,_e.prototype.detect=_e.prototype.D,_e.prototype.setOptions=_e.prototype.o,_e.createFromModelPath=function(e,t){return M(_e,e,{baseOptions:{modelAssetPath:t}})},_e.createFromModelBuffer=function(e,t){return M(_e,e,{baseOptions:{modelAssetBuffer:t}})},_e.createFromOptions=function(e,t){return M(_e,e,t)},_e.HAND_CONNECTIONS=vs;var Nc=ze([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 Ba(e){e.h={faceLandmarks:[],faceBlendshapes:[],poseLandmarks:[],poseWorldLandmarks:[],poseSegmentationMasks:[],leftHandLandmarks:[],leftHandWorldLandmarks:[],rightHandLandmarks:[],rightHandWorldLandmarks:[]}}function Da(e){try{if(!e.C)return e.h;e.C(e.h)}finally{An(e)}}function Br(e,t){e=kr(e),t.push(Tn(e))}var K=class extends Ee{constructor(e,t){super(new Be(e,t),"input_frames_image",null,!1),this.h={faceLandmarks:[],faceBlendshapes:[],poseLandmarks:[],poseWorldLandmarks:[],poseSegmentationMasks:[],leftHandLandmarks:[],leftHandWorldLandmarks:[],rightHandLandmarks:[],rightHandWorldLandmarks:[]},this.outputPoseSegmentationMasks=this.outputFaceBlendshapes=!1,T(e=this.j=new yc,0,1,t=new $),this.K=new os,T(this.j,0,2,this.K),this.aa=new A2,T(this.j,0,3,this.aa),this.s=new bn,T(this.j,0,4,this.s),this.I=new ic,T(this.j,0,5,this.I),this.v=new gc,T(this.j,0,6,this.v),this.L=new xc,T(this.j,0,7,this.L),v(this.s,2,.5),v(this.s,3,.3),v(this.I,2,.5),v(this.v,2,.5),v(this.v,3,.3),v(this.L,2,.5),v(this.K,2,.5)}get baseOptions(){return O(this.j,$,1)}set baseOptions(e){T(this.j,0,1,e)}o(e){return"minFaceDetectionConfidence"in e&&v(this.s,2,e.minFaceDetectionConfidence??.5),"minFaceSuppressionThreshold"in e&&v(this.s,3,e.minFaceSuppressionThreshold??.3),"minFacePresenceConfidence"in e&&v(this.I,2,e.minFacePresenceConfidence??.5),"outputFaceBlendshapes"in e&&(this.outputFaceBlendshapes=!!e.outputFaceBlendshapes),"minPoseDetectionConfidence"in e&&v(this.v,2,e.minPoseDetectionConfidence??.5),"minPoseSuppressionThreshold"in e&&v(this.v,3,e.minPoseSuppressionThreshold??.3),"minPosePresenceConfidence"in e&&v(this.L,2,e.minPosePresenceConfidence??.5),"outputPoseSegmentationMasks"in e&&(this.outputPoseSegmentationMasks=!!e.outputPoseSegmentationMasks),"minHandLandmarksConfidence"in e&&v(this.K,2,e.minHandLandmarksConfidence??.5),this.l(e)}D(e,t,r){let n=typeof t!="function"?t:{};return this.C=typeof t=="function"?t:r,Ba(this),De(this,e,n),Da(this)}F(e,t,r,n){let o=typeof r!="function"?r:{};return this.C=typeof r=="function"?r:n,Ba(this),rt(this,e,o,t),Da(this)}m(){var e=new be;Y(e,"input_frames_image"),P(e,"pose_landmarks"),P(e,"pose_world_landmarks"),P(e,"face_landmarks"),P(e,"left_hand_landmarks"),P(e,"left_hand_world_landmarks"),P(e,"right_hand_landmarks"),P(e,"right_hand_world_landmarks");let t=new ke,r=new na;to(r,1,Jt("type.googleapis.com/mediapipe.tasks.vision.holistic_landmarker.proto.HolisticLandmarkerGraphOptions"),""),function(o,s){if(s!=null)if(Array.isArray(s))X(o,2,cn(s,Mo,void 0,void 0,!1));else{if(!(typeof s=="string"||s instanceof at||_r(s)))throw Error("invalid value in Any.value field: "+s+" expected a ByteString, a base64 encoded string, a Uint8Array or a jspb array");to(o,2,_o(s,!1),Mt())}}(r,this.j.g());let n=new xe;Ce(n,"mediapipe.tasks.vision.holistic_landmarker.HolisticLandmarkerGraph"),$r(n,8,na,r),H(n,"IMAGE:input_frames_image"),F(n,"POSE_LANDMARKS:pose_landmarks"),F(n,"POSE_WORLD_LANDMARKS:pose_world_landmarks"),F(n,"FACE_LANDMARKS:face_landmarks"),F(n,"LEFT_HAND_LANDMARKS:left_hand_landmarks"),F(n,"LEFT_HAND_WORLD_LANDMARKS:left_hand_world_landmarks"),F(n,"RIGHT_HAND_LANDMARKS:right_hand_landmarks"),F(n,"RIGHT_HAND_WORLD_LANDMARKS:right_hand_world_landmarks"),n.o(t),Le(e,n),_n(this,e),this.g.attachProtoListener("pose_landmarks",(o,s)=>{Br(o,this.h.poseLandmarks),m(this,s)}),this.g.attachEmptyPacketListener("pose_landmarks",o=>{m(this,o)}),this.g.attachProtoListener("pose_world_landmarks",(o,s)=>{var a=this.h.poseWorldLandmarks;o=Nt(o),a.push(xr(o)),m(this,s)}),this.g.attachEmptyPacketListener("pose_world_landmarks",o=>{m(this,o)}),this.outputPoseSegmentationMasks&&(F(n,"POSE_SEGMENTATION_MASK:pose_segmentation_mask"),Xt(this,"pose_segmentation_mask"),this.g.V("pose_segmentation_mask",(o,s)=>{this.h.poseSegmentationMasks=[zt(this,o,!0,!this.C)],m(this,s)}),this.g.attachEmptyPacketListener("pose_segmentation_mask",o=>{this.h.poseSegmentationMasks=[],m(this,o)})),this.g.attachProtoListener("face_landmarks",(o,s)=>{Br(o,this.h.faceLandmarks),m(this,s)}),this.g.attachEmptyPacketListener("face_landmarks",o=>{m(this,o)}),this.outputFaceBlendshapes&&(P(e,"extra_blendshapes"),F(n,"FACE_BLENDSHAPES:extra_blendshapes"),this.g.attachProtoListener("extra_blendshapes",(o,s)=>{var a=this.h.faceBlendshapes;this.outputFaceBlendshapes&&(o=En(o),a.push(us(o.g()??[]))),m(this,s)}),this.g.attachEmptyPacketListener("extra_blendshapes",o=>{m(this,o)})),this.g.attachProtoListener("left_hand_landmarks",(o,s)=>{Br(o,this.h.leftHandLandmarks),m(this,s)}),this.g.attachEmptyPacketListener("left_hand_landmarks",o=>{m(this,o)}),this.g.attachProtoListener("left_hand_world_landmarks",(o,s)=>{var a=this.h.leftHandWorldLandmarks;o=Nt(o),a.push(xr(o)),m(this,s)}),this.g.attachEmptyPacketListener("left_hand_world_landmarks",o=>{m(this,o)}),this.g.attachProtoListener("right_hand_landmarks",(o,s)=>{Br(o,this.h.rightHandLandmarks),m(this,s)}),this.g.attachEmptyPacketListener("right_hand_landmarks",o=>{m(this,o)}),this.g.attachProtoListener("right_hand_world_landmarks",(o,s)=>{var a=this.h.rightHandWorldLandmarks;o=Nt(o),a.push(xr(o)),m(this,s)}),this.g.attachEmptyPacketListener("right_hand_world_landmarks",o=>{m(this,o)}),e=e.g(),this.setGraph(new Uint8Array(e),!0)}};K.prototype.detectForVideo=K.prototype.F,K.prototype.detect=K.prototype.D,K.prototype.setOptions=K.prototype.o,K.createFromModelPath=function(e,t){return M(K,e,{baseOptions:{modelAssetPath:t}})},K.createFromModelBuffer=function(e,t){return M(K,e,{baseOptions:{modelAssetBuffer:t}})},K.createFromOptions=function(e,t){return M(K,e,t)},K.HAND_CONNECTIONS=vs,K.POSE_CONNECTIONS=Nc,K.FACE_LANDMARKS_LIPS=fs,K.FACE_LANDMARKS_LEFT_EYE=ps,K.FACE_LANDMARKS_LEFT_EYEBROW=ms,K.FACE_LANDMARKS_LEFT_IRIS=Oc,K.FACE_LANDMARKS_RIGHT_EYE=gs,K.FACE_LANDMARKS_RIGHT_EYEBROW=xs,K.FACE_LANDMARKS_RIGHT_IRIS=Pc,K.FACE_LANDMARKS_FACE_OVAL=ys,K.FACE_LANDMARKS_CONTOURS=Bc,K.FACE_LANDMARKS_TESSELATION=Dc;var Me=class extends Ee{constructor(e,t){super(new Be(e,t),"input_image","norm_rect",!0),this.j={classifications:[]},T(e=this.h=new vc,0,1,t=new $)}get baseOptions(){return O(this.h,$,1)}set baseOptions(e){T(this.h,0,1,e)}o(e){return T(this.h,0,2,co(e,O(this.h,ts,2))),this.l(e)}ta(e,t){return this.j={classifications:[]},De(this,e,t),this.j}ua(e,t,r){return this.j={classifications:[]},rt(this,e,r,t),this.j}m(){var e=new be;Y(e,"input_image"),Y(e,"norm_rect"),P(e,"classifications");let t=new ke;Xe(t,R2,this.h);let r=new xe;Ce(r,"mediapipe.tasks.vision.image_classifier.ImageClassifierGraph"),H(r,"IMAGE:input_image"),H(r,"NORM_RECT:norm_rect"),F(r,"CLASSIFICATIONS:classifications"),r.o(t),Le(e,r),this.g.attachProtoListener("classifications",(n,o)=>{this.j=function(s){let a={classifications:ct(s,l2,1).map(i=>us(O(i,Qi,4)?.g()??[],je(Oe(i,2),0),et(i,3)))};return zr(vt(s,2))!=null&&(a.timestampMs=je(zr(vt(s,2)),0)),a}(d2(n)),m(this,o)}),this.g.attachEmptyPacketListener("classifications",n=>{m(this,n)}),e=e.g(),this.setGraph(new Uint8Array(e),!0)}};Me.prototype.classifyForVideo=Me.prototype.ua,Me.prototype.classify=Me.prototype.ta,Me.prototype.setOptions=Me.prototype.o,Me.createFromModelPath=function(e,t){return M(Me,e,{baseOptions:{modelAssetPath:t}})},Me.createFromModelBuffer=function(e,t){return M(Me,e,{baseOptions:{modelAssetBuffer:t}})},Me.createFromOptions=function(e,t){return M(Me,e,t)};var Ae=class extends Ee{constructor(e,t){super(new Be(e,t),"image_in","norm_rect",!0),this.h=new Ec,this.embeddings={embeddings:[]},T(e=this.h,0,1,t=new $)}get baseOptions(){return O(this.h,$,1)}set baseOptions(e){T(this.h,0,1,e)}o(e){var t=this.h,r=O(this.h,da,2);return r=r?r.clone():new da,e.l2Normalize!==void 0?Er(r,1,e.l2Normalize):"l2Normalize"in e&&X(r,1),e.quantize!==void 0?Er(r,2,e.quantize):"quantize"in e&&X(r,2),T(t,0,2,r),this.l(e)}Aa(e,t){return De(this,e,t),this.embeddings}Ba(e,t,r){return rt(this,e,r,t),this.embeddings}m(){var e=new be;Y(e,"image_in"),Y(e,"norm_rect"),P(e,"embeddings_out");let t=new ke;Xe(t,w2,this.h);let r=new xe;Ce(r,"mediapipe.tasks.vision.image_embedder.ImageEmbedderGraph"),H(r,"IMAGE:image_in"),H(r,"NORM_RECT:norm_rect"),F(r,"EMBEDDINGS:embeddings_out"),r.o(t),Le(e,r),this.g.attachProtoListener("embeddings_out",(n,o)=>{n=m2(n),this.embeddings=function(s){return{embeddings:ct(s,p2,1).map(a=>{let i={headIndex:je(Oe(a,3),0)??-1,headName:et(a,4)??""};if(xi(a,la,Vn(a,1))!==void 0)a=Ct(a=O(a,la,Vn(a,1)),1,At,St()),i.floatEmbedding=a.slice();else{let c=new Uint8Array(0);i.quantizedEmbedding=O(a,f2,Vn(a,2))?.pa()?.h()??c}return i}),timestampMs:je(zr(vt(s,2)),0)}}(n),m(this,o)}),this.g.attachEmptyPacketListener("embeddings_out",n=>{m(this,n)}),e=e.g(),this.setGraph(new Uint8Array(e),!0)}};Ae.cosineSimilarity=function(e,t){if(e.floatEmbedding&&t.floatEmbedding)e=xa(e.floatEmbedding,t.floatEmbedding);else{if(!e.quantizedEmbedding||!t.quantizedEmbedding)throw Error("Cannot compute cosine similarity between quantized and float embeddings.");e=xa(ga(e.quantizedEmbedding),ga(t.quantizedEmbedding))}return e},Ae.prototype.embedForVideo=Ae.prototype.Ba,Ae.prototype.embed=Ae.prototype.Aa,Ae.prototype.setOptions=Ae.prototype.o,Ae.createFromModelPath=function(e,t){return M(Ae,e,{baseOptions:{modelAssetPath:t}})},Ae.createFromModelBuffer=function(e,t){return M(Ae,e,{baseOptions:{modelAssetBuffer:t}})},Ae.createFromOptions=function(e,t){return M(Ae,e,t)};var fo=class{constructor(e,t,r){this.confidenceMasks=e,this.categoryMask=t,this.qualityScores=r}close(){this.confidenceMasks?.forEach(e=>{e.close()}),this.categoryMask?.close()}};function Na(e){e.categoryMask=void 0,e.confidenceMasks=void 0,e.qualityScores=void 0}function Ga(e){try{let t=new fo(e.confidenceMasks,e.categoryMask,e.qualityScores);if(!e.j)return t;e.j(t)}finally{An(e)}}fo.prototype.close=fo.prototype.close;var de=class extends Ee{constructor(e,t){super(new Be(e,t),"image_in","norm_rect",!1),this.s=[],this.outputCategoryMask=!1,this.outputConfidenceMasks=!0,this.h=new cs,this.v=new bc,T(this.h,0,3,this.v),T(e=this.h,0,1,t=new $)}get baseOptions(){return O(this.h,$,1)}set baseOptions(e){T(this.h,0,1,e)}o(e){return e.displayNamesLocale!==void 0?X(this.h,2,Jt(e.displayNamesLocale)):"displayNamesLocale"in e&&X(this.h,2),"outputCategoryMask"in e&&(this.outputCategoryMask=e.outputCategoryMask??!1),"outputConfidenceMasks"in e&&(this.outputConfidenceMasks=e.outputConfidenceMasks??!0),super.l(e)}J(){(function(e){let t=ct(e.ea(),xe,1).filter(r=>et(r,1).includes("mediapipe.tasks.TensorsToSegmentationCalculator"));if(e.s=[],t.length>1)throw Error("The graph has more than one mediapipe.tasks.TensorsToSegmentationCalculator.");t.length===1&&(O(t[0],ke,7)?.l()?.g()??new Map).forEach((r,n)=>{e.s[Number(n)]=et(r,1)})})(this)}segment(e,t,r){let n=typeof t!="function"?t:{};return this.j=typeof t=="function"?t:r,Na(this),De(this,e,n),Ga(this)}Ma(e,t,r,n){let o=typeof r!="function"?r:{};return this.j=typeof r=="function"?r:n,Na(this),rt(this,e,o,t),Ga(this)}Ea(){return this.s}m(){var e=new be;Y(e,"image_in"),Y(e,"norm_rect");let t=new ke;Xe(t,_c,this.h);let r=new xe;Ce(r,"mediapipe.tasks.vision.image_segmenter.ImageSegmenterGraph"),H(r,"IMAGE:image_in"),H(r,"NORM_RECT:norm_rect"),r.o(t),Le(e,r),_n(this,e),this.outputConfidenceMasks&&(P(e,"confidence_masks"),F(r,"CONFIDENCE_MASKS:confidence_masks"),Xt(this,"confidence_masks"),this.g.da("confidence_masks",(n,o)=>{this.confidenceMasks=n.map(s=>zt(this,s,!0,!this.j)),m(this,o)}),this.g.attachEmptyPacketListener("confidence_masks",n=>{this.confidenceMasks=[],m(this,n)})),this.outputCategoryMask&&(P(e,"category_mask"),F(r,"CATEGORY_MASK:category_mask"),Xt(this,"category_mask"),this.g.V("category_mask",(n,o)=>{this.categoryMask=zt(this,n,!1,!this.j),m(this,o)}),this.g.attachEmptyPacketListener("category_mask",n=>{this.categoryMask=void 0,m(this,n)})),P(e,"quality_scores"),F(r,"QUALITY_SCORES:quality_scores"),this.g.attachFloatVectorListener("quality_scores",(n,o)=>{this.qualityScores=n,m(this,o)}),this.g.attachEmptyPacketListener("quality_scores",n=>{this.categoryMask=void 0,m(this,n)}),e=e.g(),this.setGraph(new Uint8Array(e),!0)}};de.prototype.getLabels=de.prototype.Ea,de.prototype.segmentForVideo=de.prototype.Ma,de.prototype.segment=de.prototype.segment,de.prototype.setOptions=de.prototype.o,de.createFromModelPath=function(e,t){return M(de,e,{baseOptions:{modelAssetPath:t}})},de.createFromModelBuffer=function(e,t){return M(de,e,{baseOptions:{modelAssetBuffer:t}})},de.createFromOptions=function(e,t){return M(de,e,t)};var po=class{constructor(e,t,r){this.confidenceMasks=e,this.categoryMask=t,this.qualityScores=r}close(){this.confidenceMasks?.forEach(e=>{e.close()}),this.categoryMask?.close()}};po.prototype.close=po.prototype.close;var P2=class extends x{constructor(e){super(e)}},Ot=[0,ee,-2],en=[0,ot,-3,q,ot,-1],Va=[0,en],ja=[0,en,ee,-1],Kn=class extends x{constructor(e){super(e)}},Wa=[0,ot,-1,q],B2=class extends x{constructor(){super()}},Xa=class extends x{constructor(e){super(e)}},mo=[1,2,3,4,5,6,7,8,9,10,14,15],Gc=class extends x{constructor(){super()}};Gc.prototype.g=vn([0,ie,[0,mo,N,en,N,[0,en,Ot],N,Va,N,[0,Va,Ot],N,Wa,N,[0,ot,-3,q,We],N,[0,ot,-3,q],N,[0,D,ot,-2,q,ee,q,-1,2,ot,Ot],N,ja,N,[0,ja,Ot],ot,Ot,D,N,[0,ot,-3,q,Ot,-1],N,[0,ie,Wa]],D,[0,D,ee,-1,q]]);var Qe=class extends Ee{constructor(e,t){super(new Be(e,t),"image_in","norm_rect_in",!1),this.outputCategoryMask=!1,this.outputConfidenceMasks=!0,this.h=new cs,this.s=new bc,T(this.h,0,3,this.s),T(e=this.h,0,1,t=new $)}get baseOptions(){return O(this.h,$,1)}set baseOptions(e){T(this.h,0,1,e)}o(e){return"outputCategoryMask"in e&&(this.outputCategoryMask=e.outputCategoryMask??!1),"outputConfidenceMasks"in e&&(this.outputConfidenceMasks=e.outputConfidenceMasks??!0),super.l(e)}segment(e,t,r,n){let o=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 Gc;let s=new Xa;var a=new P2;if(tt(a,1,255),T(s,0,12,a),t.keypoint&&t.scribble)throw Error("Cannot provide both keypoint and scribble.");if(t.keypoint){var i=new Kn;Er(i,3,!0),v(i,1,t.keypoint.x),v(i,2,t.keypoint.y),mr(s,5,mo,i)}else{if(!t.scribble)throw Error("Must provide either a keypoint or a scribble.");for(i of(a=new B2,t.scribble))Er(t=new Kn,3,!0),v(t,1,i.x),v(t,2,i.y),$r(a,1,Kn,t);mr(s,15,mo,a)}$r(n,1,Xa,s),this.g.addProtoToStream(n.g(),"drishti.RenderData","roi_in",r),De(this,e,o);e:{try{let l=new po(this.confidenceMasks,this.categoryMask,this.qualityScores);if(!this.j){var c=l;break e}this.j(l)}finally{An(this)}c=void 0}return c}m(){var e=new be;Y(e,"image_in"),Y(e,"roi_in"),Y(e,"norm_rect_in");let t=new ke;Xe(t,_c,this.h);let r=new xe;Ce(r,"mediapipe.tasks.vision.interactive_segmenter.InteractiveSegmenterGraph"),H(r,"IMAGE:image_in"),H(r,"ROI:roi_in"),H(r,"NORM_RECT:norm_rect_in"),r.o(t),Le(e,r),_n(this,e),this.outputConfidenceMasks&&(P(e,"confidence_masks"),F(r,"CONFIDENCE_MASKS:confidence_masks"),Xt(this,"confidence_masks"),this.g.da("confidence_masks",(n,o)=>{this.confidenceMasks=n.map(s=>zt(this,s,!0,!this.j)),m(this,o)}),this.g.attachEmptyPacketListener("confidence_masks",n=>{this.confidenceMasks=[],m(this,n)})),this.outputCategoryMask&&(P(e,"category_mask"),F(r,"CATEGORY_MASK:category_mask"),Xt(this,"category_mask"),this.g.V("category_mask",(n,o)=>{this.categoryMask=zt(this,n,!1,!this.j),m(this,o)}),this.g.attachEmptyPacketListener("category_mask",n=>{this.categoryMask=void 0,m(this,n)})),P(e,"quality_scores"),F(r,"QUALITY_SCORES:quality_scores"),this.g.attachFloatVectorListener("quality_scores",(n,o)=>{this.qualityScores=n,m(this,o)}),this.g.attachEmptyPacketListener("quality_scores",n=>{this.categoryMask=void 0,m(this,n)}),e=e.g(),this.setGraph(new Uint8Array(e),!0)}};Qe.prototype.segment=Qe.prototype.segment,Qe.prototype.setOptions=Qe.prototype.o,Qe.createFromModelPath=function(e,t){return M(Qe,e,{baseOptions:{modelAssetPath:t}})},Qe.createFromModelBuffer=function(e,t){return M(Qe,e,{baseOptions:{modelAssetBuffer:t}})},Qe.createFromOptions=function(e,t){return M(Qe,e,t)};var Fe=class extends Ee{constructor(e,t){super(new Be(e,t),"input_frame_gpu","norm_rect",!1),this.j={detections:[]},T(e=this.h=new Ac,0,1,t=new $)}get baseOptions(){return O(this.h,$,1)}set baseOptions(e){T(this.h,0,1,e)}o(e){return e.displayNamesLocale!==void 0?X(this.h,2,Jt(e.displayNamesLocale)):"displayNamesLocale"in e&&X(this.h,2),e.maxResults!==void 0?tt(this.h,3,e.maxResults):"maxResults"in e&&X(this.h,3),e.scoreThreshold!==void 0?v(this.h,4,e.scoreThreshold):"scoreThreshold"in e&&X(this.h,4),e.categoryAllowlist!==void 0?qr(this.h,5,e.categoryAllowlist):"categoryAllowlist"in e&&X(this.h,5),e.categoryDenylist!==void 0?qr(this.h,6,e.categoryDenylist):"categoryDenylist"in e&&X(this.h,6),this.l(e)}D(e,t){return this.j={detections:[]},De(this,e,t),this.j}F(e,t,r){return this.j={detections:[]},rt(this,e,r,t),this.j}m(){var e=new be;Y(e,"input_frame_gpu"),Y(e,"norm_rect"),P(e,"detections");let t=new ke;Xe(t,S2,this.h);let r=new xe;Ce(r,"mediapipe.tasks.vision.ObjectDetectorGraph"),H(r,"IMAGE:input_frame_gpu"),H(r,"NORM_RECT:norm_rect"),F(r,"DETECTIONS:detections"),r.o(t),Le(e,r),this.g.attachProtoVectorListener("detections",(n,o)=>{for(let s of n)n=ec(s),this.j.detections.push(wc(n));m(this,o)}),this.g.attachEmptyPacketListener("detections",n=>{m(this,n)}),e=e.g(),this.setGraph(new Uint8Array(e),!0)}};Fe.prototype.detectForVideo=Fe.prototype.F,Fe.prototype.detect=Fe.prototype.D,Fe.prototype.setOptions=Fe.prototype.o,Fe.createFromModelPath=async function(e,t){return M(Fe,e,{baseOptions:{modelAssetPath:t}})},Fe.createFromModelBuffer=function(e,t){return M(Fe,e,{baseOptions:{modelAssetBuffer:t}})},Fe.createFromOptions=function(e,t){return M(Fe,e,t)};var go=class{constructor(e,t,r){this.landmarks=e,this.worldLandmarks=t,this.segmentationMasks=r}close(){this.segmentationMasks?.forEach(e=>{e.close()})}};function Ha(e){e.landmarks=[],e.worldLandmarks=[],e.segmentationMasks=void 0}function Ya(e){try{let t=new go(e.landmarks,e.worldLandmarks,e.segmentationMasks);if(!e.s)return t;e.s(t)}finally{An(e)}}go.prototype.close=go.prototype.close;var Re=class extends Ee{constructor(e,t){super(new Be(e,t),"image_in","norm_rect",!1),this.landmarks=[],this.worldLandmarks=[],this.outputSegmentationMasks=!1,T(e=this.h=new Rc,0,1,t=new $),this.v=new xc,T(this.h,0,3,this.v),this.j=new gc,T(this.h,0,2,this.j),tt(this.j,4,1),v(this.j,2,.5),v(this.v,2,.5),v(this.h,4,.5)}get baseOptions(){return O(this.h,$,1)}set baseOptions(e){T(this.h,0,1,e)}o(e){return"numPoses"in e&&tt(this.j,4,e.numPoses??1),"minPoseDetectionConfidence"in e&&v(this.j,2,e.minPoseDetectionConfidence??.5),"minTrackingConfidence"in e&&v(this.h,4,e.minTrackingConfidence??.5),"minPosePresenceConfidence"in e&&v(this.v,2,e.minPosePresenceConfidence??.5),"outputSegmentationMasks"in e&&(this.outputSegmentationMasks=e.outputSegmentationMasks??!1),this.l(e)}D(e,t,r){let n=typeof t!="function"?t:{};return this.s=typeof t=="function"?t:r,Ha(this),De(this,e,n),Ya(this)}F(e,t,r,n){let o=typeof r!="function"?r:{};return this.s=typeof r=="function"?r:n,Ha(this),rt(this,e,o,t),Ya(this)}m(){var e=new be;Y(e,"image_in"),Y(e,"norm_rect"),P(e,"normalized_landmarks"),P(e,"world_landmarks"),P(e,"segmentation_masks");let t=new ke;Xe(t,C2,this.h);let r=new xe;Ce(r,"mediapipe.tasks.vision.pose_landmarker.PoseLandmarkerGraph"),H(r,"IMAGE:image_in"),H(r,"NORM_RECT:norm_rect"),F(r,"NORM_LANDMARKS:normalized_landmarks"),F(r,"WORLD_LANDMARKS:world_landmarks"),r.o(t),Le(e,r),_n(this,e),this.g.attachProtoVectorListener("normalized_landmarks",(n,o)=>{this.landmarks=[];for(let s of n)n=kr(s),this.landmarks.push(Tn(n));m(this,o)}),this.g.attachEmptyPacketListener("normalized_landmarks",n=>{this.landmarks=[],m(this,n)}),this.g.attachProtoVectorListener("world_landmarks",(n,o)=>{this.worldLandmarks=[];for(let s of n)n=Nt(s),this.worldLandmarks.push(xr(n));m(this,o)}),this.g.attachEmptyPacketListener("world_landmarks",n=>{this.worldLandmarks=[],m(this,n)}),this.outputSegmentationMasks&&(F(r,"SEGMENTATION_MASK:segmentation_masks"),Xt(this,"segmentation_masks"),this.g.da("segmentation_masks",(n,o)=>{this.segmentationMasks=n.map(s=>zt(this,s,!0,!this.s)),m(this,o)}),this.g.attachEmptyPacketListener("segmentation_masks",n=>{this.segmentationMasks=[],m(this,n)})),e=e.g(),this.setGraph(new Uint8Array(e),!0)}};Re.prototype.detectForVideo=Re.prototype.F,Re.prototype.detect=Re.prototype.D,Re.prototype.setOptions=Re.prototype.o,Re.createFromModelPath=function(e,t){return M(Re,e,{baseOptions:{modelAssetPath:t}})},Re.createFromModelBuffer=function(e,t){return M(Re,e,{baseOptions:{modelAssetBuffer:t}})},Re.createFromOptions=function(e,t){return M(Re,e,t)},Re.POSE_CONNECTIONS=Nc;var _=(e,t="AssertError")=>{if(!e)throw new Error(t,{cause:e});return e};var Es=e=>e;var bs=(e,...t)=>{let r=t.reduce((n,o)=>s=>o(n(s)),Es);return(...n)=>r(e(...n))};var N2="utils/memoize/noValue",Ml=Symbol(N2);var G2=e=>`(${e})`;var Vc=e=>G2(`?:${e}`),V2=e=>`${Vc(e)}?`,j2=e=>`${Vc(e)}*`;var W2=e=>`^${e}`,X2=e=>`${e}$`,H2=e=>typeof e=="function",Y2=e=>t=>H2(t)?t(e):t;var z2=()=>e=>e,kn=(e,t=z2)=>r=>n=>bs(Y2(n),t(n),e)(r);var Ol=kn(e=>V2(e)),Pl=kn(e=>j2(e));var Bl=kn(e=>W2(e)),Dl=kn(e=>X2(e));var z={Closed:"closed",Closing:"closing",Destroyed:"destroyed",Destroying:"destroying",Error:"Error",Idle:"idle",New:"new",Opened:"opened",Opening:"opening",Processing:"processing",Updated:"updated",Updating:"updating"},jc={None:"none",Blur:"blur",Overlay:"overlay"},Wc={WebGL:"webgl",WebGPU:"webgpu"},C={ContextCreationError:"ContextCreationError",ContextLost:"ContextLost",ContextRestored:"ContextRestored",Error:"Error",ProcessorRestarted:"ProcessorRestarted",SamplingError:"SamplingError"};var K2=e=>!!(typeof e=="string"&&Object.values(C).includes(e)),Sn=e=>K2(e)?e:C.Error,Cn=e=>e instanceof Error?e.message:String(e),Ln=e=>{let t=new Set(Object.keys(e));return r=>{for(let n in r)t.has(n)&&typeof e[n]==typeof r[n]&&(e[n]=r[n])}},Xc=e=>{let t=new Map(e),r=new Set,n=async a=>{let c=await(await fetch(a)).blob();return await createImageBitmap(c)},o=async a=>{let i=t.get(a);if(!i){if(r.has(a))return null;r.add(a);let c=await n(a);return t.set(a,c),r.delete(a),c}return i},s=a=>(t.get(a)?.close(),t.delete(a));return{tryFetchingImage:o,setImage:(a,i)=>{t.has(a)&&s(a),t.set(a,i)},getImage:a=>t.get(a)??null,removeImage:s,clear:()=>{for(let a of t.values())a.close();t.clear()}}},In=(e,t)=>r=>Math.min(Math.max(r,e),t);var Hc=(e,t,r,n)=>{if(!e||!t||!r||!n||e*n===r*t)return{sx:0,sy:0,sw:e,sh:t,dx:0,dy:0,dw:r,dh:n};let o=e/t,s=r/n;if(o>s){let l=Math.ceil(e*s)/o,h=Math.abs(e-l);return{sx:Math.ceil(h/2),sy:0,sw:l,sh:t,dx:0,dy:0,dw:r,dh:n}}let a=Math.ceil(t*o)/s,i=Math.abs(t-a);return{sx:0,sy:Math.ceil(i/2),sw:e,sh:a,dx:0,dy:0,dw:r,dh:n}},or=e=>{let t={};return new Proxy(t,{get(r,n,o){return r[n]||(r[n]=e[n]?.(t)),Reflect.get(r,n,o)}})},Yc=(e,t,r)=>{let n=a=>{a.preventDefault(),r?.(),t.contextLost(a.statusMessage)},o=a=>{t.contextRestored(a.statusMessage)},s=a=>{t.contextCreationError(a.statusMessage)};return e.addEventListener("webglcontextlost",n),e.addEventListener("webglcontextrestored",o),e.addEventListener("webglcontextcreationerror",s),()=>{e.removeEventListener("webglcontextlost",n),e.removeEventListener("webglcontextrestored",o),e.removeEventListener("webglcontextcreationerror",s)}};var zc=(e,t,r)=>{let n=navigator.gpu.getPreferredCanvasFormat(),o=e.getContext("webgpu");if(!o)throw Error("WebGPU not supported on the canvas.");o.configure({device:t,format:n});let s;return{render:a=>(_(!r(),C.ContextLost),s=t.createTexture({label:"Video Frame to Texture",format:"rgba8unorm",size:[a.width,a.height],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC|GPUTextureUsage.RENDER_ATTACHMENT}),t.queue.copyExternalImageToTexture({source:a.frame,flipY:!1},{texture:s},{width:a.width,height:a.height}),t.queue.submit([]),s),release:()=>{s?.destroy()}}};var Ts="@group(0)@binding(0)var mySampler:sampler;@group(0)@binding(1)var bgTexture:texture_2d<f32>;@group(0)@binding(2)var personTexture:texture_2d<f32>;@group(0)@binding(3)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,mySampler,fragUV);let person=textureSample(personTexture,mySampler,fragUV);let mask=textureSample(maskTexture,mySampler,fragUV);var alpha=mask.r;if(alpha<0.5){alpha=0;}return mix(bg,person,alpha);}";var sr=[0,0,0,0];var Kc=(e,t,r,n)=>{let o=e.getContext("webgpu");if(!o)throw Error("WebGPU not supported on the canvas.");return o.configure({device:t,format:r,alphaMode:"premultiplied"}),{render:(s,a,i)=>{_(!n(),C.ContextLost);let c=t.createRenderPipeline({label:"blender pipeline",layout:"auto",vertex:{module:t.createShaderModule({label:"blender vertex",code:Ts})},fragment:{module:t.createShaderModule({label:"blender fragment",code:Ts}),targets:[{format:r}]}}),l=t.createCommandEncoder({label:"blender encoder"}),h=l.beginRenderPass({label:"blender renderPass",colorAttachments:[{view:o.getCurrentTexture().createView(),clearValue:sr,loadOp:"clear",storeOp:"store"}]});h.setPipeline(c);let p=t.createSampler({addressModeU:"repeat",addressModeV:"repeat",magFilter:"nearest"}),d=t.createBindGroup({layout:c.getBindGroupLayout(0),entries:[{binding:0,resource:p},{binding:1,resource:a.createView()},{binding:2,resource:s.createView()},{binding:3,resource:i.createView()}]});h.setBindGroup(0,d),h.draw(6),h.end();let g=l.finish();t.queue.submit([g])},release:()=>{}}};var _s=e=>e.features.has("bgra8unorm-storage"),$c=async e=>await e?.requestDevice({requiredFeatures:_s(e)?["bgra8unorm-storage"]:[]});var qc="@group(0)@binding(0)var u_sampler:sampler;@group(0)@binding(1)var u_frame:texture_2d<f32>;@group(0)@binding(2)var<uniform> flip:Flip;struct Flip{value:u32,}struct VertexOutput{@builtin(position)Position:vec4f,@location(0)fragUV:vec2f,}fn Downsample(uv:vec2<f32>,halfpixel:vec2<f32>)->vec4<f32>{var sum=textureSample(u_frame,u_sampler,uv)*4.0;sum+=textureSample(u_frame,u_sampler,vec2(uv.x+halfpixel.x,uv.y+halfpixel.y));sum+=textureSample(u_frame,u_sampler,vec2(uv.x+halfpixel.x,uv.y-halfpixel.y));sum+=textureSample(u_frame,u_sampler,vec2(uv.x-halfpixel.x,uv.y-halfpixel.y));sum+=textureSample(u_frame,u_sampler,vec2(uv.x-halfpixel.x,uv.y+halfpixel.y));return sum/8.0;}fn Upsample(uv:vec2<f32>,halfpixel:vec2<f32>)->vec4<f32>{var sum=textureSample(u_frame,u_sampler,vec2(uv.x-halfpixel.x*2.0,uv.y));sum+=textureSample(u_frame,u_sampler,vec2(uv.x+halfpixel.x*2.0,uv.y));sum+=textureSample(u_frame,u_sampler,vec2(uv.x,uv.y+halfpixel.y*2.0));sum+=textureSample(u_frame,u_sampler,vec2(uv.x,uv.y-halfpixel.y*2.0));sum+=textureSample(u_frame,u_sampler,vec2(uv.x-halfpixel.x,uv.y+halfpixel.y))*2.0;sum+=textureSample(u_frame,u_sampler,vec2(uv.x+halfpixel.x,uv.y+halfpixel.y))*2.0;sum+=textureSample(u_frame,u_sampler,vec2(uv.x+halfpixel.x,uv.y-halfpixel.y))*2.0;sum+=textureSample(u_frame,u_sampler,vec2(uv.x-halfpixel.x,uv.y-halfpixel.y))*2.0;return sum/12.0;}@fragment fn frag_main(@location(0)v_texCoord:vec2<f32>)->@location(0)vec4<f32>{let texSize=vec2<f32>(textureDimensions(u_frame));let texel_size=1.0/texSize;let halfpixel=texel_size*0.5;var color:vec4<f32>;if(flip.value!=1u){color=Downsample(v_texCoord,halfpixel);}else{color=Upsample(v_texCoord,halfpixel);}return color;}@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;}";var $2=In(1,9),Jc=(e,t,r,n)=>{let o=e.getContext("webgpu");if(!o)throw Error("WebGPU not supported on the canvas.");o.configure({device:t,format:r,alphaMode:"premultiplied"});let s=(S,w)=>t.createTexture({format:r,size:[S,w],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT}),a=S=>{let w=t.createBuffer({size:4,mappedAtCreation:!0,usage:GPUBufferUsage.UNIFORM});return new Uint32Array(w.getMappedRange())[0]=S,w.unmap(),w},i=t.createSampler({magFilter:"linear",minFilter:"linear"}),c=t.createShaderModule({code:qc}),l=t.createRenderPipeline({label:"dual blur render pipeline",layout:"auto",vertex:{module:c,entryPoint:"vert_main",buffers:[]},fragment:{module:c,entryPoint:"frag_main",targets:[{format:r}]},primitive:{topology:"triangle-list"}}),h=[],p=-1,d=-1;function g(S,w,f){let y=$2(S+1),b=!1;if(h.length!==y||p!==w||d!==f){for(let L of h)L.texture.destroy();h=[];for(let L=0;L<y;L++){let I=Math.max(Math.trunc(w/2**L),1),k=Math.max(Math.trunc(f/2**L),1);h.push({texture:s(I,k),width:I,height:k})}p=w,d=f,b=!0}return b}let A=a(0),R=a(1);return{render:(S,w)=>{_(!n(),C.ContextLost),g(w,e.width,e.height);let f=h[0];_(f),t.queue.copyExternalImageToTexture({source:S.frame,flipY:!1},{texture:f.texture},{width:f.width,height:f.height});for(let k=1;k<h.length;k++){let B=h[k-1];_(B);let U=h[k];_(U);let j=t.createBindGroup({layout:l.getBindGroupLayout(0),entries:[{binding:0,resource:i},{binding:1,resource:B.texture.createView()},{binding:2,resource:{buffer:A}}]}),W=t.createCommandEncoder(),le=W.beginRenderPass({colorAttachments:[{view:U.texture.createView(),loadOp:"clear",storeOp:"store",clearValue:sr}]});le.setPipeline(l),le.setBindGroup(0,j),le.draw(6),le.end(),t.queue.submit([W.finish()])}for(let k=h.length-2;k>=0;k--){let B=h[k+1];_(B);let U=h[k];_(U);let j=t.createBindGroup({layout:l.getBindGroupLayout(0),entries:[{binding:0,resource:i},{binding:1,resource:B.texture.createView()},{binding:2,resource:{buffer:R}}]}),W=t.createCommandEncoder(),le=W.beginRenderPass({colorAttachments:[{view:U.texture.createView(),loadOp:"clear",storeOp:"store",clearValue:sr}]});le.setPipeline(l),le.setBindGroup(0,j),le.draw(6),le.end(),t.queue.submit([W.finish()])}let y=h[0];_(y);let b=t.createBindGroup({layout:l.getBindGroupLayout(0),entries:[{binding:0,resource:i},{binding:1,resource:y.texture.createView()},{binding:2,resource:{buffer:R}}]}),L=t.createCommandEncoder(),I=L.beginRenderPass({colorAttachments:[{view:o.getCurrentTexture().createView(),loadOp:"clear",storeOp:"store",clearValue:sr}]});return I.setPipeline(l),I.setBindGroup(0,b),I.draw(6),I.end(),t.queue.submit([L.finish()]),y.texture},release:()=>{for(let S of h)S.texture.destroy();h=[],A.destroy(),R.destroy()}}};var Qc="@group(0)@binding(1)var mask:texture_2d<f32>;@group(0)@binding(2)var prevMask:texture_2d<f32>;@group(0)@binding(3)var outputTex:texture_storage_2d<rgba8unorm,write>;struct Params{maskCombineRatio:f32,foregroundThreshold:f32,}@group(0)@binding(4)var<uniform> params:Params;fn smoothingMask(prevMask:texture_2d<f32>,mask:texture_2d<f32>,uv:vec2<u32>,ratio:f32)->f32{let prevMaskValue=textureLoad(prevMask,uv,0u).r;let currMaskValue=textureLoad(mask,uv,0u).r;let c1=5.68842;let c2=-0.748699;let c3=-57.8051;let c4=291.309;let c5=-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*ratio);}@compute @workgroup_size(32,1,1)fn main(@builtin(workgroup_id)WorkGroupID:vec3u,@builtin(local_invocation_id)LocalInvocationID:vec3u){let blockDim:u32=128;let baseIndex=vec2i(WorkGroupID.xy*vec2(blockDim,4)+LocalInvocationID.xy*vec2(4,1));for(var r=0;r<4;r++){for(var c=0;c<4;c++){var uv=baseIndex+vec2(c,r);let maskAlpha=smoothingMask(prevMask,mask,vec2<u32>(uv),params.maskCombineRatio);var backgroundMask=maskAlpha;if backgroundMask<params.foregroundThreshold{backgroundMask=0.0;}textureStore(outputTex,uv,vec4<f32>(backgroundMask,backgroundMask,backgroundMask,backgroundMask));}}}";var Zc=(e,t,r)=>{let n=t.createTexture({label:"Smoothed Mask Texture",format:"rgba8unorm",size:[e.width,e.height],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC}),o=t.createBuffer({size:2*4,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),s=a=>{t.queue.writeBuffer(o,0,new Float32Array([a.maskCombineRatio,a.foregroundThreshold]))};return{render:(a,i,c)=>{if(_(!r(),C.ContextLost),!i)return a;let l=t.createComputePipeline({label:"smoothing mask pipeline",layout:"auto",compute:{module:t.createShaderModule({label:"smoothing mask compute",code:Qc})}});s(c);let h=t.createBindGroup({layout:l.getBindGroupLayout(0),entries:[{binding:1,resource:a.createView()},{binding:2,resource:i.createView()},{binding:3,resource:n.createView()},{binding:4,resource:{buffer:o}}]}),p=t.createCommandEncoder({label:"smoothing mask encoder"}),d=p.beginComputePass({label:" smoothing mask compute pass"});d.setPipeline(l),d.setBindGroup(0,h),d.dispatchWorkgroups(Math.ceil(e.width/128),Math.ceil(e.height/4)),d.end();let g=p.finish();return t.queue.submit([g]),n},release:()=>{n.destroy(),o.destroy()}}};var eu=(e,t)=>{let r;return{render:n=>{_(!t(),C.ContextLost);let o=e.createCommandEncoder({label:"texture to texture encoder"});return r=e.createTexture({size:{width:n.width,height:n.height,depthOrArrayLayers:n.depthOrArrayLayers},format:"rgba8unorm",usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST}),o.copyTextureToTexture({texture:n},{texture:r},{width:r.width,height:r.height,depthOrArrayLayers:r.depthOrArrayLayers}),e.queue.submit([o.finish()]),r},release:()=>{r?.destroy()}}};var tu=(e,t,r=new OffscreenCanvas(768,432))=>{let n={videoFrameRenderer:()=>{if(!s.device)throw new Error("No device.");return zc(r,s.device,h)},backgroundImageRenderer:()=>{if(!s.device)throw new Error("No device.");return Kc(r,s.device,s.presentationFormat,h)},blurRenderer:()=>{if(!s.device)throw new Error("No device.");return Jc(r,s.device,s.presentationFormat,h)},maskSmoothingRenderer:()=>{if(!s.device)throw new Error("No device.");return Zc(r,s.device,h)},prevMaskRenderer:()=>{if(!s.device)throw new Error("No device.");return eu(s.device,h)},release:p=>()=>{for(let d of Object.keys(p))d!=="release"&&p[d]?.release()}},o=or(n),s={canvas:r,presentationFormat:"rgba8unorm",backend:"webgpu",deviceLost:!1,get videoFrameRenderer(){return o.videoFrameRenderer},get blendRenderer(){return o.backgroundImageRenderer},get blurRenderer(){return o.blurRenderer},get maskSmoothingRenderer(){return o.maskSmoothingRenderer},get prevMaskRenderer(){return o.prevMaskRenderer}},a=Ln(s),i=async()=>{if(!navigator.gpu)throw Error("WebGPU not supported.");s.presentationFormat=_s(e)?navigator.gpu.getPreferredCanvasFormat():"rgba8unorm",s.device=await $c(e),s.device.lost.then(p=>{p.reason!=="destroyed"&&(s.deviceLost=!0,t.contextLost(p.message),t.contextRestored(p.message))})},c=(p,d,g)=>{g&&a(g);let A=s.videoFrameRenderer.render(d),R=s.videoFrameRenderer.render({frame:p,width:d.width,height:d.height,timestamp:d.timestamp}),S=s.maskSmoothingRenderer.render(R,s.prevMask,g);if(g.effects==="blur"){let w=s.blurRenderer.render(d,g.backgroundBlurAmount);s.blendRenderer.render(A,w,S)}else if(g.effects==="overlay"&&g.backgroundImage){let w=s.videoFrameRenderer.render({frame:g.backgroundImage,width:g.backgroundImage.width,height:g.backgroundImage.height,timestamp:d.timestamp});s.blendRenderer.render(A,w,S)}s.prevMask=s.prevMaskRenderer.render(S)},l=()=>{o.release(),s.deviceLost=!1,o=or(n)},h=()=>s.deviceLost;return{init:i,render:c,release:l,isContextLost:h}};var ue={projection:(e,t,r=-1)=>[2/e,0,0,0,2/t*r,0,-1,1*-r,1],translation:(e,t)=>[1,0,0,0,1,0,e,t,1],rotation:e=>{let t=Math.cos(e),r=Math.sin(e);return[t,-r,0,r,t,0,0,0,1]},scaling:(e,t)=>[e,0,0,0,t,0,0,0,1],multiply:(e,t)=>{let r=e[0],n=e[0*3+1],o=e[0*3+2],s=e[1*3+0],a=e[1*3+1],i=e[1*3+2],c=e[2*3+0],l=e[2*3+1],h=e[2*3+2],p=t[0*3+0],d=t[0*3+1],g=t[0*3+2],A=t[1*3+0],R=t[1*3+1],S=t[1*3+2],w=t[2*3+0],f=t[2*3+1],y=t[2*3+2];return[p*r+d*s+g*c,p*n+d*a+g*l,p*o+d*i+g*h,A*r+R*s+S*c,A*n+R*a+S*l,A*o+R*i+S*h,w*r+f*s+y*c,w*n+f*a+y*l,w*o+f*i+y*h]},translate:(e,t,r)=>ue.multiply(e,ue.translation(t,r)),rotate:(e,t)=>ue.multiply(e,ue.rotation(t)),scale:(e,t,r)=>ue.multiply(e,ue.scaling(t,r))};var Mn={VertexShader:WebGLRenderingContext.VERTEX_SHADER,FragmentShader:WebGLRenderingContext.FRAGMENT_SHADER},As={[Mn.VertexShader]:"VertexShader",[Mn.FragmentShader]:"FragmentShader"},q2=e=>typeof e=="string"?e.startsWith("#version 300 es"):!1,ru=e=>{if(!q2(e))throw new Error("Expecting GLSL ES 3.00 shader source")},J2=/ERROR:\s*\d+:(\d+)/gi;function su(e,t="",r=0){let n=[...t.matchAll(J2)],o=new Map(n.map((s,a)=>{if(!s[1]||s.index===void 0)return[0,t];let i=Number.parseInt(s[1],10),c=n[a+1],l=c?c.index:t.length,h=t.substring(s.index,l);return[i-1,h]}));return e.split(`
|
|
42
|
-
`).
|
|
41
|
+
`}C(){let t=this.g;t.activeTexture(t.TEXTURE1),this.j=br(this,t),t.activeTexture(t.TEXTURE2),this.B=br(this,t)}m(){super.m();let t=this.g;this.K=Ye(t.getUniformLocation(this.h,"defaultTexture"),"Uniform location"),this.L=Ye(t.getUniformLocation(this.h,"overlayTexture"),"Uniform location"),this.I=Ye(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 er(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 ga(t){var e=er(t,1);if(!e){if(e=er(t,0))e=new Float32Array(e).map(n=>n/255);else{e=new Float32Array(t.width*t.height);let n=Zr(t);var r=xi(t);if(eo(r,n,Tf(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 Tf(t){let e=er(t,2);if(!e){let r=Zr(t);e=Ef(t);let n=ga(t),s=kf(t);r.texImage2D(r.TEXTURE_2D,0,s,t.width,t.height,0,r.RED,r.FLOAT,n),xa(t)}return e}function Zr(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=Ye(t.canvas.getContext("webgl2"),"You cannot use a canvas that is already bound to a different type of rendering context.")),t.h}function kf(t){if(t=Zr(t),!hs)if(t.getExtension("EXT_color_buffer_float")&&t.getExtension("OES_texture_float_linear")&&t.getExtension("EXT_float_blend"))hs=t.R32F;else{if(!t.getExtension("EXT_color_buffer_half_float"))throw Error("GPU does not fully support 4-channel float32 or float16 formats");hs=t.R16F}return hs}function xi(t){return t.l||(t.l=new ln),t.l}function Ef(t){let e=Zr(t);e.viewport(0,0,t.width,t.height),e.activeTexture(e.TEXTURE0);let r=er(t,2);return r||(r=br(xi(t),e,t.m?e.LINEAR:e.NEAREST),t.g.push(r),t.j=!0),e.bindTexture(e.TEXTURE_2D,r),r}function xa(t){t.h.bindTexture(t.h.TEXTURE_2D,null)}var hs,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&&--gc===0&&console.error("You seem to be creating MPMask instances without invoking .close(). This leaks resources.")}Ga(){return!!er(this,0)}ka(){return!!er(this,1)}R(){return!!er(this,2)}ja(){return(e=er(t=this,0))||(e=ga(t),e=new Uint8Array(e.map(r=>255*r)),t.g.push(e)),e;var t,e}ia(){return ga(this)}N(){return Tf(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=Zr(this),s=xi(this);n.activeTexture(n.TEXTURE1),r=br(s,n,this.m?n.LINEAR:n.NEAREST),n.bindTexture(n.TEXTURE_2D,r);let o=kf(this);n.texImage2D(n.TEXTURE_2D,0,o,this.width,this.height,0,n.RED,n.FLOAT,null),n.bindTexture(n.TEXTURE_2D,null),eo(s,n,r),Yn(s,n,!1,()=>{Ef(this),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.drawArrays(n.TRIANGLE_FAN,0,4),xa(this)}),gi(s),xa(this)}}t.push(r)}return new Pe(t,this.m,this.R(),this.canvas,this.l,this.width,this.height)}close(){this.j&&Zr(this).deleteTexture(er(this,2)),gc=-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 gc=250,lm={color:"white",lineWidth:4,radius:6};function Qo(t){return{...lm,fillColor:(t=t||{}).color,...t}}function Jt(t,e){return t instanceof Function?t(e):t}function xc(t,e,r){return Math.max(Math.min(e,r),Math.min(Math.max(e,r),t))}function Fn(t){if(!t.l)throw Error("CPU rendering requested but CanvasRenderingContext2D not provided.");return t.l}function Wn(t){if(!t.j)throw Error("GPU rendering requested but WebGL2RenderingContext not provided.");return t.j}function yc(t,e,r){if(e.R())r(e.N());else{let n=e.ka()?e.ia():e.ja();t.m=t.m??new ln;let s=Wn(t);r((t=new Pe([n],e.m,!1,s.canvas,t.m,e.width,e.height)).N()),t.close()}}function _c(t,e,r,n){let s=function(i){return i.g||(i.g=new um),i.g}(t),o=Wn(t),a=Array.isArray(r)?new ImageData(new Uint8ClampedArray(r),1,1):r;Yn(s,o,!0,()=>{(function(u,l,c,f){let m=u.g;if(m.activeTexture(m.TEXTURE0),m.bindTexture(m.TEXTURE_2D,l),m.activeTexture(m.TEXTURE1),m.bindTexture(m.TEXTURE_2D,u.B),m.texImage2D(m.TEXTURE_2D,0,m.RGBA,m.RGBA,m.UNSIGNED_BYTE,c),u.I&&function(p,w){if(p!==w)return!1;p=p.entries(),w=w.entries();for(let[v,C]of p){p=v;let k=C;var A=w.next();if(A.done)return!1;let[T,S]=A.value;if(A=S,p!==T||k[0]!==A[0]||k[1]!==A[1]||k[2]!==A[2]||k[3]!==A[3])return!1}return!!w.next().done}(u.I,f))m.activeTexture(m.TEXTURE2),m.bindTexture(m.TEXTURE_2D,u.j);else{u.I=f;let p=Array(1024).fill(0);f.forEach((w,A)=>{if(w.length!==4)throw Error(`Color at index ${A} is not a four-channel value.`);p[4*A]=w[0],p[4*A+1]=w[1],p[4*A+2]=w[2],p[4*A+3]=w[3]}),m.activeTexture(m.TEXTURE2),m.bindTexture(m.TEXTURE_2D,u.j),m.texImage2D(m.TEXTURE_2D,0,m.RGBA,256,1,0,m.RGBA,m.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 bc(t,e,r,n){let s=Wn(t),o=function(u){return u.h||(u.h=new cm),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;Yn(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=Fn(this);e=Qo(e),r.save();var n=r.canvas,s=0;for(let o of t)r.fillStyle=Jt(e.fillColor,{index:s,from:o}),r.strokeStyle=Jt(e.color,{index:s,from:o}),r.lineWidth=Jt(e.lineWidth,{index:s,from:o}),(t=new Path2D).arc(o.x*n.width,o.y*n.height,Jt(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=Fn(this);r=Qo(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=Jt(r.color,{index:o,from:e,to:i}),n.lineWidth=Jt(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=Fn(this);e=Qo(e),r.save(),r.beginPath(),r.lineWidth=Jt(e.lineWidth,{}),r.strokeStyle=Jt(e.color,{}),r.fillStyle=Jt(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=Wn(n);yc(n,s,u=>{_c(n,u,o,a),(u=Fn(n)).drawImage(i.canvas,0,0,u.canvas.width,u.canvas.height)})}(this,t,r,e):_c(this,t.N(),r,e)}xa(t,e,r){this.l?function(n,s,o,a){let i=Wn(n);yc(n,s,u=>{bc(n,u,o,a),(u=Fn(n)).drawImage(i.canvas,0,0,u.canvas.width,u.canvas.height)})}(this,t,e,r):bc(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 Ht(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 Af(t){var e=Ht(t,0);if(!e){e=Jr(t);let r=to(t),n=new Uint8Array(t.width*t.height*4);eo(r,e,ys(t)),e.readPixels(0,0,t.width,t.height,e.RGBA,e.UNSIGNED_BYTE,n),gi(r),e=new ImageData(new Uint8ClampedArray(n.buffer),t.width,t.height),t.g.push(e)}return e}function ys(t){let e=Ht(t,2);if(!e){let r=Jr(t);e=_s(t);let n=Ht(t,1)||Af(t);r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,n),Un(t)}return e}function Jr(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=Ye(t.canvas.getContext("webgl2"),"You cannot use a canvas that is already bound to a different type of rendering context.")),t.h}function to(t){return t.l||(t.l=new ln),t.l}function _s(t){let e=Jr(t);e.viewport(0,0,t.width,t.height),e.activeTexture(e.TEXTURE0);let r=Ht(t,2);return r||(r=br(to(t),e),t.g.push(r),t.m=!0),e.bindTexture(e.TEXTURE_2D,r),r}function Un(t){t.h.bindTexture(t.h.TEXTURE_2D,null)}function vc(t){let e=Jr(t);return Yn(to(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 xc(n*(1-(t-e)/(r-e))+s*(1-(r-t)/(r-e)),n,s)},je.clamp=xc,Nc("DrawingUtils",je);var Me=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)&&--wc===0&&console.error("You seem to be creating MPImage instances without invoking .close(). This leaks resources.")}Fa(){return!!Ht(this,0)}la(){return!!Ht(this,1)}R(){return!!Ht(this,2)}Da(){return Af(this)}Ca(){var t=Ht(this,1);return t||(ys(this),_s(this),t=vc(this),Un(this),this.g.push(t),this.j=!0),t}N(){return ys(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=Jr(this),s=to(this);n.activeTexture(n.TEXTURE1),r=br(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),eo(s,n,r),Yn(s,n,!1,()=>{_s(this),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.drawArrays(n.TRIANGLE_FAN,0,4),Un(this)}),gi(s),Un(this)}else{if(!(e instanceof ImageBitmap))throw Error(`Type is not supported: ${e}`);ys(this),_s(this),r=vc(this),Un(this)}t.push(r)}return new Me(t,this.la(),this.R(),this.canvas,this.l,this.width,this.height)}close(){this.j&&Ht(this,1).close(),this.m&&Jr(this).deleteTexture(Ht(this,2)),wc=-1}};Me.prototype.close=Me.prototype.close,Me.prototype.clone=Me.prototype.clone,Me.prototype.getAsWebGLTexture=Me.prototype.N,Me.prototype.getAsImageBitmap=Me.prototype.Ca,Me.prototype.getAsImageData=Me.prototype.Da,Me.prototype.hasWebGLTexture=Me.prototype.R,Me.prototype.hasImageBitmap=Me.prototype.la,Me.prototype.hasImageData=Me.prototype.Fa;var wc=250;function Dt(...t){return t.map(([e,r])=>({start:e,end:r}))}var fm=function(t){return class extends t{La(){this.i._registerModelResourcesGraphService()}}}((Tc=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:vf()?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?'),W(this,n||"input_audio",o=>{W(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){Wt(this,"__graph_config__",e=>{t(e)}),W(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),W(this,n,a=>{this.i._addAudioToInputStream(this.g,e,r,a,s)})}addGpuBufferToStream(t,e,r){W(this,e,n=>{let[s,o]=fc(this,t,n);this.i._addBoundTextureToStream(n,s,o,r)})}addBoolToStream(t,e,r){W(this,e,n=>{this.i._addBoolToInputStream(t,n,r)})}addDoubleToStream(t,e,r){W(this,e,n=>{this.i._addDoubleToInputStream(t,n,r)})}addFloatToStream(t,e,r){W(this,e,n=>{this.i._addFloatToInputStream(t,n,r)})}addIntToStream(t,e,r){W(this,e,n=>{this.i._addIntToInputStream(t,n,r)})}addUintToStream(t,e,r){W(this,e,n=>{this.i._addUintToInputStream(t,n,r)})}addStringToStream(t,e,r){W(this,e,n=>{W(this,t,s=>{this.i._addStringToInputStream(s,n,r)})})}addStringRecordToStream(t,e,r){W(this,e,n=>{hc(this,Object.keys(t),s=>{hc(this,Object.values(t),o=>{this.i._addFlatHashMapToInputStream(s,o,Object.keys(t).length,n,r)})})})}addProtoToStream(t,e,r,n){W(this,r,s=>{W(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){W(this,t,r=>{this.i._addEmptyPacketToInputStream(r,e)})}addBoolVectorToStream(t,e,r){W(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){W(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){W(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){W(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){W(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){W(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)W(this,o,a=>{this.i._addStringVectorEntry(s,a)});this.i._addStringVectorToInputStream(s,n,r)})}addBoolToInputSidePacket(t,e){W(this,e,r=>{this.i._addBoolToInputSidePacket(t,r)})}addDoubleToInputSidePacket(t,e){W(this,e,r=>{this.i._addDoubleToInputSidePacket(t,r)})}addFloatToInputSidePacket(t,e){W(this,e,r=>{this.i._addFloatToInputSidePacket(t,r)})}addIntToInputSidePacket(t,e){W(this,e,r=>{this.i._addIntToInputSidePacket(t,r)})}addUintToInputSidePacket(t,e){W(this,e,r=>{this.i._addUintToInputSidePacket(t,r)})}addStringToInputSidePacket(t,e){W(this,e,r=>{W(this,t,n=>{this.i._addStringToInputSidePacket(n,r)})})}addProtoToInputSidePacket(t,e,r){W(this,r,n=>{W(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){W(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){W(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){W(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){W(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){W(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){W(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)W(this,s,o=>{this.i._addStringVectorEntry(n,o)});this.i._addStringVectorToInputSidePacket(n,r)})}attachBoolListener(t,e){Wt(this,t,e),W(this,t,r=>{this.i._attachBoolListener(r)})}attachBoolVectorListener(t,e){cr(this,t,e),W(this,t,r=>{this.i._attachBoolVectorListener(r)})}attachIntListener(t,e){Wt(this,t,e),W(this,t,r=>{this.i._attachIntListener(r)})}attachIntVectorListener(t,e){cr(this,t,e),W(this,t,r=>{this.i._attachIntVectorListener(r)})}attachUintListener(t,e){Wt(this,t,e),W(this,t,r=>{this.i._attachUintListener(r)})}attachUintVectorListener(t,e){cr(this,t,e),W(this,t,r=>{this.i._attachUintVectorListener(r)})}attachDoubleListener(t,e){Wt(this,t,e),W(this,t,r=>{this.i._attachDoubleListener(r)})}attachDoubleVectorListener(t,e){cr(this,t,e),W(this,t,r=>{this.i._attachDoubleVectorListener(r)})}attachFloatListener(t,e){Wt(this,t,e),W(this,t,r=>{this.i._attachFloatListener(r)})}attachFloatVectorListener(t,e){cr(this,t,e),W(this,t,r=>{this.i._attachFloatVectorListener(r)})}attachStringListener(t,e){Wt(this,t,e),W(this,t,r=>{this.i._attachStringListener(r)})}attachStringVectorListener(t,e){cr(this,t,e),W(this,t,r=>{this.i._attachStringVectorListener(r)})}attachProtoListener(t,e,r){Wt(this,t,e),W(this,t,n=>{this.i._attachProtoListener(n,r||!1)})}attachProtoVectorListener(t,e,r){cr(this,t,e),W(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?'),Wt(this,t,(n,s)=>{n=new Float32Array(n.buffer,n.byteOffset,n.length/4),e(n,s)}),W(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 Tc{get fa(){return this.i}ra(t,e,r){W(this,e,n=>{let[s,o]=fc(this,t,n);this.fa._addBoundTextureAsImageToStream(n,s,o,r)})}V(t,e){Wt(this,t,e),W(this,t,r=>{this.fa._attachImageListener(r)})}da(t,e){cr(this,t,e),W(this,t,r=>{this.fa._attachImageVectorListener(r)})}})),Tc,Tt=class extends fm{};async function X(t,e,r){return async function(n,s,o,a){return im(n,s,o,a)}(t,r.canvas??(vf()?void 0:document.createElement("canvas")),e,r)}function Rf(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].");G(o,1,(s.left+s.right)/2),G(o,2,(s.top+s.bottom)/2),G(o,4,s.right-s.left),G(o,3,s.bottom-s.top)}else G(o,1,.5),G(o,2,.5),G(o,4,1),G(o,3,1);if(r?.rotationDegrees){if(r?.rotationDegrees%90!=0)throw Error("Expected rotation to be a multiple of 90\xB0.");if(G(o,5,-Math.PI*r.rotationDegrees/180),r?.rotationDegrees%180!=0){let[a,i]=wf(e);r=Ae(o,3)*i/a,s=Ae(o,4)*a/i,G(o,4,r),G(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 kt(t,e,r){if(t.baseOptions?.g())throw Error("Task is not initialized with image mode. 'runningMode' must be set to 'IMAGE'.");Rf(t,e,r,t.B+1)}function Yt(t,e,r,n){if(!t.baseOptions?.g())throw Error("Task is not initialized with video mode. 'runningMode' must be set to 'VIDEO'.");Rf(t,e,r,n)}function Qr(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 xs{constructor(t,e,r,n){super(t),this.g=t,this.ba=e,this.U=r,this.qa=n,this.P=new ln}l(t,e=!0){if("runningMode"in t&&Gn(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 xt=class extends rt{constructor(t,e){super(new Tt(t,e),"image_in","norm_rect_in",!1),this.j={detections:[]},$(t=this.h=new Ks,0,1,e=new ye),G(this.h,2,.5),G(this.h,3,.3)}get baseOptions(){return Y(this.h,ye,1)}set baseOptions(t){$(this.h,0,1,t)}o(t){return"minDetectionConfidence"in t&&G(this.h,2,t.minDetectionConfidence??.5),"minSuppressionThreshold"in t&&G(this.h,3,t.minSuppressionThreshold??.3),this.l(t)}D(t,e){return this.j={detections:[]},kt(this,t,e),this.j}F(t,e,r){return this.j={detections:[]},Yt(this,t,r,e),this.j}m(){var t=new nt;ge(t,"image_in"),ge(t,"norm_rect_in"),Z(t,"detections");let e=new lt;Lt(e,jd,this.h);let r=new qe;ht(r,"mediapipe.tasks.vision.face_detector.FaceDetectorGraph"),le(r,"IMAGE:image_in"),le(r,"NORM_RECT:norm_rect_in"),j(r,"DETECTIONS:detections"),r.o(e),dt(t,r),this.g.attachProtoVectorListener("detections",(n,s)=>{for(let o of n)n=Xl(o),this.j.detections.push(_f(n));D(this,s)}),this.g.attachEmptyPacketListener("detections",n=>{D(this,n)}),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};xt.prototype.detectForVideo=xt.prototype.F,xt.prototype.detect=xt.prototype.D,xt.prototype.setOptions=xt.prototype.o,xt.createFromModelPath=async function(t,e){return X(xt,t,{baseOptions:{modelAssetPath:e}})},xt.createFromModelBuffer=function(t,e){return X(xt,t,{baseOptions:{modelAssetBuffer:e}})},xt.createFromOptions=function(t,e){return X(xt,t,e)};var yi=Dt([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]),_i=Dt([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]),bi=Dt([276,283],[283,282],[282,295],[295,285],[300,293],[293,334],[334,296],[296,336]),If=Dt([474,475],[475,476],[476,477],[477,474]),vi=Dt([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]),wi=Dt([46,53],[53,52],[52,65],[65,55],[70,63],[63,105],[105,66],[66,107]),Sf=Dt([469,470],[470,471],[471,472],[472,469]),Ti=Dt([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]),Cf=[...yi,..._i,...bi,...vi,...wi,...Ti],Ff=Dt([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 kc(t){t.j={faceLandmarks:[],faceBlendshapes:[],facialTransformationMatrixes:[]}}var we=class extends rt{constructor(t,e){super(new Tt(t,e),"image_in","norm_rect",!1),this.j={faceLandmarks:[],faceBlendshapes:[],facialTransformationMatrixes:[]},this.outputFacialTransformationMatrixes=this.outputFaceBlendshapes=!1,$(t=this.h=new ef,0,1,e=new ye),this.v=new Ql,$(this.h,0,3,this.v),this.s=new Ks,$(this.h,0,2,this.s),jt(this.s,4,1),G(this.s,2,.5),G(this.v,2,.5),G(this.h,4,.5)}get baseOptions(){return Y(this.h,ye,1)}set baseOptions(t){$(this.h,0,1,t)}o(t){return"numFaces"in t&&jt(this.s,4,t.numFaces??1),"minFaceDetectionConfidence"in t&&G(this.s,2,t.minFaceDetectionConfidence??.5),"minTrackingConfidence"in t&&G(this.h,4,t.minTrackingConfidence??.5),"minFacePresenceConfidence"in t&&G(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 kc(this),kt(this,t,e),this.j}F(t,e,r){return kc(this),Yt(this,t,r,e),this.j}m(){var t=new nt;ge(t,"image_in"),ge(t,"norm_rect"),Z(t,"face_landmarks");let e=new lt;Lt(e,qd,this.h);let r=new qe;ht(r,"mediapipe.tasks.vision.face_landmarker.FaceLandmarkerGraph"),le(r,"IMAGE:image_in"),le(r,"NORM_RECT:norm_rect"),j(r,"NORM_LANDMARKS:face_landmarks"),r.o(e),dt(t,r),this.g.attachProtoVectorListener("face_landmarks",(n,s)=>{for(let o of n)n=jn(o),this.j.faceLandmarks.push(Zs(n));D(this,s)}),this.g.attachEmptyPacketListener("face_landmarks",n=>{D(this,n)}),this.outputFaceBlendshapes&&(Z(t,"blendshapes"),j(r,"BLENDSHAPES:blendshapes"),this.g.attachProtoVectorListener("blendshapes",(n,s)=>{if(this.outputFaceBlendshapes)for(let o of n)n=qs(o),this.j.faceBlendshapes.push(mi(n.g()??[]));D(this,s)}),this.g.attachEmptyPacketListener("blendshapes",n=>{D(this,n)})),this.outputFacialTransformationMatrixes&&(Z(t,"face_geometry"),j(r,"FACE_GEOMETRY:face_geometry"),this.g.attachProtoVectorListener("face_geometry",(n,s)=>{if(this.outputFacialTransformationMatrixes)for(let o of n)(n=Y(Yd(o),Nd,2))&&this.j.facialTransformationMatrixes.push({rows:Bt(vt(n,1),0)??0,columns:Bt(vt(n,2),0)??0,data:Sr(n,3,wr,Ir()).slice()??[]});D(this,s)}),this.g.attachEmptyPacketListener("face_geometry",n=>{D(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=yi,we.FACE_LANDMARKS_LEFT_EYE=_i,we.FACE_LANDMARKS_LEFT_EYEBROW=bi,we.FACE_LANDMARKS_LEFT_IRIS=If,we.FACE_LANDMARKS_RIGHT_EYE=vi,we.FACE_LANDMARKS_RIGHT_EYEBROW=wi,we.FACE_LANDMARKS_RIGHT_IRIS=Sf,we.FACE_LANDMARKS_FACE_OVAL=Ti,we.FACE_LANDMARKS_CONTOURS=Cf,we.FACE_LANDMARKS_TESSELATION=Ff;var $t=class extends rt{constructor(t,e){super(new Tt(t,e),"image_in","norm_rect",!0),$(t=this.j=new rf,0,1,e=new ye)}get baseOptions(){return Y(this.j,ye,1)}set baseOptions(t){$(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,kt(this,t,n??{}),!this.h)return this.s}m(){var t=new nt;ge(t,"image_in"),ge(t,"norm_rect"),Z(t,"stylized_image");let e=new lt;Lt(e,Kd,this.j);let r=new qe;ht(r,"mediapipe.tasks.vision.face_stylizer.FaceStylizerGraph"),le(r,"IMAGE:image_in"),le(r,"NORM_RECT:norm_rect"),j(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 Me([a],!1,!1,this.g.i.canvas,this.P,i,n),this.s=o=o?i.clone():i,this.h&&this.h(o),D(this,s)}),this.g.attachEmptyPacketListener("stylized_image",n=>{this.s=null,this.h&&this.h(null),D(this,n)}),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};$t.prototype.stylize=$t.prototype.Oa,$t.prototype.setOptions=$t.prototype.o,$t.createFromModelPath=function(t,e){return X($t,t,{baseOptions:{modelAssetPath:e}})},$t.createFromModelBuffer=function(t,e){return X($t,t,{baseOptions:{modelAssetBuffer:e}})},$t.createFromOptions=function(t,e){return X($t,t,e)};var ki=Dt([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 Ec(t){t.gestures=[],t.landmarks=[],t.worldLandmarks=[],t.handedness=[]}function Ac(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 Rc(t,e=!0){let r=[];for(let s of t){var n=qs(s);t=[];for(let o of n.g())n=e&&vt(o,1)!=null?Bt(vt(o,1),0):-1,t.push({score:Ae(o,2)??0,index:n,categoryName:Xt(o,3)??"",displayName:Xt(o,4)??""});r.push(t)}return r}var ot=class extends rt{constructor(t,e){super(new Tt(t,e),"image_in","norm_rect",!1),this.gestures=[],this.landmarks=[],this.worldLandmarks=[],this.handedness=[],$(t=this.j=new of,0,1,e=new ye),this.s=new li,$(this.j,0,2,this.s),this.C=new ci,$(this.s,0,3,this.C),this.v=new sf,$(this.s,0,2,this.v),this.h=new Zd,$(this.j,0,3,this.h),G(this.v,2,.5),G(this.s,4,.5),G(this.C,2,.5)}get baseOptions(){return Y(this.j,ye,1)}set baseOptions(t){$(this.j,0,1,t)}o(t){if(jt(this.v,3,t.numHands??1),"minHandDetectionConfidence"in t&&G(this.v,2,t.minHandDetectionConfidence??.5),"minTrackingConfidence"in t&&G(this.s,4,t.minTrackingConfidence??.5),"minHandPresenceConfidence"in t&&G(this.C,2,t.minHandPresenceConfidence??.5),t.cannedGesturesClassifierOptions){var e=new Gr,r=e,n=ma(t.cannedGesturesClassifierOptions,Y(this.h,Gr,3)?.h());$(r,0,2,n),$(this.h,0,3,e)}else t.cannedGesturesClassifierOptions===void 0&&Y(this.h,Gr,3)?.g();return t.customGesturesClassifierOptions?($(r=e=new Gr,0,2,n=ma(t.customGesturesClassifierOptions,Y(this.h,Gr,4)?.h())),$(this.h,0,4,e)):t.customGesturesClassifierOptions===void 0&&Y(this.h,Gr,4)?.g(),this.l(t)}Ja(t,e){return Ec(this),kt(this,t,e),Ac(this)}Ka(t,e,r){return Ec(this),Yt(this,t,r,e),Ac(this)}m(){var t=new nt;ge(t,"image_in"),ge(t,"norm_rect"),Z(t,"hand_gestures"),Z(t,"hand_landmarks"),Z(t,"world_hand_landmarks"),Z(t,"handedness");let e=new lt;Lt(e,Jd,this.j);let r=new qe;ht(r,"mediapipe.tasks.vision.gesture_recognizer.GestureRecognizerGraph"),le(r,"IMAGE:image_in"),le(r,"NORM_RECT:norm_rect"),j(r,"HAND_GESTURES:hand_gestures"),j(r,"LANDMARKS:hand_landmarks"),j(r,"WORLD_LANDMARKS:world_hand_landmarks"),j(r,"HANDEDNESS:handedness"),r.o(e),dt(t,r),this.g.attachProtoVectorListener("hand_landmarks",(n,s)=>{for(let o of n){n=jn(o);let a=[];for(let i of nr(n,Yl,1))a.push({x:Ae(i,1)??0,y:Ae(i,2)??0,z:Ae(i,3)??0,visibility:Ae(i,4)??0});this.landmarks.push(a)}D(this,s)}),this.g.attachEmptyPacketListener("hand_landmarks",n=>{D(this,n)}),this.g.attachProtoVectorListener("world_hand_landmarks",(n,s)=>{for(let o of n){n=Hr(o);let a=[];for(let i of nr(n,jl,1))a.push({x:Ae(i,1)??0,y:Ae(i,2)??0,z:Ae(i,3)??0,visibility:Ae(i,4)??0});this.worldLandmarks.push(a)}D(this,s)}),this.g.attachEmptyPacketListener("world_hand_landmarks",n=>{D(this,n)}),this.g.attachProtoVectorListener("hand_gestures",(n,s)=>{this.gestures.push(...Rc(n,!1)),D(this,s)}),this.g.attachEmptyPacketListener("hand_gestures",n=>{D(this,n)}),this.g.attachProtoVectorListener("handedness",(n,s)=>{this.handedness.push(...Rc(n)),D(this,s)}),this.g.attachEmptyPacketListener("handedness",n=>{D(this,n)}),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};function Ic(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 X(ot,t,{baseOptions:{modelAssetPath:e}})},ot.createFromModelBuffer=function(t,e){return X(ot,t,{baseOptions:{modelAssetBuffer:e}})},ot.createFromOptions=function(t,e){return X(ot,t,e)},ot.HAND_CONNECTIONS=ki;var at=class extends rt{constructor(t,e){super(new Tt(t,e),"image_in","norm_rect",!1),this.landmarks=[],this.worldLandmarks=[],this.handedness=[],$(t=this.h=new li,0,1,e=new ye),this.s=new ci,$(this.h,0,3,this.s),this.j=new sf,$(this.h,0,2,this.j),jt(this.j,3,1),G(this.j,2,.5),G(this.s,2,.5),G(this.h,4,.5)}get baseOptions(){return Y(this.h,ye,1)}set baseOptions(t){$(this.h,0,1,t)}o(t){return"numHands"in t&&jt(this.j,3,t.numHands??1),"minHandDetectionConfidence"in t&&G(this.j,2,t.minHandDetectionConfidence??.5),"minTrackingConfidence"in t&&G(this.h,4,t.minTrackingConfidence??.5),"minHandPresenceConfidence"in t&&G(this.s,2,t.minHandPresenceConfidence??.5),this.l(t)}D(t,e){return this.landmarks=[],this.worldLandmarks=[],this.handedness=[],kt(this,t,e),Ic(this)}F(t,e,r){return this.landmarks=[],this.worldLandmarks=[],this.handedness=[],Yt(this,t,r,e),Ic(this)}m(){var t=new nt;ge(t,"image_in"),ge(t,"norm_rect"),Z(t,"hand_landmarks"),Z(t,"world_hand_landmarks"),Z(t,"handedness");let e=new lt;Lt(e,Qd,this.h);let r=new qe;ht(r,"mediapipe.tasks.vision.hand_landmarker.HandLandmarkerGraph"),le(r,"IMAGE:image_in"),le(r,"NORM_RECT:norm_rect"),j(r,"LANDMARKS:hand_landmarks"),j(r,"WORLD_LANDMARKS:world_hand_landmarks"),j(r,"HANDEDNESS:handedness"),r.o(e),dt(t,r),this.g.attachProtoVectorListener("hand_landmarks",(n,s)=>{for(let o of n)n=jn(o),this.landmarks.push(Zs(n));D(this,s)}),this.g.attachEmptyPacketListener("hand_landmarks",n=>{D(this,n)}),this.g.attachProtoVectorListener("world_hand_landmarks",(n,s)=>{for(let o of n)n=Hr(o),this.worldLandmarks.push(Dn(n));D(this,s)}),this.g.attachEmptyPacketListener("world_hand_landmarks",n=>{D(this,n)}),this.g.attachProtoVectorListener("handedness",(n,s)=>{var o=this.handedness,a=o.push;let i=[];for(let u of n){n=qs(u);let l=[];for(let c of n.g())l.push({score:Ae(c,2)??0,index:Bt(vt(c,1),0)??-1,categoryName:Xt(c,3)??"",displayName:Xt(c,4)??""});i.push(l)}a.call(o,...i),D(this,s)}),this.g.attachEmptyPacketListener("handedness",n=>{D(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 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)},at.HAND_CONNECTIONS=ki;var Bf=Dt([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 Sc(t){t.h={faceLandmarks:[],faceBlendshapes:[],poseLandmarks:[],poseWorldLandmarks:[],poseSegmentationMasks:[],leftHandLandmarks:[],leftHandWorldLandmarks:[],rightHandLandmarks:[],rightHandWorldLandmarks:[]}}function Cc(t){try{if(!t.C)return t.h;t.C(t.h)}finally{Qs(t)}}function ds(t,e){t=jn(t),e.push(Zs(t))}var xe=class extends rt{constructor(t,e){super(new Tt(t,e),"input_frames_image",null,!1),this.h={faceLandmarks:[],faceBlendshapes:[],poseLandmarks:[],poseWorldLandmarks:[],poseSegmentationMasks:[],leftHandLandmarks:[],leftHandWorldLandmarks:[],rightHandLandmarks:[],rightHandWorldLandmarks:[]},this.outputPoseSegmentationMasks=this.outputFaceBlendshapes=!1,$(t=this.j=new ff,0,1,e=new ye),this.K=new ci,$(this.j,0,2,this.K),this.aa=new em,$(this.j,0,3,this.aa),this.s=new Ks,$(this.j,0,4,this.s),this.I=new Ql,$(this.j,0,5,this.I),this.v=new cf,$(this.j,0,6,this.v),this.L=new lf,$(this.j,0,7,this.L),G(this.s,2,.5),G(this.s,3,.3),G(this.I,2,.5),G(this.v,2,.5),G(this.v,3,.3),G(this.L,2,.5),G(this.K,2,.5)}get baseOptions(){return Y(this.j,ye,1)}set baseOptions(t){$(this.j,0,1,t)}o(t){return"minFaceDetectionConfidence"in t&&G(this.s,2,t.minFaceDetectionConfidence??.5),"minFaceSuppressionThreshold"in t&&G(this.s,3,t.minFaceSuppressionThreshold??.3),"minFacePresenceConfidence"in t&&G(this.I,2,t.minFacePresenceConfidence??.5),"outputFaceBlendshapes"in t&&(this.outputFaceBlendshapes=!!t.outputFaceBlendshapes),"minPoseDetectionConfidence"in t&&G(this.v,2,t.minPoseDetectionConfidence??.5),"minPoseSuppressionThreshold"in t&&G(this.v,3,t.minPoseSuppressionThreshold??.3),"minPosePresenceConfidence"in t&&G(this.L,2,t.minPosePresenceConfidence??.5),"outputPoseSegmentationMasks"in t&&(this.outputPoseSegmentationMasks=!!t.outputPoseSegmentationMasks),"minHandLandmarksConfidence"in t&&G(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,Sc(this),kt(this,t,n),Cc(this)}F(t,e,r,n){let s=typeof r!="function"?r:{};return this.C=typeof r=="function"?r:n,Sc(this),Yt(this,t,s,e),Cc(this)}m(){var t=new nt;ge(t,"input_frames_image"),Z(t,"pose_landmarks"),Z(t,"pose_world_landmarks"),Z(t,"face_landmarks"),Z(t,"left_hand_landmarks"),Z(t,"left_hand_world_landmarks"),Z(t,"right_hand_landmarks"),Z(t,"right_hand_world_landmarks");let e=new lt,r=new qu;ia(r,1,nn("type.googleapis.com/mediapipe.tasks.vision.holistic_landmarker.proto.HolisticLandmarkerGraphOptions"),""),function(s,o){if(o!=null)if(Array.isArray(o))ce(s,2,Ds(o,Da,void 0,void 0,!1));else{if(!(typeof o=="string"||o instanceof tr||$n(o)))throw Error("invalid value in Any.value field: "+o+" expected a ByteString, a base64 encoded string, a Uint8Array or a jspb array");ia(s,2,Ia(o,!1),Br())}}(r,this.j.g());let n=new qe;ht(n,"mediapipe.tasks.vision.holistic_landmarker.HolisticLandmarkerGraph"),Es(n,8,qu,r),le(n,"IMAGE:input_frames_image"),j(n,"POSE_LANDMARKS:pose_landmarks"),j(n,"POSE_WORLD_LANDMARKS:pose_world_landmarks"),j(n,"FACE_LANDMARKS:face_landmarks"),j(n,"LEFT_HAND_LANDMARKS:left_hand_landmarks"),j(n,"LEFT_HAND_WORLD_LANDMARKS:left_hand_world_landmarks"),j(n,"RIGHT_HAND_LANDMARKS:right_hand_landmarks"),j(n,"RIGHT_HAND_WORLD_LANDMARKS:right_hand_world_landmarks"),n.o(e),dt(t,n),Js(this,t),this.g.attachProtoListener("pose_landmarks",(s,o)=>{ds(s,this.h.poseLandmarks),D(this,o)}),this.g.attachEmptyPacketListener("pose_landmarks",s=>{D(this,s)}),this.g.attachProtoListener("pose_world_landmarks",(s,o)=>{var a=this.h.poseWorldLandmarks;s=Hr(s),a.push(Dn(s)),D(this,o)}),this.g.attachEmptyPacketListener("pose_world_landmarks",s=>{D(this,s)}),this.outputPoseSegmentationMasks&&(j(n,"POSE_SEGMENTATION_MASK:pose_segmentation_mask"),Kr(this,"pose_segmentation_mask"),this.g.V("pose_segmentation_mask",(s,o)=>{this.h.poseSegmentationMasks=[Qr(this,s,!0,!this.C)],D(this,o)}),this.g.attachEmptyPacketListener("pose_segmentation_mask",s=>{this.h.poseSegmentationMasks=[],D(this,s)})),this.g.attachProtoListener("face_landmarks",(s,o)=>{ds(s,this.h.faceLandmarks),D(this,o)}),this.g.attachEmptyPacketListener("face_landmarks",s=>{D(this,s)}),this.outputFaceBlendshapes&&(Z(t,"extra_blendshapes"),j(n,"FACE_BLENDSHAPES:extra_blendshapes"),this.g.attachProtoListener("extra_blendshapes",(s,o)=>{var a=this.h.faceBlendshapes;this.outputFaceBlendshapes&&(s=qs(s),a.push(mi(s.g()??[]))),D(this,o)}),this.g.attachEmptyPacketListener("extra_blendshapes",s=>{D(this,s)})),this.g.attachProtoListener("left_hand_landmarks",(s,o)=>{ds(s,this.h.leftHandLandmarks),D(this,o)}),this.g.attachEmptyPacketListener("left_hand_landmarks",s=>{D(this,s)}),this.g.attachProtoListener("left_hand_world_landmarks",(s,o)=>{var a=this.h.leftHandWorldLandmarks;s=Hr(s),a.push(Dn(s)),D(this,o)}),this.g.attachEmptyPacketListener("left_hand_world_landmarks",s=>{D(this,s)}),this.g.attachProtoListener("right_hand_landmarks",(s,o)=>{ds(s,this.h.rightHandLandmarks),D(this,o)}),this.g.attachEmptyPacketListener("right_hand_landmarks",s=>{D(this,s)}),this.g.attachProtoListener("right_hand_world_landmarks",(s,o)=>{var a=this.h.rightHandWorldLandmarks;s=Hr(s),a.push(Dn(s)),D(this,o)}),this.g.attachEmptyPacketListener("right_hand_world_landmarks",s=>{D(this,s)}),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};xe.prototype.detectForVideo=xe.prototype.F,xe.prototype.detect=xe.prototype.D,xe.prototype.setOptions=xe.prototype.o,xe.createFromModelPath=function(t,e){return X(xe,t,{baseOptions:{modelAssetPath:e}})},xe.createFromModelBuffer=function(t,e){return X(xe,t,{baseOptions:{modelAssetBuffer:e}})},xe.createFromOptions=function(t,e){return X(xe,t,e)},xe.HAND_CONNECTIONS=ki,xe.POSE_CONNECTIONS=Bf,xe.FACE_LANDMARKS_LIPS=yi,xe.FACE_LANDMARKS_LEFT_EYE=_i,xe.FACE_LANDMARKS_LEFT_EYEBROW=bi,xe.FACE_LANDMARKS_LEFT_IRIS=If,xe.FACE_LANDMARKS_RIGHT_EYE=vi,xe.FACE_LANDMARKS_RIGHT_EYEBROW=wi,xe.FACE_LANDMARKS_RIGHT_IRIS=Sf,xe.FACE_LANDMARKS_FACE_OVAL=Ti,xe.FACE_LANDMARKS_CONTOURS=Cf,xe.FACE_LANDMARKS_TESSELATION=Ff;var yt=class extends rt{constructor(t,e){super(new Tt(t,e),"input_image","norm_rect",!0),this.j={classifications:[]},$(t=this.h=new hf,0,1,e=new ye)}get baseOptions(){return Y(this.h,ye,1)}set baseOptions(t){$(this.h,0,1,t)}o(t){return $(this.h,0,2,ma(t,Y(this.h,ai,2))),this.l(t)}ta(t,e){return this.j={classifications:[]},kt(this,t,e),this.j}ua(t,e,r){return this.j={classifications:[]},Yt(this,t,r,e),this.j}m(){var t=new nt;ge(t,"input_image"),ge(t,"norm_rect"),Z(t,"classifications");let e=new lt;Lt(e,tm,this.h);let r=new qe;ht(r,"mediapipe.tasks.vision.image_classifier.ImageClassifierGraph"),le(r,"IMAGE:input_image"),le(r,"NORM_RECT:norm_rect"),j(r,"CLASSIFICATIONS:classifications"),r.o(e),dt(t,r),this.g.attachProtoListener("classifications",(n,s)=>{this.j=function(o){let a={classifications:nr(o,Vd,1).map(i=>mi(Y(i,zl,4)?.g()??[],Bt(vt(i,2),0),Xt(i,3)))};return Ts(xr(o,2))!=null&&(a.timestampMs=Bt(Ts(xr(o,2)),0)),a}(Wd(n)),D(this,s)}),this.g.attachEmptyPacketListener("classifications",n=>{D(this,n)}),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};yt.prototype.classifyForVideo=yt.prototype.ua,yt.prototype.classify=yt.prototype.ta,yt.prototype.setOptions=yt.prototype.o,yt.createFromModelPath=function(t,e){return X(yt,t,{baseOptions:{modelAssetPath:e}})},yt.createFromModelBuffer=function(t,e){return X(yt,t,{baseOptions:{modelAssetBuffer:e}})},yt.createFromOptions=function(t,e){return X(yt,t,e)};var it=class extends rt{constructor(t,e){super(new Tt(t,e),"image_in","norm_rect",!0),this.h=new df,this.embeddings={embeddings:[]},$(t=this.h,0,1,e=new ye)}get baseOptions(){return Y(this.h,ye,1)}set baseOptions(t){$(this.h,0,1,t)}o(t){var e=this.h,r=Y(this.h,sc,2);return r=r?r.clone():new sc,t.l2Normalize!==void 0?Gn(r,1,t.l2Normalize):"l2Normalize"in t&&ce(r,1),t.quantize!==void 0?Gn(r,2,t.quantize):"quantize"in t&&ce(r,2),$(e,0,2,r),this.l(t)}Aa(t,e){return kt(this,t,e),this.embeddings}Ba(t,e,r){return Yt(this,t,r,e),this.embeddings}m(){var t=new nt;ge(t,"image_in"),ge(t,"norm_rect"),Z(t,"embeddings_out");let e=new lt;Lt(e,rm,this.h);let r=new qe;ht(r,"mediapipe.tasks.vision.image_embedder.ImageEmbedderGraph"),le(r,"IMAGE:image_in"),le(r,"NORM_RECT:norm_rect"),j(r,"EMBEDDINGS:embeddings_out"),r.o(e),dt(t,r),this.g.attachProtoListener("embeddings_out",(n,s)=>{n=Hd(n),this.embeddings=function(o){return{embeddings:nr(o,zd,1).map(a=>{let i={headIndex:Bt(vt(a,3),0)??-1,headName:Xt(a,4)??""};if(cl(a,nc,jo(a,1))!==void 0)a=Sr(a=Y(a,nc,jo(a,1)),1,wr,Ir()),i.floatEmbedding=a.slice();else{let u=new Uint8Array(0);i.quantizedEmbedding=Y(a,$d,jo(a,2))?.pa()?.h()??u}return i}),timestampMs:Bt(Ts(xr(o,2)),0)}}(n),D(this,s)}),this.g.attachEmptyPacketListener("embeddings_out",n=>{D(this,n)}),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};it.cosineSimilarity=function(t,e){if(t.floatEmbedding&&e.floatEmbedding)t=cc(t.floatEmbedding,e.floatEmbedding);else{if(!t.quantizedEmbedding||!e.quantizedEmbedding)throw Error("Cannot compute cosine similarity between quantized and float embeddings.");t=cc(uc(t.quantizedEmbedding),uc(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 X(it,t,{baseOptions:{modelAssetPath:e}})},it.createFromModelBuffer=function(t,e){return X(it,t,{baseOptions:{modelAssetBuffer:e}})},it.createFromOptions=function(t,e){return X(it,t,e)};var ya=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 Fc(t){t.categoryMask=void 0,t.confidenceMasks=void 0,t.qualityScores=void 0}function Bc(t){try{let e=new ya(t.confidenceMasks,t.categoryMask,t.qualityScores);if(!t.j)return e;t.j(e)}finally{Qs(t)}}ya.prototype.close=ya.prototype.close;var ze=class extends rt{constructor(t,e){super(new Tt(t,e),"image_in","norm_rect",!1),this.s=[],this.outputCategoryMask=!1,this.outputConfidenceMasks=!0,this.h=new di,this.v=new mf,$(this.h,0,3,this.v),$(t=this.h,0,1,e=new ye)}get baseOptions(){return Y(this.h,ye,1)}set baseOptions(t){$(this.h,0,1,t)}o(t){return t.displayNamesLocale!==void 0?ce(this.h,2,nn(t.displayNamesLocale)):"displayNamesLocale"in t&&ce(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=nr(t.ea(),qe,1).filter(r=>Xt(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&&(Y(e[0],lt,7)?.l()?.g()??new Map).forEach((r,n)=>{t.s[Number(n)]=Xt(r,1)})})(this)}segment(t,e,r){let n=typeof e!="function"?e:{};return this.j=typeof e=="function"?e:r,Fc(this),kt(this,t,n),Bc(this)}Ma(t,e,r,n){let s=typeof r!="function"?r:{};return this.j=typeof r=="function"?r:n,Fc(this),Yt(this,t,s,e),Bc(this)}Ea(){return this.s}m(){var t=new nt;ge(t,"image_in"),ge(t,"norm_rect");let e=new lt;Lt(e,gf,this.h);let r=new qe;ht(r,"mediapipe.tasks.vision.image_segmenter.ImageSegmenterGraph"),le(r,"IMAGE:image_in"),le(r,"NORM_RECT:norm_rect"),r.o(e),dt(t,r),Js(this,t),this.outputConfidenceMasks&&(Z(t,"confidence_masks"),j(r,"CONFIDENCE_MASKS:confidence_masks"),Kr(this,"confidence_masks"),this.g.da("confidence_masks",(n,s)=>{this.confidenceMasks=n.map(o=>Qr(this,o,!0,!this.j)),D(this,s)}),this.g.attachEmptyPacketListener("confidence_masks",n=>{this.confidenceMasks=[],D(this,n)})),this.outputCategoryMask&&(Z(t,"category_mask"),j(r,"CATEGORY_MASK:category_mask"),Kr(this,"category_mask"),this.g.V("category_mask",(n,s)=>{this.categoryMask=Qr(this,n,!1,!this.j),D(this,s)}),this.g.attachEmptyPacketListener("category_mask",n=>{this.categoryMask=void 0,D(this,n)})),Z(t,"quality_scores"),j(r,"QUALITY_SCORES:quality_scores"),this.g.attachFloatVectorListener("quality_scores",(n,s)=>{this.qualityScores=n,D(this,s)}),this.g.attachEmptyPacketListener("quality_scores",n=>{this.categoryMask=void 0,D(this,n)}),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};ze.prototype.getLabels=ze.prototype.Ea,ze.prototype.segmentForVideo=ze.prototype.Ma,ze.prototype.segment=ze.prototype.segment,ze.prototype.setOptions=ze.prototype.o,ze.createFromModelPath=function(t,e){return X(ze,t,{baseOptions:{modelAssetPath:e}})},ze.createFromModelBuffer=function(t,e){return X(ze,t,{baseOptions:{modelAssetBuffer:e}})},ze.createFromOptions=function(t,e){return X(ze,t,e)};var _a=class{constructor(t,e,r){this.confidenceMasks=t,this.categoryMask=e,this.qualityScores=r}close(){this.confidenceMasks?.forEach(t=>{t.close()}),this.categoryMask?.close()}};_a.prototype.close=_a.prototype.close;var hm=class extends M{constructor(t){super(t)}},Vr=[0,ke,-2],Cs=[0,Qt,-3,_e,Qt,-1],Uc=[0,Cs],Lc=[0,Cs,ke,-1],ea=class extends M{constructor(t){super(t)}},Pc=[0,Qt,-1,_e],dm=class extends M{constructor(){super()}},Oc=class extends M{constructor(t){super(t)}},ba=[1,2,3,4,5,6,7,8,9,10,14,15],Uf=class extends M{constructor(){super()}};Uf.prototype.g=Ys([0,Oe,[0,ba,se,Cs,se,[0,Cs,Vr],se,Uc,se,[0,Uc,Vr],se,Pc,se,[0,Qt,-3,_e,Ut],se,[0,Qt,-3,_e],se,[0,ne,Qt,-2,_e,ke,_e,-1,2,Qt,Vr],se,Lc,se,[0,Lc,Vr],Qt,Vr,ne,se,[0,Qt,-3,_e,Vr,-1],se,[0,Oe,Pc]],ne,[0,ne,ke,-1,_e]]);var zt=class extends rt{constructor(t,e){super(new Tt(t,e),"image_in","norm_rect_in",!1),this.outputCategoryMask=!1,this.outputConfidenceMasks=!0,this.h=new di,this.s=new mf,$(this.h,0,3,this.s),$(t=this.h,0,1,e=new ye)}get baseOptions(){return Y(this.h,ye,1)}set baseOptions(t){$(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 Uf;let o=new Oc;var a=new hm;if(jt(a,1,255),$(o,0,12,a),e.keypoint&&e.scribble)throw Error("Cannot provide both keypoint and scribble.");if(e.keypoint){var i=new ea;Gn(i,3,!0),G(i,1,e.keypoint.x),G(i,2,e.keypoint.y),Pn(o,5,ba,i)}else{if(!e.scribble)throw Error("Must provide either a keypoint or a scribble.");for(i of(a=new dm,e.scribble))Gn(e=new ea,3,!0),G(e,1,i.x),G(e,2,i.y),Es(a,1,ea,e);Pn(o,15,ba,a)}Es(n,1,Oc,o),this.g.addProtoToStream(n.g(),"drishti.RenderData","roi_in",r),kt(this,t,s);e:{try{let l=new _a(this.confidenceMasks,this.categoryMask,this.qualityScores);if(!this.j){var u=l;break e}this.j(l)}finally{Qs(this)}u=void 0}return u}m(){var t=new nt;ge(t,"image_in"),ge(t,"roi_in"),ge(t,"norm_rect_in");let e=new lt;Lt(e,gf,this.h);let r=new qe;ht(r,"mediapipe.tasks.vision.interactive_segmenter.InteractiveSegmenterGraph"),le(r,"IMAGE:image_in"),le(r,"ROI:roi_in"),le(r,"NORM_RECT:norm_rect_in"),r.o(e),dt(t,r),Js(this,t),this.outputConfidenceMasks&&(Z(t,"confidence_masks"),j(r,"CONFIDENCE_MASKS:confidence_masks"),Kr(this,"confidence_masks"),this.g.da("confidence_masks",(n,s)=>{this.confidenceMasks=n.map(o=>Qr(this,o,!0,!this.j)),D(this,s)}),this.g.attachEmptyPacketListener("confidence_masks",n=>{this.confidenceMasks=[],D(this,n)})),this.outputCategoryMask&&(Z(t,"category_mask"),j(r,"CATEGORY_MASK:category_mask"),Kr(this,"category_mask"),this.g.V("category_mask",(n,s)=>{this.categoryMask=Qr(this,n,!1,!this.j),D(this,s)}),this.g.attachEmptyPacketListener("category_mask",n=>{this.categoryMask=void 0,D(this,n)})),Z(t,"quality_scores"),j(r,"QUALITY_SCORES:quality_scores"),this.g.attachFloatVectorListener("quality_scores",(n,s)=>{this.qualityScores=n,D(this,s)}),this.g.attachEmptyPacketListener("quality_scores",n=>{this.categoryMask=void 0,D(this,n)}),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};zt.prototype.segment=zt.prototype.segment,zt.prototype.setOptions=zt.prototype.o,zt.createFromModelPath=function(t,e){return X(zt,t,{baseOptions:{modelAssetPath:e}})},zt.createFromModelBuffer=function(t,e){return X(zt,t,{baseOptions:{modelAssetBuffer:e}})},zt.createFromOptions=function(t,e){return X(zt,t,e)};var _t=class extends rt{constructor(t,e){super(new Tt(t,e),"input_frame_gpu","norm_rect",!1),this.j={detections:[]},$(t=this.h=new xf,0,1,e=new ye)}get baseOptions(){return Y(this.h,ye,1)}set baseOptions(t){$(this.h,0,1,t)}o(t){return t.displayNamesLocale!==void 0?ce(this.h,2,nn(t.displayNamesLocale)):"displayNamesLocale"in t&&ce(this.h,2),t.maxResults!==void 0?jt(this.h,3,t.maxResults):"maxResults"in t&&ce(this.h,3),t.scoreThreshold!==void 0?G(this.h,4,t.scoreThreshold):"scoreThreshold"in t&&ce(this.h,4),t.categoryAllowlist!==void 0?As(this.h,5,t.categoryAllowlist):"categoryAllowlist"in t&&ce(this.h,5),t.categoryDenylist!==void 0?As(this.h,6,t.categoryDenylist):"categoryDenylist"in t&&ce(this.h,6),this.l(t)}D(t,e){return this.j={detections:[]},kt(this,t,e),this.j}F(t,e,r){return this.j={detections:[]},Yt(this,t,r,e),this.j}m(){var t=new nt;ge(t,"input_frame_gpu"),ge(t,"norm_rect"),Z(t,"detections");let e=new lt;Lt(e,sm,this.h);let r=new qe;ht(r,"mediapipe.tasks.vision.ObjectDetectorGraph"),le(r,"IMAGE:input_frame_gpu"),le(r,"NORM_RECT:norm_rect"),j(r,"DETECTIONS:detections"),r.o(e),dt(t,r),this.g.attachProtoVectorListener("detections",(n,s)=>{for(let o of n)n=Xl(o),this.j.detections.push(_f(n));D(this,s)}),this.g.attachEmptyPacketListener("detections",n=>{D(this,n)}),t=t.g(),this.setGraph(new Uint8Array(t),!0)}};_t.prototype.detectForVideo=_t.prototype.F,_t.prototype.detect=_t.prototype.D,_t.prototype.setOptions=_t.prototype.o,_t.createFromModelPath=async function(t,e){return X(_t,t,{baseOptions:{modelAssetPath:e}})},_t.createFromModelBuffer=function(t,e){return X(_t,t,{baseOptions:{modelAssetBuffer:e}})},_t.createFromOptions=function(t,e){return X(_t,t,e)};var va=class{constructor(t,e,r){this.landmarks=t,this.worldLandmarks=e,this.segmentationMasks=r}close(){this.segmentationMasks?.forEach(t=>{t.close()})}};function Dc(t){t.landmarks=[],t.worldLandmarks=[],t.segmentationMasks=void 0}function Mc(t){try{let e=new va(t.landmarks,t.worldLandmarks,t.segmentationMasks);if(!t.s)return e;t.s(e)}finally{Qs(t)}}va.prototype.close=va.prototype.close;var ut=class extends rt{constructor(t,e){super(new Tt(t,e),"image_in","norm_rect",!1),this.landmarks=[],this.worldLandmarks=[],this.outputSegmentationMasks=!1,$(t=this.h=new yf,0,1,e=new ye),this.v=new lf,$(this.h,0,3,this.v),this.j=new cf,$(this.h,0,2,this.j),jt(this.j,4,1),G(this.j,2,.5),G(this.v,2,.5),G(this.h,4,.5)}get baseOptions(){return Y(this.h,ye,1)}set baseOptions(t){$(this.h,0,1,t)}o(t){return"numPoses"in t&&jt(this.j,4,t.numPoses??1),"minPoseDetectionConfidence"in t&&G(this.j,2,t.minPoseDetectionConfidence??.5),"minTrackingConfidence"in t&&G(this.h,4,t.minTrackingConfidence??.5),"minPosePresenceConfidence"in t&&G(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,Dc(this),kt(this,t,n),Mc(this)}F(t,e,r,n){let s=typeof r!="function"?r:{};return this.s=typeof r=="function"?r:n,Dc(this),Yt(this,t,s,e),Mc(this)}m(){var t=new nt;ge(t,"image_in"),ge(t,"norm_rect"),Z(t,"normalized_landmarks"),Z(t,"world_landmarks"),Z(t,"segmentation_masks");let e=new lt;Lt(e,om,this.h);let r=new qe;ht(r,"mediapipe.tasks.vision.pose_landmarker.PoseLandmarkerGraph"),le(r,"IMAGE:image_in"),le(r,"NORM_RECT:norm_rect"),j(r,"NORM_LANDMARKS:normalized_landmarks"),j(r,"WORLD_LANDMARKS:world_landmarks"),r.o(e),dt(t,r),Js(this,t),this.g.attachProtoVectorListener("normalized_landmarks",(n,s)=>{this.landmarks=[];for(let o of n)n=jn(o),this.landmarks.push(Zs(n));D(this,s)}),this.g.attachEmptyPacketListener("normalized_landmarks",n=>{this.landmarks=[],D(this,n)}),this.g.attachProtoVectorListener("world_landmarks",(n,s)=>{this.worldLandmarks=[];for(let o of n)n=Hr(o),this.worldLandmarks.push(Dn(n));D(this,s)}),this.g.attachEmptyPacketListener("world_landmarks",n=>{this.worldLandmarks=[],D(this,n)}),this.outputSegmentationMasks&&(j(r,"SEGMENTATION_MASK:segmentation_masks"),Kr(this,"segmentation_masks"),this.g.da("segmentation_masks",(n,s)=>{this.segmentationMasks=n.map(o=>Qr(this,o,!0,!this.s)),D(this,s)}),this.g.attachEmptyPacketListener("segmentation_masks",n=>{this.segmentationMasks=[],D(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 X(ut,t,{baseOptions:{modelAssetPath:e}})},ut.createFromModelBuffer=function(t,e){return X(ut,t,{baseOptions:{modelAssetBuffer:e}})},ut.createFromOptions=function(t,e){return X(ut,t,e)},ut.POSE_CONNECTIONS=Bf;var Pf=(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)?Ei(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}},Ei=(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(!Ei(i[l],u[l]))return!1;return!0}if(!Lf(t)||!Lf(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)||!Ei(s[u],o[u]))return!1}return!0},Lf=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&Object.getPrototypeOf(t)===Object.prototype;var mm="utils/memoize/noValue",Y1=Symbol(mm);var Ai=t=>t;var Ri=(t,...e)=>{let r=e.reduce((n,s)=>o=>s(n(o)),Ai);return(...n)=>r(t(...n))};var pm=t=>`(${t})`;var Of=t=>pm(`?:${t}`),gm=t=>`${Of(t)}?`,xm=t=>`${Of(t)}*`;var ym=t=>`^${t}`,_m=t=>`${t}$`,bm=t=>typeof t=="function",vm=t=>e=>bm(e)?e(t):e;var wm=()=>t=>t,ro=(t,e=wm)=>r=>n=>Ri(vm(n),e(n),t)(r);var eg=ro(t=>gm(t)),tg=ro(t=>xm(t));var rg=ro(t=>ym(t)),ng=ro(t=>_m(t));var I=(t,e="AssertError")=>{if(!t)throw new Error(e,{cause:t});return t};var Df=[.5,.42],fn=432,hn=768,Ii=[.2,.8],Mf=5,qn=2,Se={Closed:"closed",Closing:"closing",Destroyed:"destroyed",Destroying:"destroying",Error:"Error",Idle:"idle",New:"new",Opened:"opened",Opening:"opening",Processing:"processing",Updated:"updated",Updating:"updating"},Nf={None:"none",Blur:"blur",Overlay:"overlay"},Gf={WebGL:"webgl",WebGPU:"webgpu"},O={ContextCreationError:"ContextCreationError",ContextLost:"ContextLost",ContextRestored:"ContextRestored",Error:"Error",ProcessorRestarted:"ProcessorRestarted",SamplingError:"SamplingError"};var km=t=>!!(typeof t=="string"&&Object.values(O).includes(t)),no=t=>km(t)?t:O.Error,so=t=>t instanceof Error?t.message:String(t),oo=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])}},Em="ImageFetchError",Am=t=>t?t.toLowerCase().startsWith("image/"):!1,Vf=t=>{let e=new Map(t),r=new Set,n=async(a,i)=>{let u=await fetch(a,{signal:i});if(u.ok&&Am(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(Em,{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()}}},Et=(t,e)=>r=>Math.min(Math.max(r,t),e);var dn=t=>{let e={};return new Proxy(e,{get(r,n,s){return r[n]||(r[n]=t[n]?.(e)),Reflect.get(r,n,s)}})},Wf=(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 $f(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 zf(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 m=c>0?e[f-1]:0,p=l>0?e[f-r]:0,w=c>0&&l>0?e[f-r-1]:0,A=c<r-1&&l>0?e[f-r+1]:0,v=m||p||w||A;v||(v=s++,o[v]=v),e[f]=v,m&&m!==v&&i(v,m),p&&p!==v&&i(v,p),w&&w!==v&&i(v,w),A&&A!==v&&i(v,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 m=u.get(f)??{sumX:0,sumY:0,count:0,minX:r,minY:n,maxX:-1,maxY:-1};m.sumX+=c,m.sumY+=l,m.count++,c<m.minX&&(m.minX=c),c>m.maxX&&(m.maxX=c),l<m.minY&&(m.minY=l),l>m.maxY&&(m.maxY=l),u.set(f,m)}return u}function Hf(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),m=a/s;return r.iou*e+r.area*f+r.height*m+r.center*c}var ru=(t,e)=>((t+e-1)/e|0)*e;function Rm(t){return Object.keys(t)}function Im(t,e){return new Array(t).fill(0).map((r,n)=>e(n))}var Xf=t=>ArrayBuffer.isView(t)&&!(t instanceof DataView),Zf=t=>t,q=Zf({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}}),kn=Zf({...q,"atomic<i32>":q.i32,"atomic<u32>":q.u32,"vec2<i32>":q.vec2i,"vec2<u32>":q.vec2u,"vec2<f32>":q.vec2f,"vec2<f16>":q.vec2h,"vec3<i32>":q.vec3i,"vec3<u32>":q.vec3u,"vec3<f32>":q.vec3f,"vec3<f16>":q.vec3h,"vec4<i32>":q.vec4i,"vec4<u32>":q.vec4u,"vec4<f32>":q.vec4f,"vec4<f16>":q.vec4h,"mat2x2<f32>":q.mat2x2f,"mat2x2<f16>":q.mat2x2h,"mat3x2<f32>":q.mat3x2f,"mat3x2<f16>":q.mat3x2h,"mat4x2<f32>":q.mat4x2f,"mat4x2<f16>":q.mat4x2h,"mat2x3<f32>":q.mat2x3f,"mat2x3<f16>":q.mat2x3h,"mat3x3<f32>":q.mat3x3f,"mat3x3<f16>":q.mat3x3h,"mat4x3<f32>":q.mat4x3f,"mat4x3<f16>":q.mat4x3h,"mat2x4<f32>":q.mat2x4f,"mat2x4<f16>":q.mat2x4h,"mat3x4<f32>":q.mat3x4f,"mat3x4<f16>":q.mat3x4h,"mat4x4<f32>":q.mat4x4f,"mat4x4<f16>":q.mat4x4h}),Sm=Rm(kn);function Cm(t=[],e){let r=new Set;for(let n of Sm){let s=kn[n];r.has(s)||(r.add(s),s.flatten=t.includes(n)?e:!e)}}Cm();function Fm(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}=kn[o.type];return s>1?ru(t.size,a)*s:t.size}}}function jf(t,e,r,n){let{size:s,type:o}=t;try{let{View:a,align:i,size:u}=kn[o],l=n!==void 0,c=l?ru(s,i):u,f=c/a.BYTES_PER_ELEMENT,m=l?n===0?(e.byteLength-r)/c:n:1;return new a(e,r,f*m)}catch{throw new Error(`unknown type: ${o}`)}}function Bm(t){return!t.fields&&!t.elementType}function Um(t,e,r){let n=r||0,s=e||new ArrayBuffer(Fm(t)),o=(a,i)=>{let u=a,l=u.elementType;if(l){if(Bm(l)&&kn[l.type].flatten)return jf(l,s,i,u.numElements);{let{size:c}=Jf(a),f=u.numElements===0?(s.byteLength-i)/c:u.numElements;return Im(f,m=>o(l,i+c*m))}}else{if(typeof a=="string")throw Error("unreachable");{let c=a.fields;if(c){let f={};for(let[m,{type:p,offset:w}]of Object.entries(c))f[m]=o(p,i+w);return f}else return jf(a,s,i)}}};return{views:o(t,n),arrayBuffer:s}}function Ui(t,e){if(t!==void 0)if(Xf(e)){let r=e;if(r.length===1&&typeof t=="number")r[0]=t;else if(Array.isArray(t[0])||Xf(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)=>{Ui(n,r[s])})}else{let r=e;for(let[n,s]of Object.entries(t)){let o=r[n];o&&Ui(s,o)}}}function gt(t,e,r=0){let n=t,s=n.group===void 0?t:n.typeDefinition,o=Um(s,e,r);return{...o,set(a){Ui(a,o.views)}}}function Li(t){let r=t.elementType;if(r)return Li(r);let s=t.fields;if(s)return Object.values(s).reduce((i,{type:u})=>Math.max(i,Li(u)),0);let{type:o}=t,{align:a}=kn[o];return a}function Jf(t){let r=t.elementType;if(r){let o=r.size,a=Li(r);return{unalignedSize:o,align:a,size:ru(o,a)}}let s=t.fields;if(s){let o=Object.values(s).pop();if(o.type.size===0)return Jf(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}},ao=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}},qt=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}},Kt=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}>`}},Zn=class extends st{constructor(e,r,n){super(e,n),this.format=r}get isPointer(){return!0}getTypeName(){return`&${this.format.getTypeName()}`}},ir=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}},Ne;(t=>{t[t.Uniform=0]="Uniform",t[t.Storage=1]="Storage",t[t.Texture=2]="Texture",t[t.Sampler=3]="Sampler",t[t.StorageTexture=4]="StorageTexture"})(Ne||(Ne={}));var pn=class{constructor(e,r,n,s,o,a,i){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}},Pi=class{constructor(e,r){this.name=e,this.type=r}},Oi=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}},Di=class{constructor(e,r,n,s){this.name=e,this.type=r,this.attributes=n,this.id=s}},Mi=class{constructor(e,r,n){this.name=e,this.type=r,this.attributes=n}},Ni=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}},Gi=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}},Qf=new Float32Array(1),Lm=new Int32Array(Qf.buffer),Xe=new Uint16Array(1);function Pm(t){Qf[0]=t;let e=Lm[0],r=e>>31&1,n=e>>23&255,s=8388607&e;if(n===255)return Xe[0]=r<<15|31744|(s!==0?512:0),Xe[0];if(n===0){if(s===0)return Xe[0]=r<<15,Xe[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),Xe[0]=r<<15|n<<10|s>>13,Xe[0]):(Xe[0]=r<<15,Xe[0])}return n=n-127+15,n>=31?(Xe[0]=r<<15|31744,Xe[0]):n<=0?n<-10?(Xe[0]=r<<15,Xe[0]):(s=(8388608|s)>>1-n,Xe[0]=r<<15|s>>13,Xe[0]):(s>>=13,Xe[0]=r<<15|n<<10|s,Xe[0])}var nu=new Uint32Array(1),eh=new Float32Array(nu.buffer,0,1);function Yf(t){let e=112+(t>>6&31)<<23|(63&t)<<17;return nu[0]=e,eh[0]}function Om(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[Q(t,l,"8unorm",1)[0]];case"r8snorm":return[Q(t,l,"8snorm",1)[0]];case"r8uint":return[Q(t,l,"8uint",1)[0]];case"r8sint":return[Q(t,l,"8sint",1)[0]];case"rg8unorm":{let c=Q(t,l,"8unorm",2);return[c[0],c[1]]}case"rg8snorm":{let c=Q(t,l,"8snorm",2);return[c[0],c[1]]}case"rg8uint":{let c=Q(t,l,"8uint",2);return[c[0],c[1]]}case"rg8sint":{let c=Q(t,l,"8sint",2);return[c[0],c[1]]}case"rgba8unorm-srgb":case"rgba8unorm":{let c=Q(t,l,"8unorm",4);return[c[0],c[1],c[2],c[3]]}case"rgba8snorm":{let c=Q(t,l,"8snorm",4);return[c[0],c[1],c[2],c[3]]}case"rgba8uint":{let c=Q(t,l,"8uint",4);return[c[0],c[1],c[2],c[3]]}case"rgba8sint":{let c=Q(t,l,"8sint",4);return[c[0],c[1],c[2],c[3]]}case"bgra8unorm-srgb":case"bgra8unorm":{let c=Q(t,l,"8unorm",4);return[c[2],c[1],c[0],c[3]]}case"r16uint":return[Q(t,l,"16uint",1)[0]];case"r16sint":return[Q(t,l,"16sint",1)[0]];case"r16float":return[Q(t,l,"16float",1)[0]];case"rg16uint":{let c=Q(t,l,"16uint",2);return[c[0],c[1]]}case"rg16sint":{let c=Q(t,l,"16sint",2);return[c[0],c[1]]}case"rg16float":{let c=Q(t,l,"16float",2);return[c[0],c[1]]}case"rgba16uint":{let c=Q(t,l,"16uint",4);return[c[0],c[1],c[2],c[3]]}case"rgba16sint":{let c=Q(t,l,"16sint",4);return[c[0],c[1],c[2],c[3]]}case"rgba16float":{let c=Q(t,l,"16float",4);return[c[0],c[1],c[2],c[3]]}case"r32uint":return[Q(t,l,"32uint",1)[0]];case"r32sint":return[Q(t,l,"32sint",1)[0]];case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return[Q(t,l,"32float",1)[0]];case"rg32uint":{let c=Q(t,l,"32uint",2);return[c[0],c[1]]}case"rg32sint":{let c=Q(t,l,"32sint",2);return[c[0],c[1]]}case"rg32float":{let c=Q(t,l,"32float",2);return[c[0],c[1]]}case"rgba32uint":{let c=Q(t,l,"32uint",4);return[c[0],c[1],c[2],c[3]]}case"rgba32sint":{let c=Q(t,l,"32sint",4);return[c[0],c[1],c[2],c[3]]}case"rgba32float":{let c=Q(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,m=(4290772992&c)>>22;return[Yf(2047&c),Yf(f),function(p){let w=112+(p>>5&31)<<23|(31&p)<<18;return nu[0]=w,eh[0]}(m),1]}}return null}function Q(t,e,r,n){let s=[0,0,0,0];for(let l=0;l<n;++l)switch(r){case"8unorm":s[l]=t[e]/255,e++;break;case"8snorm":s[l]=t[e]/255*2-1,e++;break;case"8uint":s[l]=t[e],e++;break;case"8sint":s[l]=t[e]-127,e++;break;case"16uint":s[l]=t[e]|t[e+1]<<8,e+=2;break;case"16sint":s[l]=(t[e]|t[e+1]<<8)-32768,e+=2;break;case"16float":s[l]=(o=t[e]|t[e+1]<<8,a=void 0,i=void 0,u=void 0,a=(32768&o)>>15,u=1023&o,(i=(31744&o)>>10)==0?(a?-1:1)*Math.pow(2,-14)*(u/Math.pow(2,10)):i==31?u?NaN:1/0*(a?-1:1):(a?-1:1)*Math.pow(2,i-15)*(1+u/Math.pow(2,10))),e+=2;break;case"32uint":case"32sint":s[l]=t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24,e+=4;break;case"32float":s[l]=new Float32Array(t.buffer,e,1)[0],e+=4}var o,a,i,u;return s}function ee(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=Pm(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 Si={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}},Rt=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(wn.instance);for(let n of e)n instanceof Array?this.searchBlock(n,r):n.search(r);r(Tn.instance)}}constEvaluate(e,r){throw new Error("Cannot evaluate node")}constEvaluateString(e){return this.constEvaluate(e).toString()}};Rt._id=0;var wn=class extends Rt{};wn.instance=new wn;var Tn=class extends Rt{};Tn.instance=new Tn;var th=new Set(["all","all","any","select","arrayLength","abs","acos","acosh","asin","asinh","atan","atanh","atan2","ceil","clamp","cos","cosh","countLeadingZeros","countOneBits","countTrailingZeros","cross","degrees","determinant","distance","dot","dot4U8Packed","dot4I8Packed","exp","exp2","extractBits","faceForward","firstLeadingBit","firstTrailingBit","floor","fma","fract","frexp","insertBits","inverseSqrt","ldexp","length","log","log2","max","min","mix","modf","normalize","pow","quantizeToF16","radians","reflect","refract","reverseBits","round","saturate","sign","sin","sinh","smoothStep","sqrt","step","tan","tanh","transpose","trunc","dpdx","dpdxCoarse","dpdxFine","dpdy","dpdyCoarse","dpdyFine","fwidth","fwidthCoarse","fwidthFine","textureDimensions","textureGather","textureGatherCompare","textureLoad","textureNumLayers","textureNumLevels","textureNumSamples","textureSample","textureSampleBias","textureSampleCompare","textureSampleCompareLevel","textureSampleGrad","textureSampleLevel","textureSampleBaseClampToEdge","textureStore","atomicLoad","atomicStore","atomicAdd","atomicSub","atomicMax","atomicMin","atomicAnd","atomicOr","atomicXor","atomicExchange","atomicCompareExchangeWeak","pack4x8snorm","pack4x8unorm","pack4xI8","pack4xU8","pack4x8Clamp","pack4xU8Clamp","pack2x16snorm","pack2x16unorm","pack2x16float","unpack4x8snorm","unpack4x8unorm","unpack4xI8","unpack4xU8","unpack2x16snorm","unpack2x16unorm","unpack2x16float","storageBarrier","textureBarrier","workgroupBarrier","workgroupUniformLoad","subgroupAdd","subgroupExclusiveAdd","subgroupInclusiveAdd","subgroupAll","subgroupAnd","subgroupAny","subgroupBallot","subgroupBroadcast","subgroupBroadcastFirst","subgroupElect","subgroupMax","subgroupMin","subgroupMul","subgroupExclusiveMul","subgroupInclusiveMul","subgroupOr","subgroupShuffle","subgroupShuffleDown","subgroupShuffleUp","subgroupShuffleXor","subgroupXor","quadBroadcast","quadSwapDiagonal","quadSwapX","quadSwapY"]),fe=class extends Rt{constructor(){super()}},Mr=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)}},Vi=class extends fe{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}},uo=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)}},Jn=class extends fe{constructor(e,r){super(),this.body=e,this.loopId=r}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}},co=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)}},Nt=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)}},Qn=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)}},Pr=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)}},yn=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)}},gn,Kn,b,x;(t=>{t.increment="++",t.decrement="--"})(gn||(gn={})),(t=>{t.parse=function(e){let r=e;if(r=="parse")throw new Error("Invalid value for IncrementOperator");return t[r]}})(gn||(gn={}));var lo=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.subtractAssin="-=",t.multiplyAssign="*=",t.divideAssign="/=",t.moduloAssign="%=",t.andAssign="&=",t.orAssign="|=",t.xorAssign="^=",t.shiftLeftAssign="<<=",t.shiftRightAssign=">>="})(Kn||(Kn={})),(t=>{t.parse=function(e){let r=e;if(r=="parse")throw new Error("Invalid value for AssignOperator");return r}})(Kn||(Kn={}));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)}},es=class extends fe{constructor(e,r){super(),this.name=e,this.args=r}get astNodeType(){return"call"}isBuiltin(){return th.has(this.name)}search(e){for(let r of this.args)r.search(e);e(this)}},ho=class extends fe{constructor(e,r){super(),this.body=e,this.continuing=r}get astNodeType(){return"loop"}},mo=class extends fe{constructor(e,r){super(),this.condition=e,this.cases=r}get astNodeType(){return"switch"}},po=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)}},go=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)}},Wi=class extends fe{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}},$i=class extends fe{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}},xo=class extends fe{constructor(e,r){super(),this.severity=e,this.rule=r}get astNodeType(){return"diagnostic"}},ts=class extends fe{constructor(e,r){super(),this.name=e,this.type=r}get astNodeType(){return"alias"}},zi=class extends fe{constructor(){super()}get astNodeType(){return"discard"}},yo=class extends fe{constructor(){super(),this.condition=null,this.loopId=-1}get astNodeType(){return"break"}},_o=class extends fe{constructor(){super(),this.loopId=-1}get astNodeType(){return"continue"}},R=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}};R.x32=new R("x32"),R.f32=new R("f32"),R.i32=new R("i32"),R.u32=new R("u32"),R.f16=new R("f16"),R.bool=new R("bool"),R.void=new R("void"),R._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);var bo=class extends R{constructor(e){super(e)}},Mt=class extends R{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)}},_=class extends R{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}};_.vec2f=new _("vec2",R.f32,null),_.vec3f=new _("vec3",R.f32,null),_.vec4f=new _("vec4",R.f32,null),_.vec2i=new _("vec2",R.i32,null),_.vec3i=new _("vec3",R.i32,null),_.vec4i=new _("vec4",R.i32,null),_.vec2u=new _("vec2",R.u32,null),_.vec3u=new _("vec3",R.u32,null),_.vec4u=new _("vec4",R.u32,null),_.vec2h=new _("vec2",R.f16,null),_.vec3h=new _("vec3",R.f16,null),_.vec4h=new _("vec4",R.f16,null),_.vec2b=new _("vec2",R.bool,null),_.vec3b=new _("vec3",R.bool,null),_.vec4b=new _("vec4",R.bool,null),_.mat2x2f=new _("mat2x2",R.f32,null),_.mat2x3f=new _("mat2x3",R.f32,null),_.mat2x4f=new _("mat2x4",R.f32,null),_.mat3x2f=new _("mat3x2",R.f32,null),_.mat3x3f=new _("mat3x3",R.f32,null),_.mat3x4f=new _("mat3x4",R.f32,null),_.mat4x2f=new _("mat4x2",R.f32,null),_.mat4x3f=new _("mat4x3",R.f32,null),_.mat4x4f=new _("mat4x4",R.f32,null),_.mat2x2h=new _("mat2x2",R.f16,null),_.mat2x3h=new _("mat2x3",R.f16,null),_.mat2x4h=new _("mat2x4",R.f16,null),_.mat3x2h=new _("mat3x2",R.f16,null),_.mat3x3h=new _("mat3x3",R.f16,null),_.mat3x4h=new _("mat3x4",R.f16,null),_.mat4x2h=new _("mat4x2",R.f16,null),_.mat4x3h=new _("mat4x3",R.f16,null),_.mat4x4h=new _("mat4x4",R.f16,null),_.mat2x2i=new _("mat2x2",R.i32,null),_.mat2x3i=new _("mat2x3",R.i32,null),_.mat2x4i=new _("mat2x4",R.i32,null),_.mat3x2i=new _("mat3x2",R.i32,null),_.mat3x3i=new _("mat3x3",R.i32,null),_.mat3x4i=new _("mat3x4",R.i32,null),_.mat4x2i=new _("mat4x2",R.i32,null),_.mat4x3i=new _("mat4x3",R.i32,null),_.mat4x4i=new _("mat4x4",R.i32,null),_.mat2x2u=new _("mat2x2",R.u32,null),_.mat2x3u=new _("mat2x3",R.u32,null),_.mat2x4u=new _("mat2x4",R.u32,null),_.mat3x2u=new _("mat3x2",R.u32,null),_.mat3x3u=new _("mat3x3",R.u32,null),_.mat3x4u=new _("mat3x4",R.u32,null),_.mat4x2u=new _("mat4x2",R.u32,null),_.mat4x3u=new _("mat4x3",R.u32,null),_.mat4x4u=new _("mat4x4",R.u32,null);var _n=class extends R{constructor(e,r,n,s){super(e),this.storage=r,this.type=n,this.access=s}get astNodeType(){return"pointer"}},Or=class extends R{constructor(e,r,n,s){super(e),this.attributes=r,this.format=n,this.count=s}get astNodeType(){return"array"}get isArray(){return!0}},Lr=class extends R{constructor(e,r,n){super(e),this.format=r,this.access=n}get astNodeType(){return"sampler"}},pt=class extends Rt{constructor(){super(),this.postfix=null}},ur=class extends pt{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}constEvaluateString(){return this.value}},At=class extends pt{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)}},rs=class extends pt{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 th.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)}},Qe=class extends pt{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)}},vo=class extends pt{constructor(e,r){super(),this.name=e,this.initializer=r}get astNodeType(){return"constExpr"}constEvaluate(e,r){if(this.initializer){let n=e.evalExpression(this.initializer,e.context);return n!==null&&this.postfix?n.getSubData(e,this.postfix,e.context):n}return null}search(e){this.initializer.search(e)}},Ce=class extends pt{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 d||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 d||this.value instanceof H?this.value.data:(console.error("Value is not a vector or matrix."),new Float32Array(0))}},wo=class extends pt{constructor(e,r){super(),this.type=e,this.value=r}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}},Er=class extends pt{constructor(e){super(),this.index=e}search(e){this.index.search(e)}},To=class extends pt{constructor(){super()}},Ee=class extends To{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 To{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"?R.f32:e.name==="u32"||r.name==="u32"?R.u32:R.i32}constEvaluate(e,r){return e.evalExpression(this,e.context)}search(e){this.left.search(e),this.right.search(e)}},ko=class extends Rt{constructor(e){super(),this.body=e}},bn=class extends pt{constructor(){super()}get astNodeType(){return"default"}},Eo=class extends ko{constructor(e,r){super(r),this.selectors=e}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}},Ao=class extends ko{constructor(e){super(e)}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}},Ro=class extends Rt{constructor(e,r,n){super(),this.name=e,this.type=r,this.attributes=n}get astNodeType(){return"argument"}},Hi=class extends Rt{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)}},Io=class extends Rt{constructor(e,r,n){super(),this.name=e,this.type=r,this.attributes=n}get astNodeType(){return"member"}},So=class extends Rt{constructor(e,r){super(),this.name=e,this.value=r}get astNodeType(){return"attribute"}},It=class t{constructor(e,r){this.parent=null,this.typeInfo=e,this.parent=r,this.id=t._id++}clone(){throw`Clone: Not implemented for ${this.constructor.name}`}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()}>`}};It._id=0;var ns=class extends It{constructor(){super(new st("void",null),null)}toString(){return"void"}};ns.void=new ns;var kr=class extends It{constructor(e){super(new Zn("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 It{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"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 Dm(t,e,r){let n=e.length;return n===2?r==="f32"?new d(new Float32Array(e),t.getTypeInfo("vec2f")):r==="i32"||r==="bool"?new d(new Int32Array(e),t.getTypeInfo("vec2i")):r==="u32"?new d(new Uint32Array(e),t.getTypeInfo("vec2u")):r==="f16"?new d(new Float32Array(e),t.getTypeInfo("vec2h")):(console.error(`getSubData: Unknown format ${r}`),null):n===3?r==="f32"?new d(new Float32Array(e),t.getTypeInfo("vec3f")):r==="i32"||r==="bool"?new d(new Int32Array(e),t.getTypeInfo("vec3i")):r==="u32"?new d(new Uint32Array(e),t.getTypeInfo("vec3u")):r==="f16"?new d(new Float32Array(e),t.getTypeInfo("vec3h")):(console.error(`getSubData: Unknown format ${r}`),null):n===4?r==="f32"?new d(new Float32Array(e),t.getTypeInfo("vec4f")):r==="i32"||r==="bool"?new d(new Int32Array(e),t.getTypeInfo("vec4i")):r==="u32"?new d(new Uint32Array(e),t.getTypeInfo("vec4u")):r==="f16"?new d(new Float32Array(e),t.getTypeInfo("vec4h")):(console.error(`getSubData: Unknown format ${r}`),null):(console.error(`getSubData: Invalid vector size ${e.length}`),null)}var d=class t extends It{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"VectorData: Invalid data type"}setDataValue(e,r,n,s){n instanceof ur?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 ir)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 Er){let a=r.index,i=-1;if(a instanceof Ce){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"GetSubData: Invalid data type"}if(!(r instanceof ur))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=Dm(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 It{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 ur?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 ir)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 Er){let o=r.index,a=-1;if(o instanceof Ce){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 d(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 d(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 d(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}},Le=class t extends It{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 Er)if(a instanceof Kt){let i=n.index;if(i instanceof Ce){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 ur))return void console.error("SetDataValue: Unknown postfix type",n);{let i=n.value;if(a instanceof qt){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")if(a!=="vec3f"&&a!=="vec3h")if(a!=="vec4f"&&a!=="vec4h")if(a!=="vec2i")if(a!=="vec3i")if(a!=="vec4i")if(a!=="vec2u")if(a!=="vec3u")if(a!=="vec4u")if(a!=="vec2b")if(a!=="vec3b")if(a!=="vec4b")if(a!=="mat2x2f"&&a!=="mat2x2h")if(a!=="mat2x3f"&&a!=="mat2x3h")if(a!=="mat2x4f"&&a!=="mat2x4h")if(a!=="mat3x2f"&&a!=="mat3x2h")if(a!=="mat3x3f"&&a!=="mat3x3h")if(a!=="mat3x4f"&&a!=="mat3x4h")if(a!=="mat4x2f"&&a!=="mat4x2h")if(a!=="mat4x3f"&&a!=="mat4x3h")if(a!=="mat4x4f"&&a!=="mat4x4h")if(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{let i=new Float32Array(this.buffer,s,16);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])}else{let i=new Float32Array(this.buffer,s,12);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])}else{let i=new Float32Array(this.buffer,s,8);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])}else{let i=new Float32Array(this.buffer,s,12);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])}else{let i=new Float32Array(this.buffer,s,9);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])}else{let i=new Float32Array(this.buffer,s,6);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])}else{let i=new Float32Array(this.buffer,s,8);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])}else{let i=new Float32Array(this.buffer,s,6);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])}else{let i=new Float32Array(this.buffer,s,4);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])}else{let i=new Uint32Array(this.buffer,s,4);r instanceof d?(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])}else{let i=new Uint32Array(this.buffer,s,3);r instanceof d?(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])}else{let i=new Uint32Array(this.buffer,s,2);r instanceof d?(i[0]=r.data[0],i[1]=r.data[1]):(i[0]=r[0],i[1]=r[1])}else{let i=new Uint32Array(this.buffer,s,4);r instanceof d?(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])}else{let i=new Uint32Array(this.buffer,s,3);r instanceof d?(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])}else{let i=new Uint32Array(this.buffer,s,2);r instanceof d?(i[0]=r.data[0],i[1]=r.data[1]):(i[0]=r[0],i[1]=r[1])}else{let i=new Int32Array(this.buffer,s,4);r instanceof d?(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])}else{let i=new Int32Array(this.buffer,s,3);r instanceof d?(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])}else{let i=new Int32Array(this.buffer,s,2);r instanceof d?(i[0]=r.data[0],i[1]=r.data[1]):(i[0]=r[0],i[1]=r[1])}else{let i=new Float32Array(this.buffer,s,4);r instanceof d?(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])}else{let i=new Float32Array(this.buffer,s,3);r instanceof d?(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])}else{let i=new Float32Array(this.buffer,s,2);r instanceof d?(i[0]=r.data[0],i[1]=r.data[1]):(i[0]=r[0],i[1]=r[1])}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 Er){let c=r.index,f=c instanceof pt?e.evalExpression(c,n):c,m=0;if(f instanceof y?m=f.value:typeof f=="number"?m=f:console.error("GetDataValue: Invalid index type",c),u instanceof Kt)i+=m*u.stride,u=u.format;else{let p=u.getTypeName();p==="mat4x4"||p==="mat4x4f"||p==="mat4x4h"?(i+=16*m,u=e.getTypeInfo("vec4f")):console.error(`getDataValue: Type ${u.getTypeName()} is not an array`)}}else{if(!(r instanceof ur))return console.error("GetDataValue: Unknown postfix type",r),null;{let c=r.value;if(u instanceof qt){let f=!1;for(let m of u.members)if(m.name===c){i+=m.offset,u=m.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 m="f",p=[];for(let w=0;w<c.length;++w){let A=c[w].toLowerCase(),v=0;if(A==="x"||A==="r")v=0;else if(A==="y"||A==="g")v=1;else if(A==="z"||A==="b")v=2;else{if(A!=="w"&&A!=="a")return console.error(`Unknown member ${c}`),null;v=3}if(c.length===1){if(f.endsWith("f"))return this.buffer.byteLength<i+4*v+4?(console.log("Insufficient buffer data"),null):new y(new Float32Array(this.buffer,i+4*v,1),e.getTypeInfo("f32"),this);if(f.endsWith("h"))return new y(new Float32Array(this.buffer,i+4*v,1),e.getTypeInfo("f16"),this);if(f.endsWith("i"))return new y(new Int32Array(this.buffer,i+4*v,1),e.getTypeInfo("i32"),this);if(f.endsWith("b"))return new y(new Int32Array(this.buffer,i+4*v,1),e.getTypeInfo("bool"),this);if(f.endsWith("u"))return new y(new Uint32Array(this.buffer,i+4*v,1),e.getTypeInfo("i32"),this)}if(f==="vec2f")p.push(new Float32Array(this.buffer,i,2)[v]);else if(f==="vec3f"){if(i+12>=this.buffer.byteLength)return console.log("Insufficient buffer data"),null;let C=new Float32Array(this.buffer,i,3);p.push(C[v])}else if(f==="vec4f")p.push(new Float32Array(this.buffer,i,4)[v]);else if(f==="vec2i")m="i",p.push(new Int32Array(this.buffer,i,2)[v]);else if(f==="vec3i")m="i",p.push(new Int32Array(this.buffer,i,3)[v]);else if(f==="vec4i")m="i",p.push(new Int32Array(this.buffer,i,4)[v]);else if(f==="vec2u"){m="u";let C=new Uint32Array(this.buffer,i,2);p.push(C[v])}else f==="vec3u"?(m="u",p.push(new Uint32Array(this.buffer,i,3)[v])):f==="vec4u"&&(m="u",p.push(new Uint32Array(this.buffer,i,4)[v]))}return p.length===2?u=e.getTypeInfo(`vec2${m}`):p.length===3?u=e.getTypeInfo(`vec3${m}`):p.length===4?u=e.getTypeInfo(`vec4${m}`):console.error(`GetDataValue: Invalid vector length ${p.length}`),new d(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 d(new Float32Array(this.buffer,i,2),u,this):l==="vec3f"?new d(new Float32Array(this.buffer,i,3),u,this):l==="vec4f"?new d(new Float32Array(this.buffer,i,4),u,this):l==="vec2i"?new d(new Int32Array(this.buffer,i,2),u,this):l==="vec3i"?new d(new Int32Array(this.buffer,i,3),u,this):l==="vec4i"?new d(new Int32Array(this.buffer,i,4),u,this):l==="vec2u"?new d(new Uint32Array(this.buffer,i,2),u,this):l==="vec3u"?new d(new Uint32Array(this.buffer,i,3),u,this):l==="vec4u"?new d(new Uint32Array(this.buffer,i,4),u,this):u instanceof ir&&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)}toString(){let e="";if(this.typeInfo instanceof Kt)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 qt?e+="{...}":e="[...]";return e}},ar=class t extends It{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=Si[e];return r?r.isDepthStencil?4:r.bytesPerBlock:0}get bytesPerRow(){return this.width*this.texelByteSize}get isDepthStencil(){let e=this.format,r=Si[e];return!!r&&r.isDepthStencil}getGpuSize(){let e=this.format,r=Si[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 Om(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,m,p,w,A,v,C,k,T){let S=p*(v>>=w)*(A>>=w)+m*v+f*C;switch(k){case"r8unorm":return void ee(c,S,"8unorm",1,T);case"r8snorm":return void ee(c,S,"8snorm",1,T);case"r8uint":return void ee(c,S,"8uint",1,T);case"r8sint":return void ee(c,S,"8sint",1,T);case"rg8unorm":return void ee(c,S,"8unorm",2,T);case"rg8snorm":return void ee(c,S,"8snorm",2,T);case"rg8uint":return void ee(c,S,"8uint",2,T);case"rg8sint":return void ee(c,S,"8sint",2,T);case"rgba8unorm-srgb":case"rgba8unorm":case"bgra8unorm-srgb":case"bgra8unorm":return void ee(c,S,"8unorm",4,T);case"rgba8snorm":return void ee(c,S,"8snorm",4,T);case"rgba8uint":return void ee(c,S,"8uint",4,T);case"rgba8sint":return void ee(c,S,"8sint",4,T);case"r16uint":return void ee(c,S,"16uint",1,T);case"r16sint":return void ee(c,S,"16sint",1,T);case"r16float":return void ee(c,S,"16float",1,T);case"rg16uint":return void ee(c,S,"16uint",2,T);case"rg16sint":return void ee(c,S,"16sint",2,T);case"rg16float":return void ee(c,S,"16float",2,T);case"rgba16uint":return void ee(c,S,"16uint",4,T);case"rgba16sint":return void ee(c,S,"16sint",4,T);case"rgba16float":return void ee(c,S,"16float",4,T);case"r32uint":return void ee(c,S,"32uint",1,T);case"r32sint":return void ee(c,S,"32sint",1,T);case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return void ee(c,S,"32float",1,T);case"rg32uint":return void ee(c,S,"32uint",2,T);case"rg32sint":return void ee(c,S,"32sint",2,T);case"rg32float":return void ee(c,S,"32float",2,T);case"rgba32uint":return void ee(c,S,"32uint",4,T);case"rgba32sint":return void ee(c,S,"32sint",4,T);case"rgba32float":return void ee(c,S,"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 g=class{constructor(e,r,n){this.name=e,this.type=r,this.rule=n}toString(){return this.name}},h=class{};b=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"),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")},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={"@":b.tokens.attr,"{":b.tokens.brace_left,"}":b.tokens.brace_right,":":b.tokens.colon,",":b.tokens.comma,"(":b.tokens.paren_left,")":b.tokens.paren_right,";":b.tokens.semicolon},h.literalTokens={"&":b.tokens.and,"&&":b.tokens.and_and,"->":b.tokens.arrow,"/":b.tokens.forward_slash,"!":b.tokens.bang,"[":b.tokens.bracket_left,"]":b.tokens.bracket_right,"=":b.tokens.equal,"==":b.tokens.equal_equal,"!=":b.tokens.not_equal,">":b.tokens.greater_than,">=":b.tokens.greater_than_equal,">>":b.tokens.shift_right,"<":b.tokens.less_than,"<=":b.tokens.less_than_equal,"<<":b.tokens.shift_left,"%":b.tokens.modulo,"-":b.tokens.minus,"--":b.tokens.minus_minus,".":b.tokens.period,"+":b.tokens.plus,"++":b.tokens.plus_plus,"|":b.tokens.or,"||":b.tokens.or_or,"*":b.tokens.star,"~":b.tokens.tilde,_:b.tokens.underscore,"^":b.tokens.xor,"+=":b.tokens.plus_equal,"-=":b.tokens.minus_equal,"*=":b.tokens.times_equal,"/=":b.tokens.division_equal,"%=":b.tokens.modulo_equal,"&=":b.tokens.and_equal,"|=":b.tokens.or_equal,"^=":b.tokens.xor_equal,">>=":b.tokens.shift_right_equal,"<<=":b.tokens.shift_left_equal},h.regexTokens={decimal_float_literal:b.tokens.decimal_float_literal,hex_float_literal:b.tokens.hex_float_literal,int_literal:b.tokens.int_literal,uint_literal:b.tokens.uint_literal,ident:b.tokens.ident},h.storage_class=[b.keywords.function,b.keywords.private,b.keywords.workgroup,b.keywords.uniform,b.keywords.storage],h.access_mode=[b.keywords.read,b.keywords.write,b.keywords.read_write],h.sampler_type=[b.keywords.sampler,b.keywords.sampler_comparison],h.sampled_texture_type=[b.keywords.texture_1d,b.keywords.texture_2d,b.keywords.texture_2d_array,b.keywords.texture_3d,b.keywords.texture_cube,b.keywords.texture_cube_array],h.multisampled_texture_type=[b.keywords.texture_multisampled_2d],h.storage_texture_type=[b.keywords.texture_storage_1d,b.keywords.texture_storage_2d,b.keywords.texture_storage_2d_array,b.keywords.texture_storage_3d],h.depth_texture_type=[b.keywords.texture_depth_2d,b.keywords.texture_depth_2d_array,b.keywords.texture_depth_cube,b.keywords.texture_depth_cube_array,b.keywords.texture_depth_multisampled_2d],h.texture_external_type=[b.keywords.texture_external],h.any_texture_type=[...b.sampled_texture_type,...b.multisampled_texture_type,...b.storage_texture_type,...b.depth_texture_type,...b.texture_external_type],h.texel_format=[b.keywords.r8unorm,b.keywords.r8snorm,b.keywords.r8uint,b.keywords.r8sint,b.keywords.r16uint,b.keywords.r16sint,b.keywords.r16float,b.keywords.rg8unorm,b.keywords.rg8snorm,b.keywords.rg8uint,b.keywords.rg8sint,b.keywords.r32uint,b.keywords.r32sint,b.keywords.r32float,b.keywords.rg16uint,b.keywords.rg16sint,b.keywords.rg16float,b.keywords.rgba8unorm,b.keywords.rgba8unorm_srgb,b.keywords.rgba8snorm,b.keywords.rgba8uint,b.keywords.rgba8sint,b.keywords.bgra8unorm,b.keywords.bgra8unorm_srgb,b.keywords.rgb10a2unorm,b.keywords.rg11b10float,b.keywords.rg32uint,b.keywords.rg32sint,b.keywords.rg32float,b.keywords.rgba16uint,b.keywords.rgba16sint,b.keywords.rgba16float,b.keywords.rgba32uint,b.keywords.rgba32sint,b.keywords.rgba32float],h.const_literal=[b.tokens.int_literal,b.tokens.uint_literal,b.tokens.decimal_float_literal,b.tokens.hex_float_literal,b.keywords.true,b.keywords.false],h.literal_or_ident=[b.tokens.ident,b.tokens.int_literal,b.tokens.uint_literal,b.tokens.decimal_float_literal,b.tokens.hex_float_literal,b.tokens.name],h.element_count_expression=[b.tokens.int_literal,b.tokens.uint_literal,b.tokens.ident],h.template_types=[b.keywords.vec2,b.keywords.vec3,b.keywords.vec4,b.keywords.mat2x2,b.keywords.mat2x3,b.keywords.mat2x4,b.keywords.mat3x2,b.keywords.mat3x3,b.keywords.mat3x4,b.keywords.mat4x2,b.keywords.mat4x3,b.keywords.mat4x4,b.keywords.atomic,b.keywords.bitcast,...b.any_texture_type],h.attribute_name=[b.tokens.ident,b.keywords.block,b.keywords.diagnostic],h.assignment_operators=[b.tokens.equal,b.tokens.plus_equal,b.tokens.minus_equal,b.tokens.times_equal,b.tokens.division_equal,b.tokens.modulo_equal,b.tokens.and_equal,b.tokens.or_equal,b.tokens.xor_equal,b.tokens.shift_right_equal,b.tokens.shift_left_equal],h.increment_operators=[b.tokens.plus_plus,b.tokens.minus_minus];var Co=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.indexOf(this.type)!=-1}isArrayType(){return this.type==h.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}},Xi=class{constructor(e){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=e??""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new Co(h.eof,"",this._line,this._current,this._current)),this._tokens}scanToken(){let e=this._advance();if(e==`
|
|
42
|
+
`)return this._line++,!0;if(this._isWhitespace(e))return!0;if(e=="/"){if(this._peekAhead()=="/"){for(;e!=`
|
|
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.indexOf(this._tokens[u].type)!=-1||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.indexOf(this._tokens[l].type)===-1;++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!=="_"&&e!=="."&&e!=="("&&e!==")"&&e!=="["&&e!=="]"&&e!=="{"&&e!=="}"&&e!==","&&e!==";"&&e!==":"&&e!=="="&&e!=="!"&&e!=="<"&&e!==">"&&e!=="+"&&e!=="-"&&e!=="*"&&e!=="/"&&e!=="%"&&e!=="&"&&e!=="|"&&e!=="^"&&e!=="~"&&e!=="@"&&e!=="#"&&e!=="?"&&e!=="'"&&e!=="`"&&e!=='"'&&e!=="\\"&&e!==`
|
|
45
|
+
`&&e!=="\r"&&e!==" "&&e!=="\0"}_isNumeric(e){return e>="0"&&e<="9"}_isAlphaNumeric(e){return this._isAlpha(e)||this._isNumeric(e)||e==="_"}_isWhitespace(e){return e==" "||e==" "||e=="\r"}_advance(e=0){let r=this._source[this._current];return e=e||0,e++,this._current+=e,r}_peekAhead(e=0){return e=e||0,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 Co(e,r,this._line,this._start,this._current))}};function L(t){return Array.isArray(t)||t?.buffer instanceof ArrayBuffer}var Fo=new Float32Array(1),Mm=new Uint32Array(Fo.buffer),Nm=new Uint32Array(Fo.buffer),Bo=new Int32Array(1),Gm=new Float32Array(Bo.buffer),Vm=new Uint32Array(Bo.buffer),Uo=new Uint32Array(1),Wm=new Float32Array(Uo.buffer),$m=new Int32Array(Uo.buffer);function qf(t,e,r){if(e===r)return t;if(e==="f32"){if(r==="i32"||r==="x32")return Fo[0]=t,Mm[0];if(r==="u32")return Fo[0]=t,Nm[0]}else if(e==="i32"||e==="x32"){if(r==="f32")return Bo[0]=t,Gm[0];if(r==="u32")return Bo[0]=t,Vm[0]}else if(e==="u32"){if(r==="f32")return Uo[0]=t,Wm[0];if(r==="i32"||r==="x32")return Uo[0]=t,$m[0]}return console.error(`Unsupported cast from ${e} to ${r}`),t}var ji=class{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}},xn=class{constructor(e,r){this.align=e,this.size=r}},Dr=class t{constructor(){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new Gi,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 Mr&&this._functions.set(r.name,new ji(r));for(let r of e)if(r instanceof Mt){let n=this.getTypeInfo(r,null);n instanceof qt&&this.structs.push(n)}for(let r of e)if(r instanceof ts)this.aliases.push(this._getAliasInfo(r));else if(r instanceof Qn){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 Di(n.name,o,n.attributes,s))}else 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 pn(n.name,a,s,o,n.attributes,Ne.Uniform,n.access);i.access||(i.access="read"),this.uniforms.push(i)}else 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 pn(n.name,a,s,o,n.attributes,i?Ne.StorageTexture:Ne.Storage,n.access);u.access||(u.access="read"),this.storage.push(u)}else 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=new pn(n.name,a,s,o,n.attributes,i?Ne.StorageTexture:Ne.Texture,n.access);u.access||(u.access="read"),i?this.storage.push(u):this.textures.push(u)}else 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 pn(n.name,a,s,o,n.attributes,Ne.Sampler,n.access);this.samplers.push(i)}for(let r of e)if(r instanceof Mr){let n=this._getAttribute(r,"vertex"),s=this._getAttribute(r,"fragment"),o=this._getAttribute(r,"compute"),a=n||s||o,i=new Ni(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.resources=this._findResources(r,!!a),i.inputs=this._getInputs(r.args),i.outputs=this._getOutputs(r.returnType),this.entry[a.name].push(i)),i.arguments=r.args.map(u=>new Mi(u.name,this.getTypeInfo(u.type,u.attributes),u.attributes)),i.returnType=r.returnType?this.getTypeInfo(r.returnType,r.attributes):null}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 So){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 Qe)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)}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 wn)o.push({});else if(a instanceof Tn)o.pop();else if(a instanceof Nt){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 At){let i=a;r&&i.type!==null&&this._markStructsFromAST(i.type)}else if(a instanceof Pr){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 Qe){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 rs){let i=a,u=s._functions.get(i.name);u&&(r&&(u.inUse=!0),e.calls.add(u.node),u.resources===null&&(u.resources=s._findResources(u.node,r)),n.push(...u.resources))}else if(a instanceof es){let i=a,u=s._functions.get(i.name);u&&(r&&(u.inUse=!0),e.calls.add(u.node),u.resources===null&&(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 Mt)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 Mt)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 Mt)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 Mt)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 Oi(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 Pi(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 _n){let s=e.type?this.getTypeInfo(e.type,e.attributes):null,o=new Zn(e.name,s,r);return this._types.set(e,o),this._updateTypeInfo(o),o}if(e instanceof Or){let s=e,o=s.format?this.getTypeInfo(s.format,s.attributes):null,a=new Kt(s.name,r);return a.format=o,a.count=s.count,this._types.set(e,a),this._updateTypeInfo(a),a}if(e instanceof Mt){let s=e,o=new qt(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 ao(a.name,i,a.attributes))}return this._types.set(e,o),this._updateTypeInfo(o),o}if(e instanceof Lr){let s=e,o=s.format instanceof R,a=s.format?o?this.getTypeInfo(s.format,null):new st(s.format,null):null,i=new ir(s.name,a,r,s.access);return this._types.set(e,i),this._updateTypeInfo(i),i}if(e instanceof _){let s=e,o=s.format?this.getTypeInfo(s.format,null):null,a=new ir(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 Kt&&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 Zn&&this._updateTypeInfo(e.format),e instanceof qt&&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,m=c.size;n=this._roundUp(f,n+s),s=m,o=n,a=Math.max(a,f),l.offset=n,l.size=m,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 ao&&(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 xn(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 xn(Math.max(o,a.align/i),Math.max(s,a.size/i))}}if(e instanceof Kt){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 xn(Math.max(o,i),Math.max(s,u))}if(e instanceof qt){let a=0,i=0,u=0,l=0,c=0;for(let f of e.members){let m=this._getTypeSize(f.type);m!==null&&(a=Math.max(m.align,a),u=this._roundUp(m.align,u+l),l=m.size,c=u)}return i=this._roundUp(a,c+l),new xn(Math.max(o,a),Math.max(s,i))}return null}_isUniformVar(e){return e instanceof Nt&&e.storage=="uniform"}_isStorageVar(e){return e instanceof Nt&&e.storage=="storage"}_isTextureVar(e){return e instanceof Nt&&e.type!==null&&t._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof Nt&&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}};Dr._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}},Dr._textureTypes=h.any_texture_type.map(t=>t.name),Dr._samplerTypes=h.sampler_type.map(t=>t.name);var su=0,Yi=class t{constructor(e,r,n){this.id=su++,this.name=e,this.value=r,this.node=n}clone(){return new t(this.name,this.value,this.node)}},qi=class t{constructor(e){this.id=su++,this.name=e.name,this.node=e}clone(){return new t(this.node)}},Ki=class t{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName="",this.id=su++,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 Yi(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)}},Zi=class{evalExpression(e,r){return null}getTypeInfo(e){return null}getVariableName(e,r){return""}},Ji=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 d)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 d){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 Ee&&(n=n.right);let s=this.exec.evalExpression(n,r);if(s instanceof Le&&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 d)return new d(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 d)return new d(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 d)return new d(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 d)return new d(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 d)return new d(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 d)return new d(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 d)return new d(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 d&&s instanceof d)return new d(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 d)return new d(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 d&&s instanceof d&&o instanceof d)return new d(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 d)return new d(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 d)return new d(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 d)return new d(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 d)return new d(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 d)return new d(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 d&&s instanceof d){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 d([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 d?new d(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 d&&s instanceof d){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 d&&s instanceof d?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 d)return new d(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 d)return new d(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 d)return new d(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 d&&s instanceof d&&o instanceof d){let a=this._dot(s.data,o.data);return new d(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 d)return new d(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 d)return new d(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 d)return new d(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 d&&s instanceof d&&o instanceof d)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 d(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 d)return new d(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 d&&s instanceof d)return new d(n.data.map((m,p)=>m&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 d)return new d(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 d){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 d)return new d(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 d)return new d(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 d&&s instanceof d)return new d(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 d&&s instanceof d)return new d(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 d&&s instanceof d&&o instanceof d)return new d(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 d&&s instanceof d)return new d(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 d){let s=this.Length(e,r).value;return new d(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 d&&s instanceof d)return new d(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 d?new d(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 d?new d(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 d&&s instanceof d){let o=this._dot(n.data,s.data);return new d(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 d&&s instanceof d&&o instanceof y){let a=this._dot(s.data,n.data);return new d(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 d)return new d(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 d)return new d(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 d)return new d(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 d)return new d(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 d)return new d(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 d&&n instanceof d&&s instanceof d)return new d(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 d)return new d(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 d&&n instanceof d)return new d(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 d)return new d(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 d)return new d(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 d)return new d(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 Qe){let o=n.name,a=r.getVariableValue(o);if(a instanceof ar){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 d(i,this.getTypeInfo("vec3u")):u==="2d"?new d(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),o=e.args.length>2?this.exec.evalExpression(e.args[2],r).value:0;if(!(s instanceof d)||s.data.length!==2)return console.error(`Invalid UV argument for textureLoad. Line ${e.line}`),null;if(n instanceof Qe){let a=n.name,i=r.getVariableValue(a);if(i instanceof ar){let u=Math.floor(s.data[0]),l=Math.floor(s.data[1]);if(u<0||u>=i.width||l<0||l>=i.height)return console.error(`Texture ${a} out of bounds. Line ${e.line}`),null;let c=i.getPixel(u,l,0,o);return c===null?(console.error(`Invalid texture format for textureLoad. Line ${e.line}`),null):new d(c,this.getTypeInfo("vec4f"))}return console.error(`Texture ${a} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureLoad. Line ${e.line}`),null}TextureNumLayers(e,r){let n=e.args[0];if(n instanceof Qe){let s=n.name,o=r.getVariableValue(s);return o instanceof ar?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 Qe){let s=n.name,o=r.getVariableValue(s);return o instanceof ar?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 Qe){let s=n.name,o=r.getVariableValue(s);return o instanceof ar?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 d)||s.data.length!==2)return console.error(`Invalid UV argument for textureStore. Line ${e.line}`),null;if(n instanceof Qe){let i=n.name,u=r.getVariableValue(i);if(u instanceof ar){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 y&&i instanceof y&&(u.value=i.value),o.value instanceof Le&&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 y(u.value,u.typeInfo);return u instanceof y&&i instanceof y&&(u.value+=i.value),o.value instanceof Le&&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 y(u.value,u.typeInfo);return u instanceof y&&i instanceof y&&(u.value-=i.value),o.value instanceof Le&&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 y(u.value,u.typeInfo);return u instanceof y&&i instanceof y&&(u.value=Math.max(u.value,i.value)),o.value instanceof Le&&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 y(u.value,u.typeInfo);return u instanceof y&&i instanceof y&&(u.value=Math.min(u.value,i.value)),o.value instanceof Le&&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 y(u.value,u.typeInfo);return u instanceof y&&i instanceof y&&(u.value=u.value&i.value),o.value instanceof Le&&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 y(u.value,u.typeInfo);return u instanceof y&&i instanceof y&&(u.value=u.value|i.value),o.value instanceof Le&&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 y(u.value,u.typeInfo);return u instanceof y&&i instanceof y&&(u.value=u.value^i.value),o.value instanceof Le&&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 y(u.value,u.typeInfo);return u instanceof y&&i instanceof y&&(u.value=i.value),o.value instanceof Le&&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}},Ci={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},Je={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]},vn=class t extends Zi{constructor(e,r){var n;super(),this.ast=e??[],this.reflection=new Dr,this.reflection.updateAST(this.ast),this.context=(n=r?.clone())!==null&&n!==void 0?n:new Ki,this.builtins=new Ji(this),this.typeInfo={bool:this.getTypeInfo(R.bool),i32:this.getTypeInfo(R.i32),u32:this.getTypeInfo(R.u32),f32:this.getTypeInfo(R.f32),f16:this.getTypeInfo(R.f16),vec2f:this.getTypeInfo(_.vec2f),vec2u:this.getTypeInfo(_.vec2u),vec2i:this.getTypeInfo(_.vec2i),vec2h:this.getTypeInfo(_.vec2h),vec3f:this.getTypeInfo(_.vec3f),vec3u:this.getTypeInfo(_.vec3u),vec3i:this.getTypeInfo(_.vec3i),vec3h:this.getTypeInfo(_.vec3h),vec4f:this.getTypeInfo(_.vec4f),vec4u:this.getTypeInfo(_.vec4u),vec4i:this.getTypeInfo(_.vec4i),vec4h:this.getTypeInfo(_.vec4h),mat2x2f:this.getTypeInfo(_.mat2x2f),mat2x3f:this.getTypeInfo(_.mat2x3f),mat2x4f:this.getTypeInfo(_.mat2x4f),mat3x2f:this.getTypeInfo(_.mat3x2f),mat3x3f:this.getTypeInfo(_.mat3x3f),mat3x4f:this.getTypeInfo(_.mat3x4f),mat4x2f:this.getTypeInfo(_.mat4x2f),mat4x3f:this.getTypeInfo(_.mat4x3f),mat4x4f:this.getTypeInfo(_.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 d||s instanceof H)return Array.from(s.data);if(s instanceof Le&&s.typeInfo instanceof Kt){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 d(r,c));for(let f in n)for(let m in n[f]){let p=n[f][m];o.variables.forEach(w=>{var A;let v=w.node;if(v?.attributes){let C=null,k=null;for(let T of v.attributes)T.name==="binding"?C=T.value:T.name==="group"&&(k=T.value);if(m==C&&f==k)if(p.texture!==void 0&&p.descriptor!==void 0){let T=new ar(p.texture,this.getTypeInfo(v.type),p.descriptor,(A=p.texture.view)!==null&&A!==void 0?A:null);w.value=T}else p.uniform!==void 0?w.value=new Le(p.uniform,this.getTypeInfo(v.type)):w.value=new Le(p,this.getTypeInfo(v.type))}})}for(let f=0;f<l;++f)for(let m=0;m<u;++m)for(let p=0;p<i;++p)o.setVariable("@workgroup_id",new d([p,m,f],this.getTypeInfo("vec3u"))),this._dispatchWorkgroup(a,[p,m,f],o)}execStatement(e,r){if(e instanceof go)return this.evalExpression(e.value,r);if(e instanceof yo){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 _o)return t._continueObj;if(e instanceof Pr)this._let(e,r);else if(e instanceof Nt)this._var(e,r);else if(e instanceof yn)this._const(e,r);else if(e instanceof Mr)this._function(e,r);else{if(e instanceof po)return this._if(e,r);if(e instanceof mo)return this._switch(e,r);if(e instanceof co)return this._for(e,r);if(e instanceof uo)return this._while(e,r);if(e instanceof ho)return this._loop(e,r);if(e instanceof Jn){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 lo)this._increment(e,r);else{if(e instanceof Mt)return null;if(e instanceof Qn){let n=e.name;r.getVariable(n)===null&&r.setVariable(n,new y(0,this.getTypeInfo("u32")))}else if(e instanceof es)this._call(e,r);else{if(e instanceof xo||e instanceof ts)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 Ce?this._evalLiteral(e,r):e instanceof Qe?this._evalVariable(e,r):e instanceof rs?this._evalCall(e,r):e instanceof At?this._evalCreate(e,r):e instanceof vo?this._evalConst(e,r):e instanceof wo?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 R){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")),o.type.name==="u32"||o.type.name==="i32"||o.type.name==="f32"||o.type.name==="f16"?r.setVariable(n,new y(s,o.type)):o.type.name==="bool"?r.setVariable(n,new y(s?1:0,o.type)):o.type.name==="vec2"||o.type.name==="vec3"||o.type.name==="vec4"||o.type.name==="vec2f"||o.type.name==="vec3f"||o.type.name==="vec4f"||o.type.name==="vec2i"||o.type.name==="vec3i"||o.type.name==="vec4i"||o.type.name==="vec2u"||o.type.name==="vec3u"||o.type.name==="vec4u"||o.type.name==="vec2h"||o.type.name==="vec3h"||o.type.name==="vec4h"?r.setVariable(n,new d(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 d(s,o));let i=s[0],u=s[1],l=s[2];for(let c=0,f=0;c<l;++c)for(let m=0;m<u;++m)for(let p=0;p<i;++p,++f){let w=[p,m,c],A=[p+r[0]*s[0],m+r[1]*s[1],c+r[2]*s[2]];n.setVariable("@local_invocation_id",new d(w,o)),n.setVariable("@global_invocation_id",new d(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 Ee;)e=e.right;return e instanceof Qe?e.name:(console.error("Unknown variable type",e,"Line",e.line),null)}_execStatements(e,r){for(let n of e){if(n instanceof Array){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 Qe){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 kr?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 kr(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 y||u instanceof d||u instanceof H){if(l instanceof y||l instanceof d||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 Le&&l instanceof Le&&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 d||u instanceof H?l instanceof y||l instanceof d||l instanceof H?void u.data.set(l.data.map((f,m)=>u.data[m]+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 d||u instanceof H)&&(l instanceof y||l instanceof d||l instanceof H)?void u.data.set(l.data.map((f,m)=>u.data[m]-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 kr))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 kr&&(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==="=")if(n instanceof Le)n.setDataValue(this,a,o,r);else if(o){if(!(n instanceof d||n instanceof H))return void console.error(`Variable ${s} is not a vector or matrix. Line ${e.line}`);if(o instanceof Er){let u=this.evalExpression(o.index,r).value;if(n instanceof d){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 d))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 ur){let u=o.value;if(!(n instanceof d))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 d))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 d&&a instanceof d||n instanceof H&&a instanceof H?n.data.set(a.data):console.error(`Invalid assignment to ${s}. Line ${e.line}`);else{let u=n.getSubData(this,o,r);if(u instanceof d&&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 d&&a instanceof d){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}`)}n instanceof Le&&n.setDataValue(this,u,o,r)}}_function(e,r){let n=new qi(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)}_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(s==="f32"||s==="i32"||s==="u32"||s==="bool"||s==="f16"||s==="vec2"||s==="vec3"||s==="vec4"||s==="vec2f"||s==="vec3f"||s==="vec4f"||s==="vec2i"||s==="vec3i"||s==="vec4i"||s==="vec2u"||s==="vec3u"||s==="vec4u"||s==="vec2h"||s==="vec3h"||s==="vec4h"||s==="vec2b"||s==="vec3b"||s==="vec4b"||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"||s==="array"){let o=new At(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(s==="f32"||s==="i32"||s==="u32"||s==="bool"||s==="f16"||s==="vec2"||s==="vec3"||s==="vec4"||s==="vec2f"||s==="vec3f"||s==="vec4f"||s==="vec2i"||s==="vec3i"||s==="vec4i"||s==="vec2u"||s==="vec3u"||s==="vec4u"||s==="vec2h"||s==="vec3h"||s==="vec4h"||s==="vec2b"||s==="vec3b"||s==="vec4b"||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"||e.type instanceof Or||e.type instanceof Mt||e.type instanceof _){let o=new At(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 Eo)for(let a of o.selectors){if(a instanceof bn){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 Ao&&(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=qf(n.value,n.typeInfo.name,s.name);return new y(o,this.getTypeInfo(s))}if(n instanceof d){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,m){if(f===m)return c;let p=new Array(c.length);for(let w=0;w<c.length;w++)p[w]=qf(c[w],f,m);return p}(Array.from(n.data),a,u);return new d(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 At){if(e.type===null)return ns.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 At?e.type.name:e.name,o=e instanceof At?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 Le(new ArrayBuffer(o.size),o,0);if(o instanceof qt){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 Kt){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 At?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 kr(n);if(e.operator==="*")return n instanceof kr?n.reference.getSubData(this,e.postfix,r):(console.error(`Invalid dereference. Line ${e.line}`),null);let s=n instanceof y?n.value:n instanceof d?Array.from(n.data):null;switch(e.operator){case"+":{if(L(s)){let i=s.map((u,l)=>+u);return new d(i,n.typeInfo)}let o=s,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new y(+o,a)}case"-":{if(L(s)){let i=s.map((u,l)=>-u);return new d(i,n.typeInfo)}let o=s,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new y(-o,a)}case"!":{if(L(s)){let i=s.map((u,l)=>u?0:1);return new d(i,n.typeInfo)}let o=s,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new y(o?0:1,a)}case"~":{if(L(s)){let i=s.map((u,l)=>~u);return new d(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}_evalBinaryOp(e,r){let n=this.evalExpression(e.left,r),s=this.evalExpression(e.right,r),o=n instanceof y?n.value:n instanceof d||n instanceof H?Array.from(n.data):null,a=s instanceof y?s.value:s instanceof d||s instanceof H?Array.from(s.data):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 m=c.map((p,w)=>p+f[w]);return new d(m,n.typeInfo)}if(L(o)){let c=a,f=o.map((m,p)=>m+c);return new d(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((m,p)=>c+m);return new d(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(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 m=c.map((p,w)=>p-f[w]);return new d(m,n.typeInfo)}if(L(o)){let c=a,f=o.map((m,p)=>m-c);return new d(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((m,p)=>c-m);return new d(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(i-u,l)}case"*":{if(L(o)&&L(a)){let c=o,f=a;if(n instanceof H&&s instanceof H){let m=function(v,C,k,T){if(Je[C.name]===void 0||Je[T.name]===void 0)return null;let S=Je[C.name][0],F=Je[C.name][1],B=Je[T.name][0];if(S!==Je[T.name][1])return null;let z=new Array(B*F);for(let N=0;N<F;N++)for(let U=0;U<B;U++){let V=0;for(let P=0;P<S;P++)V+=v[P*F+N]*k[U*S+P];z[N*B+U]=V}return z}(c,n.typeInfo,f,s.typeInfo);if(m===null)return console.error(`Matrix multiplication failed. Line ${e.line}.`),null;let p=Je[s.typeInfo.name][0],w=Je[n.typeInfo.name][1],A=this.getTypeInfo(`mat${p}x${w}f`);return new H(m,A)}if(n instanceof H&&s instanceof d){let m=function(p,w,A,v){if(Je[w.name]===void 0||Ci[v.name]===void 0)return null;let C=Je[w.name][0],k=Je[w.name][1];if(C!==A.length)return null;let T=new Array(k);for(let S=0;S<k;S++){let F=0;for(let B=0;B<C;B++)F+=p[B*k+S]*A[B];T[S]=F}return T}(c,n.typeInfo,f,s.typeInfo);return m===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new d(m,s.typeInfo)}if(n instanceof d&&s instanceof H){let m=function(p,w,A,v){if(Ci[w.name]===void 0||Je[v.name]===void 0)return null;let C=Je[v.name][0],k=Je[v.name][1];if(k!==p.length)return null;let T=[];for(let S=0;S<C;S++){let F=0;for(let B=0;B<k;B++)F+=p[B]*A[B*C+S];T[S]=F}return T}(c,n.typeInfo,f,s.typeInfo);return m===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new d(m,n.typeInfo)}{if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let m=c.map((p,w)=>p*f[w]);return new d(m,n.typeInfo)}}if(L(o)){let c=a,f=o.map((m,p)=>m*c);return n instanceof H?new H(f,n.typeInfo):new d(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((m,p)=>c*m);return s instanceof H?new H(f,s.typeInfo):new d(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(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 m=c.map((p,w)=>p%f[w]);return new d(m,n.typeInfo)}if(L(o)){let c=a,f=o.map((m,p)=>m%c);return new d(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((m,p)=>c%m);return new d(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(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 m=c.map((p,w)=>p/f[w]);return new d(m,n.typeInfo)}if(L(o)){let c=a,f=o.map((m,p)=>m/c);return new d(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((m,p)=>c/m);return new d(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(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 m=c.map((p,w)=>p&f[w]);return new d(m,n.typeInfo)}if(L(o)){let c=a,f=o.map((m,p)=>m&c);return new d(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((m,p)=>c&m);return new d(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(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 m=c.map((p,w)=>p|f[w]);return new d(m,n.typeInfo)}if(L(o)){let c=a,f=o.map((m,p)=>m|c);return new d(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((m,p)=>c|m);return new d(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(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 m=c.map((p,w)=>p^f[w]);return new d(m,n.typeInfo)}if(L(o)){let c=a,f=o.map((m,p)=>m^c);return new d(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((m,p)=>c^m);return new d(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(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 m=c.map((p,w)=>p<<f[w]);return new d(m,n.typeInfo)}if(L(o)){let c=a,f=o.map((m,p)=>m<<c);return new d(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((m,p)=>c<<m);return new d(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(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 m=c.map((p,w)=>p>>f[w]);return new d(m,n.typeInfo)}if(L(o)){let c=a,f=o.map((m,p)=>m>>c);return new d(f,n.typeInfo)}if(L(a)){let c=o,f=a.map((m,p)=>c>>m);return new d(f,s.typeInfo)}let i=o,u=a,l=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new y(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 d(l,n.typeInfo)}if(L(o)){let i=a,u=o.map((l,c)=>l>i?1:0);return new d(u,n.typeInfo)}if(L(a)){let i=o,u=a.map((l,c)=>i>l?1:0);return new d(u,s.typeInfo)}return new y(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 d(l,n.typeInfo)}if(L(o)){let i=a,u=o.map((l,c)=>l<i?1:0);return new d(u,n.typeInfo)}if(L(a)){let i=o,u=a.map((l,c)=>i<l?1:0);return new d(u,s.typeInfo)}return new y(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 d(l,n.typeInfo)}if(L(o)){let i=a,u=o.map((l,c)=>l==i?1:0);return new d(u,n.typeInfo)}if(L(a)){let i=o,u=a.map((l,c)=>i==l?1:0);return new d(u,s.typeInfo)}return new y(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 d(l,n.typeInfo)}if(L(o)){let i=a,u=o.map((l,c)=>l!==i?1:0);return new d(u,n.typeInfo)}if(L(a)){let i=o,u=a.map((l,c)=>i!==l?1:0);return new d(u,s.typeInfo)}return new y(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 d(l,n.typeInfo)}if(L(o)){let i=a,u=o.map((l,c)=>l>=i?1:0);return new d(u,n.typeInfo)}if(L(a)){let i=o,u=a.map((l,c)=>i>=l?1:0);return new d(u,s.typeInfo)}return new y(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 d(l,n.typeInfo)}if(L(o)){let i=a,u=o.map((l,c)=>l<=i?1:0);return new d(u,n.typeInfo)}if(L(a)){let i=o,u=a.map((l,c)=>i<=l?1:0);return new d(u,s.typeInfo)}return new y(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 d(l,n.typeInfo)}if(L(o)){let i=a,u=o.map((l,c)=>l&&i?1:0);return new d(u,n.typeInfo)}if(L(a)){let i=o,u=a.map((l,c)=>i&&l?1:0);return new d(u,s.typeInfo)}return new y(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 d(l,n.typeInfo)}if(L(o)){let i=a,u=o.map((l,c)=>l||i?1:0);return new d(u,n.typeInfo)}if(L(a)){let i=o,u=a.map((l,c)=>i||l?1:0);return new d(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=Ci[s];if(o===void 0)return console.error(`Invalid vec constructor ${s}. Line ${e.line}`),null;let a=[];if(e instanceof Ce)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 d){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 _&&e.type.format===null&&(e.type.format=_.f32),a.length===0){let i=new Array(o).fill(0);return new d(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 d(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=Je[s];if(o===void 0)return console.error(`Invalid matrix constructor ${s}. Line ${e.line}`),null;let a=[];if(e instanceof Ce)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 d?a.push(...u.data):u instanceof y?a.push(u.value):u instanceof H&&a.push(...u.data)}if(n instanceof ir&&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)}};vn._breakObj=new It(new st("BREAK",null),null),vn._continueObj=new It(new st("CONTINUE",null),null),vn._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);var Qi=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},eu=class{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new Qi,this._exec=new vn,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 Qe){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 Io||s instanceof _n?s.type=this._forwardType(s.type):s instanceof Or?s.format=this._forwardType(s.format):s instanceof Nt||s instanceof Pr||s instanceof yn?s.type=this._forwardType(s.type):s instanceof Mr?s.returnType=this._forwardType(s.returnType):s instanceof Ro&&(s.type=this._forwardType(s.type))});return r}_forwardType(e){if(e instanceof bo){let r=this._getType(e.name);if(r)return r}else e instanceof _n?e.type=this._forwardType(e.type):e instanceof Or&&(e.format=this._forwardType(e.format));return e}_initialize(e){if(e)if(typeof e=="string"){let r=new Xi(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{token:e,message:r,toString:()=>`${r}`}}_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}. Line:${this._currentLine}`)}_check(e){if(this._isAtEnd())return!1;let r=this._peek();if(e instanceof Array){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.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 Ro(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 Mr(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 zi);else if(this._match(h.keywords.break)){let r=this._updateNode(new yo);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 _o);if(!(this._currentLoop.length>0))throw this._error(this._peek(),`Continue statement must be inside a loop. Line: ${r.line}`);{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 Vi(r),e)}_while_statement(){if(!this._match(h.keywords.while))return null;let e=this._updateNode(new uo(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 Jn(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 co(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 Nt(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 Pr(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 Ce&&(n=s.type),this._updateNode(new yn(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 lo(n.type===h.tokens.plus_plus?gn.increment:gn.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(Kn.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 es(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 ho([],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 Jn){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 mo(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 bn){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 Eo(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 Ao(n)))}}return e}_case_selectors(){let e=[];for(this._match(h.keywords.default)?e.push(this._updateNode(new bn)):e.push(this._shift_expression());this._match(h.tokens.comma);)this._match(h.keywords.default)?e.push(this._updateNode(new bn)):e.push(this._shift_expression());return e}_case_body(){if(this._match(h.keywords.fallthrough))return this._consume(h.tokens.semicolon,"Expected ';'"),[];let e=this._statement();if(e==null)return[];e instanceof Array||(e=[e]);let 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 po(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 Hi(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 go(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 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 Er(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 ur(e.lexeme));return r&&(n.postfix=r),n}return null}_getStruct(e){return this._context.aliases.has(e)?this._context.aliases.get(e).type:this._context.structs.has(e)?this._context.structs.get(e):null}_getType(e){let r=this._getStruct(e);if(r!==null)return r;switch(e){case"void":return R.void;case"bool":return R.bool;case"i32":return R.i32;case"u32":return R.u32;case"f32":return R.f32;case"f16":return R.f16;case"vec2f":return _.vec2f;case"vec3f":return _.vec3f;case"vec4f":return _.vec4f;case"vec2i":return _.vec2i;case"vec3i":return _.vec3i;case"vec4i":return _.vec4i;case"vec2u":return _.vec2u;case"vec3u":return _.vec3u;case"vec4u":return _.vec4u;case"vec2h":return _.vec2h;case"vec3h":return _.vec3h;case"vec4h":return _.vec4h;case"mat2x2f":return _.mat2x2f;case"mat2x3f":return _.mat2x3f;case"mat2x4f":return _.mat2x4f;case"mat3x2f":return _.mat3x2f;case"mat3x3f":return _.mat3x3f;case"mat3x4f":return _.mat3x4f;case"mat4x2f":return _.mat4x2f;case"mat4x3f":return _.mat4x3f;case"mat4x4f":return _.mat4x4f;case"mat2x2h":return _.mat2x2h;case"mat2x3h":return _.mat2x3h;case"mat2x4h":return _.mat2x4h;case"mat3x2h":return _.mat3x2h;case"mat3x3h":return _.mat3x3h;case"mat3x4h":return _.mat3x4h;case"mat4x2h":return _.mat4x2h;case"mat4x3h":return _.mat4x3h;case"mat4x4h":return _.mat4x4h;case"mat2x2i":return _.mat2x2i;case"mat2x3i":return _.mat2x3i;case"mat2x4i":return _.mat2x4i;case"mat3x2i":return _.mat3x2i;case"mat3x3i":return _.mat3x3i;case"mat3x4i":return _.mat3x4i;case"mat4x2i":return _.mat4x2i;case"mat4x3i":return _.mat4x3i;case"mat4x4i":return _.mat4x4i;case"mat2x2u":return _.mat2x2u;case"mat2x3u":return _.mat2x3u;case"mat2x4u":return _.mat2x4u;case"mat3x2u":return _.mat3x2u;case"mat3x3u":return _.mat3x3u;case"mat3x4u":return _.mat3x4u;case"mat4x2u":return _.mat4x2u;case"mat4x3u":return _.mat4x3u;case"mat4x4u":return _.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}. Line: ${this._currentLine}.`)}else if(r.name==="u32"&&(e<0||e>4294967295))throw this._error(this._previous(),`Value out of range for u32: ${e}. Line: ${this._currentLine}.`)}_primary_expression(){if(this._match(h.tokens.ident)){let n=this._previous().toString();if(this._check(h.tokens.paren_left)){let s=this._argument_expression_list(),o=this._getType(n);return o!==null?this._updateNode(new At(o,s)):this._updateNode(new rs(n,s))}if(this._context.constants.has(n)){let s=this._context.constants.get(n);return this._updateNode(new vo(n,s.value))}return this._updateNode(new Qe(n))}if(this._match(h.tokens.int_literal)){let n=this._previous().toString(),s=n.endsWith("i")||n.endsWith("i")?R.i32:n.endsWith("u")||n.endsWith("U")?R.u32:R.x32,o=parseInt(n);return this._validateTypeRange(o,s),this._updateNode(new Ce(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,R.u32),this._updateNode(new Ce(new y(n,this._exec.getTypeInfo(R.u32)),R.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?R.f16:R.f32);let a=s?R.f16:R.f32;return this._updateNode(new Ce(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 Ce(new y(n?1:0,this._exec.getTypeInfo(R.bool)),R.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 wo(n,s))}let e=this._type_decl(),r=this._argument_expression_list();return this._updateNode(new At(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 agument list"),e}_optional_paren_expression(){this._match(h.tokens.paren_left);let e=this._short_circuit_or_expression();return this._match(h.tokens.paren_right),e}_paren_expression(){this._consume(h.tokens.paren_left,"Expected '('.");let e=this._short_circuit_or_expression();return this._consume(h.tokens.paren_right,"Expected ')'."),e}_struct_decl(){if(!this._match(h.keywords.struct))return null;let e=this._currentLine,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 Io(i,l,a)))}this._consume(h.tokens.brace_right,"Expected '}' after struct body.");let s=this._currentLine,o=this._updateNode(new Mt(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 Ce){if(e.value.type.name!=="x32"&&e.type.getTypeName()!==e.value.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${e.value.type.name} to ${e.type.name}. Line:${this._currentLine}`);e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type),e.value.type=e.type}else e.type===null&&e.value instanceof Ce&&(e.type=e.value.type.name==="x32"?R.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=[R.f32],l=a.constEvaluate(this._exec,u);l instanceof y&&this._validateTypeRange(l.value,u[0]),u[0]instanceof _&&u[0].format===null&&l.typeInfo instanceof ir&&l.typeInfo.format!==null&&(l.typeInfo.format.name==="f16"?u[0].format=R.f16:l.typeInfo.format.name==="f32"?u[0].format=R.f32:l.typeInfo.format.name==="i32"?u[0].format=R.i32:l.typeInfo.format.name==="u32"?u[0].format=R.u32:l.typeInfo.format.name==="bool"?u[0].format=R.bool:console.error(`TODO: impelement template format type ${l.typeInfo.format.name}`)),o=this._updateNode(new Ce(l,u[0])),this._exec.context.setVariable(r.toString(),l)}catch{o=a}if(s!==null&&o instanceof Ce){if(o.type.name!=="x32"&&s.getTypeName()!==o.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${o.type.name} to ${s.name}. Line:${this._currentLine}`);o.type=s,o.isScalar&&this._validateTypeRange(o.scalarValue,o.type)}else s===null&&o instanceof Ce&&(s=(e=o?.type)!==null&&e!==void 0?e:R.f32,s===R.x32&&(s=R.i32));let i=this._updateNode(new yn(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 Ce){if(s.type.name!=="x32"&&n.getTypeName()!==s.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${s.type.name} to ${n.name}. Line:${this._currentLine}`);s.type=n}else n===null&&s instanceof Ce&&(n=s.type.name==="x32"?R.i32:s.type);return s instanceof Ce&&s.isScalar&&this._validateTypeRange(s.scalarValue,n),this._updateNode(new Pr(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 Nt(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 Qn(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 xo(e.toString(),r))}_enable_directive(){let e=this._consume(h.tokens.ident,"identity expected.");return this._updateNode(new Wi(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 $i(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 ts(e.toString(),r));return this._context.aliases.set(n.name,n),n}_type_decl(){if(this._check([h.tokens.ident,...h.texel_format,h.keywords.bool,h.keywords.f32,h.keywords.i32,h.keywords.u32])){let n=this._advance().toString();if(this._context.structs.has(n))return this._context.structs.get(n);if(this._context.aliases.has(n))return this._context.aliases.get(n).type;if(!this._getType(n)){let s=this._updateNode(new bo(n));return this._forwardTypeCount++,s}return this._updateNode(new R(n))}let e=this._texture_sampler_types();if(e)return e;if(this._check(h.template_types)){let n=this._advance().toString(),s=null,o=null;return this._match(h.tokens.less_than)&&(s=this._type_decl(),o=null,this._match(h.tokens.comma)&&(o=this._consume(h.access_mode,"Expected access_mode for pointer").toString()),this._consume(h.tokens.greater_than,"Expected '>' for type.")),this._updateNode(new _(n,s,o))}if(this._match(h.keywords.ptr)){let n=this._previous().toString();this._consume(h.tokens.less_than,"Expected '<' for pointer.");let s=this._consume(h.storage_class,"Expected storage_class for pointer");this._consume(h.tokens.comma,"Expected ',' for pointer.");let o=this._type_decl(),a=null;return this._match(h.tokens.comma)&&(a=this._consume(h.access_mode,"Expected access_mode for pointer").toString()),this._consume(h.tokens.greater_than,"Expected '>' for pointer."),this._updateNode(new _n(n,s.toString(),o,a))}let r=this._attribute();if(this._match(h.keywords.array)){let n=null,s=-1,o=this._previous(),a=null;if(this._match(h.tokens.less_than)){n=this._type_decl(),this._context.aliases.has(n.name)&&(n=this._context.aliases.get(n.name).type);let u="";if(this._match(h.tokens.comma)){a=this._shift_expression();try{u=a.constEvaluate(this._exec).toString(),a=null}catch{u="1"}}this._consume(h.tokens.greater_than,"Expected '>' for array."),s=u?parseInt(u):0}let i=this._updateNode(new Or(o.toString(),r,n,s));return a&&this._deferArrayCountEval.push({arrayType:i,countNode:a}),i}return null}_texture_sampler_types(){if(this._match(h.sampler_type))return this._updateNode(new Lr(this._previous().toString(),null,null));if(this._match(h.depth_texture_type))return this._updateNode(new Lr(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 Lr(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 Lr(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 So(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();n.value instanceof Array||(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}},tu=class extends Dr{constructor(e){super(),e&&this.update(e)}update(e){let r=new eu().parse(e);this.updateAST(r)}};function mn(t,e){return Object.fromEntries(e.map(r=>{let n=Ym(t,r,0);return[r.name,{typeDefinition:n,group:r.group,binding:r.binding,size:n.size}]}))}function rh(t,e,r){return{fields:Object.fromEntries(e.members.map(s=>[s.name,{offset:s.offset,type:ou(t,s.type,0)}])),size:e.size,offset:r}}function zm(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 Kf(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 Hm(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 Xm(t){return t.name.endsWith("_comparison")?"comparison":"filtering"}function jm(t,e){let{binding:r,access:n,type:s}=t;switch(t.resourceType){case Ne.Uniform:return{binding:r,visibility:e,buffer:{...t.size&&{minBindingSize:t.size}}};case Ne.Storage:return{binding:r,visibility:e,buffer:{type:n===""||n==="read"?"read-only-storage":"storage",...t.size&&{minBindingSize:t.size}}};case Ne.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:zm(s),viewDimension:Kf(s),multisampled:o}}}case Ne.Sampler:return{binding:r,visibility:e,sampler:{type:Xm(s)}};case Ne.StorageTexture:return{binding:r,visibility:e,storageTexture:{access:Hm(s),format:s.format.name,viewDimension:Kf(s)}};default:throw new Error("unknown resource type")}}function Fi(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:jm(s,e)}})};return r}function St(t){let e=new tu(t),r=Object.fromEntries(e.structs.map(c=>[c.name,rh(e,c,0)])),n=mn(e,e.uniforms),s=mn(e,e.storage.filter(c=>c.resourceType===Ne.Storage)),o=mn(e,e.storage.filter(c=>c.resourceType===Ne.StorageTexture)),a=mn(e,e.textures.filter(c=>c.type.name!=="texture_external")),i=mn(e,e.textures.filter(c=>c.type.name==="texture_external")),u=mn(e,e.samplers),l={...Fi(e.entry.vertex,GPUShaderStage.VERTEX),...Fi(e.entry.fragment,GPUShaderStage.FRAGMENT),...Fi(e.entry.compute,GPUShaderStage.COMPUTE)};return{externalTextures:i,samplers:u,structs:r,storages:s,storageTextures:o,textures:a,uniforms:n,entryPoints:l}}function Bi(t,e=""){if(!t)throw new Error(e)}function Ym(t,e,r){switch(e.resourceType){case Ne.Uniform:case Ne.Storage:case Ne.StorageTexture:return ou(t,e.type,r);default:return{size:0,type:e.type.name}}}function ou(t,e,r){if(e.isArray){Bi(!e.isStruct,"struct array is invalid"),Bi(!e.isStruct,"template array is invalid");let n=e;return{size:n.size,elementType:ou(t,n.format,r),numElements:n.count}}else{if(e.isStruct)return Bi(!e.isTemplate,"template struct is invalid"),rh(t,e,r);{let n=e,s=e.isTemplate?`${n.name}<${n.format.name}>`:e.name;return{size:e.size,type:s}}}}var qm=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}]]),i0=new Map([...qm.entries()].map(([t,{formats:[e,r]}])=>[[e,t],[r,t]]).flat());var u0={"8snorm":Int8Array,"8unorm":Uint8Array,"8sint":Int8Array,"8uint":Uint8Array,"16snorm":Int16Array,"16unorm":Uint16Array,"16sint":Int16Array,"16uint":Uint16Array,"32snorm":Int32Array,"32unorm":Uint32Array,"32sint":Int32Array,"32uint":Uint32Array,"16float":Float16Array,"32float":Float32Array};var au=t=>t.features.has("texture-formats-tier1"),iu=t=>t.features.has("shader-f16"),nh=async t=>{let e=[];return au(t)&&e.push("texture-formats-tier1"),iu(t)&&e.push("shader-f16"),await t?.requestDevice({requiredFeatures:e})};function sh(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 Km=/const WORKGROUP_SIZE_X(\s*)=(\s*)\d+u*;/,Zm=/const WORKGROUP_SIZE_Y(\s*)=(\s*)\d+u*;/,Nr=(t,{workgroupSizeX:e,workgroupSizeY:r})=>t.replace(Km,`const WORKGROUP_SIZE_X$1=$2${e}u;`).replace(Zm,`const WORKGROUP_SIZE_Y$1=$2${r}u;`),Jm=/texture_storage_2d<\w+,(\s*)write>/,Zt=(t,e)=>t.replace(Jm,`texture_storage_2d<${e},$1write>`),Qm=/alias float(\s*)=(\s*)f32;/,ss=t=>t.replace(Qm,"enable f16;alias float$1=$2f16;");var oh="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 Ar=(t,e,r,n,s,o)=>{let a=Zt(oh,s),i=16,u=16,l=Math.ceil(r/i),c=Math.ceil(n/u);a=Nr(a,{workgroupSizeX:i,workgroupSizeY:u});let f=St(a),m=gt(f.uniforms.params),p=t.createBuffer({size:m.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});m.set({outWidth:r,outHeight:n}),t.queue.writeBuffer(p,0,m.arrayBuffer);let w=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:w}}),v=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}),C=v.createView(),k=t.createSampler({magFilter:o,minFilter:o,addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}),T=null,S=null;return{render(F,B){return I(!e(),O.ContextLost),B!==S&&(T=t.createBindGroup({layout:A.getBindGroupLayout(0),entries:[{binding:0,resource:k},{binding:1,resource:B.createView()},{binding:2,resource:C},{binding:3,resource:{buffer:p}}]}),S=B),F.setPipeline(A),F.setBindGroup(0,T),F.dispatchWorkgroups(l,c),v},release(){p.destroy(),v.destroy(),T=null,S=null}}};var Lo=(t,e,r,n,s,o)=>{let a=new Map,i=Ar(t,e,n,s,r,o),u=(l,c)=>{let f=`${l}x${c}`,m=a.get(f);return m||(m=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,m)),m};return{render:(l,c)=>{I(!e(),O.ContextLost);let f=l instanceof VideoFrame?l.displayWidth:l.width,m=l instanceof VideoFrame?l.displayHeight:l.height,p=u(f,m);return t.queue.copyExternalImageToTexture({source:l,flipY:!1},{texture:p},{width:f,height:m}),i.render(c,p)},release:()=>{for(let l of a.values())l.destroy();a.clear(),i.release()}}};var uu="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 ah=(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=St(uu),a=gt(o.uniforms.thresholds),i=e.createShaderModule({label:"blender shader",code:uu}),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}),m=B=>{a.set({background:B.backgroundThreshold,foreground:B.foregroundThreshold}),e.queue.writeBuffer(f,0,a.arrayBuffer)},p={loadOp:"load",storeOp:"store"},w={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}}]}),v=null,C=null,k=null,T=null,S=-1,F=-1;return{render:(B,{foreground:z,background:N,mask:U},V)=>{I(!n(),O.ContextLost),p.view=s.getCurrentTexture().createView(),k===N&&T===z&&C===U||(v=e.createBindGroup({layout:u.getBindGroupLayout(1),entries:[{binding:0,resource:N.createView()},{binding:1,resource:z.createView()},{binding:2,resource:U.createView()}]}),k=N,T=z,C=U),S===V.backgroundThreshold&&F===V.foregroundThreshold||(m(V),S=V.backgroundThreshold,F=V.foregroundThreshold);let P=B.beginRenderPass(w);P.setPipeline(u),P.setBindGroup(0,A),P.setBindGroup(1,v),P.draw(6),P.end()},release:()=>{f.destroy(),S=-1,F=-1}}};var ih="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 ep=Et(1,9),cu=(t,e,r,n,s)=>{let o=t.createShaderModule({label:"dual blur compute shader",code:ih}),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=(F,B)=>t.createTexture({label:"dual filter blur texture",format:n,size:[F,B],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.RENDER_ATTACHMENT}),c=[],f=-1,m=-1,p=[],w=[],A=[],v=[],C=null,k=null,T=null;function S(F,B,z){let N=ep(F+1);if(c.length!==N||f!==B||m!==z){for(let U of c)U.texture.destroy();c=[],A=[],p=[],v=[],C=null,k=null;for(let U=0;U<N;U++){let V=Math.max(Math.trunc(B/2**U),1),P=Math.max(Math.trunc(z/2**U),1),te=l(V,P);c.push({texture:te,view:te.createView(),width:V,height:P})}for(let U=2;U<c.length;U++){let V=c[U-1],P=c[U];I(V),I(P),A.push(t.createBindGroup({layout:a.getBindGroupLayout(0),entries:[{binding:0,resource:u},{binding:1,resource:V.view}]})),p.push({label:`downsample render pass ${U}`,colorAttachments:[{loadOp:"load",storeOp:"store",view:P.view}]})}for(let U=c.length-2;U>=0;U--){let V=c[U+1],P=c[U];I(V),I(P),v.push(t.createBindGroup({layout:i.getBindGroupLayout(0),entries:[{binding:0,resource:u},{binding:1,resource:V.view}]})),w.push({label:`upsample render pass ${U}`,colorAttachments:[{loadOp:"load",storeOp:"store",view:P.view}]})}f=B,m=z}}return{render:(F,B,z)=>{I(!s(),O.ContextLost),S(z,e,r);let N=c[1];I(N),B!==C&&(k=t.createBindGroup({layout:a.getBindGroupLayout(0),entries:[{binding:0,resource:u},{binding:1,resource:B.createView()}]}),T={label:"downsample render pass 0",colorAttachments:[{loadOp:"load",storeOp:"store",view:N.view}]},C=B),I(T);let U=F.beginRenderPass(T);U.setPipeline(a),U.setBindGroup(0,k),U.draw(3),U.end();for(let P=2;P<c.length;P++){let te=c[P];I(te);let ue=A[P-2],me=p[P-2];I(ue),I(me);let pe=F.beginRenderPass(me);pe.setPipeline(a),pe.setBindGroup(0,ue),pe.draw(3),pe.end()}for(let P=0;P<v.length;P++){let te=c.length-2-P,ue=c[te];I(ue);let me=v[P],pe=w[P];I(me),I(pe);let re=F.beginRenderPass(pe);re.setPipeline(i),re.setBindGroup(0,me),re.draw(3),re.end()}let V=c[0];return I(V),V.texture},release:()=>{for(let F of c)F.texture.destroy();c=[],p=[],w=[],A=[],v=[],C=null,k=null}}};var uh="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 lu=(t,e,r,n,s,o)=>{let u=Math.ceil(n/16),l=Math.ceil(s/16),c=Nr(uh,{workgroupSizeX:16,workgroupSizeY:16});c=Zt(c,r),o&&(c=ss(c));let f=t.createTexture({label:"Smoothed Mask Texture",format:r,size:[n,s],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.COPY_SRC}),m=St(c),p=gt(m.uniforms.params),w=t.createBuffer({size:p.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),A=z=>{p.set({maskCombineRatio:z.maskCombineRatio}),t.queue.writeBuffer(w,0,p.arrayBuffer)},v=t.createShaderModule({label:"smoothing mask compute",code:c}),C=t.createComputePipeline({label:"smoothing mask pipeline",layout:"auto",compute:{module:v}}),k=t.createBindGroup({layout:C.getBindGroupLayout(0),entries:[{binding:0,resource:f.createView()},{binding:1,resource:{buffer:w}}]}),T=null,S=null,F=null,B=-1;return{render:(z,N,U,V)=>{I(!e(),O.ContextLost),N===T&&U===S||(F=t.createBindGroup({layout:C.getBindGroupLayout(1),entries:[{binding:0,resource:N.createView()},{binding:1,resource:U.createView()}]}),T=N,S=U),B!==V.maskCombineRatio&&(A(V),B=V.maskCombineRatio);let P=z.beginComputePass({label:"smoothing mask compute pass"});return P.setPipeline(C),P.setBindGroup(0,k),P.setBindGroup(1,F),P.dispatchWorkgroups(u,l),P.end(),f},release:()=>{f.destroy(),w.destroy(),T=null,S=null,F=null,B=-1}}};var ch=(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)=>{I(!e(),O.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 fu="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 lh="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 hu=(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}),m=St(fu),p=gt(m.uniforms.params),w=e.createBuffer({size:p.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),A=n/t.width,v=1/n,C=1/s;p.set({width:n,height:s,texelWidth:v,texelHeight:C});let k=$e=>{p.set({...$e,sigmaSpace:$e.sigmaSpace*A}),e.queue.writeBuffer(w,0,p.arrayBuffer)},T=Zt(fu,o),S=Zt(lh,o),F=e.createShaderModule({label:"joint bilateral filter horizontal compute",code:T}),B=e.createShaderModule({label:"joint bilateral filter vertical compute",code:S}),z=e.createComputePipeline({label:"joint bilateral filter horizontal pipeline",layout:"auto",compute:{module:F}}),N=e.createComputePipeline({label:"joint bilateral filter vertical pipeline",layout:"auto",compute:{module:B}}),U=e.createBindGroup({layout:z.getBindGroupLayout(1),entries:[{binding:0,resource:{buffer:w}},{binding:1,resource:c.createView()}]}),V=e.createBindGroup({layout:N.getBindGroupLayout(1),entries:[{binding:0,resource:{buffer:w}},{binding:1,resource:f.createView()}]}),P=($e,J,Ve,Fe,as,Hh,Xh)=>{let An=J.beginComputePass({label:$e});An.setPipeline(Ve),An.setBindGroup(0,Fe),An.setBindGroup(1,as),An.dispatchWorkgroups(Hh,Xh),An.end()},te=Math.ceil(n/32),ue=Math.ceil(s/4),me=Math.ceil(n/4),pe=Math.ceil(s/32),re=null,tt=null,We=null,Vt=null,Ge={sigmaSpace:-1,sigmaRangeLo:-1,sigmaRangeHi:-1,backgroundThreshold:-1,foregroundThreshold:-1};return{render:($e,J,Ve,Fe)=>(I(!r(),O.ContextLost),Ge.sigmaSpace===Fe.sigmaSpace&&Ge.sigmaRangeLo===Fe.sigmaRangeLo&&Ge.sigmaRangeHi===Fe.sigmaRangeHi&&Ge.backgroundThreshold===Fe.backgroundThreshold&&Ge.foregroundThreshold===Fe.foregroundThreshold||(k(Fe),Ge.sigmaSpace=Fe.sigmaSpace,Ge.sigmaRangeLo=Fe.sigmaRangeLo,Ge.sigmaRangeHi=Fe.sigmaRangeHi,Ge.backgroundThreshold=Fe.backgroundThreshold,Ge.foregroundThreshold=Fe.foregroundThreshold),(re!==J||tt!==Ve)&&(We=e.createBindGroup({layout:z.getBindGroupLayout(0),entries:[{binding:0,resource:J.createView()},{binding:1,resource:Ve.createView()}]}),re=J),P("Joint Bilateral Filter Horizontal pass",$e,z,We,U,te,ue),tt!==Ve&&(Vt=e.createBindGroup({layout:N.getBindGroupLayout(0),entries:[{binding:0,resource:c.createView()},{binding:1,resource:Ve.createView()}]}),tt=Ve),P("Joint Bilateral Filter Vertical pass",$e,N,Vt,V,me,pe),f),release:()=>{c.destroy(),f.destroy(),w.destroy(),re=null,tt=null,We=null,Vt=null}}};var fh="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 hh="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 tp=Et(0,9),dh=(t,e,r,n,s,o)=>{let u=Math.ceil(r/16),l=Math.ceil(n/16),c=Zt(fh,s);c=Nr(c,{workgroupSizeX:16,workgroupSizeY:16});let f=Zt(hh,s);f=Nr(f,{workgroupSizeX:16,workgroupSizeY:16}),o&&(c=ss(c),f=ss(f));let m=St(c),p=gt(m.uniforms.params),w=t.createBuffer({size:p.arrayBuffer.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});p.set({width:r,height:n});let A=P=>{p.set({radius:P}),t.queue.writeBuffer(w,0,p.arrayBuffer)},v=t.createTexture({label:`Tent Blur intermediate texture ${r}x${n} ${s}`,format:s,size:[r,n],usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.STORAGE_BINDING}),C=v.createView(),k=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}),S=t.createShaderModule({label:`Tent Blur vertical compute ${r}x${n} ${s}`,code:f}),F=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:S}}),z=t.createBindGroup({layout:B.getBindGroupLayout(0),entries:[{binding:0,resource:C},{binding:1,resource:k.createView()},{binding:2,resource:{buffer:w}}]}),N=null,U=null,V=-1;return{render(P,te,ue){I(!e(),O.ContextLost);let me=tp(ue.edgeBlurAmount);V!==me&&(A(me),V=me),N!==te&&(U=t.createBindGroup({layout:F.getBindGroupLayout(0),entries:[{binding:0,resource:te.createView()},{binding:1,resource:C},{binding:2,resource:{buffer:w}}]}),N=te);let pe=P.beginComputePass({label:"Tent Blur H pass"});pe.setPipeline(F),pe.setBindGroup(0,U),pe.dispatchWorkgroups(u,l),pe.end();let re=P.beginComputePass({label:"Tent Blur V pass"});return re.setPipeline(B),re.setBindGroup(0,z),re.dispatchWorkgroups(u,l),re.end(),k},release(){v.destroy(),k.destroy(),w.destroy(),N=null,U=null,V=-1}}};var du="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 mh=(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=St(du),a=gt(o.uniforms.sparams),i=gt(o.uniforms.dparams),u=e.createShaderModule({label:"replace shader",code:du}),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"}),m=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}),w=re=>{a.set({background:re.backgroundThreshold,foreground:re.foregroundThreshold,lightWrap:re.lightWrapIntensity,lightWrapTightness:re.lightWrapTightness,lightWrapEdgeBand:re.lightWrapEdgeBand,width:re.width,height:re.height}),e.queue.writeBuffer(m,0,a.arrayBuffer)},A=({time:re,parity:tt})=>{i.set({time:re,parity:tt}),e.queue.writeBuffer(p,0,i.arrayBuffer)},v={loadOp:"load",storeOp:"store"},C={label:"replace renderPass",colorAttachments:[v]},k=e.createBindGroup({layout:l.getBindGroupLayout(0),entries:[{binding:0,resource:c},{binding:1,resource:f},{binding:2,resource:{buffer:m}},{binding:3,resource:{buffer:p}}]}),T=null,S=null,F=null,B=null,z=null,N=-1,U=-1,V=-1,P=-1,te=-1,ue=-1,me=-1,pe=-1;return{render:(re,{foreground:tt,background:We,blurBackground:Vt,mask:Ge,timestamp:$e},J)=>{I(!n(),O.ContextLost),v.view=s.getCurrentTexture().createView(),F===We&&B===tt&&S===Ge&&z===Vt||(T=e.createBindGroup({layout:l.getBindGroupLayout(1),entries:[{binding:0,resource:tt.createView()},{binding:1,resource:We.createView()},{binding:2,resource:Ge.createView()},{binding:3,resource:Vt.createView()}]}),B=tt,F=We,S=Ge,z=Vt),N===J.backgroundThreshold&&U===J.foregroundThreshold&&V===J.lightWrapIntensity&&P===J.lightWrapTightness&&te===J.lightWrapEdgeBand&&ue===We.width&&me===We.height||(w({backgroundThreshold:J.backgroundThreshold,foregroundThreshold:J.foregroundThreshold,lightWrapIntensity:J.lightWrapIntensity,lightWrapTightness:J.lightWrapTightness,lightWrapEdgeBand:J.lightWrapEdgeBand,width:We.width,height:We.height}),N=J.backgroundThreshold,U=J.foregroundThreshold,V=J.lightWrapIntensity,P=J.lightWrapTightness,te=J.lightWrapEdgeBand,ue=We.width,me=We.height),pe=-pe,A({time:$e*1e-6%1024,parity:pe});let Ve=re.beginRenderPass(C);Ve.setPipeline(l),Ve.setBindGroup(0,k),Ve.setBindGroup(1,T),Ve.draw(6),Ve.end()},release:()=>{m.destroy(),p.destroy(),N=-1,U=-1,V=-1,P=-1,te=-1,ue=-1,me=-1,z=null,F=null,B=null,S=null,T=null}}};var ph=(t,e,r=new OffscreenCanvas(hn,fn))=>{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:()=>(I(c.device),dh(c.device,A,r.width,r.height,c.maskFormat,c.supportF16)),videoFrameRenderer:()=>(I(c.device),Lo(c.device,A,i,r.width,r.height,"linear")),maskRenderer:()=>(I(c.device),Lo(c.device,A,c.maskFormat,r.width,r.height,"nearest")),maskDownsampler2:()=>(I(c.device),Ar(c.device,A,n,s,c.maskFormat,"nearest")),maskDownsampler4:()=>(I(c.device),Ar(c.device,A,o,a,c.maskFormat,"nearest")),maskUpsampler:()=>(I(c.device),Ar(c.device,A,r.width,r.height,c.maskFormat,"nearest")),frameDownsampler2:()=>(I(c.device),Ar(c.device,A,n,s,i,"linear")),frameDownsampler4:()=>(I(c.device),Ar(c.device,A,o,a,i,"linear")),backgroundImageRenderer:()=>(I(c.device),Lo(c.device,A,i,r.width,r.height,"linear")),blendRenderer:()=>(I(c.device),ah(r,c.device,c.presentationFormat,A)),blurRenderer:()=>(I(c.device),cu(c.device,r.width,r.height,i,A)),jointBilateralFilterRenderer2:()=>(I(c.device),hu(r,c.device,A,n,s,c.maskFormat)),jointBilateralFilterRenderer4:()=>(I(c.device),hu(r,c.device,A,o,a,c.maskFormat)),maskSmoothingRenderer2:()=>(I(c.device),lu(c.device,A,c.maskFormat,n,s,c.supportF16)),maskSmoothingRenderer4:()=>(I(c.device),lu(c.device,A,c.maskFormat,o,a,c.supportF16)),prevMaskRenderer:()=>(I(c.device),ch(c.device,A)),strongMaskBlurRenderer:()=>(I(c.device),cu(c.device,r.width,r.height,c.maskFormat,A)),replaceRenderer:()=>(I(c.device),mh(r,c.device,c.presentationFormat,A)),release:v=>()=>{for(let C of Object.keys(v))C!=="release"&&v[C]?.release()}},l=dn(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=oo(c),m=async()=>{if(!navigator.gpu)throw Error("WebGPU not supported.");c.presentationFormat=navigator.gpu.getPreferredCanvasFormat(),c.device=await nh(t),c.supportR16FloatTextureStorage=au(t)&&sh(c.device,"r16float"),c.supportR16FloatTextureStorage&&(c.maskFormat="r16float"),c.supportF16=iu(t),c.device.lost.then(v=>{v.reason!=="destroyed"&&(c.deviceLost=!0,e.contextLost(v.message),e.contextRestored(v.message))})},p=(v,C,k)=>{k&&f(k),I(c.device);let T=c.device.createCommandEncoder({label:"Renderer Encoder"}),S=T.beginComputePass({label:"frame upload pass"}),F=c.videoFrameRenderer.render(C,S),B=c.maskRenderer.render(v,S);S.end();let z,N;switch(k.downSampleFactor){case 4:{let U=T.beginComputePass({label:"downsample pass"}),V=c.maskDownsampler4.render(U,B),P=c.frameDownsampler4.render(U,F);U.end();let te=c.jointBilateralFilterRenderer4.render(T,V,P,k);z=c.maskSmoothingRenderer4.render(T,te,c.prevMask4??te,k);let ue=T.beginComputePass({label:"upsample pass"}),me=c.maskUpsampler.render(ue,z);ue.end(),N=c.strongMaskBlurRenderer.render(T,me,qn);break}default:{let U=T.beginComputePass({label:"downsample pass"}),V=c.maskDownsampler2.render(U,B),P=c.frameDownsampler2.render(U,F);U.end();let te=c.jointBilateralFilterRenderer2.render(T,V,P,k);z=c.maskSmoothingRenderer2.render(T,te,c.prevMask2??te,k);let ue=T.beginComputePass({label:"upsample pass"}),me=c.maskUpsampler.render(ue,z);ue.end(),N=c.edgeBlurRenderer.render(T,me,k);break}}if(k.effects==="blur"){let U=c.blurRenderer.render(T,F,k.backgroundBlurAmount);c.blendRenderer.render(T,{foreground:F,background:U,mask:N},k)}else if(k.effects==="overlay"&&k.backgroundImage){let U=T.beginComputePass({label:"background image upload pass"}),V=c.backgroundImageRenderer.render(k.backgroundImage,U);U.end();let P=c.blurRenderer.render(T,V,k.backgroundBlurAmount);c.replaceRenderer.render(T,{foreground:F,background:V,mask:N,blurBackground:P,timestamp:C.timestamp},k)}switch(k.downSampleFactor){case 4:c.prevMask4=c.prevMaskRenderer.render(T,z);break;default:c.prevMask2=c.prevMaskRenderer.render(T,z);break}c.device.queue.submit([T.finish()])},w=()=>{l.release(),c.deviceLost=!1,c.prevMask2=void 0,c.prevMask4=void 0,c.presentationFormat="rgba8unorm",c.supportR16FloatTextureStorage=!1,c.maskFormat="rgba16float",l=dn(u)},A=()=>c.deviceLost;return{init:m,render:p,release:w,isContextLost:A}};var K={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[0*3+1],s=t[0*3+2],o=t[1*3+0],a=t[1*3+1],i=t[1*3+2],u=t[2*3+0],l=t[2*3+1],c=t[2*3+2],f=e[0*3+0],m=e[0*3+1],p=e[0*3+2],w=e[1*3+0],A=e[1*3+1],v=e[1*3+2],C=e[2*3+0],k=e[2*3+1],T=e[2*3+2];return[f*r+m*o+p*u,f*n+m*a+p*l,f*s+m*i+p*c,w*r+A*o+v*u,w*n+A*a+v*l,w*s+A*i+v*c,C*r+k*o+T*u,C*n+k*a+T*l,C*s+k*i+T*c]},translate:(t,e,r)=>K.multiply(t,K.translation(e,r)),rotate:(t,e)=>K.multiply(t,K.rotation(e)),scale:(t,e,r)=>K.multiply(t,K.scaling(e,r))};var Po={VertexShader:WebGLRenderingContext.VERTEX_SHADER,FragmentShader:WebGLRenderingContext.FRAGMENT_SHADER},mu={[Po.VertexShader]:"VertexShader",[Po.FragmentShader]:"FragmentShader"},rp=t=>typeof t=="string"?t.startsWith("#version 300 es"):!1,gh=t=>{if(!rp(t))throw new Error("Expecting GLSL ES 3.00 shader source")},np=/ERROR:\s*\d+:(\d+)/gi;function bh(t,e="",r=0){let n=[...e.matchAll(np)],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
|
+
`).map((o,a)=>{let i=s.get(a);return`${a+1+r}: ${o}${i?`
|
|
43
47
|
|
|
44
48
|
^^^ ${i}`:""}`}).join(`
|
|
45
|
-
`)}var
|
|
46
|
-
${
|
|
47
|
-
${
|
|
48
|
-
${
|
|
49
|
-
`)}`)}return[
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
in vec2 a_position;
|
|
53
|
-
in vec2 a_texCoord;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
uniform
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
void main() {
|
|
62
|
-
gl_Position = vec4((u_matrix * vec3(a_position, 1)).xy, 0, 1);
|
|
63
|
-
|
|
64
|
-
// pass the texCoord to the fragment shader
|
|
65
|
-
v_texCoord = a_texCoord;
|
|
66
|
-
}
|
|
67
|
-
`;var ar=`#version 300 es
|
|
68
|
-
precision mediump float;
|
|
69
|
-
|
|
70
|
-
// Passed in from the vertex shader.
|
|
71
|
-
in vec2 v_texCoord;
|
|
72
|
-
|
|
73
|
-
// The texture.
|
|
74
|
-
uniform sampler2D u_texture;
|
|
75
|
-
|
|
76
|
-
// we need to declare an output for the fragment shader
|
|
77
|
-
out vec4 outColor;
|
|
78
|
-
|
|
79
|
-
void main() {
|
|
80
|
-
outColor = texture(u_texture, v_texCoord);
|
|
81
|
-
}
|
|
82
|
-
`;var Fn=e=>{let{gl:t,program:r,attribLocations:n,uniformLocations:o,release:s}=Ne(e,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",texture:"u_texture"},vertexSrc:Ge,fragmentSrc:ar}),a=t.createVertexArray();t.bindVertexArray(a);let i=t.createBuffer();t.enableVertexAttribArray(n.position),t.bindBuffer(t.ARRAY_BUFFER,i),t.vertexAttribPointer(n.position,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),t.STATIC_DRAW);let c=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,c),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(n.texCoord),t.vertexAttribPointer(n.texCoord,2,t.FLOAT,!1,0,0);let l=Ke(t),h=Ke(t);t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e.width,e.height,0,t.RGBA,t.UNSIGNED_BYTE,null);let p=t.createFramebuffer();return t.bindFramebuffer(t.FRAMEBUFFER,p),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,h,0),{render:d=>{_(!t.isContextLost(),C.ContextLost),t.bindFramebuffer(t.FRAMEBUFFER,p),t.viewport(0,0,e.width,e.height),t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT),t.useProgram(r),t.bindVertexArray(a),t.uniform1i(o.texture,0);let g=ue.projection(1,1,1);return t.uniformMatrix3fv(o.matrix,!1,g),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,l),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,d.frame),t.generateMipmap(t.TEXTURE_2D),t.drawArrays(t.TRIANGLES,0,6),_(h),{texture:h,width:e.width,height:e.height}},release:()=>{t.deleteBuffer(i),t.deleteBuffer(c),t.deleteTexture(l),t.deleteTexture(h),t.deleteVertexArray(a),s()}}};var iu=`#version 300 es
|
|
49
|
+
`)}var xh=(t,e,r)=>{let n=t.createShader(e);if(!n)throw new Error(`Unable to create ${mu[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 ${mu[e]}: ${o??""}
|
|
50
|
+
${o?bh(r,o):"no error message available"}`;throw new Error(a)}return n},sp=(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=bh(t.getShaderSource(u)??""),c=t.getShaderParameter(u,t.SHADER_TYPE);return`${mu[c]}:
|
|
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)}}]},op=(t,[e,r],n,s)=>sp(t,[xh(t,Po.VertexShader,e),xh(t,Po.FragmentShader,r)],n,s),vh=(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},Gt=(t,e,r,n=!1,s=!1)=>{let o=vh(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)},ve=(t,e,r,n=!1,s=!1,o=!1)=>{let a=vh(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},yh=(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},_h=(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},{}),he=(t,{attribs:e,uniforms:r,vertexSrc:n,fragmentSrc:s})=>{let o=t.getContext("webgl2",{premultipliedAlpha:!1,powerPreference:"high-performance"});I(o,O.ContextCreationError),o.enable(o.BLEND),o.blendFunc(o.SRC_ALPHA,o.ONE_MINUS_SRC_ALPHA),gh(n),gh(s);let[a,i]=op(o,[n,s]),u=!!o.getExtension("EXT_color_buffer_float"),l=u&&yh(o,o.R16F,o.RED),c=u&&yh(o,o.RGBA16F,o.RGBA);return{gl:o,program:a,attribLocations:_h(o,a,e),uniformLocations:_h(o,a,r),release:i,floatSingleChannelSupported:l,floatFullChannelSupported:c}},wh=t=>({texture:t.getAsWebGLTexture(),width:t.width,height:t.height});var de=`#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 Th=`#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 pu=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatFullChannelSupported:i,floatSingleChannelSupported:u,release:l}=he(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",mask:"u_mask",size:"u_size",threshold:"u_threshold"},vertexSrc:de,fragmentSrc:Th}),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 m=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,m),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=ve(n,e,r,!1,u,i),w=ae(n,p);return{render:(A,v)=>{I(!n.isContextLost(),O.ContextLost),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(s),n.bindVertexArray(c),n.bindFramebuffer(n.FRAMEBUFFER,w),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,v);let C=K.projection(1,1,1);return n.uniformMatrix3fv(a.matrix,!1,C),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(m),n.deleteTexture(p),n.deleteFramebuffer(w),n.deleteVertexArray(c),l()}}};var kh=`#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 Eh=t=>{let{gl:e,program:r,attribLocations:n,floatFullChannelSupported:s,uniformLocations:o,release:a}=he(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:de,fragmentSrc:kh});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=Gt(e,t.width,t.height,!0,s),f=ae(e,c);return{render:({mask:m,foreground:p,background:w},A)=>{I(!e.isContextLost(),O.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,w.texture),e.activeTexture(e.TEXTURE2),e.uniform1i(o.mask,2),e.bindTexture(e.TEXTURE_2D,m.texture);let v=K.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 Ah=`#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 ap=Et(1,9),Oo=(t,e,r=!1)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatSingleChannelSupported:i,floatFullChannelSupported:u,release:l}=he(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",downsampling:"u_downsampling",frame:"u_frame"},vertexSrc:de,fragmentSrc:Ah}),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 m=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,m),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=(C,k,T)=>{n.bindFramebuffer(n.FRAMEBUFFER,C),n.viewport(0,0,k,T)},w=C=>{let k=Math.trunc(t.width/2**C),T=Math.trunc(t.height/2**C),S=r?ve(n,k,T,!0,i,u):Gt(n,k,T,!0,u),F=ae(n,S);return{texture:S,frameBuffer:F,width:k,height:T}},A=(C,k=0)=>{let T=Math.max(ap(k+C)-k,0);return Array.from({length:T}).map((S,F)=>w(k+F))},v=A(e+1);return{render:(C,k)=>{if(I(!n.isContextLost(),O.ContextLost),!k)return{texture:C.texture,width:C.width,height:C.height};n.useProgram(s),n.bindVertexArray(c),n.activeTexture(n.TEXTURE0),n.uniform1i(a.frame,0),n.bindTexture(n.TEXTURE_2D,C.texture),n.uniform1i(a.downsampling,1);let T=k+1;if(T>v.length)for(let S of A(T-v.length,v.length))v.push(S);for(;T<v.length;){let S=v.pop();n.deleteTexture(S?.texture??null),n.deleteFramebuffer(S?.frameBuffer??null)}for(let S=1;S<T;S++){let{frameBuffer:F=null,texture:B=null,width:z=t.width,height:N=t.height}=v[S]??{};p(F,z,N);let U=K.projection(1,1,1);n.uniformMatrix3fv(a.matrix,!1,U),n.drawArrays(n.TRIANGLES,0,6);let V=n.checkFramebufferStatus(n.FRAMEBUFFER),P=n.getError();if(I(P!==n.CONTEXT_LOST_WEBGL,O.ContextLost),I(!n.isContextLost(),O.ContextLost),V!==n.FRAMEBUFFER_COMPLETE||P!==n.NO_ERROR)throw new Error(O.SamplingError,{cause:`downsampling FrameBuffer Status: ${V}`});n.bindTexture(n.TEXTURE_2D,B)}n.uniform1i(a.downsampling,0);for(let S=k-1;S>=0;S--){let{frameBuffer:F=null,texture:B=null,width:z=t.width,height:N=t.height}=v[S]??{};p(F,z,N);let U=K.projection(1,1,1);n.uniformMatrix3fv(a.matrix,!1,U),n.drawArrays(n.TRIANGLES,0,6);let V=n.checkFramebufferStatus(n.FRAMEBUFFER),P=n.getError();if(I(P!==n.CONTEXT_LOST_WEBGL,O.ContextLost),I(!n.isContextLost(),O.ContextLost),V!==n.FRAMEBUFFER_COMPLETE||P!==n.NO_ERROR)throw new Error(O.SamplingError,{cause:`Upsampling FrameBuffer Status: ${V}`});n.bindTexture(n.TEXTURE_2D,B)}return n.bindBuffer(n.ARRAY_BUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,null),n.bindVertexArray(null),{texture:v[0]?.texture??C.texture,width:v[0]?.width??C.width,height:v[0]?.height??C.height}},release:()=>{for(let{frameBuffer:C,texture:k}of v)n.deleteTexture(k),n.deleteFramebuffer(C);n.deleteBuffer(f),n.deleteBuffer(m),n.deleteVertexArray(c),l()}}};var En=`#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 Do=t=>{let{gl:e,program:r,attribLocations:n,uniformLocations:s,release:o}=he(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",texture:"u_texture"},vertexSrc:de,fragmentSrc:En}),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=>{I(!e.isContextLost(),O.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=K.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 Ct=(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:m}=he(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",texture:"u_texture"},vertexSrc:de,fragmentSrc:En}),p=a.createVertexArray();a.bindVertexArray(p);let w=a.createBuffer();a.enableVertexAttribArray(u.position),a.bindBuffer(a.ARRAY_BUFFER,w),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 v=e?ve(a,n,s,r,o&&f,o&&c):Gt(a,n,s,r,o&&c),C=ae(a,v);return{render:k=>{I(!a.isContextLost(),O.ContextLost),a.bindFramebuffer(a.FRAMEBUFFER,C),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,k.texture);let T=K.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:v,width:n,height:s}},release:()=>{a.deleteBuffer(w),a.deleteBuffer(A),a.deleteTexture(v),a.deleteVertexArray(p),m()}}};function Rh(t,e,r){let n=t.getContext("webgl2",{premultipliedAlpha:!1,powerPreference:"high-performance"}),s=Ct(t,!0,!1,e,r,!1);I(n,O.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 m=n.createFramebuffer(),p={switchThreshold:.3,decay:.95,area:.2,height:.4,center:.2,iou:.2};return{render:(w,A)=>{let v=s.render(w);n.bindFramebuffer(n.FRAMEBUFFER,m),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,v.texture,0),n.readPixels(0,0,e,r,n.RED,n.UNSIGNED_BYTE,a),n.bindFramebuffer(n.FRAMEBUFFER,null);let C=Math.max(0,Math.min(255,Math.floor(255*A.foregroundThreshold)));for(let B=0;B<i.length;B++)i[B]=a[B]>=C?255:0;let k=-1/0,T=0,S=zf(i,o,e,r);for(let[B,z]of S.entries()){if(B===0)continue;for(let U=0;U<o.length;U++)l[U]=o[U]===B?255:0;let N=Hf(z,$f(u,l),{...p,centerX:A.personCenter[0]*e,centerY:A.personCenter[1]*r},e,r);N>k&&(k=N,T=B)}if(k>c*(1+p.switchThreshold)||c===0){for(let B=0;B<o.length;B++)u[B]=o[B]===T?255:0;c=k}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(m),s.release()}}}var Ih=`#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 Sh=`#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 Ch=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatSingleChannelSupported:i,floatFullChannelSupported:u,release:l}=he(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",texA:"u_tex_a",texB:"u_tex_b",size:"u_size"},vertexSrc:de,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 m=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,m),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=ve(n,e,r,!0,i,u),w=ae(n,p);return{render:(A,v)=>{I(!n.isContextLost(),O.ContextLost),I(A.width===v.width&&A.height===v.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,v.texture);let C=K.projection(1,1,1);return n.uniformMatrix3fv(a.matrix,!1,C),n.bindFramebuffer(n.FRAMEBUFFER,w),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:w,width:e,height:r}},release:()=>{n.deleteBuffer(f),n.deleteBuffer(m),n.deleteTexture(p),n.deleteFramebuffer(w),n.deleteVertexArray(c),l()}}};var ip=64,up=64,cp=Et(0,up),gu=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatSingleChannelSupported:i,floatFullChannelSupported:u,release:l}=he(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:de,fragmentSrc:Ih}),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 m=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,m),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,w=32,A=18,v=Math.max(Math.floor(e/4),w),C=Math.max(Math.floor(r/4),A),k=v===w?1e-8:1e-4,T=v*C,S=Ch(t,v,C),F=i||u,B=F?n.RGBA:n.RED,z=F?n.FLOAT:n.UNSIGNED_BYTE,N=F?new Float32Array(T*4):new Uint8Array(T),U=ve(n,e,r,!1,i,u),V=ve(n,e,r,!1,i,u),P=ae(n,U),te=ae(n,V);return{render:({mask:ue,maskRef:me},pe)=>{I(!n.isContextLost(),O.ContextLost);let re=P,tt=ue.texture,We=()=>{n.useProgram(s),n.bindVertexArray(c),n.uniform1i(a.radiusPx,cp(Math.floor(pe.morphDilateRadiusPx/p))),n.uniform2f(a.texelSize,1/ue.width,1/ue.height),n.activeTexture(n.TEXTURE1),n.uniform1i(a.maskRef,1),n.bindTexture(n.TEXTURE_2D,me.texture);let $e=K.projection(1,1,1);n.uniformMatrix3fv(a.matrix,!1,$e);for(let J=0;J<2;J++)n.activeTexture(n.TEXTURE0),n.uniform1i(a.mask,0),n.bindTexture(n.TEXTURE_2D,tt),n.uniform2f(a.direction,1-J,0+J),n.bindFramebuffer(n.FRAMEBUFFER,re),n.viewport(0,0,e,r),n.drawArrays(n.TRIANGLES,0,6),[tt,re]=re===P?[U,te]:[V,P]};for(let $e=0;$e<pe.morphPass;$e++)We();let Vt=!1,Ge=0;for(;!Vt;){We();let $e=S.render({texture:U,width:e,height:r},{texture:V,width:e,height:r});n.bindFramebuffer(n.FRAMEBUFFER,$e.frameBuffer),n.readPixels(0,0,v,C,B,z,N);let J=0,Ve=0;if(F){for(let Fe=0,as=0;Fe<T;++Fe,as+=4)J+=N[as];Ve=J/T}else{for(let Fe=0;Fe<T;++Fe)J+=N[Fe];Ve=J/T/255}n.bindFramebuffer(n.FRAMEBUFFER,null),(Ve<k||Ge>=ip)&&(Vt=!0),Ge++}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(m),n.deleteTexture(U),n.deleteTexture(V),n.deleteFramebuffer(P),n.deleteFramebuffer(te),n.deleteVertexArray(c),S.release(),l()}}};var Fh=`#version 300 es
|
|
61
|
+
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
62
|
+
precision highp float;
|
|
63
|
+
#else
|
|
83
64
|
precision mediump float;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
uniform sampler2D
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
in vec2 v_texCoord;
|
|
92
|
-
|
|
93
|
-
// we need to declare an output for the fragment shader
|
|
94
|
-
out vec4 outColor;
|
|
95
|
-
|
|
96
|
-
vec4 Downsample(sampler2D image, vec2 uv, vec2 halfpixel) {
|
|
97
|
-
vec4 sum = texture(image, uv) * 4.0;
|
|
98
|
-
sum += texture(image, uv - halfpixel.xy);
|
|
99
|
-
sum += texture(image, uv + halfpixel.xy);
|
|
100
|
-
sum += texture(image, uv + vec2(halfpixel.x, -halfpixel.y));
|
|
101
|
-
sum += texture(image, uv - vec2(halfpixel.x, -halfpixel.y));
|
|
102
|
-
return sum / 8.0;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
vec4 Upsample(sampler2D image, vec2 uv, vec2 halfpixel) {
|
|
106
|
-
vec4 sum = texture(image, uv + vec2(-halfpixel.x * 2.0, 0.0));
|
|
107
|
-
sum += texture(image, uv + vec2(-halfpixel.x, halfpixel.y)) * 2.0;
|
|
108
|
-
sum += texture(image, uv + vec2(0.0, halfpixel.y * 2.0));
|
|
109
|
-
sum += texture(image, uv + vec2(halfpixel.x, halfpixel.y)) * 2.0;
|
|
110
|
-
sum += texture(image, uv + vec2(halfpixel.x * 2.0, 0.0));
|
|
111
|
-
sum += texture(image, uv + vec2(halfpixel.x, -halfpixel.y)) * 2.0;
|
|
112
|
-
sum += texture(image, uv + vec2(0.0, -halfpixel.y * 2.0));
|
|
113
|
-
sum += texture(image, uv + vec2(-halfpixel.x, -halfpixel.y)) * 2.0;
|
|
114
|
-
return sum / 12.0;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
void main() {
|
|
118
|
-
vec2 halfpixel = 0.5 / vec2(textureSize(u_frame, 0));
|
|
119
|
-
|
|
120
|
-
if (u_downsampling == 1) {
|
|
121
|
-
outColor = Downsample(u_frame, v_texCoord, halfpixel);
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
outColor = Upsample(u_frame, v_texCoord, halfpixel);
|
|
125
|
-
}
|
|
126
|
-
`;var e1=In(1,9),Rs=(e,t)=>{let{gl:r,program:n,attribLocations:o,uniformLocations:s,release:a}=Ne(e,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",downsampling:"u_downsampling",frame:"u_frame"},vertexSrc:Ge,fragmentSrc:iu}),i=r.createVertexArray();r.bindVertexArray(i);let c=r.createBuffer();r.enableVertexAttribArray(o.position),r.bindBuffer(r.ARRAY_BUFFER,c),r.vertexAttribPointer(o.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 l=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,l),r.bufferData(r.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),r.STATIC_DRAW),r.enableVertexAttribArray(o.texCoord),r.vertexAttribPointer(o.texCoord,2,r.FLOAT,!1,0,0);let h=(A,R,S)=>{r.bindFramebuffer(r.FRAMEBUFFER,A),r.viewport(0,0,R,S)},p=A=>{let R=Ke(r);_(R);let S=Math.trunc(e.width/2**A),w=Math.trunc(e.height/2**A);r.texImage2D(r.TEXTURE_2D,0,r.RGBA,S,w,0,r.RGBA,r.UNSIGNED_BYTE,null);let f=r.createFramebuffer();_(f),r.bindFramebuffer(r.FRAMEBUFFER,f);let y=r.COLOR_ATTACHMENT0;return r.framebufferTexture2D(r.FRAMEBUFFER,y,r.TEXTURE_2D,R,0),{texture:R,frameBuffer:f,width:S,height:w}},d=(A,R=0)=>{let S=Math.max(e1(R+A)-R,0);return Array.from({length:S}).map((w,f)=>p(R+f))},g=d(t+1);return{render:(A,R)=>{_(!r.isContextLost(),C.ContextLost),r.useProgram(n),r.bindVertexArray(i),r.activeTexture(r.TEXTURE0),r.uniform1i(s.frame,0),r.bindTexture(r.TEXTURE_2D,A.texture),r.uniform1i(s.downsampling,1);let S=R+1;if(S>g.length)for(let w of d(S-g.length,g.length))g.push(w);for(;S<g.length;){let w=g.pop();r.deleteTexture(w?.texture??null),r.deleteFramebuffer(w?.frameBuffer??null)}for(let w=1;w<S;w++){let{frameBuffer:f=null,texture:y=null,width:b=e.width,height:L=e.height}=g[w]??{};h(f,b,L);let I=ue.projection(1,1,1);r.uniformMatrix3fv(s.matrix,!1,I),r.drawArrays(r.TRIANGLES,0,6);let k=r.checkFramebufferStatus(r.FRAMEBUFFER),B=r.getError();if(_(B!==r.CONTEXT_LOST_WEBGL,C.ContextLost),_(!r.isContextLost(),C.ContextLost),k!==r.FRAMEBUFFER_COMPLETE||B!==r.NO_ERROR)throw new Error(C.SamplingError,{cause:`downsampling FrameBuffer Status: ${k}`});r.bindTexture(r.TEXTURE_2D,y)}r.uniform1i(s.downsampling,0);for(let w=R-1;w>=0;w--){let{frameBuffer:f=null,texture:y=null,width:b=e.width,height:L=e.height}=g[w]??{};h(f,b,L);let I=ue.projection(1,1,1);r.uniformMatrix3fv(s.matrix,!1,I),r.drawArrays(r.TRIANGLES,0,6);let k=r.checkFramebufferStatus(r.FRAMEBUFFER),B=r.getError();if(_(B!==r.CONTEXT_LOST_WEBGL,C.ContextLost),_(!r.isContextLost(),C.ContextLost),k!==r.FRAMEBUFFER_COMPLETE||B!==r.NO_ERROR)throw new Error(C.SamplingError,{cause:`Upsampling FrameBuffer Status: ${k}`});r.bindTexture(r.TEXTURE_2D,y)}return{texture:g[0]?.texture??A.texture,width:g[0]?.width??A.width,height:g[0]?.height??A.height}},release:()=>{for(let{frameBuffer:A,texture:R}of g)r.deleteTexture(R),r.deleteFramebuffer(A);r.deleteBuffer(c),r.deleteBuffer(l),r.deleteVertexArray(i),a()}}};var cu=`#version 300 es
|
|
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 Mo=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,release:i}=he(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:de,fragmentSrc:Fh});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=ve(n,e,r),m=ae(n,f),p=t.width/e;return{render:({input:w,guide:A},v)=>{I(!n.isContextLost(),O.ContextLost),I(v.foregroundThreshold>=v.backgroundThreshold,"foregroundThreshold must be >= backgroundThreshold"),n.bindFramebuffer(n.FRAMEBUFFER,m),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,w.texture),n.activeTexture(n.TEXTURE1),n.uniform1i(a.frameGuide,1),n.bindTexture(n.TEXTURE_2D,A.texture),n.uniform2f(a.texelSize,1/w.width,1/w.height),n.uniform1f(a.sigmaSpace,v.sigmaSpace/p),n.uniform1f(a.sigmaRangeLo,v.sigmaRangeLo),n.uniform1f(a.sigmaRangeHi,v.sigmaRangeHi),n.uniform1f(a.backgroundThreshold,v.backgroundThreshold),n.uniform1f(a.foregroundThreshold,v.foregroundThreshold);let C=K.projection(1,1,1);return n.uniformMatrix3fv(a.matrix,!1,C),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(m),n.deleteVertexArray(u),i()}}};var Bh=`#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 lp=64,fp=Et(0,lp),xu=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatSingleChannelSupported:i,floatFullChannelSupported:u,release:l}=he(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:de,fragmentSrc:Bh}),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 m=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,m),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=ve(n,e,r,!1,i,u),w=ae(n,p),A=ve(n,e,r,!1,i,u),v=ae(n,A),C=t.width/e;return{render:({mask:k},T)=>{I(!n.isContextLost(),O.ContextLost),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(s),n.bindVertexArray(c),n.uniform2f(a.texelSize,1/k.width,1/k.height),n.uniform1i(a.radiusPx,fp(Math.floor(T.morphErodeRadiusPx/C)));let S=K.projection(1,1,1);n.uniformMatrix3fv(a.matrix,!1,S);let F=w,B=k.texture;for(let z=0;z<T.morphPass;z++)for(let N=0;N<2;N++)n.activeTexture(n.TEXTURE0),n.uniform1i(a.mask,0),n.bindTexture(n.TEXTURE_2D,B),n.uniform2f(a.direction,1-N,0+N),n.bindFramebuffer(n.FRAMEBUFFER,F),n.viewport(0,0,k.width,k.height),n.drawArrays(n.TRIANGLES,0,6),[B,F]=F===w?[p,v]:[A,w];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(m),n.deleteTexture(p),n.deleteTexture(A),n.deleteFramebuffer(w),n.deleteFramebuffer(v),n.deleteVertexArray(c),l()}}};var Uh=`#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 Lh=t=>{let{gl:e,program:r,attribLocations:n,floatFullChannelSupported:s,uniformLocations:o,release:a}=he(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:de,fragmentSrc:Uh});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=Gt(e,t.width,t.height,!0,s),f=ae(e,c),m=-1;return{render:({mask:p,foreground:w,background:A,blurredBackground:v,timestamp:C},k)=>{I(!e.isContextLost(),O.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,w.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,v.texture),e.uniform2f(o.confidenceThresholds,k.backgroundThreshold,k.foregroundThreshold),e.uniform1f(o.lightWrap,k.lightWrapIntensity),e.uniform1f(o.lightWrapTightness,k.lightWrapTightness),e.uniform1f(o.lightWrapEdgeBand,k.lightWrapEdgeBand),m=-m,e.uniform1f(o.parity,m),e.uniform1f(o.time,C*1e-6%1024),e.uniform2f(o.frameSize,t.width,t.height);let T=K.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 Ph=`#version 300 es
|
|
69
|
+
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
70
|
+
precision highp float;
|
|
71
|
+
#else
|
|
127
72
|
precision mediump float;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
uniform sampler2D u_mask;
|
|
131
|
-
uniform sampler2D u_frame_foreground;
|
|
132
|
-
uniform sampler2D u_frame_background;
|
|
133
|
-
|
|
134
|
-
in vec2 v_texCoord;
|
|
135
|
-
|
|
136
|
-
// we need to declare an output for the fragment shader
|
|
137
|
-
out vec4 outColor;
|
|
138
|
-
|
|
139
|
-
void main() {
|
|
140
|
-
vec4 background = texture(u_frame_background, v_texCoord);
|
|
141
|
-
vec4 foreground = texture(u_frame_foreground, v_texCoord);
|
|
142
|
-
float filteredMask = texture(u_mask, v_texCoord).r;
|
|
143
|
-
|
|
144
|
-
outColor = mix(background, foreground, filteredMask);
|
|
145
|
-
}
|
|
146
|
-
`;var uu=e=>{let{gl:t,program:r,attribLocations:n,uniformLocations:o,release:s}=Ne(e,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",frameBackground:"u_frame_background",frameForeground:"u_frame_foreground",mask:"u_mask"},vertexSrc:Ge,fragmentSrc:cu});t.enable(t.BLEND);let a=t.createVertexArray();t.bindVertexArray(a);let i=t.createBuffer();t.enableVertexAttribArray(n.position),t.bindBuffer(t.ARRAY_BUFFER,i),t.vertexAttribPointer(n.position,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),t.STATIC_DRAW);let c=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,c),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(n.texCoord),t.vertexAttribPointer(n.texCoord,2,t.FLOAT,!1,0,0);let l=Ke(t);t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e.width,e.height,0,t.RGBA,t.UNSIGNED_BYTE,null);let h=t.createFramebuffer();return t.bindFramebuffer(t.FRAMEBUFFER,h),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,l,0),{render:({mask:p,foreground:d,background:g})=>{_(!t.isContextLost(),C.ContextLost),t.bindFramebuffer(t.FRAMEBUFFER,h),t.viewport(0,0,e.width,e.height),t.useProgram(r),t.bindVertexArray(a),t.activeTexture(t.TEXTURE0),t.uniform1i(o.frameForeground,0),t.bindTexture(t.TEXTURE_2D,d.texture),t.activeTexture(t.TEXTURE1),t.uniform1i(o.frameBackground,1),t.bindTexture(t.TEXTURE_2D,g.texture),t.activeTexture(t.TEXTURE2),t.uniform1i(o.mask,2),t.bindTexture(t.TEXTURE_2D,p.texture);let A=ue.projection(1,1,1);return t.uniformMatrix3fv(o.matrix,!1,A),t.drawArrays(t.TRIANGLES,0,6),_(l),{texture:l,width:e.width,height:e.height}},release:()=>{t.deleteBuffer(i),t.deleteBuffer(c),t.deleteTexture(l),t.deleteFramebuffer(h),t.deleteVertexArray(a),s()}}};var Un=e=>{let{gl:t,program:r,attribLocations:n,uniformLocations:o,release:s}=Ne(e,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",texture:"u_texture"},vertexSrc:Ge,fragmentSrc:ar}),a=t.createVertexArray();t.bindVertexArray(a);let i=t.createBuffer();t.enableVertexAttribArray(n.position),t.bindBuffer(t.ARRAY_BUFFER,i),t.vertexAttribPointer(n.position,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),t.STATIC_DRAW);let c=t.createBuffer();return t.bindBuffer(t.ARRAY_BUFFER,c),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(n.texCoord),t.vertexAttribPointer(n.texCoord,2,t.FLOAT,!1,0,0),{render:l=>{_(!t.isContextLost(),C.ContextLost),t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,e.width,e.height),t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT),t.useProgram(r),t.bindVertexArray(a),t.uniform1i(o.texture,0);let h=ue.projection(1,1);t.uniformMatrix3fv(o.matrix,!1,h),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,l.texture),t.drawArrays(t.TRIANGLES,0,6)},release:()=>{t.deleteBuffer(i),t.deleteBuffer(c),t.deleteVertexArray(a),s()}}};var hu=e=>{let{gl:t,program:r,attribLocations:n,uniformLocations:o,release:s}=Ne(e,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",texture:"u_texture"},vertexSrc:Ge,fragmentSrc:ar}),a=t.createVertexArray();t.bindVertexArray(a);let i=t.createBuffer();t.enableVertexAttribArray(n.position),t.bindBuffer(t.ARRAY_BUFFER,i),t.vertexAttribPointer(n.position,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),t.STATIC_DRAW);let c=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,c),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(n.texCoord),t.vertexAttribPointer(n.texCoord,2,t.FLOAT,!1,0,0);let l=Ke(t);t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e.width,e.height,0,t.RGBA,t.UNSIGNED_BYTE,null);let h=t.createFramebuffer();return t.bindFramebuffer(t.FRAMEBUFFER,h),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,l,0),{render:p=>{_(!t.isContextLost(),C.ContextLost),t.bindFramebuffer(t.FRAMEBUFFER,h),t.viewport(0,0,e.width,e.height),t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT),t.useProgram(r),t.bindVertexArray(a),t.activeTexture(t.TEXTURE0),t.uniform1i(o.texture,0),t.bindTexture(t.TEXTURE_2D,p.texture);let d=ue.projection(1,1,1);return t.uniformMatrix3fv(o.matrix,!1,d),t.drawArrays(t.TRIANGLES,0,6),_(l),{texture:l,width:e.width,height:e.height}},release:()=>{t.deleteBuffer(i),t.deleteBuffer(c),t.deleteTexture(l),t.deleteVertexArray(a),s()}}};var lu=`#version 300 es
|
|
147
|
-
precision mediump float;
|
|
148
|
-
|
|
149
|
-
// our textures
|
|
150
|
-
uniform sampler2D u_mask;
|
|
151
|
-
uniform sampler2D u_mask_prev;
|
|
152
|
-
|
|
153
|
-
// control flags
|
|
154
|
-
uniform float u_mask_combine_ratio;
|
|
155
|
-
uniform float u_foreground_threshold;
|
|
156
|
-
|
|
157
|
-
in vec2 v_texCoord;
|
|
158
|
-
|
|
159
|
-
// we need to declare an output for the fragment shader
|
|
160
|
-
out vec4 outColor;
|
|
161
|
-
|
|
162
|
-
// Source: https://github.com/google/mediapipe/blob/8750c3dca1bc00fbe47acf501b7c9c61f3f3bd3f/mediapipe/calculators/image/segmentation_smoothing_calculator.cc#L377
|
|
163
|
-
float SmoothingMask(sampler2D prevMask, sampler2D currMask, vec2 uv, float ratio) {
|
|
164
|
-
float prevMaskValue = texture(prevMask, uv).r;
|
|
165
|
-
float newMaskValue = texture(currMask, uv).r;
|
|
166
|
-
|
|
167
|
-
/*
|
|
168
|
-
* Assume p := newMaskValue
|
|
169
|
-
* H(p) := 1 + (p * log(p) + (1-p) * log(1-p)) / log(2)
|
|
170
|
-
* uncertainty alpha(p) =
|
|
171
|
-
* Clamp(1 - (1 - H(p)) * (1 - H(p)), 0, 1) [squaring the
|
|
172
|
-
* uncertainty]
|
|
173
|
-
*
|
|
174
|
-
* The following polynomial approximates uncertainty alpha as a
|
|
175
|
-
* function of (p + 0.5):
|
|
176
|
-
*/
|
|
177
|
-
const float c1 = 5.68842;
|
|
178
|
-
const float c2 = -0.748699;
|
|
179
|
-
const float c3 = -57.8051;
|
|
180
|
-
const float c4 = 291.309;
|
|
181
|
-
const float c5 = -624.717;
|
|
182
|
-
float t = newMaskValue - 0.5;
|
|
183
|
-
float x = t * t;
|
|
184
|
-
|
|
185
|
-
float uncertainty =
|
|
186
|
-
1.0 - min(1.0, x * (c1 + x * (c2 + x * (c3 + x * (c4 + x * c5)))));
|
|
187
|
-
|
|
188
|
-
float outputValue = newMaskValue + (prevMaskValue - newMaskValue) *
|
|
189
|
-
(uncertainty * ratio);
|
|
190
|
-
return outputValue;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
void main() {
|
|
194
|
-
float maskAlpha = SmoothingMask(u_mask_prev, u_mask, v_texCoord, u_mask_combine_ratio);
|
|
195
|
-
float backgroundMask = maskAlpha;
|
|
196
|
-
if (backgroundMask < u_foreground_threshold) {
|
|
197
|
-
backgroundMask = 0.0;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
outColor = vec4(backgroundMask, backgroundMask, backgroundMask, backgroundMask);
|
|
201
|
-
}
|
|
202
|
-
`;var du=e=>{let{gl:t,program:r,attribLocations:n,uniformLocations:o,release:s}=Ne(e,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",mask:"u_mask",maskCombineRatio:"u_mask_combine_ratio",foregroundThreshold:"u_foreground_threshold",prevMask:"u_mask_prev"},vertexSrc:Ge,fragmentSrc:lu}),a=t.createVertexArray();t.bindVertexArray(a);let i=t.createBuffer();t.enableVertexAttribArray(n.position),t.bindBuffer(t.ARRAY_BUFFER,i),t.vertexAttribPointer(n.position,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),t.STATIC_DRAW);let c=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,c),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,0,0,1,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(n.texCoord),t.vertexAttribPointer(n.texCoord,2,t.FLOAT,!1,0,0);let l=Ke(t);t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e.width,e.height,0,t.RGBA,t.UNSIGNED_BYTE,null);let h=t.createFramebuffer();return t.bindFramebuffer(t.FRAMEBUFFER,h),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,l,0),{render:({mask:p,prevMask:d},g)=>{_(!t.isContextLost(),C.ContextLost),t.bindFramebuffer(t.FRAMEBUFFER,h),t.viewport(0,0,e.width,e.height),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.useProgram(r),t.bindVertexArray(a),t.activeTexture(t.TEXTURE0),t.uniform1i(o.mask,0),t.bindTexture(t.TEXTURE_2D,p.texture),t.activeTexture(t.TEXTURE1),t.uniform1i(o.prevMask,1),t.bindTexture(t.TEXTURE_2D,d?.texture??p.texture);let A=ue.projection(1,1,1);return t.uniformMatrix3fv(o.matrix,!1,A),t.uniform1f(o.maskCombineRatio,g.maskCombineRatio),t.uniform1f(o.foregroundThreshold,g.foregroundThreshold),t.drawArrays(t.TRIANGLES,0,6),_(l),{texture:l,width:e.width,height:e.height}},release:()=>{t.deleteBuffer(i),t.deleteBuffer(c),t.deleteTexture(l),t.deleteFramebuffer(h),t.deleteVertexArray(a),s()}}};var fu=(e,t=new OffscreenCanvas(768,432))=>{let r={videoFrameRenderer:()=>Fn(t),maskRenderer:()=>Fn(t),canvasRenderer:()=>Un(t),backgroundImageRenderer:()=>Fn(t),blendRenderer:()=>uu(t),blurRenderer:()=>Rs(t,3),maskBlurRenderer:()=>Rs(t,3),textureRenderer:()=>hu(t),smoothingMaskRenderer:()=>du(t),release:h=>()=>{for(let p in h)p!=="release"&&h[p]?.release()}},n=or(r),o={canvas:t,gl:null,canvasContextEventsCleanup:()=>{},get videoFrameRenderer(){return n.videoFrameRenderer},get maskRenderer(){return n.maskRenderer},get canvasRenderer(){return n.canvasRenderer},get backgroundImageRenderer(){return n.backgroundImageRenderer},get blendRenderer(){return n.blendRenderer},get blurRenderer(){return n.blurRenderer},get maskBlurRenderer(){return n.maskBlurRenderer},get textureRenderer(){return n.textureRenderer},get smoothingMaskRenderer(){return n.smoothingMaskRenderer}},s=()=>{o.canvasContextEventsCleanup=Yc(t,{contextLost:e.contextLost,contextRestored:e.contextRestored,contextCreationError:e.contextCreationError},i),o.gl=t.getContext("webgl2",{premultipliedAlpha:!1,powerPreference:"high-performance"}),_(o.gl,C.ContextCreationError)},a=(h,p,d)=>{_(!o.gl?.isContextLost(),C.ContextLost);let g=o.maskRenderer.render({frame:h,width:h.width,height:h.height,timestamp:p.timestamp}),A=o.smoothingMaskRenderer.render({mask:g,prevMask:o.prevMask},d),R=o.videoFrameRenderer.render(p),S=R;d.effects==="blur"&&d.backgroundBlurAmount?S=o.blurRenderer.render(R,d.backgroundBlurAmount):d?.effects==="overlay"&&d.backgroundImage&&(S=o.backgroundImageRenderer.render({frame:d.backgroundImage,timestamp:performance.now(),width:d.backgroundImage.width,height:d.backgroundImage.height}));let w=o.blendRenderer.render({mask:A,foreground:R,background:S});o.canvasRenderer.render(w),o.prevMask=o.textureRenderer.render(A)},i=()=>{o.canvasContextEventsCleanup(),n.release(),n=or(r),o.prevMask=void 0};return{init:s,render:a,release:()=>{i()},isContextLost:()=>!!o.gl?.isContextLost()}};var t1={drawImageDataCanvas:"drawImageDataCanvas",maskCanvas:"maskCanvas",blurredMaskCanvas:"blurredMaskCanvas",blurredCanvas:"blurredCanvas",downScaledCanvas:"downScaledCanvas",backgroundImageCanvas:"backgroundImageCanvas",inputCanvas:"inputCanvas"},wt=(e,t)=>{let r=e.getContext("2d",t);if(!r)throw new Error("Cannot get CanvasRenderingContext2D");return r},r1=e=>{let t=wt(e);t.scale(-1,1),t.translate(-e.width,0)},Ss=e=>"VideoFrame"in globalThis&&e instanceof VideoFrame?{height:e.displayHeight,width:e.displayWidth}:"offsetHeight"in e&&typeof e.offsetHeight=="number"&&e.offsetHeight!==0&&"offsetWidth"in e&&typeof e.offsetWidth=="number"&&e.offsetWidth!==0?{height:e.offsetHeight,width:e.offsetWidth}:"videoHeight"in e&&typeof e.videoHeight=="number"&&e.videoHeight!==0&&"videoWidth"in e&&typeof e.videoWidth=="number"&&e.videoWidth!==0?{height:e.videoHeight,width:e.videoWidth}:"height"in e&&e.height!==0&&"width"in e&&e.width!==0?{height:e.height,width:e.width}:{height:0,width:0},$e=(e,t)=>new OffscreenCanvas(e,t);var n1=e=>{wt(e).clearRect(0,0,e.width,e.height)},Cs=(e,t)=>{let r={downScaleFactor:3},n=f=>$e(f==="downScaledCanvas"?Math.trunc(e/r.downScaleFactor):e,f==="downScaledCanvas"?Math.trunc(t/r.downScaleFactor):t),o=f=>{let y=r[f];if(!y){let b=n(f);return r[f]=b,b}return y},s=(f,y)=>{let b=o(y);return wt(b).putImageData(f,0,0),b},a=(f,y,b,L,I,k,B,U,j,W)=>{let le=y instanceof ImageData?s(y,"drawImageDataCanvas"):y;I===void 0||k===void 0?f.drawImage(le,b,L):B===void 0||U===void 0||j===void 0||W===void 0?f.drawImage(le,b,L,I,k):f.drawImage(le,b,L,I,k,B,U,j,W)},i=(f,y,b=e,L=t,I={})=>{let{height:k,width:B}=Ss(f),U=Hc(B,k,b,L),j=wt(y,I);a(j,f,U.sx,U.sy,U.sw,U.sh,U.dx,U.dy,U.dw,U.dh)},c=(f,y)=>{let b=o(y);return i(f,b),b},l=(f,y,b)=>{f.globalCompositeOperation=b,a(f,y,0,0)},h=(f,y,b)=>{let L=wt(f),I=0,k=5,B=1/(2*Math.PI*k*k),U=b<3?1:2;for(let j=-b;j<=b;j+=U)for(let W=-b;W<=b;W+=U){let le=B*Math.exp(-(W*W+j*j)/(2*k*k));I+=le}for(let j=-b;j<=b;j+=U)for(let W=-b;W<=b;W+=U)L.globalAlpha=B*Math.exp(-(W*W+j*j)/(2*k*k))/I*b,a(L,y,W,j);L.globalAlpha=1},p=({image:f,blurAmount:y,canvas:b,preserveOldDrawing:L=!0})=>{let{height:I,width:k}=Ss(f),B=wt(b);if(y<=0)return a(B,f,0,0,k,I);let U=o("downScaledCanvas"),j=wt(U);L||(j.clearRect(0,0,U.width,U.height),B.clearRect(0,0,k,I)),"filter"in B?(j.filter=`blur(${y}px)`,a(j,f,0,0,k,I,0,0,U.width,U.height),a(B,U,0,0,k,I)):h(b,f,y)},d=({image:f,blurAmount:y,offscreenCanvasName:b,preserveOldDrawing:L})=>{let I=o(b);return n1(I),y===0?i(f,I):p({image:f,blurAmount:y,canvas:I,preserveOldDrawing:L}),I},g=(f,y,b)=>{let L=Array.isArray(f)?f[0]?.canvas:f.canvas;if(!L)return o("maskCanvas");let I=d({image:L,offscreenCanvasName:"maskCanvas",blurAmount:0});return b===0?I:d({image:I,blurAmount:b,offscreenCanvasName:"blurredMaskCanvas",preserveOldDrawing:!1})},A=(f,y,b,L,I=.5,k=3,B=3,U=!1)=>{let j=d({image:b,blurAmount:k,offscreenCanvasName:"blurredCanvas"}),W=wt(f);if(Array.isArray(L)&&L.length===0)return a(W,j,0,0);let le=g(L,I,B);W.save(),U&&r1(f);let{height:mu,width:gu}=Ss(y);a(W,y,0,0,gu,mu),l(W,le,"destination-in"),l(W,j,"destination-over"),W.restore()};return{evaluateInput:f=>c(f,"inputCanvas"),renderImageToCanvas:i,drawBlurEffect:(f,y,b,L=.5,I=3,k=3,B=!1)=>A(f,y,y,b,L,I,k,B),drawOverlayEffect:(f,y,b,L,I=.5,k=0,B=3,U=!1)=>A(f,y,b,L,I,k,B,U),renderImageToOffScreenCanvas:c,renderImageDataToOffScreenCanvas:s,drawAndBlurImageOnOffScreenCanvas:d,reset:()=>{for(let f in t1){let y=f,b=r[y];b&&b instanceof OffscreenCanvas&&(r[y]=n(y))}}}};var pu=e=>typeof e=="string"?Object.values(Wc).includes(e):!1;var u={width:768,height:432,status:z.New,directOutput:!1,delegate:"GPU",modelAssetPath:"",renderOptions:{edgeBlurAmount:3,backgroundBlurAmount:3,foregroundThreshold:.5,maskCombineRatio:.5,effects:jc.None,backgroundImageUrl:"",backgroundImage:null,backend:"webgl"}},Ms=Ln(u.renderOptions),pe=(e,t)=>postMessage(e,t??[]),a1=e=>{if(u.status!==z.Error){u.status=z.Error;try{u.segmenter?.close()}catch(t){pe({type:"event",data:{type:C.ContextLost,message:`Failed to close segmenter ${t}`}})}u.segmenter=void 0}pe({type:"event",data:{type:C.ContextLost,message:e}})},i1=e=>{pe({type:"event",data:{type:C.ContextRestored,message:e}})},c1=e=>{u.status!==z.Error&&(u.status=z.Error),pe({type:"event",data:{type:C.ContextCreationError,message:e}})},u1=async()=>{u.renderer?.release(),u.renderer=void 0;let e=[{contextLost:a1,contextRestored:i1,contextCreationError:c1},u.processCanvas],t=()=>fu(...e);if(navigator.gpu&&u.renderOptions?.backend==="webgpu"){let n=await navigator.gpu.requestAdapter();n?u.renderer=tu(n,...e):u.renderer=t()}else u.renderer=t();await u.renderer?.init()},h1=async()=>{_(u.visionInstance),u.segmenter=await de.createFromOptions(u.visionInstance,{outputCategoryMask:!1,outputConfidenceMasks:!0,runningMode:"VIDEO",canvas:u.segmenterCanvas,baseOptions:{modelAssetPath:u.modelAssetPath,delegate:u.delegate}})},Ls=async e=>{u.segmenterCanvas=e,u.segmenterTextureToCanvas=Un(u.segmenterCanvas),await h1()},Is=async e=>{u.processCanvas=e,await u1()},l1=async(e={})=>{try{u.status=z.Opening,e.processingWidth&&(u.width=e.processingWidth),e.processingHeight&&(u.height=e.processingHeight),e.renderOptions&&Ms(e.renderOptions),u.directOutput=!!e.output,u.output=e.output??$e(u.width,u.height);let{basePath:t,imageSegmenterOptions:r={}}=e;u.modelAssetPath=r.modelAsset?.path??u.modelAssetPath,u.delegate=r.delegate??u.delegate,u.visionInstance=await dt.forVisionTasks(t),u.backgroundImages=Xc(e.backgroundImage&&[[e.backgroundImage.key,e.backgroundImage.image]]),await Is(r.canvas??$e(u.width,u.height)),await Ls(r.segmenterCanvas??$e(u.width,u.height)),u.renderUtils=Cs(u.width,u.height),u.status=z.Opened,pe({type:"opened"})}catch(t){u.status=z.Error;let r=Cn(t);pe({type:"event",data:{type:Sn(r),message:r}})}},d1=(e,t)=>{try{u.videoFrame=e,_(u.segmenter),_(u.renderUtils),t&&Ms(t),_(!u.renderer?.isContextLost(),C.ContextLost);let r=u.status===z.Error||u.status===z.Opening||u.status===z.Updating||u.renderOptions.effects==="none"||u.renderOptions.effects==="blur"&&u.renderOptions.backgroundBlurAmount===0||u.renderOptions?.effects==="overlay"&&!u.renderOptions.backgroundImageUrl;if(r)return pe({type:"processed",data:e},[e.frame]),e.frame.close(),pe({type:"debug",data:{message:"skip processing",context:{name:"media worker",renderingOptions:u.renderOptions,status:u.status,contextLost:u.renderer?.isContextLost()}}});if(u.renderOptions?.effects==="overlay"&&u.renderOptions.backgroundImageUrl){let n=u.backgroundImages?.getImage(u.renderOptions.backgroundImageUrl);n?u.renderOptions.backgroundImage=n:(r=!0,u.backgroundImages?.tryFetchingImage(u.renderOptions.backgroundImageUrl).catch(o=>{u.status=z.Error,pe({type:"debug",data:{message:`failed to download ${u.renderOptions.backgroundImageUrl}`,context:{name:"media worker",error:o}}})}))}u.status=z.Processing,u.segmenter.segmentForVideo(u.renderUtils.renderImageToOffScreenCanvas(e.frame,"inputCanvas"),performance.now(),n=>{let{confidenceMasks:o}=n,s=o?.[0];if(!s)pe({type:"processed"});else{_(u.output),_(u.renderer),_(u.renderUtils),_(u.processCanvas),_(u.segmenterCanvas),_(u.segmenterTextureToCanvas),u.segmenterTextureToCanvas.render(au(s));let a=u.segmenterCanvas.transferToImageBitmap();u.renderer.render(a,e,u.renderOptions),u.renderUtils.renderImageToCanvas(u.processCanvas,u.output,u.width,u.height),e.frame.close();let i=u.directOutput?void 0:u.output.transferToImageBitmap();pe({type:"processed",data:i&&{frame:i,width:u.output.width,height:u.output.height,timestamp:performance.now()}},i?[i]:void 0)}n.close(),u.status=z.Idle})}catch(r){let n=Cn(r);return u.status=z.Error,pe({type:"event",data:{type:Sn(n),message:n,frame:e}},[e.frame]),e.frame.close()}},f1=async({backgroundImage:e,renderOptions:t,imageSegmenterOptions:r,processingHeight:n,processingWidth:o,output:s,restart:a})=>{if(u.status!==z.Updating)try{u.status=z.Updating,e&&u.backgroundImages?.setImage(e.key,e.image);let i=a;if(n&&n!==u.height&&(u.height=n,i=!0),o&&o!==u.width&&(u.width=o,i=!0),t?.backend&&!pu(t.backend)){u.status=z.Error,pe({type:"event",data:{type:"Error",message:"Render backend is not webgl or webgpu"}});return}let c=t?.backend&&t?.backend!==u.renderOptions.backend;t&&Ms(t),r&&(u.modelAssetPath=r.modelAsset?.path??u.modelAssetPath,u.delegate=r.delegate??u.delegate,r.canvas!==u.processCanvas&&await Is(r.canvas??$e(u.width,u.height)),r.segmenterCanvas!==u.segmenterCanvas&&await Ls(r?.segmenterCanvas??$e(u.width,u.height))),s!==void 0&&(u.output=s??$e(u.width,u.height),u.directOutput=!!s),(i||c)&&(s===void 0&&(u.output=$e(u.width,u.height)),u.renderUtils=Cs(u.width,u.height),await Is(r?.canvas??$e(u.width,u.height))),i&&await Ls(r?.segmenterCanvas??$e(u.width,u.height)),u.status=z.Updated,pe({type:"updated"})}catch(i){u.status=z.Error;let c=Cn(i);pe({type:"event",data:{type:Sn(c),message:c}})}};self.addEventListener("message",e=>{switch(e.data.type){case"open":{l1(e.data.data);break}case"update":{f1(e.data.data);break}case"process":{let{videoFrame:t,renderOptions:r}=e.data.data;d1(t,r);break}case"close":{u.status=z.Closing,u.renderer?.release(),u.segmenterTextureToCanvas?.release(),u.videoFrame?.frame.close(),u.segmenter?.close(),u.backgroundImages?.clear(),u.status=z.Closed;break}case"destroy":{u.status=z.Destroying,u.renderer=void 0,u.videoFrame=void 0,u.segmenter=void 0,u.backgroundImages=void 0,u.status=z.Destroyed;break}}});self.addEventListener("error",e=>{e.preventDefault(),pe({type:"event",data:{type:C.Error,message:`Uncaught Error event: ${e.error}`}})});
|
|
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 yu=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatFullChannelSupported:i,floatSingleChannelSupported:u,release:l}=he(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:de,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 m=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,m),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=ve(n,e,r,!1,u,i),w=ae(n,p);return{render:({mask:A,prevMask:v},C)=>{I(!n.isContextLost(),O.ContextLost),n.bindFramebuffer(n.FRAMEBUFFER,w),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,v.texture);let k=K.projection(1,1,1);return n.uniformMatrix3fv(a.matrix,!1,k),n.uniform1f(a.maskCombineRatio,C.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(m),n.deleteTexture(p),n.deleteFramebuffer(w),n.deleteVertexArray(c),l()}}};var Oh=`#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 hp=16,dp=Et(0,hp),Dh=(t,e,r)=>{let{gl:n,program:s,attribLocations:o,uniformLocations:a,floatSingleChannelSupported:i,floatFullChannelSupported:u,release:l}=he(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:de,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 m=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,m),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=ve(n,e,r,!1,i,u),w=ae(n,p),A=ve(n,e,r,!1,i,u),v=ae(n,A),C=t.width/e;return{render:(k,T)=>{I(!n.isContextLost(),O.ContextLost),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(s),n.bindVertexArray(c),n.uniform2f(a.texelSize,1/k.width,1/k.height),n.uniform1i(a.radiusPx,dp(Math.floor(T/C)));let S=K.projection(1,1,1);n.uniformMatrix3fv(a.matrix,!1,S);let F=w,B=k.texture;for(let z=0;z<2;z++)n.activeTexture(n.TEXTURE0),n.uniform1i(a.mask,0),n.bindTexture(n.TEXTURE_2D,B),n.uniform2f(a.direction,1-z,0+z),n.bindFramebuffer(n.FRAMEBUFFER,F),n.viewport(0,0,k.width,k.height),n.drawArrays(n.TRIANGLES,0,6),[B,F]=F===w?[p,v]:[A,w];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(m),n.deleteTexture(p),n.deleteTexture(A),n.deleteFramebuffer(w),n.deleteFramebuffer(v),n.deleteVertexArray(c),l()}}};var No=(t,e)=>{let{gl:r,program:n,attribLocations:s,uniformLocations:o,floatFullChannelSupported:a,floatSingleChannelSupported:i,release:u}=he(t,{attribs:{position:"a_position",texCoord:"a_texCoord"},uniforms:{matrix:"u_matrix",texture:"u_texture"},vertexSrc:de,fragmentSrc:En}),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 m=Gt(r,t.width,t.height,!0,a),p=e?ve(r,t.width,t.height,!1,i,a):Gt(r,t.width,t.height,!0,a),w=ae(r,p);return{render:A=>{I(!r.isContextLost(),O.ContextLost),r.bindFramebuffer(r.FRAMEBUFFER,w),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 v=K.projection(1,1,1);return r.uniformMatrix3fv(o.matrix,!1,v),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,m),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(m),r.deleteTexture(p),r.deleteVertexArray(l),u()}}};var Mh=(t,e=new OffscreenCanvas(hn,fn))=>{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:()=>No(e,!1),blendRenderer:()=>Eh(e),blurRenderer:()=>Oo(e,3),canvasRenderer:()=>Do(e),frameDownsampler2:()=>Ct(e,!1,!0,r,n),frameDownsampler4:()=>Ct(e,!1,!0,s,o),geodesicReconstructionRenderer2:()=>gu(e,r,n),geodesicReconstructionRenderer4:()=>gu(e,s,o),jointBilateralFilterRenderer2:()=>Mo(e,r,n),jointBilateralFilterRenderer4:()=>Mo(e,s,o),jointBilateralFilterRenderer:()=>Mo(e,e.width,e.height),lightWrapBlurRenderer:()=>Oo(e,3),maskBlurRenderer:()=>Dh(e,e.width,e.height),strongMaskBlurRenderer:()=>Oo(e,qn),maskDownsampler2:()=>Ct(e,!0,!1,r,n),maskDownsampler4:()=>Ct(e,!0,!1,s,o),maskRenderer:()=>No(e,!0),maskUpsampler2:()=>Ct(e,!0,!1,r,n),maskUpsampler4:()=>Ct(e,!0,!1,s,o),maskUpsampler:()=>Ct(e,!0,!1,e.width,e.height),morphErodeRenderer:()=>xu(e,r,n),morphErodeRenderer4:()=>xu(e,s,o),prevMaskRenderer2:()=>Ct(e,!0,!1,r,n),prevMaskRenderer4:()=>Ct(e,!0,!1,s,o),replaceRenderer:()=>Lh(e),selectCenterComponent:()=>Rh(e,a,i),smoothingMaskRenderer4:()=>yu(e,s,o),smoothingMaskRenderer2:()=>yu(e,r,n),binaryMaskRenderer2:()=>pu(e,r,n),binaryMaskRenderer4:()=>pu(e,s,o),videoFrameRenderer:()=>No(e,!1),release:v=>()=>{for(let C in v)C!=="release"&&v[C]?.release()}},l=dn(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=Wf(e,{contextLost:t.contextLost,contextRestored:t.contextRestored,contextCreationError:t.contextCreationError},p),c.gl=e.getContext("webgl2",{premultipliedAlpha:!1,powerPreference:"high-performance"}),I(c.gl,O.ContextCreationError)},m=(v,C,k)=>{I(!c.gl?.isContextLost(),O.ContextLost);let T=c.videoFrameRenderer.render(C),S=c.maskRenderer.render(v),F,B;switch(k.downSampleFactor){case 4:{let N=c.maskDownsampler4.render(S),U=c.frameDownsampler4.render(T),V=c.jointBilateralFilterRenderer4.render({input:N,guide:U},k);if(F=c.smoothingMaskRenderer4.render({mask:V,prevMask:c.prevMask4??V},k),k.excludeBystanders){let te=c.binaryMaskRenderer4.render(F,k.foregroundThreshold),ue=c.morphErodeRenderer4.render({mask:te},k),me=c.selectCenterComponent.render(ue,k),pe=c.maskUpsampler4.render(me);F=c.geodesicReconstructionRenderer4.render({mask:pe,maskRef:F},k)}let P=c.maskUpsampler.render(F);B=c.strongMaskBlurRenderer.render(P,qn);break}default:{let N=c.maskDownsampler2.render(S),U=c.frameDownsampler2.render(T),V=c.jointBilateralFilterRenderer2.render({input:N,guide:U},k);if(F=c.smoothingMaskRenderer2.render({mask:V,prevMask:c.prevMask2??V},k),k.excludeBystanders){let te=c.binaryMaskRenderer2.render(F,k.foregroundThreshold),ue=c.morphErodeRenderer.render({mask:te},k),me=c.selectCenterComponent.render(ue,k),pe=c.maskUpsampler2.render(me);F=c.geodesicReconstructionRenderer2.render({mask:pe,maskRef:F},k)}let P=c.maskUpsampler.render(F);B=c.maskBlurRenderer.render(P,k.edgeBlurAmount);break}}let z=T;if(k.effects==="blur"&&k.backgroundBlurAmount){let N=c.blurRenderer.render(T,k.backgroundBlurAmount);z=c.blendRenderer.render({mask:B,foreground:T,background:N},k)}else if(k?.effects==="overlay"&&k.backgroundImage){let N=c.backgroundImageRenderer.render(k.backgroundImage);z=c.replaceRenderer.render({mask:B,foreground:T,background:N,blurredBackground:c.lightWrapBlurRenderer.render(N,k.lightWrapBlurAmount),timestamp:C.timestamp},k)}switch(c.canvasRenderer.render(z),k.downSampleFactor){case 4:c.prevMask4=c.prevMaskRenderer4.render(F);break;default:c.prevMask2=c.prevMaskRenderer2.render(F);break}},p=()=>{c.canvasContextEventsCleanup(),l.release(),l=dn(u),c.prevMask2=void 0,c.prevMask4=void 0};return{init:f,render:m,release:()=>{p()},isContextLost:()=>!!c.gl?.isContextLost()}};var os=(t,e)=>new OffscreenCanvas(t,e);var Nh=t=>typeof t=="string"?Object.values(Gf).includes(t):!1;var E={width:hn,height:fn,status:Se.New,stats:[],delegate:"GPU",modelAssetPath:"",muted:!1,renderOptions:{edgeBlurAmount:4,backgroundBlurAmount:3,backgroundThreshold:.35,foregroundThreshold:.85,maskCombineRatio:.8,effects:Nf.None,sigmaRangeHi:Ii[1],sigmaRangeLo:Ii[0],sigmaSpace:Mf,backgroundImageUrl:"",backgroundImage:null,backend:"webgl",personCenter:Df,excludeBystanders:!1,morphPass:4,morphErodeRadiusPx:5,morphDilateRadiusPx:6,lightWrapIntensity:.8,lightWrapTightness:1,downSampleFactor:2,lightWrapBlurAmount:1,lightWrapEdgeBand:.25}},wu=oo(E.renderOptions),Tu=()=>{E.trackEventsSubscription?.(),E.originalTrack?.stop()},et=(t,e)=>postMessage(t,e??[]),Rp=t=>{if(E.status!==Se.Error){E.status=Se.Error;try{E.segmenter?.close()}catch(e){et({type:"event",data:{type:O.ContextLost,message:`Failed to close segmenter ${e}`}})}E.segmenter=void 0}et({type:"event",data:{type:O.ContextLost,message:t}})},Ip=t=>{et({type:"event",data:{type:O.ContextRestored,message:t}})},Sp=t=>{E.status!==Se.Error&&(E.status=Se.Error),et({type:"event",data:{type:O.ContextCreationError,message:t}})},Cp=async()=>{E.renderer?.release(),E.renderer=void 0;let t=[{contextLost:Rp,contextRestored:Ip,contextCreationError:Sp},E.processCanvas],e=()=>Mh(...t);if(navigator.gpu&&E.renderOptions?.backend==="webgpu"){let n=await navigator.gpu.requestAdapter({powerPreference:"high-performance"});n?E.renderer=ph(n,...t):(E.renderer=e(),E.renderOptions.backend="webgl")}else E.renderer=e(),E.renderOptions.backend="webgl";await E.renderer?.init()},Fp=async()=>{I(E.visionInstance),E.segmenter?.close(),E.segmenter=await ze.createFromOptions(E.visionInstance,{outputCategoryMask:!1,outputConfidenceMasks:!0,runningMode:"VIDEO",canvas:E.segmenterCanvas,baseOptions:{modelAssetPath:E.modelAssetPath,delegate:E.delegate}})},Vh=async t=>{E.segmenterTextureToCanvas?.release(),E.segmenterCanvas=t,E.segmenterTextureToCanvas=Do(E.segmenterCanvas),await Fp()},Wh=async t=>{E.processCanvas=t,await Cp()},_u=()=>{E.muted=!0,E.originalTrack&&(E.originalTrack.enabled=!1)},bu=()=>{E.muted=!1,E.originalTrack&&(E.originalTrack.enabled=!0)},Bp=t=>(t.addEventListener("mute",_u),t.addEventListener("unmute",bu),t.addEventListener("ended",vu),()=>{t.removeEventListener("mute",_u),t.removeEventListener("unmute",bu),t.removeEventListener("ended",vu)}),$h=t=>{let e={},{backgroundImage:r,...n}=E.renderOptions,s=Pf(t,n);for(let[o,a]of Object.entries(s.changed))e[o]=a.new;return e},Up=async(t={})=>{try{E.status=Se.Opening,t.processingWidth&&(E.width=t.processingWidth),t.processingHeight&&(E.height=t.processingHeight),t.renderOptions&&wu(t.renderOptions);let{basePath:e,imageSegmenterOptions:r={}}=t;if(E.modelAssetPath=r.modelAsset?.path??E.modelAssetPath,E.delegate=r.delegate??E.delegate,E.visionInstance=await lr.forVisionTasks(e),E.backgroundImages?.clear(),E.backgroundImages=Vf(t.backgroundImage&&[[t.backgroundImage.key,t.backgroundImage.image]]),t.renderOptions?.backgroundImageUrl&&t.backgroundImage?.key!==t.renderOptions.backgroundImageUrl){let s=await ku(t.renderOptions.backgroundImageUrl);s&&(E.renderOptions.backgroundImage=s)}await Wh(os(E.width,E.height)),await Vh(os(E.width,E.height)),E.status=Se.Opened;let n={};t.renderOptions&&(n=$h(t.renderOptions)),et({type:"opened",data:n})}catch(e){E.status=Se.Error;let r=so(e);et({type:"event",data:{type:no(r),message:r}})}},Lp=Math.trunc(30*.8),Gh=t=>{E.stats.push(t),E.stats.length>=Lp&&(Dp(),E.stats.length=0)},Pp={async transform(t,e){let r=performance.now();if(E.renderOptions.effects==="none"||E.muted){Gh({start:r,end:r}),e.enqueue(t);return}I(E.segmenter);let n=E.segmenter.segmentForVideo(t,r),s=performance.now(),o=n.confidenceMasks?.[0];if(o){I(E.renderer),I(E.processCanvas),I(E.segmenterCanvas),I(E.segmenterTextureToCanvas),E.segmenterTextureToCanvas.render(wh(o)),E.renderer.render(E.segmenterCanvas,t,E.renderOptions);let a=new VideoFrame(E.processCanvas,{timestamp:t.timestamp});e.enqueue(a),t.close()}else e.enqueue(t);n.close(),Gh({start:r,segmentation:s,end:performance.now()})}},zh=(t,e,r)=>t.pipeThrough(new TransformStream(Pp),{signal:r}).pipeTo(e),Op=async(t,e)=>{try{let r=new VideoTrackGenerator;et({type:"processed",data:r.track},[r.track]);let{readable:n}=new MediaStreamTrackProcessor({track:t});await zh(n,r.writable,e)}catch(r){if(Tu(),e&&!(e.aborted&&(e.reason==="close"||!("reason"in AbortSignal.prototype))))throw r}},ku=t=>(E.imageFetcherAbortController?.abort("close"),E.imageFetcherAbortController=new AbortController,E.backgroundImages?.tryFetchingImage(t,E.imageFetcherAbortController.signal)),Dp=()=>{E.stats.length&&(et({type:"stats",data:E.stats}),E.stats.length=0)},Mp=async(t,e,r,n)=>{try{if(I(E.segmenter),I(t||e&&r),n&&wu(n),I(!E.renderer?.isContextLost(),O.ContextLost),E.renderOptions?.effects==="overlay"&&E.renderOptions.backgroundImageUrl){let s=E.backgroundImages?.getImage(E.renderOptions.backgroundImageUrl);if(s)E.renderOptions.backgroundImage=s;else{let o=await ku(E.renderOptions.backgroundImageUrl);o&&(E.renderOptions.backgroundImage=o)}}E.status=Se.Processing,E.processingAbortController=new AbortController,E.stats.length=0,t?(Tu(),E.originalTrack=t,E.muted=!t.enabled,E.trackEventsSubscription=Bp(t),await Op(t,E.processingAbortController.signal)):(I(e&&r),et({type:"processed"}),await zh(e,r,E.processingAbortController.signal))}catch(s){let o=so(s);if(o==="close")return;E.status=Se.Error,et({type:"event",data:{type:no(o),message:o,track:t}},t?[t]:[])}},Np=async({backgroundImage:t,renderOptions:e,imageSegmenterOptions:r,processingHeight:n,processingWidth:s,restart:o})=>{if(E.status!==Se.Updating)try{if(E.status=Se.Updating,t&&E.backgroundImages?.setImage(t.key,t.image),e?.backgroundImageUrl){let l=await ku(e.backgroundImageUrl);l&&(E.renderOptions.backgroundImage=l)}let a=o;if(n&&n!==E.height&&(E.height=n,a=!0),s&&s!==E.width&&(E.width=s,a=!0),e?.backend&&!Nh(e.backend)){E.status=Se.Error,et({type:"event",data:{type:"Error",message:"Render backend is not webgl or webgpu"}});return}e?.effects&&e.effects!==E.renderOptions.effects&&(E.stats.length=0);let i=e?.backend&&e?.backend!==E.renderOptions.backend;e&&wu(e),r&&(E.modelAssetPath=r.modelAsset?.path??E.modelAssetPath,E.delegate=r.delegate??E.delegate),(a||i)&&await Wh(os(E.width,E.height)),a&&await Vh(os(E.width,E.height)),E.status=Se.Updated;let u={};e&&(u=$h(e)),et({type:"updated",data:u}),a&&et({type:"event",data:{type:O.ProcessorRestarted}})}catch(a){E.status=Se.Error;let i=so(a);et({type:"event",data:{type:no(i),message:i}})}},Gp=()=>{E.status=Se.Idle,Tu(),E.processingAbortController?.abort("close"),E.imageFetcherAbortController?.abort("close")},vu=()=>{E.status=Se.Closing,Gp(),E.stats.length=0,E.status=Se.Closed};self.addEventListener("message",t=>{switch(t.data.type){case"open":{Up(t.data.data);break}case"update":{Np(t.data.data);break}case"process":{let{track:e,readable:r,writable:n,renderOptions:s}=t.data.data;Mp(e,r,n,s);break}case"close":{vu();break}case"mute":{t.data.data?_u():bu();break}case"destroy":{E.status=Se.Destroying,E.renderer?.release(),E.segmenterTextureToCanvas?.release(),E.segmenter?.close(),E.backgroundImages?.clear(),E.originalTrack=void 0,E.renderer=void 0,E.segmenter=void 0,E.backgroundImages=void 0,E.trackEventsSubscription=void 0,E.status=Se.Destroyed;break}}});self.addEventListener("error",t=>{t.preventDefault(),et({type:"event",data:{type:O.Error,message:`Uncaught Error event: ${t.error}`}})});
|