import{b as s,c as o}from"./chunk-HNIQUNPL.js";import{e as i,f as n,i as r}from"./chunk-J3L46KAS.js";var c=class extends r{constructor(){super(...arguments),this._isSupported="BarcodeDetector"in window,this.errorVideoElementMissing="videoElement must be provided.",this.eventBarcodesScanned="barcodesScanned"}async startScan(e){if(!this._isSupported)throw this.createUnavailableException();if(!e?.videoElement)throw new Error(this.errorVideoElementMissing);this.videoElement=e.videoElement,this.stream=await navigator.mediaDevices.getUserMedia({video:{facingMode:{ideal:e?.lensFacing===o.Front?"user":"environment"}},audio:!1}),e.videoElement.srcObject=this.stream,await e.videoElement.play();let a=new BarcodeDetector;this.intervalId=window.setInterval(async()=>{if(!e.videoElement)return;let t=await a.detect(e.videoElement);t.length!==0&&this.handleScannedBarcodes(t)},500)}async stopScan(){if(!this._isSupported)throw this.createUnavailableException();this.intervalId&&(clearInterval(this.intervalId),this.intervalId=void 0),this.stream&&(this.stream.getTracks().forEach(e=>e.stop()),this.stream=void 0),this.videoElement&&(this.videoElement.srcObject=null,this.videoElement=void 0)}async readBarcodesFromImage(e){throw this.createUnavailableException()}async scan(){throw this.createUnavailableException()}async isSupported(){return{supported:this._isSupported}}async enableTorch(){throw this.createUnavailableException()}async disableTorch(){throw this.createUnavailableException()}async toggleTorch(){throw this.createUnavailableException()}async isTorchEnabled(){throw this.createUnavailableException}async isTorchAvailable(){return{available:!1}}async setZoomRatio(e){throw this.createUnavailableException()}async getZoomRatio(){throw this.createUnavailableException()}async getMinZoomRatio(){throw this.createUnavailableException()}async getMaxZoomRatio(){throw this.createUnavailableException()}async openSettings(){throw this.createUnavailableException()}async isGoogleBarcodeScannerModuleAvailable(){throw this.createUnavailableException()}async installGoogleBarcodeScannerModule(){throw this.createUnavailableException()}async checkPermissions(){try{return{camera:(await navigator.permissions.query({name:"camera"})).state}}catch{return{camera:"prompt"}}}async requestPermissions(){try{return(await navigator.mediaDevices.getUserMedia({video:!0})).getTracks().forEach(a=>a.stop()),{camera:"granted"}}catch{return{camera:"denied"}}}createUnavailableException(){return new n("This plugin method is not available on this platform.",i.Unavailable)}handleScannedBarcodes(e){let a={barcodes:e.map(t=>({cornerPoints:[[t.cornerPoints[0].x,t.cornerPoints[0].y],[t.cornerPoints[1].x,t.cornerPoints[1].y],[t.cornerPoints[2].x,t.cornerPoints[2].y],[t.cornerPoints[3].x,t.cornerPoints[3].y]],displayValue:t.rawValue,rawValue:t.rawValue,format:t.format.toUpperCase(),valueType:s.Unknown}))};this.notifyListeners(this.eventBarcodesScanned,a)}};export{c as BarcodeScannerWeb};
