@nddeps/barcode-scanner 0.4.1 → 0.5.0
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/package.json +65 -65
- package/dist/create-barcode-scanner.d.ts +0 -43
- package/dist/create-watchable.d.ts +0 -5
- package/dist/create-worker.d.ts +0 -6
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -289
- package/dist/utils/get-camera-access.d.ts +0 -2
- package/dist/utils/get-scan-area.d.ts +0 -9
- package/dist/utils/get-video-render-offset.d.ts +0 -8
- package/dist/utils/get-video-render-size.d.ts +0 -7
- package/dist/utils/has-camera-access.d.ts +0 -2
- package/dist/utils/index.d.ts +0 -9
- package/dist/utils/is-barcode-detector-available.d.ts +0 -7
- package/dist/utils/translate-area-to-video-render.d.ts +0 -3
- package/dist/utils/translate-area-to-video-source.d.ts +0 -3
- package/dist/utils/wait.d.ts +0 -2
- package/dist/worker.js +0 -2135
- package/dist/worker.types.d.ts +0 -22
package/package.json
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@nddeps/barcode-scanner",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"private": false,
|
|
5
|
-
"keywords": [
|
|
6
|
-
"barcode",
|
|
7
|
-
"scanner",
|
|
8
|
-
"barcode-scanner"
|
|
9
|
-
],
|
|
10
|
-
"homepage": "https://github.com/No-Deprecated-Dependencies/barcode-scanner",
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "https://github.com/No-Deprecated-Dependencies/barcode-scanner.git"
|
|
14
|
-
},
|
|
15
|
-
"license": "MIT",
|
|
16
|
-
"author": "Aleksei Saenko",
|
|
17
|
-
"type": "module",
|
|
18
|
-
"exports": {
|
|
19
|
-
".": {
|
|
20
|
-
"types": "./dist/index.d.ts",
|
|
21
|
-
"import": "./dist/index.js"
|
|
22
|
-
},
|
|
23
|
-
"./worker": {
|
|
24
|
-
"import": "./dist/worker.js"
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
"main": "./dist/index.js",
|
|
28
|
-
"types": "./dist/index.d.ts",
|
|
29
|
-
"files": [
|
|
30
|
-
"./dist"
|
|
31
|
-
],
|
|
32
|
-
"scripts": {
|
|
33
|
-
"build": "vite build && tsc -b",
|
|
34
|
-
"dev": "vite",
|
|
35
|
-
"preview": "vite preview"
|
|
36
|
-
},
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"barcode-detector": "^3.0.8",
|
|
39
|
-
"zxing-wasm": "^2.2.4"
|
|
40
|
-
},
|
|
41
|
-
"devDependencies": {
|
|
42
|
-
"@eslint/css": "^0.14.1",
|
|
43
|
-
"@eslint/js": "^9.39.2",
|
|
44
|
-
"@eslint/json": "^1.0.0",
|
|
45
|
-
"@eslint/markdown": "^7.5.1",
|
|
46
|
-
"@types/emscripten": "^1.41.5",
|
|
47
|
-
"@types/node": "^25.
|
|
48
|
-
"eslint": "^9.39.2",
|
|
49
|
-
"eslint-config-prettier": "^10.1.8",
|
|
50
|
-
"eslint-plugin-perfectionist": "^5.4.0",
|
|
51
|
-
"eslint-plugin-prettier": "^5.5.5",
|
|
52
|
-
"globals": "^17.2.0",
|
|
53
|
-
"jiti": "^2.6.1",
|
|
54
|
-
"prettier": "3.8.1",
|
|
55
|
-
"sort-package-json": "^3.6.1",
|
|
56
|
-
"stylelint": "^16.26.1",
|
|
57
|
-
"stylelint-config-recess-order": "^7.6.0",
|
|
58
|
-
"stylelint-config-standard": "^39.0.1",
|
|
59
|
-
"stylelint-config-standard-scss": "^16.0.0",
|
|
60
|
-
"stylelint-order": "^7.0.1",
|
|
61
|
-
"typescript": "~5.9.3",
|
|
62
|
-
"typescript-eslint": "^8.54.0",
|
|
63
|
-
"vite": "^7.3.1"
|
|
64
|
-
}
|
|
65
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@nddeps/barcode-scanner",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"keywords": [
|
|
6
|
+
"barcode",
|
|
7
|
+
"scanner",
|
|
8
|
+
"barcode-scanner"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/No-Deprecated-Dependencies/barcode-scanner",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/No-Deprecated-Dependencies/barcode-scanner.git"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Aleksei Saenko",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./worker": {
|
|
24
|
+
"import": "./dist/worker.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"./dist"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "vite build && tsc -b",
|
|
34
|
+
"dev": "vite",
|
|
35
|
+
"preview": "vite preview"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"barcode-detector": "^3.0.8",
|
|
39
|
+
"zxing-wasm": "^2.2.4"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@eslint/css": "^0.14.1",
|
|
43
|
+
"@eslint/js": "^9.39.2",
|
|
44
|
+
"@eslint/json": "^1.0.0",
|
|
45
|
+
"@eslint/markdown": "^7.5.1",
|
|
46
|
+
"@types/emscripten": "^1.41.5",
|
|
47
|
+
"@types/node": "^25.2.0",
|
|
48
|
+
"eslint": "^9.39.2",
|
|
49
|
+
"eslint-config-prettier": "^10.1.8",
|
|
50
|
+
"eslint-plugin-perfectionist": "^5.4.0",
|
|
51
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
52
|
+
"globals": "^17.2.0",
|
|
53
|
+
"jiti": "^2.6.1",
|
|
54
|
+
"prettier": "3.8.1",
|
|
55
|
+
"sort-package-json": "^3.6.1",
|
|
56
|
+
"stylelint": "^16.26.1",
|
|
57
|
+
"stylelint-config-recess-order": "^7.6.0",
|
|
58
|
+
"stylelint-config-standard": "^39.0.1",
|
|
59
|
+
"stylelint-config-standard-scss": "^16.0.0",
|
|
60
|
+
"stylelint-order": "^7.0.1",
|
|
61
|
+
"typescript": "~5.9.3",
|
|
62
|
+
"typescript-eslint": "^8.54.0",
|
|
63
|
+
"vite": "^7.3.1"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { type ScanArea } from './utils';
|
|
2
|
-
type DecodeFailureHandler = (this: State) => Promise<void> | void;
|
|
3
|
-
type DecodeSuccessHandler = (this: State, data: string, area: ScanArea) => Promise<void> | void;
|
|
4
|
-
type LifecycleHook = (this: State) => void;
|
|
5
|
-
type State = {
|
|
6
|
-
decodeFrameTs: number;
|
|
7
|
-
isDecodeFrameProcessed: boolean;
|
|
8
|
-
isDestroyed: boolean;
|
|
9
|
-
isVideoActive: boolean;
|
|
10
|
-
isVideoPaused: boolean;
|
|
11
|
-
scanArea: ScanArea;
|
|
12
|
-
scanRate: number;
|
|
13
|
-
video: HTMLVideoElement;
|
|
14
|
-
};
|
|
15
|
-
declare function createBarcodeScanner(video: HTMLVideoElement, { debug, getScanArea, handleDecodeFailure, handleDecodeSuccess, lifecycle, scanRate, }?: {
|
|
16
|
-
debug?: boolean;
|
|
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<{
|
|
32
|
-
destroy: () => void;
|
|
33
|
-
pause: () => Promise<void>;
|
|
34
|
-
start: ({ facingMode, ...rest }?: {
|
|
35
|
-
facingMode?: "environment" | "user";
|
|
36
|
-
handleDecodeFailure?: DecodeFailureHandler;
|
|
37
|
-
handleDecodeSuccess?: DecodeSuccessHandler;
|
|
38
|
-
}) => Promise<void>;
|
|
39
|
-
state: State;
|
|
40
|
-
stop: () => Promise<void>;
|
|
41
|
-
}>;
|
|
42
|
-
export type { DecodeFailureHandler, DecodeSuccessHandler, LifecycleHook, State };
|
|
43
|
-
export { createBarcodeScanner };
|
package/dist/create-worker.d.ts
DELETED
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
function x(t) {
|
|
2
|
-
const r = new EventTarget(), a = new Proxy(t, {
|
|
3
|
-
get(i, o, c) {
|
|
4
|
-
return Reflect.get(i, o, c);
|
|
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(
|
|
27
|
-
/* @vite-ignore */
|
|
28
|
-
"" + new URL("worker.js", import.meta.url).href,
|
|
29
|
-
import.meta.url
|
|
30
|
-
), { type: "module" }), r = new Promise((n, i) => {
|
|
31
|
-
const o = setTimeout(() => {
|
|
32
|
-
i(new Error("Worker load timeout"));
|
|
33
|
-
}, O);
|
|
34
|
-
t.addEventListener(
|
|
35
|
-
"message",
|
|
36
|
-
({ data: { payload: c, type: s } }) => {
|
|
37
|
-
s === "init" && (clearTimeout(o), c.status === "success" ? n(!0) : i(new Error("Worker failed to load")));
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
once: !0
|
|
41
|
-
}
|
|
42
|
-
);
|
|
43
|
-
});
|
|
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));
|
|
52
|
-
};
|
|
53
|
-
t.addEventListener("message", d), t.postMessage({ payload: { data: n, uuid: i }, type: "decode" });
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
decode: a,
|
|
58
|
-
worker: t
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
async function V() {
|
|
62
|
-
try {
|
|
63
|
-
return (await navigator.permissions.query({ name: "camera" })).state === "granted";
|
|
64
|
-
} catch {
|
|
65
|
-
return (await navigator.mediaDevices.enumerateDevices()).filter((a) => a.deviceId && a.kind === "videoinput").length > 0;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
async function H() {
|
|
69
|
-
if (await V())
|
|
70
|
-
return !0;
|
|
71
|
-
try {
|
|
72
|
-
const r = (await navigator.mediaDevices.getUserMedia({ video: !0 })).getTracks();
|
|
73
|
-
for (const a of r)
|
|
74
|
-
a.stop();
|
|
75
|
-
return !0;
|
|
76
|
-
} catch {
|
|
77
|
-
return !1;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function k(t) {
|
|
81
|
-
const r = Math.round(0.6666666666666666 * Math.min(t.videoWidth, t.videoHeight));
|
|
82
|
-
return {
|
|
83
|
-
height: r,
|
|
84
|
-
width: r,
|
|
85
|
-
x: Math.round((t.videoWidth - r) / 2),
|
|
86
|
-
y: Math.round((t.videoHeight - r) / 2)
|
|
87
|
-
};
|
|
88
|
-
}
|
|
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
|
-
);
|
|
93
|
-
return {
|
|
94
|
-
x: n,
|
|
95
|
-
y: i
|
|
96
|
-
};
|
|
97
|
-
}
|
|
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
|
-
case "contain":
|
|
102
|
-
return {
|
|
103
|
-
height: o < n ? t.offsetHeight : t.offsetWidth / o,
|
|
104
|
-
width: o < n ? t.offsetHeight * o : t.offsetWidth
|
|
105
|
-
};
|
|
106
|
-
case "cover":
|
|
107
|
-
return {
|
|
108
|
-
height: o > n ? t.offsetHeight : t.offsetWidth / o,
|
|
109
|
-
width: o > n ? t.offsetHeight * o : t.offsetWidth
|
|
110
|
-
};
|
|
111
|
-
case "fill":
|
|
112
|
-
return a;
|
|
113
|
-
case "none":
|
|
114
|
-
return i;
|
|
115
|
-
case "scale-down":
|
|
116
|
-
return {
|
|
117
|
-
height: Math.min(
|
|
118
|
-
o < n ? t.offsetHeight : t.offsetWidth / o,
|
|
119
|
-
t.videoHeight
|
|
120
|
-
),
|
|
121
|
-
width: Math.min(
|
|
122
|
-
o < n ? t.offsetHeight * o : t.offsetWidth,
|
|
123
|
-
t.videoWidth
|
|
124
|
-
)
|
|
125
|
-
};
|
|
126
|
-
default:
|
|
127
|
-
return i;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function L(t) {
|
|
131
|
-
return "BarcodeDetector" in t;
|
|
132
|
-
}
|
|
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
|
-
return {
|
|
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
|
-
};
|
|
141
|
-
}
|
|
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
|
-
return {
|
|
145
|
-
height: r.height * s,
|
|
146
|
-
width: r.width * d,
|
|
147
|
-
x: o * d,
|
|
148
|
-
y: c * s
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
function U(t) {
|
|
152
|
-
return new Promise((r) => setTimeout(r, t));
|
|
153
|
-
}
|
|
154
|
-
async function B(t, {
|
|
155
|
-
debug: r,
|
|
156
|
-
getScanArea: a = k,
|
|
157
|
-
handleDecodeFailure: n = () => {
|
|
158
|
-
},
|
|
159
|
-
handleDecodeSuccess: i = () => {
|
|
160
|
-
},
|
|
161
|
-
lifecycle: o = {},
|
|
162
|
-
scanRate: c = 24
|
|
163
|
-
} = {}) {
|
|
164
|
-
if (!(t instanceof HTMLVideoElement))
|
|
165
|
-
throw new Error("video is not a HTMLVideoElement");
|
|
166
|
-
if (!(i instanceof Function))
|
|
167
|
-
throw new Error("handleDecodeSuccess is not a function");
|
|
168
|
-
if (!(n instanceof Function))
|
|
169
|
-
throw new Error("handleDecodeFailure is not a function");
|
|
170
|
-
const s = document.createElement("canvas"), d = s.getContext("2d", { willReadFrequently: !0 });
|
|
171
|
-
if (!d)
|
|
172
|
-
throw new Error("canvas context is not supported");
|
|
173
|
-
const { decode: w, worker: g } = T(), { state: e } = x({
|
|
174
|
-
decodeFrameTs: performance.now(),
|
|
175
|
-
isDecodeFrameProcessed: !1,
|
|
176
|
-
isDestroyed: !1,
|
|
177
|
-
isVideoActive: !1,
|
|
178
|
-
isVideoPaused: !1,
|
|
179
|
-
scanArea: a(t),
|
|
180
|
-
scanRate: c,
|
|
181
|
-
video: t
|
|
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, o.onCreate && o.onCreate.call(e);
|
|
184
|
-
function b(h, u) {
|
|
185
|
-
v(m);
|
|
186
|
-
async function m() {
|
|
187
|
-
if (e.isDestroyed || e.isVideoActive === !1)
|
|
188
|
-
return;
|
|
189
|
-
if (
|
|
190
|
-
// Skip if the time since the last request frame is less than the scan rate
|
|
191
|
-
performance.now() - e.decodeFrameTs < 1e3 / e.scanRate || // Skip if the frame is already processed
|
|
192
|
-
e.isDecodeFrameProcessed || // Skip if the video is not ready
|
|
193
|
-
e.video.readyState <= 1
|
|
194
|
-
) {
|
|
195
|
-
v(m);
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
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
|
-
e.video,
|
|
200
|
-
e.scanArea.x,
|
|
201
|
-
e.scanArea.y,
|
|
202
|
-
e.scanArea.width,
|
|
203
|
-
e.scanArea.height,
|
|
204
|
-
0,
|
|
205
|
-
0,
|
|
206
|
-
s.width,
|
|
207
|
-
s.height
|
|
208
|
-
);
|
|
209
|
-
const l = d.getImageData(0, 0, s.width, s.height);
|
|
210
|
-
r && window.dispatchEvent(
|
|
211
|
-
new CustomEvent("barcode-scanner:decode-frame", {
|
|
212
|
-
detail: {
|
|
213
|
-
imageData: l
|
|
214
|
-
}
|
|
215
|
-
})
|
|
216
|
-
);
|
|
217
|
-
try {
|
|
218
|
-
const f = await w(l);
|
|
219
|
-
if (f) {
|
|
220
|
-
const p = f.cornerPoints.map((E) => E.x), y = f.cornerPoints.map((E) => E.y), P = {
|
|
221
|
-
height: Math.max(...y) - Math.min(...y),
|
|
222
|
-
width: Math.max(...p) - Math.min(...p),
|
|
223
|
-
x: Math.min(...p) + e.scanArea.x,
|
|
224
|
-
y: Math.min(...y) + e.scanArea.y
|
|
225
|
-
};
|
|
226
|
-
await Promise.resolve(h.call(e, f.rawValue, P));
|
|
227
|
-
} else
|
|
228
|
-
await Promise.resolve(u.call(e));
|
|
229
|
-
} catch (f) {
|
|
230
|
-
console.warn("Failed to decode barcode"), f && console.error(f);
|
|
231
|
-
} finally {
|
|
232
|
-
o.onDecode && o.onDecode.call(e), e.decodeFrameTs = performance.now(), e.isDecodeFrameProcessed = !1, v(m);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
function R() {
|
|
237
|
-
e.isDestroyed || (D(), g.terminate(), e.isDestroyed = !0);
|
|
238
|
-
}
|
|
239
|
-
async function S() {
|
|
240
|
-
if (e.isVideoActive === !1 || e.isVideoPaused || e.isDestroyed)
|
|
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;
|
|
253
|
-
}
|
|
254
|
-
async function M({
|
|
255
|
-
facingMode: h = "environment",
|
|
256
|
-
...u
|
|
257
|
-
} = {}) {
|
|
258
|
-
if (o.onBeforeStart && o.onBeforeStart.call(e), !await H())
|
|
259
|
-
throw new Error("No camera access");
|
|
260
|
-
e.video.srcObject instanceof MediaStream || (e.video.srcObject = await navigator.mediaDevices.getUserMedia({
|
|
261
|
-
video: {
|
|
262
|
-
facingMode: h
|
|
263
|
-
}
|
|
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
|
-
}
|
|
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
|
-
}
|
|
269
|
-
return {
|
|
270
|
-
destroy: R,
|
|
271
|
-
pause: S,
|
|
272
|
-
start: M,
|
|
273
|
-
state: e,
|
|
274
|
-
stop: D
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
export {
|
|
278
|
-
B as createBarcodeScanner,
|
|
279
|
-
B as default,
|
|
280
|
-
H as getCameraAccess,
|
|
281
|
-
k as getScanArea,
|
|
282
|
-
A as getVideoRenderOffset,
|
|
283
|
-
W as getVideoRenderSize,
|
|
284
|
-
V as hasCameraAccess,
|
|
285
|
-
L as isBarcodeDetectorAvailable,
|
|
286
|
-
j as translateAreaToVideoRender,
|
|
287
|
-
C as translateAreaToVideoSource,
|
|
288
|
-
U as wait
|
|
289
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { RenderSize } from './get-video-render-size';
|
|
2
|
-
type RenderOffset = {
|
|
3
|
-
x: number;
|
|
4
|
-
y: number;
|
|
5
|
-
};
|
|
6
|
-
declare function getVideoRenderOffset(video: HTMLVideoElement, renderSize: RenderSize): RenderOffset;
|
|
7
|
-
export type { RenderOffset };
|
|
8
|
-
export { getVideoRenderOffset };
|
package/dist/utils/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './get-camera-access';
|
|
2
|
-
export * from './get-scan-area';
|
|
3
|
-
export * from './get-video-render-offset';
|
|
4
|
-
export * from './get-video-render-size';
|
|
5
|
-
export * from './has-camera-access';
|
|
6
|
-
export * from './is-barcode-detector-available';
|
|
7
|
-
export * from './translate-area-to-video-render';
|
|
8
|
-
export * from './translate-area-to-video-source';
|
|
9
|
-
export * from './wait';
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { BarcodeDetector, BarcodeDetectorOptions } from 'barcode-detector/ponyfill';
|
|
2
|
-
declare function isBarcodeDetectorAvailable<T extends object>(value: T): value is {
|
|
3
|
-
BarcodeDetector: {
|
|
4
|
-
new (barcodeDetectorOptions?: BarcodeDetectorOptions): BarcodeDetector;
|
|
5
|
-
} & BarcodeDetector;
|
|
6
|
-
} & T;
|
|
7
|
-
export { isBarcodeDetectorAvailable };
|
package/dist/utils/wait.d.ts
DELETED