@nddeps/barcode-scanner 0.6.1 → 0.6.2
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.js +25 -25
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,11 +6,11 @@ function k({ formats: e }) {
|
|
|
6
6
|
import.meta.url
|
|
7
7
|
), { type: "module" }), i = new Promise((a, s) => {
|
|
8
8
|
const r = setTimeout(() => {
|
|
9
|
-
o.removeEventListener("message",
|
|
10
|
-
}, 32e3),
|
|
11
|
-
f === "init" && (clearTimeout(r), o.removeEventListener("message",
|
|
9
|
+
o.removeEventListener("message", u), s(new Error(S));
|
|
10
|
+
}, 32e3), u = ({ data: { payload: c, type: f } }) => {
|
|
11
|
+
f === "init" && (clearTimeout(r), o.removeEventListener("message", u), c.status === "success" ? a(!0) : s(new Error(y)));
|
|
12
12
|
};
|
|
13
|
-
o.addEventListener("message",
|
|
13
|
+
o.addEventListener("message", u), o.postMessage({
|
|
14
14
|
payload: {
|
|
15
15
|
formats: e,
|
|
16
16
|
wasmUrl: b
|
|
@@ -21,11 +21,11 @@ function k({ formats: e }) {
|
|
|
21
21
|
async function n(a) {
|
|
22
22
|
await i;
|
|
23
23
|
const s = `${performance.now()}-${Math.random().toString(36).slice(2)}`;
|
|
24
|
-
return new Promise((r,
|
|
24
|
+
return new Promise((r, u) => {
|
|
25
25
|
const c = setTimeout(() => {
|
|
26
|
-
o.removeEventListener("message", f),
|
|
27
|
-
}, 16e3), f = ({ data: { payload:
|
|
28
|
-
A !== "decode" ||
|
|
26
|
+
o.removeEventListener("message", f), u(new Error(V));
|
|
27
|
+
}, 16e3), f = ({ data: { payload: g, type: A } }) => {
|
|
28
|
+
A !== "decode" || g.uuid !== s || (clearTimeout(c), o.removeEventListener("message", f), r(g.data));
|
|
29
29
|
};
|
|
30
30
|
o.addEventListener("message", f), o.postMessage({
|
|
31
31
|
payload: {
|
|
@@ -123,12 +123,12 @@ function X(e, o) {
|
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
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,
|
|
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, u = e.videoHeight / n.height, c = e.videoWidth / n.width;
|
|
127
127
|
return {
|
|
128
|
-
height: o.height *
|
|
128
|
+
height: o.height * u,
|
|
129
129
|
width: o.width * c,
|
|
130
130
|
x: s * c,
|
|
131
|
-
y: r *
|
|
131
|
+
y: r * u
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
134
|
function $(e) {
|
|
@@ -151,7 +151,7 @@ async function J(e, {
|
|
|
151
151
|
handleDecodeFailure: a,
|
|
152
152
|
handleDecodeSuccess: s,
|
|
153
153
|
lifecycle: r = {},
|
|
154
|
-
scanRate:
|
|
154
|
+
scanRate: u = 24
|
|
155
155
|
} = {}) {
|
|
156
156
|
if (!(e instanceof HTMLVideoElement))
|
|
157
157
|
throw new Error("video is not a HTMLVideoElement");
|
|
@@ -162,7 +162,7 @@ async function J(e, {
|
|
|
162
162
|
const c = document.createElement("canvas"), f = c.getContext("2d", { willReadFrequently: !0 });
|
|
163
163
|
if (!f)
|
|
164
164
|
throw new Error("canvas context is not supported");
|
|
165
|
-
const { decode:
|
|
165
|
+
const { decode: g, worker: A } = k({ formats: i }), t = {
|
|
166
166
|
decodeFrameTs: performance.now(),
|
|
167
167
|
isDecodeFrameProcessed: !1,
|
|
168
168
|
isDestroyed: !1,
|
|
@@ -170,12 +170,12 @@ async function J(e, {
|
|
|
170
170
|
isVideoPaused: !1,
|
|
171
171
|
isWorkerLoadFailure: !1,
|
|
172
172
|
scanArea: n(e),
|
|
173
|
-
scanRate:
|
|
173
|
+
scanRate: u,
|
|
174
174
|
video: e
|
|
175
175
|
}, m = { state: t }, D = e.requestVideoFrameCallback?.bind(e) ?? requestAnimationFrame;
|
|
176
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
177
|
let w = null;
|
|
178
|
-
function W(d,
|
|
178
|
+
function W(d, E = () => {
|
|
179
179
|
}) {
|
|
180
180
|
D(l);
|
|
181
181
|
async function l() {
|
|
@@ -210,19 +210,19 @@ async function J(e, {
|
|
|
210
210
|
})
|
|
211
211
|
);
|
|
212
212
|
try {
|
|
213
|
-
const
|
|
214
|
-
if (
|
|
215
|
-
const R =
|
|
213
|
+
const h = await g(v);
|
|
214
|
+
if (h) {
|
|
215
|
+
const R = h.cornerPoints.map((O) => O.x), p = h.cornerPoints.map((O) => O.y), x = {
|
|
216
216
|
height: Math.max(...p) - Math.min(...p),
|
|
217
217
|
width: Math.max(...R) - Math.min(...R),
|
|
218
218
|
x: Math.min(...R) + t.scanArea.x,
|
|
219
219
|
y: Math.min(...p) + t.scanArea.y
|
|
220
220
|
};
|
|
221
|
-
await Promise.resolve(d(
|
|
221
|
+
await Promise.resolve(d(h.rawValue, x));
|
|
222
222
|
} else
|
|
223
|
-
await Promise.resolve(
|
|
224
|
-
} catch (
|
|
225
|
-
console.warn("Failed to decode barcode"),
|
|
223
|
+
await Promise.resolve(E());
|
|
224
|
+
} catch (h) {
|
|
225
|
+
console.warn("Failed to decode barcode"), h && (console.error(h), h instanceof Error && (h.message === y || h.message === S) && (t.isWorkerLoadFailure = !0));
|
|
226
226
|
} finally {
|
|
227
227
|
r.onDecode && r.onDecode(m), t.isWorkerLoadFailure === !1 && (t.isDecodeFrameProcessed = !1, t.decodeFrameTs = performance.now(), D(l));
|
|
228
228
|
}
|
|
@@ -236,11 +236,11 @@ async function J(e, {
|
|
|
236
236
|
}
|
|
237
237
|
async function C({
|
|
238
238
|
facingMode: d = "environment",
|
|
239
|
-
...
|
|
239
|
+
...E
|
|
240
240
|
} = {}) {
|
|
241
241
|
if (!w)
|
|
242
242
|
return w = (async () => {
|
|
243
|
-
const l =
|
|
243
|
+
const l = E.handleDecodeSuccess ?? s, v = E.handleDecodeFailure ?? a;
|
|
244
244
|
if (!l)
|
|
245
245
|
throw new Error("handleDecodeSuccess is required");
|
|
246
246
|
if (r.onBeforeStart && r.onBeforeStart(m), !await U())
|
|
@@ -256,7 +256,7 @@ async function J(e, {
|
|
|
256
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));
|
|
257
257
|
}
|
|
258
258
|
return {
|
|
259
|
-
decode:
|
|
259
|
+
decode: g,
|
|
260
260
|
destroy: F,
|
|
261
261
|
pause: P,
|
|
262
262
|
start: C,
|