@exige/web-scanner-sdk 0.2.35 → 0.2.37
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/dist/{driver-license-CV0oawgf.js → driver-license-DWQiITx8.js} +572 -473
- package/dist/driver-license-DWQiITx8.js.map +1 -0
- package/dist/react.js +292 -284
- package/dist/react.js.map +1 -1
- package/dist/scanner-sdk.js +3 -3
- package/dist/sdk/barcode.d.ts +28 -5
- package/dist/sdk/camera.d.ts +6 -0
- package/dist/sdk/zxing-runtime.d.ts +5 -0
- package/package.json +3 -1
- package/dist/driver-license-CV0oawgf.js.map +0 -1
|
@@ -179,12 +179,12 @@ function C() {
|
|
|
179
179
|
inflight: /* @__PURE__ */ new Map()
|
|
180
180
|
}), e[S];
|
|
181
181
|
}
|
|
182
|
-
var w = C().active, T = C().listeners,
|
|
183
|
-
function
|
|
182
|
+
var w = C().active, T = C().listeners, ee = C().cache, E = C().inflight;
|
|
183
|
+
function te(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 ne() {
|
|
188
188
|
if (w.size === 0) return {
|
|
189
189
|
downloading: !1,
|
|
190
190
|
loaded: 0,
|
|
@@ -198,23 +198,23 @@ function te() {
|
|
|
198
198
|
total: n ? t : null
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
|
-
function
|
|
202
|
-
let e =
|
|
201
|
+
function re() {
|
|
202
|
+
let e = ne();
|
|
203
203
|
for (let t of T) t(e);
|
|
204
204
|
}
|
|
205
|
-
function
|
|
206
|
-
return e(
|
|
205
|
+
function ie(e) {
|
|
206
|
+
return e(ne()), T.add(e), () => {
|
|
207
207
|
T.delete(e);
|
|
208
208
|
};
|
|
209
209
|
}
|
|
210
|
-
function
|
|
210
|
+
function ae(e, t) {
|
|
211
211
|
t.done ? w.delete(e) : w.set(e, {
|
|
212
212
|
loaded: t.loaded,
|
|
213
213
|
total: t.total
|
|
214
|
-
}),
|
|
214
|
+
}), re();
|
|
215
215
|
}
|
|
216
|
-
async function
|
|
217
|
-
let n =
|
|
216
|
+
async function oe(e, t) {
|
|
217
|
+
let n = te(e);
|
|
218
218
|
if (!e.body) {
|
|
219
219
|
let r = await e.arrayBuffer();
|
|
220
220
|
return t?.({
|
|
@@ -238,31 +238,31 @@ async function ie(e, t) {
|
|
|
238
238
|
total: n
|
|
239
239
|
}), o.buffer;
|
|
240
240
|
}
|
|
241
|
-
async function
|
|
242
|
-
let r =
|
|
241
|
+
async function se(t, n) {
|
|
242
|
+
let r = ee.get(t);
|
|
243
243
|
if (r) return r.slice(0);
|
|
244
|
-
let i =
|
|
244
|
+
let i = E.get(t);
|
|
245
245
|
if (i) return i.then((e) => e.slice(0));
|
|
246
246
|
let a = (async () => {
|
|
247
|
-
|
|
247
|
+
ae(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 oe(r, (e) => ae(t, e));
|
|
254
254
|
})();
|
|
255
|
-
|
|
255
|
+
E.set(t, a);
|
|
256
256
|
try {
|
|
257
257
|
let e = await a;
|
|
258
|
-
return
|
|
258
|
+
return ee.set(t, e), e.slice(0);
|
|
259
259
|
} finally {
|
|
260
|
-
|
|
260
|
+
E.delete(t), w.has(t) && (w.delete(t), re());
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
//#endregion
|
|
264
264
|
//#region src/sdk/camera.ts
|
|
265
|
-
function
|
|
265
|
+
function ce(e, t) {
|
|
266
266
|
let { engine: n } = t;
|
|
267
267
|
return [
|
|
268
268
|
`${e}:`,
|
|
@@ -277,9 +277,9 @@ function oe(e, t) {
|
|
|
277
277
|
` torch: ${t.torch.mode} supported=${t.torch.supported} on=${t.torch.on}`
|
|
278
278
|
].join("\n");
|
|
279
279
|
}
|
|
280
|
-
function
|
|
280
|
+
function le(e) {
|
|
281
281
|
let t = ["Exige scanner capture report", `time: ${e.capturedAt ?? (/* @__PURE__ */ new Date()).toISOString()}`];
|
|
282
|
-
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(
|
|
282
|
+
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(ce("shutter", e.shutter)), e.live && t.push(ce("live", e.live)), e.finder) {
|
|
283
283
|
let n = e.finder;
|
|
284
284
|
t.push([
|
|
285
285
|
"finder:",
|
|
@@ -296,7 +296,7 @@ function se(e) {
|
|
|
296
296
|
}
|
|
297
297
|
return `${t.join("\n")}\n`;
|
|
298
298
|
}
|
|
299
|
-
function
|
|
299
|
+
function D(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
|
|
300
300
|
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;
|
|
301
301
|
return {
|
|
302
302
|
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",
|
|
@@ -305,40 +305,40 @@ function k(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof nav
|
|
|
305
305
|
userAgent: e
|
|
306
306
|
};
|
|
307
307
|
}
|
|
308
|
-
function
|
|
308
|
+
function ue(e) {
|
|
309
309
|
return /Android/i.test(e.userAgent) && !e.iosWebKit;
|
|
310
310
|
}
|
|
311
|
-
function
|
|
312
|
-
return e.engine === "webkit" && !
|
|
311
|
+
function de(e = D()) {
|
|
312
|
+
return e.engine === "webkit" && !ue(e);
|
|
313
313
|
}
|
|
314
|
-
function
|
|
315
|
-
return e === "system-camera" || e !== "live" &&
|
|
314
|
+
function fe(e = "auto", t = D()) {
|
|
315
|
+
return e === "system-camera" || e !== "live" && ue(t);
|
|
316
316
|
}
|
|
317
|
-
function
|
|
317
|
+
function pe(e, t) {
|
|
318
318
|
return t && !e.iosWebKit;
|
|
319
319
|
}
|
|
320
|
-
function
|
|
320
|
+
function me(e, t) {
|
|
321
321
|
if (!e || !Number.isFinite(e)) return;
|
|
322
322
|
let n = t?.max;
|
|
323
323
|
if (!n || !Number.isFinite(n)) return Math.round(e);
|
|
324
324
|
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;
|
|
325
325
|
return Math.round(Math.min(n, Math.max(r, a)));
|
|
326
326
|
}
|
|
327
|
-
function
|
|
328
|
-
let t =
|
|
327
|
+
function he(e) {
|
|
328
|
+
let t = me(e?.imageWidth?.max ?? 0, e?.imageWidth), n = me(e?.imageHeight?.max ?? 0, e?.imageHeight);
|
|
329
329
|
if (t && n) return t >= n ? { imageWidth: t } : { imageHeight: n };
|
|
330
330
|
if (t) return { imageWidth: t };
|
|
331
331
|
if (n) return { imageHeight: n };
|
|
332
332
|
}
|
|
333
|
-
function
|
|
333
|
+
function ge(e, t) {
|
|
334
334
|
return !e.width || !e.height || !t.width || !t.height ? !1 : e.width * e.height > t.width * t.height * 1.15;
|
|
335
335
|
}
|
|
336
|
-
function
|
|
336
|
+
function _e(e, t) {
|
|
337
337
|
if (!e.width || !e.height || !t.width || !t.height) return !1;
|
|
338
338
|
let n = e.width / e.height / (t.width / t.height);
|
|
339
339
|
return n > .97 && n < 1.03;
|
|
340
340
|
}
|
|
341
|
-
var
|
|
341
|
+
var ve = 10, ye = class {
|
|
342
342
|
on = !1;
|
|
343
343
|
darkCount = 0;
|
|
344
344
|
brightCount = 0;
|
|
@@ -361,7 +361,7 @@ var he = 10, ge = class {
|
|
|
361
361
|
return this.on;
|
|
362
362
|
}
|
|
363
363
|
};
|
|
364
|
-
function
|
|
364
|
+
function be(e, t) {
|
|
365
365
|
return t ? e === "alwaysOn" || e === "alwaysOff" ? {
|
|
366
366
|
mode: e,
|
|
367
367
|
supported: !0,
|
|
@@ -385,37 +385,40 @@ function _e(e, t) {
|
|
|
385
385
|
automatic: e === "auto"
|
|
386
386
|
};
|
|
387
387
|
}
|
|
388
|
-
function
|
|
388
|
+
function O(e) {
|
|
389
389
|
let t = Math.floor(e.length / 4);
|
|
390
390
|
if (!t) return 0;
|
|
391
391
|
let n = 0;
|
|
392
392
|
for (let r = 0; r < t * 4; r += 4) n += e[r] * .299 + e[r + 1] * .587 + e[r + 2] * .114;
|
|
393
393
|
return n / t;
|
|
394
394
|
}
|
|
395
|
-
function
|
|
395
|
+
function k(e) {
|
|
396
|
+
return !e.width || !e.height || Se(e, e.width, e.height) <= 10;
|
|
397
|
+
}
|
|
398
|
+
function xe(e, t = 10) {
|
|
396
399
|
if (e.length < 4) return !0;
|
|
397
400
|
let n = Math.floor(e.length / 4), r = 0;
|
|
398
401
|
for (let i = 0; i < n * 4; i += 4) e[i] * .299 + e[i + 1] * .587 + e[i + 2] * .114 > t * 2 && (r += 1);
|
|
399
|
-
return
|
|
402
|
+
return O(e) <= t && r / n < .01;
|
|
400
403
|
}
|
|
401
|
-
function
|
|
404
|
+
function Se(e, t, n) {
|
|
402
405
|
if (!t || !n) return 0;
|
|
403
406
|
let r = document.createElement("canvas");
|
|
404
407
|
r.width = Math.min(32, t), r.height = Math.min(32, n);
|
|
405
408
|
let i = r.getContext("2d", { willReadFrequently: !0 });
|
|
406
|
-
return i ? (i.drawImage(e, 0, 0, r.width, r.height),
|
|
409
|
+
return i ? (i.drawImage(e, 0, 0, r.width, r.height), O(i.getImageData(0, 0, r.width, r.height).data)) : 0;
|
|
407
410
|
}
|
|
408
|
-
function
|
|
409
|
-
return
|
|
411
|
+
function Ce(e) {
|
|
412
|
+
return Se(e, e.width, e.height);
|
|
410
413
|
}
|
|
411
|
-
function
|
|
414
|
+
function we(e, t = 120) {
|
|
412
415
|
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 = () => {
|
|
413
416
|
a && (o = i ? e.requestVideoFrameCallback(f) : requestAnimationFrame(f));
|
|
414
417
|
};
|
|
415
418
|
function f() {
|
|
416
419
|
if (!a) return;
|
|
417
420
|
let { videoWidth: i, videoHeight: o } = e, f = performance.now();
|
|
418
|
-
r && i && o && f - s >= t && (s = f, l =
|
|
421
|
+
r && i && o && f - s >= t && (s = f, l = Se(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();
|
|
419
422
|
}
|
|
420
423
|
return d(), {
|
|
421
424
|
stop() {
|
|
@@ -427,14 +430,34 @@ function xe(e, t = 120) {
|
|
|
427
430
|
getMirrorAgeMs: () => c ? performance.now() - c : Infinity
|
|
428
431
|
};
|
|
429
432
|
}
|
|
430
|
-
function
|
|
433
|
+
function Te(e) {
|
|
431
434
|
let t = document.createElement("canvas");
|
|
432
435
|
return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
|
|
433
436
|
}
|
|
434
|
-
function
|
|
437
|
+
function Ee(e, n) {
|
|
438
|
+
let r = j(e.width, e.height, n);
|
|
439
|
+
if (r.width === e.width && r.height === e.height) return Te(e);
|
|
440
|
+
let i = document.createElement("canvas");
|
|
441
|
+
i.width = r.width, i.height = r.height;
|
|
442
|
+
let a = i.getContext("2d");
|
|
443
|
+
if (!a) throw t();
|
|
444
|
+
return a.imageSmoothingEnabled = !0, "imageSmoothingQuality" in a && (a.imageSmoothingQuality = "high"), a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
445
|
+
}
|
|
446
|
+
function De(e, t, n) {
|
|
447
|
+
try {
|
|
448
|
+
let t = M(e, n);
|
|
449
|
+
if (!k(t)) return t;
|
|
450
|
+
} catch {}
|
|
451
|
+
let r = t.getFrame();
|
|
452
|
+
if (!r) throw Error("The camera is not ready to capture a frame.");
|
|
453
|
+
let i = Ee(r, n);
|
|
454
|
+
if (k(i)) throw Error("The camera preview produced no visible pixels.");
|
|
455
|
+
return i;
|
|
456
|
+
}
|
|
457
|
+
function Oe(e) {
|
|
435
458
|
return e.engine === "blink";
|
|
436
459
|
}
|
|
437
|
-
function
|
|
460
|
+
function A(e = {}, t = D()) {
|
|
438
461
|
let n = { ideal: e.idealWidth ?? 3840 }, r = { ideal: e.idealHeight ?? 2160 };
|
|
439
462
|
e.maxWidth && (n.max = e.maxWidth), e.maxHeight && (r.max = e.maxHeight);
|
|
440
463
|
let i = {
|
|
@@ -446,20 +469,20 @@ function M(e = {}, t = k()) {
|
|
|
446
469
|
max: e.maxFrameRate ?? 30
|
|
447
470
|
}
|
|
448
471
|
};
|
|
449
|
-
return
|
|
472
|
+
return Oe(t) && (i.resizeMode = { ideal: "none" }), {
|
|
450
473
|
audio: !1,
|
|
451
474
|
video: i
|
|
452
475
|
};
|
|
453
476
|
}
|
|
454
|
-
function
|
|
477
|
+
function j(e, t, n) {
|
|
455
478
|
let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
|
|
456
479
|
return {
|
|
457
480
|
width: Math.max(1, Math.round(e * r)),
|
|
458
481
|
height: Math.max(1, Math.round(t * r))
|
|
459
482
|
};
|
|
460
483
|
}
|
|
461
|
-
var
|
|
462
|
-
function
|
|
484
|
+
var ke = 4096;
|
|
485
|
+
function Ae(e, t) {
|
|
463
486
|
let n = e.width, r = e.height, i = t?.width?.max, a = t?.height?.max;
|
|
464
487
|
if (!n || !r || !i || !a) return;
|
|
465
488
|
let o = Math.min(i / n, a / r);
|
|
@@ -468,13 +491,13 @@ function Ee(e, t) {
|
|
|
468
491
|
height: { ideal: Math.round(r * o) }
|
|
469
492
|
};
|
|
470
493
|
}
|
|
471
|
-
async function
|
|
472
|
-
let t =
|
|
494
|
+
async function je(e) {
|
|
495
|
+
let t = Ae(e.getSettings(), typeof e.getCapabilities == "function" ? e.getCapabilities() : void 0);
|
|
473
496
|
if (t) try {
|
|
474
497
|
await e.applyConstraints(t);
|
|
475
498
|
} catch {}
|
|
476
499
|
}
|
|
477
|
-
async function
|
|
500
|
+
async function Me(e) {
|
|
478
501
|
try {
|
|
479
502
|
return await createImageBitmap(e, {
|
|
480
503
|
imageOrientation: "from-image",
|
|
@@ -484,7 +507,7 @@ async function Oe(e) {
|
|
|
484
507
|
return await createImageBitmap(e);
|
|
485
508
|
}
|
|
486
509
|
}
|
|
487
|
-
async function
|
|
510
|
+
async function Ne(e) {
|
|
488
511
|
try {
|
|
489
512
|
await e.applyConstraints({ advanced: [{ pointsOfInterest: [{
|
|
490
513
|
x: .5,
|
|
@@ -492,25 +515,25 @@ async function ke(e) {
|
|
|
492
515
|
}] }] }), await new Promise((e) => window.setTimeout(e, 180));
|
|
493
516
|
} catch {}
|
|
494
517
|
}
|
|
495
|
-
async function
|
|
496
|
-
let n = await
|
|
518
|
+
async function Pe(e) {
|
|
519
|
+
let n = await Me(e), r = j(n.width, n.height, ke), i = document.createElement("canvas");
|
|
497
520
|
i.width = r.width, i.height = r.height;
|
|
498
521
|
let a = i.getContext("2d");
|
|
499
522
|
if (!a) throw n.close?.(), t();
|
|
500
523
|
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;
|
|
501
524
|
}
|
|
502
|
-
async function
|
|
525
|
+
async function Fe(e) {
|
|
503
526
|
let t = globalThis.ImageCapture;
|
|
504
527
|
if (!t) return;
|
|
505
|
-
await
|
|
506
|
-
let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i =
|
|
528
|
+
await Ne(e);
|
|
529
|
+
let n = new t(e), r = n.getPhotoCapabilities ? await n.getPhotoCapabilities() : void 0, i = he(r), a;
|
|
507
530
|
try {
|
|
508
531
|
a = await n.takePhoto(i);
|
|
509
532
|
} catch {
|
|
510
533
|
a = await n.takePhoto();
|
|
511
534
|
}
|
|
512
535
|
return {
|
|
513
|
-
frame: await
|
|
536
|
+
frame: await Pe(a),
|
|
514
537
|
requested: i,
|
|
515
538
|
photoMax: {
|
|
516
539
|
width: r?.imageWidth?.max,
|
|
@@ -518,42 +541,42 @@ async function je(e) {
|
|
|
518
541
|
}
|
|
519
542
|
};
|
|
520
543
|
}
|
|
521
|
-
function
|
|
544
|
+
function M(e, n) {
|
|
522
545
|
if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
|
|
523
|
-
let r =
|
|
546
|
+
let r = j(e.videoWidth, e.videoHeight, n), i = document.createElement("canvas");
|
|
524
547
|
i.width = r.width, i.height = r.height;
|
|
525
548
|
let a = i.getContext("2d");
|
|
526
549
|
if (!a) throw t();
|
|
527
550
|
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
528
551
|
}
|
|
529
|
-
function
|
|
530
|
-
let t =
|
|
531
|
-
return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [
|
|
532
|
-
|
|
552
|
+
function Ie(e) {
|
|
553
|
+
let t = D();
|
|
554
|
+
return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [A(e, t)] : [
|
|
555
|
+
A({
|
|
533
556
|
...e,
|
|
534
557
|
idealWidth: 3840,
|
|
535
558
|
idealHeight: 2160
|
|
536
559
|
}, t),
|
|
537
|
-
|
|
560
|
+
A({
|
|
538
561
|
...e,
|
|
539
562
|
idealWidth: 2560,
|
|
540
563
|
idealHeight: 1440
|
|
541
564
|
}, t),
|
|
542
|
-
|
|
565
|
+
A({
|
|
543
566
|
...e,
|
|
544
567
|
idealWidth: 1920,
|
|
545
568
|
idealHeight: 1080
|
|
546
569
|
}, t)
|
|
547
570
|
];
|
|
548
571
|
}
|
|
549
|
-
async function
|
|
572
|
+
async function Le(t, n = {}) {
|
|
550
573
|
await x("scan");
|
|
551
574
|
let r = n.torch ?? "alwaysOff";
|
|
552
575
|
if (r !== "alwaysOff" && await x("torch"), !window.isSecureContext && location.hostname !== "localhost") throw new e("secure-context", "Camera access requires HTTPS.");
|
|
553
576
|
if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
|
|
554
577
|
t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.setAttribute("playsinline", "");
|
|
555
578
|
let i, a;
|
|
556
|
-
for (let e of
|
|
579
|
+
for (let e of Ie(n)) try {
|
|
557
580
|
i = await navigator.mediaDevices.getUserMedia(e);
|
|
558
581
|
break;
|
|
559
582
|
} catch (e) {
|
|
@@ -566,8 +589,8 @@ async function Ne(t, n = {}) {
|
|
|
566
589
|
for (let e of i.getTracks()) e.stop();
|
|
567
590
|
throw Error("The camera did not provide a video track.");
|
|
568
591
|
}
|
|
569
|
-
await
|
|
570
|
-
let s =
|
|
592
|
+
await je(o);
|
|
593
|
+
let s = we(t), c = "ImageCapture" in globalThis, l = be(r, (typeof o.getCapabilities == "function" ? o.getCapabilities() : void 0)?.torch === !0), u = !1, d = async (e) => {
|
|
571
594
|
if (!l.supported || o.readyState !== "live") return !1;
|
|
572
595
|
try {
|
|
573
596
|
return await o.applyConstraints({ advanced: [{ torch: e }] }), l = {
|
|
@@ -585,7 +608,7 @@ async function Ne(t, n = {}) {
|
|
|
585
608
|
}
|
|
586
609
|
};
|
|
587
610
|
l.on && await d(!0);
|
|
588
|
-
let f = r === "auto" && l.supported ? new
|
|
611
|
+
let f = r === "auto" && l.supported ? new ye() : void 0, p = f ? window.setInterval(() => {
|
|
589
612
|
if (u || !l.supported) return;
|
|
590
613
|
let e = f.update(s.getLiveLuminance());
|
|
591
614
|
e !== void 0 && e !== l.on && (u = !0, d(e).finally(() => {
|
|
@@ -611,7 +634,7 @@ async function Ne(t, n = {}) {
|
|
|
611
634
|
torchSupported: l.supported,
|
|
612
635
|
torchOn: l.on,
|
|
613
636
|
torch: { ...l },
|
|
614
|
-
engine:
|
|
637
|
+
engine: D()
|
|
615
638
|
};
|
|
616
639
|
};
|
|
617
640
|
return {
|
|
@@ -625,17 +648,34 @@ async function Ne(t, n = {}) {
|
|
|
625
648
|
get torchOn() {
|
|
626
649
|
return l.on;
|
|
627
650
|
},
|
|
628
|
-
capture: (e) =>
|
|
651
|
+
capture: (e) => De(t, s, e),
|
|
652
|
+
async captureLiveFrame(e) {
|
|
653
|
+
let n = globalThis.ImageCapture;
|
|
654
|
+
if (n) try {
|
|
655
|
+
let t = await new n(o).grabFrame?.();
|
|
656
|
+
if (t) {
|
|
657
|
+
let n = j(t.width, t.height, e), r = document.createElement("canvas");
|
|
658
|
+
r.width = n.width, r.height = n.height;
|
|
659
|
+
let i = r.getContext("2d");
|
|
660
|
+
if (i && (i.imageSmoothingEnabled = !0, "imageSmoothingQuality" in i && (i.imageSmoothingQuality = "high"), i.drawImage(t, 0, 0, r.width, r.height)), t.close?.(), r.width && !k(r)) return r;
|
|
661
|
+
}
|
|
662
|
+
} catch {}
|
|
663
|
+
try {
|
|
664
|
+
return De(t, s, e);
|
|
665
|
+
} catch {
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
},
|
|
629
669
|
async capturePhoto() {
|
|
630
670
|
let e, n = 0;
|
|
631
671
|
try {
|
|
632
|
-
e =
|
|
672
|
+
e = M(t), n = Ce(e);
|
|
633
673
|
} catch {
|
|
634
674
|
e = void 0;
|
|
635
675
|
}
|
|
636
676
|
let r = s.getFrame(), i, a = !1, l = !1, u, d;
|
|
637
|
-
if (
|
|
638
|
-
let e = await
|
|
677
|
+
if (pe(D(), c)) try {
|
|
678
|
+
let e = await Fe(o);
|
|
639
679
|
i = e?.frame, u = e?.requested, d = e?.photoMax;
|
|
640
680
|
} catch {
|
|
641
681
|
a = !0, i = void 0;
|
|
@@ -643,14 +683,14 @@ async function Ne(t, n = {}) {
|
|
|
643
683
|
let f = {
|
|
644
684
|
width: t.videoWidth,
|
|
645
685
|
height: t.videoHeight
|
|
646
|
-
}, p = i ?
|
|
686
|
+
}, p = i ? Ce(i) : 0, h = !!(i && p > 10 && ge(i, f));
|
|
647
687
|
if (i && p > 10 && !h && (l = !0), h && i) return console.info("[exige-scanner] capture", {
|
|
648
688
|
method: "image-capture",
|
|
649
689
|
frame: `${i.width}×${i.height}`,
|
|
650
690
|
video: `${t.videoWidth}×${t.videoHeight}`,
|
|
651
691
|
photoMax: d ? `${d.width ?? "—"}×${d.height ?? "—"}` : void 0,
|
|
652
692
|
photoRequest: u,
|
|
653
|
-
aspectMatch:
|
|
693
|
+
aspectMatch: _e(i, f)
|
|
654
694
|
}), {
|
|
655
695
|
frame: i,
|
|
656
696
|
method: "image-capture",
|
|
@@ -658,7 +698,7 @@ async function Ne(t, n = {}) {
|
|
|
658
698
|
luminance: p,
|
|
659
699
|
diagnostics: m()
|
|
660
700
|
};
|
|
661
|
-
let g = e && n > 10 ? e : void 0, _ = g ?? (r ?
|
|
701
|
+
let g = e && n > 10 ? e : void 0, _ = g ?? (r ? Te(r) : void 0);
|
|
662
702
|
if (!_) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
|
|
663
703
|
let v = l ? "image-capture-preview-size" : i ? "image-capture-empty" : a ? "image-capture-failed" : g ? void 0 : "video-frame-empty";
|
|
664
704
|
return console.info("[exige-scanner] capture", {
|
|
@@ -690,13 +730,13 @@ async function Ne(t, n = {}) {
|
|
|
690
730
|
}
|
|
691
731
|
};
|
|
692
732
|
}
|
|
693
|
-
function
|
|
733
|
+
function Re() {
|
|
694
734
|
let e = typeof navigator > "u" ? void 0 : navigator.userActivation;
|
|
695
735
|
return !e || e.isActive;
|
|
696
736
|
}
|
|
697
|
-
async function
|
|
737
|
+
async function ze() {
|
|
698
738
|
let e = document.createElement("input");
|
|
699
|
-
return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"),
|
|
739
|
+
return e.type = "file", e.accept = "image/*", e.capture = "environment", e.setAttribute("capture", "environment"), Pe(await new Promise((t, n) => {
|
|
700
740
|
e.addEventListener("change", () => {
|
|
701
741
|
let r = e.files?.[0];
|
|
702
742
|
r ? t(r) : n(/* @__PURE__ */ Error("No photo was selected."));
|
|
@@ -707,20 +747,20 @@ async function Fe() {
|
|
|
707
747
|
}
|
|
708
748
|
//#endregion
|
|
709
749
|
//#region src/sdk/ort-cdn.ts
|
|
710
|
-
var
|
|
711
|
-
`${
|
|
712
|
-
function
|
|
750
|
+
var Be = "1.30.0";
|
|
751
|
+
`${Be}`, `${Be}`;
|
|
752
|
+
function Ve(e) {
|
|
713
753
|
return !e.ok && e.status !== 206 ? !1 : !(e.headers.get("content-type") ?? "").toLowerCase().includes("text/html");
|
|
714
754
|
}
|
|
715
|
-
async function
|
|
755
|
+
async function He(e, t = fetch) {
|
|
716
756
|
if (!e) return !1;
|
|
717
757
|
try {
|
|
718
758
|
let n = await t(e, { method: "HEAD" });
|
|
719
|
-
if (
|
|
759
|
+
if (Ve(n)) return !0;
|
|
720
760
|
if (n.status === 404 || n.status === 410) return !1;
|
|
721
761
|
} catch {}
|
|
722
762
|
try {
|
|
723
|
-
return
|
|
763
|
+
return Ve(await t(e, {
|
|
724
764
|
method: "GET",
|
|
725
765
|
headers: { Range: "bytes=0-63" }
|
|
726
766
|
}));
|
|
@@ -730,29 +770,29 @@ async function Re(e, t = fetch) {
|
|
|
730
770
|
}
|
|
731
771
|
//#endregion
|
|
732
772
|
//#region src/sdk/ort-runtime.ts
|
|
733
|
-
var
|
|
734
|
-
function
|
|
773
|
+
var Ue = new URL("./assets/ort-wasm-simd-threaded.jsep.wasm", import.meta.url), We = new URL("./assets/ort-wasm-simd-threaded.jsep.mjs", import.meta.url);
|
|
774
|
+
function Ge() {
|
|
735
775
|
return {
|
|
736
|
-
wasm:
|
|
737
|
-
mjs:
|
|
776
|
+
wasm: Ue.href,
|
|
777
|
+
mjs: We.href
|
|
738
778
|
};
|
|
739
779
|
}
|
|
740
|
-
function
|
|
741
|
-
return typeof e == "string" ? e.trim() ||
|
|
780
|
+
function Ke(e) {
|
|
781
|
+
return typeof e == "string" ? e.trim() || Ge() : e?.wasm.trim() && e.mjs.trim() ? {
|
|
742
782
|
wasm: e.wasm.trim(),
|
|
743
783
|
mjs: e.mjs.trim()
|
|
744
|
-
} :
|
|
784
|
+
} : Ge();
|
|
745
785
|
}
|
|
746
786
|
//#endregion
|
|
747
787
|
//#region src/sdk/image.ts
|
|
748
|
-
function
|
|
788
|
+
function qe(e, t, n) {
|
|
749
789
|
let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
|
|
750
790
|
return {
|
|
751
791
|
width: Math.max(1, Math.round(e * r)),
|
|
752
792
|
height: Math.max(1, Math.round(t * r))
|
|
753
793
|
};
|
|
754
794
|
}
|
|
755
|
-
async function
|
|
795
|
+
async function Je(e) {
|
|
756
796
|
let t = URL.createObjectURL(e);
|
|
757
797
|
try {
|
|
758
798
|
let e = new Image();
|
|
@@ -761,26 +801,26 @@ async function We(e) {
|
|
|
761
801
|
URL.revokeObjectURL(t);
|
|
762
802
|
}
|
|
763
803
|
}
|
|
764
|
-
async function
|
|
804
|
+
async function N(e, n = {}) {
|
|
765
805
|
if (e instanceof HTMLCanvasElement && n.cloneCanvas === !1 && !n.maxDimension) return e;
|
|
766
806
|
let r = document.createElement("canvas"), i = r.getContext("2d", { willReadFrequently: !0 });
|
|
767
807
|
if (!i) throw t();
|
|
768
808
|
if (e instanceof Blob) {
|
|
769
809
|
if ("createImageBitmap" in window) try {
|
|
770
|
-
let t = await createImageBitmap(e), a =
|
|
810
|
+
let t = await createImageBitmap(e), a = qe(t.width, t.height, n.maxDimension);
|
|
771
811
|
return r.width = a.width, r.height = a.height, i.drawImage(t, 0, 0, a.width, a.height), t.close(), r;
|
|
772
812
|
} catch {}
|
|
773
|
-
e = await
|
|
813
|
+
e = await Je(e);
|
|
774
814
|
}
|
|
775
815
|
let a = e instanceof HTMLImageElement ? e.naturalWidth : e.width, o = e instanceof HTMLImageElement ? e.naturalHeight : e.height;
|
|
776
816
|
if (!a || !o) throw Error("The image has no readable dimensions.");
|
|
777
|
-
let s =
|
|
817
|
+
let s = qe(a, o, n.maxDimension);
|
|
778
818
|
return r.width = s.width, r.height = s.height, i.drawImage(e, 0, 0, s.width, s.height), r;
|
|
779
819
|
}
|
|
780
|
-
function
|
|
820
|
+
function Ye(e, t = "image/png", n = .92) {
|
|
781
821
|
return new Promise((r, i) => e.toBlob((e) => e ? r(e) : i(/* @__PURE__ */ Error("Could not encode the image.")), t, n));
|
|
782
822
|
}
|
|
783
|
-
function
|
|
823
|
+
function Xe(e, t, n) {
|
|
784
824
|
let r = Math.max(0, Math.min(t, e.x)), i = Math.max(0, Math.min(n, e.y));
|
|
785
825
|
return {
|
|
786
826
|
x: r,
|
|
@@ -791,20 +831,20 @@ function Ke(e, t, n) {
|
|
|
791
831
|
}
|
|
792
832
|
//#endregion
|
|
793
833
|
//#region src/sdk/scan.ts
|
|
794
|
-
var
|
|
795
|
-
function
|
|
834
|
+
var Ze = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx", Qe = 1280;
|
|
835
|
+
function $e(e, t, n) {
|
|
796
836
|
if (n) return n;
|
|
797
|
-
let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a =
|
|
798
|
-
return i >= 1.6 ? Math.min(r, Math.max(a,
|
|
837
|
+
let r = Math.max(e, t), i = r / Math.max(1, Math.min(e, t)), a = at() ? 560 : 900;
|
|
838
|
+
return i >= 1.6 ? Math.min(r, Math.max(a, Qe)) : a;
|
|
799
839
|
}
|
|
800
|
-
function
|
|
840
|
+
function et(e) {
|
|
801
841
|
return e?.trim() || "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
|
|
802
842
|
}
|
|
803
|
-
var
|
|
804
|
-
function
|
|
843
|
+
var tt = 3, P, nt = 0, F = /* @__PURE__ */ new Map();
|
|
844
|
+
function I(e, t) {
|
|
805
845
|
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
806
846
|
}
|
|
807
|
-
function
|
|
847
|
+
function rt(e) {
|
|
808
848
|
return {
|
|
809
849
|
...e,
|
|
810
850
|
edges: {
|
|
@@ -827,7 +867,7 @@ function $e(e) {
|
|
|
827
867
|
}
|
|
828
868
|
};
|
|
829
869
|
}
|
|
830
|
-
function
|
|
870
|
+
function it(e, t) {
|
|
831
871
|
let n = (e) => ({
|
|
832
872
|
x: e.x / t,
|
|
833
873
|
y: e.y / t
|
|
@@ -839,43 +879,43 @@ function et(e, t) {
|
|
|
839
879
|
bottomLeft: n(e.bottomLeft)
|
|
840
880
|
};
|
|
841
881
|
}
|
|
842
|
-
function
|
|
882
|
+
function at() {
|
|
843
883
|
return typeof navigator > "u" ? !1 : navigator.maxTouchPoints > 0 || navigator.hardwareConcurrency <= 4 || typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
|
|
844
884
|
}
|
|
845
|
-
function
|
|
885
|
+
function ot(t, n, r, i) {
|
|
846
886
|
return new Promise((a, o) => {
|
|
847
|
-
|
|
887
|
+
P || (P = new Worker(new URL("./assets/document-worker.js", import.meta.url), { type: "module" }), P.onmessage = (t) => {
|
|
848
888
|
if (t.data.download?.url) {
|
|
849
|
-
|
|
889
|
+
ae(t.data.download.url, t.data.download);
|
|
850
890
|
return;
|
|
851
891
|
}
|
|
852
|
-
let n =
|
|
853
|
-
n && (
|
|
854
|
-
},
|
|
892
|
+
let n = F.get(t.data.id);
|
|
893
|
+
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.")));
|
|
894
|
+
}, P.onerror = () => {
|
|
855
895
|
let t = new e("worker", "The document worker could not start.");
|
|
856
|
-
for (let e of
|
|
857
|
-
|
|
896
|
+
for (let e of F.values()) e.reject(t);
|
|
897
|
+
F.clear(), P?.terminate(), P = void 0;
|
|
858
898
|
});
|
|
859
|
-
let s = ++
|
|
860
|
-
|
|
899
|
+
let s = ++nt;
|
|
900
|
+
F.set(s, {
|
|
861
901
|
resolve: a,
|
|
862
902
|
reject: o
|
|
863
903
|
});
|
|
864
904
|
let c = t.slice().buffer;
|
|
865
|
-
|
|
905
|
+
P.postMessage({
|
|
866
906
|
id: s,
|
|
867
907
|
pixels: c,
|
|
868
908
|
width: n,
|
|
869
909
|
height: r,
|
|
870
|
-
modelUrl:
|
|
910
|
+
modelUrl: et(i.modelUrl),
|
|
871
911
|
heatmapThreshold: i.heatmapThreshold,
|
|
872
912
|
cacheModel: i.cacheModel,
|
|
873
|
-
ortWasmPaths:
|
|
874
|
-
preferWebGpu: i.preferWebGpu ??
|
|
913
|
+
ortWasmPaths: Ke(i.ortWasmPaths),
|
|
914
|
+
preferWebGpu: i.preferWebGpu ?? de()
|
|
875
915
|
}, [c]);
|
|
876
916
|
});
|
|
877
917
|
}
|
|
878
|
-
async function
|
|
918
|
+
async function st(n, r) {
|
|
879
919
|
let { width: i, height: a } = n, o = r.minDimension ?? 360;
|
|
880
920
|
if (Math.min(i, a) < o) return {
|
|
881
921
|
status: "low-quality",
|
|
@@ -884,7 +924,7 @@ async function rt(n, r) {
|
|
|
884
924
|
sourceWidth: i,
|
|
885
925
|
sourceHeight: a
|
|
886
926
|
};
|
|
887
|
-
let s =
|
|
927
|
+
let s = $e(i, a, r.maxAnalysisDimension), c = Math.min(1, s / Math.max(i, a)), l = Math.max(1, Math.round(i * c)), u = Math.max(1, Math.round(a * c)), d;
|
|
888
928
|
if (c === 1) {
|
|
889
929
|
let e = n.getContext("2d", { willReadFrequently: !0 });
|
|
890
930
|
if (!e) throw t();
|
|
@@ -898,7 +938,7 @@ async function rt(n, r) {
|
|
|
898
938
|
}
|
|
899
939
|
let f;
|
|
900
940
|
if (r.useWorker !== !1 && typeof Worker < "u") try {
|
|
901
|
-
f = await
|
|
941
|
+
f = await ot(d, l, u, r);
|
|
902
942
|
} catch (t) {
|
|
903
943
|
if (t instanceof e && (t.code === "worker" || t.code === "model-http")) throw t;
|
|
904
944
|
f = {
|
|
@@ -922,7 +962,7 @@ async function rt(n, r) {
|
|
|
922
962
|
modelNote: y,
|
|
923
963
|
inferenceMs: b
|
|
924
964
|
};
|
|
925
|
-
if (p <
|
|
965
|
+
if (p < tt) return {
|
|
926
966
|
status: "low-quality",
|
|
927
967
|
confidence: Math.min(.3, p / 18),
|
|
928
968
|
message: "The image is too soft or dark to resolve four document edges.",
|
|
@@ -938,7 +978,7 @@ async function rt(n, r) {
|
|
|
938
978
|
sourceHeight: a,
|
|
939
979
|
...x
|
|
940
980
|
};
|
|
941
|
-
let S =
|
|
981
|
+
let S = it(m.corners, c), C = rt(S), w = r.minConfidence ?? .58;
|
|
942
982
|
return m.confidence < w ? {
|
|
943
983
|
status: "low-confidence",
|
|
944
984
|
quad: C,
|
|
@@ -959,14 +999,14 @@ async function rt(n, r) {
|
|
|
959
999
|
...x
|
|
960
1000
|
};
|
|
961
1001
|
}
|
|
962
|
-
function
|
|
963
|
-
let n = Math.max(1, Math.round(Math.max(
|
|
1002
|
+
function ct(e, t) {
|
|
1003
|
+
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));
|
|
964
1004
|
return {
|
|
965
1005
|
width: Math.max(1, Math.round(n * i)),
|
|
966
1006
|
height: Math.max(1, Math.round(r * i))
|
|
967
1007
|
};
|
|
968
1008
|
}
|
|
969
|
-
function
|
|
1009
|
+
function lt(e, t, n, r, i) {
|
|
970
1010
|
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) => {
|
|
971
1011
|
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;
|
|
972
1012
|
return Math.round(n * (1 - f) + r * f);
|
|
@@ -978,69 +1018,69 @@ function at(e, t, n, r, i) {
|
|
|
978
1018
|
255
|
|
979
1019
|
];
|
|
980
1020
|
}
|
|
981
|
-
function
|
|
982
|
-
let { width: i, height: a } =
|
|
1021
|
+
function ut(e, n, r) {
|
|
1022
|
+
let { width: i, height: a } = ct(n, r), o = e.getContext("2d", { willReadFrequently: !0 });
|
|
983
1023
|
if (!o) throw t();
|
|
984
1024
|
let s = o.getImageData(0, 0, e.width, e.height), c = document.createElement("canvas");
|
|
985
1025
|
c.width = i, c.height = a;
|
|
986
1026
|
let l = c.getContext("2d");
|
|
987
1027
|
if (!l) throw t();
|
|
988
|
-
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,
|
|
1028
|
+
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, ee = f.y - d.y + S * f.y, E = m.y - d.y + C * m.y;
|
|
989
1029
|
for (let t = 0; t < a; t += 1) {
|
|
990
1030
|
let n = t / Math.max(1, a - 1);
|
|
991
1031
|
for (let r = 0; r < i; r += 1) {
|
|
992
|
-
let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = (w * a + T * n + d.x) / o, l = (
|
|
1032
|
+
let a = r / Math.max(1, i - 1), o = S * a + C * n + 1, c = (w * a + T * n + d.x) / o, l = (ee * a + E * n + d.y) / o, [f, p, m, h] = lt(s.data, e.width, e.height, c, l), g = (t * i + r) * 4;
|
|
993
1033
|
u.data[g] = f, u.data[g + 1] = p, u.data[g + 2] = m, u.data[g + 3] = h;
|
|
994
1034
|
}
|
|
995
1035
|
}
|
|
996
1036
|
return l.putImageData(u, 0, 0), c;
|
|
997
1037
|
}
|
|
998
|
-
async function
|
|
999
|
-
return await x("scan"),
|
|
1038
|
+
async function dt(e, t = {}) {
|
|
1039
|
+
return await x("scan"), st(await N(e, { cloneCanvas: !1 }), t);
|
|
1000
1040
|
}
|
|
1001
|
-
async function
|
|
1041
|
+
async function ft(e, t, n = {}) {
|
|
1002
1042
|
await x("scan");
|
|
1003
|
-
let r = await
|
|
1043
|
+
let r = await N(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? 4096;
|
|
1004
1044
|
return {
|
|
1005
1045
|
status: "success",
|
|
1006
1046
|
corners: t,
|
|
1007
|
-
quad:
|
|
1047
|
+
quad: rt(t),
|
|
1008
1048
|
confidence: 1,
|
|
1009
1049
|
message: "Captured with the document edges shown in the finder.",
|
|
1010
1050
|
sourceWidth: r.width,
|
|
1011
1051
|
sourceHeight: r.height,
|
|
1012
|
-
canvas:
|
|
1052
|
+
canvas: ut(r, t, i)
|
|
1013
1053
|
};
|
|
1014
1054
|
}
|
|
1015
|
-
async function
|
|
1055
|
+
async function L(e, t = {}) {
|
|
1016
1056
|
await x("scan");
|
|
1017
|
-
let n = await
|
|
1057
|
+
let n = await N(e, { cloneCanvas: !1 }), r = await st(n, t);
|
|
1018
1058
|
if (r.status !== "success" || !r.corners) return r;
|
|
1019
1059
|
let i = t.maxOutputDimension ?? 4096;
|
|
1020
1060
|
return {
|
|
1021
1061
|
...r,
|
|
1022
|
-
canvas:
|
|
1062
|
+
canvas: ut(n, r.corners, i),
|
|
1023
1063
|
message: "Four document edges detected and perspective-corrected."
|
|
1024
1064
|
};
|
|
1025
1065
|
}
|
|
1026
|
-
function
|
|
1066
|
+
function pt(e) {
|
|
1027
1067
|
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})` : ""}`;
|
|
1028
1068
|
}
|
|
1029
|
-
async function
|
|
1030
|
-
let n = await
|
|
1069
|
+
async function mt(e, t = {}) {
|
|
1070
|
+
let n = await L(e, t);
|
|
1031
1071
|
return n.status === "success" ? n : {
|
|
1032
1072
|
...n,
|
|
1033
|
-
message:
|
|
1073
|
+
message: pt(n)
|
|
1034
1074
|
};
|
|
1035
1075
|
}
|
|
1036
1076
|
//#endregion
|
|
1037
1077
|
//#region src/sdk/lighting.ts
|
|
1038
|
-
function
|
|
1078
|
+
function ht(e, t) {
|
|
1039
1079
|
if (!e.length) return 0;
|
|
1040
1080
|
let n = [...e].sort((e, t) => e - t);
|
|
1041
1081
|
return n[Math.min(n.length - 1, Math.floor(n.length * t))];
|
|
1042
1082
|
}
|
|
1043
|
-
function
|
|
1083
|
+
function gt(e, t, n, r = 12) {
|
|
1044
1084
|
if (!t || !n || e.length < t * n) return {
|
|
1045
1085
|
strong: !1,
|
|
1046
1086
|
strength: 0,
|
|
@@ -1063,7 +1103,7 @@ function ft(e, t, n, r = 12) {
|
|
|
1063
1103
|
});
|
|
1064
1104
|
}
|
|
1065
1105
|
}
|
|
1066
|
-
let s =
|
|
1106
|
+
let s = ht(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
|
|
1067
1107
|
for (let e = 0; e < o.length; e += 1) {
|
|
1068
1108
|
if (!c[e] || l[e]) continue;
|
|
1069
1109
|
let t = [], n = [e];
|
|
@@ -1111,11 +1151,11 @@ function ft(e, t, n, r = 12) {
|
|
|
1111
1151
|
}
|
|
1112
1152
|
return d;
|
|
1113
1153
|
}
|
|
1114
|
-
function
|
|
1154
|
+
function _t(e, t, n, r, i, a, o) {
|
|
1115
1155
|
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));
|
|
1116
1156
|
return (e[c * t + u] - e[s * t + u] - e[c * t + l] + e[s * t + l]) / d;
|
|
1117
1157
|
}
|
|
1118
|
-
function
|
|
1158
|
+
function vt(e, t, n) {
|
|
1119
1159
|
let r = t + 1, i = new Uint32Array((t + 1) * (n + 1));
|
|
1120
1160
|
for (let a = 1; a <= n; a += 1) {
|
|
1121
1161
|
let n = 0;
|
|
@@ -1126,23 +1166,23 @@ function mt(e, t, n) {
|
|
|
1126
1166
|
stride: r
|
|
1127
1167
|
};
|
|
1128
1168
|
}
|
|
1129
|
-
function
|
|
1130
|
-
let { integral: i, stride: a } =
|
|
1169
|
+
function yt(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
|
|
1170
|
+
let { integral: i, stride: a } = vt(e, t, n), o = new Uint8Array(e.length);
|
|
1131
1171
|
for (let s = 0; s < n; s += 1) for (let c = 0; c < t; c += 1) {
|
|
1132
|
-
let l =
|
|
1172
|
+
let l = _t(i, a, t, n, c, s, r);
|
|
1133
1173
|
o[s * t + c] = Math.max(0, Math.min(255, Math.round(e[s * t + c] * 235 / Math.max(24, l))));
|
|
1134
1174
|
}
|
|
1135
1175
|
return o;
|
|
1136
1176
|
}
|
|
1137
|
-
function
|
|
1138
|
-
let { integral: a, stride: o } =
|
|
1177
|
+
function bt(e, t, n, r = Math.max(8, Math.round(Math.max(t, n) / 64)), i = .12) {
|
|
1178
|
+
let { integral: a, stride: o } = vt(e, t, n), s = new Uint8Array(e.length), c = 1 - i;
|
|
1139
1179
|
for (let i = 0; i < n; i += 1) for (let l = 0; l < t; l += 1) {
|
|
1140
|
-
let u =
|
|
1180
|
+
let u = _t(a, o, t, n, l, i, r);
|
|
1141
1181
|
s[i * t + l] = e[i * t + l] < u * c ? 0 : 255;
|
|
1142
1182
|
}
|
|
1143
1183
|
return s;
|
|
1144
1184
|
}
|
|
1145
|
-
function
|
|
1185
|
+
function xt(e, t, n) {
|
|
1146
1186
|
let r = [
|
|
1147
1187
|
e.topLeft,
|
|
1148
1188
|
e.topRight,
|
|
@@ -1156,8 +1196,8 @@ function _t(e, t, n) {
|
|
|
1156
1196
|
height: s - a
|
|
1157
1197
|
};
|
|
1158
1198
|
}
|
|
1159
|
-
function
|
|
1160
|
-
let n =
|
|
1199
|
+
function St(e, t) {
|
|
1200
|
+
let n = xt(t, e.width, e.height);
|
|
1161
1201
|
if (n.width <= 0 || n.height <= 0) return {
|
|
1162
1202
|
strong: !1,
|
|
1163
1203
|
strength: 0,
|
|
@@ -1176,26 +1216,26 @@ function vt(e, t) {
|
|
|
1176
1216
|
i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
|
|
1177
1217
|
let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
|
|
1178
1218
|
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);
|
|
1179
|
-
return
|
|
1219
|
+
return gt(o, r.width, r.height);
|
|
1180
1220
|
}
|
|
1181
1221
|
//#endregion
|
|
1182
1222
|
//#region src/sdk/finder.ts
|
|
1183
|
-
function
|
|
1223
|
+
function Ct(e, t) {
|
|
1184
1224
|
return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
|
|
1185
1225
|
}
|
|
1186
|
-
function
|
|
1226
|
+
function wt(e, t, n) {
|
|
1187
1227
|
if (n <= 0) return 0;
|
|
1188
1228
|
let r = n - (t - e);
|
|
1189
1229
|
return r <= 0 ? 0 : Math.max(1, Math.ceil(r / 1e3));
|
|
1190
1230
|
}
|
|
1191
|
-
function
|
|
1231
|
+
function Tt(e) {
|
|
1192
1232
|
return `Hold still for ${e}…`;
|
|
1193
1233
|
}
|
|
1194
|
-
async function
|
|
1234
|
+
async function Et(e, t) {
|
|
1195
1235
|
let n = await e();
|
|
1196
1236
|
return t(), n;
|
|
1197
1237
|
}
|
|
1198
|
-
function
|
|
1238
|
+
function Dt(e) {
|
|
1199
1239
|
return e === "alwaysOn" || e === "only" ? {
|
|
1200
1240
|
visible: !1,
|
|
1201
1241
|
checked: !0,
|
|
@@ -1210,7 +1250,7 @@ function Ct(e) {
|
|
|
1210
1250
|
mutable: !0
|
|
1211
1251
|
};
|
|
1212
1252
|
}
|
|
1213
|
-
function
|
|
1253
|
+
function R(e) {
|
|
1214
1254
|
return [
|
|
1215
1255
|
e.topLeft,
|
|
1216
1256
|
e.topRight,
|
|
@@ -1218,19 +1258,19 @@ function z(e) {
|
|
|
1218
1258
|
e.bottomLeft
|
|
1219
1259
|
];
|
|
1220
1260
|
}
|
|
1221
|
-
var
|
|
1222
|
-
function
|
|
1261
|
+
var Ot = 3e3, kt = 1600;
|
|
1262
|
+
function At(e = D()) {
|
|
1223
1263
|
return e.iosWebKit ? {
|
|
1224
1264
|
intervalMs: 70,
|
|
1225
1265
|
maxFrameDimension: 720,
|
|
1226
1266
|
maxAnalysisDimension: 720
|
|
1227
1267
|
} : {
|
|
1228
1268
|
intervalMs: 140,
|
|
1229
|
-
maxFrameDimension:
|
|
1269
|
+
maxFrameDimension: kt,
|
|
1230
1270
|
maxAnalysisDimension: 520
|
|
1231
1271
|
};
|
|
1232
1272
|
}
|
|
1233
|
-
function
|
|
1273
|
+
function jt(e, t) {
|
|
1234
1274
|
let n = e.status === "success" && e.modelStatus !== "failed", r = {
|
|
1235
1275
|
status: e.status,
|
|
1236
1276
|
confidence: Number(e.confidence.toFixed(3)),
|
|
@@ -1253,7 +1293,7 @@ function Dt(e, t) {
|
|
|
1253
1293
|
detail: r
|
|
1254
1294
|
};
|
|
1255
1295
|
}
|
|
1256
|
-
function
|
|
1296
|
+
function Mt(e) {
|
|
1257
1297
|
let t = 0;
|
|
1258
1298
|
for (let n = 0; n < e.length; n += 1) {
|
|
1259
1299
|
let r = e[n], i = e[(n + 1) % e.length];
|
|
@@ -1261,42 +1301,42 @@ function Ot(e) {
|
|
|
1261
1301
|
}
|
|
1262
1302
|
return Math.abs(t) / 2;
|
|
1263
1303
|
}
|
|
1264
|
-
function
|
|
1304
|
+
function z(e, t) {
|
|
1265
1305
|
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
1266
1306
|
}
|
|
1267
|
-
var
|
|
1307
|
+
var B = {
|
|
1268
1308
|
widthFill: 0,
|
|
1269
1309
|
heightFill: 0,
|
|
1270
1310
|
limitingFill: 0,
|
|
1271
1311
|
areaFill: 0,
|
|
1272
1312
|
aspectRatio: 1
|
|
1273
1313
|
};
|
|
1274
|
-
function
|
|
1275
|
-
let r =
|
|
1314
|
+
function Nt(e, t, n) {
|
|
1315
|
+
let r = R(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));
|
|
1276
1316
|
return {
|
|
1277
1317
|
widthFill: o,
|
|
1278
1318
|
heightFill: s,
|
|
1279
1319
|
limitingFill: Math.max(o, s),
|
|
1280
|
-
areaFill:
|
|
1320
|
+
areaFill: Mt(r) / Math.max(1, t * n),
|
|
1281
1321
|
aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
|
|
1282
1322
|
};
|
|
1283
1323
|
}
|
|
1284
|
-
function
|
|
1324
|
+
function Pt(e, t, n, r = {}) {
|
|
1285
1325
|
let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
|
|
1286
1326
|
if (e.aspectRatio < a) return i;
|
|
1287
1327
|
let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
|
|
1288
1328
|
return Math.min(o ?? i + .08, 1 - n * 2);
|
|
1289
1329
|
}
|
|
1290
|
-
function
|
|
1330
|
+
function Ft(e, t, n = {}) {
|
|
1291
1331
|
let r = n.confidenceThreshold ?? .72;
|
|
1292
1332
|
if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
|
|
1293
1333
|
hint: "Place the document in the frame",
|
|
1294
1334
|
reason: "place-document",
|
|
1295
1335
|
fillRatio: 0,
|
|
1296
|
-
fill:
|
|
1336
|
+
fill: B,
|
|
1297
1337
|
readyForAutoCapture: !1
|
|
1298
1338
|
};
|
|
1299
|
-
let i =
|
|
1339
|
+
let i = R(e.quad), a = Nt(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;
|
|
1300
1340
|
if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
|
|
1301
1341
|
hint: "Move farther away",
|
|
1302
1342
|
reason: "move-farther-away",
|
|
@@ -1304,14 +1344,14 @@ function jt(e, t, n = {}) {
|
|
|
1304
1344
|
fill: a,
|
|
1305
1345
|
readyForAutoCapture: !1
|
|
1306
1346
|
};
|
|
1307
|
-
let [u, d, f, p] = i, m =
|
|
1347
|
+
let [u, d, f, p] = i, m = z(u, d), h = z(d, f), g = z(f, p), _ = z(p, u);
|
|
1308
1348
|
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) ? {
|
|
1309
1349
|
hint: "Hold the camera straight",
|
|
1310
1350
|
reason: "straighten-camera",
|
|
1311
1351
|
fillRatio: o,
|
|
1312
1352
|
fill: a,
|
|
1313
1353
|
readyForAutoCapture: !1
|
|
1314
|
-
} : o <
|
|
1354
|
+
} : o < Pt(a, t.previouslyReady === !0, s, n) ? {
|
|
1315
1355
|
hint: "Move closer",
|
|
1316
1356
|
reason: "move-closer",
|
|
1317
1357
|
fillRatio: o,
|
|
@@ -1325,7 +1365,7 @@ function jt(e, t, n = {}) {
|
|
|
1325
1365
|
readyForAutoCapture: t.ready
|
|
1326
1366
|
};
|
|
1327
1367
|
}
|
|
1328
|
-
var
|
|
1368
|
+
var It = class {
|
|
1329
1369
|
previous;
|
|
1330
1370
|
count = 0;
|
|
1331
1371
|
ready = !1;
|
|
@@ -1342,8 +1382,8 @@ var Mt = class {
|
|
|
1342
1382
|
ready: !1,
|
|
1343
1383
|
movement: Infinity
|
|
1344
1384
|
};
|
|
1345
|
-
let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...
|
|
1346
|
-
let r =
|
|
1385
|
+
let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...R(e.quad).map((e, n) => {
|
|
1386
|
+
let r = R(this.previous)[n];
|
|
1347
1387
|
return Math.hypot(e.x - r.x, e.y - r.y) / Math.max(1, t);
|
|
1348
1388
|
})) : Infinity, r = this.options.exitCornerTolerance ?? Math.max(this.options.cornerTolerance, .036);
|
|
1349
1389
|
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, {
|
|
@@ -1353,14 +1393,14 @@ var Mt = class {
|
|
|
1353
1393
|
};
|
|
1354
1394
|
}
|
|
1355
1395
|
};
|
|
1356
|
-
function
|
|
1396
|
+
function Lt(e, n) {
|
|
1357
1397
|
let r = Math.min(1, n / Math.max(e.width, e.height)), i = document.createElement("canvas");
|
|
1358
1398
|
i.width = Math.max(1, Math.round(e.width * r)), i.height = Math.max(1, Math.round(e.height * r));
|
|
1359
1399
|
let a = i.getContext("2d");
|
|
1360
1400
|
if (!a) throw t();
|
|
1361
1401
|
return a.drawImage(e, 0, 0, i.width, i.height), i;
|
|
1362
1402
|
}
|
|
1363
|
-
function
|
|
1403
|
+
function Rt() {
|
|
1364
1404
|
let e = window.AudioContext ?? window.webkitAudioContext;
|
|
1365
1405
|
if (!e) return;
|
|
1366
1406
|
let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
|
|
@@ -1371,29 +1411,29 @@ function Pt() {
|
|
|
1371
1411
|
let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
|
|
1372
1412
|
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();
|
|
1373
1413
|
}
|
|
1374
|
-
async function
|
|
1414
|
+
async function zt(e) {
|
|
1375
1415
|
let t = document.createElement("video");
|
|
1376
1416
|
return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
|
|
1377
1417
|
}
|
|
1378
|
-
async function
|
|
1418
|
+
async function Bt(t) {
|
|
1379
1419
|
await x("scan");
|
|
1380
|
-
let n =
|
|
1420
|
+
let n = Dt(t.autoCapture), r = t.holdStillMs ?? 3e3, i = new It({
|
|
1381
1421
|
stableFrames: t.stableFrames ?? 4,
|
|
1382
1422
|
confidenceThreshold: t.confidenceThreshold ?? .72,
|
|
1383
1423
|
cornerTolerance: t.cornerTolerance ?? .024,
|
|
1384
1424
|
exitCornerTolerance: t.exitCornerTolerance ?? .036
|
|
1385
|
-
}), a =
|
|
1425
|
+
}), a = At(), o = t.maxFrameDimension ?? a.maxFrameDimension, s = t.intervalMs ?? a.intervalMs, c = {
|
|
1386
1426
|
minDimension: 220,
|
|
1387
1427
|
maxAnalysisDimension: a.maxAnalysisDimension,
|
|
1388
1428
|
...t.detection
|
|
1389
|
-
}, l = typeof MediaStream < "u" && t.source instanceof MediaStream ? await
|
|
1429
|
+
}, l = typeof MediaStream < "u" && t.source instanceof MediaStream ? await zt(t.source) : t.source, u = !0, d = !1, f = !1, p, m = 0, h, g = "", _ = 0, v = {
|
|
1390
1430
|
state: "detecting",
|
|
1391
1431
|
confidence: 0,
|
|
1392
1432
|
guidance: {
|
|
1393
1433
|
hint: "Place the document in the frame",
|
|
1394
1434
|
reason: "place-document",
|
|
1395
1435
|
fillRatio: 0,
|
|
1396
|
-
fill:
|
|
1436
|
+
fill: B,
|
|
1397
1437
|
readyForAutoCapture: !1
|
|
1398
1438
|
},
|
|
1399
1439
|
lighting: {
|
|
@@ -1403,10 +1443,10 @@ async function It(t) {
|
|
|
1403
1443
|
stableFrames: 0,
|
|
1404
1444
|
requiredStableFrames: t.stableFrames ?? 4,
|
|
1405
1445
|
autoCapture: { ...n }
|
|
1406
|
-
}, y = () => l instanceof HTMLCanvasElement ?
|
|
1446
|
+
}, y = () => l instanceof HTMLCanvasElement ? Lt(l, o) : M(l, o), b = (e) => {
|
|
1407
1447
|
v = e, t.onStatus?.(e);
|
|
1408
1448
|
}, S = (e) => {
|
|
1409
|
-
let t =
|
|
1449
|
+
let t = jt(e, l instanceof HTMLVideoElement ? {
|
|
1410
1450
|
width: l.videoWidth,
|
|
1411
1451
|
height: l.videoHeight
|
|
1412
1452
|
} : {
|
|
@@ -1421,11 +1461,11 @@ async function It(t) {
|
|
|
1421
1461
|
d = !0;
|
|
1422
1462
|
let n;
|
|
1423
1463
|
try {
|
|
1424
|
-
n = await
|
|
1464
|
+
n = await Et(t.captureFrame ?? y, () => {
|
|
1425
1465
|
b({
|
|
1426
1466
|
...v,
|
|
1427
1467
|
state: "captured"
|
|
1428
|
-
}), t.playShutterSound !== !1 &&
|
|
1468
|
+
}), t.playShutterSound !== !1 && Rt(), C();
|
|
1429
1469
|
});
|
|
1430
1470
|
} catch (e) {
|
|
1431
1471
|
throw d = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
|
|
@@ -1439,9 +1479,9 @@ async function It(t) {
|
|
|
1439
1479
|
}, T = async () => {
|
|
1440
1480
|
if (u && !d) {
|
|
1441
1481
|
try {
|
|
1442
|
-
let e = y(), a = await
|
|
1482
|
+
let e = y(), a = await dt(e, c);
|
|
1443
1483
|
h = a, S(a);
|
|
1444
|
-
let o = a.quad ?
|
|
1484
|
+
let o = a.quad ? St(e, a.quad) : {
|
|
1445
1485
|
strong: !1,
|
|
1446
1486
|
strength: 0
|
|
1447
1487
|
}, s = o.strong ? {
|
|
@@ -1451,7 +1491,7 @@ async function It(t) {
|
|
|
1451
1491
|
} : {
|
|
1452
1492
|
castShadow: !1,
|
|
1453
1493
|
strength: o.strength
|
|
1454
|
-
}, l = i.update(a), u =
|
|
1494
|
+
}, l = i.update(a), u = Ft(a, {
|
|
1455
1495
|
...l,
|
|
1456
1496
|
previouslyReady: f
|
|
1457
1497
|
}, {
|
|
@@ -1461,7 +1501,7 @@ async function It(t) {
|
|
|
1461
1501
|
f = u.readyForAutoCapture;
|
|
1462
1502
|
let d = performance.now();
|
|
1463
1503
|
u.readyForAutoCapture && n.checked ? p ??= d : p = void 0;
|
|
1464
|
-
let m = p === void 0 ? void 0 :
|
|
1504
|
+
let m = p === void 0 ? void 0 : wt(p, d, r), g = a.status !== "success" || u.reason === "place-document" ? "seeking" : u.readyForAutoCapture ? "ready" : "unstable";
|
|
1465
1505
|
if (b({
|
|
1466
1506
|
state: g,
|
|
1467
1507
|
confidence: a.confidence,
|
|
@@ -1507,7 +1547,7 @@ async function It(t) {
|
|
|
1507
1547
|
hint: "Place the document in the frame",
|
|
1508
1548
|
reason: "place-document",
|
|
1509
1549
|
fillRatio: 0,
|
|
1510
|
-
fill:
|
|
1550
|
+
fill: B,
|
|
1511
1551
|
readyForAutoCapture: !1
|
|
1512
1552
|
},
|
|
1513
1553
|
lighting: {
|
|
@@ -1538,24 +1578,24 @@ async function It(t) {
|
|
|
1538
1578
|
}
|
|
1539
1579
|
//#endregion
|
|
1540
1580
|
//#region src/sdk/ocr-runtime.ts
|
|
1541
|
-
var
|
|
1542
|
-
function
|
|
1581
|
+
var Vt = new URL("./assets/tesseract/worker.min.js", import.meta.url), Ht = new URL("./assets/tesseract/tesseract-core-lstm.wasm.js", import.meta.url), Ut = new URL("./assets/tesseract/tesseract-core-simd-lstm.wasm.js", import.meta.url), Wt = new URL("./assets/tesseract/tesseract-core-relaxedsimd-lstm.wasm.js", import.meta.url), Gt = new URL("./assets/tesseract/eng.traineddata.gz", import.meta.url), Kt = Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 15, 1, 13, 0, 65, 1, 253, 15, 65, 2, 253, 15, 253, 128, 2, 11), qt = Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 10, 1, 8, 0, 65, 0, 253, 15, 253, 98, 11);
|
|
1582
|
+
function Jt(e) {
|
|
1543
1583
|
try {
|
|
1544
1584
|
return typeof WebAssembly < "u" && WebAssembly.validate(e);
|
|
1545
1585
|
} catch {
|
|
1546
1586
|
return !1;
|
|
1547
1587
|
}
|
|
1548
1588
|
}
|
|
1549
|
-
function
|
|
1589
|
+
function Yt() {
|
|
1550
1590
|
return {
|
|
1551
|
-
relaxedSimd:
|
|
1552
|
-
simd:
|
|
1591
|
+
relaxedSimd: Jt(Kt),
|
|
1592
|
+
simd: Jt(qt)
|
|
1553
1593
|
};
|
|
1554
1594
|
}
|
|
1555
|
-
function
|
|
1556
|
-
return e.relaxedSimd ?
|
|
1595
|
+
function Xt(e) {
|
|
1596
|
+
return e.relaxedSimd ? Wt : e.simd ? Ut : Ht;
|
|
1557
1597
|
}
|
|
1558
|
-
function
|
|
1598
|
+
function Zt(t, n) {
|
|
1559
1599
|
let r = t?.trim() || "eng", i = n?.trim() || "";
|
|
1560
1600
|
if (i) return {
|
|
1561
1601
|
kind: "lang-path",
|
|
@@ -1568,14 +1608,14 @@ function qt(t, n) {
|
|
|
1568
1608
|
};
|
|
1569
1609
|
throw new e("language", `OCR language "${r}" is not packaged. Pass langPath, a directory URL that contains ${r}.traineddata.gz.`);
|
|
1570
1610
|
}
|
|
1571
|
-
function
|
|
1611
|
+
function Qt(e = Gt) {
|
|
1572
1612
|
let t = e.href, n = t.lastIndexOf("/");
|
|
1573
1613
|
return n === -1 ? t : t.slice(0, n);
|
|
1574
1614
|
}
|
|
1575
|
-
function
|
|
1576
|
-
return e.kind === "bundled-eng" ?
|
|
1615
|
+
function $t(e) {
|
|
1616
|
+
return e.kind === "bundled-eng" ? Qt() : e.langPath;
|
|
1577
1617
|
}
|
|
1578
|
-
async function
|
|
1618
|
+
async function en(t, n, r) {
|
|
1579
1619
|
return new Promise((i, a) => {
|
|
1580
1620
|
let o = !1, s = (t) => {
|
|
1581
1621
|
o || (o = !0, a(new e("worker", `OCR worker failed to start (${t instanceof Error ? t.message : String(t)}).`)));
|
|
@@ -1598,7 +1638,7 @@ async function Xt(t, n, r) {
|
|
|
1598
1638
|
}
|
|
1599
1639
|
//#endregion
|
|
1600
1640
|
//#region src/sdk/ocr.ts
|
|
1601
|
-
function
|
|
1641
|
+
function tn(e, t = 1, n = 1, r = 0, i = 0) {
|
|
1602
1642
|
return {
|
|
1603
1643
|
text: e.text,
|
|
1604
1644
|
confidence: Math.max(0, Math.min(1, e.confidence / 100)),
|
|
@@ -1610,20 +1650,20 @@ function Zt(e, t = 1, n = 1, r = 0, i = 0) {
|
|
|
1610
1650
|
}
|
|
1611
1651
|
};
|
|
1612
1652
|
}
|
|
1613
|
-
function
|
|
1653
|
+
function nn(e = .5) {
|
|
1614
1654
|
if (!Number.isFinite(e) || e < 0 || e > 1) throw RangeError("OCR minConfidence must be between 0 and 1.");
|
|
1615
1655
|
return e;
|
|
1616
1656
|
}
|
|
1617
|
-
function
|
|
1657
|
+
function rn(e, t) {
|
|
1618
1658
|
let n = Math.max(e.bbox.x, t.bbox.x), r = Math.max(e.bbox.y, t.bbox.y), i = Math.min(e.bbox.x + e.bbox.width, t.bbox.x + t.bbox.width), a = Math.min(e.bbox.y + e.bbox.height, t.bbox.y + t.bbox.height), o = Math.max(0, i - n) * Math.max(0, a - r), s = Math.min(e.bbox.width * e.bbox.height, t.bbox.width * t.bbox.height);
|
|
1619
1659
|
return s > 0 ? o / s : 0;
|
|
1620
1660
|
}
|
|
1621
|
-
function
|
|
1661
|
+
function an(e) {
|
|
1622
1662
|
let t = [...e].sort((e, t) => t.confidence - e.confidence || e.bbox.y - t.bbox.y || e.bbox.x - t.bbox.x || e.text.localeCompare(t.text)), n = [];
|
|
1623
|
-
for (let e of t) n.some((t) =>
|
|
1663
|
+
for (let e of t) n.some((t) => rn(t, e) >= .65) || n.push(e);
|
|
1624
1664
|
return n;
|
|
1625
1665
|
}
|
|
1626
|
-
function
|
|
1666
|
+
function on(e, t, n, r, i) {
|
|
1627
1667
|
let a = e.text.trim();
|
|
1628
1668
|
if (!a || !/[\p{L}\p{N}]/u.test(a)) return !1;
|
|
1629
1669
|
let o = e.bbox.width * e.bbox.height / Math.max(1, n * r), s = e.bbox.width / Math.max(1, e.bbox.height);
|
|
@@ -1634,7 +1674,7 @@ function tn(e, t, n, r, i) {
|
|
|
1634
1674
|
}
|
|
1635
1675
|
return !0;
|
|
1636
1676
|
}
|
|
1637
|
-
function
|
|
1677
|
+
function sn(e) {
|
|
1638
1678
|
let t = [...e].sort((e, t) => e.bbox.y + e.bbox.height / 2 - (t.bbox.y + t.bbox.height / 2) || e.bbox.x - t.bbox.x), n = [];
|
|
1639
1679
|
for (let e of t) {
|
|
1640
1680
|
let t = e.bbox.y + e.bbox.height / 2, r = n.find((n) => Math.abs(n.centerY - t) <= Math.max(n.height, e.bbox.height) * .6);
|
|
@@ -1650,28 +1690,28 @@ function nn(e) {
|
|
|
1650
1690
|
}
|
|
1651
1691
|
return n.sort((e, t) => e.centerY - t.centerY).map((e) => e.words.sort((e, t) => e.bbox.x - t.bbox.x).map((e) => e.text.trim()).join(" ")).join("\n");
|
|
1652
1692
|
}
|
|
1653
|
-
function
|
|
1654
|
-
let i =
|
|
1693
|
+
function cn(e, t, n, r) {
|
|
1694
|
+
let i = nn(t.minConfidence), a = [], o = [], s = 1, c = 1;
|
|
1655
1695
|
for (let t of e) {
|
|
1656
1696
|
let e = t.scaleX ?? 1, n = t.scaleY ?? 1, r = t.offsetX ?? 0, l = t.offsetY ?? 0;
|
|
1657
1697
|
for (let u of t.blocks ?? []) for (let t of u.paragraphs) for (let u of t.lines) for (let t of u.words) {
|
|
1658
|
-
let u =
|
|
1698
|
+
let u = tn(t, e, n, r, l);
|
|
1659
1699
|
s = Math.max(s, u.bbox.x + u.bbox.width), c = Math.max(c, u.bbox.y + u.bbox.height), u.confidence >= i && a.push(u);
|
|
1660
1700
|
for (let a of t.symbols) {
|
|
1661
|
-
let t =
|
|
1701
|
+
let t = tn(a, e, n, r, l);
|
|
1662
1702
|
t.confidence >= i && o.push(t);
|
|
1663
1703
|
}
|
|
1664
1704
|
}
|
|
1665
1705
|
}
|
|
1666
|
-
let l = n?.width ?? s, u = n?.height ?? c, d =
|
|
1706
|
+
let l = n?.width ?? s, u = n?.height ?? c, d = an(a).filter((e) => on(e, "word", l, u, r)), f = an(o).filter((e) => on(e, "character", l, u, r));
|
|
1667
1707
|
return {
|
|
1668
|
-
text:
|
|
1708
|
+
text: sn(d),
|
|
1669
1709
|
confidence: d.length ? d.reduce((e, t) => e + t.confidence, 0) / d.length : 0,
|
|
1670
1710
|
words: t.includeWords ? d : [],
|
|
1671
1711
|
characters: t.includeCharacters ? f : []
|
|
1672
1712
|
};
|
|
1673
1713
|
}
|
|
1674
|
-
function
|
|
1714
|
+
function ln(e) {
|
|
1675
1715
|
let n = e.getContext("2d", { willReadFrequently: !0 });
|
|
1676
1716
|
if (!n) throw t();
|
|
1677
1717
|
let r = n.getImageData(0, 0, e.width, e.height), i = new Uint8Array(e.width * e.height);
|
|
@@ -1682,7 +1722,7 @@ function an(e) {
|
|
|
1682
1722
|
luminance: i
|
|
1683
1723
|
};
|
|
1684
1724
|
}
|
|
1685
|
-
function
|
|
1725
|
+
function un(e) {
|
|
1686
1726
|
let t = document.createElement("canvas");
|
|
1687
1727
|
t.width = 72, t.height = 72;
|
|
1688
1728
|
let n = t.getContext("2d", { willReadFrequently: !0 });
|
|
@@ -1693,27 +1733,27 @@ function on(e) {
|
|
|
1693
1733
|
areaRatio: 0
|
|
1694
1734
|
};
|
|
1695
1735
|
n.drawImage(e, 0, 0, t.width, t.height);
|
|
1696
|
-
let { luminance: r } =
|
|
1697
|
-
return
|
|
1736
|
+
let { luminance: r } = ln(t);
|
|
1737
|
+
return gt(r, t.width, t.height);
|
|
1698
1738
|
}
|
|
1699
|
-
function
|
|
1739
|
+
function dn(e, t, n, r) {
|
|
1700
1740
|
let i = (e.bbox.x + e.bbox.width / 2) / n, a = (e.bbox.y + e.bbox.height / 2) / r;
|
|
1701
1741
|
return i >= t.x && i <= t.x + t.width && a >= t.y && a <= t.y + t.height;
|
|
1702
1742
|
}
|
|
1703
|
-
var
|
|
1704
|
-
function
|
|
1743
|
+
var fn = .58;
|
|
1744
|
+
function pn(e) {
|
|
1705
1745
|
let t = e.trim();
|
|
1706
1746
|
if (!t || !/[\p{L}\p{N}]/u.test(t)) return 0;
|
|
1707
1747
|
if (/^\$?\d{1,5}([.,]\d{2})?$/.test(t)) return 1;
|
|
1708
1748
|
let n = t.replace(/[^\p{L}]/gu, "");
|
|
1709
1749
|
return n.length >= 3 && /[aeiouy]/i.test(n) ? .9 : n.length >= 4 ? .7 : t.length <= 2 ? .35 : /[^\p{L}\p{N}.,'’$/-]/u.test(t) ? .25 : .5;
|
|
1710
1750
|
}
|
|
1711
|
-
function
|
|
1751
|
+
function mn(e, t, n) {
|
|
1712
1752
|
let r = Math.max(0, Math.min(1, (1 - e.darkness / 80) * (1 - e.strength / 24)));
|
|
1713
1753
|
if (!t.length) return r * .35;
|
|
1714
1754
|
let i = 0;
|
|
1715
1755
|
for (let e of t) {
|
|
1716
|
-
let t =
|
|
1756
|
+
let t = pn(e.text);
|
|
1717
1757
|
if (n) {
|
|
1718
1758
|
let r = n(e.bbox);
|
|
1719
1759
|
(r < .04 || r > .62) && (t *= .4);
|
|
@@ -1722,10 +1762,10 @@ function un(e, t, n) {
|
|
|
1722
1762
|
}
|
|
1723
1763
|
return r * .7 + i / t.length * .3;
|
|
1724
1764
|
}
|
|
1725
|
-
function
|
|
1726
|
-
return !e.strong || !e.region ? !1 :
|
|
1765
|
+
function hn(e, t, n, r) {
|
|
1766
|
+
return !e.strong || !e.region ? !1 : mn(e, t.filter((t) => dn(t, e.region, n.width, n.height)), r) < fn;
|
|
1727
1767
|
}
|
|
1728
|
-
function
|
|
1768
|
+
function gn(e, t, n, r) {
|
|
1729
1769
|
let i = Math.max(0, Math.floor(t.x * e.width)), a = Math.max(0, Math.floor(t.y * e.height)), o = Math.min(e.width, Math.ceil((t.x + t.width) * e.width)), s = Math.min(e.height, Math.ceil((t.y + t.height) * e.height)), c = document.createElement("canvas");
|
|
1730
1770
|
c.width = Math.max(1, o - i), c.height = Math.max(1, s - a), c.getContext("2d")?.drawImage(e, i, a, c.width, c.height, 0, 0, c.width, c.height);
|
|
1731
1771
|
let l = n / e.width, u = r / e.height;
|
|
@@ -1739,26 +1779,26 @@ function fn(e, t, n, r) {
|
|
|
1739
1779
|
}
|
|
1740
1780
|
};
|
|
1741
1781
|
}
|
|
1742
|
-
function
|
|
1782
|
+
function _n(e, t) {
|
|
1743
1783
|
for (let n = 0, r = 0; n < t.length; n += 1, r += 4) e.data[r] = t[n], e.data[r + 1] = t[n], e.data[r + 2] = t[n], e.data[r + 3] = 255;
|
|
1744
1784
|
}
|
|
1745
|
-
function
|
|
1785
|
+
function vn(e) {
|
|
1746
1786
|
let n = 2200, r = Math.max(e.width, e.height), i = r > n ? n / r : Math.min(1.5, n / Math.max(1, r)), a = document.createElement("canvas");
|
|
1747
1787
|
a.width = Math.max(1, Math.round(e.width * i)), a.height = Math.max(1, Math.round(e.height * i));
|
|
1748
1788
|
let o = a.getContext("2d", { willReadFrequently: !0 });
|
|
1749
1789
|
if (!o) throw t();
|
|
1750
1790
|
o.drawImage(e, 0, 0, a.width, a.height);
|
|
1751
|
-
let { image: s, luminance: c } =
|
|
1791
|
+
let { image: s, luminance: c } = ln(a), l = yt(c, a.width, a.height), u = bt(l, a.width, a.height), d = document.createElement("canvas");
|
|
1752
1792
|
d.width = a.width, d.height = a.height;
|
|
1753
1793
|
let f = d.getContext("2d", { willReadFrequently: !0 });
|
|
1754
1794
|
if (!f) throw t();
|
|
1755
1795
|
let p = f.createImageData(d.width, d.height);
|
|
1756
|
-
return
|
|
1796
|
+
return _n(p, l), f.putImageData(p, 0, 0), _n(s, u), o.putImageData(s, 0, 0), {
|
|
1757
1797
|
sparseCanvas: a,
|
|
1758
1798
|
flattenedCanvas: d
|
|
1759
1799
|
};
|
|
1760
1800
|
}
|
|
1761
|
-
function
|
|
1801
|
+
function yn(e) {
|
|
1762
1802
|
let t = document.createElement("canvas");
|
|
1763
1803
|
t.width = 24, t.height = 24;
|
|
1764
1804
|
let n = t.getContext("2d", { willReadFrequently: !0 });
|
|
@@ -1776,19 +1816,19 @@ function hn(e) {
|
|
|
1776
1816
|
return l / s.length;
|
|
1777
1817
|
};
|
|
1778
1818
|
}
|
|
1779
|
-
async function
|
|
1819
|
+
async function bn(e, t = {}) {
|
|
1780
1820
|
await x("ocr");
|
|
1781
|
-
let n =
|
|
1782
|
-
|
|
1783
|
-
let i = await
|
|
1821
|
+
let n = Zt(t.language, t.langPath), r = n.language;
|
|
1822
|
+
nn(t.minConfidence);
|
|
1823
|
+
let i = await N(e, { cloneCanvas: !1 }), { sparseCanvas: a, flattenedCanvas: o } = vn(i), s = t.shadowPass === !1 ? {
|
|
1784
1824
|
strong: !1,
|
|
1785
1825
|
strength: 0,
|
|
1786
1826
|
darkness: 0,
|
|
1787
1827
|
areaRatio: 0
|
|
1788
|
-
} :
|
|
1789
|
-
workerPath:
|
|
1790
|
-
corePath:
|
|
1791
|
-
langPath:
|
|
1828
|
+
} : un(i), { createWorker: c, PSM: l } = await import("tesseract.js"), u = 0, d = s.strong ? 3 : 2, f = await en(c, r, {
|
|
1829
|
+
workerPath: Vt.href,
|
|
1830
|
+
corePath: Xt(Yt()).href,
|
|
1831
|
+
langPath: $t(n),
|
|
1792
1832
|
logger(e) {
|
|
1793
1833
|
typeof e.progress == "number" && t.onProgress?.(Math.min(1, (u + e.progress) / d), e.status ?? "recognizing text");
|
|
1794
1834
|
}
|
|
@@ -1813,16 +1853,16 @@ async function H(e, t = {}) {
|
|
|
1813
1853
|
}], d = {
|
|
1814
1854
|
...t,
|
|
1815
1855
|
includeWords: !0
|
|
1816
|
-
}, p =
|
|
1856
|
+
}, p = yn(i), m = cn(c, d, {
|
|
1817
1857
|
width: i.width,
|
|
1818
1858
|
height: i.height
|
|
1819
|
-
}, p), h = t.shadowPass !== !1 &&
|
|
1859
|
+
}, p), h = t.shadowPass !== !1 && hn(s, m.words, {
|
|
1820
1860
|
width: i.width,
|
|
1821
1861
|
height: i.height
|
|
1822
1862
|
}, p);
|
|
1823
1863
|
if (h && s.region) {
|
|
1824
1864
|
u = 2;
|
|
1825
|
-
let { tile: e, passMapping: t } =
|
|
1865
|
+
let { tile: e, passMapping: t } = gn(o, s.region, i.width, i.height);
|
|
1826
1866
|
await f.setParameters({
|
|
1827
1867
|
tessedit_pageseg_mode: l.SPARSE_TEXT,
|
|
1828
1868
|
preserve_interword_spaces: "1"
|
|
@@ -1836,7 +1876,7 @@ async function H(e, t = {}) {
|
|
|
1836
1876
|
...t
|
|
1837
1877
|
});
|
|
1838
1878
|
}
|
|
1839
|
-
let g = c.length === 2 ? m :
|
|
1879
|
+
let g = c.length === 2 ? m : cn(c, d, {
|
|
1840
1880
|
width: i.width,
|
|
1841
1881
|
height: i.height
|
|
1842
1882
|
}, p);
|
|
@@ -1865,50 +1905,68 @@ async function H(e, t = {}) {
|
|
|
1865
1905
|
}
|
|
1866
1906
|
//#endregion
|
|
1867
1907
|
//#region src/sdk/zxing-runtime.ts
|
|
1868
|
-
var
|
|
1869
|
-
function
|
|
1908
|
+
var xn = new URL("./assets/zxing_reader.wasm", import.meta.url), Sn = "3.1.6", Cn = "zxing_reader.wasm", wn = `https://exige-scanner-sdk.vercel.app/zxing/${Sn}/`, Tn = `https://cdn.jsdelivr.net/npm/zxing-wasm@${Sn}/dist/reader/`;
|
|
1909
|
+
function En(e, t) {
|
|
1870
1910
|
return `${e.endsWith("/") ? e : `${e}/`}${t}`;
|
|
1871
1911
|
}
|
|
1872
|
-
function
|
|
1873
|
-
return
|
|
1912
|
+
function Dn(e = wn) {
|
|
1913
|
+
return En(e, Cn);
|
|
1874
1914
|
}
|
|
1875
|
-
function
|
|
1876
|
-
return
|
|
1915
|
+
function On() {
|
|
1916
|
+
return xn.href;
|
|
1877
1917
|
}
|
|
1878
|
-
var
|
|
1879
|
-
function
|
|
1918
|
+
var kn, An;
|
|
1919
|
+
function jn() {
|
|
1880
1920
|
return {
|
|
1881
|
-
binary:
|
|
1882
|
-
url:
|
|
1921
|
+
binary: kn,
|
|
1922
|
+
url: An
|
|
1883
1923
|
};
|
|
1884
1924
|
}
|
|
1885
|
-
async function
|
|
1886
|
-
let t =
|
|
1887
|
-
if (await
|
|
1888
|
-
let n =
|
|
1889
|
-
return await
|
|
1925
|
+
async function Mn(e = fetch) {
|
|
1926
|
+
let t = On();
|
|
1927
|
+
if (await He(t, e)) return t;
|
|
1928
|
+
let n = Dn(wn);
|
|
1929
|
+
return await He(n, e) ? n : Dn(Tn);
|
|
1930
|
+
}
|
|
1931
|
+
async function Nn(e = fetch) {
|
|
1932
|
+
let t = jn();
|
|
1933
|
+
if (t.binary) return t.binary.slice(0);
|
|
1934
|
+
let n = await e(await Mn(e));
|
|
1935
|
+
if (!n.ok) throw Error(`Could not download zxing-wasm (${n.status}).`);
|
|
1936
|
+
return await n.arrayBuffer();
|
|
1890
1937
|
}
|
|
1891
1938
|
//#endregion
|
|
1892
1939
|
//#region src/sdk/barcode.ts
|
|
1893
|
-
var
|
|
1940
|
+
var Pn = 1600, Fn = [
|
|
1941
|
+
1600,
|
|
1894
1942
|
1280,
|
|
1895
1943
|
960,
|
|
1896
1944
|
720,
|
|
1897
1945
|
480
|
|
1946
|
+
], In = [
|
|
1947
|
+
[.2, .8],
|
|
1948
|
+
[.32, .72],
|
|
1949
|
+
[.4, .86]
|
|
1898
1950
|
];
|
|
1899
|
-
function
|
|
1951
|
+
function Ln(e, t) {
|
|
1900
1952
|
let n = Math.max(e, t);
|
|
1901
1953
|
if (!Number.isFinite(n) || n < 1) return [];
|
|
1902
|
-
let r = [
|
|
1903
|
-
for (let e of
|
|
1904
|
-
return
|
|
1954
|
+
let r = Math.min(n, Pn), i = [r];
|
|
1955
|
+
for (let e of Fn) e <= r - 16 && i.push(e);
|
|
1956
|
+
return i;
|
|
1905
1957
|
}
|
|
1906
|
-
|
|
1958
|
+
var V = class extends Error {
|
|
1959
|
+
code = "zxing-wasm-load";
|
|
1960
|
+
constructor(e) {
|
|
1961
|
+
super("The barcode decoder failed to load."), this.name = "Pdf417DecoderError", e !== void 0 && (this.cause = e);
|
|
1962
|
+
}
|
|
1963
|
+
};
|
|
1964
|
+
function Rn() {
|
|
1907
1965
|
let e = globalThis.BarcodeDetector;
|
|
1908
1966
|
return typeof e == "function" ? e : void 0;
|
|
1909
1967
|
}
|
|
1910
|
-
async function
|
|
1911
|
-
let e =
|
|
1968
|
+
async function zn() {
|
|
1969
|
+
let e = Rn();
|
|
1912
1970
|
if (!e?.getSupportedFormats) return !1;
|
|
1913
1971
|
try {
|
|
1914
1972
|
return (await e.getSupportedFormats()).some((e) => e.toLowerCase() === "pdf417");
|
|
@@ -1916,37 +1974,50 @@ async function jn() {
|
|
|
1916
1974
|
return !1;
|
|
1917
1975
|
}
|
|
1918
1976
|
}
|
|
1919
|
-
function
|
|
1977
|
+
function Bn(e) {
|
|
1920
1978
|
try {
|
|
1921
1979
|
return e.getContext("2d", { willReadFrequently: !0 })?.getImageData(0, 0, e.width, e.height);
|
|
1922
1980
|
} catch {
|
|
1923
1981
|
return;
|
|
1924
1982
|
}
|
|
1925
1983
|
}
|
|
1926
|
-
async function
|
|
1984
|
+
async function Vn(e) {
|
|
1927
1985
|
let t = [];
|
|
1928
1986
|
if (e instanceof Blob && t.push(e), e instanceof HTMLCanvasElement) {
|
|
1929
|
-
let n =
|
|
1987
|
+
let n = Bn(e);
|
|
1930
1988
|
n && t.push(n);
|
|
1931
1989
|
try {
|
|
1932
|
-
t.push(await
|
|
1990
|
+
t.push(await Ye(e, "image/png"));
|
|
1933
1991
|
} catch {}
|
|
1934
1992
|
} else if (!(e instanceof Blob)) try {
|
|
1935
|
-
let n =
|
|
1993
|
+
let n = Bn(await N(e, { cloneCanvas: !1 }));
|
|
1936
1994
|
n && t.push(n);
|
|
1937
1995
|
} catch {}
|
|
1938
1996
|
return t;
|
|
1939
1997
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1998
|
+
var H;
|
|
1999
|
+
async function Hn() {
|
|
2000
|
+
return H ||= (async () => {
|
|
2001
|
+
let [e, t] = await Promise.all([import("zxing-wasm/reader"), Nn()]);
|
|
2002
|
+
return await e.prepareZXingModule({
|
|
2003
|
+
overrides: { wasmBinary: t },
|
|
2004
|
+
fireImmediately: !0
|
|
2005
|
+
}), e;
|
|
2006
|
+
})().catch((e) => {
|
|
2007
|
+
throw H = void 0, e instanceof Error && e.message, console.error("[exige-scanner] zxing-wasm failed to load", e), new V(e);
|
|
2008
|
+
}), H;
|
|
2009
|
+
}
|
|
2010
|
+
async function Un() {
|
|
2011
|
+
await Hn();
|
|
2012
|
+
}
|
|
2013
|
+
async function Wn(e) {
|
|
2014
|
+
let { readBarcodes: t } = await Hn();
|
|
2015
|
+
for (let n of await Vn(e)) {
|
|
2016
|
+
let e = (await t(n, {
|
|
1948
2017
|
formats: ["PDF417"],
|
|
1949
2018
|
tryHarder: !0,
|
|
2019
|
+
tryRotate: !0,
|
|
2020
|
+
tryInvert: !0,
|
|
1950
2021
|
tryDownscale: !0,
|
|
1951
2022
|
downscaleFactor: 2,
|
|
1952
2023
|
downscaleThreshold: 300,
|
|
@@ -1955,7 +2026,7 @@ async function Pn(e) {
|
|
|
1955
2026
|
if (e) return e;
|
|
1956
2027
|
}
|
|
1957
2028
|
}
|
|
1958
|
-
function
|
|
2029
|
+
function U(e, t) {
|
|
1959
2030
|
let n = Math.max(e.width, e.height);
|
|
1960
2031
|
if (n <= t) return e;
|
|
1961
2032
|
let r = t / n, i = document.createElement("canvas");
|
|
@@ -1963,39 +2034,67 @@ function Fn(e, t) {
|
|
|
1963
2034
|
let a = i.getContext("2d", { willReadFrequently: !0 }) ?? i.getContext("2d");
|
|
1964
2035
|
return a && (a.imageSmoothingEnabled = !0, "imageSmoothingQuality" in a && (a.imageSmoothingQuality = "high"), a.drawImage(e, 0, 0, i.width, i.height)), i;
|
|
1965
2036
|
}
|
|
1966
|
-
function
|
|
1967
|
-
|
|
2037
|
+
function Gn(e, t, n) {
|
|
2038
|
+
let r = Math.max(0, Math.round(e.height * t)), i = Math.max(1, Math.round(e.height * n) - r), a = document.createElement("canvas");
|
|
2039
|
+
a.width = e.width, a.height = i;
|
|
2040
|
+
let o = a.getContext("2d", { willReadFrequently: !0 }) ?? a.getContext("2d");
|
|
2041
|
+
return o && o.drawImage(e, 0, r, e.width, i, 0, 0, e.width, i), a;
|
|
2042
|
+
}
|
|
2043
|
+
function Kn(e) {
|
|
2044
|
+
return Ln(e.width, e.height).map((t) => U(e, t));
|
|
2045
|
+
}
|
|
2046
|
+
function qn(e) {
|
|
2047
|
+
if (e.height < e.width * 1.15 || e.height < 120) return [];
|
|
2048
|
+
let t = [];
|
|
2049
|
+
for (let [n, r] of In) {
|
|
2050
|
+
let i = Gn(e, n, r);
|
|
2051
|
+
t.push(U(i, Pn));
|
|
2052
|
+
let a = Ln(i.width, i.height).find((e) => e <= 960);
|
|
2053
|
+
a && t.push(U(i, a));
|
|
2054
|
+
}
|
|
2055
|
+
return t;
|
|
2056
|
+
}
|
|
2057
|
+
function Jn(e) {
|
|
2058
|
+
let t = /* @__PURE__ */ new Set(), n = [];
|
|
2059
|
+
for (let r of [...qn(e), ...Kn(e)]) {
|
|
2060
|
+
let e = `${r.width}x${r.height}`;
|
|
2061
|
+
t.has(e) || (t.add(e), n.push(r));
|
|
2062
|
+
}
|
|
2063
|
+
return n;
|
|
1968
2064
|
}
|
|
1969
|
-
async function
|
|
2065
|
+
async function W(e) {
|
|
1970
2066
|
let t;
|
|
1971
2067
|
try {
|
|
1972
|
-
t = await
|
|
2068
|
+
t = await N(e, { cloneCanvas: !1 });
|
|
1973
2069
|
} catch {
|
|
1974
2070
|
t = e instanceof HTMLCanvasElement ? e : document.createElement("canvas");
|
|
1975
2071
|
}
|
|
1976
|
-
let n = t.width && t.height ?
|
|
2072
|
+
let n = t.width && t.height ? Jn(t) : [];
|
|
1977
2073
|
for (let e of n) try {
|
|
1978
|
-
let t = await
|
|
2074
|
+
let t = await Wn(e);
|
|
1979
2075
|
if (t) return {
|
|
1980
2076
|
text: t,
|
|
1981
2077
|
source: "zxing-wasm"
|
|
1982
2078
|
};
|
|
1983
|
-
} catch {
|
|
2079
|
+
} catch (e) {
|
|
2080
|
+
if (e instanceof V) throw e;
|
|
2081
|
+
}
|
|
1984
2082
|
if (e instanceof Blob) try {
|
|
1985
|
-
let t = await
|
|
2083
|
+
let t = await Wn(e);
|
|
1986
2084
|
return t ? {
|
|
1987
2085
|
text: t,
|
|
1988
2086
|
source: "zxing-wasm"
|
|
1989
2087
|
} : void 0;
|
|
1990
|
-
} catch {
|
|
2088
|
+
} catch (e) {
|
|
2089
|
+
if (e instanceof V) throw e;
|
|
1991
2090
|
return;
|
|
1992
2091
|
}
|
|
1993
2092
|
}
|
|
1994
|
-
var
|
|
2093
|
+
var G = new Set(/* @__PURE__ */ "DCA.DCB.DCD.DBA.DCS.DAC.DAD.DBD.DBB.DBC.DAY.DAU.DAG.DAI.DAJ.DAK.DAQ.DCF.DCG.DDE.DDF.DDG.DAH.DAZ.DCI.DCJ.DCK.DBN.DBG.DBS.DCU.DCE.DCL.DCM.DCN.DCO.DCP.DCQ.DCR.DDA.DDB.DDC.DDD.DAW.DAX.DDH.DDI.DDJ.DDK.DDL.DCT.DAL.DAM.DAN.DAO.DAR.DAS.DAT.DAV.DBH.DBI.DBJ.DBK.DBL.DBM.DCH".split(".")), Yn = /* @__PURE__ */ "issuerJurisdiction.expirationDate.documentNumber.firstName.middleName.lastName.dateOfBirth.sex.eyeColor.height.addressStreet.addressCity.addressPostalCode.issueDate.country.addressStreet2.hairColor.nameSuffix.vehicleClass.restrictionCodes.endorsementCodes.documentDiscriminator.inventoryControlNumber.raceEthnicity.organDonor.veteran.weight".split("."), Xn = /* @__PURE__ */ new Set([
|
|
1995
2094
|
"expirationDate",
|
|
1996
2095
|
"dateOfBirth",
|
|
1997
2096
|
"issueDate"
|
|
1998
|
-
]),
|
|
2097
|
+
]), Zn = {
|
|
1999
2098
|
DAJ: "issuerJurisdiction",
|
|
2000
2099
|
DBA: "expirationDate",
|
|
2001
2100
|
DAQ: "documentNumber",
|
|
@@ -2027,34 +2126,34 @@ var W = new Set(/* @__PURE__ */ "DCA.DCB.DCD.DBA.DCS.DAC.DAD.DBD.DBB.DBC.DAY.DAU
|
|
|
2027
2126
|
DAW: "weight",
|
|
2028
2127
|
DAX: "weight"
|
|
2029
2128
|
};
|
|
2030
|
-
function
|
|
2129
|
+
function K(e, t, n) {
|
|
2031
2130
|
let r = Number(e), i = Number(t), a = Number(n);
|
|
2032
2131
|
if (Number.isInteger(r) && Number.isInteger(i) && Number.isInteger(a) && !(r < 1900 || r > 2100 || i < 1 || i > 12 || a < 1 || a > 31)) return `${String(r).padStart(4, "0")}-${String(i).padStart(2, "0")}-${String(a).padStart(2, "0")}`;
|
|
2033
2132
|
}
|
|
2034
|
-
function
|
|
2133
|
+
function Qn(e, t) {
|
|
2035
2134
|
return t ? e >= 30 ? 1900 + e : 2e3 + e : e >= 50 ? 1900 + e : 2e3 + e;
|
|
2036
2135
|
}
|
|
2037
|
-
function
|
|
2136
|
+
function q(e, t = !1) {
|
|
2038
2137
|
let n = e.trim();
|
|
2039
2138
|
if (!n) return;
|
|
2040
2139
|
let r = /^(\d{1,2})[/-](\d{1,2})[/-](\d{2,4})$/.exec(n);
|
|
2041
2140
|
if (r) {
|
|
2042
2141
|
let e = r[1], n = r[2], i = r[3];
|
|
2043
|
-
return i.length === 2 && (i = String(
|
|
2142
|
+
return i.length === 2 && (i = String(Qn(Number(i), t))), K(i, e.padStart(2, "0"), n.padStart(2, "0"));
|
|
2044
2143
|
}
|
|
2045
2144
|
let i = /^(\d{4})-(\d{2})-(\d{2})$/.exec(n);
|
|
2046
|
-
if (i) return
|
|
2145
|
+
if (i) return K(i[1], i[2], i[3]);
|
|
2047
2146
|
let a = n.replace(/[^\d]/g, "");
|
|
2048
2147
|
if (a.length === 8) {
|
|
2049
2148
|
let e = Number(a.slice(0, 4));
|
|
2050
|
-
return e >= 1900 && e <= 2100 ?
|
|
2149
|
+
return e >= 1900 && e <= 2100 ? K(a.slice(0, 4), a.slice(4, 6), a.slice(6, 8)) : K(a.slice(4, 8), a.slice(0, 2), a.slice(2, 4));
|
|
2051
2150
|
}
|
|
2052
2151
|
if (a.length === 6) {
|
|
2053
|
-
let e =
|
|
2054
|
-
return
|
|
2152
|
+
let e = Qn(Number(a.slice(4, 6)), t);
|
|
2153
|
+
return K(String(e), a.slice(0, 2), a.slice(2, 4));
|
|
2055
2154
|
}
|
|
2056
2155
|
}
|
|
2057
|
-
function
|
|
2156
|
+
function $n(e) {
|
|
2058
2157
|
let t = e.trim();
|
|
2059
2158
|
if (!t || t === "@") return "";
|
|
2060
2159
|
if (/^(ANSI|AAMVA)\b/.test(t)) {
|
|
@@ -2063,14 +2162,14 @@ function Vn(e) {
|
|
|
2063
2162
|
}
|
|
2064
2163
|
return t;
|
|
2065
2164
|
}
|
|
2066
|
-
function
|
|
2067
|
-
return (e.startsWith("DL") || e.startsWith("ID") || e.startsWith("ZV")) && e.length >= 5 &&
|
|
2165
|
+
function er(e) {
|
|
2166
|
+
return (e.startsWith("DL") || e.startsWith("ID") || e.startsWith("ZV")) && e.length >= 5 && G.has(e.slice(2, 5)) ? e.slice(2) : e;
|
|
2068
2167
|
}
|
|
2069
|
-
function
|
|
2168
|
+
function tr(e, t) {
|
|
2070
2169
|
let n = 0;
|
|
2071
2170
|
for (; n < e.length;) {
|
|
2072
2171
|
let r = e.slice(n, n + 3);
|
|
2073
|
-
if (!
|
|
2172
|
+
if (!G.has(r)) {
|
|
2074
2173
|
n += 1;
|
|
2075
2174
|
continue;
|
|
2076
2175
|
}
|
|
@@ -2078,14 +2177,14 @@ function Un(e, t) {
|
|
|
2078
2177
|
let i = n;
|
|
2079
2178
|
for (; i < e.length;) {
|
|
2080
2179
|
let t = e.slice(i, i + 3);
|
|
2081
|
-
if (
|
|
2180
|
+
if (G.has(t) || e[i] === "\n" || e[i] === "\r" || e[i] === "") break;
|
|
2082
2181
|
i += 1;
|
|
2083
2182
|
}
|
|
2084
2183
|
let a = e.slice(n, i).trim();
|
|
2085
2184
|
(!(r in t) || a) && (t[r] = a), n = i, (e[n] === "\n" || e[n] === "\r" || e[n] === "") && (n += 1);
|
|
2086
2185
|
}
|
|
2087
2186
|
}
|
|
2088
|
-
function
|
|
2187
|
+
function nr(e) {
|
|
2089
2188
|
let t = /(?:ANSI|AAMVA)\s?(\d{6})(\d{2})(\d{2})(\d{2})/.exec(e);
|
|
2090
2189
|
if (t) return {
|
|
2091
2190
|
iin: t[1],
|
|
@@ -2093,22 +2192,22 @@ function Wn(e) {
|
|
|
2093
2192
|
jurisdictionVersion: t[3]
|
|
2094
2193
|
};
|
|
2095
2194
|
}
|
|
2096
|
-
function
|
|
2195
|
+
function rr(e) {
|
|
2097
2196
|
let t = e.replace(/\r\n/g, "\n").replace(/\r/g, "\n"), n = {}, r = t.split("\n").flatMap((e) => e.split(""));
|
|
2098
2197
|
if (r.some((e) => {
|
|
2099
|
-
let t =
|
|
2100
|
-
return
|
|
2198
|
+
let t = er($n(e));
|
|
2199
|
+
return G.has(t.slice(0, 3));
|
|
2101
2200
|
})) {
|
|
2102
2201
|
for (let e of r) {
|
|
2103
|
-
let t =
|
|
2104
|
-
t &&
|
|
2202
|
+
let t = er($n(e));
|
|
2203
|
+
t && tr(t, n);
|
|
2105
2204
|
}
|
|
2106
2205
|
return n;
|
|
2107
2206
|
}
|
|
2108
|
-
return
|
|
2207
|
+
return tr(t, n), n;
|
|
2109
2208
|
}
|
|
2110
|
-
function
|
|
2111
|
-
if (
|
|
2209
|
+
function ir(e, t) {
|
|
2210
|
+
if (Xn.has(t)) return q(e, t === "dateOfBirth") ?? e.trim();
|
|
2112
2211
|
if (t === "issuerJurisdiction" || t === "country") return e.trim().toUpperCase();
|
|
2113
2212
|
if (t === "addressPostalCode") {
|
|
2114
2213
|
let t = e.trim();
|
|
@@ -2116,11 +2215,11 @@ function Kn(e, t) {
|
|
|
2116
2215
|
}
|
|
2117
2216
|
return e.trim();
|
|
2118
2217
|
}
|
|
2119
|
-
function
|
|
2218
|
+
function ar(e) {
|
|
2120
2219
|
let t = {};
|
|
2121
2220
|
for (let [n, r] of Object.entries(e)) {
|
|
2122
|
-
let e =
|
|
2123
|
-
e && r.trim() && (t[e] || (t[e] =
|
|
2221
|
+
let e = Zn[n];
|
|
2222
|
+
e && r.trim() && (t[e] || (t[e] = ir(r, e)));
|
|
2124
2223
|
}
|
|
2125
2224
|
if (!t.firstName && e.DCT?.trim()) {
|
|
2126
2225
|
let n = e.DCT.trim().split(/\s+/);
|
|
@@ -2128,29 +2227,29 @@ function qn(e) {
|
|
|
2128
2227
|
}
|
|
2129
2228
|
return t;
|
|
2130
2229
|
}
|
|
2131
|
-
function
|
|
2132
|
-
let t =
|
|
2230
|
+
function or(e) {
|
|
2231
|
+
let t = rr(e);
|
|
2133
2232
|
return {
|
|
2134
2233
|
rawElements: t,
|
|
2135
|
-
fields:
|
|
2136
|
-
header:
|
|
2234
|
+
fields: ar(t),
|
|
2235
|
+
header: nr(e)
|
|
2137
2236
|
};
|
|
2138
2237
|
}
|
|
2139
|
-
function
|
|
2238
|
+
function sr() {
|
|
2140
2239
|
return {};
|
|
2141
2240
|
}
|
|
2142
|
-
function
|
|
2143
|
-
for (let r of
|
|
2241
|
+
function cr(e, t, n) {
|
|
2242
|
+
for (let r of Yn) t[r] && (e[r] = n);
|
|
2144
2243
|
return e;
|
|
2145
2244
|
}
|
|
2146
2245
|
//#endregion
|
|
2147
2246
|
//#region src/sdk/face-model.ts
|
|
2148
|
-
var
|
|
2149
|
-
function
|
|
2247
|
+
var lr = /* @__PURE__ */ new Map(), ur = 8400;
|
|
2248
|
+
function dr(e, t) {
|
|
2150
2249
|
let n = Math.max(0, Math.min(e.x + e.width, t.x + t.width) - Math.max(e.x, t.x)) * Math.max(0, Math.min(e.y + e.height, t.y + t.height) - Math.max(e.y, t.y));
|
|
2151
2250
|
return n / Math.max(1, e.width * e.height + t.width * t.height - n);
|
|
2152
2251
|
}
|
|
2153
|
-
function
|
|
2252
|
+
function fr(e, t, n, r, i, a, o) {
|
|
2154
2253
|
return {
|
|
2155
2254
|
x: (e - n / 2) / i * a,
|
|
2156
2255
|
y: (t - r / 2) / i * o,
|
|
@@ -2158,39 +2257,39 @@ function er(e, t, n, r, i, a, o) {
|
|
|
2158
2257
|
height: r / i * o
|
|
2159
2258
|
};
|
|
2160
2259
|
}
|
|
2161
|
-
function
|
|
2260
|
+
function pr(e, t, n) {
|
|
2162
2261
|
let r = t.length === 3 ? t[1] : t[0], i = t.length === 3 ? t[2] : t[1];
|
|
2163
|
-
if (i !== 6 || r < 1) throw Error(`Face model expects [1, anchors, 6]. A 640 YOLOX-Nano face export is [1, ${
|
|
2262
|
+
if (i !== 6 || r < 1) throw Error(`Face model expects [1, anchors, 6]. A 640 YOLOX-Nano face export is [1, ${ur}, 6].`);
|
|
2164
2263
|
let a = n.confidence ?? .35, o = n.inputSize ?? 640, s = [];
|
|
2165
2264
|
for (let t = 0; t < r; t += 1) {
|
|
2166
2265
|
let r = t * i, c = e[r + 4] * e[r + 5];
|
|
2167
2266
|
c < a || s.push({
|
|
2168
2267
|
confidence: c,
|
|
2169
|
-
bbox:
|
|
2268
|
+
bbox: fr(e[r], e[r + 1], e[r + 2], e[r + 3], o, n.imageWidth, n.imageHeight)
|
|
2170
2269
|
});
|
|
2171
2270
|
}
|
|
2172
|
-
return s.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) =>
|
|
2271
|
+
return s.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => dr(e.bbox, t.bbox) < .45)).slice(0, 8);
|
|
2173
2272
|
}
|
|
2174
|
-
async function
|
|
2175
|
-
let i = await
|
|
2273
|
+
async function mr(e, n, r = .35) {
|
|
2274
|
+
let i = await N(e, { cloneCanvas: !1 }), a = await import("onnxruntime-web"), o = document.createElement("canvas");
|
|
2176
2275
|
o.width = 640, o.height = 640;
|
|
2177
2276
|
let s = o.getContext("2d", { willReadFrequently: !0 });
|
|
2178
2277
|
if (!s) throw t();
|
|
2179
2278
|
s.drawImage(i, 0, 0, 640, 640);
|
|
2180
2279
|
let c = s.getImageData(0, 0, 640, 640).data, l = 409600, u = new Float32Array(l * 3);
|
|
2181
2280
|
for (let e = 0; e < l; e += 1) u[e] = c[e * 4] / 255, u[l + e] = c[e * 4 + 1] / 255, u[l * 2 + e] = c[e * 4 + 2] / 255;
|
|
2182
|
-
let d =
|
|
2281
|
+
let d = lr.get(n);
|
|
2183
2282
|
d || (d = a.InferenceSession.create(n, {
|
|
2184
2283
|
executionProviders: ["wasm"],
|
|
2185
2284
|
graphOptimizationLevel: "all"
|
|
2186
|
-
}),
|
|
2285
|
+
}), lr.set(n, d));
|
|
2187
2286
|
let f = await d, p = (await f.run({ [f.inputNames[0]]: new a.Tensor("float32", u, [
|
|
2188
2287
|
1,
|
|
2189
2288
|
3,
|
|
2190
2289
|
640,
|
|
2191
2290
|
640
|
|
2192
2291
|
]) }))[f.outputNames[0]];
|
|
2193
|
-
return
|
|
2292
|
+
return pr(p.data, p.dims.map(Number), {
|
|
2194
2293
|
confidence: r,
|
|
2195
2294
|
imageWidth: i.width,
|
|
2196
2295
|
imageHeight: i.height,
|
|
@@ -2199,7 +2298,7 @@ async function nr(e, n, r = .35) {
|
|
|
2199
2298
|
}
|
|
2200
2299
|
//#endregion
|
|
2201
2300
|
//#region src/sdk/field-model.ts
|
|
2202
|
-
var
|
|
2301
|
+
var hr = /* @__PURE__ */ new Map(), gr = [
|
|
2203
2302
|
"person_name",
|
|
2204
2303
|
"date_of_birth",
|
|
2205
2304
|
"address",
|
|
@@ -2207,19 +2306,19 @@ var q = /* @__PURE__ */ new Map(), rr = [
|
|
|
2207
2306
|
"expiration_date",
|
|
2208
2307
|
"postal_code",
|
|
2209
2308
|
"state"
|
|
2210
|
-
],
|
|
2211
|
-
function
|
|
2309
|
+
], _r = 8400;
|
|
2310
|
+
function vr(e) {
|
|
2212
2311
|
return 5 + e;
|
|
2213
2312
|
}
|
|
2214
|
-
var
|
|
2215
|
-
function
|
|
2313
|
+
var yr = 640;
|
|
2314
|
+
function br(e, t) {
|
|
2216
2315
|
let n = Math.max(0, Math.min(e.bbox.x + e.bbox.width, t.bbox.x + t.bbox.width) - Math.max(e.bbox.x, t.bbox.x)) * Math.max(0, Math.min(e.bbox.y + e.bbox.height, t.bbox.y + t.bbox.height) - Math.max(e.bbox.y, t.bbox.y));
|
|
2217
2316
|
return n / Math.max(1, e.bbox.width * e.bbox.height + t.bbox.width * t.bbox.height - n);
|
|
2218
2317
|
}
|
|
2219
|
-
function
|
|
2220
|
-
return e.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => t.field !== e.field ||
|
|
2318
|
+
function xr(e) {
|
|
2319
|
+
return e.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => t.field !== e.field || br(e, t) < .45)).slice(0, 30);
|
|
2221
2320
|
}
|
|
2222
|
-
function
|
|
2321
|
+
function Sr(e, t, n, r, i, a, o) {
|
|
2223
2322
|
return {
|
|
2224
2323
|
x: (e - n / 2) / i * a,
|
|
2225
2324
|
y: (t - r / 2) / i * o,
|
|
@@ -2227,8 +2326,8 @@ function lr(e, t, n, r, i, a, o) {
|
|
|
2227
2326
|
height: r / i * o
|
|
2228
2327
|
};
|
|
2229
2328
|
}
|
|
2230
|
-
function
|
|
2231
|
-
let n =
|
|
2329
|
+
function Cr(e, t) {
|
|
2330
|
+
let n = vr(t);
|
|
2232
2331
|
return e.length === 3 && e[0] === 1 && e[2] === n && e[1] > e[2] ? {
|
|
2233
2332
|
anchors: e[1],
|
|
2234
2333
|
features: n
|
|
@@ -2237,15 +2336,15 @@ function ur(e, t) {
|
|
|
2237
2336
|
features: n
|
|
2238
2337
|
} : null;
|
|
2239
2338
|
}
|
|
2240
|
-
function
|
|
2339
|
+
function wr(e) {
|
|
2241
2340
|
return e.length === 3 && e[1] >= 5 && e[2] >= 1;
|
|
2242
2341
|
}
|
|
2243
|
-
function
|
|
2244
|
-
let t =
|
|
2245
|
-
return /* @__PURE__ */ Error(`YOLOX field layout expects [1, anchors, ${t}] (cx, cy, w, h, objectness, ${e} class scores). A 640 YOLOX-Nano export with decode baked in is [1, ${
|
|
2342
|
+
function Tr(e) {
|
|
2343
|
+
let t = vr(e);
|
|
2344
|
+
return /* @__PURE__ */ Error(`YOLOX field layout expects [1, anchors, ${t}] (cx, cy, w, h, objectness, ${e} class scores). A 640 YOLOX-Nano export with decode baked in is [1, ${_r}, ${t}].`);
|
|
2246
2345
|
}
|
|
2247
|
-
function
|
|
2248
|
-
if (!
|
|
2346
|
+
function Er(e, t, n, r, i, a, o) {
|
|
2347
|
+
if (!wr(t)) throw Error("Unsupported field-model YOLO output shape.");
|
|
2249
2348
|
let s = t[1], c = t[2], l = [];
|
|
2250
2349
|
for (let t = 0; t < c; t += 1) {
|
|
2251
2350
|
let u = 0, d = 0;
|
|
@@ -2257,14 +2356,14 @@ function pr(e, t, n, r, i, a, o) {
|
|
|
2257
2356
|
!f || u < r || l.push({
|
|
2258
2357
|
field: f,
|
|
2259
2358
|
confidence: u,
|
|
2260
|
-
bbox:
|
|
2359
|
+
bbox: Sr(e[t], e[c + t], e[c * 2 + t], e[c * 3 + t], i, a, o)
|
|
2261
2360
|
});
|
|
2262
2361
|
}
|
|
2263
|
-
return
|
|
2362
|
+
return xr(l);
|
|
2264
2363
|
}
|
|
2265
|
-
function
|
|
2266
|
-
let s =
|
|
2267
|
-
if (!s) throw
|
|
2364
|
+
function Dr(e, t, n, r, i, a, o) {
|
|
2365
|
+
let s = Cr(t, n.length);
|
|
2366
|
+
if (!s) throw Tr(n.length);
|
|
2268
2367
|
let c = [];
|
|
2269
2368
|
for (let t = 0; t < s.anchors; t += 1) {
|
|
2270
2369
|
let l = t * s.features, u = e[l + 4], d = 0, f = 0;
|
|
@@ -2276,43 +2375,43 @@ function mr(e, t, n, r, i, a, o) {
|
|
|
2276
2375
|
!p || m < r || c.push({
|
|
2277
2376
|
field: p,
|
|
2278
2377
|
confidence: m,
|
|
2279
|
-
bbox:
|
|
2378
|
+
bbox: Sr(e[l], e[l + 1], e[l + 2], e[l + 3], i, a, o)
|
|
2280
2379
|
});
|
|
2281
2380
|
}
|
|
2282
|
-
return
|
|
2381
|
+
return xr(c);
|
|
2283
2382
|
}
|
|
2284
|
-
function
|
|
2285
|
-
let r = n.classes ??
|
|
2383
|
+
function Or(e, t, n) {
|
|
2384
|
+
let r = n.classes ?? gr, i = n.confidence ?? .35, a = n.inputSize ?? yr, o = Cr(t, r.length);
|
|
2286
2385
|
if (n.layout === "yolov8" && o) throw Error("This tensor is YOLOX [1, anchors, 5+classes]. Pass fieldLayout: 'yolox', or omit fieldLayout to detect it from the shape.");
|
|
2287
|
-
return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ?
|
|
2386
|
+
return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ? Dr(e, t, r, i, a, n.imageWidth, n.imageHeight) : Er(e, t, r, i, a, n.imageWidth, n.imageHeight);
|
|
2288
2387
|
}
|
|
2289
|
-
async function
|
|
2290
|
-
let o = await
|
|
2388
|
+
async function kr(e, n, r = gr, i = .35, a) {
|
|
2389
|
+
let o = await N(e, { cloneCanvas: !1 }), s = import("onnxruntime-web"), c = yr, l = document.createElement("canvas");
|
|
2291
2390
|
l.width = c, l.height = c;
|
|
2292
2391
|
let u = l.getContext("2d", { willReadFrequently: !0 });
|
|
2293
2392
|
if (!u) throw t();
|
|
2294
2393
|
u.drawImage(o, 0, 0, c, c);
|
|
2295
2394
|
let d = u.getImageData(0, 0, c, c).data, f = c * c, p = new Float32Array(f * 3);
|
|
2296
2395
|
for (let e = 0; e < f; e += 1) p[e] = d[e * 4] / 255, p[f + e] = d[e * 4 + 1] / 255, p[f * 2 + e] = d[e * 4 + 2] / 255;
|
|
2297
|
-
let m =
|
|
2396
|
+
let m = hr.get(n);
|
|
2298
2397
|
m || (m = (async () => {
|
|
2299
2398
|
try {
|
|
2300
|
-
let [e, t] = await Promise.all([s,
|
|
2399
|
+
let [e, t] = await Promise.all([s, se(n)]);
|
|
2301
2400
|
return await e.InferenceSession.create(t, {
|
|
2302
2401
|
executionProviders: ["wasm"],
|
|
2303
2402
|
graphOptimizationLevel: "all"
|
|
2304
2403
|
});
|
|
2305
2404
|
} catch (e) {
|
|
2306
|
-
throw
|
|
2405
|
+
throw hr.delete(n), e;
|
|
2307
2406
|
}
|
|
2308
|
-
})(),
|
|
2407
|
+
})(), hr.set(n, m));
|
|
2309
2408
|
let [h, g] = await Promise.all([s, m]), _ = (await g.run({ [g.inputNames[0]]: new h.Tensor("float32", p, [
|
|
2310
2409
|
1,
|
|
2311
2410
|
3,
|
|
2312
2411
|
c,
|
|
2313
2412
|
c
|
|
2314
2413
|
]) }))[g.outputNames[0]];
|
|
2315
|
-
return
|
|
2414
|
+
return Or(_.data, _.dims.map(Number), {
|
|
2316
2415
|
classes: r,
|
|
2317
2416
|
confidence: i,
|
|
2318
2417
|
layout: a,
|
|
@@ -2323,12 +2422,12 @@ async function gr(e, n, r = rr, i = .35, a) {
|
|
|
2323
2422
|
}
|
|
2324
2423
|
//#endregion
|
|
2325
2424
|
//#region src/sdk/redact.ts
|
|
2326
|
-
async function
|
|
2425
|
+
async function Ar(e, n, r = {}) {
|
|
2327
2426
|
await x("redaction");
|
|
2328
|
-
let i = await
|
|
2427
|
+
let i = await N(e), a = i.getContext("2d");
|
|
2329
2428
|
if (!a) throw t();
|
|
2330
2429
|
for (let e of n) {
|
|
2331
|
-
let t =
|
|
2430
|
+
let t = Xe(e, i.width, i.height);
|
|
2332
2431
|
if (t.width < 1 || t.height < 1) continue;
|
|
2333
2432
|
if ((e.mode ?? r.mode ?? "blackout") === "blackout") {
|
|
2334
2433
|
a.fillStyle = "#050706", a.fillRect(t.x, t.y, t.width, t.height);
|
|
@@ -2344,7 +2443,7 @@ async function _r(e, n, r = {}) {
|
|
|
2344
2443
|
}
|
|
2345
2444
|
return {
|
|
2346
2445
|
canvas: i,
|
|
2347
|
-
blob: await
|
|
2446
|
+
blob: await Ye(i, r.mimeType ?? "image/png", r.quality)
|
|
2348
2447
|
};
|
|
2349
2448
|
}
|
|
2350
2449
|
//#endregion
|
|
@@ -2358,7 +2457,7 @@ function J(e) {
|
|
|
2358
2457
|
height: i - n
|
|
2359
2458
|
};
|
|
2360
2459
|
}
|
|
2361
|
-
function
|
|
2460
|
+
function jr(e) {
|
|
2362
2461
|
let t = [], n = [...e].sort((e, t) => e.bbox.y + e.bbox.height / 2 - (t.bbox.y + t.bbox.height / 2) || e.bbox.x - t.bbox.x);
|
|
2363
2462
|
for (let e of n) {
|
|
2364
2463
|
let n = e.bbox.y + e.bbox.height / 2, r = t.find((t) => {
|
|
@@ -2380,7 +2479,7 @@ function Y(e, t, n = !1) {
|
|
|
2380
2479
|
function X(e) {
|
|
2381
2480
|
return e.reduce((e, t) => e + t.confidence, 0) / Math.max(1, e.length);
|
|
2382
2481
|
}
|
|
2383
|
-
function
|
|
2482
|
+
function Mr(e, t) {
|
|
2384
2483
|
let n = e.mode, r = n === "case-insensitive", i = e.scope ?? "line", a;
|
|
2385
2484
|
if (n === "regex") {
|
|
2386
2485
|
let t = e.pattern ?? e.values?.[0];
|
|
@@ -2417,22 +2516,22 @@ function yr(e, t) {
|
|
|
2417
2516
|
}
|
|
2418
2517
|
return s;
|
|
2419
2518
|
}
|
|
2420
|
-
function
|
|
2519
|
+
function Nr(e, t) {
|
|
2421
2520
|
let n = e.labelMode !== "exact", r = Y(e.label, n, !0).split(" ");
|
|
2422
2521
|
for (let e of t) for (let t = 0; t <= e.words.length - r.length; t += 1) {
|
|
2423
2522
|
let i = e.words.slice(t, t + r.length);
|
|
2424
2523
|
if (i.every((e, t) => Y(e.text, n, !0) === r[t])) return i;
|
|
2425
2524
|
}
|
|
2426
2525
|
}
|
|
2427
|
-
function
|
|
2526
|
+
function Pr(e, t, n, r, i, a) {
|
|
2428
2527
|
let o = a.window?.distance ?? .28, s = a.window?.crossAxis ?? .12, c = t.x + t.width / 2, l = t.y + t.height / 2;
|
|
2429
2528
|
return e.filter((e) => {
|
|
2430
2529
|
let a = e.bbox.x + e.bbox.width / 2, u = e.bbox.y + e.bbox.height / 2;
|
|
2431
2530
|
return n === "right" ? e.bbox.x >= t.x + t.width && e.bbox.x - t.x - t.width <= r * o && Math.abs(u - l) <= i * s : n === "left" ? e.bbox.x + e.bbox.width <= t.x && t.x - e.bbox.x - e.bbox.width <= r * o && Math.abs(u - l) <= i * s : n === "below" ? e.bbox.y >= t.y + t.height && e.bbox.y - t.y - t.height <= i * o && Math.abs(a - c) <= r * s : e.bbox.y + e.bbox.height <= t.y && t.y - e.bbox.y - e.bbox.height <= i * o && Math.abs(a - c) <= r * s;
|
|
2432
2531
|
});
|
|
2433
2532
|
}
|
|
2434
|
-
function
|
|
2435
|
-
let o =
|
|
2533
|
+
function Fr(e, t, n, r, i, a = "label") {
|
|
2534
|
+
let o = Nr(e, n);
|
|
2436
2535
|
if (!o) return [];
|
|
2437
2536
|
let s = J(o), c = new Set(o), l = t.filter((e) => !c.has(e)), u = e.direction === "any" ? [
|
|
2438
2537
|
"right",
|
|
@@ -2441,7 +2540,7 @@ function Sr(e, t, n, r, i, a = "label") {
|
|
|
2441
2540
|
"above"
|
|
2442
2541
|
] : [e.direction], d;
|
|
2443
2542
|
for (let t of u) {
|
|
2444
|
-
let n =
|
|
2543
|
+
let n = jr(Pr(l, s, t, r, i, e));
|
|
2445
2544
|
for (let t of n) {
|
|
2446
2545
|
if (e.valuePattern && !new RegExp(e.valuePattern, e.patternFlags).test(t.text)) continue;
|
|
2447
2546
|
let n = t.bbox.x + t.bbox.width / 2, a = t.bbox.y + t.bbox.height / 2, o = s.x + s.width / 2, c = s.y + s.height / 2, l = Math.hypot((n - o) / r, (a - c) / i);
|
|
@@ -2462,7 +2561,7 @@ function Sr(e, t, n, r, i, a = "label") {
|
|
|
2462
2561
|
confidence: Math.max(0, X(d.words) * (1 - Math.min(.5, d.distance)))
|
|
2463
2562
|
}];
|
|
2464
2563
|
}
|
|
2465
|
-
var
|
|
2564
|
+
var Ir = {
|
|
2466
2565
|
person_name: [
|
|
2467
2566
|
"LN",
|
|
2468
2567
|
"FN",
|
|
@@ -2499,10 +2598,10 @@ var Cr = {
|
|
|
2499
2598
|
"POSTAL"
|
|
2500
2599
|
],
|
|
2501
2600
|
state: ["STATE", "DAJ"]
|
|
2502
|
-
},
|
|
2601
|
+
}, Lr = new Set(Object.values(Ir).flat()), Rr = /^(?:\d{2}[/-]\d{2}[/-]\d{2,4}|\d{4}[/-]\d{2}[/-]\d{2}|\d{6}|\d{8})$/, zr = /\b(?:ST|STREET|AVE|AVENUE|RD|ROAD|BLVD|BOULEVARD|LN|LANE|DR|DRIVE|WAY|CT|COURT)\b/i, Br = /\b(?:DRIVER|LICENSE|IDENTIFICATION|CARD|CLASS|SEX|EYES|HEIGHT|RESTRICTIONS)\b/i;
|
|
2503
2602
|
function Z(e, t) {
|
|
2504
2603
|
let n = t.trim();
|
|
2505
|
-
return n ? e === "date_of_birth" || e === "expiration_date" ?
|
|
2604
|
+
return n ? e === "date_of_birth" || e === "expiration_date" ? Rr.test(n.replace(/\s/g, "")) : e === "postal_code" ? /^(?:\d{5}(?:-\d{4})?|[A-Z]\d[A-Z]\s?\d[A-Z]\d)$/i.test(n) : e === "state" ? /^[A-Z]{2}$/i.test(n) : e === "document_number" ? /^(?=.*\d)[A-Z0-9-]{5,20}$/i.test(n) : e === "person_name" ? !/\d/.test(n) && /^[A-ZÀ-ÖØ-öø-ÿ' -]{3,}$/i.test(n) && !Br.test(n) : /\d/.test(n) && /[A-Z]/i.test(n) : !1;
|
|
2506
2605
|
}
|
|
2507
2606
|
function Q(e, t, n, r, i = 1) {
|
|
2508
2607
|
return {
|
|
@@ -2514,17 +2613,17 @@ function Q(e, t, n, r, i = 1) {
|
|
|
2514
2613
|
confidence: Math.max(0, Math.min(1, X(n) * i))
|
|
2515
2614
|
};
|
|
2516
2615
|
}
|
|
2517
|
-
function
|
|
2518
|
-
let r =
|
|
2616
|
+
function Vr(e, t, n) {
|
|
2617
|
+
let r = Ir[e], i = [];
|
|
2519
2618
|
for (let a of n) for (let n = 0; n < a.words.length; n += 1) {
|
|
2520
2619
|
let o = a.words[n].text.toUpperCase().replace(/[^A-Z0-9]/g, ""), s = r.find((e) => o === e || o.startsWith(e));
|
|
2521
2620
|
if (!s) continue;
|
|
2522
2621
|
let c, l;
|
|
2523
|
-
o === s ? (c = a.words.slice(n + 1).filter((e) => !
|
|
2622
|
+
o === s ? (c = a.words.slice(n + 1).filter((e) => !Lr.has(e.text.toUpperCase().replace(/[^A-Z0-9]/g, ""))), l = c.map((e) => e.text).join(" ")) : (c = [a.words[n]], l = a.words[n].text.replace(RegExp(`^${s}[:\\s-]*`, "i"), "")), c.length && Z(e, l) && i.push(Q(t, "alias", c, l, .98));
|
|
2524
2623
|
}
|
|
2525
2624
|
return i;
|
|
2526
2625
|
}
|
|
2527
|
-
function
|
|
2626
|
+
function Hr(e, t, n) {
|
|
2528
2627
|
let r = n.filter((e) => {
|
|
2529
2628
|
let t = e.text.replace(/\s/g, "");
|
|
2530
2629
|
return t.includes("<<") || /^[A-Z0-9<]{25,}$/.test(t);
|
|
@@ -2546,7 +2645,7 @@ function kr(e, t, n) {
|
|
|
2546
2645
|
}
|
|
2547
2646
|
return [];
|
|
2548
2647
|
}
|
|
2549
|
-
function
|
|
2648
|
+
function Ur(e) {
|
|
2550
2649
|
let t = e.replace(/\s/g, ""), n = t.match(/\d{4}/)?.[0];
|
|
2551
2650
|
if (n) return Number(n);
|
|
2552
2651
|
let r = t.match(/^\d{2}/)?.[0];
|
|
@@ -2554,16 +2653,16 @@ function Ar(e) {
|
|
|
2554
2653
|
let i = Number(r);
|
|
2555
2654
|
return i > (/* @__PURE__ */ new Date()).getFullYear() % 100 ? 1900 + i : 2e3 + i;
|
|
2556
2655
|
}
|
|
2557
|
-
function
|
|
2656
|
+
function Wr(e, t, n, r, i) {
|
|
2558
2657
|
if (e === "address") {
|
|
2559
|
-
let e = r.findIndex((e) => /\d/.test(e.text) &&
|
|
2658
|
+
let e = r.findIndex((e) => /\d/.test(e.text) && zr.test(e.text));
|
|
2560
2659
|
if (e < 0) return [];
|
|
2561
2660
|
let n = [...r[e].words], i = r[e + 1];
|
|
2562
2661
|
return i && /(?:\b[A-Z]{2}\b.*\d{5}|\d{5})/i.test(i.text) && n.push(...i.words), [Q(t, "layout", n, void 0, .76)];
|
|
2563
2662
|
}
|
|
2564
2663
|
if (e === "person_name") {
|
|
2565
2664
|
let e = r.map((e) => {
|
|
2566
|
-
let t = e.words.filter((e) => /^[A-ZÀ-ÖØ-öø-ÿ'-]+$/i.test(e.text)), n = e.bbox.y / Math.max(1, i), r = t.length >= 2 && t.length <= 5 && t.length === e.words.length && !
|
|
2665
|
+
let t = e.words.filter((e) => /^[A-ZÀ-ÖØ-öø-ÿ'-]+$/i.test(e.text)), n = e.bbox.y / Math.max(1, i), r = t.length >= 2 && t.length <= 5 && t.length === e.words.length && !Br.test(e.text) && !zr.test(e.text) && !e.text.includes("<"), a = e.text.replace(/[^A-Z]/g, "").length / Math.max(1, e.text.replace(/[^A-Za-z]/g, "").length);
|
|
2567
2666
|
return {
|
|
2568
2667
|
line: e,
|
|
2569
2668
|
score: r ? .45 + X(e.words) * .3 + a * .15 + (n < .65 ? .1 : 0) : 0
|
|
@@ -2572,9 +2671,9 @@ function jr(e, t, n, r, i) {
|
|
|
2572
2671
|
return !e.length || e[1] && e[0].score - e[1].score < .04 ? [] : [Q(t, "layout", e[0].line.words, void 0, e[0].score)];
|
|
2573
2672
|
}
|
|
2574
2673
|
if (e === "date_of_birth" || e === "expiration_date") {
|
|
2575
|
-
let r = (/* @__PURE__ */ new Date()).getFullYear(), i = n.filter((e) =>
|
|
2674
|
+
let r = (/* @__PURE__ */ new Date()).getFullYear(), i = n.filter((e) => Rr.test(e.text.replace(/\s/g, ""))).map((e) => ({
|
|
2576
2675
|
word: e,
|
|
2577
|
-
year:
|
|
2676
|
+
year: Ur(e.text)
|
|
2578
2677
|
})).filter((e) => e.year !== void 0), a = e === "date_of_birth" ? i.filter((e) => e.year <= r - 14 && e.year >= r - 120) : i.filter((e) => e.year >= r - 1);
|
|
2579
2678
|
return a.sort((t, n) => e === "date_of_birth" ? t.year - n.year : n.year - t.year), a.length ? [Q(t, "layout", [a[0].word], void 0, .72)] : [];
|
|
2580
2679
|
}
|
|
@@ -2592,29 +2691,29 @@ function jr(e, t, n, r, i) {
|
|
|
2592
2691
|
}
|
|
2593
2692
|
return [];
|
|
2594
2693
|
}
|
|
2595
|
-
function
|
|
2694
|
+
function Gr(e, t) {
|
|
2596
2695
|
return Math.max(0, Math.min(e.x + e.width, t.x + t.width) - Math.max(e.x, t.x)) * Math.max(0, Math.min(e.y + e.height, t.y + t.height) - Math.max(e.y, t.y)) / Math.max(1, t.width * t.height);
|
|
2597
2696
|
}
|
|
2598
|
-
function
|
|
2599
|
-
let i =
|
|
2600
|
-
return i.length || a.length ? [...i, ...a] :
|
|
2697
|
+
function Kr(e, t, n, r) {
|
|
2698
|
+
let i = Vr(e.field, e.id, n), a = Hr(e.field, e.id, n);
|
|
2699
|
+
return i.length || a.length ? [...i, ...a] : Wr(e.field, e.id, t, n, r);
|
|
2601
2700
|
}
|
|
2602
|
-
function
|
|
2701
|
+
function qr(e, t, n) {
|
|
2603
2702
|
let r = (n ?? []).filter((t) => t.field === e.field).sort((e, t) => t.confidence - e.confidence);
|
|
2604
2703
|
for (let n of r) {
|
|
2605
|
-
let r = t.filter((e) =>
|
|
2704
|
+
let r = t.filter((e) => Gr(n.bbox, e.bbox) >= .3);
|
|
2606
2705
|
if (!r.length) continue;
|
|
2607
2706
|
let i = r.map((e) => e.text).join(" ");
|
|
2608
2707
|
if (Z(e.field, i)) return Q(e.id, "model", r, i, n.confidence);
|
|
2609
2708
|
}
|
|
2610
2709
|
}
|
|
2611
|
-
function
|
|
2612
|
-
let o =
|
|
2710
|
+
function Jr(e, t, n, r, i, a) {
|
|
2711
|
+
let o = Kr(e, t, n, r);
|
|
2613
2712
|
if (e.detector !== "model" || !a) return o;
|
|
2614
|
-
let s =
|
|
2713
|
+
let s = qr(e, t, i);
|
|
2615
2714
|
return s ? [s] : [];
|
|
2616
2715
|
}
|
|
2617
|
-
function
|
|
2716
|
+
function Yr(e, t, n, r) {
|
|
2618
2717
|
let i = (e) => Math.max(0, Math.min(1, e)), a = i(e.rect.x), o = i(e.rect.y);
|
|
2619
2718
|
return {
|
|
2620
2719
|
ruleId: `${t}.${e.id}`,
|
|
@@ -2629,19 +2728,19 @@ function Ir(e, t, n, r) {
|
|
|
2629
2728
|
confidence: 1
|
|
2630
2729
|
};
|
|
2631
2730
|
}
|
|
2632
|
-
function
|
|
2633
|
-
let n = t.imageWidth ?? e?.imageWidth ?? 0, r = t.imageHeight ?? e?.imageHeight ?? 0, i = e?.words ?? [], a =
|
|
2731
|
+
function Xr(e, t) {
|
|
2732
|
+
let n = t.imageWidth ?? e?.imageWidth ?? 0, r = t.imageHeight ?? e?.imageHeight ?? 0, i = e?.words ?? [], a = jr(i), o = [], s = [];
|
|
2634
2733
|
for (let e of t.rules) {
|
|
2635
|
-
let c = e.strategy === "string" ?
|
|
2734
|
+
let c = e.strategy === "string" ? Mr(e, a) : e.strategy === "label" ? Fr(e, i, a, n, r) : Jr(e, i, a, r, t.semanticDetections, t.modelRequested === !0);
|
|
2636
2735
|
c.length ? o.push(...c) : s.push(e.id);
|
|
2637
2736
|
}
|
|
2638
2737
|
for (let e of t.template?.fields ?? []) {
|
|
2639
2738
|
let c = `${t.template.id}.${e.id}`;
|
|
2640
2739
|
if (e.strategy === "rect") {
|
|
2641
|
-
n && r ? o.push(
|
|
2740
|
+
n && r ? o.push(Yr(e, t.template.id, n, r)) : s.push(c);
|
|
2642
2741
|
continue;
|
|
2643
2742
|
}
|
|
2644
|
-
let l =
|
|
2743
|
+
let l = Fr({
|
|
2645
2744
|
...e,
|
|
2646
2745
|
id: c,
|
|
2647
2746
|
strategy: "label"
|
|
@@ -2659,34 +2758,34 @@ function Lr(e, t) {
|
|
|
2659
2758
|
confidence: u
|
|
2660
2759
|
};
|
|
2661
2760
|
}
|
|
2662
|
-
function
|
|
2761
|
+
function Zr(e) {
|
|
2663
2762
|
return e.rules.length > 0 || e.template?.fields.some((e) => e.strategy === "anchor") === !0;
|
|
2664
2763
|
}
|
|
2665
|
-
function
|
|
2764
|
+
function Qr(e, t = !1) {
|
|
2666
2765
|
return t && !e.complete ? "unmatched" : e.complete ? "success" : "partial";
|
|
2667
2766
|
}
|
|
2668
|
-
async function
|
|
2767
|
+
async function $r(e, t) {
|
|
2669
2768
|
await x("redaction");
|
|
2670
|
-
let n = await
|
|
2671
|
-
|
|
2769
|
+
let n = await N(e, { cloneCanvas: !1 }), r = t.ocr;
|
|
2770
|
+
Zr(t) && !r && (r = await bn(n, { includeWords: !0 }));
|
|
2672
2771
|
let i = t.semanticDetections, a = t.modelRequested === !0, o = "not-requested", s;
|
|
2673
2772
|
if (t.models?.fields) try {
|
|
2674
|
-
i = await
|
|
2773
|
+
i = await kr(n, t.models.fields, t.models.fieldClasses, t.models.confidence, t.models.fieldLayout), a = !0, o = "loaded";
|
|
2675
2774
|
} catch (e) {
|
|
2676
2775
|
s = e instanceof Error ? e.message : "The field model could not load.";
|
|
2677
2776
|
let n = t.models.allowHeuristicFallback !== !1;
|
|
2678
2777
|
a = !n, o = n ? "fallback" : "failed";
|
|
2679
2778
|
}
|
|
2680
|
-
let c =
|
|
2779
|
+
let c = Xr(r, {
|
|
2681
2780
|
rules: t.rules,
|
|
2682
2781
|
template: t.template,
|
|
2683
2782
|
imageWidth: n.width,
|
|
2684
2783
|
imageHeight: n.height,
|
|
2685
2784
|
semanticDetections: i,
|
|
2686
2785
|
modelRequested: a
|
|
2687
|
-
}), l =
|
|
2786
|
+
}), l = Qr(c, t.requireAll), u = [], d = "not-requested", f;
|
|
2688
2787
|
if (t.models?.face) try {
|
|
2689
|
-
u = await
|
|
2788
|
+
u = await mr(n, t.models.face, t.models.faceConfidence), d = "loaded";
|
|
2690
2789
|
} catch (e) {
|
|
2691
2790
|
f = e instanceof Error ? e.message : "The face model could not load.", d = "failed";
|
|
2692
2791
|
}
|
|
@@ -2700,7 +2799,7 @@ async function Br(e, t) {
|
|
|
2700
2799
|
faceStatus: d,
|
|
2701
2800
|
faceError: f
|
|
2702
2801
|
};
|
|
2703
|
-
let p = await
|
|
2802
|
+
let p = await Ar(n, [...c.matches.map((e) => ({
|
|
2704
2803
|
...e.bbox,
|
|
2705
2804
|
mode: t.style?.mode
|
|
2706
2805
|
})), ...u.map((e) => ({
|
|
@@ -2722,7 +2821,7 @@ async function Br(e, t) {
|
|
|
2722
2821
|
}
|
|
2723
2822
|
//#endregion
|
|
2724
2823
|
//#region src/sdk/driver-license.ts
|
|
2725
|
-
var
|
|
2824
|
+
var ei = [
|
|
2726
2825
|
{
|
|
2727
2826
|
id: "issuerJurisdiction",
|
|
2728
2827
|
strategy: "semantic",
|
|
@@ -2759,11 +2858,11 @@ var Vr = [
|
|
|
2759
2858
|
field: "person_name"
|
|
2760
2859
|
}
|
|
2761
2860
|
];
|
|
2762
|
-
function
|
|
2861
|
+
function ti(e, t, n) {
|
|
2763
2862
|
let r = n.trim();
|
|
2764
2863
|
if (r) {
|
|
2765
2864
|
if (t === "expirationDate" || t === "dateOfBirth" || t === "issueDate") {
|
|
2766
|
-
e[t] =
|
|
2865
|
+
e[t] = q(r, t === "dateOfBirth") ?? r;
|
|
2767
2866
|
return;
|
|
2768
2867
|
}
|
|
2769
2868
|
if (t === "issuerJurisdiction") {
|
|
@@ -2773,8 +2872,8 @@ function Hr(e, t, n) {
|
|
|
2773
2872
|
e[t] = r;
|
|
2774
2873
|
}
|
|
2775
2874
|
}
|
|
2776
|
-
function
|
|
2777
|
-
let t = {}, n =
|
|
2875
|
+
function ni(e) {
|
|
2876
|
+
let t = {}, n = Xr(e, { rules: ei });
|
|
2778
2877
|
for (let e of n.matches) {
|
|
2779
2878
|
let n = e.text?.trim();
|
|
2780
2879
|
if (n) {
|
|
@@ -2783,29 +2882,29 @@ function Ur(e) {
|
|
|
2783
2882
|
!t.firstName && e[0] && (t.firstName = e[0]), !t.lastName && e.length > 1 && (t.lastName = e[e.length - 1]), !t.middleName && e.length > 2 && (t.middleName = e.slice(1, -1).join(" "));
|
|
2784
2883
|
continue;
|
|
2785
2884
|
}
|
|
2786
|
-
|
|
2885
|
+
ti(t, e.ruleId, n);
|
|
2787
2886
|
}
|
|
2788
2887
|
}
|
|
2789
2888
|
return t;
|
|
2790
2889
|
}
|
|
2791
|
-
function
|
|
2792
|
-
let n = { ...e }, r =
|
|
2890
|
+
function ri(e, t) {
|
|
2891
|
+
let n = { ...e }, r = cr(sr(), e, "barcode");
|
|
2793
2892
|
for (let [e, i] of Object.entries(t)) i && (n[e] || (n[e] = i, r[e] = "ocr"));
|
|
2794
2893
|
return {
|
|
2795
2894
|
fields: n,
|
|
2796
2895
|
sources: r
|
|
2797
2896
|
};
|
|
2798
2897
|
}
|
|
2799
|
-
async function
|
|
2800
|
-
return t?.status === "success" && t.corners ?
|
|
2898
|
+
async function ii(e, t, n) {
|
|
2899
|
+
return t?.status === "success" && t.corners ? ft(e, t.corners, { maxOutputDimension: n?.maxOutputDimension }) : L(e, n);
|
|
2801
2900
|
}
|
|
2802
|
-
async function
|
|
2901
|
+
async function ai(e, t, n) {
|
|
2803
2902
|
if (!e.width || !e.height) return {
|
|
2804
2903
|
kind: "retry",
|
|
2805
2904
|
status: "frontFailed",
|
|
2806
2905
|
message: "The front photo was empty. Try again."
|
|
2807
2906
|
};
|
|
2808
|
-
let r = await
|
|
2907
|
+
let r = await ii(e, t, n);
|
|
2809
2908
|
if (r.status !== "success" || !r.canvas) return {
|
|
2810
2909
|
kind: "retry",
|
|
2811
2910
|
status: "frontFailed",
|
|
@@ -2813,7 +2912,7 @@ async function Kr(e, t, n) {
|
|
|
2813
2912
|
};
|
|
2814
2913
|
let i;
|
|
2815
2914
|
try {
|
|
2816
|
-
i = await
|
|
2915
|
+
i = await bn(r.canvas, { includeWords: !0 });
|
|
2817
2916
|
} catch {
|
|
2818
2917
|
i = void 0;
|
|
2819
2918
|
}
|
|
@@ -2829,7 +2928,7 @@ async function Kr(e, t, n) {
|
|
|
2829
2928
|
function $() {
|
|
2830
2929
|
return new DOMException("The barcode scan was cancelled.", "AbortError");
|
|
2831
2930
|
}
|
|
2832
|
-
function
|
|
2931
|
+
function oi(e, t) {
|
|
2833
2932
|
return new Promise((n, r) => {
|
|
2834
2933
|
if (t?.aborted) {
|
|
2835
2934
|
r($());
|
|
@@ -2843,21 +2942,21 @@ function qr(e, t) {
|
|
|
2843
2942
|
t?.addEventListener("abort", a, { once: !0 });
|
|
2844
2943
|
});
|
|
2845
2944
|
}
|
|
2846
|
-
async function
|
|
2945
|
+
async function si(e, t = {}) {
|
|
2847
2946
|
let n = t.intervalMs ?? 140;
|
|
2848
|
-
for (;;) {
|
|
2947
|
+
for (await Un();;) {
|
|
2849
2948
|
if (t.signal?.aborted) throw $();
|
|
2850
2949
|
try {
|
|
2851
2950
|
let t = await e();
|
|
2852
|
-
if (t?.width && t.height && (await
|
|
2951
|
+
if (t?.width && t.height && (await W(t))?.text) return t;
|
|
2853
2952
|
} catch (e) {
|
|
2854
2953
|
if (t.signal?.aborted) throw $();
|
|
2855
|
-
if (e instanceof DOMException && e.name === "AbortError") throw e;
|
|
2954
|
+
if (e instanceof DOMException && e.name === "AbortError" || e instanceof V) throw e;
|
|
2856
2955
|
}
|
|
2857
|
-
await
|
|
2956
|
+
await oi(n, t.signal);
|
|
2858
2957
|
}
|
|
2859
2958
|
}
|
|
2860
|
-
async function
|
|
2959
|
+
async function ci(e, t) {
|
|
2861
2960
|
if (!e.width || !e.height) return {
|
|
2862
2961
|
status: "backFailed",
|
|
2863
2962
|
fields: {},
|
|
@@ -2867,23 +2966,23 @@ async function Yr(e, t) {
|
|
|
2867
2966
|
back: {},
|
|
2868
2967
|
message: "The back photo was empty. Try again."
|
|
2869
2968
|
};
|
|
2870
|
-
let n = (await
|
|
2969
|
+
let n = (await W(e))?.text, r = {
|
|
2871
2970
|
canvas: e,
|
|
2872
2971
|
barcodeText: n
|
|
2873
2972
|
};
|
|
2874
2973
|
if (!n) {
|
|
2875
|
-
let e = t.ocr ?
|
|
2974
|
+
let e = t.ocr ? ni(t.ocr) : {};
|
|
2876
2975
|
return {
|
|
2877
2976
|
status: "barcodeUnreadable",
|
|
2878
2977
|
fields: e,
|
|
2879
2978
|
rawElements: {},
|
|
2880
|
-
sources:
|
|
2979
|
+
sources: cr(sr(), e, "ocr"),
|
|
2881
2980
|
front: t,
|
|
2882
2981
|
back: r,
|
|
2883
2982
|
message: "The PDF417 barcode on the back could not be read. Try again."
|
|
2884
2983
|
};
|
|
2885
2984
|
}
|
|
2886
|
-
let i =
|
|
2985
|
+
let i = or(n), a = t.ocr ? ni(t.ocr) : {}, o = ri(i.fields, a);
|
|
2887
2986
|
return {
|
|
2888
2987
|
status: "success",
|
|
2889
2988
|
fields: o.fields,
|
|
@@ -2893,10 +2992,10 @@ async function Yr(e, t) {
|
|
|
2893
2992
|
back: r
|
|
2894
2993
|
};
|
|
2895
2994
|
}
|
|
2896
|
-
function
|
|
2995
|
+
function li(e) {
|
|
2897
2996
|
return e === "back" ? 0 : void 0;
|
|
2898
2997
|
}
|
|
2899
|
-
function
|
|
2998
|
+
function ui(e, t) {
|
|
2900
2999
|
return e === "front" ? {
|
|
2901
3000
|
title: "Scan a driver’s license",
|
|
2902
3001
|
headline: "Show the front of the license.",
|
|
@@ -2907,7 +3006,7 @@ function Zr(e, t) {
|
|
|
2907
3006
|
detail: t ? "Take a photo of the entire PDF417 barcode. There is no document outline." : "Keep the entire PDF417 in the preview. Closer is fine if the whole code is visible."
|
|
2908
3007
|
};
|
|
2909
3008
|
}
|
|
2910
|
-
async function
|
|
3009
|
+
async function di(e = {}) {
|
|
2911
3010
|
await x("scan"), await x("ocr");
|
|
2912
3011
|
let t = "front", n, r = !1;
|
|
2913
3012
|
return {
|
|
@@ -2921,10 +3020,10 @@ async function Qr(e = {}) {
|
|
|
2921
3020
|
message: "This license scan was cancelled."
|
|
2922
3021
|
};
|
|
2923
3022
|
if (t === "front") {
|
|
2924
|
-
let r = await
|
|
3023
|
+
let r = await ai(i, a, e.scan);
|
|
2925
3024
|
return r.kind === "need-back" && (n = r.front, t = "back"), r;
|
|
2926
3025
|
}
|
|
2927
|
-
let o = await
|
|
3026
|
+
let o = await ci(i, n ?? {});
|
|
2928
3027
|
return o.status === "backFailed" ? {
|
|
2929
3028
|
kind: "retry",
|
|
2930
3029
|
status: "backFailed",
|
|
@@ -2940,6 +3039,6 @@ async function Qr(e = {}) {
|
|
|
2940
3039
|
};
|
|
2941
3040
|
}
|
|
2942
3041
|
//#endregion
|
|
2943
|
-
export {
|
|
3042
|
+
export { x as $, L as A, ue as B, Ft as C, ft as D, Ze as E, ke as F, de as G, O as H, M as I, Le as J, pe as K, D as L, pt as M, ye as N, dt as O, ve as P, o as Q, le as R, Nt as S, Bt as T, A as U, xe as V, ze as W, ie as X, be as Y, a as Z, It as _, di as a, wt as b, $r as c, or as d, b as et, Pn as f, Ot as g, bn as h, ri as i, mt as j, et as k, Ar as l, zn as m, li as n, e as nt, si as o, W as p, fe as q, ui as r, t as rt, Xr as s, ni as t, y as tt, q as u, Dt as v, Ct as w, Pt as x, Tt as y, Re as z };
|
|
2944
3043
|
|
|
2945
|
-
//# sourceMappingURL=driver-license-
|
|
3044
|
+
//# sourceMappingURL=driver-license-DWQiITx8.js.map
|