@idscan/idvc2
Version:
component for the capturing documents
1 lines • 12.2 kB
JavaScript
(self.webpackChunk_idscan_idvc2=self.webpackChunk_idscan_idvc2||[]).push([[596],{4550:(e,t,r)=>{r.d(t,{o:()=>l});var n=r(7885),o=r(7666);function i(e,t,r,n,o,i,a){try{var u=e[i](a),s=u.value}catch(e){return void r(e)}u.done?t(s):Promise.resolve(s).then(n,o)}function a(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function u(e){i(a,n,o,u,s,"next",e)}function s(e){i(a,n,o,u,s,"throw",e)}u(void 0)}))}}function u(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}var s,c=(s=a((function(e){var t,r,i,a,s;return u(this,(function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),r=Uint8Array.bind,[4,(0,o.xl)(e)];case 1:return t=new(r.apply(Uint8Array,[void 0,u.sent()])),i=(0,n.ec)(t),a=new Blob([i.buffer],{type:"application/javascript"}),[2,URL.createObjectURL(a)];case 2:throw s=u.sent(),console.error("Error loading and decompressing worker file:",s),s;case 3:return[2]}}))})),function(e){return s.apply(this,arguments)}),l=function(){var e=a((function(e){var t;return u(this,(function(r){switch(r.label){case 0:return[4,c(e)];case 1:return t=r.sent(),[2,new Worker(t)]}}))}));return function(t){return e.apply(this,arguments)}}()},8766:(e,t,r)=>{r.r(t),r.d(t,{default:()=>k});var n=r(4328),o=r(6399);function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function a(e,t,r,n,o,i,a){try{var u=e[i](a),s=u.value}catch(e){return void r(e)}u.done?t(s):Promise.resolve(s).then(n,o)}function u(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function u(e){a(i,n,o,u,s,"next",e)}function s(e){a(i,n,o,u,s,"throw",e)}u(void 0)}))}}function s(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function c(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i=[],a=!0,u=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){u=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(u)throw o}}return i}}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return i(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return i(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}var d=function(){function e(t,r,n){var o=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),c(this,"module",void 0),c(this,"handle",null),c(this,"bw",0),c(this,"bh",0),c(this,"src",null),c(this,"out",null),c(this,"isAllocate",!1),c(this,"worker",void 0),c(this,"isProcessing",!1),c(this,"isInitialized",!1),c(this,"successCount",0),c(this,"pdfCapturedCount",0),c(this,"src2",null),c(this,"locations",null),c(this,"pdfCount",0),c(this,"geometry",void 0),c(this,"minPDFframes",1),c(this,"cropSizes",void 0),c(this,"canvasSizes",void 0),c(this,"privateErrorId",0),this.worker=t,this.worker.onmessage=function(e){var t=e.data,r=t.name,n=t.data;"initialization"===r&&(o.isInitialized=n)},this.worker.postMessage({fn:"init",key:r,isNeedToLoadPDFWIthPreprocess:n})}var t,r,n;return t=e,(r=[{key:"errorId",get:function(){return this.privateErrorId},set:function(e){this.privateErrorId=[o.l.Detected,o.l.Decoded].includes(e)?0:e}},{key:"errorVal",get:function(){var e;return this.errorId===o.l.LicenseKeyHasExpired&&(e=0),this.errorId===o.l.InvalidLicenseKey&&(e=1),e}},{key:"init",value:function(e,t,r,n){this.geometry=e,this.minPDFframes=t,this.cropSizes=r,this.canvasSizes=n}},{key:"licenseError",value:function(){return{error:!0,errorType:"licenceKeyError",errorVal:this.errorVal}}},{key:"create",value:function(){}},{key:"setSizes",value:function(e,t){this.bw=e,this.bh=t,this.worker.postMessage({fn:"setSizes",bw:e,bh:t})}},{key:"allocate",value:function(){this.worker.postMessage({fn:"allocate"})}},{key:"calculateCords",value:function(e){var t=this,r=[];if(e){var n=[];Object.entries(e).forEach((function(e){var r=l(e,2),o=r[0],i=r[1],a=Math.trunc(i),u=o[0],s=+o[1]-1;n[s]||(n[s]={x:0,y:0}),"x"===u?n[s].x=t.canvasSizes.width*a/t.bw:n[s].y=t.canvasSizes.height*a/t.bh}));var o=[n[3].x-n[0].x,n[3].y-n[0].y],i=[n[1].x-n[0].x,n[1].y-n[0].y],a=[n[2].x-n[1].x,n[2].y-n[1].y],u=[n[3].x-n[2].x,n[3].y-n[2].y],s=this.geometry.angleBetweenTwoVectors(o,i),c=this.geometry.angleBetweenTwoVectors(a,u);s<=100&&s>=80&&c<=100&&c>=80&&(r=n)}return r}},{key:"processPDF",value:function(e){var t=this;return u((function(){var r,n;return f(this,(function(i){switch(i.label){case 0:return t.isProcessing?[2,{}]:(r={status:!1,predict:!1,touch:!1,image:null,type:"pdf",error:null,coords:[],trackString:"",pdfSuccessCount:0,pdfCount:0,isSuccessProcess:!1,pdfCapturedCount:0},t.isInitialized?(t.isProcessing=!0,[4,t.readPDF(e)]):[2,r]);case 1:return(n=i.sent()).error?(t.isProcessing=!1,r.error=n,[2,r]):(n&&"status"in n&&(n.status.value===o.l.Detected&&(t.pdfCapturedCount+=1),n.status.value===o.l.Detected||n.status.value===o.l.Decoded?(r.coords=t.calculateCords(n.location),r.isSuccessProcess=!0):(t.successCount+=1,t.calculateCords(null)),n.status.value===o.l.Decoded?(t.pdfCount+=1,t.pdfCount>=t.minPDFframes&&(t.successCount=0,t.pdfCapturedCount=0,t.pdfCount=0,r.trackString=n.trackString||n.data||"",r.status=!0,r.image=e,r.pdfCapturedCount=0)):t.pdfCount=0),r.pdfSuccessCount=t.successCount,r.pdfCount=t.pdfCount,r.pdfCapturedCount=t.pdfCapturedCount,t.isProcessing=!1,[2,r])}}))}))()}},{key:"decodeSubmitString",value:function(e){var t=e.data,r=e.resultParams,n=r.columns,o=r.rows,i=r.ecl,a=Object.fromEntries(Object.entries(e.location).map((function(e){var t=l(e,2),r=t[0],n=t[1];return[r,Number(n.toFixed(6))]}))),u="columns:".concat(n,",rows:").concat(o,",ecl:").concat(i,",").concat(Object.entries(a).map((function(e){var t=l(e,2),r=t[0],n=t[1];return"".concat(r,":").concat(n)})).join(","));return"".concat(t,".").concat(btoa(u))}},{key:"processPDFWithPreProcess",value:function(e){var t=this;return new Promise((function(r){t.worker.onmessage=function(e){var n=e.data,o=n.name,i=n.data;if("result"===o){var a;t.errorId=null==i||null===(a=i.status)||void 0===a?void 0:a.value;var u=t.errorId?t.licenseError():null;i.data&&(i.data=t.decodeSubmitString(i)),r(u||i)}else r(i)},t.worker.postMessage({fn:"pdfWithPreProcess",iData:e})}))}},{key:"readPDF",value:function(e){var t=this;return u((function(){return f(this,(function(r){return[2,new Promise((function(r){t.worker.onmessage=function(e){var n=e.data,o=n.name,i=n.data,a=n.bw,u=n.bh;if("ready"===o)t.worker.postMessage({fn:"process"});else if("result"===o){var s;t.errorId=null==i||null===(s=i.status)||void 0===s?void 0:s.value;var c=(t.errorId?t.licenseError():null)||i;t.bw=a,t.bh=u,r(c)}else r(i)},t.worker.postMessage({fn:"prepare",iData:e})}))]}))}))()}}])&&s(t.prototype,r),n&&s(t,n),e}();var p,h,y=r(7286),v=r(4550);function b(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function w(e,t,r,n,o,i,a){try{var u=e[i](a),s=u.value}catch(e){return void r(e)}u.done?t(s):Promise.resolve(s).then(n,o)}function m(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i=[],a=!0,u=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){u=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(u)throw o}}return i}}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return b(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return b(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}const k=(p=function(e){var t,r,o,i;return g(this,(function(a){switch(a.label){case 0:return t=e.pdf417key,r=!!Object.entries(n.Z.config.documentTypes).find((function(e){var t=m(e,2);return t[0],t[1].find((function(e){return("pdf"===e.type||"back"===e.type)&&e.mode.uploader}))})),[4,(0,v.o)("".concat(n.Z.networkUrl,"pdfWorker.js.gzip"))];case 1:return o=a.sent(),i=new d(o,t,r),y.Z.setModule("module","pdf",i),[2]}}))},h=function(){var e=this,t=arguments;return new Promise((function(r,n){var o=p.apply(e,t);function i(e){w(o,r,n,i,a,"next",e)}function a(e){w(o,r,n,i,a,"throw",e)}i(void 0)}))},function(e){return h.apply(this,arguments)})}}]);