react-qr-barcode-scanner 2.0.0 → 2.0.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/README.md +2 -0
- package/package.json +17 -14
- package/dist/BarcodeScannerComponent.d.ts +0 -14
- package/dist/BarcodeScannerComponent.js +0 -64
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
package/README.md
CHANGED
|
@@ -13,6 +13,8 @@ npm i react-qr-barcode-scanner
|
|
|
13
13
|
## Demo
|
|
14
14
|
Try a demo of the scanner [here](https://jamenamcinteer.github.io/react-qr-barcode-scanner/).
|
|
15
15
|
|
|
16
|
+

|
|
17
|
+
|
|
16
18
|
## Usage in React:
|
|
17
19
|
|
|
18
20
|
```jsx
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-qr-barcode-scanner",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "A simple React Component using the client's webcam to read barcodes and QR codes.",
|
|
5
|
-
"
|
|
5
|
+
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"author": "Jamena McInteer (https://jamena.dev)",
|
|
8
9
|
"files": [
|
|
9
10
|
"dist"
|
|
@@ -11,7 +12,8 @@
|
|
|
11
12
|
"scripts": {
|
|
12
13
|
"lint": "eslint ./src --ext .js,.jsx,.ts,.tsx --fix",
|
|
13
14
|
"build": "rm -rf dist && tsc --build tsconfig.json --declaration",
|
|
14
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
16
|
+
"release": "standard-version"
|
|
15
17
|
},
|
|
16
18
|
"repository": {
|
|
17
19
|
"type": "git",
|
|
@@ -31,20 +33,21 @@
|
|
|
31
33
|
"url": "https://github.com/jamenamcinteer/react-qr-barcode-scanner/issues"
|
|
32
34
|
},
|
|
33
35
|
"homepage": "https://github.com/jamenamcinteer/react-qr-barcode-scanner#readme",
|
|
34
|
-
"peerDependencies": {
|
|
35
|
-
"react": "^18.2.0",
|
|
36
|
-
"react-dom": "^18.2.0"
|
|
37
|
-
},
|
|
38
36
|
"dependencies": {
|
|
39
|
-
"@types/react": "^18.2.0",
|
|
40
37
|
"@zxing/library": "^0.21.3",
|
|
41
|
-
"react-webcam": "^7.
|
|
38
|
+
"react-webcam": "^7.2.0"
|
|
42
39
|
},
|
|
43
40
|
"devDependencies": {
|
|
44
|
-
"@
|
|
45
|
-
"@typescript-eslint/
|
|
46
|
-
"eslint": "^
|
|
47
|
-
"eslint
|
|
48
|
-
"
|
|
41
|
+
"@types/react": "^19.1.2",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^8.30.0",
|
|
43
|
+
"@typescript-eslint/parser": "^8.30.0",
|
|
44
|
+
"eslint": "^9.24.0",
|
|
45
|
+
"eslint-plugin-react": "^7.37.5",
|
|
46
|
+
"standard-version": "^9.5.0",
|
|
47
|
+
"typescript": "^5.8.3"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"react": "^19.1.0",
|
|
51
|
+
"react-dom": "^19.1.0"
|
|
49
52
|
}
|
|
50
53
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Result } from "@zxing/library";
|
|
3
|
-
export declare const BarcodeScannerComponent: ({ onUpdate, onError, width, height, facingMode, torch, delay, videoConstraints, stopStream, }: {
|
|
4
|
-
onUpdate: (arg0: unknown, arg1?: Result) => void;
|
|
5
|
-
onError?: (arg0: string | DOMException) => void;
|
|
6
|
-
width?: number | string;
|
|
7
|
-
height?: number | string;
|
|
8
|
-
facingMode?: "environment" | "user";
|
|
9
|
-
torch?: boolean;
|
|
10
|
-
delay?: number;
|
|
11
|
-
videoConstraints?: MediaTrackConstraints;
|
|
12
|
-
stopStream?: boolean;
|
|
13
|
-
}) => React.ReactElement;
|
|
14
|
-
export default BarcodeScannerComponent;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { BrowserMultiFormatReader } from "@zxing/library";
|
|
4
|
-
import Webcam from "react-webcam";
|
|
5
|
-
export const BarcodeScannerComponent = ({ onUpdate, onError, width = "100%", height = "100%", facingMode = "environment", torch, delay = 500, videoConstraints, stopStream, }) => {
|
|
6
|
-
const webcamRef = React.useRef(null);
|
|
7
|
-
const capture = React.useCallback(() => {
|
|
8
|
-
const codeReader = new BrowserMultiFormatReader();
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
const imageSrc = webcamRef?.current?.getScreenshot();
|
|
11
|
-
if (imageSrc) {
|
|
12
|
-
codeReader
|
|
13
|
-
.decodeFromImage(undefined, imageSrc)
|
|
14
|
-
.then((result) => {
|
|
15
|
-
onUpdate(null, result);
|
|
16
|
-
})
|
|
17
|
-
.catch((err) => {
|
|
18
|
-
onUpdate(err);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}, [onUpdate]);
|
|
22
|
-
React.useEffect(() => {
|
|
23
|
-
// Turn on the flashlight if prop is defined and device has the capability
|
|
24
|
-
if (typeof torch === "boolean" &&
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
navigator?.mediaDevices?.getSupportedConstraints().torch) {
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
const stream = webcamRef?.current?.video.srcObject;
|
|
29
|
-
const track = stream?.getVideoTracks()[0]; // get the active track of the stream
|
|
30
|
-
if (track &&
|
|
31
|
-
track.getCapabilities().torch &&
|
|
32
|
-
!track.getConstraints().torch) {
|
|
33
|
-
track
|
|
34
|
-
.applyConstraints({
|
|
35
|
-
advanced: [{ torch }],
|
|
36
|
-
})
|
|
37
|
-
.catch((err) => onUpdate(err));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}, [torch, onUpdate]);
|
|
41
|
-
React.useEffect(() => {
|
|
42
|
-
if (stopStream) {
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
let stream = webcamRef?.current?.video.srcObject;
|
|
45
|
-
if (stream) {
|
|
46
|
-
stream.getTracks().forEach((track) => {
|
|
47
|
-
stream.removeTrack(track);
|
|
48
|
-
track.stop();
|
|
49
|
-
});
|
|
50
|
-
stream = null;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}, [stopStream]);
|
|
54
|
-
React.useEffect(() => {
|
|
55
|
-
const interval = setInterval(capture, delay);
|
|
56
|
-
return () => {
|
|
57
|
-
clearInterval(interval);
|
|
58
|
-
};
|
|
59
|
-
}, []);
|
|
60
|
-
return (_jsx(Webcam, { width: width, height: height, ref: webcamRef, screenshotFormat: "image/jpeg", videoConstraints: videoConstraints || {
|
|
61
|
-
facingMode,
|
|
62
|
-
}, audio: false, onUserMediaError: onError }));
|
|
63
|
-
};
|
|
64
|
-
export default BarcodeScannerComponent;
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED