import{b as s,c as o}from"./chunk-HNIQUNPL.js";import{h as i,i as r,l as a}from"./chunk-MPNB67H6.js";var c=class extends a{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.createUnimplementedException();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 n=new BarcodeDetector;this.intervalId=window.setInterval(async()=>{if(!e.videoElement)return;let t=await n.detect(e.videoElement);t.length!==0&&this.handleScannedBarcodes(t)},500)}async stopScan(){if(!this._isSupported)throw this.createUnimplementedException();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.createUnimplementedException()}async scan(){throw this.createUnimplementedException()}async isSupported(){return{supported:this._isSupported}}async enableTorch(){throw this.createUnimplementedException()}async disableTorch(){throw this.createUnimplementedException()}async toggleTorch(){throw this.createUnimplementedException()}async isTorchEnabled(){throw this.createUnimplementedException()}async isTorchAvailable(){return{available:!1}}async setZoomRatio(e){throw this.createUnimplementedException()}async getZoomRatio(){throw this.createUnimplementedException()}async getMinZoomRatio(){throw this.createUnimplementedException()}async getMaxZoomRatio(){throw this.createUnimplementedException()}async openSettings(){throw this.createUnimplementedException()}async isGoogleBarcodeScannerModuleAvailable(){throw this.createUnimplementedException()}async installGoogleBarcodeScannerModule(){throw this.createUnimplementedException()}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(n=>n.stop()),{camera:"granted"}}catch{return{camera:"denied"}}}createUnimplementedException(){return new r("This method is not implemented on web.",i.Unimplemented)}handleScannedBarcodes(e){let n={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,n)}};export{c as BarcodeScannerWeb};
