@undecaf/zbar-wasm
Advanced tools
Comparing version
@@ -22,3 +22,19 @@ interface ZBarInstance extends Record<string, WebAssembly.ExportValue | ArrayBuffer> { | ||
declare const getInstance: () => Promise<ZBarInstance>; | ||
/** | ||
* Arguments used for building a `ZBarInstance` | ||
*/ | ||
type ZBarModuleArgs = { | ||
locateFile?: (filename: string, directory: string) => string; | ||
}; | ||
/** | ||
* Causes a new `ZBarInstance` built with the specified arguments | ||
* to be returned by subsequent `getInstance()` calls. | ||
*/ | ||
declare function setModuleArgs(args?: ZBarModuleArgs): void; | ||
/** | ||
* Returns a `ZBarInstance` built with the arguments set by `setModuleArgs()`, | ||
* or built without any arguments. | ||
* Successive calls return the same instance until `setModuleArgs()` is called. | ||
*/ | ||
declare function getInstance(): Promise<ZBarInstance>; | ||
@@ -139,2 +155,2 @@ declare enum ZBarSymbolType { | ||
export { type Point, ZBarConfigType, ZBarImage, ZBarOrientation, ZBarScanner, ZBarSymbol, ZBarSymbolType, getDefaultScanner, getInstance, scanGrayBuffer, scanImageData, scanRGBABuffer }; | ||
export { type Point, ZBarConfigType, ZBarImage, type ZBarModuleArgs, ZBarOrientation, ZBarScanner, ZBarSymbol, ZBarSymbolType, getDefaultScanner, getInstance, scanGrayBuffer, scanImageData, scanRGBABuffer, setModuleArgs }; |
@@ -1,2 +0,2 @@ | ||
var zbarWasm=function(e){"use strict";function t(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{c(n.next(e))}catch(e){o(e)}}function a(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))}function r(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function n(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})})),r}"function"==typeof SuppressedError&&SuppressedError;var i={exports:{}};const o=n(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));function s(e,t){for(var r=0,n=e.length-1;n>=0;n--){var i=e[n];"."===i?e.splice(n,1):".."===i?(e.splice(n,1),r++):r&&(e.splice(n,1),r--)}if(t)for(;r--;r)e.unshift("..");return e}var a=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,c=function(e){return a.exec(e).slice(1)};function u(){for(var e="",t=!1,r=arguments.length-1;r>=-1&&!t;r--){var n=r>=0?arguments[r]:"/";if("string"!=typeof n)throw new TypeError("Arguments to path.resolve must be strings");n&&(e=n+"/"+e,t="/"===n.charAt(0))}return(t?"/":"")+(e=s(m(e.split("/"),(function(e){return!!e})),!t).join("/"))||"."}function f(e){var t=_(e),r="/"===R(e,-1);return(e=s(m(e.split("/"),(function(e){return!!e})),!t).join("/"))||t||(e="."),e&&r&&(e+="/"),(t?"/":"")+e}function _(e){return"/"===e.charAt(0)}function l(){return f(m(Array.prototype.slice.call(arguments,0),(function(e,t){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e})).join("/"))}function A(e,t){function r(e){for(var t=0;t<e.length&&""===e[t];t++);for(var r=e.length-1;r>=0&&""===e[r];r--);return t>r?[]:e.slice(t,r-t+1)}e=u(e).substr(1),t=u(t).substr(1);for(var n=r(e.split("/")),i=r(t.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(e){var t=c(e),r=t[0],n=t[1];return r||n?(n&&(n=n.substr(0,n.length-1)),r+n):"."}function p(e,t){var r=c(e)[2];return t&&r.substr(-1*t.length)===t&&(r=r.substr(0,r.length-t.length)),r}function d(e){return c(e)[3]}const y={extname:d,basename:p,dirname:h,sep:"/",delimiter:":",relative:A,join:l,isAbsolute:_,normalize:f,resolve:u};function m(e,t){if(e.filter)return e.filter(t);for(var r=[],n=0;n<e.length;n++)t(e[n],n,e)&&r.push(e[n]);return r}var R="b"==="ab".substr(-1)?function(e,t,r){return e.substr(t,r)}:function(e,t,r){return t<0&&(t=e.length+t),e.substr(t,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(e,t){var r,n=(r="undefined"!=typeof document&&document.currentScript?document.currentScript.src:void 0,"undefined"!=typeof __filename&&(r=r||__filename),function(e={}){var t,n,i=e;i.ready=new Promise(((e,r)=>{t=e,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=(e,t)=>(e=U(e)?new URL(e):p.normalize(e),h.readFileSync(e,t?void 0:"utf8")),c=e=>{var t=s(e,!0);return t.buffer||(t=new Uint8Array(t)),t},a=(e,t,r,n=!0)=>{e=U(e)?new URL(e):p.normalize(e),h.readFile(e,n?void 0:"utf8",((e,i)=>{e?r(e):t(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=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.send(null),t.responseText},_&&(c=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}),a=(e,t,r)=>{var n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=()=>{200==n.status||0==n.status&&n.response?t(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 e=y.buffer;i.HEAP8=new Int8Array(e),i.HEAP16=new Int16Array(e),i.HEAP32=new Int32Array(e),i.HEAPU8=v=new Uint8Array(e),i.HEAPU16=new Uint16Array(e),i.HEAPU32=E=new Uint32Array(e),i.HEAPF32=new Float32Array(e),i.HEAPF64=new Float64Array(e)}var I=[],S=[],C=[],w=0,N=null;function T(e){i.onAbort&&i.onAbort(e),B(e="Aborted("+e+")"),b=!0,e+=". Build with -sASSERTIONS for more info.";var t=new WebAssembly.RuntimeError(e);throw n(t),t}var O,P,D="data:application/octet-stream;base64,";function F(e){return e.startsWith(D)}function U(e){return e.startsWith("file://")}function G(e){if(e==O&&d)return new Uint8Array(d);if(c)return c(e);throw"both async and sync fetching of the wasm failed"}function H(e,t,r){return function(e){if(!d&&(f||_)){if("function"==typeof fetch&&!U(e))return fetch(e,{credentials:"same-origin"}).then((t=>{if(!t.ok)throw"failed to load wasm binary file at '"+e+"'";return t.arrayBuffer()})).catch((()=>G(e)));if(a)return new Promise(((t,r)=>{a(e,(e=>t(new Uint8Array(e))),r)}))}return Promise.resolve().then((()=>G(e)))}(e).then((e=>WebAssembly.instantiate(e,t))).then((e=>e)).then(r,(e=>{B("failed to asynchronously prepare wasm: "+e),T(e)}))}F(O="zbar.wasm")||(P=O,O=i.locateFile?i.locateFile(P,A):A+P);var M,j=e=>{for(;e.length>0;)e.shift()(i)},x=e=>{var t=e-y.buffer.byteLength+65535>>>16;try{return y.grow(t),Z(),1}catch(e){}},L="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0,k=[null,[],[]],W=(e,t)=>{var r=k[e];0===t||10===t?((1===e?R:B)(((e,t,r)=>{for(var n=t+r,i=t;e[i]&&!(i>=n);)++i;if(i-t>16&&e.buffer&&L)return L.decode(e.subarray(t,i));for(var o="";t<i;){var s=e[t++];if(128&s){var a=63&e[t++];if(192!=(224&s)){var c=63&e[t++];if((s=224==(240&s)?(15&s)<<12|a<<6|c:(7&s)<<18|a<<12|c<<6|63&e[t++])<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(t)},Y={d:()=>!0,e:function(){return Date.now()},c:e=>{var t=v.length,r=2147483648;if((e>>>=0)>r)return!1;for(var n,i,o=1;o<=4;o*=2){var s=t*(1+.2/o);s=Math.min(s,e+100663296);var a=Math.min(r,(n=Math.max(e,s))+((i=65536)-n%i)%i);if(x(a))return!0}return!1},f:e=>52,b:function(e,t,r,n,i){return 70},a:(e,t,r,n)=>{for(var i=0,o=0;o<r;o++){var s=E[t>>2],a=E[t+4>>2];t+=8;for(var c=0;c<a;c++)W(e,v[s+c]);i+=a}return E[n>>2]=i,0}};function z(){function e(){M||(M=!0,i.calledRun=!0,b||(j(S),t(i),i.onRuntimeInitialized&&i.onRuntimeInitialized(),function(){if(i.postRun)for("function"==typeof i.postRun&&(i.postRun=[i.postRun]);i.postRun.length;)e=i.postRun.shift(),C.unshift(e);var e;j(C)}()))}w>0||(function(){if(i.preRun)for("function"==typeof i.preRun&&(i.preRun=[i.preRun]);i.preRun.length;)e=i.preRun.shift(),I.unshift(e);var e;j(I)}(),w>0||(i.setStatus?(i.setStatus("Running..."),setTimeout((function(){setTimeout((function(){i.setStatus("")}),1),e()}),1)):e()))}if(function(){var e,t,r,o,s={a:Y};function a(e,t){var r,n=e.exports;return y=(m=n).g,Z(),m.s,r=m.h,S.unshift(r),function(e){if(w--,i.monitorRunDependencies&&i.monitorRunDependencies(w),0==w&&N){var t=N;N=null,t()}}(),n}if(w++,i.monitorRunDependencies&&i.monitorRunDependencies(w),i.instantiateWasm)try{return i.instantiateWasm(s,a)}catch(e){B("Module.instantiateWasm callback failed with error: "+e),n(e)}(e=d,t=O,r=s,o=function(e){a(e.instance)},e||"function"!=typeof WebAssembly.instantiateStreaming||F(t)||U(t)||l||"function"!=typeof fetch?H(t,r,o):fetch(t,{credentials:"same-origin"}).then((e=>WebAssembly.instantiateStreaming(e,r).then(o,(function(e){return B("wasm streaming compile failed: "+e),B("falling back to ArrayBuffer instantiation"),H(t,r,o)}))))).catch(n)}(),i._ImageScanner_create=()=>(i._ImageScanner_create=m.i)(),i._ImageScanner_destory=e=>(i._ImageScanner_destory=m.j)(e),i._ImageScanner_set_config=(e,t,r,n)=>(i._ImageScanner_set_config=m.k)(e,t,r,n),i._ImageScanner_enable_cache=(e,t)=>(i._ImageScanner_enable_cache=m.l)(e,t),i._ImageScanner_recycle_image=(e,t)=>(i._ImageScanner_recycle_image=m.m)(e,t),i._ImageScanner_get_results=e=>(i._ImageScanner_get_results=m.n)(e),i._ImageScanner_scan=(e,t)=>(i._ImageScanner_scan=m.o)(e,t),i._Image_create=(e,t,r,n,o,s)=>(i._Image_create=m.p)(e,t,r,n,o,s),i._Image_destory=e=>(i._Image_destory=m.q)(e),i._Image_get_symbols=e=>(i._Image_get_symbols=m.r)(e),i._free=e=>(i._free=m.t)(e),i._malloc=e=>(i._malloc=m.u)(e),N=function e(){M||z(),M||(N=e)},i.preInit)for("function"==typeof i.preInit&&(i.preInit=[i.preInit]);i.preInit.length>0;)i.preInit.pop()();return z(),e.ready});e.exports=n}(i);const B=r(i.exports);let v;const E=t(void 0,void 0,void 0,(function*(){if(v=yield B(),!v)throw Error("WASM was not loaded");return v})),b=()=>t(void 0,void 0,void 0,(function*(){return yield E}));var Z,I,S;e.ZBarSymbolType=void 0,(Z=e.ZBarSymbolType||(e.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",e.ZBarConfigType=void 0,(I=e.ZBarConfigType||(e.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",e.ZBarOrientation=void 0,(S=e.ZBarOrientation||(e.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(e,t){this.ptr=e,this.inst=t}checkAlive(){if(!this.ptr)throw Error("Call after destroyed")}getPointer(){return this.checkAlive(),this.ptr}}class w{constructor(e,t){this.ptr=e,this.ptr32=e>>2,this.buf=t,this.HEAP8=new Int8Array(t),this.HEAPU32=new Uint32Array(t),this.HEAP32=new Int32Array(t)}}class N extends w{get type(){return this.HEAPU32[this.ptr32]}get data(){const e=this.HEAPU32[this.ptr32+4],t=this.HEAPU32[this.ptr32+5];return Int8Array.from(this.HEAP8.subarray(t,t+e))}get points(){const e=this.HEAPU32[this.ptr32+7],t=this.HEAPU32[this.ptr32+8]>>2,r=[];for(let n=0;n<e;++n){const e=this.HEAP32[t+2*n],i=this.HEAP32[t+2*n+1];r.push({x:e,y:i})}return r}get orientation(){return this.HEAP32[this.ptr32+9]}get next(){const e=this.HEAPU32[this.ptr32+11];return e?new N(e,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 e=this.HEAPU32[this.ptr32+2];return e?new N(e,this.buf):null}}class O{constructor(t){this.type=t.type,this.typeName=e.ZBarSymbolType[this.type],this.data=t.data,this.points=t.points,this.orientation=t.orientation,this.time=t.time,this.cacheCount=t.cacheCount,this.quality=t.quality}static createSymbolsFromPtr(e,t){if(0==e)return[];let r=new T(e,t).head;const n=[];for(;null!==r;)n.push(new O(r)),r=r.next;return n}decode(e){return new TextDecoder(e).decode(this.data)}}class P extends C{static createFromGrayBuffer(e,r,n,i=0){return t(this,void 0,void 0,(function*(){const t=yield b(),o=new Uint8Array(n),s=e*r;if(s!==o.byteLength)throw Error(`data length (${o.byteLength} bytes) does not match width and height (${s} bytes)`);const a=t._malloc(s);t.HEAPU8.set(o,a);return new this(t._Image_create(e,r,808466521,a,s,i),t)}))}static createFromRGBABuffer(e,r,n,i=0){return t(this,void 0,void 0,(function*(){const t=yield b(),o=new Uint8Array(n),s=e*r;if(4*s!==o.byteLength)throw Error(`data length (${o.byteLength} bytes) does not match width and height (${4*s} bytes)`);const a=t._malloc(s),c=a+s,u=t.HEAPU8;for(let e=a,t=0;e<c;e++,t+=4)u[e]=19595*o[t]+38469*o[t+1]+7472*o[t+2]>>16;return new this(t._Image_create(e,r,808466521,a,s,i),t)}))}destroy(){this.checkAlive(),this.inst._Image_destory(this.ptr),this.ptr=0}getSymbols(){this.checkAlive();const e=this.inst._Image_get_symbols(this.ptr);return O.createSymbolsFromPtr(e,this.inst.HEAPU8.buffer)}}class D extends C{static create(){return t(this,void 0,void 0,(function*(){const e=yield b();return new this(e._ImageScanner_create(),e)}))}destroy(){this.checkAlive(),this.inst._ImageScanner_destory(this.ptr),this.ptr=0}setConfig(e,t,r){return this.checkAlive(),this.inst._ImageScanner_set_config(this.ptr,e,t,r)}enableCache(e=!0){this.checkAlive(),this.inst._ImageScanner_enable_cache(this.ptr,e)}recycleImage(e){this.checkAlive(),this.inst._ImageScanner_recycle_image(this.ptr,e.getPointer())}getResults(){this.checkAlive();const e=this.inst._ImageScanner_get_results(this.ptr);return O.createSymbolsFromPtr(e,this.inst.HEAPU8.buffer)}scan(e){return this.checkAlive(),this.inst._ImageScanner_scan(this.ptr,e.getPointer())}}const F=()=>t(void 0,void 0,void 0,(function*(){const t=yield D.create();return t.setConfig(e.ZBarSymbolType.ZBAR_NONE,e.ZBarConfigType.ZBAR_CFG_BINARY,1),t}));let U;const G=(e,r)=>t(void 0,void 0,void 0,(function*(){void 0===r&&(r=U||(yield F()),U=r);const t=r.scan(e);if(t<0)throw Error("Scan Failed");return 0===t?[]:e.getSymbols()})),H=(e,r,n,i)=>t(void 0,void 0,void 0,(function*(){const t=yield P.createFromRGBABuffer(r,n,e),o=yield G(t,i);return t.destroy(),o}));return e.ZBarImage=P,e.ZBarScanner=D,e.ZBarSymbol=O,e.getDefaultScanner=F,e.getInstance=b,e.scanGrayBuffer=(e,r,n,i)=>t(void 0,void 0,void 0,(function*(){const t=yield P.createFromGrayBuffer(r,n,e),o=yield G(t,i);return t.destroy(),o})),e.scanImageData=(e,r)=>t(void 0,void 0,void 0,(function*(){return yield H(e.data.buffer,e.width,e.height,r)})),e.scanRGBABuffer=H,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({}); | ||
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="zbar.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 |
{ | ||
"name": "@undecaf/zbar-wasm", | ||
"version": "0.10.1", | ||
"version": "0.11.0", | ||
"description": "A WebAssembly build of the C/C++ ZBar barcode reader", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -26,3 +26,3 @@ # A WebAssembly build of the ZBar Bar Code Reader | ||
:warning: zbar-wasm version 0.10 contains breaking changes with respect to version 0.9, please refer to section [Bundling/deploying zbar-wasm](#bundlingdeploying-zbar-wasm). | ||
:warning: zbar-wasm versions 0.10 and above contain breaking changes with respect to version 0.9, please refer to section [Bundling/deploying zbar-wasm](#bundlingdeploying-zbar-wasm). | ||
@@ -58,3 +58,3 @@ | ||
<script type="module"> | ||
import * as zbarWasm from 'https://cdn.jsdelivr.net/npm/@undecaf/zbar-wasm@0.10.1/dist/index.js' | ||
import * as zbarWasm from 'https://cdn.jsdelivr.net/npm/@undecaf/zbar-wasm@0.11.0/dist/index.js' | ||
@@ -93,3 +93,3 @@ (async () => { | ||
<script type="module"> | ||
import * as zbarWasm from 'https://cdn.jsdelivr.net/npm/@undecaf/zbar-wasm@0.10.1/dist/index.js' | ||
import * as zbarWasm from 'https://cdn.jsdelivr.net/npm/@undecaf/zbar-wasm@0.11.0/dist/index.js' | ||
⁝ | ||
@@ -102,3 +102,3 @@ ``` | ||
⁝ | ||
<script src="https://cdn.jsdelivr.net/npm/@undecaf/zbar-wasm@0.10.1/dist/index.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@undecaf/zbar-wasm@0.11.0/dist/index.js"></script> | ||
<script> | ||
@@ -114,5 +114,5 @@ ⁝ | ||
```shell script | ||
$ npm install @undecaf/zbar-wasm@0.10.1 | ||
$ npm install @undecaf/zbar-wasm@0.11.0 | ||
or | ||
$ yarn add @undecaf/zbar-wasm@0.10.1 | ||
$ yarn add @undecaf/zbar-wasm@0.11.0 | ||
``` | ||
@@ -145,3 +145,3 @@ | ||
console.log(ssymbols[0]?.typeName, symbols[0]?.decode()) | ||
console.log(symbols[0]?.typeName, symbols[0]?.decode()) | ||
})('https://raw.githubusercontent.com/undecaf/zbar-wasm/master/tests/img/qr_code.png') | ||
@@ -160,13 +160,12 @@ ``` | ||
zbar-wasm provides ESM and CommonJS modules for Node.js and browsers. One of them needs to be | ||
bundled in your application. In any case, barcode scanning is delegated to the WebAssembly code | ||
in file `zbar.wasm`. At runtime, this file can be provided in different ways depending on the | ||
bundling configuration and on which zbar-wasm module was emitted by the bundler: | ||
Barcode scanning is always delegated to the WebAssembly code in file `zbar.wasm`. | ||
zbar-wasm provides various functionally equivalent ESM and CommonJS modules for Node.js and for browsers | ||
that differ in how `zbar.wasm` is to be provided at runtime: | ||
+ It can be loaded from a CDN by browsers. | ||
+ It can be bundled as an asset. That asset should be served to browsers as `application/wasm` | ||
+ `zbar.wasm` can be loaded from a CDN by browsers. | ||
+ `zbar.wasm` can be bundled as an asset. That asset should be served to browsers as `application/wasm` | ||
so that it can be compiled in parallel with being received. | ||
+ Several zbar-wasm modules contain `zbar.wasm` as inline data. | ||
This overview shows which modules are available in zbar-wasm: | ||
The following overview shows the modules that are available in zbar-wasm. One of them needs to be bundled in your application. | ||
@@ -189,4 +188,4 @@ | Path in package | Module type | Node core modules polyfilled<br>(suitable for browsers) | `zbar.wasm` inlined | | ||
[Building zbar-wasm](#building-zbar-wasm-from-source) runs bundling tests with [Webpack](https://webpack.js.org/), [Rollup](https://rollupjs.org/) and | ||
[esbuild](https://esbuild.github.io/) and also tests the resulting bundles. The bundler configuration files | ||
[Building zbar-wasm](#building-zbar-wasm-from-source) includes testing the bundling process with [Webpack](https://webpack.js.org/), [Rollup](https://rollupjs.org/) and | ||
[esbuild](https://esbuild.github.io/) and also testing the resulting bundles. The bundler configuration files | ||
[`tests/{webpack,rollup,esbuild}.config.js`](https://github.com/undecaf/zbar-wasm/tree/master/tests) | ||
@@ -204,2 +203,29 @@ may be used as a reference of how to achieve a particular bundling result. Each of them covers | ||
### Loading `zbar.wasm` from a custom location | ||
As a last resort, if you cannot make your bundler place `zbar.wasm` where it can be located by the script, | ||
you can specify an URL or path for that WASM file at runtime: | ||
```javascript | ||
import { scanImageData, setModuleArgs } from '@undecaf/zbar-wasm'; | ||
⁝ | ||
// Call this function once at the beginning | ||
setModuleArgs({ | ||
/** | ||
* This function must return the URL or path of the WASM file. | ||
* | ||
* @param filename default WASM filename ('zbar.wasm') | ||
* @param directory default WASM directory (URL or directory of the current script) | ||
* @returns {string} URL or path of the WASM file | ||
*/ | ||
locateFile: (filename, directory) => { | ||
return 'file:///your/wasm/directory/zbar.wasm' | ||
} | ||
}); | ||
⁝ | ||
// Then use the scanner | ||
const symbols = await scanImageData(...); | ||
``` | ||
## API documentation | ||
@@ -206,0 +232,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
3296594
0.26%5538
0.34%295
9.67%