@exige/web-scanner-sdk 0.2.36 → 0.2.38

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.
@@ -179,12 +179,12 @@ function C() {
179
179
  inflight: /* @__PURE__ */ new Map()
180
180
  }), e[S];
181
181
  }
182
- var w = C().active, T = C().listeners, E = C().cache, D = C().inflight;
183
- function ee(e) {
182
+ var w = C().active, T = C().listeners, ee = C().cache, E = C().inflight;
183
+ function te(e) {
184
184
  let t = Number(e.headers.get("content-length"));
185
185
  return Number.isFinite(t) && t > 0 ? t : null;
186
186
  }
187
- function te() {
187
+ function ne() {
188
188
  if (w.size === 0) return {
189
189
  downloading: !1,
190
190
  loaded: 0,
@@ -198,23 +198,23 @@ function te() {
198
198
  total: n ? t : null
199
199
  };
200
200
  }
201
- function ne() {
202
- let e = te();
201
+ function re() {
202
+ let e = ne();
203
203
  for (let t of T) t(e);
204
204
  }
205
- function re(e) {
206
- return e(te()), T.add(e), () => {
205
+ function ie(e) {
206
+ return e(ne()), T.add(e), () => {
207
207
  T.delete(e);
208
208
  };
209
209
  }
210
- function O(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
- }), ne();
214
+ }), re();
215
215
  }
216
- async function ie(e, t) {
217
- let n = ee(e);
216
+ async function ae(e, t) {
217
+ let n = te(e);
218
218
  if (!e.body) {
219
219
  let r = await e.arrayBuffer();
220
220
  return t?.({
@@ -238,31 +238,31 @@ async function ie(e, t) {
238
238
  total: n
239
239
  }), o.buffer;
240
240
  }
241
- async function ae(t, n) {
242
- let r = E.get(t);
241
+ async function oe(t, n) {
242
+ let r = ee.get(t);
243
243
  if (r) return r.slice(0);
244
- let i = D.get(t);
244
+ let i = E.get(t);
245
245
  if (i) return i.then((e) => e.slice(0));
246
246
  let a = (async () => {
247
- O(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 ie(r, (e) => O(t, e));
253
+ return ae(r, (e) => D(t, e));
254
254
  })();
255
- D.set(t, a);
255
+ E.set(t, a);
256
256
  try {
257
257
  let e = await a;
258
- return E.set(t, e), e.slice(0);
258
+ return ee.set(t, e), e.slice(0);
259
259
  } finally {
260
- D.delete(t), w.has(t) && (w.delete(t), ne());
260
+ E.delete(t), w.has(t) && (w.delete(t), re());
261
261
  }
262
262
  }
263
263
  //#endregion
264
264
  //#region src/sdk/camera.ts
265
- function oe(e, t) {
265
+ function se(e, t) {
266
266
  let { engine: n } = t;
267
267
  return [
268
268
  `${e}:`,
@@ -277,9 +277,9 @@ function oe(e, t) {
277
277
  ` torch: ${t.torch.mode} supported=${t.torch.supported} on=${t.torch.on}`
278
278
  ].join("\n");
279
279
  }
280
- function se(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(oe("shutter", e.shutter)), e.live && t.push(oe("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 se(e) {
296
296
  }
297
297
  return `${t.join("\n")}\n`;
298
298
  }
299
- function k(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 k(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof nav
305
305
  userAgent: e
306
306
  };
307
307
  }
308
- function ce(e) {
308
+ function le(e) {
309
309
  return /Android/i.test(e.userAgent) && !e.iosWebKit;
310
310
  }
311
- function le(e = k()) {
312
- return e.engine === "webkit" && !ce(e);
311
+ function ue(e = O()) {
312
+ return e.engine === "webkit" && !le(e);
313
313
  }
314
- function ue(e = "auto", t = k()) {
315
- return e === "system-camera" || e !== "live" && ce(t);
314
+ function de(e = "auto", t = O()) {
315
+ return e === "system-camera" || e !== "live" && le(t);
316
316
  }
317
- function de(e, t) {
317
+ function fe(e, t) {
318
318
  return t && !e.iosWebKit;
319
319
  }
320
- function fe(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 pe(e) {
328
- let t = fe(e?.imageWidth?.max ?? 0, e?.imageWidth), n = fe(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 me(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 he(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 ge = 10, _e = class {
341
+ var _e = 10, ve = class {
342
342
  on = !1;
343
343
  darkCount = 0;
344
344
  brightCount = 0;
@@ -361,7 +361,7 @@ var ge = 10, _e = class {
361
361
  return this.on;
362
362
  }
363
363
  };
364
- function ve(e, t) {
364
+ function ye(e, t) {
365
365
  return t ? e === "alwaysOn" || e === "alwaysOff" ? {
366
366
  mode: e,
367
367
  supported: !0,
@@ -385,28 +385,31 @@ function ve(e, t) {
385
385
  automatic: e === "auto"
386
386
  };
387
387
  }
388
- function ye(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;
392
392
  for (let r = 0; r < t * 4; r += 4) n += e[r] * .299 + e[r + 1] * .587 + e[r + 2] * .114;
393
393
  return n / t;
394
394
  }
395
- function be(e, t = 10) {
395
+ function k(e) {
396
+ return !e.width || !e.height || A(e, e.width, e.height) <= 10;
397
+ }
398
+ function xe(e, t = 10) {
396
399
  if (e.length < 4) return !0;
397
400
  let n = Math.floor(e.length / 4), r = 0;
398
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);
399
- return ye(e) <= t && r / n < .01;
402
+ return be(e) <= t && r / n < .01;
400
403
  }
401
- function xe(e, t, n) {
404
+ function A(e, t, n) {
402
405
  if (!t || !n) return 0;
403
406
  let r = document.createElement("canvas");
404
407
  r.width = Math.min(32, t), r.height = Math.min(32, n);
405
408
  let i = r.getContext("2d", { willReadFrequently: !0 });
406
- return i ? (i.drawImage(e, 0, 0, r.width, r.height), ye(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;
407
410
  }
408
411
  function Se(e) {
409
- return xe(e, e.width, e.height);
412
+ return A(e, e.width, e.height);
410
413
  }
411
414
  function Ce(e, t = 120) {
412
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 = () => {
@@ -415,7 +418,7 @@ function Ce(e, t = 120) {
415
418
  function f() {
416
419
  if (!a) return;
417
420
  let { videoWidth: i, videoHeight: o } = e, f = performance.now();
418
- r && i && o && f - s >= t && (s = f, l = xe(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();
419
422
  }
420
423
  return d(), {
421
424
  stop() {
@@ -431,10 +434,30 @@ function we(e) {
431
434
  let t = document.createElement("canvas");
432
435
  return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
433
436
  }
434
- function 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
+ let i = document.createElement("canvas");
441
+ i.width = r.width, i.height = r.height;
442
+ let a = i.getContext("2d");
443
+ if (!a) throw t();
444
+ return a.imageSmoothingEnabled = !0, "imageSmoothingQuality" in a && (a.imageSmoothingQuality = "high"), a.drawImage(e, 0, 0, i.width, i.height), i;
445
+ }
446
+ function Ee(e, t, n) {
447
+ try {
448
+ let t = N(e, n);
449
+ if (!k(t)) return t;
450
+ } catch {}
451
+ let r = t.getFrame();
452
+ if (!r) throw Error("The camera is not ready to capture a frame.");
453
+ let i = Te(r, n);
454
+ if (k(i)) throw Error("The camera preview produced no visible pixels.");
455
+ return i;
456
+ }
457
+ function De(e) {
435
458
  return e.engine === "blink";
436
459
  }
437
- function A(e = {}, t = k()) {
460
+ function j(e = {}, t = O()) {
438
461
  let n = { ideal: e.idealWidth ?? 3840 }, r = { ideal: e.idealHeight ?? 2160 };
439
462
  e.maxWidth && (n.max = e.maxWidth), e.maxHeight && (r.max = e.maxHeight);
440
463
  let i = {
@@ -446,20 +469,20 @@ function A(e = {}, t = k()) {
446
469
  max: e.maxFrameRate ?? 30
447
470
  }
448
471
  };
449
- return Te(t) && (i.resizeMode = { ideal: "none" }), {
472
+ return De(t) && (i.resizeMode = { ideal: "none" }), {
450
473
  audio: !1,
451
474
  video: i
452
475
  };
453
476
  }
454
- function Ee(e, t, n) {
477
+ function M(e, t, n) {
455
478
  let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
456
479
  return {
457
480
  width: Math.max(1, Math.round(e * r)),
458
481
  height: Math.max(1, Math.round(t * r))
459
482
  };
460
483
  }
461
- var De = 4096;
462
- function Oe(e, t) {
484
+ var Oe = 4096;
485
+ function ke(e, t) {
463
486
  let n = e.width, r = e.height, i = t?.width?.max, a = t?.height?.max;
464
487
  if (!n || !r || !i || !a) return;
465
488
  let o = Math.min(i / n, a / r);
@@ -468,13 +491,13 @@ function Oe(e, t) {
468
491
  height: { ideal: Math.round(r * o) }
469
492
  };
470
493
  }
471
- async function ke(e) {
472
- let t = Oe(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);
473
496
  if (t) try {
474
497
  await e.applyConstraints(t);
475
498
  } catch {}
476
499
  }
477
- async function Ae(e) {
500
+ async function je(e) {
478
501
  try {
479
502
  return await createImageBitmap(e, {
480
503
  imageOrientation: "from-image",
@@ -484,7 +507,7 @@ async function Ae(e) {
484
507
  return await createImageBitmap(e);
485
508
  }
486
509
  }
487
- async function je(e) {
510
+ async function Me(e) {
488
511
  try {
489
512
  await e.applyConstraints({ advanced: [{ pointsOfInterest: [{
490
513
  x: .5,
@@ -492,25 +515,25 @@ async function je(e) {
492
515
  }] }] }), await new Promise((e) => window.setTimeout(e, 180));
493
516
  } catch {}
494
517
  }
495
- async function Me(e) {
496
- let n = await Ae(e), r = Ee(n.width, n.height, De), 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");
497
520
  i.width = r.width, i.height = r.height;
498
521
  let a = i.getContext("2d");
499
522
  if (!a) throw n.close?.(), t();
500
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;
501
524
  }
502
- async function Ne(e) {
525
+ async function Pe(e) {
503
526
  let t = globalThis.ImageCapture;
504
527
  if (!t) return;
505
- await je(e);
506
- let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i = pe(r), a;
528
+ await Me(e);
529
+ let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i = me(r), a;
507
530
  try {
508
531
  a = await n.takePhoto(i);
509
532
  } catch {
510
533
  a = await n.takePhoto();
511
534
  }
512
535
  return {
513
- frame: await Me(a),
536
+ frame: await Ne(a),
514
537
  requested: i,
515
538
  photoMax: {
516
539
  width: r?.imageWidth?.max,
@@ -518,42 +541,42 @@ async function Ne(e) {
518
541
  }
519
542
  };
520
543
  }
521
- function j(e, n) {
544
+ function N(e, n) {
522
545
  if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
523
- let r = Ee(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
546
+ let r = M(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
524
547
  i.width = r.width, i.height = r.height;
525
548
  let a = i.getContext("2d");
526
549
  if (!a) throw t();
527
550
  return a.drawImage(e, 0, 0, i.width, i.height), i;
528
551
  }
529
- function Pe(e) {
530
- let t = k();
531
- return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [A(e, t)] : [
532
- A({
552
+ function Fe(e) {
553
+ let t = O();
554
+ return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [j(e, t)] : [
555
+ j({
533
556
  ...e,
534
557
  idealWidth: 3840,
535
558
  idealHeight: 2160
536
559
  }, t),
537
- A({
560
+ j({
538
561
  ...e,
539
562
  idealWidth: 2560,
540
563
  idealHeight: 1440
541
564
  }, t),
542
- A({
565
+ j({
543
566
  ...e,
544
567
  idealWidth: 1920,
545
568
  idealHeight: 1080
546
569
  }, t)
547
570
  ];
548
571
  }
549
- async function Fe(t, n = {}) {
572
+ async function Ie(t, n = {}) {
550
573
  await x("scan");
551
574
  let r = n.torch ?? "alwaysOff";
552
575
  if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
553
576
  if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
554
577
  t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
555
578
  let i, a;
556
- for (let e of Pe(n)) try {
579
+ for (let e of Fe(n)) try {
557
580
  i = await navigator.mediaDevices.getUserMedia(e);
558
581
  break;
559
582
  } catch (e) {
@@ -566,8 +589,8 @@ async function Fe(t, n = {}) {
566
589
  for (let e of i.getTracks()) e.stop();
567
590
  throw Error("The camera did not provide a video track.");
568
591
  }
569
- await ke(o);
570
- let s = Ce(t), c = "ImageCapture" in globalThis, l = ve(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) => {
571
594
  if (!l.supported || o.readyState !== "live") return !1;
572
595
  try {
573
596
  return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
@@ -585,7 +608,7 @@ async function Fe(t, n = {}) {
585
608
  }
586
609
  };
587
610
  l.on && await d(!0);
588
- let f = r === "auto" && l.supported ? new _e() : void 0, p = f ? window.setInterval(() => {
611
+ let f = r === "auto" && l.supported ? new ve() : void 0, p = f ? window.setInterval(() => {
589
612
  if (u || !l.supported) return;
590
613
  let e = f.update(s.getLiveLuminance());
591
614
  e !== void 0 && e !== l.on && (u = !0, d(e).finally(() => {
@@ -611,7 +634,7 @@ async function Fe(t, n = {}) {
611
634
  torchSupported: l.supported,
612
635
  torchOn: l.on,
613
636
  torch: { ...l },
614
- engine: k()
637
+ engine: O()
615
638
  };
616
639
  };
617
640
  return {
@@ -625,17 +648,34 @@ async function Fe(t, n = {}) {
625
648
  get torchOn() {
626
649
  return l.on;
627
650
  },
628
- capture: (e) => j(t, e),
651
+ capture: (e) => Ee(t, s, e),
652
+ async captureLiveFrame(e) {
653
+ let n = globalThis.ImageCapture;
654
+ if (n) try {
655
+ let t = await new n(o).grabFrame?.();
656
+ if (t) {
657
+ let n = M(t.width, t.height, e), r = document.createElement("canvas");
658
+ r.width = n.width, r.height = n.height;
659
+ let i = r.getContext("2d");
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
+ }
662
+ } catch {}
663
+ try {
664
+ return Ee(t, s, e);
665
+ } catch {
666
+ return;
667
+ }
668
+ },
629
669
  async capturePhoto() {
630
670
  let e, n = 0;
631
671
  try {
632
- e = j(t), n = Se(e);
672
+ e = N(t), n = Se(e);
633
673
  } catch {
634
674
  e = void 0;
635
675
  }
636
676
  let r = s.getFrame(), i, a = !1, l = !1, u, d;
637
- if (de(k(), c)) try {
638
- let e = await Ne(o);
677
+ if (fe(O(), c)) try {
678
+ let e = await Pe(o);
639
679
  i = e?.frame, u = e?.requested, d = e?.photoMax;
640
680
  } catch {
641
681
  a = !0, i = void 0;
@@ -643,14 +683,14 @@ async function Fe(t, n = {}) {
643
683
  let f = {
644
684
  width: t.videoWidth,
645
685
  height: t.videoHeight
646
- }, p = i ? Se(i) : 0, h = !!(i && p > 10 && me(i, f));
686
+ }, p = i ? Se(i) : 0, h = !!(i && p > 10 && he(i, f));
647
687
  if (i && p > 10 && !h && (l = !0), h && i) return console.info("[exige-scanner] capture", {
648
688
  method: "image-capture",
649
689
  frame: `${i.width}×${i.height}`,
650
690
  video: `${t.videoWidth}×${t.videoHeight}`,
651
691
  photoMax: d ? `${d.width ?? "—"}×${d.height ?? "—"}` : void 0,
652
692
  photoRequest: u,
653
- aspectMatch: he(i, f)
693
+ aspectMatch: ge(i, f)
654
694
  }), {
655
695
  frame: i,
656
696
  method: "image-capture",
@@ -690,13 +730,13 @@ async function Fe(t, n = {}) {
690
730
  }
691
731
  };
692
732
  }
693
- function Ie() {
733
+ function Le() {
694
734
  let e = typeof navigator > "u" ? void 0 : navigator.userActivation;
695
735
  return !e || e.isActive;
696
736
  }
697
- async function Le() {
737
+ async function Re() {
698
738
  let e = document.createElement("input");
699
- return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"), Me(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) => {
700
740
  e.addEventListener("change", () => {
701
741
  let r = e.files?.[0];
702
742
  r ? t(r) : n(/* @__PURE__ */ Error("No photo was selected."));
@@ -707,20 +747,20 @@ async function Le() {
707
747
  }
708
748
  //#endregion
709
749
  //#region src/sdk/ort-cdn.ts
710
- var Re = "1.30.0";
711
- `${Re}`, `${Re}`;
712
- function ze(e) {
750
+ var ze = "1.30.0";
751
+ `${ze}`, `${ze}`;
752
+ function Be(e) {
713
753
  return !e.ok && e.status !== 206 ? !1 : !(e.headers.get("content-type") ?? "").toLowerCase().includes("text/html");
714
754
  }
715
- async function Be(e, t = fetch) {
755
+ async function Ve(e, t = fetch) {
716
756
  if (!e) return !1;
717
757
  try {
718
758
  let n = await t(e, { method: "HEAD" });
719
- if (ze(n)) return !0;
759
+ if (Be(n)) return !0;
720
760
  if (n.status === 404 || n.status === 410) return !1;
721
761
  } catch {}
722
762
  try {
723
- return ze(await t(e, {
763
+ return Be(await t(e, {
724
764
  method: "GET",
725
765
  headers: { Range: "bytes=0-63" }
726
766
  }));
@@ -730,29 +770,29 @@ async function Be(e, t = fetch) {
730
770
  }
731
771
  //#endregion
732
772
  //#region src/sdk/ort-runtime.ts
733
- var Ve = new URL("./assets/ort-wasm-simd-threaded.jsep.wasm", import.meta.url), He = new URL("./assets/ort-wasm-simd-threaded.jsep.mjs", import.meta.url);
734
- function Ue() {
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() {
735
775
  return {
736
- wasm: Ve.href,
737
- mjs: He.href
776
+ wasm: He.href,
777
+ mjs: Ue.href
738
778
  };
739
779
  }
740
- function We(e) {
741
- return typeof e == "string" ? e.trim() || Ue() : e?.wasm.trim() && e.mjs.trim() ? {
780
+ function Ge(e) {
781
+ return typeof e == "string" ? e.trim() || We() : e?.wasm.trim() && e.mjs.trim() ? {
742
782
  wasm: e.wasm.trim(),
743
783
  mjs: e.mjs.trim()
744
- } : Ue();
784
+ } : We();
745
785
  }
746
786
  //#endregion
747
787
  //#region src/sdk/image.ts
748
- function Ge(e, t, n) {
788
+ function Ke(e, t, n) {
749
789
  let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
750
790
  return {
751
791
  width: Math.max(1, Math.round(e * r)),
752
792
  height: Math.max(1, Math.round(t * r))
753
793
  };
754
794
  }
755
- async function Ke(e) {
795
+ async function qe(e) {
756
796
  let t = URL.createObjectURL(e);
757
797
  try {
758
798
  let e = new Image();
@@ -761,26 +801,26 @@ async function Ke(e) {
761
801
  URL.revokeObjectURL(t);
762
802
  }
763
803
  }
764
- async function M(e, n = {}) {
804
+ async function P(e, n = {}) {
765
805
  if (e instanceof HTMLCanvasElement && n.cloneCanvas === !1 && !n.maxDimension) return e;
766
806
  let r = document.createElement("canvas"), i = r.getContext("2d", { willReadFrequently: !0 });
767
807
  if (!i) throw t();
768
808
  if (e instanceof Blob) {
769
809
  if ("createImageBitmap" in window) try {
770
- let t = await createImageBitmap(e), a = Ge(t.width, t.height, n.maxDimension);
810
+ let t = await createImageBitmap(e), a = Ke(t.width, t.height, n.maxDimension);
771
811
  return r.width = a.width, r.height = a.height, i.drawImage(t, 0, 0, a.width, a.height), t.close(), r;
772
812
  } catch {}
773
- e = await Ke(e);
813
+ e = await qe(e);
774
814
  }
775
815
  let a = e instanceof HTMLImageElement ? e.naturalWidth : e.width, o = e instanceof HTMLImageElement ? e.naturalHeight : e.height;
776
816
  if (!a || !o) throw Error("The image has no readable dimensions.");
777
- let s = Ge(a, o, n.maxDimension);
817
+ let s = Ke(a, o, n.maxDimension);
778
818
  return r.width = s.width, r.height = s.height, i.drawImage(e, 0, 0, s.width, s.height), r;
779
819
  }
780
- function qe(e, t = "image/png", n = .92) {
820
+ function Je(e, t = "image/png", n = .92) {
781
821
  return new Promise((r, i) => e.toBlob((e) => e ? r(e) : i(/* @__PURE__ */ Error("Could not encode the image.")), t, n));
782
822
  }
783
- function Je(e, t, n) {
823
+ function Ye(e, t, n) {
784
824
  let r = Math.max(0, Math.min(t, e.x)), i = Math.max(0, Math.min(n, e.y));
785
825
  return {
786
826
  x: r,
@@ -791,20 +831,20 @@ function Je(e, t, n) {
791
831
  }
792
832
  //#endregion
793
833
  //#region src/sdk/scan.ts
794
- var Ye = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", Xe = 1280;
795
- function Ze(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) {
796
836
  if (n) return n;
797
- let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a = rt() ? 560 : 900;
798
- return i >= 1.6 ? Math.min(r, Math.max(a, Xe)) : 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;
799
839
  }
800
- function Qe(e) {
840
+ function $e(e) {
801
841
  return e?.trim() || "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
802
842
  }
803
- var $e = 3, N, et = 0, P = /* @__PURE__ */ new Map();
804
- function F(e, t) {
843
+ var et = 3, F, tt = 0, I = /* @__PURE__ */ new Map();
844
+ function L(e, t) {
805
845
  return Math.hypot(e.x - t.x, e.y - t.y);
806
846
  }
807
- function tt(e) {
847
+ function nt(e) {
808
848
  return {
809
849
  ...e,
810
850
  edges: {
@@ -827,7 +867,7 @@ function tt(e) {
827
867
  }
828
868
  };
829
869
  }
830
- function nt(e, t) {
870
+ function rt(e, t) {
831
871
  let n = (e) => ({
832
872
  x: e.x / t,
833
873
  y: e.y / t
@@ -839,43 +879,43 @@ function nt(e, t) {
839
879
  bottomLeft: n(e.bottomLeft)
840
880
  };
841
881
  }
842
- function rt() {
882
+ function it() {
843
883
  return typeof navigator > "u" ? !1 : navigator.maxTouchPoints > 0 || navigator.hardwareConcurrency <= 4 || typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
844
884
  }
845
- function it(t, n, r, i) {
885
+ function at(t, n, r, i) {
846
886
  return new Promise((a, o) => {
847
- N || (N = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), N.onmessage = (t) => {
887
+ F || (F = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), F.onmessage = (t) => {
848
888
  if (t.data.download?.url) {
849
- O(t.data.download.url, t.data.download);
889
+ D(t.data.download.url, t.data.download);
850
890
  return;
851
891
  }
852
- let n = P.get(t.data.id);
853
- n && (P.delete(t.data.id), t.data.error ? n.reject(t.data.errorCode ? new e(t.data.errorCode, t.data.error) : Error(t.data.error)) : t.data.result ? n.resolve(t.data.result) : n.reject(/* @__PURE__ */ Error("The document worker returned no result.")));
854
- }, N.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 = () => {
855
895
  let t = new e("worker", "The document worker could not start.");
856
- for (let e of P.values()) e.reject(t);
857
- P.clear(), N?.terminate(), N = void 0;
896
+ for (let e of I.values()) e.reject(t);
897
+ I.clear(), F?.terminate(), F = void 0;
858
898
  });
859
- let s = ++et;
860
- P.set(s, {
899
+ let s = ++tt;
900
+ I.set(s, {
861
901
  resolve: a,
862
902
  reject: o
863
903
  });
864
904
  let c = t.slice().buffer;
865
- N.postMessage({
905
+ F.postMessage({
866
906
  id: s,
867
907
  pixels: c,
868
908
  width: n,
869
909
  height: r,
870
- modelUrl: Qe(i.modelUrl),
910
+ modelUrl: $e(i.modelUrl),
871
911
  heatmapThreshold: i.heatmapThreshold,
872
912
  cacheModel: i.cacheModel,
873
- ortWasmPaths: We(i.ortWasmPaths),
874
- preferWebGpu: i.preferWebGpu ?? le()
913
+ ortWasmPaths: Ge(i.ortWasmPaths),
914
+ preferWebGpu: i.preferWebGpu ?? ue()
875
915
  }, [c]);
876
916
  });
877
917
  }
878
- async function at(n, r) {
918
+ async function ot(n, r) {
879
919
  let { width: i, height: a } = n, o = r.minDimension ?? 360;
880
920
  if (Math.min(i, a) < o) return {
881
921
  status: "low-quality",
@@ -884,7 +924,7 @@ async function at(n, r) {
884
924
  sourceWidth: i,
885
925
  sourceHeight: a
886
926
  };
887
- let s = Ze(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;
888
928
  if (c === 1) {
889
929
  let e = n.getContext("2d", { willReadFrequently: !0 });
890
930
  if (!e) throw t();
@@ -898,7 +938,7 @@ async function at(n, r) {
898
938
  }
899
939
  let f;
900
940
  if (r.useWorker !== !1 && typeof Worker < "u") try {
901
- f = await it(d, l, u, r);
941
+ f = await at(d, l, u, r);
902
942
  } catch (t) {
903
943
  if (t instanceof e && (t.code === "worker" || t.code === "model-http")) throw t;
904
944
  f = {
@@ -922,7 +962,7 @@ async function at(n, r) {
922
962
  modelNote: y,
923
963
  inferenceMs: b
924
964
  };
925
- if (p < $e) return {
965
+ if (p < et) return {
926
966
  status: "low-quality",
927
967
  confidence: Math.min(.3, p / 18),
928
968
  message: "The image is too soft or dark to resolve four document edges.",
@@ -938,7 +978,7 @@ async function at(n, r) {
938
978
  sourceHeight: a,
939
979
  ...x
940
980
  };
941
- let S = nt(m.corners, c), C = tt(S), w = r.minConfidence ?? .58;
981
+ let S = rt(m.corners, c), C = nt(S), w = r.minConfidence ?? .58;
942
982
  return m.confidence < w ? {
943
983
  status: "low-confidence",
944
984
  quad: C,
@@ -959,14 +999,14 @@ async function at(n, r) {
959
999
  ...x
960
1000
  };
961
1001
  }
962
- function ot(e, t) {
963
- let n = Math.max(1, Math.round(Math.max(F(e.topLeft, e.topRight), F(e.bottomLeft, e.bottomRight)))), r = Math.max(1, Math.round(Math.max(F(e.topLeft, e.bottomLeft), F(e.topRight, e.bottomRight)))), i = Math.min(1, t / Math.max(n, r));
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));
964
1004
  return {
965
1005
  width: Math.max(1, Math.round(n * i)),
966
1006
  height: Math.max(1, Math.round(r * i))
967
1007
  };
968
1008
  }
969
- function st(e, t, n, r, i) {
1009
+ function ct(e, t, n, r, i) {
970
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) => {
971
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;
972
1012
  return Math.round(n * (1 - f) + r * f);
@@ -978,69 +1018,69 @@ function st(e, t, n, r, i) {
978
1018
  255
979
1019
  ];
980
1020
  }
981
- function ct(e, n, r) {
982
- let { width: i, height: a } = ot(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 });
983
1023
  if (!o) throw t();
984
1024
  let s = o.getImageData(0, 0, e.width, e.height), c = document.createElement("canvas");
985
1025
  c.width = i, c.height = a;
986
1026
  let l = c.getContext("2d");
987
1027
  if (!l) throw t();
988
- let u = l.createImageData(i, a), { topLeft: d, topRight: f, bottomRight: p, bottomLeft: m } = n, h = f.x - p.x, g = m.x - p.x, _ = f.y - p.y, v = m.y - p.y, y = d.x - f.x + p.x - m.x, b = d.y - f.y + p.y - m.y, x = h * v - g * _, S = Math.abs(x) < 1e-4 ? 0 : (y * v - g * b) / x, C = Math.abs(x) < 1e-4 ? 0 : (h * b - y * _) / x, w = f.x - d.x + S * f.x, T = m.x - d.x + C * m.x, E = f.y - d.y + S * f.y, D = m.y - d.y + C * m.y;
1028
+ let u = l.createImageData(i, a), { topLeft: d, topRight: f, bottomRight: p, bottomLeft: m } = n, h = f.x - p.x, g = m.x - p.x, _ = f.y - p.y, v = m.y - p.y, y = d.x - f.x + p.x - m.x, b = d.y - f.y + p.y - m.y, x = h * v - g * _, S = Math.abs(x) < 1e-4 ? 0 : (y * v - g * b) / x, C = Math.abs(x) < 1e-4 ? 0 : (h * b - y * _) / x, w = f.x - d.x + S * f.x, T = m.x - d.x + C * m.x, ee = f.y - d.y + S * f.y, E = m.y - d.y + C * m.y;
989
1029
  for (let t = 0; t < a; t += 1) {
990
1030
  let n = t / Math.max(1, a - 1);
991
1031
  for (let r = 0; r < i; r += 1) {
992
- let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = (w * a + T * n + d.x) / o, l = (E * a + D * n + d.y) / o, [f, p, m, h] = st(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;
993
1033
  u.data[g] = f, u.data[g + 1] = p, u.data[g + 2] = m, u.data[g + 3] = h;
994
1034
  }
995
1035
  }
996
1036
  return l.putImageData(u, 0, 0), c;
997
1037
  }
998
- async function lt(e, t = {}) {
999
- return await x("scan"), at(await M(e, { cloneCanvas: !1 }), t);
1038
+ async function ut(e, t = {}) {
1039
+ return await x("scan"), ot(await P(e, { cloneCanvas: !1 }), t);
1000
1040
  }
1001
- async function ut(e, t, n = {}) {
1041
+ async function dt(e, t, n = {}) {
1002
1042
  await x("scan");
1003
- let r = await M(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? 4096;
1043
+ let r = await P(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? 4096;
1004
1044
  return {
1005
1045
  status: "success",
1006
1046
  corners: t,
1007
- quad: tt(t),
1047
+ quad: nt(t),
1008
1048
  confidence: 1,
1009
1049
  message: "Captured with the document edges shown in the finder.",
1010
1050
  sourceWidth: r.width,
1011
1051
  sourceHeight: r.height,
1012
- canvas: ct(r, t, i)
1052
+ canvas: lt(r, t, i)
1013
1053
  };
1014
1054
  }
1015
- async function I(e, t = {}) {
1055
+ async function R(e, t = {}) {
1016
1056
  await x("scan");
1017
- let n = await M(e, { cloneCanvas: !1 }), r = await at(n, t);
1057
+ let n = await P(e, { cloneCanvas: !1 }), r = await ot(n, t);
1018
1058
  if (r.status !== "success" || !r.corners) return r;
1019
1059
  let i = t.maxOutputDimension ?? 4096;
1020
1060
  return {
1021
1061
  ...r,
1022
- canvas: ct(n, r.corners, i),
1062
+ canvas: lt(n, r.corners, i),
1023
1063
  message: "Four document edges detected and perspective-corrected."
1024
1064
  };
1025
1065
  }
1026
- function dt(e) {
1066
+ function ft(e) {
1027
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})` : ""}`;
1028
1068
  }
1029
- async function ft(e, t = {}) {
1030
- let n = await I(e, t);
1069
+ async function pt(e, t = {}) {
1070
+ let n = await R(e, t);
1031
1071
  return n.status === "success" ? n : {
1032
1072
  ...n,
1033
- message: dt(n)
1073
+ message: ft(n)
1034
1074
  };
1035
1075
  }
1036
1076
  //#endregion
1037
1077
  //#region src/sdk/lighting.ts
1038
- function pt(e, t) {
1078
+ function mt(e, t) {
1039
1079
  if (!e.length) return 0;
1040
1080
  let n = [...e].sort((e, t) => e - t);
1041
1081
  return n[Math.min(n.length - 1, Math.floor(n.length * t))];
1042
1082
  }
1043
- function mt(e, t, n, r = 12) {
1083
+ function ht(e, t, n, r = 12) {
1044
1084
  if (!t || !n || e.length < t * n) return {
1045
1085
  strong: !1,
1046
1086
  strength: 0,
@@ -1063,7 +1103,7 @@ function mt(e, t, n, r = 12) {
1063
1103
  });
1064
1104
  }
1065
1105
  }
1066
- let s = pt(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 = [];
1067
1107
  for (let e = 0; e < o.length; e += 1) {
1068
1108
  if (!c[e] || l[e]) continue;
1069
1109
  let t = [], n = [e];
@@ -1111,11 +1151,11 @@ function mt(e, t, n, r = 12) {
1111
1151
  }
1112
1152
  return d;
1113
1153
  }
1114
- function ht(e, t, n, r, i, a, o) {
1154
+ function gt(e, t, n, r, i, a, o) {
1115
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));
1116
1156
  return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
1117
1157
  }
1118
- function gt(e, t, n) {
1158
+ function _t(e, t, n) {
1119
1159
  let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
1120
1160
  for (let a = 1; a <= n; a += 1) {
1121
1161
  let n = 0;
@@ -1126,23 +1166,23 @@ function gt(e, t, n) {
1126
1166
  stride: r
1127
1167
  };
1128
1168
  }
1129
- function _t(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
1130
- let { integral: i, stride: a } = gt(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);
1131
1171
  for (let s = 0; s < n; s += 1) for (let c = 0; c < t; c += 1) {
1132
- let l = ht(i, a, t, n, c, s, r);
1172
+ let l = gt(i, a, t, n, c, s, r);
1133
1173
  o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
1134
1174
  }
1135
1175
  return o;
1136
1176
  }
1137
- function vt(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
1138
- let { integral: a, stride: o } = gt(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;
1139
1179
  for (let i = 0; i < n; i += 1) for (let l = 0; l < t; l += 1) {
1140
- let u = ht(a, o, t, n, l, i, r);
1180
+ let u = gt(a, o, t, n, l, i, r);
1141
1181
  s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
1142
1182
  }
1143
1183
  return s;
1144
1184
  }
1145
- function yt(e, t, n) {
1185
+ function bt(e, t, n) {
1146
1186
  let r = [
1147
1187
  e.topLeft,
1148
1188
  e.topRight,
@@ -1156,8 +1196,8 @@ function yt(e, t, n) {
1156
1196
  height: s - a
1157
1197
  };
1158
1198
  }
1159
- function bt(e, t) {
1160
- let n = yt(t, e.width, e.height);
1199
+ function xt(e, t) {
1200
+ let n = bt(t, e.width, e.height);
1161
1201
  if (n.width <= 0 || n.height <= 0) return {
1162
1202
  strong: !1,
1163
1203
  strength: 0,
@@ -1176,26 +1216,26 @@ function bt(e, t) {
1176
1216
  i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
1177
1217
  let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
1178
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);
1179
- return mt(o, r.width, r.height);
1219
+ return ht(o, r.width, r.height);
1180
1220
  }
1181
1221
  //#endregion
1182
1222
  //#region src/sdk/finder.ts
1183
- function xt(e, t) {
1223
+ function St(e, t) {
1184
1224
  return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
1185
1225
  }
1186
- function St(e, t, n) {
1226
+ function Ct(e, t, n) {
1187
1227
  if (n <= 0) return 0;
1188
1228
  let r = n - (t - e);
1189
1229
  return r <= 0 ? 0 : Math.max(1, Math.ceil(r / 1e3));
1190
1230
  }
1191
- function Ct(e) {
1231
+ function wt(e) {
1192
1232
  return `Hold still for ${e}…`;
1193
1233
  }
1194
- async function wt(e, t) {
1234
+ async function Tt(e, t) {
1195
1235
  let n = await e();
1196
1236
  return t(), n;
1197
1237
  }
1198
- function Tt(e) {
1238
+ function Et(e) {
1199
1239
  return e === "alwaysOn" || e === "only" ? {
1200
1240
  visible: !1,
1201
1241
  checked: !0,
@@ -1210,7 +1250,7 @@ function Tt(e) {
1210
1250
  mutable: !0
1211
1251
  };
1212
1252
  }
1213
- function L(e) {
1253
+ function z(e) {
1214
1254
  return [
1215
1255
  e.topLeft,
1216
1256
  e.topRight,
@@ -1218,19 +1258,19 @@ function L(e) {
1218
1258
  e.bottomLeft
1219
1259
  ];
1220
1260
  }
1221
- var Et = 3e3, Dt = 1600;
1222
- function Ot(e = k()) {
1261
+ var Dt = 3e3, Ot = 1600;
1262
+ function kt(e = O()) {
1223
1263
  return e.iosWebKit ? {
1224
1264
  intervalMs: 70,
1225
1265
  maxFrameDimension: 720,
1226
1266
  maxAnalysisDimension: 720
1227
1267
  } : {
1228
1268
  intervalMs: 140,
1229
- maxFrameDimension: Dt,
1269
+ maxFrameDimension: Ot,
1230
1270
  maxAnalysisDimension: 520
1231
1271
  };
1232
1272
  }
1233
- function kt(e, t) {
1273
+ function At(e, t) {
1234
1274
  let n = e.status === "success" && e.modelStatus !== "failed", r = {
1235
1275
  status: e.status,
1236
1276
  confidence: Number(e.confidence.toFixed(3)),
@@ -1253,7 +1293,7 @@ function kt(e, t) {
1253
1293
  detail: r
1254
1294
  };
1255
1295
  }
1256
- function At(e) {
1296
+ function jt(e) {
1257
1297
  let t = 0;
1258
1298
  for (let n = 0; n < e.length; n += 1) {
1259
1299
  let r = e[n], i = e[(n + 1) % e.length];
@@ -1261,42 +1301,42 @@ function At(e) {
1261
1301
  }
1262
1302
  return Math.abs(t) / 2;
1263
1303
  }
1264
- function R(e, t) {
1304
+ function B(e, t) {
1265
1305
  return Math.hypot(e.x - t.x, e.y - t.y);
1266
1306
  }
1267
- var z = {
1307
+ var V = {
1268
1308
  widthFill: 0,
1269
1309
  heightFill: 0,
1270
1310
  limitingFill: 0,
1271
1311
  areaFill: 0,
1272
1312
  aspectRatio: 1
1273
1313
  };
1274
- function jt(e, t, n) {
1275
- let r = L(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(R(c, l), R(d, u)), p = Math.max(R(c, d), R(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));
1276
1316
  return {
1277
1317
  widthFill: o,
1278
1318
  heightFill: s,
1279
1319
  limitingFill: Math.max(o, s),
1280
- areaFill: At(r) / Math.max(1, t * n),
1320
+ areaFill: jt(r) / Math.max(1, t * n),
1281
1321
  aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
1282
1322
  };
1283
1323
  }
1284
- function Mt(e, t, n, r = {}) {
1324
+ function Nt(e, t, n, r = {}) {
1285
1325
  let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
1286
1326
  if (e.aspectRatio < a) return i;
1287
1327
  let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
1288
1328
  return Math.min(o ?? i + .08, 1 - n * 2);
1289
1329
  }
1290
- function Nt(e, t, n = {}) {
1330
+ function Pt(e, t, n = {}) {
1291
1331
  let r = n.confidenceThreshold ?? .72;
1292
1332
  if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
1293
1333
  hint: "Place the document in the frame",
1294
1334
  reason: "place-document",
1295
1335
  fillRatio: 0,
1296
- fill: z,
1336
+ fill: V,
1297
1337
  readyForAutoCapture: !1
1298
1338
  };
1299
- let i = L(e.quad), a = jt(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;
1300
1340
  if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
1301
1341
  hint: "Move farther away",
1302
1342
  reason: "move-farther-away",
@@ -1304,14 +1344,14 @@ function Nt(e, t, n = {}) {
1304
1344
  fill: a,
1305
1345
  readyForAutoCapture: !1
1306
1346
  };
1307
- let [u, d, f, p] = i, m = R(u, d), h = R(d, f), g = R(f, p), _ = R(p, u);
1347
+ let [u, d, f, p] = i, m = B(u, d), h = B(d, f), g = B(f, p), _ = B(p, u);
1308
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) ? {
1309
1349
  hint: "Hold the camera straight",
1310
1350
  reason: "straighten-camera",
1311
1351
  fillRatio: o,
1312
1352
  fill: a,
1313
1353
  readyForAutoCapture: !1
1314
- } : o < Mt(a, t.previouslyReady === !0, s, n) ? {
1354
+ } : o < Nt(a, t.previouslyReady === !0, s, n) ? {
1315
1355
  hint: "Move closer",
1316
1356
  reason: "move-closer",
1317
1357
  fillRatio: o,
@@ -1325,7 +1365,7 @@ function Nt(e, t, n = {}) {
1325
1365
  readyForAutoCapture: t.ready
1326
1366
  };
1327
1367
  }
1328
- var Pt = class {
1368
+ var Ft = class {
1329
1369
  previous;
1330
1370
  count = 0;
1331
1371
  ready = !1;
@@ -1342,8 +1382,8 @@ var Pt = class {
1342
1382
  ready: !1,
1343
1383
  movement: Infinity
1344
1384
  };
1345
- let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...L(e.quad).map((e, n) => {
1346
- let r = L(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];
1347
1387
  return Math.hypot(e.x - r.x, e.y - r.y) / Math.max(1, t);
1348
1388
  })) : Infinity, r = this.options.exitCornerTolerance ?? Math.max(this.options.cornerTolerance, .036);
1349
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, {
@@ -1353,14 +1393,14 @@ var Pt = class {
1353
1393
  };
1354
1394
  }
1355
1395
  };
1356
- function Ft(e, n) {
1396
+ function It(e, n) {
1357
1397
  let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
1358
1398
  i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
1359
1399
  let a = i.getContext("2d");
1360
1400
  if (!a) throw t();
1361
1401
  return a.drawImage(e, 0, 0, i.width, i.height), i;
1362
1402
  }
1363
- function It() {
1403
+ function Lt() {
1364
1404
  let e = window.AudioContext ?? window.webkitAudioContext;
1365
1405
  if (!e) return;
1366
1406
  let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
@@ -1371,29 +1411,29 @@ function It() {
1371
1411
  let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
1372
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();
1373
1413
  }
1374
- async function Lt(e) {
1414
+ async function Rt(e) {
1375
1415
  let t = document.createElement("video");
1376
1416
  return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
1377
1417
  }
1378
- async function Rt(t) {
1418
+ async function zt(t) {
1379
1419
  await x("scan");
1380
- let n = Tt(t.autoCapture), r = t.holdStillMs ?? 3e3, i = new Pt({
1420
+ let n = Et(t.autoCapture), r = t.holdStillMs ?? 3e3, i = new Ft({
1381
1421
  stableFrames: t.stableFrames ?? 4,
1382
1422
  confidenceThreshold: t.confidenceThreshold ?? .72,
1383
1423
  cornerTolerance: t.cornerTolerance ?? .024,
1384
1424
  exitCornerTolerance: t.exitCornerTolerance ?? .036
1385
- }), a = Ot(), 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 = {
1386
1426
  minDimension: 220,
1387
1427
  maxAnalysisDimension: a.maxAnalysisDimension,
1388
1428
  ...t.detection
1389
- }, l = typeof MediaStream < "u" && t.source instanceof MediaStream ? await Lt(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 = {
1390
1430
  state: "detecting",
1391
1431
  confidence: 0,
1392
1432
  guidance: {
1393
1433
  hint: "Place the document in the frame",
1394
1434
  reason: "place-document",
1395
1435
  fillRatio: 0,
1396
- fill: z,
1436
+ fill: V,
1397
1437
  readyForAutoCapture: !1
1398
1438
  },
1399
1439
  lighting: {
@@ -1403,10 +1443,10 @@ async function Rt(t) {
1403
1443
  stableFrames: 0,
1404
1444
  requiredStableFrames: t.stableFrames ?? 4,
1405
1445
  autoCapture: { ...n }
1406
- }, y = () => l instanceof HTMLCanvasElement ? Ft(l, o) : j(l, o), b = (e) => {
1446
+ }, y = () => l instanceof HTMLCanvasElement ? It(l, o) : N(l, o), b = (e) => {
1407
1447
  v = e, t.onStatus?.(e);
1408
1448
  }, S = (e) => {
1409
- let t = kt(e, l instanceof HTMLVideoElement ? {
1449
+ let t = At(e, l instanceof HTMLVideoElement ? {
1410
1450
  width: l.videoWidth,
1411
1451
  height: l.videoHeight
1412
1452
  } : {
@@ -1421,11 +1461,11 @@ async function Rt(t) {
1421
1461
  d = !0;
1422
1462
  let n;
1423
1463
  try {
1424
- n = await wt(t.captureFrame ?? y, () => {
1464
+ n = await Tt(t.captureFrame ?? y, () => {
1425
1465
  b({
1426
1466
  ...v,
1427
1467
  state: "captured"
1428
- }), t.playShutterSound !== !1 && It(), C();
1468
+ }), t.playShutterSound !== !1 && Lt(), C();
1429
1469
  });
1430
1470
  } catch (e) {
1431
1471
  throw d = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
@@ -1439,9 +1479,9 @@ async function Rt(t) {
1439
1479
  }, T = async () => {
1440
1480
  if (u && !d) {
1441
1481
  try {
1442
- let e = y(), a = await lt(e, c);
1482
+ let e = y(), a = await ut(e, c);
1443
1483
  h = a, S(a);
1444
- let o = a.quad ? bt(e, a.quad) : {
1484
+ let o = a.quad ? xt(e, a.quad) : {
1445
1485
  strong: !1,
1446
1486
  strength: 0
1447
1487
  }, s = o.strong ? {
@@ -1451,7 +1491,7 @@ async function Rt(t) {
1451
1491
  } : {
1452
1492
  castShadow: !1,
1453
1493
  strength: o.strength
1454
- }, l = i.update(a), u = Nt(a, {
1494
+ }, l = i.update(a), u = Pt(a, {
1455
1495
  ...l,
1456
1496
  previouslyReady: f
1457
1497
  }, {
@@ -1461,7 +1501,7 @@ async function Rt(t) {
1461
1501
  f = u.readyForAutoCapture;
1462
1502
  let d = performance.now();
1463
1503
  u.readyForAutoCapture && n.checked ? p ??= d : p = void 0;
1464
- let m = p === void 0 ? void 0 : St(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";
1465
1505
  if (b({
1466
1506
  state: g,
1467
1507
  confidence: a.confidence,
@@ -1507,7 +1547,7 @@ async function Rt(t) {
1507
1547
  hint: "Place the document in the frame",
1508
1548
  reason: "place-document",
1509
1549
  fillRatio: 0,
1510
- fill: z,
1550
+ fill: V,
1511
1551
  readyForAutoCapture: !1
1512
1552
  },
1513
1553
  lighting: {
@@ -1538,24 +1578,24 @@ async function Rt(t) {
1538
1578
  }
1539
1579
  //#endregion
1540
1580
  //#region src/sdk/ocr-runtime.ts
1541
- var zt = new URL("./assets/tesseract/worker.min.js", import.meta.url), Bt = new URL("./assets/tesseract/tesseract-core-lstm.wasm.js", import.meta.url), Vt = new URL("./assets/tesseract/tesseract-core-simd-lstm.wasm.js", import.meta.url), Ht = new URL("./assets/tesseract/tesseract-core-relaxedsimd-lstm.wasm.js", import.meta.url), Ut = new URL("./assets/tesseract/eng.traineddata.gz", import.meta.url), Wt = 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), Gt = 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);
1542
- function Kt(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) {
1543
1583
  try {
1544
1584
  return typeof WebAssembly < "u" && WebAssembly.validate(e);
1545
1585
  } catch {
1546
1586
  return !1;
1547
1587
  }
1548
1588
  }
1549
- function qt() {
1589
+ function Jt() {
1550
1590
  return {
1551
- relaxedSimd: Kt(Wt),
1552
- simd: Kt(Gt)
1591
+ relaxedSimd: qt(Gt),
1592
+ simd: qt(Kt)
1553
1593
  };
1554
1594
  }
1555
- function Jt(e) {
1556
- return e.relaxedSimd ? Ht : e.simd ? Vt : Bt;
1595
+ function Yt(e) {
1596
+ return e.relaxedSimd ? Ut : e.simd ? Ht : Vt;
1557
1597
  }
1558
- function Yt(t, n) {
1598
+ function Xt(t, n) {
1559
1599
  let r = t?.trim() || "eng", i = n?.trim() || "";
1560
1600
  if (i) return {
1561
1601
  kind: "lang-path",
@@ -1568,14 +1608,14 @@ function Yt(t, n) {
1568
1608
  };
1569
1609
  throw new e("language", `OCR language "${r}" is not packaged. Pass langPath, a directory URL that contains ${r}.traineddata.gz.`);
1570
1610
  }
1571
- function Xt(e = Ut) {
1611
+ function Zt(e = Wt) {
1572
1612
  let t = e.href, n = t.lastIndexOf("/");
1573
1613
  return n === -1 ? t : t.slice(0, n);
1574
1614
  }
1575
- function Zt(e) {
1576
- return e.kind === "bundled-eng" ? Xt() : e.langPath;
1615
+ function Qt(e) {
1616
+ return e.kind === "bundled-eng" ? Zt() : e.langPath;
1577
1617
  }
1578
- async function Qt(t, n, r) {
1618
+ async function $t(t, n, r) {
1579
1619
  return new Promise((i, a) => {
1580
1620
  let o = !1, s = (t) => {
1581
1621
  o || (o = !0, a(new e("worker", `OCR worker failed to start (${t instanceof Error ? t.message : String(t)}).`)));
@@ -1598,7 +1638,7 @@ async function Qt(t, n, r) {
1598
1638
  }
1599
1639
  //#endregion
1600
1640
  //#region src/sdk/ocr.ts
1601
- function $t(e, t = 1, n = 1, r = 0, i = 0) {
1641
+ function en(e, t = 1, n = 1, r = 0, i = 0) {
1602
1642
  return {
1603
1643
  text: e.text,
1604
1644
  confidence: Math.max(0, Math.min(1, e.confidence / 100)),
@@ -1610,20 +1650,20 @@ function $t(e, t = 1, n = 1, r = 0, i = 0) {
1610
1650
  }
1611
1651
  };
1612
1652
  }
1613
- function en(e = .5) {
1653
+ function tn(e = .5) {
1614
1654
  if (!Number.isFinite(e) || e < 0 || e > 1) throw RangeError("OCR minConfidence must be between 0 and 1.");
1615
1655
  return e;
1616
1656
  }
1617
- function tn(e, t) {
1657
+ function nn(e, t) {
1618
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);
1619
1659
  return s > 0 ? o / s : 0;
1620
1660
  }
1621
- function nn(e) {
1661
+ function rn(e) {
1622
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 = [];
1623
- for (let e of t) n.some((t) => tn(t, e) >= .65) || n.push(e);
1663
+ for (let e of t) n.some((t) => nn(t, e) >= .65) || n.push(e);
1624
1664
  return n;
1625
1665
  }
1626
- function rn(e, t, n, r, i) {
1666
+ function an(e, t, n, r, i) {
1627
1667
  let a = e.text.trim();
1628
1668
  if (!a || !/[\p{L}\p{N}]/u.test(a)) return !1;
1629
1669
  let o = e.bbox.width * e.bbox.height / Math.max(1, n * r), s = e.bbox.width / Math.max(1, e.bbox.height);
@@ -1634,7 +1674,7 @@ function rn(e, t, n, r, i) {
1634
1674
  }
1635
1675
  return !0;
1636
1676
  }
1637
- function an(e) {
1677
+ function on(e) {
1638
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 = [];
1639
1679
  for (let e of t) {
1640
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);
@@ -1650,28 +1690,28 @@ function an(e) {
1650
1690
  }
1651
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");
1652
1692
  }
1653
- function on(e, t, n, r) {
1654
- let i = en(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;
1655
1695
  for (let t of e) {
1656
1696
  let e = t.scaleX ?? 1, n = t.scaleY ?? 1, r = t.offsetX ?? 0, l = t.offsetY ?? 0;
1657
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) {
1658
- let u = $t(t, e, n, r, l);
1698
+ let u = en(t, e, n, r, l);
1659
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);
1660
1700
  for (let a of t.symbols) {
1661
- let t = $t(a, e, n, r, l);
1701
+ let t = en(a, e, n, r, l);
1662
1702
  t.confidence >= i && o.push(t);
1663
1703
  }
1664
1704
  }
1665
1705
  }
1666
- let l = n?.width ?? s, u = n?.height ?? c, d = nn(a).filter((e) => rn(e, "word", l, u, r)), f = nn(o).filter((e) => rn(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));
1667
1707
  return {
1668
- text: an(d),
1708
+ text: on(d),
1669
1709
  confidence: d.length ? d.reduce((e, t) => e + t.confidence, 0) / d.length : 0,
1670
1710
  words: t.includeWords ? d : [],
1671
1711
  characters: t.includeCharacters ? f : []
1672
1712
  };
1673
1713
  }
1674
- function sn(e) {
1714
+ function cn(e) {
1675
1715
  let n = e.getContext("2d", { willReadFrequently: !0 });
1676
1716
  if (!n) throw t();
1677
1717
  let r = n.getImageData(0, 0, e.width, e.height), i = new Uint8Array(e.width * e.height);
@@ -1682,7 +1722,7 @@ function sn(e) {
1682
1722
  luminance: i
1683
1723
  };
1684
1724
  }
1685
- function cn(e) {
1725
+ function ln(e) {
1686
1726
  let t = document.createElement("canvas");
1687
1727
  t.width = 72, t.height = 72;
1688
1728
  let n = t.getContext("2d", { willReadFrequently: !0 });
@@ -1693,27 +1733,27 @@ function cn(e) {
1693
1733
  areaRatio: 0
1694
1734
  };
1695
1735
  n.drawImage(e, 0, 0, t.width, t.height);
1696
- let { luminance: r } = sn(t);
1697
- return mt(r, t.width, t.height);
1736
+ let { luminance: r } = cn(t);
1737
+ return ht(r, t.width, t.height);
1698
1738
  }
1699
- function ln(e, t, n, r) {
1739
+ function un(e, t, n, r) {
1700
1740
  let i = (e.bbox.x + e.bbox.width / 2) / n, a = (e.bbox.y + e.bbox.height / 2) / r;
1701
1741
  return i >= t.x && i <= t.x + t.width && a >= t.y && a <= t.y + t.height;
1702
1742
  }
1703
- var un = .58;
1704
- function dn(e) {
1743
+ var dn = .58;
1744
+ function fn(e) {
1705
1745
  let t = e.trim();
1706
1746
  if (!t || !/[\p{L}\p{N}]/u.test(t)) return 0;
1707
1747
  if (/^\$?\d{1,5}([.,]\d{2})?$/.test(t)) return 1;
1708
1748
  let n = t.replace(/[^\p{L}]/gu, "");
1709
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;
1710
1750
  }
1711
- function fn(e, t, n) {
1751
+ function pn(e, t, n) {
1712
1752
  let r = Math.max(0, Math.min(1, (1 - e.darkness / 80) * (1 - e.strength / 24)));
1713
1753
  if (!t.length) return r * .35;
1714
1754
  let i = 0;
1715
1755
  for (let e of t) {
1716
- let t = dn(e.text);
1756
+ let t = fn(e.text);
1717
1757
  if (n) {
1718
1758
  let r = n(e.bbox);
1719
1759
  (r < .04 || r > .62) && (t *= .4);
@@ -1722,10 +1762,10 @@ function fn(e, t, n) {
1722
1762
  }
1723
1763
  return r * .7 + i / t.length * .3;
1724
1764
  }
1725
- function pn(e, t, n, r) {
1726
- return !e.strong || !e.region ? !1 : fn(e, t.filter((t) => ln(t, e.region, n.width, n.height)), r) < un;
1727
- }
1728
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
+ }
1768
+ function hn(e, t, n, r) {
1729
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");
1730
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);
1731
1771
  let l = n / e.width, u = r / e.height;
@@ -1739,26 +1779,26 @@ function mn(e, t, n, r) {
1739
1779
  }
1740
1780
  };
1741
1781
  }
1742
- function hn(e, t) {
1782
+ function gn(e, t) {
1743
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;
1744
1784
  }
1745
- function gn(e) {
1785
+ function _n(e) {
1746
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");
1747
1787
  a.width = Math.max(1, Math.round(e.width * i)), a.height = Math.max(1, Math.round(e.height * i));
1748
1788
  let o = a.getContext("2d", { willReadFrequently: !0 });
1749
1789
  if (!o) throw t();
1750
1790
  o.drawImage(e, 0, 0, a.width, a.height);
1751
- let { image: s, luminance: c } = sn(a), l = _t(c, a.width, a.height), u = vt(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");
1752
1792
  d.width = a.width, d.height = a.height;
1753
1793
  let f = d.getContext("2d", { willReadFrequently: !0 });
1754
1794
  if (!f) throw t();
1755
1795
  let p = f.createImageData(d.width, d.height);
1756
- return hn(p, l), f.putImageData(p, 0, 0), hn(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), {
1757
1797
  sparseCanvas: a,
1758
1798
  flattenedCanvas: d
1759
1799
  };
1760
1800
  }
1761
- function _n(e) {
1801
+ function vn(e) {
1762
1802
  let t = document.createElement("canvas");
1763
1803
  t.width = 24, t.height = 24;
1764
1804
  let n = t.getContext("2d", { willReadFrequently: !0 });
@@ -1776,19 +1816,19 @@ function _n(e) {
1776
1816
  return l / s.length;
1777
1817
  };
1778
1818
  }
1779
- async function B(e, t = {}) {
1819
+ async function H(e, t = {}) {
1780
1820
  await x("ocr");
1781
- let n = Yt(t.language, t.langPath), r = n.language;
1782
- en(t.minConfidence);
1783
- let i = await M(e, { cloneCanvas: !1 }), { sparseCanvas: a, flattenedCanvas: o } = gn(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 ? {
1784
1824
  strong: !1,
1785
1825
  strength: 0,
1786
1826
  darkness: 0,
1787
1827
  areaRatio: 0
1788
- } : cn(i), { createWorker: c, PSM: l } = await import("tesseract.js"), u = 0, d = s.strong ? 3 : 2, f = await Qt(c, r, {
1789
- workerPath: zt.href,
1790
- corePath: Jt(qt()).href,
1791
- langPath: Zt(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),
1792
1832
  logger(e) {
1793
1833
  typeof e.progress == "number" && t.onProgress?.(Math.min(1, (u + e.progress) / d), e.status ?? "recognizing text");
1794
1834
  }
@@ -1813,16 +1853,16 @@ async function B(e, t = {}) {
1813
1853
  }], d = {
1814
1854
  ...t,
1815
1855
  includeWords: !0
1816
- }, p = _n(i), m = on(c, d, {
1856
+ }, p = vn(i), m = sn(c, d, {
1817
1857
  width: i.width,
1818
1858
  height: i.height
1819
- }, p), h = t.shadowPass !== !1 && pn(s, m.words, {
1859
+ }, p), h = t.shadowPass !== !1 && mn(s, m.words, {
1820
1860
  width: i.width,
1821
1861
  height: i.height
1822
1862
  }, p);
1823
1863
  if (h && s.region) {
1824
1864
  u = 2;
1825
- let { tile: e, passMapping: t } = mn(o, s.region, i.width, i.height);
1865
+ let { tile: e, passMapping: t } = hn(o, s.region, i.width, i.height);
1826
1866
  await f.setParameters({
1827
1867
  tessedit_pageseg_mode: l.SPARSE_TEXT,
1828
1868
  preserve_interword_spaces: "1"
@@ -1836,7 +1876,7 @@ async function B(e, t = {}) {
1836
1876
  ...t
1837
1877
  });
1838
1878
  }
1839
- let g = c.length === 2 ? m : on(c, d, {
1879
+ let g = c.length === 2 ? m : sn(c, d, {
1840
1880
  width: i.width,
1841
1881
  height: i.height
1842
1882
  }, p);
@@ -1865,55 +1905,68 @@ async function B(e, t = {}) {
1865
1905
  }
1866
1906
  //#endregion
1867
1907
  //#region src/sdk/zxing-runtime.ts
1868
- var vn = new URL("./assets/zxing_reader.wasm", import.meta.url), yn = "3.1.6", bn = "zxing_reader.wasm", xn = `https://exige-scanner-sdk.vercel.app/zxing/${yn}/`, Sn = `https://cdn.jsdelivr.net/npm/zxing-wasm@${yn}/dist/reader/`;
1869
- function Cn(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) {
1870
1910
  return `${e.endsWith("/") ? e : `${e}/`}${t}`;
1871
1911
  }
1872
- function wn(e = xn) {
1873
- return Cn(e, bn);
1912
+ function Tn(e = Sn) {
1913
+ return wn(e, xn);
1874
1914
  }
1875
- function Tn() {
1876
- return vn.href;
1915
+ function En() {
1916
+ return yn.href;
1877
1917
  }
1878
- var En, Dn;
1879
- function On() {
1918
+ var Dn, On;
1919
+ function kn() {
1880
1920
  return {
1881
- binary: En,
1882
- url: Dn
1921
+ binary: Dn,
1922
+ url: On
1883
1923
  };
1884
1924
  }
1885
- async function kn(e = fetch) {
1886
- let t = Tn();
1887
- if (await Be(t, e)) return t;
1888
- let n = wn(xn);
1889
- return await Be(n, e) ? n : wn(Sn);
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
+ }
1931
+ async function jn(e = fetch) {
1932
+ let t = kn();
1933
+ if (t.binary) return t.binary.slice(0);
1934
+ let n = await e(await An(e));
1935
+ if (!n.ok) throw Error(`Could not download zxing-wasm (${n.status}).`);
1936
+ return await n.arrayBuffer();
1890
1937
  }
1891
1938
  //#endregion
1892
1939
  //#region src/sdk/barcode.ts
1893
- var V = 1600, An = [
1940
+ var Mn = 1600, Nn = [
1894
1941
  1600,
1895
1942
  1280,
1896
1943
  960,
1897
1944
  720,
1898
1945
  480
1899
- ], jn = [
1946
+ ], Pn = [
1900
1947
  [.2, .8],
1901
1948
  [.32, .72],
1902
1949
  [.4, .86]
1903
1950
  ];
1904
- function Mn(e, t) {
1951
+ function Fn(e, t) {
1905
1952
  let n = Math.max(e, t);
1906
1953
  if (!Number.isFinite(n) || n < 1) return [];
1907
- let r = Math.min(n, V), i = [r];
1908
- for (let e of An) 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);
1909
1956
  return i;
1910
1957
  }
1911
- function Nn() {
1958
+ var U = class extends Error {
1959
+ code = "zxing-wasm-load";
1960
+ constructor(e) {
1961
+ super("The barcode decoder failed to load."), this.name = "Pdf417DecoderError", e !== void 0 && (this.cause = e);
1962
+ }
1963
+ };
1964
+ function In() {
1912
1965
  let e = globalThis.BarcodeDetector;
1913
1966
  return typeof e == "function" ? e : void 0;
1914
1967
  }
1915
- async function Pn() {
1916
- let e = Nn();
1968
+ async function Ln() {
1969
+ let e = In();
1917
1970
  if (!e?.getSupportedFormats) return !1;
1918
1971
  try {
1919
1972
  return (await e.getSupportedFormats()).some((e) => e.toLowerCase() === "pdf417");
@@ -1921,42 +1974,116 @@ async function Pn() {
1921
1974
  return !1;
1922
1975
  }
1923
1976
  }
1924
- function Fn(e) {
1977
+ function Rn(e) {
1925
1978
  try {
1926
1979
  return e.getContext("2d", { willReadFrequently: !0 })?.getImageData(0, 0, e.width, e.height);
1927
1980
  } catch {
1928
1981
  return;
1929
1982
  }
1930
1983
  }
1931
- async function In(e) {
1984
+ async function zn(e) {
1932
1985
  let t = [];
1933
1986
  if (e instanceof Blob && t.push(e), e instanceof HTMLCanvasElement) {
1934
- let n = Fn(e);
1987
+ let n = Rn(e);
1935
1988
  n && t.push(n);
1936
1989
  try {
1937
- t.push(await qe(e, "image/png"));
1990
+ t.push(await Je(e, "image/png"));
1938
1991
  } catch {}
1939
1992
  } else if (!(e instanceof Blob)) try {
1940
- let n = Fn(await M(e, { cloneCanvas: !1 }));
1993
+ let n = Rn(await P(e, { cloneCanvas: !1 }));
1941
1994
  n && t.push(n);
1942
1995
  } catch {}
1943
1996
  return t;
1944
1997
  }
1945
- var H;
1946
- async function Ln() {
1947
- return H ||= (async () => {
1948
- let e = await import("zxing-wasm/reader"), t = On(), n = t.binary ? void 0 : await kn();
1998
+ var Bn;
1999
+ async function Vn() {
2000
+ return Bn ||= (async () => {
2001
+ let [e, t] = await Promise.all([import("zxing-wasm/reader"), jn()]);
1949
2002
  return await e.prepareZXingModule({
1950
- overrides: t.binary ? { wasmBinary: t.binary } : { locateFile: (e, t) => e.endsWith(".wasm") ? n ?? t + e : t + e },
2003
+ overrides: { wasmBinary: t },
1951
2004
  fireImmediately: !0
1952
2005
  }), e;
1953
2006
  })().catch((e) => {
1954
- throw H = void 0, console.error("[exige-scanner] zxing-wasm failed to load", e), e;
1955
- }), 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
+ }
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;
2045
+ }
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
+ };
1956
2075
  }
1957
- async function Rn(e) {
1958
- let { readBarcodes: t } = await Ln();
1959
- for (let n of await In(e)) {
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)) {
1960
2087
  let e = (await t(n, {
1961
2088
  formats: ["PDF417"],
1962
2089
  tryHarder: !0,
@@ -1966,11 +2093,14 @@ async function Rn(e) {
1966
2093
  downscaleFactor: 2,
1967
2094
  downscaleThreshold: 300,
1968
2095
  maxNumberOfSymbols: 1
1969
- })).find((e) => e.text?.trim())?.text?.trim();
1970
- 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
+ };
1971
2101
  }
1972
2102
  }
1973
- function U(e, t) {
2103
+ function qn(e, t) {
1974
2104
  let n = Math.max(e.width, e.height);
1975
2105
  if (n <= t) return e;
1976
2106
  let r = t / n, i = document.createElement("canvas");
@@ -1978,64 +2108,78 @@ function U(e, t) {
1978
2108
  let a = i.getContext("2d", { willReadFrequently: !0 }) ?? i.getContext("2d");
1979
2109
  return a && (a.imageSmoothingEnabled = !0, "imageSmoothingQuality" in a && (a.imageSmoothingQuality = "high"), a.drawImage(e, 0, 0, i.width, i.height)), i;
1980
2110
  }
1981
- function zn(e, t, n) {
2111
+ function Jn(e, t, n) {
1982
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");
1983
2113
  a.width = e.width, a.height = i;
1984
2114
  let o = a.getContext("2d", { willReadFrequently: !0 }) ?? a.getContext("2d");
1985
2115
  return o && o.drawImage(e, 0, r, e.width, i, 0, 0, e.width, i), a;
1986
2116
  }
1987
- function Bn(e) {
1988
- return Mn(e.width, e.height).map((t) => U(e, t));
1989
- }
1990
- function Vn(e) {
1991
- if (e.height < e.width * 1.15 || e.height < 120) return [];
1992
- let t = [];
1993
- for (let [n, r] of jn) {
1994
- let i = zn(e, n, r);
1995
- t.push(U(i, V));
1996
- let a = Mn(i.width, i.height).find((e) => e <= 960);
1997
- a && t.push(U(i, a));
1998
- }
1999
- 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
+ };
2000
2130
  }
2001
- function Hn(e) {
2002
- let t = /* @__PURE__ */ new Set(), n = [];
2003
- for (let r of [...Vn(e), ...Bn(e)]) {
2004
- let e = `${r.width}x${r.height}`;
2005
- 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));
2006
2141
  }
2142
+ for (let t of Fn(e.width, e.height)) r(Yn(e, t));
2007
2143
  return n;
2008
2144
  }
2009
- async function W(e) {
2145
+ async function Zn(e) {
2010
2146
  let t;
2011
2147
  try {
2012
- t = await M(e, { cloneCanvas: !1 });
2148
+ t = await P(e, { cloneCanvas: !1 });
2013
2149
  } catch {
2014
2150
  t = e instanceof HTMLCanvasElement ? e : document.createElement("canvas");
2015
2151
  }
2016
- let n = t.width && t.height ? Hn(t) : [];
2152
+ let n = t.width && t.height ? Xn(t) : [];
2017
2153
  for (let e of n) try {
2018
- let t = await Rn(e);
2019
- if (t) return {
2020
- text: t,
2021
- source: "zxing-wasm"
2022
- };
2023
- } catch {}
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
+ }
2163
+ } catch (e) {
2164
+ if (e instanceof U) throw e;
2165
+ }
2024
2166
  if (e instanceof Blob) try {
2025
- let t = await Rn(e);
2026
- return t ? {
2027
- text: t,
2028
- 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
2029
2172
  } : void 0;
2030
- } catch {
2173
+ } catch (e) {
2174
+ if (e instanceof U) throw e;
2031
2175
  return;
2032
2176
  }
2033
2177
  }
2034
- 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(".")), Un = /* @__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("."), Wn = /* @__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([
2035
2179
  "expirationDate",
2036
2180
  "dateOfBirth",
2037
2181
  "issueDate"
2038
- ]), Gn = {
2182
+ ]), er = {
2039
2183
  DAJ: "issuerJurisdiction",
2040
2184
  DBA: "expirationDate",
2041
2185
  DAQ: "documentNumber",
@@ -2071,16 +2215,16 @@ function K(e, t, n) {
2071
2215
  let r = Number(e), i = Number(t), a = Number(n);
2072
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")}`;
2073
2217
  }
2074
- function Kn(e, t) {
2218
+ function tr(e, t) {
2075
2219
  return t ? e >= 30 ? 1900 + e : 2e3 + e : e >= 50 ? 1900 + e : 2e3 + e;
2076
2220
  }
2077
- function q(e, t = !1) {
2221
+ function nr(e, t = !1) {
2078
2222
  let n = e.trim();
2079
2223
  if (!n) return;
2080
2224
  let r = /^(\d{1,2})[/-](\d{1,2})[/-](\d{2,4})$/.exec(n);
2081
2225
  if (r) {
2082
2226
  let e = r[1], n = r[2], i = r[3];
2083
- return i.length === 2 && (i = String(Kn(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"));
2084
2228
  }
2085
2229
  let i = /^(\d{4})-(\d{2})-(\d{2})$/.exec(n);
2086
2230
  if (i) return K(i[1], i[2], i[3]);
@@ -2090,11 +2234,11 @@ function q(e, t = !1) {
2090
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));
2091
2235
  }
2092
2236
  if (a.length === 6) {
2093
- let e = Kn(Number(a.slice(4, 6)), t);
2237
+ let e = tr(Number(a.slice(4, 6)), t);
2094
2238
  return K(String(e), a.slice(0, 2), a.slice(2, 4));
2095
2239
  }
2096
2240
  }
2097
- function qn(e) {
2241
+ function rr(e) {
2098
2242
  let t = e.trim();
2099
2243
  if (!t || t === "@") return "";
2100
2244
  if (/^(ANSI|AAMVA)\b/.test(t)) {
@@ -2103,10 +2247,10 @@ function qn(e) {
2103
2247
  }
2104
2248
  return t;
2105
2249
  }
2106
- function Jn(e) {
2250
+ function ir(e) {
2107
2251
  return (e.startsWith("DL") || e.startsWith("ID") || e.startsWith("ZV")) && e.length >= 5 && G.has(e.slice(2, 5)) ? e.slice(2) : e;
2108
2252
  }
2109
- function Yn(e, t) {
2253
+ function ar(e, t) {
2110
2254
  let n = 0;
2111
2255
  for (; n < e.length;) {
2112
2256
  let r = e.slice(n, n + 3);
@@ -2125,7 +2269,7 @@ function Yn(e, t) {
2125
2269
  (!(r in t) || a) && (t[r] = a), n = i, (e[n] === "\n" || e[n] === "\r" || e[n] === "") && (n += 1);
2126
2270
  }
2127
2271
  }
2128
- function Xn(e) {
2272
+ function or(e) {
2129
2273
  let t = /(?:ANSI|AAMVA)\s?(\d{6})(\d{2})(\d{2})(\d{2})/.exec(e);
2130
2274
  if (t) return {
2131
2275
  iin: t[1],
@@ -2133,22 +2277,22 @@ function Xn(e) {
2133
2277
  jurisdictionVersion: t[3]
2134
2278
  };
2135
2279
  }
2136
- function Zn(e) {
2280
+ function sr(e) {
2137
2281
  let t = e.replace(/\r\n/g, "\n").replace(/\r/g, "\n"), n = {}, r = t.split("\n").flatMap((e) => e.split(""));
2138
2282
  if (r.some((e) => {
2139
- let t = Jn(qn(e));
2283
+ let t = ir(rr(e));
2140
2284
  return G.has(t.slice(0, 3));
2141
2285
  })) {
2142
2286
  for (let e of r) {
2143
- let t = Jn(qn(e));
2144
- t && Yn(t, n);
2287
+ let t = ir(rr(e));
2288
+ t && ar(t, n);
2145
2289
  }
2146
2290
  return n;
2147
2291
  }
2148
- return Yn(t, n), n;
2292
+ return ar(t, n), n;
2149
2293
  }
2150
- function Qn(e, t) {
2151
- if (Wn.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();
2152
2296
  if (t === "issuerJurisdiction" || t === "country") return e.trim().toUpperCase();
2153
2297
  if (t === "addressPostalCode") {
2154
2298
  let t = e.trim();
@@ -2156,11 +2300,11 @@ function Qn(e, t) {
2156
2300
  }
2157
2301
  return e.trim();
2158
2302
  }
2159
- function $n(e) {
2303
+ function lr(e) {
2160
2304
  let t = {};
2161
2305
  for (let [n, r] of Object.entries(e)) {
2162
- let e = Gn[n];
2163
- e && r.trim() && (t[e] || (t[e] = Qn(r, e)));
2306
+ let e = er[n];
2307
+ e && r.trim() && (t[e] || (t[e] = cr(r, e)));
2164
2308
  }
2165
2309
  if (!t.firstName && e.DCT?.trim()) {
2166
2310
  let n = e.DCT.trim().split(/\s+/);
@@ -2168,29 +2312,29 @@ function $n(e) {
2168
2312
  }
2169
2313
  return t;
2170
2314
  }
2171
- function er(e) {
2172
- let t = Zn(e);
2315
+ function ur(e) {
2316
+ let t = sr(e);
2173
2317
  return {
2174
2318
  rawElements: t,
2175
- fields: $n(t),
2176
- header: Xn(e)
2319
+ fields: lr(t),
2320
+ header: or(e)
2177
2321
  };
2178
2322
  }
2179
- function tr() {
2323
+ function dr() {
2180
2324
  return {};
2181
2325
  }
2182
- function nr(e, t, n) {
2183
- for (let r of Un) t[r] && (e[r] = n);
2326
+ function fr(e, t, n) {
2327
+ for (let r of Qn) t[r] && (e[r] = n);
2184
2328
  return e;
2185
2329
  }
2186
2330
  //#endregion
2187
2331
  //#region src/sdk/face-model.ts
2188
- var rr = /* @__PURE__ */ new Map(), ir = 8400;
2189
- function ar(e, t) {
2332
+ var pr = /* @__PURE__ */ new Map(), mr = 8400;
2333
+ function hr(e, t) {
2190
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));
2191
2335
  return n / Math.max(1, e.width * e.height + t.width * t.height - n);
2192
2336
  }
2193
- function or(e, t, n, r, i, a, o) {
2337
+ function gr(e, t, n, r, i, a, o) {
2194
2338
  return {
2195
2339
  x: (e - n / 2) / i * a,
2196
2340
  y: (t - r / 2) / i * o,
@@ -2198,39 +2342,39 @@ function or(e, t, n, r, i, a, o) {
2198
2342
  height: r / i * o
2199
2343
  };
2200
2344
  }
2201
- function sr(e, t, n) {
2345
+ function _r(e, t, n) {
2202
2346
  let r = t.length === 3 ? t[1] : t[0], i = t.length === 3 ? t[2] : t[1];
2203
- if (i !== 6 || r < 1) throw Error(`Face model expects [1, anchors, 6]. A 640 YOLOX-Nano face export is [1, ${ir}, 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].`);
2204
2348
  let a = n.confidence ?? .35, o = n.inputSize ?? 640, s = [];
2205
2349
  for (let t = 0; t < r; t += 1) {
2206
2350
  let r = t * i, c = e[r + 4] * e[r + 5];
2207
2351
  c < a || s.push({
2208
2352
  confidence: c,
2209
- bbox: or(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)
2210
2354
  });
2211
2355
  }
2212
- return s.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => ar(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);
2213
2357
  }
2214
- async function cr(e, n, r = .35) {
2215
- let i = await M(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");
2216
2360
  o.width = 640, o.height = 640;
2217
2361
  let s = o.getContext("2d", { willReadFrequently: !0 });
2218
2362
  if (!s) throw t();
2219
2363
  s.drawImage(i, 0, 0, 640, 640);
2220
2364
  let c = s.getImageData(0, 0, 640, 640).data, l = 409600, u = new Float32Array(l * 3);
2221
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;
2222
- let d = rr.get(n);
2366
+ let d = pr.get(n);
2223
2367
  d || (d = a.InferenceSession.create(n, {
2224
2368
  executionProviders: ["wasm"],
2225
2369
  graphOptimizationLevel: "all"
2226
- }), rr.set(n, d));
2370
+ }), pr.set(n, d));
2227
2371
  let f = await d, p = (await f.run({ [f.inputNames[0]]: new a.Tensor("float32", u, [
2228
2372
  1,
2229
2373
  3,
2230
2374
  640,
2231
2375
  640
2232
2376
  ]) }))[f.outputNames[0]];
2233
- return sr(p.data, p.dims.map(Number), {
2377
+ return _r(p.data, p.dims.map(Number), {
2234
2378
  confidence: r,
2235
2379
  imageWidth: i.width,
2236
2380
  imageHeight: i.height,
@@ -2239,7 +2383,7 @@ async function cr(e, n, r = .35) {
2239
2383
  }
2240
2384
  //#endregion
2241
2385
  //#region src/sdk/field-model.ts
2242
- var lr = /* @__PURE__ */ new Map(), ur = [
2386
+ var yr = /* @__PURE__ */ new Map(), br = [
2243
2387
  "person_name",
2244
2388
  "date_of_birth",
2245
2389
  "address",
@@ -2247,19 +2391,19 @@ var lr = /* @__PURE__ */ new Map(), ur = [
2247
2391
  "expiration_date",
2248
2392
  "postal_code",
2249
2393
  "state"
2250
- ], dr = 8400;
2251
- function fr(e) {
2394
+ ], xr = 8400;
2395
+ function Sr(e) {
2252
2396
  return 5 + e;
2253
2397
  }
2254
- var pr = 640;
2255
- function mr(e, t) {
2398
+ var Cr = 640;
2399
+ function wr(e, t) {
2256
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));
2257
2401
  return n / Math.max(1, e.bbox.width * e.bbox.height + t.bbox.width * t.bbox.height - n);
2258
2402
  }
2259
- function hr(e) {
2260
- return e.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => t.field !== e.field || mr(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);
2261
2405
  }
2262
- function gr(e, t, n, r, i, a, o) {
2406
+ function Er(e, t, n, r, i, a, o) {
2263
2407
  return {
2264
2408
  x: (e - n / 2) / i * a,
2265
2409
  y: (t - r / 2) / i * o,
@@ -2267,8 +2411,8 @@ function gr(e, t, n, r, i, a, o) {
2267
2411
  height: r / i * o
2268
2412
  };
2269
2413
  }
2270
- function _r(e, t) {
2271
- let n = fr(t);
2414
+ function Dr(e, t) {
2415
+ let n = Sr(t);
2272
2416
  return e.length === 3 && e[0] === 1 && e[2] === n && e[1] > e[2] ? {
2273
2417
  anchors: e[1],
2274
2418
  features: n
@@ -2277,15 +2421,15 @@ function _r(e, t) {
2277
2421
  features: n
2278
2422
  } : null;
2279
2423
  }
2280
- function vr(e) {
2424
+ function Or(e) {
2281
2425
  return e.length === 3 && e[1] >= 5 && e[2] >= 1;
2282
2426
  }
2283
- function yr(e) {
2284
- let t = fr(e);
2285
- 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, ${dr}, ${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}].`);
2286
2430
  }
2287
- function br(e, t, n, r, i, a, o) {
2288
- if (!vr(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.");
2289
2433
  let s = t[1], c = t[2], l = [];
2290
2434
  for (let t = 0; t < c; t += 1) {
2291
2435
  let u = 0, d = 0;
@@ -2297,14 +2441,14 @@ function br(e, t, n, r, i, a, o) {
2297
2441
  !f || u < r || l.push({
2298
2442
  field: f,
2299
2443
  confidence: u,
2300
- bbox: gr(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)
2301
2445
  });
2302
2446
  }
2303
- return hr(l);
2447
+ return Tr(l);
2304
2448
  }
2305
- function xr(e, t, n, r, i, a, o) {
2306
- let s = _r(t, n.length);
2307
- if (!s) throw yr(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);
2308
2452
  let c = [];
2309
2453
  for (let t = 0; t < s.anchors; t += 1) {
2310
2454
  let l = t * s.features, u = e[l + 4], d = 0, f = 0;
@@ -2316,43 +2460,43 @@ function xr(e, t, n, r, i, a, o) {
2316
2460
  !p || m < r || c.push({
2317
2461
  field: p,
2318
2462
  confidence: m,
2319
- bbox: gr(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)
2320
2464
  });
2321
2465
  }
2322
- return hr(c);
2466
+ return Tr(c);
2323
2467
  }
2324
- function Sr(e, t, n) {
2325
- let r = n.classes ?? ur, i = n.confidence ?? .35, a = n.inputSize ?? pr, o = _r(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);
2326
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.");
2327
- return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ? xr(e, t, r, i, a, n.imageWidth, n.imageHeight) : br(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);
2328
2472
  }
2329
- async function Cr(e, n, r = ur, i = .35, a) {
2330
- let o = await M(e, { cloneCanvas: !1 }), s = import("onnxruntime-web"), c = pr, 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");
2331
2475
  l.width = c, l.height = c;
2332
2476
  let u = l.getContext("2d", { willReadFrequently: !0 });
2333
2477
  if (!u) throw t();
2334
2478
  u.drawImage(o, 0, 0, c, c);
2335
2479
  let d = u.getImageData(0, 0, c, c).data, f = c * c, p = new Float32Array(f * 3);
2336
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;
2337
- let m = lr.get(n);
2481
+ let m = yr.get(n);
2338
2482
  m || (m = (async () => {
2339
2483
  try {
2340
- let [e, t] = await Promise.all([s, ae(n)]);
2484
+ let [e, t] = await Promise.all([s, oe(n)]);
2341
2485
  return await e.InferenceSession.create(t, {
2342
2486
  executionProviders: ["wasm"],
2343
2487
  graphOptimizationLevel: "all"
2344
2488
  });
2345
2489
  } catch (e) {
2346
- throw lr.delete(n), e;
2490
+ throw yr.delete(n), e;
2347
2491
  }
2348
- })(), lr.set(n, m));
2492
+ })(), yr.set(n, m));
2349
2493
  let [h, g] = await Promise.all([s, m]), _ = (await g.run({ [g.inputNames[0]]: new h.Tensor("float32", p, [
2350
2494
  1,
2351
2495
  3,
2352
2496
  c,
2353
2497
  c
2354
2498
  ]) }))[g.outputNames[0]];
2355
- return Sr(_.data, _.dims.map(Number), {
2499
+ return Mr(_.data, _.dims.map(Number), {
2356
2500
  classes: r,
2357
2501
  confidence: i,
2358
2502
  layout: a,
@@ -2363,12 +2507,12 @@ async function Cr(e, n, r = ur, i = .35, a) {
2363
2507
  }
2364
2508
  //#endregion
2365
2509
  //#region src/sdk/redact.ts
2366
- async function wr(e, n, r = {}) {
2510
+ async function Pr(e, n, r = {}) {
2367
2511
  await x("redaction");
2368
- let i = await M(e), a = i.getContext("2d");
2512
+ let i = await P(e), a = i.getContext("2d");
2369
2513
  if (!a) throw t();
2370
2514
  for (let e of n) {
2371
- let t = Je(e, i.width, i.height);
2515
+ let t = Ye(e, i.width, i.height);
2372
2516
  if (t.width < 1 || t.height < 1) continue;
2373
2517
  if ((e.mode ?? r.mode ?? "blackout") === "blackout") {
2374
2518
  a.fillStyle = "#050706", a.fillRect(t.x, t.y, t.width, t.height);
@@ -2384,12 +2528,12 @@ async function wr(e, n, r = {}) {
2384
2528
  }
2385
2529
  return {
2386
2530
  canvas: i,
2387
- blob: await qe(i, r.mimeType ?? "image/png", r.quality)
2531
+ blob: await Je(i, r.mimeType ?? "image/png", r.quality)
2388
2532
  };
2389
2533
  }
2390
2534
  //#endregion
2391
2535
  //#region src/sdk/programmatic-redaction.ts
2392
- function J(e) {
2536
+ function q(e) {
2393
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));
2394
2538
  return {
2395
2539
  x: t,
@@ -2398,11 +2542,11 @@ function J(e) {
2398
2542
  height: i - n
2399
2543
  };
2400
2544
  }
2401
- function Tr(e) {
2545
+ function Fr(e) {
2402
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);
2403
2547
  for (let e of n) {
2404
2548
  let n = e.bbox.y + e.bbox.height / 2, r = t.find((t) => {
2405
- let r = J(t), i = r.y + r.height / 2;
2549
+ let r = q(t), i = r.y + r.height / 2;
2406
2550
  return Math.abs(n - i) <= Math.max(e.bbox.height, r.height) * .65;
2407
2551
  });
2408
2552
  r ? r.push(e) : t.push([e]);
@@ -2410,17 +2554,17 @@ function Tr(e) {
2410
2554
  return t.map((e) => (e.sort((e, t) => e.bbox.x - t.bbox.x), {
2411
2555
  words: e,
2412
2556
  text: e.map((e) => e.text).join(" "),
2413
- bbox: J(e)
2557
+ bbox: q(e)
2414
2558
  }));
2415
2559
  }
2416
- function Y(e, t, n = !1) {
2560
+ function J(e, t, n = !1) {
2417
2561
  let r = e.trim().replace(/\s+/g, " "), i = n ? r.replace(/[::]\s*$/, "") : r;
2418
2562
  return t ? i.toLocaleLowerCase() : i;
2419
2563
  }
2420
- function X(e) {
2564
+ function Y(e) {
2421
2565
  return e.reduce((e, t) => e + t.confidence, 0) / Math.max(1, e.length);
2422
2566
  }
2423
- function Er(e, t) {
2567
+ function Ir(e, t) {
2424
2568
  let n = e.mode, r = n === "case-insensitive", i = e.scope ?? "line", a;
2425
2569
  if (n === "regex") {
2426
2570
  let t = e.pattern ?? e.values?.[0];
@@ -2431,14 +2575,14 @@ function Er(e, t) {
2431
2575
  ruleId: e.id,
2432
2576
  strategy: "string",
2433
2577
  source: "string",
2434
- bbox: J(t),
2578
+ bbox: q(t),
2435
2579
  text: t.map((e) => e.text).join(" "),
2436
- confidence: X(t)
2580
+ confidence: Y(t)
2437
2581
  });
2438
2582
  if (i === "word") {
2439
2583
  for (let e of t) for (let t of e.words) {
2440
- let e = Y(t.text, r);
2441
- (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]);
2442
2586
  }
2443
2587
  return s;
2444
2588
  }
@@ -2448,40 +2592,40 @@ function Er(e, t) {
2448
2592
  continue;
2449
2593
  }
2450
2594
  for (let t of o) {
2451
- let n = Y(t, r).split(" ");
2595
+ let n = J(t, r).split(" ");
2452
2596
  for (let t = 0; t <= e.words.length - n.length; t += 1) {
2453
2597
  let i = e.words.slice(t, t + n.length);
2454
- 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);
2455
2599
  }
2456
2600
  }
2457
2601
  }
2458
2602
  return s;
2459
2603
  }
2460
- function Dr(e, t) {
2461
- 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(" ");
2462
2606
  for (let e of t) for (let t = 0; t <= e.words.length - r.length; t += 1) {
2463
2607
  let i = e.words.slice(t, t + r.length);
2464
- 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;
2465
2609
  }
2466
2610
  }
2467
- function Or(e, t, n, r, i, a) {
2611
+ function Rr(e, t, n, r, i, a) {
2468
2612
  let o = a.window?.distance ?? .28, s = a.window?.crossAxis ?? .12, c = t.x + t.width / 2, l = t.y + t.height / 2;
2469
2613
  return e.filter((e) => {
2470
2614
  let a = e.bbox.x + e.bbox.width / 2, u = e.bbox.y + e.bbox.height / 2;
2471
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;
2472
2616
  });
2473
2617
  }
2474
- function kr(e, t, n, r, i, a = "label") {
2475
- let o = Dr(e, n);
2618
+ function zr(e, t, n, r, i, a = "label") {
2619
+ let o = Lr(e, n);
2476
2620
  if (!o) return [];
2477
- 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" ? [
2478
2622
  "right",
2479
2623
  "below",
2480
2624
  "left",
2481
2625
  "above"
2482
2626
  ] : [e.direction], d;
2483
2627
  for (let t of u) {
2484
- let n = Tr(Or(l, s, t, r, i, e));
2628
+ let n = Fr(Rr(l, s, t, r, i, e));
2485
2629
  for (let t of n) {
2486
2630
  if (e.valuePattern && !new RegExp(e.valuePattern, e.patternFlags).test(t.text)) continue;
2487
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);
@@ -2497,12 +2641,12 @@ function kr(e, t, n, r, i, a = "label") {
2497
2641
  ruleId: e.id,
2498
2642
  strategy: a,
2499
2643
  source: a === "template-anchor" ? "template" : "label",
2500
- bbox: J(f),
2644
+ bbox: q(f),
2501
2645
  text: d.words.map((e) => e.text).join(" "),
2502
- 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)))
2503
2647
  }];
2504
2648
  }
2505
- var Ar = {
2649
+ var Br = {
2506
2650
  person_name: [
2507
2651
  "LN",
2508
2652
  "FN",
@@ -2539,32 +2683,32 @@ var Ar = {
2539
2683
  "POSTAL"
2540
2684
  ],
2541
2685
  state: ["STATE", "DAJ"]
2542
- }, jr = new Set(Object.values(Ar).flat()), Mr = /^(?:\d{2}[/-]\d{2}[/-]\d{2,4}|\d{4}[/-]\d{2}[/-]\d{2}|\d{6}|\d{8})$/, Nr = /\b(?:ST|STREET|AVE|AVENUE|RD|ROAD|BLVD|BOULEVARD|LN|LANE|DR|DRIVE|WAY|CT|COURT)\b/i, Pr = /\b(?:DRIVER|LICENSE|IDENTIFICATION|CARD|CLASS|SEX|EYES|HEIGHT|RESTRICTIONS)\b/i;
2543
- 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) {
2544
2688
  let n = t.trim();
2545
- return n ? e === "date_of_birth" || e === "expiration_date" ? Mr.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) && !Pr.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;
2546
2690
  }
2547
- function Q(e, t, n, r, i = 1) {
2691
+ function Z(e, t, n, r, i = 1) {
2548
2692
  return {
2549
2693
  ruleId: e,
2550
2694
  strategy: "semantic",
2551
2695
  source: t,
2552
- bbox: J(n),
2696
+ bbox: q(n),
2553
2697
  text: r ?? n.map((e) => e.text).join(" "),
2554
- confidence: Math.max(0, Math.min(1, X(n) * i))
2698
+ confidence: Math.max(0, Math.min(1, Y(n) * i))
2555
2699
  };
2556
2700
  }
2557
- function Fr(e, t, n) {
2558
- let r = Ar[e], i = [];
2701
+ function Gr(e, t, n) {
2702
+ let r = Br[e], i = [];
2559
2703
  for (let a of n) for (let n = 0; n < a.words.length; n += 1) {
2560
2704
  let o = a.words[n].text.toUpperCase().replace(/[^A-Z0-9]/g, ""), s = r.find((e) => o === e || o.startsWith(e));
2561
2705
  if (!s) continue;
2562
2706
  let c, l;
2563
- o === s ? (c = a.words.slice(n + 1).filter((e) => !jr.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));
2564
2708
  }
2565
2709
  return i;
2566
2710
  }
2567
- function Ir(e, t, n) {
2711
+ function Kr(e, t, n) {
2568
2712
  let r = n.filter((e) => {
2569
2713
  let t = e.text.replace(/\s/g, "");
2570
2714
  return t.includes("<<") || /^[A-Z0-9<]{25,}$/.test(t);
@@ -2574,19 +2718,19 @@ function Ir(e, t, n) {
2574
2718
  let e = r.find((e) => e.text.includes("<<"));
2575
2719
  if (!e) return [];
2576
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();
2577
- return a ? [Q(t, "mrz", e.words, a, .96)] : [];
2721
+ return a ? [Z(t, "mrz", e.words, a, .96)] : [];
2578
2722
  }
2579
2723
  if (e === "date_of_birth") for (let e of r) {
2580
2724
  let n = e.text.replace(/\s/g, ""), r = /^\d{6}/.exec(n)?.[0] ?? /^.{13}(\d{6})/.exec(n)?.[1];
2581
- if (r) return [Q(t, "mrz", e.words, r, .96)];
2725
+ if (r) return [Z(t, "mrz", e.words, r, .96)];
2582
2726
  }
2583
2727
  if (e === "document_number") {
2584
2728
  let e = r[0];
2585
- return [Q(t, "mrz", e.words, e.text, .9)];
2729
+ return [Z(t, "mrz", e.words, e.text, .9)];
2586
2730
  }
2587
2731
  return [];
2588
2732
  }
2589
- function Lr(e) {
2733
+ function qr(e) {
2590
2734
  let t = e.replace(/\s/g, ""), n = t.match(/\d{4}/)?.[0];
2591
2735
  if (n) return Number(n);
2592
2736
  let r = t.match(/^\d{2}/)?.[0];
@@ -2594,67 +2738,67 @@ function Lr(e) {
2594
2738
  let i = Number(r);
2595
2739
  return i > (/* @__PURE__ */ new Date()).getFullYear() % 100 ? 1900 + i : 2e3 + i;
2596
2740
  }
2597
- function Rr(e, t, n, r, i) {
2741
+ function Jr(e, t, n, r, i) {
2598
2742
  if (e === "address") {
2599
- let e = r.findIndex((e) => /\d/.test(e.text) && Nr.test(e.text));
2743
+ let e = r.findIndex((e) => /\d/.test(e.text) && Ur.test(e.text));
2600
2744
  if (e < 0) return [];
2601
2745
  let n = [...r[e].words], i = r[e + 1];
2602
- 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)];
2603
2747
  }
2604
2748
  if (e === "person_name") {
2605
2749
  let e = r.map((e) => {
2606
- 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 && !Pr.test(e.text) && !Nr.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);
2607
2751
  return {
2608
2752
  line: e,
2609
- 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
2610
2754
  };
2611
2755
  }).filter((e) => e.score >= .68).sort((e, t) => t.score - e.score);
2612
- 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)];
2613
2757
  }
2614
2758
  if (e === "date_of_birth" || e === "expiration_date") {
2615
- let r = (/* @__PURE__ */ new Date()).getFullYear(), i = n.filter((e) => Mr.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) => ({
2616
2760
  word: e,
2617
- year: Lr(e.text)
2761
+ year: qr(e.text)
2618
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);
2619
- 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)] : [];
2620
2764
  }
2621
2765
  if (e === "postal_code") {
2622
- let r = n.find((t) => Z(e, t.text));
2623
- 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)] : [];
2624
2768
  }
2625
2769
  if (e === "state") {
2626
- let r = n.filter((t) => Z(e, t.text));
2627
- 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)] : [];
2628
2772
  }
2629
2773
  if (e === "document_number") {
2630
- let r = n.filter((t) => Z(e, t.text));
2631
- 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)] : [];
2632
2776
  }
2633
2777
  return [];
2634
2778
  }
2635
- function zr(e, t) {
2779
+ function Yr(e, t) {
2636
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);
2637
2781
  }
2638
- function Br(e, t, n, r) {
2639
- let i = Fr(e.field, e.id, n), a = Ir(e.field, e.id, n);
2640
- return i.length || a.length ? [...i, ...a] : Rr(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);
2641
2785
  }
2642
- function Vr(e, t, n) {
2786
+ function Zr(e, t, n) {
2643
2787
  let r = (n ?? []).filter((t) => t.field === e.field).sort((e, t) => t.confidence - e.confidence);
2644
2788
  for (let n of r) {
2645
- let r = t.filter((e) => zr(n.bbox, e.bbox) >= .3);
2789
+ let r = t.filter((e) => Yr(n.bbox, e.bbox) >= .3);
2646
2790
  if (!r.length) continue;
2647
2791
  let i = r.map((e) => e.text).join(" ");
2648
- 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);
2649
2793
  }
2650
2794
  }
2651
- function Hr(e, t, n, r, i, a) {
2652
- let o = Br(e, t, n, r);
2795
+ function Qr(e, t, n, r, i, a) {
2796
+ let o = Xr(e, t, n, r);
2653
2797
  if (e.detector !== "model" || !a) return o;
2654
- let s = Vr(e, t, i);
2798
+ let s = Zr(e, t, i);
2655
2799
  return s ? [s] : [];
2656
2800
  }
2657
- function Ur(e, t, n, r) {
2801
+ function $r(e, t, n, r) {
2658
2802
  let i = (e) => Math.max(0, Math.min(1, e)), a = i(e.rect.x), o = i(e.rect.y);
2659
2803
  return {
2660
2804
  ruleId: `${t}.${e.id}`,
@@ -2669,19 +2813,19 @@ function Ur(e, t, n, r) {
2669
2813
  confidence: 1
2670
2814
  };
2671
2815
  }
2672
- function Wr(e, t) {
2673
- let n = t.imageWidth ?? e?.imageWidth ?? 0, r = t.imageHeight ?? e?.imageHeight ?? 0, i = e?.words ?? [], a = Tr(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 = [];
2674
2818
  for (let e of t.rules) {
2675
- let c = e.strategy === "string" ? Er(e, a) : e.strategy === "label" ? kr(e, i, a, n, r) : Hr(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);
2676
2820
  c.length ? o.push(...c) : s.push(e.id);
2677
2821
  }
2678
2822
  for (let e of t.template?.fields ?? []) {
2679
2823
  let c = `${t.template.id}.${e.id}`;
2680
2824
  if (e.strategy === "rect") {
2681
- n && r ? o.push(Ur(e, t.template.id, n, r)) : s.push(c);
2825
+ n && r ? o.push($r(e, t.template.id, n, r)) : s.push(c);
2682
2826
  continue;
2683
2827
  }
2684
- let l = kr({
2828
+ let l = zr({
2685
2829
  ...e,
2686
2830
  id: c,
2687
2831
  strategy: "label"
@@ -2699,34 +2843,34 @@ function Wr(e, t) {
2699
2843
  confidence: u
2700
2844
  };
2701
2845
  }
2702
- function Gr(e) {
2846
+ function ti(e) {
2703
2847
  return e.rules.length > 0 || e.template?.fields.some((e) => e.strategy === "anchor") === !0;
2704
2848
  }
2705
- function Kr(e, t = !1) {
2849
+ function ni(e, t = !1) {
2706
2850
  return t && !e.complete ? "unmatched" : e.complete ? "success" : "partial";
2707
2851
  }
2708
- async function qr(e, t) {
2852
+ async function ri(e, t) {
2709
2853
  await x("redaction");
2710
- let n = await M(e, { cloneCanvas: !1 }), r = t.ocr;
2711
- Gr(t) && !r && (r = await B(n, { includeWords: !0 }));
2854
+ let n = await P(e, { cloneCanvas: !1 }), r = t.ocr;
2855
+ ti(t) && !r && (r = await H(n, { includeWords: !0 }));
2712
2856
  let i = t.semanticDetections, a = t.modelRequested === !0, o = "not-requested", s;
2713
2857
  if (t.models?.fields) try {
2714
- i = await Cr(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";
2715
2859
  } catch (e) {
2716
2860
  s = e instanceof Error ? e.message : "The field model could not load.";
2717
2861
  let n = t.models.allowHeuristicFallback !== !1;
2718
2862
  a = !n, o = n ? "fallback" : "failed";
2719
2863
  }
2720
- let c = Wr(r, {
2864
+ let c = ei(r, {
2721
2865
  rules: t.rules,
2722
2866
  template: t.template,
2723
2867
  imageWidth: n.width,
2724
2868
  imageHeight: n.height,
2725
2869
  semanticDetections: i,
2726
2870
  modelRequested: a
2727
- }), l = Kr(c, t.requireAll), u = [], d = "not-requested", f;
2871
+ }), l = ni(c, t.requireAll), u = [], d = "not-requested", f;
2728
2872
  if (t.models?.face) try {
2729
- u = await cr(n, t.models.face, t.models.faceConfidence), d = "loaded";
2873
+ u = await vr(n, t.models.face, t.models.faceConfidence), d = "loaded";
2730
2874
  } catch (e) {
2731
2875
  f = e instanceof Error ? e.message : "The face model could not load.", d = "failed";
2732
2876
  }
@@ -2740,7 +2884,7 @@ async function qr(e, t) {
2740
2884
  faceStatus: d,
2741
2885
  faceError: f
2742
2886
  };
2743
- let p = await wr(n, [...c.matches.map((e) => ({
2887
+ let p = await Pr(n, [...c.matches.map((e) => ({
2744
2888
  ...e.bbox,
2745
2889
  mode: t.style?.mode
2746
2890
  })), ...u.map((e) => ({
@@ -2762,7 +2906,7 @@ async function qr(e, t) {
2762
2906
  }
2763
2907
  //#endregion
2764
2908
  //#region src/sdk/driver-license.ts
2765
- var Jr = [
2909
+ var ii = [
2766
2910
  {
2767
2911
  id: "issuerJurisdiction",
2768
2912
  strategy: "semantic",
@@ -2799,11 +2943,11 @@ var Jr = [
2799
2943
  field: "person_name"
2800
2944
  }
2801
2945
  ];
2802
- function Yr(e, t, n) {
2946
+ function ai(e, t, n) {
2803
2947
  let r = n.trim();
2804
2948
  if (r) {
2805
2949
  if (t === "expirationDate" || t === "dateOfBirth" || t === "issueDate") {
2806
- e[t] = q(r, t === "dateOfBirth") ?? r;
2950
+ e[t] = nr(r, t === "dateOfBirth") ?? r;
2807
2951
  return;
2808
2952
  }
2809
2953
  if (t === "issuerJurisdiction") {
@@ -2813,8 +2957,8 @@ function Yr(e, t, n) {
2813
2957
  e[t] = r;
2814
2958
  }
2815
2959
  }
2816
- function Xr(e) {
2817
- let t = {}, n = Wr(e, { rules: Jr });
2960
+ function Q(e) {
2961
+ let t = {}, n = ei(e, { rules: ii });
2818
2962
  for (let e of n.matches) {
2819
2963
  let n = e.text?.trim();
2820
2964
  if (n) {
@@ -2823,29 +2967,29 @@ function Xr(e) {
2823
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(" "));
2824
2968
  continue;
2825
2969
  }
2826
- Yr(t, e.ruleId, n);
2970
+ ai(t, e.ruleId, n);
2827
2971
  }
2828
2972
  }
2829
2973
  return t;
2830
2974
  }
2831
- function Zr(e, t) {
2832
- let n = { ...e }, r = nr(tr(), e, "barcode");
2975
+ function oi(e, t) {
2976
+ let n = { ...e }, r = fr(dr(), e, "barcode");
2833
2977
  for (let [e, i] of Object.entries(t)) i && (n[e] || (n[e] = i, r[e] = "ocr"));
2834
2978
  return {
2835
2979
  fields: n,
2836
2980
  sources: r
2837
2981
  };
2838
2982
  }
2839
- async function Qr(e, t, n) {
2840
- return t?.status === "success" && t.corners ? ut(e, t.corners, { maxOutputDimension: n?.maxOutputDimension }) : I(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);
2841
2985
  }
2842
- async function $r(e, t, n) {
2986
+ async function ci(e, t, n) {
2843
2987
  if (!e.width || !e.height) return {
2844
2988
  kind: "retry",
2845
2989
  status: "frontFailed",
2846
2990
  message: "The front photo was empty. Try again."
2847
2991
  };
2848
- let r = await Qr(e, t, n);
2992
+ let r = await si(e, t, n);
2849
2993
  if (r.status !== "success" || !r.canvas) return {
2850
2994
  kind: "retry",
2851
2995
  status: "frontFailed",
@@ -2853,7 +2997,7 @@ async function $r(e, t, n) {
2853
2997
  };
2854
2998
  let i;
2855
2999
  try {
2856
- i = await B(r.canvas, { includeWords: !0 });
3000
+ i = await H(r.canvas, { includeWords: !0 });
2857
3001
  } catch {
2858
3002
  i = void 0;
2859
3003
  }
@@ -2869,7 +3013,7 @@ async function $r(e, t, n) {
2869
3013
  function $() {
2870
3014
  return new DOMException("The barcode scan was cancelled.", "AbortError");
2871
3015
  }
2872
- function ei(e, t) {
3016
+ function li(e, t) {
2873
3017
  return new Promise((n, r) => {
2874
3018
  if (t?.aborted) {
2875
3019
  r($());
@@ -2883,21 +3027,27 @@ function ei(e, t) {
2883
3027
  t?.addEventListener("abort", a, { once: !0 });
2884
3028
  });
2885
3029
  }
2886
- async function ti(e, t = {}) {
3030
+ async function ui(e, t = {}) {
2887
3031
  let n = t.intervalMs ?? 140;
2888
- for (;;) {
3032
+ for (await Hn();;) {
2889
3033
  if (t.signal?.aborted) throw $();
2890
3034
  try {
2891
3035
  let t = await e();
2892
- if (t?.width && t.height && (await W(t))?.text) return t;
3036
+ if (t?.width && t.height) {
3037
+ let e = await Zn(t);
3038
+ if (e?.text) return {
3039
+ frame: t,
3040
+ quad: e.quad
3041
+ };
3042
+ }
2893
3043
  } catch (e) {
2894
3044
  if (t.signal?.aborted) throw $();
2895
- if (e instanceof DOMException && e.name === "AbortError") throw e;
3045
+ if (e instanceof DOMException && e.name === "AbortError" || e instanceof U) throw e;
2896
3046
  }
2897
- await ei(n, t.signal);
3047
+ await li(n, t.signal);
2898
3048
  }
2899
3049
  }
2900
- async function ni(e, t) {
3050
+ async function di(e, t) {
2901
3051
  if (!e.width || !e.height) return {
2902
3052
  status: "backFailed",
2903
3053
  fields: {},
@@ -2907,23 +3057,23 @@ async function ni(e, t) {
2907
3057
  back: {},
2908
3058
  message: "The back photo was empty. Try again."
2909
3059
  };
2910
- let n = (await W(e))?.text, r = {
3060
+ let n = (await Zn(e))?.text, r = {
2911
3061
  canvas: e,
2912
3062
  barcodeText: n
2913
3063
  };
2914
3064
  if (!n) {
2915
- let e = t.ocr ? Xr(t.ocr) : {};
3065
+ let e = t.ocr ? Q(t.ocr) : {};
2916
3066
  return {
2917
3067
  status: "barcodeUnreadable",
2918
3068
  fields: e,
2919
3069
  rawElements: {},
2920
- sources: nr(tr(), e, "ocr"),
3070
+ sources: fr(dr(), e, "ocr"),
2921
3071
  front: t,
2922
3072
  back: r,
2923
3073
  message: "The PDF417 barcode on the back could not be read. Try again."
2924
3074
  };
2925
3075
  }
2926
- let i = er(n), a = t.ocr ? Xr(t.ocr) : {}, o = Zr(i.fields, a);
3076
+ let i = ur(n), a = t.ocr ? Q(t.ocr) : {}, o = oi(i.fields, a);
2927
3077
  return {
2928
3078
  status: "success",
2929
3079
  fields: o.fields,
@@ -2933,10 +3083,10 @@ async function ni(e, t) {
2933
3083
  back: r
2934
3084
  };
2935
3085
  }
2936
- function ri(e) {
3086
+ function fi(e) {
2937
3087
  return e === "back" ? 0 : void 0;
2938
3088
  }
2939
- function ii(e, t) {
3089
+ function pi(e, t) {
2940
3090
  return e === "front" ? {
2941
3091
  title: "Scan a driver’s license",
2942
3092
  headline: "Show the front of the license.",
@@ -2947,7 +3097,7 @@ function ii(e, t) {
2947
3097
  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."
2948
3098
  };
2949
3099
  }
2950
- async function ai(e = {}) {
3100
+ async function mi(e = {}) {
2951
3101
  await x("scan"), await x("ocr");
2952
3102
  let t = "front", n, r = !1;
2953
3103
  return {
@@ -2961,10 +3111,10 @@ async function ai(e = {}) {
2961
3111
  message: "This license scan was cancelled."
2962
3112
  };
2963
3113
  if (t === "front") {
2964
- let r = await $r(i, a, e.scan);
3114
+ let r = await ci(i, a, e.scan);
2965
3115
  return r.kind === "need-back" && (n = r.front, t = "back"), r;
2966
3116
  }
2967
- let o = await ni(i, n ?? {});
3117
+ let o = await di(i, n ?? {});
2968
3118
  return o.status === "backFailed" ? {
2969
3119
  kind: "retry",
2970
3120
  status: "backFailed",
@@ -2980,6 +3130,6 @@ async function ai(e = {}) {
2980
3130
  };
2981
3131
  }
2982
3132
  //#endregion
2983
- export { b as $, I as A, ce as B, Nt as C, ut as D, Ye as E, De as F, le as G, ye as H, j as I, ve as J, ue as K, k as L, dt as M, _e as N, lt as O, ge as P, x as Q, se as R, jt as S, Rt as T, A as U, be as V, Le as W, a as X, re as Y, o as Z, Pt as _, ai as a, St as b, qr as c, er as d, y as et, V as f, Et as g, B as h, Zr as i, ft as j, Qe as k, wr as l, Pn as m, ri as n, t as nt, ti as o, W as p, Fe as q, ii as r, Wr as s, Xr as t, e as tt, q as u, Tt as v, xt as w, Mt as x, Ct as y, Ie as z };
3133
+ export { x as $, R as A, le as B, Pt as C, dt as D, Xe as E, Oe as F, ue as G, be as H, N as I, Ie as J, fe as K, O as L, ft as M, ve as N, ut as O, _e as P, o as Q, ce as R, Mt as S, zt as T, j as U, xe as V, Re as W, ie as X, ye as Y, a as Z, Ft as _, mi as a, Ct as b, ri as c, ur as d, b as et, Mn as f, Dt as g, H as h, oi as i, pt as j, $e as k, Pr as l, Ln as m, fi as n, e as nt, ui as o, Zn as p, de as q, pi as r, t as rt, ei as s, Q as t, y as tt, nr as u, Et as v, St as w, Nt as x, wt as y, Le as z };
2984
3134
 
2985
- //# sourceMappingURL=driver-license-CBDCGp14.js.map
3135
+ //# sourceMappingURL=driver-license-DC8Jb0DE.js.map