var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=require(`./ocr-difficulty-9L3ewI3P.cjs`);let l=require(`onnxruntime-web/wasm`);l=s(l);const u=new URL(`./assets/ocr_router_efficientnet_b0_threshold_0.15.onnx`,require(`url`).pathToFileURL(__filename).href).href,d=new URL(`./assets/ort-wasm-simd-threaded.mjs`,require(`url`).pathToFileURL(__filename).href).href,f=new URL(`./assets/ort-wasm-simd-threaded.wasm`,require(`url`).pathToFileURL(__filename).href).href,p=[1,3,224,224],m=256,h=[.485,.456,.406],g=[.229,.224,.225];let _=null;async function v(){return _||(l.env.wasm.wasmPaths={mjs:d,wasm:f},l.env.wasm.numThreads=1,_=l.InferenceSession.create(u,{executionProviders:[`wasm`],graphOptimizationLevel:`all`}).catch(e=>{throw _=null,e})),_}async function y(e){let t=await v(),n=await x(e);try{let e=C(n),r=t.inputNames[0]??`x`,i=t.outputNames[0]??`linear`,a=performance.now(),o=await t.run({[r]:e}),s=performance.now()-a,l=o[i];if(!l)throw Error(`Model output "${i}" was not returned.`);let u=Array.from(l.data).map(b);return{scores:u,prediction:c.a(u),inferenceMs:s}}finally{n.dispose()}}function b(e){return 1/(1+Math.exp(-e))}async function x(e){if(typeof createImageBitmap==`function`){let t=await createImageBitmap(e,{imageOrientation:`from-image`});return{source:t,width:t.width,height:t.height,dispose:()=>t.close()}}let t=URL.createObjectURL(e);try{let e=await S(t);return{source:e,width:e.naturalWidth,height:e.naturalHeight,dispose:()=>URL.revokeObjectURL(t)}}catch(e){throw URL.revokeObjectURL(t),e}}function S(e){return new Promise((t,n)=>{let r=new Image;r.decoding=`async`,r.onload=()=>t(r),r.onerror=()=>n(Error(`Unable to decode the canvas image.`)),r.src=e})}function C(e){let[,t,n,r]=p,i=256/Math.min(e.width,e.height),a=Math.round(e.width*i),o=Math.round(e.height*i),s=w(a,o);T(s).drawImage(e.source,0,0,a,o);let c=Math.max(0,Math.floor((a-r)/2)),u=Math.max(0,Math.floor((o-n)/2)),d=T(w(r,n));d.drawImage(s,c,u,r,n,0,0,r,n);let f=d.getImageData(0,0,r,n).data,m=r*n,_=new Float32Array(t*m);for(let e=0;e<m;e+=1){let t=e*4,n=(f[t]??0)/255,r=(f[t+1]??0)/255,i=(f[t+2]??0)/255;_[e]=(n-h[0])/g[0],_[m+e]=(r-h[1])/g[1],_[m*2+e]=(i-h[2])/g[2]}return new l.Tensor(`float32`,_,Array.from(p))}function w(e,t){let n=document.createElement(`canvas`);return n.width=e,n.height=t,n}function T(e){let t=e.getContext(`2d`,{willReadFrequently:!0});if(!t)throw Error(`Could not acquire a 2D canvas context for image preprocessing.`);return t}exports.loadOcrClassifier=v,exports.runOcrClassifier=y,exports.t=s;