@twintag/twintag-core 0.2.283 → 0.2.284-fix-scanner-stream-visibility-9ac029dedd8eb46b8c97b6a6b8dfdb114e5e5de8

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.
@@ -14,7 +14,7 @@ const patchEsm = () => {
14
14
  const defineCustomElements = (win, options) => {
15
15
  if (typeof window === 'undefined') return Promise.resolve();
16
16
  return patchEsm().then(() => {
17
- return index.bootstrapLazy([["twintag-preview.cjs",[[1,"twintag-preview",{"item":[1],"initial":[16],"smoothExtinction":[2,"smooth-extinction"],"extension":[1],"showButtons":[4,"show-buttons"],"previewableItem":[32],"type":[32]}]]],["twintag-auth-callback.cjs",[[1,"twintag-auth-callback"]]],["twintag-auth-logout.cjs",[[1,"twintag-auth-logout"]]],["twintag-media.cjs",[[1,"twintag-media",{"first":[1],"middle":[1],"last":[1]}]]],["twintag-ocr-scanner.cjs",[[1,"twintag-ocr-scanner",{"stream":[1040],"mode":[1],"cropX":[2,"crop-x"],"cropY":[2,"crop-y"],"devices":[32]},[[0,"updateZoom","updateZoom"],[2,"recognize","ocrHandler"]]]]],["twintag-offline-actions.cjs",[[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"]]]]],["twintag-offline-state.cjs",[[1,"twintag-offline-state",{"onlineState":[32],"pendingRequests":[32]},[[8,"onlineChanged","onlineChangedHandler"],[8,"offlineRequestsChanged","offlineRequestsChangedHandler"]]]]],["twintag-offline-support.cjs",[[1,"twintag-offline-support",{"autoSync":[4,"auto-sync"],"forceOffline":[4,"force-offline"],"config":[16]}]]],["twintag-qr-scanner.cjs",[[1,"twintag-qr-scanner",{"stream":[1040],"mode":[1],"format":[1],"crop":[514],"devices":[32],"decoderIsBusy":[32]},[[0,"updateZoom","updateZoom"]]]]],["twintag-share.cjs",[[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"]]]]],["twintag-spinner.cjs",[[1,"twintag-spinner",{"color":[513],"duration":[2],"name":[1]}]]],["twintag-pdf-viewer.cjs",[[0,"twintag-pdf-viewer",{"src":[1],"fileName":[1,"file-name"],"file":[32],"fileURL":[32]}]]]], options);
17
+ return index.bootstrapLazy([["twintag-preview.cjs",[[1,"twintag-preview",{"item":[1],"initial":[16],"smoothExtinction":[2,"smooth-extinction"],"extension":[1],"showButtons":[4,"show-buttons"],"previewableItem":[32],"type":[32]}]]],["twintag-auth-callback.cjs",[[1,"twintag-auth-callback"]]],["twintag-auth-logout.cjs",[[1,"twintag-auth-logout"]]],["twintag-media.cjs",[[1,"twintag-media",{"first":[1],"middle":[1],"last":[1]}]]],["twintag-ocr-scanner.cjs",[[1,"twintag-ocr-scanner",{"stream":[1040],"mode":[1],"cropX":[2,"crop-x"],"cropY":[2,"crop-y"],"devices":[32]},[[0,"updateZoom","updateZoom"],[2,"recognize","ocrHandler"]]]]],["twintag-offline-actions.cjs",[[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"]]]]],["twintag-offline-state.cjs",[[1,"twintag-offline-state",{"onlineState":[32],"pendingRequests":[32]},[[8,"onlineChanged","onlineChangedHandler"],[8,"offlineRequestsChanged","offlineRequestsChangedHandler"]]]]],["twintag-offline-support.cjs",[[1,"twintag-offline-support",{"autoSync":[4,"auto-sync"],"forceOffline":[4,"force-offline"],"config":[16]}]]],["twintag-qr-scanner.cjs",[[1,"twintag-qr-scanner",{"stream":[1040],"mode":[1],"format":[1],"crop":[514],"devices":[32],"decoderIsBusy":[32]},[[1,"updateZoom","updateZoom"]]]]],["twintag-share.cjs",[[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"]]]]],["twintag-spinner.cjs",[[1,"twintag-spinner",{"color":[513],"duration":[2],"name":[1]}]]],["twintag-pdf-viewer.cjs",[[0,"twintag-pdf-viewer",{"src":[1],"fileName":[1,"file-name"],"file":[32],"fileURL":[32]}]]]], options);
18
18
  });
19
19
  };
20
20
 
@@ -15,5 +15,5 @@ const patchBrowser = () => {
15
15
  };
16
16
 
17
17
  patchBrowser().then(options => {
18
- return index.bootstrapLazy([["twintag-preview.cjs",[[1,"twintag-preview",{"item":[1],"initial":[16],"smoothExtinction":[2,"smooth-extinction"],"extension":[1],"showButtons":[4,"show-buttons"],"previewableItem":[32],"type":[32]}]]],["twintag-auth-callback.cjs",[[1,"twintag-auth-callback"]]],["twintag-auth-logout.cjs",[[1,"twintag-auth-logout"]]],["twintag-media.cjs",[[1,"twintag-media",{"first":[1],"middle":[1],"last":[1]}]]],["twintag-ocr-scanner.cjs",[[1,"twintag-ocr-scanner",{"stream":[1040],"mode":[1],"cropX":[2,"crop-x"],"cropY":[2,"crop-y"],"devices":[32]},[[0,"updateZoom","updateZoom"],[2,"recognize","ocrHandler"]]]]],["twintag-offline-actions.cjs",[[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"]]]]],["twintag-offline-state.cjs",[[1,"twintag-offline-state",{"onlineState":[32],"pendingRequests":[32]},[[8,"onlineChanged","onlineChangedHandler"],[8,"offlineRequestsChanged","offlineRequestsChangedHandler"]]]]],["twintag-offline-support.cjs",[[1,"twintag-offline-support",{"autoSync":[4,"auto-sync"],"forceOffline":[4,"force-offline"],"config":[16]}]]],["twintag-qr-scanner.cjs",[[1,"twintag-qr-scanner",{"stream":[1040],"mode":[1],"format":[1],"crop":[514],"devices":[32],"decoderIsBusy":[32]},[[0,"updateZoom","updateZoom"]]]]],["twintag-share.cjs",[[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"]]]]],["twintag-spinner.cjs",[[1,"twintag-spinner",{"color":[513],"duration":[2],"name":[1]}]]],["twintag-pdf-viewer.cjs",[[0,"twintag-pdf-viewer",{"src":[1],"fileName":[1,"file-name"],"file":[32],"fileURL":[32]}]]]], options);
18
+ return index.bootstrapLazy([["twintag-preview.cjs",[[1,"twintag-preview",{"item":[1],"initial":[16],"smoothExtinction":[2,"smooth-extinction"],"extension":[1],"showButtons":[4,"show-buttons"],"previewableItem":[32],"type":[32]}]]],["twintag-auth-callback.cjs",[[1,"twintag-auth-callback"]]],["twintag-auth-logout.cjs",[[1,"twintag-auth-logout"]]],["twintag-media.cjs",[[1,"twintag-media",{"first":[1],"middle":[1],"last":[1]}]]],["twintag-ocr-scanner.cjs",[[1,"twintag-ocr-scanner",{"stream":[1040],"mode":[1],"cropX":[2,"crop-x"],"cropY":[2,"crop-y"],"devices":[32]},[[0,"updateZoom","updateZoom"],[2,"recognize","ocrHandler"]]]]],["twintag-offline-actions.cjs",[[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"]]]]],["twintag-offline-state.cjs",[[1,"twintag-offline-state",{"onlineState":[32],"pendingRequests":[32]},[[8,"onlineChanged","onlineChangedHandler"],[8,"offlineRequestsChanged","offlineRequestsChangedHandler"]]]]],["twintag-offline-support.cjs",[[1,"twintag-offline-support",{"autoSync":[4,"auto-sync"],"forceOffline":[4,"force-offline"],"config":[16]}]]],["twintag-qr-scanner.cjs",[[1,"twintag-qr-scanner",{"stream":[1040],"mode":[1],"format":[1],"crop":[514],"devices":[32],"decoderIsBusy":[32]},[[1,"updateZoom","updateZoom"]]]]],["twintag-share.cjs",[[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"]]]]],["twintag-spinner.cjs",[[1,"twintag-spinner",{"color":[513],"duration":[2],"name":[1]}]]],["twintag-pdf-viewer.cjs",[[0,"twintag-pdf-viewer",{"src":[1],"fileName":[1,"file-name"],"file":[32],"fileURL":[32]}]]]], options);
19
19
  });
@@ -18524,37 +18524,24 @@ class OfflineDataService {
18524
18524
  let objectName;
18525
18525
  let projectId;
18526
18526
  let instanceId;
18527
- let queryParams;
18528
- let splitUrlAndQueryArgs = url.split('?');
18529
- const urlPath = splitUrlAndQueryArgs[0];
18530
- if (splitUrlAndQueryArgs.length > 1) {
18531
- splitUrlAndQueryArgs = splitUrlAndQueryArgs.slice(1);
18532
- }
18533
- if (splitUrlAndQueryArgs.length > 1) {
18534
- queryParams = splitUrlAndQueryArgs.join('?');
18527
+ const url_instance = new URL(url);
18528
+ const queryParams = url.split('?')[1];
18529
+ const path_segments = url_instance.pathname.split('/').filter((s) => s.length > 0);
18530
+ const viewsIndex = path_segments.findIndex((p) => p === 'views');
18531
+ const dataIndex = path_segments.findIndex((p) => p === 'data');
18532
+ const viewOrProject = (viewsIndex > -1 ? 'view' : 'project');
18533
+ if (dataIndex > -1) {
18534
+ objectName = path_segments[dataIndex + 1];
18535
18535
  }
18536
18536
  else {
18537
- queryParams = splitUrlAndQueryArgs[0];
18538
- }
18539
- const pathParts = urlPath.split('/');
18540
- // console.log(pathParts)
18541
- const viewsIndex = pathParts.findIndex((p) => p === 'views');
18542
- const dataIndex = pathParts.findIndex((p) => p === 'data');
18543
- const viewOrProject = viewsIndex > -1 ? 'view' : 'project';
18544
- objectName = pathParts[dataIndex + 1];
18537
+ objectName = 'metadata';
18538
+ }
18545
18539
  if (viewsIndex > -1) {
18546
- viewId = pathParts[viewsIndex + 1];
18547
- }
18548
- let lastPathPart = pathParts[pathParts.length - 1];
18549
- if (lastPathPart !== objectName) {
18550
- if (lastPathPart.includes('?')) {
18551
- const parts = lastPathPart.split('?');
18552
- lastPathPart = parts[0];
18553
- queryParams = parts[1];
18554
- }
18555
- if (lastPathPart !== '') {
18556
- instanceId = lastPathPart;
18557
- }
18540
+ viewId = path_segments[viewsIndex + 1];
18541
+ }
18542
+ let lastPathPart = path_segments[path_segments.length - 1];
18543
+ if (lastPathPart !== objectName && lastPathPart !== '') {
18544
+ instanceId = lastPathPart;
18558
18545
  }
18559
18546
  return {
18560
18547
  type: viewOrProject,
@@ -11,262 +11,6 @@ const workerMsgId = 'stencil.scanner.worker';
11
11
  const workerPath = /*@__PURE__*/(typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/scanner.worker-02c80109.js').href : new URL('scanner.worker-02c80109.js', document.currentScript && document.currentScript.src || document.baseURI).href);
12
12
  const worker = /*@__PURE__*/_workerHelper.createWorker(workerPath, workerName, workerMsgId);
13
13
 
14
- class Preprocessing {
15
- constructor(canvas, context) {
16
- this.canvas = canvas;
17
- this.context = context;
18
- }
19
- preprocessImage() {
20
- const processedImageData = this.context.getImageData(0, 0, this.canvas.width, this.canvas.height);
21
- this.blurARGB(processedImageData.data, this.canvas, 1);
22
- this.dilate(processedImageData.data, this.canvas);
23
- this.invertColors(processedImageData.data);
24
- this.thresholdFilter(processedImageData.data, 0.4);
25
- return processedImageData;
26
- }
27
- // from https://github.com/processing/p5.js/blob/main/src/image/filters.js
28
- thresholdFilter(pixels, level) {
29
- if (level === undefined)
30
- level = 0.5;
31
- const thresh = Math.floor(level * 255);
32
- for (let i = 0; i < pixels.length; i += 4) {
33
- const r = pixels[i];
34
- const g = pixels[i + 1];
35
- const b = pixels[i + 2];
36
- const gray = 0.2126 * r + 0.7152 * g + 0.0722 * b;
37
- let val;
38
- if (gray >= thresh)
39
- val = 255;
40
- else
41
- val = 0;
42
- pixels[i] = pixels[i + 1] = pixels[i + 2] = val;
43
- }
44
- }
45
- getARGB(data, i) {
46
- const offset = i * 4;
47
- return (((data[offset + 3] << 24) & 0xff000000) |
48
- ((data[offset] << 16) & 0x00ff0000) |
49
- ((data[offset + 1] << 8) & 0x0000ff00) |
50
- (data[offset + 2] & 0x000000ff));
51
- }
52
- setPixels(pixels, data) {
53
- let offset = 0;
54
- for (let i = 0, al = pixels.length; i < al; i++) {
55
- offset = i * 4;
56
- pixels[offset + 0] = (data[i] & 0x00ff0000) >>> 16;
57
- pixels[offset + 1] = (data[i] & 0x0000ff00) >>> 8;
58
- pixels[offset + 2] = data[i] & 0x000000ff;
59
- pixels[offset + 3] = (data[i] & 0xff000000) >>> 24;
60
- }
61
- }
62
- invertColors(pixels) {
63
- for (var i = 0; i < pixels.length; i += 4) {
64
- pixels[i] = pixels[i] ^ 255; // Invert Red
65
- pixels[i + 1] = pixels[i + 1] ^ 255; // Invert Green
66
- pixels[i + 2] = pixels[i + 2] ^ 255; // Invert Blue
67
- }
68
- }
69
- // from https://github.com/processing/p5.js/blob/main/src/image/filters.js
70
- dilate(pixels, canvas) {
71
- let currIdx = 0;
72
- const maxIdx = pixels.length ? pixels.length / 4 : 0;
73
- const out = new Int32Array(maxIdx);
74
- let currRowIdx, maxRowIdx, colOrig, colOut, currLum;
75
- let idxRight, idxLeft, idxUp, idxDown;
76
- let colRight, colLeft, colUp, colDown;
77
- let lumRight, lumLeft, lumUp, lumDown;
78
- while (currIdx < maxIdx) {
79
- currRowIdx = currIdx;
80
- maxRowIdx = currIdx + canvas.width;
81
- while (currIdx < maxRowIdx) {
82
- colOrig = colOut = this.getARGB(pixels, currIdx);
83
- idxLeft = currIdx - 1;
84
- idxRight = currIdx + 1;
85
- idxUp = currIdx - canvas.width;
86
- idxDown = currIdx + canvas.width;
87
- if (idxLeft < currRowIdx) {
88
- idxLeft = currIdx;
89
- }
90
- if (idxRight >= maxRowIdx) {
91
- idxRight = currIdx;
92
- }
93
- if (idxUp < 0) {
94
- idxUp = 0;
95
- }
96
- if (idxDown >= maxIdx) {
97
- idxDown = currIdx;
98
- }
99
- colUp = this.getARGB(pixels, idxUp);
100
- colLeft = this.getARGB(pixels, idxLeft);
101
- colDown = this.getARGB(pixels, idxDown);
102
- colRight = this.getARGB(pixels, idxRight);
103
- //compute luminance
104
- currLum =
105
- 77 * ((colOrig >> 16) & 0xff) +
106
- 151 * ((colOrig >> 8) & 0xff) +
107
- 28 * (colOrig & 0xff);
108
- lumLeft =
109
- 77 * ((colLeft >> 16) & 0xff) +
110
- 151 * ((colLeft >> 8) & 0xff) +
111
- 28 * (colLeft & 0xff);
112
- lumRight =
113
- 77 * ((colRight >> 16) & 0xff) +
114
- 151 * ((colRight >> 8) & 0xff) +
115
- 28 * (colRight & 0xff);
116
- lumUp =
117
- 77 * ((colUp >> 16) & 0xff) +
118
- 151 * ((colUp >> 8) & 0xff) +
119
- 28 * (colUp & 0xff);
120
- lumDown =
121
- 77 * ((colDown >> 16) & 0xff) +
122
- 151 * ((colDown >> 8) & 0xff) +
123
- 28 * (colDown & 0xff);
124
- if (lumLeft > currLum) {
125
- colOut = colLeft;
126
- currLum = lumLeft;
127
- }
128
- if (lumRight > currLum) {
129
- colOut = colRight;
130
- currLum = lumRight;
131
- }
132
- if (lumUp > currLum) {
133
- colOut = colUp;
134
- currLum = lumUp;
135
- }
136
- if (lumDown > currLum) {
137
- colOut = colDown;
138
- currLum = lumDown;
139
- }
140
- out[currIdx++] = colOut;
141
- }
142
- }
143
- this.setPixels(pixels, out);
144
- }
145
- // from https://github.com/processing/p5.js/blob/main/src/image/filters.js
146
- buildBlurKernel(r) {
147
- let radius = (r * 3.5) | 0;
148
- radius = radius < 1 ? 1 : radius < 248 ? radius : 248;
149
- if (this.blurRadius !== radius) {
150
- this.blurRadius = radius;
151
- this.blurKernelSize = (1 + this.blurRadius) << 1;
152
- this.blurKernel = new Int32Array(this.blurKernelSize);
153
- this.blurMult = new Array(this.blurKernelSize);
154
- for (let l = 0; l < this.blurKernelSize; l++) {
155
- this.blurMult[l] = new Int32Array(256);
156
- }
157
- let bk, bki;
158
- let bm, bmi;
159
- for (let i = 1, radiusi = radius - 1; i < radius; i++) {
160
- this.blurKernel[radius + i] = this.blurKernel[radiusi] = bki =
161
- radiusi * radiusi;
162
- bm = this.blurMult[radius + i];
163
- bmi = this.blurMult[radiusi--];
164
- for (let j = 0; j < 256; j++) {
165
- bm[j] = bmi[j] = bki * j;
166
- }
167
- }
168
- bk = this.blurKernel[radius] = radius * radius;
169
- bm = this.blurMult[radius];
170
- for (let k = 0; k < 256; k++) {
171
- bm[k] = bk * k;
172
- }
173
- }
174
- }
175
- // from https://github.com/processing/p5.js/blob/main/src/image/filters.js
176
- blurARGB(pixels, canvas, radius) {
177
- const width = canvas.width;
178
- const height = canvas.height;
179
- const numPackedPixels = width * height;
180
- const argb = new Int32Array(numPackedPixels);
181
- for (let j = 0; j < numPackedPixels; j++) {
182
- argb[j] = this.getARGB(pixels, j);
183
- }
184
- let sum, cr, cg, cb, ca;
185
- let read, ri, ym, ymi, bk0;
186
- const a2 = new Int32Array(numPackedPixels);
187
- const r2 = new Int32Array(numPackedPixels);
188
- const g2 = new Int32Array(numPackedPixels);
189
- const b2 = new Int32Array(numPackedPixels);
190
- let yi = 0;
191
- this.buildBlurKernel(radius);
192
- let x, y, i;
193
- let bm;
194
- for (y = 0; y < height; y++) {
195
- for (x = 0; x < width; x++) {
196
- cb = cg = cr = ca = sum = 0;
197
- read = x - this.blurRadius;
198
- if (read < 0) {
199
- bk0 = -read;
200
- read = 0;
201
- }
202
- else {
203
- if (read >= width)
204
- break;
205
- bk0 = 0;
206
- }
207
- for (i = bk0; i < this.blurKernelSize; i++) {
208
- if (read >= width)
209
- break;
210
- const c = argb[read + yi];
211
- bm = this.blurMult[i];
212
- ca += bm[(c & -16777216) >>> 24];
213
- cr += bm[(c & 16711680) >> 16];
214
- cg += bm[(c & 65280) >> 8];
215
- cb += bm[c & 255];
216
- sum += this.blurKernel[i];
217
- read++;
218
- }
219
- ri = yi + x;
220
- a2[ri] = ca / sum;
221
- r2[ri] = cr / sum;
222
- g2[ri] = cg / sum;
223
- b2[ri] = cb / sum;
224
- }
225
- yi += width;
226
- }
227
- yi = 0;
228
- ym = -this.blurRadius;
229
- ymi = ym * width;
230
- for (y = 0; y < height; y++) {
231
- for (x = 0; x < width; x++) {
232
- cb = cg = cr = ca = sum = 0;
233
- if (ym < 0) {
234
- bk0 = ri = -ym;
235
- read = x;
236
- }
237
- else {
238
- if (ym >= height)
239
- break;
240
- bk0 = 0;
241
- ri = ym;
242
- read = x + ymi;
243
- }
244
- for (i = bk0; i < this.blurKernelSize; i++) {
245
- if (ri >= height)
246
- break;
247
- bm = this.blurMult[i];
248
- ca += bm[a2[read]];
249
- cr += bm[r2[read]];
250
- cg += bm[g2[read]];
251
- cb += bm[b2[read]];
252
- sum += this.blurKernel[i];
253
- ri++;
254
- read += width;
255
- }
256
- argb[x + yi] =
257
- ((ca / sum) << 24) |
258
- ((cr / sum) << 16) |
259
- ((cg / sum) << 8) |
260
- (cb / sum);
261
- }
262
- yi += width;
263
- ymi += width;
264
- ym++;
265
- }
266
- this.setPixels(pixels, argb);
267
- }
268
- }
269
-
270
14
  const twintagScannerCss = ":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)}";
271
15
 
272
16
  const TwintagQRScanner = class {
@@ -276,6 +20,8 @@ const TwintagQRScanner = class {
276
20
  this.streamIsActive = index.createEvent(this, "streamIsActive", 7);
277
21
  this.frame = index.createEvent(this, "frame", 7);
278
22
  this.stageScale = 1;
23
+ this.eventsController = new AbortController();
24
+ this.videoIsPlaying = false;
279
25
  this.devices = [];
280
26
  this.decoderIsBusy = false;
281
27
  this.stream = null;
@@ -302,9 +48,6 @@ const TwintagQRScanner = class {
302
48
  }
303
49
  }
304
50
  }
305
- connectedCallback() {
306
- worker.addEventListener('message', this.messageHandler.bind(this));
307
- }
308
51
  messageHandler(e) {
309
52
  const event = e.data;
310
53
  if (event.code === 'busy') {
@@ -313,20 +56,57 @@ const TwintagQRScanner = class {
313
56
  if (event.code === 'ready') {
314
57
  this.decoderIsBusy = false;
315
58
  this.symbol.emit(event.result);
59
+ this.frame.emit(this.canvas.toDataURL('image/png', 0.7));
316
60
  if (this.mode === 'single') {
61
+ this.eventsController.abort();
317
62
  this.stopStream();
318
63
  }
319
64
  }
320
65
  }
321
- async componentDidLoad() {
66
+ componentWillLoad() {
322
67
  this.canvas = document.createElement('canvas');
323
68
  this.context = this.canvas.getContext('2d', {
324
69
  alpha: false,
325
70
  willReadFrequently: true,
326
71
  });
327
- this.preprocessor = new Preprocessing(this.canvas, this.context);
72
+ }
73
+ async componentDidLoad() {
74
+ worker.addEventListener('message', (e) => {
75
+ const event = e.data;
76
+ if (event.code === 'busy') {
77
+ this.decoderIsBusy = true;
78
+ }
79
+ if (event.code === 'ready') {
80
+ this.decoderIsBusy = false;
81
+ this.symbol.emit(event.result);
82
+ if (this.mode === 'single') {
83
+ this.eventsController.abort();
84
+ this.stopStream();
85
+ }
86
+ }
87
+ }, {
88
+ passive: true,
89
+ // @ts-ignore - old typscript version
90
+ signal: this.eventsController.signal,
91
+ });
92
+ document.addEventListener("visibilitychange", async () => {
93
+ if (document.hidden) {
94
+ if (this.stream) {
95
+ this.stopStream();
96
+ }
97
+ }
98
+ else {
99
+ await this.startStream();
100
+ }
101
+ }, {
102
+ passive: true,
103
+ // @ts-ignore - old typscript version
104
+ signal: this.eventsController.signal,
105
+ });
328
106
  this.videoContainerRef.style.setProperty('--crop', `${(1 - this.crop) * 50}`);
329
- await this.startStream();
107
+ if (!document.hidden) {
108
+ await this.startStream();
109
+ }
330
110
  }
331
111
  readBarcodeFromCanvas() {
332
112
  this.drawInCanvas();
@@ -342,7 +122,6 @@ const TwintagQRScanner = class {
342
122
  sourceBuffer: sourceBuffer,
343
123
  },
344
124
  });
345
- this.frame.emit(this.canvas.toDataURL('image/png'));
346
125
  }
347
126
  requestAnimationFrame(this.readBarcodeFromCanvas.bind(this));
348
127
  }
@@ -360,14 +139,26 @@ const TwintagQRScanner = class {
360
139
  async updateStream(constraints) {
361
140
  if (this.stream) {
362
141
  this.stream.getTracks().forEach((track) => {
363
- return track.stop();
142
+ track.stop();
364
143
  });
365
144
  }
366
145
  try {
367
146
  this.stream = await navigator.mediaDevices.getUserMedia(constraints);
147
+ this.video.srcObject = null;
368
148
  this.video.srcObject = this.stream;
369
149
  this.video.setAttribute('playsinline', 'true'); // required to tell iOS safari we don't want fullscreen
370
- await this.video.play();
150
+ // On video playing toggle values
151
+ this.video.onplaying = () => {
152
+ this.videoIsPlaying = true;
153
+ };
154
+ // On video pause toggle values
155
+ this.video.onpause = () => {
156
+ this.videoIsPlaying = false;
157
+ };
158
+ if (!this.videoIsPlaying) {
159
+ await this.video.play();
160
+ this.videoIsPlaying = true;
161
+ }
371
162
  }
372
163
  catch (err) {
373
164
  console.error(err);
@@ -434,6 +225,9 @@ const TwintagQRScanner = class {
434
225
  catch (err) {
435
226
  console.error(err);
436
227
  }
228
+ if (this.stream) {
229
+ this.streamIsActive.emit(true);
230
+ }
437
231
  }
438
232
  async startStream() {
439
233
  const constraints = {
@@ -448,38 +242,38 @@ const TwintagQRScanner = class {
448
242
  constraints.video['zoom'] = true;
449
243
  }
450
244
  await this.getMedia(constraints);
451
- index$1.gsapWithCSS.to(this.videoContainerRef, {
452
- duration: 0.2,
453
- opacity: 1,
454
- onComplete: () => {
455
- this.streamIsActive.emit(true);
456
- const currentStage = Math.min(this.video.videoWidth, this.video.videoHeight);
457
- const maxStageValue = 400;
458
- this.stageScale = Math.min(currentStage, maxStageValue) / currentStage;
459
- const stage = currentStage * this.stageScale;
460
- this.canvas.width = stage;
461
- this.canvas.height = stage;
462
- this.context.canvas.width = stage;
463
- this.context.canvas.height = stage;
464
- this.readBarcodeFromCanvas();
465
- },
466
- });
245
+ if (this.videoIsPlaying) {
246
+ index$1.gsapWithCSS.to(this.videoContainerRef, {
247
+ duration: 0.2,
248
+ opacity: 1,
249
+ onComplete: () => {
250
+ const currentStage = Math.min(this.video.videoWidth, this.video.videoHeight);
251
+ const maxStageValue = 400;
252
+ this.stageScale = Math.min(currentStage, maxStageValue) / currentStage;
253
+ const stage = currentStage * this.stageScale;
254
+ this.canvas.width = stage;
255
+ this.canvas.height = stage;
256
+ this.context.canvas.width = stage;
257
+ this.context.canvas.height = stage;
258
+ this.readBarcodeFromCanvas();
259
+ },
260
+ });
261
+ }
467
262
  }
468
263
  stopStream() {
469
- worker.removeEventListener('message', this.messageHandler.bind(this));
264
+ this.streamIsActive.emit(false);
265
+ this.stream.getTracks().forEach((track) => {
266
+ track.stop();
267
+ });
268
+ this.video.srcObject = null;
269
+ this.context.clearRect(0, 0, this.context.canvas.width, this.context.canvas.height);
470
270
  index$1.gsapWithCSS.to(this.videoContainerRef, {
471
271
  duration: 0.2,
472
272
  opacity: 0,
473
- onComplete: () => {
474
- this.stream.getTracks().forEach((track) => {
475
- return track.stop();
476
- });
477
- this.video.srcObject = null;
478
- this.context.clearRect(0, 0, this.context.canvas.width, this.context.canvas.height);
479
- },
480
273
  });
481
274
  }
482
275
  disconnectedCallback() {
276
+ this.eventsController.abort();
483
277
  this.stopStream();
484
278
  }
485
279
  render() {
@@ -61,37 +61,24 @@ export class OfflineDataService {
61
61
  let objectName;
62
62
  let projectId;
63
63
  let instanceId;
64
- let queryParams;
65
- let splitUrlAndQueryArgs = url.split('?');
66
- const urlPath = splitUrlAndQueryArgs[0];
67
- if (splitUrlAndQueryArgs.length > 1) {
68
- splitUrlAndQueryArgs = splitUrlAndQueryArgs.slice(1);
69
- }
70
- if (splitUrlAndQueryArgs.length > 1) {
71
- queryParams = splitUrlAndQueryArgs.join('?');
64
+ const url_instance = new URL(url);
65
+ const queryParams = url.split('?')[1];
66
+ const path_segments = url_instance.pathname.split('/').filter((s) => s.length > 0);
67
+ const viewsIndex = path_segments.findIndex((p) => p === 'views');
68
+ const dataIndex = path_segments.findIndex((p) => p === 'data');
69
+ const viewOrProject = (viewsIndex > -1 ? 'view' : 'project');
70
+ if (dataIndex > -1) {
71
+ objectName = path_segments[dataIndex + 1];
72
72
  }
73
73
  else {
74
- queryParams = splitUrlAndQueryArgs[0];
74
+ objectName = 'metadata';
75
75
  }
76
- const pathParts = urlPath.split('/');
77
- // console.log(pathParts)
78
- const viewsIndex = pathParts.findIndex((p) => p === 'views');
79
- const dataIndex = pathParts.findIndex((p) => p === 'data');
80
- const viewOrProject = viewsIndex > -1 ? 'view' : 'project';
81
- objectName = pathParts[dataIndex + 1];
82
76
  if (viewsIndex > -1) {
83
- viewId = pathParts[viewsIndex + 1];
77
+ viewId = path_segments[viewsIndex + 1];
84
78
  }
85
- let lastPathPart = pathParts[pathParts.length - 1];
86
- if (lastPathPart !== objectName) {
87
- if (lastPathPart.includes('?')) {
88
- const parts = lastPathPart.split('?');
89
- lastPathPart = parts[0];
90
- queryParams = parts[1];
91
- }
92
- if (lastPathPart !== '') {
93
- instanceId = lastPathPart;
94
- }
79
+ let lastPathPart = path_segments[path_segments.length - 1];
80
+ if (lastPathPart !== objectName && lastPathPart !== '') {
81
+ instanceId = lastPathPart;
95
82
  }
96
83
  return {
97
84
  type: viewOrProject,