h||e.sy+e.sHeight>l)throw new Error("Invalid position.");null===(n=Lr._onLog)||void 0===n||n.call(Lr,"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)||li.RGBA,w=null==i?void 0:i.bufferContainer;if(w&&(li.GREY===y&&w.length{if(!i)return t;let r=e+Math.round((t-e)/i)*i;return n&&(r=Math.min(r,n)),r};class Fr{static get version(){return"4.2.12-dev-20250709132053"}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"],n=["듀얼 와이드","雙廣角","双广角","デュアル広角","คู่ด้านหลังมุมกว้าง","ड्युअल वाइड","مزدوجة عريضة","כפולה רחבה","қос кең бұрышты","здвоєна ширококутна","двойная широкоугольная","двойна широкоъгълна","διπλή ευρεία","ç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"],r=t.filter(t=>{const i=t.label.toLowerCase();return e.some(t=>i.includes(t))});if(!r.length)return null;const s=r.find(t=>{const e=t.label.toLowerCase();return i.some(t=>e.includes(t))});if(s)return s.deviceId;const o=r.find(t=>{const e=t.label.toLowerCase();return n.some(t=>e.includes(t))});return o?o.deviceId:r[0].deviceId}}static findBestRearCamera(t,e){if(!t||!t.length)return null;if(["iPhone","iPad","Mac"].includes(qe.OS))return Fr.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(qe.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(n,r)=>{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(),n(t)},l=t=>{s&&clearTimeout(s),o(),r(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(),r(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 n;try{n=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==n||n.getTracks().forEach(t=>{t.stop()})}return{ok:!0}}get state(){if(!Ze(this,Jn,"f"))return"closed";if("pending"===Ze(this,Jn,"f"))return"opening";if("fulfilled"===Ze(this,Jn,"f"))return"opened";throw new Error("Unknown state.")}set ifSaveLastUsedCamera(t){t?Fr.isStorageAvailable("localStorage")?Je(this,zn,!0,"f"):(Je(this,zn,!1,"f"),console.warn("Local storage is unavailable")):Je(this,zn,!1,"f")}get ifSaveLastUsedCamera(){return Ze(this,zn,"f")}get isVideoPlaying(){return!(!Ze(this,Un,"f")||Ze(this,Un,"f").paused)&&"opened"===this.state}set tapFocusEventBoundEl(t){var e,i,n;if(!(t instanceof HTMLElement)&&null!=t)throw new TypeError("Invalid 'element'.");null===(e=Ze(this,nr,"f"))||void 0===e||e.removeEventListener("click",Ze(this,ir,"f")),null===(i=Ze(this,nr,"f"))||void 0===i||i.removeEventListener("touchend",Ze(this,ir,"f")),null===(n=Ze(this,nr,"f"))||void 0===n||n.removeEventListener("touchmove",Ze(this,er,"f")),Je(this,nr,t,"f"),t&&(window.TouchEvent&&["Android","HarmonyOS","iPhone","iPad"].includes(qe.OS)?(t.addEventListener("touchend",Ze(this,ir,"f")),t.addEventListener("touchmove",Ze(this,er,"f"))):t.addEventListener("click",Ze(this,ir,"f")))}get tapFocusEventBoundEl(){return Ze(this,nr,"f")}get disposed(){return Ze(this,dr,"f")}constructor(t){var e,i;jn.add(this),Un.set(this,null),Vn.set(this,void 0),this._zoomPreSetting=null,Gn.set(this,()=>{"opened"===this.state&&Ze(this,ar,"f").fire("resumed",null,{target:this,async:!1})}),Wn.set(this,()=>{Ze(this,ar,"f").fire("paused",null,{target:this,async:!1})}),Yn.set(this,void 0),Hn.set(this,void 0),this.cameraOpenTimeout=15e3,this._arrCameras=[],Xn.set(this,void 0),zn.set(this,!1),this.ifSkipCameraInspection=!1,this.selectIOSRearMainCameraAsDefault=!1,qn.set(this,void 0),Kn.set(this,!0),Zn.set(this,void 0),Jn.set(this,void 0),$n.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},Qn.set(this,!1),this._focusSupported=!0,this.calculateCoordInVideo=(t,e)=>{let i,n;const r=window.getComputedStyle(Ze(this,Un,"f")).objectFit,s=this.getResolution(),o=Ze(this,Un,"f").getBoundingClientRect(),a=o.left,h=o.top,{width:l,height:c}=Ze(this,Un,"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"===r)d>u?(f=l/s.width,i=(t-a)/f,n=(e-h-(c-l/d)/2)/f):(f=c/s.height,n=(e-h)/f,i=(t-a-(l-c*d)/2)/f);else{if("cover"!==r)throw new Error("Unsupported object-fit.");d>u?(f=c/s.height,n=(e-h)/f,i=(t-a+(c*d-l)/2)/f):(f=l/s.width,i=(t-a)/f,n=(e-h+(l/d-c)/2)/f)}return{x:i,y:n}},tr.set(this,!1),er.set(this,()=>{Je(this,tr,!0,"f")}),ir.set(this,async t=>{var e;if(Ze(this,tr,"f"))return void Je(this,tr,!1,"f");if(!Ze(this,Qn,"f"))return;if(!this.isVideoPlaying)return;if(!Ze(this,Vn,"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,n;if(this._focusParameters.taskBackToContinous&&(clearTimeout(this._focusParameters.taskBackToContinous),this._focusParameters.taskBackToContinous=null),t instanceof MouseEvent)i=t.clientX,n=t.clientY;else{if(!(t instanceof TouchEvent))throw new Error("Unknown event type.");if(!t.changedTouches.length)return;i=t.changedTouches[0].clientX,n=t.changedTouches[0].clientY}const r=this.getResolution(),s=2*Math.round(Math.min(r.width,r.height)/this._focusParameters.defaultFocusAreaSizeRatio/2);let o;try{o=this.calculateCoordInVideo(i,n)}catch(t){}if(o.x<0||o.x>r.width||o.y<0||o.y>r.height)return;const a={x:o.x+"px",y:o.y+"px"},h=s+"px",l=h;let c;Fr._onLog&&(c=Date.now());try{await Ze(this,jn,"m",Er).call(this,a,h,l,this._focusParameters.tapFocusMinDistance,this._focusParameters.tapFocusMaxDistance)}catch(t){if(Fr._onLog)throw Fr._onLog(t),t}Fr._onLog&&Fr._onLog(`Tap focus costs: ${Date.now()-c} ms`),this._focusParameters.taskBackToContinous=setTimeout(()=>{var t;Fr._onLog&&Fr._onLog("Back to continuous focus."),null===(t=Ze(this,Vn,"f"))||void 0===t||t.applyConstraints({advanced:[{focusMode:"continuous"}]}).catch(()=>{})},this._focusParameters.focusBackToContinousTime),Ze(this,ar,"f").fire("tapfocus",null,{target:this,async:!1})}),nr.set(this,null),rr.set(this,1),sr.set(this,{x:0,y:0}),this.updateVideoElWhenSoftwareScaled=()=>{if(!Ze(this,Un,"f"))return;const t=Ze(this,rr,"f");if(t<1)throw new RangeError("Invalid scale value.");if(1===t)Ze(this,Un,"f").style.transform="";else{const e=window.getComputedStyle(Ze(this,Un,"f")).objectFit,i=Ze(this,Un,"f").videoWidth,n=Ze(this,Un,"f").videoHeight,{width:r,height:s}=Ze(this,Un,"f").getBoundingClientRect();if(r<=0||s<=0)throw new Error("Unable to get video dimensions. Video may not be rendered on the page.");const o=r/s,a=i/n;let h=1;"contain"===e?h=oo?s/(i/t):r/(n/t));const l=h*(1-1/t)*(i/2-Ze(this,sr,"f").x),c=h*(1-1/t)*(n/2-Ze(this,sr,"f").y);Ze(this,Un,"f").style.transform=`translate(${l}px, ${c}px) scale(${t})`}},or.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===li.GREY){e=new Uint8ClampedArray(this.width*this.height*4);for(let t=0;t{var t,e;if("visible"===document.visibilityState){if(Fr._onLog&&Fr._onLog("document visible. video paused: "+(null===(t=Ze(this,Un,"f"))||void 0===t?void 0:t.paused)),"opening"==this.state||"opened"==this.state){let e=!1;if(!this.isVideoPlaying){Fr._onLog&&Fr._onLog("document visible. Not auto resume. 1st resume start.");try{await this.resume(),e=!0}catch(t){Fr._onLog&&Fr._onLog("document visible. 1st resume video failed, try open instead.")}e||await Ze(this,jn,"m",_r).call(this)}if(await new Promise(t=>setTimeout(t,300)),!this.isVideoPlaying){Fr._onLog&&Fr._onLog("document visible. 1st open failed. 2rd resume start."),e=!1;try{await this.resume(),e=!0}catch(t){Fr._onLog&&Fr._onLog("document visible. 2rd resume video failed, try open instead.")}e||await Ze(this,jn,"m",_r).call(this)}}}else"hidden"===document.visibilityState&&(Fr._onLog&&Fr._onLog("document hidden. video paused: "+(null===(e=Ze(this,Un,"f"))||void 0===e?void 0:e.paused)),"opening"==this.state||"opened"==this.state&&this.isVideoPlaying&&this.pause())}),dr.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(()=>{Fr.onWarning&&Fr.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),Je(this,ar,new Hi,"f"),this.imageDataGetter=new Lr,document.addEventListener("visibilitychange",Ze(this,ur,"f"))}setVideoEl(t){if(!(t&&t instanceof HTMLVideoElement))throw new Error("Invalid 'videoEl'.");t.addEventListener("play",Ze(this,Gn,"f")),t.addEventListener("pause",Ze(this,Wn,"f")),Je(this,Un,t,"f")}getVideoEl(){return Ze(this,Un,"f")}releaseVideoEl(){var t,e;null===(t=Ze(this,Un,"f"))||void 0===t||t.removeEventListener("play",Ze(this,Gn,"f")),null===(e=Ze(this,Un,"f"))||void 0===e||e.removeEventListener("pause",Ze(this,Wn,"f")),Je(this,Un,null,"f")}isVideoLoaded(){return!!Ze(this,Un,"f")&&4==Ze(this,Un,"f").readyState}async open(){if(Ze(this,Zn,"f")&&!Ze(this,Kn,"f")){if("pending"===Ze(this,Jn,"f"))return Ze(this,Zn,"f");if("fulfilled"===Ze(this,Jn,"f"))return}Ze(this,ar,"f").fire("before:open",null,{target:this}),await Ze(this,jn,"m",_r).call(this),Ze(this,ar,"f").fire("played",null,{target:this,async:!1}),Ze(this,ar,"f").fire("opened",null,{target:this,async:!1})}async close(){if("closed"===this.state)return;Ze(this,ar,"f").fire("before:close",null,{target:this});const t=Ze(this,Zn,"f");if(Ze(this,jn,"m",yr).call(this),t&&"pending"===Ze(this,Jn,"f")){try{await t}catch(t){}if(!1===Ze(this,Kn,"f")){const t=new Error("'close()' was interrupted.");throw t.name="AbortError",t}}Je(this,Zn,null,"f"),Je(this,Jn,null,"f"),Ze(this,ar,"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.");Ze(this,Un,"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 Ze(this,Un,"f").play()}async setCamera(t){if("string"!=typeof t)throw new TypeError("Invalid 'deviceId'.");if("object"!=typeof Ze(this,Yn,"f").video&&(Ze(this,Yn,"f").video={}),delete Ze(this,Yn,"f").video.facingMode,Ze(this,Yn,"f").video.deviceId={exact:t},!("closed"===this.state||this.videoSrc||"opening"===this.state&&Ze(this,Kn,"f"))){Ze(this,ar,"f").fire("before:camera:change",[],{target:this,async:!1}),await Ze(this,jn,"m",vr).call(this);try{this.resetSoftwareScale()}catch(t){}return Ze(this,Hn,"f")}}async switchToFrontCamera(t){if("object"!=typeof Ze(this,Yn,"f").video&&(Ze(this,Yn,"f").video={}),(null==t?void 0:t.resolution)&&(Ze(this,Yn,"f").video.width={ideal:t.resolution.width},Ze(this,Yn,"f").video.height={ideal:t.resolution.height}),delete Ze(this,Yn,"f").video.deviceId,Ze(this,Yn,"f").video.facingMode={exact:"user"},Je(this,Xn,null,"f"),!("closed"===this.state||this.videoSrc||"opening"===this.state&&Ze(this,Kn,"f"))){Ze(this,ar,"f").fire("before:camera:change",[],{target:this,async:!1}),Ze(this,jn,"m",vr).call(this);try{this.resetSoftwareScale()}catch(t){}return Ze(this,Hn,"f")}}getCamera(){var t;if(Ze(this,Hn,"f"))return Ze(this,Hn,"f");{let e=(null===(t=Ze(this,Yn,"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 n=[];if(t)try{let t=await navigator.mediaDevices.getUserMedia({video:!0});n=(await navigator.mediaDevices.enumerateDevices()).filter(t=>"videoinput"===t.kind),t.getTracks().forEach(t=>{t.stop()})}catch(t){console.error(t.message||t)}else n=(await navigator.mediaDevices.enumerateDevices()).filter(t=>"videoinput"===t.kind);const r=[],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 Ze(this,Yn,"f").video&&(Ze(this,Yn,"f").video={}),i?(Ze(this,Yn,"f").video.width={exact:t},Ze(this,Yn,"f").video.height={exact:e}):(Ze(this,Yn,"f").video.width={ideal:t},Ze(this,Yn,"f").video.height={ideal:e}),"closed"===this.state||this.videoSrc||"opening"===this.state&&Ze(this,Kn,"f"))return null;Ze(this,ar,"f").fire("before:resolution:change",[],{target:this,async:!1}),await Ze(this,jn,"m",vr).call(this);try{this.resetSoftwareScale()}catch(t){}const n=this.getResolution();return{width:n.width,height:n.height}}getResolution(){if("opened"===this.state&&this.videoSrc&&Ze(this,Un,"f"))return{width:Ze(this,Un,"f").videoWidth,height:Ze(this,Un,"f").videoHeight};if(Ze(this,Vn,"f")){const t=Ze(this,Vn,"f").getSettings();return{width:t.width,height:t.height}}if(this.isVideoLoaded())return{width:Ze(this,Un,"f").videoWidth,height:Ze(this,Un,"f").videoHeight};{const t={width:0,height:0};let e=Ze(this,Yn,"f").video.width||0,i=Ze(this,Yn,"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,n,r,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=Ze(this,lr,"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=Ze(this,Hn,"f"))||void 0===u?void 0:u.deviceId;let e=Ze(this,lr,"f").get(d);if(e&&!t)return JSON.parse(JSON.stringify(e));e=[],Ze(this,lr,"f").set(d,e),Je(this,$n,!0,"f");try{for(let t of this.detectedResolutions){await Ze(this,Vn,"f").applyConstraints({width:{ideal:t.width},height:{ideal:t.height}}),Ze(this,jn,"m",gr).call(this);const i=Ze(this,Vn,"f").getSettings(),n={width:i.width,height:i.height};f(d,n)||e.push({width:n.width,height:n.height})}}catch(t){throw Ze(this,jn,"m",yr).call(this),Je(this,$n,!1,"f"),t}try{await Ze(this,jn,"m",_r).call(this)}catch(t){if("AbortError"===t.name)return e;throw t}finally{Je(this,$n,!1,"f")}return e}{const e=async(t,e,i)=>{const n={video:{deviceId:{exact:t},width:{ideal:e},height:{ideal:i}}};let r=null;try{r=await navigator.mediaDevices.getUserMedia(n)}catch(t){return null}if(!r)return null;const s=r.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=r,o={width:e.videoWidth,height:e.videoHeight},e.srcObject=null}return s.forEach(t=>{t.stop()}),o};let i=(null===(s=null===(r=null===(n=Ze(this,Yn,"f"))||void 0===n?void 0:n.video)||void 0===r?void 0:r.deviceId)||void 0===s?void 0:s.exact)||(null===(h=null===(a=null===(o=Ze(this,Yn,"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=Ze(this,Yn,"f"))||void 0===l?void 0:l.video)||void 0===c?void 0:c.deviceId);if(!i)return[];let u=Ze(this,lr,"f").get(i);if(u&&!t)return JSON.parse(JSON.stringify(u));u=[],Ze(this,lr,"f").set(i,u);for(let t of this.detectedResolutions){const n=await e(i,t.width,t.height);n&&!f(i,n)&&u.push({width:n.width,height:n.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'.");Je(this,Yn,JSON.parse(JSON.stringify(t)),"f"),Je(this,Xn,null,"f"),e&&await Ze(this,jn,"m",vr).call(this)}getMediaStreamConstraints(){return JSON.parse(JSON.stringify(Ze(this,Yn,"f")))}resetMediaStreamConstraints(){Je(this,Yn,this.defaultConstraints?JSON.parse(JSON.stringify(this.defaultConstraints)):null,"f")}getCameraCapabilities(){if(!Ze(this,Vn,"f")||"opened"!==this.state)throw new Error("Camera is not open.");return Ze(this,Vn,"f").getCapabilities?Ze(this,Vn,"f").getCapabilities():{}}getCameraSettings(){if(!Ze(this,Vn,"f")||"opened"!==this.state)throw new Error("Camera is not open.");return Ze(this,Vn,"f").getSettings()}async turnOnTorch(){if(!Ze(this,Vn,"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 Ze(this,Vn,"f").applyConstraints({advanced:[{torch:!0}]})}async turnOffTorch(){if(!Ze(this,Vn,"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 Ze(this,Vn,"f").applyConstraints({advanced:[{torch:!1}]})}async setColorTemperature(t,e){var i;if("number"!=typeof t)throw new TypeError("Invalid 'value'.");if(!Ze(this,Vn,"f")||"opened"!==this.state)throw new Error("Camera is not open.");const n=null===(i=this.getCameraCapabilities())||void 0===i?void 0:i.colorTemperature;if(!n)throw Error("Not supported.");return e&&(tn.max&&(t=n.max),t=Mr(t,n.min,n.step,n.max)),await Ze(this,Vn,"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(!Ze(this,Vn,"f")||"opened"!==this.state)throw new Error("Camera is not open.");const n=null===(i=this.getCameraCapabilities())||void 0===i?void 0:i.exposureCompensation;if(!n)throw Error("Not supported.");return e&&(tn.max&&(t=n.max),t=Mr(t,n.min,n.step,n.max)),await Ze(this,Vn,"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(!Ze(this,Vn,"f")||"opened"!==this.state)throw new Error("Camera is not open.");let n=null===(i=this.getCameraCapabilities())||void 0===i?void 0:i.frameRate;if(!n)throw Error("Not supported.");e&&(tn.max&&(t=n.max));const r=this.getResolution();return await Ze(this,Vn,"f").applyConstraints({width:{ideal:Math.max(r.width,r.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(!Ze(this,Vn,"f")||"opened"!==this.state)throw new Error("Camera is not open.");const i=this.getCameraCapabilities(),n=null==i?void 0:i.focusMode,r=null==i?void 0:i.focusDistance;if(!n)throw Error("Not supported.");if("string"!=typeof t.mode)throw TypeError("Invalid 'mode'.");const s=t.mode.toLowerCase();if(!n.includes(s))throw Error("Unsupported focus mode.");if("manual"===s){if(!r)throw Error("Manual focus unsupported.");if(t.hasOwnProperty("distance")){let i=t.distance;e&&(ir.max&&(i=r.max),i=Mr(i,r.min,r.step,r.max)),this._focusParameters.focusArea=null,await Ze(this,Vn,"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,n=t.area.height;if(!i||!n){const t=this.getResolution();i||(i=2*Math.round(Math.min(t.width,t.height)/this._focusParameters.defaultFocusAreaSizeRatio/2)+"px"),n||(n=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:n},await Ze(this,jn,"m",Er).call(this,e,i,n)}}}else this._focusParameters.focusArea=null,await Ze(this,Vn,"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}enableTapToFocus(){Je(this,Qn,!0,"f")}disableTapToFocus(){Je(this,Qn,!1,"f")}isTapToFocusEnabled(){return Ze(this,Qn,"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){t.centerPoint?Ze(this,jn,"m",Sr).call(this,t.centerPoint):this.resetScaleCenter();try{if(Ze(this,jn,"m",br).call(this,Ze(this,sr,"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)}}else this._zoomPreSetting=t}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*Ze(this,rr,"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(!Ze(this,Vn,"f")||"opened"!==this.state)throw new Error("Camera is not open.");const n=null===(i=this.getCameraCapabilities())||void 0===i?void 0:i.zoom;if(!n)throw Error("Not supported.");return e&&(tn.max&&(t=n.max),t=Mr(t,n.min,n.step,n.max)),await Ze(this,Vn,"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&&Ze(this,jn,"m",Sr).call(this,e),Je(this,rr,t,"f"),this.updateVideoElWhenSoftwareScaled()}getSoftwareScale(){return Ze(this,rr,"f")}resetScaleCenter(){if("opened"!==this.state)throw new Error("Video is not playing.");const t=this.getResolution();Je(this,sr,{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(Ze(this,$n,"f"))return null;const e=Date.now();Fr._onLog&&Fr._onLog("getFrameData() START: "+e);const i=Ze(this,Un,"f").videoWidth,n=Ze(this,Un,"f").videoHeight;let r={sx:0,sy:0,sWidth:i,sHeight:n,dWidth:i,dHeight:n};(null==t?void 0:t.position)&&(r=JSON.parse(JSON.stringify(t.position)));let s=li.RGBA;(null==t?void 0:t.pixelFormat)&&(s=t.pixelFormat);let o=Ze(this,rr,"f");(null==t?void 0:t.scale)&&(o=t.scale);let a=Ze(this,sr,"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,r=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"))r=parseFloat(t.scaleCenter.y);else{if(!t.scaleCenter.y.endsWith("%"))throw new Error("Invalid scale center.");r=parseFloat(t.scaleCenter.y)/100*n}if(isNaN(e)||isNaN(r))throw new Error("Invalid scale center.");a.x=Math.round(e),a.y=Math.round(r)}let h=null;if((null==t?void 0:t.bufferContainer)&&(h=t.bufferContainer),0==i||0==n)return null;1!==o&&(r.sWidth=Math.round(r.sWidth/o),r.sHeight=Math.round(r.sHeight/o),r.sx=Math.round((1-1/o)*a.x+r.sx/o),r.sy=Math.round((1-1/o)*a.y+r.sy/o));const l=this.imageDataGetter.getImageData(Ze(this,Un,"f"),r,{pixelFormat:s,bufferContainer:h,isEnableMirroring:null==t?void 0:t.isEnableMirroring});if(!l)return null;const c=Date.now();return Fr._onLog&&Fr._onLog("getFrameData() END: "+c),{data:l.data,width:l.width,height:l.height,pixelFormat:l.pixelFormat,timeSpent:c-e,timeStamp:c,toCanvas:Ze(this,or,"f")}}on(t,e){if(!Ze(this,hr,"f").includes(t.toLowerCase()))throw new Error(`Event '${t}' does not exist.`);Ze(this,ar,"f").on(t,e)}off(t,e){Ze(this,ar,"f").off(t,e)}async dispose(){this.tapFocusEventBoundEl=null,await this.close(),this.releaseVideoEl(),Ze(this,ar,"f").dispose(),this.imageDataGetter.dispose(),document.removeEventListener("visibilitychange",Ze(this,ur,"f")),Je(this,dr,!0,"f")}}var Pr,kr,Nr,Br,jr,Ur,Vr,Gr,Wr,Yr,Hr,Xr,zr,qr,Kr,Zr,Jr,$r,Qr,ts,es,is,ns,rs,ss,os,as,hs,ls,cs,us,ds,fs,gs,ms,ps;Un=new WeakMap,Vn=new WeakMap,Gn=new WeakMap,Wn=new WeakMap,Yn=new WeakMap,Hn=new WeakMap,Xn=new WeakMap,zn=new WeakMap,qn=new WeakMap,Kn=new WeakMap,Zn=new WeakMap,Jn=new WeakMap,$n=new WeakMap,Qn=new WeakMap,tr=new WeakMap,er=new WeakMap,ir=new WeakMap,nr=new WeakMap,rr=new WeakMap,sr=new WeakMap,or=new WeakMap,ar=new WeakMap,hr=new WeakMap,lr=new WeakMap,cr=new WeakMap,ur=new WeakMap,dr=new WeakMap,jn=new WeakSet,fr=async function(){const t=this.getMediaStreamConstraints();if("boolean"==typeof t.video&&(t.video={}),t.video.deviceId);else if(Ze(this,Xn,"f"))delete t.video.facingMode,t.video.deviceId={exact:Ze(this,Xn,"f")};else if(this.ifSaveLastUsedCamera&&Fr.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(qe.OS)?(await this._getCameras(!1),Ze(this,jn,"m",gr).call(this),e=Fr.findBestCamera(this._arrCameras,"environment",{getMainCameraInIOS:this.selectIOSRearMainCameraAsDefault})):t||["Android","HarmonyOS","iPhone","iPad"].includes(qe.OS)||(await this._getCameras(!1),Ze(this,jn,"m",gr).call(this),e=Fr.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 n=await e(i);n&&(delete t.video.facingMode,t.video.deviceId={exact:n})}return t},gr=function(){if(Ze(this,Kn,"f")){const t=new Error("The operation was interrupted.");throw t.name="AbortError",t}},mr=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 n;try{Fr._onLog&&Fr._onLog("======try getUserMedia========");let e=[0,500,1e3,2e3],i=null;const r=async t=>{for(let r of e){r&&(await new Promise(t=>setTimeout(t,r)),Ze(this,jn,"m",gr).call(this));try{Fr._onLog&&Fr._onLog("ask "+JSON.stringify(t)),n=await navigator.mediaDevices.getUserMedia(t),Ze(this,jn,"m",gr).call(this);break}catch(t){if("NotFoundError"===t.name||"NotAllowedError"===t.name||"AbortError"===t.name||"OverconstrainedError"===t.name)throw t;i=t,Fr._onLog&&Fr._onLog(t.message||t)}}};if(await r(t),!n&&"object"==typeof t.video&&(t.video.deviceId&&(delete t.video.deviceId,await r(t)),!n&&t.video.facingMode&&(delete t.video.facingMode,await r(t)),n||!t.video.width&&!t.video.height||(delete t.video.width,delete t.video.height,await r(t)),!n)){const t=(await navigator.mediaDevices.enumerateDevices()).filter(t=>"videoinput"===t.kind);for(let e of t){const t={video:{deviceId:{ideal:e.deviceId},facingMode:{ideal:"environment"},width:{ideal:1920},height:{ideal:1080}}};if(await r(t),n)break}}if(!n)throw i;return n}catch(t){throw null==n||n.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}},pr=function(){this._mediaStream&&(this._mediaStream.getTracks().forEach(t=>{t.stop()}),this._mediaStream=null),Je(this,Vn,null,"f")},_r=async function(){Je(this,Kn,!1,"f");const t=Je(this,qn,Symbol(),"f");if(Ze(this,Zn,"f")&&"pending"===Ze(this,Jn,"f")){try{await Ze(this,Zn,"f")}catch(t){}Ze(this,jn,"m",gr).call(this)}if(t!==Ze(this,qn,"f"))return;const e=Je(this,Zn,(async()=>{Je(this,Jn,"pending","f");try{if(this.videoSrc){if(!Ze(this,Un,"f"))throw new Error("'videoEl' should be set.");await Fr.playVideo(Ze(this,Un,"f"),this.videoSrc,this.cameraOpenTimeout),Ze(this,jn,"m",gr).call(this)}else{let t=await Ze(this,jn,"m",fr).call(this);Ze(this,jn,"m",pr).call(this);let e=await Ze(this,jn,"m",mr).call(this,t);await this._getCameras(!1),Ze(this,jn,"m",gr).call(this);const i=()=>{const t=e.getVideoTracks();let i,n;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,n=e;break}}return n},n=Ze(this,Yn,"f");if("object"==typeof n.video){let r=n.video.facingMode;if(r instanceof Array&&r.length&&(r=r[0]),"object"==typeof r&&(r=r.exact||r.ideal),!(Ze(this,Xn,"f")||this.ifSaveLastUsedCamera&&Fr.isStorageAvailable&&window.localStorage.getItem("dce_last_camera_id")||this.ifSkipCameraInspection||n.video.deviceId)){const n=i(),s=Fr.findBestCamera(this._arrCameras,r,{getMainCameraInIOS:this.selectIOSRearMainCameraAsDefault});s&&s!=(null==n?void 0:n.deviceId)&&(e.getTracks().forEach(t=>{t.stop()}),t.video.deviceId={exact:s},e=await Ze(this,jn,"m",mr).call(this,t),Ze(this,jn,"m",gr).call(this))}}const r=i();(null==r?void 0:r.deviceId)&&(Je(this,Xn,r&&r.deviceId,"f"),this.ifSaveLastUsedCamera&&Fr.isStorageAvailable&&(window.localStorage.setItem("dce_last_camera_id",Ze(this,Xn,"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))))),Ze(this,Un,"f")&&(await Fr.playVideo(Ze(this,Un,"f"),e,this.cameraOpenTimeout),Ze(this,jn,"m",gr).call(this)),this._mediaStream=e;const s=e.getVideoTracks();(null==s?void 0:s.length)&&Je(this,Vn,s[0],"f"),Je(this,Hn,r,"f")}}catch(t){throw Ze(this,jn,"m",yr).call(this),Je(this,Jn,null,"f"),t}Je(this,Jn,"fulfilled","f")})(),"f");return e},vr=async function(){var t;if("closed"===this.state||this.videoSrc)return;const e=null===(t=Ze(this,Hn,"f"))||void 0===t?void 0:t.deviceId,i=this.getResolution();await Ze(this,jn,"m",_r).call(this);const n=this.getResolution();e&&e!==Ze(this,Hn,"f").deviceId&&Ze(this,ar,"f").fire("camera:changed",[Ze(this,Hn,"f").deviceId,e],{target:this,async:!1}),i.width==n.width&&i.height==n.height||Ze(this,ar,"f").fire("resolution:changed",[{width:n.width,height:n.height},{width:i.width,height:i.height}],{target:this,async:!1}),Ze(this,ar,"f").fire("played",null,{target:this,async:!1})},yr=function(){Ze(this,jn,"m",pr).call(this),Je(this,Hn,null,"f"),Ze(this,Un,"f")&&(Ze(this,Un,"f").srcObject=null,this.videoSrc&&(Ze(this,Un,"f").pause(),Ze(this,Un,"f").currentTime=0)),Je(this,Kn,!0,"f");try{this.resetSoftwareScale()}catch(t){}},wr=async function t(e,i){const n=t=>{if(!Ze(this,Vn,"f")||!this.isVideoPlaying||t.focusTaskId!=this._focusParameters.curFocusTaskId){Ze(this,Vn,"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 r;i=Mr(i,this._focusParameters.fds.min,this._focusParameters.fds.step,this._focusParameters.fds.max),await Ze(this,Vn,"f").applyConstraints({advanced:[{focusMode:"manual",focusDistance:i}]}),n(e),r=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,r)}),n(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(Ze(this,Un,"f"),{sx:s,sy:o,sWidth:a,sHeight:h,dWidth:a,dHeight:h},{pixelFormat:li.RGBA,bufferContainer:d}))return Ze(this,jn,"m",t).call(this,e,i);const f=d;let g=0;for(let t=0,e=u-8;ta&&au)return await Ze(this,jn,"m",t).call(this,e,o,a,r,s,c,u)}else{let h=await Ze(this,jn,"m",wr).call(this,e,c);if(a>h)return await Ze(this,jn,"m",t).call(this,e,o,a,r,s,c,h);if(a==h)return await Ze(this,jn,"m",t).call(this,e,o,a,c,h);let u=await Ze(this,jn,"m",wr).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!==Ze(this,rr,"f")){const t=Ze(this,rr,"f"),e=Ze(this,sr,"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 n=Mr(Math.sqrt(i*(e||this._focusParameters.fds.step)),this._focusParameters.fds.min,this._focusParameters.fds.step,this._focusParameters.fds.max),r=Mr(Math.sqrt((e||this._focusParameters.fds.step)*n),this._focusParameters.fds.min,this._focusParameters.fds.step,this._focusParameters.fds.max),s=Mr(Math.sqrt(n*i),this._focusParameters.fds.min,this._focusParameters.fds.step,this._focusParameters.fds.max),o=await Ze(this,jn,"m",wr).call(this,t,s),a=await Ze(this,jn,"m",wr).call(this,t,r),h=await Ze(this,jn,"m",wr).call(this,t,n);if(a>h&&ho&&a>o){let e=await Ze(this,jn,"m",wr).call(this,t,i);const r=await Ze(this,jn,"m",Cr).call(this,t,n,h,i,e,s,o);return this._focusParameters.isDoingFocus=0,r}if(a==h&&h