@nddeps/barcode-scanner 0.6.0 → 0.6.1
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/index.d.ts +30 -8
- package/dist/index.js +150 -144
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,13 @@ import { BarcodeDetectorOptions } from 'barcode-detector/ponyfill';
|
|
|
3
3
|
import { BarcodeFormat } from 'barcode-detector/ponyfill';
|
|
4
4
|
import { DetectedBarcode } from 'barcode-detector/ponyfill';
|
|
5
5
|
|
|
6
|
-
declare
|
|
6
|
+
export declare const BARCODE_SCANNER_BEFORE_START_EVENT = "barcode-scanner:beforestart";
|
|
7
|
+
|
|
8
|
+
export declare const BARCODE_SCANNER_DECODE_FRAME_EVENT = "barcode-scanner:decode-frame";
|
|
9
|
+
|
|
10
|
+
export declare const BARCODE_SCANNER_START_EVENT = "barcode-scanner:start";
|
|
11
|
+
|
|
12
|
+
export declare type Context = {
|
|
7
13
|
state: State;
|
|
8
14
|
};
|
|
9
15
|
|
|
@@ -16,7 +22,6 @@ declare function createBarcodeScanner(video: HTMLVideoElement, { debug, formats,
|
|
|
16
22
|
handleDecodeFailure?: DecodeFailureHandler;
|
|
17
23
|
handleDecodeSuccess?: DecodeSuccessHandler;
|
|
18
24
|
}) => Promise<void>;
|
|
19
|
-
startCallbackProcessed: boolean;
|
|
20
25
|
state: State;
|
|
21
26
|
stop: () => Promise<void>;
|
|
22
27
|
}>;
|
|
@@ -30,9 +35,9 @@ export declare function createWorker({ formats }: {
|
|
|
30
35
|
worker: Worker;
|
|
31
36
|
};
|
|
32
37
|
|
|
33
|
-
declare type DecodeFailureHandler = () => Promise<void> | void;
|
|
38
|
+
export declare type DecodeFailureHandler = () => Promise<void> | void;
|
|
34
39
|
|
|
35
|
-
declare type DecodeSuccessHandler = (data: string, area: ScanArea) => Promise<void> | void;
|
|
40
|
+
export declare type DecodeSuccessHandler = (data: string, area: ScanArea) => Promise<void> | void;
|
|
36
41
|
|
|
37
42
|
export declare function getCameraAccess(): Promise<boolean>;
|
|
38
43
|
|
|
@@ -50,7 +55,7 @@ export declare function isBarcodeDetectorAvailable<T extends object>(value: T):
|
|
|
50
55
|
} & BarcodeDetector;
|
|
51
56
|
} & T;
|
|
52
57
|
|
|
53
|
-
declare type Lifecycle = {
|
|
58
|
+
export declare type Lifecycle = {
|
|
54
59
|
onBeforeCreate?: LifecycleHook;
|
|
55
60
|
onBeforeDecode?: LifecycleHook;
|
|
56
61
|
onBeforePause?: LifecycleHook;
|
|
@@ -63,9 +68,9 @@ declare type Lifecycle = {
|
|
|
63
68
|
onStop?: LifecycleHook;
|
|
64
69
|
};
|
|
65
70
|
|
|
66
|
-
declare type LifecycleHook = (ctx: Context) => void;
|
|
71
|
+
export declare type LifecycleHook = (ctx: Context) => void;
|
|
67
72
|
|
|
68
|
-
declare type Options = {
|
|
73
|
+
export declare type Options = {
|
|
69
74
|
debug?: boolean;
|
|
70
75
|
formats?: BarcodeFormat[];
|
|
71
76
|
getScanArea?: (video: HTMLVideoElement) => ScanArea;
|
|
@@ -92,7 +97,7 @@ export declare type ScanArea = {
|
|
|
92
97
|
y: number;
|
|
93
98
|
};
|
|
94
99
|
|
|
95
|
-
declare type State = {
|
|
100
|
+
export declare type State = {
|
|
96
101
|
decodeFrameTs: number;
|
|
97
102
|
isDecodeFrameProcessed: boolean;
|
|
98
103
|
isDestroyed: boolean;
|
|
@@ -110,4 +115,21 @@ export declare function translateAreaToVideoSource(video: HTMLVideoElement, area
|
|
|
110
115
|
|
|
111
116
|
export declare function wait(ms: number): Promise<unknown>;
|
|
112
117
|
|
|
118
|
+
export declare function waitForEvent(event: string, { resolveOnError, timeout }?: {
|
|
119
|
+
resolveOnError?: boolean;
|
|
120
|
+
timeout?: number;
|
|
121
|
+
}): Promise<unknown>;
|
|
122
|
+
|
|
123
|
+
export declare const WORKER_DECODE_FAILURE_CAUSE = "decode-failure";
|
|
124
|
+
|
|
125
|
+
export declare const WORKER_DECODE_TIMEOUT: number;
|
|
126
|
+
|
|
127
|
+
export declare const WORKER_DECODE_TIMEOUT_CAUSE = "decode-timeout";
|
|
128
|
+
|
|
129
|
+
export declare const WORKER_LOAD_FAILURE_CAUSE = "worker-load-failure";
|
|
130
|
+
|
|
131
|
+
export declare const WORKER_LOAD_TIMEOUT: number;
|
|
132
|
+
|
|
133
|
+
export declare const WORKER_LOAD_TIMEOUT_CAUSE = "worker-load-timeout";
|
|
134
|
+
|
|
113
135
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,60 +1,59 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const n = new Worker(new URL(
|
|
1
|
+
const B = "barcode-scanner:beforestart", L = "barcode-scanner:decode-frame", j = "barcode-scanner:start", N = "decode-failure", K = 16e3, V = "decode-timeout", y = "worker-load-failure", q = 32e3, S = "worker-load-timeout", b = "" + new URL("zxing-reader.wasm", import.meta.url).href;
|
|
2
|
+
function k({ formats: e }) {
|
|
3
|
+
const o = new Worker(new URL(
|
|
5
4
|
/* @vite-ignore */
|
|
6
5
|
"" + new URL("worker.js", import.meta.url).href,
|
|
7
6
|
import.meta.url
|
|
8
|
-
), { type: "module" }), i = new Promise((a,
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
}, 32e3),
|
|
12
|
-
|
|
7
|
+
), { type: "module" }), i = new Promise((a, s) => {
|
|
8
|
+
const r = setTimeout(() => {
|
|
9
|
+
o.removeEventListener("message", h), s(new Error(S));
|
|
10
|
+
}, 32e3), h = ({ data: { payload: c, type: f } }) => {
|
|
11
|
+
f === "init" && (clearTimeout(r), o.removeEventListener("message", h), c.status === "success" ? a(!0) : s(new Error(y)));
|
|
13
12
|
};
|
|
14
|
-
|
|
13
|
+
o.addEventListener("message", h), o.postMessage({
|
|
15
14
|
payload: {
|
|
16
15
|
formats: e,
|
|
17
|
-
wasmUrl:
|
|
16
|
+
wasmUrl: b
|
|
18
17
|
},
|
|
19
18
|
type: "config"
|
|
20
19
|
});
|
|
21
20
|
});
|
|
22
|
-
async function
|
|
21
|
+
async function n(a) {
|
|
23
22
|
await i;
|
|
24
|
-
const
|
|
25
|
-
return new Promise((
|
|
23
|
+
const s = `${performance.now()}-${Math.random().toString(36).slice(2)}`;
|
|
24
|
+
return new Promise((r, h) => {
|
|
26
25
|
const c = setTimeout(() => {
|
|
27
|
-
|
|
28
|
-
}, 16e3),
|
|
29
|
-
|
|
26
|
+
o.removeEventListener("message", f), h(new Error(V));
|
|
27
|
+
}, 16e3), f = ({ data: { payload: E, type: A } }) => {
|
|
28
|
+
A !== "decode" || E.uuid !== s || (clearTimeout(c), o.removeEventListener("message", f), r(E.data));
|
|
30
29
|
};
|
|
31
|
-
|
|
30
|
+
o.addEventListener("message", f), o.postMessage({
|
|
32
31
|
payload: {
|
|
33
32
|
data: a,
|
|
34
|
-
uuid:
|
|
33
|
+
uuid: s
|
|
35
34
|
},
|
|
36
35
|
type: "decode"
|
|
37
36
|
});
|
|
38
37
|
});
|
|
39
38
|
}
|
|
40
39
|
return {
|
|
41
|
-
decode:
|
|
42
|
-
worker:
|
|
40
|
+
decode: n,
|
|
41
|
+
worker: o
|
|
43
42
|
};
|
|
44
43
|
}
|
|
45
|
-
async function
|
|
44
|
+
async function H() {
|
|
46
45
|
try {
|
|
47
46
|
return (await navigator.permissions.query({ name: "camera" })).state === "granted";
|
|
48
47
|
} catch {
|
|
49
48
|
return (await navigator.mediaDevices.enumerateDevices()).filter((i) => i.deviceId && i.kind === "videoinput").length > 0;
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
|
-
async function
|
|
53
|
-
if (await
|
|
51
|
+
async function U() {
|
|
52
|
+
if (await H())
|
|
54
53
|
return !0;
|
|
55
54
|
try {
|
|
56
|
-
const
|
|
57
|
-
for (const i of
|
|
55
|
+
const o = (await navigator.mediaDevices.getUserMedia({ video: !0 })).getTracks();
|
|
56
|
+
for (const i of o)
|
|
58
57
|
i.stop();
|
|
59
58
|
return !0;
|
|
60
59
|
} catch {
|
|
@@ -62,35 +61,35 @@ async function _() {
|
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
function I(e) {
|
|
65
|
-
const
|
|
64
|
+
const o = Math.round(0.6666666666666666 * Math.min(e.videoWidth, e.videoHeight));
|
|
66
65
|
return {
|
|
67
|
-
height:
|
|
68
|
-
width:
|
|
69
|
-
x: Math.round((e.videoWidth -
|
|
70
|
-
y: Math.round((e.videoHeight -
|
|
66
|
+
height: o,
|
|
67
|
+
width: o,
|
|
68
|
+
x: Math.round((e.videoWidth - o) / 2),
|
|
69
|
+
y: Math.round((e.videoHeight - o) / 2)
|
|
71
70
|
};
|
|
72
71
|
}
|
|
73
|
-
function
|
|
74
|
-
const i = window.getComputedStyle(e), [
|
|
75
|
-
(
|
|
72
|
+
function M(e, o) {
|
|
73
|
+
const i = window.getComputedStyle(e), [n, a] = i.objectPosition.split(" ").map(
|
|
74
|
+
(s, r) => s.endsWith("%") ? (r === 0 ? e.offsetWidth - o.width : e.offsetHeight - o.height) * parseFloat(s) / 100 : parseFloat(s)
|
|
76
75
|
);
|
|
77
76
|
return {
|
|
78
|
-
x:
|
|
77
|
+
x: n,
|
|
79
78
|
y: a
|
|
80
79
|
};
|
|
81
80
|
}
|
|
82
|
-
function
|
|
83
|
-
const
|
|
84
|
-
switch (
|
|
81
|
+
function _(e) {
|
|
82
|
+
const o = window.getComputedStyle(e), i = { height: e.offsetHeight, width: e.offsetWidth }, n = i.width / i.height, a = { height: e.videoHeight, width: e.videoWidth }, s = a.width / a.height;
|
|
83
|
+
switch (o.objectFit) {
|
|
85
84
|
case "contain":
|
|
86
85
|
return {
|
|
87
|
-
height:
|
|
88
|
-
width:
|
|
86
|
+
height: s < n ? e.offsetHeight : e.offsetWidth / s,
|
|
87
|
+
width: s < n ? e.offsetHeight * s : e.offsetWidth
|
|
89
88
|
};
|
|
90
89
|
case "cover":
|
|
91
90
|
return {
|
|
92
|
-
height:
|
|
93
|
-
width:
|
|
91
|
+
height: s > n ? e.offsetHeight : e.offsetWidth / s,
|
|
92
|
+
width: s > n ? e.offsetHeight * s : e.offsetWidth
|
|
94
93
|
};
|
|
95
94
|
case "fill":
|
|
96
95
|
return i;
|
|
@@ -99,11 +98,11 @@ function b(e) {
|
|
|
99
98
|
case "scale-down":
|
|
100
99
|
return {
|
|
101
100
|
height: Math.min(
|
|
102
|
-
|
|
101
|
+
s < n ? e.offsetHeight : e.offsetWidth / s,
|
|
103
102
|
e.videoHeight
|
|
104
103
|
),
|
|
105
104
|
width: Math.min(
|
|
106
|
-
|
|
105
|
+
s < n ? e.offsetHeight * s : e.offsetWidth,
|
|
107
106
|
e.videoWidth
|
|
108
107
|
)
|
|
109
108
|
};
|
|
@@ -111,66 +110,75 @@ function b(e) {
|
|
|
111
110
|
return a;
|
|
112
111
|
}
|
|
113
112
|
}
|
|
114
|
-
function
|
|
113
|
+
function z(e) {
|
|
115
114
|
return "BarcodeDetector" in e;
|
|
116
115
|
}
|
|
117
|
-
function
|
|
118
|
-
const i = /scaleX\(-1\)/.test(e.style.transform),
|
|
116
|
+
function X(e, o) {
|
|
117
|
+
const i = /scaleX\(-1\)/.test(e.style.transform), n = _(e), a = M(e, n), s = i ? e.videoWidth - o.x - o.width : o.x, r = o.y;
|
|
119
118
|
return {
|
|
120
|
-
height:
|
|
121
|
-
width:
|
|
122
|
-
x:
|
|
123
|
-
y:
|
|
119
|
+
height: o.height / e.videoHeight * n.height,
|
|
120
|
+
width: o.width / e.videoWidth * n.width,
|
|
121
|
+
x: s / e.videoWidth * n.width + a.x,
|
|
122
|
+
y: r / e.videoHeight * n.height + a.y
|
|
124
123
|
};
|
|
125
124
|
}
|
|
126
|
-
function
|
|
127
|
-
const i = /scaleX\(-1\)/.test(e.style.transform),
|
|
125
|
+
function Y(e, o) {
|
|
126
|
+
const i = /scaleX\(-1\)/.test(e.style.transform), n = _(e), a = M(e, n), s = i ? n.width - (o.x - a.x) - o.width : o.x - a.x, r = o.y - a.y, h = e.videoHeight / n.height, c = e.videoWidth / n.width;
|
|
128
127
|
return {
|
|
129
|
-
height:
|
|
130
|
-
width:
|
|
131
|
-
x:
|
|
132
|
-
y:
|
|
128
|
+
height: o.height * h,
|
|
129
|
+
width: o.width * c,
|
|
130
|
+
x: s * c,
|
|
131
|
+
y: r * h
|
|
133
132
|
};
|
|
134
133
|
}
|
|
135
|
-
function
|
|
136
|
-
return new Promise((
|
|
134
|
+
function $(e) {
|
|
135
|
+
return new Promise((o) => setTimeout(o, e));
|
|
137
136
|
}
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
function G(e, { resolveOnError: o = !1, timeout: i = 1e3 * 8 } = {}) {
|
|
138
|
+
return new Promise((n, a) => {
|
|
139
|
+
const s = setTimeout(() => {
|
|
140
|
+
window.removeEventListener(e, r), o ? n(null) : a(new Error(`Event ${e} not received`));
|
|
141
|
+
}, i), r = () => {
|
|
142
|
+
clearTimeout(s), window.removeEventListener(e, r), n(null);
|
|
143
|
+
};
|
|
144
|
+
window.addEventListener(e, r);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
async function J(e, {
|
|
148
|
+
debug: o,
|
|
140
149
|
formats: i = ["qr_code"],
|
|
141
|
-
getScanArea:
|
|
150
|
+
getScanArea: n = I,
|
|
142
151
|
handleDecodeFailure: a,
|
|
143
|
-
handleDecodeSuccess:
|
|
144
|
-
lifecycle:
|
|
145
|
-
scanRate:
|
|
152
|
+
handleDecodeSuccess: s,
|
|
153
|
+
lifecycle: r = {},
|
|
154
|
+
scanRate: h = 24
|
|
146
155
|
} = {}) {
|
|
147
156
|
if (!(e instanceof HTMLVideoElement))
|
|
148
157
|
throw new Error("video is not a HTMLVideoElement");
|
|
149
|
-
if (!(
|
|
158
|
+
if (!(s instanceof Function))
|
|
150
159
|
throw new Error("handleDecodeSuccess is not a function");
|
|
151
160
|
if (!(a instanceof Function))
|
|
152
161
|
throw new Error("handleDecodeFailure is not a function");
|
|
153
|
-
const c = document.createElement("canvas"),
|
|
154
|
-
if (!
|
|
162
|
+
const c = document.createElement("canvas"), f = c.getContext("2d", { willReadFrequently: !0 });
|
|
163
|
+
if (!f)
|
|
155
164
|
throw new Error("canvas context is not supported");
|
|
156
|
-
const { decode:
|
|
165
|
+
const { decode: E, worker: A } = k({ formats: i }), t = {
|
|
157
166
|
decodeFrameTs: performance.now(),
|
|
158
167
|
isDecodeFrameProcessed: !1,
|
|
159
168
|
isDestroyed: !1,
|
|
160
169
|
isVideoActive: !1,
|
|
161
170
|
isVideoPaused: !1,
|
|
162
171
|
isWorkerLoadFailure: !1,
|
|
163
|
-
scanArea:
|
|
164
|
-
scanRate:
|
|
172
|
+
scanArea: n(e),
|
|
173
|
+
scanRate: h,
|
|
165
174
|
video: e
|
|
166
|
-
},
|
|
167
|
-
t.video.autoplay = !0, t.video.disablePictureInPicture = !0, t.video.hidden = !1, t.video.muted = !0, t.video.playsInline = !0,
|
|
168
|
-
let
|
|
169
|
-
|
|
170
|
-
function S(d, l = () => {
|
|
175
|
+
}, m = { state: t }, D = e.requestVideoFrameCallback?.bind(e) ?? requestAnimationFrame;
|
|
176
|
+
t.video.autoplay = !0, t.video.disablePictureInPicture = !0, t.video.hidden = !1, t.video.muted = !0, t.video.playsInline = !0, r.onCreate && r.onCreate(m);
|
|
177
|
+
let w = null;
|
|
178
|
+
function W(d, g = () => {
|
|
171
179
|
}) {
|
|
172
|
-
D(
|
|
173
|
-
async function
|
|
180
|
+
D(l);
|
|
181
|
+
async function l() {
|
|
174
182
|
if (t.isDestroyed || t.isVideoActive === !1)
|
|
175
183
|
return;
|
|
176
184
|
if (
|
|
@@ -179,10 +187,10 @@ async function K(e, {
|
|
|
179
187
|
t.isDecodeFrameProcessed || // Skip if the video is not ready
|
|
180
188
|
t.video.readyState <= 1
|
|
181
189
|
) {
|
|
182
|
-
D(
|
|
190
|
+
D(l);
|
|
183
191
|
return;
|
|
184
192
|
}
|
|
185
|
-
t.isDecodeFrameProcessed = !0, t.scanArea =
|
|
193
|
+
t.isDecodeFrameProcessed = !0, t.scanArea = n(t.video), r.onBeforeDecode && r.onBeforeDecode(m), c.height = t.scanArea.height, c.width = t.scanArea.width, f.clearRect(0, 0, c.width, c.height), f.drawImage(
|
|
186
194
|
t.video,
|
|
187
195
|
t.scanArea.x,
|
|
188
196
|
t.scanArea.y,
|
|
@@ -193,92 +201,90 @@ async function K(e, {
|
|
|
193
201
|
c.width,
|
|
194
202
|
c.height
|
|
195
203
|
);
|
|
196
|
-
const v =
|
|
197
|
-
|
|
198
|
-
new CustomEvent(
|
|
204
|
+
const v = f.getImageData(0, 0, c.width, c.height);
|
|
205
|
+
o && window.dispatchEvent(
|
|
206
|
+
new CustomEvent(L, {
|
|
199
207
|
detail: {
|
|
200
208
|
imageData: v
|
|
201
209
|
}
|
|
202
210
|
})
|
|
203
211
|
);
|
|
204
212
|
try {
|
|
205
|
-
const
|
|
206
|
-
if (
|
|
207
|
-
const
|
|
208
|
-
height: Math.max(...
|
|
209
|
-
width: Math.max(...
|
|
210
|
-
x: Math.min(...
|
|
211
|
-
y: Math.min(...
|
|
213
|
+
const u = await E(v);
|
|
214
|
+
if (u) {
|
|
215
|
+
const R = u.cornerPoints.map((O) => O.x), p = u.cornerPoints.map((O) => O.y), x = {
|
|
216
|
+
height: Math.max(...p) - Math.min(...p),
|
|
217
|
+
width: Math.max(...R) - Math.min(...R),
|
|
218
|
+
x: Math.min(...R) + t.scanArea.x,
|
|
219
|
+
y: Math.min(...p) + t.scanArea.y
|
|
212
220
|
};
|
|
213
|
-
await Promise.resolve(d(
|
|
221
|
+
await Promise.resolve(d(u.rawValue, x));
|
|
214
222
|
} else
|
|
215
|
-
await Promise.resolve(
|
|
216
|
-
} catch (
|
|
217
|
-
console.warn("Failed to decode barcode"),
|
|
223
|
+
await Promise.resolve(g());
|
|
224
|
+
} catch (u) {
|
|
225
|
+
console.warn("Failed to decode barcode"), u && (console.error(u), u instanceof Error && (u.cause === y || u.cause === S) && (t.isWorkerLoadFailure = !0));
|
|
218
226
|
} finally {
|
|
219
|
-
|
|
227
|
+
r.onDecode && r.onDecode(m), t.isWorkerLoadFailure === !1 && (t.isDecodeFrameProcessed = !1, t.decodeFrameTs = performance.now(), D(l));
|
|
220
228
|
}
|
|
221
229
|
}
|
|
222
230
|
}
|
|
223
|
-
async function
|
|
224
|
-
t.isDestroyed || (await
|
|
231
|
+
async function F() {
|
|
232
|
+
t.isDestroyed || (await T(), A.terminate(), t.isDestroyed = !0);
|
|
225
233
|
}
|
|
226
|
-
async function
|
|
227
|
-
t.isVideoActive === !1 || t.isVideoPaused || t.isDestroyed || (
|
|
228
|
-
const l = setTimeout(() => {
|
|
229
|
-
document.removeEventListener("barcode-scanner:start", u), d(null);
|
|
230
|
-
}, 8e3), u = () => {
|
|
231
|
-
clearTimeout(l), document.removeEventListener("barcode-scanner:start", u), d(null);
|
|
232
|
-
};
|
|
233
|
-
document.addEventListener("barcode-scanner:start", u);
|
|
234
|
-
}), o.onBeforePause && o.onBeforePause(w), t.video.srcObject instanceof MediaStream && (t.video.srcObject.getTracks().forEach((d) => d.stop()), t.video.srcObject = null), t.isVideoPaused = !0, o.onPause && o.onPause(w));
|
|
234
|
+
async function P() {
|
|
235
|
+
t.isVideoActive === !1 || t.isVideoPaused || t.isDestroyed || (w && await w.catch((d) => console.error(d)), r.onBeforePause && r.onBeforePause(m), t.video.srcObject instanceof MediaStream && (t.video.srcObject.getTracks().forEach((d) => d.stop()), t.video.srcObject = null), t.isVideoPaused = !0, r.onPause && r.onPause(m));
|
|
235
236
|
}
|
|
236
|
-
async function
|
|
237
|
+
async function C({
|
|
237
238
|
facingMode: d = "environment",
|
|
238
|
-
...
|
|
239
|
+
...g
|
|
239
240
|
} = {}) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
241
|
+
if (!w)
|
|
242
|
+
return w = (async () => {
|
|
243
|
+
const l = g.handleDecodeSuccess ?? s, v = g.handleDecodeFailure ?? a;
|
|
244
|
+
if (!l)
|
|
245
|
+
throw new Error("handleDecodeSuccess is required");
|
|
246
|
+
if (r.onBeforeStart && r.onBeforeStart(m), !await U())
|
|
247
|
+
throw new Error("No camera access");
|
|
248
|
+
t.video.srcObject instanceof MediaStream || (t.video.srcObject = await navigator.mediaDevices.getUserMedia({
|
|
249
|
+
video: {
|
|
250
|
+
facingMode: d
|
|
251
|
+
}
|
|
252
|
+
}), await t.video.play(), t.isVideoActive = !0, t.isVideoPaused = !1, t.scanArea = n(t.video), t.video.style.transform = d === "user" ? "scaleX(-1)" : "none", r.onStart && r.onStart(m), W(l, v));
|
|
253
|
+
})().finally(() => w = null), w;
|
|
250
254
|
}
|
|
251
|
-
async function
|
|
252
|
-
t.isDestroyed || (
|
|
253
|
-
const l = setTimeout(() => {
|
|
254
|
-
document.removeEventListener("barcode-scanner:start", u), d(null);
|
|
255
|
-
}, 8e3), u = () => {
|
|
256
|
-
clearTimeout(l), document.removeEventListener("barcode-scanner:start", u), d(null);
|
|
257
|
-
};
|
|
258
|
-
document.addEventListener("barcode-scanner:start", u);
|
|
259
|
-
}), o.onBeforeStop && o.onBeforeStop(w), t.video.srcObject instanceof MediaStream && (t.video.srcObject.getTracks().forEach((d) => d.stop()), t.video.srcObject = null), t.isVideoActive = !1, t.isVideoPaused = !1, t.video.poster = "", o.onStop && o.onStop(w));
|
|
255
|
+
async function T() {
|
|
256
|
+
t.isDestroyed || (w && await w.catch((d) => console.error(d)), r.onBeforeStop && r.onBeforeStop(m), t.video.srcObject instanceof MediaStream && (t.video.srcObject.getTracks().forEach((d) => d.stop()), t.video.srcObject = null), t.isVideoActive = !1, t.isVideoPaused = !1, t.video.poster = "", r.onStop && r.onStop(m));
|
|
260
257
|
}
|
|
261
258
|
return {
|
|
262
|
-
decode:
|
|
263
|
-
destroy:
|
|
264
|
-
pause:
|
|
265
|
-
start:
|
|
266
|
-
startCallbackProcessed: E,
|
|
259
|
+
decode: E,
|
|
260
|
+
destroy: F,
|
|
261
|
+
pause: P,
|
|
262
|
+
start: C,
|
|
267
263
|
state: t,
|
|
268
|
-
stop:
|
|
264
|
+
stop: T
|
|
269
265
|
};
|
|
270
266
|
}
|
|
271
267
|
export {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
268
|
+
B as BARCODE_SCANNER_BEFORE_START_EVENT,
|
|
269
|
+
L as BARCODE_SCANNER_DECODE_FRAME_EVENT,
|
|
270
|
+
j as BARCODE_SCANNER_START_EVENT,
|
|
271
|
+
N as WORKER_DECODE_FAILURE_CAUSE,
|
|
272
|
+
K as WORKER_DECODE_TIMEOUT,
|
|
273
|
+
V as WORKER_DECODE_TIMEOUT_CAUSE,
|
|
274
|
+
y as WORKER_LOAD_FAILURE_CAUSE,
|
|
275
|
+
q as WORKER_LOAD_TIMEOUT,
|
|
276
|
+
S as WORKER_LOAD_TIMEOUT_CAUSE,
|
|
277
|
+
J as createBarcodeScanner,
|
|
278
|
+
k as createWorker,
|
|
279
|
+
J as default,
|
|
280
|
+
U as getCameraAccess,
|
|
276
281
|
I as getScanArea,
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
282
|
+
M as getVideoRenderOffset,
|
|
283
|
+
_ as getVideoRenderSize,
|
|
284
|
+
H as hasCameraAccess,
|
|
285
|
+
z as isBarcodeDetectorAvailable,
|
|
286
|
+
X as translateAreaToVideoRender,
|
|
287
|
+
Y as translateAreaToVideoSource,
|
|
288
|
+
$ as wait,
|
|
289
|
+
G as waitForEvent
|
|
284
290
|
};
|