@exige/web-scanner-sdk 0.2.0

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.
Files changed (37) hide show
  1. package/README.md +288 -0
  2. package/dist/assets/document-worker-QjcJjl9-.js +2 -0
  3. package/dist/assets/document-worker-QjcJjl9-.js.map +1 -0
  4. package/dist/assets/ort.min-CA5AZ7mL.js +2937 -0
  5. package/dist/assets/ort.min-CA5AZ7mL.js.map +1 -0
  6. package/dist/components/ScannerCameraOverlay.d.ts +36 -0
  7. package/dist/components/scanner-camera-overlay.css +2 -0
  8. package/dist/finder-Clo7f2gN.js +1447 -0
  9. package/dist/finder-Clo7f2gN.js.map +1 -0
  10. package/dist/index.d.ts +20 -0
  11. package/dist/live-overlay-geometry.d.ts +11 -0
  12. package/dist/react.d.ts +2 -0
  13. package/dist/react.js +448 -0
  14. package/dist/react.js.map +1 -0
  15. package/dist/scanner-sdk.js +921 -0
  16. package/dist/scanner-sdk.js.map +1 -0
  17. package/dist/sdk/camera.d.ts +142 -0
  18. package/dist/sdk/detect.d.ts +3 -0
  19. package/dist/sdk/display-quad.d.ts +23 -0
  20. package/dist/sdk/document-analysis.d.ts +14 -0
  21. package/dist/sdk/document-geometry.d.ts +21 -0
  22. package/dist/sdk/field-model.d.ts +4 -0
  23. package/dist/sdk/finder-simulator.d.ts +17 -0
  24. package/dist/sdk/finder.d.ts +166 -0
  25. package/dist/sdk/frame-geometry.d.ts +6 -0
  26. package/dist/sdk/image.d.ts +18 -0
  27. package/dist/sdk/license-codec.d.ts +2 -0
  28. package/dist/sdk/license-public-key.d.ts +9 -0
  29. package/dist/sdk/license-runtime.d.ts +2 -0
  30. package/dist/sdk/license.d.ts +76 -0
  31. package/dist/sdk/lighting.d.ts +22 -0
  32. package/dist/sdk/ocr.d.ts +75 -0
  33. package/dist/sdk/programmatic-redaction.d.ts +102 -0
  34. package/dist/sdk/redact.d.ts +12 -0
  35. package/dist/sdk/scan.d.ts +32 -0
  36. package/dist/sdk/types.d.ts +92 -0
  37. package/package.json +74 -0
@@ -0,0 +1,1447 @@
1
+ //#region src/sdk/license-codec.ts
2
+ function e(e) {
3
+ let t = e.replaceAll("-", "+").replaceAll("_", "/"), n = t + "=".repeat((4 - t.length % 4) % 4), r = atob(n), i = new Uint8Array(r.length);
4
+ for (let e = 0; e < r.length; e += 1) i[e] = r.charCodeAt(e);
5
+ return i;
6
+ }
7
+ //#endregion
8
+ //#region src/sdk/license-runtime.ts
9
+ function t() {
10
+ return e("uFpA_UXGk-1AjjG31cFP6cqXOQX0w2TnuR7Bl-msZ6I");
11
+ }
12
+ //#endregion
13
+ //#region src/sdk/license.ts
14
+ var n = [
15
+ "localhost",
16
+ "127.0.0.1",
17
+ "exige-scanner-sdk.vercel.app",
18
+ "exige-park-app.ngrok.io",
19
+ "*.exige.io"
20
+ ], r = class extends Error {
21
+ code;
22
+ constructor(e, t) {
23
+ super(t), this.name = "LicenseError", this.code = e;
24
+ }
25
+ }, i, a;
26
+ function o(e) {
27
+ return e.trim().toLowerCase().replace(/\.$/u, "");
28
+ }
29
+ function s() {
30
+ let e = globalThis.location?.hostname;
31
+ if (typeof e == "string") return o(e) || void 0;
32
+ }
33
+ function c() {
34
+ return Math.floor(Date.now() / 1e3);
35
+ }
36
+ function l(e, t) {
37
+ let n = o(t);
38
+ if (n.startsWith("*.")) {
39
+ let t = n.slice(2);
40
+ return !t.includes(".") || t.startsWith(".") || t.includes("*") ? !1 : e === t || e.endsWith(`.${t}`);
41
+ }
42
+ return e === n;
43
+ }
44
+ function u(e) {
45
+ let t = o(e);
46
+ return !t || t.includes("*") ? !1 : n.some((e) => l(t, e));
47
+ }
48
+ function d(e) {
49
+ return {
50
+ customerId: "dev",
51
+ domains: [e],
52
+ exp: 4102444800,
53
+ features: {
54
+ scan: !0,
55
+ ocr: !0,
56
+ redaction: !0,
57
+ vehicles: !0,
58
+ torch: !0
59
+ }
60
+ };
61
+ }
62
+ function f(e) {
63
+ return {
64
+ customerId: e.customerId,
65
+ domains: [...e.domains],
66
+ exp: e.exp,
67
+ features: { ...e.features }
68
+ };
69
+ }
70
+ function p(e = "This license key is not a signed payload.") {
71
+ return new r("malformed", e);
72
+ }
73
+ function m(e) {
74
+ if (!e || typeof e != "object" || Array.isArray(e)) throw p();
75
+ let t = e;
76
+ if (typeof t.customerId != "string" || t.customerId.trim() === "" || t.customerId.length > 200) throw p("This license key is missing a customer id.");
77
+ if (!Array.isArray(t.domains) || t.domains.some((e) => typeof e != "string")) throw p("This license key is missing a domain list.");
78
+ if (typeof t.exp != "number" || !Number.isSafeInteger(t.exp) || t.exp <= 0) throw p("This license key is missing a Unix expiry.");
79
+ if (!t.features || typeof t.features != "object" || Array.isArray(t.features)) throw p("This license key is missing feature flags.");
80
+ let n = t.features, r = [...new Set(t.domains.map((e) => o(e)).filter(Boolean))].sort();
81
+ return {
82
+ customerId: t.customerId.trim(),
83
+ domains: r,
84
+ exp: t.exp,
85
+ features: {
86
+ scan: n.scan === !0,
87
+ ocr: n.ocr === !0,
88
+ redaction: n.redaction === !0,
89
+ vehicles: n.vehicles === !0,
90
+ torch: n.torch === !0
91
+ }
92
+ };
93
+ }
94
+ async function h(t, n) {
95
+ let i = t.trim().split(".");
96
+ if (i.length !== 2 || !i[0] || !i[1]) throw p();
97
+ let a, s;
98
+ try {
99
+ a = e(i[0]), s = e(i[1]);
100
+ } catch {
101
+ throw p();
102
+ }
103
+ let c, l = !1;
104
+ try {
105
+ c = await crypto.subtle.importKey("raw", n.publicKey, { name: "Ed25519" }, !1, ["verify"]), l = await crypto.subtle.verify("Ed25519", c, s, a);
106
+ } catch {
107
+ l = !1;
108
+ }
109
+ if (!l) throw new r("invalid-signature", "This license key signature does not match the SDK public key.");
110
+ let u;
111
+ try {
112
+ u = JSON.parse(new TextDecoder().decode(a));
113
+ } catch {
114
+ throw p();
115
+ }
116
+ let d = m(u);
117
+ if (d.exp <= n.now) throw new r("expired", "This license key has expired.");
118
+ let f = o(n.hostname);
119
+ if (!f || !d.domains.includes(f)) throw new r("domain", `This license key is not valid for ${f || "this host"}.`);
120
+ return d;
121
+ }
122
+ async function g(e) {
123
+ let n = s();
124
+ if (!n) throw new r("domain", "The license check requires a browser hostname.");
125
+ let o = await h(e, {
126
+ publicKey: t(),
127
+ hostname: n,
128
+ now: c()
129
+ });
130
+ return i = e.trim(), a = o, f(o);
131
+ }
132
+ function _() {
133
+ let e = s();
134
+ return a && e && a.domains.includes(e) && a.exp > c() ? f(a) : !i && e && u(e) ? f(d(e)) : null;
135
+ }
136
+ async function v(e) {
137
+ let n = s();
138
+ if (!n) throw new r("domain", "The license check requires a browser hostname.");
139
+ if (!i) {
140
+ if (u(n)) return f(d(n));
141
+ throw new r("missing", "A license key is required. Call setLicenseKey() before using the scanner SDK.");
142
+ }
143
+ let o = await h(i, {
144
+ publicKey: t(),
145
+ hostname: n,
146
+ now: c()
147
+ });
148
+ if (a = o, !o.features[e]) throw new r("feature", `This license key does not include the ${e} feature.`);
149
+ return f(o);
150
+ }
151
+ //#endregion
152
+ //#region src/sdk/document-geometry.ts
153
+ function y(e, t, n) {
154
+ return (t.x - e.x) * (n.y - e.y) - (t.y - e.y) * (n.x - e.x);
155
+ }
156
+ function b(e) {
157
+ let t = [...e].sort((e, t) => e.x - t.x || e.y - t.y);
158
+ if (t.length <= 3) return t;
159
+ let n = [];
160
+ for (let e of t) {
161
+ for (; n.length >= 2 && y(n.at(-2), n.at(-1), e) <= 0;) n.pop();
162
+ n.push(e);
163
+ }
164
+ let r = [];
165
+ for (let e = t.length - 1; e >= 0; --e) {
166
+ let n = t[e];
167
+ for (; r.length >= 2 && y(r.at(-2), r.at(-1), n) <= 0;) r.pop();
168
+ r.push(n);
169
+ }
170
+ return n.pop(), r.pop(), n.concat(r);
171
+ }
172
+ function x(e) {
173
+ let t = 0;
174
+ for (let n = 0; n < e.length; n += 1) {
175
+ let r = e[n], i = e[(n + 1) % e.length];
176
+ t += r.x * i.y - i.x * r.y;
177
+ }
178
+ return Math.abs(t) / 2;
179
+ }
180
+ function S(e) {
181
+ if (e.length < 4) return;
182
+ let t = e.reduce((e, t) => t.x + t.y < e.x + e.y ? t : e), n = e.reduce((e, t) => t.x + t.y > e.x + e.y ? t : e), r = e.reduce((e, t) => t.x - t.y > e.x - e.y ? t : e), i = e.reduce((e, t) => t.x - t.y < e.x - e.y ? t : e);
183
+ if ((/* @__PURE__ */ new Set([
184
+ t,
185
+ r,
186
+ n,
187
+ i
188
+ ])).size === 4) return {
189
+ topLeft: t,
190
+ topRight: r,
191
+ bottomRight: n,
192
+ bottomLeft: i
193
+ };
194
+ }
195
+ function C(e) {
196
+ return Math.max(0, Math.min(1, e));
197
+ }
198
+ function w(e, t) {
199
+ return Math.hypot(e.x - t.x, e.y - t.y);
200
+ }
201
+ function ee(e, t, n) {
202
+ let r = e.x - t.x, i = e.y - t.y, a = n.x - t.x, o = n.y - t.y, s = Math.max(1e-6, Math.hypot(r, i) * Math.hypot(a, o));
203
+ return Math.acos(Math.max(-1, Math.min(1, (r * a + i * o) / s))) * 180 / Math.PI;
204
+ }
205
+ function T(e, t, n, r) {
206
+ let i = Math.atan2(t.y - e.y, t.x - e.x), a = Math.atan2(r.y - n.y, r.x - n.x), o = Math.abs(i - a) % Math.PI;
207
+ return o > Math.PI / 2 && (o = Math.PI - o), o;
208
+ }
209
+ function E(e) {
210
+ let { topLeft: t, topRight: n, bottomRight: r, bottomLeft: i } = e, a = n.x - r.x, o = i.x - r.x, s = n.y - r.y, c = i.y - r.y, l = t.x - n.x + r.x - i.x, u = t.y - n.y + r.y - i.y, d = a * c - o * s, f = Math.abs(d) < 1e-6 ? 0 : (l * c - o * u) / d, p = Math.abs(d) < 1e-6 ? 0 : (a * u - l * s) / d;
211
+ return {
212
+ a: n.x - t.x + f * n.x,
213
+ b: i.x - t.x + p * i.x,
214
+ c: t.x,
215
+ d: n.y - t.y + f * n.y,
216
+ e: i.y - t.y + p * i.y,
217
+ f: t.y,
218
+ g: f,
219
+ h: p
220
+ };
221
+ }
222
+ function D(e, t) {
223
+ let { a: n, b: r, c: i, d: a, e: o, f: s, g: c, h: l } = t, u = n - e.x * c, d = r - e.x * l, f = a - e.y * c, p = o - e.y * l, m = e.x - i, h = e.y - s, g = u * p - d * f;
224
+ if (!(Math.abs(g) < 1e-8)) return {
225
+ x: (m * p - d * h) / g,
226
+ y: (u * h - m * f) / g
227
+ };
228
+ }
229
+ function te(e, t) {
230
+ if (!t.length) return 0;
231
+ let n = E(e), r = 0, i = 0, a = Math.max(1, Math.floor(t.length / 80));
232
+ for (let e = 0; e < t.length; e += a) {
233
+ let a = D(t[e], n);
234
+ if (!a) return 0;
235
+ let o = Math.min(Math.abs(a.x), Math.abs(1 - a.x), Math.abs(a.y), Math.abs(1 - a.y)) + Math.max(0, -a.x, a.x - 1, -a.y, a.y - 1) * 2;
236
+ r += o * o, i += 1;
237
+ }
238
+ let o = Math.sqrt(r / Math.max(1, i));
239
+ return Math.exp(-o / .08);
240
+ }
241
+ function O(e, t, n, r = [
242
+ e.topLeft,
243
+ e.topRight,
244
+ e.bottomRight,
245
+ e.bottomLeft
246
+ ]) {
247
+ let i = [
248
+ e.topLeft,
249
+ e.topRight,
250
+ e.bottomRight,
251
+ e.bottomLeft
252
+ ], a = Math.max(1, Math.min(t, n)), o = Math.max(0, ...i.map((e) => Math.max(-e.x, -e.y, e.x - t, e.y - n) / a)), s = i.map((e, t) => y(e, i[(t + 1) % 4], i[(t + 2) % 4])), c = s.every((e) => e > 0) || s.every((e) => e < 0), l = x(i) / Math.max(1, t * n);
253
+ if (!c || l < .04 || l > .995 || o > .12) return {
254
+ total: 0,
255
+ areaRatio: l,
256
+ angleScore: 0,
257
+ oppositeAngleScore: 0,
258
+ parallelScore: 0,
259
+ homographyScore: 0,
260
+ aspectBoost: 0
261
+ };
262
+ let u = i.map((e, t) => ee(i[(t + 3) % 4], e, i[(t + 1) % 4])), d = i.map((e, t) => w(e, i[(t + 1) % 4])), f = Math.max(d[0], d[2]) / Math.max(1, Math.min(d[0], d[2])), p = Math.max(d[1], d[3]) / Math.max(1, Math.min(d[1], d[3]));
263
+ if (u.some((e) => e < 18 || e > 162) || f > 4 || p > 4) return {
264
+ total: 0,
265
+ areaRatio: l,
266
+ angleScore: 0,
267
+ oppositeAngleScore: 0,
268
+ parallelScore: 0,
269
+ homographyScore: 0,
270
+ aspectBoost: 0
271
+ };
272
+ let m = u.reduce((e, t) => e + Math.exp(-Math.abs(t - 90) / 48), 0) / 4, h = (Math.exp(-Math.abs(u[0] + u[2] - 180) / 55) + Math.exp(-Math.abs(u[1] + u[3] - 180) / 55)) / 2, g = (Math.exp(-T(i[0], i[1], i[3], i[2]) / .62) + Math.exp(-T(i[0], i[3], i[1], i[2]) / .62)) / 2, _ = te(e, r), v = C((l - .04) / .5) * (l > .94 ? C((.995 - l) / .055) : 1), b = Math.exp(-Math.max(0, Math.max(f, p) - 1.6) / 1.5), S = o ? Math.exp(-o / .07) : 1, E = Math.max(w(i[0], i[1]), w(i[3], i[2])), D = Math.max(w(i[0], i[3]), w(i[1], i[2])), O = Math.max(E, D) / Math.max(1, Math.min(E, D)), k = Math.exp(-Math.abs(O - 1.58) / .18), A = Math.exp(-Math.abs(O - 1.29) / .18), j = O >= 2 ? C((O - 2) / 2) : 0, M = Math.max(k, A, j) * .08;
273
+ return {
274
+ total: C(v * .18 + m * .2 + h * .14 + g * .18 + _ * .3 + M) * (.72 + b * .28) * S,
275
+ areaRatio: l,
276
+ angleScore: m,
277
+ oppositeAngleScore: h,
278
+ parallelScore: g,
279
+ homographyScore: _,
280
+ aspectBoost: M
281
+ };
282
+ }
283
+ function k(e, t, n) {
284
+ let r = new Uint8Array(e.length);
285
+ for (let i = 1; i < n - 1; i += 1) for (let n = 1; n < t - 1; n += 1) {
286
+ let a = i * t + n;
287
+ if (e[a]) for (let e = -1; e <= 1; e += 1) for (let n = -1; n <= 1; n += 1) r[a + e * t + n] = 1;
288
+ }
289
+ return r;
290
+ }
291
+ function A(e, t) {
292
+ let n = Math.cos(e.theta), r = Math.sin(e.theta), i = Math.cos(t.theta), a = Math.sin(t.theta), o = n * a - i * r;
293
+ if (!(Math.abs(o) < .12)) return {
294
+ x: (e.rho * a - t.rho * r) / o,
295
+ y: (n * t.rho - i * e.rho) / o
296
+ };
297
+ }
298
+ function j(e, t) {
299
+ let n = Math.abs(e - t) % Math.PI;
300
+ return n > Math.PI / 2 && (n = Math.PI - n), n;
301
+ }
302
+ function M(e, t, n) {
303
+ let r = Math.ceil(Math.hypot(t, n)), i = r * 2 + 1, a = new Uint16Array(72 * i), o = Array.from({ length: 72 }, (e, t) => Math.cos(t * Math.PI / 72)), s = Array.from({ length: 72 }, (e, t) => Math.sin(t * Math.PI / 72)), c = [], l = e.reduce((e, t) => e + t, 0), u = Math.max(1, Math.ceil(l / 7e3)), d = 0;
304
+ for (let t = 0; t < e.length; t += 1) e[t] && (d++ % u || c.push(t));
305
+ for (let e of c) {
306
+ let n = e % t, c = Math.floor(e / t);
307
+ for (let e = 0; e < 72; e += 1) {
308
+ let t = Math.round(n * o[e] + c * s[e]) + r, l = e * i + t;
309
+ a[l] < 65535 && (a[l] += 1);
310
+ }
311
+ }
312
+ let f = [], p = Math.max(12, Math.round(Math.min(t, n) * .08 / u));
313
+ for (let e = 0; e < 72; e += 1) for (let t = 0; t < i; t += 1) {
314
+ let n = a[e * i + t];
315
+ n < p || f.push({
316
+ theta: e * Math.PI / 72,
317
+ rho: t - r,
318
+ votes: n
319
+ });
320
+ }
321
+ f.sort((e, t) => t.votes - e.votes);
322
+ let m = [];
323
+ for (let e of f) if (!m.some((r) => j(r.theta, e.theta) < Math.PI / 36 && Math.abs(r.rho - e.rho) < Math.min(t, n) * .035) && (m.push(e), m.length === 12)) break;
324
+ return m;
325
+ }
326
+ function ne(e, t, n) {
327
+ let r = M(e, t, n), i, a = 0;
328
+ for (let e = 0; e < r.length; e += 1) for (let o = e + 1; o < r.length; o += 1) if (!(j(r[e].theta, r[o].theta) > .38) && !(Math.abs(r[e].rho - r[o].rho) < Math.min(t, n) * .16)) {
329
+ for (let s = 0; s < r.length; s += 1) if (s !== e && s !== o && !(j(r[e].theta, r[s].theta) < .52)) for (let c = s + 1; c < r.length; c += 1) {
330
+ if (c === e || c === o || j(r[s].theta, r[c].theta) > .38 || Math.abs(r[s].rho - r[c].rho) < Math.min(t, n) * .16) continue;
331
+ let l = [
332
+ A(r[e], r[s]),
333
+ A(r[e], r[c]),
334
+ A(r[o], r[s]),
335
+ A(r[o], r[c])
336
+ ];
337
+ if (l.some((e) => !e)) continue;
338
+ let u = l;
339
+ if (u.some((e) => e.x < 0 || e.y < 0 || e.x > t - 1 || e.y > n - 1)) continue;
340
+ let d = S(u);
341
+ if (!d) continue;
342
+ let f = O(d, t, n);
343
+ if (!f.total) continue;
344
+ let p = C((r[e].votes + r[o].votes + r[s].votes + r[c].votes) / Math.max(1, Math.min(t, n) * 1.2)), m = C(f.total * .9 + p * .1), h = m * Math.sqrt(f.areaRatio);
345
+ h > a && (a = h, i = {
346
+ corners: d,
347
+ confidence: m,
348
+ areaRatio: f.areaRatio
349
+ });
350
+ }
351
+ }
352
+ return i;
353
+ }
354
+ function re(e, t, n, r = {}) {
355
+ if (e.length !== t * n) throw Error("Edge map dimensions do not match.");
356
+ let i = k(e, t, n), a = new Uint8Array(i.length), o = new Int32Array(i.length), s, c = 0, l = Math.max(24, Math.round(t * n * .0015));
357
+ for (let e = 0; e < i.length; e += 1) {
358
+ if (!i[e] || a[e]) continue;
359
+ let r = 0, u = 0;
360
+ o[u++] = e, a[e] = 1;
361
+ let d = [], f = 0;
362
+ for (; r < u;) {
363
+ let e = o[r++], s = e % t, c = Math.floor(e / t);
364
+ if (s === 0 || c === 0 || s === t - 1 || c === n - 1 || !i[e - 1] || !i[e + 1] || !i[e - t] || !i[e + t]) {
365
+ f += 1;
366
+ let e = {
367
+ x: s,
368
+ y: c
369
+ };
370
+ if (d.length < 12e3) d.push(e);
371
+ else {
372
+ let t = (f * 2654435761 >>> 0) % f;
373
+ t < d.length && (d[t] = e);
374
+ }
375
+ }
376
+ for (let r = -1; r <= 1; r += 1) for (let l = -1; l <= 1; l += 1) {
377
+ if (!l && !r || s + l < 0 || s + l >= t || c + r < 0 || c + r >= n) continue;
378
+ let d = e + r * t + l;
379
+ i[d] && !a[d] && (a[d] = 1, o[u++] = d);
380
+ }
381
+ }
382
+ if (u < l || u > t * n * .65 || d.length < 4) continue;
383
+ let p = b(d), m = S(p);
384
+ if (!m) continue;
385
+ let h = x([
386
+ m.topLeft,
387
+ m.topRight,
388
+ m.bottomRight,
389
+ m.bottomLeft
390
+ ]), g = x(p);
391
+ if (h <= 0) continue;
392
+ let _ = O(m, t, n, p);
393
+ if (!_.total) continue;
394
+ let v = Math.min(1, g / h), y = Math.min(1, u / Math.max(1, Math.sqrt(h) * 10)), C = Math.min(.98, _.total * .82 + v * .08 + y * .1), w = C * Math.sqrt(_.areaRatio);
395
+ w > c && (c = w, s = {
396
+ corners: m,
397
+ confidence: C,
398
+ areaRatio: _.areaRatio
399
+ });
400
+ }
401
+ return s ?? (r.lineFallback ? ne(e, t, n) : void 0);
402
+ }
403
+ function ie(e, t) {
404
+ let n = /* @__PURE__ */ new Uint32Array(511), r = 0;
405
+ for (let t of e) t && (n[Math.min(510, t)] += 1, r += 1);
406
+ let i = r * t, a = 0;
407
+ for (let e = 0; e < n.length; e += 1) if (a += n[e], a >= i) return e;
408
+ return 72;
409
+ }
410
+ function N(e, t, n) {
411
+ let r = -e[t - n - 1] + e[t - n + 1] - 2 * e[t - 1] + 2 * e[t + 1] - e[t + n - 1] + e[t + n + 1], i = -e[t - n - 1] - 2 * e[t - n] - e[t - n + 1] + e[t + n - 1] + 2 * e[t + n] + e[t + n + 1];
412
+ return (Math.abs(r) + Math.abs(i)) / 2;
413
+ }
414
+ function ae(e, t, n, r, i) {
415
+ let a = Math.floor(r), o = Math.floor(i), s = r - a, c = i - o, l = Math.max(0, Math.min(t - 1, a)), u = Math.max(0, Math.min(t - 1, a + 1)), d = Math.max(0, Math.min(n - 1, o)), f = Math.max(0, Math.min(n - 1, o + 1)), p = e[d * t + l] * (1 - s) + e[d * t + u] * s, m = e[f * t + l] * (1 - s) + e[f * t + u] * s;
416
+ return p * (1 - c) + m * c;
417
+ }
418
+ function oe(e, t, n, r, i = [], a = !1) {
419
+ let o = new Uint8Array(t * n), s = new Int16Array(t * n), c = new Int16Array(t * n);
420
+ for (let t = 0; t < o.length; t += 1) {
421
+ let n = t * 4;
422
+ o[t] = Math.round(e[n] * .299 + e[n + 1] * .587 + e[n + 2] * .114), s[t] = e[n] - e[n + 1], c[t] = e[n + 2] - e[n + 1];
423
+ }
424
+ let l = new Uint8Array(o), u = Math.max(24, Math.round(Math.min(t, n) / 12)), d = Math.ceil(t / u), f = Math.ceil(n / u), p = new Float32Array(d * f), m = new Float32Array(d * f);
425
+ for (let e = 0; e < f; e += 1) for (let r = 0; r < d; r += 1) {
426
+ let i = r * u, a = e * u, s = Math.min(t, i + u), c = Math.min(n, a + u), l = 255, f = 0, h = 0, g = 0;
427
+ for (let e = a; e < c; e += 1) for (let n = i; n < s; n += 1) {
428
+ let r = o[e * t + n];
429
+ l = Math.min(l, r), f = Math.max(f, r), h += r, g += 1;
430
+ }
431
+ let _ = f - l, v = e * d + r;
432
+ p[v] = h / Math.max(1, g), m[v] = _ < 10 ? 1 : Math.min(3, Math.max(1, 72 / _));
433
+ }
434
+ for (let e = 0; e < n; e += 1) {
435
+ let n = e / u - .5;
436
+ for (let r = 0; r < t; r += 1) {
437
+ let i = r / u - .5, a = e * t + r, s = ae(p, d, f, i, n), c = ae(m, d, f, i, n), h = s + (o[a] - s) * c;
438
+ l[a] = Math.max(0, Math.min(255, Math.round(o[a] * .58 + h * .42)));
439
+ }
440
+ }
441
+ let h = new Uint16Array(l.length), g = 0, _ = 0;
442
+ for (let e = 1; e < n - 1; e += 1) for (let n = 1; n < t - 1; n += 1) {
443
+ let r = e * t + n, i = N(l, r, t), a = Math.max(N(s, r, t), N(c, r, t)), o = Math.min(510, Math.round(i + a * .38));
444
+ h[r] = o, g += o, _ += 1;
445
+ }
446
+ let v = g / Math.max(1, _);
447
+ if (v < 3) return { sharpness: v };
448
+ let y = r ?? Math.max(26, ie(h, .82)), b = new Uint8Array(o.length), x = new Uint8Array(o.length);
449
+ for (let e = 0; e < h.length; e += 1) h[e] >= y ? b[e] = 1 : h[e] >= y * .55 && (x[e] = 1);
450
+ let S = new Uint8Array(b);
451
+ for (let e = 0; e < 2; e += 1) {
452
+ let e = new Uint8Array(S);
453
+ for (let r = 1; r < n - 1; r += 1) for (let n = 1; n < t - 1; n += 1) {
454
+ let i = r * t + n;
455
+ if (x[i] && !S[i]) {
456
+ for (let n = -1; n <= 1 && !e[i]; n += 1) for (let r = -1; r <= 1; r += 1) if (S[i + n * t + r]) {
457
+ e[i] = 1;
458
+ break;
459
+ }
460
+ }
461
+ }
462
+ S.set(e);
463
+ }
464
+ let C = new Uint8Array(S);
465
+ for (let e of i) if (e.length === C.length) for (let t = 0; t < C.length; t += 1) C[t] ||= e[t];
466
+ return {
467
+ sharpness: v,
468
+ edgeMap: S,
469
+ candidate: re(C, t, n, { lineFallback: a })
470
+ };
471
+ }
472
+ //#endregion
473
+ //#region src/sdk/image.ts
474
+ function se(e, t, n) {
475
+ let r = n ? Math.min(1, n / Math.max(e, t)) : 1;
476
+ return {
477
+ width: Math.max(1, Math.round(e * r)),
478
+ height: Math.max(1, Math.round(t * r))
479
+ };
480
+ }
481
+ async function ce(e) {
482
+ let t = URL.createObjectURL(e);
483
+ try {
484
+ let e = new Image();
485
+ return e.src = t, await e.decode(), e;
486
+ } finally {
487
+ URL.revokeObjectURL(t);
488
+ }
489
+ }
490
+ async function P(e, t = {}) {
491
+ if (e instanceof HTMLCanvasElement && t.cloneCanvas === !1 && !t.maxDimension) return e;
492
+ let n = document.createElement("canvas"), r = n.getContext("2d", { willReadFrequently: !0 });
493
+ if (!r) throw Error("Canvas 2D is unavailable in this browser.");
494
+ if (e instanceof Blob) {
495
+ if ("createImageBitmap" in window) try {
496
+ let i = await createImageBitmap(e), a = se(i.width, i.height, t.maxDimension);
497
+ return n.width = a.width, n.height = a.height, r.drawImage(i, 0, 0, a.width, a.height), i.close(), n;
498
+ } catch {}
499
+ e = await ce(e);
500
+ }
501
+ let i = e instanceof HTMLImageElement ? e.naturalWidth : e.width, a = e instanceof HTMLImageElement ? e.naturalHeight : e.height;
502
+ if (!i || !a) throw Error("The image has no readable dimensions.");
503
+ let o = se(i, a, t.maxDimension);
504
+ return n.width = o.width, n.height = o.height, r.drawImage(e, 0, 0, o.width, o.height), n;
505
+ }
506
+ function le(e, t = "image/png", n = .92) {
507
+ return new Promise((r, i) => e.toBlob((e) => e ? r(e) : i(/* @__PURE__ */ Error("Could not encode the image.")), t, n));
508
+ }
509
+ function ue(e, t, n) {
510
+ let r = Math.max(0, Math.min(t, e.x)), i = Math.max(0, Math.min(n, e.y));
511
+ return {
512
+ x: r,
513
+ y: i,
514
+ width: Math.max(0, Math.min(t - r, e.width)),
515
+ height: Math.max(0, Math.min(n - i, e.height))
516
+ };
517
+ }
518
+ //#endregion
519
+ //#region src/sdk/scan.ts
520
+ var de = "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
521
+ function F(e = "classical", t) {
522
+ if (e !== "classical") return t?.trim() || "https://exige-scanner-sdk.vercel.app/models/docaligner-lcnet100-f4117b78.onnx";
523
+ }
524
+ var I = /* @__PURE__ */ new WeakMap(), L, fe = 0, R = /* @__PURE__ */ new Map();
525
+ function z(e, t) {
526
+ return Math.hypot(e.x - t.x, e.y - t.y);
527
+ }
528
+ function B(e) {
529
+ return {
530
+ ...e,
531
+ edges: {
532
+ top: {
533
+ start: e.topLeft,
534
+ end: e.topRight
535
+ },
536
+ right: {
537
+ start: e.topRight,
538
+ end: e.bottomRight
539
+ },
540
+ bottom: {
541
+ start: e.bottomRight,
542
+ end: e.bottomLeft
543
+ },
544
+ left: {
545
+ start: e.bottomLeft,
546
+ end: e.topLeft
547
+ }
548
+ }
549
+ };
550
+ }
551
+ function pe(e, t) {
552
+ let n = (e) => ({
553
+ x: e.x / t,
554
+ y: e.y / t
555
+ });
556
+ return {
557
+ topLeft: n(e.topLeft),
558
+ topRight: n(e.topRight),
559
+ bottomRight: n(e.bottomRight),
560
+ bottomLeft: n(e.bottomLeft)
561
+ };
562
+ }
563
+ function V() {
564
+ return typeof navigator > "u" ? !1 : navigator.maxTouchPoints > 0 || navigator.hardwareConcurrency <= 4 || typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
565
+ }
566
+ function me(e, t, n, r, i = []) {
567
+ return new Promise((a, o) => {
568
+ L || (L = new Worker(new URL(
569
+ /* @vite-ignore */
570
+ new URL("assets/document-worker-QjcJjl9-.js", import.meta.url).href,
571
+ "" + import.meta.url
572
+ ), { type: "module" }), L.onmessage = (e) => {
573
+ let t = R.get(e.data.id);
574
+ t && (R.delete(e.data.id), e.data.error ? t.reject(Error(e.data.error)) : e.data.result ? t.resolve(e.data.result) : t.reject(/* @__PURE__ */ Error("The document worker returned no result.")));
575
+ }, L.onerror = () => {
576
+ let e = /* @__PURE__ */ Error("The document worker could not start.");
577
+ for (let t of R.values()) t.reject(e);
578
+ R.clear(), L?.terminate(), L = void 0;
579
+ });
580
+ let s = ++fe;
581
+ R.set(s, {
582
+ resolve: a,
583
+ reject: o
584
+ });
585
+ let c = e.slice().buffer;
586
+ L.postMessage({
587
+ id: s,
588
+ pixels: c,
589
+ width: t,
590
+ height: n,
591
+ edgeThreshold: r.edgeThreshold,
592
+ priorEdgeMaps: i,
593
+ lineFallback: r.lineFallback,
594
+ detector: r.detector,
595
+ modelUrl: F(r.detector, r.modelUrl),
596
+ heatmapThreshold: r.heatmapThreshold,
597
+ cacheModel: r.cacheModel,
598
+ ortWasmPaths: r.ortWasmPaths
599
+ }, [c]);
600
+ });
601
+ }
602
+ async function H(e, t) {
603
+ let { width: n, height: r } = e, i = t.minDimension ?? 360;
604
+ if (Math.min(n, r) < i) return {
605
+ status: "low-quality",
606
+ confidence: 0,
607
+ message: `Use an image at least ${i}px on its shortest side.`,
608
+ sourceWidth: n,
609
+ sourceHeight: r
610
+ };
611
+ let a = V() ? 560 : 900, o = Math.min(1, (t.maxAnalysisDimension ?? a) / Math.max(n, r)), s = document.createElement("canvas");
612
+ s.width = Math.max(1, Math.round(n * o)), s.height = Math.max(1, Math.round(r * o));
613
+ let c = s.getContext("2d", { willReadFrequently: !0 });
614
+ if (!c) throw Error("Canvas 2D is unavailable in this browser.");
615
+ c.drawImage(e, 0, 0, s.width, s.height);
616
+ let l = c.getImageData(0, 0, s.width, s.height).data, u = Math.max(1, Math.min(4, t.temporalEdgeWindow ?? 1)), d = u > 1 ? I.get(t) ?? [] : [], f;
617
+ if (t.useWorker !== !1 && typeof Worker < "u") try {
618
+ f = await me(l, s.width, s.height, t, d);
619
+ } catch (e) {
620
+ let n = e instanceof Error ? e.message : "Document worker failed.";
621
+ f = t.detector === "ml" ? {
622
+ sharpness: 20,
623
+ detector: "ml",
624
+ modelStatus: "failed",
625
+ modelError: n
626
+ } : {
627
+ ...oe(l, s.width, s.height, t.edgeThreshold, d, t.lineFallback),
628
+ detector: "classical",
629
+ modelStatus: t.detector === "auto" ? "fallback" : "not-requested",
630
+ modelError: t.detector === "auto" ? n : void 0
631
+ };
632
+ }
633
+ else {
634
+ let e = t.detector === "ml" || t.detector === "auto";
635
+ f = {
636
+ ...oe(l, s.width, s.height, t.edgeThreshold, d, t.lineFallback),
637
+ detector: "classical",
638
+ modelStatus: e ? "fallback" : "not-requested",
639
+ modelError: e ? "ML detection requires a Web Worker." : void 0
640
+ };
641
+ }
642
+ u > 1 && f.edgeMap && I.set(t, [f.edgeMap, ...d].slice(0, u - 1));
643
+ let { sharpness: p, candidate: m, detector: h, modelStatus: g, modelProvider: _, modelError: v, inferenceMs: y } = f, b = {
644
+ detector: h,
645
+ modelStatus: g,
646
+ modelProvider: _,
647
+ modelError: v,
648
+ inferenceMs: y
649
+ };
650
+ if (p < 3) return {
651
+ status: "low-quality",
652
+ confidence: Math.min(.3, p / 18),
653
+ message: "The image is too soft or dark to resolve four document edges.",
654
+ sourceWidth: n,
655
+ sourceHeight: r,
656
+ ...b
657
+ };
658
+ if (!m) return {
659
+ status: "no-document",
660
+ confidence: 0,
661
+ message: "No closed document contour found. Place all four edges on a contrasting surface.",
662
+ sourceWidth: n,
663
+ sourceHeight: r,
664
+ ...b
665
+ };
666
+ let x = pe(m.corners, o), S = B(x), C = t.minConfidence ?? .58;
667
+ return m.confidence < C ? {
668
+ status: "low-confidence",
669
+ quad: S,
670
+ corners: x,
671
+ confidence: m.confidence,
672
+ message: "Four possible edges were found, but the contour is not reliable enough to crop.",
673
+ sourceWidth: n,
674
+ sourceHeight: r,
675
+ ...b
676
+ } : {
677
+ status: "success",
678
+ quad: S,
679
+ corners: x,
680
+ confidence: m.confidence,
681
+ message: "Four document edges detected.",
682
+ sourceWidth: n,
683
+ sourceHeight: r,
684
+ ...b
685
+ };
686
+ }
687
+ function he(e, t) {
688
+ let n = Math.max(1, Math.round(Math.max(z(e.topLeft, e.topRight), z(e.bottomLeft, e.bottomRight)))), r = Math.max(1, Math.round(Math.max(z(e.topLeft, e.bottomLeft), z(e.topRight, e.bottomRight)))), i = Math.min(1, t / Math.max(n, r));
689
+ return {
690
+ width: Math.max(1, Math.round(n * i)),
691
+ height: Math.max(1, Math.round(r * i))
692
+ };
693
+ }
694
+ function U(e, t, n) {
695
+ let { width: r, height: i } = he(t, n), a = e.getContext("2d", { willReadFrequently: !0 });
696
+ if (!a) throw Error("Canvas 2D is unavailable in this browser.");
697
+ let o = a.getImageData(0, 0, e.width, e.height), s = document.createElement("canvas");
698
+ s.width = r, s.height = i;
699
+ let c = s.getContext("2d");
700
+ if (!c) throw Error("Canvas 2D is unavailable in this browser.");
701
+ let l = c.createImageData(r, i), { topLeft: u, topRight: d, bottomRight: f, bottomLeft: p } = t, m = d.x - f.x, h = p.x - f.x, g = d.y - f.y, _ = p.y - f.y, v = u.x - d.x + f.x - p.x, y = u.y - d.y + f.y - p.y, b = m * _ - h * g, x = Math.abs(b) < 1e-4 ? 0 : (v * _ - h * y) / b, S = Math.abs(b) < 1e-4 ? 0 : (m * y - v * g) / b, C = d.x - u.x + x * d.x, w = p.x - u.x + S * p.x, ee = d.y - u.y + x * d.y, T = p.y - u.y + S * p.y;
702
+ for (let t = 0; t < i; t += 1) {
703
+ let n = t / Math.max(1, i - 1);
704
+ for (let i = 0; i < r; i += 1) {
705
+ let a = i / Math.max(1, r - 1), s = x * a + S * n + 1, c = Math.max(0, Math.min(e.width - 1, Math.round((C * a + w * n + u.x) / s))), d = (Math.max(0, Math.min(e.height - 1, Math.round((ee * a + T * n + u.y) / s))) * e.width + c) * 4, f = (t * r + i) * 4;
706
+ l.data[f] = o.data[d], l.data[f + 1] = o.data[d + 1], l.data[f + 2] = o.data[d + 2], l.data[f + 3] = o.data[d + 3];
707
+ }
708
+ }
709
+ return c.putImageData(l, 0, 0), s;
710
+ }
711
+ async function W(e, t = {}) {
712
+ return await v("scan"), H(await P(e, { cloneCanvas: !1 }), t);
713
+ }
714
+ async function ge(e, t, n = {}) {
715
+ await v("scan");
716
+ let r = await P(e, { cloneCanvas: !1 }), i = n.maxOutputDimension ?? (V() ? 2048 : 4096);
717
+ return {
718
+ status: "success",
719
+ corners: t,
720
+ quad: B(t),
721
+ confidence: 1,
722
+ message: "Captured with the document edges shown in the finder.",
723
+ sourceWidth: r.width,
724
+ sourceHeight: r.height,
725
+ canvas: U(r, t, i)
726
+ };
727
+ }
728
+ async function _e(e, t = {}) {
729
+ await v("scan");
730
+ let n = await P(e, { cloneCanvas: !1 }), r = await H(n, t);
731
+ if (r.status !== "success" || !r.corners) return r;
732
+ let i = t.maxOutputDimension ?? (V() ? 2048 : 4096);
733
+ return {
734
+ ...r,
735
+ canvas: U(n, r.corners, i),
736
+ message: "Four document edges detected and perspective-corrected."
737
+ };
738
+ }
739
+ //#endregion
740
+ //#region src/sdk/camera.ts
741
+ function G(e, t) {
742
+ let { engine: n } = t;
743
+ return [
744
+ `${e}:`,
745
+ ` engine: ${n.engine}/${n.browser}${n.iosWebKit ? " ios-webkit" : ""}`,
746
+ ` ua: ${n.userAgent}`,
747
+ ` video: ${t.videoWidth}x${t.videoHeight} readyState=${t.readyState}${t.paused ? " paused" : ""}${t.rendered ? "" : " hidden"}${t.connected ? "" : " disconnected"}`,
748
+ ` track: ${t.trackReadyState}${t.trackEnabled ? "" : " disabled"}${t.trackMuted ? " muted" : ""}`,
749
+ ` liveLuma: ${t.liveLuminance.toFixed(1)}`,
750
+ ` mirrorLuma: ${t.mirrorLuminance.toFixed(1)}`,
751
+ ` mirrorAgeMs: ${Number.isFinite(t.mirrorAgeMs) ? Math.round(t.mirrorAgeMs) : "none"}`,
752
+ ` hasImageCapture: ${t.hasImageCapture} (never used)`,
753
+ ` torch: ${t.torch.mode} supported=${t.torch.supported} on=${t.torch.on}`
754
+ ].join("\n");
755
+ }
756
+ function ve(e) {
757
+ let t = ["Exige scanner capture report", `time: ${e.capturedAt ?? (/* @__PURE__ */ new Date()).toISOString()}`];
758
+ 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(G("shutter", e.shutter)), e.live && t.push(G("live", e.live)), e.finder) {
759
+ let n = e.finder;
760
+ t.push([
761
+ "finder:",
762
+ ` state: ${n.state ?? "unknown"}`,
763
+ ` confidence: ${n.confidence === void 0 ? "—" : n.confidence.toFixed(3)}`,
764
+ ` stable: ${n.stableFrames ?? "—"}/${n.requiredStableFrames ?? "—"}`,
765
+ ` detector: ${n.detector ?? "—"} ${n.modelStatus ?? ""}`.trim(),
766
+ ` source: ${n.sourceWidth ?? "—"}x${n.sourceHeight ?? "—"}`
767
+ ].join("\n"));
768
+ }
769
+ return `${t.join("\n")}\n`;
770
+ }
771
+ function K(e = typeof navigator > "u" ? "" : navigator.userAgent, t = typeof navigator > "u" ? 0 : navigator.maxTouchPoints) {
772
+ 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;
773
+ return {
774
+ 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",
775
+ browser: n,
776
+ iosWebKit: a,
777
+ userAgent: e
778
+ };
779
+ }
780
+ var ye = 10, be = class {
781
+ on = !1;
782
+ darkCount = 0;
783
+ brightCount = 0;
784
+ turnOnLuminance;
785
+ turnOffLuminance;
786
+ darkSamples;
787
+ brightSamples;
788
+ constructor(e = {}) {
789
+ this.turnOnLuminance = e.turnOnLuminance ?? 62, this.turnOffLuminance = e.turnOffLuminance ?? 155, this.darkSamples = e.darkSamples ?? 3, this.brightSamples = e.brightSamples ?? 8;
790
+ }
791
+ update(e) {
792
+ if (!Number.isFinite(e) || e <= 10) {
793
+ this.darkCount = 0, this.brightCount = 0;
794
+ return;
795
+ }
796
+ if (!this.on) return this.brightCount = 0, this.darkCount = e <= this.turnOnLuminance ? this.darkCount + 1 : 0, this.darkCount < this.darkSamples ? void 0 : (this.darkCount = 0, this.on = !0, !0);
797
+ if (this.darkCount = 0, this.brightCount = e >= this.turnOffLuminance ? this.brightCount + 1 : 0, !(this.brightCount < this.brightSamples)) return this.brightCount = 0, this.on = !1, !1;
798
+ }
799
+ getState() {
800
+ return this.on;
801
+ }
802
+ };
803
+ function xe(e, t) {
804
+ return t ? e === "alwaysOn" || e === "alwaysOff" ? {
805
+ mode: e,
806
+ supported: !0,
807
+ on: e === "alwaysOn",
808
+ visible: !1,
809
+ mutable: !1,
810
+ automatic: !1
811
+ } : {
812
+ mode: e,
813
+ supported: !0,
814
+ on: e === "defaultOn",
815
+ visible: !0,
816
+ mutable: e !== "auto",
817
+ automatic: e === "auto"
818
+ } : {
819
+ mode: e,
820
+ supported: !1,
821
+ on: !1,
822
+ visible: !1,
823
+ mutable: !1,
824
+ automatic: e === "auto"
825
+ };
826
+ }
827
+ function q(e) {
828
+ let t = Math.floor(e.length / 4);
829
+ if (!t) return 0;
830
+ let n = 0;
831
+ for (let r = 0; r < t * 4; r += 4) n += e[r] * .299 + e[r + 1] * .587 + e[r + 2] * .114;
832
+ return n / t;
833
+ }
834
+ function Se(e, t = 10) {
835
+ if (e.length < 4) return !0;
836
+ let n = Math.floor(e.length / 4), r = 0;
837
+ for (let i = 0; i < n * 4; i += 4) e[i] * .299 + e[i + 1] * .587 + e[i + 2] * .114 > t * 2 && (r += 1);
838
+ return q(e) <= t && r / n < .01;
839
+ }
840
+ function Ce(e, t, n) {
841
+ if (!t || !n) return 0;
842
+ let r = document.createElement("canvas");
843
+ r.width = Math.min(32, t), r.height = Math.min(32, n);
844
+ let i = r.getContext("2d", { willReadFrequently: !0 });
845
+ return i ? (i.drawImage(e, 0, 0, r.width, r.height), q(i.getImageData(0, 0, r.width, r.height).data)) : 0;
846
+ }
847
+ function we(e) {
848
+ return Ce(e, e.width, e.height);
849
+ }
850
+ function Te(e, t = 120) {
851
+ 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 = () => {
852
+ a && (o = i ? e.requestVideoFrameCallback(f) : requestAnimationFrame(f));
853
+ };
854
+ function f() {
855
+ if (!a) return;
856
+ let { videoWidth: i, videoHeight: o } = e, f = performance.now();
857
+ r && i && o && f - s >= t && (s = f, l = Ce(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();
858
+ }
859
+ return d(), {
860
+ stop() {
861
+ a = !1, i ? e.cancelVideoFrameCallback?.(o) : cancelAnimationFrame(o);
862
+ },
863
+ getFrame: () => c ? n : void 0,
864
+ getLiveLuminance: () => l,
865
+ getMirrorLuminance: () => u,
866
+ getMirrorAgeMs: () => c ? performance.now() - c : Infinity
867
+ };
868
+ }
869
+ function Ee(e) {
870
+ let t = document.createElement("canvas");
871
+ return t.width = e.width, t.height = e.height, t.getContext("2d")?.drawImage(e, 0, 0), t;
872
+ }
873
+ function J(e = {}) {
874
+ let t = { ideal: e.idealWidth ?? 3840 }, n = { ideal: e.idealHeight ?? 2160 };
875
+ return e.maxWidth && (t.max = e.maxWidth), e.maxHeight && (n.max = e.maxHeight), {
876
+ audio: !1,
877
+ video: {
878
+ facingMode: { ideal: e.facingMode ?? "environment" },
879
+ width: t,
880
+ height: n,
881
+ frameRate: {
882
+ ideal: e.maxFrameRate ?? 30,
883
+ max: e.maxFrameRate ?? 30
884
+ }
885
+ }
886
+ };
887
+ }
888
+ function Y(e, t) {
889
+ if (!e.videoWidth || !e.videoHeight) throw Error("The camera is not ready to capture a frame.");
890
+ let n = t ? Math.min(1, t / Math.max(e.videoWidth, e.videoHeight)) : 1, r = document.createElement("canvas");
891
+ r.width = Math.max(1, Math.round(e.videoWidth * n)), r.height = Math.max(1, Math.round(e.videoHeight * n));
892
+ let i = r.getContext("2d");
893
+ if (!i) throw Error("Canvas 2D is unavailable in this browser.");
894
+ return i.drawImage(e, 0, 0, r.width, r.height), r;
895
+ }
896
+ function De(e) {
897
+ return e.idealWidth || e.idealHeight || e.maxWidth || e.maxHeight ? [J(e)] : [
898
+ J({
899
+ ...e,
900
+ idealWidth: 3840,
901
+ idealHeight: 2160
902
+ }),
903
+ J({
904
+ ...e,
905
+ idealWidth: 2560,
906
+ idealHeight: 1440
907
+ }),
908
+ J({
909
+ ...e,
910
+ idealWidth: 1920,
911
+ idealHeight: 1080
912
+ })
913
+ ];
914
+ }
915
+ async function Oe(e, t = {}) {
916
+ await v("scan");
917
+ let n = t.torch ?? "alwaysOff";
918
+ if (n !== "alwaysOff" && await v("torch"), !window.isSecureContext && location.hostname !== "localhost") throw Error("Camera access requires HTTPS.");
919
+ if (!navigator.mediaDevices?.getUserMedia) throw Error("Live camera access is unavailable. Use the native camera picker instead.");
920
+ e.muted = !0, e.autoplay = !0, e.playsInline = !0, e.setAttribute("playsinline", "");
921
+ let r, i;
922
+ for (let e of De(t)) try {
923
+ r = await navigator.mediaDevices.getUserMedia(e);
924
+ break;
925
+ } catch (e) {
926
+ if (i = e, !(e instanceof DOMException) || e.name !== "OverconstrainedError") throw e;
927
+ }
928
+ if (!r) throw i ?? /* @__PURE__ */ Error("No rear camera resolution is available.");
929
+ e.srcObject = r, await e.play();
930
+ let a = r.getVideoTracks()[0];
931
+ if (!a) {
932
+ for (let e of r.getTracks()) e.stop();
933
+ throw Error("The camera did not provide a video track.");
934
+ }
935
+ let o = Te(e), s = "ImageCapture" in globalThis, c = xe(n, (typeof a.getCapabilities == "function" ? a.getCapabilities() : void 0)?.torch === !0), l = !1, u = async (e) => {
936
+ if (!c.supported || a.readyState !== "live") return !1;
937
+ try {
938
+ return await a.applyConstraints({ advanced: [{ torch: e }] }), c = {
939
+ ...c,
940
+ on: e
941
+ }, !0;
942
+ } catch {
943
+ return c = {
944
+ ...c,
945
+ supported: !1,
946
+ on: !1,
947
+ visible: !1,
948
+ mutable: !1
949
+ }, !1;
950
+ }
951
+ };
952
+ c.on && await u(!0);
953
+ let d = n === "auto" && c.supported ? new be() : void 0, f = d ? window.setInterval(() => {
954
+ if (l || !c.supported) return;
955
+ let e = d.update(o.getLiveLuminance());
956
+ e !== void 0 && e !== c.on && (l = !0, u(e).finally(() => {
957
+ l = !1;
958
+ }));
959
+ }, 350) : 0, p = () => {
960
+ let t = e.getBoundingClientRect();
961
+ return {
962
+ videoWidth: e.videoWidth,
963
+ videoHeight: e.videoHeight,
964
+ readyState: e.readyState,
965
+ paused: e.paused,
966
+ connected: e.isConnected,
967
+ rendered: t.width > 0 && t.height > 0,
968
+ trackReadyState: a.readyState ?? "missing",
969
+ trackEnabled: a.enabled,
970
+ trackMuted: a.muted,
971
+ liveLuminance: o.getLiveLuminance(),
972
+ mirrorLuminance: o.getMirrorLuminance(),
973
+ mirrorAgeMs: o.getMirrorAgeMs(),
974
+ hasImageCapture: s,
975
+ torchMode: c.mode,
976
+ torchSupported: c.supported,
977
+ torchOn: c.on,
978
+ torch: { ...c },
979
+ engine: K()
980
+ };
981
+ };
982
+ return {
983
+ stream: r,
984
+ get torchMode() {
985
+ return c.mode;
986
+ },
987
+ get torchSupported() {
988
+ return c.supported;
989
+ },
990
+ get torchOn() {
991
+ return c.on;
992
+ },
993
+ capture: (t) => Y(e, t),
994
+ async capturePhoto() {
995
+ let t, n = 0;
996
+ try {
997
+ t = Y(e), n = we(t);
998
+ } catch {
999
+ t = void 0;
1000
+ }
1001
+ let r = o.getFrame(), i = t && n > 10 ? t : void 0, s = i ?? (r ? Ee(r) : void 0);
1002
+ if (!s) throw Error("The camera preview produced no visible pixels. Keep the scanner on screen, wait for the preview, and retake.");
1003
+ return {
1004
+ frame: s,
1005
+ method: i ? "video-frame" : "live-mirror",
1006
+ settings: a.getSettings(),
1007
+ fallbackReason: i ? void 0 : "video-frame-empty",
1008
+ luminance: i ? n : o.getMirrorLuminance(),
1009
+ diagnostics: p()
1010
+ };
1011
+ },
1012
+ getSettings: () => a.getSettings(),
1013
+ getDiagnostics: p,
1014
+ getTorchStatus: () => ({ ...c }),
1015
+ async setTorch(e) {
1016
+ return c.mutable ? u(e) : !1;
1017
+ },
1018
+ stop() {
1019
+ f && window.clearInterval(f), o.stop();
1020
+ for (let e of r.getTracks()) e.stop();
1021
+ e.srcObject === r && (e.srcObject = null);
1022
+ }
1023
+ };
1024
+ }
1025
+ //#endregion
1026
+ //#region src/sdk/lighting.ts
1027
+ function ke(e, t) {
1028
+ if (!e.length) return 0;
1029
+ let n = [...e].sort((e, t) => e - t);
1030
+ return n[Math.min(n.length - 1, Math.floor(n.length * t))];
1031
+ }
1032
+ function Ae(e, t, n, r = 12) {
1033
+ if (!t || !n || e.length < t * n) return {
1034
+ strong: !1,
1035
+ strength: 0,
1036
+ darkness: 0,
1037
+ areaRatio: 0
1038
+ };
1039
+ let i = Math.min(r, t), a = Math.min(r, n), o = [];
1040
+ for (let r = 0; r < a; r += 1) {
1041
+ let s = Math.floor(r * n / a), c = Math.max(s + 1, Math.floor((r + 1) * n / a));
1042
+ for (let n = 0; n < i; n += 1) {
1043
+ let r = Math.floor(n * t / i), a = Math.max(r + 1, Math.floor((n + 1) * t / i)), l = 0, u = 0, d = 0;
1044
+ for (let n = s; n < c; n += 1) for (let i = r; i < a; i += 1) {
1045
+ let r = e[n * t + i];
1046
+ l += r, u += r * r, d += 1;
1047
+ }
1048
+ let f = l / d;
1049
+ o.push({
1050
+ mean: f,
1051
+ deviation: Math.sqrt(Math.max(0, u / d - f * f))
1052
+ });
1053
+ }
1054
+ }
1055
+ let s = ke(o.map((e) => e.mean), .8), c = o.map((e) => s - e.mean >= 24 && e.mean >= 35), l = new Uint8Array(o.length), u = [];
1056
+ for (let e = 0; e < o.length; e += 1) {
1057
+ if (!c[e] || l[e]) continue;
1058
+ let t = [], n = [e];
1059
+ for (l[e] = 1; n.length;) {
1060
+ let e = n.shift();
1061
+ t.push(e);
1062
+ let r = Math.floor(e / i), o = e % i;
1063
+ for (let [e, t] of [
1064
+ [o - 1, r],
1065
+ [o + 1, r],
1066
+ [o, r - 1],
1067
+ [o, r + 1]
1068
+ ]) {
1069
+ if (e < 0 || e >= i || t < 0 || t >= a) continue;
1070
+ let r = t * i + e;
1071
+ c[r] && !l[r] && (l[r] = 1, n.push(r));
1072
+ }
1073
+ }
1074
+ u.push(t);
1075
+ }
1076
+ let d = {
1077
+ strong: !1,
1078
+ strength: 0,
1079
+ darkness: 0,
1080
+ areaRatio: 0
1081
+ };
1082
+ for (let e of u) {
1083
+ let t = e.length / o.length;
1084
+ if (t < .06 || t > .75) continue;
1085
+ let n = e.reduce((e, t) => e + s - o[t].mean, 0) / e.length, r = e.filter((e) => o[e].deviation >= 9).length / e.length;
1086
+ if (r < .08 && n < 42) continue;
1087
+ let c = e.map((e) => e % i), l = e.map((e) => Math.floor(e / i)), u = Math.min(...c), f = Math.max(...c), p = Math.min(...l), m = Math.max(...l), h = Math.max(0, u - 1) / i, g = Math.max(0, p - 1) / a, _ = Math.min(i, f + 1 + 1) / i, v = Math.min(a, m + 1 + 1) / a, y = n * Math.sqrt(t) * (.75 + Math.min(.25, r));
1088
+ y > d.strength && (d = {
1089
+ strong: y >= 10,
1090
+ strength: y,
1091
+ darkness: n,
1092
+ areaRatio: t,
1093
+ region: {
1094
+ x: h,
1095
+ y: g,
1096
+ width: _ - h,
1097
+ height: v - g
1098
+ }
1099
+ });
1100
+ }
1101
+ return d;
1102
+ }
1103
+ function je(e, t, n, r = Math.max(12, Math.round(Math.max(t, n) / 32))) {
1104
+ let i = t + 1, a = new Uint32Array((t + 1) * (n + 1));
1105
+ for (let r = 1; r <= n; r += 1) {
1106
+ let n = 0;
1107
+ for (let o = 1; o <= t; o += 1) n += e[(r - 1) * t + o - 1], a[r * i + o] = a[(r - 1) * i + o] + n;
1108
+ }
1109
+ let o = new Uint8Array(e.length);
1110
+ for (let s = 0; s < n; s += 1) {
1111
+ let c = Math.max(0, s - r), l = Math.min(n, s + r + 1);
1112
+ for (let n = 0; n < t; n += 1) {
1113
+ let u = Math.max(0, n - r), d = Math.min(t, n + r + 1), f = (d - u) * (l - c), p = (a[l * i + d] - a[c * i + d] - a[l * i + u] + a[c * i + u]) / f;
1114
+ o[s * t + n] = Math.max(0, Math.min(255, Math.round(e[s * t + n] * 235 / Math.max(24, p))));
1115
+ }
1116
+ }
1117
+ return o;
1118
+ }
1119
+ function Me(e, t, n) {
1120
+ let r = [
1121
+ e.topLeft,
1122
+ e.topRight,
1123
+ e.bottomRight,
1124
+ e.bottomLeft
1125
+ ], i = Math.max(0, Math.min(...r.map((e) => e.x))), a = Math.max(0, Math.min(...r.map((e) => e.y))), o = Math.min(t, Math.max(...r.map((e) => e.x))), s = Math.min(n, Math.max(...r.map((e) => e.y)));
1126
+ return {
1127
+ left: i,
1128
+ top: a,
1129
+ width: o - i,
1130
+ height: s - a
1131
+ };
1132
+ }
1133
+ function Ne(e, t) {
1134
+ let n = Me(t, e.width, e.height);
1135
+ if (n.width <= 0 || n.height <= 0) return {
1136
+ strong: !1,
1137
+ strength: 0,
1138
+ darkness: 0,
1139
+ areaRatio: 0
1140
+ };
1141
+ let r = document.createElement("canvas");
1142
+ r.width = 60, r.height = 60;
1143
+ let i = r.getContext("2d", { willReadFrequently: !0 });
1144
+ if (!i) return {
1145
+ strong: !1,
1146
+ strength: 0,
1147
+ darkness: 0,
1148
+ areaRatio: 0
1149
+ };
1150
+ i.drawImage(e, n.left, n.top, n.width, n.height, 0, 0, r.width, r.height);
1151
+ let a = i.getImageData(0, 0, r.width, r.height).data, o = new Uint8Array(r.width * r.height);
1152
+ 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);
1153
+ return Ae(o, r.width, r.height);
1154
+ }
1155
+ //#endregion
1156
+ //#region src/sdk/finder.ts
1157
+ function Pe(e, t) {
1158
+ return t.castShadow && (e.reason === "hold-still" || e.reason === "ready") ? t.hint ?? e.hint : e.hint;
1159
+ }
1160
+ async function Fe(e, t) {
1161
+ let n = await e();
1162
+ return t(), n;
1163
+ }
1164
+ function Ie(e) {
1165
+ return e === "alwaysOn" ? {
1166
+ visible: !1,
1167
+ checked: !0,
1168
+ mutable: !1
1169
+ } : e === "alwaysOff" ? {
1170
+ visible: !1,
1171
+ checked: !1,
1172
+ mutable: !1
1173
+ } : {
1174
+ visible: !0,
1175
+ checked: e === "defaultOn",
1176
+ mutable: !0
1177
+ };
1178
+ }
1179
+ function X(e) {
1180
+ return [
1181
+ e.topLeft,
1182
+ e.topRight,
1183
+ e.bottomRight,
1184
+ e.bottomLeft
1185
+ ];
1186
+ }
1187
+ var Le = 4, Re = .72, ze = .024, Be = .036, Ve = .72, He = .64, Ue = 2.2, We = .08, Ge = .015, Ke = .005, qe = .48, Je = .4;
1188
+ function Ye(e) {
1189
+ let t = 0;
1190
+ for (let n = 0; n < e.length; n += 1) {
1191
+ let r = e[n], i = e[(n + 1) % e.length];
1192
+ t += r.x * i.y - i.x * r.y;
1193
+ }
1194
+ return Math.abs(t) / 2;
1195
+ }
1196
+ function Z(e, t) {
1197
+ return Math.hypot(e.x - t.x, e.y - t.y);
1198
+ }
1199
+ var Q = {
1200
+ widthFill: 0,
1201
+ heightFill: 0,
1202
+ limitingFill: 0,
1203
+ areaFill: 0,
1204
+ aspectRatio: 1
1205
+ };
1206
+ function Xe(e, t, n) {
1207
+ let r = X(e), i = r.map(({ x: e }) => e), a = r.map(({ y: e }) => e), o = (Math.max(...i) - Math.min(...i)) / Math.max(1, t), s = (Math.max(...a) - Math.min(...a)) / Math.max(1, n), [c, l, u, d] = r, f = Math.max(Z(c, l), Z(d, u)), p = Math.max(Z(c, d), Z(l, u));
1208
+ return {
1209
+ widthFill: o,
1210
+ heightFill: s,
1211
+ limitingFill: Math.max(o, s),
1212
+ areaFill: Ye(r) / Math.max(1, t * n),
1213
+ aspectRatio: Math.max(f, p) / Math.max(1, Math.min(f, p))
1214
+ };
1215
+ }
1216
+ function Ze(e, t, n, r = {}) {
1217
+ let i = t ? r.exitFillRatio ?? .64 : r.minFillRatio ?? .72, a = r.highAspectRatio ?? 2.2;
1218
+ if (e.aspectRatio < a) return i;
1219
+ let o = t ? r.highAspectExitFillRatio : r.highAspectFillRatio;
1220
+ return Math.min(o ?? i + .08, 1 - n * 2);
1221
+ }
1222
+ function Qe(e, t, n = {}) {
1223
+ let r = n.confidenceThreshold ?? .72;
1224
+ if (e.status !== "success" || !e.quad || e.confidence < r || !e.sourceWidth || !e.sourceHeight) return {
1225
+ hint: "Place the document in the frame",
1226
+ reason: "place-document",
1227
+ fillRatio: 0,
1228
+ fill: Q,
1229
+ readyForAutoCapture: !1
1230
+ };
1231
+ let i = X(e.quad), a = Xe(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;
1232
+ if (i.some(({ x: t, y: n }) => t <= c || t >= e.sourceWidth - c || n <= l || n >= e.sourceHeight - l)) return {
1233
+ hint: "Move farther away",
1234
+ reason: "move-farther-away",
1235
+ fillRatio: o,
1236
+ fill: a,
1237
+ readyForAutoCapture: !1
1238
+ };
1239
+ let [u, d, f, p] = i, m = Z(u, d), h = Z(d, f), g = Z(f, p), _ = Z(p, u);
1240
+ 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) ? {
1241
+ hint: "Hold the camera straight",
1242
+ reason: "straighten-camera",
1243
+ fillRatio: o,
1244
+ fill: a,
1245
+ readyForAutoCapture: !1
1246
+ } : o < Ze(a, t.previouslyReady === !0, s, n) ? {
1247
+ hint: "Move closer",
1248
+ reason: "move-closer",
1249
+ fillRatio: o,
1250
+ fill: a,
1251
+ readyForAutoCapture: !1
1252
+ } : {
1253
+ hint: "Hold still",
1254
+ reason: t.ready ? "ready" : "hold-still",
1255
+ fillRatio: o,
1256
+ fill: a,
1257
+ readyForAutoCapture: t.ready
1258
+ };
1259
+ }
1260
+ var $ = class {
1261
+ previous;
1262
+ count = 0;
1263
+ ready = !1;
1264
+ options;
1265
+ constructor(e) {
1266
+ this.options = e;
1267
+ }
1268
+ reset() {
1269
+ this.previous = void 0, this.count = 0, this.ready = !1;
1270
+ }
1271
+ update(e) {
1272
+ if (e.status !== "success" || !e.quad || e.confidence < this.options.confidenceThreshold) return this.reset(), {
1273
+ stableFrames: 0,
1274
+ ready: !1,
1275
+ movement: Infinity
1276
+ };
1277
+ let t = Math.hypot(e.sourceWidth, e.sourceHeight), n = this.previous ? Math.max(...X(e.quad).map((e, n) => {
1278
+ let r = X(this.previous)[n];
1279
+ return Math.hypot(e.x - r.x, e.y - r.y) / Math.max(1, t);
1280
+ })) : Infinity, r = this.options.exitCornerTolerance ?? Math.max(this.options.cornerTolerance, .036);
1281
+ 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, {
1282
+ stableFrames: this.count,
1283
+ ready: this.ready,
1284
+ movement: n
1285
+ };
1286
+ }
1287
+ };
1288
+ function $e(e, t) {
1289
+ let n = Math.min(1, t / Math.max(e.width, e.height)), r = document.createElement("canvas");
1290
+ r.width = Math.max(1, Math.round(e.width * n)), r.height = Math.max(1, Math.round(e.height * n));
1291
+ let i = r.getContext("2d");
1292
+ if (!i) throw Error("Canvas 2D is unavailable in this browser.");
1293
+ return i.drawImage(e, 0, 0, r.width, r.height), r;
1294
+ }
1295
+ function et() {
1296
+ let e = window.AudioContext ?? window.webkitAudioContext;
1297
+ if (!e) return;
1298
+ let t = new e(), n = Math.round(t.sampleRate * .09), r = t.createBuffer(1, n, t.sampleRate), i = r.getChannelData(0);
1299
+ for (let e = 0; e < n; e += 1) {
1300
+ let n = Math.exp(-e / (t.sampleRate * .018));
1301
+ i[e] = (Math.random() * 2 - 1) * n;
1302
+ }
1303
+ let a = t.createBufferSource(), o = t.createBiquadFilter(), s = t.createGain();
1304
+ 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();
1305
+ }
1306
+ async function tt(e) {
1307
+ let t = document.createElement("video");
1308
+ return t.muted = !0, t.autoplay = !0, t.playsInline = !0, t.srcObject = e, await t.play(), t;
1309
+ }
1310
+ async function nt(e) {
1311
+ await v("scan");
1312
+ let t = Ie(e.autoCapture), n = new $({
1313
+ stableFrames: e.stableFrames ?? 4,
1314
+ confidenceThreshold: e.confidenceThreshold ?? .72,
1315
+ cornerTolerance: e.cornerTolerance ?? .024,
1316
+ exitCornerTolerance: e.exitCornerTolerance ?? .036
1317
+ }), r = e.maxFrameDimension ?? 1600, i = e.intervalMs ?? 140, a = {
1318
+ minDimension: 220,
1319
+ maxAnalysisDimension: 520,
1320
+ temporalEdgeWindow: 3,
1321
+ ...e.detection
1322
+ }, o = typeof MediaStream < "u" && e.source instanceof MediaStream ? await tt(e.source) : e.source, s = !0, c = !1, l = !1, u = 0, d, f = {
1323
+ state: "detecting",
1324
+ confidence: 0,
1325
+ guidance: {
1326
+ hint: "Place the document in the frame",
1327
+ reason: "place-document",
1328
+ fillRatio: 0,
1329
+ fill: Q,
1330
+ readyForAutoCapture: !1
1331
+ },
1332
+ lighting: {
1333
+ castShadow: !1,
1334
+ strength: 0
1335
+ },
1336
+ stableFrames: 0,
1337
+ requiredStableFrames: e.stableFrames ?? 4,
1338
+ autoCapture: { ...t }
1339
+ }, p = () => o instanceof HTMLCanvasElement ? $e(o, r) : Y(o, r), m = (t) => {
1340
+ f = t, e.onStatus?.(t);
1341
+ }, h = () => {
1342
+ s = !1, window.clearTimeout(u), o instanceof HTMLVideoElement && o !== e.source && (o.srcObject = null);
1343
+ }, g = async (t = "manual") => {
1344
+ if (c) throw Error("A finder capture is already in progress.");
1345
+ c = !0;
1346
+ let n;
1347
+ try {
1348
+ n = await Fe(e.captureFrame ?? p, () => {
1349
+ m({
1350
+ ...f,
1351
+ state: "captured"
1352
+ }), e.playShutterSound !== !1 && et(), h();
1353
+ });
1354
+ } catch (e) {
1355
+ throw c = !1, e instanceof Error ? e : /* @__PURE__ */ Error("The camera frame could not be captured.");
1356
+ }
1357
+ let r = {
1358
+ frame: n,
1359
+ detection: d,
1360
+ reason: t
1361
+ };
1362
+ return await e.onCapture?.(r), r;
1363
+ }, _ = async () => {
1364
+ if (s && !c) {
1365
+ try {
1366
+ let r = p(), i = await W(r, a);
1367
+ d = i;
1368
+ let o = i.quad ? Ne(r, i.quad) : {
1369
+ strong: !1,
1370
+ strength: 0
1371
+ }, s = o.strong ? {
1372
+ castShadow: !0,
1373
+ strength: o.strength,
1374
+ hint: "Tilt to move the shadow off the page"
1375
+ } : {
1376
+ castShadow: !1,
1377
+ strength: o.strength
1378
+ }, c = n.update(i), u = Qe(i, {
1379
+ ...c,
1380
+ previouslyReady: l
1381
+ }, {
1382
+ confidenceThreshold: e.confidenceThreshold ?? .72,
1383
+ ...e.guidance
1384
+ });
1385
+ l = u.readyForAutoCapture;
1386
+ let h = i.status !== "success" || u.reason === "place-document" ? "seeking" : u.readyForAutoCapture ? "ready" : "unstable";
1387
+ if (m({
1388
+ state: h,
1389
+ confidence: i.confidence,
1390
+ quad: i.quad,
1391
+ guidance: u,
1392
+ lighting: s,
1393
+ stableFrames: c.stableFrames,
1394
+ requiredStableFrames: f.requiredStableFrames,
1395
+ autoCapture: { ...t },
1396
+ sourceWidth: i.sourceWidth,
1397
+ sourceHeight: i.sourceHeight,
1398
+ detector: i.detector,
1399
+ modelStatus: i.modelStatus,
1400
+ modelProvider: i.modelProvider,
1401
+ modelError: i.modelError,
1402
+ inferenceMs: i.inferenceMs
1403
+ }), u.readyForAutoCapture && t.checked) try {
1404
+ await g("auto");
1405
+ return;
1406
+ } catch (t) {
1407
+ n.reset(), l = !1, e.onCaptureError?.(t instanceof Error ? t : /* @__PURE__ */ Error("Automatic capture failed."));
1408
+ }
1409
+ } catch {
1410
+ n.reset(), l = !1, m({
1411
+ state: "seeking",
1412
+ confidence: 0,
1413
+ guidance: {
1414
+ hint: "Place the document in the frame",
1415
+ reason: "place-document",
1416
+ fillRatio: 0,
1417
+ fill: Q,
1418
+ readyForAutoCapture: !1
1419
+ },
1420
+ lighting: {
1421
+ castShadow: !1,
1422
+ strength: 0
1423
+ },
1424
+ stableFrames: 0,
1425
+ requiredStableFrames: f.requiredStableFrames,
1426
+ autoCapture: { ...t }
1427
+ });
1428
+ }
1429
+ s && (u = window.setTimeout(() => void _(), i));
1430
+ }
1431
+ };
1432
+ return e.onStatus?.(f), _(), {
1433
+ stop: h,
1434
+ capture: () => g("manual"),
1435
+ setAutoCapture(e) {
1436
+ return !t.mutable || c ? !1 : (t.checked = e, m({
1437
+ ...f,
1438
+ autoCapture: { ...t }
1439
+ }), !0);
1440
+ },
1441
+ getStatus: () => f
1442
+ };
1443
+ }
1444
+ //#endregion
1445
+ export { Oe as A, n as B, ye as C, Se as D, ve as E, F, v as H, _e as I, le as L, de as M, ge as N, q as O, W as P, ue as R, be as S, K as T, _ as U, r as V, g as W, Qe as _, Ke as a, Ae as b, We as c, qe as d, Le as f, Xe as g, Ze as h, Be as i, xe as j, J as k, Ue as l, Ie as m, ze as n, He as o, $ as p, Ge as r, Je as s, Re as t, Ve as u, Pe as v, Y as w, je as x, nt as y, P as z };
1446
+
1447
+ //# sourceMappingURL=finder-Clo7f2gN.js.map