@nddeps/barcode-scanner 0.4.0 → 0.4.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.
@@ -12,10 +12,9 @@ type State = {
12
12
  scanRate: number;
13
13
  video: HTMLVideoElement;
14
14
  };
15
- declare function createBarcodeScanner(video: HTMLVideoElement, { getScanArea, debug, scanRate, handleDecodeFailure, handleDecodeSuccess, lifecycle, }?: {
16
- getScanArea?: (video: HTMLVideoElement) => ScanArea;
17
- scanRate?: number;
15
+ declare function createBarcodeScanner(video: HTMLVideoElement, { debug, getScanArea, handleDecodeFailure, handleDecodeSuccess, lifecycle, scanRate, }?: {
18
16
  debug?: boolean;
17
+ getScanArea?: (video: HTMLVideoElement) => ScanArea;
19
18
  handleDecodeFailure?: DecodeFailureHandler;
20
19
  handleDecodeSuccess?: DecodeSuccessHandler;
21
20
  lifecycle?: {
@@ -28,6 +27,7 @@ declare function createBarcodeScanner(video: HTMLVideoElement, { getScanArea, de
28
27
  onStart?: LifecycleHook;
29
28
  onStop?: LifecycleHook;
30
29
  };
30
+ scanRate?: number;
31
31
  }): Promise<{
32
32
  destroy: () => void;
33
33
  pause: () => Promise<void>;
@@ -1,60 +1,60 @@
1
1
  function x(t) {
2
- const o = new EventTarget(), c = new Proxy(t, {
3
- get(n, r, i) {
4
- return Reflect.get(n, r, i);
2
+ const r = new EventTarget(), a = new Proxy(t, {
3
+ get(i, o, c) {
4
+ return Reflect.get(i, o, c);
5
5
  },
6
- set(n, r, i, s) {
7
- const d = Reflect.set(n, r, i, s);
8
- return o.dispatchEvent(new CustomEvent("change")), d;
6
+ set(i, o, c, s) {
7
+ const d = Reflect.set(i, o, c, s);
8
+ return r.dispatchEvent(new CustomEvent("change")), d;
9
9
  }
10
10
  });
11
- function a(n, r) {
12
- let i = n();
11
+ function n(i, o) {
12
+ let c = i();
13
13
  function s() {
14
- const d = n();
15
- JSON.stringify(d) !== JSON.stringify(i) && (i = d, r(d));
14
+ const d = i();
15
+ JSON.stringify(d) !== JSON.stringify(c) && (c = d, o(d));
16
16
  }
17
- return o.addEventListener("change", s), () => o.removeEventListener("change", s);
17
+ return r.addEventListener("change", s), () => r.removeEventListener("change", s);
18
18
  }
19
19
  return {
20
- state: c,
21
- watch: a
20
+ state: a,
21
+ watch: n
22
22
  };
23
23
  }
24
- function F() {
24
+ const O = 1e3 * 32, F = 1e3 * 16;
25
+ function T() {
25
26
  const t = new Worker(new URL(
26
27
  /* @vite-ignore */
27
- "" + new URL("worker-BTT4rwmP.js", import.meta.url).href,
28
+ "" + new URL("worker.js", import.meta.url).href,
28
29
  import.meta.url
29
- ), { type: "module" }), o = new Promise((a, n) => {
30
- const r = setTimeout(() => n(new Error("Worker load timeout")), 16e3);
30
+ ), { type: "module" }), r = new Promise((n, i) => {
31
+ const o = setTimeout(() => {
32
+ i(new Error("Worker load timeout"));
33
+ }, O);
31
34
  t.addEventListener(
32
35
  "message",
33
- ({
34
- data: { payload: i, type: s }
35
- }) => {
36
- s === "message" && (clearTimeout(r), i.status === "success" ? a(!0) : n(new Error("Worker failed to load")));
36
+ ({ data: { payload: c, type: s } }) => {
37
+ s === "init" && (clearTimeout(o), c.status === "success" ? n(!0) : i(new Error("Worker failed to load")));
37
38
  },
38
39
  {
39
40
  once: !0
40
41
  }
41
42
  );
42
43
  });
43
- async function c(a) {
44
- await o;
45
- const n = `${performance.now()}-${Math.random().toString(36).slice(2)}`;
46
- return new Promise((r, i) => {
47
- let s = 0;
48
- const d = ({ data: { payload: w, type: g } }) => {
49
- g !== "decode" || w.uuid !== n || (clearTimeout(s), t.removeEventListener("message", d), r(w.data));
44
+ async function a(n) {
45
+ await r;
46
+ const i = `${performance.now()}-${Math.random().toString(36).slice(2)}`;
47
+ return new Promise((o, c) => {
48
+ const s = setTimeout(() => {
49
+ t.removeEventListener("message", d), c(new Error("Decode timeout"));
50
+ }, F), d = ({ data: { payload: w, type: g } }) => {
51
+ g !== "decode" || w.uuid !== i || (clearTimeout(s), t.removeEventListener("message", d), o(w.data));
50
52
  };
51
- s = setTimeout(() => {
52
- t.removeEventListener("message", d), i(new Error("Decode timeout"));
53
- }, 1e3 * 6), t.addEventListener("message", d), t.postMessage({ payload: { data: a, uuid: n }, type: "decode" });
53
+ t.addEventListener("message", d), t.postMessage({ payload: { data: n, uuid: i }, type: "decode" });
54
54
  });
55
55
  }
56
56
  return {
57
- decode: c,
57
+ decode: a,
58
58
  worker: t
59
59
  };
60
60
  }
@@ -62,126 +62,126 @@ async function V() {
62
62
  try {
63
63
  return (await navigator.permissions.query({ name: "camera" })).state === "granted";
64
64
  } catch {
65
- return (await navigator.mediaDevices.enumerateDevices()).filter((c) => c.deviceId && c.kind === "videoinput").length > 0;
65
+ return (await navigator.mediaDevices.enumerateDevices()).filter((a) => a.deviceId && a.kind === "videoinput").length > 0;
66
66
  }
67
67
  }
68
68
  async function H() {
69
69
  if (await V())
70
70
  return !0;
71
71
  try {
72
- const o = (await navigator.mediaDevices.getUserMedia({ video: !0 })).getTracks();
73
- for (const c of o)
74
- c.stop();
72
+ const r = (await navigator.mediaDevices.getUserMedia({ video: !0 })).getTracks();
73
+ for (const a of r)
74
+ a.stop();
75
75
  return !0;
76
76
  } catch {
77
77
  return !1;
78
78
  }
79
79
  }
80
- function T(t) {
81
- const o = Math.round(0.6666666666666666 * Math.min(t.videoWidth, t.videoHeight));
80
+ function k(t) {
81
+ const r = Math.round(0.6666666666666666 * Math.min(t.videoWidth, t.videoHeight));
82
82
  return {
83
- height: o,
84
- width: o,
85
- x: Math.round((t.videoWidth - o) / 2),
86
- y: Math.round((t.videoHeight - o) / 2)
83
+ height: r,
84
+ width: r,
85
+ x: Math.round((t.videoWidth - r) / 2),
86
+ y: Math.round((t.videoHeight - r) / 2)
87
87
  };
88
88
  }
89
- function D(t, o) {
90
- const c = window.getComputedStyle(t), [a, n] = c.objectPosition.split(" ").map(
91
- (r, i) => r.endsWith("%") ? (i === 0 ? t.offsetWidth - o.width : t.offsetHeight - o.height) * parseFloat(r) / 100 : parseFloat(r)
89
+ function A(t, r) {
90
+ const a = window.getComputedStyle(t), [n, i] = a.objectPosition.split(" ").map(
91
+ (o, c) => o.endsWith("%") ? (c === 0 ? t.offsetWidth - r.width : t.offsetHeight - r.height) * parseFloat(o) / 100 : parseFloat(o)
92
92
  );
93
93
  return {
94
- x: a,
95
- y: n
94
+ x: n,
95
+ y: i
96
96
  };
97
97
  }
98
- function S(t) {
99
- const o = window.getComputedStyle(t), c = { height: t.offsetHeight, width: t.offsetWidth }, a = c.width / c.height, n = { height: t.videoHeight, width: t.videoWidth }, r = n.width / n.height;
100
- switch (o.objectFit) {
98
+ function W(t) {
99
+ const r = window.getComputedStyle(t), a = { height: t.offsetHeight, width: t.offsetWidth }, n = a.width / a.height, i = { height: t.videoHeight, width: t.videoWidth }, o = i.width / i.height;
100
+ switch (r.objectFit) {
101
101
  case "contain":
102
102
  return {
103
- height: r < a ? t.offsetHeight : t.offsetWidth / r,
104
- width: r < a ? t.offsetHeight * r : t.offsetWidth
103
+ height: o < n ? t.offsetHeight : t.offsetWidth / o,
104
+ width: o < n ? t.offsetHeight * o : t.offsetWidth
105
105
  };
106
106
  case "cover":
107
107
  return {
108
- height: r > a ? t.offsetHeight : t.offsetWidth / r,
109
- width: r > a ? t.offsetHeight * r : t.offsetWidth
108
+ height: o > n ? t.offsetHeight : t.offsetWidth / o,
109
+ width: o > n ? t.offsetHeight * o : t.offsetWidth
110
110
  };
111
111
  case "fill":
112
- return c;
112
+ return a;
113
113
  case "none":
114
- return n;
114
+ return i;
115
115
  case "scale-down":
116
116
  return {
117
117
  height: Math.min(
118
- r < a ? t.offsetHeight : t.offsetWidth / r,
118
+ o < n ? t.offsetHeight : t.offsetWidth / o,
119
119
  t.videoHeight
120
120
  ),
121
121
  width: Math.min(
122
- r < a ? t.offsetHeight * r : t.offsetWidth,
122
+ o < n ? t.offsetHeight * o : t.offsetWidth,
123
123
  t.videoWidth
124
124
  )
125
125
  };
126
126
  default:
127
- return n;
127
+ return i;
128
128
  }
129
129
  }
130
- function k(t) {
130
+ function L(t) {
131
131
  return "BarcodeDetector" in t;
132
132
  }
133
- function L(t, o) {
134
- const c = /scaleX\(-1\)/.test(t.style.transform), a = S(t), n = D(t, a), r = c ? t.videoWidth - o.x - o.width : o.x, i = o.y;
133
+ function j(t, r) {
134
+ const a = /scaleX\(-1\)/.test(t.style.transform), n = W(t), i = A(t, n), o = a ? t.videoWidth - r.x - r.width : r.x, c = r.y;
135
135
  return {
136
- height: o.height / t.videoHeight * a.height,
137
- width: o.width / t.videoWidth * a.width,
138
- x: r / t.videoWidth * a.width + n.x,
139
- y: i / t.videoHeight * a.height + n.y
136
+ height: r.height / t.videoHeight * n.height,
137
+ width: r.width / t.videoWidth * n.width,
138
+ x: o / t.videoWidth * n.width + i.x,
139
+ y: c / t.videoHeight * n.height + i.y
140
140
  };
141
141
  }
142
- function O(t, o) {
143
- const c = /scaleX\(-1\)/.test(t.style.transform), a = S(t), n = D(t, a), r = c ? a.width - (o.x - n.x) - o.width : o.x - n.x, i = o.y - n.y, s = t.videoHeight / a.height, d = t.videoWidth / a.width;
142
+ function C(t, r) {
143
+ const a = /scaleX\(-1\)/.test(t.style.transform), n = W(t), i = A(t, n), o = a ? n.width - (r.x - i.x) - r.width : r.x - i.x, c = r.y - i.y, s = t.videoHeight / n.height, d = t.videoWidth / n.width;
144
144
  return {
145
- height: o.height * s,
146
- width: o.width * d,
147
- x: r * d,
148
- y: i * s
145
+ height: r.height * s,
146
+ width: r.width * d,
147
+ x: o * d,
148
+ y: c * s
149
149
  };
150
150
  }
151
- function j(t) {
152
- return new Promise((o) => setTimeout(o, t));
151
+ function U(t) {
152
+ return new Promise((r) => setTimeout(r, t));
153
153
  }
154
154
  async function B(t, {
155
- getScanArea: o = T,
156
- debug: c,
157
- scanRate: a = 24,
155
+ debug: r,
156
+ getScanArea: a = k,
158
157
  handleDecodeFailure: n = () => {
159
158
  },
160
- handleDecodeSuccess: r = () => {
159
+ handleDecodeSuccess: i = () => {
161
160
  },
162
- lifecycle: i = {}
161
+ lifecycle: o = {},
162
+ scanRate: c = 24
163
163
  } = {}) {
164
164
  if (!(t instanceof HTMLVideoElement))
165
165
  throw new Error("video is not a HTMLVideoElement");
166
- if (!(r instanceof Function))
166
+ if (!(i instanceof Function))
167
167
  throw new Error("handleDecodeSuccess is not a function");
168
168
  if (!(n instanceof Function))
169
169
  throw new Error("handleDecodeFailure is not a function");
170
170
  const s = document.createElement("canvas"), d = s.getContext("2d", { willReadFrequently: !0 });
171
171
  if (!d)
172
172
  throw new Error("canvas context is not supported");
173
- const { decode: w, worker: g } = F(), { state: e } = x({
173
+ const { decode: w, worker: g } = T(), { state: e } = x({
174
174
  decodeFrameTs: performance.now(),
175
175
  isDecodeFrameProcessed: !1,
176
176
  isDestroyed: !1,
177
177
  isVideoActive: !1,
178
178
  isVideoPaused: !1,
179
- scanArea: o(t),
180
- scanRate: a,
179
+ scanArea: a(t),
180
+ scanRate: c,
181
181
  video: t
182
182
  }), v = t.requestVideoFrameCallback?.bind(t) ?? requestAnimationFrame;
183
- e.video.autoplay = !0, e.video.disablePictureInPicture = !0, e.video.hidden = !1, e.video.muted = !0, e.video.playsInline = !0, i.onCreate && i.onCreate.call(e);
184
- function W(h, u) {
183
+ e.video.autoplay = !0, e.video.disablePictureInPicture = !0, e.video.hidden = !1, e.video.muted = !0, e.video.playsInline = !0, o.onCreate && o.onCreate.call(e);
184
+ function b(h, u) {
185
185
  v(m);
186
186
  async function m() {
187
187
  if (e.isDestroyed || e.isVideoActive === !1)
@@ -195,7 +195,7 @@ async function B(t, {
195
195
  v(m);
196
196
  return;
197
197
  }
198
- e.isDecodeFrameProcessed = !0, e.scanArea = o(e.video), i.onBeforeDecode && i.onBeforeDecode.call(e), s.height = e.scanArea.height, s.width = e.scanArea.width, d.clearRect(0, 0, s.width, s.height), d.drawImage(
198
+ e.isDecodeFrameProcessed = !0, e.scanArea = a(e.video), o.onBeforeDecode && o.onBeforeDecode.call(e), s.height = e.scanArea.height, s.width = e.scanArea.width, d.clearRect(0, 0, s.width, s.height), d.drawImage(
199
199
  e.video,
200
200
  e.scanArea.x,
201
201
  e.scanArea.y,
@@ -207,7 +207,7 @@ async function B(t, {
207
207
  s.height
208
208
  );
209
209
  const l = d.getImageData(0, 0, s.width, s.height);
210
- c && window.dispatchEvent(
210
+ r && window.dispatchEvent(
211
211
  new CustomEvent("barcode-scanner:decode-frame", {
212
212
  detail: {
213
213
  imageData: l
@@ -217,26 +217,26 @@ async function B(t, {
217
217
  try {
218
218
  const f = await w(l);
219
219
  if (f) {
220
- const p = f.cornerPoints.map((b) => b.x), y = f.cornerPoints.map((b) => b.y), R = {
220
+ const p = f.cornerPoints.map((E) => E.x), y = f.cornerPoints.map((E) => E.y), P = {
221
221
  height: Math.max(...y) - Math.min(...y),
222
222
  width: Math.max(...p) - Math.min(...p),
223
223
  x: Math.min(...p) + e.scanArea.x,
224
224
  y: Math.min(...y) + e.scanArea.y
225
225
  };
226
- await Promise.resolve(h.call(e, f.rawValue, R));
226
+ await Promise.resolve(h.call(e, f.rawValue, P));
227
227
  } else
228
228
  await Promise.resolve(u.call(e));
229
229
  } catch (f) {
230
230
  console.warn("Failed to decode barcode"), f && console.error(f);
231
231
  } finally {
232
- i.onDecode && i.onDecode.call(e), e.decodeFrameTs = performance.now(), e.isDecodeFrameProcessed = !1, v(m);
232
+ o.onDecode && o.onDecode.call(e), e.decodeFrameTs = performance.now(), e.isDecodeFrameProcessed = !1, v(m);
233
233
  }
234
234
  }
235
235
  }
236
- function E() {
237
- e.isDestroyed || (A(), g.terminate(), e.isDestroyed = !0);
236
+ function R() {
237
+ e.isDestroyed || (D(), g.terminate(), e.isDestroyed = !0);
238
238
  }
239
- async function P() {
239
+ async function S() {
240
240
  if (e.isVideoActive === !1 || e.isVideoPaused || e.isDestroyed)
241
241
  return;
242
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);
@@ -255,35 +255,35 @@ async function B(t, {
255
255
  facingMode: h = "environment",
256
256
  ...u
257
257
  } = {}) {
258
- if (i.onBeforeStart && i.onBeforeStart.call(e), !await H())
258
+ if (o.onBeforeStart && o.onBeforeStart.call(e), !await H())
259
259
  throw new Error("No camera access");
260
260
  e.video.srcObject instanceof MediaStream || (e.video.srcObject = await navigator.mediaDevices.getUserMedia({
261
261
  video: {
262
262
  facingMode: h
263
263
  }
264
- }), await e.video.play(), e.isVideoActive = !0, e.isVideoPaused = !1, e.scanArea = o(e.video), e.video.style.transform = h === "user" ? "scaleX(-1)" : "none", i.onStart && i.onStart.call(e), W(u.handleDecodeSuccess ?? r, u.handleDecodeFailure ?? n));
264
+ }), await e.video.play(), e.isVideoActive = !0, e.isVideoPaused = !1, e.scanArea = a(e.video), e.video.style.transform = h === "user" ? "scaleX(-1)" : "none", o.onStart && o.onStart.call(e), b(u.handleDecodeSuccess ?? i, u.handleDecodeFailure ?? n));
265
265
  }
266
- async function A() {
267
- e.isVideoActive === !1 || e.isDestroyed || (i.onBeforeStop && i.onBeforeStop.call(e), e.video.srcObject instanceof MediaStream && e.video.srcObject.getTracks().forEach((h) => h.stop()), e.video.poster.startsWith("blob:") && URL.revokeObjectURL(e.video.poster), e.isVideoActive = !1, e.isVideoPaused = !1, e.video.poster = "", e.video.srcObject = null, i.onStop && i.onStop.call(e));
266
+ async function D() {
267
+ e.isVideoActive === !1 || e.isDestroyed || (o.onBeforeStop && o.onBeforeStop.call(e), e.video.srcObject instanceof MediaStream && e.video.srcObject.getTracks().forEach((h) => h.stop()), e.video.poster.startsWith("blob:") && URL.revokeObjectURL(e.video.poster), e.isVideoActive = !1, e.isVideoPaused = !1, e.video.poster = "", e.video.srcObject = null, o.onStop && o.onStop.call(e));
268
268
  }
269
269
  return {
270
- destroy: E,
271
- pause: P,
270
+ destroy: R,
271
+ pause: S,
272
272
  start: M,
273
273
  state: e,
274
- stop: A
274
+ stop: D
275
275
  };
276
276
  }
277
277
  export {
278
278
  B as createBarcodeScanner,
279
279
  B as default,
280
280
  H as getCameraAccess,
281
- T as getScanArea,
282
- D as getVideoRenderOffset,
283
- S as getVideoRenderSize,
281
+ k as getScanArea,
282
+ A as getVideoRenderOffset,
283
+ W as getVideoRenderSize,
284
284
  V as hasCameraAccess,
285
- k as isBarcodeDetectorAvailable,
286
- L as translateAreaToVideoRender,
287
- O as translateAreaToVideoSource,
288
- j as wait
285
+ L as isBarcodeDetectorAvailable,
286
+ j as translateAreaToVideoRender,
287
+ C as translateAreaToVideoSource,
288
+ U as wait
289
289
  };
@@ -59,7 +59,7 @@ const lC = [
59
59
  function VC(Q) {
60
60
  return lC.indexOf(Q);
61
61
  }
62
- const mI = [
62
+ const TI = [
63
63
  "Unknown",
64
64
  "ASCII",
65
65
  "ISO8859_1",
@@ -99,10 +99,10 @@ const mI = [
99
99
  "UTF32LE",
100
100
  "BINARY"
101
101
  ];
102
- function mC(Q) {
103
- return Q === "UnicodeBig" ? mI.indexOf("UTF16BE") : mI.indexOf(Q);
102
+ function TC(Q) {
103
+ return Q === "UnicodeBig" ? TI.indexOf("UTF16BE") : TI.indexOf(Q);
104
104
  }
105
- const TC = [
105
+ const mC = [
106
106
  "Text",
107
107
  "Binary",
108
108
  "Mixed",
@@ -111,7 +111,7 @@ const TC = [
111
111
  "UnknownECI"
112
112
  ];
113
113
  function fC(Q) {
114
- return TC[Q];
114
+ return mC[Q];
115
115
  }
116
116
  const nC = ["Ignore", "Read", "Require"];
117
117
  function xC(Q) {
@@ -140,14 +140,14 @@ const zA = {
140
140
  textMode: "HRI",
141
141
  characterSet: "Unknown"
142
142
  };
143
- function TI(Q) {
143
+ function mI(Q) {
144
144
  return {
145
145
  ...Q,
146
146
  formats: pC(Q.formats),
147
147
  binarizer: VC(Q.binarizer),
148
148
  eanAddOnSymbol: xC(Q.eanAddOnSymbol),
149
149
  textMode: jC(Q.textMode),
150
- characterSet: mC(Q.characterSet)
150
+ characterSet: TC(Q.characterSet)
151
151
  };
152
152
  }
153
153
  function OC(Q) {
@@ -206,7 +206,7 @@ async function uC(Q, o, F = zA) {
206
206
  q,
207
207
  V,
208
208
  j,
209
- TI(S)
209
+ mI(S)
210
210
  );
211
211
  } else {
212
212
  let J, P;
@@ -221,7 +221,7 @@ async function uC(Q, o, F = zA) {
221
221
  q = M._malloc(J), M.HEAPU8.set(P, q), z = M.readBarcodesFromImage(
222
222
  q,
223
223
  J,
224
- TI(S)
224
+ mI(S)
225
225
  );
226
226
  }
227
227
  M._free(q);
@@ -261,10 +261,10 @@ async function OI(Q = {}) {
261
261
  throw new Error(I.status + " : " + I.url);
262
262
  };
263
263
  }
264
- var CA = console.log.bind(console), m = console.error.bind(console), b, MA = !1, $A, _A, X, T, FA, QA, EA, K, AI, II, gI = !1;
264
+ var CA = console.log.bind(console), T = console.error.bind(console), b, MA = !1, $A, _A, X, m, FA, QA, EA, K, AI, II, gI = !1;
265
265
  function BI() {
266
266
  var A = hA.buffer;
267
- X = new Int8Array(A), FA = new Int16Array(A), M.HEAPU8 = T = new Uint8Array(A), QA = new Uint16Array(A), EA = new Int32Array(A), K = new Uint32Array(A), AI = new Float32Array(A), II = new Float64Array(A);
267
+ X = new Int8Array(A), FA = new Int16Array(A), M.HEAPU8 = m = new Uint8Array(A), QA = new Uint16Array(A), EA = new Int32Array(A), K = new Uint32Array(A), AI = new Float32Array(A), II = new Float64Array(A);
268
268
  }
269
269
  function Cg() {
270
270
  if (M.preRun)
@@ -283,7 +283,7 @@ async function OI(Q = {}) {
283
283
  }
284
284
  function WA(A) {
285
285
  var I, g;
286
- (I = M.onAbort) === null || I === void 0 || I.call(M, A), A = "Aborted(" + A + ")", m(A), MA = !0, A += ". Build with -sASSERTIONS for more info.";
286
+ (I = M.onAbort) === null || I === void 0 || I.call(M, A), A = "Aborted(" + A + ")", T(A), MA = !0, A += ". Build with -sASSERTIONS for more info.";
287
287
  var B = new WebAssembly.RuntimeError(A);
288
288
  throw (g = _A) === null || g === void 0 || g(B), B;
289
289
  }
@@ -312,7 +312,7 @@ async function OI(Q = {}) {
312
312
  var g = await ig(A), B = await WebAssembly.instantiate(g, I);
313
313
  return B;
314
314
  } catch (C) {
315
- m(`failed to asynchronously prepare wasm: ${C}`), WA(C);
315
+ T(`failed to asynchronously prepare wasm: ${C}`), WA(C);
316
316
  }
317
317
  }
318
318
  async function Ng(A, I, g) {
@@ -323,7 +323,7 @@ async function OI(Q = {}) {
323
323
  }), C = await WebAssembly.instantiateStreaming(B, g);
324
324
  return C;
325
325
  } catch (E) {
326
- m(`wasm streaming compile failed: ${E}`), m("falling back to ArrayBuffer instantiation");
326
+ T(`wasm streaming compile failed: ${E}`), T("falling back to ArrayBuffer instantiation");
327
327
  }
328
328
  return og(I, g);
329
329
  }
@@ -505,7 +505,7 @@ async function OI(Q = {}) {
505
505
  }, ag = (A, I, g, B, C) => {
506
506
  }, W = (A) => {
507
507
  for (var I = ""; ; ) {
508
- var g = T[A++];
508
+ var g = m[A++];
509
509
  if (!g) return I;
510
510
  I += String.fromCharCode(g);
511
511
  }
@@ -543,7 +543,7 @@ async function OI(Q = {}) {
543
543
  return E ? g : B;
544
544
  },
545
545
  readValueFromPointer: function(C) {
546
- return this.fromWireType(T[C]);
546
+ return this.fromWireType(m[C]);
547
547
  },
548
548
  destructorFunction: null
549
549
  });
@@ -617,7 +617,7 @@ async function OI(Q = {}) {
617
617
  };
618
618
  function SA() {
619
619
  }
620
- var mA = (A, I) => Object.defineProperty(I, "name", {
620
+ var TA = (A, I) => Object.defineProperty(I, "name", {
621
621
  value: A
622
622
  }), iI = {}, oI = (A, I, g) => {
623
623
  if (A[I].overloadTable === void 0) {
@@ -638,7 +638,7 @@ async function OI(Q = {}) {
638
638
  function pg(A, I, g, B, C, E, D, w) {
639
639
  this.name = A, this.constructor = I, this.instancePrototype = g, this.rawDestructor = B, this.baseClass = C, this.getActualType = E, this.upcast = D, this.downcast = w, this.pureVirtualFunctions = [];
640
640
  }
641
- var TA = (A, I, g) => {
641
+ var mA = (A, I, g) => {
642
642
  for (; I !== g; )
643
643
  I.upcast || s(`Expected null or instance of ${g.name}, got an instance of ${I.name}`), A = I.upcast(A), I = I.baseClass;
644
644
  return A;
@@ -652,7 +652,7 @@ async function OI(Q = {}) {
652
652
  if (I === null)
653
653
  return this.isReference && s(`null is not a valid ${this.name}`), 0;
654
654
  I.$$ || s(`Cannot pass "${fA(I)}" as a ${this.name}`), I.$$.ptr || s(`Cannot pass deleted object as a pointer of type ${this.name}`);
655
- var g = I.$$.ptrType.registeredClass, B = TA(I.$$.ptr, g, this.registeredClass);
655
+ var g = I.$$.ptrType.registeredClass, B = mA(I.$$.ptr, g, this.registeredClass);
656
656
  return B;
657
657
  }
658
658
  function Vg(A, I) {
@@ -661,7 +661,7 @@ async function OI(Q = {}) {
661
661
  return this.isReference && s(`null is not a valid ${this.name}`), this.isSmartPointer ? (g = this.rawConstructor(), A !== null && A.push(this.rawDestructor, g), g) : 0;
662
662
  (!I || !I.$$) && s(`Cannot pass "${fA(I)}" as a ${this.name}`), I.$$.ptr || s(`Cannot pass deleted object as a pointer of type ${this.name}`), !this.isConst && I.$$.ptrType.isConst && s(`Cannot convert argument of type ${I.$$.smartPtrType ? I.$$.smartPtrType.name : I.$$.ptrType.name} to parameter type ${this.name}`);
663
663
  var B = I.$$.ptrType.registeredClass;
664
- if (g = TA(I.$$.ptr, B, this.registeredClass), this.isSmartPointer)
664
+ if (g = mA(I.$$.ptr, B, this.registeredClass), this.isSmartPointer)
665
665
  switch (I.$$.smartPtr === void 0 && s("Passing raw pointer to smart pointer is illegal"), this.sharingPolicy) {
666
666
  case 0:
667
667
  I.$$.smartPtrType === this ? g = I.$$.smartPtr : s(`Cannot convert argument of type ${I.$$.smartPtrType ? I.$$.smartPtrType.name : I.$$.ptrType.name} to parameter type ${this.name}`);
@@ -682,11 +682,11 @@ async function OI(Q = {}) {
682
682
  }
683
683
  return g;
684
684
  }
685
- function mg(A, I) {
685
+ function Tg(A, I) {
686
686
  if (I === null)
687
687
  return this.isReference && s(`null is not a valid ${this.name}`), 0;
688
688
  I.$$ || s(`Cannot pass "${fA(I)}" as a ${this.name}`), I.$$.ptr || s(`Cannot pass deleted object as a pointer of type ${this.name}`), I.$$.ptrType.isConst && s(`Cannot convert argument of type ${I.$$.ptrType.name} to parameter type ${this.name}`);
689
- var g = I.$$.ptrType.registeredClass, B = TA(I.$$.ptr, g, this.registeredClass);
689
+ var g = I.$$.ptrType.registeredClass, B = mA(I.$$.ptr, g, this.registeredClass);
690
690
  return B;
691
691
  }
692
692
  var MI = (A, I, g) => {
@@ -696,11 +696,11 @@ async function OI(Q = {}) {
696
696
  return null;
697
697
  var B = MI(A, I, g.baseClass);
698
698
  return B === null ? null : g.downcast(B);
699
- }, Tg = {}, fg = (A, I) => {
699
+ }, mg = {}, fg = (A, I) => {
700
700
  for (I === void 0 && s("ptr should not be undefined"); A.baseClass; )
701
701
  I = A.upcast(I), A = A.baseClass;
702
702
  return I;
703
- }, ng = (A, I) => (I = fg(A, I), Tg[I]), cA = (A, I) => {
703
+ }, ng = (A, I) => (I = fg(A, I), mg[I]), cA = (A, I) => {
704
704
  (!I.ptrType || !I.ptr) && sA("makeClassHandle requires ptr and ptrType");
705
705
  var g = !!I.smartPtrType, B = !!I.smartPtr;
706
706
  return g !== B && sA("Both smartPtrType and smartPtr must be specified"), I.count = {
@@ -764,7 +764,7 @@ async function OI(Q = {}) {
764
764
  });
765
765
  };
766
766
  function KA(A, I, g, B, C, E, D, w, i, N, G) {
767
- this.name = A, this.registeredClass = I, this.isReference = g, this.isConst = B, this.isSmartPointer = C, this.pointeeType = E, this.sharingPolicy = D, this.rawGetPointee = w, this.rawConstructor = i, this.rawShare = N, this.rawDestructor = G, !C && I.baseClass === void 0 ? B ? (this.toWireType = lg, this.destructorFunction = null) : (this.toWireType = mg, this.destructorFunction = null) : this.toWireType = Vg;
767
+ this.name = A, this.registeredClass = I, this.isReference = g, this.isConst = B, this.isSmartPointer = C, this.pointeeType = E, this.sharingPolicy = D, this.rawGetPointee = w, this.rawConstructor = i, this.rawShare = N, this.rawDestructor = G, !C && I.baseClass === void 0 ? B ? (this.toWireType = lg, this.destructorFunction = null) : (this.toWireType = Tg, this.destructorFunction = null) : this.toWireType = Vg;
768
768
  }
769
769
  var FI = (A, I, g) => {
770
770
  M.hasOwnProperty(A) || sA("Replacing nonexistent public symbol"), M[A].overloadTable !== void 0 && g !== void 0 ? M[A].overloadTable[g] = I : (M[A] = I, M[A].argCount = g);
@@ -825,7 +825,7 @@ async function OI(Q = {}) {
825
825
  t = t[0];
826
826
  var a, k;
827
827
  B ? (a = t.registeredClass, k = a.instancePrototype) : k = SA.prototype;
828
- var H = mA(G, function() {
828
+ var H = TA(G, function() {
829
829
  if (Object.getPrototypeOf(this) !== _)
830
830
  throw new wA(`Use 'new' to construct ${G}`);
831
831
  if (Z.constructor_body === void 0)
@@ -887,7 +887,7 @@ async function OI(Q = {}) {
887
887
  }
888
888
  return _(H);
889
889
  };
890
- return mA(A, t);
890
+ return TA(A, t);
891
891
  }
892
892
  var $g = (A, I, g, B, C, E) => {
893
893
  var D = nA(I, g);
@@ -980,7 +980,7 @@ async function OI(Q = {}) {
980
980
  }, CB = (A, I, g) => {
981
981
  switch (I) {
982
982
  case 1:
983
- return g ? (B) => X[B] : (B) => T[B];
983
+ return g ? (B) => X[B] : (B) => m[B];
984
984
  case 2:
985
985
  return g ? (B) => FA[B >> 1] : (B) => QA[B >> 1];
986
986
  case 4:
@@ -1039,7 +1039,7 @@ async function OI(Q = {}) {
1039
1039
  }
1040
1040
  }
1041
1041
  return I[g] = 0, g - C;
1042
- }, BA = (A, I, g) => iB(A, T, I, g), UI = (A) => {
1042
+ }, BA = (A, I, g) => iB(A, m, I, g), UI = (A) => {
1043
1043
  for (var I = 0, g = 0; g < A.length; ++g) {
1044
1044
  var B = A.charCodeAt(g);
1045
1045
  B <= 127 ? I++ : B <= 2047 ? I += 2 : B >= 55296 && B <= 57343 ? (I += 4, ++g) : I += 3;
@@ -1075,7 +1075,7 @@ async function OI(Q = {}) {
1075
1075
  }
1076
1076
  }
1077
1077
  return E;
1078
- }, oB = (A, I, g) => A ? cI(T, A, I, g) : "", NB = (A, I) => {
1078
+ }, oB = (A, I, g) => A ? cI(m, A, I, g) : "", NB = (A, I) => {
1079
1079
  I = W(I), p(A, {
1080
1080
  name: I,
1081
1081
  fromWireType(g) {
@@ -1087,7 +1087,7 @@ async function OI(Q = {}) {
1087
1087
  var C, E = typeof B == "string";
1088
1088
  E || ArrayBuffer.isView(B) && B.BYTES_PER_ELEMENT == 1 || s("Cannot pass non-string to std::string"), E ? C = UI(B) : C = B.length;
1089
1089
  var D = bA(4 + C + 1), w = D + 4;
1090
- return K[D >> 2] = C, E ? BA(B, w, C + 1) : T.set(B, w), g !== null && g.push(e, D), D;
1090
+ return K[D >> 2] = C, E ? BA(B, w, C + 1) : m.set(B, w), g !== null && g.push(e, D), D;
1091
1091
  },
1092
1092
  readValueFromPointer: DA,
1093
1093
  destructorFunction(g) {
@@ -1214,7 +1214,7 @@ async function OI(Q = {}) {
1214
1214
  }
1215
1215
  return hB(D, h, H);
1216
1216
  }, G = `methodCaller<(${E.map((Y) => Y.name)}) => ${C.name}>`;
1217
- return cB(mA(G, N));
1217
+ return cB(TA(G, N));
1218
1218
  }, aB = (A) => A ? (A = HI(A), l.toHandle(globalThis[A])) : l.toHandle(globalThis), tB = (A) => {
1219
1219
  A > 9 && ($[A + 1] += 1);
1220
1220
  }, zB = (A, I, g, B, C) => jA[A](I, g, B, C), qB = (A) => {
@@ -1235,7 +1235,7 @@ async function OI(Q = {}) {
1235
1235
  } catch {
1236
1236
  }
1237
1237
  }, rB = (A) => {
1238
- var I = T.length;
1238
+ var I = m.length;
1239
1239
  A >>>= 0;
1240
1240
  var g = PB();
1241
1241
  if (A > g)
@@ -1281,24 +1281,24 @@ async function OI(Q = {}) {
1281
1281
  for (var C of g)
1282
1282
  B += UI(C) + 1;
1283
1283
  return K[I >> 2] = B, 0;
1284
- }, mB = (A) => 52;
1285
- function TB(A, I, g, B, C) {
1284
+ }, TB = (A) => 52;
1285
+ function mB(A, I, g, B, C) {
1286
1286
  return 70;
1287
1287
  }
1288
1288
  var fB = [null, [], []], nB = (A, I) => {
1289
1289
  var g = fB[A];
1290
- I === 0 || I === 10 ? ((A === 1 ? CA : m)(cI(g)), g.length = 0) : g.push(I);
1290
+ I === 0 || I === 10 ? ((A === 1 ? CA : T)(cI(g)), g.length = 0) : g.push(I);
1291
1291
  }, xB = (A, I, g, B) => {
1292
1292
  for (var C = 0, E = 0; E < g; E++) {
1293
1293
  var D = K[I >> 2], w = K[I + 4 >> 2];
1294
1294
  I += 8;
1295
1295
  for (var i = 0; i < w; i++)
1296
- nB(A, T[D + i]);
1296
+ nB(A, m[D + i]);
1297
1297
  C += w;
1298
1298
  }
1299
1299
  return K[B >> 2] = C, 0;
1300
1300
  }, eB = (A) => A;
1301
- if (Pg(), eg(), M.noExitRuntime && M.noExitRuntime, M.print && (CA = M.print), M.printErr && (m = M.printErr), M.wasmBinary && (b = M.wasmBinary), M.arguments && M.arguments, M.thisProgram && (J = M.thisProgram), M.preInit)
1301
+ if (Pg(), eg(), M.noExitRuntime && M.noExitRuntime, M.print && (CA = M.print), M.printErr && (T = M.printErr), M.wasmBinary && (b = M.wasmBinary), M.arguments && M.arguments, M.thisProgram && (J = M.thisProgram), M.preInit)
1302
1302
  for (typeof M.preInit == "function" && (M.preInit = [M.preInit]); M.preInit.length > 0; )
1303
1303
  M.preInit.shift()();
1304
1304
  var hI, e, bA, kI, L, JI, aI, tI, zI, qI, dI, PI, WI, hA, ZI;
@@ -1343,8 +1343,8 @@ async function OI(Q = {}) {
1343
1343
  ga: rB,
1344
1344
  ea: lB,
1345
1345
  fa: VB,
1346
- ha: mB,
1347
- $: TB,
1346
+ ha: TB,
1347
+ $: mB,
1348
1348
  V: xB,
1349
1349
  K: LC,
1350
1350
  C: UC,
@@ -2036,13 +2036,13 @@ class GQ {
2036
2036
  topRight: { x: J, y: P },
2037
2037
  bottomLeft: { x: V, y: j },
2038
2038
  bottomRight: { x: IA, y: O }
2039
- } = z.position, CA = Math.min(q, J, V, IA), m = Math.min(d, P, j, O), b = Math.max(q, J, V, IA), MA = Math.max(d, P, j, O);
2039
+ } = z.position, CA = Math.min(q, J, V, IA), T = Math.min(d, P, j, O), b = Math.max(q, J, V, IA), MA = Math.max(d, P, j, O);
2040
2040
  return {
2041
2041
  boundingBox: new DOMRectReadOnly(
2042
2042
  CA,
2043
- m,
2043
+ T,
2044
2044
  b - CA,
2045
- MA - m
2045
+ MA - T
2046
2046
  ),
2047
2047
  rawValue: z.text,
2048
2048
  format: _C(z.format),
@@ -2083,20 +2083,35 @@ const AA = self;
2083
2083
  let qA = null;
2084
2084
  const nI = { formats: ["qr_code"] };
2085
2085
  try {
2086
- LQ(AA) ? (qA = new AA.BarcodeDetector(nI), AA.postMessage({ payload: { status: "success" }, type: "message" })) : (bI({
2086
+ LQ(AA) ? (qA = new AA.BarcodeDetector(nI), AA.postMessage({
2087
+ payload: {
2088
+ status: "success"
2089
+ },
2090
+ type: "init"
2091
+ })) : (bI({
2087
2092
  overrides: {
2088
2093
  locateFile(Q, o) {
2089
2094
  return Q.endsWith(".wasm") ? YQ : o + Q;
2090
2095
  },
2091
2096
  postRun: [
2092
2097
  () => {
2093
- AA.postMessage({ payload: { status: "success" }, type: "message" });
2098
+ AA.postMessage({
2099
+ payload: {
2100
+ status: "success"
2101
+ },
2102
+ type: "init"
2103
+ });
2094
2104
  }
2095
2105
  ]
2096
2106
  }
2097
2107
  }), qA = new GQ(nI));
2098
2108
  } catch (Q) {
2099
- console.error(Q), AA.postMessage({ payload: { status: "error" }, type: "message" });
2109
+ console.error(Q), AA.postMessage({
2110
+ payload: {
2111
+ status: "failure"
2112
+ },
2113
+ type: "init"
2114
+ });
2100
2115
  }
2101
2116
  AA.addEventListener("message", yQ);
2102
2117
  async function yQ({ data: { payload: Q, type: o } }) {
@@ -1,16 +1,22 @@
1
1
  import type { DetectedBarcode } from 'barcode-detector/ponyfill';
2
- type DecodeReq = {
2
+ type DecodeRequest = {
3
3
  payload: {
4
4
  data: ImageData;
5
5
  uuid: string;
6
6
  };
7
7
  type: 'decode';
8
8
  };
9
- type DecodeRes = {
9
+ type DecodeResponse = {
10
10
  payload: {
11
11
  data: DetectedBarcode | null;
12
12
  uuid: string;
13
13
  };
14
14
  type: 'decode';
15
15
  };
16
- export type { DecodeReq, DecodeRes };
16
+ type Init = {
17
+ payload: {
18
+ status: 'failure' | 'success';
19
+ };
20
+ type: 'init';
21
+ };
22
+ export type { DecodeRequest, DecodeResponse, Init };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nddeps/barcode-scanner",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "barcode",