@niivue/nv-ext-save-html 1.0.0-rc.1 → 1.0.0-rc.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@niivue/nv-ext-save-html",
3
- "version": "1.0.0-rc.1",
3
+ "version": "1.0.0-rc.4",
4
4
  "type": "module",
5
5
  "description": "Export a NiiVue scene as a self-contained HTML file",
6
6
  "main": "./dist/nv-ext-save-html.js",
@@ -16,10 +16,10 @@
16
16
  "dist"
17
17
  ],
18
18
  "peerDependencies": {
19
- "@niivue/niivue": "1.0.0-rc.1"
19
+ "@niivue/niivue": "1.0.0-rc.4"
20
20
  },
21
21
  "devDependencies": {
22
- "@niivue/niivue": "1.0.0-rc.1",
22
+ "@niivue/niivue": "1.0.0-rc.4",
23
23
  "typescript": "~5.8.3",
24
24
  "vite": "^6.3.2",
25
25
  "vite-plugin-dts": "^4.5.4"
@@ -27,5 +27,8 @@
27
27
  "scripts": {
28
28
  "build": "npx vite build",
29
29
  "typecheck": "bunx tsc --noEmit"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
30
33
  }
31
34
  }
package/dist/index.d.ts DELETED
@@ -1,39 +0,0 @@
1
- import { default as NiiVueGPU } from '@niivue/niivue';
2
- export interface SaveHTMLOptions {
3
- /**
4
- * Fully self-contained niivue ESM bundle as a source code string.
5
- *
6
- * The bundle must export `NiiVueGPU` as its **default export** and must
7
- * have all dependencies (cbor-x, gl-matrix, nifti-reader-js, etc.) inlined.
8
- *
9
- * Build one with e.g. `vite build` using `rollupOptions.external: []`.
10
- */
11
- niivueBundleSource: string;
12
- /** Canvas element ID in the generated HTML (default: `"gl1"`). */
13
- canvasId?: string;
14
- /** HTML `<title>` (default: `"NiiVue Scene"`). */
15
- title?: string;
16
- }
17
- /**
18
- * Generate a self-contained HTML string that embeds the current NiiVue scene.
19
- *
20
- * The returned HTML includes the niivue library and all loaded data (volumes,
21
- * meshes, drawings, settings). Opening the HTML file in a browser will
22
- * recreate the scene — no server or external files needed.
23
- *
24
- * @param nv - The NiiVue instance whose scene to export.
25
- * @param options - See {@link SaveHTMLOptions}.
26
- * @returns A complete HTML document as a string.
27
- */
28
- export declare function generateHTML(nv: NiiVueGPU, options: SaveHTMLOptions): Promise<string>;
29
- /**
30
- * Download the current NiiVue scene as a self-contained HTML file.
31
- *
32
- * Convenience wrapper around {@link generateHTML} that triggers a browser
33
- * download.
34
- *
35
- * @param nv - The NiiVue instance whose scene to export.
36
- * @param filename - Name of the downloaded file (default: `"scene.html"`).
37
- * @param options - See {@link SaveHTMLOptions}.
38
- */
39
- export declare function saveHTML(nv: NiiVueGPU, filename: string | undefined, options: SaveHTMLOptions): Promise<void>;
@@ -1,126 +0,0 @@
1
- async function l(e) {
2
- const a = new CompressionStream("gzip"), t = a.writable.getWriter();
3
- return t.write(e), t.close(), new Uint8Array(await new Response(a.readable).arrayBuffer());
4
- }
5
- function d(e) {
6
- const t = [];
7
- for (let n = 0; n < e.length; n += 32768)
8
- t.push(String.fromCharCode(...e.subarray(n, n + 32768)));
9
- return btoa(t.join(""));
10
- }
11
- function u(e) {
12
- return e.replace(/<\/script/gi, "<\\/script");
13
- }
14
- function p(e) {
15
- return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
16
- }
17
- function m(e, a, t, n) {
18
- return `<!DOCTYPE html>
19
- <html lang="en">
20
- <head>
21
- <meta charset="utf-8" />
22
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
23
- <title>${p(n)}</title>
24
- <style>
25
- html, body {
26
- margin: 0;
27
- padding: 0;
28
- height: 100%;
29
- width: 100%;
30
- overflow: hidden;
31
- background: #000;
32
- font-family: system-ui, Arial, Helvetica, sans-serif;
33
- user-select: none;
34
- }
35
- main {
36
- position: relative;
37
- width: 100%;
38
- height: 100%;
39
- }
40
- canvas {
41
- position: absolute;
42
- width: 100%;
43
- height: 100%;
44
- cursor: crosshair;
45
- }
46
- canvas:focus {
47
- outline: none;
48
- }
49
- </style>
50
- </head>
51
- <body>
52
- <main>
53
- <canvas id="${t}"></canvas>
54
- </main>
55
-
56
- <!-- NiiVue library bundle (inert — not executed by the browser) -->
57
- <script id="__niivue_bundle__" type="text/plain">
58
- ${u(e)}
59
- <\/script>
60
-
61
- <!-- NVD document data as gzip-compressed, base-64-encoded CBOR (inert) -->
62
- <script id="__nvd_data__" type="text/plain">
63
- ${a}
64
- <\/script>
65
-
66
- <!-- Loader: import the bundle, decode the document, restore the scene -->
67
- <script type="module">
68
- // 1. Dynamic-import the embedded niivue bundle
69
- const bundleSrc = document.getElementById("__niivue_bundle__").textContent;
70
- const blob = new Blob([bundleSrc], { type: "text/javascript" });
71
- const blobUrl = URL.createObjectURL(blob);
72
- const niivueModule = await import(blobUrl);
73
- URL.revokeObjectURL(blobUrl);
74
- const NiiVueGPU = niivueModule.default ?? niivueModule.NiiVueGPU;
75
-
76
- // 2. Decode base-64, gzip-decompress, and wrap as a File
77
- const base64 = document.getElementById("__nvd_data__").textContent.trim();
78
- const raw = atob(base64);
79
- const compressed = new Uint8Array(raw.length);
80
- for (let i = 0; i < raw.length; i++) compressed[i] = raw.charCodeAt(i);
81
- const ds = new DecompressionStream("gzip");
82
- const writer = ds.writable.getWriter();
83
- writer.write(compressed);
84
- writer.close();
85
- const bytes = new Uint8Array(await new Response(ds.readable).arrayBuffer());
86
- const file = new File([bytes], "scene.nvd");
87
-
88
- // 3. Create NiiVue, attach to canvas, and load the document
89
- const nv = new NiiVueGPU();
90
- await nv.attachTo("${t}");
91
- await nv.loadDocument(file);
92
- // The serialized document has an empty matcap to avoid baking in
93
- // environment-specific URLs. Restore the default matcap from this bundle.
94
- if (nv.opts?.matcaps) {
95
- const defaultMatcap = Object.values(nv.opts.matcaps)[0];
96
- if (defaultMatcap) await nv.loadMatcap(defaultMatcap);
97
- }
98
- <\/script>
99
- </body>
100
- </html>`;
101
- }
102
- async function b(e, a) {
103
- const {
104
- niivueBundleSource: t,
105
- canvasId: n = "gl1",
106
- title: r = "NiiVue Scene"
107
- } = a;
108
- if (!t)
109
- throw new Error(
110
- "nv-ext-save-html: niivueBundleSource is required. Provide the full source of a self-contained niivue ESM bundle."
111
- );
112
- const o = e.volumeMatcap;
113
- e.model.volume.matcap = "";
114
- const i = e.serializeDocument();
115
- e.model.volume.matcap = o;
116
- const c = await l(i), s = d(c);
117
- return m(t, s, n, r);
118
- }
119
- async function h(e, a = "scene.html", t) {
120
- const n = await b(e, t), r = new Blob([n], { type: "text/html" }), o = URL.createObjectURL(r), i = document.createElement("a");
121
- i.href = o, i.download = a, document.body.appendChild(i), i.click(), document.body.removeChild(i), URL.revokeObjectURL(o);
122
- }
123
- export {
124
- b as generateHTML,
125
- h as saveHTML
126
- };