@sekyro/web 0.0.0-stage → 0.1.0-rc.2

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 (68) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +20 -0
  3. package/README.md +92 -2
  4. package/dist/capture-constraints-BujkZcfb.d.cts +21 -0
  5. package/dist/capture-constraints-BujkZcfb.d.ts +21 -0
  6. package/dist/capture-session-v3-BJ8ciaWl.d.ts +457 -0
  7. package/dist/capture-session-v3-CAoWM8iT.d.cts +457 -0
  8. package/dist/chunk-BPYVZUJA.js +852 -0
  9. package/dist/chunk-BPYVZUJA.js.map +1 -0
  10. package/dist/chunk-LOTAJDRE.js +1094 -0
  11. package/dist/chunk-LOTAJDRE.js.map +1 -0
  12. package/dist/chunk-MWNFSNMP.js +52 -0
  13. package/dist/chunk-MWNFSNMP.js.map +1 -0
  14. package/dist/chunk-NILNKLK6.js +50 -0
  15. package/dist/chunk-NILNKLK6.js.map +1 -0
  16. package/dist/chunk-NWF46H7K.js +359 -0
  17. package/dist/chunk-NWF46H7K.js.map +1 -0
  18. package/dist/chunk-WY6U7AIK.js +193 -0
  19. package/dist/chunk-WY6U7AIK.js.map +1 -0
  20. package/dist/chunk-YVFF4Q4G.js +327 -0
  21. package/dist/chunk-YVFF4Q4G.js.map +1 -0
  22. package/dist/client/index.cjs +357 -0
  23. package/dist/client/index.cjs.map +1 -0
  24. package/dist/client/index.d.cts +39 -0
  25. package/dist/client/index.d.ts +39 -0
  26. package/dist/client/index.js +15 -0
  27. package/dist/client/index.js.map +1 -0
  28. package/dist/core/index.cjs +1605 -0
  29. package/dist/core/index.cjs.map +1 -0
  30. package/dist/core/index.d.cts +87 -0
  31. package/dist/core/index.d.ts +87 -0
  32. package/dist/core/index.js +139 -0
  33. package/dist/core/index.js.map +1 -0
  34. package/dist/core/v3/detect-worker.cjs +392 -0
  35. package/dist/core/v3/detect-worker.cjs.map +1 -0
  36. package/dist/core/v3/detect-worker.d.cts +1 -0
  37. package/dist/core/v3/detect-worker.d.ts +1 -0
  38. package/dist/core/v3/detect-worker.js +13 -0
  39. package/dist/core/v3/detect-worker.js.map +1 -0
  40. package/dist/create-verification-CjLnJ0w6.d.ts +348 -0
  41. package/dist/create-verification-EnZ13uY4.d.cts +348 -0
  42. package/dist/detect-worker-CKXHlXx9.d.cts +105 -0
  43. package/dist/detect-worker-CKXHlXx9.d.ts +105 -0
  44. package/dist/detector-scanic-4C6IEW2K.js +787 -0
  45. package/dist/detector-scanic-4C6IEW2K.js.map +1 -0
  46. package/dist/hosted-client-BpvBqu9f.d.cts +408 -0
  47. package/dist/hosted-client-BpvBqu9f.d.ts +408 -0
  48. package/dist/index.cjs +2636 -0
  49. package/dist/index.cjs.map +1 -0
  50. package/dist/index.d.cts +6 -0
  51. package/dist/index.d.ts +6 -0
  52. package/dist/index.js +28 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/internal/index.cjs +4166 -0
  55. package/dist/internal/index.cjs.map +1 -0
  56. package/dist/internal/index.d.cts +431 -0
  57. package/dist/internal/index.d.ts +431 -0
  58. package/dist/internal/index.js +647 -0
  59. package/dist/internal/index.js.map +1 -0
  60. package/dist/popup/index.cjs +76 -0
  61. package/dist/popup/index.cjs.map +1 -0
  62. package/dist/popup/index.d.cts +66 -0
  63. package/dist/popup/index.d.ts +66 -0
  64. package/dist/popup/index.js +11 -0
  65. package/dist/popup/index.js.map +1 -0
  66. package/dist/scanic-ml-stub-S2OZ6HEF.js +10 -0
  67. package/dist/scanic-ml-stub-S2OZ6HEF.js.map +1 -0
  68. package/package.json +118 -4
@@ -0,0 +1,4166 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // src/core/doc/doc-catalog.ts
34
+ function aspectBand(format) {
35
+ return ASPECT_BANDS[format];
36
+ }
37
+ var ASPECT_BANDS, MR_DOC_CATALOG;
38
+ var init_doc_catalog = __esm({
39
+ "src/core/doc/doc-catalog.ts"() {
40
+ "use strict";
41
+ ASPECT_BANDS = {
42
+ "ID-1": { center: 1.586, tolerance: 0.15 },
43
+ "ID-3": { center: 1.42, tolerance: 0.2 }
44
+ };
45
+ MR_DOC_CATALOG = [
46
+ {
47
+ docType: "carte_identite",
48
+ format: "ID-1",
49
+ sides: ["recto", "verso"],
50
+ mrz: "td1",
51
+ // verso; carries the NNI with ICAO check digits (findings §6)
52
+ portraitSide: "recto",
53
+ aspectRatio: 1.586,
54
+ identifierSource: "mrz"
55
+ },
56
+ {
57
+ docType: "passport",
58
+ format: "ID-3",
59
+ sides: ["single"],
60
+ mrz: "td3",
61
+ portraitSide: "single",
62
+ // data page
63
+ aspectRatio: 1.42,
64
+ identifierSource: "mrz"
65
+ }
66
+ ];
67
+ }
68
+ });
69
+
70
+ // src/core/v3/frame-quality.ts
71
+ function lumaAt(data, index) {
72
+ return 0.299 * (data[index] ?? 0) + 0.587 * (data[index + 1] ?? 0) + 0.114 * (data[index + 2] ?? 0);
73
+ }
74
+ function meanLuma(image) {
75
+ const { data, width, height } = image;
76
+ const pixels = width * height;
77
+ if (pixels === 0) return 0;
78
+ let sum = 0;
79
+ for (let i2 = 0; i2 < pixels; i2 += 1) sum += lumaAt(data, i2 * 4);
80
+ return sum / pixels;
81
+ }
82
+ function sharpness(image) {
83
+ const { data, width, height } = image;
84
+ if (width < 3 || height < 3) return 0;
85
+ const gray = new Float32Array(width * height);
86
+ for (let i2 = 0; i2 < gray.length; i2 += 1) gray[i2] = lumaAt(data, i2 * 4);
87
+ let sum = 0;
88
+ let sumSquares = 0;
89
+ let count = 0;
90
+ for (let y2 = 1; y2 < height - 1; y2 += 1) {
91
+ for (let x = 1; x < width - 1; x += 1) {
92
+ const i2 = y2 * width + x;
93
+ const response = (gray[i2 - width] ?? 0) + (gray[i2 - 1] ?? 0) + (gray[i2 + 1] ?? 0) + (gray[i2 + width] ?? 0) - 4 * (gray[i2] ?? 0);
94
+ sum += response;
95
+ sumSquares += response * response;
96
+ count += 1;
97
+ }
98
+ }
99
+ if (count === 0) return 0;
100
+ const mean = sum / count;
101
+ const variance = sumSquares / count - mean * mean;
102
+ return Math.min(1, Math.max(0, variance) / SHARP_REF);
103
+ }
104
+ function exposure(image) {
105
+ const mean = meanLuma(image);
106
+ const [low, high] = EXPOSURE_BAND;
107
+ const distance = mean < low ? low - mean : mean > high ? mean - high : 0;
108
+ return Math.max(0, 1 - distance / EXPOSURE_FALLOFF);
109
+ }
110
+ var SHARP_REF, EXPOSURE_BAND, EXPOSURE_FALLOFF;
111
+ var init_frame_quality = __esm({
112
+ "src/core/v3/frame-quality.ts"() {
113
+ "use strict";
114
+ SHARP_REF = 180;
115
+ EXPOSURE_BAND = [100, 190];
116
+ EXPOSURE_FALLOFF = 64;
117
+ }
118
+ });
119
+
120
+ // src/core/doc/doc-gate-v1.ts
121
+ function quadAreaFrac(quad, frameWidth, frameHeight) {
122
+ const pts = [quad.topLeft, quad.topRight, quad.bottomRight, quad.bottomLeft];
123
+ let doubled = 0;
124
+ for (let i2 = 0; i2 < 4; i2++) {
125
+ const a2 = pts[i2];
126
+ const b = pts[(i2 + 1) % 4];
127
+ doubled += a2.x * b.y - b.x * a2.y;
128
+ }
129
+ const frameArea = frameWidth * frameHeight;
130
+ return frameArea > 0 ? Math.abs(doubled / 2) / frameArea : 0;
131
+ }
132
+ function quadIou(a2, b) {
133
+ const boxA = bbox(a2);
134
+ const boxB = bbox(b);
135
+ const x1 = Math.max(boxA.x1, boxB.x1);
136
+ const y1 = Math.max(boxA.y1, boxB.y1);
137
+ const x2 = Math.min(boxA.x2, boxB.x2);
138
+ const y2 = Math.min(boxA.y2, boxB.y2);
139
+ const inter = Math.max(0, x2 - x1) * Math.max(0, y2 - y1);
140
+ const areaA = (boxA.x2 - boxA.x1) * (boxA.y2 - boxA.y1);
141
+ const areaB = (boxB.x2 - boxB.x1) * (boxB.y2 - boxB.y1);
142
+ const union = areaA + areaB - inter;
143
+ return union > 0 ? inter / union : 0;
144
+ }
145
+ function quadBounds(quad) {
146
+ const box = bbox(quad);
147
+ return { width: box.x2 - box.x1, height: box.y2 - box.y1 };
148
+ }
149
+ function bbox(quad) {
150
+ const pts = [quad.topLeft, quad.topRight, quad.bottomRight, quad.bottomLeft];
151
+ return {
152
+ x1: Math.min(...pts.map((p2) => p2.x)),
153
+ y1: Math.min(...pts.map((p2) => p2.y)),
154
+ x2: Math.max(...pts.map((p2) => p2.x)),
155
+ y2: Math.max(...pts.map((p2) => p2.y))
156
+ };
157
+ }
158
+ function quadAspect(quad) {
159
+ const top = Math.hypot(quad.topRight.x - quad.topLeft.x, quad.topRight.y - quad.topLeft.y);
160
+ const bottom = Math.hypot(
161
+ quad.bottomRight.x - quad.bottomLeft.x,
162
+ quad.bottomRight.y - quad.bottomLeft.y
163
+ );
164
+ const left = Math.hypot(quad.bottomLeft.x - quad.topLeft.x, quad.bottomLeft.y - quad.topLeft.y);
165
+ const right = Math.hypot(
166
+ quad.bottomRight.x - quad.topRight.x,
167
+ quad.bottomRight.y - quad.topRight.y
168
+ );
169
+ const horizontal = (top + bottom) / 2;
170
+ const vertical = (left + right) / 2;
171
+ if (horizontal <= 0 || vertical <= 0) return 0;
172
+ return Math.max(horizontal, vertical) / Math.min(horizontal, vertical);
173
+ }
174
+ var DOC_DETECT_WIDTH, DOC_GATE_V1_DEFAULTS, clamp01, DocGateV1;
175
+ var init_doc_gate_v1 = __esm({
176
+ "src/core/doc/doc-gate-v1.ts"() {
177
+ "use strict";
178
+ init_frame_quality();
179
+ init_doc_catalog();
180
+ DOC_DETECT_WIDTH = 480;
181
+ DOC_GATE_V1_DEFAULTS = Object.freeze({
182
+ MIN_AREA_FRAC: 0.15,
183
+ EDGE_CLIP_MARGIN_PX: 4,
184
+ STABLE_TICKS: 3,
185
+ IOU_STABLE_MIN: 0.85,
186
+ RISE_PER_S: 0.9,
187
+ FALL_PER_S: 0.25,
188
+ GUIDE_EXPOSURE: 0.6,
189
+ GUIDE_SHARPNESS: 0.35,
190
+ ID3_BAND_MIN_WIDTH_FRAC: 0.55,
191
+ ID3_BAND_ASPECT_MIN: 4,
192
+ ID3_BAND_ASPECT_MAX: 40
193
+ });
194
+ clamp01 = (value) => Math.min(1, Math.max(0, value));
195
+ DocGateV1 = class {
196
+ constructor(format, overrides = {}) {
197
+ this.p = 0;
198
+ this.lastTickAt = null;
199
+ this.lastQuad = null;
200
+ this.streak = 0;
201
+ this.format = format;
202
+ this.t = { ...DOC_GATE_V1_DEFAULTS, ...overrides };
203
+ }
204
+ reset() {
205
+ this.p = 0;
206
+ this.lastTickAt = null;
207
+ this.lastQuad = null;
208
+ this.streak = 0;
209
+ }
210
+ tick(input) {
211
+ const { quad, quality, timestampMs } = input;
212
+ const dtSeconds = this.lastTickAt === null ? 0 : Math.max(0, (timestampMs - this.lastTickAt) / 1e3);
213
+ this.lastTickAt = timestampMs;
214
+ let geometryKey = null;
215
+ if (quad === null) {
216
+ geometryKey = "dcv1.no_doc";
217
+ } else if (this.format === "ID-3") {
218
+ const box = quadBounds(quad);
219
+ const aspect = box.height > 0 ? box.width / box.height : 0;
220
+ if (box.width < this.t.ID3_BAND_MIN_WIDTH_FRAC * input.frameWidth) {
221
+ geometryKey = "dcv1.come_closer";
222
+ } else if (this.edgeClipped(quad, input.frameWidth, input.frameHeight)) {
223
+ geometryKey = "dcv1.fit_document";
224
+ } else if (aspect < this.t.ID3_BAND_ASPECT_MIN || aspect > this.t.ID3_BAND_ASPECT_MAX) {
225
+ geometryKey = "dcv1.wrong_shape";
226
+ }
227
+ } else if (quadAreaFrac(quad, input.frameWidth, input.frameHeight) < this.t.MIN_AREA_FRAC) {
228
+ geometryKey = "dcv1.come_closer";
229
+ } else if (this.edgeClipped(quad, input.frameWidth, input.frameHeight)) {
230
+ geometryKey = "dcv1.fit_document";
231
+ } else {
232
+ const band = aspectBand(this.format);
233
+ const aspect = quadAspect(quad);
234
+ if (Math.abs(aspect - band.center) > band.tolerance) geometryKey = "dcv1.wrong_shape";
235
+ }
236
+ const plausible = geometryKey === null;
237
+ const exposureOk = clamp01(quality.exposure) >= this.t.GUIDE_EXPOSURE;
238
+ const sharpnessOk = clamp01(quality.sharpness) >= this.t.GUIDE_SHARPNESS;
239
+ const qualityOk = exposureOk && sharpnessOk;
240
+ if (plausible && qualityOk && quad !== null) {
241
+ const held = this.lastQuad === null || quadIou(quad, this.lastQuad) >= this.t.IOU_STABLE_MIN;
242
+ this.streak = held ? this.streak + 1 : 1;
243
+ } else {
244
+ this.streak = 0;
245
+ }
246
+ this.lastQuad = quad;
247
+ const good = plausible && qualityOk;
248
+ this.p = clamp01(this.p + (good ? this.t.RISE_PER_S : -this.t.FALL_PER_S) * dtSeconds);
249
+ const ready = good && this.streak >= this.t.STABLE_TICKS;
250
+ let guidanceKey;
251
+ if (geometryKey !== null) {
252
+ guidanceKey = geometryKey;
253
+ } else if (!exposureOk) {
254
+ const bandMid = (EXPOSURE_BAND[0] + EXPOSURE_BAND[1]) / 2;
255
+ guidanceKey = quality.meanLuma < bandMid ? "dcv1.more_light" : "dcv1.too_bright";
256
+ } else if (!sharpnessOk) {
257
+ guidanceKey = "dcv1.steady";
258
+ } else {
259
+ guidanceKey = "dcv1.hold_still";
260
+ }
261
+ return { at: timestampMs, quad, plausible, p: this.p, guidanceKey, ready, stableTicks: this.streak };
262
+ }
263
+ edgeClipped(quad, frameWidth, frameHeight) {
264
+ const margin = this.t.EDGE_CLIP_MARGIN_PX;
265
+ const pts = [quad.topLeft, quad.topRight, quad.bottomRight, quad.bottomLeft];
266
+ return pts.some(
267
+ (p2) => p2.x <= margin || p2.y <= margin || p2.x >= frameWidth - margin || p2.y >= frameHeight - margin
268
+ );
269
+ }
270
+ };
271
+ }
272
+ });
273
+
274
+ // scanic-ml-stub:scanic-ml-stub
275
+ var scanic_ml_stub_exports = {};
276
+ __export(scanic_ml_stub_exports, {
277
+ default: () => scanic_ml_stub_default,
278
+ initMlDetector: () => initMlDetector
279
+ });
280
+ function initMlDetector() {
281
+ throw new Error("scanic ML detector is not vendored (classical pipeline only)");
282
+ }
283
+ var scanic_ml_stub_default;
284
+ var init_scanic_ml_stub = __esm({
285
+ "scanic-ml-stub:scanic-ml-stub"() {
286
+ "use strict";
287
+ scanic_ml_stub_default = {};
288
+ }
289
+ });
290
+
291
+ // vendor/scanic/scanic.js
292
+ function B(A2, B2 = {}) {
293
+ const t2 = B2.width || Math.sqrt(A2.length), i2 = B2.height || A2.length / t2, E2 = void 0 !== B2.mode ? B2.mode : 1, e2 = void 0 !== B2.method ? B2.method : 2, o2 = B2.minArea || I, n2 = t2 + 2, a2 = i2 + 2, s2 = new Int32Array(n2 * a2);
294
+ for (let I2 = 0; I2 < i2; I2++) for (let g2 = 0; g2 < t2; g2++) A2[I2 * t2 + g2] > 0 && (s2[(I2 + 1) * n2 + (g2 + 1)] = 1);
295
+ const c2 = [];
296
+ let r2 = 2;
297
+ for (let I2 = 1; I2 <= i2; I2++) for (let A3 = 1; A3 <= t2; A3++) {
298
+ const B3 = s2[I2 * n2 + A3], t3 = s2[I2 * n2 + (A3 - 1)];
299
+ let i3 = null, o3 = false, h3 = -1;
300
+ if (1 === B3 && 0 === t3 ? (o3 = true, i3 = { x: A3, y: I2 }, h3 = 2) : 0 === B3 && t3 >= 1 && -1 !== t3 && 1 === t3 && (o3 = false, i3 = { x: A3 - 1, y: I2 }, h3 = 6), i3) {
301
+ if (0 === E2 && !o3) {
302
+ s2[i3.y * n2 + i3.x] = -1;
303
+ continue;
304
+ }
305
+ const A4 = r2++, I3 = C(s2, n2, a2, i3, h3, A4);
306
+ if (I3 && I3.length > 0) {
307
+ let B4 = I3;
308
+ 2 === e2 && (B4 = Q(I3));
309
+ const C2 = B4.map((A5) => ({ x: A5.x - 1, y: A5.y - 1 }));
310
+ if (C2.length >= (2 === e2 ? 4 : g)) {
311
+ const I4 = { id: A4, points: C2, isOuter: o3 };
312
+ c2.push(I4);
313
+ }
314
+ } else 1 === s2[i3.y * n2 + i3.x] && (s2[i3.y * n2 + i3.x] = A4);
315
+ }
316
+ }
317
+ c2.forEach((A3) => {
318
+ A3.area = (function(A4) {
319
+ let I2 = 0;
320
+ const g2 = A4.length;
321
+ if (g2 < 3) return 0;
322
+ for (let B3 = 0; B3 < g2; B3++) {
323
+ const C2 = (B3 + 1) % g2;
324
+ I2 += A4[B3].x * A4[C2].y, I2 -= A4[C2].x * A4[B3].y;
325
+ }
326
+ return Math.abs(I2) / 2;
327
+ })(A3.points), A3.boundingBox = (function(A4) {
328
+ if (0 === A4.length) return { minX: 0, minY: 0, maxX: 0, maxY: 0 };
329
+ let I2 = A4[0].x, g2 = A4[0].y, B3 = A4[0].x, C2 = A4[0].y;
330
+ for (let Q2 = 1; Q2 < A4.length; Q2++) {
331
+ const t3 = A4[Q2];
332
+ I2 = Math.min(I2, t3.x), g2 = Math.min(g2, t3.y), B3 = Math.max(B3, t3.x), C2 = Math.max(C2, t3.y);
333
+ }
334
+ return { minX: I2, minY: g2, maxX: B3, maxY: C2 };
335
+ })(A3.points);
336
+ });
337
+ const h2 = c2.filter((A3) => A3.area >= o2);
338
+ return h2.sort((A3, I2) => I2.area - A3.area), B2.debug && (B2.debug.labels = s2, B2.debug.rawContours = c2, B2.debug.finalContours = h2), h2;
339
+ }
340
+ function C(A2, I2, g2, B2, C2, Q2) {
341
+ const t2 = [], i2 = /* @__PURE__ */ new Set();
342
+ let E2 = B2.x, e2 = B2.y;
343
+ const o2 = E2, n2 = e2;
344
+ let a2 = -1;
345
+ A2[n2 * I2 + o2] = Q2;
346
+ let s2 = 0;
347
+ const c2 = I2 * g2, r2 = [0, 1, 1, 1, 0, -1, -1, -1], h2 = [-1, -1, 0, 1, 1, 1, 0, -1];
348
+ for (; s2++ < c2; ) {
349
+ let B3;
350
+ if (-1 === a2) {
351
+ let Q3 = false;
352
+ for (let t3 = 0; t3 < 8; t3++) {
353
+ B3 = C2 + t3 & 7;
354
+ const i3 = E2 + r2[B3], o3 = e2 + h2[B3];
355
+ if (i3 >= 0 && i3 < I2 && o3 >= 0 && o3 < g2 && A2[o3 * I2 + i3] > 0) {
356
+ Q3 = true;
357
+ break;
358
+ }
359
+ }
360
+ if (!Q3) return null;
361
+ } else B3 = a2 + 2 & 7;
362
+ let s3 = -1, c3 = -1;
363
+ for (let C3 = 0; C3 < 8; C3++) {
364
+ const Q3 = B3 + C3 & 7, t3 = E2 + r2[Q3], i3 = e2 + h2[Q3];
365
+ if (t3 >= 0 && t3 < I2 && i3 >= 0 && i3 < g2 && A2[i3 * I2 + t3] > 0) {
366
+ s3 = t3, c3 = i3, a2 = Q3 + 4 & 7;
367
+ break;
368
+ }
369
+ }
370
+ if (-1 === s3) {
371
+ 0 === t2.length && t2.push({ x: E2, y: e2 });
372
+ break;
373
+ }
374
+ const l2 = e2 * I2 + E2;
375
+ if (i2.has(l2)) return t2;
376
+ t2.push({ x: E2, y: e2 }), i2.add(l2);
377
+ const y2 = c3 * I2 + s3;
378
+ if (1 === A2[y2] && (A2[y2] = Q2), E2 = s3, e2 = c3, E2 === o2 && e2 === n2) break;
379
+ }
380
+ return s2 >= c2 ? null : t2;
381
+ }
382
+ function Q(A2) {
383
+ const I2 = A2.length;
384
+ if (I2 <= 2) return A2;
385
+ const g2 = [], B2 = A2[I2 - 1], C2 = A2[0];
386
+ let Q2 = B2, t2 = C2, i2 = A2[1], E2 = t2.x - Q2.x, e2 = t2.y - Q2.y, o2 = i2.x - t2.x, n2 = i2.y - t2.y;
387
+ E2 * n2 !== e2 * o2 && g2.push(t2);
388
+ for (let a2 = 1; a2 < I2 - 1; a2++) Q2 = A2[a2 - 1], t2 = A2[a2], i2 = A2[a2 + 1], E2 = t2.x - Q2.x, e2 = t2.y - Q2.y, o2 = i2.x - t2.x, n2 = i2.y - t2.y, E2 * n2 !== e2 * o2 && g2.push(t2);
389
+ if (Q2 = A2[I2 - 2], t2 = B2, i2 = C2, E2 = t2.x - Q2.x, e2 = t2.y - Q2.y, o2 = i2.x - t2.x, n2 = i2.y - t2.y, E2 * n2 !== e2 * o2 && g2.push(t2), 0 === g2.length) {
390
+ if (1 === I2) return [A2[0]];
391
+ if (2 === I2) return A2;
392
+ let g3 = 0, B3 = 1;
393
+ const Q3 = C2.x, t3 = C2.y;
394
+ for (let C3 = 1; C3 < I2; C3++) {
395
+ const I3 = A2[C3], i3 = I3.x - Q3, E3 = I3.y - t3, e3 = i3 * i3 + E3 * E3;
396
+ e3 > g3 && (g3 = e3, B3 = C3);
397
+ }
398
+ return [C2, A2[B3]];
399
+ }
400
+ return g2;
401
+ }
402
+ function t(A2, I2 = 1) {
403
+ if (A2.length <= 2) return A2;
404
+ let g2 = 0, B2 = 0;
405
+ const C2 = A2[0], Q2 = A2[A2.length - 1];
406
+ for (let t2 = 1; t2 < A2.length - 1; t2++) {
407
+ const I3 = i(A2[t2], C2, Q2);
408
+ I3 > g2 && (g2 = I3, B2 = t2);
409
+ }
410
+ if (g2 > I2) {
411
+ const g3 = t(A2.slice(0, B2 + 1), I2), C3 = t(A2.slice(B2), I2);
412
+ return g3.slice(0, -1).concat(C3);
413
+ }
414
+ return [C2, Q2];
415
+ }
416
+ function i(A2, I2, g2) {
417
+ const B2 = g2.x - I2.x, C2 = g2.y - I2.y, Q2 = B2 * B2 + C2 * C2;
418
+ if (0 === Q2) return Math.sqrt(Math.pow(A2.x - I2.x, 2) + Math.pow(A2.y - I2.y, 2));
419
+ const t2 = ((A2.x - I2.x) * B2 + (A2.y - I2.y) * C2) / Q2;
420
+ let i2, E2;
421
+ t2 < 0 ? (i2 = I2.x, E2 = I2.y) : t2 > 1 ? (i2 = g2.x, E2 = g2.y) : (i2 = I2.x + t2 * B2, E2 = I2.y + t2 * C2);
422
+ const e2 = A2.x - i2, o2 = A2.y - E2;
423
+ return Math.sqrt(e2 * e2 + o2 * o2);
424
+ }
425
+ function E(A2, I2 = 0.02) {
426
+ return t(A2, I2 * (function(A3) {
427
+ let I3 = 0;
428
+ const g2 = A3.length;
429
+ if (g2 < 2) return 0;
430
+ for (let B2 = 0; B2 < g2; B2++) {
431
+ const C2 = (B2 + 1) % g2, Q2 = A3[B2].x - A3[C2].x, t2 = A3[B2].y - A3[C2].y;
432
+ I3 += Math.sqrt(Q2 * Q2 + t2 * t2);
433
+ }
434
+ return I3;
435
+ })(A2));
436
+ }
437
+ function e(A2, I2) {
438
+ return Math.hypot(I2.x - A2.x, I2.y - A2.y);
439
+ }
440
+ function o(A2) {
441
+ let I2 = 0, g2 = 0;
442
+ for (const B2 of A2) I2 += B2.x, g2 += B2.y;
443
+ return { x: I2 / A2.length, y: g2 / A2.length };
444
+ }
445
+ function n(A2, I2 = {}) {
446
+ if (!A2 || !A2.points || A2.points.length < 4) return null;
447
+ const g2 = I2.epsilon || 0.02, B2 = (function(A3, I3) {
448
+ if (!A3 || A3.length < 4) return null;
449
+ const g3 = [I3, 1.3 * I3, 1.6 * I3, 2 * I3], B3 = /* @__PURE__ */ new Set();
450
+ for (const C3 of g3) {
451
+ const I4 = Math.min(0.12, C3), g4 = I4.toFixed(4);
452
+ if (B3.has(g4)) continue;
453
+ B3.add(g4);
454
+ const Q2 = a(E(A3, I4));
455
+ if (Q2 && 4 === Q2.length) return Q2;
456
+ }
457
+ return null;
458
+ })(A2.points, g2);
459
+ let C2;
460
+ return B2 && 4 === B2.length ? C2 = (function(A3) {
461
+ if (4 !== A3.length) return null;
462
+ const I3 = o(A3), g3 = [...A3].sort((A4, g4) => Math.atan2(A4.y - I3.y, A4.x - I3.x) - Math.atan2(g4.y - I3.y, g4.x - I3.x));
463
+ let B3 = 1 / 0, C3 = 0;
464
+ for (let t2 = 0; t2 < 4; t2++) {
465
+ const A4 = g3[t2].x + g3[t2].y;
466
+ A4 < B3 && (B3 = A4, C3 = t2);
467
+ }
468
+ const Q2 = [g3[C3], g3[(C3 + 1) % 4], g3[(C3 + 2) % 4], g3[(C3 + 3) % 4]];
469
+ return { topLeft: Q2[0], topRight: Q2[1], bottomRight: Q2[2], bottomLeft: Q2[3] };
470
+ })(B2) : (C2 = (function(A3) {
471
+ if (!A3 || A3.length < 4) return null;
472
+ const I3 = o(A3);
473
+ let g3 = null, B3 = null, C3 = null, Q2 = null, t2 = 0, i2 = 0, E2 = 0, n2 = 0;
474
+ for (const o2 of A3) {
475
+ const A4 = e(o2, I3);
476
+ o2.x < I3.x && o2.y < I3.y ? A4 > t2 && (g3 = o2, t2 = A4) : o2.x > I3.x && o2.y < I3.y ? A4 > i2 && (B3 = o2, i2 = A4) : o2.x > I3.x && o2.y > I3.y ? A4 > E2 && (C3 = o2, E2 = A4) : o2.x < I3.x && o2.y > I3.y && A4 > n2 && (Q2 = o2, n2 = A4);
477
+ }
478
+ return g3 && B3 && C3 && Q2 ? { topLeft: g3, topRight: B3, bottomRight: C3, bottomLeft: Q2 } : null;
479
+ })(A2.points), C2 && C2.topLeft && C2.topRight && C2.bottomRight && C2.bottomLeft || (C2 = (function(A3) {
480
+ if (!A3 || 0 === A3.length) return null;
481
+ let I3 = A3[0], g3 = A3[0], B3 = A3[0], C3 = A3[0], Q2 = I3.x + I3.y, t2 = g3.x - g3.y, i2 = B3.x + B3.y, E2 = C3.x - C3.y;
482
+ for (let e2 = 1; e2 < A3.length; e2++) {
483
+ const o2 = A3[e2], n2 = o2.x + o2.y, a2 = o2.x - o2.y;
484
+ n2 < Q2 && (Q2 = n2, I3 = o2), n2 > i2 && (i2 = n2, B3 = o2), a2 > t2 && (t2 = a2, g3 = o2), a2 < E2 && (E2 = a2, C3 = o2);
485
+ }
486
+ return { topLeft: I3, topRight: g3, bottomRight: B3, bottomLeft: C3 };
487
+ })(A2.points))), C2 && C2.topLeft && C2.topRight && C2.bottomRight && C2.bottomLeft ? C2 : null;
488
+ }
489
+ function a(A2) {
490
+ if (!A2 || A2.length < 4) return null;
491
+ if (4 === A2.length) return A2;
492
+ if (A2.length > 8) return null;
493
+ let I2 = (function(A3, I3) {
494
+ if (!A3 || 0 === A3.length) return [];
495
+ const g2 = [];
496
+ for (const B2 of A3) (0 === g2.length || e(B2, g2[g2.length - 1]) > I3) && g2.push(B2);
497
+ g2.length > 2 && e(g2[0], g2[g2.length - 1]) <= I3 && g2.pop();
498
+ return g2;
499
+ })(A2, 6);
500
+ return 4 === I2.length ? I2 : (I2.length, null);
501
+ }
502
+ function c() {
503
+ return null !== s && 0 !== s.byteLength || (s = new Uint8Array(A.memory.buffer)), s;
504
+ }
505
+ function h(A2, I2) {
506
+ const g2 = I2(1 * A2.length, 1) >>> 0;
507
+ return c().set(A2, g2 / 1), r = A2.length, g2;
508
+ }
509
+ function l(A2, I2) {
510
+ return A2 >>>= 0, c().subarray(A2 / 1, A2 / 1 + I2);
511
+ }
512
+ function D() {
513
+ return null !== y && 0 !== y.byteLength || (y = new Float32Array(A.memory.buffer)), y;
514
+ }
515
+ function w(I2, g2, B2, C2, Q2) {
516
+ const t2 = (function(A2, I3) {
517
+ const g3 = I3(4 * A2.length, 4) >>> 0;
518
+ return D().set(A2, g3 / 4), r = A2.length, g3;
519
+ })(I2, A.__wbindgen_malloc), i2 = r, E2 = A.hysteresis_thresholding(t2, i2, g2, B2, C2, Q2);
520
+ var e2 = l(E2[0], E2[1]).slice();
521
+ return A.__wbindgen_free(E2[0], 1 * E2[1], 1), e2;
522
+ }
523
+ function f(I2, g2) {
524
+ const B2 = g2(2 * I2.length, 2) >>> 0;
525
+ return (null !== d && 0 !== d.byteLength || (d = new Uint16Array(A.memory.buffer)), d).set(I2, B2 / 2), r = I2.length, B2;
526
+ }
527
+ function u(I2, g2, B2, C2, Q2) {
528
+ const t2 = f(I2, A.__wbindgen_malloc), i2 = r, E2 = f(g2, A.__wbindgen_malloc), e2 = r, o2 = A.non_maximum_suppression(t2, i2, E2, e2, B2, C2, Q2);
529
+ var n2, a2, s2 = (n2 = o2[0], a2 = o2[1], n2 >>>= 0, D().subarray(n2 / 4, n2 / 4 + a2)).slice();
530
+ return A.__wbindgen_free(o2[0], 4 * o2[1], 4), s2;
531
+ }
532
+ async function m(I2) {
533
+ if (void 0 !== A) return A;
534
+ if (void 0 !== I2 && Object.getPrototypeOf(I2) === Object.prototype && ({ module_or_path: I2 } = I2), void 0 === I2) throw new Error("scanic: WASM module bytes must be passed to init().");
535
+ const g2 = (function() {
536
+ const I3 = { wbg: {} };
537
+ return I3.wbg.__wbindgen_init_externref_table = function() {
538
+ const I4 = A.__wbindgen_export_0, g3 = I4.grow(4);
539
+ I4.set(0, void 0), I4.set(g3 + 0, void 0), I4.set(g3 + 1, null), I4.set(g3 + 2, true), I4.set(g3 + 3, false);
540
+ }, I3;
541
+ })();
542
+ ("string" == typeof I2 || "function" == typeof Request && I2 instanceof Request || "function" == typeof URL && I2 instanceof URL) && (I2 = fetch(I2));
543
+ const { instance: B2, module: C2 } = await (async function(A2, I3) {
544
+ if ("function" == typeof Response && A2 instanceof Response) {
545
+ if ("function" == typeof WebAssembly.instantiateStreaming) try {
546
+ return await WebAssembly.instantiateStreaming(A2, I3);
547
+ } catch (g3) {
548
+ if ("application/wasm" == A2.headers.get("Content-Type")) throw g3;
549
+ }
550
+ const B3 = await A2.arrayBuffer();
551
+ return await WebAssembly.instantiate(B3, I3);
552
+ }
553
+ {
554
+ const g3 = await WebAssembly.instantiate(A2, I3);
555
+ return g3 instanceof WebAssembly.Instance ? { instance: g3, module: A2 } : g3;
556
+ }
557
+ })(await I2, g2);
558
+ return (function(I3, g3) {
559
+ return A = I3.exports, m.__wbindgen_wasm_module = g3, y = null, d = null, s = null, A.__wbindgen_start(), A;
560
+ })(B2, C2);
561
+ }
562
+ function F(A2) {
563
+ if ("function" == typeof atob) {
564
+ const I2 = atob(A2), g2 = new Uint8Array(I2.length);
565
+ for (let A3 = 0; A3 < I2.length; A3++) g2[A3] = I2.charCodeAt(A3);
566
+ return g2;
567
+ }
568
+ return Uint8Array.from(Buffer.from(A2, "base64"));
569
+ }
570
+ async function J() {
571
+ if (!(function() {
572
+ if (null !== p) return p;
573
+ let A2 = false;
574
+ if ("object" == typeof WebAssembly && "function" == typeof WebAssembly.validate) {
575
+ const I2 = new Uint8Array([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]), g2 = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 111, 3, 2, 1, 0, 10, 6, 1, 4, 0, 208, 111, 11]);
576
+ try {
577
+ A2 = WebAssembly.validate(I2) && WebAssembly.validate(g2);
578
+ } catch {
579
+ A2 = false;
580
+ }
581
+ }
582
+ return p = A2, A2;
583
+ })()) throw new Error("scanic: WebAssembly features required by the WASM module (reference-types, SIMD) are unavailable in this engine; using the JavaScript fallback.");
584
+ return await m({ module_or_path: F("AGFzbQEAAAABtQEWYAJ/fwBgAAJ/f2ACf38Bf2ADf39/AX9gAX8AYAN/f38AYAV/f39/fwBgBH9/f38Bf2AGf39/f319An9/YAAAYAF/AX9gB39/f39/f38AYAh/f39/f39/fwBgB39/f39/f30AYAZ/f39/f38AYAR/f39/AGALf39/f319f31/f38Cf39gB39/f39/f38Cf39gBn9/f39/fQJ/f2AFf39/f38Cf39gBH9/f38Cf39gAn9/An9/AicBA3diZx9fX3diaW5kZ2VuX2luaXRfZXh0ZXJucmVmX3RhYmxlAAkDOzoKCwwNBgQDAAIAAAICAAYADgUCBAQEAAUDAA8FEAcEERIICAITABQVBAQAAAAEBQMHAgAAAgICAAAABAkCcAETE28AgAEFAwEAEQYJAX8BQYCAwAALB4QCDQZtZW1vcnkCAARibHVyACESZWRnZV9tYXBfdG9fYmluYXJ5ACgXaHlzdGVyZXNpc190aHJlc2hvbGRpbmcAIh5oeXN0ZXJlc2lzX3RocmVzaG9sZGluZ19iaW5hcnkAIxNjYWxjdWxhdGVfZ3JhZGllbnRzACcGZGlsYXRlACUYY2FubnlfZWRnZV9kZXRlY3Rvcl9mdWxsAB0Xbm9uX21heGltdW1fc3VwcHJlc3Npb24AIBNfX3diaW5kZ2VuX2V4cG9ydF8wAQERX193YmluZGdlbl9tYWxsb2MAJA9fX3diaW5kZ2VuX2ZyZWUALxBfX3diaW5kZ2VuX3N0YXJ0AAAJGAEAQQELEi4XDCoZDTcyGjM4KRMOEDosKwwBAgrGiwI6ySUCCX8BfiMAQRBrIggkAAJAAkACQAJAAkAgAEH1AU8EQCAAQcz/e0sEQEEAIQAMBgsgAEELaiICQXhxIQVBvJvAACgCACIJRQ0EQR8hBkEAIAVrIQMgAEH0//8HTQRAIAVBJiACQQh2ZyIAa3ZBAXEgAEEBdGtBPmohBgsgBkECdEGgmMAAaigCACICRQRAQQAhAAwCCyAFQRkgBkEBdmtBACAGQR9HG3QhBEEAIQADQAJAIAIoAgRBeHEiByAFSQ0AIAcgBWsiByADTw0AIAIhASAHIgMNAEEAIQMgASEADAQLIAIoAhQiByAAIAcgAiAEQR12QQRxaigCECICRxsgACAHGyEAIARBAXQhBCACDQALDAELAkACQAJAAkACQEG4m8AAKAIAIgRBECAAQQtqQfgDcSAAQQtJGyIFQQN2IgB2IgFBA3EEQCABQX9zQQFxIABqIgdBA3QiAUGwmcAAaiIAIAFBuJnAAGooAgAiAigCCCIDRg0BIAMgADYCDCAAIAM2AggMAgsgBUHAm8AAKAIATQ0IIAENAkG8m8AAKAIAIgBFDQggAGhBAnRBoJjAAGooAgAiAigCBEF4cSAFayEDIAIhAQNAAkAgASgCECIADQAgASgCFCIADQAgAigCGCEGAkACQCACIAIoAgwiAEYEQCACQRRBECACKAIUIgAbaigCACIBDQFBACEADAILIAIoAggiASAANgIMIAAgATYCCAwBCyACQRRqIAJBEGogABshBANAIAQhByABIgBBFGogAEEQaiAAKAIUIgEbIQQgAEEUQRAgARtqKAIAIgENAAsgB0EANgIACyAGRQ0GAkAgAigCHEECdEGgmMAAaiIBKAIAIAJHBEAgAiAGKAIQRwRAIAYgADYCFCAADQIMCQsgBiAANgIQIAANAQwICyABIAA2AgAgAEUNBgsgACAGNgIYIAIoAhAiAQRAIAAgATYCECABIAA2AhgLIAIoAhQiAUUNBiAAIAE2AhQgASAANgIYDAYLIAAoAgRBeHEgBWsiASADIAEgA0kiARshAyAAIAIgARshAiAAIQEMAAsAC0G4m8AAIARBfiAHd3E2AgALIAJBCGohACACIAFBA3I2AgQgASACaiIBIAEoAgRBAXI2AgQMBwsCQEECIAB0IgJBACACa3IgASAAdHFoIgdBA3QiAUGwmcAAaiICIAFBuJnAAGooAgAiACgCCCIDRwRAIAMgAjYCDCACIAM2AggMAQtBuJvAACAEQX4gB3dxNgIACyAAIAVBA3I2AgQgACAFaiIGIAEgBWsiB0EBcjYCBCAAIAFqIAc2AgBBwJvAACgCACICBEBByJvAACgCACEBAkBBuJvAACgCACIEQQEgAkEDd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EHwmcAANgIAQfCZwABB6JnAADYCAEH4mcAAQfCZwAA2AgBBhJrAAEH4mcAANgIAQYCawABB+JnAADYCAEGMmsAAQYCawAA2AgBBiJrAAEGAmsAANgIAQZSawABBiJrAADYCAEGQmsAAQYiawAA2AgBBnJrAAEGQmsAANgIAQZiawABBkJrAADYCAEGkmsAAQZiawAA2AgBBoJrAAEGYmsAANgIAQayawABBoJrAADYCAEGomsAAQaCawAA2AgBBtJrAAEGomsAANgIAQbCawABBqJrAADYCAEG8msAAQbCawAA2AgBBxJrAAEG4msAANgIAQbiawABBsJrAADYCAEHMmsAAQcCawAA2AgBBwJrAAEG4msAANgIAQdSawABByJrAADYCAEHImsAAQcCawAA2AgBB3JrAAEHQmsAANgIAQdCawABByJrAADYCAEHkmsAAQdiawAA2AgBB2JrAAEHQmsAANgIAQeyawABB4JrAADYCAEHgmsAAQdiawAA2AgBB9JrAAEHomsAANgIAQeiawABB4JrAADYCAEH8msAAQfCawAA2AgBB8JrAAEHomsAANgIAQYSbwABB+JrAADYCAEH4msAAQfCawAA2AgBBjJvAAEGAm8AANgIAQYCbwABB+JrAADYCAEGUm8AAQYibwAA2AgBBiJvAAEGAm8AANgIAQZybwABBkJvAADYCAEGQm8AAQYibwAA2AgBBpJvAAEGYm8AANgIAQZibwABBkJvAADYCAEGsm8AAQaCbwAA2AgBBoJvAAEGYm8AANgIAQbSbwABBqJvAADYCAEGom8AAQaCbwAA2AgBBzJvAACABQQ9qQXhxIgBBCGsiAjYCAEGwm8AAQaibwAA2AgBBxJvAACAEQShrIgQgASAAa2pBCGoiADYCACACIABBAXI2AgQgASAEakEoNgIEQdibwABBgICAATYCAAwICyACIANJIAEgAk1yDQAgACgCDCIDQQFxDQAgA0EBdiAHRg0DC0Hcm8AAQdybwAAoAgAiACABIAAgAUkbNgIAIAEgBGohA0GgmcAAIQACQAJAA0AgAyAAKAIAIgZHBEAgACgCCCIADQEMAgsLIAAoAgwiA0EBcQ0AIANBAXYgB0YNAQtBoJnAAC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DH58IEUgCzUCCH58IAs1AhAgACAWajEAAH58QgiIPgIAIAciCSAERw0ACwwGCyAAIAJLBEAgACEHDAMLIAAgAksEQCAAIQcMAgsMDAsgByAAQYSIwAAQGAALIAkgByACQfSHwAAQGwALIAkgByACQeSHwAAQGwALIAggCSACQcSGwAAQGwALIAggCSACQbSGwAAQGwALIBAhCSACIQcgBCEYIB4hAUEAIQJBACEVAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAIBFBA0cEQCAERQ0SIANBBGsiEEEAIAMgEE8bIRRBACARQQF2ayEIIARBAWshDAwBCyADIAdNBEAgATUCCCFFIAE1AgQhRyABNQIAIUggA0UNAyBHIEh8IUYgByADayIAQQAgACAHTRsiACADQQFrIgEgACABSRtBAWoiAEEETQ0CIANBAnQhBCBF/RIhTSBG/RIhTyAJIQEgACAAQQNxIgBBBCAAG2siAiELIAUhAANAIAEgTSAAIARq/QACACJQ/ckB/dUBIE8gAP0AAgAiUf3JAf3VAf3OAUEY/c0BIk79DP8AAAAAAAAA/wAAAAAAAAD9DP/////////////////////9DAAAAAAAAAAAAAAAAAAAAAAgTv0dAEL/AVQbQn9CACBO/R0BQv8BVBv9HgH9UiBNIFD9ygH91QEgTyBR/coB/dUB/c4BQRj9zQEiTv0M/wAAAAAAAAD/AAAAAAAAAP0M//////////////////////0MAAAAAAAAAAAAAAAAAAAAACBO/R0AQv8BVBtCf0IAIE79HQFC/wFUG/0eAf1S/Q0ACBAYAAAAAAAAAAAAAAAA/VoAAAAgAUEEaiEBIABBEGohACALQQRrIgsNAAsMAgtBACADIAdB1ITAABAbAAsDQAJAAkACQAJAIAMgFWwiDiAVQQFqIhUgA2wiAEsgACAHS3JFBEAgCSAOaiENQQAhAEEAIQQCQANAAkAgACEKAkAgEUUEQP0MAAAAAAAAAAAAAAAAAAAAACJNIU8MAQsgDEEASA0BIAUgBEECdGohFiAIIQAgESELIAEhAv0MAAAAAAAAAAAAAAAAAAAAACJPIU0DQCACNQIA/RI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IgG2pBAnRqIQEgBSACIBxqQQJ0aiELA0AgAiAsaiIKIAdPDQ0gAiAbaiISIAdPDQogAiAcaiIKIAdPDQcgAiAlakL/ASABNQIAIEd+IAA1AgAgSH58IAs1AgAgRX58QhiIIkYgRkL/AVobPAAAIABBBGohACABQQRqIQEgC0EEaiELIAJBAWoiAiADRw0ACwsgAyAsaiEsIAMgG2ohGyADIBxqIRwgAyAlaiElIAMgIWohISAZICRqIRkgHyAkaiEfICAgJGohICAnIANrIScgAyAoaiEoICYgA2shJiADIClqISkgHSADayEdIAMgEWohESAzQQFqITMgKiAvSQ0ACwwNCyAHIAdBlIbAABAYAAsgA0EBdCAKaiEKDAILIANBAXQgCmpBAmohCgwBCyADQQF0IApqQQFqIQoLIAogB0HEhcAAEBgACyAEQQJqIRIMAQsgBEEBaiESCyASIAdBtIXAABAYAAsgCkECaiEKDAELIApBAWohCgsgCiAHQaSFwAAQGAALIAMgCmohAiADQQF0IApqIQALIAIgACAHQZSFwAAQGwALIBhBAkkNACAHIAMgGGwiAE8gACAYQQFrIANsIghPcUUEQCAIIAAgB0HkhMAAEBsACyADRQ0AQQAhBCBFIEd8IUUgByAIayIAQQAgACAHTRsiACAHIBhBAmsgA2wiDGsiAUEAIAEgB00bIgEgACABSRsiACADQQFrIgEgACABSRsiAUEBaiIKQQVPBEAgCCAJaiEAIApBA3EiAkEEIAIbIgQgAUF/c2ohCyAFIAhBAnRqIQIgBSAMQQJ0aiEBIAogBGshBCBI/RIhTSBF/RIhTwNAIAAgTyAC/QACACJQ/ckB/dUBIE0gAf0AAgAiUf3JAf3VAf3OAUEY/c0BIk79DP8AAAAAAAAA/wAAAAAAAAD9DP/////////////////////9DAAAAAAAAAAAAAAAAAAAAAAgTv0dAEL/AVQbQn9CACBO/R0BQv8BVBv9HgH9UiBPIFD9ygH91QEgTSBR/coB/dUB/c4BQRj9zQEiTv0M/wAAAAAAAAD/AAAAAAAAAP0M//////////////////////0MAAAAAAAAAAAAAAAAAAAAACBO/R0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hkl8AANgIIIANCAjcCFCADQoCAgIAwIgQgA62ENwMoIAMgBCADQQRqrYQ3AyAgAyADQSBqNgIQIANBCGogAhAmAAtHAQF/IAAoAgAgACgCCCIDayACSQRAIAAgAyACEBIgACgCCCEDCyACBEAgACgCBCADaiABIAL8CgAACyAAIAIgA2o2AghBAAtEAQJ/IAEoAgQhAiABKAIAIQNBCEEEEDUiAUUEQEEEQQgQOQALIAEgAjYCBCABIAM2AgAgAEHcksAANgIEIAAgATYCAAvGAgACQCAAIAJNBEAgACABTSABIAJLcg0BIwBBMGsiAiQAIAIgATYCBCACIAA2AgAgAkECNgIMIAJB2JbAADYCCCACQgI3AhQgAiACQQRqrUKAgICAMIQ3AyggAiACrUKAgICAMIQ3AyAgAiACQSBqNgIQIAJBCGogAxAmAAsjAEEwayIBJAAgASACNgIEIAEgADYCACABQQI2AgwgAUH8lsAANgIIIAFCAjcCFCABIAFBBGqtQoCAgIAwhDcDKCABIAGtQoCAgIAwhDcDICABIAFBIGo2AhAgAUEIaiADECYACyMAQTBrIgAkACAAIAI2AgQgACABNgIAIABBAjYCDCAAQaSWwAA2AgggAEICNwIUIAAgAEEEaq1CgICAgDCENwMoIAAgAK1CgICAgDCENwMgIAAgAEEgajYCECAAQQhqIAMQJgALQQEBfyMAQSBrIgMkACADQQA2AhAgA0EBNgIEIANCBDcCCCADIAE2AhwgAyAANgIYIAMgA0EYajYCACADIAIQJgALywwBD38jAEEQayIOJAAgCCEMIAkhFiAKIRdBACEIQQAhCSMAQdAAayILJAAgC0EIaiAAIhggASITIAIiCiADIAYgBxAEIAtBFGogCygCDCIZIAsoAhAgAiADEAUgAiADbCIBQQF0IQACfwJAAkAgAUEASCAAQf7///8HS3JFBEAgAEUNAUECIQggAEECEDUiAg0CCyAIIAAQLQALIAtBADYCKCALQoCAgIAgNwIgIAtBADYCNCALQoCAgIAgNwIsQQIhCEEBDAELIAtBADYCKCALIAI2AiQgCyABNgIgAkACQCAAQQIQNSIIBEAgC0EANgI0IAs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kMTI4KwtidWxrLW1lbW9yeSsIc2lnbi1leHQrD3JlZmVyZW5jZS10eXBlcysKbXVsdGl2YWx1ZQ==") });
585
+ }
586
+ function G() {
587
+ return N || (N = J().catch((A2) => {
588
+ throw N = null, A2;
589
+ })), N;
590
+ }
591
+ function k(A2, I2, g2, B2 = 5, C2 = 0) {
592
+ 0 === C2 && (C2 = 0.3 * (0.5 * (B2 - 1) - 1) + 0.8);
593
+ const Q2 = Math.floor(B2 / 2), t2 = (function(A3, I3) {
594
+ const g3 = new Float32Array(A3), B3 = Math.floor(A3 / 2);
595
+ let C3 = 0;
596
+ for (let Q3 = 0; Q3 < A3; Q3++) {
597
+ const A4 = Q3 - B3;
598
+ g3[Q3] = Math.exp(-A4 * A4 / (2 * I3 * I3)), C3 += g3[Q3];
599
+ }
600
+ for (let Q3 = 0; Q3 < A3; Q3++) g3[Q3] /= C3;
601
+ return g3;
602
+ })(B2, C2), i2 = new Uint8ClampedArray(I2 * g2), E2 = new Uint8ClampedArray(I2 * g2);
603
+ for (let e2 = 0; e2 < g2; e2++) {
604
+ const g3 = e2 * I2;
605
+ for (let B3 = 0; B3 < I2; B3++) {
606
+ let C3 = 0;
607
+ for (let i3 = -Q2; i3 <= Q2; i3++) {
608
+ C3 += A2[g3 + Math.min(I2 - 1, Math.max(0, B3 + i3))] * t2[Q2 + i3];
609
+ }
610
+ i2[g3 + B3] = C3;
611
+ }
612
+ }
613
+ for (let e2 = 0; e2 < I2; e2++) for (let A3 = 0; A3 < g2; A3++) {
614
+ let B3 = 0;
615
+ for (let C3 = -Q2; C3 <= Q2; C3++) {
616
+ B3 += i2[Math.min(g2 - 1, Math.max(0, A3 + C3)) * I2 + e2] * t2[Q2 + C3];
617
+ }
618
+ E2[A3 * I2 + e2] = Math.round(B3);
619
+ }
620
+ return E2;
621
+ }
622
+ function S(A2, I2, g2, B2, C2) {
623
+ const Q2 = new Uint8Array(I2 * g2), t2 = [];
624
+ for (let e2 = 1; e2 < g2 - 1; e2++) for (let g3 = 1; g3 < I2 - 1; g3++) {
625
+ const i3 = e2 * I2 + g3, E3 = A2[i3];
626
+ E3 >= C2 ? (Q2[i3] = 2, t2.push({ x: g3, y: e2 })) : Q2[i3] = E3 >= B2 ? 0 : 1;
627
+ }
628
+ for (let e2 = 0; e2 < I2; e2++) Q2[e2] = 1, Q2[(g2 - 1) * I2 + e2] = 1;
629
+ for (let e2 = 1; e2 < g2 - 1; e2++) Q2[e2 * I2] = 1, Q2[e2 * I2 + I2 - 1] = 1;
630
+ const i2 = [-1, 0, 1, -1, 1, -1, 0, 1], E2 = [-1, -1, -1, 0, 0, 1, 1, 1];
631
+ for (; t2.length > 0; ) {
632
+ const { x: A3, y: g3 } = t2.pop();
633
+ for (let B3 = 0; B3 < 8; B3++) {
634
+ const C3 = A3 + i2[B3], e2 = g3 + E2[B3], o2 = e2 * I2 + C3;
635
+ 0 === Q2[o2] && (Q2[o2] = 2, t2.push({ x: C3, y: e2 }));
636
+ }
637
+ }
638
+ return Q2;
639
+ }
640
+ async function M(I2, g2 = {}) {
641
+ const B2 = !(!g2.debug || g2.debug._timingsOnly), C2 = [], Q2 = performance.now();
642
+ let t2, i2, E2;
643
+ if (g2.skipGrayscale || false) t2 = g2.width, i2 = g2.height, E2 = I2, B2 && (g2.debug.grayscale = E2);
644
+ else {
645
+ t2 = I2.width, i2 = I2.height;
646
+ let A2 = performance.now();
647
+ E2 = (function(A3) {
648
+ const { width: I3, height: g3, data: B3 } = A3, C3 = new Uint8ClampedArray(I3 * g3);
649
+ for (let Q4 = 0, t3 = 0; Q4 < B3.length; Q4 += 4, t3++) C3[t3] = 54 * B3[Q4] + 183 * B3[Q4 + 1] + 19 * B3[Q4 + 2] >> 8;
650
+ return C3;
651
+ })(I2);
652
+ let Q3 = performance.now();
653
+ C2.push({ step: "Grayscale", ms: (Q3 - A2).toFixed(2) }), B2 && (g2.debug.grayscale = E2);
654
+ }
655
+ let e2 = void 0 !== g2.lowThreshold ? g2.lowThreshold : null, o2 = void 0 !== g2.highThreshold ? g2.highThreshold : null;
656
+ if (null === e2 || null === o2) {
657
+ const A2 = 1024, I3 = new Uint32Array(A2);
658
+ let g3 = 0;
659
+ for (let e3 = 1; e3 < i2 - 1; e3++) for (let B4 = 1; B4 < t2 - 1; B4++) {
660
+ const C4 = e3 * t2 + B4, Q4 = -E2[C4 - t2 - 1] + E2[C4 - t2 + 1] - 2 * E2[C4 - 1] + 2 * E2[C4 + 1] - E2[C4 + t2 - 1] + E2[C4 + t2 + 1], i3 = -E2[C4 - t2 - 1] - 2 * E2[C4 - t2] - E2[C4 - t2 + 1] + E2[C4 + t2 - 1] + 2 * E2[C4 + t2] + E2[C4 + t2 + 1];
661
+ let o3 = Math.abs(Q4) + Math.abs(i3);
662
+ o3 >= A2 && (o3 = A2 - 1), o3 > 0 && (I3[o3]++, g3++);
663
+ }
664
+ const B3 = Math.round(0.7 * g3);
665
+ let C3 = 0, Q3 = 75;
666
+ for (let t3 = 1; t3 < A2; t3++) if (C3 += I3[t3], C3 >= B3) {
667
+ Q3 = t3;
668
+ break;
669
+ }
670
+ null === e2 && (e2 = Math.max(5, Math.round(0.5 * Q3))), null === o2 && (o2 = Math.min(500, Math.round(1.5 * Q3)));
671
+ }
672
+ const n2 = g2.kernelSize || 5, a2 = g2.sigma || 0, s2 = void 0 !== g2.L2gradient && g2.L2gradient, c2 = void 0 === g2.applyDilation || g2.applyDilation, y2 = g2.dilationKernelSize || 5, D2 = void 0 !== g2.useWasmHysteresis && g2.useWasmHysteresis, d2 = void 0 !== g2.useWasmFullCanny && g2.useWasmFullCanny;
673
+ if (e2 >= o2 && ([e2, o2] = [o2, e2]), d2) try {
674
+ await G();
675
+ const I3 = performance.now(), D3 = new Uint8ClampedArray((function(I4, g3, B3, C3, Q3, t3, i3, E3, e3, o3) {
676
+ const n3 = h(I4, A.__wbindgen_malloc), a3 = r, s3 = A.canny_edge_detector_full(n3, a3, g3, B3, C3, Q3, t3, i3, E3, e3, o3);
677
+ var c3 = l(s3[0], s3[1]).slice();
678
+ return A.__wbindgen_free(s3[0], 1 * s3[1], 1), c3;
679
+ })(E2, t2, i2, e2, o2, n2, a2, s2, c2, y2)), w2 = (performance.now() - I3).toFixed(2);
680
+ C2.push({ step: "Edge Processing (WASM)", ms: w2 }), B2 && (g2.debug.finalEdges = D3), g2.debug ? g2.debug.timings = C2 : g2.debug = { timings: C2 };
681
+ const d3 = performance.now();
682
+ return C2.unshift({ step: "Edge Detection Total", ms: (d3 - Q2).toFixed(2) }), D3;
683
+ } catch (Y) {
684
+ if (!R) {
685
+ R = true;
686
+ Y instanceof Error ? Y.message : String(Y);
687
+ }
688
+ }
689
+ let f2, m2, N2, p2, F2, J2;
690
+ f2 = performance.now();
691
+ try {
692
+ await G(), N2 = (function(I3, g3, B3, C3, Q3) {
693
+ const t3 = h(I3, A.__wbindgen_malloc), i3 = r, E3 = A.blur(t3, i3, g3, B3, C3, Q3);
694
+ var e3 = l(E3[0], E3[1]).slice();
695
+ return A.__wbindgen_free(E3[0], 1 * E3[1], 1), e3;
696
+ })(E2, t2, i2, n2, a2);
697
+ } catch {
698
+ N2 = k(E2, t2, i2, n2, a2);
699
+ }
700
+ m2 = performance.now(), C2.push({ step: "Gaussian Blur", ms: (m2 - f2).toFixed(2) }), B2 && (g2.debug.blurred = N2), f2 = performance.now();
701
+ {
702
+ const A2 = (function(A3, I3, g3) {
703
+ const B3 = new Int16Array(I3 * g3), C3 = new Int16Array(I3 * g3);
704
+ for (let Q3 = 1; Q3 < g3 - 1; Q3++) {
705
+ const g4 = Q3 * I3, t3 = (Q3 - 1) * I3, i3 = (Q3 + 1) * I3;
706
+ for (let Q4 = 1; Q4 < I3 - 1; Q4++) {
707
+ const I4 = g4 + Q4, E3 = A3[t3 + Q4 - 1], e3 = A3[t3 + Q4], o3 = A3[t3 + Q4 + 1], n3 = A3[g4 + Q4 - 1], a3 = A3[g4 + Q4 + 1], s3 = A3[i3 + Q4 - 1], c3 = A3[i3 + Q4], r2 = A3[i3 + Q4 + 1], h2 = o3 - E3 + 2 * (a3 - n3) + (r2 - s3), l2 = s3 + 2 * c3 + r2 - (E3 + 2 * e3 + o3);
708
+ B3[I4] = h2, C3[I4] = l2;
709
+ }
710
+ }
711
+ return { dx: B3, dy: C3 };
712
+ })(N2, t2, i2);
713
+ p2 = A2.dx, F2 = A2.dy;
714
+ }
715
+ m2 = performance.now(), C2.push({ step: "Gradients", ms: (m2 - f2).toFixed(2) }), f2 = performance.now();
716
+ try {
717
+ await G(), J2 = await u(p2, F2, t2, i2, s2);
718
+ } catch {
719
+ J2 = (function(A2, I3, g3, B3, C3) {
720
+ const Q3 = new Float32Array(g3 * B3), t3 = new Float32Array(g3 * B3);
721
+ for (let i3 = 0; i3 < A2.length; i3++) {
722
+ const g4 = A2[i3], B4 = I3[i3];
723
+ Q3[i3] = C3 ? Math.sqrt(g4 * g4 + B4 * B4) : Math.abs(g4) + Math.abs(B4);
724
+ }
725
+ for (let i3 = 1; i3 < B3 - 1; i3++) for (let B4 = 1; B4 < g3 - 1; B4++) {
726
+ const C4 = i3 * g3 + B4, E3 = Q3[C4];
727
+ if (0 === E3) {
728
+ t3[C4] = 0;
729
+ continue;
730
+ }
731
+ const e3 = A2[C4], o3 = I3[C4];
732
+ let n3 = 0, a3 = 0;
733
+ const s3 = Math.abs(e3), c3 = Math.abs(o3);
734
+ if (c3 > 2.4142 * s3) n3 = Q3[C4 - g3], a3 = Q3[C4 + g3];
735
+ else if (s3 > 2.4142 * c3) n3 = Q3[C4 - 1], a3 = Q3[C4 + 1];
736
+ else {
737
+ const A3 = (e3 ^ o3) < 0 ? -1 : 1;
738
+ o3 > 0 ? (n3 = Q3[(i3 - 1) * g3 + (B4 - A3)], a3 = Q3[(i3 + 1) * g3 + (B4 + A3)]) : (n3 = Q3[(i3 + 1) * g3 + (B4 - A3)], a3 = Q3[(i3 - 1) * g3 + (B4 + A3)]), e3 > 0 && o3 > 0 || e3 < 0 && o3 < 0 ? (n3 = Q3[(i3 - 1) * g3 + (B4 + 1)], a3 = Q3[(i3 + 1) * g3 + (B4 - 1)]) : (n3 = Q3[(i3 - 1) * g3 + (B4 - 1)], a3 = Q3[(i3 + 1) * g3 + (B4 + 1)]);
739
+ }
740
+ t3[C4] = E3 >= n3 && E3 >= a3 ? E3 : 0;
741
+ }
742
+ return t3;
743
+ })(p2, F2, t2, i2, s2);
744
+ }
745
+ m2 = performance.now(), C2.push({ step: "Non-Max Suppression", ms: (m2 - f2).toFixed(2) }), f2 = performance.now();
746
+ const M2 = s2 ? e2 * e2 : e2, b = s2 ? o2 * o2 : o2;
747
+ let L;
748
+ if (D2) try {
749
+ await G(), L = w(J2, t2, i2, M2, b);
750
+ } catch (q) {
751
+ L = S(J2, t2, i2, M2, b);
752
+ }
753
+ else L = S(J2, t2, i2, M2, b);
754
+ m2 = performance.now(), C2.push({ step: "Hysteresis", ms: (m2 - f2).toFixed(2) }), f2 = performance.now();
755
+ const x = new Uint8ClampedArray(t2 * i2);
756
+ for (let A2 = 0; A2 < L.length; A2++) x[A2] = 2 === L[A2] ? 255 : 0;
757
+ m2 = performance.now(), C2.push({ step: "Binary Image", ms: (m2 - f2).toFixed(2) }), f2 = performance.now();
758
+ let U = x;
759
+ if (c2) try {
760
+ await G(), U = (function(I3, g3, B3, C3) {
761
+ const Q3 = h(I3, A.__wbindgen_malloc), t3 = r, i3 = A.dilate(Q3, t3, g3, B3, C3);
762
+ var E3 = l(i3[0], i3[1]).slice();
763
+ return A.__wbindgen_free(i3[0], 1 * i3[1], 1), E3;
764
+ })(x, t2, i2, y2);
765
+ } catch {
766
+ U = (function(A2, I3, g3, B3 = 5) {
767
+ const C3 = Math.floor(B3 / 2), Q3 = new Uint8ClampedArray(I3 * g3), t3 = new Uint8ClampedArray(I3 * g3);
768
+ for (let i3 = 0; i3 < g3; i3++) {
769
+ const g4 = i3 * I3;
770
+ for (let B4 = 0; B4 < I3; B4++) {
771
+ let t4 = 0;
772
+ for (let Q4 = -C3; Q4 <= C3; Q4++) {
773
+ const C4 = B4 + Q4;
774
+ if (C4 >= 0 && C4 < I3) {
775
+ const I4 = A2[g4 + C4];
776
+ I4 > t4 && (t4 = I4);
777
+ }
778
+ }
779
+ Q3[g4 + B4] = t4;
780
+ }
781
+ }
782
+ for (let i3 = 0; i3 < I3; i3++) for (let A3 = 0; A3 < g3; A3++) {
783
+ let B4 = 0;
784
+ for (let t4 = -C3; t4 <= C3; t4++) {
785
+ const C4 = A3 + t4;
786
+ if (C4 >= 0 && C4 < g3) {
787
+ const A4 = Q3[C4 * I3 + i3];
788
+ A4 > B4 && (B4 = A4);
789
+ }
790
+ }
791
+ t3[A3 * I3 + i3] = B4;
792
+ }
793
+ return t3;
794
+ })(x, t2, i2, y2);
795
+ }
796
+ if (m2 = performance.now(), C2.push({ step: "Dilation", ms: (m2 - f2).toFixed(2) }), B2) {
797
+ g2.debug.dx = p2, g2.debug.dy = F2;
798
+ const A2 = new Float32Array(t2 * i2);
799
+ for (let I3 = 0; I3 < p2.length; I3++) {
800
+ const g3 = p2[I3], B3 = F2[I3];
801
+ A2[I3] = s2 ? Math.sqrt(g3 * g3 + B3 * B3) : Math.abs(g3) + Math.abs(B3);
802
+ }
803
+ g2.debug.magnitude = A2, g2.debug.suppressed = J2, g2.debug.edgeMap = L, g2.debug.cannyEdges = x, g2.debug.finalEdges = U;
804
+ }
805
+ g2.debug ? g2.debug.timings = C2 : g2.debug || (g2.debug = { timings: C2 });
806
+ const H = performance.now();
807
+ return C2.unshift({ step: "Edge Detection Total", ms: (H - Q2).toFixed(2) }), U;
808
+ }
809
+ function Z(A2) {
810
+ return A2 <= 0 ? 0 : A2 >= 1 ? 1 : A2;
811
+ }
812
+ function X(A2, I2) {
813
+ return Math.hypot(A2.x - I2.x, A2.y - I2.y);
814
+ }
815
+ function V(A2) {
816
+ return [X(A2.topLeft, A2.topRight), X(A2.topRight, A2.bottomRight), X(A2.bottomRight, A2.bottomLeft), X(A2.bottomLeft, A2.topLeft)];
817
+ }
818
+ function j(A2) {
819
+ const I2 = (function(A3) {
820
+ const I3 = [A3.topLeft, A3.topRight, A3.bottomRight, A3.bottomLeft], g3 = [];
821
+ for (let B2 = 0; B2 < I3.length; B2++) {
822
+ const A4 = I3[(B2 + I3.length - 1) % I3.length], C2 = I3[B2], Q2 = I3[(B2 + 1) % I3.length], t2 = A4.x - C2.x, i2 = A4.y - C2.y, E2 = Q2.x - C2.x, e2 = Q2.y - C2.y, o2 = t2 * E2 + i2 * e2, n2 = Math.max(1e-6, Math.hypot(t2, i2) * Math.hypot(E2, e2)), a2 = Math.max(-1, Math.min(1, o2 / n2));
823
+ g3.push(180 * Math.acos(a2) / Math.PI);
824
+ }
825
+ return g3;
826
+ })(A2);
827
+ let g2 = 0;
828
+ for (const B2 of I2) {
829
+ g2 += Z(1 - Math.abs(B2 - 90) / 55);
830
+ }
831
+ return g2 / Math.max(1, I2.length);
832
+ }
833
+ function O(A2, I2) {
834
+ const g2 = Number(I2.isValid) - Number(A2.isValid);
835
+ if (0 !== g2) return g2;
836
+ const B2 = I2.confidence - A2.confidence;
837
+ if (!(Math.abs(B2) < 0.015) && 0 !== B2) return B2;
838
+ const C2 = Math.abs((A2.approxCount ?? 99) - 4) - Math.abs((I2.approxCount ?? 99) - 4);
839
+ if (0 !== C2) return C2;
840
+ const Q2 = (I2.rightAngleScore ?? 0) - (A2.rightAngleScore ?? 0);
841
+ if (Math.abs(Q2) > 1e-6) return Q2;
842
+ const t2 = Math.abs(1 - (A2.contourFitRatio ?? 1)) - Math.abs(1 - (I2.contourFitRatio ?? 1));
843
+ return Math.abs(t2) > 1e-6 ? t2 : B2 || I2.score - A2.score || I2.coverageRatio - A2.coverageRatio || I2.area - A2.area;
844
+ }
845
+ function z(A2, I2, g2, B2, C2 = {}) {
846
+ const Q2 = C2.epsilon || 0.02, t2 = E(A2.points, Q2).length, i2 = n(A2, { epsilon: Q2 });
847
+ if (!i2) return { contour: A2, corners: null, score: 0, confidence: 0, isValid: false, area: A2.area || 0, fillRatio: 0, coverageRatio: 0, cornersArea: 0, approxCount: t2, convex: false, edgeSupport: 0, aspectRatio: 1 / 0, minSide: 0, rightAngleScore: 0, oppositeSideConsistency: 0, contourFitRatio: 0, contourFitScore: 0 };
848
+ const e2 = g2 * B2, o2 = A2.area || 0, a2 = A2.boundingBox || { minX: 0, minY: 0, maxX: 0, maxY: 0 }, s2 = o2 / Math.max(1, (a2.maxX - a2.minX + 1) * (a2.maxY - a2.minY + 1)), c2 = (function(A3) {
849
+ if (!A3) return 0;
850
+ const I3 = [A3.topLeft, A3.topRight, A3.bottomRight, A3.bottomLeft];
851
+ let g3 = 0;
852
+ for (let B3 = 0; B3 < I3.length; B3++) {
853
+ const A4 = (B3 + 1) % I3.length;
854
+ g3 += I3[B3].x * I3[A4].y - I3[A4].x * I3[B3].y;
855
+ }
856
+ return Math.abs(g3) / 2;
857
+ })(i2), r2 = c2 / Math.max(1, e2), h2 = V(i2), l2 = Math.min(...h2), y2 = (h2[0] + h2[2]) / 2, D2 = (h2[1] + h2[3]) / 2, w2 = y2 > D2 ? y2 / Math.max(1e-6, D2) : D2 / Math.max(1e-6, y2), d2 = (function(A3) {
858
+ const I3 = [A3.topLeft, A3.topRight, A3.bottomRight, A3.bottomLeft], g3 = [];
859
+ for (let C3 = 0; C3 < I3.length; C3++) {
860
+ const A4 = I3[C3], B4 = I3[(C3 + 1) % I3.length], Q3 = I3[(C3 + 2) % I3.length], t3 = (B4.x - A4.x) * (Q3.y - B4.y) - (B4.y - A4.y) * (Q3.x - B4.x);
861
+ Math.abs(t3) < 1e-6 || g3.push(Math.sign(t3));
862
+ }
863
+ if (g3.length < 3) return false;
864
+ const B3 = g3[0];
865
+ return g3.every((A4) => A4 === B3);
866
+ })(i2), f2 = (function(A3, I3, g3, B3) {
867
+ if (!A3?.points || 0 === A3.points.length) return 0;
868
+ const C3 = Math.max(1, Math.floor(A3.points.length / 240));
869
+ let Q3 = 0, t3 = 0;
870
+ for (let i3 = 0; i3 < A3.points.length; i3 += C3) {
871
+ const C4 = A3.points[i3], E2 = Math.max(0, Math.min(g3 - 1, 0 | C4.x)), e3 = Math.max(0, Math.min(B3 - 1, 0 | C4.y));
872
+ Q3++;
873
+ let o3 = false;
874
+ for (let A4 = -1; A4 <= 1 && !o3; A4++) {
875
+ const C5 = e3 + A4;
876
+ if (!(C5 < 0 || C5 >= B3)) for (let A5 = -1; A5 <= 1; A5++) {
877
+ const B4 = E2 + A5;
878
+ if (!(B4 < 0 || B4 >= g3) && I3[C5 * g3 + B4] > 0) {
879
+ o3 = true;
880
+ break;
881
+ }
882
+ }
883
+ }
884
+ o3 && t3++;
885
+ }
886
+ return 0 === Q3 ? 0 : t3 / Q3;
887
+ })(A2, I2, g2, B2), u2 = j(i2), m2 = (function(A3) {
888
+ const I3 = V(A3);
889
+ return (Math.min(I3[0], I3[2]) / Math.max(1e-6, Math.max(I3[0], I3[2])) + Math.min(I3[1], I3[3]) / Math.max(1e-6, Math.max(I3[1], I3[3]))) / 2;
890
+ })(i2), N2 = o2 / Math.max(1, c2), R2 = Z(1 - Math.abs(N2 - 1) / 0.55), p2 = 4 === t2 ? 1 : 5 === t2 ? 0.9 : 6 === t2 ? 0.7 : t2 <= 8 ? 0.5 : 0.28, F2 = Z(o2 / Math.max(1, 0.4 * e2)), J2 = Z((s2 - 0.08) / 0.72), G2 = Z((r2 - 0.03) / 0.82), k2 = void 0 !== C2.minDocumentSideRatio ? C2.minDocumentSideRatio : 0.06, S2 = void 0 !== C2.minDocumentCoverageRatio ? C2.minDocumentCoverageRatio : 0.04, M2 = void 0 !== C2.maxDocumentAspectRatio ? C2.maxDocumentAspectRatio : 8, b = void 0 !== C2.minDocumentFillRatio ? C2.minDocumentFillRatio : 0.07, L = void 0 !== C2.minContourFitRatio ? C2.minContourFitRatio : 0.11, x = void 0 !== C2.maxContourFitRatio ? C2.maxContourFitRatio : 1.2, U = void 0 !== C2.minRightAngleScore ? C2.minRightAngleScore : 0.42, H = void 0 !== C2.minOppositeSideConsistency ? C2.minOppositeSideConsistency : 0.3, Y = Math.min(g2, B2) * k2, q = (function(A3, I3 = 6) {
891
+ const g3 = [A3?.topLeft, A3?.topRight, A3?.bottomRight, A3?.bottomLeft];
892
+ if (g3.some((A4) => !A4 || !Number.isFinite(A4.x) || !Number.isFinite(A4.y))) return false;
893
+ for (let B3 = 0; B3 < g3.length; B3++) for (let A4 = B3 + 1; A4 < g3.length; A4++) if (X(g3[B3], g3[A4]) < I3) return false;
894
+ return true;
895
+ })(i2) && d2 && l2 >= Y && r2 >= S2 && w2 <= M2 && s2 >= b && N2 >= L && N2 <= x && u2 >= U && m2 >= H, v = 0.22 * F2 + 0.14 * J2 + 0.15 * p2 + 0.08 * (d2 ? 1 : 0) + 0.08 * f2 + 0.13 * G2 + 0.1 * u2 + 0.05 * m2 + 0.05 * R2;
896
+ return { contour: A2, corners: i2, score: v, confidence: q ? v : 0.33 * v, isValid: q, area: o2, fillRatio: s2, coverageRatio: r2, cornersArea: c2, approxCount: t2, convex: d2, edgeSupport: f2, aspectRatio: w2, minSide: l2, rightAngleScore: u2, oppositeSideConsistency: m2, contourFitRatio: N2, contourFitScore: R2 };
897
+ }
898
+ async function _(A2, I2, g2, C2, Q2 = {}) {
899
+ const t2 = Q2.debug ? {} : { _timingsOnly: true }, i2 = [];
900
+ t2 && !t2._timingsOnly && (t2.preprocessing = { scaledDimensions: { width: I2, height: g2 }, scaleFactor: C2, maxProcessingDimension: Q2.maxProcessingDimension || 800 });
901
+ const E2 = (function(A3 = {}) {
902
+ const I3 = A3.dilationKernelSize || 3, g3 = A3.dilationIterations || 1, B2 = void 0 === A3.applyDilation || A3.applyDilation, C3 = [{ name: "default", lowThreshold: A3.lowThreshold, highThreshold: A3.highThreshold, dilationKernelSize: I3, dilationIterations: g3, applyDilation: B2 }];
903
+ if (false === A3.enableDetectionCascade) return C3;
904
+ C3.push({ name: "connect-edges", lowThreshold: A3.lowThreshold, highThreshold: A3.highThreshold, dilationKernelSize: Math.max(I3, 5), dilationIterations: Math.max(g3, 2), applyDilation: true }), C3.push({ name: "no-dilation", lowThreshold: A3.lowThreshold, highThreshold: A3.highThreshold, dilationKernelSize: I3, dilationIterations: g3, applyDilation: false }), void 0 === A3.lowThreshold && void 0 === A3.highThreshold && C3.push({ name: "fixed-mid-thresholds", lowThreshold: 60, highThreshold: 180, dilationKernelSize: I3, dilationIterations: g3, applyDilation: B2 });
905
+ const Q3 = [], t3 = /* @__PURE__ */ new Set();
906
+ for (const i3 of C3) {
907
+ const A4 = [i3.lowThreshold, i3.highThreshold, i3.dilationKernelSize, i3.dilationIterations, i3.applyDilation].join(":");
908
+ t3.has(A4) || (t3.add(A4), Q3.push(i3));
909
+ }
910
+ return Q3;
911
+ })(Q2), e2 = [], o2 = async (t3, E3) => {
912
+ const e3 = t3.name || `pass-${E3 + 1}`, o3 = 0 === E3 ? "" : ` (${e3})`, n3 = Q2.debug ? {} : { _timingsOnly: true }, a3 = await M(A2, { width: I2, height: g2, lowThreshold: t3.lowThreshold, highThreshold: t3.highThreshold, dilationKernelSize: t3.dilationKernelSize, dilationIterations: t3.dilationIterations, applyDilation: t3.applyDilation, debug: n3, skipGrayscale: true, useWasmBlur: true, useWasmHysteresis: Q2.useWasmHysteresis, useWasmFullCanny: Q2.useWasmFullCanny });
913
+ n3.timings && n3.timings.forEach((A3) => {
914
+ "Edge Detection Total" !== A3.step && i2.push({ step: `${A3.step}${o3}`, ms: A3.ms });
915
+ });
916
+ let s3 = performance.now();
917
+ const c3 = B(a3, { minArea: (Q2.minArea || 1e3) / (C2 * C2), width: I2, height: g2 });
918
+ i2.push({ step: `Find Contours${o3}`, ms: (performance.now() - s3).toFixed(2) }), s3 = performance.now();
919
+ const { best: r3, candidates: h3 } = (function(A3, I3, g3, B2, C3 = {}) {
920
+ const Q3 = C3.maxCandidateContours || 12, t4 = A3.slice(0, Q3).map((A4, Q4) => ({ rankByArea: Q4, ...z(A4, I3, g3, B2, C3) })).sort(O);
921
+ return { best: t4[0] || null, candidates: t4 };
922
+ })(c3, a3, I2, g2, Q2);
923
+ return i2.push({ step: `Corner Detection${o3}`, ms: (performance.now() - s3).toFixed(2) }), { name: e3, params: { lowThreshold: t3.lowThreshold, highThreshold: t3.highThreshold, dilationKernelSize: t3.dilationKernelSize, dilationIterations: t3.dilationIterations, applyDilation: t3.applyDilation }, contours: c3, best: r3, candidates: h3 };
924
+ }, n2 = await o2(E2[0], 0);
925
+ if (e2.push(n2), (function(A3, I3 = {}) {
926
+ if (false === I3.enableDetectionCascade) return false;
927
+ if (!A3 || !A3.corners) return true;
928
+ const g3 = void 0 !== I3.minCascadeTriggerConfidence ? I3.minCascadeTriggerConfidence : 0.68;
929
+ return !A3.isValid || A3.confidence < g3 || A3.approxCount > 5 || A3.rightAngleScore < 0.55 || A3.contourFitRatio < 0.14;
930
+ })(n2.best, Q2)) for (let B2 = 1; B2 < E2.length; B2++) e2.push(await o2(E2[B2], B2));
931
+ const a2 = [];
932
+ for (const B2 of e2) for (const A3 of B2.candidates) a2.push({ ...A3, passName: B2.name, passParams: B2.params });
933
+ a2.sort(O);
934
+ const s2 = a2[0] || null, c2 = a2;
935
+ if (!s2 || !s2.corners) return { success: false, message: "No document detected", debug: t2._timingsOnly ? null : t2, timings: i2 };
936
+ t2 && !t2._timingsOnly && (t2.passes = e2.map((A3) => ({ name: A3.name, params: A3.params, contourCount: A3.contours.length, bestCandidate: A3.best ? { score: A3.best.score, confidence: A3.best.confidence, isValid: A3.best.isValid, approxCount: A3.best.approxCount, coverageRatio: A3.best.coverageRatio, fillRatio: A3.best.fillRatio, rightAngleScore: A3.best.rightAngleScore, contourFitRatio: A3.best.contourFitRatio } : null })), t2.candidates = c2.map((A3) => ({ passName: A3.passName, rankByArea: A3.rankByArea, area: A3.area, fillRatio: A3.fillRatio, coverageRatio: A3.coverageRatio, cornersArea: A3.cornersArea, approxCount: A3.approxCount, convex: A3.convex, edgeSupport: A3.edgeSupport, aspectRatio: A3.aspectRatio, minSide: A3.minSide, rightAngleScore: A3.rightAngleScore, oppositeSideConsistency: A3.oppositeSideConsistency, contourFitRatio: A3.contourFitRatio, contourFitScore: A3.contourFitScore, score: A3.score, confidence: A3.confidence, isValid: A3.isValid })), t2.selectedCandidate = c2[0] ? { passName: c2[0].passName, rankByArea: c2[0].rankByArea, area: c2[0].area, fillRatio: c2[0].fillRatio, coverageRatio: c2[0].coverageRatio, approxCount: c2[0].approxCount, edgeSupport: c2[0].edgeSupport, aspectRatio: c2[0].aspectRatio, minSide: c2[0].minSide, rightAngleScore: c2[0].rightAngleScore, oppositeSideConsistency: c2[0].oppositeSideConsistency, contourFitRatio: c2[0].contourFitRatio, score: c2[0].score, confidence: c2[0].confidence, isValid: c2[0].isValid } : null);
937
+ const r2 = s2.corners, h2 = s2.contour;
938
+ let l2 = r2;
939
+ return 1 !== C2 && (l2 = { topLeft: { x: r2.topLeft.x * C2, y: r2.topLeft.y * C2 }, topRight: { x: r2.topRight.x * C2, y: r2.topRight.y * C2 }, bottomRight: { x: r2.bottomRight.x * C2, y: r2.bottomRight.y * C2 }, bottomLeft: { x: r2.bottomLeft.x * C2, y: r2.bottomLeft.y * C2 } }), { success: true, contour: h2, corners: l2, confidence: s2.confidence, debug: t2._timingsOnly ? null : t2, timings: i2 };
940
+ }
941
+ function $(A2, I2, g2) {
942
+ const { topLeft: B2, topRight: C2, bottomRight: Q2, bottomLeft: t2 } = g2, i2 = Math.hypot(Q2.x - t2.x, Q2.y - t2.y), E2 = Math.hypot(C2.x - B2.x, C2.y - B2.y), e2 = Math.round(Math.max(i2, E2)), o2 = Math.hypot(C2.x - Q2.x, C2.y - Q2.y), n2 = Math.hypot(B2.x - t2.x, B2.y - t2.y), a2 = Math.round(Math.max(o2, n2));
943
+ A2.canvas.width = e2, A2.canvas.height = a2, (function(A3, I3, g3, B3, C3) {
944
+ const Q3 = I3 && "number" == typeof I3.width && "number" == typeof I3.height && I3.data, t3 = I3.width || I3.naturalWidth, i3 = I3.height || I3.naturalHeight, E3 = document.createElement("canvas");
945
+ E3.width = t3, E3.height = i3;
946
+ const e3 = E3.getContext("2d", { willReadFrequently: true });
947
+ Q3 ? e3.putImageData(I3, 0, 0) : e3.drawImage(I3, 0, 0, t3, i3);
948
+ const o3 = e3.getImageData(0, 0, t3, i3).data, n3 = (function(A4) {
949
+ const I4 = A4[0][0], g4 = A4[0][1], B4 = A4[0][2], C4 = A4[1][0], Q4 = A4[1][1], t4 = A4[1][2], i4 = A4[2][0], E4 = A4[2][1], e4 = A4[2][2], o4 = Q4 * e4 - t4 * E4, n4 = -(C4 * e4 - t4 * i4), a4 = C4 * E4 - Q4 * i4, s3 = -(g4 * e4 - B4 * E4), c3 = I4 * e4 - B4 * i4, r3 = -(I4 * E4 - g4 * i4), h3 = g4 * t4 - B4 * Q4, l3 = -(I4 * t4 - B4 * C4), y3 = I4 * Q4 - g4 * C4, D3 = I4 * o4 + g4 * n4 + B4 * a4;
950
+ if (0 === D3) throw new Error("Singular matrix");
951
+ return [[o4 / D3, s3 / D3, h3 / D3], [n4 / D3, c3 / D3, l3 / D3], [a4 / D3, r3 / D3, y3 / D3]];
952
+ })(g3), a3 = n3[0][0], s2 = n3[0][1], c2 = n3[0][2], r2 = n3[1][0], h2 = n3[1][1], l2 = n3[1][2], y2 = n3[2][0], D2 = n3[2][1], w2 = n3[2][2], d2 = A3.createImageData(B3, C3), f2 = d2.data, u2 = t3 - 1, m2 = i3 - 1;
953
+ for (let N2 = 0; N2 < C3; N2++) {
954
+ const A4 = s2 * N2 + c2, I4 = h2 * N2 + l2, g4 = D2 * N2 + w2;
955
+ for (let C4 = 0; C4 < B3; C4++) {
956
+ const Q4 = 1 / (y2 * C4 + g4), i4 = (a3 * C4 + A4) * Q4, E4 = (r2 * C4 + I4) * Q4, e4 = i4 < 0 ? 0 : i4 > u2 ? u2 : i4, n4 = E4 < 0 ? 0 : E4 > m2 ? m2 : E4, s3 = 0 | e4, c3 = 0 | n4, h3 = s3 < u2 ? s3 + 1 : s3, l3 = c3 < m2 ? c3 + 1 : c3, D3 = e4 - s3, w3 = n4 - c3, d3 = 1 - D3, R2 = 1 - w3, p2 = d3 * R2, F2 = D3 * R2, J2 = d3 * w3, G2 = D3 * w3, k2 = c3 * t3 + s3 << 2, S2 = c3 * t3 + h3 << 2, M2 = l3 * t3 + s3 << 2, b = l3 * t3 + h3 << 2, L = N2 * B3 + C4 << 2;
957
+ f2[L] = o3[k2] * p2 + o3[S2] * F2 + o3[M2] * J2 + o3[b] * G2 + 0.5 | 0, f2[L + 1] = o3[k2 + 1] * p2 + o3[S2 + 1] * F2 + o3[M2 + 1] * J2 + o3[b + 1] * G2 + 0.5 | 0, f2[L + 2] = o3[k2 + 2] * p2 + o3[S2 + 2] * F2 + o3[M2 + 2] * J2 + o3[b + 2] * G2 + 0.5 | 0, f2[L + 3] = 255;
958
+ }
959
+ }
960
+ A3.putImageData(d2, 0, 0);
961
+ })(A2, I2, (function(A3, I3) {
962
+ const g3 = (function(A4, I4) {
963
+ const g4 = A4.length, B3 = A4[0].length, C3 = A4.map((A5) => A5.slice()), Q3 = I4.slice();
964
+ for (let i3 = 0; i3 < B3; i3++) {
965
+ let A5 = i3;
966
+ for (let I5 = i3 + 1; I5 < g4; I5++) Math.abs(C3[I5][i3]) > Math.abs(C3[A5][i3]) && (A5 = I5);
967
+ [C3[i3], C3[A5]] = [C3[A5], C3[i3]], [Q3[i3], Q3[A5]] = [Q3[A5], Q3[i3]];
968
+ for (let I5 = i3 + 1; I5 < g4; I5++) {
969
+ const A6 = C3[I5][i3] / C3[i3][i3];
970
+ for (let g5 = i3; g5 < B3; g5++) C3[I5][g5] -= A6 * C3[i3][g5];
971
+ Q3[I5] -= A6 * Q3[i3];
972
+ }
973
+ }
974
+ const t3 = new Array(B3);
975
+ for (let i3 = B3 - 1; i3 >= 0; i3--) {
976
+ let A5 = Q3[i3];
977
+ for (let I5 = i3 + 1; I5 < B3; I5++) A5 -= C3[i3][I5] * t3[I5];
978
+ t3[i3] = A5 / C3[i3][i3];
979
+ }
980
+ return t3;
981
+ })((function(A4) {
982
+ const g4 = [];
983
+ for (let B3 = 0; B3 < 4; B3++) {
984
+ const [C3, Q3] = A4[B3];
985
+ g4.push([C3, Q3, 1, 0, 0, 0, -C3 * I3[B3][0], -Q3 * I3[B3][0]]), g4.push([0, 0, 0, C3, Q3, 1, -C3 * I3[B3][1], -Q3 * I3[B3][1]]);
986
+ }
987
+ return g4;
988
+ })(A3), [I3[0][0], I3[0][1], I3[1][0], I3[1][1], I3[2][0], I3[2][1], I3[3][0], I3[3][1]]);
989
+ return [[g3[0], g3[1], g3[2]], [g3[3], g3[4], g3[5]], [g3[6], g3[7], 1]];
990
+ })([[B2.x, B2.y], [C2.x, C2.y], [Q2.x, Q2.y], [t2.x, t2.y]], [[0, 0], [e2 - 1, 0], [e2 - 1, a2 - 1], [0, a2 - 1]]), e2, a2);
991
+ }
992
+ async function IA(A2, I2 = {}) {
993
+ const g2 = [], B2 = performance.now(), C2 = I2.mode || "detect", Q2 = I2.output || "canvas", t2 = I2.maxProcessingDimension || 800;
994
+ let i2, E2, e2, o2;
995
+ if ("ml" === (I2.detector || "classical")) {
996
+ E2 = performance.now();
997
+ const { detectDocumentMl: B3 } = await Promise.resolve().then(() => (init_scanic_ml_stub(), scanic_ml_stub_exports));
998
+ i2 = await B3(A2, I2.ml || {}), g2.push({ step: "ML Detection Total", ms: (performance.now() - E2).toFixed(2) }), i2.timings && i2.timings.forEach((A3) => g2.push(A3));
999
+ } else {
1000
+ E2 = performance.now();
1001
+ const { grayscaleData: B3, scaleFactor: C3, scaledDimensions: Q3 } = await (async function(A3, I3 = 800) {
1002
+ let g3, B4;
1003
+ const C4 = A3 && "number" == typeof A3.width && "number" == typeof A3.height && A3.data;
1004
+ if (C4) g3 = A3.width, B4 = A3.height;
1005
+ else {
1006
+ if (!A3) throw new Error("No image provided");
1007
+ g3 = A3.width || A3.naturalWidth, B4 = A3.height || A3.naturalHeight;
1008
+ }
1009
+ const Q4 = Math.max(g3, B4);
1010
+ let t3, i3, E3;
1011
+ if (Q4 <= I3) t3 = g3, i3 = B4, E3 = 1;
1012
+ else {
1013
+ const A4 = I3 / Q4;
1014
+ t3 = Math.round(g3 * A4), i3 = Math.round(B4 * A4), E3 = 1 / A4;
1015
+ }
1016
+ const e3 = "undefined" != typeof OffscreenCanvas, o3 = e3 ? new OffscreenCanvas(t3, i3) : document.createElement("canvas");
1017
+ e3 || (o3.width = t3, o3.height = i3);
1018
+ const n3 = o3.getContext("2d", { willReadFrequently: true });
1019
+ if (n3.imageSmoothingEnabled = true, n3.imageSmoothingQuality = "medium", C4) {
1020
+ const I4 = e3 ? new OffscreenCanvas(g3, B4) : document.createElement("canvas");
1021
+ e3 || (I4.width = g3, I4.height = B4), I4.getContext("2d").putImageData(A3, 0, 0), n3.drawImage(I4, 0, 0, g3, B4, 0, 0, t3, i3);
1022
+ } else n3.drawImage(A3, 0, 0, g3, B4, 0, 0, t3, i3);
1023
+ const a2 = n3.getImageData(0, 0, t3, i3), s2 = a2.data, c2 = new Uint8ClampedArray(t3 * i3);
1024
+ for (let r2 = 0, h2 = 0; r2 < s2.length; r2 += 4, h2++) {
1025
+ const A4 = 54 * s2[r2] + 183 * s2[r2 + 1] + 19 * s2[r2 + 2] >> 8;
1026
+ c2[h2] = A4, s2[r2] = s2[r2 + 1] = s2[r2 + 2] = A4;
1027
+ }
1028
+ return { grayscaleData: c2, imageData: a2, scaleFactor: E3, originalDimensions: { width: g3, height: B4 }, scaledDimensions: { width: t3, height: i3 } };
1029
+ })(A2, t2);
1030
+ g2.push({ step: "Image Prep + Scale + Gray", ms: (performance.now() - E2).toFixed(2) }), i2 = await _(B3, Q3.width, Q3.height, C3, I2), i2.timings && i2.timings.forEach((A3) => g2.push(A3));
1031
+ }
1032
+ if (!i2.success) {
1033
+ const A3 = performance.now();
1034
+ return g2.unshift({ step: "Total", ms: (A3 - B2).toFixed(2) }), { output: null, corners: null, contour: null, confidence: i2.confidence || null, score: i2.score ?? null, debug: i2.debug, success: false, message: i2.message || "No document detected", timings: g2 };
1035
+ }
1036
+ "detect" === C2 ? o2 = null : "extract" === C2 && (E2 = performance.now(), e2 = document.createElement("canvas"), $(e2.getContext("2d"), A2, i2.corners), g2.push({ step: "Perspective Transform", ms: (performance.now() - E2).toFixed(2) })), "detect" !== C2 && e2 && (E2 = performance.now(), o2 = "canvas" === Q2 ? e2 : "imagedata" === Q2 ? e2.getContext("2d").getImageData(0, 0, e2.width, e2.height) : "dataurl" === Q2 ? e2.toDataURL() : e2, g2.push({ step: "Output Conversion", ms: (performance.now() - E2).toFixed(2) }));
1037
+ const n2 = performance.now();
1038
+ return g2.unshift({ step: "Total", ms: (n2 - B2).toFixed(2) }), { output: o2, corners: i2.corners, contour: i2.contour ?? null, confidence: i2.confidence || null, score: i2.score ?? null, debug: i2.debug, success: true, message: "Document detected", timings: g2 };
1039
+ }
1040
+ var A, I, g, s, r, y, d, N, R, p;
1041
+ var init_scanic = __esm({
1042
+ "vendor/scanic/scanic.js"() {
1043
+ "use strict";
1044
+ I = 1e3;
1045
+ g = 10;
1046
+ s = null;
1047
+ r = 0;
1048
+ y = null;
1049
+ d = null;
1050
+ N = null;
1051
+ R = false;
1052
+ p = null;
1053
+ }
1054
+ });
1055
+
1056
+ // src/core/doc/detector-scanic.ts
1057
+ var detector_scanic_exports = {};
1058
+ __export(detector_scanic_exports, {
1059
+ DOC_DETECT_MIN_CONFIDENCE: () => DOC_DETECT_MIN_CONFIDENCE,
1060
+ DOC_DETECT_WIDTH: () => DOC_DETECT_WIDTH,
1061
+ SCANIC_VERSION: () => SCANIC_VERSION,
1062
+ detectQuad: () => detectQuad
1063
+ });
1064
+ async function detectQuad(image) {
1065
+ const result = await IA(image, {
1066
+ mode: "detect",
1067
+ detector: "classical",
1068
+ maxProcessingDimension: DOC_DETECT_WIDTH
1069
+ });
1070
+ if (!result.success || result.corners === null) return null;
1071
+ if (typeof result.confidence === "number" && result.confidence < DOC_DETECT_MIN_CONFIDENCE) {
1072
+ return null;
1073
+ }
1074
+ return result.corners;
1075
+ }
1076
+ var SCANIC_VERSION, DOC_DETECT_MIN_CONFIDENCE;
1077
+ var init_detector_scanic = __esm({
1078
+ "src/core/doc/detector-scanic.ts"() {
1079
+ "use strict";
1080
+ init_scanic();
1081
+ init_doc_gate_v1();
1082
+ SCANIC_VERSION = "1.5.0";
1083
+ DOC_DETECT_MIN_CONFIDENCE = 0.35;
1084
+ }
1085
+ });
1086
+
1087
+ // src/internal/index.ts
1088
+ var internal_exports = {};
1089
+ __export(internal_exports, {
1090
+ ASPECT_BANDS: () => ASPECT_BANDS,
1091
+ AttestationError: () => AttestationError,
1092
+ CAPTURE_CANDIDATE_SPACING_MS: () => CAPTURE_CANDIDATE_SPACING_MS,
1093
+ CAPTURE_EXTRA_CANDIDATES: () => CAPTURE_EXTRA_CANDIDATES,
1094
+ CENTERED_FACTOR: () => CENTERED_FACTOR,
1095
+ CIRCLE_RADIUS_FACTOR: () => CIRCLE_RADIUS_FACTOR,
1096
+ CLIP_MIME_ALLOWLIST: () => CLIP_MIME_ALLOWLIST,
1097
+ CaptureSessionDoc: () => CaptureSessionDoc,
1098
+ DOC_ANALYSIS_DEFAULTS: () => DOC_ANALYSIS_DEFAULTS,
1099
+ DOC_CADENCE_HZ: () => DOC_CADENCE_HZ,
1100
+ DOC_DETECT_WIDTH: () => DOC_DETECT_WIDTH,
1101
+ DOC_FEEDBACK_STATES: () => DOC_FEEDBACK_STATES,
1102
+ DOC_GATE_V1_DEFAULTS: () => DOC_GATE_V1_DEFAULTS,
1103
+ DocFeedbackAggregator: () => DocFeedbackAggregator,
1104
+ DocGateV1: () => DocGateV1,
1105
+ IN_CIRCLE_FACTOR: () => IN_CIRCLE_FACTOR,
1106
+ MRZ_BAND_DEFAULTS: () => MRZ_BAND_DEFAULTS,
1107
+ MR_DOC_CATALOG: () => MR_DOC_CATALOG,
1108
+ PROCESSING_POLL_DELAY_MS: () => PROCESSING_POLL_DELAY_MS,
1109
+ PROCESSING_POLL_MAX: () => PROCESSING_POLL_MAX,
1110
+ REGISTRY_RETRY_DELAY_MS: () => REGISTRY_RETRY_DELAY_MS,
1111
+ RETRYABLE_REASONS: () => RETRYABLE_REASONS,
1112
+ TRANSPORT_REPLAY_ATTEMPTS: () => TRANSPORT_REPLAY_ATTEMPTS,
1113
+ TRANSPORT_REPLAY_DELAY_MS: () => TRANSPORT_REPLAY_DELAY_MS,
1114
+ TURNSTILE_EXECUTE_TIMEOUT_MS: () => TURNSTILE_EXECUTE_TIMEOUT_MS,
1115
+ TURNSTILE_SCRIPT_SRC: () => TURNSTILE_SCRIPT_SRC,
1116
+ analyzeDocFrame: () => analyzeDocFrame,
1117
+ aspectBand: () => aspectBand,
1118
+ createLivenessCaptureInternal: () => createLivenessCaptureInternal,
1119
+ createVerificationInternal: () => createVerificationInternal,
1120
+ detectMrzBand: () => detectMrzBand,
1121
+ executeTurnstile: () => executeTurnstile,
1122
+ feedbackVoteOf: () => feedbackVoteOf,
1123
+ frontierStep: () => frontierStep,
1124
+ isExecutable: () => isExecutable,
1125
+ isTerminalView: () => isTerminalView,
1126
+ loadTurnstile: () => loadTurnstile,
1127
+ mapEngineState: () => mapEngineState,
1128
+ mapErrorKind: () => mapErrorKind,
1129
+ mapGuidanceHint: () => mapGuidanceHint,
1130
+ mapSessionResult: () => mapSessionResult,
1131
+ mergeSessionView: () => mergeSessionView,
1132
+ quadAreaFrac: () => quadAreaFrac,
1133
+ quadBounds: () => quadBounds,
1134
+ quadIou: () => quadIou,
1135
+ quadTiltRatio: () => quadTiltRatio,
1136
+ randomUuid: () => randomUuid,
1137
+ resetTurnstileForTests: () => resetTurnstileForTests,
1138
+ runLivenessFlow: () => runLivenessFlow,
1139
+ runSubmission: () => runSubmission,
1140
+ specularFraction: () => specularFraction,
1141
+ stepOf: () => stepOf,
1142
+ warmDocDetector: () => warmDocDetector
1143
+ });
1144
+ module.exports = __toCommonJS(internal_exports);
1145
+ init_doc_catalog();
1146
+ init_doc_gate_v1();
1147
+
1148
+ // src/core/doc/mrz-band.ts
1149
+ var MRZ_BAND_DEFAULTS = Object.freeze({
1150
+ EDGE_LUMA_DELTA: 40,
1151
+ MIN_ROW_DENSITY: 0.08,
1152
+ MIN_COLUMN_COVERAGE: 0.6,
1153
+ MIN_WIDTH_FRAC: 0.55,
1154
+ MIN_HEIGHT_FRAC: 0.02,
1155
+ MAX_HEIGHT_FRAC: 0.16,
1156
+ ROW_MERGE_GAP: 18
1157
+ });
1158
+ var COLUMN_BUCKETS = 12;
1159
+ function detectMrzBand(frame, overrides = {}) {
1160
+ const t2 = { ...MRZ_BAND_DEFAULTS, ...overrides };
1161
+ const { data, width, height } = frame;
1162
+ if (width < 32 || height < 32) return null;
1163
+ const qualifies = new Array(height).fill(false);
1164
+ const density = new Float32Array(height);
1165
+ const minX = new Int32Array(height).fill(width);
1166
+ const maxX = new Int32Array(height).fill(-1);
1167
+ const bucketWidth = width / COLUMN_BUCKETS;
1168
+ const buckets = new Array(COLUMN_BUCKETS);
1169
+ for (let y2 = 0; y2 < height; y2++) {
1170
+ let edges = 0;
1171
+ buckets.fill(false);
1172
+ const rowOffset = y2 * width * 4;
1173
+ let previousLuma = 0.299 * (data[rowOffset] ?? 0) + 0.587 * (data[rowOffset + 1] ?? 0) + 0.114 * (data[rowOffset + 2] ?? 0);
1174
+ for (let x = 1; x < width; x++) {
1175
+ const i2 = rowOffset + x * 4;
1176
+ const luma = 0.299 * (data[i2] ?? 0) + 0.587 * (data[i2 + 1] ?? 0) + 0.114 * (data[i2 + 2] ?? 0);
1177
+ if (Math.abs(luma - previousLuma) >= t2.EDGE_LUMA_DELTA) {
1178
+ edges += 1;
1179
+ buckets[Math.min(COLUMN_BUCKETS - 1, Math.floor(x / bucketWidth))] = true;
1180
+ if (x < minX[y2]) minX[y2] = x;
1181
+ if (x > maxX[y2]) maxX[y2] = x;
1182
+ }
1183
+ previousLuma = luma;
1184
+ }
1185
+ density[y2] = edges / width;
1186
+ const coverage = buckets.filter(Boolean).length / COLUMN_BUCKETS;
1187
+ qualifies[y2] = density[y2] >= t2.MIN_ROW_DENSITY && coverage >= t2.MIN_COLUMN_COVERAGE && maxX[y2] - minX[y2] >= t2.MIN_WIDTH_FRAC * width;
1188
+ }
1189
+ let best = null;
1190
+ let runTop = -1;
1191
+ let lastQualifying = -1;
1192
+ let runRows = 0;
1193
+ const flush = (bottom) => {
1194
+ if (runTop < 0) return;
1195
+ const bandHeight = bottom - runTop + 1;
1196
+ if (bandHeight >= t2.MIN_HEIGHT_FRAC * height && bandHeight <= t2.MAX_HEIGHT_FRAC * height && runRows >= 4 && // at least a few real stroke rows, not a lone edge
1197
+ (best === null || runRows > best.rows)) {
1198
+ best = { top: runTop, bottom, rows: runRows };
1199
+ }
1200
+ runTop = -1;
1201
+ runRows = 0;
1202
+ };
1203
+ for (let y2 = 0; y2 < height; y2++) {
1204
+ if (qualifies[y2]) {
1205
+ if (runTop < 0) runTop = y2;
1206
+ else if (y2 - lastQualifying > t2.ROW_MERGE_GAP) {
1207
+ flush(lastQualifying);
1208
+ runTop = y2;
1209
+ }
1210
+ lastQualifying = y2;
1211
+ runRows += 1;
1212
+ }
1213
+ }
1214
+ flush(lastQualifying);
1215
+ if (best === null) return null;
1216
+ const band = best;
1217
+ let x1 = width;
1218
+ let x2 = -1;
1219
+ let densitySum = 0;
1220
+ let densityRows = 0;
1221
+ for (let y2 = band.top; y2 <= band.bottom; y2++) {
1222
+ if (!qualifies[y2]) continue;
1223
+ if (minX[y2] < x1) x1 = minX[y2];
1224
+ if (maxX[y2] > x2) x2 = maxX[y2];
1225
+ densitySum += density[y2];
1226
+ densityRows += 1;
1227
+ }
1228
+ if (x2 - x1 < t2.MIN_WIDTH_FRAC * width) return null;
1229
+ return {
1230
+ x: x1,
1231
+ y: band.top,
1232
+ width: x2 - x1,
1233
+ height: band.bottom - band.top + 1,
1234
+ density: densityRows > 0 ? densitySum / densityRows : 0
1235
+ };
1236
+ }
1237
+
1238
+ // src/core/doc/frame-analysis.ts
1239
+ init_frame_quality();
1240
+ init_doc_catalog();
1241
+ init_doc_gate_v1();
1242
+ var DOC_ANALYSIS_DEFAULTS = Object.freeze({
1243
+ /** Doc area fraction above which the camera is too close (capture would crop). */
1244
+ MAX_AREA_FRAC: 0.92,
1245
+ /** Opposite-side length ratio beyond which the view is too oblique. */
1246
+ TILT_MAX_SIDE_RATIO: 1.3,
1247
+ /** Specular-pixel fraction at/above which the frame reads as glare. */
1248
+ GLARE_MAX_SPECULAR_FRAC: 0.025
1249
+ });
1250
+ function specularFraction(crop) {
1251
+ const { data, width, height } = crop;
1252
+ const pixels = width * height;
1253
+ if (pixels === 0) return 0;
1254
+ let hot = 0;
1255
+ for (let i2 = 0; i2 < pixels; i2++) {
1256
+ const o2 = i2 * 4;
1257
+ const luma = 0.299 * (data[o2] ?? 0) + 0.587 * (data[o2 + 1] ?? 0) + 0.114 * (data[o2 + 2] ?? 0);
1258
+ if (luma >= 252) hot++;
1259
+ }
1260
+ return hot / pixels;
1261
+ }
1262
+ function quadTiltRatio(quad) {
1263
+ const len = (a2, b) => Math.hypot(b.x - a2.x, b.y - a2.y);
1264
+ const top = len(quad.topLeft, quad.topRight);
1265
+ const bottom = len(quad.bottomLeft, quad.bottomRight);
1266
+ const left = len(quad.topLeft, quad.bottomLeft);
1267
+ const right = len(quad.topRight, quad.bottomRight);
1268
+ const h2 = Math.max(top, bottom) / Math.max(1e-6, Math.min(top, bottom));
1269
+ const v = Math.max(left, right) / Math.max(1e-6, Math.min(left, right));
1270
+ return Math.max(h2, v);
1271
+ }
1272
+ function analyzeDocFrame(input) {
1273
+ const t2 = { ...DOC_GATE_V1_DEFAULTS, ...input.thresholds };
1274
+ const a2 = DOC_ANALYSIS_DEFAULTS;
1275
+ const { quad, frameWidth, frameHeight, measures } = input;
1276
+ const bandMode = input.format === "ID-3";
1277
+ let framing = "ok";
1278
+ if (quad === null) {
1279
+ framing = "no_document";
1280
+ } else if (bandMode) {
1281
+ const bounds = quadBounds(quad);
1282
+ const widthFrac = frameWidth > 0 ? bounds.width / frameWidth : 0;
1283
+ const aspect = bounds.height > 0 ? bounds.width / bounds.height : 0;
1284
+ if (widthFrac < t2.ID3_BAND_MIN_WIDTH_FRAC) framing = "too_far";
1285
+ else if (edgeClipped(quad, frameWidth, frameHeight, t2.EDGE_CLIP_MARGIN_PX)) {
1286
+ framing = "edge_clipped";
1287
+ } else if (aspect < t2.ID3_BAND_ASPECT_MIN || aspect > t2.ID3_BAND_ASPECT_MAX) {
1288
+ framing = "wrong_shape";
1289
+ }
1290
+ } else {
1291
+ const areaFrac = quadAreaFrac(quad, frameWidth, frameHeight);
1292
+ const band = aspectBand(input.format);
1293
+ const bounds = quadBounds(quad);
1294
+ const aspect = Math.max(bounds.width, bounds.height) / Math.max(1e-6, Math.min(bounds.width, bounds.height));
1295
+ if (areaFrac < t2.MIN_AREA_FRAC) framing = "too_far";
1296
+ else if (areaFrac > a2.MAX_AREA_FRAC) framing = "too_close";
1297
+ else if (edgeClipped(quad, frameWidth, frameHeight, t2.EDGE_CLIP_MARGIN_PX)) {
1298
+ framing = "edge_clipped";
1299
+ } else if (Math.abs(aspect - band.center) > band.tolerance) framing = "wrong_shape";
1300
+ else if (quadTiltRatio(quad) > a2.TILT_MAX_SIDE_RATIO) framing = "tilted";
1301
+ }
1302
+ const lighting = measures.exposure >= t2.GUIDE_EXPOSURE ? "ok" : measures.meanLuma < (EXPOSURE_BAND[0] + EXPOSURE_BAND[1]) / 2 ? "too_dark" : "too_bright";
1303
+ const blur = measures.sharpness >= t2.GUIDE_SHARPNESS ? "ok" : "blurry";
1304
+ const glare = measures.specularFraction >= a2.GLARE_MAX_SPECULAR_FRAC ? "glare" : "ok";
1305
+ return {
1306
+ framing,
1307
+ lighting,
1308
+ blur,
1309
+ glare,
1310
+ acceptable: framing === "ok" && lighting === "ok" && blur === "ok" && glare === "ok"
1311
+ };
1312
+ }
1313
+ function edgeClipped(quad, frameWidth, frameHeight, margin) {
1314
+ const pts = [quad.topLeft, quad.topRight, quad.bottomRight, quad.bottomLeft];
1315
+ return pts.some(
1316
+ (p2) => p2.x <= margin || p2.y <= margin || p2.x >= frameWidth - margin || p2.y >= frameHeight - margin
1317
+ );
1318
+ }
1319
+
1320
+ // src/core/doc/feedback-aggregator.ts
1321
+ var DOC_FEEDBACK_STATES = Object.freeze({
1322
+ sensing: { key: "sensing", reticle: "searching", minDurationMs: 900 },
1323
+ too_far: { key: "too_far", reticle: "coaching", minDurationMs: 1400 },
1324
+ too_close: { key: "too_close", reticle: "coaching", minDurationMs: 1400 },
1325
+ edge_clipped: { key: "edge_clipped", reticle: "coaching", minDurationMs: 1400 },
1326
+ wrong_shape: { key: "wrong_shape", reticle: "coaching", minDurationMs: 1400 },
1327
+ tilted: { key: "tilted", reticle: "coaching", minDurationMs: 1400 },
1328
+ too_dark: { key: "too_dark", reticle: "coaching", minDurationMs: 1400 },
1329
+ too_bright: { key: "too_bright", reticle: "coaching", minDurationMs: 1400 },
1330
+ blurry: { key: "blurry", reticle: "coaching", minDurationMs: 1400 },
1331
+ glare: { key: "glare", reticle: "coaching", minDurationMs: 1400 },
1332
+ hold_still: { key: "hold_still", reticle: "locking", minDurationMs: 900 },
1333
+ processing: { key: "processing", reticle: "processing", minDurationMs: 800 },
1334
+ side_captured: { key: "side_captured", reticle: "flip", minDurationMs: 2600 },
1335
+ captured: { key: "captured", reticle: "done", minDurationMs: 800 }
1336
+ });
1337
+ function feedbackVoteOf(analysis) {
1338
+ if (analysis.framing === "no_document") return "sensing";
1339
+ if (analysis.framing === "too_far") return "too_far";
1340
+ if (analysis.framing === "too_close") return "too_close";
1341
+ if (analysis.framing === "edge_clipped") return "edge_clipped";
1342
+ if (analysis.framing === "wrong_shape") return "wrong_shape";
1343
+ if (analysis.framing === "tilted") return "tilted";
1344
+ if (analysis.lighting === "too_dark") return "too_dark";
1345
+ if (analysis.lighting === "too_bright") return "too_bright";
1346
+ if (analysis.glare === "glare") return "glare";
1347
+ if (analysis.blur === "blurry") return "blurry";
1348
+ return "hold_still";
1349
+ }
1350
+ var DocFeedbackAggregator = class {
1351
+ constructor(windowMs = 2600, decayPerSecond = 0.35) {
1352
+ this.windowMs = windowMs;
1353
+ this.decayPerSecond = decayPerSecond;
1354
+ this.votes = [];
1355
+ this.current = DOC_FEEDBACK_STATES.sensing;
1356
+ this.currentSinceMs = null;
1357
+ }
1358
+ reset() {
1359
+ this.votes = [];
1360
+ this.current = DOC_FEEDBACK_STATES.sensing;
1361
+ this.currentSinceMs = null;
1362
+ }
1363
+ /** Force a terminal/choreography state (capture fired, side flip, upload). */
1364
+ force(key, nowMs) {
1365
+ this.votes = [];
1366
+ this.current = DOC_FEEDBACK_STATES[key];
1367
+ this.currentSinceMs = nowMs;
1368
+ return this.current;
1369
+ }
1370
+ /** Cast this frame's vote and return the (possibly held) winning state. */
1371
+ tick(vote, nowMs) {
1372
+ if (this.currentSinceMs === null) this.currentSinceMs = nowMs;
1373
+ this.votes.push({ key: vote, atMs: nowMs });
1374
+ this.votes = this.votes.filter((v) => nowMs - v.atMs <= this.windowMs);
1375
+ if (nowMs - this.currentSinceMs < this.current.minDurationMs) return this.current;
1376
+ const scores = /* @__PURE__ */ new Map();
1377
+ for (const v of this.votes) {
1378
+ const ageSeconds = (nowMs - v.atMs) / 1e3;
1379
+ const weight = this.decayPerSecond ** ageSeconds;
1380
+ scores.set(v.key, (scores.get(v.key) ?? 0) + weight);
1381
+ }
1382
+ let winner = this.current.key;
1383
+ let best = -1;
1384
+ for (const [key, score] of scores) {
1385
+ if (score > best) {
1386
+ best = score;
1387
+ winner = key;
1388
+ }
1389
+ }
1390
+ if (winner !== this.current.key) {
1391
+ this.current = DOC_FEEDBACK_STATES[winner];
1392
+ this.currentSinceMs = nowMs;
1393
+ }
1394
+ return this.current;
1395
+ }
1396
+ };
1397
+
1398
+ // src/core/media.ts
1399
+ var MIME_CANDIDATES = [
1400
+ "video/mp4;codecs=avc1.42E01E,mp4a.40.2",
1401
+ "video/mp4;codecs=avc1.42E01E",
1402
+ "video/mp4",
1403
+ "video/webm;codecs=vp9,opus",
1404
+ "video/webm;codecs=vp9",
1405
+ "video/webm;codecs=vp8,opus",
1406
+ "video/webm;codecs=vp8",
1407
+ "video/webm"
1408
+ ];
1409
+ function pickMimeType() {
1410
+ const MR = globalThis.MediaRecorder;
1411
+ if (!MR || typeof MR.isTypeSupported !== "function") return "";
1412
+ return MIME_CANDIDATES.find((t2) => MR.isTypeSupported(t2)) ?? "";
1413
+ }
1414
+ var DEFAULT_CLIP_MIME = "video/webm";
1415
+ function mapGetUserMediaError(err) {
1416
+ if (err instanceof TypeError) return "insecure";
1417
+ const name = err?.name ?? "";
1418
+ switch (name) {
1419
+ case "NotAllowedError":
1420
+ case "PermissionDeniedError":
1421
+ return "permission";
1422
+ case "NotFoundError":
1423
+ case "DevicesNotFoundError":
1424
+ return "notfound";
1425
+ case "NotReadableError":
1426
+ case "TrackStartError":
1427
+ return "inuse";
1428
+ case "OverconstrainedError":
1429
+ case "ConstraintNotSatisfiedError":
1430
+ return "overconstrained";
1431
+ default:
1432
+ return "generic";
1433
+ }
1434
+ }
1435
+ function cameraPreflight() {
1436
+ const w2 = globalThis;
1437
+ if (typeof w2.window !== "undefined" && w2.window.isSecureContext === false)
1438
+ return "INSECURE_CONTEXT";
1439
+ const md = w2.navigator?.mediaDevices;
1440
+ if (!md || typeof md.getUserMedia !== "function") return "UNSUPPORTED";
1441
+ return "OK";
1442
+ }
1443
+ function isMediaRecorderSupported() {
1444
+ const MR = globalThis.MediaRecorder;
1445
+ return typeof MR !== "undefined" && typeof MR.isTypeSupported === "function";
1446
+ }
1447
+ var MAX_CLIP_BYTES = 8 * 1024 * 1024;
1448
+ function isClipTooLarge(blob) {
1449
+ return blob.size > MAX_CLIP_BYTES;
1450
+ }
1451
+
1452
+ // src/core/v3/device-profile.ts
1453
+ var DEVICE_PROFILES = Object.freeze({
1454
+ LOW: Object.freeze({ cadenceHz: 5, inputWidth: 128, animations: "reduced" }),
1455
+ MID: Object.freeze({ cadenceHz: 8, inputWidth: 160, animations: "full" }),
1456
+ HIGH: Object.freeze({ cadenceHz: 10, inputWidth: 192, animations: "full" })
1457
+ });
1458
+ var SIMD_TEST_BYTES = new Uint8Array([
1459
+ 0,
1460
+ 97,
1461
+ 115,
1462
+ 109,
1463
+ 1,
1464
+ 0,
1465
+ 0,
1466
+ 0,
1467
+ 1,
1468
+ 5,
1469
+ 1,
1470
+ 96,
1471
+ 0,
1472
+ 1,
1473
+ 123,
1474
+ 3,
1475
+ 2,
1476
+ 1,
1477
+ 0,
1478
+ 10,
1479
+ 10,
1480
+ 1,
1481
+ 8,
1482
+ 0,
1483
+ 65,
1484
+ 0,
1485
+ 253,
1486
+ 15,
1487
+ 253,
1488
+ 98,
1489
+ 11
1490
+ ]);
1491
+ function probeDevice() {
1492
+ const nav = typeof navigator === "undefined" ? void 0 : navigator;
1493
+ let simd = false;
1494
+ try {
1495
+ simd = typeof WebAssembly !== "undefined" && WebAssembly.validate(SIMD_TEST_BYTES);
1496
+ } catch {
1497
+ simd = false;
1498
+ }
1499
+ return {
1500
+ cores: nav?.hardwareConcurrency ?? 2,
1501
+ memGB: nav?.deviceMemory ?? null,
1502
+ simd
1503
+ };
1504
+ }
1505
+ function classifyDevice(probe) {
1506
+ const memGB = probe.memGB ?? 4;
1507
+ if (probe.cores < 4 || memGB < 3) return "LOW";
1508
+ if (probe.cores >= 8 && memGB >= 6) return "HIGH";
1509
+ return "MID";
1510
+ }
1511
+ var ORDER = ["LOW", "MID", "HIGH"];
1512
+ var DeviceProfiler = class {
1513
+ constructor(initial) {
1514
+ this.samples = [];
1515
+ this.adjusted = false;
1516
+ this.current = initial;
1517
+ }
1518
+ get deviceClass() {
1519
+ return this.current;
1520
+ }
1521
+ get profile() {
1522
+ return DEVICE_PROFILES[this.current];
1523
+ }
1524
+ record(detectMs) {
1525
+ if (this.adjusted || this.samples.length >= 10) return this.current;
1526
+ this.samples.push(detectMs);
1527
+ if (this.samples.length < 10) return this.current;
1528
+ this.adjusted = true;
1529
+ const mean = this.samples.reduce((sum, value) => sum + value, 0) / this.samples.length;
1530
+ if (mean > 70) {
1531
+ this.current = "LOW";
1532
+ } else if (mean < 25) {
1533
+ const index = ORDER.indexOf(this.current);
1534
+ this.current = ORDER[Math.min(ORDER.length - 1, index + 1)] ?? this.current;
1535
+ }
1536
+ return this.current;
1537
+ }
1538
+ };
1539
+
1540
+ // src/core/doc/capture-session-doc.ts
1541
+ init_frame_quality();
1542
+ init_doc_gate_v1();
1543
+ var scanicDetect = null;
1544
+ async function lazyScanicDetect(image) {
1545
+ if (scanicDetect === null) {
1546
+ const module_ = await Promise.resolve().then(() => (init_detector_scanic(), detector_scanic_exports));
1547
+ scanicDetect = module_.detectQuad;
1548
+ }
1549
+ return scanicDetect(image);
1550
+ }
1551
+ async function mrzBandDetect(image) {
1552
+ const band = detectMrzBand(image);
1553
+ if (band === null) return null;
1554
+ return {
1555
+ topLeft: { x: band.x, y: band.y },
1556
+ topRight: { x: band.x + band.width, y: band.y },
1557
+ bottomRight: { x: band.x + band.width, y: band.y + band.height },
1558
+ bottomLeft: { x: band.x, y: band.y + band.height }
1559
+ };
1560
+ }
1561
+ function warmDocDetector() {
1562
+ if (scanicDetect !== null) return;
1563
+ void Promise.resolve().then(() => (init_detector_scanic(), detector_scanic_exports)).then((module_) => {
1564
+ scanicDetect = module_.detectQuad;
1565
+ }).catch(() => void 0);
1566
+ }
1567
+ var DOC_CADENCE_HZ = Object.freeze({
1568
+ LOW: 3,
1569
+ MID: 5,
1570
+ HIGH: 6
1571
+ });
1572
+ var CaptureSessionDoc = class {
1573
+ constructor(opts) {
1574
+ this.handlers = /* @__PURE__ */ new Map();
1575
+ this.stream = null;
1576
+ this.timer = null;
1577
+ this.state = "idle";
1578
+ this.lastGuidance = null;
1579
+ this.attempt = 0;
1580
+ this.capturing = false;
1581
+ this.feedback = new DocFeedbackAggregator();
1582
+ this.lastFeedbackKey = null;
1583
+ this.opts = opts;
1584
+ this.gate = new DocGateV1(opts.format ?? "ID-1", opts.thresholds);
1585
+ const deviceClass = opts.deviceClass ?? classifyDevice(probeDevice());
1586
+ this.cadenceMs = 1e3 / DOC_CADENCE_HZ[deviceClass];
1587
+ }
1588
+ on(event, handler) {
1589
+ let set = this.handlers.get(event);
1590
+ if (!set) {
1591
+ set = /* @__PURE__ */ new Set();
1592
+ this.handlers.set(event, set);
1593
+ }
1594
+ set.add(handler);
1595
+ return () => set?.delete(handler);
1596
+ }
1597
+ emit(event, payload) {
1598
+ for (const handler of [...this.handlers.get(event) ?? []]) {
1599
+ handler(payload);
1600
+ }
1601
+ }
1602
+ async start() {
1603
+ const attempt = ++this.attempt;
1604
+ this.gate.reset();
1605
+ this.feedback.reset();
1606
+ this.lastFeedbackKey = null;
1607
+ this.lastGuidance = null;
1608
+ this.capturing = false;
1609
+ this.setState("preflight");
1610
+ try {
1611
+ const getUserMedia = this.opts.getUserMedia ?? ((constraints) => navigator.mediaDevices.getUserMedia(constraints));
1612
+ this.setState("acquiring");
1613
+ this.stream = await getUserMedia({
1614
+ audio: false,
1615
+ video: {
1616
+ facingMode: { ideal: "environment" },
1617
+ width: { ideal: 1920 },
1618
+ height: { ideal: 1080 }
1619
+ }
1620
+ });
1621
+ if (attempt !== this.attempt) {
1622
+ for (const track of this.stream.getTracks()) track.stop();
1623
+ return;
1624
+ }
1625
+ this.opts.video.srcObject = this.stream;
1626
+ await this.opts.video.play().catch(() => void 0);
1627
+ this.setState("positioning");
1628
+ this.scheduleTick(attempt);
1629
+ } catch (err) {
1630
+ const kind = mapGetUserMediaError(err);
1631
+ this.setState("error");
1632
+ this.emit("error", { kind, retryable: true });
1633
+ }
1634
+ }
1635
+ /** Restart the gate for another side / a retake (same stream). */
1636
+ rearm(side) {
1637
+ if (side !== void 0) this.opts.side = side;
1638
+ this.gate.reset();
1639
+ this.feedback.reset();
1640
+ this.lastFeedbackKey = null;
1641
+ this.lastGuidance = null;
1642
+ this.capturing = false;
1643
+ if (this.state === "captured") {
1644
+ this.setState("positioning");
1645
+ this.scheduleTick(this.attempt);
1646
+ }
1647
+ }
1648
+ destroy() {
1649
+ this.attempt += 1;
1650
+ if (this.timer !== null) (this.opts.clearTimer ?? clearTimeout)(this.timer);
1651
+ this.timer = null;
1652
+ if (this.stream) for (const track of this.stream.getTracks()) track.stop();
1653
+ this.stream = null;
1654
+ this.opts.video.srcObject = null;
1655
+ }
1656
+ setState(state) {
1657
+ this.state = state;
1658
+ this.emit("statechange", { state });
1659
+ }
1660
+ scheduleTick(attempt) {
1661
+ const setTimer = this.opts.setTimer ?? setTimeout;
1662
+ this.timer = setTimer(() => void this.tick(attempt), this.cadenceMs);
1663
+ }
1664
+ async tick(attempt) {
1665
+ if (attempt !== this.attempt || this.state !== "positioning" || this.capturing) return;
1666
+ const now = this.opts.now ?? (() => performance.now());
1667
+ const grab = this.opts.grabDetectFrame ?? defaultGrabDetectFrame;
1668
+ const detect = this.opts.detect ?? ((this.opts.format ?? "ID-1") === "ID-3" ? mrzBandDetect : lazyScanicDetect);
1669
+ const frame = grab(this.opts.video, DOC_DETECT_WIDTH);
1670
+ if (frame === null) {
1671
+ this.scheduleTick(attempt);
1672
+ return;
1673
+ }
1674
+ let quad = null;
1675
+ try {
1676
+ quad = await detect(frame);
1677
+ } catch {
1678
+ quad = null;
1679
+ }
1680
+ if (attempt !== this.attempt) return;
1681
+ const crop = quad !== null ? cropQuadRegion(frame, quad) : frame;
1682
+ const atMs = now();
1683
+ const measures = {
1684
+ sharpness: sharpness(crop),
1685
+ exposure: exposure(crop),
1686
+ meanLuma: meanLuma(crop),
1687
+ specularFraction: specularFraction(crop)
1688
+ };
1689
+ const analysis = analyzeDocFrame({
1690
+ format: this.opts.format ?? "ID-1",
1691
+ quad,
1692
+ frameWidth: frame.width,
1693
+ frameHeight: frame.height,
1694
+ measures,
1695
+ ...this.opts.thresholds !== void 0 ? { thresholds: this.opts.thresholds } : {}
1696
+ });
1697
+ const tick = this.gate.tick({
1698
+ timestampMs: atMs,
1699
+ quad,
1700
+ quality: measures,
1701
+ frameWidth: frame.width,
1702
+ frameHeight: frame.height
1703
+ });
1704
+ this.emit("checks", {
1705
+ engine: "docv1",
1706
+ p: tick.p,
1707
+ plausible: tick.plausible,
1708
+ stableTicks: tick.stableTicks,
1709
+ quad: tick.quad,
1710
+ frameWidth: frame.width,
1711
+ frameHeight: frame.height,
1712
+ analysis
1713
+ });
1714
+ const feedbackState = this.feedback.tick(feedbackVoteOf(analysis), atMs);
1715
+ if (feedbackState.key !== this.lastFeedbackKey) {
1716
+ this.lastFeedbackKey = feedbackState.key;
1717
+ this.emit("feedback", feedbackState);
1718
+ }
1719
+ if (tick.guidanceKey !== this.lastGuidance) {
1720
+ this.lastGuidance = tick.guidanceKey;
1721
+ this.emit("guidance", { key: tick.guidanceKey });
1722
+ }
1723
+ if (tick.ready && quad !== null) {
1724
+ const processing = this.feedback.force("processing", atMs);
1725
+ this.lastFeedbackKey = processing.key;
1726
+ this.emit("feedback", processing);
1727
+ await this.fire(attempt, quad, {
1728
+ width: frame.width,
1729
+ height: frame.height,
1730
+ tickSharpness: measures.sharpness
1731
+ });
1732
+ return;
1733
+ }
1734
+ this.scheduleTick(attempt);
1735
+ }
1736
+ /**
1737
+ * BEST-FRAME capture window (capture-v2): the first ready tick captures a
1738
+ * candidate immediately, then up to CAPTURE_EXTRA_CANDIDATES more stills are
1739
+ * taken at CAPTURE_CANDIDATE_SPACING_MS while the user holds — each scored
1740
+ * by the live detect-tick sharpness at its capture moment — and the SHARPEST
1741
+ * wins. Beats first-acceptable-frame capture without decoding stills.
1742
+ */
1743
+ async fire(attempt, quad, detectSize) {
1744
+ this.capturing = true;
1745
+ const capture = this.opts.captureStill ?? defaultCaptureStill;
1746
+ const grab = this.opts.grabDetectFrame ?? defaultGrabDetectFrame;
1747
+ const setTimer = this.opts.setTimer ?? setTimeout;
1748
+ const size = { width: detectSize.width, height: detectSize.height };
1749
+ try {
1750
+ let best = {
1751
+ still: await capture(this.opts.video, quad, size),
1752
+ sharpness: detectSize.tickSharpness
1753
+ };
1754
+ for (let i2 = 0; i2 < CAPTURE_EXTRA_CANDIDATES; i2++) {
1755
+ await new Promise((resolve) => {
1756
+ setTimer(() => resolve(), CAPTURE_CANDIDATE_SPACING_MS);
1757
+ });
1758
+ if (attempt !== this.attempt) return;
1759
+ const frame = grab(this.opts.video, DOC_DETECT_WIDTH);
1760
+ if (frame === null) continue;
1761
+ const candidateSharpness = sharpness(cropQuadRegion(frame, quad));
1762
+ if (candidateSharpness > best.sharpness * CAPTURE_IMPROVEMENT_MIN_RATIO) {
1763
+ const still = await capture(this.opts.video, quad, size);
1764
+ if (attempt !== this.attempt) return;
1765
+ best = { still, sharpness: candidateSharpness };
1766
+ }
1767
+ }
1768
+ if (attempt !== this.attempt) return;
1769
+ this.setState("captured");
1770
+ this.emit("artifacts", {
1771
+ keyframe: best.still.blob,
1772
+ previewDataUrl: best.still.previewDataUrl,
1773
+ ...this.opts.side !== void 0 ? { side: this.opts.side } : {}
1774
+ });
1775
+ } catch {
1776
+ if (attempt !== this.attempt) return;
1777
+ this.capturing = false;
1778
+ this.gate.reset();
1779
+ this.scheduleTick(attempt);
1780
+ }
1781
+ }
1782
+ };
1783
+ var CAPTURE_EXTRA_CANDIDATES = 2;
1784
+ var CAPTURE_CANDIDATE_SPACING_MS = 260;
1785
+ var CAPTURE_IMPROVEMENT_MIN_RATIO = 1.08;
1786
+ function defaultGrabDetectFrame(video, targetWidth) {
1787
+ const vw = video.videoWidth;
1788
+ const vh = video.videoHeight;
1789
+ if (vw === 0 || vh === 0) return null;
1790
+ const scale = Math.min(1, targetWidth / vw);
1791
+ const width = Math.round(vw * scale);
1792
+ const height = Math.round(vh * scale);
1793
+ const canvas = document.createElement("canvas");
1794
+ canvas.width = width;
1795
+ canvas.height = height;
1796
+ const context = canvas.getContext("2d", { willReadFrequently: true });
1797
+ if (context === null) return null;
1798
+ context.drawImage(video, 0, 0, width, height);
1799
+ return context.getImageData(0, 0, width, height);
1800
+ }
1801
+ async function defaultCaptureStill(video, _quad, _detectSize) {
1802
+ const canvas = document.createElement("canvas");
1803
+ canvas.width = Math.max(1, video.videoWidth);
1804
+ canvas.height = Math.max(1, video.videoHeight);
1805
+ const context = canvas.getContext("2d");
1806
+ if (context === null) throw new Error("2d context unavailable");
1807
+ context.drawImage(video, 0, 0, canvas.width, canvas.height);
1808
+ const blob = await new Promise((resolve, reject) => {
1809
+ canvas.toBlob((b) => b ? resolve(b) : reject(new Error("toBlob failed")), "image/jpeg", 0.92);
1810
+ });
1811
+ return { blob, previewDataUrl: canvas.toDataURL("image/jpeg", 0.85) };
1812
+ }
1813
+ function cropQuadRegion(frame, quad) {
1814
+ const xs = [quad.topLeft.x, quad.topRight.x, quad.bottomRight.x, quad.bottomLeft.x];
1815
+ const ys = [quad.topLeft.y, quad.topRight.y, quad.bottomRight.y, quad.bottomLeft.y];
1816
+ const x1 = Math.max(0, Math.floor(Math.min(...xs)));
1817
+ const y1 = Math.max(0, Math.floor(Math.min(...ys)));
1818
+ const x2 = Math.min(frame.width, Math.ceil(Math.max(...xs)));
1819
+ const y2 = Math.min(frame.height, Math.ceil(Math.max(...ys)));
1820
+ const width = Math.max(1, x2 - x1);
1821
+ const height = Math.max(1, y2 - y1);
1822
+ const data = new Uint8ClampedArray(width * height * 4);
1823
+ for (let row = 0; row < height; row++) {
1824
+ const src = ((y1 + row) * frame.width + x1) * 4;
1825
+ data.set(frame.data.subarray(src, src + width * 4), row * width * 4);
1826
+ }
1827
+ return { data, width, height, colorSpace: frame.colorSpace };
1828
+ }
1829
+
1830
+ // src/core/capture-constraints.ts
1831
+ function buildCaptureConstraints(isMobile, facingMode) {
1832
+ void isMobile;
1833
+ return {
1834
+ video: {
1835
+ width: { ideal: 1280, max: 1280 },
1836
+ height: { ideal: 720, max: 720 },
1837
+ facingMode,
1838
+ frameRate: { ideal: 24, max: 30 }
1839
+ },
1840
+ audio: false
1841
+ };
1842
+ }
1843
+ function detectIsMobile() {
1844
+ if (typeof window === "undefined" || typeof navigator === "undefined") return false;
1845
+ return window.innerWidth <= 768 || /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
1846
+ String(navigator.userAgent ?? "")
1847
+ );
1848
+ }
1849
+ var CIRCLE_RADIUS_FACTOR = 0.45;
1850
+ var IN_CIRCLE_FACTOR = 0.9;
1851
+ var CENTERED_FACTOR = 0.4;
1852
+
1853
+ // src/core/clip-recorder.ts
1854
+ var CLIP_MS = 2500;
1855
+ var TIMESLICE_MS = 1e3;
1856
+ var STOP_GRACE_MS = 1500;
1857
+ var VIDEO_BPS = 25e5;
1858
+ var ClipError = class extends Error {
1859
+ constructor(kind, msg) {
1860
+ super(msg ?? kind);
1861
+ this.kind = kind;
1862
+ }
1863
+ };
1864
+ var ClipRecorder = class {
1865
+ constructor() {
1866
+ this.recorder = null;
1867
+ this.stream = null;
1868
+ // own field so teardown can stop tracks (REVIEW FIX 8)
1869
+ this.chunks = [];
1870
+ this.bytes = 0;
1871
+ this.hardStopTimer = null;
1872
+ this.graceTimer = null;
1873
+ this.settled = false;
1874
+ }
1875
+ clearTimers() {
1876
+ if (this.hardStopTimer) clearTimeout(this.hardStopTimer);
1877
+ if (this.graceTimer) clearTimeout(this.graceTimer);
1878
+ this.hardStopTimer = null;
1879
+ this.graceTimer = null;
1880
+ }
1881
+ /** Records CLIP_MS of the stream. Resolves with the clip blob + its container mime;
1882
+ * rejects with ClipError. Behavior contract is the v1 hook's `start`, verbatim
1883
+ * (iOS workarounds included).
1884
+ *
1885
+ * ONE RECORDING AT A TIME: chunk/byte/timer state is shared per instance, so a
1886
+ * second record() while one is in flight rejects ClipError("generic") instead of
1887
+ * corrupting the in-flight clip. (v2 guard — v1's hook was gated by its owning
1888
+ * component; a class API invites reuse. Zero impact on clip bytes.)
1889
+ *
1890
+ * `onStopped` (optional) fires ONCE the moment the CLIP_MS recording window
1891
+ * elapses (the hard-stop), BEFORE finalize — which on iOS can lag up to
1892
+ * STOP_GRACE_MS while onstop flushes the last chunk. It lets the host freeze
1893
+ * the display on the already-captured keyframe the instant recording ends,
1894
+ * instead of waiting for the blob. PURE NOTIFICATION — it does not touch
1895
+ * timers, chunks, or the finalize path, so it is calibration-neutral (no
1896
+ * effect on clip bytes). Never fires on a rejected capture (error /
1897
+ * cliptoolarge settle before the hard-stop and clear the timer). */
1898
+ record(stream, onStopped) {
1899
+ if (this.recorder && !this.settled) {
1900
+ return Promise.reject(
1901
+ new ClipError(
1902
+ "generic",
1903
+ "record() called while a recording is in flight \u2014 ClipRecorder handles one recording at a time"
1904
+ )
1905
+ );
1906
+ }
1907
+ this.recorder = null;
1908
+ this.clearTimers();
1909
+ this.chunks = [];
1910
+ this.bytes = 0;
1911
+ this.settled = false;
1912
+ this.stream = stream;
1913
+ const picked = pickMimeType();
1914
+ return new Promise((resolve, reject) => {
1915
+ let recorder;
1916
+ try {
1917
+ recorder = new MediaRecorder(
1918
+ stream,
1919
+ picked ? { mimeType: picked, videoBitsPerSecond: VIDEO_BPS } : { videoBitsPerSecond: VIDEO_BPS }
1920
+ );
1921
+ } catch {
1922
+ try {
1923
+ recorder = new MediaRecorder(stream);
1924
+ } catch {
1925
+ reject(new ClipError("unsupported"));
1926
+ return;
1927
+ }
1928
+ }
1929
+ this.recorder = recorder;
1930
+ const settle = (fn) => {
1931
+ if (this.settled) return;
1932
+ this.settled = true;
1933
+ this.clearTimers();
1934
+ fn();
1935
+ };
1936
+ const finalize = () => settle(() => {
1937
+ const type = recorder.mimeType || picked || DEFAULT_CLIP_MIME;
1938
+ const blob = new Blob(this.chunks, { type });
1939
+ if (isClipTooLarge(blob)) {
1940
+ reject(new ClipError("cliptoolarge"));
1941
+ return;
1942
+ }
1943
+ resolve({ blob, mimeType: type });
1944
+ });
1945
+ recorder.ondataavailable = (e2) => {
1946
+ if (e2.data && e2.data.size) {
1947
+ this.chunks.push(e2.data);
1948
+ this.bytes += e2.data.size;
1949
+ if (this.bytes > MAX_CLIP_BYTES) {
1950
+ settle(() => {
1951
+ try {
1952
+ if (recorder.state !== "inactive") recorder.stop();
1953
+ } catch {
1954
+ }
1955
+ reject(new ClipError("cliptoolarge"));
1956
+ });
1957
+ }
1958
+ }
1959
+ };
1960
+ recorder.onstop = finalize;
1961
+ recorder.onerror = () => settle(() => reject(new ClipError("generic")));
1962
+ try {
1963
+ recorder.start(TIMESLICE_MS);
1964
+ } catch {
1965
+ settle(() => reject(new ClipError("generic")));
1966
+ return;
1967
+ }
1968
+ this.hardStopTimer = setTimeout(() => {
1969
+ if (!this.settled) onStopped?.();
1970
+ if (recorder.state !== "inactive") {
1971
+ try {
1972
+ recorder.stop();
1973
+ } catch {
1974
+ finalize();
1975
+ }
1976
+ this.graceTimer = setTimeout(finalize, STOP_GRACE_MS);
1977
+ } else {
1978
+ finalize();
1979
+ }
1980
+ }, CLIP_MS);
1981
+ });
1982
+ }
1983
+ /** Idempotent teardown: stop recorder + ALL tracks (v1 `stopAndCleanup` + the unmount
1984
+ * effect). Optional `stream` override mirrors v1's `stopAndCleanup(stream?)`.
1985
+ *
1986
+ * MID-RECORDING SEMANTICS (verbatim v1): calling stop() while a record() is in
1987
+ * flight may LATER resolve the pending promise with a TRUNCATED clip (recorder.stop()
1988
+ * fires onstop → finalize from whatever chunks arrived so far), or — because this
1989
+ * method clears the hard-stop/grace timers — never settle it at all if onstop never
1990
+ * fires (the iOS grace path has been torn down). Callers MUST NOT treat a resolution
1991
+ * arriving after stop() as a full CLIP_MS clip, and must not await a record()
1992
+ * promise past stop() without their own timeout. (Task 4's CaptureSession owns
1993
+ * sequencing on top of this contract.) */
1994
+ stop(stream) {
1995
+ this.clearTimers();
1996
+ const rec = this.recorder;
1997
+ if (rec && rec.state !== "inactive") {
1998
+ try {
1999
+ rec.stop();
2000
+ } catch {
2001
+ }
2002
+ }
2003
+ this.recorder = null;
2004
+ const s2 = stream ?? this.stream;
2005
+ s2?.getTracks().forEach((t2) => t2.stop());
2006
+ this.stream = null;
2007
+ }
2008
+ };
2009
+
2010
+ // src/core/keyframe.ts
2011
+ function captureMirroredKeyframe(video, canvas, quality = 0.92) {
2012
+ return new Promise((resolve, reject) => {
2013
+ const w2 = video.videoWidth;
2014
+ const h2 = video.videoHeight;
2015
+ if (!w2 || !h2) {
2016
+ reject(new Error("video-not-ready"));
2017
+ return;
2018
+ }
2019
+ const ctx = canvas.getContext("2d");
2020
+ if (!ctx) {
2021
+ reject(new Error("no-2d-context"));
2022
+ return;
2023
+ }
2024
+ canvas.width = w2;
2025
+ canvas.height = h2;
2026
+ ctx.scale(-1, 1);
2027
+ ctx.drawImage(video, -w2, 0);
2028
+ canvas.toBlob(
2029
+ (blob) => blob ? resolve(blob) : reject(new Error("empty-keyframe")),
2030
+ "image/jpeg",
2031
+ quality
2032
+ );
2033
+ });
2034
+ }
2035
+
2036
+ // src/core/v3/detector-blaze.ts
2037
+ var BLAZE_INIT_TIMEOUT_MS = 1e4;
2038
+ var BlazeDetector = class _BlazeDetector {
2039
+ constructor(inner, fallbackReason) {
2040
+ this.tier = "blaze";
2041
+ this.inner = inner;
2042
+ if (fallbackReason !== void 0) this.fallbackReason = fallbackReason;
2043
+ }
2044
+ static async create(assetBaseUrl, fallbackReason) {
2045
+ const vision = await import("@mediapipe/tasks-vision");
2046
+ const fileset = await vision.FilesetResolver.forVisionTasks(assetBaseUrl);
2047
+ const inner = await vision.FaceDetector.createFromOptions(fileset, {
2048
+ baseOptions: {
2049
+ modelAssetPath: `${assetBaseUrl}/blaze_face_short_range.tflite`,
2050
+ // CPU delegate — the iOS-Safari-safe path (see header). NEVER 'GPU'.
2051
+ delegate: "CPU"
2052
+ },
2053
+ runningMode: "IMAGE"
2054
+ });
2055
+ return new _BlazeDetector(inner, fallbackReason);
2056
+ }
2057
+ async detect(source, sourceWidth, sourceHeight) {
2058
+ let detections;
2059
+ try {
2060
+ detections = this.inner.detect(source).detections;
2061
+ } catch {
2062
+ return null;
2063
+ }
2064
+ const best = pickMostConfident(detections);
2065
+ if (best?.boundingBox === void 0) return null;
2066
+ const size = intrinsicSize(source);
2067
+ const eyes = extractEyes(best.keypoints, size);
2068
+ const observation = {
2069
+ box: {
2070
+ x: best.boundingBox.originX,
2071
+ y: best.boundingBox.originY,
2072
+ width: best.boundingBox.width,
2073
+ height: best.boundingBox.height
2074
+ },
2075
+ ...eyes !== void 0 ? { eyes } : {},
2076
+ score: best.categories[0]?.score ?? 0
2077
+ };
2078
+ return toStreamPixels(observation, source, sourceWidth, sourceHeight);
2079
+ }
2080
+ destroy() {
2081
+ try {
2082
+ this.inner.close();
2083
+ } catch {
2084
+ }
2085
+ }
2086
+ };
2087
+ function pickMostConfident(detections) {
2088
+ let best;
2089
+ let bestScore = -1;
2090
+ for (const detection of detections) {
2091
+ const score = detection.categories[0]?.score ?? 0;
2092
+ if (score > bestScore) {
2093
+ best = detection;
2094
+ bestScore = score;
2095
+ }
2096
+ }
2097
+ return best;
2098
+ }
2099
+ function extractEyes(keypoints, size) {
2100
+ const a2 = keypoints?.[0];
2101
+ const b = keypoints?.[1];
2102
+ if (a2 === void 0 || b === void 0) return void 0;
2103
+ const toSource = (p2) => ({ x: p2.x * size.width, y: p2.y * size.height });
2104
+ const [pa, pb] = [toSource(a2), toSource(b)];
2105
+ return pa.x <= pb.x ? { left: pa, right: pb } : { left: pb, right: pa };
2106
+ }
2107
+
2108
+ // src/core/v3/detector-native.ts
2109
+ function smokeSource() {
2110
+ if (typeof OffscreenCanvas === "function") return new OffscreenCanvas(2, 2);
2111
+ const canvas = document.createElement("canvas");
2112
+ canvas.width = 2;
2113
+ canvas.height = 2;
2114
+ return canvas;
2115
+ }
2116
+ async function probeNativeDetector() {
2117
+ const ctor = globalThis.FaceDetector;
2118
+ if (typeof ctor !== "function") return { ok: false, reason: "unsupported" };
2119
+ try {
2120
+ const instance = new ctor({ fastMode: true, maxDetectedFaces: 1 });
2121
+ await instance.detect(smokeSource());
2122
+ return { ok: true, instance };
2123
+ } catch (err) {
2124
+ return { ok: false, reason: `smoke_failed:${err instanceof Error ? err.message : String(err)}` };
2125
+ }
2126
+ }
2127
+ var NativeDetector = class {
2128
+ constructor(inner, fallbackReason) {
2129
+ this.tier = "native";
2130
+ this.inner = inner;
2131
+ if (fallbackReason !== void 0) this.fallbackReason = fallbackReason;
2132
+ }
2133
+ async detect(source, sourceWidth, sourceHeight) {
2134
+ let faces;
2135
+ try {
2136
+ faces = await this.inner.detect(source);
2137
+ } catch {
2138
+ return null;
2139
+ }
2140
+ const face = faces[0];
2141
+ if (face === void 0) return null;
2142
+ const eyes = extractEyes2(face.landmarks);
2143
+ const observation = {
2144
+ box: {
2145
+ x: face.boundingBox.x,
2146
+ y: face.boundingBox.y,
2147
+ width: face.boundingBox.width,
2148
+ height: face.boundingBox.height
2149
+ },
2150
+ ...eyes !== void 0 ? { eyes } : {},
2151
+ // The Shape Detection API exposes no confidence — the smoke-tested
2152
+ // native tier treats any detection as confident.
2153
+ score: 1
2154
+ };
2155
+ return toStreamPixels(observation, source, sourceWidth, sourceHeight);
2156
+ }
2157
+ destroy() {
2158
+ }
2159
+ };
2160
+ function extractEyes2(landmarks) {
2161
+ if (landmarks === void 0) return void 0;
2162
+ const eyePoints = landmarks.filter((landmark) => landmark.type === "eye").map((landmark) => landmark.locations[0]).filter((point) => point !== void 0);
2163
+ const [a2, b] = eyePoints;
2164
+ if (a2 === void 0 || b === void 0) return void 0;
2165
+ return a2.x <= b.x ? { left: a2, right: b } : { left: b, right: a2 };
2166
+ }
2167
+
2168
+ // src/core/v3/detector.ts
2169
+ var DEFAULT_V3_ASSET_BASE_URL = "/models-v3";
2170
+ var DEFAULT_TIER_ORDER = ["native", "blaze"];
2171
+ var DetectorLadderError = class extends Error {
2172
+ constructor(fallbackReason) {
2173
+ super(`no detector tier available (${fallbackReason})`);
2174
+ this.name = "DetectorLadderError";
2175
+ this.fallbackReason = fallbackReason;
2176
+ }
2177
+ };
2178
+ function intrinsicSize(source) {
2179
+ const candidate = source;
2180
+ if (typeof candidate.videoWidth === "number" && candidate.videoWidth > 0) {
2181
+ return { width: candidate.videoWidth, height: candidate.videoHeight ?? 0 };
2182
+ }
2183
+ if (typeof candidate.naturalWidth === "number" && candidate.naturalWidth > 0) {
2184
+ return { width: candidate.naturalWidth, height: candidate.naturalHeight ?? 0 };
2185
+ }
2186
+ const width = typeof candidate.width === "number" ? candidate.width : 0;
2187
+ const height = typeof candidate.height === "number" ? candidate.height : 0;
2188
+ return { width, height };
2189
+ }
2190
+ function toStreamPixels(observation, source, streamWidth, streamHeight) {
2191
+ const size = intrinsicSize(source);
2192
+ const scaleX = size.width > 0 ? streamWidth / size.width : 1;
2193
+ const scaleY = size.height > 0 ? streamHeight / size.height : 1;
2194
+ const scalePoint = (p2) => ({ x: p2.x * scaleX, y: p2.y * scaleY });
2195
+ return {
2196
+ box: {
2197
+ x: observation.box.x * scaleX,
2198
+ y: observation.box.y * scaleY,
2199
+ width: observation.box.width * scaleX,
2200
+ height: observation.box.height * scaleY
2201
+ },
2202
+ ...observation.eyes !== void 0 ? { eyes: { left: scalePoint(observation.eyes.left), right: scalePoint(observation.eyes.right) } } : {},
2203
+ score: observation.score
2204
+ };
2205
+ }
2206
+ function describeError(err) {
2207
+ return err instanceof Error ? err.message : String(err);
2208
+ }
2209
+ async function createDetector(options) {
2210
+ const order = options.preferred ?? DEFAULT_TIER_ORDER;
2211
+ const reasons = [];
2212
+ for (const tier of order) {
2213
+ if (tier === "native") {
2214
+ const probed = await probeNativeDetector();
2215
+ if (probed.ok) {
2216
+ return new NativeDetector(probed.instance, reasonOf(reasons));
2217
+ }
2218
+ reasons.push(`native:${probed.reason}`);
2219
+ continue;
2220
+ }
2221
+ try {
2222
+ return await withTimeout(
2223
+ BlazeDetector.create(
2224
+ options.v3AssetBaseUrl ?? DEFAULT_V3_ASSET_BASE_URL,
2225
+ reasonOf(reasons)
2226
+ ),
2227
+ options.blazeInitTimeoutMs ?? BLAZE_INIT_TIMEOUT_MS
2228
+ );
2229
+ } catch (err) {
2230
+ reasons.push(
2231
+ err instanceof InitTimeoutError ? "blaze:blaze_init_timeout" : `blaze:${describeError(err)}`
2232
+ );
2233
+ }
2234
+ }
2235
+ throw new DetectorLadderError(reasonOf(reasons) ?? "no_tier_available");
2236
+ }
2237
+ function reasonOf(reasons) {
2238
+ return reasons.length > 0 ? reasons.join("; ") : void 0;
2239
+ }
2240
+ var InitTimeoutError = class extends Error {
2241
+ };
2242
+ function withTimeout(promise, deadlineMs) {
2243
+ return new Promise((resolvePromise, rejectPromise) => {
2244
+ const timer = setTimeout(() => {
2245
+ rejectPromise(new InitTimeoutError(`init exceeded ${deadlineMs}ms`));
2246
+ promise.then(
2247
+ (value) => value.destroy(),
2248
+ () => void 0
2249
+ );
2250
+ }, deadlineMs);
2251
+ promise.then(
2252
+ (value) => {
2253
+ clearTimeout(timer);
2254
+ resolvePromise(value);
2255
+ },
2256
+ (err) => {
2257
+ clearTimeout(timer);
2258
+ rejectPromise(err);
2259
+ }
2260
+ );
2261
+ });
2262
+ }
2263
+
2264
+ // src/core/v3/detect-worker.ts
2265
+ var WORKER_PROTOCOL_VERSION = 1;
2266
+ function workerOffloadSupported() {
2267
+ return typeof OffscreenCanvas === "function" && typeof createImageBitmap === "function" && typeof Worker === "function";
2268
+ }
2269
+ function installWorkerDetectorHost(scope, deps = {}) {
2270
+ const create = deps.createDetector ?? createDetector;
2271
+ let detector = null;
2272
+ scope.onmessage = (event) => {
2273
+ const message = event.data;
2274
+ if (message.v !== WORKER_PROTOCOL_VERSION) {
2275
+ message.bitmap?.close?.();
2276
+ return;
2277
+ }
2278
+ if (message.type === "init") {
2279
+ void create(message.options).then((created) => {
2280
+ detector = created;
2281
+ const ready = {
2282
+ v: WORKER_PROTOCOL_VERSION,
2283
+ type: "ready",
2284
+ tier: created.tier,
2285
+ ...created.fallbackReason !== void 0 ? { fallbackReason: created.fallbackReason } : {}
2286
+ };
2287
+ scope.postMessage(ready);
2288
+ });
2289
+ return;
2290
+ }
2291
+ if (message.type === "detect") {
2292
+ const respond = (observation) => {
2293
+ const result = {
2294
+ v: WORKER_PROTOCOL_VERSION,
2295
+ type: "result",
2296
+ id: message.id,
2297
+ observation
2298
+ };
2299
+ scope.postMessage(result);
2300
+ message.bitmap.close?.();
2301
+ };
2302
+ if (detector === null) {
2303
+ respond(null);
2304
+ return;
2305
+ }
2306
+ void detector.detect(message.bitmap, message.streamWidth, message.streamHeight).then(respond, () => respond(null));
2307
+ }
2308
+ };
2309
+ }
2310
+ if (typeof self !== "undefined" && typeof self.importScripts === "function") {
2311
+ installWorkerDetectorHost(self);
2312
+ }
2313
+ var WorkerDetectorProxy = class _WorkerDetectorProxy {
2314
+ constructor(worker, ready) {
2315
+ this.pending = /* @__PURE__ */ new Map();
2316
+ this.nextId = 1;
2317
+ this.worker = worker;
2318
+ this.tier = ready.tier;
2319
+ if (ready.fallbackReason !== void 0) this.fallbackReason = ready.fallbackReason;
2320
+ worker.addEventListener("message", (event) => {
2321
+ const message = event.data;
2322
+ if (message.v !== WORKER_PROTOCOL_VERSION || message.type !== "result") return;
2323
+ const resolve = this.pending.get(message.id);
2324
+ this.pending.delete(message.id);
2325
+ resolve?.(message.observation);
2326
+ });
2327
+ }
2328
+ static create(worker, options, readyTimeoutMs = 1e4) {
2329
+ return new Promise((resolve, reject) => {
2330
+ const timer = setTimeout(() => {
2331
+ worker.removeEventListener("message", onReady);
2332
+ worker.terminate();
2333
+ reject(new Error(`worker detector not ready within ${readyTimeoutMs}ms`));
2334
+ }, readyTimeoutMs);
2335
+ const onReady = (event) => {
2336
+ const message = event.data;
2337
+ if (message.v !== WORKER_PROTOCOL_VERSION || message.type !== "ready") return;
2338
+ clearTimeout(timer);
2339
+ worker.removeEventListener("message", onReady);
2340
+ resolve(new _WorkerDetectorProxy(worker, message));
2341
+ };
2342
+ worker.addEventListener("message", onReady);
2343
+ const init = { v: WORKER_PROTOCOL_VERSION, type: "init", options };
2344
+ worker.postMessage(init);
2345
+ });
2346
+ }
2347
+ async detect(source, sourceWidth, sourceHeight) {
2348
+ let bitmap;
2349
+ try {
2350
+ if (typeof ImageBitmap !== "undefined" && source instanceof ImageBitmap) {
2351
+ bitmap = source;
2352
+ } else if (typeof createImageBitmap === "function") {
2353
+ bitmap = await createImageBitmap(source);
2354
+ } else {
2355
+ bitmap = source;
2356
+ }
2357
+ } catch {
2358
+ return null;
2359
+ }
2360
+ const id = this.nextId;
2361
+ this.nextId += 1;
2362
+ return new Promise((resolve) => {
2363
+ this.pending.set(id, resolve);
2364
+ const message = {
2365
+ v: WORKER_PROTOCOL_VERSION,
2366
+ type: "detect",
2367
+ id,
2368
+ bitmap,
2369
+ streamWidth: sourceWidth,
2370
+ streamHeight: sourceHeight
2371
+ };
2372
+ this.worker.postMessage(message, [bitmap]);
2373
+ });
2374
+ }
2375
+ destroy() {
2376
+ for (const resolve of this.pending.values()) resolve(null);
2377
+ this.pending.clear();
2378
+ this.worker.terminate();
2379
+ }
2380
+ };
2381
+
2382
+ // src/core/v3/detect-scheduler.ts
2383
+ var STATS_WINDOW = 20;
2384
+ var DetectScheduler = class {
2385
+ constructor(options) {
2386
+ this.timer = null;
2387
+ this.frameCallbackId = null;
2388
+ this.running = false;
2389
+ this.busy = false;
2390
+ this.lastRunAt = Number.NEGATIVE_INFINITY;
2391
+ this.degradeCount = 0;
2392
+ this.durations = [];
2393
+ this.options = options;
2394
+ this.periodMs = 1e3 / options.cadenceHz;
2395
+ }
2396
+ start() {
2397
+ if (this.running) return;
2398
+ this.running = true;
2399
+ const video = this.options.video;
2400
+ if (typeof video?.requestVideoFrameCallback === "function") {
2401
+ const loop = () => {
2402
+ if (!this.running) return;
2403
+ this.frameCallbackId = video.requestVideoFrameCallback?.(() => {
2404
+ this.frameCallbackId = null;
2405
+ if (this.now() - this.lastRunAt >= this.periodMs) this.tick();
2406
+ loop();
2407
+ });
2408
+ };
2409
+ loop();
2410
+ return;
2411
+ }
2412
+ this.timer = setInterval(() => this.tick(), this.periodMs);
2413
+ }
2414
+ stop() {
2415
+ this.running = false;
2416
+ if (this.timer !== null) {
2417
+ clearInterval(this.timer);
2418
+ this.timer = null;
2419
+ }
2420
+ if (this.frameCallbackId !== null) {
2421
+ this.options.video?.cancelVideoFrameCallback?.(
2422
+ this.frameCallbackId
2423
+ );
2424
+ this.frameCallbackId = null;
2425
+ }
2426
+ }
2427
+ stats() {
2428
+ const meanDetectMs = this.durations.length === 0 ? 0 : this.durations.reduce((sum, value) => sum + value, 0) / this.durations.length;
2429
+ return { degradeCount: this.degradeCount, meanDetectMs };
2430
+ }
2431
+ now() {
2432
+ return this.options.now?.() ?? performance.now();
2433
+ }
2434
+ tick() {
2435
+ if (!this.running) return;
2436
+ if (this.busy) {
2437
+ this.degradeCount += 1;
2438
+ return;
2439
+ }
2440
+ this.busy = true;
2441
+ this.lastRunAt = this.now();
2442
+ const startedAt = this.now();
2443
+ this.options.run().catch(() => void 0).finally(() => {
2444
+ this.busy = false;
2445
+ this.durations.push(this.now() - startedAt);
2446
+ if (this.durations.length > STATS_WINDOW) this.durations.shift();
2447
+ });
2448
+ }
2449
+ };
2450
+
2451
+ // src/core/v3/face-gate-v3.ts
2452
+ init_frame_quality();
2453
+ var V3_GATE_DEFAULTS = Object.freeze({
2454
+ Q_GOOD: 0.6,
2455
+ RISE_PER_S: 0.9,
2456
+ FALL_PER_S: 0.25,
2457
+ CENTER_FALLOFF_IOD_MULTIPLE: 1.35,
2458
+ BOX_EYE_OFFSET_FACTOR: 0.12,
2459
+ IOD_BOX_PROXY_FACTOR: 0.42,
2460
+ SIZE_IDEAL_MIN: 0.12,
2461
+ SIZE_IDEAL_MAX: 0.3,
2462
+ SIZE_HARD_MIN: 0.08,
2463
+ SIZE_HARD_MAX: 0.45,
2464
+ ROLL_MAX_DEG: 25,
2465
+ MOTION_VELOCITY_IOD_PER_S: 0.5,
2466
+ MOTION_TAU_S: 0.4,
2467
+ MOTION_DEADBAND_IOD_PER_S: 0.1,
2468
+ READY_WINDOW_MS: 500,
2469
+ // 0.7→0.75 with the trimmed window: trimming forgives exactly ONE flaky
2470
+ // tick; the raised mean keeps a SECOND bad tick (a real sustained wobble)
2471
+ // from diluting through at 10 Hz cadences.
2472
+ READY_MEAN_Q: 0.75,
2473
+ GUIDE_SIZE: 0.6,
2474
+ GUIDE_CENTERING: 0.6,
2475
+ GUIDE_POSE: 0.6,
2476
+ GUIDE_EXPOSURE: 0.6,
2477
+ GUIDE_SHARPNESS: 0.35,
2478
+ GUIDE_MOTION: 0.5
2479
+ });
2480
+ var clamp012 = (value) => Math.min(1, Math.max(0, value));
2481
+ var FaceGateV3 = class {
2482
+ constructor(overrides = {}) {
2483
+ this.p = 0;
2484
+ this.lastTickAt = null;
2485
+ this.lastCenter = null;
2486
+ this.velocityEma = 0;
2487
+ this.qWindow = [];
2488
+ /** Which side of the ideal band the last size measurement fell on. */
2489
+ this.lastSizeDirection = "ideal";
2490
+ this.t = { ...V3_GATE_DEFAULTS, ...overrides };
2491
+ }
2492
+ reset() {
2493
+ this.p = 0;
2494
+ this.lastTickAt = null;
2495
+ this.lastCenter = null;
2496
+ this.velocityEma = 0;
2497
+ this.qWindow = [];
2498
+ this.lastSizeDirection = "ideal";
2499
+ }
2500
+ tick(input) {
2501
+ const { observation, quality, timestampMs } = input;
2502
+ const dtSeconds = this.lastTickAt === null ? 0 : Math.max(0, (timestampMs - this.lastTickAt) / 1e3);
2503
+ this.lastTickAt = timestampMs;
2504
+ const factors = {
2505
+ presence: 0,
2506
+ centering: 0,
2507
+ size: 0,
2508
+ pose: 0,
2509
+ sharpness: clamp012(quality.sharpness),
2510
+ exposure: clamp012(quality.exposure),
2511
+ motion: 1
2512
+ };
2513
+ if (observation !== null) {
2514
+ factors.presence = 1;
2515
+ const geometry = this.geometryOf(observation, input);
2516
+ factors.centering = geometry.centering;
2517
+ factors.size = geometry.size;
2518
+ factors.pose = geometry.pose;
2519
+ factors.motion = this.motionOf(
2520
+ geometry.center,
2521
+ geometry.iod,
2522
+ timestampMs
2523
+ );
2524
+ } else {
2525
+ this.lastCenter = null;
2526
+ this.velocityEma = 0;
2527
+ }
2528
+ const q = Math.min(
2529
+ factors.presence,
2530
+ factors.centering,
2531
+ factors.size,
2532
+ factors.pose,
2533
+ factors.sharpness,
2534
+ factors.exposure,
2535
+ factors.motion
2536
+ );
2537
+ this.p = clamp012(
2538
+ this.p + (q >= this.t.Q_GOOD ? this.t.RISE_PER_S * q : -this.t.FALL_PER_S * (1 - q)) * dtSeconds
2539
+ );
2540
+ this.qWindow.push({ at: timestampMs, q });
2541
+ this.qWindow = this.qWindow.filter(
2542
+ (entry) => entry.at >= timestampMs - this.t.READY_WINDOW_MS
2543
+ );
2544
+ let windowSamples = this.qWindow.map((entry) => entry.q);
2545
+ if (windowSamples.length >= 3) {
2546
+ const worst = Math.min(...windowSamples);
2547
+ const worstIndex = windowSamples.indexOf(worst);
2548
+ windowSamples = windowSamples.filter((_2, index) => index !== worstIndex);
2549
+ }
2550
+ const windowMean = windowSamples.reduce((sum, value) => sum + value, 0) / Math.max(1, windowSamples.length);
2551
+ const ready = this.p >= 1 && windowMean >= this.t.READY_MEAN_Q;
2552
+ return {
2553
+ at: timestampMs,
2554
+ q,
2555
+ p: this.p,
2556
+ factors,
2557
+ guidanceKey: this.guidanceOf(factors, quality, q),
2558
+ ready
2559
+ };
2560
+ }
2561
+ geometryOf(observation, input) {
2562
+ const { box, eyes } = observation;
2563
+ const frameCenter = { x: input.frameWidth / 2, y: input.frameHeight / 2 };
2564
+ const shortSide = Math.min(input.frameWidth, input.frameHeight);
2565
+ const center = eyes !== void 0 ? {
2566
+ x: (eyes.left.x + eyes.right.x) / 2,
2567
+ y: (eyes.left.y + eyes.right.y) / 2
2568
+ } : {
2569
+ x: box.x + box.width / 2,
2570
+ y: box.y + box.height / 2 - this.t.BOX_EYE_OFFSET_FACTOR * box.height
2571
+ };
2572
+ const iod = eyes !== void 0 ? Math.hypot(eyes.right.x - eyes.left.x, eyes.right.y - eyes.left.y) : this.t.IOD_BOX_PROXY_FACTOR * box.width;
2573
+ const distance = Math.hypot(
2574
+ center.x - frameCenter.x,
2575
+ center.y - frameCenter.y
2576
+ );
2577
+ const centering = iod <= 0 ? 0 : 1 - clamp012(distance / (this.t.CENTER_FALLOFF_IOD_MULTIPLE * iod));
2578
+ const ratio = shortSide > 0 ? iod / shortSide : 0;
2579
+ this.lastSizeDirection = ratio < this.t.SIZE_IDEAL_MIN ? "far" : ratio > this.t.SIZE_IDEAL_MAX ? "close" : "ideal";
2580
+ let size;
2581
+ if (ratio < this.t.SIZE_HARD_MIN || ratio > this.t.SIZE_HARD_MAX) {
2582
+ size = 0;
2583
+ } else if (ratio < this.t.SIZE_IDEAL_MIN) {
2584
+ size = (ratio - this.t.SIZE_HARD_MIN) / (this.t.SIZE_IDEAL_MIN - this.t.SIZE_HARD_MIN);
2585
+ } else if (ratio > this.t.SIZE_IDEAL_MAX) {
2586
+ size = (this.t.SIZE_HARD_MAX - ratio) / (this.t.SIZE_HARD_MAX - this.t.SIZE_IDEAL_MAX);
2587
+ } else {
2588
+ size = 1;
2589
+ }
2590
+ let pose = 1;
2591
+ if (eyes !== void 0) {
2592
+ const rollDeg = Math.abs(
2593
+ Math.atan2(eyes.right.y - eyes.left.y, eyes.right.x - eyes.left.x)
2594
+ ) * 180 / Math.PI;
2595
+ pose = 1 - clamp012(rollDeg / this.t.ROLL_MAX_DEG);
2596
+ }
2597
+ return { center, iod, centering, size, pose };
2598
+ }
2599
+ motionOf(center, iod, at) {
2600
+ const previous = this.lastCenter;
2601
+ this.lastCenter = { ...center, at };
2602
+ if (previous === null || iod <= 0) return 1;
2603
+ const dtSeconds = (at - previous.at) / 1e3;
2604
+ if (dtSeconds <= 0) return 1;
2605
+ let velocityIodPerS = Math.hypot(center.x - previous.x, center.y - previous.y) / iod / dtSeconds;
2606
+ if (velocityIodPerS <= this.t.MOTION_DEADBAND_IOD_PER_S)
2607
+ velocityIodPerS = 0;
2608
+ const alpha = 1 - Math.exp(-dtSeconds / this.t.MOTION_TAU_S);
2609
+ this.velocityEma = alpha * velocityIodPerS + (1 - alpha) * this.velocityEma;
2610
+ return 1 - clamp012(this.velocityEma / this.t.MOTION_VELOCITY_IOD_PER_S);
2611
+ }
2612
+ /** Lowest failing factor speaks — fixed priority (diagnostic, incl. light):
2613
+ * presence → size → centering → pose → exposure → sharpness → hold.
2614
+ *
2615
+ * HONESTY FALLBACK (operator ruling 2026-07-12): when every factor clears
2616
+ * its guide threshold but q (= min factor) is still below Q_GOOD — i.e.
2617
+ * progress is DRAINING — "hold still" would be a lie ("Perfect" while
2618
+ * nothing advances; the field symptom was users discovering by accident
2619
+ * that only leaning in fires the gate). In that state the WORST factor
2620
+ * speaks even though it passed its guide level, so the user always hears
2621
+ * the change that actually unblocks recording. */
2622
+ guidanceOf(factors, quality, q) {
2623
+ if (factors.presence <= 0) return "fcv3.no_face";
2624
+ if (factors.size < this.t.GUIDE_SIZE) return this.sizeGuidance();
2625
+ if (factors.centering < this.t.GUIDE_CENTERING) return "fcv3.center_face";
2626
+ if (factors.pose < this.t.GUIDE_POSE) return "fcv3.straighten";
2627
+ if (factors.exposure < this.t.GUIDE_EXPOSURE)
2628
+ return this.exposureGuidance(quality);
2629
+ if (factors.sharpness < this.t.GUIDE_SHARPNESS) return "fcv3.steady_camera";
2630
+ if (factors.motion < this.t.GUIDE_MOTION) return "fcv3.hold_still";
2631
+ if (q < this.t.Q_GOOD) {
2632
+ const coachable = [
2633
+ ["size", this.sizeGuidance()],
2634
+ ["centering", "fcv3.center_face"],
2635
+ ["pose", "fcv3.straighten"],
2636
+ ["exposure", this.exposureGuidance(quality)],
2637
+ ["sharpness", "fcv3.steady_camera"],
2638
+ ["motion", "fcv3.hold_still"]
2639
+ ];
2640
+ let worst = coachable[0];
2641
+ for (const entry of coachable) {
2642
+ if (factors[entry[0]] < factors[worst[0]]) worst = entry;
2643
+ }
2644
+ return worst[1];
2645
+ }
2646
+ return "fcv3.hold_still";
2647
+ }
2648
+ /** Direction from the size band set THIS tick (never inverted at the hard
2649
+ * limits: past SIZE_HARD_MAX the direction is 'close' → move_back). */
2650
+ sizeGuidance() {
2651
+ return this.lastSizeDirection === "far" ? "fcv3.come_closer" : "fcv3.move_back";
2652
+ }
2653
+ /** Band midpoint — direction only (tracks EXPOSURE_BAND automatically). */
2654
+ exposureGuidance(quality) {
2655
+ const bandMid = (EXPOSURE_BAND[0] + EXPOSURE_BAND[1]) / 2;
2656
+ return quality.meanLuma < bandMid ? "fcv3.more_light" : "fcv3.too_bright";
2657
+ }
2658
+ };
2659
+
2660
+ // src/core/v3/capture-session-v3.ts
2661
+ init_frame_quality();
2662
+ var KEYFRAME_CANDIDATES = 4;
2663
+ var KEYFRAME_WINDOW_MS = 600;
2664
+ var NEUTRAL_QUALITY = { sharpness: 1, exposure: 1, meanLuma: 128 };
2665
+ var CaptureSessionV3 = class {
2666
+ constructor(options) {
2667
+ this.handlers = /* @__PURE__ */ new Map();
2668
+ this.stateValue = "idle";
2669
+ this.attempt = 0;
2670
+ this.stream = null;
2671
+ this.detector = null;
2672
+ this.scheduler = null;
2673
+ this.gate = null;
2674
+ this.profiler = null;
2675
+ this.lastGuidanceKey = null;
2676
+ this.positioningStartedAt = 0;
2677
+ this.fired = false;
2678
+ this.carriedDegrade = 0;
2679
+ this.carriedMeans = [];
2680
+ /** Reused downscale canvas — falls back to the raw video where canvas 2D
2681
+ * is unavailable (jsdom) so tests and exotic hosts keep detecting. */
2682
+ this.snapshotCanvas = null;
2683
+ this.options = options;
2684
+ this.facing = options.facingMode ?? "user";
2685
+ }
2686
+ get state() {
2687
+ return this.stateValue;
2688
+ }
2689
+ on(event, handler) {
2690
+ let set = this.handlers.get(event);
2691
+ if (!set) {
2692
+ set = /* @__PURE__ */ new Set();
2693
+ this.handlers.set(event, set);
2694
+ }
2695
+ set.add(handler);
2696
+ return () => set?.delete(handler);
2697
+ }
2698
+ emit(event, payload) {
2699
+ for (const handler of [...this.handlers.get(event) ?? []]) {
2700
+ handler(payload);
2701
+ }
2702
+ }
2703
+ async start() {
2704
+ this.attempt += 1;
2705
+ await this.run(this.attempt);
2706
+ }
2707
+ /** Full reset + camera restart — the documented recovery path (v1 parity). */
2708
+ retry() {
2709
+ this.teardownAttempt();
2710
+ void this.start();
2711
+ }
2712
+ switchCamera() {
2713
+ this.facing = this.facing === "user" ? "environment" : "user";
2714
+ this.teardownAttempt();
2715
+ void this.start();
2716
+ }
2717
+ destroy() {
2718
+ this.attempt += 1;
2719
+ this.teardownAttempt();
2720
+ this.detector?.destroy();
2721
+ this.detector = null;
2722
+ this.options.video.srcObject = null;
2723
+ }
2724
+ // ── attempt lifecycle ──────────────────────────────────────────────────────
2725
+ async run(attempt) {
2726
+ const { options } = this;
2727
+ this.fired = false;
2728
+ this.lastGuidanceKey = null;
2729
+ this.carriedDegrade = 0;
2730
+ this.carriedMeans = [];
2731
+ this.setState("preflight");
2732
+ const preflight = cameraPreflight();
2733
+ if (preflight !== "OK") {
2734
+ this.fail(preflight === "INSECURE_CONTEXT" ? "insecure" : "unsupported");
2735
+ return;
2736
+ }
2737
+ this.setState("acquiring");
2738
+ const getUserMedia = options.getUserMedia ?? ((constraints) => navigator.mediaDevices.getUserMedia(constraints));
2739
+ let stream;
2740
+ try {
2741
+ stream = await getUserMedia(buildCaptureConstraints(detectIsMobile(), this.facing));
2742
+ } catch (err) {
2743
+ if (attempt !== this.attempt) return;
2744
+ this.fail(mapGetUserMediaError(err));
2745
+ return;
2746
+ }
2747
+ if (attempt !== this.attempt) {
2748
+ for (const track of stream.getTracks()) track.stop();
2749
+ return;
2750
+ }
2751
+ this.stream = stream;
2752
+ options.video.srcObject = stream;
2753
+ await options.video.play().catch(() => void 0);
2754
+ if (attempt !== this.attempt) return;
2755
+ if (this.detector === null) {
2756
+ const ladderOptions = {
2757
+ ...options.v3AssetBaseUrl !== void 0 ? { v3AssetBaseUrl: options.v3AssetBaseUrl } : {}
2758
+ };
2759
+ const create = options.createDetector ?? (options.createWorker !== void 0 && workerOffloadSupported() ? async () => {
2760
+ try {
2761
+ return await WorkerDetectorProxy.create(
2762
+ options.createWorker(),
2763
+ ladderOptions
2764
+ );
2765
+ } catch {
2766
+ return createDetector(ladderOptions);
2767
+ }
2768
+ } : () => createDetector(ladderOptions));
2769
+ let created;
2770
+ try {
2771
+ created = await create();
2772
+ } catch (err) {
2773
+ if (attempt === this.attempt) {
2774
+ this.fail(
2775
+ "models",
2776
+ err instanceof DetectorLadderError ? err.fallbackReason : describeError2(err)
2777
+ );
2778
+ }
2779
+ return;
2780
+ }
2781
+ if (attempt !== this.attempt) {
2782
+ created.destroy();
2783
+ return;
2784
+ }
2785
+ this.detector = created;
2786
+ this.options.telemetry?.({
2787
+ type: "detector",
2788
+ tier: created.tier,
2789
+ ...created.fallbackReason !== void 0 ? { fallbackReason: created.fallbackReason } : {}
2790
+ });
2791
+ }
2792
+ const probe = probeDevice();
2793
+ const staticClass = options.deviceClass ?? classifyDevice(probe);
2794
+ this.profiler = new DeviceProfiler(staticClass);
2795
+ this.options.telemetry?.({
2796
+ type: "profile",
2797
+ staticClass,
2798
+ activeClass: this.profiler.deviceClass,
2799
+ simd: probe.simd
2800
+ });
2801
+ this.gate = new FaceGateV3(options.thresholds ?? {});
2802
+ this.setState("positioning");
2803
+ this.positioningStartedAt = this.now();
2804
+ this.startScheduler(attempt);
2805
+ }
2806
+ /** Chrome hint (Task 11): 'reduced' on LOW even without the media query. */
2807
+ get animations() {
2808
+ return this.profiler?.profile.animations ?? "full";
2809
+ }
2810
+ startScheduler(attempt) {
2811
+ const profiler = this.profiler;
2812
+ if (profiler === null) return;
2813
+ if (this.scheduler !== null) {
2814
+ const stats = this.scheduler.stats();
2815
+ this.carriedDegrade += stats.degradeCount;
2816
+ if (stats.meanDetectMs > 0) this.carriedMeans.push(stats.meanDetectMs);
2817
+ this.scheduler.stop();
2818
+ }
2819
+ const scheduler = new DetectScheduler({
2820
+ cadenceHz: profiler.profile.cadenceHz,
2821
+ video: this.options.video,
2822
+ ...this.options.now !== void 0 ? { now: this.options.now } : {},
2823
+ run: () => this.detectTick(attempt)
2824
+ });
2825
+ this.scheduler = scheduler;
2826
+ scheduler.start();
2827
+ }
2828
+ async detectTick(attempt) {
2829
+ const { detector, gate, profiler } = this;
2830
+ const video = this.options.video;
2831
+ if (attempt !== this.attempt || detector === null || gate === null || profiler === null)
2832
+ return;
2833
+ if (this.fired || video.videoWidth === 0) return;
2834
+ const before = profiler.deviceClass;
2835
+ const t0 = this.now();
2836
+ const source = this.options.makeSnapshot?.(video, profiler.profile.inputWidth) ?? this.defaultSnapshot(video, profiler.profile.inputWidth);
2837
+ let observation = null;
2838
+ try {
2839
+ observation = await detector.detect(source, video.videoWidth, video.videoHeight);
2840
+ } catch {
2841
+ observation = null;
2842
+ }
2843
+ if (attempt !== this.attempt || this.fired) return;
2844
+ profiler.record(this.now() - t0);
2845
+ if (profiler.deviceClass !== before) this.startScheduler(attempt);
2846
+ const quality = observation === null ? NEUTRAL_QUALITY : this.options.measureQuality?.(video, observation.box) ?? this.defaultQuality(video, observation.box);
2847
+ const tick = gate.tick({
2848
+ timestampMs: this.now(),
2849
+ observation,
2850
+ quality,
2851
+ frameWidth: video.videoWidth,
2852
+ frameHeight: video.videoHeight
2853
+ });
2854
+ this.emit("checks", {
2855
+ engine: "v3",
2856
+ progress: tick.p,
2857
+ q: tick.q,
2858
+ factors: tick.factors,
2859
+ attempt
2860
+ });
2861
+ if (tick.guidanceKey !== this.lastGuidanceKey) {
2862
+ this.lastGuidanceKey = tick.guidanceKey;
2863
+ this.emit("guidance", { key: tick.guidanceKey });
2864
+ }
2865
+ if (tick.ready && this.stateValue === "positioning") {
2866
+ this.fired = true;
2867
+ void this.fire(attempt);
2868
+ }
2869
+ }
2870
+ async fire(attempt) {
2871
+ const { options } = this;
2872
+ const scheduler = this.scheduler;
2873
+ scheduler?.stop();
2874
+ const stats = scheduler?.stats() ?? { degradeCount: 0, meanDetectMs: 0 };
2875
+ const means = [...this.carriedMeans, ...stats.meanDetectMs > 0 ? [stats.meanDetectMs] : []];
2876
+ options.telemetry?.({
2877
+ type: "fired",
2878
+ timeToGateMs: this.now() - this.positioningStartedAt,
2879
+ degradeCount: this.carriedDegrade + stats.degradeCount,
2880
+ meanDetectMs: means.length === 0 ? 0 : means.reduce((sum, value) => sum + value, 0) / means.length
2881
+ });
2882
+ const mode = options.mode ?? "clip";
2883
+ const bestOf = this.collectKeyframes(attempt);
2884
+ if (mode === "photo") {
2885
+ const best2 = await bestOf;
2886
+ if (attempt !== this.attempt) return;
2887
+ if (best2 === null) {
2888
+ this.fail("generic");
2889
+ return;
2890
+ }
2891
+ this.finishCapture({ keyframe: best2.blob, previewDataUrl: best2.previewDataUrl });
2892
+ return;
2893
+ }
2894
+ this.setState("recording");
2895
+ const recorder = options.createRecorder?.() ?? new ClipRecorder();
2896
+ const stream = this.stream;
2897
+ if (stream === null) {
2898
+ this.fail("generic");
2899
+ return;
2900
+ }
2901
+ let frozenBest = null;
2902
+ void bestOf.then(
2903
+ (candidate) => {
2904
+ frozenBest = candidate;
2905
+ },
2906
+ () => {
2907
+ }
2908
+ );
2909
+ const onRecordingStopped = () => {
2910
+ if (attempt !== this.attempt) return;
2911
+ if (frozenBest !== null) {
2912
+ this.emit("frozen", { previewDataUrl: frozenBest.previewDataUrl });
2913
+ }
2914
+ };
2915
+ let clip;
2916
+ let best;
2917
+ try {
2918
+ [clip, best] = await Promise.all([recorder.record(stream, onRecordingStopped), bestOf]);
2919
+ } catch (err) {
2920
+ if (attempt !== this.attempt) return;
2921
+ const kind = err.kind;
2922
+ this.fail(kind === "cliptoolarge" ? "cliptoolarge" : "recorder");
2923
+ return;
2924
+ }
2925
+ if (attempt !== this.attempt) return;
2926
+ if (isClipTooLarge(clip.blob)) {
2927
+ this.fail("cliptoolarge");
2928
+ return;
2929
+ }
2930
+ if (best === null) {
2931
+ this.fail("generic");
2932
+ return;
2933
+ }
2934
+ this.finishCapture({
2935
+ clip: clip.blob,
2936
+ clipMimeType: clip.mimeType,
2937
+ keyframe: best.blob,
2938
+ previewDataUrl: best.previewDataUrl
2939
+ });
2940
+ }
2941
+ /** Up to KEYFRAME_CANDIDATES mirrored frames over KEYFRAME_WINDOW_MS —
2942
+ * sharpest wins (reuses frame-quality.sharpness via the capture seam). */
2943
+ async collectKeyframes(attempt) {
2944
+ const capture = this.options.captureKeyframe ?? ((video) => this.defaultKeyframe(video));
2945
+ const stepMs = KEYFRAME_WINDOW_MS / (KEYFRAME_CANDIDATES - 1);
2946
+ let best = null;
2947
+ for (let i2 = 0; i2 < KEYFRAME_CANDIDATES; i2 += 1) {
2948
+ if (attempt !== this.attempt) return best;
2949
+ try {
2950
+ const candidate = await capture(this.options.video);
2951
+ if (best === null || candidate.sharpness > best.sharpness) best = candidate;
2952
+ } catch {
2953
+ }
2954
+ if (i2 < KEYFRAME_CANDIDATES - 1) await delay(stepMs);
2955
+ }
2956
+ return best;
2957
+ }
2958
+ finishCapture(artifacts) {
2959
+ this.stopTracks();
2960
+ this.setState("captured");
2961
+ this.emit("artifacts", artifacts);
2962
+ }
2963
+ // ── defaults for the canvas-bound seams ────────────────────────────────────
2964
+ async defaultKeyframe(video) {
2965
+ const canvas = document.createElement("canvas");
2966
+ const blob = await captureMirroredKeyframe(video, canvas);
2967
+ const previewDataUrl = canvas.toDataURL("image/jpeg", 0.92);
2968
+ return { blob, previewDataUrl, sharpness: this.centerSharpness(video) };
2969
+ }
2970
+ defaultSnapshot(video, targetWidth) {
2971
+ try {
2972
+ const canvas = this.snapshotCanvas ?? document.createElement("canvas");
2973
+ const scale = targetWidth / Math.max(1, video.videoWidth);
2974
+ const width = Math.max(1, Math.round(video.videoWidth * scale));
2975
+ const height = Math.max(1, Math.round(video.videoHeight * scale));
2976
+ const ctx = canvas.getContext("2d");
2977
+ if (ctx === null) return video;
2978
+ if (canvas.width !== width) canvas.width = width;
2979
+ if (canvas.height !== height) canvas.height = height;
2980
+ ctx.drawImage(video, 0, 0, width, height);
2981
+ this.snapshotCanvas = canvas;
2982
+ return canvas;
2983
+ } catch {
2984
+ return video;
2985
+ }
2986
+ }
2987
+ defaultQuality(video, box) {
2988
+ const crop = cropImageData(video, box, 96);
2989
+ if (crop === null) return NEUTRAL_QUALITY;
2990
+ return { sharpness: sharpness(crop), exposure: exposure(crop), meanLuma: meanLuma(crop) };
2991
+ }
2992
+ centerSharpness(video) {
2993
+ const size = intrinsicSize(video);
2994
+ const crop = cropImageData(
2995
+ video,
2996
+ { x: size.width * 0.25, y: size.height * 0.25, width: size.width * 0.5, height: size.height * 0.5 },
2997
+ 96
2998
+ );
2999
+ return crop === null ? 0 : sharpness(crop);
3000
+ }
3001
+ // ── teardown ──────────────────────────────────────────────────────────────
3002
+ teardownAttempt() {
3003
+ this.scheduler?.stop();
3004
+ this.scheduler = null;
3005
+ this.gate = null;
3006
+ this.stopTracks();
3007
+ }
3008
+ stopTracks() {
3009
+ if (this.stream === null) return;
3010
+ for (const track of this.stream.getTracks()) track.stop();
3011
+ this.stream = null;
3012
+ }
3013
+ fail(kind, fallbackReason) {
3014
+ this.scheduler?.stop();
3015
+ this.stopTracks();
3016
+ this.setState("error");
3017
+ this.options.telemetry?.({
3018
+ type: "error",
3019
+ kind,
3020
+ ...fallbackReason !== void 0 ? { fallbackReason } : {}
3021
+ });
3022
+ this.emit("error", { kind, retryable: kind !== "insecure" && kind !== "unsupported" });
3023
+ }
3024
+ setState(state) {
3025
+ this.stateValue = state;
3026
+ this.emit("statechange", { state });
3027
+ }
3028
+ now() {
3029
+ return this.options.now?.() ?? performance.now();
3030
+ }
3031
+ };
3032
+ function delay(ms) {
3033
+ return new Promise((resolve) => setTimeout(resolve, ms));
3034
+ }
3035
+ function describeError2(err) {
3036
+ return err instanceof Error ? err.message : String(err);
3037
+ }
3038
+ function cropImageData(video, box, targetWidth) {
3039
+ try {
3040
+ const canvas = document.createElement("canvas");
3041
+ const scale = targetWidth / Math.max(1, box.width);
3042
+ canvas.width = Math.max(1, Math.round(box.width * scale));
3043
+ canvas.height = Math.max(1, Math.round(box.height * scale));
3044
+ const ctx = canvas.getContext("2d");
3045
+ if (ctx === null) return null;
3046
+ ctx.drawImage(
3047
+ video,
3048
+ box.x,
3049
+ box.y,
3050
+ box.width,
3051
+ box.height,
3052
+ 0,
3053
+ 0,
3054
+ canvas.width,
3055
+ canvas.height
3056
+ );
3057
+ return ctx.getImageData(0, 0, canvas.width, canvas.height);
3058
+ } catch {
3059
+ return null;
3060
+ }
3061
+ }
3062
+
3063
+ // src/verification/emitter.ts
3064
+ function createEmitter() {
3065
+ const handlers = /* @__PURE__ */ new Map();
3066
+ return {
3067
+ on(event, handler) {
3068
+ let set = handlers.get(event);
3069
+ if (set === void 0) {
3070
+ set = /* @__PURE__ */ new Set();
3071
+ handlers.set(event, set);
3072
+ }
3073
+ const h2 = handler;
3074
+ set.add(h2);
3075
+ return () => {
3076
+ set?.delete(h2);
3077
+ };
3078
+ },
3079
+ emit(event, payload) {
3080
+ const set = handlers.get(event);
3081
+ if (set === void 0) return;
3082
+ for (const handler of [...set]) {
3083
+ handler(payload);
3084
+ }
3085
+ },
3086
+ clear() {
3087
+ handlers.clear();
3088
+ }
3089
+ };
3090
+ }
3091
+
3092
+ // src/capture/create-liveness-capture.ts
3093
+ function mapGuidanceHint(key) {
3094
+ switch (key) {
3095
+ case "fcv3.no_face":
3096
+ case "fcv3.center_face":
3097
+ case "fcv3.straighten":
3098
+ return "center";
3099
+ case "fcv3.come_closer":
3100
+ return "closer";
3101
+ case "fcv3.move_back":
3102
+ return "farther";
3103
+ case "fcv3.more_light":
3104
+ case "fcv3.too_bright":
3105
+ return "light";
3106
+ case "fcv3.hold_still":
3107
+ case "fcv3.steady_camera":
3108
+ return "still";
3109
+ default:
3110
+ return null;
3111
+ }
3112
+ }
3113
+ function mapEngineState(state) {
3114
+ switch (state) {
3115
+ case "preflight":
3116
+ case "acquiring":
3117
+ return "starting";
3118
+ case "positioning":
3119
+ return "gating";
3120
+ case "idle":
3121
+ case "recording":
3122
+ case "captured":
3123
+ case "error":
3124
+ return state;
3125
+ default: {
3126
+ const unhandled = state;
3127
+ throw new Error(`mapEngineState: unhandled state ${unhandled}`);
3128
+ }
3129
+ }
3130
+ }
3131
+ function mapErrorKind(kind) {
3132
+ switch (kind) {
3133
+ case "permission":
3134
+ case "notfound":
3135
+ case "inuse":
3136
+ case "insecure":
3137
+ case "unsupported":
3138
+ return kind;
3139
+ case "overconstrained":
3140
+ case "generic":
3141
+ case "models":
3142
+ case "cliptoolarge":
3143
+ case "recorder":
3144
+ return "generic";
3145
+ default: {
3146
+ const unhandled = kind;
3147
+ throw new Error(`mapErrorKind: unhandled kind ${unhandled}`);
3148
+ }
3149
+ }
3150
+ }
3151
+ function createLivenessCaptureInternal(options, internals = {}) {
3152
+ const now = internals.now ?? (() => performance.now());
3153
+ const emitter = createEmitter();
3154
+ const degraded = !isMediaRecorderSupported();
3155
+ const engineOptions = {
3156
+ video: options.video,
3157
+ mode: degraded ? "photo" : "clip",
3158
+ ...options.facing !== void 0 ? { facingMode: options.facing } : {},
3159
+ ...options.assetBaseUrl !== void 0 ? { v3AssetBaseUrl: options.assetBaseUrl } : {},
3160
+ ...internals.engineOptions ?? {}
3161
+ };
3162
+ const engine = internals.createEngine?.(engineOptions) ?? new CaptureSessionV3(engineOptions);
3163
+ let state = "idle";
3164
+ let hint = null;
3165
+ let progress = 0;
3166
+ let faceDetected = false;
3167
+ let animations = "full";
3168
+ let recordingStartedAt = null;
3169
+ let frozenAt = null;
3170
+ const setState = (next) => {
3171
+ state = next;
3172
+ emitter.emit("state", next);
3173
+ };
3174
+ const emitGate = () => emitter.emit("gate", { progress, hint, faceDetected });
3175
+ const syncProfile = () => {
3176
+ const next = engine.animations ?? "full";
3177
+ if (next === animations) return;
3178
+ animations = next;
3179
+ emitter.emit("profile", { animations });
3180
+ };
3181
+ const unsubscribes = [
3182
+ engine.on("statechange", ({ state: engineState }) => {
3183
+ const next = mapEngineState(engineState);
3184
+ if (next === "starting" && state !== "starting") {
3185
+ hint = null;
3186
+ progress = 0;
3187
+ faceDetected = false;
3188
+ recordingStartedAt = null;
3189
+ frozenAt = null;
3190
+ }
3191
+ setState(next);
3192
+ syncProfile();
3193
+ if (next === "recording") {
3194
+ recordingStartedAt = now();
3195
+ hint = "hold";
3196
+ progress = 1;
3197
+ emitGate();
3198
+ }
3199
+ }),
3200
+ engine.on("checks", (payload) => {
3201
+ progress = payload.progress;
3202
+ faceDetected = payload.factors.presence > 0;
3203
+ emitGate();
3204
+ syncProfile();
3205
+ }),
3206
+ engine.on("guidance", ({ key }) => {
3207
+ hint = mapGuidanceHint(key);
3208
+ emitGate();
3209
+ }),
3210
+ engine.on("frozen", ({ previewDataUrl }) => {
3211
+ frozenAt = now();
3212
+ emitter.emit("frozen", { previewDataUrl });
3213
+ }),
3214
+ engine.on("artifacts", (artifacts) => {
3215
+ const clipMs = recordingStartedAt !== null && frozenAt !== null ? Math.max(0, Math.round(frozenAt - recordingStartedAt)) : void 0;
3216
+ emitter.emit("captured", {
3217
+ keyframe: artifacts.keyframe,
3218
+ ...artifacts.clip !== void 0 ? { clip: artifacts.clip } : {},
3219
+ ...artifacts.clipMimeType !== void 0 ? { clipMime: artifacts.clipMimeType } : {},
3220
+ width: options.video.videoWidth,
3221
+ height: options.video.videoHeight,
3222
+ ...clipMs !== void 0 ? { clipMs } : {},
3223
+ captureChannel: detectIsMobile() ? "mobile" : "desktop",
3224
+ ...degraded ? { degraded: "NO_RECORDER" } : {}
3225
+ });
3226
+ }),
3227
+ engine.on("error", ({ kind, retryable }) => {
3228
+ emitter.emit("error", { kind: mapErrorKind(kind), retryable });
3229
+ })
3230
+ ];
3231
+ const handle = {
3232
+ get state() {
3233
+ return state;
3234
+ },
3235
+ on: (event, handler) => emitter.on(event, handler),
3236
+ start: () => engine.start(),
3237
+ retry: () => engine.retry(),
3238
+ switchCamera: () => engine.switchCamera(),
3239
+ destroy: () => {
3240
+ for (const unsubscribe of unsubscribes) unsubscribe();
3241
+ engine.destroy();
3242
+ emitter.clear();
3243
+ }
3244
+ };
3245
+ return {
3246
+ handle,
3247
+ setFlowState: (next) => {
3248
+ if (state !== next) setState(next);
3249
+ }
3250
+ };
3251
+ }
3252
+
3253
+ // src/client/errors.ts
3254
+ var HostedApiError = class extends Error {
3255
+ constructor(args) {
3256
+ super(args.message);
3257
+ this.name = "HostedApiError";
3258
+ this.status = args.status;
3259
+ this.code = args.code;
3260
+ if (args.retryAfterSeconds !== void 0) this.retryAfterSeconds = args.retryAfterSeconds;
3261
+ }
3262
+ };
3263
+
3264
+ // src/client/hosted-client.ts
3265
+ var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
3266
+ var SPACES_PUT_TIMEOUT_MS = 9e5;
3267
+ var UPLOAD_ERROR_SNIPPET_CHARS = 200;
3268
+ var IN_PROGRESS_RETRY_ATTEMPTS = 5;
3269
+ var IN_PROGRESS_RETRY_DELAY_MS = 400;
3270
+ function stripMimeParams(contentType) {
3271
+ return (contentType.split(";")[0] ?? "").trim();
3272
+ }
3273
+ var MEDIA_INPUT_FIELD = {
3274
+ liveness: "clipKey",
3275
+ face_match: "imageKey",
3276
+ doc_ocr: "imageKey"
3277
+ };
3278
+ var HostedClient = class {
3279
+ constructor(opts) {
3280
+ this.sessionId = null;
3281
+ this.bootstrap = null;
3282
+ this.apiOrigin = opts.apiOrigin.replace(/\/+$/, "");
3283
+ this.sessionToken = opts.sessionToken;
3284
+ const impl = opts.fetch;
3285
+ this.fetchImpl = (input, init) => (impl ?? globalThis.fetch).call(globalThis, input, init);
3286
+ this.requestTimeoutMs = opts.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
3287
+ this.retryAttempts = opts.inProgressRetry?.attempts ?? IN_PROGRESS_RETRY_ATTEMPTS;
3288
+ this.retryDelayMs = opts.inProgressRetry?.delayMs ?? IN_PROGRESS_RETRY_DELAY_MS;
3289
+ }
3290
+ /** Token-addressed bootstrap — the hosted page's first call. Caches the sessionId. */
3291
+ async getSession() {
3292
+ const view = await this.api("GET", "/hosted/session");
3293
+ this.sessionId = view.sessionId;
3294
+ return view;
3295
+ }
3296
+ /**
3297
+ * Record consent once (201; an idempotent replay answers 200 with
3298
+ * `alreadyRecorded: true`). Until recorded, media presign/complete AND check
3299
+ * submission answer 409 `consent_required`.
3300
+ */
3301
+ async recordConsent(locale) {
3302
+ return this.api("POST", "/hosted/consent", { body: { locale } });
3303
+ }
3304
+ /**
3305
+ * Presign a Spaces PUT for a new pending object. `contentType` is stripped of
3306
+ * MIME parameters defensively (the allowlist holds bare types; the engine's
3307
+ * `clipMimeType` carries codec params) — PUT with the SAME bare type, or the
3308
+ * signed-header check rejects the upload.
3309
+ */
3310
+ async presign(kind, contentType, contentLength) {
3311
+ const id = await this.ensureSessionId();
3312
+ const body = { kind, contentType: stripMimeParams(contentType), contentLength };
3313
+ return this.api("POST", `/sessions/${id}/media`, { body });
3314
+ }
3315
+ /**
3316
+ * Bare PUT to the presigned Spaces URL: EXACTLY the signed headers — the
3317
+ * declared Content-Type and the blob body. NO `x-session-token` (the
3318
+ * signature IS the credential; an extra header breaks nothing but leaks the
3319
+ * token to a third-party host) and no JSON envelope.
3320
+ *
3321
+ * `contentType` is param-stripped here too (idempotent for bare types): the
3322
+ * presign strips internally, so a caller composing manually with the engine's
3323
+ * parameterful `clipMimeType` would otherwise sign `video/webm` but PUT
3324
+ * `video/webm;codecs=…` — a signed-header mismatch S3 rejects at runtime.
3325
+ *
3326
+ * Timeout: 15 min (`AbortSignal.timeout(900_000)`, matching the presign TTL)
3327
+ * rather than the API calls' 30 s — a 15 MB clip on a slow link legitimately
3328
+ * exceeds 30 s, but a stalled in-flight socket must still be bounded (the TTL
3329
+ * alone only bounds when a PUT can START).
3330
+ *
3331
+ * Failures are ALWAYS typed: non-2xx throws {@link HostedApiError} with the
3332
+ * client-synthesized `upload_failed` (message carries a truncated S3 body
3333
+ * snippet — e.g. SignatureDoesNotMatch); a mid-transfer drop → `network_error`;
3334
+ * the timeout → `timeout`.
3335
+ */
3336
+ async uploadToSpaces(uploadUrl, blob, contentType) {
3337
+ let res;
3338
+ try {
3339
+ res = await this.fetchImpl(uploadUrl, {
3340
+ method: "PUT",
3341
+ headers: { "content-type": stripMimeParams(contentType) },
3342
+ body: blob,
3343
+ signal: AbortSignal.timeout(SPACES_PUT_TIMEOUT_MS)
3344
+ });
3345
+ } catch (err) {
3346
+ throw asTransportError(err);
3347
+ }
3348
+ if (!res.ok) {
3349
+ const snippet = (await res.text().catch(() => "")).slice(0, UPLOAD_ERROR_SNIPPET_CHARS);
3350
+ throw new HostedApiError({
3351
+ status: res.status,
3352
+ code: "upload_failed",
3353
+ message: `media upload failed (HTTP ${res.status})${snippet ? `: ${snippet}` : ""}`
3354
+ });
3355
+ }
3356
+ }
3357
+ /** Finalize an upload: the backend sniffs + promotes; returns the PROMOTED key to submit. */
3358
+ async completeMedia(key) {
3359
+ const id = await this.ensureSessionId();
3360
+ return this.api("POST", `/sessions/${id}/media/complete`, {
3361
+ body: { key }
3362
+ });
3363
+ }
3364
+ /**
3365
+ * Submit one check. Sends `{input, forceOutcome?}` (SubmitCheckSchema) and the
3366
+ * optional `x-idempotency-key` header. Returns the whitelisted SessionView.
3367
+ */
3368
+ async submitCheck(checkType, input, opts = {}) {
3369
+ const id = await this.ensureSessionId();
3370
+ const body = {
3371
+ input,
3372
+ ...opts.forceOutcome !== void 0 ? { forceOutcome: opts.forceOutcome } : {}
3373
+ };
3374
+ return this.api("POST", `/sessions/${id}/checks/${checkType}`, {
3375
+ body,
3376
+ ...opts.idempotencyKey !== void 0 ? { idempotencyKey: opts.idempotencyKey } : {}
3377
+ });
3378
+ }
3379
+ /**
3380
+ * Convenience composition: presign → PUT → complete → submit, passing the
3381
+ * PROMOTED key (from complete's response — never the pending presign key)
3382
+ * into the check's media input field (`clipKey` for liveness, `imageKey` for
3383
+ * face_match/doc_ocr). `extraInput` carries the remaining input fields
3384
+ * (liveness `attestation`, doc_ocr `side`). The media content type is
3385
+ * param-stripped ONCE and used for both presign and PUT, so the signed
3386
+ * header always matches.
3387
+ */
3388
+ async uploadAndSubmit(checkType, media, extraInput, opts = {}) {
3389
+ const bareType = stripMimeParams(media.contentType);
3390
+ const presigned = await this.presign(media.kind, bareType, media.blob.size);
3391
+ await this.uploadToSpaces(presigned.uploadUrl, media.blob, bareType);
3392
+ const completed = await this.completeMedia(presigned.key);
3393
+ const input = {
3394
+ ...extraInput,
3395
+ [MEDIA_INPUT_FIELD[checkType]]: completed.key
3396
+ };
3397
+ return this.submitCheck(checkType, input, opts);
3398
+ }
3399
+ // ── transport ──────────────────────────────────────────────────────────────
3400
+ /** The token's own sessionId — cached from getSession(), lazily bootstrapped. */
3401
+ async ensureSessionId() {
3402
+ if (this.sessionId !== null) return this.sessionId;
3403
+ this.bootstrap ?? (this.bootstrap = this.getSession().finally(() => {
3404
+ this.bootstrap = null;
3405
+ }));
3406
+ return (await this.bootstrap).sessionId;
3407
+ }
3408
+ /**
3409
+ * One API request: `${apiOrigin}/api/v2${path}`, `x-session-token` always,
3410
+ * AbortSignal timeout (30 s default), `{success, data}` unwrap on 2xx, flat
3411
+ * `{code, message}` → {@link HostedApiError} on non-2xx. EVERY failure is
3412
+ * typed: a rejected fetch → `network_error`, the timeout → `timeout`, an
3413
+ * unparseable 2xx body → `unknown_error` — the page never sees a raw
3414
+ * TypeError/DOMException. The ONLY automatic retry is 409
3415
+ * `idempotency_in_progress` (bounded, short delay).
3416
+ */
3417
+ async api(method, path, opts = {}) {
3418
+ const url = `${this.apiOrigin}/api/v2${path}`;
3419
+ const headers = { "x-session-token": this.sessionToken };
3420
+ if (opts.body !== void 0) headers["content-type"] = "application/json";
3421
+ if (opts.idempotencyKey !== void 0) headers["x-idempotency-key"] = opts.idempotencyKey;
3422
+ for (let attempt = 0; ; attempt++) {
3423
+ let res;
3424
+ try {
3425
+ res = await this.fetchImpl(url, {
3426
+ method,
3427
+ headers,
3428
+ ...opts.body !== void 0 ? { body: JSON.stringify(opts.body) } : {},
3429
+ signal: AbortSignal.timeout(this.requestTimeoutMs)
3430
+ });
3431
+ } catch (err2) {
3432
+ throw asTransportError(err2);
3433
+ }
3434
+ if (res.ok) {
3435
+ let raw;
3436
+ try {
3437
+ raw = await res.json();
3438
+ } catch {
3439
+ throw new HostedApiError({
3440
+ status: res.status,
3441
+ code: "unknown_error",
3442
+ message: `response body was not valid JSON (HTTP ${res.status})`
3443
+ });
3444
+ }
3445
+ return unwrap(raw);
3446
+ }
3447
+ const err = await parseErrorResponse(res);
3448
+ if (err.code === "idempotency_in_progress" && attempt < this.retryAttempts) {
3449
+ if (this.retryDelayMs > 0) await sleep(this.retryDelayMs);
3450
+ continue;
3451
+ }
3452
+ throw err;
3453
+ }
3454
+ }
3455
+ };
3456
+ function asTransportError(err) {
3457
+ const name = typeof err === "object" && err !== null ? err.name : void 0;
3458
+ if (name === "TimeoutError") {
3459
+ return new HostedApiError({ status: 0, code: "timeout", message: "request timed out" });
3460
+ }
3461
+ const detail = err instanceof Error ? err.message : String(err);
3462
+ return new HostedApiError({
3463
+ status: 0,
3464
+ code: "network_error",
3465
+ message: `network request failed: ${detail}`
3466
+ });
3467
+ }
3468
+ function unwrap(raw) {
3469
+ if (raw !== null && typeof raw === "object" && "success" in raw && "data" in raw) {
3470
+ return raw.data;
3471
+ }
3472
+ return raw;
3473
+ }
3474
+ async function parseErrorResponse(res) {
3475
+ let code = "unknown_error";
3476
+ let message = `request failed (HTTP ${res.status})`;
3477
+ try {
3478
+ const body = await res.json();
3479
+ if (body !== null && typeof body === "object") {
3480
+ const env = body;
3481
+ if (typeof env.code === "string" && env.code.length > 0) code = env.code;
3482
+ if (typeof env.message === "string" && env.message.length > 0) message = env.message;
3483
+ }
3484
+ } catch {
3485
+ }
3486
+ const retryAfterRaw = res.headers.get("retry-after");
3487
+ const retryAfter = retryAfterRaw === null ? Number.NaN : Number.parseInt(retryAfterRaw, 10);
3488
+ return new HostedApiError({
3489
+ status: res.status,
3490
+ code,
3491
+ message,
3492
+ ...Number.isFinite(retryAfter) && retryAfter >= 0 ? { retryAfterSeconds: retryAfter } : {}
3493
+ });
3494
+ }
3495
+ function sleep(ms) {
3496
+ return new Promise((resolve) => setTimeout(resolve, ms));
3497
+ }
3498
+
3499
+ // src/verification/result.ts
3500
+ var RETRYABLE_REASONS = /* @__PURE__ */ new Set([
3501
+ "no_face",
3502
+ "media_unreadable",
3503
+ "clip_too_short",
3504
+ "no_face_source",
3505
+ "side_missing",
3506
+ "unreadable",
3507
+ "registry_unavailable",
3508
+ "otp_mismatch",
3509
+ "otp_expired",
3510
+ "otp_send_failed"
3511
+ ]);
3512
+ var BIOMETRIC_CHECKS = /* @__PURE__ */ new Set(["liveness", "face_match"]);
3513
+ function isExecutable(step) {
3514
+ return step !== void 0 && (step.state === "pending" || step.state === "input_required");
3515
+ }
3516
+ function isTerminalView(view) {
3517
+ return view.status !== "created" && view.status !== "in_progress";
3518
+ }
3519
+ function frontierStep(view) {
3520
+ return view.steps.find((step) => isExecutable(step));
3521
+ }
3522
+ function stepOf(view, checkType) {
3523
+ return view.steps.find((step) => step.checkType === checkType);
3524
+ }
3525
+ function mergeSessionView(prev, next, submitted) {
3526
+ const byType = new Map(prev.steps.map((step) => [step.checkType, step]));
3527
+ const steps = next.steps.map((step) => {
3528
+ const before = byType.get(step.checkType);
3529
+ const attemptsBefore = before?.attemptsRemaining ?? 0;
3530
+ const merged = {
3531
+ ...before ?? {},
3532
+ checkType: step.checkType,
3533
+ state: step.state,
3534
+ attemptsRemaining: step.checkType === submitted ? Math.max(0, attemptsBefore - 1) : attemptsBefore
3535
+ };
3536
+ if (step.reason !== void 0) merged.reason = step.reason;
3537
+ else delete merged.reason;
3538
+ return merged;
3539
+ });
3540
+ return { ...prev, status: next.status, outcome: next.outcome, steps, expiresAt: next.expiresAt };
3541
+ }
3542
+ function unavailable(sessionId, reason) {
3543
+ return reason === void 0 ? { sessionId, status: "unavailable" } : { sessionId, status: "unavailable", reason };
3544
+ }
3545
+ function withReason(sessionId, status, reason) {
3546
+ return reason === void 0 ? { sessionId, status } : { sessionId, status, reason };
3547
+ }
3548
+ function mapSessionResult(view, opts) {
3549
+ const { sessionId } = view;
3550
+ switch (view.status) {
3551
+ case "completed":
3552
+ if (view.outcome === "approved") return { sessionId, status: "approved" };
3553
+ if (view.outcome === "review") return withReason(sessionId, "review", reasonIn(view, "review"));
3554
+ return withReason(sessionId, "rejected", reasonIn(view, "failed"));
3555
+ case "failed":
3556
+ return withReason(sessionId, "rejected", reasonIn(view, "failed"));
3557
+ case "review_pending":
3558
+ return withReason(sessionId, "review", reasonIn(view, "review"));
3559
+ case "expired":
3560
+ return unavailable(sessionId);
3561
+ case "created":
3562
+ case "in_progress":
3563
+ break;
3564
+ default: {
3565
+ const unhandled = view.status;
3566
+ throw new Error(`mapSessionResult: unhandled status ${unhandled}`);
3567
+ }
3568
+ }
3569
+ const parked = view.steps.find(
3570
+ (step) => BIOMETRIC_CHECKS.has(step.checkType) && step.state === "input_required" && step.reason !== void 0
3571
+ );
3572
+ if (parked?.reason !== void 0) {
3573
+ const canRetry = opts.autoRetry && RETRYABLE_REASONS.has(parked.reason) && parked.attemptsRemaining > 0;
3574
+ return {
3575
+ sessionId,
3576
+ status: canRetry ? "retry" : "rejected",
3577
+ reason: parked.reason,
3578
+ attemptsRemaining: parked.attemptsRemaining
3579
+ };
3580
+ }
3581
+ if (frontierStep(view) === void 0 && view.steps.some((step) => step.state === "review")) {
3582
+ return withReason(sessionId, "review", reasonIn(view, "review"));
3583
+ }
3584
+ return unavailable(sessionId);
3585
+ }
3586
+ function reasonIn(view, state) {
3587
+ return view.steps.find((step) => step.state === state && step.reason !== void 0)?.reason;
3588
+ }
3589
+
3590
+ // src/verification/liveness-flow.ts
3591
+ var CLIP_MIME_ALLOWLIST = ["video/webm", "video/mp4"];
3592
+ var KEYFRAME_MIME = "image/jpeg";
3593
+ var TRANSPORT_REPLAY_ATTEMPTS = 2;
3594
+ var TRANSPORT_REPLAY_DELAY_MS = 1e3;
3595
+ var MAX_RETRY_AFTER_MS = 1e4;
3596
+ var RESYNC_REENTRY_MAX = 3;
3597
+ var TRANSPORT_CODES = /* @__PURE__ */ new Set([
3598
+ "network_error",
3599
+ "timeout",
3600
+ "upload_failed",
3601
+ "unknown_error",
3602
+ "rate_limit_exceeded"
3603
+ ]);
3604
+ var RESYNC_CODES = /* @__PURE__ */ new Set([
3605
+ "session_not_active",
3606
+ "check_not_found",
3607
+ "check_already_finalized",
3608
+ "check_out_of_order"
3609
+ ]);
3610
+ var AttestationError = class extends Error {
3611
+ constructor(message) {
3612
+ super(message);
3613
+ this.name = "AttestationError";
3614
+ }
3615
+ };
3616
+ async function runSubmission(rt, executor, hooks = {}) {
3617
+ let key = rt.uuid();
3618
+ let consentRecovered = false;
3619
+ let attestationRetried = false;
3620
+ let transportReplays = 0;
3621
+ for (; ; ) {
3622
+ try {
3623
+ return await executor(rt.client, key);
3624
+ } catch (err) {
3625
+ if (err instanceof AttestationError) {
3626
+ if (attestationRetried) throw err;
3627
+ attestationRetried = true;
3628
+ hooks.onAttestationInvalid?.();
3629
+ key = rt.uuid();
3630
+ continue;
3631
+ }
3632
+ if (!(err instanceof HostedApiError)) throw err;
3633
+ if (err.code === "consent_required" && !consentRecovered) {
3634
+ consentRecovered = true;
3635
+ await rt.ensureConsent({ force: true });
3636
+ key = rt.uuid();
3637
+ continue;
3638
+ }
3639
+ if (err.code === "attestation_invalid" && !attestationRetried) {
3640
+ attestationRetried = true;
3641
+ hooks.onAttestationInvalid?.();
3642
+ key = rt.uuid();
3643
+ continue;
3644
+ }
3645
+ if (TRANSPORT_CODES.has(err.code) && transportReplays < TRANSPORT_REPLAY_ATTEMPTS) {
3646
+ transportReplays += 1;
3647
+ const retryAfterMs = err.retryAfterSeconds !== void 0 ? err.retryAfterSeconds * 1e3 : void 0;
3648
+ await rt.sleep(
3649
+ retryAfterMs !== void 0 ? Math.min(retryAfterMs, MAX_RETRY_AFTER_MS) : TRANSPORT_REPLAY_DELAY_MS
3650
+ );
3651
+ continue;
3652
+ }
3653
+ throw err;
3654
+ }
3655
+ }
3656
+ }
3657
+ var LIVENESS_CHAINABLE = /* @__PURE__ */ new Set(["passed", "review", "processing", "skipped"]);
3658
+ async function runLivenessFlow(deps) {
3659
+ const { artifacts } = deps;
3660
+ const clip = artifacts.clip;
3661
+ const bareMime = stripMimeParams(artifacts.clipMime ?? "");
3662
+ if (artifacts.degraded === "NO_RECORDER" || clip === void 0 || !CLIP_MIME_ALLOWLIST.includes(bareMime)) {
3663
+ return { kind: "unavailable", reason: "no_recorder" };
3664
+ }
3665
+ const submitLiveness = buildLivenessSubmit(deps, clip, bareMime);
3666
+ const submitFaceMatch = buildFaceMatchSubmit(deps, artifacts.keyframe);
3667
+ let livenessSubmitted = false;
3668
+ let faceMatchSubmitted = false;
3669
+ let livenessChainable = true;
3670
+ let resyncs = 0;
3671
+ for (; ; ) {
3672
+ if (deps.isCancelled()) return { kind: "cancelled" };
3673
+ const view = deps.getView();
3674
+ if (isTerminalView(view)) return { kind: "settled" };
3675
+ const frontier = frontierStep(view)?.checkType;
3676
+ const next = frontier === "liveness" && !livenessSubmitted ? "liveness" : frontier === "face_match" && !faceMatchSubmitted && livenessChainable ? "face_match" : null;
3677
+ if (next === null) return { kind: "settled" };
3678
+ try {
3679
+ if (next === "liveness") {
3680
+ livenessSubmitted = true;
3681
+ const response = await submitLiveness();
3682
+ if (deps.isCancelled()) return { kind: "cancelled" };
3683
+ deps.applySubmit(response, "liveness");
3684
+ const state = stepOf(deps.getView(), "liveness")?.state;
3685
+ livenessChainable = state === void 0 || LIVENESS_CHAINABLE.has(state);
3686
+ } else {
3687
+ faceMatchSubmitted = true;
3688
+ const response = await submitFaceMatch();
3689
+ if (deps.isCancelled()) return { kind: "cancelled" };
3690
+ deps.applySubmit(response, "face_match");
3691
+ }
3692
+ } catch (err) {
3693
+ if (deps.isCancelled()) return { kind: "cancelled" };
3694
+ const outcome = classifyFailure(err);
3695
+ if (outcome.kind !== "resync" || resyncs >= RESYNC_REENTRY_MAX) return outcome;
3696
+ resyncs += 1;
3697
+ await deps.refreshView();
3698
+ }
3699
+ }
3700
+ }
3701
+ function buildLivenessSubmit(deps, clip, bareMime) {
3702
+ let clipKey = null;
3703
+ let attestation = null;
3704
+ return () => runSubmission(
3705
+ deps,
3706
+ async (client, idempotencyKey) => {
3707
+ if (clipKey === null) {
3708
+ deps.onPhase("uploading");
3709
+ const presigned = await client.presign("clip", bareMime, clip.size);
3710
+ await client.uploadToSpaces(presigned.uploadUrl, clip, bareMime);
3711
+ clipKey = (await client.completeMedia(presigned.key)).key;
3712
+ }
3713
+ if (attestation === null) {
3714
+ try {
3715
+ attestation = await deps.getAttestation();
3716
+ } catch (err) {
3717
+ throw new AttestationError(err instanceof Error ? err.message : String(err));
3718
+ }
3719
+ }
3720
+ deps.onPhase("checking");
3721
+ return client.submitCheck(
3722
+ "liveness",
3723
+ { clipKey, attestation, captureChannel: deps.artifacts.captureChannel },
3724
+ { idempotencyKey }
3725
+ );
3726
+ },
3727
+ {
3728
+ onAttestationInvalid: () => {
3729
+ attestation = null;
3730
+ }
3731
+ }
3732
+ );
3733
+ }
3734
+ function buildFaceMatchSubmit(deps, keyframe) {
3735
+ let imageKey = null;
3736
+ return () => runSubmission(deps, async (client, idempotencyKey) => {
3737
+ if (imageKey === null) {
3738
+ deps.onPhase("uploading");
3739
+ const presigned = await client.presign("image", KEYFRAME_MIME, keyframe.size);
3740
+ await client.uploadToSpaces(presigned.uploadUrl, keyframe, KEYFRAME_MIME);
3741
+ imageKey = (await client.completeMedia(presigned.key)).key;
3742
+ }
3743
+ deps.onPhase("checking");
3744
+ return client.submitCheck("face_match", { imageKey }, { idempotencyKey });
3745
+ });
3746
+ }
3747
+ function classifyFailure(err) {
3748
+ if (err instanceof AttestationError) return { kind: "unavailable", reason: "attestation" };
3749
+ if (err instanceof HostedApiError) {
3750
+ if (err.code === "attestation_invalid") return { kind: "unavailable", reason: "attestation" };
3751
+ if (RESYNC_CODES.has(err.code)) return { kind: "resync" };
3752
+ }
3753
+ return { kind: "unavailable", reason: "network" };
3754
+ }
3755
+
3756
+ // src/verification/turnstile.ts
3757
+ var TURNSTILE_SCRIPT_SRC = "https://challenges.cloudflare.com/turnstile/v0/api.js";
3758
+ var TURNSTILE_EXECUTE_TIMEOUT_MS = 3e4;
3759
+ function installedApi() {
3760
+ return window.turnstile;
3761
+ }
3762
+ var loaderPromise = null;
3763
+ function resetTurnstileForTests() {
3764
+ loaderPromise = null;
3765
+ }
3766
+ function loadTurnstile() {
3767
+ loaderPromise ?? (loaderPromise = new Promise((resolve, reject) => {
3768
+ const present = installedApi();
3769
+ if (present) {
3770
+ resolve(present);
3771
+ return;
3772
+ }
3773
+ const script = document.createElement("script");
3774
+ script.src = TURNSTILE_SCRIPT_SRC;
3775
+ script.async = true;
3776
+ script.onload = () => {
3777
+ const api = installedApi();
3778
+ if (api) {
3779
+ resolve(api);
3780
+ } else {
3781
+ loaderPromise = null;
3782
+ reject(new Error("Turnstile script loaded but exposed no API"));
3783
+ }
3784
+ };
3785
+ script.onerror = () => {
3786
+ loaderPromise = null;
3787
+ script.remove();
3788
+ reject(new Error("Turnstile script failed to load"));
3789
+ };
3790
+ document.head.appendChild(script);
3791
+ }));
3792
+ return loaderPromise;
3793
+ }
3794
+ function abortError() {
3795
+ return new Error("Turnstile challenge aborted");
3796
+ }
3797
+ async function executeTurnstile(siteKey, opts = {}) {
3798
+ const timeoutMs = opts.timeoutMs ?? TURNSTILE_EXECUTE_TIMEOUT_MS;
3799
+ const signal = opts.signal;
3800
+ if (signal?.aborted) throw abortError();
3801
+ const api = await loadTurnstile();
3802
+ if (signal?.aborted) throw abortError();
3803
+ const container = document.createElement("div");
3804
+ document.body.appendChild(container);
3805
+ let widgetId;
3806
+ let timer;
3807
+ let onAbort;
3808
+ try {
3809
+ return await new Promise((resolve, reject) => {
3810
+ timer = setTimeout(
3811
+ () => reject(new Error(`Turnstile challenge timed out (${timeoutMs} ms)`)),
3812
+ timeoutMs
3813
+ );
3814
+ if (signal !== void 0) {
3815
+ onAbort = () => reject(abortError());
3816
+ signal.addEventListener("abort", onAbort, { once: true });
3817
+ }
3818
+ widgetId = api.render(container, {
3819
+ sitekey: siteKey,
3820
+ execution: "execute",
3821
+ appearance: "execute",
3822
+ callback: resolve,
3823
+ "error-callback": (code) => {
3824
+ reject(new Error(`Turnstile challenge failed${code ? ` (${code})` : ""}`));
3825
+ }
3826
+ });
3827
+ if (widgetId === void 0) {
3828
+ reject(new Error("Turnstile render returned no widget id"));
3829
+ return;
3830
+ }
3831
+ api.execute(widgetId);
3832
+ });
3833
+ } finally {
3834
+ clearTimeout(timer);
3835
+ if (signal !== void 0 && onAbort !== void 0) signal.removeEventListener("abort", onAbort);
3836
+ if (widgetId !== void 0) {
3837
+ try {
3838
+ api.remove(widgetId);
3839
+ } catch {
3840
+ }
3841
+ }
3842
+ container.remove();
3843
+ }
3844
+ }
3845
+
3846
+ // src/verification/create-verification.ts
3847
+ var DEFAULT_API_ORIGIN = "https://api.sekyro.ai";
3848
+ var REGISTRY_RETRY_DELAY_MS = 5e3;
3849
+ var PROCESSING_POLL_DELAY_MS = 1500;
3850
+ var PROCESSING_POLL_MAX = 10;
3851
+ function defaultSleep(ms) {
3852
+ return new Promise((resolve) => setTimeout(resolve, ms));
3853
+ }
3854
+ function randomUuid() {
3855
+ const c2 = globalThis.crypto;
3856
+ if (c2 !== void 0 && typeof c2.randomUUID === "function") return c2.randomUUID();
3857
+ const bytes = new Uint8Array(16);
3858
+ if (c2 !== void 0 && typeof c2.getRandomValues === "function") c2.getRandomValues(bytes);
3859
+ else for (let i2 = 0; i2 < 16; i2 += 1) bytes[i2] = Math.floor(Math.random() * 256);
3860
+ bytes[6] = (bytes[6] ?? 0) & 15 | 64;
3861
+ bytes[8] = (bytes[8] ?? 0) & 63 | 128;
3862
+ const hex = [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
3863
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
3864
+ }
3865
+ function createVerificationInternal(options, internals) {
3866
+ const apiOrigin = options.apiOrigin ?? DEFAULT_API_ORIGIN;
3867
+ const autoRetry = options.autoRetry ?? true;
3868
+ const rearm = options.rearm ?? "auto";
3869
+ const client = internals.client ?? new HostedClient({
3870
+ apiOrigin,
3871
+ sessionToken: options.clientToken,
3872
+ ...options.fetch !== void 0 ? { fetch: options.fetch } : {}
3873
+ });
3874
+ const sleep2 = internals.sleep ?? defaultSleep;
3875
+ const uuid = internals.uuid ?? randomUuid;
3876
+ const getTurnstileToken = internals.getTurnstileToken ?? executeTurnstile;
3877
+ const emitter = createEmitter();
3878
+ let destroyed = false;
3879
+ const lifetime = new AbortController();
3880
+ let view = null;
3881
+ let bootstrap = null;
3882
+ const setView = (next) => {
3883
+ view = next;
3884
+ emitter.emit("view", next);
3885
+ };
3886
+ const ensureView = () => {
3887
+ if (view !== null) return Promise.resolve(view);
3888
+ bootstrap ?? (bootstrap = client.getSession().then((next) => {
3889
+ setView(next);
3890
+ return next;
3891
+ }).finally(() => {
3892
+ bootstrap = null;
3893
+ }));
3894
+ return bootstrap;
3895
+ };
3896
+ const refreshView = async () => {
3897
+ const next = await client.getSession();
3898
+ setView(next);
3899
+ return next;
3900
+ };
3901
+ const applySubmit = (response, submitted) => {
3902
+ if (view !== null) setView(mergeSessionView(view, response, submitted));
3903
+ };
3904
+ let consentInFlight = null;
3905
+ const recordConsent = async (force) => {
3906
+ const current = await ensureView();
3907
+ if (!force && current.consentRecorded) return;
3908
+ await client.recordConsent(options.locale);
3909
+ if (view !== null) setView({ ...view, consentRecorded: true });
3910
+ };
3911
+ const ensureConsent = (opts) => {
3912
+ if (opts?.force === true) return recordConsent(true);
3913
+ consentInFlight ?? (consentInFlight = recordConsent(false).finally(() => {
3914
+ consentInFlight = null;
3915
+ }));
3916
+ return consentInFlight;
3917
+ };
3918
+ const runtime = {
3919
+ client,
3920
+ ensureConsent: (opts) => ensureConsent(opts),
3921
+ sleep: sleep2,
3922
+ uuid
3923
+ };
3924
+ let terminalEmitted = false;
3925
+ const emitResult = (result) => {
3926
+ if (result.status === "approved" || result.status === "rejected" || result.status === "review") {
3927
+ if (terminalEmitted) return;
3928
+ terminalEmitted = true;
3929
+ }
3930
+ emitter.emit("result", result);
3931
+ };
3932
+ let registry = null;
3933
+ let registryFailed = false;
3934
+ let registryUnbound = false;
3935
+ const submitRegistry = () => runSubmission(
3936
+ runtime,
3937
+ (c2, idempotencyKey) => (
3938
+ // `{}` input: the session is bound to a SERVER-provided NNI (Plan A Task 2).
3939
+ c2.submitCheck("population_registry", {}, { idempotencyKey })
3940
+ )
3941
+ );
3942
+ const runRegistry = async () => {
3943
+ try {
3944
+ const current = await ensureView();
3945
+ if (isTerminalView(current) || frontierStep(current)?.checkType !== "population_registry") {
3946
+ return;
3947
+ }
3948
+ if (current.nniBound !== true) {
3949
+ registryUnbound = true;
3950
+ return;
3951
+ }
3952
+ await ensureConsent();
3953
+ applySubmit(await submitRegistry(), "population_registry");
3954
+ const step = view === null ? void 0 : stepOf(view, "population_registry");
3955
+ if (step?.state === "input_required" && step.reason === "registry_unavailable" && step.attemptsRemaining > 0) {
3956
+ await sleep2(REGISTRY_RETRY_DELAY_MS);
3957
+ if (destroyed) return;
3958
+ applySubmit(await submitRegistry(), "population_registry");
3959
+ }
3960
+ } catch {
3961
+ registryFailed = true;
3962
+ return;
3963
+ }
3964
+ if (view !== null && isTerminalView(view)) emitResult(mapSessionResult(view, { autoRetry }));
3965
+ };
3966
+ const startRegistry = () => {
3967
+ registry ?? (registry = runRegistry());
3968
+ return registry;
3969
+ };
3970
+ const getAttestation = async () => {
3971
+ const current = await ensureView();
3972
+ const siteKey = current.turnstileSiteKey;
3973
+ if (siteKey === null) return { sandbox: true };
3974
+ return {
3975
+ channel: "hosted_web",
3976
+ siteKey,
3977
+ turnstileToken: await getTurnstileToken(siteKey, { signal: lifetime.signal })
3978
+ };
3979
+ };
3980
+ let active = null;
3981
+ let chain = Promise.resolve();
3982
+ let chainDepth = 0;
3983
+ const settleProcessing = async () => {
3984
+ let current = await ensureView();
3985
+ for (let i2 = 0; i2 < PROCESSING_POLL_MAX && !destroyed && !isTerminalView(current) && frontierStep(current) === void 0 && current.steps.some((step) => step.state === "processing"); i2 += 1) {
3986
+ await sleep2(PROCESSING_POLL_DELAY_MS);
3987
+ if (destroyed) break;
3988
+ current = await refreshView();
3989
+ }
3990
+ return current;
3991
+ };
3992
+ const runFlow = async (bound, artifacts, capturedAttempt) => {
3993
+ const { capture } = bound;
3994
+ const isCancelled = () => destroyed;
3995
+ const ownsHandle = () => bound.alive && bound.attempt === capturedAttempt;
3996
+ const setPhase = (phase) => {
3997
+ if (ownsHandle()) capture.setFlowState(phase);
3998
+ };
3999
+ const finish = (result) => {
4000
+ if (isCancelled()) return;
4001
+ emitResult(result);
4002
+ if (!ownsHandle()) return;
4003
+ if (result.status === "retry" && rearm === "auto") {
4004
+ capture.handle.retry();
4005
+ return;
4006
+ }
4007
+ capture.setFlowState("done");
4008
+ };
4009
+ if (artifacts.degraded === "NO_RECORDER") {
4010
+ const sessionId = view?.sessionId ?? (await ensureView().catch(() => null))?.sessionId ?? "";
4011
+ finish(unavailable(sessionId, "no_recorder"));
4012
+ return;
4013
+ }
4014
+ setPhase("uploading");
4015
+ try {
4016
+ await startRegistry();
4017
+ if (isCancelled()) return;
4018
+ let current = await ensureView();
4019
+ if (!isTerminalView(current)) {
4020
+ if (frontierStep(current)?.checkType === "population_registry") {
4021
+ finish(
4022
+ unavailable(
4023
+ current.sessionId,
4024
+ registryUnbound ? "nni_unbound" : registryFailed ? "network" : "registry_unavailable"
4025
+ )
4026
+ );
4027
+ return;
4028
+ }
4029
+ await ensureConsent();
4030
+ if (isCancelled()) return;
4031
+ const outcome = await runLivenessFlow({
4032
+ ...runtime,
4033
+ artifacts,
4034
+ getAttestation,
4035
+ getView: () => view ?? current,
4036
+ refreshView,
4037
+ applySubmit,
4038
+ onPhase: setPhase,
4039
+ isCancelled
4040
+ });
4041
+ if (isCancelled()) return;
4042
+ if (outcome.kind === "unavailable") {
4043
+ finish(unavailable(current.sessionId, outcome.reason));
4044
+ return;
4045
+ }
4046
+ if (outcome.kind === "resync") await refreshView();
4047
+ current = await settleProcessing();
4048
+ }
4049
+ finish(mapSessionResult(current, { autoRetry }));
4050
+ } catch {
4051
+ if (isCancelled()) return;
4052
+ finish(unavailable(view?.sessionId ?? "", "network"));
4053
+ }
4054
+ };
4055
+ const enqueueFlow = (bound, artifacts) => {
4056
+ const capturedAttempt = bound.attempt;
4057
+ if (chainDepth > 0 && bound.alive) {
4058
+ bound.capture.setFlowState("uploading");
4059
+ }
4060
+ chainDepth += 1;
4061
+ chain = chain.then(() => runFlow(bound, artifacts, capturedAttempt)).finally(() => {
4062
+ chainDepth -= 1;
4063
+ }).catch(() => void 0);
4064
+ };
4065
+ const liveness = (captureOptions) => {
4066
+ active?.capture.handle.destroy();
4067
+ if (active !== null) active.alive = false;
4068
+ const capture = createLivenessCaptureInternal(captureOptions, internals.capture);
4069
+ const bound = { capture, alive: true, attempt: 0 };
4070
+ active = bound;
4071
+ capture.handle.on("state", (state) => {
4072
+ if (state === "starting") bound.attempt += 1;
4073
+ });
4074
+ capture.handle.on("captured", (artifacts) => {
4075
+ void Promise.resolve().then(() => enqueueFlow(bound, artifacts));
4076
+ });
4077
+ const inner = capture.handle;
4078
+ return {
4079
+ get state() {
4080
+ return inner.state;
4081
+ },
4082
+ on: (event, handler) => inner.on(event, handler),
4083
+ start: () => inner.start(),
4084
+ retry: () => inner.retry(),
4085
+ switchCamera: () => inner.switchCamera(),
4086
+ destroy: () => {
4087
+ bound.alive = false;
4088
+ if (active === bound) active = null;
4089
+ inner.destroy();
4090
+ }
4091
+ };
4092
+ };
4093
+ return {
4094
+ consent: () => ensureConsent(),
4095
+ startRegistry,
4096
+ liveness,
4097
+ on: (event, handler) => emitter.on(event, handler),
4098
+ destroy: () => {
4099
+ destroyed = true;
4100
+ lifetime.abort();
4101
+ if (active !== null) {
4102
+ active.alive = false;
4103
+ active.capture.handle.destroy();
4104
+ active = null;
4105
+ }
4106
+ emitter.clear();
4107
+ }
4108
+ };
4109
+ }
4110
+ // Annotate the CommonJS export names for ESM import in node:
4111
+ 0 && (module.exports = {
4112
+ ASPECT_BANDS,
4113
+ AttestationError,
4114
+ CAPTURE_CANDIDATE_SPACING_MS,
4115
+ CAPTURE_EXTRA_CANDIDATES,
4116
+ CENTERED_FACTOR,
4117
+ CIRCLE_RADIUS_FACTOR,
4118
+ CLIP_MIME_ALLOWLIST,
4119
+ CaptureSessionDoc,
4120
+ DOC_ANALYSIS_DEFAULTS,
4121
+ DOC_CADENCE_HZ,
4122
+ DOC_DETECT_WIDTH,
4123
+ DOC_FEEDBACK_STATES,
4124
+ DOC_GATE_V1_DEFAULTS,
4125
+ DocFeedbackAggregator,
4126
+ DocGateV1,
4127
+ IN_CIRCLE_FACTOR,
4128
+ MRZ_BAND_DEFAULTS,
4129
+ MR_DOC_CATALOG,
4130
+ PROCESSING_POLL_DELAY_MS,
4131
+ PROCESSING_POLL_MAX,
4132
+ REGISTRY_RETRY_DELAY_MS,
4133
+ RETRYABLE_REASONS,
4134
+ TRANSPORT_REPLAY_ATTEMPTS,
4135
+ TRANSPORT_REPLAY_DELAY_MS,
4136
+ TURNSTILE_EXECUTE_TIMEOUT_MS,
4137
+ TURNSTILE_SCRIPT_SRC,
4138
+ analyzeDocFrame,
4139
+ aspectBand,
4140
+ createLivenessCaptureInternal,
4141
+ createVerificationInternal,
4142
+ detectMrzBand,
4143
+ executeTurnstile,
4144
+ feedbackVoteOf,
4145
+ frontierStep,
4146
+ isExecutable,
4147
+ isTerminalView,
4148
+ loadTurnstile,
4149
+ mapEngineState,
4150
+ mapErrorKind,
4151
+ mapGuidanceHint,
4152
+ mapSessionResult,
4153
+ mergeSessionView,
4154
+ quadAreaFrac,
4155
+ quadBounds,
4156
+ quadIou,
4157
+ quadTiltRatio,
4158
+ randomUuid,
4159
+ resetTurnstileForTests,
4160
+ runLivenessFlow,
4161
+ runSubmission,
4162
+ specularFraction,
4163
+ stepOf,
4164
+ warmDocDetector
4165
+ });
4166
+ //# sourceMappingURL=index.cjs.map