@exige/web-scanner-sdk 0.2.23 → 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,19 +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;
600
- if (t && n && Number.isFinite(t) && Number.isFinite(n)) return {
601
- imageWidth: Math.round(t),
602
- imageHeight: Math.round(n)
603
- };
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 };
604
610
  }
605
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) {
606
615
  if (!e.width || !e.height || !t.width || !t.height) return !1;
607
616
  let n = e.width / e.height / (t.width / t.height);
608
617
  return n > .97 && n < 1.03;
609
618
  }
610
- var ke = 10, V = class {
619
+ var Ae = 10, H = class {
611
620
  on = !1;
612
621
  darkCount = 0;
613
622
  brightCount = 0;
@@ -630,7 +639,7 @@ var ke = 10, V = class {
630
639
  return this.on;
631
640
  }
632
641
  };
633
- function H(e, t) {
642
+ function U(e, t) {
634
643
  return t ? e === "alwaysOn" || e === "alwaysOff" ? {
635
644
  mode: e,
636
645
  supported: !0,
@@ -654,37 +663,37 @@ function H(e, t) {
654
663
  automatic: e === "auto"
655
664
  };
656
665
  }
657
- function U(e) {
666
+ function W(e) {
658
667
  let t = Math.floor(e.length / 4);
659
668
  if (!t) return 0;
660
669
  let n = 0;
661
670
  for (let r = 0; r < t * 4; r += 4) n += e[r] * .299 + e[r + 1] * .587 + e[r + 2] * .114;
662
671
  return n / t;
663
672
  }
664
- function Ae(e, t = 10) {
673
+ function je(e, t = 10) {
665
674
  if (e.length < 4) return !0;
666
675
  let n = Math.floor(e.length / 4), r = 0;
667
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);
668
- return U(e) <= t && r / n < .01;
677
+ return W(e) <= t && r / n < .01;
669
678
  }
670
- function W(e, t, n) {
679
+ function G(e, t, n) {
671
680
  if (!t || !n) return 0;
672
681
  let r = document.createElement("canvas");
673
682
  r.width = Math.min(32, t), r.height = Math.min(32, n);
674
683
  let i = r.getContext("2d", { willReadFrequently: !0 });
675
- 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;
676
685
  }
677
- function G(e) {
678
- return W(e, e.width, e.height);
686
+ function K(e) {
687
+ return G(e, e.width, e.height);
679
688
  }
680
- function je(e, t = 120) {
689
+ function Me(e, t = 120) {
681
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 = () => {
682
691
  a && (o = i ? e.requestVideoFrameCallback(f) : requestAnimationFrame(f));
683
692
  };
684
693
  function f() {
685
694
  if (!a) return;
686
695
  let { videoWidth: i, videoHeight: o } = e, f = performance.now();
687
- r && i && o && f - s >= t && (s = f, l = W(e, i, o), l > 10 && ((n.width !== i || n.height !== o) && (n.width = i, n.height = o), r.drawImage(e, 0, 0, i, o), u = l, c = f)), d();
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();
688
697
  }
689
698
  return d(), {
690
699
  stop() {
@@ -696,14 +705,14 @@ function je(e, t = 120) {
696
705
  getMirrorAgeMs: () => c ? performance.now() - c : Infinity
697
706
  };
698
707
  }
699
- function Me(e) {
708
+ function Ne(e) {
700
709
  let t = document.createElement("canvas");
701
710
  return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
702
711
  }
703
- function Ne(e) {
712
+ function Pe(e) {
704
713
  return e.engine === "blink";
705
714
  }
706
- function K(e = {}, t = B()) {
715
+ function q(e = {}, t = B()) {
707
716
  let n = { ideal: e.idealWidth ?? 3840 }, r = { ideal: e.idealHeight ?? 2160 };
708
717
  e.maxWidth && (n.max = e.maxWidth), e.maxHeight && (r.max = e.maxHeight);
709
718
  let i = {
@@ -715,20 +724,20 @@ function K(e = {}, t = B()) {
715
724
  max: e.maxFrameRate ?? 30
716
725
  }
717
726
  };
718
- return Ne(t) && (i.resizeMode = { ideal: "none" }), {
727
+ return Pe(t) && (i.resizeMode = { ideal: "none" }), {
719
728
  audio: !1,
720
729
  video: i
721
730
  };
722
731
  }
723
- function q(e, t, n) {
732
+ function Fe(e, t, n) {
724
733
  let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
725
734
  return {
726
735
  width: Math.max(1, Math.round(e * r)),
727
736
  height: Math.max(1, Math.round(t * r))
728
737
  };
729
738
  }
730
- var J = 4096;
731
- function Pe(e, t) {
739
+ var Ie = 4096;
740
+ function Le(e, t) {
732
741
  let n = e.width, r = e.height, i = t?.width?.max, a = t?.height?.max;
733
742
  if (!n || !r || !i || !a) return;
734
743
  let o = Math.min(i / n, a / r);
@@ -737,64 +746,92 @@ function Pe(e, t) {
737
746
  height: { ideal: Math.round(r * o) }
738
747
  };
739
748
  }
740
- async function Fe(e) {
741
- 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);
742
751
  if (t) try {
743
752
  await e.applyConstraints(t);
744
753
  } catch {}
745
754
  }
746
- async function Ie(e) {
747
- let n = globalThis.ImageCapture;
748
- if (!n) return;
749
- let r = new n(e), i;
755
+ async function ze(e) {
750
756
  try {
751
- let e = r.getPhotoCapabilities ? De(await r.getPhotoCapabilities()) : void 0;
752
- i = await r.takePhoto(e);
757
+ return await createImageBitmap(e, {
758
+ imageOrientation: "from-image",
759
+ colorSpaceConversion: "none"
760
+ });
753
761
  } catch {
754
- i = await r.takePhoto();
762
+ return await createImageBitmap(e);
755
763
  }
756
- let a = await createImageBitmap(i), o = q(a.width, a.height, J), s = document.createElement("canvas");
757
- s.width = o.width, s.height = o.height;
758
- let c = s.getContext("2d");
759
- if (!c) throw a.close?.(), t();
760
- 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;
761
764
  }
762
- function Y(e, n) {
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;
785
+ try {
786
+ a = await n.takePhoto(i);
787
+ } catch {
788
+ a = await n.takePhoto();
789
+ }
790
+ return {
791
+ frame: await Ve(a),
792
+ requested: i,
793
+ photoMax: {
794
+ width: r?.imageWidth?.max,
795
+ height: r?.imageHeight?.max
796
+ }
797
+ };
798
+ }
799
+ function J(e, n) {
763
800
  if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
764
- 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");
765
802
  i.width = r.width, i.height = r.height;
766
803
  let a = i.getContext("2d");
767
804
  if (!a) throw t();
768
805
  return a.drawImage(e, 0, 0, i.width, i.height), i;
769
806
  }
770
- function Le(e) {
807
+ function Ue(e) {
771
808
  let t = B();
772
- return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [K(e, t)] : [
773
- K({
809
+ return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [q(e, t)] : [
810
+ q({
774
811
  ...e,
775
812
  idealWidth: 3840,
776
813
  idealHeight: 2160
777
814
  }, t),
778
- K({
815
+ q({
779
816
  ...e,
780
817
  idealWidth: 2560,
781
818
  idealHeight: 1440
782
819
  }, t),
783
- K({
820
+ q({
784
821
  ...e,
785
822
  idealWidth: 1920,
786
823
  idealHeight: 1080
787
824
  }, t)
788
825
  ];
789
826
  }
790
- async function Re(t, n = {}) {
827
+ async function We(t, n = {}) {
791
828
  await x("scan");
792
829
  let r = n.torch ?? "alwaysOff";
793
830
  if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
794
831
  if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
795
832
  t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
796
833
  let i, a;
797
- for (let e of Le(n)) try {
834
+ for (let e of Ue(n)) try {
798
835
  i = await navigator.mediaDevices.getUserMedia(e);
799
836
  break;
800
837
  } catch (e) {
@@ -807,8 +844,8 @@ async function Re(t, n = {}) {
807
844
  for (let e of i.getTracks()) e.stop();
808
845
  throw Error("The camera did not provide a video track.");
809
846
  }
810
- await Fe(o);
811
- 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) => {
812
849
  if (!l.supported || o.readyState !== "live") return !1;
813
850
  try {
814
851
  return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
@@ -826,7 +863,7 @@ async function Re(t, n = {}) {
826
863
  }
827
864
  };
828
865
  l.on && await d(!0);
829
- 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(() => {
830
867
  if (u || !l.supported) return;
831
868
  let e = f.update(s.getLiveLuminance());
832
869
  e !== void 0 && e !== l.on && (u = !0, d(e).finally(() => {
@@ -866,50 +903,55 @@ async function Re(t, n = {}) {
866
903
  get torchOn() {
867
904
  return l.on;
868
905
  },
869
- capture: (e) => Y(t, e),
906
+ capture: (e) => J(t, e),
870
907
  async capturePhoto() {
871
908
  let e, n = 0;
872
909
  try {
873
- e = Y(t), n = G(e);
910
+ e = J(t), n = K(e);
874
911
  } catch {
875
912
  e = void 0;
876
913
  }
877
- let r = s.getFrame(), i, a = !1;
914
+ let r = s.getFrame(), i, a = !1, l = !1, u, d;
878
915
  if (Ee(B(), c)) try {
879
- i = await Ie(o);
916
+ let e = await He(o);
917
+ i = e?.frame, u = e?.requested, d = e?.photoMax;
880
918
  } catch {
881
919
  a = !0, i = void 0;
882
920
  }
883
- let l = i ? G(i) : 0;
884
- 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", {
885
926
  method: "image-capture",
886
927
  frame: `${i.width}×${i.height}`,
887
928
  video: `${t.videoWidth}×${t.videoHeight}`,
888
- aspectMatch: Oe(i, {
889
- width: t.videoWidth,
890
- height: t.videoHeight
891
- })
929
+ photoMax: d ? `${d.width ?? "—"}×${d.height ?? "—"}` : void 0,
930
+ photoRequest: u,
931
+ aspectMatch: ke(i, f)
892
932
  }), {
893
933
  frame: i,
894
934
  method: "image-capture",
895
935
  settings: o.getSettings(),
896
- luminance: l,
936
+ luminance: p,
897
937
  diagnostics: m()
898
938
  };
899
- let u = e && n > 10 ? e : void 0, d = u ?? (r ? Me(r) : void 0);
900
- if (!d) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
901
- 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";
902
942
  return console.info("[exige-scanner] capture", {
903
- method: u ? "video-frame" : "live-mirror",
904
- frame: `${d.width}×${d.height}`,
943
+ method: g ? "video-frame" : "live-mirror",
944
+ frame: `${_.width}×${_.height}`,
905
945
  video: `${t.videoWidth}×${t.videoHeight}`,
906
- fallbackReason: f
946
+ photoMax: d ? `${d.width ?? "—"}×${d.height ?? "—"}` : void 0,
947
+ photoRequest: u,
948
+ fallbackReason: v
907
949
  }), {
908
- frame: d,
909
- method: u ? "video-frame" : "live-mirror",
950
+ frame: _,
951
+ method: g ? "video-frame" : "live-mirror",
910
952
  settings: o.getSettings(),
911
- fallbackReason: f,
912
- luminance: u ? n : s.getMirrorLuminance(),
953
+ fallbackReason: v,
954
+ luminance: g ? n : s.getMirrorLuminance(),
913
955
  diagnostics: m()
914
956
  };
915
957
  },
@@ -926,14 +968,25 @@ async function Re(t, n = {}) {
926
968
  }
927
969
  };
928
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
+ }
929
982
  //#endregion
930
983
  //#region src/sdk/lighting.ts
931
- function ze(e, t) {
984
+ function Ke(e, t) {
932
985
  if (!e.length) return 0;
933
986
  let n = [...e].sort((e, t) => e - t);
934
987
  return n[Math.min(n.length - 1, Math.floor(n.length * t))];
935
988
  }
936
- function X(e, t, n, r = 12) {
989
+ function qe(e, t, n, r = 12) {
937
990
  if (!t || !n || e.length < t * n) return {
938
991
  strong: !1,
939
992
  strength: 0,
@@ -956,7 +1009,7 @@ function X(e, t, n, r = 12) {
956
1009
  });
957
1010
  }
958
1011
  }
959
- 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 = [];
960
1013
  for (let e = 0; e < o.length; e += 1) {
961
1014
  if (!c[e] || l[e]) continue;
962
1015
  let t = [], n = [e];
@@ -1004,11 +1057,11 @@ function X(e, t, n, r = 12) {
1004
1057
  }
1005
1058
  return d;
1006
1059
  }
1007
- function Be(e, t, n, r, i, a, o) {
1060
+ function Je(e, t, n, r, i, a, o) {
1008
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));
1009
1062
  return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
1010
1063
  }
1011
- function Ve(e, t, n) {
1064
+ function Y(e, t, n) {
1012
1065
  let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
1013
1066
  for (let a = 1; a <= n; a += 1) {
1014
1067
  let n = 0;
@@ -1019,23 +1072,23 @@ function Ve(e, t, n) {
1019
1072
  stride: r
1020
1073
  };
1021
1074
  }
1022
- function He(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
1023
- 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);
1024
1077
  for (let s = 0; s < n; s += 1) for (let c = 0; c < t; c += 1) {
1025
- let l = Be(i, a, t, n, c, s, r);
1078
+ let l = Je(i, a, t, n, c, s, r);
1026
1079
  o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
1027
1080
  }
1028
1081
  return o;
1029
1082
  }
1030
- function Ue(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
1031
- 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;
1032
1085
  for (let i = 0; i < n; i += 1) for (let l = 0; l < t; l += 1) {
1033
- let u = Be(a, o, t, n, l, i, r);
1086
+ let u = Je(a, o, t, n, l, i, r);
1034
1087
  s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
1035
1088
  }
1036
1089
  return s;
1037
1090
  }
1038
- function We(e, t, n) {
1091
+ function Ze(e, t, n) {
1039
1092
  let r = [
1040
1093
  e.topLeft,
1041
1094
  e.topRight,
@@ -1049,8 +1102,8 @@ function We(e, t, n) {
1049
1102
  height: s - a
1050
1103
  };
1051
1104
  }
1052
- function Ge(e, t) {
1053
- let n = We(t, e.width, e.height);
1105
+ function Qe(e, t) {
1106
+ let n = Ze(t, e.width, e.height);
1054
1107
  if (n.width <= 0 || n.height <= 0) return {
1055
1108
  strong: !1,
1056
1109
  strength: 0,
@@ -1069,18 +1122,18 @@ function Ge(e, t) {
1069
1122
  i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
1070
1123
  let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
1071
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);
1072
- return X(o, r.width, r.height);
1125
+ return qe(o, r.width, r.height);
1073
1126
  }
1074
1127
  //#endregion
1075
1128
  //#region src/sdk/finder.ts
1076
- function Ke(e, t) {
1129
+ function $e(e, t) {
1077
1130
  return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
1078
1131
  }
1079
- async function qe(e, t) {
1132
+ async function et(e, t) {
1080
1133
  let n = await e();
1081
1134
  return t(), n;
1082
1135
  }
1083
- function Je(e) {
1136
+ function tt(e) {
1084
1137
  return e === "alwaysOn" || e === "only" ? {
1085
1138
  visible: !1,
1086
1139
  checked: !0,
@@ -1095,7 +1148,7 @@ function Je(e) {
1095
1148
  mutable: !0
1096
1149
  };
1097
1150
  }
1098
- function Z(e) {
1151
+ function X(e) {
1099
1152
  return [
1100
1153
  e.topLeft,
1101
1154
  e.topRight,
@@ -1103,7 +1156,7 @@ function Z(e) {
1103
1156
  e.bottomLeft
1104
1157
  ];
1105
1158
  }
1106
- function Ye(e, t) {
1159
+ function nt(e, t) {
1107
1160
  let n = e.status === "success" && e.modelStatus !== "failed", r = {
1108
1161
  status: e.status,
1109
1162
  confidence: Number(e.confidence.toFixed(3)),
@@ -1126,7 +1179,7 @@ function Ye(e, t) {
1126
1179
  detail: r
1127
1180
  };
1128
1181
  }
1129
- function Xe(e) {
1182
+ function rt(e) {
1130
1183
  let t = 0;
1131
1184
  for (let n = 0; n < e.length; n += 1) {
1132
1185
  let r = e[n], i = e[(n + 1) % e.length];
@@ -1134,42 +1187,42 @@ function Xe(e) {
1134
1187
  }
1135
1188
  return Math.abs(t) / 2;
1136
1189
  }
1137
- function Q(e, t) {
1190
+ function Z(e, t) {
1138
1191
  return Math.hypot(e.x - t.x, e.y - t.y);
1139
1192
  }
1140
- var $ = {
1193
+ var Q = {
1141
1194
  widthFill: 0,
1142
1195
  heightFill: 0,
1143
1196
  limitingFill: 0,
1144
1197
  areaFill: 0,
1145
1198
  aspectRatio: 1
1146
1199
  };
1147
- function Ze(e, t, n) {
1148
- 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));
1149
1202
  return {
1150
1203
  widthFill: o,
1151
1204
  heightFill: s,
1152
1205
  limitingFill: Math.max(o, s),
1153
- areaFill: Xe(r) / Math.max(1, t * n),
1206
+ areaFill: rt(r) / Math.max(1, t * n),
1154
1207
  aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
1155
1208
  };
1156
1209
  }
1157
- function Qe(e, t, n, r = {}) {
1210
+ function at(e, t, n, r = {}) {
1158
1211
  let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
1159
1212
  if (e.aspectRatio < a) return i;
1160
1213
  let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
1161
1214
  return Math.min(o ?? i + .08, 1 - n * 2);
1162
1215
  }
1163
- function $e(e, t, n = {}) {
1216
+ function ot(e, t, n = {}) {
1164
1217
  let r = n.confidenceThreshold ?? .72;
1165
1218
  if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
1166
1219
  hint: "Place the document in the frame",
1167
1220
  reason: "place-document",
1168
1221
  fillRatio: 0,
1169
- fill: $,
1222
+ fill: Q,
1170
1223
  readyForAutoCapture: !1
1171
1224
  };
1172
- 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;
1173
1226
  if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
1174
1227
  hint: "Move farther away",
1175
1228
  reason: "move-farther-away",
@@ -1177,14 +1230,14 @@ function $e(e, t, n = {}) {
1177
1230
  fill: a,
1178
1231
  readyForAutoCapture: !1
1179
1232
  };
1180
- 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);
1181
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) ? {
1182
1235
  hint: "Hold the camera straight",
1183
1236
  reason: "straighten-camera",
1184
1237
  fillRatio: o,
1185
1238
  fill: a,
1186
1239
  readyForAutoCapture: !1
1187
- } : o < Qe(a, t.previouslyReady === !0, s, n) ? {
1240
+ } : o < at(a, t.previouslyReady === !0, s, n) ? {
1188
1241
  hint: "Move closer",
1189
1242
  reason: "move-closer",
1190
1243
  fillRatio: o,
@@ -1198,7 +1251,7 @@ function $e(e, t, n = {}) {
1198
1251
  readyForAutoCapture: t.ready
1199
1252
  };
1200
1253
  }
1201
- var et = class {
1254
+ var $ = class {
1202
1255
  previous;
1203
1256
  count = 0;
1204
1257
  ready = !1;
@@ -1215,8 +1268,8 @@ var et = class {
1215
1268
  ready: !1,
1216
1269
  movement: Infinity
1217
1270
  };
1218
- let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...Z(e.quad).map((e, n) => {
1219
- 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];
1220
1273
  return Math.hypot(e.x - r.x, e.y - r.y) / Math.max(1, t);
1221
1274
  })) : Infinity, r = this.options.exitCornerTolerance ?? Math.max(this.options.cornerTolerance, .036);
1222
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, {
@@ -1226,14 +1279,14 @@ var et = class {
1226
1279
  };
1227
1280
  }
1228
1281
  };
1229
- function tt(e, n) {
1282
+ function st(e, n) {
1230
1283
  let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
1231
1284
  i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
1232
1285
  let a = i.getContext("2d");
1233
1286
  if (!a) throw t();
1234
1287
  return a.drawImage(e, 0, 0, i.width, i.height), i;
1235
1288
  }
1236
- function nt() {
1289
+ function ct() {
1237
1290
  let e = window.AudioContext ?? window.webkitAudioContext;
1238
1291
  if (!e) return;
1239
1292
  let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
@@ -1244,13 +1297,13 @@ function nt() {
1244
1297
  let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
1245
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();
1246
1299
  }
1247
- async function rt(e) {
1300
+ async function lt(e) {
1248
1301
  let t = document.createElement("video");
1249
1302
  return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
1250
1303
  }
1251
- async function it(t) {
1304
+ async function ut(t) {
1252
1305
  await x("scan");
1253
- let n = Je(t.autoCapture), r = new et({
1306
+ let n = tt(t.autoCapture), r = new $({
1254
1307
  stableFrames: t.stableFrames ?? 4,
1255
1308
  confidenceThreshold: t.confidenceThreshold ?? .72,
1256
1309
  cornerTolerance: t.cornerTolerance ?? .024,
@@ -1259,14 +1312,14 @@ async function it(t) {
1259
1312
  minDimension: 220,
1260
1313
  maxAnalysisDimension: 520,
1261
1314
  ...t.detection
1262
- }, 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 = {
1263
1316
  state: "detecting",
1264
1317
  confidence: 0,
1265
1318
  guidance: {
1266
1319
  hint: "Place the document in the frame",
1267
1320
  reason: "place-document",
1268
1321
  fillRatio: 0,
1269
- fill: $,
1322
+ fill: Q,
1270
1323
  readyForAutoCapture: !1
1271
1324
  },
1272
1325
  lighting: {
@@ -1276,10 +1329,10 @@ async function it(t) {
1276
1329
  stableFrames: 0,
1277
1330
  requiredStableFrames: t.stableFrames ?? 4,
1278
1331
  autoCapture: { ...n }
1279
- }, g = () => s instanceof HTMLCanvasElement ? tt(s, i) : Y(s, i), _ = (e) => {
1332
+ }, g = () => s instanceof HTMLCanvasElement ? st(s, i) : J(s, i), _ = (e) => {
1280
1333
  h = e, t.onStatus?.(e);
1281
1334
  }, v = (e) => {
1282
- let t = Ye(e, s instanceof HTMLVideoElement ? {
1335
+ let t = nt(e, s instanceof HTMLVideoElement ? {
1283
1336
  width: s.videoWidth,
1284
1337
  height: s.videoHeight
1285
1338
  } : {
@@ -1294,11 +1347,11 @@ async function it(t) {
1294
1347
  l = !0;
1295
1348
  let n;
1296
1349
  try {
1297
- n = await qe(t.captureFrame ?? g, () => {
1350
+ n = await et(t.captureFrame ?? g, () => {
1298
1351
  _({
1299
1352
  ...h,
1300
1353
  state: "captured"
1301
- }), t.playShutterSound !== !1 && nt(), y();
1354
+ }), t.playShutterSound !== !1 && ct(), y();
1302
1355
  });
1303
1356
  } catch (e) {
1304
1357
  throw l = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
@@ -1312,9 +1365,9 @@ async function it(t) {
1312
1365
  }, S = async () => {
1313
1366
  if (c && !l) {
1314
1367
  try {
1315
- let e = g(), i = await Se(e, o);
1368
+ let e = g(), i = await R(e, o);
1316
1369
  f = i, v(i);
1317
- let a = i.quad ? Ge(e, i.quad) : {
1370
+ let a = i.quad ? Qe(e, i.quad) : {
1318
1371
  strong: !1,
1319
1372
  strength: 0
1320
1373
  }, s = a.strong ? {
@@ -1324,7 +1377,7 @@ async function it(t) {
1324
1377
  } : {
1325
1378
  castShadow: !1,
1326
1379
  strength: a.strength
1327
- }, c = r.update(i), l = $e(i, {
1380
+ }, c = r.update(i), l = ot(i, {
1328
1381
  ...c,
1329
1382
  previouslyReady: u
1330
1383
  }, {
@@ -1377,7 +1430,7 @@ async function it(t) {
1377
1430
  hint: "Place the document in the frame",
1378
1431
  reason: "place-document",
1379
1432
  fillRatio: 0,
1380
- fill: $,
1433
+ fill: Q,
1381
1434
  readyForAutoCapture: !1
1382
1435
  },
1383
1436
  lighting: {
@@ -1406,6 +1459,6 @@ async function it(t) {
1406
1459
  };
1407
1460
  }
1408
1461
  //#endregion
1409
- 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 };
1410
1463
 
1411
- //# sourceMappingURL=finder-CLTG1caj.js.map
1464
+ //# sourceMappingURL=finder-B3t_3g6Z.js.map