@exige/web-scanner-sdk 0.2.29 → 0.2.30
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 { B as e, I as t, M as n, N as r, R as i, T as a, U as o, V as s, i as c, j as l, n as u, v as d, y as f } from "./driver-license-
|
|
2
|
+
import { B as e, I as t, M as n, N as r, R as i, T as a, U as o, V as s, i as c, j as l, n as u, v as d, y as f } from "./driver-license-DpjQqOKx.js";
|
|
3
3
|
import { createContext as p, useCallback as m, useContext as h, useEffect as g, useLayoutEffect as ee, useMemo as te, useRef as _, useState as v } from "react";
|
|
4
4
|
import { Fragment as y, jsx as b, jsxs as x } from "react/jsx-runtime";
|
|
5
5
|
//#region src/sdk/display-quad.ts
|
|
@@ -90,7 +90,10 @@ function ae(e) {
|
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function oe(e, t) {
|
|
94
|
+
if (typeof e == "function") return e(t);
|
|
95
|
+
}
|
|
96
|
+
function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", captureMode: h = "auto", torch: y = "defaultOff", onCapture: x, onDriverLicense: S, onCancel: C, onError: w, onSettings: T, onFinderStatus: E, modelUrl: D, ortWasmPaths: O, detectionIntervalMs: se, apiRef: k, children: ce }) {
|
|
94
97
|
let A = e(h), j = _(void 0), M = _(void 0), N = _(void 0), P = _(void 0), F = _({}), I = _(new ne()), L = _(!1), R = _(!1), z = _({
|
|
95
98
|
onCapture: x,
|
|
96
99
|
onDriverLicense: S,
|
|
@@ -99,20 +102,20 @@ function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", cap
|
|
|
99
102
|
onSettings: T,
|
|
100
103
|
onFinderStatus: E,
|
|
101
104
|
useCase: u
|
|
102
|
-
}),
|
|
105
|
+
}), le = _(void 0), B = _(void 0), ue = _(async () => void 0), de = _(null), [V, fe] = v(null), [pe, H] = v(A && l ? "capturing" : A ? "ready" : "starting"), [U, me] = v(), [he, W] = v(), [ge, _e] = v({
|
|
103
106
|
width: 1,
|
|
104
107
|
height: 1
|
|
105
|
-
}), [
|
|
108
|
+
}), [ve, ye] = v(), [be, G] = v(), [xe, K] = v(""), [Se, Ce] = v(0), [we, q] = v(), [Te, J] = v(), [Ee, Y] = v("idle"), [De, Oe] = v(), X = _(void 0), [ke, Ae] = v("front"), je = _("front"), [Me, Ne] = v(!1), [Pe, Fe] = v({
|
|
106
109
|
downloading: !1,
|
|
107
110
|
loaded: 0,
|
|
108
111
|
total: null
|
|
109
112
|
}), Z = m(() => {
|
|
110
|
-
ie(X.current), X.current = void 0,
|
|
113
|
+
ie(X.current), X.current = void 0, Oe(void 0);
|
|
111
114
|
}, []), Q = m((e, t) => {
|
|
112
115
|
let n = ae(e);
|
|
113
|
-
ie(X.current), X.current = n,
|
|
116
|
+
ie(X.current), X.current = n, Oe(n), t?.pause();
|
|
114
117
|
}, []);
|
|
115
|
-
|
|
118
|
+
ee(() => {
|
|
116
119
|
z.current = {
|
|
117
120
|
onCapture: x,
|
|
118
121
|
onDriverLicense: S,
|
|
@@ -130,9 +133,9 @@ function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", cap
|
|
|
130
133
|
T,
|
|
131
134
|
E,
|
|
132
135
|
u
|
|
133
|
-
]), g(() => o(
|
|
136
|
+
]), g(() => o(Fe), []), g(() => {
|
|
134
137
|
if (!l || u !== "drivers-license") {
|
|
135
|
-
B.current = void 0,
|
|
138
|
+
B.current = void 0, le.current = void 0, Ae("front"), Ne(!1);
|
|
136
139
|
return;
|
|
137
140
|
}
|
|
138
141
|
let e = c({ scan: {
|
|
@@ -140,9 +143,9 @@ function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", cap
|
|
|
140
143
|
ortWasmPaths: O
|
|
141
144
|
} });
|
|
142
145
|
return B.current = e, e.then((e) => {
|
|
143
|
-
|
|
146
|
+
le.current = e;
|
|
144
147
|
}), () => {
|
|
145
|
-
e.then((e) => e.cancel()),
|
|
148
|
+
e.then((e) => e.cancel()), le.current &&= void 0, B.current = void 0;
|
|
146
149
|
};
|
|
147
150
|
}, [
|
|
148
151
|
l,
|
|
@@ -150,14 +153,14 @@ function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", cap
|
|
|
150
153
|
D,
|
|
151
154
|
O
|
|
152
155
|
]);
|
|
153
|
-
let
|
|
154
|
-
|
|
156
|
+
let Ie = m((e) => {
|
|
157
|
+
fe(e);
|
|
155
158
|
}, []);
|
|
156
159
|
g(() => {
|
|
157
160
|
if (!l || !V) return;
|
|
158
161
|
let e = () => {
|
|
159
162
|
let e = V.getBoundingClientRect();
|
|
160
|
-
|
|
163
|
+
_e({
|
|
161
164
|
width: e.width,
|
|
162
165
|
height: e.height
|
|
163
166
|
});
|
|
@@ -172,7 +175,7 @@ function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", cap
|
|
|
172
175
|
e && q(e);
|
|
173
176
|
}, 500);
|
|
174
177
|
return () => window.clearInterval(e);
|
|
175
|
-
}, [l,
|
|
178
|
+
}, [l, Se]), g(() => {
|
|
176
179
|
if (!l) return;
|
|
177
180
|
let e = 0, t = performance.now(), n = (r) => {
|
|
178
181
|
let i = I.current.step(r - t);
|
|
@@ -185,7 +188,7 @@ function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", cap
|
|
|
185
188
|
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();
|
|
186
189
|
};
|
|
187
190
|
return (async () => {
|
|
188
|
-
t(), L.current = !1, H("starting"), K(""),
|
|
191
|
+
t(), L.current = !1, H("starting"), K(""), me(void 0), G(void 0), J(void 0), Y("idle"), Z();
|
|
189
192
|
try {
|
|
190
193
|
let t = await s(V, { torch: y });
|
|
191
194
|
if (e) {
|
|
@@ -194,16 +197,16 @@ function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", cap
|
|
|
194
197
|
}
|
|
195
198
|
j.current = t;
|
|
196
199
|
let n = t.getSettings();
|
|
197
|
-
|
|
200
|
+
ye(n), z.current.onSettings?.(n), console.info("[ScannerProvider] camera settings", n), M.current = await f({
|
|
198
201
|
source: V,
|
|
199
202
|
autoCapture: p,
|
|
200
|
-
intervalMs:
|
|
203
|
+
intervalMs: se,
|
|
201
204
|
detection: {
|
|
202
205
|
modelUrl: D,
|
|
203
206
|
ortWasmPaths: O
|
|
204
207
|
},
|
|
205
208
|
onStatus: (e) => {
|
|
206
|
-
if (N.current = e,
|
|
209
|
+
if (N.current = e, me(e), z.current.onFinderStatus?.(e), e.quad && e.sourceWidth && e.sourceHeight) {
|
|
207
210
|
let t = I.current.setTarget(e.quad, e.sourceWidth, e.sourceHeight);
|
|
208
211
|
W(t.quad);
|
|
209
212
|
} else I.current.clear(), W(void 0);
|
|
@@ -239,10 +242,10 @@ function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", cap
|
|
|
239
242
|
displaySourceHeight: F.current.sourceHeight
|
|
240
243
|
};
|
|
241
244
|
if (z.current.useCase === "drivers-license") {
|
|
242
|
-
await
|
|
245
|
+
await ue.current(r);
|
|
243
246
|
return;
|
|
244
247
|
}
|
|
245
|
-
await z.current.onCapture
|
|
248
|
+
await oe(z.current.onCapture, r);
|
|
246
249
|
}
|
|
247
250
|
});
|
|
248
251
|
} catch (n) {
|
|
@@ -262,38 +265,38 @@ function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", cap
|
|
|
262
265
|
y,
|
|
263
266
|
D,
|
|
264
267
|
O,
|
|
265
|
-
|
|
266
|
-
|
|
268
|
+
se,
|
|
269
|
+
Se,
|
|
267
270
|
Z,
|
|
268
271
|
Q
|
|
269
272
|
]);
|
|
270
|
-
let
|
|
273
|
+
let Le = {
|
|
271
274
|
open: l,
|
|
272
|
-
phase:
|
|
275
|
+
phase: pe,
|
|
273
276
|
autoCapture: p,
|
|
274
277
|
captureMode: h,
|
|
275
278
|
usingSystemCamera: A,
|
|
276
279
|
finderStatus: U,
|
|
277
|
-
displayQuad:
|
|
278
|
-
previewSize:
|
|
279
|
-
settings:
|
|
280
|
-
captureMethod:
|
|
281
|
-
error:
|
|
282
|
-
diagnostics:
|
|
283
|
-
shutterDiagnostics:
|
|
284
|
-
copyState:
|
|
280
|
+
displayQuad: he,
|
|
281
|
+
previewSize: ge,
|
|
282
|
+
settings: ve,
|
|
283
|
+
captureMethod: be,
|
|
284
|
+
error: xe,
|
|
285
|
+
diagnostics: we,
|
|
286
|
+
shutterDiagnostics: Te,
|
|
287
|
+
copyState: Ee,
|
|
285
288
|
guidanceHint: U ? d(U.guidance, U.lighting) : void 0,
|
|
286
289
|
detectorStatus: U?.modelStatus === "failed" ? `ML failed${U.modelError ? `: ${U.modelError}` : ""}` : U?.detector === "ml" ? `ML ${U.modelProvider ?? ""}`.trim() : "ML loading",
|
|
287
|
-
modelDownload:
|
|
288
|
-
frozenPreviewUrl:
|
|
290
|
+
modelDownload: Pe,
|
|
291
|
+
frozenPreviewUrl: De,
|
|
289
292
|
useCase: u,
|
|
290
|
-
licenseSide: u === "drivers-license" ?
|
|
291
|
-
licenseBusy: u === "drivers-license" ?
|
|
293
|
+
licenseSide: u === "drivers-license" ? ke : void 0,
|
|
294
|
+
licenseBusy: u === "drivers-license" ? Me : void 0
|
|
292
295
|
};
|
|
293
296
|
g(() => {
|
|
294
|
-
|
|
297
|
+
de.current = Le;
|
|
295
298
|
});
|
|
296
|
-
let
|
|
299
|
+
let Re = m(() => {
|
|
297
300
|
z.current.onCancel();
|
|
298
301
|
}, []), $ = m(async () => {
|
|
299
302
|
if (!R.current) {
|
|
@@ -305,7 +308,7 @@ function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", cap
|
|
|
305
308
|
width: e.width,
|
|
306
309
|
height: e.height
|
|
307
310
|
};
|
|
308
|
-
|
|
311
|
+
ye(n), z.current.onSettings?.(n), G("system-camera");
|
|
309
312
|
let r;
|
|
310
313
|
try {
|
|
311
314
|
let n = e.getContext("2d", { willReadFrequently: !0 })?.getImageData(0, 0, e.width, e.height).data;
|
|
@@ -317,7 +320,7 @@ function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", cap
|
|
|
317
320
|
modelUrl: D,
|
|
318
321
|
ortWasmPaths: O
|
|
319
322
|
});
|
|
320
|
-
if ((z.current.useCase !== "drivers-license" ||
|
|
323
|
+
if ((z.current.useCase !== "drivers-license" || je.current !== "back") && (o.status !== "success" || !o.corners || !o.quad)) {
|
|
321
324
|
L.current = !0, H("error"), K(o.message), z.current.onError?.(Error(o.message));
|
|
322
325
|
return;
|
|
323
326
|
}
|
|
@@ -338,10 +341,10 @@ function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", cap
|
|
|
338
341
|
displaySourceHeight: o.sourceHeight
|
|
339
342
|
};
|
|
340
343
|
if (z.current.useCase === "drivers-license") {
|
|
341
|
-
await
|
|
344
|
+
await ue.current(s);
|
|
342
345
|
return;
|
|
343
346
|
}
|
|
344
|
-
await z.current.onCapture
|
|
347
|
+
await oe(z.current.onCapture, s);
|
|
345
348
|
} catch (e) {
|
|
346
349
|
let t = e instanceof Error ? e : /* @__PURE__ */ Error("Could not take a photo.");
|
|
347
350
|
if (t.message === "No photo was selected.") {
|
|
@@ -361,30 +364,30 @@ function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", cap
|
|
|
361
364
|
Q,
|
|
362
365
|
D,
|
|
363
366
|
O
|
|
364
|
-
]),
|
|
367
|
+
]), ze = m(async (e) => {
|
|
365
368
|
let t = await B.current;
|
|
366
369
|
if (t) {
|
|
367
|
-
|
|
370
|
+
Ne(!0);
|
|
368
371
|
try {
|
|
369
372
|
let n = await t.submitStill(e.frame, e.detection);
|
|
370
373
|
if (n.kind === "need-back") {
|
|
371
|
-
if (
|
|
374
|
+
if (je.current = "back", Ae("back"), L.current = !1, K(""), W(void 0), I.current.clear(), Z(), A) {
|
|
372
375
|
H("ready");
|
|
373
376
|
return;
|
|
374
377
|
}
|
|
375
|
-
V?.paused && V.play(), H("starting"),
|
|
378
|
+
V?.paused && V.play(), H("starting"), Ce((e) => e + 1);
|
|
376
379
|
return;
|
|
377
380
|
}
|
|
378
381
|
if (n.kind === "retry") {
|
|
379
382
|
L.current = !0, K(n.message), H("error");
|
|
380
383
|
return;
|
|
381
384
|
}
|
|
382
|
-
await z.current.onDriverLicense
|
|
385
|
+
await oe(z.current.onDriverLicense, n.result);
|
|
383
386
|
} catch (e) {
|
|
384
387
|
let t = e instanceof Error ? e : /* @__PURE__ */ Error("Driver’s license scan failed.");
|
|
385
388
|
L.current = !0, K(t.message), H("error"), z.current.onError?.(t);
|
|
386
389
|
} finally {
|
|
387
|
-
|
|
390
|
+
Ne(!1);
|
|
388
391
|
}
|
|
389
392
|
}
|
|
390
393
|
}, [
|
|
@@ -393,9 +396,9 @@ function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", cap
|
|
|
393
396
|
A
|
|
394
397
|
]);
|
|
395
398
|
ee(() => {
|
|
396
|
-
|
|
397
|
-
}, [
|
|
398
|
-
let
|
|
399
|
+
ue.current = ze;
|
|
400
|
+
}, [ze]);
|
|
401
|
+
let Be = m(async () => {
|
|
399
402
|
if (A) {
|
|
400
403
|
await $();
|
|
401
404
|
return;
|
|
@@ -408,50 +411,50 @@ function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", cap
|
|
|
408
411
|
let n = j.current?.getDiagnostics();
|
|
409
412
|
n && q(n), P.current?.diagnostics && J(P.current.diagnostics), H("error"), z.current.onError?.(t);
|
|
410
413
|
}
|
|
411
|
-
}, [$, A]),
|
|
412
|
-
|
|
413
|
-
let
|
|
414
|
+
}, [$, A]), Ve = _($);
|
|
415
|
+
Ve.current = $;
|
|
416
|
+
let He = _(!1);
|
|
414
417
|
ee(() => {
|
|
415
418
|
if (!l || !A) {
|
|
416
|
-
|
|
419
|
+
He.current = !1;
|
|
417
420
|
return;
|
|
418
421
|
}
|
|
419
|
-
if (!
|
|
420
|
-
if (
|
|
422
|
+
if (!He.current) {
|
|
423
|
+
if (He.current = !0, L.current = !1, K(""), me(void 0), G(void 0), J(void 0), Y("idle"), W(void 0), I.current.clear(), Z(), !r()) {
|
|
421
424
|
H("ready");
|
|
422
425
|
return;
|
|
423
426
|
}
|
|
424
|
-
|
|
427
|
+
Ve.current();
|
|
425
428
|
}
|
|
426
429
|
}, [
|
|
427
430
|
l,
|
|
428
431
|
A,
|
|
429
432
|
Z
|
|
430
433
|
]);
|
|
431
|
-
let
|
|
434
|
+
let Ue = m(() => {
|
|
432
435
|
if (L.current = !1, K(""), J(void 0), Y("idle"), W(void 0), I.current.clear(), A) {
|
|
433
436
|
$();
|
|
434
437
|
return;
|
|
435
438
|
}
|
|
436
439
|
if (Z(), u === "drivers-license") {
|
|
437
|
-
H("starting"),
|
|
440
|
+
H("starting"), Ce((e) => e + 1);
|
|
438
441
|
return;
|
|
439
442
|
}
|
|
440
443
|
let e = j.current;
|
|
441
|
-
V?.paused && V.play(), H(e ? "ready" : "starting"), e ||
|
|
444
|
+
V?.paused && V.play(), H(e ? "ready" : "starting"), e || Ce((e) => e + 1);
|
|
442
445
|
}, [
|
|
443
446
|
$,
|
|
444
447
|
Z,
|
|
445
448
|
V,
|
|
446
449
|
u,
|
|
447
450
|
A
|
|
448
|
-
]),
|
|
451
|
+
]), We = m(async (e) => {
|
|
449
452
|
let t = j.current;
|
|
450
453
|
t && (await t.setTorch(e), q(t.getDiagnostics()));
|
|
451
|
-
}, []),
|
|
454
|
+
}, []), Ge = m((e) => {
|
|
452
455
|
M.current?.setAutoCapture(e);
|
|
453
|
-
}, []),
|
|
454
|
-
let e =
|
|
456
|
+
}, []), Ke = m(async () => {
|
|
457
|
+
let e = de.current, t = j.current?.getDiagnostics() ?? e.diagnostics, r = e.finderStatus, i = n({
|
|
455
458
|
error: e.error || void 0,
|
|
456
459
|
captureMethod: e.captureMethod,
|
|
457
460
|
luminance: P.current?.luminance,
|
|
@@ -485,36 +488,36 @@ function T({ open: l, useCase: u = "document", autoCapture: p = "defaultOn", cap
|
|
|
485
488
|
} catch {
|
|
486
489
|
Y("failed");
|
|
487
490
|
}
|
|
488
|
-
}, []),
|
|
489
|
-
capture:
|
|
490
|
-
cancel:
|
|
491
|
-
retry:
|
|
492
|
-
setTorch:
|
|
493
|
-
setAutoCapture:
|
|
494
|
-
copyReport:
|
|
495
|
-
getState:
|
|
491
|
+
}, []), qe = m(() => de.current, []), Je = te(() => ({
|
|
492
|
+
capture: Be,
|
|
493
|
+
cancel: Re,
|
|
494
|
+
retry: Ue,
|
|
495
|
+
setTorch: We,
|
|
496
|
+
setAutoCapture: Ge,
|
|
497
|
+
copyReport: Ke,
|
|
498
|
+
getState: qe
|
|
496
499
|
}), [
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
He,
|
|
500
|
+
Be,
|
|
501
|
+
Re,
|
|
500
502
|
Ue,
|
|
501
503
|
We,
|
|
502
504
|
Ge,
|
|
503
|
-
Ke
|
|
505
|
+
Ke,
|
|
506
|
+
qe
|
|
504
507
|
]);
|
|
505
508
|
g(() => {
|
|
506
|
-
if (k) return k.current =
|
|
509
|
+
if (k) return k.current = Je, () => {
|
|
507
510
|
k.current = null;
|
|
508
511
|
};
|
|
509
|
-
}, [
|
|
510
|
-
let
|
|
511
|
-
...
|
|
512
|
-
...
|
|
513
|
-
bindPreview:
|
|
512
|
+
}, [Je, k]);
|
|
513
|
+
let Ye = {
|
|
514
|
+
...Le,
|
|
515
|
+
...Je,
|
|
516
|
+
bindPreview: Ie
|
|
514
517
|
};
|
|
515
518
|
return /* @__PURE__ */ b(re.Provider, {
|
|
516
|
-
value:
|
|
517
|
-
children:
|
|
519
|
+
value: Ye,
|
|
520
|
+
children: ce
|
|
518
521
|
});
|
|
519
522
|
}
|
|
520
523
|
//#endregion
|
|
@@ -549,7 +552,7 @@ function O(e, t, n, r, i) {
|
|
|
549
552
|
}
|
|
550
553
|
//#endregion
|
|
551
554
|
//#region src/components/ModelDownloadRing.tsx
|
|
552
|
-
function
|
|
555
|
+
function se({ snapshot: e }) {
|
|
553
556
|
if (!e.downloading) return null;
|
|
554
557
|
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;
|
|
555
558
|
return /* @__PURE__ */ x("div", {
|
|
@@ -593,7 +596,7 @@ var k = {
|
|
|
593
596
|
readyColorHex: "--scanner-overlay-ready",
|
|
594
597
|
capturedColorHex: "--scanner-overlay-captured"
|
|
595
598
|
};
|
|
596
|
-
function
|
|
599
|
+
function ce(e) {
|
|
597
600
|
if (!e) return;
|
|
598
601
|
let t = {};
|
|
599
602
|
for (let [n, r] of Object.entries(k)) {
|
|
@@ -605,7 +608,7 @@ function se(e) {
|
|
|
605
608
|
function A({ theme: e, style: t, title: n, children: r }) {
|
|
606
609
|
let i = D();
|
|
607
610
|
if (!i.open) return null;
|
|
608
|
-
let a = n ?? (i.useCase === "drivers-license" ? "Scan a driver’s license" : "Scan a document"), o =
|
|
611
|
+
let a = n ?? (i.useCase === "drivers-license" ? "Scan a driver’s license" : "Scan a document"), o = ce(e), s = o ? {
|
|
609
612
|
...t,
|
|
610
613
|
...o
|
|
611
614
|
} : t;
|
|
@@ -852,7 +855,7 @@ function L() {
|
|
|
852
855
|
}
|
|
853
856
|
function R({ snapshot: e }) {
|
|
854
857
|
let { modelDownload: t } = D();
|
|
855
|
-
return /* @__PURE__ */ b(
|
|
858
|
+
return /* @__PURE__ */ b(se, { snapshot: e ?? t });
|
|
856
859
|
}
|
|
857
860
|
//#endregion
|
|
858
861
|
export { L as ScannerControls, I as ScannerDiagnostics, A as ScannerFrame, R as ScannerModelDownload, P as ScannerNotice, j as ScannerPreview, T as ScannerProvider, M as ScannerQuad, F as ScannerStatus, N as ScannerTopBar, D as useScanner, E as useScannerRef };
|