@react-opencv/fiber 0.1.0 → 0.1.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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +118 -0
  3. package/package.json +3 -2
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Eran Stal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # react-opencv-fiber
2
+
3
+ A React renderer for OpenCV.js. Write image-processing pipelines as JSX — each element maps to an OpenCV operation, and the tree executes bottom-up through a custom React reconciler.
4
+
5
+ [**Live demo**](https://erasta.github.io/react-opencv-fiber/)
6
+
7
+ ```tsx
8
+ <CvCanvas>
9
+ <cvCanny threshold1={50} threshold2={100}>
10
+ <cvCvtColor code={11}>
11
+ <cvGaussianBlur ksize={[5, 5]} sigmaX={0}>
12
+ <cvImage src="photo.jpg" />
13
+ </cvGaussianBlur>
14
+ </cvCvtColor>
15
+ </cvCanny>
16
+ </CvCanvas>
17
+ ```
18
+
19
+ ## How it works
20
+
21
+ The library uses a custom React Fiber reconciler to build a tree of `CvNode`s from JSX. When the tree changes (props update, nodes added/removed), the pipeline re-executes:
22
+
23
+ 1. **Leaf nodes** (`<cvImage>`) load source images into OpenCV `Mat` objects
24
+ 2. **Inner nodes** (`<cvGaussianBlur>`, `<cvCanny>`, ...) receive their child's `Mat` as input, apply the corresponding `cv.*` function, and pass the result up
25
+ 3. **`<CvCanvas>`** displays the final `Mat` on an HTML canvas
26
+
27
+ Intermediate `Mat` objects are automatically cleaned up to avoid WebAssembly memory leaks.
28
+
29
+ ## API
30
+
31
+ ### `<OpenCVProvider>`
32
+
33
+ Loads OpenCV.js (WASM, ~8 MB) and provides it via context. Wrap your app with this.
34
+
35
+ ```tsx
36
+ <OpenCVProvider>
37
+ <App />
38
+ </OpenCVProvider>
39
+ ```
40
+
41
+ ### `useOpenCV()`
42
+
43
+ ```tsx
44
+ const { cv, loading, error } = useOpenCV();
45
+ ```
46
+
47
+ ### `<CvCanvas>`
48
+
49
+ Renders a `<canvas>` and executes the CV pipeline defined by its children.
50
+
51
+ ```tsx
52
+ <CvCanvas
53
+ style={{ maxWidth: "100%" }}
54
+ className="my-canvas"
55
+ onResult={(mat) => { /* final Mat before display */ }}
56
+ >
57
+ {/* CV operation tree */}
58
+ </CvCanvas>
59
+ ```
60
+
61
+ Supports `ref` forwarding to the underlying canvas element.
62
+
63
+ ### CV operation elements
64
+
65
+ Any OpenCV function can be used as a JSX element with a `cv` prefix:
66
+
67
+ | JSX element | OpenCV function |
68
+ |---|---|
69
+ | `<cvGaussianBlur ksize={[5,5]} sigmaX={0}>` | `cv.GaussianBlur(...)` |
70
+ | `<cvCanny threshold1={50} threshold2={100}>` | `cv.Canny(...)` |
71
+ | `<cvCvtColor code={11}>` | `cv.cvtColor(...)` |
72
+ | `<cvThreshold thresh={127} maxval={255} type={0}>` | `cv.threshold(...)` |
73
+ | `<cvResize dsize={[320, 240]}>` | `cv.resize(...)` |
74
+ | `<cvMedianBlur ksize={5}>` | `cv.medianBlur(...)` |
75
+ | `<cvBilateralFilter d={9} sigmaColor={75} sigmaSpace={75}>` | `cv.bilateralFilter(...)` |
76
+
77
+ Operations are nested inside-out — the innermost element runs first:
78
+
79
+ ```tsx
80
+ // Execution order: image load -> blur -> grayscale -> edge detection
81
+ <cvCanny threshold1={50} threshold2={100}>
82
+ <cvCvtColor code={11}>
83
+ <cvGaussianBlur ksize={[5, 5]} sigmaX={0}>
84
+ <cvImage src="photo.jpg" />
85
+ </cvGaussianBlur>
86
+ </cvCvtColor>
87
+ </cvCanny>
88
+ ```
89
+
90
+ Props map directly to OpenCV function parameters. Array values are coerced to the appropriate OpenCV types (`Size`, `Point`, `Scalar`).
91
+
92
+ ### `<cvImage>`
93
+
94
+ Special element that loads an image (URL or data URI) into a `Mat`.
95
+
96
+ ```tsx
97
+ <cvImage src="https://example.com/photo.jpg" />
98
+ ```
99
+
100
+ ## Demo
101
+
102
+ The `demo/` directory contains a small app with a slider-driven pipeline (blur + grayscale + Canny edge detection). To run it:
103
+
104
+ ```sh
105
+ npm install
106
+ cd demo && npm install
107
+ npm run dev
108
+ ```
109
+
110
+ ## Acknowledgements
111
+
112
+ - [OpenCV](https://opencv.org/) — the computer vision library that powers all the operations
113
+ - [OpenCV.js](https://docs.opencv.org/4.x/d5/d10/tutorial_js_root.html) — the JavaScript/WebAssembly port of OpenCV
114
+ - [React Three Fiber](https://github.com/pmndrs/react-three-fiber) — the inspiration for using a custom React reconciler to drive a non-DOM library
115
+
116
+ ## License
117
+
118
+ [MIT](./LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-opencv/fiber",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/erasta/react-opencv-fiber.git"
@@ -30,7 +30,8 @@
30
30
  "computer-vision"
31
31
  ],
32
32
  "scripts": {
33
- "build": "vite build && tsc -p tsconfig.build.json"
33
+ "build": "vite build && tsc -p tsconfig.build.json",
34
+ "prepack": "cp ../README.md ../LICENSE ."
34
35
  },
35
36
  "dependencies": {
36
37
  "react-reconciler": "^0.33.0"