UNPKG

contextmax

Version:

Privacy-first, browser-based tool for creating precise context sets for LLMs

2 lines 422 kB
var zm=Object.defineProperty;var Am=(e,t,r)=>t in e?zm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Rs=(e,t,r)=>Am(e,typeof t!="symbol"?t+"":t,r);const gd=/#/g,yd=/&/g,_d=/\//g,Om=/=/g,Rm=/\?/g,Yr=/\+/g,Bm=/%5e/gi,Dm=/%60/gi,Nm=/%7c/gi,Mm=/%20/gi,Pm=/%252f/gi;function bd(e){return encodeURI(""+e).replace(Nm,"|")}function vn(e){return bd(typeof e=="string"?e:JSON.stringify(e)).replace(Yr,"%2B").replace(Mm,"+").replace(gd,"%23").replace(yd,"%26").replace(Dm,"`").replace(Bm,"^").replace(_d,"%2F")}function wi(e){return vn(e).replace(Om,"%3D")}function Um(e){return bd(e).replace(gd,"%23").replace(Rm,"%3F").replace(Pm,"%2F").replace(yd,"%26").replace(Yr,"%2B")}function Vy(e){return Um(e).replace(_d,"%2F")}function qr(e=""){try{return decodeURIComponent(""+e)}catch{return""+e}}function Lm(e){return qr(e.replace(Yr," "))}function Wm(e){return qr(e.replace(Yr," "))}function qm(e=""){const t=Object.create(null);e[0]==="?"&&(e=e.slice(1));for(const r of e.split("&")){const n=r.match(/([^=]+)=?(.*)/)||[];if(n.length<2)continue;const a=Lm(n[1]);if(a==="__proto__"||a==="constructor")continue;const i=Wm(n[2]||"");t[a]===void 0?t[a]=i:Array.isArray(t[a])?t[a].push(i):t[a]=[t[a],i]}return t}function jm(e,t){return(typeof t=="number"||typeof t=="boolean")&&(t=String(t)),t?Array.isArray(t)?t.map(r=>`${wi(e)}=${vn(r)}`).join("&"):`${wi(e)}=${vn(t)}`:wi(e)}function Vm(e){return Object.keys(e).filter(t=>e[t]!==void 0).map(t=>jm(t,e[t])).filter(Boolean).join("&")}const Gm=/^[\s\w\0+.-]{2,}:([/\\]{1,2})/,Hm=/^[\s\w\0+.-]{2,}:([/\\]{2})?/,Fm=/^([/\\]\s*){2,}[^/\\]/,Km=/^[\s\0]*(blob|data|javascript|vbscript):$/i,Qm=/\/$|\/\?|\/#/,Zm=/^\.?\//;function qn(e,t={}){return typeof t=="boolean"&&(t={acceptRelative:t}),t.strict?Gm.test(e):Hm.test(e)||(t.acceptRelative?Fm.test(e):!1)}function Gy(e){return!!e&&Km.test(e)}function xn(e="",t){return t?Qm.test(e):e.endsWith("/")}function jr(e="",t){if(!t)return(xn(e)?e.slice(0,-1):e)||"/";if(!xn(e,!0))return e||"/";let r=e,n="";const a=e.indexOf("#");a!==-1&&(r=e.slice(0,a),n=e.slice(a));const[i,...s]=r.split("?");return((i.endsWith("/")?i.slice(0,-1):i)||"/")+(s.length>0?`?${s.join("?")}`:"")+n}function Xm(e="",t){if(!t)return e.endsWith("/")?e:e+"/";if(xn(e,!0))return e||"/";let r=e,n="";const a=e.indexOf("#");if(a!==-1&&(r=e.slice(0,a),n=e.slice(a),!r))return n;const[i,...s]=r.split("?");return i+"/"+(s.length>0?`?${s.join("?")}`:"")+n}function Ym(e=""){return e.startsWith("/")}function Hy(e=""){return Ym(e)?e:"/"+e}function Fy(e,t){if(wd(t)||qn(e))return e;const r=jr(t);return e.startsWith(r)?e:eg(r,e)}function Ky(e,t){if(wd(t))return e;const r=jr(t);if(!e.startsWith(r))return e;const n=e.slice(r.length);return n[0]==="/"?n:"/"+n}function Qy(e,t){const r=tg(e),n={...qm(r.search),...t};return r.search=Vm(n),rg(r)}function wd(e){return!e||e==="/"}function Jm(e){return e&&e!=="/"}function eg(e,...t){let r=e||"";for(const n of t.filter(a=>Jm(a)))if(r){const a=n.replace(Zm,"");r=Xm(r)+a}else r=n;return r}function $d(...e){var s,u,d,l;const t=/\/(?!\/)/,r=e.filter(Boolean),n=[];let a=0;for(const c of r)if(!(!c||c==="/")){for(const[f,h]of c.split(t).entries())if(!(!h||h===".")){if(h===".."){if(n.length===1&&qn(n[0]))continue;n.pop(),a--;continue}if(f===1&&((s=n[n.length-1])!=null&&s.endsWith(":/"))){n[n.length-1]+="/"+h;continue}n.push(h),a++}}let i=n.join("/");return a>=0?(u=r[0])!=null&&u.startsWith("/")&&!i.startsWith("/")?i="/"+i:(d=r[0])!=null&&d.startsWith("./")&&!i.startsWith("./")&&(i="./"+i):i="../".repeat(-1*a)+i,(l=r[r.length-1])!=null&&l.endsWith("/")&&!i.endsWith("/")&&(i+="/"),i}function Zy(e,t){return qr(jr(e))===qr(jr(t))}const vd=Symbol.for("ufo:protocolRelative");function tg(e="",t){const r=e.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);if(r){const[,f,h=""]=r;return{protocol:f.toLowerCase(),pathname:h,href:f+h,auth:"",host:"",search:"",hash:""}}if(!qn(e,{acceptRelative:!0}))return Bs(e);const[,n="",a,i=""]=e.replace(/\\/g,"/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/)||[];let[,s="",u=""]=i.match(/([^#/?]*)(.*)?/)||[];n==="file:"&&(u=u.replace(/\/(?=[A-Za-z]:)/,""));const{pathname:d,search:l,hash:c}=Bs(u);return{protocol:n.toLowerCase(),auth:a?a.slice(0,Math.max(0,a.length-1)):"",host:s,pathname:d,search:l,hash:c,[vd]:!n}}function Bs(e=""){const[t="",r="",n=""]=(e.match(/([^#?]*)(\?[^#]*)?(#.*)?/)||[]).splice(1);return{pathname:t,search:r,hash:n}}function rg(e){const t=e.pathname||"",r=e.search?(e.search.startsWith("?")?"":"?")+e.search:"",n=e.hash||"",a=e.auth?e.auth+"@":"",i=e.host||"";return(e.protocol||e[vd]?(e.protocol||"")+"//":"")+a+i+t+r+n}const ig=()=>{var e;return((e=window==null?void 0:window.__NUXT__)==null?void 0:e.config)||{}},Vr=ig().app,Xy=()=>Vr.baseURL,ng=()=>Vr.buildAssetsDir,ag=(...e)=>$d(xd(),ng(),...e),xd=(...e)=>{const t=Vr.cdnURL||Vr.baseURL;return e.length?$d(t,...e):t};globalThis.__buildAssetsURL=ag,globalThis.__publicAssetsURL=xd;const Pr=new Map,St=[],sg=(e,t,r)=>{if(t&&typeof t.init=="function"&&typeof t.createInferenceSessionHandler=="function"){const n=Pr.get(e);if(n===void 0)Pr.set(e,{backend:t,priority:r});else{if(n.priority>r)return;if(n.priority===r&&n.backend!==t)throw new Error(`cannot register backend "${e}" using priority ${r}`)}if(r>=0){const a=St.indexOf(e);a!==-1&&St.splice(a,1);for(let i=0;i<St.length;i++)if(Pr.get(St[i]).priority<=r){St.splice(i,0,e);return}St.push(e)}return}throw new TypeError("not a valid backend")},og=async e=>{const t=Pr.get(e);if(!t)return"backend not found.";if(t.initialized)return t.backend;if(t.aborted)return t.error;{const r=!!t.initPromise;try{return r||(t.initPromise=t.backend.init(e)),await t.initPromise,t.initialized=!0,t.backend}catch(n){return r||(t.error=`${n}`,t.aborted=!0),t.error}finally{delete t.initPromise}}},ug=async e=>{const t=e.executionProviders||[],r=t.map(d=>typeof d=="string"?d:d.name),n=r.length===0?St:r;let a;const i=[],s=new Set;for(const d of n){const l=await og(d);typeof l=="string"?i.push({name:d,err:l}):(a||(a=l),a===l&&s.add(d))}if(!a)throw new Error(`no available backend found. ERR: ${i.map(d=>`[${d.name}] ${d.err}`).join(", ")}`);for(const{name:d,err:l}of i)r.includes(d)&&console.warn(`removing requested execution provider "${d}" from session options because it is not available: ${l}`);const u=t.filter(d=>s.has(typeof d=="string"?d:d.name));return[a,new Proxy(e,{get:(d,l)=>l==="executionProviders"?u:Reflect.get(d,l)})]},lg="1.21.0";let Ds="warning";const Ke={wasm:{},webgl:{},webgpu:{},versions:{common:lg},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}`);Ds=e}},get logLevel(){return Ds}};Object.defineProperty(Ke,"logLevel",{enumerable:!0});const dg=Ke,pg=(e,t)=>{const r=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);r.width=e.dims[3],r.height=e.dims[2];const n=r.getContext("2d");if(n!=null){let a,i;(t==null?void 0:t.tensorLayout)!==void 0&&t.tensorLayout==="NHWC"?(a=e.dims[2],i=e.dims[3]):(a=e.dims[3],i=e.dims[2]);const s=(t==null?void 0:t.format)!==void 0?t.format:"RGB",u=t==null?void 0:t.norm;let d,l;u===void 0||u.mean===void 0?d=[255,255,255,255]:typeof u.mean=="number"?d=[u.mean,u.mean,u.mean,u.mean]:(d=[u.mean[0],u.mean[1],u.mean[2],0],u.mean[3]!==void 0&&(d[3]=u.mean[3])),u===void 0||u.bias===void 0?l=[0,0,0,0]:typeof u.bias=="number"?l=[u.bias,u.bias,u.bias,u.bias]:(l=[u.bias[0],u.bias[1],u.bias[2],0],u.bias[3]!==void 0&&(l[3]=u.bias[3]));const c=i*a;let f=0,h=c,g=c*2,y=-1;s==="RGBA"?(f=0,h=c,g=c*2,y=c*3):s==="RGB"?(f=0,h=c,g=c*2):s==="RBG"&&(f=0,g=c,h=c*2);for(let b=0;b<i;b++)for(let x=0;x<a;x++){const $=(e.data[f++]-l[0])*d[0],w=(e.data[h++]-l[1])*d[1],S=(e.data[g++]-l[2])*d[2],T=y===-1?255:(e.data[y++]-l[3])*d[3];n.fillStyle="rgba("+$+","+w+","+S+","+T+")",n.fillRect(x,b,1,1)}if("toDataURL"in r)return r.toDataURL();throw new Error("toDataURL is not supported")}else throw new Error("Can not access image data")},cg=(e,t)=>{const r=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d");let n;if(r!=null){let a,i,s;(t==null?void 0:t.tensorLayout)!==void 0&&t.tensorLayout==="NHWC"?(a=e.dims[2],i=e.dims[1],s=e.dims[3]):(a=e.dims[3],i=e.dims[2],s=e.dims[1]);const u=t!==void 0&&t.format!==void 0?t.format:"RGB",d=t==null?void 0:t.norm;let l,c;d===void 0||d.mean===void 0?l=[255,255,255,255]:typeof d.mean=="number"?l=[d.mean,d.mean,d.mean,d.mean]:(l=[d.mean[0],d.mean[1],d.mean[2],255],d.mean[3]!==void 0&&(l[3]=d.mean[3])),d===void 0||d.bias===void 0?c=[0,0,0,0]:typeof d.bias=="number"?c=[d.bias,d.bias,d.bias,d.bias]:(c=[d.bias[0],d.bias[1],d.bias[2],0],d.bias[3]!==void 0&&(c[3]=d.bias[3]));const f=i*a;if(t!==void 0&&(t.format!==void 0&&s===4&&t.format!=="RGBA"||s===3&&t.format!=="RGB"&&t.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");const h=4;let g=0,y=1,b=2,x=3,$=0,w=f,S=f*2,T=-1;u==="RGBA"?($=0,w=f,S=f*2,T=f*3):u==="RGB"?($=0,w=f,S=f*2):u==="RBG"&&($=0,S=f,w=f*2),n=r.createImageData(a,i);for(let I=0;I<i*a;g+=h,y+=h,b+=h,x+=h,I++)n.data[g]=(e.data[$++]-c[0])*l[0],n.data[y]=(e.data[w++]-c[1])*l[1],n.data[b]=(e.data[S++]-c[2])*l[2],n.data[x]=T===-1?255:(e.data[T++]-c[3])*l[3]}else throw new Error("Can not access image data");return n},$i=(e,t)=>{if(e===void 0)throw new Error("Image buffer must be defined");if(t.height===void 0||t.width===void 0)throw new Error("Image height and width must be defined");if(t.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");const{height:r,width:n}=t,a=t.norm??{mean:255,bias:0};let i,s;typeof a.mean=="number"?i=[a.mean,a.mean,a.mean,a.mean]:i=[a.mean[0],a.mean[1],a.mean[2],a.mean[3]??255],typeof a.bias=="number"?s=[a.bias,a.bias,a.bias,a.bias]:s=[a.bias[0],a.bias[1],a.bias[2],a.bias[3]??0];const u=t.format!==void 0?t.format:"RGBA",d=t.tensorFormat!==void 0&&t.tensorFormat!==void 0?t.tensorFormat:"RGB",l=r*n,c=d==="RGBA"?new Float32Array(l*4):new Float32Array(l*3);let f=4,h=0,g=1,y=2,b=3,x=0,$=l,w=l*2,S=-1;u==="RGB"&&(f=3,h=0,g=1,y=2,b=-1),d==="RGBA"?S=l*3:d==="RBG"?(x=0,w=l,$=l*2):d==="BGR"&&(w=0,$=l,x=l*2);for(let I=0;I<l;I++,h+=f,y+=f,g+=f,b+=f)c[x++]=(e[h]+s[0])/i[0],c[$++]=(e[g]+s[1])/i[1],c[w++]=(e[y]+s[2])/i[2],S!==-1&&b!==-1&&(c[S++]=(e[b]+s[3])/i[3]);return d==="RGBA"?new Ue("float32",c,[1,4,r,n]):new Ue("float32",c,[1,3,r,n])},fg=async(e,t)=>{const r=typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement,n=typeof ImageData<"u"&&e instanceof ImageData,a=typeof ImageBitmap<"u"&&e instanceof ImageBitmap,i=typeof e=="string";let s,u=t??{};const d=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},l=c=>typeof HTMLCanvasElement<"u"&&c instanceof HTMLCanvasElement||c instanceof OffscreenCanvas?c.getContext("2d"):null;if(r){const c=d();c.width=e.width,c.height=e.height;const f=l(c);if(f!=null){let h=e.height,g=e.width;if(t!==void 0&&t.resizedHeight!==void 0&&t.resizedWidth!==void 0&&(h=t.resizedHeight,g=t.resizedWidth),t!==void 0){if(u=t,t.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");u.tensorFormat="RGBA",u.height=h,u.width=g}else u.tensorFormat="RGBA",u.height=h,u.width=g;f.drawImage(e,0,0),s=f.getImageData(0,0,g,h).data}else throw new Error("Can not access image data")}else if(n){let c,f;if(t!==void 0&&t.resizedWidth!==void 0&&t.resizedHeight!==void 0?(c=t.resizedHeight,f=t.resizedWidth):(c=e.height,f=e.width),t!==void 0&&(u=t),u.format="RGBA",u.height=c,u.width=f,t!==void 0){const h=d();h.width=f,h.height=c;const g=l(h);if(g!=null)g.putImageData(e,0,0),s=g.getImageData(0,0,f,c).data;else throw new Error("Can not access image data")}else s=e.data}else if(a){if(t===void 0)throw new Error("Please provide image config with format for Imagebitmap");const c=d();c.width=e.width,c.height=e.height;const f=l(c);if(f!=null){const h=e.height,g=e.width;return f.drawImage(e,0,0,g,h),s=f.getImageData(0,0,g,h).data,u.height=h,u.width=g,$i(s,u)}else throw new Error("Can not access image data")}else{if(i)return new Promise((c,f)=>{const h=d(),g=l(h);if(!e||!g)return f();const y=new Image;y.crossOrigin="Anonymous",y.src=e,y.onload=()=>{h.width=y.width,h.height=y.height,g.drawImage(y,0,0,h.width,h.height);const b=g.getImageData(0,0,h.width,h.height);u.height=h.height,u.width=h.width,c($i(b.data,u))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(s!==void 0)return $i(s,u);throw new Error("Input data provided is not supported - aborted tensor creation")},hg=(e,t)=>{const{width:r,height:n,download:a,dispose:i}=t,s=[1,n,r,4];return new Ue({location:"texture",type:"float32",texture:e,dims:s,download:a,dispose:i})},mg=(e,t)=>{const{dataType:r,dims:n,download:a,dispose:i}=t;return new Ue({location:"gpu-buffer",type:r??"float32",gpuBuffer:e,dims:n,download:a,dispose:i})},gg=(e,t)=>{const{dataType:r,dims:n,download:a,dispose:i}=t;return new Ue({location:"ml-tensor",type:r??"float32",mlTensor:e,dims:n,download:a,dispose:i})},yg=(e,t,r)=>new Ue({location:"cpu-pinned",type:e,data:t,dims:r??[t.length]}),Ut=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),Ur=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]);let Ns=!1;const _g=()=>{if(!Ns){Ns=!0;const e=typeof BigInt64Array<"u"&&BigInt64Array.from,t=typeof BigUint64Array<"u"&&BigUint64Array.from,r=globalThis.Float16Array,n=typeof r<"u"&&r.from;e&&(Ut.set("int64",BigInt64Array),Ur.set(BigInt64Array,"int64")),t&&(Ut.set("uint64",BigUint64Array),Ur.set(BigUint64Array,"uint64")),n?(Ut.set("float16",r),Ur.set(r,"float16")):Ut.set("float16",Uint16Array)}},bg=e=>{let t=1;for(let r=0;r<e.length;r++){const n=e[r];if(typeof n!="number"||!Number.isSafeInteger(n))throw new TypeError(`dims[${r}] must be an integer, got: ${n}`);if(n<0)throw new RangeError(`dims[${r}] must be a non-negative integer, got: ${n}`);t*=n}return t},wg=(e,t)=>{switch(e.location){case"cpu":return new Ue(e.type,e.data,t);case"cpu-pinned":return new Ue({location:"cpu-pinned",data:e.data,type:e.type,dims:t});case"texture":return new Ue({location:"texture",texture:e.texture,type:e.type,dims:t});case"gpu-buffer":return new Ue({location:"gpu-buffer",gpuBuffer:e.gpuBuffer,type:e.type,dims:t});case"ml-tensor":return new Ue({location:"ml-tensor",mlTensor:e.mlTensor,type:e.type,dims:t});default:throw new Error(`tensorReshape: tensor location ${e.location} is not supported`)}};let Ue=class{constructor(t,r,n){_g();let a,i;if(typeof t=="object"&&"location"in t)switch(this.dataLocation=t.location,a=t.type,i=t.dims,t.location){case"cpu-pinned":{const u=Ut.get(a);if(!u)throw new TypeError(`unsupported type "${a}" to create tensor from pinned buffer`);if(!(t.data instanceof u))throw new TypeError(`buffer should be of type ${u.name}`);this.cpuData=t.data;break}case"texture":{if(a!=="float32")throw new TypeError(`unsupported type "${a}" to create tensor from texture`);this.gpuTextureData=t.texture,this.downloader=t.download,this.disposer=t.dispose;break}case"gpu-buffer":{if(a!=="float32"&&a!=="float16"&&a!=="int32"&&a!=="int64"&&a!=="uint32"&&a!=="uint8"&&a!=="bool"&&a!=="uint4"&&a!=="int4")throw new TypeError(`unsupported type "${a}" to create tensor from gpu buffer`);this.gpuBufferData=t.gpuBuffer,this.downloader=t.download,this.disposer=t.dispose;break}case"ml-tensor":{if(a!=="float32"&&a!=="float16"&&a!=="int32"&&a!=="int64"&&a!=="uint32"&&a!=="uint64"&&a!=="int8"&&a!=="uint8"&&a!=="bool"&&a!=="uint4"&&a!=="int4")throw new TypeError(`unsupported type "${a}" to create tensor from MLTensor`);this.mlTensorData=t.mlTensor,this.downloader=t.download,this.disposer=t.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let u,d;if(typeof t=="string")if(a=t,d=n,t==="string"){if(!Array.isArray(r))throw new TypeError("A string tensor's data must be a string array.");u=r}else{const l=Ut.get(t);if(l===void 0)throw new TypeError(`Unsupported tensor type: ${t}.`);if(Array.isArray(r)){if(t==="float16"&&l===Uint16Array||t==="uint4"||t==="int4")throw new TypeError(`Creating a ${t} tensor from number array is not supported. Please use ${l.name} as data.`);t==="uint64"||t==="int64"?u=l.from(r,BigInt):u=l.from(r)}else if(r instanceof l)u=r;else if(r instanceof Uint8ClampedArray)if(t==="uint8")u=Uint8Array.from(r);else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else if(t==="float16"&&r instanceof Uint16Array&&l!==Uint16Array)u=new globalThis.Float16Array(r.buffer,r.byteOffset,r.length);else throw new TypeError(`A ${a} tensor's data must be type of ${l}`)}else if(d=r,Array.isArray(t)){if(t.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");const l=typeof t[0];if(l==="string")a="string",u=t;else if(l==="boolean")a="bool",u=Uint8Array.from(t);else throw new TypeError(`Invalid element type of data array: ${l}.`)}else if(t instanceof Uint8ClampedArray)a="uint8",u=Uint8Array.from(t);else{const l=Ur.get(t.constructor);if(l===void 0)throw new TypeError(`Unsupported type for tensor data: ${t.constructor}.`);a=l,u=t}if(d===void 0)d=[u.length];else if(!Array.isArray(d))throw new TypeError("A tensor's dims must be a number array");i=d,this.cpuData=u,this.dataLocation="cpu"}const s=bg(i);if(this.cpuData&&s!==this.cpuData.length&&!((a==="uint4"||a==="int4")&&Math.ceil(s/2)===this.cpuData.length))throw new Error(`Tensor's size(${s}) does not match data length(${this.cpuData.length}).`);this.type=a,this.dims=i,this.size=s}static async fromImage(t,r){return fg(t,r)}static fromTexture(t,r){return hg(t,r)}static fromGpuBuffer(t,r){return mg(t,r)}static fromMLTensor(t,r){return gg(t,r)}static fromPinnedBuffer(t,r,n){return yg(t,r,n)}toDataURL(t){return pg(this,t)}toImageData(t){return cg(this,t)}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(t){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;const r=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=r,t&&this.disposer&&(this.disposer(),this.disposer=void 0),r}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(t){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return wg(this,t)}};const Mt=Ue,Td=(e,t)=>{(typeof Ke.trace>"u"?!Ke.wasm.trace:!Ke.trace)||console.timeStamp(`${e}::ORT::${t}`)},Sd=(e,t)=>{var a;const r=((a=new Error().stack)==null?void 0:a.split(/\r\n|\r|\n/g))||[];let n=!1;for(let i=0;i<r.length;i++){if(n&&!r[i].includes("TRACE_FUNC")){let s=`FUNC_${e}::${r[i].trim().split(" ")[1]}`;t&&(s+=`::${t}`),Td("CPU",s);return}r[i].includes("TRACE_FUNC")&&(n=!0)}},Tn=e=>{(typeof Ke.trace>"u"?!Ke.wasm.trace:!Ke.trace)||Sd("BEGIN",e)},Sn=e=>{(typeof Ke.trace>"u"?!Ke.wasm.trace:!Ke.trace)||Sd("END",e)};let $g=class Id{constructor(t){this.handler=t}async run(t,r,n){Tn();const a={};let i={};if(typeof t!="object"||t===null||t instanceof Mt||Array.isArray(t))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let s=!0;if(typeof r=="object"){if(r===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(r instanceof Mt)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(r)){if(r.length===0)throw new TypeError("'fetches' cannot be an empty array.");s=!1;for(const l of r){if(typeof l!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(l)===-1)throw new RangeError(`'fetches' contains invalid output name: ${l}.`);a[l]=null}if(typeof n=="object"&&n!==null)i=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else{let l=!1;const c=Object.getOwnPropertyNames(r);for(const f of this.outputNames)if(c.indexOf(f)!==-1){const h=r[f];(h===null||h instanceof Mt)&&(l=!0,s=!1,a[f]=h)}if(l){if(typeof n=="object"&&n!==null)i=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else i=r}}else if(typeof r<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(const l of this.inputNames)if(typeof t[l]>"u")throw new Error(`input '${l}' is missing in 'feeds'.`);if(s)for(const l of this.outputNames)a[l]=null;const u=await this.handler.run(t,a,i),d={};for(const l in u)if(Object.hasOwnProperty.call(u,l)){const c=u[l];c instanceof Mt?d[l]=c:d[l]=new Mt(c.type,c.data,c.dims)}return Sn(),d}async release(){return this.handler.dispose()}static async create(t,r,n,a){Tn();let i,s={};if(typeof t=="string"){if(i=t,typeof r=="object"&&r!==null)s=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(t instanceof Uint8Array){if(i=t,typeof r=="object"&&r!==null)s=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(t instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&t instanceof SharedArrayBuffer){const c=t;let f=0,h=t.byteLength;if(typeof r=="object"&&r!==null)s=r;else if(typeof r=="number"){if(f=r,!Number.isSafeInteger(f))throw new RangeError("'byteOffset' must be an integer.");if(f<0||f>=c.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${c.byteLength}).`);if(h=t.byteLength-f,typeof n=="number"){if(h=n,!Number.isSafeInteger(h))throw new RangeError("'byteLength' must be an integer.");if(h<=0||f+h>c.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${c.byteLength-f}].`);if(typeof a=="object"&&a!==null)s=a;else if(typeof a<"u")throw new TypeError("'options' must be an object.")}else if(typeof n<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof r<"u")throw new TypeError("'options' must be an object.");i=new Uint8Array(c,f,h)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");const[u,d]=await ug(s),l=await u.createInferenceSessionHandler(i,d);return Sn(),new Id(l)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}};const vg=$g,Jy=Object.freeze(Object.defineProperty({__proto__:null,InferenceSession:vg,TRACE:Td,TRACE_FUNC_BEGIN:Tn,TRACE_FUNC_END:Sn,Tensor:Mt,env:dg,registerBackend:sg},Symbol.toStringTag,{value:"Module"}));var jn=Object.defineProperty,xg=Object.getOwnPropertyDescriptor,Tg=Object.getOwnPropertyNames,Sg=Object.prototype.hasOwnProperty,Ig=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),U=(e,t)=>()=>(e&&(t=e(e=0)),t),jt=(e,t)=>{for(var r in t)jn(e,r,{get:t[r],enumerable:!0})},Eg=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Tg(t))!Sg.call(e,a)&&a!==r&&jn(e,a,{get:()=>t[a],enumerable:!(n=xg(t,a))||n.enumerable});return e},dr=e=>Eg(jn({},"__esModule",{value:!0}),e),Qt,ft,kt,Ms,Ed,kd=U(()=>{Qt=new Map,ft=[],kt=(e,t,r)=>{if(t&&typeof t.init=="function"&&typeof t.createInferenceSessionHandler=="function"){let n=Qt.get(e);if(n===void 0)Qt.set(e,{backend:t,priority:r});else{if(n.priority>r)return;if(n.priority===r&&n.backend!==t)throw new Error(`cannot register backend "${e}" using priority ${r}`)}if(r>=0){let a=ft.indexOf(e);a!==-1&&ft.splice(a,1);for(let i=0;i<ft.length;i++)if(Qt.get(ft[i]).priority<=r){ft.splice(i,0,e);return}ft.push(e)}return}throw new TypeError("not a valid backend")},Ms=async e=>{let t=Qt.get(e);if(!t)return"backend not found.";if(t.initialized)return t.backend;if(t.aborted)return t.error;{let r=!!t.initPromise;try{return r||(t.initPromise=t.backend.init(e)),await t.initPromise,t.initialized=!0,t.backend}catch(n){return r||(t.error=`${n}`,t.aborted=!0),t.error}finally{delete t.initPromise}}},Ed=async e=>{let t=e.executionProviders||[],r=t.map(d=>typeof d=="string"?d:d.name),n=r.length===0?ft:r,a,i=[],s=new Set;for(let d of n){let l=await Ms(d);typeof l=="string"?i.push({name:d,err:l}):(a||(a=l),a===l&&s.add(d))}if(!a)throw new Error(`no available backend found. ERR: ${i.map(d=>`[${d.name}] ${d.err}`).join(", ")}`);for(let{name:d,err:l}of i)r.includes(d)&&console.warn(`removing requested execution provider "${d}" from session options because it is not available: ${l}`);let u=t.filter(d=>s.has(typeof d=="string"?d:d.name));return[a,new Proxy(e,{get:(d,l)=>l==="executionProviders"?u:Reflect.get(d,l)})]}}),kg=U(()=>{kd()}),Cd,Cg=U(()=>{Cd="1.22.0-dev.20250409-89f8206ba4"}),vi,Pe,zd=U(()=>{Cg(),vi="warning",Pe={wasm:{},webgl:{},webgpu:{},versions:{common:Cd},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}`);vi=e}},get logLevel(){return vi}},Object.defineProperty(Pe,"logLevel",{enumerable:!0})}),_e,zg=U(()=>{zd(),_e=Pe}),Ad,Od,Ag=U(()=>{Ad=(e,t)=>{let r=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);r.width=e.dims[3],r.height=e.dims[2];let n=r.getContext("2d");if(n!=null){let a,i;(t==null?void 0:t.tensorLayout)!==void 0&&t.tensorLayout==="NHWC"?(a=e.dims[2],i=e.dims[3]):(a=e.dims[3],i=e.dims[2]);let s=(t==null?void 0:t.format)!==void 0?t.format:"RGB",u=t==null?void 0:t.norm,d,l;u===void 0||u.mean===void 0?d=[255,255,255,255]:typeof u.mean=="number"?d=[u.mean,u.mean,u.mean,u.mean]:(d=[u.mean[0],u.mean[1],u.mean[2],0],u.mean[3]!==void 0&&(d[3]=u.mean[3])),u===void 0||u.bias===void 0?l=[0,0,0,0]:typeof u.bias=="number"?l=[u.bias,u.bias,u.bias,u.bias]:(l=[u.bias[0],u.bias[1],u.bias[2],0],u.bias[3]!==void 0&&(l[3]=u.bias[3]));let c=i*a,f=0,h=c,g=c*2,y=-1;s==="RGBA"?(f=0,h=c,g=c*2,y=c*3):s==="RGB"?(f=0,h=c,g=c*2):s==="RBG"&&(f=0,g=c,h=c*2);for(let b=0;b<i;b++)for(let x=0;x<a;x++){let $=(e.data[f++]-l[0])*d[0],w=(e.data[h++]-l[1])*d[1],S=(e.data[g++]-l[2])*d[2],T=y===-1?255:(e.data[y++]-l[3])*d[3];n.fillStyle="rgba("+$+","+w+","+S+","+T+")",n.fillRect(x,b,1,1)}if("toDataURL"in r)return r.toDataURL();throw new Error("toDataURL is not supported")}else throw new Error("Can not access image data")},Od=(e,t)=>{let r=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),n;if(r!=null){let a,i,s;(t==null?void 0:t.tensorLayout)!==void 0&&t.tensorLayout==="NHWC"?(a=e.dims[2],i=e.dims[1],s=e.dims[3]):(a=e.dims[3],i=e.dims[2],s=e.dims[1]);let u=t!==void 0&&t.format!==void 0?t.format:"RGB",d=t==null?void 0:t.norm,l,c;d===void 0||d.mean===void 0?l=[255,255,255,255]:typeof d.mean=="number"?l=[d.mean,d.mean,d.mean,d.mean]:(l=[d.mean[0],d.mean[1],d.mean[2],255],d.mean[3]!==void 0&&(l[3]=d.mean[3])),d===void 0||d.bias===void 0?c=[0,0,0,0]:typeof d.bias=="number"?c=[d.bias,d.bias,d.bias,d.bias]:(c=[d.bias[0],d.bias[1],d.bias[2],0],d.bias[3]!==void 0&&(c[3]=d.bias[3]));let f=i*a;if(t!==void 0&&(t.format!==void 0&&s===4&&t.format!=="RGBA"||s===3&&t.format!=="RGB"&&t.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let h=4,g=0,y=1,b=2,x=3,$=0,w=f,S=f*2,T=-1;u==="RGBA"?($=0,w=f,S=f*2,T=f*3):u==="RGB"?($=0,w=f,S=f*2):u==="RBG"&&($=0,S=f,w=f*2),n=r.createImageData(a,i);for(let I=0;I<i*a;g+=h,y+=h,b+=h,x+=h,I++)n.data[g]=(e.data[$++]-c[0])*l[0],n.data[y]=(e.data[w++]-c[1])*l[1],n.data[b]=(e.data[S++]-c[2])*l[2],n.data[x]=T===-1?255:(e.data[T++]-c[3])*l[3]}else throw new Error("Can not access image data");return n}}),Tr,Rd,Bd,Dd,Nd,Md,Og=U(()=>{Vn(),Tr=(e,t)=>{if(e===void 0)throw new Error("Image buffer must be defined");if(t.height===void 0||t.width===void 0)throw new Error("Image height and width must be defined");if(t.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:r,width:n}=t,a=t.norm??{mean:255,bias:0},i,s;typeof a.mean=="number"?i=[a.mean,a.mean,a.mean,a.mean]:i=[a.mean[0],a.mean[1],a.mean[2],a.mean[3]??255],typeof a.bias=="number"?s=[a.bias,a.bias,a.bias,a.bias]:s=[a.bias[0],a.bias[1],a.bias[2],a.bias[3]??0];let u=t.format!==void 0?t.format:"RGBA",d=t.tensorFormat!==void 0&&t.tensorFormat!==void 0?t.tensorFormat:"RGB",l=r*n,c=d==="RGBA"?new Float32Array(l*4):new Float32Array(l*3),f=4,h=0,g=1,y=2,b=3,x=0,$=l,w=l*2,S=-1;u==="RGB"&&(f=3,h=0,g=1,y=2,b=-1),d==="RGBA"?S=l*3:d==="RBG"?(x=0,w=l,$=l*2):d==="BGR"&&(w=0,$=l,x=l*2);for(let T=0;T<l;T++,h+=f,y+=f,g+=f,b+=f)c[x++]=(e[h]+s[0])/i[0],c[$++]=(e[g]+s[1])/i[1],c[w++]=(e[y]+s[2])/i[2],S!==-1&&b!==-1&&(c[S++]=(e[b]+s[3])/i[3]);return d==="RGBA"?new Be("float32",c,[1,4,r,n]):new Be("float32",c,[1,3,r,n])},Rd=async(e,t)=>{let r=typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement,n=typeof ImageData<"u"&&e instanceof ImageData,a=typeof ImageBitmap<"u"&&e instanceof ImageBitmap,i=typeof e=="string",s,u=t??{},d=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},l=c=>typeof HTMLCanvasElement<"u"&&c instanceof HTMLCanvasElement||c instanceof OffscreenCanvas?c.getContext("2d"):null;if(r){let c=d();c.width=e.width,c.height=e.height;let f=l(c);if(f!=null){let h=e.height,g=e.width;if(t!==void 0&&t.resizedHeight!==void 0&&t.resizedWidth!==void 0&&(h=t.resizedHeight,g=t.resizedWidth),t!==void 0){if(u=t,t.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");u.tensorFormat="RGBA",u.height=h,u.width=g}else u.tensorFormat="RGBA",u.height=h,u.width=g;f.drawImage(e,0,0),s=f.getImageData(0,0,g,h).data}else throw new Error("Can not access image data")}else if(n){let c,f;if(t!==void 0&&t.resizedWidth!==void 0&&t.resizedHeight!==void 0?(c=t.resizedHeight,f=t.resizedWidth):(c=e.height,f=e.width),t!==void 0&&(u=t),u.format="RGBA",u.height=c,u.width=f,t!==void 0){let h=d();h.width=f,h.height=c;let g=l(h);if(g!=null)g.putImageData(e,0,0),s=g.getImageData(0,0,f,c).data;else throw new Error("Can not access image data")}else s=e.data}else if(a){if(t===void 0)throw new Error("Please provide image config with format for Imagebitmap");let c=d();c.width=e.width,c.height=e.height;let f=l(c);if(f!=null){let h=e.height,g=e.width;return f.drawImage(e,0,0,g,h),s=f.getImageData(0,0,g,h).data,u.height=h,u.width=g,Tr(s,u)}else throw new Error("Can not access image data")}else{if(i)return new Promise((c,f)=>{let h=d(),g=l(h);if(!e||!g)return f();let y=new Image;y.crossOrigin="Anonymous",y.src=e,y.onload=()=>{h.width=y.width,h.height=y.height,g.drawImage(y,0,0,h.width,h.height);let b=g.getImageData(0,0,h.width,h.height);u.height=h.height,u.width=h.width,c(Tr(b.data,u))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(s!==void 0)return Tr(s,u);throw new Error("Input data provided is not supported - aborted tensor creation")},Bd=(e,t)=>{let{width:r,height:n,download:a,dispose:i}=t,s=[1,n,r,4];return new Be({location:"texture",type:"float32",texture:e,dims:s,download:a,dispose:i})},Dd=(e,t)=>{let{dataType:r,dims:n,download:a,dispose:i}=t;return new Be({location:"gpu-buffer",type:r??"float32",gpuBuffer:e,dims:n,download:a,dispose:i})},Nd=(e,t)=>{let{dataType:r,dims:n,download:a,dispose:i}=t;return new Be({location:"ml-tensor",type:r??"float32",mlTensor:e,dims:n,download:a,dispose:i})},Md=(e,t,r)=>new Be({location:"cpu-pinned",type:e,data:t,dims:r??[t.length]})}),It,ar,xi,Pd,Rg=U(()=>{It=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),ar=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),xi=!1,Pd=()=>{if(!xi){xi=!0;let e=typeof BigInt64Array<"u"&&BigInt64Array.from,t=typeof BigUint64Array<"u"&&BigUint64Array.from,r=globalThis.Float16Array,n=typeof r<"u"&&r.from;e&&(It.set("int64",BigInt64Array),ar.set(BigInt64Array,"int64")),t&&(It.set("uint64",BigUint64Array),ar.set(BigUint64Array,"uint64")),n?(It.set("float16",r),ar.set(r,"float16")):It.set("float16",Uint16Array)}}}),Ud,Ld,Bg=U(()=>{Vn(),Ud=e=>{let t=1;for(let r=0;r<e.length;r++){let n=e[r];if(typeof n!="number"||!Number.isSafeInteger(n))throw new TypeError(`dims[${r}] must be an integer, got: ${n}`);if(n<0)throw new RangeError(`dims[${r}] must be a non-negative integer, got: ${n}`);t*=n}return t},Ld=(e,t)=>{switch(e.location){case"cpu":return new Be(e.type,e.data,t);case"cpu-pinned":return new Be({location:"cpu-pinned",data:e.data,type:e.type,dims:t});case"texture":return new Be({location:"texture",texture:e.texture,type:e.type,dims:t});case"gpu-buffer":return new Be({location:"gpu-buffer",gpuBuffer:e.gpuBuffer,type:e.type,dims:t});case"ml-tensor":return new Be({location:"ml-tensor",mlTensor:e.mlTensor,type:e.type,dims:t});default:throw new Error(`tensorReshape: tensor location ${e.location} is not supported`)}}}),Be,Vn=U(()=>{Ag(),Og(),Rg(),Bg(),Be=class{constructor(e,t,r){Pd();let n,a;if(typeof e=="object"&&"location"in e)switch(this.dataLocation=e.location,n=e.type,a=e.dims,e.location){case"cpu-pinned":{let s=It.get(n);if(!s)throw new TypeError(`unsupported type "${n}" to create tensor from pinned buffer`);if(!(e.data instanceof s))throw new TypeError(`buffer should be of type ${s.name}`);this.cpuData=e.data;break}case"texture":{if(n!=="float32")throw new TypeError(`unsupported type "${n}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.dispose;break}case"gpu-buffer":{if(n!=="float32"&&n!=="float16"&&n!=="int32"&&n!=="int64"&&n!=="uint32"&&n!=="uint8"&&n!=="bool"&&n!=="uint4"&&n!=="int4")throw new TypeError(`unsupported type "${n}" to create tensor from gpu buffer`);this.gpuBufferData=e.gpuBuffer,this.downloader=e.download,this.disposer=e.dispose;break}case"ml-tensor":{if(n!=="float32"&&n!=="float16"&&n!=="int32"&&n!=="int64"&&n!=="uint32"&&n!=="uint64"&&n!=="int8"&&n!=="uint8"&&n!=="bool"&&n!=="uint4"&&n!=="int4")throw new TypeError(`unsupported type "${n}" 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 s,u;if(typeof e=="string")if(n=e,u=r,e==="string"){if(!Array.isArray(t))throw new TypeError("A string tensor's data must be a string array.");s=t}else{let d=It.get(e);if(d===void 0)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(t)){if(e==="float16"&&d===Uint16Array||e==="uint4"||e==="int4")throw new TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${d.name} as data.`);e==="uint64"||e==="int64"?s=d.from(t,BigInt):s=d.from(t)}else if(t instanceof d)s=t;else if(t instanceof Uint8ClampedArray)if(e==="uint8")s=Uint8Array.from(t);else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else if(e==="float16"&&t instanceof Uint16Array&&d!==Uint16Array)s=new globalThis.Float16Array(t.buffer,t.byteOffset,t.length);else throw new TypeError(`A ${n} tensor's data must be type of ${d}`)}else if(u=t,Array.isArray(e)){if(e.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let d=typeof e[0];if(d==="string")n="string",s=e;else if(d==="boolean")n="bool",s=Uint8Array.from(e);else throw new TypeError(`Invalid element type of data array: ${d}.`)}else if(e instanceof Uint8ClampedArray)n="uint8",s=Uint8Array.from(e);else{let d=ar.get(e.constructor);if(d===void 0)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);n=d,s=e}if(u===void 0)u=[s.length];else if(!Array.isArray(u))throw new TypeError("A tensor's dims must be a number array");a=u,this.cpuData=s,this.dataLocation="cpu"}let i=Ud(a);if(this.cpuData&&i!==this.cpuData.length&&!((n==="uint4"||n==="int4")&&Math.ceil(i/2)===this.cpuData.length))throw new Error(`Tensor's size(${i}) does not match data length(${this.cpuData.length}).`);this.type=n,this.dims=a,this.size=i}static async fromImage(e,t){return Rd(e,t)}static fromTexture(e,t){return Bd(e,t)}static fromGpuBuffer(e,t){return Dd(e,t)}static fromMLTensor(e,t){return Nd(e,t)}static fromPinnedBuffer(e,t,r){return Md(e,t,r)}toDataURL(e){return Ad(this,e)}toImageData(e){return Od(this,e)}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(e){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,e&&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(e){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return Ld(this,e)}}}),Fe,Wd=U(()=>{Vn(),Fe=Be}),pr,Ti,Qe,Le,qd=U(()=>{zd(),pr=(e,t)=>{(typeof Pe.trace>"u"?!Pe.wasm.trace:!Pe.trace)||console.timeStamp(`${e}::ORT::${t}`)},Ti=(e,t)=>{var a;let r=((a=new Error().stack)==null?void 0:a.split(/\r\n|\r|\n/g))||[],n=!1;for(let i=0;i<r.length;i++){if(n&&!r[i].includes("TRACE_FUNC")){let s=`FUNC_${e}::${r[i].trim().split(" ")[1]}`;t&&(s+=`::${t}`),pr("CPU",s);return}r[i].includes("TRACE_FUNC")&&(n=!0)}},Qe=e=>{(typeof Pe.trace>"u"?!Pe.wasm.trace:!Pe.trace)||Ti("BEGIN",e)},Le=e=>{(typeof Pe.trace>"u"?!Pe.wasm.trace:!Pe.trace)||Ti("END",e)}}),jd,Dg=U(()=>{kd(),Wd(),qd(),jd=class Vd{constructor(t){this.handler=t}async run(t,r,n){Qe();let a={},i={};if(typeof t!="object"||t===null||t instanceof Fe||Array.isArray(t))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let s=!0;if(typeof r=="object"){if(r===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(r instanceof Fe)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(r)){if(r.length===0)throw new TypeError("'fetches' cannot be an empty array.");s=!1;for(let l of r){if(typeof l!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(l)===-1)throw new RangeError(`'fetches' contains invalid output name: ${l}.`);a[l]=null}if(typeof n=="object"&&n!==null)i=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else{let l=!1,c=Object.getOwnPropertyNames(r);for(let f of this.outputNames)if(c.indexOf(f)!==-1){let h=r[f];(h===null||h instanceof Fe)&&(l=!0,s=!1,a[f]=h)}if(l){if(typeof n=="object"&&n!==null)i=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else i=r}}else if(typeof r<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let l of this.inputNames)if(typeof t[l]>"u")throw new Error(`input '${l}' is missing in 'feeds'.`);if(s)for(let l of this.outputNames)a[l]=null;let u=await this.handler.run(t,a,i),d={};for(let l in u)if(Object.hasOwnProperty.call(u,l)){let c=u[l];c instanceof Fe?d[l]=c:d[l]=new Fe(c.type,c.data,c.dims)}return Le(),d}async release(){return this.handler.dispose()}static async create(t,r,n,a){Qe();let i,s={};if(typeof t=="string"){if(i=t,typeof r=="object"&&r!==null)s=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(t instanceof Uint8Array){if(i=t,typeof r=="object"&&r!==null)s=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(t instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&t instanceof SharedArrayBuffer){let c=t,f=0,h=t.byteLength;if(typeof r=="object"&&r!==null)s=r;else if(typeof r=="number"){if(f=r,!Number.isSafeInteger(f))throw new RangeError("'byteOffset' must be an integer.");if(f<0||f>=c.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${c.byteLength}).`);if(h=t.byteLength-f,typeof n=="number"){if(h=n,!Number.isSafeInteger(h))throw new RangeError("'byteLength' must be an integer.");if(h<=0||f+h>c.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${c.byteLength-f}].`);if(typeof a=="object"&&a!==null)s=a;else if(typeof a<"u")throw new TypeError("'options' must be an object.")}else if(typeof n<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof r<"u")throw new TypeError("'options' must be an object.");i=new Uint8Array(c,f,h)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[u,d]=await Ed(s),l=await u.createInferenceSessionHandler(i,d);return Le(),new Vd(l)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}get inputMetadata(){return this.handler.inputMetadata}get outputMetadata(){return this.handler.outputMetadata}}}),Gn,Ng=U(()=>{Dg(),Gn=jd}),Mg=U(()=>{}),Pg=U(()=>{}),Ug=U(()=>{}),Lg=U(()=>{}),Gd={};jt(Gd,{InferenceSession:()=>Gn,TRACE:()=>pr,TRACE_FUNC_BEGIN:()=>Qe,TRACE_FUNC_END:()=>Le,Tensor:()=>Fe,env:()=>_e,registerBackend:()=>kt});var Ze=U(()=>{kg(),zg(),Ng(),Wd(),Mg(),Pg(),qd(),Ug(),Lg()}),Hn=U(()=>{}),Hd={};jt(Hd,{default:()=>Fd});var Si,Ii,Fd,Wg=U(()=>{var e;Jf(),Ot(),Fn(),Si="ort-wasm-proxy-worker",Ii=((e=globalThis.self)==null?void 0:e.name)===Si,Ii&&(self.onmessage=t=>{let{type:r,in:n}=t.data;try{switch(r){case"init-wasm":Kn(n.wasm).then(()=>{ca(n).then(()=>{postMessage({type:r})},a=>{postMessage({type:r,err:a})})},a=>{postMessage({type:r,err:a})});break;case"init-ep":{let{epName:a,env:i}=n;fa(i,a).then(()=>{postMessage({type:r})},s=>{postMessage({type:r,err:s})});break}case"copy-from":{let{buffer:a}=n,i=Xr(a);postMessage({type:r,out:i});break}case"create":{let{model:a,options:i}=n;ha(a,i).then(s=>{postMessage({type:r,out:s})},s=>{postMessage({type:r,err:s})});break}case"release":ma(n),postMessage({type:r});break;case"run":{let{sessionId:a,inputIndices:i,inputs:s,outputIndices:u,options:d}=n;ga(a,i,s,u,new Array(u.length).fill(null),d).then(l=>{l.some(c=>c[3]!=="cpu")?postMessage({type:r,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:r,out:l},_a([...s,...l]))},l=>{postMessage({type:r,err:l})});break}case"end-profiling":ya(n),postMessage({type:r});break;default:}}catch(a){postMessage({type:r,err:a})}}),Fd=Ii?null:t=>new Worker(t??Re,{type:"module",name:Si})}),Kd={};jt(Kd,{default:()=>Qd});var Ei,ki,Qd,Ps,qg=U(()=>{var e,t;ki=(Ei=import.meta.url,async function(r={}){var Os;var n,a,i=r,s=new Promise((o,p)=>{n=o,a=p}),u=typeof window=="object",d=typeof WorkerGlobalScope<"u",l=d&&((Os=self.name)==null?void 0:Os.startsWith("em-pthread"));i.mountExternalData=(o,p)=>{o.startsWith("./")&&(o=o.substring(2)),(i.Eb||(i.Eb=new Map)).set(o,p)},i.unmountExternalData=()=>{delete i.Eb};var c=globalThis.SharedArrayBuffer??new WebAssembly.Memory({initial:0,maximum:0,pc:!0}).buffer.constructor;let f=o=>async(...p)=>{var m;try{if(i.Fb)throw Error("Session already started");let _=i.Fb={dc:p[0],errors:[]},v=await o(...p);if(i.Fb!==_)throw Error("Session mismatch");(m=i.Jb)==null||m.flush();let E=_.errors;if(0<E.length){let R=await Promise.all(E);if(R=R.filter(M=>M),0<R.length)throw Error(R.join(` `))}return v}finally{i.Fb=null}};i.jsepInit=(o,p)=>{if(o==="webgpu"){[i.Jb,i.Ub,i.Yb,i.Kb,i.Xb,i.jb,i.Zb,i.ac,i.Vb,i.Wb,i.$b]=p;let m=i.Jb;i.jsepRegisterBuffer=(_,v,E,R)=>m.registerBuffer(_,v,E,R),i.jsepGetBuffer=_=>m.getBuffer(_),i.jsepCreateDownloader=(_,v,E)=>m.createDownloader(_,v,E),i.jsepOnCreateSession=_=>{m.onCreateSession(_)},i.jsepOnReleaseSession=_=>{m.onReleaseSession(_)},i.jsepOnRunStart=_=>m.onRunStart(_),i.bc=(_,v)=>{m.upload(_,v)}}else if(o==="webnn"){let m=p[0];[i.nc,i.Nb,i.webnnEnsureTensor,i.Ob,i.webnnDownloadTensor]=p.slice(1),i.webnnReleaseTensorId=i.Nb,i.webnnUploadTensor=i.Ob,i.webnnOnRunStart=_=>m.onRunStart(_),i.webnnOnRunEnd=m.onRunEnd.bind(m),i.webnnRegisterMLContext=(_,v)=>{m.registerMLContext(_,v)},i.webnnOnReleaseSession=_=>{m.onReleaseSession(_)},i.webnnCreateMLTensorDownloader=(_,v)=>m.createMLTensorDownloader(_,v),i.webnnRegisterMLTensor=(_,v,E,R)=>m.registerMLTensor(_,v,E,R),i.webnnCreateMLContext=_=>m.createMLContext(_),i.webnnRegisterMLConstant=(_,v,E,R,M,q)=>m.registerMLConstant(_,v,E,R,M,i.Eb,q),i.webnnRegisterGraphInput=m.registerGraphInput.bind(m),i.webnnIsGraphInput=m.isGraphInput.bind(m),i.webnnCreateTemporaryTensor=m.createTemporaryTensor.bind(m),i.webnnIsInt64Supported=m.isInt64Supported.bind(m)}};let h=()=>{let o=(p,m,_)=>(...v)=>{let E=Je,R=m==null?void 0:m();v=p(...v);let M=m==null?void 0:m();return R!==M&&(p=M,_(R),m=_=null),Je!=E?new Promise((q,K)=>{ci={resolve:q,reject:K}}):v};(()=>{for(let p of["_OrtAppendExecutionProvider","_OrtCreateSession","_OrtRun","_OrtRunWithBinding","_OrtBindInput"])i[p]=o(i[p],()=>i[p],m=>i[p]=m)})(),f!==void 0&&(i._OrtRun=f(i._OrtRun),i._OrtRunWithBinding=f(i._OrtRunWithBinding)),h=void 0};i.asyncInit=()=>{h==null||h()};var g,y,b=Object.assign({},i),x=(o,p)=>{throw p},$="";(u||d)&&(d?$=self.location.href:typeof document<"u"&&document.currentScript&&($=document.currentScript.src),Ei&&($=Ei),$=$.startsWith("blob:")?"":$.slice(0,$.replace(/[?#].*/,"").lastIndexOf("/")+1),d&&(y=o=>{var p=new XMLHttpRequest;return p.open("GET",o,!1),p.responseType="arraybuffer",p.send(null),new Uint8Array(p.response)}),g=async o=>{if(D(o))return new Promise((m,_)=>{var v=new XMLHttpRequest;v.open("GET",o,!0),v.responseType="arraybuffer",v.onload=()=>{v.status==200||v.status==0&&v.response?m(v.response):_(v.status)},v.onerror=_,v.send(null)});var p=await fetch(o,{credentials:"same-origin"});if(p.ok)return p.arrayBuffer();throw Error(p.status+" : "+p.url)});var w=console.log.bind(console),S=console.error.bind(console),T=w,I=S;Object.assign(i,b),b=null;var k,C,A,O,L,X,G,Z,oe,te,j,W,le,ee=i.wasmBinary,ne=!1,D=o=>o.startsWith("file://");function P(){return k.buffer!=O.buffer&&fe(),O}function V(){return k.buffer!=O.buffer&&fe(),L}function se(){return k.buffer!=O.buffer&&fe(),X}function Se(){return k.buffer!=O.buffer&&fe(),G}function N(){return k.buffer!=O.buffer&&fe(),Z}function me(){return k.buffer!=O.buffer&&fe(),oe}function Ne(){return k.buffer!=O.buffer&&fe(),te}function ze(){return k.buffer!=O.buffer&&fe(),le}if(l){let o=function(p){try{var m=p.data,_=m.Bb;if(_==="load"){let v=[];self.onmessage=E=>v.push(E),self.startWorker=()=>{postMessage({Bb:"loaded"});for(let E of v)o(E);self.onmessage=o};for(let E of m.Rb)i[E]&&!i[E].proxy||(i[E]=(...R)=>{postMessage({Bb:"callHandler",Qb:E,args:R})},E=="print"&&(T=i[E]),E=="printErr"&&(I=i[E]));k=m.kc,fe(),_t(m.lc)}else if(_==="run"){fh(m.Ab),gi(m.Ab,0,0,1,0,0),Ia(),di(m.Ab),xe||(ws(),xe=!0);try{hh(m.fc,m.Hb)}catch(v){if(v!="unwind")throw v}}else m.target!=="setimmediate"&&(_==="checkMailbox"?xe&&fr():_&&(I(`worker: received unknown command ${_}`),I(m)))}catch(v){throw $s(),v}};var _t,xe=!1;I=function(...p){p=p.join(" "),console.error(p)},s