@exige/web-scanner-sdk 0.2.14 → 0.2.15

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.
@@ -263,28 +263,28 @@ async function ie(t, n) {
263
263
  //#endregion
264
264
  //#region src/sdk/ort-runtime.ts
265
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() {
266
+ function A() {
267
267
  return {
268
268
  wasm: ae.href,
269
269
  mjs: oe.href
270
270
  };
271
271
  }
272
- function ce(e) {
273
- return typeof e == "string" ? e.trim() || se() : e?.wasm.trim() && e.mjs.trim() ? {
272
+ function se(e) {
273
+ return typeof e == "string" ? e.trim() || A() : e?.wasm.trim() && e.mjs.trim() ? {
274
274
  wasm: e.wasm.trim(),
275
275
  mjs: e.mjs.trim()
276
- } : se();
276
+ } : A();
277
277
  }
278
278
  //#endregion
279
279
  //#region src/sdk/image.ts
280
- function le(e, t, n) {
280
+ function ce(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 ue(e) {
287
+ async function le(e) {
288
288
  let t = URL.createObjectURL(e);
289
289
  try {
290
290
  let e = new Image();
@@ -293,26 +293,26 @@ async function ue(e) {
293
293
  URL.revokeObjectURL(t);
294
294
  }
295
295
  }
296
- async function A(e, n = {}) {
296
+ async function j(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 = le(t.width, t.height, n.maxDimension);
302
+ let t = await createImageBitmap(e), a = ce(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 ue(e);
305
+ e = await le(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 = le(a, o, n.maxDimension);
309
+ let s = ce(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 de(e, t = "image/png", n = .92) {
312
+ function ue(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 fe(e, t, n) {
315
+ function de(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,20 +323,20 @@ function fe(e, t, n) {
323
323
  }
324
324
  //#endregion
325
325
  //#region src/sdk/scan.ts
326
- var pe = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", me = 1280;
327
- function he(e, t, n) {
326
+ var fe = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", pe = 1280;
327
+ function me(e, t, n) {
328
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;
329
+ let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a = L() ? 560 : 900;
330
+ return i >= 1.6 ? Math.min(r, Math.max(a, pe)) : a;
331
331
  }
332
- function j(e) {
332
+ function M(e) {
333
333
  return e?.trim() || "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
334
334
  }
335
- var ge = 3, M, _e = 0, N = /* @__PURE__ */ new Map();
336
- function P(e, t) {
335
+ var he = 3, N, ge = 0, P = /* @__PURE__ */ new Map();
336
+ function F(e, t) {
337
337
  return Math.hypot(e.x - t.x, e.y - t.y);
338
338
  }
339
- function F(e) {
339
+ function I(e) {
340
340
  return {
341
341
  ...e,
342
342
  edges: {
@@ -359,7 +359,7 @@ function F(e) {
359
359
  }
360
360
  };
361
361
  }
362
- function ve(e, t) {
362
+ function _e(e, t) {
363
363
  let n = (e) => ({
364
364
  x: e.x / t,
365
365
  y: e.y / t
@@ -371,42 +371,42 @@ function ve(e, t) {
371
371
  bottomLeft: n(e.bottomLeft)
372
372
  };
373
373
  }
374
- function I() {
374
+ function L() {
375
375
  return typeof navigator > "u" ? !1 : navigator.maxTouchPoints > 0 || navigator.hardwareConcurrency <= 4 || typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
376
376
  }
377
- function ye(t, n, r, i) {
377
+ function ve(t, n, r, i) {
378
378
  return new Promise((a, o) => {
379
- M || (M = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), M.onmessage = (t) => {
379
+ N || (N = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), N.onmessage = (t) => {
380
380
  if (t.data.download?.url) {
381
381
  k(t.data.download.url, t.data.download);
382
382
  return;
383
383
  }
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 = () => {
384
+ let n = P.get(t.data.id);
385
+ 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.")));
386
+ }, N.onerror = () => {
387
387
  let t = new e("worker", "The document worker could not start.");
388
- for (let e of N.values()) e.reject(t);
389
- N.clear(), M?.terminate(), M = void 0;
388
+ for (let e of P.values()) e.reject(t);
389
+ P.clear(), N?.terminate(), N = void 0;
390
390
  });
391
- let s = ++_e;
392
- N.set(s, {
391
+ let s = ++ge;
392
+ P.set(s, {
393
393
  resolve: a,
394
394
  reject: o
395
395
  });
396
396
  let c = t.slice().buffer;
397
- M.postMessage({
397
+ N.postMessage({
398
398
  id: s,
399
399
  pixels: c,
400
400
  width: n,
401
401
  height: r,
402
- modelUrl: j(i.modelUrl),
402
+ modelUrl: M(i.modelUrl),
403
403
  heatmapThreshold: i.heatmapThreshold,
404
404
  cacheModel: i.cacheModel,
405
- ortWasmPaths: ce(i.ortWasmPaths)
405
+ ortWasmPaths: se(i.ortWasmPaths)
406
406
  }, [c]);
407
407
  });
408
408
  }
409
- async function L(n, r) {
409
+ async function R(n, r) {
410
410
  let { width: i, height: a } = n, o = r.minDimension ?? 360;
411
411
  if (Math.min(i, a) < o) return {
412
412
  status: "low-quality",
@@ -415,14 +415,14 @@ async function L(n, r) {
415
415
  sourceWidth: i,
416
416
  sourceHeight: a
417
417
  };
418
- let s = he(i, a, r.maxAnalysisDimension), c = Math.min(1, s / Math.max(i, a)), l = document.createElement("canvas");
418
+ let s = me(i, a, r.maxAnalysisDimension), c = Math.min(1, s / Math.max(i, a)), l = document.createElement("canvas");
419
419
  l.width = Math.max(1, Math.round(i * c)), l.height = Math.max(1, Math.round(a * c));
420
420
  let u = l.getContext("2d", { willReadFrequently: !0 });
421
421
  if (!u) throw t();
422
422
  u.drawImage(n, 0, 0, l.width, l.height);
423
423
  let d = u.getImageData(0, 0, l.width, l.height).data, f;
424
424
  if (r.useWorker !== !1 && typeof Worker < "u") try {
425
- f = await ye(d, l.width, l.height, r);
425
+ f = await ve(d, l.width, l.height, r);
426
426
  } catch (t) {
427
427
  if (t instanceof e && (t.code === "worker" || t.code === "model-http")) throw t;
428
428
  f = {
@@ -445,7 +445,7 @@ async function L(n, r) {
445
445
  modelError: v,
446
446
  inferenceMs: y
447
447
  };
448
- if (p < ge) return {
448
+ if (p < he) return {
449
449
  status: "low-quality",
450
450
  confidence: Math.min(.3, p / 18),
451
451
  message: "The image is too soft or dark to resolve four document edges.",
@@ -461,7 +461,7 @@ async function L(n, r) {
461
461
  sourceHeight: a,
462
462
  ...b
463
463
  };
464
- let x = ve(m.corners, c), S = F(x), C = r.minConfidence ?? .58;
464
+ let x = _e(m.corners, c), S = I(x), C = r.minConfidence ?? .58;
465
465
  return m.confidence < C ? {
466
466
  status: "low-confidence",
467
467
  quad: S,
@@ -482,15 +482,15 @@ async function L(n, r) {
482
482
  ...b
483
483
  };
484
484
  }
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));
485
+ function ye(e, t) {
486
+ 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));
487
487
  return {
488
488
  width: Math.max(1, Math.round(n * i)),
489
489
  height: Math.max(1, Math.round(r * i))
490
490
  };
491
491
  }
492
- function R(e, n, r) {
493
- let { width: i, height: a } = be(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
492
+ function z(e, n, r) {
493
+ let { width: i, height: a } = ye(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
494
494
  if (!o) throw t();
495
495
  let s = o.getImageData(0, 0, e.width, e.height), c = document.createElement("canvas");
496
496
  c.width = i, c.height = a;
@@ -506,37 +506,37 @@ function R(e, n, r) {
506
506
  }
507
507
  return l.putImageData(u, 0, 0), c;
508
508
  }
509
- async function z(e, t = {}) {
510
- return await x("scan"), L(await A(e, { cloneCanvas: !1 }), t);
509
+ async function B(e, t = {}) {
510
+ return await x("scan"), R(await j(e, { cloneCanvas: !1 }), t);
511
511
  }
512
- async function xe(e, t, n = {}) {
512
+ async function be(e, t, n = {}) {
513
513
  await x("scan");
514
- let r = await A(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? (I() ? 2048 : 4096);
514
+ let r = await j(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? (L() ? 2048 : 4096);
515
515
  return {
516
516
  status: "success",
517
517
  corners: t,
518
- quad: F(t),
518
+ quad: I(t),
519
519
  confidence: 1,
520
520
  message: "Captured with the document edges shown in the finder.",
521
521
  sourceWidth: r.width,
522
522
  sourceHeight: r.height,
523
- canvas: R(r, t, i)
523
+ canvas: z(r, t, i)
524
524
  };
525
525
  }
526
- async function Se(e, t = {}) {
526
+ async function xe(e, t = {}) {
527
527
  await x("scan");
528
- let n = await A(e, { cloneCanvas: !1 }), r = await L(n, t);
528
+ let n = await j(e, { cloneCanvas: !1 }), r = await R(n, t);
529
529
  if (r.status !== "success" || !r.corners) return r;
530
- let i = t.maxOutputDimension ?? (I() ? 2048 : 4096);
530
+ let i = t.maxOutputDimension ?? (L() ? 2048 : 4096);
531
531
  return {
532
532
  ...r,
533
- canvas: R(n, r.corners, i),
533
+ canvas: z(n, r.corners, i),
534
534
  message: "Four document edges detected and perspective-corrected."
535
535
  };
536
536
  }
537
537
  //#endregion
538
538
  //#region src/sdk/camera.ts
539
- function B(e, t) {
539
+ function V(e, t) {
540
540
  let { engine: n } = t;
541
541
  return [
542
542
  `${e}:`,
@@ -551,9 +551,9 @@ function B(e, t) {
551
551
  ` torch: ${t.torch.mode} supported=${t.torch.supported} on=${t.torch.on}`
552
552
  ].join("\n");
553
553
  }
554
- function Ce(e) {
554
+ function Se(e) {
555
555
  let t = ["Exige scanner capture report", `time: ${e.capturedAt ?? (/* @__PURE__ */ new Date()).toISOString()}`];
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) {
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(V("shutter", e.shutter)), e.live && t.push(V("live", e.live)), e.finder) {
557
557
  let n = e.finder;
558
558
  t.push([
559
559
  "finder:",
@@ -566,7 +566,7 @@ function Ce(e) {
566
566
  }
567
567
  return `${t.join("\n")}\n`;
568
568
  }
569
- function V(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
569
+ function H(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
570
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;
571
571
  return {
572
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",
@@ -575,12 +575,12 @@ function V(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof nav
575
575
  userAgent: e
576
576
  };
577
577
  }
578
- var we = 1920, Te = 1280;
579
- function H(e) {
580
- let t = e ?? V();
578
+ var Ce = 1080, we = 1920, Te = 1920, Ee = 1280;
579
+ function U(e) {
580
+ let t = e ?? H();
581
581
  return !t.iosWebKit && t.browser === "chrome" && /Android/i.test(t.userAgent) && !/Edg|OPR|SamsungBrowser/i.test(t.userAgent);
582
582
  }
583
- var Ee = 10, U = class {
583
+ var De = 10, W = class {
584
584
  on = !1;
585
585
  darkCount = 0;
586
586
  brightCount = 0;
@@ -603,7 +603,7 @@ var Ee = 10, U = class {
603
603
  return this.on;
604
604
  }
605
605
  };
606
- function W(e, t) {
606
+ function G(e, t) {
607
607
  return t ? e === "alwaysOn" || e === "alwaysOff" ? {
608
608
  mode: e,
609
609
  supported: !0,
@@ -627,37 +627,37 @@ function W(e, t) {
627
627
  automatic: e === "auto"
628
628
  };
629
629
  }
630
- function G(e) {
630
+ function K(e) {
631
631
  let t = Math.floor(e.length / 4);
632
632
  if (!t) return 0;
633
633
  let n = 0;
634
634
  for (let r = 0; r < t * 4; r += 4) n += e[r] * .299 + e[r + 1] * .587 + e[r + 2] * .114;
635
635
  return n / t;
636
636
  }
637
- function De(e, t = 10) {
637
+ function Oe(e, t = 10) {
638
638
  if (e.length < 4) return !0;
639
639
  let n = Math.floor(e.length / 4), r = 0;
640
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);
641
- return G(e) <= t && r / n < .01;
641
+ return K(e) <= t && r / n < .01;
642
642
  }
643
- function K(e, t, n) {
643
+ function q(e, t, n) {
644
644
  if (!t || !n) return 0;
645
645
  let r = document.createElement("canvas");
646
646
  r.width = Math.min(32, t), r.height = Math.min(32, n);
647
647
  let i = r.getContext("2d", { willReadFrequently: !0 });
648
- return i ? (i.drawImage(e, 0, 0, r.width, r.height), G(i.getImageData(0, 0, r.width, r.height).data)) : 0;
648
+ return i ? (i.drawImage(e, 0, 0, r.width, r.height), K(i.getImageData(0, 0, r.width, r.height).data)) : 0;
649
649
  }
650
- function Oe(e) {
651
- return K(e, e.width, e.height);
650
+ function ke(e) {
651
+ return q(e, e.width, e.height);
652
652
  }
653
- function ke(e, t = 120) {
653
+ function Ae(e, t = 120) {
654
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 = () => {
655
655
  a && (o = i ? e.requestVideoFrameCallback(f) : requestAnimationFrame(f));
656
656
  };
657
657
  function f() {
658
658
  if (!a) return;
659
659
  let { videoWidth: i, videoHeight: o } = e, f = performance.now();
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();
660
+ r && i && o && f - s >= t && (s = f, l = q(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();
661
661
  }
662
662
  return d(), {
663
663
  stop() {
@@ -669,13 +669,13 @@ function ke(e, t = 120) {
669
669
  getMirrorAgeMs: () => c ? performance.now() - c : Infinity
670
670
  };
671
671
  }
672
- function Ae(e) {
672
+ function je(e) {
673
673
  let t = document.createElement("canvas");
674
674
  return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
675
675
  }
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), {
676
+ function J(e = {}, t = H()) {
677
+ let n = U(t), r = e.idealWidth ?? (n ? 1080 : 3840), i = e.idealHeight ?? (n ? 1920 : 2160), a = { ideal: r }, o = { ideal: i };
678
+ return e.maxWidth && (a.max = e.maxWidth), e.maxHeight ? o.max = e.maxHeight : n && e.maxWidth === void 0 && (o.max = Te), {
679
679
  audio: !1,
680
680
  video: {
681
681
  facingMode: { ideal: e.facingMode ?? "environment" },
@@ -688,42 +688,65 @@ function q(e = {}, t = V()) {
688
688
  }
689
689
  };
690
690
  }
691
- function J(e, n) {
691
+ function Me(e, t, n) {
692
+ let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
693
+ return {
694
+ width: Math.max(1, Math.round(e * r)),
695
+ height: Math.max(1, Math.round(t * r))
696
+ };
697
+ }
698
+ function Y(e, n) {
692
699
  if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
693
- let r = n ? Math.min(1, n / Math.max(e.videoWidth, e.videoHeight)) : 1, i = document.createElement("canvas");
694
- i.width = Math.max(1, Math.round(e.videoWidth * r)), i.height = Math.max(1, Math.round(e.videoHeight * r));
700
+ let r = Me(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
701
+ i.width = r.width, i.height = r.height;
695
702
  let a = i.getContext("2d");
696
703
  if (!a) throw t();
697
704
  return a.drawImage(e, 0, 0, i.width, i.height), i;
698
705
  }
699
- function je(e) {
700
- let t = V();
701
- return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [q(e, t)] : [
702
- q({
706
+ function Ne(e) {
707
+ let t = H();
708
+ return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [J(e, t)] : U(t) ? [
709
+ J({
710
+ ...e,
711
+ idealWidth: Ce,
712
+ idealHeight: we
713
+ }, t),
714
+ J({
715
+ ...e,
716
+ idealWidth: 720,
717
+ idealHeight: 1280
718
+ }, t),
719
+ J({
720
+ ...e,
721
+ idealWidth: 1920,
722
+ idealHeight: 1080
723
+ }, t)
724
+ ] : [
725
+ J({
703
726
  ...e,
704
727
  idealWidth: 3840,
705
728
  idealHeight: 2160
706
729
  }, t),
707
- q({
730
+ J({
708
731
  ...e,
709
732
  idealWidth: 2560,
710
733
  idealHeight: 1440
711
734
  }, t),
712
- q({
735
+ J({
713
736
  ...e,
714
737
  idealWidth: 1920,
715
738
  idealHeight: 1080
716
739
  }, t)
717
740
  ];
718
741
  }
719
- async function Me(t, n = {}) {
742
+ async function Pe(t, n = {}) {
720
743
  await x("scan");
721
744
  let r = n.torch ?? "alwaysOff";
722
745
  if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
723
746
  if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
724
747
  t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
725
748
  let i, a;
726
- for (let e of je(n)) try {
749
+ for (let e of Ne(n)) try {
727
750
  i = await navigator.mediaDevices.getUserMedia(e);
728
751
  break;
729
752
  } catch (e) {
@@ -736,7 +759,7 @@ async function Me(t, n = {}) {
736
759
  for (let e of i.getTracks()) e.stop();
737
760
  throw Error("The camera did not provide a video track.");
738
761
  }
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) => {
762
+ let s = Ae(t), c = "ImageCapture" in globalThis, l = G(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
740
763
  if (!l.supported || o.readyState !== "live") return !1;
741
764
  try {
742
765
  return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
@@ -754,7 +777,7 @@ async function Me(t, n = {}) {
754
777
  }
755
778
  };
756
779
  l.on && await d(!0);
757
- let f = r === "auto" && l.supported ? new U() : void 0, p = f ? window.setInterval(() => {
780
+ let f = r === "auto" && l.supported ? new W() : void 0, p = f ? window.setInterval(() => {
758
781
  if (u || !l.supported) return;
759
782
  let e = f.update(s.getLiveLuminance());
760
783
  e !== void 0 && e !== l.on && (u = !0, d(e).finally(() => {
@@ -780,7 +803,7 @@ async function Me(t, n = {}) {
780
803
  torchSupported: l.supported,
781
804
  torchOn: l.on,
782
805
  torch: { ...l },
783
- engine: V()
806
+ engine: H()
784
807
  };
785
808
  };
786
809
  return {
@@ -794,15 +817,15 @@ async function Me(t, n = {}) {
794
817
  get torchOn() {
795
818
  return l.on;
796
819
  },
797
- capture: (e) => J(t, e),
820
+ capture: (e) => Y(t, e),
798
821
  async capturePhoto() {
799
822
  let e, n = 0;
800
823
  try {
801
- e = J(t), n = Oe(e);
824
+ e = Y(t), n = ke(e);
802
825
  } catch {
803
826
  e = void 0;
804
827
  }
805
- let r = s.getFrame(), i = e && n > 10 ? e : void 0, a = i ?? (r ? Ae(r) : void 0);
828
+ let r = s.getFrame(), i = e && n > 10 ? e : void 0, a = i ?? (r ? je(r) : void 0);
806
829
  if (!a) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
807
830
  return {
808
831
  frame: a,
@@ -828,12 +851,12 @@ async function Me(t, n = {}) {
828
851
  }
829
852
  //#endregion
830
853
  //#region src/sdk/lighting.ts
831
- function Ne(e, t) {
854
+ function Fe(e, t) {
832
855
  if (!e.length) return 0;
833
856
  let n = [...e].sort((e, t) => e - t);
834
857
  return n[Math.min(n.length - 1, Math.floor(n.length * t))];
835
858
  }
836
- function Pe(e, t, n, r = 12) {
859
+ function Ie(e, t, n, r = 12) {
837
860
  if (!t || !n || e.length < t * n) return {
838
861
  strong: !1,
839
862
  strength: 0,
@@ -856,7 +879,7 @@ function Pe(e, t, n, r = 12) {
856
879
  });
857
880
  }
858
881
  }
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 = [];
882
+ let s = Fe(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
860
883
  for (let e = 0; e < o.length; e += 1) {
861
884
  if (!c[e] || l[e]) continue;
862
885
  let t = [], n = [e];
@@ -904,7 +927,7 @@ function Pe(e, t, n, r = 12) {
904
927
  }
905
928
  return d;
906
929
  }
907
- function Fe(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
930
+ function Le(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
908
931
  let i = t + 1, a = new Uint32Array((t + 1) * (n + 1));
909
932
  for (let r = 1; r <= n; r += 1) {
910
933
  let n = 0;
@@ -920,7 +943,7 @@ function Fe(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
920
943
  }
921
944
  return o;
922
945
  }
923
- function Ie(e, t, n) {
946
+ function Re(e, t, n) {
924
947
  let r = [
925
948
  e.topLeft,
926
949
  e.topRight,
@@ -934,8 +957,8 @@ function Ie(e, t, n) {
934
957
  height: s - a
935
958
  };
936
959
  }
937
- function Le(e, t) {
938
- let n = Ie(t, e.width, e.height);
960
+ function ze(e, t) {
961
+ let n = Re(t, e.width, e.height);
939
962
  if (n.width <= 0 || n.height <= 0) return {
940
963
  strong: !1,
941
964
  strength: 0,
@@ -954,18 +977,18 @@ function Le(e, t) {
954
977
  i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
955
978
  let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
956
979
  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);
957
- return Pe(o, r.width, r.height);
980
+ return Ie(o, r.width, r.height);
958
981
  }
959
982
  //#endregion
960
983
  //#region src/sdk/finder.ts
961
- function Re(e, t) {
984
+ function Be(e, t) {
962
985
  return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
963
986
  }
964
- async function ze(e, t) {
987
+ async function Ve(e, t) {
965
988
  let n = await e();
966
989
  return t(), n;
967
990
  }
968
- function Be(e) {
991
+ function He(e) {
969
992
  return e === "alwaysOn" || e === "only" ? {
970
993
  visible: !1,
971
994
  checked: !0,
@@ -980,7 +1003,7 @@ function Be(e) {
980
1003
  mutable: !0
981
1004
  };
982
1005
  }
983
- function Y(e) {
1006
+ function X(e) {
984
1007
  return [
985
1008
  e.topLeft,
986
1009
  e.topRight,
@@ -988,11 +1011,11 @@ function Y(e) {
988
1011
  e.bottomLeft
989
1012
  ];
990
1013
  }
991
- var Ve = 1600;
992
- function He(e = V()) {
993
- return H(e) ? Te : Ve;
1014
+ var Ue = 1600;
1015
+ function We(e = H()) {
1016
+ return U(e) ? Ee : Ue;
994
1017
  }
995
- function Ue(e) {
1018
+ function Ge(e) {
996
1019
  let t = 0;
997
1020
  for (let n = 0; n < e.length; n += 1) {
998
1021
  let r = e[n], i = e[(n + 1) % e.length];
@@ -1000,42 +1023,42 @@ function Ue(e) {
1000
1023
  }
1001
1024
  return Math.abs(t) / 2;
1002
1025
  }
1003
- function X(e, t) {
1026
+ function Z(e, t) {
1004
1027
  return Math.hypot(e.x - t.x, e.y - t.y);
1005
1028
  }
1006
- var Z = {
1029
+ var Q = {
1007
1030
  widthFill: 0,
1008
1031
  heightFill: 0,
1009
1032
  limitingFill: 0,
1010
1033
  areaFill: 0,
1011
1034
  aspectRatio: 1
1012
1035
  };
1013
- function We(e, t, n) {
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));
1036
+ function Ke(e, t, n) {
1037
+ let r = X(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(Z(c, l), Z(d, u)), p = Math.max(Z(c, d), Z(l, u));
1015
1038
  return {
1016
1039
  widthFill: o,
1017
1040
  heightFill: s,
1018
1041
  limitingFill: Math.max(o, s),
1019
- areaFill: Ue(r) / Math.max(1, t * n),
1042
+ areaFill: Ge(r) / Math.max(1, t * n),
1020
1043
  aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
1021
1044
  };
1022
1045
  }
1023
- function Ge(e, t, n, r = {}) {
1046
+ function qe(e, t, n, r = {}) {
1024
1047
  let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
1025
1048
  if (e.aspectRatio < a) return i;
1026
1049
  let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
1027
1050
  return Math.min(o ?? i + .08, 1 - n * 2);
1028
1051
  }
1029
- function Q(e, t, n = {}) {
1052
+ function Je(e, t, n = {}) {
1030
1053
  let r = n.confidenceThreshold ?? .72;
1031
1054
  if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
1032
1055
  hint: "Place the document in the frame",
1033
1056
  reason: "place-document",
1034
1057
  fillRatio: 0,
1035
- fill: Z,
1058
+ fill: Q,
1036
1059
  readyForAutoCapture: !1
1037
1060
  };
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;
1061
+ let i = X(e.quad), a = Ke(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;
1039
1062
  if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
1040
1063
  hint: "Move farther away",
1041
1064
  reason: "move-farther-away",
@@ -1043,14 +1066,14 @@ function Q(e, t, n = {}) {
1043
1066
  fill: a,
1044
1067
  readyForAutoCapture: !1
1045
1068
  };
1046
- let [u, d, f, p] = i, m = X(u, d), h = X(d, f), g = X(f, p), _ = X(p, u);
1069
+ let [u, d, f, p] = i, m = Z(u, d), h = Z(d, f), g = Z(f, p), _ = Z(p, u);
1047
1070
  return Math.min(Math.min(m, g) / Math.max(1, Math.max(m, g)), Math.min(_, h) / Math.max(1, Math.max(_, h))) < (t.previouslyReady ? n.exitMinPerspectiveRatio ?? .4 : n.minPerspectiveRatio ?? .48) ? {
1048
1071
  hint: "Hold the camera straight",
1049
1072
  reason: "straighten-camera",
1050
1073
  fillRatio: o,
1051
1074
  fill: a,
1052
1075
  readyForAutoCapture: !1
1053
- } : o < Ge(a, t.previouslyReady === !0, s, n) ? {
1076
+ } : o < qe(a, t.previouslyReady === !0, s, n) ? {
1054
1077
  hint: "Move closer",
1055
1078
  reason: "move-closer",
1056
1079
  fillRatio: o,
@@ -1081,8 +1104,8 @@ var $ = class {
1081
1104
  ready: !1,
1082
1105
  movement: Infinity
1083
1106
  };
1084
- let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...Y(e.quad).map((e, n) => {
1085
- let r = Y(this.previous)[n];
1107
+ let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...X(e.quad).map((e, n) => {
1108
+ let r = X(this.previous)[n];
1086
1109
  return Math.hypot(e.x - r.x, e.y - r.y) / Math.max(1, t);
1087
1110
  })) : Infinity, r = this.options.exitCornerTolerance ?? Math.max(this.options.cornerTolerance, .036);
1088
1111
  return this.ready && this.previous && n <= r ? this.count = Math.max(this.options.stableFrames, this.count + 1) : (this.ready = !1, this.count = this.previous && n <= this.options.cornerTolerance ? this.count + 1 : 1, this.count >= this.options.stableFrames && (this.ready = !0)), this.previous = e.quad, {
@@ -1092,14 +1115,14 @@ var $ = class {
1092
1115
  };
1093
1116
  }
1094
1117
  };
1095
- function Ke(e, n) {
1096
- let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
1097
- i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
1118
+ function Ye(e, n) {
1119
+ let r = Me(e.width, e.height, n), i = document.createElement("canvas");
1120
+ i.width = r.width, i.height = r.height;
1098
1121
  let a = i.getContext("2d");
1099
1122
  if (!a) throw t();
1100
1123
  return a.drawImage(e, 0, 0, i.width, i.height), i;
1101
1124
  }
1102
- function qe() {
1125
+ function Xe() {
1103
1126
  let e = window.AudioContext ?? window.webkitAudioContext;
1104
1127
  if (!e) return;
1105
1128
  let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
@@ -1110,29 +1133,29 @@ function qe() {
1110
1133
  let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
1111
1134
  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();
1112
1135
  }
1113
- async function Je(e) {
1136
+ async function Ze(e) {
1114
1137
  let t = document.createElement("video");
1115
1138
  return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
1116
1139
  }
1117
- async function Ye(t) {
1140
+ async function Qe(t) {
1118
1141
  await x("scan");
1119
- let n = Be(t.autoCapture), r = new $({
1142
+ let n = He(t.autoCapture), r = new $({
1120
1143
  stableFrames: t.stableFrames ?? 4,
1121
1144
  confidenceThreshold: t.confidenceThreshold ?? .72,
1122
1145
  cornerTolerance: t.cornerTolerance ?? .024,
1123
1146
  exitCornerTolerance: t.exitCornerTolerance ?? .036
1124
- }), i = t.maxFrameDimension ?? He(), a = t.intervalMs ?? 140, o = {
1147
+ }), i = t.maxFrameDimension ?? We(), a = t.intervalMs ?? 140, o = {
1125
1148
  minDimension: 220,
1126
1149
  maxAnalysisDimension: i,
1127
1150
  ...t.detection
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 = {
1151
+ }, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await Ze(t.source) : t.source, c = !0, l = !1, u = !1, d = 0, f, p = {
1129
1152
  state: "detecting",
1130
1153
  confidence: 0,
1131
1154
  guidance: {
1132
1155
  hint: "Place the document in the frame",
1133
1156
  reason: "place-document",
1134
1157
  fillRatio: 0,
1135
- fill: Z,
1158
+ fill: Q,
1136
1159
  readyForAutoCapture: !1
1137
1160
  },
1138
1161
  lighting: {
@@ -1142,7 +1165,7 @@ async function Ye(t) {
1142
1165
  stableFrames: 0,
1143
1166
  requiredStableFrames: t.stableFrames ?? 4,
1144
1167
  autoCapture: { ...n }
1145
- }, m = () => s instanceof HTMLCanvasElement ? Ke(s, i) : J(s, i), h = (e) => {
1168
+ }, m = () => s instanceof HTMLCanvasElement ? Ye(s, i) : Y(s, i), h = (e) => {
1146
1169
  p = e, t.onStatus?.(e);
1147
1170
  }, g = () => {
1148
1171
  c = !1, window.clearTimeout(d), s instanceof HTMLVideoElement && s !== t.source && (s.srcObject = null);
@@ -1151,11 +1174,11 @@ async function Ye(t) {
1151
1174
  l = !0;
1152
1175
  let n;
1153
1176
  try {
1154
- n = await ze(t.captureFrame ?? m, () => {
1177
+ n = await Ve(t.captureFrame ?? m, () => {
1155
1178
  h({
1156
1179
  ...p,
1157
1180
  state: "captured"
1158
- }), t.playShutterSound !== !1 && qe(), g();
1181
+ }), t.playShutterSound !== !1 && Xe(), g();
1159
1182
  });
1160
1183
  } catch (e) {
1161
1184
  throw l = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
@@ -1169,9 +1192,9 @@ async function Ye(t) {
1169
1192
  }, v = async () => {
1170
1193
  if (c && !l) {
1171
1194
  try {
1172
- let e = m(), i = await z(e, o);
1195
+ let e = m(), i = await B(e, o);
1173
1196
  f = i;
1174
- let a = i.quad ? Le(e, i.quad) : {
1197
+ let a = i.quad ? ze(e, i.quad) : {
1175
1198
  strong: !1,
1176
1199
  strength: 0
1177
1200
  }, s = a.strong ? {
@@ -1181,7 +1204,7 @@ async function Ye(t) {
1181
1204
  } : {
1182
1205
  castShadow: !1,
1183
1206
  strength: a.strength
1184
- }, c = r.update(i), l = Q(i, {
1207
+ }, c = r.update(i), l = Je(i, {
1185
1208
  ...c,
1186
1209
  previouslyReady: u
1187
1210
  }, {
@@ -1226,7 +1249,7 @@ async function Ye(t) {
1226
1249
  hint: "Place the document in the frame",
1227
1250
  reason: "place-document",
1228
1251
  fillRatio: 0,
1229
- fill: Z,
1252
+ fill: Q,
1230
1253
  readyForAutoCapture: !1
1231
1254
  },
1232
1255
  lighting: {
@@ -1255,6 +1278,6 @@ async function Ye(t) {
1255
1278
  };
1256
1279
  }
1257
1280
  //#endregion
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 };
1281
+ 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, ie as O, y as P, B as S, ue as T, J as _, Je as a, fe as b, Ie as c, De as d, Y as f, K as g, Oe as h, Ke as i, o as j, ne as k, Le as l, Se as m, He as n, Be as o, H as p, qe as r, Qe as s, $ as t, W as u, Pe as v, xe as w, be as x, G as y };
1259
1282
 
1260
- //# sourceMappingURL=finder-DdnCpnjz.js.map
1283
+ //# sourceMappingURL=finder-Bjo3TAHi.js.map