UNPKG

ngx-scanner-qrcode

Version:

This library is built to provide a solution scanner QR code. This library takes in raw images and will locate, extract and parse any QR code found within.

2 lines 15.8 kB
var zbarWasm=function(t){"use strict";function e(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))}function r(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function n(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var r=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach((function(e){var n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(r,e,n.get?n:{enumerable:!0,get:function(){return t[e]}})})),r}"function"==typeof SuppressedError&&SuppressedError;var i={exports:{}};const o=n(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));function s(t,e){for(var r=0,n=t.length-1;n>=0;n--){var i=t[n];"."===i?t.splice(n,1):".."===i?(t.splice(n,1),r++):r&&(t.splice(n,1),r--)}if(e)for(;r--;r)t.unshift("..");return t}var a=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,c=function(t){return a.exec(t).slice(1)};function u(){for(var t="",e=!1,r=arguments.length-1;r>=-1&&!e;r--){var n=r>=0?arguments[r]:"/";if("string"!=typeof n)throw new TypeError("Arguments to path.resolve must be strings");n&&(t=n+"/"+t,e="/"===n.charAt(0))}return(e?"/":"")+(t=s(m(t.split("/"),(function(t){return!!t})),!e).join("/"))||"."}function f(t){var e=_(t),r="/"===R(t,-1);return(t=s(m(t.split("/"),(function(t){return!!t})),!e).join("/"))||e||(t="."),t&&r&&(t+="/"),(e?"/":"")+t}function _(t){return"/"===t.charAt(0)}function l(){return f(m(Array.prototype.slice.call(arguments,0),(function(t,e){if("string"!=typeof t)throw new TypeError("Arguments to path.join must be strings");return t})).join("/"))}function A(t,e){function r(t){for(var e=0;e<t.length&&""===t[e];e++);for(var r=t.length-1;r>=0&&""===t[r];r--);return e>r?[]:t.slice(e,r-e+1)}t=u(t).substr(1),e=u(e).substr(1);for(var n=r(t.split("/")),i=r(e.split("/")),o=Math.min(n.length,i.length),s=o,a=0;a<o;a++)if(n[a]!==i[a]){s=a;break}var c=[];for(a=s;a<n.length;a++)c.push("..");return(c=c.concat(i.slice(s))).join("/")}function h(t){var e=c(t),r=e[0],n=e[1];return r||n?(n&&(n=n.substr(0,n.length-1)),r+n):"."}function p(t,e){var r=c(t)[2];return e&&r.substr(-1*e.length)===e&&(r=r.substr(0,r.length-e.length)),r}function d(t){return c(t)[3]}const y={extname:d,basename:p,dirname:h,sep:"/",delimiter:":",relative:A,join:l,isAbsolute:_,normalize:f,resolve:u};function m(t,e){if(t.filter)return t.filter(e);for(var r=[],n=0;n<t.length;n++)e(t[n],n,t)&&r.push(t[n]);return r}var R="b"==="ab".substr(-1)?function(t,e,r){return t.substr(e,r)}:function(t,e,r){return e<0&&(e=t.length+e),t.substr(e,r)};const g=n(Object.freeze(Object.defineProperty({__proto__:null,basename:p,default:y,delimiter:":",dirname:h,extname:d,isAbsolute:_,join:l,normalize:f,relative:A,resolve:u,sep:"/"},Symbol.toStringTag,{value:"Module"})));!function(t,e){var r,n=(r="undefined"!=typeof document&&document.currentScript?document.currentScript.src:void 0,"undefined"!=typeof __filename&&(r=r||__filename),function(t={}){var e,n,i=t;i.ready=new Promise(((t,r)=>{e=t,n=r}));var s,a,c,u=Object.assign({},i),f="object"==typeof window,_="function"==typeof importScripts,l="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,A="";if(l){var h=o,p=g;A=_?p.dirname(A)+"/":__dirname+"/",s=(t,e)=>(t=U(t)?new URL(t):p.normalize(t),h.readFileSync(t,e?void 0:"utf8")),c=t=>{var e=s(t,!0);return e.buffer||(e=new Uint8Array(e)),e},a=(t,e,r,n=!0)=>{t=U(t)?new URL(t):p.normalize(t),h.readFile(t,n?void 0:"utf8",((t,i)=>{t?r(t):e(n?i.buffer:i)}))},!i.thisProgram&&process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),i.inspect=()=>"[Emscripten Module object]"}else(f||_)&&(_?A=self.location.href:"undefined"!=typeof document&&document.currentScript&&(A=document.currentScript.src),r&&(A=r),A=0!==A.indexOf("blob:")?A.substr(0,A.replace(/[?#].*/,"").lastIndexOf("/")+1):"",s=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.send(null),e.responseText},_&&(c=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}),a=(t,e,r)=>{var n=new XMLHttpRequest;n.open("GET",t,!0),n.responseType="arraybuffer",n.onload=()=>{200==n.status||0==n.status&&n.response?e(n.response):r()},n.onerror=r,n.send(null)});var d,y,m,R=i.print||console.log.bind(console),B=i.printErr||console.error.bind(console);Object.assign(i,u),u=null,i.arguments&&i.arguments,i.thisProgram&&i.thisProgram,i.quit&&i.quit,i.wasmBinary&&(d=i.wasmBinary),i.noExitRuntime,"object"!=typeof WebAssembly&&T("no native wasm support detected");var v,E,b=!1;function Z(){var t=y.buffer;i.HEAP8=new Int8Array(t),i.HEAP16=new Int16Array(t),i.HEAP32=new Int32Array(t),i.HEAPU8=v=new Uint8Array(t),i.HEAPU16=new Uint16Array(t),i.HEAPU32=E=new Uint32Array(t),i.HEAPF32=new Float32Array(t),i.HEAPF64=new Float64Array(t)}var I=[],S=[],C=[],w=0,N=null;function T(t){i.onAbort&&i.onAbort(t),B(t="Aborted("+t+")"),b=!0,t+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(t);throw n(e),e}var O,P,D="data:application/octet-stream;base64,";function F(t){return t.startsWith(D)}function U(t){return t.startsWith("file://")}function G(t){if(t==O&&d)return new Uint8Array(d);if(c)return c(t);throw"both async and sync fetching of the wasm failed"}function H(t,e,r){return function(t){if(!d&&(f||_)){if("function"==typeof fetch&&!U(t))return fetch(t,{credentials:"same-origin"}).then((e=>{if(!e.ok)throw"failed to load wasm binary file at '"+t+"'";return e.arrayBuffer()})).catch((()=>G(t)));if(a)return new Promise(((e,r)=>{a(t,(t=>e(new Uint8Array(t))),r)}))}return Promise.resolve().then((()=>G(t)))}(t).then((t=>WebAssembly.instantiate(t,e))).then((t=>t)).then(r,(t=>{B("failed to asynchronously prepare wasm: "+t),T(t)}))}F(O="ngx-scanner-qrcode.wasm")||(P=O,O=i.locateFile?i.locateFile(P,A):A+P);var M,j=t=>{for(;t.length>0;)t.shift()(i)},x=t=>{var e=t-y.buffer.byteLength+65535>>>16;try{return y.grow(e),Z(),1}catch(t){}},L="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0,k=[null,[],[]],W=(t,e)=>{var r=k[t];0===e||10===e?((1===t?R:B)(((t,e,r)=>{for(var n=e+r,i=e;t[i]&&!(i>=n);)++i;if(i-e>16&&t.buffer&&L)return L.decode(t.subarray(e,i));for(var o="";e<i;){var s=t[e++];if(128&s){var a=63&t[e++];if(192!=(224&s)){var c=63&t[e++];if((s=224==(240&s)?(15&s)<<12|a<<6|c:(7&s)<<18|a<<12|c<<6|63&t[e++])<65536)o+=String.fromCharCode(s);else{var u=s-65536;o+=String.fromCharCode(55296|u>>10,56320|1023&u)}}else o+=String.fromCharCode((31&s)<<6|a)}else o+=String.fromCharCode(s)}return o})(r,0)),r.length=0):r.push(e)},Y={d:()=>!0,e:function(){return Date.now()},c:t=>{var e=v.length,r=2147483648;if((t>>>=0)>r)return!1;for(var n,i,o=1;o<=4;o*=2){var s=e*(1+.2/o);s=Math.min(s,t+100663296);var a=Math.min(r,(n=Math.max(t,s))+((i=65536)-n%i)%i);if(x(a))return!0}return!1},f:t=>52,b:function(t,e,r,n,i){return 70},a:(t,e,r,n)=>{for(var i=0,o=0;o<r;o++){var s=E[e>>2],a=E[e+4>>2];e+=8;for(var c=0;c<a;c++)W(t,v[s+c]);i+=a}return E[n>>2]=i,0}};function z(){function t(){M||(M=!0,i.calledRun=!0,b||(j(S),e(i),i.onRuntimeInitialized&&i.onRuntimeInitialized(),function(){if(i.postRun)for("function"==typeof i.postRun&&(i.postRun=[i.postRun]);i.postRun.length;)t=i.postRun.shift(),C.unshift(t);var t;j(C)}()))}w>0||(function(){if(i.preRun)for("function"==typeof i.preRun&&(i.preRun=[i.preRun]);i.preRun.length;)t=i.preRun.shift(),I.unshift(t);var t;j(I)}(),w>0||(i.setStatus?(i.setStatus("Running..."),setTimeout((function(){setTimeout((function(){i.setStatus("")}),1),t()}),1)):t()))}if(function(){var t,e,r,o,s={a:Y};function a(t,e){var r,n=t.exports;return y=(m=n).g,Z(),m.s,r=m.h,S.unshift(r),function(t){if(w--,i.monitorRunDependencies&&i.monitorRunDependencies(w),0==w&&N){var e=N;N=null,e()}}(),n}if(w++,i.monitorRunDependencies&&i.monitorRunDependencies(w),i.instantiateWasm)try{return i.instantiateWasm(s,a)}catch(t){B("Module.instantiateWasm callback failed with error: "+t),n(t)}(t=d,e=O,r=s,o=function(t){a(t.instance)},t||"function"!=typeof WebAssembly.instantiateStreaming||F(e)||U(e)||l||"function"!=typeof fetch?H(e,r,o):fetch(e,{credentials:"same-origin"}).then((t=>WebAssembly.instantiateStreaming(t,r).then(o,(function(t){return B("wasm streaming compile failed: "+t),B("falling back to ArrayBuffer instantiation"),H(e,r,o)}))))).catch(n)}(),i._ImageScanner_create=()=>(i._ImageScanner_create=m.i)(),i._ImageScanner_destory=t=>(i._ImageScanner_destory=m.j)(t),i._ImageScanner_set_config=(t,e,r,n)=>(i._ImageScanner_set_config=m.k)(t,e,r,n),i._ImageScanner_enable_cache=(t,e)=>(i._ImageScanner_enable_cache=m.l)(t,e),i._ImageScanner_recycle_image=(t,e)=>(i._ImageScanner_recycle_image=m.m)(t,e),i._ImageScanner_get_results=t=>(i._ImageScanner_get_results=m.n)(t),i._ImageScanner_scan=(t,e)=>(i._ImageScanner_scan=m.o)(t,e),i._Image_create=(t,e,r,n,o,s)=>(i._Image_create=m.p)(t,e,r,n,o,s),i._Image_destory=t=>(i._Image_destory=m.q)(t),i._Image_get_symbols=t=>(i._Image_get_symbols=m.r)(t),i._free=t=>(i._free=m.t)(t),i._malloc=t=>(i._malloc=m.u)(t),N=function t(){M||z(),M||(N=t)},i.preInit)for("function"==typeof i.preInit&&(i.preInit=[i.preInit]);i.preInit.length>0;)i.preInit.pop()();return z(),t.ready});t.exports=n}(i);const B=r(i.exports);let v;function E(t={}){v=function(){return e(this,void 0,void 0,(function*(){const e=yield B(t);if(e)return e;throw Error("WASM was not loaded")}))}()}function b(){return e(this,void 0,void 0,(function*(){return v||E(),yield v}))}var Z,I,S;t.ZBarSymbolType=void 0,(Z=t.ZBarSymbolType||(t.ZBarSymbolType={}))[Z.ZBAR_NONE=0]="ZBAR_NONE",Z[Z.ZBAR_PARTIAL=1]="ZBAR_PARTIAL",Z[Z.ZBAR_EAN2=2]="ZBAR_EAN2",Z[Z.ZBAR_EAN5=5]="ZBAR_EAN5",Z[Z.ZBAR_EAN8=8]="ZBAR_EAN8",Z[Z.ZBAR_UPCE=9]="ZBAR_UPCE",Z[Z.ZBAR_ISBN10=10]="ZBAR_ISBN10",Z[Z.ZBAR_UPCA=12]="ZBAR_UPCA",Z[Z.ZBAR_EAN13=13]="ZBAR_EAN13",Z[Z.ZBAR_ISBN13=14]="ZBAR_ISBN13",Z[Z.ZBAR_COMPOSITE=15]="ZBAR_COMPOSITE",Z[Z.ZBAR_I25=25]="ZBAR_I25",Z[Z.ZBAR_DATABAR=34]="ZBAR_DATABAR",Z[Z.ZBAR_DATABAR_EXP=35]="ZBAR_DATABAR_EXP",Z[Z.ZBAR_CODABAR=38]="ZBAR_CODABAR",Z[Z.ZBAR_CODE39=39]="ZBAR_CODE39",Z[Z.ZBAR_PDF417=57]="ZBAR_PDF417",Z[Z.ZBAR_QRCODE=64]="ZBAR_QRCODE",Z[Z.ZBAR_SQCODE=80]="ZBAR_SQCODE",Z[Z.ZBAR_CODE93=93]="ZBAR_CODE93",Z[Z.ZBAR_CODE128=128]="ZBAR_CODE128",Z[Z.ZBAR_SYMBOL=255]="ZBAR_SYMBOL",Z[Z.ZBAR_ADDON2=512]="ZBAR_ADDON2",Z[Z.ZBAR_ADDON5=1280]="ZBAR_ADDON5",Z[Z.ZBAR_ADDON=1792]="ZBAR_ADDON",t.ZBarConfigType=void 0,(I=t.ZBarConfigType||(t.ZBarConfigType={}))[I.ZBAR_CFG_ENABLE=0]="ZBAR_CFG_ENABLE",I[I.ZBAR_CFG_ADD_CHECK=1]="ZBAR_CFG_ADD_CHECK",I[I.ZBAR_CFG_EMIT_CHECK=2]="ZBAR_CFG_EMIT_CHECK",I[I.ZBAR_CFG_ASCII=3]="ZBAR_CFG_ASCII",I[I.ZBAR_CFG_BINARY=4]="ZBAR_CFG_BINARY",I[I.ZBAR_CFG_NUM=5]="ZBAR_CFG_NUM",I[I.ZBAR_CFG_MIN_LEN=32]="ZBAR_CFG_MIN_LEN",I[I.ZBAR_CFG_MAX_LEN=33]="ZBAR_CFG_MAX_LEN",I[I.ZBAR_CFG_UNCERTAINTY=64]="ZBAR_CFG_UNCERTAINTY",I[I.ZBAR_CFG_POSITION=128]="ZBAR_CFG_POSITION",I[I.ZBAR_CFG_TEST_INVERTED=129]="ZBAR_CFG_TEST_INVERTED",I[I.ZBAR_CFG_X_DENSITY=256]="ZBAR_CFG_X_DENSITY",I[I.ZBAR_CFG_Y_DENSITY=257]="ZBAR_CFG_Y_DENSITY",t.ZBarOrientation=void 0,(S=t.ZBarOrientation||(t.ZBarOrientation={}))[S.ZBAR_ORIENT_UNKNOWN=-1]="ZBAR_ORIENT_UNKNOWN",S[S.ZBAR_ORIENT_UP=0]="ZBAR_ORIENT_UP",S[S.ZBAR_ORIENT_RIGHT=1]="ZBAR_ORIENT_RIGHT",S[S.ZBAR_ORIENT_DOWN=2]="ZBAR_ORIENT_DOWN",S[S.ZBAR_ORIENT_LEFT=3]="ZBAR_ORIENT_LEFT";class C{constructor(t,e){this.ptr=t,this.inst=e}checkAlive(){if(!this.ptr)throw Error("Call after destroyed")}getPointer(){return this.checkAlive(),this.ptr}}class w{constructor(t,e){this.ptr=t,this.ptr32=t>>2,this.buf=e,this.HEAP8=new Int8Array(e),this.HEAPU32=new Uint32Array(e),this.HEAP32=new Int32Array(e)}}class N extends w{get type(){return this.HEAPU32[this.ptr32]}get data(){const t=this.HEAPU32[this.ptr32+4],e=this.HEAPU32[this.ptr32+5];return Int8Array.from(this.HEAP8.subarray(e,e+t))}get points(){const t=this.HEAPU32[this.ptr32+7],e=this.HEAPU32[this.ptr32+8]>>2,r=[];for(let n=0;n<t;++n){const t=this.HEAP32[e+2*n],i=this.HEAP32[e+2*n+1];r.push({x:t,y:i})}return r}get orientation(){return this.HEAP32[this.ptr32+9]}get next(){const t=this.HEAPU32[this.ptr32+11];return t?new N(t,this.buf):null}get time(){return this.HEAPU32[this.ptr32+13]}get cacheCount(){return this.HEAP32[this.ptr32+14]}get quality(){return this.HEAP32[this.ptr32+15]}}class T extends w{get head(){const t=this.HEAPU32[this.ptr32+2];return t?new N(t,this.buf):null}}class O{constructor(e){this.type=e.type,this.typeName=t.ZBarSymbolType[this.type],this.data=e.data,this.points=e.points,this.orientation=e.orientation,this.time=e.time,this.cacheCount=e.cacheCount,this.quality=e.quality}static createSymbolsFromPtr(t,e){if(0==t)return[];let r=new T(t,e).head;const n=[];for(;null!==r;)n.push(new O(r)),r=r.next;return n}decode(t){return new TextDecoder(t).decode(this.data)}}class P extends C{static createFromGrayBuffer(t,r,n,i=0){return e(this,void 0,void 0,(function*(){const e=yield b(),o=new Uint8Array(n),s=t*r;if(s!==o.byteLength)throw Error(`data length (${o.byteLength} bytes) does not match width and height (${s} bytes)`);const a=e._malloc(s);e.HEAPU8.set(o,a);return new this(e._Image_create(t,r,808466521,a,s,i),e)}))}static createFromRGBABuffer(t,r,n,i=0){return e(this,void 0,void 0,(function*(){const e=yield b(),o=new Uint8Array(n),s=t*r;if(4*s!==o.byteLength)throw Error(`data length (${o.byteLength} bytes) does not match width and height (${4*s} bytes)`);const a=e._malloc(s),c=a+s,u=e.HEAPU8;for(let t=a,e=0;t<c;t++,e+=4)u[t]=19595*o[e]+38469*o[e+1]+7472*o[e+2]>>16;return new this(e._Image_create(t,r,808466521,a,s,i),e)}))}destroy(){this.checkAlive(),this.inst._Image_destory(this.ptr),this.ptr=0}getSymbols(){this.checkAlive();const t=this.inst._Image_get_symbols(this.ptr);return O.createSymbolsFromPtr(t,this.inst.HEAPU8.buffer)}}class D extends C{static create(){return e(this,void 0,void 0,(function*(){const t=yield b();return new this(t._ImageScanner_create(),t)}))}destroy(){this.checkAlive(),this.inst._ImageScanner_destory(this.ptr),this.ptr=0}setConfig(t,e,r){return this.checkAlive(),this.inst._ImageScanner_set_config(this.ptr,t,e,r)}enableCache(t=!0){this.checkAlive(),this.inst._ImageScanner_enable_cache(this.ptr,t)}recycleImage(t){this.checkAlive(),this.inst._ImageScanner_recycle_image(this.ptr,t.getPointer())}getResults(){this.checkAlive();const t=this.inst._ImageScanner_get_results(this.ptr);return O.createSymbolsFromPtr(t,this.inst.HEAPU8.buffer)}scan(t){return this.checkAlive(),this.inst._ImageScanner_scan(this.ptr,t.getPointer())}}const F=()=>e(void 0,void 0,void 0,(function*(){const e=yield D.create();return e.setConfig(t.ZBarSymbolType.ZBAR_NONE,t.ZBarConfigType.ZBAR_CFG_BINARY,1),e}));let U;const G=(t,r)=>e(void 0,void 0,void 0,(function*(){void 0===r&&(r=U||(yield F()),U=r);const e=r.scan(t);if(e<0)throw Error("Scan Failed");return 0===e?[]:t.getSymbols()})),H=(t,r,n,i)=>e(void 0,void 0,void 0,(function*(){const e=yield P.createFromRGBABuffer(r,n,t),o=yield G(e,i);return e.destroy(),o}));return t.ZBarImage=P,t.ZBarScanner=D,t.ZBarSymbol=O,t.getDefaultScanner=F,t.getInstance=b,t.scanGrayBuffer=(t,r,n,i)=>e(void 0,void 0,void 0,(function*(){const e=yield P.createFromGrayBuffer(r,n,t),o=yield G(e,i);return e.destroy(),o})),t.scanImageData=(t,r)=>e(void 0,void 0,void 0,(function*(){return yield H(t.data.buffer,t.width,t.height,r)})),t.scanRGBABuffer=H,t.setModuleArgs=E,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),t}({}); //# sourceMappingURL=index.js.map