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