@exige/web-scanner-sdk 0.2.24 → 0.2.26
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 +2 -2
- package/dist/{finder-B3kHQ2Jh.js → finder-Dcg3mVJM.js} +268 -198
- package/dist/finder-Dcg3mVJM.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/react/context.d.ts +1 -1
- package/dist/react/types.d.ts +13 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +381 -274
- package/dist/react.js.map +1 -1
- package/dist/scanner-sdk.js +239 -239
- package/dist/scanner-sdk.js.map +1 -1
- package/dist/sdk/camera.d.ts +44 -2
- package/dist/sdk/ocr.d.ts +1 -1
- package/dist/sdk/scan.d.ts +12 -0
- package/package.json +1 -1
- package/dist/finder-B3kHQ2Jh.js.map +0 -1
|
@@ -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
|
|
187
|
+
function te() {
|
|
188
188
|
if (w.size === 0) return {
|
|
189
189
|
downloading: !1,
|
|
190
190
|
loaded: 0,
|
|
@@ -198,22 +198,22 @@ function O() {
|
|
|
198
198
|
total: n ? t : null
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
|
-
function
|
|
202
|
-
let e =
|
|
201
|
+
function O() {
|
|
202
|
+
let e = te();
|
|
203
203
|
for (let t of T) t(e);
|
|
204
204
|
}
|
|
205
|
-
function
|
|
206
|
-
return e(
|
|
205
|
+
function ne(e) {
|
|
206
|
+
return e(te()), T.add(e), () => {
|
|
207
207
|
T.delete(e);
|
|
208
208
|
};
|
|
209
209
|
}
|
|
210
|
-
function
|
|
210
|
+
function k(e, t) {
|
|
211
211
|
t.done ? w.delete(e) : w.set(e, {
|
|
212
212
|
loaded: t.loaded,
|
|
213
213
|
total: t.total
|
|
214
|
-
}),
|
|
214
|
+
}), O();
|
|
215
215
|
}
|
|
216
|
-
async function
|
|
216
|
+
async function re(e, t) {
|
|
217
217
|
let n = ee(e);
|
|
218
218
|
if (!e.body) {
|
|
219
219
|
let r = await e.arrayBuffer();
|
|
@@ -238,53 +238,53 @@ async function ne(e, t) {
|
|
|
238
238
|
total: n
|
|
239
239
|
}), o.buffer;
|
|
240
240
|
}
|
|
241
|
-
async function
|
|
241
|
+
async function ie(t, n) {
|
|
242
242
|
let r = E.get(t);
|
|
243
243
|
if (r) return r.slice(0);
|
|
244
244
|
let i = D.get(t);
|
|
245
245
|
if (i) return i.then((e) => e.slice(0));
|
|
246
246
|
let a = (async () => {
|
|
247
|
-
|
|
247
|
+
k(t, {
|
|
248
248
|
loaded: 0,
|
|
249
249
|
total: null
|
|
250
250
|
});
|
|
251
251
|
let r = await fetch(t, { cache: n?.cache });
|
|
252
252
|
if (!r.ok) throw new e("model-http", `Model request failed with HTTP ${r.status}.`);
|
|
253
|
-
return
|
|
253
|
+
return re(r, (e) => k(t, e));
|
|
254
254
|
})();
|
|
255
255
|
D.set(t, a);
|
|
256
256
|
try {
|
|
257
257
|
let e = await a;
|
|
258
258
|
return E.set(t, e), e.slice(0);
|
|
259
259
|
} finally {
|
|
260
|
-
D.delete(t), w.has(t) && (w.delete(t),
|
|
260
|
+
D.delete(t), w.has(t) && (w.delete(t), O());
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
//#endregion
|
|
264
264
|
//#region src/sdk/ort-runtime.ts
|
|
265
|
-
var
|
|
266
|
-
function
|
|
265
|
+
var ae = new URL("./assets/ort-wasm-simd-threaded.jsep.wasm", import.meta.url), oe = new URL("./assets/ort-wasm-simd-threaded.jsep.mjs", import.meta.url);
|
|
266
|
+
function se() {
|
|
267
267
|
return {
|
|
268
|
-
wasm:
|
|
269
|
-
mjs:
|
|
268
|
+
wasm: ae.href,
|
|
269
|
+
mjs: oe.href
|
|
270
270
|
};
|
|
271
271
|
}
|
|
272
|
-
function
|
|
273
|
-
return typeof e == "string" ? e.trim() ||
|
|
272
|
+
function ce(e) {
|
|
273
|
+
return typeof e == "string" ? e.trim() || se() : e?.wasm.trim() && e.mjs.trim() ? {
|
|
274
274
|
wasm: e.wasm.trim(),
|
|
275
275
|
mjs: e.mjs.trim()
|
|
276
|
-
} :
|
|
276
|
+
} : se();
|
|
277
277
|
}
|
|
278
278
|
//#endregion
|
|
279
279
|
//#region src/sdk/image.ts
|
|
280
|
-
function
|
|
280
|
+
function le(e, t, n) {
|
|
281
281
|
let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
|
|
282
282
|
return {
|
|
283
283
|
width: Math.max(1, Math.round(e * r)),
|
|
284
284
|
height: Math.max(1, Math.round(t * r))
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
|
-
async function
|
|
287
|
+
async function ue(e) {
|
|
288
288
|
let t = URL.createObjectURL(e);
|
|
289
289
|
try {
|
|
290
290
|
let e = new Image();
|
|
@@ -293,26 +293,26 @@ async function ce(e) {
|
|
|
293
293
|
URL.revokeObjectURL(t);
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
|
-
async function
|
|
296
|
+
async function A(e, n = {}) {
|
|
297
297
|
if (e instanceof HTMLCanvasElement && n.cloneCanvas === !1 && !n.maxDimension) return e;
|
|
298
298
|
let r = document.createElement("canvas"), i = r.getContext("2d", { willReadFrequently: !0 });
|
|
299
299
|
if (!i) throw t();
|
|
300
300
|
if (e instanceof Blob) {
|
|
301
301
|
if ("createImageBitmap" in window) try {
|
|
302
|
-
let t = await createImageBitmap(e), a =
|
|
302
|
+
let t = await createImageBitmap(e), a = le(t.width, t.height, n.maxDimension);
|
|
303
303
|
return r.width = a.width, r.height = a.height, i.drawImage(t, 0, 0, a.width, a.height), t.close(), r;
|
|
304
304
|
} catch {}
|
|
305
|
-
e = await
|
|
305
|
+
e = await ue(e);
|
|
306
306
|
}
|
|
307
307
|
let a = e instanceof HTMLImageElement ? e.naturalWidth : e.width, o = e instanceof HTMLImageElement ? e.naturalHeight : e.height;
|
|
308
308
|
if (!a || !o) throw Error("The image has no readable dimensions.");
|
|
309
|
-
let s =
|
|
309
|
+
let s = le(a, o, n.maxDimension);
|
|
310
310
|
return r.width = s.width, r.height = s.height, i.drawImage(e, 0, 0, s.width, s.height), r;
|
|
311
311
|
}
|
|
312
|
-
function
|
|
312
|
+
function de(e, t = "image/png", n = .92) {
|
|
313
313
|
return new Promise((r, i) => e.toBlob((e) => e ? r(e) : i(/* @__PURE__ */ Error("Could not encode the image.")), t, n));
|
|
314
314
|
}
|
|
315
|
-
function
|
|
315
|
+
function fe(e, t, n) {
|
|
316
316
|
let r = Math.max(0, Math.min(t, e.x)), i = Math.max(0, Math.min(n, e.y));
|
|
317
317
|
return {
|
|
318
318
|
x: r,
|
|
@@ -323,20 +323,20 @@ function ue(e, t, n) {
|
|
|
323
323
|
}
|
|
324
324
|
//#endregion
|
|
325
325
|
//#region src/sdk/scan.ts
|
|
326
|
-
var
|
|
327
|
-
function
|
|
326
|
+
var pe = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", me = 1280;
|
|
327
|
+
function he(e, t, n) {
|
|
328
328
|
if (n) return n;
|
|
329
|
-
let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a =
|
|
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 = ye() ? 560 : 900;
|
|
330
|
+
return i >= 1.6 ? Math.min(r, Math.max(a, me)) : a;
|
|
331
331
|
}
|
|
332
|
-
function
|
|
332
|
+
function j(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 ge = 3, M, _e = 0, N = /* @__PURE__ */ new Map();
|
|
336
|
+
function P(e, t) {
|
|
337
337
|
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
338
338
|
}
|
|
339
|
-
function
|
|
339
|
+
function F(e) {
|
|
340
340
|
return {
|
|
341
341
|
...e,
|
|
342
342
|
edges: {
|
|
@@ -359,7 +359,7 @@ function L(e) {
|
|
|
359
359
|
}
|
|
360
360
|
};
|
|
361
361
|
}
|
|
362
|
-
function
|
|
362
|
+
function ve(e, t) {
|
|
363
363
|
let n = (e) => ({
|
|
364
364
|
x: e.x / t,
|
|
365
365
|
y: e.y / t
|
|
@@ -371,42 +371,42 @@ function ge(e, t) {
|
|
|
371
371
|
bottomLeft: n(e.bottomLeft)
|
|
372
372
|
};
|
|
373
373
|
}
|
|
374
|
-
function
|
|
374
|
+
function ye() {
|
|
375
375
|
return typeof navigator > "u" ? !1 : navigator.maxTouchPoints > 0 || navigator.hardwareConcurrency <= 4 || typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
|
|
376
376
|
}
|
|
377
|
-
function
|
|
377
|
+
function be(t, n, r, i) {
|
|
378
378
|
return new Promise((a, o) => {
|
|
379
|
-
|
|
379
|
+
M || (M = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), M.onmessage = (t) => {
|
|
380
380
|
if (t.data.download?.url) {
|
|
381
|
-
|
|
381
|
+
k(t.data.download.url, t.data.download);
|
|
382
382
|
return;
|
|
383
383
|
}
|
|
384
|
-
let n =
|
|
385
|
-
n && (
|
|
386
|
-
},
|
|
384
|
+
let n = N.get(t.data.id);
|
|
385
|
+
n && (N.delete(t.data.id), t.data.error ? n.reject(t.data.errorCode ? new e(t.data.errorCode, t.data.error) : Error(t.data.error)) : t.data.result ? n.resolve(t.data.result) : n.reject(/* @__PURE__ */ Error("The document worker returned no result.")));
|
|
386
|
+
}, M.onerror = () => {
|
|
387
387
|
let t = new e("worker", "The document worker could not start.");
|
|
388
|
-
for (let e of
|
|
389
|
-
|
|
388
|
+
for (let e of N.values()) e.reject(t);
|
|
389
|
+
N.clear(), M?.terminate(), M = void 0;
|
|
390
390
|
});
|
|
391
|
-
let s = ++
|
|
392
|
-
|
|
391
|
+
let s = ++_e;
|
|
392
|
+
N.set(s, {
|
|
393
393
|
resolve: a,
|
|
394
394
|
reject: o
|
|
395
395
|
});
|
|
396
396
|
let c = t.slice().buffer;
|
|
397
|
-
|
|
397
|
+
M.postMessage({
|
|
398
398
|
id: s,
|
|
399
399
|
pixels: c,
|
|
400
400
|
width: n,
|
|
401
401
|
height: r,
|
|
402
|
-
modelUrl:
|
|
402
|
+
modelUrl: j(i.modelUrl),
|
|
403
403
|
heatmapThreshold: i.heatmapThreshold,
|
|
404
404
|
cacheModel: i.cacheModel,
|
|
405
|
-
ortWasmPaths:
|
|
405
|
+
ortWasmPaths: ce(i.ortWasmPaths)
|
|
406
406
|
}, [c]);
|
|
407
407
|
});
|
|
408
408
|
}
|
|
409
|
-
async function
|
|
409
|
+
async function I(n, r) {
|
|
410
410
|
let { width: i, height: a } = n, o = r.minDimension ?? 360;
|
|
411
411
|
if (Math.min(i, a) < o) return {
|
|
412
412
|
status: "low-quality",
|
|
@@ -415,14 +415,14 @@ async function ve(n, r) {
|
|
|
415
415
|
sourceWidth: i,
|
|
416
416
|
sourceHeight: a
|
|
417
417
|
};
|
|
418
|
-
let s =
|
|
418
|
+
let s = he(i, a, r.maxAnalysisDimension), c = Math.min(1, s / Math.max(i, a)), l = document.createElement("canvas");
|
|
419
419
|
l.width = Math.max(1, Math.round(i * c)), l.height = Math.max(1, Math.round(a * c));
|
|
420
420
|
let u = l.getContext("2d", { willReadFrequently: !0 });
|
|
421
421
|
if (!u) throw t();
|
|
422
422
|
u.drawImage(n, 0, 0, l.width, l.height);
|
|
423
423
|
let d = u.getImageData(0, 0, l.width, l.height).data, f;
|
|
424
424
|
if (r.useWorker !== !1 && typeof Worker < "u") try {
|
|
425
|
-
f = await
|
|
425
|
+
f = await be(d, l.width, l.height, r);
|
|
426
426
|
} catch (t) {
|
|
427
427
|
if (t instanceof e && (t.code === "worker" || t.code === "model-http")) throw t;
|
|
428
428
|
f = {
|
|
@@ -446,7 +446,7 @@ async function ve(n, r) {
|
|
|
446
446
|
modelNote: y,
|
|
447
447
|
inferenceMs: b
|
|
448
448
|
};
|
|
449
|
-
if (p <
|
|
449
|
+
if (p < ge) return {
|
|
450
450
|
status: "low-quality",
|
|
451
451
|
confidence: Math.min(.3, p / 18),
|
|
452
452
|
message: "The image is too soft or dark to resolve four document edges.",
|
|
@@ -462,7 +462,7 @@ async function ve(n, r) {
|
|
|
462
462
|
sourceHeight: a,
|
|
463
463
|
...x
|
|
464
464
|
};
|
|
465
|
-
let S =
|
|
465
|
+
let S = ve(m.corners, c), C = F(S), w = r.minConfidence ?? .58;
|
|
466
466
|
return m.confidence < w ? {
|
|
467
467
|
status: "low-confidence",
|
|
468
468
|
quad: C,
|
|
@@ -483,14 +483,14 @@ async function ve(n, r) {
|
|
|
483
483
|
...x
|
|
484
484
|
};
|
|
485
485
|
}
|
|
486
|
-
function
|
|
487
|
-
let n = Math.max(1, Math.round(Math.max(
|
|
486
|
+
function xe(e, t) {
|
|
487
|
+
let n = Math.max(1, Math.round(Math.max(P(e.topLeft, e.topRight), P(e.bottomLeft, e.bottomRight)))), r = Math.max(1, Math.round(Math.max(P(e.topLeft, e.bottomLeft), P(e.topRight, e.bottomRight)))), i = Math.min(1, t / Math.max(n, r));
|
|
488
488
|
return {
|
|
489
489
|
width: Math.max(1, Math.round(n * i)),
|
|
490
490
|
height: Math.max(1, Math.round(r * i))
|
|
491
491
|
};
|
|
492
492
|
}
|
|
493
|
-
function
|
|
493
|
+
function Se(e, t, n, r, i) {
|
|
494
494
|
let a = Math.max(0, Math.min(t - 1, r)), o = Math.max(0, Math.min(n - 1, i)), s = Math.floor(a), c = Math.floor(o), l = Math.min(t - 1, s + 1), u = Math.min(n - 1, c + 1), d = a - s, f = o - c, p = c * t, m = u * t, h = (t) => {
|
|
495
495
|
let n = e[(p + s) * 4 + t] * (1 - d) + e[(p + l) * 4 + t] * d, r = e[(m + s) * 4 + t] * (1 - d) + e[(m + l) * 4 + t] * d;
|
|
496
496
|
return Math.round(n * (1 - f) + r * f);
|
|
@@ -502,8 +502,8 @@ function be(e, t, n, r, i) {
|
|
|
502
502
|
255
|
|
503
503
|
];
|
|
504
504
|
}
|
|
505
|
-
function
|
|
506
|
-
let { width: i, height: a } =
|
|
505
|
+
function L(e, n, r) {
|
|
506
|
+
let { width: i, height: a } = xe(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
|
|
507
507
|
if (!o) throw t();
|
|
508
508
|
let s = o.getImageData(0, 0, e.width, e.height), c = document.createElement("canvas");
|
|
509
509
|
c.width = i, c.height = a;
|
|
@@ -513,43 +513,53 @@ function xe(e, n, r) {
|
|
|
513
513
|
for (let t = 0; t < a; t += 1) {
|
|
514
514
|
let n = t / Math.max(1, a - 1);
|
|
515
515
|
for (let r = 0; r < i; r += 1) {
|
|
516
|
-
let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = (w * a + T * n + d.x) / o, l = (E * a + D * n + d.y) / o, [f, p, m, h] =
|
|
516
|
+
let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = (w * a + T * n + d.x) / o, l = (E * a + D * n + d.y) / o, [f, p, m, h] = Se(s.data, e.width, e.height, c, l), g = (t * i + r) * 4;
|
|
517
517
|
u.data[g] = f, u.data[g + 1] = p, u.data[g + 2] = m, u.data[g + 3] = h;
|
|
518
518
|
}
|
|
519
519
|
}
|
|
520
520
|
return l.putImageData(u, 0, 0), c;
|
|
521
521
|
}
|
|
522
|
-
async function
|
|
523
|
-
return await x("scan"),
|
|
522
|
+
async function R(e, t = {}) {
|
|
523
|
+
return await x("scan"), I(await A(e, { cloneCanvas: !1 }), t);
|
|
524
524
|
}
|
|
525
525
|
async function Ce(e, t, n = {}) {
|
|
526
526
|
await x("scan");
|
|
527
|
-
let r = await
|
|
527
|
+
let r = await A(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? 4096;
|
|
528
528
|
return {
|
|
529
529
|
status: "success",
|
|
530
530
|
corners: t,
|
|
531
|
-
quad:
|
|
531
|
+
quad: F(t),
|
|
532
532
|
confidence: 1,
|
|
533
533
|
message: "Captured with the document edges shown in the finder.",
|
|
534
534
|
sourceWidth: r.width,
|
|
535
535
|
sourceHeight: r.height,
|
|
536
|
-
canvas:
|
|
536
|
+
canvas: L(r, t, i)
|
|
537
537
|
};
|
|
538
538
|
}
|
|
539
|
-
async function
|
|
539
|
+
async function z(e, t = {}) {
|
|
540
540
|
await x("scan");
|
|
541
|
-
let n = await
|
|
541
|
+
let n = await A(e, { cloneCanvas: !1 }), r = await I(n, t);
|
|
542
542
|
if (r.status !== "success" || !r.corners) return r;
|
|
543
|
-
let i = t.maxOutputDimension ??
|
|
543
|
+
let i = t.maxOutputDimension ?? 4096;
|
|
544
544
|
return {
|
|
545
545
|
...r,
|
|
546
|
-
canvas:
|
|
546
|
+
canvas: L(n, r.corners, i),
|
|
547
547
|
message: "Four document edges detected and perspective-corrected."
|
|
548
548
|
};
|
|
549
549
|
}
|
|
550
|
+
function B(e) {
|
|
551
|
+
return e.status === "success" ? e.message : e.status === "low-quality" ? e.message.includes("shortest side") ? `${e.message} Take another photo.` : "That photo is too soft or dark to find a document. Take another photo in better light." : e.status === "low-confidence" ? "The page edges were not clear enough to crop. Take another photo with the whole page in frame." : `No document was found in that photo. Take another photo with the whole page in frame.${e.modelStatus === "failed" && e.modelError ? ` (${e.modelError})` : ""}`;
|
|
552
|
+
}
|
|
553
|
+
async function we(e, t = {}) {
|
|
554
|
+
let n = await z(e, t);
|
|
555
|
+
return n.status === "success" ? n : {
|
|
556
|
+
...n,
|
|
557
|
+
message: B(n)
|
|
558
|
+
};
|
|
559
|
+
}
|
|
550
560
|
//#endregion
|
|
551
561
|
//#region src/sdk/camera.ts
|
|
552
|
-
function
|
|
562
|
+
function V(e, t) {
|
|
553
563
|
let { engine: n } = t;
|
|
554
564
|
return [
|
|
555
565
|
`${e}:`,
|
|
@@ -566,7 +576,7 @@ function z(e, t) {
|
|
|
566
576
|
}
|
|
567
577
|
function Te(e) {
|
|
568
578
|
let t = ["Exige scanner capture report", `time: ${e.capturedAt ?? (/* @__PURE__ */ new Date()).toISOString()}`];
|
|
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(
|
|
579
|
+
if (e.error && t.push(`error: ${e.error}`), e.captureMethod && t.push(`method: ${e.captureMethod}`), e.luminance !== void 0 && t.push(`luminance: ${e.luminance.toFixed(1)}`), e.fallbackReason && t.push(`fallback: ${e.fallbackReason}`), e.shutter && t.push(V("shutter", e.shutter)), e.live && t.push(V("live", e.live)), e.finder) {
|
|
570
580
|
let n = e.finder;
|
|
571
581
|
t.push([
|
|
572
582
|
"finder:",
|
|
@@ -583,7 +593,7 @@ function Te(e) {
|
|
|
583
593
|
}
|
|
584
594
|
return `${t.join("\n")}\n`;
|
|
585
595
|
}
|
|
586
|
-
function
|
|
596
|
+
function H(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
|
|
587
597
|
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;
|
|
588
598
|
return {
|
|
589
599
|
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",
|
|
@@ -592,21 +602,37 @@ function B(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof nav
|
|
|
592
602
|
userAgent: e
|
|
593
603
|
};
|
|
594
604
|
}
|
|
595
|
-
function
|
|
605
|
+
function U(e) {
|
|
606
|
+
return /Android/i.test(e.userAgent) && !e.iosWebKit;
|
|
607
|
+
}
|
|
608
|
+
function Ee(e = "auto", t = H()) {
|
|
609
|
+
return e === "system-camera" || e !== "live" && U(t);
|
|
610
|
+
}
|
|
611
|
+
function De(e, t) {
|
|
596
612
|
return t && !e.iosWebKit;
|
|
597
613
|
}
|
|
598
|
-
function
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
if (
|
|
602
|
-
|
|
614
|
+
function W(e, t) {
|
|
615
|
+
if (!e || !Number.isFinite(e)) return;
|
|
616
|
+
let n = t?.max;
|
|
617
|
+
if (!n || !Number.isFinite(n)) return Math.round(e);
|
|
618
|
+
let r = t?.min && Number.isFinite(t.min) ? t.min : 1, i = t?.step && t.step > 0 ? t.step : 1, a = r + Math.round((Math.min(n, Math.max(r, e)) - r) / i) * i;
|
|
619
|
+
return Math.round(Math.min(n, Math.max(r, a)));
|
|
620
|
+
}
|
|
621
|
+
function Oe(e) {
|
|
622
|
+
let t = W(e?.imageWidth?.max ?? 0, e?.imageWidth), n = W(e?.imageHeight?.max ?? 0, e?.imageHeight);
|
|
623
|
+
if (t && n) return t >= n ? { imageWidth: t } : { imageHeight: n };
|
|
624
|
+
if (t) return { imageWidth: t };
|
|
625
|
+
if (n) return { imageHeight: n };
|
|
626
|
+
}
|
|
627
|
+
function ke(e, t) {
|
|
628
|
+
return !e.width || !e.height || !t.width || !t.height ? !1 : e.width * e.height > t.width * t.height * 1.15;
|
|
603
629
|
}
|
|
604
|
-
function
|
|
630
|
+
function Ae(e, t) {
|
|
605
631
|
if (!e.width || !e.height || !t.width || !t.height) return !1;
|
|
606
632
|
let n = e.width / e.height / (t.width / t.height);
|
|
607
633
|
return n > .97 && n < 1.03;
|
|
608
634
|
}
|
|
609
|
-
var
|
|
635
|
+
var je = 10, G = class {
|
|
610
636
|
on = !1;
|
|
611
637
|
darkCount = 0;
|
|
612
638
|
brightCount = 0;
|
|
@@ -629,7 +655,7 @@ var ke = 10, V = class {
|
|
|
629
655
|
return this.on;
|
|
630
656
|
}
|
|
631
657
|
};
|
|
632
|
-
function
|
|
658
|
+
function K(e, t) {
|
|
633
659
|
return t ? e === "alwaysOn" || e === "alwaysOff" ? {
|
|
634
660
|
mode: e,
|
|
635
661
|
supported: !0,
|
|
@@ -653,37 +679,37 @@ function H(e, t) {
|
|
|
653
679
|
automatic: e === "auto"
|
|
654
680
|
};
|
|
655
681
|
}
|
|
656
|
-
function
|
|
682
|
+
function q(e) {
|
|
657
683
|
let t = Math.floor(e.length / 4);
|
|
658
684
|
if (!t) return 0;
|
|
659
685
|
let n = 0;
|
|
660
686
|
for (let r = 0; r < t * 4; r += 4) n += e[r] * .299 + e[r + 1] * .587 + e[r + 2] * .114;
|
|
661
687
|
return n / t;
|
|
662
688
|
}
|
|
663
|
-
function
|
|
689
|
+
function Me(e, t = 10) {
|
|
664
690
|
if (e.length < 4) return !0;
|
|
665
691
|
let n = Math.floor(e.length / 4), r = 0;
|
|
666
692
|
for (let i = 0; i < n * 4; i += 4) e[i] * .299 + e[i + 1] * .587 + e[i + 2] * .114 > t * 2 && (r += 1);
|
|
667
|
-
return
|
|
693
|
+
return q(e) <= t && r / n < .01;
|
|
668
694
|
}
|
|
669
|
-
function
|
|
695
|
+
function Ne(e, t, n) {
|
|
670
696
|
if (!t || !n) return 0;
|
|
671
697
|
let r = document.createElement("canvas");
|
|
672
698
|
r.width = Math.min(32, t), r.height = Math.min(32, n);
|
|
673
699
|
let i = r.getContext("2d", { willReadFrequently: !0 });
|
|
674
|
-
return i ? (i.drawImage(e, 0, 0, r.width, r.height),
|
|
700
|
+
return i ? (i.drawImage(e, 0, 0, r.width, r.height), q(i.getImageData(0, 0, r.width, r.height).data)) : 0;
|
|
675
701
|
}
|
|
676
|
-
function
|
|
677
|
-
return
|
|
702
|
+
function Pe(e) {
|
|
703
|
+
return Ne(e, e.width, e.height);
|
|
678
704
|
}
|
|
679
|
-
function
|
|
705
|
+
function Fe(e, t = 120) {
|
|
680
706
|
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 = () => {
|
|
681
707
|
a && (o = i ? e.requestVideoFrameCallback(f) : requestAnimationFrame(f));
|
|
682
708
|
};
|
|
683
709
|
function f() {
|
|
684
710
|
if (!a) return;
|
|
685
711
|
let { videoWidth: i, videoHeight: o } = e, f = performance.now();
|
|
686
|
-
r && i && o && f - s >= t && (s = f, l =
|
|
712
|
+
r && i && o && f - s >= t && (s = f, l = Ne(e, i, o), l > 10 && ((n.width !== i || n.height !== o) && (n.width = i, n.height = o), r.drawImage(e, 0, 0, i, o), u = l, c = f)), d();
|
|
687
713
|
}
|
|
688
714
|
return d(), {
|
|
689
715
|
stop() {
|
|
@@ -695,14 +721,14 @@ function je(e, t = 120) {
|
|
|
695
721
|
getMirrorAgeMs: () => c ? performance.now() - c : Infinity
|
|
696
722
|
};
|
|
697
723
|
}
|
|
698
|
-
function
|
|
724
|
+
function Ie(e) {
|
|
699
725
|
let t = document.createElement("canvas");
|
|
700
726
|
return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
|
|
701
727
|
}
|
|
702
|
-
function
|
|
728
|
+
function Le(e) {
|
|
703
729
|
return e.engine === "blink";
|
|
704
730
|
}
|
|
705
|
-
function
|
|
731
|
+
function J(e = {}, t = H()) {
|
|
706
732
|
let n = { ideal: e.idealWidth ?? 3840 }, r = { ideal: e.idealHeight ?? 2160 };
|
|
707
733
|
e.maxWidth && (n.max = e.maxWidth), e.maxHeight && (r.max = e.maxHeight);
|
|
708
734
|
let i = {
|
|
@@ -714,20 +740,20 @@ function K(e = {}, t = B()) {
|
|
|
714
740
|
max: e.maxFrameRate ?? 30
|
|
715
741
|
}
|
|
716
742
|
};
|
|
717
|
-
return
|
|
743
|
+
return Le(t) && (i.resizeMode = { ideal: "none" }), {
|
|
718
744
|
audio: !1,
|
|
719
745
|
video: i
|
|
720
746
|
};
|
|
721
747
|
}
|
|
722
|
-
function
|
|
748
|
+
function Re(e, t, n) {
|
|
723
749
|
let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
|
|
724
750
|
return {
|
|
725
751
|
width: Math.max(1, Math.round(e * r)),
|
|
726
752
|
height: Math.max(1, Math.round(t * r))
|
|
727
753
|
};
|
|
728
754
|
}
|
|
729
|
-
var
|
|
730
|
-
function
|
|
755
|
+
var ze = 4096;
|
|
756
|
+
function Be(e, t) {
|
|
731
757
|
let n = e.width, r = e.height, i = t?.width?.max, a = t?.height?.max;
|
|
732
758
|
if (!n || !r || !i || !a) return;
|
|
733
759
|
let o = Math.min(i / n, a / r);
|
|
@@ -736,64 +762,92 @@ function Pe(e, t) {
|
|
|
736
762
|
height: { ideal: Math.round(r * o) }
|
|
737
763
|
};
|
|
738
764
|
}
|
|
739
|
-
async function
|
|
740
|
-
let t =
|
|
765
|
+
async function Ve(e) {
|
|
766
|
+
let t = Be(e.getSettings(), typeof e.getCapabilities == "function" ? e.getCapabilities() : void 0);
|
|
741
767
|
if (t) try {
|
|
742
768
|
await e.applyConstraints(t);
|
|
743
769
|
} catch {}
|
|
744
770
|
}
|
|
745
|
-
async function
|
|
746
|
-
let n = globalThis.ImageCapture;
|
|
747
|
-
if (!n) return;
|
|
748
|
-
let r = new n(e), i;
|
|
771
|
+
async function He(e) {
|
|
749
772
|
try {
|
|
750
|
-
|
|
751
|
-
|
|
773
|
+
return await createImageBitmap(e, {
|
|
774
|
+
imageOrientation: "from-image",
|
|
775
|
+
colorSpaceConversion: "none"
|
|
776
|
+
});
|
|
752
777
|
} catch {
|
|
753
|
-
|
|
778
|
+
return await createImageBitmap(e);
|
|
754
779
|
}
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
780
|
+
}
|
|
781
|
+
async function Ue(e) {
|
|
782
|
+
try {
|
|
783
|
+
await e.applyConstraints({ advanced: [{ pointsOfInterest: [{
|
|
784
|
+
x: .5,
|
|
785
|
+
y: .5
|
|
786
|
+
}] }] }), await new Promise((e) => window.setTimeout(e, 180));
|
|
787
|
+
} catch {}
|
|
788
|
+
}
|
|
789
|
+
async function We(e) {
|
|
790
|
+
let n = await He(e), r = Re(n.width, n.height, ze), i = document.createElement("canvas");
|
|
791
|
+
i.width = r.width, i.height = r.height;
|
|
792
|
+
let a = i.getContext("2d");
|
|
793
|
+
if (!a) throw n.close?.(), t();
|
|
794
|
+
return a.imageSmoothingEnabled = r.width !== n.width || r.height !== n.height, a.imageSmoothingQuality = "high", a.drawImage(n, 0, 0, i.width, i.height), n.close?.(), i;
|
|
795
|
+
}
|
|
796
|
+
async function Ge(e) {
|
|
797
|
+
let t = globalThis.ImageCapture;
|
|
798
|
+
if (!t) return;
|
|
799
|
+
await Ue(e);
|
|
800
|
+
let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i = Oe(r), a;
|
|
801
|
+
try {
|
|
802
|
+
a = await n.takePhoto(i);
|
|
803
|
+
} catch {
|
|
804
|
+
a = await n.takePhoto();
|
|
805
|
+
}
|
|
806
|
+
return {
|
|
807
|
+
frame: await We(a),
|
|
808
|
+
requested: i,
|
|
809
|
+
photoMax: {
|
|
810
|
+
width: r?.imageWidth?.max,
|
|
811
|
+
height: r?.imageHeight?.max
|
|
812
|
+
}
|
|
813
|
+
};
|
|
760
814
|
}
|
|
761
815
|
function Y(e, n) {
|
|
762
816
|
if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
|
|
763
|
-
let r =
|
|
817
|
+
let r = Re(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
|
|
764
818
|
i.width = r.width, i.height = r.height;
|
|
765
819
|
let a = i.getContext("2d");
|
|
766
820
|
if (!a) throw t();
|
|
767
821
|
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
768
822
|
}
|
|
769
|
-
function
|
|
770
|
-
let t =
|
|
771
|
-
return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [
|
|
772
|
-
|
|
823
|
+
function Ke(e) {
|
|
824
|
+
let t = H();
|
|
825
|
+
return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [J(e, t)] : [
|
|
826
|
+
J({
|
|
773
827
|
...e,
|
|
774
828
|
idealWidth: 3840,
|
|
775
829
|
idealHeight: 2160
|
|
776
830
|
}, t),
|
|
777
|
-
|
|
831
|
+
J({
|
|
778
832
|
...e,
|
|
779
833
|
idealWidth: 2560,
|
|
780
834
|
idealHeight: 1440
|
|
781
835
|
}, t),
|
|
782
|
-
|
|
836
|
+
J({
|
|
783
837
|
...e,
|
|
784
838
|
idealWidth: 1920,
|
|
785
839
|
idealHeight: 1080
|
|
786
840
|
}, t)
|
|
787
841
|
];
|
|
788
842
|
}
|
|
789
|
-
async function
|
|
843
|
+
async function qe(t, n = {}) {
|
|
790
844
|
await x("scan");
|
|
791
845
|
let r = n.torch ?? "alwaysOff";
|
|
792
846
|
if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
|
|
793
847
|
if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
|
|
794
848
|
t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
|
|
795
849
|
let i, a;
|
|
796
|
-
for (let e of
|
|
850
|
+
for (let e of Ke(n)) try {
|
|
797
851
|
i = await navigator.mediaDevices.getUserMedia(e);
|
|
798
852
|
break;
|
|
799
853
|
} catch (e) {
|
|
@@ -806,8 +860,8 @@ async function Re(t, n = {}) {
|
|
|
806
860
|
for (let e of i.getTracks()) e.stop();
|
|
807
861
|
throw Error("The camera did not provide a video track.");
|
|
808
862
|
}
|
|
809
|
-
await
|
|
810
|
-
let s =
|
|
863
|
+
await Ve(o);
|
|
864
|
+
let s = Fe(t), c = "ImageCapture" in globalThis, l = K(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
|
|
811
865
|
if (!l.supported || o.readyState !== "live") return !1;
|
|
812
866
|
try {
|
|
813
867
|
return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
|
|
@@ -825,7 +879,7 @@ async function Re(t, n = {}) {
|
|
|
825
879
|
}
|
|
826
880
|
};
|
|
827
881
|
l.on && await d(!0);
|
|
828
|
-
let f = r === "auto" && l.supported ? new
|
|
882
|
+
let f = r === "auto" && l.supported ? new G() : void 0, p = f ? window.setInterval(() => {
|
|
829
883
|
if (u || !l.supported) return;
|
|
830
884
|
let e = f.update(s.getLiveLuminance());
|
|
831
885
|
e !== void 0 && e !== l.on && (u = !0, d(e).finally(() => {
|
|
@@ -851,7 +905,7 @@ async function Re(t, n = {}) {
|
|
|
851
905
|
torchSupported: l.supported,
|
|
852
906
|
torchOn: l.on,
|
|
853
907
|
torch: { ...l },
|
|
854
|
-
engine:
|
|
908
|
+
engine: H()
|
|
855
909
|
};
|
|
856
910
|
};
|
|
857
911
|
return {
|
|
@@ -869,46 +923,51 @@ async function Re(t, n = {}) {
|
|
|
869
923
|
async capturePhoto() {
|
|
870
924
|
let e, n = 0;
|
|
871
925
|
try {
|
|
872
|
-
e = Y(t), n =
|
|
926
|
+
e = Y(t), n = Pe(e);
|
|
873
927
|
} catch {
|
|
874
928
|
e = void 0;
|
|
875
929
|
}
|
|
876
|
-
let r = s.getFrame(), i, a = !1;
|
|
877
|
-
if (
|
|
878
|
-
|
|
930
|
+
let r = s.getFrame(), i, a = !1, l = !1, u, d;
|
|
931
|
+
if (De(H(), c)) try {
|
|
932
|
+
let e = await Ge(o);
|
|
933
|
+
i = e?.frame, u = e?.requested, d = e?.photoMax;
|
|
879
934
|
} catch {
|
|
880
935
|
a = !0, i = void 0;
|
|
881
936
|
}
|
|
882
|
-
let
|
|
883
|
-
|
|
937
|
+
let f = {
|
|
938
|
+
width: t.videoWidth,
|
|
939
|
+
height: t.videoHeight
|
|
940
|
+
}, p = i ? Pe(i) : 0, h = !!(i && p > 10 && ke(i, f));
|
|
941
|
+
if (i && p > 10 && !h && (l = !0), h && i) return console.info("[exige-scanner] capture", {
|
|
884
942
|
method: "image-capture",
|
|
885
943
|
frame: `${i.width}×${i.height}`,
|
|
886
944
|
video: `${t.videoWidth}×${t.videoHeight}`,
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
})
|
|
945
|
+
photoMax: d ? `${d.width ?? "—"}×${d.height ?? "—"}` : void 0,
|
|
946
|
+
photoRequest: u,
|
|
947
|
+
aspectMatch: Ae(i, f)
|
|
891
948
|
}), {
|
|
892
949
|
frame: i,
|
|
893
950
|
method: "image-capture",
|
|
894
951
|
settings: o.getSettings(),
|
|
895
|
-
luminance:
|
|
952
|
+
luminance: p,
|
|
896
953
|
diagnostics: m()
|
|
897
954
|
};
|
|
898
|
-
let
|
|
899
|
-
if (!
|
|
900
|
-
let
|
|
955
|
+
let g = e && n > 10 ? e : void 0, _ = g ?? (r ? Ie(r) : void 0);
|
|
956
|
+
if (!_) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
|
|
957
|
+
let v = l ? "image-capture-preview-size" : i ? "image-capture-empty" : a ? "image-capture-failed" : g ? void 0 : "video-frame-empty";
|
|
901
958
|
return console.info("[exige-scanner] capture", {
|
|
902
|
-
method:
|
|
903
|
-
frame: `${
|
|
959
|
+
method: g ? "video-frame" : "live-mirror",
|
|
960
|
+
frame: `${_.width}×${_.height}`,
|
|
904
961
|
video: `${t.videoWidth}×${t.videoHeight}`,
|
|
905
|
-
|
|
962
|
+
photoMax: d ? `${d.width ?? "—"}×${d.height ?? "—"}` : void 0,
|
|
963
|
+
photoRequest: u,
|
|
964
|
+
fallbackReason: v
|
|
906
965
|
}), {
|
|
907
|
-
frame:
|
|
908
|
-
method:
|
|
966
|
+
frame: _,
|
|
967
|
+
method: g ? "video-frame" : "live-mirror",
|
|
909
968
|
settings: o.getSettings(),
|
|
910
|
-
fallbackReason:
|
|
911
|
-
luminance:
|
|
969
|
+
fallbackReason: v,
|
|
970
|
+
luminance: g ? n : s.getMirrorLuminance(),
|
|
912
971
|
diagnostics: m()
|
|
913
972
|
};
|
|
914
973
|
},
|
|
@@ -925,14 +984,25 @@ async function Re(t, n = {}) {
|
|
|
925
984
|
}
|
|
926
985
|
};
|
|
927
986
|
}
|
|
987
|
+
async function Je() {
|
|
988
|
+
let e = document.createElement("input");
|
|
989
|
+
return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"), We(await new Promise((t, n) => {
|
|
990
|
+
e.addEventListener("change", () => {
|
|
991
|
+
let r = e.files?.[0];
|
|
992
|
+
r ? t(r) : n(/* @__PURE__ */ Error("No photo was selected."));
|
|
993
|
+
}, { once: !0 }), e.addEventListener("cancel", () => {
|
|
994
|
+
n(/* @__PURE__ */ Error("No photo was selected."));
|
|
995
|
+
}, { once: !0 }), e.click();
|
|
996
|
+
}));
|
|
997
|
+
}
|
|
928
998
|
//#endregion
|
|
929
999
|
//#region src/sdk/lighting.ts
|
|
930
|
-
function
|
|
1000
|
+
function Ye(e, t) {
|
|
931
1001
|
if (!e.length) return 0;
|
|
932
1002
|
let n = [...e].sort((e, t) => e - t);
|
|
933
1003
|
return n[Math.min(n.length - 1, Math.floor(n.length * t))];
|
|
934
1004
|
}
|
|
935
|
-
function
|
|
1005
|
+
function Xe(e, t, n, r = 12) {
|
|
936
1006
|
if (!t || !n || e.length < t * n) return {
|
|
937
1007
|
strong: !1,
|
|
938
1008
|
strength: 0,
|
|
@@ -955,7 +1025,7 @@ function X(e, t, n, r = 12) {
|
|
|
955
1025
|
});
|
|
956
1026
|
}
|
|
957
1027
|
}
|
|
958
|
-
let s =
|
|
1028
|
+
let s = Ye(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
|
|
959
1029
|
for (let e = 0; e < o.length; e += 1) {
|
|
960
1030
|
if (!c[e] || l[e]) continue;
|
|
961
1031
|
let t = [], n = [e];
|
|
@@ -1003,11 +1073,11 @@ function X(e, t, n, r = 12) {
|
|
|
1003
1073
|
}
|
|
1004
1074
|
return d;
|
|
1005
1075
|
}
|
|
1006
|
-
function
|
|
1076
|
+
function Ze(e, t, n, r, i, a, o) {
|
|
1007
1077
|
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));
|
|
1008
1078
|
return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
|
|
1009
1079
|
}
|
|
1010
|
-
function
|
|
1080
|
+
function Qe(e, t, n) {
|
|
1011
1081
|
let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
|
|
1012
1082
|
for (let a = 1; a <= n; a += 1) {
|
|
1013
1083
|
let n = 0;
|
|
@@ -1018,23 +1088,23 @@ function Ve(e, t, n) {
|
|
|
1018
1088
|
stride: r
|
|
1019
1089
|
};
|
|
1020
1090
|
}
|
|
1021
|
-
function
|
|
1022
|
-
let { integral: i, stride: a } =
|
|
1091
|
+
function $e(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
|
|
1092
|
+
let { integral: i, stride: a } = Qe(e, t, n), o = new Uint8Array(e.length);
|
|
1023
1093
|
for (let s = 0; s < n; s += 1) for (let c = 0; c < t; c += 1) {
|
|
1024
|
-
let l =
|
|
1094
|
+
let l = Ze(i, a, t, n, c, s, r);
|
|
1025
1095
|
o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
|
|
1026
1096
|
}
|
|
1027
1097
|
return o;
|
|
1028
1098
|
}
|
|
1029
|
-
function
|
|
1030
|
-
let { integral: a, stride: o } =
|
|
1099
|
+
function et(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
|
|
1100
|
+
let { integral: a, stride: o } = Qe(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
|
|
1031
1101
|
for (let i = 0; i < n; i += 1) for (let l = 0; l < t; l += 1) {
|
|
1032
|
-
let u =
|
|
1102
|
+
let u = Ze(a, o, t, n, l, i, r);
|
|
1033
1103
|
s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
|
|
1034
1104
|
}
|
|
1035
1105
|
return s;
|
|
1036
1106
|
}
|
|
1037
|
-
function
|
|
1107
|
+
function tt(e, t, n) {
|
|
1038
1108
|
let r = [
|
|
1039
1109
|
e.topLeft,
|
|
1040
1110
|
e.topRight,
|
|
@@ -1048,8 +1118,8 @@ function We(e, t, n) {
|
|
|
1048
1118
|
height: s - a
|
|
1049
1119
|
};
|
|
1050
1120
|
}
|
|
1051
|
-
function
|
|
1052
|
-
let n =
|
|
1121
|
+
function nt(e, t) {
|
|
1122
|
+
let n = tt(t, e.width, e.height);
|
|
1053
1123
|
if (n.width <= 0 || n.height <= 0) return {
|
|
1054
1124
|
strong: !1,
|
|
1055
1125
|
strength: 0,
|
|
@@ -1068,18 +1138,18 @@ function Ge(e, t) {
|
|
|
1068
1138
|
i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
|
|
1069
1139
|
let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
|
|
1070
1140
|
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);
|
|
1071
|
-
return
|
|
1141
|
+
return Xe(o, r.width, r.height);
|
|
1072
1142
|
}
|
|
1073
1143
|
//#endregion
|
|
1074
1144
|
//#region src/sdk/finder.ts
|
|
1075
|
-
function
|
|
1145
|
+
function rt(e, t) {
|
|
1076
1146
|
return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
|
|
1077
1147
|
}
|
|
1078
|
-
async function
|
|
1148
|
+
async function it(e, t) {
|
|
1079
1149
|
let n = await e();
|
|
1080
1150
|
return t(), n;
|
|
1081
1151
|
}
|
|
1082
|
-
function
|
|
1152
|
+
function at(e) {
|
|
1083
1153
|
return e === "alwaysOn" || e === "only" ? {
|
|
1084
1154
|
visible: !1,
|
|
1085
1155
|
checked: !0,
|
|
@@ -1094,7 +1164,7 @@ function Je(e) {
|
|
|
1094
1164
|
mutable: !0
|
|
1095
1165
|
};
|
|
1096
1166
|
}
|
|
1097
|
-
function
|
|
1167
|
+
function X(e) {
|
|
1098
1168
|
return [
|
|
1099
1169
|
e.topLeft,
|
|
1100
1170
|
e.topRight,
|
|
@@ -1102,7 +1172,7 @@ function Z(e) {
|
|
|
1102
1172
|
e.bottomLeft
|
|
1103
1173
|
];
|
|
1104
1174
|
}
|
|
1105
|
-
function
|
|
1175
|
+
function ot(e, t) {
|
|
1106
1176
|
let n = e.status === "success" && e.modelStatus !== "failed", r = {
|
|
1107
1177
|
status: e.status,
|
|
1108
1178
|
confidence: Number(e.confidence.toFixed(3)),
|
|
@@ -1125,7 +1195,7 @@ function Ye(e, t) {
|
|
|
1125
1195
|
detail: r
|
|
1126
1196
|
};
|
|
1127
1197
|
}
|
|
1128
|
-
function
|
|
1198
|
+
function st(e) {
|
|
1129
1199
|
let t = 0;
|
|
1130
1200
|
for (let n = 0; n < e.length; n += 1) {
|
|
1131
1201
|
let r = e[n], i = e[(n + 1) % e.length];
|
|
@@ -1133,42 +1203,42 @@ function Xe(e) {
|
|
|
1133
1203
|
}
|
|
1134
1204
|
return Math.abs(t) / 2;
|
|
1135
1205
|
}
|
|
1136
|
-
function
|
|
1206
|
+
function Z(e, t) {
|
|
1137
1207
|
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
1138
1208
|
}
|
|
1139
|
-
var
|
|
1209
|
+
var Q = {
|
|
1140
1210
|
widthFill: 0,
|
|
1141
1211
|
heightFill: 0,
|
|
1142
1212
|
limitingFill: 0,
|
|
1143
1213
|
areaFill: 0,
|
|
1144
1214
|
aspectRatio: 1
|
|
1145
1215
|
};
|
|
1146
|
-
function
|
|
1147
|
-
let r =
|
|
1216
|
+
function ct(e, t, n) {
|
|
1217
|
+
let r = X(e), i = r.map(({ x: e }) => e), a = r.map(({ y: e }) => e), o = (Math.max(...i) - Math.min(...i)) / Math.max(1, t), s = (Math.max(...a) - Math.min(...a)) / Math.max(1, n), [c, l, u, d] = r, f = Math.max(Z(c, l), Z(d, u)), p = Math.max(Z(c, d), Z(l, u));
|
|
1148
1218
|
return {
|
|
1149
1219
|
widthFill: o,
|
|
1150
1220
|
heightFill: s,
|
|
1151
1221
|
limitingFill: Math.max(o, s),
|
|
1152
|
-
areaFill:
|
|
1222
|
+
areaFill: st(r) / Math.max(1, t * n),
|
|
1153
1223
|
aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
|
|
1154
1224
|
};
|
|
1155
1225
|
}
|
|
1156
|
-
function
|
|
1226
|
+
function lt(e, t, n, r = {}) {
|
|
1157
1227
|
let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
|
|
1158
1228
|
if (e.aspectRatio < a) return i;
|
|
1159
1229
|
let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
|
|
1160
1230
|
return Math.min(o ?? i + .08, 1 - n * 2);
|
|
1161
1231
|
}
|
|
1162
|
-
function
|
|
1232
|
+
function ut(e, t, n = {}) {
|
|
1163
1233
|
let r = n.confidenceThreshold ?? .72;
|
|
1164
1234
|
if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
|
|
1165
1235
|
hint: "Place the document in the frame",
|
|
1166
1236
|
reason: "place-document",
|
|
1167
1237
|
fillRatio: 0,
|
|
1168
|
-
fill:
|
|
1238
|
+
fill: Q,
|
|
1169
1239
|
readyForAutoCapture: !1
|
|
1170
1240
|
};
|
|
1171
|
-
let i =
|
|
1241
|
+
let i = X(e.quad), a = ct(e.quad, e.sourceWidth, e.sourceHeight), o = a.limitingFill, s = t.previouslyReady ? n.exitEdgeMarginRatio ?? .005 : n.edgeMarginRatio ?? .015, c = e.sourceWidth * s, l = e.sourceHeight * s;
|
|
1172
1242
|
if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
|
|
1173
1243
|
hint: "Move farther away",
|
|
1174
1244
|
reason: "move-farther-away",
|
|
@@ -1176,14 +1246,14 @@ function $e(e, t, n = {}) {
|
|
|
1176
1246
|
fill: a,
|
|
1177
1247
|
readyForAutoCapture: !1
|
|
1178
1248
|
};
|
|
1179
|
-
let [u, d, f, p] = i, m =
|
|
1249
|
+
let [u, d, f, p] = i, m = Z(u, d), h = Z(d, f), g = Z(f, p), _ = Z(p, u);
|
|
1180
1250
|
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) ? {
|
|
1181
1251
|
hint: "Hold the camera straight",
|
|
1182
1252
|
reason: "straighten-camera",
|
|
1183
1253
|
fillRatio: o,
|
|
1184
1254
|
fill: a,
|
|
1185
1255
|
readyForAutoCapture: !1
|
|
1186
|
-
} : o <
|
|
1256
|
+
} : o < lt(a, t.previouslyReady === !0, s, n) ? {
|
|
1187
1257
|
hint: "Move closer",
|
|
1188
1258
|
reason: "move-closer",
|
|
1189
1259
|
fillRatio: o,
|
|
@@ -1197,7 +1267,7 @@ function $e(e, t, n = {}) {
|
|
|
1197
1267
|
readyForAutoCapture: t.ready
|
|
1198
1268
|
};
|
|
1199
1269
|
}
|
|
1200
|
-
var
|
|
1270
|
+
var $ = class {
|
|
1201
1271
|
previous;
|
|
1202
1272
|
count = 0;
|
|
1203
1273
|
ready = !1;
|
|
@@ -1214,8 +1284,8 @@ var et = class {
|
|
|
1214
1284
|
ready: !1,
|
|
1215
1285
|
movement: Infinity
|
|
1216
1286
|
};
|
|
1217
|
-
let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...
|
|
1218
|
-
let r =
|
|
1287
|
+
let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...X(e.quad).map((e, n) => {
|
|
1288
|
+
let r = X(this.previous)[n];
|
|
1219
1289
|
return Math.hypot(e.x - r.x, e.y - r.y) / Math.max(1, t);
|
|
1220
1290
|
})) : Infinity, r = this.options.exitCornerTolerance ?? Math.max(this.options.cornerTolerance, .036);
|
|
1221
1291
|
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, {
|
|
@@ -1225,14 +1295,14 @@ var et = class {
|
|
|
1225
1295
|
};
|
|
1226
1296
|
}
|
|
1227
1297
|
};
|
|
1228
|
-
function
|
|
1298
|
+
function dt(e, n) {
|
|
1229
1299
|
let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
|
|
1230
1300
|
i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
|
|
1231
1301
|
let a = i.getContext("2d");
|
|
1232
1302
|
if (!a) throw t();
|
|
1233
1303
|
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
1234
1304
|
}
|
|
1235
|
-
function
|
|
1305
|
+
function ft() {
|
|
1236
1306
|
let e = window.AudioContext ?? window.webkitAudioContext;
|
|
1237
1307
|
if (!e) return;
|
|
1238
1308
|
let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
|
|
@@ -1243,13 +1313,13 @@ function nt() {
|
|
|
1243
1313
|
let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
|
|
1244
1314
|
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();
|
|
1245
1315
|
}
|
|
1246
|
-
async function
|
|
1316
|
+
async function pt(e) {
|
|
1247
1317
|
let t = document.createElement("video");
|
|
1248
1318
|
return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
|
|
1249
1319
|
}
|
|
1250
|
-
async function
|
|
1320
|
+
async function mt(t) {
|
|
1251
1321
|
await x("scan");
|
|
1252
|
-
let n =
|
|
1322
|
+
let n = at(t.autoCapture), r = new $({
|
|
1253
1323
|
stableFrames: t.stableFrames ?? 4,
|
|
1254
1324
|
confidenceThreshold: t.confidenceThreshold ?? .72,
|
|
1255
1325
|
cornerTolerance: t.cornerTolerance ?? .024,
|
|
@@ -1258,14 +1328,14 @@ async function it(t) {
|
|
|
1258
1328
|
minDimension: 220,
|
|
1259
1329
|
maxAnalysisDimension: 520,
|
|
1260
1330
|
...t.detection
|
|
1261
|
-
}, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await
|
|
1331
|
+
}, s = typeof MediaStream < "u" && t.source instanceof MediaStream ? await pt(t.source) : t.source, c = !0, l = !1, u = !1, d = 0, f, p = "", m = 0, h = {
|
|
1262
1332
|
state: "detecting",
|
|
1263
1333
|
confidence: 0,
|
|
1264
1334
|
guidance: {
|
|
1265
1335
|
hint: "Place the document in the frame",
|
|
1266
1336
|
reason: "place-document",
|
|
1267
1337
|
fillRatio: 0,
|
|
1268
|
-
fill:
|
|
1338
|
+
fill: Q,
|
|
1269
1339
|
readyForAutoCapture: !1
|
|
1270
1340
|
},
|
|
1271
1341
|
lighting: {
|
|
@@ -1275,10 +1345,10 @@ async function it(t) {
|
|
|
1275
1345
|
stableFrames: 0,
|
|
1276
1346
|
requiredStableFrames: t.stableFrames ?? 4,
|
|
1277
1347
|
autoCapture: { ...n }
|
|
1278
|
-
}, g = () => s instanceof HTMLCanvasElement ?
|
|
1348
|
+
}, g = () => s instanceof HTMLCanvasElement ? dt(s, i) : Y(s, i), _ = (e) => {
|
|
1279
1349
|
h = e, t.onStatus?.(e);
|
|
1280
1350
|
}, v = (e) => {
|
|
1281
|
-
let t =
|
|
1351
|
+
let t = ot(e, s instanceof HTMLVideoElement ? {
|
|
1282
1352
|
width: s.videoWidth,
|
|
1283
1353
|
height: s.videoHeight
|
|
1284
1354
|
} : {
|
|
@@ -1293,11 +1363,11 @@ async function it(t) {
|
|
|
1293
1363
|
l = !0;
|
|
1294
1364
|
let n;
|
|
1295
1365
|
try {
|
|
1296
|
-
n = await
|
|
1366
|
+
n = await it(t.captureFrame ?? g, () => {
|
|
1297
1367
|
_({
|
|
1298
1368
|
...h,
|
|
1299
1369
|
state: "captured"
|
|
1300
|
-
}), t.playShutterSound !== !1 &&
|
|
1370
|
+
}), t.playShutterSound !== !1 && ft(), y();
|
|
1301
1371
|
});
|
|
1302
1372
|
} catch (e) {
|
|
1303
1373
|
throw l = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
|
|
@@ -1311,9 +1381,9 @@ async function it(t) {
|
|
|
1311
1381
|
}, S = async () => {
|
|
1312
1382
|
if (c && !l) {
|
|
1313
1383
|
try {
|
|
1314
|
-
let e = g(), i = await
|
|
1384
|
+
let e = g(), i = await R(e, o);
|
|
1315
1385
|
f = i, v(i);
|
|
1316
|
-
let a = i.quad ?
|
|
1386
|
+
let a = i.quad ? nt(e, i.quad) : {
|
|
1317
1387
|
strong: !1,
|
|
1318
1388
|
strength: 0
|
|
1319
1389
|
}, s = a.strong ? {
|
|
@@ -1323,7 +1393,7 @@ async function it(t) {
|
|
|
1323
1393
|
} : {
|
|
1324
1394
|
castShadow: !1,
|
|
1325
1395
|
strength: a.strength
|
|
1326
|
-
}, c = r.update(i), l =
|
|
1396
|
+
}, c = r.update(i), l = ut(i, {
|
|
1327
1397
|
...c,
|
|
1328
1398
|
previouslyReady: u
|
|
1329
1399
|
}, {
|
|
@@ -1376,7 +1446,7 @@ async function it(t) {
|
|
|
1376
1446
|
hint: "Place the document in the frame",
|
|
1377
1447
|
reason: "place-document",
|
|
1378
1448
|
fillRatio: 0,
|
|
1379
|
-
fill:
|
|
1449
|
+
fill: Q,
|
|
1380
1450
|
readyForAutoCapture: !1
|
|
1381
1451
|
},
|
|
1382
1452
|
lighting: {
|
|
@@ -1405,6 +1475,6 @@ async function it(t) {
|
|
|
1405
1475
|
};
|
|
1406
1476
|
}
|
|
1407
1477
|
//#endregion
|
|
1408
|
-
export {
|
|
1478
|
+
export { we as A, b as B, qe as C, R as D, Ce as E, ie as F, e as H, ne as I, a as L, de as M, fe as N, j as O, A as P, o as R, Ee as S, pe as T, t as U, y as V, U as _, ut as a, J as b, et as c, G as d, je as f, Te as g, H as h, ct as i, B as j, z as k, Xe as l, Y as m, at as n, rt as o, ze as p, lt as r, mt as s, $ as t, $e as u, Me as v, K as w, Je as x, q as y, x as z };
|
|
1409
1479
|
|
|
1410
|
-
//# sourceMappingURL=finder-
|
|
1480
|
+
//# sourceMappingURL=finder-Dcg3mVJM.js.map
|