@exige/web-scanner-sdk 0.2.9 → 0.2.11

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.
@@ -1,4 +1,4 @@
1
- import { A as e, C as t, D as n, E as r, F as i, M as a, N as o, O as s, P as c, S as l, T as u, _ as d, a as f, b as p, c as m, d as h, f as g, g as _, h as v, i as y, j as b, k as ee, l as te, m as ne, n as re, o as ie, p as ae, r as oe, s as se, t as ce, u as le, v as ue, w as de, x as fe, y as pe } from "./finder-DFueuWuS.js";
1
+ import { A as e, C as t, D as n, E as r, F as i, M as a, N as o, O as s, P as c, S as l, T as u, _ as d, a as f, b as p, c as m, d as h, f as g, g as _, h as v, i as y, j as b, k as ee, l as te, m as ne, n as re, o as ie, p as ae, r as oe, s as se, t as ce, u as le, v as ue, w as de, x as fe, y as pe } from "./finder-BeINpYm3.js";
2
2
  //#region src/sdk/frame-geometry.ts
3
3
  function x(e, t, n) {
4
4
  let r = Math.max(1, t.width), i = Math.max(1, t.height), a = Math.max(1, n.width), o = Math.max(1, n.height), s = Math.max(r / a, i / o), c = (r - a * s) / 2, l = (i - o * s) / 2;
@@ -141,10 +141,36 @@ function Ee(e, t) {
141
141
  };
142
142
  throw new c("language", `OCR language "${n}" is not packaged. Pass langPath, a directory URL that contains ${n}.traineddata.gz.`);
143
143
  }
144
- async function De() {
145
- let e = await fetch(xe);
146
- if (!e.ok) throw new c("model-http", `Packaged English OCR data failed to load (HTTP ${e.status}).`);
147
- return new Uint8Array(await e.arrayBuffer());
144
+ function De(e = xe) {
145
+ let t = e.href, n = t.lastIndexOf("/");
146
+ return n === -1 ? t : t.slice(0, n);
147
+ }
148
+ function Oe(e) {
149
+ return e.kind === "bundled-eng" ? De() : e.langPath;
150
+ }
151
+ async function ke(e, t, n) {
152
+ return new Promise((r, i) => {
153
+ let a = !1, o = (e) => {
154
+ if (a) return;
155
+ a = !0;
156
+ let t = e instanceof Error ? e.message : String(e);
157
+ i(new c("worker", `OCR worker failed to start (${t}).`));
158
+ };
159
+ e(t, void 0, {
160
+ workerPath: n.workerPath,
161
+ corePath: n.corePath,
162
+ langPath: n.langPath,
163
+ gzip: !0,
164
+ logger: n.logger,
165
+ errorHandler: o
166
+ }).then((e) => {
167
+ if (a) {
168
+ e.terminate?.();
169
+ return;
170
+ }
171
+ a = !0, r(e);
172
+ }, o);
173
+ });
148
174
  }
149
175
  //#endregion
150
176
  //#region src/sdk/ocr.ts
@@ -164,13 +190,13 @@ function D(e = .5) {
164
190
  if (!Number.isFinite(e) || e < 0 || e > 1) throw RangeError("OCR minConfidence must be between 0 and 1.");
165
191
  return e;
166
192
  }
167
- function Oe(e, t) {
193
+ function Ae(e, t) {
168
194
  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);
169
195
  return s > 0 ? o / s : 0;
170
196
  }
171
197
  function O(e) {
172
198
  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 = [];
173
- for (let e of t) n.some((t) => Oe(t, e) >= .65) || n.push(e);
199
+ for (let e of t) n.some((t) => Ae(t, e) >= .65) || n.push(e);
174
200
  return n;
175
201
  }
176
202
  function k(e, t, n, r, i) {
@@ -184,7 +210,7 @@ function k(e, t, n, r, i) {
184
210
  }
185
211
  return !0;
186
212
  }
187
- function ke(e) {
213
+ function je(e) {
188
214
  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 = [];
189
215
  for (let e of t) {
190
216
  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);
@@ -215,13 +241,13 @@ function A(e, t, n, r) {
215
241
  }
216
242
  let l = n?.width ?? s, u = n?.height ?? c, d = O(a).filter((e) => k(e, "word", l, u, r)), f = O(o).filter((e) => k(e, "character", l, u, r));
217
243
  return {
218
- text: ke(d),
244
+ text: je(d),
219
245
  confidence: d.length ? d.reduce((e, t) => e + t.confidence, 0) / d.length : 0,
220
246
  words: t.includeWords ? d : [],
221
247
  characters: t.includeCharacters ? f : []
222
248
  };
223
249
  }
224
- function Ae(e) {
250
+ function Me(e) {
225
251
  let t = /* @__PURE__ */ new Uint32Array(256);
226
252
  for (let n of e) t[n] += 1;
227
253
  let n = 0;
@@ -248,7 +274,7 @@ function j(e) {
248
274
  luminance: r
249
275
  };
250
276
  }
251
- function je(e) {
277
+ function Ne(e) {
252
278
  let t = 1800, n = Math.max(e.width, e.height), r = n > t ? t / n : Math.min(2, t / Math.max(1, n)), a = document.createElement("canvas");
253
279
  a.width = Math.max(1, Math.round(e.width * r)), a.height = Math.max(1, Math.round(e.height * r));
254
280
  let o = a.getContext("2d", { willReadFrequently: !0 });
@@ -258,7 +284,7 @@ function je(e) {
258
284
  for (let e = 0, t = 0; e < l.length; e += 1, t += 4) s.data[t] = l[e], s.data[t + 1] = l[e], s.data[t + 2] = l[e], s.data[t + 3] = 255;
259
285
  return o.putImageData(s, 0, 0), a;
260
286
  }
261
- function Me(e) {
287
+ function Pe(e) {
262
288
  let t = document.createElement("canvas");
263
289
  t.width = 72, t.height = 72;
264
290
  let n = t.getContext("2d", { willReadFrequently: !0 });
@@ -272,16 +298,16 @@ function Me(e) {
272
298
  let { luminance: r } = j(t);
273
299
  return m(r, t.width, t.height);
274
300
  }
275
- function Ne(e, t, n, r) {
301
+ function Fe(e, t, n, r) {
276
302
  let i = (e.bbox.x + e.bbox.width / 2) / n, a = (e.bbox.y + e.bbox.height / 2) / r;
277
303
  return i >= t.x && i <= t.x + t.width && a >= t.y && a <= t.y + t.height;
278
304
  }
279
- function Pe(e, t, n) {
305
+ function Ie(e, t, n) {
280
306
  if (!e.strong || !e.region) return !1;
281
- let r = t.filter((t) => Ne(t, e.region, n.width, n.height)).length, i = t.length - r, a = e.region.width * e.region.height, o = i > 0 && a < .95 ? i / (1 - a) * a : 3;
307
+ let r = t.filter((t) => Fe(t, e.region, n.width, n.height)).length, i = t.length - r, a = e.region.width * e.region.height, o = i > 0 && a < .95 ? i / (1 - a) * a : 3;
282
308
  return r < Math.max(3, o * .85);
283
309
  }
284
- function Fe(e, t, n, r) {
310
+ function Le(e, t, n, r) {
285
311
  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");
286
312
  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);
287
313
  let l = n / e.width, u = r / e.height;
@@ -295,7 +321,7 @@ function Fe(e, t, n, r) {
295
321
  }
296
322
  };
297
323
  }
298
- function Ie(e) {
324
+ function Re(e) {
299
325
  let t = 2200, n = Math.max(e.width, e.height), r = n > t ? t / n : Math.min(1.5, t / Math.max(1, n)), a = document.createElement("canvas");
300
326
  a.width = Math.max(1, Math.round(e.width * r)), a.height = Math.max(1, Math.round(e.height * r));
301
327
  let o = a.getContext("2d", { willReadFrequently: !0 });
@@ -303,14 +329,14 @@ function Ie(e) {
303
329
  o.drawImage(e, 0, 0, a.width, a.height);
304
330
  let s = o.getImageData(0, 0, a.width, a.height), c = new Uint8Array(a.width * a.height);
305
331
  for (let e = 0, t = 0; e < c.length; e += 1, t += 4) c[e] = Math.round(s.data[t] * .299 + s.data[t + 1] * .587 + s.data[t + 2] * .114);
306
- let l = Ae(c);
332
+ let l = Me(c);
307
333
  for (let e = 0, t = 0; e < c.length; e += 1, t += 4) {
308
334
  let n = c[e] <= l ? 0 : 255;
309
335
  s.data[t] = n, s.data[t + 1] = n, s.data[t + 2] = n, s.data[t + 3] = 255;
310
336
  }
311
337
  return o.putImageData(s, 0, 0), a;
312
338
  }
313
- function Le(e) {
339
+ function ze(e) {
314
340
  let t = document.createElement("canvas");
315
341
  t.width = 24, t.height = 24;
316
342
  let n = t.getContext("2d", { willReadFrequently: !0 });
@@ -332,20 +358,17 @@ async function M(e, t = {}) {
332
358
  await b("ocr");
333
359
  let r = Ee(t.language, t.langPath), i = r.language;
334
360
  D(t.minConfidence);
335
- let a = await n(e, { cloneCanvas: !1 }), o = Ie(a), s = t.shadowPass === !1 ? {
361
+ let a = await n(e, { cloneCanvas: !1 }), o = Re(a), s = t.shadowPass === !1 ? {
336
362
  strong: !1,
337
363
  strength: 0,
338
364
  darkness: 0,
339
365
  areaRatio: 0
340
- } : Me(a), { createWorker: c, PSM: l } = await import("tesseract.js"), u = 0, d = s.strong ? 3 : 2, f = await c(r.kind === "bundled-eng" ? [{
341
- code: "eng",
342
- data: await De()
343
- }] : r.language, void 0, {
366
+ } : Pe(a), { createWorker: c, PSM: l } = await import("tesseract.js"), u = 0, d = s.strong ? 3 : 2, f = await ke(c, i, {
344
367
  workerPath: _e.href,
345
368
  corePath: Te(we()).href,
346
- ...r.kind === "lang-path" ? { langPath: r.langPath } : {},
369
+ langPath: Oe(r),
347
370
  logger(e) {
348
- typeof e.progress == "number" && t.onProgress?.(Math.min(1, (u + e.progress) / d), e.status);
371
+ typeof e.progress == "number" && t.onProgress?.(Math.min(1, (u + e.progress) / d), e.status ?? "recognizing text");
349
372
  }
350
373
  });
351
374
  try {
@@ -368,16 +391,16 @@ async function M(e, t = {}) {
368
391
  }], c = {
369
392
  ...t,
370
393
  includeWords: !0
371
- }, d = Le(a), p = A(r, c, {
394
+ }, d = ze(a), p = A(r, c, {
372
395
  width: a.width,
373
396
  height: a.height
374
- }, d), m = t.shadowPass !== !1 && Pe(s, p.words, {
397
+ }, d), m = t.shadowPass !== !1 && Ie(s, p.words, {
375
398
  width: a.width,
376
399
  height: a.height
377
400
  });
378
401
  if (m && s.region) {
379
402
  u = 2;
380
- let { tile: e, passMapping: t } = Fe(je(a), s.region, a.width, a.height);
403
+ let { tile: e, passMapping: t } = Le(Ne(a), s.region, a.width, a.height);
381
404
  await f.setParameters({
382
405
  tessedit_pageseg_mode: l.SPARSE_TEXT,
383
406
  preserve_interword_spaces: "1"
@@ -446,12 +469,12 @@ async function N(e, t, a = {}) {
446
469
  }
447
470
  //#endregion
448
471
  //#region src/sdk/face-model.ts
449
- var P = /* @__PURE__ */ new Map(), Re = 8400;
450
- function ze(e, t) {
472
+ var P = /* @__PURE__ */ new Map(), Be = 8400;
473
+ function Ve(e, t) {
451
474
  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));
452
475
  return n / Math.max(1, e.width * e.height + t.width * t.height - n);
453
476
  }
454
- function Be(e, t, n, r, i, a, o) {
477
+ function He(e, t, n, r, i, a, o) {
455
478
  return {
456
479
  x: (e - n / 2) / i * a,
457
480
  y: (t - r / 2) / i * o,
@@ -459,20 +482,20 @@ function Be(e, t, n, r, i, a, o) {
459
482
  height: r / i * o
460
483
  };
461
484
  }
462
- function Ve(e, t, n) {
485
+ function Ue(e, t, n) {
463
486
  let r = t.length === 3 ? t[1] : t[0], i = t.length === 3 ? t[2] : t[1];
464
- if (i !== 6 || r < 1) throw Error(`Face model expects [1, anchors, 6]. A 640 YOLOX-Nano face export is [1, ${Re}, 6].`);
487
+ if (i !== 6 || r < 1) throw Error(`Face model expects [1, anchors, 6]. A 640 YOLOX-Nano face export is [1, ${Be}, 6].`);
465
488
  let a = n.confidence ?? .35, o = n.inputSize ?? 640, s = [];
466
489
  for (let t = 0; t < r; t += 1) {
467
490
  let r = t * i, c = e[r + 4] * e[r + 5];
468
491
  c < a || s.push({
469
492
  confidence: c,
470
- bbox: Be(e[r], e[r + 1], e[r + 2], e[r + 3], o, n.imageWidth, n.imageHeight)
493
+ bbox: He(e[r], e[r + 1], e[r + 2], e[r + 3], o, n.imageWidth, n.imageHeight)
471
494
  });
472
495
  }
473
- return s.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => ze(e.bbox, t.bbox) < .45)).slice(0, 8);
496
+ return s.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => Ve(e.bbox, t.bbox) < .45)).slice(0, 8);
474
497
  }
475
- async function He(e, t, r = .35) {
498
+ async function We(e, t, r = .35) {
476
499
  let a = await n(e, { cloneCanvas: !1 }), o = await import("onnxruntime-web"), s = document.createElement("canvas");
477
500
  s.width = 640, s.height = 640;
478
501
  let c = s.getContext("2d", { willReadFrequently: !0 });
@@ -491,7 +514,7 @@ async function He(e, t, r = .35) {
491
514
  640,
492
515
  640
493
516
  ]) }))[p.outputNames[0]];
494
- return Ve(m.data, m.dims.map(Number), {
517
+ return Ue(m.data, m.dims.map(Number), {
495
518
  confidence: r,
496
519
  imageWidth: a.width,
497
520
  imageHeight: a.height,
@@ -508,17 +531,17 @@ var F = /* @__PURE__ */ new Map(), I = [
508
531
  "expiration_date",
509
532
  "postal_code",
510
533
  "state"
511
- ], Ue = 8400;
534
+ ], Ge = 8400;
512
535
  function L(e) {
513
536
  return 5 + e;
514
537
  }
515
538
  var R = 640;
516
- function We(e, t) {
539
+ function Ke(e, t) {
517
540
  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));
518
541
  return n / Math.max(1, e.bbox.width * e.bbox.height + t.bbox.width * t.bbox.height - n);
519
542
  }
520
543
  function z(e) {
521
- return e.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => t.field !== e.field || We(e, t) < .45)).slice(0, 30);
544
+ return e.sort((e, t) => t.confidence - e.confidence).filter((e, t, n) => n.slice(0, t).every((t) => t.field !== e.field || Ke(e, t) < .45)).slice(0, 30);
522
545
  }
523
546
  function B(e, t, n, r, i, a, o) {
524
547
  return {
@@ -538,15 +561,15 @@ function V(e, t) {
538
561
  features: n
539
562
  } : null;
540
563
  }
541
- function Ge(e) {
564
+ function qe(e) {
542
565
  return e.length === 3 && e[1] >= 5 && e[2] >= 1;
543
566
  }
544
- function Ke(e) {
567
+ function Je(e) {
545
568
  let t = L(e);
546
- 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, ${Ue}, ${t}].`);
569
+ 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, ${Ge}, ${t}].`);
547
570
  }
548
- function qe(e, t, n, r, i, a, o) {
549
- if (!Ge(t)) throw Error("Unsupported field-model YOLO output shape.");
571
+ function Ye(e, t, n, r, i, a, o) {
572
+ if (!qe(t)) throw Error("Unsupported field-model YOLO output shape.");
550
573
  let s = t[1], c = t[2], l = [];
551
574
  for (let t = 0; t < c; t += 1) {
552
575
  let u = 0, d = 0;
@@ -563,9 +586,9 @@ function qe(e, t, n, r, i, a, o) {
563
586
  }
564
587
  return z(l);
565
588
  }
566
- function Je(e, t, n, r, i, a, o) {
589
+ function Xe(e, t, n, r, i, a, o) {
567
590
  let s = V(t, n.length);
568
- if (!s) throw Ke(n.length);
591
+ if (!s) throw Je(n.length);
569
592
  let c = [];
570
593
  for (let t = 0; t < s.anchors; t += 1) {
571
594
  let l = t * s.features, u = e[l + 4], d = 0, f = 0;
@@ -582,12 +605,12 @@ function Je(e, t, n, r, i, a, o) {
582
605
  }
583
606
  return z(c);
584
607
  }
585
- function Ye(e, t, n) {
608
+ function Ze(e, t, n) {
586
609
  let r = n.classes ?? I, i = n.confidence ?? .35, a = n.inputSize ?? R, o = V(t, r.length);
587
610
  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.");
588
- return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ? Je(e, t, r, i, a, n.imageWidth, n.imageHeight) : qe(e, t, r, i, a, n.imageWidth, n.imageHeight);
611
+ return (n.layout ?? (o ? "yolox" : "yolov8")) === "yolox" ? Xe(e, t, r, i, a, n.imageWidth, n.imageHeight) : Ye(e, t, r, i, a, n.imageWidth, n.imageHeight);
589
612
  }
590
- async function Xe(e, t, r = I, a = .35, o) {
613
+ async function Qe(e, t, r = I, a = .35, o) {
591
614
  let c = await n(e, { cloneCanvas: !1 }), l = import("onnxruntime-web"), u = R, d = document.createElement("canvas");
592
615
  d.width = u, d.height = u;
593
616
  let f = d.getContext("2d", { willReadFrequently: !0 });
@@ -613,7 +636,7 @@ async function Xe(e, t, r = I, a = .35, o) {
613
636
  u,
614
637
  u
615
638
  ]) }))[v.outputNames[0]];
616
- return Ye(y.data, y.dims.map(Number), {
639
+ return Ze(y.data, y.dims.map(Number), {
617
640
  classes: r,
618
641
  confidence: a,
619
642
  layout: o,
@@ -655,7 +678,7 @@ function W(e, t, n = !1) {
655
678
  function G(e) {
656
679
  return e.reduce((e, t) => e + t.confidence, 0) / Math.max(1, e.length);
657
680
  }
658
- function Ze(e, t) {
681
+ function $e(e, t) {
659
682
  let n = e.mode, r = n === "case-insensitive", i = e.scope ?? "line", a;
660
683
  if (n === "regex") {
661
684
  let t = e.pattern ?? e.values?.[0];
@@ -692,14 +715,14 @@ function Ze(e, t) {
692
715
  }
693
716
  return s;
694
717
  }
695
- function Qe(e, t) {
718
+ function et(e, t) {
696
719
  let n = e.labelMode !== "exact", r = W(e.label, n, !0).split(" ");
697
720
  for (let e of t) for (let t = 0; t <= e.words.length - r.length; t += 1) {
698
721
  let i = e.words.slice(t, t + r.length);
699
722
  if (i.every((e, t) => W(e.text, n, !0) === r[t])) return i;
700
723
  }
701
724
  }
702
- function $e(e, t, n, r, i, a) {
725
+ function tt(e, t, n, r, i, a) {
703
726
  let o = a.window?.distance ?? .28, s = a.window?.crossAxis ?? .12, c = t.x + t.width / 2, l = t.y + t.height / 2;
704
727
  return e.filter((e) => {
705
728
  let a = e.bbox.x + e.bbox.width / 2, u = e.bbox.y + e.bbox.height / 2;
@@ -707,7 +730,7 @@ function $e(e, t, n, r, i, a) {
707
730
  });
708
731
  }
709
732
  function K(e, t, n, r, i, a = "label") {
710
- let o = Qe(e, n);
733
+ let o = et(e, n);
711
734
  if (!o) return [];
712
735
  let s = H(o), c = new Set(o), l = t.filter((e) => !c.has(e)), u = e.direction === "any" ? [
713
736
  "right",
@@ -716,7 +739,7 @@ function K(e, t, n, r, i, a = "label") {
716
739
  "above"
717
740
  ] : [e.direction], d;
718
741
  for (let t of u) {
719
- let n = U($e(l, s, t, r, i, e));
742
+ let n = U(tt(l, s, t, r, i, e));
720
743
  for (let t of n) {
721
744
  if (e.valuePattern && !new RegExp(e.valuePattern, e.patternFlags).test(t.text)) continue;
722
745
  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);
@@ -774,7 +797,7 @@ var q = {
774
797
  "POSTAL"
775
798
  ],
776
799
  state: ["STATE", "DAJ"]
777
- }, et = new Set(Object.values(q).flat()), J = /^(?:\d{2}[/-]\d{2}[/-]\d{2,4}|\d{4}[/-]\d{2}[/-]\d{2}|\d{6}|\d{8})$/, Y = /\b(?:ST|STREET|AVE|AVENUE|RD|ROAD|BLVD|BOULEVARD|LN|LANE|DR|DRIVE|WAY|CT|COURT)\b/i, X = /\b(?:DRIVER|LICENSE|IDENTIFICATION|CARD|CLASS|SEX|EYES|HEIGHT|RESTRICTIONS)\b/i;
800
+ }, nt = new Set(Object.values(q).flat()), J = /^(?:\d{2}[/-]\d{2}[/-]\d{2,4}|\d{4}[/-]\d{2}[/-]\d{2}|\d{6}|\d{8})$/, Y = /\b(?:ST|STREET|AVE|AVENUE|RD|ROAD|BLVD|BOULEVARD|LN|LANE|DR|DRIVE|WAY|CT|COURT)\b/i, X = /\b(?:DRIVER|LICENSE|IDENTIFICATION|CARD|CLASS|SEX|EYES|HEIGHT|RESTRICTIONS)\b/i;
778
801
  function Z(e, t) {
779
802
  let n = t.trim();
780
803
  return n ? e === "date_of_birth" || e === "expiration_date" ? J.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) && !X.test(n) : /\d/.test(n) && /[A-Z]/i.test(n) : !1;
@@ -789,17 +812,17 @@ function Q(e, t, n, r, i = 1) {
789
812
  confidence: Math.max(0, Math.min(1, G(n) * i))
790
813
  };
791
814
  }
792
- function tt(e, t, n) {
815
+ function rt(e, t, n) {
793
816
  let r = q[e], i = [];
794
817
  for (let a of n) for (let n = 0; n < a.words.length; n += 1) {
795
818
  let o = a.words[n].text.toUpperCase().replace(/[^A-Z0-9]/g, ""), s = r.find((e) => o === e || o.startsWith(e));
796
819
  if (!s) continue;
797
820
  let c, l;
798
- o === s ? (c = a.words.slice(n + 1).filter((e) => !et.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));
821
+ o === s ? (c = a.words.slice(n + 1).filter((e) => !nt.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));
799
822
  }
800
823
  return i;
801
824
  }
802
- function nt(e, t, n) {
825
+ function it(e, t, n) {
803
826
  let r = n.filter((e) => {
804
827
  let t = e.text.replace(/\s/g, "");
805
828
  return t.includes("<<") || /^[A-Z0-9<]{25,}$/.test(t);
@@ -821,7 +844,7 @@ function nt(e, t, n) {
821
844
  }
822
845
  return [];
823
846
  }
824
- function rt(e) {
847
+ function at(e) {
825
848
  let t = e.replace(/\s/g, ""), n = t.match(/\d{4}/)?.[0];
826
849
  if (n) return Number(n);
827
850
  let r = t.match(/^\d{2}/)?.[0];
@@ -829,7 +852,7 @@ function rt(e) {
829
852
  let i = Number(r);
830
853
  return i > (/* @__PURE__ */ new Date()).getFullYear() % 100 ? 1900 + i : 2e3 + i;
831
854
  }
832
- function it(e, t, n, r, i) {
855
+ function ot(e, t, n, r, i) {
833
856
  if (e === "address") {
834
857
  let e = r.findIndex((e) => /\d/.test(e.text) && Y.test(e.text));
835
858
  if (e < 0) return [];
@@ -849,7 +872,7 @@ function it(e, t, n, r, i) {
849
872
  if (e === "date_of_birth" || e === "expiration_date") {
850
873
  let r = (/* @__PURE__ */ new Date()).getFullYear(), i = n.filter((e) => J.test(e.text.replace(/\s/g, ""))).map((e) => ({
851
874
  word: e,
852
- year: rt(e.text)
875
+ year: at(e.text)
853
876
  })).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);
854
877
  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)] : [];
855
878
  }
@@ -867,29 +890,29 @@ function it(e, t, n, r, i) {
867
890
  }
868
891
  return [];
869
892
  }
870
- function at(e, t) {
893
+ function st(e, t) {
871
894
  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);
872
895
  }
873
- function ot(e, t, n, r) {
874
- let i = tt(e.field, e.id, n), a = nt(e.field, e.id, n);
875
- return i.length || a.length ? [...i, ...a] : it(e.field, e.id, t, n, r);
896
+ function ct(e, t, n, r) {
897
+ let i = rt(e.field, e.id, n), a = it(e.field, e.id, n);
898
+ return i.length || a.length ? [...i, ...a] : ot(e.field, e.id, t, n, r);
876
899
  }
877
- function st(e, t, n) {
900
+ function lt(e, t, n) {
878
901
  let r = (n ?? []).filter((t) => t.field === e.field).sort((e, t) => t.confidence - e.confidence);
879
902
  for (let n of r) {
880
- let r = t.filter((e) => at(n.bbox, e.bbox) >= .3);
903
+ let r = t.filter((e) => st(n.bbox, e.bbox) >= .3);
881
904
  if (!r.length) continue;
882
905
  let i = r.map((e) => e.text).join(" ");
883
906
  if (Z(e.field, i)) return Q(e.id, "model", r, i, n.confidence);
884
907
  }
885
908
  }
886
- function ct(e, t, n, r, i, a) {
887
- let o = ot(e, t, n, r);
909
+ function ut(e, t, n, r, i, a) {
910
+ let o = ct(e, t, n, r);
888
911
  if (e.detector !== "model" || !a) return o;
889
- let s = st(e, t, i);
912
+ let s = lt(e, t, i);
890
913
  return s ? [s] : [];
891
914
  }
892
- function lt(e, t, n, r) {
915
+ function dt(e, t, n, r) {
893
916
  let i = (e) => Math.max(0, Math.min(1, e)), a = i(e.rect.x), o = i(e.rect.y);
894
917
  return {
895
918
  ruleId: `${t}.${e.id}`,
@@ -907,13 +930,13 @@ function lt(e, t, n, r) {
907
930
  function $(e, t) {
908
931
  let n = t.imageWidth ?? e?.imageWidth ?? 0, r = t.imageHeight ?? e?.imageHeight ?? 0, i = e?.words ?? [], a = U(i), o = [], s = [];
909
932
  for (let e of t.rules) {
910
- let c = e.strategy === "string" ? Ze(e, a) : e.strategy === "label" ? K(e, i, a, n, r) : ct(e, i, a, r, t.semanticDetections, t.modelRequested === !0);
933
+ let c = e.strategy === "string" ? $e(e, a) : e.strategy === "label" ? K(e, i, a, n, r) : ut(e, i, a, r, t.semanticDetections, t.modelRequested === !0);
911
934
  c.length ? o.push(...c) : s.push(e.id);
912
935
  }
913
936
  for (let e of t.template?.fields ?? []) {
914
937
  let c = `${t.template.id}.${e.id}`;
915
938
  if (e.strategy === "rect") {
916
- n && r ? o.push(lt(e, t.template.id, n, r)) : s.push(c);
939
+ n && r ? o.push(dt(e, t.template.id, n, r)) : s.push(c);
917
940
  continue;
918
941
  }
919
942
  let l = K({
@@ -934,19 +957,19 @@ function $(e, t) {
934
957
  confidence: u
935
958
  };
936
959
  }
937
- function ut(e) {
960
+ function ft(e) {
938
961
  return e.rules.length > 0 || e.template?.fields.some((e) => e.strategy === "anchor") === !0;
939
962
  }
940
- function dt(e, t = !1) {
963
+ function pt(e, t = !1) {
941
964
  return t && !e.complete ? "unmatched" : e.complete ? "success" : "partial";
942
965
  }
943
- async function ft(e, t) {
966
+ async function mt(e, t) {
944
967
  await b("redaction");
945
968
  let r = await n(e, { cloneCanvas: !1 }), i = t.ocr;
946
- ut(t) && !i && (i = await M(r, { includeWords: !0 }));
969
+ ft(t) && !i && (i = await M(r, { includeWords: !0 }));
947
970
  let a = t.semanticDetections, o = t.modelRequested === !0, s = "not-requested", c;
948
971
  if (t.models?.fields) try {
949
- a = await Xe(r, t.models.fields, t.models.fieldClasses, t.models.confidence, t.models.fieldLayout), o = !0, s = "loaded";
972
+ a = await Qe(r, t.models.fields, t.models.fieldClasses, t.models.confidence, t.models.fieldLayout), o = !0, s = "loaded";
950
973
  } catch (e) {
951
974
  c = e instanceof Error ? e.message : "The field model could not load.";
952
975
  let n = t.models.allowHeuristicFallback !== !1;
@@ -959,9 +982,9 @@ async function ft(e, t) {
959
982
  imageHeight: r.height,
960
983
  semanticDetections: a,
961
984
  modelRequested: o
962
- }), u = dt(l, t.requireAll), d = [], f = "not-requested", p;
985
+ }), u = pt(l, t.requireAll), d = [], f = "not-requested", p;
963
986
  if (t.models?.face) try {
964
- d = await He(r, t.models.face, t.models.faceConfidence), f = "loaded";
987
+ d = await We(r, t.models.face, t.models.faceConfidence), f = "loaded";
965
988
  } catch (e) {
966
989
  p = e instanceof Error ? e.message : "The face model could not load.", f = "failed";
967
990
  }
@@ -996,6 +1019,6 @@ async function ft(e, t) {
996
1019
  };
997
1020
  }
998
1021
  //#endregion
999
- export { le as AutoTorchController, p as DEFAULT_DOCUMENT_MODEL_URL, ee as DEV_LICENSE_HOSTS, e as LicenseError, h as NEAR_BLACK_LUMINANCE, ce as QuadStabilityTracker, c as ScannerError, N as applyRedactions, b as assertLicense, re as autoCaptureControl, g as captureVideoFrame, ge as createFinderSimulator, fe as cropDocument, ae as detectBrowserEngine, l as detectDocument, ne as formatCaptureDiagnosticsReport, a as getLicense, v as isNearBlackFrame, oe as limitingFillTarget, me as mapDocumentCornersToFrame, $ as matchRedactionRules, _ as meanFrameLuminance, y as measureQuadFill, d as mobileCameraConstraints, M as recognizeText, ft as redactProgrammatically, t as resolveDocumentModelUrl, de as scanDocument, f as selectFinderGuidance, ie as selectFinderHint, o as setLicenseKey, he as simulatorQuad, ue as startCamera, se as startFinder, pe as torchControl };
1022
+ export { le as AutoTorchController, p as DEFAULT_DOCUMENT_MODEL_URL, ee as DEV_LICENSE_HOSTS, e as LicenseError, h as NEAR_BLACK_LUMINANCE, ce as QuadStabilityTracker, c as ScannerError, N as applyRedactions, b as assertLicense, re as autoCaptureControl, g as captureVideoFrame, ge as createFinderSimulator, fe as cropDocument, ae as detectBrowserEngine, l as detectDocument, ne as formatCaptureDiagnosticsReport, a as getLicense, v as isNearBlackFrame, oe as limitingFillTarget, me as mapDocumentCornersToFrame, $ as matchRedactionRules, _ as meanFrameLuminance, y as measureQuadFill, d as mobileCameraConstraints, M as recognizeText, mt as redactProgrammatically, t as resolveDocumentModelUrl, de as scanDocument, f as selectFinderGuidance, ie as selectFinderHint, o as setLicenseKey, he as simulatorQuad, ue as startCamera, se as startFinder, pe as torchControl };
1000
1023
 
1001
1024
  //# sourceMappingURL=scanner-sdk.js.map