Build 576754stable
Module 976886
23,003 characters · in 7af349a24887a0e7.jsDependencies
Source Raw
function(e,t,i){i.d(t,{a:()=>b,c:()=>w,i:()=>m,l:()=>p,n:()=>D,o:()=>y,r:()=>E,s:()=>S,t:()=>F,u:()=>h});var n,r,o=class{constructor(e=1,t=3e4){this.pending=[],this.available=[],this.processing=new Set,this.maxId=e-1,this.acquireTimeoutMs=t;for(let t=0;t<e;t++)this.available.push(t)}async acquire(){if(this.available.length>0){let e=this.available.shift();return this.processing.add(e),e}return new Promise((e,t)=>{let i={resolve:t=>{clearTimeout(i.timer),this.processing.add(t),e(t)},reject:e=>{clearTimeout(i.timer),t(e)},timer:setTimeout(()=>{console.error(`SemaphoreProvider: all slots occupied for ${this.acquireTimeoutMs}ms, ${this.pending.length} request(s) waiting`)},this.acquireTimeoutMs)};this.pending.push(i)})}release(e){e<0||e>this.maxId?console.error(`SemaphoreProvider: invalid threadId ${e}`):this.processing.has(e)?(this.processing.delete(e),this.pending.length>0?this.pending.shift().resolve(e):this.available.unshift(e)):console.error(`SemaphoreProvider: double-release of threadId ${e}`)}reset(){let e=this.pending;this.pending=[],this.available=[],this.processing=new Set;for(let e=0;e<=this.maxId;e++)this.available.push(e);for(let t of e)t.reject(Error("SemaphoreProvider reset: pending acquire cancelled"))}async withLock(e,...t){let i=await this.acquire();try{return await e(i,...t)}finally{this.release(i)}}};"u">typeof window&&void 0===window.wasmArrayBuffer&&(window.wasmArrayBuffer=null);let a=null,s=null;async function l(e){let t=await import(e);if("function"!=typeof t.Module)throw Error(`WASM glue at ${e} did not export a Module factory`);return t.Module}async function c(e){let t=await fetch(e);if(!t.ok)throw Error(`Failed to fetch WASM binary at ${e}: ${t.status} ${t.statusText}`);return new Uint8Array(await t.arrayBuffer())}async function d(e,t){return window.wasmArrayBuffer=await c(t),await e()}async function u(e){return s||a||(a=(async()=>{try{let t=!1!==e.useSimd,i=e.wasmSimdPath??e.wasmPath;if(t&&i!==e.wasmPath)try{let t=await l(e.glueCodeSimdPath??i.replace(/\.wasm($|\?)/,".js$1"));window.Module=t;let n={wasmModule:await d(t,i),simdUsed:!0};return s=n,n}catch(e){console.warn("[Incode SDK] SIMD WASM load failed, falling back to non-SIMD",e)}let n=await l(e.glueCodePath);window.Module=n;let r={wasmModule:await d(n,e.wasmPath),simdUsed:!1};return s=r,r}catch(e){throw a=null,e}})())}let h=((n={})[n.IdCaptureV1x=0]="IdCaptureV1x",n[n.IdCaptureV2x=1]="IdCaptureV2x",n[n.IdCaptureV3x=2]="IdCaptureV3x",n),p=((r={})[r.IdBlurGlarePipeline=0]="IdBlurGlarePipeline",r[r.IdBarcodeAndTextQualityPipeline=1]="IdBarcodeAndTextQualityPipeline",r[r.IdVideoSelfiePipeline=2]="IdVideoSelfiePipeline",r[r.SelfieWithAggregationMetrics=3]="SelfieWithAggregationMetrics",r[r.SelfieWithQualityMetrics=4]="SelfieWithQualityMetrics",r[r.OnDeviceSelfieWorkflow=5]="OnDeviceSelfieWorkflow",r);async function f(e,t,i=!0,...n){let r=async()=>{for(;;){if(t(...n))return;await new Promise(e=>setTimeout(e,0))}};i?await e.withLock(r):await r()}var m=class extends Error{constructor(e,t,i){super(e),this.name="WasmWebClientError",this.status=t,this.statusCode=t,(t>0||void 0!==i)&&(this.response={status:t,data:i})}};let g=null,v=null,C=new o(4);async function y(e,t,i,n,r){if(!g)return v||(v=(async()=>{try{let{wasmModule:o}=await u({wasmPath:e,wasmSimdPath:t,glueCodePath:i,glueCodeSimdPath:n||void 0,useSimd:r});if("function"!=typeof o.WebClient)throw Error("WASM module does not expose a WebClient class. Update webLib.wasm to a build that includes WebClient.");g=new o.WebClient}catch(e){throw v=null,e}})())}async function w(e,t,i,n,r){let o=L();o.resetSessionState?.(),o.setDefaultHeaders?.(n),await f(C,()=>o.createApi(e,t,r,i),!1);let a=o.getRequestResult(-1);if(a.hasError)throw new m(a.errorMessage||"WebClient handshake failed",a.statusCode,a.result)}async function b(e,t,i,n,r,o,a,s=!1){let l=L(),c=(e=>{if(!e)return;let t={};for(let i of Object.keys(e)){let n=e[i];null!=n&&(t[i]=String(n))}return t})(r);return C.withLock(async r=>{a&&l.setOnUploadProgress&&l.setOnUploadProgress(e=>{try{a(e)}catch(e){console.error("WasmWebClient: error in onUploadProgress callback",e)}});try{return await f(C,()=>(function(e,t,i,n,r,o,a,s,l){switch(t){case"GET":return e.get(i,n,a,o,s);case"POST":return e.post(i,n,r??{},o,a,s,l);case"PUT":return e.put(i,n,r??{},o,a,s,l);case"PATCH":return e.patch(i,n,r??{},o,a,s,l);case"DELETE":return e.del(i,n,r??{},o,a,s,l);default:throw Error(`Unsupported WASM HTTP method: ${t}`)}})(l,e,r,t,i,n,c,o,s),!1),function(e,t){let i=e.getRequestResult(t);if(i.hasError)throw new m(i.errorMessage||"WasmWebClient request failed",i.statusCode,i.result);return{data:i.result,status:i.statusCode}}(l,r)}finally{l.clearOnUploadProgress?.(r),l.clearOnDownloadProgress?.(r)}})}let _=null;function S(e){_=e}function L(){if(!g)throw Error("WasmWebClient not initialized. Call initializeWasmWebClient() first.");return g}var E=(class e{constructor(){this.versionsFile=null,this.modelsBuffers=null,this.inputImageBuffer=null,this.wasmModule=null,this.workflowApiUtilities=null,this.utilityApi=null,this.idCaptureWasmApi=null,this.faceProcessingWasmApi=null,this.webApi=null,this.imageWidth_=null,this.imageHeight_=null,this.pipelines_=null,this.isInitialized_=!1,this.inspectorOpened_=!1,this.wasmCallSemaphore=new o,this.Module=null}async initialize(e,t,i,n,r,o,a){await this.freeResources(),this.pipelines_=a,this.versionsFile=o;let{wasmModule:s,simdUsed:l}=await u({glueCodePath:i,glueCodeSimdPath:n||void 0,wasmPath:e,wasmSimdPath:t,useSimd:r});return this.wasmModule=s,this.Module=window.Module,this.workflowApiUtilities=new this.wasmModule.WorkflowApiUtilities,this.utilityApi=new this.wasmModule.UtilityApi,this.idCaptureWasmApi=new this.wasmModule.IdCaptureApi,this.faceProcessingWasmApi=new this.wasmModule.FaceProcessingApi,this.webApi=new this.wasmModule.WebApi({post(e,t,i){let n=i??{},r=_;return r?r(e,t,n):b("POST",e,t,n.headers??{},n.params,n.timeout??3e4,void 0,!0===n.ie)}}),this.isInitialized_=!0,l}static getInstance(){return e.instance||(e.instance=new e),e.instance}isInitialized(){return null!=this.workflowApiUtilities&&null!=this.utilityApi&&null!=this.idCaptureWasmApi&&null!=this.faceProcessingWasmApi&&this.isInitialized_}async allocateImageBuffers(e,t){this.checkWasmInitialization("Unable to allocate image buffers, cpp API hasn't been initialized"),e&&t&&e==this.imageWidth_&&t==this.imageHeight_&&this.inputImageBuffer&&e*t*4===this.inputImageBuffer.length||(this.imageWidth_=e,this.imageHeight_=t,this.inputImageBuffer=this.workflowApiUtilities.allocateInputImageBuffer(e,t,4))}async handleDetectionCallAndUpdateState(e){this.checkWasmInitialization("Unable to update pipeline state, cpp API hasn't been initialized"),this.workflowApiUtilities.handleDetectionCallAndUpdateState(this.pipelineTypeToWasmEnum(e))}ens(e){return this.checkWasmInitialization("Unable to encrypt the image, cpp API hasn't been initialized"),this.utilityApi.ens(e)}isVirtualCamera(e){return this.checkWasmInitialization("Unable to check if the camera is virtual, cpp API hasn't been initialized"),!!e&&this.utilityApi.isVirtualCamera(e)}estimatePerformance(){return this.checkWasmInitialization("Unable to estimate performance, cpp API hasn't been initialized"),this.utilityApi.estimatePerformance()}async analyzeFrame(e){this.checkWasmInitialization("Unable to analyze the frame, cpp API hasn't been initialized"),await this.allocateImageBuffers(e.width,e.height),this.inputImageBuffer.set(e.data),this.utilityApi.analyzeFrame()}async freeResources(){this.versionsFile=null,this.modelsBuffers=null,this.inputImageBuffer=null,this.imageWidth_=null,this.imageHeight_=null,this.pipelines_=null,window.wasmArrayBuffer=null,this.workflowApiUtilities&&"function"==typeof this.workflowApiUtilities.delete&&(this.workflowApiUtilities.delete(),this.workflowApiUtilities=null),this.utilityApi&&"function"==typeof this.utilityApi.delete&&(this.utilityApi.delete(),this.utilityApi=null),this.idCaptureWasmApi&&"function"==typeof this.idCaptureWasmApi.delete&&(this.idCaptureWasmApi.delete(),this.idCaptureWasmApi=null),this.faceProcessingWasmApi&&"function"==typeof this.faceProcessingWasmApi.delete&&(this.faceProcessingWasmApi.delete(),this.faceProcessingWasmApi=null),this.webApi&&"function"==typeof this.webApi.delete&&this.webApi.delete(),this.webApi=null,this.wasmModule=null,this.isInitialized_=!1}resetPipeline(e){this.checkWasmInitialization("Unable to reset pipeline, cpp API hasn't been initialized"),this.workflowApiUtilities.resetWorkflow(this.pipelineTypeToWasmEnum(e))}resetAllPipelines(){for(let[e,t]of(this.checkWasmInitialization("Unable to reset pipelines, cpp API hasn't been initialized"),this.pipelines_))this.resetPipeline(e)}resetOther(){this.checkWasmInitialization("Unable to reset other states, cpp API hasn't been initialized"),this.utilityApi.resetOther()}reset(){this.resetAllPipelines(),this.resetOther()}async process(e,t){if(this.checkWasmInitialization("Unable to process the image, cpp API hasn't been initialized"),null===this.inputImageBuffer)throw Error("Unable to process the image, buffers haven't been allocated!");switch(this.inputImageBuffer.set(e.data),t){case p.IdBlurGlarePipeline:case p.IdBarcodeAndTextQualityPipeline:return this.idCaptureWasmApi.runIdCaptureWorkflow(this.pipelineTypeToWasmEnum(t));case p.IdVideoSelfiePipeline:return this.idCaptureWasmApi.runIdVideoSelfieWorkflow();case p.SelfieWithAggregationMetrics:case p.SelfieWithQualityMetrics:case p.OnDeviceSelfieWorkflow:return this.faceProcessingWasmApi.runSelfieWorkflow(this.pipelineTypeToWasmEnum(t));default:throw Error("Unknown pipeline type")}}async runIdCapture(e){if(this.checkWasmInitialization("Unable to run Id Capture, cpp API hasn't been initialized"),null===this.inputImageBuffer)throw Error("Unable to process the image, buffers haven't been allocated!");return this.inputImageBuffer.set(e.data),this.idCaptureWasmApi.runIdCapture()}async runSelfieCapture(e){if(this.checkWasmInitialization("Unable to run Selfie Capture, cpp API hasn't been initialized"),null===this.inputImageBuffer)throw Error("Unable to process the image, buffers haven't been allocated!");return this.inputImageBuffer.set(e.data),this.faceProcessingWasmApi.runSelfieCapture()}async setFacePositionConstraints(e,t,i,n,r){this.checkWasmInitialization("Unable to set face position constraints, cpp API hasn't been initialized"),this.faceProcessingWasmApi.setFacePositionConstraints(this.pipelineTypeToWasmEnum(e),t,i,n,r)}async setFaceDetectionThresholds(e,t,i,n,r,o,a,s,l,c,d){this.checkWasmInitialization("Unable to set face detection thresholds, cpp API hasn't been initialized"),this.faceProcessingWasmApi.setFaceProcessingThresholds(this.pipelineTypeToWasmEnum(e),t,i,n,r,o,a,s,l,c,d)}async setFaceAttributesThresholds(e,t,i,n,r){this.checkWasmInitialization("Unable to set face attributes thresholds, cpp API hasn't been initialized"),this.faceProcessingWasmApi.setFaceAttributesThresholds(this.pipelineTypeToWasmEnum(e),t,i,n,r)}async setFaceChecksEnabled(e,t,i,n,r,o){this.checkWasmInitialization("Unable to set face checks enabled flags, cpp API hasn't been initialized"),this.faceProcessingWasmApi.setFaceChecksEnabled(this.pipelineTypeToWasmEnum(e),t,i,n,r,o)}async setFaceDetectionMode(e,t){this.checkWasmInitialization("Unable to set face detection mode, cpp API hasn't been initialized"),this.faceProcessingWasmApi.setFaceProcessingMode(this.pipelineTypeToWasmEnum(e),t)}async setFaceDetectionCallbacks(e,t,i,n,r,o,a,s,l,c,d,u,h,p,f,m,g,v){this.checkWasmInitialization("Unable to set face detection callbacks, cpp API hasn't been initialized"),this.faceProcessingWasmApi.setFaceProcessingCallbacks(this.pipelineTypeToWasmEnum(e),t,i,n,r,o,a,s,l,c,d,u,h,p,f,m,g,v)}async setIdCaptureThresholds(e,t,i,n,r,o,a,s,l,c){this.checkWasmInitialization("Unable to set thresholds, cpp API hasn't been initialized"),this.idCaptureWasmApi.setIdCaptureThresholds(this.pipelineTypeToWasmEnum(e),t,i,n,r,o,a,s,l,c)}async setIdCaptureCallbacks(e,t,i,n,r,o,a,s,l,c,d,u,h,p){this.checkWasmInitialization("Unable to set callbacks, cpp API hasn't been initialized"),this.idCaptureWasmApi.setIdCaptureCallbacks(this.pipelineTypeToWasmEnum(e),t,i,n,r,o,a,s,l,c,d,u,h,p)}async setIdCaptureGeometryParams(e,t,i,n,r,o,a,s,l,c,d,u,h){this.checkWasmInitialization("Unable to set geometry params, cpp API hasn't been initialized"),this.idCaptureWasmApi.setIdCaptureGeometryParams(this.pipelineTypeToWasmEnum(e),t,i,n,r,o,a,s,l,c,d,u,h)}async setIdCaptureConfigParams(e,t,i,n,r,o,a,s,l){this.checkWasmInitialization("Unable to set config params, cpp API hasn't been initialized"),this.idCaptureWasmApi.setIdCaptureConfigParams(this.pipelineTypeToWasmEnum(e),t,i,n,r,o,s,l)}setIdCaptureModelType(e,t){this.checkWasmInitialization("Unable to set model type, cpp API hasn't been initialized"),this.idCaptureWasmApi.setIdCaptureModelType(this.pipelineTypeToWasmEnum(e),this.IdCaptureModelTypeToWasmEnum(t))}IdPerspectiveTransform(e,t){return this.checkWasmInitialization("Unable to perform perspective transform, cpp API hasn't been initialized"),this.idCaptureWasmApi.IdPerspectiveTransform(e,t)}async getVersions(){return JSON.parse(await (await fetch(this.versionsFile)).text())}async loadModels(){this.checkWasmInitialization("Unable load the models, cpp API hasn't been initialized");let e=new this.wasmModule.WorkflowTypeToIntMap,t=new Map,i=new Map;for(let[n,r]of this.pipelines_){let o=this.pipelineTypeToWasmEnum(n),a=[],s=new this.wasmModule.VectorInt;for(let e of r){if(!i.has(e)){let t=await fetch(e).then(e=>e.arrayBuffer()).then(e=>new Uint8Array(e));i.set(e,t)}let t=i.get(e);s.push_back(t.byteLength),a.push(t)}e.set(o,s),t.set(o,a)}for(let[i,n]of(this.modelsBuffers=this.workflowApiUtilities.allocateModelsBuffers(e),t)){let e=this.modelsBuffers?.get(i);for(let t=0;t<e.size();t++){let i=e?.get(t);if(i)i.set(n[t]);else throw Error("Unable to get model buffer from shared memory!")}}}async initializePipelines(){this.checkWasmInitialization("Unable to initialize pipelines, cpp API hasn't been initialized"),this.modelsBuffers||await this.loadModels(),this.workflowApiUtilities.initializeWorkflows()}async setProductionMode(e){this.checkWasmInitialization("Unable to set production mode, cpp API hasn't been initialized"),this.utilityApi.setProductionMode(e)}getPipelineState(){return this.checkWasmInitialization("Unable to get pipeline state, cpp API hasn't been initialized"),this.workflowApiUtilities.getWorkflowState()}getCurrentPipeline(){return this.checkWasmInitialization("Unable to get current pipeline, cpp API hasn't been initialized"),this.pipelineTypeFromWasmEnum(this.workflowApiUtilities.getCurrentWorkflow())}setSdkVersion(e){this.checkWasmInitialization("Unable to set sdk version, cpp API hasn't been initialized"),this.utilityApi.setSdkVersion(e)}setSdkPlatform(e){this.checkWasmInitialization("Unable to set device type, cpp API hasn't been initialized"),this.utilityApi.setSdkPlatform(e)}setDeviceInfo(e,t=!0){this.checkWasmInitialization("Unable to set device info, cpp API hasn't been initialized"),this.utilityApi.setDeviceInfo(e,t)}setBrowserInfo(e,t=!0){this.checkWasmInitialization("Unable to set browser info, cpp API hasn't been initialized"),this.utilityApi.setBrowserInfo(e,t)}setCameraInfo(e,t=!0){this.checkWasmInitialization("Unable to set camera info, cpp API hasn't been initialized"),this.utilityApi.setCameraInfo(e,t)}setZc(e){this.checkWasmInitialization("Unable to set zc, cpp API hasn't been initialized"),this.utilityApi.setZc(e)}setMotionStatus(e){this.checkWasmInitialization("Unable to set motion status, cpp API hasn't been initialized"),this.utilityApi.setMotionStatus(e)}setMetadataField(e,t){this.checkWasmInitialization("Unable to set metadata field, cpp API hasn't been initialized"),this.utilityApi.setMetadataField(e,t)}setInspectorOpened(e){this.inspectorOpened_=e}setBackgroundMode(e){this.checkWasmInitialization("Unable to set background mode, cpp API hasn't been initialized"),this.utilityApi.setBackgroundMode(e)}getCheck(){return this.checkWasmInitialization("Unable to get check, cpp API hasn't been initialized"),this.utilityApi.getCheck()}getMetadata(){return this.checkWasmInitialization("Unable to get metadata, cpp API hasn't been initialized"),this.utilityApi.setInspectorOpened(this.inspectorOpened_),this.utilityApi.getMetadata()}async prc(){this.checkWasmInitialization("Unable to prc, cpp API hasn't been initialized"),await f(this.wasmCallSemaphore,()=>this.utilityApi.prc(),!0)}async poc(e){this.checkWasmInitialization("Unable to poc, cpp API hasn't been initialized"),await f(this.wasmCallSemaphore,()=>this.utilityApi.poc(e),!0)}ckvcks(e){this.checkWasmInitialization("Unable to ckvcks, cpp API hasn't been initialized"),this.utilityApi.ckvcks(e)}processPhoto(e){this.checkWasmInitialization("Unable to process photo, cpp API hasn't been initialized"),this.faceProcessingWasmApi.processPhoto(e)}postFaceResults(e){return this.checkWasmInitialization("Unable to post face results, cpp API hasn't been initialized"),this.webApi.postFaceResults(e??{})}pipelineTypeToWasmEnum(e){switch(e){case p.IdBlurGlarePipeline:return this.wasmModule.WorkflowType.IdBlurGlareWorkflow;case p.IdBarcodeAndTextQualityPipeline:return this.wasmModule.WorkflowType.IdBarcodeAndTextQualityWorkflow;case p.IdVideoSelfiePipeline:return this.wasmModule.WorkflowType.IdVideoSelfieWorkflow;case p.SelfieWithAggregationMetrics:return this.wasmModule.WorkflowType.SelfieWithAggregationMetrics;case p.SelfieWithQualityMetrics:return this.wasmModule.WorkflowType.SelfieWithQualityMetrics;case p.OnDeviceSelfieWorkflow:return this.wasmModule.WorkflowType.OnDeviceSelfieWorkflow;default:throw Error("Unknown pipeline type")}}pipelineTypeFromWasmEnum(e){switch(e){case this.wasmModule.WorkflowType.IdBlurGlareWorkflow:return p.IdBlurGlarePipeline;case this.wasmModule.WorkflowType.IdBarcodeAndTextQualityWorkflow:return p.IdBarcodeAndTextQualityPipeline;case this.wasmModule.WorkflowType.IdVideoSelfieWorkflow:return p.IdVideoSelfiePipeline;case this.wasmModule.WorkflowType.SelfieWithAggregationMetrics:return p.SelfieWithAggregationMetrics;case this.wasmModule.WorkflowType.SelfieWithQualityMetrics:return p.SelfieWithQualityMetrics;case this.wasmModule.WorkflowType.OnDeviceSelfieWorkflow:return p.OnDeviceSelfieWorkflow;default:throw Error("Unknown pipeline type")}}IdCaptureModelTypeToWasmEnum(e){switch(e){case h.IdCaptureV1x:return this.wasmModule.IdCaptureModelType.IdCaptureV1x;case h.IdCaptureV2x:return this.wasmModule.IdCaptureModelType.IdCaptureV2x;case h.IdCaptureV3x:return this.wasmModule.IdCaptureModelType.IdCaptureV3x;default:throw Error("Unknown Id Capture model type")}}IdCaptureModelTypeFromWasmEnum(e){switch(e){case this.wasmModule.IdCaptureModelType.IdCaptureV1x:return h.IdCaptureV1x;case this.wasmModule.IdCaptureModelType.IdCaptureV2x:return h.IdCaptureV2x;case this.wasmModule.IdCaptureModelType.IdCaptureV3x:return h.IdCaptureV3x;default:throw Error("Unknown Id Capture model type")}}checkWasmInitialization(e){if(!this.isInitialized())throw Error(e)}}).getInstance();let k=["selfie","idCapture"],x={selfie:["selfie_bf_angles_192x192_opset9_fp16.ortmodelv2","face_attributes_v1_3_fp16.ortmodelv2","mls_regressor_4773007c657b4f05a460321456740d0f_fp16.ortmodelv2","face_occlusion_v0_2_fp16.ortmodelv2"],onDeviceSelfie:["selfie_bf_angles_192x192_opset9_fp16.ortmodelv2","face_attributes_v1_3_fp16.ortmodelv2","mls_regressor_4773007c657b4f05a460321456740d0f_fp16.ortmodelv2","face_occlusion_v0_2_fp16.ortmodelv2","ondevice_physical_liveness_v2_1_fp16.ortmodelv2","age_estimation_v2_2_2_fp16.ortmodelv2"],idCapture:["id_capture_2_01_fp16.ortmodelv2","id_fiqa_19a81a0b9bf6492eb03b4667f6db4c85_fp16.ortmodelv2"]},I="idle",T=null,M=null,A=[],R=null;function O(e){let t=e.lastIndexOf("/");return -1===t?"models":`${e.substring(0,t)}/models`}function P(e,t,i){let n=new Map;for(let r of e){let e=function(e){switch(e){case"selfie":return p.SelfieWithQualityMetrics;case"onDeviceSelfie":return p.OnDeviceSelfieWorkflow;case"idCapture":return p.IdBlurGlarePipeline;default:throw Error(`Unknown pipeline: ${e}`)}}(r);if(!n.has(e)){let o=(i?.[r]??x[r]).map(e=>`${t}/${e}`);n.set(e,o)}}return n}async function D(e){let t=e.pipelines??[...k],i=e.modelsBasePath??O(e.wasmPath);if("loading"===I&&T)return T;if("ready"===I){if(0===t.filter(e=>!A.includes(e)).length)return;if(!R)throw Error("Cannot add pipelines: original warmup config not available");if(R.wasmPath!==e.wasmPath||R.glueCodePath!==e.glueCodePath||(R.wasmSimdPath??R.wasmPath)!==(e.wasmSimdPath??e.wasmPath)||(R.glueCodeSimdPath??"")!==(e.glueCodeSimdPath??"")||(R.useSimd??!0)!==(e.useSimd??!0))throw Error("Cannot add pipelines: WASM config mismatch. Use same wasmPath, glueCodePath, and useSimd settings.");let i=[...new Set([...A,...t])];return I="loading",M=null,T=(async()=>{try{let e=P(i,R.modelsBasePath??O(R.wasmPath),R.pipelineModels);await E.initialize(R.wasmPath,R.wasmSimdPath??R.wasmPath,R.glueCodePath,R.glueCodeSimdPath??"",R.useSimd??!0,"",e),await E.loadModels(),await E.initializePipelines(),I="ready",A=i,R={...R,pipelines:i},T=null}catch(e){throw I="error",M=e instanceof Error?e:Error(String(e)),T=null,M}})()}return I="loading",M=null,T=(async()=>{try{let n=P(t,i,e.pipelineModels);await E.initialize(e.wasmPath,e.wasmSimdPath??e.wasmPath,e.glueCodePath,e.glueCodeSimdPath??"",e.useSimd??!0,"",n),await E.loadModels(),await E.initializePipelines(),I="ready",A=[...t],R={...e,pipelines:t},T=null}catch(e){throw I="error",M=e instanceof Error?e:Error(String(e)),T=null,M}})()}var F=class{constructor(e){this._isInitialized=!1,this.pipelineType=e}get initialized(){return this._isInitialized}getPipelineType(){if(void 0===this.pipelineType)throw Error(`${this.constructor.name} has no pipeline type configured.`);return this.pipelineType}async initializeBase(e,t){if(this._isInitialized)return;let i={isReady:"ready"===I,isLoading:"loading"===I,error:M??void 0,loadedPipelines:[...A]};if(i.isLoading||"ready"===I||i.error)await ("ready"===I?Promise.resolve():"loading"===I&&T?T:"error"===I?Promise.reject(M??Error("WASM initialization failed")):Promise.reject(Error("WASM warmup was not started. Call warmupWasm() first.")));else{if(!e.wasmPath||!e.glueCodePath)throw Error("WASM path and glue code path are required. Call warmupWasm() first.");await D({wasmPath:e.wasmPath,wasmSimdPath:e.wasmSimdPath,glueCodePath:e.glueCodePath,glueCodeSimdPath:e.glueCodeSimdPath,useSimd:e.useSimd,modelsBasePath:e.modelsBasePath,pipelines:[t]})}this._isInitialized=!0}ensureInitialized(){if(!this._isInitialized)throw Error(`${this.constructor.name} not initialized. Call initialize() first.`)}async processFrameWasm(e){this.ensureInitialized();let t=this.getPipelineType();return await E.allocateImageBuffers(e.width,e.height),await E.handleDetectionCallAndUpdateState(t),await E.process(e,t)}reset(){this._isInitialized&&void 0!==this.pipelineType&&E.resetPipeline(this.pipelineType)}async dispose(){this.reset(),this._isInitialized=!1}}}