UNPKG

dynamsoft-mrz-scanner

Version:

Dynamsoft MRZ Scanner JavaScript Edition is a ready-to-use SDK for web applications that accurately recognizes and parses Machine-Readable Zones on Machine-Readable Travel Documents.

1 lines 53.6 kB
import{EnumValidationStatus as e,MultiFrameResultCrossFilter as t,EnumCapturedResultItemType as n,CapturedResultReceiver as i,_toCanvas as s,_toBlob as a,Feedback as o,EnumImagePixelFormat as r,CoreModule as l,CodeParserModule as c,LicenseManager as d,CameraView as h,CameraEnhancer as u,CaptureVisionRouter as m}from"dynamsoft-capture-vision-bundle";import*as g from"dynamsoft-capture-vision-bundle";export{g as Dynamsoft};var p,f,y;!function(e){e.Passport="passport",e.TD1="td1",e.TD2="td2",e.PassportAndTD1="passportAndTd1",e.PassportAndTD2="passportAndTd2",e.TD1AndTD2="td1AndTd2",e.All="all"}(p||(p={})),function(e){e.Passport="passport",e.TD1="td1",e.TD2="td2"}(f||(f={})),function(e){e.Scanner="scanner",e.Result="scan-result"}(y||(y={}));const w={[p.Passport]:"ReadPassport",[p.TD1]:"ReadId-TD1",[p.TD2]:"ReadId-TD2",[p.PassportAndTD1]:"ReadPassportAndId-TD1",[p.PassportAndTD2]:"ReadPassportAndId-TD2",[p.TD1AndTD2]:"ReadId",[p.All]:"ReadPassportAndId"};var v;function S(e){if("string"==typeof e){const t=document.querySelector(e);if(!t)throw new Error("Element not found");return t}return e instanceof HTMLElement?e:null}!function(e){e[e.RS_SUCCESS=0]="RS_SUCCESS",e[e.RS_CANCELLED=1]="RS_CANCELLED",e[e.RS_FAILED=2]="RS_FAILED"}(v||(v={}));function R(e,t){if(!document.getElementById(e)){const n=document.createElement("style");n.id=e,n.textContent=t,document.head.appendChild(n)}}const E=e=>!e||0===Object.keys(e).length;function D(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}const C={"4k":{width:3840,height:2160},"2k":{width:2560,height:1440},"1080p":{width:1920,height:1080},"720p":{width:1280,height:720},"480p":{width:640,height:480}};function M(e,t={}){const{message:n,spinnerSize:i=32}=t,s=document.createElement("div");s.className="dynamsoft-mrz-loading-screen";const a=document.createElement("div");a.className="dynamsoft-mrz-loading";const o=document.createElement("div");o.className="dynamsoft-mrz-loading-content";const r=`\n <svg \n xmlns="http://www.w3.org/2000/svg" \n viewBox="0 0 24 24" \n fill="none" \n stroke="white" \n stroke-linecap="round" \n stroke-linejoin="round" \n width="${i}" \n height="${i}" \n stroke-width="0.75"\n > \n <path d="M12 3a9 9 0 1 0 9 9"></path> \n </svg>\n `;if(o.innerHTML=r,n){const e=document.createElement("div");e.className="dynamsoft-mrz-loading-message",e.textContent=n,o.appendChild(e)}return a.appendChild(o),s.appendChild(a),e.appendChild(s),{element:s,updateMessage:e=>{let t=a.querySelector(".dynamsoft-mrz-loading-message");null!==e?t?t.textContent=e:(t=document.createElement("div"),t.className="dynamsoft-mrz-loading-message",t.textContent=e,o.appendChild(t)):null==t||t.remove()},hide:()=>{s&&s.parentNode&&(s.classList.add("fade-out"),setTimeout((()=>{var e;null===(e=s.parentNode)||void 0===e||e.removeChild(s)}),200))}}}const T='\n .dynamsoft-mrz-loading-screen {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background-color: #323234;\n z-index: 998;\n opacity: 1;\n transition: opacity 0.2s ease-out;\n }\n\n .dynamsoft-mrz-loading-screen.fade-out {\n opacity: 0;\n }\n\n .dynamsoft-mrz-loading {\n position: absolute;\n left: 50%;\n top: 50%;\n color: white;\n z-index: 999;\n transform: translate(-50%, -50%);\n }\n\n .dynamsoft-mrz-loading-content {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 16px;\n }\n\n .dynamsoft-mrz-loading svg {\n animation: spin 1s linear infinite;\n }\n\n .dynamsoft-mrz-loading-message {\n color: white;\n font-family: "Verdana";\n font-size: 14px;\n text-align: center;\n max-width: 200px;\n line-height: 1.4;\n opacity: 0.9;\n }\n\n @keyframes spin {\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n }\n';var b;!function(e){e.InvalidFields="invalidFields",e.DocumentType="documentType",e.DocumentNumber="documentNumber",e.MRZText="mrzText",e.FirstName="firstName",e.LastName="lastName",e.Age="age",e.Sex="sex",e.IssuingState="issuingState",e.IssuingStateRaw="issuingStateRaw",e.Nationality="nationality",e.NationalityRaw="nationalityRaw",e.DateOfBirth="dateOfBirth",e.DateOfExpiry="dateOfExpiry"}(b||(b={}));const x={[b.InvalidFields]:"Invalid Fields",[b.DocumentType]:"Document Type",[b.DocumentNumber]:"Document Number",[b.MRZText]:"MRZ Text",[b.FirstName]:"Given Name(s)",[b.LastName]:"Surname",[b.Age]:"Age",[b.Sex]:"Sex",[b.IssuingState]:"Issuing State",[b.IssuingStateRaw]:"Issuing State (Raw Value)",[b.Nationality]:"Nationality",[b.NationalityRaw]:"Nationality State (Raw Value)",[b.DateOfBirth]:"Date Of Birth (YYYY-MM-DD)",[b.DateOfExpiry]:"Date Of Expiry (YYYY-MM-DD)"};function z(e,t,n,i=!1){const s=parseInt(e,10);let a;if(i)a=s>=60?1900+s:2e3+s;else{a=s>(new Date).getFullYear()%100?1900+s:2e3+s}return{year:a,month:parseInt(t,10),day:parseInt(n,10)}}function I(e){const t=e=>{var t;return 1===(null===(t=`${e}`)||void 0===t?void 0:t.length)?`0${e}`:e};return`${null==e?void 0:e.year}-${t(null==e?void 0:e.month)}${(null==e?void 0:e.day)&&`-${t(null==e?void 0:e.day)}`}`}function V(e){return"D<<"===e?"D":e}function F(t,n){const i=[],s=t=>n.getFieldValidationStatus(t)===e.VS_FAILED,a=n.codeType,o=function(e){switch(e){case"MRTD_TD1_ID":return f.TD1;case"MRTD_TD2_ID":case"MRTD_TD2_VISA":case"MRTD_TD2_FRENCH_ID":return f.TD2;case"MRTD_TD3_PASSPORT":case"MRTD_TD3_VISA":return f.Passport;default:throw new Error(`Unknown document type: ${e}`)}}(a),r=function(e){switch(e){case"MRTD_TD1_ID":return"ID (TD1)";case"MRTD_TD2_ID":return"ID (TD2)";case"MRTD_TD2_VISA":return"ID (VISA)";case"MRTD_TD2_FRENCH_ID":return"French ID (TD2)";case"MRTD_TD3_PASSPORT":return"Passport (TD3)";case"MRTD_TD3_VISA":return"Visa (TD3)";default:throw new Error(`Unknown document type: ${e}`)}}(a),l=o===f.Passport&&"MRTD_TD3_PASSPORT"===a?"passportNumber":"documentNumber",c=z(n.getFieldValue("birthYear"),n.getFieldValue("birthMonth"),n.getFieldValue("birthDay")),d=z(n.getFieldValue("expiryYear"),n.getFieldValue("expiryMonth"),n.getFieldValue("expiryDay"),!0);["birthYear","birthMonth","birthDay"].forEach((e=>{s(e)&&i.push(b.DateOfBirth)})),["expiryYear","expiryMonth","expiryDay"].forEach((e=>{s(e)&&i.push(b.DateOfExpiry)}));const h={[b.LastName]:n.getFieldValue("primaryIdentifier"),[b.FirstName]:n.getFieldValue("secondaryIdentifier"),[b.Nationality]:n.getFieldValue("nationality"),[b.NationalityRaw]:V(n.getFieldRawValue("nationality")),[b.DocumentNumber]:n.getFieldValue(l)||n.getFieldValue("longDocumentNumber"),[b.IssuingState]:n.getFieldValue("issuingState"),[b.IssuingStateRaw]:V(n.getFieldRawValue("issuingState")),[b.Sex]:D(n.getFieldValue("sex"))};Object.keys(h).forEach((e=>{let t=!1;switch(e){case b.FirstName:t=s("secondaryIdentifier");break;case b.LastName:t=s("primaryIdentifier");break;case b.DocumentNumber:t=s(l)||s("longDocumentNumber");break;default:t=s(e)}t&&i.push(e)}));const u=function(e){const t=new Date,n=t.getMonth()+1>e.month||t.getMonth()+1===e.month&&t.getDate()>=e.day;return t.getFullYear()-e.year-(n?0:1)}(c);u<1&&i.push(b.Age);return{[b.InvalidFields]:i,[b.FirstName]:h[b.FirstName],[b.LastName]:h[b.LastName],[b.Age]:u,[b.DateOfBirth]:c,[b.Sex]:h[b.Sex],[b.Nationality]:h[b.Nationality],[b.NationalityRaw]:h[b.NationalityRaw],[b.DocumentNumber]:h[b.DocumentNumber],[b.DateOfExpiry]:d,[b.IssuingState]:h[b.IssuingState],[b.IssuingStateRaw]:h[b.IssuingStateRaw],[b.DocumentType]:D(r),[b.MRZText]:t}}const N={[f.TD1]:{width:85.6,height:53.98},[f.TD2]:{width:105,height:74},[f.Passport]:{width:125,height:88}};class _{showScannerLoadingOverlay(e){const t=S(this.config.container);this.loadingScreen=M(t,{message:e}),t.style.display="block",t.style.position="relative"}hideScannerLoadingOverlay(e=!1){this.loadingScreen&&(this.loadingScreen.hide(),this.loadingScreen=null,e&&(S(this.config.container).style.display="none"))}constructor(e,t){this.resources=e,this.config=t,this.isSoundFeedbackOn=!1,this.scanModeManager={[f.Passport]:!0,[f.TD1]:!0,[f.TD2]:!0},this.currentScanMode=p.All,this.resizeTimer=null,this.capturedResultItems=[],this.originalImageData=null,this.initialized=!1,this.initializedDCE=!1,this.DCE_ELEMENTS={selectCameraBtn:null,uploadImageBtn:null,soundFeedbackBtn:null,closeScannerBtn:null,scanModeSelectContainer:null,passportModeOption:null,td1ModeOption:null,td2ModeOption:null,toast:null},this.loadingScreen=null,this.handleResize=()=>{this.toggleScanGuide(!1),this.resizeTimer&&window.clearTimeout(this.resizeTimer),this.resizeTimer=window.setTimeout((()=>{this.toggleScanGuide(!0)}),500)},this.firstFrame=!0}async initialize(){if(!this.initialized){this.initializeScanModeManager(),this.currentScanMode=this.getScanMode(),R("dynamsoft-mrz-loading-screen-style",T);try{const{cameraView:e,cameraEnhancer:s,cvRouter:a}=this.resources;if(e.setScanRegionMaskStyle({strokeStyle:"transparent",fillStyle:"transparent",lineWidth:0}),e.setVideoFit("cover"),a.setInput(s),!0===this.config.enableMultiFrameCrossFilter){const e=new t;e.enableResultCrossVerification(n.CRIT_TEXT_LINE,!0),await a.addResultFilter(e)}const o=new i;o.onCapturedResultReceived=e=>this.handleMRZResult(e),await a.addResultReceiver(o),this.toggleSoundFeedback(!1),!1===this.config.showScanGuide&&this.toggleScanGuide(!1),this.initialized=!0}catch(e){let t=(null==e?void 0:e.message)||e;console.error(t),alert(t),this.closeCamera();const n={status:{code:v.RS_FAILED,message:"Dynamsoft MRZ Scanner initialize error"}};this.currentScanResolver(n)}}}initializeElements(){var e;const t=S(this.config.container),n=t.children[t.children.length-1];if(!(null==n?void 0:n.shadowRoot))throw new Error("Shadow root not found");if(this.DCE_ELEMENTS={selectCameraBtn:n.shadowRoot.querySelector(".dce-mn-select-camera-icon"),uploadImageBtn:n.shadowRoot.querySelector(".dce-mn-upload-image-icon"),soundFeedbackBtn:n.shadowRoot.querySelector(".dce-mn-sound-feedback"),closeScannerBtn:n.shadowRoot.querySelector(".dce-mn-close"),scanModeSelectContainer:n.shadowRoot.querySelector(".dce-mn-scan-mode-select"),passportModeOption:n.shadowRoot.querySelector(".scan-mode-option-passport"),td1ModeOption:n.shadowRoot.querySelector(".scan-mode-option-td1"),td2ModeOption:n.shadowRoot.querySelector(".scan-mode-option-td2"),toast:n.shadowRoot.querySelector(".dce-mn-toast")},this.setupScanModeSelector(),this.assignDCEClickEvents(),this.DCE_ELEMENTS.toast.style.display="none",!1===this.config.showUploadImage&&(this.DCE_ELEMENTS.uploadImageBtn.style.visibility="hidden"),!1===this.config.showSoundToggle&&(this.DCE_ELEMENTS.soundFeedbackBtn.style.visibility="hidden"),!1===(null===(e=this.config)||void 0===e?void 0:e.showPoweredByDynamsoft)){n.shadowRoot.querySelector(".dce-mn-msg-poweredby").style.display="none"}this.initializedDCE=!0}setupScanModeSelector(){if(!1!==this.config.showFormatSelector)switch(this.currentScanMode){case p.PassportAndTD1:this.DCE_ELEMENTS.td2ModeOption.style.display="none";break;case p.PassportAndTD2:this.DCE_ELEMENTS.td1ModeOption.style.display="none";break;case p.TD1AndTD2:this.DCE_ELEMENTS.passportModeOption.style.display="none";break;case p.All:break;default:this.DCE_ELEMENTS.scanModeSelectContainer.style.display="none"}else this.DCE_ELEMENTS.scanModeSelectContainer.style.display="none"}assignDCEClickEvents(){if(!Object.values(this.DCE_ELEMENTS).every(Boolean))throw new Error("Camera control elements not found");this.closeCamera=this.closeCamera.bind(this),this.DCE_ELEMENTS.uploadImageBtn.onclick=()=>this.uploadFile(),this.DCE_ELEMENTS.soundFeedbackBtn.onclick=()=>this.toggleSoundFeedback(),this.DCE_ELEMENTS.closeScannerBtn.onclick=()=>this.handleCloseBtn(),this.DCE_ELEMENTS.selectCameraBtn.onclick=e=>{e.stopPropagation(),this.toggleSelectCameraBox()},this.DCE_ELEMENTS.passportModeOption.onclick=async()=>{"none"!==this.DCE_ELEMENTS.passportModeOption.style.display&&await this.toggleScanDocType(f.Passport)},this.DCE_ELEMENTS.td1ModeOption.onclick=async()=>{"none"!==this.DCE_ELEMENTS.td1ModeOption.style.display&&await this.toggleScanDocType(f.TD1)},this.DCE_ELEMENTS.td2ModeOption.onclick=async()=>{"none"!==this.DCE_ELEMENTS.td2ModeOption.style.display&&await this.toggleScanDocType(f.TD2)}}handleCloseBtn(){this.closeCamera(),this.currentScanResolver&&this.currentScanResolver({status:{code:v.RS_CANCELLED,message:"Cancelled"}})}attachOptionClickListeners(){const e=S(this.config.container),t=e.children[e.children.length-1];if(!(null==t?void 0:t.shadowRoot))return;const n=t.shadowRoot.querySelector(".dce-mn-camera-and-resolution-settings");[...t.shadowRoot.querySelectorAll(".dce-mn-camera-option"),...t.shadowRoot.querySelectorAll(".dce-mn-resolution-option")].forEach((e=>{e.addEventListener("click",(async t=>{const i=e.getAttribute("data-davice-id"),s=e.getAttribute("data-height"),a=e.getAttribute("data-width");i?this.resources.cameraEnhancer.selectCamera(i).then((()=>{this.toggleScanGuide()})):s&&a&&this.resources.cameraEnhancer.setResolution({width:parseInt(a),height:parseInt(s)}).then((()=>{this.toggleScanGuide()})),"none"!==n.style.display&&this.toggleSelectCameraBox()}))}))}highlightCameraAndResolutionOption(){const e=S(this.config.container),t=e.children[e.children.length-1];if(!(null==t?void 0:t.shadowRoot))return;const n=t.shadowRoot.querySelector(".dce-mn-camera-and-resolution-settings"),i=n.querySelectorAll(".dce-mn-camera-option"),s=n.querySelectorAll(".dce-mn-resolution-option"),a=this.resources.cameraEnhancer.getSelectedCamera(),o=this.resources.cameraEnhancer.getResolution();i.forEach((e=>{const t=e;t.getAttribute("data-davice-id")===(null==a?void 0:a.deviceId)?t.style.border="2px solid #fe814a":t.style.border="none"}));const r={"480p":"480","720p":"720","1080p":"1080","2k":"1440","4k":"2160"},l=function(e){const t=e.width*e.height,n=e.width/e.height;let i="480p",s=Number.MAX_VALUE;for(const[e,a]of Object.entries(C)){const o=a.width*a.height,r=a.width/a.height,l=.7*Math.abs(o-t)+Math.abs(r-n)*o*.3;l<s&&(s=l,i=e)}return i}(o);s.forEach((e=>{const t=e,n=t.getAttribute("data-height");t.style.border=n===r[l]?"2px solid #fe814a":"none"}))}toggleSelectCameraBox(){const e=S(this.config.container),t=e.children[e.children.length-1];if(!(null==t?void 0:t.shadowRoot))return;const n=t.shadowRoot.querySelector(".dce-mn-resolution-box");this.highlightCameraAndResolutionOption(),this.attachOptionClickListeners(),n.click()}async relaunch(){}async uploadFile(){var e,t,i,o,r,l;const{cvRouter:c}=this.resources,d=document.createElement("input");d.type="file",d.accept=null!==(e=this.config.uploadAcceptedTypes)&&void 0!==e?e:"image/*",d.style.display="none",document.body.appendChild(d);try{this.showScannerLoadingOverlay("Processing file..."),await this.closeCamera(!1);const e=await new Promise(((e,t)=>{d.onchange=n=>{var i;const s=null===(i=n.target.files)||void 0===i?void 0:i[0];s?e(s):t(new Error("No file selected"))},d.addEventListener("cancel",(async()=>{this.hideScannerLoadingOverlay(!1),this.showScannerLoadingOverlay("Initializing camera..."),await this.openCamera(),this.toggleScanGuide(),await this.startCapturing(),this.hideScannerLoadingOverlay()})),d.click()}));if(!e)return;let h;if(this.config.uploadFileConverter&&!e.type.startsWith("image/"))try{h=await this.config.uploadFileConverter(e)}catch(e){throw new Error(`Error converting file: ${e.message}`)}else{if(!e.type.startsWith("image/"))throw new Error("Unsupported file type. Please provide a converter function for this file type.");h=e}const u=this.config.utilizedTemplateNames[this.currentScanMode];if(!1!==this.config.showScanGuide){const e=await c.getSimplifiedSettings(u);e.roiMeasuredInPercentage=!0,e.roi.points=[{x:0,y:0},{x:100,y:0},{x:100,y:100},{x:0,y:100}],await c.updateSettings(u,e)}const m=await c.capture(h,u);this.capturedResultItems=m.items;const g=this.capturedResultItems.filter((e=>e.type===n.CRIT_ORIGINAL_IMAGE));if(0===g.length)throw new Error("No image data found in the captured result");const p=g[0].imageData;p.toCanvas=()=>s(p),p.toBlob=async()=>await a("image/png",p),this.originalImageData=p;const f=null===(t=null==m?void 0:m.parsedResult)||void 0===t?void 0:t.parsedResultItems;let y={};if(null==f?void 0:f.length){const e=(null===(o=null===(i=f[0])||void 0===i?void 0:i.referencedItem)||void 0===o?void 0:o.text)||"";y=F(e,f[0])}const w={status:{code:v.RS_SUCCESS,message:"Success"},originalImageResult:this.originalImageData,data:y,imageData:!0,_imageData:this.originalImageData};null===(l=(r=this.resources).onResultUpdated)||void 0===l||l.call(r,w),this.currentScanResolver(w)}catch(e){let t=(null==e?void 0:e.message)||e;console.error(t),alert(t),this.closeCamera();const n={status:{code:v.RS_FAILED,message:`Error processing file: ${t}`}};this.currentScanResolver(n)}finally{this.hideScannerLoadingOverlay(!0),document.body.removeChild(d)}}toggleSoundFeedback(e){this.isSoundFeedbackOn=void 0!==e?e:!this.isSoundFeedbackOn;const t=S(this.config.container),n=t.children[t.children.length-1];if(!(null==n?void 0:n.shadowRoot))return;const i=n.shadowRoot.querySelector(".dce-mn-sound-feedback"),s=i.querySelector(".dce-mn-sound-feedback-on");i.querySelector(".dce-mn-sound-feedback-off").style.display=this.isSoundFeedbackOn?"none":"block",s.style.display=this.isSoundFeedbackOn?"block":"none"}calculateScanRegion(e){const{cameraEnhancer:t,cameraView:n}=this.resources;if(!t||!t.isOpen())return;const i=N[e].width/N[e].height;let s;const a=n.getVisibleRegionOfVideo({inPixels:!0}),{width:o,height:r}=a;if(a){if(a.width>a.height){const e=.5*r*i,t=Math.round(e/o*100),n=(100-t)/2;s={left:n,right:n+t,top:25,bottom:75,isMeasuredInPercentage:!0}}else{const e=.9*o/i,t=Math.round(e/r*100),n=(100-t)/2;s={left:5,right:95,top:n,bottom:n+t,isMeasuredInPercentage:!0}}null==n||n.setScanRegionMaskVisible(!0),t.setScanRegion(s)}}toggleScanGuide(e){const t=S(this.config.container),n=t.children[t.children.length-1];if(!(null==n?void 0:n.shadowRoot))return;const i=n.shadowRoot.querySelector(".dce-scanguide-passport"),s=n.shadowRoot.querySelector(".dce-scanguide-td1"),a=n.shadowRoot.querySelector(".dce-scanguide-td2");if(!1===e||!1===this.config.showScanGuide)return i.style.display="none",s.style.display="none",void(a.style.display="none");switch(this.currentScanMode){case p.All:case p.Passport:case p.PassportAndTD1:case p.PassportAndTD2:i.style.display="block",s.style.display="none",a.style.display="none",this.calculateScanRegion(f.Passport);break;case p.TD1:case p.TD1AndTD2:i.style.display="none",s.style.display="block",a.style.display="none",this.calculateScanRegion(f.TD1);break;case p.TD2:i.style.display="none",s.style.display="none",a.style.display="block",this.calculateScanRegion(f.TD2)}}async openCamera(){try{const{cameraEnhancer:e,cameraView:t}=this.resources,n=S(this.config.container);if(n.style.display="block",e.isOpen())e.isPaused()&&await e.resume();else{const i=t.getUIElement();i.parentElement||n.append(i),await e.open()}await e.setResolution({width:2560,height:1440}),!this.initializedDCE&&e.isOpen()&&await this.initializeElements(),window.addEventListener("resize",this.handleResize);const i=n.children[n.children.length-1];if(!(null==i?void 0:i.shadowRoot))throw new Error("Shadow root not found");i.shadowRoot.querySelector(".dce-mn-torch-off").style.display="none",i.shadowRoot.querySelector(".dce-mn-torch-on").style.display="none"}catch(e){let t=(null==e?void 0:e.message)||e;console.error(t),alert(t),this.closeCamera();const n={status:{code:v.RS_FAILED,message:"MRZ Scanner Open Camera Error"}};this.currentScanResolver(n)}}async closeCamera(e=!0){try{window.removeEventListener("resize",this.handleResize),this.resizeTimer&&(window.clearTimeout(this.resizeTimer),this.resizeTimer=null);const{cameraEnhancer:t,cameraView:n}=this.resources,i=S(this.config.container);i.style.display=e?"none":"block",(null==n?void 0:n.getUIElement().parentElement)&&i.removeChild(n.getUIElement()),t.close(),this.stopCapturing()}catch(e){let t=(null==e?void 0:e.message)||e;console.error(`Close Camera error: ${t}`)}}pauseCamera(){const{cameraEnhancer:e}=this.resources;e.pause()}stopCapturing(){const{cameraView:e,cvRouter:t}=this.resources;t.stopCapturing(),e.clearAllInnerDrawingItems()}async handleMRZResult(e){var t,i,r;if(this.firstFrame)this.firstFrame=!1;else if(!(e.items.length<=1)){this.capturedResultItems=e.items;try{const{onResultUpdated:l}=this.resources,c=e.items.filter((e=>e.type===n.CRIT_ORIGINAL_IMAGE))[0].imageData;c.toCanvas=()=>s(c),c.toBlob=async()=>await a("image/png",c),this.originalImageData=c;const d=null===(t=null==e?void 0:e.parsedResult)||void 0===t?void 0:t.parsedResultItems;if(null==d?void 0:d.length){this.isSoundFeedbackOn&&o.beep();const e=(null===(r=null===(i=d[0])||void 0===i?void 0:i.referencedItem)||void 0===r?void 0:r.text)||"",t=F(e,d[0]);this.closeCamera();const n={status:{code:v.RS_SUCCESS,message:"Success"},originalImageResult:this.originalImageData,data:t,imageData:!0,_imageData:this.originalImageData};null==l||l(n),this.currentScanResolver(n)}}catch(e){let t=(null==e?void 0:e.message)||e;console.error(t),alert(t),this.closeCamera();const n={status:{code:v.RS_FAILED,message:"Error capturing image"}};this.currentScanResolver(n)}}}initializeScanModeManager(){const{mrzFormatType:e}=this.config;if(this.scanModeManager={[f.Passport]:!0,[f.TD1]:!0,[f.TD2]:!0},!e||Array.isArray(e)&&0===e.length)return;Object.keys(this.scanModeManager).forEach((e=>{this.scanModeManager[e]=!1}));(Array.isArray(e)?e:[e]).forEach((e=>{this.scanModeManager[e]=!0}))}getScanMode(){const e=Object.entries(this.scanModeManager).filter((([e,t])=>t)).map((([e])=>e)).sort().join(",");return{[f.Passport]:p.Passport,[f.TD1]:p.TD1,[f.TD2]:p.TD2,[`${f.Passport},${f.TD1}`]:p.PassportAndTD1,[`${f.Passport},${f.TD2}`]:p.PassportAndTD2,[`${f.TD1},${f.TD2}`]:p.TD1AndTD2,[`${f.Passport},${f.TD1},${f.TD2}`]:p.All,"":p.All}[e]}DCEShowToast(e,t=3e3){this.DCE_ELEMENTS.toast&&(this.DCE_ELEMENTS.toast.textContent=e,this.DCE_ELEMENTS.toast.style.display="",setTimeout((()=>{this.DCE_ELEMENTS.toast.style.display="none"}),t))}async startCapturing(){const{cvRouter:e,cameraEnhancer:t}=this.resources,n=this.config.utilizedTemplateNames[this.currentScanMode];try{if(!1!==this.config.showScanGuide){const t=await e.getSimplifiedSettings(n);t.roiMeasuredInPercentage=!0,t.roi.points=[{x:0,y:50},{x:100,y:50},{x:100,y:100},{x:0,y:100}],await e.updateSettings(n,t)}this.firstFrame=!0,await e.startCapturing(n),t.setPixelFormat(r.IPF_ABGR_8888)}catch(e){let t=(null==e?void 0:e.message)||e;console.error("Failed to start capturing:",t),this.closeCamera(),this.currentScanResolver&&this.currentScanResolver({status:{code:v.RS_FAILED,message:"Failed to start capturing"}})}}async toggleScanDocType(e){try{if(this.scanModeManager[e]&&0===Object.entries(this.scanModeManager).filter((([t,n])=>n&&t!==e)).length)return console.warn("MRZ Scanner - At least one mode must be enabled"),void this.DCEShowToast("At least one mode must be enabled");this.scanModeManager[e]=!this.scanModeManager[e],this.currentScanMode=this.getScanMode(),this.stopCapturing(),this.toggleScanGuide(),await this.startCapturing(),this.DCE_ELEMENTS.td1ModeOption.classList.toggle("selected",this.scanModeManager[f.TD1]),this.DCE_ELEMENTS.td2ModeOption.classList.toggle("selected",this.scanModeManager[f.TD2]),this.DCE_ELEMENTS.passportModeOption.classList.toggle("selected",this.scanModeManager[f.Passport])}catch(e){let t=(null==e?void 0:e.message)||e;console.error("MRZ Scanner switch scan mode error: ",t),this.closeCamera();const n={status:{code:v.RS_FAILED,message:"MRZ Scanner switch scan mode error"}};this.currentScanResolver(n)}}async launch(){try{await this.initialize();const{cvRouter:e,cameraEnhancer:t}=this.resources;return new Promise((async e=>{this.currentScanResolver=e,this.showScannerLoadingOverlay("Initializing camera..."),await this.openCamera(),!this.initializedDCE&&t.isOpen()&&await this.initializeElements(),this.toggleScanGuide(),await this.startCapturing(),this.hideScannerLoadingOverlay()}))}catch(e){let t=(null==e?void 0:e.message)||e;console.error("MRZ Scanner launch error: ",t),this.closeCamera();const n={status:{code:v.RS_FAILED,message:"MRZ Scanner launch error"}};this.currentScanResolver(n)}}}const L={cancel:'\n<svg id="cancel" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24" height="24" viewBox="0 0 24 24">\n <defs>\n <clipPath id="cancelclip-path">\n <rect id="Rectangle_2774" data-name="Rectangle 2774" width="24" height="24" fill="currentColor"/>\n </clipPath>\n </defs>\n <g id="Group_582" data-name="Group 582" clip-path="url(#cancelclip-path)" transform="rotate(180 12 12)">\n <path id="Path_1524" data-name="Path 1524" d="M12,0A12,12,0,1,0,24,12,12.013,12.013,0,0,0,12,0m0,23A11,11,0,1,1,23,12,11.013,11.013,0,0,1,12,23" fill="currentColor"/>\n <path id="Path_1525" data-name="Path 1525" d="M19.862,12a.17.17,0,0,0,0-.024.512.512,0,0,0-.033-.168.532.532,0,0,0-.113-.17l-4.219-4.29a.5.5,0,0,0-.714,0,.51.51,0,0,0,0,.719l3.371,3.428H4.643a.509.509,0,0,0,0,1.018h13.5l-3.373,3.428a.512.512,0,0,0,0,.72.5.5,0,0,0,.714,0l4.224-4.295a.438.438,0,0,0,.056-.086.5.5,0,0,0,.051-.078A.521.521,0,0,0,19.862,12h0" fill="currentColor"/>\n </g>\n</svg> \n ',rescan:'<svg id="re-take" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="28.761" height="23" viewBox="0 0 28.761 23">\n<defs>\n<clipPath id="retakeclip-path">\n <rect id="Rectangle_2773" data-name="Rectangle 2773" width="28.761" height="23" fill="#fff"/>\n</clipPath>\n</defs>\n<g id="Group_580" data-name="Group 580" clip-path="url(#retakeclip-path)">\n<path id="Path_1522" data-name="Path 1522" d="M25.877,3.639H21.663a.7.7,0,0,1-.575-.288l-.575-.764C19.264.961,18.59,0,17.44,0H11.4C10.151,0,9.486.961,8.336,2.588l-.674.764a.7.7,0,0,1-.575.288H2.875C.476,3.639,0,5.077,0,6.227v13.9C0,22.041,1.051,23,2.974,23H25.787c1.914,0,2.974-.961,2.974-2.776v-14c-.008-1.147-.485-2.585-2.884-2.585m-.1,18.411H2.974c-1.339,0-2.013-.575-2.013-1.824v-14c0-.863.189-1.626,1.914-1.626H7.188a1.666,1.666,0,0,0,1.339-.674L9.1,3.162c1.15-1.626,1.536-2.2,2.2-2.2H17.34c.674,0,1.15.575,2.3,2.2l.575.764a1.562,1.562,0,0,0,1.339.674h4.313c1.725,0,1.914.764,1.914,1.626v14h.009c0,1.249-.673,1.824-2.012,1.824" fill="#fff"/>\n<path id="Path_1523" data-name="Path 1523" d="M15.978,9.16H9.462l1.745-1.743A.5.5,0,0,0,10.5,6.71l-2.6,2.6a.484.484,0,0,0-.108.162.5.5,0,0,0,0,.382.479.479,0,0,0,.108.163l2.6,2.6a.5.5,0,0,0,.708-.708L9.462,10.16h6.516a4.028,4.028,0,0,1,0,8.055H10.255a.5.5,0,1,0,0,1h5.723a5.028,5.028,0,0,0,0-10.055" fill="#fff"/>\n</g>\n</svg>\n',complete:'\n<svg id="continue" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24" height="24" viewBox="0 0 24 24">\n<defs>\n<clipPath id="continueclip-path">\n <rect id="Rectangle_2774" data-name="Rectangle 2774" width="24" height="24" fill="currentColor"/>\n</clipPath>\n</defs>\n<g id="Group_582" data-name="Group 582" clip-path="url(#continueclip-path)">\n<path id="Path_1524" data-name="Path 1524" d="M12,0A12,12,0,1,0,24,12,12.013,12.013,0,0,0,12,0m0,23A11,11,0,1,1,23,12,11.013,11.013,0,0,1,12,23" fill="currentColor"/>\n<path id="Path_1525" data-name="Path 1525" d="M19.862,12a.17.17,0,0,0,0-.024.512.512,0,0,0-.033-.168.532.532,0,0,0-.113-.17l-4.219-4.29a.5.5,0,0,0-.714,0,.51.51,0,0,0,0,.719l3.371,3.428H4.643a.509.509,0,0,0,0,1.018h13.5l-3.373,3.428a.512.512,0,0,0,0,.72.5.5,0,0,0,.714,0l4.224-4.295a.438.438,0,0,0,.056-.086.5.5,0,0,0,.051-.078A.521.521,0,0,0,19.862,12h0" fill="currentColor"/>\n</g>\n</svg>\n',failed:'\n <svg\n xmlns="http://www.w3.org/2000/svg"\n width="20"\n height="20"\n viewBox="0 0 20 20"\n fill="none"\n stroke="#ef4444"\n stroke-width="2"\n stroke-linecap="round"\n stroke-linejoin="round"\n>\n <path d="M18 6l-12 12" />\n <path d="M6 6l12 12" />\n</svg>\n',info:'\n<svg\n xmlns="http://www.w3.org/2000/svg"\n width="24"\n height="24"\n viewBox="0 0 24 24"\n fill="none"\n stroke="white"\n stroke-width="2"\n stroke-linecap="round"\n stroke-linejoin="round"\n>\n <path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />\n <path d="M12 9h.01" />\n <path d="M11 12h1v4h1" />\n</svg>\n'};class k{constructor(e,t,n){this.resources=e,this.config=t,this.scannerView=n,this.editedFields={}}async launch(){try{return S(this.config.container).textContent="",await this.initialize(),S(this.config.container).style.display="flex",new Promise((e=>{this.currentScanResultViewResolver=e}))}catch(e){let t=(null==e?void 0:e.message)||e;throw console.error(t),t}}async handleRescan(){var e;try{if(!this.scannerView)return void console.error("Scanner View not initialized");this.hideView();const t=await this.scannerView.launch();if((null===(e=null==t?void 0:t.status)||void 0===e?void 0:e.code)===v.RS_FAILED)return void(this.currentScanResultViewResolver&&this.currentScanResultViewResolver(t));this.resources.onResultUpdated&&((null==t?void 0:t.status.code)===v.RS_CANCELLED?this.resources.onResultUpdated(this.resources.result):(null==t?void 0:t.status.code)===v.RS_SUCCESS&&this.resources.onResultUpdated(t)),this.dispose(!0),await this.initialize(),S(this.config.container).style.display="flex"}catch(e){throw console.error("Error in rescan handler:",e),this.currentScanResultViewResolver&&this.currentScanResultViewResolver({status:{code:v.RS_FAILED,message:(null==e?void 0:e.message)||e}}),e}}async handleCancel(){var e;try{(null===(e=this.config)||void 0===e?void 0:e.onCancel)&&await this.config.onCancel(this.resources.result),this.currentScanResultViewResolver&&this.currentScanResultViewResolver({status:{code:v.RS_CANCELLED,message:"Upload file cancelled"}}),this.hideView(),this.dispose()}catch(e){throw console.error("Error in cancel handler:",e),this.currentScanResultViewResolver&&this.currentScanResultViewResolver({status:{code:v.RS_FAILED,message:(null==e?void 0:e.message)||e}}),e}}async handleDone(){var e,t;try{(null===(e=this.resources.result)||void 0===e?void 0:e.data)&&!E(this.editedFields)&&(this.resources.result.data=Object.assign(Object.assign({},this.resources.result.data),this.editedFields),this.resources.onResultUpdated&&this.resources.onResultUpdated(this.resources.result)),(null===(t=this.config)||void 0===t?void 0:t.onDone)&&await this.config.onDone(this.resources.result),this.currentScanResultViewResolver&&this.resources.result&&this.currentScanResultViewResolver(this.resources.result),this.hideView(),this.dispose()}catch(e){throw console.error("Error in done handler:",e),this.currentScanResultViewResolver&&this.currentScanResultViewResolver({status:{code:v.RS_FAILED,message:(null==e?void 0:e.message)||e}}),e}}createControls(){var e,t,n,i,s,a,o,r,l,c,d,h;const{toolbarButtonsConfig:u}=this.config;return function(e){R("dynamsoft-mrz-controls-style","\n .dynamsoft-mrz-controls {\n display: flex;\n height: 6rem;\n background-color: #323234;\n align-items: center;\n font-size: 12px;\n font-family: Verdana;\n color: white;\n width: 100%;\n }\n\n .dynamsoft-mrz-control-btn {\n background-color: #323234;\n color: white;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n height: 100%;\n width: 100%;\n gap: 0.5rem;\n text-align: center;\n user-select: none;\n }\n\n .dynamsoft-mrz-control-btn.hide {\n display: none;\n }\n\n .dynamsoft-mrz-control-btn.disabled {\n opacity: 0.4;\n pointer-events: none;\n cursor: default;\n }\n\n .dynamsoft-mrz-control-icon-wrapper {\n flex: 0.75;\n display: flex;\n align-items: flex-end;\n justify-content: center;\n min-height: 40px;\n }\n\n .dynamsoft-mrz-control-icon img,\n .dynamsoft-mrz-control-icon svg {\n width: 32px;\n height: 32px;\n fill: #fe8e14;\n }\n\n .dynamsoft-mrz-control-text {\n flex: 0.5;\n display: flex;\n align-items: flex-start;\n justify-content: center;\n padding-bottom: 0.5rem;\n }\n\n \n @media screen and (orientation: landscape) and (max-width: 1024px) and (max-height: 600px) {\n .dynamsoft-mrz-controls {\n flex-direction: column;\n height: 100%;\n width: 5rem;\n }\n\n .dynamsoft-mrz-control-text {\n padding: 0 0.5rem 0.5rem;\n }\n }\n");const t=document.createElement("div");return t.className="dynamsoft-mrz-controls",e.forEach((e=>{const n=document.createElement("div");n.className=`dynamsoft-mrz-control-btn ${null==e?void 0:e.className}`;const i=document.createElement("div");if(i.className="dynamsoft-mrz-control-icon-wrapper",(s=e.icon).trim().startsWith("<svg")&&s.trim().endsWith("</svg>"))i.innerHTML=e.icon;else{const t=document.createElement("img");t.src=e.icon,t.alt=e.label,t.width=24,t.height=24,i.appendChild(t)}var s;const a=document.createElement("div");a.className="dynamsoft-mrz-control-text",a.textContent=e.label,e.isDisabled&&n.classList.add("disabled"),e.isHidden&&n.classList.add("hide"),n.appendChild(i),n.appendChild(a),e.onClick&&!e.isDisabled&&n.addEventListener("click",e.onClick),t.appendChild(n)})),t}([this.config._isFileMode?{id:"dynamsoft-mrz-scanResult-cancel",icon:(null===(e=null==u?void 0:u.cancel)||void 0===e?void 0:e.icon)||L.cancel,label:(null===(t=null==u?void 0:u.cancel)||void 0===t?void 0:t.label)||"Cancel",onClick:()=>this.handleCancel(),className:`${(null===(n=null==u?void 0:u.cancel)||void 0===n?void 0:n.className)||""}`,isHidden:(null===(i=null==u?void 0:u.cancel)||void 0===i?void 0:i.isHidden)||!1}:{id:"dynamsoft-mrz-scanResult-rescan",icon:(null===(s=null==u?void 0:u.rescan)||void 0===s?void 0:s.icon)||L.rescan,label:(null===(a=null==u?void 0:u.rescan)||void 0===a?void 0:a.label)||"Re-scan",onClick:()=>this.handleRescan(),className:`${(null===(o=null==u?void 0:u.rescan)||void 0===o?void 0:o.className)||""}`,isHidden:(null===(r=null==u?void 0:u.rescan)||void 0===r?void 0:r.isHidden)||!1,isDisabled:!this.scannerView},{id:"dynamsoft-mrz-scanResult-done",icon:(null===(l=null==u?void 0:u.done)||void 0===l?void 0:l.icon)||L.complete,label:(null===(c=null==u?void 0:u.done)||void 0===c?void 0:c.label)||"Done",className:`${(null===(d=null==u?void 0:u.done)||void 0===d?void 0:d.className)||""}`,isHidden:(null===(h=null==u?void 0:u.done)||void 0===h?void 0:h.isHidden)||!1,onClick:()=>this.handleDone()}])}handleFieldEdit(e,t){if(e===b.DateOfBirth||e===b.DateOfExpiry)try{const[n,i,s]=t.split(/[\/\-\.]/);s&&i&&n&&(this.editedFields[e]={day:parseInt(s,10),month:parseInt(i,10),year:parseInt(n,10)})}catch(e){console.error("Error parsing date",e)}else this.editedFields[e]=t}createMRZDataDisplay(){var e,t,n,i;const s=(null===(e=this.resources.result)||void 0===e?void 0:e.data)||{},a=!!this.config.allowResultEditing,o=s.invalidFields||[],r=[b.InvalidFields,b.IssuingStateRaw,b.NationalityRaw];!1===(null===(t=this.config)||void 0===t?void 0:t.showMRZText)&&r.push(b.MRZText);const l=document.createElement("div");if(l.className="dynamsoft-mrz-data-container",E(s)){const e=document.createElement("div");return e.className="dynamsoft-mrz-data-row empty",e.innerText=null!==(i=null===(n=this.config)||void 0===n?void 0:n.emptyResultMessage)&&void 0!==i?i:"The necessary information could not be detected. Please try again.",l.appendChild(e),l}if(o.length>0){const e=document.createElement("div");e.className="dynamsoft-mrz-error-notification",e.innerHTML=`\n <div class="dynamsoft-mrz-error-icon">${L.failed}</div>\n <div class="dynamsoft-mrz-error-message">\n ${a?"Some fields require correction. Please review highlighted fields.":"Some fields contain invalid information. Please rescan the document."}\n </div>\n `,l.appendChild(e)}else if(0===o.length&&a){const e=document.createElement("div");e.className="dynamsoft-mrz-info-notification",e.innerHTML=`\n <div class="dynamsoft-mrz-info-icon">${L.info}</div>\n <div class="dynamsoft-mrz-info-message">\n Please review all fields to ensure the information is correct.\n </div>\n `,l.appendChild(e)}return Object.entries(s).forEach((([e,t])=>{if(r.includes(e)||!t)return;const n=document.createElement("div");n.className="dynamsoft-mrz-data-row";const i=o.includes(e);i&&n.classList.add("invalid-field");const s=[b.MRZText,b.DocumentType,b.IssuingStateRaw,b.NationalityRaw],c=document.createElement("span");if(c.className="dynamsoft-mrz-data-label",c.innerText=x[e]||e,i){const e=document.createElement("span");if(e.className="dynamsoft-mrz-error-icon",e.innerHTML=L.failed,c.appendChild(e),a){const e=document.createElement("span");e.className="dynamsoft-mrz-error-hint",e.textContent="Please correct this field",c.appendChild(e)}}const d=document.createElement("div");if(d.className="dynamsoft-mrz-data-value",a&&!s.includes(e)){const s=document.createElement("input");s.className="dynamsoft-mrz-data-input",i&&s.classList.add("invalid"),e===b.DateOfBirth||e===b.DateOfExpiry?(s.value=I(t),s.setAttribute("placeholder","YYYY-MM-DD")):s.value=t,s.addEventListener("input",(t=>{if(this.handleFieldEdit(e,t.target.value),i){s.classList.remove("invalid"),n.classList.remove("invalid-field"),this.editedFields.invalidFields||(this.editedFields.invalidFields=[...o]);const t=this.editedFields.invalidFields.indexOf(e);t>-1&&this.editedFields.invalidFields.splice(t,1)}})),d.appendChild(s)}else e===b.MRZText?(d.classList.add("code"),d.innerText=t):e===b.DateOfBirth||e===b.DateOfExpiry?d.innerText=I(t):d.innerText=t,i&&d.classList.add("invalid-value");n.appendChild(c),n.appendChild(d),l.appendChild(n)})),l}async initialize(){try{if(!this.resources.result)throw Error("Captured image is missing. Please capture an image first!");if(!this.config.container)throw new Error("Please create a Scan Result View Container element");R("dynamsoft-mrz-result-view-style",A);const e=document.createElement("div");if(e.className="dynamsoft-mrz-result-view-container",!1!==this.config.showOriginalImage){const t=this.resources.result.originalImageResult,n=document.createElement("div");let i;n.className="dynamsoft-mrz-result-view-image-container",(null==t?void 0:t.toCanvas)&&(i=null==t?void 0:t.toCanvas()),Object.assign(i.style,{maxWidth:"100%",maxHeight:"100%",objectFit:"contain"}),n.appendChild(i),e.appendChild(n)}const t=this.createMRZDataDisplay();e.appendChild(t);const n=this.createControls();e.appendChild(n),S(this.config.container).appendChild(e)}catch(e){let t=(null==e?void 0:e.message)||e;console.error(t),alert(t)}}hideView(){S(this.config.container).style.display="none"}dispose(e=!1){S(this.config.container).textContent="",e||(this.currentScanResultViewResolver=void 0)}}const A="\n .dynamsoft-mrz-result-view-container {\n display: flex;\n width: 100%;\n height: 100%;\n background-color:#575757;\n font-size: 12px;\n flex-direction: column;\n align-items: center;\n }\n\n .dynamsoft-mrz-result-view-image-container {\n width: 100%;\n height: 200px;\n display: flex;\n justify-content: center;\n align-items: center;\n background-color: #323234;\n }\n\n \n.dynamsoft-mrz-data-container {\n font-size: 16px;\n font-family: Verdana;\n color: white;\n overflow: auto;\n width: 100%;\n height: 100%;\n min-height: 0;\n margin: 1rem 0;\n}\n\n.dynamsoft-mrz-data-row {\n padding: 0.5rem 2rem;\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n transition: background-color 0.3s ease;\n}\n\n.dynamsoft-mrz-data-row.invalid-field {\n background-color: rgba(231, 76, 60, 0.1);\n border-left: 3px solid #e74c3c;\n padding-left: calc(2rem - 3px);\n}\n\n.dynamsoft-mrz-data-label {\n color: #aaa;\n display: flex;\n gap: 0.5rem;\n align-items: end;\n flex-wrap: wrap;\n}\n\n.dynamsoft-mrz-error-notification,\n.dynamsoft-mrz-info-notification {\n color: white;\n padding: 1rem;\n margin: 0.5rem 2rem;\n border-radius: 4px;\n display: flex;\n align-items: center;\n gap: 1rem;\n text-align: start;\n}\n\n.dynamsoft-mrz-error-notification {\n background-color: rgba(231, 76, 60, 0.2);\n}\n\n.dynamsoft-mrz-info-notification {\n background-color: #fe8e14;\n}\n\n.dynamsoft-mrz-edit-icon {\n display: flex;\n align-items: center;\n justify-content: center;\n color: #aaa;\n}\n\n.dynamsoft-mrz-error-icon {\n display: flex;\n align-items: center;\n justify-content: center;\n color: #e74c3c;\n}\n\n.dynamsoft-mrz-info-icon {\n display: flex;\n align-items: center;\n justify-content: center;\n color: white;\n}\n\n.dynamsoft-mrz-info-message,\n.dynamsoft-mrz-error-message {\n flex: 1;\n}\n\n.dynamsoft-mrz-error-hint {\n font-size: 0.8rem;\n color: #e74c3c;\n}\n\n.dynamsoft-mrz-data-value {\n word-wrap: break-word;\n text-align: start;\n}\n\n.dynamsoft-mrz-data-value.code {\n font-family: monospace;\n}\n\n.dynamsoft-mrz-data-value.invalid-value {\n color: #e74c3c;\n text-decoration: wavy underline #e74c3c;\n text-decoration-skip-ink: none;\n}\n\n.dynamsoft-mrz-data-input {\n width: 100%;\n padding: 5px;\n background-color: rgba(255, 255, 255, 0.1);\n border: 1px solid rgba(255, 255, 255, 0.3);\n color: white;\n border-radius: 4px;\n font-size: 14px;\n transition: all 0.3s ease;\n}\n\n.dynamsoft-mrz-data-input.invalid {\n background-color: rgba(231, 76, 60, 0.1);\n border-color: #e74c3c;\n}\n\n.dynamsoft-mrz-data-input:focus {\n background-color: rgba(255, 255, 255, 0.2);\n border-color: #fe8e14;\n outline: none;\n}\n\n@media screen and (orientation: landscape) and (max-width: 1024px) and (max-height: 600px) {\n .dynamsoft-mrz-result-view-container {\n flex-direction: row;\n }\n\n .dynamsoft-mrz-result-view-image-container{\n flex: 1;\n height: 100%;\n }\n\n .dynamsoft-mrz-data-container{\n flex: 1;\n }\n\n .dynamsoft-mrz-data-row:first-of-type {\n padding-top: 2rem;\n }\n\n .dynamsoft-mrz-data-row:last-of-type {\n padding-bottom: 2rem;\n }\n\n .dynamsoft-mrz-data-row.empty {\n display: flex;\n align-items: center;\n justify-content: center;\n height: 100%;\n padding-top: 0;\n padding-bottom: 0;\n }\n}\n",O={rootDirectory:"https://cdn.jsdelivr.net/npm/"};class P{showLoadingOverlay(e){var t,n;const i=S(null===(t=this.config.scannerViewConfig)||void 0===t?void 0:t.container)||S(null===(n=this.config.resultViewConfig)||void 0===n?void 0:n.container);this.loadingScreen=M(i,{message:e}),i.style.display="block",i.style.position="relative"}hideLoadingOverlay(e=!1){var t,n,i;const s=S(null===(t=this.config.scannerViewConfig)||void 0===t?void 0:t.container)||S(null===(n=this.config.resultViewConfig)||void 0===n?void 0:n.container);this.loadingScreen&&(this.loadingScreen.hide(),this.loadingScreen=null,s.style.display="none",e&&(null===(i=this.config)||void 0===i?void 0:i.container)&&(S(this.config.container).style.display="none"))}constructor(e){this.config=e,this.resources={},this.isInitialized=!1,this.isCapturing=!1,this.loadingScreen=null,this.isDynamsoftResourcesLoaded=!1,this.isFileMode=!1,this.isDynamsoftResourcesLoaded||this.initializeDynamsoftResources()}async initialize(){if(this.isInitialized)return{resources:this.resources,components:{scannerView:this.scannerView,resultView:this.resultView}};try{if(!this.initializeMRZScannerConfig())return console.error("Failed to initialize mrz scanner config"),{resources:this.resources,components:{}};R("dynamsoft-mrz-loading-screen-style",T),this.showLoadingOverlay("Loading..."),await this.initializeDCVResources(),this.resources.onResultUpdated=e=>{this.resources.result=e};const e={};return!this.isFileMode&&this.config.scannerViewConfig&&(this.scannerView=new _(this.resources,this.config.scannerViewConfig),e.scannerView=this.scannerView,await this.scannerView.initialize()),this.config.resultViewConfig&&(this.resultView=new k(this.resources,this.config.resultViewConfig,this.scannerView),e.resultView=this.resultView),this.isInitialized=!0,{resources:this.resources,components:e}}catch(e){this.isInitialized=!1;const t=`Initialization Failed: ${(null==e?void 0:e.message)||e}`;throw console.error(t),new Error(t)}finally{this.hideLoadingOverlay(!0)}}initializeDynamsoftResources(){var e;l.engineResourcePaths=E(null===(e=this.config)||void 0===e?void 0:e.engineResourcePaths)?O:this.config.engineResourcePaths,l.loadWasm(),c.loadSpec("MRTD_TD3_PASSPORT"),c.loadSpec("MRTD_TD3_VISA"),c.loadSpec("MRTD_TD1_ID"),c.loadSpec("MRTD_TD2_ID"),c.loadSpec("MRTD_TD2_VISA"),this.isDynamsoftResourcesLoaded=!0}async initializeDCVResources(){var e,t,n,i;try{this.isDynamsoftResourcesLoaded||this.initializeDynamsoftResources(),d._onAuthMessage=e=>e.replace("(https://www.dynamsoft.com/customer/license/trialLicense?product=unknown&deploymenttype=unknown)","(https://www.dynamsoft.com/customer/license/trialLicense?product=mrz&deploymenttype=web)"),await d.initLicense((null===(e=this.config)||void 0===e?void 0:e.license)||"",{executeNow:!0}),this.isFileMode||(this.resources.cameraView=await h.createInstance((null===(t=this.config.scannerViewConfig)||void 0===t?void 0:t.uiPath)||(null===(n=this.config.scannerViewConfig)||void 0===n?void 0:n.cameraEnhancerUIPath)),this.resources.cameraEnhancer=await u.createInstance(this.resources.cameraView)),this.resources.cvRouter=await m.createInstance(),await this.resources.cvRouter.initSettings(this.config.templateFilePath)}catch(e){let t="string"==typeof e?e:null!==(i=null==e?void 0:e.message)&&void 0!==i?i:"object"==typeof e?JSON.stringify(e):String(e);const n=(null==t?void 0:t.toLowerCase().includes("license"))?"The MRZ Scanner license is invalid or has expired. Please contact the site administrator to resolve this issue.":`Resource Initialization Failed: ${t}`;throw console.error(n),new Error(n)}}shouldCreateDefaultContainer(){var e,t;const n=!this.config.container,i=!((null===(e=this.config.scannerViewConfig)||void 0===e?void 0:e.container)||(null===(t=this.config.resultViewConfig)||void 0===t?void 0:t.container));return n&&i}createDefaultMRZScannerContainer(){const e=document.createElement("div");return e.className="mrz-scanner-main-container",Object.assign(e.style,{height:"100dvh",width:"100%",position:"absolute",left:"0",top:"0",zIndex:"999"}),document.body.append(e),e}checkForTemporaryLicense(e){return!(null==e?void 0:e.length)||(null==e?void 0:e.startsWith("A"))||(null==e?void 0:e.startsWith("L"))||(null==e?void 0:e.startsWith("P"))||(null==e?void 0:e.startsWith("Y"))?"DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9":e}validateViewConfigs(){var e,t,n,i,s,a,o,r;if(!this.config.container){if((null===(e=this.config.scannerViewConfig)||void 0===e?void 0:e.container)&&this.config.showResultView&&!(null===(t=this.config.resultViewConfig)||void 0===t?void 0:t.container)){const e="MRZResultView container is required when showResultView is true";return alert(e),console.error(e),!1}if(!(null===(n=this.config.scannerViewConfig)||void 0===n?void 0:n.container)&&(null===(i=this.config.resultViewConfig)||void 0===i?void 0:i.container)&&!this.resources.result){const e="Result is needed to create MRZResultView without a scanner view";return alert(e),console.error(e),!1}}try{if(this.config.container&&!S(this.config.container)){const e="Invalid main container reference";return alert(e),console.error(e),!1}if((null===(s=this.config.scannerViewConfig)||void 0===s?void 0:s.container)&&!S(null===(a=this.config.scannerViewConfig)||void 0===a?void 0:a.container)){const e="Invalid scanner view container reference";return alert(e),console.error(e),!1}if((null===(o=this.config.resultViewConfig)||void 0===o?void 0:o.container)&&!S(null===(r=this.config.resultViewConfig)||void 0===r?void 0:r.container)){const e="Invalid result view container reference";return alert(e),console.error(e),!1}}catch(e){const t=`Error accessing container references: ${e.message}`;return alert(t),console.error(t),!1}return!0}showResultView(){var e,t;return!1!==this.config.showResultView&&(this.config.container?!(void 0!==this.config.showResultView||!(null===(e=this.config.resultViewConfig)||void 0===e?void 0:e.container)&&!this.config.container)||!!this.config.showResultView:this.config.showResultView&&!!(null===(t=this.config.resultViewConfig)||void 0===t?void 0:t.container))}initializeMRZScannerConfig(){var e,t,n,i,s,a,o,r;this.config=null!==(e=this.config)&&void 0!==e?e:{};if(!this.validateViewConfigs())return!1;this.shouldCreateDefaultContainer()?this.config.container=this.createDefaultMRZScannerContainer():this.config.container&&(this.config.container=S(this.config.container));const l=this.config.container?this.createViewContainers(S(this.config.container)):{},c={license:this.checkForTemporaryLicense(this.config.license),utilizedTemplateNames:Object.fromEntries(Object.values(p).map((e=>{var t;return[e,(null===(t=this.config.utilizedTemplateNames)||void 0===t?void 0:t[e])||w[e]]}))),templateFilePath:(null===(t=this.config)||void 0===t?void 0:t.templateFilePath)||"https://cdn.jsdelivr.net/npm/dynamsoft-mrz-scanner@3.0.1/dist/mrz-scanner.template.json"},d=Object.assign(Object.assign({},this.config.scannerViewConfig),{container:l[y.Scanner]||S(null===(n=this.config.scannerViewConfig)||void 0===n?void 0:n.container)||null,cameraEnhancerUIPath:(null===(i=this.config.scannerViewConfig)||void 0===i?void 0:i.uiPath)||(null===(s=this.config.scannerViewConfig)||void 0===s?void 0:s.cameraEnhancerUIPath)||"https://cdn.jsdelivr.net/npm/dynamsoft-mrz-scanner@3.0.1/dist/mrz-scanner.ui.html",templateFilePath:c.templateFilePath,utilizedTemplateNames:c.utilizedTemplateNames,enableMultiFrameCrossFilter:null===(o=null===(a=this.config.scannerViewConfig)||void 0===a?void 0:a.enableMultiFrameCrossFilter)||void 0===o||o,mrzFormatType:this.config.mrzFormatType}),h=this.showResultView()?Object.assign(Object.assign({},this.config.resultViewConfig),{_isFileMode:this.isFileMode,container:l[y.Result]||S(null===(r=this.config.resultViewConfig)||void 0===r?void 0:r.container)||null}):void 0;return Object.assign(this.config,Object.assign(Object.assign({},c),{scannerViewConfig:d,resultViewConf