UNPKG

scandit-web-datacapture-barcode

Version:

Scandit Data Capture SDK for the Web

8 lines (5 loc) 13.5 kB
import { a as a$1, b } from './chunk-IWT2RVHA.js'; import { a as a$2 } from './chunk-K74I4SRW.js'; import { a } from './chunk-3RD7BKH4.js'; var u=URL.createObjectURL(new Blob(['"use strict";(()=>{var n;(r=>{(s=>(s.Debug="debug",s.Info="info",s.Warn="warn",s.Error="error",s.Quiet="quiet"))(r.Level||(r.Level={}));let e=new Map([["debug",1],["info",2],["warn",3],["error",4],["quiet",5]]),t="debug";function a(s){t=s}r.setLevel=a;function o(s,...i){if(!(e.get(t)>e.get(s)))switch(s){case"debug":console.debug(...i);break;case"info":console.log(...i);break;case"warn":console.warn(...i);break;case"error":console.error(...i);break}}r.log=o})(n||(n={}));var O={"core.view.loading":"Loading the Scandit SDK...","core.singleImageUploader.title":"Analyze an image from your device.","core.singleImageUploader.button":"Choose an Image","core.camera.recovery":"Tap/click to resume scanning","barcode.find.view.textForCollapseCardsButton":"Collapse Cards"};function $(r){return/^https?:\\/\\/(?:[^./]*\\.)*cdn.jsdelivr.net\\//.test(r)?{result:!0,cdnBaseURL:"https://cdn.jsdelivr.net/npm/"}:/^https?:\\/\\/(?:[^./]*\\.)*unpkg.com\\//.test(r)?{result:!0,cdnBaseURL:"https://unpkg.com/"}:{result:!1,cdnBaseURL:""}}function U(r){let e=/scandit-web-datacapture-[a-z]+/i.exec(r);return e?e[0]:null}function P(r,e,t){let a=e,o=$(a);if(o.result){let i=U(a);i!=null&&(a=`${o.cdnBaseURL}${i}@${r}/build/engine/`)}let s=t.replace(".wasm","");return o.result?{jsURI:`${a}${s}.js`,wasmURI:`${a}${s}.wasm`}:{jsURI:`${a}${s}.js?v=${r}`,wasmURI:`${a}${s}.wasm?v=${r}`}}var M=class _ extends Error{constructor(e){super(e.message),Object.setPrototypeOf(this,_.prototype),this.name=e.name}toString(){return`${this.name}: ${this.message}`}};var L=(r,e)=>(e=Symbol[r])?e:Symbol.for("Symbol."+r);var R=function(r,e){this[0]=r,this[1]=e},F=(r,e,t)=>{var a=(i,l,c,u)=>{try{var m=t[i](l),g=(l=m.value)instanceof R,d=m.done;Promise.resolve(g?l[0]:l).then(f=>g?a(i==="return"?i:"next",l[1]?{done:f.done,value:f.value}:f,c,u):c({value:f,done:d})).catch(f=>a("throw",f,c,u))}catch(f){u(f)}},o=i=>s[i]=l=>new Promise((c,u)=>a(i,l,c,u)),s={};return t=t.apply(r,e),s[L("asyncIterator")]=()=>s,o("next"),o("throw"),o("return"),s},N=(r,e,t)=>(e=r[L("asyncIterator")])?e.call(r):(r=r[L("iterator")](),e={},t=(a,o)=>(o=r[a])&&(e[a]=s=>new Promise((i,l,c)=>(s=o.call(r,s),c=s.done,Promise.resolve(s.value).then(u=>i({value:u,done:c}),l)))),t("next"),t("return"),e);var K={};function q(r){return[...new Uint8Array(r)].map(e=>{let t=e.toString(16);return t.length===1?`0${t}`:t}).join("")}function J(r){return F(this,null,function*(){let e=r.getReader();try{for(;;){let{done:t,value:a}=yield new R(e.read());if(t)return;yield a}}finally{e.releaseLock()}})}async function Q(r){let e=[],t=0,a=0;try{for(var o=N(J(r)),s,i,l;s=!(i=await o.next()).done;s=!1){let u=i.value;e.push(u),t+=u.length}}catch(u){l=[u]}finally{try{s&&(i=o.return)&&await i.call(o)}finally{if(l)throw l[0]}}let c=new Uint8Array(t);for(let u of e)c.set(u,a),a+=u.length;return c.buffer}var G=(r=>(r.VALID="VALID",r.INVALID="INVALID",r.NOT_VERIFIABLE="NOT_VERIFIABLE",r))(G||{});async function Z(r,e,t){if(typeof crypto.subtle.digest!="function")return n.log(n.Level.Warn,`Insecure context (see https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts): The hash of the Scandit Data Capture library WASM file found at ${t} could not be verified`),"NOT_VERIFIABLE";try{let a=r instanceof Promise?await r:r,o=await crypto.subtle.digest("SHA-256",a),s=q(o);return e==null?(n.log(n.Level.Warn,"The library hash is not defined or empty, cannot correctly verify integrity."),"NOT_VERIFIABLE"):s===e?(n.log(n.Level.Debug,"Data Capture library WASM integrity has been verified correctly."),"VALID"):(n.log(n.Level.Warn,`The Scandit Data Capture library WASM file found at ${t} seems invalid: expected file hash doesn\'t match (received: ${s}, expected: ${e}). Please ensure the correct Scandit Data Capture file (with correct version) is retrieved.`),"INVALID")}catch(a){return n.log(n.Level.Warn,"Wasm response could not be verified",a),"NOT_VERIFIABLE"}}var I=new Map([["br",4.4],["gzip",2.9],["none",1]]);function X(r){var e;let t="content-encoding";if(r==null||r.get(t)==null)return I.get("none");let a=new Set(((e=r.get(t))!=null?e:"").split(",").map(o=>o.trim()));for(let[o,s]of I)if(a.has(o))return s;return I.get("none")}function Y(r){var e,t;if(r==null)return 0;let a=(e=X(r))!=null?e:1,o=Number.parseInt((t=r.get("content-length"))!=null?t:"0",10);return Number.isNaN(o)?0:Math.floor(o*a*100)/100}function ee(r){let{pathname:e}=new URL(r);for(let[t,a]of Object.entries(K))if(e.endsWith(t))return a.bytes;return 0}var re=(r,e)=>{let t=Y(e);return t===0?ee(r):t};function te(r,e,t,{onProgress:a,onError:o,onComplete:s}){if(!e.body)return[e];let i=re(r,e.headers),l=0,c=0,[u,m]=t?e.body.tee():[e.body],g=u.pipeThrough(new TransformStream({async transform(d,f){try{l+=d.length,c=Number((l/i*100).toFixed(2)),i>0&&d.length>0&&c<100?a?.({percentage:c,loadedBytes:l,privateUri:r}):i===0&&d.length>0&&a?.({percentage:null,loadedBytes:l,privateUri:r}),f.enqueue(d)}catch(w){f.error(w),o?.({error:w})}},flush(d){a?.({percentage:100,loadedBytes:l,privateUri:r}),s?.({percentage:100,loadedBytes:l,privateUri:r}),d.terminate()}}));return[new Response(g,{headers:new Headers(e.headers),status:e.status,statusText:e.statusText}),m]}async function A({wasmURI:r,expectedHash:e,verifyResponseHash:t,onProgress:a,onComplete:o,onError:s,referredOrigin:i}){let l=await fetch(r,{referrerPolicy:"origin",referrer:i??""});if(!l.ok)throw new Error(`HTTP status code is not ok: ${l.status}, ${l.statusText}`);let[c,u]=te(r,l,t,{onProgress:a,onError:s,onComplete:o});return u!=null&&Z(Q(u),e,r),c}function E({wasmURI:r,expectedHash:e,verifyResponseHash:t,progressCallback:a,successCallback:o,importObject:s,referredOrigin:i}){async function l(u){try{let m=await A({wasmURI:r,expectedHash:e,verifyResponseHash:t,onProgress:a,referredOrigin:i}),g=await(u??m).arrayBuffer(),d=await globalThis.WebAssembly.instantiate(g,s);o(d.instance,d.module)}catch(m){n.log(n.Level.Error,m),n.log(n.Level.Error,`Couldn\'t instantiate Scandit SDK DataCapture library at ${r}, did you configure the path for it correctly?`)}}async function c(){let u;try{u=await A({wasmURI:r,expectedHash:e,verifyResponseHash:t,onProgress:a,referredOrigin:i});let m=await globalThis.WebAssembly.instantiateStreaming(u,s);o(m.instance,m.module)}catch(m){n.log(n.Level.Warn,m),n.log(n.Level.Warn,"WebAssembly streaming compile failed. Falling back to ArrayBuffer instantiation (this will make things slower)"),l(u?.bodyUsed===!0?void 0:u)}}typeof globalThis.WebAssembly.instantiateStreaming=="function"?c():l()}async function S(r,e,t,a){return new Promise((o,s)=>{r().then(o).catch(i=>{let l=e*2;if(l>t){s(i);return}a(i),globalThis.setTimeout(()=>{S(r,l,t,a).then(o).catch(s)},e)})})}async function W(r,e){async function t(){return importScripts(r)}try{await S(t,250,4e3,o=>{n.log(n.Level.Warn,o),n.log(n.Level.Warn,`Couldn\'t retrieve Scandit Data Capture library at ${r}, retrying...`)}),self.Module.mainScriptUrlOrBlob=r;let a=globalThis.SDC_WASM_JS_VERSION;return a!==e&&n.log(n.Level.Warn,`The Scandit Data Capture library JS file found at ${r} seems invalid: expected version doesn\'t match (received: ${a}, expected: ${e}). Please ensure the correct Scandit Data Capture file (with correct version) is retrieved.`),!0}catch(a){return n.log(n.Level.Error,a),!1}}var b;(r=>{function e(){return"6.28.10"}r.sdkVersion=e})(b||(b={}));var C=class{constructor(){this.promise=new Promise((r,e)=>{this.reject=e,this.resolve=r})}};var ae=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])),se=()=>(async r=>{try{return typeof MessageChannel<"u"&&new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(r)}catch{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]));function j(){return typeof crossOriginIsolated>"u"?!1:crossOriginIsolated}function H(){try{return new WebAssembly.Memory({initial:1,maximum:1,shared:!0}).buffer.constructor.name==="SharedArrayBuffer"}catch{return!1}}async function k(){return ae()}async function V(){if(!await se())return!1;let r=null;try{r=new Worker(URL.createObjectURL(new Blob([\'postMessage("Worker" in self);\'],{type:"text/javascript"})),{name:"nestedWorkerTest"})}catch{return!1}return new Promise(e=>{if(r==null){e(!1);return}r.onmessage=t=>{r?.terminate(),e(t.data)}})}async function D(){let r=await V();return j()&&H()&&r}function T(r){return typeof r=="object"&&r!=null&&r.document==null&&"addEventListener"in r&&typeof r.importScripts=="function"}var B=class v{constructor(){this.translations=new Map}static getInstance(){return v.instance==null&&(v.instance=new v),v.instance}get(e){var t;return(t=this.translations.get(e))!=null?t:""}getAll(){return{...this.translations}}update(e){this.translations=new Map(Object.entries({...Object.fromEntries(this.translations),...e}))}updateIfMissing(e){for(let[t,a]of Object.entries(e))this.translations.has(t)||this.translations.set(t,a)}};B.getInstance().updateIfMissing(O);var oe=r=>r.result!=null&&r.error==null;function h(r,e){return{type:"djinniResult",payload:{id:r.id,className:r.className,methodName:r.methodName,instanceId:r.instanceId,result:e}}}function ne(r){try{return{type:"result",result:JSON.parse(r)}}catch(e){return{type:"error",error:e}}}var x=class{constructor(e,t){this.parsers=new Map;this.onMessageListener=this.onMessage.bind(this);this.setupPromise=null;this.workerSelf=e,this.moduleHandler=t,T(e)&&(this.workerFunctions={postMessage:this.workerSelf.postMessage.bind(this.workerSelf)},this.listenToMessages())}get Module(){return this.moduleHandler.get()}listenToMessages(){this.workerSelf.addEventListener("message",this.onMessageListener),this.workerSelf.addEventListener("error",e=>{n.log(n.Level.Error,e)}),this.workerSelf.addEventListener("messageerror",e=>{n.log(n.Level.Error,e)})}onMessage(e){return this.performDjinniAction(e.data),!0}async performDjinniAction(e){let t;if(n.log(n.Level.Debug,`ParserMode:performDjinniAction for class: ${e.className}, method: ${e.methodName}`,e.args),e.methodName==="create"){let s=e.args[0].toString();if(this.parsers.has(s)){this.workerFunctions.postMessage(h(e,{type:"result",result:s}));return}try{await this.setup(e.args[1])}catch(i){this.workerFunctions.postMessage(h(e,{type:"error",error:i}));return}t=this.createParser(e),n.log(n.Level.Debug,t),this.workerFunctions.postMessage(t);return}let a=this.parsers.get(e.instanceId??"");if(a==null){this.workerFunctions.postMessage(h(e,{type:"error",error:`parser is not defined: try to access instance with id ${e.instanceId??""}`}));return}let o=a[e.methodName](...e.args);oe(o)?(e.methodName.endsWith("ToJson")&&typeof o.result=="string"&&(o=ne(o.result)),t=h(e,o)):t=h(e,{type:"error",error:o.error}),this.workerFunctions.postMessage(t)}async setup({libraryLocation:e,overrideThreadsSupport:t,overrideSimdSupport:a,verifyResponseHash:o,referredOrigin:s}){if(this.setupPromise!=null)return this.setupPromise;let{resolve:i,reject:l,promise:c}=new C;this.setupPromise=c;let u=b.sdkVersion();if(u==="")throw new M({name:"Invalid library version",message:"Library version is not defined or empty, cannot generate proper path to library files."});let[m,g]=await Promise.all([k(),D()]);t!=="auto"&&(g=t==="on"),a!=="auto"&&(m=a==="on");let d=P(u,e,this.getWasmParserFileName(m,g)),{jsURI:f,wasmURI:w}=d;return this.moduleHandler.set({mainScriptUrlOrBlob:f,locateFile:y=>e+y,onMainComplete:()=>{},onRuntimeInitialized:()=>{i()},print:y=>{n.log(n.Level.Info,y)},instantiateWasm:(y,z)=>(E({importObject:y,wasmURI:w,expectedHash:this.getWasmParserExpectedHash(m,g),verifyResponseHash:o,successCallback:z,progressCallback:()=>{},referredOrigin:s}),{})}),await W(f,u)||l(`Couldn\'t retrieve Parser library at ${f}, did you configure the path for it correctly?`),c}createParser(e){let t=this.Module.ParserInterface.create(e.args[0]);if(n.log(n.Level.Debug,`Parser:create returns ${t.type}`,t),t.type==="error")return h(e,t);let a=e.args[0]?.toString()??"",o=h(e,{type:"result",result:a});return this.parsers.set(a,t.result),o}getWasmParserExpectedHash(e,t){return t?e?"ca637628c6978db0961517d0000ed3c4a7068bbcb0ad4c7c37d120af5296f1b0":"16b8fbd42b70789f0b37c00f7003fea17e58e2177c7f152be188dd6a95f4eda9":e?"b03570962187385708b1201e5c8bdead076e990d5665215f9c535f50b26f55da":"a38d890d13c37a2bc914a8aeb87e6039bb1dec68514c78fc1bf803ca06264738"}getWasmParserFileName(e,t){return t?e?"scandit-datacapture-sdk-parser-simd-pthreads.wasm":"scandit-datacapture-sdk-parser-pthreads.wasm":e?"scandit-datacapture-sdk-parser-simd.wasm":"scandit-datacapture-sdk-parser.wasm"}};var Mr=new x(globalThis,{get:()=>globalThis.Module,set:r=>{globalThis.Module=r}});function Lr(r){}})();\n'],{type:"application/javascript"}));function i(n){return new Worker(u,n)}var l=new Map,r=class extends a$2{constructor(){super(...arguments);this.command="djinniAction";}get worker(){let e=l.get("ParserWorker");return e!=null||(e=i({name:"ParserWorker"}),l.set("ParserWorker",e)),e}async parseStringToJson(e){return {}}async setOptions(e){return !1}getId(){return `${this.dataFormat}`}async create(e,p){return this.dataFormat=e,""}};a([a$1()],r.prototype,"parseStringToJson",1),a([a$1({argumentsSerializer:e=>[JSON.stringify(e[0])]})],r.prototype,"setOptions",1),a([a$1()],r.prototype,"create",1),r=a([b("ParserInterface")],r); export { r as a };