@exige/web-scanner-sdk 0.2.15 → 0.2.22

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.
@@ -277,14 +277,14 @@ function se(e) {
277
277
  }
278
278
  //#endregion
279
279
  //#region src/sdk/image.ts
280
- function ce(e, t, n) {
280
+ function j(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 ce(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 M(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 = j(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 ce(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 = j(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 le(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 ue(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 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", pe = 1280;
327
- function me(e, t, n) {
326
+ var de = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", fe = 1280;
327
+ function pe(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 = L() ? 560 : 900;
330
- return i >= 1.6 ? Math.min(r, Math.max(a, pe)) : a;
329
+ let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a = R() ? 560 : 900;
330
+ return i >= 1.6 ? Math.min(r, Math.max(a, fe)) : a;
331
331
  }
332
- function M(e) {
332
+ function N(e) {
333
333
  return e?.trim() || "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
334
334
  }
335
- var he = 3, N, ge = 0, P = /* @__PURE__ */ new Map();
336
- function F(e, t) {
335
+ var me = 3, P, he = 0, F = /* @__PURE__ */ new Map();
336
+ function I(e, t) {
337
337
  return Math.hypot(e.x - t.x, e.y - t.y);
338
338
  }
339
- function I(e) {
339
+ function L(e) {
340
340
  return {
341
341
  ...e,
342
342
  edges: {
@@ -359,7 +359,7 @@ function I(e) {
359
359
  }
360
360
  };
361
361
  }
362
- function _e(e, t) {
362
+ function ge(e, t) {
363
363
  let n = (e) => ({
364
364
  x: e.x / t,
365
365
  y: e.y / t
@@ -371,42 +371,42 @@ function _e(e, t) {
371
371
  bottomLeft: n(e.bottomLeft)
372
372
  };
373
373
  }
374
- function L() {
374
+ function R() {
375
375
  return typeof navigator > "u" ? !1 : navigator.maxTouchPoints > 0 || navigator.hardwareConcurrency <= 4 || typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
376
376
  }
377
- function ve(t, n, r, i) {
377
+ function _e(t, n, r, i) {
378
378
  return new Promise((a, o) => {
379
- N || (N = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), N.onmessage = (t) => {
379
+ P || (P = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), P.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 = 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 = () => {
384
+ let n = F.get(t.data.id);
385
+ n && (F.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
+ }, P.onerror = () => {
387
387
  let t = new e("worker", "The document worker could not start.");
388
- for (let e of P.values()) e.reject(t);
389
- P.clear(), N?.terminate(), N = void 0;
388
+ for (let e of F.values()) e.reject(t);
389
+ F.clear(), P?.terminate(), P = void 0;
390
390
  });
391
- let s = ++ge;
392
- P.set(s, {
391
+ let s = ++he;
392
+ F.set(s, {
393
393
  resolve: a,
394
394
  reject: o
395
395
  });
396
396
  let c = t.slice().buffer;
397
- N.postMessage({
397
+ P.postMessage({
398
398
  id: s,
399
399
  pixels: c,
400
400
  width: n,
401
401
  height: r,
402
- modelUrl: M(i.modelUrl),
402
+ modelUrl: N(i.modelUrl),
403
403
  heatmapThreshold: i.heatmapThreshold,
404
404
  cacheModel: i.cacheModel,
405
405
  ortWasmPaths: se(i.ortWasmPaths)
406
406
  }, [c]);
407
407
  });
408
408
  }
409
- async function R(n, r) {
409
+ async function ve(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 R(n, r) {
415
415
  sourceWidth: i,
416
416
  sourceHeight: a
417
417
  };
418
- let s = me(i, a, r.maxAnalysisDimension), c = Math.min(1, s / Math.max(i, a)), l = document.createElement("canvas");
418
+ let s = pe(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 ve(d, l.width, l.height, r);
425
+ f = await _e(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 = {
@@ -438,20 +438,21 @@ async function R(n, r) {
438
438
  modelStatus: "failed",
439
439
  modelError: "ML detection requires a Web Worker."
440
440
  };
441
- let { sharpness: p, candidate: m, detector: h, modelStatus: g, modelProvider: _, modelError: v, inferenceMs: y } = f, b = {
441
+ let { sharpness: p, candidate: m, detector: h, modelStatus: g, modelProvider: _, modelError: v, modelNote: y, inferenceMs: b } = f, x = {
442
442
  detector: h,
443
443
  modelStatus: g,
444
444
  modelProvider: _,
445
445
  modelError: v,
446
- inferenceMs: y
446
+ modelNote: y,
447
+ inferenceMs: b
447
448
  };
448
- if (p < he) return {
449
+ if (p < me) return {
449
450
  status: "low-quality",
450
451
  confidence: Math.min(.3, p / 18),
451
452
  message: "The image is too soft or dark to resolve four document edges.",
452
453
  sourceWidth: i,
453
454
  sourceHeight: a,
454
- ...b
455
+ ...x
455
456
  };
456
457
  if (!m) return {
457
458
  status: "no-document",
@@ -459,37 +460,49 @@ async function R(n, r) {
459
460
  message: "No document corners found. Place all four edges on a contrasting surface.",
460
461
  sourceWidth: i,
461
462
  sourceHeight: a,
462
- ...b
463
+ ...x
463
464
  };
464
- let x = _e(m.corners, c), S = I(x), C = r.minConfidence ?? .58;
465
- return m.confidence < C ? {
465
+ let S = ge(m.corners, c), C = L(S), w = r.minConfidence ?? .58;
466
+ return m.confidence < w ? {
466
467
  status: "low-confidence",
467
- quad: S,
468
- corners: x,
468
+ quad: C,
469
+ corners: S,
469
470
  confidence: m.confidence,
470
471
  message: "Four possible corners were found, but the geometry is not reliable enough to crop.",
471
472
  sourceWidth: i,
472
473
  sourceHeight: a,
473
- ...b
474
+ ...x
474
475
  } : {
475
476
  status: "success",
476
- quad: S,
477
- corners: x,
477
+ quad: C,
478
+ corners: S,
478
479
  confidence: m.confidence,
479
480
  message: "Four document edges detected.",
480
481
  sourceWidth: i,
481
482
  sourceHeight: a,
482
- ...b
483
+ ...x
483
484
  };
484
485
  }
485
486
  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
+ let n = Math.max(1, Math.round(Math.max(I(e.topLeft, e.topRight), I(e.bottomLeft, e.bottomRight)))), r = Math.max(1, Math.round(Math.max(I(e.topLeft, e.bottomLeft), I(e.topRight, e.bottomRight)))), i = Math.min(1, t / Math.max(n, r));
487
488
  return {
488
489
  width: Math.max(1, Math.round(n * i)),
489
490
  height: Math.max(1, Math.round(r * i))
490
491
  };
491
492
  }
492
- function z(e, n, r) {
493
+ function be(e, t, n, r, i) {
494
+ let a = Math.max(0, Math.min(t - 1, r)), o = Math.max(0, Math.min(n - 1, i)), s = Math.floor(a), c = Math.floor(o), l = Math.min(t - 1, s + 1), u = Math.min(n - 1, c + 1), d = a - s, f = o - c, p = c * t, m = u * t, h = (t) => {
495
+ let n = e[(p + s) * 4 + t] * (1 - d) + e[(p + l) * 4 + t] * d, r = e[(m + s) * 4 + t] * (1 - d) + e[(m + l) * 4 + t] * d;
496
+ return Math.round(n * (1 - f) + r * f);
497
+ };
498
+ return [
499
+ h(0),
500
+ h(1),
501
+ h(2),
502
+ 255
503
+ ];
504
+ }
505
+ function xe(e, n, r) {
493
506
  let { width: i, height: a } = ye(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
494
507
  if (!o) throw t();
495
508
  let s = o.getImageData(0, 0, e.width, e.height), c = document.createElement("canvas");
@@ -500,43 +513,43 @@ function z(e, n, r) {
500
513
  for (let t = 0; t < a; t += 1) {
501
514
  let n = t / Math.max(1, a - 1);
502
515
  for (let r = 0; r < i; r += 1) {
503
- let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = Math.max(0, Math.min(e.width - 1, Math.round((w * a + T * n + d.x) / o))), l = (Math.max(0, Math.min(e.height - 1, Math.round((E * a + D * n + d.y) / o))) * e.width + c) * 4, f = (t * i + r) * 4;
504
- u.data[f] = s.data[l], u.data[f + 1] = s.data[l + 1], u.data[f + 2] = s.data[l + 2], u.data[f + 3] = s.data[l + 3];
516
+ let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = (w * a + T * n + d.x) / o, l = (E * a + D * n + d.y) / o, [f, p, m, h] = be(s.data, e.width, e.height, c, l), g = (t * i + r) * 4;
517
+ u.data[g] = f, u.data[g + 1] = p, u.data[g + 2] = m, u.data[g + 3] = h;
505
518
  }
506
519
  }
507
520
  return l.putImageData(u, 0, 0), c;
508
521
  }
509
- async function B(e, t = {}) {
510
- return await x("scan"), R(await j(e, { cloneCanvas: !1 }), t);
522
+ async function Se(e, t = {}) {
523
+ return await x("scan"), ve(await M(e, { cloneCanvas: !1 }), t);
511
524
  }
512
- async function be(e, t, n = {}) {
525
+ async function Ce(e, t, n = {}) {
513
526
  await x("scan");
514
- let r = await j(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? (L() ? 2048 : 4096);
527
+ let r = await M(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? (R() ? 2048 : 4096);
515
528
  return {
516
529
  status: "success",
517
530
  corners: t,
518
- quad: I(t),
531
+ quad: L(t),
519
532
  confidence: 1,
520
533
  message: "Captured with the document edges shown in the finder.",
521
534
  sourceWidth: r.width,
522
535
  sourceHeight: r.height,
523
- canvas: z(r, t, i)
536
+ canvas: xe(r, t, i)
524
537
  };
525
538
  }
526
- async function xe(e, t = {}) {
539
+ async function we(e, t = {}) {
527
540
  await x("scan");
528
- let n = await j(e, { cloneCanvas: !1 }), r = await R(n, t);
541
+ let n = await M(e, { cloneCanvas: !1 }), r = await ve(n, t);
529
542
  if (r.status !== "success" || !r.corners) return r;
530
- let i = t.maxOutputDimension ?? (L() ? 2048 : 4096);
543
+ let i = t.maxOutputDimension ?? (R() ? 2048 : 4096);
531
544
  return {
532
545
  ...r,
533
- canvas: z(n, r.corners, i),
546
+ canvas: xe(n, r.corners, i),
534
547
  message: "Four document edges detected and perspective-corrected."
535
548
  };
536
549
  }
537
550
  //#endregion
538
551
  //#region src/sdk/camera.ts
539
- function V(e, t) {
552
+ function z(e, t) {
540
553
  let { engine: n } = t;
541
554
  return [
542
555
  `${e}:`,
@@ -547,13 +560,13 @@ function V(e, t) {
547
560
  ` liveLuma: ${t.liveLuminance.toFixed(1)}`,
548
561
  ` mirrorLuma: ${t.mirrorLuminance.toFixed(1)}`,
549
562
  ` mirrorAgeMs: ${Number.isFinite(t.mirrorAgeMs) ? Math.round(t.mirrorAgeMs) : "none"}`,
550
- ` hasImageCapture: ${t.hasImageCapture} (never used)`,
563
+ ` hasImageCapture: ${t.hasImageCapture}${t.engine.iosWebKit ? " (skipped on webkit)" : " (still capture)"}`,
551
564
  ` torch: ${t.torch.mode} supported=${t.torch.supported} on=${t.torch.on}`
552
565
  ].join("\n");
553
566
  }
554
- function Se(e) {
567
+ function Te(e) {
555
568
  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(V("shutter", e.shutter)), e.live && t.push(V("live", e.live)), e.finder) {
569
+ 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(z("shutter", e.shutter)), e.live && t.push(z("live", e.live)), e.finder) {
557
570
  let n = e.finder;
558
571
  t.push([
559
572
  "finder:",
@@ -561,12 +574,16 @@ function Se(e) {
561
574
  ` confidence: ${n.confidence === void 0 ? "—" : n.confidence.toFixed(3)}`,
562
575
  ` stable: ${n.stableFrames ?? "—"}/${n.requiredStableFrames ?? "—"}`,
563
576
  ` detector: ${n.detector ?? "—"} ${n.modelStatus ?? ""}`.trim(),
577
+ ` modelError: ${n.modelError ?? "—"}`,
578
+ ` provider: ${n.modelProvider ?? "—"}`,
579
+ ` note: ${n.modelNote ?? "—"}`,
580
+ ` inferenceMs: ${n.inferenceMs === void 0 ? "—" : Math.round(n.inferenceMs)}`,
564
581
  ` source: ${n.sourceWidth ?? "—"}x${n.sourceHeight ?? "—"}`
565
582
  ].join("\n"));
566
583
  }
567
584
  return `${t.join("\n")}\n`;
568
585
  }
569
- function H(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
586
+ function B(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
570
587
  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
588
  return {
572
589
  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 +592,22 @@ function H(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof nav
575
592
  userAgent: e
576
593
  };
577
594
  }
578
- var Ce = 1080, we = 1920, Te = 1920, Ee = 1280;
579
- function U(e) {
580
- let t = e ?? H();
581
- return !t.iosWebKit && t.browser === "chrome" && /Android/i.test(t.userAgent) && !/Edg|OPR|SamsungBrowser/i.test(t.userAgent);
595
+ function Ee(e, t) {
596
+ return t && !e.iosWebKit;
582
597
  }
583
- var De = 10, W = class {
598
+ function De(e) {
599
+ let t = e?.imageWidth?.max, n = e?.imageHeight?.max;
600
+ if (t && n && Number.isFinite(t) && Number.isFinite(n)) return {
601
+ imageWidth: Math.round(t),
602
+ imageHeight: Math.round(n)
603
+ };
604
+ }
605
+ function Oe(e, t) {
606
+ if (!e.width || !e.height || !t.width || !t.height) return !1;
607
+ let n = e.width / e.height / (t.width / t.height);
608
+ return n > .97 && n < 1.03;
609
+ }
610
+ var ke = 10, V = class {
584
611
  on = !1;
585
612
  darkCount = 0;
586
613
  brightCount = 0;
@@ -603,7 +630,7 @@ var De = 10, W = class {
603
630
  return this.on;
604
631
  }
605
632
  };
606
- function G(e, t) {
633
+ function H(e, t) {
607
634
  return t ? e === "alwaysOn" || e === "alwaysOff" ? {
608
635
  mode: e,
609
636
  supported: !0,
@@ -627,37 +654,37 @@ function G(e, t) {
627
654
  automatic: e === "auto"
628
655
  };
629
656
  }
630
- function K(e) {
657
+ function U(e) {
631
658
  let t = Math.floor(e.length / 4);
632
659
  if (!t) return 0;
633
660
  let n = 0;
634
661
  for (let r = 0; r < t * 4; r += 4) n += e[r] * .299 + e[r + 1] * .587 + e[r + 2] * .114;
635
662
  return n / t;
636
663
  }
637
- function Oe(e, t = 10) {
664
+ function Ae(e, t = 10) {
638
665
  if (e.length < 4) return !0;
639
666
  let n = Math.floor(e.length / 4), r = 0;
640
667
  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 K(e) <= t && r / n < .01;
668
+ return U(e) <= t && r / n < .01;
642
669
  }
643
- function q(e, t, n) {
670
+ function W(e, t, n) {
644
671
  if (!t || !n) return 0;
645
672
  let r = document.createElement("canvas");
646
673
  r.width = Math.min(32, t), r.height = Math.min(32, n);
647
674
  let i = r.getContext("2d", { willReadFrequently: !0 });
648
- return i ? (i.drawImage(e, 0, 0, r.width, r.height), K(i.getImageData(0, 0, r.width, r.height).data)) : 0;
675
+ return i ? (i.drawImage(e, 0, 0, r.width, r.height), U(i.getImageData(0, 0, r.width, r.height).data)) : 0;
649
676
  }
650
- function ke(e) {
651
- return q(e, e.width, e.height);
677
+ function G(e) {
678
+ return W(e, e.width, e.height);
652
679
  }
653
- function Ae(e, t = 120) {
680
+ function je(e, t = 120) {
654
681
  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
682
  a && (o = i ? e.requestVideoFrameCallback(f) : requestAnimationFrame(f));
656
683
  };
657
684
  function f() {
658
685
  if (!a) return;
659
686
  let { videoWidth: i, videoHeight: o } = e, f = performance.now();
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();
687
+ r && i && o && f - s >= t && (s = f, l = W(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
688
  }
662
689
  return d(), {
663
690
  stop() {
@@ -669,18 +696,18 @@ function Ae(e, t = 120) {
669
696
  getMirrorAgeMs: () => c ? performance.now() - c : Infinity
670
697
  };
671
698
  }
672
- function je(e) {
699
+ function Me(e) {
673
700
  let t = document.createElement("canvas");
674
701
  return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
675
702
  }
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), {
703
+ function K(e = {}) {
704
+ let t = { ideal: e.idealWidth ?? 3840 }, n = { ideal: e.idealHeight ?? 2160 };
705
+ return e.maxWidth && (t.max = e.maxWidth), e.maxHeight && (n.max = e.maxHeight), {
679
706
  audio: !1,
680
707
  video: {
681
708
  facingMode: { ideal: e.facingMode ?? "environment" },
682
- width: a,
683
- height: o,
709
+ width: t,
710
+ height: n,
684
711
  frameRate: {
685
712
  ideal: e.maxFrameRate ?? 30,
686
713
  max: e.maxFrameRate ?? 30
@@ -688,65 +715,65 @@ function J(e = {}, t = H()) {
688
715
  }
689
716
  };
690
717
  }
691
- function Me(e, t, n) {
718
+ function Ne(e, t, n) {
692
719
  let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
693
720
  return {
694
721
  width: Math.max(1, Math.round(e * r)),
695
722
  height: Math.max(1, Math.round(t * r))
696
723
  };
697
724
  }
698
- function Y(e, n) {
725
+ var Pe = 4096;
726
+ async function Fe(e) {
727
+ let n = globalThis.ImageCapture;
728
+ if (!n) return;
729
+ let r = new n(e), i;
730
+ try {
731
+ let e = r.getPhotoCapabilities ? De(await r.getPhotoCapabilities()) : void 0;
732
+ i = await r.takePhoto(e);
733
+ } catch {
734
+ i = await r.takePhoto();
735
+ }
736
+ let a = await createImageBitmap(i), o = Math.min(1, Pe / Math.max(a.width, a.height, 1)), s = document.createElement("canvas");
737
+ s.width = Math.max(1, Math.round(a.width * o)), s.height = Math.max(1, Math.round(a.height * o));
738
+ let c = s.getContext("2d");
739
+ if (!c) throw a.close?.(), t();
740
+ return c.imageSmoothingEnabled = !0, c.imageSmoothingQuality = "high", c.drawImage(a, 0, 0, s.width, s.height), a.close?.(), s;
741
+ }
742
+ function q(e, n) {
699
743
  if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
700
- let r = Me(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
744
+ let r = Ne(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
701
745
  i.width = r.width, i.height = r.height;
702
746
  let a = i.getContext("2d");
703
747
  if (!a) throw t();
704
748
  return a.drawImage(e, 0, 0, i.width, i.height), i;
705
749
  }
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({
750
+ function Ie(e) {
751
+ return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [K(e)] : [
752
+ K({
726
753
  ...e,
727
754
  idealWidth: 3840,
728
755
  idealHeight: 2160
729
- }, t),
730
- J({
756
+ }),
757
+ K({
731
758
  ...e,
732
759
  idealWidth: 2560,
733
760
  idealHeight: 1440
734
- }, t),
735
- J({
761
+ }),
762
+ K({
736
763
  ...e,
737
764
  idealWidth: 1920,
738
765
  idealHeight: 1080
739
- }, t)
766
+ })
740
767
  ];
741
768
  }
742
- async function Pe(t, n = {}) {
769
+ async function Le(t, n = {}) {
743
770
  await x("scan");
744
771
  let r = n.torch ?? "alwaysOff";
745
772
  if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
746
773
  if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
747
774
  t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
748
775
  let i, a;
749
- for (let e of Ne(n)) try {
776
+ for (let e of Ie(n)) try {
750
777
  i = await navigator.mediaDevices.getUserMedia(e);
751
778
  break;
752
779
  } catch (e) {
@@ -759,7 +786,7 @@ async function Pe(t, n = {}) {
759
786
  for (let e of i.getTracks()) e.stop();
760
787
  throw Error("The camera did not provide a video track.");
761
788
  }
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) => {
789
+ let s = je(t), c = "ImageCapture" in globalThis, l = H(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
763
790
  if (!l.supported || o.readyState !== "live") return !1;
764
791
  try {
765
792
  return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
@@ -777,7 +804,7 @@ async function Pe(t, n = {}) {
777
804
  }
778
805
  };
779
806
  l.on && await d(!0);
780
- let f = r === "auto" && l.supported ? new W() : void 0, p = f ? window.setInterval(() => {
807
+ let f = r === "auto" && l.supported ? new V() : void 0, p = f ? window.setInterval(() => {
781
808
  if (u || !l.supported) return;
782
809
  let e = f.update(s.getLiveLuminance());
783
810
  e !== void 0 && e !== l.on && (u = !0, d(e).finally(() => {
@@ -803,7 +830,7 @@ async function Pe(t, n = {}) {
803
830
  torchSupported: l.supported,
804
831
  torchOn: l.on,
805
832
  torch: { ...l },
806
- engine: H()
833
+ engine: B()
807
834
  };
808
835
  };
809
836
  return {
@@ -817,22 +844,49 @@ async function Pe(t, n = {}) {
817
844
  get torchOn() {
818
845
  return l.on;
819
846
  },
820
- capture: (e) => Y(t, e),
847
+ capture: (e) => q(t, e),
821
848
  async capturePhoto() {
822
849
  let e, n = 0;
823
850
  try {
824
- e = Y(t), n = ke(e);
851
+ e = q(t), n = G(e);
825
852
  } catch {
826
853
  e = void 0;
827
854
  }
828
- let r = s.getFrame(), i = e && n > 10 ? e : void 0, a = i ?? (r ? je(r) : void 0);
829
- if (!a) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
830
- return {
831
- frame: a,
832
- method: i ? "video-frame" : "live-mirror",
855
+ let r = s.getFrame(), i, a = !1;
856
+ if (Ee(B(), c)) try {
857
+ i = await Fe(o);
858
+ } catch {
859
+ a = !0, i = void 0;
860
+ }
861
+ let l = i ? G(i) : 0, u = !!(i && Oe(i, {
862
+ width: t.videoWidth,
863
+ height: t.videoHeight
864
+ }));
865
+ if (i && l > 10 && u) return console.info("[exige-scanner] capture", {
866
+ method: "image-capture",
867
+ frame: `${i.width}×${i.height}`,
868
+ video: `${t.videoWidth}×${t.videoHeight}`
869
+ }), {
870
+ frame: i,
871
+ method: "image-capture",
833
872
  settings: o.getSettings(),
834
- fallbackReason: i ? void 0 : "video-frame-empty",
835
- luminance: i ? n : s.getMirrorLuminance(),
873
+ luminance: l,
874
+ diagnostics: m()
875
+ };
876
+ let d = e && n > 10 ? e : void 0, f = d ?? (r ? Me(r) : void 0);
877
+ if (!f) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
878
+ let p = i ? l <= 10 ? "image-capture-empty" : "image-capture-aspect" : a ? "image-capture-failed" : d ? void 0 : "video-frame-empty";
879
+ return console.info("[exige-scanner] capture", {
880
+ method: d ? "video-frame" : "live-mirror",
881
+ frame: `${f.width}×${f.height}`,
882
+ video: `${t.videoWidth}×${t.videoHeight}`,
883
+ fallbackReason: p
884
+ }), {
885
+ frame: f,
886
+ method: d ? "video-frame" : "live-mirror",
887
+ settings: o.getSettings(),
888
+ fallbackReason: p,
889
+ luminance: d ? n : s.getMirrorLuminance(),
836
890
  diagnostics: m()
837
891
  };
838
892
  },
@@ -851,12 +905,12 @@ async function Pe(t, n = {}) {
851
905
  }
852
906
  //#endregion
853
907
  //#region src/sdk/lighting.ts
854
- function Fe(e, t) {
908
+ function Re(e, t) {
855
909
  if (!e.length) return 0;
856
910
  let n = [...e].sort((e, t) => e - t);
857
911
  return n[Math.min(n.length - 1, Math.floor(n.length * t))];
858
912
  }
859
- function Ie(e, t, n, r = 12) {
913
+ function J(e, t, n, r = 12) {
860
914
  if (!t || !n || e.length < t * n) return {
861
915
  strong: !1,
862
916
  strength: 0,
@@ -879,7 +933,7 @@ function Ie(e, t, n, r = 12) {
879
933
  });
880
934
  }
881
935
  }
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 = [];
936
+ let s = Re(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
883
937
  for (let e = 0; e < o.length; e += 1) {
884
938
  if (!c[e] || l[e]) continue;
885
939
  let t = [], n = [e];
@@ -927,23 +981,38 @@ function Ie(e, t, n, r = 12) {
927
981
  }
928
982
  return d;
929
983
  }
930
- function Le(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
931
- let i = t + 1, a = new Uint32Array((t + 1) * (n + 1));
932
- for (let r = 1; r <= n; r += 1) {
984
+ function Y(e, t, n, r, i, a, o) {
985
+ let s = Math.max(0, a - o), c = Math.min(r, a + o + 1), l = Math.max(0, i - o), u = Math.min(n, i + o + 1), d = Math.max(1, (u - l) * (c - s));
986
+ return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
987
+ }
988
+ function X(e, t, n) {
989
+ let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
990
+ for (let a = 1; a <= n; a += 1) {
933
991
  let n = 0;
934
- for (let o = 1; o <= t; o += 1) n += e[(r - 1) * t + o - 1], a[r * i + o] = a[(r - 1) * i + o] + n;
992
+ for (let o = 1; o <= t; o += 1) n += e[(a - 1) * t + o - 1], i[a * r + o] = i[(a - 1) * r + o] + n;
935
993
  }
936
- let o = new Uint8Array(e.length);
937
- for (let s = 0; s < n; s += 1) {
938
- let c = Math.max(0, s - r), l = Math.min(n, s + r + 1);
939
- for (let n = 0; n < t; n += 1) {
940
- let u = Math.max(0, n - r), d = Math.min(t, n + r + 1), f = (d - u) * (l - c), p = (a[l * i + d] - a[c * i + d] - a[l * i + u] + a[c * i + u]) / f;
941
- o[s * t + n] = Math.max(0, Math.min(255, Math.round(e[s * t + n] * 235 / Math.max(24, p))));
942
- }
994
+ return {
995
+ integral: i,
996
+ stride: r
997
+ };
998
+ }
999
+ function ze(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
1000
+ let { integral: i, stride: a } = X(e, t, n), o = new Uint8Array(e.length);
1001
+ for (let s = 0; s < n; s += 1) for (let c = 0; c < t; c += 1) {
1002
+ let l = Y(i, a, t, n, c, s, r);
1003
+ o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
943
1004
  }
944
1005
  return o;
945
1006
  }
946
- function Re(e, t, n) {
1007
+ function Be(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
1008
+ let { integral: a, stride: o } = X(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
1009
+ for (let i = 0; i < n; i += 1) for (let l = 0; l < t; l += 1) {
1010
+ let u = Y(a, o, t, n, l, i, r);
1011
+ s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
1012
+ }
1013
+ return s;
1014
+ }
1015
+ function Ve(e, t, n) {
947
1016
  let r = [
948
1017
  e.topLeft,
949
1018
  e.topRight,
@@ -957,8 +1026,8 @@ function Re(e, t, n) {
957
1026
  height: s - a
958
1027
  };
959
1028
  }
960
- function ze(e, t) {
961
- let n = Re(t, e.width, e.height);
1029
+ function He(e, t) {
1030
+ let n = Ve(t, e.width, e.height);
962
1031
  if (n.width <= 0 || n.height <= 0) return {
963
1032
  strong: !1,
964
1033
  strength: 0,
@@ -977,18 +1046,18 @@ function ze(e, t) {
977
1046
  i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
978
1047
  let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
979
1048
  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);
980
- return Ie(o, r.width, r.height);
1049
+ return J(o, r.width, r.height);
981
1050
  }
982
1051
  //#endregion
983
1052
  //#region src/sdk/finder.ts
984
- function Be(e, t) {
1053
+ function Ue(e, t) {
985
1054
  return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
986
1055
  }
987
- async function Ve(e, t) {
1056
+ async function We(e, t) {
988
1057
  let n = await e();
989
1058
  return t(), n;
990
1059
  }
991
- function He(e) {
1060
+ function Ge(e) {
992
1061
  return e === "alwaysOn" || e === "only" ? {
993
1062
  visible: !1,
994
1063
  checked: !0,
@@ -1003,7 +1072,7 @@ function He(e) {
1003
1072
  mutable: !0
1004
1073
  };
1005
1074
  }
1006
- function X(e) {
1075
+ function Z(e) {
1007
1076
  return [
1008
1077
  e.topLeft,
1009
1078
  e.topRight,
@@ -1011,11 +1080,30 @@ function X(e) {
1011
1080
  e.bottomLeft
1012
1081
  ];
1013
1082
  }
1014
- var Ue = 1600;
1015
- function We(e = H()) {
1016
- return U(e) ? Ee : Ue;
1083
+ function Ke(e, t) {
1084
+ let n = e.status === "success" && e.modelStatus !== "failed", r = {
1085
+ status: e.status,
1086
+ confidence: Number(e.confidence.toFixed(3)),
1087
+ source: `${e.sourceWidth}×${e.sourceHeight}`
1088
+ };
1089
+ t?.width && t?.height && (r.video = `${t.width}×${t.height}`), e.modelStatus && (r.modelStatus = e.modelStatus), e.modelProvider && (r.provider = e.modelProvider), e.modelError && (r.modelError = e.modelError), e.modelNote && (r.modelNote = e.modelNote), e.inferenceMs !== void 0 && (r.inferenceMs = Math.round(e.inferenceMs)), !n && e.message && (r.message = e.message);
1090
+ let i = n ? "document found" : e.modelStatus === "failed" ? "document not found (ML failed)" : `document not found (${e.status})`;
1091
+ return {
1092
+ level: n ? "info" : "warn",
1093
+ key: [
1094
+ i,
1095
+ r.modelStatus ?? "",
1096
+ r.modelError ?? "",
1097
+ r.provider ?? "",
1098
+ r.modelNote ?? "",
1099
+ r.source,
1100
+ r.video ?? ""
1101
+ ].join("|"),
1102
+ summary: i,
1103
+ detail: r
1104
+ };
1017
1105
  }
1018
- function Ge(e) {
1106
+ function qe(e) {
1019
1107
  let t = 0;
1020
1108
  for (let n = 0; n < e.length; n += 1) {
1021
1109
  let r = e[n], i = e[(n + 1) % e.length];
@@ -1023,42 +1111,42 @@ function Ge(e) {
1023
1111
  }
1024
1112
  return Math.abs(t) / 2;
1025
1113
  }
1026
- function Z(e, t) {
1114
+ function Q(e, t) {
1027
1115
  return Math.hypot(e.x - t.x, e.y - t.y);
1028
1116
  }
1029
- var Q = {
1117
+ var $ = {
1030
1118
  widthFill: 0,
1031
1119
  heightFill: 0,
1032
1120
  limitingFill: 0,
1033
1121
  areaFill: 0,
1034
1122
  aspectRatio: 1
1035
1123
  };
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));
1124
+ function Je(e, t, n) {
1125
+ let r = Z(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(Q(c, l), Q(d, u)), p = Math.max(Q(c, d), Q(l, u));
1038
1126
  return {
1039
1127
  widthFill: o,
1040
1128
  heightFill: s,
1041
1129
  limitingFill: Math.max(o, s),
1042
- areaFill: Ge(r) / Math.max(1, t * n),
1130
+ areaFill: qe(r) / Math.max(1, t * n),
1043
1131
  aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
1044
1132
  };
1045
1133
  }
1046
- function qe(e, t, n, r = {}) {
1134
+ function Ye(e, t, n, r = {}) {
1047
1135
  let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
1048
1136
  if (e.aspectRatio < a) return i;
1049
1137
  let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
1050
1138
  return Math.min(o ?? i + .08, 1 - n * 2);
1051
1139
  }
1052
- function Je(e, t, n = {}) {
1140
+ function Xe(e, t, n = {}) {
1053
1141
  let r = n.confidenceThreshold ?? .72;
1054
1142
  if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
1055
1143
  hint: "Place the document in the frame",
1056
1144
  reason: "place-document",
1057
1145
  fillRatio: 0,
1058
- fill: Q,
1146
+ fill: $,
1059
1147
  readyForAutoCapture: !1
1060
1148
  };
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;
1149
+ let i = Z(e.quad), a = Je(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;
1062
1150
  if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
1063
1151
  hint: "Move farther away",
1064
1152
  reason: "move-farther-away",
@@ -1066,14 +1154,14 @@ function Je(e, t, n = {}) {
1066
1154
  fill: a,
1067
1155
  readyForAutoCapture: !1
1068
1156
  };
1069
- let [u, d, f, p] = i, m = Z(u, d), h = Z(d, f), g = Z(f, p), _ = Z(p, u);
1157
+ let [u, d, f, p] = i, m = Q(u, d), h = Q(d, f), g = Q(f, p), _ = Q(p, u);
1070
1158
  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) ? {
1071
1159
  hint: "Hold the camera straight",
1072
1160
  reason: "straighten-camera",
1073
1161
  fillRatio: o,
1074
1162
  fill: a,
1075
1163
  readyForAutoCapture: !1
1076
- } : o < qe(a, t.previouslyReady === !0, s, n) ? {
1164
+ } : o < Ye(a, t.previouslyReady === !0, s, n) ? {
1077
1165
  hint: "Move closer",
1078
1166
  reason: "move-closer",
1079
1167
  fillRatio: o,
@@ -1087,7 +1175,7 @@ function Je(e, t, n = {}) {
1087
1175
  readyForAutoCapture: t.ready
1088
1176
  };
1089
1177
  }
1090
- var $ = class {
1178
+ var Ze = class {
1091
1179
  previous;
1092
1180
  count = 0;
1093
1181
  ready = !1;
@@ -1104,8 +1192,8 @@ var $ = class {
1104
1192
  ready: !1,
1105
1193
  movement: Infinity
1106
1194
  };
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];
1195
+ let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...Z(e.quad).map((e, n) => {
1196
+ let r = Z(this.previous)[n];
1109
1197
  return Math.hypot(e.x - r.x, e.y - r.y) / Math.max(1, t);
1110
1198
  })) : Infinity, r = this.options.exitCornerTolerance ?? Math.max(this.options.cornerTolerance, .036);
1111
1199
  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, {
@@ -1115,14 +1203,14 @@ var $ = class {
1115
1203
  };
1116
1204
  }
1117
1205
  };
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;
1206
+ function Qe(e, n) {
1207
+ let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
1208
+ i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
1121
1209
  let a = i.getContext("2d");
1122
1210
  if (!a) throw t();
1123
1211
  return a.drawImage(e, 0, 0, i.width, i.height), i;
1124
1212
  }
1125
- function Xe() {
1213
+ function $e() {
1126
1214
  let e = window.AudioContext ?? window.webkitAudioContext;
1127
1215
  if (!e) return;
1128
1216
  let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
@@ -1133,29 +1221,29 @@ function Xe() {
1133
1221
  let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
1134
1222
  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();
1135
1223
  }
1136
- async function Ze(e) {
1224
+ async function et(e) {
1137
1225
  let t = document.createElement("video");
1138
1226
  return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
1139
1227
  }
1140
- async function Qe(t) {
1228
+ async function tt(t) {
1141
1229
  await x("scan");
1142
- let n = He(t.autoCapture), r = new $({
1230
+ let n = Ge(t.autoCapture), r = new Ze({
1143
1231
  stableFrames: t.stableFrames ?? 4,
1144
1232
  confidenceThreshold: t.confidenceThreshold ?? .72,
1145
1233
  cornerTolerance: t.cornerTolerance ?? .024,
1146
1234
  exitCornerTolerance: t.exitCornerTolerance ?? .036
1147
- }), i = t.maxFrameDimension ?? We(), a = t.intervalMs ?? 140, o = {
1235
+ }), i = t.maxFrameDimension ?? 1600, a = t.intervalMs ?? 140, o = {
1148
1236
  minDimension: 220,
1149
- maxAnalysisDimension: i,
1237
+ maxAnalysisDimension: 520,
1150
1238
  ...t.detection
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 = {
1239
+ }, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await et(t.source) : t.source, c = !0, l = !1, u = !1, d = 0, f, p = "", m = 0, h = {
1152
1240
  state: "detecting",
1153
1241
  confidence: 0,
1154
1242
  guidance: {
1155
1243
  hint: "Place the document in the frame",
1156
1244
  reason: "place-document",
1157
1245
  fillRatio: 0,
1158
- fill: Q,
1246
+ fill: $,
1159
1247
  readyForAutoCapture: !1
1160
1248
  },
1161
1249
  lighting: {
@@ -1165,20 +1253,29 @@ async function Qe(t) {
1165
1253
  stableFrames: 0,
1166
1254
  requiredStableFrames: t.stableFrames ?? 4,
1167
1255
  autoCapture: { ...n }
1168
- }, m = () => s instanceof HTMLCanvasElement ? Ye(s, i) : Y(s, i), h = (e) => {
1169
- p = e, t.onStatus?.(e);
1170
- }, g = () => {
1256
+ }, g = () => s instanceof HTMLCanvasElement ? Qe(s, i) : q(s, i), _ = (e) => {
1257
+ h = e, t.onStatus?.(e);
1258
+ }, v = (e) => {
1259
+ let t = Ke(e, s instanceof HTMLVideoElement ? {
1260
+ width: s.videoWidth,
1261
+ height: s.videoHeight
1262
+ } : {
1263
+ width: s.width,
1264
+ height: s.height
1265
+ }), n = performance.now();
1266
+ t.key === p && n - m < 2e3 || (p = t.key, m = n, console[t.level](`[exige-scanner] ${t.summary}`, t.detail));
1267
+ }, y = () => {
1171
1268
  c = !1, window.clearTimeout(d), s instanceof HTMLVideoElement && s !== t.source && (s.srcObject = null);
1172
- }, _ = async (e = "manual") => {
1269
+ }, b = async (e = "manual") => {
1173
1270
  if (l) throw Error("A finder capture is already in progress.");
1174
1271
  l = !0;
1175
1272
  let n;
1176
1273
  try {
1177
- n = await Ve(t.captureFrame ?? m, () => {
1178
- h({
1179
- ...p,
1274
+ n = await We(t.captureFrame ?? g, () => {
1275
+ _({
1276
+ ...h,
1180
1277
  state: "captured"
1181
- }), t.playShutterSound !== !1 && Xe(), g();
1278
+ }), t.playShutterSound !== !1 && $e(), y();
1182
1279
  });
1183
1280
  } catch (e) {
1184
1281
  throw l = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
@@ -1189,12 +1286,12 @@ async function Qe(t) {
1189
1286
  reason: e
1190
1287
  };
1191
1288
  return await t.onCapture?.(r), r;
1192
- }, v = async () => {
1289
+ }, S = async () => {
1193
1290
  if (c && !l) {
1194
1291
  try {
1195
- let e = m(), i = await B(e, o);
1196
- f = i;
1197
- let a = i.quad ? ze(e, i.quad) : {
1292
+ let e = g(), i = await Se(e, o);
1293
+ f = i, v(i);
1294
+ let a = i.quad ? He(e, i.quad) : {
1198
1295
  strong: !1,
1199
1296
  strength: 0
1200
1297
  }, s = a.strong ? {
@@ -1204,7 +1301,7 @@ async function Qe(t) {
1204
1301
  } : {
1205
1302
  castShadow: !1,
1206
1303
  strength: a.strength
1207
- }, c = r.update(i), l = Je(i, {
1304
+ }, c = r.update(i), l = Xe(i, {
1208
1305
  ...c,
1209
1306
  previouslyReady: u
1210
1307
  }, {
@@ -1213,14 +1310,14 @@ async function Qe(t) {
1213
1310
  });
1214
1311
  u = l.readyForAutoCapture;
1215
1312
  let d = i.status !== "success" || l.reason === "place-document" ? "seeking" : l.readyForAutoCapture ? "ready" : "unstable";
1216
- if (h({
1313
+ if (_({
1217
1314
  state: d,
1218
1315
  confidence: i.confidence,
1219
1316
  quad: i.quad,
1220
1317
  guidance: l,
1221
1318
  lighting: s,
1222
1319
  stableFrames: c.stableFrames,
1223
- requiredStableFrames: p.requiredStableFrames,
1320
+ requiredStableFrames: h.requiredStableFrames,
1224
1321
  autoCapture: { ...n },
1225
1322
  sourceWidth: i.sourceWidth,
1226
1323
  sourceHeight: i.sourceHeight,
@@ -1228,9 +1325,10 @@ async function Qe(t) {
1228
1325
  modelStatus: i.modelStatus,
1229
1326
  modelProvider: i.modelProvider,
1230
1327
  modelError: i.modelError,
1328
+ modelNote: i.modelNote,
1231
1329
  inferenceMs: i.inferenceMs
1232
1330
  }), l.readyForAutoCapture && n.checked) try {
1233
- await _("auto");
1331
+ await b("auto");
1234
1332
  return;
1235
1333
  } catch (e) {
1236
1334
  r.reset(), u = !1, t.onCaptureError?.(e instanceof Error ? e : /* @__PURE__ */ Error("Automatic capture failed."));
@@ -1241,15 +1339,22 @@ async function Qe(t) {
1241
1339
  detector: "ml",
1242
1340
  modelStatus: "failed",
1243
1341
  modelError: t.message
1244
- } : {};
1245
- h({
1342
+ } : { modelError: t instanceof Error ? t.message : "Finder tick failed." };
1343
+ v({
1344
+ status: "no-document",
1345
+ confidence: 0,
1346
+ message: i.modelError ?? "Finder tick failed.",
1347
+ sourceWidth: 0,
1348
+ sourceHeight: 0,
1349
+ ...i
1350
+ }), _({
1246
1351
  state: "seeking",
1247
1352
  confidence: 0,
1248
1353
  guidance: {
1249
1354
  hint: "Place the document in the frame",
1250
1355
  reason: "place-document",
1251
1356
  fillRatio: 0,
1252
- fill: Q,
1357
+ fill: $,
1253
1358
  readyForAutoCapture: !1
1254
1359
  },
1255
1360
  lighting: {
@@ -1257,27 +1362,27 @@ async function Qe(t) {
1257
1362
  strength: 0
1258
1363
  },
1259
1364
  stableFrames: 0,
1260
- requiredStableFrames: p.requiredStableFrames,
1365
+ requiredStableFrames: h.requiredStableFrames,
1261
1366
  autoCapture: { ...n },
1262
1367
  ...i
1263
1368
  });
1264
1369
  }
1265
- c && (d = window.setTimeout(() => void v(), a));
1370
+ c && (d = window.setTimeout(() => void S(), a));
1266
1371
  }
1267
1372
  };
1268
- return t.onStatus?.(p), v(), {
1269
- stop: g,
1270
- capture: () => _("manual"),
1373
+ return t.onStatus?.(h), S(), {
1374
+ stop: y,
1375
+ capture: () => b("manual"),
1271
1376
  setAutoCapture(e) {
1272
- return !n.mutable || l ? !1 : (n.checked = e, h({
1273
- ...p,
1377
+ return !n.mutable || l ? !1 : (n.checked = e, _({
1378
+ ...h,
1274
1379
  autoCapture: { ...n }
1275
1380
  }), !0);
1276
1381
  },
1277
- getStatus: () => p
1382
+ getStatus: () => h
1278
1383
  };
1279
1384
  }
1280
1385
  //#endregion
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 };
1386
+ export { ne as A, Se as C, ue as D, le as E, y as F, e as I, t as L, o as M, x as N, M as O, b as P, Ce as S, we as T, U as _, Xe as a, H as b, Be as c, V as d, ke as f, Ae as g, Te as h, Je as i, a as j, ie as k, J as l, B as m, Ge as n, Ue as o, q as p, Ye as r, tt as s, Ze as t, ze as u, K as v, N as w, de as x, Le as y };
1282
1387
 
1283
- //# sourceMappingURL=finder-Bjo3TAHi.js.map
1388
+ //# sourceMappingURL=finder-kHZVA7ug.js.map