@exige/web-scanner-sdk 0.2.26 → 0.2.28

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 te() {
187
+ function O() {
188
188
  if (w.size === 0) return {
189
189
  downloading: !1,
190
190
  loaded: 0,
@@ -198,12 +198,12 @@ function te() {
198
198
  total: n ? t : null
199
199
  };
200
200
  }
201
- function O() {
202
- let e = te();
201
+ function te() {
202
+ let e = O();
203
203
  for (let t of T) t(e);
204
204
  }
205
205
  function ne(e) {
206
- return e(te()), T.add(e), () => {
206
+ return e(O()), T.add(e), () => {
207
207
  T.delete(e);
208
208
  };
209
209
  }
@@ -211,7 +211,7 @@ 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
- }), O();
214
+ }), te();
215
215
  }
216
216
  async function re(e, t) {
217
217
  let n = ee(e);
@@ -257,309 +257,12 @@ async function ie(t, n) {
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), O());
260
+ D.delete(t), w.has(t) && (w.delete(t), te());
261
261
  }
262
262
  }
263
263
  //#endregion
264
- //#region src/sdk/ort-runtime.ts
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
- return {
268
- wasm: ae.href,
269
- mjs: oe.href
270
- };
271
- }
272
- function ce(e) {
273
- return typeof e == "string" ? e.trim() || se() : e?.wasm.trim() && e.mjs.trim() ? {
274
- wasm: e.wasm.trim(),
275
- mjs: e.mjs.trim()
276
- } : se();
277
- }
278
- //#endregion
279
- //#region src/sdk/image.ts
280
- function le(e, t, n) {
281
- let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
282
- return {
283
- width: Math.max(1, Math.round(e * r)),
284
- height: Math.max(1, Math.round(t * r))
285
- };
286
- }
287
- async function ue(e) {
288
- let t = URL.createObjectURL(e);
289
- try {
290
- let e = new Image();
291
- return e.src = t, await e.decode(), e;
292
- } finally {
293
- URL.revokeObjectURL(t);
294
- }
295
- }
296
- async function A(e, n = {}) {
297
- if (e instanceof HTMLCanvasElement && n.cloneCanvas === !1 && !n.maxDimension) return e;
298
- let r = document.createElement("canvas"), i = r.getContext("2d", { willReadFrequently: !0 });
299
- if (!i) throw t();
300
- if (e instanceof Blob) {
301
- if ("createImageBitmap" in window) try {
302
- let t = await createImageBitmap(e), a = le(t.width, t.height, n.maxDimension);
303
- return r.width = a.width, r.height = a.height, i.drawImage(t, 0, 0, a.width, a.height), t.close(), r;
304
- } catch {}
305
- e = await ue(e);
306
- }
307
- let a = e instanceof HTMLImageElement ? e.naturalWidth : e.width, o = e instanceof HTMLImageElement ? e.naturalHeight : e.height;
308
- if (!a || !o) throw Error("The image has no readable dimensions.");
309
- let s = le(a, o, n.maxDimension);
310
- return r.width = s.width, r.height = s.height, i.drawImage(e, 0, 0, s.width, s.height), r;
311
- }
312
- function de(e, t = "image/png", n = .92) {
313
- return new Promise((r, i) => e.toBlob((e) => e ? r(e) : i(/* @__PURE__ */ Error("Could not encode the image.")), t, n));
314
- }
315
- function fe(e, t, n) {
316
- let r = Math.max(0, Math.min(t, e.x)), i = Math.max(0, Math.min(n, e.y));
317
- return {
318
- x: r,
319
- y: i,
320
- width: Math.max(0, Math.min(t - r, e.width)),
321
- height: Math.max(0, Math.min(n - i, e.height))
322
- };
323
- }
324
- //#endregion
325
- //#region src/sdk/scan.ts
326
- var pe = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", me = 1280;
327
- function he(e, t, n) {
328
- if (n) return n;
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
- }
332
- function j(e) {
333
- return e?.trim() || "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
334
- }
335
- var ge = 3, M, _e = 0, N = /* @__PURE__ */ new Map();
336
- function P(e, t) {
337
- return Math.hypot(e.x - t.x, e.y - t.y);
338
- }
339
- function F(e) {
340
- return {
341
- ...e,
342
- edges: {
343
- top: {
344
- start: e.topLeft,
345
- end: e.topRight
346
- },
347
- right: {
348
- start: e.topRight,
349
- end: e.bottomRight
350
- },
351
- bottom: {
352
- start: e.bottomRight,
353
- end: e.bottomLeft
354
- },
355
- left: {
356
- start: e.bottomLeft,
357
- end: e.topLeft
358
- }
359
- }
360
- };
361
- }
362
- function ve(e, t) {
363
- let n = (e) => ({
364
- x: e.x / t,
365
- y: e.y / t
366
- });
367
- return {
368
- topLeft: n(e.topLeft),
369
- topRight: n(e.topRight),
370
- bottomRight: n(e.bottomRight),
371
- bottomLeft: n(e.bottomLeft)
372
- };
373
- }
374
- function ye() {
375
- return typeof navigator > "u" ? !1 : navigator.maxTouchPoints > 0 || navigator.hardwareConcurrency <= 4 || typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
376
- }
377
- function be(t, n, r, i) {
378
- return new Promise((a, o) => {
379
- M || (M = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), M.onmessage = (t) => {
380
- if (t.data.download?.url) {
381
- k(t.data.download.url, t.data.download);
382
- return;
383
- }
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
- let t = new e("worker", "The document worker could not start.");
388
- for (let e of N.values()) e.reject(t);
389
- N.clear(), M?.terminate(), M = void 0;
390
- });
391
- let s = ++_e;
392
- N.set(s, {
393
- resolve: a,
394
- reject: o
395
- });
396
- let c = t.slice().buffer;
397
- M.postMessage({
398
- id: s,
399
- pixels: c,
400
- width: n,
401
- height: r,
402
- modelUrl: j(i.modelUrl),
403
- heatmapThreshold: i.heatmapThreshold,
404
- cacheModel: i.cacheModel,
405
- ortWasmPaths: ce(i.ortWasmPaths)
406
- }, [c]);
407
- });
408
- }
409
- async function I(n, r) {
410
- let { width: i, height: a } = n, o = r.minDimension ?? 360;
411
- if (Math.min(i, a) < o) return {
412
- status: "low-quality",
413
- confidence: 0,
414
- message: `Use an image at least ${o}px on its shortest side.`,
415
- sourceWidth: i,
416
- sourceHeight: a
417
- };
418
- let s = he(i, a, r.maxAnalysisDimension), c = Math.min(1, s / Math.max(i, a)), l = document.createElement("canvas");
419
- l.width = Math.max(1, Math.round(i * c)), l.height = Math.max(1, Math.round(a * c));
420
- let u = l.getContext("2d", { willReadFrequently: !0 });
421
- if (!u) throw t();
422
- u.drawImage(n, 0, 0, l.width, l.height);
423
- let d = u.getImageData(0, 0, l.width, l.height).data, f;
424
- if (r.useWorker !== !1 && typeof Worker < "u") try {
425
- f = await be(d, l.width, l.height, r);
426
- } catch (t) {
427
- if (t instanceof e && (t.code === "worker" || t.code === "model-http")) throw t;
428
- f = {
429
- sharpness: 20,
430
- detector: "ml",
431
- modelStatus: "failed",
432
- modelError: t instanceof Error ? t.message : "Document worker failed."
433
- };
434
- }
435
- else f = {
436
- sharpness: 20,
437
- detector: "ml",
438
- modelStatus: "failed",
439
- modelError: "ML detection requires a Web Worker."
440
- };
441
- let { sharpness: p, candidate: m, detector: h, modelStatus: g, modelProvider: _, modelError: v, modelNote: y, inferenceMs: b } = f, x = {
442
- detector: h,
443
- modelStatus: g,
444
- modelProvider: _,
445
- modelError: v,
446
- modelNote: y,
447
- inferenceMs: b
448
- };
449
- if (p < ge) return {
450
- status: "low-quality",
451
- confidence: Math.min(.3, p / 18),
452
- message: "The image is too soft or dark to resolve four document edges.",
453
- sourceWidth: i,
454
- sourceHeight: a,
455
- ...x
456
- };
457
- if (!m) return {
458
- status: "no-document",
459
- confidence: 0,
460
- message: "No document corners found. Place all four edges on a contrasting surface.",
461
- sourceWidth: i,
462
- sourceHeight: a,
463
- ...x
464
- };
465
- let S = ve(m.corners, c), C = F(S), w = r.minConfidence ?? .58;
466
- return m.confidence < w ? {
467
- status: "low-confidence",
468
- quad: C,
469
- corners: S,
470
- confidence: m.confidence,
471
- message: "Four possible corners were found, but the geometry is not reliable enough to crop.",
472
- sourceWidth: i,
473
- sourceHeight: a,
474
- ...x
475
- } : {
476
- status: "success",
477
- quad: C,
478
- corners: S,
479
- confidence: m.confidence,
480
- message: "Four document edges detected.",
481
- sourceWidth: i,
482
- sourceHeight: a,
483
- ...x
484
- };
485
- }
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
- return {
489
- width: Math.max(1, Math.round(n * i)),
490
- height: Math.max(1, Math.round(r * i))
491
- };
492
- }
493
- function Se(e, t, n, r, i) {
494
- let a = Math.max(0, Math.min(t - 1, r)), o = Math.max(0, Math.min(n - 1, i)), s = Math.floor(a), c = Math.floor(o), l = Math.min(t - 1, s + 1), u = Math.min(n - 1, c + 1), d = a - s, f = o - c, p = c * t, m = u * t, h = (t) => {
495
- let n = e[(p + s) * 4 + t] * (1 - d) + e[(p + l) * 4 + t] * d, r = e[(m + s) * 4 + t] * (1 - d) + e[(m + l) * 4 + t] * d;
496
- return Math.round(n * (1 - f) + r * f);
497
- };
498
- return [
499
- h(0),
500
- h(1),
501
- h(2),
502
- 255
503
- ];
504
- }
505
- function L(e, n, r) {
506
- let { width: i, height: a } = xe(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
507
- if (!o) throw t();
508
- let s = o.getImageData(0, 0, e.width, e.height), c = document.createElement("canvas");
509
- c.width = i, c.height = a;
510
- let l = c.getContext("2d");
511
- if (!l) throw t();
512
- 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;
513
- for (let t = 0; t < a; t += 1) {
514
- let n = t / Math.max(1, a - 1);
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] = Se(s.data, e.width, e.height, c, l), g = (t * i + r) * 4;
517
- u.data[g] = f, u.data[g + 1] = p, u.data[g + 2] = m, u.data[g + 3] = h;
518
- }
519
- }
520
- return l.putImageData(u, 0, 0), c;
521
- }
522
- async function R(e, t = {}) {
523
- return await x("scan"), I(await A(e, { cloneCanvas: !1 }), t);
524
- }
525
- async function Ce(e, t, n = {}) {
526
- await x("scan");
527
- let r = await A(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? 4096;
528
- return {
529
- status: "success",
530
- corners: t,
531
- quad: F(t),
532
- confidence: 1,
533
- message: "Captured with the document edges shown in the finder.",
534
- sourceWidth: r.width,
535
- sourceHeight: r.height,
536
- canvas: L(r, t, i)
537
- };
538
- }
539
- async function z(e, t = {}) {
540
- await x("scan");
541
- let n = await A(e, { cloneCanvas: !1 }), r = await I(n, t);
542
- if (r.status !== "success" || !r.corners) return r;
543
- let i = t.maxOutputDimension ?? 4096;
544
- return {
545
- ...r,
546
- canvas: L(n, r.corners, i),
547
- message: "Four document edges detected and perspective-corrected."
548
- };
549
- }
550
- function B(e) {
551
- 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})` : ""}`;
552
- }
553
- async function we(e, t = {}) {
554
- let n = await z(e, t);
555
- return n.status === "success" ? n : {
556
- ...n,
557
- message: B(n)
558
- };
559
- }
560
- //#endregion
561
264
  //#region src/sdk/camera.ts
562
- function V(e, t) {
265
+ function ae(e, t) {
563
266
  let { engine: n } = t;
564
267
  return [
565
268
  `${e}:`,
@@ -574,9 +277,9 @@ function V(e, t) {
574
277
  ` torch: ${t.torch.mode} supported=${t.torch.supported} on=${t.torch.on}`
575
278
  ].join("\n");
576
279
  }
577
- function Te(e) {
280
+ function oe(e) {
578
281
  let t = ["Exige scanner capture report", `time: ${e.capturedAt ?? (/* @__PURE__ */ new Date()).toISOString()}`];
579
- if (e.error && t.push(`error: ${e.error}`), e.captureMethod && t.push(`method: ${e.captureMethod}`), e.luminance !== void 0 && t.push(`luminance: ${e.luminance.toFixed(1)}`), e.fallbackReason && t.push(`fallback: ${e.fallbackReason}`), e.shutter && t.push(V("shutter", e.shutter)), e.live && t.push(V("live", e.live)), e.finder) {
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(ae("shutter", e.shutter)), e.live && t.push(ae("live", e.live)), e.finder) {
580
283
  let n = e.finder;
581
284
  t.push([
582
285
  "finder:",
@@ -593,7 +296,7 @@ function Te(e) {
593
296
  }
594
297
  return `${t.join("\n")}\n`;
595
298
  }
596
- function H(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
299
+ function A(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
597
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;
598
301
  return {
599
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",
@@ -602,37 +305,40 @@ function H(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof nav
602
305
  userAgent: e
603
306
  };
604
307
  }
605
- function U(e) {
308
+ function j(e) {
606
309
  return /Android/i.test(e.userAgent) && !e.iosWebKit;
607
310
  }
608
- function Ee(e = "auto", t = H()) {
609
- return e === "system-camera" || e !== "live" && U(t);
311
+ function M(e = A()) {
312
+ return e.engine === "webkit" && !j(e);
610
313
  }
611
- function De(e, t) {
314
+ function se(e = "auto", t = A()) {
315
+ return e === "system-camera" || e !== "live" && j(t);
316
+ }
317
+ function ce(e, t) {
612
318
  return t && !e.iosWebKit;
613
319
  }
614
- function W(e, t) {
320
+ function N(e, t) {
615
321
  if (!e || !Number.isFinite(e)) return;
616
322
  let n = t?.max;
617
323
  if (!n || !Number.isFinite(n)) return Math.round(e);
618
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;
619
325
  return Math.round(Math.min(n, Math.max(r, a)));
620
326
  }
621
- function Oe(e) {
622
- let t = W(e?.imageWidth?.max ?? 0, e?.imageWidth), n = W(e?.imageHeight?.max ?? 0, e?.imageHeight);
327
+ function le(e) {
328
+ let t = N(e?.imageWidth?.max ?? 0, e?.imageWidth), n = N(e?.imageHeight?.max ?? 0, e?.imageHeight);
623
329
  if (t && n) return t >= n ? { imageWidth: t } : { imageHeight: n };
624
330
  if (t) return { imageWidth: t };
625
331
  if (n) return { imageHeight: n };
626
332
  }
627
- function ke(e, t) {
333
+ function ue(e, t) {
628
334
  return !e.width || !e.height || !t.width || !t.height ? !1 : e.width * e.height > t.width * t.height * 1.15;
629
335
  }
630
- function Ae(e, t) {
336
+ function de(e, t) {
631
337
  if (!e.width || !e.height || !t.width || !t.height) return !1;
632
338
  let n = e.width / e.height / (t.width / t.height);
633
339
  return n > .97 && n < 1.03;
634
340
  }
635
- var je = 10, G = class {
341
+ var fe = 10, P = class {
636
342
  on = !1;
637
343
  darkCount = 0;
638
344
  brightCount = 0;
@@ -655,7 +361,7 @@ var je = 10, G = class {
655
361
  return this.on;
656
362
  }
657
363
  };
658
- function K(e, t) {
364
+ function F(e, t) {
659
365
  return t ? e === "alwaysOn" || e === "alwaysOff" ? {
660
366
  mode: e,
661
367
  supported: !0,
@@ -679,37 +385,37 @@ function K(e, t) {
679
385
  automatic: e === "auto"
680
386
  };
681
387
  }
682
- function q(e) {
388
+ function I(e) {
683
389
  let t = Math.floor(e.length / 4);
684
390
  if (!t) return 0;
685
391
  let n = 0;
686
392
  for (let r = 0; r < t * 4; r += 4) n += e[r] * .299 + e[r + 1] * .587 + e[r + 2] * .114;
687
393
  return n / t;
688
394
  }
689
- function Me(e, t = 10) {
395
+ function pe(e, t = 10) {
690
396
  if (e.length < 4) return !0;
691
397
  let n = Math.floor(e.length / 4), r = 0;
692
398
  for (let i = 0; i < n * 4; i += 4) e[i] * .299 + e[i + 1] * .587 + e[i + 2] * .114 > t * 2 && (r += 1);
693
- return q(e) <= t && r / n < .01;
399
+ return I(e) <= t && r / n < .01;
694
400
  }
695
- function Ne(e, t, n) {
401
+ function me(e, t, n) {
696
402
  if (!t || !n) return 0;
697
403
  let r = document.createElement("canvas");
698
404
  r.width = Math.min(32, t), r.height = Math.min(32, n);
699
405
  let i = r.getContext("2d", { willReadFrequently: !0 });
700
- return i ? (i.drawImage(e, 0, 0, r.width, r.height), q(i.getImageData(0, 0, r.width, r.height).data)) : 0;
406
+ return i ? (i.drawImage(e, 0, 0, r.width, r.height), I(i.getImageData(0, 0, r.width, r.height).data)) : 0;
701
407
  }
702
- function Pe(e) {
703
- return Ne(e, e.width, e.height);
408
+ function he(e) {
409
+ return me(e, e.width, e.height);
704
410
  }
705
- function Fe(e, t = 120) {
411
+ function ge(e, t = 120) {
706
412
  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 = () => {
707
413
  a && (o = i ? e.requestVideoFrameCallback(f) : requestAnimationFrame(f));
708
414
  };
709
415
  function f() {
710
416
  if (!a) return;
711
417
  let { videoWidth: i, videoHeight: o } = e, f = performance.now();
712
- r && i && o && f - s >= t && (s = f, l = Ne(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();
418
+ r && i && o && f - s >= t && (s = f, l = me(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();
713
419
  }
714
420
  return d(), {
715
421
  stop() {
@@ -721,14 +427,14 @@ function Fe(e, t = 120) {
721
427
  getMirrorAgeMs: () => c ? performance.now() - c : Infinity
722
428
  };
723
429
  }
724
- function Ie(e) {
430
+ function _e(e) {
725
431
  let t = document.createElement("canvas");
726
432
  return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
727
433
  }
728
- function Le(e) {
434
+ function ve(e) {
729
435
  return e.engine === "blink";
730
436
  }
731
- function J(e = {}, t = H()) {
437
+ function L(e = {}, t = A()) {
732
438
  let n = { ideal: e.idealWidth ?? 3840 }, r = { ideal: e.idealHeight ?? 2160 };
733
439
  e.maxWidth && (n.max = e.maxWidth), e.maxHeight && (r.max = e.maxHeight);
734
440
  let i = {
@@ -740,20 +446,20 @@ function J(e = {}, t = H()) {
740
446
  max: e.maxFrameRate ?? 30
741
447
  }
742
448
  };
743
- return Le(t) && (i.resizeMode = { ideal: "none" }), {
449
+ return ve(t) && (i.resizeMode = { ideal: "none" }), {
744
450
  audio: !1,
745
451
  video: i
746
452
  };
747
453
  }
748
- function Re(e, t, n) {
454
+ function ye(e, t, n) {
749
455
  let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
750
456
  return {
751
457
  width: Math.max(1, Math.round(e * r)),
752
458
  height: Math.max(1, Math.round(t * r))
753
459
  };
754
460
  }
755
- var ze = 4096;
756
- function Be(e, t) {
461
+ var R = 4096;
462
+ function be(e, t) {
757
463
  let n = e.width, r = e.height, i = t?.width?.max, a = t?.height?.max;
758
464
  if (!n || !r || !i || !a) return;
759
465
  let o = Math.min(i / n, a / r);
@@ -762,13 +468,13 @@ function Be(e, t) {
762
468
  height: { ideal: Math.round(r * o) }
763
469
  };
764
470
  }
765
- async function Ve(e) {
766
- let t = Be(e.getSettings(), typeof e.getCapabilities == "function" ? e.getCapabilities() : void 0);
471
+ async function xe(e) {
472
+ let t = be(e.getSettings(), typeof e.getCapabilities == "function" ? e.getCapabilities() : void 0);
767
473
  if (t) try {
768
474
  await e.applyConstraints(t);
769
475
  } catch {}
770
476
  }
771
- async function He(e) {
477
+ async function Se(e) {
772
478
  try {
773
479
  return await createImageBitmap(e, {
774
480
  imageOrientation: "from-image",
@@ -778,7 +484,7 @@ async function He(e) {
778
484
  return await createImageBitmap(e);
779
485
  }
780
486
  }
781
- async function Ue(e) {
487
+ async function Ce(e) {
782
488
  try {
783
489
  await e.applyConstraints({ advanced: [{ pointsOfInterest: [{
784
490
  x: .5,
@@ -786,25 +492,25 @@ async function Ue(e) {
786
492
  }] }] }), await new Promise((e) => window.setTimeout(e, 180));
787
493
  } catch {}
788
494
  }
789
- async function We(e) {
790
- let n = await He(e), r = Re(n.width, n.height, ze), i = document.createElement("canvas");
495
+ async function z(e) {
496
+ let n = await Se(e), r = ye(n.width, n.height, R), i = document.createElement("canvas");
791
497
  i.width = r.width, i.height = r.height;
792
498
  let a = i.getContext("2d");
793
499
  if (!a) throw n.close?.(), t();
794
500
  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;
795
501
  }
796
- async function Ge(e) {
502
+ async function we(e) {
797
503
  let t = globalThis.ImageCapture;
798
504
  if (!t) return;
799
- await Ue(e);
800
- let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i = Oe(r), a;
505
+ await Ce(e);
506
+ let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i = le(r), a;
801
507
  try {
802
508
  a = await n.takePhoto(i);
803
509
  } catch {
804
510
  a = await n.takePhoto();
805
511
  }
806
512
  return {
807
- frame: await We(a),
513
+ frame: await z(a),
808
514
  requested: i,
809
515
  photoMax: {
810
516
  width: r?.imageWidth?.max,
@@ -812,42 +518,42 @@ async function Ge(e) {
812
518
  }
813
519
  };
814
520
  }
815
- function Y(e, n) {
521
+ function B(e, n) {
816
522
  if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
817
- let r = Re(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
523
+ let r = ye(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
818
524
  i.width = r.width, i.height = r.height;
819
525
  let a = i.getContext("2d");
820
526
  if (!a) throw t();
821
527
  return a.drawImage(e, 0, 0, i.width, i.height), i;
822
528
  }
823
- function Ke(e) {
824
- let t = H();
825
- return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [J(e, t)] : [
826
- J({
529
+ function Te(e) {
530
+ let t = A();
531
+ return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [L(e, t)] : [
532
+ L({
827
533
  ...e,
828
534
  idealWidth: 3840,
829
535
  idealHeight: 2160
830
536
  }, t),
831
- J({
537
+ L({
832
538
  ...e,
833
539
  idealWidth: 2560,
834
540
  idealHeight: 1440
835
541
  }, t),
836
- J({
542
+ L({
837
543
  ...e,
838
544
  idealWidth: 1920,
839
545
  idealHeight: 1080
840
546
  }, t)
841
547
  ];
842
548
  }
843
- async function qe(t, n = {}) {
549
+ async function Ee(t, n = {}) {
844
550
  await x("scan");
845
551
  let r = n.torch ?? "alwaysOff";
846
552
  if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
847
553
  if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
848
554
  t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
849
555
  let i, a;
850
- for (let e of Ke(n)) try {
556
+ for (let e of Te(n)) try {
851
557
  i = await navigator.mediaDevices.getUserMedia(e);
852
558
  break;
853
559
  } catch (e) {
@@ -860,8 +566,8 @@ async function qe(t, n = {}) {
860
566
  for (let e of i.getTracks()) e.stop();
861
567
  throw Error("The camera did not provide a video track.");
862
568
  }
863
- await Ve(o);
864
- let s = Fe(t), c = "ImageCapture" in globalThis, l = K(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
569
+ await xe(o);
570
+ let s = ge(t), c = "ImageCapture" in globalThis, l = F(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
865
571
  if (!l.supported || o.readyState !== "live") return !1;
866
572
  try {
867
573
  return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
@@ -879,7 +585,7 @@ async function qe(t, n = {}) {
879
585
  }
880
586
  };
881
587
  l.on && await d(!0);
882
- let f = r === "auto" && l.supported ? new G() : void 0, p = f ? window.setInterval(() => {
588
+ let f = r === "auto" && l.supported ? new P() : void 0, p = f ? window.setInterval(() => {
883
589
  if (u || !l.supported) return;
884
590
  let e = f.update(s.getLiveLuminance());
885
591
  e !== void 0 && e !== l.on && (u = !0, d(e).finally(() => {
@@ -905,7 +611,7 @@ async function qe(t, n = {}) {
905
611
  torchSupported: l.supported,
906
612
  torchOn: l.on,
907
613
  torch: { ...l },
908
- engine: H()
614
+ engine: A()
909
615
  };
910
616
  };
911
617
  return {
@@ -919,17 +625,17 @@ async function qe(t, n = {}) {
919
625
  get torchOn() {
920
626
  return l.on;
921
627
  },
922
- capture: (e) => Y(t, e),
628
+ capture: (e) => B(t, e),
923
629
  async capturePhoto() {
924
630
  let e, n = 0;
925
631
  try {
926
- e = Y(t), n = Pe(e);
632
+ e = B(t), n = he(e);
927
633
  } catch {
928
634
  e = void 0;
929
635
  }
930
636
  let r = s.getFrame(), i, a = !1, l = !1, u, d;
931
- if (De(H(), c)) try {
932
- let e = await Ge(o);
637
+ if (ce(A(), c)) try {
638
+ let e = await we(o);
933
639
  i = e?.frame, u = e?.requested, d = e?.photoMax;
934
640
  } catch {
935
641
  a = !0, i = void 0;
@@ -937,14 +643,14 @@ async function qe(t, n = {}) {
937
643
  let f = {
938
644
  width: t.videoWidth,
939
645
  height: t.videoHeight
940
- }, p = i ? Pe(i) : 0, h = !!(i && p > 10 && ke(i, f));
646
+ }, p = i ? he(i) : 0, h = !!(i && p > 10 && ue(i, f));
941
647
  if (i && p > 10 && !h && (l = !0), h && i) return console.info("[exige-scanner] capture", {
942
648
  method: "image-capture",
943
649
  frame: `${i.width}×${i.height}`,
944
650
  video: `${t.videoWidth}×${t.videoHeight}`,
945
651
  photoMax: d ? `${d.width ?? "—"}×${d.height ?? "—"}` : void 0,
946
652
  photoRequest: u,
947
- aspectMatch: Ae(i, f)
653
+ aspectMatch: de(i, f)
948
654
  }), {
949
655
  frame: i,
950
656
  method: "image-capture",
@@ -952,7 +658,7 @@ async function qe(t, n = {}) {
952
658
  luminance: p,
953
659
  diagnostics: m()
954
660
  };
955
- let g = e && n > 10 ? e : void 0, _ = g ?? (r ? Ie(r) : void 0);
661
+ let g = e && n > 10 ? e : void 0, _ = g ?? (r ? _e(r) : void 0);
956
662
  if (!_) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
957
663
  let v = l ? "image-capture-preview-size" : i ? "image-capture-empty" : a ? "image-capture-failed" : g ? void 0 : "video-frame-empty";
958
664
  return console.info("[exige-scanner] capture", {
@@ -984,9 +690,13 @@ async function qe(t, n = {}) {
984
690
  }
985
691
  };
986
692
  }
987
- async function Je() {
693
+ function De() {
694
+ let e = typeof navigator > "u" ? void 0 : navigator.userActivation;
695
+ return !e || e.isActive;
696
+ }
697
+ async function Oe() {
988
698
  let e = document.createElement("input");
989
- return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"), We(await new Promise((t, n) => {
699
+ return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"), z(await new Promise((t, n) => {
990
700
  e.addEventListener("change", () => {
991
701
  let r = e.files?.[0];
992
702
  r ? t(r) : n(/* @__PURE__ */ Error("No photo was selected."));
@@ -996,13 +706,318 @@ async function Je() {
996
706
  }));
997
707
  }
998
708
  //#endregion
709
+ //#region src/sdk/ort-runtime.ts
710
+ var ke = 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);
711
+ function V() {
712
+ return {
713
+ wasm: ke.href,
714
+ mjs: Ae.href
715
+ };
716
+ }
717
+ function je(e) {
718
+ return typeof e == "string" ? e.trim() || V() : e?.wasm.trim() && e.mjs.trim() ? {
719
+ wasm: e.wasm.trim(),
720
+ mjs: e.mjs.trim()
721
+ } : V();
722
+ }
723
+ //#endregion
724
+ //#region src/sdk/image.ts
725
+ function H(e, t, n) {
726
+ let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
727
+ return {
728
+ width: Math.max(1, Math.round(e * r)),
729
+ height: Math.max(1, Math.round(t * r))
730
+ };
731
+ }
732
+ async function Me(e) {
733
+ let t = URL.createObjectURL(e);
734
+ try {
735
+ let e = new Image();
736
+ return e.src = t, await e.decode(), e;
737
+ } finally {
738
+ URL.revokeObjectURL(t);
739
+ }
740
+ }
741
+ async function U(e, n = {}) {
742
+ if (e instanceof HTMLCanvasElement && n.cloneCanvas === !1 && !n.maxDimension) return e;
743
+ let r = document.createElement("canvas"), i = r.getContext("2d", { willReadFrequently: !0 });
744
+ if (!i) throw t();
745
+ if (e instanceof Blob) {
746
+ if ("createImageBitmap" in window) try {
747
+ let t = await createImageBitmap(e), a = H(t.width, t.height, n.maxDimension);
748
+ return r.width = a.width, r.height = a.height, i.drawImage(t, 0, 0, a.width, a.height), t.close(), r;
749
+ } catch {}
750
+ e = await Me(e);
751
+ }
752
+ let a = e instanceof HTMLImageElement ? e.naturalWidth : e.width, o = e instanceof HTMLImageElement ? e.naturalHeight : e.height;
753
+ if (!a || !o) throw Error("The image has no readable dimensions.");
754
+ let s = H(a, o, n.maxDimension);
755
+ return r.width = s.width, r.height = s.height, i.drawImage(e, 0, 0, s.width, s.height), r;
756
+ }
757
+ function Ne(e, t = "image/png", n = .92) {
758
+ return new Promise((r, i) => e.toBlob((e) => e ? r(e) : i(/* @__PURE__ */ Error("Could not encode the image.")), t, n));
759
+ }
760
+ function Pe(e, t, n) {
761
+ let r = Math.max(0, Math.min(t, e.x)), i = Math.max(0, Math.min(n, e.y));
762
+ return {
763
+ x: r,
764
+ y: i,
765
+ width: Math.max(0, Math.min(t - r, e.width)),
766
+ height: Math.max(0, Math.min(n - i, e.height))
767
+ };
768
+ }
769
+ //#endregion
770
+ //#region src/sdk/scan.ts
771
+ var Fe = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", Ie = 1280;
772
+ function Le(e, t, n) {
773
+ if (n) return n;
774
+ let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a = Ve() ? 560 : 900;
775
+ return i >= 1.6 ? Math.min(r, Math.max(a, Ie)) : a;
776
+ }
777
+ function W(e) {
778
+ return e?.trim() || "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
779
+ }
780
+ var Re = 3, G, ze = 0, K = /* @__PURE__ */ new Map();
781
+ function q(e, t) {
782
+ return Math.hypot(e.x - t.x, e.y - t.y);
783
+ }
784
+ function J(e) {
785
+ return {
786
+ ...e,
787
+ edges: {
788
+ top: {
789
+ start: e.topLeft,
790
+ end: e.topRight
791
+ },
792
+ right: {
793
+ start: e.topRight,
794
+ end: e.bottomRight
795
+ },
796
+ bottom: {
797
+ start: e.bottomRight,
798
+ end: e.bottomLeft
799
+ },
800
+ left: {
801
+ start: e.bottomLeft,
802
+ end: e.topLeft
803
+ }
804
+ }
805
+ };
806
+ }
807
+ function Be(e, t) {
808
+ let n = (e) => ({
809
+ x: e.x / t,
810
+ y: e.y / t
811
+ });
812
+ return {
813
+ topLeft: n(e.topLeft),
814
+ topRight: n(e.topRight),
815
+ bottomRight: n(e.bottomRight),
816
+ bottomLeft: n(e.bottomLeft)
817
+ };
818
+ }
819
+ function Ve() {
820
+ return typeof navigator > "u" ? !1 : navigator.maxTouchPoints > 0 || navigator.hardwareConcurrency <= 4 || typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
821
+ }
822
+ function He(t, n, r, i) {
823
+ return new Promise((a, o) => {
824
+ G || (G = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), G.onmessage = (t) => {
825
+ if (t.data.download?.url) {
826
+ k(t.data.download.url, t.data.download);
827
+ return;
828
+ }
829
+ let n = K.get(t.data.id);
830
+ n && (K.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.")));
831
+ }, G.onerror = () => {
832
+ let t = new e("worker", "The document worker could not start.");
833
+ for (let e of K.values()) e.reject(t);
834
+ K.clear(), G?.terminate(), G = void 0;
835
+ });
836
+ let s = ++ze;
837
+ K.set(s, {
838
+ resolve: a,
839
+ reject: o
840
+ });
841
+ let c = t.slice().buffer;
842
+ G.postMessage({
843
+ id: s,
844
+ pixels: c,
845
+ width: n,
846
+ height: r,
847
+ modelUrl: W(i.modelUrl),
848
+ heatmapThreshold: i.heatmapThreshold,
849
+ cacheModel: i.cacheModel,
850
+ ortWasmPaths: je(i.ortWasmPaths),
851
+ preferWebGpu: i.preferWebGpu ?? M()
852
+ }, [c]);
853
+ });
854
+ }
855
+ async function Y(n, r) {
856
+ let { width: i, height: a } = n, o = r.minDimension ?? 360;
857
+ if (Math.min(i, a) < o) return {
858
+ status: "low-quality",
859
+ confidence: 0,
860
+ message: `Use an image at least ${o}px on its shortest side.`,
861
+ sourceWidth: i,
862
+ sourceHeight: a
863
+ };
864
+ let s = Le(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;
865
+ if (c === 1) {
866
+ let e = n.getContext("2d", { willReadFrequently: !0 });
867
+ if (!e) throw t();
868
+ d = e.getImageData(0, 0, l, u).data;
869
+ } else {
870
+ let e = document.createElement("canvas");
871
+ e.width = l, e.height = u;
872
+ let r = e.getContext("2d", { willReadFrequently: !0 });
873
+ if (!r) throw t();
874
+ r.drawImage(n, 0, 0, e.width, e.height), d = r.getImageData(0, 0, e.width, e.height).data;
875
+ }
876
+ let f;
877
+ if (r.useWorker !== !1 && typeof Worker < "u") try {
878
+ f = await He(d, l, u, r);
879
+ } catch (t) {
880
+ if (t instanceof e && (t.code === "worker" || t.code === "model-http")) throw t;
881
+ f = {
882
+ sharpness: 20,
883
+ detector: "ml",
884
+ modelStatus: "failed",
885
+ modelError: t instanceof Error ? t.message : "Document worker failed."
886
+ };
887
+ }
888
+ else f = {
889
+ sharpness: 20,
890
+ detector: "ml",
891
+ modelStatus: "failed",
892
+ modelError: "ML detection requires a Web Worker."
893
+ };
894
+ let { sharpness: p, candidate: m, detector: h, modelStatus: g, modelProvider: _, modelError: v, modelNote: y, inferenceMs: b } = f, x = {
895
+ detector: h,
896
+ modelStatus: g,
897
+ modelProvider: _,
898
+ modelError: v,
899
+ modelNote: y,
900
+ inferenceMs: b
901
+ };
902
+ if (p < Re) return {
903
+ status: "low-quality",
904
+ confidence: Math.min(.3, p / 18),
905
+ message: "The image is too soft or dark to resolve four document edges.",
906
+ sourceWidth: i,
907
+ sourceHeight: a,
908
+ ...x
909
+ };
910
+ if (!m) return {
911
+ status: "no-document",
912
+ confidence: 0,
913
+ message: "No document corners found. Place all four edges on a contrasting surface.",
914
+ sourceWidth: i,
915
+ sourceHeight: a,
916
+ ...x
917
+ };
918
+ let S = Be(m.corners, c), C = J(S), w = r.minConfidence ?? .58;
919
+ return m.confidence < w ? {
920
+ status: "low-confidence",
921
+ quad: C,
922
+ corners: S,
923
+ confidence: m.confidence,
924
+ message: "Four possible corners were found, but the geometry is not reliable enough to crop.",
925
+ sourceWidth: i,
926
+ sourceHeight: a,
927
+ ...x
928
+ } : {
929
+ status: "success",
930
+ quad: C,
931
+ corners: S,
932
+ confidence: m.confidence,
933
+ message: "Four document edges detected.",
934
+ sourceWidth: i,
935
+ sourceHeight: a,
936
+ ...x
937
+ };
938
+ }
939
+ function Ue(e, t) {
940
+ let n = Math.max(1, Math.round(Math.max(q(e.topLeft, e.topRight), q(e.bottomLeft, e.bottomRight)))), r = Math.max(1, Math.round(Math.max(q(e.topLeft, e.bottomLeft), q(e.topRight, e.bottomRight)))), i = Math.min(1, t / Math.max(n, r));
941
+ return {
942
+ width: Math.max(1, Math.round(n * i)),
943
+ height: Math.max(1, Math.round(r * i))
944
+ };
945
+ }
946
+ function We(e, t, n, r, i) {
947
+ 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) => {
948
+ 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;
949
+ return Math.round(n * (1 - f) + r * f);
950
+ };
951
+ return [
952
+ h(0),
953
+ h(1),
954
+ h(2),
955
+ 255
956
+ ];
957
+ }
958
+ function Ge(e, n, r) {
959
+ let { width: i, height: a } = Ue(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
960
+ if (!o) throw t();
961
+ let s = o.getImageData(0, 0, e.width, e.height), c = document.createElement("canvas");
962
+ c.width = i, c.height = a;
963
+ let l = c.getContext("2d");
964
+ if (!l) throw t();
965
+ 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;
966
+ for (let t = 0; t < a; t += 1) {
967
+ let n = t / Math.max(1, a - 1);
968
+ for (let r = 0; r < i; r += 1) {
969
+ 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] = We(s.data, e.width, e.height, c, l), g = (t * i + r) * 4;
970
+ u.data[g] = f, u.data[g + 1] = p, u.data[g + 2] = m, u.data[g + 3] = h;
971
+ }
972
+ }
973
+ return l.putImageData(u, 0, 0), c;
974
+ }
975
+ async function Ke(e, t = {}) {
976
+ return await x("scan"), Y(await U(e, { cloneCanvas: !1 }), t);
977
+ }
978
+ async function qe(e, t, n = {}) {
979
+ await x("scan");
980
+ let r = await U(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? 4096;
981
+ return {
982
+ status: "success",
983
+ corners: t,
984
+ quad: J(t),
985
+ confidence: 1,
986
+ message: "Captured with the document edges shown in the finder.",
987
+ sourceWidth: r.width,
988
+ sourceHeight: r.height,
989
+ canvas: Ge(r, t, i)
990
+ };
991
+ }
992
+ async function Je(e, t = {}) {
993
+ await x("scan");
994
+ let n = await U(e, { cloneCanvas: !1 }), r = await Y(n, t);
995
+ if (r.status !== "success" || !r.corners) return r;
996
+ let i = t.maxOutputDimension ?? 4096;
997
+ return {
998
+ ...r,
999
+ canvas: Ge(n, r.corners, i),
1000
+ message: "Four document edges detected and perspective-corrected."
1001
+ };
1002
+ }
1003
+ function Ye(e) {
1004
+ 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})` : ""}`;
1005
+ }
1006
+ async function Xe(e, t = {}) {
1007
+ let n = await Je(e, t);
1008
+ return n.status === "success" ? n : {
1009
+ ...n,
1010
+ message: Ye(n)
1011
+ };
1012
+ }
1013
+ //#endregion
999
1014
  //#region src/sdk/lighting.ts
1000
- function Ye(e, t) {
1015
+ function Ze(e, t) {
1001
1016
  if (!e.length) return 0;
1002
1017
  let n = [...e].sort((e, t) => e - t);
1003
1018
  return n[Math.min(n.length - 1, Math.floor(n.length * t))];
1004
1019
  }
1005
- function Xe(e, t, n, r = 12) {
1020
+ function Qe(e, t, n, r = 12) {
1006
1021
  if (!t || !n || e.length < t * n) return {
1007
1022
  strong: !1,
1008
1023
  strength: 0,
@@ -1025,7 +1040,7 @@ function Xe(e, t, n, r = 12) {
1025
1040
  });
1026
1041
  }
1027
1042
  }
1028
- let s = Ye(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
1043
+ 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 = [];
1029
1044
  for (let e = 0; e < o.length; e += 1) {
1030
1045
  if (!c[e] || l[e]) continue;
1031
1046
  let t = [], n = [e];
@@ -1073,11 +1088,11 @@ function Xe(e, t, n, r = 12) {
1073
1088
  }
1074
1089
  return d;
1075
1090
  }
1076
- function Ze(e, t, n, r, i, a, o) {
1091
+ function $e(e, t, n, r, i, a, o) {
1077
1092
  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));
1078
1093
  return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
1079
1094
  }
1080
- function Qe(e, t, n) {
1095
+ function X(e, t, n) {
1081
1096
  let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
1082
1097
  for (let a = 1; a <= n; a += 1) {
1083
1098
  let n = 0;
@@ -1088,23 +1103,23 @@ function Qe(e, t, n) {
1088
1103
  stride: r
1089
1104
  };
1090
1105
  }
1091
- function $e(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
1092
- let { integral: i, stride: a } = Qe(e, t, n), o = new Uint8Array(e.length);
1106
+ function et(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
1107
+ let { integral: i, stride: a } = X(e, t, n), o = new Uint8Array(e.length);
1093
1108
  for (let s = 0; s < n; s += 1) for (let c = 0; c < t; c += 1) {
1094
- let l = Ze(i, a, t, n, c, s, r);
1109
+ let l = $e(i, a, t, n, c, s, r);
1095
1110
  o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
1096
1111
  }
1097
1112
  return o;
1098
1113
  }
1099
- function et(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
1100
- let { integral: a, stride: o } = Qe(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
1114
+ function tt(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
1115
+ let { integral: a, stride: o } = X(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
1101
1116
  for (let i = 0; i < n; i += 1) for (let l = 0; l < t; l += 1) {
1102
- let u = Ze(a, o, t, n, l, i, r);
1117
+ let u = $e(a, o, t, n, l, i, r);
1103
1118
  s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
1104
1119
  }
1105
1120
  return s;
1106
1121
  }
1107
- function tt(e, t, n) {
1122
+ function nt(e, t, n) {
1108
1123
  let r = [
1109
1124
  e.topLeft,
1110
1125
  e.topRight,
@@ -1118,8 +1133,8 @@ function tt(e, t, n) {
1118
1133
  height: s - a
1119
1134
  };
1120
1135
  }
1121
- function nt(e, t) {
1122
- let n = tt(t, e.width, e.height);
1136
+ function rt(e, t) {
1137
+ let n = nt(t, e.width, e.height);
1123
1138
  if (n.width <= 0 || n.height <= 0) return {
1124
1139
  strong: !1,
1125
1140
  strength: 0,
@@ -1138,18 +1153,18 @@ function nt(e, t) {
1138
1153
  i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
1139
1154
  let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
1140
1155
  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);
1141
- return Xe(o, r.width, r.height);
1156
+ return Qe(o, r.width, r.height);
1142
1157
  }
1143
1158
  //#endregion
1144
1159
  //#region src/sdk/finder.ts
1145
- function rt(e, t) {
1160
+ function it(e, t) {
1146
1161
  return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
1147
1162
  }
1148
- async function it(e, t) {
1163
+ async function at(e, t) {
1149
1164
  let n = await e();
1150
1165
  return t(), n;
1151
1166
  }
1152
- function at(e) {
1167
+ function ot(e) {
1153
1168
  return e === "alwaysOn" || e === "only" ? {
1154
1169
  visible: !1,
1155
1170
  checked: !0,
@@ -1164,7 +1179,7 @@ function at(e) {
1164
1179
  mutable: !0
1165
1180
  };
1166
1181
  }
1167
- function X(e) {
1182
+ function Z(e) {
1168
1183
  return [
1169
1184
  e.topLeft,
1170
1185
  e.topRight,
@@ -1172,7 +1187,19 @@ function X(e) {
1172
1187
  e.bottomLeft
1173
1188
  ];
1174
1189
  }
1175
- function ot(e, t) {
1190
+ var st = 1600;
1191
+ function ct(e = A()) {
1192
+ return e.iosWebKit ? {
1193
+ intervalMs: 70,
1194
+ maxFrameDimension: 720,
1195
+ maxAnalysisDimension: 720
1196
+ } : {
1197
+ intervalMs: 140,
1198
+ maxFrameDimension: st,
1199
+ maxAnalysisDimension: 520
1200
+ };
1201
+ }
1202
+ function lt(e, t) {
1176
1203
  let n = e.status === "success" && e.modelStatus !== "failed", r = {
1177
1204
  status: e.status,
1178
1205
  confidence: Number(e.confidence.toFixed(3)),
@@ -1195,7 +1222,7 @@ function ot(e, t) {
1195
1222
  detail: r
1196
1223
  };
1197
1224
  }
1198
- function st(e) {
1225
+ function ut(e) {
1199
1226
  let t = 0;
1200
1227
  for (let n = 0; n < e.length; n += 1) {
1201
1228
  let r = e[n], i = e[(n + 1) % e.length];
@@ -1203,42 +1230,42 @@ function st(e) {
1203
1230
  }
1204
1231
  return Math.abs(t) / 2;
1205
1232
  }
1206
- function Z(e, t) {
1233
+ function Q(e, t) {
1207
1234
  return Math.hypot(e.x - t.x, e.y - t.y);
1208
1235
  }
1209
- var Q = {
1236
+ var $ = {
1210
1237
  widthFill: 0,
1211
1238
  heightFill: 0,
1212
1239
  limitingFill: 0,
1213
1240
  areaFill: 0,
1214
1241
  aspectRatio: 1
1215
1242
  };
1216
- function ct(e, t, n) {
1217
- 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));
1243
+ function dt(e, t, n) {
1244
+ 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));
1218
1245
  return {
1219
1246
  widthFill: o,
1220
1247
  heightFill: s,
1221
1248
  limitingFill: Math.max(o, s),
1222
- areaFill: st(r) / Math.max(1, t * n),
1249
+ areaFill: ut(r) / Math.max(1, t * n),
1223
1250
  aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
1224
1251
  };
1225
1252
  }
1226
- function lt(e, t, n, r = {}) {
1253
+ function ft(e, t, n, r = {}) {
1227
1254
  let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
1228
1255
  if (e.aspectRatio < a) return i;
1229
1256
  let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
1230
1257
  return Math.min(o ?? i + .08, 1 - n * 2);
1231
1258
  }
1232
- function ut(e, t, n = {}) {
1259
+ function pt(e, t, n = {}) {
1233
1260
  let r = n.confidenceThreshold ?? .72;
1234
1261
  if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
1235
1262
  hint: "Place the document in the frame",
1236
1263
  reason: "place-document",
1237
1264
  fillRatio: 0,
1238
- fill: Q,
1265
+ fill: $,
1239
1266
  readyForAutoCapture: !1
1240
1267
  };
1241
- let i = X(e.quad), a = ct(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;
1268
+ let i = Z(e.quad), a = dt(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;
1242
1269
  if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
1243
1270
  hint: "Move farther away",
1244
1271
  reason: "move-farther-away",
@@ -1246,14 +1273,14 @@ function ut(e, t, n = {}) {
1246
1273
  fill: a,
1247
1274
  readyForAutoCapture: !1
1248
1275
  };
1249
- let [u, d, f, p] = i, m = Z(u, d), h = Z(d, f), g = Z(f, p), _ = Z(p, u);
1276
+ let [u, d, f, p] = i, m = Q(u, d), h = Q(d, f), g = Q(f, p), _ = Q(p, u);
1250
1277
  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) ? {
1251
1278
  hint: "Hold the camera straight",
1252
1279
  reason: "straighten-camera",
1253
1280
  fillRatio: o,
1254
1281
  fill: a,
1255
1282
  readyForAutoCapture: !1
1256
- } : o < lt(a, t.previouslyReady === !0, s, n) ? {
1283
+ } : o < ft(a, t.previouslyReady === !0, s, n) ? {
1257
1284
  hint: "Move closer",
1258
1285
  reason: "move-closer",
1259
1286
  fillRatio: o,
@@ -1267,7 +1294,7 @@ function ut(e, t, n = {}) {
1267
1294
  readyForAutoCapture: t.ready
1268
1295
  };
1269
1296
  }
1270
- var $ = class {
1297
+ var mt = class {
1271
1298
  previous;
1272
1299
  count = 0;
1273
1300
  ready = !1;
@@ -1284,8 +1311,8 @@ var $ = class {
1284
1311
  ready: !1,
1285
1312
  movement: Infinity
1286
1313
  };
1287
- let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...X(e.quad).map((e, n) => {
1288
- let r = X(this.previous)[n];
1314
+ let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...Z(e.quad).map((e, n) => {
1315
+ let r = Z(this.previous)[n];
1289
1316
  return Math.hypot(e.x - r.x, e.y - r.y) / Math.max(1, t);
1290
1317
  })) : Infinity, r = this.options.exitCornerTolerance ?? Math.max(this.options.cornerTolerance, .036);
1291
1318
  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, {
@@ -1295,14 +1322,14 @@ var $ = class {
1295
1322
  };
1296
1323
  }
1297
1324
  };
1298
- function dt(e, n) {
1325
+ function ht(e, n) {
1299
1326
  let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
1300
1327
  i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
1301
1328
  let a = i.getContext("2d");
1302
1329
  if (!a) throw t();
1303
1330
  return a.drawImage(e, 0, 0, i.width, i.height), i;
1304
1331
  }
1305
- function ft() {
1332
+ function gt() {
1306
1333
  let e = window.AudioContext ?? window.webkitAudioContext;
1307
1334
  if (!e) return;
1308
1335
  let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
@@ -1313,29 +1340,29 @@ function ft() {
1313
1340
  let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
1314
1341
  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();
1315
1342
  }
1316
- async function pt(e) {
1343
+ async function _t(e) {
1317
1344
  let t = document.createElement("video");
1318
1345
  return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
1319
1346
  }
1320
- async function mt(t) {
1347
+ async function vt(t) {
1321
1348
  await x("scan");
1322
- let n = at(t.autoCapture), r = new $({
1349
+ let n = ot(t.autoCapture), r = new mt({
1323
1350
  stableFrames: t.stableFrames ?? 4,
1324
1351
  confidenceThreshold: t.confidenceThreshold ?? .72,
1325
1352
  cornerTolerance: t.cornerTolerance ?? .024,
1326
1353
  exitCornerTolerance: t.exitCornerTolerance ?? .036
1327
- }), i = t.maxFrameDimension ?? 1600, a = t.intervalMs ?? 140, o = {
1354
+ }), i = ct(), a = t.maxFrameDimension ?? i.maxFrameDimension, o = t.intervalMs ?? i.intervalMs, s = {
1328
1355
  minDimension: 220,
1329
- maxAnalysisDimension: 520,
1356
+ maxAnalysisDimension: i.maxAnalysisDimension,
1330
1357
  ...t.detection
1331
- }, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await pt(t.source) : t.source, c = !0, l = !1, u = !1, d = 0, f, p = "", m = 0, h = {
1358
+ }, c = typeof MediaStream < "u" && t.source instanceof MediaStream ? await _t(t.source) : t.source, l = !0, u = !1, d = !1, f = 0, p, m = "", h = 0, g = {
1332
1359
  state: "detecting",
1333
1360
  confidence: 0,
1334
1361
  guidance: {
1335
1362
  hint: "Place the document in the frame",
1336
1363
  reason: "place-document",
1337
1364
  fillRatio: 0,
1338
- fill: Q,
1365
+ fill: $,
1339
1366
  readyForAutoCapture: !1
1340
1367
  },
1341
1368
  lighting: {
@@ -1345,71 +1372,71 @@ async function mt(t) {
1345
1372
  stableFrames: 0,
1346
1373
  requiredStableFrames: t.stableFrames ?? 4,
1347
1374
  autoCapture: { ...n }
1348
- }, g = () => s instanceof HTMLCanvasElement ? dt(s, i) : Y(s, i), _ = (e) => {
1349
- h = e, t.onStatus?.(e);
1350
- }, v = (e) => {
1351
- let t = ot(e, s instanceof HTMLVideoElement ? {
1352
- width: s.videoWidth,
1353
- height: s.videoHeight
1375
+ }, _ = () => c instanceof HTMLCanvasElement ? ht(c, a) : B(c, a), v = (e) => {
1376
+ g = e, t.onStatus?.(e);
1377
+ }, y = (e) => {
1378
+ let t = lt(e, c instanceof HTMLVideoElement ? {
1379
+ width: c.videoWidth,
1380
+ height: c.videoHeight
1354
1381
  } : {
1355
- width: s.width,
1356
- height: s.height
1382
+ width: c.width,
1383
+ height: c.height
1357
1384
  }), n = performance.now();
1358
- t.key === p && n - m < 2e3 || (p = t.key, m = n, console[t.level](`[exige-scanner] ${t.summary}`, t.detail));
1359
- }, y = () => {
1360
- c = !1, window.clearTimeout(d), s instanceof HTMLVideoElement && s !== t.source && (s.srcObject = null);
1361
- }, b = async (e = "manual") => {
1362
- if (l) throw Error("A finder capture is already in progress.");
1363
- l = !0;
1385
+ t.key === m && n - h < 2e3 || (m = t.key, h = n, console[t.level](`[exige-scanner] ${t.summary}`, t.detail));
1386
+ }, b = () => {
1387
+ l = !1, window.clearTimeout(f), c instanceof HTMLVideoElement && c !== t.source && (c.srcObject = null);
1388
+ }, S = async (e = "manual") => {
1389
+ if (u) throw Error("A finder capture is already in progress.");
1390
+ u = !0;
1364
1391
  let n;
1365
1392
  try {
1366
- n = await it(t.captureFrame ?? g, () => {
1367
- _({
1368
- ...h,
1393
+ n = await at(t.captureFrame ?? _, () => {
1394
+ v({
1395
+ ...g,
1369
1396
  state: "captured"
1370
- }), t.playShutterSound !== !1 && ft(), y();
1397
+ }), t.playShutterSound !== !1 && gt(), b();
1371
1398
  });
1372
1399
  } catch (e) {
1373
- throw l = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
1400
+ throw u = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
1374
1401
  }
1375
1402
  let r = {
1376
1403
  frame: n,
1377
- detection: f,
1404
+ detection: p,
1378
1405
  reason: e
1379
1406
  };
1380
1407
  return await t.onCapture?.(r), r;
1381
- }, S = async () => {
1382
- if (c && !l) {
1408
+ }, C = async () => {
1409
+ if (l && !u) {
1383
1410
  try {
1384
- let e = g(), i = await R(e, o);
1385
- f = i, v(i);
1386
- let a = i.quad ? nt(e, i.quad) : {
1411
+ let e = _(), i = await Ke(e, s);
1412
+ p = i, y(i);
1413
+ let a = i.quad ? rt(e, i.quad) : {
1387
1414
  strong: !1,
1388
1415
  strength: 0
1389
- }, s = a.strong ? {
1416
+ }, o = a.strong ? {
1390
1417
  castShadow: !0,
1391
1418
  strength: a.strength,
1392
1419
  hint: "Tilt to move the shadow off the page"
1393
1420
  } : {
1394
1421
  castShadow: !1,
1395
1422
  strength: a.strength
1396
- }, c = r.update(i), l = ut(i, {
1423
+ }, c = r.update(i), l = pt(i, {
1397
1424
  ...c,
1398
- previouslyReady: u
1425
+ previouslyReady: d
1399
1426
  }, {
1400
1427
  confidenceThreshold: t.confidenceThreshold ?? .72,
1401
1428
  ...t.guidance
1402
1429
  });
1403
- u = l.readyForAutoCapture;
1404
- let d = i.status !== "success" || l.reason === "place-document" ? "seeking" : l.readyForAutoCapture ? "ready" : "unstable";
1405
- if (_({
1406
- state: d,
1430
+ d = l.readyForAutoCapture;
1431
+ let u = i.status !== "success" || l.reason === "place-document" ? "seeking" : l.readyForAutoCapture ? "ready" : "unstable";
1432
+ if (v({
1433
+ state: u,
1407
1434
  confidence: i.confidence,
1408
1435
  quad: i.quad,
1409
1436
  guidance: l,
1410
- lighting: s,
1437
+ lighting: o,
1411
1438
  stableFrames: c.stableFrames,
1412
- requiredStableFrames: h.requiredStableFrames,
1439
+ requiredStableFrames: g.requiredStableFrames,
1413
1440
  autoCapture: { ...n },
1414
1441
  sourceWidth: i.sourceWidth,
1415
1442
  sourceHeight: i.sourceHeight,
@@ -1420,33 +1447,33 @@ async function mt(t) {
1420
1447
  modelNote: i.modelNote,
1421
1448
  inferenceMs: i.inferenceMs
1422
1449
  }), l.readyForAutoCapture && n.checked) try {
1423
- await b("auto");
1450
+ await S("auto");
1424
1451
  return;
1425
1452
  } catch (e) {
1426
- r.reset(), u = !1, t.onCaptureError?.(e instanceof Error ? e : /* @__PURE__ */ Error("Automatic capture failed."));
1453
+ r.reset(), d = !1, t.onCaptureError?.(e instanceof Error ? e : /* @__PURE__ */ Error("Automatic capture failed."));
1427
1454
  }
1428
1455
  } catch (t) {
1429
- r.reset(), u = !1;
1456
+ r.reset(), d = !1;
1430
1457
  let i = t instanceof e ? {
1431
1458
  detector: "ml",
1432
1459
  modelStatus: "failed",
1433
1460
  modelError: t.message
1434
1461
  } : { modelError: t instanceof Error ? t.message : "Finder tick failed." };
1435
- v({
1462
+ y({
1436
1463
  status: "no-document",
1437
1464
  confidence: 0,
1438
1465
  message: i.modelError ?? "Finder tick failed.",
1439
1466
  sourceWidth: 0,
1440
1467
  sourceHeight: 0,
1441
1468
  ...i
1442
- }), _({
1469
+ }), v({
1443
1470
  state: "seeking",
1444
1471
  confidence: 0,
1445
1472
  guidance: {
1446
1473
  hint: "Place the document in the frame",
1447
1474
  reason: "place-document",
1448
1475
  fillRatio: 0,
1449
- fill: Q,
1476
+ fill: $,
1450
1477
  readyForAutoCapture: !1
1451
1478
  },
1452
1479
  lighting: {
@@ -1454,27 +1481,27 @@ async function mt(t) {
1454
1481
  strength: 0
1455
1482
  },
1456
1483
  stableFrames: 0,
1457
- requiredStableFrames: h.requiredStableFrames,
1484
+ requiredStableFrames: g.requiredStableFrames,
1458
1485
  autoCapture: { ...n },
1459
1486
  ...i
1460
1487
  });
1461
1488
  }
1462
- c && (d = window.setTimeout(() => void S(), a));
1489
+ l && (f = window.setTimeout(() => void C(), o));
1463
1490
  }
1464
1491
  };
1465
- return t.onStatus?.(h), S(), {
1466
- stop: y,
1467
- capture: () => b("manual"),
1492
+ return t.onStatus?.(g), C(), {
1493
+ stop: b,
1494
+ capture: () => S("manual"),
1468
1495
  setAutoCapture(e) {
1469
- return !n.mutable || l ? !1 : (n.checked = e, _({
1470
- ...h,
1496
+ return !n.mutable || u ? !1 : (n.checked = e, v({
1497
+ ...g,
1471
1498
  autoCapture: { ...n }
1472
1499
  }), !0);
1473
1500
  },
1474
- getStatus: () => h
1501
+ getStatus: () => g
1475
1502
  };
1476
1503
  }
1477
1504
  //#endregion
1478
- export { we as A, b as B, qe as C, R as D, Ce as E, ie as F, e as H, ne as I, a as L, de as M, fe as N, j as O, A as P, o as R, Ee as S, pe as T, t as U, y as V, U as _, ut as a, J as b, et as c, G as d, je as f, Te as g, H as h, ct as i, B as j, z as k, Xe as l, Y as m, at as n, rt as o, ze as p, lt as r, mt as s, $ as t, $e as u, Me as v, K as w, Je as x, q as y, x as z };
1505
+ export { I as A, o as B, R as C, De as D, oe as E, Ee as F, t as G, b as H, F as I, ie as L, Oe as M, M as N, j as O, se as P, ne as R, fe as S, A as T, y as U, x as V, e as W, Ye as _, pt as a, U as b, tt as c, Fe as d, qe as f, Xe as g, Je as h, dt as i, L as j, pe as k, Qe as l, W as m, ot as n, it as o, Ke as p, ft as r, vt as s, mt as t, et as u, Ne as v, B as w, P as x, Pe as y, a as z };
1479
1506
 
1480
- //# sourceMappingURL=finder-Dcg3mVJM.js.map
1507
+ //# sourceMappingURL=finder-BvBpdbHa.js.map