UNPKG

@vonage/ml-transformers

Version:

<!-- README for NPM; the one for GitHub is in .github directory. -->

19 lines (17 loc) 596 kB
(function(De,Ar){typeof exports=="object"&&typeof module<"u"?Ar(exports):typeof define=="function"&&define.amd?define(["exports"],Ar):(De=typeof globalThis<"u"?globalThis:De||self,Ar(De["ml-transformers"]={}))})(this,function(De){"use strict";function Ar(){return new Promise((r,e)=>{typeof MediaStreamTrackProcessor>"u"||typeof MediaStreamTrackGenerator>"u"?e("Your browser does not support the MediaStreamTrack API for Insertable Streams of Media."):r()})}class tr{}tr.updates={transformer_new:"New transformer",transformer_null:"Null transformer"},tr.errors={transformer_none:"No transformers provided",transformer_start:"Cannot start transformer",transformer_transform:"Cannot transform frame",transformer_flush:"Cannot flush transformer",readable_null:"Readable is null",writable_null:"Writable is null"};function m2(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}const rr=new WeakMap,ui=new WeakMap,Br=new WeakMap,ho=Symbol("anyProducer"),Zs=Promise.resolve(),ai=Symbol("listenerAdded"),hi=Symbol("listenerRemoved");let fo=!1;function Sr(r){if(typeof r!="string"&&typeof r!="symbol")throw new TypeError("eventName must be a string or a symbol")}function di(r){if(typeof r!="function")throw new TypeError("listener must be a function")}function Tr(r,e){const i=ui.get(r);return i.has(e)||i.set(e,new Set),i.get(e)}function zr(r,e){const i=typeof e=="string"||typeof e=="symbol"?e:ho,m=Br.get(r);return m.has(i)||m.set(i,new Set),m.get(i)}function p2(r,e,i){const m=Br.get(r);if(m.has(e))for(const v of m.get(e))v.enqueue(i);if(m.has(ho)){const v=Promise.all([e,i]);for(const S of m.get(ho))S.enqueue(v)}}function vs(r,e){e=Array.isArray(e)?e:[e];let i=!1,m=()=>{},v=[];const S={enqueue(L){v.push(L),m()},finish(){i=!0,m()}};for(const L of e)zr(r,L).add(S);return{async next(){return v?v.length===0?i?(v=void 0,this.next()):(await new Promise(L=>{m=L}),this.next()):{done:!1,value:await v.shift()}:{done:!0}},async return(L){v=void 0;for(const T of e)zr(r,T).delete(S);return m(),arguments.length>0?{done:!0,value:await L}:{done:!0}},[Symbol.asyncIterator](){return this}}}function Gs(r){if(r===void 0)return Xs;if(!Array.isArray(r))throw new TypeError("`methodNames` must be an array of strings");for(const e of r)if(!Xs.includes(e))throw typeof e!="string"?new TypeError("`methodNames` element must be a string"):new Error(`${e} is not Emittery method`);return r}const mo=r=>r===ai||r===hi;let fi=class ys{static mixin(e,i){return i=Gs(i),m=>{if(typeof m!="function")throw new TypeError("`target` must be function");for(const L of i)if(m.prototype[L]!==void 0)throw new Error(`The property \`${L}\` already exists on \`target\``);function v(){return Object.defineProperty(this,e,{enumerable:!1,value:new ys}),this[e]}Object.defineProperty(m.prototype,e,{enumerable:!1,get:v});const S=L=>function(...T){return this[e][L](...T)};for(const L of i)Object.defineProperty(m.prototype,L,{enumerable:!1,value:S(L)});return m}}static get isDebugEnabled(){if(typeof process!="object")return fo;const{env:e}=process||{env:{}};return e.DEBUG==="emittery"||e.DEBUG==="*"||fo}static set isDebugEnabled(e){fo=e}constructor(e={}){rr.set(this,new Set),ui.set(this,new Map),Br.set(this,new Map),this.debug=e.debug||{},this.debug.enabled===void 0&&(this.debug.enabled=!1),this.debug.logger||(this.debug.logger=(i,m,v,S)=>{try{S=JSON.stringify(S)}catch{S=`Object with the following keys failed to stringify: ${Object.keys(S).join(",")}`}typeof v=="symbol"&&(v=v.toString());const L=new Date,T=`${L.getHours()}:${L.getMinutes()}:${L.getSeconds()}.${L.getMilliseconds()}`;console.log(`[${T}][emittery:${i}][${m}] Event Name: ${v} data: ${S}`)})}logIfDebugEnabled(e,i,m){(ys.isDebugEnabled||this.debug.enabled)&&this.debug.logger(e,this.debug.name,i,m)}on(e,i){di(i),e=Array.isArray(e)?e:[e];for(const m of e)Sr(m),Tr(this,m).add(i),this.logIfDebugEnabled("subscribe",m,void 0),mo(m)||this.emit(ai,{eventName:m,listener:i});return this.off.bind(this,e,i)}off(e,i){di(i),e=Array.isArray(e)?e:[e];for(const m of e)Sr(m),Tr(this,m).delete(i),this.logIfDebugEnabled("unsubscribe",m,void 0),mo(m)||this.emit(hi,{eventName:m,listener:i})}once(e){return new Promise(i=>{const m=this.on(e,v=>{m(),i(v)})})}events(e){e=Array.isArray(e)?e:[e];for(const i of e)Sr(i);return vs(this,e)}async emit(e,i){Sr(e),this.logIfDebugEnabled("emit",e,i),p2(this,e,i);const m=Tr(this,e),v=rr.get(this),S=[...m],L=mo(e)?[]:[...v];await Zs,await Promise.all([...S.map(async T=>{if(m.has(T))return T(i)}),...L.map(async T=>{if(v.has(T))return T(e,i)})])}async emitSerial(e,i){Sr(e),this.logIfDebugEnabled("emitSerial",e,i);const m=Tr(this,e),v=rr.get(this),S=[...m],L=[...v];await Zs;for(const T of S)m.has(T)&&await T(i);for(const T of L)v.has(T)&&await T(e,i)}onAny(e){return di(e),this.logIfDebugEnabled("subscribeAny",void 0,void 0),rr.get(this).add(e),this.emit(ai,{listener:e}),this.offAny.bind(this,e)}anyEvent(){return vs(this)}offAny(e){di(e),this.logIfDebugEnabled("unsubscribeAny",void 0,void 0),this.emit(hi,{listener:e}),rr.get(this).delete(e)}clearListeners(e){e=Array.isArray(e)?e:[e];for(const i of e)if(this.logIfDebugEnabled("clear",i,void 0),typeof i=="string"||typeof i=="symbol"){Tr(this,i).clear();const m=zr(this,i);for(const v of m)v.finish();m.clear()}else{rr.get(this).clear();for(const m of ui.get(this).values())m.clear();for(const m of Br.get(this).values()){for(const v of m)v.finish();m.clear()}}}listenerCount(e){e=Array.isArray(e)?e:[e];let i=0;for(const m of e){if(typeof m=="string"){i+=rr.get(this).size+Tr(this,m).size+zr(this,m).size+zr(this).size;continue}typeof m<"u"&&Sr(m),i+=rr.get(this).size;for(const v of ui.get(this).values())i+=v.size;for(const v of Br.get(this).values())i+=v.size}return i}bindMethods(e,i){if(typeof e!="object"||e===null)throw new TypeError("`target` must be an object");i=Gs(i);for(const m of i){if(e[m]!==void 0)throw new Error(`The property \`${m}\` already exists on \`target\``);Object.defineProperty(e,m,{enumerable:!1,value:this[m].bind(this)})}}};const Xs=Object.getOwnPropertyNames(fi.prototype).filter(r=>r!=="constructor");Object.defineProperty(fi,"listenerAdded",{value:ai,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(fi,"listenerRemoved",{value:hi,writable:!1,enumerable:!0,configurable:!1});var b2=fi;const po=m2(b2);function y2(r){return typeof r=="object"&&r!==null&&"message"in r&&typeof r.message=="string"}function g2(r){if(y2(r))return r;try{return new Error(JSON.stringify(r))}catch{return new Error(String(r))}}function bo(r){return g2(r).message}var Z2=Object.defineProperty,v2=(r,e,i)=>e in r?Z2(r,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[e]=i,G2=(r,e,i)=>(v2(r,e+"",i),i);const X2="hlg.tokbox.com/prod/logging/vcp_webrtc",W2="https://",V2=1e4;let mi;const R2=new Uint8Array(16);function x2(){if(!mi&&(mi=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!mi))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return mi(R2)}const Hn=[];for(let r=0;r<256;++r)Hn.push((r+256).toString(16).slice(1));function I2(r,e=0){return(Hn[r[e+0]]+Hn[r[e+1]]+Hn[r[e+2]]+Hn[r[e+3]]+"-"+Hn[r[e+4]]+Hn[r[e+5]]+"-"+Hn[r[e+6]]+Hn[r[e+7]]+"-"+Hn[r[e+8]]+Hn[r[e+9]]+"-"+Hn[r[e+10]]+Hn[r[e+11]]+Hn[r[e+12]]+Hn[r[e+13]]+Hn[r[e+14]]+Hn[r[e+15]]).toLowerCase()}const S2=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Ws={randomUUID:S2};function T2(r,e,i){if(Ws.randomUUID&&!e&&!r)return Ws.randomUUID();r=r||{};const m=r.random||(r.rng||x2)();return m[6]=m[6]&15|64,m[8]=m[8]&63|128,I2(m)}function yo(r,e){globalThis.vonage||(globalThis.vonage={}),globalThis.vonage.workerizer||(globalThis.vonage.workerizer={});let i=globalThis.vonage.workerizer;return i[r]||(i[r]=e),i[r]}const ir=yo("globals",{});var br=(r=>(r.INIT="INIT",r.FORWARD="FORWARD",r.TERMINATE="TERMINATE",r.GLOBALS_SYNC="GLOBALS_SYNC",r))(br||{});function Vs(r){return[ImageBitmap,ReadableStream,WritableStream].some(e=>r instanceof e)}let Y2=0;function F2(r,e,i,m,v){const S=Y2++;return r.postMessage({id:S,type:e,functionName:i,args:m},m.filter(L=>Vs(L))),new Promise(L=>{v==null||v.set(S,L)})}function jr(r,e){const{id:i,type:m}=r,v=Array.isArray(e)?e:[e];postMessage({id:i,type:m,result:e},v.filter(S=>Vs(S)))}const Rs=yo("workerized",{});function xs(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}async function w2(){if(xs())jr({type:br.GLOBALS_SYNC},ir);else{const r=[];for(const e in Rs){const{worker:i,resolvers:m}=Rs[e].workerContext;i&&r.push(F2(i,br.GLOBALS_SYNC,"",[ir],m))}await Promise.all(r)}}function pi(r,e){if(Array.isArray(e))e.splice(0,e.length);else if(typeof e=="object")for(const i in e)delete e[i];for(const i in r)Array.isArray(r[i])?(e[i]=[],pi(r[i],e[i])):typeof r[i]=="object"?(e[i]={},pi(r[i],e[i])):e[i]=r[i]}async function L2(r,e){const{functionName:i,args:m}=r;if(!e.instance)throw"instance not initialized";if(!i)throw"missing function name to call";if(!e.instance[i])throw`undefined function [${i}] in class ${e.instance.constructor.workerId}`;jr(r,await e.instance[i](...m??[]))}const H2=yo("registeredWorkers",{});function C2(r,e){if(!r.args)throw"Missing className while initializing worker";const[i,m]=r.args,v=H2[i];if(v)e.instance=new v(r.args.slice(1));else throw`unknown worker class ${i}`;pi(m,ir),jr(r,typeof e.instance!==void 0)}async function N2(r,e){const{args:i}=r;if(!e.instance)throw"instance not initialized";let m;e.instance.terminate&&(m=await e.instance.terminate(...i??[])),jr(r,m)}function U2(r){if(!r.args)throw"Missing globals while syncing";pi(r.args[0],ir),jr(r,{})}function J2(){const r={};onmessage=async e=>{const i=e.data;switch(i.type){case br.INIT:C2(i,r);break;case br.FORWARD:L2(i,r);break;case br.TERMINATE:N2(i,r);break;case br.GLOBALS_SYNC:U2(i);break}}}xs()&&J2();function E2(r,e){return ir[r]||(ir[r]=e),[()=>ir[r],async i=>{ir[r]=i,await w2()}]}function k2(r,e){return E2(r,e)}const[M2,A2]=k2("metadata");function B2(r){A2(r)}function bi(){return M2()}let go=class{constructor(e,i){G2(this,"uuid"),this.config=e,this.uuid=i??T2()}async send(e){var i,m,v;const{appId:S,sourceType:L}=(i=bi())!=null?i:{};if(!S||!L)return"metadata missing";const T=new AbortController,J=setTimeout(()=>T.abort(),V2);return await((v=(m=this.config)==null?void 0:m.fetch)!=null?v:fetch)(this.getUrl(),{method:"POST",headers:this.getHeaders(),body:JSON.stringify(this.buildReport(e)),signal:T.signal}),clearTimeout(J),"success"}getUrl(){var e;let i=(e=bi().proxyUrl)!=null?e:W2;return i+=(i.at(-1)==="/"?"":"/")+X2,i}getHeaders(){return{"Content-Type":"application/json"}}buildReport(e){const i=bi();return{guid:this.uuid,...e,applicationId:i.appId,timestamp:Date.now(),proxyUrl:i.proxyUrl,source:i.sourceType}}};const yi="2.0.4";class z2{constructor(e,i){this.config=e,this.frameTransformedCount=0,this.frameFromSourceCount=0,this.startAt=0,this.reporter=new go(e,i)}async onFrameFromSource(){this.frameFromSourceCount++}get fps(){const{startAt:e,frameFromSourceCount:i}=this,m=(Date.now()-e)/1e3;return i/m}async onFrameTransformed(e={},i=!1){this.startAt===0&&(this.startAt=Date.now()),this.frameTransformedCount++;const{startAt:m,frameTransformedCount:v,frameFromSourceCount:S}=this,L=Date.now(),T=(L-m)/1e3,J=v/T,tt=S/T;return i||this.frameTransformedCount>=this.config.loggingIntervalFrameCount?(this.frameFromSourceCount=0,this.frameTransformedCount=0,this.startAt=L,this.reporter.config=this.config,this.reporter.send({...this.config.report,variation:"QoS",fps:tt,transformedFps:J,framesTransformed:v,...e})):"success"}}var Is=(r=>(r.FPS_DROP="fps_drop",r))(Is||{}),Ss=(r=>(r.start="start",r.transform="transform",r.flush="flush",r))(Ss||{}),gi=(r=>(r.pipeline_ended="pipeline_ended",r.pipeline_ended_with_error="pipeline_ended_with_error",r.pipeline_started="pipeline_started",r.pipeline_started_with_error="pipeline_started_with_error",r.pipeline_restarted="pipeline_restarted",r.pipeline_restarted_with_error="pipeline_restarted_with_error",r))(gi||{});const j2=500,K2=.8;class P2 extends po{constructor(e,i){super(),this.reporter_=new go,this.reporterQos_=new z2({loggingIntervalFrameCount:j2,report:{version:yi}}),this.index_=i,this.transformer_=e,this.shouldStop_=!1,this.isFlashed_=!1,this.mediaTransformerQosReportStartTimestamp_=0,this.videoHeight_=0,this.videoWidth_=0,this.trackExpectedRate_=-1,this.transformerType_="Custom","getTransformerType"in e&&(this.transformerType_=e.getTransformerType()),this.report({variation:"Create"})}setTrackExpectedRate(e){this.trackExpectedRate_=e}async start(e){if(this.controller_=e,this.transformer_&&typeof this.transformer_.start=="function")try{await this.transformer_.start(e)}catch(i){this.report({message:tr.errors.transformer_start,variation:"Error",error:bo(i)});const m={eventMetaData:{transformerIndex:this.index_},error:i,function:"start"};this.emit("error",m)}}async transform(e,i){var m,v;if(this.mediaTransformerQosReportStartTimestamp_===0&&(this.mediaTransformerQosReportStartTimestamp_=Date.now()),e instanceof VideoFrame&&(this.videoHeight_=(e==null?void 0:e.displayHeight)??0,this.videoWidth_=(e==null?void 0:e.displayWidth)??0),this.reporterQos_.onFrameFromSource(),this.transformer_)if(this.shouldStop_)console.warn("[Pipeline] flush from transform"),e.close(),this.flush(i),i.terminate();else{try{await((v=(m=this.transformer_).transform)==null?void 0:v.call(m,e,i)),this.reportQos()}catch(S){this.report({message:tr.errors.transformer_transform,variation:"Error",error:bo(S)});const L={eventMetaData:{transformerIndex:this.index_},error:S,function:"transform"};this.emit("error",L)}if(this.trackExpectedRate_!=-1&&this.trackExpectedRate_*K2>this.reporterQos_.fps){const S={eventMetaData:{transformerIndex:this.index_},warningType:"fps_drop",dropInfo:{requested:this.trackExpectedRate_,current:this.reporterQos_.fps}};this.emit("warn",S)}}}async flush(e){if(this.transformer_&&typeof this.transformer_.flush=="function"&&!this.isFlashed_){this.isFlashed_=!0;try{await this.transformer_.flush(e)}catch(i){this.report({message:tr.errors.transformer_flush,variation:"Error",error:bo(i)});const m={eventMetaData:{transformerIndex:this.index_},error:i,function:"flush"};this.emit("error",m)}}this.reportQos(!0),this.report({variation:"Delete"})}stop(){console.log("[Pipeline] Stop stream."),this.controller_&&(this.flush(this.controller_),this.controller_.terminate()),this.shouldStop_=!0}report(e){this.reporter_.send({version:yi,action:"MediaTransformer",transformerType:this.transformerType_,...e})}reportQos(e=!1){this.reporterQos_.config={...this.reporterQos_.config},this.reporterQos_.onFrameTransformed({version:yi,action:"MediaTransformer",transformerType:this.transformerType_,videoWidth:this.videoWidth_,videoHeight:this.videoHeight_},e)}}class O2 extends po{constructor(e){super(),this.transformers_=[],this.trackExpectedRate_=-1;for(let i=0;i<e.length;i++){let m=new P2(e[i],i);m.on("error",v=>{this.emit("error",v)}),m.on("warn",v=>{this.emit("warn",v)}),this.transformers_.push(m)}}setTrackExpectedRate(e){this.trackExpectedRate_=e;for(let i of this.transformers_)i.setTrackExpectedRate(this.trackExpectedRate_)}async start(e,i){if(!this.transformers_||this.transformers_.length===0){console.log("[Pipeline] No transformers.");return}try{let m=e;for(let v of this.transformers_)e=e.pipeThrough(new TransformStream(v));e.pipeTo(i).then(async()=>{console.log("[Pipeline] Setup."),await i.abort(),await m.cancel(),this.emit("pipelineInfo","pipeline_ended")}).catch(async v=>{e.cancel().then(()=>{console.log("[Pipeline] Shutting down streams after abort.")}).catch(S=>{console.error("[Pipeline] Error from stream transform:",S)}),await i.abort(v),await m.cancel(v),this.emit("pipelineInfo","pipeline_ended_with_error")})}catch{this.emit("pipelineInfo","pipeline_started_with_error"),this.destroy();return}this.emit("pipelineInfo","pipeline_started"),console.log("[Pipeline] Pipeline started.")}async destroy(){console.log("[Pipeline] Destroying Pipeline.");for(let e of this.transformers_)e.stop()}}class _2 extends po{constructor(){super(),this.reporter_=new go,this.trackExpectedRate_=-1,this.report({variation:"Create"})}setTrackExpectedRate(e){this.trackExpectedRate_=e,this.pipeline_&&this.pipeline_.setTrackExpectedRate(this.trackExpectedRate_)}transform(e,i){return this.readable_=e,this.writable_=i,this.transformInternal()}transformInternal(){return new Promise(async(e,i)=>{if(!this.transformers_||this.transformers_.length===0){this.report({message:tr.errors.transformer_none,variation:"Error"}),i("[MediaProcessor] Need to set transformers.");return}if(!this.readable_){this.report({variation:"Error",message:tr.errors.readable_null}),i("[MediaProcessor] Readable is null.");return}if(!this.writable_){this.report({variation:"Error",message:tr.errors.writable_null}),i("[MediaProcessor] Writable is null.");return}let m=!1;this.pipeline_&&(m=!0,this.pipeline_.clearListeners(),this.pipeline_.destroy()),this.pipeline_=new O2(this.transformers_),this.pipeline_.on("warn",v=>{this.emit("warn",v)}),this.pipeline_.on("error",v=>{this.emit("error",v)}),this.pipeline_.on("pipelineInfo",v=>{m&&(v==="pipeline_started"?v=gi.pipeline_restarted:v==="pipeline_started_with_error"&&(v=gi.pipeline_restarted_with_error)),this.emit("pipelineInfo",v)}),this.trackExpectedRate_!=-1&&this.pipeline_.setTrackExpectedRate(this.trackExpectedRate_),this.pipeline_.start(this.readable_,this.writable_).then(()=>{e()}).catch(v=>{i(v)})})}setTransformers(e){return this.report({variation:"Update",message:tr.updates.transformer_new}),this.transformers_=e,this.readable_&&this.writable_?this.transformInternal():Promise.resolve()}destroy(){return new Promise(async e=>{this.pipeline_&&this.pipeline_.destroy(),this.report({variation:"Delete"}),e()})}report(e){this.reporter_.send({version:yi,action:"MediaProcessor",...e})}}class Q2{constructor(){this.processor_=null,this.generator_=null}init(e){return new Promise((i,m)=>{try{this.processor_=new MediaStreamTrackProcessor(e)}catch(v){console.log(`[InsertableStreamHelper] MediaStreamTrackProcessor failed: ${v}`),m(v)}try{e.kind==="audio"?this.generator_=new MediaStreamTrackGenerator({kind:"audio"}):e.kind==="video"?this.generator_=new MediaStreamTrackGenerator({kind:"video"}):m("kind not supported")}catch(v){console.log(`[InsertableStreamHelper] MediaStreamTrackGenerator failed: ${v}`),m(v)}i()})}getReadable(){return this.processor_.readable}getWriteable(){return this.generator_.writable}getProccesorTrack(){return this.generator_}}class D2{constructor(e){this.insertableStreamHelper_=new Q2,this.mediaProcessor_=e}setTrack(e){return new Promise((i,m)=>{this.insertableStreamHelper_.init(e).then(()=>{this.mediaProcessor_.transform(this.insertableStreamHelper_.getReadable(),this.insertableStreamHelper_.getWriteable()).then(()=>{i(this.insertableStreamHelper_.getProccesorTrack())}).catch(v=>{m(v)})}).catch(v=>{m(v)})})}destroy(){return new Promise((e,i)=>{this.mediaProcessor_?this.mediaProcessor_.destroy().then(()=>{e()}).catch(m=>{i(m)}):i("no processor")})}}var Kr=(r=>(r.Low="Low",r.High="High",r))(Kr||{}),Ts=(r=>(r.BackgroundBlur="BackgroundBlur",r.VirtualBackground="VirtualBackground",r.VideoBackground="VideoBackground",r.SilhouetteBlur="SilhouetteBlur",r))(Ts||{}),Zi=(r=>(r.FAST="FAST",r.PRECISE="PRECISE",r))(Zi||{}),Pr=(r=>(r.CANVAS="CANVAS",r.WEBGL="WEBGL",r))(Pr||{});const $2=async()=>WebAssembly.validate(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 q2(){const{wasm:r,insertableStreams:e,simd:i,webgl:m}=await Ys();if(!r.supported)throw r.message;if(!e.supported)throw e.message;if(!i.supported)throw i.message;if(!m.supported)throw m.message}async function Ys(){const r={wasm:{supported:typeof WebAssembly=="object"&&typeof WebAssembly.instantiate=="function",message:"Your browser does not support WebAssembly features."},simd:{supported:await $2(),message:"Your browser does not support simd features."},insertableStreams:{supported:!0},gpu:{message:"Your browser does not support gpu features.",supported:!0},webgl:tc(),performance:Fs()};try{await Ar()}catch(e){r.insertableStreams.supported=!1,r.insertableStreams.message=e}return r}function tc(){if(!OffscreenCanvas)return{supported:!1,message:"Your browser does not support offscreen canvas"};const e=new OffscreenCanvas(0,0).getContext("webgl2");if(e){const i=e==null?void 0:e.getExtension("WEBGL_lose_context");i&&i.loseContext()}else return{supported:!1,message:"Your browser does not support webgl 2"};return{supported:!0}}function Fs(){const e=new OffscreenCanvas(0,0).getContext("webgl2",{failIfMajorPerformanceCaveat:!0});if(e){const i=e==null?void 0:e.getExtension("WEBGL_lose_context");i&&i.loseContext()}else return{supported:!1,message:"Your hardware does not perform good enough to run the library efficiently"};return{supported:!0}}const vi={};(function(){var r;function e(p){var W=0;return function(){return W<p.length?{done:!1,value:p[W++]}:{done:!0}}}var i=typeof Object.defineProperties=="function"?Object.defineProperty:function(p,W,V){return p==Array.prototype||p==Object.prototype||(p[W]=V.value),p};function m(p){p=[typeof globalThis=="object"&&globalThis,p,typeof window=="object"&&window,typeof self=="object"&&self,typeof global=="object"&&global];for(var W=0;W<p.length;++W){var V=p[W];if(V&&V.Math==Math)return V}throw Error("Cannot find global object")}var v=m(this);function S(p,W){if(W)t:{var V=v;p=p.split(".");for(var E=0;E<p.length-1;E++){var P=p[E];if(!(P in V))break t;V=V[P]}p=p[p.length-1],E=V[p],W=W(E),W!=E&&W!=null&&i(V,p,{configurable:!0,writable:!0,value:W})}}S("Symbol",function(p){function W(rt){if(this instanceof W)throw new TypeError("Symbol is not a constructor");return new V(E+(rt||"")+"_"+P++,rt)}function V(rt,K){this.g=rt,i(this,"description",{configurable:!0,writable:!0,value:K})}if(p)return p;V.prototype.toString=function(){return this.g};var E="jscomp_symbol_"+(1e9*Math.random()>>>0)+"_",P=0;return W}),S("Symbol.iterator",function(p){if(p)return p;p=Symbol("Symbol.iterator");for(var W="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),V=0;V<W.length;V++){var E=v[W[V]];typeof E=="function"&&typeof E.prototype[p]!="function"&&i(E.prototype,p,{configurable:!0,writable:!0,value:function(){return L(e(this))}})}return p});function L(p){return p={next:p},p[Symbol.iterator]=function(){return this},p}function T(p){var W=typeof Symbol<"u"&&Symbol.iterator&&p[Symbol.iterator];return W?W.call(p):{next:e(p)}}function J(p){if(!(p instanceof Array)){p=T(p);for(var W,V=[];!(W=p.next()).done;)V.push(W.value);p=V}return p}var tt=typeof Object.create=="function"?Object.create:function(p){function W(){}return W.prototype=p,new W},st;if(typeof Object.setPrototypeOf=="function")st=Object.setPrototypeOf;else{var bt;t:{var xt={a:!0},Yt={};try{Yt.__proto__=xt,bt=Yt.a;break t}catch{}bt=!1}st=bt?function(p,W){if(p.__proto__=W,p.__proto__!==W)throw new TypeError(p+" is not extensible");return p}:null}var at=st;function dt(p,W){if(p.prototype=tt(W.prototype),p.prototype.constructor=p,at)at(p,W);else for(var V in W)if(V!="prototype")if(Object.defineProperties){var E=Object.getOwnPropertyDescriptor(W,V);E&&Object.defineProperty(p,V,E)}else p[V]=W[V];p.ea=W.prototype}function Et(){this.l=!1,this.i=null,this.h=void 0,this.g=1,this.s=this.m=0,this.j=null}function Mt(p){if(p.l)throw new TypeError("Generator is already running");p.l=!0}Et.prototype.o=function(p){this.h=p};function oe(p,W){p.j={U:W,V:!0},p.g=p.m||p.s}Et.prototype.return=function(p){this.j={return:p},this.g=this.s};function D(p,W,V){return p.g=V,{value:W}}function fn(p){this.g=new Et,this.h=p}function yn(p,W){Mt(p.g);var V=p.g.i;return V?ge(p,"return"in V?V.return:function(E){return{value:E,done:!0}},W,p.g.return):(p.g.return(W),Kt(p))}function ge(p,W,V,E){try{var P=W.call(p.g.i,V);if(!(P instanceof Object))throw new TypeError("Iterator result "+P+" is not an object");if(!P.done)return p.g.l=!1,P;var rt=P.value}catch(K){return p.g.i=null,oe(p.g,K),Kt(p)}return p.g.i=null,E.call(p.g,rt),Kt(p)}function Kt(p){for(;p.g.g;)try{var W=p.h(p.g);if(W)return p.g.l=!1,{value:W.value,done:!1}}catch(V){p.g.h=void 0,oe(p.g,V)}if(p.g.l=!1,p.g.j){if(W=p.g.j,p.g.j=null,W.V)throw W.U;return{value:W.return,done:!0}}return{value:void 0,done:!0}}function Pn(p){this.next=function(W){return Mt(p.g),p.g.i?W=ge(p,p.g.i.next,W,p.g.o):(p.g.o(W),W=Kt(p)),W},this.throw=function(W){return Mt(p.g),p.g.i?W=ge(p,p.g.i.throw,W,p.g.o):(oe(p.g,W),W=Kt(p)),W},this.return=function(W){return yn(p,W)},this[Symbol.iterator]=function(){return this}}function ue(p,W){return W=new Pn(new fn(W)),at&&p.prototype&&at(W,p.prototype),W}function yt(p,W){p instanceof String&&(p+="");var V=0,E=!1,P={next:function(){if(!E&&V<p.length){var rt=V++;return{value:W(rt,p[rt]),done:!1}}return E=!0,{done:!0,value:void 0}}};return P[Symbol.iterator]=function(){return P},P}var On=typeof Object.assign=="function"?Object.assign:function(p,W){for(var V=1;V<arguments.length;V++){var E=arguments[V];if(E)for(var P in E)Object.prototype.hasOwnProperty.call(E,P)&&(p[P]=E[P])}return p};S("Object.assign",function(p){return p||On}),S("Promise",function(p){function W(K){this.h=0,this.i=void 0,this.g=[],this.o=!1;var nt=this.j();try{K(nt.resolve,nt.reject)}catch(ht){nt.reject(ht)}}function V(){this.g=null}function E(K){return K instanceof W?K:new W(function(nt){nt(K)})}if(p)return p;V.prototype.h=function(K){if(this.g==null){this.g=[];var nt=this;this.i(function(){nt.l()})}this.g.push(K)};var P=v.setTimeout;V.prototype.i=function(K){P(K,0)},V.prototype.l=function(){for(;this.g&&this.g.length;){var K=this.g;this.g=[];for(var nt=0;nt<K.length;++nt){var ht=K[nt];K[nt]=null;try{ht()}catch(vt){this.j(vt)}}}this.g=null},V.prototype.j=function(K){this.i(function(){throw K})},W.prototype.j=function(){function K(vt){return function(Ct){ht||(ht=!0,vt.call(nt,Ct))}}var nt=this,ht=!1;return{resolve:K(this.C),reject:K(this.l)}},W.prototype.C=function(K){if(K===this)this.l(new TypeError("A Promise cannot resolve to itself"));else if(K instanceof W)this.F(K);else{t:switch(typeof K){case"object":var nt=K!=null;break t;case"function":nt=!0;break t;default:nt=!1}nt?this.u(K):this.m(K)}},W.prototype.u=function(K){var nt=void 0;try{nt=K.then}catch(ht){this.l(ht);return}typeof nt=="function"?this.G(nt,K):this.m(K)},W.prototype.l=function(K){this.s(2,K)},W.prototype.m=function(K){this.s(1,K)},W.prototype.s=function(K,nt){if(this.h!=0)throw Error("Cannot settle("+K+", "+nt+"): Promise already settled in state"+this.h);this.h=K,this.i=nt,this.h===2&&this.D(),this.A()},W.prototype.D=function(){var K=this;P(function(){if(K.B()){var nt=v.console;typeof nt<"u"&&nt.error(K.i)}},1)},W.prototype.B=function(){if(this.o)return!1;var K=v.CustomEvent,nt=v.Event,ht=v.dispatchEvent;return typeof ht>"u"?!0:(typeof K=="function"?K=new K("unhandledrejection",{cancelable:!0}):typeof nt=="function"?K=new nt("unhandledrejection",{cancelable:!0}):(K=v.document.createEvent("CustomEvent"),K.initCustomEvent("unhandledrejection",!1,!0,K)),K.promise=this,K.reason=this.i,ht(K))},W.prototype.A=function(){if(this.g!=null){for(var K=0;K<this.g.length;++K)rt.h(this.g[K]);this.g=null}};var rt=new V;return W.prototype.F=function(K){var nt=this.j();K.J(nt.resolve,nt.reject)},W.prototype.G=function(K,nt){var ht=this.j();try{K.call(nt,ht.resolve,ht.reject)}catch(vt){ht.reject(vt)}},W.prototype.then=function(K,nt){function ht(jt,Ft){return typeof jt=="function"?function(Vt){try{vt(jt(Vt))}catch(Ht){Ct(Ht)}}:Ft}var vt,Ct,Tt=new W(function(jt,Ft){vt=jt,Ct=Ft});return this.J(ht(K,vt),ht(nt,Ct)),Tt},W.prototype.catch=function(K){return this.then(void 0,K)},W.prototype.J=function(K,nt){function ht(){switch(vt.h){case 1:K(vt.i);break;case 2:nt(vt.i);break;default:throw Error("Unexpected state: "+vt.h)}}var vt=this;this.g==null?rt.h(ht):this.g.push(ht),this.o=!0},W.resolve=E,W.reject=function(K){return new W(function(nt,ht){ht(K)})},W.race=function(K){return new W(function(nt,ht){for(var vt=T(K),Ct=vt.next();!Ct.done;Ct=vt.next())E(Ct.value).J(nt,ht)})},W.all=function(K){var nt=T(K),ht=nt.next();return ht.done?E([]):new W(function(vt,Ct){function Tt(Vt){return function(Ht){jt[Vt]=Ht,Ft--,Ft==0&&vt(jt)}}var jt=[],Ft=0;do jt.push(void 0),Ft++,E(ht.value).J(Tt(jt.length-1),Ct),ht=nt.next();while(!ht.done)})},W}),S("Object.is",function(p){return p||function(W,V){return W===V?W!==0||1/W===1/V:W!==W&&V!==V}}),S("Array.prototype.includes",function(p){return p||function(W,V){var E=this;E instanceof String&&(E=String(E));var P=E.length;for(V=V||0,0>V&&(V=Math.max(V+P,0));V<P;V++){var rt=E[V];if(rt===W||Object.is(rt,W))return!0}return!1}}),S("String.prototype.includes",function(p){return p||function(W,V){if(this==null)throw new TypeError("The 'this' value for String.prototype.includes must not be null or undefined");if(W instanceof RegExp)throw new TypeError("First argument to String.prototype.includes must not be a regular expression");return this.indexOf(W,V||0)!==-1}}),S("Array.prototype.keys",function(p){return p||function(){return yt(this,function(W){return W})}});var _n=this||self;function Xe(p,W){p=p.split(".");var V=_n;p[0]in V||typeof V.execScript>"u"||V.execScript("var "+p[0]);for(var E;p.length&&(E=p.shift());)p.length||W===void 0?V[E]&&V[E]!==Object.prototype[E]?V=V[E]:V=V[E]={}:V[E]=W}function Lt(p,W){return W=String.fromCharCode.apply(null,W),p==null?W:p+W}var Ye,on=typeof TextDecoder<"u",gn,Fn=typeof TextEncoder<"u";function xn(p){if(Fn)p=(gn||(gn=new TextEncoder)).encode(p);else{var W=void 0;W=W===void 0?!1:W;for(var V=0,E=new Uint8Array(3*p.length),P=0;P<p.length;P++){var rt=p.charCodeAt(P);if(128>rt)E[V++]=rt;else{if(2048>rt)E[V++]=rt>>6|192;else{if(55296<=rt&&57343>=rt){if(56319>=rt&&P<p.length){var K=p.charCodeAt(++P);if(56320<=K&&57343>=K){rt=1024*(rt-55296)+K-56320+65536,E[V++]=rt>>18|240,E[V++]=rt>>12&63|128,E[V++]=rt>>6&63|128,E[V++]=rt&63|128;continue}else P--}if(W)throw Error("Found an unpaired surrogate");rt=65533}E[V++]=rt>>12|224,E[V++]=rt>>6&63|128}E[V++]=rt&63|128}}p=E.subarray(0,V)}return p}var Nn={},sn=null;function an(p,W){W===void 0&&(W=0),Zn(),W=Nn[W];for(var V=Array(Math.floor(p.length/3)),E=W[64]||"",P=0,rt=0;P<p.length-2;P+=3){var K=p[P],nt=p[P+1],ht=p[P+2],vt=W[K>>2];K=W[(K&3)<<4|nt>>4],nt=W[(nt&15)<<2|ht>>6],ht=W[ht&63],V[rt++]=vt+K+nt+ht}switch(vt=0,ht=E,p.length-P){case 2:vt=p[P+1],ht=W[(vt&15)<<2]||E;case 1:p=p[P],V[rt]=W[p>>2]+W[(p&3)<<4|vt>>4]+ht+E}return V.join("")}function kn(p){var W=p.length,V=3*W/4;V%3?V=Math.floor(V):"=.".indexOf(p[W-1])!=-1&&(V="=.".indexOf(p[W-2])!=-1?V-2:V-1);var E=new Uint8Array(V),P=0;return wn(p,function(rt){E[P++]=rt}),E.subarray(0,P)}function wn(p,W){function V(ht){for(;E<p.length;){var vt=p.charAt(E++),Ct=sn[vt];if(Ct!=null)return Ct;if(!/^[\s\xa0]*$/.test(vt))throw Error("Unknown base64 encoding at char: "+vt)}return ht}Zn();for(var E=0;;){var P=V(-1),rt=V(0),K=V(64),nt=V(64);if(nt===64&&P===-1)break;W(P<<2|rt>>4),K!=64&&(W(rt<<4&240|K>>2),nt!=64&&W(K<<6&192|nt))}}function Zn(){if(!sn){sn={};for(var p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),W=["+/=","+/","-_=","-_.","-_"],V=0;5>V;V++){var E=p.concat(W[V].split(""));Nn[V]=E;for(var P=0;P<E.length;P++){var rt=E[P];sn[rt]===void 0&&(sn[rt]=P)}}}}var ln=typeof Uint8Array.prototype.slice=="function",In;function vn(p,W,V){return W===V?In||(In=new Uint8Array(0)):ln?p.slice(W,V):new Uint8Array(p.subarray(W,V))}var be=0,We=0;function Oe(p,W){W=W===void 0?{}:W,W=W.v===void 0?!1:W.v,this.h=null,this.g=this.i=this.j=0,this.l=!1,this.v=W,p&&pe(this,p)}function pe(p,W){W=W.constructor===Uint8Array?W:W.constructor===ArrayBuffer?new Uint8Array(W):W.constructor===Array?new Uint8Array(W):W.constructor===String?kn(W):W instanceof Uint8Array?new Uint8Array(W.buffer,W.byteOffset,W.byteLength):new Uint8Array(0),p.h=W,p.j=0,p.i=p.h.length,p.g=p.j}Oe.prototype.reset=function(){this.g=this.j};function ye(p){var W=p.h,V=W[p.g],E=V&127;return 128>V?(p.g+=1,E):(V=W[p.g+1],E|=(V&127)<<7,128>V?(p.g+=2,E):(V=W[p.g+2],E|=(V&127)<<14,128>V?(p.g+=3,E):(V=W[p.g+3],E|=(V&127)<<21,128>V?(p.g+=4,E):(V=W[p.g+4],E|=(V&15)<<28,128>V?(p.g+=5,E>>>0):(p.g+=5,128<=W[p.g++]&&128<=W[p.g++]&&128<=W[p.g++]&&128<=W[p.g++]&&p.g++,E)))))}function qe(p){var W=p.h[p.g],V=p.h[p.g+1],E=p.h[p.g+2],P=p.h[p.g+3];return p.g+=4,V=(W<<0|V<<8|E<<16|P<<24)>>>0,p=2*(V>>31)+1,W=V>>>23&255,V&=8388607,W==255?V?NaN:1/0*p:W==0?p*Math.pow(2,-149)*V:p*Math.pow(2,W-150)*(V+Math.pow(2,23))}var Ce=[];function Ot(){this.g=new Uint8Array(64),this.h=0}Ot.prototype.push=function(p){if(!(this.h+1<this.g.length)){var W=this.g;this.g=new Uint8Array(Math.ceil(1+2*this.g.length)),this.g.set(W)}this.g[this.h++]=p},Ot.prototype.length=function(){return this.h},Ot.prototype.end=function(){var p=this.g,W=this.h;return this.h=0,vn(p,0,W)};function he(p,W){for(;127<W;)p.push(W&127|128),W>>>=7;p.push(W)}function Fe(p){var W={},V=W.N===void 0?!1:W.N;this.o={v:W.v===void 0?!1:W.v},this.N=V,W=this.o,Ce.length?(V=Ce.pop(),W&&(V.v=W.v),p&&pe(V,p),p=V):p=new Oe(p,W),this.g=p,this.m=this.g.g,this.h=this.i=this.l=-1,this.j=!1}Fe.prototype.reset=function(){this.g.reset(),this.h=this.l=-1};function Ut(p){var W=p.g;if((W=W.g==W.i)||(W=p.j)||(W=p.g,W=W.l||0>W.g||W.g>W.i),W)return!1;p.m=p.g.g,W=ye(p.g);var V=W&7;return V!=0&&V!=5&&V!=1&&V!=2&&V!=3&&V!=4?(p.j=!0,!1):(p.i=W,p.l=W>>>3,p.h=V,!0)}function Ze(p){switch(p.h){case 0:if(p.h!=0)Ze(p);else{for(p=p.g;p.h[p.g]&128;)p.g++;p.g++}break;case 1:p.h!=1?Ze(p):(p=p.g,p.g+=8);break;case 2:if(p.h!=2)Ze(p);else{var W=ye(p.g);p=p.g,p.g+=W}break;case 5:p.h!=5?Ze(p):(p=p.g,p.g+=4);break;case 3:W=p.l;do{if(!Ut(p)){p.j=!0;break}if(p.h==4){p.l!=W&&(p.j=!0);break}Ze(p)}while(!0);break;default:p.j=!0}}function _t(p,W,V){var E=p.g.i,P=ye(p.g);return P=p.g.g+P,p.g.i=P,V(W,p),p.g.g=P,p.g.i=E,W}function ae(p){var W=ye(p.g);p=p.g;var V=p.g;p.g+=W,p=p.h;var E;if(on)(E=Ye)||(E=Ye=new TextDecoder("utf-8",{fatal:!1})),E=E.decode(p.subarray(V,V+W));else{W=V+W;for(var P=[],rt=null,K,nt,ht;V<W;)K=p[V++],128>K?P.push(K):224>K?V>=W?P.push(65533):(nt=p[V++],194>K||(nt&192)!==128?(V--,P.push(65533)):P.push((K&31)<<6|nt&63)):240>K?V>=W-1?P.push(65533):(nt=p[V++],(nt&192)!==128||K===224&&160>nt||K===237&&160<=nt||((E=p[V++])&192)!==128?(V--,P.push(65533)):P.push((K&15)<<12|(nt&63)<<6|E&63)):244>=K?V>=W-2?P.push(65533):(nt=p[V++],(nt&192)!==128||(K<<28)+(nt-144)>>30||((E=p[V++])&192)!==128||((ht=p[V++])&192)!==128?(V--,P.push(65533)):(K=(K&7)<<18|(nt&63)<<12|(E&63)<<6|ht&63,K-=65536,P.push((K>>10&1023)+55296,(K&1023)+56320))):P.push(65533),8192<=P.length&&(rt=Lt(rt,P),P.length=0);E=Lt(rt,P)}return E}function xe(){this.h=[],this.i=0,this.g=new Ot}function _e(p,W){W.length!==0&&(p.h.push(W),p.i+=W.length)}function me(p){var W=p.i+p.g.length();if(W===0)return new Uint8Array(0);W=new Uint8Array(W);for(var V=p.h,E=V.length,P=0,rt=0;rt<E;rt++){var K=V[rt];K.length!==0&&(W.set(K,P),P+=K.length)}return V=p.g,E=V.h,E!==0&&(W.set(V.g.subarray(0,E),P),V.h=0),p.h=[W],W}function At(p,W,V){if(V!=null){he(p.g,8*W+5),p=p.g;var E=V;E=(V=0>E?1:0)?-E:E,E===0?0<1/E?be=We=0:(We=0,be=2147483648):isNaN(E)?(We=0,be=2147483647):34028234663852886e22<E?(We=0,be=(V<<31|2139095040)>>>0):11754943508222875e-54>E?(E=Math.round(E/Math.pow(2,-149)),We=0,be=(V<<31|E)>>>0):(W=Math.floor(Math.log(E)/Math.LN2),E*=Math.pow(2,-W),E=Math.round(8388608*E)&8388607,We=0,be=(V<<31|W+127<<23|E)>>>0),V=be,p.push(V>>>0&255),p.push(V>>>8&255),p.push(V>>>16&255),p.push(V>>>24&255)}}var Ue=typeof Uint8Array=="function";function Be(p,W,V){if(p!=null)return typeof p=="object"?Ue&&p instanceof Uint8Array?V(p):ve(p,W,V):W(p)}function ve(p,W,V){if(Array.isArray(p)){for(var E=Array(p.length),P=0;P<p.length;P++)E[P]=Be(p[P],W,V);return Array.isArray(p)&&p.W&&hn(E),E}E={};for(P in p)E[P]=Be(p[P],W,V);return E}function Tn(p){return typeof p=="number"?isFinite(p)?p:String(p):p}var tn={W:{value:!0,configurable:!0}};function hn(p){return Array.isArray(p)&&!Object.isFrozen(p)&&Object.defineProperties(p,tn),p}var mn;function de(p,W,V){var E=mn;mn=null,p||(p=E),E=this.constructor.ca,p||(p=E?[E]:[]),this.j=E?0:-1,this.i=null,this.g=p;t:{if(E=this.g.length,p=E-1,E&&(E=this.g[p],E!==null&&typeof E=="object"&&E.constructor===Object)){this.l=p-this.j,this.h=E;break t}W!==void 0&&-1<W?(this.l=Math.max(W,p+1-this.j),this.h=null):this.l=Number.MAX_VALUE}if(V)for(W=0;W<V.length;W++)p=V[W],p<this.l?(p+=this.j,(E=this.g[p])?hn(E):this.g[p]=Ie):(fe(this),(E=this.h[p])?hn(E):this.h[p]=Ie)}var Ie=Object.freeze(hn([]));function fe(p){var W=p.l+p.j;p.g[W]||(p.h=p.g[W]={})}function ee(p,W,V){return W===-1?null:V!==void 0&&V||W>=p.l?p.h?p.h[W]:void 0:p.g[W+p.j]}function ze(p){var W=W===void 0?!1:W,V=ee(p,1,W);return V==null&&(V=Ie),V===Ie&&(V=hn([]),Bt(p,1,V,W)),V}function Qt(p,W,V){return p=ee(p,W),p=p==null?p:+p,p??(V===void 0?0:V)}function Bt(p,W,V,E){E!==void 0&&E||W>=p.l?(fe(p),p.h[W]=V):p.g[W+p.j]=V}function Gn(p,W){p.i||(p.i={});var V=p.i[1];if(!V){var E=ze(p);V=[];for(var P=0;P<E.length;P++)V[P]=new W(E[P]);p.i[1]=V}return V}function le(p,W,V,E){var P=Gn(p,V);W=W||new V,p=ze(p),E!=null?(P.splice(E,0,W),p.splice(E,0,wt(W))):(P.push(W),p.push(wt(W)))}de.prototype.toJSON=function(){var p=wt(this);return ve(p,Tn,an)};function wt(p,W){if(p.i)for(var V in p.i){var E=p.i[V];if(Array.isArray(E))for(var P=0;P<E.length;P++)E[P]&&wt(E[P]);else E&&wt(E)}return p.g}de.prototype.toString=function(){return wt(this).toString()};function Wt(p,W){return p=ee(p,W),p??0}function ne(p,W){return p=ee(p,W),p??""}function He(p,W){if(p=p.m){_e(W,W.g.end());for(var V=0;V<p.length;V++)_e(W,p[V])}}function Dt(p,W){if(W.h==4)return!1;var V=W.m;return Ze(W),W.N||(W=vn(W.g.h,V,W.g.g),(V=p.m)?V.push(W):p.m=[W]),!0}function re(p,W){var V=void 0;return new(V||(V=Promise))(function(E,P){function rt(ht){try{nt(W.next(ht))}catch(vt){P(vt)}}function K(ht){try{nt(W.throw(ht))}catch(vt){P(vt)}}function nt(ht){ht.done?E(ht.value):new V(function(vt){vt(ht.value)}).then(rt,K)}nt((W=W.apply(p,void 0)).next())})}function Ne(p){de.call(this,p)}dt(Ne,de);function zt(p,W){for(;Ut(W);)switch(W.i){case 8:var V=ye(W.g);Bt(p,1,V);break;case 21:V=qe(W.g),Bt(p,2,V);break;case 26:V=ae(W),Bt(p,3,V);break;case 34:V=ae(W),Bt(p,4,V);break;default:if(!Dt(p,W))return p}return p}function It(p){de.call(this,p,-1,je)}dt(It,de),It.prototype.addClassification=function(p,W){le(this,p,Ne,W)};var je=[1];function Ke(p){de.call(this,p)}dt(Ke,de);function we(p,W){for(;Ut(W);)switch(W.i){case 13:var V=qe(W.g);Bt(p,1,V);break;case 21:V=qe(W.g),Bt(p,2,V);break;case 29:V=qe(W.g),Bt(p,3,V);break;case 37:V=qe(W.g),Bt(p,4,V);break;case 45:V=qe(W.g),Bt(p,5,V);break;default:if(!Dt(p,W))return p}return p}function Pt(p){de.call(this,p,-1,Je)}dt(Pt,de);var Je=[1];function pn(p){de.call(this,p)}dt(pn,de);function en(p,W,V){if(V=p.createShader(V===0?p.VERTEX_SHADER:p.FRAGMENT_SHADER),p.shaderSource(V,W),p.compileShader(V),!p.getShaderParameter(V,p.COMPILE_STATUS))throw Error(`Could not compile WebGL shader. `+p.getShaderInfoLog(V));return V}function Ee(p){return Gn(p,Ne).map(function(W){return{index:Wt(W,1),Y:Qt(W,2),label:ee(W,3)!=null?ne(W,3):void 0,displayName:ee(W,4)!=null?ne(W,4):void 0}})}function Qe(p){return{x:Qt(p,1),y:Qt(p,2),z:Qt(p,3),visibility:ee(p,4)!=null?Qt(p,4):void 0}}function nn(p,W){this.h=p,this.g=W,this.l=0}function Ge(p,W,V){return ke(p,W),typeof p.g.canvas.transferToImageBitmap=="function"?Promise.resolve(p.g.canvas.transferToImageBitmap()):V?Promise.resolve(p.g.canvas):typeof createImageBitmap=="function"?createImageBitmap(p.g.canvas):(p.i===void 0&&(p.i=document.createElement("canvas")),new Promise(function(E){p.i.height=p.g.canvas.height,p.i.width=p.g.canvas.width,p.i.getContext("2d",{}).drawImage(p.g.canvas,0,0,p.g.canvas.width,p.g.canvas.height),E(p.i)}))}function ke(p,W){var V=p.g;if(p.m===void 0){var E=en(V,` attribute vec2 aVertex; attribute vec2 aTex; varying vec2 vTex; void main(void) { gl_Position = vec4(aVertex, 0.0, 1.0); vTex = aTex; }`,0),P=en(V,` precision mediump float; varying vec2 vTex; uniform sampler2D sampler0; void main(){ gl_FragColor = texture2D(sampler0, vTex); }`,1),rt=V.createProgram();if(V.attachShader(rt,E),V.attachShader(rt,P),V.linkProgram(rt),!V.getProgramParameter(rt,V.LINK_STATUS))throw Error(`Could not compile WebGL program. `+V.getProgramInfoLog(rt));E=p.m=rt,V.useProgram(E),P=V.getUniformLocation(E,"sampler0"),p.j={I:V.getAttribLocation(E,"aVertex"),H:V.getAttribLocation(E,"aTex"),da:P},p.s=V.createBuffer(),V.bindBuffer(V.ARRAY_BUFFER,p.s),V.enableVertexAttribArray(p.j.I),V.vertexAttribPointer(p.j.I,2,V.FLOAT,!1,0,0),V.bufferData(V.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,1,1,-1]),V.STATIC_DRAW),V.bindBuffer(V.ARRAY_BUFFER,null),p.o=V.createBuffer(),V.bindBuffer(V.ARRAY_BUFFER,p.o),V.enableVertexAttribArray(p.j.H),V.vertexAttribPointer(p.j.H,2,V.FLOAT,!1,0,0),V.bufferData(V.ARRAY_BUFFER,new Float32Array([0,1,0,0,1,0,1,1]),V.STATIC_DRAW),V.bindBuffer(V.ARRAY_BUFFER,null),V.uniform1i(P,0)}E=p.j,V.useProgram(p.m),V.canvas.width=W.width,V.canvas.height=W.height,V.viewport(0,0,W.width,W.height),V.activeTexture(V.TEXTURE0),p.h.bindTexture2d(W.glName),V.enableVertexAttribArray(E.I),V.bindBuffer(V.ARRAY_BUFFER,p.s),V.vertexAttribPointer(E.I,2,V.FLOAT,!1,0,0),V.enableVertexAttribArray(E.H),V.bindBuffer(V.ARRAY_BUFFER,p.o),V.vertexAttribPointer(E.H,2,V.FLOAT,!1,0,0),V.bindFramebuffer(V.DRAW_FRAMEBUFFER?V.DRAW_FRAMEBUFFER:V.FRAMEBUFFER,null),V.clearColor(0,0,0,0),V.clear(V.COLOR_BUFFER_BIT),V.colorMask(!0,!0,!0,!0),V.drawArrays(V.TRIANGLE_FAN,0,4),V.disableVertexAttribArray(E.I),V.disableVertexAttribArray(E.H),V.bindBuffer(V.ARRAY_BUFFER,null),p.h.bindTexture2d(0)}function Mn(p){this.g=p}var Me=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,9,1,7,0,65,0,253,15,26,11]);function Ve(p,W){return W+p}function cn(p,W){window[p]=W}function bn(p){var W=document.createElement("script");return W.setAttribute("src",p),W.setAttribute("crossorigin","anonymous"),new Promise(function(V){W.addEventListener("load",function(){V()},!1),W.addEventListener("error",function(){V()},!1),document.body.appendChild(W)})}function Le(){return re(this,function p(){return ue(p,function(W){switch(W.g){case 1:return W.m=2,D(W,WebAssembly.instantiate(Me),4);case 4:W.g=3,W.m=0;break;case 2:return W.m=0,W.j=null,W.return(!1);case 3:return W.return(!0)}})})}function Ln(p){if(this.g=p,this.listeners={},this.j={},this.F={},this.m={},this.s={},this.G=this.o=this.R=!0,this.C=Promise.resolve(),this.P="",this.B={},this.locateFile=p&&p.locateFile||Ve,typeof window=="object")var W=window.location.pathname.toString().substring(0,window.location.pathname.toString().lastIndexOf("/"))+"/";else if(typeof location<"u")W=location.pathname.toString().substring(0,location.pathname.toString().lastIndexOf("/"))+"/";else throw Error("solutions can only be loaded on a web page or in a web worker");if(this.S=W,p.options){W=T(Object.keys(p.options));for(var V=W.next();!V.done;V=W.next()){V=V.value;var E=p.options[V].default;E!==void 0&&(this.j[V]=typeof E=="function"?E():E)}}}r=Ln.prototype,r.close=function(){return this.i&&this.i.delete(),Promise.resolve()};function Ae(p,W){return p.g.files===void 0?[]:typeof p.g.files=="function"?p.g.files(W):p.g.files}function un(p){return re(p,function W(){var V=this,E,P,rt,K,nt,ht,vt,Ct,Tt,jt,Ft;return ue(W,function(Vt){switch(Vt.g){case 1:return E=V,V.R?(P=Ae(V,V.j),D(Vt,Le(),2)):Vt.return();case 2:if(rt=Vt.h,typeof window=="object")return cn("createMediapipeSolutionsWasm",{locateFile:V.locateFile}),cn("createMediapipeSolutionsPackedAssets",{locateFile:V.locateFile}),ht=P.filter(function(Ht){return Ht.data!==void 0}),vt=P.filter(function(Ht){return Ht.data===void 0}),Ct=Promise.all(ht.map(function(Ht){var kt=Pe(E,Ht.url);if(Ht.path!==void 0){var te=Ht.path;kt=kt.then(function(ie){return E.overrideFile(te,ie),Promise.resolve(ie)})}return kt})),Tt=Promise.all(vt.map(function(Ht){return Ht.simd===void 0||Ht.simd&&rt||!Ht.simd&&!rt?bn(E.locateFile(Ht.url,E.S)):Promise.resolve()})).then(function(){return re(E,function Ht(){var kt,te,ie=this;return ue(Ht,function(ce){if(ce.g==1)return kt=window.createMediapipeSolutionsWasm,te=window.createMediapipeSolutionsPackedAssets,D(ce,kt(te),2);ie.h=ce.h,ce.g=0})})}),jt=function(){return re(E,function Ht(){var kt=this;return ue(Ht,function(te){return kt.g.graph&&kt.g.graph.url?te=D(te,Pe(kt,kt.g.graph.url),0):(te.g=0,te=void 0),te})})}(),D(Vt,Promise.all([Tt,Ct,jt]),7);if(typeof importScripts!="function")throw Error("solutions can only be loaded on a web page or in a web worker");return K=P.filter(function(Ht){return Ht.simd===void 0||Ht.simd&&rt||!Ht.simd&&!rt}).map(function(Ht){return E.locateFile(Ht.url,E.S)}),importScripts.apply(null,J(K)),D(Vt,createMediapipeSolutionsWasm(Module),6);case 6:V.h=Vt.h,V.l=new OffscreenCanvas(1,1),V.h.canvas=V.l,nt=V.h.GL.createContext(V.l,{antialias:!1,alpha:!1,ba:typeof WebGL2RenderingContext<"u"?2:1}),V.h.GL.makeContextCurrent(nt),Vt.g=4;break;case 7:if(V.l=document.createElement("canvas"),Ft=V.l.getContext("webgl2",{}),!Ft&&(Ft=V.l.getContext("webgl",{}),!Ft))return alert("Failed to create WebGL canvas context when passing video frame."),Vt.return();V.D=Ft,V.h.canvas=V.l,V.h.createContext(V.l,!0,!0,{});case 4:V.i=new V.h.SolutionWasm,V.R=!1,Vt.g=0}})})}function Xn(p){return re(p,function W(){var V=this,E,P,rt,K,nt,ht,vt,Ct;return ue(W,function(Tt){if(Tt.g==1){if(V.g.graph&&V.g.graph.url&&V.P===V.g.graph.url)return Tt.return();if(V.o=!0,!V.g.graph||!V.g.graph.url){Tt.g=2;return}return V.P=V.g.graph.url,D(Tt,Pe(V,V.g.graph.url),3)}for(Tt.g!=2&&(E=Tt.h,V.i.loadGraph(E)),P=T(Object.keys(V.B)),rt=P.next();!rt.done;rt=P.next())K=rt.value,V.i.overrideFile(K,V.B[K]);if(V.B={},V.g.listeners)for(nt=T(V.g.listeners),ht=nt.next();!ht.done;ht=nt.next())vt=ht.value,jn(V,vt);Ct=V.j,V.j={},V.setOptions(Ct),Tt.g=0})})}r.reset=function(){return re(this,function p(){var W=this;return ue(p,function(V){W.i&&(W.i.reset(),W.m={},W.s={}),V.g=0})})},r.setOptions=function(p,W){var V=this;if(W=W||this.g.options){for(var E=[],P=[],rt={},K=T(Object.keys(p)),nt=K.next();!nt.done;rt={K:rt.K,L:rt.L},nt=K.next()){var ht=nt.value;ht in this.j&&this.j[ht]===p[ht]||(this.j[ht]=p[ht],nt=W[ht],nt!==void 0&&(nt.onChange&&(rt.K=nt.onChange,rt.L=p[ht],E.push(function(vt){return function(){return re(V,function Ct(){var Tt,jt=this;return ue(Ct,function(Ft){if(Ft.g==1)return D(Ft,vt.K(vt.L),2);Tt=Ft.h,Tt===!0&&(jt.o=!0),Ft.g=0})})}}(rt))),nt.graphOptionXref&&(ht={valueNumber:nt.type===1?p[ht]:0,valueBoolean:nt.type===0?p[ht]:!1,valueString:nt.type===2?p[ht]:""},nt=Object.assign(Object.assign(Object.assign({},{calculatorName:"",calculatorIndex:0}),nt.graphOptionXref),ht),P.push(nt))))}(E.length!==0||P.length!==0)&&(this.o=!0,this.A=(this.A===void 0?[]:this.A).concat(P),this.u=(this.u===void 0?[]:this.u).concat(E))}};function Un(p){return re(p,function W(){var V=this,E,P,rt,K,nt,ht,vt;return ue(W,function(Ct){switch(Ct.g){case 1:if(!V.o)return Ct.return();if(!V.u){Ct.g=2;break}E=T(V.u),P=E.next();case 3:if(P.done){Ct.g=5;break}return rt=P.value,D(Ct,rt(),4);case 4:P=E.next(),Ct.g=3;break;case 5:V.u=void 0;case 2:if(V.A){for(K=new V.h.GraphOptionChangeRequestList,nt=T(V.A),ht=nt.next();!ht.done;ht=nt.next())vt=ht.value,K.push_back(vt);V.i.changeOptions(K),K.delete(),V.A=void 0}V.o=!1,Ct.g=0}})})}r.initialize=function(){return re(this,function p(){var W=this;return ue(p,function(V){return V.g==1?D(V,un(W),2):V.g!=3?D(V,Xn(W),3):D(V,Un(W),0)})})};function Pe(p,W){return re(p,function V(){var E=this,P,rt;return ue(V,function(K){return W in E.F?K.return(E.F[W]):(P=E.locateFile(W,""),rt=fetch(P).then(function(nt){return nt.arrayBuffer()}),E.F[W]=rt,K.return(rt))})})}r.overrideFile=function(p,W){this.i?this.i.overrideFile(p,W):this.B[p]=W},r.clearOverriddenFiles=function(){this.B={},this.i&&this.i.clearOverriddenFiles()},r.send=function(p,W){return re(this,function V(){var E=this,P,rt,K,nt,ht,vt,Ct,Tt,jt;return ue(V,function(Ft){switch(Ft.g){case 1:return E.g.inputs?(P=1e3*(W??performance.now()),D(Ft,E.C,2)):Ft.return();case 2:return D(Ft,E.initialize(),3);case 3:for(rt=new E.h.PacketDataList,K=T(Object.keys(p)),nt=K.next();!nt.done;nt=K.next())if(ht=nt.value,vt=E.g.inputs[ht]){t:{var Vt=E,Ht=p[ht];switch(vt.type){case"video":var kt=Vt.m[vt.stream];if(kt||(kt=new nn(Vt.h,Vt.D),Vt.m[vt.stream]=kt),Vt=kt,Vt.l===0&&(Vt.l=Vt.h.createTexture()),typeof HTMLVideoElement<"u"&&Ht instanceof HTMLVideoElement){var te=Ht.videoWidth;kt=Ht.videoHeight}else typeof HTMLImageElement<"u"&&Ht instanceof HTMLImageElement?(te=Ht.naturalWidth,kt=Ht.naturalHeight):(te=Ht.width,kt=Ht.height);kt={glName:Vt.l,width:te,height:kt},te=Vt.g,te.canvas.width=kt.width,te.canvas.height=kt.height,te.activeTexture(te.TEXTURE0),Vt.h.bindTexture2d(Vt.l),te.texImage2D(te.TEXTURE_2D,0,te.RGBA,te.RGBA,te.UNSIGNED_BYTE,Ht),Vt.h.bindTexture2d(0),Vt=kt;break t;case"detections":for(kt=Vt.m[vt.stream],kt||(kt=new Mn(Vt.h),Vt.m[vt.stream]=kt),Vt=kt,Vt.data||(Vt.data=new Vt.g.DetectionListData),Vt.data.reset(Ht.length),kt=0;kt<Ht.length;++kt){te=Ht[kt];var ie=Vt.data,ce=ie.setBoundingBox,Re=kt,d=te.T,y=new pn;Bt(y,1,d.Z),Bt(y,2,d.$),Bt(y,3,d.height),Bt(y,4,d.width),Bt(y,5,d.rotation),Bt(y,6,d.X);var G=d=new xe;At(G,1,ee(y,1)),At(G,2,ee(y,2)),At(G,3,ee(y,3)),At(G,4,ee(y,4)),At(G,5,ee(y,5));var C=ee(y,6);if(C!=null&&C!=null){he(G.g,48);var A=G.g,O=C;C=0>O,O=Math.abs(O);var B=O>>>0;for(O=Math.floor((O-B)/4294967296),O>>>=0,C&&(O=~O>>>0,B=(~B>>>0)+1,4294967295<B&&(B=0,O++,4294967295<O&&(O=0))),be=B,We=O,C=be,B=We;0<B||127<C;)A.push(C&127|128),C=(C>>>7|B<<25)>>>0,B>>>=7;A.push(C)}if(He(y,G),d=me(d),ce.call(ie,Re,d),te.O)for(ie=0;ie<te.O.length;++ie)y=te.O[ie],G=!!y.visibility,ce=Vt.data,Re=ce.addNormalizedLandmark,d=kt,y=Object.assign(Object.assign({},y),{visibility:G?y.visibility:0}),G=new Ke,Bt(G,1,y.x),Bt(G,2,y.y),Bt(G,3,y.z),y.visibility&&Bt(G,4,y.visibility),A=y=new xe,At(A,1,ee(G,1)),At(A,2,ee(G,2)),At(A,3,ee(G,3)),