UNPKG

scandit-web-datacapture-core

Version:

Scandit Data Capture SDK for the Web

7 lines (4 loc) 3.52 kB
import { a } from './chunk-SP3HSP4K.js'; import { e, d as d$1, c } from './chunk-FSQXZE3N.js'; var b={};function T(e){return [...new Uint8Array(e)].map(r=>{let n=r.toString(16);return n.length===1?`0${n}`:n}).join("")}function I(e){return d$1(this,null,function*(){let r=e.getReader();try{for(;;){let{done:n,value:t}=yield new c(r.read());if(n)return;yield t;}}finally{r.releaseLock();}})}async function L(e$1){let r=[],n=0,t=0;try{for(var s=e(I(e$1)),f,o,l;f=!(o=await s.next()).done;f=!1){let c=o.value;r.push(c),n+=c.length;}}catch(o){l=[o];}finally{try{f&&(o=s.return)&&await o.call(s);}finally{if(l)throw l[0]}}let a=new Uint8Array(n);for(let c of r)a.set(c,t),t+=c.length;return a.buffer}var S=(t=>(t.VALID="VALID",t.INVALID="INVALID",t.NOT_VERIFIABLE="NOT_VERIFIABLE",t))(S||{});async function R(e,r,n){if(typeof crypto.subtle.digest!="function")return a.log(a.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 ${n} could not be verified`),"NOT_VERIFIABLE";try{let t=e instanceof Promise?await e:e,a$1=await crypto.subtle.digest("SHA-256",t),s=T(a$1);return r==null?(a.log(a.Level.Warn,"The library hash is not defined or empty, cannot correctly verify integrity."),"NOT_VERIFIABLE"):s===r?(a.log(a.Level.Debug,"Data Capture library WASM integrity has been verified correctly."),"VALID"):(a.log(a.Level.Warn,`The Scandit Data Capture library WASM file found at ${n} seems invalid: expected file hash doesn't match (received: ${s}, expected: ${r}). Please ensure the correct Scandit Data Capture file (with correct version) is retrieved.`),"INVALID")}catch(t){return a.log(a.Level.Warn,"Wasm response could not be verified",t),"NOT_VERIFIABLE"}}var d=new Map([["br",4.4],["gzip",2.9],["none",1]]);function w(e){var t;let r="content-encoding";if(e==null||e.get(r)==null)return d.get("none");let n=new Set(((t=e.get(r))!=null?t:"").split(",").map(a=>a.trim()));for(let[a,s]of d)if(n.has(a))return s;return d.get("none")}function B(e){var t,a;if(e==null)return 0;let r=(t=w(e))!=null?t:1,n=Number.parseInt((a=e.get("content-length"))!=null?a:"0",10);return Number.isNaN(n)?0:Math.floor(n*r*100)/100}function x(e){let{pathname:r}=new URL(e);for(let[n,t]of Object.entries(b))if(r.endsWith(n))return t.bytes;return 0}function V(e){b=e;}var N=(e,r)=>{let n=B(r);return n===0?x(e):n};function W(e,r,n,{onProgress:t,onError:a,onComplete:s}){if(!r.body)return [r];let f=N(e,r.headers),o=0,l=0,[c,A]=n?r.body.tee():[r.body],v=c.pipeThrough(new TransformStream({async transform(u,y){try{o+=u.length,l=Number((o/f*100).toFixed(2)),f>0&&u.length>0&&l<100?t==null||t({percentage:l,loadedBytes:o,privateUri:e}):f===0&&u.length>0&&(t==null||t({percentage:null,loadedBytes:o,privateUri:e})),y.enqueue(u);}catch(m){y.error(m),a==null||a({error:m});}},flush(u){t==null||t({percentage:100,loadedBytes:o,privateUri:e}),s==null||s({percentage:100,loadedBytes:o,privateUri:e}),u.terminate();}}));return [new Response(v,{headers:new Headers(r.headers),status:r.status,statusText:r.statusText}),A]}async function D({wasmURI:e,expectedHash:r,verifyResponseHash:n,onProgress:t,onComplete:a,onError:s,referredOrigin:f}){let o=await fetch(e,{referrerPolicy:"origin",referrer:f!=null?f:""});if(!o.ok)throw new Error(`HTTP status code is not ok: ${o.status}, ${o.statusText}`);let[l,c]=W(e,o,n,{onProgress:t,onError:s,onComplete:a});return c!=null&&R(L(c),r,e),l} export { S as a, R as b, V as c, N as d, W as e, D as f };