@exige/web-scanner-sdk 0.2.10 → 0.2.12

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.
@@ -169,37 +169,52 @@ async function x(e) {
169
169
  }
170
170
  //#endregion
171
171
  //#region src/sdk/model-download.ts
172
- var S = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Set(), w = /* @__PURE__ */ new Map(), T = /* @__PURE__ */ new Map();
173
- function E(e) {
172
+ var S = Symbol.for("exige.web-scanner-sdk.model-downloads");
173
+ function C() {
174
+ let e = globalThis;
175
+ return e[S] || (e[S] = {
176
+ active: /* @__PURE__ */ new Map(),
177
+ listeners: /* @__PURE__ */ new Set(),
178
+ cache: /* @__PURE__ */ new Map(),
179
+ inflight: /* @__PURE__ */ new Map()
180
+ }), e[S];
181
+ }
182
+ var w = C().active, T = C().listeners, E = C().cache, D = C().inflight;
183
+ function ee(e) {
174
184
  let t = Number(e.headers.get("content-length"));
175
185
  return Number.isFinite(t) && t > 0 ? t : null;
176
186
  }
177
- function ee() {
178
- if (S.size === 0) return {
187
+ function O() {
188
+ if (w.size === 0) return {
179
189
  downloading: !1,
180
190
  loaded: 0,
181
191
  total: null
182
192
  };
183
193
  let e = 0, t = 0, n = !0;
184
- for (let r of S.values()) e += r.loaded, r.total == null ? n = !1 : t += r.total;
194
+ for (let r of w.values()) e += r.loaded, r.total == null ? n = !1 : t += r.total;
185
195
  return {
186
196
  downloading: !0,
187
197
  loaded: e,
188
198
  total: n ? t : null
189
199
  };
190
200
  }
191
- function D() {
192
- let e = ee();
193
- for (let t of C) t(e);
201
+ function k() {
202
+ let e = O();
203
+ for (let t of T) t(e);
204
+ }
205
+ function te(e) {
206
+ return e(O()), T.add(e), () => {
207
+ T.delete(e);
208
+ };
194
209
  }
195
- function O(e, t) {
196
- t.done ? S.delete(e) : S.set(e, {
210
+ function A(e, t) {
211
+ t.done ? w.delete(e) : w.set(e, {
197
212
  loaded: t.loaded,
198
213
  total: t.total
199
- }), D();
214
+ }), k();
200
215
  }
201
- async function te(e, t) {
202
- let n = E(e);
216
+ async function ne(e, t) {
217
+ let n = ee(e);
203
218
  if (!e.body) {
204
219
  let r = await e.arrayBuffer();
205
220
  return t?.({
@@ -223,53 +238,53 @@ async function te(e, t) {
223
238
  total: n
224
239
  }), o.buffer;
225
240
  }
226
- async function ne(t, n) {
227
- let r = w.get(t);
241
+ async function re(t, n) {
242
+ let r = E.get(t);
228
243
  if (r) return r.slice(0);
229
- let i = T.get(t);
244
+ let i = D.get(t);
230
245
  if (i) return i.then((e) => e.slice(0));
231
246
  let a = (async () => {
232
- O(t, {
247
+ A(t, {
233
248
  loaded: 0,
234
249
  total: null
235
250
  });
236
251
  let r = await fetch(t, { cache: n?.cache });
237
252
  if (!r.ok) throw new e("model-http", `Model request failed with HTTP ${r.status}.`);
238
- return te(r, (e) => O(t, e));
253
+ return ne(r, (e) => A(t, e));
239
254
  })();
240
- T.set(t, a);
255
+ D.set(t, a);
241
256
  try {
242
257
  let e = await a;
243
- return w.set(t, e), e.slice(0);
258
+ return E.set(t, e), e.slice(0);
244
259
  } finally {
245
- T.delete(t), S.has(t) && (S.delete(t), D());
260
+ D.delete(t), w.has(t) && (w.delete(t), k());
246
261
  }
247
262
  }
248
263
  //#endregion
249
264
  //#region src/sdk/ort-runtime.ts
250
- var re = new URL("./assets/ort-wasm-simd-threaded.jsep.wasm", import.meta.url), ie = new URL("./assets/ort-wasm-simd-threaded.jsep.mjs", import.meta.url);
251
- function k() {
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() {
252
267
  return {
253
- wasm: re.href,
254
- mjs: ie.href
268
+ wasm: ie.href,
269
+ mjs: ae.href
255
270
  };
256
271
  }
257
- function ae(e) {
258
- return typeof e == "string" ? e.trim() || k() : e?.wasm.trim() && e.mjs.trim() ? {
272
+ function se(e) {
273
+ return typeof e == "string" ? e.trim() || oe() : e?.wasm.trim() && e.mjs.trim() ? {
259
274
  wasm: e.wasm.trim(),
260
275
  mjs: e.mjs.trim()
261
- } : k();
276
+ } : oe();
262
277
  }
263
278
  //#endregion
264
279
  //#region src/sdk/image.ts
265
- function oe(e, t, n) {
280
+ function ce(e, t, n) {
266
281
  let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
267
282
  return {
268
283
  width: Math.max(1, Math.round(e * r)),
269
284
  height: Math.max(1, Math.round(t * r))
270
285
  };
271
286
  }
272
- async function se(e) {
287
+ async function le(e) {
273
288
  let t = URL.createObjectURL(e);
274
289
  try {
275
290
  let e = new Image();
@@ -278,26 +293,26 @@ async function se(e) {
278
293
  URL.revokeObjectURL(t);
279
294
  }
280
295
  }
281
- async function A(e, n = {}) {
296
+ async function j(e, n = {}) {
282
297
  if (e instanceof HTMLCanvasElement && n.cloneCanvas === !1 && !n.maxDimension) return e;
283
298
  let r = document.createElement("canvas"), i = r.getContext("2d", { willReadFrequently: !0 });
284
299
  if (!i) throw t();
285
300
  if (e instanceof Blob) {
286
301
  if ("createImageBitmap" in window) try {
287
- let t = await createImageBitmap(e), a = oe(t.width, t.height, n.maxDimension);
302
+ let t = await createImageBitmap(e), a = ce(t.width, t.height, n.maxDimension);
288
303
  return r.width = a.width, r.height = a.height, i.drawImage(t, 0, 0, a.width, a.height), t.close(), r;
289
304
  } catch {}
290
- e = await se(e);
305
+ e = await le(e);
291
306
  }
292
307
  let a = e instanceof HTMLImageElement ? e.naturalWidth : e.width, o = e instanceof HTMLImageElement ? e.naturalHeight : e.height;
293
308
  if (!a || !o) throw Error("The image has no readable dimensions.");
294
- let s = oe(a, o, n.maxDimension);
309
+ let s = ce(a, o, n.maxDimension);
295
310
  return r.width = s.width, r.height = s.height, i.drawImage(e, 0, 0, s.width, s.height), r;
296
311
  }
297
- function ce(e, t = "image/png", n = .92) {
312
+ function ue(e, t = "image/png", n = .92) {
298
313
  return new Promise((r, i) => e.toBlob((e) => e ? r(e) : i(/* @__PURE__ */ Error("Could not encode the image.")), t, n));
299
314
  }
300
- function le(e, t, n) {
315
+ function de(e, t, n) {
301
316
  let r = Math.max(0, Math.min(t, e.x)), i = Math.max(0, Math.min(n, e.y));
302
317
  return {
303
318
  x: r,
@@ -308,15 +323,15 @@ function le(e, t, n) {
308
323
  }
309
324
  //#endregion
310
325
  //#region src/sdk/scan.ts
311
- var ue = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
312
- function j(e) {
326
+ var fe = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
327
+ function M(e) {
313
328
  return e?.trim() || "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
314
329
  }
315
- var de = 3, M, fe = 0, N = /* @__PURE__ */ new Map();
316
- function P(e, t) {
330
+ var pe = 3, N, me = 0, P = /* @__PURE__ */ new Map();
331
+ function F(e, t) {
317
332
  return Math.hypot(e.x - t.x, e.y - t.y);
318
333
  }
319
- function F(e) {
334
+ function I(e) {
320
335
  return {
321
336
  ...e,
322
337
  edges: {
@@ -339,7 +354,7 @@ function F(e) {
339
354
  }
340
355
  };
341
356
  }
342
- function pe(e, t) {
357
+ function he(e, t) {
343
358
  let n = (e) => ({
344
359
  x: e.x / t,
345
360
  y: e.y / t
@@ -351,42 +366,42 @@ function pe(e, t) {
351
366
  bottomLeft: n(e.bottomLeft)
352
367
  };
353
368
  }
354
- function I() {
369
+ function L() {
355
370
  return typeof navigator > "u" ? !1 : navigator.maxTouchPoints > 0 || navigator.hardwareConcurrency <= 4 || typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
356
371
  }
357
- function me(t, n, r, i) {
372
+ function ge(t, n, r, i) {
358
373
  return new Promise((a, o) => {
359
- M || (M = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), M.onmessage = (t) => {
374
+ N || (N = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), N.onmessage = (t) => {
360
375
  if (t.data.download?.url) {
361
- O(t.data.download.url, t.data.download);
376
+ A(t.data.download.url, t.data.download);
362
377
  return;
363
378
  }
364
- let n = N.get(t.data.id);
365
- 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.")));
366
- }, M.onerror = () => {
379
+ let n = P.get(t.data.id);
380
+ 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.")));
381
+ }, N.onerror = () => {
367
382
  let t = new e("worker", "The document worker could not start.");
368
- for (let e of N.values()) e.reject(t);
369
- N.clear(), M?.terminate(), M = void 0;
383
+ for (let e of P.values()) e.reject(t);
384
+ P.clear(), N?.terminate(), N = void 0;
370
385
  });
371
- let s = ++fe;
372
- N.set(s, {
386
+ let s = ++me;
387
+ P.set(s, {
373
388
  resolve: a,
374
389
  reject: o
375
390
  });
376
391
  let c = t.slice().buffer;
377
- M.postMessage({
392
+ N.postMessage({
378
393
  id: s,
379
394
  pixels: c,
380
395
  width: n,
381
396
  height: r,
382
- modelUrl: j(i.modelUrl),
397
+ modelUrl: M(i.modelUrl),
383
398
  heatmapThreshold: i.heatmapThreshold,
384
399
  cacheModel: i.cacheModel,
385
- ortWasmPaths: ae(i.ortWasmPaths)
400
+ ortWasmPaths: se(i.ortWasmPaths)
386
401
  }, [c]);
387
402
  });
388
403
  }
389
- async function L(n, r) {
404
+ async function R(n, r) {
390
405
  let { width: i, height: a } = n, o = r.minDimension ?? 360;
391
406
  if (Math.min(i, a) < o) return {
392
407
  status: "low-quality",
@@ -395,14 +410,14 @@ async function L(n, r) {
395
410
  sourceWidth: i,
396
411
  sourceHeight: a
397
412
  };
398
- let s = I() ? 560 : 900, c = Math.min(1, (r.maxAnalysisDimension ?? s) / Math.max(i, a)), l = document.createElement("canvas");
413
+ let s = L() ? 560 : 900, c = Math.min(1, (r.maxAnalysisDimension ?? s) / Math.max(i, a)), l = document.createElement("canvas");
399
414
  l.width = Math.max(1, Math.round(i * c)), l.height = Math.max(1, Math.round(a * c));
400
415
  let u = l.getContext("2d", { willReadFrequently: !0 });
401
416
  if (!u) throw t();
402
417
  u.drawImage(n, 0, 0, l.width, l.height);
403
418
  let d = u.getImageData(0, 0, l.width, l.height).data, f;
404
419
  if (r.useWorker !== !1 && typeof Worker < "u") try {
405
- f = await me(d, l.width, l.height, r);
420
+ f = await ge(d, l.width, l.height, r);
406
421
  } catch (t) {
407
422
  if (t instanceof e && (t.code === "worker" || t.code === "model-http")) throw t;
408
423
  f = {
@@ -425,7 +440,7 @@ async function L(n, r) {
425
440
  modelError: v,
426
441
  inferenceMs: y
427
442
  };
428
- if (p < de) return {
443
+ if (p < pe) return {
429
444
  status: "low-quality",
430
445
  confidence: Math.min(.3, p / 18),
431
446
  message: "The image is too soft or dark to resolve four document edges.",
@@ -441,7 +456,7 @@ async function L(n, r) {
441
456
  sourceHeight: a,
442
457
  ...b
443
458
  };
444
- let x = pe(m.corners, c), S = F(x), C = r.minConfidence ?? .58;
459
+ let x = he(m.corners, c), S = I(x), C = r.minConfidence ?? .58;
445
460
  return m.confidence < C ? {
446
461
  status: "low-confidence",
447
462
  quad: S,
@@ -462,61 +477,61 @@ async function L(n, r) {
462
477
  ...b
463
478
  };
464
479
  }
465
- function he(e, t) {
466
- 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));
480
+ function _e(e, t) {
481
+ 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));
467
482
  return {
468
483
  width: Math.max(1, Math.round(n * i)),
469
484
  height: Math.max(1, Math.round(r * i))
470
485
  };
471
486
  }
472
- function R(e, n, r) {
473
- let { width: i, height: a } = he(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
487
+ function z(e, n, r) {
488
+ let { width: i, height: a } = _e(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
474
489
  if (!o) throw t();
475
490
  let s = o.getImageData(0, 0, e.width, e.height), c = document.createElement("canvas");
476
491
  c.width = i, c.height = a;
477
492
  let l = c.getContext("2d");
478
493
  if (!l) throw t();
479
- 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, ee = m.y - d.y + C * m.y;
494
+ 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;
480
495
  for (let t = 0; t < a; t += 1) {
481
496
  let n = t / Math.max(1, a - 1);
482
497
  for (let r = 0; r < i; r += 1) {
483
- 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 + ee * n + d.y) / o))) * e.width + c) * 4, f = (t * i + r) * 4;
498
+ 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;
484
499
  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];
485
500
  }
486
501
  }
487
502
  return l.putImageData(u, 0, 0), c;
488
503
  }
489
- async function z(e, t = {}) {
490
- return await x("scan"), L(await A(e, { cloneCanvas: !1 }), t);
504
+ async function B(e, t = {}) {
505
+ return await x("scan"), R(await j(e, { cloneCanvas: !1 }), t);
491
506
  }
492
- async function ge(e, t, n = {}) {
507
+ async function ve(e, t, n = {}) {
493
508
  await x("scan");
494
- let r = await A(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? (I() ? 2048 : 4096);
509
+ let r = await j(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? (L() ? 2048 : 4096);
495
510
  return {
496
511
  status: "success",
497
512
  corners: t,
498
- quad: F(t),
513
+ quad: I(t),
499
514
  confidence: 1,
500
515
  message: "Captured with the document edges shown in the finder.",
501
516
  sourceWidth: r.width,
502
517
  sourceHeight: r.height,
503
- canvas: R(r, t, i)
518
+ canvas: z(r, t, i)
504
519
  };
505
520
  }
506
- async function _e(e, t = {}) {
521
+ async function ye(e, t = {}) {
507
522
  await x("scan");
508
- let n = await A(e, { cloneCanvas: !1 }), r = await L(n, t);
523
+ let n = await j(e, { cloneCanvas: !1 }), r = await R(n, t);
509
524
  if (r.status !== "success" || !r.corners) return r;
510
- let i = t.maxOutputDimension ?? (I() ? 2048 : 4096);
525
+ let i = t.maxOutputDimension ?? (L() ? 2048 : 4096);
511
526
  return {
512
527
  ...r,
513
- canvas: R(n, r.corners, i),
528
+ canvas: z(n, r.corners, i),
514
529
  message: "Four document edges detected and perspective-corrected."
515
530
  };
516
531
  }
517
532
  //#endregion
518
533
  //#region src/sdk/camera.ts
519
- function B(e, t) {
534
+ function V(e, t) {
520
535
  let { engine: n } = t;
521
536
  return [
522
537
  `${e}:`,
@@ -531,9 +546,9 @@ function B(e, t) {
531
546
  ` torch: ${t.torch.mode} supported=${t.torch.supported} on=${t.torch.on}`
532
547
  ].join("\n");
533
548
  }
534
- function ve(e) {
549
+ function be(e) {
535
550
  let t = ["Exige scanner capture report", `time: ${e.capturedAt ?? (/* @__PURE__ */ new Date()).toISOString()}`];
536
- 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(B("shutter", e.shutter)), e.live && t.push(B("live", e.live)), e.finder) {
551
+ 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) {
537
552
  let n = e.finder;
538
553
  t.push([
539
554
  "finder:",
@@ -546,7 +561,7 @@ function ve(e) {
546
561
  }
547
562
  return `${t.join("\n")}\n`;
548
563
  }
549
- function V(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
564
+ function H(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
550
565
  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;
551
566
  return {
552
567
  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",
@@ -555,7 +570,7 @@ function V(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof nav
555
570
  userAgent: e
556
571
  };
557
572
  }
558
- var ye = 10, H = class {
573
+ var xe = 10, U = class {
559
574
  on = !1;
560
575
  darkCount = 0;
561
576
  brightCount = 0;
@@ -578,7 +593,7 @@ var ye = 10, H = class {
578
593
  return this.on;
579
594
  }
580
595
  };
581
- function U(e, t) {
596
+ function W(e, t) {
582
597
  return t ? e === "alwaysOn" || e === "alwaysOff" ? {
583
598
  mode: e,
584
599
  supported: !0,
@@ -602,37 +617,37 @@ function U(e, t) {
602
617
  automatic: e === "auto"
603
618
  };
604
619
  }
605
- function W(e) {
620
+ function G(e) {
606
621
  let t = Math.floor(e.length / 4);
607
622
  if (!t) return 0;
608
623
  let n = 0;
609
624
  for (let r = 0; r < t * 4; r += 4) n += e[r] * .299 + e[r + 1] * .587 + e[r + 2] * .114;
610
625
  return n / t;
611
626
  }
612
- function be(e, t = 10) {
627
+ function Se(e, t = 10) {
613
628
  if (e.length < 4) return !0;
614
629
  let n = Math.floor(e.length / 4), r = 0;
615
630
  for (let i = 0; i < n * 4; i += 4) e[i] * .299 + e[i + 1] * .587 + e[i + 2] * .114 > t * 2 && (r += 1);
616
- return W(e) <= t && r / n < .01;
631
+ return G(e) <= t && r / n < .01;
617
632
  }
618
- function G(e, t, n) {
633
+ function Ce(e, t, n) {
619
634
  if (!t || !n) return 0;
620
635
  let r = document.createElement("canvas");
621
636
  r.width = Math.min(32, t), r.height = Math.min(32, n);
622
637
  let i = r.getContext("2d", { willReadFrequently: !0 });
623
- return i ? (i.drawImage(e, 0, 0, r.width, r.height), W(i.getImageData(0, 0, r.width, r.height).data)) : 0;
638
+ return i ? (i.drawImage(e, 0, 0, r.width, r.height), G(i.getImageData(0, 0, r.width, r.height).data)) : 0;
624
639
  }
625
- function xe(e) {
626
- return G(e, e.width, e.height);
640
+ function we(e) {
641
+ return Ce(e, e.width, e.height);
627
642
  }
628
- function Se(e, t = 120) {
643
+ function Te(e, t = 120) {
629
644
  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 = () => {
630
645
  a && (o = i ? e.requestVideoFrameCallback(f) : requestAnimationFrame(f));
631
646
  };
632
647
  function f() {
633
648
  if (!a) return;
634
649
  let { videoWidth: i, videoHeight: o } = e, f = performance.now();
635
- r && i && o && f - s >= t && (s = f, l = G(e, i, o), l > 10 && ((n.width !== i || n.height !== o) && (n.width = i, n.height = o), r.drawImage(e, 0, 0, i, o), u = l, c = f)), d();
650
+ r && i && o && f - s >= t && (s = f, l = Ce(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();
636
651
  }
637
652
  return d(), {
638
653
  stop() {
@@ -644,7 +659,7 @@ function Se(e, t = 120) {
644
659
  getMirrorAgeMs: () => c ? performance.now() - c : Infinity
645
660
  };
646
661
  }
647
- function Ce(e) {
662
+ function Ee(e) {
648
663
  let t = document.createElement("canvas");
649
664
  return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
650
665
  }
@@ -671,7 +686,7 @@ function q(e, n) {
671
686
  if (!a) throw t();
672
687
  return a.drawImage(e, 0, 0, i.width, i.height), i;
673
688
  }
674
- function we(e) {
689
+ function De(e) {
675
690
  return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [K(e)] : [
676
691
  K({
677
692
  ...e,
@@ -690,14 +705,14 @@ function we(e) {
690
705
  })
691
706
  ];
692
707
  }
693
- async function Te(t, n = {}) {
708
+ async function Oe(t, n = {}) {
694
709
  await x("scan");
695
710
  let r = n.torch ?? "alwaysOff";
696
711
  if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
697
712
  if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
698
713
  t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
699
714
  let i, a;
700
- for (let e of we(n)) try {
715
+ for (let e of De(n)) try {
701
716
  i = await navigator.mediaDevices.getUserMedia(e);
702
717
  break;
703
718
  } catch (e) {
@@ -710,7 +725,7 @@ async function Te(t, n = {}) {
710
725
  for (let e of i.getTracks()) e.stop();
711
726
  throw Error("The camera did not provide a video track.");
712
727
  }
713
- let s = Se(t), c = "ImageCapture" in globalThis, l = U(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
728
+ let s = Te(t), c = "ImageCapture" in globalThis, l = W(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
714
729
  if (!l.supported || o.readyState !== "live") return !1;
715
730
  try {
716
731
  return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
@@ -728,7 +743,7 @@ async function Te(t, n = {}) {
728
743
  }
729
744
  };
730
745
  l.on && await d(!0);
731
- let f = r === "auto" && l.supported ? new H() : void 0, p = f ? window.setInterval(() => {
746
+ let f = r === "auto" && l.supported ? new U() : void 0, p = f ? window.setInterval(() => {
732
747
  if (u || !l.supported) return;
733
748
  let e = f.update(s.getLiveLuminance());
734
749
  e !== void 0 && e !== l.on && (u = !0, d(e).finally(() => {
@@ -754,7 +769,7 @@ async function Te(t, n = {}) {
754
769
  torchSupported: l.supported,
755
770
  torchOn: l.on,
756
771
  torch: { ...l },
757
- engine: V()
772
+ engine: H()
758
773
  };
759
774
  };
760
775
  return {
@@ -772,11 +787,11 @@ async function Te(t, n = {}) {
772
787
  async capturePhoto() {
773
788
  let e, n = 0;
774
789
  try {
775
- e = q(t), n = xe(e);
790
+ e = q(t), n = we(e);
776
791
  } catch {
777
792
  e = void 0;
778
793
  }
779
- let r = s.getFrame(), i = e && n > 10 ? e : void 0, a = i ?? (r ? Ce(r) : void 0);
794
+ let r = s.getFrame(), i = e && n > 10 ? e : void 0, a = i ?? (r ? Ee(r) : void 0);
780
795
  if (!a) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
781
796
  return {
782
797
  frame: a,
@@ -802,7 +817,7 @@ async function Te(t, n = {}) {
802
817
  }
803
818
  //#endregion
804
819
  //#region src/sdk/lighting.ts
805
- function Ee(e, t) {
820
+ function ke(e, t) {
806
821
  if (!e.length) return 0;
807
822
  let n = [...e].sort((e, t) => e - t);
808
823
  return n[Math.min(n.length - 1, Math.floor(n.length * t))];
@@ -830,7 +845,7 @@ function J(e, t, n, r = 12) {
830
845
  });
831
846
  }
832
847
  }
833
- let s = Ee(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
848
+ let s = ke(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
834
849
  for (let e = 0; e < o.length; e += 1) {
835
850
  if (!c[e] || l[e]) continue;
836
851
  let t = [], n = [e];
@@ -878,7 +893,7 @@ function J(e, t, n, r = 12) {
878
893
  }
879
894
  return d;
880
895
  }
881
- function De(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
896
+ function Ae(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
882
897
  let i = t + 1, a = new Uint32Array((t + 1) * (n + 1));
883
898
  for (let r = 1; r <= n; r += 1) {
884
899
  let n = 0;
@@ -894,7 +909,7 @@ function De(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
894
909
  }
895
910
  return o;
896
911
  }
897
- function Oe(e, t, n) {
912
+ function je(e, t, n) {
898
913
  let r = [
899
914
  e.topLeft,
900
915
  e.topRight,
@@ -908,8 +923,8 @@ function Oe(e, t, n) {
908
923
  height: s - a
909
924
  };
910
925
  }
911
- function ke(e, t) {
912
- let n = Oe(t, e.width, e.height);
926
+ function Me(e, t) {
927
+ let n = je(t, e.width, e.height);
913
928
  if (n.width <= 0 || n.height <= 0) return {
914
929
  strong: !1,
915
930
  strength: 0,
@@ -932,14 +947,14 @@ function ke(e, t) {
932
947
  }
933
948
  //#endregion
934
949
  //#region src/sdk/finder.ts
935
- function Ae(e, t) {
950
+ function Ne(e, t) {
936
951
  return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
937
952
  }
938
- async function je(e, t) {
953
+ async function Pe(e, t) {
939
954
  let n = await e();
940
955
  return t(), n;
941
956
  }
942
- function Y(e) {
957
+ function Fe(e) {
943
958
  return e === "alwaysOn" || e === "only" ? {
944
959
  visible: !1,
945
960
  checked: !0,
@@ -954,7 +969,7 @@ function Y(e) {
954
969
  mutable: !0
955
970
  };
956
971
  }
957
- function X(e) {
972
+ function Y(e) {
958
973
  return [
959
974
  e.topLeft,
960
975
  e.topRight,
@@ -962,7 +977,7 @@ function X(e) {
962
977
  e.bottomLeft
963
978
  ];
964
979
  }
965
- function Me(e) {
980
+ function Ie(e) {
966
981
  let t = 0;
967
982
  for (let n = 0; n < e.length; n += 1) {
968
983
  let r = e[n], i = e[(n + 1) % e.length];
@@ -970,42 +985,42 @@ function Me(e) {
970
985
  }
971
986
  return Math.abs(t) / 2;
972
987
  }
973
- function Z(e, t) {
988
+ function X(e, t) {
974
989
  return Math.hypot(e.x - t.x, e.y - t.y);
975
990
  }
976
- var Q = {
991
+ var Z = {
977
992
  widthFill: 0,
978
993
  heightFill: 0,
979
994
  limitingFill: 0,
980
995
  areaFill: 0,
981
996
  aspectRatio: 1
982
997
  };
983
- function Ne(e, t, n) {
984
- 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));
998
+ function Le(e, t, n) {
999
+ let r = Y(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(X(c, l), X(d, u)), p = Math.max(X(c, d), X(l, u));
985
1000
  return {
986
1001
  widthFill: o,
987
1002
  heightFill: s,
988
1003
  limitingFill: Math.max(o, s),
989
- areaFill: Me(r) / Math.max(1, t * n),
1004
+ areaFill: Ie(r) / Math.max(1, t * n),
990
1005
  aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
991
1006
  };
992
1007
  }
993
- function Pe(e, t, n, r = {}) {
1008
+ function Re(e, t, n, r = {}) {
994
1009
  let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
995
1010
  if (e.aspectRatio < a) return i;
996
1011
  let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
997
1012
  return Math.min(o ?? i + .08, 1 - n * 2);
998
1013
  }
999
- function Fe(e, t, n = {}) {
1014
+ function Q(e, t, n = {}) {
1000
1015
  let r = n.confidenceThreshold ?? .72;
1001
1016
  if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
1002
1017
  hint: "Place the document in the frame",
1003
1018
  reason: "place-document",
1004
1019
  fillRatio: 0,
1005
- fill: Q,
1020
+ fill: Z,
1006
1021
  readyForAutoCapture: !1
1007
1022
  };
1008
- let i = X(e.quad), a = Ne(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;
1023
+ let i = Y(e.quad), a = Le(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;
1009
1024
  if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
1010
1025
  hint: "Move farther away",
1011
1026
  reason: "move-farther-away",
@@ -1013,14 +1028,14 @@ function Fe(e, t, n = {}) {
1013
1028
  fill: a,
1014
1029
  readyForAutoCapture: !1
1015
1030
  };
1016
- let [u, d, f, p] = i, m = Z(u, d), h = Z(d, f), g = Z(f, p), _ = Z(p, u);
1031
+ let [u, d, f, p] = i, m = X(u, d), h = X(d, f), g = X(f, p), _ = X(p, u);
1017
1032
  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) ? {
1018
1033
  hint: "Hold the camera straight",
1019
1034
  reason: "straighten-camera",
1020
1035
  fillRatio: o,
1021
1036
  fill: a,
1022
1037
  readyForAutoCapture: !1
1023
- } : o < Pe(a, t.previouslyReady === !0, s, n) ? {
1038
+ } : o < Re(a, t.previouslyReady === !0, s, n) ? {
1024
1039
  hint: "Move closer",
1025
1040
  reason: "move-closer",
1026
1041
  fillRatio: o,
@@ -1051,8 +1066,8 @@ var $ = class {
1051
1066
  ready: !1,
1052
1067
  movement: Infinity
1053
1068
  };
1054
- let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...X(e.quad).map((e, n) => {
1055
- let r = X(this.previous)[n];
1069
+ let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...Y(e.quad).map((e, n) => {
1070
+ let r = Y(this.previous)[n];
1056
1071
  return Math.hypot(e.x - r.x, e.y - r.y) / Math.max(1, t);
1057
1072
  })) : Infinity, r = this.options.exitCornerTolerance ?? Math.max(this.options.cornerTolerance, .036);
1058
1073
  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, {
@@ -1062,14 +1077,14 @@ var $ = class {
1062
1077
  };
1063
1078
  }
1064
1079
  };
1065
- function Ie(e, n) {
1080
+ function ze(e, n) {
1066
1081
  let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
1067
1082
  i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
1068
1083
  let a = i.getContext("2d");
1069
1084
  if (!a) throw t();
1070
1085
  return a.drawImage(e, 0, 0, i.width, i.height), i;
1071
1086
  }
1072
- function Le() {
1087
+ function Be() {
1073
1088
  let e = window.AudioContext ?? window.webkitAudioContext;
1074
1089
  if (!e) return;
1075
1090
  let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
@@ -1080,13 +1095,13 @@ function Le() {
1080
1095
  let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
1081
1096
  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();
1082
1097
  }
1083
- async function Re(e) {
1098
+ async function Ve(e) {
1084
1099
  let t = document.createElement("video");
1085
1100
  return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
1086
1101
  }
1087
- async function ze(t) {
1102
+ async function He(t) {
1088
1103
  await x("scan");
1089
- let n = Y(t.autoCapture), r = new $({
1104
+ let n = Fe(t.autoCapture), r = new $({
1090
1105
  stableFrames: t.stableFrames ?? 4,
1091
1106
  confidenceThreshold: t.confidenceThreshold ?? .72,
1092
1107
  cornerTolerance: t.cornerTolerance ?? .024,
@@ -1095,14 +1110,14 @@ async function ze(t) {
1095
1110
  minDimension: 220,
1096
1111
  maxAnalysisDimension: 520,
1097
1112
  ...t.detection
1098
- }, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await Re(t.source) : t.source, c = !0, l = !1, u = !1, d = 0, f, p = {
1113
+ }, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await Ve(t.source) : t.source, c = !0, l = !1, u = !1, d = 0, f, p = {
1099
1114
  state: "detecting",
1100
1115
  confidence: 0,
1101
1116
  guidance: {
1102
1117
  hint: "Place the document in the frame",
1103
1118
  reason: "place-document",
1104
1119
  fillRatio: 0,
1105
- fill: Q,
1120
+ fill: Z,
1106
1121
  readyForAutoCapture: !1
1107
1122
  },
1108
1123
  lighting: {
@@ -1112,7 +1127,7 @@ async function ze(t) {
1112
1127
  stableFrames: 0,
1113
1128
  requiredStableFrames: t.stableFrames ?? 4,
1114
1129
  autoCapture: { ...n }
1115
- }, m = () => s instanceof HTMLCanvasElement ? Ie(s, i) : q(s, i), h = (e) => {
1130
+ }, m = () => s instanceof HTMLCanvasElement ? ze(s, i) : q(s, i), h = (e) => {
1116
1131
  p = e, t.onStatus?.(e);
1117
1132
  }, g = () => {
1118
1133
  c = !1, window.clearTimeout(d), s instanceof HTMLVideoElement && s !== t.source && (s.srcObject = null);
@@ -1121,11 +1136,11 @@ async function ze(t) {
1121
1136
  l = !0;
1122
1137
  let n;
1123
1138
  try {
1124
- n = await je(t.captureFrame ?? m, () => {
1139
+ n = await Pe(t.captureFrame ?? m, () => {
1125
1140
  h({
1126
1141
  ...p,
1127
1142
  state: "captured"
1128
- }), t.playShutterSound !== !1 && Le(), g();
1143
+ }), t.playShutterSound !== !1 && Be(), g();
1129
1144
  });
1130
1145
  } catch (e) {
1131
1146
  throw l = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
@@ -1139,9 +1154,9 @@ async function ze(t) {
1139
1154
  }, v = async () => {
1140
1155
  if (c && !l) {
1141
1156
  try {
1142
- let e = m(), i = await z(e, o);
1157
+ let e = m(), i = await B(e, o);
1143
1158
  f = i;
1144
- let a = i.quad ? ke(e, i.quad) : {
1159
+ let a = i.quad ? Me(e, i.quad) : {
1145
1160
  strong: !1,
1146
1161
  strength: 0
1147
1162
  }, s = a.strong ? {
@@ -1151,7 +1166,7 @@ async function ze(t) {
1151
1166
  } : {
1152
1167
  castShadow: !1,
1153
1168
  strength: a.strength
1154
- }, c = r.update(i), l = Fe(i, {
1169
+ }, c = r.update(i), l = Q(i, {
1155
1170
  ...c,
1156
1171
  previouslyReady: u
1157
1172
  }, {
@@ -1196,7 +1211,7 @@ async function ze(t) {
1196
1211
  hint: "Place the document in the frame",
1197
1212
  reason: "place-document",
1198
1213
  fillRatio: 0,
1199
- fill: Q,
1214
+ fill: Z,
1200
1215
  readyForAutoCapture: !1
1201
1216
  },
1202
1217
  lighting: {
@@ -1225,6 +1240,6 @@ async function ze(t) {
1225
1240
  };
1226
1241
  }
1227
1242
  //#endregion
1228
- export { o as A, j as C, A as D, le as E, t as F, b as M, y as N, ne as O, e as P, z as S, ce as T, K as _, Fe as a, ue as b, J as c, ye as d, q as f, W as g, be as h, Ne as i, x as j, a as k, De as l, ve as m, Y as n, Ae as o, V as p, Pe as r, ze as s, $ as t, H as u, Te as v, _e as w, ge as x, U as y };
1243
+ 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, re as O, y as P, B as S, ue as T, K as _, Q as a, fe as b, J as c, xe as d, q as f, G as g, Se as h, Le as i, o as j, te as k, Ae as l, be as m, Fe as n, Ne as o, H as p, Re as r, He as s, $ as t, U as u, Oe as v, ye as w, ve as x, W as y };
1229
1244
 
1230
- //# sourceMappingURL=finder-BeINpYm3.js.map
1245
+ //# sourceMappingURL=finder-B8yMQmN9.js.map