h||e.sy+e.sHeight>l)throw new Error("Invalid position.");null===(r=Xn._onLog)||void 0===r||r.call(Xn,"getImageData(), START: "+(c=Date.now()));const d=Math.round(e.sx),f=Math.round(e.sy),g=Math.round(e.sWidth),m=Math.round(e.sHeight),p=Math.round(e.dWidth),_=Math.round(e.dHeight);let v,y=(null==i?void 0:i.pixelFormat)||qr.RGBA,w=null==i?void 0:i.bufferContainer;if(w&&(qr.GREY===y&&w.length{this.disposed||r.includes(n)&&n.apply(i.target,s)}),0);else try{o=n.apply(i.target,s)}catch(t){}if(!0===o)break}}}dispose(){jr(this,nn,!0,"f")}}rn=new WeakMap,nn=new WeakMap;const Zn=(t,e,i,r)=>{if(!i)return t;let n=e+Math.round((t-e)/i)*i;return r&&(n=Math.min(n,r)),n};class qn{static get version(){return"2.0.18"}static isStorageAvailable(t){let e;try{e=window[t];const i="__storage_test__";return e.setItem(i,i),e.removeItem(i),!0}catch(t){return t instanceof DOMException&&(22===t.code||1014===t.code||"QuotaExceededError"===t.name||"NS_ERROR_DOM_QUOTA_REACHED"===t.name)&&e&&0!==e.length}}static findBestRearCameraInIOS(t,e){if(!t||!t.length)return null;let i=!1;if((null==e?void 0:e.getMainCamera)&&(i=!0),i){const e=["후면 카메라","背面カメラ","後置鏡頭","后置相机","กล้องด้านหลัง","बैक कैमरा","الكاميرا الخلفية","מצלמה אחורית","камера на задней панели","задня камера","задна камера","артқы камера","πίσω κάμερα","zadní fotoaparát","zadná kamera","tylny aparat","takakamera","stražnja kamera","rückkamera","kamera på baksidan","kamera belakang","kamera bak","hátsó kamera","fotocamera (posteriore)","câmera traseira","câmara traseira","cámara trasera","càmera posterior","caméra arrière","cameră spate","camera mặt sau","camera aan achterzijde","bagsidekamera","back camera","arka kamera"],i=t.find((t=>e.includes(t.label.toLowerCase())));return null==i?void 0:i.deviceId}{const e=["후면","背面","後置","后置","านหลัง","बैक","خلفية","אחורית","задняя","задней","задна","πίσω","zadní","zadná","tylny","trasera","traseira","taka","stražnja","spate","sau","rück","posteriore","posterior","hátsó","belakang","baksidan","bakre","bak","bagside","back","aртқы","arrière","arka","achterzijde"],i=["트리플","三镜头","三鏡頭","トリプル","สาม","ट्रिपल","ثلاثية","משולשת","үштік","тройная","тройна","потроєна","τριπλή","üçlü","trójobiektywowy","trostruka","trojný","trojitá","trippelt","trippel","triplă","triple","tripla","tiga","kolmois","ba camera"],r=["듀얼 와이드","雙廣角","双广角","デュアル広角","คู่ด้านหลังมุมกว้าง","ड्युअल वाइड","مزدوجة عريضة","כפולה רחבה","қос кең бұрышты","здвоєна ширококутна","двойная широкоугольная","двойна широкоъгълна","διπλή ευρεία","çift geniş","laajakulmainen kaksois","kép rộng mặt sau","kettős, széles látószögű","grande angular dupla","ganda","dwuobiektywowy","dwikamera","dvostruka široka","duální širokoúhlý","duálna širokouhlá","dupla grande-angular","dublă","dubbel vidvinkel","dual-weitwinkel","dual wide","dual con gran angular","dual","double","doppia con grandangolo","doble","dobbelt vidvinkelkamera"],n=t.filter((t=>{const i=t.label.toLowerCase();return e.some((t=>i.includes(t)))}));if(!n.length)return null;const s=n.find((t=>{const e=t.label.toLowerCase();return i.some((t=>e.includes(t)))}));if(s)return s.deviceId;const o=n.find((t=>{const e=t.label.toLowerCase();return r.some((t=>e.includes(t)))}));return o?o.deviceId:n[0].deviceId}}static findBestRearCamera(t,e){if(!t||!t.length)return null;if(["iPhone","iPad","Mac"].includes(Hr.OS))return qn.findBestRearCameraInIOS(t,{getMainCamera:null==e?void 0:e.getMainCameraInIOS});const i=["후","背面","背置","後面","後置","后面","后置","านหลัง","หลัง","बैक","خلفية","אחורית","задняя","задня","задней","задна","πίσω","zadní","zadná","tylny","trás","trasera","traseira","taka","stražnja","spate","sau","rück","rear","posteriore","posterior","hátsó","darrere","belakang","baksidan","bakre","bak","bagside","back","aртқы","arrière","arka","achterzijde"];for(let e of t){const t=e.label.toLowerCase();if(t&&i.some((e=>t.includes(e)))&&/\b0(\b)?/.test(t))return e.deviceId}return["Android","HarmonyOS"].includes(Hr.OS)?t[t.length-1].deviceId:null}static findBestCamera(t,e,i){return t&&t.length?"environment"===e?this.findBestRearCamera(t,i):"user"===e?null:e?void 0:null:null}static async playVideo(t,e,i){if(!t)throw new Error("Invalid 'videoEl'.");if(!e)throw new Error("Invalid 'source'.");return new Promise((async(r,n)=>{let s;const o=()=>{t.removeEventListener("loadstart",c),t.removeEventListener("abort",u),t.removeEventListener("play",d),t.removeEventListener("error",f),t.removeEventListener("loadedmetadata",p)};let a=!1;const h=()=>{a=!0,s&&clearTimeout(s),o(),r(t)},l=t=>{s&&clearTimeout(s),o(),n(t)},c=()=>{t.addEventListener("abort",u,{once:!0})},u=()=>{const t=new Error("Video playing was interrupted.");t.name="AbortError",l(t)},d=()=>{h()},f=()=>{l(new Error(`Video error ${t.error.code}: ${t.error.message}.`))};let g;const m=new Promise((t=>{g=t})),p=()=>{g()};if(t.addEventListener("loadstart",c,{once:!0}),t.addEventListener("play",d,{once:!0}),t.addEventListener("error",f,{once:!0}),t.addEventListener("loadedmetadata",p,{once:!0}),"string"==typeof e||e instanceof String?t.src=e:t.srcObject=e,t.autoplay&&await new Promise((t=>{setTimeout(t,1e3)})),!a){i&&(s=setTimeout((()=>{o(),n(new Error("Failed to play video. Timeout."))}),i)),await m;try{await t.play(),h()}catch(t){console.warn("1st play error: "+((null==t?void 0:t.message)||t))}if(!a)try{await t.play(),h()}catch(t){console.warn("2rd play error: "+((null==t?void 0:t.message)||t)),l(t)}}}))}static async testCameraAccess(t){var e,i;if(!(null===(i=null===(e=null===window||void 0===window?void 0:window.navigator)||void 0===e?void 0:e.mediaDevices)||void 0===i?void 0:i.getUserMedia))return{ok:!1,errorName:"InsecureContext",errorMessage:"Insecure context."};let r;try{r=t?await navigator.mediaDevices.getUserMedia(t):await navigator.mediaDevices.getUserMedia({video:!0})}catch(t){return{ok:!1,errorName:t.name,errorMessage:t.message}}finally{null==r||r.getTracks().forEach((t=>{t.stop()}))}return{ok:!0}}get state(){if(!Nr(this,vn,"f"))return"closed";if("pending"===Nr(this,vn,"f"))return"opening";if("fulfilled"===Nr(this,vn,"f"))return"opened";throw new Error("Unknown state.")}set ifSaveLastUsedCamera(t){t?qn.isStorageAvailable("localStorage")?jr(this,gn,!0,"f"):(jr(this,gn,!1,"f"),console.warn("Local storage is unavailable")):jr(this,gn,!1,"f")}get ifSaveLastUsedCamera(){return Nr(this,gn,"f")}get isVideoPlaying(){return!(!Nr(this,an,"f")||Nr(this,an,"f").paused)&&"opened"===this.state}set tapFocusEventBoundEl(t){var e,i,r;if(!(t instanceof HTMLElement)&&null!=t)throw new TypeError("Invalid 'element'.");null===(e=Nr(this,Sn,"f"))||void 0===e||e.removeEventListener("click",Nr(this,Tn,"f")),null===(i=Nr(this,Sn,"f"))||void 0===i||i.removeEventListener("touchend",Nr(this,Tn,"f")),null===(r=Nr(this,Sn,"f"))||void 0===r||r.removeEventListener("touchmove",Nr(this,En,"f")),jr(this,Sn,t,"f"),t&&(window.TouchEvent&&["Android","HarmonyOS","iPhone","iPad"].includes(Hr.OS)?(t.addEventListener("touchend",Nr(this,Tn,"f")),t.addEventListener("touchmove",Nr(this,En,"f"))):t.addEventListener("click",Nr(this,Tn,"f")))}get tapFocusEventBoundEl(){return Nr(this,Sn,"f")}get disposed(){return Nr(this,Mn,"f")}constructor(t){var e,i;on.add(this),an.set(this,null),hn.set(this,void 0),ln.set(this,(()=>{"opened"===this.state&&Nr(this,An,"f").fire("resumed",null,{target:this,async:!1})})),cn.set(this,(()=>{Nr(this,An,"f").fire("paused",null,{target:this,async:!1})})),un.set(this,void 0),dn.set(this,void 0),this.cameraOpenTimeout=15e3,this._arrCameras=[],fn.set(this,void 0),gn.set(this,!1),this.ifSkipCameraInspection=!1,this.selectIOSRearMainCameraAsDefault=!1,mn.set(this,void 0),pn.set(this,!0),_n.set(this,void 0),vn.set(this,void 0),yn.set(this,!1),this._focusParameters={maxTimeout:400,minTimeout:300,kTimeout:void 0,oldDistance:null,fds:null,isDoingFocus:0,taskBackToContinous:null,curFocusTaskId:0,focusCancelableTime:1500,defaultFocusAreaSizeRatio:6,focusBackToContinousTime:5e3,tapFocusMinDistance:null,tapFocusMaxDistance:null,focusArea:null,tempBufferContainer:null,defaultTempBufferContainerLenRatio:1/4},wn.set(this,!1),this._focusSupported=!0,this.calculateCoordInVideo=(t,e)=>{let i,r;const n=window.getComputedStyle(Nr(this,an,"f")).objectFit,s=this.getResolution(),o=Nr(this,an,"f").getBoundingClientRect(),a=o.left,h=o.top,{width:l,height:c}=Nr(this,an,"f").getBoundingClientRect();if(l<=0||c<=0)throw new Error("Unable to get video dimensions. Video may not be rendered on the page.");const u=l/c,d=s.width/s.height;let f=1;if("contain"===n)d>u?(f=l/s.width,i=(t-a)/f,r=(e-h-(c-l/d)/2)/f):(f=c/s.height,r=(e-h)/f,i=(t-a-(l-c*d)/2)/f);else{if("cover"!==n)throw new Error("Unsupported object-fit.");d>u?(f=c/s.height,r=(e-h)/f,i=(t-a+(c*d-l)/2)/f):(f=l/s.width,i=(t-a)/f,r=(e-h+(l/d-c)/2)/f)}return{x:i,y:r}},Cn.set(this,!1),En.set(this,(()=>{jr(this,Cn,!0,"f")})),Tn.set(this,(async t=>{var e;if(Nr(this,Cn,"f"))return void jr(this,Cn,!1,"f");if(!Nr(this,wn,"f"))return;if(!this.isVideoPlaying)return;if(!Nr(this,hn,"f"))return;if(!this._focusSupported)return;if(!this._focusParameters.fds&&(this._focusParameters.fds=null===(e=this.getCameraCapabilities())||void 0===e?void 0:e.focusDistance,!this._focusParameters.fds))return void(this._focusSupported=!1);if(null==this._focusParameters.kTimeout&&(this._focusParameters.kTimeout=(this._focusParameters.maxTimeout-this._focusParameters.minTimeout)/(1/this._focusParameters.fds.min-1/this._focusParameters.fds.max)),1==this._focusParameters.isDoingFocus)return;let i,r;if(this._focusParameters.taskBackToContinous&&(clearTimeout(this._focusParameters.taskBackToContinous),this._focusParameters.taskBackToContinous=null),t instanceof MouseEvent)i=t.clientX,r=t.clientY;else{if(!(t instanceof TouchEvent))throw new Error("Unknown event type.");if(!t.changedTouches.length)return;i=t.changedTouches[0].clientX,r=t.changedTouches[0].clientY}const n=this.getResolution(),s=2*Math.round(Math.min(n.width,n.height)/this._focusParameters.defaultFocusAreaSizeRatio/2);let o;try{o=this.calculateCoordInVideo(i,r)}catch(t){}if(o.x<0||o.x>n.width||o.y<0||o.y>n.height)return;const a={x:o.x+"px",y:o.y+"px"},h=s+"px",l=h;let c;qn._onLog&&(c=Date.now());try{await Nr(this,on,"m",Wn).call(this,a,h,l,this._focusParameters.tapFocusMinDistance,this._focusParameters.tapFocusMaxDistance)}catch(t){if(qn._onLog)throw qn._onLog(t),t}qn._onLog&&qn._onLog(`Tap focus costs: ${Date.now()-c} ms`),this._focusParameters.taskBackToContinous=setTimeout((()=>{var t;qn._onLog&&qn._onLog("Back to continuous focus."),null===(t=Nr(this,hn,"f"))||void 0===t||t.applyConstraints({advanced:[{focusMode:"continuous"}]}).catch((()=>{}))}),this._focusParameters.focusBackToContinousTime),Nr(this,An,"f").fire("tapfocus",null,{target:this,async:!1})})),Sn.set(this,null),bn.set(this,1),In.set(this,{x:0,y:0}),this.updateVideoElWhenSoftwareScaled=()=>{if(!Nr(this,an,"f"))return;const t=Nr(this,bn,"f");if(t<1)throw new RangeError("Invalid scale value.");if(1===t)Nr(this,an,"f").style.transform="";else{const e=window.getComputedStyle(Nr(this,an,"f")).objectFit,i=Nr(this,an,"f").videoWidth,r=Nr(this,an,"f").videoHeight,{width:n,height:s}=Nr(this,an,"f").getBoundingClientRect();if(n<=0||s<=0)throw new Error("Unable to get video dimensions. Video may not be rendered on the page.");const o=n/s,a=i/r;let h=1;"contain"===e?h=oo?s/(i/t):n/(r/t));const l=h*(1-1/t)*(i/2-Nr(this,In,"f").x),c=h*(1-1/t)*(r/2-Nr(this,In,"f").y);Nr(this,an,"f").style.transform=`translate(${l}px, ${c}px) scale(${t})`}},xn.set(this,(function(){if(!(this.data instanceof Uint8Array||this.data instanceof Uint8ClampedArray))throw new TypeError("Invalid data.");if("number"!=typeof this.width||this.width<=0)throw new Error("Invalid width.");if("number"!=typeof this.height||this.height<=0)throw new Error("Invalid height.");const t=document.createElement("canvas");let e;if(t.width=this.width,t.height=this.height,this.pixelFormat===qr.GREY){e=new Uint8ClampedArray(this.width*this.height*4);for(let t=0;t{var t,e;if("visible"===document.visibilityState){if(qn._onLog&&qn._onLog("document visible. video paused: "+(null===(t=Nr(this,an,"f"))||void 0===t?void 0:t.paused)),"opening"==this.state||"opened"==this.state){let e=!1;if(!this.isVideoPlaying){qn._onLog&&qn._onLog("document visible. Not auto resume. 1st resume start.");try{await this.resume(),e=!0}catch(t){qn._onLog&&qn._onLog("document visible. 1st resume video failed, try open instead.")}e||await Nr(this,on,"m",Nn).call(this)}if(await new Promise((t=>setTimeout(t,300))),!this.isVideoPlaying){qn._onLog&&qn._onLog("document visible. 1st open failed. 2rd resume start."),e=!1;try{await this.resume(),e=!0}catch(t){qn._onLog&&qn._onLog("document visible. 2rd resume video failed, try open instead.")}e||await Nr(this,on,"m",Nn).call(this)}}}else"hidden"===document.visibilityState&&(qn._onLog&&qn._onLog("document hidden. video paused: "+(null===(e=Nr(this,an,"f"))||void 0===e?void 0:e.paused)),"opening"==this.state||"opened"==this.state&&this.isVideoPlaying&&this.pause())})),Mn.set(this,!1),(null===(i=null===(e=null===window||void 0===window?void 0:window.navigator)||void 0===e?void 0:e.mediaDevices)||void 0===i?void 0:i.getUserMedia)||setTimeout((()=>{qn.onWarning&&qn.onWarning("The browser is too old or the page is loaded from an insecure origin.")}),0),this.defaultConstraints={video:{facingMode:{ideal:"environment"}}},this.resetMediaStreamConstraints(),t instanceof HTMLVideoElement&&this.setVideoEl(t),jr(this,An,new zn,"f"),this.imageDataGetter=new Xn,document.addEventListener("visibilitychange",Nr(this,Ln,"f"))}setVideoEl(t){if(!(t&&t instanceof HTMLVideoElement))throw new Error("Invalid 'videoEl'.");t.addEventListener("play",Nr(this,ln,"f")),t.addEventListener("pause",Nr(this,cn,"f")),jr(this,an,t,"f")}getVideoEl(){return Nr(this,an,"f")}releaseVideoEl(){var t,e;null===(t=Nr(this,an,"f"))||void 0===t||t.removeEventListener("play",Nr(this,ln,"f")),null===(e=Nr(this,an,"f"))||void 0===e||e.removeEventListener("pause",Nr(this,cn,"f")),jr(this,an,null,"f")}isVideoLoaded(){return!!Nr(this,an,"f")&&4==Nr(this,an,"f").readyState}async open(){if(Nr(this,_n,"f")&&!Nr(this,pn,"f")){if("pending"===Nr(this,vn,"f"))return Nr(this,_n,"f");if("fulfilled"===Nr(this,vn,"f"))return}Nr(this,An,"f").fire("before:open",null,{target:this}),await Nr(this,on,"m",Nn).call(this),Nr(this,An,"f").fire("played",null,{target:this,async:!1}),Nr(this,An,"f").fire("opened",null,{target:this,async:!1})}async close(){if("closed"===this.state)return;Nr(this,An,"f").fire("before:close",null,{target:this});const t=Nr(this,_n,"f");if(Nr(this,on,"m",Un).call(this),t&&"pending"===Nr(this,vn,"f")){try{await t}catch(t){}if(!1===Nr(this,pn,"f")){const t=new Error("'close()' was interrupted.");throw t.name="AbortError",t}}jr(this,_n,null,"f"),jr(this,vn,null,"f"),Nr(this,An,"f").fire("closed",null,{target:this,async:!1})}pause(){if(!this.isVideoLoaded())throw new Error("Video is not loaded.");if("opened"!==this.state)throw new Error("Camera or video is not open.");Nr(this,an,"f").pause()}async resume(){if(!this.isVideoLoaded())throw new Error("Video is not loaded.");if("opened"!==this.state)throw new Error("Camera or video is not open.");await Nr(this,an,"f").play()}async setCamera(t){if("string"!=typeof t)throw new TypeError("Invalid 'deviceId'.");if("object"!=typeof Nr(this,un,"f").video&&(Nr(this,un,"f").video={}),delete Nr(this,un,"f").video.facingMode,Nr(this,un,"f").video.deviceId={exact:t},!("closed"===this.state||this.videoSrc||"opening"===this.state&&Nr(this,pn,"f"))){Nr(this,An,"f").fire("before:camera:change",[],{target:this,async:!1}),await Nr(this,on,"m",jn).call(this);try{this.resetSoftwareScale()}catch(t){}return Nr(this,dn,"f")}}async switchToFrontCamera(t){if("object"!=typeof Nr(this,un,"f").video&&(Nr(this,un,"f").video={}),(null==t?void 0:t.resolution)&&(Nr(this,un,"f").video.width={ideal:t.resolution.width},Nr(this,un,"f").video.height={ideal:t.resolution.height}),delete Nr(this,un,"f").video.deviceId,Nr(this,un,"f").video.facingMode={exact:"user"},jr(this,fn,null,"f"),!("closed"===this.state||this.videoSrc||"opening"===this.state&&Nr(this,pn,"f"))){Nr(this,An,"f").fire("before:camera:change",[],{target:this,async:!1}),Nr(this,on,"m",jn).call(this);try{this.resetSoftwareScale()}catch(t){}return Nr(this,dn,"f")}}getCamera(){var t;if(Nr(this,dn,"f"))return Nr(this,dn,"f");{let e=(null===(t=Nr(this,un,"f").video)||void 0===t?void 0:t.deviceId)||"";if(e){e=e.exact||e.ideal||e;for(let t of this._arrCameras)if(t.deviceId===e)return JSON.parse(JSON.stringify(t))}return{deviceId:"",label:"",_checked:!1}}}async _getCameras(t){var e,i;if(!(null===(i=null===(e=null===window||void 0===window?void 0:window.navigator)||void 0===e?void 0:e.mediaDevices)||void 0===i?void 0:i.getUserMedia))throw new Error("Failed to access the camera because the browser is too old or the page is loaded from an insecure origin.");let r;if(t){let t=await navigator.mediaDevices.getUserMedia({video:!0});r=(await navigator.mediaDevices.enumerateDevices()).filter((t=>"videoinput"===t.kind)),t.getTracks().forEach((t=>{t.stop()}))}else r=(await navigator.mediaDevices.enumerateDevices()).filter((t=>"videoinput"===t.kind));const n=[],s=[];if(this._arrCameras)for(let t of this._arrCameras)t._checked&&s.push(t);for(let t=0;t"videoinput"===t.kind));return i&&i.length&&!i[0].deviceId?this._getCameras(!0):this._getCameras(!1)}async getAllCameras(){return this.getCameras()}async setResolution(t,e,i){if("number"!=typeof t||t<=0)throw new TypeError("Invalid 'width'.");if("number"!=typeof e||e<=0)throw new TypeError("Invalid 'height'.");if("object"!=typeof Nr(this,un,"f").video&&(Nr(this,un,"f").video={}),i?(Nr(this,un,"f").video.width={exact:t},Nr(this,un,"f").video.height={exact:e}):(Nr(this,un,"f").video.width={ideal:t},Nr(this,un,"f").video.height={ideal:e}),"closed"===this.state||this.videoSrc||"opening"===this.state&&Nr(this,pn,"f"))return null;Nr(this,An,"f").fire("before:resolution:change",[],{target:this,async:!1}),await Nr(this,on,"m",jn).call(this);try{this.resetSoftwareScale()}catch(t){}const r=this.getResolution();return{width:r.width,height:r.height}}getResolution(){if("opened"===this.state&&this.videoSrc&&Nr(this,an,"f"))return{width:Nr(this,an,"f").videoWidth,height:Nr(this,an,"f").videoHeight};if(Nr(this,hn,"f")){const t=Nr(this,hn,"f").getSettings();return{width:t.width,height:t.height}}if(this.isVideoLoaded())return{width:Nr(this,an,"f").videoWidth,height:Nr(this,an,"f").videoHeight};{const t={width:0,height:0};let e=Nr(this,un,"f").video.width||0,i=Nr(this,un,"f").video.height||0;return e&&(t.width=e.exact||e.ideal||e),i&&(t.height=i.exact||i.ideal||i),t}}async getResolutions(t){var e,i,r,n,s,o,a,h,l,c,u;if(!(null===(i=null===(e=null===window||void 0===window?void 0:window.navigator)||void 0===e?void 0:e.mediaDevices)||void 0===i?void 0:i.getUserMedia))throw new Error("Failed to access the camera because the browser is too old or the page is loaded from an insecure origin.");let d="";const f=(t,e)=>{const i=Nr(this,Rn,"f").get(t);if(!i||!i.length)return!1;for(let t of i)if(t.width===e.width&&t.height===e.height)return!0;return!1};if(this._mediaStream){d=null===(u=Nr(this,dn,"f"))||void 0===u?void 0:u.deviceId;let e=Nr(this,Rn,"f").get(d);if(e&&!t)return JSON.parse(JSON.stringify(e));e=[],Nr(this,Rn,"f").set(d,e),jr(this,yn,!0,"f");try{for(let t of this.detectedResolutions){await Nr(this,hn,"f").applyConstraints({width:{ideal:t.width},height:{ideal:t.height}}),Nr(this,on,"m",Pn).call(this);const i=Nr(this,hn,"f").getSettings(),r={width:i.width,height:i.height};f(d,r)||e.push({width:r.width,height:r.height})}}catch(t){throw Nr(this,on,"m",Un).call(this),jr(this,yn,!1,"f"),t}try{await Nr(this,on,"m",Nn).call(this)}catch(t){if("AbortError"===t.name)return e;throw t}finally{jr(this,yn,!1,"f")}return e}{const e=async(t,e,i)=>{const r={video:{deviceId:{exact:t},width:{ideal:e},height:{ideal:i}}};let n=null;try{n=await navigator.mediaDevices.getUserMedia(r)}catch(t){return null}if(!n)return null;const s=n.getVideoTracks();let o=null;try{const t=s[0].getSettings();o={width:t.width,height:t.height}}catch(t){const e=document.createElement("video");e.srcObject=n,o={width:e.videoWidth,height:e.videoHeight},e.srcObject=null}return s.forEach((t=>{t.stop()})),o};let i=(null===(s=null===(n=null===(r=Nr(this,un,"f"))||void 0===r?void 0:r.video)||void 0===n?void 0:n.deviceId)||void 0===s?void 0:s.exact)||(null===(h=null===(a=null===(o=Nr(this,un,"f"))||void 0===o?void 0:o.video)||void 0===a?void 0:a.deviceId)||void 0===h?void 0:h.ideal)||(null===(c=null===(l=Nr(this,un,"f"))||void 0===l?void 0:l.video)||void 0===c?void 0:c.deviceId);if(!i)return[];let u=Nr(this,Rn,"f").get(i);if(u&&!t)return JSON.parse(JSON.stringify(u));u=[],Nr(this,Rn,"f").set(i,u);for(let t of this.detectedResolutions){const r=await e(i,t.width,t.height);r&&!f(i,r)&&u.push({width:r.width,height:r.height})}return u}}async setMediaStreamConstraints(t,e){if(!(t=>{return null!==t&&"[object Object]"===(e=t,Object.prototype.toString.call(e));var e})(t))throw new TypeError("Invalid 'mediaStreamConstraints'.");jr(this,un,JSON.parse(JSON.stringify(t)),"f"),jr(this,fn,null,"f"),e&&Nr(this,on,"m",jn).call(this)}getMediaStreamConstraints(){return JSON.parse(JSON.stringify(Nr(this,un,"f")))}resetMediaStreamConstraints(){jr(this,un,this.defaultConstraints?JSON.parse(JSON.stringify(this.defaultConstraints)):null,"f")}getCameraCapabilities(){if(!Nr(this,hn,"f")||"opened"!==this.state)throw new Error("Camera is not open.");return Nr(this,hn,"f").getCapabilities?Nr(this,hn,"f").getCapabilities():{}}getCameraSettings(){if(!Nr(this,hn,"f")||"opened"!==this.state)throw new Error("Camera is not open.");return Nr(this,hn,"f").getSettings()}async turnOnTorch(){if(!Nr(this,hn,"f")||"opened"!==this.state)throw new Error("Camera is not open.");const t=this.getCameraCapabilities();if(!(null==t?void 0:t.torch))throw Error("Not supported.");await Nr(this,hn,"f").applyConstraints({advanced:[{torch:!0}]})}async turnOffTorch(){if(!Nr(this,hn,"f")||"opened"!==this.state)throw new Error("Camera is not open.");const t=this.getCameraCapabilities();if(!(null==t?void 0:t.torch))throw Error("Not supported.");await Nr(this,hn,"f").applyConstraints({advanced:[{torch:!1}]})}async setColorTemperature(t,e){var i;if("number"!=typeof t)throw new TypeError("Invalid 'value'.");if(!Nr(this,hn,"f")||"opened"!==this.state)throw new Error("Camera is not open.");const r=null===(i=this.getCameraCapabilities())||void 0===i?void 0:i.colorTemperature;if(!r)throw Error("Not supported.");return e&&(tr.max&&(t=r.max),t=Zn(t,r.min,r.step,r.max)),await Nr(this,hn,"f").applyConstraints({advanced:[{colorTemperature:t,whiteBalanceMode:"manual"}]}),t}getColorTemperature(){return this.getCameraSettings().colorTemperature||0}async setExposureCompensation(t,e){var i;if("number"!=typeof t)throw new TypeError("Invalid 'value'.");if(!Nr(this,hn,"f")||"opened"!==this.state)throw new Error("Camera is not open.");const r=null===(i=this.getCameraCapabilities())||void 0===i?void 0:i.exposureCompensation;if(!r)throw Error("Not supported.");return e&&(tr.max&&(t=r.max),t=Zn(t,r.min,r.step,r.max)),await Nr(this,hn,"f").applyConstraints({advanced:[{exposureCompensation:t}]}),t}getExposureCompensation(){return this.getCameraSettings().exposureCompensation||0}async setFrameRate(t,e){var i;if("number"!=typeof t)throw new TypeError("Invalid 'value'.");if(!Nr(this,hn,"f")||"opened"!==this.state)throw new Error("Camera is not open.");let r=null===(i=this.getCameraCapabilities())||void 0===i?void 0:i.frameRate;if(!r)throw Error("Not supported.");e&&(tr.max&&(t=r.max));const n=this.getResolution();return await Nr(this,hn,"f").applyConstraints({width:{ideal:Math.max(n.width,n.height)},frameRate:t}),t}getFrameRate(){return this.getCameraSettings().frameRate}async setFocus(t,e){if("object"!=typeof t||Array.isArray(t)||null==t)throw new TypeError("Invalid 'settings'.");if(!Nr(this,hn,"f")||"opened"!==this.state)throw new Error("Camera is not open.");const i=this.getCameraCapabilities(),r=null==i?void 0:i.focusMode,n=null==i?void 0:i.focusDistance;if(!r)throw Error("Not supported.");if("string"!=typeof t.mode)throw TypeError("Invalid 'mode'.");const s=t.mode.toLowerCase();if(!r.includes(s))throw Error("Unsupported focus mode.");if("manual"===s){if(!n)throw Error("Manual focus unsupported.");if(t.hasOwnProperty("distance")){let i=t.distance;e&&(in.max&&(i=n.max),i=Zn(i,n.min,n.step,n.max)),this._focusParameters.focusArea=null,await Nr(this,hn,"f").applyConstraints({advanced:[{focusMode:s,focusDistance:i}]})}else{if(!t.area)throw new Error("'distance' or 'area' should be specified in 'manual' mode.");{const e=t.area.centerPoint;let i=t.area.width,r=t.area.height;if(!i||!r){const t=this.getResolution();i||(i=2*Math.round(Math.min(t.width,t.height)/this._focusParameters.defaultFocusAreaSizeRatio/2)+"px"),r||(r=2*Math.round(Math.min(t.width,t.height)/this._focusParameters.defaultFocusAreaSizeRatio/2)+"px")}this._focusParameters.focusArea={centerPoint:{x:e.x,y:e.y},width:i,height:r},await Nr(this,on,"m",Wn).call(this,e,i,r)}}}else this._focusParameters.focusArea=null,await Nr(this,hn,"f").applyConstraints({advanced:[{focusMode:s}]})}getFocus(){const t=this.getCameraSettings(),e=t.focusMode;return e?"manual"===e?this._focusParameters.focusArea?{mode:"manual",area:JSON.parse(JSON.stringify(this._focusParameters.focusArea))}:{mode:"manual",distance:t.focusDistance}:{mode:e}:null}async enableTapToFocus(){jr(this,wn,!0,"f")}disableTapToFocus(){jr(this,wn,!1,"f")}isTapToFocusEnabled(){return Nr(this,wn,"f")}async setZoom(t){if("object"!=typeof t||Array.isArray(t)||null==t)throw new TypeError("Invalid 'settings'.");if("number"!=typeof t.factor)throw new TypeError("Illegal type of 'factor'.");if(t.factor<1)throw new RangeError("Invalid 'factor'.");if("opened"!==this.state)throw new Error("Video is not playing.");t.centerPoint?Nr(this,on,"m",Yn).call(this,t.centerPoint):this.resetScaleCenter();try{if(Nr(this,on,"m",Hn).call(this,Nr(this,In,"f"))){const e=await this.setHardwareScale(t.factor,!0);let i=this.getHardwareScale();1==i&&1!=e&&(i=e),t.factor>i?this.setSoftwareScale(t.factor/i):this.setSoftwareScale(1)}else await this.setHardwareScale(1),this.setSoftwareScale(t.factor)}catch(e){const i=e.message||e;if("Not supported."!==i&&"Camera is not open."!==i)throw e;this.setSoftwareScale(t.factor)}}getZoom(){if("opened"!==this.state)throw new Error("Video is not playing.");let t=1;try{t=this.getHardwareScale()}catch(t){if("Camera is not open."!==(t.message||t))throw t}return{factor:t*Nr(this,bn,"f")}}async resetZoom(){await this.setZoom({factor:1})}async setHardwareScale(t,e){var i;if("number"!=typeof t)throw new TypeError("Invalid 'value'.");if(t<1)throw new RangeError("Invalid 'value'.");if(!Nr(this,hn,"f")||"opened"!==this.state)throw new Error("Camera is not open.");const r=null===(i=this.getCameraCapabilities())||void 0===i?void 0:i.zoom;if(!r)throw Error("Not supported.");return e&&(tr.max&&(t=r.max),t=Zn(t,r.min,r.step,r.max)),await Nr(this,hn,"f").applyConstraints({advanced:[{zoom:t}]}),t}getHardwareScale(){return this.getCameraSettings().zoom||1}setSoftwareScale(t,e){if("number"!=typeof t)throw new TypeError("Invalid 'value'.");if(t<1)throw new RangeError("Invalid 'value'.");if("opened"!==this.state)throw new Error("Video is not playing.");e&&Nr(this,on,"m",Yn).call(this,e),jr(this,bn,t,"f"),this.updateVideoElWhenSoftwareScaled()}getSoftwareScale(){return Nr(this,bn,"f")}resetScaleCenter(){if("opened"!==this.state)throw new Error("Video is not playing.");const t=this.getResolution();jr(this,In,{x:t.width/2,y:t.height/2},"f")}resetSoftwareScale(){this.setSoftwareScale(1),this.resetScaleCenter()}getFrameData(t){if(this.disposed)throw Error("The 'Camera' instance has been disposed.");if(!this.isVideoLoaded())return null;if(Nr(this,yn,"f"))return null;const e=Date.now();qn._onLog&&qn._onLog("getFrameData() START: "+e);const i=Nr(this,an,"f").videoWidth,r=Nr(this,an,"f").videoHeight;let n={sx:0,sy:0,sWidth:i,sHeight:r,dWidth:i,dHeight:r};(null==t?void 0:t.position)&&(n=JSON.parse(JSON.stringify(t.position)));let s=qr.RGBA;(null==t?void 0:t.pixelFormat)&&(s=t.pixelFormat);let o=Nr(this,bn,"f");(null==t?void 0:t.scale)&&(o=t.scale);let a=Nr(this,In,"f");if(null==t?void 0:t.scaleCenter){if("string"!=typeof t.scaleCenter.x||"string"!=typeof t.scaleCenter.y)throw new Error("Invalid scale center.");let e=0,n=0;if(t.scaleCenter.x.endsWith("px"))e=parseFloat(t.scaleCenter.x);else{if(!t.scaleCenter.x.endsWith("%"))throw new Error("Invalid scale center.");e=parseFloat(t.scaleCenter.x)/100*i}if(t.scaleCenter.y.endsWith("px"))n=parseFloat(t.scaleCenter.y);else{if(!t.scaleCenter.y.endsWith("%"))throw new Error("Invalid scale center.");n=parseFloat(t.scaleCenter.y)/100*r}if(isNaN(e)||isNaN(n))throw new Error("Invalid scale center.");a.x=Math.round(e),a.y=Math.round(n)}let h=null;if((null==t?void 0:t.bufferContainer)&&(h=t.bufferContainer),0==i||0==r)return null;1!==o&&(n.sWidth=Math.round(n.sWidth/o),n.sHeight=Math.round(n.sHeight/o),n.sx=Math.round((1-1/o)*a.x+n.sx/o),n.sy=Math.round((1-1/o)*a.y+n.sy/o));const l=this.imageDataGetter.getImageData(Nr(this,an,"f"),n,{pixelFormat:s,bufferContainer:h});if(!l)return null;const c=Date.now();return qn._onLog&&qn._onLog("getFrameData() END: "+c),{data:l.data,width:l.width,height:l.height,pixelFormat:l.pixelFormat,timeSpent:c-e,timeStamp:c,toCanvas:Nr(this,xn,"f")}}on(t,e){if(!Nr(this,On,"f").includes(t.toLowerCase()))throw new Error(`Event '${t}' does not exist.`);Nr(this,An,"f").on(t,e)}off(t,e){Nr(this,An,"f").off(t,e)}async dispose(){this.tapFocusEventBoundEl=null,await this.close(),this.releaseVideoEl(),Nr(this,An,"f").dispose(),this.imageDataGetter.dispose(),document.removeEventListener("visibilitychange",Nr(this,Ln,"f")),jr(this,Mn,!0,"f")}}var Kn,Jn,Qn,$n,ts,es,is,rs,ns,ss,os,as,hs,ls,cs,us,ds,fs,gs,ms,ps,_s,vs,ys,ws,Cs,Es,Ts,Ss,bs,Is,xs,As,Os,Rs;an=new WeakMap,hn=new WeakMap,ln=new WeakMap,cn=new WeakMap,un=new WeakMap,dn=new WeakMap,fn=new WeakMap,gn=new WeakMap,mn=new WeakMap,pn=new WeakMap,_n=new WeakMap,vn=new WeakMap,yn=new WeakMap,wn=new WeakMap,Cn=new WeakMap,En=new WeakMap,Tn=new WeakMap,Sn=new WeakMap,bn=new WeakMap,In=new WeakMap,xn=new WeakMap,An=new WeakMap,On=new WeakMap,Rn=new WeakMap,Dn=new WeakMap,Ln=new WeakMap,Mn=new WeakMap,on=new WeakSet,Fn=async function(){const t=this.getMediaStreamConstraints();if("boolean"==typeof t.video&&(t.video={}),t.video.deviceId);else if(Nr(this,fn,"f"))delete t.video.facingMode,t.video.deviceId={exact:Nr(this,fn,"f")};else if(this.ifSaveLastUsedCamera&&qn.isStorageAvailable&&window.localStorage.getItem("dce_last_camera_id")){delete t.video.facingMode,t.video.deviceId={ideal:window.localStorage.getItem("dce_last_camera_id")};const e=JSON.parse(window.localStorage.getItem("dce_last_apply_width")),i=JSON.parse(window.localStorage.getItem("dce_last_apply_height"));e&&i&&(t.video.width=e,t.video.height=i)}else if(this.ifSkipCameraInspection);else{const e=async t=>{let e=null;return"environment"===t&&["Android","HarmonyOS","iPhone","iPad"].includes(Hr.OS)?(await this._getCameras(!1),Nr(this,on,"m",Pn).call(this),e=qn.findBestCamera(this._arrCameras,"environment",{getMainCameraInIOS:this.selectIOSRearMainCameraAsDefault})):t||["Android","HarmonyOS","iPhone","iPad"].includes(Hr.OS)||(await this._getCameras(!1),Nr(this,on,"m",Pn).call(this),e=qn.findBestCamera(this._arrCameras,null,{getMainCameraInIOS:this.selectIOSRearMainCameraAsDefault})),e};let i=t.video.facingMode;i instanceof Array&&i.length&&(i=i[0]),"object"==typeof i&&(i=i.exact||i.ideal);const r=await e(i);r&&(delete t.video.facingMode,t.video.deviceId={exact:r})}return t},Pn=function(){if(Nr(this,pn,"f")){const t=new Error("The operation was interrupted.");throw t.name="AbortError",t}},kn=async function(t){var e,i;if(!(null===(i=null===(e=null===window||void 0===window?void 0:window.navigator)||void 0===e?void 0:e.mediaDevices)||void 0===i?void 0:i.getUserMedia))throw new Error("Failed to access the camera because the browser is too old or the page is loaded from an insecure origin.");let r;try{qn._onLog&&qn._onLog("======try getUserMedia========");let e=[0,500,1e3,2e3],i=null;const n=async t=>{for(let n of e){n&&(await new Promise((t=>setTimeout(t,n))),Nr(this,on,"m",Pn).call(this));try{qn._onLog&&qn._onLog("ask "+JSON.stringify(t)),r=await navigator.mediaDevices.getUserMedia(t),Nr(this,on,"m",Pn).call(this);break}catch(t){if("NotFoundError"===t.name||"NotAllowedError"===t.name||"AbortError"===t.name||"OverconstrainedError"===t.name)throw t;i=t,qn._onLog&&qn._onLog(t.message||t)}}};if(await n(t),r||"object"!=typeof t.video||(t.video.deviceId&&(delete t.video.deviceId,await n(t)),!r&&t.video.facingMode&&(delete t.video.facingMode,await n(t)),r||!t.video.width&&!t.video.height||(delete t.video.width,delete t.video.height,await n(t))),!r)throw i;return r}catch(t){throw null==r||r.getTracks().forEach((t=>{t.stop()})),"NotFoundError"===t.name&&(DOMException?t=new DOMException("No camera available, please use a device with an accessible camera.",t.name):(t=new Error("No camera available, please use a device with an accessible camera.")).name="NotFoundError"),t}},Bn=function(){this._mediaStream&&(this._mediaStream.getTracks().forEach((t=>{t.stop()})),this._mediaStream=null),jr(this,hn,null,"f")},Nn=async function(){jr(this,pn,!1,"f");const t=jr(this,mn,Symbol(),"f");if(Nr(this,_n,"f")&&"pending"===Nr(this,vn,"f")){try{await Nr(this,_n,"f")}catch(t){}Nr(this,on,"m",Pn).call(this)}if(t!==Nr(this,mn,"f"))return;const e=jr(this,_n,(async()=>{jr(this,vn,"pending","f");try{if(this.videoSrc){if(!Nr(this,an,"f"))throw new Error("'videoEl' should be set.");await qn.playVideo(Nr(this,an,"f"),this.videoSrc,this.cameraOpenTimeout),Nr(this,on,"m",Pn).call(this)}else{let t=await Nr(this,on,"m",Fn).call(this);Nr(this,on,"m",Bn).call(this);let e=await Nr(this,on,"m",kn).call(this,t);await this._getCameras(!1),Nr(this,on,"m",Pn).call(this);const i=()=>{const t=e.getVideoTracks();let i,r;if(t.length&&(i=t[0]),i){const t=i.getSettings();if(t)for(let e of this._arrCameras)if(t.deviceId===e.deviceId){e._checked=!0,e.label=i.label,r=e;break}}return r},r=Nr(this,un,"f");if("object"==typeof r.video){let n=r.video.facingMode;if(n instanceof Array&&n.length&&(n=n[0]),"object"==typeof n&&(n=n.exact||n.ideal),!(Nr(this,fn,"f")||this.ifSaveLastUsedCamera&&qn.isStorageAvailable&&window.localStorage.getItem("dce_last_camera_id")||this.ifSkipCameraInspection||r.video.deviceId)){const r=i(),s=qn.findBestCamera(this._arrCameras,n,{getMainCameraInIOS:this.selectIOSRearMainCameraAsDefault});s&&s!=(null==r?void 0:r.deviceId)&&(e.getTracks().forEach((t=>{t.stop()})),t.video.deviceId={exact:s},e=await Nr(this,on,"m",kn).call(this,t),Nr(this,on,"m",Pn).call(this))}}const n=i();(null==n?void 0:n.deviceId)&&(jr(this,fn,n&&n.deviceId,"f"),this.ifSaveLastUsedCamera&&qn.isStorageAvailable&&(window.localStorage.setItem("dce_last_camera_id",Nr(this,fn,"f")),"object"==typeof t.video&&t.video.width&&t.video.height&&(window.localStorage.setItem("dce_last_apply_width",JSON.stringify(t.video.width)),window.localStorage.setItem("dce_last_apply_height",JSON.stringify(t.video.height))))),Nr(this,an,"f")&&(await qn.playVideo(Nr(this,an,"f"),e,this.cameraOpenTimeout),Nr(this,on,"m",Pn).call(this)),this._mediaStream=e;const s=e.getVideoTracks();(null==s?void 0:s.length)&&jr(this,hn,s[0],"f"),jr(this,dn,n,"f")}}catch(t){throw Nr(this,on,"m",Un).call(this),jr(this,vn,null,"f"),t}jr(this,vn,"fulfilled","f")})(),"f");return e},jn=async function(){var t;if("closed"===this.state||this.videoSrc)return;const e=null===(t=Nr(this,dn,"f"))||void 0===t?void 0:t.deviceId,i=this.getResolution();await Nr(this,on,"m",Nn).call(this);const r=this.getResolution();e&&e!==Nr(this,dn,"f").deviceId&&Nr(this,An,"f").fire("camera:changed",[Nr(this,dn,"f").deviceId,e],{target:this,async:!1}),i.width==r.width&&i.height==r.height||Nr(this,An,"f").fire("resolution:changed",[{width:r.width,height:r.height},{width:i.width,height:i.height}],{target:this,async:!1}),Nr(this,An,"f").fire("played",null,{target:this,async:!1})},Un=function(){Nr(this,on,"m",Bn).call(this),jr(this,dn,null,"f"),Nr(this,an,"f")&&(Nr(this,an,"f").srcObject=null,this.videoSrc&&(Nr(this,an,"f").pause(),Nr(this,an,"f").currentTime=0)),jr(this,pn,!0,"f");try{this.resetSoftwareScale()}catch(t){}},Vn=async function t(e,i){const r=t=>{if(!Nr(this,hn,"f")||!this.isVideoPlaying||t.focusTaskId!=this._focusParameters.curFocusTaskId){Nr(this,hn,"f")&&this.isVideoPlaying||(this._focusParameters.isDoingFocus=0);const e=new Error(`Focus task ${t.focusTaskId} canceled.`);throw e.name="DeprecatedTaskError",e}1===this._focusParameters.isDoingFocus&&Date.now()-t.timeStart>this._focusParameters.focusCancelableTime&&(this._focusParameters.isDoingFocus=-1)};let n;i=Zn(i,this._focusParameters.fds.min,this._focusParameters.fds.step,this._focusParameters.fds.max),await Nr(this,hn,"f").applyConstraints({advanced:[{focusMode:"manual",focusDistance:i}]}),r(e),n=null==this._focusParameters.oldDistance?this._focusParameters.kTimeout*Math.max(Math.abs(1/this._focusParameters.fds.min-1/i),Math.abs(1/this._focusParameters.fds.max-1/i))+this._focusParameters.minTimeout:this._focusParameters.kTimeout*Math.abs(1/this._focusParameters.oldDistance-1/i)+this._focusParameters.minTimeout,this._focusParameters.oldDistance=i,await new Promise((t=>{setTimeout(t,n)})),r(e);let s=e.focusL-e.focusW/2,o=e.focusT-e.focusH/2,a=e.focusW,h=e.focusH;const l=this.getResolution();s=Math.round(s),o=Math.round(o),a=Math.round(a),h=Math.round(h),a>l.width&&(a=l.width),h>l.height&&(h=l.height),s<0?s=0:s+a>l.width&&(s=l.width-a),o<0?o=0:o+h>l.height&&(o=l.height-h);const c=4*l.width*l.height*this._focusParameters.defaultTempBufferContainerLenRatio,u=4*a*h;let d=this._focusParameters.tempBufferContainer;if(d){const t=d.length;c>t&&c>=u?d=new Uint8Array(c):u>t&&u>=c&&(d=new Uint8Array(u))}else d=this._focusParameters.tempBufferContainer=new Uint8Array(Math.max(c,u));if(!this.imageDataGetter.getImageData(Nr(this,an,"f"),{sx:s,sy:o,sWidth:a,sHeight:h,dWidth:a,dHeight:h},{pixelFormat:qr.RGBA,bufferContainer:d}))return Nr(this,on,"m",t).call(this,e,i);const f=d;let g=0;for(let t=0,e=u-8;ta&&au)return await Nr(this,on,"m",t).call(this,e,o,a,n,s,c,u)}else{let h=await Nr(this,on,"m",Vn).call(this,e,c);if(a>h)return await Nr(this,on,"m",t).call(this,e,o,a,n,s,c,h);if(a==h)return await Nr(this,on,"m",t).call(this,e,o,a,c,h);let u=await Nr(this,on,"m",Vn).call(this,e,l);if(u>a&&ao.width||h<0||h>o.height)throw new Error("Invalid 'centerPoint'.");let l=0;if(e.endsWith("px"))l=parseFloat(e);else{if(!e.endsWith("%"))throw new Error("Invalid 'width'.");l=parseFloat(e)/100*o.width}if(isNaN(l)||l<0)throw new Error("Invalid 'width'.");let c=0;if(i.endsWith("px"))c=parseFloat(i);else{if(!i.endsWith("%"))throw new Error("Invalid 'height'.");c=parseFloat(i)/100*o.height}if(isNaN(c)||c<0)throw new Error("Invalid 'height'.");if(1!==Nr(this,bn,"f")){const t=Nr(this,bn,"f"),e=Nr(this,In,"f");l/=t,c/=t,a=(1-1/t)*e.x+a/t,h=(1-1/t)*e.y+h/t}if(!this._focusSupported)throw new Error("Manual focus unsupported.");if(!this._focusParameters.fds&&(this._focusParameters.fds=null===(s=this.getCameraCapabilities())||void 0===s?void 0:s.focusDistance,!this._focusParameters.fds))throw this._focusSupported=!1,new Error("Manual focus unsupported.");null==this._focusParameters.kTimeout&&(this._focusParameters.kTimeout=(this._focusParameters.maxTimeout-this._focusParameters.minTimeout)/(1/this._focusParameters.fds.min-1/this._focusParameters.fds.max)),this._focusParameters.isDoingFocus=1;const u={focusL:a,focusT:h,focusW:l,focusH:c,focusTaskId:++this._focusParameters.curFocusTaskId,timeStart:Date.now()},d=async(t,e,i)=>{try{(null==e||ethis._focusParameters.fds.max)&&(i=this._focusParameters.fds.max),this._focusParameters.oldDistance=null;let r=Zn(Math.sqrt(i*(e||this._focusParameters.fds.step)),this._focusParameters.fds.min,this._focusParameters.fds.step,this._focusParameters.fds.max),n=Zn(Math.sqrt((e||this._focusParameters.fds.step)*r),this._focusParameters.fds.min,this._focusParameters.fds.step,this._focusParameters.fds.max),s=Zn(Math.sqrt(r*i),this._focusParameters.fds.min,this._focusParameters.fds.step,this._focusParameters.fds.max),o=await Nr(this,on,"m",Vn).call(this,t,s),a=await Nr(this,on,"m",Vn).call(this,t,n),h=await Nr(this,on,"m",Vn).call(this,t,r);if(a>h&&ho&&a>o){let e=await Nr(this,on,"m",Vn).call(this,t,i);const n=await Nr(this,on,"m",Gn).call(this,t,r,h,i,e,s,o);return this._focusParameters.isDoingFocus=0,n}if(a==h&&hh){const e=await Nr(this,on,"m",Gn).call(this,t,r,h,s,o);return this._focusParameters.isDoingFocus=0,e}return d(t,e,i)}catch(t){if("DeprecatedTaskError"!==t.name)throw t}};return d(u,r,n)},Yn=function(t){if("opened"!==this.state)throw new Error("Video is not playing.");if(!t||"string"!=typeof t.x||"string"!=typeof t.y)throw new Error("Invalid 'center'.");const e=this.getResolution();let i=0,r=0;if(t.x.endsWith("px"))i=parseFloat(t.x);else{if(!t.x.endsWith("%"))throw new Error("Invalid scale center.");i=parseFloat(t.x)/100*e.width}if(t.y.endsWith("px"))r=parseFloat(t.y);else{if(!t.y.endsWith("%"))throw new Error("Invalid scale center.");r=parseFloat(t.y)/100*e.height}if(isNaN(i)||isNaN(r))throw new Error("Invalid scale center.");jr(this,In,{x:i,y:r},"f")},Hn=function(t){if("opened"!==this.state)throw new Error("Video is not playing.");const e=this.getResolution();return t&&t.x==e.width/2&&t.y==e.height/2},qn.browserInfo=Hr,qn.onWarning=null===(sn=null===window||void 0===window?void 0:window.console)||void 0===sn?void 0:sn.warn;class Ds{constructor(t){Kn.add(this),Jn.set(this,void 0),Qn.set(this,0),$n.set(this,void 0),ts.set(this,0),es.set(this,!1),Qe(this,Jn,t,"f")}startCharging(){Je(this,es,"f")||(Ds._onLog&&Ds._onLog("start charging."),Je(this,Kn,"m",rs).call(this),Qe(this,es,!0,"f"))}stopCharging(){Je(this,$n,"f")&&clearTimeout(Je(this,$n,"f")),Je(this,es,"f")&&(Ds._onLog&&Ds._onLog("stop charging."),Qe(this,Qn,Date.now()-Je(this,ts,"f"),"f"),Qe(this,es,!1,"f"))}}Jn=new WeakMap,Qn=new WeakMap,$n=new WeakMap,ts=new WeakMap,es=new WeakMap,Kn=new WeakSet,is=function(){vt.cfd(1),Ds._onLog&&Ds._onLog("charge 1.")},rs=function t(){0==Je(this,Qn,"f")&&Je(this,Kn,"m",is).call(this),Qe(this,ts,Date.now(),"f"),Je(this,$n,"f")&&clearTimeout(Je(this,$n,"f")),Qe(this,$n,setTimeout((()=>{Qe(this,Qn,0,"f"),Je(this,Kn,"m",t).call(this)}),Je(this,Jn,"f")-Je(this,Qn,"f")),"f")};class Ls{static beep(){if(!this.allowBeep)return;if(!this.beepSoundSource)return;let t,e=Date.now();if(!(e-Je(this,ns,"f",as)<100)){if(Qe(this,ns,e,"f",as),Je(this,ns,"f",ss).size&&(t=Je(this,ns,"f",ss).values().next().value,this.beepSoundSource==t.src?(Je(this,ns,"f",ss).delete(t),t.play()):t=null),!t)if(Je(this,ns,"f",os).size<16){t=new Audio(this.beepSoundSource);let e=null,i=()=>{t.removeEventListener("loadedmetadata",i),t.play(),e=setTimeout((()=>{Je(this,ns,"f",os).delete(t)}),2e3*t.duration)};t.addEventListener("loadedmetadata",i),t.addEventListener("ended",(()=>{null!=e&&(clearTimeout(e),e=null),t.pause(),t.currentTime=0,Je(this,ns,"f",os).delete(t),Je(this,ns,"f",ss).add(t)}))}else Je(this,ns,"f",hs)||(Qe(this,ns,!0,"f",hs),console.warn("The requested audio tracks exceed 16 and will not be played."));t&&Je(this,ns,"f",os).add(t)}}static vibrate(){if(this.allowVibrate){if(!navigator||!navigator.vibrate)throw new Error("Not supported.");navigator.vibrate(Ls.vibrateDuration)}}}ns=Ls,ss={value:new Set},os={value:new Set},as={value:0},hs={value:!1},Ls.allowBeep=!0,Ls.beepSoundSource="data:audio/mpeg;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjI5LjEwMAAAAAAAAAAAAAAA/+M4wAAAAAAAAAAAAEluZm8AAAAPAAAABQAAAkAAgICAgICAgICAgICAgICAgICAgKCgoKCgoKCgoKCgoKCgoKCgoKCgwMDAwMDAwMDAwMDAwMDAwMDAwMDg4ODg4ODg4ODg4ODg4ODg4ODg4P//////////////////////////AAAAAExhdmM1OC41NAAAAAAAAAAAAAAAACQEUQAAAAAAAAJAk0uXRQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/+MYxAANQAbGeUEQAAHZYZ3fASqD4P5TKBgocg+Bw/8+CAYBA4XB9/4EBAEP4nB9+UOf/6gfUCAIKyjgQ/Kf//wfswAAAwQA/+MYxAYOqrbdkZGQAMA7DJLCsQxNOij///////////+tv///3RWiZGBEhsf/FO/+LoCSFs1dFVS/g8f/4Mhv0nhqAieHleLy/+MYxAYOOrbMAY2gABf/////////////////usPJ66R0wI4boY9/8jQYg//g2SPx1M0N3Z0kVJLIs///Uw4aMyvHJJYmPBYG/+MYxAgPMALBucAQAoGgaBoFQVBUFQWDv6gZBUFQVBUGgaBr5YSgqCoKhIGg7+IQVBUFQVBoGga//SsFSoKnf/iVTEFNRTMu/+MYxAYAAANIAAAAADEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",Ls.allowVibrate=!0,Ls.vibrateDuration=300;const Ms=new Map([[qr.GREY,a.IPF_GRAYSCALED],[qr.RGBA,a.IPF_ABGR_8888]]),Fs="function"==typeof BigInt?{BF_NULL:BigInt(0),BF_ALL:BigInt(0x10000000000000000),BF_DEFAULT:BigInt(4265345023),BF_ONED:BigInt(3147775),BF_GS1_DATABAR:BigInt(260096),BF_CODE_39:BigInt(1),BF_CODE_128:BigInt(2),BF_CODE_93:BigInt(4),BF_CODABAR:BigInt(8),BF_ITF:BigInt(16),BF_EAN_13:BigInt(32),BF_EAN_8:BigInt(64),BF_UPC_A:BigInt(128),BF_UPC_E:BigInt(256),BF_INDUSTRIAL_25:BigInt(512),BF_CODE_39_EXTENDED:BigInt(1024),BF_GS1_DATABAR_OMNIDIRECTIONAL:BigInt(2048),BF_GS1_DATABAR_TRUNCATED:BigInt(4096),BF_GS1_DATABAR_STACKED:BigInt(8192),BF_GS1_DATABAR_STACKED_OMNIDIRECTIONAL:BigInt(16384),BF_GS1_DATABAR_EXPANDED:BigInt(32768),BF_GS1_DATABAR_EXPANDED_STACKED:BigInt(65536),BF_GS1_DATABAR_LIMITED:BigInt(131072),BF_PATCHCODE:BigInt(262144),BF_CODE_32:BigInt(16777216),BF_PDF417:BigInt(33554432),BF_QR_CODE:BigInt(67108864),BF_DATAMATRIX:BigInt(134217728),BF_AZTEC:BigInt(268435456),BF_MAXICODE:BigInt(536870912),BF_MICRO_QR:BigInt(1073741824),BF_MICRO_PDF417:BigInt(524288),BF_GS1_COMPOSITE:BigInt(2147483648),BF_MSI_CODE:BigInt(1048576),BF_CODE_11:BigInt(2097152),BF_TWO_DIGIT_ADD_ON:BigInt(4194304),BF_FIVE_DIGIT_ADD_ON:BigInt(8388608),BF_MATRIX_25:BigInt(68719476736),BF_POSTALCODE:BigInt(0x3f0000000000000),BF_NONSTANDARD_BARCODE:BigInt(4294967296),BF_USPSINTELLIGENTMAIL:BigInt(4503599627370496),BF_POSTNET:BigInt(9007199254740992),BF_PLANET:BigInt(0x40000000000000),BF_AUSTRALIANPOST:BigInt(0x80000000000000),BF_RM4SCC:BigInt(72057594037927940),BF_KIX:BigInt(0x200000000000000),BF_DOTCODE:BigInt(8589934592),BF_PHARMACODE_ONE_TRACK:BigInt(17179869184),BF_PHARMACODE_TWO_TRACK:BigInt(34359738368),BF_PHARMACODE:BigInt(51539607552)}:{BF_NULL:"0x00",BF_ALL:"0xFFFFFFFFFFFFFFFF",BF_DEFAULT:"0xFE3BFFFF",BF_ONED:"0x003007FF",BF_GS1_DATABAR:"0x0003F800",BF_CODE_39:"0x1",BF_CODE_128:"0x2",BF_CODE_93:"0x4",BF_CODABAR:"0x8",BF_ITF:"0x10",BF_EAN_13:"0x20",BF_EAN_8:"0x40",BF_UPC_A:"0x80",BF_UPC_E:"0x100",BF_INDUSTRIAL_25:"0x200",BF_CODE_39_EXTENDED:"0x400",BF_GS1_DATABAR_OMNIDIRECTIONAL:"0x800",BF_GS1_DATABAR_TRUNCATED:"0x1000",BF_GS1_DATABAR_STACKED:"0x2000",BF_GS1_DATABAR_STACKED_OMNIDIRECTIONAL:"0x4000",BF_GS1_DATABAR_EXPANDED:"0x8000",BF_GS1_DATABAR_EXPANDED_STACKED:"0x10000",BF_GS1_DATABAR_LIMITED:"0x20000",BF_PATCHCODE:"0x00040000",BF_CODE_32:"0x01000000",BF_PDF417:"0x02000000",BF_QR_CODE:"0x04000000",BF_DATAMATRIX:"0x08000000",BF_AZTEC:"0x10000000",BF_MAXICODE:"0x20000000",BF_MICRO_QR:"0x40000000",BF_MICRO_PDF417:"0x00080000",BF_GS1_COMPOSITE:"0x80000000",BF_MSI_CODE:"0x100000",BF_CODE_11:"0x200000",BF_TWO_DIGIT_ADD_ON:"0x400000",BF_FIVE_DIGIT_ADD_ON:"0x800000",BF_MATRIX_25:"0x1000000000",BF_POSTALCODE:"0x3F0000000000000",BF_NONSTANDARD_BARCODE:"0x100000000",BF_USPSINTELLIGENTMAIL:"0x10000000000000",BF_POSTNET:"0x20000000000000",BF_PLANET:"0x40000000000000",BF_AUSTRALIANPOST:"0x80000000000000",BF_RM4SCC:"0x100000000000000",BF_KIX:"0x200000000000000",BF_DOTCODE:"0x200000000",BF_PHARMACODE_ONE_TRACK:"0x400000000",BF_PHARMACODE_TWO_TRACK:"0x800000000",BF_PHARMACODE:"0xC00000000"};class Ps extends J{static set _onLog(t){Qe(Ps,cs,t,"f",us),qn._onLog=t,Ds._onLog=t}static get _onLog(){return Je(Ps,cs,"f",us)}static async detectEnvironment(){return await(async()=>({wasm:$e,worker:ti,getUserMedia:ei,camera:await ii(),browser:qe.browser,version:qe.version,OS:qe.OS}))()}static async testCameraAccess(){const t=await qn.testCameraAccess();return t.ok?{ok:!0,message:"Successfully accessed the camera."}:"InsecureContext"===t.errorName?{ok:!1,message:"Insecure context."}:"OverconstrainedError"===t.errorName||"NotFoundError"===t.errorName?{ok:!1,message:"No camera detected."}:"NotAllowedError"===t.errorName?{ok:!1,message:"No permission to access camera."}:"AbortError"===t.errorName?{ok:!1,message:"Some problem occurred which prevented the device from being used."}:"NotReadableError"===t.errorName?{ok:!1,message:"A hardware error occurred."}:"SecurityError"===t.errorName?{ok:!1,message:"User media support is disabled."}:{ok:!1,message:t.errorMessage}}static async createInstance(t){var e,i;if(t&&!(t instanceof Br))throw new TypeError("Invalid view.");if(null===(e=gt.license)||void 0===e?void 0:e.LicenseManager){if(!(null===(i=gt.license)||void 0===i?void 0:i.LicenseManager.bCallInitLicense))throw new Error("License is not set.");await vt.loadWasm(["license"]),await gt.license.dynamsoft()}const r=new Ps(t);return Ps.onWarning&&(location&&"file:"===location.protocol?setTimeout((()=>{Ps.onWarning&&Ps.onWarning({id:1,message:"The page is opened over file:// and Dynamsoft Camera Enhancer may not work properly. Please open the page via https://."})}),0):!1!==window.isSecureContext&&navigator&&navigator.mediaDevices&&navigator.mediaDevices.getUserMedia||setTimeout((()=>{Ps.onWarning&&Ps.onWarning({id:2,message:"Dynamsoft Camera Enhancer may not work properly in a non-secure context. Please open the page via https://."})}),0)),r}get video(){return this.cameraManager.getVideoEl()}set videoSrc(t){if(!this.cameraManager)throw new Error("Camera manager is null.");this.cameraView&&(this.cameraView._hideDefaultSelection=!0),this.cameraManager.videoSrc=t}get videoSrc(){var t;return null===(t=this.cameraManager)||void 0===t?void 0:t.videoSrc}set ifSaveLastUsedCamera(t){if(!this.cameraManager)throw new Error("Camera manager is null.");this.cameraManager.ifSaveLastUsedCamera=t}get ifSaveLastUsedCamera(){var t;return null===(t=this.cameraManager)||void 0===t?void 0:t.ifSaveLastUsedCamera}set ifSkipCameraInspection(t){if(!this.cameraManager)throw new Error("Camera manager is null.");this.cameraManager.ifSkipCameraInspection=t}get ifSkipCameraInspection(){var t;return null===(t=this.cameraManager)||void 0===t?void 0:t.ifSkipCameraInspection}set cameraOpenTimeout(t){if(!this.cameraManager)throw new Error("Camera manager is null.");this.cameraManager.cameraOpenTimeout=t}get cameraOpenTimeout(){var t;return null===(t=this.cameraManager)||void 0===t?void 0:t.cameraOpenTimeout}set singleFrameMode(t){if(!["disabled","image","camera"].includes(t))throw new Error("Invalid value.");if(this.isOpen())throw new Error("It is not allowed to change `singleFrameMode` when the camera is open.");Qe(this,gs,t,"f")}get singleFrameMode(){return Je(this,gs,"f")}get _isFetchingStarted(){return Je(this,ws,"f")}get disposed(){return Je(this,bs,"f")}constructor(t){if(super(),ls.add(this),ds.set(this,"closed"),fs.set(this,void 0),this.isTorchOn=void 0,gs.set(this,void 0),this._onCameraSelChange=async()=>{this.isOpen()&&this.cameraView&&!this.cameraView.disposed&&await this.selectCamera(this.cameraView._selCam.value)},this._onResolutionSelChange=async()=>{if(!this.isOpen())return;if(!this.cameraView||this.cameraView.disposed)return;let t,e;if(this.cameraView._selRsl&&-1!=this.cameraView._selRsl.selectedIndex){let i=this.cameraView._selRsl.options[this.cameraView._selRsl.selectedIndex];t=parseInt(i.getAttribute("data-width")),e=parseInt(i.getAttribute("data-height"))}await this.setResolution({width:t,height:e})},this._onCloseBtnClick=async()=>{this.isOpen()&&this.cameraView&&!this.cameraView.disposed&&this.close()},ms.set(this,((t,e,i,r)=>{const n=Date.now(),s={sx:r.x,sy:r.y,sWidth:r.width,sHeight:r.height,dWidth:r.width,dHeight:r.height},o=Math.max(s.dWidth,s.dHeight);if(this.canvasSizeLimit&&o>this.canvasSizeLimit){const t=this.canvasSizeLimit/o;s.dWidth>s.dHeight?(s.dWidth=this.canvasSizeLimit,s.dHeight=Math.round(s.dHeight*t)):(s.dWidth=Math.round(s.dWidth*t),s.dHeight=this.canvasSizeLimit)}const h=this.cameraManager.imageDataGetter.getImageData(t,s,{pixelFormat:this.getPixelFormat()===a.IPF_GRAYSCALED?qr.GREY:qr.RGBA});let l=null;if(h){const t=Date.now();let o;o=h.pixelFormat===qr.GREY?h.width:4*h.width;let a=!0;0===s.sx&&0===s.sy&&s.sWidth===e&&s.sHeight===i&&(a=!1),l={bytes:h.data,width:h.width,height:h.height,stride:o,format:Ms.get(h.pixelFormat),tag:{imageId:this._imageId==Number.MAX_VALUE?this._imageId=0:++this._imageId,type:St.ITT_FILE_IMAGE,isCropped:a,cropRegion:{left:r.x,top:r.y,right:r.x+r.width,bottom:r.y+r.height,isMeasuredInPercentage:!1},originalWidth:e,originalHeight:i,currentWidth:h.width,currentHeight:h.height,timeSpent:t-n,timeStamp:t},toCanvas:Je(this,ps,"f"),isDCEFrame:!0}}return l})),this._onSingleFrameAcquired=t=>{let e;e=this.cameraView?this.cameraView.getConvertedRegion():Wi.convert(Je(this,vs,"f"),t.width,t.height),e||(e={x:0,y:0,width:t.width,height:t.height});const i=Je(this,ms,"f").call(this,t,t.width,t.height,e);Je(this,fs,"f").fire("singleFrameAcquired",[i],{async:!1,copy:!1})},ps.set(this,(function(){if(!(this.bytes instanceof Uint8Array||this.bytes instanceof Uint8ClampedArray))throw new TypeError("Invalid bytes.");if("number"!=typeof this.width||this.width<=0)throw new Error("Invalid width.");if("number"!=typeof this.height||this.height<=0)throw new Error("Invalid height.");const t=document.createElement("canvas");let e;if(t.width=this.width,t.height=this.height,this.format===a.IPF_GRAYSCALED){e=new Uint8ClampedArray(this.width*this.height*4);for(let t=0;t{if(!this.video)return;const t=this.cameraManager.getSoftwareScale();if(t<1)throw new RangeError("Invalid scale value.");this.cameraView&&!this.cameraView.disposed?(this.video.style.transform=1===t?"":`scale(${t})`,this.cameraView._updateVideoContainer()):this.video.style.transform=1===t?"":`scale(${t})`},["iPhone","iPad","Android","HarmonyOS"].includes(qe.OS)?this.cameraManager.setResolution(1280,720):this.cameraManager.setResolution(1920,1080),navigator&&navigator.mediaDevices&&navigator.mediaDevices.getUserMedia?this.singleFrameMode="disabled":this.singleFrameMode="image",t&&(this.setCameraView(t),t.cameraEnhancer=this),this._on("before:camera:change",(()=>{Je(this,Ss,"f").stopCharging();const t=this.cameraView;t&&!t.disposed&&(t._startLoading(),t.clearAllInnerDrawingItems())})),this._on("camera:changed",(()=>{this.clearBuffer()})),this._on("before:resolution:change",(()=>{const t=this.cameraView;t&&!t.disposed&&(t._startLoading(),t.clearAllInnerDrawingItems())})),this._on("resolution:changed",(()=>{this.clearBuffer(),t.eventHandler.fire("content:updated",null,{async:!1})})),this._on("paused",(()=>{Je(this,Ss,"f").stopCharging();const t=this.cameraView;t&&t.disposed})),this._on("resumed",(()=>{const t=this.cameraView;t&&t.disposed})),this._on("tapfocus",(()=>{Je(this,Es,"f").tapToFocus&&Je(this,Ss,"f").startCharging()})),this._intermediateResultReceiver={},this._intermediateResultReceiver.onTaskResultsReceived=async(t,e)=>{var i,r,n,s;if(Je(this,ls,"m",Is).call(this)||!this.isOpen()||this.isPaused())return;const o=t.intermediateResultUnits;Ps._onLog&&(Ps._onLog("intermediateResultUnits:"),Ps._onLog(o));let a=!1,h=!1;for(let t of o){if(t.unitType===At.IRUT_DECODED_BARCODES&&t.decodedBarcodes.length){a=!0;break}t.unitType===At.IRUT_LOCALIZED_BARCODES&&t.localizedBarcodes.length&&(h=!0)}if(Ps._onLog&&(Ps._onLog("hasLocalizedBarcodes:"),Ps._onLog(h)),Je(this,Es,"f").autoZoom||Je(this,Es,"f").enhancedFocus)if(a)Je(this,Ts,"f").autoZoomInFrameArray.length=0,Je(this,Ts,"f").autoZoomOutFrameCount=0,Je(this,Ts,"f").frameArrayInIdealZoom.length=0,Je(this,Ts,"f").autoFocusFrameArray.length=0;else{const e=async t=>{await this.setZoom(t),Je(this,Es,"f").autoZoom&&Je(this,Ss,"f").startCharging()},a=async t=>{await this.setFocus(t),Je(this,Es,"f").enhancedFocus&&Je(this,Ss,"f").startCharging()};if(h){const h=o[0].originalImageTag,l=(null===(i=h.cropRegion)||void 0===i?void 0:i.left)||0,c=(null===(r=h.cropRegion)||void 0===r?void 0:r.top)||0,u=(null===(n=h.cropRegion)||void 0===n?void 0:n.right)?h.cropRegion.right-l:h.originalWidth,d=(null===(s=h.cropRegion)||void 0===s?void 0:s.bottom)?h.cropRegion.bottom-c:h.originalHeight,f=h.currentWidth,g=h.currentHeight;let m;{let t,e,i,r,n;{const t=this.video.videoWidth*(1-Je(this,Ts,"f").autoZoomDetectionArea)/2,e=this.video.videoWidth*(1+Je(this,Ts,"f").autoZoomDetectionArea)/2,i=e,r=t,s=this.video.videoHeight*(1-Je(this,Ts,"f").autoZoomDetectionArea)/2,o=s,a=this.video.videoHeight*(1+Je(this,Ts,"f").autoZoomDetectionArea)/2;n=[{x:t,y:s},{x:e,y:o},{x:i,y:a},{x:r,y:a}]}Ps._onLog&&(Ps._onLog("detectionArea:"),Ps._onLog(n));const s=[];{const t=(t,e)=>{const i=(t,e)=>{if(!t&&!e)throw new Error("Invalid arguments.");return function(t,e,i){let r=!1;const n=t.length;if(n<=2)return!1;for(let s=0;s0!=Zi(a.y-i)>0&&Zi(e-(i-o.y)*(o.x-a.x)/(o.y-a.y)-o.x)<0&&(r=!r)}return r}(e,t.x,t.y)},r=(t,e)=>!!(qi([t[0],t[1]],[t[2],t[3]],[e[0].x,e[0].y],[e[1].x,e[1].y])||qi([t[0],t[1]],[t[2],t[3]],[e[1].x,e[1].y],[e[2].x,e[2].y])||qi([t[0],t[1]],[t[2],t[3]],[e[2].x,e[2].y],[e[3].x,e[3].y])||qi([t[0],t[1]],[t[2],t[3]],[e[3].x,e[3].y],[e[0].x,e[0].y]));return!!(i({x:t[0].x,y:t[0].y},e)||i({x:t[1].x,y:t[1].y},e)||i({x:t[2].x,y:t[2].y},e)||i({x:t[3].x,y:t[3].y},e))||!!(i({x:e[0].x,y:e[0].y},t)||i({x:e[1].x,y:e[1].y},t)||i({x:e[2].x,y:e[2].y},t)||i({x:e[3].x,y:e[3].y},t))||!!(r([e[0].x,e[0].y,e[1].x,e[1].y],t)||r([e[1].x,e[1].y,e[2].x,e[2].y],t)||r([e[2].x,e[2].y,e[3].x,e[3].y],t)||r([e[3].x,e[3].y,e[0].x,e[0].y],t))};for(let e of o)if(e.unitType===At.IRUT_LOCALIZED_BARCODES)for(let i of e.localizedBarcodes){if(!i)continue;const e=i.location.points;e.forEach((t=>{Br._transformCoordinates(t,l,c,u,d,f,g)})),t(n,e)&&s.push(i)}if(Ps._debug&&this.cameraView){const t=this.__layer||(this.__layer=this.cameraView._createDrawingLayer(99));t.clearDrawingItems();const e=this.__styleId2||(this.__styleId2=Dr.createDrawingStyle({strokeStyle:"red"}));for(let i of o)if(i.unitType===At.IRUT_LOCALIZED_BARCODES)for(let r of i.localizedBarcodes){if(!r)continue;const i=r.location.points,n=new Di({points:i},e);t.addDrawingItems([n])}}}if(Ps._onLog&&(Ps._onLog("intersectedResults:"),Ps._onLog(s)),!s.length)return;let a;if(s.length){let t=s.filter((t=>t.possibleFormats==Fs.BF_QR_CODE||t.possibleFormats==Fs.BF_DATAMATRIX));if(t.length||(t=s.filter((t=>t.possibleFormats==Fs.BF_ONED)),t.length||(t=s)),t.length){const e=t=>{const e=t.location.points,i=(e[0].x+e[1].x+e[2].x+e[3].x)/4,r=(e[0].y+e[1].y+e[2].y+e[3].y)/4;return(i-f/2)*(i-f/2)+(r-g/2)*(r-g/2)};a=t[0];let i=e(a);if(1!=t.length)for(let r=1;r1.1*a.confidence||t[r].confidence>.9*a.confidence&&ni&&s>i&&o>i&&h>i&&m.result.moduleSize{})),Je(this,Ts,"f").autoZoomInFrameArray.filter((t=>!0===t)).length>=Je(this,Ts,"f").autoZoomInFrameLimit[1]){Je(this,Ts,"f").autoZoomInFrameArray.length=0;const i=[(.5-r)/(.5-n),(.5-r)/(.5-s),(.5-r)/(.5-o),(.5-r)/(.5-h)].filter((t=>t>0)),a=Math.min(...i,Je(this,Ts,"f").autoZoomInIdealModuleSize/m.result.moduleSize),l=this.getZoomSettings().factor;let c=Math.max(Math.pow(l*a,1/Je(this,Ts,"f").autoZoomInMaxTimes),Je(this,Ts,"f").autoZoomInMinStep);c=Math.min(c,a);let u=l*c;u=Math.max(Je(this,Ts,"f").minValue,u),u=Math.min(Je(this,Ts,"f").maxValue,u);try{await e({factor:u})}catch(t){const e=t.message||t;console.warn(e)}this.clearBuffer()}}else if(Je(this,Ts,"f").autoZoomInFrameArray.length=0,Je(this,Ts,"f").frameArrayInIdealZoom.push(!0),Je(this,Ts,"f").frameArrayInIdealZoom.splice(0,Je(this,Ts,"f").frameArrayInIdealZoom.length-Je(this,Ts,"f").frameLimitInIdealZoom[0]),Je(this,Ts,"f").frameArrayInIdealZoom.filter((t=>!0===t)).length>=Je(this,Ts,"f").frameLimitInIdealZoom[1]&&(Je(this,Ts,"f").frameArrayInIdealZoom.length=0,Je(this,Es,"f").enhancedFocus)){const e=m.points;try{await a({mode:"manual",area:{centerPoint:{x:(e[0].x+e[2].x)/2+"px",y:(e[0].y+e[2].y)/2+"px"},width:e[2].x-e[0].x+"px",height:e[2].y-e[0].y+"px"}})}catch(t){const e=t.message||t;console.warn(e)}this.clearBuffer()}}if(!Je(this,Es,"f").autoZoom&&Je(this,Es,"f").enhancedFocus&&(Je(this,Ts,"f").autoFocusFrameArray.push(!0),Je(this,Ts,"f").autoFocusFrameArray.splice(0,Je(this,Ts,"f").autoFocusFrameArray.length-Je(this,Ts,"f").autoFocusFrameLimit[0]),Je(this,Ts,"f").autoFocusFrameArray.filter((t=>!0===t)).length>=Je(this,Ts,"f").autoFocusFrameLimit[1])){Je(this,Ts,"f").autoFocusFrameArray.length=0;try{const t=m.points;await a({mode:"manual",area:{centerPoint:{x:(t[0].x+t[2].x)/2+"px",y:(t[0].y+t[2].y)/2+"px"},width:t[2].x-t[0].x+"px",height:t[2].y-t[0].y+"px"}})}catch(t){const e=t.message||t;console.warn(e)}this.clearBuffer()}}else{if(Je(this,Es,"f").autoZoom){if(Je(this,Ts,"f").autoZoomInFrameArray.push(!1),Je(this,Ts,"f").autoZoomInFrameArray.splice(0,Je(this,Ts,"f").autoZoomInFrameArray.length-Je(this,Ts,"f").autoZoomInFrameLimit[0]),Je(this,Ts,"f").autoZoomOutFrameCount++,Je(this,Ts,"f").frameArrayInIdealZoom.push(!1),Je(this,Ts,"f").frameArrayInIdealZoom.splice(0,Je(this,Ts,"f").frameArrayInIdealZoom.length-Je(this,Ts,"f").frameLimitInIdealZoom[0]),Je(this,Ts,"f").autoZoomOutFrameCount>=Je(this,Ts,"f").autoZoomOutFrameLimit){Je(this,Ts,"f").autoZoomOutFrameCount=0;const i=this.getZoomSettings().factor;let r=i-Math.max((i-1)*Je(this,Ts,"f").autoZoomOutStepRate,Je(this,Ts,"f").autoZoomOutMinStep);r=Math.max(Je(this,Ts,"f").minValue,r),r=Math.min(Je(this,Ts,"f").maxValue,r);try{await e({factor:r})}catch(t){const e=t.message||t;console.warn(e)}this.clearBuffer()}Je(this,Es,"f").enhancedFocus&&a({mode:"continuous"}).catch((()=>{}))}!Je(this,Es,"f").autoZoom&&Je(this,Es,"f").enhancedFocus&&(Je(this,Ts,"f").autoFocusFrameArray.length=0,a({mode:"continuous"}).catch((()=>{})))}}},Qe(this,Ss,new Ds(1e4),"f")}setCameraView(t){if(!(t instanceof Br))throw new TypeError("Invalid view.");if(t.disposed)throw new Error("The camera view has been disposed.");if(this.isOpen())throw new Error("It is not allowed to change camera view when the camera is open.");this.releaseCameraView(),t._singleFrameMode=this.singleFrameMode,t._onSingleFrameAcquired=this._onSingleFrameAcquired,this.videoSrc&&(this.cameraView._hideDefaultSelection=!0),Je(this,ls,"m",Is).call(this)||this.cameraManager.setVideoEl(t.getVideoElement()),this.cameraView=t,this.addListenerToView()}getCameraView(){return this.cameraView}releaseCameraView(){this.cameraView&&(this.removeListenerFromView(),this.cameraView.disposed||(this.cameraView._singleFrameMode="disabled",this.cameraView._onSingleFrameAcquired=null,this.cameraView._hideDefaultSelection=!1),this.cameraManager.releaseVideoEl(),this.cameraView=null)}addListenerToView(){if(!this.cameraView)return;if(this.cameraView.disposed)throw new Error("'cameraView' has been disposed.");const t=this.cameraView;Je(this,ls,"m",Is).call(this)||this.videoSrc||(t._innerComponent&&(this.cameraManager.tapFocusEventBoundEl=t._innerComponent),t._selCam&&t._selCam.addEventListener("change",this._onCameraSelChange),t._selRsl&&t._selRsl.addEventListener("change",this._onResolutionSelChange)),t._btnClose&&t._btnClose.addEventListener("click",this._onCloseBtnClick)}removeListenerFromView(){if(!this.cameraView||this.cameraView.disposed)return;const t=this.cameraView;this.cameraManager.tapFocusEventBoundEl=null,t._selCam&&t._selCam.removeEventListener("change",this._onCameraSelChange),t._selRsl&&t._selRsl.removeEventListener("change",this._onResolutionSelChange),t._btnClose&&t._btnClose.removeEventListener("click",this._onCloseBtnClick)}getCameraState(){return Je(this,ls,"m",Is).call(this)?Je(this,ds,"f"):new Map([["closed","closed"],["opening","opening"],["opened","open"]]).get(this.cameraManager.state)}isOpen(){return"open"===this.getCameraState()}getVideoEl(){return this.video}async open(){const t=this.cameraView;if(null==t?void 0:t.disposed)throw new Error("'cameraView' has been disposed.");t&&(t._singleFrameMode=this.singleFrameMode,Je(this,ls,"m",Is).call(this)?t._clickIptSingleFrameMode():(this.cameraManager.setVideoEl(t.getVideoElement()),t._startLoading()));let e={width:0,height:0,deviceId:""};if(Je(this,ls,"m",Is).call(this));else{try{await this.cameraManager.open()}catch(e){throw t&&t._stopLoading(),"NotFoundError"===e.name?new Error(`No camera devices were detected. Please ensure a camera is connected and recognized by your system. ${null==e?void 0:e.name}: ${null==e?void 0:e.message}`):"NotAllowedError"===e.name?new Error(`Camera access is blocked. Please check your browser settings or grant permission to use the camera. ${null==e?void 0:e.name}: ${null==e?void 0:e.message}`):e}let i,r=t.getUIElement();if(r=r.shadowRoot||r,i=r.querySelector(".dce-macro-use-mobile-native-like-ui")){let t=r.elTorchAuto=r.querySelector(".dce-mn-torch-auto"),e=r.elTorchOn=r.querySelector(".dce-mn-torch-on"),n=r.elTorchOff=r.querySelector(".dce-mn-torch-off");t&&(e.style.display=null==this.isTorchOn?"":"none"),e&&(e.style.display=1==this.isTorchOn?"":"none"),n&&(n.style.display=0==this.isTorchOn?"":"none");let s=r.elBeepOn=r.querySelector(".dce-mn-beep-on"),o=r.elBeepOff=r.querySelector(".dce-mn-beep-off");s&&(s.style.display=Ls.allowBeep?"":"none"),o&&(o.style.display=Ls.allowBeep?"none":"");let a=r.elVibrateOn=r.querySelector(".dce-mn-vibrate-on"),h=r.elVibrateOff=r.querySelector(".dce-mn-vibrate-off");a&&(a.style.display=Ls.allowVibrate?"":"none"),h&&(h.style.display=Ls.allowVibrate?"none":""),r.elResolutionBox=r.querySelector(".dce-mn-resolution-box");let l,c=r.elZoom=r.querySelector(".dce-mn-zoom");c&&(c.style.display="none",l=r.elZoomSpan=c.querySelector("span"));let u=r.elToast=r.querySelector(".dce-mn-toast"),d=r.elCameraClose=r.querySelector(".dce-mn-camera-close"),f=r.elTakePhoto=r.querySelector(".dce-mn-take-photo"),g=r.elCameraSwitch=r.querySelector(".dce-mn-camera-switch"),m=r.elCameraAndResolutionSettings=r.querySelector(".dce-mn-camera-and-resolution-settings");m&&(m.style.display="none");const p=r.dceMnFs={},_=()=>{this.turnOnTorch()};null==t||t.addEventListener("pointerdown",_);const v=()=>{this.turnOffTorch()};null==e||e.addEventListener("pointerdown",v);const y=()=>{this.turnAutoTorch()};null==n||n.addEventListener("pointerdown",y);const w=()=>{Ls.allowBeep=!Ls.allowBeep,s&&(s.style.display=Ls.allowBeep?"":"none"),o&&(o.style.display=Ls.allowBeep?"none":"")};for(let t of[o,s])null==t||t.addEventListener("pointerdown",w);const C=()=>{Ls.allowVibrate=!Ls.allowVibrate,a&&(a.style.display=Ls.allowVibrate?"":"none"),h&&(h.style.display=Ls.allowVibrate?"none":"")};for(let t of[h,a])null==t||t.addEventListener("pointerdown",C);const E=async t=>{let e,i=t.target;if(e=i.closest(".dce-mn-camera-option"))this.selectCamera(e.getAttribute("data-davice-id"));else if(e=i.closest(".dce-mn-resolution-option")){let t,i=parseInt(e.getAttribute("data-width")),r=parseInt(e.getAttribute("data-height")),n=await this.setResolution({width:i,height:r});{let e=Math.max(n.width,n.height),i=Math.min(n.width,n.height);t=i<=1080?i+"P":e<3e3?"2K":Math.round(e/1e3)+"K"}t!=e.textContent&&b(`Fallback to ${t}`)}else i.closest(".dce-mn-camera-and-resolution-settings")||(i.closest(".dce-mn-resolution-box")?m&&(m.style.display=m.style.display?"":"none"):m&&""===m.style.display&&(m.style.display="none"))};r.addEventListener("click",E);let T=null;p.funcInfoZoomChange=(t,e=3e3)=>{c&&l&&(l.textContent=t.toFixed(1),c.style.display="",null!=T&&(clearTimeout(T),T=null),T=setTimeout((()=>{c.style.display="none",T=null}),e))};let S=null,b=p.funcShowToast=(t,e=3e3)=>{u&&(u.textContent=t,u.style.display="",null!=S&&(clearTimeout(S),S=null),S=setTimeout((()=>{u.style.display="none",S=null}),e))};const I=()=>{this.close()};null==d||d.addEventListener("click",I);const x=()=>{};null==f||f.addEventListener("pointerdown",x);const A=()=>{var t,e;let i,r=this.getVideoSettings(),n=r.video.facingMode,s=null===(e=null===(t=this.cameraManager.getCamera())||void 0===t?void 0:t.label)||void 0===e?void 0:e.toLowerCase(),o=null==s?void 0:s.indexOf("front");-1===o&&(o=null==s?void 0:s.indexOf("前"));let a=null==s?void 0:s.indexOf("back");-1===a&&(a=null==s?void 0:s.indexOf("后")),"number"==typeof o&&-1!==o?i=!0:"number"==typeof a&&-1!==a&&(i=!1),void 0===i&&(i="user"===((null==n?void 0:n.ideal)||(null==n?void 0:n.exact)||n)),r.video.facingMode={ideal:i?"environment":"user"},delete r.video.deviceId,this.updateVideoSettings(r)};null==g||g.addEventListener("pointerdown",A);let O=-1/0,R=1;const D=t=>{let e=Date.now();e-O>1e3&&(R=this.getZoomSettings().factor),R-=t.deltaY/200,R>20&&(R=20),R<1&&(R=1),this.setZoom({factor:R}),O=e};i.addEventListener("wheel",D);const L=new Map;let M=!1;const F=async t=>{var e;for(t.touches.length>=2&&"touchmove"==t.type&&t.preventDefault();t.changedTouches.length>1&&2==t.touches.length;){let i=t.touches[0],r=t.touches[1],n=L.get(i.identifier),s=L.get(r.identifier);if(!n||!s)break;let o=Math.pow(Math.pow(n.x-s.x,2)+Math.pow(n.y-s.y,2),.5),a=Math.pow(Math.pow(i.clientX-r.clientX,2)+Math.pow(i.clientY-r.clientY,2),.5),h=Date.now();if(M||h-O<100)return;h-O>1e3&&(R=this.getZoomSettings().factor),R*=a/o,R>20&&(R=20),R<1&&(R=1);let l=!1;"safari"==(null===(e=null==qe?void 0:qe.browser)||void 0===e?void 0:e.toLocaleLowerCase())&&(a/o>1&&R<2?(R=2,l=!0):a/o<1&&R<2&&(R=1,l=!0)),M=!0,l&&b("zooming..."),await this.setZoom({factor:R}),l&&(u.textContent=""),M=!1,O=Date.now();break}L.clear();for(let e of t.touches)L.set(e.identifier,{x:e.clientX,y:e.clientY})};r.addEventListener("touchstart",F),r.addEventListener("touchmove",F),r.addEventListener("touchend",F),r.addEventListener("touchcancel",F),p.unbind=()=>{null==t||t.removeEventListener("pointerdown",_),null==e||e.removeEventListener("pointerdown",v),null==n||n.removeEventListener("pointerdown",y);for(let t of[o,s])null==t||t.removeEventListener("pointerdown",w);for(let t of[h,a])null==t||t.removeEventListener("pointerdown",C);r.removeEventListener("click",E),null==d||d.removeEventListener("click",I),null==f||f.removeEventListener("pointerdown",x),null==g||g.removeEventListener("pointerdown",A),i.removeEventListener("wheel",D),r.removeEventListener("touchstart",F),r.removeEventListener("touchmove",F),r.removeEventListener("touchend",F),r.removeEventListener("touchcancel",F),delete r.dceMnFs,i.style.display="none"},i.style.display="",t&&null==this.isTorchOn&&setTimeout((()=>{this.turnAutoTorch(1e3)}),0)}this.isTorchOn&&this.turnOnTorch().catch((()=>{}));const n=this.getResolution();e.width=n.width,e.height=n.height,e.deviceId=this.getSelectedCamera().deviceId}return Qe(this,ds,"open","f"),t&&(t._innerComponent.style.display="",Je(this,ls,"m",Is).call(this)||(t._stopLoading(),t._renderCamerasInfo(this.getSelectedCamera(),this.cameraManager._arrCameras),t._renderResolutionInfo({width:e.width,height:e.height}),t.eventHandler.fire("content:updated",null,{async:!1}),t.eventHandler.fire("videoEl:resized",null,{async:!1}))),Je(this,fs,"f").fire("opened",null,{target:this,async:!1}),e}close(){var t;const e=this.cameraView;if(null==e?void 0:e.disposed)throw new Error("'cameraView' has been disposed.");if(this.stopFetching(),this.clearBuffer(),Je(this,ls,"m",Is).call(this));else{this.cameraManager.close();let i=e.getUIElement();i=i.shadowRoot||i,i.querySelector(".dce-macro-use-mobile-native-like-ui")&&(null===(t=i.dceMnFs)||void 0===t||t.unbind())}Qe(this,ds,"closed","f"),Je(this,Ss,"f").stopCharging(),e&&(e._innerComponent.style.display="none",Je(this,ls,"m",Is).call(this)&&e._innerComponent.removeElement("content"),e._stopLoading()),Je(this,fs,"f").fire("closed",null,{target:this,async:!1})}pause(){if(Je(this,ls,"m",Is).call(this))throw new Error("'pause()' is invalid in 'singleFrameMode'.");this.cameraManager.pause()}isPaused(){var t;return!Je(this,ls,"m",Is).call(this)&&!0===(null===(t=this.video)||void 0===t?void 0:t.paused)}async resume(){if(Je(this,ls,"m",Is).call(this))throw new Error("'resume()' is invalid in 'singleFrameMode'.");await this.cameraManager.resume()}async selectCamera(t){if(!t)throw new Error("Invalid value.");let e;e="string"==typeof t?t:t.deviceId,await this.cameraManager.setCamera(e),this.isTorchOn=!1;const i=this.getResolution(),r=this.cameraView;return r&&!r.disposed&&(r._stopLoading(),r._renderCamerasInfo(this.getSelectedCamera(),this.cameraManager._arrCameras),r._renderResolutionInfo({width:i.width,height:i.height})),{width:i.width,height:i.height,deviceId:this.getSelectedCamera().deviceId}}getSelectedCamera(){return this.cameraManager.getCamera()}async getAllCameras(){return this.cameraManager.getCameras()}async setResolution(t){await this.cameraManager.setResolution(t.width,t.height),this.isTorchOn&&this.turnOnTorch().catch((()=>{}));const e=this.getResolution(),i=this.cameraView;return i&&!i.disposed&&(i._stopLoading(),i._renderResolutionInfo({width:e.width,height:e.height})),{width:e.width,height:e.height,deviceId:this.getSelectedCamera().deviceId}}getResolution(){return this.cameraManager.getResolution()}getAvailableResolutions(){var t;return null===(t=this.cameraManager)||void 0===t?void 0:t.getResolutions()}_on(t,e){["opened","closed","singleframeacquired","frameaddedtobuffer"].includes(t.toLowerCase())?Je(this,fs,"f").on(t,e):this.cameraManager.on(t,e)}_off(t,e){["opened","closed","singleframeacquired","frameaddedtobuffer"].includes(t.toLowerCase())?Je(this,fs,"f").off(t,e):this.cameraManager.off(t,e)}on(t,e){const i=t.toLowerCase(),r=new Map([["cameraopen","opened"],["cameraclose","closed"],["camerachange","camera:changed"],["resolutionchange","resolution:changed"],["played","played"],["singleframeacquired","singleFrameAcquired"],["frameaddedtobuffer","frameAddedToBuffer"]]).get(i);if(!r)throw new Error("Invalid event.");this._on(r,e)}off(t,e){const i=t.toLowerCase(),r=new Map([["cameraopen","opened"],["cameraclose","closed"],["camerachange","camera:changed"],["resolutionchange","resolution:changed"],["played","played"],["singleframeacquired","singleFrameAcquired"],["frameaddedtobuffer","frameAddedToBuffer"]]).get(i);if(!r)throw new Error("Invalid event.");this._off(r,e)}getVideoSettings(){var t;return null===(t=this.cameraManager)||void 0===t?void 0:t.getMediaStreamConstraints()}async updateVideoSettings(t){var e;await(null===(e=this.cameraManager)||void 0===e?void 0:e.setMediaStreamConstraints(t,!0))}getCapabilities(){var t;return null===(t=this.cameraManager)||void 0===t?void 0:t.getCameraCapabilities()}getCameraSettings(){return this.cameraManager.getCameraSettings()}async turnOnTorch(){var t,e;if(Je(this,ls,"m",Is).call(this))throw new Error("'turnOnTorch()' is invalid in 'singleFrameMode'.");try{await(null===(t=this.cameraManager)||void 0===t?void 0:t.turnOnTorch())}catch(t){let i=this.cameraView.getUIElement();throw i=i.shadowRoot||i,null===(e=null==i?void 0:i.dceMnFs)||void 0===e||e.funcShowToast("Torch Not Supported"),t}this.isTorchOn=!0;let i=this.cameraView.getUIElement();i=i.shadowRoot||i,i.elTorchAuto&&(i.elTorchAuto.style.display="none"),i.elTorchOn&&(i.elTorchOn.style.display=""),i.elTorchOff&&(i.elTorchOff.style.display="none")}async turnOffTorch(){var t;if(Je(this,ls,"m",Is).call(this))throw new Error("'turnOffTorch()' is invalid in 'singleFrameMode'.");await(null===(t=this.cameraManager)||void 0===t?void 0:t.turnOffTorch()),this.isTorchOn=!1;let e=this.cameraView.getUIElement();e=e.shadowRoot||e,e.elTorchAuto&&(e.elTorchAuto.style.display="none"),e.elTorchOn&&(e.elTorchOn.style.display="none"),e.elTorchOff&&(e.elTorchOff.style.display="")}async turnAutoTorch(t=250){if(null!=this._taskid4AutoTorch){if(!(t{var t,n,s;if(this.disposed||e||null!=this.isTorchOn||!this.isOpen())return clearInterval(this._taskid4AutoTorch),void(this._taskid4AutoTorch=null);if(this.isPaused())return;if(++r>10&&this._delay4AutoTorch<1e3)return clearInterval(this._taskid4AutoTorch),this._taskid4AutoTorch=null,void this.turnAutoTorch(1e3);let o;try{o=this.fetchImage()}catch(t){}if(!o||!o.width||!o.height)return;let h=0;if(a.IPF_GRAYSCALED===o.format){for(let t=0;t=this.maxDarkCount4AutoTroch){null===(t=Ps._onLog)||void 0===t||t.call(Ps,`darkCount ${i}`);try{await this.turnOnTorch(),this.isTorchOn=!0;let t=this.cameraView.getUIElement();t=t.shadowRoot||t,null===(n=null==t?void 0:t.dceMnFs)||void 0===n||n.funcShowToast("Torch Auto On")}catch(t){console.warn(t),e=!0;let i=this.cameraView.getUIElement();i=i.shadowRoot||i,null===(s=null==i?void 0:i.dceMnFs)||void 0===s||s.funcShowToast("Torch Not Supported")}}}else i=0};this._taskid4AutoTorch=setInterval(n,t),this.isTorchOn=void 0,n();let s=this.cameraView.getUIElement();s=s.shadowRoot||s,s.elTorchAuto&&(s.elTorchAuto.style.display=""),s.elTorchOn&&(s.elTorchOn.style.display="none"),s.elTorchOff&&(s.elTorchOff.style.display="none")}async setColorTemperature(t){if(Je(this,ls,"m",Is).call(this))throw new Error("'setColorTemperature()' is invalid in 'singleFrameMode'.");await this.cameraManager.setColorTemperature(t,!0)}getColorTemperature(){return this.cameraManager.getColorTemperature()}async setExposureCompensation(t){var e;if(Je(this,ls,"m",Is).call(this))throw new Error("'setExposureCompensation()' is invalid in 'singleFrameMode'.");await(null===(e=this.cameraManager)||void 0===e?void 0:e.setExposureCompensation(t,!0))}getExposureCompensation(){var t;return null===(t=this.cameraManager)||void 0===t?void 0:t.getExposureCompensation()}async _setZoom(t){var e,i,r;if(Je(this,ls,"m",Is).call(this))throw new Error("'setZoom()' is invalid in 'singleFrameMode'.");await(null===(e=this.cameraManager)||void 0===e?void 0:e.setZoom(t));{let e=null===(i=this.cameraView)||void 0===i?void 0:i.getUIElement();e=(null==e?void 0:e.shadowRoot)||e,null===(r=null==e?void 0:e.dceMnFs)||void 0===r||r.funcInfoZoomChange(t.factor)}}async setZoom(t){await this._setZoom(t)}getZoomSettings(){var t;return null===(t=this.cameraManager)||void 0===t?void 0:t.getZoom()}async resetZoom(){var t;if(Je(this,ls,"m",Is).call(this))throw new Error("'resetZoom()' is invalid in 'singleFrameMode'.");await(null===(t=this.cameraManager)||void 0===t?void 0:t.resetZoom())}async setFrameRate(t){var e;if(Je(this,ls,"m",Is).call(this))throw new Error("'setFrameRate()' is invalid in 'singleFrameMode'.");await(null===(e=this.cameraManager)||void 0===e?void 0:e.setFrameRate(t,!0))}getFrameRate(){var t;return null===(t=this.cameraManager)||void 0===t?void 0:t.getFrameRate()}async setFocus(t){var e;if(Je(this,ls,"m",Is).call(this))throw new Error("'setFocus()' is invalid in 'singleFrameMode'.");await(null===(e=this.cameraManager)||void 0===e?void 0:e.setFocus(t,!0))}getFocusSettings(){var t;return null===(t=this.cameraManager)||void 0===t?void 0:t.getFocus()}setAutoZoomRange(t){Je(this,Ts,"f").minValue=t.min,Je(this,Ts,"f").maxValue=t.max}getAutoZoomRange(){return{min:Je(this,Ts,"f").minValue,max:Je(this,Ts,"f").maxValue}}async enableEnhancedFeatures(t){var e,i;if(!(null===(i=null===(e=gt.license)||void 0===e?void 0:e.LicenseManager)||void 0===i?void 0:i.bPassValidation))throw new Error("License is not verified, or license is invalid.");if(0!==vt.bSupportDce4Module)throw new Error("Please set a license containing the DCE module.");t&li.EF_ENHANCED_FOCUS&&(Je(this,Es,"f").enhancedFocus=!0),t&li.EF_AUTO_ZOOM&&(Je(this,Es,"f").autoZoom=!0),t&li.EF_TAP_TO_FOCUS&&(Je(this,Es,"f").tapToFocus=!0,this.cameraManager.enableTapToFocus())}disableEnhancedFeatures(t){t&li.EF_ENHANCED_FOCUS&&(Je(this,Es,"f").enhancedFocus=!1,this.setFocus({mode:"continuous"}).catch((()=>{}))),t&li.EF_AUTO_ZOOM&&(Je(this,Es,"f").autoZoom=!1,this.resetZoom().catch((()=>{}))),t&li.EF_TAP_TO_FOCUS&&(Je(this,Es,"f").tapToFocus=!1,this.cameraManager.disableTapToFocus()),Je(this,ls,"m",As).call(this)&&Je(this,ls,"m",xs).call(this)||Je(this,Ss,"f").stopCharging()}_setScanRegion(t){if(null!=t&&!E(t)&&!A(t))throw TypeError("Invalid 'region'.");Qe(this,vs,t?JSON.parse(JSON.stringify(t)):null,"f"),this.cameraView&&!this.cameraView.disposed&&this.cameraView.setScanRegion(t)}setScanRegion(t){this._setScanRegion(t),this.cameraView&&!this.cameraView.disposed&&(null===t?this.cameraView.setScanRegionMaskVisible(!1):this.cameraView.setScanRegionMaskVisible(!0))}getScanRegion(){return JSON.parse(JSON.stringify(Je(this,vs,"f")))}setErrorListener(t){if(!t)throw new TypeError("Invalid 'listener'");Qe(this,_s,t,"f")}hasNextImageToFetch(){return!("open"!==this.getCameraState()||!this.cameraManager.isVideoLoaded()||Je(this,ls,"m",Is).call(this))}startFetching(){if(Je(this,ls,"m",Is).call(this))throw Error("'startFetching()' is unavailable in 'singleFrameMode'.");Je(this,ws,"f")||(Qe(this,ws,!0,"f"),Je(this,ls,"m",Os).call(this))}stopFetching(){Je(this,ws,"f")&&(Ps._onLog&&Ps._onLog("DCE: stop fetching loop: "+Date.now()),Je(this,Cs,"f")&&clearTimeout(Je(this,Cs,"f")),Qe(this,ws,!1,"f"))}fetchImage(){if(Je(this,ls,"m",Is).call(this))throw new Error("'fetchImage()' is unavailable in 'singleFrameMode'.");if(!this.video)throw new Error("The video element does not exist.");if(4!==this.video.readyState)throw new Error("The video is not loaded.");const t=this.getResolution();if(!(null==t?void 0:t.width)||!(null==t?void 0:t.height))throw new Error("The video is not loaded.");let e;if(e=Wi.convert(Je(this,vs,"f"),t.width,t.height),e||(e={x:0,y:0,width:t.width,height:t.height}),e.x>t.width||e.y>t.height)throw new Error("Invalid scan region.");e.x+e.width>t.width&&(e.width=t.width-e.x),e.y+e.height>t.height&&(e.height=t.height-e.y);const i={sx:e.x,sy:e.y,sWidth:e.width,sHeight:e.height,dWidth:e.width,dHeight:e.height},r=Math.max(i.dWidth,i.dHeight);if(this.canvasSizeLimit&&r>this.canvasSizeLimit){const t=this.canvasSizeLimit/r;i.dWidth>i.dHeight?(i.dWidth=this.canvasSizeLimit,i.dHeight=Math.round(i.dHeight*t)):(i.dWidth=Math.round(i.dWidth*t),i.dHeight=this.canvasSizeLimit)}const n=this.cameraManager.getFrameData({position:i,pixelFormat:this.getPixelFormat()===a.IPF_GRAYSCALED?qr.GREY:qr.RGBA});if(!n)return null;let s;s=n.pixelFormat===qr.GREY?n.width:4*n.width;let o=!0;return 0===i.sx&&0===i.sy&&i.sWidth===t.width&&i.sHeight===t.height&&(o=!1),{bytes:n.data,width:n.width,height:n.height,stride:s,format:Ms.get(n.pixelFormat),tag:{imageId:this._imageId==Number.MAX_VALUE?this._imageId=0:++this._imageId,type:St.ITT_VIDEO_FRAME,isCropped:o,cropRegion:{left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height,isMeasuredInPercentage:!1},originalWidth:t.width,originalHeight:t.height,currentWidth:n.width,currentHeight:n.height,timeSpent:n.timeSpent,timeStamp:n.timeStamp},toCanvas:Je(this,ps,"f"),isDCEFrame:!0}}setImageFetchInterval(t){this.fetchInterval=t,Je(this,ws,"f")&&(Je(this,Cs,"f")&&clearTimeout(Je(this,Cs,"f")),Qe(this,Cs,setTimeout((()=>{this.disposed||Je(this,ls,"m",Os).call(this)}),t),"f"))}getImageFetchInterval(){return this.fetchInterval}setPixelFormat(t){Qe(this,ys,t,"f")}getPixelFormat(){return Je(this,ys,"f")}takePhoto(t){if(!this.isOpen())throw new Error("Not open.");if(Je(this,ls,"m",Is).call(this))throw new Error("'takePhoto()' is unavailable in 'singleFrameMode'.");const e=document.createElement("input");e.setAttribute("type","file"),e.setAttribute("accept",".jpg,.jpeg,.icon,.gif,.svg,.webp,.png,.bmp"),e.setAttribute("capture",""),e.style.position="absolute",e.style.top="-9999px",e.style.backgroundColor="transparent",e.style.color="transparent",e.addEventListener("click",(()=>{const t=this.isOpen();this.close(),window.addEventListener("focus",(()=>{t&&this.open(),e.remove()}),{once:!0})})),e.addEventListener("change",(async()=>{const i=e.files[0],r=await(async t=>{let e=null,i=null;if("undefined"!=typeof createImageBitmap)try{if(e=await createImageBitmap(t),e)return e}catch(t){}var r;return e||(i=await(r=t,new Promise(((t,e)=>{let i=URL.createObjectURL(r),n=new Image;n.src=i,n.onload=()=>{URL.revokeObjectURL(n.src),t(n)},n.onerror=t=>{e(new Error("Can't convert blob to image : "+(t instanceof Event?t.type:t)))}})))),i})(i),n=r instanceof HTMLImageElement?r.naturalWidth:r.width,s=r instanceof HTMLImageElement?r.naturalHeight:r.height;let o=Wi.convert(Je(this,vs,"f"),n,s);o||(o={x:0,y:0,width:n,height:s});const a=Je(this,ms,"f").call(this,r,n,s,o);t&&t(a)})),document.body.appendChild(e),e.click()}convertToPageCoordinates(t){const e=Je(this,ls,"m",Rs).call(this,t);return{x:e.pageX,y:e.pageY}}convertToClientCoordinates(t){const e=Je(this,ls,"m",Rs).call(this,t);return{x:e.clientX,y:e.clientY}}convertToScanRegionCoordinates(t){if(!Je(this,vs,"f"))return JSON.parse(JSON.stringify(t));let e,i,r=Je(this,vs,"f").left||Je(this,vs,"f").x||0,n=Je(this,vs,"f").top||Je(this,vs,"f").y||0;if(!Je(this,vs,"f").isMeasuredInPercentage)return{x:t.x-r,y:t.y-n};if(!this.cameraView)throw new Error("Camera view is not set.");if(this.cameraView.disposed)throw new Error("'cameraView' has been disposed.");if(!this.isOpen())throw new Error("Not open.");if(!Je(this,ls,"m",Is).call(this)&&!this.cameraManager.isVideoLoaded())throw new Error("Video is not loaded.");if(Je(this,ls,"m",Is).call(this)&&!this.cameraView._cvsSingleFrameMode)throw new Error("No image is selected.");if(Je(this,ls,"m",Is).call(this)){const t=this.cameraView._innerComponent.getElement("content");e=t.width,i=t.height}else{const t=this.getVideoEl();e=t.videoWidth,i=t.videoHeight}return{x:t.x-Math.round(r*e/100),y:t.y-Math.round(n*i/100)}}dispose(){this.close(),this.cameraManager.dispose(),this.releaseCameraView(),Qe(this,bs,!0,"f")}}var ks,Bs,Ns,js,Us,Vs,Gs,Ws;cs=Ps,ds=new WeakMap,fs=new WeakMap,gs=new WeakMap,ms=new WeakMap,ps=new WeakMap,_s=new WeakMap,vs=new WeakMap,ys=new WeakMap,ws=new WeakMap,Cs=new WeakMap,Es=new WeakMap,Ts=new WeakMap,Ss=new WeakMap,bs=new WeakMap,ls=new WeakSet,Is=function(){return"disabled"!==this.singleFrameMode},xs=function(){return!this.videoSrc&&"opened"===this.cameraManager.state},As=function(){for(let t in Je(this,Es,"f"))if(1==Je(this,Es,"f")[t])return!0;return!1},Os=function t(){if(this.disposed)return;if("open"!==this.getCameraState()||!Je(this,ws,"f"))return Je(this,Cs,"f")&&clearTimeout(Je(this,Cs,"f")),void Qe(this,Cs,setTimeout((()=>{this.disposed||Je(this,ls,"m",t).call(this)}),this.fetchInterval),"f");const e=()=>{var t;let e;Ps._onLog&&Ps._onLog("DCE: start fetching a frame into buffer: "+Date.now());try{e=this.fetchImage()}catch(e){const i=e.message||e;if("The video is not loaded."===i)return;if(null===(t=Je(this,_s,"f"))||void 0===t?void 0:t.onErrorReceived)return void setTimeout((()=>{var t;null===(t=Je(this,_s,"f"))||void 0===t||t.onErrorReceived(Ct.EC_IMAGE_READ_FAILED,i)}),0);console.warn(e)}e?(this.addImageToBuffer(e),Ps._onLog&&Ps._onLog("DCE: finish fetching a frame into buffer: "+Date.now()),Je(this,fs,"f").fire("frameAddedToBuffer",null,{async:!1})):Ps._onLog&&Ps._onLog("DCE: get a invalid frame, abandon it: "+Date.now())};if(this.getImageCount()>=this.getMaxImageCount())switch(this.getBufferOverflowProtectionMode()){case s.BOPM_BLOCK:break;case s.BOPM_UPDATE:e()}else e();Je(this,Cs,"f")&&clearTimeout(Je(this,Cs,"f")),Qe(this,Cs,setTimeout((()=>{this.disposed||Je(this,ls,"m",t).call(this)}),this.fetchInterval),"f")},Rs=function(t){if(!this.cameraView)throw new Error("Camera view is not set.");if(this.cameraView.disposed)throw new Error("'cameraView' has been disposed.");if(!this.isOpen())throw new Error("Not open.");if(!Je(this,ls,"m",Is).call(this)&&!this.cameraManager.isVideoLoaded())throw new Error("Video is not loaded.");if(Je(this,ls,"m",Is).call(this)&&!this.cameraView._cvsSingleFrameMode)throw new Error("No image is selected.");const e=this.cameraView._innerComponent.getBoundingClientRect(),i=e.left,r=e.top,n=i+window.scrollX,s=r+window.scrollY,{width:o,height:a}=this.cameraView._innerComponent.getBoundingClientRect();if(o<=0||a<=0)throw new Error("Unable to get content dimensions. Camera view may not be rendered on the page.");let h,l,c;if(Je(this,ls,"m",Is).call(this)){const t=this.cameraView._innerComponent.getElement("content");h=t.width,l=t.height,c="contain"}else{const t=this.getVideoEl();h=t.videoWidth,l=t.videoHeight,c=this.cameraView.getVideoFit()}const u=o/a,d=h/l;let f,g,m,p,_=1;if("contain"===c)u{var e;if(!this.isUseMagnifier)return;if(Je(this,js,"f")||Qe(this,js,new Ys,"f"),!Je(this,js,"f").magnifierCanvas)return;document.body.contains(Je(this,js,"f").magnifierCanvas)||(Je(this,js,"f").magnifierCanvas.style.position="fixed",Je(this,js,"f").magnifierCanvas.style.boxSizing="content-box",Je(this,js,"f").magnifierCanvas.style.border="2px solid #FFFFFF",document.body.append(Je(this,js,"f").magnifierCanvas));const i=this._innerComponent.getElement("content");if(!i)return;if(t.pointer.x<0||t.pointer.x>i.width||t.pointer.y<0||t.pointer.y>i.height)return void Je(this,Vs,"f").call(this);const r=null===(e=this._drawingLayerManager._getFabricCanvas())||void 0===e?void 0:e.lowerCanvasEl;if(!r)return;const n=Math.max(i.clientWidth/5/1.5,i.clientHeight/4/1.5),s=1.5*n,o=[{image:i,width:i.width,height:i.height},{image:r,width:r.width,height:r.height}];Je(this,js,"f").update(s,t.pointer,n,o);{let e=0,i=0;t.e instanceof MouseEvent?(e=t.e.clientX,i=t.e.clientY):t.e instanceof TouchEvent&&t.e.changedTouches.length&&(e=t.e.changedTouches[0].clientX,i=t.e.changedTouches[0].clientY),e<1.5*s&&i<1.5*s?(Je(this,js,"f").magnifierCanvas.style.left="auto",Je(this,js,"f").magnifierCanvas.style.top="0",Je(this,js,"f").magnifierCanvas.style.right="0"):(Je(this,js,"f").magnifierCanvas.style.left="0",Je(this,js,"f").magnifierCanvas.style.top="0",Je(this,js,"f").magnifierCanvas.style.right="auto")}Je(this,js,"f").show()})),Vs.set(this,(()=>{Je(this,js,"f")&&Je(this,js,"f").hide()})),Gs.set(this,!1)}_setUIElement(t){this.UIElement=t,this._unbindUI(),this._bindUI()}async setUIElement(t){let e;if("string"==typeof t){let i=await Ki(t);e=document.createElement("div"),Object.assign(e.style,{width:"100%",height:"100%"}),e.attachShadow({mode:"open"}).appendChild(i)}else e=t;this._setUIElement(e)}getUIElement(){return this.UIElement}_bindUI(){if(!this.UIElement)throw new Error("Need to set 'UIElement'.");if(this._innerComponent)return;const t=this.UIElement;let e=t.classList.contains(this.containerClassName)?t:t.querySelector(`.${this.containerClassName}`);e||(e=document.createElement("div"),e.style.width="100%",e.style.height="100%",e.className=this.containerClassName,t.append(e)),this._innerComponent=document.createElement("dce-component"),e.appendChild(this._innerComponent)}_unbindUI(){var t,e,i;null===(t=this._drawingLayerManager)||void 0===t||t.clearDrawingLayers(),null===(e=this._innerComponent)||void 0===e||e.removeElement("drawing-layer"),this._layerBaseCvs=null,null===(i=this._innerComponent)||void 0===i||i.remove(),this._innerComponent=null}setImage(t,e,i){if(!this._innerComponent)throw new Error("Need to set 'UIElement'.");let r=this._innerComponent.getElement("content");r||(r=document.createElement("canvas"),r.style.objectFit="contain",this._innerComponent.setElement("content",r)),r.width===e&&r.height===i||(r.width=e,r.height=i);const n=r.getContext("2d");n.clearRect(0,0,r.width,r.height),t instanceof Uint8Array||t instanceof Uint8ClampedArray?(t instanceof Uint8Array&&(t=new Uint8ClampedArray(t.buffer)),n.putImageData(new ImageData(t,e,i),0,0)):(t instanceof HTMLCanvasElement||t instanceof HTMLImageElement)&&n.drawImage(t,0,0)}getImage(){return this._innerComponent.getElement("content")}clearImage(){if(!this._innerComponent)return;let t=this._innerComponent.getElement("content");t&&t.getContext("2d").clearRect(0,0,t.width,t.height)}removeImage(){this._innerComponent&&this._innerComponent.removeElement("content")}setOriginalImage(t){if(C(t)){Qe(this,Ns,t,"f");const{width:e,height:i,bytes:r,format:n}=Object.assign({},t);let s;if(n===a.IPF_GRAYSCALED){s=new Uint8ClampedArray(e*i*4);for(let t=0;t{if(!zs){if(!Xs&&document.currentScript){let t=document.currentScript.src,e=t.indexOf("?");if(-1!=e)t=t.substring(0,e);else{let e=t.indexOf("#");-1!=e&&(t=t.substring(0,e))}return t.substring(0,t.lastIndexOf("/")+1)}return"./"}})(),qs=t=>{if(null==t&&(t="./"),Xs||zs);else{let e=document.createElement("a");e.href=t,t=e.href}return t.endsWith("/")||(t+="/"),t};vt.engineResourcePaths.dbr={version:"10.4.31",path:Zs,isInternal:!0},mt.dbr={js:!1,wasm:!0,deps:["license","dip"]},gt.dbr={};const Ks="1.4.21";"string"!=typeof vt.engineResourcePaths.std&&D(vt.engineResourcePaths.std.version,Ks)<0&&(vt.engineResourcePaths.std={version:Ks,path:qs(Zs+`../../dynamsoft-capture-vision-std@${Ks}/dist/`),isInternal:!0});const Js="2.4.31";(!vt.engineResourcePaths.dip||"string"!=typeof vt.engineResourcePaths.dip&&D(vt.engineResourcePaths.dip.version,Js)<0)&&(vt.engineResourcePaths.dip={version:Js,path:qs(Zs+`../../dynamsoft-image-processing@${Js}/dist/`),isInternal:!0});let Qs=class{static getVersion(){const t=ft.dbr&&ft.dbr.wasm;return`10.4.31(Worker: ${ft.dbr&&ft.dbr.worker||"Not Loaded"}, Wasm: ${t||"Not Loaded"})`}};const $s={BF_NULL:BigInt(0),BF_ALL:BigInt("0xFFFFFFFEFFFFFFFF"),BF_DEFAULT:BigInt(4265345023),BF_ONED:BigInt(3147775),BF_GS1_DATABAR:BigInt(260096),BF_CODE_39:BigInt(1),BF_CODE_128:BigInt(2),BF_CODE_93:BigInt(4),BF_CODABAR:BigInt(8),BF_ITF:BigInt(16),BF_EAN_13:BigInt(32),BF_EAN_8:BigInt(64),BF_UPC_A:BigInt(128),BF_UPC_E:BigInt(256),BF_INDUSTRIAL_25:BigInt(512),BF_CODE_39_EXTENDED:BigInt(1024),BF_GS1_DATABAR_OMNIDIRECTIONAL:BigInt(2048),BF_GS1_DATABAR_TRUNCATED:BigInt(4096),BF_GS1_DATABAR_STACKED:BigInt(8192),BF_GS1_DATABAR_STACKED_OMNIDIRECTIONAL:BigInt(16384),BF_GS1_DATABAR_EXPANDED:BigInt(32768),BF_GS1_DATABAR_EXPANDED_STACKED:BigInt(65536),BF_GS1_DATABAR_LIMITED:BigInt(131072),BF_PATCHCODE:BigInt(262144),BF_CODE_32:BigInt(16777216),BF_PDF417:BigInt(33554432),BF_QR_CODE:BigInt(67108864),BF_DATAMATRIX:BigInt(134217728),BF_AZTEC:BigInt(268435456),BF_MAXICODE:BigInt(536870912),BF_MICRO_QR:BigInt(1073741824),BF_MICRO_PDF417:BigInt(524288),BF_GS1_COMPOSITE:BigInt(2147483648),BF_MSI_CODE:BigInt(1048576),BF_CODE_11:BigInt(2097152),BF_TWO_DIGIT_ADD_ON:BigInt(4194304),BF_FIVE_DIGIT_ADD_ON:BigInt(8388608),BF_MATRIX_25:BigInt(68719476736),BF_POSTALCODE:BigInt(0x3f0000000000000),BF_NONSTANDARD_BARCODE:BigInt(4294967296),BF_USPSINTELLIGENTMAIL:BigInt(4503599627370496),BF_POSTNET:BigInt(9007199254740992),BF_PLANET:BigInt(0x40000000000000),BF_AUSTRALIANPOST:BigInt(0x80000000000000),BF_RM4SCC:BigInt(72057594037927940),BF_KIX:BigInt(0x200000000000000),BF_DOTCODE:BigInt(8589934592),BF_PHARMACODE_ONE_TRACK:BigInt(17179869184),BF_PHARMACODE_TWO_TRACK:BigInt(34359738368),BF_PHARMACODE:BigInt(51539607552)};var to,eo,io,ro;!function(t){t[t.EBRT_STANDARD_RESULT=0]="EBRT_STANDARD_RESULT",t[t.EBRT_CANDIDATE_RESULT=1]="EBRT_CANDIDATE_RESULT",t[t.EBRT_PARTIAL_RESULT=2]="EBRT_PARTIAL_RESULT"}(to||(to={})),function(t){t[t.QRECL_ERROR_CORRECTION_H=0]="QRECL_ERROR_CORRECTION_H",t[t.QRECL_ERROR_CORRECTION_L=1]="QRECL_ERROR_CORRECTION_L",t[t.QRECL_ERROR_CORRECTION_M=2]="QRECL_ERROR_CORRECTION_M",t[t.QRECL_ERROR_CORRECTION_Q=3]="QRECL_ERROR_CORRECTION_Q"}(eo||(eo={})),function(t){t[t.LM_AUTO=1]="LM_AUTO",t[t.LM_CONNECTED_BLOCKS=2]="LM_CONNECTED_BLOCKS",t[t.LM_STATISTICS=4]="LM_STATISTICS",t[t.LM_LINES=8]="LM_LINES",t[t.LM_SCAN_DIRECTLY=16]="LM_SCAN_DIRECTLY",t[t.LM_STATISTICS_MARKS=32]="LM_STATISTICS_MARKS",t[t.LM_STATISTICS_POSTAL_CODE=64]="LM_STATISTICS_POSTAL_CODE",t[t.LM_CENTRE=128]="LM_CENTRE",t[t.LM_ONED_FAST_SCAN=256]="LM_ONED_FAST_SCAN",t[t.LM_REV=-2147483648]="LM_REV",t[t.LM_SKIP=0]="LM_SKIP"}(io||(io={})),function(t){t[t.DM_DIRECT_BINARIZATION=1]="DM_DIRECT_BINARIZATION",t[t.DM_THRESHOLD_BINARIZATION=2]="DM_THRESHOLD_BINARIZATION",t[t.DM_GRAY_EQUALIZATION=4]="DM_GRAY_EQUALIZATION",t[t.DM_SMOOTHING=8]="DM_SMOOTHING",t[t.DM_MORPHING=16]="DM_MORPHING",t[t.DM_DEEP_ANALYSIS=32]="DM_DEEP_ANALYSIS",t[t.DM_SHARPENING=64]="DM_SHARPENING",t[t.DM_BASED_ON_LOC_BIN=128]="DM_BASED_ON_LOC_BIN",t[t.DM_SHARPENING_SMOOTHING=256]="DM_SHARPENING_SMOOTHING",t[t.DM_REV=-2147483648]="DM_REV",t[t.DM_SKIP=0]="DM_SKIP"}(ro||(ro={}));const no=async t=>{let e;await new Promise(((i,r)=>{e=new Image,e.onload=()=>i(e),e.onerror=r,e.src=URL.createObjectURL(t)}));const i=document.createElement("canvas"),r=i.getContext("2d");return i.width=e.width,i.height=e.height,r.drawImage(e,0,0),{bytes:Uint8Array.from(r.getImageData(0,0,i.width,i.height).data),width:i.width,height:i.height,stride:4*i.width,format:10}};class so{async saveToFile(t,e,i){if(!t||!e)return null;if("string"!=typeof e)throw new TypeError("FileName must be of type string.");const r=B(t);return M(r,e,i)}async drawOnImage(t,e,i,r=4294901760,n=1,s){let o;if(t instanceof Blob)o=await no(t);else if("string"==typeof t){let e=await O(t,"blob");o=await no(e)}return await new Promise(((t,a)=>{let h=at();ht[h]=async e=>{if(e.success)return s&&this.saveToFile(e.image,"test.png",s),t(e.image);{let t=new Error(e.message);return t.stack=e.stack+"\n"+t.stack,a(t)}},st.postMessage({type:"utility_drawOnImage",id:h,body:{dsImage:o,drawingItem:e instanceof Array?e:[e],color:r,thickness:n,type:i}})}))}}const oo="undefined"==typeof self,ao="function"==typeof importScripts,ho=(()=>{if(!ao){if(!oo&&document.currentScript){let t=document.currentScript.src,e=t.indexOf("?");if(-1!=e)t=t.substring(0,e);else{let e=t.indexOf("#");-1!=e&&(t=t.substring(0,e))}return t.substring(0,t.lastIndexOf("/")+1)}return"./"}})(),lo=t=>{if(null==t&&(t="./"),oo||ao);else{let e=document.createElement("a");e.href=t,t=e.href}return t.endsWith("/")||(t+="/"),t};vt.engineResourcePaths.utility={version:"1.4.32",path:ho,isInternal:!0},mt.utility={js:!0,wasm:!0};const co="1.4.21";"string"!=typeof vt.engineResourcePaths.std&&D(vt.engineResourcePaths.std.version,co)<0&&(vt.engineResourcePaths.std={version:co,path:lo(ho+`../../dynamsoft-capture-vision-std@${co}/dist/`),isInternal:!0});const uo="2.4.31";(!vt.engineResourcePaths.dip||"string"!=typeof vt.engineResourcePaths.dip&&D(vt.engineResourcePaths.dip.version,uo)<0)&&(vt.engineResourcePaths.dip={version:uo,path:lo(ho+`../../dynamsoft-image-processing@${uo}/dist/`),isInternal:!0});class fo{static getVersion(){return`1.4.32(Worker: ${ft.utility&&ft.utility.worker||"Not Loaded"}, Wasm: ${ft.utility&&ft.utility.wasm||"Not Loaded"})`}}function go(t,e,i,r){if("a"===i&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?r:"a"===i?r.call(t):r?r.value:e.get(t)}var mo,po,_o,vo,yo;function wo(t,e){let i=!0;for(let o=0;o1)return Math.sqrt((h-o)**2+(l-a)**2);{const t=n+u*(o-n),e=s+u*(a-s);return Math.sqrt((h-t)**2+(l-e)**2)}}function To(t){const e=[];for(let i=0;i=0&&h<=1&&l>=0&&l<=1?{x:t.x+l*n,y:t.y+l*s}:null}function Io(t){let e=0;for(let i=0;i0}function Ao(t,e){for(let i=0;i<4;i++)if(!xo(t.points[i],t.points[(i+1)%4],e))return!1;return!0}"function"==typeof SuppressedError&&SuppressedError;function Oo(t,e,i,r){const n=t.points,s=e.points;let o=8*i;o=Math.max(o,5);const a=To(n)[3],h=To(n)[1],l=To(s)[3],c=To(s)[1];let u,d=0;if(u=Math.max(Math.abs(Eo(a,e.points[0])),Math.abs(Eo(a,e.points[3]))),u>d&&(d=u),u=Math.max(Math.abs(Eo(h,e.points[1])),Math.abs(Eo(h,e.points[2]))),u>d&&(d=u),u=Math.max(Math.abs(Eo(l,t.points[0])),Math.abs(Eo(l,t.points[3]))),u>d&&(d=u),u=Math.max(Math.abs(Eo(c,t.points[1])),Math.abs(Eo(c,t.points[2]))),u>d&&(d=u),d>o)return!1;const f=So(To(n)[0]),g=So(To(n)[2]),m=So(To(s)[0]),p=So(To(s)[2]),_=Co(f,p),v=Co(m,g),y=_>v,w=Math.min(_,v),C=Co(f,g),E=Co(m,p);let T=12*i;return T=Math.max(T,5),T=Math.min(T,C),T=Math.min(T,E),!!(w{e.x+=t,e.y+=i})),e.x/=t.length,e.y/=t.length,e}isProbablySameLocationWithOffset(t,e){const i=this.item.location,r=t.location;if(i.area<=0)return!1;if(Math.abs(i.area-r.area)>.4*i.area)return!1;let n=new Array(4).fill(0),s=new Array(4).fill(0),o=0,a=0;for(let t=0;t<4;++t)n[t]=Math.round(100*(r.points[t].x-i.points[t].x))/100,o+=n[t],s[t]=Math.round(100*(r.points[t].y-i.points[t].y))/100,a+=s[t];o/=4,a/=4;for(let t=0;t<4;++t){if(Math.abs(n[t]-o)>this.strictLimit||Math.abs(o)>.8)return!1;if(Math.abs(s[t]-a)>this.strictLimit||Math.abs(a)>.8)return!1}return e.x=o,e.y=a,!0}isLocationOverlap(t,e){if(this.locationArea>e){for(let e=0;e<4;e++)if(Ao(this.location,t.points[e]))return!0;const e=this.getCenterPoint(t.points);if(Ao(this.location,e))return!0}else{for(let e=0;e<4;e++)if(Ao(t,this.location.points[e]))return!0;if(Ao(t,this.getCenterPoint(this.location.points)))return!0}return!1}isMatchedLocationWithOffset(t,e={x:0,y:0}){if(this.isOneD){const i=Object.assign({},t.location);for(let t=0;t<4;t++)i.points[t].x-=e.x,i.points[t].y-=e.y;if(!this.isLocationOverlap(i,t.locationArea))return!1;const r=[this.location.points[0],this.location.points[3]],n=[this.location.points[1],this.location.points[2]];for(let t=0;t<4;t++){const e=i.points[t],s=0===t||3===t?r:n;if(Math.abs(Eo(s,e))>this.locationThreshold)return!1}}else for(let i=0;i<4;i++){const r=t.location.points[i],n=this.location.points[i];if(!(Math.abs(n.x+e.x-r.x)=this.locationThreshold)return!1}return!0}isOverlappedLocationWithOffset(t,e,i=!0){const r=Object.assign({},t.location);for(let t=0;t<4;t++)r.points[t].x-=e.x,r.points[t].y-=e.y;if(!this.isLocationOverlap(r,t.location.area))return!1;if(i){const t=.75;return function(t,e){const i=[];for(let r=0;r<4;r++)for(let n=0;n<4;n++){const s=bo(t[r],t[(r+1)%4],e[n],e[(n+1)%4]);s&&i.push(s)}return t.forEach((t=>{wo(e,t)&&i.push(t)})),e.forEach((e=>{wo(t,e)&&i.push(e)})),Io(function(t){if(t.length<=1)return t;t.sort(((t,e)=>t.x-e.x||t.y-e.y));const e=t.shift();return t.sort(((t,i)=>Math.atan2(t.y-e.y,t.x-e.x)-Math.atan2(i.y-e.y,i.x-e.x))),[e,...t]}(i))}([...this.location.points],r.points)>this.locationArea*t}return!0}}const Do={BF_ONED:BigInt(3147775),BF_GS1_DATABAR:BigInt(260096)},Lo={barcode:2,text_line:4,detected_quad:8,normalized_image:16},Mo=t=>Object.values(Lo).includes(t)||Lo.hasOwnProperty(t),Fo=(t,e)=>"string"==typeof t?e[Lo[t]]:e[t],Po=(t,e,i)=>{"string"==typeof t?e[Lo[t]]=i:e[t]=i},ko=(t,e,i)=>{const r=[8,16].includes(i);if(!r&&t.isResultCrossVerificationEnabled(i))for(let t=0;t{Po(e,this.verificationEnabled,t)})),go(this,po,"f").forEach(((t,e)=>{Po(e,this.duplicateFilterEnabled,t)})),go(this,_o,"f").forEach(((t,e)=>{Po(e,this.duplicateForgetTime,t)})),go(this,vo,"f").forEach(((t,e)=>{Po(e,this.latestOverlappingEnabled,t)})),go(this,yo,"f").forEach(((t,e)=>{Po(e,this.maxOverlappingFrames,t)}))}enableResultCrossVerification(t,e){Mo(t)&&go(this,mo,"f").set(t,e)}isResultCrossVerificationEnabled(t){return!!Mo(t)&&Fo(t,this.verificationEnabled)}enableResultDeduplication(t,e){Mo(t)&&(e&&this.enableLatestOverlapping(t,!1),go(this,po,"f").set(t,e))}isResultDeduplicationEnabled(t){return!!Mo(t)&&Fo(t,this.duplicateFilterEnabled)}setDuplicateForgetTime(t,e){Mo(t)&&(e>18e4&&(e=18e4),e<0&&(e=0),go(this,_o,"f").set(t,e))}getDuplicateForgetTime(t){return Mo(t)?Fo(t,this.duplicateForgetTime):-1}setMaxOverlappingFrames(t,e){Mo(t)&&go(this,yo,"f").set(t,e)}getMaxOverlappingFrames(t){return Mo(t)?Fo(t,this.maxOverlappingFrames):-1}enableLatestOverlapping(t,e){Mo(t)&&(e&&this.enableResultDeduplication(t,!1),go(this,vo,"f").set(t,e))}isLatestOverlappingEnabled(t){return!!Mo(t)&&Fo(t,this.latestOverlappingEnabled)}getFilteredResultItemTypes(){let t=0;const e=[yt.CRIT_BARCODE,yt.CRIT_TEXT_LINE,yt.CRIT_DETECTED_QUAD,yt.CRIT_NORMALIZED_IMAGE];for(let i=0;i{if(1!==t.type){const e=(BigInt(t.format)&BigInt(Do.BF_ONED))!=BigInt(0)||(BigInt(t.format)&BigInt(Do.BF_GS1_DATABAR))!=BigInt(0);return new Ro(h,e?1:2,e,t)}})).filter(Boolean);if(this.overlapSet.length>0){const t=new Array(l).fill(new Array(this.overlapSet.length).fill(1));let e=0;for(;e-1!==t)).length;n>p&&(p=n,m=r,g.x=i.x,g.y=i.y)}}if(0===p){for(let e=0;e-1!=t)).length}let i=this.overlapSet.length<=3?p>=1:p>=2;if(!i&&s&&u>0){let t=0;for(let e=0;e=1:t>=3}i||(this.overlapSet=[])}if(0===this.overlapSet.length)this.stabilityCount=0,t.items.forEach(((t,e)=>{if(1!==t.type){const i=Object.assign({},t),r=(BigInt(t.format)&BigInt(Do.BF_ONED))!=BigInt(0)||(BigInt(t.format)&BigInt(Do.BF_GS1_DATABAR))!=BigInt(0),s=t.confidence5||Math.abs(g.y)>5)&&(e=!1):e=!1;for(let i=0;i0){for(let t=0;t!(t.overlapCount+this.stabilityCount<=0&&t.crossVerificationFrame<=0)))}f.sort(((t,e)=>e-t)).forEach(((e,i)=>{t.items.splice(e,1)})),d.forEach((e=>{t.items.push(Object.assign(Object.assign({},e),{overlapped:!0}))}))}}onDecodedBarcodesReceived(t){this.latestOverlappingFilter(t),ko(this,t.items,yt.CRIT_BARCODE)}onRecognizedTextLinesReceived(t){ko(this,t.items,yt.CRIT_TEXT_LINE)}onDetectedQuadsReceived(t){ko(this,t.items,yt.CRIT_DETECTED_QUAD)}onNormalizedImagesReceived(t){ko(this,t.items,yt.CRIT_NORMALIZED_IMAGE)}}mo=new WeakMap,po=new WeakMap,_o=new WeakMap,vo=new WeakMap,yo=new WeakMap,de._defaultTemplate="ReadSingleBarcode";export{Qs as BarcodeReaderModule,Ps as CameraEnhancer,Ke as CameraEnhancerModule,Br as CameraView,de as CaptureVisionRouter,Zt as CaptureVisionRouterModule,pe as CapturedResultReceiver,vt as CoreModule,bi as DrawingItem,Dr as DrawingStyleManager,$s as EnumBarcodeFormat,s as EnumBufferOverflowProtectionMode,yt as EnumCapturedResultItemType,o as EnumColourChannelUsageType,wt as EnumCornerType,xt as EnumCrossVerificationStatus,ro as EnumDeblurMode,ai as EnumDrawingItemMediaType,hi as EnumDrawingItemState,li as EnumEnhancedFeatures,Ct as EnumErrorCode,to as EnumExtendedBarcodeResultType,Et as EnumGrayscaleEnhancementMode,Tt as EnumGrayscaleTransformationMode,a as EnumImagePixelFormat,Kt as EnumImageSourceState,St as EnumImageTagType,At as EnumIntermediateResultUnitType,io as EnumLocalizationMode,bt as EnumPDFReadingMode,ve as EnumPresetTemplate,eo as EnumQRCodeErrorCorrectionLevel,It as EnumRasterDataSource,Ot as EnumRegionObjectElementType,Rt as EnumSectionType,Ls as Feedback,ji as GroupDrawingItem,Li as ImageDrawingItem,Hs as ImageEditorView,so as ImageManager,J as ImageSourceAdapter,_e as IntermediateResultReceiver,je as LicenseManager,Ve as LicenseModule,Bi as LineDrawingItem,Bo as MultiFrameResultCrossFilter,Ni as QuadDrawingItem,Ii as RectDrawingItem,Fi as TextDrawingItem,fo as UtilityModule,B as _getNorImageData,M as _saveToFile,k as _toBlob,F as _toCanvas,P as _toImage,ut as bDebug,R as checkIsLink,D as compareVersion,nt as doOrWaitAsyncDependency,at as getNextTaskID,L as handleEngineResourcePaths,ft as innerVersions,_ as isArc,v as isContour,C as isDSImageData,E as isDSRect,T as isImageTag,S as isLineSegment,p as isObject,w as isOriginalDsImageData,b as isPoint,I as isPolygon,x as isQuad,A as isRect,_t as loadWasm,it as mapAsyncDependency,gt as mapPackageRegister,ht as mapTaskCallBack,lt as onLog,O as requestResource,dt as setBDebug,ct as setOnLog,rt as waitAsyncDependency,st as worker,mt as workerAutoResources};
diff --git a/dist/dbr.no-content-bundle.esm.js b/dist/dbr.no-content-bundle.esm.js
index 200f8f6..ccd0ac5 100644
--- a/dist/dbr.no-content-bundle.esm.js
+++ b/dist/dbr.no-content-bundle.esm.js
@@ -2,10 +2,10 @@
* Dynamsoft JavaScript Library
* @product Dynamsoft Barcode Reader JS Edition Bundle
* @website http://www.dynamsoft.com
-* @copyright Copyright 2024, Dynamsoft Corporation
+* @copyright Copyright 2025, Dynamsoft Corporation
* @author Dynamsoft
-* @version 10.4.2002
+* @version 10.4.3100
* @fileoverview Dynamsoft JavaScript Library for Barcode Reader
* More info on dbr JS: https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/
*/
-export*from"dynamsoft-core";export*from"dynamsoft-license";export*from"dynamsoft-capture-vision-router";export*from"dynamsoft-camera-enhancer";export*from"dynamsoft-barcode-reader";export*from"dynamsoft-utility";
+import{CaptureVisionRouter as o}from"dynamsoft-capture-vision-router";export*from"dynamsoft-capture-vision-router";export*from"dynamsoft-core";export*from"dynamsoft-license";export*from"dynamsoft-camera-enhancer";export*from"dynamsoft-barcode-reader";export*from"dynamsoft-utility";o._defaultTemplate="ReadSingleBarcode";
diff --git a/package.json b/package.json
index 06e7deb..5de9810 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "dynamsoft-barcode-reader-bundle",
- "version": "10.4.2002",
+ "version": "10.4.3100",
"description": "Dynamsoft Barcode Reader JS is a recognition SDK which enables you to embed barcode reading functionality in your web, desktop, and mobile applications. With a few lines of JavaScript code, you can develop a robust application to scan a linear barcode, QR Code, DaraMatrix, PDF417, and Aztec Code.",
"main": "dist/dbr.bundle.js",
"module": "dist/dbr.no-content-bundle.esm.js",
@@ -20,7 +20,9 @@
"files": [
"/dist",
"LEGAL.txt",
- "LICENSE"
+ "LICENSE",
+ "samples.url",
+ "API Reference.url"
],
"scripts": {
"build": "rollup -c --environment BUILD:production",
@@ -64,7 +66,7 @@
"tag": "latest"
},
"devDependencies": {
- "@dynamsoft/rd2-scripts": "^0.1.27",
+ "@dynamsoft/rd2-scripts": "^0.1.36",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-terser": "^0.4.4",
@@ -76,11 +78,11 @@
"typescript": "^4.9.5"
},
"dependencies": {
- "dynamsoft-barcode-reader": "10.4.20",
- "dynamsoft-camera-enhancer": "4.1.0",
- "dynamsoft-capture-vision-router": "2.4.22",
- "dynamsoft-core": "3.4.21",
- "dynamsoft-license": "3.4.21",
- "dynamsoft-utility": "1.4.21"
+ "dynamsoft-barcode-reader": "10.4.31",
+ "dynamsoft-camera-enhancer": "4.1.1",
+ "dynamsoft-capture-vision-router": "2.4.33",
+ "dynamsoft-core": "3.4.31",
+ "dynamsoft-license": "3.4.31",
+ "dynamsoft-utility": "1.4.32"
}
}
diff --git a/samples.url b/samples.url
index 518ce30..7ef97fa 100644
--- a/samples.url
+++ b/samples.url
@@ -1,2 +1,2 @@
[InternetShortcut]
-URL=https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/v10.4.20
\ No newline at end of file
+URL=https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/v10.4.31
\ No newline at end of file