Socket
Socket
Sign inDemoInstall

dynamsoft-label-recognizer

Package Overview
Dependencies
7
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.1 to 2.2.2

dist/dlr-2.2.2.wasm

4

dist/dlr.browser.esm.js

@@ -7,6 +7,6 @@ /*!

* @author Dynamsoft
* @version 2.2.1 (js 20220216)
* @version 2.2.2 (js 20220302)
* @fileoverview Dynamsoft JavaScript Library for Label Recognizer
* More info on DLR JS: https://www.dynamsoft.com/label-recognizer/sdk-javascript/
*/
function e(e,t,i,s){return new(i||(i=Promise))((function(n,r){function o(e){try{l(s.next(e))}catch(e){r(e)}}function a(e){try{l(s.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}l((s=s.apply(e,t||[])).next())}))}var t,i,s;!function(e){e[e.IPF_BINARY=0]="IPF_BINARY",e[e.IPF_BINARYINVERTED=1]="IPF_BINARYINVERTED",e[e.IPF_GRAYSCALED=2]="IPF_GRAYSCALED",e[e.IPF_NV21=3]="IPF_NV21",e[e.IPF_RGB_565=4]="IPF_RGB_565",e[e.IPF_RGB_555=5]="IPF_RGB_555",e[e.IPF_RGB_888=6]="IPF_RGB_888",e[e.IPF_ARGB_8888=7]="IPF_ARGB_8888",e[e.IPF_RGB_161616=8]="IPF_RGB_161616",e[e.IPF_ARGB_16161616=9]="IPF_ARGB_16161616",e[e.IPF_ABGR_8888=10]="IPF_ABGR_8888",e[e.IPF_ABGR_16161616=11]="IPF_ABGR_16161616",e[e.IPF_BGR_888=12]="IPF_BGR_888"}(t||(t={})),function(e){e[e.OK=0]="OK",e[e.UNKNOWN=-1e4]="UNKNOWN",e[e.NO_MEMORY=-10001]="NO_MEMORY",e[e.NULL_POINTER=-10002]="NULL_POINTER",e[e.LICENSE_INVALID=-10003]="LICENSE_INVALID",e[e.LICENSE_EXPIRED=-10004]="LICENSE_EXPIRED",e[e.FILE_NOT_FOUND=-10005]="FILE_NOT_FOUND",e[e.FILETYPE_NOT_SUPPORTED=-10006]="FILETYPE_NOT_SUPPORTED",e[e.BPP_NOT_SUPPORTED=-10007]="BPP_NOT_SUPPORTED",e[e.IMAGE_READ_FAILED=-10012]="IMAGE_READ_FAILED",e[e.TIFF_READ_FAILED=-10013]="TIFF_READ_FAILED",e[e.PDF_READ_FAILED=-10021]="PDF_READ_FAILED",e[e.PDF_DLL_MISSING=-10022]="PDF_DLL_MISSING",e[e.RECOGNITION_TIMEOUT=-10026]="RECOGNITION_TIMEOUT",e[e.JSON_PARSE_FAILED=-10030]="JSON_PARSE_FAILED",e[e.JSON_TYPE_INVALID=-10031]="JSON_TYPE_INVALID",e[e.JSON_KEY_INVALID=-10032]="JSON_KEY_INVALID",e[e.JSON_VALUE_INVALID=-10033]="JSON_VALUE_INVALID",e[e.JSON_NAME_KEY_MISSING=-10034]="JSON_NAME_KEY_MISSING",e[e.JSON_NAME_VALUE_DUPLICATED=-10035]="JSON_NAME_VALUE_DUPLICATED",e[e.TEMPLATE_NAME_INVALID=-10036]="TEMPLATE_NAME_INVALID",e[e.PARAMETER_VALUE_INVALID=-10038]="PARAMETER_VALUE_INVALID",e[e.SET_MODE_ARGUMENT_ERROR=-10051]="SET_MODE_ARGUMENT_ERROR",e[e.GET_MODE_ARGUMENT_ERROR=-10055]="GET_MODE_ARGUMENT_ERROR",e[e.CHARACTER_MODEL_FILE_NOT_FOUND=-10100]="CHARACTER_MODEL_FILE_NOT_FOUND"}(i||(i={})),function(e){e[e.LST_MANUAL_SPECIFICATION=1]="LST_MANUAL_SPECIFICATION",e[e.LST_PREDETECTED_REGION=2]="LST_PREDETECTED_REGION",e[e.LST_BARCODE=4]="LST_BARCODE"}(s||(s={})),"object"==typeof global&&global.process&&global.process.release&&global.process.release.name;const n="undefined"==typeof self,r=n?{}:self;class o{constructor(){this._canvasMaxWH="iPhone"==o.browserInfo.OS||"Android"==o.browserInfo.OS?2048:4096,this._instanceID=void 0,this.bSaveOriCanvas=!1,this.oriCanvas=null,this._region=null,this._timeStartRecognize=null,this._timeEnterInnerDLR=null,this.recognizeRecords={},this.drawRegionsultRecords={},this.bDestroyed=!1,this._setWarnnedEx=new Set,this._lastErrorCode=0,this._lastErrorString="",this._lastInnerDecodeDuration=0,this._clickIptSingleFrameMode=()=>{},this.intervalTime=0,this._intervalGetVideoFrame=0,this.array_getFrameTimeCost=[],this.array_decodeFrameTimeCost=[],this._bPauseScan=!1,this._intervalDetectVideoPause=1e3,this._cvsDrawArea=null,this._divScanArea=null,this._divScanLight=null,this._selCam=null,this._selRsl=null,this._selMinLtr=null,this._optGotMinLtr=null,this._btnClose=null,this._minLetter=0,this._soundOnSuccessfullRead=new Audio("data:audio/mpeg;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjI5LjEwMAAAAAAAAAAAAAAA/+M4wAAAAAAAAAAAAEluZm8AAAAPAAAABQAAAkAAgICAgICAgICAgICAgICAgICAgKCgoKCgoKCgoKCgoKCgoKCgoKCgwMDAwMDAwMDAwMDAwMDAwMDAwMDg4ODg4ODg4ODg4ODg4ODg4ODg4P//////////////////////////AAAAAExhdmM1OC41NAAAAAAAAAAAAAAAACQEUQAAAAAAAAJAk0uXRQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/+MYxAANQAbGeUEQAAHZYZ3fASqD4P5TKBgocg+Bw/8+CAYBA4XB9/4EBAEP4nB9+UOf/6gfUCAIKyjgQ/Kf//wfswAAAwQA/+MYxAYOqrbdkZGQAMA7DJLCsQxNOij///////////+tv///3RWiZGBEhsf/FO/+LoCSFs1dFVS/g8f/4Mhv0nhqAieHleLy/+MYxAYOOrbMAY2gABf/////////////////usPJ66R0wI4boY9/8jQYg//g2SPx1M0N3Z0kVJLIs///Uw4aMyvHJJYmPBYG/+MYxAgPMALBucAQAoGgaBoFQVBUFQWDv6gZBUFQVBUGgaBr5YSgqCoKhIGg7+IQVBUFQVBoGga//SsFSoKnf/iVTEFNRTMu/+MYxAYAAANIAAAAADEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"),this.bPlaySoundOnSuccessfulRead=!1,this.bVibrateOnSuccessfulRead=!1,this.vibrateDuration=300,this.regionMaskFillStyle="rgba(0,0,0,0.5)",this.regionMaskStrokeStyle="rgb(254,142,20)",this.regionMaskLineWidth=2,this.highlightFillStyle="rgba(254,180,32,0.3)",this.highlightStrokeStyle="rgba(254,180,32,0.9)",this.highlightLineWidth=1,this.beingLazyDrawRegionsults=!1,this.currentSettingsTemplate="cppdefault",this.dce=null,this._onCameraSelChange=()=>{this._divScanLight&&(this._divScanLight.style.display="none"),this._drawRegionsults(),this.array_decodeFrameTimeCost.length=0,this.array_getFrameTimeCost.length=0,this._intervalGetVideoFrame=0},this._onResolutionSelChange=()=>{this._divScanLight&&(this._divScanLight.style.display="none"),this._drawRegionsults(),this.array_decodeFrameTimeCost.length=0,this.array_getFrameTimeCost.length=0,this._intervalGetVideoFrame=0},this._onMinLetterSelChange=t=>e(this,void 0,void 0,(function*(){let e=t.target.value;if("got"===e)return;e=JSON.parse(e);let i=JSON.parse(yield this.outputRuntimeSettingsToString());i.LabelRecognizerParameterArray[0].LineStringLengthRange=[e,999],i.TextAreaArray[0].LineStringLengthRange=[e,999],yield this.updateRuntimeSettingsFromString(i)})),this._onCloseBtnClick=()=>{this.stopScanning(!0)},this._tempSolutionStatus="closed"}static getVersion(){return this._version}static get license(){return this._license}static set license(e){if("unload"!=this._loadWasmStatus)throw new Error("`license` is not allowed to change after `createInstance` or `loadWasm` is called.");o._license=e}static initLicense(e){if("unload"!=this._loadWasmStatus)throw new Error("`license` is not allowed to change after `createInstance` or `loadWasm` is called.");o._license=e}static set sessionPassword(e){if("unload"!=this._loadWasmStatus)throw new Error("`sessionPassword` is not allowed to change after `createInstance` or `loadWasm` is called.");o._sessionPassword=e}static get sessionPassword(){return this._sessionPassword}static detectEnvironment(){return e(this,void 0,void 0,(function*(){let e={wasm:"undefined"!=typeof WebAssembly&&("undefined"==typeof navigator||!(/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)&&/\(.+\s11_2_([2-6]).*\)/.test(navigator.userAgent))),worker:!("undefined"==typeof Worker),getUserMedia:!("undefined"==typeof navigator||!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia),camera:!1,browser:this.browserInfo.browser,version:this.browserInfo.version,OS:this.browserInfo.OS};if(e.getUserMedia)try{(yield navigator.mediaDevices.getUserMedia({video:!0})).getTracks().forEach((e=>{e.stop()})),e.camera=!0}catch(e){}return e}))}static get engineResourcePath(){return this._engineResourcePath}static set engineResourcePath(e){if("unload"!=this._loadWasmStatus)throw new Error("`engineResourcePath` is not allowed to change after `createInstance` or `loadWasm` is called.");if(null==e&&(e="./"),n)o._engineResourcePath=e;else{let t=document.createElement("a");t.href=e,o._engineResourcePath=t.href}this._engineResourcePath.endsWith("/")||(o._engineResourcePath+="/")}static get licenseServer(){return this._licenseServer}static set licenseServer(e){if("unload"!=this._loadWasmStatus)throw new Error("`licenseServer` is not allowed to change after `createInstance` or `loadWasm` is called.");if(null==e)o._licenseServer=[];else{e instanceof Array||(e=[e]);for(let t=0;t<e.length;++t){if(!n){let i=document.createElement("a");i.href=e[t],e[t]=i.href}e[t].endsWith("/")||(e[t]+="/")}o._licenseServer=e}}static get deviceFriendlyName(){return this._deviceFriendlyName}static set deviceFriendlyName(e){if("unload"!=this._loadWasmStatus)throw new Error("`deviceFriendlyName` is not allowed to change after loadWasm is called.");o._deviceFriendlyName=e||""}get ifSaveOriginalImageInACanvas(){return this.bSaveOriCanvas}set ifSaveOriginalImageInACanvas(e){this.dce&&(this.dce.ifSaveOriginalImageInACanvas=e),this.bSaveOriCanvas=e}getOriginalImageInACanvas(){return this.oriCanvas}set region(e){this._region=e,this.dce&&!this.singleFrameMode&&(this.beingLazyDrawRegionsults=!0,setTimeout((()=>{this.beingLazyDrawRegionsults&&this._drawRegionsults()}),500))}get region(){return this._region}static isWasmLoaded(){return"loadSuccess"==this._loadWasmStatus}isContextDestroyed(){return this.bDestroyed}static get lastErrorCode(){return this._lastErrorCode}static get lastErrorString(){return this._lastErrorString}get lastErrorCode(){return this._lastErrorCode}get lastErrorString(){return this._lastErrorString}static get defaultUIElementURL(){var e;return null===(e=this._defaultUIElementURL)||void 0===e?void 0:e.replace("@engineResourcePath/",o.engineResourcePath)}static set defaultUIElementURL(e){this._defaultUIElementURL=e}get singleFrameMode(){if(!this.dce)throw new Error("Need to set 'cameraEnhancer' first.");return this.dce.singleFrameMode}set singleFrameMode(t){if(!this.dce)throw new Error("Need to set 'cameraEnhancer' first.");this.dce.singleFrameMode=t,t&&(()=>{e(this,void 0,void 0,(function*(){let e=yield this.getScanSettings();e.trustFrameCount=1,yield this.updateScanSettings(e)}))})()}_assertOpen(){if(!this.dce)throw new Error("Need to set 'cameraEnhancer' first.");if(!this.dce.isOpen())throw Error("The camera is not open.")}_updateMinLtrSel(e){if(this._minLetter=e,this._optGotMinLtr){const t=e?`${e}+ letters`:"any letter";this._optGotMinLtr.innerText=t,this._selMinLtr&&this._optGotMinLtr.parentNode==this._selMinLtr&&(this._selMinLtr.value="got")}}get soundOnSuccessfullRead(){return this._soundOnSuccessfullRead}set soundOnSuccessfullRead(e){e instanceof HTMLAudioElement?this._soundOnSuccessfullRead=e:this._soundOnSuccessfullRead=new Audio(e)}get whenToPlaySoundforSuccessfulRead(){return!0===this.bPlaySoundOnSuccessfulRead?"frame":this.bPlaySoundOnSuccessfulRead?this.bPlaySoundOnSuccessfulRead:"never"}set whenToPlaySoundforSuccessfulRead(e){this.bPlaySoundOnSuccessfulRead="never"!==e&&e}get whenToVibrateforSuccessfulRead(){return!0===this.bVibrateOnSuccessfulRead?"frame":this.bVibrateOnSuccessfulRead?this.bVibrateOnSuccessfulRead:"never"}set whenToVibrateforSuccessfulRead(e){this.bVibrateOnSuccessfulRead="never"!==e&&e}get cameraEnhancer(){return this.dce}set cameraEnhancer(e){this.dce=e,this.adjustDCESettings()}adjustDCESettings(){this.dce&&(o._onLog&&o._onLog("adjustDCESettings()"),this.dce.bufferRefreshInterval=200,this.dce.alwaysRefreshBuffer=!1,this.dce.ifSaveOriginalImageInACanvas=this.bSaveOriCanvas,this.dce._singleFrameModeIpt=function(){let t=document.createElement("input");return t.setAttribute("type","file"),t.setAttribute("accept","image/*"),t.setAttribute("capture",""),t.addEventListener("change",(()=>e(this,void 0,void 0,(function*(){let e=t.files[0];t.value="",this.onSingleFrameAcquired(e)})))),t.style.position="fixed",t.style.left="0",t.style.top="0",t.style.width="1px",t.style.height="1px",t.style.backgroundColor="transparent",t.style.color="transparent",this._video.parentElement.appendChild(t),t},this.dce.onSingleFrameAcquired=t=>e(this,void 0,void 0,(function*(){let e=yield this.recognize(t);yield this.clearMapDecodeRecord();for(let t of e)for(let e of t.lineResults)e.bUnduplicated&&delete t.bUnduplicated;if(this._drawRegionsults(e),this.onFrameRead&&this.dce.isOpen()&&!this._bPauseScan&&this.onFrameRead(e),this.onUniqueRead&&this.dce.isOpen()&&!this._bPauseScan)for(let t of e){if(["passportMRZ","visaMRZ","MRZ"].includes(this.currentSettingsTemplate)){let e="";for(let i of t.lineResults)i.bUnduplicated&&(e.length>0&&(e+="\n"),e+=i.text);e.length>0&&this.onUniqueRead(e,this._cloneDecodeResults(t.lineResults))}else for(let e of t.lineResults)e.bUnduplicated&&this.onUniqueRead(e.text,[this._cloneDecodeResults(e)])}})),this._clickIptSingleFrameMode=this.dce._clickIptSingleFrameMode)}static loadWasm(){return e(this,void 0,void 0,(function*(){let t,s=this.license,n=JSON.parse(JSON.stringify(this._licenseServer)),a=this._sessionPassword,l=null,c=null,d=0;if(s.startsWith("t")||s.startsWith("f"))d=0;else if(0===s.length||s.startsWith("P")||s.startsWith("L"))d=1;else{d=2;const e=s.indexOf(":");if(-1!=e&&(s=s.substring(e+1)),s.startsWith("DLS2")){let e=s.substring(4);e=atob(e);const t=JSON.parse(e);if(t.handshakeCode?s=t.handshakeCode:t.organizationID&&(s=t.organizationID),"number"==typeof s&&(s=JSON.stringify(s)),s||(s=""),0===n.length){let e=[];t.mainServerURL&&(e[0]=t.mainServerURL),t.standbyServerURL&&(e[1]=t.standbyServerURL),this.licenseServer=e,n=this.licenseServer}!a&&t.sessionPassword&&(a=t.sessionPassword),t.chargeWay&&(c=t.chargeWay),t.limitedLicenseModules&&(l=t.limitedLicenseModules)}}if(d&&(r.crypto||(t="Please upgrade your browser to support online key."),r.crypto.subtle||(t="Require https to use online key in this browser.")),t){if(1!==d)throw new Error(t);d=0,console.warn(t),this._lastErrorCode=i.UNKNOWN,this._lastErrorString=t}return 1===d&&(s="",console.warn("Applying for a public trial license ...")),yield new Promise(((t,i)=>e(this,void 0,void 0,(function*(){switch(this._loadWasmStatus){case"unload":{o._loadWasmStatus="loading";let t=this.engineResourcePath+this._workerName;this.engineResourcePath.startsWith(location.origin)||(t=yield fetch(t).then((e=>e.blob())).then((e=>URL.createObjectURL(e)))),o._dlrWorker=new Worker(t),this._dlrWorker.onerror=e=>{o._loadWasmStatus="loadFail";let t=new Error(e.message);this._loadWasmErr=t;for(let e of this._loadWasmCallbackArr)e(t);this._loadWasmCallbackArr=[]},this._dlrWorker.onmessage=t=>e(this,void 0,void 0,(function*(){let e=t.data?t.data:t;switch(e.type){case"log":this._onLog&&this._onLog(e.message);break;case"load":{e.message&&(e.message=e.message.replace("(https://www.dynamsoft.com/purchase-center/)","(https://www.dynamsoft.com/store/dynamsoft-label-recognizer/#javascript)"));let t=!1;if(1===d&&(t=!0),e.success){o._loadWasmStatus="loadSuccess",o._version=e.version+"(JS "+this._jsVersion+"."+this._jsEditVersion+")",this._onLog&&this._onLog("load dlr worker success");for(let e of this._loadWasmCallbackArr)e();this._loadWasmCallbackArr=[],this._dlrWorker.onerror=null,e.message&&console.warn(e.message)}else{let i=new Error(e.message);i.stack=e.stack+"\n"+i.stack,o._loadWasmStatus="loadFail",this._loadWasmErr=i;for(let e of this._loadWasmCallbackArr)e(i);this._loadWasmCallbackArr=[],t||111==e.ltsErrorCode&&-1!=e.message.toLowerCase().indexOf("trial license")&&(t=!0)}t&&this.showDialog(e.success?"warn":"error",e.message);break}case"task":{let t=e.id,i=e.body;try{this._taskCallbackMap.get(t)(i),this._taskCallbackMap.delete(t)}catch(e){throw this._taskCallbackMap.delete(t),e}break}case"message":"modelLoadStarted"===e.body.message?o.onResourcesLoadStarted&&setTimeout((()=>o.onResourcesLoadStarted(e.body.resourcesPath)),0):"modelLoaded"===e.body.message&&o.onResourcesLoaded&&setTimeout((()=>o.onResourcesLoaded(e.body.resourcesPath)),0);default:this._onLog&&this._onLog(t)}})),this._dlrWorker.postMessage({type:"loadWasm",bd:this._bWasmDebug,engineResourcePath:this.engineResourcePath,version:this._jsVersion,brtk:!!d,bptk:1===d,lcs:s,dm:location.origin.startsWith("http")?location.origin:"https://localhost",browserInfo:this.browserInfo,deviceFriendlyName:this.deviceFriendlyName,ls:n,sp:a,lm:l,cw:c})}case"loading":this._loadWasmCallbackArr.push((e=>{e?i(e):t()}));break;case"loadSuccess":t();break;case"loadFail":i(this._loadWasmErr)}}))))}))}static showDialog(t,i){return e(this,void 0,void 0,(function*(){if(!this._bNeverShowDialog)try{let e=yield fetch(this.engineResourcePath+"dls.license.dialog.html");if(!e.ok)throw Error("Get license dialog fail. Network Error: "+e.statusText);let s=yield e.text();if(!s.trim().startsWith("<"))throw Error("Get license dialog fail. Can't get valid HTMLElement.");let n=document.createElement("div");n.innerHTML=s;let r=[];for(let e=0;e<n.childElementCount;++e){let t=n.children[e];t instanceof HTMLStyleElement&&(r.push(t),document.head.append(t))}let o=1==n.childElementCount?n.children[0]:n;o.remove();let a,l,c,d,h,u=[o],g=o.children;for(let e of g)u.push(e);for(let e=0;e<u.length;++e)for(let t of u[e].children)u.push(t);for(let e of u)if(!a&&e.classList.contains("dls-license-mask"))a=e,e.addEventListener("click",(t=>{if(e==t.target){o.remove();for(let e of r)e.remove()}}));else if(!l&&e.classList.contains("dls-license-icon-close"))l=e,e.addEventListener("click",(()=>{o.remove();for(let e of r)e.remove()}));else if(!c&&e.classList.contains("dls-license-icon-error"))c=e,"error"!=t&&e.remove();else if(!d&&e.classList.contains("dls-license-icon-warn"))d=e,"warn"!=t&&e.remove();else if(!h&&e.classList.contains("dls-license-msg-content")){h=e;let t=i;for(;t;){let i=t.indexOf("["),s=t.indexOf("]",i),n=t.indexOf("(",s),r=t.indexOf(")",n);if(-1==i||-1==s||-1==n||-1==r){e.appendChild(new Text(t));break}i>0&&e.appendChild(new Text(t.substring(0,i)));let o=document.createElement("a"),a=t.substring(i+1,s);o.innerText=a;let l=t.substring(n+1,r);o.setAttribute("href",l),o.setAttribute("target","_blank"),e.appendChild(o),t=t.substring(r+1)}}document.body.appendChild(o)}catch(e){this._onLog&&this._onLog(e.message||e)}}))}static createInstanceInWorker(){return e(this,void 0,void 0,(function*(){return yield this.loadWasm(),yield new Promise(((e,t)=>{let i=this._nextTaskID++;this._taskCallbackMap.set(i,(i=>{if(i.success)return e(i.instanceID);{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),this._dlrWorker.postMessage({type:"createInstance",id:i,bScanner:!1})}))}))}static createInstance(t){return e(this,void 0,void 0,(function*(){let e=new o;return e._instanceID=yield this.createInstanceInWorker(),t&&t.runtimeSettings&&e.updateRuntimeSettingsFromString(t.runtimeSettings),e}))}recognize(i,s){return e(this,void 0,void 0,(function*(){if(o._onLog&&o._onLog("recognize(source: any, modelName?: string)"),o._onLog&&(this._timeStartRecognize=Date.now()),s=s||{},i instanceof Blob)return yield this._recognize_Blob(i,s);if(i instanceof ArrayBuffer)return yield this._recognize_ArrayBuffer(i,s);if(i instanceof Uint8Array||i instanceof Uint8ClampedArray)return yield this._recognize_Uint8Array(i,s);if(i instanceof HTMLImageElement||"undefined"!=typeof ImageBitmap&&i instanceof ImageBitmap)return yield this._recognize_Image(i,s);if(i instanceof HTMLCanvasElement||"undefined"!=typeof OffscreenCanvas&&i instanceof OffscreenCanvas)return yield this._recognize_Canvas(i,s);if(i instanceof HTMLVideoElement)return yield this._recognize_Video(i,s);if("string"==typeof i)return"data:image/"==i.substring(0,11)?yield this._recognize_Base64(i,s):yield this._recognize_Url(i,s);if(i&&"object"==typeof i){const{data:e,canvas:s,region:n,sx:r,sy:o,width:a,height:l}=i;return s&&e?yield this._recognizeBuffer_Uint8Array(e,s.width,s.height,4*s.width,t.IPF_ABGR_8888):e&&a&&l?yield this._recognizeBuffer_Uint8Array(e,a,l,a,t.IPF_GRAYSCALED):yield Promise.reject(TypeError("'_recognize(source, config)': Type of 'source' should be 'Blob', 'ArrayBuffer', 'Uint8Array', 'HTMLImageElement', 'HTMLCanvasElement', 'HTMLVideoElement', 'string(base64 with image mime)', 'string(url)' or 'object(dceFrame)'."))}return yield Promise.reject(TypeError("'_recognize(source, config)': Type of 'source' should be 'Blob', 'ArrayBuffer', 'Uint8Array', 'HTMLImageElement', 'HTMLCanvasElement', 'HTMLVideoElement', 'string(base64 with image mime)', 'string(url)' or 'object(dceFrame)'."))}))}recognizeBase64String(t,i){return e(this,void 0,void 0,(function*(){let e={};return i&&(e.modelName=i),this._recognize_Base64(t,e)}))}recognizeUrl(t,i){return e(this,void 0,void 0,(function*(){let e={};return i&&(e.modelName=i),this._recognize_Url(t,e)}))}_recognizeBuffer_Uint8Array(t,i,s,n,r,a){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,l)=>{let c=o._nextTaskID++;o._taskCallbackMap.set(c,(t=>{if(t.success){let i,s=o._onLog?Date.now():0;this._lastInnerDecodeDuration=t.duration,this.bufferShared&&!this.bufferShared.length&&(this.bufferShared=t.buffer);try{i=this._handleRetJsonString(t.decodeReturn);const e=e=>!!e&&("VIN_NA"===this.currentSettingsTemplate?this._checkValidVIN(e):"passportMRZ"===this.currentSettingsTemplate?44==e.length&&(/[0-9]/.test(e)?this._checkValidMRP(e):null):"visaMRZ"===this.currentSettingsTemplate?(44==e.length||36==e.length)&&(/[0-9]/.test(e)?this._checkValidMRV(e):null):null);for(let t of i)for(let i of t.lineResults)i.isCheckDigitMatched=e(i.text)}catch(e){return l(e)}if(o._onLog){let e=Date.now();o._onLog("time get result: "+s),o._onLog("Handle image cost: "+(this._timeEnterInnerDLR-this._timeStartRecognize)),o._onLog("worker recognize image cost: "+(s-this._timeEnterInnerDLR)),o._onLog("worker handle results: "+(e-s)),o._onLog("Total recognize image cost: "+(e-this._timeStartRecognize))}return e(i)}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,l(e)}})),o._onLog&&(this._timeEnterInnerDLR=Date.now()),o._onLog&&o._onLog("Send buffer to worker:"+this._timeEnterInnerDLR),o._dlrWorker.postMessage({type:"recognizeByBuffer",id:c,instanceID:this._instanceID,body:{config:a,imageData:{bytes:t,length:s*i*4,width:i,height:s,stride:n,format:r}}},[t.buffer])}))}))}_recognizeBuffer_Blob(t,i,s,n,r,a){return e(this,void 0,void 0,(function*(){o._onLog&&o._onLog("_recognizeBuffer_Blob(buffer,width,height,stride,format)");const e=t.arrayBuffer?yield t.arrayBuffer():yield new Promise(((e,i)=>{let s=new FileReader;s.readAsArrayBuffer(t),s.onload=()=>{e(s.result)},s.onerror=()=>{i(s.error)}}));return yield this._recognizeBuffer_Uint8Array(new Uint8Array(e),i,s,n,r,a)}))}recognizeBuffer(t,i,s,n,r,a){return e(this,void 0,void 0,(function*(){let e;return o._onLog&&o._onLog("recognizeBuffer(buffer,width,height,stride,format)"),o._onLog&&(this._timeStartRecognize=Date.now()),t instanceof Uint8Array||t instanceof Uint8ClampedArray?e=yield this._recognizeBuffer_Uint8Array(t,i,s,n,r,a):t instanceof ArrayBuffer?e=yield this._recognizeBuffer_Uint8Array(new Uint8Array(t),i,s,n,r,a):t instanceof Blob&&(e=yield this._recognizeBuffer_Blob(t,i,s,n,r,a)),e}))}_recognizeFileInMemory_Uint8Array(t,i){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,s)=>{let n=o._nextTaskID++;o._taskCallbackMap.set(n,(t=>{if(t.success){let i;try{i=this._handleRetJsonString(t.decodeReturn)}catch(e){return s(e)}return e(i)}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,s(e)}})),o._dlrWorker.postMessage({type:"recognizeFileInMemory",id:n,instanceID:this._instanceID,body:{config:i,bytes:t}})}))}))}getRuntimeSettings(){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=o._nextTaskID++;o._taskCallbackMap.set(i,(i=>{if(i.success){let t=JSON.parse(i.results);return e(t)}{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),o._dlrWorker.postMessage({type:"getRuntimeSettings",id:i,instanceID:this._instanceID})}))}))}static isRegionNormalPreset(e){return s.LST_MANUAL_SPECIFICATION==e.localizationSourceType&&1==e.regionMeasuredByPercentage&&JSON.stringify([{x:0,y:100},{x:100,y:0},{x:100,y:100},{x:0,y:100}])===JSON.stringify(e.location.points)}updateRuntimeSettings(t){return e(this,void 0,void 0,(function*(){let e;if("string"==typeof t){if(!(t=t.trim()).startsWith("{"))return void this.updateRuntimeSettingsFromString(t);e=JSON.parse(t)}else{if("object"!=typeof t)throw TypeError("'UpdateRuntimeSettings(settings)': Type of 'settings' should be 'string' or 'PlainObject'.");e=JSON.parse(JSON.stringify(t))}const i=e.referenceRegion;o.isRegionNormalPreset(i)?this.region=null:this.region=i,this._updateMinLtrSel(0),yield new Promise(((t,i)=>{let s=o._nextTaskID++;o._taskCallbackMap.set(s,(e=>{if(e.success){try{this._handleRetJsonString(e.updateReturn)}catch(e){i(e)}return t()}{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,i(t)}})),o._dlrWorker.postMessage({type:"updateRuntimeSettings",id:s,instanceID:this._instanceID,body:{settings:JSON.stringify(e)}})}))}))}resetRuntimeSettings(){return e(this,void 0,void 0,(function*(){return this.region=null,this._updateMinLtrSel(0),yield new Promise(((e,t)=>{let i=o._nextTaskID++;o._taskCallbackMap.set(i,(i=>{if(i.success)return e();{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),o._dlrWorker.postMessage({type:"resetRuntimeSettings",id:i,instanceID:this._instanceID})}))}))}updateRuntimeSettingsFromString(t){return e(this,void 0,void 0,(function*(){let e=0;if("string"==typeof t)if((t=t.trim()).startsWith("{"))t=JSON.parse(t);else{if(t.length>50)throw new Error("Error: preset longer than 50 letters.");const i=t.toLowerCase().split("-");if(i.length>2)throw new Error(`Error: '${t}' is not supported.`);if(i.includes("numberletter"))e=3,this.currentSettingsTemplate="numberLetter";else if(i.includes("numberuppercase"))e=3,this.currentSettingsTemplate="numberUppercase";else if(i.includes("number"))e=3,this.currentSettingsTemplate="number";else if(i.includes("letter"))e=3,this.currentSettingsTemplate="letter";else if(i.includes("passportmrz"))e=44,this.currentSettingsTemplate="passportMRZ";else if(i.includes("visamrz"))e=36,this.currentSettingsTemplate="visaMRZ";else if(i.includes("mrz"))e=30,this.currentSettingsTemplate="MRZ";else if(i.includes("vin_na"))e=14,this.currentSettingsTemplate="VIN_NA";else if(i.includes("vin"))e=14,this.currentSettingsTemplate="VIN";else{if(!i.includes("cppdefault"))throw new Error(`Error: '${t}' is not supported.`);this.currentSettingsTemplate="cppdefault"}i.includes("video")?this.region={localizationSourceType:s.LST_MANUAL_SPECIFICATION,location:{points:[{x:0,y:40},{x:100,y:40},{x:100,y:60},{x:0,y:60}]},regionMeasuredByPercentage:1}:this.region=null}else{if("object"!=typeof t)throw TypeError("'updateRuntimeSettingsFromString(settings)': Type of 'settings' should be 'string' or 'PlainObject'.");this.currentSettingsTemplate=null}if("object"==typeof t){const i=t.ReferenceRegionArray[0].Localization,n=i.FirstPoint?{localizationSourceType:s[i.SourceType],location:{points:[{x:i.FirstPoint[0],y:i.FirstPoint[1]},{x:i.SecondPoint[0],y:i.SecondPoint[1]},{x:i.ThirdPoint[0],y:i.ThirdPoint[1]},{x:i.FourthPoint[0],y:i.FourthPoint[1]}]},regionMeasuredByPercentage:i.MeasuredByPercentage}:null;n&&o.isRegionNormalPreset(n)?this.region=null:this.region=n;const r=t.LabelRecognizerParameterArray[0].LineStringLengthRange;e=r?r[0]:0}return this._updateMinLtrSel(e),yield new Promise(((e,i)=>{let s=o._nextTaskID++;o._taskCallbackMap.set(s,(t=>{if(t.success){try{this._handleRetJsonString(t.updateReturn)}catch(e){i(e)}return e()}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,i(e)}})),o._dlrWorker.postMessage({type:"updateRuntimeSettingsFromString",id:s,instanceID:this._instanceID,body:{settings:t}})}))}))}outputRuntimeSettingsToString(){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=o._nextTaskID++;o._taskCallbackMap.set(i,(i=>{if(i.success)return e(i.results);{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),o._dlrWorker.postMessage({type:"outputSettingsToString",id:i,instanceID:this._instanceID})}))}))}updateReferenceRegionFromBarcodeResults(t){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,i)=>{let s=o._nextTaskID++;o._taskCallbackMap.set(s,(t=>{if(t.success)return e();{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,i(e)}})),o._dlrWorker.postMessage({type:"updateReferenceRegionFromBarcodeResults",id:s,instanceID:this._instanceID,body:{dbrTextResults:t}})}))}))}static appendCaffeModelBuffer(t,i){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,s)=>{let n=o._nextTaskID++;o._taskCallbackMap.set(n,(t=>{if(t.success){try{return e()}catch(e){s(e)}return e()}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,s(e)}})),o._dlrWorker.postMessage({type:"appendCaffeModelBuffer",id:n,body:{name:t,folderUrl:i}})}))}))}static eraseCaffeModelByName(t){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,i)=>{let s=o._nextTaskID++;o._taskCallbackMap.set(s,(t=>{if(t.success)return e();{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,i(e)}})),o._dlrWorker.postMessage({type:"eraseCaffeModelByName",id:s,body:{name:t}})}))}))}static eraseAllCaffeModels(){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=o._nextTaskID++;o._taskCallbackMap.set(i,(i=>{if(i.success)return e();{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),o._dlrWorker.postMessage({type:"eraseAllCaffeModels",id:i})}))}))}_recognize_Blob(t,i){return e(this,void 0,void 0,(function*(){o._onLog&&o._onLog("_recognize_Blob(blob: Blob)");let e=null,s=null;if("undefined"!=typeof createImageBitmap)try{e=yield createImageBitmap(t)}catch(e){}e||(s=yield function(e){return new Promise(((t,i)=>{let s=URL.createObjectURL(e),n=new Image;n.dlrObjUrl=s,n.src=s,n.onload=()=>{t(n)},n.onerror=e=>{i(new Error("Can't convert blob to image : "+(e instanceof Event?e.type:e)))}}))}(t));let n=yield this._recognize_Image(e||s,i);return e&&e.close(),n}))}_recognize_ArrayBuffer(t,i){return e(this,void 0,void 0,(function*(){return yield this._recognize_Blob(new Blob([t]),i)}))}_recognize_Uint8Array(t,i){return e(this,void 0,void 0,(function*(){return yield this._recognize_Blob(new Blob([t]),i)}))}_recognize_Image(t,i){return e(this,void 0,void 0,(function*(){o._onLog&&o._onLog("_recognize_Image(image: HTMLImageElement|ImageBitmap)"),i=i||{};let e,s,n=t instanceof HTMLImageElement?t.naturalWidth:t.width,a=t instanceof HTMLImageElement?t.naturalHeight:t.height,l=Math.max(n,a);if(l>this._canvasMaxWH){let t=this._canvasMaxWH/l;e=Math.round(n*t),s=Math.round(a*t)}else e=n,s=a;let c,d=n,h=a,u=e,g=s;!this.bSaveOriCanvas&&r.OffscreenCanvas?c=new OffscreenCanvas(u,g):(c=document.createElement("canvas"),c.width=u,c.height=g);let _=c.getContext("2d");return n==d&&a==h&&n==u&&a==g?_.drawImage(t,0,0):_.drawImage(t,0,0,d,h,0,0,u,g),t.dlrObjUrl&&URL.revokeObjectURL(t.dlrObjUrl),yield this._recognize_Canvas(c,i)}))}_recognize_Canvas(i,s){return e(this,void 0,void 0,(function*(){if(o._onLog&&o._onLog("_recognize_Canvas(canvas:HTMLCanvasElement)"),i.crossOrigin&&"anonymous"!=i.crossOrigin)throw"cors";(this.bSaveOriCanvas||this.dce&&this.singleFrameMode)&&(this.oriCanvas=i);let e=(i.dlrCtx2d||i.getContext("2d")).getImageData(0,0,i.width,i.height).data;return yield this._recognizeBuffer_Uint8Array(e,i.width,i.height,4*i.width,t.IPF_ABGR_8888,s)}))}_recognize_Video(t,i){return e(this,void 0,void 0,(function*(){if(o._onLog&&o._onLog("_recognize_Video(video)"),!(t instanceof HTMLVideoElement))throw TypeError("'_recognize_Video(video [, config] )': Type of 'video' should be 'HTMLVideoElement'.");if(t.crossOrigin&&"anonymous"!=t.crossOrigin)throw"cors";i=i||{};let e,s,n=t.videoWidth,a=t.videoHeight,l=Math.max(n,a);if(l>this._canvasMaxWH){let t=this._canvasMaxWH/l;e=Math.round(n*t),s=Math.round(a*t)}else e=n,s=a;let c=n,d=a,h=e,u=s,g=n==c&&a==d&&n==h&&a==u,_=null;!this.bSaveOriCanvas&&r.OffscreenCanvas?_=new OffscreenCanvas(h,u):(_=document.createElement("canvas"),_.width=h,_.height=u);const f=_.dlrCtx2d=_.getContext("2d");return g?f.drawImage(t,0,0):f.drawImage(t,0,0,c,d,0,0,h,u),yield this._recognize_Canvas(_,i)}))}_recognize_Base64(t,i){return e(this,void 0,void 0,(function*(){if(o._onLog&&o._onLog("_recognize_Base64(base64Str)"),"string"!=typeof t&&"object"!=typeof t)return Promise.reject("'_recognize_Base64(base64Str, config)': Type of 'base64Str' should be 'string'.");"data:image/"==t.substring(0,11)&&(t=t.substring(t.indexOf(",")+1));{let e=atob(t),s=e.length,n=new Uint8Array(s);for(;s--;)n[s]=e.charCodeAt(s);return yield this._recognize_Blob(new Blob([n]),i)}}))}_recognize_Url(t,i){return e(this,void 0,void 0,(function*(){if(o._onLog&&o._onLog("_recognize_Url(url)"),"string"!=typeof t&&"object"!=typeof t)throw TypeError("'_recognize_Url(url, config)': Type of 'url' should be 'string'.");{let s=yield new Promise(((i,s)=>{let n=new XMLHttpRequest;n.open("GET",t,!0),n.responseType="blob",n.send(),n.onloadend=()=>e(this,void 0,void 0,(function*(){i(n.response)})),n.onerror=()=>{s(new Error("Network Error: "+n.statusText))}}));return yield this._recognize_Blob(s,i)}}))}_recognize_FilePath(t,i){return e(this,void 0,void 0,(function*(){throw o._onLog&&o._onLog("_recognize_FilePath(path)"),Error("'_recognize_FilePath(path, config)': The method is only supported in node environment.")}))}static LabelRecognizerException(e,t){let s,n=i.UNKNOWN;return"number"==typeof e?(n=e,s=new Error(t)):s=new Error(e),s.code=n,s}_handleRetJsonString(e){let t=i;if(e.results){const t=this.drawRegionsultRecords,s={};for(let i=0;i<e.results.length;i++){let n=e.results[i];if(null!=n.exception){this._setWarnnedEx.has(n.exception)||(this._setWarnnedEx.add(n.exception),console.warn(n.exception));let e={};n.exception.split(";").forEach((t=>{let i=t.indexOf(":");e[t.substring(0,i)]=t.substring(i+1)})),n.exception=e}for(let e of n.lineResults){const i=e.text;if(s[i]=1,e.bUnduplicated){(t[i]=t[i]||[]).push(e)}else t[i]&&(t[i]=[e])}}if(e.records){const i=this.recognizeRecords=e.records;for(let e in t)i[e]||delete t[e];for(let e in t)s[e]||(t[e]=[])}else this.recognizeRecords={},this.drawRegionsultRecords={};return this._lastErrorCode=e.exception,this._lastErrorString=e.description,e.exception&&!this._setWarnnedEx.has(e.description)&&(this._setWarnnedEx.add(e.description),e.exception==i.LICENSE_INVALID||e.exception==i.LICENSE_EXPIRED?console.error(e.description):console.warn(e.description)),e.results}if(e.exception==t.OK)return e.data;throw o.LabelRecognizerException(e.exception,e.description)}setModeArgument(t,i,s,n){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,r)=>{let a=o._nextTaskID++;o._taskCallbackMap.set(a,(t=>{if(t.success){try{this._handleRetJsonString(t.setReturn)}catch(e){return r(e)}return e()}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,r(e)}})),o._dlrWorker.postMessage({type:"setModeArgument",id:a,instanceID:this._instanceID,body:{modeName:t,index:i,argumentName:s,argumentValue:n}})}))}))}getModeArgument(t,i,s){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,n)=>{let r=o._nextTaskID++;o._taskCallbackMap.set(r,(t=>{if(t.success){let i;try{i=this._handleRetJsonString(t.getReturn)}catch(e){return n(e)}return e(i)}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,n(e)}})),o._dlrWorker.postMessage({type:"getModeArgument",id:r,instanceID:this._instanceID,body:{modeName:t,index:i,argumentName:s}})}))}))}recognizeCurrentFrame(){return e(this,void 0,void 0,(function*(){this._assertOpen();let e=this.dce.getFrame();if(e&&null===e.canvas){let{data:i,width:s,height:n}=e;return yield this._recognizeBuffer_Uint8Array(i,s,n,s,t.IPF_GRAYSCALED)}if(e&&e.canvas){let{data:i,canvas:s}=e;return(this.bSaveOriCanvas||this.singleFrameMode)&&(this.oriCanvas=s),yield this._recognizeBuffer_Uint8Array(i,s.width,s.height,4*s.width,t.IPF_ABGR_8888)}}))}clearMapDecodeRecord(){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=o._nextTaskID++;o._taskCallbackMap.set(i,(i=>{if(i.success)return e();{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),o._dlrWorker.postMessage({type:"clearMapDecodeRecord",id:i,instanceID:this._instanceID})}))}))}_bindUI(){const e=this.dce.getUIElement();if(!e)throw new Error("Need to define `UIElement` before opening.");this.dce._bindUI();let t=[e],i=e.children;for(let e of i)t.push(e);for(let e=0;e<t.length;++e)for(let i of t[e].children)t.push(i);for(let e of t)!this._cvsDrawArea&&e.classList.contains("dlr-cvs-drawarea")?this._cvsDrawArea=e:!this._divScanArea&&e.classList.contains("dlr-cvs-scanarea")?this._divScanArea=e:!this._divScanLight&&e.classList.contains("dlr-scanlight")?this._divScanLight=e:!this._selCam&&e.classList.contains("dce-sel-camera")?this._selCam=e:!this._selRsl&&e.classList.contains("dce-sel-resolution")?this._selRsl=e:!this._selMinLtr&&e.classList.contains("dlr-sel-minletter")?(this._selMinLtr=e,this._selMinLtr.options.length||(this._selMinLtr.innerHTML=[this._optGotMinLtr?"":'<option class="dlr-opt-gotMinLtr" value="got"></option>','<option value="0" selected>any letter</option>','<option value="3">3+ letters</option>','<option value="5">5+ letters</option>','<option value="8">8+ letters</option>','<option value="12">12+ letters</option>','<option value="18">18+ letters</option>','<option value="30">30+ letters</option>','<option value="50">50+ letters</option>','<option value="80">80+ letters</option>','<option value="120">120+ letters</option>'].join(""),this._optGotMinLtr=this._optGotMinLtr||this._selMinLtr.options[0])):this._optGotMinLtr||!e.classList.contains("dlr-opt-gotMinLtr")&&!e.classList.contains("dlr-opt-gotMinLtr")?!this._btnClose&&e.classList.contains("dce-btn-close")&&(this._btnClose=e):this._optGotMinLtr=e;if(this.singleFrameMode&&(this._cvsDrawArea&&(this._cvsDrawArea.addEventListener("click",this._clickIptSingleFrameMode),this._cvsDrawArea.style.cursor="pointer",this._cvsDrawArea.setAttribute("title","Take a photo")),this._divScanArea&&(this._divScanArea.addEventListener("click",this._clickIptSingleFrameMode),this._divScanArea.style.cursor="pointer",this._divScanArea.setAttribute("title","Take a photo"))),this._selCam&&this._selCam.addEventListener("change",this._onCameraSelChange),this._selRsl&&this._selRsl.addEventListener("change",this._onResolutionSelChange),this._selMinLtr&&this._selMinLtr.addEventListener("change",this._onMinLetterSelChange),this._btnClose&&this._btnClose.addEventListener("click",this._onCloseBtnClick),!this.dce.video)throw this._unbindUI(),Error("Can not find HTMLVideoElement with class `dce-video`.");this._updateMinLtrSel(this._minLetter)}_unbindUI(){this._clearRegionsults(),this.singleFrameMode&&(this._cvsDrawArea&&(this._cvsDrawArea.removeEventListener("click",this._clickIptSingleFrameMode),this._cvsDrawArea.style.cursor="",this._cvsDrawArea.removeAttribute("title")),this._divScanArea&&(this._divScanArea.removeEventListener("click",this._clickIptSingleFrameMode),this._divScanArea.style.cursor="",this._divScanArea.removeAttribute("title"))),this._selCam&&this._selCam.removeEventListener("change",this._onCameraSelChange),this._selRsl&&this._selRsl.removeEventListener("change",this._onResolutionSelChange),this._selMinLtr&&this._selMinLtr.removeEventListener("change",this._onMinLetterSelChange),this._btnClose&&this._btnClose.removeEventListener("click",this._onCloseBtnClick),this.dce._unbindUI(),this._cvsDrawArea=null,this._divScanArea=null,this._divScanLight=null,this._selCam=null,this._selRsl=null,this._selMinLtr=null,this._optGotMinLtr=null,this._btnClose=null}getScanSettings(){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=o._nextTaskID++;o._taskCallbackMap.set(i,(i=>{if(i.success){let t=i.results;return t.intervalTime=this.intervalTime,e(t)}{let e=new Error(i.message);return e.stack+="\n"+i.stack,t(e)}})),o._dlrWorker.postMessage({type:"getScanSettings",id:i,instanceID:this._instanceID})}))}))}updateScanSettings(t){return e(this,void 0,void 0,(function*(){return this.intervalTime=t.intervalTime,yield new Promise(((e,i)=>{let s=o._nextTaskID++;o._taskCallbackMap.set(s,(t=>{if(t.success)return e();{let e=new Error(t.message);return e.stack+="\n"+t.stack,i(e)}})),o._dlrWorker.postMessage({type:"updateScanSettings",id:s,instanceID:this._instanceID,body:{settings:t}})}))}))}_show(){const e=this.dce.getUIElement();e.parentNode||(e.style.position="fixed",e.style.left="0",e.style.top="0",document.body.append(e)),"none"==e.style.display&&(e.style.display="")}stop(){this.dce&&this.dce.stop(),this._divScanLight&&(this._divScanLight.style.display="none"),this._drawRegionsults(),this.array_decodeFrameTimeCost.length=0,this.array_getFrameTimeCost.length=0,this._intervalGetVideoFrame=0}_cloneDecodeResults(e){if(e instanceof Array){let t=[];for(let i of e)t.push(this._cloneDecodeResults(i));return t}{let t=e;return JSON.parse(JSON.stringify(t,((e,t)=>"oriVideoCanvas"==e||"searchRegionCanvas"==e?void 0:t)))}}_loopReadVideo(){return e(this,void 0,void 0,(function*(){if(this.bDestroyed)return void(this.dce&&this.dce.stopFetchingLoop());if(!this.dce||!this.dce.isOpen())return this.dce&&this.dce.stopFetchingLoop(),void(yield this.clearMapDecodeRecord());if(!this.dce.video||this.dce.video.paused||this._bPauseScan)return o._onLog&&o._onLog("Video or scan is paused. Ask in 1s."),this.dce&&this.dce.stopFetchingLoop(),yield this.clearMapDecodeRecord(),this._loopReadVideoTimeoutId&&clearTimeout(this._loopReadVideoTimeoutId),void(this._loopReadVideoTimeoutId=setTimeout((()=>{this._loopReadVideo()}),this._intervalDetectVideoPause));this._divScanLight&&"none"==this._divScanLight.style.display&&(this._divScanLight.style.display=""),o._onLog&&o._onLog("======= once read ======="),o._onLog&&(this._timeStartRecognize=Date.now());let i=this._getVideoFrame();if(!i)return this._loopReadVideoTimeoutId&&clearTimeout(this._loopReadVideoTimeoutId),void(this._loopReadVideoTimeoutId=setTimeout((()=>{this._loopReadVideo()}),0));(()=>e(this,void 0,void 0,(function*(){if(i&&null===i.canvas){let{data:e,width:s,height:n,timeStamp:r}=i,o={timeStamp:r,bScanner:!0};return yield this._recognizeBuffer_Uint8Array(e,s,n,s,t.IPF_GRAYSCALED,o)}if(i&&i.canvas){let{data:e,canvas:s,region:n,sx:r,sy:o,width:a,height:l,timeStamp:c}=i,d={timeStamp:c,bScanner:!0};return(this.bSaveOriCanvas||this.singleFrameMode)&&(this.oriCanvas=s),yield this._recognizeBuffer_Uint8Array(e,s.width,s.height,4*s.width,t.IPF_ABGR_8888,d)}{let e=new Error("imgData is empty.");return new Promise((t=>t(e)))}})))().then((e=>{o._onLog&&o._onLog(e);let t=this.array_decodeFrameTimeCost,i=this.array_getFrameTimeCost;if((()=>{for(;t.length>=5;)t.shift();t.push(this._lastInnerDecodeDuration)})(),this._intervalGetVideoFrame=(()=>{let e=0;if(i&&i.length){let s=Math.min(...t),n=Math.max(...i);s&&n&&(e=s-n)}else e=0;return e>0?e:0})(),this.dce&&this.dce.isOpen()&&this.dce.video&&!this.dce.video.paused&&!this._bPauseScan){if(this.bPlaySoundOnSuccessfulRead&&e.length){let t=!1;if(!0===this.bPlaySoundOnSuccessfulRead||"frame"===this.bPlaySoundOnSuccessfulRead)t=!0;else if("unique"===this.bPlaySoundOnSuccessfulRead)for(let i of e)for(let e of i.lineResults)if(e.bUnduplicated){t=!0;break}t&&(this.soundOnSuccessfullRead.currentTime=0,this.soundOnSuccessfullRead.play().catch((e=>{console.warn("Autoplay not allowed. User interaction required.")})))}if(navigator.vibrate&&this.bVibrateOnSuccessfulRead&&e.length){let t=!1;if(!0===this.bVibrateOnSuccessfulRead||"frame"===this.bVibrateOnSuccessfulRead)t=!0;else if("unique"===this.bVibrateOnSuccessfulRead)for(let i of e)for(let e of i.lineResults)if(e.bUnduplicated){t=!0;break}if(t)try{navigator.vibrate(this.vibrateDuration)}catch(e){console.warn("Vibration not allowed. User interaction required: "+(e.message||e))}}if(this.onFrameRead){let t=this._cloneDecodeResults(e);for(let e of t)for(let t of e.lineResults)t.bUnduplicated&&delete e.bUnduplicated;this.onFrameRead(t)}if(this.onUniqueRead)for(let t of e){if(["passportMRZ","visaMRZ","MRZ"].includes(this.currentSettingsTemplate)){let e="";for(let i of t.lineResults)i.bUnduplicated&&(e.length>0&&(e+="\n"),e+=i.text);e.length>0&&this.onUniqueRead(e,this._cloneDecodeResults(t.lineResults))}else for(let e of t.lineResults)e.bUnduplicated&&this.onUniqueRead(e.text,[this._cloneDecodeResults(e)])}{const e=[];for(let t in this.drawRegionsultRecords)e.push(...this.drawRegionsultRecords[t]);this._drawRegionsults([{lineResults:e}])}}this._loopReadVideoTimeoutId&&clearTimeout(this._loopReadVideoTimeoutId),this.intervalTime?this._loopReadVideoTimeoutId=setTimeout((()=>{this._loopReadVideo()}),this.intervalTime):this._loopReadVideo()})).catch((e=>{this.dce.stopFetchingLoop(),o._onLog&&o._onLog(e.message||e),this._loopReadVideoTimeoutId&&clearTimeout(this._loopReadVideoTimeoutId),this._loopReadVideoTimeoutId=setTimeout((()=>{this._loopReadVideo()}),Math.max(this.intervalTime,1e3)),"platform error"==e.message||console.warn(e.message)}))}))}_getVideoFrame(){let e=this.dce.isFetchingLoopStarted();if(this.dce.loopInterval=this._intervalGetVideoFrame,e||this.dce.startFetchingLoop(),!this.dce.getQueueLength())return this.dce.loopInterval=0,null;let t=this.dce.getFrameFromBuffer();return(e=>{let t=e.timeSpent,i=this.array_getFrameTimeCost;for(;i.length>=5;)i.shift();i.push(t)})(t),t}_checkValidVIN(e){if(!e||17!=e.length)return!1;const t=(e=>{const t=new Map([["A",1],["B",2],["C",3],["D",4],["E",5],["F",6],["G",7],["H",8],["J",1],["K",2],["L",3],["M",4],["N",5],["P",7],["R",9],["S",2],["T",3],["U",4],["V",5],["W",6],["X",7],["Y",8],["Z",9],["1",1],["2",2],["3",3],["4",4],["5",5],["6",6],["7",7],["8",8],["9",9]]),i=[8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2];let s=0;for(let n=0;n<e.length;n++){let r=t.get(e[n]);r&&(s+=r*i[n])}return s%11})(e);return t.toString()===e[8]}_checkValidMRP(e){if(!e||44!=e.length)return!1;const t=(e,t,i)=>{const s=new Map([["<",0],["0",0],["1",1],["2",2],["3",3],["4",4],["5",5],["6",6],["7",7],["8",8],["9",9],["A",10],["B",11],["C",12],["D",13],["E",14],["F",15],["G",16],["H",17],["I",18],["J",19],["K",20],["L",21],["M",22],["N",23],["O",24],["P",25],["Q",26],["R",27],["S",28],["T",29],["U",30],["V",31],["W",32],["X",33],["Y",34],["Z",35]]),n=[7,3,1];let r=0;for(let o=t,a=0;o<=i;o++){let t=s.get(e[o]);t&&(r+=t*n[a%3]),a++}return r%10},i=e.slice(0,10)+e.slice(13,20)+e.slice(21,43),s=t(e,0,8).toString(),n=t(e,13,18).toString(),r=t(e,21,26).toString(),o=t(e,28,41).toString(),a=t(i,0,i.length).toString();return s===e[9]&&n===e[19]&&r===e[27]&&o===e[42]&&a===e[43]}_checkValidMRV(e){if(!e||44!=e.length&&36!=e.length)return!1;const t=(e,t,i)=>{const s=new Map([["<",0],["0",0],["1",1],["2",2],["3",3],["4",4],["5",5],["6",6],["7",7],["8",8],["9",9],["A",10],["B",11],["C",12],["D",13],["E",14],["F",15],["G",16],["H",17],["I",18],["J",19],["K",20],["L",21],["M",22],["N",23],["O",24],["P",25],["Q",26],["R",27],["S",28],["T",29],["U",30],["V",31],["W",32],["X",33],["Y",34],["Z",35]]),n=[7,3,1];let r=0;for(let o=t,a=0;o<=i;o++){let t=s.get(e[o]);t&&(r+=t*n[a%3]),a++}return r%10},i=t(e,0,8).toString(),s=t(e,13,18).toString(),n=t(e,21,26).toString();return i===e[9]&&s===e[19]&&n===e[27]}_drawRegionsults(e){let t,i,n;if(this.beingLazyDrawRegionsults=!1,this.singleFrameMode){if(!this.oriCanvas)return;t="contain",i=this.oriCanvas.width,n=this.oriCanvas.height}else{if(!this.dce.video)return;t=this.dce.video.style.objectFit||"contain",i=this.dce.video.videoWidth,n=this.dce.video.videoHeight}let r,o,a,l,c,d,h,u,g=this.region;if(g)if(s.LST_MANUAL_SPECIFICATION!=g.localizationSourceType)g=null;else if(g.regionMeasuredByPercentage){let e=g.location.points;if(0==e[0].x&&0==e[0].y&&100==e[1].x&&0==e[1].y&&100==e[2].x&&100==e[2].y&&0==e[3].x&&100==e[3].y)g=null;else{g={location:{points:[]}};for(let t=0;t<4;++t)g.location.points.push({x:Math.round(e[t].x/100*i),y:Math.round(e[t].y/100*n)})}}else g=JSON.parse(JSON.stringify(g)),delete g.regionMeasuredByPercentage;if(g){let e=g.location.points;r=e[0].x,c=e[0].y,o=e[1].x,d=e[1].y,a=e[2].x,h=e[2].y,l=e[3].x,u=e[3].y}if(this._cvsDrawArea){this._cvsDrawArea.style.objectFit=t;let s=this._cvsDrawArea;s.width=i,s.height=n;let _=s.getContext("2d");if(g){_.fillStyle=this.regionMaskFillStyle,_.fillRect(0,0,s.width,s.height);let e=Math.round(this.regionMaskLineWidth/2),t=(t,i,s,n,r,o)=>(-(s-t)*e/Math.hypot(s-t,n-i)-(r-t)*e/Math.hypot(r-t,o-i))/2+t,i=(t,i,s,n,r,o)=>(-(n-i)*e/Math.hypot(s-t,n-i)-(o-i)*e/Math.hypot(r-t,o-i))/2+i;_.globalCompositeOperation="destination-out",_.fillStyle="#000",_.beginPath(),_.moveTo(t(r,c,o,d,l,u),i(r,c,o,d,l,u)),_.lineTo(t(o,d,r,c,a,h),i(o,d,r,c,a,h)),_.lineTo(t(a,h,o,d,l,u),i(a,h,o,d,l,u)),_.lineTo(t(l,u,a,h,r,c),i(l,u,a,h,r,c)),_.fill(),_.globalCompositeOperation="source-over",_.strokeStyle=this.regionMaskStrokeStyle,_.lineWidth=this.regionMaskLineWidth,_.beginPath(),_.moveTo(r,c),_.lineTo(o,d),_.lineTo(a,h),_.lineTo(l,u),_.closePath(),_.stroke()}if(e){_.globalCompositeOperation="destination-over",_.fillStyle=this.highlightFillStyle,_.strokeStyle=this.highlightStrokeStyle,_.lineWidth=this.highlightLineWidth,e=e||[];for(let t of e)for(let e of t.lineResults){let t=e.location.points;_.beginPath(),_.moveTo(t[0].x,t[0].y),_.lineTo(t[1].x,t[1].y),_.lineTo(t[2].x,t[2].y),_.lineTo(t[3].x,t[3].y),_.fill(),_.beginPath(),_.moveTo(t[0].x,t[0].y),_.lineTo(t[1].x,t[1].y),_.lineTo(t[2].x,t[2].y),_.lineTo(t[3].x,t[3].y),_.closePath(),_.stroke()}}this.singleFrameMode&&(_.globalCompositeOperation="destination-over",_.drawImage(this.oriCanvas,0,0))}if(this._divScanArea&&this.dce.video){let e=this.dce.video.offsetWidth,t=this.dce.video.offsetHeight,s=1;e/t<i/n?(s=e/i,this._divScanArea.style.left="0",this._divScanArea.style.top=Math.round((t-n*s)/2)+"px"):(s=t/n,this._divScanArea.style.left=Math.round((e-i*s)/2)+"px",this._divScanArea.style.top="0");let _=g?Math.round(Math.min(r,o,a,l)*s):0,f=g?Math.round(Math.min(c,d,h,u)*s):0,m=g?Math.round(Math.max(r,o,a,l)*s-_):Math.round(i*s),p=g?Math.round(Math.max(c,d,h,u)*s-f):Math.round(n*s);this._divScanArea.style.marginLeft=_+"px",this._divScanArea.style.marginTop=f+"px",this._divScanArea.style.width=m+"px",this._divScanArea.style.height=p+"px"}}_clearRegionsults(){this._cvsDrawArea&&(this._cvsDrawArea.width=this._cvsDrawArea.height=0)}startScanning(t){return e(this,void 0,void 0,(function*(){if("closed"!=this._tempSolutionStatus)return;if(this._tempSolutionStatus="opening",!this.dce)throw new Error("Need to set 'cameraEnhancer' first.");if("opening"!=this._tempSolutionStatus)return;this._bindUI(),t&&this._show();let e=yield this.dce.play();return"opening"==this._tempSolutionStatus?(this._bPauseScan=!1,this.singleFrameMode||(this._loopReadVideo(),this._drawRegionsults()),this._tempSolutionStatus="opened",e):void 0}))}stopScanning(e){this.stop(),this._unbindUI(),this.dce&&this.dce.stopFetchingLoop(),this._bPauseScan=!0,e&&this.dce&&(this.dce.getUIElement().style.display="none"),this._tempSolutionStatus="closed"}pauseScanning(){this.dce&&this.dce.stopFetchingLoop(),this._bPauseScan=!0,this._clearRegionsults(),this._divScanLight&&(this._divScanLight.style.display="none")}resumeScanning(){this._assertOpen(),this._bPauseScan=!1}destroyContext(){if(!this.bDestroyed)return o._onLog&&o._onLog("destroy()"),this.bDestroyed=!0,(this.dce||"opening"===this._tempSolutionStatus)&&this.stopScanning(),new Promise(((e,t)=>{let i=o._nextTaskID++;o._taskCallbackMap.set(i,(i=>{if(i.success)return e();{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),o._dlrWorker.postMessage({type:"destroy",id:i,instanceID:this._instanceID})}))}}var a,l;o._jsVersion="2.2.1",o._jsEditVersion="20220216",o._version="loading...(JS "+o._jsVersion+"."+o._jsEditVersion+")",o._license=!n&&document.currentScript&&document.currentScript.getAttribute("data-license")||"",o._sessionPassword=!n&&document.currentScript&&document.currentScript.getAttribute("data-sessionPassword")||"",o.browserInfo=function(){if(!n){var e={init:function(){this.browser=this.searchString(this.dataBrowser)||"unknownBrowser",this.version=this.searchVersion(navigator.userAgent)||this.searchVersion(navigator.appVersion)||"unknownVersion",this.OS=this.searchString(this.dataOS)||"unknownOS","Linux"==this.OS&&-1!=navigator.userAgent.indexOf("Windows NT")&&(this.OS="HarmonyOS")},searchString:function(e){for(var t=0;t<e.length;t++){var i=e[t].string,s=e[t].prop;if(this.versionSearchString=e[t].versionSearch||e[t].identity,i){if(-1!=i.indexOf(e[t].subString))return e[t].identity}else if(s)return e[t].identity}},searchVersion:function(e){var t=e.indexOf(this.versionSearchString);if(-1!=t)return parseFloat(e.substring(t+this.versionSearchString.length+1))},dataBrowser:[{string:navigator.userAgent,subString:"Edge",identity:"Edge"},{string:navigator.userAgent,subString:"OPR",identity:"OPR"},{string:navigator.userAgent,subString:"Chrome",identity:"Chrome"},{string:navigator.vendor,subString:"Apple",identity:"Safari",versionSearch:"Version"},{string:navigator.userAgent,subString:"Firefox",identity:"Firefox"},{string:navigator.userAgent,subString:"MSIE",identity:"Explorer",versionSearch:"MSIE"}],dataOS:[{string:navigator.userAgent,subString:"HarmonyOS",identity:"HarmonyOS"},{string:navigator.userAgent,subString:"Android",identity:"Android"},{string:navigator.userAgent,subString:"iPhone",identity:"iPhone"},{string:navigator.platform,subString:"Win",identity:"Windows"},{string:navigator.platform,subString:"Mac",identity:"Mac"},{string:navigator.platform,subString:"Linux",identity:"Linux"}]};return e.init(),{browser:e.browser,version:e.version,OS:e.OS}}if(n)return{browser:"ssr",version:0,OS:"ssr"}}(),o._workerName="dlr-"+o._jsVersion+".worker.js",o._engineResourcePath=(()=>{if(!n&&document.currentScript){let e=document.currentScript.src,t=e.indexOf("?");if(-1!=t)e=e.substring(0,t);else{let t=e.indexOf("#");-1!=t&&(e=e.substring(0,t))}return e.substring(0,e.lastIndexOf("/")+1)}return"./"})(),o._licenseServer=[],o._deviceFriendlyName="",o._isShowRelRecognizeTimeInResults=!1,o._bWasmDebug=!1,o._bNeverShowDialog=!1,o._nextTaskID=0,o._taskCallbackMap=new Map,o._loadWasmStatus="unload",o._loadWasmCallbackArr=[],o.onResourcesLoaded=null,o.onResourcesLoadStarted=null,o._lastErrorCode=0,o._lastErrorString="",o._defaultUIElementURL="@engineResourcePath/dlr.ui.html",o._loadWasmErr=null,function(e){e[e.GTM_INVERTED=1]="GTM_INVERTED",e[e.GTM_ORIGINAL=2]="GTM_ORIGINAL",e[e.GTM_AUTO=4]="GTM_AUTO",e[e.GTM_REV=2147483648]="GTM_REV",e[e.GTM_SKIP=0]="GTM_SKIP"}(a||(a={})),function(e){e[e.RPM_AUTO=1]="RPM_AUTO",e[e.RPM_GENERAL=2]="RPM_GENERAL",e[e.RPM_GENERAL_RGB_CONTRAST=4]="RPM_GENERAL_RGB_CONTRAST",e[e.RPM_GENERAL_GRAY_CONTRAST=8]="RPM_GENERAL_GRAY_CONTRAST",e[e.RPM_GENERAL_HSV_CONTRAST=16]="RPM_GENERAL_HSV_CONTRAST",e[e.RPM_REV=2147483648]="RPM_REV",e[e.RPM_SKIP=0]="RPM_SKIP"}(l||(l={}));export{i as EnumDLRErrorCode,a as EnumDLRGrayscaleTransformationMode,t as EnumDLRImagePixelFormat,l as EnumDLRRegionPredetectionMode,o as LabelRecognizer};
function e(e,t,i,s){return new(i||(i=Promise))((function(n,r){function o(e){try{l(s.next(e))}catch(e){r(e)}}function a(e){try{l(s.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}l((s=s.apply(e,t||[])).next())}))}var t,i,s;!function(e){e[e.IPF_BINARY=0]="IPF_BINARY",e[e.IPF_BINARYINVERTED=1]="IPF_BINARYINVERTED",e[e.IPF_GRAYSCALED=2]="IPF_GRAYSCALED",e[e.IPF_NV21=3]="IPF_NV21",e[e.IPF_RGB_565=4]="IPF_RGB_565",e[e.IPF_RGB_555=5]="IPF_RGB_555",e[e.IPF_RGB_888=6]="IPF_RGB_888",e[e.IPF_ARGB_8888=7]="IPF_ARGB_8888",e[e.IPF_RGB_161616=8]="IPF_RGB_161616",e[e.IPF_ARGB_16161616=9]="IPF_ARGB_16161616",e[e.IPF_ABGR_8888=10]="IPF_ABGR_8888",e[e.IPF_ABGR_16161616=11]="IPF_ABGR_16161616",e[e.IPF_BGR_888=12]="IPF_BGR_888"}(t||(t={})),function(e){e[e.OK=0]="OK",e[e.UNKNOWN=-1e4]="UNKNOWN",e[e.NO_MEMORY=-10001]="NO_MEMORY",e[e.NULL_POINTER=-10002]="NULL_POINTER",e[e.LICENSE_INVALID=-10003]="LICENSE_INVALID",e[e.LICENSE_EXPIRED=-10004]="LICENSE_EXPIRED",e[e.FILE_NOT_FOUND=-10005]="FILE_NOT_FOUND",e[e.FILETYPE_NOT_SUPPORTED=-10006]="FILETYPE_NOT_SUPPORTED",e[e.BPP_NOT_SUPPORTED=-10007]="BPP_NOT_SUPPORTED",e[e.IMAGE_READ_FAILED=-10012]="IMAGE_READ_FAILED",e[e.TIFF_READ_FAILED=-10013]="TIFF_READ_FAILED",e[e.PDF_READ_FAILED=-10021]="PDF_READ_FAILED",e[e.PDF_DLL_MISSING=-10022]="PDF_DLL_MISSING",e[e.RECOGNITION_TIMEOUT=-10026]="RECOGNITION_TIMEOUT",e[e.JSON_PARSE_FAILED=-10030]="JSON_PARSE_FAILED",e[e.JSON_TYPE_INVALID=-10031]="JSON_TYPE_INVALID",e[e.JSON_KEY_INVALID=-10032]="JSON_KEY_INVALID",e[e.JSON_VALUE_INVALID=-10033]="JSON_VALUE_INVALID",e[e.JSON_NAME_KEY_MISSING=-10034]="JSON_NAME_KEY_MISSING",e[e.JSON_NAME_VALUE_DUPLICATED=-10035]="JSON_NAME_VALUE_DUPLICATED",e[e.TEMPLATE_NAME_INVALID=-10036]="TEMPLATE_NAME_INVALID",e[e.PARAMETER_VALUE_INVALID=-10038]="PARAMETER_VALUE_INVALID",e[e.SET_MODE_ARGUMENT_ERROR=-10051]="SET_MODE_ARGUMENT_ERROR",e[e.GET_MODE_ARGUMENT_ERROR=-10055]="GET_MODE_ARGUMENT_ERROR",e[e.CHARACTER_MODEL_FILE_NOT_FOUND=-10100]="CHARACTER_MODEL_FILE_NOT_FOUND"}(i||(i={})),function(e){e[e.LST_MANUAL_SPECIFICATION=1]="LST_MANUAL_SPECIFICATION",e[e.LST_PREDETECTED_REGION=2]="LST_PREDETECTED_REGION",e[e.LST_BARCODE=4]="LST_BARCODE"}(s||(s={})),"object"==typeof global&&global.process&&global.process.release&&global.process.release.name;const n="undefined"==typeof self,r=n?{}:self;class o{constructor(){this._canvasMaxWH="iPhone"==o.browserInfo.OS||"Android"==o.browserInfo.OS?2048:4096,this._instanceID=void 0,this.bSaveOriCanvas=!1,this.oriCanvas=null,this._region=null,this._timeStartRecognize=null,this._timeEnterInnerDLR=null,this.recognizeRecords={},this.drawRegionsultRecords={},this.bDestroyed=!1,this._setWarnnedEx=new Set,this._lastErrorCode=0,this._lastErrorString="",this._lastInnerDecodeDuration=0,this._clickIptSingleFrameMode=()=>{},this.intervalTime=0,this._intervalGetVideoFrame=0,this.array_getFrameTimeCost=[],this.array_decodeFrameTimeCost=[],this._bPauseScan=!1,this._intervalDetectVideoPause=1e3,this._cvsDrawArea=null,this._divScanArea=null,this._divScanLight=null,this._selCam=null,this._selRsl=null,this._selMinLtr=null,this._optGotMinLtr=null,this._btnClose=null,this._minLetter=0,this._soundOnSuccessfullRead=new Audio("data:audio/mpeg;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjI5LjEwMAAAAAAAAAAAAAAA/+M4wAAAAAAAAAAAAEluZm8AAAAPAAAABQAAAkAAgICAgICAgICAgICAgICAgICAgKCgoKCgoKCgoKCgoKCgoKCgoKCgwMDAwMDAwMDAwMDAwMDAwMDAwMDg4ODg4ODg4ODg4ODg4ODg4ODg4P//////////////////////////AAAAAExhdmM1OC41NAAAAAAAAAAAAAAAACQEUQAAAAAAAAJAk0uXRQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/+MYxAANQAbGeUEQAAHZYZ3fASqD4P5TKBgocg+Bw/8+CAYBA4XB9/4EBAEP4nB9+UOf/6gfUCAIKyjgQ/Kf//wfswAAAwQA/+MYxAYOqrbdkZGQAMA7DJLCsQxNOij///////////+tv///3RWiZGBEhsf/FO/+LoCSFs1dFVS/g8f/4Mhv0nhqAieHleLy/+MYxAYOOrbMAY2gABf/////////////////usPJ66R0wI4boY9/8jQYg//g2SPx1M0N3Z0kVJLIs///Uw4aMyvHJJYmPBYG/+MYxAgPMALBucAQAoGgaBoFQVBUFQWDv6gZBUFQVBUGgaBr5YSgqCoKhIGg7+IQVBUFQVBoGga//SsFSoKnf/iVTEFNRTMu/+MYxAYAAANIAAAAADEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"),this.bPlaySoundOnSuccessfulRead=!1,this.bVibrateOnSuccessfulRead=!1,this.vibrateDuration=300,this.regionMaskFillStyle="rgba(0,0,0,0.5)",this.regionMaskStrokeStyle="rgb(254,142,20)",this.regionMaskLineWidth=2,this.highlightFillStyle="rgba(254,180,32,0.3)",this.highlightStrokeStyle="rgba(254,180,32,0.9)",this.highlightLineWidth=1,this.beingLazyDrawRegionsults=!1,this.currentSettingsTemplate="cppdefault",this.dce=null,this._onCameraSelChange=()=>{this._divScanLight&&(this._divScanLight.style.display="none"),this._drawRegionsults(),this.array_decodeFrameTimeCost.length=0,this.array_getFrameTimeCost.length=0,this._intervalGetVideoFrame=0},this._onResolutionSelChange=()=>{this._divScanLight&&(this._divScanLight.style.display="none"),this._drawRegionsults(),this.array_decodeFrameTimeCost.length=0,this.array_getFrameTimeCost.length=0,this._intervalGetVideoFrame=0},this._onMinLetterSelChange=t=>e(this,void 0,void 0,(function*(){let e=t.target.value;if("got"===e)return;e=JSON.parse(e);let i=JSON.parse(yield this.outputRuntimeSettingsToString());i.LabelRecognizerParameterArray[0].LineStringLengthRange=[e,999],i.TextAreaArray[0].LineStringLengthRange=[e,999],yield this.updateRuntimeSettingsFromString(i)})),this._onCloseBtnClick=()=>{this.stopScanning(!0)},this._tempSolutionStatus="closed"}static getVersion(){return this._version}static get license(){return this._license}static set license(e){if("unload"!=this._loadWasmStatus)throw new Error("`license` is not allowed to change after `createInstance` or `loadWasm` is called.");o._license=e}static initLicense(e){if("unload"!=this._loadWasmStatus)throw new Error("`license` is not allowed to change after `createInstance` or `loadWasm` is called.");o._license=e}static set sessionPassword(e){if("unload"!=this._loadWasmStatus)throw new Error("`sessionPassword` is not allowed to change after `createInstance` or `loadWasm` is called.");o._sessionPassword=e}static get sessionPassword(){return this._sessionPassword}static detectEnvironment(){return e(this,void 0,void 0,(function*(){let e={wasm:"undefined"!=typeof WebAssembly&&("undefined"==typeof navigator||!(/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)&&/\(.+\s11_2_([2-6]).*\)/.test(navigator.userAgent))),worker:!("undefined"==typeof Worker),getUserMedia:!("undefined"==typeof navigator||!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia),camera:!1,browser:this.browserInfo.browser,version:this.browserInfo.version,OS:this.browserInfo.OS};if(e.getUserMedia)try{(yield navigator.mediaDevices.getUserMedia({video:!0})).getTracks().forEach((e=>{e.stop()})),e.camera=!0}catch(e){}return e}))}static get engineResourcePath(){return this._engineResourcePath}static set engineResourcePath(e){if("unload"!=this._loadWasmStatus)throw new Error("`engineResourcePath` is not allowed to change after `createInstance` or `loadWasm` is called.");if(null==e&&(e="./"),n)o._engineResourcePath=e;else{let t=document.createElement("a");t.href=e,o._engineResourcePath=t.href}this._engineResourcePath.endsWith("/")||(o._engineResourcePath+="/")}static get licenseServer(){return this._licenseServer}static set licenseServer(e){if("unload"!=this._loadWasmStatus)throw new Error("`licenseServer` is not allowed to change after `createInstance` or `loadWasm` is called.");if(null==e)o._licenseServer=[];else{e instanceof Array||(e=[e]);for(let t=0;t<e.length;++t){if(!n){let i=document.createElement("a");i.href=e[t],e[t]=i.href}e[t].endsWith("/")||(e[t]+="/")}o._licenseServer=e}}static get deviceFriendlyName(){return this._deviceFriendlyName}static set deviceFriendlyName(e){if("unload"!=this._loadWasmStatus)throw new Error("`deviceFriendlyName` is not allowed to change after loadWasm is called.");o._deviceFriendlyName=e||""}get ifSaveOriginalImageInACanvas(){return this.bSaveOriCanvas}set ifSaveOriginalImageInACanvas(e){this.dce&&(this.dce.ifSaveOriginalImageInACanvas=e),this.bSaveOriCanvas=e}getOriginalImageInACanvas(){return this.oriCanvas}set region(e){this._region=e,this.dce&&!this.singleFrameMode&&(this.beingLazyDrawRegionsults=!0,setTimeout((()=>{this.beingLazyDrawRegionsults&&this._drawRegionsults()}),500))}get region(){return this._region}static isWasmLoaded(){return"loadSuccess"==this._loadWasmStatus}isContextDestroyed(){return this.bDestroyed}static get lastErrorCode(){return this._lastErrorCode}static get lastErrorString(){return this._lastErrorString}get lastErrorCode(){return this._lastErrorCode}get lastErrorString(){return this._lastErrorString}static get defaultUIElementURL(){var e;return null===(e=this._defaultUIElementURL)||void 0===e?void 0:e.replace("@engineResourcePath/",o.engineResourcePath)}static set defaultUIElementURL(e){this._defaultUIElementURL=e}get singleFrameMode(){if(!this.dce)throw new Error("Need to set 'cameraEnhancer' first.");return this.dce.singleFrameMode}set singleFrameMode(t){if(!this.dce)throw new Error("Need to set 'cameraEnhancer' first.");this.dce.singleFrameMode=t,t&&(()=>{e(this,void 0,void 0,(function*(){let e=yield this.getScanSettings();e.trustFrameCount=1,yield this.updateScanSettings(e)}))})()}_assertOpen(){if(!this.dce)throw new Error("Need to set 'cameraEnhancer' first.");if(!this.dce.isOpen())throw Error("The camera is not open.")}_updateMinLtrSel(e){if(this._minLetter=e,this._optGotMinLtr){const t=e?`${e}+ letters`:"any letter";this._optGotMinLtr.innerText=t,this._selMinLtr&&this._optGotMinLtr.parentNode==this._selMinLtr&&(this._selMinLtr.value="got")}}get soundOnSuccessfullRead(){return this._soundOnSuccessfullRead}set soundOnSuccessfullRead(e){e instanceof HTMLAudioElement?this._soundOnSuccessfullRead=e:this._soundOnSuccessfullRead=new Audio(e)}get whenToPlaySoundforSuccessfulRead(){return!0===this.bPlaySoundOnSuccessfulRead?"frame":this.bPlaySoundOnSuccessfulRead?this.bPlaySoundOnSuccessfulRead:"never"}set whenToPlaySoundforSuccessfulRead(e){this.bPlaySoundOnSuccessfulRead="never"!==e&&e}get whenToVibrateforSuccessfulRead(){return!0===this.bVibrateOnSuccessfulRead?"frame":this.bVibrateOnSuccessfulRead?this.bVibrateOnSuccessfulRead:"never"}set whenToVibrateforSuccessfulRead(e){this.bVibrateOnSuccessfulRead="never"!==e&&e}get cameraEnhancer(){return this.dce}set cameraEnhancer(e){this.dce=e,this.adjustDCESettings()}adjustDCESettings(){this.dce&&(o._onLog&&o._onLog("adjustDCESettings()"),this.dce.bufferRefreshInterval=200,this.dce.alwaysRefreshBuffer=!1,this.dce.ifSaveOriginalImageInACanvas=this.bSaveOriCanvas,this.dce._singleFrameModeIpt=function(){let t=document.createElement("input");return t.setAttribute("type","file"),t.setAttribute("accept","image/*"),t.setAttribute("capture",""),t.addEventListener("change",(()=>e(this,void 0,void 0,(function*(){let e=t.files[0];t.value="",this.onSingleFrameAcquired(e)})))),t.style.position="fixed",t.style.left="0",t.style.top="0",t.style.width="1px",t.style.height="1px",t.style.backgroundColor="transparent",t.style.color="transparent",this._video.parentElement.appendChild(t),t},this.dce.onSingleFrameAcquired=t=>e(this,void 0,void 0,(function*(){let e=yield this.recognize(t);yield this.clearMapDecodeRecord();for(let t of e)for(let e of t.lineResults)e.bUnduplicated&&delete t.bUnduplicated;if(this._drawRegionsults(e),this.onFrameRead&&this.dce.isOpen()&&!this._bPauseScan&&this.onFrameRead(e),this.onUniqueRead&&this.dce.isOpen()&&!this._bPauseScan)for(let t of e)for(let e of t.lineResults)e.bUnduplicated&&this.onUniqueRead(e.text,this._cloneDecodeResults(e));if(this.onMRZRead&&this.dce.isOpen()&&!this._bPauseScan){if(["passportMRZ","visaMRZ","MRZ"].includes(this.currentSettingsTemplate))for(let t of e){let e="",i=0;for(let s of t.lineResults)e.length>0&&(e+="\n"),e+=s.text,s.bUnduplicated&&i++;i>0&&e.length>0&&this.onMRZRead(e,this._cloneDecodeResults(t.lineResults))}}})),this._clickIptSingleFrameMode=this.dce._clickIptSingleFrameMode)}static loadWasm(){return e(this,void 0,void 0,(function*(){let t,s=this.license,n=JSON.parse(JSON.stringify(this._licenseServer)),a=this._sessionPassword,l=null,c=null,d=0;if(s.startsWith("t")||s.startsWith("f"))d=0;else if(0===s.length||s.startsWith("P")||s.startsWith("L"))d=1;else{d=2;const e=s.indexOf(":");if(-1!=e&&(s=s.substring(e+1)),s.startsWith("DLS2")){let e=s.substring(4);e=atob(e);const t=JSON.parse(e);if(t.handshakeCode?s=t.handshakeCode:t.organizationID&&(s=t.organizationID),"number"==typeof s&&(s=JSON.stringify(s)),s||(s=""),0===n.length){let e=[];t.mainServerURL&&(e[0]=t.mainServerURL),t.standbyServerURL&&(e[1]=t.standbyServerURL),this.licenseServer=e,n=this.licenseServer}!a&&t.sessionPassword&&(a=t.sessionPassword),t.chargeWay&&(c=t.chargeWay),t.limitedLicenseModules&&(l=t.limitedLicenseModules)}}if(d&&(r.crypto||(t="Please upgrade your browser to support online key."),r.crypto.subtle||(t="Require https to use online key in this browser.")),t){if(1!==d)throw new Error(t);d=0,console.warn(t),this._lastErrorCode=i.UNKNOWN,this._lastErrorString=t}return 1===d&&(s="",console.warn("Applying for a public trial license ...")),yield new Promise(((t,i)=>e(this,void 0,void 0,(function*(){switch(this._loadWasmStatus){case"unload":{o._loadWasmStatus="loading";let t=this.engineResourcePath+this._workerName;this.engineResourcePath.startsWith(location.origin)||(t=yield fetch(t).then((e=>e.blob())).then((e=>URL.createObjectURL(e)))),o._dlrWorker=new Worker(t),this._dlrWorker.onerror=e=>{o._loadWasmStatus="loadFail";let t=new Error(e.message);this._loadWasmErr=t;for(let e of this._loadWasmCallbackArr)e(t);this._loadWasmCallbackArr=[]},this._dlrWorker.onmessage=t=>e(this,void 0,void 0,(function*(){let e=t.data?t.data:t;switch(e.type){case"log":this._onLog&&this._onLog(e.message);break;case"load":{e.message&&(e.message=e.message.replace("(https://www.dynamsoft.com/purchase-center/)","(https://www.dynamsoft.com/store/dynamsoft-label-recognizer/#javascript)"));let t=!1;if(1===d&&(t=!0),e.success){o._loadWasmStatus="loadSuccess",o._version=e.version+"(JS "+this._jsVersion+"."+this._jsEditVersion+")",this._onLog&&this._onLog("load dlr worker success");for(let e of this._loadWasmCallbackArr)e();this._loadWasmCallbackArr=[],this._dlrWorker.onerror=null,e.message&&console.warn(e.message)}else{let i=new Error(e.message);i.stack=e.stack+"\n"+i.stack,o._loadWasmStatus="loadFail",this._loadWasmErr=i;for(let e of this._loadWasmCallbackArr)e(i);this._loadWasmCallbackArr=[],t||111==e.ltsErrorCode&&-1!=e.message.toLowerCase().indexOf("trial license")&&(t=!0)}t&&this.showDialog(e.success?"warn":"error",e.message);break}case"task":{let t=e.id,i=e.body;try{this._taskCallbackMap.get(t)(i),this._taskCallbackMap.delete(t)}catch(e){throw this._taskCallbackMap.delete(t),e}break}case"event":"resourcesLoadStarted"===e.body.type?o.onResourcesLoadStarted&&setTimeout((()=>o.onResourcesLoadStarted(e.body.resourcesPath)),0):"resourcesLoadProgress"===e.body.type?o.onResourcesLoadProgress&&setTimeout((()=>o.onResourcesLoadProgress(e.body.resourcesPath,{loaded:e.body.loaded,total:e.body.total})),0):"resourcesLoaded"===e.body.type&&o.onResourcesLoaded&&setTimeout((()=>o.onResourcesLoaded(e.body.resourcesPath)),0);break;default:this._onLog&&this._onLog(t)}})),this._dlrWorker.postMessage({type:"loadWasm",bd:this._bWasmDebug,engineResourcePath:this.engineResourcePath,version:this._jsVersion,brtk:!!d,bptk:1===d,lcs:s,dm:location.origin.startsWith("http")?location.origin:"https://localhost",browserInfo:this.browserInfo,deviceFriendlyName:this.deviceFriendlyName,ls:n,sp:a,lm:l,cw:c})}case"loading":this._loadWasmCallbackArr.push((e=>{e?i(e):t()}));break;case"loadSuccess":t();break;case"loadFail":i(this._loadWasmErr)}}))))}))}static showDialog(t,i){return e(this,void 0,void 0,(function*(){if(!this._bNeverShowDialog)try{let e=yield fetch(this.engineResourcePath+"dls.license.dialog.html");if(!e.ok)throw Error("Get license dialog fail. Network Error: "+e.statusText);let s=yield e.text();if(!s.trim().startsWith("<"))throw Error("Get license dialog fail. Can't get valid HTMLElement.");let n=document.createElement("div");n.innerHTML=s;let r=[];for(let e=0;e<n.childElementCount;++e){let t=n.children[e];t instanceof HTMLStyleElement&&(r.push(t),document.head.append(t))}let o=1==n.childElementCount?n.children[0]:n;o.remove();let a,l,c,d,h,u=[o],g=o.children;for(let e of g)u.push(e);for(let e=0;e<u.length;++e)for(let t of u[e].children)u.push(t);for(let e of u)if(!a&&e.classList.contains("dls-license-mask"))a=e,e.addEventListener("click",(t=>{if(e==t.target){o.remove();for(let e of r)e.remove()}}));else if(!l&&e.classList.contains("dls-license-icon-close"))l=e,e.addEventListener("click",(()=>{o.remove();for(let e of r)e.remove()}));else if(!c&&e.classList.contains("dls-license-icon-error"))c=e,"error"!=t&&e.remove();else if(!d&&e.classList.contains("dls-license-icon-warn"))d=e,"warn"!=t&&e.remove();else if(!h&&e.classList.contains("dls-license-msg-content")){h=e;let t=i;for(;t;){let i=t.indexOf("["),s=t.indexOf("]",i),n=t.indexOf("(",s),r=t.indexOf(")",n);if(-1==i||-1==s||-1==n||-1==r){e.appendChild(new Text(t));break}i>0&&e.appendChild(new Text(t.substring(0,i)));let o=document.createElement("a"),a=t.substring(i+1,s);o.innerText=a;let l=t.substring(n+1,r);o.setAttribute("href",l),o.setAttribute("target","_blank"),e.appendChild(o),t=t.substring(r+1)}}document.body.appendChild(o)}catch(e){this._onLog&&this._onLog(e.message||e)}}))}static createInstanceInWorker(){return e(this,void 0,void 0,(function*(){return yield this.loadWasm(),yield new Promise(((e,t)=>{let i=this._nextTaskID++;this._taskCallbackMap.set(i,(i=>{if(i.success)return e(i.instanceID);{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),this._dlrWorker.postMessage({type:"createInstance",id:i,bScanner:!1})}))}))}static createInstance(t){return e(this,void 0,void 0,(function*(){let e=new o;return e._instanceID=yield this.createInstanceInWorker(),t&&t.runtimeSettings&&e.updateRuntimeSettingsFromString(t.runtimeSettings),e}))}recognize(i,s){return e(this,void 0,void 0,(function*(){if(o._onLog&&o._onLog("recognize(source: any, modelName?: string)"),o._onLog&&(this._timeStartRecognize=Date.now()),s=s||{},i instanceof Blob)return yield this._recognize_Blob(i,s);if(i instanceof ArrayBuffer)return yield this._recognize_ArrayBuffer(i,s);if(i instanceof Uint8Array||i instanceof Uint8ClampedArray)return yield this._recognize_Uint8Array(i,s);if(i instanceof HTMLImageElement||"undefined"!=typeof ImageBitmap&&i instanceof ImageBitmap)return yield this._recognize_Image(i,s);if(i instanceof HTMLCanvasElement||"undefined"!=typeof OffscreenCanvas&&i instanceof OffscreenCanvas)return yield this._recognize_Canvas(i,s);if(i instanceof HTMLVideoElement)return yield this._recognize_Video(i,s);if("string"==typeof i)return"data:image/"==i.substring(0,11)?yield this._recognize_Base64(i,s):yield this._recognize_Url(i,s);if(i&&"object"==typeof i){const{data:e,canvas:s,region:n,sx:r,sy:o,width:a,height:l}=i;return s&&e?yield this._recognizeBuffer_Uint8Array(e,s.width,s.height,4*s.width,t.IPF_ABGR_8888):e&&a&&l?yield this._recognizeBuffer_Uint8Array(e,a,l,a,t.IPF_GRAYSCALED):yield Promise.reject(TypeError("'_recognize(source, config)': Type of 'source' should be 'Blob', 'ArrayBuffer', 'Uint8Array', 'HTMLImageElement', 'HTMLCanvasElement', 'HTMLVideoElement', 'string(base64 with image mime)', 'string(url)' or 'object(dceFrame)'."))}return yield Promise.reject(TypeError("'_recognize(source, config)': Type of 'source' should be 'Blob', 'ArrayBuffer', 'Uint8Array', 'HTMLImageElement', 'HTMLCanvasElement', 'HTMLVideoElement', 'string(base64 with image mime)', 'string(url)' or 'object(dceFrame)'."))}))}recognizeBase64String(t,i){return e(this,void 0,void 0,(function*(){let e={};return i&&(e.modelName=i),this._recognize_Base64(t,e)}))}recognizeUrl(t,i){return e(this,void 0,void 0,(function*(){let e={};return i&&(e.modelName=i),this._recognize_Url(t,e)}))}_recognizeBuffer_Uint8Array(t,i,s,n,r,a){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,l)=>{let c=o._nextTaskID++;o._taskCallbackMap.set(c,(t=>{if(t.success){let i,s=o._onLog?Date.now():0;this._lastInnerDecodeDuration=t.duration,this.bufferShared&&!this.bufferShared.length&&(this.bufferShared=t.buffer);try{i=this._handleRetJsonString(t.decodeReturn);const e=e=>!!e&&("VIN_NA"===this.currentSettingsTemplate?this._checkValidVIN(e):"passportMRZ"===this.currentSettingsTemplate?44==e.length&&(/[0-9]/.test(e)?this._checkValidMRP(e):null):"visaMRZ"===this.currentSettingsTemplate?(44==e.length||36==e.length)&&(/[0-9]/.test(e)?this._checkValidMRV(e):null):null);for(let t of i)for(let i of t.lineResults)i.isCheckDigitMatched=e(i.text)}catch(e){return l(e)}if(o._onLog){let e=Date.now();o._onLog("time get result: "+s),o._onLog("Handle image cost: "+(this._timeEnterInnerDLR-this._timeStartRecognize)),o._onLog("worker recognize image cost: "+(s-this._timeEnterInnerDLR)),o._onLog("worker handle results: "+(e-s)),o._onLog("Total recognize image cost: "+(e-this._timeStartRecognize))}return e(i)}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,l(e)}})),o._onLog&&(this._timeEnterInnerDLR=Date.now()),o._onLog&&o._onLog("Send buffer to worker:"+this._timeEnterInnerDLR),o._dlrWorker.postMessage({type:"recognizeByBuffer",id:c,instanceID:this._instanceID,body:{config:a,imageData:{bytes:t,length:s*i*4,width:i,height:s,stride:n,format:r}}},[t.buffer])}))}))}_recognizeBuffer_Blob(t,i,s,n,r,a){return e(this,void 0,void 0,(function*(){o._onLog&&o._onLog("_recognizeBuffer_Blob(buffer,width,height,stride,format)");const e=t.arrayBuffer?yield t.arrayBuffer():yield new Promise(((e,i)=>{let s=new FileReader;s.readAsArrayBuffer(t),s.onload=()=>{e(s.result)},s.onerror=()=>{i(s.error)}}));return yield this._recognizeBuffer_Uint8Array(new Uint8Array(e),i,s,n,r,a)}))}recognizeBuffer(t,i,s,n,r,a){return e(this,void 0,void 0,(function*(){let e;return o._onLog&&o._onLog("recognizeBuffer(buffer,width,height,stride,format)"),o._onLog&&(this._timeStartRecognize=Date.now()),t instanceof Uint8Array||t instanceof Uint8ClampedArray?e=yield this._recognizeBuffer_Uint8Array(t,i,s,n,r,a):t instanceof ArrayBuffer?e=yield this._recognizeBuffer_Uint8Array(new Uint8Array(t),i,s,n,r,a):t instanceof Blob&&(e=yield this._recognizeBuffer_Blob(t,i,s,n,r,a)),e}))}_recognizeFileInMemory_Uint8Array(t,i){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,s)=>{let n=o._nextTaskID++;o._taskCallbackMap.set(n,(t=>{if(t.success){let i;try{i=this._handleRetJsonString(t.decodeReturn)}catch(e){return s(e)}return e(i)}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,s(e)}})),o._dlrWorker.postMessage({type:"recognizeFileInMemory",id:n,instanceID:this._instanceID,body:{config:i,bytes:t}})}))}))}getRuntimeSettings(){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=o._nextTaskID++;o._taskCallbackMap.set(i,(i=>{if(i.success){let t=JSON.parse(i.results);return e(t)}{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),o._dlrWorker.postMessage({type:"getRuntimeSettings",id:i,instanceID:this._instanceID})}))}))}static isRegionNormalPreset(e){return s.LST_MANUAL_SPECIFICATION==e.localizationSourceType&&1==e.regionMeasuredByPercentage&&JSON.stringify([{x:0,y:100},{x:100,y:0},{x:100,y:100},{x:0,y:100}])===JSON.stringify(e.location.points)}updateRuntimeSettings(t){return e(this,void 0,void 0,(function*(){let e;if("string"==typeof t){if(!(t=t.trim()).startsWith("{"))return void this.updateRuntimeSettingsFromString(t);e=JSON.parse(t)}else{if("object"!=typeof t)throw TypeError("'UpdateRuntimeSettings(settings)': Type of 'settings' should be 'string' or 'PlainObject'.");e=JSON.parse(JSON.stringify(t))}const i=e.referenceRegion;o.isRegionNormalPreset(i)?this.region=null:this.region=i,this._updateMinLtrSel(0),yield new Promise(((t,i)=>{let s=o._nextTaskID++;o._taskCallbackMap.set(s,(e=>{if(e.success){try{this._handleRetJsonString(e.updateReturn)}catch(e){i(e)}return t()}{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,i(t)}})),o._dlrWorker.postMessage({type:"updateRuntimeSettings",id:s,instanceID:this._instanceID,body:{settings:JSON.stringify(e)}})}))}))}resetRuntimeSettings(){return e(this,void 0,void 0,(function*(){return this.region=null,this._updateMinLtrSel(0),yield new Promise(((e,t)=>{let i=o._nextTaskID++;o._taskCallbackMap.set(i,(i=>{if(i.success)return e();{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),o._dlrWorker.postMessage({type:"resetRuntimeSettings",id:i,instanceID:this._instanceID})}))}))}updateRuntimeSettingsFromString(t){return e(this,void 0,void 0,(function*(){let e=0;if("string"==typeof t)if((t=t.trim()).startsWith("{"))t=JSON.parse(t);else{if(t.length>50)throw new Error("Error: preset longer than 50 letters.");const i=t.toLowerCase().split("-");if(i.length>2)throw new Error(`Error: '${t}' is not supported.`);if(i.includes("numberletter"))e=3,this.currentSettingsTemplate="numberLetter";else if(i.includes("numberuppercase"))e=3,this.currentSettingsTemplate="numberUppercase";else if(i.includes("number"))e=3,this.currentSettingsTemplate="number";else if(i.includes("letter"))e=3,this.currentSettingsTemplate="letter";else if(i.includes("passportmrz"))e=44,this.currentSettingsTemplate="passportMRZ";else if(i.includes("visamrz"))e=36,this.currentSettingsTemplate="visaMRZ";else if(i.includes("mrz"))e=30,this.currentSettingsTemplate="MRZ";else if(i.includes("vin_na"))e=14,this.currentSettingsTemplate="VIN_NA";else if(i.includes("vin"))e=14,this.currentSettingsTemplate="VIN";else{if(!i.includes("cppdefault"))throw new Error(`Error: '${t}' is not supported.`);this.currentSettingsTemplate="cppdefault"}i.includes("video")?this.region={localizationSourceType:s.LST_MANUAL_SPECIFICATION,location:{points:[{x:0,y:40},{x:100,y:40},{x:100,y:60},{x:0,y:60}]},regionMeasuredByPercentage:1}:this.region=null}else{if("object"!=typeof t)throw TypeError("'updateRuntimeSettingsFromString(settings)': Type of 'settings' should be 'string' or 'PlainObject'.");this.currentSettingsTemplate=null}if("object"==typeof t){const i=t.ReferenceRegionArray[0].Localization,n=i.FirstPoint?{localizationSourceType:s[i.SourceType],location:{points:[{x:i.FirstPoint[0],y:i.FirstPoint[1]},{x:i.SecondPoint[0],y:i.SecondPoint[1]},{x:i.ThirdPoint[0],y:i.ThirdPoint[1]},{x:i.FourthPoint[0],y:i.FourthPoint[1]}]},regionMeasuredByPercentage:i.MeasuredByPercentage}:null;n&&o.isRegionNormalPreset(n)?this.region=null:this.region=n;const r=t.LabelRecognizerParameterArray[0].LineStringLengthRange;e=r?r[0]:0}return this._updateMinLtrSel(e),yield new Promise(((e,i)=>{let s=o._nextTaskID++;o._taskCallbackMap.set(s,(t=>{if(t.success){try{this._handleRetJsonString(t.updateReturn)}catch(e){i(e)}return e()}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,i(e)}})),o._dlrWorker.postMessage({type:"updateRuntimeSettingsFromString",id:s,instanceID:this._instanceID,body:{settings:t}})}))}))}outputRuntimeSettingsToString(){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=o._nextTaskID++;o._taskCallbackMap.set(i,(i=>{if(i.success)return e(i.results);{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),o._dlrWorker.postMessage({type:"outputSettingsToString",id:i,instanceID:this._instanceID})}))}))}updateReferenceRegionFromBarcodeResults(t){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,i)=>{let s=o._nextTaskID++;o._taskCallbackMap.set(s,(t=>{if(t.success)return e();{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,i(e)}})),o._dlrWorker.postMessage({type:"updateReferenceRegionFromBarcodeResults",id:s,instanceID:this._instanceID,body:{dbrTextResults:t}})}))}))}static appendCaffeModelBuffer(t,i){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,s)=>{let n=o._nextTaskID++;o._taskCallbackMap.set(n,(t=>{if(t.success){try{return e()}catch(e){s(e)}return e()}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,s(e)}})),o._dlrWorker.postMessage({type:"appendCaffeModelBuffer",id:n,body:{name:t,folderUrl:i}})}))}))}static eraseCaffeModelByName(t){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,i)=>{let s=o._nextTaskID++;o._taskCallbackMap.set(s,(t=>{if(t.success)return e();{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,i(e)}})),o._dlrWorker.postMessage({type:"eraseCaffeModelByName",id:s,body:{name:t}})}))}))}static eraseAllCaffeModels(){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=o._nextTaskID++;o._taskCallbackMap.set(i,(i=>{if(i.success)return e();{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),o._dlrWorker.postMessage({type:"eraseAllCaffeModels",id:i})}))}))}_recognize_Blob(t,i){return e(this,void 0,void 0,(function*(){o._onLog&&o._onLog("_recognize_Blob(blob: Blob)");let e=null,s=null;if("undefined"!=typeof createImageBitmap)try{e=yield createImageBitmap(t)}catch(e){}e||(s=yield function(e){return new Promise(((t,i)=>{let s=URL.createObjectURL(e),n=new Image;n.dlrObjUrl=s,n.src=s,n.onload=()=>{t(n)},n.onerror=e=>{i(new Error("Can't convert blob to image : "+(e instanceof Event?e.type:e)))}}))}(t));let n=yield this._recognize_Image(e||s,i);return e&&e.close(),n}))}_recognize_ArrayBuffer(t,i){return e(this,void 0,void 0,(function*(){return yield this._recognize_Blob(new Blob([t]),i)}))}_recognize_Uint8Array(t,i){return e(this,void 0,void 0,(function*(){return yield this._recognize_Blob(new Blob([t]),i)}))}_recognize_Image(t,i){return e(this,void 0,void 0,(function*(){o._onLog&&o._onLog("_recognize_Image(image: HTMLImageElement|ImageBitmap)"),i=i||{};let e,s,n=t instanceof HTMLImageElement?t.naturalWidth:t.width,a=t instanceof HTMLImageElement?t.naturalHeight:t.height,l=Math.max(n,a);if(l>this._canvasMaxWH){let t=this._canvasMaxWH/l;e=Math.round(n*t),s=Math.round(a*t)}else e=n,s=a;let c,d=n,h=a,u=e,g=s;!this.bSaveOriCanvas&&r.OffscreenCanvas?c=new OffscreenCanvas(u,g):(c=document.createElement("canvas"),c.width=u,c.height=g);let _=c.getContext("2d");return n==d&&a==h&&n==u&&a==g?_.drawImage(t,0,0):_.drawImage(t,0,0,d,h,0,0,u,g),t.dlrObjUrl&&URL.revokeObjectURL(t.dlrObjUrl),yield this._recognize_Canvas(c,i)}))}_recognize_Canvas(i,s){return e(this,void 0,void 0,(function*(){if(o._onLog&&o._onLog("_recognize_Canvas(canvas:HTMLCanvasElement)"),i.crossOrigin&&"anonymous"!=i.crossOrigin)throw"cors";if(0===i.width||0===i.height)throw Error("The width or height of the 'canvas' is 0.");(this.bSaveOriCanvas||this.dce&&this.singleFrameMode)&&(this.oriCanvas=i);let e=(i.dlrCtx2d||i.getContext("2d")).getImageData(0,0,i.width,i.height).data;return yield this._recognizeBuffer_Uint8Array(e,i.width,i.height,4*i.width,t.IPF_ABGR_8888,s)}))}_recognize_Video(t,i){return e(this,void 0,void 0,(function*(){if(o._onLog&&o._onLog("_recognize_Video(video)"),!(t instanceof HTMLVideoElement))throw TypeError("'_recognize_Video(video [, config] )': Type of 'video' should be 'HTMLVideoElement'.");if(t.crossOrigin&&"anonymous"!=t.crossOrigin)throw"cors";i=i||{};let e,s,n=t.videoWidth,a=t.videoHeight,l=Math.max(n,a);if(l>this._canvasMaxWH){let t=this._canvasMaxWH/l;e=Math.round(n*t),s=Math.round(a*t)}else e=n,s=a;let c=n,d=a,h=e,u=s,g=n==c&&a==d&&n==h&&a==u,_=null;!this.bSaveOriCanvas&&r.OffscreenCanvas?_=new OffscreenCanvas(h,u):(_=document.createElement("canvas"),_.width=h,_.height=u);const f=_.dlrCtx2d=_.getContext("2d");return g?f.drawImage(t,0,0):f.drawImage(t,0,0,c,d,0,0,h,u),yield this._recognize_Canvas(_,i)}))}_recognize_Base64(t,i){return e(this,void 0,void 0,(function*(){if(o._onLog&&o._onLog("_recognize_Base64(base64Str)"),"string"!=typeof t&&"object"!=typeof t)return Promise.reject("'_recognize_Base64(base64Str, config)': Type of 'base64Str' should be 'string'.");"data:image/"==t.substring(0,11)&&(t=t.substring(t.indexOf(",")+1));{let e=atob(t),s=e.length,n=new Uint8Array(s);for(;s--;)n[s]=e.charCodeAt(s);return yield this._recognize_Blob(new Blob([n]),i)}}))}_recognize_Url(t,i){return e(this,void 0,void 0,(function*(){if(o._onLog&&o._onLog("_recognize_Url(url)"),"string"!=typeof t&&"object"!=typeof t)throw TypeError("'_recognize_Url(url, config)': Type of 'url' should be 'string'.");{let s=yield new Promise(((i,s)=>{let n=new XMLHttpRequest;n.open("GET",t,!0),n.responseType="blob",n.send(),n.onloadend=()=>e(this,void 0,void 0,(function*(){i(n.response)})),n.onerror=()=>{s(new Error("Network Error: "+n.statusText))}}));return yield this._recognize_Blob(s,i)}}))}_recognize_FilePath(t,i){return e(this,void 0,void 0,(function*(){throw o._onLog&&o._onLog("_recognize_FilePath(path)"),Error("'_recognize_FilePath(path, config)': The method is only supported in node environment.")}))}static LabelRecognizerException(e,t){let s,n=i.UNKNOWN;return"number"==typeof e?(n=e,s=new Error(t)):s=new Error(e),s.code=n,s}_handleRetJsonString(e){let t=i;if(e.results){const t=this.drawRegionsultRecords,s={};for(let i=0;i<e.results.length;i++){let n=e.results[i];if(null!=n.exception){this._setWarnnedEx.has(n.exception)||(this._setWarnnedEx.add(n.exception),console.warn(n.exception));let e={};n.exception.split(";").forEach((t=>{let i=t.indexOf(":");e[t.substring(0,i)]=t.substring(i+1)})),n.exception=e}for(let e of n.lineResults){const i=e.text;if(s[i]=1,e.bUnduplicated){(t[i]=t[i]||[]).push(e)}else t[i]&&(t[i]=[e])}}if(e.records){const i=this.recognizeRecords=e.records;for(let e in t)i[e]||delete t[e];for(let e in t)s[e]||(t[e]=[])}else this.recognizeRecords={},this.drawRegionsultRecords={};return this._lastErrorCode=e.exception,this._lastErrorString=e.description,e.exception&&!this._setWarnnedEx.has(e.description)&&(this._setWarnnedEx.add(e.description),e.exception==i.LICENSE_INVALID||e.exception==i.LICENSE_EXPIRED?console.error(e.description):console.warn(e.description)),e.results}if(e.exception==t.OK)return e.data;throw o.LabelRecognizerException(e.exception,e.description)}setModeArgument(t,i,s,n){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,r)=>{let a=o._nextTaskID++;o._taskCallbackMap.set(a,(t=>{if(t.success){try{this._handleRetJsonString(t.setReturn)}catch(e){return r(e)}return e()}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,r(e)}})),o._dlrWorker.postMessage({type:"setModeArgument",id:a,instanceID:this._instanceID,body:{modeName:t,index:i,argumentName:s,argumentValue:n}})}))}))}getModeArgument(t,i,s){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,n)=>{let r=o._nextTaskID++;o._taskCallbackMap.set(r,(t=>{if(t.success){let i;try{i=this._handleRetJsonString(t.getReturn)}catch(e){return n(e)}return e(i)}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,n(e)}})),o._dlrWorker.postMessage({type:"getModeArgument",id:r,instanceID:this._instanceID,body:{modeName:t,index:i,argumentName:s}})}))}))}recognizeCurrentFrame(){return e(this,void 0,void 0,(function*(){this._assertOpen();let e=this.dce.getFrame();if(e&&null===e.canvas){let{data:i,width:s,height:n}=e;return yield this._recognizeBuffer_Uint8Array(i,s,n,s,t.IPF_GRAYSCALED)}if(e&&e.canvas){let{data:i,canvas:s}=e;return(this.bSaveOriCanvas||this.singleFrameMode)&&(this.oriCanvas=s),yield this._recognizeBuffer_Uint8Array(i,s.width,s.height,4*s.width,t.IPF_ABGR_8888)}}))}clearMapDecodeRecord(){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=o._nextTaskID++;o._taskCallbackMap.set(i,(i=>{if(i.success)return e();{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),o._dlrWorker.postMessage({type:"clearMapDecodeRecord",id:i,instanceID:this._instanceID})}))}))}_bindUI(){const e=this.dce.getUIElement();if(!e)throw new Error("Need to define `UIElement` before opening.");this.dce._bindUI();let t=[e],i=e.children;for(let e of i)t.push(e);for(let e=0;e<t.length;++e)for(let i of t[e].children)t.push(i);for(let e of t)!this._cvsDrawArea&&e.classList.contains("dlr-cvs-drawarea")?this._cvsDrawArea=e:!this._divScanArea&&e.classList.contains("dlr-cvs-scanarea")?this._divScanArea=e:!this._divScanLight&&e.classList.contains("dlr-scanlight")?this._divScanLight=e:!this._selCam&&e.classList.contains("dce-sel-camera")?this._selCam=e:!this._selRsl&&e.classList.contains("dce-sel-resolution")?this._selRsl=e:!this._selMinLtr&&e.classList.contains("dlr-sel-minletter")?(this._selMinLtr=e,this._selMinLtr.options.length||(this._selMinLtr.innerHTML=[this._optGotMinLtr?"":'<option class="dlr-opt-gotMinLtr" value="got"></option>','<option value="0" selected>any letter</option>','<option value="3">3+ letters</option>','<option value="5">5+ letters</option>','<option value="8">8+ letters</option>','<option value="12">12+ letters</option>','<option value="18">18+ letters</option>','<option value="30">30+ letters</option>','<option value="50">50+ letters</option>','<option value="80">80+ letters</option>','<option value="120">120+ letters</option>'].join(""),this._optGotMinLtr=this._optGotMinLtr||this._selMinLtr.options[0])):this._optGotMinLtr||!e.classList.contains("dlr-opt-gotMinLtr")&&!e.classList.contains("dlr-opt-gotMinLtr")?!this._btnClose&&e.classList.contains("dce-btn-close")&&(this._btnClose=e):this._optGotMinLtr=e;if(this.singleFrameMode&&(this._cvsDrawArea&&(this._cvsDrawArea.addEventListener("click",this._clickIptSingleFrameMode),this._cvsDrawArea.style.cursor="pointer",this._cvsDrawArea.setAttribute("title","Take a photo")),this._divScanArea&&(this._divScanArea.addEventListener("click",this._clickIptSingleFrameMode),this._divScanArea.style.cursor="pointer",this._divScanArea.setAttribute("title","Take a photo"))),this._selCam&&this._selCam.addEventListener("change",this._onCameraSelChange),this._selRsl&&this._selRsl.addEventListener("change",this._onResolutionSelChange),this._selMinLtr&&this._selMinLtr.addEventListener("change",this._onMinLetterSelChange),this._btnClose&&this._btnClose.addEventListener("click",this._onCloseBtnClick),!this.dce.video)throw this._unbindUI(),Error("Can not find HTMLVideoElement with class `dce-video`.");this._updateMinLtrSel(this._minLetter)}_unbindUI(){this._clearRegionsults(),this.singleFrameMode&&(this._cvsDrawArea&&(this._cvsDrawArea.removeEventListener("click",this._clickIptSingleFrameMode),this._cvsDrawArea.style.cursor="",this._cvsDrawArea.removeAttribute("title")),this._divScanArea&&(this._divScanArea.removeEventListener("click",this._clickIptSingleFrameMode),this._divScanArea.style.cursor="",this._divScanArea.removeAttribute("title"))),this._selCam&&this._selCam.removeEventListener("change",this._onCameraSelChange),this._selRsl&&this._selRsl.removeEventListener("change",this._onResolutionSelChange),this._selMinLtr&&this._selMinLtr.removeEventListener("change",this._onMinLetterSelChange),this._btnClose&&this._btnClose.removeEventListener("click",this._onCloseBtnClick),this.dce._unbindUI(),this._cvsDrawArea=null,this._divScanArea=null,this._divScanLight=null,this._selCam=null,this._selRsl=null,this._selMinLtr=null,this._optGotMinLtr=null,this._btnClose=null}getScanSettings(){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=o._nextTaskID++;o._taskCallbackMap.set(i,(i=>{if(i.success){let t=i.results;return t.intervalTime=this.intervalTime,e(t)}{let e=new Error(i.message);return e.stack+="\n"+i.stack,t(e)}})),o._dlrWorker.postMessage({type:"getScanSettings",id:i,instanceID:this._instanceID})}))}))}updateScanSettings(t){return e(this,void 0,void 0,(function*(){return this.intervalTime=t.intervalTime,yield new Promise(((e,i)=>{let s=o._nextTaskID++;o._taskCallbackMap.set(s,(t=>{if(t.success)return e();{let e=new Error(t.message);return e.stack+="\n"+t.stack,i(e)}})),o._dlrWorker.postMessage({type:"updateScanSettings",id:s,instanceID:this._instanceID,body:{settings:t}})}))}))}_show(){const e=this.dce.getUIElement();e.parentNode||(e.style.position="fixed",e.style.left="0",e.style.top="0",document.body.append(e)),"none"==e.style.display&&(e.style.display="")}stop(){this.dce&&this.dce.stop(),this._divScanLight&&(this._divScanLight.style.display="none"),this._drawRegionsults(),this.array_decodeFrameTimeCost.length=0,this.array_getFrameTimeCost.length=0,this._intervalGetVideoFrame=0}_cloneDecodeResults(e){if(e instanceof Array){let t=[];for(let i of e)t.push(this._cloneDecodeResults(i));return t}{let t=e;return JSON.parse(JSON.stringify(t,((e,t)=>"oriVideoCanvas"==e||"searchRegionCanvas"==e?void 0:t)))}}_loopReadVideo(){return e(this,void 0,void 0,(function*(){if(this.bDestroyed)return void(this.dce&&this.dce.stopFetchingLoop());if(!this.dce||!this.dce.isOpen())return this.dce&&this.dce.stopFetchingLoop(),void(yield this.clearMapDecodeRecord());if(!this.dce.video||this.dce.video.paused||this._bPauseScan)return o._onLog&&o._onLog("Video or scan is paused. Ask in 1s."),this.dce&&this.dce.stopFetchingLoop(),yield this.clearMapDecodeRecord(),this._loopReadVideoTimeoutId&&clearTimeout(this._loopReadVideoTimeoutId),void(this._loopReadVideoTimeoutId=setTimeout((()=>{this._loopReadVideo()}),this._intervalDetectVideoPause));this._divScanLight&&"none"==this._divScanLight.style.display&&(this._divScanLight.style.display=""),o._onLog&&o._onLog("======= once read ======="),o._onLog&&(this._timeStartRecognize=Date.now());let i=this._getVideoFrame();if(!i)return this._loopReadVideoTimeoutId&&clearTimeout(this._loopReadVideoTimeoutId),void(this._loopReadVideoTimeoutId=setTimeout((()=>{this._loopReadVideo()}),0));(()=>e(this,void 0,void 0,(function*(){if(i&&null===i.canvas){let{data:e,width:s,height:n,timeStamp:r}=i,o={timeStamp:r,bScanner:!0};return yield this._recognizeBuffer_Uint8Array(e,s,n,s,t.IPF_GRAYSCALED,o)}if(i&&i.canvas){let{data:e,canvas:s,region:n,sx:r,sy:o,width:a,height:l,timeStamp:c}=i,d={timeStamp:c,bScanner:!0};return(this.bSaveOriCanvas||this.singleFrameMode)&&(this.oriCanvas=s),yield this._recognizeBuffer_Uint8Array(e,s.width,s.height,4*s.width,t.IPF_ABGR_8888,d)}{let e=new Error("imgData is empty.");return new Promise((t=>t(e)))}})))().then((e=>{o._onLog&&o._onLog(e);let t=this.array_decodeFrameTimeCost,i=this.array_getFrameTimeCost;if((()=>{for(;t.length>=5;)t.shift();t.push(this._lastInnerDecodeDuration)})(),this._intervalGetVideoFrame=(()=>{let e=0;if(i&&i.length){let s=Math.min(...t),n=Math.max(...i);s&&n&&(e=s-n)}else e=0;return e>0?e:0})(),this.dce&&this.dce.isOpen()&&this.dce.video&&!this.dce.video.paused&&!this._bPauseScan){if(this.bPlaySoundOnSuccessfulRead&&e.length){let t=!1;if(!0===this.bPlaySoundOnSuccessfulRead||"frame"===this.bPlaySoundOnSuccessfulRead)t=!0;else if("unique"===this.bPlaySoundOnSuccessfulRead)for(let i of e)for(let e of i.lineResults)if(e.bUnduplicated){t=!0;break}t&&(this.soundOnSuccessfullRead.currentTime=0,this.soundOnSuccessfullRead.play().catch((e=>{console.warn("Autoplay not allowed. User interaction required.")})))}if(navigator.vibrate&&this.bVibrateOnSuccessfulRead&&e.length){let t=!1;if(!0===this.bVibrateOnSuccessfulRead||"frame"===this.bVibrateOnSuccessfulRead)t=!0;else if("unique"===this.bVibrateOnSuccessfulRead)for(let i of e)for(let e of i.lineResults)if(e.bUnduplicated){t=!0;break}if(t)try{navigator.vibrate(this.vibrateDuration)}catch(e){console.warn("Vibration not allowed. User interaction required: "+(e.message||e))}}if(this.onFrameRead){let t=this._cloneDecodeResults(e);for(let e of t)for(let t of e.lineResults)t.bUnduplicated&&delete e.bUnduplicated;this.onFrameRead(t)}if(this.onUniqueRead)for(let t of e)for(let e of t.lineResults)e.bUnduplicated&&this.onUniqueRead(e.text,this._cloneDecodeResults(e));if(this.onMRZRead){if(["passportMRZ","visaMRZ","MRZ"].includes(this.currentSettingsTemplate))for(let t of e){let e="",i=0;for(let s of t.lineResults)e.length>0&&(e+="\n"),e+=s.text,s.bUnduplicated&&i++;i>0&&e.length>0&&this.onMRZRead(e,this._cloneDecodeResults(t.lineResults))}}{const e=[];for(let t in this.drawRegionsultRecords)e.push(...this.drawRegionsultRecords[t]);this._drawRegionsults([{lineResults:e}])}}this._loopReadVideoTimeoutId&&clearTimeout(this._loopReadVideoTimeoutId),this.intervalTime?this._loopReadVideoTimeoutId=setTimeout((()=>{this._loopReadVideo()}),this.intervalTime):this._loopReadVideo()})).catch((e=>{this.dce.stopFetchingLoop(),o._onLog&&o._onLog(e.message||e),this._loopReadVideoTimeoutId&&clearTimeout(this._loopReadVideoTimeoutId),this._loopReadVideoTimeoutId=setTimeout((()=>{this._loopReadVideo()}),Math.max(this.intervalTime,1e3)),"platform error"==e.message||console.warn(e.message)}))}))}_getVideoFrame(){let e=this.dce.isFetchingLoopStarted();if(this.dce.loopInterval=this._intervalGetVideoFrame,e||this.dce.startFetchingLoop(),!this.dce.getQueueLength())return this.dce.loopInterval=0,null;let t=this.dce.getFrameFromBuffer();return(e=>{let t=e.timeSpent,i=this.array_getFrameTimeCost;for(;i.length>=5;)i.shift();i.push(t)})(t),t}_checkValidVIN(e){if(!e||17!=e.length)return!1;const t=(e=>{const t=new Map([["A",1],["B",2],["C",3],["D",4],["E",5],["F",6],["G",7],["H",8],["J",1],["K",2],["L",3],["M",4],["N",5],["P",7],["R",9],["S",2],["T",3],["U",4],["V",5],["W",6],["X",7],["Y",8],["Z",9],["1",1],["2",2],["3",3],["4",4],["5",5],["6",6],["7",7],["8",8],["9",9]]),i=[8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2];let s=0;for(let n=0;n<e.length;n++){let r=t.get(e[n]);r&&(s+=r*i[n])}return s%11})(e);return t.toString()===e[8]}_checkValidMRP(e){if(!e||44!=e.length)return!1;const t=(e,t,i)=>{const s=new Map([["<",0],["0",0],["1",1],["2",2],["3",3],["4",4],["5",5],["6",6],["7",7],["8",8],["9",9],["A",10],["B",11],["C",12],["D",13],["E",14],["F",15],["G",16],["H",17],["I",18],["J",19],["K",20],["L",21],["M",22],["N",23],["O",24],["P",25],["Q",26],["R",27],["S",28],["T",29],["U",30],["V",31],["W",32],["X",33],["Y",34],["Z",35]]),n=[7,3,1];let r=0;for(let o=t,a=0;o<=i;o++){let t=s.get(e[o]);t&&(r+=t*n[a%3]),a++}return r%10},i=e.slice(0,10)+e.slice(13,20)+e.slice(21,43),s=t(e,0,8).toString(),n=t(e,13,18).toString(),r=t(e,21,26).toString(),o=t(e,28,41).toString(),a=t(i,0,i.length).toString();return s===e[9]&&n===e[19]&&r===e[27]&&o===e[42]&&a===e[43]}_checkValidMRV(e){if(!e||44!=e.length&&36!=e.length)return!1;const t=(e,t,i)=>{const s=new Map([["<",0],["0",0],["1",1],["2",2],["3",3],["4",4],["5",5],["6",6],["7",7],["8",8],["9",9],["A",10],["B",11],["C",12],["D",13],["E",14],["F",15],["G",16],["H",17],["I",18],["J",19],["K",20],["L",21],["M",22],["N",23],["O",24],["P",25],["Q",26],["R",27],["S",28],["T",29],["U",30],["V",31],["W",32],["X",33],["Y",34],["Z",35]]),n=[7,3,1];let r=0;for(let o=t,a=0;o<=i;o++){let t=s.get(e[o]);t&&(r+=t*n[a%3]),a++}return r%10},i=t(e,0,8).toString(),s=t(e,13,18).toString(),n=t(e,21,26).toString();return i===e[9]&&s===e[19]&&n===e[27]}_drawRegionsults(e){let t,i,n;if(this.beingLazyDrawRegionsults=!1,this.singleFrameMode){if(!this.oriCanvas)return;t="contain",i=this.oriCanvas.width,n=this.oriCanvas.height}else{if(!this.dce.video)return;t=this.dce.video.style.objectFit||"contain",i=this.dce.video.videoWidth,n=this.dce.video.videoHeight}if(i<=0||i<=0)return;let r,o,a,l,c,d,h,u,g=this.region;if(g)if(s.LST_MANUAL_SPECIFICATION!=g.localizationSourceType)g=null;else if(g.regionMeasuredByPercentage){let e=g.location.points;if(0==e[0].x&&0==e[0].y&&100==e[1].x&&0==e[1].y&&100==e[2].x&&100==e[2].y&&0==e[3].x&&100==e[3].y)g=null;else{g={location:{points:[]}};for(let t=0;t<4;++t)g.location.points.push({x:Math.round(e[t].x/100*i),y:Math.round(e[t].y/100*n)})}}else g=JSON.parse(JSON.stringify(g)),delete g.regionMeasuredByPercentage;if(g){let e=g.location.points;r=e[0].x,c=e[0].y,o=e[1].x,d=e[1].y,a=e[2].x,h=e[2].y,l=e[3].x,u=e[3].y}if(this._cvsDrawArea){this._cvsDrawArea.style.objectFit=t;let s=this._cvsDrawArea;s.width=i,s.height=n;let _=s.getContext("2d");if(g){_.fillStyle=this.regionMaskFillStyle,_.fillRect(0,0,s.width,s.height);let e=Math.round(this.regionMaskLineWidth/2),t=(t,i,s,n,r,o)=>(-(s-t)*e/Math.hypot(s-t,n-i)-(r-t)*e/Math.hypot(r-t,o-i))/2+t,i=(t,i,s,n,r,o)=>(-(n-i)*e/Math.hypot(s-t,n-i)-(o-i)*e/Math.hypot(r-t,o-i))/2+i;_.globalCompositeOperation="destination-out",_.fillStyle="#000",_.beginPath(),_.moveTo(t(r,c,o,d,l,u),i(r,c,o,d,l,u)),_.lineTo(t(o,d,r,c,a,h),i(o,d,r,c,a,h)),_.lineTo(t(a,h,o,d,l,u),i(a,h,o,d,l,u)),_.lineTo(t(l,u,a,h,r,c),i(l,u,a,h,r,c)),_.fill(),_.globalCompositeOperation="source-over",_.strokeStyle=this.regionMaskStrokeStyle,_.lineWidth=this.regionMaskLineWidth,_.beginPath(),_.moveTo(r,c),_.lineTo(o,d),_.lineTo(a,h),_.lineTo(l,u),_.closePath(),_.stroke()}if(e){_.globalCompositeOperation="destination-over",_.fillStyle=this.highlightFillStyle,_.strokeStyle=this.highlightStrokeStyle,_.lineWidth=this.highlightLineWidth,e=e||[];for(let t of e)for(let e of t.lineResults){let t=e.location.points;_.beginPath(),_.moveTo(t[0].x,t[0].y),_.lineTo(t[1].x,t[1].y),_.lineTo(t[2].x,t[2].y),_.lineTo(t[3].x,t[3].y),_.fill(),_.beginPath(),_.moveTo(t[0].x,t[0].y),_.lineTo(t[1].x,t[1].y),_.lineTo(t[2].x,t[2].y),_.lineTo(t[3].x,t[3].y),_.closePath(),_.stroke()}}this.singleFrameMode&&(_.globalCompositeOperation="destination-over",_.drawImage(this.oriCanvas,0,0))}if(this._divScanArea&&this.dce.video){let e=this.dce.video.offsetWidth,t=this.dce.video.offsetHeight,s=1;e/t<i/n?(s=e/i,this._divScanArea.style.left="0",this._divScanArea.style.top=Math.round((t-n*s)/2)+"px"):(s=t/n,this._divScanArea.style.left=Math.round((e-i*s)/2)+"px",this._divScanArea.style.top="0");let _=g?Math.round(Math.min(r,o,a,l)*s):0,f=g?Math.round(Math.min(c,d,h,u)*s):0,m=g?Math.round(Math.max(r,o,a,l)*s-_):Math.round(i*s),p=g?Math.round(Math.max(c,d,h,u)*s-f):Math.round(n*s);this._divScanArea.style.marginLeft=_+"px",this._divScanArea.style.marginTop=f+"px",this._divScanArea.style.width=m+"px",this._divScanArea.style.height=p+"px"}}_clearRegionsults(){this._cvsDrawArea&&(this._cvsDrawArea.width=this._cvsDrawArea.height=0)}startScanning(t){return e(this,void 0,void 0,(function*(){if("closed"!=this._tempSolutionStatus)return;if(this._tempSolutionStatus="opening",!this.dce)throw new Error("Need to set 'cameraEnhancer' first.");if("opening"!=this._tempSolutionStatus)return;this._bindUI(),t&&this._show();let e=yield this.dce.play();return"opening"==this._tempSolutionStatus?(this._bPauseScan=!1,this.singleFrameMode||(this._loopReadVideo(),this._drawRegionsults()),this._tempSolutionStatus="opened",e):void 0}))}stopScanning(e){this.stop(),this._unbindUI(),this.dce&&this.dce.stopFetchingLoop(),this._bPauseScan=!0,e&&this.dce&&(this.dce.getUIElement().style.display="none"),this._tempSolutionStatus="closed"}pauseScanning(){this.dce&&this.dce.stopFetchingLoop(),this._bPauseScan=!0,this._clearRegionsults(),this._divScanLight&&(this._divScanLight.style.display="none")}resumeScanning(){this._assertOpen(),this._bPauseScan=!1}destroyContext(){if(!this.bDestroyed)return o._onLog&&o._onLog("destroy()"),this.bDestroyed=!0,(this.dce||"opening"===this._tempSolutionStatus)&&this.stopScanning(),new Promise(((e,t)=>{let i=o._nextTaskID++;o._taskCallbackMap.set(i,(i=>{if(i.success)return e();{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),o._dlrWorker.postMessage({type:"destroy",id:i,instanceID:this._instanceID})}))}}var a,l;o._jsVersion="2.2.2",o._jsEditVersion="20220302",o._version="loading...(JS "+o._jsVersion+"."+o._jsEditVersion+")",o._license=!n&&document.currentScript&&document.currentScript.getAttribute("data-license")||"",o._sessionPassword=!n&&document.currentScript&&document.currentScript.getAttribute("data-sessionPassword")||"",o.browserInfo=function(){if(!n){var e={init:function(){this.browser=this.searchString(this.dataBrowser)||"unknownBrowser",this.version=this.searchVersion(navigator.userAgent)||this.searchVersion(navigator.appVersion)||"unknownVersion",this.OS=this.searchString(this.dataOS)||"unknownOS","Linux"==this.OS&&-1!=navigator.userAgent.indexOf("Windows NT")&&(this.OS="HarmonyOS")},searchString:function(e){for(var t=0;t<e.length;t++){var i=e[t].string,s=e[t].prop;if(this.versionSearchString=e[t].versionSearch||e[t].identity,i){if(-1!=i.indexOf(e[t].subString))return e[t].identity}else if(s)return e[t].identity}},searchVersion:function(e){var t=e.indexOf(this.versionSearchString);if(-1!=t)return parseFloat(e.substring(t+this.versionSearchString.length+1))},dataBrowser:[{string:navigator.userAgent,subString:"Edge",identity:"Edge"},{string:navigator.userAgent,subString:"OPR",identity:"OPR"},{string:navigator.userAgent,subString:"Chrome",identity:"Chrome"},{string:navigator.vendor,subString:"Apple",identity:"Safari",versionSearch:"Version"},{string:navigator.userAgent,subString:"Firefox",identity:"Firefox"},{string:navigator.userAgent,subString:"MSIE",identity:"Explorer",versionSearch:"MSIE"}],dataOS:[{string:navigator.userAgent,subString:"HarmonyOS",identity:"HarmonyOS"},{string:navigator.userAgent,subString:"Android",identity:"Android"},{string:navigator.userAgent,subString:"iPhone",identity:"iPhone"},{string:navigator.platform,subString:"Win",identity:"Windows"},{string:navigator.platform,subString:"Mac",identity:"Mac"},{string:navigator.platform,subString:"Linux",identity:"Linux"}]};return e.init(),{browser:e.browser,version:e.version,OS:e.OS}}if(n)return{browser:"ssr",version:0,OS:"ssr"}}(),o._workerName="dlr-"+o._jsVersion+".worker.js",o._engineResourcePath=(()=>{if(!n&&document.currentScript){let e=document.currentScript.src,t=e.indexOf("?");if(-1!=t)e=e.substring(0,t);else{let t=e.indexOf("#");-1!=t&&(e=e.substring(0,t))}return e.substring(0,e.lastIndexOf("/")+1)}return"./"})(),o._licenseServer=[],o._deviceFriendlyName="",o._isShowRelRecognizeTimeInResults=!1,o._bWasmDebug=!1,o._bNeverShowDialog=!1,o._nextTaskID=0,o._taskCallbackMap=new Map,o._loadWasmStatus="unload",o._loadWasmCallbackArr=[],o.onResourcesLoadStarted=null,o.onResourcesLoadProgress=null,o.onResourcesLoaded=null,o._lastErrorCode=0,o._lastErrorString="",o._defaultUIElementURL="@engineResourcePath/dlr.ui.html",o._loadWasmErr=null,function(e){e[e.GTM_INVERTED=1]="GTM_INVERTED",e[e.GTM_ORIGINAL=2]="GTM_ORIGINAL",e[e.GTM_AUTO=4]="GTM_AUTO",e[e.GTM_REV=2147483648]="GTM_REV",e[e.GTM_SKIP=0]="GTM_SKIP"}(a||(a={})),function(e){e[e.RPM_AUTO=1]="RPM_AUTO",e[e.RPM_GENERAL=2]="RPM_GENERAL",e[e.RPM_GENERAL_RGB_CONTRAST=4]="RPM_GENERAL_RGB_CONTRAST",e[e.RPM_GENERAL_GRAY_CONTRAST=8]="RPM_GENERAL_GRAY_CONTRAST",e[e.RPM_GENERAL_HSV_CONTRAST=16]="RPM_GENERAL_HSV_CONTRAST",e[e.RPM_REV=2147483648]="RPM_REV",e[e.RPM_SKIP=0]="RPM_SKIP"}(l||(l={}));export{i as EnumDLRErrorCode,a as EnumDLRGrayscaleTransformationMode,t as EnumDLRImagePixelFormat,l as EnumDLRRegionPredetectionMode,o as LabelRecognizer};

@@ -7,6 +7,6 @@ /*!

* @author Dynamsoft
* @version 2.2.1 (js 20220216)
* @version 2.2.2 (js 20220302)
* @fileoverview Dynamsoft JavaScript Library for Label Recognizer
* More info on DLR JS: https://www.dynamsoft.com/label-recognizer/sdk-javascript/
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).Dynamsoft=e.Dynamsoft||{},e.Dynamsoft.DLR={}))}(this,(function(e){"use strict";function t(e,t,i,s){return new(i||(i=Promise))((function(n,r){function o(e){try{l(s.next(e))}catch(e){r(e)}}function a(e){try{l(s.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}l((s=s.apply(e,t||[])).next())}))}var i,s,n;e.EnumDLRImagePixelFormat=void 0,(i=e.EnumDLRImagePixelFormat||(e.EnumDLRImagePixelFormat={}))[i.IPF_BINARY=0]="IPF_BINARY",i[i.IPF_BINARYINVERTED=1]="IPF_BINARYINVERTED",i[i.IPF_GRAYSCALED=2]="IPF_GRAYSCALED",i[i.IPF_NV21=3]="IPF_NV21",i[i.IPF_RGB_565=4]="IPF_RGB_565",i[i.IPF_RGB_555=5]="IPF_RGB_555",i[i.IPF_RGB_888=6]="IPF_RGB_888",i[i.IPF_ARGB_8888=7]="IPF_ARGB_8888",i[i.IPF_RGB_161616=8]="IPF_RGB_161616",i[i.IPF_ARGB_16161616=9]="IPF_ARGB_16161616",i[i.IPF_ABGR_8888=10]="IPF_ABGR_8888",i[i.IPF_ABGR_16161616=11]="IPF_ABGR_16161616",i[i.IPF_BGR_888=12]="IPF_BGR_888",e.EnumDLRErrorCode=void 0,(s=e.EnumDLRErrorCode||(e.EnumDLRErrorCode={}))[s.OK=0]="OK",s[s.UNKNOWN=-1e4]="UNKNOWN",s[s.NO_MEMORY=-10001]="NO_MEMORY",s[s.NULL_POINTER=-10002]="NULL_POINTER",s[s.LICENSE_INVALID=-10003]="LICENSE_INVALID",s[s.LICENSE_EXPIRED=-10004]="LICENSE_EXPIRED",s[s.FILE_NOT_FOUND=-10005]="FILE_NOT_FOUND",s[s.FILETYPE_NOT_SUPPORTED=-10006]="FILETYPE_NOT_SUPPORTED",s[s.BPP_NOT_SUPPORTED=-10007]="BPP_NOT_SUPPORTED",s[s.IMAGE_READ_FAILED=-10012]="IMAGE_READ_FAILED",s[s.TIFF_READ_FAILED=-10013]="TIFF_READ_FAILED",s[s.PDF_READ_FAILED=-10021]="PDF_READ_FAILED",s[s.PDF_DLL_MISSING=-10022]="PDF_DLL_MISSING",s[s.RECOGNITION_TIMEOUT=-10026]="RECOGNITION_TIMEOUT",s[s.JSON_PARSE_FAILED=-10030]="JSON_PARSE_FAILED",s[s.JSON_TYPE_INVALID=-10031]="JSON_TYPE_INVALID",s[s.JSON_KEY_INVALID=-10032]="JSON_KEY_INVALID",s[s.JSON_VALUE_INVALID=-10033]="JSON_VALUE_INVALID",s[s.JSON_NAME_KEY_MISSING=-10034]="JSON_NAME_KEY_MISSING",s[s.JSON_NAME_VALUE_DUPLICATED=-10035]="JSON_NAME_VALUE_DUPLICATED",s[s.TEMPLATE_NAME_INVALID=-10036]="TEMPLATE_NAME_INVALID",s[s.PARAMETER_VALUE_INVALID=-10038]="PARAMETER_VALUE_INVALID",s[s.SET_MODE_ARGUMENT_ERROR=-10051]="SET_MODE_ARGUMENT_ERROR",s[s.GET_MODE_ARGUMENT_ERROR=-10055]="GET_MODE_ARGUMENT_ERROR",s[s.CHARACTER_MODEL_FILE_NOT_FOUND=-10100]="CHARACTER_MODEL_FILE_NOT_FOUND",function(e){e[e.LST_MANUAL_SPECIFICATION=1]="LST_MANUAL_SPECIFICATION",e[e.LST_PREDETECTED_REGION=2]="LST_PREDETECTED_REGION",e[e.LST_BARCODE=4]="LST_BARCODE"}(n||(n={}));const r=!!("object"==typeof global&&global.process&&global.process.release&&global.process.release.name&&"undefined"==typeof HTMLCanvasElement),o=!r&&"undefined"==typeof self,a=r?global:o?{}:self;class l{constructor(){this._canvasMaxWH="iPhone"==l.browserInfo.OS||"Android"==l.browserInfo.OS?2048:4096,this._instanceID=void 0,this.bSaveOriCanvas=!1,this.oriCanvas=null,this._region=null,this._timeStartRecognize=null,this._timeEnterInnerDLR=null,this.recognizeRecords={},this.drawRegionsultRecords={},this.bDestroyed=!1,this._setWarnnedEx=new Set,this._lastErrorCode=0,this._lastErrorString="",this._lastInnerDecodeDuration=0,this._clickIptSingleFrameMode=()=>{},this.intervalTime=0,this._intervalGetVideoFrame=0,this.array_getFrameTimeCost=[],this.array_decodeFrameTimeCost=[],this._bPauseScan=!1,this._intervalDetectVideoPause=1e3,this._cvsDrawArea=null,this._divScanArea=null,this._divScanLight=null,this._selCam=null,this._selRsl=null,this._selMinLtr=null,this._optGotMinLtr=null,this._btnClose=null,this._minLetter=0,this._soundOnSuccessfullRead=!r&&new Audio("data:audio/mpeg;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjI5LjEwMAAAAAAAAAAAAAAA/+M4wAAAAAAAAAAAAEluZm8AAAAPAAAABQAAAkAAgICAgICAgICAgICAgICAgICAgKCgoKCgoKCgoKCgoKCgoKCgoKCgwMDAwMDAwMDAwMDAwMDAwMDAwMDg4ODg4ODg4ODg4ODg4ODg4ODg4P//////////////////////////AAAAAExhdmM1OC41NAAAAAAAAAAAAAAAACQEUQAAAAAAAAJAk0uXRQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/+MYxAANQAbGeUEQAAHZYZ3fASqD4P5TKBgocg+Bw/8+CAYBA4XB9/4EBAEP4nB9+UOf/6gfUCAIKyjgQ/Kf//wfswAAAwQA/+MYxAYOqrbdkZGQAMA7DJLCsQxNOij///////////+tv///3RWiZGBEhsf/FO/+LoCSFs1dFVS/g8f/4Mhv0nhqAieHleLy/+MYxAYOOrbMAY2gABf/////////////////usPJ66R0wI4boY9/8jQYg//g2SPx1M0N3Z0kVJLIs///Uw4aMyvHJJYmPBYG/+MYxAgPMALBucAQAoGgaBoFQVBUFQWDv6gZBUFQVBUGgaBr5YSgqCoKhIGg7+IQVBUFQVBoGga//SsFSoKnf/iVTEFNRTMu/+MYxAYAAANIAAAAADEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"),this.bPlaySoundOnSuccessfulRead=!1,this.bVibrateOnSuccessfulRead=!1,this.vibrateDuration=300,this.regionMaskFillStyle="rgba(0,0,0,0.5)",this.regionMaskStrokeStyle="rgb(254,142,20)",this.regionMaskLineWidth=2,this.highlightFillStyle="rgba(254,180,32,0.3)",this.highlightStrokeStyle="rgba(254,180,32,0.9)",this.highlightLineWidth=1,this.beingLazyDrawRegionsults=!1,this.currentSettingsTemplate="cppdefault",this.dce=null,this._onCameraSelChange=()=>{this._divScanLight&&(this._divScanLight.style.display="none"),this._drawRegionsults(),this.array_decodeFrameTimeCost.length=0,this.array_getFrameTimeCost.length=0,this._intervalGetVideoFrame=0},this._onResolutionSelChange=()=>{this._divScanLight&&(this._divScanLight.style.display="none"),this._drawRegionsults(),this.array_decodeFrameTimeCost.length=0,this.array_getFrameTimeCost.length=0,this._intervalGetVideoFrame=0},this._onMinLetterSelChange=e=>t(this,void 0,void 0,(function*(){let t=e.target.value;if("got"===t)return;t=JSON.parse(t);let i=JSON.parse(yield this.outputRuntimeSettingsToString());i.LabelRecognizerParameterArray[0].LineStringLengthRange=[t,999],i.TextAreaArray[0].LineStringLengthRange=[t,999],yield this.updateRuntimeSettingsFromString(i)})),this._onCloseBtnClick=()=>{this.stopScanning(!0)},this._tempSolutionStatus="closed"}static getVersion(){return this._version}static get license(){return this._license}static set license(e){if("unload"!=this._loadWasmStatus)throw new Error("`license` is not allowed to change after `createInstance` or `loadWasm` is called.");l._license=e}static initLicense(e){if("unload"!=this._loadWasmStatus)throw new Error("`license` is not allowed to change after `createInstance` or `loadWasm` is called.");l._license=e}static set sessionPassword(e){if("unload"!=this._loadWasmStatus)throw new Error("`sessionPassword` is not allowed to change after `createInstance` or `loadWasm` is called.");l._sessionPassword=e}static get sessionPassword(){return this._sessionPassword}static detectEnvironment(){return t(this,void 0,void 0,(function*(){let e={wasm:"undefined"!=typeof WebAssembly&&("undefined"==typeof navigator||!(/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)&&/\(.+\s11_2_([2-6]).*\)/.test(navigator.userAgent))),worker:!!(r?process.version>="v12":"undefined"!=typeof Worker),getUserMedia:!("undefined"==typeof navigator||!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia),camera:!1,browser:this.browserInfo.browser,version:this.browserInfo.version,OS:this.browserInfo.OS};if(e.getUserMedia)try{(yield navigator.mediaDevices.getUserMedia({video:!0})).getTracks().forEach((e=>{e.stop()})),e.camera=!0}catch(e){}return e}))}static get engineResourcePath(){return this._engineResourcePath}static set engineResourcePath(e){if("unload"!=this._loadWasmStatus)throw new Error("`engineResourcePath` is not allowed to change after `createInstance` or `loadWasm` is called.");if(null==e&&(e="./"),r||o)l._engineResourcePath=e;else{let t=document.createElement("a");t.href=e,l._engineResourcePath=t.href}this._engineResourcePath.endsWith("/")||(l._engineResourcePath+="/")}static get licenseServer(){return this._licenseServer}static set licenseServer(e){if("unload"!=this._loadWasmStatus)throw new Error("`licenseServer` is not allowed to change after `createInstance` or `loadWasm` is called.");if(null==e)l._licenseServer=[];else{e instanceof Array||(e=[e]);for(let t=0;t<e.length;++t){if(!r&&!o){let i=document.createElement("a");i.href=e[t],e[t]=i.href}e[t].endsWith("/")||(e[t]+="/")}l._licenseServer=e}}static get deviceFriendlyName(){return this._deviceFriendlyName}static set deviceFriendlyName(e){if("unload"!=this._loadWasmStatus)throw new Error("`deviceFriendlyName` is not allowed to change after loadWasm is called.");l._deviceFriendlyName=e||""}get ifSaveOriginalImageInACanvas(){return this.bSaveOriCanvas}set ifSaveOriginalImageInACanvas(e){this.dce&&(this.dce.ifSaveOriginalImageInACanvas=e),this.bSaveOriCanvas=e}getOriginalImageInACanvas(){return this.oriCanvas}set region(e){this._region=e,this.dce&&!this.singleFrameMode&&(this.beingLazyDrawRegionsults=!0,setTimeout((()=>{this.beingLazyDrawRegionsults&&this._drawRegionsults()}),500))}get region(){return this._region}static isWasmLoaded(){return"loadSuccess"==this._loadWasmStatus}isContextDestroyed(){return this.bDestroyed}static get lastErrorCode(){return this._lastErrorCode}static get lastErrorString(){return this._lastErrorString}get lastErrorCode(){return this._lastErrorCode}get lastErrorString(){return this._lastErrorString}static get defaultUIElementURL(){var e;return null===(e=this._defaultUIElementURL)||void 0===e?void 0:e.replace("@engineResourcePath/",l.engineResourcePath)}static set defaultUIElementURL(e){this._defaultUIElementURL=e}get singleFrameMode(){if(!this.dce)throw new Error("Need to set 'cameraEnhancer' first.");return this.dce.singleFrameMode}set singleFrameMode(e){if(!this.dce)throw new Error("Need to set 'cameraEnhancer' first.");this.dce.singleFrameMode=e,e&&(()=>{t(this,void 0,void 0,(function*(){let e=yield this.getScanSettings();e.trustFrameCount=1,yield this.updateScanSettings(e)}))})()}_assertOpen(){if(!this.dce)throw new Error("Need to set 'cameraEnhancer' first.");if(!this.dce.isOpen())throw Error("The camera is not open.")}_updateMinLtrSel(e){if(this._minLetter=e,this._optGotMinLtr){const t=e?`${e}+ letters`:"any letter";this._optGotMinLtr.innerText=t,this._selMinLtr&&this._optGotMinLtr.parentNode==this._selMinLtr&&(this._selMinLtr.value="got")}}get soundOnSuccessfullRead(){return this._soundOnSuccessfullRead}set soundOnSuccessfullRead(e){e instanceof HTMLAudioElement?this._soundOnSuccessfullRead=e:this._soundOnSuccessfullRead=new Audio(e)}get whenToPlaySoundforSuccessfulRead(){return!0===this.bPlaySoundOnSuccessfulRead?"frame":this.bPlaySoundOnSuccessfulRead?this.bPlaySoundOnSuccessfulRead:"never"}set whenToPlaySoundforSuccessfulRead(e){this.bPlaySoundOnSuccessfulRead="never"!==e&&e}get whenToVibrateforSuccessfulRead(){return!0===this.bVibrateOnSuccessfulRead?"frame":this.bVibrateOnSuccessfulRead?this.bVibrateOnSuccessfulRead:"never"}set whenToVibrateforSuccessfulRead(e){this.bVibrateOnSuccessfulRead="never"!==e&&e}get cameraEnhancer(){return this.dce}set cameraEnhancer(e){if(r)throw new Error("`cameraEnhancer` is not supported in Node.js.");this.dce=e,this.adjustDCESettings()}adjustDCESettings(){this.dce&&(l._onLog&&l._onLog("adjustDCESettings()"),this.dce.bufferRefreshInterval=200,this.dce.alwaysRefreshBuffer=!1,this.dce.ifSaveOriginalImageInACanvas=this.bSaveOriCanvas,this.dce._singleFrameModeIpt=function(){let e=document.createElement("input");return e.setAttribute("type","file"),e.setAttribute("accept","image/*"),e.setAttribute("capture",""),e.addEventListener("change",(()=>t(this,void 0,void 0,(function*(){let t=e.files[0];e.value="",this.onSingleFrameAcquired(t)})))),e.style.position="fixed",e.style.left="0",e.style.top="0",e.style.width="1px",e.style.height="1px",e.style.backgroundColor="transparent",e.style.color="transparent",this._video.parentElement.appendChild(e),e},this.dce.onSingleFrameAcquired=e=>t(this,void 0,void 0,(function*(){let t=yield this.recognize(e);yield this.clearMapDecodeRecord();for(let e of t)for(let t of e.lineResults)t.bUnduplicated&&delete e.bUnduplicated;if(this._drawRegionsults(t),this.onFrameRead&&this.dce.isOpen()&&!this._bPauseScan&&this.onFrameRead(t),this.onUniqueRead&&this.dce.isOpen()&&!this._bPauseScan)for(let e of t){if(["passportMRZ","visaMRZ","MRZ"].includes(this.currentSettingsTemplate)){let t="";for(let i of e.lineResults)i.bUnduplicated&&(t.length>0&&(t+="\n"),t+=i.text);t.length>0&&this.onUniqueRead(t,this._cloneDecodeResults(e.lineResults))}else for(let t of e.lineResults)t.bUnduplicated&&this.onUniqueRead(t.text,[this._cloneDecodeResults(t)])}})),this._clickIptSingleFrameMode=this.dce._clickIptSingleFrameMode)}static loadWasm(){return t(this,void 0,void 0,(function*(){if(r&&process.version<"v12")throw new Error("DLRJS SDK requires nodejs version >= v12.");let i,s=this.license,n=JSON.parse(JSON.stringify(this._licenseServer)),o=this._sessionPassword,c=null,d=null,h=0;if(s.startsWith("t")||s.startsWith("f"))h=0;else if(0===s.length||s.startsWith("P")||s.startsWith("L"))h=1;else{h=2;const e=s.indexOf(":");if(-1!=e&&(s=s.substring(e+1)),s.startsWith("DLS2")){let e=s.substring(4);e=r?Buffer.from(e,"base64").toString("binary"):atob(e);const t=JSON.parse(e);if(t.handshakeCode?s=t.handshakeCode:t.organizationID&&(s=t.organizationID),"number"==typeof s&&(s=JSON.stringify(s)),s||(s=""),0===n.length){let e=[];t.mainServerURL&&(e[0]=t.mainServerURL),t.standbyServerURL&&(e[1]=t.standbyServerURL),this.licenseServer=e,n=this.licenseServer}!o&&t.sessionPassword&&(o=t.sessionPassword),t.chargeWay&&(d=t.chargeWay),t.limitedLicenseModules&&(c=t.limitedLicenseModules)}}if(h&&(r?process.version<"v15"&&(i="To use online key requires nodejs version >= v15."):(a.crypto||(i="Please upgrade your browser to support online key."),a.crypto.subtle||(i="Require https to use online key in this browser."))),i){if(1!==h)throw new Error(i);h=0,console.warn(i),this._lastErrorCode=e.EnumDLRErrorCode.UNKNOWN,this._lastErrorString=i}return 1===h&&(s="",console.warn("Applying for a public trial license ...")),yield new Promise(((e,i)=>t(this,void 0,void 0,(function*(){switch(this._loadWasmStatus){case"unload":{l._loadWasmStatus="loading";let e=this.engineResourcePath+this._workerName;if(r||this.engineResourcePath.startsWith(location.origin)||(e=yield fetch(e).then((e=>e.blob())).then((e=>URL.createObjectURL(e)))),r){const t=require("worker_threads");l._dlrWorker=new t.Worker(e)}else l._dlrWorker=new Worker(e);this._dlrWorker.onerror=e=>{l._loadWasmStatus="loadFail";let t=new Error(e.message);this._loadWasmErr=t;for(let e of this._loadWasmCallbackArr)e(t);this._loadWasmCallbackArr=[]},this._dlrWorker.onmessage=e=>t(this,void 0,void 0,(function*(){let t=e.data?e.data:e;switch(t.type){case"log":this._onLog&&this._onLog(t.message);break;case"load":{t.message&&(t.message=t.message.replace("(https://www.dynamsoft.com/purchase-center/)","(https://www.dynamsoft.com/store/dynamsoft-label-recognizer/#javascript)"));let e=!1;if(1===h&&(e=!0),t.success){l._loadWasmStatus="loadSuccess",l._version=t.version+"(JS "+this._jsVersion+"."+this._jsEditVersion+")",this._onLog&&this._onLog("load dlr worker success");for(let e of this._loadWasmCallbackArr)e();this._loadWasmCallbackArr=[],this._dlrWorker.onerror=null,t.message&&console.warn(t.message)}else{let i=new Error(t.message);i.stack=t.stack+"\n"+i.stack,l._loadWasmStatus="loadFail",this._loadWasmErr=i;for(let e of this._loadWasmCallbackArr)e(i);this._loadWasmCallbackArr=[],e||111==t.ltsErrorCode&&-1!=t.message.toLowerCase().indexOf("trial license")&&(e=!0)}e&&this.showDialog(t.success?"warn":"error",t.message);break}case"task":{let e=t.id,i=t.body;try{this._taskCallbackMap.get(e)(i),this._taskCallbackMap.delete(e)}catch(t){throw this._taskCallbackMap.delete(e),t}break}case"message":"modelLoadStarted"===t.body.message?l.onResourcesLoadStarted&&setTimeout((()=>l.onResourcesLoadStarted(t.body.resourcesPath)),0):"modelLoaded"===t.body.message&&l.onResourcesLoaded&&setTimeout((()=>l.onResourcesLoaded(t.body.resourcesPath)),0);default:this._onLog&&this._onLog(e)}})),r&&this._dlrWorker.on("message",this._dlrWorker.onmessage),this._dlrWorker.postMessage({type:"loadWasm",bd:this._bWasmDebug,engineResourcePath:this.engineResourcePath,version:this._jsVersion,brtk:!!h,bptk:1===h,lcs:s,dm:!r&&location.origin.startsWith("http")?location.origin:"https://localhost",browserInfo:this.browserInfo,deviceFriendlyName:this.deviceFriendlyName,ls:n,sp:o,lm:c,cw:d})}case"loading":this._loadWasmCallbackArr.push((t=>{t?i(t):e()}));break;case"loadSuccess":e();break;case"loadFail":i(this._loadWasmErr)}}))))}))}static showDialog(e,i){return t(this,void 0,void 0,(function*(){if(!r&&!this._bNeverShowDialog)try{let t=yield fetch(this.engineResourcePath+"dls.license.dialog.html");if(!t.ok)throw Error("Get license dialog fail. Network Error: "+t.statusText);let s=yield t.text();if(!s.trim().startsWith("<"))throw Error("Get license dialog fail. Can't get valid HTMLElement.");let n=document.createElement("div");n.innerHTML=s;let r=[];for(let e=0;e<n.childElementCount;++e){let t=n.children[e];t instanceof HTMLStyleElement&&(r.push(t),document.head.append(t))}let o=1==n.childElementCount?n.children[0]:n;o.remove();let a,l,c,d,h,u=[o],g=o.children;for(let e of g)u.push(e);for(let e=0;e<u.length;++e)for(let t of u[e].children)u.push(t);for(let t of u)if(!a&&t.classList.contains("dls-license-mask"))a=t,t.addEventListener("click",(e=>{if(t==e.target){o.remove();for(let e of r)e.remove()}}));else if(!l&&t.classList.contains("dls-license-icon-close"))l=t,t.addEventListener("click",(()=>{o.remove();for(let e of r)e.remove()}));else if(!c&&t.classList.contains("dls-license-icon-error"))c=t,"error"!=e&&t.remove();else if(!d&&t.classList.contains("dls-license-icon-warn"))d=t,"warn"!=e&&t.remove();else if(!h&&t.classList.contains("dls-license-msg-content")){h=t;let e=i;for(;e;){let i=e.indexOf("["),s=e.indexOf("]",i),n=e.indexOf("(",s),r=e.indexOf(")",n);if(-1==i||-1==s||-1==n||-1==r){t.appendChild(new Text(e));break}i>0&&t.appendChild(new Text(e.substring(0,i)));let o=document.createElement("a"),a=e.substring(i+1,s);o.innerText=a;let l=e.substring(n+1,r);o.setAttribute("href",l),o.setAttribute("target","_blank"),t.appendChild(o),e=e.substring(r+1)}}document.body.appendChild(o)}catch(e){this._onLog&&this._onLog(e.message||e)}}))}static createInstanceInWorker(){return t(this,void 0,void 0,(function*(){return yield this.loadWasm(),yield new Promise(((e,t)=>{let i=this._nextTaskID++;this._taskCallbackMap.set(i,(i=>{if(i.success)return e(i.instanceID);{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),this._dlrWorker.postMessage({type:"createInstance",id:i,bScanner:!1})}))}))}static createInstance(e){return t(this,void 0,void 0,(function*(){let t=new l;return t._instanceID=yield this.createInstanceInWorker(),e&&e.runtimeSettings&&t.updateRuntimeSettingsFromString(e.runtimeSettings),t}))}recognize(i,s){return t(this,void 0,void 0,(function*(){if(l._onLog&&l._onLog("recognize(source: any, modelName?: string)"),l._onLog&&(this._timeStartRecognize=Date.now()),s=s||{},r)return i instanceof Buffer?yield this._recognizeFileInMemory_Uint8Array(new Uint8Array(i),s):i instanceof Uint8Array?yield this._recognizeFileInMemory_Uint8Array(i,s):"string"==typeof i?"data:image/"==i.substring(0,11)?yield this._recognize_Base64(i,s):"http"==i.substring(0,4)?yield this._recognize_Url(i,s):yield this._recognize_FilePath(i,s):yield Promise.reject(TypeError("'_recognize(source, config)': Type of 'source' should be 'Buffer', 'Uint8Array', 'string(base64 with image mime)' or 'string(url)'."));if(i instanceof Blob)return yield this._recognize_Blob(i,s);if(i instanceof ArrayBuffer)return yield this._recognize_ArrayBuffer(i,s);if(i instanceof Uint8Array||i instanceof Uint8ClampedArray)return yield this._recognize_Uint8Array(i,s);if(i instanceof HTMLImageElement||"undefined"!=typeof ImageBitmap&&i instanceof ImageBitmap)return yield this._recognize_Image(i,s);if(i instanceof HTMLCanvasElement||"undefined"!=typeof OffscreenCanvas&&i instanceof OffscreenCanvas)return yield this._recognize_Canvas(i,s);if(i instanceof HTMLVideoElement)return yield this._recognize_Video(i,s);if("string"==typeof i)return"data:image/"==i.substring(0,11)?yield this._recognize_Base64(i,s):yield this._recognize_Url(i,s);if(i&&"object"==typeof i){const{data:t,canvas:s,region:n,sx:r,sy:o,width:a,height:l}=i;return s&&t?yield this._recognizeBuffer_Uint8Array(t,s.width,s.height,4*s.width,e.EnumDLRImagePixelFormat.IPF_ABGR_8888):t&&a&&l?yield this._recognizeBuffer_Uint8Array(t,a,l,a,e.EnumDLRImagePixelFormat.IPF_GRAYSCALED):yield Promise.reject(TypeError("'_recognize(source, config)': Type of 'source' should be 'Blob', 'ArrayBuffer', 'Uint8Array', 'HTMLImageElement', 'HTMLCanvasElement', 'HTMLVideoElement', 'string(base64 with image mime)', 'string(url)' or 'object(dceFrame)'."))}return yield Promise.reject(TypeError("'_recognize(source, config)': Type of 'source' should be 'Blob', 'ArrayBuffer', 'Uint8Array', 'HTMLImageElement', 'HTMLCanvasElement', 'HTMLVideoElement', 'string(base64 with image mime)', 'string(url)' or 'object(dceFrame)'."))}))}recognizeBase64String(e,i){return t(this,void 0,void 0,(function*(){let t={};return i&&(t.modelName=i),this._recognize_Base64(e,t)}))}recognizeUrl(e,i){return t(this,void 0,void 0,(function*(){let t={};return i&&(t.modelName=i),this._recognize_Url(e,t)}))}_recognizeBuffer_Uint8Array(e,i,s,n,r,o){return t(this,void 0,void 0,(function*(){return yield new Promise(((t,a)=>{let c=l._nextTaskID++;l._taskCallbackMap.set(c,(e=>{if(e.success){let i,s=l._onLog?Date.now():0;this._lastInnerDecodeDuration=e.duration,this.bufferShared&&!this.bufferShared.length&&(this.bufferShared=e.buffer);try{i=this._handleRetJsonString(e.decodeReturn);const t=e=>!!e&&("VIN_NA"===this.currentSettingsTemplate?this._checkValidVIN(e):"passportMRZ"===this.currentSettingsTemplate?44==e.length&&(/[0-9]/.test(e)?this._checkValidMRP(e):null):"visaMRZ"===this.currentSettingsTemplate?(44==e.length||36==e.length)&&(/[0-9]/.test(e)?this._checkValidMRV(e):null):null);for(let e of i)for(let i of e.lineResults)i.isCheckDigitMatched=t(i.text)}catch(e){return a(e)}if(l._onLog){let e=Date.now();l._onLog("time get result: "+s),l._onLog("Handle image cost: "+(this._timeEnterInnerDLR-this._timeStartRecognize)),l._onLog("worker recognize image cost: "+(s-this._timeEnterInnerDLR)),l._onLog("worker handle results: "+(e-s)),l._onLog("Total recognize image cost: "+(e-this._timeStartRecognize))}return t(i)}{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,a(t)}})),l._onLog&&(this._timeEnterInnerDLR=Date.now()),l._onLog&&l._onLog("Send buffer to worker:"+this._timeEnterInnerDLR),l._dlrWorker.postMessage({type:"recognizeByBuffer",id:c,instanceID:this._instanceID,body:{config:o,imageData:{bytes:e,length:s*i*4,width:i,height:s,stride:n,format:r}}},[e.buffer])}))}))}_recognizeBuffer_Blob(e,i,s,n,r,o){return t(this,void 0,void 0,(function*(){l._onLog&&l._onLog("_recognizeBuffer_Blob(buffer,width,height,stride,format)");const t=e.arrayBuffer?yield e.arrayBuffer():yield new Promise(((t,i)=>{let s=new FileReader;s.readAsArrayBuffer(e),s.onload=()=>{t(s.result)},s.onerror=()=>{i(s.error)}}));return yield this._recognizeBuffer_Uint8Array(new Uint8Array(t),i,s,n,r,o)}))}recognizeBuffer(e,i,s,n,o,a){return t(this,void 0,void 0,(function*(){let t;return l._onLog&&l._onLog("recognizeBuffer(buffer,width,height,stride,format)"),l._onLog&&(this._timeStartRecognize=Date.now()),r?e instanceof Uint8Array?t=yield this._recognizeBuffer_Uint8Array(e,i,s,n,o,a):e instanceof Buffer&&(t=yield this._recognizeBuffer_Uint8Array(new Uint8Array(e),i,s,n,o,a)):e instanceof Uint8Array||e instanceof Uint8ClampedArray?t=yield this._recognizeBuffer_Uint8Array(e,i,s,n,o,a):e instanceof ArrayBuffer?t=yield this._recognizeBuffer_Uint8Array(new Uint8Array(e),i,s,n,o,a):e instanceof Blob&&(t=yield this._recognizeBuffer_Blob(e,i,s,n,o,a)),t}))}_recognizeFileInMemory_Uint8Array(e,i){return t(this,void 0,void 0,(function*(){return yield new Promise(((t,s)=>{let n=l._nextTaskID++;l._taskCallbackMap.set(n,(e=>{if(e.success){let i;try{i=this._handleRetJsonString(e.decodeReturn)}catch(e){return s(e)}return t(i)}{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,s(t)}})),l._dlrWorker.postMessage({type:"recognizeFileInMemory",id:n,instanceID:this._instanceID,body:{config:i,bytes:e}})}))}))}getRuntimeSettings(){return t(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=l._nextTaskID++;l._taskCallbackMap.set(i,(i=>{if(i.success){let t=JSON.parse(i.results);return e(t)}{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),l._dlrWorker.postMessage({type:"getRuntimeSettings",id:i,instanceID:this._instanceID})}))}))}static isRegionNormalPreset(e){return n.LST_MANUAL_SPECIFICATION==e.localizationSourceType&&1==e.regionMeasuredByPercentage&&JSON.stringify([{x:0,y:100},{x:100,y:0},{x:100,y:100},{x:0,y:100}])===JSON.stringify(e.location.points)}updateRuntimeSettings(e){return t(this,void 0,void 0,(function*(){let t;if("string"==typeof e){if(!(e=e.trim()).startsWith("{"))return void this.updateRuntimeSettingsFromString(e);t=JSON.parse(e)}else{if("object"!=typeof e)throw TypeError("'UpdateRuntimeSettings(settings)': Type of 'settings' should be 'string' or 'PlainObject'.");t=JSON.parse(JSON.stringify(e))}const i=t.referenceRegion;l.isRegionNormalPreset(i)?this.region=null:this.region=i,this._updateMinLtrSel(0),yield new Promise(((e,i)=>{let s=l._nextTaskID++;l._taskCallbackMap.set(s,(t=>{if(t.success){try{this._handleRetJsonString(t.updateReturn)}catch(e){i(e)}return e()}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,i(e)}})),l._dlrWorker.postMessage({type:"updateRuntimeSettings",id:s,instanceID:this._instanceID,body:{settings:JSON.stringify(t)}})}))}))}resetRuntimeSettings(){return t(this,void 0,void 0,(function*(){return this.region=null,this._updateMinLtrSel(0),yield new Promise(((e,t)=>{let i=l._nextTaskID++;l._taskCallbackMap.set(i,(i=>{if(i.success)return e();{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),l._dlrWorker.postMessage({type:"resetRuntimeSettings",id:i,instanceID:this._instanceID})}))}))}updateRuntimeSettingsFromString(e){return t(this,void 0,void 0,(function*(){let t=0;if("string"==typeof e)if((e=e.trim()).startsWith("{"))e=JSON.parse(e);else{if(e.length>50)throw new Error("Error: preset longer than 50 letters.");const i=e.toLowerCase().split("-");if(i.length>2)throw new Error(`Error: '${e}' is not supported.`);if(i.includes("numberletter"))t=3,this.currentSettingsTemplate="numberLetter";else if(i.includes("numberuppercase"))t=3,this.currentSettingsTemplate="numberUppercase";else if(i.includes("number"))t=3,this.currentSettingsTemplate="number";else if(i.includes("letter"))t=3,this.currentSettingsTemplate="letter";else if(i.includes("passportmrz"))t=44,this.currentSettingsTemplate="passportMRZ";else if(i.includes("visamrz"))t=36,this.currentSettingsTemplate="visaMRZ";else if(i.includes("mrz"))t=30,this.currentSettingsTemplate="MRZ";else if(i.includes("vin_na"))t=14,this.currentSettingsTemplate="VIN_NA";else if(i.includes("vin"))t=14,this.currentSettingsTemplate="VIN";else{if(!i.includes("cppdefault"))throw new Error(`Error: '${e}' is not supported.`);this.currentSettingsTemplate="cppdefault"}i.includes("video")?this.region={localizationSourceType:n.LST_MANUAL_SPECIFICATION,location:{points:[{x:0,y:40},{x:100,y:40},{x:100,y:60},{x:0,y:60}]},regionMeasuredByPercentage:1}:this.region=null}else{if("object"!=typeof e)throw TypeError("'updateRuntimeSettingsFromString(settings)': Type of 'settings' should be 'string' or 'PlainObject'.");this.currentSettingsTemplate=null}if("object"==typeof e){const i=e.ReferenceRegionArray[0].Localization,s=i.FirstPoint?{localizationSourceType:n[i.SourceType],location:{points:[{x:i.FirstPoint[0],y:i.FirstPoint[1]},{x:i.SecondPoint[0],y:i.SecondPoint[1]},{x:i.ThirdPoint[0],y:i.ThirdPoint[1]},{x:i.FourthPoint[0],y:i.FourthPoint[1]}]},regionMeasuredByPercentage:i.MeasuredByPercentage}:null;s&&l.isRegionNormalPreset(s)?this.region=null:this.region=s;const r=e.LabelRecognizerParameterArray[0].LineStringLengthRange;t=r?r[0]:0}return this._updateMinLtrSel(t),yield new Promise(((t,i)=>{let s=l._nextTaskID++;l._taskCallbackMap.set(s,(e=>{if(e.success){try{this._handleRetJsonString(e.updateReturn)}catch(e){i(e)}return t()}{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,i(t)}})),l._dlrWorker.postMessage({type:"updateRuntimeSettingsFromString",id:s,instanceID:this._instanceID,body:{settings:e}})}))}))}outputRuntimeSettingsToString(){return t(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=l._nextTaskID++;l._taskCallbackMap.set(i,(i=>{if(i.success)return e(i.results);{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),l._dlrWorker.postMessage({type:"outputSettingsToString",id:i,instanceID:this._instanceID})}))}))}updateReferenceRegionFromBarcodeResults(e){return t(this,void 0,void 0,(function*(){return yield new Promise(((t,i)=>{let s=l._nextTaskID++;l._taskCallbackMap.set(s,(e=>{if(e.success)return t();{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,i(t)}})),l._dlrWorker.postMessage({type:"updateReferenceRegionFromBarcodeResults",id:s,instanceID:this._instanceID,body:{dbrTextResults:e}})}))}))}static appendCaffeModelBuffer(e,i){return t(this,void 0,void 0,(function*(){return yield new Promise(((t,s)=>{let n=l._nextTaskID++;l._taskCallbackMap.set(n,(e=>{if(e.success){try{return t()}catch(e){s(e)}return t()}{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,s(t)}})),l._dlrWorker.postMessage({type:"appendCaffeModelBuffer",id:n,body:{name:e,folderUrl:i}})}))}))}static eraseCaffeModelByName(e){return t(this,void 0,void 0,(function*(){return yield new Promise(((t,i)=>{let s=l._nextTaskID++;l._taskCallbackMap.set(s,(e=>{if(e.success)return t();{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,i(t)}})),l._dlrWorker.postMessage({type:"eraseCaffeModelByName",id:s,body:{name:e}})}))}))}static eraseAllCaffeModels(){return t(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=l._nextTaskID++;l._taskCallbackMap.set(i,(i=>{if(i.success)return e();{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),l._dlrWorker.postMessage({type:"eraseAllCaffeModels",id:i})}))}))}_recognize_Blob(e,i){return t(this,void 0,void 0,(function*(){l._onLog&&l._onLog("_recognize_Blob(blob: Blob)");let t=null,s=null;if("undefined"!=typeof createImageBitmap)try{t=yield createImageBitmap(e)}catch(e){}t||(s=yield function(e){return new Promise(((t,i)=>{let s=URL.createObjectURL(e),n=new Image;n.dlrObjUrl=s,n.src=s,n.onload=()=>{t(n)},n.onerror=e=>{i(new Error("Can't convert blob to image : "+(e instanceof Event?e.type:e)))}}))}(e));let n=yield this._recognize_Image(t||s,i);return t&&t.close(),n}))}_recognize_ArrayBuffer(e,i){return t(this,void 0,void 0,(function*(){return yield this._recognize_Blob(new Blob([e]),i)}))}_recognize_Uint8Array(e,i){return t(this,void 0,void 0,(function*(){return yield this._recognize_Blob(new Blob([e]),i)}))}_recognize_Image(e,i){return t(this,void 0,void 0,(function*(){l._onLog&&l._onLog("_recognize_Image(image: HTMLImageElement|ImageBitmap)"),i=i||{};let t,s,n=e instanceof HTMLImageElement?e.naturalWidth:e.width,r=e instanceof HTMLImageElement?e.naturalHeight:e.height,o=Math.max(n,r);if(o>this._canvasMaxWH){let e=this._canvasMaxWH/o;t=Math.round(n*e),s=Math.round(r*e)}else t=n,s=r;let c,d=n,h=r,u=t,g=s;!this.bSaveOriCanvas&&a.OffscreenCanvas?c=new OffscreenCanvas(u,g):(c=document.createElement("canvas"),c.width=u,c.height=g);let _=c.getContext("2d");return n==d&&r==h&&n==u&&r==g?_.drawImage(e,0,0):_.drawImage(e,0,0,d,h,0,0,u,g),e.dlrObjUrl&&URL.revokeObjectURL(e.dlrObjUrl),yield this._recognize_Canvas(c,i)}))}_recognize_Canvas(i,s){return t(this,void 0,void 0,(function*(){if(l._onLog&&l._onLog("_recognize_Canvas(canvas:HTMLCanvasElement)"),i.crossOrigin&&"anonymous"!=i.crossOrigin)throw"cors";(this.bSaveOriCanvas||this.dce&&this.singleFrameMode)&&(this.oriCanvas=i);let t=(i.dlrCtx2d||i.getContext("2d")).getImageData(0,0,i.width,i.height).data;return yield this._recognizeBuffer_Uint8Array(t,i.width,i.height,4*i.width,e.EnumDLRImagePixelFormat.IPF_ABGR_8888,s)}))}_recognize_Video(e,i){return t(this,void 0,void 0,(function*(){if(l._onLog&&l._onLog("_recognize_Video(video)"),!(e instanceof HTMLVideoElement))throw TypeError("'_recognize_Video(video [, config] )': Type of 'video' should be 'HTMLVideoElement'.");if(e.crossOrigin&&"anonymous"!=e.crossOrigin)throw"cors";i=i||{};let t,s,n=e.videoWidth,r=e.videoHeight,o=Math.max(n,r);if(o>this._canvasMaxWH){let e=this._canvasMaxWH/o;t=Math.round(n*e),s=Math.round(r*e)}else t=n,s=r;let c=n,d=r,h=t,u=s,g=n==c&&r==d&&n==h&&r==u,_=null;!this.bSaveOriCanvas&&a.OffscreenCanvas?_=new OffscreenCanvas(h,u):(_=document.createElement("canvas"),_.width=h,_.height=u);const f=_.dlrCtx2d=_.getContext("2d");return g?f.drawImage(e,0,0):f.drawImage(e,0,0,c,d,0,0,h,u),yield this._recognize_Canvas(_,i)}))}_recognize_Base64(e,i){return t(this,void 0,void 0,(function*(){if(l._onLog&&l._onLog("_recognize_Base64(base64Str)"),"string"!=typeof e&&"object"!=typeof e)return Promise.reject("'_recognize_Base64(base64Str, config)': Type of 'base64Str' should be 'string'.");if("data:image/"==e.substring(0,11)&&(e=e.substring(e.indexOf(",")+1)),r){let t=Buffer.from(e,"base64");return yield this._recognizeFileInMemory_Uint8Array(new Uint8Array(t),i)}{let t=atob(e),s=t.length,n=new Uint8Array(s);for(;s--;)n[s]=t.charCodeAt(s);return yield this._recognize_Blob(new Blob([n]),i)}}))}_recognize_Url(e,i){return t(this,void 0,void 0,(function*(){if(l._onLog&&l._onLog("_recognize_Url(url)"),"string"!=typeof e&&"object"!=typeof e)throw TypeError("'_recognize_Url(url, config)': Type of 'url' should be 'string'.");if(r){let t=yield new Promise(((t,i)=>{(e.startsWith("https")?require("https"):require("http")).get(e,(e=>{if(200==e.statusCode){let i=[];e.on("data",(e=>{i.push(e)})).on("end",(()=>{t(new Uint8Array(Buffer.concat(i)))}))}else i("http get fail, statusCode: "+e.statusCode)}))}));return yield this._recognizeFileInMemory_Uint8Array(t,i)}{let s=yield new Promise(((i,s)=>{let n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="blob",n.send(),n.onloadend=()=>t(this,void 0,void 0,(function*(){i(n.response)})),n.onerror=()=>{s(new Error("Network Error: "+n.statusText))}}));return yield this._recognize_Blob(s,i)}}))}_recognize_FilePath(e,i){return t(this,void 0,void 0,(function*(){if(l._onLog&&l._onLog("_recognize_FilePath(path)"),!r)throw Error("'_recognize_FilePath(path, config)': The method is only supported in node environment.");if("string"!=typeof e&&"object"!=typeof e)throw TypeError("'_recognize_FilePath(path, config)': Type of 'path' should be 'string'.");const t=require("fs");let s=yield new Promise(((i,s)=>{t.readFile(e,((e,t)=>{e?s(e):i(new Uint8Array(t))}))}));return yield this._recognizeFileInMemory_Uint8Array(s,i)}))}static LabelRecognizerException(t,i){let s,n=e.EnumDLRErrorCode.UNKNOWN;return"number"==typeof t?(n=t,s=new Error(i)):s=new Error(t),s.code=n,s}_handleRetJsonString(t){let i=e.EnumDLRErrorCode;if(t.results){const i=this.drawRegionsultRecords,s={};for(let e=0;e<t.results.length;e++){let n=t.results[e];if(null!=n.exception){this._setWarnnedEx.has(n.exception)||(this._setWarnnedEx.add(n.exception),console.warn(n.exception));let e={};n.exception.split(";").forEach((t=>{let i=t.indexOf(":");e[t.substring(0,i)]=t.substring(i+1)})),n.exception=e}for(let e of n.lineResults){const t=e.text;if(s[t]=1,e.bUnduplicated){(i[t]=i[t]||[]).push(e)}else i[t]&&(i[t]=[e])}}if(t.records){const e=this.recognizeRecords=t.records;for(let t in i)e[t]||delete i[t];for(let e in i)s[e]||(i[e]=[])}else this.recognizeRecords={},this.drawRegionsultRecords={};return this._lastErrorCode=t.exception,this._lastErrorString=t.description,t.exception&&!this._setWarnnedEx.has(t.description)&&(this._setWarnnedEx.add(t.description),t.exception==e.EnumDLRErrorCode.LICENSE_INVALID||t.exception==e.EnumDLRErrorCode.LICENSE_EXPIRED?console.error(t.description):console.warn(t.description)),t.results}if(t.exception==i.OK)return t.data;throw l.LabelRecognizerException(t.exception,t.description)}setModeArgument(e,i,s,n){return t(this,void 0,void 0,(function*(){return yield new Promise(((t,r)=>{let o=l._nextTaskID++;l._taskCallbackMap.set(o,(e=>{if(e.success){try{this._handleRetJsonString(e.setReturn)}catch(e){return r(e)}return t()}{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,r(t)}})),l._dlrWorker.postMessage({type:"setModeArgument",id:o,instanceID:this._instanceID,body:{modeName:e,index:i,argumentName:s,argumentValue:n}})}))}))}getModeArgument(e,i,s){return t(this,void 0,void 0,(function*(){return yield new Promise(((t,n)=>{let r=l._nextTaskID++;l._taskCallbackMap.set(r,(e=>{if(e.success){let i;try{i=this._handleRetJsonString(e.getReturn)}catch(e){return n(e)}return t(i)}{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,n(t)}})),l._dlrWorker.postMessage({type:"getModeArgument",id:r,instanceID:this._instanceID,body:{modeName:e,index:i,argumentName:s}})}))}))}recognizeCurrentFrame(){return t(this,void 0,void 0,(function*(){this._assertOpen();let t=this.dce.getFrame();if(t&&null===t.canvas){let{data:i,width:s,height:n}=t;return yield this._recognizeBuffer_Uint8Array(i,s,n,s,e.EnumDLRImagePixelFormat.IPF_GRAYSCALED)}if(t&&t.canvas){let{data:i,canvas:s}=t;return(this.bSaveOriCanvas||this.singleFrameMode)&&(this.oriCanvas=s),yield this._recognizeBuffer_Uint8Array(i,s.width,s.height,4*s.width,e.EnumDLRImagePixelFormat.IPF_ABGR_8888)}}))}clearMapDecodeRecord(){return t(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=l._nextTaskID++;l._taskCallbackMap.set(i,(i=>{if(i.success)return e();{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),l._dlrWorker.postMessage({type:"clearMapDecodeRecord",id:i,instanceID:this._instanceID})}))}))}_bindUI(){const e=this.dce.getUIElement();if(!e)throw new Error("Need to define `UIElement` before opening.");this.dce._bindUI();let t=[e],i=e.children;for(let e of i)t.push(e);for(let e=0;e<t.length;++e)for(let i of t[e].children)t.push(i);for(let e of t)!this._cvsDrawArea&&e.classList.contains("dlr-cvs-drawarea")?this._cvsDrawArea=e:!this._divScanArea&&e.classList.contains("dlr-cvs-scanarea")?this._divScanArea=e:!this._divScanLight&&e.classList.contains("dlr-scanlight")?this._divScanLight=e:!this._selCam&&e.classList.contains("dce-sel-camera")?this._selCam=e:!this._selRsl&&e.classList.contains("dce-sel-resolution")?this._selRsl=e:!this._selMinLtr&&e.classList.contains("dlr-sel-minletter")?(this._selMinLtr=e,this._selMinLtr.options.length||(this._selMinLtr.innerHTML=[this._optGotMinLtr?"":'<option class="dlr-opt-gotMinLtr" value="got"></option>','<option value="0" selected>any letter</option>','<option value="3">3+ letters</option>','<option value="5">5+ letters</option>','<option value="8">8+ letters</option>','<option value="12">12+ letters</option>','<option value="18">18+ letters</option>','<option value="30">30+ letters</option>','<option value="50">50+ letters</option>','<option value="80">80+ letters</option>','<option value="120">120+ letters</option>'].join(""),this._optGotMinLtr=this._optGotMinLtr||this._selMinLtr.options[0])):this._optGotMinLtr||!e.classList.contains("dlr-opt-gotMinLtr")&&!e.classList.contains("dlr-opt-gotMinLtr")?!this._btnClose&&e.classList.contains("dce-btn-close")&&(this._btnClose=e):this._optGotMinLtr=e;if(this.singleFrameMode&&(this._cvsDrawArea&&(this._cvsDrawArea.addEventListener("click",this._clickIptSingleFrameMode),this._cvsDrawArea.style.cursor="pointer",this._cvsDrawArea.setAttribute("title","Take a photo")),this._divScanArea&&(this._divScanArea.addEventListener("click",this._clickIptSingleFrameMode),this._divScanArea.style.cursor="pointer",this._divScanArea.setAttribute("title","Take a photo"))),this._selCam&&this._selCam.addEventListener("change",this._onCameraSelChange),this._selRsl&&this._selRsl.addEventListener("change",this._onResolutionSelChange),this._selMinLtr&&this._selMinLtr.addEventListener("change",this._onMinLetterSelChange),this._btnClose&&this._btnClose.addEventListener("click",this._onCloseBtnClick),!this.dce.video)throw this._unbindUI(),Error("Can not find HTMLVideoElement with class `dce-video`.");this._updateMinLtrSel(this._minLetter)}_unbindUI(){this._clearRegionsults(),this.singleFrameMode&&(this._cvsDrawArea&&(this._cvsDrawArea.removeEventListener("click",this._clickIptSingleFrameMode),this._cvsDrawArea.style.cursor="",this._cvsDrawArea.removeAttribute("title")),this._divScanArea&&(this._divScanArea.removeEventListener("click",this._clickIptSingleFrameMode),this._divScanArea.style.cursor="",this._divScanArea.removeAttribute("title"))),this._selCam&&this._selCam.removeEventListener("change",this._onCameraSelChange),this._selRsl&&this._selRsl.removeEventListener("change",this._onResolutionSelChange),this._selMinLtr&&this._selMinLtr.removeEventListener("change",this._onMinLetterSelChange),this._btnClose&&this._btnClose.removeEventListener("click",this._onCloseBtnClick),this.dce._unbindUI(),this._cvsDrawArea=null,this._divScanArea=null,this._divScanLight=null,this._selCam=null,this._selRsl=null,this._selMinLtr=null,this._optGotMinLtr=null,this._btnClose=null}getScanSettings(){return t(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=l._nextTaskID++;l._taskCallbackMap.set(i,(i=>{if(i.success){let t=i.results;return t.intervalTime=this.intervalTime,e(t)}{let e=new Error(i.message);return e.stack+="\n"+i.stack,t(e)}})),l._dlrWorker.postMessage({type:"getScanSettings",id:i,instanceID:this._instanceID})}))}))}updateScanSettings(e){return t(this,void 0,void 0,(function*(){return this.intervalTime=e.intervalTime,yield new Promise(((t,i)=>{let s=l._nextTaskID++;l._taskCallbackMap.set(s,(e=>{if(e.success)return t();{let t=new Error(e.message);return t.stack+="\n"+e.stack,i(t)}})),l._dlrWorker.postMessage({type:"updateScanSettings",id:s,instanceID:this._instanceID,body:{settings:e}})}))}))}_show(){const e=this.dce.getUIElement();e.parentNode||(e.style.position="fixed",e.style.left="0",e.style.top="0",document.body.append(e)),"none"==e.style.display&&(e.style.display="")}stop(){this.dce&&this.dce.stop(),this._divScanLight&&(this._divScanLight.style.display="none"),this._drawRegionsults(),this.array_decodeFrameTimeCost.length=0,this.array_getFrameTimeCost.length=0,this._intervalGetVideoFrame=0}_cloneDecodeResults(e){if(e instanceof Array){let t=[];for(let i of e)t.push(this._cloneDecodeResults(i));return t}{let t=e;return JSON.parse(JSON.stringify(t,((e,t)=>"oriVideoCanvas"==e||"searchRegionCanvas"==e?void 0:t)))}}_loopReadVideo(){return t(this,void 0,void 0,(function*(){if(this.bDestroyed)return void(this.dce&&this.dce.stopFetchingLoop());if(!this.dce||!this.dce.isOpen())return this.dce&&this.dce.stopFetchingLoop(),void(yield this.clearMapDecodeRecord());if(!this.dce.video||this.dce.video.paused||this._bPauseScan)return l._onLog&&l._onLog("Video or scan is paused. Ask in 1s."),this.dce&&this.dce.stopFetchingLoop(),yield this.clearMapDecodeRecord(),this._loopReadVideoTimeoutId&&clearTimeout(this._loopReadVideoTimeoutId),void(this._loopReadVideoTimeoutId=setTimeout((()=>{this._loopReadVideo()}),this._intervalDetectVideoPause));this._divScanLight&&"none"==this._divScanLight.style.display&&(this._divScanLight.style.display=""),l._onLog&&l._onLog("======= once read ======="),l._onLog&&(this._timeStartRecognize=Date.now());let i=this._getVideoFrame();if(!i)return this._loopReadVideoTimeoutId&&clearTimeout(this._loopReadVideoTimeoutId),void(this._loopReadVideoTimeoutId=setTimeout((()=>{this._loopReadVideo()}),0));(()=>t(this,void 0,void 0,(function*(){if(i&&null===i.canvas){let{data:t,width:s,height:n,timeStamp:r}=i,o={timeStamp:r,bScanner:!0};return yield this._recognizeBuffer_Uint8Array(t,s,n,s,e.EnumDLRImagePixelFormat.IPF_GRAYSCALED,o)}if(i&&i.canvas){let{data:t,canvas:s,region:n,sx:r,sy:o,width:a,height:l,timeStamp:c}=i,d={timeStamp:c,bScanner:!0};return(this.bSaveOriCanvas||this.singleFrameMode)&&(this.oriCanvas=s),yield this._recognizeBuffer_Uint8Array(t,s.width,s.height,4*s.width,e.EnumDLRImagePixelFormat.IPF_ABGR_8888,d)}{let e=new Error("imgData is empty.");return new Promise((t=>t(e)))}})))().then((e=>{l._onLog&&l._onLog(e);let t=this.array_decodeFrameTimeCost,i=this.array_getFrameTimeCost;if((()=>{for(;t.length>=5;)t.shift();t.push(this._lastInnerDecodeDuration)})(),this._intervalGetVideoFrame=(()=>{let e=0;if(i&&i.length){let s=Math.min(...t),n=Math.max(...i);s&&n&&(e=s-n)}else e=0;return e>0?e:0})(),this.dce&&this.dce.isOpen()&&this.dce.video&&!this.dce.video.paused&&!this._bPauseScan){if(this.bPlaySoundOnSuccessfulRead&&e.length){let t=!1;if(!0===this.bPlaySoundOnSuccessfulRead||"frame"===this.bPlaySoundOnSuccessfulRead)t=!0;else if("unique"===this.bPlaySoundOnSuccessfulRead)for(let i of e)for(let e of i.lineResults)if(e.bUnduplicated){t=!0;break}t&&(this.soundOnSuccessfullRead.currentTime=0,this.soundOnSuccessfullRead.play().catch((e=>{console.warn("Autoplay not allowed. User interaction required.")})))}if(navigator.vibrate&&this.bVibrateOnSuccessfulRead&&e.length){let t=!1;if(!0===this.bVibrateOnSuccessfulRead||"frame"===this.bVibrateOnSuccessfulRead)t=!0;else if("unique"===this.bVibrateOnSuccessfulRead)for(let i of e)for(let e of i.lineResults)if(e.bUnduplicated){t=!0;break}if(t)try{navigator.vibrate(this.vibrateDuration)}catch(e){console.warn("Vibration not allowed. User interaction required: "+(e.message||e))}}if(this.onFrameRead){let t=this._cloneDecodeResults(e);for(let e of t)for(let t of e.lineResults)t.bUnduplicated&&delete e.bUnduplicated;this.onFrameRead(t)}if(this.onUniqueRead)for(let t of e){if(["passportMRZ","visaMRZ","MRZ"].includes(this.currentSettingsTemplate)){let e="";for(let i of t.lineResults)i.bUnduplicated&&(e.length>0&&(e+="\n"),e+=i.text);e.length>0&&this.onUniqueRead(e,this._cloneDecodeResults(t.lineResults))}else for(let e of t.lineResults)e.bUnduplicated&&this.onUniqueRead(e.text,[this._cloneDecodeResults(e)])}{const e=[];for(let t in this.drawRegionsultRecords)e.push(...this.drawRegionsultRecords[t]);this._drawRegionsults([{lineResults:e}])}}this._loopReadVideoTimeoutId&&clearTimeout(this._loopReadVideoTimeoutId),this.intervalTime?this._loopReadVideoTimeoutId=setTimeout((()=>{this._loopReadVideo()}),this.intervalTime):this._loopReadVideo()})).catch((e=>{this.dce.stopFetchingLoop(),l._onLog&&l._onLog(e.message||e),this._loopReadVideoTimeoutId&&clearTimeout(this._loopReadVideoTimeoutId),this._loopReadVideoTimeoutId=setTimeout((()=>{this._loopReadVideo()}),Math.max(this.intervalTime,1e3)),"platform error"==e.message||console.warn(e.message)}))}))}_getVideoFrame(){let e=this.dce.isFetchingLoopStarted();if(this.dce.loopInterval=this._intervalGetVideoFrame,e||this.dce.startFetchingLoop(),!this.dce.getQueueLength())return this.dce.loopInterval=0,null;let t=this.dce.getFrameFromBuffer();return(e=>{let t=e.timeSpent,i=this.array_getFrameTimeCost;for(;i.length>=5;)i.shift();i.push(t)})(t),t}_checkValidVIN(e){if(!e||17!=e.length)return!1;const t=(e=>{const t=new Map([["A",1],["B",2],["C",3],["D",4],["E",5],["F",6],["G",7],["H",8],["J",1],["K",2],["L",3],["M",4],["N",5],["P",7],["R",9],["S",2],["T",3],["U",4],["V",5],["W",6],["X",7],["Y",8],["Z",9],["1",1],["2",2],["3",3],["4",4],["5",5],["6",6],["7",7],["8",8],["9",9]]),i=[8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2];let s=0;for(let n=0;n<e.length;n++){let r=t.get(e[n]);r&&(s+=r*i[n])}return s%11})(e);return t.toString()===e[8]}_checkValidMRP(e){if(!e||44!=e.length)return!1;const t=(e,t,i)=>{const s=new Map([["<",0],["0",0],["1",1],["2",2],["3",3],["4",4],["5",5],["6",6],["7",7],["8",8],["9",9],["A",10],["B",11],["C",12],["D",13],["E",14],["F",15],["G",16],["H",17],["I",18],["J",19],["K",20],["L",21],["M",22],["N",23],["O",24],["P",25],["Q",26],["R",27],["S",28],["T",29],["U",30],["V",31],["W",32],["X",33],["Y",34],["Z",35]]),n=[7,3,1];let r=0;for(let o=t,a=0;o<=i;o++){let t=s.get(e[o]);t&&(r+=t*n[a%3]),a++}return r%10},i=e.slice(0,10)+e.slice(13,20)+e.slice(21,43),s=t(e,0,8).toString(),n=t(e,13,18).toString(),r=t(e,21,26).toString(),o=t(e,28,41).toString(),a=t(i,0,i.length).toString();return s===e[9]&&n===e[19]&&r===e[27]&&o===e[42]&&a===e[43]}_checkValidMRV(e){if(!e||44!=e.length&&36!=e.length)return!1;const t=(e,t,i)=>{const s=new Map([["<",0],["0",0],["1",1],["2",2],["3",3],["4",4],["5",5],["6",6],["7",7],["8",8],["9",9],["A",10],["B",11],["C",12],["D",13],["E",14],["F",15],["G",16],["H",17],["I",18],["J",19],["K",20],["L",21],["M",22],["N",23],["O",24],["P",25],["Q",26],["R",27],["S",28],["T",29],["U",30],["V",31],["W",32],["X",33],["Y",34],["Z",35]]),n=[7,3,1];let r=0;for(let o=t,a=0;o<=i;o++){let t=s.get(e[o]);t&&(r+=t*n[a%3]),a++}return r%10},i=t(e,0,8).toString(),s=t(e,13,18).toString(),n=t(e,21,26).toString();return i===e[9]&&s===e[19]&&n===e[27]}_drawRegionsults(e){let t,i,s;if(this.beingLazyDrawRegionsults=!1,this.singleFrameMode){if(!this.oriCanvas)return;t="contain",i=this.oriCanvas.width,s=this.oriCanvas.height}else{if(!this.dce.video)return;t=this.dce.video.style.objectFit||"contain",i=this.dce.video.videoWidth,s=this.dce.video.videoHeight}let r,o,a,l,c,d,h,u,g=this.region;if(g)if(n.LST_MANUAL_SPECIFICATION!=g.localizationSourceType)g=null;else if(g.regionMeasuredByPercentage){let e=g.location.points;if(0==e[0].x&&0==e[0].y&&100==e[1].x&&0==e[1].y&&100==e[2].x&&100==e[2].y&&0==e[3].x&&100==e[3].y)g=null;else{g={location:{points:[]}};for(let t=0;t<4;++t)g.location.points.push({x:Math.round(e[t].x/100*i),y:Math.round(e[t].y/100*s)})}}else g=JSON.parse(JSON.stringify(g)),delete g.regionMeasuredByPercentage;if(g){let e=g.location.points;r=e[0].x,c=e[0].y,o=e[1].x,d=e[1].y,a=e[2].x,h=e[2].y,l=e[3].x,u=e[3].y}if(this._cvsDrawArea){this._cvsDrawArea.style.objectFit=t;let n=this._cvsDrawArea;n.width=i,n.height=s;let _=n.getContext("2d");if(g){_.fillStyle=this.regionMaskFillStyle,_.fillRect(0,0,n.width,n.height);let e=Math.round(this.regionMaskLineWidth/2),t=(t,i,s,n,r,o)=>(-(s-t)*e/Math.hypot(s-t,n-i)-(r-t)*e/Math.hypot(r-t,o-i))/2+t,i=(t,i,s,n,r,o)=>(-(n-i)*e/Math.hypot(s-t,n-i)-(o-i)*e/Math.hypot(r-t,o-i))/2+i;_.globalCompositeOperation="destination-out",_.fillStyle="#000",_.beginPath(),_.moveTo(t(r,c,o,d,l,u),i(r,c,o,d,l,u)),_.lineTo(t(o,d,r,c,a,h),i(o,d,r,c,a,h)),_.lineTo(t(a,h,o,d,l,u),i(a,h,o,d,l,u)),_.lineTo(t(l,u,a,h,r,c),i(l,u,a,h,r,c)),_.fill(),_.globalCompositeOperation="source-over",_.strokeStyle=this.regionMaskStrokeStyle,_.lineWidth=this.regionMaskLineWidth,_.beginPath(),_.moveTo(r,c),_.lineTo(o,d),_.lineTo(a,h),_.lineTo(l,u),_.closePath(),_.stroke()}if(e){_.globalCompositeOperation="destination-over",_.fillStyle=this.highlightFillStyle,_.strokeStyle=this.highlightStrokeStyle,_.lineWidth=this.highlightLineWidth,e=e||[];for(let t of e)for(let e of t.lineResults){let t=e.location.points;_.beginPath(),_.moveTo(t[0].x,t[0].y),_.lineTo(t[1].x,t[1].y),_.lineTo(t[2].x,t[2].y),_.lineTo(t[3].x,t[3].y),_.fill(),_.beginPath(),_.moveTo(t[0].x,t[0].y),_.lineTo(t[1].x,t[1].y),_.lineTo(t[2].x,t[2].y),_.lineTo(t[3].x,t[3].y),_.closePath(),_.stroke()}}this.singleFrameMode&&(_.globalCompositeOperation="destination-over",_.drawImage(this.oriCanvas,0,0))}if(this._divScanArea&&this.dce.video){let e=this.dce.video.offsetWidth,t=this.dce.video.offsetHeight,n=1;e/t<i/s?(n=e/i,this._divScanArea.style.left="0",this._divScanArea.style.top=Math.round((t-s*n)/2)+"px"):(n=t/s,this._divScanArea.style.left=Math.round((e-i*n)/2)+"px",this._divScanArea.style.top="0");let _=g?Math.round(Math.min(r,o,a,l)*n):0,f=g?Math.round(Math.min(c,d,h,u)*n):0,m=g?Math.round(Math.max(r,o,a,l)*n-_):Math.round(i*n),p=g?Math.round(Math.max(c,d,h,u)*n-f):Math.round(s*n);this._divScanArea.style.marginLeft=_+"px",this._divScanArea.style.marginTop=f+"px",this._divScanArea.style.width=m+"px",this._divScanArea.style.height=p+"px"}}_clearRegionsults(){this._cvsDrawArea&&(this._cvsDrawArea.width=this._cvsDrawArea.height=0)}startScanning(e){return t(this,void 0,void 0,(function*(){if("closed"!=this._tempSolutionStatus)return;if(this._tempSolutionStatus="opening",!this.dce)throw new Error("Need to set 'cameraEnhancer' first.");if("opening"!=this._tempSolutionStatus)return;this._bindUI(),e&&this._show();let t=yield this.dce.play();return"opening"==this._tempSolutionStatus?(this._bPauseScan=!1,this.singleFrameMode||(this._loopReadVideo(),this._drawRegionsults()),this._tempSolutionStatus="opened",t):void 0}))}stopScanning(e){this.stop(),this._unbindUI(),this.dce&&this.dce.stopFetchingLoop(),this._bPauseScan=!0,e&&this.dce&&(this.dce.getUIElement().style.display="none"),this._tempSolutionStatus="closed"}pauseScanning(){this.dce&&this.dce.stopFetchingLoop(),this._bPauseScan=!0,this._clearRegionsults(),this._divScanLight&&(this._divScanLight.style.display="none")}resumeScanning(){this._assertOpen(),this._bPauseScan=!1}destroyContext(){if(!this.bDestroyed)return l._onLog&&l._onLog("destroy()"),this.bDestroyed=!0,(this.dce||"opening"===this._tempSolutionStatus)&&this.stopScanning(),new Promise(((e,t)=>{let i=l._nextTaskID++;l._taskCallbackMap.set(i,(i=>{if(i.success)return e();{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),l._dlrWorker.postMessage({type:"destroy",id:i,instanceID:this._instanceID})}))}}var c,d;l._jsVersion="2.2.1",l._jsEditVersion="20220216",l._version="loading...(JS "+l._jsVersion+"."+l._jsEditVersion+")",l._license=r||o||!document.currentScript?"":document.currentScript.getAttribute("data-license")||"",l._sessionPassword=r||o||!document.currentScript?"":document.currentScript.getAttribute("data-sessionPassword")||"",l.browserInfo=function(){if(!r&&!o){var e={init:function(){this.browser=this.searchString(this.dataBrowser)||"unknownBrowser",this.version=this.searchVersion(navigator.userAgent)||this.searchVersion(navigator.appVersion)||"unknownVersion",this.OS=this.searchString(this.dataOS)||"unknownOS","Linux"==this.OS&&-1!=navigator.userAgent.indexOf("Windows NT")&&(this.OS="HarmonyOS")},searchString:function(e){for(var t=0;t<e.length;t++){var i=e[t].string,s=e[t].prop;if(this.versionSearchString=e[t].versionSearch||e[t].identity,i){if(-1!=i.indexOf(e[t].subString))return e[t].identity}else if(s)return e[t].identity}},searchVersion:function(e){var t=e.indexOf(this.versionSearchString);if(-1!=t)return parseFloat(e.substring(t+this.versionSearchString.length+1))},dataBrowser:[{string:navigator.userAgent,subString:"Edge",identity:"Edge"},{string:navigator.userAgent,subString:"OPR",identity:"OPR"},{string:navigator.userAgent,subString:"Chrome",identity:"Chrome"},{string:navigator.vendor,subString:"Apple",identity:"Safari",versionSearch:"Version"},{string:navigator.userAgent,subString:"Firefox",identity:"Firefox"},{string:navigator.userAgent,subString:"MSIE",identity:"Explorer",versionSearch:"MSIE"}],dataOS:[{string:navigator.userAgent,subString:"HarmonyOS",identity:"HarmonyOS"},{string:navigator.userAgent,subString:"Android",identity:"Android"},{string:navigator.userAgent,subString:"iPhone",identity:"iPhone"},{string:navigator.platform,subString:"Win",identity:"Windows"},{string:navigator.platform,subString:"Mac",identity:"Mac"},{string:navigator.platform,subString:"Linux",identity:"Linux"}]};return e.init(),{browser:e.browser,version:e.version,OS:e.OS}}if(o)return{browser:"ssr",version:0,OS:"ssr"};if(r){const e={browser:"node",version:process.version.substring(1),OS:"loading"};return(()=>{t(this,void 0,void 0,(function*(){const t=yield import("os");e.OS=t&&t.platform?t.platform()+t.release():"Unknown"}))})(),e}}(),l._workerName="dlr-"+l._jsVersion+".worker.js",l._engineResourcePath=(()=>{if(r)return __dirname+"/";if(!o&&document.currentScript){let e=document.currentScript.src,t=e.indexOf("?");if(-1!=t)e=e.substring(0,t);else{let t=e.indexOf("#");-1!=t&&(e=e.substring(0,t))}return e.substring(0,e.lastIndexOf("/")+1)}return"./"})(),l._licenseServer=[],l._deviceFriendlyName="",l._isShowRelRecognizeTimeInResults=!1,l._bWasmDebug=!1,l._bNeverShowDialog=!1,l._nextTaskID=0,l._taskCallbackMap=new Map,l._loadWasmStatus="unload",l._loadWasmCallbackArr=[],l.onResourcesLoaded=null,l.onResourcesLoadStarted=null,l._lastErrorCode=0,l._lastErrorString="",l._defaultUIElementURL="@engineResourcePath/dlr.ui.html",l._loadWasmErr=null,e.EnumDLRGrayscaleTransformationMode=void 0,(c=e.EnumDLRGrayscaleTransformationMode||(e.EnumDLRGrayscaleTransformationMode={}))[c.GTM_INVERTED=1]="GTM_INVERTED",c[c.GTM_ORIGINAL=2]="GTM_ORIGINAL",c[c.GTM_AUTO=4]="GTM_AUTO",c[c.GTM_REV=2147483648]="GTM_REV",c[c.GTM_SKIP=0]="GTM_SKIP",e.EnumDLRRegionPredetectionMode=void 0,(d=e.EnumDLRRegionPredetectionMode||(e.EnumDLRRegionPredetectionMode={}))[d.RPM_AUTO=1]="RPM_AUTO",d[d.RPM_GENERAL=2]="RPM_GENERAL",d[d.RPM_GENERAL_RGB_CONTRAST=4]="RPM_GENERAL_RGB_CONTRAST",d[d.RPM_GENERAL_GRAY_CONTRAST=8]="RPM_GENERAL_GRAY_CONTRAST",d[d.RPM_GENERAL_HSV_CONTRAST=16]="RPM_GENERAL_HSV_CONTRAST",d[d.RPM_REV=2147483648]="RPM_REV",d[d.RPM_SKIP=0]="RPM_SKIP",e.LabelRecognizer=l,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).Dynamsoft=e.Dynamsoft||{},e.Dynamsoft.DLR={}))}(this,(function(e){"use strict";function t(e,t,i,s){return new(i||(i=Promise))((function(r,n){function o(e){try{l(s.next(e))}catch(e){n(e)}}function a(e){try{l(s.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}l((s=s.apply(e,t||[])).next())}))}var i,s,r;e.EnumDLRImagePixelFormat=void 0,(i=e.EnumDLRImagePixelFormat||(e.EnumDLRImagePixelFormat={}))[i.IPF_BINARY=0]="IPF_BINARY",i[i.IPF_BINARYINVERTED=1]="IPF_BINARYINVERTED",i[i.IPF_GRAYSCALED=2]="IPF_GRAYSCALED",i[i.IPF_NV21=3]="IPF_NV21",i[i.IPF_RGB_565=4]="IPF_RGB_565",i[i.IPF_RGB_555=5]="IPF_RGB_555",i[i.IPF_RGB_888=6]="IPF_RGB_888",i[i.IPF_ARGB_8888=7]="IPF_ARGB_8888",i[i.IPF_RGB_161616=8]="IPF_RGB_161616",i[i.IPF_ARGB_16161616=9]="IPF_ARGB_16161616",i[i.IPF_ABGR_8888=10]="IPF_ABGR_8888",i[i.IPF_ABGR_16161616=11]="IPF_ABGR_16161616",i[i.IPF_BGR_888=12]="IPF_BGR_888",e.EnumDLRErrorCode=void 0,(s=e.EnumDLRErrorCode||(e.EnumDLRErrorCode={}))[s.OK=0]="OK",s[s.UNKNOWN=-1e4]="UNKNOWN",s[s.NO_MEMORY=-10001]="NO_MEMORY",s[s.NULL_POINTER=-10002]="NULL_POINTER",s[s.LICENSE_INVALID=-10003]="LICENSE_INVALID",s[s.LICENSE_EXPIRED=-10004]="LICENSE_EXPIRED",s[s.FILE_NOT_FOUND=-10005]="FILE_NOT_FOUND",s[s.FILETYPE_NOT_SUPPORTED=-10006]="FILETYPE_NOT_SUPPORTED",s[s.BPP_NOT_SUPPORTED=-10007]="BPP_NOT_SUPPORTED",s[s.IMAGE_READ_FAILED=-10012]="IMAGE_READ_FAILED",s[s.TIFF_READ_FAILED=-10013]="TIFF_READ_FAILED",s[s.PDF_READ_FAILED=-10021]="PDF_READ_FAILED",s[s.PDF_DLL_MISSING=-10022]="PDF_DLL_MISSING",s[s.RECOGNITION_TIMEOUT=-10026]="RECOGNITION_TIMEOUT",s[s.JSON_PARSE_FAILED=-10030]="JSON_PARSE_FAILED",s[s.JSON_TYPE_INVALID=-10031]="JSON_TYPE_INVALID",s[s.JSON_KEY_INVALID=-10032]="JSON_KEY_INVALID",s[s.JSON_VALUE_INVALID=-10033]="JSON_VALUE_INVALID",s[s.JSON_NAME_KEY_MISSING=-10034]="JSON_NAME_KEY_MISSING",s[s.JSON_NAME_VALUE_DUPLICATED=-10035]="JSON_NAME_VALUE_DUPLICATED",s[s.TEMPLATE_NAME_INVALID=-10036]="TEMPLATE_NAME_INVALID",s[s.PARAMETER_VALUE_INVALID=-10038]="PARAMETER_VALUE_INVALID",s[s.SET_MODE_ARGUMENT_ERROR=-10051]="SET_MODE_ARGUMENT_ERROR",s[s.GET_MODE_ARGUMENT_ERROR=-10055]="GET_MODE_ARGUMENT_ERROR",s[s.CHARACTER_MODEL_FILE_NOT_FOUND=-10100]="CHARACTER_MODEL_FILE_NOT_FOUND",function(e){e[e.LST_MANUAL_SPECIFICATION=1]="LST_MANUAL_SPECIFICATION",e[e.LST_PREDETECTED_REGION=2]="LST_PREDETECTED_REGION",e[e.LST_BARCODE=4]="LST_BARCODE"}(r||(r={}));const n=!!("object"==typeof global&&global.process&&global.process.release&&global.process.release.name&&"undefined"==typeof HTMLCanvasElement),o=!n&&"undefined"==typeof self,a=n?global:o?{}:self;class l{constructor(){this._canvasMaxWH="iPhone"==l.browserInfo.OS||"Android"==l.browserInfo.OS?2048:4096,this._instanceID=void 0,this.bSaveOriCanvas=!1,this.oriCanvas=null,this._region=null,this._timeStartRecognize=null,this._timeEnterInnerDLR=null,this.recognizeRecords={},this.drawRegionsultRecords={},this.bDestroyed=!1,this._setWarnnedEx=new Set,this._lastErrorCode=0,this._lastErrorString="",this._lastInnerDecodeDuration=0,this._clickIptSingleFrameMode=()=>{},this.intervalTime=0,this._intervalGetVideoFrame=0,this.array_getFrameTimeCost=[],this.array_decodeFrameTimeCost=[],this._bPauseScan=!1,this._intervalDetectVideoPause=1e3,this._cvsDrawArea=null,this._divScanArea=null,this._divScanLight=null,this._selCam=null,this._selRsl=null,this._selMinLtr=null,this._optGotMinLtr=null,this._btnClose=null,this._minLetter=0,this._soundOnSuccessfullRead=!n&&new Audio("data:audio/mpeg;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjI5LjEwMAAAAAAAAAAAAAAA/+M4wAAAAAAAAAAAAEluZm8AAAAPAAAABQAAAkAAgICAgICAgICAgICAgICAgICAgKCgoKCgoKCgoKCgoKCgoKCgoKCgwMDAwMDAwMDAwMDAwMDAwMDAwMDg4ODg4ODg4ODg4ODg4ODg4ODg4P//////////////////////////AAAAAExhdmM1OC41NAAAAAAAAAAAAAAAACQEUQAAAAAAAAJAk0uXRQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/+MYxAANQAbGeUEQAAHZYZ3fASqD4P5TKBgocg+Bw/8+CAYBA4XB9/4EBAEP4nB9+UOf/6gfUCAIKyjgQ/Kf//wfswAAAwQA/+MYxAYOqrbdkZGQAMA7DJLCsQxNOij///////////+tv///3RWiZGBEhsf/FO/+LoCSFs1dFVS/g8f/4Mhv0nhqAieHleLy/+MYxAYOOrbMAY2gABf/////////////////usPJ66R0wI4boY9/8jQYg//g2SPx1M0N3Z0kVJLIs///Uw4aMyvHJJYmPBYG/+MYxAgPMALBucAQAoGgaBoFQVBUFQWDv6gZBUFQVBUGgaBr5YSgqCoKhIGg7+IQVBUFQVBoGga//SsFSoKnf/iVTEFNRTMu/+MYxAYAAANIAAAAADEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"),this.bPlaySoundOnSuccessfulRead=!1,this.bVibrateOnSuccessfulRead=!1,this.vibrateDuration=300,this.regionMaskFillStyle="rgba(0,0,0,0.5)",this.regionMaskStrokeStyle="rgb(254,142,20)",this.regionMaskLineWidth=2,this.highlightFillStyle="rgba(254,180,32,0.3)",this.highlightStrokeStyle="rgba(254,180,32,0.9)",this.highlightLineWidth=1,this.beingLazyDrawRegionsults=!1,this.currentSettingsTemplate="cppdefault",this.dce=null,this._onCameraSelChange=()=>{this._divScanLight&&(this._divScanLight.style.display="none"),this._drawRegionsults(),this.array_decodeFrameTimeCost.length=0,this.array_getFrameTimeCost.length=0,this._intervalGetVideoFrame=0},this._onResolutionSelChange=()=>{this._divScanLight&&(this._divScanLight.style.display="none"),this._drawRegionsults(),this.array_decodeFrameTimeCost.length=0,this.array_getFrameTimeCost.length=0,this._intervalGetVideoFrame=0},this._onMinLetterSelChange=e=>t(this,void 0,void 0,(function*(){let t=e.target.value;if("got"===t)return;t=JSON.parse(t);let i=JSON.parse(yield this.outputRuntimeSettingsToString());i.LabelRecognizerParameterArray[0].LineStringLengthRange=[t,999],i.TextAreaArray[0].LineStringLengthRange=[t,999],yield this.updateRuntimeSettingsFromString(i)})),this._onCloseBtnClick=()=>{this.stopScanning(!0)},this._tempSolutionStatus="closed"}static getVersion(){return this._version}static get license(){return this._license}static set license(e){if("unload"!=this._loadWasmStatus)throw new Error("`license` is not allowed to change after `createInstance` or `loadWasm` is called.");l._license=e}static initLicense(e){if("unload"!=this._loadWasmStatus)throw new Error("`license` is not allowed to change after `createInstance` or `loadWasm` is called.");l._license=e}static set sessionPassword(e){if("unload"!=this._loadWasmStatus)throw new Error("`sessionPassword` is not allowed to change after `createInstance` or `loadWasm` is called.");l._sessionPassword=e}static get sessionPassword(){return this._sessionPassword}static detectEnvironment(){return t(this,void 0,void 0,(function*(){let e={wasm:"undefined"!=typeof WebAssembly&&("undefined"==typeof navigator||!(/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)&&/\(.+\s11_2_([2-6]).*\)/.test(navigator.userAgent))),worker:!!(n?process.version>="v12":"undefined"!=typeof Worker),getUserMedia:!("undefined"==typeof navigator||!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia),camera:!1,browser:this.browserInfo.browser,version:this.browserInfo.version,OS:this.browserInfo.OS};if(e.getUserMedia)try{(yield navigator.mediaDevices.getUserMedia({video:!0})).getTracks().forEach((e=>{e.stop()})),e.camera=!0}catch(e){}return e}))}static get engineResourcePath(){return this._engineResourcePath}static set engineResourcePath(e){if("unload"!=this._loadWasmStatus)throw new Error("`engineResourcePath` is not allowed to change after `createInstance` or `loadWasm` is called.");if(null==e&&(e="./"),n||o)l._engineResourcePath=e;else{let t=document.createElement("a");t.href=e,l._engineResourcePath=t.href}this._engineResourcePath.endsWith("/")||(l._engineResourcePath+="/")}static get licenseServer(){return this._licenseServer}static set licenseServer(e){if("unload"!=this._loadWasmStatus)throw new Error("`licenseServer` is not allowed to change after `createInstance` or `loadWasm` is called.");if(null==e)l._licenseServer=[];else{e instanceof Array||(e=[e]);for(let t=0;t<e.length;++t){if(!n&&!o){let i=document.createElement("a");i.href=e[t],e[t]=i.href}e[t].endsWith("/")||(e[t]+="/")}l._licenseServer=e}}static get deviceFriendlyName(){return this._deviceFriendlyName}static set deviceFriendlyName(e){if("unload"!=this._loadWasmStatus)throw new Error("`deviceFriendlyName` is not allowed to change after loadWasm is called.");l._deviceFriendlyName=e||""}get ifSaveOriginalImageInACanvas(){return this.bSaveOriCanvas}set ifSaveOriginalImageInACanvas(e){this.dce&&(this.dce.ifSaveOriginalImageInACanvas=e),this.bSaveOriCanvas=e}getOriginalImageInACanvas(){return this.oriCanvas}set region(e){this._region=e,this.dce&&!this.singleFrameMode&&(this.beingLazyDrawRegionsults=!0,setTimeout((()=>{this.beingLazyDrawRegionsults&&this._drawRegionsults()}),500))}get region(){return this._region}static isWasmLoaded(){return"loadSuccess"==this._loadWasmStatus}isContextDestroyed(){return this.bDestroyed}static get lastErrorCode(){return this._lastErrorCode}static get lastErrorString(){return this._lastErrorString}get lastErrorCode(){return this._lastErrorCode}get lastErrorString(){return this._lastErrorString}static get defaultUIElementURL(){var e;return null===(e=this._defaultUIElementURL)||void 0===e?void 0:e.replace("@engineResourcePath/",l.engineResourcePath)}static set defaultUIElementURL(e){this._defaultUIElementURL=e}get singleFrameMode(){if(!this.dce)throw new Error("Need to set 'cameraEnhancer' first.");return this.dce.singleFrameMode}set singleFrameMode(e){if(!this.dce)throw new Error("Need to set 'cameraEnhancer' first.");this.dce.singleFrameMode=e,e&&(()=>{t(this,void 0,void 0,(function*(){let e=yield this.getScanSettings();e.trustFrameCount=1,yield this.updateScanSettings(e)}))})()}_assertOpen(){if(!this.dce)throw new Error("Need to set 'cameraEnhancer' first.");if(!this.dce.isOpen())throw Error("The camera is not open.")}_updateMinLtrSel(e){if(this._minLetter=e,this._optGotMinLtr){const t=e?`${e}+ letters`:"any letter";this._optGotMinLtr.innerText=t,this._selMinLtr&&this._optGotMinLtr.parentNode==this._selMinLtr&&(this._selMinLtr.value="got")}}get soundOnSuccessfullRead(){return this._soundOnSuccessfullRead}set soundOnSuccessfullRead(e){e instanceof HTMLAudioElement?this._soundOnSuccessfullRead=e:this._soundOnSuccessfullRead=new Audio(e)}get whenToPlaySoundforSuccessfulRead(){return!0===this.bPlaySoundOnSuccessfulRead?"frame":this.bPlaySoundOnSuccessfulRead?this.bPlaySoundOnSuccessfulRead:"never"}set whenToPlaySoundforSuccessfulRead(e){this.bPlaySoundOnSuccessfulRead="never"!==e&&e}get whenToVibrateforSuccessfulRead(){return!0===this.bVibrateOnSuccessfulRead?"frame":this.bVibrateOnSuccessfulRead?this.bVibrateOnSuccessfulRead:"never"}set whenToVibrateforSuccessfulRead(e){this.bVibrateOnSuccessfulRead="never"!==e&&e}get cameraEnhancer(){return this.dce}set cameraEnhancer(e){if(n)throw new Error("`cameraEnhancer` is not supported in Node.js.");this.dce=e,this.adjustDCESettings()}adjustDCESettings(){this.dce&&(l._onLog&&l._onLog("adjustDCESettings()"),this.dce.bufferRefreshInterval=200,this.dce.alwaysRefreshBuffer=!1,this.dce.ifSaveOriginalImageInACanvas=this.bSaveOriCanvas,this.dce._singleFrameModeIpt=function(){let e=document.createElement("input");return e.setAttribute("type","file"),e.setAttribute("accept","image/*"),e.setAttribute("capture",""),e.addEventListener("change",(()=>t(this,void 0,void 0,(function*(){let t=e.files[0];e.value="",this.onSingleFrameAcquired(t)})))),e.style.position="fixed",e.style.left="0",e.style.top="0",e.style.width="1px",e.style.height="1px",e.style.backgroundColor="transparent",e.style.color="transparent",this._video.parentElement.appendChild(e),e},this.dce.onSingleFrameAcquired=e=>t(this,void 0,void 0,(function*(){let t=yield this.recognize(e);yield this.clearMapDecodeRecord();for(let e of t)for(let t of e.lineResults)t.bUnduplicated&&delete e.bUnduplicated;if(this._drawRegionsults(t),this.onFrameRead&&this.dce.isOpen()&&!this._bPauseScan&&this.onFrameRead(t),this.onUniqueRead&&this.dce.isOpen()&&!this._bPauseScan)for(let e of t)for(let t of e.lineResults)t.bUnduplicated&&this.onUniqueRead(t.text,this._cloneDecodeResults(t));if(this.onMRZRead&&this.dce.isOpen()&&!this._bPauseScan){if(["passportMRZ","visaMRZ","MRZ"].includes(this.currentSettingsTemplate))for(let e of t){let t="",i=0;for(let s of e.lineResults)t.length>0&&(t+="\n"),t+=s.text,s.bUnduplicated&&i++;i>0&&t.length>0&&this.onMRZRead(t,this._cloneDecodeResults(e.lineResults))}}})),this._clickIptSingleFrameMode=this.dce._clickIptSingleFrameMode)}static loadWasm(){return t(this,void 0,void 0,(function*(){if(n&&process.version<"v12")throw new Error("DLRJS SDK requires nodejs version >= v12.");let i,s=this.license,r=JSON.parse(JSON.stringify(this._licenseServer)),o=this._sessionPassword,c=null,d=null,h=0;if(s.startsWith("t")||s.startsWith("f"))h=0;else if(0===s.length||s.startsWith("P")||s.startsWith("L"))h=1;else{h=2;const e=s.indexOf(":");if(-1!=e&&(s=s.substring(e+1)),s.startsWith("DLS2")){let e=s.substring(4);e=n?Buffer.from(e,"base64").toString("binary"):atob(e);const t=JSON.parse(e);if(t.handshakeCode?s=t.handshakeCode:t.organizationID&&(s=t.organizationID),"number"==typeof s&&(s=JSON.stringify(s)),s||(s=""),0===r.length){let e=[];t.mainServerURL&&(e[0]=t.mainServerURL),t.standbyServerURL&&(e[1]=t.standbyServerURL),this.licenseServer=e,r=this.licenseServer}!o&&t.sessionPassword&&(o=t.sessionPassword),t.chargeWay&&(d=t.chargeWay),t.limitedLicenseModules&&(c=t.limitedLicenseModules)}}if(h&&(n?process.version<"v15"&&(i="To use online key requires nodejs version >= v15."):(a.crypto||(i="Please upgrade your browser to support online key."),a.crypto.subtle||(i="Require https to use online key in this browser."))),i){if(1!==h)throw new Error(i);h=0,console.warn(i),this._lastErrorCode=e.EnumDLRErrorCode.UNKNOWN,this._lastErrorString=i}return 1===h&&(s="",console.warn("Applying for a public trial license ...")),yield new Promise(((e,i)=>t(this,void 0,void 0,(function*(){switch(this._loadWasmStatus){case"unload":{l._loadWasmStatus="loading";let e=this.engineResourcePath+this._workerName;if(n||this.engineResourcePath.startsWith(location.origin)||(e=yield fetch(e).then((e=>e.blob())).then((e=>URL.createObjectURL(e)))),n){const t=require("worker_threads");l._dlrWorker=new t.Worker(e)}else l._dlrWorker=new Worker(e);this._dlrWorker.onerror=e=>{l._loadWasmStatus="loadFail";let t=new Error(e.message);this._loadWasmErr=t;for(let e of this._loadWasmCallbackArr)e(t);this._loadWasmCallbackArr=[]},this._dlrWorker.onmessage=e=>t(this,void 0,void 0,(function*(){let t=e.data?e.data:e;switch(t.type){case"log":this._onLog&&this._onLog(t.message);break;case"load":{t.message&&(t.message=t.message.replace("(https://www.dynamsoft.com/purchase-center/)","(https://www.dynamsoft.com/store/dynamsoft-label-recognizer/#javascript)"));let e=!1;if(1===h&&(e=!0),t.success){l._loadWasmStatus="loadSuccess",l._version=t.version+"(JS "+this._jsVersion+"."+this._jsEditVersion+")",this._onLog&&this._onLog("load dlr worker success");for(let e of this._loadWasmCallbackArr)e();this._loadWasmCallbackArr=[],this._dlrWorker.onerror=null,t.message&&console.warn(t.message)}else{let i=new Error(t.message);i.stack=t.stack+"\n"+i.stack,l._loadWasmStatus="loadFail",this._loadWasmErr=i;for(let e of this._loadWasmCallbackArr)e(i);this._loadWasmCallbackArr=[],e||111==t.ltsErrorCode&&-1!=t.message.toLowerCase().indexOf("trial license")&&(e=!0)}e&&this.showDialog(t.success?"warn":"error",t.message);break}case"task":{let e=t.id,i=t.body;try{this._taskCallbackMap.get(e)(i),this._taskCallbackMap.delete(e)}catch(t){throw this._taskCallbackMap.delete(e),t}break}case"event":"resourcesLoadStarted"===t.body.type?l.onResourcesLoadStarted&&setTimeout((()=>l.onResourcesLoadStarted(t.body.resourcesPath)),0):"resourcesLoadProgress"===t.body.type?l.onResourcesLoadProgress&&setTimeout((()=>l.onResourcesLoadProgress(t.body.resourcesPath,{loaded:t.body.loaded,total:t.body.total})),0):"resourcesLoaded"===t.body.type&&l.onResourcesLoaded&&setTimeout((()=>l.onResourcesLoaded(t.body.resourcesPath)),0);break;default:this._onLog&&this._onLog(e)}})),n&&this._dlrWorker.on("message",this._dlrWorker.onmessage),this._dlrWorker.postMessage({type:"loadWasm",bd:this._bWasmDebug,engineResourcePath:this.engineResourcePath,version:this._jsVersion,brtk:!!h,bptk:1===h,lcs:s,dm:!n&&location.origin.startsWith("http")?location.origin:"https://localhost",browserInfo:this.browserInfo,deviceFriendlyName:this.deviceFriendlyName,ls:r,sp:o,lm:c,cw:d})}case"loading":this._loadWasmCallbackArr.push((t=>{t?i(t):e()}));break;case"loadSuccess":e();break;case"loadFail":i(this._loadWasmErr)}}))))}))}static showDialog(e,i){return t(this,void 0,void 0,(function*(){if(!n&&!this._bNeverShowDialog)try{let t=yield fetch(this.engineResourcePath+"dls.license.dialog.html");if(!t.ok)throw Error("Get license dialog fail. Network Error: "+t.statusText);let s=yield t.text();if(!s.trim().startsWith("<"))throw Error("Get license dialog fail. Can't get valid HTMLElement.");let r=document.createElement("div");r.innerHTML=s;let n=[];for(let e=0;e<r.childElementCount;++e){let t=r.children[e];t instanceof HTMLStyleElement&&(n.push(t),document.head.append(t))}let o=1==r.childElementCount?r.children[0]:r;o.remove();let a,l,c,d,h,u=[o],g=o.children;for(let e of g)u.push(e);for(let e=0;e<u.length;++e)for(let t of u[e].children)u.push(t);for(let t of u)if(!a&&t.classList.contains("dls-license-mask"))a=t,t.addEventListener("click",(e=>{if(t==e.target){o.remove();for(let e of n)e.remove()}}));else if(!l&&t.classList.contains("dls-license-icon-close"))l=t,t.addEventListener("click",(()=>{o.remove();for(let e of n)e.remove()}));else if(!c&&t.classList.contains("dls-license-icon-error"))c=t,"error"!=e&&t.remove();else if(!d&&t.classList.contains("dls-license-icon-warn"))d=t,"warn"!=e&&t.remove();else if(!h&&t.classList.contains("dls-license-msg-content")){h=t;let e=i;for(;e;){let i=e.indexOf("["),s=e.indexOf("]",i),r=e.indexOf("(",s),n=e.indexOf(")",r);if(-1==i||-1==s||-1==r||-1==n){t.appendChild(new Text(e));break}i>0&&t.appendChild(new Text(e.substring(0,i)));let o=document.createElement("a"),a=e.substring(i+1,s);o.innerText=a;let l=e.substring(r+1,n);o.setAttribute("href",l),o.setAttribute("target","_blank"),t.appendChild(o),e=e.substring(n+1)}}document.body.appendChild(o)}catch(e){this._onLog&&this._onLog(e.message||e)}}))}static createInstanceInWorker(){return t(this,void 0,void 0,(function*(){return yield this.loadWasm(),yield new Promise(((e,t)=>{let i=this._nextTaskID++;this._taskCallbackMap.set(i,(i=>{if(i.success)return e(i.instanceID);{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),this._dlrWorker.postMessage({type:"createInstance",id:i,bScanner:!1})}))}))}static createInstance(e){return t(this,void 0,void 0,(function*(){let t=new l;return t._instanceID=yield this.createInstanceInWorker(),e&&e.runtimeSettings&&t.updateRuntimeSettingsFromString(e.runtimeSettings),t}))}recognize(i,s){return t(this,void 0,void 0,(function*(){if(l._onLog&&l._onLog("recognize(source: any, modelName?: string)"),l._onLog&&(this._timeStartRecognize=Date.now()),s=s||{},n)return i instanceof Buffer?yield this._recognizeFileInMemory_Uint8Array(new Uint8Array(i),s):i instanceof Uint8Array?yield this._recognizeFileInMemory_Uint8Array(i,s):"string"==typeof i?"data:image/"==i.substring(0,11)?yield this._recognize_Base64(i,s):"http"==i.substring(0,4)?yield this._recognize_Url(i,s):yield this._recognize_FilePath(i,s):yield Promise.reject(TypeError("'_recognize(source, config)': Type of 'source' should be 'Buffer', 'Uint8Array', 'string(base64 with image mime)' or 'string(url)'."));if(i instanceof Blob)return yield this._recognize_Blob(i,s);if(i instanceof ArrayBuffer)return yield this._recognize_ArrayBuffer(i,s);if(i instanceof Uint8Array||i instanceof Uint8ClampedArray)return yield this._recognize_Uint8Array(i,s);if(i instanceof HTMLImageElement||"undefined"!=typeof ImageBitmap&&i instanceof ImageBitmap)return yield this._recognize_Image(i,s);if(i instanceof HTMLCanvasElement||"undefined"!=typeof OffscreenCanvas&&i instanceof OffscreenCanvas)return yield this._recognize_Canvas(i,s);if(i instanceof HTMLVideoElement)return yield this._recognize_Video(i,s);if("string"==typeof i)return"data:image/"==i.substring(0,11)?yield this._recognize_Base64(i,s):yield this._recognize_Url(i,s);if(i&&"object"==typeof i){const{data:t,canvas:s,region:r,sx:n,sy:o,width:a,height:l}=i;return s&&t?yield this._recognizeBuffer_Uint8Array(t,s.width,s.height,4*s.width,e.EnumDLRImagePixelFormat.IPF_ABGR_8888):t&&a&&l?yield this._recognizeBuffer_Uint8Array(t,a,l,a,e.EnumDLRImagePixelFormat.IPF_GRAYSCALED):yield Promise.reject(TypeError("'_recognize(source, config)': Type of 'source' should be 'Blob', 'ArrayBuffer', 'Uint8Array', 'HTMLImageElement', 'HTMLCanvasElement', 'HTMLVideoElement', 'string(base64 with image mime)', 'string(url)' or 'object(dceFrame)'."))}return yield Promise.reject(TypeError("'_recognize(source, config)': Type of 'source' should be 'Blob', 'ArrayBuffer', 'Uint8Array', 'HTMLImageElement', 'HTMLCanvasElement', 'HTMLVideoElement', 'string(base64 with image mime)', 'string(url)' or 'object(dceFrame)'."))}))}recognizeBase64String(e,i){return t(this,void 0,void 0,(function*(){let t={};return i&&(t.modelName=i),this._recognize_Base64(e,t)}))}recognizeUrl(e,i){return t(this,void 0,void 0,(function*(){let t={};return i&&(t.modelName=i),this._recognize_Url(e,t)}))}_recognizeBuffer_Uint8Array(e,i,s,r,n,o){return t(this,void 0,void 0,(function*(){return yield new Promise(((t,a)=>{let c=l._nextTaskID++;l._taskCallbackMap.set(c,(e=>{if(e.success){let i,s=l._onLog?Date.now():0;this._lastInnerDecodeDuration=e.duration,this.bufferShared&&!this.bufferShared.length&&(this.bufferShared=e.buffer);try{i=this._handleRetJsonString(e.decodeReturn);const t=e=>!!e&&("VIN_NA"===this.currentSettingsTemplate?this._checkValidVIN(e):"passportMRZ"===this.currentSettingsTemplate?44==e.length&&(/[0-9]/.test(e)?this._checkValidMRP(e):null):"visaMRZ"===this.currentSettingsTemplate?(44==e.length||36==e.length)&&(/[0-9]/.test(e)?this._checkValidMRV(e):null):null);for(let e of i)for(let i of e.lineResults)i.isCheckDigitMatched=t(i.text)}catch(e){return a(e)}if(l._onLog){let e=Date.now();l._onLog("time get result: "+s),l._onLog("Handle image cost: "+(this._timeEnterInnerDLR-this._timeStartRecognize)),l._onLog("worker recognize image cost: "+(s-this._timeEnterInnerDLR)),l._onLog("worker handle results: "+(e-s)),l._onLog("Total recognize image cost: "+(e-this._timeStartRecognize))}return t(i)}{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,a(t)}})),l._onLog&&(this._timeEnterInnerDLR=Date.now()),l._onLog&&l._onLog("Send buffer to worker:"+this._timeEnterInnerDLR),l._dlrWorker.postMessage({type:"recognizeByBuffer",id:c,instanceID:this._instanceID,body:{config:o,imageData:{bytes:e,length:s*i*4,width:i,height:s,stride:r,format:n}}},[e.buffer])}))}))}_recognizeBuffer_Blob(e,i,s,r,n,o){return t(this,void 0,void 0,(function*(){l._onLog&&l._onLog("_recognizeBuffer_Blob(buffer,width,height,stride,format)");const t=e.arrayBuffer?yield e.arrayBuffer():yield new Promise(((t,i)=>{let s=new FileReader;s.readAsArrayBuffer(e),s.onload=()=>{t(s.result)},s.onerror=()=>{i(s.error)}}));return yield this._recognizeBuffer_Uint8Array(new Uint8Array(t),i,s,r,n,o)}))}recognizeBuffer(e,i,s,r,o,a){return t(this,void 0,void 0,(function*(){let t;return l._onLog&&l._onLog("recognizeBuffer(buffer,width,height,stride,format)"),l._onLog&&(this._timeStartRecognize=Date.now()),n?e instanceof Uint8Array?t=yield this._recognizeBuffer_Uint8Array(e,i,s,r,o,a):e instanceof Buffer&&(t=yield this._recognizeBuffer_Uint8Array(new Uint8Array(e),i,s,r,o,a)):e instanceof Uint8Array||e instanceof Uint8ClampedArray?t=yield this._recognizeBuffer_Uint8Array(e,i,s,r,o,a):e instanceof ArrayBuffer?t=yield this._recognizeBuffer_Uint8Array(new Uint8Array(e),i,s,r,o,a):e instanceof Blob&&(t=yield this._recognizeBuffer_Blob(e,i,s,r,o,a)),t}))}_recognizeFileInMemory_Uint8Array(e,i){return t(this,void 0,void 0,(function*(){return yield new Promise(((t,s)=>{let r=l._nextTaskID++;l._taskCallbackMap.set(r,(e=>{if(e.success){let i;try{i=this._handleRetJsonString(e.decodeReturn)}catch(e){return s(e)}return t(i)}{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,s(t)}})),l._dlrWorker.postMessage({type:"recognizeFileInMemory",id:r,instanceID:this._instanceID,body:{config:i,bytes:e}})}))}))}getRuntimeSettings(){return t(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=l._nextTaskID++;l._taskCallbackMap.set(i,(i=>{if(i.success){let t=JSON.parse(i.results);return e(t)}{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),l._dlrWorker.postMessage({type:"getRuntimeSettings",id:i,instanceID:this._instanceID})}))}))}static isRegionNormalPreset(e){return r.LST_MANUAL_SPECIFICATION==e.localizationSourceType&&1==e.regionMeasuredByPercentage&&JSON.stringify([{x:0,y:100},{x:100,y:0},{x:100,y:100},{x:0,y:100}])===JSON.stringify(e.location.points)}updateRuntimeSettings(e){return t(this,void 0,void 0,(function*(){let t;if("string"==typeof e){if(!(e=e.trim()).startsWith("{"))return void this.updateRuntimeSettingsFromString(e);t=JSON.parse(e)}else{if("object"!=typeof e)throw TypeError("'UpdateRuntimeSettings(settings)': Type of 'settings' should be 'string' or 'PlainObject'.");t=JSON.parse(JSON.stringify(e))}const i=t.referenceRegion;l.isRegionNormalPreset(i)?this.region=null:this.region=i,this._updateMinLtrSel(0),yield new Promise(((e,i)=>{let s=l._nextTaskID++;l._taskCallbackMap.set(s,(t=>{if(t.success){try{this._handleRetJsonString(t.updateReturn)}catch(e){i(e)}return e()}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,i(e)}})),l._dlrWorker.postMessage({type:"updateRuntimeSettings",id:s,instanceID:this._instanceID,body:{settings:JSON.stringify(t)}})}))}))}resetRuntimeSettings(){return t(this,void 0,void 0,(function*(){return this.region=null,this._updateMinLtrSel(0),yield new Promise(((e,t)=>{let i=l._nextTaskID++;l._taskCallbackMap.set(i,(i=>{if(i.success)return e();{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),l._dlrWorker.postMessage({type:"resetRuntimeSettings",id:i,instanceID:this._instanceID})}))}))}updateRuntimeSettingsFromString(e){return t(this,void 0,void 0,(function*(){let t=0;if("string"==typeof e)if((e=e.trim()).startsWith("{"))e=JSON.parse(e);else{if(e.length>50)throw new Error("Error: preset longer than 50 letters.");const i=e.toLowerCase().split("-");if(i.length>2)throw new Error(`Error: '${e}' is not supported.`);if(i.includes("numberletter"))t=3,this.currentSettingsTemplate="numberLetter";else if(i.includes("numberuppercase"))t=3,this.currentSettingsTemplate="numberUppercase";else if(i.includes("number"))t=3,this.currentSettingsTemplate="number";else if(i.includes("letter"))t=3,this.currentSettingsTemplate="letter";else if(i.includes("passportmrz"))t=44,this.currentSettingsTemplate="passportMRZ";else if(i.includes("visamrz"))t=36,this.currentSettingsTemplate="visaMRZ";else if(i.includes("mrz"))t=30,this.currentSettingsTemplate="MRZ";else if(i.includes("vin_na"))t=14,this.currentSettingsTemplate="VIN_NA";else if(i.includes("vin"))t=14,this.currentSettingsTemplate="VIN";else{if(!i.includes("cppdefault"))throw new Error(`Error: '${e}' is not supported.`);this.currentSettingsTemplate="cppdefault"}i.includes("video")?this.region={localizationSourceType:r.LST_MANUAL_SPECIFICATION,location:{points:[{x:0,y:40},{x:100,y:40},{x:100,y:60},{x:0,y:60}]},regionMeasuredByPercentage:1}:this.region=null}else{if("object"!=typeof e)throw TypeError("'updateRuntimeSettingsFromString(settings)': Type of 'settings' should be 'string' or 'PlainObject'.");this.currentSettingsTemplate=null}if("object"==typeof e){const i=e.ReferenceRegionArray[0].Localization,s=i.FirstPoint?{localizationSourceType:r[i.SourceType],location:{points:[{x:i.FirstPoint[0],y:i.FirstPoint[1]},{x:i.SecondPoint[0],y:i.SecondPoint[1]},{x:i.ThirdPoint[0],y:i.ThirdPoint[1]},{x:i.FourthPoint[0],y:i.FourthPoint[1]}]},regionMeasuredByPercentage:i.MeasuredByPercentage}:null;s&&l.isRegionNormalPreset(s)?this.region=null:this.region=s;const n=e.LabelRecognizerParameterArray[0].LineStringLengthRange;t=n?n[0]:0}return this._updateMinLtrSel(t),yield new Promise(((t,i)=>{let s=l._nextTaskID++;l._taskCallbackMap.set(s,(e=>{if(e.success){try{this._handleRetJsonString(e.updateReturn)}catch(e){i(e)}return t()}{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,i(t)}})),l._dlrWorker.postMessage({type:"updateRuntimeSettingsFromString",id:s,instanceID:this._instanceID,body:{settings:e}})}))}))}outputRuntimeSettingsToString(){return t(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=l._nextTaskID++;l._taskCallbackMap.set(i,(i=>{if(i.success)return e(i.results);{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),l._dlrWorker.postMessage({type:"outputSettingsToString",id:i,instanceID:this._instanceID})}))}))}updateReferenceRegionFromBarcodeResults(e){return t(this,void 0,void 0,(function*(){return yield new Promise(((t,i)=>{let s=l._nextTaskID++;l._taskCallbackMap.set(s,(e=>{if(e.success)return t();{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,i(t)}})),l._dlrWorker.postMessage({type:"updateReferenceRegionFromBarcodeResults",id:s,instanceID:this._instanceID,body:{dbrTextResults:e}})}))}))}static appendCaffeModelBuffer(e,i){return t(this,void 0,void 0,(function*(){return yield new Promise(((t,s)=>{let r=l._nextTaskID++;l._taskCallbackMap.set(r,(e=>{if(e.success){try{return t()}catch(e){s(e)}return t()}{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,s(t)}})),l._dlrWorker.postMessage({type:"appendCaffeModelBuffer",id:r,body:{name:e,folderUrl:i}})}))}))}static eraseCaffeModelByName(e){return t(this,void 0,void 0,(function*(){return yield new Promise(((t,i)=>{let s=l._nextTaskID++;l._taskCallbackMap.set(s,(e=>{if(e.success)return t();{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,i(t)}})),l._dlrWorker.postMessage({type:"eraseCaffeModelByName",id:s,body:{name:e}})}))}))}static eraseAllCaffeModels(){return t(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=l._nextTaskID++;l._taskCallbackMap.set(i,(i=>{if(i.success)return e();{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),l._dlrWorker.postMessage({type:"eraseAllCaffeModels",id:i})}))}))}_recognize_Blob(e,i){return t(this,void 0,void 0,(function*(){l._onLog&&l._onLog("_recognize_Blob(blob: Blob)");let t=null,s=null;if("undefined"!=typeof createImageBitmap)try{t=yield createImageBitmap(e)}catch(e){}t||(s=yield function(e){return new Promise(((t,i)=>{let s=URL.createObjectURL(e),r=new Image;r.dlrObjUrl=s,r.src=s,r.onload=()=>{t(r)},r.onerror=e=>{i(new Error("Can't convert blob to image : "+(e instanceof Event?e.type:e)))}}))}(e));let r=yield this._recognize_Image(t||s,i);return t&&t.close(),r}))}_recognize_ArrayBuffer(e,i){return t(this,void 0,void 0,(function*(){return yield this._recognize_Blob(new Blob([e]),i)}))}_recognize_Uint8Array(e,i){return t(this,void 0,void 0,(function*(){return yield this._recognize_Blob(new Blob([e]),i)}))}_recognize_Image(e,i){return t(this,void 0,void 0,(function*(){l._onLog&&l._onLog("_recognize_Image(image: HTMLImageElement|ImageBitmap)"),i=i||{};let t,s,r=e instanceof HTMLImageElement?e.naturalWidth:e.width,n=e instanceof HTMLImageElement?e.naturalHeight:e.height,o=Math.max(r,n);if(o>this._canvasMaxWH){let e=this._canvasMaxWH/o;t=Math.round(r*e),s=Math.round(n*e)}else t=r,s=n;let c,d=r,h=n,u=t,g=s;!this.bSaveOriCanvas&&a.OffscreenCanvas?c=new OffscreenCanvas(u,g):(c=document.createElement("canvas"),c.width=u,c.height=g);let _=c.getContext("2d");return r==d&&n==h&&r==u&&n==g?_.drawImage(e,0,0):_.drawImage(e,0,0,d,h,0,0,u,g),e.dlrObjUrl&&URL.revokeObjectURL(e.dlrObjUrl),yield this._recognize_Canvas(c,i)}))}_recognize_Canvas(i,s){return t(this,void 0,void 0,(function*(){if(l._onLog&&l._onLog("_recognize_Canvas(canvas:HTMLCanvasElement)"),i.crossOrigin&&"anonymous"!=i.crossOrigin)throw"cors";if(0===i.width||0===i.height)throw Error("The width or height of the 'canvas' is 0.");(this.bSaveOriCanvas||this.dce&&this.singleFrameMode)&&(this.oriCanvas=i);let t=(i.dlrCtx2d||i.getContext("2d")).getImageData(0,0,i.width,i.height).data;return yield this._recognizeBuffer_Uint8Array(t,i.width,i.height,4*i.width,e.EnumDLRImagePixelFormat.IPF_ABGR_8888,s)}))}_recognize_Video(e,i){return t(this,void 0,void 0,(function*(){if(l._onLog&&l._onLog("_recognize_Video(video)"),!(e instanceof HTMLVideoElement))throw TypeError("'_recognize_Video(video [, config] )': Type of 'video' should be 'HTMLVideoElement'.");if(e.crossOrigin&&"anonymous"!=e.crossOrigin)throw"cors";i=i||{};let t,s,r=e.videoWidth,n=e.videoHeight,o=Math.max(r,n);if(o>this._canvasMaxWH){let e=this._canvasMaxWH/o;t=Math.round(r*e),s=Math.round(n*e)}else t=r,s=n;let c=r,d=n,h=t,u=s,g=r==c&&n==d&&r==h&&n==u,_=null;!this.bSaveOriCanvas&&a.OffscreenCanvas?_=new OffscreenCanvas(h,u):(_=document.createElement("canvas"),_.width=h,_.height=u);const f=_.dlrCtx2d=_.getContext("2d");return g?f.drawImage(e,0,0):f.drawImage(e,0,0,c,d,0,0,h,u),yield this._recognize_Canvas(_,i)}))}_recognize_Base64(e,i){return t(this,void 0,void 0,(function*(){if(l._onLog&&l._onLog("_recognize_Base64(base64Str)"),"string"!=typeof e&&"object"!=typeof e)return Promise.reject("'_recognize_Base64(base64Str, config)': Type of 'base64Str' should be 'string'.");if("data:image/"==e.substring(0,11)&&(e=e.substring(e.indexOf(",")+1)),n){let t=Buffer.from(e,"base64");return yield this._recognizeFileInMemory_Uint8Array(new Uint8Array(t),i)}{let t=atob(e),s=t.length,r=new Uint8Array(s);for(;s--;)r[s]=t.charCodeAt(s);return yield this._recognize_Blob(new Blob([r]),i)}}))}_recognize_Url(e,i){return t(this,void 0,void 0,(function*(){if(l._onLog&&l._onLog("_recognize_Url(url)"),"string"!=typeof e&&"object"!=typeof e)throw TypeError("'_recognize_Url(url, config)': Type of 'url' should be 'string'.");if(n){let t=yield new Promise(((t,i)=>{(e.startsWith("https")?require("https"):require("http")).get(e,(e=>{if(200==e.statusCode){let i=[];e.on("data",(e=>{i.push(e)})).on("end",(()=>{t(new Uint8Array(Buffer.concat(i)))}))}else i("http get fail, statusCode: "+e.statusCode)}))}));return yield this._recognizeFileInMemory_Uint8Array(t,i)}{let s=yield new Promise(((i,s)=>{let r=new XMLHttpRequest;r.open("GET",e,!0),r.responseType="blob",r.send(),r.onloadend=()=>t(this,void 0,void 0,(function*(){i(r.response)})),r.onerror=()=>{s(new Error("Network Error: "+r.statusText))}}));return yield this._recognize_Blob(s,i)}}))}_recognize_FilePath(e,i){return t(this,void 0,void 0,(function*(){if(l._onLog&&l._onLog("_recognize_FilePath(path)"),!n)throw Error("'_recognize_FilePath(path, config)': The method is only supported in node environment.");if("string"!=typeof e&&"object"!=typeof e)throw TypeError("'_recognize_FilePath(path, config)': Type of 'path' should be 'string'.");const t=require("fs");let s=yield new Promise(((i,s)=>{t.readFile(e,((e,t)=>{e?s(e):i(new Uint8Array(t))}))}));return yield this._recognizeFileInMemory_Uint8Array(s,i)}))}static LabelRecognizerException(t,i){let s,r=e.EnumDLRErrorCode.UNKNOWN;return"number"==typeof t?(r=t,s=new Error(i)):s=new Error(t),s.code=r,s}_handleRetJsonString(t){let i=e.EnumDLRErrorCode;if(t.results){const i=this.drawRegionsultRecords,s={};for(let e=0;e<t.results.length;e++){let r=t.results[e];if(null!=r.exception){this._setWarnnedEx.has(r.exception)||(this._setWarnnedEx.add(r.exception),console.warn(r.exception));let e={};r.exception.split(";").forEach((t=>{let i=t.indexOf(":");e[t.substring(0,i)]=t.substring(i+1)})),r.exception=e}for(let e of r.lineResults){const t=e.text;if(s[t]=1,e.bUnduplicated){(i[t]=i[t]||[]).push(e)}else i[t]&&(i[t]=[e])}}if(t.records){const e=this.recognizeRecords=t.records;for(let t in i)e[t]||delete i[t];for(let e in i)s[e]||(i[e]=[])}else this.recognizeRecords={},this.drawRegionsultRecords={};return this._lastErrorCode=t.exception,this._lastErrorString=t.description,t.exception&&!this._setWarnnedEx.has(t.description)&&(this._setWarnnedEx.add(t.description),t.exception==e.EnumDLRErrorCode.LICENSE_INVALID||t.exception==e.EnumDLRErrorCode.LICENSE_EXPIRED?console.error(t.description):console.warn(t.description)),t.results}if(t.exception==i.OK)return t.data;throw l.LabelRecognizerException(t.exception,t.description)}setModeArgument(e,i,s,r){return t(this,void 0,void 0,(function*(){return yield new Promise(((t,n)=>{let o=l._nextTaskID++;l._taskCallbackMap.set(o,(e=>{if(e.success){try{this._handleRetJsonString(e.setReturn)}catch(e){return n(e)}return t()}{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,n(t)}})),l._dlrWorker.postMessage({type:"setModeArgument",id:o,instanceID:this._instanceID,body:{modeName:e,index:i,argumentName:s,argumentValue:r}})}))}))}getModeArgument(e,i,s){return t(this,void 0,void 0,(function*(){return yield new Promise(((t,r)=>{let n=l._nextTaskID++;l._taskCallbackMap.set(n,(e=>{if(e.success){let i;try{i=this._handleRetJsonString(e.getReturn)}catch(e){return r(e)}return t(i)}{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,r(t)}})),l._dlrWorker.postMessage({type:"getModeArgument",id:n,instanceID:this._instanceID,body:{modeName:e,index:i,argumentName:s}})}))}))}recognizeCurrentFrame(){return t(this,void 0,void 0,(function*(){this._assertOpen();let t=this.dce.getFrame();if(t&&null===t.canvas){let{data:i,width:s,height:r}=t;return yield this._recognizeBuffer_Uint8Array(i,s,r,s,e.EnumDLRImagePixelFormat.IPF_GRAYSCALED)}if(t&&t.canvas){let{data:i,canvas:s}=t;return(this.bSaveOriCanvas||this.singleFrameMode)&&(this.oriCanvas=s),yield this._recognizeBuffer_Uint8Array(i,s.width,s.height,4*s.width,e.EnumDLRImagePixelFormat.IPF_ABGR_8888)}}))}clearMapDecodeRecord(){return t(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=l._nextTaskID++;l._taskCallbackMap.set(i,(i=>{if(i.success)return e();{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),l._dlrWorker.postMessage({type:"clearMapDecodeRecord",id:i,instanceID:this._instanceID})}))}))}_bindUI(){const e=this.dce.getUIElement();if(!e)throw new Error("Need to define `UIElement` before opening.");this.dce._bindUI();let t=[e],i=e.children;for(let e of i)t.push(e);for(let e=0;e<t.length;++e)for(let i of t[e].children)t.push(i);for(let e of t)!this._cvsDrawArea&&e.classList.contains("dlr-cvs-drawarea")?this._cvsDrawArea=e:!this._divScanArea&&e.classList.contains("dlr-cvs-scanarea")?this._divScanArea=e:!this._divScanLight&&e.classList.contains("dlr-scanlight")?this._divScanLight=e:!this._selCam&&e.classList.contains("dce-sel-camera")?this._selCam=e:!this._selRsl&&e.classList.contains("dce-sel-resolution")?this._selRsl=e:!this._selMinLtr&&e.classList.contains("dlr-sel-minletter")?(this._selMinLtr=e,this._selMinLtr.options.length||(this._selMinLtr.innerHTML=[this._optGotMinLtr?"":'<option class="dlr-opt-gotMinLtr" value="got"></option>','<option value="0" selected>any letter</option>','<option value="3">3+ letters</option>','<option value="5">5+ letters</option>','<option value="8">8+ letters</option>','<option value="12">12+ letters</option>','<option value="18">18+ letters</option>','<option value="30">30+ letters</option>','<option value="50">50+ letters</option>','<option value="80">80+ letters</option>','<option value="120">120+ letters</option>'].join(""),this._optGotMinLtr=this._optGotMinLtr||this._selMinLtr.options[0])):this._optGotMinLtr||!e.classList.contains("dlr-opt-gotMinLtr")&&!e.classList.contains("dlr-opt-gotMinLtr")?!this._btnClose&&e.classList.contains("dce-btn-close")&&(this._btnClose=e):this._optGotMinLtr=e;if(this.singleFrameMode&&(this._cvsDrawArea&&(this._cvsDrawArea.addEventListener("click",this._clickIptSingleFrameMode),this._cvsDrawArea.style.cursor="pointer",this._cvsDrawArea.setAttribute("title","Take a photo")),this._divScanArea&&(this._divScanArea.addEventListener("click",this._clickIptSingleFrameMode),this._divScanArea.style.cursor="pointer",this._divScanArea.setAttribute("title","Take a photo"))),this._selCam&&this._selCam.addEventListener("change",this._onCameraSelChange),this._selRsl&&this._selRsl.addEventListener("change",this._onResolutionSelChange),this._selMinLtr&&this._selMinLtr.addEventListener("change",this._onMinLetterSelChange),this._btnClose&&this._btnClose.addEventListener("click",this._onCloseBtnClick),!this.dce.video)throw this._unbindUI(),Error("Can not find HTMLVideoElement with class `dce-video`.");this._updateMinLtrSel(this._minLetter)}_unbindUI(){this._clearRegionsults(),this.singleFrameMode&&(this._cvsDrawArea&&(this._cvsDrawArea.removeEventListener("click",this._clickIptSingleFrameMode),this._cvsDrawArea.style.cursor="",this._cvsDrawArea.removeAttribute("title")),this._divScanArea&&(this._divScanArea.removeEventListener("click",this._clickIptSingleFrameMode),this._divScanArea.style.cursor="",this._divScanArea.removeAttribute("title"))),this._selCam&&this._selCam.removeEventListener("change",this._onCameraSelChange),this._selRsl&&this._selRsl.removeEventListener("change",this._onResolutionSelChange),this._selMinLtr&&this._selMinLtr.removeEventListener("change",this._onMinLetterSelChange),this._btnClose&&this._btnClose.removeEventListener("click",this._onCloseBtnClick),this.dce._unbindUI(),this._cvsDrawArea=null,this._divScanArea=null,this._divScanLight=null,this._selCam=null,this._selRsl=null,this._selMinLtr=null,this._optGotMinLtr=null,this._btnClose=null}getScanSettings(){return t(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=l._nextTaskID++;l._taskCallbackMap.set(i,(i=>{if(i.success){let t=i.results;return t.intervalTime=this.intervalTime,e(t)}{let e=new Error(i.message);return e.stack+="\n"+i.stack,t(e)}})),l._dlrWorker.postMessage({type:"getScanSettings",id:i,instanceID:this._instanceID})}))}))}updateScanSettings(e){return t(this,void 0,void 0,(function*(){return this.intervalTime=e.intervalTime,yield new Promise(((t,i)=>{let s=l._nextTaskID++;l._taskCallbackMap.set(s,(e=>{if(e.success)return t();{let t=new Error(e.message);return t.stack+="\n"+e.stack,i(t)}})),l._dlrWorker.postMessage({type:"updateScanSettings",id:s,instanceID:this._instanceID,body:{settings:e}})}))}))}_show(){const e=this.dce.getUIElement();e.parentNode||(e.style.position="fixed",e.style.left="0",e.style.top="0",document.body.append(e)),"none"==e.style.display&&(e.style.display="")}stop(){this.dce&&this.dce.stop(),this._divScanLight&&(this._divScanLight.style.display="none"),this._drawRegionsults(),this.array_decodeFrameTimeCost.length=0,this.array_getFrameTimeCost.length=0,this._intervalGetVideoFrame=0}_cloneDecodeResults(e){if(e instanceof Array){let t=[];for(let i of e)t.push(this._cloneDecodeResults(i));return t}{let t=e;return JSON.parse(JSON.stringify(t,((e,t)=>"oriVideoCanvas"==e||"searchRegionCanvas"==e?void 0:t)))}}_loopReadVideo(){return t(this,void 0,void 0,(function*(){if(this.bDestroyed)return void(this.dce&&this.dce.stopFetchingLoop());if(!this.dce||!this.dce.isOpen())return this.dce&&this.dce.stopFetchingLoop(),void(yield this.clearMapDecodeRecord());if(!this.dce.video||this.dce.video.paused||this._bPauseScan)return l._onLog&&l._onLog("Video or scan is paused. Ask in 1s."),this.dce&&this.dce.stopFetchingLoop(),yield this.clearMapDecodeRecord(),this._loopReadVideoTimeoutId&&clearTimeout(this._loopReadVideoTimeoutId),void(this._loopReadVideoTimeoutId=setTimeout((()=>{this._loopReadVideo()}),this._intervalDetectVideoPause));this._divScanLight&&"none"==this._divScanLight.style.display&&(this._divScanLight.style.display=""),l._onLog&&l._onLog("======= once read ======="),l._onLog&&(this._timeStartRecognize=Date.now());let i=this._getVideoFrame();if(!i)return this._loopReadVideoTimeoutId&&clearTimeout(this._loopReadVideoTimeoutId),void(this._loopReadVideoTimeoutId=setTimeout((()=>{this._loopReadVideo()}),0));(()=>t(this,void 0,void 0,(function*(){if(i&&null===i.canvas){let{data:t,width:s,height:r,timeStamp:n}=i,o={timeStamp:n,bScanner:!0};return yield this._recognizeBuffer_Uint8Array(t,s,r,s,e.EnumDLRImagePixelFormat.IPF_GRAYSCALED,o)}if(i&&i.canvas){let{data:t,canvas:s,region:r,sx:n,sy:o,width:a,height:l,timeStamp:c}=i,d={timeStamp:c,bScanner:!0};return(this.bSaveOriCanvas||this.singleFrameMode)&&(this.oriCanvas=s),yield this._recognizeBuffer_Uint8Array(t,s.width,s.height,4*s.width,e.EnumDLRImagePixelFormat.IPF_ABGR_8888,d)}{let e=new Error("imgData is empty.");return new Promise((t=>t(e)))}})))().then((e=>{l._onLog&&l._onLog(e);let t=this.array_decodeFrameTimeCost,i=this.array_getFrameTimeCost;if((()=>{for(;t.length>=5;)t.shift();t.push(this._lastInnerDecodeDuration)})(),this._intervalGetVideoFrame=(()=>{let e=0;if(i&&i.length){let s=Math.min(...t),r=Math.max(...i);s&&r&&(e=s-r)}else e=0;return e>0?e:0})(),this.dce&&this.dce.isOpen()&&this.dce.video&&!this.dce.video.paused&&!this._bPauseScan){if(this.bPlaySoundOnSuccessfulRead&&e.length){let t=!1;if(!0===this.bPlaySoundOnSuccessfulRead||"frame"===this.bPlaySoundOnSuccessfulRead)t=!0;else if("unique"===this.bPlaySoundOnSuccessfulRead)for(let i of e)for(let e of i.lineResults)if(e.bUnduplicated){t=!0;break}t&&(this.soundOnSuccessfullRead.currentTime=0,this.soundOnSuccessfullRead.play().catch((e=>{console.warn("Autoplay not allowed. User interaction required.")})))}if(navigator.vibrate&&this.bVibrateOnSuccessfulRead&&e.length){let t=!1;if(!0===this.bVibrateOnSuccessfulRead||"frame"===this.bVibrateOnSuccessfulRead)t=!0;else if("unique"===this.bVibrateOnSuccessfulRead)for(let i of e)for(let e of i.lineResults)if(e.bUnduplicated){t=!0;break}if(t)try{navigator.vibrate(this.vibrateDuration)}catch(e){console.warn("Vibration not allowed. User interaction required: "+(e.message||e))}}if(this.onFrameRead){let t=this._cloneDecodeResults(e);for(let e of t)for(let t of e.lineResults)t.bUnduplicated&&delete e.bUnduplicated;this.onFrameRead(t)}if(this.onUniqueRead)for(let t of e)for(let e of t.lineResults)e.bUnduplicated&&this.onUniqueRead(e.text,this._cloneDecodeResults(e));if(this.onMRZRead){if(["passportMRZ","visaMRZ","MRZ"].includes(this.currentSettingsTemplate))for(let t of e){let e="",i=0;for(let s of t.lineResults)e.length>0&&(e+="\n"),e+=s.text,s.bUnduplicated&&i++;i>0&&e.length>0&&this.onMRZRead(e,this._cloneDecodeResults(t.lineResults))}}{const e=[];for(let t in this.drawRegionsultRecords)e.push(...this.drawRegionsultRecords[t]);this._drawRegionsults([{lineResults:e}])}}this._loopReadVideoTimeoutId&&clearTimeout(this._loopReadVideoTimeoutId),this.intervalTime?this._loopReadVideoTimeoutId=setTimeout((()=>{this._loopReadVideo()}),this.intervalTime):this._loopReadVideo()})).catch((e=>{this.dce.stopFetchingLoop(),l._onLog&&l._onLog(e.message||e),this._loopReadVideoTimeoutId&&clearTimeout(this._loopReadVideoTimeoutId),this._loopReadVideoTimeoutId=setTimeout((()=>{this._loopReadVideo()}),Math.max(this.intervalTime,1e3)),"platform error"==e.message||console.warn(e.message)}))}))}_getVideoFrame(){let e=this.dce.isFetchingLoopStarted();if(this.dce.loopInterval=this._intervalGetVideoFrame,e||this.dce.startFetchingLoop(),!this.dce.getQueueLength())return this.dce.loopInterval=0,null;let t=this.dce.getFrameFromBuffer();return(e=>{let t=e.timeSpent,i=this.array_getFrameTimeCost;for(;i.length>=5;)i.shift();i.push(t)})(t),t}_checkValidVIN(e){if(!e||17!=e.length)return!1;const t=(e=>{const t=new Map([["A",1],["B",2],["C",3],["D",4],["E",5],["F",6],["G",7],["H",8],["J",1],["K",2],["L",3],["M",4],["N",5],["P",7],["R",9],["S",2],["T",3],["U",4],["V",5],["W",6],["X",7],["Y",8],["Z",9],["1",1],["2",2],["3",3],["4",4],["5",5],["6",6],["7",7],["8",8],["9",9]]),i=[8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2];let s=0;for(let r=0;r<e.length;r++){let n=t.get(e[r]);n&&(s+=n*i[r])}return s%11})(e);return t.toString()===e[8]}_checkValidMRP(e){if(!e||44!=e.length)return!1;const t=(e,t,i)=>{const s=new Map([["<",0],["0",0],["1",1],["2",2],["3",3],["4",4],["5",5],["6",6],["7",7],["8",8],["9",9],["A",10],["B",11],["C",12],["D",13],["E",14],["F",15],["G",16],["H",17],["I",18],["J",19],["K",20],["L",21],["M",22],["N",23],["O",24],["P",25],["Q",26],["R",27],["S",28],["T",29],["U",30],["V",31],["W",32],["X",33],["Y",34],["Z",35]]),r=[7,3,1];let n=0;for(let o=t,a=0;o<=i;o++){let t=s.get(e[o]);t&&(n+=t*r[a%3]),a++}return n%10},i=e.slice(0,10)+e.slice(13,20)+e.slice(21,43),s=t(e,0,8).toString(),r=t(e,13,18).toString(),n=t(e,21,26).toString(),o=t(e,28,41).toString(),a=t(i,0,i.length).toString();return s===e[9]&&r===e[19]&&n===e[27]&&o===e[42]&&a===e[43]}_checkValidMRV(e){if(!e||44!=e.length&&36!=e.length)return!1;const t=(e,t,i)=>{const s=new Map([["<",0],["0",0],["1",1],["2",2],["3",3],["4",4],["5",5],["6",6],["7",7],["8",8],["9",9],["A",10],["B",11],["C",12],["D",13],["E",14],["F",15],["G",16],["H",17],["I",18],["J",19],["K",20],["L",21],["M",22],["N",23],["O",24],["P",25],["Q",26],["R",27],["S",28],["T",29],["U",30],["V",31],["W",32],["X",33],["Y",34],["Z",35]]),r=[7,3,1];let n=0;for(let o=t,a=0;o<=i;o++){let t=s.get(e[o]);t&&(n+=t*r[a%3]),a++}return n%10},i=t(e,0,8).toString(),s=t(e,13,18).toString(),r=t(e,21,26).toString();return i===e[9]&&s===e[19]&&r===e[27]}_drawRegionsults(e){let t,i,s;if(this.beingLazyDrawRegionsults=!1,this.singleFrameMode){if(!this.oriCanvas)return;t="contain",i=this.oriCanvas.width,s=this.oriCanvas.height}else{if(!this.dce.video)return;t=this.dce.video.style.objectFit||"contain",i=this.dce.video.videoWidth,s=this.dce.video.videoHeight}if(i<=0||i<=0)return;let n,o,a,l,c,d,h,u,g=this.region;if(g)if(r.LST_MANUAL_SPECIFICATION!=g.localizationSourceType)g=null;else if(g.regionMeasuredByPercentage){let e=g.location.points;if(0==e[0].x&&0==e[0].y&&100==e[1].x&&0==e[1].y&&100==e[2].x&&100==e[2].y&&0==e[3].x&&100==e[3].y)g=null;else{g={location:{points:[]}};for(let t=0;t<4;++t)g.location.points.push({x:Math.round(e[t].x/100*i),y:Math.round(e[t].y/100*s)})}}else g=JSON.parse(JSON.stringify(g)),delete g.regionMeasuredByPercentage;if(g){let e=g.location.points;n=e[0].x,c=e[0].y,o=e[1].x,d=e[1].y,a=e[2].x,h=e[2].y,l=e[3].x,u=e[3].y}if(this._cvsDrawArea){this._cvsDrawArea.style.objectFit=t;let r=this._cvsDrawArea;r.width=i,r.height=s;let _=r.getContext("2d");if(g){_.fillStyle=this.regionMaskFillStyle,_.fillRect(0,0,r.width,r.height);let e=Math.round(this.regionMaskLineWidth/2),t=(t,i,s,r,n,o)=>(-(s-t)*e/Math.hypot(s-t,r-i)-(n-t)*e/Math.hypot(n-t,o-i))/2+t,i=(t,i,s,r,n,o)=>(-(r-i)*e/Math.hypot(s-t,r-i)-(o-i)*e/Math.hypot(n-t,o-i))/2+i;_.globalCompositeOperation="destination-out",_.fillStyle="#000",_.beginPath(),_.moveTo(t(n,c,o,d,l,u),i(n,c,o,d,l,u)),_.lineTo(t(o,d,n,c,a,h),i(o,d,n,c,a,h)),_.lineTo(t(a,h,o,d,l,u),i(a,h,o,d,l,u)),_.lineTo(t(l,u,a,h,n,c),i(l,u,a,h,n,c)),_.fill(),_.globalCompositeOperation="source-over",_.strokeStyle=this.regionMaskStrokeStyle,_.lineWidth=this.regionMaskLineWidth,_.beginPath(),_.moveTo(n,c),_.lineTo(o,d),_.lineTo(a,h),_.lineTo(l,u),_.closePath(),_.stroke()}if(e){_.globalCompositeOperation="destination-over",_.fillStyle=this.highlightFillStyle,_.strokeStyle=this.highlightStrokeStyle,_.lineWidth=this.highlightLineWidth,e=e||[];for(let t of e)for(let e of t.lineResults){let t=e.location.points;_.beginPath(),_.moveTo(t[0].x,t[0].y),_.lineTo(t[1].x,t[1].y),_.lineTo(t[2].x,t[2].y),_.lineTo(t[3].x,t[3].y),_.fill(),_.beginPath(),_.moveTo(t[0].x,t[0].y),_.lineTo(t[1].x,t[1].y),_.lineTo(t[2].x,t[2].y),_.lineTo(t[3].x,t[3].y),_.closePath(),_.stroke()}}this.singleFrameMode&&(_.globalCompositeOperation="destination-over",_.drawImage(this.oriCanvas,0,0))}if(this._divScanArea&&this.dce.video){let e=this.dce.video.offsetWidth,t=this.dce.video.offsetHeight,r=1;e/t<i/s?(r=e/i,this._divScanArea.style.left="0",this._divScanArea.style.top=Math.round((t-s*r)/2)+"px"):(r=t/s,this._divScanArea.style.left=Math.round((e-i*r)/2)+"px",this._divScanArea.style.top="0");let _=g?Math.round(Math.min(n,o,a,l)*r):0,f=g?Math.round(Math.min(c,d,h,u)*r):0,m=g?Math.round(Math.max(n,o,a,l)*r-_):Math.round(i*r),p=g?Math.round(Math.max(c,d,h,u)*r-f):Math.round(s*r);this._divScanArea.style.marginLeft=_+"px",this._divScanArea.style.marginTop=f+"px",this._divScanArea.style.width=m+"px",this._divScanArea.style.height=p+"px"}}_clearRegionsults(){this._cvsDrawArea&&(this._cvsDrawArea.width=this._cvsDrawArea.height=0)}startScanning(e){return t(this,void 0,void 0,(function*(){if("closed"!=this._tempSolutionStatus)return;if(this._tempSolutionStatus="opening",!this.dce)throw new Error("Need to set 'cameraEnhancer' first.");if("opening"!=this._tempSolutionStatus)return;this._bindUI(),e&&this._show();let t=yield this.dce.play();return"opening"==this._tempSolutionStatus?(this._bPauseScan=!1,this.singleFrameMode||(this._loopReadVideo(),this._drawRegionsults()),this._tempSolutionStatus="opened",t):void 0}))}stopScanning(e){this.stop(),this._unbindUI(),this.dce&&this.dce.stopFetchingLoop(),this._bPauseScan=!0,e&&this.dce&&(this.dce.getUIElement().style.display="none"),this._tempSolutionStatus="closed"}pauseScanning(){this.dce&&this.dce.stopFetchingLoop(),this._bPauseScan=!0,this._clearRegionsults(),this._divScanLight&&(this._divScanLight.style.display="none")}resumeScanning(){this._assertOpen(),this._bPauseScan=!1}destroyContext(){if(!this.bDestroyed)return l._onLog&&l._onLog("destroy()"),this.bDestroyed=!0,(this.dce||"opening"===this._tempSolutionStatus)&&this.stopScanning(),new Promise(((e,t)=>{let i=l._nextTaskID++;l._taskCallbackMap.set(i,(i=>{if(i.success)return e();{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),l._dlrWorker.postMessage({type:"destroy",id:i,instanceID:this._instanceID})}))}}var c,d;l._jsVersion="2.2.2",l._jsEditVersion="20220302",l._version="loading...(JS "+l._jsVersion+"."+l._jsEditVersion+")",l._license=n||o||!document.currentScript?"":document.currentScript.getAttribute("data-license")||"",l._sessionPassword=n||o||!document.currentScript?"":document.currentScript.getAttribute("data-sessionPassword")||"",l.browserInfo=function(){if(!n&&!o){var e={init:function(){this.browser=this.searchString(this.dataBrowser)||"unknownBrowser",this.version=this.searchVersion(navigator.userAgent)||this.searchVersion(navigator.appVersion)||"unknownVersion",this.OS=this.searchString(this.dataOS)||"unknownOS","Linux"==this.OS&&-1!=navigator.userAgent.indexOf("Windows NT")&&(this.OS="HarmonyOS")},searchString:function(e){for(var t=0;t<e.length;t++){var i=e[t].string,s=e[t].prop;if(this.versionSearchString=e[t].versionSearch||e[t].identity,i){if(-1!=i.indexOf(e[t].subString))return e[t].identity}else if(s)return e[t].identity}},searchVersion:function(e){var t=e.indexOf(this.versionSearchString);if(-1!=t)return parseFloat(e.substring(t+this.versionSearchString.length+1))},dataBrowser:[{string:navigator.userAgent,subString:"Edge",identity:"Edge"},{string:navigator.userAgent,subString:"OPR",identity:"OPR"},{string:navigator.userAgent,subString:"Chrome",identity:"Chrome"},{string:navigator.vendor,subString:"Apple",identity:"Safari",versionSearch:"Version"},{string:navigator.userAgent,subString:"Firefox",identity:"Firefox"},{string:navigator.userAgent,subString:"MSIE",identity:"Explorer",versionSearch:"MSIE"}],dataOS:[{string:navigator.userAgent,subString:"HarmonyOS",identity:"HarmonyOS"},{string:navigator.userAgent,subString:"Android",identity:"Android"},{string:navigator.userAgent,subString:"iPhone",identity:"iPhone"},{string:navigator.platform,subString:"Win",identity:"Windows"},{string:navigator.platform,subString:"Mac",identity:"Mac"},{string:navigator.platform,subString:"Linux",identity:"Linux"}]};return e.init(),{browser:e.browser,version:e.version,OS:e.OS}}if(o)return{browser:"ssr",version:0,OS:"ssr"};if(n){const e={browser:"node",version:process.version.substring(1),OS:"loading"};return(()=>{t(this,void 0,void 0,(function*(){const t=yield import("os");e.OS=t&&t.platform?t.platform()+t.release():"Unknown"}))})(),e}}(),l._workerName="dlr-"+l._jsVersion+".worker.js",l._engineResourcePath=(()=>{if(n)return __dirname+"/";if(!o&&document.currentScript){let e=document.currentScript.src,t=e.indexOf("?");if(-1!=t)e=e.substring(0,t);else{let t=e.indexOf("#");-1!=t&&(e=e.substring(0,t))}return e.substring(0,e.lastIndexOf("/")+1)}return"./"})(),l._licenseServer=[],l._deviceFriendlyName="",l._isShowRelRecognizeTimeInResults=!1,l._bWasmDebug=!1,l._bNeverShowDialog=!1,l._nextTaskID=0,l._taskCallbackMap=new Map,l._loadWasmStatus="unload",l._loadWasmCallbackArr=[],l.onResourcesLoadStarted=null,l.onResourcesLoadProgress=null,l.onResourcesLoaded=null,l._lastErrorCode=0,l._lastErrorString="",l._defaultUIElementURL="@engineResourcePath/dlr.ui.html",l._loadWasmErr=null,e.EnumDLRGrayscaleTransformationMode=void 0,(c=e.EnumDLRGrayscaleTransformationMode||(e.EnumDLRGrayscaleTransformationMode={}))[c.GTM_INVERTED=1]="GTM_INVERTED",c[c.GTM_ORIGINAL=2]="GTM_ORIGINAL",c[c.GTM_AUTO=4]="GTM_AUTO",c[c.GTM_REV=2147483648]="GTM_REV",c[c.GTM_SKIP=0]="GTM_SKIP",e.EnumDLRRegionPredetectionMode=void 0,(d=e.EnumDLRRegionPredetectionMode||(e.EnumDLRRegionPredetectionMode={}))[d.RPM_AUTO=1]="RPM_AUTO",d[d.RPM_GENERAL=2]="RPM_GENERAL",d[d.RPM_GENERAL_RGB_CONTRAST=4]="RPM_GENERAL_RGB_CONTRAST",d[d.RPM_GENERAL_GRAY_CONTRAST=8]="RPM_GENERAL_GRAY_CONTRAST",d[d.RPM_GENERAL_HSV_CONTRAST=16]="RPM_GENERAL_HSV_CONTRAST",d[d.RPM_REV=2147483648]="RPM_REV",d[d.RPM_SKIP=0]="RPM_SKIP",e.LabelRecognizer=l,Object.defineProperty(e,"__esModule",{value:!0})}));
/// <reference types="node" />
import { DLRResult } from "../interface/dlrresult";
import { DLRLineResult } from "../interface/dlrlineresult";
import { DLRRuntimeSettings } from "../interface/dlrruntimesettings";

@@ -46,3 +47,3 @@ import { EnumDLRImagePixelFormat } from "../enum/enumdlrimagepixelformat";

* ```html
* <script src="https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.1/dist/dlr.js" data-license="LICENSE"></script>
* <script src="https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.2/dist/dlr.js" data-license="LICENSE"></script>
* ```

@@ -82,3 +83,3 @@ */

* ```js
* Dynamsoft.DLR.LabelRecognizer.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.1/dist/";
* Dynamsoft.DLR.LabelRecognizer.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.2/dist/";
* await Dynamsoft.DLR.LabelRecognizer.loadWasm();

@@ -117,13 +118,26 @@ * ```

/**
* Fire when resources loaded.
* @see [[onResourcesLoadStarted]]
* Fire when resources start loading.
* @see [[onResourcesLoadProgress]]
* @see [[onResourcesLoaded]]
* @param resourcesPath The path of resources
*/
static onResourcesLoaded: (resourcesPath: string) => {};
static onResourcesLoadStarted: (resourcesPath?: string) => void;
/**
* Fire when resources start loading.
* Fire when resources progress.
* @see [[onResourcesLoadStarted]]
* @see [[onResourcesLoaded]]
* @param resourcesPath The path of resources
* @param progress The download progress of resources
*/
static onResourcesLoadStarted: (resourcesPath: string) => {};
static onResourcesLoadProgress: (resourcesPath?: string, progress?: {
loaded: number;
total: number;
}) => void;
/**
* Fire when resources loaded.
* @see [[onResourcesLoadStarted]]
* @see [[onResourcesLoadProgress]]
* @param resourcesPath The path of resources
*/
static onResourcesLoaded: (resourcesPath?: string) => void;
/** @ignore */

@@ -677,3 +691,4 @@ _instanceID: number;

*/
onUniqueRead?: (txt: string, result: DLRResult[]) => void;
onUniqueRead?: (txt: string, result: DLRLineResult) => void;
onMRZRead?: (txt: string, result: DLRLineResult[]) => void;
/**

@@ -680,0 +695,0 @@ * Get current scan settings of the LabelRecognizer object and saves it into a struct.

{
"name": "dynamsoft-label-recognizer",
"version": "2.2.1",
"version": "2.2.2",
"description": "Dynamsoft Label Recognizer (DLR) is an SDK designed to recognize meaningful zonal text or symbols in an image (Label). Common scenarios include price tags in supermarkets, inventory labels in warehouses, VIN codes on car windshields, driver licenses, passports, visas, ID cards, etc.",

@@ -5,0 +5,0 @@ "files": [

@@ -5,3 +5,3 @@ # Dynamsoft Label Recognizer for Your Website

[![](https://img.shields.io/badge/Download-Offline%20SDK-orange)](https://www.dynamsoft.com/survey/dlr/?utm_source=zip&product=dlr&package=js)
[![](https://img.shields.io/badge/Download-Offline%20SDK-orange)](https://www.dynamsoft.com/survey/dlr/?utm_source=npm&product=dlr&package=js)

@@ -12,3 +12,3 @@ Once integrated, your users can open your website in a browser, access their cameras, and read the intended text directly from the video input.

[TEST THE LIBRARY](https://www.dynamsoft.com/survey/dlr/?utm_source=zip&product=dlr&package=js)
[GET THE LIBRARY](https://www.dynamsoft.com/survey/dlr/?utm_source=npm&product=dlr&package=js)

@@ -29,3 +29,3 @@ **Table of Contents**

* [API reference](https://www.dynamsoft.com/label-recognition/programming/javascript/api-reference/?ver=latest&utm_source=zip&product=dlr&package=js)
* [API reference](https://www.dynamsoft.com/label-recognition/programming/javascript/api-reference/?ver=latest&utm_source=npm&product=dlr&package=js)

@@ -50,4 +50,4 @@ ## Hello World - Simplest Implementation

<body>
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.1/dist/dlr.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@2.0.3/dist/dce.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.2/dist/dlr.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@2.0.3/dist/dce.js"></script>
<script>

@@ -57,4 +57,11 @@ // initializes and uses the library

Dynamsoft.DCE.CameraEnhancer.defaultUIElementURL = Dynamsoft.DLR.LabelRecognizer.defaultUIElementURL;
let enhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
let cameraEnhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
Dynamsoft.DLR.LabelRecognizer.onResourcesLoadStarted = (resourcePath) => {
console.log("Loading " + resourcePath);
// Show a visual cue that a model file is being
};
Dynamsoft.DLR.LabelRecognizer.onResourcesLoaded = (resourcePath) => {
console.log("Finished loading " + resourcePath);
// Hide the visual cue
};
let recognizer = await Dynamsoft.DLR.LabelRecognizer.createInstance({

@@ -73,3 +80,3 @@ runtimeSettings: "video-letter"

};
recognizer.cameraEnhancer = enhancer;
recognizer.cameraEnhancer = cameraEnhancer;
await recognizer.startScanning(true);

@@ -83,2 +90,22 @@ })();

<p align="center" style="text-align:center; ">
<!--<a target="_blank" href="https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/master/1.hello-world/1.minimum-code.html" title="Code in Github">
<img src="https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/github.svg" alt="Code in Github" style="width:20px;height:20px;">
</a>
&nbsp; -->
<a target="_blank" href="https://jsfiddle.net/DynamsoftTeam/b1w8vm0t/" title="Run via JSFiddle">
<img src="https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/jsfiddle.svg" alt="Run via JSFiddle" width="20" height="20" style="width:20px;height:20px;">
</a>
<!--&nbsp;
<a target="_blank" href="https://demo.dynamsoft.com/Samples/DBR/JS/1.hello-world/1.minimum-code.html?utm_source=npm" title="Run in Dynamsoft">
<img src="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.0.0/svgs/solid/circle-play.svg" alt="Run in Dynamsoft" style="width:20px;height:20px;">
</a>
&nbsp;
<a target="_blank" href="https://tst.dynamsoft.com/public/download/dbr/browser/code/helloworld-v8.8.7.zip?utm_source=npm" title="Download from Dynamsoft">
<img src="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.0.0/svgs/solid/download.svg" alt="Download from Dynamsoft" style="width:20px;height:20px; ">
</a>-->
</p>
-----
*About the code*

@@ -88,3 +115,3 @@

+ `CameraEnhancer.createInstance()`: this method creates a `CameraEnhancer` object called `enhancer` which is used to control the camera as well as the default user interface. To use `enhancer` with `recognizer`, we pass to it the customized UI provided by the Dynamsoft Label Recognizer SDK and then bind it to `recognizer` to allow the latter to fetch frames from the camera for recognition as well as highlight the recognized text areas.
+ `CameraEnhancer.createInstance()`: this method creates a `CameraEnhancer` object called `cameraEnhancer` which is used to control the camera as well as the default user interface. To use `cameraEnhancer` with `recognizer`, we pass to it the customized UI provided by the Dynamsoft Label Recognizer SDK and then bind it to `recognizer` to allow the latter to fetch frames from the camera for recognition as well as highlight the recognized text areas.

@@ -95,3 +122,3 @@ + `onFrameRead`: This event is triggered every time the library finishes scanning a video frame. The `results` object contains all the text results that the library has found on this frame. In this example, we print the results to the browser console.

+ `startScanning(true)`: Starts contious video frame scanning. The return value is a Promise which resovles when the camera is opened, the video shows up on the page and the scanning begins (which means `enhancer` has started feeding `recognizer` with frames to recognize).
+ `startScanning(true)`: Starts contious video frame scanning. The return value is a Promise which resovles when the camera is opened, the video shows up on the page and the scanning begins (which means `cameraEnhancer` has started feeding `recognizer` with frames to recognize).

@@ -110,9 +137,11 @@ ### Step Two: Test the example

+ The library requires a license to work. However, when no license is specified in the code, Dynamsoft allows a [7-day free period](https://www.dynamsoft.com/license-server/docs/about/terms.html?ver=latest#public-trial-license?utm_source=zip&product=dlr&package=js) during which you can make initial evaluation of the library to decide whether or not you want to evaluate it further. If you do, you can [request a trial](#requesting-a-trial).
> Network connection is required for the 7-day free license to work.
+ The library requires a license to work. However, when no license is specified in the code, a [free public trial license](https://www.dynamsoft.com/license-server/docs/about/terms.html?ver=latest#public-trial-license?utm_source=npm&product=dlr&package=js) will be applied. You can make initial evaluation of the library to decide whether or not you want to evaluate it further. If you do want more evaluation time, you can [request a trial](#requesting-a-trial).
> Network connection is required for the free public trial license to work.
If the test doesn't go as expected, you can check out the [FAQ](#faq) or [contact us](https://www.dynamsoft.com/company/contact/?utm_source=zip&product=dlr&package=js).
If the test doesn't go as expected, you can check out the [FAQ](#faq) or [contact us](https://www.dynamsoft.com/company/contact/?utm_source=npm&product=dlr&package=js).
## Building your own page
We'll show all the steps required to build a web page for reading machine-readable zones (MRZ) on passports, visas, etc.
### Include the library

@@ -127,3 +156,3 @@

```html
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.1/dist/dlr.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.2/dist/dlr.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@2.0.3/dist/dce.js"></script>

@@ -135,3 +164,3 @@ ```

```html
<script src="https://unpkg.com/dynamsoft-label-recognizer@2.2.1/dist/dlr.js"></script>
<script src="https://unpkg.com/dynamsoft-label-recognizer@2.2.2/dist/dlr.js"></script>
<script src="https://unpkg.com/dynamsoft-camera-enhancer@2.0.3/dist/dce.js"></script>

@@ -148,3 +177,3 @@ ```

[Download the JavaScript Package](https://www.dynamsoft.com/survey/dlr/?utm_source=zip&product=dlr&package=js)
[Download the JavaScript Package](https://www.dynamsoft.com/survey/dlr/?utm_source=npm&product=dlr&package=js)

@@ -163,3 +192,3 @@ > NOTE that the package contains the library Dynamsoft Camera Enhancer

```
$ npm install dynamsoft-label-recognizer@2.2.1 --save
$ npm install dynamsoft-label-recognizer@2.2.2 --save
$ npm install dynamsoft-camera-enhancer@2.0.3 --save

@@ -171,4 +200,4 @@ ```

```html
<script src="/dlr-js-2.2.1/dist/dlr.js"></script>
<script src="/dlr-js-2.2.1/dce/dist/dce.js"></script>
<script src="/dlr-js-2.2.2/dist/dlr.js"></script>
<script src="/dlr-js-2.2.2/dce/dist/dce.js"></script>
```

@@ -191,8 +220,7 @@

The library requires a license to work, use the API `initLicense()` to specify the license.
The library requires a license to work, use the API `license` to specify the license.
```javascript
// The following line uses a public trial license (valid for 7 days) which is equivalent to not setting any license.
Dynamsoft.DLR.LabelRecognizer.initlicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9");
Dynamsoft.DLR.LabelRecognizer.license =
"YOUR-ORGANIZATION-ID or YOUR-HANDSHAKECODE or AN-OFFLINE-LICENSE or ANY-OTHER-TYPE-OF-SUPPORTED-LICENSE-STRING";
```

@@ -202,10 +230,9 @@

* By default, network connection is required for the license to work.
* If nothing is specified, a [7-day free license](https://www.dynamsoft.com/license-server/docs/about/terms.html?ver=latest#public-trial-license?utm_source=zip&product=dlr&package=js) will be used by default which is the case in the above "hello world" example.
* The license is actually fetched during the creation of a `LabelRecognizer` instance.
* If a public network connection is not available, you can choose to host a license server in your private network or apply for an offline license. [Contact us](https://www.dynamsoft.com/company/contact/?utm_source=zip&product=dlr&package=js) for more information.
* When specified by YOUR-ORGANIZATION-ID or YOUR-HANDSHAKECODE, the license is an online license and a network connection to Dynamsoft License Server is required for it to work.
* In most cases, online licenses are offered. If you want to use an offline license, you can [contact us](https://www.dynamsoft.com/company/contact/?utm_source=npm).
* If nothing is specified like the above "hello world" example, a [free public trial license](https://www.dynamsoft.com/company/contact/?utm_source=npm&product=dlr&package=js) will be automatically used. This license requires a network connection.
#### Specify the location of the "engine" files
The "engine" files refer to *.worker.js, *.wasm.js and *.wasm, etc. which are loaded by the main library at runtime. This configuration option uses the API `engineResourcePath` and is often not required as these files usually are in the same location with the main library file (dlr.js). However, in cases where the engine files are not in the same location as the main library file (for example, with frameworks like Angular or React, dlr.js is compiled into another file), this configuration will be required.
The "engine" files refer to *.worker.js, *.wasm.js and *.wasm, etc. which are loaded by the main library at runtime as well as model files (\*.data) which are necessary for the recognition of specific types of text. This configuration option uses the API `engineResourcePath` and is often not required as these files usually are in the same location with the main library file (dlr.js). However, in cases where the engine files are not in the same location as the main library file (for example, with frameworks like Angular or React, dlr.js is compiled into another file), this configuration will be required.

@@ -215,6 +242,25 @@ The following code uses the jsDelivr CDN, feel free to change it to your own location of these files.

```javascript
Dynamsoft.DLR.LabelRecognizer.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.1/dist/";
Dynamsoft.DLR.LabelRecognizer.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.2/dist/";
Dynamsoft.DCE.CameraEnhancer.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@2.0.3/dist/";
```
#### Add a visual cue about the loading of a .data file
The .data files are crucial for the recognition of certain types of text. For example, to read the MRZ zone on passports, the file MRZ.data must be loaded first. These .data files are loaded from the server on demand at runtime. At present, these files are quite large, for example, MRZ.data is about 10MB. Although these files are cached locally as soon as they are downloaded, loading them for the first time can be quite time-consuming. To make the process user-friendly, it's recommended to show a visual cue about the loading process to the user with the help of the APIs `onResourcesLoadStarted`, `onResourcesLoadProgress` and `onResourcesLoaded` :
```js
Dynamsoft.DLR.LabelRecognizer.onResourcesLoadStarted = (resourcePath) => {
console.log("Loading " + resourcePath);
// Show a visual cue that a model file is being
}
Dynamsoft.DLR.LabelRecognizer.onResourcesLoadProgress = (resourcePath, progress) => {
console.log(resourcePath + "loading progress: " + progress.loaded + "/" + progress.total);
// Show the progress
}
Dynamsoft.DLR.LabelRecognizer.onResourcesLoaded = (resourcePath) => {
console.log("Finished loading " + resourcePath);
// Hide the visual cue
}
```
### Interact with the library

@@ -229,5 +275,3 @@

try {
recognizer = await Dynamsoft.DLR.LabelRecognizer.createInstance({
runtimeSettings: "video-letter"
});
recognizer = await Dynamsoft.DLR.LabelRecognizer.createInstance();
} catch (ex) {

@@ -248,4 +292,4 @@ console.error(ex);

Dynamsoft.DCE.CameraEnhancer.defaultUIElementURL = Dynamsoft.DLR.LabelRecognizer.defaultUIElementURL;
let enhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
recognizer.cameraEnhancer = enhancer;
let cameraEnhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
recognizer.cameraEnhancer = cameraEnhancer;
```

@@ -255,9 +299,9 @@

In some cases, a different camera might be required instead of the default one. Also, a different resolution might work better. To change the camera or the resolution, we use the `CameraEnhancer` object. Learn more [here](https://www.dynamsoft.com/camera-enhancer/docs/programming/javascript/api-reference/camera-control.html?ver=latest&utm_source=zip&product=dlr&package=js).
In some cases, a different camera might be required instead of the default one. Also, a different resolution might work better. To change the camera or the resolution, we use the `CameraEnhancer` object. Learn more [here](https://www.dynamsoft.com/camera-enhancer/docs/programming/javascript/api-reference/camera-control.html?ver=latest&utm_source=npm&product=dlr&package=js).
```javascript
// set which camera and what resolution to use
let allCameras = await enhancer.getAllCameras();
await enhancer.selectCamera(allCameras[0]);
await enhancer.setResolution(1280, 720);
let allCameras = await cameraEnhancer.getAllCameras();
await cameraEnhancer.selectCamera(allCameras[0]);
await cameraEnhancer.setResolution(1280, 720);
```

@@ -272,5 +316,5 @@

// disregard duplicated results found in a specified time period (in milliseconds)
scanSettings.duplicateForgetTime = 5000;
scanSettings.duplicateForgetTime = 6000;
// set a scan interval in milliseconds so the library may release the CPU from time to time
scanSettings.intervalTime = 300;
scanSettings.intervalTime = 100;
await recognizer.updateScanSettings(scanSettings);

@@ -280,4 +324,8 @@ ```

```javascript
// use one of the built-in RuntimeSetting templates: "number", "letter", "numberLetter", "numberUppercase", "VIN", "passportMRZ", "video-number", "video-letter", "video-numberLetter", "video-numberUppercase", "video-VIN", "video-passportMRZ". For convenience, these names are not case-sensitive. You can also pass in a JSON string as the template.
await recognizer.updateRuntimeSettingsFromString("video-passportMRZ");
// use one of the built-in RuntimeSetting templates:
// "number", "letter", "numberLetter", "numberUppercase", "VIN", "MRZ",
// "video-number", "video-letter", "video-numberLetter", "video-numberUppercase", "video-VIN", "video-MRZ".
// For convenience, these names are not case-sensitive.
// You can also pass in a JSON string as the template.
await recognizer.updateRuntimeSettingsFromString("video-MRZ");
```

@@ -312,4 +360,4 @@

```javascript
await enhancer.setUIElement(Dynamsoft.DLR.LabelRecognizer.defaultUIElementURL);
document.getElementById('recognizerUI').appendChild(enhancer.getUIElement());
await cameraEnhancer.setUIElement(Dynamsoft.DLR.LabelRecognizer.defaultUIElementURL);
document.getElementById('recognizerUI').appendChild(cameraEnhancer.getUIElement());
document.getElementsByClassName('dce-btn-close')[0].hidden = true; // Hide the close button

@@ -330,6 +378,5 @@ ```

await cameraEnhancer.setUIElement(document.getElementById('div-video-container'));
let recognizer = await Dynamsoft.DLR.LabelRecognizer.createInstance({
runtimeSettings: "video-passportMRZ"
});
let recognizer = await Dynamsoft.DLR.LabelRecognizer.createInstance();
recognizer.cameraEnhancer = cameraEnhancer;
await recognizer.updateRuntimeSettingsFromString("video-MRZ");
recognizer.onFrameRead = results => {

@@ -342,3 +389,3 @@ for (let result of results) {

};
recognizer.onUniqueRead = (txt, results) => {
recognizer.onMRZRead = (txt, results) => {
alert(txt);

@@ -379,9 +426,9 @@ };

If no license is specified, a [7-day free license](https://www.dynamsoft.com/license-server/docs/about/terms.html?ver=latest#public-trial-license?utm_source=zip&product=dlr&package=js) will be used by default.
If no license is specified, a [free public trial license](https://www.dynamsoft.com/license-server/docs/about/terms.html?ver=latest#public-trial-license?utm_source=npm&product=dlr&package=js) will be used by default.
> Network connection is required for the 7-day free license to work.
> Network connection is required for the free public trial license to work.
After that, if you want to evaluate the library further, you can [register for a Dynamsoft account](https://www.dynamsoft.com/api-common/Regist/Regist?utm_source=zip&product=dlr&package=js) (if you haven't already done so) and request a 30-day trial in the [customer portal](https://www.dynamsoft.com/customer/license/trialLicense?utm_source=zip&product=dlr&package=js).
After that, if you want to evaluate the library further, you can [register for a Dynamsoft account](https://www.dynamsoft.com/api-common/Regist/Regist?utm_source=npm&product=dlr&package=js) (if you haven't already done so) and request a 30-day trial in the [customer portal](https://www.dynamsoft.com/customer/license/trialLicense?utm_source=npm&product=dlr&package=js).
* If you like, you can also [contact our support team](https://www.dynamsoft.com/company/contact/?utm_source=zip&product=dlr&package=js) to get a trial license.
* If you like, you can also [contact our support team](https://www.dynamsoft.com/company/contact/?utm_source=npm&product=dlr&package=js) to get a trial license.

@@ -392,3 +439,3 @@ ## System Requirements

* `WebAssembly`, `Blob`, `URL`/`createObjectURL`, `Web Workers`
* `WebAssembly`, `Blob`, `URL`/`createObjectURL`, `Web Workers`

@@ -399,3 +446,3 @@ The above four features are required for the library to work.

This API is only required for in-browser video streaming. If a browser does not support this API, the [Single Frame Mode](https://www.dynamsoft.com/label-recognition/programming/javascript/api-reference/ui.html?ver=latest&utm_source=zip&product=dlr&package=js#singleframemode) will be used automatically. If the API exists but doesn't work correctly, the Single Frame Mode can be used as an alternative way to access the camera.
This API is only required for in-browser video streaming. If a browser does not support this API, the [Single Frame Mode](https://www.dynamsoft.com/label-recognition/programming/javascript/api-reference/ui.html?ver=latest&utm_source=npm&product=dlr&package=js#singleframemode) will be used automatically. If the API exists but doesn't work correctly, the Single Frame Mode can be used as an alternative way to access the camera.

@@ -466,3 +513,3 @@ The following table is a list of supported browsers based on the above requirements:

Yes, for simple testing purposes, it's perfectly fine to open the file directly from the hard drive. However, you might encounter some issues in doing so (like unable to access the camera, etc.). The recommendation is to deploy this page to your web server and run it over **HTTPS**. If you don't have a ready-to-use web server but have a package manager like *npm* or *yarn*, you can set up a simple HTTP server in minutes. Check out [ `http-server` on npm](https://www.npmjs.com/package/http-server) or [yarn](https://yarnpkg.com/package/http-server).
Yes, for simple testing purposes, it's perfectly fine to open the file directly from the hard drive. However, you might encounter some issues in doing so (like unable to access the camera, etc.). The recommendation is to deploy this page to your web server and run it over **HTTPS**. If you don't have a ready-to-use web server but have a package manager like *npm* or *yarn*, you can set up a simple HTTP server in minutes. Check out [http-server on npm](https://www.npmjs.com/package/http-server).

@@ -469,0 +516,0 @@ ### Why can't I use my camera?

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc