@exige/web-scanner-sdk 0.2.17 → 0.2.23

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,22 +198,22 @@ function te() {
198
198
  total: n ? t : null
199
199
  };
200
200
  }
201
- function O() {
202
- let e = te();
201
+ function k() {
202
+ let e = O();
203
203
  for (let t of T) t(e);
204
204
  }
205
- function ne(e) {
206
- return e(te()), T.add(e), () => {
205
+ function te(e) {
206
+ return e(O()), T.add(e), () => {
207
207
  T.delete(e);
208
208
  };
209
209
  }
210
- function k(e, t) {
210
+ function A(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
+ }), k();
215
215
  }
216
- async function re(e, t) {
216
+ async function ne(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 re(e, t) {
238
238
  total: n
239
239
  }), o.buffer;
240
240
  }
241
- async function ie(t, n) {
241
+ async function re(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
- k(t, {
247
+ A(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 re(r, (e) => k(t, e));
253
+ return ne(r, (e) => A(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), O());
260
+ D.delete(t), w.has(t) && (w.delete(t), k());
261
261
  }
262
262
  }
263
263
  //#endregion
264
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 A() {
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() {
267
267
  return {
268
- wasm: ae.href,
269
- mjs: oe.href
268
+ wasm: ie.href,
269
+ mjs: ae.href
270
270
  };
271
271
  }
272
272
  function se(e) {
273
- return typeof e == "string" ? e.trim() || A() : e?.wasm.trim() && e.mjs.trim() ? {
273
+ return typeof e == "string" ? e.trim() || oe() : e?.wasm.trim() && e.mjs.trim() ? {
274
274
  wasm: e.wasm.trim(),
275
275
  mjs: e.mjs.trim()
276
- } : A();
276
+ } : oe();
277
277
  }
278
278
  //#endregion
279
279
  //#region src/sdk/image.ts
280
- function ce(e, t, n) {
280
+ function j(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 le(e) {
287
+ async function ce(e) {
288
288
  let t = URL.createObjectURL(e);
289
289
  try {
290
290
  let e = new Image();
@@ -293,26 +293,26 @@ async function le(e) {
293
293
  URL.revokeObjectURL(t);
294
294
  }
295
295
  }
296
- async function j(e, n = {}) {
296
+ async function M(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 = ce(t.width, t.height, n.maxDimension);
302
+ let t = await createImageBitmap(e), a = j(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 le(e);
305
+ e = await ce(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 = ce(a, o, n.maxDimension);
309
+ let s = j(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 ue(e, t = "image/png", n = .92) {
312
+ function le(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 de(e, t, n) {
315
+ function ue(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 de(e, t, n) {
323
323
  }
324
324
  //#endregion
325
325
  //#region src/sdk/scan.ts
326
- var fe = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", pe = 1280;
327
- function me(e, t, n) {
326
+ var de = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", fe = 1280;
327
+ function pe(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 = L() ? 560 : 900;
330
- return i >= 1.6 ? Math.min(r, Math.max(a, pe)) : a;
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;
331
331
  }
332
- function M(e) {
332
+ function N(e) {
333
333
  return e?.trim() || "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
334
334
  }
335
- var he = 3, N, ge = 0, P = /* @__PURE__ */ new Map();
336
- function F(e, t) {
335
+ var me = 3, P, he = 0, F = /* @__PURE__ */ new Map();
336
+ function I(e, t) {
337
337
  return Math.hypot(e.x - t.x, e.y - t.y);
338
338
  }
339
- function I(e) {
339
+ function L(e) {
340
340
  return {
341
341
  ...e,
342
342
  edges: {
@@ -359,7 +359,7 @@ function I(e) {
359
359
  }
360
360
  };
361
361
  }
362
- function _e(e, t) {
362
+ function ge(e, t) {
363
363
  let n = (e) => ({
364
364
  x: e.x / t,
365
365
  y: e.y / t
@@ -371,42 +371,42 @@ function _e(e, t) {
371
371
  bottomLeft: n(e.bottomLeft)
372
372
  };
373
373
  }
374
- function L() {
374
+ function R() {
375
375
  return typeof navigator > "u" ? !1 : navigator.maxTouchPoints > 0 || navigator.hardwareConcurrency <= 4 || typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
376
376
  }
377
- function ve(t, n, r, i) {
377
+ function _e(t, n, r, i) {
378
378
  return new Promise((a, o) => {
379
- N || (N = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), N.onmessage = (t) => {
379
+ P || (P = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), P.onmessage = (t) => {
380
380
  if (t.data.download?.url) {
381
- k(t.data.download.url, t.data.download);
381
+ A(t.data.download.url, t.data.download);
382
382
  return;
383
383
  }
384
- let n = P.get(t.data.id);
385
- n && (P.delete(t.data.id), t.data.error ? n.reject(t.data.errorCode ? new e(t.data.errorCode, t.data.error) : Error(t.data.error)) : t.data.result ? n.resolve(t.data.result) : n.reject(/* @__PURE__ */ Error("The document worker returned no result.")));
386
- }, N.onerror = () => {
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 = () => {
387
387
  let t = new e("worker", "The document worker could not start.");
388
- for (let e of P.values()) e.reject(t);
389
- P.clear(), N?.terminate(), N = void 0;
388
+ for (let e of F.values()) e.reject(t);
389
+ F.clear(), P?.terminate(), P = void 0;
390
390
  });
391
- let s = ++ge;
392
- P.set(s, {
391
+ let s = ++he;
392
+ F.set(s, {
393
393
  resolve: a,
394
394
  reject: o
395
395
  });
396
396
  let c = t.slice().buffer;
397
- N.postMessage({
397
+ P.postMessage({
398
398
  id: s,
399
399
  pixels: c,
400
400
  width: n,
401
401
  height: r,
402
- modelUrl: M(i.modelUrl),
402
+ modelUrl: N(i.modelUrl),
403
403
  heatmapThreshold: i.heatmapThreshold,
404
404
  cacheModel: i.cacheModel,
405
405
  ortWasmPaths: se(i.ortWasmPaths)
406
406
  }, [c]);
407
407
  });
408
408
  }
409
- async function R(n, r) {
409
+ async function ve(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 R(n, r) {
415
415
  sourceWidth: i,
416
416
  sourceHeight: a
417
417
  };
418
- let s = me(i, a, r.maxAnalysisDimension), c = Math.min(1, s / Math.max(i, a)), l = document.createElement("canvas");
418
+ let s = pe(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 ve(d, l.width, l.height, r);
425
+ f = await _e(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 = {
@@ -438,20 +438,21 @@ async function R(n, r) {
438
438
  modelStatus: "failed",
439
439
  modelError: "ML detection requires a Web Worker."
440
440
  };
441
- let { sharpness: p, candidate: m, detector: h, modelStatus: g, modelProvider: _, modelError: v, inferenceMs: y } = f, b = {
441
+ let { sharpness: p, candidate: m, detector: h, modelStatus: g, modelProvider: _, modelError: v, modelNote: y, inferenceMs: b } = f, x = {
442
442
  detector: h,
443
443
  modelStatus: g,
444
444
  modelProvider: _,
445
445
  modelError: v,
446
- inferenceMs: y
446
+ modelNote: y,
447
+ inferenceMs: b
447
448
  };
448
- if (p < he) return {
449
+ if (p < me) return {
449
450
  status: "low-quality",
450
451
  confidence: Math.min(.3, p / 18),
451
452
  message: "The image is too soft or dark to resolve four document edges.",
452
453
  sourceWidth: i,
453
454
  sourceHeight: a,
454
- ...b
455
+ ...x
455
456
  };
456
457
  if (!m) return {
457
458
  status: "no-document",
@@ -459,37 +460,49 @@ async function R(n, r) {
459
460
  message: "No document corners found. Place all four edges on a contrasting surface.",
460
461
  sourceWidth: i,
461
462
  sourceHeight: a,
462
- ...b
463
+ ...x
463
464
  };
464
- let x = _e(m.corners, c), S = I(x), C = r.minConfidence ?? .58;
465
- return m.confidence < C ? {
465
+ let S = ge(m.corners, c), C = L(S), w = r.minConfidence ?? .58;
466
+ return m.confidence < w ? {
466
467
  status: "low-confidence",
467
- quad: S,
468
- corners: x,
468
+ quad: C,
469
+ corners: S,
469
470
  confidence: m.confidence,
470
471
  message: "Four possible corners were found, but the geometry is not reliable enough to crop.",
471
472
  sourceWidth: i,
472
473
  sourceHeight: a,
473
- ...b
474
+ ...x
474
475
  } : {
475
476
  status: "success",
476
- quad: S,
477
- corners: x,
477
+ quad: C,
478
+ corners: S,
478
479
  confidence: m.confidence,
479
480
  message: "Four document edges detected.",
480
481
  sourceWidth: i,
481
482
  sourceHeight: a,
482
- ...b
483
+ ...x
483
484
  };
484
485
  }
485
486
  function ye(e, t) {
486
- let n = Math.max(1, Math.round(Math.max(F(e.topLeft, e.topRight), F(e.bottomLeft, e.bottomRight)))), r = Math.max(1, Math.round(Math.max(F(e.topLeft, e.bottomLeft), F(e.topRight, e.bottomRight)))), i = Math.min(1, t / Math.max(n, r));
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));
487
488
  return {
488
489
  width: Math.max(1, Math.round(n * i)),
489
490
  height: Math.max(1, Math.round(r * i))
490
491
  };
491
492
  }
492
- function z(e, n, r) {
493
+ function be(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 xe(e, n, r) {
493
506
  let { width: i, height: a } = ye(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
494
507
  if (!o) throw t();
495
508
  let s = o.getImageData(0, 0, e.width, e.height), c = document.createElement("canvas");
@@ -500,43 +513,43 @@ function z(e, n, r) {
500
513
  for (let t = 0; t < a; t += 1) {
501
514
  let n = t / Math.max(1, a - 1);
502
515
  for (let r = 0; r < i; r += 1) {
503
- let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = Math.max(0, Math.min(e.width - 1, Math.round((w * a + T * n + d.x) / o))), l = (Math.max(0, Math.min(e.height - 1, Math.round((E * a + D * n + d.y) / o))) * e.width + c) * 4, f = (t * i + r) * 4;
504
- u.data[f] = s.data[l], u.data[f + 1] = s.data[l + 1], u.data[f + 2] = s.data[l + 2], u.data[f + 3] = s.data[l + 3];
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;
517
+ u.data[g] = f, u.data[g + 1] = p, u.data[g + 2] = m, u.data[g + 3] = h;
505
518
  }
506
519
  }
507
520
  return l.putImageData(u, 0, 0), c;
508
521
  }
509
- async function B(e, t = {}) {
510
- return await x("scan"), R(await j(e, { cloneCanvas: !1 }), t);
522
+ async function Se(e, t = {}) {
523
+ return await x("scan"), ve(await M(e, { cloneCanvas: !1 }), t);
511
524
  }
512
- async function be(e, t, n = {}) {
525
+ async function Ce(e, t, n = {}) {
513
526
  await x("scan");
514
- let r = await j(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? (L() ? 2048 : 4096);
527
+ let r = await M(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? (R() ? 2048 : 4096);
515
528
  return {
516
529
  status: "success",
517
530
  corners: t,
518
- quad: I(t),
531
+ quad: L(t),
519
532
  confidence: 1,
520
533
  message: "Captured with the document edges shown in the finder.",
521
534
  sourceWidth: r.width,
522
535
  sourceHeight: r.height,
523
- canvas: z(r, t, i)
536
+ canvas: xe(r, t, i)
524
537
  };
525
538
  }
526
- async function xe(e, t = {}) {
539
+ async function we(e, t = {}) {
527
540
  await x("scan");
528
- let n = await j(e, { cloneCanvas: !1 }), r = await R(n, t);
541
+ let n = await M(e, { cloneCanvas: !1 }), r = await ve(n, t);
529
542
  if (r.status !== "success" || !r.corners) return r;
530
- let i = t.maxOutputDimension ?? (L() ? 2048 : 4096);
543
+ let i = t.maxOutputDimension ?? (R() ? 2048 : 4096);
531
544
  return {
532
545
  ...r,
533
- canvas: z(n, r.corners, i),
546
+ canvas: xe(n, r.corners, i),
534
547
  message: "Four document edges detected and perspective-corrected."
535
548
  };
536
549
  }
537
550
  //#endregion
538
551
  //#region src/sdk/camera.ts
539
- function V(e, t) {
552
+ function z(e, t) {
540
553
  let { engine: n } = t;
541
554
  return [
542
555
  `${e}:`,
@@ -547,13 +560,13 @@ function V(e, t) {
547
560
  ` liveLuma: ${t.liveLuminance.toFixed(1)}`,
548
561
  ` mirrorLuma: ${t.mirrorLuminance.toFixed(1)}`,
549
562
  ` mirrorAgeMs: ${Number.isFinite(t.mirrorAgeMs) ? Math.round(t.mirrorAgeMs) : "none"}`,
550
- ` hasImageCapture: ${t.hasImageCapture} (never used)`,
563
+ ` hasImageCapture: ${t.hasImageCapture}${t.engine.iosWebKit ? " (skipped on webkit)" : " (still capture)"}`,
551
564
  ` torch: ${t.torch.mode} supported=${t.torch.supported} on=${t.torch.on}`
552
565
  ].join("\n");
553
566
  }
554
- function Se(e) {
567
+ function Te(e) {
555
568
  let t = ["Exige scanner capture report", `time: ${e.capturedAt ?? (/* @__PURE__ */ new Date()).toISOString()}`];
556
- 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) {
569
+ 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(z("shutter", e.shutter)), e.live && t.push(z("live", e.live)), e.finder) {
557
570
  let n = e.finder;
558
571
  t.push([
559
572
  "finder:",
@@ -561,12 +574,16 @@ function Se(e) {
561
574
  ` confidence: ${n.confidence === void 0 ? "—" : n.confidence.toFixed(3)}`,
562
575
  ` stable: ${n.stableFrames ?? "—"}/${n.requiredStableFrames ?? "—"}`,
563
576
  ` detector: ${n.detector ?? "—"} ${n.modelStatus ?? ""}`.trim(),
577
+ ` modelError: ${n.modelError ?? "—"}`,
578
+ ` provider: ${n.modelProvider ?? "—"}`,
579
+ ` note: ${n.modelNote ?? "—"}`,
580
+ ` inferenceMs: ${n.inferenceMs === void 0 ? "—" : Math.round(n.inferenceMs)}`,
564
581
  ` source: ${n.sourceWidth ?? "—"}x${n.sourceHeight ?? "—"}`
565
582
  ].join("\n"));
566
583
  }
567
584
  return `${t.join("\n")}\n`;
568
585
  }
569
- function H(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
586
+ function B(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
570
587
  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;
571
588
  return {
572
589
  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",
@@ -575,12 +592,22 @@ function H(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof nav
575
592
  userAgent: e
576
593
  };
577
594
  }
578
- var Ce = 1080, we = 1920, Te = 1920, Ee = 1280;
579
- function U(e) {
580
- let t = e ?? H();
581
- return !t.iosWebKit && t.browser === "chrome" && /Android/i.test(t.userAgent) && !/Edg|OPR|SamsungBrowser/i.test(t.userAgent);
595
+ function Ee(e, t) {
596
+ return t && !e.iosWebKit;
597
+ }
598
+ 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
+ };
582
604
  }
583
- var De = 10, W = class {
605
+ function Oe(e, t) {
606
+ if (!e.width || !e.height || !t.width || !t.height) return !1;
607
+ let n = e.width / e.height / (t.width / t.height);
608
+ return n > .97 && n < 1.03;
609
+ }
610
+ var ke = 10, V = class {
584
611
  on = !1;
585
612
  darkCount = 0;
586
613
  brightCount = 0;
@@ -603,7 +630,7 @@ var De = 10, W = class {
603
630
  return this.on;
604
631
  }
605
632
  };
606
- function G(e, t) {
633
+ function H(e, t) {
607
634
  return t ? e === "alwaysOn" || e === "alwaysOff" ? {
608
635
  mode: e,
609
636
  supported: !0,
@@ -627,37 +654,37 @@ function G(e, t) {
627
654
  automatic: e === "auto"
628
655
  };
629
656
  }
630
- function K(e) {
657
+ function U(e) {
631
658
  let t = Math.floor(e.length / 4);
632
659
  if (!t) return 0;
633
660
  let n = 0;
634
661
  for (let r = 0; r < t * 4; r += 4) n += e[r] * .299 + e[r + 1] * .587 + e[r + 2] * .114;
635
662
  return n / t;
636
663
  }
637
- function Oe(e, t = 10) {
664
+ function Ae(e, t = 10) {
638
665
  if (e.length < 4) return !0;
639
666
  let n = Math.floor(e.length / 4), r = 0;
640
667
  for (let i = 0; i < n * 4; i += 4) e[i] * .299 + e[i + 1] * .587 + e[i + 2] * .114 > t * 2 && (r += 1);
641
- return K(e) <= t && r / n < .01;
668
+ return U(e) <= t && r / n < .01;
642
669
  }
643
- function q(e, t, n) {
670
+ function W(e, t, n) {
644
671
  if (!t || !n) return 0;
645
672
  let r = document.createElement("canvas");
646
673
  r.width = Math.min(32, t), r.height = Math.min(32, n);
647
674
  let i = r.getContext("2d", { willReadFrequently: !0 });
648
- return i ? (i.drawImage(e, 0, 0, r.width, r.height), K(i.getImageData(0, 0, r.width, r.height).data)) : 0;
675
+ return i ? (i.drawImage(e, 0, 0, r.width, r.height), U(i.getImageData(0, 0, r.width, r.height).data)) : 0;
649
676
  }
650
- function ke(e) {
651
- return q(e, e.width, e.height);
677
+ function G(e) {
678
+ return W(e, e.width, e.height);
652
679
  }
653
- function Ae(e, t = 120) {
680
+ function je(e, t = 120) {
654
681
  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 = () => {
655
682
  a && (o = i ? e.requestVideoFrameCallback(f) : requestAnimationFrame(f));
656
683
  };
657
684
  function f() {
658
685
  if (!a) return;
659
686
  let { videoWidth: i, videoHeight: o } = e, f = performance.now();
660
- r && i && o && f - s >= t && (s = f, l = q(e, i, o), l > 10 && ((n.width !== i || n.height !== o) && (n.width = i, n.height = o), r.drawImage(e, 0, 0, i, o), u = l, c = f)), d();
687
+ 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();
661
688
  }
662
689
  return d(), {
663
690
  stop() {
@@ -669,84 +696,105 @@ function Ae(e, t = 120) {
669
696
  getMirrorAgeMs: () => c ? performance.now() - c : Infinity
670
697
  };
671
698
  }
672
- function je(e) {
699
+ function Me(e) {
673
700
  let t = document.createElement("canvas");
674
701
  return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
675
702
  }
676
- function J(e = {}, t = H()) {
677
- let n = U(t), r = e.idealWidth ?? (n ? 1080 : 3840), i = e.idealHeight ?? (n ? 1920 : 2160), a = { ideal: r }, o = { ideal: i };
678
- return e.maxWidth && (a.max = e.maxWidth), e.maxHeight ? o.max = e.maxHeight : n && e.maxWidth === void 0 && (o.max = Te), {
679
- audio: !1,
680
- video: {
681
- facingMode: { ideal: e.facingMode ?? "environment" },
682
- width: a,
683
- height: o,
684
- frameRate: {
685
- ideal: e.maxFrameRate ?? 30,
686
- max: e.maxFrameRate ?? 30
687
- }
703
+ function Ne(e) {
704
+ return e.engine === "blink";
705
+ }
706
+ function K(e = {}, t = B()) {
707
+ let n = { ideal: e.idealWidth ?? 3840 }, r = { ideal: e.idealHeight ?? 2160 };
708
+ e.maxWidth && (n.max = e.maxWidth), e.maxHeight && (r.max = e.maxHeight);
709
+ let i = {
710
+ facingMode: { ideal: e.facingMode ?? "environment" },
711
+ width: n,
712
+ height: r,
713
+ frameRate: {
714
+ ideal: e.maxFrameRate ?? 30,
715
+ max: e.maxFrameRate ?? 30
688
716
  }
689
717
  };
718
+ return Ne(t) && (i.resizeMode = { ideal: "none" }), {
719
+ audio: !1,
720
+ video: i
721
+ };
690
722
  }
691
- function Me(e, t, n) {
723
+ function q(e, t, n) {
692
724
  let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
693
725
  return {
694
726
  width: Math.max(1, Math.round(e * r)),
695
727
  height: Math.max(1, Math.round(t * r))
696
728
  };
697
729
  }
730
+ var J = 4096;
731
+ function Pe(e, t) {
732
+ let n = e.width, r = e.height, i = t?.width?.max, a = t?.height?.max;
733
+ if (!n || !r || !i || !a) return;
734
+ let o = Math.min(i / n, a / r);
735
+ if (!(o <= 1.05)) return {
736
+ width: { ideal: Math.round(n * o) },
737
+ height: { ideal: Math.round(r * o) }
738
+ };
739
+ }
740
+ async function Fe(e) {
741
+ let t = Pe(e.getSettings(), typeof e.getCapabilities == "function" ? e.getCapabilities() : void 0);
742
+ if (t) try {
743
+ await e.applyConstraints(t);
744
+ } catch {}
745
+ }
746
+ async function Ie(e) {
747
+ let n = globalThis.ImageCapture;
748
+ if (!n) return;
749
+ let r = new n(e), i;
750
+ try {
751
+ let e = r.getPhotoCapabilities ? De(await r.getPhotoCapabilities()) : void 0;
752
+ i = await r.takePhoto(e);
753
+ } catch {
754
+ i = await r.takePhoto();
755
+ }
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
+ }
698
762
  function Y(e, n) {
699
763
  if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
700
- let r = Me(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
764
+ let r = q(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
701
765
  i.width = r.width, i.height = r.height;
702
766
  let a = i.getContext("2d");
703
767
  if (!a) throw t();
704
768
  return a.drawImage(e, 0, 0, i.width, i.height), i;
705
769
  }
706
- function Ne(e) {
707
- let t = H();
708
- return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [J(e, t)] : U(t) ? [
709
- J({
710
- ...e,
711
- idealWidth: Ce,
712
- idealHeight: we
713
- }, t),
714
- J({
715
- ...e,
716
- idealWidth: 720,
717
- idealHeight: 1280
718
- }, t),
719
- J({
720
- ...e,
721
- idealWidth: 1920,
722
- idealHeight: 1080
723
- }, t)
724
- ] : [
725
- J({
770
+ function Le(e) {
771
+ let t = B();
772
+ return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [K(e, t)] : [
773
+ K({
726
774
  ...e,
727
775
  idealWidth: 3840,
728
776
  idealHeight: 2160
729
777
  }, t),
730
- J({
778
+ K({
731
779
  ...e,
732
780
  idealWidth: 2560,
733
781
  idealHeight: 1440
734
782
  }, t),
735
- J({
783
+ K({
736
784
  ...e,
737
785
  idealWidth: 1920,
738
786
  idealHeight: 1080
739
787
  }, t)
740
788
  ];
741
789
  }
742
- async function Pe(t, n = {}) {
790
+ async function Re(t, n = {}) {
743
791
  await x("scan");
744
792
  let r = n.torch ?? "alwaysOff";
745
793
  if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
746
794
  if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
747
795
  t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
748
796
  let i, a;
749
- for (let e of Ne(n)) try {
797
+ for (let e of Le(n)) try {
750
798
  i = await navigator.mediaDevices.getUserMedia(e);
751
799
  break;
752
800
  } catch (e) {
@@ -759,7 +807,8 @@ async function Pe(t, n = {}) {
759
807
  for (let e of i.getTracks()) e.stop();
760
808
  throw Error("The camera did not provide a video track.");
761
809
  }
762
- let s = Ae(t), c = "ImageCapture" in globalThis, l = G(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
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) => {
763
812
  if (!l.supported || o.readyState !== "live") return !1;
764
813
  try {
765
814
  return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
@@ -777,7 +826,7 @@ async function Pe(t, n = {}) {
777
826
  }
778
827
  };
779
828
  l.on && await d(!0);
780
- let f = r === "auto" && l.supported ? new W() : void 0, p = f ? window.setInterval(() => {
829
+ let f = r === "auto" && l.supported ? new V() : void 0, p = f ? window.setInterval(() => {
781
830
  if (u || !l.supported) return;
782
831
  let e = f.update(s.getLiveLuminance());
783
832
  e !== void 0 && e !== l.on && (u = !0, d(e).finally(() => {
@@ -803,7 +852,7 @@ async function Pe(t, n = {}) {
803
852
  torchSupported: l.supported,
804
853
  torchOn: l.on,
805
854
  torch: { ...l },
806
- engine: H()
855
+ engine: B()
807
856
  };
808
857
  };
809
858
  return {
@@ -821,18 +870,46 @@ async function Pe(t, n = {}) {
821
870
  async capturePhoto() {
822
871
  let e, n = 0;
823
872
  try {
824
- e = Y(t), n = ke(e);
873
+ e = Y(t), n = G(e);
825
874
  } catch {
826
875
  e = void 0;
827
876
  }
828
- let r = s.getFrame(), i = e && n > 10 ? e : void 0, a = i ?? (r ? je(r) : void 0);
829
- if (!a) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
830
- return {
831
- frame: a,
832
- method: i ? "video-frame" : "live-mirror",
877
+ let r = s.getFrame(), i, a = !1;
878
+ if (Ee(B(), c)) try {
879
+ i = await Ie(o);
880
+ } catch {
881
+ a = !0, i = void 0;
882
+ }
883
+ let l = i ? G(i) : 0;
884
+ if (i && l > 10) return console.info("[exige-scanner] capture", {
885
+ method: "image-capture",
886
+ frame: `${i.width}×${i.height}`,
887
+ video: `${t.videoWidth}×${t.videoHeight}`,
888
+ aspectMatch: Oe(i, {
889
+ width: t.videoWidth,
890
+ height: t.videoHeight
891
+ })
892
+ }), {
893
+ frame: i,
894
+ method: "image-capture",
895
+ settings: o.getSettings(),
896
+ luminance: l,
897
+ diagnostics: m()
898
+ };
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";
902
+ return console.info("[exige-scanner] capture", {
903
+ method: u ? "video-frame" : "live-mirror",
904
+ frame: `${d.width}×${d.height}`,
905
+ video: `${t.videoWidth}×${t.videoHeight}`,
906
+ fallbackReason: f
907
+ }), {
908
+ frame: d,
909
+ method: u ? "video-frame" : "live-mirror",
833
910
  settings: o.getSettings(),
834
- fallbackReason: i ? void 0 : "video-frame-empty",
835
- luminance: i ? n : s.getMirrorLuminance(),
911
+ fallbackReason: f,
912
+ luminance: u ? n : s.getMirrorLuminance(),
836
913
  diagnostics: m()
837
914
  };
838
915
  },
@@ -850,59 +927,13 @@ async function Pe(t, n = {}) {
850
927
  };
851
928
  }
852
929
  //#endregion
853
- //#region src/sdk/preview-frame.ts
854
- function Fe(e) {
855
- let t = e.parentElement?.getBoundingClientRect();
856
- return t && t.width > 0 && t.height > 0 ? t : e.getBoundingClientRect();
857
- }
858
- function Ie(e, t, n, r) {
859
- let i = Math.max(1, e), a = Math.max(1, t);
860
- if (n <= 0 || r <= 0) return {
861
- sx: 0,
862
- sy: 0,
863
- sw: i,
864
- sh: a
865
- };
866
- let o = i / a, s = n / r;
867
- if (o > s) {
868
- let e = a * s;
869
- return {
870
- sx: (i - e) / 2,
871
- sy: 0,
872
- sw: e,
873
- sh: a
874
- };
875
- }
876
- let c = i / s;
877
- return {
878
- sx: 0,
879
- sy: (a - c) / 2,
880
- sw: i,
881
- sh: c
882
- };
883
- }
884
- function Le(e, t, n, r, i) {
885
- let a = Ie(e, t, n, r);
886
- return {
887
- crop: a,
888
- size: Me(a.sw, a.sh, i)
889
- };
890
- }
891
- function Re(e, n, r, i, a, o) {
892
- let { crop: s, size: c } = Le(n, r, i, a, o), l = document.createElement("canvas");
893
- l.width = c.width, l.height = c.height;
894
- let u = l.getContext("2d");
895
- if (!u) throw t();
896
- return u.drawImage(e, s.sx, s.sy, s.sw, s.sh, 0, 0, c.width, c.height), l;
897
- }
898
- //#endregion
899
930
  //#region src/sdk/lighting.ts
900
931
  function ze(e, t) {
901
932
  if (!e.length) return 0;
902
933
  let n = [...e].sort((e, t) => e - t);
903
934
  return n[Math.min(n.length - 1, Math.floor(n.length * t))];
904
935
  }
905
- function Be(e, t, n, r = 12) {
936
+ function X(e, t, n, r = 12) {
906
937
  if (!t || !n || e.length < t * n) return {
907
938
  strong: !1,
908
939
  strength: 0,
@@ -973,23 +1004,38 @@ function Be(e, t, n, r = 12) {
973
1004
  }
974
1005
  return d;
975
1006
  }
976
- function Ve(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
977
- let i = t + 1, a = new Uint32Array((t + 1) * (n + 1));
978
- for (let r = 1; r <= n; r += 1) {
1007
+ function Be(e, t, n, r, i, a, o) {
1008
+ 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
+ return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
1010
+ }
1011
+ function Ve(e, t, n) {
1012
+ let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
1013
+ for (let a = 1; a <= n; a += 1) {
979
1014
  let n = 0;
980
- for (let o = 1; o <= t; o += 1) n += e[(r - 1) * t + o - 1], a[r * i + o] = a[(r - 1) * i + o] + n;
1015
+ for (let o = 1; o <= t; o += 1) n += e[(a - 1) * t + o - 1], i[a * r + o] = i[(a - 1) * r + o] + n;
981
1016
  }
982
- let o = new Uint8Array(e.length);
983
- for (let s = 0; s < n; s += 1) {
984
- let c = Math.max(0, s - r), l = Math.min(n, s + r + 1);
985
- for (let n = 0; n < t; n += 1) {
986
- let u = Math.max(0, n - r), d = Math.min(t, n + r + 1), f = (d - u) * (l - c), p = (a[l * i + d] - a[c * i + d] - a[l * i + u] + a[c * i + u]) / f;
987
- o[s * t + n] = Math.max(0, Math.min(255, Math.round(e[s * t + n] * 235 / Math.max(24, p))));
988
- }
1017
+ return {
1018
+ integral: i,
1019
+ stride: r
1020
+ };
1021
+ }
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);
1024
+ 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);
1026
+ o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
989
1027
  }
990
1028
  return o;
991
1029
  }
992
- function He(e, t, n) {
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;
1032
+ 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);
1034
+ s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
1035
+ }
1036
+ return s;
1037
+ }
1038
+ function We(e, t, n) {
993
1039
  let r = [
994
1040
  e.topLeft,
995
1041
  e.topRight,
@@ -1003,8 +1049,8 @@ function He(e, t, n) {
1003
1049
  height: s - a
1004
1050
  };
1005
1051
  }
1006
- function Ue(e, t) {
1007
- let n = He(t, e.width, e.height);
1052
+ function Ge(e, t) {
1053
+ let n = We(t, e.width, e.height);
1008
1054
  if (n.width <= 0 || n.height <= 0) return {
1009
1055
  strong: !1,
1010
1056
  strength: 0,
@@ -1023,18 +1069,18 @@ function Ue(e, t) {
1023
1069
  i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
1024
1070
  let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
1025
1071
  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);
1026
- return Be(o, r.width, r.height);
1072
+ return X(o, r.width, r.height);
1027
1073
  }
1028
1074
  //#endregion
1029
1075
  //#region src/sdk/finder.ts
1030
- function We(e, t) {
1076
+ function Ke(e, t) {
1031
1077
  return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
1032
1078
  }
1033
- async function Ge(e, t) {
1079
+ async function qe(e, t) {
1034
1080
  let n = await e();
1035
1081
  return t(), n;
1036
1082
  }
1037
- function Ke(e) {
1083
+ function Je(e) {
1038
1084
  return e === "alwaysOn" || e === "only" ? {
1039
1085
  visible: !1,
1040
1086
  checked: !0,
@@ -1049,7 +1095,7 @@ function Ke(e) {
1049
1095
  mutable: !0
1050
1096
  };
1051
1097
  }
1052
- function X(e) {
1098
+ function Z(e) {
1053
1099
  return [
1054
1100
  e.topLeft,
1055
1101
  e.topRight,
@@ -1057,11 +1103,30 @@ function X(e) {
1057
1103
  e.bottomLeft
1058
1104
  ];
1059
1105
  }
1060
- var qe = 1600;
1061
- function Je(e = H()) {
1062
- return U(e) ? Ee : qe;
1106
+ function Ye(e, t) {
1107
+ let n = e.status === "success" && e.modelStatus !== "failed", r = {
1108
+ status: e.status,
1109
+ confidence: Number(e.confidence.toFixed(3)),
1110
+ source: `${e.sourceWidth}×${e.sourceHeight}`
1111
+ };
1112
+ t?.width && t?.height && (r.video = `${t.width}×${t.height}`), e.modelStatus && (r.modelStatus = e.modelStatus), e.modelProvider && (r.provider = e.modelProvider), e.modelError && (r.modelError = e.modelError), e.modelNote && (r.modelNote = e.modelNote), e.inferenceMs !== void 0 && (r.inferenceMs = Math.round(e.inferenceMs)), !n && e.message && (r.message = e.message);
1113
+ let i = n ? "document found" : e.modelStatus === "failed" ? "document not found (ML failed)" : `document not found (${e.status})`;
1114
+ return {
1115
+ level: n ? "info" : "warn",
1116
+ key: [
1117
+ i,
1118
+ r.modelStatus ?? "",
1119
+ r.modelError ?? "",
1120
+ r.provider ?? "",
1121
+ r.modelNote ?? "",
1122
+ r.source,
1123
+ r.video ?? ""
1124
+ ].join("|"),
1125
+ summary: i,
1126
+ detail: r
1127
+ };
1063
1128
  }
1064
- function Ye(e) {
1129
+ function Xe(e) {
1065
1130
  let t = 0;
1066
1131
  for (let n = 0; n < e.length; n += 1) {
1067
1132
  let r = e[n], i = e[(n + 1) % e.length];
@@ -1069,42 +1134,42 @@ function Ye(e) {
1069
1134
  }
1070
1135
  return Math.abs(t) / 2;
1071
1136
  }
1072
- function Z(e, t) {
1137
+ function Q(e, t) {
1073
1138
  return Math.hypot(e.x - t.x, e.y - t.y);
1074
1139
  }
1075
- var Q = {
1140
+ var $ = {
1076
1141
  widthFill: 0,
1077
1142
  heightFill: 0,
1078
1143
  limitingFill: 0,
1079
1144
  areaFill: 0,
1080
1145
  aspectRatio: 1
1081
1146
  };
1082
- function Xe(e, t, n) {
1083
- 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));
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));
1084
1149
  return {
1085
1150
  widthFill: o,
1086
1151
  heightFill: s,
1087
1152
  limitingFill: Math.max(o, s),
1088
- areaFill: Ye(r) / Math.max(1, t * n),
1153
+ areaFill: Xe(r) / Math.max(1, t * n),
1089
1154
  aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
1090
1155
  };
1091
1156
  }
1092
- function Ze(e, t, n, r = {}) {
1157
+ function Qe(e, t, n, r = {}) {
1093
1158
  let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
1094
1159
  if (e.aspectRatio < a) return i;
1095
1160
  let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
1096
1161
  return Math.min(o ?? i + .08, 1 - n * 2);
1097
1162
  }
1098
- function Qe(e, t, n = {}) {
1163
+ function $e(e, t, n = {}) {
1099
1164
  let r = n.confidenceThreshold ?? .72;
1100
1165
  if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
1101
1166
  hint: "Place the document in the frame",
1102
1167
  reason: "place-document",
1103
1168
  fillRatio: 0,
1104
- fill: Q,
1169
+ fill: $,
1105
1170
  readyForAutoCapture: !1
1106
1171
  };
1107
- let i = X(e.quad), a = Xe(e.quad, e.sourceWidth, e.sourceHeight), o = a.limitingFill, s = t.previouslyReady ? n.exitEdgeMarginRatio ?? .005 : n.edgeMarginRatio ?? .015, c = e.sourceWidth * s, l = e.sourceHeight * s;
1172
+ 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;
1108
1173
  if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
1109
1174
  hint: "Move farther away",
1110
1175
  reason: "move-farther-away",
@@ -1112,14 +1177,14 @@ function Qe(e, t, n = {}) {
1112
1177
  fill: a,
1113
1178
  readyForAutoCapture: !1
1114
1179
  };
1115
- let [u, d, f, p] = i, m = Z(u, d), h = Z(d, f), g = Z(f, p), _ = Z(p, u);
1180
+ let [u, d, f, p] = i, m = Q(u, d), h = Q(d, f), g = Q(f, p), _ = Q(p, u);
1116
1181
  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) ? {
1117
1182
  hint: "Hold the camera straight",
1118
1183
  reason: "straighten-camera",
1119
1184
  fillRatio: o,
1120
1185
  fill: a,
1121
1186
  readyForAutoCapture: !1
1122
- } : o < Ze(a, t.previouslyReady === !0, s, n) ? {
1187
+ } : o < Qe(a, t.previouslyReady === !0, s, n) ? {
1123
1188
  hint: "Move closer",
1124
1189
  reason: "move-closer",
1125
1190
  fillRatio: o,
@@ -1133,7 +1198,7 @@ function Qe(e, t, n = {}) {
1133
1198
  readyForAutoCapture: t.ready
1134
1199
  };
1135
1200
  }
1136
- var $ = class {
1201
+ var et = class {
1137
1202
  previous;
1138
1203
  count = 0;
1139
1204
  ready = !1;
@@ -1150,8 +1215,8 @@ var $ = class {
1150
1215
  ready: !1,
1151
1216
  movement: Infinity
1152
1217
  };
1153
- let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...X(e.quad).map((e, n) => {
1154
- let r = X(this.previous)[n];
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];
1155
1220
  return Math.hypot(e.x - r.x, e.y - r.y) / Math.max(1, t);
1156
1221
  })) : Infinity, r = this.options.exitCornerTolerance ?? Math.max(this.options.cornerTolerance, .036);
1157
1222
  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, {
@@ -1161,13 +1226,14 @@ var $ = class {
1161
1226
  };
1162
1227
  }
1163
1228
  };
1164
- function $e(e, t) {
1165
- let n = e instanceof HTMLVideoElement ? e.videoWidth : e.width, r = e instanceof HTMLVideoElement ? e.videoHeight : e.height;
1166
- if (!n || !r) throw Error("The camera is not ready to capture a frame.");
1167
- let i = Fe(e);
1168
- return Re(e, n, r, i.width, i.height, t);
1229
+ function tt(e, n) {
1230
+ let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
1231
+ i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
1232
+ let a = i.getContext("2d");
1233
+ if (!a) throw t();
1234
+ return a.drawImage(e, 0, 0, i.width, i.height), i;
1169
1235
  }
1170
- function et() {
1236
+ function nt() {
1171
1237
  let e = window.AudioContext ?? window.webkitAudioContext;
1172
1238
  if (!e) return;
1173
1239
  let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
@@ -1178,29 +1244,29 @@ function et() {
1178
1244
  let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
1179
1245
  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();
1180
1246
  }
1181
- async function tt(e) {
1247
+ async function rt(e) {
1182
1248
  let t = document.createElement("video");
1183
1249
  return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
1184
1250
  }
1185
- async function nt(t) {
1251
+ async function it(t) {
1186
1252
  await x("scan");
1187
- let n = Ke(t.autoCapture), r = new $({
1253
+ let n = Je(t.autoCapture), r = new et({
1188
1254
  stableFrames: t.stableFrames ?? 4,
1189
1255
  confidenceThreshold: t.confidenceThreshold ?? .72,
1190
1256
  cornerTolerance: t.cornerTolerance ?? .024,
1191
1257
  exitCornerTolerance: t.exitCornerTolerance ?? .036
1192
- }), i = t.maxFrameDimension ?? Je(), a = t.intervalMs ?? 140, o = {
1258
+ }), i = t.maxFrameDimension ?? 1600, a = t.intervalMs ?? 140, o = {
1193
1259
  minDimension: 220,
1194
- maxAnalysisDimension: i,
1260
+ maxAnalysisDimension: 520,
1195
1261
  ...t.detection
1196
- }, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await tt(t.source) : t.source, c = !0, l = !1, u = !1, d = 0, f, p = {
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 = {
1197
1263
  state: "detecting",
1198
1264
  confidence: 0,
1199
1265
  guidance: {
1200
1266
  hint: "Place the document in the frame",
1201
1267
  reason: "place-document",
1202
1268
  fillRatio: 0,
1203
- fill: Q,
1269
+ fill: $,
1204
1270
  readyForAutoCapture: !1
1205
1271
  },
1206
1272
  lighting: {
@@ -1210,20 +1276,29 @@ async function nt(t) {
1210
1276
  stableFrames: 0,
1211
1277
  requiredStableFrames: t.stableFrames ?? 4,
1212
1278
  autoCapture: { ...n }
1213
- }, m = () => $e(s, i), h = (e) => {
1214
- p = e, t.onStatus?.(e);
1215
- }, g = () => {
1279
+ }, g = () => s instanceof HTMLCanvasElement ? tt(s, i) : Y(s, i), _ = (e) => {
1280
+ h = e, t.onStatus?.(e);
1281
+ }, v = (e) => {
1282
+ let t = Ye(e, s instanceof HTMLVideoElement ? {
1283
+ width: s.videoWidth,
1284
+ height: s.videoHeight
1285
+ } : {
1286
+ width: s.width,
1287
+ height: s.height
1288
+ }), n = performance.now();
1289
+ t.key === p && n - m < 2e3 || (p = t.key, m = n, console[t.level](`[exige-scanner] ${t.summary}`, t.detail));
1290
+ }, y = () => {
1216
1291
  c = !1, window.clearTimeout(d), s instanceof HTMLVideoElement && s !== t.source && (s.srcObject = null);
1217
- }, _ = async (e = "manual") => {
1292
+ }, b = async (e = "manual") => {
1218
1293
  if (l) throw Error("A finder capture is already in progress.");
1219
1294
  l = !0;
1220
1295
  let n;
1221
1296
  try {
1222
- n = await Ge(t.captureFrame ?? m, () => {
1223
- h({
1224
- ...p,
1297
+ n = await qe(t.captureFrame ?? g, () => {
1298
+ _({
1299
+ ...h,
1225
1300
  state: "captured"
1226
- }), t.playShutterSound !== !1 && et(), g();
1301
+ }), t.playShutterSound !== !1 && nt(), y();
1227
1302
  });
1228
1303
  } catch (e) {
1229
1304
  throw l = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
@@ -1234,12 +1309,12 @@ async function nt(t) {
1234
1309
  reason: e
1235
1310
  };
1236
1311
  return await t.onCapture?.(r), r;
1237
- }, v = async () => {
1312
+ }, S = async () => {
1238
1313
  if (c && !l) {
1239
1314
  try {
1240
- let e = m(), i = await B(e, o);
1241
- f = i;
1242
- let a = i.quad ? Ue(e, i.quad) : {
1315
+ let e = g(), i = await Se(e, o);
1316
+ f = i, v(i);
1317
+ let a = i.quad ? Ge(e, i.quad) : {
1243
1318
  strong: !1,
1244
1319
  strength: 0
1245
1320
  }, s = a.strong ? {
@@ -1249,7 +1324,7 @@ async function nt(t) {
1249
1324
  } : {
1250
1325
  castShadow: !1,
1251
1326
  strength: a.strength
1252
- }, c = r.update(i), l = Qe(i, {
1327
+ }, c = r.update(i), l = $e(i, {
1253
1328
  ...c,
1254
1329
  previouslyReady: u
1255
1330
  }, {
@@ -1258,14 +1333,14 @@ async function nt(t) {
1258
1333
  });
1259
1334
  u = l.readyForAutoCapture;
1260
1335
  let d = i.status !== "success" || l.reason === "place-document" ? "seeking" : l.readyForAutoCapture ? "ready" : "unstable";
1261
- if (h({
1336
+ if (_({
1262
1337
  state: d,
1263
1338
  confidence: i.confidence,
1264
1339
  quad: i.quad,
1265
1340
  guidance: l,
1266
1341
  lighting: s,
1267
1342
  stableFrames: c.stableFrames,
1268
- requiredStableFrames: p.requiredStableFrames,
1343
+ requiredStableFrames: h.requiredStableFrames,
1269
1344
  autoCapture: { ...n },
1270
1345
  sourceWidth: i.sourceWidth,
1271
1346
  sourceHeight: i.sourceHeight,
@@ -1273,9 +1348,10 @@ async function nt(t) {
1273
1348
  modelStatus: i.modelStatus,
1274
1349
  modelProvider: i.modelProvider,
1275
1350
  modelError: i.modelError,
1351
+ modelNote: i.modelNote,
1276
1352
  inferenceMs: i.inferenceMs
1277
1353
  }), l.readyForAutoCapture && n.checked) try {
1278
- await _("auto");
1354
+ await b("auto");
1279
1355
  return;
1280
1356
  } catch (e) {
1281
1357
  r.reset(), u = !1, t.onCaptureError?.(e instanceof Error ? e : /* @__PURE__ */ Error("Automatic capture failed."));
@@ -1286,15 +1362,22 @@ async function nt(t) {
1286
1362
  detector: "ml",
1287
1363
  modelStatus: "failed",
1288
1364
  modelError: t.message
1289
- } : {};
1290
- h({
1365
+ } : { modelError: t instanceof Error ? t.message : "Finder tick failed." };
1366
+ v({
1367
+ status: "no-document",
1368
+ confidence: 0,
1369
+ message: i.modelError ?? "Finder tick failed.",
1370
+ sourceWidth: 0,
1371
+ sourceHeight: 0,
1372
+ ...i
1373
+ }), _({
1291
1374
  state: "seeking",
1292
1375
  confidence: 0,
1293
1376
  guidance: {
1294
1377
  hint: "Place the document in the frame",
1295
1378
  reason: "place-document",
1296
1379
  fillRatio: 0,
1297
- fill: Q,
1380
+ fill: $,
1298
1381
  readyForAutoCapture: !1
1299
1382
  },
1300
1383
  lighting: {
@@ -1302,27 +1385,27 @@ async function nt(t) {
1302
1385
  strength: 0
1303
1386
  },
1304
1387
  stableFrames: 0,
1305
- requiredStableFrames: p.requiredStableFrames,
1388
+ requiredStableFrames: h.requiredStableFrames,
1306
1389
  autoCapture: { ...n },
1307
1390
  ...i
1308
1391
  });
1309
1392
  }
1310
- c && (d = window.setTimeout(() => void v(), a));
1393
+ c && (d = window.setTimeout(() => void S(), a));
1311
1394
  }
1312
1395
  };
1313
- return t.onStatus?.(p), v(), {
1314
- stop: g,
1315
- capture: () => _("manual"),
1396
+ return t.onStatus?.(h), S(), {
1397
+ stop: y,
1398
+ capture: () => b("manual"),
1316
1399
  setAutoCapture(e) {
1317
- return !n.mutable || l ? !1 : (n.checked = e, h({
1318
- ...p,
1400
+ return !n.mutable || l ? !1 : (n.checked = e, _({
1401
+ ...h,
1319
1402
  autoCapture: { ...n }
1320
1403
  }), !0);
1321
1404
  },
1322
- getStatus: () => p
1405
+ getStatus: () => h
1323
1406
  };
1324
1407
  }
1325
1408
  //#endregion
1326
- export { a as A, M as C, j as D, de as E, e as F, t as I, x as M, b as N, ie as O, y as P, B as S, ue as T, J as _, Qe as a, fe as b, Be as c, De as d, Y as f, K as g, Oe as h, Xe as i, o as j, ne as k, Ve as l, Se as m, Ke as n, We as o, H as p, Ze as r, nt as s, $ as t, W as u, Pe as v, xe as w, be as x, G as y };
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 };
1327
1410
 
1328
- //# sourceMappingURL=finder-D0Wgl-6-.js.map
1411
+ //# sourceMappingURL=finder-CLTG1caj.js.map