UNPKG

@microblink/blinkcard-in-browser-sdk

Version:

BlinkCard SDK is credit or payment cards scanning library for WebAssembly-enabled browsers.

2 lines (1 loc) 27 kB
!function(){"use strict";let e=0;class t{constructor(t){this.action=t,this.messageID=function(){const t=e;return e+=1,t}()}}class s extends t{constructor(e,t){super(s.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.wasmFlavor=e.wasmFlavor,this.numberOfWorkers=e.numberOfWorkers}}var r,n;s.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 i extends t{constructor(e,t){super(i.action),this.funcName=e,this.params=t}}i.action="invokeFunction";class a extends t{constructor(e,t){super(a.action),this.className=e,this.params=t}}a.action="createNewNativeObject";class o extends t{constructor(e,t,s){super(o.action),this.recognizerHandles=e,this.allowMultipleResults=t,this.registeredMetadataCallbacks=s}}o.action="createRecognizerRunner";class c extends t{constructor(e,t){super(c.action),this.recognizerHandles=e,this.allowMultipleResults=t}}c.action="reconfigureRecognizerRunner";class E extends t{constructor(){super(E.action)}}E.action="deleteRecognizerRunner";class R extends t{constructor(e,t,s){super(R.action),this.objectHandle=e,this.methodName=t,this.params=s}}R.action="invokeObject";class l extends t{constructor(e){super(l.action),this.frame=e}getTransferrables(){return[this.frame.imageData.data.buffer]}}l.action="processImage";class _ extends t{constructor(e){super(_.action),this.hardReset=e}}_.action="resetRecognizers";class I extends t{constructor(e){super(I.action),this.registeredMetadataCallbacks=e}}I.action="registerMetadataCallbacks";class u extends t{constructor(e){super(u.action),this.detectionOnlyMode=e}}u.action="setDetectionOnly";class d extends t{constructor(e){super(d.action),this.callbackNonEmpty=e}}d.action="setClearTimeoutCallback";class N extends t{constructor(e){super(N.action),this.cameraPreviewMirrored=e}}N.action="setCameraPreviewMirrored";class O extends t{constructor(e){super(O.action),this.userId=e}}O.action="getProductIntegrationInfo";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,r){this.success=!0,this.showOverlay=!0,this.messageID=e,this.success=t,this.showOverlay=s,this.wasmType=r}}class g extends h{constructor(e,t){super(e,!0,null),this.result=t}}class m extends h{constructor(e,t){super(e,!0,null),this.objectHandle=t}}class C extends h{constructor(e,t){super(e,!0,null),this.recognitionState=t}}class A extends h{constructor(e,t){super(e,!0,null),this.result=t}}class D{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"}(n||(n={}));class f{constructor(e,t){this.isCallbackMessage=!0,this.callbackType=e,this.callbackParameters=t}}function w(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 p,L,M;async function T(){if(!await(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])))return!1;if(!("importScripts"in self))throw Error("Not implemented");return!function(){const e=navigator.userAgent.toLowerCase();return e.includes("safari")&&!e.includes("chrome")}()&&"Worker"in self}async function F(){const e=await(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])))(),t=await T();return e?t?p.AdvancedWithThreads:p.Advanced:p.Basic}!function(e){e.Basic="BASIC",e.Advanced="ADVANCED",e.AdvancedWithThreads="ADVANCED_WITH_THREADS"}(p||(p={}));class y extends Error{constructor(e,t){if(super(),!e.code||!e.message)throw Error("Instance of SDKError is required to have code and message.");if(this.message=e.message,this.code=e.code,e instanceof U&&e.details&&"message"in e.details){const t=Error(e.details.message);"stack"in e.details&&(t.stack=e.details.stack),this.details=t}else this.details=t}}class U{constructor(e,t){if(!e.code||!e.message)throw Error("Instance of SerializableSDKError is required to have code and message.");this.message=e.message,this.code=e.code,this.details=t instanceof Error?new k(t):t}}class k{constructor(e){this.message=e.message,this.name=e.name,this.stack=e.stack}}!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.WORKER_INTEGRATION_INFO_FAILURE="WORKER_INTEGRATION_INFO_FAILURE",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_WORKER_LOCATION_INVALID="SDK_WORKER_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.WORKER_INTEGRATION_INFO_FAILURE="Failed to get product integration info!",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_WORKER_LOCATION_INVALID="Setting property 'workerLocation' 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 b={licenseTokenStateIncorrect:{code:L.LICENSE_UNLOCK_ERROR,message:M.LICENSE_TOKEN_STATE_INCORRECT},licensePayloadVerificationFailed:{code:L.LICENSE_UNLOCK_ERROR,message:M.LICENSE_PAYLOAD_VERIFICATION_FAILED},licensePayloadCorrupted:{code:L.LICENSE_UNLOCK_ERROR,message:M.LICENSE_PAYLOAD_CORRUPTED},licensePermissionExpired:{code:L.LICENSE_UNLOCK_ERROR,message:M.LICENSE_PERMISSION_EXPIRED},licenseRemoteLocked:{code:L.LICENSE_UNLOCK_ERROR,message:M.LICENSE_REMOTE_LOCKED},licenseNetworkError:{code:L.LICENSE_UNLOCK_ERROR},licenseInvalid:{code:L.LICENSE_UNLOCK_ERROR}},K={imageProcessFailure:{message:M.WORKER_IMAGE_PROCESS_FAILURE,code:L.WORKER_IMAGE_PROCESS_FAILURE},objectInvokeFailure:{message:M.WORKER_OBJECT_INVOKE_FAILURE,code:L.WORKER_OBJECT_INVOKE_FAILURE},runnerDeleteFailure:{message:M.WORKER_RUNNER_DELETE_FAILURE,code:L.WORKER_RUNNER_DELETE_FAILURE},runnerDeleted:{message:M.WORKER_RUNNER_DELETED,code:L.WORKER_RUNNER_DELETED},runnerReconfigureFailure:{message:M.WORKER_RUNNER_RECONFIGURE_FAILURE,code:L.WORKER_RUNNER_RECONFIGURE_FAILURE},runnerMissing:{message:M.WORKER_RUNNER_MISSING,code:L.WORKER_RUNNER_MISSING},runnerCreationFailure:{message:M.WORKER_RUNNER_CREATION_FAILURE,code:L.WORKER_RUNNER_CREATION_FAILURE},runnerExists:{message:M.WORKER_RUNNER_EXISTS,code:L.WORKER_RUNNER_EXISTS},recognizerCreationFailure:{message:M.WORKER_RECOGNIZER_CREATION_FAILURE,code:L.WORKER_RECOGNIZER_CREATION_FAILURE},functionInvokeFailure:{message:M.WORKER_FUNCTION_INVOKE_FAILURE,code:L.WORKER_FUNCTION_INVOKE_FAILURE},wasmInitMissing:{message:M.WORKER_WASM_INIT_MISSING,code:L.WORKER_WASM_INIT_MISSING},wasmLoadFailure:{message:M.WORKER_WASM_LOAD_FAILURE,code:L.WORKER_WASM_LOAD_FAILURE},handleUndefined:{message:M.WORKER_HANDLE_UNDEFINED,code:L.WORKER_HANDLE_UNDEFINED},integrationInfoFailure:{message:M.WORKER_INTEGRATION_INFO_FAILURE,code:L.WORKER_INTEGRATION_INFO_FAILURE}};var P,W;!function(e){e[e.Invalid=0]="Invalid",e[e.RequiresServerPermission=1]="RequiresServerPermission",e[e.Valid=2]="Valid"}(P||(P={})),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"}(W||(W={}));function G(e){return{licenseId:e.licenseId,licensee:e.licensee,applicationIds:e.applicationIds,packageName:e.packageName,platform:"Browser",sdkName:e.sdkName,sdkVersion:e.sdkVersion}}var v;async function V(e,t){try{const s=await fetch("https://baltazar.microblink.com/api/v2/status/check",{method:"POST",headers:{"Content-Type":"application/json"},cache:"no-cache",body:JSON.stringify(G(e))});if(s.ok){const e=""+await s.text();return t.submitServerPermission(e)}return{status:v.NetworkError,lease:0,networkErrorDescription:"Server responded with status "+s.status}}catch(e){return{status:v.NetworkError,lease:0,networkErrorDescription:"Unexpected error: "+JSON.stringify(e)}}}function z(e){return e===p.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"}(v||(v={}));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 s.action:this.processInitMessage(t);break;case i.action:this.processInvokeFunction(t);break;case a.action:this.processCreateNewRecognizer(t);break;case R.action:this.processInvokeObject(t);break;case o.action:this.processCreateRecognizerRunner(t);break;case c.action:this.processReconfigureRecognizerRunner(t);break;case E.action:this.processDeleteRecognizerRunner(t);break;case l.action:this.processImage(t);break;case _.action:this.resetRecognizers(t);break;case u.action:this.setDetectionOnly(t);break;case N.action:this.setCameraPreviewMirrored(t);break;case I.action:this.registerMetadataCallbacks(t);break;case d.action:this.registerClearTimeoutCallback(t);break;case O.action:this.processGetProductIntegrationInfo(t);break;default:throw new y({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){let s=null;s=t instanceof y?new U({code:t.code,message:t.message},t.details):t,this.context.postMessage(new h(e.messageID,!1,s))}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 y(K.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 f(n.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 r of t){const t=e[r];t instanceof ImageData?s.push(t.data.buffer):t instanceof Uint8Array?s.push(t.buffer):null!==t&&"object"==typeof t&&s.push(...this.scanForTransferrables(t))}return s}return[]}registerHeartBeat(e){this.unregisterHeartBeat(),this.lease=e;let t=e-Math.floor(Date.now()/1e3);t>120?t-=120:t/=2,this.inFlightHeartBeatTimeoutId=setTimeout(()=>{this.obtainNewServerPermission(!0)},1e3*t)}unregisterHeartBeat(){this.lease&&delete this.lease,this.inFlightHeartBeatTimeoutId&&(clearTimeout(this.inFlightHeartBeatTimeoutId),delete this.inFlightHeartBeatTimeoutId)}async obtainNewServerPermission(e){if(this.wasmModule){const t=this.wasmModule.getActiveLicenseTokenInfo(),s=await V(t,this.wasmModule);switch(s.status){case v.Ok:case v.RemoteLock:this.registerHeartBeat(s.lease);break;case v.NetworkError:case v.PayloadSignatureVerificationFailed:case v.PayloadCorrupted:e?(console.warn("Problem with obtaining server permission. Will attempt in 10 seconds "+v[s.status]),this.inFlightHeartBeatTimeoutId=setTimeout(()=>{this.obtainNewServerPermission(!1)},1e4)):console.error("Problem with obtaining server permission. "+v[s.status]);break;case v.IncorrectTokenState:case v.PermissionExpired:console.error("Internal error: "+v[s.status])}return s.status}return console.error("Internal inconsistency! Wasm module not initialized where it's expected to be!"),v.IncorrectTokenState}willSoonExpire(){if(this.lease){if(this.wasmModule.getActiveLicenseTokenInfo().unlockResult===P.Valid){const e=Math.floor(Date.now()/1e3);return 30>this.lease-e}return!0}return!1}async calculateWasmType(e){return null!==e.wasmType?e.wasmType:await F()}calculateEngineLocationPrefix(e,t){let s=""===e.engineLocation?self.location.origin:e.engineLocation;""!==e.wasmFlavor&&(s=w(s,e.wasmFlavor));const r=w(s,function(e){switch(e){case p.AdvancedWithThreads:return"advanced-threads";case p.Advanced:return"advanced";case p.Basic:return"basic"}}(t));return e.allowHelloMessage&&console.log("Engine location prefix is:",r),r}async processInitMessage(e){const t=await this.calculateWasmType(e),s=this.calculateEngineLocationPrefix(e,t);let r={locateFile:e=>w(s,e),noExitRuntime:!0};e.registerLoadCallback&&(r=Object.assign(r,{setStatus:e=>{const t=new D(function(e){if("Running..."===e)return 100;if(0===e.length)return 0;const t=RegExp(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/).exec(e);if(t)return 100*parseInt(t[2])/parseInt(t[4]);return NaN}(e));this.context.postMessage(t)}}));try{const n=w(s,e.wasmModuleName+".js");z(t)&&(r=function(e,t,s){return t&&t>0&&(e=Object.assign(e,{allowedThreads:t})),null!==s&&(e=Object.assign(e,{mainScriptUrlOrBlob:s})),e}(r,e.numberOfWorkers,n)),importScripts(n);(0,self[e.wasmModuleName])(r).then(async s=>{z(t)&&(e.allowHelloMessage&&console.log("Waiting for thread workers to boot..."),await async function(e){e.threadWorkersReadyPromise&&await e.threadWorkersReadyPromise}(s));const r=await async function(e,t,s,r){const n=r.initializeWithLicenseKey(e,s,t);switch(n.unlockResult){case P.Invalid:return{error:new y({...b.licenseInvalid,message:n.licenseError},{type:W.LicenseTokenStateInvalid})};case P.Valid:return{error:null,showOverlay:(i=n.isTrial,a=n.allowRemoveDemoOverlay,o=n.allowRemoveProductionOverlay,!(i&&a||!i&&o))};case P.RequiresServerPermission:{const e=await V(n,r);switch(e.status){case v.Ok:return{error:null,lease:e.lease};case v.NetworkError:{let t="";return e.networkErrorDescription&&(t=" "+e.networkErrorDescription),{error:new y({...b.licenseNetworkError,message:"There has been a network error while obtaining the server permission!"+t},{type:W.NetworkError})}}case v.RemoteLock:return{error:new y(b.licenseRemoteLocked,{type:W.RemoteLock}),lease:e.lease};case v.PermissionExpired:return{error:new y(b.licensePermissionExpired,{type:W.PermissionExpired}),lease:e.lease};case v.PayloadCorrupted:return{error:new y(b.licensePayloadCorrupted,{type:W.PayloadCorrupted}),lease:e.lease};case v.PayloadSignatureVerificationFailed:return{error:new y(b.licensePayloadVerificationFailed,{type:W.PayloadSignatureVerificationFailed}),lease:e.lease};case v.IncorrectTokenState:return{error:new y(b.licenseTokenStateIncorrect,{type:W.IncorrectTokenState}),lease:e.lease}}}}var i,a,o}(e.licenseKey,e.allowHelloMessage,e.userId,s);null===r.error?(this.wasmModule=s,r.lease?this.registerHeartBeat(r.lease):this.unregisterHeartBeat(),this.notifyInitSuccess(e,!!r.showOverlay,t)):this.notifyError(e,r.error)},t=>{this.notifyError(e,new y(K.wasmLoadFailure,t))})}catch(t){this.notifyError(e,new y(K.wasmLoadFailure,t))}}processInvokeFunction(e){if(null===this.wasmModule)return void this.notifyError(e,new y(K.wasmInitMissing));const t=e.funcName,s=this.unwrapParameters(e);try{const r=this.wasmModule[t](...s);this.context.postMessage(new g(e.messageID,r))}catch(t){this.notifyError(e,new y(K.functionInvokeFailure,t))}}processCreateNewRecognizer(e){if(null===this.wasmModule)return void this.notifyError(e,new y(K.wasmInitMissing));const t=e.className,s=this.unwrapParameters(e);try{const r=new this.wasmModule[t](...s),n=this.getNextObjectHandle();this.objects[n]=r,this.context.postMessage(new m(e.messageID,n))}catch(t){this.notifyError(e,new y(K.recognizerCreationFailure,t))}}getRecognizers(e){const t=[];for(const s of e){t.push(this.objects[s])}return t}async processCreateRecognizerRunner(e){if(null===this.wasmModule)this.notifyError(e,new y(K.wasmInitMissing));else if(null!==this.nativeRecognizerRunner)this.notifyError(e,new y(K.runnerExists));else{this.setupMetadataCallbacks(e.registeredMetadataCallbacks);try{if(this.willSoonExpire()){const t=await this.obtainNewServerPermission(!1);if(t!==v.Ok){const s=v[t];return void this.notifyError(e,new y({code:L.WORKER_LICENSE_UNLOCK_ERROR,message:"Cannot initialize recognizers because of invalid server permission:\n "+s},{type:W[s]}))}}const t=this.getRecognizers(e.recognizerHandles);this.nativeRecognizerRunner=new this.wasmModule.RecognizerRunner(t,e.allowMultipleResults,this.metadataCallbacks),this.notifySuccess(e)}catch(t){this.notifyError(e,new y(K.runnerCreationFailure,t))}}}processReconfigureRecognizerRunner(e){if(null===this.wasmModule)this.notifyError(e,new y(K.wasmInitMissing));else if(null===this.nativeRecognizerRunner)this.notifyError(e,new y(K.runnerMissing));else try{const t=this.getRecognizers(e.recognizerHandles);this.nativeRecognizerRunner.reconfigureRecognizers(t,e.allowMultipleResults),this.notifySuccess(e)}catch(t){this.notifyError(e,new y(K.runnerReconfigureFailure,t))}}processDeleteRecognizerRunner(e){if(null!==this.nativeRecognizerRunner)try{this.nativeRecognizerRunner.delete(),this.nativeRecognizerRunner=null,this.notifySuccess(e)}catch(t){this.notifyError(e,new y(K.runnerDeleteFailure,t))}else this.notifyError(e,new y(K.runnerDeleted))}wrapFunctions(e,t){if("object"!=typeof e)return e;const s={...e},n=Object.keys(s);for(const e of n){if("function"==typeof s[e]){s[e]={parameter:{recognizerHandle:t,callbackName:e},type:r.Callback}}}return s}processInvokeObject(e){try{const t=e.objectHandle,s=e.methodName,r=this.unwrapParameters(e),n=this.objects[t];if(void 0===n)this.notifyError(e,new y({message:"Cannot find object with handle: "+t,code:L.WORKER_HANDLE_UNDEFINED}));else{const i=this.wrapFunctions(n[s](...r),t),a=this.scanForTransferrables(i);"delete"===s&&delete this.objects[t],this.context.postMessage(new g(e.messageID,i),a)}}catch(t){this.notifyError(e,new y(K.objectInvokeFailure,t))}}processImage(e){if(null!==this.nativeRecognizerRunner)try{let t=e.frame;const s=this.nativeRecognizerRunner.processImage(t);this.context.postMessage(new C(e.messageID,s),[t.imageData.data.buffer]),t=null}catch(t){this.notifyError(e,new y(K.imageProcessFailure,t))}else this.notifyError(e,new y(K.imageProcessFailure))}resetRecognizers(e){if(null!==this.nativeRecognizerRunner)try{this.nativeRecognizerRunner.resetRecognizers(e.hardReset),this.notifySuccess(e)}catch(t){this.notifyError(e,new y(K.imageProcessFailure,t))}else this.notifyError(e,new y(K.imageProcessFailure))}setDetectionOnly(e){if(null!==this.nativeRecognizerRunner)try{this.nativeRecognizerRunner.setDetectionOnlyMode(e.detectionOnlyMode),this.notifySuccess(e)}catch(t){this.notifyError(e,new y(K.imageProcessFailure,t))}else this.notifyError(e,new y(K.imageProcessFailure))}setCameraPreviewMirrored(e){if(null!==this.nativeRecognizerRunner)try{this.nativeRecognizerRunner.setCameraPreviewMirrored(e.cameraPreviewMirrored),this.notifySuccess(e)}catch(t){this.notifyError(e,new y(K.imageProcessFailure,t))}else this.notifyError(e,new y(K.imageProcessFailure))}setupMetadataCallbacks(e){e.onDebugText?this.metadataCallbacks.onDebugText=e=>{const t=new f(n.onDebugText,[e]);this.context.postMessage(t)}:delete this.metadataCallbacks.onDebugText,e.onDetectionFailed?this.metadataCallbacks.onDetectionFailed=()=>{const e=new f(n.onDetectionFailed,[]);this.context.postMessage(e)}:delete this.metadataCallbacks.onDetectionFailed,e.onPointsDetection?this.metadataCallbacks.onPointsDetection=e=>{const t=new f(n.onPointsDetection,[e]);this.context.postMessage(t)}:delete this.metadataCallbacks.onPointsDetection,e.onQuadDetection?this.metadataCallbacks.onQuadDetection=e=>{const t=new f(n.onQuadDetection,[e]);this.context.postMessage(t)}:delete this.metadataCallbacks.onQuadDetection,e.onFirstSideResult?this.metadataCallbacks.onFirstSideResult=()=>{const e=new f(n.onFirstSideResult,[]);this.context.postMessage(e)}:delete this.metadataCallbacks.onFirstSideResult,e.onGlare?this.metadataCallbacks.onGlare=e=>{const t=new f(n.onGlare,[e]);this.context.postMessage(t)}:delete this.metadataCallbacks.onGlare}registerMetadataCallbacks(e){if(null!==this.nativeRecognizerRunner){this.setupMetadataCallbacks(e.registeredMetadataCallbacks);try{this.nativeRecognizerRunner.setJSDelegate(this.metadataCallbacks),this.notifySuccess(e)}catch(t){this.notifyError(e,new y(K.imageProcessFailure,t))}}else this.notifyError(e,new y(K.imageProcessFailure))}registerClearTimeoutCallback(e){if(null!==this.nativeRecognizerRunner){this.clearTimeoutCallback=e.callbackNonEmpty?{onClearTimeout:()=>{const e=new f(n.clearTimeoutCallback,[]);this.context.postMessage(e)}}:null;try{this.nativeRecognizerRunner.setClearTimeoutCallback(this.clearTimeoutCallback),this.notifySuccess(e)}catch(t){this.notifyError(e,new y(K.imageProcessFailure,t))}}else this.notifyError(e,new y(K.imageProcessFailure))}processGetProductIntegrationInfo(e){if(null!==this.wasmModule)try{const t=this.wasmModule.getActiveLicenseTokenInfo(),s={userId:e.userId,licenseId:t.licenseId,licensee:t.licensee,productName:t.sdkName,productVersion:t.sdkVersion,platform:"Browser",device:self.navigator.userAgent,packageName:t.packageName};this.context.postMessage(new A(e.messageID,s))}catch(t){this.notifyError(e,new y(K.objectInvokeFailure,t))}else this.notifyError(e,new y(K.wasmInitMissing))}}}();