accuraidscanplugin 1.0.29 → 1.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see accuramain.js.LICENSE.txt */
2
- var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function r(t,e,n){return(e=d(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return a(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,s=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return s=t.done,t},e:function(t){c=!0,o=t},f:function(){try{s||null==n.return||n.return()}finally{if(c)throw o}}}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function o(){var t,e,n="function"==typeof Symbol?Symbol:{},r=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function a(n,r,i,a){var o=r&&r.prototype instanceof l?r:l,u=Object.create(o.prototype);return s(u,"_invoke",function(n,r,i){var a,o,s,l=0,u=i||[],d=!1,h={p:0,n:0,v:t,a:m,f:m.bind(t,4),d:function(e,n){return a=e,o=0,s=t,h.n=n,c}};function m(n,r){for(o=n,s=r,e=0;!d&&l&&!i&&e<u.length;e++){var i,a=u[e],m=h.p,f=a[2];n>3?(i=f===r)&&(s=a[(o=a[4])?5:(o=3,3)],a[4]=a[5]=t):a[0]<=m&&((i=n<2&&m<a[1])?(o=0,h.v=r,h.n=a[1]):m<f&&(i=n<3||a[0]>r||r>f)&&(a[4]=n,a[5]=r,h.n=f,o=0))}if(i||n>1)return c;throw d=!0,r}return function(i,u,f){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&m(u,f),o=u,s=f;(e=o<2?t:s)||!d;){a||(o?o<3?(o>1&&(h.n=-1),m(o,s)):h.n=s:h.v=s);try{if(l=2,a){if(o||(i="next"),e=a[i]){if(!(e=e.call(a,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,o<2&&(o=0)}else 1===o&&(e=a.return)&&e.call(a),o<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),o=1);a=t}else if((e=(d=h.n<0)?s:n.call(r,h))!==c)break}catch(e){a=t,o=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,a),!0),u}var c={};function l(){}function u(){}function d(){}e=Object.getPrototypeOf;var h=[][r]?e(e([][r]())):(s(e={},r,(function(){return this})),e),m=d.prototype=l.prototype=Object.create(h);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,s(t,i,"GeneratorFunction")),t.prototype=Object.create(m),t}return u.prototype=d,s(m,"constructor",d),s(d,"constructor",u),u.displayName="GeneratorFunction",s(d,i,"GeneratorFunction"),s(m),s(m,i,"Generator"),s(m,r,(function(){return this})),s(m,"toString",(function(){return"[object Generator]"})),(o=function(){return{w:a,m:f}})()}function s(t,e,n,r){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}s=function(t,e,n,r){function a(e,n){s(t,e,(function(t){return this._invoke(e,n,t)}))}e?i?i(t,e,{value:n,enumerable:!r,configurable:!r,writable:!r}):t[e]=n:(a("next",0),a("throw",1),a("return",2))},s(t,e,n,r)}function c(t,e,n,r,i,a,o){try{var s=t[a](o),c=s.value}catch(t){return void n(t)}s.done?e(c):Promise.resolve(c).then(r,i)}function l(t){return function(){var e=this,n=arguments;return new Promise((function(r,i){var a=t.apply(e,n);function o(t){c(a,r,i,o,s,"next",t)}function s(t){c(a,r,i,o,s,"throw",t)}o(void 0)}))}}function u(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,d(r.key),r)}}function d(t){var e=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var i=r.call(t,e||"default");if("object"!=n(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==n(e)?e:e+""}t.d(e,{A:()=>h});var h=function(){return t=function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.countryCode,i=n.cardCode,a=n.topTextSize,o=n.topTextColor,s=n.topTextWeight,c=n.bottomTextSize,l=n.bottomTextColor,u=n.bottomTextWeight,d=n.bottomTextText,h=n.containerId,m=n.basePath,f=n.jsJsonUrl,p=n.opencvUrl,v=n.piexifUrl,y=n.faUrl;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.callback=e,this.country_code=r,this.card_code=i,this.containerId=h,this.basePath=m||"https://unpkg.com/accuraidscanplugin/dist/",this.jsJsonUrl=f||"".concat(this.basePath,"accura/js.json"),this.opencvUrl=p||"".concat(this.basePath,"accuraface1.js"),this.piexifUrl=v||"".concat(this.basePath,"libs/piexif.js"),this.faUrl=y||"".concat(this.basePath,"fontawesome-free/css/all.min.css"),this.audioUrl="".concat(this.basePath,"audio/ding.mp3"),this.countriesData=[],this.frontStream=null,this.backStream=null,this.uaParserLoaded="undefined"!=typeof UAParser,this.frontCapture=null,this.backCapture=null,this.result={front:null,back:null},this.topInstructSize=a,this.topInstructColor=o,this.topInstructWeight=s,this.InstructSize=c,this.InstructWeight=u,this.InstructColor=l,this.InstructText=d,this.audioUnlocked=!1,this.ding=null,this.selectedCard=null,this.cameraContainer=null,this.styleTag=null,this.unlockAudioHandler=null},e=[{key:"start",value:(h=l(o().m((function t(){var e,n;return o().w((function(t){for(;;)switch(t.p=t.n){case 0:if("undefined"!=typeof window){t.n=1;break}return t.a(2);case 1:return this.loadStyles(),t.n=2,this.loadDependencies();case 2:return this.initAudio(),t.p=3,t.n=4,fetch(this.jsJsonUrl);case 4:if((e=t.v).ok){t.n=5;break}throw new Error("Failed to load data from "+this.jsJsonUrl);case 5:return t.n=6,e.json();case 6:return this.countriesData=t.v,t.n=7,this.setSelectedCard();case 7:this.startCamera(),t.n=9;break;case 8:t.p=8,n=t.v,console.error("Error initializing IDCardPlugin:",n);case 9:return t.a(2)}}),t,this,[[3,8]])}))),function(){return h.apply(this,arguments)})},{key:"initAudio",value:function(){var t=this;this.ding=new Audio(this.audioUrl),this.ding.preload="auto",this.ding.muted=!0,this.unlockAudioHandler=function(){t.audioUnlocked||(t.ding.play().then((function(){t.ding.pause(),t.ding.currentTime=0,t.ding.muted=!1,t.audioUnlocked=!0})).catch((function(){})),document.removeEventListener("click",t.unlockAudioHandler))},document.addEventListener("click",this.unlockAudioHandler,{once:!0})}},{key:"loadDependencies",value:(d=l(o().m((function t(){return o().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.loadScript(this.piexifUrl);case 1:return t.a(2)}}),t,this)}))),function(){return d.apply(this,arguments)})},{key:"loadScript",value:(c=l(o().m((function t(e){return o().w((function(t){for(;;)if(0===t.n)return t.a(2,new Promise((function(t,n){if(document.querySelector('script[src="'.concat(e,'"]')))t();else{var r=document.createElement("script");r.src=e,r.async=!0,r.onload=t,r.onerror=function(){return n(new Error("Failed to load script: ".concat(e)))},document.head.appendChild(r)}})))}),t)}))),function(t){return c.apply(this,arguments)})},{key:"setSelectedCard",value:(s=l(o().m((function t(){var e,n,r,a,s,c,l,u=this;return o().w((function(t){for(;;)switch(t.p=t.n){case 0:if(e=this.countriesData.find((function(t){return t.country_code===u.country_code}))){t.n=1;break}return console.error("Country with code ".concat(this.country_code," not found")),t.a(2);case 1:n=null,r=null,a=i(e.cards||[]),t.p=2,a.s();case 3:if((s=a.n()).done){t.n=5;break}if(!(c=s.value).allcard||!Array.isArray(c.allcard)){t.n=4;break}if(!(n=c.allcard.find((function(t){return t.card_code===u.card_code})))){t.n=4;break}return r=2===c.allcard.length?c.allcard.find((function(t){return t.card_code!==u.card_code})):null,t.a(3,5);case 4:t.n=3;break;case 5:t.n=7;break;case 6:t.p=6,l=t.v,a.e(l);case 7:return t.p=7,a.f(),t.f(7);case 8:if(n){t.n=9;break}return console.error("Card with code ".concat(this.card_code," not found for country ").concat(this.country_code)),t.a(2);case 9:this.selectedCard={country_code:e.country_code,card_code:n.card_code,country:e,frontCard:n,backCard:r,requiresBack:!!r};case 10:return t.a(2)}}),t,this,[[2,6,7,8]])}))),function(){return s.apply(this,arguments)})},{key:"loadStyles",value:function(){if(!document.querySelector('link[href="'.concat(this.faUrl,'"]'))){var t=document.createElement("link");t.rel="stylesheet",t.href=this.faUrl,document.head.appendChild(t)}this.styleTag||(this.styleTag=document.createElement("style"),this.styleTag.textContent="\n @keyframes spin { \n from { transform: rotate(0deg); } \n to { transform: rotate(360deg); } \n }\n @keyframes flipAnimation { \n from { transform: translate(-50%, -50%) rotateY(0deg); } \n to { transform: translate(-50%, -50%) rotateY(360deg); } \n }\n ",document.head.appendChild(this.styleTag))}},{key:"startCamera",value:function(){var t=this;this.selectedCard?(this.createCameraUI(),"undefined"!=typeof cv&&cv.getBuildInformation?this.startCameraProcessing():this.loadScript(this.opencvUrl).then((function(){"undefined"!=typeof cv&&(cv.getBuildInformation?t.startCameraProcessing():cv.onRuntimeInitialized=function(){return t.startCameraProcessing()})}))):console.error("No card selected. Cannot start camera.")}},{key:"createCameraUI",value:function(){this.cameraContainer=document.createElement("div"),this.cameraContainer.className="camera-container",this.cameraContainer.style.position="absolute",this.cameraContainer.style.top="0",this.cameraContainer.style.left="0",this.cameraContainer.style.width="100%",this.cameraContainer.style.height="100%",this.cameraContainer.style.display="flex",this.cameraContainer.style.justifyContent="center",this.cameraContainer.style.alignItems="center",this.cameraContainer.style.background="rgba(0,0,0,0.8)",this.cameraContainer.style.zIndex="2000",this.cameraContainer.style.overflow="hidden";var t=this.containerId?document.getElementById(this.containerId):document.body;t?(this.containerId&&(t.style.position="relative"),t.appendChild(this.cameraContainer)):document.body.appendChild(this.cameraContainer),this.video=document.createElement("video"),this.video.id="video",this.video.autoplay=!0,this.video.playsInline=!0,this.video.style.width="auto",this.video.style.height="100%",this.video.style.objectFit="cover",this.video.style.position="absolute",this.video.style.top="0",this.video.style.left="50%",this.video.style.transform="translateX(-50%)",this.cameraContainer.appendChild(this.video),this.canvas=document.createElement("canvas"),this.canvas.id="canvas",this.canvas.style.display="none",this.canvas.style.transform="scaleX(-1)",this.cameraContainer.appendChild(this.canvas),this.scanFrame=document.createElement("div"),this.scanFrame.className="scan-frame",this.scanFrame.style.position="absolute",this.scanFrame.style.top="50%",this.scanFrame.style.left="50%",this.scanFrame.style.transform="translate(-50%, -50%)",this.scanFrame.style.border="2px solid red",this.scanFrame.style.boxSizing="border-box",this.scanFrame.style.boxShadow="0 0 0 9999px rgba(0, 0, 0, 0.6)",window.innerWidth<=767?(this.scanFrame.style.width="90vw",this.scanFrame.style.height="50vw",this.scanFrame.style.maxWidth="350px",this.scanFrame.style.maxHeight="200px"):window.innerWidth<=1024?(this.scanFrame.style.width="60vw",this.scanFrame.style.height="40vw",this.scanFrame.style.maxWidth="600px",this.scanFrame.style.maxHeight="400px"):(this.scanFrame.style.width="50vw",this.scanFrame.style.height="30vw",this.scanFrame.style.maxWidth="800px",this.scanFrame.style.maxHeight="500px"),this.cameraContainer.appendChild(this.scanFrame),this.instructionText=document.createElement("div"),this.instructionText.className="instruction-text",this.instructionText.id="instructionText",this.instructionText.textContent=this.InstructText||"Keep Document in Frame",this.instructionText.style.position="absolute",this.instructionText.style.left="50%",this.instructionText.style.transform="translateX(-50%)",this.instructionText.style.padding="8px 12px",this.instructionText.style.borderRadius="6px",this.instructionText.style.pointerEvents="none",this.instructionText.style.textAlign="center",this.instructionText.style.fontSize=this.InstructSize||"0.8rem",this.instructionText.style.fontWeight=this.InstructWeight||"450",this.instructionText.style.width="100%",this.instructionText.style.maxWidth="100%",this.instructionText.style.zIndex="8000",this.instructionText.style.color=this.InstructColor||"#fff",this.instructionText.style.bottom="10%",this.cameraContainer.appendChild(this.instructionText),this.topInstructionText=document.createElement("div"),this.topInstructionText.className="top-instruction-text",this.topInstructionText.id="topInstructionText",this.topInstructionText.style.position="absolute",this.topInstructionText.style.left="50%",this.topInstructionText.style.transform="translateX(-50%)",this.topInstructionText.style.padding="8px 12px",this.topInstructionText.style.borderRadius="6px",this.topInstructionText.style.pointerEvents="none",this.topInstructionText.style.textAlign="center",this.topInstructionText.style.fontSize=this.topInstructSize||"0.8rem",this.topInstructionText.style.fontWeight=this.topInstructWeight||"450",this.topInstructionText.style.width="100%",this.topInstructionText.style.maxWidth="100%",this.topInstructionText.style.zIndex="8000",this.topInstructionText.style.color=this.topInstructColor||"#fff",this.topInstructionText.style.top="10%",this.cameraContainer.appendChild(this.topInstructionText)}},{key:"startCameraProcessing",value:function(){var t=this,e=this.selectedCard,n=e.country,r=(e.REWARDS,e.frontCard),i=e.backCard,a=e.requiresBack,o=r.card_code,s=.12,c=.12;"CLMIDN"===o&&(s=.09,c=.1),"CLMID"===o&&(s=.1,c=.1),"COLPAF"===o&&(s=.09,c=.1),"CLMDL"===o&&(s=.11,c=.1),"COLCIF"===o&&(s=.08,c=.09),"UGNIDF"===o&&(s=.1,c=.12);var l="CLMIDN"===o?"Scan Front Side of ".concat(n.country_name," National ID Card New"):"CLMID"===o?"Scan Front Side of ".concat(n.country_name," National ID Card"):"COLPAF"===o?"Scan Front Side of ".concat(n.country_name,"'s Passport"):"CLMDL"===o?"Scan Front Side of ".concat(n.country_name,"'s Driving License"):"COLCIF"===o?"Scan Front Side of ".concat(n.country_name,"'s Citizen Card"):"UGNIDF"===o?"Scan Front Side of ".concat(n.country_name,"'s National ID Card"):"Scanning front side...";this.topInstructionText.textContent=l,this.instructionText.textContent="Keep Document in Frame";var u=new Image;u.src="data:image/jpeg;base64,"+r.card_img;var d=!1,h=0,m=0,f=!1;u.onload=function(){var e=cv.imread(u),o=Math.round(.15*e.rows),l=e.roi(new cv.Rect(0,0,e.cols,o));navigator.mediaDevices.getUserMedia({video:{width:{ideal:1920},height:{ideal:1080},facingMode:{ideal:"environment"},frameRate:{ideal:60,max:60}}}).then((function(o){t.frontStream=o,t.video.srcObject=t.frontStream,t.video.addEventListener("loadedmetadata",(function(){t.canvas.width=t.video.videoWidth,t.canvas.height=t.video.videoHeight}));var u=function(o){if(t.frontStream&&t.frontStream.active&&!d){var p=t.video.getBoundingClientRect(),v=t.scanFrame.getBoundingClientRect();t.instructionText.style.top=v.bottom+10+"px",t.topInstructionText.style.top=v.top-35+"px";var y=t.video.videoWidth/p.width,g=t.video.videoHeight/p.height,C=(v.left-p.left)*y,x=(v.top-p.top)*g,b=v.width*y,w=v.height*g;if(b>0&&w>0){var T=document.createElement("canvas");T.width=b,T.height=w,T.getContext("2d").drawImage(t.video,C,x,b,w,0,0,b,w);var S=cv.imread(T),I=t.multiScaleTemplateMatch(S,e);if(I.maxVal>=s){var k=t.multiScaleTemplateMatch(S,l);k.maxVal>=c&&3==++h&&(d=!0,t.frontStream.getTracks().forEach((function(t){return t.stop()})),t.processCapturedFrame(T,n,r,I,k,"front").then((function(){if(a&&i){t.audioUnlocked&&(t.ding.currentTime=0,t.ding.play().catch((function(){})));var e=document.createElement("div");e.id="flipAnimation",e.innerHTML='<i class="fas fa-id-card"></i>',e.style.animation="flipAnimation 1s linear forwards",e.style.position="absolute",e.style.top="50%",e.style.left="50%",e.style.width="50px",e.style.height="50px",e.style.transform="translate(-50%, -50%)",e.style.fontSize="48px",e.style.color="#e53935",t.cameraContainer.appendChild(e),setTimeout((function(){e.parentNode===t.cameraContainer&&t.cameraContainer.removeChild(e),t.startBackCameraProcessing(n,i)}),1e3)}})))}++m%20!=0||f||(f=!0,t.instructionText.textContent="Keep Document Near to Camera",setTimeout((function(){d||(t.instructionText.textContent="Keep Document in Frame"),f=!1}),1200)),S.delete()}requestAnimationFrame(u)}else requestAnimationFrame(u)};requestAnimationFrame(u)})).catch((function(t){console.error("Front camera error:",t)}))}}},{key:"startBackCameraProcessing",value:function(t,e){var n=this,r=.1,i=.12;"UGNIDB"===e.card_code&&(r=.12,i=.12);var a="COLIDB"===e.card_code?"Scan Back Side of ".concat(t.country_name," National ID Card New"):"COLMIDB"===e.card_code?"Scan Back Side of ".concat(t.country_name," National ID Card"):"COLCIB"===e.card_code?"Scan Back Side of ".concat(t.country_name," Citizen Card"):"UGNIDB"===e.card_code?"Scan Back Side of ".concat(t.country_name,"'s National ID Card"):"Scanning back side...";this.topInstructionText.textContent=a,this.instructionText.textContent="Keep Document in Frame";var o=new Image;o.src="data:image/jpeg;base64,"+e.card_img;var s=!1,c=0,l=0,u=!1;o.onload=function(){var a=cv.imread(o),d=Math.round(.35*a.rows),h=a.roi(new cv.Rect(0,0,a.cols,d));navigator.mediaDevices.getUserMedia({video:{width:{ideal:1920},height:{ideal:1080},facingMode:{ideal:"environment"},frameRate:{ideal:60,max:60}}}).then((function(o){n.backStream=o,n.video.srcObject=n.backStream,n.video.addEventListener("loadedmetadata",(function(){n.canvas.width=n.video.videoWidth,n.canvas.height=n.video.videoHeight}));var d=function(o){if(n.backStream&&n.backStream.active&&!s){var m=n.video.getBoundingClientRect(),f=n.scanFrame.getBoundingClientRect();n.instructionText.style.top=f.bottom+10+"px",n.topInstructionText.style.top=f.top-35+"px";var p=n.video.videoWidth/m.width,v=n.video.videoHeight/m.height,y=(f.left-m.left)*p,g=(f.top-m.top)*v,C=f.width*p,x=f.height*v;if(C>0&&x>0){var b=document.createElement("canvas");b.width=C,b.height=x,b.getContext("2d").drawImage(n.video,y,g,C,x,0,0,C,x);var w=cv.imread(b),T=n.multiScaleTemplateMatch(w,a);if(T.maxVal>=r){var S=n.multiScaleTemplateMatch(w,h);S.maxVal>=i&&3==++c&&(s=!0,n.backStream.getTracks().forEach((function(t){return t.stop()})),n.processCapturedFrame(b,t,e,T,S,"back"))}++l%20!=0||u||(u=!0,n.instructionText.textContent="Keep Document Near to Camera",setTimeout((function(){s||(n.instructionText.textContent="Keep Document in Frame"),u=!1}),1200)),w.delete()}requestAnimationFrame(d)}else requestAnimationFrame(d)};requestAnimationFrame(d)})).catch((function(t){console.error("Back camera error:",t)}))}}},{key:"multiScaleTemplateMatch",value:function(t,e){var n=null,r=1,i=0,a=new cv.Mat,o=new cv.Mat;cv.resize(e,o,new cv.Size(e.cols,e.rows));var s=new cv.Mat;cv.cvtColor(o,s,cv.COLOR_RGBA2GRAY),cv.Canny(s,s,60,255);for(var c=1;c<=2;c+=.1){var l=new cv.Mat,u=Math.round(t.cols/c),d=Math.round(t.rows/c);cv.resize(t,l,new cv.Size(u,d));var h=l.cols<s.cols||l.rows<s.rows?new cv.Mat:s;if(l.cols<s.cols||l.rows<s.rows){var m=Math.min(l.cols/s.cols,l.rows/s.rows);cv.resize(s,h,new cv.Size(Math.round(s.cols*m),Math.round(s.rows*m)))}var f=new cv.Mat;cv.cvtColor(l,f,cv.COLOR_RGBA2GRAY),cv.Canny(f,f,60,255);try{cv.matchTemplate(f,h,a,cv.TM_CCOEFF_NORMED)}catch(t){console.error("Error in matchTemplate at scale",c,t)}var p=cv.minMaxLoc(a);p.maxVal>i&&(i=p.maxVal,n=p,r=c),f.delete(),(l.cols<s.cols||l.rows<s.rows)&&h.delete(),l.delete()}return o.delete(),s.delete(),a.delete(),{bestMatch:n,bestScale:r,maxVal:i}}},{key:"processCapturedFrame",value:(a=l(o().m((function t(e,n,i,a,s,c){var l,u,d,h,m,f=this;return o().w((function(t){for(;;)switch(t.p=t.n){case 0:return this.showLoadingAnimation(),this.instructionText.textContent="Processing...",t.p=1,t.n=2,new Promise((function(t){return e.toBlob(t,"image/jpeg",.9)}));case 2:return l=t.v,u={"0th":r(r({},piexif.ImageIFD.Make,"AutoID"),piexif.ImageIFD.Model,"IDDetectionCamera")},d=piexif.dump(u),h=piexif.insert(d,e.toDataURL("image/jpeg",.92)),t.n=3,new Promise((function(t){var e=new FileReader;e.onload=function(){return t(e.result)},e.readAsDataURL(l)}));case 3:t.v,"front"===c?this.result.front=h:"back"===c&&(this.result.back=h),!this.selectedCard.requiresBack||this.result.back?(this.callback(this.result),this.hideLoadingAnimation(),setTimeout((function(){f.stopAllStreams(),f.cameraContainer.remove()}),1e3)):this.hideLoadingAnimation(),t.n=5;break;case 4:t.p=4,m=t.v,console.error("Error processing captured frame:",m),this.hideLoadingAnimation(),this.instructionText.textContent="Error processing image. Please try again.";case 5:return t.a(2)}}),t,this,[[1,4]])}))),function(t,e,n,r,i,o){return a.apply(this,arguments)})},{key:"showLoadingAnimation",value:function(){var t=document.createElement("div");t.className="loading-spinner",t.innerHTML='<i class="fas fa-spinner"></i>',t.style.position="absolute",t.style.top="50%",t.style.left="50%",t.style.transform="translate(-50%, -50%)",t.style.zIndex="3500";var e=t.querySelector("i");e.style.fontSize="48px",e.style.animation="spin 1s linear infinite",e.style.color="#e53935",this.cameraContainer.appendChild(t),this.loadingSpinner=t}},{key:"hideLoadingAnimation",value:function(){this.loadingSpinner&&this.loadingSpinner.parentNode===this.cameraContainer&&this.cameraContainer.removeChild(this.loadingSpinner)}},{key:"destroy",value:function(){this.stopAllStreams(),this.cameraContainer&&this.cameraContainer.parentNode&&this.cameraContainer.parentNode.removeChild(this.cameraContainer),this.styleTag&&this.styleTag.parentNode&&this.styleTag.parentNode.removeChild(this.styleTag),this.unlockAudioHandler&&document.removeEventListener("click",this.unlockAudioHandler)}},{key:"stopAllStreams",value:function(){this.frontStream&&(this.frontStream.getTracks().forEach((function(t){return t.stop()})),this.frontStream=null),this.backStream&&(this.backStream.getTracks().forEach((function(t){return t.stop()})),this.backStream=null)}}],e&&u(t.prototype,e),n&&u(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,a,s,c,d,h}();const m=e.A;export{m as default};
2
+ var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function r(t,e,n){return(e=d(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return a(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,s=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return s=t.done,t},e:function(t){c=!0,o=t},f:function(){try{s||null==n.return||n.return()}finally{if(c)throw o}}}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function o(){var t,e,n="function"==typeof Symbol?Symbol:{},r=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function a(n,r,i,a){var o=r&&r.prototype instanceof l?r:l,u=Object.create(o.prototype);return s(u,"_invoke",function(n,r,i){var a,o,s,l=0,u=i||[],d=!1,h={p:0,n:0,v:t,a:m,f:m.bind(t,4),d:function(e,n){return a=e,o=0,s=t,h.n=n,c}};function m(n,r){for(o=n,s=r,e=0;!d&&l&&!i&&e<u.length;e++){var i,a=u[e],m=h.p,f=a[2];n>3?(i=f===r)&&(s=a[(o=a[4])?5:(o=3,3)],a[4]=a[5]=t):a[0]<=m&&((i=n<2&&m<a[1])?(o=0,h.v=r,h.n=a[1]):m<f&&(i=n<3||a[0]>r||r>f)&&(a[4]=n,a[5]=r,h.n=f,o=0))}if(i||n>1)return c;throw d=!0,r}return function(i,u,f){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&m(u,f),o=u,s=f;(e=o<2?t:s)||!d;){a||(o?o<3?(o>1&&(h.n=-1),m(o,s)):h.n=s:h.v=s);try{if(l=2,a){if(o||(i="next"),e=a[i]){if(!(e=e.call(a,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,o<2&&(o=0)}else 1===o&&(e=a.return)&&e.call(a),o<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),o=1);a=t}else if((e=(d=h.n<0)?s:n.call(r,h))!==c)break}catch(e){a=t,o=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,a),!0),u}var c={};function l(){}function u(){}function d(){}e=Object.getPrototypeOf;var h=[][r]?e(e([][r]())):(s(e={},r,(function(){return this})),e),m=d.prototype=l.prototype=Object.create(h);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,s(t,i,"GeneratorFunction")),t.prototype=Object.create(m),t}return u.prototype=d,s(m,"constructor",d),s(d,"constructor",u),u.displayName="GeneratorFunction",s(d,i,"GeneratorFunction"),s(m),s(m,i,"Generator"),s(m,r,(function(){return this})),s(m,"toString",(function(){return"[object Generator]"})),(o=function(){return{w:a,m:f}})()}function s(t,e,n,r){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}s=function(t,e,n,r){function a(e,n){s(t,e,(function(t){return this._invoke(e,n,t)}))}e?i?i(t,e,{value:n,enumerable:!r,configurable:!r,writable:!r}):t[e]=n:(a("next",0),a("throw",1),a("return",2))},s(t,e,n,r)}function c(t,e,n,r,i,a,o){try{var s=t[a](o),c=s.value}catch(t){return void n(t)}s.done?e(c):Promise.resolve(c).then(r,i)}function l(t){return function(){var e=this,n=arguments;return new Promise((function(r,i){var a=t.apply(e,n);function o(t){c(a,r,i,o,s,"next",t)}function s(t){c(a,r,i,o,s,"throw",t)}o(void 0)}))}}function u(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,d(r.key),r)}}function d(t){var e=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var i=r.call(t,e||"default");if("object"!=n(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==n(e)?e:e+""}t.d(e,{A:()=>h});var h=function(){return t=function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.countryCode,i=n.cardCode,a=n.topTextSize,o=n.topTextColor,s=n.topTextWeight,c=n.bottomTextSize,l=n.bottomTextColor,u=n.bottomTextWeight,d=n.bottomTextText,h=n.containerId,m=n.basePath,f=n.jsJsonUrl,p=n.opencvUrl,v=n.piexifUrl,y=n.faUrl;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.callback=e,this.country_code=r,this.card_code=i,this.containerId=h,this.basePath=m||"https://unpkg.com/accuraidscanplugin/dist/",this.jsJsonUrl=f||"".concat(this.basePath,"accura/js.json"),this.opencvUrl=p||"".concat(this.basePath,"accuraface1.js"),this.piexifUrl=v||"".concat(this.basePath,"libs/piexif.js"),this.faUrl=y||"".concat(this.basePath,"fontawesome-free/css/all.min.css"),this.audioUrl="".concat(this.basePath,"audio/ding.mp3"),this.countriesData=[],this.frontStream=null,this.backStream=null,this.uaParserLoaded="undefined"!=typeof UAParser,this.frontCapture=null,this.backCapture=null,this.result={front:null,back:null},this.topInstructSize=a,this.topInstructColor=o,this.topInstructWeight=s,this.InstructSize=c,this.InstructWeight=u,this.InstructColor=l,this.InstructText=d,this.audioUnlocked=!1,this.ding=null,this.selectedCard=null,this.cameraContainer=null,this.styleTag=null,this.unlockAudioHandler=null},e=[{key:"start",value:(h=l(o().m((function t(){var e,n;return o().w((function(t){for(;;)switch(t.p=t.n){case 0:if("undefined"!=typeof window){t.n=1;break}return t.a(2);case 1:return this.loadStyles(),t.n=2,this.loadDependencies();case 2:return this.initAudio(),t.p=3,t.n=4,fetch(this.jsJsonUrl);case 4:if((e=t.v).ok){t.n=5;break}throw new Error("Failed to load data from "+this.jsJsonUrl);case 5:return t.n=6,e.json();case 6:return this.countriesData=t.v,t.n=7,this.setSelectedCard();case 7:this.startCamera(),t.n=9;break;case 8:t.p=8,n=t.v,console.error("Error initializing IDCardPlugin:",n);case 9:return t.a(2)}}),t,this,[[3,8]])}))),function(){return h.apply(this,arguments)})},{key:"initAudio",value:function(){var t=this;this.ding=new Audio(this.audioUrl),this.ding.preload="auto",this.ding.muted=!0,this.unlockAudioHandler=function(){t.audioUnlocked||(t.ding.play().then((function(){t.ding.pause(),t.ding.currentTime=0,t.ding.muted=!1,t.audioUnlocked=!0})).catch((function(){})),document.removeEventListener("click",t.unlockAudioHandler))},document.addEventListener("click",this.unlockAudioHandler,{once:!0})}},{key:"loadDependencies",value:(d=l(o().m((function t(){return o().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.loadScript(this.piexifUrl);case 1:return t.a(2)}}),t,this)}))),function(){return d.apply(this,arguments)})},{key:"loadScript",value:(c=l(o().m((function t(e){return o().w((function(t){for(;;)if(0===t.n)return t.a(2,new Promise((function(t,n){if(document.querySelector('script[src="'.concat(e,'"]')))t();else{var r=document.createElement("script");r.src=e,r.async=!0,r.onload=t,r.onerror=function(){return n(new Error("Failed to load script: ".concat(e)))},document.head.appendChild(r)}})))}),t)}))),function(t){return c.apply(this,arguments)})},{key:"setSelectedCard",value:(s=l(o().m((function t(){var e,n,r,a,s,c,l,u=this;return o().w((function(t){for(;;)switch(t.p=t.n){case 0:if(e=this.countriesData.find((function(t){return t.country_code===u.country_code}))){t.n=1;break}return console.error("Country with code ".concat(this.country_code," not found")),t.a(2);case 1:n=null,r=null,a=i(e.cards||[]),t.p=2,a.s();case 3:if((s=a.n()).done){t.n=5;break}if(!(c=s.value).allcard||!Array.isArray(c.allcard)){t.n=4;break}if(!(n=c.allcard.find((function(t){return t.card_code===u.card_code})))){t.n=4;break}return r=2===c.allcard.length?c.allcard.find((function(t){return t.card_code!==u.card_code})):null,t.a(3,5);case 4:t.n=3;break;case 5:t.n=7;break;case 6:t.p=6,l=t.v,a.e(l);case 7:return t.p=7,a.f(),t.f(7);case 8:if(n){t.n=9;break}return console.error("Card with code ".concat(this.card_code," not found for country ").concat(this.country_code)),t.a(2);case 9:this.selectedCard={country_code:e.country_code,card_code:n.card_code,country:e,frontCard:n,backCard:r,requiresBack:!!r};case 10:return t.a(2)}}),t,this,[[2,6,7,8]])}))),function(){return s.apply(this,arguments)})},{key:"loadStyles",value:function(){if(!document.querySelector('link[href="'.concat(this.faUrl,'"]'))){var t=document.createElement("link");t.rel="stylesheet",t.href=this.faUrl,document.head.appendChild(t)}this.styleTag||(this.styleTag=document.createElement("style"),this.styleTag.textContent="\n @keyframes spin { \n from { transform: rotate(0deg); } \n to { transform: rotate(360deg); } \n }\n @keyframes flipAnimation { \n from { transform: translate(-50%, -50%) rotateY(0deg); } \n to { transform: translate(-50%, -50%) rotateY(360deg); } \n }\n ",document.head.appendChild(this.styleTag))}},{key:"startCamera",value:function(){var t=this;this.selectedCard?(this.createCameraUI(),"undefined"!=typeof cv&&cv.getBuildInformation?this.startCameraProcessing():this.loadScript(this.opencvUrl).then((function(){"undefined"!=typeof cv&&(cv.getBuildInformation?t.startCameraProcessing():cv.onRuntimeInitialized=function(){return t.startCameraProcessing()})}))):console.error("No card selected. Cannot start camera.")}},{key:"createCameraUI",value:function(){this.cameraContainer=document.createElement("div"),this.cameraContainer.className="camera-container",this.cameraContainer.style.position="absolute",this.cameraContainer.style.top="0",this.cameraContainer.style.left="0",this.cameraContainer.style.width="100%",this.cameraContainer.style.height="100%",this.cameraContainer.style.display="flex",this.cameraContainer.style.justifyContent="center",this.cameraContainer.style.alignItems="center",this.cameraContainer.style.background="rgba(0,0,0,0.8)",this.cameraContainer.style.zIndex="2000",this.cameraContainer.style.overflow="hidden";var t=this.containerId?document.getElementById(this.containerId):document.body;t?(this.containerId&&(t.style.position="relative"),t.appendChild(this.cameraContainer)):document.body.appendChild(this.cameraContainer),this.video=document.createElement("video"),this.video.id="video",this.video.autoplay=!0,this.video.playsInline=!0,this.video.style.width="auto",this.video.style.height="100%",this.video.style.objectFit="cover",this.video.style.position="absolute",this.video.style.top="0",this.video.style.left="50%",this.video.style.transform="translateX(-50%)",this.cameraContainer.appendChild(this.video),this.canvas=document.createElement("canvas"),this.canvas.id="canvas",this.canvas.style.display="none",this.canvas.style.transform="scaleX(-1)",this.cameraContainer.appendChild(this.canvas),this.scanFrame=document.createElement("div"),this.scanFrame.className="scan-frame",this.scanFrame.style.position="absolute",this.scanFrame.style.top="50%",this.scanFrame.style.left="50%",this.scanFrame.style.transform="translate(-50%, -50%)",this.scanFrame.style.border="2px solid red",this.scanFrame.style.boxSizing="border-box",this.scanFrame.style.boxShadow="0 0 0 9999px rgba(0, 0, 0, 0.6)",window.innerWidth<=767?(this.scanFrame.style.width="90vw",this.scanFrame.style.height="50vw",this.scanFrame.style.maxWidth="350px",this.scanFrame.style.maxHeight="200px"):window.innerWidth<=1024?(this.scanFrame.style.width="60vw",this.scanFrame.style.height="40vw",this.scanFrame.style.maxWidth="600px",this.scanFrame.style.maxHeight="400px"):(this.scanFrame.style.width="50vw",this.scanFrame.style.height="30vw",this.scanFrame.style.maxWidth="800px",this.scanFrame.style.maxHeight="500px"),this.cameraContainer.appendChild(this.scanFrame),this.instructionText=document.createElement("div"),this.instructionText.className="instruction-text",this.instructionText.id="instructionText",this.instructionText.textContent=this.InstructText||"Keep Document in Frame",this.instructionText.style.position="absolute",this.instructionText.style.left="50%",this.instructionText.style.transform="translateX(-50%)",this.instructionText.style.padding="8px 12px",this.instructionText.style.borderRadius="6px",this.instructionText.style.pointerEvents="none",this.instructionText.style.textAlign="center",this.instructionText.style.fontSize=this.InstructSize||"0.8rem",this.instructionText.style.fontWeight=this.InstructWeight||"450",this.instructionText.style.width="100%",this.instructionText.style.maxWidth="100%",this.instructionText.style.zIndex="8000",this.instructionText.style.color=this.InstructColor||"#fff",this.instructionText.style.bottom="10%",this.cameraContainer.appendChild(this.instructionText),this.topInstructionText=document.createElement("div"),this.topInstructionText.className="top-instruction-text",this.topInstructionText.id="topInstructionText",this.topInstructionText.style.position="absolute",this.topInstructionText.style.left="50%",this.topInstructionText.style.transform="translateX(-50%)",this.topInstructionText.style.padding="8px 12px",this.topInstructionText.style.borderRadius="6px",this.topInstructionText.style.pointerEvents="none",this.topInstructionText.style.textAlign="center",this.topInstructionText.style.fontSize=this.topInstructSize||"0.8rem",this.topInstructionText.style.fontWeight=this.topInstructWeight||"450",this.topInstructionText.style.width="100%",this.topInstructionText.style.maxWidth="100%",this.topInstructionText.style.zIndex="8000",this.topInstructionText.style.color=this.topInstructColor||"#fff",this.topInstructionText.style.top="10%",this.cameraContainer.appendChild(this.topInstructionText)}},{key:"startCameraProcessing",value:function(){var t=this,e=this.selectedCard,n=e.country,r=(e.REWARDS,e.frontCard),i=e.backCard,a=e.requiresBack,o=r.card_code,s=.12,c=.12;"CLMIDN"===o&&(s=.09,c=.1),"CLMID"===o&&(s=.1,c=.1),"COLPAF"===o&&(s=.09,c=.1),"CLMDL"===o&&(s=.11,c=.1),"COLCIF"===o&&(s=.08,c=.09),"UGNIDF"===o&&(s=.1,c=.12),"UGIDFN"===o&&(s=.1,c=.12);var l="CLMIDN"===o?"Scan Front Side of ".concat(n.country_name," National ID Card New"):"CLMID"===o?"Scan Front Side of ".concat(n.country_name," National ID Card"):"COLPAF"===o?"Scan Front Side of ".concat(n.country_name,"'s Passport"):"CLMDL"===o?"Scan Front Side of ".concat(n.country_name,"'s Driving License"):"COLCIF"===o?"Scan Front Side of ".concat(n.country_name,"'s Citizen Card"):"UGNIDF"===o?"Scan Front Side of ".concat(n.country_name,"'s National ID Card"):"UGIDFN"===o?"Scan Front Side of ".concat(n.country_name,"'s National ID Card New"):"Scanning front side...";this.topInstructionText.textContent=l,this.instructionText.textContent="Keep Document in Frame";var u=new Image;u.src="data:image/jpeg;base64,"+r.card_img;var d=!1,h=0,m=0,f=!1;u.onload=function(){var e=cv.imread(u),o=Math.round(.15*e.rows),l=e.roi(new cv.Rect(0,0,e.cols,o));navigator.mediaDevices.getUserMedia({video:{width:{ideal:1920},height:{ideal:1080},facingMode:{ideal:"environment"},frameRate:{ideal:60,max:60}}}).then((function(o){t.frontStream=o,t.video.srcObject=t.frontStream,t.video.addEventListener("loadedmetadata",(function(){t.canvas.width=t.video.videoWidth,t.canvas.height=t.video.videoHeight}));var u=function(o){if(t.frontStream&&t.frontStream.active&&!d){var p=t.video.getBoundingClientRect(),v=t.scanFrame.getBoundingClientRect();t.instructionText.style.top=v.bottom+10+"px",t.topInstructionText.style.top=v.top-35+"px";var y=t.video.videoWidth/p.width,g=t.video.videoHeight/p.height,C=(v.left-p.left)*y,x=(v.top-p.top)*g,b=v.width*y,w=v.height*g;if(b>0&&w>0){var T=document.createElement("canvas");T.width=b,T.height=w,T.getContext("2d").drawImage(t.video,C,x,b,w,0,0,b,w);var S=cv.imread(T),I=t.multiScaleTemplateMatch(S,e);if(I.maxVal>=s){var k=t.multiScaleTemplateMatch(S,l);k.maxVal>=c&&3==++h&&(d=!0,t.frontStream.getTracks().forEach((function(t){return t.stop()})),t.processCapturedFrame(T,n,r,I,k,"front").then((function(){if(a&&i){t.audioUnlocked&&(t.ding.currentTime=0,t.ding.play().catch((function(){})));var e=document.createElement("div");e.id="flipAnimation",e.innerHTML='<i class="fas fa-id-card"></i>',e.style.animation="flipAnimation 1s linear forwards",e.style.position="absolute",e.style.top="50%",e.style.left="50%",e.style.width="50px",e.style.height="50px",e.style.transform="translate(-50%, -50%)",e.style.fontSize="48px",e.style.color="#e53935",t.cameraContainer.appendChild(e),setTimeout((function(){e.parentNode===t.cameraContainer&&t.cameraContainer.removeChild(e),t.startBackCameraProcessing(n,i)}),1e3)}})))}++m%20!=0||f||(f=!0,t.instructionText.textContent="Keep Document Near to Camera",setTimeout((function(){d||(t.instructionText.textContent="Keep Document in Frame"),f=!1}),1200)),S.delete()}requestAnimationFrame(u)}else requestAnimationFrame(u)};requestAnimationFrame(u)})).catch((function(t){console.error("Front camera error:",t)}))}}},{key:"startBackCameraProcessing",value:function(t,e){var n=this,r=.1,i=.12;"UGNIDB"===e.card_code&&(r=.12,i=.12),"UGIDBN"===e.card_code&&(r=.06,i=.06);var a="COLIDB"===e.card_code?"Scan Back Side of ".concat(t.country_name," National ID Card New"):"COLMIDB"===e.card_code?"Scan Back Side of ".concat(t.country_name," National ID Card"):"COLCIB"===e.card_code?"Scan Back Side of ".concat(t.country_name," Citizen Card"):"UGNIDB"===e.card_code?"Scan Back Side of ".concat(t.country_name,"'s National ID Card"):"UGIDBN"===e.card_code?"Scan Back Side of ".concat(t.country_name,"'s National ID Card New"):"Scanning back side...";this.topInstructionText.textContent=a,this.instructionText.textContent="Keep Document in Frame";var o=new Image;o.src="data:image/jpeg;base64,"+e.card_img;var s=!1,c=0,l=0,u=!1;o.onload=function(){var a=cv.imread(o),d=Math.round(.35*a.rows),h=a.roi(new cv.Rect(0,0,a.cols,d));navigator.mediaDevices.getUserMedia({video:{width:{ideal:1920},height:{ideal:1080},facingMode:{ideal:"environment"},frameRate:{ideal:60,max:60}}}).then((function(o){n.backStream=o,n.video.srcObject=n.backStream,n.video.addEventListener("loadedmetadata",(function(){n.canvas.width=n.video.videoWidth,n.canvas.height=n.video.videoHeight}));var d=function(o){if(n.backStream&&n.backStream.active&&!s){var m=n.video.getBoundingClientRect(),f=n.scanFrame.getBoundingClientRect();n.instructionText.style.top=f.bottom+10+"px",n.topInstructionText.style.top=f.top-35+"px";var p=n.video.videoWidth/m.width,v=n.video.videoHeight/m.height,y=(f.left-m.left)*p,g=(f.top-m.top)*v,C=f.width*p,x=f.height*v;if(C>0&&x>0){var b=document.createElement("canvas");b.width=C,b.height=x,b.getContext("2d").drawImage(n.video,y,g,C,x,0,0,C,x);var w=cv.imread(b),T=n.multiScaleTemplateMatch(w,a);if(T.maxVal>=r){var S=n.multiScaleTemplateMatch(w,h);S.maxVal>=i&&3==++c&&(s=!0,n.backStream.getTracks().forEach((function(t){return t.stop()})),n.processCapturedFrame(b,t,e,T,S,"back"))}++l%20!=0||u||(u=!0,n.instructionText.textContent="Keep Document Near to Camera",setTimeout((function(){s||(n.instructionText.textContent="Keep Document in Frame"),u=!1}),1200)),w.delete()}requestAnimationFrame(d)}else requestAnimationFrame(d)};requestAnimationFrame(d)})).catch((function(t){console.error("Back camera error:",t)}))}}},{key:"multiScaleTemplateMatch",value:function(t,e){var n=null,r=1,i=0,a=new cv.Mat,o=new cv.Mat;cv.resize(e,o,new cv.Size(e.cols,e.rows));var s=new cv.Mat;cv.cvtColor(o,s,cv.COLOR_RGBA2GRAY),cv.Canny(s,s,60,255);for(var c=1;c<=2;c+=.1){var l=new cv.Mat,u=Math.round(t.cols/c),d=Math.round(t.rows/c);cv.resize(t,l,new cv.Size(u,d));var h=l.cols<s.cols||l.rows<s.rows?new cv.Mat:s;if(l.cols<s.cols||l.rows<s.rows){var m=Math.min(l.cols/s.cols,l.rows/s.rows);cv.resize(s,h,new cv.Size(Math.round(s.cols*m),Math.round(s.rows*m)))}var f=new cv.Mat;cv.cvtColor(l,f,cv.COLOR_RGBA2GRAY),cv.Canny(f,f,60,255);try{cv.matchTemplate(f,h,a,cv.TM_CCOEFF_NORMED)}catch(t){console.error("Error in matchTemplate at scale",c,t)}var p=cv.minMaxLoc(a);p.maxVal>i&&(i=p.maxVal,n=p,r=c),f.delete(),(l.cols<s.cols||l.rows<s.rows)&&h.delete(),l.delete()}return o.delete(),s.delete(),a.delete(),{bestMatch:n,bestScale:r,maxVal:i}}},{key:"processCapturedFrame",value:(a=l(o().m((function t(e,n,i,a,s,c){var l,u,d,h,m,f=this;return o().w((function(t){for(;;)switch(t.p=t.n){case 0:return this.showLoadingAnimation(),this.instructionText.textContent="Processing...",t.p=1,t.n=2,new Promise((function(t){return e.toBlob(t,"image/jpeg",.9)}));case 2:return l=t.v,u={"0th":r(r({},piexif.ImageIFD.Make,"AutoID"),piexif.ImageIFD.Model,"IDDetectionCamera")},d=piexif.dump(u),h=piexif.insert(d,e.toDataURL("image/jpeg",.92)),t.n=3,new Promise((function(t){var e=new FileReader;e.onload=function(){return t(e.result)},e.readAsDataURL(l)}));case 3:t.v,"front"===c?this.result.front=h:"back"===c&&(this.result.back=h),!this.selectedCard.requiresBack||this.result.back?(this.callback(this.result),this.hideLoadingAnimation(),setTimeout((function(){f.stopAllStreams(),f.cameraContainer.remove()}),1e3)):this.hideLoadingAnimation(),t.n=5;break;case 4:t.p=4,m=t.v,console.error("Error processing captured frame:",m),this.hideLoadingAnimation(),this.instructionText.textContent="Error processing image. Please try again.";case 5:return t.a(2)}}),t,this,[[1,4]])}))),function(t,e,n,r,i,o){return a.apply(this,arguments)})},{key:"showLoadingAnimation",value:function(){var t=document.createElement("div");t.className="loading-spinner",t.innerHTML='<i class="fas fa-spinner"></i>',t.style.position="absolute",t.style.top="50%",t.style.left="50%",t.style.transform="translate(-50%, -50%)",t.style.zIndex="3500";var e=t.querySelector("i");e.style.fontSize="48px",e.style.animation="spin 1s linear infinite",e.style.color="#e53935",this.cameraContainer.appendChild(t),this.loadingSpinner=t}},{key:"hideLoadingAnimation",value:function(){this.loadingSpinner&&this.loadingSpinner.parentNode===this.cameraContainer&&this.cameraContainer.removeChild(this.loadingSpinner)}},{key:"destroy",value:function(){this.stopAllStreams(),this.cameraContainer&&this.cameraContainer.parentNode&&this.cameraContainer.parentNode.removeChild(this.cameraContainer),this.styleTag&&this.styleTag.parentNode&&this.styleTag.parentNode.removeChild(this.styleTag),this.unlockAudioHandler&&document.removeEventListener("click",this.unlockAudioHandler)}},{key:"stopAllStreams",value:function(){this.frontStream&&(this.frontStream.getTracks().forEach((function(t){return t.stop()})),this.frontStream=null),this.backStream&&(this.backStream.getTracks().forEach((function(t){return t.stop()})),this.backStream=null)}}],e&&u(t.prototype,e),n&&u(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,a,s,c,d,h}();const m=e.A;export{m as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "accuraidscanplugin",
3
- "version": "1.0.29",
3
+ "version": "1.0.30",
4
4
  "main": "./dist/accuramain.js",
5
5
  "module": "./dist/accuramain.js",
6
6
  "scripts": {