@exige/web-scanner-sdk 0.2.24 → 0.2.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -184,7 +184,7 @@ function ee(e) {
184
184
  let t = Number(e.headers.get("content-length"));
185
185
  return Number.isFinite(t) && t > 0 ? t : null;
186
186
  }
187
- function O() {
187
+ function te() {
188
188
  if (w.size === 0) return {
189
189
  downloading: !1,
190
190
  loaded: 0,
@@ -198,22 +198,22 @@ function O() {
198
198
  total: n ? t : null
199
199
  };
200
200
  }
201
- function k() {
202
- let e = O();
201
+ function O() {
202
+ let e = te();
203
203
  for (let t of T) t(e);
204
204
  }
205
- function te(e) {
206
- return e(O()), T.add(e), () => {
205
+ function ne(e) {
206
+ return e(te()), T.add(e), () => {
207
207
  T.delete(e);
208
208
  };
209
209
  }
210
- function A(e, t) {
210
+ function k(e, t) {
211
211
  t.done ? w.delete(e) : w.set(e, {
212
212
  loaded: t.loaded,
213
213
  total: t.total
214
- }), k();
214
+ }), O();
215
215
  }
216
- async function ne(e, t) {
216
+ async function re(e, t) {
217
217
  let n = ee(e);
218
218
  if (!e.body) {
219
219
  let r = await e.arrayBuffer();
@@ -238,53 +238,53 @@ async function ne(e, t) {
238
238
  total: n
239
239
  }), o.buffer;
240
240
  }
241
- async function re(t, n) {
241
+ async function ie(t, n) {
242
242
  let r = E.get(t);
243
243
  if (r) return r.slice(0);
244
244
  let i = D.get(t);
245
245
  if (i) return i.then((e) => e.slice(0));
246
246
  let a = (async () => {
247
- A(t, {
247
+ k(t, {
248
248
  loaded: 0,
249
249
  total: null
250
250
  });
251
251
  let r = await fetch(t, { cache: n?.cache });
252
252
  if (!r.ok) throw new e("model-http", `Model request failed with HTTP ${r.status}.`);
253
- return ne(r, (e) => A(t, e));
253
+ return re(r, (e) => k(t, e));
254
254
  })();
255
255
  D.set(t, a);
256
256
  try {
257
257
  let e = await a;
258
258
  return E.set(t, e), e.slice(0);
259
259
  } finally {
260
- D.delete(t), w.has(t) && (w.delete(t), k());
260
+ D.delete(t), w.has(t) && (w.delete(t), O());
261
261
  }
262
262
  }
263
263
  //#endregion
264
264
  //#region src/sdk/ort-runtime.ts
265
- var ie = new URL("./assets/ort-wasm-simd-threaded.jsep.wasm", import.meta.url), ae = new URL("./assets/ort-wasm-simd-threaded.jsep.mjs", import.meta.url);
266
- function oe() {
265
+ var ae = new URL("./assets/ort-wasm-simd-threaded.jsep.wasm", import.meta.url), oe = new URL("./assets/ort-wasm-simd-threaded.jsep.mjs", import.meta.url);
266
+ function se() {
267
267
  return {
268
- wasm: ie.href,
269
- mjs: ae.href
268
+ wasm: ae.href,
269
+ mjs: oe.href
270
270
  };
271
271
  }
272
- function se(e) {
273
- return typeof e == "string" ? e.trim() || oe() : e?.wasm.trim() && e.mjs.trim() ? {
272
+ function ce(e) {
273
+ return typeof e == "string" ? e.trim() || se() : e?.wasm.trim() && e.mjs.trim() ? {
274
274
  wasm: e.wasm.trim(),
275
275
  mjs: e.mjs.trim()
276
- } : oe();
276
+ } : se();
277
277
  }
278
278
  //#endregion
279
279
  //#region src/sdk/image.ts
280
- function j(e, t, n) {
280
+ function le(e, t, n) {
281
281
  let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
282
282
  return {
283
283
  width: Math.max(1, Math.round(e * r)),
284
284
  height: Math.max(1, Math.round(t * r))
285
285
  };
286
286
  }
287
- async function ce(e) {
287
+ async function ue(e) {
288
288
  let t = URL.createObjectURL(e);
289
289
  try {
290
290
  let e = new Image();
@@ -293,26 +293,26 @@ async function ce(e) {
293
293
  URL.revokeObjectURL(t);
294
294
  }
295
295
  }
296
- async function M(e, n = {}) {
296
+ async function A(e, n = {}) {
297
297
  if (e instanceof HTMLCanvasElement && n.cloneCanvas === !1 && !n.maxDimension) return e;
298
298
  let r = document.createElement("canvas"), i = r.getContext("2d", { willReadFrequently: !0 });
299
299
  if (!i) throw t();
300
300
  if (e instanceof Blob) {
301
301
  if ("createImageBitmap" in window) try {
302
- let t = await createImageBitmap(e), a = j(t.width, t.height, n.maxDimension);
302
+ let t = await createImageBitmap(e), a = le(t.width, t.height, n.maxDimension);
303
303
  return r.width = a.width, r.height = a.height, i.drawImage(t, 0, 0, a.width, a.height), t.close(), r;
304
304
  } catch {}
305
- e = await ce(e);
305
+ e = await ue(e);
306
306
  }
307
307
  let a = e instanceof HTMLImageElement ? e.naturalWidth : e.width, o = e instanceof HTMLImageElement ? e.naturalHeight : e.height;
308
308
  if (!a || !o) throw Error("The image has no readable dimensions.");
309
- let s = j(a, o, n.maxDimension);
309
+ let s = le(a, o, n.maxDimension);
310
310
  return r.width = s.width, r.height = s.height, i.drawImage(e, 0, 0, s.width, s.height), r;
311
311
  }
312
- function le(e, t = "image/png", n = .92) {
312
+ function de(e, t = "image/png", n = .92) {
313
313
  return new Promise((r, i) => e.toBlob((e) => e ? r(e) : i(/* @__PURE__ */ Error("Could not encode the image.")), t, n));
314
314
  }
315
- function ue(e, t, n) {
315
+ function fe(e, t, n) {
316
316
  let r = Math.max(0, Math.min(t, e.x)), i = Math.max(0, Math.min(n, e.y));
317
317
  return {
318
318
  x: r,
@@ -323,20 +323,20 @@ function ue(e, t, n) {
323
323
  }
324
324
  //#endregion
325
325
  //#region src/sdk/scan.ts
326
- var de = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", fe = 1280;
327
- function pe(e, t, n) {
326
+ var pe = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", me = 1280;
327
+ function he(e, t, n) {
328
328
  if (n) return n;
329
- let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a = R() ? 560 : 900;
330
- return i >= 1.6 ? Math.min(r, Math.max(a, fe)) : a;
329
+ let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a = ye() ? 560 : 900;
330
+ return i >= 1.6 ? Math.min(r, Math.max(a, me)) : a;
331
331
  }
332
- function N(e) {
332
+ function j(e) {
333
333
  return e?.trim() || "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
334
334
  }
335
- var me = 3, P, he = 0, F = /* @__PURE__ */ new Map();
336
- function I(e, t) {
335
+ var ge = 3, M, _e = 0, N = /* @__PURE__ */ new Map();
336
+ function P(e, t) {
337
337
  return Math.hypot(e.x - t.x, e.y - t.y);
338
338
  }
339
- function L(e) {
339
+ function F(e) {
340
340
  return {
341
341
  ...e,
342
342
  edges: {
@@ -359,7 +359,7 @@ function L(e) {
359
359
  }
360
360
  };
361
361
  }
362
- function ge(e, t) {
362
+ function ve(e, t) {
363
363
  let n = (e) => ({
364
364
  x: e.x / t,
365
365
  y: e.y / t
@@ -371,42 +371,42 @@ function ge(e, t) {
371
371
  bottomLeft: n(e.bottomLeft)
372
372
  };
373
373
  }
374
- function R() {
374
+ function ye() {
375
375
  return typeof navigator > "u" ? !1 : navigator.maxTouchPoints > 0 || navigator.hardwareConcurrency <= 4 || typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
376
376
  }
377
- function _e(t, n, r, i) {
377
+ function be(t, n, r, i) {
378
378
  return new Promise((a, o) => {
379
- P || (P = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), P.onmessage = (t) => {
379
+ M || (M = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), M.onmessage = (t) => {
380
380
  if (t.data.download?.url) {
381
- A(t.data.download.url, t.data.download);
381
+ k(t.data.download.url, t.data.download);
382
382
  return;
383
383
  }
384
- let n = F.get(t.data.id);
385
- n && (F.delete(t.data.id), t.data.error ? n.reject(t.data.errorCode ? new e(t.data.errorCode, t.data.error) : Error(t.data.error)) : t.data.result ? n.resolve(t.data.result) : n.reject(/* @__PURE__ */ Error("The document worker returned no result.")));
386
- }, P.onerror = () => {
384
+ let n = N.get(t.data.id);
385
+ n && (N.delete(t.data.id), t.data.error ? n.reject(t.data.errorCode ? new e(t.data.errorCode, t.data.error) : Error(t.data.error)) : t.data.result ? n.resolve(t.data.result) : n.reject(/* @__PURE__ */ Error("The document worker returned no result.")));
386
+ }, M.onerror = () => {
387
387
  let t = new e("worker", "The document worker could not start.");
388
- for (let e of F.values()) e.reject(t);
389
- F.clear(), P?.terminate(), P = void 0;
388
+ for (let e of N.values()) e.reject(t);
389
+ N.clear(), M?.terminate(), M = void 0;
390
390
  });
391
- let s = ++he;
392
- F.set(s, {
391
+ let s = ++_e;
392
+ N.set(s, {
393
393
  resolve: a,
394
394
  reject: o
395
395
  });
396
396
  let c = t.slice().buffer;
397
- P.postMessage({
397
+ M.postMessage({
398
398
  id: s,
399
399
  pixels: c,
400
400
  width: n,
401
401
  height: r,
402
- modelUrl: N(i.modelUrl),
402
+ modelUrl: j(i.modelUrl),
403
403
  heatmapThreshold: i.heatmapThreshold,
404
404
  cacheModel: i.cacheModel,
405
- ortWasmPaths: se(i.ortWasmPaths)
405
+ ortWasmPaths: ce(i.ortWasmPaths)
406
406
  }, [c]);
407
407
  });
408
408
  }
409
- async function ve(n, r) {
409
+ async function I(n, r) {
410
410
  let { width: i, height: a } = n, o = r.minDimension ?? 360;
411
411
  if (Math.min(i, a) < o) return {
412
412
  status: "low-quality",
@@ -415,14 +415,14 @@ async function ve(n, r) {
415
415
  sourceWidth: i,
416
416
  sourceHeight: a
417
417
  };
418
- let s = pe(i, a, r.maxAnalysisDimension), c = Math.min(1, s / Math.max(i, a)), l = document.createElement("canvas");
418
+ let s = he(i, a, r.maxAnalysisDimension), c = Math.min(1, s / Math.max(i, a)), l = document.createElement("canvas");
419
419
  l.width = Math.max(1, Math.round(i * c)), l.height = Math.max(1, Math.round(a * c));
420
420
  let u = l.getContext("2d", { willReadFrequently: !0 });
421
421
  if (!u) throw t();
422
422
  u.drawImage(n, 0, 0, l.width, l.height);
423
423
  let d = u.getImageData(0, 0, l.width, l.height).data, f;
424
424
  if (r.useWorker !== !1 && typeof Worker < "u") try {
425
- f = await _e(d, l.width, l.height, r);
425
+ f = await be(d, l.width, l.height, r);
426
426
  } catch (t) {
427
427
  if (t instanceof e && (t.code === "worker" || t.code === "model-http")) throw t;
428
428
  f = {
@@ -446,7 +446,7 @@ async function ve(n, r) {
446
446
  modelNote: y,
447
447
  inferenceMs: b
448
448
  };
449
- if (p < me) return {
449
+ if (p < ge) return {
450
450
  status: "low-quality",
451
451
  confidence: Math.min(.3, p / 18),
452
452
  message: "The image is too soft or dark to resolve four document edges.",
@@ -462,7 +462,7 @@ async function ve(n, r) {
462
462
  sourceHeight: a,
463
463
  ...x
464
464
  };
465
- let S = ge(m.corners, c), C = L(S), w = r.minConfidence ?? .58;
465
+ let S = ve(m.corners, c), C = F(S), w = r.minConfidence ?? .58;
466
466
  return m.confidence < w ? {
467
467
  status: "low-confidence",
468
468
  quad: C,
@@ -483,14 +483,14 @@ async function ve(n, r) {
483
483
  ...x
484
484
  };
485
485
  }
486
- function ye(e, t) {
487
- let n = Math.max(1, Math.round(Math.max(I(e.topLeft, e.topRight), I(e.bottomLeft, e.bottomRight)))), r = Math.max(1, Math.round(Math.max(I(e.topLeft, e.bottomLeft), I(e.topRight, e.bottomRight)))), i = Math.min(1, t / Math.max(n, r));
486
+ function xe(e, t) {
487
+ let n = Math.max(1, Math.round(Math.max(P(e.topLeft, e.topRight), P(e.bottomLeft, e.bottomRight)))), r = Math.max(1, Math.round(Math.max(P(e.topLeft, e.bottomLeft), P(e.topRight, e.bottomRight)))), i = Math.min(1, t / Math.max(n, r));
488
488
  return {
489
489
  width: Math.max(1, Math.round(n * i)),
490
490
  height: Math.max(1, Math.round(r * i))
491
491
  };
492
492
  }
493
- function be(e, t, n, r, i) {
493
+ function Se(e, t, n, r, i) {
494
494
  let a = Math.max(0, Math.min(t - 1, r)), o = Math.max(0, Math.min(n - 1, i)), s = Math.floor(a), c = Math.floor(o), l = Math.min(t - 1, s + 1), u = Math.min(n - 1, c + 1), d = a - s, f = o - c, p = c * t, m = u * t, h = (t) => {
495
495
  let n = e[(p + s) * 4 + t] * (1 - d) + e[(p + l) * 4 + t] * d, r = e[(m + s) * 4 + t] * (1 - d) + e[(m + l) * 4 + t] * d;
496
496
  return Math.round(n * (1 - f) + r * f);
@@ -502,8 +502,8 @@ function be(e, t, n, r, i) {
502
502
  255
503
503
  ];
504
504
  }
505
- function xe(e, n, r) {
506
- let { width: i, height: a } = ye(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
505
+ function L(e, n, r) {
506
+ let { width: i, height: a } = xe(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
507
507
  if (!o) throw t();
508
508
  let s = o.getImageData(0, 0, e.width, e.height), c = document.createElement("canvas");
509
509
  c.width = i, c.height = a;
@@ -513,37 +513,37 @@ function xe(e, n, r) {
513
513
  for (let t = 0; t < a; t += 1) {
514
514
  let n = t / Math.max(1, a - 1);
515
515
  for (let r = 0; r < i; r += 1) {
516
- let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = (w * a + T * n + d.x) / o, l = (E * a + D * n + d.y) / o, [f, p, m, h] = be(s.data, e.width, e.height, c, l), g = (t * i + r) * 4;
516
+ let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = (w * a + T * n + d.x) / o, l = (E * a + D * n + d.y) / o, [f, p, m, h] = Se(s.data, e.width, e.height, c, l), g = (t * i + r) * 4;
517
517
  u.data[g] = f, u.data[g + 1] = p, u.data[g + 2] = m, u.data[g + 3] = h;
518
518
  }
519
519
  }
520
520
  return l.putImageData(u, 0, 0), c;
521
521
  }
522
- async function Se(e, t = {}) {
523
- return await x("scan"), ve(await M(e, { cloneCanvas: !1 }), t);
522
+ async function R(e, t = {}) {
523
+ return await x("scan"), I(await A(e, { cloneCanvas: !1 }), t);
524
524
  }
525
525
  async function Ce(e, t, n = {}) {
526
526
  await x("scan");
527
- let r = await M(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? (R() ? 2048 : 4096);
527
+ let r = await A(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? 4096;
528
528
  return {
529
529
  status: "success",
530
530
  corners: t,
531
- quad: L(t),
531
+ quad: F(t),
532
532
  confidence: 1,
533
533
  message: "Captured with the document edges shown in the finder.",
534
534
  sourceWidth: r.width,
535
535
  sourceHeight: r.height,
536
- canvas: xe(r, t, i)
536
+ canvas: L(r, t, i)
537
537
  };
538
538
  }
539
539
  async function we(e, t = {}) {
540
540
  await x("scan");
541
- let n = await M(e, { cloneCanvas: !1 }), r = await ve(n, t);
541
+ let n = await A(e, { cloneCanvas: !1 }), r = await I(n, t);
542
542
  if (r.status !== "success" || !r.corners) return r;
543
- let i = t.maxOutputDimension ?? (R() ? 2048 : 4096);
543
+ let i = t.maxOutputDimension ?? 4096;
544
544
  return {
545
545
  ...r,
546
- canvas: xe(n, r.corners, i),
546
+ canvas: L(n, r.corners, i),
547
547
  message: "Four document edges detected and perspective-corrected."
548
548
  };
549
549
  }
@@ -595,18 +595,28 @@ function B(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof nav
595
595
  function Ee(e, t) {
596
596
  return t && !e.iosWebKit;
597
597
  }
598
+ function V(e, t) {
599
+ if (!e || !Number.isFinite(e)) return;
600
+ let n = t?.max;
601
+ if (!n || !Number.isFinite(n)) return Math.round(e);
602
+ 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;
603
+ return Math.round(Math.min(n, Math.max(r, a)));
604
+ }
598
605
  function De(e) {
599
- let t = e?.imageWidth?.max, n = e?.imageHeight?.max, r = t && Number.isFinite(t) ? Math.round(t) : void 0, i = n && Number.isFinite(n) ? Math.round(n) : void 0;
600
- if (r && i) return r >= i ? { imageWidth: r } : { imageHeight: i };
601
- if (r) return { imageWidth: r };
602
- if (i) return { imageHeight: i };
606
+ let t = V(e?.imageWidth?.max ?? 0, e?.imageWidth), n = V(e?.imageHeight?.max ?? 0, e?.imageHeight);
607
+ if (t && n) return t >= n ? { imageWidth: t } : { imageHeight: n };
608
+ if (t) return { imageWidth: t };
609
+ if (n) return { imageHeight: n };
603
610
  }
604
611
  function Oe(e, t) {
612
+ return !e.width || !e.height || !t.width || !t.height ? !1 : e.width * e.height > t.width * t.height * 1.15;
613
+ }
614
+ function ke(e, t) {
605
615
  if (!e.width || !e.height || !t.width || !t.height) return !1;
606
616
  let n = e.width / e.height / (t.width / t.height);
607
617
  return n > .97 && n < 1.03;
608
618
  }
609
- var ke = 10, V = class {
619
+ var Ae = 10, H = class {
610
620
  on = !1;
611
621
  darkCount = 0;
612
622
  brightCount = 0;
@@ -629,7 +639,7 @@ var ke = 10, V = class {
629
639
  return this.on;
630
640
  }
631
641
  };
632
- function H(e, t) {
642
+ function U(e, t) {
633
643
  return t ? e === "alwaysOn" || e === "alwaysOff" ? {
634
644
  mode: e,
635
645
  supported: !0,
@@ -653,37 +663,37 @@ function H(e, t) {
653
663
  automatic: e === "auto"
654
664
  };
655
665
  }
656
- function U(e) {
666
+ function W(e) {
657
667
  let t = Math.floor(e.length / 4);
658
668
  if (!t) return 0;
659
669
  let n = 0;
660
670
  for (let r = 0; r < t * 4; r += 4) n += e[r] * .299 + e[r + 1] * .587 + e[r + 2] * .114;
661
671
  return n / t;
662
672
  }
663
- function Ae(e, t = 10) {
673
+ function je(e, t = 10) {
664
674
  if (e.length < 4) return !0;
665
675
  let n = Math.floor(e.length / 4), r = 0;
666
676
  for (let i = 0; i < n * 4; i += 4) e[i] * .299 + e[i + 1] * .587 + e[i + 2] * .114 > t * 2 && (r += 1);
667
- return U(e) <= t && r / n < .01;
677
+ return W(e) <= t && r / n < .01;
668
678
  }
669
- function W(e, t, n) {
679
+ function G(e, t, n) {
670
680
  if (!t || !n) return 0;
671
681
  let r = document.createElement("canvas");
672
682
  r.width = Math.min(32, t), r.height = Math.min(32, n);
673
683
  let i = r.getContext("2d", { willReadFrequently: !0 });
674
- return i ? (i.drawImage(e, 0, 0, r.width, r.height), U(i.getImageData(0, 0, r.width, r.height).data)) : 0;
684
+ return i ? (i.drawImage(e, 0, 0, r.width, r.height), W(i.getImageData(0, 0, r.width, r.height).data)) : 0;
675
685
  }
676
- function G(e) {
677
- return W(e, e.width, e.height);
686
+ function K(e) {
687
+ return G(e, e.width, e.height);
678
688
  }
679
- function je(e, t = 120) {
689
+ function Me(e, t = 120) {
680
690
  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 = () => {
681
691
  a && (o = i ? e.requestVideoFrameCallback(f) : requestAnimationFrame(f));
682
692
  };
683
693
  function f() {
684
694
  if (!a) return;
685
695
  let { videoWidth: i, videoHeight: o } = e, f = performance.now();
686
- r && i && o && f - s >= t && (s = f, l = W(e, i, o), l > 10 && ((n.width !== i || n.height !== o) && (n.width = i, n.height = o), r.drawImage(e, 0, 0, i, o), u = l, c = f)), d();
696
+ r && i && o && f - s >= t && (s = f, l = G(e, i, o), l > 10 && ((n.width !== i || n.height !== o) && (n.width = i, n.height = o), r.drawImage(e, 0, 0, i, o), u = l, c = f)), d();
687
697
  }
688
698
  return d(), {
689
699
  stop() {
@@ -695,14 +705,14 @@ function je(e, t = 120) {
695
705
  getMirrorAgeMs: () => c ? performance.now() - c : Infinity
696
706
  };
697
707
  }
698
- function Me(e) {
708
+ function Ne(e) {
699
709
  let t = document.createElement("canvas");
700
710
  return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
701
711
  }
702
- function Ne(e) {
712
+ function Pe(e) {
703
713
  return e.engine === "blink";
704
714
  }
705
- function K(e = {}, t = B()) {
715
+ function q(e = {}, t = B()) {
706
716
  let n = { ideal: e.idealWidth ?? 3840 }, r = { ideal: e.idealHeight ?? 2160 };
707
717
  e.maxWidth && (n.max = e.maxWidth), e.maxHeight && (r.max = e.maxHeight);
708
718
  let i = {
@@ -714,20 +724,20 @@ function K(e = {}, t = B()) {
714
724
  max: e.maxFrameRate ?? 30
715
725
  }
716
726
  };
717
- return Ne(t) && (i.resizeMode = { ideal: "none" }), {
727
+ return Pe(t) && (i.resizeMode = { ideal: "none" }), {
718
728
  audio: !1,
719
729
  video: i
720
730
  };
721
731
  }
722
- function q(e, t, n) {
732
+ function Fe(e, t, n) {
723
733
  let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
724
734
  return {
725
735
  width: Math.max(1, Math.round(e * r)),
726
736
  height: Math.max(1, Math.round(t * r))
727
737
  };
728
738
  }
729
- var J = 4096;
730
- function Pe(e, t) {
739
+ var Ie = 4096;
740
+ function Le(e, t) {
731
741
  let n = e.width, r = e.height, i = t?.width?.max, a = t?.height?.max;
732
742
  if (!n || !r || !i || !a) return;
733
743
  let o = Math.min(i / n, a / r);
@@ -736,64 +746,92 @@ function Pe(e, t) {
736
746
  height: { ideal: Math.round(r * o) }
737
747
  };
738
748
  }
739
- async function Fe(e) {
740
- let t = Pe(e.getSettings(), typeof e.getCapabilities == "function" ? e.getCapabilities() : void 0);
749
+ async function Re(e) {
750
+ let t = Le(e.getSettings(), typeof e.getCapabilities == "function" ? e.getCapabilities() : void 0);
741
751
  if (t) try {
742
752
  await e.applyConstraints(t);
743
753
  } catch {}
744
754
  }
745
- async function Ie(e) {
746
- let n = globalThis.ImageCapture;
747
- if (!n) return;
748
- let r = new n(e), i;
755
+ async function ze(e) {
756
+ try {
757
+ return await createImageBitmap(e, {
758
+ imageOrientation: "from-image",
759
+ colorSpaceConversion: "none"
760
+ });
761
+ } catch {
762
+ return await createImageBitmap(e);
763
+ }
764
+ }
765
+ async function Be(e) {
766
+ try {
767
+ await e.applyConstraints({ advanced: [{ pointsOfInterest: [{
768
+ x: .5,
769
+ y: .5
770
+ }] }] }), await new Promise((e) => window.setTimeout(e, 180));
771
+ } catch {}
772
+ }
773
+ async function Ve(e) {
774
+ let n = await ze(e), r = Fe(n.width, n.height, Ie), i = document.createElement("canvas");
775
+ i.width = r.width, i.height = r.height;
776
+ let a = i.getContext("2d");
777
+ if (!a) throw n.close?.(), t();
778
+ 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;
779
+ }
780
+ async function He(e) {
781
+ let t = globalThis.ImageCapture;
782
+ if (!t) return;
783
+ await Be(e);
784
+ let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i = De(r), a;
749
785
  try {
750
- let e = r.getPhotoCapabilities ? De(await r.getPhotoCapabilities()) : void 0;
751
- i = await r.takePhoto(e);
786
+ a = await n.takePhoto(i);
752
787
  } catch {
753
- i = await r.takePhoto();
788
+ a = await n.takePhoto();
754
789
  }
755
- let a = await createImageBitmap(i), o = q(a.width, a.height, J), s = document.createElement("canvas");
756
- s.width = o.width, s.height = o.height;
757
- let c = s.getContext("2d");
758
- if (!c) throw a.close?.(), t();
759
- return c.imageSmoothingEnabled = o.width !== a.width || o.height !== a.height, c.imageSmoothingQuality = "high", c.drawImage(a, 0, 0, s.width, s.height), a.close?.(), s;
790
+ return {
791
+ frame: await Ve(a),
792
+ requested: i,
793
+ photoMax: {
794
+ width: r?.imageWidth?.max,
795
+ height: r?.imageHeight?.max
796
+ }
797
+ };
760
798
  }
761
- function Y(e, n) {
799
+ function J(e, n) {
762
800
  if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
763
- let r = q(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
801
+ let r = Fe(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
764
802
  i.width = r.width, i.height = r.height;
765
803
  let a = i.getContext("2d");
766
804
  if (!a) throw t();
767
805
  return a.drawImage(e, 0, 0, i.width, i.height), i;
768
806
  }
769
- function Le(e) {
807
+ function Ue(e) {
770
808
  let t = B();
771
- return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [K(e, t)] : [
772
- K({
809
+ return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [q(e, t)] : [
810
+ q({
773
811
  ...e,
774
812
  idealWidth: 3840,
775
813
  idealHeight: 2160
776
814
  }, t),
777
- K({
815
+ q({
778
816
  ...e,
779
817
  idealWidth: 2560,
780
818
  idealHeight: 1440
781
819
  }, t),
782
- K({
820
+ q({
783
821
  ...e,
784
822
  idealWidth: 1920,
785
823
  idealHeight: 1080
786
824
  }, t)
787
825
  ];
788
826
  }
789
- async function Re(t, n = {}) {
827
+ async function We(t, n = {}) {
790
828
  await x("scan");
791
829
  let r = n.torch ?? "alwaysOff";
792
830
  if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
793
831
  if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
794
832
  t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
795
833
  let i, a;
796
- for (let e of Le(n)) try {
834
+ for (let e of Ue(n)) try {
797
835
  i = await navigator.mediaDevices.getUserMedia(e);
798
836
  break;
799
837
  } catch (e) {
@@ -806,8 +844,8 @@ async function Re(t, n = {}) {
806
844
  for (let e of i.getTracks()) e.stop();
807
845
  throw Error("The camera did not provide a video track.");
808
846
  }
809
- await Fe(o);
810
- let s = je(t), c = "ImageCapture" in globalThis, l = H(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
847
+ await Re(o);
848
+ let s = Me(t), c = "ImageCapture" in globalThis, l = U(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
811
849
  if (!l.supported || o.readyState !== "live") return !1;
812
850
  try {
813
851
  return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
@@ -825,7 +863,7 @@ async function Re(t, n = {}) {
825
863
  }
826
864
  };
827
865
  l.on && await d(!0);
828
- let f = r === "auto" && l.supported ? new V() : void 0, p = f ? window.setInterval(() => {
866
+ let f = r === "auto" && l.supported ? new H() : void 0, p = f ? window.setInterval(() => {
829
867
  if (u || !l.supported) return;
830
868
  let e = f.update(s.getLiveLuminance());
831
869
  e !== void 0 && e !== l.on && (u = !0, d(e).finally(() => {
@@ -865,50 +903,55 @@ async function Re(t, n = {}) {
865
903
  get torchOn() {
866
904
  return l.on;
867
905
  },
868
- capture: (e) => Y(t, e),
906
+ capture: (e) => J(t, e),
869
907
  async capturePhoto() {
870
908
  let e, n = 0;
871
909
  try {
872
- e = Y(t), n = G(e);
910
+ e = J(t), n = K(e);
873
911
  } catch {
874
912
  e = void 0;
875
913
  }
876
- let r = s.getFrame(), i, a = !1;
914
+ let r = s.getFrame(), i, a = !1, l = !1, u, d;
877
915
  if (Ee(B(), c)) try {
878
- i = await Ie(o);
916
+ let e = await He(o);
917
+ i = e?.frame, u = e?.requested, d = e?.photoMax;
879
918
  } catch {
880
919
  a = !0, i = void 0;
881
920
  }
882
- let l = i ? G(i) : 0;
883
- if (i && l > 10) return console.info("[exige-scanner] capture", {
921
+ let f = {
922
+ width: t.videoWidth,
923
+ height: t.videoHeight
924
+ }, p = i ? K(i) : 0, h = !!(i && p > 10 && Oe(i, f));
925
+ if (i && p > 10 && !h && (l = !0), h && i) return console.info("[exige-scanner] capture", {
884
926
  method: "image-capture",
885
927
  frame: `${i.width}×${i.height}`,
886
928
  video: `${t.videoWidth}×${t.videoHeight}`,
887
- aspectMatch: Oe(i, {
888
- width: t.videoWidth,
889
- height: t.videoHeight
890
- })
929
+ photoMax: d ? `${d.width ?? "—"}×${d.height ?? "—"}` : void 0,
930
+ photoRequest: u,
931
+ aspectMatch: ke(i, f)
891
932
  }), {
892
933
  frame: i,
893
934
  method: "image-capture",
894
935
  settings: o.getSettings(),
895
- luminance: l,
936
+ luminance: p,
896
937
  diagnostics: m()
897
938
  };
898
- let u = e && n > 10 ? e : void 0, d = u ?? (r ? Me(r) : void 0);
899
- if (!d) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
900
- let f = i ? "image-capture-empty" : a ? "image-capture-failed" : u ? void 0 : "video-frame-empty";
939
+ let g = e && n > 10 ? e : void 0, _ = g ?? (r ? Ne(r) : void 0);
940
+ if (!_) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
941
+ let v = l ? "image-capture-preview-size" : i ? "image-capture-empty" : a ? "image-capture-failed" : g ? void 0 : "video-frame-empty";
901
942
  return console.info("[exige-scanner] capture", {
902
- method: u ? "video-frame" : "live-mirror",
903
- frame: `${d.width}×${d.height}`,
943
+ method: g ? "video-frame" : "live-mirror",
944
+ frame: `${_.width}×${_.height}`,
904
945
  video: `${t.videoWidth}×${t.videoHeight}`,
905
- fallbackReason: f
946
+ photoMax: d ? `${d.width ?? "—"}×${d.height ?? "—"}` : void 0,
947
+ photoRequest: u,
948
+ fallbackReason: v
906
949
  }), {
907
- frame: d,
908
- method: u ? "video-frame" : "live-mirror",
950
+ frame: _,
951
+ method: g ? "video-frame" : "live-mirror",
909
952
  settings: o.getSettings(),
910
- fallbackReason: f,
911
- luminance: u ? n : s.getMirrorLuminance(),
953
+ fallbackReason: v,
954
+ luminance: g ? n : s.getMirrorLuminance(),
912
955
  diagnostics: m()
913
956
  };
914
957
  },
@@ -925,14 +968,25 @@ async function Re(t, n = {}) {
925
968
  }
926
969
  };
927
970
  }
971
+ async function Ge() {
972
+ let e = document.createElement("input");
973
+ return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"), Ve(await new Promise((t, n) => {
974
+ e.addEventListener("change", () => {
975
+ let r = e.files?.[0];
976
+ r ? t(r) : n(/* @__PURE__ */ Error("No photo was selected."));
977
+ }, { once: !0 }), e.addEventListener("cancel", () => {
978
+ n(/* @__PURE__ */ Error("No photo was selected."));
979
+ }, { once: !0 }), e.click();
980
+ }));
981
+ }
928
982
  //#endregion
929
983
  //#region src/sdk/lighting.ts
930
- function ze(e, t) {
984
+ function Ke(e, t) {
931
985
  if (!e.length) return 0;
932
986
  let n = [...e].sort((e, t) => e - t);
933
987
  return n[Math.min(n.length - 1, Math.floor(n.length * t))];
934
988
  }
935
- function X(e, t, n, r = 12) {
989
+ function qe(e, t, n, r = 12) {
936
990
  if (!t || !n || e.length < t * n) return {
937
991
  strong: !1,
938
992
  strength: 0,
@@ -955,7 +1009,7 @@ function X(e, t, n, r = 12) {
955
1009
  });
956
1010
  }
957
1011
  }
958
- let s = ze(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
1012
+ let s = Ke(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
959
1013
  for (let e = 0; e < o.length; e += 1) {
960
1014
  if (!c[e] || l[e]) continue;
961
1015
  let t = [], n = [e];
@@ -1003,11 +1057,11 @@ function X(e, t, n, r = 12) {
1003
1057
  }
1004
1058
  return d;
1005
1059
  }
1006
- function Be(e, t, n, r, i, a, o) {
1060
+ function Je(e, t, n, r, i, a, o) {
1007
1061
  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));
1008
1062
  return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
1009
1063
  }
1010
- function Ve(e, t, n) {
1064
+ function Y(e, t, n) {
1011
1065
  let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
1012
1066
  for (let a = 1; a <= n; a += 1) {
1013
1067
  let n = 0;
@@ -1018,23 +1072,23 @@ function Ve(e, t, n) {
1018
1072
  stride: r
1019
1073
  };
1020
1074
  }
1021
- function He(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
1022
- let { integral: i, stride: a } = Ve(e, t, n), o = new Uint8Array(e.length);
1075
+ function Ye(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
1076
+ let { integral: i, stride: a } = Y(e, t, n), o = new Uint8Array(e.length);
1023
1077
  for (let s = 0; s < n; s += 1) for (let c = 0; c < t; c += 1) {
1024
- let l = Be(i, a, t, n, c, s, r);
1078
+ let l = Je(i, a, t, n, c, s, r);
1025
1079
  o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
1026
1080
  }
1027
1081
  return o;
1028
1082
  }
1029
- function Ue(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
1030
- let { integral: a, stride: o } = Ve(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
1083
+ function Xe(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
1084
+ let { integral: a, stride: o } = Y(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
1031
1085
  for (let i = 0; i < n; i += 1) for (let l = 0; l < t; l += 1) {
1032
- let u = Be(a, o, t, n, l, i, r);
1086
+ let u = Je(a, o, t, n, l, i, r);
1033
1087
  s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
1034
1088
  }
1035
1089
  return s;
1036
1090
  }
1037
- function We(e, t, n) {
1091
+ function Ze(e, t, n) {
1038
1092
  let r = [
1039
1093
  e.topLeft,
1040
1094
  e.topRight,
@@ -1048,8 +1102,8 @@ function We(e, t, n) {
1048
1102
  height: s - a
1049
1103
  };
1050
1104
  }
1051
- function Ge(e, t) {
1052
- let n = We(t, e.width, e.height);
1105
+ function Qe(e, t) {
1106
+ let n = Ze(t, e.width, e.height);
1053
1107
  if (n.width <= 0 || n.height <= 0) return {
1054
1108
  strong: !1,
1055
1109
  strength: 0,
@@ -1068,18 +1122,18 @@ function Ge(e, t) {
1068
1122
  i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
1069
1123
  let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
1070
1124
  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);
1071
- return X(o, r.width, r.height);
1125
+ return qe(o, r.width, r.height);
1072
1126
  }
1073
1127
  //#endregion
1074
1128
  //#region src/sdk/finder.ts
1075
- function Ke(e, t) {
1129
+ function $e(e, t) {
1076
1130
  return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
1077
1131
  }
1078
- async function qe(e, t) {
1132
+ async function et(e, t) {
1079
1133
  let n = await e();
1080
1134
  return t(), n;
1081
1135
  }
1082
- function Je(e) {
1136
+ function tt(e) {
1083
1137
  return e === "alwaysOn" || e === "only" ? {
1084
1138
  visible: !1,
1085
1139
  checked: !0,
@@ -1094,7 +1148,7 @@ function Je(e) {
1094
1148
  mutable: !0
1095
1149
  };
1096
1150
  }
1097
- function Z(e) {
1151
+ function X(e) {
1098
1152
  return [
1099
1153
  e.topLeft,
1100
1154
  e.topRight,
@@ -1102,7 +1156,7 @@ function Z(e) {
1102
1156
  e.bottomLeft
1103
1157
  ];
1104
1158
  }
1105
- function Ye(e, t) {
1159
+ function nt(e, t) {
1106
1160
  let n = e.status === "success" && e.modelStatus !== "failed", r = {
1107
1161
  status: e.status,
1108
1162
  confidence: Number(e.confidence.toFixed(3)),
@@ -1125,7 +1179,7 @@ function Ye(e, t) {
1125
1179
  detail: r
1126
1180
  };
1127
1181
  }
1128
- function Xe(e) {
1182
+ function rt(e) {
1129
1183
  let t = 0;
1130
1184
  for (let n = 0; n < e.length; n += 1) {
1131
1185
  let r = e[n], i = e[(n + 1) % e.length];
@@ -1133,42 +1187,42 @@ function Xe(e) {
1133
1187
  }
1134
1188
  return Math.abs(t) / 2;
1135
1189
  }
1136
- function Q(e, t) {
1190
+ function Z(e, t) {
1137
1191
  return Math.hypot(e.x - t.x, e.y - t.y);
1138
1192
  }
1139
- var $ = {
1193
+ var Q = {
1140
1194
  widthFill: 0,
1141
1195
  heightFill: 0,
1142
1196
  limitingFill: 0,
1143
1197
  areaFill: 0,
1144
1198
  aspectRatio: 1
1145
1199
  };
1146
- function Ze(e, t, n) {
1147
- let r = Z(e), i = r.map(({ x: e }) => e), a = r.map(({ y: e }) => e), o = (Math.max(...i) - Math.min(...i)) / Math.max(1, t), s = (Math.max(...a) - Math.min(...a)) / Math.max(1, n), [c, l, u, d] = r, f = Math.max(Q(c, l), Q(d, u)), p = Math.max(Q(c, d), Q(l, u));
1200
+ function it(e, t, n) {
1201
+ let r = X(e), i = r.map(({ x: e }) => e), a = r.map(({ y: e }) => e), o = (Math.max(...i) - Math.min(...i)) / Math.max(1, t), s = (Math.max(...a) - Math.min(...a)) / Math.max(1, n), [c, l, u, d] = r, f = Math.max(Z(c, l), Z(d, u)), p = Math.max(Z(c, d), Z(l, u));
1148
1202
  return {
1149
1203
  widthFill: o,
1150
1204
  heightFill: s,
1151
1205
  limitingFill: Math.max(o, s),
1152
- areaFill: Xe(r) / Math.max(1, t * n),
1206
+ areaFill: rt(r) / Math.max(1, t * n),
1153
1207
  aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
1154
1208
  };
1155
1209
  }
1156
- function Qe(e, t, n, r = {}) {
1210
+ function at(e, t, n, r = {}) {
1157
1211
  let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
1158
1212
  if (e.aspectRatio < a) return i;
1159
1213
  let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
1160
1214
  return Math.min(o ?? i + .08, 1 - n * 2);
1161
1215
  }
1162
- function $e(e, t, n = {}) {
1216
+ function ot(e, t, n = {}) {
1163
1217
  let r = n.confidenceThreshold ?? .72;
1164
1218
  if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
1165
1219
  hint: "Place the document in the frame",
1166
1220
  reason: "place-document",
1167
1221
  fillRatio: 0,
1168
- fill: $,
1222
+ fill: Q,
1169
1223
  readyForAutoCapture: !1
1170
1224
  };
1171
- let i = Z(e.quad), a = Ze(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;
1225
+ let i = X(e.quad), a = it(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;
1172
1226
  if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
1173
1227
  hint: "Move farther away",
1174
1228
  reason: "move-farther-away",
@@ -1176,14 +1230,14 @@ function $e(e, t, n = {}) {
1176
1230
  fill: a,
1177
1231
  readyForAutoCapture: !1
1178
1232
  };
1179
- let [u, d, f, p] = i, m = Q(u, d), h = Q(d, f), g = Q(f, p), _ = Q(p, u);
1233
+ let [u, d, f, p] = i, m = Z(u, d), h = Z(d, f), g = Z(f, p), _ = Z(p, u);
1180
1234
  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) ? {
1181
1235
  hint: "Hold the camera straight",
1182
1236
  reason: "straighten-camera",
1183
1237
  fillRatio: o,
1184
1238
  fill: a,
1185
1239
  readyForAutoCapture: !1
1186
- } : o < Qe(a, t.previouslyReady === !0, s, n) ? {
1240
+ } : o < at(a, t.previouslyReady === !0, s, n) ? {
1187
1241
  hint: "Move closer",
1188
1242
  reason: "move-closer",
1189
1243
  fillRatio: o,
@@ -1197,7 +1251,7 @@ function $e(e, t, n = {}) {
1197
1251
  readyForAutoCapture: t.ready
1198
1252
  };
1199
1253
  }
1200
- var et = class {
1254
+ var $ = class {
1201
1255
  previous;
1202
1256
  count = 0;
1203
1257
  ready = !1;
@@ -1214,8 +1268,8 @@ var et = class {
1214
1268
  ready: !1,
1215
1269
  movement: Infinity
1216
1270
  };
1217
- let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...Z(e.quad).map((e, n) => {
1218
- let r = Z(this.previous)[n];
1271
+ let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...X(e.quad).map((e, n) => {
1272
+ let r = X(this.previous)[n];
1219
1273
  return Math.hypot(e.x - r.x, e.y - r.y) / Math.max(1, t);
1220
1274
  })) : Infinity, r = this.options.exitCornerTolerance ?? Math.max(this.options.cornerTolerance, .036);
1221
1275
  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, {
@@ -1225,14 +1279,14 @@ var et = class {
1225
1279
  };
1226
1280
  }
1227
1281
  };
1228
- function tt(e, n) {
1282
+ function st(e, n) {
1229
1283
  let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
1230
1284
  i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
1231
1285
  let a = i.getContext("2d");
1232
1286
  if (!a) throw t();
1233
1287
  return a.drawImage(e, 0, 0, i.width, i.height), i;
1234
1288
  }
1235
- function nt() {
1289
+ function ct() {
1236
1290
  let e = window.AudioContext ?? window.webkitAudioContext;
1237
1291
  if (!e) return;
1238
1292
  let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
@@ -1243,13 +1297,13 @@ function nt() {
1243
1297
  let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
1244
1298
  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();
1245
1299
  }
1246
- async function rt(e) {
1300
+ async function lt(e) {
1247
1301
  let t = document.createElement("video");
1248
1302
  return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
1249
1303
  }
1250
- async function it(t) {
1304
+ async function ut(t) {
1251
1305
  await x("scan");
1252
- let n = Je(t.autoCapture), r = new et({
1306
+ let n = tt(t.autoCapture), r = new $({
1253
1307
  stableFrames: t.stableFrames ?? 4,
1254
1308
  confidenceThreshold: t.confidenceThreshold ?? .72,
1255
1309
  cornerTolerance: t.cornerTolerance ?? .024,
@@ -1258,14 +1312,14 @@ async function it(t) {
1258
1312
  minDimension: 220,
1259
1313
  maxAnalysisDimension: 520,
1260
1314
  ...t.detection
1261
- }, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await rt(t.source) : t.source, c = !0, l = !1, u = !1, d = 0, f, p = "", m = 0, h = {
1315
+ }, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await lt(t.source) : t.source, c = !0, l = !1, u = !1, d = 0, f, p = "", m = 0, h = {
1262
1316
  state: "detecting",
1263
1317
  confidence: 0,
1264
1318
  guidance: {
1265
1319
  hint: "Place the document in the frame",
1266
1320
  reason: "place-document",
1267
1321
  fillRatio: 0,
1268
- fill: $,
1322
+ fill: Q,
1269
1323
  readyForAutoCapture: !1
1270
1324
  },
1271
1325
  lighting: {
@@ -1275,10 +1329,10 @@ async function it(t) {
1275
1329
  stableFrames: 0,
1276
1330
  requiredStableFrames: t.stableFrames ?? 4,
1277
1331
  autoCapture: { ...n }
1278
- }, g = () => s instanceof HTMLCanvasElement ? tt(s, i) : Y(s, i), _ = (e) => {
1332
+ }, g = () => s instanceof HTMLCanvasElement ? st(s, i) : J(s, i), _ = (e) => {
1279
1333
  h = e, t.onStatus?.(e);
1280
1334
  }, v = (e) => {
1281
- let t = Ye(e, s instanceof HTMLVideoElement ? {
1335
+ let t = nt(e, s instanceof HTMLVideoElement ? {
1282
1336
  width: s.videoWidth,
1283
1337
  height: s.videoHeight
1284
1338
  } : {
@@ -1293,11 +1347,11 @@ async function it(t) {
1293
1347
  l = !0;
1294
1348
  let n;
1295
1349
  try {
1296
- n = await qe(t.captureFrame ?? g, () => {
1350
+ n = await et(t.captureFrame ?? g, () => {
1297
1351
  _({
1298
1352
  ...h,
1299
1353
  state: "captured"
1300
- }), t.playShutterSound !== !1 && nt(), y();
1354
+ }), t.playShutterSound !== !1 && ct(), y();
1301
1355
  });
1302
1356
  } catch (e) {
1303
1357
  throw l = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
@@ -1311,9 +1365,9 @@ async function it(t) {
1311
1365
  }, S = async () => {
1312
1366
  if (c && !l) {
1313
1367
  try {
1314
- let e = g(), i = await Se(e, o);
1368
+ let e = g(), i = await R(e, o);
1315
1369
  f = i, v(i);
1316
- let a = i.quad ? Ge(e, i.quad) : {
1370
+ let a = i.quad ? Qe(e, i.quad) : {
1317
1371
  strong: !1,
1318
1372
  strength: 0
1319
1373
  }, s = a.strong ? {
@@ -1323,7 +1377,7 @@ async function it(t) {
1323
1377
  } : {
1324
1378
  castShadow: !1,
1325
1379
  strength: a.strength
1326
- }, c = r.update(i), l = $e(i, {
1380
+ }, c = r.update(i), l = ot(i, {
1327
1381
  ...c,
1328
1382
  previouslyReady: u
1329
1383
  }, {
@@ -1376,7 +1430,7 @@ async function it(t) {
1376
1430
  hint: "Place the document in the frame",
1377
1431
  reason: "place-document",
1378
1432
  fillRatio: 0,
1379
- fill: $,
1433
+ fill: Q,
1380
1434
  readyForAutoCapture: !1
1381
1435
  },
1382
1436
  lighting: {
@@ -1405,6 +1459,6 @@ async function it(t) {
1405
1459
  };
1406
1460
  }
1407
1461
  //#endregion
1408
- export { re as A, Ce as C, le as D, we as E, b as F, y as I, e as L, a as M, o as N, ue as O, x as P, t as R, de as S, N as T, Ae as _, $e as a, Re as b, Ue as c, V as d, ke as f, Te as g, B as h, Ze as i, te as j, M as k, X as l, Y as m, Je as n, Ke as o, J as p, Qe as r, it as s, et as t, He as u, U as v, Se as w, H as x, K as y };
1462
+ export { A, pe as C, we as D, j as E, x as F, b as I, y as L, ne as M, a as N, de as O, o as P, e as R, U as S, R as T, je as _, ot as a, Ge as b, Xe as c, H as d, Ae as f, Te as g, B as h, it as i, ie as j, fe as k, qe as l, J as m, tt as n, $e as o, Ie as p, at as r, ut as s, $ as t, Ye as u, W as v, Ce as w, We as x, q as y, t as z };
1409
1463
 
1410
- //# sourceMappingURL=finder-B3kHQ2Jh.js.map
1464
+ //# sourceMappingURL=finder-B3t_3g6Z.js.map