Skip to content

Commit

Permalink
feat: add react hooks and components
Browse files Browse the repository at this point in the history
  • Loading branch information
Sec-ant committed Aug 24, 2024
1 parent c902dc9 commit 6bfe105
Show file tree
Hide file tree
Showing 49 changed files with 2,911 additions and 192 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ The wasm binary won't be fetched or instantiated unless a [read](#readbarcodesfr
import { getZXingModule } from "zxing-wasm";

/**
* This function will trigger the download and
* instantiation of the wasm binary immediately
* This function will trigger the download and instantiation of the wasm binary immediately
*/
const zxingModulePromise1 = getZXingModule();

Expand Down
6 changes: 6 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
}
}
},
{
"include": ["react/components"],
"formatter": {
"lineWidth": 120
}
},
{
"include": ["package.json"],
"json": {
Expand Down
4 changes: 4 additions & 0 deletions copy-files-from-to.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
{
"from": "./src/full/*.wasm",
"to": "./dist/full/"
},
{
"from": "./src/stream/media-track-shims.d.ts",
"to": "./dist/"
}
],
"copyFilesSettings": {
Expand Down
11 changes: 7 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<!doctype html>
<html>
<html lang="en">
<head>
<title>ZXing Reader Demo</title>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ZXing WASM React</title>
</head>
<body>
<div></div>
<script type="module" src="./main.ts"></script>
<div id="root"></div>
<script type="module" src="./main.tsx"></script>
</body>
</html>
18 changes: 0 additions & 18 deletions main.ts

This file was deleted.

45 changes: 45 additions & 0 deletions main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/// <reference types="./src/stream/media-track-shims" />

import React, { useState } from "react";
import ReactDOM from "react-dom/client";
import { StreamBarcodeDetector } from "./src/react/components/StreamBarcodeDetector.js";

import type { InitConstraints } from "./src/stream/index.js";

const App = () => {
const [initConstraints] = useState<InitConstraints>({
video: {
aspectRatio: undefined,
},
});

const [videoConstraints] = useState<MediaTrackConstraints>({
advanced: [
{
exposureMode: "continuous",
},
],
});

return (
<StreamBarcodeDetector
onScanDetect={(r) => {
console.log(r);
}}
onStreamInspect={(c) => {
console.log(c);
}}
initConstraints={initConstraints}
videoConstraints={videoConstraints}
scanThrottle={0}
negativeDebounce={0}
formats={["QRCode"]}
/>
);
};

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
43 changes: 41 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,35 @@
},
"./reader/zxing_reader.wasm": "./dist/reader/zxing_reader.wasm",
"./writer/zxing_writer.wasm": "./dist/writer/zxing_writer.wasm",
"./full/zxing_full.wasm": "./dist/full/zxing_full.wasm"
"./full/zxing_full.wasm": "./dist/full/zxing_full.wasm",
"./scanner": {
"import": "./dist/es/scanner/index.js",
"require": "./dist/cjs/scanner/index.js",
"default": "./dist/es/scanner/index.js"
},
"./stream": {
"import": "./dist/es/stream/index.js",
"require": "./dist/cjs/stream/index.js",
"default": "./dist/es/stream/index.js"
},
"./media-track-shims": {
"types": "./dist/media-track-shims.d.ts"
},
"./react": {
"import": "./dist/es/react/index.js",
"require": "./dist/cjs/react/index.js",
"default": "./dist/es/react/index.js"
},
"./react/components": {
"import": "./dist/es/react/components/index.js",
"require": "./dist/cjs/react/components/index.js",
"default": "./dist/es/react/components/index.js"
},
"./react/hooks": {
"import": "./dist/es/react/hooks/index.js",
"require": "./dist/cjs/react/hooks/index.js",
"default": "./dist/es/react/hooks/index.js"
}
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -101,11 +129,17 @@
"@changesets/cli": "^2.27.7",
"@types/babel__core": "^7.20.5",
"@types/node": "^22.5.0",
"@types/react": "^18.3.4",
"@types/react-dom": "^18.3.0",
"@vanilla-extract/css": "^1.15.5",
"@vanilla-extract/vite-plugin": "^4.0.15",
"concurrently": "^8.2.2",
"copy-files-from-to": "^3.11.0",
"lint-staged": "^15.2.9",
"prettier": "^3.3.3",
"pretty-quick": "^4.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rimraf": "^6.0.1",
"simple-git-hooks": "^2.11.1",
"tsx": "^4.17.0",
Expand All @@ -115,7 +149,12 @@
"vite-plugin-babel": "^1.2.0"
},
"dependencies": {
"@types/emscripten": "^1.39.13"
"@types/emscripten": "^1.39.13",
"just-compare": "^2.3.0",
"sha1-uint8array": "^0.10.7",
"type-fest": "^4.25.0",
"webrtc-adapter": "^9.0.1",
"zustand": "^4.5.5"
},
"overrides": {
"typedoc": {
Expand Down
Loading

0 comments on commit 6bfe105

Please sign in to comment.