UNPKG

@scandit/web-datacapture-id

Version:

Scandit Data Capture SDK for the Web

6 lines 23.1 kB
!function proxyXMLHttpRequest(){Object.defineProperty(globalThis.XMLHttpRequest.prototype,"send",{value:()=>{void 0},configurable:true,writable:true})}();!function proxyConsole(){const CentaurusWordsToSDC=new Map;CentaurusWordsToSDC.set([77,105,99,114,111,98,108,105,110,107],"Scandit");CentaurusWordsToSDC.set([66,108,105,110,107,73,68],"ID Capture");function fixCentaurusMentions(input){const output=input;if(typeof output==="string")return[...CentaurusWordsToSDC.entries()].reduce((s,[word,replacement])=>{const realWord=word.map(char=>String.fromCodePoint(char)).join("");return s.replace(new RegExp(realWord,"gi"),replacement)},output);return output}if(console&&!console["__scandit_console_proxy__"]){const functionNames=["debug","error","info","warn","log"];const originalFunctions=functionNames.reduce((fnMaps,functionName)=>{fnMaps[functionName]=console[functionName];return fnMaps},{});for(const functionName of functionNames)console[functionName]=(...args)=>{const filteredArgs=args.map(fixCentaurusMentions);originalFunctions[functionName].apply(console,filteredArgs)};console["__scandit_console_proxy__"]=true}}();var ve=Object.defineProperty;var J=e=>{throw TypeError(e)};var Ne=(e,r,t)=>r in e?ve(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var v=(e,r,t)=>Ne(e,typeof r!="symbol"?r+"":r,t),V=(e,r,t)=>r.has(e)||J("Cannot "+t);var i=(e,r,t)=>(V(e,r,"read from private field"),t?t.call(e):r.get(e)),P=(e,r,t)=>r.has(e)?J("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(e):r.set(e,t),p=(e,r,t,s)=>(V(e,r,"write to private field"),s?s.call(e,t):r.set(e,t),t),Q=(e,r,t)=>(V(e,r,"access private method"),t);var Z=(e,r,t,s)=>({set _(o){p(e,r,o,t)},get _(){return i(e,r,s)}}); /** * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: Apache-2.0 */const ae=Symbol("Comlink.proxy"),xe=Symbol("Comlink.endpoint"),Ae=Symbol("Comlink.releaseProxy"),z=Symbol("Comlink.finalizer"),D=Symbol("Comlink.thrown"),ce=e=>typeof e=="object"&&e!==null||typeof e=="function",Le={canHandle:e=>ce(e)&&e[ae],serialize(e){const{port1:r,port2:t}=new MessageChannel;return q(e,r),[t,[t]]},deserialize(e){return e.start(),Me(e)}},Oe={canHandle:e=>ce(e)&&D in e,serialize({value:e}){let r;return e instanceof Error?r={isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:r={isError:!1,value:e},[r,[]]},deserialize(e){throw e.isError?Object.assign(new Error(e.value.message),e.value):e.value}},le=new Map([["proxy",Le],["throw",Oe]]);function Ie(e,r){for(const t of e)if(r===t||t==="*"||t instanceof RegExp&&t.test(r))return!0;return!1}function q(e,r=globalThis,t=["*"]){r.addEventListener("message",function s(o){if(!o||!o.data)return;if(!Ie(t,o.origin)){console.warn(`Invalid origin '${o.origin}' for comlink proxy`);return}const{id:l,type:a,path:n}=Object.assign({path:[]},o.data),d=(o.data.argumentList||[]).map(T);let u;try{const c=n.slice(0,-1).reduce((g,w)=>g[w],e),m=n.reduce((g,w)=>g[w],e);switch(a){case"GET":u=m;break;case"SET":c[n.slice(-1)[0]]=T(o.data.value),u=!0;break;case"APPLY":u=m.apply(c,d);break;case"CONSTRUCT":{const g=new m(...d);u=fe(g)}break;case"ENDPOINT":{const{port1:g,port2:w}=new MessageChannel;q(e,w),u=me(g,[g])}break;case"RELEASE":u=void 0;break;default:return}}catch(c){u={value:c,[D]:0}}Promise.resolve(u).catch(c=>({value:c,[D]:0})).then(c=>{const[m,g]=j(c);r.postMessage(Object.assign(Object.assign({},m),{id:l}),g),a==="RELEASE"&&(r.removeEventListener("message",s),ue(r),z in e&&typeof e[z]=="function"&&e[z]())}).catch(c=>{const[m,g]=j({value:new TypeError("Unserializable return value"),[D]:0});r.postMessage(Object.assign(Object.assign({},m),{id:l}),g)})}),r.start&&r.start()}function Ue(e){return e.constructor.name==="MessagePort"}function ue(e){Ue(e)&&e.close()}function Me(e,r){const t=new Map;return e.addEventListener("message",function(o){const{data:l}=o;if(!l||!l.id)return;const a=t.get(l.id);if(a)try{a(l)}finally{t.delete(l.id)}}),_(e,t,[],r)}function U(e){if(e)throw new Error("Proxy has been released and is not useable")}function de(e){return N(e,new Map,{type:"RELEASE"}).then(()=>{ue(e)})}const F=new WeakMap,W="FinalizationRegistry"in globalThis&&new FinalizationRegistry(e=>{const r=(F.get(e)||0)-1;F.set(e,r),r===0&&de(e)});function Ce(e,r){const t=(F.get(r)||0)+1;F.set(r,t),W&&W.register(e,r,e)}function ze(e){W&&W.unregister(e)}function _(e,r,t=[],s=function(){}){let o=!1;const l=new Proxy(s,{get(a,n){if(U(o),n===Ae)return()=>{ze(l),de(e),r.clear(),o=!0};if(n==="then"){if(t.length===0)return{then:()=>l};const d=N(e,r,{type:"GET",path:t.map(u=>u.toString())}).then(T);return d.then.bind(d)}return _(e,r,[...t,n])},set(a,n,d){U(o);const[u,c]=j(d);return N(e,r,{type:"SET",path:[...t,n].map(m=>m.toString()),value:u},c).then(T)},apply(a,n,d){U(o);const u=t[t.length-1];if(u===xe)return N(e,r,{type:"ENDPOINT"}).then(T);if(u==="bind")return _(e,r,t.slice(0,-1));const[c,m]=ee(d);return N(e,r,{type:"APPLY",path:t.map(g=>g.toString()),argumentList:c},m).then(T)},construct(a,n){U(o);const[d,u]=ee(n);return N(e,r,{type:"CONSTRUCT",path:t.map(c=>c.toString()),argumentList:d},u).then(T)}});return Ce(l,e),l}function De(e){return Array.prototype.concat.apply([],e)}function ee(e){const r=e.map(j);return[r.map(t=>t[0]),De(r.map(t=>t[1]))]}const he=new WeakMap;function me(e,r){return he.set(e,r),e}function fe(e){return Object.assign(e,{[ae]:!0})}function j(e){for(const[r,t]of le)if(t.canHandle(e)){const[s,o]=t.serialize(e);return[{type:"HANDLER",name:r,value:s},o]}return[{type:"RAW",value:e},he.get(e)||[]]}function T(e){switch(e.type){case"HANDLER":return le.get(e.name).deserialize(e.value);case"RAW":return e.value}}function N(e,r,t,s){return new Promise(o=>{const l=Fe();r.set(l,o),e.start&&e.start(),e.postMessage(Object.assign({id:l},t),s)})}function Fe(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}const We=async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,3,1,0,1,10,14,1,12,0,65,0,65,0,65,0,252,10,0,0,11])),je=async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,2,8,1,1,97,1,98,3,127,1,6,6,1,127,1,65,0,11,7,5,1,1,97,3,1])),Be=async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,7,1,5,0,208,112,26,11])),Ve=async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,12,1,10,0,67,0,0,0,0,252,0,26,11])),$e=async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,8,1,6,0,65,0,192,26,11])),_e=async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11])),qe=()=>(async e=>{try{return typeof MessageChannel<"u"&&(new MessageChannel).port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(e)}catch{return!1}})(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]));function He(){const e=navigator.userAgent.toLowerCase();return e.includes("safari")&&!e.includes("chrome")}async function Ge(){if(!await qe())return!1;if(!("importScripts"in self))throw Error("Not implemented");return He()?!1:"Worker"in self}async function Ke(){const e=[je(),Be(),We(),Ve(),$e()];if(!(await Promise.all(e)).every(Boolean))throw new Error("Browser doesn't meet minimum requirements!");return await _e()?await Ge()?"advanced-threads":"advanced":"basic"}const Ye={basic:{full:3288111,lightweight:3326644},advanced:{full:3300823,lightweight:3336970},"advanced-threads":{full:3352383,lightweight:3387693}},Xe={basic:{full:13747128,lightweight:12114443},advanced:{full:13747128,lightweight:12114443},"advanced-threads":{full:13747128,lightweight:12114443}},Je={wasm:Ye,data:Xe};function M(...e){const r=e.filter(t=>t).join("/").replace(/([^:]\/)\/+/g,"$1");try{new URL(r,"http://example.com")}catch{throw new Error(`Invalid URL: ${r}`)}return r}async function re(e,r){var w;const{url:t,fileType:s,variant:o,buildType:l,progressCallback:a}=e,n=await fetch(t);if(!a)return n.arrayBuffer();const d=n.headers.get("Content-Length"),u=d?parseInt(d,10):r({fileType:s,variant:o,buildType:l});if(isNaN(u)||u<=0)throw new Error(`Invalid content length for ${s} file: ${u}`);let c=0;const m=new TransformStream({transform(E,S){c+=E.length;const I=Math.min(Math.round(c/u*100),100);a({loaded:c,contentLength:u,progress:I,finished:!1}),S.enqueue(E)},flush(){a({loaded:c,contentLength:u,progress:100,finished:!0})}});return new Response((w=n.body)==null?void 0:w.pipeThrough(m),n).arrayBuffer()}const te="application/javascript",Qe=(e,r={})=>{const t={skipSameOrigin:!0,useBlob:!0,...r};return t.skipSameOrigin&&new URL(e).origin===self.location.origin?Promise.resolve(e):new Promise((s,o)=>void fetch(e).then(l=>l.text()).then(l=>{new URL(e).href.split("/").pop();let n="";if(t.useBlob){const d=new Blob([l],{type:te});n=URL.createObjectURL(d)}else n=`data:${te},`+encodeURIComponent(l);s(n)}).catch(o))};function Ze(e,r){const t=r[e.fileType][e.variant];if(typeof t=="number")return t;if(e.buildType===void 0)throw new Error("buildType is required when size manifest entry is build-aware");return t[e.buildType]}function er(){const e=self.navigator.userAgent.toLowerCase();return/iphone|ipad|ipod/.test(e)}function rr(e){return{licenseId:e.licenseId,licensee:e.licensee,applicationIds:e.applicationIds,packageName:e.packageName,platform:"Browser",sdkName:e.sdkName,sdkVersion:e.sdkVersion}}async function ne(e,r="https://www.scandit.com"){if(!r||typeof r!="string")throw new Error("Invalid baltazarUrl: must be a non-empty string");try{new URL(r)}catch{throw new Error(`Invalid baltazarUrl format: ${r}`)}try{const t=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},cache:"no-cache",body:JSON.stringify(rr(e))});if(!t.ok)throw new Error(`Server returned error: ${t.status} ${t.statusText}`);return await t.text()}catch(t){throw console.error("Server permission request failed:",t),t}}function se(e){return Math.ceil(e*1024*1024/64/1024)}class $ extends Error{constructor(t,s,o){super(`Proxy URL validation failed for "${o}": ${s}`);v(this,"code");v(this,"url");this.code=t,this.url=o,this.name="ProxyUrlValidationError"}}function tr(e){const r=e.unlockResult==="requires-server-permission",{allowPingProxy:t,allowBaltazarProxy:s,hasPing:o}=e;if(!t&&!s)throw new Error("Centaurus proxy URL is set but your license doesn't permit proxy usage. Check your license.");if(!r&&!o)throw new Error("Centaurus proxy URL is set but your license doesn't permit proxy usage. Check your license.");if(!r&&o&&s&&!t||r&&!o&&!s&&t)throw new Error("Centaurus proxy URL is set but your license doesn't permit proxy usage. Check your license.")}function nr(e){let r;try{r=new URL(e)}catch{throw new $("INVALID_PROXY_URL",`Failed to create URL instance for provided Centaurus proxy URL "${e}". Expected format: https://your-proxy.com or https://your-proxy.com/`,e)}if(r.protocol!=="https:")throw new $("HTTPS_REQUIRED",`Proxy URL validation failed for "${e}": HTTPS protocol must be used. Expected format: https://your-proxy.com or https://your-proxy.com/`,e);const t=r.origin;try{const s=new URL(`${r.pathname}${r.pathname.endsWith("/")?"":"/"}api/v2/status/check`,t).toString();return{ping:t+r.pathname.replace(/\/$/,""),baltazar:s}}catch{throw new $("INVALID_PROXY_URL","Failed to build baltazar service URL",e)}}function ge(e){return Object.prototype.toString.call(e).slice(8,-1)}function C(e){if(ge(e)!=="Object")return!1;const r=Object.getPrototypeOf(e);return!!r&&r.constructor===Object&&r===Object.prototype}function oe(e){return ge(e)==="Symbol"}function ie(e,r,t,s){const o={}.propertyIsEnumerable.call(s,r)?"enumerable":"nonenumerable";o==="enumerable"&&(e[r]=t),o==="nonenumerable"&&Object.defineProperty(e,r,{value:t,enumerable:!1,writable:!0,configurable:!0})}function pe(e,r,t){if(!C(r))return r;let s={};if(C(e)){const n=Object.getOwnPropertyNames(e),d=Object.getOwnPropertySymbols(e);s=[...n,...d].reduce((u,c)=>{const m=e[c];return(!oe(c)&&!Object.getOwnPropertyNames(r).includes(c)||oe(c)&&!Object.getOwnPropertySymbols(r).includes(c))&&ie(u,c,m,e),u},{})}const o=Object.getOwnPropertyNames(r),l=Object.getOwnPropertySymbols(r);return[...o,...l].reduce((n,d)=>{let u=r[d];const c=C(e)?e[d]:void 0;return c!==void 0&&C(u)&&(u=pe(c,u)),ie(n,d,u,r),n},s)}function sr(e,...r){return r.reduce((t,s)=>pe(t,s),e)}function ye(e){return{country:(e==null?void 0:e.country)??void 0,region:(e==null?void 0:e.region)??void 0,type:(e==null?void 0:e.type)??void 0}}const or=e=>({documentFilter:ye(e.documentFilter),fields:e.fields??[]}),ir=e=>({documentFilter:ye(e.documentFilter),fields:e.fields||[],documentNumberAnonymizationSettings:e.documentNumberAnonymizationSettings?{prefixDigitsVisible:e.documentNumberAnonymizationSettings.prefixDigitsVisible,suffixDigitsVisible:e.documentNumberAnonymizationSettings.suffixDigitsVisible}:void 0});function ar(e={},r){var a,n,d,u;e&&(e=Object.fromEntries(Object.entries(e).filter(([c,m])=>m!==void 0)));const t=((n=(a=e==null?void 0:e.scanningSettings)==null?void 0:a.customDocumentRules)==null?void 0:n.map(or))??[],s=((u=(d=e==null?void 0:e.scanningSettings)==null?void 0:d.customDocumentAnonymizationSettings)==null?void 0:u.map(ir))??[],o={...e==null?void 0:e.scanningSettings,customDocumentRules:t,customDocumentAnonymizationSettings:s};return sr(r,{...e,scanningSettings:o})}class cr extends Error{constructor(t){super(t);v(this,"code","SERVER_PERMISSION_ERROR");this.name="ServerPermissionError"}}class lr extends Error{constructor(t){super(t);v(this,"code","LICENSE_ERROR");this.name="LicenseError"}}function ur({workerScope:e,getSessionNumber:r,onError:t}){const s=e??self,o=r??(()=>0);let l=!1;const a=(u,c)=>{if(!l){l=!0;try{t({origin:u,error:c,sessionNumber:o()})}finally{l=!1}}},n=u=>{const c=u;a("worker.onerror",c.error??c.message??"Unknown worker error")},d=u=>{a("worker.unhandledrejection",u.reason??"Unhandled worker rejection")};return s.addEventListener("error",n),s.addEventListener("unhandledrejection",d),()=>{s.removeEventListener("error",n),s.removeEventListener("unhandledrejection",d)}}const we="FrameTransferError",dr=(e,r)=>{const t=r instanceof Error&&r.message?`: ${r.message}`:"",s=new Error(`${e}${t}`,r instanceof Error?{cause:r}:void 0);return s.name=we,s};var h,b,A,L,O,y,k,x,R,B,be;class hr{constructor(){P(this,B);P(this,h);P(this,b);P(this,A);v(this,"progressStatusCallback");P(this,L,!0);P(this,O,!0);P(this,y,0);P(this,k);P(this,x);P(this,R);p(this,R,ur({getSessionNumber:()=>i(this,y),onError:({error:r,sessionNumber:t})=>{i(this,h)&&(this.reportPinglet({schemaName:"ping.error",schemaVersion:"1.0.0",sessionNumber:t,data:{errorType:"Crash",errorMessage:r instanceof Error?r.message:String(r),stackTrace:r instanceof Error?r.stack:void 0}}),this.sendPinglets())}}))}reportPinglet(r){if(!i(this,h))throw new Error("Cannot report pinglet: Wasm module not loaded");try{i(this,h).queuePinglet(JSON.stringify(r.data),r.schemaName,r.schemaVersion,r.sessionNumber??i(this,y))}catch(t){console.warn("Failed to queue pinglet:",t,r)}}sendPinglets(){if(!i(this,h))throw new Error("Cannot send pinglets: Wasm module not loaded");try{i(this,h).sendPinglets()}catch(r){console.warn("Failed to send pinglets:",r)}}async[atob("aW5pdEJsaW5rSWQ=")](r,t,s){var d,u;const o=new URL("resources/",r.resourcesLocation).toString();p(this,A,t),this.progressStatusCallback=s,p(this,x,r.userId);const l=r.wasmVariant??await Ke(),a=r.useLightweightBuild?"lightweight":"full";if(await Q(this,B,be).call(this,{resourceUrl:o,wasmVariant:l,featureVariant:a,initialMemory:r.initialMemory}),!i(this,h))throw new Error("Wasm module not loaded");const n=i(this,h).initializeWithLicenseKey(r.licenseKey,r.userId,!1);if(this.reportPinglet({schemaName:"ping.sdk.init.start",schemaVersion:"1.1.0",sessionNumber:0,data:{packageName:self.location.hostname,platform:"Emscripten",platformDetails:`${a}-${l}`,product:atob("QmxpbmtJRA=="),userId:i(this,x)}}),n.licenseError)throw new lr("License unlock error: "+n.licenseError);if(r[atob("bWljcm9ibGlua1Byb3h5VXJs")]&&(tr(n),p(this,k,nr(r[atob("bWljcm9ibGlua1Byb3h5VXJs")])),n.allowPingProxy&&n.hasPing&&(i(this,h).setPingProxyUrl(i(this,k).ping),console.debug(`Using ping proxy URL: ${i(this,k).ping}`))),n.unlockResult==="requires-server-permission"){const m=((d=i(this,k))==null?void 0:d.baltazar)&&n.allowBaltazarProxy?(u=i(this,k))==null?void 0:u.baltazar:void 0;m&&console.debug(`Using Baltazar proxy URL: ${m}`);const g=m?await ne(n,m):await ne(n),w=i(this,h).submitServerPermission(g);if(w!=null&&w.error)throw new cr("Server unlock error: "+w.error)}try{console.debug(`Centaurus SDK ${n.sdkVersion} unlocked`),p(this,L,n.showDemoOverlay),p(this,O,n.showProductionOverlay),i(this,h).initializeSdk(r.userId)}catch(c){throw console.warn("Failed to initialize Centaurus SDK:",c),this.reportPinglet({schemaName:"ping.error",schemaVersion:"1.0.0",sessionNumber:0,data:{errorType:"Crash",errorMessage:c instanceof Error?c.message:String(c),stackTrace:c instanceof Error?c.stack:void 0}}),this.sendPinglets(),c}}createScanningSession(r){if(!i(this,h))throw new Error("Wasm module not loaded");try{const t=ar(r,i(this,A)),s=i(this,h).createScanningSession(t,i(this,x));return Z(this,y)._++,this.sendPinglets(),this.createProxySession(s,t)}catch(t){throw this.reportPinglet({schemaName:"ping.error",schemaVersion:"1.0.0",sessionNumber:i(this,y),data:{errorType:"Crash",errorMessage:t instanceof Error?t.message:String(t),stackTrace:t instanceof Error?t.stack:void 0}}),this.sendPinglets(),t}}[atob("Y3JlYXRlQmxpbmtJZFNjYW5uaW5nU2Vzc2lvbg==")](r){return this.createScanningSession(r)}createProxySession(r,t){p(this,b,r);let s=null,o=null;return fe({getResult:()=>{try{return r.getResult()}catch(a){throw i(this,h)&&(this.reportPinglet({schemaName:"ping.error",schemaVersion:"1.0.0",sessionNumber:i(this,y),data:{errorType:"NonFatal",errorMessage:a instanceof Error?a.message:String(a),stackTrace:a instanceof Error?a.stack:void 0}}),this.sendPinglets()),a}},process:a=>{try{const n=r.process(a);"error"in n?i(this,h)&&(this.reportPinglet({schemaName:"ping.error",schemaVersion:"1.0.0",sessionNumber:i(this,y),data:{errorType:"NonFatal",errorMessage:String(n.error),stackTrace:void 0}}),this.sendPinglets()):(n.inputImageAnalysisResult.documentClassInfo.type&&(s=n.inputImageAnalysisResult.documentClassInfo),n.inputImageAnalysisResult.documentRotation!=="not-available"&&(o=n.inputImageAnalysisResult.documentRotation),s&&(s==null?void 0:s.type)!==n.inputImageAnalysisResult.documentClassInfo.type&&(n.inputImageAnalysisResult.documentClassInfo=s),o&&o!==n.inputImageAnalysisResult.documentRotation&&(n.inputImageAnalysisResult.documentRotation=o));let d;try{d=me({...n,arrayBuffer:a.data.buffer},[a.data.buffer])}catch(u){const c=dr("Failed to transfer frame from worker",u);throw i(this,h)&&(this.reportPinglet({schemaName:"ping.error",schemaVersion:"1.0.0",sessionNumber:i(this,y),data:{errorType:"Crash",errorMessage:c.message,stackTrace:c.stack}}),this.sendPinglets()),c}return d}catch(n){throw n instanceof Error&&n.name===we||!i(this,h)||(this.reportPinglet({schemaName:"ping.error",schemaVersion:"1.0.0",sessionNumber:i(this,y),data:{errorType:"NonFatal",errorMessage:n instanceof Error?n.message:String(n),stackTrace:n instanceof Error?n.stack:void 0}}),this.sendPinglets()),n}},ping:a=>{this.reportPinglet({...a,sessionNumber:a.sessionNumber??i(this,y)})},sendPinglets:()=>this.sendPinglets(),getSettings:()=>t,reset:()=>{try{r.reset(),s=null,o=null}catch(a){throw i(this,h)&&(this.reportPinglet({schemaName:"ping.error",schemaVersion:"1.0.0",sessionNumber:i(this,y),data:{errorType:"NonFatal",errorMessage:a instanceof Error?a.message:String(a),stackTrace:a instanceof Error?a.stack:void 0}}),this.sendPinglets()),a}},delete:()=>{r.isDeleted()||r.delete(),i(this,b)===r&&p(this,b,void 0)},deleteLater:()=>{r.isDeleted()||r.deleteLater(),i(this,b)===r&&p(this,b,void 0)},isDeleted:()=>r.isDeleted(),isAliasOf:a=>r.isAliasOf(a),showDemoOverlay:()=>i(this,L),showProductionOverlay:()=>i(this,O)})}[z](){}async terminate(){var s,o;if(self.setTimeout(()=>self.close,5e3),i(this,b))try{i(this,b).isDeleted()||(console.debug("Deleting Centaurus session during terminate"),i(this,b).delete())}catch(l){if(console.warn("Failed to delete Centaurus session during terminate:",l),!i(this,h))return;this.reportPinglet({schemaName:"ping.error",schemaVersion:"1.0.0",sessionNumber:i(this,y),data:{errorType:"NonFatal",errorMessage:l instanceof Error?l.message:String(l),stackTrace:l instanceof Error?l.stack:void 0}}),this.sendPinglets()}finally{p(this,b,void 0)}if(!i(this,h)){(s=i(this,R))==null||s.call(this),p(this,R,void 0),console.warn("No Wasm module loaded during worker termination. Skipping cleanup."),self.close();return}i(this,h).terminateSdk(),await new Promise(l=>setTimeout(l,0)),this.sendPinglets();const t=Date.now();for(;i(this,h).arePingRequestsInProgress()&&Date.now()-t<5e3;)await new Promise(l=>setTimeout(l,100));p(this,h,void 0),(o=i(this,R))==null||o.call(this),p(this,R,void 0),console.debug("CentaurusWorker terminated 🔴"),self.close()}}h=new WeakMap,b=new WeakMap,A=new WeakMap,L=new WeakMap,O=new WeakMap,y=new WeakMap,k=new WeakMap,x=new WeakMap,R=new WeakMap,B=new WeakSet,be=async function({resourceUrl:r,wasmVariant:t,featureVariant:s,initialMemory:o}){if(i(this,h)){console.log("Wasm already loaded");return}const l="Centaurus",a=M(r,s,t),n=M(a,`${l}.js`),d=M(a,`${l}.wasm`),u=M(a,`${l}.data`),c=await Qe(n),g=(await import(c)).default;o||(o=er()?700:200);const w=new WebAssembly.Memory({initial:se(o),maximum:se(2048),shared:t==="advanced-threads"});let E,S,I=0;const Pe=32,H=()=>{if(!this.progressStatusCallback||!E||!S)return;const f=E.finished&&S.finished,K=E.loaded+S.loaded,Y=E.contentLength+S.contentLength,Te=f?100:Math.min(Math.round(K/Y*100),100),X=performance.now();X-I<Pe||(I=X,this.progressStatusCallback({loaded:K,contentLength:Y,progress:Te,finished:f}))},Ee=f=>{E=f,H()},Se=f=>{S=f,H()},G=f=>Ze({...f,buildType:s},Je),[ke,Re]=await Promise.all([re({url:d,fileType:"wasm",variant:t,buildType:s,progressCallback:Ee},G),re({url:u,fileType:"data",variant:t,buildType:s,progressCallback:Se},G)]);if(this.progressStatusCallback&&E&&S){const f=E.contentLength+S.contentLength;this.progressStatusCallback({loaded:f,contentLength:f,progress:100,finished:!0})}if(p(this,h,await g({locateFile:f=>`${a}/${t}/${f}`,onAbort:f=>{i(this,h)&&(this.reportPinglet({schemaName:"ping.error",schemaVersion:"1.0.0",sessionNumber:i(this,y),data:{errorType:"Crash",errorMessage:f instanceof Error?f.message:String(f),stackTrace:f instanceof Error?f.stack:void 0}}),this.sendPinglets())},printErr:f=>{if(console.error(f),/\babort(ed)?\b/i.test(f)){if(!i(this,h))return;this.reportPinglet({schemaName:"ping.error",schemaVersion:"1.0.0",sessionNumber:i(this,y),data:{errorType:"Crash",errorMessage:String(f),stackTrace:void 0}}),this.sendPinglets()}},mainScriptUrlOrBlob:c,wasmBinary:ke,getPreloadedPackage(){return Re},wasmMemory:w,noExitRuntime:!0})),!i(this,h))throw new Error("Failed to load Wasm module")};const mr=new hr;q(mr);