@microblink/blinkinput-in-browser-sdk
Version:
A simple barcode scanning library for WebAssembly-enabled browsers.
37 lines (32 loc) • 256 kB
JavaScript
import{r as e,c as t,h as i,H as r,g as o}from"./p-7fd1a99e.js";import{s as a,a as s,b as n,c,g as l,h as M}from"./p-21600f60.js";
/*! ****************************************************************************
Copyright (c) Microblink. All rights reserved.
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
***************************************************************************** */
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function g(e,t,i,r){return new(i||(i=Promise))((function(o,a){function s(e){try{c(r.next(e))}catch(e){a(e)}}function n(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,n)}c((r=r.apply(e,t||[])).next())}))}let N=0;class d{constructor(e){this.action=e,this.messageID=function(){const e=N;return N+=1,e}()}}class I extends d{constructor(e,t){super(I.action),this.wasmModuleName=e.wasmModuleName,this.licenseKey=e.licenseKey,this.userId=t,this.registerLoadCallback=null!==e.loadProgressCallback,this.allowHelloMessage=e.allowHelloMessage,this.engineLocation=e.engineLocation,this.wasmType=e.wasmType,this.numberOfWorkers=e.numberOfWorkers}}var D,h,u,j,m;I.action="init",function(e){e[e.Any=0]="Any",e[e.Recognizer=1]="Recognizer",e[e.RecognizerSettings=2]="RecognizerSettings",e[e.Callback=3]="Callback"}(D||(D={}));class b extends d{constructor(e,t){super(b.action),this.className=e,this.params=t}}b.action="createNewNativeObject";class z extends d{constructor(e,t,i){super(z.action),this.recognizerHandles=e,this.allowMultipleResults=t,this.registeredMetadataCallbacks=i}}z.action="createRecognizerRunner";class A extends d{constructor(e,t){super(A.action),this.recognizerHandles=e,this.allowMultipleResults=t}}A.action="reconfigureRecognizerRunner";class y extends d{constructor(){super(y.action)}}y.action="deleteRecognizerRunner";class p extends d{constructor(e,t,i){super(p.action),this.objectHandle=e,this.methodName=t,this.params=i}}p.action="invokeObject";class T extends d{constructor(e){super(T.action),this.frame=e}getTransferrables(){return[this.frame.imageData.data.buffer]}}T.action="processImage";class E extends d{constructor(e){super(E.action),this.hardReset=e}}E.action="resetRecognizers";class x{constructor(){this.onDebugText=!1,this.onDetectionFailed=!1,this.onQuadDetection=!1,this.onPointsDetection=!1,this.onFirstSideResult=!1,this.onGlare=!1}}class w extends d{constructor(e){super(w.action),this.registeredMetadataCallbacks=e}}w.action="registerMetadataCallbacks";class C extends d{constructor(e){super(C.action),this.detectionOnlyMode=e}}C.action="setDetectionOnly";class O extends d{constructor(e){super(O.action),this.callbackNonEmpty=e}}O.action="setClearTimeoutCallback";class L extends d{constructor(e){super(L.action),this.cameraPreviewMirrored=e}}function S(e,t){return i=>{const r=i;r.success?e():t(r.error)}}function k(e,t){return i=>{const r=i;r.success?e(i):t(r.error)}}L.action="setCameraPreviewMirrored",function(e){e[e.onDebugText=0]="onDebugText",e[e.onDetectionFailed=1]="onDetectionFailed",e[e.onQuadDetection=2]="onQuadDetection",e[e.onPointsDetection=3]="onPointsDetection",e[e.onFirstSideResult=4]="onFirstSideResult",e[e.clearTimeoutCallback=5]="clearTimeoutCallback",e[e.onGlare=6]="onGlare",e[e.recognizerCallback=7]="recognizerCallback"}(h||(h={})),function(e){e.Basic="BASIC",e.Advanced="ADVANCED",e.AdvancedWithThreads="ADVANCED_WITH_THREADS"}(u||(u={}));class f{constructor(e,t,i){this.wasmSDKWorker=e,this.objectHandle=i,this.recognizerName=t,this.callbacks=new Map}getRemoteObjectHandle(){return this.objectHandle}currentSettings(){return new Promise(((e,t)=>{if(this.objectHandle<0)return void t("Invalid object handle: "+this.objectHandle.toString());const i=new p(this.objectHandle,"currentSettings",[]),r=k((t=>{e(t.result)}),t);this.wasmSDKWorker.postMessage(i,r)}))}toJSON(){return Promise.resolve(null)}clearAllCallbacks(){this.callbacks.clear(),this.wasmSDKWorker.unregisterRecognizerCallbacks(this.objectHandle)}removeFunctions(e){this.clearAllCallbacks();const t=Object.keys(e);let i=!1;for(const r of t){const t=e[r];"function"==typeof t&&(this.callbacks.set(r,t),e[r]={parameter:{recognizerHandle:this.objectHandle,callbackName:r},type:D.Callback},i=!0)}return i&&this.wasmSDKWorker.registerRecognizerCallbacks(this.objectHandle,this),e}updateSettings(e){return new Promise(((t,i)=>{if(this.objectHandle<0)return void i("Invalid object handle: "+this.objectHandle.toString());const r=new p(this.objectHandle,"updateSettings",[{parameter:this.removeFunctions(e),type:D.RecognizerSettings}]),o=S(t,i);this.wasmSDKWorker.postMessage(r,o)}))}invokeCallback(e,t){const i=this.callbacks.get(e);void 0!==i?i(...t):console.warn("Cannot find callback",e)}getResult(){return new Promise(((e,t)=>{if(this.objectHandle<0)return void t("Invalid object handle: "+this.objectHandle.toString());const i=new p(this.objectHandle,"getResult",[]),r=k((t=>{e(t.result)}),t);this.wasmSDKWorker.postMessage(i,r)}))}delete(){return new Promise(((e,t)=>{if(this.objectHandle<0)return void t("Invalid object handle: "+this.objectHandle.toString());this.clearAllCallbacks();const i=new p(this.objectHandle,"delete",[]),r=S((()=>{this.objectHandle=-1,e()}),t);this.wasmSDKWorker.postMessage(i,r)}))}}function R(e){const t=new x;return t.onDebugText=!!e.onDebugText,t.onDetectionFailed=!!e.onDetectionFailed,t.onPointsDetection=!!e.onPointsDetection,t.onQuadDetection=!!e.onQuadDetection,t.onFirstSideResult=!!e.onFirstSideResult,t.onGlare=!!e.onGlare,t}class v{constructor(e){this.deleted=!1,this.wasmSDKWorker=e}processImage(e){return new Promise(((t,i)=>{if(this.deleted)return void i("Recognizer runner is deleted. It cannot be used anymore!");const r=new T(e),o=k((e=>{t(e.recognitionState)}),i);this.wasmSDKWorker.postTransferrableMessage(r,o)}))}reconfigureRecognizers(e,t){return new Promise(((i,r)=>{if(this.deleted)return void r("Recognizer runner is deleted. It cannot be used anymore!");const o=U(e),a=new A(o,t),s=S(i,r);this.wasmSDKWorker.postMessage(a,s)}))}setMetadataCallbacks(e){return new Promise(((t,i)=>{const r=new w(R(e)),o=S(t,i);this.wasmSDKWorker.postMessageAndRegisterCallbacks(r,e,o)}))}resetRecognizers(e){return new Promise(((t,i)=>{const r=new E(e),o=S(t,i);this.wasmSDKWorker.postMessage(r,o)}))}setDetectionOnlyMode(e){return new Promise(((t,i)=>{const r=new C(e),o=S(t,i);this.wasmSDKWorker.postMessage(r,o)}))}setClearTimeoutCallback(e){return new Promise(((t,i)=>{const r=new O(null!==e),o=S(t,i);this.wasmSDKWorker.registerClearTimeoutCallback(e),this.wasmSDKWorker.postMessage(r,o)}))}setCameraPreviewMirrored(e){return new Promise(((t,i)=>{const r=new L(e),o=S(t,i);this.wasmSDKWorker.postMessage(r,o)}))}delete(){return this.deleted?Promise.reject("Recognizer runner is already deleted."):new Promise(((e,t)=>{const i=new y,r=S((()=>{this.deleted=!0,e()}),t);this.wasmSDKWorker.postMessage(i,r)}))}}function U(e){const t=[];for(const i of e)t.push(i.getRemoteObjectHandle());return t}class _{constructor(e){this.wasmSDKWorker=e}createRecognizerRunner(e,t=!1,i={}){return new Promise(((r,o)=>{const a=U(e),s=new z(a,t,R(i)),n=S((()=>{r(new v(this.wasmSDKWorker))}),o);this.wasmSDKWorker.postMessageAndRegisterCallbacks(s,i,n)}))}newRecognizer(e,...t){return new Promise(((i,r)=>{const o=new b(e,function(e){const t=[];for(let i of e){let e=D.Any;i instanceof f&&(e=D.Recognizer,i=i.getRemoteObjectHandle()),t.push({parameter:i,type:e})}return t}(t)),a=k((t=>{const r=new f(this.wasmSDKWorker,e,t.objectHandle);i(r)}),r);this.wasmSDKWorker.postMessage(o,a)}))}}class Q{constructor(e,t,i){this.eventHandlers={},this.metadataCallbacks={},this.clearTimeoutCallback=null,this.loadedWasmType=u.Basic,this.mbWasmWorker=e,this.mbWasmWorker.onmessage=e=>{this.handleWorkerEvent(e)},this.mbWasmWorker.onerror=()=>{i("Problem during initialization of worker file!")},this.mbWasmModule=new _(this),this.loadCallback=t,this.recognizersWithCallbacks=new Map,this.showOverlay=!1}postMessage(e,t){this.eventHandlers[e.messageID]=t,this.mbWasmWorker.postMessage(e)}postTransferrableMessage(e,t){this.eventHandlers[e.messageID]=t,this.mbWasmWorker.postMessage(e,e.getTransferrables())}postMessageAndRegisterCallbacks(e,t,i){this.eventHandlers[e.messageID]=i,this.metadataCallbacks=t,this.mbWasmWorker.postMessage(e)}registerClearTimeoutCallback(e){this.clearTimeoutCallback=e}registerRecognizerCallbacks(e,t){this.recognizersWithCallbacks.set(e,t)}unregisterRecognizerCallbacks(e){this.recognizersWithCallbacks.delete(e)}delete(){this.mbWasmWorker.terminate()}handleWorkerEvent(e){if("isCallbackMessage"in e.data){const t=e.data;switch(t.callbackType){case h.onDebugText:"function"==typeof this.metadataCallbacks.onDebugText&&this.metadataCallbacks.onDebugText(t.callbackParameters[0]);break;case h.onDetectionFailed:"function"==typeof this.metadataCallbacks.onDetectionFailed&&this.metadataCallbacks.onDetectionFailed();break;case h.onPointsDetection:"function"==typeof this.metadataCallbacks.onPointsDetection&&this.metadataCallbacks.onPointsDetection(t.callbackParameters[0]);break;case h.onQuadDetection:"function"==typeof this.metadataCallbacks.onQuadDetection&&this.metadataCallbacks.onQuadDetection(t.callbackParameters[0]);break;case h.onFirstSideResult:"function"==typeof this.metadataCallbacks.onFirstSideResult&&this.metadataCallbacks.onFirstSideResult();break;case h.clearTimeoutCallback:this.clearTimeoutCallback&&"function"==typeof this.clearTimeoutCallback.onClearTimeout&&this.clearTimeoutCallback.onClearTimeout();break;case h.onGlare:"function"==typeof this.metadataCallbacks.onGlare&&this.metadataCallbacks.onGlare(t.callbackParameters[0]);break;case h.recognizerCallback:{const e=t.callbackParameters.shift(),i=this.recognizersWithCallbacks.get(e.recognizerHandle);void 0!==i?i.invokeCallback(e.callbackName,t.callbackParameters):console.warn("Cannot find recognizer to deliver callback message. Maybe it's destroyed?",e);break}default:throw new Error(`Unknown callback type: ${h[t.callbackType]}`)}}else if("isLoadProgressMessage"in e.data){const t=e.data;"function"==typeof this.loadCallback&&this.loadCallback(t.progress)}else{const t=e.data,i=this.eventHandlers[t.messageID];delete this.eventHandlers[t.messageID],i(t)}}static createWasmWorker(e,t,i){return g(this,void 0,void 0,(function*(){return new Promise(((r,o)=>{const a=new Q(e,t.loadProgressCallback,o),s=new I(t,i),n=k((e=>{const t=e;a.showOverlay=t.showOverlay,a.loadedWasmType=t.wasmType,r(a)}),(e=>{a&&"function"==typeof a.delete&&a.delete(),o(e)}));a.postMessage(s,n)}))}))}}class Z{constructor(e,t){if(!e.code||!e.message)throw new Error("Instance of SDKError is required to have code and message.");this.message=e.message,this.code=e.code,this.details=t}}!function(e){e.WORKER_WASM_LOAD_FAILURE="WORKER_WASM_LOAD_FAILURE",e.WORKER_WASM_INIT_MISSING="WORKER_WASM_INIT_MISSING",e.WORKER_FUNCTION_INVOKE_FAILURE="WORKER_FUNCTION_INVOKE_FAILURE",e.WORKER_RECOGNIZER_CREATION_FAILURE="WORKER_RECOGNIZER_CREATION_FAILURE",e.WORKER_RUNNER_EXISTS="WORKER_RUNNER_EXISTS",e.WORKER_RUNNER_CREATION_FAILURE="WORKER_RUNNER_CREATION_FAILURE",e.WORKER_RUNNER_MISSING="WORKER_RUNNER_MISSING",e.WORKER_RUNNER_RECONFIGURE_FAILURE="WORKER_RUNNER_RECONFIGURE_FAILURE",e.WORKER_RUNNER_DELETED="WORKER_RUNNER_DELETED",e.WORKER_RUNNER_DELETE_FAILURE="WORKER_RUNNER_DELETE_FAILURE",e.WORKER_OBJECT_INVOKE_FAILURE="WORKER_OBJECT_INVOKE_FAILURE",e.WORKER_IMAGE_PROCESS_FAILURE="WORKER_IMAGE_PROCESS_FAILURE",e.WORKER_HANDLE_UNDEFINED="WORKER_HANDLE_UNDEFINED",e.WORKER_MESSAGE_ACTION_UNKNOWN="WORKER_MESSAGE_ACTION_UNKNOWN",e.WORKER_LICENSE_UNLOCK_ERROR="WORKER_LICENSE_UNLOCK_ERROR",e.LOCAL_SDK_RUNNER_MISSING="LOCAL_SDK_RUNNER_MISSING",e.LOCAL_SDK_RUNNER_EMPTY="LOCAL_SDK_RUNNER_EMPTY",e.LICENSE_UNLOCK_ERROR="LICENSE_UNLOCK_ERROR",e.FRAME_CAPTURE_SVG_UNSUPPORTED="FRAME_CAPTURE_SVG_UNSUPPORTED",e.FRAME_CAPTURE_CANVAS_MISSING="FRAME_CAPTURE_CANVAS_MISSING",e.SDK_WASM_SETTINGS_MISSING="SDK_WASM_SETTINGS_MISSING",e.SDK_LICENSE_KEY_MISSING="SDK_LICENSE_KEY_MISSING",e.SDK_WASM_MODULE_NAME_MISSING="SDK_WASM_MODULE_NAME_MISSING",e.SDK_ENGINE_LOCATION_INVALID="SDK_ENGINE_LOCATION_INVALID",e.SDK_MISSING="SDK_MISSING",e.SDK_RECOGNIZERS_MISSING="SDK_RECOGNIZERS_MISSING",e.VIDEO_RECOGNIZER_ELEMENT_MISSING="VIDEO_RECOGNIZER_ELEMENT_MISSING",e.VIDEO_RECOGNIZER_CAMERA_MISSING="VIDEO_RECOGNIZER_CAMERA_MISSING",e.VIDEO_RECOGNIZER_CAMERA_NOT_ALLOWED="VIDEO_RECOGNIZER_CAMERA_NOT_ALLOWED",e.VIDEO_RECOGNIZER_CAMERA_UNAVAILABLE="VIDEO_RECOGNIZER_CAMERA_UNAVAILABLE",e.VIDEO_RECOGNIZER_CAMERA_IN_USE="VIDEO_RECOGNIZER_CAMERA_IN_USE",e.VIDEO_RECOGNIZER_MEDIA_DEVICES_UNSUPPORTED="VIDEO_RECOGNIZER_MEDIA_DEVICES_UNSUPPORTED",e.VIDEO_RECOGNIZER_FEED_RELEASED="VIDEO_RECOGNIZER_FEED_RELEASED",e.VIDEO_RECOGNIZER_FEED_NOT_PAUSED="VIDEO_RECOGNIZER_FEED_NOT_PAUSED",e.VIDEO_RECOGNIZER_PLAY_REQUEST_INTERRUPTED="VIDEO_RECOGNIZER_PLAY_REQUEST_INTERRUPTED",e.VIDEO_RECOGNIZER_FEED_PAUSED="VIDEO_RECOGNIZER_FEED_PAUSED",e.VIDEO_RECOGNIZER_RECOGNIZERS_RESET_FAILURE="VIDEO_RECOGNIZER_RECOGNIZERS_RESET_FAILURE",e.VIDEO_RECOGNIZER_FEED_MISSING="VIDEO_RECOGNIZER_FEED_MISSING"}(j||(j={})),function(e){e.WORKER_HANDLE_UNDEFINED="Cannot find object with handle: undefined",e.WORKER_WASM_LOAD_FAILURE="Failed to load WASM in web worker!",e.WORKER_WASM_INIT_MISSING="WASM module is not initialized!",e.WORKER_FUNCTION_INVOKE_FAILURE="Failed to invoke function!",e.WORKER_RECOGNIZER_CREATION_FAILURE="Failed to create new recognizer!",e.WORKER_RUNNER_EXISTS="Recognizer runner is already created! Multiple instances are not allowed!",e.WORKER_RUNNER_CREATION_FAILURE="Failed to create new recognizer runner!",e.WORKER_RUNNER_MISSING="Recognizer runner is not created! There is nothing to reconfigure!",e.WORKER_RUNNER_RECONFIGURE_FAILURE="Failed to reconfigure recognizer runner!",e.WORKER_RUNNER_DELETED="Recognizer runner is already deleted!",e.WORKER_RUNNER_DELETE_FAILURE="Failed to delete recognizer runner!",e.WORKER_OBJECT_INVOKE_FAILURE="Failed to invoke object!",e.WORKER_IMAGE_PROCESS_FAILURE="Recognizer runner is not initialized! Cannot process image!",e.LOCAL_SDK_RUNNER_MISSING="Property nativeRecognizerRunner is not available!",e.LOCAL_SDK_RUNNER_EMPTY="Native RecognizerRunner cannot be empty!",e.LICENSE_TOKEN_STATE_INCORRECT="Internal error (Incorrect token state)",e.LICENSE_PAYLOAD_VERIFICATION_FAILED="Failed to verify server permission's digital signature!",e.LICENSE_PAYLOAD_CORRUPTED="Server permission payload is corrupted!",e.LICENSE_PERMISSION_EXPIRED="Internal error (server permission expired)",e.LICENSE_REMOTE_LOCKED="Provided license key has been remotely locked. Please contact support for more information!",e.FRAME_CAPTURE_SVG_UNSUPPORTED="Recognition of SVG elements not supported!",e.FRAME_CAPTURE_CANVAS_MISSING="Could not get canvas 2d context!",e.SDK_WASM_SETTINGS_MISSING="Missing WASM load settings!",e.SDK_LICENSE_KEY_MISSING="Missing license key!",e.SDK_WASM_MODULE_NAME_MISSING="Missing WASM module name!",e.SDK_ENGINE_LOCATION_INVALID="Setting property 'engineLocation' must be a string!",e.SDK_MISSING="SDK is not provided!",e.SDK_RECOGNIZERS_MISSING="To create RecognizerRunner at least 1 recognizer is required.",e.VIDEO_RECOGNIZER_ELEMENT_MISSING="Video element, i.e. camera feed is not provided!",e.VIDEO_RECOGNIZER_CAMERA_MISSING="Camera not found!",e.VIDEO_RECOGNIZER_CAMERA_NOT_ALLOWED="Camera not allowed!",e.VIDEO_RECOGNIZER_CAMERA_UNAVAILABLE="Camera not available!",e.VIDEO_RECOGNIZER_CAMERA_IN_USE="Camera in use!",e.VIDEO_RECOGNIZER_MEDIA_DEVICES_UNSUPPORTED="Media devices not supported by browser.",e.VIDEO_RECOGNIZER_FEED_RELEASED="The associated video feed has been released!",e.VIDEO_RECOGNIZER_FEED_NOT_PAUSED="The associated video feed is not paused. Use resumeRecognition instead!",e.VIDEO_RECOGNIZER_PLAY_REQUEST_INTERRUPTED="The play() request was interrupted or prevented by browser security rules!",e.VIDEO_RECOGNIZER_FEED_PAUSED="Cannot resume recognition while video feed is paused! Use recognize or startRecognition",e.VIDEO_RECOGNIZER_RECOGNIZERS_RESET_FAILURE="Could not reset recognizers!",e.VIDEO_RECOGNIZER_FEED_MISSING="Missing video feed!"}(m||(m={}));const Y={feedMissing:{message:m.VIDEO_RECOGNIZER_FEED_MISSING,code:j.VIDEO_RECOGNIZER_FEED_MISSING},recognizersResetFailure:{message:m.VIDEO_RECOGNIZER_RECOGNIZERS_RESET_FAILURE,code:j.VIDEO_RECOGNIZER_RECOGNIZERS_RESET_FAILURE},feedPaused:{message:m.VIDEO_RECOGNIZER_FEED_PAUSED,code:j.VIDEO_RECOGNIZER_FEED_PAUSED},playRequestInterrupted:{message:m.VIDEO_RECOGNIZER_PLAY_REQUEST_INTERRUPTED,code:j.VIDEO_RECOGNIZER_PLAY_REQUEST_INTERRUPTED},videoFeedNotPaused:{message:m.VIDEO_RECOGNIZER_FEED_NOT_PAUSED,code:j.VIDEO_RECOGNIZER_FEED_NOT_PAUSED},videoFeedReleased:{message:m.VIDEO_RECOGNIZER_FEED_RELEASED,code:j.VIDEO_RECOGNIZER_FEED_RELEASED},mediaDevicesUnsupported:{code:j.VIDEO_RECOGNIZER_MEDIA_DEVICES_UNSUPPORTED,message:m.VIDEO_RECOGNIZER_MEDIA_DEVICES_UNSUPPORTED},cameraMissing:{code:j.VIDEO_RECOGNIZER_CAMERA_MISSING,message:m.VIDEO_RECOGNIZER_CAMERA_MISSING},elementMissing:{message:m.VIDEO_RECOGNIZER_ELEMENT_MISSING,code:j.VIDEO_RECOGNIZER_ELEMENT_MISSING}},G={wasmSettingsMissing:{message:m.SDK_WASM_SETTINGS_MISSING,code:j.SDK_WASM_SETTINGS_MISSING},licenseKeyMissing:{message:m.SDK_LICENSE_KEY_MISSING,code:j.SDK_LICENSE_KEY_MISSING},wasmModuleNameMissing:{message:m.SDK_WASM_MODULE_NAME_MISSING,code:j.SDK_WASM_MODULE_NAME_MISSING},engineLocationInvalid:{message:m.SDK_ENGINE_LOCATION_INVALID,code:j.SDK_ENGINE_LOCATION_INVALID},missing:{message:m.SDK_MISSING,code:j.SDK_MISSING},recognizersMissing:{message:m.SDK_RECOGNIZERS_MISSING,code:j.SDK_RECOGNIZERS_MISSING}},W={svgUnsupported:{message:m.FRAME_CAPTURE_SVG_UNSUPPORTED,code:j.FRAME_CAPTURE_SVG_UNSUPPORTED},canvasMissing:{message:m.FRAME_CAPTURE_CANVAS_MISSING,code:j.FRAME_CAPTURE_CANVAS_MISSING}},F={licenseTokenStateIncorrect:{code:j.LICENSE_UNLOCK_ERROR,message:m.LICENSE_TOKEN_STATE_INCORRECT},licensePayloadVerificationFailed:{code:j.LICENSE_UNLOCK_ERROR,message:m.LICENSE_PAYLOAD_VERIFICATION_FAILED},licensePayloadCorrupted:{code:j.LICENSE_UNLOCK_ERROR,message:m.LICENSE_PAYLOAD_CORRUPTED},licensePermissionExpired:{code:j.LICENSE_UNLOCK_ERROR,message:m.LICENSE_PERMISSION_EXPIRED},licenseRemoteLocked:{code:j.LICENSE_UNLOCK_ERROR,message:m.LICENSE_REMOTE_LOCKED},licenseNetworkError:{code:j.LICENSE_UNLOCK_ERROR},licenseInvalid:{code:j.LICENSE_UNLOCK_ERROR}},P={runnerMissing:{message:m.LOCAL_SDK_RUNNER_MISSING,code:j.LOCAL_SDK_RUNNER_MISSING},runnerEmpty:{message:m.LOCAL_SDK_RUNNER_EMPTY,code:j.LOCAL_SDK_RUNNER_EMPTY}},V={imageProcessFailure:{message:m.WORKER_IMAGE_PROCESS_FAILURE,code:j.WORKER_IMAGE_PROCESS_FAILURE},objectInvokeFailure:{message:m.WORKER_OBJECT_INVOKE_FAILURE,code:j.WORKER_OBJECT_INVOKE_FAILURE},runnerDeleteFailure:{message:m.WORKER_RUNNER_DELETE_FAILURE,code:j.WORKER_RUNNER_DELETE_FAILURE},runnerDeleted:{message:m.WORKER_RUNNER_DELETED,code:j.WORKER_RUNNER_DELETED},runnerReconfigureFailure:{message:m.WORKER_RUNNER_RECONFIGURE_FAILURE,code:j.WORKER_RUNNER_RECONFIGURE_FAILURE},runnerMissing:{message:m.WORKER_RUNNER_MISSING,code:j.WORKER_RUNNER_MISSING},runnerCreationFailure:{message:m.WORKER_RUNNER_CREATION_FAILURE,code:j.WORKER_RUNNER_CREATION_FAILURE},runnerExists:{message:m.WORKER_RUNNER_EXISTS,code:j.WORKER_RUNNER_EXISTS},recognizerCreationFailure:{message:m.WORKER_RECOGNIZER_CREATION_FAILURE,code:j.WORKER_RECOGNIZER_CREATION_FAILURE},functionInvokeFailure:{message:m.WORKER_FUNCTION_INVOKE_FAILURE,code:j.WORKER_FUNCTION_INVOKE_FAILURE},wasmInitMissing:{message:m.WORKER_WASM_INIT_MISSING,code:j.WORKER_WASM_INIT_MISSING},wasmLoadFailure:{message:m.WORKER_WASM_LOAD_FAILURE,code:j.WORKER_WASM_LOAD_FAILURE},handleUndefined:{message:m.WORKER_HANDLE_UNDEFINED,code:j.WORKER_HANDLE_UNDEFINED}};var H;!function(e){e[e.BackFacingCamera=0]="BackFacingCamera",e[e.FrontFacingCamera=1]="FrontFacingCamera"}(H||(H={}));const K=["rear","back","rück","arrière","trasera","trás","traseira","posteriore","后面","後面","背面","后置","後置","背置","задней","الخلفية","후","arka","achterzijde","หลัง","baksidan","bagside","sau","bak","tylny","takakamera","belakang","אחורית","πίσω","spate","hátsó","zadní","darrere","zadná","задня","stražnja","belakang","बैक"];function B(e){const t=e.toLowerCase();return K.some((e=>t.includes(e)))}class X{constructor(e,t){this.deviceId=e.deviceId,this.facing=t,this.groupId=e.groupId,this.label=e.label}}function J(){return g(this,void 0,void 0,(function*(){const e=[],t=[];{let i=yield navigator.mediaDevices.enumerateDevices();if(i.filter((e=>"videoinput"===e.kind)).every((e=>""===e.label))){const e=yield navigator.mediaDevices.getUserMedia({video:{facingMode:{ideal:"environment"}},audio:!1});i=yield navigator.mediaDevices.enumerateDevices(),e.getTracks().forEach((e=>e.stop()))}const r=i.filter((e=>"videoinput"===e.kind));for(const i of r)B(i.label)?t.push(new X(i,H.BackFacingCamera)):e.push(new X(i,H.FrontFacingCamera))}return{frontCameras:e,backCameras:t}}))}function $(e,t){return g(this,void 0,void 0,(function*(){const{frontCameras:i,backCameras:r}=yield J();if(i.length>0||r.length>0){let o=r.length>0?r:i;t===H.BackFacingCamera&&r.length>0&&(o=r),t===H.FrontFacingCamera&&i.length>0&&(o=i),o=o.sort(((e,t)=>e.label.localeCompare(t.label)));{let t=0;const a=o.map((e=>{const t=RegExp(/\b([0-9]+)MP?\b/,"i").exec(e.label);return null!==t?parseInt(t[1],10):NaN}));if(a.some((e=>isNaN(e)))||(t=a.lastIndexOf(Math.max(...a))),e){let t=null;return t=i.filter((t=>t.deviceId===e))[0],t||(t=r.filter((t=>t.deviceId===e))[0]),t||null}return o[t]}}return null}))}function q(e,t,i=H.BackFacingCamera){return g(this,void 0,void 0,(function*(){const r={audio:!1,video:{width:{min:640,ideal:1920,max:1920},height:{min:480,ideal:1080,max:1080}}};""===e.deviceId?r.video.facingMode={ideal:i===H.BackFacingCamera?"environment":"user"}:r.video.deviceId={exact:e.deviceId};const o=yield navigator.mediaDevices.getUserMedia(r);t.controls=!1,t.srcObject=o;let a=!1;return e.facing===H.FrontFacingCamera&&(t.style.transform="scaleX(-1)",a=!0),a}))}function ee(e){e&&null!==e.srcObject&&(e.srcObject.getTracks().forEach((e=>e.stop())),e.srcObject=null)}var te,ie;function re(){try{if("object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate){const e=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(e instanceof WebAssembly.Module)return new WebAssembly.Instance(e)instanceof WebAssembly.Instance}}catch(e){return!1}return!1}let oe;!function(e){e[e.RotatedLeft90=0]="RotatedLeft90",e[e.NoRotation=1]="NoRotation",e[e.RotatedRight90=2]="RotatedRight90",e[e.Rotated180=3]="Rotated180"}(te||(te={})),function(e){e[e.Empty=0]="Empty",e[e.Uncertain=1]="Uncertain",e[e.Valid=2]="Valid",e[e.StageValid=3]="StageValid"}(ie||(ie={}));class ae{constructor(e,t,i){this.imageData=e,this.orientation=t,this.videoFrame=i}}function se(e){let t,i,r=!1;if(e instanceof HTMLVideoElement)t=e.videoWidth,i=e.videoHeight,r=!0;else if(e instanceof HTMLImageElement)t=e.naturalWidth,i=e.naturalHeight;else{if(e instanceof SVGImageElement)throw new Z(W.svgUnsupported);t=e.width,i=e.height}oe=oe||document.createElement("canvas"),oe.width=t,oe.height=i;const o=oe.getContext("2d");if(!o)throw new Z(W.canvasMissing);o.drawImage(e,0,0,oe.width,oe.height);const a=o.getImageData(0,0,oe.width,oe.height);return new ae(a,te.NoRotation,r)}var ne,ce,le,Me,ge,Ne,de;function Ie(e){return{licenseId:e.licenseId,licensee:e.licensee,packageName:e.packageName,platform:"Browser",sdkName:e.sdkName,sdkVersion:e.sdkVersion}}function De(e,t){return g(this,void 0,void 0,(function*(){try{const i=yield fetch("https://baltazar.microblink.com/api/v1/status/check",{method:"POST",headers:{"Content-Type":"application/json"},cache:"no-cache",body:JSON.stringify(Ie(e))});if(i.ok){const e=(yield i.text()).toString();return t.submitServerPermission(e)}return{status:le.NetworkError,lease:0,networkErrorDescription:`Server responded with status ${i.status}`}}catch(e){return{status:le.NetworkError,lease:0,networkErrorDescription:`Unexpected error: ${JSON.stringify(e)}`}}}))}!function(e){e[e.Invalid=0]="Invalid",e[e.RequiresServerPermission=1]="RequiresServerPermission",e[e.Valid=2]="Valid"}(ne||(ne={})),function(e){e.LicenseTokenStateInvalid="LICENSE_TOKEN_STATE_INVALID",e.NetworkError="NETWORK_ERROR",e.RemoteLock="REMOTE_LOCK",e.PermissionExpired="PERMISSION_EXPIRED",e.PayloadCorrupted="PAYLOAD_CORRUPTED",e.PayloadSignatureVerificationFailed="PAYLOAD_SIGNATURE_VERIFICATION_FAILED",e.IncorrectTokenState="INCORRECT_TOKEN_STATE"}(ce||(ce={})),function(e){e[e.Ok=0]="Ok",e[e.NetworkError=1]="NetworkError",e[e.RemoteLock=2]="RemoteLock",e[e.PermissionExpired=3]="PermissionExpired",e[e.PayloadCorrupted=4]="PayloadCorrupted",e[e.PayloadSignatureVerificationFailed=5]="PayloadSignatureVerificationFailed",e[e.IncorrectTokenState=6]="IncorrectTokenState"}(le||(le={})),function(e){e[e.Fail=0]="Fail",e[e.Success=1]="Success",e[e.CameraTooHigh=2]="CameraTooHigh",e[e.FallbackSuccess=3]="FallbackSuccess",e[e.Partial=4]="Partial",e[e.CameraAtAngle=5]="CameraAtAngle",e[e.CameraTooNear=6]="CameraTooNear",e[e.DocumentTooCloseToEdge=7]="DocumentTooCloseToEdge"}(Me||(Me={})),function(e){e.MediaDevicesNotSupported="MediaDevicesNotSupported",e.CameraNotFound="CameraNotFound",e.CameraNotAllowed="CameraNotAllowed",e.CameraInUse="CameraInUse",e.CameraNotAvailable="CameraNotAvailable",e.VideoElementNotProvided="VideoElementNotProvided"}(ge||(ge={})),function(e){e[e.Recognition=0]="Recognition",e[e.RecognitionTest=1]="RecognitionTest",e[e.DetectionTest=2]="DetectionTest"}(Ne||(Ne={}));class he{constructor(e,t,i=!1,r=!1,o=null){this.deviceId=null,this.videoFeed=null,this.cancelled=!1,this.timedOut=!1,this.recognitionPaused=!1,this.recognitionTimeoutMs=2e4,this.timeoutID=0,this.videoRecognitionMode=Ne.Recognition,this.onScanningDone=null,this.allowManualVideoPlayout=!1,this.cameraFlipped=!1,this.shouldReleaseVideoFeed=!1,this.videoFeed=e,this.recognizerRunner=t,this.cameraFlipped=i,this.allowManualVideoPlayout=r,this.deviceId=o}static createVideoRecognizerFromCameraStream(e,t,i=null,r=H.BackFacingCamera){return g(this,void 0,void 0,(function*(){return new Promise(((o,a)=>g(this,void 0,void 0,(function*(){if(e&&e instanceof Element)if(navigator.mediaDevices&&void 0!==navigator.mediaDevices.getUserMedia)try{const s=yield $(i,r);if(null===s)return void a(new Z(Y.cameraMissing,{reason:ge.CameraNotFound}));const n=yield q(s,e,r);yield t.setCameraPreviewMirrored(n),o(new he(e,t,n,!1,s.deviceId))}catch(e){let t=ge.CameraInUse,i=j.VIDEO_RECOGNIZER_CAMERA_IN_USE;switch(e.name){case"NotFoundError":case"OverconstrainedError":t=ge.CameraNotFound,i=j.VIDEO_RECOGNIZER_CAMERA_MISSING;break;case"NotAllowedError":case"SecurityError":t=ge.CameraNotAllowed,i=j.VIDEO_RECOGNIZER_CAMERA_NOT_ALLOWED;break;case"AbortError":case"NotReadableError":t=ge.CameraNotAvailable,i=j.VIDEO_RECOGNIZER_CAMERA_UNAVAILABLE;break;case"TypeError":throw e}a(new Z({message:e.message,code:i},{reason:t}))}else a(new Z(Y.mediaDevicesUnsupported,{reason:ge.MediaDevicesNotSupported}));else a(new Z(Y.elementMissing,{reason:ge.VideoElementNotProvided}))}))))}))}static createVideoRecognizerFromVideoPath(e,t,i){return g(this,void 0,void 0,(function*(){return new Promise((r=>{t.src=e,t.currentTime=0,t.onended=()=>{o.cancelRecognition()};const o=new he(t,i);r(o)}))}))}flipCamera(){return g(this,void 0,void 0,(function*(){this.videoFeed&&(this.cameraFlipped?(this.videoFeed.style.transform="scaleX(1)",this.cameraFlipped=!1):(this.videoFeed.style.transform="scaleX(-1)",this.cameraFlipped=!0),yield this.recognizerRunner.setCameraPreviewMirrored(this.cameraFlipped))}))}isCameraFlipped(){return this.cameraFlipped}setVideoRecognitionMode(e){return g(this,void 0,void 0,(function*(){this.videoRecognitionMode=e;const t=this.videoRecognitionMode===Ne.DetectionTest;yield this.recognizerRunner.setDetectionOnlyMode(t)}))}startRecognition(e,t=2e4){return new Promise(((i,r)=>{null!==this.videoFeed?this.videoFeed.paused?(this.cancelled=!1,this.recognitionPaused=!1,this.clearTimeout(),this.recognitionTimeoutMs=t,this.onScanningDone=e,this.recognizerRunner.setClearTimeoutCallback({onClearTimeout:()=>this.clearTimeout()}),this.videoFeed.play().then((()=>this.playPauseEvent().then((()=>i())).catch((e=>r(e)))),(e=>{this.allowManualVideoPlayout?this.videoFeed&&(this.videoFeed.controls=!0,this.videoFeed.addEventListener("play",(()=>{this.playPauseEvent().then().catch((e=>r(e)))})),this.videoFeed.addEventListener("pause",(()=>{this.playPauseEvent().then().catch((e=>r(e)))}))):r(new Z(Y.playRequestInterrupted,e))}))):r(new Z(Y.videoFeedNotPaused)):r(new Z(Y.videoFeedReleased))}))}recognize(e=2e4){return new Promise(((t,i)=>{try{this.startRecognition((e=>{this.pauseVideoFeed(),t(e)}),e).then().catch((e=>i(e)))}catch(e){i(e)}}))}cancelRecognition(){this.cancelled=!0}pauseVideoFeed(){this.pauseRecognition(),this.videoFeed&&this.videoFeed.pause()}pauseRecognition(){this.recognitionPaused=!0}resetRecognizers(e){return g(this,void 0,void 0,(function*(){yield this.recognizerRunner.resetRecognizers(e)}))}getRecognizerRunner(){return this.recognizerRunner}resumeRecognition(e){return new Promise(((t,i)=>{this.cancelled=!1,this.timedOut=!1,this.recognitionPaused=!1,this.videoFeed&&this.videoFeed.paused?i(new Z(Y.feedPaused)):setTimeout((()=>{e?this.resetRecognizers(!0).then((()=>{this.recognitionLoop().then((()=>t())).catch((e=>i(e)))})).catch((()=>{i(new Z(Y.recognizersResetFailure))})):this.recognitionLoop().then((()=>t())).catch((e=>i(e)))}),1)}))}releaseVideoFeed(){var e,t;!this.videoFeed||(null===(e=this.videoFeed)||void 0===e?void 0:e.readyState)<(null===(t=this.videoFeed)||void 0===t?void 0:t.HAVE_CURRENT_DATA)?this.shouldReleaseVideoFeed=!0:(this.videoFeed.paused||this.cancelRecognition(),ee(this.videoFeed),this.videoFeed=null,this.shouldReleaseVideoFeed=!1)}changeCameraDevice(e){return new Promise(((t,i)=>{null!==this.videoFeed?(this.pauseRecognition(),ee(this.videoFeed),q(e,this.videoFeed).then((()=>{null!==this.videoFeed?this.videoFeed.play().then((()=>{this.resumeRecognition(!0),t()}),(e=>{this.allowManualVideoPlayout?this.videoFeed?this.videoFeed.controls=!0:i(new Z(Y.feedMissing)):i(new Z(Y.playRequestInterrupted,e))})):i(new Z(Y.feedMissing))})).catch((e=>i(e)))):i(new Z(Y.feedMissing))}))}playPauseEvent(){return new Promise(((e,t)=>{if(this.videoFeed&&this.videoFeed.paused)return this.cancelRecognition(),void e();this.resumeRecognition(!0).then((()=>e())).catch((e=>t(e)))}))}recognitionLoop(){return new Promise(((e,t)=>{if(!this.videoFeed)return void t(new Z(Y.feedMissing));if(this.shouldReleaseVideoFeed&&this.videoFeed.readyState>this.videoFeed.HAVE_CURRENT_DATA)return this.releaseVideoFeed(),void e();const i=se(this.videoFeed);this.recognizerRunner.processImage(i).then((i=>{const r=()=>{this.recognitionPaused?e():setTimeout((()=>{this.recognitionLoop().then((()=>e())).catch((e=>t(e)))}),1)};if(i===ie.Valid||this.cancelled||this.timedOut){if(this.videoRecognitionMode!==Ne.Recognition&&!this.cancelled)return void this.recognizerRunner.resetRecognizers(!0).then((()=>{this.clearTimeout(),r()})).catch((e=>t(e)));this.clearTimeout(),this.onScanningDone&&this.onScanningDone(i)}else{if(i===ie.Uncertain)return 0===this.timeoutID&&(this.timeoutID=window.setTimeout((()=>{this.timedOut=!0}),this.recognitionTimeoutMs)),void r();if(i===ie.StageValid)return this.clearTimeout(),void r()}r()})).catch((e=>t(e)))}))}clearTimeout(){this.timeoutID>0&&(window.clearTimeout(this.timeoutID),this.timeoutID=0)}}class ue{constructor(e){if(this.allowHelloMessage=!0,this.engineLocation="",this.wasmType=null,this.numberOfWorkers=null,this.loadProgressCallback=null,this.wasmModuleName="BlinkInputWasmSDK",!e)throw new Z(G.licenseKeyMissing);this.licenseKey=e}}function je(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16)))}function me(e){return g(this,void 0,void 0,(function*(){return new Promise(((t,i)=>{if(!e||"object"!=typeof e)return void i(new Z(G.wasmSettingsMissing));if("string"!=typeof e.licenseKey)return void i(new Z(G.licenseKeyMissing));if(!e.wasmModuleName)return void i(new Z(G.wasmModuleNameMissing));if("string"!=typeof e.engineLocation)return void i(new Z(G.engineLocationInvalid));const r=function(){try{let e=localStorage.getItem("mb-user-id");return null===e&&(e=je(),localStorage.setItem("mb-user-id",e)),e}catch(e){return je()}}();try{const o=new Blob([String.raw`!function(){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function e(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}c((n=n.apply(e,t||[])).next())}))}let t=0;class s{constructor(e){this.action=e,this.messageID=function(){const e=t;return t+=1,e}()}}class n extends s{constructor(e,t){super(n.action),this.wasmModuleName=e.wasmModuleName,this.licenseKey=e.licenseKey,this.userId=t,this.registerLoadCallback=null!==e.loadProgressCallback,this.allowHelloMessage=e.allowHelloMessage,this.engineLocation=e.engineLocation,this.wasmType=e.wasmType,this.numberOfWorkers=e.numberOfWorkers}}var r,i;n.action="init",function(e){e[e.Any=0]="Any",e[e.Recognizer=1]="Recognizer",e[e.RecognizerSettings=2]="RecognizerSettings",e[e.Callback=3]="Callback"}(r||(r={}));class o extends s{constructor(e,t){super(o.action),this.funcName=e,this.params=t}}o.action="invokeFunction";class a extends s{constructor(e,t){super(a.action),this.className=e,this.params=t}}a.action="createNewNativeObject";class c extends s{constructor(e,t,s){super(c.action),this.recognizerHandles=e,this.allowMultipleResults=t,this.registeredMetadataCallbacks=s}}c.action="createRecognizerRunner";class E extends s{constructor(e,t){super(E.action),this.recognizerHandles=e,this.allowMultipleResults=t}}E.action="reconfigureRecognizerRunner";class R extends s{constructor(){super(R.action)}}R.action="deleteRecognizerRunner";class l extends s{constructor(e,t,s){super(l.action),this.objectHandle=e,this.methodName=t,this.params=s}}l.action="invokeObject";class _ extends s{constructor(e){super(_.action),this.frame=e}getTransferrables(){return[this.frame.imageData.data.buffer]}}_.action="processImage";class u extends s{constructor(e){super(u.action),this.hardReset=e}}u.action="resetRecognizers";class I extends s{constructor(e){super(I.action),this.registeredMetadataCallbacks=e}}I.action="registerMetadataCallbacks";class d extends s{constructor(e){super(d.action),this.detectionOnlyMode=e}}d.action="setDetectionOnly";class N extends s{constructor(e){super(N.action),this.callbackNonEmpty=e}}N.action="setClearTimeoutCallback";class O extends s{constructor(e){super(O.action),this.cameraPreviewMirrored=e}}O.action="setCameraPreviewMirrored";class h{constructor(e,t,s){this.success=!0,this.error=null,this.messageID=e,this.success=t,this.error=s}}class S{constructor(e,t,s,n){this.success=!0,this.showOverlay=!0,this.messageID=e,this.success=t,this.showOverlay=s,this.wasmType=n}}class g extends h{constructor(e,t){super(e,!0,null),this.result=t}}class C extends h{constructor(e,t){super(e,!0,null),this.objectHandle=t}}class m extends h{constructor(e,t){super(e,!0,null),this.recognitionState=t}}class A{constructor(e){this.isLoadProgressMessage=!0,this.progress=e}}!function(e){e[e.onDebugText=0]="onDebugText",e[e.onDetectionFailed=1]="onDetectionFailed",e[e.onQuadDetection=2]="onQuadDetection",e[e.onPointsDetection=3]="onPointsDetection",e[e.onFirstSideResult=4]="onFirstSideResult",e[e.clearTimeoutCallback=5]="clearTimeoutCallback",e[e.onGlare=6]="onGlare",e[e.recognizerCallback=7]="recognizerCallback"}(i||(i={}));class D{constructor(e,t){this.isCallbackMessage=!0,this.callbackType=e,this.callbackParameters=t}}function f(e,t){return t=t||"",""===(e=e||"")?t:e.endsWith("/")?t.startsWith("/")?e+t.substring(1):e+t:t.startsWith("/")?e+t:e+"/"+t}var M,L,y;function w(t){return e(this,void 0,void 0,(function*(){const e=yield(async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,3,1,0,1,10,14,1,12,0,65,0,65,0,65,0,252,10,0,0,11])))(),s=yield(async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,12,1,10,0,67,0,0,0,0,252,0,26,11])))(),n=yield(async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,8,1,6,0,65,0,192,26,11])))(),r=yield(async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11])))(),i=yield(async e=>{try{return"undefined"!=typeof MessageChannel&&(new MessageChannel).port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(e)}catch(e){return!1}})(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11]));if(!(e&&s&&n&&r))return M.Basic;if(!i)return M.Advanced;try{return new Worker(t+"/Worker.test.js").terminate(),M.AdvancedWithThreads}catch(e){return M.Advanced}}))}!function(e){e.Basic="BASIC",e.Advanced="ADVANCED",e.AdvancedWithThreads="ADVANCED_WITH_THREADS"}(M||(M={}));class T{constructor(e,t){if(!e.code||!e.message)throw Error("Instance of SDKError is required to have code and message.");this.message=e.message,this.code=e.code,this.details=t}}!function(e){e.WORKER_WASM_LOAD_FAILURE="WORKER_WASM_LOAD_FAILURE",e.WORKER_WASM_INIT_MISSING="WORKER_WASM_INIT_MISSING",e.WORKER_FUNCTION_INVOKE_FAILURE="WORKER_FUNCTION_INVOKE_FAILURE",e.WORKER_RECOGNIZER_CREATION_FAILURE="WORKER_RECOGNIZER_CREATION_FAILURE",e.WORKER_RUNNER_EXISTS="WORKER_RUNNER_EXISTS",e.WORKER_RUNNER_CREATION_FAILURE="WORKER_RUNNER_CREATION_FAILURE",e.WORKER_RUNNER_MISSING="WORKER_RUNNER_MISSING",e.WORKER_RUNNER_RECONFIGURE_FAILURE="WORKER_RUNNER_RECONFIGURE_FAILURE",e.WORKER_RUNNER_DELETED="WORKER_RUNNER_DELETED",e.WORKER_RUNNER_DELETE_FAILURE="WORKER_RUNNER_DELETE_FAILURE",e.WORKER_OBJECT_INVOKE_FAILURE="WORKER_OBJECT_INVOKE_FAILURE",e.WORKER_IMAGE_PROCESS_FAILURE="WORKER_IMAGE_PROCESS_FAILURE",e.WORKER_HANDLE_UNDEFINED="WORKER_HANDLE_UNDEFINED",e.WORKER_MESSAGE_ACTION_UNKNOWN="WORKER_MESSAGE_ACTION_UNKNOWN",e.WORKER_LICENSE_UNLOCK_ERROR="WORKER_LICENSE_UNLOCK_ERROR",e.LOCAL_SDK_RUNNER_MISSING="LOCAL_SDK_RUNNER_MISSING",e.LOCAL_SDK_RUNNER_EMPTY="LOCAL_SDK_RUNNER_EMPTY",e.LICENSE_UNLOCK_ERROR="LICENSE_UNLOCK_ERROR",e.FRAME_CAPTURE_SVG_UNSUPPORTED="FRAME_CAPTURE_SVG_UNSUPPORTED",e.FRAME_CAPTURE_CANVAS_MISSING="FRAME_CAPTURE_CANVAS_MISSING",e.SDK_WASM_SETTINGS_MISSING="SDK_WASM_SETTINGS_MISSING",e.SDK_LICENSE_KEY_MISSING="SDK_LICENSE_KEY_MISSING",e.SDK_WASM_MODULE_NAME_MISSING="SDK_WASM_MODULE_NAME_MISSING",e.SDK_ENGINE_LOCATION_INVALID="SDK_ENGINE_LOCATION_INVALID",e.SDK_MISSING="SDK_MISSING",e.SDK_RECOGNIZERS_MISSING="SDK_RECOGNIZERS_MISSING",e.VIDEO_RECOGNIZER_ELEMENT_MISSING="VIDEO_RECOGNIZER_ELEMENT_MISSING",e.VIDEO_RECOGNIZER_CAMERA_MISSING="VIDEO_RECOGNIZER_CAMERA_MISSING",e.VIDEO_RECOGNIZER_CAMERA_NOT_ALLOWED="VIDEO_RECOGNIZER_CAMERA_NOT_ALLOWED",e.VIDEO_RECOGNIZER_CAMERA_UNAVAILABLE="VIDEO_RECOGNIZER_CAMERA_UNAVAILABLE",e.VIDEO_RECOGNIZER_CAMERA_IN_USE="VIDEO_RECOGNIZER_CAMERA_IN_USE",e.VIDEO_RECOGNIZER_MEDIA_DEVICES_UNSUPPORTED="VIDEO_RECOGNIZER_MEDIA_DEVICES_UNSUPPORTED",e.VIDEO_RECOGNIZER_FEED_RELEASED="VIDEO_RECOGNIZER_FEED_RELEASED",e.VIDEO_RECOGNIZER_FEED_NOT_PAUSED="VIDEO_RECOGNIZER_FEED_NOT_PAUSED",e.VIDEO_RECOGNIZER_PLAY_REQUEST_INTERRUPTED="VIDEO_RECOGNIZER_PLAY_REQUEST_INTERRUPTED",e.VIDEO_RECOGNIZER_FEED_PAUSED="VIDEO_RECOGNIZER_FEED_PAUSED",e.VIDEO_RECOGNIZER_RECOGNIZERS_RESET_FAILURE="VIDEO_RECOGNIZER_RECOGNIZERS_RESET_FAILURE",e.VIDEO_RECOGNIZER_FEED_MISSING="VIDEO_RECOGNIZER_FEED_MISSING"}(L||(L={})),function(e){e.WORKER_HANDLE_UNDEFINED="Cannot find object with handle: undefined",e.WORKER_WASM_LOAD_FAILURE="Failed to load WASM in web worker!",e.WORKER_WASM_INIT_MISSING="WASM module is not initialized!",e.WORKER_FUNCTION_INVOKE_FAILURE="Failed to invoke function!",e.WORKER_RECOGNIZER_CREATION_FAILURE="Failed to create new recognizer!",e.WORKER_RUNNER_EXISTS="Recognizer runner is already created! Multiple instances are not allowed!",e.WORKER_RUNNER_CREATION_FAILURE="Failed to create new recognizer runner!",e.WORKER_RUNNER_MISSING="Recognizer runner is not created! There is nothing to reconfigure!",e.WORKER_RUNNER_RECONFIGURE_FAILURE="Failed to reconfigure recognizer runner!",e.WORKER_RUNNER_DELETED="Recognizer runner is already deleted!",e.WORKER_RUNNER_DELETE_FAILURE="Failed to delete recognizer runner!",e.WORKER_OBJECT_INVOKE_FAILURE="Failed to invoke object!",e.WORKER_IMAGE_PROCESS_FAILURE="Recognizer runner is not initialized! Cannot process image!",e.LOCAL_SDK_RUNNER_MISSING="Property nativeRecognizerRunner is not available!",e.LOCAL_SDK_RUNNER_EMPTY="Native RecognizerRunner cannot be empty!",e.LICENSE_TOKEN_STATE_INCORRECT="Internal error (Incorrect token state)",e.LICENSE_PAYLOAD_VERIFICATION_FAILED="Failed to verify server permission's digital signature!",e.LICENSE_PAYLOAD_CORRUPTED="Server permission payload is corrupted!",e.LICENSE_PERMISSION_EXPIRED="Internal error (server permission expired)",e.LICENSE_REMOTE_LOCKED="Provided license key has been remotely locked. Please contact support for more information!",e.FRAME_CAPTURE_SVG_UNSUPPORTED="Recognition of SVG elements not supported!",e.FRAME_CAPTURE_CANVAS_MISSING="Could not get canvas 2d context!",e.SDK_WASM_SETTINGS_MISSING="Missing WASM load settings!",e.SDK_LICENSE_KEY_MISSING="Missing license key!",e.SDK_WASM_MODULE_NAME_MISSING="Missing WASM module name!",e.SDK_ENGINE_LOCATION_INVALID="Setting property 'engineLocation' must be a string!",e.SDK_MISSING="SDK is not provided!",e.SDK_RECOGNIZERS_MISSING="To create RecognizerRunner at least 1 recognizer is required.",e.VIDEO_RECOGNIZER_ELEMENT_MISSING="Video element, i.e. camera feed is not provided!",e.VIDEO_RECOGNIZER_CAMERA_MISSING="Camera not found!",e.VIDEO_RECOGNIZER_CAMERA_NOT_ALLOWED="Camera not allowed!",e.VIDEO_RECOGNIZER_CAMERA_UNAVAILABLE="Camera not available!",e.VIDEO_RECOGNIZER_CAMERA_IN_USE="Camera in use!",e.VIDEO_RECOGNIZER_MEDIA_DEVICES_UNSUPPORTED="Media devices not supported by browser.",e.VIDEO_RECOGNIZER_FEED_RELEASED="The associated video feed has been released!",e.VIDEO_RECOGNIZER_FEED_NOT_PAUSED="The associated video feed is not paused. Use resumeRecognition instead!",e.VIDEO_RECOGNIZER_PLAY_REQUEST_INTERRUPTED="The play() request was interrupted or prevented by browser security rules!",e.VIDEO_RECOGNIZER_FEED_PAUSED="Cannot resume recognition while video feed is paused! Use recognize or startRecognition",e.VIDEO_RECOGNIZER_RECOGNIZERS_RESET_FAILURE="Could not reset recognizers!",e.VIDEO_RECOGNIZER_FEED_MISSING="Missing video feed!"}(y||(y={}));const p={licenseTokenStateIncorrect:{code:L.LICENSE_UNLOCK_ERROR,message:y.LICENSE_TOKEN_STATE_INCORRECT},licensePayloadVerificationFailed:{code:L.LICENSE_UNLOCK_ERROR,message:y.LICENSE_PAYLOAD_VERIFICATION_FAILED},licensePayloadCorrupted:{code:L.LICENSE_UNLOCK_ERROR,message:y.LICENSE_PAYLOAD_CORRUPTED},licensePermissionExpired:{code:L.LICENSE_UNLOCK_ERROR,message:y.LICENSE_PERMISSION_EXPIRED},licenseRemoteLocked:{code:L.LICENSE_UNLOCK_ERROR,message:y.LICENSE_REMOTE_LOCKED},licenseNetworkError:{code:L.LICENSE_UNLOCK_ERROR},licenseInvalid:{code:L.LICENSE_UNLOCK_ERROR}},U={imageProcessFailure:{message:y.WORKER_IMAGE_PROCESS_FAILURE,code:L.WORKER_IMAGE_PROCESS_FAILURE},objectInvokeFailure:{message:y.WORKER_OBJECT_INVOKE_FAILURE,code:L.WORKER_OBJECT_INVOKE_FAILURE},runnerDeleteFailure:{message:y.WORKER_RUNNER_DELETE_FAILURE,code:L.WORKER_RUNNER_DELETE_FAILURE},runnerDeleted:{message:y.WORKER_RUNNER_DELETED,code:L.WORKER_RUNNER_DELETED},runnerReconfigureFailure:{message:y.WORKER_RUNNER_RECONFIGURE_FAILURE,code:L.WORKER_RUNNER_RECONFIGURE_FAILURE},runnerMissing:{message:y.WORKER_RUNNER_MISSING,code:L.WORKER_RUNNER_MISSING},runnerCreationFailure:{message:y.WORKER_RUNNER_CREATION_FAILURE,code:L.WORKER_RUNNER_CREATION_FAILURE},runnerExists:{message:y.WORKER_RUNNER_EXISTS,code:L.WORKER_RUNNER_EXISTS},recognizerCreationFailure:{message:y.WORKER_RECOGNIZER_CREATION_FAILURE,code:L.WORKER_RECOGNIZER_CREATION_FAILURE},functionInvokeFailure:{message:y.WORKER_FUNCTION_INVOKE_FAILURE,code:L.WORKER_FUNCTION_INVOKE_FAILURE},wasmInitMissing:{message:y.WORKER_WASM_INIT_MISSING,code:L.WORKER_WASM_INIT_MISSING},wasmLoadFailure:{message:y.WORKER_WASM_LOAD_FAILURE,code:L.WORKER_WASM_LOAD_FAILURE},handleUndefined:{message:y.WORKER_HANDLE_UNDEFINED,code:L.WORKER_HANDLE_UNDEFINED}};var b,F;!function(e){e[e.Invalid=0]="Invalid",e[e.RequiresServerPermission=1]="RequiresServerPermission",e[e.Valid=2]="Valid"}(b||(b={})),function(e){e.LicenseTokenStateInvalid="LICENSE_TOKEN_STATE_INVALID",e.NetworkError="NETWORK_ERROR",e.RemoteLock="REMOTE_LOCK",e.PermissionExpired="PERMISSION_EXPIRED",e.PayloadCorrupted="PAYLOAD_CORRUPTED",e.PayloadSignatureVerificationFailed="PAYLOAD_SIGNATURE_VERIFICATION_FAILED",e.IncorrectTokenState="INCORRECT_TOKEN_STATE"}(F||(F={}));function k(e){return{licenseId:e.licenseId,licensee:e.licensee,packageName:e.packageName,platform:"Browser",sdkName:e.sdkName,sdkVersion:e.sdkVersion}}var K;function v(t,s){return e(this,void 0,void 0,(function*(){try{const e=yield fetch("https://baltazar.microblink.com/api/v1/status/check",{method:"POST",headers:{"Content-Type":"application/json"},cache:"no-cache",body:JSON.stringify(k(t))});if(e.ok){const t=""+(yield e.text());return s.submitServerPermission(t)}return{status:K.NetworkError,lease:0,networkErrorDescription:"Server responded with status "+e.status}}catch(e){return{status:K.NetworkError,lease:0,networkErrorDescription:"Unexpected error: "+JSON.stringify(e)}}}))}function P(e){return e===M.AdvancedWithThreads}!function(e){e[e.Ok=0]="Ok",e[e.NetworkError=1]="NetworkError",e[e.RemoteLock=2]="RemoteLock",e[e.PermissionExpired=3]="PermissionExpired",e[e.PayloadCorrupted=4]="PayloadCorrupted",e[e.PayloadSignatureVerificationFailed=5]="PayloadSignatureVerificationFailed",e[e.IncorrectTokenState=6]="IncorrectTokenState"}(K||(K={}));new class{constructor(){this.context=self,this.wasmModule=null,this.nativeRecognizerRunner=null,this.objects={},this.nextObjectHandle=0,this.metadataCallbacks={},this.clearTimeoutCallback=null,this.context.onmessage=e=>{const t=e.data;switch(t.action){case n.action:this.processInitMessage(t);break;case o.action:this.processInvokeFunction(t);break;case a.action:this.processCreateNewRecognizer(t);break;case l.action:this.processInvokeObject(t);break;case c.action:this.processCreateRecognizerRunner(t);break;case E.action:this.processReconfigureRecognizerRunner(t);break;case R.action:this.processDeleteRecognizerRunner(t);break;case _.action:this.processImage(t);break;case u.action:this.resetRecognizers(t);break;case d.action:this.setDetectionOnly(t);break;case O.action:this.setCameraPreviewMirrored(t);break;case I.action:this.registerMetadataCallbacks(t);break;case N.action:this.registerClearTimeoutCallback(t);break;default:throw new T({code:L.WORKER_MESSAGE_ACTION_UNKNOWN,message:"Unknown message action: "+JSON.stringify(t.action)})}}}getNextObjectHandle(){const e=this.nextObjectHandle;return this.nextObjectHandle=this.nextObjectHandle+1,e}notifyError(e,t){this.context.postMessage(new h(e.messageID,!1,t))}notifySuccess(e){this.context.postMessage(new h(e.messageID,!0,null))}notifyInitSuccess(e,t,s){this.context.postMessage(new S(e.messageID,!0,t,s))}unwrapParameters(e){const t=[];for(const s of e.params){let n=s.parameter;s.type===r.Recognizer?(n=this.objects[n],void 0===n&&this.notifyError(e,new T(U.handleUndefined))):s.type===r.RecognizerSettings&&(n=this.restoreFunctions(n)),t.push(n)}return t}restoreFunctions(e){const t=Object.keys(e);for(const s of t){const t=e[s];"object"==typeof t&&null!==t&&"parameter"in t&&"type"in t&&t.type===r.Callback&&(e[s]=(...e)=>{const s=new D(i.recognizerCallback,[t.parameter].concat(e));this.context.postMessage(s)})}return e}scanForTransferrables(e){if("object"==typeof e){const t=Object.keys(e),s=[];for(const n of t){const t=e[n];t instanceof ImageData?s.push(t.data.buffer):t instanceof Uint8Array?s.push(t.buffer):null!==t&&"object"==typeof t&&s.push(...this.scanF