@exige/web-scanner-sdk 0.2.35 → 0.2.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
- import { A as e, C as t, G as n, I as r, J as i, K as a, L as o, R as s, U as c, V as l, a as u, f as d, o as f, r as p, v as m, w as ee } from "./driver-license-CV0oawgf.js";
3
- import { createContext as h, useCallback as g, useContext as te, useEffect as _, useLayoutEffect as v, useMemo as ne, useRef as y, useState as b } from "react";
4
- import { Fragment as x, jsx as S, jsxs as C } from "react/jsx-runtime";
2
+ import { H as e, J as t, K as n, L as r, R as i, T as a, W as o, X as s, a as c, f as l, j as u, o as d, p as f, q as p, r as m, w as ee, y as h, z as te } from "./driver-license-DWQiITx8.js";
3
+ import { createContext as g, useCallback as _, useContext as v, useEffect as y, useLayoutEffect as ne, useMemo as re, useRef as b, useState as x } from "react";
4
+ import { Fragment as ie, jsx as S, jsxs as C } from "react/jsx-runtime";
5
5
  //#region src/sdk/display-quad.ts
6
6
  function w(e) {
7
7
  return [
@@ -38,10 +38,10 @@ function T(e) {
38
38
  }
39
39
  };
40
40
  }
41
- function re(e) {
41
+ function E(e) {
42
42
  return T(w(e).map((e) => ({ ...e })));
43
43
  }
44
- var ie = class {
44
+ var ae = class {
45
45
  current;
46
46
  target;
47
47
  response;
@@ -54,7 +54,7 @@ var ie = class {
54
54
  let n = w(this.current)[t];
55
55
  return Math.hypot(e.x - n.x, e.y - n.y) / r > this.snapDistance;
56
56
  });
57
- return this.target = re(e), i && (this.current = re(e)), {
57
+ return this.target = E(e), i && (this.current = E(e)), {
58
58
  quad: this.current,
59
59
  snapped: i
60
60
  };
@@ -76,13 +76,13 @@ var ie = class {
76
76
  getCurrent() {
77
77
  return this.current;
78
78
  }
79
- }, ae = h(null);
79
+ }, oe = g(null);
80
80
  //#endregion
81
81
  //#region src/react/context.tsx
82
- function oe(e) {
82
+ function se(e) {
83
83
  e?.startsWith("blob:") && URL.revokeObjectURL(e);
84
84
  }
85
- function se(e) {
85
+ function ce(e) {
86
86
  try {
87
87
  let t = e.toDataURL("image/jpeg", .92);
88
88
  return t.startsWith("data:image/") ? t : void 0;
@@ -90,77 +90,77 @@ function se(e) {
90
90
  return;
91
91
  }
92
92
  }
93
- function ce(e, t) {
93
+ function le(e, t) {
94
94
  if (typeof e == "function") return e(t);
95
95
  }
96
- function le({ open: r, useCase: p = "document", autoCapture: m = "defaultOn", captureMode: h = "auto", torch: te = "defaultOff", onCapture: x, onDriverLicense: C, onCancel: w, onError: T, onSettings: re, onFinderStatus: le, modelUrl: E, ortWasmPaths: D, detectionIntervalMs: ue, apiRef: O, children: de }) {
97
- let k = n(h), A = y(void 0), j = y(void 0), M = y(void 0), N = y(void 0), P = y({}), F = y(new ie()), I = y(!1), fe = y(!1), L = y({
98
- onCapture: x,
99
- onDriverLicense: C,
100
- onCancel: w,
101
- onError: T,
102
- onSettings: re,
103
- onFinderStatus: le,
104
- useCase: p
105
- }), R = y(void 0), pe = y(void 0), z = y(async () => void 0), B = y(!1), V = y(void 0), me = y(null), [H, he] = b(null), [ge, U] = b(k && r ? "capturing" : k ? "ready" : "starting"), [W, G] = b(), [_e, K] = b(), [ve, ye] = b({
96
+ function ue({ open: m, useCase: h = "document", autoCapture: g = "defaultOn", captureMode: v = "auto", torch: ie = "defaultOff", onCapture: C, onDriverLicense: w, onCancel: T, onError: E, onSettings: ue, onFinderStatus: de, modelUrl: D, ortWasmPaths: O, detectionIntervalMs: fe, apiRef: k, children: pe }) {
97
+ let A = p(v), j = b(void 0), M = b(void 0), N = b(void 0), P = b(void 0), F = b({}), I = b(new ae()), L = b(!1), me = b(!1), R = b({
98
+ onCapture: C,
99
+ onDriverLicense: w,
100
+ onCancel: T,
101
+ onError: E,
102
+ onSettings: ue,
103
+ onFinderStatus: de,
104
+ useCase: h
105
+ }), he = b(void 0), ge = b(void 0), z = b(async () => void 0), B = b(!1), V = b(void 0), _e = b(null), [H, ve] = x(null), [ye, U] = x(A && m ? "capturing" : A ? "ready" : "starting"), [W, G] = x(), [be, K] = x(), [xe, Se] = x({
106
106
  width: 1,
107
107
  height: 1
108
- }), [be, xe] = b(), [Se, q] = b(), [Ce, J] = b(""), [we, Te] = b(0), [Ee, Y] = b(), [De, X] = b(), [Oe, ke] = b("idle"), [Ae, je] = b(), Me = y(void 0), [Ne, Pe] = b("front"), Fe = y("front"), [Ie, Le] = b(!1), [Re, ze] = b({
108
+ }), [Ce, we] = x(), [Te, q] = x(), [Ee, J] = x(""), [De, Oe] = x(0), [ke, Y] = x(), [Ae, X] = x(), [je, Me] = x("idle"), [Ne, Pe] = x(), Fe = b(void 0), [Ie, Le] = x("front"), Re = b("front"), [ze, Be] = x(!1), [Ve, He] = x({
109
109
  downloading: !1,
110
110
  loaded: 0,
111
111
  total: null
112
- }), Z = g(() => {
113
- oe(Me.current), Me.current = void 0, je(void 0);
114
- }, []), Q = g((e, t) => {
115
- let n = se(e);
116
- oe(Me.current), Me.current = n, je(n), t?.pause();
112
+ }), Z = _(() => {
113
+ se(Fe.current), Fe.current = void 0, Pe(void 0);
114
+ }, []), Q = _((e, t) => {
115
+ let n = ce(e);
116
+ se(Fe.current), Fe.current = n, Pe(n), t?.pause();
117
117
  }, []);
118
- v(() => {
119
- L.current = {
120
- onCapture: x,
121
- onDriverLicense: C,
122
- onCancel: w,
123
- onError: T,
124
- onSettings: re,
125
- onFinderStatus: le,
126
- useCase: p
118
+ ne(() => {
119
+ R.current = {
120
+ onCapture: C,
121
+ onDriverLicense: w,
122
+ onCancel: T,
123
+ onError: E,
124
+ onSettings: ue,
125
+ onFinderStatus: de,
126
+ useCase: h
127
127
  };
128
128
  }, [
129
- x,
130
129
  C,
131
130
  w,
132
131
  T,
133
- re,
134
- le,
135
- p
136
- ]), _(() => i(ze), []), _(() => {
137
- if (!r || p !== "drivers-license") {
138
- pe.current = void 0, R.current = void 0, B.current = !1, Pe("front"), Le(!1);
132
+ E,
133
+ ue,
134
+ de,
135
+ h
136
+ ]), y(() => s(He), []), y(() => {
137
+ if (!m || h !== "drivers-license") {
138
+ ge.current = void 0, he.current = void 0, B.current = !1, Le("front"), Be(!1);
139
139
  return;
140
140
  }
141
- let e = u({ scan: {
142
- modelUrl: E,
143
- ortWasmPaths: D
141
+ let e = c({ scan: {
142
+ modelUrl: D,
143
+ ortWasmPaths: O
144
144
  } });
145
- return pe.current = e, e.then((e) => {
146
- R.current = e;
145
+ return ge.current = e, e.then((e) => {
146
+ he.current = e;
147
147
  }), () => {
148
- e.then((e) => e.cancel()), R.current &&= void 0, pe.current = void 0;
148
+ e.then((e) => e.cancel()), he.current &&= void 0, ge.current = void 0;
149
149
  };
150
150
  }, [
151
- r,
152
- p,
153
- E,
154
- D
151
+ m,
152
+ h,
153
+ D,
154
+ O
155
155
  ]);
156
- let Be = g((e) => {
157
- he(e);
156
+ let Ue = _((e) => {
157
+ ve(e);
158
158
  }, []);
159
- _(() => {
160
- if (!r || !H) return;
159
+ y(() => {
160
+ if (!m || !H) return;
161
161
  let e = () => {
162
162
  let e = H.getBoundingClientRect();
163
- ye({
163
+ Se({
164
164
  width: e.width,
165
165
  height: e.height
166
166
  });
@@ -168,186 +168,192 @@ function le({ open: r, useCase: p = "document", autoCapture: m = "defaultOn", ca
168
168
  if (e(), typeof ResizeObserver > "u") return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
169
169
  let t = new ResizeObserver(e);
170
170
  return t.observe(H), () => t.disconnect();
171
- }, [r, H]), _(() => {
172
- if (!r) return;
171
+ }, [m, H]), y(() => {
172
+ if (!m) return;
173
173
  let e = window.setInterval(() => {
174
- let e = A.current?.getDiagnostics();
174
+ let e = j.current?.getDiagnostics();
175
175
  e && Y(e);
176
176
  }, 500);
177
177
  return () => window.clearInterval(e);
178
- }, [r, we]), _(() => {
179
- if (!r) return;
178
+ }, [m, De]), y(() => {
179
+ if (!m) return;
180
180
  let e = 0, t = performance.now(), n = (r) => {
181
- let i = F.current.step(r - t);
181
+ let i = I.current.step(r - t);
182
182
  t = r, i && K(i), e = requestAnimationFrame(n);
183
183
  };
184
184
  return e = requestAnimationFrame(n), () => cancelAnimationFrame(e);
185
- }, [r]), _(() => {
186
- if (!r || k || !H) return;
187
- let e = !1, t = new AbortController();
188
- V.current = t;
189
- let n = () => {
190
- t.abort(), V.current === t && (V.current = void 0), j.current?.stop(), j.current = void 0, A.current?.stop(), A.current = void 0, N.current = void 0, M.current = void 0, P.current = {}, Z();
185
+ }, [m]), y(() => {
186
+ if (!m || A || !H) return;
187
+ let e = !1, i = new AbortController();
188
+ V.current = i;
189
+ let o = () => {
190
+ i.abort(), V.current === i && (V.current = void 0), M.current?.stop(), M.current = void 0, j.current?.stop(), j.current = void 0, P.current = void 0, N.current = void 0, F.current = {}, Z();
191
191
  };
192
192
  return (async () => {
193
- n(), t = new AbortController(), V.current = t, I.current = !1, U("starting"), J(""), G(void 0), q(void 0), X(void 0), ke("idle"), Z();
193
+ o(), i = new AbortController(), V.current = i, L.current = !1, U("starting"), J(""), G(void 0), q(void 0), X(void 0), Me("idle"), Z();
194
194
  try {
195
- let n = await a(H, { torch: te });
195
+ let o = await t(H, { torch: ie });
196
196
  if (e) {
197
- n.stop();
197
+ o.stop();
198
198
  return;
199
199
  }
200
- A.current = n;
201
- let r = n.getSettings();
202
- if (xe(r), L.current.onSettings?.(r), console.info("[ScannerProvider] camera settings", r), L.current.useCase === "drivers-license" && Fe.current === "back") {
203
- G(void 0), K(void 0), F.current.clear(), U("ready"), (async () => {
200
+ j.current = o;
201
+ let s = o.getSettings();
202
+ if (we(s), R.current.onSettings?.(s), console.info("[ScannerProvider] camera settings", s), R.current.useCase === "drivers-license" && Re.current === "back") {
203
+ G(void 0), K(void 0), I.current.clear(), U("ready"), (async () => {
204
204
  try {
205
- let r = await f(() => {
205
+ let t = 0, a = await d(async () => {
206
+ t += 1;
207
+ let e = r();
208
+ if (t % 4 == 0 && n(e, "ImageCapture" in globalThis)) try {
209
+ let e = await o.capturePhoto();
210
+ if (e.frame && e.luminance > 10) return e.frame;
211
+ } catch {}
206
212
  try {
207
- return n.capture();
213
+ return await o.captureLiveFrame(l);
208
214
  } catch {
209
215
  return;
210
216
  }
211
217
  }, {
212
- intervalMs: ue ?? 140,
213
- signal: t.signal
218
+ intervalMs: fe ?? 140,
219
+ signal: i.signal
214
220
  });
215
- if (e || t.signal.aborted || B.current) return;
216
- B.current = !0, Q(r, H), q("video-frame"), U("captured"), await z.current({
217
- frame: r,
221
+ if (e || i.signal.aborted || B.current) return;
222
+ B.current = !0, Q(a, H), q("live-mirror"), U("captured"), await z.current({
223
+ frame: a,
218
224
  reason: "auto",
219
- method: "video-frame",
220
- settings: n.getSettings()
225
+ method: "live-mirror",
226
+ settings: o.getSettings()
221
227
  });
222
- } catch (n) {
223
- if (e || t.signal.aborted || n instanceof DOMException && n.name === "AbortError") return;
224
- let r = n instanceof Error ? n : /* @__PURE__ */ Error("Could not read the barcode.");
225
- I.current = !0, J(r.message), U("error"), L.current.onError?.(r);
228
+ } catch (t) {
229
+ if (e || i.signal.aborted || t instanceof DOMException && t.name === "AbortError") return;
230
+ let n = t instanceof Error ? t : /* @__PURE__ */ Error("Could not read the barcode.");
231
+ L.current = !0, J(n.message), U("error"), R.current.onError?.(n);
226
232
  }
227
233
  })();
228
234
  return;
229
235
  }
230
- j.current = await ee({
236
+ M.current = await a({
231
237
  source: H,
232
- autoCapture: m,
233
- intervalMs: ue,
238
+ autoCapture: g,
239
+ intervalMs: fe,
234
240
  detection: {
235
- modelUrl: E,
236
- ortWasmPaths: D
241
+ modelUrl: D,
242
+ ortWasmPaths: O
237
243
  },
238
244
  onStatus: (e) => {
239
- if (M.current = e, G(e), L.current.onFinderStatus?.(e), e.quad && e.sourceWidth && e.sourceHeight) {
240
- let t = F.current.setTarget(e.quad, e.sourceWidth, e.sourceHeight);
245
+ if (N.current = e, G(e), R.current.onFinderStatus?.(e), e.quad && e.sourceWidth && e.sourceHeight) {
246
+ let t = I.current.setTarget(e.quad, e.sourceWidth, e.sourceHeight);
241
247
  K(t.quad);
242
- } else F.current.clear(), K(void 0);
243
- e.state !== "captured" && !I.current && U("ready");
248
+ } else I.current.clear(), K(void 0);
249
+ e.state !== "captured" && !L.current && U("ready");
244
250
  },
245
251
  captureFrame: async () => {
246
- U("capturing"), P.current = {
247
- quad: F.current.getCurrent(),
248
- sourceWidth: M.current?.sourceWidth,
249
- sourceHeight: M.current?.sourceHeight
252
+ U("capturing"), F.current = {
253
+ quad: I.current.getCurrent(),
254
+ sourceWidth: N.current?.sourceWidth,
255
+ sourceHeight: N.current?.sourceHeight
250
256
  };
251
- let e = await n.capturePhoto();
252
- if (N.current = e, q(e.method), X(e.diagnostics), Y(e.diagnostics), e.luminance <= 10) throw Error(`The captured frame was blank (luminance ${e.luminance.toFixed(1)} via ${e.method}). Keep the scanner visible while capturing and retake.`);
257
+ let e = await o.capturePhoto();
258
+ if (P.current = e, q(e.method), X(e.diagnostics), Y(e.diagnostics), e.luminance <= 10) throw Error(`The captured frame was blank (luminance ${e.luminance.toFixed(1)} via ${e.method}). Keep the scanner visible while capturing and retake.`);
253
259
  return Q(e.frame, H), U("captured"), e.frame;
254
260
  },
255
261
  onCaptureError: (e) => {
256
- I.current = !0, U("error"), J(e.message);
257
- let t = A.current?.getDiagnostics();
258
- t && Y(t), L.current.onError?.(e);
262
+ L.current = !0, U("error"), J(e.message);
263
+ let t = j.current?.getDiagnostics();
264
+ t && Y(t), R.current.onError?.(e);
259
265
  },
260
266
  onCapture: async (e) => {
261
- let t = N.current;
267
+ let t = P.current;
262
268
  await new Promise((e) => window.setTimeout(e, 140));
263
- let r = {
269
+ let n = {
264
270
  ...e,
265
271
  method: t?.method ?? "video-frame",
266
- settings: t?.settings ?? n.getSettings(),
272
+ settings: t?.settings ?? o.getSettings(),
267
273
  fallbackReason: t?.fallbackReason,
268
274
  luminance: t?.luminance,
269
275
  diagnostics: t?.diagnostics,
270
- displayedQuad: P.current.quad,
271
- displaySourceWidth: P.current.sourceWidth,
272
- displaySourceHeight: P.current.sourceHeight
276
+ displayedQuad: F.current.quad,
277
+ displaySourceWidth: F.current.sourceWidth,
278
+ displaySourceHeight: F.current.sourceHeight
273
279
  };
274
- if (L.current.useCase === "drivers-license") {
275
- await z.current(r);
280
+ if (R.current.useCase === "drivers-license") {
281
+ await z.current(n);
276
282
  return;
277
283
  }
278
- await ce(L.current.onCapture, r);
284
+ await le(R.current.onCapture, n);
279
285
  }
280
286
  });
281
287
  } catch (t) {
282
288
  if (e) return;
283
- n();
284
- let r = t instanceof Error ? t : /* @__PURE__ */ Error("Camera access failed.");
285
- J(r.message), U("error"), L.current.onError?.(r);
289
+ o();
290
+ let n = t instanceof Error ? t : /* @__PURE__ */ Error("Camera access failed.");
291
+ J(n.message), U("error"), R.current.onError?.(n);
286
292
  }
287
293
  })(), () => {
288
- e = !0, n();
294
+ e = !0, o();
289
295
  };
290
296
  }, [
291
- r,
292
- H,
293
- k,
294
297
  m,
295
- te,
296
- E,
298
+ H,
299
+ A,
300
+ g,
301
+ ie,
297
302
  D,
298
- ue,
299
- we,
303
+ O,
304
+ fe,
305
+ De,
300
306
  Z,
301
307
  Q
302
308
  ]);
303
- let Ve = {
304
- open: r,
305
- phase: ge,
306
- autoCapture: m,
307
- captureMode: h,
308
- usingSystemCamera: k,
309
+ let We = {
310
+ open: m,
311
+ phase: ye,
312
+ autoCapture: g,
313
+ captureMode: v,
314
+ usingSystemCamera: A,
309
315
  finderStatus: W,
310
- displayQuad: _e,
311
- previewSize: ve,
312
- settings: be,
313
- captureMethod: Se,
314
- error: Ce,
315
- diagnostics: Ee,
316
- shutterDiagnostics: De,
317
- copyState: Oe,
318
- guidanceHint: W ? t(W.guidance, W.lighting) : void 0,
319
- detectorStatus: W?.modelStatus === "failed" ? `ML failed${W.modelError ? `: ${W.modelError}` : ""}` : W?.detector === "ml" ? `ML ${W.modelProvider ?? ""}`.trim() : "ML loading",
320
- modelDownload: Re,
321
- frozenPreviewUrl: Ae,
322
- useCase: p,
323
- licenseSide: p === "drivers-license" ? Ne : void 0,
324
- licenseBusy: p === "drivers-license" ? Ie : void 0
316
+ displayQuad: be,
317
+ previewSize: xe,
318
+ settings: Ce,
319
+ captureMethod: Te,
320
+ error: Ee,
321
+ diagnostics: ke,
322
+ shutterDiagnostics: Ae,
323
+ copyState: je,
324
+ guidanceHint: W ? ee(W.guidance, W.lighting) : void 0,
325
+ detectorStatus: h === "drivers-license" && Ie === "back" && !A ? "zxing" : W?.modelStatus === "failed" ? `ML failed${W.modelError ? `: ${W.modelError}` : ""}` : W?.detector === "ml" ? `ML ${W.modelProvider ?? ""}`.trim() : "ML loading",
326
+ modelDownload: Ve,
327
+ frozenPreviewUrl: Ne,
328
+ useCase: h,
329
+ licenseSide: h === "drivers-license" ? Ie : void 0,
330
+ licenseBusy: h === "drivers-license" ? ze : void 0
325
331
  };
326
- _(() => {
327
- me.current = Ve;
332
+ y(() => {
333
+ _e.current = We;
328
334
  });
329
- let He = g(() => {
330
- L.current.onCancel();
331
- }, []), $ = g(async () => {
332
- if (!fe.current) {
333
- fe.current = !0, I.current = !1, J(""), K(void 0), F.current.clear(), U("capturing");
335
+ let Ge = _(() => {
336
+ R.current.onCancel();
337
+ }, []), $ = _(async () => {
338
+ if (!me.current) {
339
+ me.current = !0, L.current = !1, J(""), K(void 0), I.current.clear(), U("capturing");
334
340
  try {
335
- let t = await c();
341
+ let t = await o();
336
342
  Q(t);
337
343
  let n = {
338
344
  width: t.width,
339
345
  height: t.height
340
346
  };
341
- xe(n), L.current.onSettings?.(n), q("system-camera");
347
+ we(n), R.current.onSettings?.(n), q("system-camera");
342
348
  let r;
343
349
  try {
344
- let e = t.getContext("2d", { willReadFrequently: !0 })?.getImageData(0, 0, t.width, t.height).data;
345
- e && (r = l(e));
350
+ let n = t.getContext("2d", { willReadFrequently: !0 })?.getImageData(0, 0, t.width, t.height).data;
351
+ n && (r = e(n));
346
352
  } catch {
347
353
  r = void 0;
348
354
  }
349
- if (L.current.useCase === "drivers-license" && Fe.current === "back") {
350
- K(void 0), F.current.clear(), P.current = {}, U("captured"), await z.current({
355
+ if (R.current.useCase === "drivers-license" && Re.current === "back") {
356
+ K(void 0), I.current.clear(), F.current = {}, U("captured"), await z.current({
351
357
  frame: t,
352
358
  reason: "manual",
353
359
  method: "system-camera",
@@ -356,15 +362,15 @@ function le({ open: r, useCase: p = "document", autoCapture: m = "defaultOn", ca
356
362
  });
357
363
  return;
358
364
  }
359
- let i = await e(t, {
360
- modelUrl: E,
361
- ortWasmPaths: D
365
+ let i = await u(t, {
366
+ modelUrl: D,
367
+ ortWasmPaths: O
362
368
  });
363
369
  if (i.status !== "success" || !i.corners || !i.quad) {
364
- I.current = !0, U("error"), J(i.message), L.current.onError?.(Error(i.message));
370
+ L.current = !0, U("error"), J(i.message), R.current.onError?.(Error(i.message));
365
371
  return;
366
372
  }
367
- P.current = {
373
+ F.current = {
368
374
  quad: i.quad,
369
375
  sourceWidth: i.sourceWidth,
370
376
  sourceHeight: i.sourceHeight
@@ -380,75 +386,75 @@ function le({ open: r, useCase: p = "document", autoCapture: m = "defaultOn", ca
380
386
  displaySourceWidth: i.sourceWidth,
381
387
  displaySourceHeight: i.sourceHeight
382
388
  };
383
- if (L.current.useCase === "drivers-license") {
389
+ if (R.current.useCase === "drivers-license") {
384
390
  await z.current(a);
385
391
  return;
386
392
  }
387
- await ce(L.current.onCapture, a);
393
+ await le(R.current.onCapture, a);
388
394
  } catch (e) {
389
395
  let t = e instanceof Error ? e : /* @__PURE__ */ Error("Could not take a photo.");
390
396
  if (t.message === "No photo was selected.") {
391
- if (Me.current) {
397
+ if (Fe.current) {
392
398
  U("error");
393
399
  return;
394
400
  }
395
- L.current.onCancel();
401
+ R.current.onCancel();
396
402
  return;
397
403
  }
398
- I.current = !0, J(t.message), U("error"), L.current.onError?.(t);
404
+ L.current = !0, J(t.message), U("error"), R.current.onError?.(t);
399
405
  } finally {
400
- fe.current = !1;
406
+ me.current = !1;
401
407
  }
402
408
  }
403
409
  }, [
404
410
  Q,
405
- E,
406
- D
407
- ]), Ue = g(async (e) => {
408
- let t = await pe.current;
411
+ D,
412
+ O
413
+ ]), Ke = _(async (e) => {
414
+ let t = await ge.current;
409
415
  if (t) {
410
- Le(!0);
416
+ Be(!0);
411
417
  try {
412
418
  let n = await t.submitStill(e.frame, e.detection);
413
419
  if (n.kind === "need-back") {
414
- if (Fe.current = "back", B.current = !1, Pe("back"), I.current = !1, J(""), G(void 0), K(void 0), F.current.clear(), Z(), k) {
420
+ if (Re.current = "back", B.current = !1, Le("back"), L.current = !1, J(""), G(void 0), K(void 0), I.current.clear(), Z(), A) {
415
421
  U("ready");
416
422
  return;
417
423
  }
418
- H?.paused && H.play(), U("starting"), Te((e) => e + 1);
424
+ H?.paused && H.play(), U("starting"), Oe((e) => e + 1);
419
425
  return;
420
426
  }
421
427
  if (n.kind === "retry") {
422
- I.current = !0, J(n.message), U("error");
428
+ L.current = !0, J(n.message), U("error");
423
429
  return;
424
430
  }
425
- await ce(L.current.onDriverLicense, n.result);
431
+ await le(R.current.onDriverLicense, n.result);
426
432
  } catch (e) {
427
433
  let t = e instanceof Error ? e : /* @__PURE__ */ Error("Driver’s license scan failed.");
428
- I.current = !0, J(t.message), U("error"), L.current.onError?.(t);
434
+ L.current = !0, J(t.message), U("error"), R.current.onError?.(t);
429
435
  } finally {
430
- Le(!1);
436
+ Be(!1);
431
437
  }
432
438
  }
433
439
  }, [
434
440
  Z,
435
441
  H,
436
- k
442
+ A
437
443
  ]);
438
- v(() => {
439
- z.current = Ue;
440
- }, [Ue]);
441
- let We = g(async () => {
442
- if (k) {
444
+ ne(() => {
445
+ z.current = Ke;
446
+ }, [Ke]);
447
+ let qe = _(async () => {
448
+ if (A) {
443
449
  await $();
444
450
  return;
445
451
  }
446
- let e = A.current;
447
- if (e && L.current.useCase === "drivers-license" && Fe.current === "back") {
452
+ let e = j.current;
453
+ if (e && R.current.useCase === "drivers-license" && Re.current === "back") {
448
454
  try {
449
455
  let t = await e.capturePhoto();
450
- if (!(await d(t.frame))?.text || B.current) return;
451
- B.current = !0, V.current?.abort(), N.current = t, q(t.method), X(t.diagnostics), Y(t.diagnostics), Q(t.frame, H), U("captured"), await z.current({
456
+ if (!(await f(t.frame))?.text || B.current) return;
457
+ B.current = !0, V.current?.abort(), P.current = t, q(t.method), X(t.diagnostics), Y(t.diagnostics), Q(t.frame, H), U("captured"), await z.current({
452
458
  frame: t.frame,
453
459
  reason: "manual",
454
460
  method: t.method,
@@ -459,74 +465,74 @@ function le({ open: r, useCase: p = "document", autoCapture: m = "defaultOn", ca
459
465
  });
460
466
  } catch (e) {
461
467
  let t = e instanceof Error ? e : /* @__PURE__ */ Error("Could not capture the camera frame.");
462
- I.current = !0, J(t.message);
463
- let n = A.current?.getDiagnostics();
464
- n && Y(n), N.current?.diagnostics && X(N.current.diagnostics), U("error"), L.current.onError?.(t);
468
+ L.current = !0, J(t.message);
469
+ let n = j.current?.getDiagnostics();
470
+ n && Y(n), P.current?.diagnostics && X(P.current.diagnostics), U("error"), R.current.onError?.(t);
465
471
  }
466
472
  return;
467
473
  }
468
474
  try {
469
- await j.current?.capture();
475
+ await M.current?.capture();
470
476
  } catch (e) {
471
477
  let t = e instanceof Error ? e : /* @__PURE__ */ Error("Could not capture the camera frame.");
472
- I.current = !0, J(t.message);
473
- let n = A.current?.getDiagnostics();
474
- n && Y(n), N.current?.diagnostics && X(N.current.diagnostics), U("error"), L.current.onError?.(t);
478
+ L.current = !0, J(t.message);
479
+ let n = j.current?.getDiagnostics();
480
+ n && Y(n), P.current?.diagnostics && X(P.current.diagnostics), U("error"), R.current.onError?.(t);
475
481
  }
476
482
  }, [
477
483
  $,
478
484
  Q,
479
485
  H,
480
- k
481
- ]), Ge = y($);
482
- Ge.current = $;
483
- let Ke = y(!1);
484
- v(() => {
485
- if (!r || !k) {
486
- Ke.current = !1;
486
+ A
487
+ ]), Je = b($);
488
+ Je.current = $;
489
+ let Ye = b(!1);
490
+ ne(() => {
491
+ if (!m || !A) {
492
+ Ye.current = !1;
487
493
  return;
488
494
  }
489
- if (!Ke.current) {
490
- if (Ke.current = !0, I.current = !1, J(""), G(void 0), q(void 0), X(void 0), ke("idle"), K(void 0), F.current.clear(), Z(), !s()) {
495
+ if (!Ye.current) {
496
+ if (Ye.current = !0, L.current = !1, J(""), G(void 0), q(void 0), X(void 0), Me("idle"), K(void 0), I.current.clear(), Z(), !te()) {
491
497
  U("ready");
492
498
  return;
493
499
  }
494
- Ge.current();
500
+ Je.current();
495
501
  }
496
502
  }, [
497
- r,
498
- k,
503
+ m,
504
+ A,
499
505
  Z
500
506
  ]);
501
- let qe = g(() => {
502
- if (I.current = !1, B.current = !1, J(""), X(void 0), ke("idle"), G(void 0), K(void 0), F.current.clear(), k) {
507
+ let Xe = _(() => {
508
+ if (L.current = !1, B.current = !1, J(""), X(void 0), Me("idle"), G(void 0), K(void 0), I.current.clear(), A) {
503
509
  $();
504
510
  return;
505
511
  }
506
- if (Z(), p === "drivers-license") {
507
- U("starting"), Te((e) => e + 1);
512
+ if (Z(), h === "drivers-license") {
513
+ U("starting"), Oe((e) => e + 1);
508
514
  return;
509
515
  }
510
- let e = A.current;
511
- H?.paused && H.play(), U(e ? "ready" : "starting"), e || Te((e) => e + 1);
516
+ let e = j.current;
517
+ H?.paused && H.play(), U(e ? "ready" : "starting"), e || Oe((e) => e + 1);
512
518
  }, [
513
519
  $,
514
520
  Z,
515
521
  H,
516
- p,
517
- k
518
- ]), Je = g(async (e) => {
519
- let t = A.current;
522
+ h,
523
+ A
524
+ ]), Ze = _(async (e) => {
525
+ let t = j.current;
520
526
  t && (await t.setTorch(e), Y(t.getDiagnostics()));
521
- }, []), Ye = g((e) => {
522
- j.current?.setAutoCapture(e);
523
- }, []), Xe = g(async () => {
524
- let e = me.current, t = A.current?.getDiagnostics() ?? e.diagnostics, n = e.finderStatus, r = o({
527
+ }, []), Qe = _((e) => {
528
+ M.current?.setAutoCapture(e);
529
+ }, []), $e = _(async () => {
530
+ let e = _e.current, t = j.current?.getDiagnostics() ?? e.diagnostics, n = e.finderStatus, r = i({
525
531
  error: e.error || void 0,
526
532
  captureMethod: e.captureMethod,
527
- luminance: N.current?.luminance,
528
- fallbackReason: N.current?.fallbackReason,
529
- shutter: e.shutterDiagnostics ?? N.current?.diagnostics,
533
+ luminance: P.current?.luminance,
534
+ fallbackReason: P.current?.fallbackReason,
535
+ shutter: e.shutterDiagnostics ?? P.current?.diagnostics,
530
536
  live: t,
531
537
  finder: n ? {
532
538
  state: n.state,
@@ -551,55 +557,55 @@ function le({ open: r, useCase: p = "document", autoCapture: m = "defaultOn", ca
551
557
  let t = document.execCommand("copy");
552
558
  if (e.remove(), !t) throw Error("Clipboard copy is unavailable.");
553
559
  }
554
- ke("copied");
560
+ Me("copied");
555
561
  } catch {
556
- ke("failed");
562
+ Me("failed");
557
563
  }
558
- }, []), Ze = g(() => me.current, []), Qe = ne(() => ({
559
- capture: We,
560
- cancel: He,
561
- retry: qe,
562
- setTorch: Je,
563
- setAutoCapture: Ye,
564
- copyReport: Xe,
565
- getState: Ze
564
+ }, []), et = _(() => _e.current, []), tt = re(() => ({
565
+ capture: qe,
566
+ cancel: Ge,
567
+ retry: Xe,
568
+ setTorch: Ze,
569
+ setAutoCapture: Qe,
570
+ copyReport: $e,
571
+ getState: et
566
572
  }), [
567
- We,
568
- He,
569
573
  qe,
570
- Je,
571
- Ye,
574
+ Ge,
572
575
  Xe,
573
- Ze
576
+ Ze,
577
+ Qe,
578
+ $e,
579
+ et
574
580
  ]);
575
- _(() => {
576
- if (O) return O.current = Qe, () => {
577
- O.current = null;
581
+ y(() => {
582
+ if (k) return k.current = tt, () => {
583
+ k.current = null;
578
584
  };
579
- }, [Qe, O]);
580
- let $e = {
581
- ...Ve,
582
- ...Qe,
583
- bindPreview: Be
585
+ }, [tt, k]);
586
+ let nt = {
587
+ ...We,
588
+ ...tt,
589
+ bindPreview: Ue
584
590
  };
585
- return /* @__PURE__ */ S(ae.Provider, {
586
- value: $e,
587
- children: de
591
+ return /* @__PURE__ */ S(oe.Provider, {
592
+ value: nt,
593
+ children: pe
588
594
  });
589
595
  }
590
596
  //#endregion
591
597
  //#region src/react/hooks.ts
592
- function E() {
593
- return y(null);
598
+ function de() {
599
+ return b(null);
594
600
  }
595
601
  function D() {
596
- let e = te(ae);
602
+ let e = v(oe);
597
603
  if (!e) throw Error("useScanner must be used within ScannerProvider.");
598
604
  return e;
599
605
  }
600
606
  //#endregion
601
607
  //#region src/live-overlay-geometry.ts
602
- function ue(e, t, n, r, i) {
608
+ function O(e, t, n, r, i) {
603
609
  let a = Math.max(1, e), o = Math.max(1, t), s = Math.max(1, n), c = Math.max(1, r), l = s / a, u = c / o, d = i === "cover" ? Math.max(l, u) : Math.min(l, u), f = (s - a * d) / 2, p = (c - o * d) / 2;
604
610
  if (i === "contain") return {
605
611
  viewBox: `0 0 ${a} ${o}`,
@@ -619,7 +625,7 @@ function ue(e, t, n, r, i) {
619
625
  }
620
626
  //#endregion
621
627
  //#region src/components/ModelDownloadRing.tsx
622
- function O({ snapshot: e }) {
628
+ function fe({ snapshot: e }) {
623
629
  if (!e.downloading) return null;
624
630
  let t = e.total && e.total > 0 ? Math.min(1, e.loaded / e.total) : null, n = t === null ? null : Math.round(t * 100), r = 2 * Math.PI * 28;
625
631
  return /* @__PURE__ */ C("div", {
@@ -655,12 +661,12 @@ function O({ snapshot: e }) {
655
661
  }
656
662
  //#endregion
657
663
  //#region src/react/guidance.ts
658
- function de(e) {
659
- if (!(e.usingSystemCamera || e.licenseBusy) && e.phase !== "error") return e.phase === "starting" ? e.licenseHeadline : e.phase === "capturing" ? "Capturing full resolution…" : e.phase === "captured" ? "Document captured" : e.holdStillSeconds && e.holdStillSeconds > 0 ? m(e.holdStillSeconds) : e.guidanceHint && e.guidanceReason && e.guidanceReason !== "place-document" ? e.guidanceHint : e.licenseHeadline ?? e.guidanceHint ?? "Place the document in the frame";
664
+ function k(e) {
665
+ if (!(e.usingSystemCamera || e.licenseBusy) && e.phase !== "error") return e.phase === "starting" ? e.licenseHeadline : e.phase === "capturing" ? "Capturing full resolution…" : e.phase === "captured" ? "Document captured" : e.holdStillSeconds && e.holdStillSeconds > 0 ? h(e.holdStillSeconds) : e.guidanceHint && e.guidanceReason && e.guidanceReason !== "place-document" ? e.guidanceHint : e.licenseHeadline ?? e.guidanceHint ?? "Place the document in the frame";
660
666
  }
661
667
  //#endregion
662
668
  //#region src/react/parts.tsx
663
- var k = {
669
+ var pe = {
664
670
  primaryColorHex: "--scanner-overlay-primary",
665
671
  seekingColorHex: "--scanner-overlay-seeking",
666
672
  detectingColorHex: "--scanner-overlay-detecting",
@@ -671,7 +677,7 @@ var k = {
671
677
  function A(e) {
672
678
  if (!e) return;
673
679
  let t = {};
674
- for (let [n, r] of Object.entries(k)) {
680
+ for (let [n, r] of Object.entries(pe)) {
675
681
  let i = e[n]?.trim();
676
682
  i && (t[r] = i);
677
683
  }
@@ -694,10 +700,10 @@ function j({ theme: e, style: t, title: n, children: r }) {
694
700
  });
695
701
  }
696
702
  function M() {
697
- let { bindPreview: e, frozenPreviewUrl: t, usingSystemCamera: n } = D(), r = y(null), i = g((t) => {
703
+ let { bindPreview: e, frozenPreviewUrl: t, usingSystemCamera: n } = D(), r = b(null), i = _((t) => {
698
704
  r.current = t, e(t);
699
705
  }, [e]);
700
- return _(() => {
706
+ return y(() => {
701
707
  t && r.current?.pause();
702
708
  }, [t]), n ? t ? /* @__PURE__ */ S("img", {
703
709
  src: t,
@@ -707,7 +713,7 @@ function M() {
707
713
  }) : /* @__PURE__ */ S("div", {
708
714
  className: "scanner-camera-overlay__video",
709
715
  "aria-hidden": "true"
710
- }) : /* @__PURE__ */ C(x, { children: [/* @__PURE__ */ S("video", {
716
+ }) : /* @__PURE__ */ C(ie, { children: [/* @__PURE__ */ S("video", {
711
717
  ref: i,
712
718
  className: "scanner-camera-overlay__video",
713
719
  muted: !0,
@@ -726,7 +732,7 @@ function M() {
726
732
  function N() {
727
733
  let { finderStatus: e, displayQuad: t, previewSize: n } = D();
728
734
  if (!t || !e?.sourceWidth || !e.sourceHeight) return null;
729
- let r = ue(e.sourceWidth, e.sourceHeight, n.width, n.height, "cover");
735
+ let r = O(e.sourceWidth, e.sourceHeight, n.width, n.height, "cover");
730
736
  return /* @__PURE__ */ S("svg", {
731
737
  className: `scanner-camera-overlay__quad ${e.state}`,
732
738
  viewBox: r.viewBox,
@@ -736,7 +742,7 @@ function N() {
736
742
  });
737
743
  }
738
744
  function P({ title: e }) {
739
- let { phase: t, cancel: n, usingSystemCamera: r, useCase: i, licenseSide: a, licenseBusy: o } = D(), s = i === "drivers-license" ? p(a ?? "front", r) : void 0, c = e ?? s?.title ?? "Scan a document";
745
+ let { phase: t, cancel: n, usingSystemCamera: r, useCase: i, licenseSide: a, licenseBusy: o } = D(), s = i === "drivers-license" ? m(a ?? "front", r) : void 0, c = e ?? s?.title ?? "Scan a document";
740
746
  return /* @__PURE__ */ C("div", {
741
747
  className: "scanner-camera-overlay__topbar",
742
748
  children: [/* @__PURE__ */ C("div", { children: [/* @__PURE__ */ S("strong", { children: c }), /* @__PURE__ */ C("span", {
@@ -744,7 +750,7 @@ function P({ title: e }) {
744
750
  children: [
745
751
  o && (a === "back" ? "Reading the barcode…" : "Reading the front…"),
746
752
  !o && s && t === "error" && (a === "back" ? "Could not read the back" : "Could not read the front"),
747
- !o && !s && r && /* @__PURE__ */ C(x, { children: [
753
+ !o && !s && r && /* @__PURE__ */ C(ie, { children: [
748
754
  t === "starting" && "Preparing the system camera…",
749
755
  t === "ready" && "Take a photo. There is no live document guide.",
750
756
  t === "capturing" && "Looking for a document…",
@@ -762,7 +768,7 @@ function P({ title: e }) {
762
768
  });
763
769
  }
764
770
  function F() {
765
- let { phase: e, error: t, diagnostics: n, copyState: r, retry: i, copyReport: a, cancel: o, usingSystemCamera: s, frozenPreviewUrl: c, useCase: l, licenseSide: u, licenseBusy: d } = D(), f = l === "drivers-license" ? p(u ?? "front", s) : void 0;
771
+ let { phase: e, error: t, diagnostics: n, copyState: r, retry: i, copyReport: a, cancel: o, usingSystemCamera: s, frozenPreviewUrl: c, useCase: l, licenseSide: u, licenseBusy: d } = D(), f = l === "drivers-license" ? m(u ?? "front", s) : void 0;
766
772
  return e === "error" ? /* @__PURE__ */ C("div", {
767
773
  className: "scanner-camera-overlay__message",
768
774
  role: "alert",
@@ -819,7 +825,7 @@ function F() {
819
825
  }
820
826
  function I() {
821
827
  let { finderStatus: e, detectorStatus: t, settings: n, usingSystemCamera: r, captureMethod: i, phase: a, useCase: o, licenseSide: s } = D(), c = n?.width, l = n?.height, u = o === "drivers-license" ? ` · ${s === "back" ? "back" : "front"}` : "";
822
- return r ? /* @__PURE__ */ S("div", {
828
+ if (r) return /* @__PURE__ */ S("div", {
823
829
  className: "scanner-camera-overlay__status",
824
830
  "aria-live": "polite",
825
831
  children: /* @__PURE__ */ C("div", {
@@ -831,14 +837,16 @@ function I() {
831
837
  c && l ? ` · ${c}×${l}` : ""
832
838
  ]
833
839
  })
834
- }) : /* @__PURE__ */ S("div", {
840
+ });
841
+ let d = o === "drivers-license" && s === "back", f = d && !e ? "reading" : e?.state ?? "detecting";
842
+ return /* @__PURE__ */ S("div", {
835
843
  className: "scanner-camera-overlay__status",
836
844
  "aria-live": "polite",
837
845
  children: /* @__PURE__ */ C("div", {
838
846
  className: "scanner-camera-overlay__status-line",
839
847
  children: [
840
- /* @__PURE__ */ S("span", { className: e?.state ?? "detecting" }),
841
- e?.state ?? "detecting",
848
+ /* @__PURE__ */ S("span", { className: d && !e ? "detecting" : e?.state ?? "detecting" }),
849
+ f,
842
850
  u,
843
851
  e ? ` · ${Math.round(e.confidence * 100)}% · ${e.stableFrames}/${e.requiredStableFrames}` : "",
844
852
  ` · ${t}`,
@@ -848,7 +856,7 @@ function I() {
848
856
  })
849
857
  });
850
858
  }
851
- function fe() {
859
+ function L() {
852
860
  let { diagnostics: e, shutterDiagnostics: t, captureMethod: n, copyState: i, copyReport: a } = D(), o = e?.engine ?? r();
853
861
  return /* @__PURE__ */ C("dl", {
854
862
  className: "scanner-camera-overlay__diagnostics",
@@ -875,8 +883,8 @@ function fe() {
875
883
  ]
876
884
  });
877
885
  }
878
- function L() {
879
- let { autoCapture: e, phase: t, finderStatus: n, diagnostics: r, captureMethod: i, settings: a, cancel: o, capture: s, setAutoCapture: c, setTorch: l, usingSystemCamera: u, licenseBusy: d, useCase: f, licenseSide: m, guidanceHint: ee } = D(), h = a?.width, g = a?.height, te = u ? t === "ready" : e !== "only", _ = f === "drivers-license" ? p(m ?? "front", u) : void 0, v = de({
886
+ function me() {
887
+ let { autoCapture: e, phase: t, finderStatus: n, diagnostics: r, captureMethod: i, settings: a, cancel: o, capture: s, setAutoCapture: c, setTorch: l, usingSystemCamera: u, licenseBusy: d, useCase: f, licenseSide: p, guidanceHint: ee } = D(), h = a?.width, te = a?.height, g = u ? t === "ready" : e !== "only", _ = f === "drivers-license" ? m(p ?? "front", u) : void 0, v = k({
880
888
  usingSystemCamera: u,
881
889
  phase: t,
882
890
  licenseBusy: d,
@@ -884,7 +892,7 @@ function L() {
884
892
  guidanceHint: ee,
885
893
  guidanceReason: n?.guidance.reason,
886
894
  licenseHeadline: _?.headline
887
- }), ne = !!n?.holdStillSeconds;
895
+ }), y = !!n?.holdStillSeconds;
888
896
  return /* @__PURE__ */ C("div", {
889
897
  className: "scanner-camera-overlay__controls",
890
898
  children: [
@@ -898,11 +906,11 @@ function L() {
898
906
  className: "scanner-camera-overlay__capture",
899
907
  children: [
900
908
  v && /* @__PURE__ */ S("p", {
901
- className: `scanner-camera-overlay__guidance${ne ? " is-ready" : ""}`,
909
+ className: `scanner-camera-overlay__guidance${y ? " is-ready" : ""}`,
902
910
  "aria-live": "polite",
903
911
  children: v
904
912
  }),
905
- te && /* @__PURE__ */ S("button", {
913
+ g && /* @__PURE__ */ S("button", {
906
914
  type: "button",
907
915
  className: "scanner-camera-overlay__shutter",
908
916
  onClick: () => void s(),
@@ -930,16 +938,16 @@ function L() {
930
938
  }),
931
939
  /* @__PURE__ */ C("div", {
932
940
  className: "scanner-camera-overlay__quality",
933
- children: [/* @__PURE__ */ S("span", { children: u ? "System camera" : i === "live-mirror" ? "Mirror" : "Camera" }), /* @__PURE__ */ S("strong", { children: h && g ? `${h} × ${g}` : u ? "Tap to photograph" : "Measuring…" })]
941
+ children: [/* @__PURE__ */ S("span", { children: u ? "System camera" : i === "live-mirror" ? "Mirror" : "Camera" }), /* @__PURE__ */ S("strong", { children: h && te ? `${h} × ${te}` : u ? "Tap to photograph" : "Measuring…" })]
934
942
  })
935
943
  ]
936
944
  });
937
945
  }
938
946
  function R({ snapshot: e }) {
939
947
  let { modelDownload: t } = D();
940
- return /* @__PURE__ */ S(O, { snapshot: e ?? t });
948
+ return /* @__PURE__ */ S(fe, { snapshot: e ?? t });
941
949
  }
942
950
  //#endregion
943
- export { L as ScannerControls, fe as ScannerDiagnostics, j as ScannerFrame, R as ScannerModelDownload, F as ScannerNotice, M as ScannerPreview, le as ScannerProvider, N as ScannerQuad, I as ScannerStatus, P as ScannerTopBar, D as useScanner, E as useScannerRef };
951
+ export { me as ScannerControls, L as ScannerDiagnostics, j as ScannerFrame, R as ScannerModelDownload, F as ScannerNotice, M as ScannerPreview, ue as ScannerProvider, N as ScannerQuad, I as ScannerStatus, P as ScannerTopBar, D as useScanner, de as useScannerRef };
944
952
 
945
953
  //# sourceMappingURL=react.js.map