@sekyro/web 0.1.0-rc.2 → 0.1.0-rc.20

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 (133) hide show
  1. package/CHANGELOG.md +300 -0
  2. package/LICENSE +25 -16
  3. package/README.md +111 -60
  4. package/THIRD-PARTY-NOTICES.txt +154 -0
  5. package/dist/background-monitor-A7FKJOAG.js +1 -0
  6. package/dist/camera-trait-45MJTW4K.js +1 -0
  7. package/dist/capture-constraints-B5omafmk.d.cts +44 -0
  8. package/dist/capture-constraints-B5omafmk.d.ts +44 -0
  9. package/dist/capture-session-doc-QA4DOFRF.js +1 -0
  10. package/dist/{capture-session-v3-CAoWM8iT.d.cts → capture-session-v3-CNL-GX11.d.cts} +185 -15
  11. package/dist/{capture-session-v3-BJ8ciaWl.d.ts → capture-session-v3-DaBqN8fO.d.ts} +185 -15
  12. package/dist/chunk-5ZKQHFFW.js +1 -0
  13. package/dist/chunk-7ZCZY3ZP.js +1 -0
  14. package/dist/chunk-A3FUGHAH.js +2 -0
  15. package/dist/chunk-BPE5NSQ2.js +1 -0
  16. package/dist/chunk-CJHMFPL6.js +1 -0
  17. package/dist/chunk-CQ7SKLMC.js +1 -0
  18. package/dist/chunk-DFTCAWMP.js +1 -0
  19. package/dist/chunk-DK5YPBDQ.js +1 -0
  20. package/dist/chunk-FGOVIGGL.js +1 -0
  21. package/dist/chunk-FPXL63KZ.js +1 -0
  22. package/dist/chunk-FUHDOEBP.js +1 -0
  23. package/dist/chunk-G6LKLN4U.js +1 -0
  24. package/dist/chunk-GI3UFGRQ.js +1 -0
  25. package/dist/chunk-GT2ZLGF7.js +1 -0
  26. package/dist/chunk-IG466TOP.js +1 -0
  27. package/dist/chunk-KHR4U2SZ.js +1 -0
  28. package/dist/chunk-KZBBB5B2.js +1 -0
  29. package/dist/chunk-MXWLCDFX.js +1 -0
  30. package/dist/chunk-NJML6FMD.js +1 -0
  31. package/dist/chunk-O5WKNZ2C.js +1 -0
  32. package/dist/chunk-OKWG3PVH.js +1 -0
  33. package/dist/chunk-POIQGEZM.js +1 -0
  34. package/dist/chunk-RI3E7GBN.js +1 -0
  35. package/dist/chunk-SMKCBUJL.js +1 -0
  36. package/dist/chunk-TDLIXFDT.js +1 -0
  37. package/dist/chunk-TQB3URP2.js +1 -0
  38. package/dist/chunk-U6S7SCBY.js +1 -0
  39. package/dist/chunk-U6TYL2IJ.js +1 -0
  40. package/dist/chunk-W2WD7PR2.js +1 -0
  41. package/dist/chunk-XCKE2MJL.js +1 -0
  42. package/dist/chunk-ZLWH4RBO.js +1 -0
  43. package/dist/client/index.cjs +1 -357
  44. package/dist/client/index.d.cts +6 -37
  45. package/dist/client/index.d.ts +6 -37
  46. package/dist/client/index.js +1 -15
  47. package/dist/core/index.cjs +1 -1605
  48. package/dist/core/index.d.cts +5 -4
  49. package/dist/core/index.d.ts +5 -4
  50. package/dist/core/index.js +1 -139
  51. package/dist/core/ocr/worker.bundle.js +42 -0
  52. package/dist/core/ocr/worker.cjs +42 -0
  53. package/dist/core/ocr/worker.d.cts +84 -0
  54. package/dist/core/ocr/worker.d.ts +84 -0
  55. package/dist/core/ocr/worker.js +41 -0
  56. package/dist/core/v3/detect-worker.cjs +1 -392
  57. package/dist/core/v3/detect-worker.d.cts +1 -1
  58. package/dist/core/v3/detect-worker.d.ts +1 -1
  59. package/dist/core/v3/detect-worker.js +1 -13
  60. package/dist/create-document-capture-GJXBQMTC.js +1 -0
  61. package/dist/create-portrait-capture-MOS2D7CL.js +1 -0
  62. package/dist/create-verification-BBOUYpga.d.cts +3274 -0
  63. package/dist/create-verification-COpe2hxf.d.ts +3274 -0
  64. package/dist/{detect-worker-CKXHlXx9.d.cts → detect-worker-DclNxkZT.d.cts} +6 -0
  65. package/dist/{detect-worker-CKXHlXx9.d.ts → detect-worker-DclNxkZT.d.ts} +6 -0
  66. package/dist/detector-scanic-YCDNLCGV.js +1 -0
  67. package/dist/icao-gate-CEGvJR3q.d.ts +534 -0
  68. package/dist/icao-gate-PWBMKRGC.js +1 -0
  69. package/dist/icao-gate-l40OU6x1.d.cts +534 -0
  70. package/dist/icao-policy-BgI1Y870.d.ts +71 -0
  71. package/dist/icao-policy-C7fIdRzo.d.cts +71 -0
  72. package/dist/icao-tuning-4GGVX6B4.js +1 -0
  73. package/dist/index.cjs +1 -2636
  74. package/dist/index.d.cts +110 -5
  75. package/dist/index.d.ts +110 -5
  76. package/dist/index.js +1 -28
  77. package/dist/internal/index.cjs +1 -4166
  78. package/dist/internal/index.d.cts +365 -324
  79. package/dist/internal/index.d.ts +365 -324
  80. package/dist/internal/index.js +1 -647
  81. package/dist/keyframe-rank-YAJLYJYF.js +1 -0
  82. package/dist/landmarker-KB7LVXAU.js +1 -0
  83. package/dist/mrz-band-VYHOTDHY.js +1 -0
  84. package/dist/plan-runner-35655N4Z.js +1 -0
  85. package/dist/popup/index.cjs +1 -76
  86. package/dist/popup/index.d.cts +7 -1
  87. package/dist/popup/index.d.ts +7 -1
  88. package/dist/popup/index.js +1 -11
  89. package/dist/print-AYSCRSZB.js +1 -0
  90. package/dist/scanic-ml-stub-KW7IZHUT.js +1 -0
  91. package/dist/segmenter-USLNBX65.js +1 -0
  92. package/dist/turnstile-FATNZ4AG.js +1 -0
  93. package/dist/types-Dpfg2cO8.d.cts +1699 -0
  94. package/dist/types-Dpfg2cO8.d.ts +1699 -0
  95. package/dist/upload-file-UYXOHCRG.js +1 -0
  96. package/package.json +27 -11
  97. package/sbom.cdx.json +234 -0
  98. package/dist/capture-constraints-BujkZcfb.d.cts +0 -21
  99. package/dist/capture-constraints-BujkZcfb.d.ts +0 -21
  100. package/dist/chunk-BPYVZUJA.js +0 -852
  101. package/dist/chunk-BPYVZUJA.js.map +0 -1
  102. package/dist/chunk-LOTAJDRE.js +0 -1094
  103. package/dist/chunk-LOTAJDRE.js.map +0 -1
  104. package/dist/chunk-MWNFSNMP.js +0 -52
  105. package/dist/chunk-MWNFSNMP.js.map +0 -1
  106. package/dist/chunk-NILNKLK6.js +0 -50
  107. package/dist/chunk-NILNKLK6.js.map +0 -1
  108. package/dist/chunk-NWF46H7K.js +0 -359
  109. package/dist/chunk-NWF46H7K.js.map +0 -1
  110. package/dist/chunk-WY6U7AIK.js +0 -193
  111. package/dist/chunk-WY6U7AIK.js.map +0 -1
  112. package/dist/chunk-YVFF4Q4G.js +0 -327
  113. package/dist/chunk-YVFF4Q4G.js.map +0 -1
  114. package/dist/client/index.cjs.map +0 -1
  115. package/dist/client/index.js.map +0 -1
  116. package/dist/core/index.cjs.map +0 -1
  117. package/dist/core/index.js.map +0 -1
  118. package/dist/core/v3/detect-worker.cjs.map +0 -1
  119. package/dist/core/v3/detect-worker.js.map +0 -1
  120. package/dist/create-verification-CjLnJ0w6.d.ts +0 -348
  121. package/dist/create-verification-EnZ13uY4.d.cts +0 -348
  122. package/dist/detector-scanic-4C6IEW2K.js +0 -787
  123. package/dist/detector-scanic-4C6IEW2K.js.map +0 -1
  124. package/dist/hosted-client-BpvBqu9f.d.cts +0 -408
  125. package/dist/hosted-client-BpvBqu9f.d.ts +0 -408
  126. package/dist/index.cjs.map +0 -1
  127. package/dist/index.js.map +0 -1
  128. package/dist/internal/index.cjs.map +0 -1
  129. package/dist/internal/index.js.map +0 -1
  130. package/dist/popup/index.cjs.map +0 -1
  131. package/dist/popup/index.js.map +0 -1
  132. package/dist/scanic-ml-stub-S2OZ6HEF.js +0 -10
  133. package/dist/scanic-ml-stub-S2OZ6HEF.js.map +0 -1
@@ -1,4 +1,5 @@
1
- import { F as FaceObservation, b as Detector, W as WorkerLike } from './detect-worker-CKXHlXx9.js';
1
+ import { aS as ScreenRampReport, aK as CaptureProvenance, aQ as ScreenRampChallenge, aG as ScreenRampColour } from './types-Dpfg2cO8.js';
2
+ import { F as FaceObservation, b as Detector, W as WorkerLike } from './detect-worker-DclNxkZT.js';
2
3
 
3
4
  /** MP4-first ladder: one container (H.264 MP4) covers iOS/macOS Safari + Chrome 130+.
4
5
  * WebM/VP9→VP8 only as the Firefox/older-Chromium fallback. */
@@ -67,8 +68,14 @@ declare class ClipRecorder {
67
68
  * instead of waiting for the blob. PURE NOTIFICATION — it does not touch
68
69
  * timers, chunks, or the finalize path, so it is calibration-neutral (no
69
70
  * effect on clip bytes). Never fires on a rejected capture (error /
70
- * cliptoolarge settle before the hard-stop and clear the timer). */
71
- record(stream: MediaStream, onStopped?: () => void): Promise<ClipResult>;
71
+ * cliptoolarge settle before the hard-stop and clear the timer).
72
+ *
73
+ * `onStarted` (optional, liveness v7 §4.4) fires ONCE on the recorder's
74
+ * `start` event: the zero of the clip's own timeline, which the screen ramp
75
+ * stamps its colour changes against. PURE NOTIFICATION as well (the
76
+ * `onstart` handler was unset before; nothing else changes), so it is
77
+ * calibration-neutral. Never fires when construction or `start()` failed. */
78
+ record(stream: MediaStream, onStopped?: () => void, onStarted?: () => void): Promise<ClipResult>;
72
79
  /** Idempotent teardown: stop recorder + ALL tracks (v1 `stopAndCleanup` + the unmount
73
80
  * effect). Optional `stream` override mirrors v1's `stopAndCleanup(stream?)`.
74
81
  *
@@ -105,16 +112,39 @@ interface GateChecks {
105
112
  goodQuality: boolean;
106
113
  stable: boolean;
107
114
  }
115
+ /**
116
+ * Client-side capture timing (face-capture duration, 2026-10-17), measured
117
+ * by the engine with its monotonic clock (`performance.now()` by default) and
118
+ * rounded to whole milliseconds. All fields are optional: a phase that never
119
+ * happened (e.g. no face ever detected before a retry) is simply absent.
120
+ */
121
+ interface CaptureTiming {
122
+ /** `getUserMedia` call → stream attached and the preview playing. */
123
+ cameraReadyMs?: number;
124
+ /** Camera ready → the first tick on which the GATE accepted the face
125
+ * (present + size / centering / quality good enough to make progress —
126
+ * not merely detected). */
127
+ faceAcquireMs?: number;
128
+ /** FIRST accepted face → gate progress 100 % (capture complete, BEFORE the
129
+ * clip window / upload). A face lost and re-acquired keeps the first start. */
130
+ captureMs?: number;
131
+ }
108
132
  /** Capture output. Upload is NOT the engine's job — hosts submit these themselves. */
109
133
  interface CaptureArtifacts {
110
134
  /** Absent in photo mode. */
111
135
  clip?: Blob;
112
136
  /** Container mime the clip finalized with. Absent in photo mode. */
113
137
  clipMimeType?: string;
114
- /** Mirrored JPEG keyframe (captureMirroredKeyframe). */
138
+ /** JPEG keyframe (captureMirroredKeyframe): mirrored on the front camera, as the sensor sees it on the back one. */
115
139
  keyframe: Blob;
116
140
  /** JPEG data URL of the keyframe canvas (v1 preview, quality 0.92). */
117
141
  previewDataUrl: string;
142
+ /** Capture-phase timing of the attempt that produced these artifacts. */
143
+ timing?: CaptureTiming;
144
+ /** Liveness v7 §4.4: the screen ramp rendered against the session's issued challenge (clip mode, a challenge issued, a host painting). */
145
+ screenRamp?: ScreenRampReport;
146
+ /** Liveness v7 §4.5 item 2: how the capture was made (whenever the engine had a camera track). */
147
+ provenance?: CaptureProvenance;
118
148
  }
119
149
  interface CaptureSessionEvents {
120
150
  statechange: {
@@ -167,12 +197,13 @@ interface V3GateThresholds {
167
197
  /** Velocities at/below this (IOD/s) count as stillness — absorbs detector
168
198
  * box jitter (largest on LOW's 128px input) before it reaches the EMA. */
169
199
  MOTION_DEADBAND_IOD_PER_S: number;
170
- /** ready = p ≥ 1 AND mean q over this window ≥ READY_MEAN_Q. The mean is
171
- * TRIMMED: with ≥3 samples in the window the single worst is dropped, so
172
- * one flaky tick (5 Hz LOW cadence = only 2–3 samples per window) cannot
173
- * veto an otherwise-ready user. */
200
+ /** ready = p ≥ 1 AND no bad tick (q < Q_GOOD) left in this window after
201
+ * TRIMMING: with ≥3 samples the single worst is dropped, so one flaky tick
202
+ * (5 Hz LOW cadence = only 2–3 samples per window) cannot veto an
203
+ * otherwise-ready user, while a SECOND bad tick (a real sustained wobble)
204
+ * still blocks. The readiness bar is Q_GOOD itself — the level the
205
+ * integrator rises on — so any input that fills the ring also fires it. */
174
206
  READY_WINDOW_MS: number;
175
- READY_MEAN_Q: number;
176
207
  /** Per-factor guidance trigger levels (lowest failing factor speaks). */
177
208
  GUIDE_SIZE: number;
178
209
  GUIDE_CENTERING: number;
@@ -215,8 +246,12 @@ interface V3GateTick {
215
246
  factors: Record<V3GateFactor, number>;
216
247
  /** fcv3.* message key for the lowest failing factor (host translates). */
217
248
  guidanceKey: string;
218
- /** Fire signal: p ≥ 1 AND the READY_WINDOW mean q ≥ READY_MEAN_Q. */
249
+ /** Fire signal: p ≥ 1 AND no second bad tick (q < Q_GOOD) in READY_WINDOW_MS. */
219
250
  ready: boolean;
251
+ /** The face on THIS tick is ACCEPTED by the gate — present and every factor
252
+ * (size, centering, pose, sharpness, exposure, motion) good enough that the
253
+ * integrator RISES (q ≥ Q_GOOD). The engine's "first accepted face" mark. */
254
+ accepted: boolean;
220
255
  }
221
256
  declare class FaceGateV3 {
222
257
  private readonly t;
@@ -288,9 +323,56 @@ declare class DeviceProfiler {
288
323
  record(detectMs: number): DeviceClass;
289
324
  }
290
325
 
326
+ /** Where a capture failed: the engine step that was running. */
327
+ type CaptureErrorPhase = "preflight" | "acquiring" | "models" | "recording" | "keyframes" | "upload";
328
+ /** Engine-side failure detail (the public handle adds the engine kind). */
329
+ interface EngineErrorDetail {
330
+ phase: CaptureErrorPhase;
331
+ /** The thrown error's `name` only, sanitised by {@link errorNameOf}. */
332
+ name?: string;
333
+ }
334
+
335
+ /** Why a gate tick did not advance: no face, or the weakest gate check. */
336
+ type GateBlockReason = "no_face" | Exclude<V3GateFactor, "presence">;
337
+ interface GateBlockEntry {
338
+ /** Ticks blocked by this reason. */
339
+ count: number;
340
+ /** Wall time (whole ms) those ticks covered. */
341
+ ms: number;
342
+ }
343
+ interface GateBlockSummary {
344
+ /** Only the reasons that blocked at least once. */
345
+ blocked: Partial<Record<GateBlockReason, GateBlockEntry>>;
346
+ /** Wall time (whole ms) of ticks the gate accepted (progress rising). */
347
+ acceptedMs: number;
348
+ /** Total ticks seen. */
349
+ ticks: number;
350
+ }
351
+ /** The reason one tick was held back, or null when the gate accepted it. */
352
+ declare function blockReasonOf(tick: Pick<V3GateTick, "accepted" | "factors">): GateBlockReason | null;
353
+ declare class GateBlockStats {
354
+ private blocked;
355
+ private acceptedMs;
356
+ private ticks;
357
+ private lastAt;
358
+ /** Record one gate tick; the time since the previous tick is charged to THIS tick's state. */
359
+ record(tick: Pick<V3GateTick, "at" | "accepted" | "factors">): void;
360
+ summary(): GateBlockSummary;
361
+ }
362
+
363
+ /** A non-final `gate` telemetry snapshot at most this often while positioning
364
+ * (so an abandoned attempt still reports where its time went). */
365
+ declare const GATE_SNAPSHOT_MS = 1000;
366
+ /** Guidance key while a phone shows a landscape camera frame (the upright guard). */
367
+ declare const HOLD_UPRIGHT_KEY = "fcv3.hold_upright";
368
+ /** How often the upright guard re-reads the frame size while the clip records (plus every `resize` event). */
369
+ declare const UPRIGHT_WATCH_MS = 200;
291
370
  /** Best-of-N keyframe window: up to 4 candidates over the first 600ms. */
292
371
  declare const KEYFRAME_CANDIDATES = 4;
293
372
  declare const KEYFRAME_WINDOW_MS = 600;
373
+ /** Liveness v7 §4.5 item 2: the longest the capture waits on the track description (its WebCrypto hash) once the
374
+ * clip is done; past it the artifacts ship without `provenance`. */
375
+ declare const PROVENANCE_WAIT_MS = 1000;
294
376
  interface V3ChecksPayload {
295
377
  engine: "v3";
296
378
  /** Gate integrator 0..1 — the ring drives off this directly. */
@@ -311,9 +393,11 @@ interface CaptureSessionV3Events {
311
393
  key: string;
312
394
  };
313
395
  artifacts: CaptureArtifacts;
396
+ /** `detail`: where the attempt failed and the thrown error's name (never its message). */
314
397
  error: {
315
398
  kind: CaptureErrorKind;
316
399
  retryable: boolean;
400
+ detail?: EngineErrorDetail;
317
401
  };
318
402
  /** v3-only, CHROME-only (no data flows here): fires the instant the clip
319
403
  * recording window ends — BEFORE the blob finalizes (iOS onstop can lag up
@@ -324,6 +408,12 @@ interface CaptureSessionV3Events {
324
408
  frozen: {
325
409
  previewDataUrl: string;
326
410
  };
411
+ /** Liveness v7 §4.4: paint the full-viewport screen-ramp layer this colour (`null` clears it). Clip mode, a
412
+ * challenge issued by `screenRamp()`; at most four events per recording. CHROME-only: the host paints, the
413
+ * engine stamps the clip timeline. */
414
+ ramp: {
415
+ colour: ScreenRampColour | null;
416
+ };
327
417
  }
328
418
  type V3TelemetryEvent = {
329
419
  type: "detector";
@@ -339,10 +429,39 @@ type V3TelemetryEvent = {
339
429
  timeToGateMs: number;
340
430
  degradeCount: number;
341
431
  meanDetectMs: number;
342
- } | {
432
+ }
433
+ /** Where the attempt's gate time went (see gate-blocking.ts): per-reason
434
+ * blocked tick counts + ms, accepted ms, and the ACTIVE device class /
435
+ * cadence after any dynamic profile adjustment. `final` on the attempt's
436
+ * end (fired / error / retry / destroy); throttled snapshots before it. */
437
+ | ({
438
+ type: "gate";
439
+ final: boolean;
440
+ activeClass: DeviceClass;
441
+ cadenceHz: number;
442
+ } & GateBlockSummary) | {
343
443
  type: "error";
344
444
  kind: CaptureErrorKind;
345
445
  fallbackReason?: string;
446
+ }
447
+ /** Keyframe ranking (SDK spec §4.8a; only when `rankKeyframes` is on): the
448
+ * rank numbers of every candidate (never an image), the chosen index, the
449
+ * index sharpness alone would have chosen, and the extra detector time. */
450
+ | {
451
+ type: "keyframe";
452
+ tier: Detector["tier"] | null;
453
+ chosen: number;
454
+ sharpest: number;
455
+ detectMs: number;
456
+ candidates: Array<{
457
+ face: boolean;
458
+ frontal: number;
459
+ yaw?: number;
460
+ roll?: number;
461
+ eyes?: number;
462
+ score: number;
463
+ sharpness: number;
464
+ }>;
346
465
  };
347
466
  interface KeyframeCandidate {
348
467
  blob: Blob;
@@ -381,7 +500,7 @@ interface CaptureSessionV3Options {
381
500
  createRecorder?: () => Pick<ClipRecorder, "record" | "stop">;
382
501
  /** (navigator.mediaDevices.getUserMedia) */
383
502
  getUserMedia?: (constraints: MediaStreamConstraints) => Promise<MediaStream>;
384
- /** (mirrored canvas keyframe + downscaled Laplacian sharpness) */
503
+ /** (canvas keyframe, mirrored on the front camera only, + downscaled Laplacian sharpness) */
385
504
  captureKeyframe?: (video: HTMLVideoElement) => Promise<KeyframeCandidate>;
386
505
  /** (downscaled face-crop sharpness/exposure via canvas) */
387
506
  measureQuality?: (video: HTMLVideoElement, box: {
@@ -398,13 +517,33 @@ interface CaptureSessionV3Options {
398
517
  * worker-side through WorkerDetectorProxy. Hosts own Worker construction
399
518
  * (bundler-specific `new Worker(new URL(...))`). */
400
519
  createWorker?: () => WorkerLike;
520
+ /** Keyframe ranking switch (SDK spec §4.8a; server tuning
521
+ * `capture.liveness.keyframe.rank`, default off): read when positioning
522
+ * starts (prefetches the lazy ranker) and again when the capture fires.
523
+ * Off → today's sharpest-of-N, byte for byte. */
524
+ rankKeyframes?: () => boolean;
525
+ /** Screen-ramp challenge (liveness v7 §4.4; server tuning `capture.liveness.screenRamp`): read once when the
526
+ * clip recording starts. A challenge → the engine emits `ramp` at each issued onset on the clip timeline and
527
+ * reports what it rendered in `artifacts.screenRamp`; `undefined` (older backends, assisted sessions, no host
528
+ * painting) → no ramp, no field. Photo mode never ramps. */
529
+ screenRamp?: () => ScreenRampChallenge | undefined;
401
530
  /** INERT (Phase 3 escalation seam — see EscalationHook). Accepted and
402
531
  * retained, never called in Phases 1–2. */
403
532
  escalation?: EscalationHook;
533
+ /** Upright guard (spec 2026-10-28 §4.2): the device is a phone, so a landscape frame (videoWidth > videoHeight)
534
+ * holds the gate and drops a clip being recorded (or the keyframes of a photo-mode capture). Read at each attempt
535
+ * start. (detectFormFactor() === 'phone' — desktop webcams are landscape by nature, and a tablet may stand in
536
+ * landscape on a stand: neither is ever guarded) */
537
+ isPhone?: () => boolean;
404
538
  /** (performance.now) */
405
539
  now?: () => number;
406
540
  }
407
541
  type Handler<K extends keyof CaptureSessionV3Events> = (payload: CaptureSessionV3Events[K]) => void;
542
+ /** Per-start options (the public handle's `start({ facing })`). */
543
+ interface CaptureSessionV3StartOptions {
544
+ /** Camera for this attempt AND later retries; absent → keep the current one. */
545
+ facingMode?: "user" | "environment";
546
+ }
408
547
  declare class CaptureSessionV3 {
409
548
  private readonly options;
410
549
  private readonly handlers;
@@ -418,14 +557,29 @@ declare class CaptureSessionV3 {
418
557
  private profiler;
419
558
  private lastGuidanceKey;
420
559
  private positioningStartedAt;
560
+ private cameraRequestedAt;
561
+ private cameraReadyAt;
562
+ private faceAcquiredAt;
563
+ private captureCompleteAt;
421
564
  private fired;
422
565
  private carriedDegrade;
423
566
  private carriedMeans;
567
+ private blockStats;
568
+ private lastGateSnapshotAt;
569
+ /** The upright guard applies to this attempt (a phone). */
570
+ private uprightGuard;
571
+ /** Liveness v7 §4.5 item 2: the attempt's video track described right after getUserMedia (null: no track). */
572
+ private trackProvenance;
573
+ /** The ramp of the clip being recorded (stopped with the recording, the attempt or the session). */
574
+ private ramp;
424
575
  constructor(options: CaptureSessionV3Options);
425
576
  get state(): CaptureState;
426
577
  on<K extends keyof CaptureSessionV3Events>(event: K, handler: Handler<K>): () => void;
427
578
  private emit;
428
- start(): Promise<void>;
579
+ start(options?: CaptureSessionV3StartOptions): Promise<void>;
580
+ /** The camera of the current attempt: the one its track reports once the stream is live, else the requested one
581
+ * (start option, switchCamera toggles). */
582
+ get facingMode(): "user" | "environment";
429
583
  /** Full reset + camera restart — the documented recovery path (v1 parity). */
430
584
  retry(): void;
431
585
  switchCamera(): void;
@@ -436,10 +590,24 @@ declare class CaptureSessionV3 {
436
590
  private startScheduler;
437
591
  private detectTick;
438
592
  private fire;
439
- /** Up to KEYFRAME_CANDIDATES mirrored frames over KEYFRAME_WINDOW_MS —
593
+ /** `{ provenance }` from the live track's description, the recording's frame statistics and the painter flag; `{}` without a track. */
594
+ private provenance;
595
+ /** A phone showing a landscape frame: the guard holds the gate. */
596
+ private isLandscape;
597
+ /** Positioning on a sideways phone: no detection, the gate restarts from zero and the coaching says why. */
598
+ private holdUpright;
599
+ /** While the clip records (or, `recorder` null, the photo-mode keyframes are taken): a rotation to landscape aborts
600
+ * it. Returns the unwatch function. */
601
+ private watchRotation;
602
+ /** Drop the clip being recorded (or the photo-mode keyframes being taken; same stream, same detector) and go back to
603
+ * positioning with the upright coaching. */
604
+ private abortRecording;
605
+ /** Up to KEYFRAME_CANDIDATES frames (mirrored on the front camera) over KEYFRAME_WINDOW_MS —
440
606
  * sharpest wins (reuses frame-quality.sharpness via the capture seam). */
441
607
  private collectKeyframes;
442
608
  private finishCapture;
609
+ /** The attempt's capture-phase timing (whole ms, ≥ 0); undefined when no mark landed. */
610
+ private captureTiming;
443
611
  private defaultKeyframe;
444
612
  /** Reused downscale canvas — falls back to the raw video where canvas 2D
445
613
  * is unavailable (jsdom) so tests and exotic hosts keep detecting. */
@@ -448,10 +616,12 @@ declare class CaptureSessionV3 {
448
616
  private defaultQuality;
449
617
  private centerSharpness;
450
618
  private teardownAttempt;
619
+ /** Emit the attempt's gate breakdown; a final report closes it (exactly once). */
620
+ private reportGate;
451
621
  private stopTracks;
452
622
  private fail;
453
623
  private setState;
454
624
  private now;
455
625
  }
456
626
 
457
- export { V3_GATE_DEFAULTS as A, VIDEO_BPS as B, type CameraErrorKind as C, DEFAULT_CLIP_MIME as D, type EscalationClipArtifact as E, FaceGateV3 as F, type GateChecks as G, buildLivenessV2FormData as H, cameraPreflight as I, classifyDevice as J, KEYFRAME_CANDIDATES as K, extForMime as L, MAX_CLIP_BYTES as M, isClipTooLarge as N, isMediaRecorderSupported as O, mapGetUserMediaError as P, pickMimeType as Q, probeDevice as R, STOP_GRACE_MS as S, TIMESLICE_MS as T, type V3ChecksPayload as V, CLIP_MS as a, type CaptureArtifacts as b, type CaptureErrorKind as c, type CaptureSessionEvents as d, CaptureSessionV3 as e, type CaptureSessionV3Events as f, type CaptureSessionV3Options as g, type CaptureState as h, ClipError as i, type ClipErrorKind as j, ClipRecorder as k, type ClipResult as l, DEVICE_PROFILES as m, type DeviceClass as n, type DeviceProbe as o, type DeviceProfile as p, DeviceProfiler as q, type EscalationHook as r, KEYFRAME_WINDOW_MS as s, MIME_CANDIDATES as t, type V3GateFactor as u, type V3GateQuality as v, type V3GateThresholds as w, type V3GateTick as x, type V3GateTickInput as y, type V3TelemetryEvent as z };
627
+ export { isClipTooLarge as $, MIME_CANDIDATES as A, type V3GateFactor as B, type CameraErrorKind as C, DEFAULT_CLIP_MIME as D, type EscalationClipArtifact as E, FaceGateV3 as F, GATE_SNAPSHOT_MS as G, HOLD_UPRIGHT_KEY as H, type V3GateQuality as I, type V3GateThresholds as J, KEYFRAME_CANDIDATES as K, type V3GateTick as L, MAX_CLIP_BYTES as M, type V3GateTickInput as N, type V3TelemetryEvent as O, PROVENANCE_WAIT_MS as P, V3_GATE_DEFAULTS as Q, VIDEO_BPS as R, STOP_GRACE_MS as S, TIMESLICE_MS as T, UPRIGHT_WATCH_MS as U, type V3ChecksPayload as V, blockReasonOf as W, buildLivenessV2FormData as X, cameraPreflight as Y, classifyDevice as Z, extForMime as _, CLIP_MS as a, isMediaRecorderSupported as a0, mapGetUserMediaError as a1, pickMimeType as a2, probeDevice as a3, type EngineErrorDetail as a4, type CaptureArtifacts as b, type CaptureErrorKind as c, type CaptureSessionEvents as d, CaptureSessionV3 as e, type CaptureSessionV3Events as f, type CaptureSessionV3Options as g, type CaptureSessionV3StartOptions as h, type CaptureState as i, type CaptureTiming as j, ClipError as k, type ClipErrorKind as l, ClipRecorder as m, type ClipResult as n, DEVICE_PROFILES as o, type DeviceClass as p, type DeviceProbe as q, type DeviceProfile as r, DeviceProfiler as s, type EscalationHook as t, type GateBlockEntry as u, type GateBlockReason as v, GateBlockStats as w, type GateBlockSummary as x, type GateChecks as y, KEYFRAME_WINDOW_MS as z };
@@ -0,0 +1 @@
1
+ import{c as v,d as V,e as A}from"./chunk-NJML6FMD.js";var j=new Set(["nni_unbound","id_number_unbound","method_required","mobile_required","portrait_required"]);function we(e){return j.has(e)}function be(e,n,t){let i=n.detail;return{check:e,kind:n.kind,...i?.name!==void 0?{name:i.name}:{},...i?.phase!==void 0?{phase:i.phase}:{},...i?.engineKind!==void 0?{engineKind:i.engineKind}:{},attempt:Math.max(0,Math.min(1e3,t))}}function ke(){let e=-1,n="";return{note(t){t==="starting"&&n!=="starting"&&(e+=1),n=t},newHandle(){n=""},noteError(){e<0&&(e=0)},get value(){return e}}}var H=Object.freeze({nni_invalid:"id_number_invalid",nni_not_found:"registry_record_not_found",nni_recheck:"id_number_recheck",document_nni_mismatch:"document_id_number_mismatch",nni_locked:"id_number_locked",nni_unbound:"id_number_unbound",sandbox_nni_not_seeded:"sandbox_id_number_not_seeded",missing_nni:"missing_id_number",registry_needs_nni_source:"registry_needs_id_number_source"}),I=new Map(Object.entries(H)),$=new Map(Object.entries(H).map(([e,n])=>[n,e]));function ve(e){return I.get(e)??e}function z(e){let n=I.get(e)??$.get(e);return n===void 0?[e]:[e,n]}function T(e){let n=[];for(let t of e)for(let i of z(t))n.includes(i)||n.push(i);return n}var W=new Set(T(["no_face","media_unreadable","clip_too_short","no_face_source","side_missing","unreadable","registry_unavailable","otp_mismatch","otp_expired","otp_send_failed","document_type_not_accepted","age_unverifiable","nationality_unreadable","liveness_inconclusive","match_inconclusive","document_authenticity","probe_not_from_liveness","capture_back_camera","capture_not_upright","chip_read_failed","chip_access_denied","chip_parse_failed","icao_pose","icao_eyes","icao_mouth","icao_occlusion","icao_lighting","icao_background","icao_resolution","portrait_not_from_liveness","nni_recheck","device_integrity_failed","eid_identifier_invalid","eid_code_invalid","eid_code_expired","eid_unavailable","eid_resend_too_soon"])),X={document:"document_photo",nfc:"document_chip",population_registry:"national_number",national_eid:"national_eid"};function p(e){return e.plan?.steps??[]}function O(e){return Math.max(0,e.attempts.max-e.attempts.used)}function G(e){let n=e.plan?.choice;return n!==void 0&&e.plan?.current===n.nodeId?n:null}function Me(e){let n=G(e);if(n?.kind!=="identity_method")return null;let t=n.options.map(o=>X[o.service]).filter(o=>o!==void 0),i=n.options.find(o=>o.nationalEid)?.nationalEid;return i?{available:!0,selected:null,options:t,nationalEid:i}:{available:!0,selected:null,options:t}}var J=new Set(["liveness","face_match"]);function x(e){return e!==void 0&&(e.state==="pending"||e.state==="input_required")}function L(e){return e.status!=="created"&&e.status!=="in_progress"}function E(e){let n=e.plan?.current,t=n==null?void 0:p(e).find(i=>i.id===n);return x(t)?t:void 0}function y(e,n){return p(e).find(t=>t.checkType===n)}function g(e){let n=p(e),t=n.findIndex(i=>i.checkType==="liveness");return n.find((i,o)=>o>t&&i.checkType==="face_match")}function N(e,n){let t=y(n,"liveness")?.state,i=g(n)?.state;return(g(e)?.state??"pending")==="pending"&&(t==="passed"||t==="review")&&i!==void 0&&i!=="pending"&&i!=="skipped"}function M(e,n){let t=new Map(p(e).map(i=>[i.id,i.state]));return p(n).filter(i=>i.checkType==="face_match"&&(t.get(i.id)??"pending")==="pending"&&i.state!=="pending"&&i.state!=="skipped").map(i=>i.id)}var Q=/^[0-9a-f]{24}$/i;function b(e){return Q.test(e)?`ses_${e}`:e}function w(e,n){let t=b(e);return n===void 0?{sessionId:t,status:"unavailable"}:{sessionId:t,status:"unavailable",reason:n}}function _(e,n,t){let i=b(e);return t===void 0?{sessionId:i,status:n}:{sessionId:i,status:n,reason:t}}function Pe(e,n){let{sessionId:t}=e;switch(e.status){case"completed":case"failed":case"review_pending":return ee(e,ne(e));case"expired":return w(t);case"created":case"in_progress":break;default:{let i=e.status;throw new Error(`mapSessionResult: unhandled status ${i}`)}}return ie(e,n)}var Z=new Set([0,1,2,3]);function ee(e,n){return Z.has(e.level)&&(n.level=e.level),typeof e.assurance=="string"&&e.assurance.length>0&&(n.assurance=e.assurance),n}function ne(e){let n=b(e.sessionId);switch(e.status){case"completed":return e.outcome==="approved"?{sessionId:n,status:"approved"}:e.outcome==="review"?_(n,"review",h(e,"review")):_(n,"rejected",h(e,"failed"));case"failed":{let t=_(n,"rejected",e.failureReason??h(e,"failed"));return e.failureReason==="device_cooldown"&&e.retryAfter!==void 0&&(t.retryAfter=e.retryAfter),t}default:return _(n,"review",h(e,"review"))}}function te(e,n){if(n===void 0)return!1;let t=p(n).find(i=>i.id===e.id);return t!==void 0&&t.attempts.used===e.attempts.used}function ie(e,n){let t=b(e.sessionId),i=p(e).find(s=>J.has(s.checkType)&&s.state==="input_required"&&s.reason!==void 0);if(i?.reason==="mobile_required")return w(t,"mobile_required");if(i?.reason!==void 0){let s=n.autoRetry&&O(i)>0&&(W.has(i.reason)||te(i,n.previous)),d={sessionId:t,status:s?"retry":"rejected",reason:i.reason,attemptsRemaining:O(i)};return i.retakeHint!==void 0&&(d.retakeHint=i.retakeHint),d}let o=E(e);return o===void 0&&p(e).some(s=>s.state==="review")?_(t,"review",h(e,"review")):o?.checkType==="portrait_icao"?w(t,"portrait_required"):w(t)}function h(e,n){let t=p(e).filter(i=>i.state===n&&i.reason!==void 0);return t[n==="failed"?t.length-1:0]?.reason}function K(e,n,t,i,o){return e.presignCapture!==void 0?e.presignCapture(n,t,i,o):e.presign(n,t,i)}function q(e){return{engine:e?.engine,durationMs:e?.clipMs}}var oe=["video/webm","video/mp4"],F="image/jpeg",se=2,re=1e3,ae=1e4,de=3,ue=10,ce=3,le=new Set(["network_error","timeout","upload_failed","unknown_error","rate_limit_exceeded"]),pe=new Set(["session_not_active","check_not_found","check_already_finalized","check_out_of_order","identity_confirm_required","check_not_active","step_not_on_path"]),S=class extends Error{constructor(){super("verification destroyed"),this.name="FlowCancelledError"}};function fe(e){let n=g(e);return y(e,"portrait_icao")?.state!=="pending"&&(n!==void 0?x(n):e.capture?.livePhoto?.oneCapture===!0)}var R=class extends Error{constructor(n){super(n),this.name="AttestationError"}};async function D(e,n,t={}){let i=e.uuid(),o=!1,s=!1,d=0,u=0;for(;;)try{return await n(e.client,i)}catch(r){if(r instanceof R){if(s)throw r;s=!0,t.onAttestationInvalid?.(),i=e.uuid();continue}if(!(r instanceof v))throw r;if(r.code==="consent_required"&&!o){o=!0,await e.ensureConsent({force:!0}),i=e.uuid();continue}if(r.code==="attestation_invalid"&&!s){s=!0,t.onAttestationInvalid?.(),i=e.uuid();continue}if(r.code==="inference_unavailable"&&u<de){u+=1;let a=V(r.retryAfterSeconds,ue,e.random??Math.random);e.onBusy?.({attempt:u,retryAfterSeconds:a/1e3}),await e.sleep(a),t.onAttestationInvalid?.(),i=e.uuid();continue}if(le.has(r.code)&&d<se){d+=1;let a=r.retryAfterSeconds!==void 0?r.retryAfterSeconds*1e3:void 0;await e.sleep(a!==void 0?Math.min(a,ae):re);continue}throw r}}var me=new Set(["passed","review","processing","skipped"]);async function Oe(e){let{artifacts:n}=e,t=n.clip,i=A(n.clipMime??"");if(n.degraded==="NO_RECORDER"||t===void 0||!oe.includes(i))return{kind:"unavailable",reason:"no_recorder"};e.client.armCapture?.(2);let o=_e(e,n.keyframe),s=he(e,t,i,o),d=ge(e,o),u=!1,r=new Set,a=!0,m=0;for(;;){if(e.isCancelled())return{kind:"cancelled"};let l=e.getView();if(L(l))return{kind:"settled"};let k=E(l),P=k?.checkType,C=P==="liveness"&&!u?"liveness":P==="face_match"&&!r.has(k?.id)&&r.size<2&&a?"face_match":null;if(C===null)return{kind:"settled"};if(C==="liveness"&&n.captureChannel==="desktop"&&y(l,"liveness")?.requiresMobile===!0)return{kind:"unavailable",reason:"mobile_required"};try{if(C==="liveness"){u=!0;let c=await s();if(e.isCancelled())return{kind:"cancelled"};N(l,c)&&r.add(g(c)?.id);for(let B of M(l,c))r.add(B);await e.applySubmit(c,"liveness");let f=y(e.getView(),"liveness")?.state;a=f===void 0||me.has(f)}else{r.add(k?.id);let c=await d();if(e.isCancelled())return{kind:"cancelled"};for(let f of M(l,c))r.add(f);await e.applySubmit(c,"face_match")}}catch(c){if(e.isCancelled()||c instanceof S)return{kind:"cancelled"};let f=Re(c);if(f.kind!=="resync"||m>=ce)return f;m+=1,await e.refreshView()}}}function _e(e,n){let t=null,i=null,o=()=>t!==null?Promise.resolve(t):(i??(i=(async()=>{let s=await K(e.client,"image",F,n.size,q(e.artifacts));return await e.client.uploadToSpaces(s.uploadUrl,n,F),t=(await e.client.completeMedia(s.key)).key,e.onKeyframePromoted?.(t),t})().finally(()=>{i=null})),i);return{ensure:o,attempt:()=>o().catch(()=>null),current:()=>t}}function he(e,n,t,i){let o=null,s,d=null;return()=>D(e,async(u,r)=>{if(o===null||s===void 0){if(e.isCancelled())throw new S;s===void 0&&!fe(e.getView())&&(s=null),e.onPhase("uploading");let[a,m]=await Promise.all([o!==null?Promise.resolve(o):(async()=>{let l=await K(u,"clip",t,n.size,q(e.artifacts));return await u.uploadToSpaces(l.uploadUrl,n,t),(await u.completeMedia(l.key)).key})(),s!==void 0?Promise.resolve(s===null?null:s.imageKey):i.attempt()]);o=a,s===void 0&&(s=m===null?null:{imageKey:m})}if(d===null)try{d=await e.getAttestation()}catch(a){throw new R(a instanceof Error?a.message:String(a))}return e.onPhase("checking"),u.submitCheck("liveness",{clipKey:o,attestation:d,captureChannel:e.artifacts.captureChannel,capture:ye(e.artifacts),...s!==null?{faceMatch:s}:{}},{idempotencyKey:r})},{onAttestationInvalid:()=>{d=null}})}function ge(e,n){return()=>D(e,async(t,i)=>{if(n.current()===null){if(e.isCancelled())throw new S;e.onPhase("uploading")}let o=await n.ensure();return e.onPhase("checking"),t.submitCheck("face_match",{imageKey:o},{idempotencyKey:i})})}function ye(e){let n={width:e.width,height:e.height};for(let t of Se)e[t]!==void 0&&(n[t]=e[t]);return n}var Se=["engine","facingMode","mode","formFactor","clipMs","cameraReadyMs","faceAcquireMs","captureMs","screenRamp","provenance"];function Re(e){if(e instanceof R)return{kind:"unavailable",reason:"attestation"};if(e instanceof v){if(e.code==="attestation_invalid")return{kind:"unavailable",reason:"attestation"};if(e.code==="inference_unavailable")return{kind:"unavailable",reason:"inference_unavailable"};if(e.code==="mobile_required")return{kind:"unavailable",reason:"mobile_required"};if(pe.has(e.code))return{kind:"resync"}}return{kind:"unavailable",reason:"network"}}var U=class extends Error{constructor(n,t){super(`invalid ${n} (${t})`),this.name="InvalidInputError",this.field=n,this.kind=t}},Y=class extends Error{constructor(n,t){super(`invalid ${n} (${t})`),this.name="OtpInputError",this.field=n,this.kind=t}};function Fe(e){let n=e?.capture,t=n?.mode;return t==="assisted"||t==="self"||t==="choice"?t:n?.cameraSwitch===!0?"assisted":"self"}function Ke(e,n){return e==="choice"?n??"self":e}export{we as a,be as b,ke as c,Fe as d,Ke as e,ve as f,W as g,X as h,p as i,O as j,G as k,Me as l,x as m,L as n,E as o,y as p,b as q,w as r,Pe as s,K as t,oe as u,se as v,re as w,de as x,ue as y,R as z,D as A,Oe as B,U as C,Y as D};
@@ -0,0 +1 @@
1
+ var w=[468,473],K=[[33,133],[362,263]],V=[[33,7,163,144,145,153,154,155,133,173,157,158,159,160,161,246],[362,382,381,380,374,373,390,249,263,466,388,387,386,385,384,398]],D=1;function S(e){let n=Number.POSITIVE_INFINITY,o=Number.POSITIVE_INFINITY,t=Number.NEGATIVE_INFINITY,s=Number.NEGATIVE_INFINITY;for(let r of e)r.x<n&&(n=r.x),r.y<o&&(o=r.y),r.x>t&&(t=r.x),r.y>s&&(s=r.y);return e.length===0?{x:0,y:0,width:0,height:0}:{x:n,y:o,width:t-n,height:s-o}}var _=(e,n)=>({x:(e.x+n.x)/2,y:(e.y+n.y)/2});function $(e,n,o){if(e.length<468)return null;let t=l=>{let i=e[l];return{x:i.x*n,y:i.y*o}},s=[0,1].map(l=>{let i=e.length>w[1]?t(w[l]):null,[c,p]=K[l];return i??_(t(c),t(p))}),r=V.map(l=>S(l.map(t))),h=[];for(let l=0;l<Math.min(e.length,468);l+=1)h.push(t(l));let[d,m]=s,u=d.x>m.x,b=u?m:d,f=u?d:m;return{leftEye:b,rightEye:f,iod:Math.hypot(f.x-b.x,f.y-b.y),box:S(h),nose:t(D),leftEyeBox:u?r[1]:r[0],rightEyeBox:u?r[0]:r[1]}}var R=180/Math.PI;function F(e,n="column"){if(e.length<16||e.some(l=>!Number.isFinite(l)))return null;let o=(l,i)=>n==="column"?e[i*4+l]:e[l*4+i],t=Math.hypot(o(0,0),o(1,0),o(2,0))||1,s=o(0,0)/t,r=o(1,0)/t,h=o(2,0)/t,d=o(2,1)/t,m=o(2,2)/t,u=Math.asin(Math.max(-1,Math.min(1,-h)))*R,b=Math.atan2(d,m)*R,f=Math.atan2(r,s)*R;return{yaw:u,pitch:b,roll:f}}function B(e){return Math.atan2(e.rightEye.y-e.leftEye.y,e.rightEye.x-e.leftEye.x)*R}var E={width:480,height:640,eyeX:240,eyeY:289,iodMin:120,iodMax:160};function G(e){let n=E,o=e.iod>=n.iodMin&&e.iod<=n.iodMax?1:n.iodMin/Math.max(e.iod,1e-6),t=n.width/o,s=n.height/o,r=_(e.leftEye,e.rightEye);return{x:r.x-n.eyeX/n.width*t,y:r.y-n.eyeY/n.height*s,width:t,height:s}}function N(e,n,o){let t=Math.max(0,-e.x),s=Math.max(0,-e.y),r=Math.max(0,e.x+e.width-n),h=Math.max(0,e.y+e.height-o);return Math.max((t+r)/e.width,(s+h)/e.height)}function ee(e,n,o,t){let s=G(e),r=s.x+s.width/2,h=s.y+s.height/2,d=E.width/E.height,m=Math.max(s.height*t.margin,t.minHeight,t.minWidth/d);m=Math.min(m,o,n/d);let u=m*d,b=Math.min(Math.max(r-u/2,0),Math.max(0,n-u)),f=Math.min(Math.max(h-m/2,0),Math.max(0,o-m));return{x:Math.round(b),y:Math.round(f),width:Math.round(u),height:Math.round(m)}}var v=["face","framing","pose","eyes","mouth","glare","lighting","background","resolution","sharpness"],H=new Set(["glare","background"]),x=e=>({pass:!0,value:e,coach:null}),y=(e,n)=>({pass:!1,value:e,coach:n}),I=(e,n)=>({pass:e,value:null,coach:e?null:n,none:!0});function X(e,n){let o=e.pose,t;if(o!==null){let c=o.pitch-n.pitchOffsetDeg,p=Math.max(Math.abs(o.yaw),Math.abs(c),Math.abs(o.roll));t=Math.abs(o.yaw)<=n.yawDeg&&Math.abs(c)<=n.pitchDeg&&Math.abs(o.roll)<=n.rollDeg?x(p):y(p,"pose")}else t={...I(!1,"pose"),value:e.eyeLineRoll??null};let s=I(!1,"eyes");if(e.eyes!==null){let c=e.baseline,p=Math.min(e.eyes.left,e.eyes.right),M=Math.max(1-n.eyes.blinkMax,c!==null&&c>0&&c<=1?n.eyes.relativeMin*c:0),g=c!==null&&c>0?p/c:null;s=p>=M-1e-9?x(g):y(g,"eyes")}let r=I(!1,"mouth");if(e.mouth!==null){let{jawOpen:c,smile:p,pucker:M}=e.mouth,g=Math.max(c/n.mouth.jawOpenMax,p/n.mouth.smileMax,M/n.mouth.puckerMax);r=c<=n.mouth.jawOpenMax&&p<=n.mouth.smileMax&&M<=n.mouth.puckerMax?x(g):y(g,"mouth")}let h=e.lighting,d=I(!0,"lighting");if(h!==null){let[c,p]=n.lighting.faceLuma,[M,g]=n.lighting.halfRatio;d=h.faceLuma<c||h.faceLuma>p||h.clipped>n.lighting.clippedMax?y(h.faceLuma,"lighting"):h.halfRatio<M||h.halfRatio>g?y(h.halfRatio,"lighting_side"):x(h.faceLuma)}let m=e.uniformity,u=e.background,b=n.background.required?m!=null&&n.backgroundCheck.enabled?m.uniform?x(m.colorStd):y(m.colorStd,"background"):u===null?I(!0,"background"):u.luma>=n.background.lumaMin&&u.sd<=n.background.lumaSdMax?x(u.luma):y(u.luma,"background"):I(!0,"background"),f=n.resolution,l=Math.min(e.frameWidth,e.frameHeight)>=f.minWidth&&Math.max(e.frameWidth,e.frameHeight)>=f.minHeight,i=e.iod>=f.minIodPx&&l?x(e.iod):y(e.iod,"resolution");return{pose:t,eyes:s,mouth:r,lighting:d,background:b,resolution:i}}function L(e){let n=e?.eyeBlinkLeft,o=e?.eyeBlinkRight;return typeof n!="number"||typeof o!="number"?null:{left:1-n,right:1-o,blinkLeft:n,blinkRight:o}}function q(e,n){if(e.length===0)return null;let o=[...e].sort((s,r)=>s-r),t=Math.min(o.length-1,Math.max(0,Math.ceil(n*o.length)-1));return o[t]}function T(e,n,o){let t={},s=e.geometry;if(e.faces!==1||s===null){let c=e.faces>1?y(e.faces,"multiple_faces"):y(e.faces,"no_face");for(let p of v)t[p]=p==="face"?c:I(!1,"no_face");return{results:t,pose:null}}t.face=x(1);let r=G(s),h=N(r,e.frameWidth,e.frameHeight);t.framing=r.height>e.frameHeight*1.02||r.width>e.frameWidth*1.02?y(h,"too_close"):h>.02?y(h,"center"):x(h);let d=e.matrix!=null?F(e.matrix):null,m=L(e.blendshapes),u=e.blendshapes,b=e.stats??null,f=X({pose:d,eyeLineRoll:Math.abs(B(s)),eyes:m,baseline:o,mouth:u==null?null:{jawOpen:u.jawOpen??0,smile:Math.max(u.mouthSmileLeft??0,u.mouthSmileRight??0),pucker:u.mouthPucker??0},lighting:b?.lighting??null,background:b?.background??null,uniformity:e.backgroundCheck??null,iod:s.iod,frameWidth:e.frameWidth,frameHeight:e.frameHeight},n);Object.assign(t,f);let l=b?.eyeSpecular??null;t.glare=l===null?I(!0,"glare"):l<=n.glare.specularMax?x(l):y(l,"glare");let i=b?.sharpness??null;return t.sharpness=i===null||i>=n.sharpnessMin?x(i):y(i,"hold_still"),{results:t,pose:d}}var J={pose:"pose",eyes:"eyes",mouth:"mouth",glare:"glare",lighting:"lighting",background:"background",framing:"resolution",resolution:"resolution"};function oe(e,n={}){let o=n.policy==="alert",t=new Map,s=0,r=null,h=null,d={},m=[],u=null,b=null,f=l=>{if(m=m.filter(c=>l-c.at<=e.baseline.windowMs),m.length<e.baseline.minSamples)return null;let i=q(m.map(c=>c.open),e.baseline.percentile);return i===null||i<=0?null:Math.min(1,i)};return{push(l,i){let c=T(l,e,null),p=L(l.blendshapes);p!==null&&c.results.face.pass&&c.results.pose.pass&&m.push({at:i,open:(p.left+p.right)/2});let M=f(i),{results:g,pose:A}=T(l,e,M);for(let a of v)g[a].pass&&(a!=="eyes"||M!==null)?t.has(a)||t.set(a,i):t.delete(a);let P=a=>{let C=t.get(a);return C!==void 0&&i-C>=e.holdMs};v.filter(a=>!H.has(a)).every(P)?r??(r=i):r=null;let W=a=>a==="background"&&l.backgroundCheck!=null?e.backgroundCheck.timeoutMs:e.softGraceMs,U=a=>H.has(a)&&!g[a].pass&&r!==null&&i-r>=W(a),k=v.map(a=>({criterion:a,pass:g[a].pass,held:P(a),waived:U(a),value:g[a].value,coach:g[a].pass?null:g[a].coach}));s=k.every(a=>a.pass||a.waived)?s+1:0;let O=k.find(a=>!a.pass&&!a.waived)??null,j=k.filter(a=>a.held||a.waived).length;g.face.pass&&g.framing.pass?h??(h=i):h=null;let Y=k.every(a=>a.held||a.waived)&&s>=e.holdFrames||o&&h!==null&&i-h>=e.alertGraceMs;d={};for(let a of v){let C=J[a];C!==void 0&&g[a].none!==!0&&(d[C]=(d[C]??!0)&&g[a].pass)}return b=l.backgroundCheck??null,u={criteria:k,coach:O?.coach??"hold",failing:O?.criterion??null,progress:j/k.length,ready:Y,baseline:M,pose:A},u},last:()=>u,summary(){let l={criteria:{}};if(u===null)return l;l.verdict={...d},u.baseline!==null&&Math.round(u.baseline*1e3)>0&&(l.baselineEyeOpenness=Math.round(u.baseline*1e3)/1e3);for(let i of u.criteria){let c=i.value===null||!Number.isFinite(i.value)?null:Math.round(i.value*1e3)/1e3;l.criteria[i.criterion]=i.waived?{pass:i.pass,value:c,waived:!0}:{pass:i.pass,value:c}}if(b!==null&&e.background.required){let{pixels:i,...c}=b;l.backgroundCheck=c}return l},reset(){t.clear(),s=0,r=null,h=null,d={},u=null,b=null}}}export{$ as a,F as b,B as c,E as d,G as e,N as f,ee as g,v as h,X as i,L as j,q as k,T as l,oe as m};
@@ -0,0 +1,2 @@
1
+ import{a as o}from"./chunk-DFTCAWMP.js";var A="sekyro-mrz-1";function w(e){return Array.from(new Uint8Array(e),t=>t.toString(16).padStart(2,"0")).join("")}async function m(e){return w(await crypto.subtle.digest("SHA-256",e))}function x(e,t){return m(new TextEncoder().encode(`${A}\0${e}\0${t.join(`
2
+ `)}`))}var i=class extends Error{constructor(t){super(t),this.name="AssetFailure",this.reason=t}},B=Object.keys(o.files).filter(e=>o.files[e].tier==="live"),N=Object.keys(o.files).filter(e=>o.files[e].tier==="lazy");function g(e,t){return`${e.replace(/\/+$/,"")}/${o.fp12}/${t}`}async function b(e,t,d,p=fetch,n=()=>performance.now()){let c=o.files[t],y=n(),f=async s=>{try{let r=await p(g(e,t),{cache:s,signal:d,credentials:"omit"});if(!r.ok)throw new i("download");return await r.arrayBuffer()}catch(r){throw r instanceof i?r:new i("download")}},l=async s=>s.byteLength===c.bytes&&await m(s)===c.sha256,a=await f("force-cache");if(!await l(a)&&(a=await f("reload"),!await l(a)))throw new i("integrity");return{bytes:a,ms:n()-y}}async function T(e,t,d,p=fetch,n=()=>performance.now()){let c=new AbortController,y=new Map,f=t.reduce((r,u)=>r+o.files[u].bytes,0),l=n(),a=!0,s=0;for(let r of t){let u=await b(e,r,c.signal,p,n);y.set(r,u.bytes),u.ms>=50&&(a=!1),s+=u.bytes.byteLength;let h=n()-l;if(s<f&&h>0&&h*f/s>d)throw c.abort(),new i("download")}return{files:y,downloadMs:Math.round(n()-l),cached:a}}function _(e,t){return e==="hosted"?"/models-ocr":t==="live"?"https://assets.sekyro.ai/sdk/web/ocr":"https://assets-staging.sekyro.ai/sdk/web/ocr"}export{x as a,i as b,B as c,T as d,_ as e};
@@ -0,0 +1 @@
1
+ import{a as M,c as p}from"./chunk-GI3UFGRQ.js";var f={id_document:{pose:{yawDeg:7,pitchDeg:7,rollDeg:5,pitchOffsetDeg:4},eyes:{relativeMin:.62,blinkMax:.48},mouth:{jawOpenMax:.13,smileMax:.28,puckerMax:.28},lighting:{faceLuma:[95,185],halfRatio:[.77,1.31],clippedMax:.015},background:{required:!0,lumaMin:165,lumaSdMax:20},resolution:{minIodPx:110,minWidth:480,minHeight:640}},selfie:{pose:{yawDeg:7,pitchDeg:7,rollDeg:7,pitchOffsetDeg:4},eyes:{relativeMin:.62,blinkMax:.48},mouth:{jawOpenMax:.13,smileMax:.28,puckerMax:.28},lighting:{faceLuma:[95,185],halfRatio:[.77,1.31],clippedMax:.015},background:{required:!1,lumaMin:165,lumaSdMax:20},resolution:{minIodPx:100,minWidth:480,minHeight:640}}};function k(a){let i=f[a];return{profile:a,backgroundCheck:M,...i.pose,holdMs:500,alertGraceMs:3e3,eyes:{...i.eyes},mouth:{...i.mouth},lighting:{...i.lighting,faceLuma:[i.lighting.faceLuma[0],i.lighting.faceLuma[1]],halfRatio:[i.lighting.halfRatio[0],i.lighting.halfRatio[1]]},background:{...i.background},resolution:{...i.resolution},holdFrames:3,cadenceHz:10,baseline:{windowMs:3e3,minSamples:6,percentile:.8},sharpnessMin:.25,glare:{specularMax:.01},softGraceMs:4e3,cropMargin:1.25,camera:{width:1920,height:1080}}}var I=k("id_document"),D=/^[A-Za-z0-9._-]{1,64}$/;function n(a,i,r,u){return typeof a=="number"&&Number.isFinite(a)&&a>=r&&a<=u?a:i}function x(a,i,r,u){if(!Array.isArray(a)||a.length!==2)return[i[0],i[1]];let[e,l]=a,t=n(e,Number.NaN,r,u),m=n(l,Number.NaN,r,u);return Number.isNaN(t)||Number.isNaN(m)||t>m?[i[0],i[1]]:[t,m]}function o(a){return typeof a=="object"&&a!==null&&!Array.isArray(a)?a:{}}function R(a,i){let r=o(a),u=r.profile==="selfie"?"selfie":"id_document",e=u==="selfie"?k(u):I,l=o(r.eyes),t=o(r.mouth),m=o(r.lighting),c=o(r.background),s=o(r.resolution),g=o(r.baseline),w=o(r.glare),b=o(r.camera),h=typeof c.required=="boolean"?c.required:e.background.required,d=p(r.backgroundCheck);return{profile:u,yawDeg:n(r.yawDeg,e.yawDeg,1,45),pitchDeg:n(r.pitchDeg,e.pitchDeg,1,45),pitchOffsetDeg:n(r.pitchOffsetDeg,e.pitchOffsetDeg,-20,20),rollDeg:n(r.rollDeg,e.rollDeg,1,45),holdMs:n(r.holdMs,e.holdMs,0,5e3),alertGraceMs:n(r.alertGraceMs,e.alertGraceMs,0,6e4),eyes:{relativeMin:n(l.relativeMin,e.eyes.relativeMin,0,1),blinkMax:n(l.blinkMax,e.eyes.blinkMax,0,1)},mouth:{jawOpenMax:n(t.jawOpenMax,e.mouth.jawOpenMax,0,1),smileMax:n(t.smileMax,e.mouth.smileMax,0,1),puckerMax:n(t.puckerMax,e.mouth.puckerMax,0,1)},lighting:{faceLuma:x(m.faceLuma,e.lighting.faceLuma,0,255),halfRatio:x(m.halfRatio,e.lighting.halfRatio,0,10),clippedMax:n(m.clippedMax,e.lighting.clippedMax,0,1)},background:{required:h,lumaMin:n(c.lumaMin,e.background.lumaMin,0,255),lumaSdMax:n(c.lumaSdMax,e.background.lumaSdMax,0,255)},resolution:{minIodPx:n(s.minIodPx,e.resolution.minIodPx,1,2e3),minWidth:n(s.minWidth,e.resolution.minWidth,1,8e3),minHeight:n(s.minHeight,e.resolution.minHeight,1,8e3)},holdFrames:Math.round(n(r.holdFrames,e.holdFrames,1,60)),cadenceHz:n(r.cadenceHz,e.cadenceHz,1,30),baseline:{windowMs:n(g.windowMs,e.baseline.windowMs,200,3e4),minSamples:Math.round(n(g.minSamples,e.baseline.minSamples,1,300)),percentile:n(g.percentile,e.baseline.percentile,.5,1)},sharpnessMin:n(r.sharpnessMin,e.sharpnessMin,0,1),glare:{specularMax:n(w.specularMax,e.glare.specularMax,0,1)},softGraceMs:n(r.softGraceMs,e.softGraceMs,0,6e4),cropMargin:n(r.cropMargin,e.cropMargin,1,2),camera:{width:Math.round(n(b.width,e.camera.width,320,4096)),height:Math.round(n(b.height,e.camera.height,240,4096))},backgroundCheck:h?d:{...d,enabled:!1},tuningVersion:typeof i=="string"&&D.test(i)?i:null}}export{I as a,R as b};
@@ -0,0 +1 @@
1
+ var l=2e4,m="face_landmarker.task";function d(a){let r=[],n=a.faceLandmarks??[];for(let e=0;e<n.length;e+=1){let o=n[e]??[],c=a.faceBlendshapes?.[e]?.categories,t=null;if(c!==void 0){t={};for(let s of c)t[s.categoryName]=s.score}let i=a.facialTransformationMatrixes?.[e]?.data;r.push({landmarks:o.map(s=>({x:s.x,y:s.y})),blendshapes:t,matrix:i!==void 0&&i.length>=16?[...i]:null})}return r}async function u(a){let r=a.replace(/\/+$/,""),n=await import("@mediapipe/tasks-vision"),e=await n.FilesetResolver.forVisionTasks(r),o=await n.FaceLandmarker.createFromOptions(e,{baseOptions:{modelAssetPath:`${r}/${m}`,delegate:"CPU"},runningMode:"VIDEO",numFaces:2,outputFaceBlendshapes:!0,outputFacialTransformationMatrixes:!0});return{detect(c,t){try{return d(o.detectForVideo(c,t))}catch{return[]}},close(){try{o.close()}catch{}}}}export{l as a,m as b,d as c,u as d};
@@ -0,0 +1 @@
1
+ var m=["video/mp4;codecs=avc1.42E01E,mp4a.40.2","video/mp4;codecs=avc1.42E01E","video/mp4","video/webm;codecs=vp9,opus","video/webm;codecs=vp9","video/webm;codecs=vp8,opus","video/webm;codecs=vp8","video/webm"];function S(){let e=globalThis.MediaRecorder;return!e||typeof e.isTypeSupported!="function"?"":m.find(r=>e.isTypeSupported(r))??""}var l="video/webm";function f(e){if(e instanceof TypeError)return"insecure";switch(e?.name??""){case"NotAllowedError":case"PermissionDeniedError":return"permission";case"NotFoundError":case"DevicesNotFoundError":return"notfound";case"NotReadableError":case"TrackStartError":return"inuse";case"OverconstrainedError":case"ConstraintNotSatisfiedError":return"overconstrained";default:return"generic"}}function b(){let e=globalThis;if(typeof e.window<"u"&&e.window.isSecureContext===!1)return"INSECURE_CONTEXT";let r=e.navigator?.mediaDevices;return!r||typeof r.getUserMedia!="function"?"UNSUPPORTED":"OK"}function v(){let e=globalThis.MediaRecorder;return typeof e<"u"&&typeof e.isTypeSupported=="function"}var E=8*1024*1024;function T(e){return e.size>E}function u(e){let r=(e||"").toLowerCase();return r.startsWith("image/jpeg")?"jpg":r.startsWith("video/mp4")?"mp4":(r.startsWith("video/webm"),"webm")}function k(e){let{token:r,clip:n,keyframe:o}=e,c=e.ts??Date.now(),p=n.type||l,d=o.type||"image/jpeg",t=new FormData;return t.append("token",r),t.append("clip",new File([n],`liveness-${c}.${u(p)}`,{type:p})),t.append("keyframe",new File([o],`keyframe-${c}.${u(d)}`,{type:d})),t}var w=40;function y(e){if(e===null||typeof e!="object"&&typeof e!="function")return;let r;try{r=e.name}catch{return}return g(r)}function g(e){if(typeof e!="string")return;let r=e.replace(/[^A-Za-z]/g,"").slice(0,w);return r===""?void 0:r}function C(e){let r=f(e);if(r!=="generic")return r;switch(y(e)){case"AbortError":return"inuse";case"SecurityError":return"permission";default:return r}}var i=Symbol.for("sekyro.web.cameraStreams"),a=globalThis,s=a[i]??(a[i]=new Set);function N(e){try{s.add(e)}catch{}}function R(e){let r=0;for(let n of[...s])if(n!==e){s.delete(n);try{for(let o of n.getTracks())o.readyState!=="ended"&&(o.stop(),r+=1)}catch{}}return r}export{m as a,S as b,l as c,f as d,b as e,v as f,E as g,T as h,u as i,k as j,y as k,g as l,C as m,N as n,R as o};
@@ -0,0 +1 @@
1
+ var e={fp12:"08390000c48a",engine:"sekyro-ocr-1",precision:"fp32",files:{"sekyro-ocr.wasm":{bytes:3550608,sha256:"c15968a6de3d2225e2fdbf36d71a9214c2910419056c6878444fd2d0567bb748",tier:"live",contentType:"application/wasm"},"sekyro-ocr.mjs":{bytes:4270,sha256:"209a78d96ca53344996a0c2300aed4ff8a5c69e142713216975a2840eec08cac",tier:"bundled",contentType:"text/javascript"},"det.param":{bytes:24252,sha256:"c39ba0b1195e8ad37cfc5bdd7acedcfc1d9cb901e7b8eb1c9c4f6e5a66c04eb3",tier:"live",contentType:"text/plain"},"det.bin":{bytes:4685856,sha256:"652bafe366565109a1a5766caf482bc46f01481f8044d3a785bd9a1be67c63bb",tier:"live",contentType:"application/octet-stream"},"mrz-rec.param":{bytes:3510,sha256:"bc69b1b9683e35f6605b21001fadeb81468063459c00c0fc83c67c139f23df01",tier:"live",contentType:"text/plain"},"mrz-rec.bin":{bytes:494196,sha256:"de93a2aa2f08670cc7dedd17ba378d2f5d7cf6ae409054a9eac863a02c2febae",tier:"live",contentType:"application/octet-stream"},"mrz_dict.txt":{bytes:73,sha256:"b19858a4de2ccbbbdd4b53982188ea2c7664013183bbd1ae9d20ab52c661f97f",tier:"live",contentType:"text/plain"},"latin-rec.param":{bytes:19602,sha256:"2ae30dfdc7ee482c6cbbc0419c16ee125e880e9eaf69053d61953694bb0fcf4c",tier:"lazy",contentType:"text/plain"},"latin-rec.bin":{bytes:10750388,sha256:"f91ebdcf4d6b58c58a87704160e59d07ae56bc2d5021eae09d095c5a20bf7525",tier:"lazy",contentType:"application/octet-stream"},"ppocr_keys_v1.txt":{bytes:26249,sha256:"28b2362ad4ab2dc38769aa72feb535e3a9ddb3fd2a7585a05920e6393b1dc7f7",tier:"lazy",contentType:"text/plain"},"arabic-rec.param":{bytes:9858,sha256:"4e5cc85667dfaaa0c67d3f308400645a578c08bd43f952cab6c55b7bce143ea9",tier:"lazy",contentType:"text/plain"},"arabic-rec.bin":{bytes:8853572,sha256:"5acc3265a1738dc31316258383830d5dbdfa5e8ebc2e710f9001f832ecfbffb0",tier:"lazy",contentType:"application/octet-stream"},"arabic_dict.txt":{bytes:405,sha256:"637c27c88512c22089bef927b34ada08f748dc132ac70facd68d8202384c2726",tier:"lazy",contentType:"text/plain"}}};export{e as a};
@@ -0,0 +1 @@
1
+ var h=Object.freeze({minLines:4,fillMin:.55,fillMax:.98,offsetMax:.12,steadyFillDelta:.04,steadyOffsetDelta:.03,layoutShiftMax:.025,lineCountDelta:1,lockMs:600,steadyMs:900,minFrames:3});function y(a,r){let o=a.lineBoxes;if(o.length===0)return{lineCount:0,detected:!1,fill:0,offsetX:0,offsetY:0,centers:[]};let s=Math.min(...o.map(n=>n[0])),e=Math.max(...o.map(n=>n[0]+n[2])),t=Math.min(...o.map(n=>n[1])),l=Math.max(...o.map(n=>n[1]+n[3]));return{lineCount:o.length,detected:o.length>=r.minLines,fill:e-s,offsetX:(s+e)/2-.5,offsetY:(t+l)/2-.5,centers:o.map(n=>[n[0]+n[2]/2,n[1]+n[3]/2])}}function x(a,r){if(a.centers.length===0||r.centers.length===0)return Number.POSITIVE_INFINITY;let o=0;for(let[s,e]of r.centers){let t=Number.POSITIVE_INFINITY;for(let[l,n]of a.centers)t=Math.min(t,Math.hypot(s-l,e-n));o+=t}return o/r.centers.length}var c=class{constructor(r=h){this.t=r;this.last=null;this.goodSince=null;this.steadySince=null;this.frames=0}offer(r,o,s={glareOk:!0,sharpOk:!0}){let e=this.t,t=y(r,e),l=this.last;this.last=t;let n=t.fill>=e.fillMin&&t.fill<=e.fillMax,i=Math.abs(t.offsetX)<=e.offsetMax&&Math.abs(t.offsetY)<=e.offsetMax,m=l!==null&&l.detected&&Math.abs(t.lineCount-l.lineCount)<=e.lineCountDelta&&x(l,t)<=e.layoutShiftMax,f=t.detected&&s.glareOk&&s.sharpOk&&n&&m&&l!==null&&Math.abs(t.fill-l.fill)<=e.steadyFillDelta&&Math.abs(t.offsetX-l.offsetX)<=e.steadyOffsetDelta&&Math.abs(t.offsetY-l.offsetY)<=e.steadyOffsetDelta,d=f&&i,u=t.detected?s.glareOk?t.fill<e.fillMin?"closer":t.fill>e.fillMax?"farther":i?s.sharpOk?void 0:"blurry":"center":"glare":void 0;return f?(this.frames++,this.steadySince??(this.steadySince=o),this.goodSince=d?this.goodSince??o:null,(this.goodSince!==null&&o-this.goodSince>=e.lockMs||o-this.steadySince>=e.steadyMs)&&this.frames>=e.minFrames?{state:"locked"}:{state:"locking",...u?{hint:u}:{}}):(this.goodSince=null,this.steadySince=null,this.frames=t.detected?1:0,{state:t.detected?"locking":"searching",...u?{hint:u}:{}})}reset(){this.last=null,this.goodSince=null,this.steadySince=null,this.frames=0}};function M(a,r,o){let s=e=>Math.round(Math.min(1,Math.max(0,e))*1e4)/1e4;return a.map(e=>{let t=[e[0],e[2],e[4],e[6]],l=[e[1],e[3],e[5],e[7]],n=Math.min(...t),i=Math.min(...l);return[s(n/r),s(i/o),s((Math.max(...t)-n)/r),s((Math.max(...l)-i)/o)]}).sort((e,t)=>e[1]-t[1]||e[0]-t[0])}export{h as a,c as b,M as c};
@@ -0,0 +1 @@
1
+ import{a as F,c as N,d as H,e as U}from"./chunk-FUHDOEBP.js";import{b as J,c as ee,d as te}from"./chunk-POIQGEZM.js";import{b as K,c as B,e as W,g as z,h as R,k,m as q,n as Z}from"./chunk-CQ7SKLMC.js";import{b as O,c as re,d as x,e as ie}from"./chunk-FPXL63KZ.js";import{d as X}from"./chunk-ZLWH4RBO.js";import{c as Q,d as Y,f as w,h as j,j as $}from"./chunk-OKWG3PVH.js";var ge=2500,be=1e3,ye=1500,ne=25e5,b=class extends Error{constructor(e,t){super(t??e),this.kind=e}},A=class{constructor(){this.recorder=null;this.stream=null;this.chunks=[];this.bytes=0;this.hardStopTimer=null;this.graceTimer=null;this.settled=!1}clearTimers(){this.hardStopTimer&&clearTimeout(this.hardStopTimer),this.graceTimer&&clearTimeout(this.graceTimer),this.hardStopTimer=null,this.graceTimer=null}record(e,t,r){if(this.recorder&&!this.settled)return Promise.reject(new b("generic","record() called while a recording is in flight \u2014 ClipRecorder handles one recording at a time"));this.recorder=null,this.clearTimers(),this.chunks=[],this.bytes=0,this.settled=!1,this.stream=e;let i=K();return new Promise((n,a)=>{let s;try{s=new MediaRecorder(e,i?{mimeType:i,videoBitsPerSecond:ne}:{videoBitsPerSecond:ne})}catch{try{s=new MediaRecorder(e)}catch{a(new b("unsupported"));return}}this.recorder=s;let d=c=>{this.settled||(this.settled=!0,this.clearTimers(),c())},u=()=>d(()=>{let c=s.mimeType||i||B,l=new Blob(this.chunks,{type:c});if(l.size===0){a(new b("generic","empty clip"));return}if(R(l)){a(new b("cliptoolarge"));return}n({blob:l,mimeType:c})});if(s.ondataavailable=c=>{c.data&&c.data.size&&(this.chunks.push(c.data),this.bytes+=c.data.size,this.bytes>z&&d(()=>{try{s.state!=="inactive"&&s.stop()}catch{}a(new b("cliptoolarge"))}))},s.onstop=u,s.onerror=()=>d(()=>a(new b("generic"))),r!==void 0){let c=!1;s.onstart=()=>{if(!(c||this.settled)){c=!0;try{r()}catch{}}}}try{s.start(be)}catch{d(()=>a(new b("generic")));return}this.hardStopTimer=setTimeout(()=>{if(this.settled||t?.(),s.state!=="inactive"){try{s.stop()}catch{u()}this.graceTimer=setTimeout(u,ye)}else u()},ge)})}stop(e){this.clearTimers();let t=this.recorder;if(t&&t.state!=="inactive")try{t.stop()}catch{}this.recorder=null,(e??this.stream)?.getTracks().forEach(i=>i.stop()),this.stream=null}};var Be=400,We=2e3,Se=["rose","peach","sand","mint","sky","lilac"],Ee={rose:"rgb(255, 185, 205)",peach:"rgb(245, 193, 159)",sand:"rgb(195, 210, 158)",mint:"rgb(139, 219, 203)",sky:"rgb(140, 214, 249)",lilac:"rgb(208, 197, 249)"};function ze(o){return Ee[o]}var Me=4,_e=4;function Ce(o){if(typeof o!="object"||o===null)return!1;let e=o;if(typeof e.nonce!="string"||e.nonce.length===0||!Array.isArray(e.colours)||e.colours.length!==3||!e.colours.every(r=>Se.includes(r))||!Array.isArray(e.onsetsMs)||e.onsetsMs.length!==3)return!1;let t=-1;for(let r of e.onsetsMs){if(typeof r!="number"||!Number.isFinite(r)||r<=t||r>=2e3)return!1;t=r}return!0}function ae(o,e){let t=e.now??(()=>performance.now()),r=Ce(o)?o:void 0,i=[],n=null,a=null,s=null,d=!1,u=null,c=p=>{u=p;try{e.paint(p)}catch{}},l=p=>{let m=e.frames?.()??null;return m!==null&&s!==null?m.mediaTimeMs+(p-m.presentationTimeMs)-s:p-(a??p)},f=(p,m,v=0)=>{if(d)return;let E=Math.max(0,p-l(t()));n=setTimeout(()=>{if(n=null,!d){if(v<Me&&l(t())<p-_e){f(p,m,v+1);return}m()}},E)},h=p=>{if(r!==void 0){if(p>=3){f(2e3,()=>c(null));return}f(r.onsetsMs[p],()=>{let m=l(t());if(m>2e3){u!==null&&c(null);return}let v=r.colours[p];c(v);let E=i.length===0?0:i[i.length-1].tMs;i.push({tMs:Math.max(E,Math.round(m)),colour:v}),h(p+1)})}};return{started(p){if(r===void 0||d||a!==null)return;a=p;let m=e.frames?.()??null;s=m===null?null:m.mediaTimeMs+(p-m.presentationTimeMs),h(0)},stop(){d||(d=!0,n!==null&&clearTimeout(n),n=null,u!==null&&c(null))},report(){return r===void 0?void 0:{nonce:r.nonce,rendered:[...i]}}}}function se(o,e,t=.92){return new Promise((r,i)=>{let n=o.videoWidth,a=o.videoHeight;if(!n||!a){i(new Error("video-not-ready"));return}let s=e.getContext("2d");if(!s){i(new Error("no-2d-context"));return}e.width=n,e.height=a,s.scale(-1,1),s.drawImage(o,-n,0),e.toBlob(d=>d?r(d):i(new Error("empty-keyframe")),"image/jpeg",t)})}var I=class{constructor(e){this.timer=null;this.frameCallbackId=null;this.running=!1;this.busy=!1;this.lastRunAt=Number.NEGATIVE_INFINITY;this.degradeCount=0;this.durations=[];this.options=e,this.periodMs=1e3/e.cadenceHz}start(){if(this.running)return;this.running=!0;let e=this.options.video;if(typeof e?.requestVideoFrameCallback=="function"){let t=()=>{this.running&&(this.frameCallbackId=e.requestVideoFrameCallback?.(()=>{this.frameCallbackId=null,this.now()-this.lastRunAt>=this.periodMs&&this.tick(),t()}))};t();return}this.timer=setInterval(()=>this.tick(),this.periodMs)}stop(){this.running=!1,this.timer!==null&&(clearInterval(this.timer),this.timer=null),this.frameCallbackId!==null&&(this.options.video?.cancelVideoFrameCallback?.(this.frameCallbackId),this.frameCallbackId=null)}stats(){let e=this.durations.length===0?0:this.durations.reduce((t,r)=>t+r,0)/this.durations.length;return{degradeCount:this.degradeCount,meanDetectMs:e}}now(){return this.options.now?.()??performance.now()}tick(){if(!this.running)return;if(this.busy){this.degradeCount+=1;return}this.busy=!0,this.lastRunAt=this.now();let e=this.now();this.options.run().catch(()=>{}).finally(()=>{this.busy=!1,this.durations.push(this.now()-e),this.durations.length>20&&this.durations.shift()})}};var Te=Object.freeze({Q_GOOD:.6,RISE_PER_S:.9,FALL_PER_S:.25,CENTER_FALLOFF_IOD_MULTIPLE:1.35,BOX_EYE_OFFSET_FACTOR:.12,IOD_BOX_PROXY_FACTOR:.42,SIZE_IDEAL_MIN:.12,SIZE_IDEAL_MAX:.3,SIZE_HARD_MIN:.08,SIZE_HARD_MAX:.45,ROLL_MAX_DEG:25,MOTION_VELOCITY_IOD_PER_S:.5,MOTION_TAU_S:.4,MOTION_DEADBAND_IOD_PER_S:.1,READY_WINDOW_MS:500,GUIDE_SIZE:.6,GUIDE_CENTERING:.6,GUIDE_POSE:.6,GUIDE_EXPOSURE:.6,GUIDE_SHARPNESS:.35,GUIDE_MOTION:.5}),S=o=>Math.min(1,Math.max(0,o)),M=class{constructor(e={}){this.p=0;this.lastTickAt=null;this.lastCenter=null;this.velocityEma=0;this.qWindow=[];this.lastSizeDirection="ideal";this.t={...Te,...e}}reset(){this.p=0,this.lastTickAt=null,this.lastCenter=null,this.velocityEma=0,this.qWindow=[],this.lastSizeDirection="ideal"}tick(e){let{observation:t,quality:r,timestampMs:i}=e,n=this.lastTickAt===null?0:Math.max(0,(i-this.lastTickAt)/1e3);this.lastTickAt=i;let a={presence:0,centering:0,size:0,pose:0,sharpness:S(r.sharpness),exposure:S(r.exposure),motion:1};if(t!==null){a.presence=1;let c=this.geometryOf(t,e);a.centering=c.centering,a.size=c.size,a.pose=c.pose,a.motion=this.motionOf(c.center,c.iod,i)}else this.lastCenter=null,this.velocityEma=0;let s=Math.min(a.presence,a.centering,a.size,a.pose,a.sharpness,a.exposure,a.motion);this.p=S(this.p+(s>=this.t.Q_GOOD?this.t.RISE_PER_S*s:-this.t.FALL_PER_S*(1-s))*n),this.qWindow.push({at:i,q:s}),this.qWindow=this.qWindow.filter(c=>c.at>=i-this.t.READY_WINDOW_MS);let d=this.qWindow.map(c=>c.q);if(d.length>=3){let c=Math.min(...d),l=d.indexOf(c);d=d.filter((f,h)=>h!==l)}let u=this.p>=1&&d.every(c=>c>=this.t.Q_GOOD);return{at:i,q:s,p:this.p,factors:a,guidanceKey:this.guidanceOf(a,r,s),ready:u,accepted:s>=this.t.Q_GOOD}}geometryOf(e,t){let{box:r,eyes:i}=e,n={x:t.frameWidth/2,y:t.frameHeight/2},a=Math.min(t.frameWidth,t.frameHeight),s=i!==void 0?{x:(i.left.x+i.right.x)/2,y:(i.left.y+i.right.y)/2}:{x:r.x+r.width/2,y:r.y+r.height/2-this.t.BOX_EYE_OFFSET_FACTOR*r.height},d=i!==void 0?Math.hypot(i.right.x-i.left.x,i.right.y-i.left.y):this.t.IOD_BOX_PROXY_FACTOR*r.width,u=Math.hypot(s.x-n.x,s.y-n.y),c=d<=0?0:1-S(u/(this.t.CENTER_FALLOFF_IOD_MULTIPLE*d)),l=a>0?d/a:0;this.lastSizeDirection=l<this.t.SIZE_IDEAL_MIN?"far":l>this.t.SIZE_IDEAL_MAX?"close":"ideal";let f;l<this.t.SIZE_HARD_MIN||l>this.t.SIZE_HARD_MAX?f=0:l<this.t.SIZE_IDEAL_MIN?f=(l-this.t.SIZE_HARD_MIN)/(this.t.SIZE_IDEAL_MIN-this.t.SIZE_HARD_MIN):l>this.t.SIZE_IDEAL_MAX?f=(this.t.SIZE_HARD_MAX-l)/(this.t.SIZE_HARD_MAX-this.t.SIZE_IDEAL_MAX):f=1;let h=1;if(i!==void 0){let p=Math.abs(Math.atan2(i.right.y-i.left.y,i.right.x-i.left.x))*180/Math.PI;h=1-S(p/this.t.ROLL_MAX_DEG)}return{center:s,iod:d,centering:c,size:f,pose:h}}motionOf(e,t,r){let i=this.lastCenter;if(this.lastCenter={...e,at:r},i===null||t<=0)return 1;let n=(r-i.at)/1e3;if(n<=0)return 1;let a=Math.hypot(e.x-i.x,e.y-i.y)/t/n;a<=this.t.MOTION_DEADBAND_IOD_PER_S&&(a=0);let s=1-Math.exp(-n/this.t.MOTION_TAU_S);return this.velocityEma=s*a+(1-s)*this.velocityEma,1-S(this.velocityEma/this.t.MOTION_VELOCITY_IOD_PER_S)}guidanceOf(e,t,r){if(e.presence<=0)return"fcv3.no_face";if(e.size<this.t.GUIDE_SIZE)return this.sizeGuidance();if(e.centering<this.t.GUIDE_CENTERING)return"fcv3.center_face";if(e.pose<this.t.GUIDE_POSE)return"fcv3.straighten";if(e.exposure<this.t.GUIDE_EXPOSURE)return this.exposureGuidance(t);if(e.sharpness<this.t.GUIDE_SHARPNESS)return"fcv3.steady_camera";if(e.motion<this.t.GUIDE_MOTION)return"fcv3.hold_still";if(r<this.t.Q_GOOD){let i=[["size",this.sizeGuidance()],["centering","fcv3.center_face"],["pose","fcv3.straighten"],["exposure",this.exposureGuidance(t)],["sharpness","fcv3.steady_camera"],["motion","fcv3.hold_still"]],n=i[0];for(let a of i)e[a[0]]<e[n[0]]&&(n=a);return n[1]}return"fcv3.hold_still"}sizeGuidance(){return this.lastSizeDirection==="far"?"fcv3.come_closer":"fcv3.move_back"}exposureGuidance(e){let t=(O[0]+O[1])/2;return e.meanLuma<t?"fcv3.more_light":"fcv3.too_bright"}};var Re=["size","centering","pose","exposure","sharpness","motion"];function ke(o){if(o.accepted)return null;if(o.factors.presence<=0)return"no_face";let e="size";for(let t of Re)o.factors[t]<o.factors[e]&&(e=t);return e}var _=class{constructor(){this.blocked={};this.acceptedMs=0;this.ticks=0;this.lastAt=null}record(e){let t=this.lastAt===null?0:Math.max(0,e.at-this.lastAt);this.lastAt=e.at,this.ticks+=1;let r=ke(e);if(r===null){this.acceptedMs+=t;return}let i=this.blocked[r]??{count:0,ms:0};i.count+=1,i.ms+=t,this.blocked[r]=i}summary(){let e={};for(let[t,r]of Object.entries(this.blocked))e[t]={count:r.count,ms:Math.round(r.ms)};return{blocked:e,acceptedMs:Math.round(this.acceptedMs),ticks:this.ticks}}};var Ae=["obs","manycam","virtual","snap camera","xsplit","droidcam","iriun","camo"],Ie=[/^(front|back|rear)( [a-z ]+)? camera$/i,/^camera2? ?\d+, facing (front|back|external)/i,/facetime/i,/\b(integrated|built-in|builtin) (web)?cam(era)?\b/i,/\b(hd )?web ?cam\b/i,/\([0-9a-f]{4}:[0-9a-f]{4}\)\s*$/i];function De(o){let e=(o??"").trim().toLowerCase();return e.length===0?"unknown":Ae.some(t=>e.includes(t))?"known_virtual":Ie.some(t=>t.test(e))?"platform":"unknown"}function oe(o){if(typeof o!="function")return!1;try{return/\{\s*\[native code\]\s*\}\s*$/.test(Function.prototype.toString.call(o))}catch{return!1}}function we(o=globalThis){return oe(o.navigator?.mediaDevices?.getUserMedia)&&oe(o.MediaStreamTrack?.prototype?.getSettings)}async function Oe(o,e=globalThis){let t=e.crypto?.subtle?.digest;if(typeof t=="function")try{let r=new Uint8Array(await t.call(e.crypto?.subtle,"SHA-256",new TextEncoder().encode(o)));return Array.from(r.subarray(0,8),i=>i.toString(16).padStart(2,"0")).join("")}catch{return}}async function ce(o,e=globalThis){let t={};try{t=typeof o.getSettings=="function"?o.getSettings()??{}:{}}catch{t={}}let r={};if((t.facingMode==="user"||t.facingMode==="environment"||t.facingMode==="left"||t.facingMode==="right")&&(r.facingMode=t.facingMode),typeof t.frameRate=="number"&&Number.isFinite(t.frameRate)&&(r.frameRate=t.frameRate),typeof t.width=="number"&&Number.isFinite(t.width)&&(r.width=t.width),typeof t.height=="number"&&Number.isFinite(t.height)&&(r.height=t.height),typeof t.deviceId=="string"&&t.deviceId.length>0){let n=await Oe(t.deviceId,e);n!==void 0&&(r.deviceIdHash=n)}let i;try{i=o.label}catch{i=void 0}return{trackSettings:r,capabilitiesPresent:typeof o.getCapabilities=="function",labelClass:De(i),prototypesIntact:we(e)}}var P=o=>Math.round(o*100)/100;function le(o){let e=o,t=typeof e?.requestVideoFrameCallback=="function",r=null,i=null,n=0,a=0,s=0,d=0,u=0,c=0,l=()=>{!t||e?.requestVideoFrameCallback===void 0||(r=e.requestVideoFrameCallback((f,h)=>{if(r=null,!t)return;let p=h.presentationTime;if(i!==null){let m=p-i.presentationTimeMs;a+=1;let v=m-s;s+=v/a,d+=v*(m-s)}typeof h.captureTime=="number"&&Number.isFinite(h.captureTime)&&(u+=p-h.captureTime,c+=1),n+=1,i={mediaTimeMs:h.mediaTime*1e3,presentationTimeMs:p},l()}))};return l(),{latest:()=>i,stats:()=>({n,meanGapMs:a===0?0:P(s),stdGapMs:a<2?0:P(Math.sqrt(d/(a-1))),captureLatencyMs:c===0?null:P(u/c)}),stop:()=>{t&&(t=!1,r!==null&&e?.cancelVideoFrameCallback?.(r),r=null)}}}function ue(o,e,t){return{...o,rvfc:e,rampPainter:t}}var xe=1e3,G="fcv3.hold_upright",Pe=200,L=4,Ge=600,Le=1e3,de={sharpness:1,exposure:1,meanLuma:128};function Ve(o,e){return e.width=o.videoWidth,e.height=o.videoHeight,e.getContext("2d").drawImage(o,0,0),new Promise((t,r)=>e.toBlob(i=>i?t(i):r(new Error("empty-keyframe")),"image/jpeg",.92))}function Fe(){return N()==="phone"}var pe=class{constructor(e){this.handlers=new Map;this.stateValue="idle";this.attempt=0;this.stream=null;this.detector=null;this.scheduler=null;this.gate=null;this.profiler=null;this.lastGuidanceKey=null;this.positioningStartedAt=0;this.cameraRequestedAt=null;this.cameraReadyAt=null;this.faceAcquiredAt=null;this.captureCompleteAt=null;this.fired=!1;this.carriedDegrade=0;this.carriedMeans=[];this.blockStats=null;this.lastGateSnapshotAt=Number.NEGATIVE_INFINITY;this.uprightGuard=!1;this.trackProvenance=null;this.ramp=null;this.snapshotCanvas=null;this.options=e,this.facing=e.facingMode??"user"}get state(){return this.stateValue}on(e,t){let r=this.handlers.get(e);return r||(r=new Set,this.handlers.set(e,r)),r.add(t),()=>r?.delete(t)}emit(e,t){for(let r of[...this.handlers.get(e)??[]])r(t)}async start(e={}){e.facingMode!==void 0&&(this.facing=e.facingMode),this.attempt+=1,await this.run(this.attempt)}get facingMode(){return this.facing}retry(){this.teardownAttempt(),this.start()}switchCamera(){this.facing=this.facing==="user"?"environment":"user",this.teardownAttempt(),this.start()}destroy(){this.attempt+=1,this.teardownAttempt(),this.detector?.destroy(),this.detector=null,this.options.video.srcObject=null}async run(e){let{options:t}=this;this.fired=!1,this.lastGuidanceKey=null,this.carriedDegrade=0,this.carriedMeans=[],this.cameraRequestedAt=null,this.cameraReadyAt=null,this.faceAcquiredAt=null,this.captureCompleteAt=null,this.uprightGuard=(t.isPhone??Fe)(),this.setState("preflight");let r=W();if(r!=="OK"){this.fail(r==="INSECURE_CONTEXT"?"insecure":"unsupported",{phase:"preflight"});return}this.setState("acquiring");let i=t.getUserMedia??(u=>navigator.mediaDevices.getUserMedia(u)),n;this.cameraRequestedAt=this.now();try{n=await i(F(H(),this.facing))}catch(u){if(e!==this.attempt)return;this.fail(q(u),{phase:"acquiring",name:k(u)});return}if(X(n),Z(n),e!==this.attempt){for(let u of n.getTracks())u.stop();return}this.stream=n;let a=n.getVideoTracks?.()[0];if(this.trackProvenance=a===void 0?null:ce(a).catch(()=>null),this.facing=U(n)??this.facing,t.video.srcObject=n,await t.video.play().catch(()=>{}),e!==this.attempt)return;if(this.cameraReadyAt=this.now(),this.detector===null){let u={v3AssetBaseUrl:t.v3AssetBaseUrl},c=t.createDetector??(t.createWorker!==void 0&&j()?async()=>{try{return await $.create(t.createWorker(),u)}catch{return w(u)}}:()=>w(u)),l;try{l=await c()}catch(f){e===this.attempt&&this.fail("models",{phase:"models",name:k(f)},f instanceof Q?f.fallbackReason:He(f));return}if(e!==this.attempt){l.destroy();return}this.detector=l,this.options.telemetry?.({type:"detector",tier:l.tier,fallbackReason:l.fallbackReason})}let s=J(),d=t.deviceClass??ee(s);this.profiler=new te(d),this.options.telemetry?.({type:"profile",staticClass:d,activeClass:this.profiler.deviceClass,simd:s.simd}),this.gate=new M(t.thresholds??{}),this.blockStats=new _,this.lastGateSnapshotAt=this.now(),t.rankKeyframes?.()&&import("./keyframe-rank-YAJLYJYF.js").then(u=>V=u,()=>{}),this.setState("positioning"),this.positioningStartedAt=this.now(),this.startScheduler(e)}get animations(){return this.profiler?.profile.animations??"full"}startScheduler(e){let t=this.profiler;if(t===null)return;if(this.scheduler!==null){let i=this.scheduler.stats();this.carriedDegrade+=i.degradeCount,i.meanDetectMs>0&&this.carriedMeans.push(i.meanDetectMs),this.scheduler.stop()}let r=new I({cadenceHz:t.profile.cadenceHz,video:this.options.video,now:this.options.now,run:()=>this.detectTick(e)});this.scheduler=r,r.start()}async detectTick(e){let{detector:t,gate:r,profiler:i}=this,n=this.options.video;if(e!==this.attempt||t===null||r===null||i===null||this.fired||n.videoWidth===0)return;if(this.isLandscape()){this.holdUpright(e);return}let a=i.deviceClass,s=this.now(),d=this.options.makeSnapshot?.(n,i.profile.inputWidth)??this.defaultSnapshot(n,i.profile.inputWidth),u=null;try{u=await t.detect(d,n.videoWidth,n.videoHeight)}catch{u=null}if(e!==this.attempt||this.fired)return;i.record(this.now()-s),i.deviceClass!==a&&this.startScheduler(e);let c=u===null?de:this.options.measureQuality?.(n,u.box)??this.defaultQuality(n,u.box),l=r.tick({timestampMs:this.now(),observation:u,quality:c,frameWidth:n.videoWidth,frameHeight:n.videoHeight});l.accepted&&this.faceAcquiredAt===null&&(this.faceAcquiredAt=l.at),this.blockStats?.record(l),!l.ready&&l.at-this.lastGateSnapshotAt>=xe&&(this.lastGateSnapshotAt=l.at,this.reportGate(!1)),this.emit("checks",{engine:"v3",progress:l.p,q:l.q,factors:l.factors,attempt:e}),l.guidanceKey!==this.lastGuidanceKey&&(this.lastGuidanceKey=l.guidanceKey,this.emit("guidance",{key:l.guidanceKey})),l.ready&&this.stateValue==="positioning"&&(this.fired=!0,this.captureCompleteAt=l.at,this.fire(e))}async fire(e){let{options:t}=this,r=this.scheduler;r?.stop(),this.reportGate(!0);let i=r?.stats()??{degradeCount:0,meanDetectMs:0},n=[...this.carriedMeans,...i.meanDetectMs>0?[i.meanDetectMs]:[]];t.telemetry?.({type:"fired",timeToGateMs:this.now()-this.positioningStartedAt,degradeCount:this.carriedDegrade+i.degradeCount,meanDetectMs:n.length===0?0:n.reduce((g,y)=>g+y,0)/n.length});let a=t.mode??"clip",s=t.rankKeyframes?.()&&V?V.default(this,e).catch(()=>this.collectKeyframes(e)):this.collectKeyframes(e);if(a==="photo"){let g=this.watchRotation(e,null),y=await s;if(g(),e!==this.attempt)return;if(y===null){this.fail("generic",{phase:"keyframes"});return}let ve=await this.provenance({n:0,meanGapMs:0,stdGapMs:0,captureLatencyMs:null},!1);if(e!==this.attempt)return;this.finishCapture({keyframe:y.blob,previewDataUrl:y.previewDataUrl,...ve});return}this.setState("recording");let d=t.createRecorder?.()??new A,u=this.stream;if(u===null){this.fail("generic",{phase:"recording"});return}let c=le(t.video),l=t.screenRamp?.(),f=l!==void 0,h=ae(l,{paint:g=>{(g===null||e===this.attempt)&&this.emit("ramp",{colour:g})},now:()=>this.now(),frames:c.latest});this.ramp=h;let p=()=>{c.stop(),h.stop(),this.ramp===h&&(this.ramp=null)},m=this.watchRotation(e,d),v=null;s.then(g=>{v=g},()=>{});let E=()=>{e===this.attempt&&v!==null&&this.emit("frozen",{previewDataUrl:v.previewDataUrl})},C,T;try{[C,T]=await Promise.all([d.record(u,E,()=>h.started(this.now())),s])}catch(g){if(m(),p(),e!==this.attempt)return;let y=g.kind;this.fail(y==="cliptoolarge"?"cliptoolarge":"recorder",{phase:"recording",name:k(g)});return}m();let me=c.stats();if(p(),e!==this.attempt)return;if(R(C.blob)){this.fail("cliptoolarge",{phase:"recording"});return}if(T===null){this.fail("generic",{phase:"keyframes"});return}let D=h.report(),fe=await this.provenance(me,f);e===this.attempt&&this.finishCapture({clip:C.blob,clipMimeType:C.mimeType,keyframe:T.blob,previewDataUrl:T.previewDataUrl,...D!==void 0&&D.rendered.length>0?{screenRamp:D}:{},...fe})}async provenance(e,t){let r=this.trackProvenance;if(r===null)return{};let i,n=new Promise(s=>{i=setTimeout(()=>s(null),Le)}),a=await Promise.race([r,n]);return clearTimeout(i),a===null?{}:{provenance:ue(a,e,t)}}isLandscape(){let e=this.options.video;return this.uprightGuard&&e.videoWidth>e.videoHeight}holdUpright(e){this.gate?.reset(),this.emit("checks",{engine:"v3",progress:0,q:0,factors:{presence:0,centering:0,size:0,pose:0,sharpness:0,exposure:0,motion:0},attempt:e}),this.lastGuidanceKey!==G&&(this.lastGuidanceKey=G,this.emit("guidance",{key:G}))}watchRotation(e,t){if(!this.uprightGuard)return()=>{};let r=this.options.video,i=()=>{if(e!==this.attempt||t!==null&&this.stateValue!=="recording"){s();return}r.videoWidth>0&&this.isLandscape()&&(s(),this.abortRecording(e,t))},n=setInterval(i,Pe);r.addEventListener?.("resize",i);let a=!1;function s(){a||(a=!0,clearInterval(n),r.removeEventListener?.("resize",i))}return s}abortRecording(e,t){if(e!==this.attempt)return;this.attempt+=1;let r=this.attempt;try{t?.stop()}catch{}this.ramp?.stop(),this.ramp=null,this.fired=!1,this.captureCompleteAt=null,this.gate=new M(this.options.thresholds??{}),this.blockStats=new _,this.lastGateSnapshotAt=this.now(),this.lastGuidanceKey=null,this.setState("positioning"),this.positioningStartedAt=this.now(),this.holdUpright(r),this.startScheduler(r)}async collectKeyframes(e){let t=this.options.captureKeyframe??(n=>this.defaultKeyframe(n)),r=Ge/(L-1),i=null;for(let n=0;n<L;n+=1){if(e!==this.attempt)return i;try{let a=await t(this.options.video);(i===null||a.sharpness>i.sharpness)&&(i=a)}catch{}n<L-1&&await Ne(r)}return i}finishCapture(e){this.stopTracks(),this.setState("captured");let t=this.captureTiming();this.emit("artifacts",t===void 0?e:{...e,timing:t})}captureTiming(){let e={},t=(r,i,n)=>{i!==null&&n!==null&&(e[r]=Math.max(0,Math.round(n-i)))};return t("cameraReadyMs",this.cameraRequestedAt,this.cameraReadyAt),t("faceAcquireMs",this.cameraReadyAt,this.faceAcquiredAt),t("captureMs",this.faceAcquiredAt,this.captureCompleteAt),Object.keys(e).length>0?e:void 0}async defaultKeyframe(e){let t=document.createElement("canvas"),r=await(this.facing==="user"?se:Ve)(e,t),i=t.toDataURL("image/jpeg",.92);return{blob:r,previewDataUrl:i,sharpness:this.centerSharpness(e)}}defaultSnapshot(e,t){try{let r=this.snapshotCanvas??document.createElement("canvas"),i=t/Math.max(1,e.videoWidth),n=Math.max(1,Math.round(e.videoWidth*i)),a=Math.max(1,Math.round(e.videoHeight*i)),s=r.getContext("2d");return s===null?e:(r.width!==n&&(r.width=n),r.height!==a&&(r.height=a),s.drawImage(e,0,0,n,a),this.snapshotCanvas=r,r)}catch{return e}}defaultQuality(e,t){let r=he(e,t,96);return r===null?de:{sharpness:x(r),exposure:ie(r),meanLuma:re(r)}}centerSharpness(e){let t=Y(e),r=he(e,{x:t.width*.25,y:t.height*.25,width:t.width*.5,height:t.height*.5},96);return r===null?0:x(r)}teardownAttempt(){this.scheduler?.stop(),this.scheduler=null,this.reportGate(!0),this.gate=null,this.ramp?.stop(),this.ramp=null,this.stopTracks()}reportGate(e){let t=this.blockStats,r=this.profiler;if(t===null||r===null)return;let i=t.summary();e&&(this.blockStats=null),i.ticks!==0&&this.options.telemetry?.({type:"gate",final:e,activeClass:r.deviceClass,cadenceHz:r.profile.cadenceHz,...i})}stopTracks(){if(this.stream!==null){for(let e of this.stream.getTracks())e.stop();this.stream=null}}fail(e,t,r){this.scheduler?.stop(),this.reportGate(!0),this.stopTracks(),this.setState("error"),this.options.telemetry?.({type:"error",kind:e,fallbackReason:r});let{phase:i,name:n}=t;this.emit("error",{kind:e,retryable:e!=="insecure"&&e!=="unsupported",detail:n===void 0?{phase:i}:{phase:i,name:n}})}setState(e){this.stateValue=e,this.emit("statechange",{state:e})}now(){return this.options.now?.()??performance.now()}},V;function Ne(o){return new Promise(e=>setTimeout(e,o))}function He(o){return o instanceof Error?o.message:String(o)}function he(o,e,t){try{let r=document.createElement("canvas"),i=t/Math.max(1,e.width);r.width=Math.max(1,Math.round(e.width*i)),r.height=Math.max(1,Math.round(e.height*i));let n=r.getContext("2d");return n===null?null:(n.drawImage(o,e.x,e.y,e.width,e.height,0,0,r.width,r.height),n.getImageData(0,0,r.width,r.height))}catch{return null}}export{ge as a,be as b,ye as c,ne as d,b as e,A as f,Be as g,We as h,Se as i,ze as j,se as k,I as l,Te as m,M as n,ke as o,_ as p,xe as q,G as r,Pe as s,L as t,Ge as u,Le as v,pe as w};
@@ -0,0 +1 @@
1
+ var A=180,g=[100,190],x=64;function f(r,n){return .299*(r[n]??0)+.587*(r[n+1]??0)+.114*(r[n+2]??0)}function b(r){let{data:n,width:e,height:o}=r,t=e*o;if(t===0)return 0;let u=0;for(let s=0;s<t;s+=1)u+=f(n,s*4);return u/t}function E(r){let{data:n,width:e,height:o}=r;if(e<3||o<3)return 0;let t=new Float32Array(e*o);for(let a=0;a<t.length;a+=1)t[a]=f(n,a*4);let u=0,s=0,c=0;for(let a=1;a<o-1;a+=1)for(let i=1;i<e-1;i+=1){let m=a*e+i,l=(t[m-e]??0)+(t[m-1]??0)+(t[m+1]??0)+(t[m+e]??0)-4*(t[m]??0);u+=l,s+=l*l,c+=1}if(c===0)return 0;let h=u/c,p=s/c-h*h;return Math.min(1,Math.max(0,p)/180)}function F(r){let n=b(r),[e,o]=g,t=n<e?e-n:n>o?n-o:0;return Math.max(0,1-t/x)}export{A as a,g as b,b as c,E as d,F as e};
@@ -0,0 +1 @@
1
+ function c(t,n){return{video:{width:{ideal:1280,max:1280},height:{ideal:720,max:720},facingMode:n,frameRate:{ideal:24,max:30}},audio:!1}}var o=600;function r(){if(typeof window>"u"||typeof navigator>"u")return"desktop";let t=String(navigator.userAgent??"");if(/iPhone|iPod/i.test(t))return"phone";if(/iPad/i.test(t))return"tablet";if(/Android/i.test(t))return/Mobile/i.test(t)?"phone":"tablet";if(/BlackBerry|IEMobile|Opera Mini/i.test(t))return"phone";if(Number(navigator.maxTouchPoints??0)<=1)return"desktop";if(/Macintosh/.test(t))return"tablet";if(!a())return"desktop";let e=i();return e>0&&e<o?"phone":"tablet"}function s(){return r()!=="desktop"}function i(){try{let t=window.screen,n=Number(t?.width??0),e=Number(t?.height??0);return n>0&&e>0?Math.min(n,e):0}catch{return 0}}function u(t){try{let e=t?.getVideoTracks?.()[0]?.getSettings?.().facingMode;return e==="user"||e==="environment"?e:null}catch{return null}}function a(){try{return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches}catch{return!1}}var d=.45,f=.9,h=.4;export{c as a,o as b,r as c,s as d,u as e,d as f,f as g,h};
@@ -0,0 +1 @@
1
+ import{a as T,b as R}from"./chunk-DK5YPBDQ.js";var N=1e3,_=[[1,0],[0,1],[1,1],[1,-1]];function w(i){let{width:t,height:e,data:r}=i;if(t<16||e<16)return-1;let s=new Uint8Array(t*e);for(let n=0,a=0;n<s.length;n+=1,a+=4)s[n]=Math.round(.299*(r[a]??0)+.587*(r[a+1]??0)+.114*(r[a+2]??0));let o=-1;for(let[n,a]of _){let l=new Uint32Array(256),c=new Float64Array(256),p=0;for(let h=1;h<e-1;h+=1){let u=h*t,S=(h+a)*t,A=(h-a)*t;for(let g=1;g<t-1;g+=1){let y=s[S+g+n]??0,z=s[A+g-n]??0,v=Math.abs(y-z);l[v]=(l[v]??0)+1,c[v]=(c[v]??0)+Math.abs(y+z-2*(s[u+g]??0)),p+=1}}let M=Math.max(1,Math.floor(p/20)),m=0,d=0,f=0;for(let h=255;h>=0&&m<M;h-=1){let u=l[h]??0;m+=u,d+=u*h,f+=c[h]??0}if(d===0)return 0;let b=f/d;o=o<0?b:Math.min(o,b)}return o}var I=.06;function P(i,t,e,r=I){if(i===null||t.width<=0||t.height<=0)return null;let s=[i.topLeft,i.topRight,i.bottomRight,i.bottomLeft],o=e.width/t.width,n=e.height/t.height,a=Math.min(...s.map(u=>u.x))*o,l=Math.max(...s.map(u=>u.x))*o,c=Math.min(...s.map(u=>u.y))*n,p=Math.max(...s.map(u=>u.y))*n,M=(l-a)*r,m=(p-c)*r,d=Math.max(0,Math.floor(a-M)),f=Math.max(0,Math.floor(c-m)),b=Math.min(e.width,Math.ceil(l+M)),h=Math.min(e.height,Math.ceil(p+m));return b-d<16||h-f<16?null:{x:d,y:f,width:b-d,height:h-f}}function F(i,t){let e=new Uint8ClampedArray(t.width*t.height*4);for(let r=0;r<t.height;r+=1)for(let s=0;s<t.width*4;s+=1)e[r*t.width*4+s]=i.data[((t.y+r)*i.width+t.x)*4+s]??0;return{data:e,width:t.width,height:t.height}}function E(i,t=1e3){let e=t/Math.max(i.width,i.height);if(e>=1)return i;let r=Math.max(1,Math.round(i.width*e)),s=Math.max(1,Math.round(i.height*e)),o=new Uint8ClampedArray(r*s*4);for(let n=0;n<s;n+=1){let a=Math.floor(n/e),l=Math.min(i.height,Math.max(a+1,Math.floor((n+1)/e)));for(let c=0;c<r;c+=1){let p=Math.floor(c/e),M=Math.min(i.width,Math.max(p+1,Math.floor((c+1)/e)));for(let m=0;m<3;m+=1){let d=0;for(let f=a;f<l;f+=1)for(let b=p;b<M;b+=1)d+=i.data[(f*i.width+b)*4+m]??0;o[(n*r+c)*4+m]=d/((l-a)*(M-p))}o[(n*r+c)*4+3]=255}}return{data:o,width:r,height:s}}function V(i,t){return w(E(t===null?i:F(i,t)))}function B(i,t){let e=t??{x:0,y:0,width:i.width,height:i.height},r=Math.min(1,1e3/Math.max(e.width,e.height)),s=Math.max(1,Math.round(e.width*r)),o=Math.max(1,Math.round(e.height*r)),n=document.createElement("canvas");n.width=s,n.height=o;try{let a=n.getContext("2d",{willReadFrequently:!0});return a===null?-1:(a.imageSmoothingQuality="high",a.drawImage(i,e.x,e.y,e.width,e.height,0,0,s,o),w(a.getImageData(0,0,s,o)))}catch{return-1}finally{n.width=0,n.height=0}}var k=class{constructor(t=2){this.stableReads=t;this.last=null;this.run=0}offer(t){return t===null?(this.reset(),!1):(this.run=t===this.last?this.run+1:1,this.last=t,this.run>=this.stableReads)}reset(){this.last=null,this.run=0}};var D=Object.freeze({...T,minIntervalMs:150,maxWidthPx:480,detectorLimit:960,searchTimeoutMs:12e3}),O=Object.freeze({detectorLimit:960,bandMaxWidthPx:1280,minBandWidthPx:900,bandTop:.55,minIntervalMs:150,stableReads:2,profileReads:5,maxReadMs:1200,searchTimeoutMs:12e3}),C=(i,t,e)=>createImageBitmap(i,Math.round(t.x),Math.round(t.y),Math.max(1,Math.round(t.w)),Math.max(1,Math.round(t.h)),{resizeWidth:Math.max(1,Math.round(Math.min(t.w,e))),resizeQuality:"high"}),x=(i,t)=>{if(i.length===0)return 0;let e=[...i].sort((r,s)=>r-s);return e[Math.min(e.length-1,Math.floor(e.length*t))]};function G(i){return i<=250?"fast":i<=600?"mid":"slow"}function Y(i,t,e){let r=i.y+i.h*t,s=Math.min(e,i.y+i.h*1.05);return{x:i.x,y:r,w:i.w,h:Math.max(1,s-r)}}var L=class{constructor(t){this.o=t;this.engine=null;this.gen=0;this.inFlight=!1;this.lastReadAt=Number.NEGATIVE_INFINITY;this.firstSeen=null;this.reads=0;this.times=[];this.mrzState={state:"searching"};this.lockState={state:"searching"};this.fallback=null;this.lockOff=!1;this.lockError=!1;this.fired=null;this.valid=null;this.faceMode="off";this.disabled=!1;this.crop=t.crop??C,this.mrzGate=new k(t.liveMrz?.stableReads??2),this.lockGate=new R(t.textLock??D)}setEngine(t){this.engine=t}get bandTop(){return this.o.liveMrz?.bandTop??O.bandTop}get hasEngine(){return this.engine!==null&&!this.disabled}reset(){this.gen++,this.inFlight=!1,this.lastReadAt=Number.NEGATIVE_INFINITY,this.firstSeen=null,this.reads=0,this.times=[],this.mrzGate.reset(),this.lockGate.reset(),this.mrzState={state:"searching"},this.lockState={state:"searching"},this.fallback=null,this.lockOff=!1,this.lockError=!1,this.fired=null,this.valid=null,this.faceMode="off"}rearmFace(){this.gen++,this.inFlight=!1,this.lastReadAt=Number.NEGATIVE_INFINITY,this.mrzGate.reset(),this.lockGate.reset(),this.fired=null,this.valid=null,this.fallback===null&&(this.mrzState={state:"searching"}),this.lockOff||(this.lockState={state:"searching"})}liveCapture(){return this.fired?.via==="live_mrz"?this.valid:null}modeFor(t){return this.engine===null||this.disabled?"off":t.mrzFace&&this.o.liveMrz!==null&&this.fallback===null?"live_mrz":this.o.textLock!==null&&!this.lockOff?"text_lock":"off"}tick(t){let e=this.modeFor(t);return e!=="off"&&(this.faceMode=e),this.fired!==null?{ready:!0,via:this.fired.via,suspendQuality:this.fired.via==="live_mrz",mode:e,...this.states()}:e==="live_mrz"?this.liveTick(t,this.o.liveMrz):e==="text_lock"?this.lockTick(t,this.o.textLock):{ready:!1,suspendQuality:!1,mode:e,...this.states()}}states(){return{...this.faceMode==="live_mrz"||this.fallback!==null?{mrz:this.fallback!==null?{state:"fallback",reason:this.fallback}:this.mrzState}:{},...this.faceMode==="text_lock"?{lock:this.lockState}:{}}}canRead(t,e){let r=this.engine;return r!==null&&!this.inFlight&&!r.busy&&t-this.lastReadAt>=e}fall(t){this.fallback=t,this.mrzGate.reset()}liveTick(t,e){let r=()=>this.fallback!==null?{ready:!1,suspendQuality:!1,mode:"live_mrz",mrz:{state:"fallback",reason:this.fallback}}:{ready:!1,suspendQuality:!0,mode:"live_mrz",mrz:this.mrzState};if(!t.present||t.band===null)return this.mrzGate.reset(),this.mrzState={state:"searching"},r();if(this.firstSeen??(this.firstSeen=t.atMs),t.atMs-this.firstSeen>e.searchTimeoutMs)return this.fall("timeout"),r();if(t.band.w<e.minBandWidthPx)return t.card!==null&&t.card.w<e.minBandWidthPx?(this.fall("unsupported"),r()):(this.mrzState={state:"reading",coach:t.portrait?"turnSideways":"moveCloser"},{ready:!1,suspendQuality:!1,mode:"live_mrz",mrz:this.mrzState});if(!this.canRead(t.atMs,e.minIntervalMs))return r();this.inFlight=!0,this.lastReadAt=t.atMs;let s=this.gen,o=this.engine,n=t.glareOk?t.sharpOk?void 0:"holdStill":"glare";return this.crop(t.video,t.band,e.bandMaxWidthPx).then(a=>o.bandRead(a,e.detectorLimit)).then(a=>{if(s===this.gen){if(this.reads++,this.times.push(a.ms),this.times.length>8&&this.times.shift(),this.reads>=e.profileReads&&x(this.times,.5)>e.maxReadMs)return this.fall("slow");if(this.mrzGate.offer(a.valid?a.digest??null:null)&&a.format&&a.digest){this.valid={format:a.format,...a.documentCode!==void 0?{documentCode:a.documentCode}:{},digest:a.digest,lineCount:a.lineCount,framesToValid:this.reads,msToValid:Math.round(t.atMs-(this.firstSeen??t.atMs))},this.mrzState={state:"valid",format:a.format},this.fired={via:"live_mrz",at:t.atMs};return}this.mrzState={state:"reading",...n?{coach:n}:{},...a.format?{format:a.format}:{}}}}).catch(()=>{s===this.gen&&this.fall("error")}).finally(()=>{s===this.gen&&(this.inFlight=!1)}),r()}lockTick(t,e){let r=()=>({ready:!1,suspendQuality:!1,mode:"text_lock",lock:this.lockState,...this.fallback!==null?{mrz:{state:"fallback",reason:this.fallback}}:{}});if(!t.present||t.card===null)return this.lockGate.reset(),this.lockState={state:"searching"},r();if(this.firstSeen??(this.firstSeen=t.atMs),t.atMs-this.firstSeen>e.searchTimeoutMs)return this.lockOff=!0,r();if(!this.canRead(t.atMs,e.minIntervalMs))return r();this.inFlight=!0,this.lastReadAt=t.atMs;let s=this.gen,o=this.engine,n={glareOk:t.glareOk,sharpOk:t.sharpOk};return this.crop(t.video,t.card,e.maxWidthPx).then(a=>o.layoutRead(a,e.detectorLimit)).then(a=>{if(s!==this.gen)return;this.reads++,this.times.push(a.ms),this.times.length>8&&this.times.shift();let l=this.lockGate.offer(a,t.atMs,n);this.lockState=l.state==="locked"?{state:"locked"}:{state:l.state,...l.hint?{hint:l.hint}:{}},l.state==="locked"&&(this.fired={via:"text_lock",at:t.atMs})}).catch(()=>{s===this.gen&&(this.lockOff=!0,this.lockError=!0)}).finally(()=>{s===this.gen&&(this.inFlight=!1)}),r()}disable(){this.disabled=!0,this.reset()}report(t,e,r){let s=this.faceMode;if(s==="off")return null;let o=x(this.times,.5),n={capture:t,mode:s,reads:this.reads,...this.times.length>0?{readP50Ms:Math.round(o),readP90Ms:Math.round(x(this.times,.9)),deviceClass:G(o)}:{}};return s==="live_mrz"?this.fired?.via==="live_mrz"&&this.valid!==null&&e==="live_mrz"?{...n,outcome:"valid",format:this.valid.format,framesToValid:this.valid.framesToValid,msToValid:this.valid.msToValid}:this.fallback!==null?{...n,outcome:this.fallback}:{...n,outcome:r-(this.firstSeen??r)>=(this.o.liveMrz?.searchTimeoutMs??1/0)?"timeout":"off"}:this.fired?.via==="text_lock"?{...n,outcome:"locked",framesToLock:Math.max(1,this.reads),msToLock:Math.round(this.fired.at-(this.firstSeen??this.fired.at))}:{...n,outcome:this.lockError?"error":this.lockOff?"timeout":"off"}}};export{N as a,w as b,I as c,P as d,F as e,E as f,V as g,B as h,D as i,O as j,Y as k,L as l};
@@ -0,0 +1 @@
1
+ var K={enabled:!0,hz:3,segmenterTimeoutMs:8e3,segmenterBudgetMs:120,maskThreshold:.5,maxColorStd:28,maxEdgeDensity:.08,edgeLuma:24,maxGradient:.18,minPixels:300,timeoutMs:4e3},V=12e3,b=(n,o,t)=>Math.min(t,Math.max(o,Math.round(n)));function W(n,o,t){let{x:r,y:m,width:a,height:u}=n;if(t)return[{x:r-1.5*a,y:m-.8*u,width:4*a,height:2.8*u}];let d=m-.4*u,p=1.4*u;return[{x:r-.9*a,y:d,width:.75*a,height:p},{x:r+1.15*a,y:d,width:.75*a,height:p}].map(h=>{let M=Math.max(0,h.x),l=Math.min(o.width,h.x+h.width);return{x:M,y:h.y,width:Math.max(0,l-M),height:h.height}})}function Z(n,o,t,r=K){let m=t!==null&&t.width>0&&t.height>0,a=W(o,n,m),u=a.reduce((e,s)=>e+Math.max(0,s.width)*Math.max(0,s.height),0);if(u<=0)return null;let d=Math.max(1,Math.floor(Math.sqrt(u/V))),p=m?t.data instanceof Float32Array?1:1/255:1,h=(e,s)=>{if(!m)return!1;let w=b(e/n.width*t.width-.5,0,t.width-1),C=b(s/n.height*t.height-.5,0,t.height-1);return t.data[C*t.width+w]*p>=r.maskThreshold},M=e=>.299*n.data[e]+.587*n.data[e+1]+.114*n.data[e+2],l=0,B=[0,0,0],S=[0,0,0],k=0,T=0,D=0,_=0,P=0,A=0,E=0,L=0,F=0,G=0,O=Math.min(...a.map(e=>e.x)),j=Math.max(...a.map(e=>e.x+e.width)),H=Math.min(...a.map(e=>e.y)),I=Math.max(...a.map(e=>e.y+e.height)),J=(O+j)/2,Q=(H+I)/2;for(let e of a){let s=b(e.x,0,n.width),w=b(e.x+e.width,0,n.width),C=b(e.y,0,n.height),q=b(e.y+e.height,0,n.height);for(let c=C;c<q;c+=d)for(let g=s;g<w;g+=d){if(h(g,c))continue;let Y=(c*n.width+g)*4;for(let i=0;i<3;i+=1){let x=n.data[Y+i];B[i]=B[i]+x,S[i]=S[i]+x*x}l+=1;let y=M(Y);g<J?(D+=y,_+=1):(P+=y,A+=1),c<Q?(E+=y,L+=1):(F+=y,G+=1);for(let[i,x]of[[g+d,c],[g,c+d]])i>=w||x>=q||h(i,x)||(k+=1,Math.abs(M((x*n.width+i)*4)-y)>r.edgeLuma&&(T+=1))}}if(l<r.minPixels)return null;let U=0;for(let e=0;e<3;e+=1){let s=B[e]/l;U+=Math.max(0,S[e]/l-s*s)}let N=Math.sqrt(U/3),z=k===0?0:T/k,f=(e,s)=>s===0?null:e/s,R=(e,s)=>e===null||s===null?0:Math.abs(e-s)/255,X=Math.max(R(f(D,_),f(P,A)),R(f(E,L),f(F,G)));return{method:m?"segmenter":"strip",uniform:N<=r.maxColorStd&&z<=r.maxEdgeDensity&&X<=r.maxGradient,colorStd:Math.round(N*10)/10,edgeDensity:Math.round(z*1e3)/1e3,gradient:Math.round(X*1e3)/1e3,pixels:l}}function $(n){let o=n!==null&&typeof n=="object"?n:{},t=K,r=(m,a,u,d)=>typeof m=="number"&&Number.isFinite(m)&&m>=u&&m<=d?m:a;return{enabled:typeof o.enabled=="boolean"?o.enabled:t.enabled,hz:r(o.hz,t.hz,.5,15),segmenterTimeoutMs:r(o.segmenterTimeoutMs,t.segmenterTimeoutMs,0,6e4),segmenterBudgetMs:r(o.segmenterBudgetMs,t.segmenterBudgetMs,1,2e3),maskThreshold:r(o.maskThreshold,t.maskThreshold,0,1),maxColorStd:r(o.maxColorStd,t.maxColorStd,0,255),maxEdgeDensity:r(o.maxEdgeDensity,t.maxEdgeDensity,0,1),edgeLuma:r(o.edgeLuma,t.edgeLuma,0,255),maxGradient:r(o.maxGradient,t.maxGradient,0,1),minPixels:r(o.minPixels,t.minPixels,1,1e6),timeoutMs:r(o.timeoutMs,t.timeoutMs,0,6e4)}}export{K as a,Z as b,$ as c};
@@ -0,0 +1 @@
1
+ function y(){let e=new Map;return{on(i,n){let t=e.get(i);t===void 0&&(t=new Set,e.set(i,t));let r=n;return t.add(r),()=>{t?.delete(r)}},emit(i,n){let t=e.get(i);if(t!==void 0)for(let r of[...t])r(n)},count(i){return e.get(i)?.size??0},clear(){e.clear()}}}async function f(){try{return typeof navigator>"u"||typeof navigator.permissions?.query!="function"?null:await navigator.permissions.query({name:"camera"})}catch{return null}}function u(e){return e==="granted"||e==="prompt"||e==="denied"?e:"unknown"}async function g(){let e=await f();return e===null?"unknown":u(e.state)}function h(e){let i=!1,n=null,t=()=>{!i&&n!==null&&e(u(n.state))};return f().then(r=>{i||(n=r,e(r===null?"unknown":u(r.state)),r?.addEventListener?.("change",t))}),()=>{i=!0,n?.removeEventListener?.("change",t)}}async function b(){if(typeof navigator>"u")return!1;let e=String(navigator.userAgent??"");if(/Android|iPhone|iPad|iPod/i.test(e)||/Macintosh/.test(e)&&(navigator.maxTouchPoints??0)>1)return!0;try{return(await navigator.mediaDevices?.enumerateDevices?.()??[]).filter(n=>n.kind==="videoinput").length>=2}catch{return!1}}function v(){if(typeof navigator>"u"||!("wakeLock"in navigator))return null;let e=navigator.wakeLock;return typeof e?.request=="function"?e:null}function m(){return typeof document>"u"||document.visibilityState==="visible"}function p(e){try{e.release().catch(()=>{})}catch{}}function S(e={}){if(e.enabled===!1)return{setActive:()=>{}};let i=!1,n=null,t=!1,r=!1,l=()=>{if(!i||t||n!==null&&!n.released)return;let o=v();if(o===null||!m())return;let a;try{a=o.request("screen")}catch{return}t=!0,a.then(s=>{if(t=!1,!i){p(s);return}n=s,s.addEventListener?.("release",()=>{n===s&&(n=null)})},()=>{t=!1})},c=()=>{m()&&l()},d=o=>{typeof document>"u"||o===r||(r=o,o?document.addEventListener("visibilitychange",c):document.removeEventListener("visibilitychange",c))};return{setActive:o=>{if(i=o,o){if(v()===null)return;d(!0),l();return}if(d(!1),n!==null){let a=n;n=null,p(a)}}}}export{y as a,g as b,h as c,b as d,S as e};