/*!
* Dynamsoft JavaScript Library
* @product Dynamsoft Code Parser JS Edition
* @website http://www.dynamsoft.com
* @copyright Copyright 2024, Dynamsoft Corporation
* @author Dynamsoft
* @version 2.4.20
* @fileoverview Dynamsoft JavaScript Library for Code Parser
* More info on dcp JS: https://www.dynamsoft.com/code-parser/docs/web/programming/javascript/
*/
!function(){"use strict";let e=new Map,s=new Map;const t=self;async function a(e,s){return await new Promise(((t,a)=>{let n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType=s,n.send(),n.onloadend=async()=>{n.status<200||n.status>=300?a(e+" "+n.status):t(n.response)},n.onerror=()=>{a(new Error("Network Error: "+n.statusText))}}))}t.dcpWorkerVersion="2.4.20";const n=t.checkAndAutoLoadResourceBuffer=async(t,n)=>{if(t=t.toUpperCase(),!e.has(t)){let r,c,o,i;e.set(t,(async()=>{try{const e=new TextDecoder;r=await a(n+t+".data","arraybuffer"),e.decode(new Uint8Array(r,0,8)).startsWith("DCPD_DLL")&&await loadDynamicLibrary(engineResourcePaths.dcp+"dedicator.wasm",{loadAsync:!0,global:!0,nodelete:!0,allowUndefined:!0});let d=0;const p=new Uint8Array(r,8,8);for(let e=7;e>=0;--e)d=256*d+p[e];const l=e.decode(new Uint8Array(r,16,d));c=JSON.parse(l),o=16+d;const m=(e=>{const s=c[e];if(!s)throw new Error(`File name ${e} not found.`);return new Uint8Array(r,o+s[0],s[1])})(t+".dcpres");i=UTF8ToString(wasmImports.emscripten_bind_DcpWasm_GetMapNameBySpecification_2(setBufferIntoWasm(m,0),m.length)),i&&!s.has(i)&&s.set(i,a(n+i,"arraybuffer"));const u=await s.get(i);if(u){const e=new Uint8Array(u);ep(),log(UTF8ToString(wasmImports.emscripten_bind_DcpWasm_AppendResourceBuffer_5(es(t+".dcpres"),setBufferIntoWasm(m,0),m.length,setBufferIntoWasm(e,1),e.length)))}else ep(),log(UTF8ToString(wasmImports.emscripten_bind_DcpWasm_AppendResourceBuffer_5(es(t+".dcpres"),setBufferIntoWasm(m,0),m.length,null,0)));return!0}catch(a){throw e.delete(t),s.delete(i),a}})())}await e.get(t)};Object.assign(mapController,{dcp_appendResourceBuffer:async(e,s)=>{try{for(let s of e.specificationNames)await n(s,e.specificationPath)}catch(e){return void postMessage({type:"task",id:s,body:{success:!1,message:(null==e?void 0:e.message)||e,stack:(null==e?void 0:e.stack)||e}})}handleTaskRes(s,{success:!0})},dcp_createInstance:async(e,s)=>{try{let e=wasmImports.emscripten_bind_DcpWasm_CreateInstance_0();handleTaskRes(s,{instanceID:e})}catch(e){return void handleTaskErr(s,e)}},dcp_dispose:async(e,s,t)=>{try{wasmImports.emscripten_bind_DcpWasm___destroy___0(t),handleTaskRes(s,{success:!0})}catch(e){handleTaskErr(s,e)}},dcp_initSettings:async(e,s,t)=>{try{await loadDynamicLibrary(engineResourcePaths.dcp+"dedicator.wasm",{loadAsync:!0,global:!0,nodelete:!0,allowUndefined:!0}),ep();let a=UTF8ToString(wasmImports.emscripten_bind_DcpWasm_InitSettings_1(t,es(e.settings)));handleTaskRes(s,{success:!0,response:a})}catch(e){return void handleTaskErr(s,e)}},dcp_resetSettings:async(e,s,t)=>{try{wasmImports.emscripten_bind_DcpWasm_ResetSettings_0(t),handleTaskRes(s,{success:!0})}catch(e){return void handleTaskErr(s,e)}},dcp_parse:async(e,s,t)=>{try{ep();let a=UTF8ToString(wasmImports.emscripten_bind_DcpWasm_Parse_3(t,setBufferIntoWasm(e.source,0),e.source.length,es(e.taskSettingName)));handleTaskRes(s,{success:!0,parseResponse:a})}catch(e){return void handleTaskErr(s,e)}}})}();
