@exige/web-scanner-sdk 0.2.17 → 0.2.22
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.
- package/README.md +20 -17
- package/dist/assets/document-worker.js +1 -1
- package/dist/assets/document-worker.js.map +1 -1
- package/dist/{finder-D0Wgl-6-.js → finder-kHZVA7ug.js} +315 -255
- package/dist/finder-kHZVA7ug.js.map +1 -0
- package/dist/react.js +23 -19
- package/dist/react.js.map +1 -1
- package/dist/scanner-sdk.js +323 -325
- package/dist/scanner-sdk.js.map +1 -1
- package/dist/sdk/camera.d.ts +33 -32
- package/dist/sdk/finder.d.ts +14 -11
- package/dist/sdk/lighting.d.ts +6 -0
- package/dist/sdk/ocr.d.ts +7 -3
- package/dist/sdk/ort-runtime.d.ts +1 -1
- package/dist/sdk/scan.d.ts +1 -0
- package/dist/sdk/types.d.ts +2 -0
- package/package.json +1 -1
- package/dist/finder-D0Wgl-6-.js.map +0 -1
- package/dist/sdk/preview-frame.d.ts +0 -27
|
@@ -277,14 +277,14 @@ function se(e) {
|
|
|
277
277
|
}
|
|
278
278
|
//#endregion
|
|
279
279
|
//#region src/sdk/image.ts
|
|
280
|
-
function
|
|
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
|
|
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
|
|
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 =
|
|
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
|
|
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 =
|
|
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
|
|
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
|
|
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
|
|
327
|
-
function
|
|
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 =
|
|
330
|
-
return i >= 1.6 ? Math.min(r, Math.max(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
|
|
332
|
+
function N(e) {
|
|
333
333
|
return e?.trim() || "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
|
|
334
334
|
}
|
|
335
|
-
var
|
|
336
|
-
function
|
|
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
|
|
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
|
|
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
|
|
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
|
|
377
|
+
function _e(t, n, r, i) {
|
|
378
378
|
return new Promise((a, o) => {
|
|
379
|
-
|
|
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
381
|
k(t.data.download.url, t.data.download);
|
|
382
382
|
return;
|
|
383
383
|
}
|
|
384
|
-
let n =
|
|
385
|
-
n && (
|
|
386
|
-
},
|
|
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
|
|
389
|
-
|
|
388
|
+
for (let e of F.values()) e.reject(t);
|
|
389
|
+
F.clear(), P?.terminate(), P = void 0;
|
|
390
390
|
});
|
|
391
|
-
let s = ++
|
|
392
|
-
|
|
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
|
-
|
|
397
|
+
P.postMessage({
|
|
398
398
|
id: s,
|
|
399
399
|
pixels: c,
|
|
400
400
|
width: n,
|
|
401
401
|
height: r,
|
|
402
|
-
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
|
|
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 =
|
|
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
|
|
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,
|
|
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
|
-
|
|
446
|
+
modelNote: y,
|
|
447
|
+
inferenceMs: b
|
|
447
448
|
};
|
|
448
|
-
if (p <
|
|
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
|
-
...
|
|
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
|
-
...
|
|
463
|
+
...x
|
|
463
464
|
};
|
|
464
|
-
let
|
|
465
|
-
return m.confidence <
|
|
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:
|
|
468
|
-
corners:
|
|
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
|
-
...
|
|
474
|
+
...x
|
|
474
475
|
} : {
|
|
475
476
|
status: "success",
|
|
476
|
-
quad:
|
|
477
|
-
corners:
|
|
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
|
-
...
|
|
483
|
+
...x
|
|
483
484
|
};
|
|
484
485
|
}
|
|
485
486
|
function ye(e, t) {
|
|
486
|
-
let n = Math.max(1, Math.round(Math.max(
|
|
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
|
|
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 =
|
|
504
|
-
u.data[
|
|
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
|
|
510
|
-
return await x("scan"),
|
|
522
|
+
async function Se(e, t = {}) {
|
|
523
|
+
return await x("scan"), ve(await M(e, { cloneCanvas: !1 }), t);
|
|
511
524
|
}
|
|
512
|
-
async function
|
|
525
|
+
async function Ce(e, t, n = {}) {
|
|
513
526
|
await x("scan");
|
|
514
|
-
let r = await
|
|
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:
|
|
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:
|
|
536
|
+
canvas: xe(r, t, i)
|
|
524
537
|
};
|
|
525
538
|
}
|
|
526
|
-
async function
|
|
539
|
+
async function we(e, t = {}) {
|
|
527
540
|
await x("scan");
|
|
528
|
-
let n = await
|
|
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 ?? (
|
|
543
|
+
let i = t.maxOutputDimension ?? (R() ? 2048 : 4096);
|
|
531
544
|
return {
|
|
532
545
|
...r,
|
|
533
|
-
canvas:
|
|
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
|
|
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} (
|
|
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
|
|
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(
|
|
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
|
|
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
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
668
|
+
return U(e) <= t && r / n < .01;
|
|
642
669
|
}
|
|
643
|
-
function
|
|
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),
|
|
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
|
|
651
|
-
return
|
|
677
|
+
function G(e) {
|
|
678
|
+
return W(e, e.width, e.height);
|
|
652
679
|
}
|
|
653
|
-
function
|
|
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 =
|
|
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,18 +696,18 @@ function Ae(e, t = 120) {
|
|
|
669
696
|
getMirrorAgeMs: () => c ? performance.now() - c : Infinity
|
|
670
697
|
};
|
|
671
698
|
}
|
|
672
|
-
function
|
|
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
|
|
677
|
-
let
|
|
678
|
-
return e.maxWidth && (
|
|
703
|
+
function K(e = {}) {
|
|
704
|
+
let t = { ideal: e.idealWidth ?? 3840 }, n = { ideal: e.idealHeight ?? 2160 };
|
|
705
|
+
return e.maxWidth && (t.max = e.maxWidth), e.maxHeight && (n.max = e.maxHeight), {
|
|
679
706
|
audio: !1,
|
|
680
707
|
video: {
|
|
681
708
|
facingMode: { ideal: e.facingMode ?? "environment" },
|
|
682
|
-
width:
|
|
683
|
-
height:
|
|
709
|
+
width: t,
|
|
710
|
+
height: n,
|
|
684
711
|
frameRate: {
|
|
685
712
|
ideal: e.maxFrameRate ?? 30,
|
|
686
713
|
max: e.maxFrameRate ?? 30
|
|
@@ -688,65 +715,65 @@ function J(e = {}, t = H()) {
|
|
|
688
715
|
}
|
|
689
716
|
};
|
|
690
717
|
}
|
|
691
|
-
function
|
|
718
|
+
function Ne(e, t, n) {
|
|
692
719
|
let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
|
|
693
720
|
return {
|
|
694
721
|
width: Math.max(1, Math.round(e * r)),
|
|
695
722
|
height: Math.max(1, Math.round(t * r))
|
|
696
723
|
};
|
|
697
724
|
}
|
|
698
|
-
|
|
725
|
+
var Pe = 4096;
|
|
726
|
+
async function Fe(e) {
|
|
727
|
+
let n = globalThis.ImageCapture;
|
|
728
|
+
if (!n) return;
|
|
729
|
+
let r = new n(e), i;
|
|
730
|
+
try {
|
|
731
|
+
let e = r.getPhotoCapabilities ? De(await r.getPhotoCapabilities()) : void 0;
|
|
732
|
+
i = await r.takePhoto(e);
|
|
733
|
+
} catch {
|
|
734
|
+
i = await r.takePhoto();
|
|
735
|
+
}
|
|
736
|
+
let a = await createImageBitmap(i), o = Math.min(1, Pe / Math.max(a.width, a.height, 1)), s = document.createElement("canvas");
|
|
737
|
+
s.width = Math.max(1, Math.round(a.width * o)), s.height = Math.max(1, Math.round(a.height * o));
|
|
738
|
+
let c = s.getContext("2d");
|
|
739
|
+
if (!c) throw a.close?.(), t();
|
|
740
|
+
return c.imageSmoothingEnabled = !0, c.imageSmoothingQuality = "high", c.drawImage(a, 0, 0, s.width, s.height), a.close?.(), s;
|
|
741
|
+
}
|
|
742
|
+
function q(e, n) {
|
|
699
743
|
if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
|
|
700
|
-
let r =
|
|
744
|
+
let r = Ne(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
|
|
701
745
|
i.width = r.width, i.height = r.height;
|
|
702
746
|
let a = i.getContext("2d");
|
|
703
747
|
if (!a) throw t();
|
|
704
748
|
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
705
749
|
}
|
|
706
|
-
function
|
|
707
|
-
|
|
708
|
-
|
|
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({
|
|
750
|
+
function Ie(e) {
|
|
751
|
+
return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [K(e)] : [
|
|
752
|
+
K({
|
|
726
753
|
...e,
|
|
727
754
|
idealWidth: 3840,
|
|
728
755
|
idealHeight: 2160
|
|
729
|
-
}
|
|
730
|
-
|
|
756
|
+
}),
|
|
757
|
+
K({
|
|
731
758
|
...e,
|
|
732
759
|
idealWidth: 2560,
|
|
733
760
|
idealHeight: 1440
|
|
734
|
-
}
|
|
735
|
-
|
|
761
|
+
}),
|
|
762
|
+
K({
|
|
736
763
|
...e,
|
|
737
764
|
idealWidth: 1920,
|
|
738
765
|
idealHeight: 1080
|
|
739
|
-
}
|
|
766
|
+
})
|
|
740
767
|
];
|
|
741
768
|
}
|
|
742
|
-
async function
|
|
769
|
+
async function Le(t, n = {}) {
|
|
743
770
|
await x("scan");
|
|
744
771
|
let r = n.torch ?? "alwaysOff";
|
|
745
772
|
if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
|
|
746
773
|
if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
|
|
747
774
|
t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
|
|
748
775
|
let i, a;
|
|
749
|
-
for (let e of
|
|
776
|
+
for (let e of Ie(n)) try {
|
|
750
777
|
i = await navigator.mediaDevices.getUserMedia(e);
|
|
751
778
|
break;
|
|
752
779
|
} catch (e) {
|
|
@@ -759,7 +786,7 @@ async function Pe(t, n = {}) {
|
|
|
759
786
|
for (let e of i.getTracks()) e.stop();
|
|
760
787
|
throw Error("The camera did not provide a video track.");
|
|
761
788
|
}
|
|
762
|
-
let s =
|
|
789
|
+
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
790
|
if (!l.supported || o.readyState !== "live") return !1;
|
|
764
791
|
try {
|
|
765
792
|
return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
|
|
@@ -777,7 +804,7 @@ async function Pe(t, n = {}) {
|
|
|
777
804
|
}
|
|
778
805
|
};
|
|
779
806
|
l.on && await d(!0);
|
|
780
|
-
let f = r === "auto" && l.supported ? new
|
|
807
|
+
let f = r === "auto" && l.supported ? new V() : void 0, p = f ? window.setInterval(() => {
|
|
781
808
|
if (u || !l.supported) return;
|
|
782
809
|
let e = f.update(s.getLiveLuminance());
|
|
783
810
|
e !== void 0 && e !== l.on && (u = !0, d(e).finally(() => {
|
|
@@ -803,7 +830,7 @@ async function Pe(t, n = {}) {
|
|
|
803
830
|
torchSupported: l.supported,
|
|
804
831
|
torchOn: l.on,
|
|
805
832
|
torch: { ...l },
|
|
806
|
-
engine:
|
|
833
|
+
engine: B()
|
|
807
834
|
};
|
|
808
835
|
};
|
|
809
836
|
return {
|
|
@@ -817,22 +844,49 @@ async function Pe(t, n = {}) {
|
|
|
817
844
|
get torchOn() {
|
|
818
845
|
return l.on;
|
|
819
846
|
},
|
|
820
|
-
capture: (e) =>
|
|
847
|
+
capture: (e) => q(t, e),
|
|
821
848
|
async capturePhoto() {
|
|
822
849
|
let e, n = 0;
|
|
823
850
|
try {
|
|
824
|
-
e =
|
|
851
|
+
e = q(t), n = G(e);
|
|
825
852
|
} catch {
|
|
826
853
|
e = void 0;
|
|
827
854
|
}
|
|
828
|
-
let r = s.getFrame(), i
|
|
829
|
-
if (
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
855
|
+
let r = s.getFrame(), i, a = !1;
|
|
856
|
+
if (Ee(B(), c)) try {
|
|
857
|
+
i = await Fe(o);
|
|
858
|
+
} catch {
|
|
859
|
+
a = !0, i = void 0;
|
|
860
|
+
}
|
|
861
|
+
let l = i ? G(i) : 0, u = !!(i && Oe(i, {
|
|
862
|
+
width: t.videoWidth,
|
|
863
|
+
height: t.videoHeight
|
|
864
|
+
}));
|
|
865
|
+
if (i && l > 10 && u) return console.info("[exige-scanner] capture", {
|
|
866
|
+
method: "image-capture",
|
|
867
|
+
frame: `${i.width}×${i.height}`,
|
|
868
|
+
video: `${t.videoWidth}×${t.videoHeight}`
|
|
869
|
+
}), {
|
|
870
|
+
frame: i,
|
|
871
|
+
method: "image-capture",
|
|
833
872
|
settings: o.getSettings(),
|
|
834
|
-
|
|
835
|
-
|
|
873
|
+
luminance: l,
|
|
874
|
+
diagnostics: m()
|
|
875
|
+
};
|
|
876
|
+
let d = e && n > 10 ? e : void 0, f = d ?? (r ? Me(r) : void 0);
|
|
877
|
+
if (!f) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
|
|
878
|
+
let p = i ? l <= 10 ? "image-capture-empty" : "image-capture-aspect" : a ? "image-capture-failed" : d ? void 0 : "video-frame-empty";
|
|
879
|
+
return console.info("[exige-scanner] capture", {
|
|
880
|
+
method: d ? "video-frame" : "live-mirror",
|
|
881
|
+
frame: `${f.width}×${f.height}`,
|
|
882
|
+
video: `${t.videoWidth}×${t.videoHeight}`,
|
|
883
|
+
fallbackReason: p
|
|
884
|
+
}), {
|
|
885
|
+
frame: f,
|
|
886
|
+
method: d ? "video-frame" : "live-mirror",
|
|
887
|
+
settings: o.getSettings(),
|
|
888
|
+
fallbackReason: p,
|
|
889
|
+
luminance: d ? n : s.getMirrorLuminance(),
|
|
836
890
|
diagnostics: m()
|
|
837
891
|
};
|
|
838
892
|
},
|
|
@@ -850,59 +904,13 @@ async function Pe(t, n = {}) {
|
|
|
850
904
|
};
|
|
851
905
|
}
|
|
852
906
|
//#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
907
|
//#region src/sdk/lighting.ts
|
|
900
|
-
function
|
|
908
|
+
function Re(e, t) {
|
|
901
909
|
if (!e.length) return 0;
|
|
902
910
|
let n = [...e].sort((e, t) => e - t);
|
|
903
911
|
return n[Math.min(n.length - 1, Math.floor(n.length * t))];
|
|
904
912
|
}
|
|
905
|
-
function
|
|
913
|
+
function J(e, t, n, r = 12) {
|
|
906
914
|
if (!t || !n || e.length < t * n) return {
|
|
907
915
|
strong: !1,
|
|
908
916
|
strength: 0,
|
|
@@ -925,7 +933,7 @@ function Be(e, t, n, r = 12) {
|
|
|
925
933
|
});
|
|
926
934
|
}
|
|
927
935
|
}
|
|
928
|
-
let s =
|
|
936
|
+
let s = Re(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
|
|
929
937
|
for (let e = 0; e < o.length; e += 1) {
|
|
930
938
|
if (!c[e] || l[e]) continue;
|
|
931
939
|
let t = [], n = [e];
|
|
@@ -973,23 +981,38 @@ function Be(e, t, n, r = 12) {
|
|
|
973
981
|
}
|
|
974
982
|
return d;
|
|
975
983
|
}
|
|
976
|
-
function
|
|
977
|
-
let
|
|
978
|
-
|
|
984
|
+
function Y(e, t, n, r, i, a, o) {
|
|
985
|
+
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));
|
|
986
|
+
return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
|
|
987
|
+
}
|
|
988
|
+
function X(e, t, n) {
|
|
989
|
+
let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
|
|
990
|
+
for (let a = 1; a <= n; a += 1) {
|
|
979
991
|
let n = 0;
|
|
980
|
-
for (let o = 1; o <= t; o += 1) n += e[(
|
|
992
|
+
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
993
|
}
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
994
|
+
return {
|
|
995
|
+
integral: i,
|
|
996
|
+
stride: r
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
function ze(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
|
|
1000
|
+
let { integral: i, stride: a } = X(e, t, n), o = new Uint8Array(e.length);
|
|
1001
|
+
for (let s = 0; s < n; s += 1) for (let c = 0; c < t; c += 1) {
|
|
1002
|
+
let l = Y(i, a, t, n, c, s, r);
|
|
1003
|
+
o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
|
|
989
1004
|
}
|
|
990
1005
|
return o;
|
|
991
1006
|
}
|
|
992
|
-
function
|
|
1007
|
+
function Be(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
|
|
1008
|
+
let { integral: a, stride: o } = X(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
|
|
1009
|
+
for (let i = 0; i < n; i += 1) for (let l = 0; l < t; l += 1) {
|
|
1010
|
+
let u = Y(a, o, t, n, l, i, r);
|
|
1011
|
+
s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
|
|
1012
|
+
}
|
|
1013
|
+
return s;
|
|
1014
|
+
}
|
|
1015
|
+
function Ve(e, t, n) {
|
|
993
1016
|
let r = [
|
|
994
1017
|
e.topLeft,
|
|
995
1018
|
e.topRight,
|
|
@@ -1003,8 +1026,8 @@ function He(e, t, n) {
|
|
|
1003
1026
|
height: s - a
|
|
1004
1027
|
};
|
|
1005
1028
|
}
|
|
1006
|
-
function
|
|
1007
|
-
let n =
|
|
1029
|
+
function He(e, t) {
|
|
1030
|
+
let n = Ve(t, e.width, e.height);
|
|
1008
1031
|
if (n.width <= 0 || n.height <= 0) return {
|
|
1009
1032
|
strong: !1,
|
|
1010
1033
|
strength: 0,
|
|
@@ -1023,18 +1046,18 @@ function Ue(e, t) {
|
|
|
1023
1046
|
i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
|
|
1024
1047
|
let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
|
|
1025
1048
|
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
|
|
1049
|
+
return J(o, r.width, r.height);
|
|
1027
1050
|
}
|
|
1028
1051
|
//#endregion
|
|
1029
1052
|
//#region src/sdk/finder.ts
|
|
1030
|
-
function
|
|
1053
|
+
function Ue(e, t) {
|
|
1031
1054
|
return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
|
|
1032
1055
|
}
|
|
1033
|
-
async function
|
|
1056
|
+
async function We(e, t) {
|
|
1034
1057
|
let n = await e();
|
|
1035
1058
|
return t(), n;
|
|
1036
1059
|
}
|
|
1037
|
-
function
|
|
1060
|
+
function Ge(e) {
|
|
1038
1061
|
return e === "alwaysOn" || e === "only" ? {
|
|
1039
1062
|
visible: !1,
|
|
1040
1063
|
checked: !0,
|
|
@@ -1049,7 +1072,7 @@ function Ke(e) {
|
|
|
1049
1072
|
mutable: !0
|
|
1050
1073
|
};
|
|
1051
1074
|
}
|
|
1052
|
-
function
|
|
1075
|
+
function Z(e) {
|
|
1053
1076
|
return [
|
|
1054
1077
|
e.topLeft,
|
|
1055
1078
|
e.topRight,
|
|
@@ -1057,11 +1080,30 @@ function X(e) {
|
|
|
1057
1080
|
e.bottomLeft
|
|
1058
1081
|
];
|
|
1059
1082
|
}
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1083
|
+
function Ke(e, t) {
|
|
1084
|
+
let n = e.status === "success" && e.modelStatus !== "failed", r = {
|
|
1085
|
+
status: e.status,
|
|
1086
|
+
confidence: Number(e.confidence.toFixed(3)),
|
|
1087
|
+
source: `${e.sourceWidth}×${e.sourceHeight}`
|
|
1088
|
+
};
|
|
1089
|
+
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);
|
|
1090
|
+
let i = n ? "document found" : e.modelStatus === "failed" ? "document not found (ML failed)" : `document not found (${e.status})`;
|
|
1091
|
+
return {
|
|
1092
|
+
level: n ? "info" : "warn",
|
|
1093
|
+
key: [
|
|
1094
|
+
i,
|
|
1095
|
+
r.modelStatus ?? "",
|
|
1096
|
+
r.modelError ?? "",
|
|
1097
|
+
r.provider ?? "",
|
|
1098
|
+
r.modelNote ?? "",
|
|
1099
|
+
r.source,
|
|
1100
|
+
r.video ?? ""
|
|
1101
|
+
].join("|"),
|
|
1102
|
+
summary: i,
|
|
1103
|
+
detail: r
|
|
1104
|
+
};
|
|
1063
1105
|
}
|
|
1064
|
-
function
|
|
1106
|
+
function qe(e) {
|
|
1065
1107
|
let t = 0;
|
|
1066
1108
|
for (let n = 0; n < e.length; n += 1) {
|
|
1067
1109
|
let r = e[n], i = e[(n + 1) % e.length];
|
|
@@ -1069,42 +1111,42 @@ function Ye(e) {
|
|
|
1069
1111
|
}
|
|
1070
1112
|
return Math.abs(t) / 2;
|
|
1071
1113
|
}
|
|
1072
|
-
function
|
|
1114
|
+
function Q(e, t) {
|
|
1073
1115
|
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
1074
1116
|
}
|
|
1075
|
-
var
|
|
1117
|
+
var $ = {
|
|
1076
1118
|
widthFill: 0,
|
|
1077
1119
|
heightFill: 0,
|
|
1078
1120
|
limitingFill: 0,
|
|
1079
1121
|
areaFill: 0,
|
|
1080
1122
|
aspectRatio: 1
|
|
1081
1123
|
};
|
|
1082
|
-
function
|
|
1083
|
-
let r =
|
|
1124
|
+
function Je(e, t, n) {
|
|
1125
|
+
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
1126
|
return {
|
|
1085
1127
|
widthFill: o,
|
|
1086
1128
|
heightFill: s,
|
|
1087
1129
|
limitingFill: Math.max(o, s),
|
|
1088
|
-
areaFill:
|
|
1130
|
+
areaFill: qe(r) / Math.max(1, t * n),
|
|
1089
1131
|
aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
|
|
1090
1132
|
};
|
|
1091
1133
|
}
|
|
1092
|
-
function
|
|
1134
|
+
function Ye(e, t, n, r = {}) {
|
|
1093
1135
|
let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
|
|
1094
1136
|
if (e.aspectRatio < a) return i;
|
|
1095
1137
|
let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
|
|
1096
1138
|
return Math.min(o ?? i + .08, 1 - n * 2);
|
|
1097
1139
|
}
|
|
1098
|
-
function
|
|
1140
|
+
function Xe(e, t, n = {}) {
|
|
1099
1141
|
let r = n.confidenceThreshold ?? .72;
|
|
1100
1142
|
if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
|
|
1101
1143
|
hint: "Place the document in the frame",
|
|
1102
1144
|
reason: "place-document",
|
|
1103
1145
|
fillRatio: 0,
|
|
1104
|
-
fill:
|
|
1146
|
+
fill: $,
|
|
1105
1147
|
readyForAutoCapture: !1
|
|
1106
1148
|
};
|
|
1107
|
-
let i =
|
|
1149
|
+
let i = Z(e.quad), a = Je(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
1150
|
if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
|
|
1109
1151
|
hint: "Move farther away",
|
|
1110
1152
|
reason: "move-farther-away",
|
|
@@ -1112,14 +1154,14 @@ function Qe(e, t, n = {}) {
|
|
|
1112
1154
|
fill: a,
|
|
1113
1155
|
readyForAutoCapture: !1
|
|
1114
1156
|
};
|
|
1115
|
-
let [u, d, f, p] = i, m =
|
|
1157
|
+
let [u, d, f, p] = i, m = Q(u, d), h = Q(d, f), g = Q(f, p), _ = Q(p, u);
|
|
1116
1158
|
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
1159
|
hint: "Hold the camera straight",
|
|
1118
1160
|
reason: "straighten-camera",
|
|
1119
1161
|
fillRatio: o,
|
|
1120
1162
|
fill: a,
|
|
1121
1163
|
readyForAutoCapture: !1
|
|
1122
|
-
} : o <
|
|
1164
|
+
} : o < Ye(a, t.previouslyReady === !0, s, n) ? {
|
|
1123
1165
|
hint: "Move closer",
|
|
1124
1166
|
reason: "move-closer",
|
|
1125
1167
|
fillRatio: o,
|
|
@@ -1133,7 +1175,7 @@ function Qe(e, t, n = {}) {
|
|
|
1133
1175
|
readyForAutoCapture: t.ready
|
|
1134
1176
|
};
|
|
1135
1177
|
}
|
|
1136
|
-
var
|
|
1178
|
+
var Ze = class {
|
|
1137
1179
|
previous;
|
|
1138
1180
|
count = 0;
|
|
1139
1181
|
ready = !1;
|
|
@@ -1150,8 +1192,8 @@ var $ = class {
|
|
|
1150
1192
|
ready: !1,
|
|
1151
1193
|
movement: Infinity
|
|
1152
1194
|
};
|
|
1153
|
-
let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...
|
|
1154
|
-
let r =
|
|
1195
|
+
let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...Z(e.quad).map((e, n) => {
|
|
1196
|
+
let r = Z(this.previous)[n];
|
|
1155
1197
|
return Math.hypot(e.x - r.x, e.y - r.y) / Math.max(1, t);
|
|
1156
1198
|
})) : Infinity, r = this.options.exitCornerTolerance ?? Math.max(this.options.cornerTolerance, .036);
|
|
1157
1199
|
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 +1203,14 @@ var $ = class {
|
|
|
1161
1203
|
};
|
|
1162
1204
|
}
|
|
1163
1205
|
};
|
|
1164
|
-
function
|
|
1165
|
-
let
|
|
1166
|
-
|
|
1167
|
-
let
|
|
1168
|
-
|
|
1206
|
+
function Qe(e, n) {
|
|
1207
|
+
let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
|
|
1208
|
+
i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
|
|
1209
|
+
let a = i.getContext("2d");
|
|
1210
|
+
if (!a) throw t();
|
|
1211
|
+
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
1169
1212
|
}
|
|
1170
|
-
function
|
|
1213
|
+
function $e() {
|
|
1171
1214
|
let e = window.AudioContext ?? window.webkitAudioContext;
|
|
1172
1215
|
if (!e) return;
|
|
1173
1216
|
let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
|
|
@@ -1178,29 +1221,29 @@ function et() {
|
|
|
1178
1221
|
let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
|
|
1179
1222
|
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
1223
|
}
|
|
1181
|
-
async function
|
|
1224
|
+
async function et(e) {
|
|
1182
1225
|
let t = document.createElement("video");
|
|
1183
1226
|
return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
|
|
1184
1227
|
}
|
|
1185
|
-
async function
|
|
1228
|
+
async function tt(t) {
|
|
1186
1229
|
await x("scan");
|
|
1187
|
-
let n =
|
|
1230
|
+
let n = Ge(t.autoCapture), r = new Ze({
|
|
1188
1231
|
stableFrames: t.stableFrames ?? 4,
|
|
1189
1232
|
confidenceThreshold: t.confidenceThreshold ?? .72,
|
|
1190
1233
|
cornerTolerance: t.cornerTolerance ?? .024,
|
|
1191
1234
|
exitCornerTolerance: t.exitCornerTolerance ?? .036
|
|
1192
|
-
}), i = t.maxFrameDimension ??
|
|
1235
|
+
}), i = t.maxFrameDimension ?? 1600, a = t.intervalMs ?? 140, o = {
|
|
1193
1236
|
minDimension: 220,
|
|
1194
|
-
maxAnalysisDimension:
|
|
1237
|
+
maxAnalysisDimension: 520,
|
|
1195
1238
|
...t.detection
|
|
1196
|
-
}, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await
|
|
1239
|
+
}, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await et(t.source) : t.source, c = !0, l = !1, u = !1, d = 0, f, p = "", m = 0, h = {
|
|
1197
1240
|
state: "detecting",
|
|
1198
1241
|
confidence: 0,
|
|
1199
1242
|
guidance: {
|
|
1200
1243
|
hint: "Place the document in the frame",
|
|
1201
1244
|
reason: "place-document",
|
|
1202
1245
|
fillRatio: 0,
|
|
1203
|
-
fill:
|
|
1246
|
+
fill: $,
|
|
1204
1247
|
readyForAutoCapture: !1
|
|
1205
1248
|
},
|
|
1206
1249
|
lighting: {
|
|
@@ -1210,20 +1253,29 @@ async function nt(t) {
|
|
|
1210
1253
|
stableFrames: 0,
|
|
1211
1254
|
requiredStableFrames: t.stableFrames ?? 4,
|
|
1212
1255
|
autoCapture: { ...n }
|
|
1213
|
-
},
|
|
1214
|
-
|
|
1215
|
-
},
|
|
1256
|
+
}, g = () => s instanceof HTMLCanvasElement ? Qe(s, i) : q(s, i), _ = (e) => {
|
|
1257
|
+
h = e, t.onStatus?.(e);
|
|
1258
|
+
}, v = (e) => {
|
|
1259
|
+
let t = Ke(e, s instanceof HTMLVideoElement ? {
|
|
1260
|
+
width: s.videoWidth,
|
|
1261
|
+
height: s.videoHeight
|
|
1262
|
+
} : {
|
|
1263
|
+
width: s.width,
|
|
1264
|
+
height: s.height
|
|
1265
|
+
}), n = performance.now();
|
|
1266
|
+
t.key === p && n - m < 2e3 || (p = t.key, m = n, console[t.level](`[exige-scanner] ${t.summary}`, t.detail));
|
|
1267
|
+
}, y = () => {
|
|
1216
1268
|
c = !1, window.clearTimeout(d), s instanceof HTMLVideoElement && s !== t.source && (s.srcObject = null);
|
|
1217
|
-
},
|
|
1269
|
+
}, b = async (e = "manual") => {
|
|
1218
1270
|
if (l) throw Error("A finder capture is already in progress.");
|
|
1219
1271
|
l = !0;
|
|
1220
1272
|
let n;
|
|
1221
1273
|
try {
|
|
1222
|
-
n = await
|
|
1223
|
-
|
|
1224
|
-
...
|
|
1274
|
+
n = await We(t.captureFrame ?? g, () => {
|
|
1275
|
+
_({
|
|
1276
|
+
...h,
|
|
1225
1277
|
state: "captured"
|
|
1226
|
-
}), t.playShutterSound !== !1 &&
|
|
1278
|
+
}), t.playShutterSound !== !1 && $e(), y();
|
|
1227
1279
|
});
|
|
1228
1280
|
} catch (e) {
|
|
1229
1281
|
throw l = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
|
|
@@ -1234,12 +1286,12 @@ async function nt(t) {
|
|
|
1234
1286
|
reason: e
|
|
1235
1287
|
};
|
|
1236
1288
|
return await t.onCapture?.(r), r;
|
|
1237
|
-
},
|
|
1289
|
+
}, S = async () => {
|
|
1238
1290
|
if (c && !l) {
|
|
1239
1291
|
try {
|
|
1240
|
-
let e =
|
|
1241
|
-
f = i;
|
|
1242
|
-
let a = i.quad ?
|
|
1292
|
+
let e = g(), i = await Se(e, o);
|
|
1293
|
+
f = i, v(i);
|
|
1294
|
+
let a = i.quad ? He(e, i.quad) : {
|
|
1243
1295
|
strong: !1,
|
|
1244
1296
|
strength: 0
|
|
1245
1297
|
}, s = a.strong ? {
|
|
@@ -1249,7 +1301,7 @@ async function nt(t) {
|
|
|
1249
1301
|
} : {
|
|
1250
1302
|
castShadow: !1,
|
|
1251
1303
|
strength: a.strength
|
|
1252
|
-
}, c = r.update(i), l =
|
|
1304
|
+
}, c = r.update(i), l = Xe(i, {
|
|
1253
1305
|
...c,
|
|
1254
1306
|
previouslyReady: u
|
|
1255
1307
|
}, {
|
|
@@ -1258,14 +1310,14 @@ async function nt(t) {
|
|
|
1258
1310
|
});
|
|
1259
1311
|
u = l.readyForAutoCapture;
|
|
1260
1312
|
let d = i.status !== "success" || l.reason === "place-document" ? "seeking" : l.readyForAutoCapture ? "ready" : "unstable";
|
|
1261
|
-
if (
|
|
1313
|
+
if (_({
|
|
1262
1314
|
state: d,
|
|
1263
1315
|
confidence: i.confidence,
|
|
1264
1316
|
quad: i.quad,
|
|
1265
1317
|
guidance: l,
|
|
1266
1318
|
lighting: s,
|
|
1267
1319
|
stableFrames: c.stableFrames,
|
|
1268
|
-
requiredStableFrames:
|
|
1320
|
+
requiredStableFrames: h.requiredStableFrames,
|
|
1269
1321
|
autoCapture: { ...n },
|
|
1270
1322
|
sourceWidth: i.sourceWidth,
|
|
1271
1323
|
sourceHeight: i.sourceHeight,
|
|
@@ -1273,9 +1325,10 @@ async function nt(t) {
|
|
|
1273
1325
|
modelStatus: i.modelStatus,
|
|
1274
1326
|
modelProvider: i.modelProvider,
|
|
1275
1327
|
modelError: i.modelError,
|
|
1328
|
+
modelNote: i.modelNote,
|
|
1276
1329
|
inferenceMs: i.inferenceMs
|
|
1277
1330
|
}), l.readyForAutoCapture && n.checked) try {
|
|
1278
|
-
await
|
|
1331
|
+
await b("auto");
|
|
1279
1332
|
return;
|
|
1280
1333
|
} catch (e) {
|
|
1281
1334
|
r.reset(), u = !1, t.onCaptureError?.(e instanceof Error ? e : /* @__PURE__ */ Error("Automatic capture failed."));
|
|
@@ -1286,15 +1339,22 @@ async function nt(t) {
|
|
|
1286
1339
|
detector: "ml",
|
|
1287
1340
|
modelStatus: "failed",
|
|
1288
1341
|
modelError: t.message
|
|
1289
|
-
} : {};
|
|
1290
|
-
|
|
1342
|
+
} : { modelError: t instanceof Error ? t.message : "Finder tick failed." };
|
|
1343
|
+
v({
|
|
1344
|
+
status: "no-document",
|
|
1345
|
+
confidence: 0,
|
|
1346
|
+
message: i.modelError ?? "Finder tick failed.",
|
|
1347
|
+
sourceWidth: 0,
|
|
1348
|
+
sourceHeight: 0,
|
|
1349
|
+
...i
|
|
1350
|
+
}), _({
|
|
1291
1351
|
state: "seeking",
|
|
1292
1352
|
confidence: 0,
|
|
1293
1353
|
guidance: {
|
|
1294
1354
|
hint: "Place the document in the frame",
|
|
1295
1355
|
reason: "place-document",
|
|
1296
1356
|
fillRatio: 0,
|
|
1297
|
-
fill:
|
|
1357
|
+
fill: $,
|
|
1298
1358
|
readyForAutoCapture: !1
|
|
1299
1359
|
},
|
|
1300
1360
|
lighting: {
|
|
@@ -1302,27 +1362,27 @@ async function nt(t) {
|
|
|
1302
1362
|
strength: 0
|
|
1303
1363
|
},
|
|
1304
1364
|
stableFrames: 0,
|
|
1305
|
-
requiredStableFrames:
|
|
1365
|
+
requiredStableFrames: h.requiredStableFrames,
|
|
1306
1366
|
autoCapture: { ...n },
|
|
1307
1367
|
...i
|
|
1308
1368
|
});
|
|
1309
1369
|
}
|
|
1310
|
-
c && (d = window.setTimeout(() => void
|
|
1370
|
+
c && (d = window.setTimeout(() => void S(), a));
|
|
1311
1371
|
}
|
|
1312
1372
|
};
|
|
1313
|
-
return t.onStatus?.(
|
|
1314
|
-
stop:
|
|
1315
|
-
capture: () =>
|
|
1373
|
+
return t.onStatus?.(h), S(), {
|
|
1374
|
+
stop: y,
|
|
1375
|
+
capture: () => b("manual"),
|
|
1316
1376
|
setAutoCapture(e) {
|
|
1317
|
-
return !n.mutable || l ? !1 : (n.checked = e,
|
|
1318
|
-
...
|
|
1377
|
+
return !n.mutable || l ? !1 : (n.checked = e, _({
|
|
1378
|
+
...h,
|
|
1319
1379
|
autoCapture: { ...n }
|
|
1320
1380
|
}), !0);
|
|
1321
1381
|
},
|
|
1322
|
-
getStatus: () =>
|
|
1382
|
+
getStatus: () => h
|
|
1323
1383
|
};
|
|
1324
1384
|
}
|
|
1325
1385
|
//#endregion
|
|
1326
|
-
export {
|
|
1386
|
+
export { ne as A, Se as C, ue as D, le as E, y as F, e as I, t as L, o as M, x as N, M as O, b as P, Ce as S, we as T, U as _, Xe as a, H as b, Be as c, V as d, ke as f, Ae as g, Te as h, Je as i, a as j, ie as k, J as l, B as m, Ge as n, Ue as o, q as p, Ye as r, tt as s, Ze as t, ze as u, K as v, N as w, de as x, Le as y };
|
|
1327
1387
|
|
|
1328
|
-
//# sourceMappingURL=finder-
|
|
1388
|
+
//# sourceMappingURL=finder-kHZVA7ug.js.map
|