@omnimedia/omnitool
Version:
open source video processing tools
7 lines • 873 kB
JavaScript
var mT=Object.defineProperty;var Eo=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(r,t)=>(typeof require<"u"?require:r)[t]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var cf=(e,r)=>{for(var t in r)mT(e,t,{get:r[t],enumerable:!0})};var Ds=Object.freeze({eq(e,r){if(e.length!==r.length)return!1;for(let t=0;t<=e.length;t++)if(e.at(t)!==r.at(t))return!1;return!0},random(e){return crypto.getRandomValues(new Uint8Array(e))}});var ko=Object.freeze({fromBytes(e){return[...e].map(r=>r.toString(16).padStart(2,"0")).join("")},toBytes(e){if(e.length%2!==0)throw new Error("must have even number of hex characters");let r=new Uint8Array(e.length/2);for(let t=0;t<e.length;t+=2)r[t/2]=parseInt(e.slice(t,t+2),16);return r},random(e=32){return this.fromBytes(Ds.random(e))},string(e){return ko.fromBytes(e)},bytes(e){return ko.toBytes(e)}});var vc=58,_i="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",yc=Object.freeze({fromBytes(e){let r=BigInt("0x"+ko.fromBytes(e)),t="";for(;r>0;){let s=r%BigInt(vc);r=r/BigInt(vc),t=_i[Number(s)]+t}for(let s of e)if(s===0)t=_i[0]+t;else break;return t},toBytes(e){let r=BigInt(0);for(let n of e){let i=_i.indexOf(n);if(i===-1)throw new Error(`Invalid character '${n}' in base58 string`);r=r*BigInt(vc)+BigInt(i)}let t=r.toString(16);t.length%2!==0&&(t="0"+t);let s=ko.toBytes(t),o=0;for(let n of e)if(n===_i[0])o++;else break;let a=new Uint8Array(o+s.length);return a.set(s,o),a},random(e=32){return this.fromBytes(Ds.random(e))},string(e){return yc.fromBytes(e)},bytes(e){return yc.toBytes(e)}});var df=class{lexicon;static lexicons=Object.freeze({base2:{characters:"01"},hex:{characters:"0123456789abcdef"},base36:{characters:"0123456789abcdefghijklmnopqrstuvwxyz"},base58:{characters:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"},base62:{characters:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"},base64url:{negativePrefix:"~",characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"},base64:{characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",padding:{character:"=",size:4}}});lookup;negativePrefix;constructor(r){this.lexicon=r,this.lookup=Object.fromEntries([...r.characters].map((t,s)=>[t,s])),this.negativePrefix=r.negativePrefix??"-"}toBytes(r){let t=Math.log2(this.lexicon.characters.length);if(Number.isInteger(t)){let i=0,l=0,c=[];for(let _ of r){if(_===this.lexicon.padding?.character)continue;let u=this.lookup[_];if(u===void 0)throw new Error(`Invalid character: ${_}`);for(i=i<<t|u,l+=t;l>=8;)l-=8,c.push(i>>l&255)}return new Uint8Array(c)}let s=0n,o=BigInt(this.lexicon.characters.length),a=!1;r.startsWith(this.negativePrefix)&&(r=r.slice(this.negativePrefix.length),a=!0);for(let i of r){let l=this.lookup[i];if(l===void 0)throw new Error(`Invalid character: ${i}`);s=s*o+BigInt(l)}let n=[];for(;s>0n;)n.unshift(Number(s%256n)),s=s/256n;return new Uint8Array(n)}fromBytes(r){let t=Math.log2(this.lexicon.characters.length);if(Number.isInteger(t)){let n=0,i=0,l="";for(let c of r)for(n=n<<8|c,i+=8;i>=t;){i-=t;let _=n>>i&(1<<t)-1;l+=this.lexicon.characters[_]}if(i>0){let c=n<<t-i&(1<<t)-1;l+=this.lexicon.characters[c]}if(this.lexicon.padding)for(;l.length%this.lexicon.padding.size!==0;)l+=this.lexicon.padding.character;return l}let s=0n;for(let n of r)s=(s<<8n)+BigInt(n);if(s===0n)return this.lexicon.characters[0];let o=BigInt(this.lexicon.characters.length),a="";for(;s>0n;)a=this.lexicon.characters[Number(s%o)]+a,s=s/o;return a}toInteger(r){if(!r)return 0;let t=0n,s=!1,o=BigInt(this.lexicon.characters.length);r.startsWith(this.negativePrefix)&&(r=r.slice(this.negativePrefix.length),s=!0);for(let a of r){let n=this.lookup[a];if(n===void 0)throw new Error(`Invalid character: ${a}`);t=t*o+BigInt(n)}return Number(s?-t:t)}fromInteger(r){r=Math.floor(r);let t=r<0,s=BigInt(t?-r:r);if(s===0n)return this.lexicon.characters[0];let o=BigInt(this.lexicon.characters.length),a="";for(;s>0n;)a=this.lexicon.characters[Number(s%o)]+a,s=s/o;return t?`${this.negativePrefix}${a}`:a}random(r=32){return this.fromBytes(Ds.random(r))}};var Tc=Object.freeze({fromBytes(e){return typeof btoa=="function"?btoa(String.fromCharCode(...e)):Buffer.from(e).toString("base64")},toBytes(e){return typeof atob=="function"?Uint8Array.from(atob(e),r=>r.charCodeAt(0)):Uint8Array.from(Buffer.from(e,"base64"))},random(e=32){return this.fromBytes(Ds.random(e))},string(e){return Tc.fromBytes(e)},bytes(e){return Tc.toBytes(e)}});var uf=Object.freeze({fromBytes(e){return new TextDecoder().decode(e)},toBytes(e){return new TextEncoder().encode(e)},string(e){return uf.fromBytes(e)},bytes(e){return uf.toBytes(e)}});var pi=Object.freeze({set:e=>e!=null,unset:e=>e==null,boolean:e=>typeof e=="boolean",number:e=>typeof e=="number",string:e=>typeof e=="string",bigint:e=>typeof e=="bigint",object:e=>typeof e=="object"&&e!==null,array:e=>Array.isArray(e),fn:e=>typeof e=="function",symbol:e=>typeof e=="symbol"});var Ha=class extends Error{milliseconds;name=this.constructor.name;constructor(r){super(`deadline exceeded (${(r/1e3).toFixed(1)} seconds)`),this.milliseconds=r}};function mi(e,r){return e<=0||e===1/0?r():new Promise((t,s)=>{let o=setTimeout(()=>s(new Ha(e)),e);r().then(t).catch(s).finally(()=>clearTimeout(o))})}function es(){let e,r,t=new Promise((o,a)=>{e=o,r=a});function s(o){return o.then(e).catch(r),t}return{promise:t,resolve:e,reject:r,entangle:s}}function _f(e,r){let t=e;for(let s of r)if(t=t[s],pi.unset(t))break;return t}function hT(e){return{map:r=>pf(e,r),filter:r=>mf(e,r)}}hT.pipe=Object.freeze({map:e=>r=>pf(r,e),filter:e=>r=>mf(r,e)});var pf=(e,r)=>Object.fromEntries(Object.entries(e).map(([t,s])=>[t,r(s,t)])),mf=(e,r)=>Object.fromEntries(Object.entries(e).filter(([t,s])=>r(s,t)));function hf(e){let r=!1,t;return(...s)=>(r||(r=!0,t=e(...s)),t)}function fT(){let e=new Set;function r(a){return e.add(a),()=>{e.delete(a)}}async function t(...a){await Promise.all([...e].map(n=>n(...a)))}async function s(){let{promise:a,resolve:n}=es(),i=r((...l)=>{n(l),i()});return a}function o(){e.clear()}return r.pub=t,r.sub=r,r.on=r,r.next=s,r.clear=o,t.pub=t,t.sub=r,t.on=r,t.next=s,t.clear=o,[t,r]}function hi(e){let r=fT()[0];return e&&r.sub(e),r}var Vs=class{#e=[];add(...r){return this.#e.push(...r),this}disposable(r){return this.bag(r,()=>r.dispose())}bag(r,t){return this.add(()=>t(r)),r}dispose(){for(let r of this.#e.reverse())r();this.#e=[]}};function Pc(e,r){return{error:t=>e.error({...r,...t}),rpcRequest:t=>e.rpcRequest({...r,...t}),rpcError:t=>e.rpcError({...r,...t})}}var fi=()=>e=>({plain:e.none,errMessage:e.mix(e.brightRed,e.bold),errName:e.red,errStack:e.mix(e.red,e.dim),timestamp:e.blue,timestampErr:e.red});function ff(){return fi()}var oo=Object.freeze({black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",brightBlack:"\x1B[90m",brightRed:"\x1B[91m",brightGreen:"\x1B[92m",brightYellow:"\x1B[93m",brightBlue:"\x1B[94m",brightMagenta:"\x1B[95m",brightCyan:"\x1B[96m",brightWhite:"\x1B[97m",bgBlack:"\x1B[40m",bgRed:"\x1B[41m",bgGreen:"\x1B[42m",bgYellow:"\x1B[43m",bgBlue:"\x1B[44m",bgMagenta:"\x1B[45m",bgCyan:"\x1B[46m",bgWhite:"\x1B[47m",bgBrightBlack:"\x1B[100m",bgBrightRed:"\x1B[101m",bgBrightGreen:"\x1B[102m",bgBrightYellow:"\x1B[103m",bgBrightBlue:"\x1B[104m",bgBrightMagenta:"\x1B[105m",bgBrightCyan:"\x1B[106m",bgBrightWhite:"\x1B[107m",bold:"\x1B[1m",dim:"\x1B[2m",italic:"\x1B[3m",underline:"\x1B[4m",inverse:"\x1B[7m",hidden:"\x1B[8m",strikethrough:"\x1B[9m",reset:"\x1B[0m"});var gi=()=>({none:e=>e,uncolor:wT,mix:MT,hex:bT,rgb:gf,bgRgb:xT});function wT(e){return e.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,"")}function MT(...e){return r=>{for(let t of e)r=t(r);return r}}function bT(e){e=e.replace(/^#/,"");let r,t,s,o;if(e.length===3)r=parseInt(e.split("").map(a=>a+a).join(""),16);else if(e.length===6)r=parseInt(e,16);else throw new Error("Invalid hex color");return t=r>>16&255,s=r>>8&255,o=r&255,gf(t,s,o)}function gf(e,r,t){let s=`\x1B[38;2;${e};${r};${t}m`;return o=>`${s}${o}${oo.reset}`}function xT(e,r,t){let s=`\x1B[48;2;${e};${r};${t}m`;return o=>`${s}${o}${oo.reset}`}var Qa={...Object.fromEntries(Object.entries(oo).map(([e])=>[e,r=>r])),...gi()};var Xa={...Object.fromEntries(Object.entries(oo).map(([e,r])=>[e,t=>`${r}${t}${oo.reset}`])),...gi()};function Ec(){return typeof Deno<"u"&&typeof Deno.version<"u"}function kc(){return typeof process<"u"&&process.versions&&process.versions.node}function wf(){return kc()?process.env.FORCE_COLOR||process.stdout.isTTY&&process.env.TERM!=="dumb":Ec()?Deno.env.get("FORCE_COLOR")||Deno.isatty(Deno.stdout.rid)&&Deno.env.get("TERM")!=="dumb":!1}var Cc=()=>wf()?Xa:Qa;var wi=()=>({colors:e,theme:r})=>{let t=r(e);function s(n){let i=n.stack?`
`+n.stack+`
`:"";return[t.errName(n.name+":"),t.errMessage(n.message)].join(" ")+t.errStack(i)}function o(n){return n&&n instanceof Error?s(n):n}function a(n){return n&&n instanceof Error?s(n):t.errMessage(n)}return{stdout:n=>n.map(o),stderr:n=>n.map(a)}};function Ja(...e){return r=>({stdout:t=>{for(let s of e)t=s(r).stdout(t);return t},stderr:t=>{for(let s of e)t=s(r).stderr(t);return t}})}function vT(){return{icon:"\u{1F6A8}",now:()=>Date.now()}}var Mi=e=>({colors:r,theme:t})=>{let s={...vT(),...e},o=t(r),a=new Date(s.now()),n=a.getUTCFullYear().toString().padStart(4,"0"),i=(a.getUTCMonth()+1).toString().padStart(2,"0"),l=a.getUTCDate().toString().padStart(2,"0"),c=`${n}-${i}-${l}`,_=a.getUTCHours().toString().padStart(2,"0"),u=a.getUTCMinutes().toString().padStart(2,"0"),d=a.getUTCSeconds().toString().padStart(2,"0"),f=a.getUTCMilliseconds().toString().padStart(3,"0"),h=`${_}:${u}:${d}.${f}`,v=`${c}::${h}`;return{stdout:F=>[o.timestamp(v),...F],stderr:F=>[o.timestampErr(v),...[s.icon].filter(Boolean),...F]}};function Mf(){return Ja(wi(),Mi())}var bi=()=>({stdout:async e=>{await Deno.stdout.write(new TextEncoder().encode(e+`
`))},stderr:async e=>{await Deno.stderr.write(new TextEncoder().encode(e+`
`))}});var xi=()=>({stdout:async e=>void process.stdout.write(e+`
`),stderr:async e=>void process.stderr.write(e+`
`)});var vi=()=>({stdout:async e=>console.log(e),stderr:async e=>console.error(e)});var bf=()=>Ec()?bi():kc()?xi():vi();var xf=()=>({stdout:async()=>{},stderr:async()=>{}});function vf(){return()=>({stdout:e=>e,stderr:e=>e})}var da=class e{static writers={auto:bf,void:xf,deno:bi,node:xi,console:vi};static colors={auto:Cc,colorful:()=>Xa,colorless:()=>Qa};static themes={auto:ff,basic:fi};static shapers={auto:Mf,none:vf,errors:wi,timestamp:Mi};writer=e.writers.auto();colors=e.colors.auto();theme=e.themes.auto();shaper=e.shapers.auto();async log(...r){await this.writer.stdout(this.shaper(this).stdout(r).join(" "))}async error(...r){await this.writer.stderr(this.shaper(this).stderr(r).join(" "))}setWriter(r){return this.writer=r,this}setColors(r){return this.colors=r,this}setTheme(r){return this.theme=r,this}setShaper(...r){return this.shaper=Ja(...r),this}};var Ya=class extends da{static dummy(){return new this().setWriter(da.writers.void())}rpcRequest=async({request:r,...t})=>{let s=this.colors.none;this.log(...this.#e(t),s(`${r.method}()`))};rpcError=async({request:r,error:t,...s})=>{this.error(...this.#e(s),`${r.method}()`,t)};#e({meta:r,label:t,remote:s}){let o=this.colors.mix(this.colors.blue,this.colors.dim),a=this.colors.mix(this.colors.cyan,this.colors.dim);return[r?this.#t(r):void 0,t||void 0,s===void 0?void 0:s?o("<-"):a("->")].filter(Boolean)}#t(r){let{headers:t}=r.request;return[this.colors.yellow(`[${r.ip}]`),this.colors.green(t.origin?t.origin:"(no-origin)")].join(" ")}};var Os=class extends Ya{rpcRequest=async()=>{}};var ao;(function(e){e.version="2.0";function r(t){return"id"in t?t.id:null}e.getId=r,e.errorCodes={serverError:-32e3,unexposedError:-32001}})(ao||(ao={}));var yi=class extends Error{name=this.constructor.name},Co=class extends Error{name=this.constructor.name};async function yf({tap:e,request:r,action:t}){let s=ao.getId(r);try{let o=await t();return s===null?null:{id:s,result:o,jsonrpc:ao.version}}catch(o){return e.rpcError({request:r,error:o}),s===null?null:{id:s,jsonrpc:ao.version,error:o instanceof yi?{code:ao.errorCodes.serverError,message:o.message}:{code:ao.errorCodes.unexposedError,message:"unexposed error"}}}}function Ti(e){let r=e.tap??new Os;return async t=>{let s=t.method.split("."),o=_f(e.fns,s),a=async()=>await o(...t.params);return r.rpcRequest({request:t}),await yf({tap:r,request:t,action:a})}}var Tf=Symbol("tune"),yT=Symbol("query"),TT=Symbol("notify"),PT=Symbol("settings");function Pf(e){function r(t){let s={notify:void 0};return new Proxy(()=>{},{apply:(o,a,n)=>e(t,n,s),get:(o,a)=>{if(a!=="then")return a===Tf?n=>(...i)=>e(t,i,{...s,...n}):a===TT?(...n)=>e(t,n,{...s,notify:!0}):a===yT?(...n)=>e(t,n,{...s,notify:!1}):a===PT?s:(o[a]||(o[a]=r([...t,a])),o[a])},set:(o,a,n)=>(o[a]=n,!0)})}return r([])}function So(e){let{endpoint:r,tap:t=new Os}=e,s=1;return Pf(async(o,a,n)=>{let i=n.notify??e.notify??!1,l=n.transfer,c={jsonrpc:"2.0",method:o.join("."),params:a},_=i?c:{...c,id:s++};t.rpcRequest({request:_});let u=await r(_,{transfer:l});if(i&&!u)return null;if(!u)throw new Co("response was null, but shouldn't be, because the request was not a notification");if("error"in u)throw new Co(e.label?`${e.label}: ${u.error.message}`:u.error.message);return u.result})}function Za(e){return So({endpoint:Ti(e),tap:e.tap})}var Fo=class{recv=hi();sendRequest=hi();sendResponse=hi();static makeEntangledPair({origin:r="example.e280.org"}={}){let t=new this,s=new this,o=[t.sendRequest.sub(n=>s.recv(n,{origin:r})),t.sendResponse.sub(n=>s.recv(n,{origin:r})),s.sendRequest.sub(n=>t.recv(n,{origin:r})),s.sendResponse.sub(n=>t.recv(n,{origin:r}))];return[t,s,()=>o.forEach(n=>n())]}};function Pi(e,r){return e.addEventListener("message",r),()=>e.removeEventListener("message",r)}function Ef(e,r){return async(t,{transfer:s}={})=>{if("id"in t){let o=es();return r(t,s,o.promise),e.wait(t.id,t.method).then(a=>(o.resolve(a),a))}else{let o=Promise.resolve(null);return r(t,s,o),o}}}function kf(e){let r=[],t=[];for(let s of Array.isArray(e)?e:[e])"method"in s?r.push(s):t.push(s);return{requests:r,responses:t}}async function Cf(e,r){let t=(await Promise.all(r.map(async s=>e(s)))).filter(s=>s!==null);return t.length===0?null:t.length===1?t[0]:t}var ua=class extends Fo{#e=new Vs;constructor(r){super(),this.#e.add(this.sendRequest.sub((t,s)=>r.postMessage(t,s)),this.sendResponse.sub((t,s)=>r.postMessage(t,s)),Pi(r,t=>this.recv(t.data,t)))}dispose(){this.#e.dispose()}};var Ei=class{remote;transfer;constructor(r){this.remote=r}};var Sc=Object.freeze({timeout:6e4,maxRequestBytes:1e7});var ki=class{timeout;pending=new Map;constructor(r){this.timeout=r}async wait(r,t){let s=es();return this.pending.set(r,{method:t,deferred:s}),await mi(this.timeout,()=>s.promise).catch(o=>{throw o instanceof Ha&&(o.message=`request #${r} ${t}(), ${o.message}`),o})}deliverResponse(r){let t=this.pending.get(r.id);t&&("error"in r?t.deferred.reject(new Co(r.error.message)):t.deferred.resolve(r))}};var Io=class{options;remote;remoteEndpoint;#e;#t=new Vs;constructor(r){this.options=r;let{conduit:t,tap:s}=r;this.#e=new ki(r.timeout??Sc.timeout),this.remoteEndpoint=Ef(this.#e,t.sendRequest.pub.bind(t.sendRequest)),this.remote=So({endpoint:this.remoteEndpoint,tap:s&&Pc(s,{remote:!0})}),this.#t.add(t.recv.sub(o=>this.recv(o)))}async recv(r){let t=new Ei(this.remote),{conduit:s,rpc:o,tap:a}=this.options,{requests:n,responses:i}=kf(r);for(let u of i)this.#e.deliverResponse(u);if(!o)return;let l=await o(t),c=Ti({fns:l,tap:a&&Pc(a,{remote:!1})}),_=await Cf(c,n);_&&await s.sendResponse(_,t.transfer)}dispose(){this.#t.dispose()}};var Ws={derive:{host:e=>({host:e.remote.host,get transfer(){return e.transfer},set transfer(r){e.transfer=r}}),work:e=>({work:e.remote,get transfer(){return e.transfer},set transfer(r){e.transfer=r}})},mock:{host:()=>({host:void 0,transfer:void 0}),work:()=>({work:void 0,transfer:void 0})}};var Us=new Os;async function Sf(e,r,t={}){let s=t.tap??Us,o=new Io({tap:s,timeout:t.timeout??1/0,conduit:new ua(e.getSelf()),rpc:async a=>r(Ws.derive.host(a))});return await o.remote.infra.ready(),o.remote.host}var _a=class{worker;messenger;constructor(r,t){this.worker=r,this.messenger=t}static async make(r,t){let s=t.tap??Us,o=t.label??"comrade",a=r.loadWorker(t.workerUrl,o),n=es(),i={async ready(){n.resolve()}},l=new Io({tap:s,timeout:t.timeout??1/0,conduit:new ua(a),rpc:async c=>({infra:i,host:t.setupHost(Ws.derive.work(c))})});return await n.promise,new this(a,l)}get work(){return this.messenger.remote}terminate(){this.worker.terminate()}};var Ci=class{threads;static async make(r,t){let s=t.workerCount??r.guessOptimalThreadCount(),o=await Promise.all([...Array(s)].map(async(a,n)=>_a.make(r,{...t,label:t.label??`${t.label??"comrade"}_${n+1}`})));return new this(o,{tap:t.tap})}work;#e=new Set;#t=[];constructor(r,t={}){this.threads=r;let s=t.tap??Us,o=async(a,n)=>this.#s({request:a,prom:es(),transfer:n?.transfer});this.work=So({tap:s,endpoint:o}),r.forEach(a=>this.#e.add(a))}get threadCount(){return this.threads.length}terminate(){for(let r of this.threads)r.terminate()}#s(r){return this.#t.push(r),this.#r(),r.prom.promise}#r(){for(;this.#e.size>0&&this.#t.length>0;){let r=[...this.#e].pop();this.#e.delete(r);let t=this.#t.shift();this.#e.delete(r);let s=r.messenger.remoteEndpoint(t.request,{transfer:t.transfer});t.prom.entangle(s).finally(()=>{this.#e.add(r),this.#r()})}}};var Ff=e=>({thread:r=>_a.make(e,r),cluster:r=>Ci.make(e,r),worker:(r,t={})=>Sf(e,r,t),work:r=>r,host:r=>r,mocks(r){let{setupWork:t,setupHost:s,tap:o=Us}=r,a=Ws.mock.host(),n=Ws.mock.work();return n.work=Za({tap:o,fns:t(a)}),a.host=Za({tap:o,fns:s(n)}),{workShell:n,hostShell:a,work:n.work,host:a.host}},mockWork(r,t=Us){let s=Ws.mock.host(),o=Ws.mock.work();return o.work=Za({tap:t,fns:r(s)}),{workShell:o,hostShell:s,work:o.work,mockHost:a=>(s.host=Za({tap:t,fns:a(o)}),{workShell:o,hostShell:s,work:o.work,host:s.host})}}});var If=()=>({getSelf(){return self},guessOptimalThreadCount(){let e=navigator.hardwareConcurrency??1;return Math.max(1,e-1)},loadWorker(e,r){return new window.Worker(e,{name:r,type:"module"})},async loadWasm(e){return WebAssembly.instantiateStreaming(fetch(e))}});var ST=If(),Af=Ff(ST);var Ic={};cf(Ic,{InferenceSession:()=>AT,TRACE:()=>Hf,TRACE_FUNC_BEGIN:()=>Fi,TRACE_FUNC_END:()=>Ii,Tensor:()=>Do,env:()=>IT,registerBackend:()=>$f});var Si=new Map,Ao=[],$f=(e,r,t)=>{if(r&&typeof r.init=="function"&&typeof r.createInferenceSessionHandler=="function"){let s=Si.get(e);if(s===void 0)Si.set(e,{backend:r,priority:t});else{if(s.priority>t)return;if(s.priority===t&&s.backend!==r)throw new Error(`cannot register backend "${e}" using priority ${t}`)}if(t>=0){let o=Ao.indexOf(e);o!==-1&&Ao.splice(o,1);for(let a=0;a<Ao.length;a++)if(Si.get(Ao[a]).priority<=t){Ao.splice(a,0,e);return}Ao.push(e)}return}throw new TypeError("not a valid backend")},FT=async e=>{let r=Si.get(e);if(!r)return"backend not found.";if(r.initialized)return r.backend;if(r.aborted)return r.error;{let t=!!r.initPromise;try{return t||(r.initPromise=r.backend.init(e)),await r.initPromise,r.initialized=!0,r.backend}catch(s){return t||(r.error=`${s}`,r.aborted=!0),r.error}finally{delete r.initPromise}}},Df=async e=>{let r=e.executionProviders||[],t=r.map(l=>typeof l=="string"?l:l.name),s=t.length===0?Ao:t,o,a=[],n=new Set;for(let l of s){let c=await FT(l);typeof c=="string"?a.push({name:l,err:c}):(o||(o=c),o===c&&n.add(l))}if(!o)throw new Error(`no available backend found. ERR: ${a.map(l=>`[${l.name}] ${l.err}`).join(", ")}`);for(let{name:l,err:c}of a)t.includes(l)&&console.warn(`removing requested execution provider "${l}" from session options because it is not available: ${c}`);let i=r.filter(l=>n.has(typeof l=="string"?l:l.name));return[o,new Proxy(e,{get:(l,c)=>c==="executionProviders"?i:Reflect.get(l,c)})]};var Of="1.21.0";var Lf="warning",ts={wasm:{},webgl:{},webgpu:{},versions:{common:Of},set logLevel(e){if(e!==void 0){if(typeof e!="string"||["verbose","info","warning","error","fatal"].indexOf(e)===-1)throw new Error(`Unsupported logging level: ${e}`);Lf=e}},get logLevel(){return Lf}};Object.defineProperty(ts,"logLevel",{enumerable:!0});var IT=ts;var Bf=(e,r)=>{let t=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);t.width=e.dims[3],t.height=e.dims[2];let s=t.getContext("2d");if(s!=null){let o,a;r?.tensorLayout!==void 0&&r.tensorLayout==="NHWC"?(o=e.dims[2],a=e.dims[3]):(o=e.dims[3],a=e.dims[2]);let n=r?.format!==void 0?r.format:"RGB",i=r?.norm,l,c;i===void 0||i.mean===void 0?l=[255,255,255,255]:typeof i.mean=="number"?l=[i.mean,i.mean,i.mean,i.mean]:(l=[i.mean[0],i.mean[1],i.mean[2],0],i.mean[3]!==void 0&&(l[3]=i.mean[3])),i===void 0||i.bias===void 0?c=[0,0,0,0]:typeof i.bias=="number"?c=[i.bias,i.bias,i.bias,i.bias]:(c=[i.bias[0],i.bias[1],i.bias[2],0],i.bias[3]!==void 0&&(c[3]=i.bias[3]));let _=a*o,u=0,d=_,f=_*2,h=-1;n==="RGBA"?(u=0,d=_,f=_*2,h=_*3):n==="RGB"?(u=0,d=_,f=_*2):n==="RBG"&&(u=0,f=_,d=_*2);for(let v=0;v<a;v++)for(let F=0;F<o;F++){let x=(e.data[u++]-c[0])*l[0],w=(e.data[d++]-c[1])*l[1],C=(e.data[f++]-c[2])*l[2],y=h===-1?255:(e.data[h++]-c[3])*l[3];s.fillStyle="rgba("+x+","+w+","+C+","+y+")",s.fillRect(F,v,1,1)}if("toDataURL"in t)return t.toDataURL();throw new Error("toDataURL is not supported")}else throw new Error("Can not access image data")},zf=(e,r)=>{let t=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),s;if(t!=null){let o,a,n;r?.tensorLayout!==void 0&&r.tensorLayout==="NHWC"?(o=e.dims[2],a=e.dims[1],n=e.dims[3]):(o=e.dims[3],a=e.dims[2],n=e.dims[1]);let i=r!==void 0&&r.format!==void 0?r.format:"RGB",l=r?.norm,c,_;l===void 0||l.mean===void 0?c=[255,255,255,255]:typeof l.mean=="number"?c=[l.mean,l.mean,l.mean,l.mean]:(c=[l.mean[0],l.mean[1],l.mean[2],255],l.mean[3]!==void 0&&(c[3]=l.mean[3])),l===void 0||l.bias===void 0?_=[0,0,0,0]:typeof l.bias=="number"?_=[l.bias,l.bias,l.bias,l.bias]:(_=[l.bias[0],l.bias[1],l.bias[2],0],l.bias[3]!==void 0&&(_[3]=l.bias[3]));let u=a*o;if(r!==void 0&&(r.format!==void 0&&n===4&&r.format!=="RGBA"||n===3&&r.format!=="RGB"&&r.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let d=4,f=0,h=1,v=2,F=3,x=0,w=u,C=u*2,y=-1;i==="RGBA"?(x=0,w=u,C=u*2,y=u*3):i==="RGB"?(x=0,w=u,C=u*2):i==="RBG"&&(x=0,C=u,w=u*2),s=t.createImageData(o,a);for(let P=0;P<a*o;f+=d,h+=d,v+=d,F+=d,P++)s.data[f]=(e.data[x++]-_[0])*c[0],s.data[h]=(e.data[w++]-_[1])*c[1],s.data[v]=(e.data[C++]-_[2])*c[2],s.data[F]=y===-1?255:(e.data[y++]-_[3])*c[3]}else throw new Error("Can not access image data");return s};var Fc=(e,r)=>{if(e===void 0)throw new Error("Image buffer must be defined");if(r.height===void 0||r.width===void 0)throw new Error("Image height and width must be defined");if(r.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:t,width:s}=r,o=r.norm??{mean:255,bias:0},a,n;typeof o.mean=="number"?a=[o.mean,o.mean,o.mean,o.mean]:a=[o.mean[0],o.mean[1],o.mean[2],o.mean[3]??255],typeof o.bias=="number"?n=[o.bias,o.bias,o.bias,o.bias]:n=[o.bias[0],o.bias[1],o.bias[2],o.bias[3]??0];let i=r.format!==void 0?r.format:"RGBA",l=r.tensorFormat!==void 0&&r.tensorFormat!==void 0?r.tensorFormat:"RGB",c=t*s,_=l==="RGBA"?new Float32Array(c*4):new Float32Array(c*3),u=4,d=0,f=1,h=2,v=3,F=0,x=c,w=c*2,C=-1;i==="RGB"&&(u=3,d=0,f=1,h=2,v=-1),l==="RGBA"?C=c*3:l==="RBG"?(F=0,w=c,x=c*2):l==="BGR"&&(w=0,x=c,F=c*2);for(let P=0;P<c;P++,d+=u,h+=u,f+=u,v+=u)_[F++]=(e[d]+n[0])/a[0],_[x++]=(e[f]+n[1])/a[1],_[w++]=(e[h]+n[2])/a[2],C!==-1&&v!==-1&&(_[C++]=(e[v]+n[3])/a[3]);return l==="RGBA"?new Br("float32",_,[1,4,t,s]):new Br("float32",_,[1,3,t,s])},Rf=async(e,r)=>{let t=typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement,s=typeof ImageData<"u"&&e instanceof ImageData,o=typeof ImageBitmap<"u"&&e instanceof ImageBitmap,a=typeof e=="string",n,i=r??{},l=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},c=_=>typeof HTMLCanvasElement<"u"&&_ instanceof HTMLCanvasElement||_ instanceof OffscreenCanvas?_.getContext("2d"):null;if(t){let _=l();_.width=e.width,_.height=e.height;let u=c(_);if(u!=null){let d=e.height,f=e.width;if(r!==void 0&&r.resizedHeight!==void 0&&r.resizedWidth!==void 0&&(d=r.resizedHeight,f=r.resizedWidth),r!==void 0){if(i=r,r.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");i.tensorFormat="RGBA",i.height=d,i.width=f}else i.tensorFormat="RGBA",i.height=d,i.width=f;u.drawImage(e,0,0),n=u.getImageData(0,0,f,d).data}else throw new Error("Can not access image data")}else if(s){let _,u;if(r!==void 0&&r.resizedWidth!==void 0&&r.resizedHeight!==void 0?(_=r.resizedHeight,u=r.resizedWidth):(_=e.height,u=e.width),r!==void 0&&(i=r),i.format="RGBA",i.height=_,i.width=u,r!==void 0){let d=l();d.width=u,d.height=_;let f=c(d);if(f!=null)f.putImageData(e,0,0),n=f.getImageData(0,0,u,_).data;else throw new Error("Can not access image data")}else n=e.data}else if(o){if(r===void 0)throw new Error("Please provide image config with format for Imagebitmap");let _=l();_.width=e.width,_.height=e.height;let u=c(_);if(u!=null){let d=e.height,f=e.width;return u.drawImage(e,0,0,f,d),n=u.getImageData(0,0,f,d).data,i.height=d,i.width=f,Fc(n,i)}else throw new Error("Can not access image data")}else{if(a)return new Promise((_,u)=>{let d=l(),f=c(d);if(!e||!f)return u();let h=new Image;h.crossOrigin="Anonymous",h.src=e,h.onload=()=>{d.width=h.width,d.height=h.height,f.drawImage(h,0,0,d.width,d.height);let v=f.getImageData(0,0,d.width,d.height);i.height=d.height,i.width=d.width,_(Fc(v.data,i))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(n!==void 0)return Fc(n,i);throw new Error("Input data provided is not supported - aborted tensor creation")},Nf=(e,r)=>{let{width:t,height:s,download:o,dispose:a}=r,n=[1,s,t,4];return new Br({location:"texture",type:"float32",texture:e,dims:n,download:o,dispose:a})},jf=(e,r)=>{let{dataType:t,dims:s,download:o,dispose:a}=r;return new Br({location:"gpu-buffer",type:t??"float32",gpuBuffer:e,dims:s,download:o,dispose:a})},Vf=(e,r)=>{let{dataType:t,dims:s,download:o,dispose:a}=r;return new Br({location:"ml-tensor",type:t??"float32",mlTensor:e,dims:s,download:o,dispose:a})},Wf=(e,r,t)=>new Br({location:"cpu-pinned",type:e,data:r,dims:t??[r.length]});var $o=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),en=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),Uf=!1,Gf=()=>{if(!Uf){Uf=!0;let e=typeof BigInt64Array<"u"&&BigInt64Array.from,r=typeof BigUint64Array<"u"&&BigUint64Array.from,t=globalThis.Float16Array,s=typeof t<"u"&&t.from;e&&($o.set("int64",BigInt64Array),en.set(BigInt64Array,"int64")),r&&($o.set("uint64",BigUint64Array),en.set(BigUint64Array,"uint64")),s?($o.set("float16",t),en.set(t,"float16")):$o.set("float16",Uint16Array)}};var Kf=e=>{let r=1;for(let t=0;t<e.length;t++){let s=e[t];if(typeof s!="number"||!Number.isSafeInteger(s))throw new TypeError(`dims[${t}] must be an integer, got: ${s}`);if(s<0)throw new RangeError(`dims[${t}] must be a non-negative integer, got: ${s}`);r*=s}return r},qf=(e,r)=>{switch(e.location){case"cpu":return new Br(e.type,e.data,r);case"cpu-pinned":return new Br({location:"cpu-pinned",data:e.data,type:e.type,dims:r});case"texture":return new Br({location:"texture",texture:e.texture,type:e.type,dims:r});case"gpu-buffer":return new Br({location:"gpu-buffer",gpuBuffer:e.gpuBuffer,type:e.type,dims:r});case"ml-tensor":return new Br({location:"ml-tensor",mlTensor:e.mlTensor,type:e.type,dims:r});default:throw new Error(`tensorReshape: tensor location ${e.location} is not supported`)}};var Br=class{constructor(r,t,s){Gf();let o,a;if(typeof r=="object"&&"location"in r)switch(this.dataLocation=r.location,o=r.type,a=r.dims,r.location){case"cpu-pinned":{let i=$o.get(o);if(!i)throw new TypeError(`unsupported type "${o}" to create tensor from pinned buffer`);if(!(r.data instanceof i))throw new TypeError(`buffer should be of type ${i.name}`);this.cpuData=r.data;break}case"texture":{if(o!=="float32")throw new TypeError(`unsupported type "${o}" to create tensor from texture`);this.gpuTextureData=r.texture,this.downloader=r.download,this.disposer=r.dispose;break}case"gpu-buffer":{if(o!=="float32"&&o!=="float16"&&o!=="int32"&&o!=="int64"&&o!=="uint32"&&o!=="uint8"&&o!=="bool"&&o!=="uint4"&&o!=="int4")throw new TypeError(`unsupported type "${o}" to create tensor from gpu buffer`);this.gpuBufferData=r.gpuBuffer,this.downloader=r.download,this.disposer=r.dispose;break}case"ml-tensor":{if(o!=="float32"&&o!=="float16"&&o!=="int32"&&o!=="int64"&&o!=="uint32"&&o!=="uint64"&&o!=="int8"&&o!=="uint8"&&o!=="bool"&&o!=="uint4"&&o!=="int4")throw new TypeError(`unsupported type "${o}" to create tensor from MLTensor`);this.mlTensorData=r.mlTensor,this.downloader=r.download,this.disposer=r.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let i,l;if(typeof r=="string")if(o=r,l=s,r==="string"){if(!Array.isArray(t))throw new TypeError("A string tensor's data must be a string array.");i=t}else{let c=$o.get(r);if(c===void 0)throw new TypeError(`Unsupported tensor type: ${r}.`);if(Array.isArray(t)){if(r==="float16"&&c===Uint16Array||r==="uint4"||r==="int4")throw new TypeError(`Creating a ${r} tensor from number array is not supported. Please use ${c.name} as data.`);r==="uint64"||r==="int64"?i=c.from(t,BigInt):i=c.from(t)}else if(t instanceof c)i=t;else if(t instanceof Uint8ClampedArray)if(r==="uint8")i=Uint8Array.from(t);else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else if(r==="float16"&&t instanceof Uint16Array&&c!==Uint16Array)i=new globalThis.Float16Array(t.buffer,t.byteOffset,t.length);else throw new TypeError(`A ${o} tensor's data must be type of ${c}`)}else if(l=t,Array.isArray(r)){if(r.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let c=typeof r[0];if(c==="string")o="string",i=r;else if(c==="boolean")o="bool",i=Uint8Array.from(r);else throw new TypeError(`Invalid element type of data array: ${c}.`)}else if(r instanceof Uint8ClampedArray)o="uint8",i=Uint8Array.from(r);else{let c=en.get(r.constructor);if(c===void 0)throw new TypeError(`Unsupported type for tensor data: ${r.constructor}.`);o=c,i=r}if(l===void 0)l=[i.length];else if(!Array.isArray(l))throw new TypeError("A tensor's dims must be a number array");a=l,this.cpuData=i,this.dataLocation="cpu"}let n=Kf(a);if(this.cpuData&&n!==this.cpuData.length&&!((o==="uint4"||o==="int4")&&Math.ceil(n/2)===this.cpuData.length))throw new Error(`Tensor's size(${n}) does not match data length(${this.cpuData.length}).`);this.type=o,this.dims=a,this.size=n}static async fromImage(r,t){return Rf(r,t)}static fromTexture(r,t){return Nf(r,t)}static fromGpuBuffer(r,t){return jf(r,t)}static fromMLTensor(r,t){return Vf(r,t)}static fromPinnedBuffer(r,t,s){return Wf(r,t,s)}toDataURL(r){return Bf(this,r)}toImageData(r){return zf(this,r)}get data(){if(this.ensureValid(),!this.cpuData)throw new Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw new Error("The data is not stored as a WebGL texture.");return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw new Error("The data is not stored as a WebGPU buffer.");return this.gpuBufferData}get mlTensor(){if(this.ensureValid(),!this.mlTensorData)throw new Error("The data is not stored as a WebNN MLTensor.");return this.mlTensorData}async getData(r){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":case"ml-tensor":{if(!this.downloader)throw new Error("The current tensor is not created with a specified data downloader.");if(this.isDownloading)throw new Error("The current tensor is being downloaded.");try{this.isDownloading=!0;let t=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=t,r&&this.disposer&&(this.disposer(),this.disposer=void 0),t}finally{this.isDownloading=!1}}default:throw new Error(`cannot get data from location: ${this.dataLocation}`)}}dispose(){if(this.isDownloading)throw new Error("The current tensor is being downloaded.");this.disposer&&(this.disposer(),this.disposer=void 0),this.cpuData=void 0,this.gpuTextureData=void 0,this.gpuBufferData=void 0,this.mlTensorData=void 0,this.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if(this.dataLocation==="none")throw new Error("The tensor is disposed.")}reshape(r){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return qf(this,r)}};var Do=Br;var Hf=(e,r)=>{(typeof ts.trace>"u"?!ts.wasm.trace:!ts.trace)||console.timeStamp(`${e}::ORT::${r}`)},Qf=(e,r)=>{let t=new Error().stack?.split(/\r\n|\r|\n/g)||[],s=!1;for(let o=0;o<t.length;o++){if(s&&!t[o].includes("TRACE_FUNC")){let a=`FUNC_${e}::${t[o].trim().split(" ")[1]}`;r&&(a+=`::${r}`),Hf("CPU",a);return}t[o].includes("TRACE_FUNC")&&(s=!0)}},Fi=e=>{(typeof ts.trace>"u"?!ts.wasm.trace:!ts.trace)||Qf("BEGIN",e)},Ii=e=>{(typeof ts.trace>"u"?!ts.wasm.trace:!ts.trace)||Qf("END",e)};var Ai=class e{constructor(r){this.handler=r}async run(r,t,s){Fi();let o={},a={};if(typeof r!="object"||r===null||r instanceof Do||Array.isArray(r))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let n=!0;if(typeof t=="object"){if(t===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(t instanceof Do)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(t)){if(t.length===0)throw new TypeError("'fetches' cannot be an empty array.");n=!1;for(let c of t){if(typeof c!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(c)===-1)throw new RangeError(`'fetches' contains invalid output name: ${c}.`);o[c]=null}if(typeof s=="object"&&s!==null)a=s;else if(typeof s<"u")throw new TypeError("'options' must be an object.")}else{let c=!1,_=Object.getOwnPropertyNames(t);for(let u of this.outputNames)if(_.indexOf(u)!==-1){let d=t[u];(d===null||d instanceof Do)&&(c=!0,n=!1,o[u]=d)}if(c){if(typeof s=="object"&&s!==null)a=s;else if(typeof s<"u")throw new TypeError("'options' must be an object.")}else a=t}}else if(typeof t<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let c of this.inputNames)if(typeof r[c]>"u")throw new Error(`input '${c}' is missing in 'feeds'.`);if(n)for(let c of this.outputNames)o[c]=null;let i=await this.handler.run(r,o,a),l={};for(let c in i)if(Object.hasOwnProperty.call(i,c)){let _=i[c];_ instanceof Do?l[c]=_:l[c]=new Do(_.type,_.data,_.dims)}return Ii(),l}async release(){return this.handler.dispose()}static async create(r,t,s,o){Fi();let a,n={};if(typeof r=="string"){if(a=r,typeof t=="object"&&t!==null)n=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else if(r instanceof Uint8Array){if(a=r,typeof t=="object"&&t!==null)n=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else if(r instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&r instanceof SharedArrayBuffer){let _=r,u=0,d=r.byteLength;if(typeof t=="object"&&t!==null)n=t;else if(typeof t=="number"){if(u=t,!Number.isSafeInteger(u))throw new RangeError("'byteOffset' must be an integer.");if(u<0||u>=_.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${_.byteLength}).`);if(d=r.byteLength-u,typeof s=="number"){if(d=s,!Number.isSafeInteger(d))throw new RangeError("'byteLength' must be an integer.");if(d<=0||u+d>_.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${_.byteLength-u}].`);if(typeof o=="object"&&o!==null)n=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else if(typeof s<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof t<"u")throw new TypeError("'options' must be an object.");a=new Uint8Array(_,u,d)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[i,l]=await Df(n),c=await i.createInferenceSessionHandler(a,l);return Ii(),new e(c)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}};var AT=Ai;var yu={};cf(yu,{InferenceSession:()=>Qd,TRACE:()=>wn,TRACE_FUNC_BEGIN:()=>Ps,TRACE_FUNC_END:()=>cs,Tensor:()=>Ts,default:()=>YP,env:()=>Xt,registerBackend:()=>jo});var qd=Object.defineProperty,$T=Object.getOwnPropertyDescriptor,DT=Object.getOwnPropertyNames,OT=Object.prototype.hasOwnProperty,LT=(e=>typeof Eo<"u"?Eo:typeof Proxy<"u"?new Proxy(e,{get:(r,t)=>(typeof Eo<"u"?Eo:r)[t]}):e)(function(e){if(typeof Eo<"u")return Eo.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),ze=(e,r)=>()=>(e&&(r=e(e=0)),r),wa=(e,r)=>{for(var t in r)qd(e,t,{get:r[t],enumerable:!0})},BT=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of DT(r))!OT.call(e,o)&&o!==t&&qd(e,o,{get:()=>r[o],enumerable:!(s=$T(r,o))||s.enumerable});return e},gn=e=>BT(qd({},"__esModule",{value:!0}),e),tn,no,jo,Xf,Cb,Sb=ze(()=>{"use strict";tn=new Map,no=[],jo=(e,r,t)=>{if(r&&typeof r.init=="function"&&typeof r.createInferenceSessionHandler=="function"){let s=tn.get(e);if(s===void 0)tn.set(e,{backend:r,priority:t});else{if(s.priority>t)return;if(s.priority===t&&s.backend!==r)throw new Error(`cannot register backend "${e}" using priority ${t}`)}if(t>=0){let o=no.indexOf(e);o!==-1&&no.splice(o,1);for(let a=0;a<no.length;a++)if(tn.get(no[a]).priority<=t){no.splice(a,0,e);return}no.push(e)}return}throw new TypeError("not a valid backend")},Xf=async e=>{let r=tn.get(e);if(!r)return"backend not found.";if(r.initialized)return r.backend;if(r.aborted)return r.error;{let t=!!r.initPromise;try{return t||(r.initPromise=r.backend.init(e)),await r.initPromise,r.initialized=!0,r.backend}catch(s){return t||(r.error=`${s}`,r.aborted=!0),r.error}finally{delete r.initPromise}}},Cb=async e=>{let r=e.executionProviders||[],t=r.map(l=>typeof l=="string"?l:l.name),s=t.length===0?no:t,o,a=[],n=new Set;for(let l of s){let c=await Xf(l);typeof c=="string"?a.push({name:l,err:c}):(o||(o=c),o===c&&n.add(l))}if(!o)throw new Error(`no available backend found. ERR: ${a.map(l=>`[${l.name}] ${l.err}`).join(", ")}`);for(let{name:l,err:c}of a)t.includes(l)&&console.warn(`removing requested execution provider "${l}" from session options because it is not available: ${c}`);let i=r.filter(l=>n.has(typeof l=="string"?l:l.name));return[o,new Proxy(e,{get:(l,c)=>c==="executionProviders"?i:Reflect.get(l,c)})]}}),zT=ze(()=>{"use strict";Sb()}),Fb,RT=ze(()=>{"use strict";Fb="1.22.0-dev.20250409-89f8206ba4"}),Ac,ls,Ib=ze(()=>{"use strict";RT(),Ac="warning",ls={wasm:{},webgl:{},webgpu:{},versions:{common:Fb},set logLevel(e){if(e!==void 0){if(typeof e!="string"||["verbose","info","warning","error","fatal"].indexOf(e)===-1)throw new Error(`Unsupported logging level: ${e}`);Ac=e}},get logLevel(){return Ac}},Object.defineProperty(ls,"logLevel",{enumerable:!0})}),Xt,NT=ze(()=>{"use strict";Ib(),Xt=ls}),Ab,$b,jT=ze(()=>{"use strict";Ab=(e,r)=>{let t=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);t.width=e.dims[3],t.height=e.dims[2];let s=t.getContext("2d");if(s!=null){let o,a;r?.tensorLayout!==void 0&&r.tensorLayout==="NHWC"?(o=e.dims[2],a=e.dims[3]):(o=e.dims[3],a=e.dims[2]);let n=r?.format!==void 0?r.format:"RGB",i=r?.norm,l,c;i===void 0||i.mean===void 0?l=[255,255,255,255]:typeof i.mean=="number"?l=[i.mean,i.mean,i.mean,i.mean]:(l=[i.mean[0],i.mean[1],i.mean[2],0],i.mean[3]!==void 0&&(l[3]=i.mean[3])),i===void 0||i.bias===void 0?c=[0,0,0,0]:typeof i.bias=="number"?c=[i.bias,i.bias,i.bias,i.bias]:(c=[i.bias[0],i.bias[1],i.bias[2],0],i.bias[3]!==void 0&&(c[3]=i.bias[3]));let _=a*o,u=0,d=_,f=_*2,h=-1;n==="RGBA"?(u=0,d=_,f=_*2,h=_*3):n==="RGB"?(u=0,d=_,f=_*2):n==="RBG"&&(u=0,f=_,d=_*2);for(let v=0;v<a;v++)for(let F=0;F<o;F++){let x=(e.data[u++]-c[0])*l[0],w=(e.data[d++]-c[1])*l[1],C=(e.data[f++]-c[2])*l[2],y=h===-1?255:(e.data[h++]-c[3])*l[3];s.fillStyle="rgba("+x+","+w+","+C+","+y+")",s.fillRect(F,v,1,1)}if("toDataURL"in t)return t.toDataURL();throw new Error("toDataURL is not supported")}else throw new Error("Can not access image data")},$b=(e,r)=>{let t=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),s;if(t!=null){let o,a,n;r?.tensorLayout!==void 0&&r.tensorLayout==="NHWC"?(o=e.dims[2],a=e.dims[1],n=e.dims[3]):(o=e.dims[3],a=e.dims[2],n=e.dims[1]);let i=r!==void 0&&r.format!==void 0?r.format:"RGB",l=r?.norm,c,_;l===void 0||l.mean===void 0?c=[255,255,255,255]:typeof l.mean=="number"?c=[l.mean,l.mean,l.mean,l.mean]:(c=[l.mean[0],l.mean[1],l.mean[2],255],l.mean[3]!==void 0&&(c[3]=l.mean[3])),l===void 0||l.bias===void 0?_=[0,0,0,0]:typeof l.bias=="number"?_=[l.bias,l.bias,l.bias,l.bias]:(_=[l.bias[0],l.bias[1],l.bias[2],0],l.bias[3]!==void 0&&(_[3]=l.bias[3]));let u=a*o;if(r!==void 0&&(r.format!==void 0&&n===4&&r.format!=="RGBA"||n===3&&r.format!=="RGB"&&r.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let d=4,f=0,h=1,v=2,F=3,x=0,w=u,C=u*2,y=-1;i==="RGBA"?(x=0,w=u,C=u*2,y=u*3):i==="RGB"?(x=0,w=u,C=u*2):i==="RBG"&&(x=0,C=u,w=u*2),s=t.createImageData(o,a);for(let P=0;P<a*o;f+=d,h+=d,v+=d,F+=d,P++)s.data[f]=(e.data[x++]-_[0])*c[0],s.data[h]=(e.data[w++]-_[1])*c[1],s.data[v]=(e.data[C++]-_[2])*c[2],s.data[F]=y===-1?255:(e.data[y++]-_[3])*c[3]}else throw new Error("Can not access image data");return s}}),$i,Db,Ob,Lb,Bb,zb,VT=ze(()=>{"use strict";Hd(),$i=(e,r)=>{if(e===void 0)throw new Error("Image buffer must be defined");if(r.height===void 0||r.width===void 0)throw new Error("Image height and width must be defined");if(r.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:t,width:s}=r,o=r.norm??{mean:255,bias:0},a,n;typeof o.mean=="number"?a=[o.mean,o.mean,o.mean,o.mean]:a=[o.mean[0],o.mean[1],o.mean[2],o.mean[3]??255],typeof o.bias=="number"?n=[o.bias,o.bias,o.bias,o.bias]:n=[o.bias[0],o.bias[1],o.bias[2],o.bias[3]??0];let i=r.format!==void 0?r.format:"RGBA",l=r.tensorFormat!==void 0&&r.tensorFormat!==void 0?r.tensorFormat:"RGB",c=t*s,_=l==="RGBA"?new Float32Array(c*4):new Float32Array(c*3),u=4,d=0,f=1,h=2,v=3,F=0,x=c,w=c*2,C=-1;i==="RGB"&&(u=3,d=0,f=1,h=2,v=-1),l==="RGBA"?C=c*3:l==="RBG"?(F=0,w=c,x=c*2):l==="BGR"&&(w=0,x=c,F=c*2);for(let y=0;y<c;y++,d+=u,h+=u,f+=u,v+=u)_[F++]=(e[d]+n[0])/a[0],_[x++]=(e[f]+n[1])/a[1],_[w++]=(e[h]+n[2])/a[2],C!==-1&&v!==-1&&(_[C++]=(e[v]+n[3])/a[3]);return l==="RGBA"?new ss("float32",_,[1,4,t,s]):new ss("float32",_,[1,3,t,s])},Db=async(e,r)=>{let t=typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement,s=typeof ImageData<"u"&&e instanceof ImageData,o=typeof ImageBitmap<"u"&&e instanceof ImageBitmap,a=typeof e=="string",n,i=r??{},l=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},c=_=>typeof HTMLCanvasElement<"u"&&_ instanceof HTMLCanvasElement||_ instanceof OffscreenCanvas?_.getContext("2d"):null;if(t){let _=l();_.width=e.width,_.height=e.height;let u=c(_);if(u!=null){let d=e.height,f=e.width;if(r!==void 0&&r.resizedHeight!==void 0&&r.resizedWidth!==void 0&&(d=r.resizedHeight,f=r.resizedWidth),r!==void 0){if(i=r,r.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");i.tensorFormat="RGBA",i.height=d,i.width=f}else i.tensorFormat="RGBA",i.height=d,i.width=f;u.drawImage(e,0,0),n=u.getImageData(0,0,f,d).data}else throw new Error("Can not access image data")}else if(s){let _,u;if(r!==void 0&&r.resizedWidth!==void 0&&r.resizedHeight!==void 0?(_=r.resizedHeight,u=r.resizedWidth):(_=e.height,u=e.width),r!==void 0&&(i=r),i.format="RGBA",i.height=_,i.width=u,r!==void 0){let d=l();d.width=u,d.height=_;let f=c(d);if(f!=null)f.putImageData(e,0,0),n=f.getImageData(0,0,u,_).data;else throw new Error("Can not access image data")}else n=e.data}else if(o){if(r===void 0)throw new Error("Please provide image config with format for Imagebitmap");let _=l();_.width=e.width,_.height=e.height;let u=c(_);if(u!=null){let d=e.height,f=e.width;return u.drawImage(e,0,0,f,d),n=u.getImageData(0,0,f,d).data,i.height=d,i.width=f,$i(n,i)}else throw new Error("Can not access image data")}else{if(a)return new Promise((_,u)=>{let d=l(),f=c(d);if(!e||!f)return u();let h=new Image;h.crossOrigin="Anonymous",h.src=e,h.onload=()=>{d.width=h.width,d.height=h.height,f.drawImage(h,0,0,d.width,d.height);let v=f.getImageData(0,0,d.width,d.height);i.height=d.height,i.width=d.width,_($i(v.data,i))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(n!==void 0)return $i(n,i);throw new Error("Input data provided is not supported - aborted tensor creation")},Ob=(e,r)=>{let{width:t,height:s,download:o,dispose:a}=r,n=[1,s,t,4];return new ss({location:"texture",type:"float32",texture:e,dims:n,download:o,dispose:a})},Lb=(e,r)=>{let{dataType:t,dims:s,download:o,dispose:a}=r;return new ss({location:"gpu-buffer",type:t??"float32",gpuBuffer:e,dims:s,download:o,dispose:a})},Bb=(e,r)=>{let{dataType:t,dims:s,download:o,dispose:a}=r;return new ss({location:"ml-tensor",type:t??"float32",mlTensor:e,dims:s,download:o,dispose:a})},zb=(e,r,t)=>new ss({location:"cpu-pinned",type:e,data:r,dims:t??[r.length]})}),Ro,_n,$c,Rb,WT=ze(()=>{"use strict";Ro=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),_n=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),$c=!1,Rb=()=>{if(!$c){$c=!0;let e=typeof BigInt64Array<"u"&&BigInt64Array.from,r=typeof BigUint64Array<"u"&&BigUint64Array.from,t=globalThis.Float16Array,s=typeof t<"u"&&t.from;e&&(Ro.set("int64",BigInt64Array),_n.set(BigInt64Array,"int64")),r&&(Ro.set("uint64",BigUint64Array),_n.set(BigUint64Array,"uint64")),s?(Ro.set("float16",t),_n.set(t,"float16")):Ro.set("float16",Uint16Array)}}}),Nb,jb,UT=ze(()=>{"use strict";Hd(),Nb=e=>{let r=1;for(let t=0;t<e.length;t++){let s=e[t];if(typeof s!="number"||!Number.isSafeInteger(s))throw new TypeError(`dims[${t}] must be an integer, got: ${s}`);if(s<0)throw new RangeError(`dims[${t}] must be a non-negative integer, got: ${s}`);r*=s}return r},jb=(e,r)=>{switch(e.location){case"cpu":return new ss(e.type,e.data,r);case"cpu-pinned":return new ss({location:"cpu-pinned",data:e.data,type:e.type,dims:r});case"texture":return new ss({location:"texture",texture:e.texture,type:e.type,dims:r});case"gpu-buffer":return new ss({location:"gpu-buffer",gpuBuffer:e.gpuBuffer,type:e.type,dims:r});case"ml-tensor":return new ss({location:"ml-tensor",mlTensor:e.mlTensor,type:e.type,dims:r});default:throw new Error(`tensorReshape: tensor location ${e.location} is not supported`)}}}),ss,Hd=ze(()=>{"use strict";jT(),VT(),WT(),UT(),ss=class{constructor(e,r,t){Rb();let s,o;if(typeof e=="object"&&"location"in e)switch(this.dataLocation=e.location,s=e.type,o=e.dims,e.location){case"cpu-pinned":{let n=Ro.get(s);if(!n)throw new TypeError(`unsupported type "${s}" to create tensor from pinned buffer`);if(!(e.data instanceof n))throw new TypeError(`buffer should be of type ${n.name}`);this.cpuData=e.data;break}case"texture":{if(s!=="float32")throw new TypeError(`unsupported type "${s}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.dispose;break}case"gpu-buffer":{if(s!=="float32"&&s!=="float16"&&s!=="int32"&&s!=="int64"&&s!=="uint32"&&s!=="uint8"&&s!=="bool"&&s!=="uint4"&&s!=="int4")throw new TypeError(`unsupported type "${s}" to create tensor from gpu buffer`);this.gpuBufferData=e.gpuBuffer,this.downloader=e.download,this.disposer=e.dispose;break}case"ml-tensor":{if(s!=="float32"&&s!=="float16"&&s!=="int32"&&s!=="int64"&&s!=="uint32"&&s!=="uint64"&&s!=="int8"&&s!=="uint8"&&s!=="bool"&&s!=="uint4"&&s!=="int4")throw new TypeError(`unsupported type "${s}" to create tensor from MLTensor`);this.mlTensorData=e.mlTensor,this.downloader=e.download,this.disposer=e.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let n,i;if(typeof e=="string")if(s=e,i=t,e==="string"){if(!Array.isArray(r))throw new TypeError("A string tensor's data must be a string array.");n=r}else{let l=Ro.get(e);if(l===void 0)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(r)){if(e==="float16"&&l===Uint16Array||e==="uint4"||e==="int4")throw new TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${l.name} as data.`);e==="uint64"||e==="int64"?n=l.from(r,BigInt)