@rerun-io/web-viewer 0.0.0
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 +28 -0
- package/index.d.ts +10 -0
- package/index.d.ts.map +14 -0
- package/index.js +66 -0
- package/package.json +43 -0
- package/re_viewer.js +4 -0
- package/re_viewer_bg.js +3111 -0
- package/re_viewer_bg.wasm +0 -0
- package/tsconfig.json +16 -0
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Rerun Web Viewer
|
|
2
|
+
|
|
3
|
+
Embed the Rerun web viewer within your app.
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<img width="800" alt="Rerun Viewer" src="https://github.com/rerun-io/rerun/assets/2624717/c4900538-fc3a-43b8-841a-8d226e7b5a2e">
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm i @rerun-io/web-viewer
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Example
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { WebViewer } from "@rerun-io/web-viewer";
|
|
19
|
+
|
|
20
|
+
const URL = "...";
|
|
21
|
+
const parentElement = document.body;
|
|
22
|
+
|
|
23
|
+
const viewer = new WebViewer();
|
|
24
|
+
await viewer.start(URL, parentElement);
|
|
25
|
+
|
|
26
|
+
// Once you're done with it, call `stop`:
|
|
27
|
+
viewer.stop();
|
|
28
|
+
```
|
package/index.d.ts
ADDED
package/index.d.ts.map
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** @type {(typeof import("./re_viewer").WebHandle) | null} */
|
|
2
|
+
let WebHandle = null;
|
|
3
|
+
/** @returns {Promise<(typeof import("./re_viewer").WebHandle)>} */
|
|
4
|
+
async function load() {
|
|
5
|
+
if (WebHandle) {
|
|
6
|
+
return WebHandle;
|
|
7
|
+
}
|
|
8
|
+
WebHandle = (await import("./re_viewer")).WebHandle;
|
|
9
|
+
return WebHandle;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** @returns {string} */
|
|
13
|
+
function randomId() {
|
|
14
|
+
const bytes = new Uint8Array(16);
|
|
15
|
+
crypto.getRandomValues(bytes);
|
|
16
|
+
return Array.from(bytes)
|
|
17
|
+
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
18
|
+
.join("");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class WebViewer {
|
|
22
|
+
/** @type {(import("./re_viewer").WebHandle) | null} */
|
|
23
|
+
#handle = null;
|
|
24
|
+
|
|
25
|
+
/** @type {HTMLCanvasElement | null} */
|
|
26
|
+
#canvas = null;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} url
|
|
30
|
+
* @param {HTMLElement} [parent]
|
|
31
|
+
* @returns {Promise<this>}
|
|
32
|
+
*/
|
|
33
|
+
async start(url, parent = document.body) {
|
|
34
|
+
const canvas = document.createElement("canvas");
|
|
35
|
+
canvas.id = randomId();
|
|
36
|
+
|
|
37
|
+
let WebHandle_class = await load();
|
|
38
|
+
const handle = new WebHandle_class();
|
|
39
|
+
await handle.start(canvas.id, url);
|
|
40
|
+
if (handle.has_panicked()) {
|
|
41
|
+
throw new Error(`Web viewer crashed: ${handle.panic_message()}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
parent.append(canvas);
|
|
45
|
+
this.#canvas = canvas;
|
|
46
|
+
this.#handle = handle;
|
|
47
|
+
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
stop() {
|
|
52
|
+
const canvas = this.#canvas;
|
|
53
|
+
this.#canvas = null;
|
|
54
|
+
if (canvas) {
|
|
55
|
+
canvas.remove();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const handle = this.#handle;
|
|
59
|
+
this.#handle = null;
|
|
60
|
+
if (handle) {
|
|
61
|
+
handle.destroy();
|
|
62
|
+
handle.free();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rerun-io/web-viewer",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Embed the Rerun web viewer in your app",
|
|
5
|
+
"private": false,
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build:wasm": "cargo run -p re_build_web_viewer -- --release --module -o rerun_js/web-viewer",
|
|
8
|
+
"build:types": "dts-buddy",
|
|
9
|
+
"build": "node build:wasm && build:types",
|
|
10
|
+
"publish": "npm publish --access public",
|
|
11
|
+
"prepublishOnly": "dts-buddy"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/rerun-io/rerun.git"
|
|
16
|
+
},
|
|
17
|
+
"author": "rerun-io",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/rerun-io/rerun/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://rerun.io",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./index.d.ts",
|
|
26
|
+
"import": "./index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"package.json",
|
|
31
|
+
"tsconfig.json",
|
|
32
|
+
"index.d.ts",
|
|
33
|
+
"index.d.ts.map",
|
|
34
|
+
"index.js",
|
|
35
|
+
"re_viewer.js",
|
|
36
|
+
"re_viewer_bg.js",
|
|
37
|
+
"re_viewer_bg.wasm"
|
|
38
|
+
],
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"dts-buddy": "^0.3.0"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
package/re_viewer.js
ADDED