@niivue/nv-ext-save-html 1.0.0-rc.3 → 1.0.0-rc.31

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
@@ -13,10 +13,10 @@ Requires `@niivue/niivue` as a peer dependency.
13
13
  ## Usage
14
14
 
15
15
  ```ts
16
- import NiiVueGPU from '@niivue/niivue'
16
+ import NiiVue from '@niivue/niivue'
17
17
  import { saveHTML } from '@niivue/nv-ext-save-html'
18
18
 
19
- const nv = new NiiVueGPU()
19
+ const nv = new NiiVue()
20
20
  await nv.attachTo('gl1')
21
21
  await nv.loadVolumes([{ url: 'brain.nii.gz' }])
22
22
 
package/dist/gzip.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Gzip helpers built on the Web Streams API (available in all modern browsers).
3
+ *
4
+ * Split out of `index.ts` so it can be unit tested: `index.ts` imports
5
+ * `@niivue/niivue`, whose module graph uses Vite's `import.meta.glob` and cannot
6
+ * be loaded by the Bun test runner.
7
+ */
8
+ /**
9
+ * Gzip-compress a Uint8Array.
10
+ *
11
+ * Start consuming `readable` BEFORE awaiting the write/close. A CompressionStream
12
+ * is a TransformStream whose readable side applies backpressure once its queue
13
+ * fills; if nothing is reading, `writer.write()` / `writer.close()` never settle
14
+ * and this hangs forever. In Chromium that happens for inputs as small as ~1 MB —
15
+ * i.e. every real document — so the read must already be in flight. (This is the
16
+ * same shape niivue's own `codecs/NVGz.ts` compress() uses.)
17
+ *
18
+ * `chunk` is a copy: a view backed by a SharedArrayBuffer (see the extension
19
+ * context's `acquireSharedBuffer`) cannot be enqueued directly.
20
+ */
21
+ export declare function gzipCompress(data: Uint8Array): Promise<Uint8Array>;
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { default as NiiVueGPU } from '@niivue/niivue';
1
+ import { default as NiiVue } from '@niivue/niivue';
2
2
  export interface SaveHTMLOptions {
3
3
  /**
4
4
  * Fully self-contained niivue ESM bundle as a source code string.
5
5
  *
6
- * The bundle must export `NiiVueGPU` as its **default export** and must
6
+ * The bundle must export `NiiVue` as its **default export** and must
7
7
  * have all dependencies (cbor-x, gl-matrix, nifti-reader-js, etc.) inlined.
8
8
  *
9
9
  * Build one with e.g. `vite build` using `rollupOptions.external: []`.
@@ -25,7 +25,7 @@ export interface SaveHTMLOptions {
25
25
  * @param options - See {@link SaveHTMLOptions}.
26
26
  * @returns A complete HTML document as a string.
27
27
  */
28
- export declare function generateHTML(nv: NiiVueGPU, options: SaveHTMLOptions): Promise<string>;
28
+ export declare function generateHTML(nv: NiiVue, options: SaveHTMLOptions): Promise<string>;
29
29
  /**
30
30
  * Download the current NiiVue scene as a self-contained HTML file.
31
31
  *
@@ -36,4 +36,4 @@ export declare function generateHTML(nv: NiiVueGPU, options: SaveHTMLOptions): P
36
36
  * @param filename - Name of the downloaded file (default: `"scene.html"`).
37
37
  * @param options - See {@link SaveHTMLOptions}.
38
38
  */
39
- export declare function saveHTML(nv: NiiVueGPU, filename: string | undefined, options: SaveHTMLOptions): Promise<void>;
39
+ export declare function saveHTML(nv: NiiVue, filename: string | undefined, options: SaveHTMLOptions): Promise<void>;
@@ -1,6 +1,8 @@
1
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());
2
+ const a = new CompressionStream("gzip"), t = new Uint8Array(e.byteLength);
3
+ t.set(e);
4
+ const n = new Response(a.readable).arrayBuffer(), o = a.writable.getWriter();
5
+ return await o.write(t), await o.close(), new Uint8Array(await n);
4
6
  }
5
7
  function d(e) {
6
8
  const t = [];
@@ -71,7 +73,7 @@ ${a}
71
73
  const blobUrl = URL.createObjectURL(blob);
72
74
  const niivueModule = await import(blobUrl);
73
75
  URL.revokeObjectURL(blobUrl);
74
- const NiiVueGPU = niivueModule.default ?? niivueModule.NiiVueGPU;
76
+ const NiiVue = niivueModule.default ?? niivueModule.NiiVue;
75
77
 
76
78
  // 2. Decode base-64, gzip-decompress, and wrap as a File
77
79
  const base64 = document.getElementById("__nvd_data__").textContent.trim();
@@ -86,7 +88,7 @@ ${a}
86
88
  const file = new File([bytes], "scene.nvd");
87
89
 
88
90
  // 3. Create NiiVue, attach to canvas, and load the document
89
- const nv = new NiiVueGPU();
91
+ const nv = new NiiVue();
90
92
  await nv.attachTo("${t}");
91
93
  await nv.loadDocument(file);
92
94
  // The serialized document has an empty matcap to avoid baking in
@@ -103,22 +105,22 @@ async function b(e, a) {
103
105
  const {
104
106
  niivueBundleSource: t,
105
107
  canvasId: n = "gl1",
106
- title: r = "NiiVue Scene"
108
+ title: o = "NiiVue Scene"
107
109
  } = a;
108
110
  if (!t)
109
111
  throw new Error(
110
112
  "nv-ext-save-html: niivueBundleSource is required. Provide the full source of a self-contained niivue ESM bundle."
111
113
  );
112
- const o = e.volumeMatcap;
114
+ const r = e.volumeMatcap;
113
115
  e.model.volume.matcap = "";
114
116
  const i = e.serializeDocument();
115
- e.model.volume.matcap = o;
117
+ e.model.volume.matcap = r;
116
118
  const c = await l(i), s = d(c);
117
- return m(t, s, n, r);
119
+ return m(t, s, n, o);
118
120
  }
119
121
  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
+ const n = await b(e, t), o = new Blob([n], { type: "text/html" }), r = URL.createObjectURL(o), i = document.createElement("a");
123
+ i.href = r, i.download = a, document.body.appendChild(i), i.click(), document.body.removeChild(i), URL.revokeObjectURL(r);
122
124
  }
123
125
  export {
124
126
  b as generateHTML,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@niivue/nv-ext-save-html",
3
- "version": "1.0.0-rc.3",
3
+ "version": "1.0.0-rc.31",
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": "workspace:*"
19
+ "@niivue/niivue": "1.0.0-rc.31"
20
20
  },
21
21
  "devDependencies": {
22
- "@niivue/niivue": "workspace:*",
22
+ "@niivue/niivue": "1.0.0-rc.31",
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
  }