UNPKG

@openhealthnz-credentials/pdf-image-qr-scanner

Version:

Library to scan user-uploaded PDF's or images locally and reliably for QR codes using jsQR.

3 lines (2 loc) 3.03 kB
import e from"jsqr";import t from"pdfjs-dist";function n(e,t,i){if(!e.s){if(i instanceof r){if(!i.s)return void(i.o=n.bind(null,e,t));1&t&&(t=i.s),i=i.v}if(i&&i.then)return void i.then(n.bind(null,e,t),n.bind(null,e,2));e.s=t,e.v=i;var o=e.o;o&&o(e)}}var r=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var i=new e,o=this.s;if(o){var u=1&o?t:r;if(u){try{n(i,1,u(this.v))}catch(e){n(i,2,e)}return i}return this}return this.o=function(e){try{var o=e.v;1&e.s?n(i,1,t?t(o):o):r?n(i,1,r(o)):n(i,2,o)}catch(e){n(i,2,e)}},i},e}();function i(e){return e instanceof r&&1&e.s}var o=function(e){try{var t=new Response(e);return"application/pdf"===e.type?Promise.resolve(t.arrayBuffer()).then(function(e){var t=new Uint8Array(e);return Promise.resolve(u(t).promise).then(function(e){return Promise.resolve(function(e){try{var t,o=null,u=1,a=function(e,t,o){for(var u;;){var h=e();if(i(h)&&(h=h.v),!h)return a;if(h.then){u=0;break}var a=o();if(a&&a.then){if(!i(a)){u=1;break}a=a.s}if(t){var s=t();if(s&&s.then&&!i(s)){u=2;break}}}var c=new r,f=n.bind(null,c,2);return(0===u?h.then(l):1===u?a.then(v):s.then(d)).then(void 0,f),c;function v(r){a=r;do{if(t&&(s=t())&&s.then&&!i(s))return void s.then(d).then(void 0,f);if(!(h=e())||i(h)&&!h.v)return void n(c,1,a);if(h.then)return void h.then(l).then(void 0,f);i(a=o())&&(a=a.v)}while(!a||!a.then);a.then(v).then(void 0,f)}function l(e){e?(a=o())&&a.then?a.then(v).then(void 0,f):v(a):n(c,1,a)}function d(){(h=e())?h.then?h.then(l).then(void 0,f):l(h):n(c,1,a)}}(function(){return!t&&u<=e.numPages},function(){return u++},function(){return Promise.resolve(e.getPage(u)).then(function(e){var n=document.createElement("canvas");n.height=3508,n.width=2480;var r=e.getViewport({scale:1}),i=Math.min(n.height/r.height,n.width/r.width),u=e.getViewport({scale:i}),a={canvasContext:n.getContext("2d"),viewport:u};return Promise.resolve(e.render(a).promise).then(function(){if(null!==(o=h(n)))return t=1,o})})});return Promise.resolve(a&&a.then?a.then(function(e){return t?e:null}):t?a:null)}catch(e){return Promise.reject(e)}}(e))})}):Promise.resolve(t.blob()).then(function(e){return Promise.resolve(function(e){return Promise.resolve(function(e){try{return Promise.resolve(new Promise(function(t,n){var r=new Image;r.onload=function(){return t(r)},r.onerror=n,r.src=URL.createObjectURL(e)}))}catch(e){return Promise.reject(e)}}(e)).then(function(e){for(var t=document.createElement("canvas"),n=0,r=[.5,1,.25];n<r.length;n++){var i=r[n];t.height=e.height*i,t.width=e.width*i,t.getContext("2d").drawImage(e,0,0,t.width,t.height);var o=h(t);if(o)return o}return null})}(e))})}catch(e){return Promise.reject(e)}},u=t.getDocument;function h(t){var n=t.getContext("2d").getImageData(0,0,t.width,t.height),r=e(n.data,t.width,t.height,{inversionAttempts:"attemptBoth"});return(null==r?void 0:r.data)||null}t.GlobalWorkerOptions.workerSrc="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/"+t.version+"/pdf.worker.min.js";export{o as scanFile}; //# sourceMappingURL=index.module.mjs.map