PageSourceSearch

https://iwzero.me/assets/piper.worker-CiZZ5PCp.js

js iwzero.me collected 2026-10-09 04:53:22 UTC 54,245 bytes, 5 lines download raw bytes

vendor: 16,146 bytes, lines 1-5
1/*!
2 * ONNX Runtime Web v1.22.0-dev.20250409-89f8206ba4
3 * Copyright (c) Microsoft Corporation. All rights reserved.
4 * Licensed under the MIT License.
5 */var rt=Object.defineProperty,Dr=Object.getOwnPropertyDescriptor,Gr=Object.getOwnPropertyNames,Fr=Object.prototype.hasOwnProperty,jr=(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')}),v=(e,t)=>()=>(e&&(t=e(e=0)),t),nt=(e,t)=>{for(var r in t)rt(e,r,{get:t[r],enumerable:!0})},Wr=(e,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Gr(t))!Fr.call(e,n)&&n!==r&&rt(e,n,{get:()=>t[n],enumerable:!(a=Dr(t,n))||a.enumerable});return e},Vt=e=>Wr(rt({},"__esModule",{value:!0}),e),de,W,Le,Rt,Ht,zt=v(()=>{de=new Map,W=[],Le=(e,t,r)=>{if(t&&typeof t.init=="function"&&typeof t.createInferenceSessionHandler=="function"){let a=de.get(e);if(a===void 0)de.set(e,{backend:t,priority:r});else{if(a.priority>r)return;if(a.priority===r&&a.backend!==t)throw new Error(`cannot register backend "${e}" using priority ${r}`)}if(r>=0){let n=W.indexOf(e);n!==-1&&W.splice(n,1);for(let s=0;s<W.length;s++)if(de.get(W[s]).priority<=r){W.splice(s,0,e);return}W.push(e)}return}throw new TypeError("not a valid backend")},Rt=async e=>{let t=de.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(a){return r||(t.error=`${a}`,t.aborted=!0),t.error}finally{delete t.initPromise}}},Ht=async e=>{let t=e.executionProviders||[],r=t.map(i=>typeof i=="string"?i:i.name),a=r.length===0?W:r,n,s=[],o=new Set;for(let i of a){let u=await Rt(i);typeof u=="string"?s.push({name:i,err:u}):(n||(n=u),n===u&&o.add(i))}if(!n)throw new Error(`no available backend found. ERR: ${s.map(i=>`[${i.name}] ${i.err}`).join(", ")}`);for(let{name:i,err:u}of s)r.includes(i)&&console.warn(`removing requested execution provider "${i}" from session options because it is not available: ${u}`);let l=t.filter(i=>o.has(typeof i=="string"?i:i.name));return[n,new Proxy(e,{get:(i,u)=>u==="executionProviders"?l:Reflect.get(i,u)})]}}),Vr=v(()=>{zt()}),qt,Hr=v(()=>{qt="1.22.0-dev.20250409-89f8206ba4"}),Se,N,Zt=v(()=>{Hr(),Se="warning",N={wasm:{},webgl:{},webgpu:{},versions:{common:qt},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}`);Se=e}},get logLevel(){return Se}},Object.defineProperty(N,"logLevel",{enumerable:!0})}),E,zr=v(()=>{Zt(),E=N}),Jt,Kt,qr=v(()=>{Jt=(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 a=r.getContext("2d");if(a!=null){let n,s;(t==null?void 0:t.tensorLayout)!==void 0&&t.tensorLayout==="NHWC"?(n=e.dims[2],s=e.dims[3]):(n=e.dims[3],s=e.dims[2]);let o=(t==null?void 0:t.format)!==void 0?t.format:"RGB",l=t==null?void 0:t.norm,i,u;l===void 0||l.mean===void 0?i=[255,255,255,255]:typeof l.mean=="number"?i=[l.mean,l.mean,l.mean,l.mean]:(i=[l.mean[0],l.mean[1],l.mean[2],0],l.mean[3]!==void 0&&(i[3]=l.mean[3])),l===void 0||l.bias===void 0?u=[0,0,0,0]:typeof l.bias=="number"?u=[l.bias,l.bias,l.bias,l.bias]:(u=[l.bias[0],l.bias[1],l.bias[2],0],l.bias[3]!==void 0&&(u[3]=l.bias[3]));let f=s*n,d=0,c=f,p=f*2,h=-1;o==="RGBA"?(d=0,c=f,p=f*2,h=f*3):o==="RGB"?(d=0,c=f,p=f*2):o==="RBG"&&(d=0,p=f,c=f*2);for(let y=0;y<s;y++)for(let T=0;T<n;T++){let m=(e.data[d++]-u[0])*i[0],w=(e.data[c++]-u[1])*i[1],O=(e.data[p++]-u[2])*i[2],U=h===-1?255:(e.data[h++]-u[3])*i[3];a.fillStyle="rgba("+m+","+w+","+O+","+U+")",a.fillRect(T,y,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")},Kt=(e,t)=>{let r=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),a;if(r!=null){let n,s,o;(t==null?void 0:t.tensorLayout)!==void 0&&t.tensorLayout==="NHWC"?(n=e.dims[2],s=e.dims[1],o=e.dims[3]):(n=e.dims[3],s=e.dims[2],o=e.dims[1]);let l=t!==void 0&&t.format!==void 0?t.format:"RGB",i=t==null?void 0:t.norm,u,f;i===void 0||i.mean===void 0?u=[255,255,255,255]:typeof i.mean=="number"?u=[i.mean,i.mean,i.mean,i.mean]:(u=[i.mean[0],i.mean[1],i.mean[2],255],i.mean[3]!==void 0&&(u[3]=i.mean[3])),i===void 0||i.bias===void 0?f=[0,0,0,0]:typeof i.bias=="number"?f=[i.bias,i.bias,i.bias,i.bias]:(f=[i.bias[0],i.bias[1],i.bias[2],0],i.bias[3]!==void 0&&(f[3]=i.bias[3]));let d=s*n;if(t!==void 0&&(t.format!==void 0&&o===4&&t.format!=="RGBA"||o===3&&t.format!=="RGB"&&t.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let c=4,p=0,h=1,y=2,T=3,m=0,w=d,O=d*2,U=-1;l==="RGBA"?(m=0,w=d,O=d*2,U=d*3):l==="RGB"?(m=0,w=d,O=d*2):l==="RBG"&&(m=0,O=d,w=d*2),a=r.createImageData(n,s);for(let C=0;C<s*n;p+=c,h+=c,y+=c,T+=c,C++)a.data[p]=(e.data[m++]-f[0])*u[0],a.data[h]=(e.data[w++]-f[1])*u[1],a.data[y]=(e.data[O++]-f[2])*u[2],a.data[T]=U===-1?255:(e.data[U++]-f[3])*u[3]}else throw new Error("Can not access image data");return a}}),Ee,Qt,Yt,Xt,er,tr,Zr=v(()=>{at(),Ee=(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:a}=t,n=t.norm??{mean:255,bias:0},s,o;typeof n.mean=="number"?s=[n.mean,n.mean,n.mean,n.mean]:s=[n.mean[0],n.mean[1],n.mean[2],n.mean[3]??255],typeof n.bias=="number"?o=[n.bias,n.bias,n.bias,n.bias]:o=[n.bias[0],n.bias[1],n.bias[2],n.bias[3]??0];let l=t.format!==void 0?t.format:"RGBA",i=t.tensorFormat!==void 0&&t.tensorFormat!==void 0?t.tensorFormat:"RGB",u=r*a,f=i==="RGBA"?new Float32Array(u*4):new Float32Array(u*3),d=4,c=0,p=1,h=2,y=3,T=0,m=u,w=u*2,O=-1;l==="RGB"&&(d=3,c=0,p=1,h=2,y=-1),i==="RGBA"?O=u*3:i==="RBG"?(T=0,w=u,m=u*2):i==="BGR"&&(w=0,m=u,T=u*2);for(let U=0;U<u;U++,c+=d,h+=d,p+=d,y+=d)f[T++]=(e[c]+o[0])/s[0],f[m++]=(e[p]+o[1])/s[1],f[w++]=(e[h]+o[2])/s[2],O!==-1&&y!==-1&&(f[O++]=(e[y]+o[3])/s[3]);return i==="RGBA"?new S("float32",f,[1,4,r,a]):new S("float32",f,[1,3,r,a])},Qt=async(e,t)=>{let r=typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement,a=typeof ImageData<"u"&&e instanceof ImageData,n=typeof ImageBitmap<"u"&&e instanceof ImageBitmap,s=typeof e=="string",o,l=t??{},i=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},u=f=>typeof HTMLCanvasElement<"u"&&f instanceof HTMLCanvasElement||f instanceof OffscreenCanvas?f.getContext("2d"):null;if(r){let f=i();f.width=e.width,f.height=e.height;let d=u(f);if(d!=null){let c=e.height,p=e.width;if(t!==void 0&&t.resizedHeight!==void 0&&t.resizedWidth!==void 0&&(c=t.resizedHeight,p=t.resizedWidth),t!==void 0){if(l=t,t.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");l.tensorFormat="RGBA",l.height=c,l.width=p}else l.tensorFormat="RGBA",l.height=c,l.width=p;d.drawImage(e,0,0),o=d.getImageData(0,0,p,c).data}else throw new Error("Can not access image data")}else if(a){let f,d;if(t!==void 0&&t.resizedWidth!==void 0&&t.resizedHeight!==void 0?(f=t.resizedHeight,d=t.resizedWidth):(f=e.height,d=e.width),t!==void 0&&(l=t),l.format="RGBA",l.height=f,l.width=d,t!==void 0){let c=i();c.width=d,c.height=f;let p=u(c);if(p!=null)p.putImageData(e,0,0),o=p.getImageData(0,0,d,f).data;else throw new Error("Can not access image data")}else o=e.data}else if(n){if(t===void 0)throw new Error("Please provide image config with format for Imagebitmap");let f=i();f.width=e.width,f.height=e.height;let d=u(f);if(d!=null){let c=e.height,p=e.width;return d.drawImage(e,0,0,p,c),o=d.getImageData(0,0,p,c).data,l.height=c,l.width=p,Ee(o,l)}else throw new Error("Can not access image data")}else{if(s)return new Promise((f,d)=>{let c=i(),p=u(c);if(!e||!p)return d();let h=new Image;h.crossOrigin="Anonymous",h.src=e,h.onload=()=>{c.width=h.width,c.height=h.height,p.drawImage(h,0,0,c.width,c.height);let y=p.getImageData(0,0,c.width,c.height);l.height=c.height,l.width=c.width,f(Ee(y.data,l))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(o!==void 0)return Ee(o,l);throw new Error("Input data provided is not supported - aborted tensor creation")},Yt=(e,t)=>{let{width:r,height:a,download:n,dispose:s}=t,o=[1,a,r,4];return new S({location:"texture",type:"float32",texture:e,dims:o,download:n,dispose:s})},Xt=(e,t)=>{let{dataType:r,dims:a,download:n,dispose:s}=t;return new S({location:"gpu-buffer",type:r??"float32",gpuBuffer:e,dims:a,download:n,dispose:s})},er=(e,t)=>{let{dataType:r,dims:a,download:n,dispose:s}=t;return new S({location:"ml-tensor",type:r??"float32",mlTensor:e,dims:a,download:n,dispose:s})},tr=(e,t,r)=>new S({location:"cpu-pinned",type:e,data:t,dims:r??[t.length]})}),Y,me,Be,rr,Jr=v(()=>{Y=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),me=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),Be=!1,rr=()=>{if(!Be){Be=!0;let e=typeof BigInt64Array<"u"&&BigInt64Array.from,t=typeof BigUint64Array<"u"&&BigUint64Array.from,r=globalThis.Float16Array,a=typeof r<"u"&&r.from;e&&(Y.set("int64",BigInt64Array),me.set(BigInt64Array,"int64")),t&&(Y.set("uint64",BigUint64Array),me.set(BigUint64Array,"uint64")),a?(Y.set("float16",r),me.set(r,"float16")):Y.set("float16",Uint16Array)}}}),nr,ar,Kr=v(()=>{at(),nr=e=>{let t=1;for(let r=0;r<e.length;r++){let a=e[r];if(typeof a!="number"||!Number.isSafeInteger(a))throw new TypeError(`dims[${r}] must be an integer, got: ${a}`);if(a<0)throw new RangeError(`dims[${r}] must be a non-negative integer, got: ${a}`);t*=a}return t},ar=(e,t)=>{switch(e.location){case"cpu":return new S(e.type,e.data,t);case"cpu-pinned":return new S({location:"cpu-pinned",data:e.data,type:e.type,dims:t});case"texture":return new S({location:"texture",texture:e.texture,type:e.type,dims:t});case"gpu-buffer":return new S({location:"gpu-buffer",gpuBuffer:e.gpuBuffer,type:e.type,dims:t});case"ml-tensor":return new S({location:"ml-tensor",mlTensor:e.mlTensor,type:e.type,dims:t});default:throw new Error(`tensorReshape: tensor location ${e.location} is not supported`)}}}),S,at=v(()=>{qr(),Zr(),Jr(),Kr(),S=class{constructor(e,t,r){rr();let a,n;if(typeof e=="object"&&"location"in e)switch(this.dataLocation=e.location,a=e.type,n=e.dims,e.location){case"cpu-pinned":{let o=Y.get(a);if(!o)throw new TypeError(`unsupported type "${a}" to create tensor from pinned buffer`);if(!(e.data instanceof o))throw new TypeError(`buffer should be of type ${o.name}`);this.cpuData=e.data;break}case"texture":{if(a!=="float32")throw new TypeError(`unsupported type "${a}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.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=e.gpuBuffer,this.downloader=e.download,this.disposer=e.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=e.mlTensor,this.downloader=e.download,this.disposer=e.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let o,l;if(typeof e=="string")if(a=e,l=r,e==="string"){if(!Array.isArray(t))throw new TypeError("A string tensor's data must be a string array.");o=t}else{let i=Y.get(e);if(i===void 0)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(t)){if(e==="float16"&&i===Uint16Array||e==="uint4"||e==="int4")throw new TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${i.name} as data.`);e==="uint64"||e==="int64"?o=i.from(t,BigInt):o=i.from(t)}else if(t instanceof i)o=t;else if(t instanceof Uint8ClampedArray)if(e==="uint8")o=Uint8Array.from(t);else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else if(e==="float16"&&t instanceof Uint16Array&&i!==Uint16Array)o=new globalThis.Float16Array(t.buffer,t.byteOffset,t.length);else throw new TypeError(`A ${a} tensor's data must be type of ${i}`)}else if(l=t,Array.isArray(e)){if(e.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let i=typeof e[0];if(i==="string")a="string",o=e;else if(i==="boolean")a="bool",o=Uint8Array.from(e);else throw new TypeError(`Invalid element type of data array: ${i}.`)}else if(e instanceof Uint8ClampedArray)a="uint8",o=Uint8Array.from(e);else{let i=me.get(e.constructor);if(i===void 0)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);a=i,o=e}if(l===void 0)l=[o.length];else if(!Array.isArray(l))throw new TypeError("A tensor's dims must be a number array");n=l,this.cpuData=o,this.dataLocation="cpu"}let s=nr(n);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=n,this.size=s}static async fromImage(e,t){return Qt(e,t)}static fromTexture(e,t){return Yt(e,t)}static fromGpuBuffer(e,t){return Xt(e,t)}static fromMLTensor(e,t){return er(e,t)}static fromPinnedBuffer(e,t,r){return tr(e,t,r)}toDataURL(e){return Jt(this,e)}toImageData(e){return Kt(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 ar(this,e)}}}),$,or=v(()=>{at(),$=S}),Ye,ke,se,ie,sr=v(()=>{Zt(),Ye=(e,t)=>
5{(typeof N.trace>"u"?!N.wasm.trace:!N.trace)||console.timeStamp(`${e}::ORT::${t}`)},ke=(e,t)=>{var n;let r=((n=new Error().stack)==null?void 0:n.split(/\r\n|\r|\n/g))||[],a=!1;for(let s=0;s<r.length;s++){if(a&&!r[s].includes("TRACE_FUNC")){let o=`FUNC_${e}::${r[s].trim().split(" ")[1]}`;t&&(o+=`::${t}`),Ye("CPU",o);return}r[s].includes("TRACE_FUNC")&&(a=!0)}},se=e=>{(typeof N.trace>"u"?!N.wasm.trace:!N.trace)||ke("BEGIN",e)},ie=e=>{(typeof N.trace>"u"?!N.wasm.trace:!N.trace)||ke("END",e)}}),ir,Qr=v(()=>{zt(),or(),sr(),ir=class lr{constructor(t){this.handler=t}async run(t,r,a){se();let n={},s={};if(typeof t!="object"||t===null||t instanceof $||Array.isArray(t))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let o=!0;if(typeof r=="object"){if(r===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(r instanceof $)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.");o=!1;for(let u of r){if(typeof u!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(u)===-1)throw new RangeError(`'fetches' contains invalid output name: ${u}.`);n[u]=null}if(typeof a=="object"&&a!==null)s=a;else if(typeof a<"u")throw new TypeError("'options' must be an object.")}else{let u=!1,f=Object.getOwnPropertyNames(r);for(let d of this.outputNames)if(f.indexOf(d)!==-1){let c=r[d];(c===null||c instanceof $)&&(u=!0,o=!1,n[d]=c)}if(u){if(typeof a=="object"&&a!==null)s=a;else if(typeof a<"u")throw new TypeError("'options' must be an object.")}else s=r}}else if(typeof r<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let u of this.inputNames)if(typeof t[u]>"u")throw new Error(`input '${u}' is missing in 'feeds'.`);if(o)for(let u of this.outputNames)n[u]=null;let l=await this.handler.run(t,n,s),i={};for(let u in l)if(Object.hasOwnProperty.call(l,u)){let f=l[u];f instanceof $?i[u]=f:i[u]=new $(f.type,f.data,f.dims)}return ie(),i}async release(){return this.handler.dispose()}static async create(t,r,a,n){se();let s,o={};if(typeof t=="string"){if(s=t,typeof r=="object"&&r!==null)o=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(t instanceof Uint8Array){if(s=t,typeof r=="object"&&r!==null)o=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 f=t,d=0,c=t.byteLength;if(typeof r=="object"&&r!==null)o=r;else if(typeof r=="number"){if(d=r,!Number.isSafeInteger(d))throw new RangeError("'byteOffset' must be an integer.");if(d<0||d>=f.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${f.byteLength}).`);if(c=t.byteLength-d,typeof a=="number"){if(c=a,!Number.isSafeInteger(c))throw new RangeError("'byteLength' must be an integer.");if(c<=0||d+c>f.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${f.byteLength-d}].`);if(typeof n=="object"&&n!==null)o=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else if(typeof a<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof r<"u")throw new TypeError("'options' must be an object.");s=new Uint8Array(f,d,c)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[l,i]=await Ht(o),u=await l.createInferenceSessionHandler(s,i);return ie(),new lr(u)}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}}}),ot,Yr=v(()=>{Qr(),ot=ir}),Xr=v(()=>{}),en=v(()=>{}),tn=v(()=>{}),rn=v(()=>{}),nn={};nt(nn,{InferenceSession:()=>ot,TRACE:()=>Ye,TRACE_FUNC_BEGIN:()=>se,TRACE_FUNC_END:()=>ie,Tensor:()=>$,env:()=>E,registerBackend:()=>Le});var le=v(()=>{Vr(),zr(),Yr(),or(),Xr(),en(),sr(),tn(),rn()}),st=v(()=>{}),ur={};nt(ur,{default:()=>fr});var Ne,De,fr,an=v(()=>{var e;vr(),ue(),lt(),Ne="ort-wasm-proxy-worker",De=((e=globalThis.self)==null?void 0:e.name)===Ne,De&&(self.onmessage=t=>{let{type:r,in:a}=t.data;
5try{switch(r){case"init-wasm":ut(a.wasm).then(()=>{ht(a).then(()=>{postMessage({type:r})},n=>{postMessage({type:r,err:n})})},n=>{postMessage({type:r,err:n})});break;case"init-ep":{let{epName:n,env:s}=a;wt(s,n).then(()=>{postMessage({type:r})},o=>{postMessage({type:r,err:o})});break}case"copy-from":{let{buffer:n}=a,s=Pe(n);postMessage({type:r,out:s});break}case"create":{let{model:n,options:s}=a;mt(n,s).then(o=>{postMessage({type:r,out:o})},o=>{postMessage({type:r,err:o})});break}case"release":yt(a),postMessage({type:r});break;case"run":{let{sessionId:n,inputIndices:s,inputs:o,outputIndices:l,options:i}=a;gt(n,s,o,l,new Array(l.length).fill(null),i).then(u=>{u.some(f=>f[3]!=="cpu")?postMessage({type:r,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:r,out:u},vt([...o,...u]))},u=>{postMessage({type:r,err:u})});break}case"end-profiling":bt(a),postMessage({type:r});break;default:}}catch(n){postMessage({type:r,err:n})}}),fr=De?null:t=>new Worker(t??M,{type:"module",name:Ne})}),Ge,Ot,Ct,M,it,Te,xt,Ut,Fe,Lt,je,dr,We,cr,lt=v(()=>{st(),Ge=typeof location>"u"?void 0:location.origin,Ot=import.meta.url>"file:"&&import.meta.url<"file;",Ct=()=>{{if(Ot){let e=URL;return new URL(new e("ort.wasm.bundle.min.mjs",import.meta.url).href,Ge).href}return import.meta.url}},M=Ct(),it=()=>{if(M&&!M.startsWith("blob:"))return M.substring(0,M.lastIndexOf("/")+1)},Te=(e,t)=>
5{try{let r=t??M;return(r?new URL(e,r):new URL(e)).origin===Ge}catch{return!1}},xt=(e,t)=>{let r=t??M;try{return(r?new URL(e,r):new URL(e)).href}catch{return}},Ut=(e,t)=>`${t??"./"}${e}`,Fe=async e=>{let t=await(await fetch(e,{credentials:"same-origin"})).blob();return URL.createObjectURL(t)},Lt=async e=>(await import(e)).default,je=(an(),Vt(ur)).default,dr=async()=>{if(!M)throw new Error("Failed to load proxy worker: cannot determine the script source URL.");if(Te(M))return[void 0,je()];let e=await Fe(M);return[e,je(e)]},We=void 0,cr=async(e,t,r)=>{if(!e&&!t&&We&&M&&Te(M))return[void 0,We];{let a="ort-wasm-simd-threaded.mjs",n=e??xt(a,t),s=r&&n&&!Te(n,t),o=s?await Fe(n):n??Ut(a,t);return[s?o:void 0,await Lt(o)]}}}),Ve,Ae,ce,He,It,Pt,_t,ut,R,ue=v(()=>{lt(),Ae=!1,ce=!1,He=!1,It=()=>{if(typeof SharedArrayBuffer>"u")return!1;try{return typeof MessageChannel<"u"&&new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11]))}catch{return!1}},Pt=()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,30,1,28,0,65,0,253,15,253,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,253,186,1,26,11]))}catch{return!1}},_t=()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,19,1,17,0,65,1,253,15,65,2,253,15,65,3,253,15,253,147,2,11]))}catch{return!1}},ut=async e=>{if(Ae)return Promise.resolve();if(ce)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(He)throw new Error("previous call to 'initializeWebAssembly()' failed.");ce=!0;let t=e.initTimeout,r=e.numThreads;if(e.simd!==!1){if(e.simd==="relaxed"){if(!_t())throw new Error("Relaxed WebAssembly SIMD is not supported in the current environment.")}else if(!Pt())throw new Error("WebAssembly SIMD is not supported in the current environment.")}let a=It();r>1&&!a&&(typeof self<"u"&&!self.crossOriginIsolated&&console.warn("env.wasm.numThreads is set to "+r+", but this will not work unless you enable crossOriginIsolated mode. See https://web.dev/cross-origin-isolation-guide/ for more info."),console.warn("WebAssembly multi-threading is not supported in the current environment. Falling back to single-threading."),e.numThreads=r=1);let n=e.wasmPaths,s=typeof n=="string"?n:void 0,o=n==null?void 0:n.mjs,l=(o==null?void 0:o.href)??o,i=n==null?void 0:n.wasm,u=(i==null?void 0:i.href)??i,f=e.wasmBinary,[d,c]=await cr(l,s,r>1),p=!1,h=[];if(t>0&&h.push(new Promise(y=>{setTimeout(()=>{p=!0,y()},t)})),h.push(new Promise((y,T)=>{let m={numThreads:r};if(f)m.wasmBinary=f;else if(u||s)m.locateFile=w=>u??s+w;else if(l&&l.indexOf("blob:")!==0)m.locateFile=w=>new URL(w,l).href;else if(d){let w=it();w&&(m.locateFile=O=>w+O)}c(m).then(w=>{ce=!1,Ae=!0,Ve=w,y(),d&&URL.revokeObjectURL(d)},w=>{ce=!1,He=!0,T(w)})})),await Promise.race(h),p)throw new Error(`WebAssembly backend initializing failed due to timeout: ${t}ms`)},R=()=>{if(Ae&&Ve)return Ve;throw new Error("WebAssembly is not initialized yet.")}}),G,Ie,A,ft=v(()=>{ue(),G=(e,t)=>{let r=R(),a=r.lengthBytesUTF8(e)+1,n=r._malloc(a);return r.stringToUTF8(e,n,a),t.push(n),n},Ie=(e,t,r,a)=>{if(typeof e=="object"&&e!==null){if(r.has(e))throw new Error("Circular reference in options");r.add(e)}Object.entries(e).forEach(([n,s])=>{let o=t?t+n:n;if(typeof s=="object")Ie(s,o+".",r,a);else if(typeof s=="string"||typeof s=="number")a(o,s.toString());else if(typeof s=="boolean")a(o,s?"1":"0");else throw new Error(`Can't handle extra config type: ${typeof s}`)})},A=e=>{let t=R(),r=t.stackSave();try{let a=t.PTR_SIZE,n=t.stackAlloc(2*a);t._OrtGetLastError(n,n+a);let s=Number(t.getValue(n,a===4?"i32":"i64")),o=t.getValue(n+a,"*"),l=o?t.UTF8ToString(o):"";throw new Error(`${e} ERROR_CODE: ${s}, ERROR_MESSAGE: ${l}`)}finally{t.stackRestore(r)}}}),pr,on=v(()=>{ue(),ft(),pr=e=>{let t=R(),r=0,a=[],n=e||{};try{if((e==null?void 0:e.logSeverityLevel)===void 0)n.logSeverityLevel=2;else if(typeof e.logSeverityLevel!="number"||!Number.isInteger(e.logSeverityLevel)||e.logSeverityLevel<0||e.logSeverityLevel>
54)throw new Error(`log serverity level is not valid: ${e.logSeverityLevel}`);if((e==null?void 0:e.logVerbosityLevel)===void 0)n.logVerbosityLevel=0;else if(typeof e.logVerbosityLevel!="number"||!Number.isInteger(e.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${e.logVerbosityLevel}`);(e==null?void 0:e.terminate)===void 0&&(n.terminate=!1);let s=0;return(e==null?void 0:e.tag)!==void 0&&(s=G(e.tag,a)),r=t._OrtCreateRunOptions(n.logSeverityLevel,n.logVerbosityLevel,!!n.terminate,s),r===0&&A("Can't create run options."),(e==null?void 0:e.extra)!==void 0&&Ie(e.extra,"",new WeakSet,(o,l)=>{let i=G(o,a),u=G(l,a);t._OrtAddRunConfigEntry(r,i,u)!==0&&A(`Can't set a run config entry: ${o} - ${l}.`)}),[r,a]}catch(s){throw r!==0&&t._OrtReleaseRunOptions(r),a.forEach(o=>t._free(o)),s}}}),$t,Mt,St,pe,Bt,hr,sn=v(()=>{ue(),ft(),$t=e=>{switch(e){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${e}`)}},Mt=e=>{switch(e){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${e}`)}},St=e=>{e.extra||(e.extra={}),e.extra.session||(e.extra.session={});let t=e.extra.session;t.use_ort_model_bytes_directly||(t.use_ort_model_bytes_directly="1"),e.executionProviders&&e.executionProviders.some(r=>(typeof r=="string"?r:r.name)==="webgpu")&&(e.enableMemPattern=!1)},pe=(e,t,r,a)=>{let n=G(t,a),s=G(r,a);R()._OrtAddSessionConfigEntry(e,n,s)!==0&&A(`Can't set a session config entry: ${t} - ${r}.`)},Bt=async(e,t,r)=>{for(let a of t){let n=typeof a=="string"?a:a.name,s=[];switch(n){case"webnn":if(n="WEBNN",typeof a!="string"){let f=a==null?void 0:a.deviceType;f&&pe(e,"deviceType",f,r)}break;case"webgpu":if(n="JS",typeof a!="string"){let f=a;if(f!=null&&f.preferredLayout){if(f.preferredLayout!=="NCHW"&&f.preferredLayout!=="NHWC")throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${f.preferredLayout}`);pe(e,"preferredLayout",f.preferredLayout,r)}}break;case"wasm":case"cpu":continue;default:throw new Error(`not supported execution provider: ${n}`)}let o=G(n,r),l=s.length,i=0,u=0;if(l>0){i=R()._malloc(l*R().PTR_SIZE),r.push(i),u=R()._malloc(l*R().PTR_SIZE),r.push(u);for(let f=0;f<l;f++)R().setValue(i+f*R().PTR_SIZE,s[f][0],"*"),R().setValue(u+f*R().PTR_SIZE,s[f][1],"*")}await R()._OrtAppendExecutionProvider(e,o,i,u,l)!==0&&A(`Can't append execution provider: ${n}.`)}},hr=async e=>{let t=R(),r=0,a=[],n=e||{};St(n);try{let s=$t(n.graphOptimizationLevel??"all"),o=Mt(n.executionMode??"sequential"),l=typeof n.logId=="string"?G(n.logId,a):0,i=n.logSeverityLevel??2;if(!Number.isInteger(i)||i<0||i>4)throw new Error(`log serverity level is not valid: ${i}`);let u=n.logVerbosityLevel??0;if(!Number.isInteger(u)||u<0||u>4)throw new Error(`log verbosity level is not valid: ${u}`);let f=typeof n.optimizedModelFilePath=="string"?G(n.optimizedModelFilePath,a):0;if(r=t._OrtCreateSessionOptions(s,!!n.enableCpuMemArena,!!n.enableMemPattern,o,!!n.enableProfiling,0,l,i,u,f),r===0&&A("Can't create session options."),n.executionProviders&&await Bt(r,n.executionProviders,a),n.enableGraphCapture!==void 0){if(typeof n.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${n.enableGraphCapture}`);pe(r,"enableGraphCapture",n.enableGraphCapture.toString(),a)}if(n.freeDimensionOverrides)for(let[d,c]of Object.entries(n.freeDimensionOverrides)){if(typeof d!="string")throw new Error(`free dimension override name must be a string: ${d}`);if(typeof c!="number"||!Number.isInteger(c)||c<0)throw new Error(`free dimension override value must be a non-negative integer: ${c}`);let p=G(d,a);t._OrtAddFreeDimensionOverride(r,p,c)!==0&&A(`Can't set a free dimension override: ${d} - ${c}.`)}return n.extra!==void 0&&Ie(n.extra,"",new WeakSet,(d,c)=>{pe(r,d,c,a)}),[r,a]}catch(s){throw r!==0&&t._OrtReleaseSessionOptions(r)!==0&&A("Can't release session options."),a.forEach(o=>t._free(o)),s}}}),te,xe,re,wr,mr,dt,ct,yr,gr=v(()=>{te=e=>{switch(e){case"int8":return 3;case"uint8":return 2;case"bool":return 9;
vendor: 4,256 bytes, line 5
5case"int16":return 5;case"uint16":return 4;case"int32":return 6;case"uint32":return 12;case"float16":return 10;case"float32":return 1;case"float64":return 11;case"string":return 8;case"int64":return 7;case"uint64":return 13;case"int4":return 22;case"uint4":return 21;default:throw new Error(`unsupported data type: ${e}`)}},xe=e=>{switch(e){case 3:return"int8";case 2:return"uint8";case 9:return"bool";case 5:return"int16";case 4:return"uint16";case 6:return"int32";case 12:return"uint32";case 10:return"float16";case 1:return"float32";case 11:return"float64";case 8:return"string";case 7:return"int64";case 13:return"uint64";case 22:return"int4";case 21:return"uint4";default:throw new Error(`unsupported data type: ${e}`)}},re=(e,t)=>{let r=[-1,4,1,1,2,2,4,8,-1,1,2,8,4,8,-1,-1,-1,-1,-1,-1,-1,.5,.5][e],a=typeof t=="number"?t:t.reduce((n,s)=>n*s,1);return r>0?Math.ceil(a*r):void 0},wr=e=>{switch(e){case"float16":return typeof Float16Array<"u"&&Float16Array.from?Float16Array:Uint16Array;case"float32":return Float32Array;case"uint8":return Uint8Array;case"int8":return Int8Array;case"uint16":return Uint16Array;case"int16":return Int16Array;case"int32":return Int32Array;case"bool":return Uint8Array;case"float64":return Float64Array;case"uint32":return Uint32Array;case"int64":return BigInt64Array;case"uint64":return BigUint64Array;default:throw new Error(`unsupported type: ${e}`)}},mr=e=>{switch(e){case"verbose":return 0;case"info":return 1;case"warning":return 2;case"error":return 3;case"fatal":return 4;default:throw new Error(`unsupported logging level: ${e}`)}},dt=e=>e==="float32"||e==="float16"||e==="int32"||e==="int64"||e==="uint32"||e==="uint8"||e==="bool"||e==="uint4"||e==="int4",ct=e=>e==="float32"||e==="float16"||e==="int32"||e==="int64"||e==="uint32"||e==="uint64"||e==="int8"||e==="uint8"||e==="bool"||e==="uint4"||e==="int4",yr=e=>{switch(e){case"none":return 0;case"cpu":return 1;case"cpu-pinned":return 2;case"texture":return 3;case"gpu-buffer":return 4;case"ml-tensor":return 5;default:throw new Error(`unsupported data location: ${e}`)}}}),pt,br=v(()=>{st(),pt=async e=>{if(typeof e=="string"){let t=await fetch(e);if(!t.ok)throw new Error(`failed to load external data file: ${e}`);let r=t.headers.get("Content-Length"),a=r?parseInt(r,10):0;if(a<1073741824)return new Uint8Array(await t.arrayBuffer());{if(!t.body)throw new Error(`failed to load external data file: ${e}, no response body.`);let n=t.body.getReader(),s;try{s=new ArrayBuffer(a)}catch(l){if(l instanceof RangeError){let i=Math.ceil(a/65536);s=new WebAssembly.Memory({initial:i,maximum:i}).buffer}else throw l}let o=0;for(;;){let{done:l,value:i}=await n.read();if(l)break;let u=i.byteLength;new Uint8Array(s,o,u).set(i),o+=u}return new Uint8Array(s,0,a)}}else return e instanceof Blob?new Uint8Array(await e.arrayBuffer()):e instanceof Uint8Array?e:new Uint8Array(e)}}),kt,ht,wt,J,Nt,ze,Pe,mt,yt,qe,gt,bt,vt,vr=v(()=>{on(),sn(),gr(),ue(),ft(),br(),kt=(e,t)=>{R()._OrtInit(e,t)!==0&&A("Can't initialize onnxruntime.")},ht=async e=>{kt(e.wasm.numThreads,mr(e.logLevel))},wt=async(e,t)=>{var r,a;(a=(r=R()).asyncInit)==null||a.call(r)},J=new Map,Nt=e=>{let t=R(),r=t.stackSave();try{let a=t.PTR_SIZE,n=t.stackAlloc(2*a);t._OrtGetInputOutputCount(e,n,n+a)!==0&&A("Can't get session input/output count.");let s=a===4?"i32":"i64";return[Number(t.getValue(n,s)),Number(t.getValue(n+a,s))]}finally{t.stackRestore(r)}},ze=(e,t)=>{let r=R(),a=r.stackSave(),n=0;try{let s=r.PTR_SIZE,o=r.stackAlloc(2*s);r._OrtGetInputOutputMetadata(e,t,o,o+s)!==0&&A("Can't get session input/output metadata.");let l=Number(r.getValue(o,"*"));n=Number(r.getValue(o+s,"*"));let i=r.HEAP32[n/4];if(i===0)return[l,0];let u=r.HEAPU32[n/4+1],f=[];for(let d=0;d<u;d++){let c=Number(r.getValue(n+8+d*s,"*"));f.push(c!==0?r.UTF8ToString(c):Number(r.getValue(n+8+(d+u)*s,"*")))}return[l,i,f]}finally{r.stackRestore(a),n!==0&&r._OrtFree(n)}},Pe=e=>{let t=R(),r=t._malloc(e.byteLength);if(r===0)throw new Error(`Can't create a session. failed to allocate a buffer of size ${e.byteLength}.`);return t.HEAPU8.set(e,r),[r,e.byteLength]},mt=async(e,t)=>{var f,d,c;let r,a,n=R();Array.isArray(e)?[r,a]=e:e.buffer===n.HEAPU8.buffer?[r,a]=[e.byteOffset,e.byteLength]:[r,a]=Pe(e);let s=0,o=0,l=[],i=[],u=[];
5try{if([o,l]=await hr(t),(t==null?void 0:t.externalData)&&n.mountExternalData){let C=[];for(let g of t.externalData){let L=typeof g=="string"?g:g.path;C.push(pt(typeof g=="string"?g:g.data).then(B=>{n.mountExternalData(L,B)}))}await Promise.all(C)}for(let C of(t==null?void 0:t.executionProviders)??[])if((typeof C=="string"?C:C.name)==="webnn"){if(n.shouldTransferToMLTensor=!1,typeof C!="string"){let g=C,L=g==null?void 0:g.context,B=g==null?void 0:g.gpuDevice,k=g==null?void 0:g.deviceType,ge=g==null?void 0:g.powerPreference;L?n.currentContext=L:B?n.currentContext=await n.webnnCreateMLContext(B):n.currentContext=await n.webnnCreateMLContext({deviceType:k,powerPreference:ge})}else n.currentContext=await n.webnnCreateMLContext();break}s=await n._OrtCreateSession(r,a,o),(f=n.webgpuOnCreateSession)==null||f.call(n,s),s===0&&A("Can't create a session."),(d=n.jsepOnCreateSession)==null||d.call(n),n.currentContext&&(n.webnnRegisterMLContext(s,n.currentContext),n.currentContext=void 0,n.shouldTransferToMLTensor=!0);let[p,h]=Nt(s),y=!!(t!=null&&t.enableGraphCapture),T=[],m=[],w=[],O=[],U=[];for(let C=0;C<p;C++){let[g,L,B]=ze(s,C);g===0&&A("Can't get an input name."),i.push(g);let k=n.UTF8ToString(g);T.push(k),w.push(L===0?{name:k,isTensor:!1}:{name:k,isTensor:!0,type:xe(L),shape:B})}for(let C=0;C<h;C++){let[g,L,B]=ze(s,C+p);g===0&&A("Can't get an output name."),u.push(g);let k=n.UTF8ToString(g);m.push(k),O.push(L===0?{name:k,isTensor:!1}:{name:k,isTensor:!0,type:xe(L),shape:B})}return J.set(s,[s,i,u,null,y,!1]),[s,T,m,w,O]}catch(p){throw i.forEach(h=>n._OrtFree(h)),u.forEach(h=>n._OrtFree(h)),s!==0&&n._OrtReleaseSession(s)!==0&&A("Can't release session."),p}finally{n._free(r),o!==0&&n._OrtReleaseSessionOptions(o)!==0&&A("Can't release session options."),l.forEach(p=>n._free(p)),(c=n.unmountExternalData)==null||c.call(n)}},yt=e=>{var i,u,f;let t=R(),r=J.get(e);if(!r)throw new Error(`cannot release session. invalid session id: ${e}`);let[a,n,s,o,l]=r;o&&(l&&t._OrtClearBoundOutputs(o.handle)!==0&&A("Can't clear bound outputs."),t._OrtReleaseBinding(o.handle)!==0&&A("Can't release IO binding.")),(i=t.jsepOnReleaseSession)==null||i.call(t,e),(u=t.webnnOnReleaseSession)==null||u.call(t,e),(f=t.webgpuOnReleaseSession)==null||f.call(t,e),n.forEach(d=>t._OrtFree(d)),s.forEach(d=>t._OrtFree(d)),t._OrtReleaseSession(a)!==0&&A("Can't release session."),J.delete(e)},qe=async(e,t,r,a,n,s,o=!1)=>{if(!e){t.push(0);return}let l=R(),i=l.PTR_SIZE,u=e[0],f=e[1],d=e[3],c=d,p,h;if(u==="string"&&(d==="gpu-buffer"||d==="ml-tensor"))throw new Error("String tensor is not supported on GPU.");if(o&&d!=="gpu-buffer")throw new Error(`External buffer must be provided for input/output index ${s} when enableGraphCapture is true.`);if(d==="gpu-buffer"){let m=e[2].gpuBuffer;h=re(te(u),f);{let w=l.jsepRegisterBuffer;if(!w)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');p=w(a,s,m,h)}}else if(d==="ml-tensor"){let m=e[2].mlTensor;h=re(te(u),f);let w=l.webnnRegisterMLTensor;if(!w)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');p=w(a,m,te(u),f)}else{let m=e[2];if(Array.isArray(m)){h=i*m.length,p=l._malloc(h),r.push(p);for(let w=0;w<m.length;w++){if(typeof m[w]!="string")throw new TypeError(`tensor data at index ${w} is not a string`);l.setValue(p+w*i,G(m[w],r),"*")}}else{let w=l.webnnIsGraphInput;if(u!=="string"&&w){let O=l.UTF8ToString(n);if(w(a,O)){let U=te(u);h=re(U,f),c="ml-tensor";let C=l.webnnCreateTemporaryTensor,g=l.webnnUploadTensor;if(!C||!g)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');let L=await C(a,U,f);g(L,new Uint8Array(m.buffer,m.byteOffset,m.byteLength)),p=L}else h=m.byteLength,p=l._malloc(h),r.push(p),l.HEAPU8.set(new Uint8Array(m.buffer,m.byteOffset,h),p)}else h=m.byteLength,p=l._malloc(h),r.push(p),l.HEAPU8.set(new Uint8Array(m.buffer,m.byteOffset,h),p)}}let y=l.stackSave(),T=l.stackAlloc(4*f.length);try{f.forEach((w,O)=>l.setValue(T+O*i,w,i===4?"i32":"i64"));let m=l._OrtCreateTensor(te(u),p,h,T,f.length,yr(c));m===0&&A(`Can't create tensor for input/output. session=${a}, index=${s}.`),t.push(m)}finally{l.stackRestore(y)}},gt=async(e,t,r,a,n,s)=>{var ge,Et,Tt;let o=R(),l=o.PTR_SIZE,i=J.get(e);if(!i)throw new Error(`cannot run inference. invalid session id: ${e}`);let u=i[0],f=i[1],d=i[2],c=i[3],p=i[4];i[5];let h=t.length,y=a.length,T=0,m=[],w=[],O=[],U=[],C=o.stackSave(),g=o.stackAlloc(h*l),L=o.stackAlloc(h*l),B=o.stackAlloc(y*l),k=o.stackAlloc(y*l);try{[T,m]=pr(s);for(let b=0;b<h;b++)await qe(r[b],w,U,e,f[t[b]],t[b],p);for(let b=0;b<y;b++)await qe(n[b],O,U,e,d[a[b]],h+a[b],p);for(let b=0;b<h;b++)o.setValue(g+b*l,w[b],"*"),o.setValue(L+b*l,f[t[b]],"*");for(let b=0;b<y;b++)o.setValue(B+b*l,O[b],"*"),o.setValue(k+b*l,d[a[b]],"*");(ge=o.jsepOnRunStart)==null||ge.call(o,u),(Et=o.webnnOnRunStart)==null||Et.call(o,u);let F;F=await o._OrtRun(u,L,g,h,k,y,B,T),F!==0&&A("failed to call OrtRun().");let X=[];for(let b=0;b<y;b++){let fe=Number(o.getValue(B+b*l,"*"));if(fe===O[b]){X.push(n[b]);continue}let Sr=o.stackSave(),j=o.stackAlloc(4*l),$e=!1,P,D=0;try{o._OrtGetTensorData(fe,j,j+l,j+2*l,j+3*l)!==0&&A(`Can't access output tensor data on index ${b}.`);let Me=l===4?"i32":"i64",be=Number(o.getValue(j,Me));D=o.getValue(j+l,"*");let At=o.getValue(j+l*2,"*"),Br=Number(o.getValue(j+l*3,Me)),z=[];for(let I=0;I<Br;I++)z.push(Number(o.getValue(At+I*l,Me)));o._OrtFree(At)!==0&&A("Can't free memory for tensor dims.");let q=z.reduce((I,x)=>I*x,1);P=xe(be);let ve=c==null?void 0:c.outputPreferredLocations[a[b]];if(P==="string"){if(ve==="gpu-buffer"||ve==="ml-tensor")throw new Error("String tensor is not supported on GPU.");let I=[];for(let x=0;x<q;x++){let Z=o.getValue(D+x*l,"*"),kr=o.getValue(D+(x+1)*l,"*"),Nr=x===q-1?void 0:kr-Z;I.push(o.UTF8ToString(Z,Nr))}X.push([P,z,I,"cpu"])}else if(ve==="gpu-buffer"&&q>0){let I=o.jsepGetBuffer;if(!I)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let x=I(D),Z=re(be,q);if(Z===void 0||!dt(P))throw new Error(`Unsupported data type: ${P}`);$e=!0,X.push([P,z,{gpuBuffer:x,download:o.jsepCreateDownloader(x,Z,P),dispose:()=>{o._OrtReleaseTensor(fe)!==0&&A("Can't release tensor.")}},"gpu-buffer"])}else if(ve==="ml-tensor"&&q>0){let I=o.webnnEnsureTensor,x=o.webnnIsInt64Supported;if(!I||!x)throw new Error('preferredLocation "ml-tensor" is not supported without using WebNN.');if(re(be,q)===void 0||!ct(P))throw new Error(`Unsupported data type: ${P}`);if(P==="int64"&&!x(e))throw new Error('preferredLocation "ml-tensor" for int64 output is not supported by current WebNN Context.');let Z=await I(e,D,be,z,!1);$e=!0,X.push([P,z,{mlTensor:Z,download:o.webnnCreateMLTensorDownloader(D,P),dispose:()=>{o.webnnReleaseTensorId(D),o._OrtReleaseTensor(fe)}},"ml-tensor"])}else{let I=wr(P),x=new I(q);new Uint8Array(x.buffer,x.byteOffset,x.byteLength).set(o.HEAPU8.subarray(D,D+x.byteLength)),X.push([P,z,x,"cpu"])}}finally{o.stackRestore(Sr),P==="string"&&D&&o._free(D),$e||o._OrtReleaseTensor(fe),(Tt=o.webnnOnRunEnd)==null||Tt.call(o,u)}}return c&&!p&&(o._OrtClearBoundOutputs(c.handle)!==0&&A("Can't clear bound outputs."),J.set(e,[u,f,d,c,p,!1])),X}
5finally{o.stackRestore(C),w.forEach(F=>o._OrtReleaseTensor(F)),O.forEach(F=>o._OrtReleaseTensor(F)),U.forEach(F=>o._free(F)),T!==0&&o._OrtReleaseRunOptions(T),m.forEach(F=>o._free(F))}},bt=e=>{let t=R(),r=J.get(e);if(!r)throw new Error("invalid session id");let a=r[0],n=t._OrtEndProfiling(a);n===0&&A("Can't get an profile file name."),t._OrtFree(n)},vt=e=>{let t=[];for(let r of e){let a=r[2];!Array.isArray(a)&&"buffer"in a&&t.push(a.buffer)}return t}}),V,_,ee,he,we,Re,Ze,Oe,K,Q,Dt,Er,Tr,Ar,Rr,Or,Cr,xr,Ur=v(()=>{le(),vr(),ue(),lt(),V=()=>!!E.wasm.proxy&&typeof document<"u",ee=!1,he=!1,we=!1,Oe=new Map,K=(e,t)=>{let r=Oe.get(e);r?r.push(t):Oe.set(e,[t])},Q=()=>{if(ee||!he||we||!_)throw new Error("worker not ready")},Dt=e=>{switch(e.data.type){case"init-wasm":ee=!1,e.data.err?(we=!0,Ze[1](e.data.err)):(he=!0,Ze[0]()),Re&&(URL.revokeObjectURL(Re),Re=void 0);break;case"init-ep":case"copy-from":case"create":case"release":case"run":case"end-profiling":{let t=Oe.get(e.data.type);e.data.err?t.shift()[1](e.data.err):t.shift()[0](e.data.out);break}}},Er=async()=>{if(!he){if(ee)throw new Error("multiple calls to 'initWasm()' detected.");if(we)throw new Error("previous call to 'initWasm()' failed.");if(ee=!0,V())return new Promise((e,t)=>{_==null||_.terminate(),dr().then(([r,a])=>{try{_=a,_.onerror=s=>t(s),_.onmessage=Dt,Ze=[e,t];let n={type:"init-wasm",in:E};if(!n.in.wasm.wasmPaths&&r){let s=it();s&&(n.in.wasm.wasmPaths=s)}_.postMessage(n),Re=r}catch(n){t(n)}},t)});try{await ut(E.wasm),await ht(E),he=!0}catch(e){throw we=!0,e}finally{ee=!1}}},Tr=async e=>{if(V())return Q(),new Promise((t,r)=>{K("init-ep",[t,r]);let a={type:"init-ep",in:{epName:e,env:E}};_.postMessage(a)});await wt(E,e)},Ar=async e=>V()?(Q(),new Promise((t,r)=>{K("copy-from",[t,r]);let a={type:"copy-from",in:{buffer:e}};_.postMessage(a,[e.buffer])})):Pe(e),Rr=async(e,t)=>{if(V()){if(t!=null&&t.preferredOutputLocation)throw new Error('session option "preferredOutputLocation" is not supported for proxy.');return Q(),new Promise((r,a)=>{K("create",[r,a]);let n={type:"create",in:{model:e,options:{...t}}},s=[];e instanceof Uint8Array&&s.push(e.buffer),_.postMessage(n,s)})}else return mt(e,t)},Or=async e=>{if(V())return Q(),new Promise((t,r)=>{K("release",[t,r]);let a={type:"release",in:e};_.postMessage(a)});yt(e)},Cr=async(e,t,r,a,n,s)=>{if(V()){if(r.some(o=>o[3]!=="cpu"))throw new Error("input tensor on GPU is not supported for proxy.");if(n.some(o=>o))throw new Error("pre-allocated output tensor is not supported for proxy.");return Q(),new Promise((o,l)=>{K("run",[o,l]);let i=r,u={type:"run",in:{sessionId:e,inputIndices:t,inputs:i,outputIndices:a,options:s}};_.postMessage(u,vt(i))})}else return gt(e,t,r,a,n,s)},xr=async e=>{if(V())return Q(),new Promise((t,r)=>{K("end-profiling",[t,r]);let a={type:"end-profiling",in:e};_.postMessage(a)});bt(e)}}),Je,Gt,Lr,ln=v(()=>{le(),Ur(),gr(),st(),br(),Je=(e,t)=>
vendor: 1,543 bytes, line 5
5{switch(e.location){case"cpu":return[e.type,e.dims,e.data,"cpu"];case"gpu-buffer":return[e.type,e.dims,{gpuBuffer:e.gpuBuffer},"gpu-buffer"];case"ml-tensor":return[e.type,e.dims,{mlTensor:e.mlTensor},"ml-tensor"];default:throw new Error(`invalid data location: ${e.location} for ${t()}`)}},Gt=e=>{switch(e[3]){case"cpu":return new $(e[0],e[2],e[1]);case"gpu-buffer":{let t=e[0];if(!dt(t))throw new Error(`not supported data type: ${t} for deserializing GPU tensor`);let{gpuBuffer:r,download:a,dispose:n}=e[2];return $.fromGpuBuffer(r,{dataType:t,dims:e[1],download:a,dispose:n})}case"ml-tensor":{let t=e[0];if(!ct(t))throw new Error(`not supported data type: ${t} for deserializing MLTensor tensor`);let{mlTensor:r,download:a,dispose:n}=e[2];return $.fromMLTensor(r,{dataType:t,dims:e[1],download:a,dispose:n})}default:throw new Error(`invalid data location: ${e[3]}`)}},Lr=class{async fetchModelAndCopyToWasmMemory(e){return Ar(await pt(e))}async loadModel(e,t){se();let r;typeof e=="string"?r=await this.fetchModelAndCopyToWasmMemory(e):r=e,[this.sessionId,this.inputNames,this.outputNames,this.inputMetadata,this.outputMetadata]=await Rr(r,t),ie()}async dispose(){return Or(this.sessionId)}async run(e,t,r){se();let a=[],n=[];Object.entries(e).forEach(d=>{let c=d[0],p=d[1],h=this.inputNames.indexOf(c);if(h===-1)throw new Error(`invalid input '${c}'`);a.push(p),n.push(h)});let s=[],o=[];Object.entries(t).forEach(d=>{let c=d[0],p=d[1],h=this.outputNames.indexOf(c);if(h===-1)throw new Error(`invalid output '${c}'`);s.push(p),o.push(h)});
5let l=a.map((d,c)=>Je(d,()=>`input "${this.inputNames[n[c]]}"`)),i=s.map((d,c)=>d?Je(d,()=>`output "${this.outputNames[o[c]]}"`):null),u=await Cr(this.sessionId,n,l,o,i,r),f={};for(let d=0;d<u.length;d++)f[this.outputNames[o[d]]]=s[d]??Gt(u[d]);return ie(),f}startProfiling(){}endProfiling(){xr(this.sessionId)}}}),Ir={};nt(Ir,{OnnxruntimeWebAssemblyBackend:()=>et,initializeFlags:()=>Xe,wasmBackend:()=>Pr});var Xe,et,Pr,un=v(()=>{le(),Ur(),ln(),Xe=()=>{(typeof E.wasm.initTimeout!="number"||E.wasm.initTimeout<0)&&(E.wasm.initTimeout=0);let e=E.wasm.simd;if(typeof e!="boolean"&&e!==void 0&&e!=="fixed"&&e!=="relaxed"&&(console.warn(`Property "env.wasm.simd" is set to unknown value "${e}". Reset it to \`false\` and ignore SIMD feature checking.`),E.wasm.simd=!1),typeof E.wasm.proxy!="boolean"&&(E.wasm.proxy=!1),typeof E.wasm.trace!="boolean"&&(E.wasm.trace=!1),typeof E.wasm.numThreads!="number"||!Number.isInteger(E.wasm.numThreads)||E.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)E.wasm.numThreads=1;else{let t=typeof navigator>"u"?jr("node:os").cpus().length:navigator.hardwareConcurrency;E.wasm.numThreads=Math.min(4,Math.ceil((t||1)/2))}},et=class{async init(e){Xe(),await Er(),await Tr(e)}async createInferenceSessionHandler(e,t){let r=new Lr;return await r.loadModel(e,t),r}},Pr=new et});le();le();le();var fn="1.22.0-dev.20250409-89f8206ba4";{let e=(un(),Vt(Ir)).wasmBackend;Le("cpu",e,10),Le("wasm",e,10)}Object.defineProperty(E.versions,"web",{value:fn,enumerable:!0});const ae=new Map;class _e extends Error{}class Ft extends Error{}const _r="x-iw-bytes",tt=e=>e.reduce((t,r)=>t+r.byteLength,0);async function dn(e){const t=await crypto.subtle.digest("SHA-256",e);return[...new Uint8Array(t)].map(r=>r.toString(16).padStart(2,"0")).join("")}async function cn(e,t){try{const r=await e.match(t.url);if(!r)return!1;const a=Number(r.headers.get(_r));return t.bytes===void 0?a>0:a===t.bytes}catch{return!1}}async function pn(e,t,r){let a=ae.get(e.url)??[],n=tt(a);const s=new AbortController;let o=setTimeout(()=>s.abort(),t.stallMs??3e4);const l=()=>{clearTimeout(o),o=setTimeout(()=>s.abort(),t.stallMs??3e4)};try{const i=n>0?{Range:`bytes=${n}-`}:{},u=t.fetch,f=await u(e.url,{headers:i,signal:s.signal,credentials:"omit",cache:"no-store"});if(n>0&&f.status===200)r(-n),a=[],n=0;else if(n>0&&f.status!==206)throw new _e(`the server answered ${f.status}`);if(!f.ok||!f.body)throw new _e(`the server answered ${f.status}`);ae.set(e.url,a);const d=f.body.getReader();for(;;){const{done:y,value:T}=await d.read();if(y)break;l(),a.push(T),r(T.byteLength)}clearTimeout(o);const c=tt(a);if(e.bytes!==void 0&&c!==e.bytes)throw ae.delete(e.url),r(-c),new Ft(`${e.url.split("/").pop()} arrived as ${c} bytes, not ${e.bytes}`);const p=new Uint8Array(c);let h=0;for(const y of a)p.set(y,h),h+=y.byteLength;if(e.sha256&&await dn(p)!==e.sha256)throw ae.delete(e.url),r(-c),new Ft(`${e.url.split("/").pop()} failed its integrity check`);return p}finally{clearTimeout(o)}}async function hn(e,t){const r=t.sleep??(i=>new Promise(u=>setTimeout(u,i))),a=[];for(const i of e)await cn(t.cache,i)||a.push(i);if(!a.length)return{downloaded:0};let n=a.reduce((i,u)=>i+tt(ae.get(u.url)??[]),0),s=a.reduce((i,u)=>i+(u.bytes??0),0);const o=()=>{var i;return(i=t.onProgress)==null?void 0:i.call(t,{loaded:n,total:Math.max(s,n,1)})};o();let l=0;for(const i of a){let u=null;const f=(t.retries??4)+1;for(let d=0;d<f;d++)try{const c=await pn(i,t,p=>{n+=p,o()});i.bytes===void 0&&(s+=c.byteLength),await t.cache.put(i.url,new Response(c,{headers:{"content-type":"application/octet-stream",[_r]:String(c.byteLength)}})),ae.delete(i.url),l+=c.byteLength,u=null;break}catch(c){u=c,d<f-1&&await r(Math.min(8e3,1e3*2**d))}if(u){const d=u instanceof Error?u.message:String(u);throw new _e(d==="Failed to fetch"||/network|abort/i.test(d)?"the connection dropped":d)}}return{downloaded:l}}let Ke=null;function $r(){return Ke??(Ke=import("./phonemizer-CpN3j-Vj.js").then(e=>
5e.phonemize).catch(e=>{throw Ke=null,e})),Ke}const wn="rhasspy/piper-voices",mn="c10ece1aade47bb51c153c893d14e5bf8e5b7117",Ce=`https://huggingface.co/${wn}/resolve/${mn}/`,H={model:{path:"en/en_GB/cori/medium/en_GB-cori-medium.onnx",bytes:63531379,sha256:"1899f98e5fb8310154f3c2973f4b8a929ba7245e722b3d3a85680b833d95f10d"},config:{path:"en/en_GB/cori/medium/en_GB-cori-medium.onnx.json",bytes:4966,sha256:"e262c16d7f192f69d4edd6b4ef8a5915379e67495fcc402f1ab15eeb33da3d36"}},yn="iw-keep-piper-v1",gn=/(?:\s*[;:,.!?¡¿—–…"«»“”()[\]{}]+\s*)+/gu;function bn(e){return/[?¿]/u.test(e)?"?":/!/u.test(e)?"!":/[.…]/u.test(e)?".":/;/u.test(e)?";":/:/u.test(e)?":":/[,—–]/u.test(e)?",":""}async function vn(e,t,r="en"){const a=[];let n=0;for(const o of e.matchAll(gn))o.index>n&&a.push({words:!0,text:e.slice(n,o.index)}),a.push({words:!1,text:o[0]}),n=o.index+o[0].length;return n<e.length&&a.push({words:!0,text:e.slice(n)}),(await Promise.all(a.map(async o=>{if(!o.words){const l=bn(o.text);return l?`${l} `:" "}return o.text.trim()?(await t(o.text,r)).join(" ").trim():" "}))).join("").replace(/\s+/gu," ").trim()}function En(e,t){const r=t._??[0],a=[...t["^"]??[1],...r];for(const n of e){const s=t[n];s&&a.push(...s,...r)}return a.push(...t.$??[2]),a}function Tn(e,t=.9,r=8){let a=0;for(let s=0;s<e.length;s++)a=Math.max(a,Math.abs(e[s]));if(!a)return e;const n=Math.min(r,t/a);for(let s=0;s<e.length;s++)e[s]*=n;return e}const jt=new URL("/assets/ort-wasm-simd-threaded-But7yj32.wasm",import.meta.url).href,An=new URL("/assets/ort-wasm-simd-threaded-BQa_0C5h.mjs",import.meta.url).href,ye=(e,t=[])=>self.postMessage(e,t),Ue=new Map;function Rn(e){return{match:async t=>{var a;const r=String(t instanceof Request?t.url:t);return await(e==null?void 0:e.match(r).catch(()=>{}))??((a=Ue.get(r))==null?void 0:a.clone())},put:async(t,r)=>{const a=String(t instanceof Request?t.url:t);Ue.set(a,r.clone()),await(e==null?void 0:e.put(a,r).catch(()=>{}))},delete:async t=>{const r=String(t instanceof Request?t.url:t);
5return Ue.delete(r),await(e==null?void 0:e.delete(r).catch(()=>!1))??!1}}}let oe=null,ne=null;async function On(){const e=Rn(await caches.open(yn).catch(()=>null)),t=[{url:Ce+H.config.path,bytes:H.config.bytes,sha256:H.config.sha256},{url:Ce+H.model.path,bytes:H.model.bytes,sha256:H.model.sha256},{url:jt}],{downloaded:r}=await hn(t,{cache:e,fetch,onProgress:({loaded:l,total:i})=>ye({type:"progress",loaded:l,total:i})});if(oe)return{downloaded:r,initMs:0};const a=performance.now(),n=async l=>{const i=await e.match(l);if(!i)throw new Error("The voice could not be read back from this device.");return i.arrayBuffer()};E.wasm.wasmBinary=await n(jt),E.wasm.wasmPaths={mjs:An},E.wasm.numThreads=self.crossOriginIsolated?Math.min(4,navigator.hardwareConcurrency||1):1,E.wasm.proxy=!1;const[s,o]=await Promise.all([n(Ce+H.config.path),n(Ce+H.model.path),$r()]);return ne=JSON.parse(new TextDecoder().decode(s)),oe=await ot.create(new Uint8Array(o),{executionProviders:["wasm"]}),Ue.clear(),await Mr("Ready.",1).catch(()=>{}),{downloaded:r,initMs:performance.now()-a}}async function Mr(e,t){var c;if(!oe||!ne)throw new Error("The Piper voice is not loaded yet.");const r=performance.now(),a=await vn(e,await $r(),ne.espeak.voice),n=En(a,ne.phoneme_id_map),{noise_scale:s,length_scale:o,noise_w:l}=ne.inference,i={input:new $("int64",BigInt64Array.from(n,BigInt),[1,n.length]),input_lengths:new $("int64",BigInt64Array.from([BigInt(n.length)]),[1]),scales:new $("float32",Float32Array.from([s,o*t,l]),[3])};oe.inputNames.includes("sid")&&(i.sid=new $("int64",BigInt64Array.from([0n]),[1]));const f=(await oe.run(i))[oe.outputNames[0]],d=Tn(Float32Array.from(f.data));return(c=f.dispose)==null||c.call(f),{audio:d,sampleRate:ne.audio.sample_rate,renderMs:performance.now()-r}}let Qe=0,Wt=Promise.resolve();self.onmessage=e=>{const t=e.data;if(t.type==="cancel"){Qe=Math.max(Qe,t.before);return}Wt=Wt.then(async()=>{try{if(t.type==="load")ye({id:t.id,ok:!0,type:"loaded",...await On()});else if(t.id<Qe)ye({id:t.id,ok:!0,type:"cancelled"});else{const r=await Mr(t.text,t.lengthScale);ye({id:t.id,ok:!0,type:"spoken",...r},[r.audio.buffer])}}catch(r){ye({id:t.id,ok:!1,error:r instanceof Error?r.message:String(r),download:r instanceof _e})}})};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.