@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.
Files changed (2) hide show
  1. package/dist/index.js +25 -25
  2. 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", 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)));
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", h), o.postMessage({
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, h) => {
24
+ return new Promise((r, u) => {
25
25
  const c = setTimeout(() => {
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));
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, h = e.videoHeight / n.height, c = e.videoWidth / n.width;
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 * h,
128
+ height: o.height * u,
129
129
  width: o.width * c,
130
130
  x: s * c,
131
- y: r * h
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: h = 24
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: E, worker: A } = k({ formats: i }), t = {
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: h,
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, g = () => {
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 u = await E(v);
214
- if (u) {
215
- const R = u.cornerPoints.map((O) => O.x), p = u.cornerPoints.map((O) => O.y), x = {
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(u.rawValue, x));
221
+ await Promise.resolve(d(h.rawValue, x));
222
222
  } else
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));
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
- ...g
239
+ ...E
240
240
  } = {}) {
241
241
  if (!w)
242
242
  return w = (async () => {
243
- const l = g.handleDecodeSuccess ?? s, v = g.handleDecodeFailure ?? a;
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: E,
259
+ decode: g,
260
260
  destroy: F,
261
261
  pause: P,
262
262
  start: C,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nddeps/barcode-scanner",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "barcode",