@twintag/twintag-core 0.2.287 → 0.2.288

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -69,6 +69,7 @@ const TwintagQRScanner = class {
69
69
  constructor(hostRef) {
70
70
  index.registerInstance(this, hostRef);
71
71
  this.symbol = index.createEvent(this, "symbol", 7);
72
+ this.reject = index.createEvent(this, "reject", 7);
72
73
  this.streamIsActive = index.createEvent(this, "streamIsActive", 7);
73
74
  this.frame = index.createEvent(this, "frame", 7);
74
75
  this.stage = 0;
@@ -206,7 +207,7 @@ const TwintagQRScanner = class {
206
207
  }
207
208
  }
208
209
  catch (err) {
209
- throw new Error(err);
210
+ throw err;
210
211
  }
211
212
  }
212
213
  async getTrackSettings(constraints) {
@@ -285,11 +286,13 @@ const TwintagQRScanner = class {
285
286
  }
286
287
  }
287
288
  catch (err) {
288
- if (err instanceof Error) {
289
+ if (err instanceof DOMException) {
289
290
  console.error(err.message);
291
+ this.reject.emit({ name: err.name, message: err.message });
290
292
  }
291
293
  else {
292
294
  console.error(err);
295
+ this.reject.emit({ name: 'UNKNOWN', message: JSON.stringify(err) });
293
296
  }
294
297
  }
295
298
  finally {
@@ -141,7 +141,7 @@ export class TwintagQRScanner {
141
141
  }
142
142
  }
143
143
  catch (err) {
144
- throw new Error(err);
144
+ throw err;
145
145
  }
146
146
  }
147
147
  async getTrackSettings(constraints) {
@@ -220,11 +220,13 @@ export class TwintagQRScanner {
220
220
  }
221
221
  }
222
222
  catch (err) {
223
- if (err instanceof Error) {
223
+ if (err instanceof DOMException) {
224
224
  console.error(err.message);
225
+ this.reject.emit({ name: err.name, message: err.message });
225
226
  }
226
227
  else {
227
228
  console.error(err);
229
+ this.reject.emit({ name: 'UNKNOWN', message: JSON.stringify(err) });
228
230
  }
229
231
  }
230
232
  finally {
@@ -394,6 +396,21 @@ export class TwintagQRScanner {
394
396
  "resolved": "{ format: string; text: string; }",
395
397
  "references": {}
396
398
  }
399
+ }, {
400
+ "method": "reject",
401
+ "name": "reject",
402
+ "bubbles": true,
403
+ "cancelable": true,
404
+ "composed": true,
405
+ "docs": {
406
+ "tags": [],
407
+ "text": ""
408
+ },
409
+ "complexType": {
410
+ "original": "{\n name: string;\n message: string;\n }",
411
+ "resolved": "{ name: string; message: string; }",
412
+ "references": {}
413
+ }
397
414
  }, {
398
415
  "method": "streamIsActive",
399
416
  "name": "streamIsActive",
@@ -2,4 +2,4 @@
2
2
  /**
3
3
  * The library version.
4
4
  */
5
- export const VERSION = '0.2.287';
5
+ export const VERSION = '0.2.288';
@@ -67,6 +67,7 @@ const TwintagQRScanner = /*@__PURE__*/ proxyCustomElement(class extends HTMLElem
67
67
  this.__registerHost();
68
68
  this.__attachShadow();
69
69
  this.symbol = createEvent(this, "symbol", 7);
70
+ this.reject = createEvent(this, "reject", 7);
70
71
  this.streamIsActive = createEvent(this, "streamIsActive", 7);
71
72
  this.frame = createEvent(this, "frame", 7);
72
73
  this.stage = 0;
@@ -204,7 +205,7 @@ const TwintagQRScanner = /*@__PURE__*/ proxyCustomElement(class extends HTMLElem
204
205
  }
205
206
  }
206
207
  catch (err) {
207
- throw new Error(err);
208
+ throw err;
208
209
  }
209
210
  }
210
211
  async getTrackSettings(constraints) {
@@ -283,11 +284,13 @@ const TwintagQRScanner = /*@__PURE__*/ proxyCustomElement(class extends HTMLElem
283
284
  }
284
285
  }
285
286
  catch (err) {
286
- if (err instanceof Error) {
287
+ if (err instanceof DOMException) {
287
288
  console.error(err.message);
289
+ this.reject.emit({ name: err.name, message: err.message });
288
290
  }
289
291
  else {
290
292
  console.error(err);
293
+ this.reject.emit({ name: 'UNKNOWN', message: JSON.stringify(err) });
291
294
  }
292
295
  }
293
296
  finally {
@@ -65,6 +65,7 @@ const TwintagQRScanner = class {
65
65
  constructor(hostRef) {
66
66
  registerInstance(this, hostRef);
67
67
  this.symbol = createEvent(this, "symbol", 7);
68
+ this.reject = createEvent(this, "reject", 7);
68
69
  this.streamIsActive = createEvent(this, "streamIsActive", 7);
69
70
  this.frame = createEvent(this, "frame", 7);
70
71
  this.stage = 0;
@@ -202,7 +203,7 @@ const TwintagQRScanner = class {
202
203
  }
203
204
  }
204
205
  catch (err) {
205
- throw new Error(err);
206
+ throw err;
206
207
  }
207
208
  }
208
209
  async getTrackSettings(constraints) {
@@ -281,11 +282,13 @@ const TwintagQRScanner = class {
281
282
  }
282
283
  }
283
284
  catch (err) {
284
- if (err instanceof Error) {
285
+ if (err instanceof DOMException) {
285
286
  console.error(err.message);
287
+ this.reject.emit({ name: err.name, message: err.message });
286
288
  }
287
289
  else {
288
290
  console.error(err);
291
+ this.reject.emit({ name: 'UNKNOWN', message: JSON.stringify(err) });
289
292
  }
290
293
  }
291
294
  finally {
@@ -0,0 +1 @@
1
+ import{r as t,c as a,h as i,H as n}from"./p-d5d0e2ee.js";import{g as r}from"./p-60325667.js";import{c as s,a as e}from"./p-7b959006.js";const c=(t,a)=>{try{return JSON.parse(t.getItem(a))}catch(t){return null}},o=(t,a,i,n=!1)=>{var r;const e=s(null!==(r=c(t,a))&&void 0!==r?r:i),o=(()=>{let i=!1;return()=>{i||(i=!0,setTimeout((()=>{t.setItem(a,JSON.stringify(e.state)),i=!1}),0))}})();return o(),n&&window.addEventListener("storage",(()=>{const i=c(t,a);if(null!==i)for(const t in i)e.set(t,i[t])})),e.use({set:o,reset:o}),e},h=((t,a,i=!1)=>o(localStorage,"twintag-barcode-scanner",{deviceId:""},i))(),l=e(new URL("p-02c80109.js",import.meta.url).href,"scanner.worker","stencil.scanner.worker"),d=class{constructor(i){t(this,i),this.symbol=a(this,"symbol",7),this.reject=a(this,"reject",7),this.streamIsActive=a(this,"streamIsActive",7),this.frame=a(this,"frame",7),this.stage=0,this.stageScale=1,this.videoIsPlaying=!1,this.decoderIsBusy=!1,this.eventsController=new AbortController,this.stream=null,this.mode="single",this.format="QRCode",this.crop=1}async updateZoom(t){const[a]=this.stream.getVideoTracks();if(a.getCapabilities&&"function"==typeof a.applyConstraints){const i=a.getCapabilities();if("zoom"in a.getSettings()){const n=i.zoom.min,r=i.zoom.max;await a.applyConstraints({advanced:[{zoom:n+(r-n)*t.detail}]})}}}componentWillLoad(){this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d",{alpha:!1,willReadFrequently:!0})}async componentDidLoad(){l.addEventListener("message",(t=>{const a=t.data;"busy"===a.code&&(this.decoderIsBusy=!0),"ready"===a.code&&(this.decoderIsBusy=!1,this.symbol.emit(a.result),"single"===this.mode&&(this.eventsController.abort(),this.stopStream()))}),{passive:!0,signal:this.eventsController.signal}),document.addEventListener("visibilitychange",(async()=>{document.hidden?this.stream&&this.stopStream():await this.startStream()}),{passive:!0,signal:this.eventsController.signal}),this.videoContainerRef.style.setProperty("--crop",""+50*(1-this.crop)),document.hidden||await this.startStream()}readBarcodeFromCanvas(){if(this.reqAnimFrame=requestAnimationFrame(this.readBarcodeFromCanvas.bind(this)),!this.stage||!this.stageScale){const t=Math.min(this.video.videoWidth,this.video.videoHeight);return this.stageScale=Math.min(t,400)/t,this.stage=t*this.stageScale,this.canvas.width=this.stage,void(this.canvas.height=this.stage)}this.drawInCanvas();const t=this.context.getImageData(0,0,this.stage,this.stage);this.decoderIsBusy||(l.postMessage({type:"read",format:this.format,details:{width:this.stage,height:this.stage,sourceBuffer:t.data}}),this.frame.emit(this.canvas.toDataURL("image/png",.7)))}drawInCanvas(){const t=Math.min(this.video.videoWidth,this.video.videoHeight),a=t*this.crop;this.context.drawImage(this.video,this.video.videoWidth/2-a/2,this.video.videoHeight/2-a/2,a,a,0,0,t*this.stageScale,t*this.stageScale)}async updateStream(t){this.stream&&this.stream.getTracks().forEach((t=>{t.stop()}));try{this.stream=await navigator.mediaDevices.getUserMedia(t),this.video.srcObject=this.stream,this.video.setAttribute("playsinline","true"),this.video.onplaying=()=>{this.videoIsPlaying=!0},this.video.onpause=()=>{this.videoIsPlaying=!1},this.videoIsPlaying||(await this.video.play(),this.videoIsPlaying=!0)}catch(t){throw t}}async getTrackSettings(t){try{return(await navigator.mediaDevices.getUserMedia(t)).getVideoTracks()[0].getSettings()}catch(t){throw new Error(t)}}async getMedia(t){t.video.width={min:1080,ideal:1600,max:1920};try{if((a=h.get("deviceId"))&&0!==a.length&&a.trim())try{const a=JSON.parse(JSON.stringify(t));return a.video.deviceId={exact:h.get("deviceId")},void await this.updateStream(a)}catch(t){console.warn("Invalid deviceId stored in localStorage. Resetting...")}await this.updateStream(t);const i=(await navigator.mediaDevices.enumerateDevices()).filter((t=>"videoinput"===t.kind.toLowerCase()&&t.label.toLowerCase().includes("back")));if(0===i.length)return;if(1===i.length){const a=i[0].deviceId;h.set("deviceId",a),t.video.deviceId={exact:a},await this.updateStream(t)}let n=i.length-1;const r=i.map((t=>{const a=t.label.match(/\b([0-9]+)MP?\b/i);return null!=a?parseInt(a[1],10):NaN}));r.some((t=>isNaN(t)))||(n=r.lastIndexOf(Math.max(...r)));const s=i[n];if(s){const a=s.deviceId;return h.set("deviceId",a),t.video.deviceId={exact:a},void await this.updateStream(t)}const e=await this.getTrackSettings(t);e.focusDistance&&(t.video.advanced=[{focusMode:"continuous",focusDistance:e.focusDistance}],await this.updateStream(t))}catch(t){t instanceof DOMException?(console.error(t.message),this.reject.emit({name:t.name,message:t.message})):(console.error(t),this.reject.emit({name:"UNKNOWN",message:JSON.stringify(t)}))}finally{this.stream&&this.streamIsActive.emit(!0)}var a}async startStream(){const t={audio:!1,video:{aspectRatio:{ideal:1},facingMode:"environment"}};navigator.mediaDevices.getSupportedConstraints().zoom&&(t.video.zoom=!0),await this.getMedia(t),this.videoIsPlaying&&r.to(this.videoContainerRef,{duration:.2,opacity:1,onComplete:()=>{const t=Math.min(this.video.videoWidth,this.video.videoHeight);this.stageScale=Math.min(t,400)/t,this.stage=t*this.stageScale,this.canvas.width=this.stage,this.canvas.height=this.stage,this.readBarcodeFromCanvas()}})}stopStream(){this.streamIsActive.emit(!1),this.video.srcObject=null,this.stream.getTracks().forEach((t=>{t.stop()})),cancelAnimationFrame(this.reqAnimFrame),this.context.clearRect(0,0,this.context.canvas.width,this.context.canvas.height),r.to(this.videoContainerRef,{duration:.2,opacity:0})}disconnectedCallback(){this.eventsController.abort(),this.stopStream()}render(){return i(n,null,i("div",{class:"video-container",ref:t=>this.videoContainerRef=t},i("div",{class:"video-corners"}),i("video",{crossOrigin:"Anonymous",autoplay:!0,playsinline:!0,ref:t=>this.video=t})))}static get assetsDirs(){return["assets"]}};d.style=':host{--twintag-scanner-bg-select-cameras:white;--twintag-scanner-text-select-cameras:black;--twintag-scanner-radius-select-cameras:6px 0 0 0;--twintag-scanner-min-height:min-content;--twintag-scanner-corners-color:white;--twintag-scanner-corners-width:4px;--twintag-scanner-corners-length:36px;--twintag-scanner-corners-offset:24px;display:grid;place-items:center;position:relative;width:100%}:host .icon-container{display:grid;place-items:center;position:absolute;inset:0;z-index:-2222}:host .icon-container .check-icon{opacity:0;z-index:2222}:host .video-container{--crop:0;--crop-x:var(--crop);--crop-y:var(--crop);display:flex;align-items:center;justify-content:center;position:relative;width:100%;height:100%;opacity:0;overflow:hidden;z-index:1}:host .video-container::after{content:"";position:absolute;width:100%;height:100%;opacity:inherit;background:rgba(0, 0, 0, 0.5);-webkit-clip-path:polygon(0% 0%, 0% 100%, calc(var(--crop-x) * 1%) 100%, calc(var(--crop-x) * 1%) calc(var(--crop-y) * 1%), calc(calc(100 - var(--crop-x)) * 1%) calc(var(--crop-y) * 1%), calc(calc(100 - var(--crop-x)) * 1%) calc(calc(100 - var(--crop-y)) * 1%), calc(var(--crop-x) * 1%) calc(calc(100 - var(--crop-y)) * 1%), calc(var(--crop-x) * 1%) 100%, 100% 100%, 100% 0%);clip-path:polygon(0% 0%, 0% 100%, calc(var(--crop-x) * 1%) 100%, calc(var(--crop-x) * 1%) calc(var(--crop-y) * 1%), calc(calc(100 - var(--crop-x)) * 1%) calc(var(--crop-y) * 1%), calc(calc(100 - var(--crop-x)) * 1%) calc(calc(100 - var(--crop-y)) * 1%), calc(var(--crop-x) * 1%) calc(calc(100 - var(--crop-y)) * 1%), calc(var(--crop-x) * 1%) 100%, 100% 100%, 100% 0%)}:host .video-container:before{display:block;content:"";width:100%;padding-top:100%}:host .video-container .video-corners{position:absolute;width:calc((1 - var(--crop-x) / 50) * 100% + var(--twintag-scanner-corners-offset));height:calc((1 - var(--crop-y) / 50) * 100% + var(--twintag-scanner-corners-offset));opacity:inherit;background:linear-gradient(to right, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 0 0, linear-gradient(to right, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 0 100%, linear-gradient(to left, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 100% 0, linear-gradient(to left, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 100% 100%, linear-gradient(to bottom, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 0 0, linear-gradient(to bottom, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 100% 0, linear-gradient(to top, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 0 100%, linear-gradient(to top, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 100% 100%;background-size:var(--twintag-scanner-corners-length) var(--twintag-scanner-corners-length);background-repeat:no-repeat;z-index:2222}:host .video-container video{position:absolute;width:100% !important;object-fit:cover;object-position:center;aspect-ratio:1/1 !important;min-height:var(--twintag-scanner-min-height)}';export{d as twintag_qr_scanner}
@@ -1 +1 @@
1
- import{p as e,b as t}from"./p-d5d0e2ee.js";(()=>{const t=import.meta.url,n={};return""!==t&&(n.resourcesUrl=new URL(".",t).href),e(n)})().then((e=>t([["p-d1230452",[[1,"twintag-preview",{item:[1],initial:[16],smoothExtinction:[2,"smooth-extinction"],extension:[1],showButtons:[4,"show-buttons"],previewableItem:[32],type:[32]}]]],["p-7943b86a",[[1,"twintag-auth-callback"]]],["p-f58c7a83",[[1,"twintag-auth-logout"]]],["p-6cd7075c",[[1,"twintag-media",{first:[1],middle:[1],last:[1]}]]],["p-d428ed6b",[[1,"twintag-ocr-scanner",{stream:[1040],mode:[1],cropX:[2,"crop-x"],cropY:[2,"crop-y"],devices:[32]},[[0,"updateZoom","updateZoom"],[2,"recognize","ocrHandler"]]]]],["p-1e296694",[[1,"twintag-offline-actions",{enableSingleRetry:[4,"enable-single-retry"],header:[1],showTimestamp:[4,"show-timestamp"],showDescription:[4,"show-description"],closeText:[1,"close-text"],retryText:[1,"retry-text"],noPendingActionsText:[1,"no-pending-actions-text"],pendingOfflineRequests:[32],processing:[32]},[[8,"offlineRequestsChanged","offlineRequestsChangedHandler"]]]]],["p-9f7518ab",[[1,"twintag-offline-state",{onlineState:[32],pendingRequests:[32]},[[8,"onlineChanged","onlineChangedHandler"],[8,"offlineRequestsChanged","offlineRequestsChangedHandler"]]]]],["p-a53a2c70",[[1,"twintag-offline-support",{autoSync:[4,"auto-sync"],forceOffline:[4,"force-offline"],config:[16]}]]],["p-1807206d",[[1,"twintag-qr-scanner",{stream:[1040],mode:[1],format:[1],crop:[514]},[[1,"updateZoom","updateZoom"]]]]],["p-a6f626bb",[[1,"twintag-share",{url:[1],modalTitle:[1,"modal-title"],modalSubtitle:[1,"modal-subtitle"],closeBtn:[1,"close-btn"],copyClipboardBtn:[1,"copy-clipboard-btn"],open:[1540]},[[0,"keydown","handleKeyDown"]]]]],["p-5bd6d110",[[1,"twintag-spinner",{color:[513],duration:[2],name:[1]}]]],["p-8806444b",[[0,"twintag-pdf-viewer",{src:[1],fileName:[1,"file-name"],file:[32],fileURL:[32]}]]]],e)));
1
+ import{p as e,b as t}from"./p-d5d0e2ee.js";(()=>{const t=import.meta.url,n={};return""!==t&&(n.resourcesUrl=new URL(".",t).href),e(n)})().then((e=>t([["p-d1230452",[[1,"twintag-preview",{item:[1],initial:[16],smoothExtinction:[2,"smooth-extinction"],extension:[1],showButtons:[4,"show-buttons"],previewableItem:[32],type:[32]}]]],["p-7943b86a",[[1,"twintag-auth-callback"]]],["p-f58c7a83",[[1,"twintag-auth-logout"]]],["p-6cd7075c",[[1,"twintag-media",{first:[1],middle:[1],last:[1]}]]],["p-d428ed6b",[[1,"twintag-ocr-scanner",{stream:[1040],mode:[1],cropX:[2,"crop-x"],cropY:[2,"crop-y"],devices:[32]},[[0,"updateZoom","updateZoom"],[2,"recognize","ocrHandler"]]]]],["p-1e296694",[[1,"twintag-offline-actions",{enableSingleRetry:[4,"enable-single-retry"],header:[1],showTimestamp:[4,"show-timestamp"],showDescription:[4,"show-description"],closeText:[1,"close-text"],retryText:[1,"retry-text"],noPendingActionsText:[1,"no-pending-actions-text"],pendingOfflineRequests:[32],processing:[32]},[[8,"offlineRequestsChanged","offlineRequestsChangedHandler"]]]]],["p-9f7518ab",[[1,"twintag-offline-state",{onlineState:[32],pendingRequests:[32]},[[8,"onlineChanged","onlineChangedHandler"],[8,"offlineRequestsChanged","offlineRequestsChangedHandler"]]]]],["p-a53a2c70",[[1,"twintag-offline-support",{autoSync:[4,"auto-sync"],forceOffline:[4,"force-offline"],config:[16]}]]],["p-cd7b66f2",[[1,"twintag-qr-scanner",{stream:[1040],mode:[1],format:[1],crop:[514]},[[1,"updateZoom","updateZoom"]]]]],["p-a6f626bb",[[1,"twintag-share",{url:[1],modalTitle:[1,"modal-title"],modalSubtitle:[1,"modal-subtitle"],closeBtn:[1,"close-btn"],copyClipboardBtn:[1,"copy-clipboard-btn"],open:[1540]},[[0,"keydown","handleKeyDown"]]]]],["p-5bd6d110",[[1,"twintag-spinner",{color:[513],duration:[2],name:[1]}]]],["p-8806444b",[[0,"twintag-pdf-viewer",{src:[1],fileName:[1,"file-name"],file:[32],fileURL:[32]}]]]],e)));
@@ -19,6 +19,10 @@ export declare class TwintagQRScanner {
19
19
  format: string;
20
20
  text: string;
21
21
  }>;
22
+ reject: EventEmitter<{
23
+ name: string;
24
+ message: string;
25
+ }>;
22
26
  streamIsActive: EventEmitter<boolean>;
23
27
  frame: EventEmitter<string>;
24
28
  updateZoom(e: CustomEvent<number>): Promise<void>;
@@ -282,6 +282,10 @@ declare namespace LocalJSX {
282
282
  "format"?: Format;
283
283
  "mode"?: 'single' | 'streaming';
284
284
  "onFrame"?: (event: TwintagQrScannerCustomEvent<string>) => void;
285
+ "onReject"?: (event: TwintagQrScannerCustomEvent<{
286
+ name: string;
287
+ message: string;
288
+ }>) => void;
285
289
  "onStreamIsActive"?: (event: TwintagQrScannerCustomEvent<boolean>) => void;
286
290
  "onSymbol"?: (event: TwintagQrScannerCustomEvent<{
287
291
  format: string;
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * The library version.
3
3
  */
4
- export declare const VERSION = "0.2.287";
4
+ export declare const VERSION = "0.2.288";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twintag/twintag-core",
3
- "version": "0.2.287",
3
+ "version": "0.2.288",
4
4
  "author": "Twintag",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",
@@ -1 +0,0 @@
1
- import{r as t,c as a,h as i,H as r}from"./p-d5d0e2ee.js";import{g as n}from"./p-60325667.js";import{c as s,a as e}from"./p-7b959006.js";const c=(t,a)=>{try{return JSON.parse(t.getItem(a))}catch(t){return null}},o=(t,a,i,r=!1)=>{var n;const e=s(null!==(n=c(t,a))&&void 0!==n?n:i),o=(()=>{let i=!1;return()=>{i||(i=!0,setTimeout((()=>{t.setItem(a,JSON.stringify(e.state)),i=!1}),0))}})();return o(),r&&window.addEventListener("storage",(()=>{const i=c(t,a);if(null!==i)for(const t in i)e.set(t,i[t])})),e.use({set:o,reset:o}),e},h=((t,a,i=!1)=>o(localStorage,"twintag-barcode-scanner",{deviceId:""},i))(),l=e(new URL("p-02c80109.js",import.meta.url).href,"scanner.worker","stencil.scanner.worker"),d=class{constructor(i){t(this,i),this.symbol=a(this,"symbol",7),this.streamIsActive=a(this,"streamIsActive",7),this.frame=a(this,"frame",7),this.stage=0,this.stageScale=1,this.videoIsPlaying=!1,this.decoderIsBusy=!1,this.eventsController=new AbortController,this.stream=null,this.mode="single",this.format="QRCode",this.crop=1}async updateZoom(t){const[a]=this.stream.getVideoTracks();if(a.getCapabilities&&"function"==typeof a.applyConstraints){const i=a.getCapabilities();if("zoom"in a.getSettings()){const r=i.zoom.min,n=i.zoom.max;await a.applyConstraints({advanced:[{zoom:r+(n-r)*t.detail}]})}}}componentWillLoad(){this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d",{alpha:!1,willReadFrequently:!0})}async componentDidLoad(){l.addEventListener("message",(t=>{const a=t.data;"busy"===a.code&&(this.decoderIsBusy=!0),"ready"===a.code&&(this.decoderIsBusy=!1,this.symbol.emit(a.result),"single"===this.mode&&(this.eventsController.abort(),this.stopStream()))}),{passive:!0,signal:this.eventsController.signal}),document.addEventListener("visibilitychange",(async()=>{document.hidden?this.stream&&this.stopStream():await this.startStream()}),{passive:!0,signal:this.eventsController.signal}),this.videoContainerRef.style.setProperty("--crop",""+50*(1-this.crop)),document.hidden||await this.startStream()}readBarcodeFromCanvas(){if(this.reqAnimFrame=requestAnimationFrame(this.readBarcodeFromCanvas.bind(this)),!this.stage||!this.stageScale){const t=Math.min(this.video.videoWidth,this.video.videoHeight);return this.stageScale=Math.min(t,400)/t,this.stage=t*this.stageScale,this.canvas.width=this.stage,void(this.canvas.height=this.stage)}this.drawInCanvas();const t=this.context.getImageData(0,0,this.stage,this.stage);this.decoderIsBusy||(l.postMessage({type:"read",format:this.format,details:{width:this.stage,height:this.stage,sourceBuffer:t.data}}),this.frame.emit(this.canvas.toDataURL("image/png",.7)))}drawInCanvas(){const t=Math.min(this.video.videoWidth,this.video.videoHeight),a=t*this.crop;this.context.drawImage(this.video,this.video.videoWidth/2-a/2,this.video.videoHeight/2-a/2,a,a,0,0,t*this.stageScale,t*this.stageScale)}async updateStream(t){this.stream&&this.stream.getTracks().forEach((t=>{t.stop()}));try{this.stream=await navigator.mediaDevices.getUserMedia(t),this.video.srcObject=this.stream,this.video.setAttribute("playsinline","true"),this.video.onplaying=()=>{this.videoIsPlaying=!0},this.video.onpause=()=>{this.videoIsPlaying=!1},this.videoIsPlaying||(await this.video.play(),this.videoIsPlaying=!0)}catch(t){throw new Error(t)}}async getTrackSettings(t){try{return(await navigator.mediaDevices.getUserMedia(t)).getVideoTracks()[0].getSettings()}catch(t){throw new Error(t)}}async getMedia(t){t.video.width={min:1080,ideal:1600,max:1920};try{if((a=h.get("deviceId"))&&0!==a.length&&a.trim())try{const a=JSON.parse(JSON.stringify(t));return a.video.deviceId={exact:h.get("deviceId")},void await this.updateStream(a)}catch(t){console.warn("Invalid deviceId stored in localStorage. Resetting...")}await this.updateStream(t);const i=(await navigator.mediaDevices.enumerateDevices()).filter((t=>"videoinput"===t.kind.toLowerCase()&&t.label.toLowerCase().includes("back")));if(0===i.length)return;if(1===i.length){const a=i[0].deviceId;h.set("deviceId",a),t.video.deviceId={exact:a},await this.updateStream(t)}let r=i.length-1;const n=i.map((t=>{const a=t.label.match(/\b([0-9]+)MP?\b/i);return null!=a?parseInt(a[1],10):NaN}));n.some((t=>isNaN(t)))||(r=n.lastIndexOf(Math.max(...n)));const s=i[r];if(s){const a=s.deviceId;return h.set("deviceId",a),t.video.deviceId={exact:a},void await this.updateStream(t)}const e=await this.getTrackSettings(t);e.focusDistance&&(t.video.advanced=[{focusMode:"continuous",focusDistance:e.focusDistance}],await this.updateStream(t))}catch(t){t instanceof Error?console.error(t.message):console.error(t)}finally{this.stream&&this.streamIsActive.emit(!0)}var a}async startStream(){const t={audio:!1,video:{aspectRatio:{ideal:1},facingMode:"environment"}};navigator.mediaDevices.getSupportedConstraints().zoom&&(t.video.zoom=!0),await this.getMedia(t),this.videoIsPlaying&&n.to(this.videoContainerRef,{duration:.2,opacity:1,onComplete:()=>{const t=Math.min(this.video.videoWidth,this.video.videoHeight);this.stageScale=Math.min(t,400)/t,this.stage=t*this.stageScale,this.canvas.width=this.stage,this.canvas.height=this.stage,this.readBarcodeFromCanvas()}})}stopStream(){this.streamIsActive.emit(!1),this.video.srcObject=null,this.stream.getTracks().forEach((t=>{t.stop()})),cancelAnimationFrame(this.reqAnimFrame),this.context.clearRect(0,0,this.context.canvas.width,this.context.canvas.height),n.to(this.videoContainerRef,{duration:.2,opacity:0})}disconnectedCallback(){this.eventsController.abort(),this.stopStream()}render(){return i(r,null,i("div",{class:"video-container",ref:t=>this.videoContainerRef=t},i("div",{class:"video-corners"}),i("video",{crossOrigin:"Anonymous",autoplay:!0,playsinline:!0,ref:t=>this.video=t})))}static get assetsDirs(){return["assets"]}};d.style=':host{--twintag-scanner-bg-select-cameras:white;--twintag-scanner-text-select-cameras:black;--twintag-scanner-radius-select-cameras:6px 0 0 0;--twintag-scanner-min-height:min-content;--twintag-scanner-corners-color:white;--twintag-scanner-corners-width:4px;--twintag-scanner-corners-length:36px;--twintag-scanner-corners-offset:24px;display:grid;place-items:center;position:relative;width:100%}:host .icon-container{display:grid;place-items:center;position:absolute;inset:0;z-index:-2222}:host .icon-container .check-icon{opacity:0;z-index:2222}:host .video-container{--crop:0;--crop-x:var(--crop);--crop-y:var(--crop);display:flex;align-items:center;justify-content:center;position:relative;width:100%;height:100%;opacity:0;overflow:hidden;z-index:1}:host .video-container::after{content:"";position:absolute;width:100%;height:100%;opacity:inherit;background:rgba(0, 0, 0, 0.5);-webkit-clip-path:polygon(0% 0%, 0% 100%, calc(var(--crop-x) * 1%) 100%, calc(var(--crop-x) * 1%) calc(var(--crop-y) * 1%), calc(calc(100 - var(--crop-x)) * 1%) calc(var(--crop-y) * 1%), calc(calc(100 - var(--crop-x)) * 1%) calc(calc(100 - var(--crop-y)) * 1%), calc(var(--crop-x) * 1%) calc(calc(100 - var(--crop-y)) * 1%), calc(var(--crop-x) * 1%) 100%, 100% 100%, 100% 0%);clip-path:polygon(0% 0%, 0% 100%, calc(var(--crop-x) * 1%) 100%, calc(var(--crop-x) * 1%) calc(var(--crop-y) * 1%), calc(calc(100 - var(--crop-x)) * 1%) calc(var(--crop-y) * 1%), calc(calc(100 - var(--crop-x)) * 1%) calc(calc(100 - var(--crop-y)) * 1%), calc(var(--crop-x) * 1%) calc(calc(100 - var(--crop-y)) * 1%), calc(var(--crop-x) * 1%) 100%, 100% 100%, 100% 0%)}:host .video-container:before{display:block;content:"";width:100%;padding-top:100%}:host .video-container .video-corners{position:absolute;width:calc((1 - var(--crop-x) / 50) * 100% + var(--twintag-scanner-corners-offset));height:calc((1 - var(--crop-y) / 50) * 100% + var(--twintag-scanner-corners-offset));opacity:inherit;background:linear-gradient(to right, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 0 0, linear-gradient(to right, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 0 100%, linear-gradient(to left, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 100% 0, linear-gradient(to left, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 100% 100%, linear-gradient(to bottom, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 0 0, linear-gradient(to bottom, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 100% 0, linear-gradient(to top, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 0 100%, linear-gradient(to top, var(--twintag-scanner-corners-color) var(--twintag-scanner-corners-width), transparent var(--twintag-scanner-corners-width)) 100% 100%;background-size:var(--twintag-scanner-corners-length) var(--twintag-scanner-corners-length);background-repeat:no-repeat;z-index:2222}:host .video-container video{position:absolute;width:100% !important;object-fit:cover;object-position:center;aspect-ratio:1/1 !important;min-height:var(--twintag-scanner-min-height)}';export{d as twintag_qr_scanner}