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