@exige/web-scanner-sdk 0.2.37 → 0.2.38

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,5 +1,5 @@
1
1
  "use client";
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";
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-DC8Jb0DE.js";
3
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
4
  import { Fragment as ie, jsx as S, jsxs as C } from "react/jsx-runtime";
5
5
  //#region src/sdk/display-quad.ts
@@ -11,7 +11,7 @@ function w(e) {
11
11
  e.bottomLeft
12
12
  ];
13
13
  }
14
- function T(e) {
14
+ function ae(e) {
15
15
  let [t, n, r, i] = e;
16
16
  return {
17
17
  topLeft: t,
@@ -38,10 +38,10 @@ function T(e) {
38
38
  }
39
39
  };
40
40
  }
41
- function E(e) {
42
- return T(w(e).map((e) => ({ ...e })));
41
+ function oe(e) {
42
+ return ae(w(e).map((e) => ({ ...e })));
43
43
  }
44
- var ae = class {
44
+ var se = class {
45
45
  current;
46
46
  target;
47
47
  response;
@@ -54,7 +54,7 @@ var ae = 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 = E(e), i && (this.current = E(e)), {
57
+ return this.target = oe(e), i && (this.current = oe(e)), {
58
58
  quad: this.current,
59
59
  snapped: i
60
60
  };
@@ -62,7 +62,7 @@ var ae = class {
62
62
  step(e) {
63
63
  if (!this.current || !this.target) return this.current;
64
64
  let t = 1 - Math.exp(-this.response * Math.max(0, e) / 1e3);
65
- return this.current = T(w(this.current).map((e, n) => {
65
+ return this.current = ae(w(this.current).map((e, n) => {
66
66
  let r = w(this.target)[n];
67
67
  return {
68
68
  x: e.x + (r.x - e.x) * t,
@@ -76,13 +76,22 @@ var ae = class {
76
76
  getCurrent() {
77
77
  return this.current;
78
78
  }
79
- }, oe = g(null);
79
+ }, ce = g(null);
80
80
  //#endregion
81
81
  //#region src/react/context.tsx
82
- function se(e) {
82
+ function le(e) {
83
83
  e?.startsWith("blob:") && URL.revokeObjectURL(e);
84
84
  }
85
- function ce(e) {
85
+ function ue() {
86
+ return new Promise((e) => {
87
+ if (typeof requestAnimationFrame == "function") {
88
+ requestAnimationFrame(() => requestAnimationFrame(() => e()));
89
+ return;
90
+ }
91
+ setTimeout(e, 0);
92
+ });
93
+ }
94
+ function de(e) {
86
95
  try {
87
96
  let t = e.toDataURL("image/jpeg", .92);
88
97
  return t.startsWith("data:image/") ? t : void 0;
@@ -90,117 +99,124 @@ function ce(e) {
90
99
  return;
91
100
  }
92
101
  }
93
- function le(e, t) {
102
+ function fe(e, t) {
94
103
  if (typeof e == "function") return e(t);
95
104
  }
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({
105
+ function pe({ open: m, useCase: h = "document", autoCapture: g = "defaultOn", captureMode: v = "auto", torch: ie = "defaultOff", onCapture: C, onDriverLicense: w, onCancel: ae, onError: oe, onSettings: pe, onFinderStatus: me, modelUrl: T, ortWasmPaths: E, detectionIntervalMs: he, apiRef: D, children: ge }) {
106
+ let O = p(v), k = b(void 0), A = b(void 0), j = b(void 0), M = b(void 0), N = b({}), P = b(new se()), F = b(!1), _e = b(!1), I = b({
98
107
  onCapture: C,
99
108
  onDriverLicense: w,
100
- onCancel: T,
101
- onError: E,
102
- onSettings: ue,
103
- onFinderStatus: de,
109
+ onCancel: ae,
110
+ onError: oe,
111
+ onSettings: pe,
112
+ onFinderStatus: me,
104
113
  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({
114
+ }), ve = b(void 0), ye = b(void 0), L = b(async () => void 0), R = b(!1), z = b(void 0), be = b(null), [B, xe] = x(null), [Se, V] = x(O && m ? "capturing" : O ? "ready" : "starting"), [H, U] = x(), [Ce, W] = x(), [we, G] = x(), [Te, Ee] = x({
106
115
  width: 1,
107
116
  height: 1
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({
117
+ }), [De, Oe] = x(), [ke, K] = x(), [Ae, q] = x(""), [je, Me] = x(0), [Ne, J] = x(), [Pe, Y] = x(), [Fe, Ie] = x("idle"), [Le, Re] = x(), ze = b(void 0), [Be, Ve] = x("front"), He = b("front"), [Ue, We] = x(!1), [Ge, Ke] = x({
109
118
  downloading: !1,
110
119
  loaded: 0,
111
120
  total: null
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();
121
+ }), X = _(() => {
122
+ le(ze.current), ze.current = void 0, Re(void 0);
123
+ }, []), Z = _((e, t) => {
124
+ let n = de(e);
125
+ le(ze.current), ze.current = n, Re(n), t?.pause();
126
+ }, []), Q = _(async (e, t) => {
127
+ t && (G({
128
+ width: e.width,
129
+ height: e.height
130
+ }), W(t), await ue(), await new Promise((e) => {
131
+ window.setTimeout(e, 280);
132
+ }));
117
133
  }, []);
118
134
  ne(() => {
119
- R.current = {
135
+ I.current = {
120
136
  onCapture: C,
121
137
  onDriverLicense: w,
122
- onCancel: T,
123
- onError: E,
124
- onSettings: ue,
125
- onFinderStatus: de,
138
+ onCancel: ae,
139
+ onError: oe,
140
+ onSettings: pe,
141
+ onFinderStatus: me,
126
142
  useCase: h
127
143
  };
128
144
  }, [
129
145
  C,
130
146
  w,
131
- T,
132
- E,
133
- ue,
134
- de,
147
+ ae,
148
+ oe,
149
+ pe,
150
+ me,
135
151
  h
136
- ]), y(() => s(He), []), y(() => {
152
+ ]), y(() => s(Ke), []), y(() => {
137
153
  if (!m || h !== "drivers-license") {
138
- ge.current = void 0, he.current = void 0, B.current = !1, Le("front"), Be(!1);
154
+ ye.current = void 0, ve.current = void 0, R.current = !1, Ve("front"), We(!1);
139
155
  return;
140
156
  }
141
157
  let e = c({ scan: {
142
- modelUrl: D,
143
- ortWasmPaths: O
158
+ modelUrl: T,
159
+ ortWasmPaths: E
144
160
  } });
145
- return ge.current = e, e.then((e) => {
146
- he.current = e;
161
+ return ye.current = e, e.then((e) => {
162
+ ve.current = e;
147
163
  }), () => {
148
- e.then((e) => e.cancel()), he.current &&= void 0, ge.current = void 0;
164
+ e.then((e) => e.cancel()), ve.current &&= void 0, ye.current = void 0;
149
165
  };
150
166
  }, [
151
167
  m,
152
168
  h,
153
- D,
154
- O
169
+ T,
170
+ E
155
171
  ]);
156
- let Ue = _((e) => {
157
- ve(e);
172
+ let qe = _((e) => {
173
+ xe(e);
158
174
  }, []);
159
175
  y(() => {
160
- if (!m || !H) return;
176
+ if (!m || !B) return;
161
177
  let e = () => {
162
- let e = H.getBoundingClientRect();
163
- Se({
178
+ let e = B.getBoundingClientRect();
179
+ Ee({
164
180
  width: e.width,
165
181
  height: e.height
166
182
  });
167
183
  };
168
184
  if (e(), typeof ResizeObserver > "u") return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
169
185
  let t = new ResizeObserver(e);
170
- return t.observe(H), () => t.disconnect();
171
- }, [m, H]), y(() => {
186
+ return t.observe(B), () => t.disconnect();
187
+ }, [m, B]), y(() => {
172
188
  if (!m) return;
173
189
  let e = window.setInterval(() => {
174
- let e = j.current?.getDiagnostics();
175
- e && Y(e);
190
+ let e = k.current?.getDiagnostics();
191
+ e && J(e);
176
192
  }, 500);
177
193
  return () => window.clearInterval(e);
178
- }, [m, De]), y(() => {
194
+ }, [m, je]), y(() => {
179
195
  if (!m) return;
180
196
  let e = 0, t = performance.now(), n = (r) => {
181
- let i = I.current.step(r - t);
182
- t = r, i && K(i), e = requestAnimationFrame(n);
197
+ let i = P.current.step(r - t);
198
+ t = r, i && W(i), e = requestAnimationFrame(n);
183
199
  };
184
200
  return e = requestAnimationFrame(n), () => cancelAnimationFrame(e);
185
201
  }, [m]), y(() => {
186
- if (!m || A || !H) return;
202
+ if (!m || O || !B) return;
187
203
  let e = !1, i = new AbortController();
188
- V.current = i;
204
+ z.current = i;
189
205
  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();
206
+ i.abort(), z.current === i && (z.current = void 0), A.current?.stop(), A.current = void 0, k.current?.stop(), k.current = void 0, M.current = void 0, j.current = void 0, N.current = {}, X();
191
207
  };
192
208
  return (async () => {
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();
209
+ o(), i = new AbortController(), z.current = i, F.current = !1, V("starting"), q(""), U(void 0), K(void 0), Y(void 0), Ie("idle"), X();
194
210
  try {
195
- let o = await t(H, { torch: ie });
211
+ let o = await t(B, { torch: ie });
196
212
  if (e) {
197
213
  o.stop();
198
214
  return;
199
215
  }
200
- j.current = o;
216
+ k.current = o;
201
217
  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 () => {
218
+ if (Oe(s), I.current.onSettings?.(s), console.info("[ScannerProvider] camera settings", s), I.current.useCase === "drivers-license" && He.current === "back") {
219
+ U(void 0), W(void 0), G(void 0), P.current.clear(), V("ready"), (async () => {
204
220
  try {
205
221
  let t = 0, a = await d(async () => {
206
222
  t += 1;
@@ -215,12 +231,12 @@ function ue({ open: m, useCase: h = "document", autoCapture: g = "defaultOn", ca
215
231
  return;
216
232
  }
217
233
  }, {
218
- intervalMs: fe ?? 140,
234
+ intervalMs: he ?? 140,
219
235
  signal: i.signal
220
236
  });
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,
237
+ if (e || i.signal.aborted || R.current || (R.current = !0, Z(a.frame, B), K("live-mirror"), V("captured"), await Q(a.frame, a.quad), e || i.signal.aborted)) return;
238
+ await L.current({
239
+ frame: a.frame,
224
240
  reason: "auto",
225
241
  method: "live-mirror",
226
242
  settings: o.getSettings()
@@ -228,43 +244,43 @@ function ue({ open: m, useCase: h = "document", autoCapture: g = "defaultOn", ca
228
244
  } catch (t) {
229
245
  if (e || i.signal.aborted || t instanceof DOMException && t.name === "AbortError") return;
230
246
  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);
247
+ F.current = !0, q(n.message), V("error"), I.current.onError?.(n);
232
248
  }
233
249
  })();
234
250
  return;
235
251
  }
236
- M.current = await a({
237
- source: H,
252
+ A.current = await a({
253
+ source: B,
238
254
  autoCapture: g,
239
- intervalMs: fe,
255
+ intervalMs: he,
240
256
  detection: {
241
- modelUrl: D,
242
- ortWasmPaths: O
257
+ modelUrl: T,
258
+ ortWasmPaths: E
243
259
  },
244
260
  onStatus: (e) => {
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);
247
- K(t.quad);
248
- } else I.current.clear(), K(void 0);
249
- e.state !== "captured" && !L.current && U("ready");
261
+ if (j.current = e, U(e), I.current.onFinderStatus?.(e), e.quad && e.sourceWidth && e.sourceHeight) {
262
+ let t = P.current.setTarget(e.quad, e.sourceWidth, e.sourceHeight);
263
+ W(t.quad);
264
+ } else P.current.clear(), W(void 0);
265
+ e.state !== "captured" && !F.current && V("ready");
250
266
  },
251
267
  captureFrame: async () => {
252
- U("capturing"), F.current = {
253
- quad: I.current.getCurrent(),
254
- sourceWidth: N.current?.sourceWidth,
255
- sourceHeight: N.current?.sourceHeight
268
+ V("capturing"), N.current = {
269
+ quad: P.current.getCurrent(),
270
+ sourceWidth: j.current?.sourceWidth,
271
+ sourceHeight: j.current?.sourceHeight
256
272
  };
257
273
  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.`);
259
- return Q(e.frame, H), U("captured"), e.frame;
274
+ if (M.current = e, K(e.method), Y(e.diagnostics), J(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.`);
275
+ return Z(e.frame, B), V("captured"), e.frame;
260
276
  },
261
277
  onCaptureError: (e) => {
262
- L.current = !0, U("error"), J(e.message);
263
- let t = j.current?.getDiagnostics();
264
- t && Y(t), R.current.onError?.(e);
278
+ F.current = !0, V("error"), q(e.message);
279
+ let t = k.current?.getDiagnostics();
280
+ t && J(t), I.current.onError?.(e);
265
281
  },
266
282
  onCapture: async (e) => {
267
- let t = P.current;
283
+ let t = M.current;
268
284
  await new Promise((e) => window.setTimeout(e, 140));
269
285
  let n = {
270
286
  ...e,
@@ -273,78 +289,80 @@ function ue({ open: m, useCase: h = "document", autoCapture: g = "defaultOn", ca
273
289
  fallbackReason: t?.fallbackReason,
274
290
  luminance: t?.luminance,
275
291
  diagnostics: t?.diagnostics,
276
- displayedQuad: F.current.quad,
277
- displaySourceWidth: F.current.sourceWidth,
278
- displaySourceHeight: F.current.sourceHeight
292
+ displayedQuad: N.current.quad,
293
+ displaySourceWidth: N.current.sourceWidth,
294
+ displaySourceHeight: N.current.sourceHeight
279
295
  };
280
- if (R.current.useCase === "drivers-license") {
281
- await z.current(n);
296
+ if (I.current.useCase === "drivers-license") {
297
+ await L.current(n);
282
298
  return;
283
299
  }
284
- await le(R.current.onCapture, n);
300
+ await fe(I.current.onCapture, n);
285
301
  }
286
302
  });
287
303
  } catch (t) {
288
304
  if (e) return;
289
305
  o();
290
306
  let n = t instanceof Error ? t : /* @__PURE__ */ Error("Camera access failed.");
291
- J(n.message), U("error"), R.current.onError?.(n);
307
+ q(n.message), V("error"), I.current.onError?.(n);
292
308
  }
293
309
  })(), () => {
294
310
  e = !0, o();
295
311
  };
296
312
  }, [
297
313
  m,
298
- H,
299
- A,
314
+ B,
315
+ O,
300
316
  g,
301
317
  ie,
302
- D,
303
- O,
304
- fe,
305
- De,
318
+ T,
319
+ E,
320
+ he,
321
+ je,
322
+ X,
306
323
  Z,
307
324
  Q
308
325
  ]);
309
- let We = {
326
+ let Je = {
310
327
  open: m,
311
- phase: ye,
328
+ phase: Se,
312
329
  autoCapture: g,
313
330
  captureMode: v,
314
- usingSystemCamera: A,
315
- finderStatus: W,
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,
331
+ usingSystemCamera: O,
332
+ finderStatus: H,
333
+ displayQuad: Ce,
334
+ barcodeOverlay: we,
335
+ previewSize: Te,
336
+ settings: De,
337
+ captureMethod: ke,
338
+ error: Ae,
339
+ diagnostics: Ne,
340
+ shutterDiagnostics: Pe,
341
+ copyState: Fe,
342
+ guidanceHint: H ? ee(H.guidance, H.lighting) : void 0,
343
+ detectorStatus: h === "drivers-license" && Be === "back" && !O ? "zxing" : H?.modelStatus === "failed" ? `ML failed${H.modelError ? `: ${H.modelError}` : ""}` : H?.detector === "ml" ? `ML ${H.modelProvider ?? ""}`.trim() : "ML loading",
344
+ modelDownload: Ge,
345
+ frozenPreviewUrl: Le,
328
346
  useCase: h,
329
- licenseSide: h === "drivers-license" ? Ie : void 0,
330
- licenseBusy: h === "drivers-license" ? ze : void 0
347
+ licenseSide: h === "drivers-license" ? Be : void 0,
348
+ licenseBusy: h === "drivers-license" ? Ue : void 0
331
349
  };
332
350
  y(() => {
333
- _e.current = We;
351
+ be.current = Je;
334
352
  });
335
- let Ge = _(() => {
336
- R.current.onCancel();
353
+ let Ye = _(() => {
354
+ I.current.onCancel();
337
355
  }, []), $ = _(async () => {
338
- if (!me.current) {
339
- me.current = !0, L.current = !1, J(""), K(void 0), I.current.clear(), U("capturing");
356
+ if (!_e.current) {
357
+ _e.current = !0, F.current = !1, q(""), W(void 0), G(void 0), P.current.clear(), V("capturing");
340
358
  try {
341
359
  let t = await o();
342
- Q(t);
360
+ Z(t);
343
361
  let n = {
344
362
  width: t.width,
345
363
  height: t.height
346
364
  };
347
- we(n), R.current.onSettings?.(n), q("system-camera");
365
+ Oe(n), I.current.onSettings?.(n), K("system-camera");
348
366
  let r;
349
367
  try {
350
368
  let n = t.getContext("2d", { willReadFrequently: !0 })?.getImageData(0, 0, t.width, t.height).data;
@@ -352,8 +370,10 @@ function ue({ open: m, useCase: h = "document", autoCapture: g = "defaultOn", ca
352
370
  } catch {
353
371
  r = void 0;
354
372
  }
355
- if (R.current.useCase === "drivers-license" && Re.current === "back") {
356
- K(void 0), I.current.clear(), F.current = {}, U("captured"), await z.current({
373
+ if (I.current.useCase === "drivers-license" && He.current === "back") {
374
+ W(void 0), G(void 0), P.current.clear(), N.current = {}, V("captured");
375
+ let e = await f(t);
376
+ await Q(t, e?.quad), await L.current({
357
377
  frame: t,
358
378
  reason: "manual",
359
379
  method: "system-camera",
@@ -363,18 +383,18 @@ function ue({ open: m, useCase: h = "document", autoCapture: g = "defaultOn", ca
363
383
  return;
364
384
  }
365
385
  let i = await u(t, {
366
- modelUrl: D,
367
- ortWasmPaths: O
386
+ modelUrl: T,
387
+ ortWasmPaths: E
368
388
  });
369
389
  if (i.status !== "success" || !i.corners || !i.quad) {
370
- L.current = !0, U("error"), J(i.message), R.current.onError?.(Error(i.message));
390
+ F.current = !0, V("error"), q(i.message), I.current.onError?.(Error(i.message));
371
391
  return;
372
392
  }
373
- F.current = {
393
+ N.current = {
374
394
  quad: i.quad,
375
395
  sourceWidth: i.sourceWidth,
376
396
  sourceHeight: i.sourceHeight
377
- }, i.quad && K(i.quad), U("captured");
397
+ }, i.quad && W(i.quad), V("captured");
378
398
  let a = {
379
399
  frame: t,
380
400
  detection: i,
@@ -386,75 +406,76 @@ function ue({ open: m, useCase: h = "document", autoCapture: g = "defaultOn", ca
386
406
  displaySourceWidth: i.sourceWidth,
387
407
  displaySourceHeight: i.sourceHeight
388
408
  };
389
- if (R.current.useCase === "drivers-license") {
390
- await z.current(a);
409
+ if (I.current.useCase === "drivers-license") {
410
+ await L.current(a);
391
411
  return;
392
412
  }
393
- await le(R.current.onCapture, a);
413
+ await fe(I.current.onCapture, a);
394
414
  } catch (e) {
395
415
  let t = e instanceof Error ? e : /* @__PURE__ */ Error("Could not take a photo.");
396
416
  if (t.message === "No photo was selected.") {
397
- if (Fe.current) {
398
- U("error");
417
+ if (ze.current) {
418
+ V("error");
399
419
  return;
400
420
  }
401
- R.current.onCancel();
421
+ I.current.onCancel();
402
422
  return;
403
423
  }
404
- L.current = !0, J(t.message), U("error"), R.current.onError?.(t);
424
+ F.current = !0, q(t.message), V("error"), I.current.onError?.(t);
405
425
  } finally {
406
- me.current = !1;
426
+ _e.current = !1;
407
427
  }
408
428
  }
409
429
  }, [
410
- Q,
411
- D,
412
- O
413
- ]), Ke = _(async (e) => {
414
- let t = await ge.current;
430
+ Z,
431
+ T,
432
+ E,
433
+ Q
434
+ ]), Xe = _(async (e) => {
435
+ let t = await ye.current;
415
436
  if (t) {
416
- Be(!0);
437
+ We(!0);
417
438
  try {
418
439
  let n = await t.submitStill(e.frame, e.detection);
419
440
  if (n.kind === "need-back") {
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) {
421
- U("ready");
441
+ if (He.current = "back", R.current = !1, Ve("back"), F.current = !1, q(""), U(void 0), W(void 0), G(void 0), P.current.clear(), X(), O) {
442
+ V("ready");
422
443
  return;
423
444
  }
424
- H?.paused && H.play(), U("starting"), Oe((e) => e + 1);
445
+ B?.paused && B.play(), V("starting"), Me((e) => e + 1);
425
446
  return;
426
447
  }
427
448
  if (n.kind === "retry") {
428
- L.current = !0, J(n.message), U("error");
449
+ F.current = !0, q(n.message), V("error");
429
450
  return;
430
451
  }
431
- await le(R.current.onDriverLicense, n.result);
452
+ await fe(I.current.onDriverLicense, n.result);
432
453
  } catch (e) {
433
454
  let t = e instanceof Error ? e : /* @__PURE__ */ Error("Driver’s license scan failed.");
434
- L.current = !0, J(t.message), U("error"), R.current.onError?.(t);
455
+ F.current = !0, q(t.message), V("error"), I.current.onError?.(t);
435
456
  } finally {
436
- Be(!1);
457
+ We(!1);
437
458
  }
438
459
  }
439
460
  }, [
440
- Z,
441
- H,
442
- A
461
+ X,
462
+ B,
463
+ O
443
464
  ]);
444
465
  ne(() => {
445
- z.current = Ke;
446
- }, [Ke]);
447
- let qe = _(async () => {
448
- if (A) {
466
+ L.current = Xe;
467
+ }, [Xe]);
468
+ let Ze = _(async () => {
469
+ if (O) {
449
470
  await $();
450
471
  return;
451
472
  }
452
- let e = j.current;
453
- if (e && R.current.useCase === "drivers-license" && Re.current === "back") {
473
+ let e = k.current;
474
+ if (e && I.current.useCase === "drivers-license" && He.current === "back") {
454
475
  try {
455
- let t = await e.capturePhoto();
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({
476
+ let t = await e.capturePhoto(), n = await f(t.frame);
477
+ if (!n?.text || R.current) return;
478
+ R.current = !0, z.current?.abort(), M.current = t, K(t.method), Y(t.diagnostics), J(t.diagnostics), Z(t.frame, B), V("captured"), await Q(t.frame, n.quad), await L.current({
458
479
  frame: t.frame,
459
480
  reason: "manual",
460
481
  method: t.method,
@@ -465,74 +486,75 @@ function ue({ open: m, useCase: h = "document", autoCapture: g = "defaultOn", ca
465
486
  });
466
487
  } catch (e) {
467
488
  let t = e instanceof Error ? e : /* @__PURE__ */ Error("Could not capture the camera frame.");
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);
489
+ F.current = !0, q(t.message);
490
+ let n = k.current?.getDiagnostics();
491
+ n && J(n), M.current?.diagnostics && Y(M.current.diagnostics), V("error"), I.current.onError?.(t);
471
492
  }
472
493
  return;
473
494
  }
474
495
  try {
475
- await M.current?.capture();
496
+ await A.current?.capture();
476
497
  } catch (e) {
477
498
  let t = e instanceof Error ? e : /* @__PURE__ */ Error("Could not capture the camera frame.");
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);
499
+ F.current = !0, q(t.message);
500
+ let n = k.current?.getDiagnostics();
501
+ n && J(n), M.current?.diagnostics && Y(M.current.diagnostics), V("error"), I.current.onError?.(t);
481
502
  }
482
503
  }, [
483
504
  $,
505
+ Z,
506
+ B,
484
507
  Q,
485
- H,
486
- A
487
- ]), Je = b($);
488
- Je.current = $;
489
- let Ye = b(!1);
508
+ O
509
+ ]), Qe = b($);
510
+ Qe.current = $;
511
+ let $e = b(!1);
490
512
  ne(() => {
491
- if (!m || !A) {
492
- Ye.current = !1;
513
+ if (!m || !O) {
514
+ $e.current = !1;
493
515
  return;
494
516
  }
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()) {
497
- U("ready");
517
+ if (!$e.current) {
518
+ if ($e.current = !0, F.current = !1, q(""), U(void 0), K(void 0), Y(void 0), Ie("idle"), W(void 0), G(void 0), P.current.clear(), X(), !te()) {
519
+ V("ready");
498
520
  return;
499
521
  }
500
- Je.current();
522
+ Qe.current();
501
523
  }
502
524
  }, [
503
525
  m,
504
- A,
505
- Z
526
+ O,
527
+ X
506
528
  ]);
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) {
529
+ let et = _(() => {
530
+ if (F.current = !1, R.current = !1, q(""), Y(void 0), Ie("idle"), U(void 0), W(void 0), G(void 0), P.current.clear(), O) {
509
531
  $();
510
532
  return;
511
533
  }
512
- if (Z(), h === "drivers-license") {
513
- U("starting"), Oe((e) => e + 1);
534
+ if (X(), h === "drivers-license") {
535
+ V("starting"), Me((e) => e + 1);
514
536
  return;
515
537
  }
516
- let e = j.current;
517
- H?.paused && H.play(), U(e ? "ready" : "starting"), e || Oe((e) => e + 1);
538
+ let e = k.current;
539
+ B?.paused && B.play(), V(e ? "ready" : "starting"), e || Me((e) => e + 1);
518
540
  }, [
519
541
  $,
520
- Z,
521
- H,
542
+ X,
543
+ B,
522
544
  h,
523
- A
524
- ]), Ze = _(async (e) => {
525
- let t = j.current;
526
- t && (await t.setTorch(e), Y(t.getDiagnostics()));
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({
545
+ O
546
+ ]), tt = _(async (e) => {
547
+ let t = k.current;
548
+ t && (await t.setTorch(e), J(t.getDiagnostics()));
549
+ }, []), nt = _((e) => {
550
+ A.current?.setAutoCapture(e);
551
+ }, []), rt = _(async () => {
552
+ let e = be.current, t = k.current?.getDiagnostics() ?? e.diagnostics, n = e.finderStatus, r = i({
531
553
  error: e.error || void 0,
532
554
  captureMethod: e.captureMethod,
533
- luminance: P.current?.luminance,
534
- fallbackReason: P.current?.fallbackReason,
535
- shutter: e.shutterDiagnostics ?? P.current?.diagnostics,
555
+ luminance: M.current?.luminance,
556
+ fallbackReason: M.current?.fallbackReason,
557
+ shutter: e.shutterDiagnostics ?? M.current?.diagnostics,
536
558
  live: t,
537
559
  finder: n ? {
538
560
  state: n.state,
@@ -557,55 +579,55 @@ function ue({ open: m, useCase: h = "document", autoCapture: g = "defaultOn", ca
557
579
  let t = document.execCommand("copy");
558
580
  if (e.remove(), !t) throw Error("Clipboard copy is unavailable.");
559
581
  }
560
- Me("copied");
582
+ Ie("copied");
561
583
  } catch {
562
- Me("failed");
584
+ Ie("failed");
563
585
  }
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
586
+ }, []), it = _(() => be.current, []), at = re(() => ({
587
+ capture: Ze,
588
+ cancel: Ye,
589
+ retry: et,
590
+ setTorch: tt,
591
+ setAutoCapture: nt,
592
+ copyReport: rt,
593
+ getState: it
572
594
  }), [
573
- qe,
574
- Ge,
575
- Xe,
576
595
  Ze,
577
- Qe,
578
- $e,
579
- et
596
+ Ye,
597
+ et,
598
+ tt,
599
+ nt,
600
+ rt,
601
+ it
580
602
  ]);
581
603
  y(() => {
582
- if (k) return k.current = tt, () => {
583
- k.current = null;
604
+ if (D) return D.current = at, () => {
605
+ D.current = null;
584
606
  };
585
- }, [tt, k]);
586
- let nt = {
587
- ...We,
588
- ...tt,
589
- bindPreview: Ue
607
+ }, [at, D]);
608
+ let ot = {
609
+ ...Je,
610
+ ...at,
611
+ bindPreview: qe
590
612
  };
591
- return /* @__PURE__ */ S(oe.Provider, {
592
- value: nt,
593
- children: pe
613
+ return /* @__PURE__ */ S(ce.Provider, {
614
+ value: ot,
615
+ children: ge
594
616
  });
595
617
  }
596
618
  //#endregion
597
619
  //#region src/react/hooks.ts
598
- function de() {
620
+ function me() {
599
621
  return b(null);
600
622
  }
601
- function D() {
602
- let e = v(oe);
623
+ function T() {
624
+ let e = v(ce);
603
625
  if (!e) throw Error("useScanner must be used within ScannerProvider.");
604
626
  return e;
605
627
  }
606
628
  //#endregion
607
629
  //#region src/live-overlay-geometry.ts
608
- function O(e, t, n, r, i) {
630
+ function E(e, t, n, r, i) {
609
631
  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;
610
632
  if (i === "contain") return {
611
633
  viewBox: `0 0 ${a} ${o}`,
@@ -625,7 +647,7 @@ function O(e, t, n, r, i) {
625
647
  }
626
648
  //#endregion
627
649
  //#region src/components/ModelDownloadRing.tsx
628
- function fe({ snapshot: e }) {
650
+ function he({ snapshot: e }) {
629
651
  if (!e.downloading) return null;
630
652
  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;
631
653
  return /* @__PURE__ */ C("div", {
@@ -661,12 +683,12 @@ function fe({ snapshot: e }) {
661
683
  }
662
684
  //#endregion
663
685
  //#region src/react/guidance.ts
664
- function k(e) {
686
+ function D(e) {
665
687
  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";
666
688
  }
667
689
  //#endregion
668
690
  //#region src/react/parts.tsx
669
- var pe = {
691
+ var ge = {
670
692
  primaryColorHex: "--scanner-overlay-primary",
671
693
  seekingColorHex: "--scanner-overlay-seeking",
672
694
  detectingColorHex: "--scanner-overlay-detecting",
@@ -674,19 +696,19 @@ var pe = {
674
696
  readyColorHex: "--scanner-overlay-ready",
675
697
  capturedColorHex: "--scanner-overlay-captured"
676
698
  };
677
- function A(e) {
699
+ function O(e) {
678
700
  if (!e) return;
679
701
  let t = {};
680
- for (let [n, r] of Object.entries(pe)) {
702
+ for (let [n, r] of Object.entries(ge)) {
681
703
  let i = e[n]?.trim();
682
704
  i && (t[r] = i);
683
705
  }
684
706
  return Object.keys(t).length > 0 ? t : void 0;
685
707
  }
686
- function j({ theme: e, style: t, title: n, children: r }) {
687
- let i = D();
708
+ function k({ theme: e, style: t, title: n, children: r }) {
709
+ let i = T();
688
710
  if (!i.open) return null;
689
- let a = n ?? (i.useCase === "drivers-license" ? "Scan a driver’s license" : "Scan a document"), o = A(e), s = o ? {
711
+ let a = n ?? (i.useCase === "drivers-license" ? "Scan a driver’s license" : "Scan a document"), o = O(e), s = o ? {
690
712
  ...t,
691
713
  ...o
692
714
  } : t;
@@ -696,11 +718,11 @@ function j({ theme: e, style: t, title: n, children: r }) {
696
718
  role: "dialog",
697
719
  "aria-modal": "true",
698
720
  "aria-label": a,
699
- children: [r, /* @__PURE__ */ S(R, {})]
721
+ children: [r, /* @__PURE__ */ S(I, {})]
700
722
  });
701
723
  }
702
- function M() {
703
- let { bindPreview: e, frozenPreviewUrl: t, usingSystemCamera: n } = D(), r = b(null), i = _((t) => {
724
+ function A() {
725
+ let { bindPreview: e, frozenPreviewUrl: t, usingSystemCamera: n } = T(), r = b(null), i = _((t) => {
704
726
  r.current = t, e(t);
705
727
  }, [e]);
706
728
  return y(() => {
@@ -729,20 +751,20 @@ function M() {
729
751
  "aria-label": "Captured document"
730
752
  }) : null] });
731
753
  }
732
- function N() {
733
- let { finderStatus: e, displayQuad: t, previewSize: n } = D();
734
- if (!t || !e?.sourceWidth || !e.sourceHeight) return null;
735
- let r = O(e.sourceWidth, e.sourceHeight, n.width, n.height, "cover");
754
+ function j() {
755
+ let { finderStatus: e, displayQuad: t, previewSize: n, barcodeOverlay: r } = T(), i = e?.sourceWidth ?? r?.width, a = e?.sourceHeight ?? r?.height;
756
+ if (!t || !i || !a) return null;
757
+ let o = E(i, a, n.width, n.height, "cover"), s = r ? "ready" : e?.state;
736
758
  return /* @__PURE__ */ S("svg", {
737
- className: `scanner-camera-overlay__quad ${e.state}`,
738
- viewBox: r.viewBox,
739
- preserveAspectRatio: r.preserveAspectRatio,
740
- "aria-label": `${e.state} document boundary`,
759
+ className: `scanner-camera-overlay__quad ${s ?? ""}`.trim(),
760
+ viewBox: o.viewBox,
761
+ preserveAspectRatio: o.preserveAspectRatio,
762
+ "aria-label": r ? "PDF417 barcode boundary" : `${e?.state ?? "document"} document boundary`,
741
763
  children: /* @__PURE__ */ S("polygon", { points: `${t.topLeft.x},${t.topLeft.y} ${t.topRight.x},${t.topRight.y} ${t.bottomRight.x},${t.bottomRight.y} ${t.bottomLeft.x},${t.bottomLeft.y}` })
742
764
  });
743
765
  }
744
- function P({ title: e }) {
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";
766
+ function M({ title: e }) {
767
+ let { phase: t, cancel: n, usingSystemCamera: r, useCase: i, licenseSide: a, licenseBusy: o } = T(), s = i === "drivers-license" ? m(a ?? "front", r) : void 0, c = e ?? s?.title ?? "Scan a document";
746
768
  return /* @__PURE__ */ C("div", {
747
769
  className: "scanner-camera-overlay__topbar",
748
770
  children: [/* @__PURE__ */ C("div", { children: [/* @__PURE__ */ S("strong", { children: c }), /* @__PURE__ */ C("span", {
@@ -767,8 +789,8 @@ function P({ title: e }) {
767
789
  })]
768
790
  });
769
791
  }
770
- function F() {
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;
792
+ function N() {
793
+ 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 } = T(), f = l === "drivers-license" ? m(u ?? "front", s) : void 0;
772
794
  return e === "error" ? /* @__PURE__ */ C("div", {
773
795
  className: "scanner-camera-overlay__message",
774
796
  role: "alert",
@@ -823,8 +845,8 @@ function F() {
823
845
  ]
824
846
  }) : null;
825
847
  }
826
- function I() {
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"}` : "";
848
+ function P() {
849
+ let { finderStatus: e, detectorStatus: t, settings: n, usingSystemCamera: r, captureMethod: i, phase: a, useCase: o, licenseSide: s } = T(), c = n?.width, l = n?.height, u = o === "drivers-license" ? ` · ${s === "back" ? "back" : "front"}` : "";
828
850
  if (r) return /* @__PURE__ */ S("div", {
829
851
  className: "scanner-camera-overlay__status",
830
852
  "aria-live": "polite",
@@ -856,8 +878,8 @@ function I() {
856
878
  })
857
879
  });
858
880
  }
859
- function L() {
860
- let { diagnostics: e, shutterDiagnostics: t, captureMethod: n, copyState: i, copyReport: a } = D(), o = e?.engine ?? r();
881
+ function F() {
882
+ let { diagnostics: e, shutterDiagnostics: t, captureMethod: n, copyState: i, copyReport: a } = T(), o = e?.engine ?? r();
861
883
  return /* @__PURE__ */ C("dl", {
862
884
  className: "scanner-camera-overlay__diagnostics",
863
885
  "aria-label": "Camera diagnostics",
@@ -883,8 +905,8 @@ function L() {
883
905
  ]
884
906
  });
885
907
  }
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({
908
+ function _e() {
909
+ 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 } = T(), h = a?.width, te = a?.height, g = u ? t === "ready" : e !== "only", _ = f === "drivers-license" ? m(p ?? "front", u) : void 0, v = D({
888
910
  usingSystemCamera: u,
889
911
  phase: t,
890
912
  licenseBusy: d,
@@ -943,11 +965,11 @@ function me() {
943
965
  ]
944
966
  });
945
967
  }
946
- function R({ snapshot: e }) {
947
- let { modelDownload: t } = D();
948
- return /* @__PURE__ */ S(fe, { snapshot: e ?? t });
968
+ function I({ snapshot: e }) {
969
+ let { modelDownload: t } = T();
970
+ return /* @__PURE__ */ S(he, { snapshot: e ?? t });
949
971
  }
950
972
  //#endregion
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 };
973
+ export { _e as ScannerControls, F as ScannerDiagnostics, k as ScannerFrame, I as ScannerModelDownload, N as ScannerNotice, A as ScannerPreview, pe as ScannerProvider, j as ScannerQuad, P as ScannerStatus, M as ScannerTopBar, T as useScanner, me as useScannerRef };
952
974
 
953
975
  //# sourceMappingURL=react.js.map