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.39 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("jsqr"),require("pdfjs-dist")):"function"==typeof define&&define.amd?define(["exports","jsqr","pdfjs-dist"],t):t((e||self).pdfImageQrScanner={},e.jsqr,e.pdfjsDist)}(this,function(e,t,n){function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=/*#__PURE__*/r(t),o=/*#__PURE__*/r(n);function u(e,t,n){if(!e.s){if(n instanceof a){if(!n.s)return void(n.o=u.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(u.bind(null,e,t),u.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var a=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,i=this.s;if(i){var o=1&i?t:n;if(o){try{u(r,1,o(this.v))}catch(e){u(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?u(r,1,t?t(i):i):n?u(r,1,n(i)):u(r,2,i)}catch(e){u(r,2,e)}},r},e}();function f(e){return e instanceof a&&1&e.s}var s=o.default.getDocument;function h(e){var t=e.getContext("2d").getImageData(0,0,e.width,e.height),n=i.default(t.data,e.width,e.height,{inversionAttempts:"attemptBoth"});return(null==n?void 0:n.data)||null}o.default.GlobalWorkerOptions.workerSrc="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/"+o.default.version+"/pdf.worker.min.js",e.scanFile=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(s(t).promise).then(function(e){return Promise.resolve(function(e){try{var t,n=null,r=1,i=function(e,t,n){for(var r;;){var i=e();if(f(i)&&(i=i.v),!i)return o;if(i.then){r=0;break}var o=n();if(o&&o.then){if(!f(o)){r=1;break}o=o.s}if(t){var s=t();if(s&&s.then&&!f(s)){r=2;break}}}var h=new a,c=u.bind(null,h,2);return(0===r?i.then(l):1===r?o.then(d):s.then(v)).then(void 0,c),h;function d(r){o=r;do{if(t&&(s=t())&&s.then&&!f(s))return void s.then(v).then(void 0,c);if(!(i=e())||f(i)&&!i.v)return void u(h,1,o);if(i.then)return void i.then(l).then(void 0,c);f(o=n())&&(o=o.v)}while(!o||!o.then);o.then(d).then(void 0,c)}function l(e){e?(o=n())&&o.then?o.then(d).then(void 0,c):d(o):u(h,1,o)}function v(){(i=e())?i.then?i.then(l).then(void 0,c):l(i):u(h,1,o)}}(function(){return!t&&r<=e.numPages},function(){return r++},function(){return Promise.resolve(e.getPage(r)).then(function(e){var r=document.createElement("canvas");r.height=3508,r.width=2480;var i=e.getViewport({scale:1}),o=Math.min(r.height/i.height,r.width/i.width),u=e.getViewport({scale:o}),a={canvasContext:r.getContext("2d"),viewport:u};return Promise.resolve(e.render(a).promise).then(function(){if(null!==(n=h(r)))return t=1,n})})});return Promise.resolve(i&&i.then?i.then(function(e){return t?e:null}):t?i: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)}}}); //# sourceMappingURL=index.umd.js.map