freebrowse 2.5.0-next.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 (73) hide show
  1. package/README.md +134 -0
  2. package/dist-lib/index.js +21492 -0
  3. package/dist-lib/index.js.map +1 -0
  4. package/dist-lib/react.js +10790 -0
  5. package/dist-lib/react.js.map +1 -0
  6. package/dist-lib/style.css +1 -0
  7. package/dist-lib/types/components/canvas-area.d.ts +10 -0
  8. package/dist-lib/types/components/dialogs/imaging-upload-confirmation-dialog.d.ts +6 -0
  9. package/dist-lib/types/components/dialogs/remove-dialog.d.ts +6 -0
  10. package/dist-lib/types/components/dialogs/save-dialog.d.ts +14 -0
  11. package/dist-lib/types/components/dialogs/session-delete-confirmation-dialog.d.ts +6 -0
  12. package/dist-lib/types/components/dialogs/settings-dialog.d.ts +6 -0
  13. package/dist-lib/types/components/drag-mode-selector.d.ts +9 -0
  14. package/dist-lib/types/components/file-list.d.ts +12 -0
  15. package/dist-lib/types/components/footer.d.ts +1 -0
  16. package/dist-lib/types/components/freebrowse.d.ts +32 -0
  17. package/dist-lib/types/components/header.d.ts +6 -0
  18. package/dist-lib/types/components/image-canvas.d.ts +7 -0
  19. package/dist-lib/types/components/image-uploader.d.ts +6 -0
  20. package/dist-lib/types/components/sidebar.d.ts +56 -0
  21. package/dist-lib/types/components/tabs/ai-annotation-tab.d.ts +20 -0
  22. package/dist-lib/types/components/tabs/data-tab.d.ts +6 -0
  23. package/dist-lib/types/components/tabs/drawing-tab.d.ts +17 -0
  24. package/dist-lib/types/components/tabs/nvd-tab.d.ts +6 -0
  25. package/dist-lib/types/components/tabs/scene-details-tab.d.ts +22 -0
  26. package/dist-lib/types/components/tabs/surface-details-tab.d.ts +20 -0
  27. package/dist-lib/types/components/ui/button.d.ts +10 -0
  28. package/dist-lib/types/components/ui/checkbox.d.ts +4 -0
  29. package/dist-lib/types/components/ui/dialog.d.ts +15 -0
  30. package/dist-lib/types/components/ui/input.d.ts +5 -0
  31. package/dist-lib/types/components/ui/label.d.ts +4 -0
  32. package/dist-lib/types/components/ui/labeled-slider-with-input.d.ts +14 -0
  33. package/dist-lib/types/components/ui/radio-group.d.ts +5 -0
  34. package/dist-lib/types/components/ui/scroll-area.d.ts +5 -0
  35. package/dist-lib/types/components/ui/select.d.ts +5 -0
  36. package/dist-lib/types/components/ui/slider.d.ts +4 -0
  37. package/dist-lib/types/components/ui/tabs.d.ts +7 -0
  38. package/dist-lib/types/components/ui/toggle-group.d.ts +7 -0
  39. package/dist-lib/types/components/ui/toggle.d.ts +9 -0
  40. package/dist-lib/types/components/view-selector.d.ts +7 -0
  41. package/dist-lib/types/components/viewer-shell.d.ts +13 -0
  42. package/dist-lib/types/hooks/use-ai-capabilities.d.ts +1 -0
  43. package/dist-lib/types/hooks/use-ai-session.d.ts +9 -0
  44. package/dist-lib/types/hooks/use-drawing.d.ts +27 -0
  45. package/dist-lib/types/hooks/use-file-loading.d.ts +15 -0
  46. package/dist-lib/types/hooks/use-magic-wand.d.ts +15 -0
  47. package/dist-lib/types/hooks/use-mesh-layers.d.ts +21 -0
  48. package/dist-lib/types/hooks/use-save.d.ts +12 -0
  49. package/dist-lib/types/hooks/use-surfaces.d.ts +16 -0
  50. package/dist-lib/types/hooks/use-viewer-options.d.ts +42 -0
  51. package/dist-lib/types/hooks/use-volumes.d.ts +39 -0
  52. package/dist-lib/types/lib/confirmations.d.ts +4 -0
  53. package/dist-lib/types/lib/default-niivue-options.d.ts +16 -0
  54. package/dist-lib/types/lib/deployment-config.d.ts +66 -0
  55. package/dist-lib/types/lib/niivue-helpers.d.ts +27 -0
  56. package/dist-lib/types/lib/nvd-volume-urls.d.ts +26 -0
  57. package/dist-lib/types/lib/random-session-name.d.ts +1 -0
  58. package/dist-lib/types/lib/utils.d.ts +2 -0
  59. package/dist-lib/types/lib.d.ts +16 -0
  60. package/dist-lib/types/mount.d.ts +49 -0
  61. package/dist-lib/types/react.d.ts +10 -0
  62. package/dist-lib/types/store/ai-slice.d.ts +25 -0
  63. package/dist-lib/types/store/drawing-slice.d.ts +7 -0
  64. package/dist-lib/types/store/index.d.ts +21 -0
  65. package/dist-lib/types/store/location-slice.d.ts +7 -0
  66. package/dist-lib/types/store/niivue-store-sync.d.ts +41 -0
  67. package/dist-lib/types/store/niivue-sync.d.ts +57 -0
  68. package/dist-lib/types/store/save-slice.d.ts +9 -0
  69. package/dist-lib/types/store/surface-slice.d.ts +15 -0
  70. package/dist-lib/types/store/types.d.ts +69 -0
  71. package/dist-lib/types/store/viewer-slice.d.ts +31 -0
  72. package/dist-lib/types/store/volume-slice.d.ts +13 -0
  73. package/package.json +130 -0
package/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # freebrowse
2
+
3
+ FreeBrowse is a browser-based neuroimaging viewer built on [NiiVue](https://github.com/niivue/mono).
4
+ This package lets another web app mount the FreeBrowse UI around a NiiVue instance the host
5
+ controls. Full project documentation: https://github.com/freesurfer/freebrowse
6
+
7
+ ## Embedding FreeBrowse in your own app (npm package)
8
+
9
+ FreeBrowse is published to npm as `freebrowse`. Until the niivue-mono migration lands on
10
+ `main` it is available under the `next` dist-tag only:
11
+
12
+ ```bash
13
+ npm install freebrowse@next @niivue/niivue@1.0.0-rc.13
14
+ ```
15
+
16
+ `@niivue/niivue` is a peer dependency: **you** create the NiiVue instance, FreeBrowse renders
17
+ its UI for it, and anything you do to the instance through niivue's API shows up in that UI
18
+ (see [Driving FreeBrowse from your own code](#driving-freebrowse-from-your-own-code)). A
19
+ classic-niivue (0.x) instance cannot be used — the package targets niivue 1.0.
20
+
21
+ **Vanilla JavaScript** (React is bundled; nothing else to install):
22
+
23
+ ```js
24
+ import { NiiVue } from "@niivue/niivue";
25
+ import { mountFreeBrowse } from "freebrowse";
26
+ import "freebrowse/style.css";
27
+
28
+ const nv = new NiiVue({ backgroundColor: [0, 0, 0, 1] });
29
+ const fb = mountFreeBrowse(document.getElementById("viewer"), { nv });
30
+ await nv.addVolume({ url: "https://niivue.com/demos/images/mni152.nii.gz" });
31
+ // ... later
32
+ fb.destroy();
33
+ ```
34
+
35
+ **React 19 hosts** (`react` / `react-dom` are peers on this entry, not bundled):
36
+
37
+ ```jsx
38
+ import { FreeBrowse, configureFreeBrowse } from "freebrowse/react";
39
+ import "freebrowse/style.css";
40
+
41
+ configureFreeBrowse({ backend: null }); // once, before the first render
42
+ <FreeBrowse nv={nv} hostInstance />
43
+ ```
44
+
45
+ `mountFreeBrowse(container, options)` options, all optional:
46
+
47
+ | option | default | meaning |
48
+ | --- | --- | --- |
49
+ | `nv` | created for you | Your NiiVue instance. When given, FreeBrowse seeds its UI from the instance's settings and never pushes its own defaults onto it. |
50
+ | `backend` | `null` | `{ dataUrl, aiUrl }` of a FreeBrowse backend. `null` hides Save-to-server, the Data/NVD tabs and AI. |
51
+ | `persist` | `"freebrowse-user-settings"` | localStorage key for user preferences, or `false` to keep them in memory. |
52
+ | `readUrlParams` | `false` | Honour `?nvd=` / `?vol=` on the host page URL. |
53
+ | `exposeGlobal` | `false` | Also publish the instance as `window.freebrowse.nv`. |
54
+ | `downloadDisabled` | `false` | Disable the Download button and niivue's save-to-disk methods. |
55
+ | `dragDrop` | `true` | `false` turns off drag-and-drop loading (niivue's canvas drop and the drop zone) and shows the canvas from the start — for hosts that load data themselves. |
56
+ | `sidebar` | `true` | Show the sidebar initially; the header button still toggles it. |
57
+ | `footer` | `true` | Show the footer (coordinate readout) initially. |
58
+
59
+ The handle returned has `nv` and `destroy()`. **One mount at a time**: FreeBrowse's UI state is a
60
+ single store, so a second concurrent mount throws; destroy the first one. Styles are scoped to
61
+ the mounted element (`.freebrowse-root`) and never touch your page's `html`/`body`; import
62
+ `freebrowse/style.css` once. Working examples for both entries live in
63
+ [`frontend/examples/`](https://github.com/freesurfer/freebrowse/tree/main/frontend/examples/).
64
+
65
+ Releasing (maintainers): bump `version` in `frontend/package.json` (the app and the package
66
+ share it; pre-merge builds use a `-next.N` suffix), then from `frontend/`:
67
+
68
+ ```bash
69
+ npm run build:package && npm run pack:check # publint + arethetypeswrong on the tarball
70
+ npm publish --tag next # `latest` is reserved for the main-branch release
71
+ ```
72
+
73
+ ## Driving FreeBrowse from your own code
74
+
75
+ FreeBrowse's UI is a *derived view* of its NiiVue instance: the React store is
76
+ updated only by the events niivue emits, and FreeBrowse's own controls go
77
+ through the same path as any external caller. The live instance is exposed as
78
+ `window.freebrowse.nv`, so from the browser console (or an embedding page) you
79
+ can drive the viewer with niivue's API and watch the sidebar, toolbar and footer
80
+ follow:
81
+
82
+ ```js
83
+ const nv = window.freebrowse.nv;
84
+ await nv.addVolume({ url: "https://niivue.com/demos/images/mni152.nii.gz" });
85
+ await nv.setVolume(0, { colormap: "Hot", opacity: 0.8 }); // sidebar updates
86
+ nv.sliceType = 4; // toolbar switches to Render
87
+ await nv.loadDocument(fileOrUrl); // document path, same events
88
+ ```
89
+
90
+ **Supported mutations**: anything that emits an event: `setVolume(i, {...})`,
91
+ `setMesh(i, {...})`, `setMeshLayerProperty`, `add`/`remove`/`move` methods, the
92
+ flat setters (`sliceType`, `showRender`, `isRadiological`, `crosshairColor`,
93
+ `drawOpacity`, …), the drawing API and `loadDocument`.
94
+
95
+ **Not supported**: raw field writes such as `nv.volumes[0].colormap = "Hot"`.
96
+ Niivue-mono volumes and meshes are plain objects, so nothing observes the write
97
+ and the UI will not update.
98
+
99
+ ## NiiVue documents (`.nvd`)
100
+
101
+ A FreeBrowse scene is a plain [NiiVue document](https://github.com/niivue/mono/blob/main/packages/niivue/src/NVDocument.ts)
102
+ (`NVDocumentData`, schema version 9).
103
+
104
+ The **Download** dialog writes it as JSON (text) or CBOR (binary);
105
+ loading detects the encoding, so either can be passed to `?nvd=`, dropped onto
106
+ the viewer, or embedded in a single-file build.
107
+
108
+ - **Downloaded documents are self-contained**: every volume's voxels are embedded
109
+ (`volumes[i].data`), so the file stands alone. Meshes are embedded as geometry
110
+ too, but mesh *overlays* (curvature, thickness) are not yet persisted — see
111
+ [#43](https://github.com/freesurfer/freebrowse/issues/43).
112
+ - **Saved-to-backend documents are linked**: volumes are uploaded as `.nii.gz`
113
+ and the document references them by URL. The one FreeBrowse-specific save
114
+ behaviour is `retargetVolumeUrls` (`frontend/src/lib/nvd-volume-urls.ts`),
115
+ which points each volume entry at the path it is being uploaded to; a volume
116
+ given no destination keeps its bytes.
117
+ - **Loading changes only what the document sets.** FreeBrowse loads with
118
+ niivue's `fill: "current"` policy, so a document that says nothing about,
119
+ say, the crosshair colour or the view layout leaves the current viewer
120
+ settings alone.
121
+
122
+ **Documents from FreeBrowse ≤ 2.4 (classic niivue) do not load** — the viewer
123
+ reports *"This .nvd predates the niivue document schema"*. Convert them once
124
+ with the stdlib-only migration script, which writes `<name>.v9.nvd` next to
125
+ each input (originals are never touched) and handles documents with embedded
126
+ volumes:
127
+
128
+ ```bash
129
+ python3 scripts/migrate-nvd.py path/to/docs/ # directory, file or glob
130
+ python3 scripts/migrate-nvd.py scene.nvd --cbor # binary output (needs cbor2)
131
+ ```
132
+
133
+ `scripts/nvd-embed.py` embeds a document into a single-file build (see
134
+ [Build](#build)), and `python3 -m pytest` runs the script's tests.