UNPKG

@vonage/ml-transformers

Version:

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

1 lines 590 kB
function l2(){return new Promise(((t,e)=>{typeof MediaStreamTrackProcessor>"u"||typeof MediaStreamTrackGenerator>"u"?e("Your browser does not support the MediaStreamTrack API for Insertable Streams of Media."):t()}))}class er{}function c2(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}er.updates={transformer_new:"New transformer",transformer_null:"Null transformer"},er.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"};const rr=new WeakMap,bi=new WeakMap,zr=new WeakMap,bo=Symbol("anyProducer"),bs=Promise.resolve(),vi=Symbol("listenerAdded"),Gi=Symbol("listenerRemoved");let so=!1;function Ir(t){if("string"!=typeof t&&"symbol"!=typeof t)throw new TypeError("eventName must be a string or a symbol")}function oi(t){if("function"!=typeof t)throw new TypeError("listener must be a function")}function Sr(t,e){const n=bi.get(t);return n.has(e)||n.set(e,new Set),n.get(e)}function jr(t,e){const n="string"==typeof e||"symbol"==typeof e?e:bo,r=zr.get(t);return r.has(n)||r.set(n,new Set),r.get(n)}function u2(t,e,n){const r=zr.get(t);if(r.has(e))for(const t of r.get(e))t.enqueue(n);if(r.has(bo)){const t=Promise.all([e,n]);for(const e of r.get(bo))e.enqueue(t)}}function ys(t,e){e=Array.isArray(e)?e:[e];let n=!1,r=()=>{},i=[];const o={enqueue(t){i.push(t),r()},finish(){n=!0,r()}};for(const n of e)jr(t,n).add(o);return{async next(){return i?0===i.length?n?(i=void 0,this.next()):(await new Promise((t=>{r=t})),this.next()):{done:!1,value:await i.shift()}:{done:!0}},async return(n){i=void 0;for(const n of e)jr(t,n).delete(o);return r(),arguments.length>0?{done:!0,value:await n}:{done:!0}},[Symbol.asyncIterator](){return this}}}function gs(t){if(void 0===t)return Zs;if(!Array.isArray(t))throw new TypeError("`methodNames` must be an array of strings");for(const e of t)if(!Zs.includes(e))throw"string"!=typeof e?new TypeError("`methodNames` element must be a string"):new Error(`${e} is not Emittery method`);return t}const lo=t=>t===vi||t===Gi;let Oi=class t{static mixin(e,n){return n=gs(n),r=>{if("function"!=typeof r)throw new TypeError("`target` must be function");for(const t of n)if(void 0!==r.prototype[t])throw new Error(`The property \`${t}\` already exists on \`target\``);Object.defineProperty(r.prototype,e,{enumerable:!1,get:function(){return Object.defineProperty(this,e,{enumerable:!1,value:new t}),this[e]}});const i=t=>function(...n){return this[e][t](...n)};for(const t of n)Object.defineProperty(r.prototype,t,{enumerable:!1,value:i(t)});return r}}static get isDebugEnabled(){if("object"!=typeof process)return so;const{env:t}=process||{env:{}};return"emittery"===t.DEBUG||"*"===t.DEBUG||so}static set isDebugEnabled(t){so=t}constructor(t={}){rr.set(this,new Set),bi.set(this,new Map),zr.set(this,new Map),this.debug=t.debug||{},void 0===this.debug.enabled&&(this.debug.enabled=!1),this.debug.logger||(this.debug.logger=(t,e,n,r)=>{try{r=JSON.stringify(r)}catch{r=`Object with the following keys failed to stringify: ${Object.keys(r).join(",")}`}"symbol"==typeof n&&(n=n.toString());const i=new Date,o=`${i.getHours()}:${i.getMinutes()}:${i.getSeconds()}.${i.getMilliseconds()}`;console.log(`[${o}][emittery:${t}][${e}] Event Name: ${n}\n\tdata: ${r}`)})}logIfDebugEnabled(e,n,r){(t.isDebugEnabled||this.debug.enabled)&&this.debug.logger(e,this.debug.name,n,r)}on(t,e){oi(e),t=Array.isArray(t)?t:[t];for(const n of t)Ir(n),Sr(this,n).add(e),this.logIfDebugEnabled("subscribe",n,void 0),lo(n)||this.emit(vi,{eventName:n,listener:e});return this.off.bind(this,t,e)}off(t,e){oi(e),t=Array.isArray(t)?t:[t];for(const n of t)Ir(n),Sr(this,n).delete(e),this.logIfDebugEnabled("unsubscribe",n,void 0),lo(n)||this.emit(Gi,{eventName:n,listener:e})}once(t){return new Promise((e=>{const n=this.on(t,(t=>{n(),e(t)}))}))}events(t){t=Array.isArray(t)?t:[t];for(const e of t)Ir(e);return ys(this,t)}async emit(t,e){Ir(t),this.logIfDebugEnabled("emit",t,e),u2(this,t,e);const n=Sr(this,t),r=rr.get(this),i=[...n],o=lo(t)?[]:[...r];await bs,await Promise.all([...i.map((async t=>{if(n.has(t))return t(e)})),...o.map((async n=>{if(r.has(n))return n(t,e)}))])}async emitSerial(t,e){Ir(t),this.logIfDebugEnabled("emitSerial",t,e);const n=Sr(this,t),r=rr.get(this),i=[...n],o=[...r];await bs;for(const t of i)n.has(t)&&await t(e);for(const n of o)r.has(n)&&await n(t,e)}onAny(t){return oi(t),this.logIfDebugEnabled("subscribeAny",void 0,void 0),rr.get(this).add(t),this.emit(vi,{listener:t}),this.offAny.bind(this,t)}anyEvent(){return ys(this)}offAny(t){oi(t),this.logIfDebugEnabled("unsubscribeAny",void 0,void 0),this.emit(Gi,{listener:t}),rr.get(this).delete(t)}clearListeners(t){t=Array.isArray(t)?t:[t];for(const e of t)if(this.logIfDebugEnabled("clear",e,void 0),"string"==typeof e||"symbol"==typeof e){Sr(this,e).clear();const t=jr(this,e);for(const e of t)e.finish();t.clear()}else{rr.get(this).clear();for(const t of bi.get(this).values())t.clear();for(const t of zr.get(this).values()){for(const e of t)e.finish();t.clear()}}}listenerCount(t){t=Array.isArray(t)?t:[t];let e=0;for(const n of t)if("string"!=typeof n){typeof n<"u"&&Ir(n),e+=rr.get(this).size;for(const t of bi.get(this).values())e+=t.size;for(const t of zr.get(this).values())e+=t.size}else e+=rr.get(this).size+Sr(this,n).size+jr(this,n).size+jr(this).size;return e}bindMethods(t,e){if("object"!=typeof t||null===t)throw new TypeError("`target` must be an object");e=gs(e);for(const n of e){if(void 0!==t[n])throw new Error(`The property \`${n}\` already exists on \`target\``);Object.defineProperty(t,n,{enumerable:!1,value:this[n].bind(this)})}}};const Zs=Object.getOwnPropertyNames(Oi.prototype).filter((t=>"constructor"!==t));Object.defineProperty(Oi,"listenerAdded",{value:vi,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(Oi,"listenerRemoved",{value:Gi,writable:!1,enumerable:!0,configurable:!1});var a2=Oi;const No=c2(a2);function h2(t){return"object"==typeof t&&null!==t&&"message"in t&&"string"==typeof t.message}function d2(t){if(h2(t))return t;try{return new Error(JSON.stringify(t))}catch{return new Error(String(t))}}function co(t){return d2(t).message}var f2=Object.defineProperty,m2=(t,e,n)=>e in t?f2(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,p2=(t,e,n)=>(m2(t,e+"",n),n);const b2="hlg.tokbox.com/prod/logging/vcp_webrtc",y2="https://",g2=1e4;let si;const Z2=new Uint8Array(16);function v2(){if(!si&&(si=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!si))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return si(Z2)}const Cn=[];for(let t=0;t<256;++t)Cn.push((t+256).toString(16).slice(1));function G2(t,e=0){return(Cn[t[e+0]]+Cn[t[e+1]]+Cn[t[e+2]]+Cn[t[e+3]]+"-"+Cn[t[e+4]]+Cn[t[e+5]]+"-"+Cn[t[e+6]]+Cn[t[e+7]]+"-"+Cn[t[e+8]]+Cn[t[e+9]]+"-"+Cn[t[e+10]]+Cn[t[e+11]]+Cn[t[e+12]]+Cn[t[e+13]]+Cn[t[e+14]]+Cn[t[e+15]]).toLowerCase()}const X2=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),vs={randomUUID:X2};function W2(t,e,n){if(vs.randomUUID&&!e&&!t)return vs.randomUUID();const r=(t=t||{}).random||(t.rng||v2)();return r[6]=15&r[6]|64,r[8]=63&r[8]|128,G2(r)}function Uo(t,e){globalThis.vonage||(globalThis.vonage={}),globalThis.vonage.workerizer||(globalThis.vonage.workerizer={});let n=globalThis.vonage.workerizer;return n[t]||(n[t]=e),n[t]}const cr=Uo("globals",{});var Gr=(t=>(t.INIT="INIT",t.FORWARD="FORWARD",t.TERMINATE="TERMINATE",t.GLOBALS_SYNC="GLOBALS_SYNC",t))(Gr||{});function Ps(t){return[ImageBitmap,ReadableStream,WritableStream].some((e=>t instanceof e))}let V2=0;function R2(t,e,n,r,i){const o=V2++;return t.postMessage({id:o,type:e,functionName:n,args:r},r.filter((t=>Ps(t)))),new Promise((t=>{null==i||i.set(o,t)}))}function $r(t,e){const{id:n,type:r}=t,i=Array.isArray(e)?e:[e];postMessage({id:n,type:r,result:e},i.filter((t=>Ps(t))))}const Gs=Uo("workerized",{});function Os(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}async function x2(){if(Os())$r({type:Gr.GLOBALS_SYNC},cr);else{const t=[];for(const e in Gs){const{worker:n,resolvers:r}=Gs[e].workerContext;n&&t.push(R2(n,Gr.GLOBALS_SYNC,"",[cr],r))}await Promise.all(t)}}function Xi(t,e){if(Array.isArray(e))e.splice(0,e.length);else if("object"==typeof e)for(const t in e)delete e[t];for(const n in t)Array.isArray(t[n])?(e[n]=[],Xi(t[n],e[n])):"object"==typeof t[n]?(e[n]={},Xi(t[n],e[n])):e[n]=t[n]}async function I2(t,e){const{functionName:n,args:r}=t;if(!e.instance)throw"instance not initialized";if(!n)throw"missing function name to call";if(!e.instance[n])throw`undefined function [${n}] in class ${e.instance.constructor.workerId}`;$r(t,await e.instance[n](...r??[]))}const S2=Uo("registeredWorkers",{});function T2(t,e){if(!t.args)throw"Missing className while initializing worker";const[n,r]=t.args,i=S2[n];if(!i)throw`unknown worker class ${n}`;e.instance=new i(t.args.slice(1)),Xi(r,cr),$r(t,void 0!==typeof e.instance)}async function Y2(t,e){const{args:n}=t;if(!e.instance)throw"instance not initialized";let r;e.instance.terminate&&(r=await e.instance.terminate(...n??[])),$r(t,r)}function F2(t){if(!t.args)throw"Missing globals while syncing";Xi(t.args[0],cr),$r(t,{})}function w2(){const t={};onmessage=async e=>{const n=e.data;switch(n.type){case Gr.INIT:T2(n,t);break;case Gr.FORWARD:I2(n,t);break;case Gr.TERMINATE:Y2(n,t);break;case Gr.GLOBALS_SYNC:F2(n)}}}function L2(t,e){return cr[t]||(cr[t]=e),[()=>cr[t],async e=>{cr[t]=e,await x2()}]}function H2(t,e){return L2(t,e)}Os()&&w2();const[C2,N2]=H2("metadata");function U2(t){N2(t)}function yi(){return C2()}let Jo=class{constructor(t,e){p2(this,"uuid"),this.config=t,this.uuid=e??W2()}async send(t){var e,n,r;const{appId:i,sourceType:o}=null!=(e=yi())?e:{};if(!i||!o)return"metadata missing";const a=new AbortController,l=setTimeout((()=>a.abort()),g2);return await(null!=(r=null==(n=this.config)?void 0:n.fetch)?r:fetch)(this.getUrl(),{method:"POST",headers:this.getHeaders(),body:JSON.stringify(this.buildReport(t)),signal:a.signal}),clearTimeout(l),"success"}getUrl(){var t;let e=null!=(t=yi().proxyUrl)?t:y2;return e+=("/"===e.at(-1)?"":"/")+b2,e}getHeaders(){return{"Content-Type":"application/json"}}buildReport(t){const e=yi();return{guid:this.uuid,...t,applicationId:e.appId,timestamp:Date.now(),proxyUrl:e.proxyUrl,source:e.sourceType}}};const gi="2.0.4";class J2{constructor(t,e){this.config=t,this.frameTransformedCount=0,this.frameFromSourceCount=0,this.startAt=0,this.reporter=new Jo(t,e)}async onFrameFromSource(){this.frameFromSourceCount++}get fps(){const{startAt:t,frameFromSourceCount:e}=this;return e/((Date.now()-t)/1e3)}async onFrameTransformed(t={},e=!1){0===this.startAt&&(this.startAt=Date.now()),this.frameTransformedCount++;const{startAt:n,frameTransformedCount:r,frameFromSourceCount:i}=this,o=Date.now(),a=(o-n)/1e3,l=r/a,s=i/a;return e||this.frameTransformedCount>=this.config.loggingIntervalFrameCount?(this.frameFromSourceCount=0,this.frameTransformedCount=0,this.startAt=o,this.reporter.config=this.config,this.reporter.send({...this.config.report,variation:"QoS",fps:s,transformedFps:l,framesTransformed:r,...t})):"success"}}var E2=(t=>(t.FPS_DROP="fps_drop",t))(E2||{}),k2=(t=>(t.start="start",t.transform="transform",t.flush="flush",t))(k2||{}),go=(t=>(t.pipeline_ended="pipeline_ended",t.pipeline_ended_with_error="pipeline_ended_with_error",t.pipeline_started="pipeline_started",t.pipeline_started_with_error="pipeline_started_with_error",t.pipeline_restarted="pipeline_restarted",t.pipeline_restarted_with_error="pipeline_restarted_with_error",t))(go||{});const M2=500,A2=.8;class B2 extends No{constructor(t,e){super(),this.reporter_=new Jo,this.reporterQos_=new J2({loggingIntervalFrameCount:M2,report:{version:gi}}),this.index_=e,this.transformer_=t,this.shouldStop_=!1,this.isFlashed_=!1,this.mediaTransformerQosReportStartTimestamp_=0,this.videoHeight_=0,this.videoWidth_=0,this.trackExpectedRate_=-1,this.transformerType_="Custom","getTransformerType"in t&&(this.transformerType_=t.getTransformerType()),this.report({variation:"Create"})}setTrackExpectedRate(t){this.trackExpectedRate_=t}async start(t){if(this.controller_=t,this.transformer_&&"function"==typeof this.transformer_.start)try{await this.transformer_.start(t)}catch(t){this.report({message:er.errors.transformer_start,variation:"Error",error:co(t)});const e={eventMetaData:{transformerIndex:this.index_},error:t,function:"start"};this.emit("error",e)}}async transform(t,e){var n,r;if(0===this.mediaTransformerQosReportStartTimestamp_&&(this.mediaTransformerQosReportStartTimestamp_=Date.now()),t instanceof VideoFrame&&(this.videoHeight_=(null==t?void 0:t.displayHeight)??0,this.videoWidth_=(null==t?void 0:t.displayWidth)??0),this.reporterQos_.onFrameFromSource(),this.transformer_)if(this.shouldStop_)console.warn("[Pipeline] flush from transform"),t.close(),this.flush(e),e.terminate();else{try{await(null==(r=(n=this.transformer_).transform)?void 0:r.call(n,t,e)),this.reportQos()}catch(t){this.report({message:er.errors.transformer_transform,variation:"Error",error:co(t)});const e={eventMetaData:{transformerIndex:this.index_},error:t,function:"transform"};this.emit("error",e)}if(-1!=this.trackExpectedRate_&&this.trackExpectedRate_*A2>this.reporterQos_.fps){const t={eventMetaData:{transformerIndex:this.index_},warningType:"fps_drop",dropInfo:{requested:this.trackExpectedRate_,current:this.reporterQos_.fps}};this.emit("warn",t)}}}async flush(t){if(this.transformer_&&"function"==typeof this.transformer_.flush&&!this.isFlashed_){this.isFlashed_=!0;try{await this.transformer_.flush(t)}catch(t){this.report({message:er.errors.transformer_flush,variation:"Error",error:co(t)});const e={eventMetaData:{transformerIndex:this.index_},error:t,function:"flush"};this.emit("error",e)}}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(t){this.reporter_.send({version:gi,action:"MediaTransformer",transformerType:this.transformerType_,...t})}reportQos(t=!1){this.reporterQos_.config={...this.reporterQos_.config},this.reporterQos_.onFrameTransformed({version:gi,action:"MediaTransformer",transformerType:this.transformerType_,videoWidth:this.videoWidth_,videoHeight:this.videoHeight_},t)}}class z2 extends No{constructor(t){super(),this.transformers_=[],this.trackExpectedRate_=-1;for(let e=0;e<t.length;e++){let n=new B2(t[e],e);n.on("error",(t=>{this.emit("error",t)})),n.on("warn",(t=>{this.emit("warn",t)})),this.transformers_.push(n)}}setTrackExpectedRate(t){this.trackExpectedRate_=t;for(let t of this.transformers_)t.setTrackExpectedRate(this.trackExpectedRate_)}async start(t,e){if(this.transformers_&&0!==this.transformers_.length){try{let n=t;for(let e of this.transformers_)t=t.pipeThrough(new TransformStream(e));t.pipeTo(e).then((async()=>{console.log("[Pipeline] Setup."),await e.abort(),await n.cancel(),this.emit("pipelineInfo","pipeline_ended")})).catch((async r=>{t.cancel().then((()=>{console.log("[Pipeline] Shutting down streams after abort.")})).catch((t=>{console.error("[Pipeline] Error from stream transform:",t)})),await e.abort(r),await n.cancel(r),this.emit("pipelineInfo","pipeline_ended_with_error")}))}catch{return this.emit("pipelineInfo","pipeline_started_with_error"),void this.destroy()}this.emit("pipelineInfo","pipeline_started"),console.log("[Pipeline] Pipeline started.")}else console.log("[Pipeline] No transformers.")}async destroy(){console.log("[Pipeline] Destroying Pipeline.");for(let t of this.transformers_)t.stop()}}class j2 extends No{constructor(){super(),this.reporter_=new Jo,this.trackExpectedRate_=-1,this.report({variation:"Create"})}setTrackExpectedRate(t){this.trackExpectedRate_=t,this.pipeline_&&this.pipeline_.setTrackExpectedRate(this.trackExpectedRate_)}transform(t,e){return this.readable_=t,this.writable_=e,this.transformInternal()}transformInternal(){return new Promise((async(t,e)=>{if(!this.transformers_||0===this.transformers_.length)return this.report({message:er.errors.transformer_none,variation:"Error"}),void e("[MediaProcessor] Need to set transformers.");if(!this.readable_)return this.report({variation:"Error",message:er.errors.readable_null}),void e("[MediaProcessor] Readable is null.");if(!this.writable_)return this.report({variation:"Error",message:er.errors.writable_null}),void e("[MediaProcessor] Writable is null.");let n=!1;this.pipeline_&&(n=!0,this.pipeline_.clearListeners(),this.pipeline_.destroy()),this.pipeline_=new z2(this.transformers_),this.pipeline_.on("warn",(t=>{this.emit("warn",t)})),this.pipeline_.on("error",(t=>{this.emit("error",t)})),this.pipeline_.on("pipelineInfo",(t=>{n&&("pipeline_started"===t?t=go.pipeline_restarted:"pipeline_started_with_error"===t&&(t=go.pipeline_restarted_with_error)),this.emit("pipelineInfo",t)})),-1!=this.trackExpectedRate_&&this.pipeline_.setTrackExpectedRate(this.trackExpectedRate_),this.pipeline_.start(this.readable_,this.writable_).then((()=>{t()})).catch((t=>{e(t)}))}))}setTransformers(t){return this.report({variation:"Update",message:er.updates.transformer_new}),this.transformers_=t,this.readable_&&this.writable_?this.transformInternal():Promise.resolve()}destroy(){return new Promise((async t=>{this.pipeline_&&this.pipeline_.destroy(),this.report({variation:"Delete"}),t()}))}report(t){this.reporter_.send({version:gi,action:"MediaProcessor",...t})}}class K2{constructor(){this.processor_=null,this.generator_=null}init(t){return new Promise(((e,n)=>{try{this.processor_=new MediaStreamTrackProcessor(t)}catch(t){console.log(`[InsertableStreamHelper] MediaStreamTrackProcessor failed: ${t}`),n(t)}try{"audio"===t.kind?this.generator_=new MediaStreamTrackGenerator({kind:"audio"}):"video"===t.kind?this.generator_=new MediaStreamTrackGenerator({kind:"video"}):n("kind not supported")}catch(t){console.log(`[InsertableStreamHelper] MediaStreamTrackGenerator failed: ${t}`),n(t)}e()}))}getReadable(){return this.processor_.readable}getWriteable(){return this.generator_.writable}getProccesorTrack(){return this.generator_}}class P2{constructor(t){this.insertableStreamHelper_=new K2,this.mediaProcessor_=t}setTrack(t){return new Promise(((e,n)=>{this.insertableStreamHelper_.init(t).then((()=>{this.mediaProcessor_.transform(this.insertableStreamHelper_.getReadable(),this.insertableStreamHelper_.getWriteable()).then((()=>{e(this.insertableStreamHelper_.getProccesorTrack())})).catch((t=>{n(t)}))})).catch((t=>{n(t)}))}))}destroy(){return new Promise(((t,e)=>{this.mediaProcessor_?this.mediaProcessor_.destroy().then((()=>{t()})).catch((t=>{e(t)})):e("no processor")}))}}var Zi=(t=>(t.Low="Low",t.High="High",t))(Zi||{}),O2=(t=>(t.BackgroundBlur="BackgroundBlur",t.VirtualBackground="VirtualBackground",t.VideoBackground="VideoBackground",t.SilhouetteBlur="SilhouetteBlur",t))(O2||{}),Zo=(t=>(t.FAST="FAST",t.PRECISE="PRECISE",t))(Zo||{}),Wi=(t=>(t.CANVAS="CANVAS",t.WEBGL="WEBGL",t))(Wi||{});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 T3(){const{wasm:t,insertableStreams:e,simd:n,webgl:r}=await Q2();if(!t.supported)throw t.message;if(!e.supported)throw e.message;if(!n.supported)throw n.message;if(!r.supported)throw r.message}async function Q2(){const t={wasm:{supported:"object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate,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:D2(),performance:_s()};try{await l2()}catch(e){t.insertableStreams.supported=!1,t.insertableStreams.message=e}return t}function D2(){if(!OffscreenCanvas)return{supported:!1,message:"Your browser does not support offscreen canvas"};const t=new OffscreenCanvas(0,0).getContext("webgl2");if(!t)return{supported:!1,message:"Your browser does not support webgl 2"};{const e=null==t?void 0:t.getExtension("WEBGL_lose_context");e&&e.loseContext()}return{supported:!0}}function _s(){const t=new OffscreenCanvas(0,0).getContext("webgl2",{failIfMajorPerformanceCaveat:!0});if(!t)return{supported:!1,message:"Your hardware does not perform good enough to run the library efficiently"};{const e=null==t?void 0:t.getExtension("WEBGL_lose_context");e&&e.loseContext()}return{supported:!0}}const Vi={};(function(){var t;function e(t){var e=0;return function(){return e<t.length?{done:!1,value:t[e++]}:{done:!0}}}var n="function"==typeof Object.defineProperties?Object.defineProperty:function(t,e,n){return t==Array.prototype||t==Object.prototype||(t[e]=n.value),t};var r=function(t){t=["object"==typeof globalThis&&globalThis,t,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var e=0;e<t.length;++e){var n=t[e];if(n&&n.Math==Math)return n}throw Error("Cannot find global object")}(this);function i(t,e){if(e)t:{var i=r;t=t.split(".");for(var o=0;o<t.length-1;o++){var a=t[o];if(!(a in i))break t;i=i[a]}(e=e(o=i[t=t[t.length-1]]))!=o&&null!=e&&n(i,t,{configurable:!0,writable:!0,value:e})}}function o(t){return(t={next:t})[Symbol.iterator]=function(){return this},t}function a(t){var n=typeof Symbol<"u"&&Symbol.iterator&&t[Symbol.iterator];return n?n.call(t):{next:e(t)}}function l(t){if(!(t instanceof Array)){t=a(t);for(var e,n=[];!(e=t.next()).done;)n.push(e.value);t=n}return t}i("Symbol",(function(t){function e(t,e){this.g=t,n(this,"description",{configurable:!0,writable:!0,value:e})}if(t)return t;e.prototype.toString=function(){return this.g};var r="jscomp_symbol_"+(1e9*Math.random()>>>0)+"_",i=0;return function t(n){if(this instanceof t)throw new TypeError("Symbol is not a constructor");return new e(r+(n||"")+"_"+i++,n)}})),i("Symbol.iterator",(function(t){if(t)return t;t=Symbol("Symbol.iterator");for(var i="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),a=0;a<i.length;a++){var l=r[i[a]];"function"==typeof l&&"function"!=typeof l.prototype[t]&&n(l.prototype,t,{configurable:!0,writable:!0,value:function(){return o(e(this))}})}return t}));var s,c="function"==typeof Object.create?Object.create:function(t){function e(){}return e.prototype=t,new e};if("function"==typeof Object.setPrototypeOf)s=Object.setPrototypeOf;else{var u;t:{var d={};try{d.__proto__={a:!0},u=d.a;break t}catch{}u=!1}s=u?function(t,e){if(t.__proto__=e,t.__proto__!==e)throw new TypeError(t+" is not extensible");return t}:null}var h=s;function f(t,e){if(t.prototype=c(e.prototype),t.prototype.constructor=t,h)h(t,e);else for(var n in e)if("prototype"!=n)if(Object.defineProperties){var r=Object.getOwnPropertyDescriptor(e,n);r&&Object.defineProperty(t,n,r)}else t[n]=e[n];t.ea=e.prototype}function m(){this.l=!1,this.i=null,this.h=void 0,this.g=1,this.s=this.m=0,this.j=null}function p(t){if(t.l)throw new TypeError("Generator is already running");t.l=!0}function b(t,e){t.j={U:e,V:!0},t.g=t.m||t.s}function g(t,e,n){return t.g=n,{value:e}}function y(t){this.g=new m,this.h=t}function Z(t,e,n,r){try{var i=e.call(t.g.i,n);if(!(i instanceof Object))throw new TypeError("Iterator result "+i+" is not an object");if(!i.done)return t.g.l=!1,i;var o=i.value}catch(e){return t.g.i=null,b(t.g,e),v(t)}return t.g.i=null,r.call(t.g,o),v(t)}function v(t){for(;t.g.g;)try{var e=t.h(t.g);if(e)return t.g.l=!1,{value:e.value,done:!1}}catch(e){t.g.h=void 0,b(t.g,e)}if(t.g.l=!1,t.g.j){if(e=t.g.j,t.g.j=null,e.V)throw e.U;return{value:e.return,done:!0}}return{value:void 0,done:!0}}function G(t){this.next=function(e){return p(t.g),t.g.i?e=Z(t,t.g.i.next,e,t.g.o):(t.g.o(e),e=v(t)),e},this.throw=function(e){return p(t.g),t.g.i?e=Z(t,t.g.i.throw,e,t.g.o):(b(t.g,e),e=v(t)),e},this.return=function(e){return function(t,e){p(t.g);var n=t.g.i;return n?Z(t,"return"in n?n.return:function(t){return{value:t,done:!0}},e,t.g.return):(t.g.return(e),v(t))}(t,e)},this[Symbol.iterator]=function(){return this}}function X(t,e){return e=new G(new y(e)),h&&t.prototype&&h(e,t.prototype),e}m.prototype.o=function(t){this.h=t},m.prototype.return=function(t){this.j={return:t},this.g=this.s};var W="function"==typeof Object.assign?Object.assign:function(t,e){for(var n=1;n<arguments.length;n++){var r=arguments[n];if(r)for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t};i("Object.assign",(function(t){return t||W})),i("Promise",(function(t){function e(t){this.h=0,this.i=void 0,this.g=[],this.o=!1;var e=this.j();try{t(e.resolve,e.reject)}catch(t){e.reject(t)}}function n(){this.g=null}function i(t){return t instanceof e?t:new e((function(e){e(t)}))}if(t)return t;n.prototype.h=function(t){if(null==this.g){this.g=[];var e=this;this.i((function(){e.l()}))}this.g.push(t)};var o=r.setTimeout;n.prototype.i=function(t){o(t,0)},n.prototype.l=function(){for(;this.g&&this.g.length;){var t=this.g;this.g=[];for(var e=0;e<t.length;++e){var n=t[e];t[e]=null;try{n()}catch(t){this.j(t)}}}this.g=null},n.prototype.j=function(t){this.i((function(){throw t}))},e.prototype.j=function(){function t(t){return function(r){n||(n=!0,t.call(e,r))}}var e=this,n=!1;return{resolve:t(this.C),reject:t(this.l)}},e.prototype.C=function(t){if(t===this)this.l(new TypeError("A Promise cannot resolve to itself"));else if(t instanceof e)this.F(t);else{t:switch(typeof t){case"object":var n=null!=t;break t;case"function":n=!0;break t;default:n=!1}n?this.u(t):this.m(t)}},e.prototype.u=function(t){var e=void 0;try{e=t.then}catch(t){return void this.l(t)}"function"==typeof e?this.G(e,t):this.m(t)},e.prototype.l=function(t){this.s(2,t)},e.prototype.m=function(t){this.s(1,t)},e.prototype.s=function(t,e){if(0!=this.h)throw Error("Cannot settle("+t+", "+e+"): Promise already settled in state"+this.h);this.h=t,this.i=e,2===this.h&&this.D(),this.A()},e.prototype.D=function(){var t=this;o((function(){if(t.B()){var e=r.console;typeof e<"u"&&e.error(t.i)}}),1)},e.prototype.B=function(){if(this.o)return!1;var t=r.CustomEvent,e=r.Event,n=r.dispatchEvent;return typeof n>"u"||("function"==typeof t?t=new t("unhandledrejection",{cancelable:!0}):"function"==typeof e?t=new e("unhandledrejection",{cancelable:!0}):(t=r.document.createEvent("CustomEvent")).initCustomEvent("unhandledrejection",!1,!0,t),t.promise=this,t.reason=this.i,n(t))},e.prototype.A=function(){if(null!=this.g){for(var t=0;t<this.g.length;++t)l.h(this.g[t]);this.g=null}};var l=new n;return e.prototype.F=function(t){var e=this.j();t.J(e.resolve,e.reject)},e.prototype.G=function(t,e){var n=this.j();try{t.call(e,n.resolve,n.reject)}catch(t){n.reject(t)}},e.prototype.then=function(t,n){function r(t,e){return"function"==typeof t?function(e){try{i(t(e))}catch(t){o(t)}}:e}var i,o,a=new e((function(t,e){i=t,o=e}));return this.J(r(t,i),r(n,o)),a},e.prototype.catch=function(t){return this.then(void 0,t)},e.prototype.J=function(t,e){function n(){switch(r.h){case 1:t(r.i);break;case 2:e(r.i);break;default:throw Error("Unexpected state: "+r.h)}}var r=this;null==this.g?l.h(n):this.g.push(n),this.o=!0},e.resolve=i,e.reject=function(t){return new e((function(e,n){n(t)}))},e.race=function(t){return new e((function(e,n){for(var r=a(t),o=r.next();!o.done;o=r.next())i(o.value).J(e,n)}))},e.all=function(t){var n=a(t),r=n.next();return r.done?i([]):new e((function(t,e){function o(e){return function(n){a[e]=n,0==--l&&t(a)}}var a=[],l=0;do{a.push(void 0),l++,i(r.value).J(o(a.length-1),e),r=n.next()}while(!r.done)}))},e})),i("Object.is",(function(t){return t||function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e}})),i("Array.prototype.includes",(function(t){return t||function(t,e){var n=this;n instanceof String&&(n=String(n));var r=n.length;for(0>(e=e||0)&&(e=Math.max(e+r,0));e<r;e++){var i=n[e];if(i===t||Object.is(i,t))return!0}return!1}})),i("String.prototype.includes",(function(t){return t||function(t,e){if(null==this)throw new TypeError("The 'this' value for String.prototype.includes must not be null or undefined");if(t instanceof RegExp)throw new TypeError("First argument to String.prototype.includes must not be a regular expression");return-1!==this.indexOf(t,e||0)}})),i("Array.prototype.keys",(function(t){return t||function(){return function(t,e){t instanceof String&&(t+="");var n=0,r=!1,i={next:function(){if(!r&&n<t.length){var i=n++;return{value:e(i,t[i]),done:!1}}return r=!0,{done:!0,value:void 0}}};return i[Symbol.iterator]=function(){return i},i}(this,(function(t){return t}))}}));var V=this||self;function R(t,e){t=t.split(".");var n,r=V;t[0]in r||typeof r.execScript>"u"||r.execScript("var "+t[0]);for(;t.length&&(n=t.shift());)t.length||void 0===e?r=r[n]&&r[n]!==Object.prototype[n]?r[n]:r[n]={}:r[n]=e}function x(t,e){return e=String.fromCharCode.apply(null,e),null==t?e:t+e}var I,w,S=typeof TextDecoder<"u",Y=typeof TextEncoder<"u";function F(t){if(Y)t=(w||(w=new TextEncoder)).encode(t);else{var e=void 0;e=void 0!==e&&e;for(var n=0,r=new Uint8Array(3*t.length),i=0;i<t.length;i++){var o=t.charCodeAt(i);if(128>o)r[n++]=o;else{if(2048>o)r[n++]=o>>6|192;else{if(55296<=o&&57343>=o){if(56319>=o&&i<t.length){var a=t.charCodeAt(++i);if(56320<=a&&57343>=a){o=1024*(o-55296)+a-56320+65536,r[n++]=o>>18|240,r[n++]=o>>12&63|128,r[n++]=o>>6&63|128,r[n++]=63&o|128;continue}i--}if(e)throw Error("Found an unpaired surrogate");o=65533}r[n++]=o>>12|224,r[n++]=o>>6&63|128}r[n++]=63&o|128}}t=r.subarray(0,n)}return t}var L={},H=null;function T(t,e){void 0===e&&(e=0),k(),e=L[e];for(var n=Array(Math.floor(t.length/3)),r=e[64]||"",i=0,o=0;i<t.length-2;i+=3){var a=t[i],l=t[i+1],s=t[i+2],c=e[a>>2];a=e[(3&a)<<4|l>>4],l=e[(15&l)<<2|s>>6],s=e[63&s],n[o++]=c+a+l+s}switch(c=0,s=r,t.length-i){case 2:s=e[(15&(c=t[i+1]))<<2]||r;case 1:t=t[i],n[o]=e[t>>2]+e[(3&t)<<4|c>>4]+s+r}return n.join("")}function C(t){var e=t.length,n=3*e/4;n%3?n=Math.floor(n):-1!="=.".indexOf(t[e-1])&&(n=-1!="=.".indexOf(t[e-2])?n-2:n-1);var r=new Uint8Array(n),i=0;return function(t,e){function n(e){for(;r<t.length;){var n=t.charAt(r++),i=H[n];if(null!=i)return i;if(!/^[\s\xa0]*$/.test(n))throw Error("Unknown base64 encoding at char: "+n)}return e}k();for(var r=0;;){var i=n(-1),o=n(0),a=n(64),l=n(64);if(64===l&&-1===i)break;e(i<<2|o>>4),64!=a&&(e(o<<4&240|a>>2),64!=l&&e(a<<6&192|l))}}(t,(function(t){r[i++]=t})),r.subarray(0,i)}function k(){if(!H){H={};for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"],n=0;5>n;n++){var r=t.concat(e[n].split(""));L[n]=r;for(var i=0;i<r.length;i++){var o=r[i];void 0===H[o]&&(H[o]=i)}}}}var N,J="function"==typeof Uint8Array.prototype.slice;function U(t,e,n){return e===n?N||(N=new Uint8Array(0)):J?t.slice(e,n):new Uint8Array(t.subarray(e,n))}var z=0;function M(t,e){e=void 0!==(e=void 0===e?{}:e).v&&e.v,this.h=null,this.g=this.i=this.j=0,this.l=!1,this.v=e,t&&j(this,t)}function j(t,e){e=e.constructor===Uint8Array?e:e.constructor===ArrayBuffer||e.constructor===Array?new Uint8Array(e):e.constructor===String?C(e):e instanceof Uint8Array?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(0),t.h=e,t.j=0,t.i=t.h.length,t.g=t.j}function E(t){var e=t.h,n=e[t.g],r=127&n;return 128>n?(t.g+=1,r):(r|=(127&(n=e[t.g+1]))<<7,128>n?(t.g+=2,r):(r|=(127&(n=e[t.g+2]))<<14,128>n?(t.g+=3,r):(r|=(127&(n=e[t.g+3]))<<21,128>n?(t.g+=4,r):(r|=(15&(n=e[t.g+4]))<<28,128>n?(t.g+=5,r>>>0):(t.g+=5,128<=e[t.g++]&&128<=e[t.g++]&&128<=e[t.g++]&&128<=e[t.g++]&&t.g++,r)))))}function B(t){var e=t.h[t.g],n=t.h[t.g+1],r=t.h[t.g+2],i=t.h[t.g+3];return t.g+=4,t=2*((n=(e<<0|n<<8|r<<16|i<<24)>>>0)>>31)+1,e=n>>>23&255,n&=8388607,255==e?n?NaN:1/0*t:0==e?t*Math.pow(2,-149)*n:t*Math.pow(2,e-150)*(n+Math.pow(2,23))}M.prototype.reset=function(){this.g=this.j};var A=[];function K(){this.g=new Uint8Array(64),this.h=0}function O(t,e){for(;127<e;)t.push(127&e|128),e>>>=7;t.push(e)}function P(t){var e={},n=void 0!==e.N&&e.N;this.o={v:void 0!==e.v&&e.v},this.N=n,e=this.o,A.length?(n=A.pop(),e&&(n.v=e.v),t&&j(n,t),t=n):t=new M(t,e),this.g=t,this.m=this.g.g,this.h=this.i=this.l=-1,this.j=!1}function Q(t){var e=t.g;if((e=e.g==e.i)||(e=t.j)||(e=(e=t.g).l||0>e.g||e.g>e.i),e)return!1;t.m=t.g.g;var n=7&(e=E(t.g));return 0!=n&&5!=n&&1!=n&&2!=n&&3!=n&&4!=n?(t.j=!0,!1):(t.i=e,t.l=e>>>3,t.h=n,!0)}function _(t){switch(t.h){case 0:if(0!=t.h)_(t);else{for(t=t.g;128&t.h[t.g];)t.g++;t.g++}break;case 1:1!=t.h?_(t):(t=t.g).g+=8;break;case 2:if(2!=t.h)_(t);else{var e=E(t.g);(t=t.g).g+=e}break;case 5:5!=t.h?_(t):(t=t.g).g+=4;break;case 3:for(e=t.l;;){if(!Q(t)){t.j=!0;break}if(4==t.h){t.l!=e&&(t.j=!0);break}_(t)}break;default:t.j=!0}}function D(t,e,n){var r=t.g.i,i=E(t.g);return i=t.g.g+i,t.g.i=i,n(e,t),t.g.g=i,t.g.i=r,e}function $(t){var e,n=E(t.g),r=(t=t.g).g;if(t.g+=n,t=t.h,S)(e=I)||(e=I=new TextDecoder("utf-8",{fatal:!1})),e=e.decode(t.subarray(r,r+n));else{n=r+n;for(var i,o,a,l=[],s=null;r<n;)128>(i=t[r++])?l.push(i):224>i?r>=n?l.push(65533):(o=t[r++],194>i||128!=(192&o)?(r--,l.push(65533)):l.push((31&i)<<6|63&o)):240>i?r>=n-1?l.push(65533):128!=(192&(o=t[r++]))||224===i&&160>o||237===i&&160<=o||128!=(192&(e=t[r++]))?(r--,l.push(65533)):l.push((15&i)<<12|(63&o)<<6|63&e):244>=i?r>=n-2?l.push(65533):128!=(192&(o=t[r++]))||o-144+(i<<28)>>30||128!=(192&(e=t[r++]))||128!=(192&(a=t[r++]))?(r--,l.push(65533)):(i=(7&i)<<18|(63&o)<<12|(63&e)<<6|63&a,i-=65536,l.push(55296+(i>>10&1023),56320+(1023&i))):l.push(65533),8192<=l.length&&(s=x(s,l),l.length=0);e=x(s,l)}return e}function q(){this.h=[],this.i=0,this.g=new K}function tt(t,e){0!==e.length&&(t.h.push(e),t.i+=e.length)}function et(t){var e=t.i+t.g.length();if(0===e)return new Uint8Array(0);e=new Uint8Array(e);for(var n=t.h,r=n.length,i=0,o=0;o<r;o++){var a=n[o];0!==a.length&&(e.set(a,i),i+=a.length)}return 0!==(r=(n=t.g).h)&&(e.set(n.g.subarray(0,r),i),n.h=0),t.h=[e],e}function nt(t,e,n){if(null!=n){O(t.g,8*e+5),t=t.g;var r=n;0===(r=(n=0>r?1:0)?-r:r)?0<1/r?z=0:(0,z=2147483648):isNaN(r)?(0,z=2147483647):34028234663852886e22<r?(0,z=(n<<31|2139095040)>>>0):11754943508222875e-54>r?(r=Math.round(r/Math.pow(2,-149)),0,z=(n<<31|r)>>>0):(e=Math.floor(Math.log(r)/Math.LN2),r*=Math.pow(2,-e),r=8388607&Math.round(8388608*r),0,z=(n<<31|e+127<<23|r)>>>0),n=z,t.push(n>>>0&255),t.push(n>>>8&255),t.push(n>>>16&255),t.push(n>>>24&255)}}K.prototype.push=function(t){if(!(this.h+1<this.g.length)){var e=this.g;this.g=new Uint8Array(Math.ceil(1+2*this.g.length)),this.g.set(e)}this.g[this.h++]=t},K.prototype.length=function(){return this.h},K.prototype.end=function(){var t=this.g,e=this.h;return this.h=0,U(t,0,e)},P.prototype.reset=function(){this.g.reset(),this.h=this.l=-1};var rt="function"==typeof Uint8Array;function it(t,e,n){if(null!=t)return"object"==typeof t?rt&&t instanceof Uint8Array?n(t):ot(t,e,n):e(t)}function ot(t,e,n){if(Array.isArray(t)){for(var r=Array(t.length),i=0;i<t.length;i++)r[i]=it(t[i],e,n);return Array.isArray(t)&&t.W&&ct(r),r}for(i in r={},t)r[i]=it(t[i],e,n);return r}function at(t){return"number"==typeof t?isFinite(t)?t:String(t):t}var lt,st={W:{value:!0,configurable:!0}};function ct(t){return Array.isArray(t)&&!Object.isFrozen(t)&&Object.defineProperties(t,st),t}function ut(t,e,n){var r=lt;if(lt=null,t||(t=r),r=this.constructor.ca,t||(t=r?[r]:[]),this.j=r?0:-1,this.i=null,this.g=t,t=(r=this.g.length)-1,r&&null!==(r=this.g[t])&&"object"==typeof r&&r.constructor===Object?(this.l=t-this.j,this.h=r):void 0!==e&&-1<e?(this.l=Math.max(e,t+1-this.j),this.h=null):this.l=Number.MAX_VALUE,n)for(e=0;e<n.length;e++)(t=n[e])<this.l?(t+=this.j,(r=this.g[t])?ct(r):this.g[t]=dt):(ht(this),(r=this.h[t])?ct(r):this.h[t]=dt)}var dt=Object.freeze(ct([]));function ht(t){var e=t.l+t.j;t.g[e]||(t.h=t.g[e]={})}function ft(t,e,n){return-1===e?null:void 0!==n&&n||e>=t.l?t.h?t.h[e]:void 0:t.g[e+t.j]}function mt(t){var e=void 0!==e&&e,n=ft(t,1,e);return null==n&&(n=dt),n===dt&&bt(t,1,n=ct([]),e),n}function pt(t,e,n){return(t=null==(t=ft(t,e))?t:+t)??(void 0===n?0:n)}function bt(t,e,n,r){void 0!==r&&r||e>=t.l?(ht(t),t.h[e]=n):t.g[e+t.j]=n}function gt(t,e){t.i||(t.i={});var n=t.i[1];if(!n){var r=mt(t);n=[];for(var i=0;i<r.length;i++)n[i]=new e(r[i]);t.i[1]=n}return n}function yt(t,e,n,r){var i=gt(t,n);e=e||new n,t=mt(t),null!=r?(i.splice(r,0,e),t.splice(r,0,Zt(e))):(i.push(e),t.push(Zt(e)))}function Zt(t,e){if(t.i)for(var n in t.i){var r=t.i[n];if(Array.isArray(r))for(var i=0;i<r.length;i++)r[i]&&Zt(r[i]);else r&&Zt(r)}return t.g}function vt(t,e){return(t=ft(t,e))??0}function Gt(t,e){return(t=ft(t,e))??""}function Xt(t,e){if(t=t.m){tt(e,e.g.end());for(var n=0;n<t.length;n++)tt(e,t[n])}}function Wt(t,e){if(4==e.h)return!1;var n=e.m;return _(e),e.N||(e=U(e.g.h,n,e.g.g),(n=t.m)?n.push(e):t.m=[e]),!0}function Vt(t,e){var n=void 0;return new(n||(n=Promise))((function(r,i){function o(t){try{l(e.next(t))}catch(t){i(t)}}function a(t){try{l(e.throw(t))}catch(t){i(t)}}function l(t){t.done?r(t.value):new n((function(e){e(t.value)})).then(o,a)}l((e=e.apply(t,void 0)).next())}))}function Rt(t){ut.call(this,t)}function xt(t,e){for(;Q(e);)switch(e.i){case 8:var n=E(e.g);bt(t,1,n);break;case 21:bt(t,2,n=B(e.g));break;case 26:bt(t,3,n=$(e));break;case 34:bt(t,4,n=$(e));break;default:if(!Wt(t,e))return t}return t}function It(t){ut.call(this,t,-1,wt)}ut.prototype.toJSON=function(){return ot(Zt(this),at,T)},ut.prototype.toString=function(){return Zt(this).toString()},f(Rt,ut),f(It,ut),It.prototype.addClassification=function(t,e){yt(this,t,Rt,e)};var wt=[1];function St(t){ut.call(this,t)}function Yt(t,e){for(;Q(e);)switch(e.i){case 13:var n=B(e.g);bt(t,1,n);break;case 21:bt(t,2,n=B(e.g));break;case 29:bt(t,3,n=B(e.g));break;case 37:bt(t,4,n=B(e.g));break;case 45:bt(t,5,n=B(e.g));break;default:if(!Wt(t,e))return t}return t}function Ft(t){ut.call(this,t,-1,Lt)}f(St,ut),f(Ft,ut);var Lt=[1];function Ht(t){ut.call(this,t)}function Tt(t,e,n){if(n=t.createShader(0===n?t.VERTEX_SHADER:t.FRAGMENT_SHADER),t.shaderSource(n,e),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw Error("Could not compile WebGL shader.\n\n"+t.getShaderInfoLog(n));return n}function Ct(t){return gt(t,Rt).map((function(t){return{index:vt(t,1),Y:pt(t,2),label:null!=ft(t,3)?Gt(t,3):void 0,displayName:null!=ft(t,4)?Gt(t,4):void 0}}))}function kt(t){return{x:pt(t,1),y:pt(t,2),z:pt(t,3),visibility:null!=ft(t,4)?pt(t,4):void 0}}function Nt(t,e){this.h=t,this.g=e,this.l=0}function Jt(t,e,n){return function(t,e){var n=t.g;if(void 0===t.m){var r=Tt(n,"\n attribute vec2 aVertex;\n attribute vec2 aTex;\n varying vec2 vTex;\n void main(void) {\n gl_Position = vec4(aVertex, 0.0, 1.0);\n vTex = aTex;\n }",0),i=Tt(n,"\n precision mediump float;\n varying vec2 vTex;\n uniform sampler2D sampler0;\n void main(){\n gl_FragColor = texture2D(sampler0, vTex);\n }",1),o=n.createProgram();if(n.attachShader(o,r),n.attachShader(o,i),n.linkProgram(o),!n.getProgramParameter(o,n.LINK_STATUS))throw Error("Could not compile WebGL program.\n\n"+n.getProgramInfoLog(o));r=t.m=o,n.useProgram(r),i=n.getUniformLocation(r,"sampler0"),t.j={I:n.getAttribLocation(r,"aVertex"),H:n.getAttribLocation(r,"aTex"),da:i},t.s=n.createBuffer(),n.bindBuffer(n.ARRAY_BUFFER,t.s),n.enableVertexAttribArray(t.j.I),n.vertexAttribPointer(t.j.I,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,1,1,-1]),n.STATIC_DRAW),n.bindBuffer(n.ARRAY_BUFFER,null),t.o=n.createBuffer(),n.bindBuffer(n.ARRAY_BUFFER,t.o),n.enableVertexAttribArray(t.j.H),n.vertexAttribPointer(t.j.H,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,1,0,0,1,0,1,1]),n.STATIC_DRAW),n.bindBuffer(n.ARRAY_BUFFER,null),n.uniform1i(i,0)}r=t.j,n.useProgram(t.m),n.canvas.width=e.width,n.canvas.height=e.height,n.viewport(0,0,e.width,e.height),n.activeTexture(n.TEXTURE0),t.h.bindTexture2d(e.glName),n.enableVertexAttribArray(r.I),n.bindBuffer(n.ARRAY_BUFFER,t.s),n.vertexAttribPointer(r.I,2,n.FLOAT,!1,0,0),n.enableVertexAttribArray(r.H),n.bindBuffer(n.ARRAY_BUFFER,t.o),n.vertexAttribPointer(r.H,2,n.FLOAT,!1,0,0),n.bindFramebuffer(n.DRAW_FRAMEBUFFER?n.DRAW_FRAMEBUFFER:n.FRAMEBUFFER,null),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.colorMask(!0,!0,!0,!0),n.drawArrays(n.TRIANGLE_FAN,0,4),n.disableVertexAttribArray(r.I),n.disableVertexAttribArray(r.H),n.bindBuffer(n.ARRAY_BUFFER,null),t.h.bindTexture2d(0)}(t,e),"function"==typeof t.g.canvas.transferToImageBitmap?Promise.resolve(t.g.canvas.transferToImageBitmap()):n?Promise.resolve(t.g.canvas):"function"==typeof createImageBitmap?createImageBitmap(t.g.canvas):(void 0===t.i&&(t.i=document.createElement("canvas")),new Promise((function(e){t.i.height=t.g.canvas.height,t.i.width=t.g.canvas.width,t.i.getContext("2d",{}).drawImage(t.g.canvas,0,0,t.g.canvas.width,t.g.canvas.height),e(t.i)})))}function Ut(t){this.g=t}f(Ht,ut);var zt=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 Mt(t,e){return e+t}function jt(t,e){window[t]=e}function Et(t){if(this.g=t,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=t&&t.locateFile||Mt,"object"==typeof window)var e=window.location.pathname.toString().substring(0,window.location.pathname.toString().lastIndexOf("/"))+"/";else{if(!(typeof location<"u"))throw Error("solutions can only be loaded on a web page or in a web worker");e=location.pathname.toString().substring(0,location.pathname.toString().lastIndexOf("/"))+"/"}if(this.S=e,t.options)for(var n=(e=a(Object.keys(t.options))).next();!n.done;n=e.next()){n=n.value;var r=t.options[n].default;void 0!==r&&(this.j[n]="function"==typeof r?r():r)}}function Bt(t){return Vt(t,(function t(){var e,n,r,i,o,a,s,c,u,d,h,f=this;return X(t,(function(t){switch(t.g){case 1:return e=f,f.R?(n=function(t,e){return void 0===t.g.files?[]:"function"==typeof t.g.files?t.g.files(e):t.g.files}(f,f.j),g(t,function(){return Vt(this,(function t(){return X(t,(function(t){switch(t.g){case 1:return t.m=2,g(t,WebAssembly.instantiate(zt),4);case 4:t.g=3,t.m=0;break;case 2:return t.m=0,t.j=null,t.return(!1);case 3:return t.return(!0)}}))}))}(),2)):t.return();case 2:if(r=t.h,"object"==typeof window)return jt("createMediapipeSolutionsWasm",{locateFile:f.locateFile}),jt("createMediapipeSolutionsPackedAssets",{locateFile:f.locateFile}),a=n.filter((function(t){return void 0!==t.data})),s=n.filter((function(t){return void 0===t.data})),c=Promise.all(a.map((function(t){var n=At(e,t.url);if(void 0!==t.path){var r=t.path;n=n.then((function(t){return e.overrideFile(r,t),Promise.resolve(t)}))}return n}))),u=Promise.all(s.map((function(t){return void 0===t.simd||t.simd&&r||!t.simd&&!r?function(t){var e=document.createElement("script");return e.setAttribute("src",t),e.setAttribute("crossorigin","anonymous"),new Promise((function(t){e.addEventListener("load",(function(){t()}),!1),e.addEventListener("error",(function(){t()}),!1),document.body.appendChild(e)}))}(e.locateFile(t.url,e.S)):Promise.resolve()}))).then((function(){return Vt(e,(function t(){var e,n,r=this;return X(t,(function(t){if(1==t.g)return e=window.createMediapipeSolutionsWasm,n=window.createMediapipeSolutionsPackedAssets,g(t,e(n),2);r.h=t.h,t.g=0}))}))})),d=Vt(e,(function t(){var e=this;return X(t,(function(t){return e.g.graph&&e.g.graph.url?t=g(t,At(e,e.g.graph.url),0):(t.g=0,t=void 0),t}))})),g(t,Promise.all([u,c,d]),7);if("function"!=typeof importScripts)throw Error("solutions can only be loaded on a web page or in a web worker");return i=n.filter((function(t){return void 0===t.simd||t.simd&&r||!t.simd&&!r})).map((function(t){return e.locateFile(t.url,e.S)})),importScripts.apply(null,l(i)),g(t,createMediapipeSolutionsWasm(Module),6);case 6:f.h=t.h,f.l=new OffscreenCanvas(1,1),f.h.canvas=f.l,o=f.h.GL.createContext(f.l,{antialias:!1,alpha:!1,ba:typeof WebGL2RenderingContext<"u"?2:1}),f.h.GL.makeContextCurrent(o),t.g=4;break;case 7:if(f.l=document.createElement("canvas"),!(h=f.l.getContext("webgl2",{}))&&!(h=f.l.getContext("webgl",{})))return alert("Failed to create WebGL canvas context when passing video frame."),t.return();f.D=h,f.h.canvas=f.l,f.h.createContext(f.l,!0,!0,{});case 4:f.i=new f.h.SolutionWasm,f.R=!1,t.g=0}}))}))}function At(t,e){return Vt(t,(function t(){var n,r,i=this;return X(t,(function(t){return e in i.F?t.return(i.F[e]):(n=i.locateFile(e,""),r=fetch(n).then((function(t){return t.arrayBuffer()})),i.F[e]=r,t.return(r))}))}))}function Kt(t,e,n){return Vt(t,(function t(){var r,i,o,l,s,c,u,d,h,f,m,p,b,y,Z=this;return X(t,(function(t){switch(t.g){case 1:if(!n)return t.return(e);for(r={},i=0,o=a(Object.keys(n)),l=o.next();!l.done;l=o.next())s=l.value,"string"!=typeof(c=n[s])&&"texture"===c.type&&void 0!==e[c.stream]&&++i;1<i&&(Z.G=!1),u=a(Object.keys(n)),l=u.next();case 2:if(l.done){t.g=4;break}if(d=l.value,"string"==typeof(h=n[d]))return b=r,y=d,g(t,function(t,e,n){return Vt(t,(function t(){var r,i=this;return X(t,(function(t){return"number"==typeof n||n instanceof Uint8Array||n instanceof i.h.Uint8BlobList?t.return(n):n instanceof i.h.Texture2dDataOut?((r=i.s[e])||(r=new Nt(i.h,i.D),i.s[e]=r),t.return(Jt(r,n,i.G))):t.return(void 0)}))}))}(Z,d,e[h]),14);if(f=e[h.stream],"detection_list"===h.type){if(f){for(var v=f.getRectList(),G=f.getLandmarksList(),W=f.getClassificationsList(),V=[],R=0;R<v.size();++R){var x=v.get(R);t:{var I=new Ht;for(x=new P(x);Q(x);)switch(x.i){case 13:var w=B(x.g);bt(I,1,w);break;case 21:bt(I,2,w=B(x.g));break;case 29:bt(I,3,w=B(x.g));break;case 37:bt(I,4,w=B(x.g));break;case 45:bt(I,5,w=B(x.g));break;case 48:for(var S=x.g,Y=128,F=0,L=w=0;4>L&&128<=Y;L++)F|=(127&(Y=S.h[S.g++]))<<7*L;if(128<=Y&&(F|=(127&(Y=S.h[S.g++]))<<28,w|=(127&Y)>>4),128<=Y)for(L=0;5>L&&128<=Y;L++)w|=(127&(Y=S.h[S.g++]))<<7*L+3;128>Y?(S=F>>>0,(w=2147483648&(Y=w>>>0))&&(Y=~Y>>>0,0==(S=1+~S>>>0)&&(Y=Y+1>>>0)),S=4294967296*Y+(S>>>0),w=w?-S:S):(S.l=!0,w=void 0),bt(I,6,w);break;default:if(!Wt(I,x))break t}}I={Z:pt(I,1),$:pt(I,2),height:pt(I,3),width:pt(I,4),rotation:pt(I,5,0),X:vt(I,6)},w=G.get(R);t:for(x=new Ft,w=new P(w);Q(w);)if(10===w.i)yt(x,S=D(w,new St,Yt),St,void 0);else if(!Wt(x,w))break t;x=gt(x,St).map(kt),S=W.get(R);t:for(w=new It,S=new P(S);Q(S);)if(10===S.i)w.addClassification(D(S,new Rt,xt));else if(!Wt(w,S))break t;I={T:I,O:x,M:Ct(w)},V.push(I)}v=V}else v=[];r[d]=v,t.g=7;break}if("proto_list"===h.type){if(f){for(v=Array(f.size()),G=0;G<f.size();G++)v[G]=f.get(G);f.delete()}else v=[];r[d]=v,t.g=7;break}if(void 0===f){t.g=3;break}if("float_list"===h.type){r[d]=f,t.g=7;break}if("proto"===h.type){r[d]=f,t.g=7;break}if("texture"!==h.type)throw Error("Unknown output config type: '"+h.type+"'");return(m=Z.s[d])||(m=new Nt(Z.h,Z.D),Z.s[d]=m),g(t,Jt(m,f,Z.G),13);case 13:p=t.h,r[d]=p;case 7:h.transform&&r[d]&&(r[d]=h.transform(r[d])),t.g=3;break;case 14:b[y]=t.h;case 3:l=u.next(),t.g=2;break;case 4:return t.return(r)}}))}))}function Ot(t,e){for(var n=e.name||"$",r=[].concat(l(e.wants)),i=new t.h.StringList,o=a(e.wants),s=o.next();!s.done;s=o.next())i.push_back(s.value);o=t.h.PacketListener.implement({onResults:function(i){for(var o={},a=0;a<e.wants.length;++a)o[r[a]]=i.get(a);var l=t.listeners[n];l&&(t.C=Kt(t,o,e.outs).then((function(n){n=l(n);for(var i=0;i<e.wants.length;++i){var a=o[r[i]];"object"==typeof a&&a.hasOwnProperty&&a.hasOwnProperty("delete")&&a.delete()}n&&(t.C=n)})))}}),t.i.attachMultiListener(i,o),i.delete()}function Pt(t){return 1===(void 0===t&&(t=0),t)?"selfie_segmentation_landscape.tflite":"selfie_segmentation.tflite"}function Qt(t){var e=this;t=t||{},this.g=new Et({locateFile:t.locateFile,files:function(t){return[{simd:!0,url:"selfie_segmentation_solution_simd_wasm_bin.js"},{simd:!1,url:"selfie_segmentation_solution_wasm_bin.js"},{data:!0,url:Pt(t.modelSelection)}]},graph:{url:"selfie_segmentation.binarypb"},listeners:[{wants:["segmentation_mask","image_transformed"],outs:{image:{type:"texture",stream:"image_transformed"},segmentationMask:{type:"texture",stream:"segmentation_mask"}}}],inputs:{image:{type:"video",stream:"input_frames_gpu"}},options:{useCpuInference:{type:0,graphOptionXref:{calculatorType:"InferenceCalculator",fieldName:"use_cpu_inference"},default:"iPad Simulator;iPhone Simulator;iPod Simulator;iPad;iPhone;iPod".split(";").includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document},selfieMode:{type:0,graphOptionXref:{calculatorType:"GlScalerCalculator",calculatorIndex:1,fieldName:"flip_horizontal"}},modelSelection:{type:1,graphOptionXref:{calculatorType:"ConstantSidePacketCalculator",calculatorName:"ConstantSidePacketCalculatorModelSelection",fieldName:"int_value"},onChange:function(t){return Vt(e,(function e(){var n,r,i,o=this;return X(e,(function(e){return 1==e.g?(n=Pt(t),r="third_party/mediapipe/modules/selfie_segmentation/"+n,g(e,At(o.g,n),2)):(i=e.h,o.g.overrideFile(r,i),e.return(!0))}))}))}}}})}(t=Et.prototype).close=function(){return this.i&&this.i.delete(),Promise.resolve()},t.reset=function(){return Vt(this,(function t(){var e=this;return X(t,(function(t){e.i&&(e.i.reset(),e.m={},e.s={}),t.g=0}))}))},t.setOptions=function(t,e){var n=this;if(e=e||this.g.options){for(var r=[],i=[],o={},l=a(Object.keys(t)),s=l.next();!s.done;o={K:o.K,L:o.L},s=l.next()){var c=s.value;c in this.j&&this.j[c]===t[c]||(this.j[c]=t[c],void 0!==(s=e[c])&&(s.onChange&&(o.K=s.onChange,o.L=t[c],r.push(function(t){return function(){return Vt(n,(function e(){var n=this;return X(e,(function(e){if(1==e.g)return g(e,t.K(t.L),2);!0===e.h&&(n.o=!0),e.g=0}))}))}}(o))),s.graphOptionXref&&(c={valueNumber:1===s.type?t[c]:0,valueBoolean:0===s.type&&t[c],valueString:2===s.type?t[c]:""},s=Object.assign(Object.assign(Object.assign({},{calculatorName:"",calculatorIndex:0}),s.graphOptionXref),c),i.push(s))))}(0!==r.length||0!==i.length)&&(this.o=!0,this.A=(void