@opencvjs/web 4.10.0-release.1 → 4.10.0-release.3

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 CHANGED
@@ -10,51 +10,30 @@ npm install @opencvjs/web
10
10
 
11
11
  ## Usage
12
12
 
13
- `@opencvjs/web` exports a `load` function that returns a Promise that resolves to the OpenCV.js API.
13
+ `@opencvjs/web` exports a `loadOpenCV` function that returns a Promise that resolves to the OpenCV.js API.
14
14
 
15
15
  ```ts
16
- import { load } from "@opencvjs/web";
16
+ import { loadOpenCV } from "@opencvjs/web";
17
17
 
18
- async function main() {
19
- // Wait for the OpenCV.js library to load
20
- const cv = await load();
21
-
22
- const imgSrc = document.getElementById("img_src");
23
- const imgDst = document.getElementById("img_dst");
24
-
25
- // Wait for the image to load
26
- await imgSrc.decode();
27
-
28
- // Read the image
29
- let src = cv.imread(imgSrc);
30
-
31
- // Convert the image to grayscale
32
- let dst = new cv.Mat();
33
- cv.cvtColor(src, dst, cv.COLOR_RGBA2GRAY, 0);
34
-
35
- // Show the grayscale image
36
- cv.imshow(imgDst, dst);
37
-
38
- // Release the memory
39
- src.delete();
40
- dst.delete();
41
- }
42
-
43
- main();
18
+ const cv = await loadOpenCV();
19
+ const mat = new cv.Mat();
44
20
  ```
45
21
 
46
22
  ## TypeScript
47
23
 
48
- `@opencvjs/web` exports a type definition for the OpenCV.js API.
24
+ `@opencvjs/web` exports a type `OpenCV` for the OpenCV.js API.
49
25
 
50
26
  ```ts
51
- import type { OpenCV } from "@opencvjs/web";
52
- import { load } from "@opencvjs/web";
27
+ import { loadOpenCV, type OpenCV } from "@opencvjs/web";
53
28
 
54
- const cv = await load();
55
- const src: OpenCV.Mat = cv.imread(imgSrc);
29
+ const cv: typeof OpenCV = await loadOpenCV();
30
+ const mat: OpenCV.Mat = new cv.Mat();
56
31
  ```
57
32
 
33
+ ## Example
34
+
35
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/fork/github/ocavue/opencvjs/tree/master/examples/web-vite)
36
+
58
37
  ## Credits
59
38
 
60
39
  TypeScript definitions are based on the [@techstark/opencv-js](https://github.com/TechStark/opencv-js) and [mirada](https://github.com/cancerberoSgx/mirada) projects.
package/lib/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import type { OpenCV } from "@opencvjs/types";
4
4
  * Compile the WASM library and return a promise that resolves to the
5
5
  * OpenCV.js library.
6
6
  */
7
- declare function load(): Promise<typeof OpenCV>;
7
+ declare function loadOpenCV(): Promise<typeof OpenCV>;
8
8
 
9
9
  export type { OpenCV };
10
- export { load };
10
+ export { loadOpenCV };
package/lib/index.js CHANGED
@@ -1,5 +1,10 @@
1
1
  import cv from "./opencv_js.js";
2
2
 
3
- export function load() {
4
- return cv();
3
+ let promise;
4
+
5
+ export function loadOpenCV() {
6
+ if (!promise) {
7
+ promise = cv();
8
+ }
9
+ return promise;
5
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencvjs/web",
3
- "version": "4.10.0-release.1",
3
+ "version": "4.10.0-release.3",
4
4
  "author": "ocavue <ocavue@gmail.com>",
5
5
  "repository": "https://github.com/ocavue/opencvjs",
6
6
  "type": "module",