@exige/web-scanner-sdk 0.2.12 → 0.2.14

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.
@@ -184,7 +184,7 @@ function ee(e) {
184
184
  let t = Number(e.headers.get("content-length"));
185
185
  return Number.isFinite(t) && t > 0 ? t : null;
186
186
  }
187
- function O() {
187
+ function te() {
188
188
  if (w.size === 0) return {
189
189
  downloading: !1,
190
190
  loaded: 0,
@@ -198,22 +198,22 @@ function O() {
198
198
  total: n ? t : null
199
199
  };
200
200
  }
201
- function k() {
202
- let e = O();
201
+ function O() {
202
+ let e = te();
203
203
  for (let t of T) t(e);
204
204
  }
205
- function te(e) {
206
- return e(O()), T.add(e), () => {
205
+ function ne(e) {
206
+ return e(te()), T.add(e), () => {
207
207
  T.delete(e);
208
208
  };
209
209
  }
210
- function A(e, t) {
210
+ function k(e, t) {
211
211
  t.done ? w.delete(e) : w.set(e, {
212
212
  loaded: t.loaded,
213
213
  total: t.total
214
- }), k();
214
+ }), O();
215
215
  }
216
- async function ne(e, t) {
216
+ async function re(e, t) {
217
217
  let n = ee(e);
218
218
  if (!e.body) {
219
219
  let r = await e.arrayBuffer();
@@ -238,53 +238,53 @@ async function ne(e, t) {
238
238
  total: n
239
239
  }), o.buffer;
240
240
  }
241
- async function re(t, n) {
241
+ async function ie(t, n) {
242
242
  let r = E.get(t);
243
243
  if (r) return r.slice(0);
244
244
  let i = D.get(t);
245
245
  if (i) return i.then((e) => e.slice(0));
246
246
  let a = (async () => {
247
- A(t, {
247
+ k(t, {
248
248
  loaded: 0,
249
249
  total: null
250
250
  });
251
251
  let r = await fetch(t, { cache: n?.cache });
252
252
  if (!r.ok) throw new e("model-http", `Model request failed with HTTP ${r.status}.`);
253
- return ne(r, (e) => A(t, e));
253
+ return re(r, (e) => k(t, e));
254
254
  })();
255
255
  D.set(t, a);
256
256
  try {
257
257
  let e = await a;
258
258
  return E.set(t, e), e.slice(0);
259
259
  } finally {
260
- D.delete(t), w.has(t) && (w.delete(t), k());
260
+ D.delete(t), w.has(t) && (w.delete(t), O());
261
261
  }
262
262
  }
263
263
  //#endregion
264
264
  //#region src/sdk/ort-runtime.ts
265
- var ie = new URL("./assets/ort-wasm-simd-threaded.jsep.wasm", import.meta.url), ae = new URL("./assets/ort-wasm-simd-threaded.jsep.mjs", import.meta.url);
266
- function oe() {
265
+ var ae = new URL("./assets/ort-wasm-simd-threaded.jsep.wasm", import.meta.url), oe = new URL("./assets/ort-wasm-simd-threaded.jsep.mjs", import.meta.url);
266
+ function se() {
267
267
  return {
268
- wasm: ie.href,
269
- mjs: ae.href
268
+ wasm: ae.href,
269
+ mjs: oe.href
270
270
  };
271
271
  }
272
- function se(e) {
273
- return typeof e == "string" ? e.trim() || oe() : e?.wasm.trim() && e.mjs.trim() ? {
272
+ function ce(e) {
273
+ return typeof e == "string" ? e.trim() || se() : e?.wasm.trim() && e.mjs.trim() ? {
274
274
  wasm: e.wasm.trim(),
275
275
  mjs: e.mjs.trim()
276
- } : oe();
276
+ } : se();
277
277
  }
278
278
  //#endregion
279
279
  //#region src/sdk/image.ts
280
- function ce(e, t, n) {
280
+ function le(e, t, n) {
281
281
  let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
282
282
  return {
283
283
  width: Math.max(1, Math.round(e * r)),
284
284
  height: Math.max(1, Math.round(t * r))
285
285
  };
286
286
  }
287
- async function le(e) {
287
+ async function ue(e) {
288
288
  let t = URL.createObjectURL(e);
289
289
  try {
290
290
  let e = new Image();
@@ -293,26 +293,26 @@ async function le(e) {
293
293
  URL.revokeObjectURL(t);
294
294
  }
295
295
  }
296
- async function j(e, n = {}) {
296
+ async function A(e, n = {}) {
297
297
  if (e instanceof HTMLCanvasElement && n.cloneCanvas === !1 && !n.maxDimension) return e;
298
298
  let r = document.createElement("canvas"), i = r.getContext("2d", { willReadFrequently: !0 });
299
299
  if (!i) throw t();
300
300
  if (e instanceof Blob) {
301
301
  if ("createImageBitmap" in window) try {
302
- let t = await createImageBitmap(e), a = ce(t.width, t.height, n.maxDimension);
302
+ let t = await createImageBitmap(e), a = le(t.width, t.height, n.maxDimension);
303
303
  return r.width = a.width, r.height = a.height, i.drawImage(t, 0, 0, a.width, a.height), t.close(), r;
304
304
  } catch {}
305
- e = await le(e);
305
+ e = await ue(e);
306
306
  }
307
307
  let a = e instanceof HTMLImageElement ? e.naturalWidth : e.width, o = e instanceof HTMLImageElement ? e.naturalHeight : e.height;
308
308
  if (!a || !o) throw Error("The image has no readable dimensions.");
309
- let s = ce(a, o, n.maxDimension);
309
+ let s = le(a, o, n.maxDimension);
310
310
  return r.width = s.width, r.height = s.height, i.drawImage(e, 0, 0, s.width, s.height), r;
311
311
  }
312
- function ue(e, t = "image/png", n = .92) {
312
+ function de(e, t = "image/png", n = .92) {
313
313
  return new Promise((r, i) => e.toBlob((e) => e ? r(e) : i(/* @__PURE__ */ Error("Could not encode the image.")), t, n));
314
314
  }
315
- function de(e, t, n) {
315
+ function fe(e, t, n) {
316
316
  let r = Math.max(0, Math.min(t, e.x)), i = Math.max(0, Math.min(n, e.y));
317
317
  return {
318
318
  x: r,
@@ -323,15 +323,20 @@ function de(e, t, n) {
323
323
  }
324
324
  //#endregion
325
325
  //#region src/sdk/scan.ts
326
- var fe = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
327
- function M(e) {
326
+ var pe = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", me = 1280;
327
+ function he(e, t, n) {
328
+ if (n) return n;
329
+ let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a = I() ? 560 : 900;
330
+ return i >= 1.6 ? Math.min(r, Math.max(a, me)) : a;
331
+ }
332
+ function j(e) {
328
333
  return e?.trim() || "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
329
334
  }
330
- var pe = 3, N, me = 0, P = /* @__PURE__ */ new Map();
331
- function F(e, t) {
335
+ var ge = 3, M, _e = 0, N = /* @__PURE__ */ new Map();
336
+ function P(e, t) {
332
337
  return Math.hypot(e.x - t.x, e.y - t.y);
333
338
  }
334
- function I(e) {
339
+ function F(e) {
335
340
  return {
336
341
  ...e,
337
342
  edges: {
@@ -354,7 +359,7 @@ function I(e) {
354
359
  }
355
360
  };
356
361
  }
357
- function he(e, t) {
362
+ function ve(e, t) {
358
363
  let n = (e) => ({
359
364
  x: e.x / t,
360
365
  y: e.y / t
@@ -366,42 +371,42 @@ function he(e, t) {
366
371
  bottomLeft: n(e.bottomLeft)
367
372
  };
368
373
  }
369
- function L() {
374
+ function I() {
370
375
  return typeof navigator > "u" ? !1 : navigator.maxTouchPoints > 0 || navigator.hardwareConcurrency <= 4 || typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
371
376
  }
372
- function ge(t, n, r, i) {
377
+ function ye(t, n, r, i) {
373
378
  return new Promise((a, o) => {
374
- N || (N = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), N.onmessage = (t) => {
379
+ M || (M = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), M.onmessage = (t) => {
375
380
  if (t.data.download?.url) {
376
- A(t.data.download.url, t.data.download);
381
+ k(t.data.download.url, t.data.download);
377
382
  return;
378
383
  }
379
- let n = P.get(t.data.id);
380
- n && (P.delete(t.data.id), t.data.error ? n.reject(t.data.errorCode ? new e(t.data.errorCode, t.data.error) : Error(t.data.error)) : t.data.result ? n.resolve(t.data.result) : n.reject(/* @__PURE__ */ Error("The document worker returned no result.")));
381
- }, N.onerror = () => {
384
+ let n = N.get(t.data.id);
385
+ n && (N.delete(t.data.id), t.data.error ? n.reject(t.data.errorCode ? new e(t.data.errorCode, t.data.error) : Error(t.data.error)) : t.data.result ? n.resolve(t.data.result) : n.reject(/* @__PURE__ */ Error("The document worker returned no result.")));
386
+ }, M.onerror = () => {
382
387
  let t = new e("worker", "The document worker could not start.");
383
- for (let e of P.values()) e.reject(t);
384
- P.clear(), N?.terminate(), N = void 0;
388
+ for (let e of N.values()) e.reject(t);
389
+ N.clear(), M?.terminate(), M = void 0;
385
390
  });
386
- let s = ++me;
387
- P.set(s, {
391
+ let s = ++_e;
392
+ N.set(s, {
388
393
  resolve: a,
389
394
  reject: o
390
395
  });
391
396
  let c = t.slice().buffer;
392
- N.postMessage({
397
+ M.postMessage({
393
398
  id: s,
394
399
  pixels: c,
395
400
  width: n,
396
401
  height: r,
397
- modelUrl: M(i.modelUrl),
402
+ modelUrl: j(i.modelUrl),
398
403
  heatmapThreshold: i.heatmapThreshold,
399
404
  cacheModel: i.cacheModel,
400
- ortWasmPaths: se(i.ortWasmPaths)
405
+ ortWasmPaths: ce(i.ortWasmPaths)
401
406
  }, [c]);
402
407
  });
403
408
  }
404
- async function R(n, r) {
409
+ async function L(n, r) {
405
410
  let { width: i, height: a } = n, o = r.minDimension ?? 360;
406
411
  if (Math.min(i, a) < o) return {
407
412
  status: "low-quality",
@@ -410,14 +415,14 @@ async function R(n, r) {
410
415
  sourceWidth: i,
411
416
  sourceHeight: a
412
417
  };
413
- let s = L() ? 560 : 900, c = Math.min(1, (r.maxAnalysisDimension ?? s) / Math.max(i, a)), l = document.createElement("canvas");
418
+ let s = he(i, a, r.maxAnalysisDimension), c = Math.min(1, s / Math.max(i, a)), l = document.createElement("canvas");
414
419
  l.width = Math.max(1, Math.round(i * c)), l.height = Math.max(1, Math.round(a * c));
415
420
  let u = l.getContext("2d", { willReadFrequently: !0 });
416
421
  if (!u) throw t();
417
422
  u.drawImage(n, 0, 0, l.width, l.height);
418
423
  let d = u.getImageData(0, 0, l.width, l.height).data, f;
419
424
  if (r.useWorker !== !1 && typeof Worker < "u") try {
420
- f = await ge(d, l.width, l.height, r);
425
+ f = await ye(d, l.width, l.height, r);
421
426
  } catch (t) {
422
427
  if (t instanceof e && (t.code === "worker" || t.code === "model-http")) throw t;
423
428
  f = {
@@ -440,7 +445,7 @@ async function R(n, r) {
440
445
  modelError: v,
441
446
  inferenceMs: y
442
447
  };
443
- if (p < pe) return {
448
+ if (p < ge) return {
444
449
  status: "low-quality",
445
450
  confidence: Math.min(.3, p / 18),
446
451
  message: "The image is too soft or dark to resolve four document edges.",
@@ -456,7 +461,7 @@ async function R(n, r) {
456
461
  sourceHeight: a,
457
462
  ...b
458
463
  };
459
- let x = he(m.corners, c), S = I(x), C = r.minConfidence ?? .58;
464
+ let x = ve(m.corners, c), S = F(x), C = r.minConfidence ?? .58;
460
465
  return m.confidence < C ? {
461
466
  status: "low-confidence",
462
467
  quad: S,
@@ -477,15 +482,15 @@ async function R(n, r) {
477
482
  ...b
478
483
  };
479
484
  }
480
- function _e(e, t) {
481
- let n = Math.max(1, Math.round(Math.max(F(e.topLeft, e.topRight), F(e.bottomLeft, e.bottomRight)))), r = Math.max(1, Math.round(Math.max(F(e.topLeft, e.bottomLeft), F(e.topRight, e.bottomRight)))), i = Math.min(1, t / Math.max(n, r));
485
+ function be(e, t) {
486
+ let n = Math.max(1, Math.round(Math.max(P(e.topLeft, e.topRight), P(e.bottomLeft, e.bottomRight)))), r = Math.max(1, Math.round(Math.max(P(e.topLeft, e.bottomLeft), P(e.topRight, e.bottomRight)))), i = Math.min(1, t / Math.max(n, r));
482
487
  return {
483
488
  width: Math.max(1, Math.round(n * i)),
484
489
  height: Math.max(1, Math.round(r * i))
485
490
  };
486
491
  }
487
- function z(e, n, r) {
488
- let { width: i, height: a } = _e(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
492
+ function R(e, n, r) {
493
+ let { width: i, height: a } = be(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
489
494
  if (!o) throw t();
490
495
  let s = o.getImageData(0, 0, e.width, e.height), c = document.createElement("canvas");
491
496
  c.width = i, c.height = a;
@@ -501,37 +506,37 @@ function z(e, n, r) {
501
506
  }
502
507
  return l.putImageData(u, 0, 0), c;
503
508
  }
504
- async function B(e, t = {}) {
505
- return await x("scan"), R(await j(e, { cloneCanvas: !1 }), t);
509
+ async function z(e, t = {}) {
510
+ return await x("scan"), L(await A(e, { cloneCanvas: !1 }), t);
506
511
  }
507
- async function ve(e, t, n = {}) {
512
+ async function xe(e, t, n = {}) {
508
513
  await x("scan");
509
- let r = await j(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? (L() ? 2048 : 4096);
514
+ let r = await A(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? (I() ? 2048 : 4096);
510
515
  return {
511
516
  status: "success",
512
517
  corners: t,
513
- quad: I(t),
518
+ quad: F(t),
514
519
  confidence: 1,
515
520
  message: "Captured with the document edges shown in the finder.",
516
521
  sourceWidth: r.width,
517
522
  sourceHeight: r.height,
518
- canvas: z(r, t, i)
523
+ canvas: R(r, t, i)
519
524
  };
520
525
  }
521
- async function ye(e, t = {}) {
526
+ async function Se(e, t = {}) {
522
527
  await x("scan");
523
- let n = await j(e, { cloneCanvas: !1 }), r = await R(n, t);
528
+ let n = await A(e, { cloneCanvas: !1 }), r = await L(n, t);
524
529
  if (r.status !== "success" || !r.corners) return r;
525
- let i = t.maxOutputDimension ?? (L() ? 2048 : 4096);
530
+ let i = t.maxOutputDimension ?? (I() ? 2048 : 4096);
526
531
  return {
527
532
  ...r,
528
- canvas: z(n, r.corners, i),
533
+ canvas: R(n, r.corners, i),
529
534
  message: "Four document edges detected and perspective-corrected."
530
535
  };
531
536
  }
532
537
  //#endregion
533
538
  //#region src/sdk/camera.ts
534
- function V(e, t) {
539
+ function B(e, t) {
535
540
  let { engine: n } = t;
536
541
  return [
537
542
  `${e}:`,
@@ -546,9 +551,9 @@ function V(e, t) {
546
551
  ` torch: ${t.torch.mode} supported=${t.torch.supported} on=${t.torch.on}`
547
552
  ].join("\n");
548
553
  }
549
- function be(e) {
554
+ function Ce(e) {
550
555
  let t = ["Exige scanner capture report", `time: ${e.capturedAt ?? (/* @__PURE__ */ new Date()).toISOString()}`];
551
- if (e.error && t.push(`error: ${e.error}`), e.captureMethod && t.push(`method: ${e.captureMethod}`), e.luminance !== void 0 && t.push(`luminance: ${e.luminance.toFixed(1)}`), e.fallbackReason && t.push(`fallback: ${e.fallbackReason}`), e.shutter && t.push(V("shutter", e.shutter)), e.live && t.push(V("live", e.live)), e.finder) {
556
+ if (e.error && t.push(`error: ${e.error}`), e.captureMethod && t.push(`method: ${e.captureMethod}`), e.luminance !== void 0 && t.push(`luminance: ${e.luminance.toFixed(1)}`), e.fallbackReason && t.push(`fallback: ${e.fallbackReason}`), e.shutter && t.push(B("shutter", e.shutter)), e.live && t.push(B("live", e.live)), e.finder) {
552
557
  let n = e.finder;
553
558
  t.push([
554
559
  "finder:",
@@ -561,7 +566,7 @@ function be(e) {
561
566
  }
562
567
  return `${t.join("\n")}\n`;
563
568
  }
564
- function H(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
569
+ function V(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
565
570
  let n = /CriOS|Chrome/i.test(e) ? "chrome" : /EdgiOS|Edg/i.test(e) ? "edge" : /FxiOS|Firefox/i.test(e) ? "firefox" : /Safari/i.test(e) ? "safari" : "unknown", r = /iPhone|iPad|iPod/i.test(e) || /Macintosh/i.test(e) && t > 1, i = /CriOS|EdgiOS|FxiOS|OPiOS|Mercury/i.test(e), a = r || i;
566
571
  return {
567
572
  engine: a || /AppleWebKit/i.test(e) && !/Chrome|Chromium|Edg/i.test(e) ? "webkit" : /Chrome|Chromium|Edg/i.test(e) ? "blink" : /Gecko\//i.test(e) ? "gecko" : "unknown",
@@ -570,7 +575,12 @@ function H(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof nav
570
575
  userAgent: e
571
576
  };
572
577
  }
573
- var xe = 10, U = class {
578
+ var we = 1920, Te = 1280;
579
+ function H(e) {
580
+ let t = e ?? V();
581
+ return !t.iosWebKit && t.browser === "chrome" && /Android/i.test(t.userAgent) && !/Edg|OPR|SamsungBrowser/i.test(t.userAgent);
582
+ }
583
+ var Ee = 10, U = class {
574
584
  on = !1;
575
585
  darkCount = 0;
576
586
  brightCount = 0;
@@ -624,30 +634,30 @@ function G(e) {
624
634
  for (let r = 0; r < t * 4; r += 4) n += e[r] * .299 + e[r + 1] * .587 + e[r + 2] * .114;
625
635
  return n / t;
626
636
  }
627
- function Se(e, t = 10) {
637
+ function De(e, t = 10) {
628
638
  if (e.length < 4) return !0;
629
639
  let n = Math.floor(e.length / 4), r = 0;
630
640
  for (let i = 0; i < n * 4; i += 4) e[i] * .299 + e[i + 1] * .587 + e[i + 2] * .114 > t * 2 && (r += 1);
631
641
  return G(e) <= t && r / n < .01;
632
642
  }
633
- function Ce(e, t, n) {
643
+ function K(e, t, n) {
634
644
  if (!t || !n) return 0;
635
645
  let r = document.createElement("canvas");
636
646
  r.width = Math.min(32, t), r.height = Math.min(32, n);
637
647
  let i = r.getContext("2d", { willReadFrequently: !0 });
638
648
  return i ? (i.drawImage(e, 0, 0, r.width, r.height), G(i.getImageData(0, 0, r.width, r.height).data)) : 0;
639
649
  }
640
- function we(e) {
641
- return Ce(e, e.width, e.height);
650
+ function Oe(e) {
651
+ return K(e, e.width, e.height);
642
652
  }
643
- function Te(e, t = 120) {
653
+ function ke(e, t = 120) {
644
654
  let n = document.createElement("canvas"), r = n.getContext("2d"), i = typeof e.requestVideoFrameCallback == "function", a = !0, o = 0, s = 0, c = 0, l = 0, u = 0, d = () => {
645
655
  a && (o = i ? e.requestVideoFrameCallback(f) : requestAnimationFrame(f));
646
656
  };
647
657
  function f() {
648
658
  if (!a) return;
649
659
  let { videoWidth: i, videoHeight: o } = e, f = performance.now();
650
- r && i && o && f - s >= t && (s = f, l = Ce(e, i, o), l > 10 && ((n.width !== i || n.height !== o) && (n.width = i, n.height = o), r.drawImage(e, 0, 0, i, o), u = l, c = f)), d();
660
+ r && i && o && f - s >= t && (s = f, l = K(e, i, o), l > 10 && ((n.width !== i || n.height !== o) && (n.width = i, n.height = o), r.drawImage(e, 0, 0, i, o), u = l, c = f)), d();
651
661
  }
652
662
  return d(), {
653
663
  stop() {
@@ -659,18 +669,18 @@ function Te(e, t = 120) {
659
669
  getMirrorAgeMs: () => c ? performance.now() - c : Infinity
660
670
  };
661
671
  }
662
- function Ee(e) {
672
+ function Ae(e) {
663
673
  let t = document.createElement("canvas");
664
674
  return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
665
675
  }
666
- function K(e = {}) {
667
- let t = { ideal: e.idealWidth ?? 3840 }, n = { ideal: e.idealHeight ?? 2160 };
668
- return e.maxWidth && (t.max = e.maxWidth), e.maxHeight && (n.max = e.maxHeight), {
676
+ function q(e = {}, t = V()) {
677
+ let n = H(t) && e.maxWidth === void 0 && e.maxHeight === void 0 ? we : void 0, r = e.idealWidth ?? 3840, i = e.idealHeight ?? 2160, a = { ideal: n ? Math.min(r, n) : r }, o = { ideal: n ? Math.min(i, n) : i };
678
+ return e.maxWidth ? a.max = e.maxWidth : n && (a.max = n), e.maxHeight ? o.max = e.maxHeight : n && (o.max = n), {
669
679
  audio: !1,
670
680
  video: {
671
681
  facingMode: { ideal: e.facingMode ?? "environment" },
672
- width: t,
673
- height: n,
682
+ width: a,
683
+ height: o,
674
684
  frameRate: {
675
685
  ideal: e.maxFrameRate ?? 30,
676
686
  max: e.maxFrameRate ?? 30
@@ -678,7 +688,7 @@ function K(e = {}) {
678
688
  }
679
689
  };
680
690
  }
681
- function q(e, n) {
691
+ function J(e, n) {
682
692
  if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
683
693
  let r = n ? Math.min(1, n / Math.max(e.videoWidth, e.videoHeight)) : 1, i = document.createElement("canvas");
684
694
  i.width = Math.max(1, Math.round(e.videoWidth * r)), i.height = Math.max(1, Math.round(e.videoHeight * r));
@@ -686,33 +696,34 @@ function q(e, n) {
686
696
  if (!a) throw t();
687
697
  return a.drawImage(e, 0, 0, i.width, i.height), i;
688
698
  }
689
- function De(e) {
690
- return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [K(e)] : [
691
- K({
699
+ function je(e) {
700
+ let t = V();
701
+ return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [q(e, t)] : [
702
+ q({
692
703
  ...e,
693
704
  idealWidth: 3840,
694
705
  idealHeight: 2160
695
- }),
696
- K({
706
+ }, t),
707
+ q({
697
708
  ...e,
698
709
  idealWidth: 2560,
699
710
  idealHeight: 1440
700
- }),
701
- K({
711
+ }, t),
712
+ q({
702
713
  ...e,
703
714
  idealWidth: 1920,
704
715
  idealHeight: 1080
705
- })
716
+ }, t)
706
717
  ];
707
718
  }
708
- async function Oe(t, n = {}) {
719
+ async function Me(t, n = {}) {
709
720
  await x("scan");
710
721
  let r = n.torch ?? "alwaysOff";
711
722
  if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
712
723
  if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
713
724
  t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
714
725
  let i, a;
715
- for (let e of De(n)) try {
726
+ for (let e of je(n)) try {
716
727
  i = await navigator.mediaDevices.getUserMedia(e);
717
728
  break;
718
729
  } catch (e) {
@@ -725,7 +736,7 @@ async function Oe(t, n = {}) {
725
736
  for (let e of i.getTracks()) e.stop();
726
737
  throw Error("The camera did not provide a video track.");
727
738
  }
728
- let s = Te(t), c = "ImageCapture" in globalThis, l = W(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
739
+ let s = ke(t), c = "ImageCapture" in globalThis, l = W(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
729
740
  if (!l.supported || o.readyState !== "live") return !1;
730
741
  try {
731
742
  return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
@@ -769,7 +780,7 @@ async function Oe(t, n = {}) {
769
780
  torchSupported: l.supported,
770
781
  torchOn: l.on,
771
782
  torch: { ...l },
772
- engine: H()
783
+ engine: V()
773
784
  };
774
785
  };
775
786
  return {
@@ -783,15 +794,15 @@ async function Oe(t, n = {}) {
783
794
  get torchOn() {
784
795
  return l.on;
785
796
  },
786
- capture: (e) => q(t, e),
797
+ capture: (e) => J(t, e),
787
798
  async capturePhoto() {
788
799
  let e, n = 0;
789
800
  try {
790
- e = q(t), n = we(e);
801
+ e = J(t), n = Oe(e);
791
802
  } catch {
792
803
  e = void 0;
793
804
  }
794
- let r = s.getFrame(), i = e && n > 10 ? e : void 0, a = i ?? (r ? Ee(r) : void 0);
805
+ let r = s.getFrame(), i = e && n > 10 ? e : void 0, a = i ?? (r ? Ae(r) : void 0);
795
806
  if (!a) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
796
807
  return {
797
808
  frame: a,
@@ -817,12 +828,12 @@ async function Oe(t, n = {}) {
817
828
  }
818
829
  //#endregion
819
830
  //#region src/sdk/lighting.ts
820
- function ke(e, t) {
831
+ function Ne(e, t) {
821
832
  if (!e.length) return 0;
822
833
  let n = [...e].sort((e, t) => e - t);
823
834
  return n[Math.min(n.length - 1, Math.floor(n.length * t))];
824
835
  }
825
- function J(e, t, n, r = 12) {
836
+ function Pe(e, t, n, r = 12) {
826
837
  if (!t || !n || e.length < t * n) return {
827
838
  strong: !1,
828
839
  strength: 0,
@@ -845,7 +856,7 @@ function J(e, t, n, r = 12) {
845
856
  });
846
857
  }
847
858
  }
848
- let s = ke(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
859
+ let s = Ne(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
849
860
  for (let e = 0; e < o.length; e += 1) {
850
861
  if (!c[e] || l[e]) continue;
851
862
  let t = [], n = [e];
@@ -893,7 +904,7 @@ function J(e, t, n, r = 12) {
893
904
  }
894
905
  return d;
895
906
  }
896
- function Ae(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
907
+ function Fe(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
897
908
  let i = t + 1, a = new Uint32Array((t + 1) * (n + 1));
898
909
  for (let r = 1; r <= n; r += 1) {
899
910
  let n = 0;
@@ -909,7 +920,7 @@ function Ae(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
909
920
  }
910
921
  return o;
911
922
  }
912
- function je(e, t, n) {
923
+ function Ie(e, t, n) {
913
924
  let r = [
914
925
  e.topLeft,
915
926
  e.topRight,
@@ -923,8 +934,8 @@ function je(e, t, n) {
923
934
  height: s - a
924
935
  };
925
936
  }
926
- function Me(e, t) {
927
- let n = je(t, e.width, e.height);
937
+ function Le(e, t) {
938
+ let n = Ie(t, e.width, e.height);
928
939
  if (n.width <= 0 || n.height <= 0) return {
929
940
  strong: !1,
930
941
  strength: 0,
@@ -943,18 +954,18 @@ function Me(e, t) {
943
954
  i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
944
955
  let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
945
956
  for (let e = 0, t = 0; e < o.length; e += 1, t += 4) o[e] = Math.round(a[t] * .299 + a[t + 1] * .587 + a[t + 2] * .114);
946
- return J(o, r.width, r.height);
957
+ return Pe(o, r.width, r.height);
947
958
  }
948
959
  //#endregion
949
960
  //#region src/sdk/finder.ts
950
- function Ne(e, t) {
961
+ function Re(e, t) {
951
962
  return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
952
963
  }
953
- async function Pe(e, t) {
964
+ async function ze(e, t) {
954
965
  let n = await e();
955
966
  return t(), n;
956
967
  }
957
- function Fe(e) {
968
+ function Be(e) {
958
969
  return e === "alwaysOn" || e === "only" ? {
959
970
  visible: !1,
960
971
  checked: !0,
@@ -977,7 +988,11 @@ function Y(e) {
977
988
  e.bottomLeft
978
989
  ];
979
990
  }
980
- function Ie(e) {
991
+ var Ve = 1600;
992
+ function He(e = V()) {
993
+ return H(e) ? Te : Ve;
994
+ }
995
+ function Ue(e) {
981
996
  let t = 0;
982
997
  for (let n = 0; n < e.length; n += 1) {
983
998
  let r = e[n], i = e[(n + 1) % e.length];
@@ -995,17 +1010,17 @@ var Z = {
995
1010
  areaFill: 0,
996
1011
  aspectRatio: 1
997
1012
  };
998
- function Le(e, t, n) {
1013
+ function We(e, t, n) {
999
1014
  let r = Y(e), i = r.map(({ x: e }) => e), a = r.map(({ y: e }) => e), o = (Math.max(...i) - Math.min(...i)) / Math.max(1, t), s = (Math.max(...a) - Math.min(...a)) / Math.max(1, n), [c, l, u, d] = r, f = Math.max(X(c, l), X(d, u)), p = Math.max(X(c, d), X(l, u));
1000
1015
  return {
1001
1016
  widthFill: o,
1002
1017
  heightFill: s,
1003
1018
  limitingFill: Math.max(o, s),
1004
- areaFill: Ie(r) / Math.max(1, t * n),
1019
+ areaFill: Ue(r) / Math.max(1, t * n),
1005
1020
  aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
1006
1021
  };
1007
1022
  }
1008
- function Re(e, t, n, r = {}) {
1023
+ function Ge(e, t, n, r = {}) {
1009
1024
  let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
1010
1025
  if (e.aspectRatio < a) return i;
1011
1026
  let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
@@ -1020,7 +1035,7 @@ function Q(e, t, n = {}) {
1020
1035
  fill: Z,
1021
1036
  readyForAutoCapture: !1
1022
1037
  };
1023
- let i = Y(e.quad), a = Le(e.quad, e.sourceWidth, e.sourceHeight), o = a.limitingFill, s = t.previouslyReady ? n.exitEdgeMarginRatio ?? .005 : n.edgeMarginRatio ?? .015, c = e.sourceWidth * s, l = e.sourceHeight * s;
1038
+ let i = Y(e.quad), a = We(e.quad, e.sourceWidth, e.sourceHeight), o = a.limitingFill, s = t.previouslyReady ? n.exitEdgeMarginRatio ?? .005 : n.edgeMarginRatio ?? .015, c = e.sourceWidth * s, l = e.sourceHeight * s;
1024
1039
  if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
1025
1040
  hint: "Move farther away",
1026
1041
  reason: "move-farther-away",
@@ -1035,7 +1050,7 @@ function Q(e, t, n = {}) {
1035
1050
  fillRatio: o,
1036
1051
  fill: a,
1037
1052
  readyForAutoCapture: !1
1038
- } : o < Re(a, t.previouslyReady === !0, s, n) ? {
1053
+ } : o < Ge(a, t.previouslyReady === !0, s, n) ? {
1039
1054
  hint: "Move closer",
1040
1055
  reason: "move-closer",
1041
1056
  fillRatio: o,
@@ -1077,14 +1092,14 @@ var $ = class {
1077
1092
  };
1078
1093
  }
1079
1094
  };
1080
- function ze(e, n) {
1095
+ function Ke(e, n) {
1081
1096
  let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
1082
1097
  i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
1083
1098
  let a = i.getContext("2d");
1084
1099
  if (!a) throw t();
1085
1100
  return a.drawImage(e, 0, 0, i.width, i.height), i;
1086
1101
  }
1087
- function Be() {
1102
+ function qe() {
1088
1103
  let e = window.AudioContext ?? window.webkitAudioContext;
1089
1104
  if (!e) return;
1090
1105
  let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
@@ -1095,22 +1110,22 @@ function Be() {
1095
1110
  let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
1096
1111
  o.type = "bandpass", o.frequency.value = 1400, s.gain.value = .42, a.buffer = r, a.connect(o).connect(s).connect(t.destination), a.start(), a.onended = () => void t.close();
1097
1112
  }
1098
- async function Ve(e) {
1113
+ async function Je(e) {
1099
1114
  let t = document.createElement("video");
1100
1115
  return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
1101
1116
  }
1102
- async function He(t) {
1117
+ async function Ye(t) {
1103
1118
  await x("scan");
1104
- let n = Fe(t.autoCapture), r = new $({
1119
+ let n = Be(t.autoCapture), r = new $({
1105
1120
  stableFrames: t.stableFrames ?? 4,
1106
1121
  confidenceThreshold: t.confidenceThreshold ?? .72,
1107
1122
  cornerTolerance: t.cornerTolerance ?? .024,
1108
1123
  exitCornerTolerance: t.exitCornerTolerance ?? .036
1109
- }), i = t.maxFrameDimension ?? 1600, a = t.intervalMs ?? 140, o = {
1124
+ }), i = t.maxFrameDimension ?? He(), a = t.intervalMs ?? 140, o = {
1110
1125
  minDimension: 220,
1111
- maxAnalysisDimension: 520,
1126
+ maxAnalysisDimension: i,
1112
1127
  ...t.detection
1113
- }, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await Ve(t.source) : t.source, c = !0, l = !1, u = !1, d = 0, f, p = {
1128
+ }, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await Je(t.source) : t.source, c = !0, l = !1, u = !1, d = 0, f, p = {
1114
1129
  state: "detecting",
1115
1130
  confidence: 0,
1116
1131
  guidance: {
@@ -1127,7 +1142,7 @@ async function He(t) {
1127
1142
  stableFrames: 0,
1128
1143
  requiredStableFrames: t.stableFrames ?? 4,
1129
1144
  autoCapture: { ...n }
1130
- }, m = () => s instanceof HTMLCanvasElement ? ze(s, i) : q(s, i), h = (e) => {
1145
+ }, m = () => s instanceof HTMLCanvasElement ? Ke(s, i) : J(s, i), h = (e) => {
1131
1146
  p = e, t.onStatus?.(e);
1132
1147
  }, g = () => {
1133
1148
  c = !1, window.clearTimeout(d), s instanceof HTMLVideoElement && s !== t.source && (s.srcObject = null);
@@ -1136,11 +1151,11 @@ async function He(t) {
1136
1151
  l = !0;
1137
1152
  let n;
1138
1153
  try {
1139
- n = await Pe(t.captureFrame ?? m, () => {
1154
+ n = await ze(t.captureFrame ?? m, () => {
1140
1155
  h({
1141
1156
  ...p,
1142
1157
  state: "captured"
1143
- }), t.playShutterSound !== !1 && Be(), g();
1158
+ }), t.playShutterSound !== !1 && qe(), g();
1144
1159
  });
1145
1160
  } catch (e) {
1146
1161
  throw l = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
@@ -1154,9 +1169,9 @@ async function He(t) {
1154
1169
  }, v = async () => {
1155
1170
  if (c && !l) {
1156
1171
  try {
1157
- let e = m(), i = await B(e, o);
1172
+ let e = m(), i = await z(e, o);
1158
1173
  f = i;
1159
- let a = i.quad ? Me(e, i.quad) : {
1174
+ let a = i.quad ? Le(e, i.quad) : {
1160
1175
  strong: !1,
1161
1176
  strength: 0
1162
1177
  }, s = a.strong ? {
@@ -1240,6 +1255,6 @@ async function He(t) {
1240
1255
  };
1241
1256
  }
1242
1257
  //#endregion
1243
- export { a as A, M as C, j as D, de as E, e as F, t as I, x as M, b as N, re as O, y as P, B as S, ue as T, K as _, Q as a, fe as b, J as c, xe as d, q as f, G as g, Se as h, Le as i, o as j, te as k, Ae as l, be as m, Fe as n, Ne as o, H as p, Re as r, He as s, $ as t, U as u, Oe as v, ye as w, ve as x, W as y };
1258
+ export { a as A, j as C, A as D, fe as E, e as F, t as I, x as M, b as N, ie as O, y as P, z as S, de as T, q as _, Q as a, pe as b, Pe as c, Ee as d, J as f, G as g, De as h, We as i, o as j, ne as k, Fe as l, Ce as m, Be as n, Re as o, V as p, Ge as r, Ye as s, $ as t, U as u, Me as v, Se as w, xe as x, W as y };
1244
1259
 
1245
- //# sourceMappingURL=finder-B8yMQmN9.js.map
1260
+ //# sourceMappingURL=finder-DdnCpnjz.js.map