@exige/web-scanner-sdk 0.2.37 → 0.2.39

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.
@@ -207,13 +207,13 @@ function ie(e) {
207
207
  T.delete(e);
208
208
  };
209
209
  }
210
- function ae(e, t) {
210
+ function D(e, t) {
211
211
  t.done ? w.delete(e) : w.set(e, {
212
212
  loaded: t.loaded,
213
213
  total: t.total
214
214
  }), re();
215
215
  }
216
- async function oe(e, t) {
216
+ async function ae(e, t) {
217
217
  let n = te(e);
218
218
  if (!e.body) {
219
219
  let r = await e.arrayBuffer();
@@ -238,19 +238,19 @@ async function oe(e, t) {
238
238
  total: n
239
239
  }), o.buffer;
240
240
  }
241
- async function se(t, n) {
241
+ async function oe(t, n) {
242
242
  let r = ee.get(t);
243
243
  if (r) return r.slice(0);
244
244
  let i = E.get(t);
245
245
  if (i) return i.then((e) => e.slice(0));
246
246
  let a = (async () => {
247
- ae(t, {
247
+ D(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 oe(r, (e) => ae(t, e));
253
+ return ae(r, (e) => D(t, e));
254
254
  })();
255
255
  E.set(t, a);
256
256
  try {
@@ -262,7 +262,7 @@ async function se(t, n) {
262
262
  }
263
263
  //#endregion
264
264
  //#region src/sdk/camera.ts
265
- function ce(e, t) {
265
+ function se(e, t) {
266
266
  let { engine: n } = t;
267
267
  return [
268
268
  `${e}:`,
@@ -277,9 +277,9 @@ function ce(e, t) {
277
277
  ` torch: ${t.torch.mode} supported=${t.torch.supported} on=${t.torch.on}`
278
278
  ].join("\n");
279
279
  }
280
- function le(e) {
280
+ function ce(e) {
281
281
  let t = ["Exige scanner capture report", `time: ${e.capturedAt ?? (/* @__PURE__ */ new Date()).toISOString()}`];
282
- 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(ce("shutter", e.shutter)), e.live && t.push(ce("live", e.live)), e.finder) {
282
+ 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(se("shutter", e.shutter)), e.live && t.push(se("live", e.live)), e.finder) {
283
283
  let n = e.finder;
284
284
  t.push([
285
285
  "finder:",
@@ -296,7 +296,7 @@ function le(e) {
296
296
  }
297
297
  return `${t.join("\n")}\n`;
298
298
  }
299
- function D(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
299
+ function O(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
300
300
  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;
301
301
  return {
302
302
  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",
@@ -305,40 +305,40 @@ function D(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof nav
305
305
  userAgent: e
306
306
  };
307
307
  }
308
- function ue(e) {
308
+ function le(e) {
309
309
  return /Android/i.test(e.userAgent) && !e.iosWebKit;
310
310
  }
311
- function de(e = D()) {
312
- return e.engine === "webkit" && !ue(e);
311
+ function ue(e = O()) {
312
+ return e.engine === "webkit" && !le(e);
313
313
  }
314
- function fe(e = "auto", t = D()) {
315
- return e === "system-camera" || e !== "live" && ue(t);
314
+ function de(e = "auto", t = O()) {
315
+ return e === "system-camera" || e !== "live" && le(t);
316
316
  }
317
- function pe(e, t) {
317
+ function fe(e, t) {
318
318
  return t && !e.iosWebKit;
319
319
  }
320
- function me(e, t) {
320
+ function pe(e, t) {
321
321
  if (!e || !Number.isFinite(e)) return;
322
322
  let n = t?.max;
323
323
  if (!n || !Number.isFinite(n)) return Math.round(e);
324
324
  let r = t?.min && Number.isFinite(t.min) ? t.min : 1, i = t?.step && t.step > 0 ? t.step : 1, a = r + Math.round((Math.min(n, Math.max(r, e)) - r) / i) * i;
325
325
  return Math.round(Math.min(n, Math.max(r, a)));
326
326
  }
327
- function he(e) {
328
- let t = me(e?.imageWidth?.max ?? 0, e?.imageWidth), n = me(e?.imageHeight?.max ?? 0, e?.imageHeight);
327
+ function me(e) {
328
+ let t = pe(e?.imageWidth?.max ?? 0, e?.imageWidth), n = pe(e?.imageHeight?.max ?? 0, e?.imageHeight);
329
329
  if (t && n) return t >= n ? { imageWidth: t } : { imageHeight: n };
330
330
  if (t) return { imageWidth: t };
331
331
  if (n) return { imageHeight: n };
332
332
  }
333
- function ge(e, t) {
333
+ function he(e, t) {
334
334
  return !e.width || !e.height || !t.width || !t.height ? !1 : e.width * e.height > t.width * t.height * 1.15;
335
335
  }
336
- function _e(e, t) {
336
+ function ge(e, t) {
337
337
  if (!e.width || !e.height || !t.width || !t.height) return !1;
338
338
  let n = e.width / e.height / (t.width / t.height);
339
339
  return n > .97 && n < 1.03;
340
340
  }
341
- var ve = 10, ye = class {
341
+ var _e = 10, ve = class {
342
342
  on = !1;
343
343
  darkCount = 0;
344
344
  brightCount = 0;
@@ -361,7 +361,7 @@ var ve = 10, ye = class {
361
361
  return this.on;
362
362
  }
363
363
  };
364
- function be(e, t) {
364
+ function ye(e, t) {
365
365
  return t ? e === "alwaysOn" || e === "alwaysOff" ? {
366
366
  mode: e,
367
367
  supported: !0,
@@ -385,7 +385,7 @@ function be(e, t) {
385
385
  automatic: e === "auto"
386
386
  };
387
387
  }
388
- function O(e) {
388
+ function be(e) {
389
389
  let t = Math.floor(e.length / 4);
390
390
  if (!t) return 0;
391
391
  let n = 0;
@@ -393,32 +393,32 @@ function O(e) {
393
393
  return n / t;
394
394
  }
395
395
  function k(e) {
396
- return !e.width || !e.height || Se(e, e.width, e.height) <= 10;
396
+ return !e.width || !e.height || A(e, e.width, e.height) <= 10;
397
397
  }
398
398
  function xe(e, t = 10) {
399
399
  if (e.length < 4) return !0;
400
400
  let n = Math.floor(e.length / 4), r = 0;
401
401
  for (let i = 0; i < n * 4; i += 4) e[i] * .299 + e[i + 1] * .587 + e[i + 2] * .114 > t * 2 && (r += 1);
402
- return O(e) <= t && r / n < .01;
402
+ return be(e) <= t && r / n < .01;
403
403
  }
404
- function Se(e, t, n) {
404
+ function A(e, t, n) {
405
405
  if (!t || !n) return 0;
406
406
  let r = document.createElement("canvas");
407
407
  r.width = Math.min(32, t), r.height = Math.min(32, n);
408
408
  let i = r.getContext("2d", { willReadFrequently: !0 });
409
- return i ? (i.drawImage(e, 0, 0, r.width, r.height), O(i.getImageData(0, 0, r.width, r.height).data)) : 0;
409
+ return i ? (i.drawImage(e, 0, 0, r.width, r.height), be(i.getImageData(0, 0, r.width, r.height).data)) : 0;
410
410
  }
411
- function Ce(e) {
412
- return Se(e, e.width, e.height);
411
+ function Se(e) {
412
+ return A(e, e.width, e.height);
413
413
  }
414
- function we(e, t = 120) {
414
+ function Ce(e, t = 120) {
415
415
  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 = () => {
416
416
  a && (o = i ? e.requestVideoFrameCallback(f) : requestAnimationFrame(f));
417
417
  };
418
418
  function f() {
419
419
  if (!a) return;
420
420
  let { videoWidth: i, videoHeight: o } = e, f = performance.now();
421
- r && i && o && f - s >= t && (s = f, l = Se(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();
421
+ r && i && o && f - s >= t && (s = f, l = A(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();
422
422
  }
423
423
  return d(), {
424
424
  stop() {
@@ -430,34 +430,34 @@ function we(e, t = 120) {
430
430
  getMirrorAgeMs: () => c ? performance.now() - c : Infinity
431
431
  };
432
432
  }
433
- function Te(e) {
433
+ function we(e) {
434
434
  let t = document.createElement("canvas");
435
435
  return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
436
436
  }
437
- function Ee(e, n) {
438
- let r = j(e.width, e.height, n);
439
- if (r.width === e.width && r.height === e.height) return Te(e);
437
+ function Te(e, n) {
438
+ let r = M(e.width, e.height, n);
439
+ if (r.width === e.width && r.height === e.height) return we(e);
440
440
  let i = document.createElement("canvas");
441
441
  i.width = r.width, i.height = r.height;
442
442
  let a = i.getContext("2d");
443
443
  if (!a) throw t();
444
444
  return a.imageSmoothingEnabled = !0, "imageSmoothingQuality" in a && (a.imageSmoothingQuality = "high"), a.drawImage(e, 0, 0, i.width, i.height), i;
445
445
  }
446
- function De(e, t, n) {
446
+ function Ee(e, t, n) {
447
447
  try {
448
- let t = M(e, n);
448
+ let t = N(e, n);
449
449
  if (!k(t)) return t;
450
450
  } catch {}
451
451
  let r = t.getFrame();
452
452
  if (!r) throw Error("The camera is not ready to capture a frame.");
453
- let i = Ee(r, n);
453
+ let i = Te(r, n);
454
454
  if (k(i)) throw Error("The camera preview produced no visible pixels.");
455
455
  return i;
456
456
  }
457
- function Oe(e) {
457
+ function De(e) {
458
458
  return e.engine === "blink";
459
459
  }
460
- function A(e = {}, t = D()) {
460
+ function j(e = {}, t = O()) {
461
461
  let n = { ideal: e.idealWidth ?? 3840 }, r = { ideal: e.idealHeight ?? 2160 };
462
462
  e.maxWidth && (n.max = e.maxWidth), e.maxHeight && (r.max = e.maxHeight);
463
463
  let i = {
@@ -469,20 +469,20 @@ function A(e = {}, t = D()) {
469
469
  max: e.maxFrameRate ?? 30
470
470
  }
471
471
  };
472
- return Oe(t) && (i.resizeMode = { ideal: "none" }), {
472
+ return De(t) && (i.resizeMode = { ideal: "none" }), {
473
473
  audio: !1,
474
474
  video: i
475
475
  };
476
476
  }
477
- function j(e, t, n) {
477
+ function M(e, t, n) {
478
478
  let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
479
479
  return {
480
480
  width: Math.max(1, Math.round(e * r)),
481
481
  height: Math.max(1, Math.round(t * r))
482
482
  };
483
483
  }
484
- var ke = 4096;
485
- function Ae(e, t) {
484
+ var Oe = 4096;
485
+ function ke(e, t) {
486
486
  let n = e.width, r = e.height, i = t?.width?.max, a = t?.height?.max;
487
487
  if (!n || !r || !i || !a) return;
488
488
  let o = Math.min(i / n, a / r);
@@ -491,13 +491,13 @@ function Ae(e, t) {
491
491
  height: { ideal: Math.round(r * o) }
492
492
  };
493
493
  }
494
- async function je(e) {
495
- let t = Ae(e.getSettings(), typeof e.getCapabilities == "function" ? e.getCapabilities() : void 0);
494
+ async function Ae(e) {
495
+ let t = ke(e.getSettings(), typeof e.getCapabilities == "function" ? e.getCapabilities() : void 0);
496
496
  if (t) try {
497
497
  await e.applyConstraints(t);
498
498
  } catch {}
499
499
  }
500
- async function Me(e) {
500
+ async function je(e) {
501
501
  try {
502
502
  return await createImageBitmap(e, {
503
503
  imageOrientation: "from-image",
@@ -507,7 +507,7 @@ async function Me(e) {
507
507
  return await createImageBitmap(e);
508
508
  }
509
509
  }
510
- async function Ne(e) {
510
+ async function Me(e) {
511
511
  try {
512
512
  await e.applyConstraints({ advanced: [{ pointsOfInterest: [{
513
513
  x: .5,
@@ -515,25 +515,25 @@ async function Ne(e) {
515
515
  }] }] }), await new Promise((e) => window.setTimeout(e, 180));
516
516
  } catch {}
517
517
  }
518
- async function Pe(e) {
519
- let n = await Me(e), r = j(n.width, n.height, ke), i = document.createElement("canvas");
518
+ async function Ne(e) {
519
+ let n = await je(e), r = M(n.width, n.height, Oe), i = document.createElement("canvas");
520
520
  i.width = r.width, i.height = r.height;
521
521
  let a = i.getContext("2d");
522
522
  if (!a) throw n.close?.(), t();
523
523
  return a.imageSmoothingEnabled = r.width !== n.width || r.height !== n.height, a.imageSmoothingQuality = "high", a.drawImage(n, 0, 0, i.width, i.height), n.close?.(), i;
524
524
  }
525
- async function Fe(e) {
525
+ async function Pe(e) {
526
526
  let t = globalThis.ImageCapture;
527
527
  if (!t) return;
528
- await Ne(e);
529
- let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i = he(r), a;
528
+ await Me(e);
529
+ let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i = me(r), a;
530
530
  try {
531
531
  a = await n.takePhoto(i);
532
532
  } catch {
533
533
  a = await n.takePhoto();
534
534
  }
535
535
  return {
536
- frame: await Pe(a),
536
+ frame: await Ne(a),
537
537
  requested: i,
538
538
  photoMax: {
539
539
  width: r?.imageWidth?.max,
@@ -541,42 +541,42 @@ async function Fe(e) {
541
541
  }
542
542
  };
543
543
  }
544
- function M(e, n) {
544
+ function N(e, n) {
545
545
  if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
546
- let r = j(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
546
+ let r = M(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
547
547
  i.width = r.width, i.height = r.height;
548
548
  let a = i.getContext("2d");
549
549
  if (!a) throw t();
550
550
  return a.drawImage(e, 0, 0, i.width, i.height), i;
551
551
  }
552
- function Ie(e) {
553
- let t = D();
554
- return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [A(e, t)] : [
555
- A({
552
+ function Fe(e) {
553
+ let t = O();
554
+ return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [j(e, t)] : [
555
+ j({
556
556
  ...e,
557
557
  idealWidth: 3840,
558
558
  idealHeight: 2160
559
559
  }, t),
560
- A({
560
+ j({
561
561
  ...e,
562
562
  idealWidth: 2560,
563
563
  idealHeight: 1440
564
564
  }, t),
565
- A({
565
+ j({
566
566
  ...e,
567
567
  idealWidth: 1920,
568
568
  idealHeight: 1080
569
569
  }, t)
570
570
  ];
571
571
  }
572
- async function Le(t, n = {}) {
572
+ async function Ie(t, n = {}) {
573
573
  await x("scan");
574
574
  let r = n.torch ?? "alwaysOff";
575
575
  if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
576
576
  if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
577
577
  t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
578
578
  let i, a;
579
- for (let e of Ie(n)) try {
579
+ for (let e of Fe(n)) try {
580
580
  i = await navigator.mediaDevices.getUserMedia(e);
581
581
  break;
582
582
  } catch (e) {
@@ -589,8 +589,8 @@ async function Le(t, n = {}) {
589
589
  for (let e of i.getTracks()) e.stop();
590
590
  throw Error("The camera did not provide a video track.");
591
591
  }
592
- await je(o);
593
- let s = we(t), c = "ImageCapture" in globalThis, l = be(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
592
+ await Ae(o);
593
+ let s = Ce(t), c = "ImageCapture" in globalThis, l = ye(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
594
594
  if (!l.supported || o.readyState !== "live") return !1;
595
595
  try {
596
596
  return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
@@ -608,7 +608,7 @@ async function Le(t, n = {}) {
608
608
  }
609
609
  };
610
610
  l.on && await d(!0);
611
- let f = r === "auto" && l.supported ? new ye() : void 0, p = f ? window.setInterval(() => {
611
+ let f = r === "auto" && l.supported ? new ve() : void 0, p = f ? window.setInterval(() => {
612
612
  if (u || !l.supported) return;
613
613
  let e = f.update(s.getLiveLuminance());
614
614
  e !== void 0 && e !== l.on && (u = !0, d(e).finally(() => {
@@ -634,7 +634,7 @@ async function Le(t, n = {}) {
634
634
  torchSupported: l.supported,
635
635
  torchOn: l.on,
636
636
  torch: { ...l },
637
- engine: D()
637
+ engine: O()
638
638
  };
639
639
  };
640
640
  return {
@@ -648,20 +648,20 @@ async function Le(t, n = {}) {
648
648
  get torchOn() {
649
649
  return l.on;
650
650
  },
651
- capture: (e) => De(t, s, e),
651
+ capture: (e) => Ee(t, s, e),
652
652
  async captureLiveFrame(e) {
653
653
  let n = globalThis.ImageCapture;
654
654
  if (n) try {
655
655
  let t = await new n(o).grabFrame?.();
656
656
  if (t) {
657
- let n = j(t.width, t.height, e), r = document.createElement("canvas");
657
+ let n = M(t.width, t.height, e), r = document.createElement("canvas");
658
658
  r.width = n.width, r.height = n.height;
659
659
  let i = r.getContext("2d");
660
660
  if (i && (i.imageSmoothingEnabled = !0, "imageSmoothingQuality" in i && (i.imageSmoothingQuality = "high"), i.drawImage(t, 0, 0, r.width, r.height)), t.close?.(), r.width && !k(r)) return r;
661
661
  }
662
662
  } catch {}
663
663
  try {
664
- return De(t, s, e);
664
+ return Ee(t, s, e);
665
665
  } catch {
666
666
  return;
667
667
  }
@@ -669,13 +669,13 @@ async function Le(t, n = {}) {
669
669
  async capturePhoto() {
670
670
  let e, n = 0;
671
671
  try {
672
- e = M(t), n = Ce(e);
672
+ e = N(t), n = Se(e);
673
673
  } catch {
674
674
  e = void 0;
675
675
  }
676
676
  let r = s.getFrame(), i, a = !1, l = !1, u, d;
677
- if (pe(D(), c)) try {
678
- let e = await Fe(o);
677
+ if (fe(O(), c)) try {
678
+ let e = await Pe(o);
679
679
  i = e?.frame, u = e?.requested, d = e?.photoMax;
680
680
  } catch {
681
681
  a = !0, i = void 0;
@@ -683,14 +683,14 @@ async function Le(t, n = {}) {
683
683
  let f = {
684
684
  width: t.videoWidth,
685
685
  height: t.videoHeight
686
- }, p = i ? Ce(i) : 0, h = !!(i && p > 10 && ge(i, f));
686
+ }, p = i ? Se(i) : 0, h = !!(i && p > 10 && he(i, f));
687
687
  if (i && p > 10 && !h && (l = !0), h && i) return console.info("[exige-scanner] capture", {
688
688
  method: "image-capture",
689
689
  frame: `${i.width}×${i.height}`,
690
690
  video: `${t.videoWidth}×${t.videoHeight}`,
691
691
  photoMax: d ? `${d.width ?? "—"}×${d.height ?? "—"}` : void 0,
692
692
  photoRequest: u,
693
- aspectMatch: _e(i, f)
693
+ aspectMatch: ge(i, f)
694
694
  }), {
695
695
  frame: i,
696
696
  method: "image-capture",
@@ -698,7 +698,7 @@ async function Le(t, n = {}) {
698
698
  luminance: p,
699
699
  diagnostics: m()
700
700
  };
701
- let g = e && n > 10 ? e : void 0, _ = g ?? (r ? Te(r) : void 0);
701
+ let g = e && n > 10 ? e : void 0, _ = g ?? (r ? we(r) : void 0);
702
702
  if (!_) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
703
703
  let v = l ? "image-capture-preview-size" : i ? "image-capture-empty" : a ? "image-capture-failed" : g ? void 0 : "video-frame-empty";
704
704
  return console.info("[exige-scanner] capture", {
@@ -730,13 +730,13 @@ async function Le(t, n = {}) {
730
730
  }
731
731
  };
732
732
  }
733
- function Re() {
733
+ function Le() {
734
734
  let e = typeof navigator > "u" ? void 0 : navigator.userActivation;
735
735
  return !e || e.isActive;
736
736
  }
737
- async function ze() {
737
+ async function Re() {
738
738
  let e = document.createElement("input");
739
- return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"), Pe(await new Promise((t, n) => {
739
+ return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"), Ne(await new Promise((t, n) => {
740
740
  e.addEventListener("change", () => {
741
741
  let r = e.files?.[0];
742
742
  r ? t(r) : n(/* @__PURE__ */ Error("No photo was selected."));
@@ -747,20 +747,20 @@ async function ze() {
747
747
  }
748
748
  //#endregion
749
749
  //#region src/sdk/ort-cdn.ts
750
- var Be = "1.30.0";
751
- `${Be}`, `${Be}`;
752
- function Ve(e) {
750
+ var ze = "1.30.0";
751
+ `${ze}`, `${ze}`;
752
+ function Be(e) {
753
753
  return !e.ok && e.status !== 206 ? !1 : !(e.headers.get("content-type") ?? "").toLowerCase().includes("text/html");
754
754
  }
755
- async function He(e, t = fetch) {
755
+ async function Ve(e, t = fetch) {
756
756
  if (!e) return !1;
757
757
  try {
758
758
  let n = await t(e, { method: "HEAD" });
759
- if (Ve(n)) return !0;
759
+ if (Be(n)) return !0;
760
760
  if (n.status === 404 || n.status === 410) return !1;
761
761
  } catch {}
762
762
  try {
763
- return Ve(await t(e, {
763
+ return Be(await t(e, {
764
764
  method: "GET",
765
765
  headers: { Range: "bytes=0-63" }
766
766
  }));
@@ -770,29 +770,29 @@ async function He(e, t = fetch) {
770
770
  }
771
771
  //#endregion
772
772
  //#region src/sdk/ort-runtime.ts
773
- var Ue = new URL("./assets/ort-wasm-simd-threaded.jsep.wasm", import.meta.url), We = new URL("./assets/ort-wasm-simd-threaded.jsep.mjs", import.meta.url);
774
- function Ge() {
773
+ var He = new URL("./assets/ort-wasm-simd-threaded.jsep.wasm", import.meta.url), Ue = new URL("./assets/ort-wasm-simd-threaded.jsep.mjs", import.meta.url);
774
+ function We() {
775
775
  return {
776
- wasm: Ue.href,
777
- mjs: We.href
776
+ wasm: He.href,
777
+ mjs: Ue.href
778
778
  };
779
779
  }
780
- function Ke(e) {
781
- return typeof e == "string" ? e.trim() || Ge() : e?.wasm.trim() && e.mjs.trim() ? {
780
+ function Ge(e) {
781
+ return typeof e == "string" ? e.trim() || We() : e?.wasm.trim() && e.mjs.trim() ? {
782
782
  wasm: e.wasm.trim(),
783
783
  mjs: e.mjs.trim()
784
- } : Ge();
784
+ } : We();
785
785
  }
786
786
  //#endregion
787
787
  //#region src/sdk/image.ts
788
- function qe(e, t, n) {
788
+ function Ke(e, t, n) {
789
789
  let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
790
790
  return {
791
791
  width: Math.max(1, Math.round(e * r)),
792
792
  height: Math.max(1, Math.round(t * r))
793
793
  };
794
794
  }
795
- async function Je(e) {
795
+ async function qe(e) {
796
796
  let t = URL.createObjectURL(e);
797
797
  try {
798
798
  let e = new Image();
@@ -801,26 +801,26 @@ async function Je(e) {
801
801
  URL.revokeObjectURL(t);
802
802
  }
803
803
  }
804
- async function N(e, n = {}) {
804
+ async function P(e, n = {}) {
805
805
  if (e instanceof HTMLCanvasElement && n.cloneCanvas === !1 && !n.maxDimension) return e;
806
806
  let r = document.createElement("canvas"), i = r.getContext("2d", { willReadFrequently: !0 });
807
807
  if (!i) throw t();
808
808
  if (e instanceof Blob) {
809
809
  if ("createImageBitmap" in window) try {
810
- let t = await createImageBitmap(e), a = qe(t.width, t.height, n.maxDimension);
810
+ let t = await createImageBitmap(e), a = Ke(t.width, t.height, n.maxDimension);
811
811
  return r.width = a.width, r.height = a.height, i.drawImage(t, 0, 0, a.width, a.height), t.close(), r;
812
812
  } catch {}
813
- e = await Je(e);
813
+ e = await qe(e);
814
814
  }
815
815
  let a = e instanceof HTMLImageElement ? e.naturalWidth : e.width, o = e instanceof HTMLImageElement ? e.naturalHeight : e.height;
816
816
  if (!a || !o) throw Error("The image has no readable dimensions.");
817
- let s = qe(a, o, n.maxDimension);
817
+ let s = Ke(a, o, n.maxDimension);
818
818
  return r.width = s.width, r.height = s.height, i.drawImage(e, 0, 0, s.width, s.height), r;
819
819
  }
820
- function Ye(e, t = "image/png", n = .92) {
820
+ function Je(e, t = "image/png", n = .92) {
821
821
  return new Promise((r, i) => e.toBlob((e) => e ? r(e) : i(/* @__PURE__ */ Error("Could not encode the image.")), t, n));
822
822
  }
823
- function Xe(e, t, n) {
823
+ function Ye(e, t, n) {
824
824
  let r = Math.max(0, Math.min(t, e.x)), i = Math.max(0, Math.min(n, e.y));
825
825
  return {
826
826
  x: r,
@@ -831,20 +831,20 @@ function Xe(e, t, n) {
831
831
  }
832
832
  //#endregion
833
833
  //#region src/sdk/scan.ts
834
- var Ze = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", Qe = 1280;
835
- function $e(e, t, n) {
834
+ var Xe = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", Ze = 1280;
835
+ function Qe(e, t, n) {
836
836
  if (n) return n;
837
- let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a = at() ? 560 : 900;
838
- return i >= 1.6 ? Math.min(r, Math.max(a, Qe)) : a;
837
+ let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a = it() ? 560 : 900;
838
+ return i >= 1.6 ? Math.min(r, Math.max(a, Ze)) : a;
839
839
  }
840
- function et(e) {
840
+ function $e(e) {
841
841
  return e?.trim() || "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
842
842
  }
843
- var tt = 3, P, nt = 0, F = /* @__PURE__ */ new Map();
844
- function I(e, t) {
843
+ var et = 3, F, tt = 0, I = /* @__PURE__ */ new Map();
844
+ function L(e, t) {
845
845
  return Math.hypot(e.x - t.x, e.y - t.y);
846
846
  }
847
- function rt(e) {
847
+ function nt(e) {
848
848
  return {
849
849
  ...e,
850
850
  edges: {
@@ -867,7 +867,7 @@ function rt(e) {
867
867
  }
868
868
  };
869
869
  }
870
- function it(e, t) {
870
+ function rt(e, t) {
871
871
  let n = (e) => ({
872
872
  x: e.x / t,
873
873
  y: e.y / t
@@ -879,43 +879,43 @@ function it(e, t) {
879
879
  bottomLeft: n(e.bottomLeft)
880
880
  };
881
881
  }
882
- function at() {
882
+ function it() {
883
883
  return typeof navigator > "u" ? !1 : navigator.maxTouchPoints > 0 || navigator.hardwareConcurrency <= 4 || typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
884
884
  }
885
- function ot(t, n, r, i) {
885
+ function at(t, n, r, i) {
886
886
  return new Promise((a, o) => {
887
- P || (P = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), P.onmessage = (t) => {
887
+ F || (F = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), F.onmessage = (t) => {
888
888
  if (t.data.download?.url) {
889
- ae(t.data.download.url, t.data.download);
889
+ D(t.data.download.url, t.data.download);
890
890
  return;
891
891
  }
892
- let n = F.get(t.data.id);
893
- 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.")));
894
- }, P.onerror = () => {
892
+ let n = I.get(t.data.id);
893
+ n && (I.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.")));
894
+ }, F.onerror = () => {
895
895
  let t = new e("worker", "The document worker could not start.");
896
- for (let e of F.values()) e.reject(t);
897
- F.clear(), P?.terminate(), P = void 0;
896
+ for (let e of I.values()) e.reject(t);
897
+ I.clear(), F?.terminate(), F = void 0;
898
898
  });
899
- let s = ++nt;
900
- F.set(s, {
899
+ let s = ++tt;
900
+ I.set(s, {
901
901
  resolve: a,
902
902
  reject: o
903
903
  });
904
904
  let c = t.slice().buffer;
905
- P.postMessage({
905
+ F.postMessage({
906
906
  id: s,
907
907
  pixels: c,
908
908
  width: n,
909
909
  height: r,
910
- modelUrl: et(i.modelUrl),
910
+ modelUrl: $e(i.modelUrl),
911
911
  heatmapThreshold: i.heatmapThreshold,
912
912
  cacheModel: i.cacheModel,
913
- ortWasmPaths: Ke(i.ortWasmPaths),
914
- preferWebGpu: i.preferWebGpu ?? de()
913
+ ortWasmPaths: Ge(i.ortWasmPaths),
914
+ preferWebGpu: i.preferWebGpu ?? ue()
915
915
  }, [c]);
916
916
  });
917
917
  }
918
- async function st(n, r) {
918
+ async function ot(n, r) {
919
919
  let { width: i, height: a } = n, o = r.minDimension ?? 360;
920
920
  if (Math.min(i, a) < o) return {
921
921
  status: "low-quality",
@@ -924,7 +924,7 @@ async function st(n, r) {
924
924
  sourceWidth: i,
925
925
  sourceHeight: a
926
926
  };
927
- let s = $e(i, a, r.maxAnalysisDimension), c = Math.min(1, s / Math.max(i, a)), l = Math.max(1, Math.round(i * c)), u = Math.max(1, Math.round(a * c)), d;
927
+ let s = Qe(i, a, r.maxAnalysisDimension), c = Math.min(1, s / Math.max(i, a)), l = Math.max(1, Math.round(i * c)), u = Math.max(1, Math.round(a * c)), d;
928
928
  if (c === 1) {
929
929
  let e = n.getContext("2d", { willReadFrequently: !0 });
930
930
  if (!e) throw t();
@@ -938,7 +938,7 @@ async function st(n, r) {
938
938
  }
939
939
  let f;
940
940
  if (r.useWorker !== !1 && typeof Worker < "u") try {
941
- f = await ot(d, l, u, r);
941
+ f = await at(d, l, u, r);
942
942
  } catch (t) {
943
943
  if (t instanceof e && (t.code === "worker" || t.code === "model-http")) throw t;
944
944
  f = {
@@ -962,7 +962,7 @@ async function st(n, r) {
962
962
  modelNote: y,
963
963
  inferenceMs: b
964
964
  };
965
- if (p < tt) return {
965
+ if (p < et) return {
966
966
  status: "low-quality",
967
967
  confidence: Math.min(.3, p / 18),
968
968
  message: "The image is too soft or dark to resolve four document edges.",
@@ -978,7 +978,7 @@ async function st(n, r) {
978
978
  sourceHeight: a,
979
979
  ...x
980
980
  };
981
- let S = it(m.corners, c), C = rt(S), w = r.minConfidence ?? .58;
981
+ let S = rt(m.corners, c), C = nt(S), w = r.minConfidence ?? .58;
982
982
  return m.confidence < w ? {
983
983
  status: "low-confidence",
984
984
  quad: C,
@@ -999,14 +999,14 @@ async function st(n, r) {
999
999
  ...x
1000
1000
  };
1001
1001
  }
1002
- function ct(e, t) {
1003
- 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));
1002
+ function st(e, t) {
1003
+ let n = Math.max(1, Math.round(Math.max(L(e.topLeft, e.topRight), L(e.bottomLeft, e.bottomRight)))), r = Math.max(1, Math.round(Math.max(L(e.topLeft, e.bottomLeft), L(e.topRight, e.bottomRight)))), i = Math.min(1, t / Math.max(n, r));
1004
1004
  return {
1005
1005
  width: Math.max(1, Math.round(n * i)),
1006
1006
  height: Math.max(1, Math.round(r * i))
1007
1007
  };
1008
1008
  }
1009
- function lt(e, t, n, r, i) {
1009
+ function ct(e, t, n, r, i) {
1010
1010
  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) => {
1011
1011
  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;
1012
1012
  return Math.round(n * (1 - f) + r * f);
@@ -1018,8 +1018,8 @@ function lt(e, t, n, r, i) {
1018
1018
  255
1019
1019
  ];
1020
1020
  }
1021
- function ut(e, n, r) {
1022
- let { width: i, height: a } = ct(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
1021
+ function lt(e, n, r) {
1022
+ let { width: i, height: a } = st(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
1023
1023
  if (!o) throw t();
1024
1024
  let s = o.getImageData(0, 0, e.width, e.height), c = document.createElement("canvas");
1025
1025
  c.width = i, c.height = a;
@@ -1029,58 +1029,58 @@ function ut(e, n, r) {
1029
1029
  for (let t = 0; t < a; t += 1) {
1030
1030
  let n = t / Math.max(1, a - 1);
1031
1031
  for (let r = 0; r < i; r += 1) {
1032
- let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = (w * a + T * n + d.x) / o, l = (ee * a + E * n + d.y) / o, [f, p, m, h] = lt(s.data, e.width, e.height, c, l), g = (t * i + r) * 4;
1032
+ let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = (w * a + T * n + d.x) / o, l = (ee * a + E * n + d.y) / o, [f, p, m, h] = ct(s.data, e.width, e.height, c, l), g = (t * i + r) * 4;
1033
1033
  u.data[g] = f, u.data[g + 1] = p, u.data[g + 2] = m, u.data[g + 3] = h;
1034
1034
  }
1035
1035
  }
1036
1036
  return l.putImageData(u, 0, 0), c;
1037
1037
  }
1038
- async function dt(e, t = {}) {
1039
- return await x("scan"), st(await N(e, { cloneCanvas: !1 }), t);
1038
+ async function ut(e, t = {}) {
1039
+ return await x("scan"), ot(await P(e, { cloneCanvas: !1 }), t);
1040
1040
  }
1041
- async function ft(e, t, n = {}) {
1041
+ async function dt(e, t, n = {}) {
1042
1042
  await x("scan");
1043
- let r = await N(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? 4096;
1043
+ let r = await P(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? 4096;
1044
1044
  return {
1045
1045
  status: "success",
1046
1046
  corners: t,
1047
- quad: rt(t),
1047
+ quad: nt(t),
1048
1048
  confidence: 1,
1049
1049
  message: "Captured with the document edges shown in the finder.",
1050
1050
  sourceWidth: r.width,
1051
1051
  sourceHeight: r.height,
1052
- canvas: ut(r, t, i)
1052
+ canvas: lt(r, t, i)
1053
1053
  };
1054
1054
  }
1055
- async function L(e, t = {}) {
1055
+ async function R(e, t = {}) {
1056
1056
  await x("scan");
1057
- let n = await N(e, { cloneCanvas: !1 }), r = await st(n, t);
1057
+ let n = await P(e, { cloneCanvas: !1 }), r = await ot(n, t);
1058
1058
  if (r.status !== "success" || !r.corners) return r;
1059
1059
  let i = t.maxOutputDimension ?? 4096;
1060
1060
  return {
1061
1061
  ...r,
1062
- canvas: ut(n, r.corners, i),
1062
+ canvas: lt(n, r.corners, i),
1063
1063
  message: "Four document edges detected and perspective-corrected."
1064
1064
  };
1065
1065
  }
1066
- function pt(e) {
1066
+ function ft(e) {
1067
1067
  return e.status === "success" ? e.message : e.status === "low-quality" ? e.message.includes("shortest side") ? `${e.message} Take another photo.` : "That photo is too soft or dark to find a document. Take another photo in better light." : e.status === "low-confidence" ? "The page edges were not clear enough to crop. Take another photo with the whole page in frame." : `No document was found in that photo. Take another photo with the whole page in frame.${e.modelStatus === "failed" && e.modelError ? ` (${e.modelError})` : ""}`;
1068
1068
  }
1069
- async function mt(e, t = {}) {
1070
- let n = await L(e, t);
1069
+ async function pt(e, t = {}) {
1070
+ let n = await R(e, t);
1071
1071
  return n.status === "success" ? n : {
1072
1072
  ...n,
1073
- message: pt(n)
1073
+ message: ft(n)
1074
1074
  };
1075
1075
  }
1076
1076
  //#endregion
1077
1077
  //#region src/sdk/lighting.ts
1078
- function ht(e, t) {
1078
+ function mt(e, t) {
1079
1079
  if (!e.length) return 0;
1080
1080
  let n = [...e].sort((e, t) => e - t);
1081
1081
  return n[Math.min(n.length - 1, Math.floor(n.length * t))];
1082
1082
  }
1083
- function gt(e, t, n, r = 12) {
1083
+ function ht(e, t, n, r = 12) {
1084
1084
  if (!t || !n || e.length < t * n) return {
1085
1085
  strong: !1,
1086
1086
  strength: 0,
@@ -1103,7 +1103,7 @@ function gt(e, t, n, r = 12) {
1103
1103
  });
1104
1104
  }
1105
1105
  }
1106
- let s = ht(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
1106
+ let s = mt(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
1107
1107
  for (let e = 0; e < o.length; e += 1) {
1108
1108
  if (!c[e] || l[e]) continue;
1109
1109
  let t = [], n = [e];
@@ -1151,11 +1151,11 @@ function gt(e, t, n, r = 12) {
1151
1151
  }
1152
1152
  return d;
1153
1153
  }
1154
- function _t(e, t, n, r, i, a, o) {
1154
+ function gt(e, t, n, r, i, a, o) {
1155
1155
  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));
1156
1156
  return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
1157
1157
  }
1158
- function vt(e, t, n) {
1158
+ function _t(e, t, n) {
1159
1159
  let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
1160
1160
  for (let a = 1; a <= n; a += 1) {
1161
1161
  let n = 0;
@@ -1166,23 +1166,23 @@ function vt(e, t, n) {
1166
1166
  stride: r
1167
1167
  };
1168
1168
  }
1169
- function yt(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
1170
- let { integral: i, stride: a } = vt(e, t, n), o = new Uint8Array(e.length);
1169
+ function vt(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
1170
+ let { integral: i, stride: a } = _t(e, t, n), o = new Uint8Array(e.length);
1171
1171
  for (let s = 0; s < n; s += 1) for (let c = 0; c < t; c += 1) {
1172
- let l = _t(i, a, t, n, c, s, r);
1172
+ let l = gt(i, a, t, n, c, s, r);
1173
1173
  o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
1174
1174
  }
1175
1175
  return o;
1176
1176
  }
1177
- function bt(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
1178
- let { integral: a, stride: o } = vt(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
1177
+ function yt(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
1178
+ let { integral: a, stride: o } = _t(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
1179
1179
  for (let i = 0; i < n; i += 1) for (let l = 0; l < t; l += 1) {
1180
- let u = _t(a, o, t, n, l, i, r);
1180
+ let u = gt(a, o, t, n, l, i, r);
1181
1181
  s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
1182
1182
  }
1183
1183
  return s;
1184
1184
  }
1185
- function xt(e, t, n) {
1185
+ function bt(e, t, n) {
1186
1186
  let r = [
1187
1187
  e.topLeft,
1188
1188
  e.topRight,
@@ -1196,8 +1196,8 @@ function xt(e, t, n) {
1196
1196
  height: s - a
1197
1197
  };
1198
1198
  }
1199
- function St(e, t) {
1200
- let n = xt(t, e.width, e.height);
1199
+ function xt(e, t) {
1200
+ let n = bt(t, e.width, e.height);
1201
1201
  if (n.width <= 0 || n.height <= 0) return {
1202
1202
  strong: !1,
1203
1203
  strength: 0,
@@ -1216,26 +1216,26 @@ function St(e, t) {
1216
1216
  i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
1217
1217
  let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
1218
1218
  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);
1219
- return gt(o, r.width, r.height);
1219
+ return ht(o, r.width, r.height);
1220
1220
  }
1221
1221
  //#endregion
1222
1222
  //#region src/sdk/finder.ts
1223
- function Ct(e, t) {
1223
+ function St(e, t) {
1224
1224
  return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
1225
1225
  }
1226
- function wt(e, t, n) {
1226
+ function Ct(e, t, n) {
1227
1227
  if (n <= 0) return 0;
1228
1228
  let r = n - (t - e);
1229
1229
  return r <= 0 ? 0 : Math.max(1, Math.ceil(r / 1e3));
1230
1230
  }
1231
- function Tt(e) {
1231
+ function wt(e) {
1232
1232
  return `Hold still for ${e}…`;
1233
1233
  }
1234
- async function Et(e, t) {
1234
+ async function Tt(e, t) {
1235
1235
  let n = await e();
1236
1236
  return t(), n;
1237
1237
  }
1238
- function Dt(e) {
1238
+ function Et(e) {
1239
1239
  return e === "alwaysOn" || e === "only" ? {
1240
1240
  visible: !1,
1241
1241
  checked: !0,
@@ -1250,7 +1250,7 @@ function Dt(e) {
1250
1250
  mutable: !0
1251
1251
  };
1252
1252
  }
1253
- function R(e) {
1253
+ function z(e) {
1254
1254
  return [
1255
1255
  e.topLeft,
1256
1256
  e.topRight,
@@ -1258,19 +1258,19 @@ function R(e) {
1258
1258
  e.bottomLeft
1259
1259
  ];
1260
1260
  }
1261
- var Ot = 3e3, kt = 1600;
1262
- function At(e = D()) {
1261
+ var Dt = 3e3, Ot = 1600;
1262
+ function kt(e = O()) {
1263
1263
  return e.iosWebKit ? {
1264
1264
  intervalMs: 70,
1265
1265
  maxFrameDimension: 720,
1266
1266
  maxAnalysisDimension: 720
1267
1267
  } : {
1268
1268
  intervalMs: 140,
1269
- maxFrameDimension: kt,
1269
+ maxFrameDimension: Ot,
1270
1270
  maxAnalysisDimension: 520
1271
1271
  };
1272
1272
  }
1273
- function jt(e, t) {
1273
+ function At(e, t) {
1274
1274
  let n = e.status === "success" && e.modelStatus !== "failed", r = {
1275
1275
  status: e.status,
1276
1276
  confidence: Number(e.confidence.toFixed(3)),
@@ -1293,7 +1293,7 @@ function jt(e, t) {
1293
1293
  detail: r
1294
1294
  };
1295
1295
  }
1296
- function Mt(e) {
1296
+ function jt(e) {
1297
1297
  let t = 0;
1298
1298
  for (let n = 0; n < e.length; n += 1) {
1299
1299
  let r = e[n], i = e[(n + 1) % e.length];
@@ -1301,42 +1301,42 @@ function Mt(e) {
1301
1301
  }
1302
1302
  return Math.abs(t) / 2;
1303
1303
  }
1304
- function z(e, t) {
1304
+ function B(e, t) {
1305
1305
  return Math.hypot(e.x - t.x, e.y - t.y);
1306
1306
  }
1307
- var B = {
1307
+ var V = {
1308
1308
  widthFill: 0,
1309
1309
  heightFill: 0,
1310
1310
  limitingFill: 0,
1311
1311
  areaFill: 0,
1312
1312
  aspectRatio: 1
1313
1313
  };
1314
- function Nt(e, t, n) {
1315
- let r = R(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));
1314
+ function Mt(e, t, n) {
1315
+ 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(B(c, l), B(d, u)), p = Math.max(B(c, d), B(l, u));
1316
1316
  return {
1317
1317
  widthFill: o,
1318
1318
  heightFill: s,
1319
1319
  limitingFill: Math.max(o, s),
1320
- areaFill: Mt(r) / Math.max(1, t * n),
1320
+ areaFill: jt(r) / Math.max(1, t * n),
1321
1321
  aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
1322
1322
  };
1323
1323
  }
1324
- function Pt(e, t, n, r = {}) {
1324
+ function Nt(e, t, n, r = {}) {
1325
1325
  let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
1326
1326
  if (e.aspectRatio < a) return i;
1327
1327
  let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
1328
1328
  return Math.min(o ?? i + .08, 1 - n * 2);
1329
1329
  }
1330
- function Ft(e, t, n = {}) {
1330
+ function Pt(e, t, n = {}) {
1331
1331
  let r = n.confidenceThreshold ?? .72;
1332
1332
  if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
1333
1333
  hint: "Place the document in the frame",
1334
1334
  reason: "place-document",
1335
1335
  fillRatio: 0,
1336
- fill: B,
1336
+ fill: V,
1337
1337
  readyForAutoCapture: !1
1338
1338
  };
1339
- let i = R(e.quad), a = Nt(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;
1339
+ let i = z(e.quad), a = Mt(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;
1340
1340
  if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
1341
1341
  hint: "Move farther away",
1342
1342
  reason: "move-farther-away",
@@ -1344,14 +1344,14 @@ function Ft(e, t, n = {}) {
1344
1344
  fill: a,
1345
1345
  readyForAutoCapture: !1
1346
1346
  };
1347
- let [u, d, f, p] = i, m = z(u, d), h = z(d, f), g = z(f, p), _ = z(p, u);
1347
+ let [u, d, f, p] = i, m = B(u, d), h = B(d, f), g = B(f, p), _ = B(p, u);
1348
1348
  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) ? {
1349
1349
  hint: "Hold the camera straight",
1350
1350
  reason: "straighten-camera",
1351
1351
  fillRatio: o,
1352
1352
  fill: a,
1353
1353
  readyForAutoCapture: !1
1354
- } : o < Pt(a, t.previouslyReady === !0, s, n) ? {
1354
+ } : o < Nt(a, t.previouslyReady === !0, s, n) ? {
1355
1355
  hint: "Move closer",
1356
1356
  reason: "move-closer",
1357
1357
  fillRatio: o,
@@ -1365,7 +1365,7 @@ function Ft(e, t, n = {}) {
1365
1365
  readyForAutoCapture: t.ready
1366
1366
  };
1367
1367
  }
1368
- var It = class {
1368
+ var Ft = class {
1369
1369
  previous;
1370
1370
  count = 0;
1371
1371
  ready = !1;
@@ -1382,8 +1382,8 @@ var It = class {
1382
1382
  ready: !1,
1383
1383
  movement: Infinity
1384
1384
  };
1385
- let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...R(e.quad).map((e, n) => {
1386
- let r = R(this.previous)[n];
1385
+ let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...z(e.quad).map((e, n) => {
1386
+ let r = z(this.previous)[n];
1387
1387
  return Math.hypot(e.x - r.x, e.y - r.y) / Math.max(1, t);
1388
1388
  })) : Infinity, r = this.options.exitCornerTolerance ?? Math.max(this.options.cornerTolerance, .036);
1389
1389
  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, {
@@ -1393,14 +1393,14 @@ var It = class {
1393
1393
  };
1394
1394
  }
1395
1395
  };
1396
- function Lt(e, n) {
1396
+ function It(e, n) {
1397
1397
  let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
1398
1398
  i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
1399
1399
  let a = i.getContext("2d");
1400
1400
  if (!a) throw t();
1401
1401
  return a.drawImage(e, 0, 0, i.width, i.height), i;
1402
1402
  }
1403
- function Rt() {
1403
+ function Lt() {
1404
1404
  let e = window.AudioContext ?? window.webkitAudioContext;
1405
1405
  if (!e) return;
1406
1406
  let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
@@ -1411,29 +1411,29 @@ function Rt() {
1411
1411
  let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
1412
1412
  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();
1413
1413
  }
1414
- async function zt(e) {
1414
+ async function Rt(e) {
1415
1415
  let t = document.createElement("video");
1416
1416
  return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
1417
1417
  }
1418
- async function Bt(t) {
1418
+ async function zt(t) {
1419
1419
  await x("scan");
1420
- let n = Dt(t.autoCapture), r = t.holdStillMs ?? 3e3, i = new It({
1420
+ let n = Et(t.autoCapture), r = t.holdStillMs ?? 3e3, i = new Ft({
1421
1421
  stableFrames: t.stableFrames ?? 4,
1422
1422
  confidenceThreshold: t.confidenceThreshold ?? .72,
1423
1423
  cornerTolerance: t.cornerTolerance ?? .024,
1424
1424
  exitCornerTolerance: t.exitCornerTolerance ?? .036
1425
- }), a = At(), o = t.maxFrameDimension ?? a.maxFrameDimension, s = t.intervalMs ?? a.intervalMs, c = {
1425
+ }), a = kt(), o = t.maxFrameDimension ?? a.maxFrameDimension, s = t.intervalMs ?? a.intervalMs, c = {
1426
1426
  minDimension: 220,
1427
1427
  maxAnalysisDimension: a.maxAnalysisDimension,
1428
1428
  ...t.detection
1429
- }, l = typeof MediaStream < "u" && t.source instanceof MediaStream ? await zt(t.source) : t.source, u = !0, d = !1, f = !1, p, m = 0, h, g = "", _ = 0, v = {
1429
+ }, l = typeof MediaStream < "u" && t.source instanceof MediaStream ? await Rt(t.source) : t.source, u = !0, d = !1, f = !1, p, m = 0, h, g = "", _ = 0, v = {
1430
1430
  state: "detecting",
1431
1431
  confidence: 0,
1432
1432
  guidance: {
1433
1433
  hint: "Place the document in the frame",
1434
1434
  reason: "place-document",
1435
1435
  fillRatio: 0,
1436
- fill: B,
1436
+ fill: V,
1437
1437
  readyForAutoCapture: !1
1438
1438
  },
1439
1439
  lighting: {
@@ -1443,10 +1443,10 @@ async function Bt(t) {
1443
1443
  stableFrames: 0,
1444
1444
  requiredStableFrames: t.stableFrames ?? 4,
1445
1445
  autoCapture: { ...n }
1446
- }, y = () => l instanceof HTMLCanvasElement ? Lt(l, o) : M(l, o), b = (e) => {
1446
+ }, y = () => l instanceof HTMLCanvasElement ? It(l, o) : N(l, o), b = (e) => {
1447
1447
  v = e, t.onStatus?.(e);
1448
1448
  }, S = (e) => {
1449
- let t = jt(e, l instanceof HTMLVideoElement ? {
1449
+ let t = At(e, l instanceof HTMLVideoElement ? {
1450
1450
  width: l.videoWidth,
1451
1451
  height: l.videoHeight
1452
1452
  } : {
@@ -1461,11 +1461,11 @@ async function Bt(t) {
1461
1461
  d = !0;
1462
1462
  let n;
1463
1463
  try {
1464
- n = await Et(t.captureFrame ?? y, () => {
1464
+ n = await Tt(t.captureFrame ?? y, () => {
1465
1465
  b({
1466
1466
  ...v,
1467
1467
  state: "captured"
1468
- }), t.playShutterSound !== !1 && Rt(), C();
1468
+ }), t.playShutterSound !== !1 && Lt(), C();
1469
1469
  });
1470
1470
  } catch (e) {
1471
1471
  throw d = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
@@ -1479,9 +1479,9 @@ async function Bt(t) {
1479
1479
  }, T = async () => {
1480
1480
  if (u && !d) {
1481
1481
  try {
1482
- let e = y(), a = await dt(e, c);
1482
+ let e = y(), a = await ut(e, c);
1483
1483
  h = a, S(a);
1484
- let o = a.quad ? St(e, a.quad) : {
1484
+ let o = a.quad ? xt(e, a.quad) : {
1485
1485
  strong: !1,
1486
1486
  strength: 0
1487
1487
  }, s = o.strong ? {
@@ -1491,7 +1491,7 @@ async function Bt(t) {
1491
1491
  } : {
1492
1492
  castShadow: !1,
1493
1493
  strength: o.strength
1494
- }, l = i.update(a), u = Ft(a, {
1494
+ }, l = i.update(a), u = Pt(a, {
1495
1495
  ...l,
1496
1496
  previouslyReady: f
1497
1497
  }, {
@@ -1501,7 +1501,7 @@ async function Bt(t) {
1501
1501
  f = u.readyForAutoCapture;
1502
1502
  let d = performance.now();
1503
1503
  u.readyForAutoCapture && n.checked ? p ??= d : p = void 0;
1504
- let m = p === void 0 ? void 0 : wt(p, d, r), g = a.status !== "success" || u.reason === "place-document" ? "seeking" : u.readyForAutoCapture ? "ready" : "unstable";
1504
+ let m = p === void 0 ? void 0 : Ct(p, d, r), g = a.status !== "success" || u.reason === "place-document" ? "seeking" : u.readyForAutoCapture ? "ready" : "unstable";
1505
1505
  if (b({
1506
1506
  state: g,
1507
1507
  confidence: a.confidence,
@@ -1547,7 +1547,7 @@ async function Bt(t) {
1547
1547
  hint: "Place the document in the frame",
1548
1548
  reason: "place-document",
1549
1549
  fillRatio: 0,
1550
- fill: B,
1550
+ fill: V,
1551
1551
  readyForAutoCapture: !1
1552
1552
  },
1553
1553
  lighting: {
@@ -1578,24 +1578,24 @@ async function Bt(t) {
1578
1578
  }
1579
1579
  //#endregion
1580
1580
  //#region src/sdk/ocr-runtime.ts
1581
- var Vt = new URL("./assets/tesseract/worker.min.js", import.meta.url), Ht = new URL("./assets/tesseract/tesseract-core-lstm.wasm.js", import.meta.url), Ut = new URL("./assets/tesseract/tesseract-core-simd-lstm.wasm.js", import.meta.url), Wt = new URL("./assets/tesseract/tesseract-core-relaxedsimd-lstm.wasm.js", import.meta.url), Gt = new URL("./assets/tesseract/eng.traineddata.gz", import.meta.url), Kt = Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 15, 1, 13, 0, 65, 1, 253, 15, 65, 2, 253, 15, 253, 128, 2, 11), qt = Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 10, 1, 8, 0, 65, 0, 253, 15, 253, 98, 11);
1582
- function Jt(e) {
1581
+ var Bt = new URL("./assets/tesseract/worker.min.js", import.meta.url), Vt = new URL("./assets/tesseract/tesseract-core-lstm.wasm.js", import.meta.url), Ht = new URL("./assets/tesseract/tesseract-core-simd-lstm.wasm.js", import.meta.url), Ut = new URL("./assets/tesseract/tesseract-core-relaxedsimd-lstm.wasm.js", import.meta.url), Wt = new URL("./assets/tesseract/eng.traineddata.gz", import.meta.url), Gt = Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 15, 1, 13, 0, 65, 1, 253, 15, 65, 2, 253, 15, 253, 128, 2, 11), Kt = Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 10, 1, 8, 0, 65, 0, 253, 15, 253, 98, 11);
1582
+ function qt(e) {
1583
1583
  try {
1584
1584
  return typeof WebAssembly < "u" && WebAssembly.validate(e);
1585
1585
  } catch {
1586
1586
  return !1;
1587
1587
  }
1588
1588
  }
1589
- function Yt() {
1589
+ function Jt() {
1590
1590
  return {
1591
- relaxedSimd: Jt(Kt),
1592
- simd: Jt(qt)
1591
+ relaxedSimd: qt(Gt),
1592
+ simd: qt(Kt)
1593
1593
  };
1594
1594
  }
1595
- function Xt(e) {
1596
- return e.relaxedSimd ? Wt : e.simd ? Ut : Ht;
1595
+ function Yt(e) {
1596
+ return e.relaxedSimd ? Ut : e.simd ? Ht : Vt;
1597
1597
  }
1598
- function Zt(t, n) {
1598
+ function Xt(t, n) {
1599
1599
  let r = t?.trim() || "eng", i = n?.trim() || "";
1600
1600
  if (i) return {
1601
1601
  kind: "lang-path",
@@ -1608,14 +1608,14 @@ function Zt(t, n) {
1608
1608
  };
1609
1609
  throw new e("language", `OCR language "${r}" is not packaged. Pass langPath, a directory URL that contains ${r}.traineddata.gz.`);
1610
1610
  }
1611
- function Qt(e = Gt) {
1611
+ function Zt(e = Wt) {
1612
1612
  let t = e.href, n = t.lastIndexOf("/");
1613
1613
  return n === -1 ? t : t.slice(0, n);
1614
1614
  }
1615
- function $t(e) {
1616
- return e.kind === "bundled-eng" ? Qt() : e.langPath;
1615
+ function Qt(e) {
1616
+ return e.kind === "bundled-eng" ? Zt() : e.langPath;
1617
1617
  }
1618
- async function en(t, n, r) {
1618
+ async function $t(t, n, r) {
1619
1619
  return new Promise((i, a) => {
1620
1620
  let o = !1, s = (t) => {
1621
1621
  o || (o = !0, a(new e("worker", `OCR worker failed to start (${t instanceof Error ? t.message : String(t)}).`)));
@@ -1638,7 +1638,7 @@ async function en(t, n, r) {
1638
1638
  }
1639
1639
  //#endregion
1640
1640
  //#region src/sdk/ocr.ts
1641
- function tn(e, t = 1, n = 1, r = 0, i = 0) {
1641
+ function en(e, t = 1, n = 1, r = 0, i = 0) {
1642
1642
  return {
1643
1643
  text: e.text,
1644
1644
  confidence: Math.max(0, Math.min(1, e.confidence / 100)),
@@ -1650,20 +1650,20 @@ function tn(e, t = 1, n = 1, r = 0, i = 0) {
1650
1650
  }
1651
1651
  };
1652
1652
  }
1653
- function nn(e = .5) {
1653
+ function tn(e = .5) {
1654
1654
  if (!Number.isFinite(e) || e < 0 || e > 1) throw RangeError("OCR minConfidence must be between 0 and 1.");
1655
1655
  return e;
1656
1656
  }
1657
- function rn(e, t) {
1657
+ function nn(e, t) {
1658
1658
  let n = Math.max(e.bbox.x, t.bbox.x), r = Math.max(e.bbox.y, t.bbox.y), i = Math.min(e.bbox.x + e.bbox.width, t.bbox.x + t.bbox.width), a = Math.min(e.bbox.y + e.bbox.height, t.bbox.y + t.bbox.height), o = Math.max(0, i - n) * Math.max(0, a - r), s = Math.min(e.bbox.width * e.bbox.height, t.bbox.width * t.bbox.height);
1659
1659
  return s > 0 ? o / s : 0;
1660
1660
  }
1661
- function an(e) {
1661
+ function rn(e) {
1662
1662
  let t = [...e].sort((e, t) => t.confidence - e.confidence || e.bbox.y - t.bbox.y || e.bbox.x - t.bbox.x || e.text.localeCompare(t.text)), n = [];
1663
- for (let e of t) n.some((t) => rn(t, e) >= .65) || n.push(e);
1663
+ for (let e of t) n.some((t) => nn(t, e) >= .65) || n.push(e);
1664
1664
  return n;
1665
1665
  }
1666
- function on(e, t, n, r, i) {
1666
+ function an(e, t, n, r, i) {
1667
1667
  let a = e.text.trim();
1668
1668
  if (!a || !/[\p{L}\p{N}]/u.test(a)) return !1;
1669
1669
  let o = e.bbox.width * e.bbox.height / Math.max(1, n * r), s = e.bbox.width / Math.max(1, e.bbox.height);
@@ -1674,7 +1674,7 @@ function on(e, t, n, r, i) {
1674
1674
  }
1675
1675
  return !0;
1676
1676
  }
1677
- function sn(e) {
1677
+ function on(e) {
1678
1678
  let t = [...e].sort((e, t) => e.bbox.y + e.bbox.height / 2 - (t.bbox.y + t.bbox.height / 2) || e.bbox.x - t.bbox.x), n = [];
1679
1679
  for (let e of t) {
1680
1680
  let t = e.bbox.y + e.bbox.height / 2, r = n.find((n) => Math.abs(n.centerY - t) <= Math.max(n.height, e.bbox.height) * .6);
@@ -1690,28 +1690,28 @@ function sn(e) {
1690
1690
  }
1691
1691
  return n.sort((e, t) => e.centerY - t.centerY).map((e) => e.words.sort((e, t) => e.bbox.x - t.bbox.x).map((e) => e.text.trim()).join(" ")).join("\n");
1692
1692
  }
1693
- function cn(e, t, n, r) {
1694
- let i = nn(t.minConfidence), a = [], o = [], s = 1, c = 1;
1693
+ function sn(e, t, n, r) {
1694
+ let i = tn(t.minConfidence), a = [], o = [], s = 1, c = 1;
1695
1695
  for (let t of e) {
1696
1696
  let e = t.scaleX ?? 1, n = t.scaleY ?? 1, r = t.offsetX ?? 0, l = t.offsetY ?? 0;
1697
1697
  for (let u of t.blocks ?? []) for (let t of u.paragraphs) for (let u of t.lines) for (let t of u.words) {
1698
- let u = tn(t, e, n, r, l);
1698
+ let u = en(t, e, n, r, l);
1699
1699
  s = Math.max(s, u.bbox.x + u.bbox.width), c = Math.max(c, u.bbox.y + u.bbox.height), u.confidence >= i && a.push(u);
1700
1700
  for (let a of t.symbols) {
1701
- let t = tn(a, e, n, r, l);
1701
+ let t = en(a, e, n, r, l);
1702
1702
  t.confidence >= i && o.push(t);
1703
1703
  }
1704
1704
  }
1705
1705
  }
1706
- let l = n?.width ?? s, u = n?.height ?? c, d = an(a).filter((e) => on(e, "word", l, u, r)), f = an(o).filter((e) => on(e, "character", l, u, r));
1706
+ let l = n?.width ?? s, u = n?.height ?? c, d = rn(a).filter((e) => an(e, "word", l, u, r)), f = rn(o).filter((e) => an(e, "character", l, u, r));
1707
1707
  return {
1708
- text: sn(d),
1708
+ text: on(d),
1709
1709
  confidence: d.length ? d.reduce((e, t) => e + t.confidence, 0) / d.length : 0,
1710
1710
  words: t.includeWords ? d : [],
1711
1711
  characters: t.includeCharacters ? f : []
1712
1712
  };
1713
1713
  }
1714
- function ln(e) {
1714
+ function cn(e) {
1715
1715
  let n = e.getContext("2d", { willReadFrequently: !0 });
1716
1716
  if (!n) throw t();
1717
1717
  let r = n.getImageData(0, 0, e.width, e.height), i = new Uint8Array(e.width * e.height);
@@ -1722,7 +1722,7 @@ function ln(e) {
1722
1722
  luminance: i
1723
1723
  };
1724
1724
  }
1725
- function un(e) {
1725
+ function ln(e) {
1726
1726
  let t = document.createElement("canvas");
1727
1727
  t.width = 72, t.height = 72;
1728
1728
  let n = t.getContext("2d", { willReadFrequently: !0 });
@@ -1733,27 +1733,27 @@ function un(e) {
1733
1733
  areaRatio: 0
1734
1734
  };
1735
1735
  n.drawImage(e, 0, 0, t.width, t.height);
1736
- let { luminance: r } = ln(t);
1737
- return gt(r, t.width, t.height);
1736
+ let { luminance: r } = cn(t);
1737
+ return ht(r, t.width, t.height);
1738
1738
  }
1739
- function dn(e, t, n, r) {
1739
+ function un(e, t, n, r) {
1740
1740
  let i = (e.bbox.x + e.bbox.width / 2) / n, a = (e.bbox.y + e.bbox.height / 2) / r;
1741
1741
  return i >= t.x && i <= t.x + t.width && a >= t.y && a <= t.y + t.height;
1742
1742
  }
1743
- var fn = .58;
1744
- function pn(e) {
1743
+ var dn = .58;
1744
+ function fn(e) {
1745
1745
  let t = e.trim();
1746
1746
  if (!t || !/[\p{L}\p{N}]/u.test(t)) return 0;
1747
1747
  if (/^\$?\d{1,5}([.,]\d{2})?$/.test(t)) return 1;
1748
1748
  let n = t.replace(/[^\p{L}]/gu, "");
1749
1749
  return n.length >= 3 && /[aeiouy]/i.test(n) ? .9 : n.length >= 4 ? .7 : t.length <= 2 ? .35 : /[^\p{L}\p{N}.,'’$/-]/u.test(t) ? .25 : .5;
1750
1750
  }
1751
- function mn(e, t, n) {
1751
+ function pn(e, t, n) {
1752
1752
  let r = Math.max(0, Math.min(1, (1 - e.darkness / 80) * (1 - e.strength / 24)));
1753
1753
  if (!t.length) return r * .35;
1754
1754
  let i = 0;
1755
1755
  for (let e of t) {
1756
- let t = pn(e.text);
1756
+ let t = fn(e.text);
1757
1757
  if (n) {
1758
1758
  let r = n(e.bbox);
1759
1759
  (r < .04 || r > .62) && (t *= .4);
@@ -1762,10 +1762,10 @@ function mn(e, t, n) {
1762
1762
  }
1763
1763
  return r * .7 + i / t.length * .3;
1764
1764
  }
1765
- function hn(e, t, n, r) {
1766
- return !e.strong || !e.region ? !1 : mn(e, t.filter((t) => dn(t, e.region, n.width, n.height)), r) < fn;
1765
+ function mn(e, t, n, r) {
1766
+ return !e.strong || !e.region ? !1 : pn(e, t.filter((t) => un(t, e.region, n.width, n.height)), r) < dn;
1767
1767
  }
1768
- function gn(e, t, n, r) {
1768
+ function hn(e, t, n, r) {
1769
1769
  let i = Math.max(0, Math.floor(t.x * e.width)), a = Math.max(0, Math.floor(t.y * e.height)), o = Math.min(e.width, Math.ceil((t.x + t.width) * e.width)), s = Math.min(e.height, Math.ceil((t.y + t.height) * e.height)), c = document.createElement("canvas");
1770
1770
  c.width = Math.max(1, o - i), c.height = Math.max(1, s - a), c.getContext("2d")?.drawImage(e, i, a, c.width, c.height, 0, 0, c.width, c.height);
1771
1771
  let l = n / e.width, u = r / e.height;
@@ -1779,26 +1779,26 @@ function gn(e, t, n, r) {
1779
1779
  }
1780
1780
  };
1781
1781
  }
1782
- function _n(e, t) {
1782
+ function gn(e, t) {
1783
1783
  for (let n = 0, r = 0; n < t.length; n += 1, r += 4) e.data[r] = t[n], e.data[r + 1] = t[n], e.data[r + 2] = t[n], e.data[r + 3] = 255;
1784
1784
  }
1785
- function vn(e) {
1785
+ function _n(e) {
1786
1786
  let n = 2200, r = Math.max(e.width, e.height), i = r > n ? n / r : Math.min(1.5, n / Math.max(1, r)), a = document.createElement("canvas");
1787
1787
  a.width = Math.max(1, Math.round(e.width * i)), a.height = Math.max(1, Math.round(e.height * i));
1788
1788
  let o = a.getContext("2d", { willReadFrequently: !0 });
1789
1789
  if (!o) throw t();
1790
1790
  o.drawImage(e, 0, 0, a.width, a.height);
1791
- let { image: s, luminance: c } = ln(a), l = yt(c, a.width, a.height), u = bt(l, a.width, a.height), d = document.createElement("canvas");
1791
+ let { image: s, luminance: c } = cn(a), l = vt(c, a.width, a.height), u = yt(l, a.width, a.height), d = document.createElement("canvas");
1792
1792
  d.width = a.width, d.height = a.height;
1793
1793
  let f = d.getContext("2d", { willReadFrequently: !0 });
1794
1794
  if (!f) throw t();
1795
1795
  let p = f.createImageData(d.width, d.height);
1796
- return _n(p, l), f.putImageData(p, 0, 0), _n(s, u), o.putImageData(s, 0, 0), {
1796
+ return gn(p, l), f.putImageData(p, 0, 0), gn(s, u), o.putImageData(s, 0, 0), {
1797
1797
  sparseCanvas: a,
1798
1798
  flattenedCanvas: d
1799
1799
  };
1800
1800
  }
1801
- function yn(e) {
1801
+ function vn(e) {
1802
1802
  let t = document.createElement("canvas");
1803
1803
  t.width = 24, t.height = 24;
1804
1804
  let n = t.getContext("2d", { willReadFrequently: !0 });
@@ -1816,19 +1816,19 @@ function yn(e) {
1816
1816
  return l / s.length;
1817
1817
  };
1818
1818
  }
1819
- async function bn(e, t = {}) {
1819
+ async function H(e, t = {}) {
1820
1820
  await x("ocr");
1821
- let n = Zt(t.language, t.langPath), r = n.language;
1822
- nn(t.minConfidence);
1823
- let i = await N(e, { cloneCanvas: !1 }), { sparseCanvas: a, flattenedCanvas: o } = vn(i), s = t.shadowPass === !1 ? {
1821
+ let n = Xt(t.language, t.langPath), r = n.language;
1822
+ tn(t.minConfidence);
1823
+ let i = await P(e, { cloneCanvas: !1 }), { sparseCanvas: a, flattenedCanvas: o } = _n(i), s = t.shadowPass === !1 ? {
1824
1824
  strong: !1,
1825
1825
  strength: 0,
1826
1826
  darkness: 0,
1827
1827
  areaRatio: 0
1828
- } : un(i), { createWorker: c, PSM: l } = await import("tesseract.js"), u = 0, d = s.strong ? 3 : 2, f = await en(c, r, {
1829
- workerPath: Vt.href,
1830
- corePath: Xt(Yt()).href,
1831
- langPath: $t(n),
1828
+ } : ln(i), { createWorker: c, PSM: l } = await import("tesseract.js"), u = 0, d = s.strong ? 3 : 2, f = await $t(c, r, {
1829
+ workerPath: Bt.href,
1830
+ corePath: Yt(Jt()).href,
1831
+ langPath: Qt(n),
1832
1832
  logger(e) {
1833
1833
  typeof e.progress == "number" && t.onProgress?.(Math.min(1, (u + e.progress) / d), e.status ?? "recognizing text");
1834
1834
  }
@@ -1853,16 +1853,16 @@ async function bn(e, t = {}) {
1853
1853
  }], d = {
1854
1854
  ...t,
1855
1855
  includeWords: !0
1856
- }, p = yn(i), m = cn(c, d, {
1856
+ }, p = vn(i), m = sn(c, d, {
1857
1857
  width: i.width,
1858
1858
  height: i.height
1859
- }, p), h = t.shadowPass !== !1 && hn(s, m.words, {
1859
+ }, p), h = t.shadowPass !== !1 && mn(s, m.words, {
1860
1860
  width: i.width,
1861
1861
  height: i.height
1862
1862
  }, p);
1863
1863
  if (h && s.region) {
1864
1864
  u = 2;
1865
- let { tile: e, passMapping: t } = gn(o, s.region, i.width, i.height);
1865
+ let { tile: e, passMapping: t } = hn(o, s.region, i.width, i.height);
1866
1866
  await f.setParameters({
1867
1867
  tessedit_pageseg_mode: l.SPARSE_TEXT,
1868
1868
  preserve_interword_spaces: "1"
@@ -1876,7 +1876,7 @@ async function bn(e, t = {}) {
1876
1876
  ...t
1877
1877
  });
1878
1878
  }
1879
- let g = c.length === 2 ? m : cn(c, d, {
1879
+ let g = c.length === 2 ? m : sn(c, d, {
1880
1880
  width: i.width,
1881
1881
  height: i.height
1882
1882
  }, p);
@@ -1905,68 +1905,68 @@ async function bn(e, t = {}) {
1905
1905
  }
1906
1906
  //#endregion
1907
1907
  //#region src/sdk/zxing-runtime.ts
1908
- var xn = new URL("./assets/zxing_reader.wasm", import.meta.url), Sn = "3.1.6", Cn = "zxing_reader.wasm", wn = `https://exige-scanner-sdk.vercel.app/zxing/${Sn}/`, Tn = `https://cdn.jsdelivr.net/npm/zxing-wasm@${Sn}/dist/reader/`;
1909
- function En(e, t) {
1908
+ var yn = new URL("./assets/zxing_reader.wasm", import.meta.url), bn = "3.1.6", xn = "zxing_reader.wasm", Sn = `https://exige-scanner-sdk.vercel.app/zxing/${bn}/`, Cn = `https://cdn.jsdelivr.net/npm/zxing-wasm@${bn}/dist/reader/`;
1909
+ function wn(e, t) {
1910
1910
  return `${e.endsWith("/") ? e : `${e}/`}${t}`;
1911
1911
  }
1912
- function Dn(e = wn) {
1913
- return En(e, Cn);
1912
+ function Tn(e = Sn) {
1913
+ return wn(e, xn);
1914
1914
  }
1915
- function On() {
1916
- return xn.href;
1915
+ function En() {
1916
+ return yn.href;
1917
1917
  }
1918
- var kn, An;
1919
- function jn() {
1918
+ var Dn, On;
1919
+ function kn() {
1920
1920
  return {
1921
- binary: kn,
1922
- url: An
1921
+ binary: Dn,
1922
+ url: On
1923
1923
  };
1924
1924
  }
1925
- async function Mn(e = fetch) {
1926
- let t = On();
1927
- if (await He(t, e)) return t;
1928
- let n = Dn(wn);
1929
- return await He(n, e) ? n : Dn(Tn);
1925
+ async function An(e = fetch) {
1926
+ let t = En();
1927
+ if (await Ve(t, e)) return t;
1928
+ let n = Tn(Sn);
1929
+ return await Ve(n, e) ? n : Tn(Cn);
1930
1930
  }
1931
- async function Nn(e = fetch) {
1932
- let t = jn();
1931
+ async function jn(e = fetch) {
1932
+ let t = kn();
1933
1933
  if (t.binary) return t.binary.slice(0);
1934
- let n = await e(await Mn(e));
1934
+ let n = await e(await An(e));
1935
1935
  if (!n.ok) throw Error(`Could not download zxing-wasm (${n.status}).`);
1936
1936
  return await n.arrayBuffer();
1937
1937
  }
1938
1938
  //#endregion
1939
1939
  //#region src/sdk/barcode.ts
1940
- var Pn = 1600, Fn = [
1940
+ var Mn = 1600, Nn = [
1941
1941
  1600,
1942
1942
  1280,
1943
1943
  960,
1944
1944
  720,
1945
1945
  480
1946
- ], In = [
1946
+ ], Pn = [
1947
1947
  [.2, .8],
1948
1948
  [.32, .72],
1949
1949
  [.4, .86]
1950
1950
  ];
1951
- function Ln(e, t) {
1951
+ function Fn(e, t) {
1952
1952
  let n = Math.max(e, t);
1953
1953
  if (!Number.isFinite(n) || n < 1) return [];
1954
- let r = Math.min(n, Pn), i = [r];
1955
- for (let e of Fn) e <= r - 16 && i.push(e);
1954
+ let r = Math.min(n, Mn), i = [r];
1955
+ for (let e of Nn) e <= r - 16 && i.push(e);
1956
1956
  return i;
1957
1957
  }
1958
- var V = class extends Error {
1958
+ var U = class extends Error {
1959
1959
  code = "zxing-wasm-load";
1960
1960
  constructor(e) {
1961
1961
  super("The barcode decoder failed to load."), this.name = "Pdf417DecoderError", e !== void 0 && (this.cause = e);
1962
1962
  }
1963
1963
  };
1964
- function Rn() {
1964
+ function In() {
1965
1965
  let e = globalThis.BarcodeDetector;
1966
1966
  return typeof e == "function" ? e : void 0;
1967
1967
  }
1968
- async function zn() {
1969
- let e = Rn();
1968
+ async function Ln() {
1969
+ let e = In();
1970
1970
  if (!e?.getSupportedFormats) return !1;
1971
1971
  try {
1972
1972
  return (await e.getSupportedFormats()).some((e) => e.toLowerCase() === "pdf417");
@@ -1974,45 +1974,116 @@ async function zn() {
1974
1974
  return !1;
1975
1975
  }
1976
1976
  }
1977
- function Bn(e) {
1977
+ function Rn(e) {
1978
1978
  try {
1979
1979
  return e.getContext("2d", { willReadFrequently: !0 })?.getImageData(0, 0, e.width, e.height);
1980
1980
  } catch {
1981
1981
  return;
1982
1982
  }
1983
1983
  }
1984
- async function Vn(e) {
1984
+ async function zn(e) {
1985
1985
  let t = [];
1986
1986
  if (e instanceof Blob && t.push(e), e instanceof HTMLCanvasElement) {
1987
- let n = Bn(e);
1987
+ let n = Rn(e);
1988
1988
  n && t.push(n);
1989
1989
  try {
1990
- t.push(await Ye(e, "image/png"));
1990
+ t.push(await Je(e, "image/png"));
1991
1991
  } catch {}
1992
1992
  } else if (!(e instanceof Blob)) try {
1993
- let n = Bn(await N(e, { cloneCanvas: !1 }));
1993
+ let n = Rn(await P(e, { cloneCanvas: !1 }));
1994
1994
  n && t.push(n);
1995
1995
  } catch {}
1996
1996
  return t;
1997
1997
  }
1998
- var H;
1999
- async function Hn() {
2000
- return H ||= (async () => {
2001
- let [e, t] = await Promise.all([import("zxing-wasm/reader"), Nn()]);
1998
+ var Bn;
1999
+ async function Vn() {
2000
+ return Bn ||= (async () => {
2001
+ let [e, t] = await Promise.all([import("zxing-wasm/reader"), jn()]);
2002
2002
  return await e.prepareZXingModule({
2003
2003
  overrides: { wasmBinary: t },
2004
2004
  fireImmediately: !0
2005
2005
  }), e;
2006
2006
  })().catch((e) => {
2007
- throw H = void 0, e instanceof Error && e.message, console.error("[exige-scanner] zxing-wasm failed to load", e), new V(e);
2008
- }), H;
2007
+ throw Bn = void 0, e instanceof Error && e.message, console.error("[exige-scanner] zxing-wasm failed to load", e), new U(e);
2008
+ }), Bn;
2009
2009
  }
2010
- async function Un() {
2011
- await Hn();
2010
+ async function Hn() {
2011
+ await Vn();
2012
+ }
2013
+ function Un(e) {
2014
+ let t = e.position;
2015
+ if (!t?.topLeft || !t.topRight || !t.bottomRight || !t.bottomLeft) return;
2016
+ let n = {
2017
+ topLeft: {
2018
+ x: t.topLeft.x,
2019
+ y: t.topLeft.y
2020
+ },
2021
+ topRight: {
2022
+ x: t.topRight.x,
2023
+ y: t.topRight.y
2024
+ },
2025
+ bottomRight: {
2026
+ x: t.bottomRight.x,
2027
+ y: t.bottomRight.y
2028
+ },
2029
+ bottomLeft: {
2030
+ x: t.bottomLeft.x,
2031
+ y: t.bottomLeft.y
2032
+ }
2033
+ }, r = [
2034
+ n.topLeft.x,
2035
+ n.topRight.x,
2036
+ n.bottomRight.x,
2037
+ n.bottomLeft.x
2038
+ ], i = [
2039
+ n.topLeft.y,
2040
+ n.topRight.y,
2041
+ n.bottomRight.y,
2042
+ n.bottomLeft.y
2043
+ ];
2044
+ if (!(Math.max(...r) - Math.min(...r) < 2 || Math.max(...i) - Math.min(...i) < 2)) return n;
2012
2045
  }
2013
- async function Wn(e) {
2014
- let { readBarcodes: t } = await Hn();
2015
- for (let n of await Vn(e)) {
2046
+ function Wn(e) {
2047
+ return {
2048
+ ...e,
2049
+ edges: {
2050
+ top: {
2051
+ start: e.topLeft,
2052
+ end: e.topRight
2053
+ },
2054
+ right: {
2055
+ start: e.topRight,
2056
+ end: e.bottomRight
2057
+ },
2058
+ bottom: {
2059
+ start: e.bottomRight,
2060
+ end: e.bottomLeft
2061
+ },
2062
+ left: {
2063
+ start: e.bottomLeft,
2064
+ end: e.topLeft
2065
+ }
2066
+ }
2067
+ };
2068
+ }
2069
+ function W(e, t) {
2070
+ let n = t.scale > 0 ? t.scale : 1;
2071
+ return {
2072
+ x: t.originX + e.x / n,
2073
+ y: t.originY + e.y / n
2074
+ };
2075
+ }
2076
+ function Gn(e, t) {
2077
+ return {
2078
+ topLeft: W(e.topLeft, t),
2079
+ topRight: W(e.topRight, t),
2080
+ bottomRight: W(e.bottomRight, t),
2081
+ bottomLeft: W(e.bottomLeft, t)
2082
+ };
2083
+ }
2084
+ async function Kn(e) {
2085
+ let { readBarcodes: t } = await Vn();
2086
+ for (let n of await zn(e)) {
2016
2087
  let e = (await t(n, {
2017
2088
  formats: ["PDF417"],
2018
2089
  tryHarder: !0,
@@ -2022,11 +2093,14 @@ async function Wn(e) {
2022
2093
  downscaleFactor: 2,
2023
2094
  downscaleThreshold: 300,
2024
2095
  maxNumberOfSymbols: 1
2025
- })).find((e) => e.text?.trim())?.text?.trim();
2026
- if (e) return e;
2096
+ })).find((e) => e.text?.trim()), r = e?.text?.trim();
2097
+ if (r) return {
2098
+ text: r,
2099
+ position: Un(e ?? {})
2100
+ };
2027
2101
  }
2028
2102
  }
2029
- function U(e, t) {
2103
+ function qn(e, t) {
2030
2104
  let n = Math.max(e.width, e.height);
2031
2105
  if (n <= t) return e;
2032
2106
  let r = t / n, i = document.createElement("canvas");
@@ -2034,67 +2108,78 @@ function U(e, t) {
2034
2108
  let a = i.getContext("2d", { willReadFrequently: !0 }) ?? i.getContext("2d");
2035
2109
  return a && (a.imageSmoothingEnabled = !0, "imageSmoothingQuality" in a && (a.imageSmoothingQuality = "high"), a.drawImage(e, 0, 0, i.width, i.height)), i;
2036
2110
  }
2037
- function Gn(e, t, n) {
2111
+ function Jn(e, t, n) {
2038
2112
  let r = Math.max(0, Math.round(e.height * t)), i = Math.max(1, Math.round(e.height * n) - r), a = document.createElement("canvas");
2039
2113
  a.width = e.width, a.height = i;
2040
2114
  let o = a.getContext("2d", { willReadFrequently: !0 }) ?? a.getContext("2d");
2041
2115
  return o && o.drawImage(e, 0, r, e.width, i, 0, 0, e.width, i), a;
2042
2116
  }
2043
- function Kn(e) {
2044
- return Ln(e.width, e.height).map((t) => U(e, t));
2045
- }
2046
- function qn(e) {
2047
- if (e.height < e.width * 1.15 || e.height < 120) return [];
2048
- let t = [];
2049
- for (let [n, r] of In) {
2050
- let i = Gn(e, n, r);
2051
- t.push(U(i, Pn));
2052
- let a = Ln(i.width, i.height).find((e) => e <= 960);
2053
- a && t.push(U(i, a));
2054
- }
2055
- return t;
2117
+ function Yn(e, t, n = 0, r = 0) {
2118
+ let i = Math.max(e.width, e.height);
2119
+ return i <= t ? {
2120
+ canvas: e,
2121
+ originX: n,
2122
+ originY: r,
2123
+ scale: 1
2124
+ } : {
2125
+ canvas: qn(e, t),
2126
+ originX: n,
2127
+ originY: r,
2128
+ scale: t / i
2129
+ };
2056
2130
  }
2057
- function Jn(e) {
2058
- let t = /* @__PURE__ */ new Set(), n = [];
2059
- for (let r of [...qn(e), ...Kn(e)]) {
2060
- let e = `${r.width}x${r.height}`;
2061
- t.has(e) || (t.add(e), n.push(r));
2131
+ function Xn(e) {
2132
+ let t = /* @__PURE__ */ new Set(), n = [], r = (e) => {
2133
+ let r = `${e.canvas.width}x${e.canvas.height}@${e.originX},${e.originY},${e.scale}`;
2134
+ t.has(r) || (t.add(r), n.push(e));
2135
+ };
2136
+ if (e.height >= e.width * 1.15 && e.height >= 120) for (let [t, n] of Pn) {
2137
+ let i = Math.max(0, Math.round(e.height * t)), a = Jn(e, t, n);
2138
+ r(Yn(a, Mn, 0, i));
2139
+ let o = Fn(a.width, a.height).find((e) => e <= 960);
2140
+ o && r(Yn(a, o, 0, i));
2062
2141
  }
2142
+ for (let t of Fn(e.width, e.height)) r(Yn(e, t));
2063
2143
  return n;
2064
2144
  }
2065
- async function W(e) {
2145
+ async function Zn(e) {
2066
2146
  let t;
2067
2147
  try {
2068
- t = await N(e, { cloneCanvas: !1 });
2148
+ t = await P(e, { cloneCanvas: !1 });
2069
2149
  } catch {
2070
2150
  t = e instanceof HTMLCanvasElement ? e : document.createElement("canvas");
2071
2151
  }
2072
- let n = t.width && t.height ? Jn(t) : [];
2152
+ let n = t.width && t.height ? Xn(t) : [];
2073
2153
  for (let e of n) try {
2074
- let t = await Wn(e);
2075
- if (t) return {
2076
- text: t,
2077
- source: "zxing-wasm"
2078
- };
2154
+ let t = await Kn(e.canvas);
2155
+ if (t?.text) {
2156
+ let n = t.position ? Gn(t.position, e) : void 0;
2157
+ return {
2158
+ text: t.text,
2159
+ source: "zxing-wasm",
2160
+ quad: n ? Wn(n) : void 0
2161
+ };
2162
+ }
2079
2163
  } catch (e) {
2080
- if (e instanceof V) throw e;
2164
+ if (e instanceof U) throw e;
2081
2165
  }
2082
2166
  if (e instanceof Blob) try {
2083
- let t = await Wn(e);
2084
- return t ? {
2085
- text: t,
2086
- source: "zxing-wasm"
2167
+ let t = await Kn(e);
2168
+ return t?.text ? {
2169
+ text: t.text,
2170
+ source: "zxing-wasm",
2171
+ quad: t.position ? Wn(t.position) : void 0
2087
2172
  } : void 0;
2088
2173
  } catch (e) {
2089
- if (e instanceof V) throw e;
2174
+ if (e instanceof U) throw e;
2090
2175
  return;
2091
2176
  }
2092
2177
  }
2093
- var G = new Set(/* @__PURE__ */ "DCA.DCB.DCD.DBA.DCS.DAC.DAD.DBD.DBB.DBC.DAY.DAU.DAG.DAI.DAJ.DAK.DAQ.DCF.DCG.DDE.DDF.DDG.DAH.DAZ.DCI.DCJ.DCK.DBN.DBG.DBS.DCU.DCE.DCL.DCM.DCN.DCO.DCP.DCQ.DCR.DDA.DDB.DDC.DDD.DAW.DAX.DDH.DDI.DDJ.DDK.DDL.DCT.DAL.DAM.DAN.DAO.DAR.DAS.DAT.DAV.DBH.DBI.DBJ.DBK.DBL.DBM.DCH".split(".")), Yn = /* @__PURE__ */ "issuerJurisdiction.expirationDate.documentNumber.firstName.middleName.lastName.dateOfBirth.sex.eyeColor.height.addressStreet.addressCity.addressPostalCode.issueDate.country.addressStreet2.hairColor.nameSuffix.vehicleClass.restrictionCodes.endorsementCodes.documentDiscriminator.inventoryControlNumber.raceEthnicity.organDonor.veteran.weight".split("."), Xn = /* @__PURE__ */ new Set([
2178
+ var G = new Set(/* @__PURE__ */ "DCA.DCB.DCD.DBA.DCS.DAC.DAD.DBD.DBB.DBC.DAY.DAU.DAG.DAI.DAJ.DAK.DAQ.DCF.DCG.DDE.DDF.DDG.DAH.DAZ.DCI.DCJ.DCK.DBN.DBG.DBS.DCU.DCE.DCL.DCM.DCN.DCO.DCP.DCQ.DCR.DDA.DDB.DDC.DDD.DAW.DAX.DDH.DDI.DDJ.DDK.DDL.DCT.DAL.DAM.DAN.DAO.DAR.DAS.DAT.DAV.DBH.DBI.DBJ.DBK.DBL.DBM.DCH".split(".")), Qn = /* @__PURE__ */ "issuerJurisdiction.expirationDate.documentNumber.firstName.middleName.lastName.dateOfBirth.sex.eyeColor.height.addressStreet.addressCity.addressPostalCode.issueDate.country.addressStreet2.hairColor.nameSuffix.vehicleClass.restrictionCodes.endorsementCodes.documentDiscriminator.inventoryControlNumber.raceEthnicity.organDonor.veteran.weight".split("."), $n = /* @__PURE__ */ new Set([
2094
2179
  "expirationDate",
2095
2180
  "dateOfBirth",
2096
2181
  "issueDate"
2097
- ]), Zn = {
2182
+ ]), er = {
2098
2183
  DAJ: "issuerJurisdiction",
2099
2184
  DBA: "expirationDate",
2100
2185
  DAQ: "documentNumber",
@@ -2130,16 +2215,16 @@ function K(e, t, n) {
2130
2215
  let r = Number(e), i = Number(t), a = Number(n);
2131
2216
  if (Number.isInteger(r) && Number.isInteger(i) && Number.isInteger(a) && !(r < 1900 || r > 2100 || i < 1 || i > 12 || a < 1 || a > 31)) return `${String(r).padStart(4, "0")}-${String(i).padStart(2, "0")}-${String(a).padStart(2, "0")}`;
2132
2217
  }
2133
- function Qn(e, t) {
2218
+ function tr(e, t) {
2134
2219
  return t ? e >= 30 ? 1900 + e : 2e3 + e : e >= 50 ? 1900 + e : 2e3 + e;
2135
2220
  }
2136
- function q(e, t = !1) {
2221
+ function nr(e, t = !1) {
2137
2222
  let n = e.trim();
2138
2223
  if (!n) return;
2139
2224
  let r = /^(\d{1,2})[/-](\d{1,2})[/-](\d{2,4})$/.exec(n);
2140
2225
  if (r) {
2141
2226
  let e = r[1], n = r[2], i = r[3];
2142
- return i.length === 2 && (i = String(Qn(Number(i), t))), K(i, e.padStart(2, "0"), n.padStart(2, "0"));
2227
+ return i.length === 2 && (i = String(tr(Number(i), t))), K(i, e.padStart(2, "0"), n.padStart(2, "0"));
2143
2228
  }
2144
2229
  let i = /^(\d{4})-(\d{2})-(\d{2})$/.exec(n);
2145
2230
  if (i) return K(i[1], i[2], i[3]);
@@ -2149,11 +2234,11 @@ function q(e, t = !1) {
2149
2234
  return e >= 1900 && e <= 2100 ? K(a.slice(0, 4), a.slice(4, 6), a.slice(6, 8)) : K(a.slice(4, 8), a.slice(0, 2), a.slice(2, 4));
2150
2235
  }
2151
2236
  if (a.length === 6) {
2152
- let e = Qn(Number(a.slice(4, 6)), t);
2237
+ let e = tr(Number(a.slice(4, 6)), t);
2153
2238
  return K(String(e), a.slice(0, 2), a.slice(2, 4));
2154
2239
  }
2155
2240
  }
2156
- function $n(e) {
2241
+ function rr(e) {
2157
2242
  let t = e.trim();
2158
2243
  if (!t || t === "@") return "";
2159
2244
  if (/^(ANSI|AAMVA)\b/.test(t)) {
@@ -2162,10 +2247,10 @@ function $n(e) {
2162
2247
  }
2163
2248
  return t;
2164
2249
  }
2165
- function er(e) {
2250
+ function ir(e) {
2166
2251
  return (e.startsWith("DL") || e.startsWith("ID") || e.startsWith("ZV")) && e.length >= 5 && G.has(e.slice(2, 5)) ? e.slice(2) : e;
2167
2252
  }
2168
- function tr(e, t) {
2253
+ function ar(e, t) {
2169
2254
  let n = 0;
2170
2255
  for (; n < e.length;) {
2171
2256
  let r = e.slice(n, n + 3);
@@ -2184,7 +2269,7 @@ function tr(e, t) {
2184
2269
  (!(r in t) || a) && (t[r] = a), n = i, (e[n] === "\n" || e[n] === "\r" || e[n] === "") && (n += 1);
2185
2270
  }
2186
2271
  }
2187
- function nr(e) {
2272
+ function or(e) {
2188
2273
  let t = /(?:ANSI|AAMVA)\s?(\d{6})(\d{2})(\d{2})(\d{2})/.exec(e);
2189
2274
  if (t) return {
2190
2275
  iin: t[1],
@@ -2192,22 +2277,22 @@ function nr(e) {
2192
2277
  jurisdictionVersion: t[3]
2193
2278
  };
2194
2279
  }
2195
- function rr(e) {
2280
+ function sr(e) {
2196
2281
  let t = e.replace(/\r\n/g, "\n").replace(/\r/g, "\n"), n = {}, r = t.split("\n").flatMap((e) => e.split(""));
2197
2282
  if (r.some((e) => {
2198
- let t = er($n(e));
2283
+ let t = ir(rr(e));
2199
2284
  return G.has(t.slice(0, 3));
2200
2285
  })) {
2201
2286
  for (let e of r) {
2202
- let t = er($n(e));
2203
- t && tr(t, n);
2287
+ let t = ir(rr(e));
2288
+ t && ar(t, n);
2204
2289
  }
2205
2290
  return n;
2206
2291
  }
2207
- return tr(t, n), n;
2292
+ return ar(t, n), n;
2208
2293
  }
2209
- function ir(e, t) {
2210
- if (Xn.has(t)) return q(e, t === "dateOfBirth") ?? e.trim();
2294
+ function cr(e, t) {
2295
+ if ($n.has(t)) return nr(e, t === "dateOfBirth") ?? e.trim();
2211
2296
  if (t === "issuerJurisdiction" || t === "country") return e.trim().toUpperCase();
2212
2297
  if (t === "addressPostalCode") {
2213
2298
  let t = e.trim();
@@ -2215,11 +2300,11 @@ function ir(e, t) {
2215
2300
  }
2216
2301
  return e.trim();
2217
2302
  }
2218
- function ar(e) {
2303
+ function lr(e) {
2219
2304
  let t = {};
2220
2305
  for (let [n, r] of Object.entries(e)) {
2221
- let e = Zn[n];
2222
- e && r.trim() && (t[e] || (t[e] = ir(r, e)));
2306
+ let e = er[n];
2307
+ e && r.trim() && (t[e] || (t[e] = cr(r, e)));
2223
2308
  }
2224
2309
  if (!t.firstName && e.DCT?.trim()) {
2225
2310
  let n = e.DCT.trim().split(/\s+/);
@@ -2227,29 +2312,29 @@ function ar(e) {
2227
2312
  }
2228
2313
  return t;
2229
2314
  }
2230
- function or(e) {
2231
- let t = rr(e);
2315
+ function ur(e) {
2316
+ let t = sr(e);
2232
2317
  return {
2233
2318
  rawElements: t,
2234
- fields: ar(t),
2235
- header: nr(e)
2319
+ fields: lr(t),
2320
+ header: or(e)
2236
2321
  };
2237
2322
  }
2238
- function sr() {
2323
+ function dr() {
2239
2324
  return {};
2240
2325
  }
2241
- function cr(e, t, n) {
2242
- for (let r of Yn) t[r] && (e[r] = n);
2326
+ function fr(e, t, n) {
2327
+ for (let r of Qn) t[r] && (e[r] = n);
2243
2328
  return e;
2244
2329
  }
2245
2330
  //#endregion
2246
2331
  //#region src/sdk/face-model.ts
2247
- var lr = /* @__PURE__ */ new Map(), ur = 8400;
2248
- function dr(e, t) {
2332
+ var pr = /* @__PURE__ */ new Map(), mr = 8400;
2333
+ function hr(e, t) {
2249
2334
  let n = Math.max(0, Math.min(e.x + e.width, t.x + t.width) - Math.max(e.x, t.x)) * Math.max(0, Math.min(e.y + e.height, t.y + t.height) - Math.max(e.y, t.y));
2250
2335
  return n / Math.max(1, e.width * e.height + t.width * t.height - n);
2251
2336
  }
2252
- function fr(e, t, n, r, i, a, o) {
2337
+ function gr(e, t, n, r, i, a, o) {
2253
2338
  return {
2254
2339
  x: (e - n / 2) / i * a,
2255
2340
  y: (t - r / 2) / i * o,
@@ -2257,39 +2342,39 @@ function fr(e, t, n, r, i, a, o) {
2257
2342
  height: r / i * o
2258
2343
  };
2259
2344
  }
2260
- function pr(e, t, n) {
2345
+ function _r(e, t, n) {
2261
2346
  let r = t.length === 3 ? t[1] : t[0], i = t.length === 3 ? t[2] : t[1];
2262
- if (i !== 6 || r < 1) throw Error(`Face model expects [1, anchors, 6]. A 640 YOLOX-Nano face export is [1, ${ur}, 6].`);
2347
+ if (i !== 6 || r < 1) throw Error(`Face model expects [1, anchors, 6]. A 640 YOLOX-Nano face export is [1, ${mr}, 6].`);
2263
2348
  let a = n.confidence ?? .35, o = n.inputSize ?? 640, s = [];
2264
2349
  for (let t = 0; t < r; t += 1) {
2265
2350
  let r = t * i, c = e[r + 4] * e[r + 5];
2266
2351
  c < a || s.push({
2267
2352
  confidence: c,
2268
- bbox: fr(e[r], e[r + 1], e[r + 2], e[r + 3], o, n.imageWidth, n.imageHeight)
2353
+ bbox: gr(e[r], e[r + 1], e[r + 2], e[r + 3], o, n.imageWidth, n.imageHeight)
2269
2354
  });
2270
2355
  }
2271
- return s.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => dr(e.bbox, t.bbox) < .45)).slice(0, 8);
2356
+ return s.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => hr(e.bbox, t.bbox) < .45)).slice(0, 8);
2272
2357
  }
2273
- async function mr(e, n, r = .35) {
2274
- let i = await N(e, { cloneCanvas: !1 }), a = await import("onnxruntime-web"), o = document.createElement("canvas");
2358
+ async function vr(e, n, r = .35) {
2359
+ let i = await P(e, { cloneCanvas: !1 }), a = await import("onnxruntime-web"), o = document.createElement("canvas");
2275
2360
  o.width = 640, o.height = 640;
2276
2361
  let s = o.getContext("2d", { willReadFrequently: !0 });
2277
2362
  if (!s) throw t();
2278
2363
  s.drawImage(i, 0, 0, 640, 640);
2279
2364
  let c = s.getImageData(0, 0, 640, 640).data, l = 409600, u = new Float32Array(l * 3);
2280
2365
  for (let e = 0; e < l; e += 1) u[e] = c[e * 4] / 255, u[l + e] = c[e * 4 + 1] / 255, u[l * 2 + e] = c[e * 4 + 2] / 255;
2281
- let d = lr.get(n);
2366
+ let d = pr.get(n);
2282
2367
  d || (d = a.InferenceSession.create(n, {
2283
2368
  executionProviders: ["wasm"],
2284
2369
  graphOptimizationLevel: "all"
2285
- }), lr.set(n, d));
2370
+ }), pr.set(n, d));
2286
2371
  let f = await d, p = (await f.run({ [f.inputNames[0]]: new a.Tensor("float32", u, [
2287
2372
  1,
2288
2373
  3,
2289
2374
  640,
2290
2375
  640
2291
2376
  ]) }))[f.outputNames[0]];
2292
- return pr(p.data, p.dims.map(Number), {
2377
+ return _r(p.data, p.dims.map(Number), {
2293
2378
  confidence: r,
2294
2379
  imageWidth: i.width,
2295
2380
  imageHeight: i.height,
@@ -2298,7 +2383,7 @@ async function mr(e, n, r = .35) {
2298
2383
  }
2299
2384
  //#endregion
2300
2385
  //#region src/sdk/field-model.ts
2301
- var hr = /* @__PURE__ */ new Map(), gr = [
2386
+ var yr = /* @__PURE__ */ new Map(), br = [
2302
2387
  "person_name",
2303
2388
  "date_of_birth",
2304
2389
  "address",
@@ -2306,19 +2391,19 @@ var hr = /* @__PURE__ */ new Map(), gr = [
2306
2391
  "expiration_date",
2307
2392
  "postal_code",
2308
2393
  "state"
2309
- ], _r = 8400;
2310
- function vr(e) {
2394
+ ], xr = 8400;
2395
+ function Sr(e) {
2311
2396
  return 5 + e;
2312
2397
  }
2313
- var yr = 640;
2314
- function br(e, t) {
2398
+ var Cr = 640;
2399
+ function wr(e, t) {
2315
2400
  let n = Math.max(0, Math.min(e.bbox.x + e.bbox.width, t.bbox.x + t.bbox.width) - Math.max(e.bbox.x, t.bbox.x)) * Math.max(0, Math.min(e.bbox.y + e.bbox.height, t.bbox.y + t.bbox.height) - Math.max(e.bbox.y, t.bbox.y));
2316
2401
  return n / Math.max(1, e.bbox.width * e.bbox.height + t.bbox.width * t.bbox.height - n);
2317
2402
  }
2318
- function xr(e) {
2319
- return e.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => t.field !== e.field || br(e, t) < .45)).slice(0, 30);
2403
+ function Tr(e) {
2404
+ return e.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => t.field !== e.field || wr(e, t) < .45)).slice(0, 30);
2320
2405
  }
2321
- function Sr(e, t, n, r, i, a, o) {
2406
+ function Er(e, t, n, r, i, a, o) {
2322
2407
  return {
2323
2408
  x: (e - n / 2) / i * a,
2324
2409
  y: (t - r / 2) / i * o,
@@ -2326,8 +2411,8 @@ function Sr(e, t, n, r, i, a, o) {
2326
2411
  height: r / i * o
2327
2412
  };
2328
2413
  }
2329
- function Cr(e, t) {
2330
- let n = vr(t);
2414
+ function Dr(e, t) {
2415
+ let n = Sr(t);
2331
2416
  return e.length === 3 && e[0] === 1 && e[2] === n && e[1] > e[2] ? {
2332
2417
  anchors: e[1],
2333
2418
  features: n
@@ -2336,15 +2421,15 @@ function Cr(e, t) {
2336
2421
  features: n
2337
2422
  } : null;
2338
2423
  }
2339
- function wr(e) {
2424
+ function Or(e) {
2340
2425
  return e.length === 3 && e[1] >= 5 && e[2] >= 1;
2341
2426
  }
2342
- function Tr(e) {
2343
- let t = vr(e);
2344
- return /* @__PURE__ */ Error(`YOLOX field layout expects [1, anchors, ${t}] (cx, cy, w, h, objectness, ${e} class scores). A 640 YOLOX-Nano export with decode baked in is [1, ${_r}, ${t}].`);
2427
+ function kr(e) {
2428
+ let t = Sr(e);
2429
+ return /* @__PURE__ */ Error(`YOLOX field layout expects [1, anchors, ${t}] (cx, cy, w, h, objectness, ${e} class scores). A 640 YOLOX-Nano export with decode baked in is [1, ${xr}, ${t}].`);
2345
2430
  }
2346
- function Er(e, t, n, r, i, a, o) {
2347
- if (!wr(t)) throw Error("Unsupported field-model YOLO output shape.");
2431
+ function Ar(e, t, n, r, i, a, o) {
2432
+ if (!Or(t)) throw Error("Unsupported field-model YOLO output shape.");
2348
2433
  let s = t[1], c = t[2], l = [];
2349
2434
  for (let t = 0; t < c; t += 1) {
2350
2435
  let u = 0, d = 0;
@@ -2356,14 +2441,14 @@ function Er(e, t, n, r, i, a, o) {
2356
2441
  !f || u < r || l.push({
2357
2442
  field: f,
2358
2443
  confidence: u,
2359
- bbox: Sr(e[t], e[c + t], e[c * 2 + t], e[c * 3 + t], i, a, o)
2444
+ bbox: Er(e[t], e[c + t], e[c * 2 + t], e[c * 3 + t], i, a, o)
2360
2445
  });
2361
2446
  }
2362
- return xr(l);
2447
+ return Tr(l);
2363
2448
  }
2364
- function Dr(e, t, n, r, i, a, o) {
2365
- let s = Cr(t, n.length);
2366
- if (!s) throw Tr(n.length);
2449
+ function jr(e, t, n, r, i, a, o) {
2450
+ let s = Dr(t, n.length);
2451
+ if (!s) throw kr(n.length);
2367
2452
  let c = [];
2368
2453
  for (let t = 0; t < s.anchors; t += 1) {
2369
2454
  let l = t * s.features, u = e[l + 4], d = 0, f = 0;
@@ -2375,43 +2460,43 @@ function Dr(e, t, n, r, i, a, o) {
2375
2460
  !p || m < r || c.push({
2376
2461
  field: p,
2377
2462
  confidence: m,
2378
- bbox: Sr(e[l], e[l + 1], e[l + 2], e[l + 3], i, a, o)
2463
+ bbox: Er(e[l], e[l + 1], e[l + 2], e[l + 3], i, a, o)
2379
2464
  });
2380
2465
  }
2381
- return xr(c);
2466
+ return Tr(c);
2382
2467
  }
2383
- function Or(e, t, n) {
2384
- let r = n.classes ?? gr, i = n.confidence ?? .35, a = n.inputSize ?? yr, o = Cr(t, r.length);
2468
+ function Mr(e, t, n) {
2469
+ let r = n.classes ?? br, i = n.confidence ?? .35, a = n.inputSize ?? Cr, o = Dr(t, r.length);
2385
2470
  if (n.layout === "yolov8" && o) throw Error("This tensor is YOLOX [1, anchors, 5+classes]. Pass fieldLayout: 'yolox', or omit fieldLayout to detect it from the shape.");
2386
- return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ? Dr(e, t, r, i, a, n.imageWidth, n.imageHeight) : Er(e, t, r, i, a, n.imageWidth, n.imageHeight);
2471
+ return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ? jr(e, t, r, i, a, n.imageWidth, n.imageHeight) : Ar(e, t, r, i, a, n.imageWidth, n.imageHeight);
2387
2472
  }
2388
- async function kr(e, n, r = gr, i = .35, a) {
2389
- let o = await N(e, { cloneCanvas: !1 }), s = import("onnxruntime-web"), c = yr, l = document.createElement("canvas");
2473
+ async function Nr(e, n, r = br, i = .35, a) {
2474
+ let o = await P(e, { cloneCanvas: !1 }), s = import("onnxruntime-web"), c = Cr, l = document.createElement("canvas");
2390
2475
  l.width = c, l.height = c;
2391
2476
  let u = l.getContext("2d", { willReadFrequently: !0 });
2392
2477
  if (!u) throw t();
2393
2478
  u.drawImage(o, 0, 0, c, c);
2394
2479
  let d = u.getImageData(0, 0, c, c).data, f = c * c, p = new Float32Array(f * 3);
2395
2480
  for (let e = 0; e < f; e += 1) p[e] = d[e * 4] / 255, p[f + e] = d[e * 4 + 1] / 255, p[f * 2 + e] = d[e * 4 + 2] / 255;
2396
- let m = hr.get(n);
2481
+ let m = yr.get(n);
2397
2482
  m || (m = (async () => {
2398
2483
  try {
2399
- let [e, t] = await Promise.all([s, se(n)]);
2484
+ let [e, t] = await Promise.all([s, oe(n)]);
2400
2485
  return await e.InferenceSession.create(t, {
2401
2486
  executionProviders: ["wasm"],
2402
2487
  graphOptimizationLevel: "all"
2403
2488
  });
2404
2489
  } catch (e) {
2405
- throw hr.delete(n), e;
2490
+ throw yr.delete(n), e;
2406
2491
  }
2407
- })(), hr.set(n, m));
2492
+ })(), yr.set(n, m));
2408
2493
  let [h, g] = await Promise.all([s, m]), _ = (await g.run({ [g.inputNames[0]]: new h.Tensor("float32", p, [
2409
2494
  1,
2410
2495
  3,
2411
2496
  c,
2412
2497
  c
2413
2498
  ]) }))[g.outputNames[0]];
2414
- return Or(_.data, _.dims.map(Number), {
2499
+ return Mr(_.data, _.dims.map(Number), {
2415
2500
  classes: r,
2416
2501
  confidence: i,
2417
2502
  layout: a,
@@ -2422,12 +2507,12 @@ async function kr(e, n, r = gr, i = .35, a) {
2422
2507
  }
2423
2508
  //#endregion
2424
2509
  //#region src/sdk/redact.ts
2425
- async function Ar(e, n, r = {}) {
2510
+ async function Pr(e, n, r = {}) {
2426
2511
  await x("redaction");
2427
- let i = await N(e), a = i.getContext("2d");
2512
+ let i = await P(e), a = i.getContext("2d");
2428
2513
  if (!a) throw t();
2429
2514
  for (let e of n) {
2430
- let t = Xe(e, i.width, i.height);
2515
+ let t = Ye(e, i.width, i.height);
2431
2516
  if (t.width < 1 || t.height < 1) continue;
2432
2517
  if ((e.mode ?? r.mode ?? "blackout") === "blackout") {
2433
2518
  a.fillStyle = "#050706", a.fillRect(t.x, t.y, t.width, t.height);
@@ -2443,12 +2528,12 @@ async function Ar(e, n, r = {}) {
2443
2528
  }
2444
2529
  return {
2445
2530
  canvas: i,
2446
- blob: await Ye(i, r.mimeType ?? "image/png", r.quality)
2531
+ blob: await Je(i, r.mimeType ?? "image/png", r.quality)
2447
2532
  };
2448
2533
  }
2449
2534
  //#endregion
2450
2535
  //#region src/sdk/programmatic-redaction.ts
2451
- function J(e) {
2536
+ function q(e) {
2452
2537
  let t = Math.min(...e.map((e) => e.bbox.x)), n = Math.min(...e.map((e) => e.bbox.y)), r = Math.max(...e.map((e) => e.bbox.x + e.bbox.width)), i = Math.max(...e.map((e) => e.bbox.y + e.bbox.height));
2453
2538
  return {
2454
2539
  x: t,
@@ -2457,11 +2542,11 @@ function J(e) {
2457
2542
  height: i - n
2458
2543
  };
2459
2544
  }
2460
- function jr(e) {
2545
+ function Fr(e) {
2461
2546
  let t = [], n = [...e].sort((e, t) => e.bbox.y + e.bbox.height / 2 - (t.bbox.y + t.bbox.height / 2) || e.bbox.x - t.bbox.x);
2462
2547
  for (let e of n) {
2463
2548
  let n = e.bbox.y + e.bbox.height / 2, r = t.find((t) => {
2464
- let r = J(t), i = r.y + r.height / 2;
2549
+ let r = q(t), i = r.y + r.height / 2;
2465
2550
  return Math.abs(n - i) <= Math.max(e.bbox.height, r.height) * .65;
2466
2551
  });
2467
2552
  r ? r.push(e) : t.push([e]);
@@ -2469,17 +2554,17 @@ function jr(e) {
2469
2554
  return t.map((e) => (e.sort((e, t) => e.bbox.x - t.bbox.x), {
2470
2555
  words: e,
2471
2556
  text: e.map((e) => e.text).join(" "),
2472
- bbox: J(e)
2557
+ bbox: q(e)
2473
2558
  }));
2474
2559
  }
2475
- function Y(e, t, n = !1) {
2560
+ function J(e, t, n = !1) {
2476
2561
  let r = e.trim().replace(/\s+/g, " "), i = n ? r.replace(/[::]\s*$/, "") : r;
2477
2562
  return t ? i.toLocaleLowerCase() : i;
2478
2563
  }
2479
- function X(e) {
2564
+ function Y(e) {
2480
2565
  return e.reduce((e, t) => e + t.confidence, 0) / Math.max(1, e.length);
2481
2566
  }
2482
- function Mr(e, t) {
2567
+ function Ir(e, t) {
2483
2568
  let n = e.mode, r = n === "case-insensitive", i = e.scope ?? "line", a;
2484
2569
  if (n === "regex") {
2485
2570
  let t = e.pattern ?? e.values?.[0];
@@ -2490,14 +2575,14 @@ function Mr(e, t) {
2490
2575
  ruleId: e.id,
2491
2576
  strategy: "string",
2492
2577
  source: "string",
2493
- bbox: J(t),
2578
+ bbox: q(t),
2494
2579
  text: t.map((e) => e.text).join(" "),
2495
- confidence: X(t)
2580
+ confidence: Y(t)
2496
2581
  });
2497
2582
  if (i === "word") {
2498
2583
  for (let e of t) for (let t of e.words) {
2499
- let e = Y(t.text, r);
2500
- (a ? a.test(t.text) : o.some((t) => e === Y(t, r))) && c([t]);
2584
+ let e = J(t.text, r);
2585
+ (a ? a.test(t.text) : o.some((t) => e === J(t, r))) && c([t]);
2501
2586
  }
2502
2587
  return s;
2503
2588
  }
@@ -2507,40 +2592,40 @@ function Mr(e, t) {
2507
2592
  continue;
2508
2593
  }
2509
2594
  for (let t of o) {
2510
- let n = Y(t, r).split(" ");
2595
+ let n = J(t, r).split(" ");
2511
2596
  for (let t = 0; t <= e.words.length - n.length; t += 1) {
2512
2597
  let i = e.words.slice(t, t + n.length);
2513
- i.every((e, t) => Y(e.text, r) === n[t]) && c(i);
2598
+ i.every((e, t) => J(e.text, r) === n[t]) && c(i);
2514
2599
  }
2515
2600
  }
2516
2601
  }
2517
2602
  return s;
2518
2603
  }
2519
- function Nr(e, t) {
2520
- let n = e.labelMode !== "exact", r = Y(e.label, n, !0).split(" ");
2604
+ function Lr(e, t) {
2605
+ let n = e.labelMode !== "exact", r = J(e.label, n, !0).split(" ");
2521
2606
  for (let e of t) for (let t = 0; t <= e.words.length - r.length; t += 1) {
2522
2607
  let i = e.words.slice(t, t + r.length);
2523
- if (i.every((e, t) => Y(e.text, n, !0) === r[t])) return i;
2608
+ if (i.every((e, t) => J(e.text, n, !0) === r[t])) return i;
2524
2609
  }
2525
2610
  }
2526
- function Pr(e, t, n, r, i, a) {
2611
+ function Rr(e, t, n, r, i, a) {
2527
2612
  let o = a.window?.distance ?? .28, s = a.window?.crossAxis ?? .12, c = t.x + t.width / 2, l = t.y + t.height / 2;
2528
2613
  return e.filter((e) => {
2529
2614
  let a = e.bbox.x + e.bbox.width / 2, u = e.bbox.y + e.bbox.height / 2;
2530
2615
  return n === "right" ? e.bbox.x >= t.x + t.width && e.bbox.x - t.x - t.width <= r * o && Math.abs(u - l) <= i * s : n === "left" ? e.bbox.x + e.bbox.width <= t.x && t.x - e.bbox.x - e.bbox.width <= r * o && Math.abs(u - l) <= i * s : n === "below" ? e.bbox.y >= t.y + t.height && e.bbox.y - t.y - t.height <= i * o && Math.abs(a - c) <= r * s : e.bbox.y + e.bbox.height <= t.y && t.y - e.bbox.y - e.bbox.height <= i * o && Math.abs(a - c) <= r * s;
2531
2616
  });
2532
2617
  }
2533
- function Fr(e, t, n, r, i, a = "label") {
2534
- let o = Nr(e, n);
2618
+ function zr(e, t, n, r, i, a = "label") {
2619
+ let o = Lr(e, n);
2535
2620
  if (!o) return [];
2536
- let s = J(o), c = new Set(o), l = t.filter((e) => !c.has(e)), u = e.direction === "any" ? [
2621
+ let s = q(o), c = new Set(o), l = t.filter((e) => !c.has(e)), u = e.direction === "any" ? [
2537
2622
  "right",
2538
2623
  "below",
2539
2624
  "left",
2540
2625
  "above"
2541
2626
  ] : [e.direction], d;
2542
2627
  for (let t of u) {
2543
- let n = jr(Pr(l, s, t, r, i, e));
2628
+ let n = Fr(Rr(l, s, t, r, i, e));
2544
2629
  for (let t of n) {
2545
2630
  if (e.valuePattern && !new RegExp(e.valuePattern, e.patternFlags).test(t.text)) continue;
2546
2631
  let n = t.bbox.x + t.bbox.width / 2, a = t.bbox.y + t.bbox.height / 2, o = s.x + s.width / 2, c = s.y + s.height / 2, l = Math.hypot((n - o) / r, (a - c) / i);
@@ -2556,12 +2641,12 @@ function Fr(e, t, n, r, i, a = "label") {
2556
2641
  ruleId: e.id,
2557
2642
  strategy: a,
2558
2643
  source: a === "template-anchor" ? "template" : "label",
2559
- bbox: J(f),
2644
+ bbox: q(f),
2560
2645
  text: d.words.map((e) => e.text).join(" "),
2561
- confidence: Math.max(0, X(d.words) * (1 - Math.min(.5, d.distance)))
2646
+ confidence: Math.max(0, Y(d.words) * (1 - Math.min(.5, d.distance)))
2562
2647
  }];
2563
2648
  }
2564
- var Ir = {
2649
+ var Br = {
2565
2650
  person_name: [
2566
2651
  "LN",
2567
2652
  "FN",
@@ -2598,32 +2683,32 @@ var Ir = {
2598
2683
  "POSTAL"
2599
2684
  ],
2600
2685
  state: ["STATE", "DAJ"]
2601
- }, Lr = new Set(Object.values(Ir).flat()), Rr = /^(?:\d{2}[/-]\d{2}[/-]\d{2,4}|\d{4}[/-]\d{2}[/-]\d{2}|\d{6}|\d{8})$/, zr = /\b(?:ST|STREET|AVE|AVENUE|RD|ROAD|BLVD|BOULEVARD|LN|LANE|DR|DRIVE|WAY|CT|COURT)\b/i, Br = /\b(?:DRIVER|LICENSE|IDENTIFICATION|CARD|CLASS|SEX|EYES|HEIGHT|RESTRICTIONS)\b/i;
2602
- function Z(e, t) {
2686
+ }, Vr = new Set(Object.values(Br).flat()), Hr = /^(?:\d{2}[/-]\d{2}[/-]\d{2,4}|\d{4}[/-]\d{2}[/-]\d{2}|\d{6}|\d{8})$/, Ur = /\b(?:ST|STREET|AVE|AVENUE|RD|ROAD|BLVD|BOULEVARD|LN|LANE|DR|DRIVE|WAY|CT|COURT)\b/i, Wr = /\b(?:DRIVER|LICENSE|IDENTIFICATION|CARD|CLASS|SEX|EYES|HEIGHT|RESTRICTIONS)\b/i;
2687
+ function X(e, t) {
2603
2688
  let n = t.trim();
2604
- return n ? e === "date_of_birth" || e === "expiration_date" ? Rr.test(n.replace(/\s/g, "")) : e === "postal_code" ? /^(?:\d{5}(?:-\d{4})?|[A-Z]\d[A-Z]\s?\d[A-Z]\d)$/i.test(n) : e === "state" ? /^[A-Z]{2}$/i.test(n) : e === "document_number" ? /^(?=.*\d)[A-Z0-9-]{5,20}$/i.test(n) : e === "person_name" ? !/\d/.test(n) && /^[A-ZÀ-ÖØ-öø-ÿ' -]{3,}$/i.test(n) && !Br.test(n) : /\d/.test(n) && /[A-Z]/i.test(n) : !1;
2689
+ return n ? e === "date_of_birth" || e === "expiration_date" ? Hr.test(n.replace(/\s/g, "")) : e === "postal_code" ? /^(?:\d{5}(?:-\d{4})?|[A-Z]\d[A-Z]\s?\d[A-Z]\d)$/i.test(n) : e === "state" ? /^[A-Z]{2}$/i.test(n) : e === "document_number" ? /^(?=.*\d)[A-Z0-9-]{5,20}$/i.test(n) : e === "person_name" ? !/\d/.test(n) && /^[A-ZÀ-ÖØ-öø-ÿ' -]{3,}$/i.test(n) && !Wr.test(n) : /\d/.test(n) && /[A-Z]/i.test(n) : !1;
2605
2690
  }
2606
- function Q(e, t, n, r, i = 1) {
2691
+ function Z(e, t, n, r, i = 1) {
2607
2692
  return {
2608
2693
  ruleId: e,
2609
2694
  strategy: "semantic",
2610
2695
  source: t,
2611
- bbox: J(n),
2696
+ bbox: q(n),
2612
2697
  text: r ?? n.map((e) => e.text).join(" "),
2613
- confidence: Math.max(0, Math.min(1, X(n) * i))
2698
+ confidence: Math.max(0, Math.min(1, Y(n) * i))
2614
2699
  };
2615
2700
  }
2616
- function Vr(e, t, n) {
2617
- let r = Ir[e], i = [];
2701
+ function Gr(e, t, n) {
2702
+ let r = Br[e], i = [];
2618
2703
  for (let a of n) for (let n = 0; n < a.words.length; n += 1) {
2619
2704
  let o = a.words[n].text.toUpperCase().replace(/[^A-Z0-9]/g, ""), s = r.find((e) => o === e || o.startsWith(e));
2620
2705
  if (!s) continue;
2621
2706
  let c, l;
2622
- o === s ? (c = a.words.slice(n + 1).filter((e) => !Lr.has(e.text.toUpperCase().replace(/[^A-Z0-9]/g, ""))), l = c.map((e) => e.text).join(" ")) : (c = [a.words[n]], l = a.words[n].text.replace(RegExp(`^${s}[:\\s-]*`, "i"), "")), c.length && Z(e, l) && i.push(Q(t, "alias", c, l, .98));
2707
+ o === s ? (c = a.words.slice(n + 1).filter((e) => !Vr.has(e.text.toUpperCase().replace(/[^A-Z0-9]/g, ""))), l = c.map((e) => e.text).join(" ")) : (c = [a.words[n]], l = a.words[n].text.replace(RegExp(`^${s}[:\\s-]*`, "i"), "")), c.length && X(e, l) && i.push(Z(t, "alias", c, l, .98));
2623
2708
  }
2624
2709
  return i;
2625
2710
  }
2626
- function Hr(e, t, n) {
2711
+ function Kr(e, t, n) {
2627
2712
  let r = n.filter((e) => {
2628
2713
  let t = e.text.replace(/\s/g, "");
2629
2714
  return t.includes("<<") || /^[A-Z0-9<]{25,}$/.test(t);
@@ -2633,19 +2718,19 @@ function Hr(e, t, n) {
2633
2718
  let e = r.find((e) => e.text.includes("<<"));
2634
2719
  if (!e) return [];
2635
2720
  let n = e.text.replace(/\s/g, ""), i = /^[PIV]<[A-Z]{3}/.test(n) ? 5 : n.indexOf("<") + 1, a = n.slice(i).replace(/<+/g, " ").trim();
2636
- return a ? [Q(t, "mrz", e.words, a, .96)] : [];
2721
+ return a ? [Z(t, "mrz", e.words, a, .96)] : [];
2637
2722
  }
2638
2723
  if (e === "date_of_birth") for (let e of r) {
2639
2724
  let n = e.text.replace(/\s/g, ""), r = /^\d{6}/.exec(n)?.[0] ?? /^.{13}(\d{6})/.exec(n)?.[1];
2640
- if (r) return [Q(t, "mrz", e.words, r, .96)];
2725
+ if (r) return [Z(t, "mrz", e.words, r, .96)];
2641
2726
  }
2642
2727
  if (e === "document_number") {
2643
2728
  let e = r[0];
2644
- return [Q(t, "mrz", e.words, e.text, .9)];
2729
+ return [Z(t, "mrz", e.words, e.text, .9)];
2645
2730
  }
2646
2731
  return [];
2647
2732
  }
2648
- function Ur(e) {
2733
+ function qr(e) {
2649
2734
  let t = e.replace(/\s/g, ""), n = t.match(/\d{4}/)?.[0];
2650
2735
  if (n) return Number(n);
2651
2736
  let r = t.match(/^\d{2}/)?.[0];
@@ -2653,67 +2738,67 @@ function Ur(e) {
2653
2738
  let i = Number(r);
2654
2739
  return i > (/* @__PURE__ */ new Date()).getFullYear() % 100 ? 1900 + i : 2e3 + i;
2655
2740
  }
2656
- function Wr(e, t, n, r, i) {
2741
+ function Jr(e, t, n, r, i) {
2657
2742
  if (e === "address") {
2658
- let e = r.findIndex((e) => /\d/.test(e.text) && zr.test(e.text));
2743
+ let e = r.findIndex((e) => /\d/.test(e.text) && Ur.test(e.text));
2659
2744
  if (e < 0) return [];
2660
2745
  let n = [...r[e].words], i = r[e + 1];
2661
- return i && /(?:\b[A-Z]{2}\b.*\d{5}|\d{5})/i.test(i.text) && n.push(...i.words), [Q(t, "layout", n, void 0, .76)];
2746
+ return i && /(?:\b[A-Z]{2}\b.*\d{5}|\d{5})/i.test(i.text) && n.push(...i.words), [Z(t, "layout", n, void 0, .76)];
2662
2747
  }
2663
2748
  if (e === "person_name") {
2664
2749
  let e = r.map((e) => {
2665
- let t = e.words.filter((e) => /^[A-ZÀ-ÖØ-öø-ÿ'-]+$/i.test(e.text)), n = e.bbox.y / Math.max(1, i), r = t.length >= 2 && t.length <= 5 && t.length === e.words.length && !Br.test(e.text) && !zr.test(e.text) && !e.text.includes("<"), a = e.text.replace(/[^A-Z]/g, "").length / Math.max(1, e.text.replace(/[^A-Za-z]/g, "").length);
2750
+ let t = e.words.filter((e) => /^[A-ZÀ-ÖØ-öø-ÿ'-]+$/i.test(e.text)), n = e.bbox.y / Math.max(1, i), r = t.length >= 2 && t.length <= 5 && t.length === e.words.length && !Wr.test(e.text) && !Ur.test(e.text) && !e.text.includes("<"), a = e.text.replace(/[^A-Z]/g, "").length / Math.max(1, e.text.replace(/[^A-Za-z]/g, "").length);
2666
2751
  return {
2667
2752
  line: e,
2668
- score: r ? .45 + X(e.words) * .3 + a * .15 + (n < .65 ? .1 : 0) : 0
2753
+ score: r ? .45 + Y(e.words) * .3 + a * .15 + (n < .65 ? .1 : 0) : 0
2669
2754
  };
2670
2755
  }).filter((e) => e.score >= .68).sort((e, t) => t.score - e.score);
2671
- return !e.length || e[1] && e[0].score - e[1].score < .04 ? [] : [Q(t, "layout", e[0].line.words, void 0, e[0].score)];
2756
+ return !e.length || e[1] && e[0].score - e[1].score < .04 ? [] : [Z(t, "layout", e[0].line.words, void 0, e[0].score)];
2672
2757
  }
2673
2758
  if (e === "date_of_birth" || e === "expiration_date") {
2674
- let r = (/* @__PURE__ */ new Date()).getFullYear(), i = n.filter((e) => Rr.test(e.text.replace(/\s/g, ""))).map((e) => ({
2759
+ let r = (/* @__PURE__ */ new Date()).getFullYear(), i = n.filter((e) => Hr.test(e.text.replace(/\s/g, ""))).map((e) => ({
2675
2760
  word: e,
2676
- year: Ur(e.text)
2761
+ year: qr(e.text)
2677
2762
  })).filter((e) => e.year !== void 0), a = e === "date_of_birth" ? i.filter((e) => e.year <= r - 14 && e.year >= r - 120) : i.filter((e) => e.year >= r - 1);
2678
- return a.sort((t, n) => e === "date_of_birth" ? t.year - n.year : n.year - t.year), a.length ? [Q(t, "layout", [a[0].word], void 0, .72)] : [];
2763
+ return a.sort((t, n) => e === "date_of_birth" ? t.year - n.year : n.year - t.year), a.length ? [Z(t, "layout", [a[0].word], void 0, .72)] : [];
2679
2764
  }
2680
2765
  if (e === "postal_code") {
2681
- let r = n.find((t) => Z(e, t.text));
2682
- return r ? [Q(t, "layout", [r], void 0, .78)] : [];
2766
+ let r = n.find((t) => X(e, t.text));
2767
+ return r ? [Z(t, "layout", [r], void 0, .78)] : [];
2683
2768
  }
2684
2769
  if (e === "state") {
2685
- let r = n.filter((t) => Z(e, t.text));
2686
- return r.length === 1 ? [Q(t, "layout", r, void 0, .7)] : [];
2770
+ let r = n.filter((t) => X(e, t.text));
2771
+ return r.length === 1 ? [Z(t, "layout", r, void 0, .7)] : [];
2687
2772
  }
2688
2773
  if (e === "document_number") {
2689
- let r = n.filter((t) => Z(e, t.text));
2690
- return r.sort((e, t) => t.text.length - e.text.length), r.length ? [Q(t, "layout", [r[0]], void 0, .7)] : [];
2774
+ let r = n.filter((t) => X(e, t.text));
2775
+ return r.sort((e, t) => t.text.length - e.text.length), r.length ? [Z(t, "layout", [r[0]], void 0, .7)] : [];
2691
2776
  }
2692
2777
  return [];
2693
2778
  }
2694
- function Gr(e, t) {
2779
+ function Yr(e, t) {
2695
2780
  return Math.max(0, Math.min(e.x + e.width, t.x + t.width) - Math.max(e.x, t.x)) * Math.max(0, Math.min(e.y + e.height, t.y + t.height) - Math.max(e.y, t.y)) / Math.max(1, t.width * t.height);
2696
2781
  }
2697
- function Kr(e, t, n, r) {
2698
- let i = Vr(e.field, e.id, n), a = Hr(e.field, e.id, n);
2699
- return i.length || a.length ? [...i, ...a] : Wr(e.field, e.id, t, n, r);
2782
+ function Xr(e, t, n, r) {
2783
+ let i = Gr(e.field, e.id, n), a = Kr(e.field, e.id, n);
2784
+ return i.length || a.length ? [...i, ...a] : Jr(e.field, e.id, t, n, r);
2700
2785
  }
2701
- function qr(e, t, n) {
2786
+ function Zr(e, t, n) {
2702
2787
  let r = (n ?? []).filter((t) => t.field === e.field).sort((e, t) => t.confidence - e.confidence);
2703
2788
  for (let n of r) {
2704
- let r = t.filter((e) => Gr(n.bbox, e.bbox) >= .3);
2789
+ let r = t.filter((e) => Yr(n.bbox, e.bbox) >= .3);
2705
2790
  if (!r.length) continue;
2706
2791
  let i = r.map((e) => e.text).join(" ");
2707
- if (Z(e.field, i)) return Q(e.id, "model", r, i, n.confidence);
2792
+ if (X(e.field, i)) return Z(e.id, "model", r, i, n.confidence);
2708
2793
  }
2709
2794
  }
2710
- function Jr(e, t, n, r, i, a) {
2711
- let o = Kr(e, t, n, r);
2795
+ function Qr(e, t, n, r, i, a) {
2796
+ let o = Xr(e, t, n, r);
2712
2797
  if (e.detector !== "model" || !a) return o;
2713
- let s = qr(e, t, i);
2798
+ let s = Zr(e, t, i);
2714
2799
  return s ? [s] : [];
2715
2800
  }
2716
- function Yr(e, t, n, r) {
2801
+ function $r(e, t, n, r) {
2717
2802
  let i = (e) => Math.max(0, Math.min(1, e)), a = i(e.rect.x), o = i(e.rect.y);
2718
2803
  return {
2719
2804
  ruleId: `${t}.${e.id}`,
@@ -2728,19 +2813,19 @@ function Yr(e, t, n, r) {
2728
2813
  confidence: 1
2729
2814
  };
2730
2815
  }
2731
- function Xr(e, t) {
2732
- let n = t.imageWidth ?? e?.imageWidth ?? 0, r = t.imageHeight ?? e?.imageHeight ?? 0, i = e?.words ?? [], a = jr(i), o = [], s = [];
2816
+ function ei(e, t) {
2817
+ let n = t.imageWidth ?? e?.imageWidth ?? 0, r = t.imageHeight ?? e?.imageHeight ?? 0, i = e?.words ?? [], a = Fr(i), o = [], s = [];
2733
2818
  for (let e of t.rules) {
2734
- let c = e.strategy === "string" ? Mr(e, a) : e.strategy === "label" ? Fr(e, i, a, n, r) : Jr(e, i, a, r, t.semanticDetections, t.modelRequested === !0);
2819
+ let c = e.strategy === "string" ? Ir(e, a) : e.strategy === "label" ? zr(e, i, a, n, r) : Qr(e, i, a, r, t.semanticDetections, t.modelRequested === !0);
2735
2820
  c.length ? o.push(...c) : s.push(e.id);
2736
2821
  }
2737
2822
  for (let e of t.template?.fields ?? []) {
2738
2823
  let c = `${t.template.id}.${e.id}`;
2739
2824
  if (e.strategy === "rect") {
2740
- n && r ? o.push(Yr(e, t.template.id, n, r)) : s.push(c);
2825
+ n && r ? o.push($r(e, t.template.id, n, r)) : s.push(c);
2741
2826
  continue;
2742
2827
  }
2743
- let l = Fr({
2828
+ let l = zr({
2744
2829
  ...e,
2745
2830
  id: c,
2746
2831
  strategy: "label"
@@ -2758,34 +2843,34 @@ function Xr(e, t) {
2758
2843
  confidence: u
2759
2844
  };
2760
2845
  }
2761
- function Zr(e) {
2846
+ function ti(e) {
2762
2847
  return e.rules.length > 0 || e.template?.fields.some((e) => e.strategy === "anchor") === !0;
2763
2848
  }
2764
- function Qr(e, t = !1) {
2849
+ function ni(e, t = !1) {
2765
2850
  return t && !e.complete ? "unmatched" : e.complete ? "success" : "partial";
2766
2851
  }
2767
- async function $r(e, t) {
2852
+ async function ri(e, t) {
2768
2853
  await x("redaction");
2769
- let n = await N(e, { cloneCanvas: !1 }), r = t.ocr;
2770
- Zr(t) && !r && (r = await bn(n, { includeWords: !0 }));
2854
+ let n = await P(e, { cloneCanvas: !1 }), r = t.ocr;
2855
+ ti(t) && !r && (r = await H(n, { includeWords: !0 }));
2771
2856
  let i = t.semanticDetections, a = t.modelRequested === !0, o = "not-requested", s;
2772
2857
  if (t.models?.fields) try {
2773
- i = await kr(n, t.models.fields, t.models.fieldClasses, t.models.confidence, t.models.fieldLayout), a = !0, o = "loaded";
2858
+ i = await Nr(n, t.models.fields, t.models.fieldClasses, t.models.confidence, t.models.fieldLayout), a = !0, o = "loaded";
2774
2859
  } catch (e) {
2775
2860
  s = e instanceof Error ? e.message : "The field model could not load.";
2776
2861
  let n = t.models.allowHeuristicFallback !== !1;
2777
2862
  a = !n, o = n ? "fallback" : "failed";
2778
2863
  }
2779
- let c = Xr(r, {
2864
+ let c = ei(r, {
2780
2865
  rules: t.rules,
2781
2866
  template: t.template,
2782
2867
  imageWidth: n.width,
2783
2868
  imageHeight: n.height,
2784
2869
  semanticDetections: i,
2785
2870
  modelRequested: a
2786
- }), l = Qr(c, t.requireAll), u = [], d = "not-requested", f;
2871
+ }), l = ni(c, t.requireAll), u = [], d = "not-requested", f;
2787
2872
  if (t.models?.face) try {
2788
- u = await mr(n, t.models.face, t.models.faceConfidence), d = "loaded";
2873
+ u = await vr(n, t.models.face, t.models.faceConfidence), d = "loaded";
2789
2874
  } catch (e) {
2790
2875
  f = e instanceof Error ? e.message : "The face model could not load.", d = "failed";
2791
2876
  }
@@ -2799,7 +2884,7 @@ async function $r(e, t) {
2799
2884
  faceStatus: d,
2800
2885
  faceError: f
2801
2886
  };
2802
- let p = await Ar(n, [...c.matches.map((e) => ({
2887
+ let p = await Pr(n, [...c.matches.map((e) => ({
2803
2888
  ...e.bbox,
2804
2889
  mode: t.style?.mode
2805
2890
  })), ...u.map((e) => ({
@@ -2821,7 +2906,7 @@ async function $r(e, t) {
2821
2906
  }
2822
2907
  //#endregion
2823
2908
  //#region src/sdk/driver-license.ts
2824
- var ei = [
2909
+ var ii = [
2825
2910
  {
2826
2911
  id: "issuerJurisdiction",
2827
2912
  strategy: "semantic",
@@ -2858,11 +2943,11 @@ var ei = [
2858
2943
  field: "person_name"
2859
2944
  }
2860
2945
  ];
2861
- function ti(e, t, n) {
2946
+ function ai(e, t, n) {
2862
2947
  let r = n.trim();
2863
2948
  if (r) {
2864
2949
  if (t === "expirationDate" || t === "dateOfBirth" || t === "issueDate") {
2865
- e[t] = q(r, t === "dateOfBirth") ?? r;
2950
+ e[t] = nr(r, t === "dateOfBirth") ?? r;
2866
2951
  return;
2867
2952
  }
2868
2953
  if (t === "issuerJurisdiction") {
@@ -2872,8 +2957,8 @@ function ti(e, t, n) {
2872
2957
  e[t] = r;
2873
2958
  }
2874
2959
  }
2875
- function ni(e) {
2876
- let t = {}, n = Xr(e, { rules: ei });
2960
+ function Q(e) {
2961
+ let t = {}, n = ei(e, { rules: ii });
2877
2962
  for (let e of n.matches) {
2878
2963
  let n = e.text?.trim();
2879
2964
  if (n) {
@@ -2882,29 +2967,29 @@ function ni(e) {
2882
2967
  !t.firstName && e[0] && (t.firstName = e[0]), !t.lastName && e.length > 1 && (t.lastName = e[e.length - 1]), !t.middleName && e.length > 2 && (t.middleName = e.slice(1, -1).join(" "));
2883
2968
  continue;
2884
2969
  }
2885
- ti(t, e.ruleId, n);
2970
+ ai(t, e.ruleId, n);
2886
2971
  }
2887
2972
  }
2888
2973
  return t;
2889
2974
  }
2890
- function ri(e, t) {
2891
- let n = { ...e }, r = cr(sr(), e, "barcode");
2975
+ function oi(e, t) {
2976
+ let n = { ...e }, r = fr(dr(), e, "barcode");
2892
2977
  for (let [e, i] of Object.entries(t)) i && (n[e] || (n[e] = i, r[e] = "ocr"));
2893
2978
  return {
2894
2979
  fields: n,
2895
2980
  sources: r
2896
2981
  };
2897
2982
  }
2898
- async function ii(e, t, n) {
2899
- return t?.status === "success" && t.corners ? ft(e, t.corners, { maxOutputDimension: n?.maxOutputDimension }) : L(e, n);
2983
+ async function si(e, t, n) {
2984
+ return t?.status === "success" && t.corners ? dt(e, t.corners, { maxOutputDimension: n?.maxOutputDimension }) : R(e, n);
2900
2985
  }
2901
- async function ai(e, t, n) {
2986
+ async function ci(e, t, n) {
2902
2987
  if (!e.width || !e.height) return {
2903
2988
  kind: "retry",
2904
2989
  status: "frontFailed",
2905
2990
  message: "The front photo was empty. Try again."
2906
2991
  };
2907
- let r = await ii(e, t, n);
2992
+ let r = await si(e, t, n);
2908
2993
  if (r.status !== "success" || !r.canvas) return {
2909
2994
  kind: "retry",
2910
2995
  status: "frontFailed",
@@ -2912,7 +2997,7 @@ async function ai(e, t, n) {
2912
2997
  };
2913
2998
  let i;
2914
2999
  try {
2915
- i = await bn(r.canvas, { includeWords: !0 });
3000
+ i = await H(r.canvas, { includeWords: !0 });
2916
3001
  } catch {
2917
3002
  i = void 0;
2918
3003
  }
@@ -2928,7 +3013,7 @@ async function ai(e, t, n) {
2928
3013
  function $() {
2929
3014
  return new DOMException("The barcode scan was cancelled.", "AbortError");
2930
3015
  }
2931
- function oi(e, t) {
3016
+ function li(e, t) {
2932
3017
  return new Promise((n, r) => {
2933
3018
  if (t?.aborted) {
2934
3019
  r($());
@@ -2942,21 +3027,31 @@ function oi(e, t) {
2942
3027
  t?.addEventListener("abort", a, { once: !0 });
2943
3028
  });
2944
3029
  }
2945
- async function si(e, t = {}) {
3030
+ var ui = 1600;
3031
+ function di(e) {
3032
+ return li(ui, e);
3033
+ }
3034
+ async function fi(e, t = {}) {
2946
3035
  let n = t.intervalMs ?? 140;
2947
- for (await Un();;) {
3036
+ for (await Hn();;) {
2948
3037
  if (t.signal?.aborted) throw $();
2949
3038
  try {
2950
3039
  let t = await e();
2951
- if (t?.width && t.height && (await W(t))?.text) return t;
3040
+ if (t?.width && t.height) {
3041
+ let e = await Zn(t);
3042
+ if (e?.text) return {
3043
+ frame: t,
3044
+ quad: e.quad
3045
+ };
3046
+ }
2952
3047
  } catch (e) {
2953
3048
  if (t.signal?.aborted) throw $();
2954
- if (e instanceof DOMException && e.name === "AbortError" || e instanceof V) throw e;
3049
+ if (e instanceof DOMException && e.name === "AbortError" || e instanceof U) throw e;
2955
3050
  }
2956
- await oi(n, t.signal);
3051
+ await li(n, t.signal);
2957
3052
  }
2958
3053
  }
2959
- async function ci(e, t) {
3054
+ async function pi(e, t) {
2960
3055
  if (!e.width || !e.height) return {
2961
3056
  status: "backFailed",
2962
3057
  fields: {},
@@ -2966,23 +3061,23 @@ async function ci(e, t) {
2966
3061
  back: {},
2967
3062
  message: "The back photo was empty. Try again."
2968
3063
  };
2969
- let n = (await W(e))?.text, r = {
3064
+ let n = (await Zn(e))?.text, r = {
2970
3065
  canvas: e,
2971
3066
  barcodeText: n
2972
3067
  };
2973
3068
  if (!n) {
2974
- let e = t.ocr ? ni(t.ocr) : {};
3069
+ let e = t.ocr ? Q(t.ocr) : {};
2975
3070
  return {
2976
3071
  status: "barcodeUnreadable",
2977
3072
  fields: e,
2978
3073
  rawElements: {},
2979
- sources: cr(sr(), e, "ocr"),
3074
+ sources: fr(dr(), e, "ocr"),
2980
3075
  front: t,
2981
3076
  back: r,
2982
3077
  message: "The PDF417 barcode on the back could not be read. Try again."
2983
3078
  };
2984
3079
  }
2985
- let i = or(n), a = t.ocr ? ni(t.ocr) : {}, o = ri(i.fields, a);
3080
+ let i = ur(n), a = t.ocr ? Q(t.ocr) : {}, o = oi(i.fields, a);
2986
3081
  return {
2987
3082
  status: "success",
2988
3083
  fields: o.fields,
@@ -2992,21 +3087,25 @@ async function ci(e, t) {
2992
3087
  back: r
2993
3088
  };
2994
3089
  }
2995
- function li(e) {
3090
+ function mi(e) {
2996
3091
  return e === "back" ? 0 : void 0;
2997
3092
  }
2998
- function ui(e, t) {
3093
+ function hi(e, t) {
2999
3094
  return e === "front" ? {
3000
3095
  title: "Scan a driver’s license",
3001
3096
  headline: "Show the front of the license.",
3002
3097
  detail: t ? "Take a photo of the front. There is no live document guide." : "Place the front of the license in the frame."
3098
+ } : e === "flip" ? {
3099
+ title: "Scan a driver’s license",
3100
+ headline: "Turn your license over and scan the back.",
3101
+ detail: t ? "The PDF417 barcode is on the back. Take a photo of the entire code next." : "The PDF417 barcode is on the back. Hold the whole code in view next."
3003
3102
  } : {
3004
3103
  title: "Scan a driver’s license",
3005
3104
  headline: "Hold the whole barcode in view",
3006
3105
  detail: t ? "Take a photo of the entire PDF417 barcode. There is no document outline." : "Keep the entire PDF417 in the preview. Closer is fine if the whole code is visible."
3007
3106
  };
3008
3107
  }
3009
- async function di(e = {}) {
3108
+ async function gi(e = {}) {
3010
3109
  await x("scan"), await x("ocr");
3011
3110
  let t = "front", n, r = !1;
3012
3111
  return {
@@ -3020,10 +3119,10 @@ async function di(e = {}) {
3020
3119
  message: "This license scan was cancelled."
3021
3120
  };
3022
3121
  if (t === "front") {
3023
- let r = await ai(i, a, e.scan);
3122
+ let r = await ci(i, a, e.scan);
3024
3123
  return r.kind === "need-back" && (n = r.front, t = "back"), r;
3025
3124
  }
3026
- let o = await ci(i, n ?? {});
3125
+ let o = await pi(i, n ?? {});
3027
3126
  return o.status === "backFailed" ? {
3028
3127
  kind: "retry",
3029
3128
  status: "backFailed",
@@ -3039,6 +3138,6 @@ async function di(e = {}) {
3039
3138
  };
3040
3139
  }
3041
3140
  //#endregion
3042
- export { x as $, L as A, ue as B, Ft as C, ft as D, Ze as E, ke as F, de as G, O as H, M as I, Le as J, pe as K, D as L, pt as M, ye as N, dt as O, ve as P, o as Q, le as R, Nt as S, Bt as T, A as U, xe as V, ze as W, ie as X, be as Y, a as Z, It as _, di as a, wt as b, $r as c, or as d, b as et, Pn as f, Ot as g, bn as h, ri as i, mt as j, et as k, Ar as l, zn as m, li as n, e as nt, si as o, W as p, fe as q, ui as r, t as rt, Xr as s, ni as t, y as tt, q as u, Dt as v, Ct as w, Pt as x, Tt as y, Re as z };
3141
+ export { o as $, $e as A, Le as B, Mt as C, Xe as D, zt as E, _e as F, Re as G, xe as H, Oe as I, de as J, ue as K, N as L, pt as M, ft as N, dt as O, ve as P, a as Q, O as R, Nt as S, St as T, be as U, le as V, j as W, ye as X, Ie as Y, ie as Z, Dt as _, gi as a, wt as b, ei as c, nr as d, x as et, ur as f, H as g, Ln as h, oi as i, t as it, R as j, ut as k, ri as l, Zn as m, mi as n, y as nt, fi as o, Mn as p, fe as q, hi as r, e as rt, di as s, Q as t, b as tt, Pr as u, Ft as v, Pt as w, Ct as x, Et as y, ce as z };
3043
3142
 
3044
- //# sourceMappingURL=driver-license-DWQiITx8.js.map
3143
+ //# sourceMappingURL=driver-license-BmeEh0a_.js.map