@exige/web-scanner-sdk 0.2.11 → 0.2.13
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/README.md +1 -1
- package/dist/assets/document-worker.js +1 -1
- package/dist/assets/document-worker.js.map +1 -1
- package/dist/{finder-BeINpYm3.js → finder-CLEe-Zhj.js} +184 -153
- package/dist/finder-CLEe-Zhj.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/react/parts.d.ts +1 -1
- package/dist/react/types.d.ts +6 -0
- package/dist/react.js +250 -244
- package/dist/react.js.map +1 -1
- package/dist/scanner-sdk.js +286 -286
- package/dist/scanner-sdk.js.map +1 -1
- package/dist/sdk/camera.d.ts +16 -1
- package/dist/sdk/finder.d.ts +6 -0
- package/dist/sdk/model-download.d.ts +1 -1
- package/package.json +1 -1
- package/dist/finder-BeINpYm3.js.map +0 -1
package/dist/react.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import { createContext as
|
|
4
|
-
import { Fragment as
|
|
2
|
+
import { k as e, m as t, o as n, p as r, s as i, v as a } from "./finder-CLEe-Zhj.js";
|
|
3
|
+
import { createContext as o, useCallback as s, useContext as c, useEffect as l, useMemo as u, useRef as d, useState as f } from "react";
|
|
4
|
+
import { Fragment as p, jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
5
5
|
//#region src/sdk/display-quad.ts
|
|
6
|
-
function
|
|
6
|
+
function g(e) {
|
|
7
7
|
return [
|
|
8
8
|
e.topLeft,
|
|
9
9
|
e.topRight,
|
|
@@ -11,7 +11,7 @@ function h(e) {
|
|
|
11
11
|
e.bottomLeft
|
|
12
12
|
];
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function _(e) {
|
|
15
15
|
let [t, n, r, i] = e;
|
|
16
16
|
return {
|
|
17
17
|
topLeft: t,
|
|
@@ -38,8 +38,8 @@ function g(e) {
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
return g(
|
|
41
|
+
function v(e) {
|
|
42
|
+
return _(g(e).map((e) => ({ ...e })));
|
|
43
43
|
}
|
|
44
44
|
var ee = class {
|
|
45
45
|
current;
|
|
@@ -50,11 +50,11 @@ var ee = class {
|
|
|
50
50
|
this.response = e.response ?? 14, this.snapDistance = e.snapDistance ?? .1;
|
|
51
51
|
}
|
|
52
52
|
setTarget(e, t, n) {
|
|
53
|
-
let r = Math.max(1, Math.hypot(t, n)), i = !this.current ||
|
|
54
|
-
let n =
|
|
53
|
+
let r = Math.max(1, Math.hypot(t, n)), i = !this.current || g(e).some((e, t) => {
|
|
54
|
+
let n = g(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 =
|
|
57
|
+
return this.target = v(e), i && (this.current = v(e)), {
|
|
58
58
|
quad: this.current,
|
|
59
59
|
snapped: i
|
|
60
60
|
};
|
|
@@ -62,8 +62,8 @@ var ee = 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 = g(
|
|
66
|
-
let r =
|
|
65
|
+
return this.current = _(g(this.current).map((e, n) => {
|
|
66
|
+
let r = g(this.target)[n];
|
|
67
67
|
return {
|
|
68
68
|
x: e.x + (r.x - e.x) * t,
|
|
69
69
|
y: e.y + (r.y - e.y) * t
|
|
@@ -76,13 +76,13 @@ var ee = class {
|
|
|
76
76
|
getCurrent() {
|
|
77
77
|
return this.current;
|
|
78
78
|
}
|
|
79
|
-
},
|
|
79
|
+
}, y = o(null);
|
|
80
80
|
//#endregion
|
|
81
81
|
//#region src/react/context.tsx
|
|
82
|
-
function
|
|
82
|
+
function b(e) {
|
|
83
83
|
e?.startsWith("blob:") && URL.revokeObjectURL(e);
|
|
84
84
|
}
|
|
85
|
-
function
|
|
85
|
+
function te(e) {
|
|
86
86
|
try {
|
|
87
87
|
let t = e.toDataURL("image/jpeg", .92);
|
|
88
88
|
return t.startsWith("data:image/") ? t : void 0;
|
|
@@ -90,123 +90,127 @@ function ne(e) {
|
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
let
|
|
95
|
-
onCapture:
|
|
96
|
-
onCancel:
|
|
97
|
-
onError:
|
|
98
|
-
onSettings:
|
|
99
|
-
onFinderStatus:
|
|
100
|
-
}),
|
|
93
|
+
function x({ open: r, autoCapture: o = "defaultOn", torch: c = "defaultOff", onCapture: p, onCancel: h, onError: g, onSettings: _, onFinderStatus: v, modelUrl: x, ortWasmPaths: S, detectionIntervalMs: C, apiRef: w, children: T }) {
|
|
94
|
+
let E = d(void 0), D = d(void 0), O = d(void 0), k = d(void 0), A = d({}), j = d(new ee()), M = d(!1), N = d({
|
|
95
|
+
onCapture: p,
|
|
96
|
+
onCancel: h,
|
|
97
|
+
onError: g,
|
|
98
|
+
onSettings: _,
|
|
99
|
+
onFinderStatus: v
|
|
100
|
+
}), P = d(null), [F, I] = f(null), [ne, L] = f("starting"), [R, z] = f(), [re, B] = f(), [ie, ae] = f({
|
|
101
101
|
width: 1,
|
|
102
102
|
height: 1
|
|
103
|
-
}), [
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
}), [oe, se] = f(), [ce, V] = f(), [le, H] = f(""), [U, ue] = f(0), [de, W] = f(), [fe, G] = f(), [pe, K] = f("idle"), [me, q] = f(), J = d(void 0), [he, ge] = f({
|
|
104
|
+
downloading: !1,
|
|
105
|
+
loaded: 0,
|
|
106
|
+
total: null
|
|
107
|
+
}), Y = s(() => {
|
|
108
|
+
b(J.current), J.current = void 0, q(void 0);
|
|
109
|
+
}, []), X = s((e, t) => {
|
|
110
|
+
let n = te(e);
|
|
111
|
+
b(J.current), J.current = n, q(n), t?.pause();
|
|
108
112
|
}, []);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
onCapture:
|
|
112
|
-
onCancel:
|
|
113
|
-
onError:
|
|
114
|
-
onSettings:
|
|
115
|
-
onFinderStatus:
|
|
113
|
+
l(() => {
|
|
114
|
+
N.current = {
|
|
115
|
+
onCapture: p,
|
|
116
|
+
onCancel: h,
|
|
117
|
+
onError: g,
|
|
118
|
+
onSettings: _,
|
|
119
|
+
onFinderStatus: v
|
|
116
120
|
};
|
|
117
121
|
}, [
|
|
118
|
-
|
|
119
|
-
m,
|
|
122
|
+
p,
|
|
120
123
|
h,
|
|
121
124
|
g,
|
|
122
|
-
_
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
_,
|
|
126
|
+
v
|
|
127
|
+
]), l(() => e(ge), []);
|
|
128
|
+
let _e = s((e) => {
|
|
129
|
+
I(e);
|
|
126
130
|
}, []);
|
|
127
|
-
|
|
128
|
-
if (!
|
|
131
|
+
l(() => {
|
|
132
|
+
if (!r || !F) return;
|
|
129
133
|
let e = () => {
|
|
130
|
-
let e =
|
|
131
|
-
|
|
134
|
+
let e = F.getBoundingClientRect();
|
|
135
|
+
ae({
|
|
132
136
|
width: e.width,
|
|
133
137
|
height: e.height
|
|
134
138
|
});
|
|
135
139
|
};
|
|
136
140
|
if (e(), typeof ResizeObserver > "u") return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
|
|
137
141
|
let t = new ResizeObserver(e);
|
|
138
|
-
return t.observe(
|
|
139
|
-
}, [
|
|
140
|
-
if (!
|
|
142
|
+
return t.observe(F), () => t.disconnect();
|
|
143
|
+
}, [r, F]), l(() => {
|
|
144
|
+
if (!r) return;
|
|
141
145
|
let e = window.setInterval(() => {
|
|
142
|
-
let e =
|
|
143
|
-
e &&
|
|
146
|
+
let e = E.current?.getDiagnostics();
|
|
147
|
+
e && W(e);
|
|
144
148
|
}, 500);
|
|
145
149
|
return () => window.clearInterval(e);
|
|
146
|
-
}, [
|
|
147
|
-
if (!
|
|
148
|
-
let e = 0, t = performance.now(),
|
|
149
|
-
let i =
|
|
150
|
-
t =
|
|
150
|
+
}, [r, U]), l(() => {
|
|
151
|
+
if (!r) return;
|
|
152
|
+
let e = 0, t = performance.now(), n = (r) => {
|
|
153
|
+
let i = j.current.step(r - t);
|
|
154
|
+
t = r, i && B(i), e = requestAnimationFrame(n);
|
|
151
155
|
};
|
|
152
|
-
return e = requestAnimationFrame(
|
|
153
|
-
}, [
|
|
154
|
-
if (!
|
|
156
|
+
return e = requestAnimationFrame(n), () => cancelAnimationFrame(e);
|
|
157
|
+
}, [r]), l(() => {
|
|
158
|
+
if (!r || !F) return;
|
|
155
159
|
let e = !1, t = () => {
|
|
156
|
-
|
|
160
|
+
D.current?.stop(), D.current = void 0, E.current?.stop(), E.current = void 0, k.current = void 0, O.current = void 0, A.current = {}, Y();
|
|
157
161
|
};
|
|
158
162
|
return (async () => {
|
|
159
|
-
t(),
|
|
163
|
+
t(), M.current = !1, L("starting"), H(""), z(void 0), V(void 0), G(void 0), K("idle"), Y();
|
|
160
164
|
try {
|
|
161
|
-
let t = await
|
|
165
|
+
let t = await a(F, { torch: c });
|
|
162
166
|
if (e) {
|
|
163
167
|
t.stop();
|
|
164
168
|
return;
|
|
165
169
|
}
|
|
166
|
-
|
|
170
|
+
E.current = t;
|
|
167
171
|
let n = t.getSettings();
|
|
168
|
-
|
|
169
|
-
source:
|
|
170
|
-
autoCapture:
|
|
171
|
-
intervalMs:
|
|
172
|
+
se(n), N.current.onSettings?.(n), console.info("[ScannerProvider] camera settings", n), D.current = await i({
|
|
173
|
+
source: F,
|
|
174
|
+
autoCapture: o,
|
|
175
|
+
intervalMs: C,
|
|
172
176
|
detection: {
|
|
173
|
-
modelUrl:
|
|
174
|
-
ortWasmPaths:
|
|
177
|
+
modelUrl: x,
|
|
178
|
+
ortWasmPaths: S
|
|
175
179
|
},
|
|
176
180
|
onStatus: (e) => {
|
|
177
|
-
if (
|
|
178
|
-
let t =
|
|
179
|
-
|
|
180
|
-
} else
|
|
181
|
-
e.state !== "captured" && !
|
|
181
|
+
if (O.current = e, z(e), N.current.onFinderStatus?.(e), e.quad && e.sourceWidth && e.sourceHeight) {
|
|
182
|
+
let t = j.current.setTarget(e.quad, e.sourceWidth, e.sourceHeight);
|
|
183
|
+
B(t.quad);
|
|
184
|
+
} else j.current.clear(), B(void 0);
|
|
185
|
+
e.state !== "captured" && !M.current && L("ready");
|
|
182
186
|
},
|
|
183
187
|
captureFrame: async () => {
|
|
184
|
-
|
|
185
|
-
quad:
|
|
186
|
-
sourceWidth:
|
|
187
|
-
sourceHeight:
|
|
188
|
+
L("capturing"), A.current = {
|
|
189
|
+
quad: j.current.getCurrent(),
|
|
190
|
+
sourceWidth: O.current?.sourceWidth,
|
|
191
|
+
sourceHeight: O.current?.sourceHeight
|
|
188
192
|
};
|
|
189
193
|
let e = await t.capturePhoto();
|
|
190
|
-
if (
|
|
191
|
-
return
|
|
194
|
+
if (k.current = e, V(e.method), G(e.diagnostics), W(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.`);
|
|
195
|
+
return X(e.frame, F), L("captured"), e.frame;
|
|
192
196
|
},
|
|
193
197
|
onCaptureError: (e) => {
|
|
194
|
-
|
|
195
|
-
let t =
|
|
196
|
-
t &&
|
|
198
|
+
M.current = !0, L("error"), H(e.message);
|
|
199
|
+
let t = E.current?.getDiagnostics();
|
|
200
|
+
t && W(t), N.current.onError?.(e);
|
|
197
201
|
},
|
|
198
202
|
onCapture: async (e) => {
|
|
199
|
-
let n =
|
|
200
|
-
await new Promise((e) => window.setTimeout(e, 140)), await
|
|
203
|
+
let n = k.current;
|
|
204
|
+
await new Promise((e) => window.setTimeout(e, 140)), await N.current.onCapture({
|
|
201
205
|
...e,
|
|
202
206
|
method: n?.method ?? "video-frame",
|
|
203
207
|
settings: n?.settings ?? t.getSettings(),
|
|
204
208
|
fallbackReason: n?.fallbackReason,
|
|
205
209
|
luminance: n?.luminance,
|
|
206
210
|
diagnostics: n?.diagnostics,
|
|
207
|
-
displayedQuad:
|
|
208
|
-
displaySourceWidth:
|
|
209
|
-
displaySourceHeight:
|
|
211
|
+
displayedQuad: A.current.quad,
|
|
212
|
+
displaySourceWidth: A.current.sourceWidth,
|
|
213
|
+
displaySourceHeight: A.current.sourceHeight
|
|
210
214
|
});
|
|
211
215
|
}
|
|
212
216
|
});
|
|
@@ -214,70 +218,71 @@ function y({ open: n, autoCapture: a = "defaultOn", torch: s = "defaultOff", onC
|
|
|
214
218
|
if (e) return;
|
|
215
219
|
t();
|
|
216
220
|
let r = n instanceof Error ? n : /* @__PURE__ */ Error("Camera access failed.");
|
|
217
|
-
|
|
221
|
+
H(r.message), L("error"), N.current.onError?.(r);
|
|
218
222
|
}
|
|
219
223
|
})(), () => {
|
|
220
224
|
e = !0, t();
|
|
221
225
|
};
|
|
222
226
|
}, [
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
y,
|
|
228
|
-
b,
|
|
227
|
+
r,
|
|
228
|
+
F,
|
|
229
|
+
o,
|
|
230
|
+
c,
|
|
229
231
|
x,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
232
|
+
S,
|
|
233
|
+
C,
|
|
234
|
+
U,
|
|
235
|
+
Y,
|
|
236
|
+
X
|
|
233
237
|
]);
|
|
234
|
-
let
|
|
235
|
-
open:
|
|
236
|
-
phase:
|
|
237
|
-
autoCapture:
|
|
238
|
-
finderStatus:
|
|
239
|
-
displayQuad:
|
|
240
|
-
previewSize:
|
|
241
|
-
settings:
|
|
242
|
-
captureMethod:
|
|
243
|
-
error:
|
|
244
|
-
diagnostics:
|
|
245
|
-
shutterDiagnostics:
|
|
246
|
-
copyState:
|
|
247
|
-
guidanceHint:
|
|
248
|
-
detectorStatus:
|
|
249
|
-
|
|
238
|
+
let Z = {
|
|
239
|
+
open: r,
|
|
240
|
+
phase: ne,
|
|
241
|
+
autoCapture: o,
|
|
242
|
+
finderStatus: R,
|
|
243
|
+
displayQuad: re,
|
|
244
|
+
previewSize: ie,
|
|
245
|
+
settings: oe,
|
|
246
|
+
captureMethod: ce,
|
|
247
|
+
error: le,
|
|
248
|
+
diagnostics: de,
|
|
249
|
+
shutterDiagnostics: fe,
|
|
250
|
+
copyState: pe,
|
|
251
|
+
guidanceHint: R ? n(R.guidance, R.lighting) : void 0,
|
|
252
|
+
detectorStatus: R?.modelStatus === "failed" ? "ML failed" : R?.detector === "ml" ? `ML ${R.modelProvider ?? ""}`.trim() : "ML loading",
|
|
253
|
+
modelDownload: he,
|
|
254
|
+
frozenPreviewUrl: me
|
|
250
255
|
};
|
|
251
|
-
|
|
252
|
-
|
|
256
|
+
l(() => {
|
|
257
|
+
P.current = Z;
|
|
253
258
|
});
|
|
254
|
-
let
|
|
255
|
-
|
|
256
|
-
}, []),
|
|
259
|
+
let ve = s(() => {
|
|
260
|
+
N.current.onCancel();
|
|
261
|
+
}, []), ye = s(async () => {
|
|
257
262
|
try {
|
|
258
|
-
await
|
|
263
|
+
await D.current?.capture();
|
|
259
264
|
} catch (e) {
|
|
260
265
|
let t = e instanceof Error ? e : /* @__PURE__ */ Error("Could not capture the camera frame.");
|
|
261
|
-
|
|
262
|
-
let n =
|
|
263
|
-
n &&
|
|
266
|
+
M.current = !0, H(t.message);
|
|
267
|
+
let n = E.current?.getDiagnostics();
|
|
268
|
+
n && W(n), k.current?.diagnostics && G(k.current.diagnostics), L("error"), N.current.onError?.(t);
|
|
264
269
|
}
|
|
265
|
-
}, []),
|
|
266
|
-
|
|
267
|
-
let e =
|
|
268
|
-
|
|
269
|
-
}, [
|
|
270
|
-
let t =
|
|
271
|
-
t && (await t.setTorch(e),
|
|
272
|
-
}, []),
|
|
273
|
-
|
|
274
|
-
}, []),
|
|
275
|
-
let
|
|
276
|
-
error:
|
|
277
|
-
captureMethod:
|
|
278
|
-
luminance:
|
|
279
|
-
fallbackReason:
|
|
280
|
-
shutter:
|
|
270
|
+
}, []), be = s(() => {
|
|
271
|
+
M.current = !1, H(""), G(void 0), K("idle"), Y();
|
|
272
|
+
let e = E.current;
|
|
273
|
+
F?.paused && F.play(), L(e ? "ready" : "starting"), e || ue((e) => e + 1);
|
|
274
|
+
}, [Y, F]), xe = s(async (e) => {
|
|
275
|
+
let t = E.current;
|
|
276
|
+
t && (await t.setTorch(e), W(t.getDiagnostics()));
|
|
277
|
+
}, []), Se = s((e) => {
|
|
278
|
+
D.current?.setAutoCapture(e);
|
|
279
|
+
}, []), Ce = s(async () => {
|
|
280
|
+
let e = P.current, n = E.current?.getDiagnostics() ?? e.diagnostics, r = e.finderStatus, i = t({
|
|
281
|
+
error: e.error || void 0,
|
|
282
|
+
captureMethod: e.captureMethod,
|
|
283
|
+
luminance: k.current?.luminance,
|
|
284
|
+
fallbackReason: k.current?.fallbackReason,
|
|
285
|
+
shutter: e.shutterDiagnostics ?? k.current?.diagnostics,
|
|
281
286
|
live: n,
|
|
282
287
|
finder: r ? {
|
|
283
288
|
state: r.state,
|
|
@@ -298,55 +303,55 @@ function y({ open: n, autoCapture: a = "defaultOn", torch: s = "defaultOff", onC
|
|
|
298
303
|
let t = document.execCommand("copy");
|
|
299
304
|
if (e.remove(), !t) throw Error("Clipboard copy is unavailable.");
|
|
300
305
|
}
|
|
301
|
-
|
|
306
|
+
K("copied");
|
|
302
307
|
} catch {
|
|
303
|
-
|
|
308
|
+
K("failed");
|
|
304
309
|
}
|
|
305
|
-
}, []),
|
|
306
|
-
capture:
|
|
307
|
-
cancel:
|
|
308
|
-
retry:
|
|
309
|
-
setTorch:
|
|
310
|
-
setAutoCapture:
|
|
311
|
-
copyReport:
|
|
312
|
-
getState:
|
|
310
|
+
}, []), Q = s(() => P.current, []), $ = u(() => ({
|
|
311
|
+
capture: ye,
|
|
312
|
+
cancel: ve,
|
|
313
|
+
retry: be,
|
|
314
|
+
setTorch: xe,
|
|
315
|
+
setAutoCapture: Se,
|
|
316
|
+
copyReport: Ce,
|
|
317
|
+
getState: Q
|
|
313
318
|
}), [
|
|
314
|
-
Z,
|
|
315
|
-
X,
|
|
316
|
-
Q,
|
|
317
|
-
_e,
|
|
318
|
-
ve,
|
|
319
319
|
ye,
|
|
320
|
-
|
|
320
|
+
ve,
|
|
321
|
+
be,
|
|
322
|
+
xe,
|
|
323
|
+
Se,
|
|
324
|
+
Ce,
|
|
325
|
+
Q
|
|
321
326
|
]);
|
|
322
|
-
|
|
323
|
-
if (
|
|
324
|
-
|
|
327
|
+
l(() => {
|
|
328
|
+
if (w) return w.current = $, () => {
|
|
329
|
+
w.current = null;
|
|
325
330
|
};
|
|
326
|
-
}, [$,
|
|
327
|
-
let
|
|
328
|
-
...
|
|
331
|
+
}, [$, w]);
|
|
332
|
+
let we = {
|
|
333
|
+
...Z,
|
|
329
334
|
...$,
|
|
330
|
-
bindPreview:
|
|
335
|
+
bindPreview: _e
|
|
331
336
|
};
|
|
332
|
-
return /* @__PURE__ */
|
|
333
|
-
value:
|
|
334
|
-
children:
|
|
337
|
+
return /* @__PURE__ */ m(y.Provider, {
|
|
338
|
+
value: we,
|
|
339
|
+
children: T
|
|
335
340
|
});
|
|
336
341
|
}
|
|
337
342
|
//#endregion
|
|
338
343
|
//#region src/react/hooks.ts
|
|
339
|
-
function
|
|
340
|
-
return
|
|
344
|
+
function S() {
|
|
345
|
+
return d(null);
|
|
341
346
|
}
|
|
342
|
-
function
|
|
343
|
-
let e =
|
|
347
|
+
function C() {
|
|
348
|
+
let e = c(y);
|
|
344
349
|
if (!e) throw Error("useScanner must be used within ScannerProvider.");
|
|
345
350
|
return e;
|
|
346
351
|
}
|
|
347
352
|
//#endregion
|
|
348
353
|
//#region src/live-overlay-geometry.ts
|
|
349
|
-
function
|
|
354
|
+
function w(e, t, n, r, i) {
|
|
350
355
|
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;
|
|
351
356
|
if (i === "contain") return {
|
|
352
357
|
viewBox: `0 0 ${a} ${o}`,
|
|
@@ -366,10 +371,10 @@ function S(e, t, n, r, i) {
|
|
|
366
371
|
}
|
|
367
372
|
//#endregion
|
|
368
373
|
//#region src/components/ModelDownloadRing.tsx
|
|
369
|
-
function
|
|
374
|
+
function T({ snapshot: e }) {
|
|
370
375
|
if (!e.downloading) return null;
|
|
371
376
|
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;
|
|
372
|
-
return /* @__PURE__ */
|
|
377
|
+
return /* @__PURE__ */ h("div", {
|
|
373
378
|
className: `model-download-ring${t === null ? " is-indeterminate" : ""}`,
|
|
374
379
|
role: "progressbar",
|
|
375
380
|
"aria-label": "Model download",
|
|
@@ -378,15 +383,15 @@ function C({ snapshot: e }) {
|
|
|
378
383
|
"aria-valuenow": n ?? void 0,
|
|
379
384
|
"data-loaded": e.loaded,
|
|
380
385
|
"data-total": e.total ?? "",
|
|
381
|
-
children: [/* @__PURE__ */
|
|
386
|
+
children: [/* @__PURE__ */ h("svg", {
|
|
382
387
|
viewBox: "0 0 72 72",
|
|
383
388
|
"aria-hidden": "true",
|
|
384
|
-
children: [/* @__PURE__ */
|
|
389
|
+
children: [/* @__PURE__ */ m("circle", {
|
|
385
390
|
className: "track",
|
|
386
391
|
cx: "36",
|
|
387
392
|
cy: "36",
|
|
388
393
|
r: 28
|
|
389
|
-
}), /* @__PURE__ */
|
|
394
|
+
}), /* @__PURE__ */ m("circle", {
|
|
390
395
|
className: "value",
|
|
391
396
|
cx: "36",
|
|
392
397
|
cy: "36",
|
|
@@ -394,15 +399,15 @@ function C({ snapshot: e }) {
|
|
|
394
399
|
strokeDasharray: t === null ? void 0 : `${r} ${r}`,
|
|
395
400
|
strokeDashoffset: t === null ? void 0 : r * (1 - t)
|
|
396
401
|
})]
|
|
397
|
-
}), n === null ? /* @__PURE__ */
|
|
402
|
+
}), n === null ? /* @__PURE__ */ m("strong", {
|
|
398
403
|
className: "model-download-ring__pending",
|
|
399
404
|
children: "…"
|
|
400
|
-
}) : /* @__PURE__ */
|
|
405
|
+
}) : /* @__PURE__ */ h("strong", { children: [n, "%"] })]
|
|
401
406
|
});
|
|
402
407
|
}
|
|
403
408
|
//#endregion
|
|
404
409
|
//#region src/react/parts.tsx
|
|
405
|
-
var
|
|
410
|
+
var E = {
|
|
406
411
|
primaryColorHex: "--scanner-overlay-primary",
|
|
407
412
|
seekingColorHex: "--scanner-overlay-seeking",
|
|
408
413
|
detectingColorHex: "--scanner-overlay-detecting",
|
|
@@ -410,38 +415,38 @@ var w = {
|
|
|
410
415
|
readyColorHex: "--scanner-overlay-ready",
|
|
411
416
|
capturedColorHex: "--scanner-overlay-captured"
|
|
412
417
|
};
|
|
413
|
-
function
|
|
418
|
+
function D(e) {
|
|
414
419
|
if (!e) return;
|
|
415
420
|
let t = {};
|
|
416
|
-
for (let [n, r] of Object.entries(
|
|
421
|
+
for (let [n, r] of Object.entries(E)) {
|
|
417
422
|
let i = e[n]?.trim();
|
|
418
423
|
i && (t[r] = i);
|
|
419
424
|
}
|
|
420
425
|
return Object.keys(t).length > 0 ? t : void 0;
|
|
421
426
|
}
|
|
422
|
-
function
|
|
423
|
-
let i =
|
|
427
|
+
function O({ theme: e, style: t, title: n = "Scan a document", children: r }) {
|
|
428
|
+
let i = C();
|
|
424
429
|
if (!i.open) return null;
|
|
425
|
-
let a =
|
|
430
|
+
let a = D(e), o = a ? {
|
|
426
431
|
...t,
|
|
427
432
|
...a
|
|
428
433
|
} : t;
|
|
429
|
-
return /* @__PURE__ */
|
|
434
|
+
return /* @__PURE__ */ h("div", {
|
|
430
435
|
className: `scanner-camera-overlay ${i.finderStatus?.state === "captured" ? "is-captured" : ""}`.trim(),
|
|
431
436
|
style: o,
|
|
432
437
|
role: "dialog",
|
|
433
438
|
"aria-modal": "true",
|
|
434
439
|
"aria-label": n,
|
|
435
|
-
children: r
|
|
440
|
+
children: [r, /* @__PURE__ */ m(I, {})]
|
|
436
441
|
});
|
|
437
442
|
}
|
|
438
|
-
function
|
|
439
|
-
let { bindPreview: e, frozenPreviewUrl: t } =
|
|
443
|
+
function k() {
|
|
444
|
+
let { bindPreview: e, frozenPreviewUrl: t } = C(), n = d(null), r = s((t) => {
|
|
440
445
|
n.current = t, e(t);
|
|
441
446
|
}, [e]);
|
|
442
|
-
return
|
|
447
|
+
return l(() => {
|
|
443
448
|
t && n.current?.pause();
|
|
444
|
-
}, [t]), /* @__PURE__ */
|
|
449
|
+
}, [t]), /* @__PURE__ */ h(p, { children: [/* @__PURE__ */ m("video", {
|
|
445
450
|
ref: r,
|
|
446
451
|
className: "scanner-camera-overlay__video",
|
|
447
452
|
muted: !0,
|
|
@@ -450,30 +455,30 @@ function D() {
|
|
|
450
455
|
style: { objectFit: "cover" },
|
|
451
456
|
"aria-hidden": !!t,
|
|
452
457
|
"aria-label": "Rear camera preview"
|
|
453
|
-
}), t ? /* @__PURE__ */
|
|
458
|
+
}), t ? /* @__PURE__ */ m("img", {
|
|
454
459
|
src: t,
|
|
455
460
|
className: "scanner-camera-overlay__video scanner-camera-overlay__still",
|
|
456
461
|
alt: "",
|
|
457
462
|
"aria-label": "Captured document"
|
|
458
463
|
}) : null] });
|
|
459
464
|
}
|
|
460
|
-
function
|
|
461
|
-
let { finderStatus: e, displayQuad: t, previewSize: n } =
|
|
465
|
+
function A() {
|
|
466
|
+
let { finderStatus: e, displayQuad: t, previewSize: n } = C();
|
|
462
467
|
if (!t || !e?.sourceWidth || !e.sourceHeight) return null;
|
|
463
|
-
let r =
|
|
464
|
-
return /* @__PURE__ */
|
|
468
|
+
let r = w(e.sourceWidth, e.sourceHeight, n.width, n.height, "cover");
|
|
469
|
+
return /* @__PURE__ */ m("svg", {
|
|
465
470
|
className: `scanner-camera-overlay__quad ${e.state}`,
|
|
466
471
|
viewBox: r.viewBox,
|
|
467
472
|
preserveAspectRatio: r.preserveAspectRatio,
|
|
468
473
|
"aria-label": `${e.state} document boundary`,
|
|
469
|
-
children: /* @__PURE__ */
|
|
474
|
+
children: /* @__PURE__ */ m("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}` })
|
|
470
475
|
});
|
|
471
476
|
}
|
|
472
|
-
function
|
|
473
|
-
let { phase: t, guidanceHint: n, cancel: r } =
|
|
474
|
-
return /* @__PURE__ */
|
|
477
|
+
function j({ title: e = "Scan a document" }) {
|
|
478
|
+
let { phase: t, guidanceHint: n, cancel: r } = C();
|
|
479
|
+
return /* @__PURE__ */ h("div", {
|
|
475
480
|
className: "scanner-camera-overlay__topbar",
|
|
476
|
-
children: [/* @__PURE__ */
|
|
481
|
+
children: [/* @__PURE__ */ h("div", { children: [/* @__PURE__ */ m("strong", { children: e }), /* @__PURE__ */ h("span", {
|
|
477
482
|
"aria-live": "polite",
|
|
478
483
|
children: [
|
|
479
484
|
t === "starting" && "Starting rear camera…",
|
|
@@ -482,7 +487,7 @@ function k({ title: e = "Scan a document" }) {
|
|
|
482
487
|
t === "captured" && "Document captured",
|
|
483
488
|
t === "error" && "Camera unavailable"
|
|
484
489
|
]
|
|
485
|
-
})] }), /* @__PURE__ */
|
|
490
|
+
})] }), /* @__PURE__ */ m("button", {
|
|
486
491
|
type: "button",
|
|
487
492
|
onClick: r,
|
|
488
493
|
"aria-label": "Close camera",
|
|
@@ -490,51 +495,51 @@ function k({ title: e = "Scan a document" }) {
|
|
|
490
495
|
})]
|
|
491
496
|
});
|
|
492
497
|
}
|
|
493
|
-
function
|
|
494
|
-
let { phase: e, error: t, diagnostics: n, copyState: r, retry: i, copyReport: a, cancel: o } =
|
|
495
|
-
return e === "error" ? /* @__PURE__ */
|
|
498
|
+
function M() {
|
|
499
|
+
let { phase: e, error: t, diagnostics: n, copyState: r, retry: i, copyReport: a, cancel: o } = C();
|
|
500
|
+
return e === "error" ? /* @__PURE__ */ h("div", {
|
|
496
501
|
className: "scanner-camera-overlay__message",
|
|
497
502
|
role: "alert",
|
|
498
503
|
children: [
|
|
499
|
-
/* @__PURE__ */
|
|
500
|
-
/* @__PURE__ */
|
|
501
|
-
/* @__PURE__ */
|
|
502
|
-
/* @__PURE__ */
|
|
504
|
+
/* @__PURE__ */ m("strong", { children: n ? "Capture failed" : "Could not open the camera" }),
|
|
505
|
+
/* @__PURE__ */ m("p", { children: t }),
|
|
506
|
+
/* @__PURE__ */ h("div", { children: [
|
|
507
|
+
/* @__PURE__ */ m("button", {
|
|
503
508
|
type: "button",
|
|
504
509
|
onClick: i,
|
|
505
510
|
children: "Try again"
|
|
506
511
|
}),
|
|
507
|
-
/* @__PURE__ */
|
|
512
|
+
/* @__PURE__ */ m("button", {
|
|
508
513
|
type: "button",
|
|
509
514
|
onClick: () => void a(),
|
|
510
515
|
children: r === "copied" ? "Copied" : r === "failed" ? "Copy failed" : "Copy report"
|
|
511
516
|
}),
|
|
512
|
-
/* @__PURE__ */
|
|
517
|
+
/* @__PURE__ */ m("button", {
|
|
513
518
|
type: "button",
|
|
514
519
|
onClick: o,
|
|
515
520
|
children: "Cancel"
|
|
516
521
|
})
|
|
517
522
|
] })
|
|
518
523
|
]
|
|
519
|
-
}) : e === "starting" ? /* @__PURE__ */
|
|
524
|
+
}) : e === "starting" ? /* @__PURE__ */ h("div", {
|
|
520
525
|
className: "scanner-camera-overlay__message",
|
|
521
526
|
"aria-live": "polite",
|
|
522
527
|
children: [
|
|
523
|
-
/* @__PURE__ */
|
|
524
|
-
/* @__PURE__ */
|
|
525
|
-
/* @__PURE__ */
|
|
528
|
+
/* @__PURE__ */ m("span", { className: "scanner-camera-overlay__spinner" }),
|
|
529
|
+
/* @__PURE__ */ m("strong", { children: "Requesting the highest practical resolution" }),
|
|
530
|
+
/* @__PURE__ */ m("p", { children: "Allow camera access to continue." })
|
|
526
531
|
]
|
|
527
532
|
}) : null;
|
|
528
533
|
}
|
|
529
|
-
function
|
|
530
|
-
let { finderStatus: e, detectorStatus: t, settings: n } =
|
|
531
|
-
return /* @__PURE__ */
|
|
534
|
+
function N() {
|
|
535
|
+
let { finderStatus: e, detectorStatus: t, settings: n } = C(), r = n?.width, i = n?.height;
|
|
536
|
+
return /* @__PURE__ */ m("div", {
|
|
532
537
|
className: "scanner-camera-overlay__status",
|
|
533
538
|
"aria-live": "polite",
|
|
534
|
-
children: /* @__PURE__ */
|
|
539
|
+
children: /* @__PURE__ */ h("div", {
|
|
535
540
|
className: "scanner-camera-overlay__status-line",
|
|
536
541
|
children: [
|
|
537
|
-
/* @__PURE__ */
|
|
542
|
+
/* @__PURE__ */ m("span", { className: e?.state ?? "detecting" }),
|
|
538
543
|
e?.state ?? "detecting",
|
|
539
544
|
e ? ` · ${Math.round(e.confidence * 100)}% · ${e.stableFrames}/${e.requiredStableFrames}` : "",
|
|
540
545
|
` · ${t}`,
|
|
@@ -544,25 +549,25 @@ function j() {
|
|
|
544
549
|
})
|
|
545
550
|
});
|
|
546
551
|
}
|
|
547
|
-
function
|
|
548
|
-
let { diagnostics: e, shutterDiagnostics: t, captureMethod:
|
|
549
|
-
return /* @__PURE__ */
|
|
552
|
+
function P() {
|
|
553
|
+
let { diagnostics: e, shutterDiagnostics: t, captureMethod: n, copyState: i, copyReport: a } = C(), o = e?.engine ?? r();
|
|
554
|
+
return /* @__PURE__ */ h("dl", {
|
|
550
555
|
className: "scanner-camera-overlay__diagnostics",
|
|
551
556
|
"aria-label": "Camera diagnostics",
|
|
552
557
|
children: [
|
|
553
|
-
/* @__PURE__ */
|
|
558
|
+
/* @__PURE__ */ h("div", { children: [/* @__PURE__ */ m("dt", { children: "engine" }), /* @__PURE__ */ h("dd", { children: [
|
|
554
559
|
o.engine,
|
|
555
560
|
"/",
|
|
556
561
|
o.browser,
|
|
557
562
|
o.iosWebKit ? " ios" : ""
|
|
558
563
|
] })] }),
|
|
559
|
-
/* @__PURE__ */
|
|
560
|
-
/* @__PURE__ */
|
|
561
|
-
/* @__PURE__ */
|
|
562
|
-
/* @__PURE__ */
|
|
563
|
-
/* @__PURE__ */
|
|
564
|
-
t ? /* @__PURE__ */
|
|
565
|
-
/* @__PURE__ */
|
|
564
|
+
/* @__PURE__ */ h("div", { children: [/* @__PURE__ */ m("dt", { children: "video" }), /* @__PURE__ */ m("dd", { children: e ? `${e.videoWidth}×${e.videoHeight} rs${e.readyState}${e.paused ? " paused" : ""}${e.rendered ? "" : " hidden"}` : "starting" })] }),
|
|
565
|
+
/* @__PURE__ */ h("div", { children: [/* @__PURE__ */ m("dt", { children: "track" }), /* @__PURE__ */ m("dd", { children: e ? `${e.trackReadyState}${e.trackMuted ? " muted" : ""}${e.trackEnabled ? "" : " disabled"}` : "—" })] }),
|
|
566
|
+
/* @__PURE__ */ h("div", { children: [/* @__PURE__ */ m("dt", { children: "torch" }), /* @__PURE__ */ m("dd", { children: e ? `${e.torch.mode} · ${e.torch.supported ? e.torch.on ? "on" : "off" : "unsupported"}` : "starting" })] }),
|
|
567
|
+
/* @__PURE__ */ h("div", { children: [/* @__PURE__ */ m("dt", { children: "luma" }), /* @__PURE__ */ m("dd", { children: e ? `live ${e.liveLuminance.toFixed(1)} · mirror ${e.mirrorLuminance.toFixed(1)}${Number.isFinite(e.mirrorAgeMs) ? ` (${Math.round(e.mirrorAgeMs)}ms)` : " (none)"}` : "—" })] }),
|
|
568
|
+
/* @__PURE__ */ h("div", { children: [/* @__PURE__ */ m("dt", { children: "path" }), /* @__PURE__ */ m("dd", { children: n ?? "video-frame / live-mirror" })] }),
|
|
569
|
+
t ? /* @__PURE__ */ h("div", { children: [/* @__PURE__ */ m("dt", { children: "shutter" }), /* @__PURE__ */ m("dd", { children: `live ${t.liveLuminance.toFixed(1)} · mirror ${t.mirrorLuminance.toFixed(1)}${Number.isFinite(t.mirrorAgeMs) ? ` (${Math.round(t.mirrorAgeMs)}ms)` : " (none)"}` })] }) : null,
|
|
570
|
+
/* @__PURE__ */ h("div", { children: [/* @__PURE__ */ m("dt", { children: "share" }), /* @__PURE__ */ m("dd", { children: /* @__PURE__ */ m("button", {
|
|
566
571
|
type: "button",
|
|
567
572
|
className: "scanner-camera-overlay__copy",
|
|
568
573
|
onClick: () => void a(),
|
|
@@ -571,35 +576,35 @@ function M() {
|
|
|
571
576
|
]
|
|
572
577
|
});
|
|
573
578
|
}
|
|
574
|
-
function
|
|
575
|
-
let { autoCapture: e, phase: t, finderStatus: n, diagnostics: r, captureMethod: i, settings: a, cancel: o, capture: s, setAutoCapture: c, setTorch: l } =
|
|
576
|
-
return /* @__PURE__ */
|
|
579
|
+
function F() {
|
|
580
|
+
let { autoCapture: e, phase: t, finderStatus: n, diagnostics: r, captureMethod: i, settings: a, cancel: o, capture: s, setAutoCapture: c, setTorch: l } = C(), u = a?.width, d = a?.height;
|
|
581
|
+
return /* @__PURE__ */ h("div", {
|
|
577
582
|
className: "scanner-camera-overlay__controls",
|
|
578
583
|
children: [
|
|
579
|
-
/* @__PURE__ */
|
|
584
|
+
/* @__PURE__ */ m("button", {
|
|
580
585
|
type: "button",
|
|
581
586
|
className: "scanner-camera-overlay__cancel",
|
|
582
587
|
onClick: o,
|
|
583
588
|
children: "Cancel"
|
|
584
589
|
}),
|
|
585
|
-
/* @__PURE__ */
|
|
590
|
+
/* @__PURE__ */ h("div", {
|
|
586
591
|
className: "scanner-camera-overlay__capture",
|
|
587
|
-
children: [e !== "only" && /* @__PURE__ */
|
|
592
|
+
children: [e !== "only" && /* @__PURE__ */ m("button", {
|
|
588
593
|
type: "button",
|
|
589
594
|
className: "scanner-camera-overlay__shutter",
|
|
590
595
|
onClick: () => void s(),
|
|
591
596
|
disabled: t !== "ready",
|
|
592
597
|
"aria-label": "Capture full-resolution photo",
|
|
593
|
-
children: /* @__PURE__ */
|
|
594
|
-
}), /* @__PURE__ */
|
|
598
|
+
children: /* @__PURE__ */ m("span", {})
|
|
599
|
+
}), /* @__PURE__ */ h("div", {
|
|
595
600
|
className: "scanner-camera-overlay__toggles",
|
|
596
|
-
children: [n?.autoCapture.visible && /* @__PURE__ */
|
|
601
|
+
children: [n?.autoCapture.visible && /* @__PURE__ */ h("label", { children: [/* @__PURE__ */ m("input", {
|
|
597
602
|
type: "checkbox",
|
|
598
603
|
checked: n.autoCapture.checked,
|
|
599
604
|
onChange: (e) => c(e.target.checked)
|
|
600
|
-
}), "Auto-capture"] }), r?.torch.visible && /* @__PURE__ */
|
|
605
|
+
}), "Auto-capture"] }), r?.torch.visible && /* @__PURE__ */ h("label", {
|
|
601
606
|
title: r.torch.automatic ? "Torch is controlled automatically from scene brightness" : void 0,
|
|
602
|
-
children: [/* @__PURE__ */
|
|
607
|
+
children: [/* @__PURE__ */ m("input", {
|
|
603
608
|
type: "checkbox",
|
|
604
609
|
checked: r.torch.on,
|
|
605
610
|
disabled: !r.torch.mutable,
|
|
@@ -608,17 +613,18 @@ function N() {
|
|
|
608
613
|
})]
|
|
609
614
|
})]
|
|
610
615
|
}),
|
|
611
|
-
/* @__PURE__ */
|
|
616
|
+
/* @__PURE__ */ h("div", {
|
|
612
617
|
className: "scanner-camera-overlay__quality",
|
|
613
|
-
children: [/* @__PURE__ */
|
|
618
|
+
children: [/* @__PURE__ */ m("span", { children: i === "live-mirror" ? "Mirror" : "Camera" }), /* @__PURE__ */ m("strong", { children: u && d ? `${u} × ${d}` : "Measuring…" })]
|
|
614
619
|
})
|
|
615
620
|
]
|
|
616
621
|
});
|
|
617
622
|
}
|
|
618
|
-
function
|
|
619
|
-
|
|
623
|
+
function I({ snapshot: e }) {
|
|
624
|
+
let { modelDownload: t } = C();
|
|
625
|
+
return /* @__PURE__ */ m(T, { snapshot: e ?? t });
|
|
620
626
|
}
|
|
621
627
|
//#endregion
|
|
622
|
-
export {
|
|
628
|
+
export { F as ScannerControls, P as ScannerDiagnostics, O as ScannerFrame, I as ScannerModelDownload, M as ScannerNotice, k as ScannerPreview, x as ScannerProvider, A as ScannerQuad, N as ScannerStatus, j as ScannerTopBar, C as useScanner, S as useScannerRef };
|
|
623
629
|
|
|
624
630
|
//# sourceMappingURL=react.js.map
|