scandit-web-datacapture-core
Version:
Scandit Data Capture SDK for the Web
15 lines (12 loc) • 13 kB
JavaScript
import { d } from './chunk-ZAOFG2OQ.js';
import { a as a$4 } from './chunk-TM7QAJVA.js';
import { a as a$5 } from './chunk-MZFVLSKK.js';
import { c as c$1, a as a$6 } from './chunk-7AWOP7WL.js';
import { c } from './chunk-RR3PHYWZ.js';
import { a as a$2 } from './chunk-KFGYYHZO.js';
import { a as a$1 } from './chunk-O7TZTIHO.js';
import { a } from './chunk-SP3HSP4K.js';
import { a as a$3 } from './chunk-QCZSSQAQ.js';
import { c as c$2, e } from './chunk-HIOHGPUS.js';
var C=class C{constructor(e,t){this.hintPresenterV2=null;this.MAX_NUMBER_OF_IMAGES_IN_FRAME_DATA_POOL=10;this.redrawInterval=1e3/30;this.redrawRequests=[];this._isDrawLoopRunning=!1;this.frameDataPool=new Map;this.lastFrameCounter=-1;this.poorMansBenchmarkLogs=!1;this.writableDataPathStandard="/scandit_sync_folder";this.resourceFilesSubfolder="resources";this.performanceMetricsReporterTimer=void 0;this.performanceMetrics={frameDataPoolSize:0,processedFramesCount:0,redrawRequestsCount:0,actualRedrawsCount:0};this.gestureListener=null;this.webPlatformHintPresenter=null;this.moduleHandler=e,this.workerFunctions=t,this._loadProgressCallback=this._loadProgressCallback.bind(this),c(this.getWasmMetadata());}get Module(){return this.moduleHandler.get()}set isDrawLoopRunning(e){this._isDrawLoopRunning=e,!e&&typeof this.loopTimeoutId=="number"&&(clearTimeout(this.loopTimeoutId),this.loopTimeoutId=void 0);}get isDrawLoopRunning(){return this._isDrawLoopRunning}convertToLoadableFrameData(e){let t=this.getNextFrameId();this.frameDataPool.set(t,new Uint8ClampedArray(e.getFrameData()));let r=this.lastUsedModuleMirrorAxis==null?!1:this.lastUsedModuleMirrorAxis!==this.Module.Axis.None;return {frameId:t,width:e.getWidth(),height:e.getHeight(),isFrameSourceMirrored:r}}createContext(e){var g,D,f,b,m;let t=this.getModeDeserializers(),r=c$1(location);(r==="localhost"||r==="127.0.0.1")&&navigator.userAgent.includes("Electron")&&e.appName!=null&&(r+=`-${e.appName}`),this.parentDomain=e.parentDomain,this.contextDeserializer=new this.Module.DataCaptureContextDeserializer(this.writableDataPath,e.deviceId,e.context.deviceModelName,r,this.parentDomain,t,e.delayedRegistration,e.highEndBlurryRecognition,this.resourcePath);let a=this.contextDeserializer.contextFromJson(JSON.stringify(e.context));if(a==null)throw new Error("Could not create the context");let i=a.getView();this.context=a.getContext(),a.delete();let l=this.Module.DataCaptureContextListener.extend("DataCaptureContextListener",{didChangeStatus:(s,h)=>{this.contextDidChangeStatus(JSON.parse(h.toJson()));},didStartObservingContext:()=>{this.didStartObservingContext();}}),c=this.Module.DataCaptureContextFrameListener.extend("DataCaptureContextFrameListener",{onObservationStarted:s=>{},onObservationStopped:s=>{},onFrameProcessingStarted:(s,h)=>{this.workerFunctions.postMessage({type:"onFrameProcessingStarted"});},onFrameProcessingFinished:(s,h)=>{this.workerFunctions.postMessage({type:"onFrameProcessingFinished"});},onFrameSkipped:(s,h)=>{this.workerFunctions.postMessage({type:"onFrameSkipped"});}}),p=this.Module.GestureRecognizer.extend("GestureRecognizer",{setGestureListener:(s,h)=>{var M;(M=this.gestureListener)==null||M.delete(),this.gestureListener=s.clone();}});(g=this.gestureRecognizer)==null||g.delete(),this.gestureRecognizer=new p;let d=new l;this.context.addListener(d),d.delete();let u=new c;this.context.addFrameListener(u),u.delete(),this.setView(i),(D=this.view)==null||D.setGestureRecognizer(this.gestureRecognizer);let w=this.Module.PlatformHintPresenter.extend("PlatformHintPresenter",{setHintPresenter:s=>{},showToast:s=>{this.workerFunctions.postMessage({type:"showToast",payload:JSON.parse(s)});},hideToast:s=>{this.workerFunctions.postMessage({type:"hideToast",payload:JSON.parse(s)});},showGuidance:s=>{this.workerFunctions.postMessage({type:"showGuidance",payload:JSON.parse(s)});},hideGuidance:s=>{this.workerFunctions.postMessage({type:"hideGuidance",payload:JSON.parse(s)});},startUpdateTimer:s=>{this.workerFunctions.postMessage({type:"startUpdateTimer",payload:{duration:{unit:"ms",value:s}}});},stopUpdateTimer:()=>{this.workerFunctions.postMessage({type:"stopUpdateTimer"});}});(f=this.hintPresenterV2)==null||f.delete(),(b=this.webPlatformHintPresenter)==null||b.delete(),this.webPlatformHintPresenter=new w,this.hintPresenterV2=new this.Module.HintPresenterV2(this.webPlatformHintPresenter),(m=this.view)==null||m.setHintPresenterV2(this.hintPresenterV2);}onTap(e){var t;(t=this.gestureListener)==null||t.onTap(JSON.stringify(e));}hintPresenterV2Update(){var e;(e=this.hintPresenterV2)==null||e.update();}startReportingPerformanceMetrics(){this.performanceMetricsReporterTimer==null&&(this.performanceMetricsReporterTimer=setInterval(()=>{this.reportPerformanceMetrics();for(let e of Object.keys(this.performanceMetrics))this.performanceMetrics[e]=0;},1e3));}async reportPerformanceMetrics(){this.workerFunctions.postMessage({type:"performanceMetricsReport",payload:{...this.performanceMetrics}});}deleteFrameData(e){this.frameDataPool.delete(e);}dispose(){var e,t;this.context.dispose(),this.frameDataPool.clear(),this.isDrawLoopRunning=!1,this.lastFrameCounter=-1,(e=this.gestureRecognizer)==null||e.delete(),this.gestureRecognizer=null,(t=this.gestureListener)==null||t.delete(),this.gestureListener=null;}flushAnalytics(){this.context.flushAnalytics();}extractCentaurusLicense(e){return {payload:{centaurus:{licenseKey:this.Module.LicenseUtils[C.get3dPartyLicenseKeyMethodName](e)}}}}getModeDeserializers(){return new this.Module.VectorDataCaptureModeDeserializer}loadLibrary(e){return this.libraryLoadingPromise!=null?this.libraryLoadingPromise:(this.libraryLoadingPromise=this.setup(e),this.libraryLoadingPromise)}processFrame(e){var i;if(this.context==null)return {payload:e,transferables:[e.data.buffer]};let t=e.data,r=e.colorType==="GRAYSCALE"?this.Module.ImageBufferFormat.Grayscale8:this.Module.ImageBufferFormat.Rgba8888,a=this.Module.allocateUint8Array(t.byteLength);return this.Module.HEAPU8.set(t,a),(i=this.imageFrameSource)==null||i.outputFrame(a,e.width,e.height,r),{payload:e,transferables:[e.data.buffer]}}reportCameraProperties(e){this.context.setCameraProperties(e.deviceId,e.isFrontFacing,e.hasAutofocus);}requestFrameData(e){let t=this.frameDataPool.get(e);return t==null?{payload:{data:null}}:{payload:{data:t},transferables:[t.buffer]}}scheduleRedraw(e,t){this.addRedrawRequest(t),this.isDrawLoopRunning||this.startDrawLoop(e);}sendViewRefreshCommands(e){this.workerFunctions.postMessage({type:"draw",payload:e},[e.buffer]);}setFrameSource(e,t){var r;this.lastUsedModuleMirrorAxis=this.mapMirrorAxisOnModule(e),(r=this.imageFrameSource)==null||r.delete(),this.imageFrameSource=new this.Module.ImageBufferFrameSource(this.lastUsedModuleMirrorAxis,t,0),this.context.setFrameSource(this.imageFrameSource);}startDrawLoop(e){this.isDrawLoopRunning=!0;let t=i=>this.redrawRequests.length>0&&this.redrawRequests[0]<=i,r=i=>{for(;this.redrawRequests.length>0&&this.redrawRequests[0]<=i;)this.redrawRequests.shift();},a=()=>{this.loopTimeoutId=setTimeout(()=>{if(!this.isDrawLoopRunning)return;let i=performance.now();if(t(i)){r(i),e.draw();let l=e.getDrawCommands();this.sendViewRefreshCommands(new Uint8Array(l));}a();},this.redrawInterval);};a();}updateContext(e){if(this.context!=null&&this.contextDeserializer!=null){e.view!=null&&!e.view.visible&&this.context.flushAnalytics();let t=this.contextDeserializer.updateContextFromJson(this.context,this.view,JSON.stringify(e.context));if(t==null)throw new Error("Could not update the context");this.context.delete(),this.context=t.getContext();let r=t.getView();t.delete(),r!=null&&e.view!=null&&r.setViewSize(e.view.width,e.view.height,e.view.orientation),this.hintPresenterV2!=null&&(r==null||r.setHintPresenterV2(this.hintPresenterV2)),this.gestureRecognizer!=null&&(r==null||r.setGestureRecognizer(this.gestureRecognizer)),this.setView(r),a.log(a.Level.Debug,"context updated",e);}}onDocumentVisibilityChange(e){e==="hidden"&&this.context.flushAnalytics();}isFeatureSupported(e){return {payload:{supported:this.context.isFeatureSupported(e)}}}getViewfinderInfo(){var e,t;return {payload:{isDisplayingViewfinder:(t=(e=this.view)==null?void 0:e.isDisplayingViewfinder())!=null?t:!1,rect:JSON.parse(this.view.getViewfinderRect())}}}getNextFrameId(){return this.lastFrameCounter++,this.lastFrameCounter>=this.MAX_NUMBER_OF_IMAGES_IN_FRAME_DATA_POOL&&(this.lastFrameCounter=0),this.lastFrameCounter}getWasmDynamicLibraries(e){return this.getWasmSideModuleFileName()==null?[]:[`${e.replace(/\/[^/]*$/,"/")}${this.getWasmSideModuleFileName()}`]}getWasmCoreExpectedHash(e,t){return t?e?globalThis.SDC_WASM_CORE_MT_SIMD_HASH:globalThis.SDC_WASM_CORE_MT_HASH:e?globalThis.SDC_WASM_CORE_SIMD_HASH:""}getWasmCoreFileName(e,t){return t?e?globalThis.SDC_WASM_CORE_MT_SIMD_FILE_NAME:globalThis.SDC_WASM_CORE_MT_FILE_NAME:e?globalThis.SDC_WASM_CORE_SIMD_FILE_NAME:""}getWasmMetadata(){return globalThis.WASM_METADATA}getWasmSideModuleFileName(){return ""}_loadProgressCallback(e){this.workerFunctions.postMessage({type:"loadLibraryProgress",payload:e});}addRedrawRequest(e){this.redrawRequests.push(Math.round(performance.now())+e),this.redrawRequests.sort((t,r)=>t-r);}contextDidChangeStatus(e){e.code===260?e.message=e.message.replace("domain name",`domain name (${c$1(location)})`):e.code===265&&(e.message=e.message.replace("domain name",`domain name (${this.parentDomain})`)),this.workerFunctions.postMessage({type:"contextDidChangeStatus",payload:e});}didStartObservingContext(){this.workerFunctions.postMessage({type:"didStartObservingContext"});}mapMirrorAxisOnModule(e){switch(e){case"None":return this.Module.Axis.None;case"X":return this.Module.Axis.X;case"Y":return this.Module.Axis.Y;default:return this.Module.Axis.None}}setView(e){this.view=e,this.setViewRefreshHandler(e),e==null&&(this.isDrawLoopRunning=!1,this.sendViewRefreshCommands(new Uint8Array([])));}setViewRefreshHandler(e){if(e==null||e.isViewRefreshHandlerSet)return;let t=this.Module.NeedsRedrawDelegate.extend("NeedsRedrawDelegate",{setNeedsRedrawIn:this.scheduleRedraw.bind(this,e)}),r=new t;e.setNeedsRedrawDelegate(r),e.isViewRefreshHandlerSet=!0;}setupDataDecoding(){let e=this.moduleHandler.get(),t=e.DataDecoding.extend("DataDecoding",{decode(r,a){try{let i=JSON.parse(a),l=[];for(let c of i){let p=new TextDecoder(c.ianaName,{fatal:!0});l.push(p.decode(r.slice(c.startIndex,c.endIndex)));}return l.join("")}catch(i){return ""}}});e.setDataDecoding(new t);}start(e,t,r){e&&t&&(this.setupDataDecoding(),this.moduleHandler.get().callMain(),typeof this.moduleHandler.get().PThread=="object"||r());}getWritableDataPath(e){return e!=null?(a.log(a.Level.Debug,`IndexedDB database name override in use to recover from blocked standard database: ${e}`),e):this.writableDataPathStandard}numOfMBToPages(e){return Math.ceil(1024*e*1024/64/1024)}async setup({libraryLocation:e$1,locationPath:t,writableDataPathOverride:r,overrideThreadsSupport:a$7,overrideSimdSupport:i,verifyResponseHash:l,referredOrigin:c,fixedWasmMemory:p}){var F;let d$1=!1,u=!1;this.writableDataPath=this.getWritableDataPath(r),this.resourcePath=`${e$1}${this.resourceFilesSubfolder}/`,globalThis.path=t;let{resolve:w,reject:g,promise:D}=new a$1,f=a$2.sdkVersion();if(f==="")throw new a$3({name:"Invalid library version",message:"Library version is not defined or empty, cannot generate proper path to library files."});let[b,m]=await Promise.all([c$2(),e()]);a$7!=="auto"&&(m=a$7==="on"),i!=="auto"&&(b=i==="on");let s=this.getWasmCoreFileName(b,m),h=d(f,e$1,s),{jsURI:M,wasmURI:P}=h,O={instantiateWasm:(o,N)=>(a$6({importObject:o,wasmURI:P,expectedHash:this.getWasmCoreExpectedHash(b,m),verifyResponseHash:l,successCallback:N,progressCallback:this._loadProgressCallback,referredOrigin:c}),{})},y=p===null?null:new WebAssembly.Memory({initial:this.numOfMBToPages(p),maximum:this.numOfMBToPages(p),shared:m});return y!==null&&a.log(a.Level.Debug,"Fixed wasmMemory set",y),this.moduleHandler.set({...y?{wasmMemory:y}:{},mainScriptUrlOrBlob:M,canvas:(F=this.workerFunctions.getOffscreenCanvas())!=null?F:{getContext:()=>null},...O,dynamicLibraries:this.getWasmDynamicLibraries(P),locateFile:o=>e$1+o,noInitialRun:!0,preRun:[async()=>{try{await a$4({writableDataPath:this.writableDataPath});}catch(o){if(o.name==="BlockedIndexedDB"){g(o.toString());return}a.log(a.Level.Debug,"No IndexedDB support, some data will not be persisted:",o);}u=!0,this.start(u,d$1,w);}],onMainComplete:()=>{if([d$1,u].includes(!1)){a.log(a.Level.Warn,{runtimeLoaded:d$1,fileSystemSynced:u},"Both runtimeLoaded and fileSystemSynced should be true when calling onMainComplete"),g("onMainComplete has been called but runtime or file system was not ready.");return}w();},onRuntimeInitialized:()=>{d$1=!0,this.start(u,d$1,w);},print:o=>{a.log(a.Level.Info,o);}}),await a$5(M,f)||g(`Couldn't retrieve Scandit Data Capture library at ${M}, did you configure the path for it correctly?`),D}};C.get3dPartyLicenseKeyMethodName=atob("Z2V0QmxpbmtJZExpY2Vuc2VLZXk=");var W=C;
export { W as a };