-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add react hooks and components
- Loading branch information
Showing
48 changed files
with
2,521 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import type { PluginItem } from "@babel/core"; | ||
import { | ||
binaryExpression, | ||
identifier, | ||
logicalExpression, | ||
stringLiteral, | ||
unaryExpression, | ||
variableDeclaration, | ||
variableDeclarator, | ||
} from "@babel/types"; | ||
import babel from "vite-plugin-babel"; | ||
|
||
function emscriptenBunBabel(): PluginItem { | ||
return { | ||
visitor: { | ||
VariableDeclaration(path) { | ||
if ( | ||
path.node.kind === "var" && | ||
path.node.declarations[0]?.id.type === "Identifier" && | ||
path.node.declarations[0]?.id.name === "ENVIRONMENT_IS_WEB" | ||
) { | ||
path.insertAfter([ | ||
variableDeclaration("var", [ | ||
variableDeclarator( | ||
identifier("ENVIRONMENT_IS_BUN"), | ||
binaryExpression( | ||
"!==", | ||
unaryExpression("typeof", identifier("Bun")), | ||
stringLiteral("undefined"), | ||
), | ||
), | ||
]), | ||
]); | ||
} | ||
}, | ||
LogicalExpression(path) { | ||
if ( | ||
path.node.operator === "||" && | ||
path.node.left.type === "Identifier" && | ||
(path.node.left.name === "ENVIRONMENT_IS_WEB" || | ||
path.node.left.name === "ENVIRONMENT_IS_WORKER") && | ||
path.node.right.type === "Identifier" && | ||
(path.node.right.name === "ENVIRONMENT_IS_WORKER" || | ||
path.node.right.name === "ENVIRONMENT_IS_WEB") | ||
) { | ||
path.replaceWith( | ||
logicalExpression( | ||
"||", | ||
path.node, | ||
identifier("ENVIRONMENT_IS_BUN"), | ||
), | ||
); | ||
path.skip(); | ||
} | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
export function emscriptenBun() { | ||
return babel({ | ||
babelConfig: { | ||
plugins: [emscriptenBunBabel()], | ||
}, | ||
filter: /zxing_(reader|writer|full)\.js$/, | ||
include: /zxing_(reader|writer|full)\.js$/, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.