dwt
Version:
Dynamic Web TWAIN is a TWAIN/ICA/SANE-based scanning SDK software specifically designed for web applications running on Windows/macOS/Linux. With just a few lines of code, you can develop robust applications to scan documents from TWAIN/ICA/SANE-compatibl
22 lines • 105 kB
JavaScript
/*!
* Dynamsoft JavaScript Library
* @product Dynamsoft Barcode Reader JS Edition
* @website http://www.dynamsoft.com
* @copyright Copyright 2022, Dynamsoft Corporation
* @author Dynamsoft
* @version 8.8.7 (js 20220125)
* @fileoverview Dynamsoft JavaScript Library for Barcode Reader
* More info on DBR JS: https://www.dynamsoft.com/barcode-reader/sdk-javascript/
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).Dynamsoft=e.Dynamsoft||{},e.Dynamsoft.DBR=t())}(this,(function(){"use strict";function e(e,t,i,n){return new(i||(i=Promise))((function(s,r){function o(e){try{d(n.next(e))}catch(e){r(e)}}function a(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}d((n=n.apply(e,t||[])).next())}))}var t,i,n,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.DBR_SYSTEM_EXCEPTION=1]="DBR_SYSTEM_EXCEPTION",e[e.DBR_SUCCESS=0]="DBR_SUCCESS",e[e.DBR_UNKNOWN=-1e4]="DBR_UNKNOWN",e[e.DBR_NO_MEMORY=-10001]="DBR_NO_MEMORY",e[e.DBR_NULL_REFERENCE=-10002]="DBR_NULL_REFERENCE",e[e.DBR_LICENSE_INVALID=-10003]="DBR_LICENSE_INVALID",e[e.DBR_LICENSE_EXPIRED=-10004]="DBR_LICENSE_EXPIRED",e[e.DBR_FILE_NOT_FOUND=-10005]="DBR_FILE_NOT_FOUND",e[e.DBR_FILETYPE_NOT_SUPPORTED=-10006]="DBR_FILETYPE_NOT_SUPPORTED",e[e.DBR_BPP_NOT_SUPPORTED=-10007]="DBR_BPP_NOT_SUPPORTED",e[e.DBR_INDEX_INVALID=-10008]="DBR_INDEX_INVALID",e[e.DBR_BARCODE_FORMAT_INVALID=-10009]="DBR_BARCODE_FORMAT_INVALID",e[e.DBR_CUSTOM_REGION_INVALID=-10010]="DBR_CUSTOM_REGION_INVALID",e[e.DBR_MAX_BARCODE_NUMBER_INVALID=-10011]="DBR_MAX_BARCODE_NUMBER_INVALID",e[e.DBR_IMAGE_READ_FAILED=-10012]="DBR_IMAGE_READ_FAILED",e[e.DBR_TIFF_READ_FAILED=-10013]="DBR_TIFF_READ_FAILED",e[e.DBR_QR_LICENSE_INVALID=-10016]="DBR_QR_LICENSE_INVALID",e[e.DBR_1D_LICENSE_INVALID=-10017]="DBR_1D_LICENSE_INVALID",e[e.DBR_DIB_BUFFER_INVALID=-10018]="DBR_DIB_BUFFER_INVALID",e[e.DBR_PDF417_LICENSE_INVALID=-10019]="DBR_PDF417_LICENSE_INVALID",e[e.DBR_DATAMATRIX_LICENSE_INVALID=-10020]="DBR_DATAMATRIX_LICENSE_INVALID",e[e.DBR_PDF_READ_FAILED=-10021]="DBR_PDF_READ_FAILED",e[e.DBR_PDF_DLL_MISSING=-10022]="DBR_PDF_DLL_MISSING",e[e.DBR_PAGE_NUMBER_INVALID=-10023]="DBR_PAGE_NUMBER_INVALID",e[e.DBR_CUSTOM_SIZE_INVALID=-10024]="DBR_CUSTOM_SIZE_INVALID",e[e.DBR_CUSTOM_MODULESIZE_INVALID=-10025]="DBR_CUSTOM_MODULESIZE_INVALID",e[e.DBR_RECOGNITION_TIMEOUT=-10026]="DBR_RECOGNITION_TIMEOUT",e[e.DBR_JSON_PARSE_FAILED=-10030]="DBR_JSON_PARSE_FAILED",e[e.DBR_JSON_TYPE_INVALID=-10031]="DBR_JSON_TYPE_INVALID",e[e.DBR_JSON_KEY_INVALID=-10032]="DBR_JSON_KEY_INVALID",e[e.DBR_JSON_VALUE_INVALID=-10033]="DBR_JSON_VALUE_INVALID",e[e.DBR_JSON_NAME_KEY_MISSING=-10034]="DBR_JSON_NAME_KEY_MISSING",e[e.DBR_JSON_NAME_VALUE_DUPLICATED=-10035]="DBR_JSON_NAME_VALUE_DUPLICATED",e[e.DBR_TEMPLATE_NAME_INVALID=-10036]="DBR_TEMPLATE_NAME_INVALID",e[e.DBR_JSON_NAME_REFERENCE_INVALID=-10037]="DBR_JSON_NAME_REFERENCE_INVALID",e[e.DBR_PARAMETER_VALUE_INVALID=-10038]="DBR_PARAMETER_VALUE_INVALID",e[e.DBR_DOMAIN_NOT_MATCHED=-10039]="DBR_DOMAIN_NOT_MATCHED",e[e.DBR_RESERVEDINFO_NOT_MATCHED=-10040]="DBR_RESERVEDINFO_NOT_MATCHED",e[e.DBR_AZTEC_LICENSE_INVALID=-10041]="DBR_AZTEC_LICENSE_INVALID",e[e.DBR_LICENSE_DLL_MISSING=-10042]="DBR_LICENSE_DLL_MISSING",e[e.DBR_LICENSEKEY_NOT_MATCHED=-10043]="DBR_LICENSEKEY_NOT_MATCHED",e[e.DBR_REQUESTED_FAILED=-10044]="DBR_REQUESTED_FAILED",e[e.DBR_LICENSE_INIT_FAILED=-10045]="DBR_LICENSE_INIT_FAILED",e[e.DBR_PATCHCODE_LICENSE_INVALID=-10046]="DBR_PATCHCODE_LICENSE_INVALID",e[e.DBR_POSTALCODE_LICENSE_INVALID=-10047]="DBR_POSTALCODE_LICENSE_INVALID",e[e.DBR_DPM_LICENSE_INVALID=-10048]="DBR_DPM_LICENSE_INVALID",e[e.DBR_FRAME_DECODING_THREAD_EXISTS=-10049]="DBR_FRAME_DECODING_THREAD_EXISTS",e[e.DBR_STOP_DECODING_THREAD_FAILED=-10050]="DBR_STOP_DECODING_THREAD_FAILED",e[e.DBR_SET_MODE_ARGUMENT_ERROR=-10051]="DBR_SET_MODE_ARGUMENT_ERROR",e[e.DBR_LICENSE_CONTENT_INVALID=-10052]="DBR_LICENSE_CONTENT_INVALID",e[e.DBR_LICENSE_KEY_INVALID=-10053]="DBR_LICENSE_KEY_INVALID",e[e.DBR_LICENSE_DEVICE_RUNS_OUT=-10054]="DBR_LICENSE_DEVICE_RUNS_OUT",e[e.DBR_GET_MODE_ARGUMENT_ERROR=-10055]="DBR_GET_MODE_ARGUMENT_ERROR",e[e.DBR_IRT_LICENSE_INVALID=-10056]="DBR_IRT_LICENSE_INVALID",e[e.DBR_MAXICODE_LICENSE_INVALID=-10057]="DBR_MAXICODE_LICENSE_INVALID",e[e.DBR_GS1_DATABAR_LICENSE_INVALID=-10058]="DBR_GS1_DATABAR_LICENSE_INVALID",e[e.DBR_GS1_COMPOSITE_LICENSE_INVALID=-10059]="DBR_GS1_COMPOSITE_LICENSE_INVALID",e[e.DBR_DOTCODE_LICENSE_INVALID=-10061]="DBR_DOTCODE_LICENSE_INVALID",e[e.DMERR_NO_LICENSE=-2e4]="DMERR_NO_LICENSE",e[e.DMERR_LICENSE_SYNC_FAILED=-20003]="DMERR_LICENSE_SYNC_FAILED",e[e.DMERR_TRIAL_LICENSE=-20010]="DMERR_TRIAL_LICENSE",e[e.DMERR_FAILED_TO_REACH_LTS=-20200]="DMERR_FAILED_TO_REACH_LTS"}(i||(i={})),function(e){e[e.IMRDT_IMAGE=1]="IMRDT_IMAGE",e[e.IMRDT_CONTOUR=2]="IMRDT_CONTOUR",e[e.IMRDT_LINESEGMENT=4]="IMRDT_LINESEGMENT",e[e.IMRDT_LOCALIZATIONRESULT=8]="IMRDT_LOCALIZATIONRESULT",e[e.IMRDT_REGIONOFINTEREST=16]="IMRDT_REGIONOFINTEREST",e[e.IMRDT_QUADRILATERAL=32]="IMRDT_QUADRILATERAL"}(n||(n={})),function(e){e[e.BF_ALL=-31457281]="BF_ALL",e[e.BF_ONED=1050623]="BF_ONED",e[e.BF_GS1_DATABAR=260096]="BF_GS1_DATABAR",e[e.BF_CODE_39=1]="BF_CODE_39",e[e.BF_CODE_128=2]="BF_CODE_128",e[e.BF_CODE_93=4]="BF_CODE_93",e[e.BF_CODABAR=8]="BF_CODABAR",e[e.BF_ITF=16]="BF_ITF",e[e.BF_EAN_13=32]="BF_EAN_13",e[e.BF_EAN_8=64]="BF_EAN_8",e[e.BF_UPC_A=128]="BF_UPC_A",e[e.BF_UPC_E=256]="BF_UPC_E",e[e.BF_INDUSTRIAL_25=512]="BF_INDUSTRIAL_25",e[e.BF_CODE_39_EXTENDED=1024]="BF_CODE_39_EXTENDED",e[e.BF_GS1_DATABAR_OMNIDIRECTIONAL=2048]="BF_GS1_DATABAR_OMNIDIRECTIONAL",e[e.BF_GS1_DATABAR_TRUNCATED=4096]="BF_GS1_DATABAR_TRUNCATED",e[e.BF_GS1_DATABAR_STACKED=8192]="BF_GS1_DATABAR_STACKED",e[e.BF_GS1_DATABAR_STACKED_OMNIDIRECTIONAL=16384]="BF_GS1_DATABAR_STACKED_OMNIDIRECTIONAL",e[e.BF_GS1_DATABAR_EXPANDED=32768]="BF_GS1_DATABAR_EXPANDED",e[e.BF_GS1_DATABAR_EXPANDED_STACKED=65536]="BF_GS1_DATABAR_EXPANDED_STACKED",e[e.BF_GS1_DATABAR_LIMITED=131072]="BF_GS1_DATABAR_LIMITED",e[e.BF_PATCHCODE=262144]="BF_PATCHCODE",e[e.BF_PDF417=33554432]="BF_PDF417",e[e.BF_QR_CODE=67108864]="BF_QR_CODE",e[e.BF_DATAMATRIX=134217728]="BF_DATAMATRIX",e[e.BF_AZTEC=268435456]="BF_AZTEC",e[e.BF_MAXICODE=536870912]="BF_MAXICODE",e[e.BF_MICRO_QR=1073741824]="BF_MICRO_QR",e[e.BF_MICRO_PDF417=524288]="BF_MICRO_PDF417",e[e.BF_GS1_COMPOSITE=-2147483648]="BF_GS1_COMPOSITE",e[e.BF_MSI_CODE=1048576]="BF_MSI_CODE",e[e.BF_NULL=0]="BF_NULL"}(s||(s={}));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 d{constructor(){this._canvasMaxWH="iPhone"==d.browserInfo.OS||"Android"==d.browserInfo.OS?2048:4096,this._instanceID=void 0,this.bSaveOriCanvas=!1,this.oriCanvas=null,this.bFilterRegionInJs=!0,this._region=null,this._timeStartDecode=null,this._timeEnterInnerDBR=null,this._timeGetMessage=null,this._bUseWebgl=!0,this.decodeRecords={},this.bDestroyed=!1,this._lastErrorCode=0,this._lastErrorString="",this._lastInnerDecodeDuration=0}static get version(){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.");d._license=e}static get productKeys(){return this._license}static set productKeys(e){d.license=e}static get handshakeCode(){return this._license}static set handshakeCode(e){d.license=e}static get organizationID(){return this._license}static set organizationID(e){d.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.");d._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:!!(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)d._engineResourcePath=e;else{let t=document.createElement("a");t.href=e,d._engineResourcePath=t.href}this._engineResourcePath.endsWith("/")||(d._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)d._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]+="/")}d._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 `createInstance` or `loadWasm` is called.");d._deviceFriendlyName=e||""}static get _bUseFullFeature(){return this.__bUseFullFeature}static set _bUseFullFeature(e){if("unload"!=this._loadWasmStatus)throw new Error("`_bUseFullFeature` is not allowed to change after `createInstance` or `loadWasm` is called.");d.__bUseFullFeature=e}get ifSaveOriginalImageInACanvas(){return this.bSaveOriCanvas}set ifSaveOriginalImageInACanvas(e){this.bSaveOriCanvas=e}getOriginalImageInACanvas(){return this.oriCanvas}set region(e){this._region=e}get region(){return this._region}static isLoaded(){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 loadWasm(){return e(this,void 0,void 0,(function*(){if(r&&process.version<"v12")throw new Error("DBRJS SDK requires nodejs version >= v12.");let t,n=d._license,s=JSON.parse(JSON.stringify(d._licenseServer)),o=d._sessionPassword,l=null,_=null,h=0;if(n.startsWith("t")||n.startsWith("f"))h=0;else if(0===n.length||n.startsWith("P")||n.startsWith("L"))h=1;else{h=2;const e=n.indexOf(":");if(-1!=e&&(n=n.substring(e+1)),n.startsWith("DLS2")){let e=n.substring(4);e=r?Buffer.from(e,"base64").toString("binary"):atob(e);const t=JSON.parse(e);if(t.handshakeCode?n=t.handshakeCode:t.organizationID&&(n=t.organizationID),"number"==typeof n&&(n=JSON.stringify(n)),n||(n=""),0===s.length){let e=[];t.mainServerURL&&(e[0]=t.mainServerURL),t.standbyServerURL&&(e[1]=t.standbyServerURL),d.licenseServer=e,s=d.licenseServer}!o&&t.sessionPassword&&(o=t.sessionPassword),t.chargeWay&&(_=t.chargeWay),t.limitedLicenseModules&&(l=t.limitedLicenseModules)}}if(h&&(r?process.version<"v15"&&(t="To use online key requires nodejs version >= v15."):(a.crypto||(t="Please upgrade your browser to support online key."),a.crypto.subtle||(t="Require https to use online key in this browser."))),t){if(1!==h)throw new Error(t);h=0,console.warn(t),d._lastErrorCode=i.DMERR_FAILED_TO_REACH_LTS,d._lastErrorString=t}return 1===h&&(n="",console.warn("Automatically apply for a public trial license.")),yield new Promise(((t,i)=>e(this,void 0,void 0,(function*(){switch(d._loadWasmStatus){case"unload":{d._loadWasmStatus="loading";let t=d.engineResourcePath+d._workerName;if(r||d.engineResourcePath.startsWith(location.origin)||(t=yield fetch(t).then((e=>e.blob())).then((e=>URL.createObjectURL(e)))),r){const e=yield import("worker_threads");d._dbrWorker=new e.Worker(t)}else d._dbrWorker=new Worker(t);d._dbrWorker.onerror=e=>{d._loadWasmStatus="loadFail";let t=new Error(e.message);d._loadWasmErr=t;for(let e of d._loadWasmCallbackArr)e(t);d._loadWasmCallbackArr=[]},d._dbrWorker.onmessage=t=>e(this,void 0,void 0,(function*(){let e=t.data?t.data:t;switch(e.type){case"log":d._onLog&&d._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-barcode-reader/#javascript)"));let t=!1;if(1===h&&(t=!0),e.success){d._loadWasmStatus="loadSuccess",d._version=e.version+"(JS "+d._jsVersion+"."+d._jsEditVersion+")",d._onLog&&d._onLog("load dbr worker success");for(let e of d._loadWasmCallbackArr)e();d._loadWasmCallbackArr=[],d._dbrWorker.onerror=null,e.message&&console.warn(e.message)}else{let i=new Error(e.message);i.stack=e.stack+"\n"+i.stack,d._loadWasmStatus="loadFail",d._loadWasmErr=i;for(let e of d._loadWasmCallbackArr)e(i);d._loadWasmCallbackArr=[],t||111==e.ltsErrorCode&&-1!=e.message.toLowerCase().indexOf("trial license")&&(t=!0)}t&&d.showDialog(e.success?"warn":"error",e.message);break}case"task":{let t=e.id,i=e.body;try{d._taskCallbackMap.get(t)(i),d._taskCallbackMap.delete(t)}catch(e){throw d._taskCallbackMap.delete(t),e}break}default:d._onLog&&d._onLog(t)}})),r&&d._dbrWorker.on("message",d._dbrWorker.onmessage),d._dbrWorker.postMessage({type:"loadWasm",bd:d._bWasmDebug,engineResourcePath:d.engineResourcePath,version:d._jsVersion,brtk:!!h,bptk:1===h,lcs:n,dm:!r&&location.origin.startsWith("http")?location.origin:"https://localhost",bUseFullFeature:d._bUseFullFeature,browserInfo:d.browserInfo,deviceFriendlyName:d.deviceFriendlyName,ls:s,sp:o,lm:l,cw:_})}case"loading":d._loadWasmCallbackArr.push((e=>{e?i(e):t()}));break;case"loadSuccess":t();break;case"loadFail":i(d._loadWasmErr)}}))))}))}static showDialog(t,i){return e(this,void 0,void 0,(function*(){if(!r&&!d._bNeverShowDialog)try{let e=yield fetch(d.engineResourcePath+"dls.license.dialog.html");if(!e.ok)throw Error("Get license dialog fail. Network Error: "+e.statusText);let n=yield e.text();if(!n.trim().startsWith("<"))throw Error("Get license dialog fail. Can't get valid HTMLElement.");let s=document.createElement("div");s.innerHTML=n;let r=[];for(let e=0;e<s.childElementCount;++e){let t=s.children[e];t instanceof HTMLStyleElement&&(r.push(t),document.head.append(t))}let o=1==s.childElementCount?s.children[0]:s;o.remove();let a,l,_,h,c,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(!_&&e.classList.contains("dls-license-icon-error"))_=e,"error"!=t&&e.remove();else if(!h&&e.classList.contains("dls-license-icon-warn"))h=e,"warn"!=t&&e.remove();else if(!c&&e.classList.contains("dls-license-msg-content")){c=e;let t=i;for(;t;){let i=t.indexOf("["),n=t.indexOf("]",i),s=t.indexOf("(",n),r=t.indexOf(")",s);if(-1==i||-1==n||-1==s||-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,n);o.innerText=a;let d=t.substring(s+1,r);o.setAttribute("href",d),o.setAttribute("target","_blank"),e.appendChild(o),t=t.substring(r+1)}}document.body.appendChild(o)}catch(e){d._onLog&&d._onLog(e.message||e)}}))}static createInstanceInWorker(t=!1){return e(this,void 0,void 0,(function*(){return yield d.loadWasm(),yield new Promise(((e,i)=>{let n=d._nextTaskID++;d._taskCallbackMap.set(n,(t=>{if(t.success)return e(t.instanceID);{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,i(e)}})),d._dbrWorker.postMessage({type:"createInstance",id:n,bScanner:t})}))}))}static createInstance(){return e(this,void 0,void 0,(function*(){let e=new d;return e._instanceID=yield d.createInstanceInWorker(),e}))}decode(t){return e(this,void 0,void 0,(function*(){if(d._onLog&&d._onLog("decode(source: any)"),d._onLog&&(this._timeStartDecode=Date.now()),r)return t instanceof Buffer?yield this._decodeFileInMemory_Uint8Array(new Uint8Array(t)):t instanceof Uint8Array?yield this._decodeFileInMemory_Uint8Array(t):"string"==typeof t?"data:image/"==t.substring(0,11)?yield this._decode_Base64(t):"http"==t.substring(0,4)?yield this._decode_Url(t):yield this._decode_FilePath(t):yield Promise.reject(TypeError("'_decode(source, config)': Type of 'source' should be 'Buffer', 'Uint8Array', 'String(base64 with image mime)' or 'String(url)'."));{let e={};return!this.region||this.region instanceof Array||(e.region=JSON.parse(JSON.stringify(this.region))),t instanceof Blob?yield this._decode_Blob(t,e):t instanceof ArrayBuffer?yield this._decode_ArrayBuffer(t,e):t instanceof Uint8Array||t instanceof Uint8ClampedArray?yield this._decode_Uint8Array(t,e):t instanceof HTMLImageElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?yield this._decode_Image(t,e):t instanceof HTMLCanvasElement||"undefined"!=typeof OffscreenCanvas&&t instanceof OffscreenCanvas?yield this._decode_Canvas(t,e):t instanceof HTMLVideoElement?yield this._decode_Video(t,e):"string"==typeof t?"data:image/"==t.substring(0,11)?yield this._decode_Base64(t,e):yield this._decode_Url(t,e):yield Promise.reject(TypeError("'_decode(source, config)': Type of 'source' should be 'Blob', 'ArrayBuffer', 'Uint8Array', 'HTMLImageElement', 'HTMLCanvasElement', 'HTMLVideoElement', 'String(base64 with image mime)' or 'String(url)'."))}}))}decodeBase64String(t){return e(this,void 0,void 0,(function*(){let e={};return!this.region||this.region instanceof Array||(e.region=JSON.parse(JSON.stringify(this.region))),this._decode_Base64(t,e)}))}decodeUrl(t){return e(this,void 0,void 0,(function*(){let e={};return!this.region||this.region instanceof Array||(e.region=JSON.parse(JSON.stringify(this.region))),this._decode_Url(t,e)}))}_decodeBuffer_Uint8Array(t,i,n,s,r,o){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,a)=>{let l=d._nextTaskID++;d._taskCallbackMap.set(l,(t=>{if(t.success){let i,n=d._onLog?Date.now():0;d._onLog&&d._onLog("worker return result: "+n),this._lastInnerDecodeDuration=t.duration;try{i=this._handleRetJsonString(t.decodeReturn)}catch(e){return a(e)}if(d._onLog){let e=Date.now();d._onLog("DBR time get result: "+n),d._onLog("Handle image cost: "+(this._timeEnterInnerDBR-this._timeStartDecode)),d._onLog("DBR worker decode image cost: "+(n-this._timeEnterInnerDBR)),d._onLog("DBR worker handle results: "+(e-n)),d._onLog("Total decode image cost: "+(e-this._timeStartDecode))}return e(i)}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,a(e)}})),this._timeEnterInnerDBR=Date.now(),d._onLog&&d._onLog("Send buffer to worker:"+this._timeEnterInnerDBR),d._dbrWorker.postMessage({type:"decodeBuffer",id:l,instanceID:this._instanceID,body:{buffer:t,width:i,height:n,stride:s,format:r,config:o}},[t.buffer]),d._onLog&&o&&o._timeEndGettingFrame&&d._onLog("decode image delay: "+(this._timeEnterInnerDBR-o._timeEndGettingFrame))}))}))}_decodeBuffer_Blob(t,i,n,s,r,o){return e(this,void 0,void 0,(function*(){d._onLog&&d._onLog("_decodeBuffer_Blob(buffer,width,height,stride,format)");const e=t.arrayBuffer?yield t.arrayBuffer():yield new Promise(((e,i)=>{let n=new FileReader;n.readAsArrayBuffer(t),n.onload=()=>{e(n.result)},n.onerror=()=>{i(n.error)}}));return yield this._decodeBuffer_Uint8Array(new Uint8Array(e),i,n,s,r,o)}))}decodeBuffer(t,i,n,s,o,a){return e(this,void 0,void 0,(function*(){let e;return d._onLog&&d._onLog("decodeBuffer(buffer,width,height,stride,format)"),d._onLog&&(this._timeStartDecode=Date.now()),r?t instanceof Uint8Array?e=yield this._decodeBuffer_Uint8Array(t,i,n,s,o,a):t instanceof Buffer&&(e=yield this._decodeBuffer_Uint8Array(new Uint8Array(t),i,n,s,o,a)):t instanceof Uint8Array||t instanceof Uint8ClampedArray?e=yield this._decodeBuffer_Uint8Array(t,i,n,s,o,a):t instanceof ArrayBuffer?e=yield this._decodeBuffer_Uint8Array(new Uint8Array(t),i,n,s,o,a):t instanceof Blob&&(e=yield this._decodeBuffer_Blob(t,i,n,s,o,a)),e}))}_decodeFileInMemory_Uint8Array(t){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,i)=>{let n=d._nextTaskID++;d._taskCallbackMap.set(n,(t=>{if(t.success){let n;this._lastInnerDecodeDuration=t.duration;try{n=this._handleRetJsonString(t.decodeReturn)}catch(e){return i(e)}return e(n)}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,i(e)}})),d._dbrWorker.postMessage({type:"decodeFileInMemory",id:n,instanceID:this._instanceID,body:{bytes:t}})}))}))}getRuntimeSettings(){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=d._nextTaskID++;d._taskCallbackMap.set(i,(i=>{if(i.success){let t=JSON.parse(i.results);return null!=this.userDefinedRegion&&(t.region=JSON.parse(JSON.stringify(this.userDefinedRegion))),e(t)}{let e=new Error(i.message);return e.stack=i.stack+"\n"+e.stack,t(e)}})),d._dbrWorker.postMessage({type:"getRuntimeSettings",id:i,instanceID:this._instanceID})}))}))}updateRuntimeSettings(t){return e(this,void 0,void 0,(function*(){let e;if("string"==typeof t)if("speed"==t){let t=yield this.getRuntimeSettings();yield this.resetRuntimeSettings(),e=yield this.getRuntimeSettings(),e.barcodeFormatIds=t.barcodeFormatIds,e.barcodeFormatIds_2=t.barcodeFormatIds_2,e.region=t.region,e.deblurLevel=3,e.expectedBarcodesCount=0,e.localizationModes=[2,0,0,0,0,0,0,0]}else if("balance"==t){let t=yield this.getRuntimeSettings();yield this.resetRuntimeSettings(),e=yield this.getRuntimeSettings(),e.barcodeFormatIds=t.barcodeFormatIds,e.barcodeFormatIds_2=t.barcodeFormatIds_2,e.region=t.region,e.deblurLevel=5,e.expectedBarcodesCount=512,e.localizationModes=[2,16,0,0,0,0,0,0]}else if("coverage"==t){let t=yield this.getRuntimeSettings();yield this.resetRuntimeSettings(),e=yield this.getRuntimeSettings(),e.barcodeFormatIds=t.barcodeFormatIds,e.barcodeFormatIds_2=t.barcodeFormatIds_2,e.region=t.region}else e=JSON.parse(t);else{if("object"!=typeof t)throw TypeError("'UpdateRuntimeSettings(settings)': Type of 'settings' should be 'string' or 'PlainObject'.");if(e=JSON.parse(JSON.stringify(t)),e.region instanceof Array){let t=e.region;[t.regionLeft,t.regionTop,t.regionLeft,t.regionBottom,t.regionMeasuredByPercentage].some((e=>void 0!==e))&&(e.region={regionLeft:t.regionLeft||0,regionTop:t.regionTop||0,regionRight:t.regionRight||0,regionBottom:t.regionBottom||0,regionMeasuredByPercentage:t.regionMeasuredByPercentage||0})}}if(!d._bUseFullFeature){if(0!=(e.barcodeFormatIds&~(s.BF_ONED|s.BF_QR_CODE|s.BF_PDF417|s.BF_DATAMATRIX))||0!=e.barcodeFormatIds_2)throw Error("Some of the specified barcode formats are not supported in the compact version. Please try the full-featured version.");if(0!=e.intermediateResultTypes)throw Error("Intermediate results is not supported in the compact version. Please try the full-featured version.")}if(!r)if(this.bFilterRegionInJs){let t=e.region;if(t instanceof Array)throw Error("The `region` of type `Array` is only allowed in `BarcodeScanner`.");this.userDefinedRegion=JSON.parse(JSON.stringify(t)),(t.regionLeft||t.regionTop||t.regionRight||t.regionBottom||t.regionMeasuredByPercentage)&&(t.regionLeft||t.regionTop||100!=t.regionRight||100!=t.regionBottom||!t.regionMeasuredByPercentage)?this.region=t:this.region=null,e.region={regionLeft:0,regionTop:0,regionRight:0,regionBottom:0,regionMeasuredByPercentage:0}}else this.userDefinedRegion=null,this.region=null;return yield new Promise(((t,i)=>{let n=d._nextTaskID++;d._taskCallbackMap.set(n,(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)}})),d._dbrWorker.postMessage({type:"updateRuntimeSettings",id:n,instanceID:this._instanceID,body:{settings:JSON.stringify(e)}})}))}))}resetRuntimeSettings(){return e(this,void 0,void 0,(function*(){return this.userDefinedRegion=null,this.region=null,yield new Promise(((e,t)=>{let i=d._nextTaskID++;d._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)}})),d._dbrWorker.postMessage({type:"resetRuntimeSettings",id:i,instanceID:this._instanceID})}))}))}outputSettingsToString(){return e(this,void 0,void 0,(function*(){if(!d._bUseFullFeature)throw Error("outputSettingsToString() is not supported in the compact version. Please try the full-featured version.");return yield new Promise(((e,t)=>{let i=d._nextTaskID++;d._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)}})),d._dbrWorker.postMessage({type:"outputSettingsToString",id:i,instanceID:this._instanceID})}))}))}initRuntimeSettingsWithString(t){return e(this,void 0,void 0,(function*(){if(!d._bUseFullFeature)throw Error("initRuntimeSettingsWithString() is not supported in the compact version. Please try the full-featured version.");if("string"==typeof t)t=t;else{if("object"!=typeof t)throw TypeError("'initRuntimeSettingstWithString(settings)': Type of 'settings' should be 'string' or 'PlainObject'.");t=JSON.stringify(t)}return yield new Promise(((e,i)=>{let n=d._nextTaskID++;d._taskCallbackMap.set(n,(t=>{if(t.success){try{this._handleRetJsonString(t.initReturn)}catch(e){i(e)}return e()}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,i(e)}})),d._dbrWorker.postMessage({type:"initRuntimeSettingsWithString",id:n,instanceID:this._instanceID,body:{settings:t}})}))}))}_decode_Blob(t,i){return e(this,void 0,void 0,(function*(){d._onLog&&d._onLog("_decode_Blob(blob: Blob)");let e=null,n=null;if("undefined"!=typeof createImageBitmap)try{e=yield createImageBitmap(t)}catch(e){}e||(n=yield function(e){return new Promise(((t,i)=>{let n=URL.createObjectURL(e),s=new Image;s.dbrObjUrl=n,s.src=n,s.onload=()=>{t(s)},s.onerror=e=>{i(new Error("Can't convert blob to image : "+(e instanceof Event?e.type:e)))}}))}(t));let s=yield this._decode_Image(e||n,i);return e&&e.close(),s}))}_decode_ArrayBuffer(t,i){return e(this,void 0,void 0,(function*(){return yield this._decode_Blob(new Blob([t]),i)}))}_decode_Uint8Array(t,i){return e(this,void 0,void 0,(function*(){return yield this._decode_Blob(new Blob([t]),i)}))}_decode_Image(t,i){return e(this,void 0,void 0,(function*(){d._onLog&&d._onLog("_decode_Image(image: HTMLImageElement|ImageBitmap)"),i=i||{};let e,n,s,r,o=t instanceof HTMLImageElement?t.naturalWidth:t.width,l=t instanceof HTMLImageElement?t.naturalHeight:t.height,_=i.region;if(_){let t,i,s,r;_.regionMeasuredByPercentage?(t=_.regionLeft*o/100,i=_.regionTop*l/100,s=_.regionRight*o/100,r=_.regionBottom*l/100):(t=_.regionLeft,i=_.regionTop,s=_.regionRight,r=_.regionBottom),e=t,n=i,o=Math.round(s-t),l=Math.round(r-i)}else e=0,n=0;const h=Math.max(o,l);if(h>this._canvasMaxWH){const e=this._canvasMaxWH/h;o>l?(s=this._canvasMaxWH,r=Math.round(l*e)):(s=Math.round(o*e),r=this._canvasMaxWH)}else s=o,r=l;let c,u;!this.bSaveOriCanvas&&a.OffscreenCanvas?c=new OffscreenCanvas(s,r):(c=document.createElement("canvas"),c.width=s,c.height=r),c.getContext("2d").drawImage(t,e,n,o,l,0,0,s,r),t.dbrObjUrl&&URL.revokeObjectURL(t.dbrObjUrl),_?(u=JSON.parse(JSON.stringify(i)),delete u.region):u=i;let g=yield this._decode_Canvas(c,u);return d.fixResultLocationWhenFilterRegionInJs(_,g,e,n,o,l,s,r),g}))}_decode_Canvas(i,n){return e(this,void 0,void 0,(function*(){if(d._onLog&&d._onLog("_decode_Canvas(canvas:HTMLCanvasElement)"),i.crossOrigin&&"anonymous"!=i.crossOrigin)throw"cors";(this.bSaveOriCanvas||this.singleFrameMode)&&(this.oriCanvas=i);let e=(i.dbrCtx2d||i.getContext("2d")).getImageData(0,0,i.width,i.height).data;return yield this._decodeBuffer_Uint8Array(e,i.width,i.height,4*i.width,t.IPF_ABGR_8888,n)}))}_decode_Video(t,i){return e(this,void 0,void 0,(function*(){if(d._onLog&&d._onLog("_decode_Video(video)"),!(t instanceof HTMLVideoElement))throw TypeError("'_decode_Video(video [, config] )': Type of 'video' should be 'HTMLVideoElement'.");if(t.crossOrigin&&"anonymous"!=t.crossOrigin)throw"cors";i=i||{};let e,n,s,r,o=t.videoWidth,l=t.videoHeight,_=i.region;if(_){let t,i,s,r;_.regionMeasuredByPercentage?(t=_.regionLeft*o/100,i=_.regionTop*l/100,s=_.regionRight*o/100,r=_.regionBottom*l/100):(t=_.regionLeft,i=_.regionTop,s=_.regionRight,r=_.regionBottom),e=t,n=i,o=Math.round(s-t),l=Math.round(r-i)}else e=0,n=0;const h=Math.max(o,l);if(h>this._canvasMaxWH){const e=this._canvasMaxWH/h;o>l?(s=this._canvasMaxWH,r=Math.round(l*e)):(s=Math.round(o*e),r=this._canvasMaxWH)}else s=o,r=l;let c=null;!this.bSaveOriCanvas&&a.OffscreenCanvas?c=new OffscreenCanvas(s,r):(c=document.createElement("canvas"),c.width=s,c.height=r);let u;(c.dbrCtx2d=c.getContext("2d")).drawImage(t,e,n,o,l,0,0,s,r),_?(u=JSON.parse(JSON.stringify(i)),delete u.region):u=i;let g=yield this._decode_Canvas(c,i);return _&&d.fixResultLocationWhenFilterRegionInJs(_,g,e,n,o,l,s,r),g}))}_decode_Base64(t,i){return e(this,void 0,void 0,(function*(){if(d._onLog&&d._onLog("_decode_Base64(base64Str)"),"string"!=typeof t)return Promise.reject("'_decode_Base64(base64Str, config)': Type of 'base64Str' should be 'string'.");if("data:image/"==t.substring(0,11)&&(t=t.substring(t.indexOf(",")+1)),r){let e=Buffer.from(t,"base64");return yield this._decodeFileInMemory_Uint8Array(new Uint8Array(e))}{let e=atob(t),n=e.length,s=new Uint8Array(n);for(;n--;)s[n]=e.charCodeAt(n);return yield this._decode_Blob(new Blob([s]),i)}}))}_decode_Url(t,i){return e(this,void 0,void 0,(function*(){if(d._onLog&&d._onLog("_decode_Url(url)"),"string"!=typeof t)throw TypeError("'_decode_Url(url, config)': Type of 'url' should be 'string'.");if(t=t,r){let i=yield new Promise(((i,n)=>e(this,void 0,void 0,(function*(){(t.startsWith("https")?yield import("https"):yield import("http")).get(t,(e=>{if(200==e.statusCode){let t=[];e.on("data",(e=>{t.push(e)})).on("end",(()=>{i(new Uint8Array(Buffer.concat(t)))}))}else n("http get fail, statusCode: "+e.statusCode)}))}))));return yield this._decodeFileInMemory_Uint8Array(i)}{let n=yield new Promise(((i,n)=>{let s=new XMLHttpRequest;s.open("GET",t,!0),s.responseType="blob",s.send(),s.onloadend=()=>e(this,void 0,void 0,(function*(){i(s.response)})),s.onerror=()=>{n(new Error("Network Error: "+s.statusText))}}));return yield this._decode_Blob(n,i)}}))}_decode_FilePath(t,i){return e(this,void 0,void 0,(function*(){if(d._onLog&&d._onLog("_decode_FilePath(path)"),!r)throw Error("'_decode_FilePath(path, config)': The method is only supported in node environment.");if("string"!=typeof t)throw TypeError("'_decode_FilePath(path, config)': Type of 'path' should be 'string'.");const e=yield import("fs");let i=yield new Promise(((i,n)=>{e.readFile(t,((e,t)=>{e?n(e):i(new Uint8Array(t))}))}));return yield this._decodeFileInMemory_Uint8Array(i)}))}static fixResultLocationWhenFilterRegionInJs(e,t,i,n,s,r,o,a){if(e&&t.length>0)for(let e of t){let t=e.localizationResult;2==t.resultCoordinateType&&(t.x1*=.01*o,t.x2*=.01*o,t.x3*=.01*o,t.x4*=.01*o,t.y1*=.01*a,t.y2*=.01*a,t.y3*=.01*a,t.y4*=.01*a);let d=o/s,l=a/r;t.x1=t.x1/d+i,t.x2=t.x2/d+i,t.x3=t.x3/d+i,t.x4=t.x4/d+i,t.y1=t.y1/l+n,t.y2=t.y2/l+n,t.y3=t.y3/l+n,t.y4=t.y4/l+n,2==t.resultCoordinateType&&(t.x1*=100/s,t.x2*=100/s,t.x3*=100/s,t.x4*=100/s,t.y1*=100/r,t.y2*=100/r,t.y3*=100/r,t.y4*=100/r)}}static BarcodeReaderException(e,t){let n,s=i.DBR_UNKNOWN;return"number"==typeof e?(s=e,n=new Error(t)):n=new Error(e),n.code=s,n}_handleRetJsonString(e){let t=i;if(e.textResults){for(let t=0;t<e.textResults.length;t++){let i=e.textResults[t];try{let e=i.barcodeText,t="";for(let i=0;i<e.length;i++)t+=String.fromCharCode(e[i]);try{i.barcodeText=decodeURIComponent(escape(t))}catch(e){i.barcodeText=t}}catch(e){i.barcodeText=""}if(null!=i.exception){d._setWarnnedEx.has(i.exception)||(d._setWarnnedEx.add(i.exception),console.warn(i.exception));let e={};i.exception.split(";").forEach((t=>{let i=t.indexOf(":");e[t.substring(0,i)]=t.substring(i+1)})),i.exception=e}}return e.decodeRecords?this.decodeRecords=e.decodeRecords:this.decodeRecords={},this._lastErrorCode=e.exception,this._lastErrorString=e.description,e.exception&&!d._setWarnnedEx.has(e.description)&&(d._setWarnnedEx.add(e.description),console.warn(e.description)),e.textResults}if(e.exception==t.DBR_SUCCESS)return e.data;throw d.BarcodeReaderException(e.exception,e.description)}setModeArgument(t,i,n,s){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,r)=>{let o=d._nextTaskID++;d._taskCallbackMap.set(o,(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)}})),d._dbrWorker.postMessage({type:"setModeArgument",id:o,instanceID:this._instanceID,body:{modeName:t,index:i,argumentName:n,argumentValue:s}})}))}))}getModeArgument(t,i,n){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,s)=>{let r=d._nextTaskID++;d._taskCallbackMap.set(r,(t=>{if(t.success){let i;try{i=this._handleRetJsonString(t.getReturn)}catch(e){return s(e)}return e(i)}{let e=new Error(t.message);return e.stack=t.stack+"\n"+e.stack,s(e)}})),d._dbrWorker.postMessage({type:"getModeArgument",id:r,instanceID:this._instanceID,body:{modeName:t,index:i,argumentName:n}})}))}))}getIntermediateResults(){return e(this,void 0,void 0,(function*(){return yield new Promise(((e,t)=>{let i=d._nextTaskID++;d._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)}})),d._dbrWorker.postMessage({type:"getIntermediateResults",id:i,instanceID:this._instanceID})}))}))}getIntermediateCanvas(){return e(this,void 0,void 0,(function*(){let e=yield this.getIntermediateResults(),i=[];for(let s of e)if(s.dataType==n.IMRDT_IMAGE)for(let e of s.results){const n=e.bytes;let s;switch(d._onLog&&d._onLog(" "+n.length+" "+n.byteLength+" "+e.width+" "+e.height+" "+e.stride+" "+e.format),e.format){case t.IPF_ABGR_8888:s=new Uint8ClampedArray(n);break;case t.IPF_RGB_888:{const e=n.length/3;s=new Uint8ClampedArray(4*e);for(let t=0;t<e;++t)s[4*t]=n[3*t+2],s[4*t+1]=n[3*t+1],s[4*t+2]=n[3*t],s[4*t+3]=255;break}case t.IPF_GrayScaled:{const e=n.length;s=new Uint8ClampedArray(4*e);for(let t=0;t<e;t++)s[4*t]=s[4*t+1]=s[4*t+2]=n[t],s[4*t+3]=255;break}case t.IPF_Binary:case t.IPF_BinaryInverted:{e.width=8*e.stride,e.height=n.length/e.stride;const t=n.length;s=new Uint8ClampedArray(8*t*4);for(let e=0;e<t;e++){let t=n[e];for(let i=0;i<8;++i)s[4*(8*e+i)]=s[4*(8*e+i)+1]=s[4*(8*e+i)+2]=(128&t)/128*255,s[4*(8*e+i)+3]=255,t<<=1}break}default:console.warn("unknow intermediate image",e)}if(!s)continue;let r=new ImageData(s,e.width,e.height),o=document.createElement("canvas");o.width=e.width,o.height=e.height,o.getContext("2d").putImageData(r,0,0),i.push(o)}return i}))}destroy(){return this.destroyContext()}destroyContext(){if(d._onLog&&d._onLog("destroyContext()"),!this.bDestroyed)return this.bDestroyed=!0,new Promise(((e,t)=>{let i=d._nextTaskID++;d._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)}})),d._dbrWorker.postMessage({type:"destroyContext",id:i,instanceID:this._instanceID})}))}}
/*!
* Dynamsoft JavaScript Library
* @product Dynamsoft Camera Enhancer JS Edition
* @website http://www.dynamsoft.com
* @copyright Copyright 2021, Dynamsoft Corporation
* @author Dynamsoft
* @version 2.0.1 (js 20210628)
* @fileoverview Dynamsoft JavaScript Library for Camera Enhancer
* More info on DBR JS: https://www.dynamsoft.com/barcode-reader/sdk-javascript/
*/
function l(e,t,i,n){return new(i||(i=Promise))((function(s,r){function o(e){try{d(n.next(e))}catch(e){r(e)}}function a(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}d((n=n.apply(e,t||[])).next())}))}d._jsVersion="8.8.7",d._jsEditVersion="20220125",d._version="loading...(JS "+d._jsVersion+"."+d._jsEditVersion+")",d._license=r||o||!document.currentScript?"":document.currentScript.getAttribute("data-license")||document.currentScript.getAttribute("data-productKeys")||document.currentScript.getAttribute("data-licenseKey")||document.currentScript.getAttribute("data-handshakeCode")||document.currentScript.getAttribute("data-organizationID")||"",d._sessionPassword=r||o||!document.currentScript?"":document.currentScript.getAttribute("data-sessionPassword")||"",d.browserInfo=function(){if(!r&&!o){var t={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,n=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(n)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 t.init(),{browser:t.browser,version:t.version,OS:t.OS}}if(o)return{browser:"ssr",version:0,OS:"ssr"};if(r){const t={browser:"node",version:process.version.substring(1),OS:"loading"};return(()=>{e(this,void 0,void 0,(function*(){const e=yield import("os");t.OS=e&&e.platform?e.platform()+e.release():"Unknown"}))})(),t}}(),d._workerName="dbr-"+d._jsVersion+".worker.js",d._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"./"})(),d._licenseServer=[],d._deviceFriendlyName="",d._isShowRelDecodeTimeInResults=!1,d._bWasmDebug=!1,d._bNeverShowDialog=!1,d.__bUseFullFeature=!0,d._nextTaskID=0,d._taskCallbackMap=new Map,d._loadWasmStatus="unload",d._loadWasmCallbackArr=[],d._lastErrorCode=0,d._lastErrorString="",d._setWarnnedEx=new Set,d._loadWasmErr=null;const _=!!("object"==typeof global&&global.process&&global.process.release&&global.process.release.name&&"undefined"==typeof HTMLCanvasElement),h=!_&&"undefined"==typeof self;class c{constructor(){this._canvasMaxWH="iPhone"==c.browserInfo.OS||"Android"==c.browserInfo.OS?2048:4096,this._singleFrameMode=!(navigator&&navigator.mediaDevices&&navigator.mediaDevices.getUserMedia),this._singleFrameModeIpt=()=>{let e=document.createElement("input");return e.setAttribute("type","file"),e.setAttribute("accept","image/*"),e.setAttribute("capture",""),e.addEventListener("change",(()=>l(this,void 0,void 0,(function*(){let t=e.files[0];e.value="",this.onSingleFrameAcquired(t)})))),e},this._clickIptSingleFrameMode=()=>{this._singleFrameModeIpt().click()},this.styleEls=[],this.bSaveOriCanvas=!0,this.maxVideoCvsLength=3,this.videoCvses=[],this.videoGlCvs=null,this.videoGl=null,this.glImgData=null,this._onCameraSelChange=()=>{this.play(this._selCam.value).then((()=>{this._isOpen||this.stop()}))},this._onResolutionSelChange=()=>{let e,t;if(this._selRsl&&-1!=this._selRsl.selectedIndex){let i=this._selRsl.options[this._selRsl.selectedIndex];e=i.getAttribute("data-width"),t=i.getAttribute("data-height")}this.play(void 0,e,t).then((()=>{this._isOpen||this.stop()}))},this._onCloseBtnClick=()=>{this.close()},this._isOpen=!1,this.videoSettings={video:{width:{ideal:1280},height:{ideal:720},facingMode:{ideal:"environment"}}},this.iPlayRound=0,this.promisePlay=null,this._allCameras=[],this._currentCamera=null,this._videoTrack=null,this._lastDeviceId=void 0,this._vc_bPlayingVideoBeforeHide=!1,this._ev_documentHideEvent=()=>{"visible"===document.visibilityState?this._vc_bPlayingVideoBeforeHide&&("Firefox"==c.browserInfo.browser?this.play():this._video.play(),this._vc_bPlayingVideoBeforeHide=!1):this._video&&!this._video.paused&&(this._vc_bPlayingVideoBeforeHide=!0,this._video.pause())},this._video=null,this._bgLoading=null,this._selCam=null,this._bgCamera=null,this._selRsl=null,this._optGotRsl=null,this._btnClose=null,this._region=null,this.bChangeRegionIndexManually=!1,this._regionIndex=-1,this._loopInterval=0,this._frameQueueMaxLength=1,this._frameQueue=[],this._bFetchingLoopStarted=!1,this._bStoppedByPause=!1,this.alwaysRefreshBuffer=!0,this._bufferRefreshInterval=0,this.bDestroyed=!1}static getVersion(){return this._version}static detectEnvironment(){return l(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:!!(_?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(this._hasEngineResourceLoaded)throw new Error("`engineResourcePath` is not allowed to change after `createInstance` is called.");if(null==e&&(e="./"),_||h)c._engineResourcePath=e;else{let t=document.createElement("a");t.href=e,c._engineResourcePath=t.href}this._engineResourcePath.endsWith("/")||(c._engineResourcePath+="/")}static get defaultUIElementURL(){var e;return null===(e=this._defaultUIElementURL)||void 0===e?void 0:e.replace("@engineResourcePath/",c.engineResourcePath)}static set defaultUIElementURL(e){this._defaultUIElementURL=e}getUIElement(){return this.UIElement}setUIElement(e){return l(this,void 0,void 0,(function*(){if("string"==typeof e||e instanceof String){if(!e.trim().startsWith("<")){let t=yield fetch(e);if(!t.ok)throw Error("setUIElement(elementOrUrl): Network Error: "+t.statusText);e=yield t.text()}if(!e.trim().startsWith("<"))throw Error("setUIElement(elementOrUrl): Can't get valid HTMLElement.");let t=document.createElement("div");t.innerHTML=e;for(let e=0;e<t.childElementCount;++e){let i=t.children[e];i instanceof HTMLStyleElement&&(this.styleEls.push(i),document.head.append(i))}(e=1==t.childElementCount?t.children[0]:t).remove()}this.UIElement=e}))}get singleFrameMode(){return this._singleFrameMode}set singleFrameMode(e){if(this._isOpen)throw new Error("`singleFrameMode` is not allowed to change when camera is open.");this._singleFrameMode=e}get ifSaveOriginalImageInACanvas(){return this.bSaveOriCanvas}set ifSaveOriginalImageInACanvas(e){this.bSaveOriCanvas=e}_bindUI(){if(!this.UIElement)throw new Error("Need to define `UIElement` before opening.");let e=[this.UIElement],t=this.UIElement.children;for(let i of t)e.push(i);for(let t=0;t<e.length;++t)for(let i of e[t].children)e.push(i);let i=null;for(let t of e)!this._video&&t.classList.contains("dce-video")?(this._video=t,this._video.setAttribute("playsinline","true")):!this._bgLoading&&t.classList.contains("dce-bg-loading")?this._bgLoading=t:!this._bgCamera&&t.classList.contains("dce-bg-camera")?this._bgCamera=t:!this._selCam&&t.classList.contains("dce-sel-camera")?this._selCam=t:!this._selRsl&&t.classList.contains("dce-sel-resolution")?(this._selRsl=t,this._selRsl.options.length||(this._selRsl.innerHTML=[this._optGotRsl?"":'<option class="dce-opt-gotResolution" value="got"></option>','<option data-width="1920" data-height="1080">ask 1920 x 1080</option>','<option data-width="1280" data-height="720">ask 1280 x 720</option>','<option data-width="640" data-height="480">ask 640 x 480</option>'].join(""),this._optGotRsl=this._optGotRsl||this._selRsl.options[0])):!this._optGotRsl&&t.classList.contains("dce-opt-gotResolution")?this._optGotRsl=t:!this._btnClose&&t.classList.contains("dce-btn-close")?this._btnClose=t:!this._video&&t.classList.contains("dce-existingVideo")?(this._video=t,this._video.setAttribute("playsinline","true")):!i&&t.tagName&&"video"==t.tagName.toLowerCase()&&(i=t);if(!this._video&&i&&(this._video=i),this.singleFrameMode?this._video&&(this._video.addEventListener("click",this._clickIptSingleFrameMode),this._video.style.cursor="pointer",this._video.setAttribute("title","Take a photo")):this._bgLoading&&(this._bgLoading.style.display=""),this.singleFrameMode?(this._video&&(this._video.addEventListener("click",this._clickIptSingleFrameMode),this._video.style.cursor="pointer",this._video.setAttribute("title","Take a photo")),this._bgCamera&&(this._bgCamera.style.display="")):this._bgLoading&&(this._bgLoading.style.display=""),this._selCam&&this._selCam.addEventListener("change",this._onCameraSelChange),this._selRsl&&this._selRsl.addEventListener("change",this._onResolutionSelChange),this._btnClose&&this._btnClose.addEventListener("click",this._onCloseBtnClick),!this._video)throw this._unbindUI(),Error("Can not find HTMLVideoElement with class `dce-video`");this._isOpen=!0}_unbindUI(){this.singleFrameMode?(this._video&&(this._video.removeEventListener("click",this._clickIptSingleFrameMode),this._video.style.cursor="",this._video.removeAttribute("title")),this._bgCamera&&(this._bgCamera.style.display="none")):this._bgLoading&&(this._bgLoading.style.display="none"),this._selCam&&this._selCam.removeEventListener("change",this._onCameraSelChange),this._selRsl&&this._selRsl.removeEventListener("change",this._onResolutionSelChange),this._btnClose&&this._btnClose.removeEventListener("click",this._onCloseBtnClick),this._video=null,this._selCam=null,this._selRsl=null,this._optGotRsl=null,this._btnClose=null,this._isOpen=!1}_assertOpen(){if(!this._isOpen)throw Error("The camera is not open.")}get video(){return this._video}set region(e){this._region=e,this._bFetchingLoopStarted&&(this._regionIndex=-1,this._fetchingLoop(!1))}get region(){return this._region}set regionIndex(e){this.bChangeRegionIndexManually&&(this._region instanceof Array&&this._region.length>e?this._regionIndex=e:this._regionIndex=0)}get regionIndex(){return this._regionIndex}set loopInterval(e){e>=0&&(this._loopInterval=e),this._bFetchingLoopStarted&&this._fetchingLoop(!1)}get loopInterval(){return this._loopInterval}set frameQueueMaxLength(e){for(this._frameQueueMaxLength=e;this._frameQueue&&this._frameQueue.length>this._frameQueueMaxLength;)this._frameQueue.shift()}get frameQueueMaxLength(){return this._frameQueueMaxLength}get frameQueue(){return JSON.parse(JSON.stringify(this._frameQueue))}set bufferRefreshInterval(e){this._bufferRefreshInterval=e}get bufferRefreshInterval(){return this._bufferRefreshInterval}isContextDestroyed(){return this.bDestroyed}static createInstance(e){return l(this,void 0,void 0,(function*(){if(_)throw new Error("`CameraEnhancer` is not supported in Node.js.");let t=new c;("string"==typeof e||e instanceof String)&&(e=JSON.parse(e));for(let i in e)t[i]=e[i];return yield t.setUIElement(this.defaultUIElementURL),this._hasEngineResourceLoaded=!0,document.addEventListener("visibilitychange",t._ev_documentHideEvent),t}))}play(e,t,i){return l(this,void 0,void 0,(function*(){if(this._assertOpen(),this._video&&this.videoSrc){yield new Promise(((e,t)=>{this._video.onloadedmetadata=()=>l(this,void 0,void 0,(function*(){this._video.onloadedmetadata=null,yield this._video.play(),e()})),"string"==typeof this.videoSrc||this.videoSrc instanceof String?this._video.src=this.videoSrc:this._video.srcObject=this.videoSrc,setTimeout((()=>t(new Error("Failed to play video. Timeout."))),4e3)}));let e={width:this._video.videoWidth,height:this._video.videoHeight};return this.onPlayed&&setTimeout((()=>{this.onPlayed(e)}),0),e}if(this.singleFrameMode)return this._clickIptSingleFrameMode(),{width:0,height:0};const n=++this.iPlayRound;return this.promisePlay&&(yield this.promisePlay,n<this.iPlayRound)?{width:this._video.videoWidth,height:this._video.videoHeight}:(this.promisePlay=(()=>l(