@niivue/nv-web-component 1.0.0-rc.2 → 1.0.0-rc.21

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.
@@ -0,0 +1,140 @@
1
+ import { NiiVueOptions, NVImage, default as NiiVue, SLICE_TYPE } from '@niivue/niivue';
2
+ import { LayoutConfig } from './layouts';
3
+ import { ImageFromUrlOptions, NvSceneEventMap, ViewerState } from './types';
4
+ export { SLICE_TYPE };
5
+ export type NiivueCallback = (nv: NiiVue, index: number) => void;
6
+ export interface ViewerSlot {
7
+ id: string;
8
+ niivue: NiiVue;
9
+ canvasElement: HTMLCanvasElement;
10
+ containerDiv: HTMLDivElement;
11
+ ready: Promise<void>;
12
+ }
13
+ export interface NvSceneControllerSnapshot {
14
+ currentLayout: string;
15
+ viewerCount: number;
16
+ slots: number;
17
+ isBroadcasting: boolean;
18
+ isLoading: boolean;
19
+ viewerStates: ViewerState[];
20
+ }
21
+ export interface BroadcastOptions {
22
+ '2d': boolean;
23
+ '3d': boolean;
24
+ }
25
+ export interface SliceLayoutTile {
26
+ sliceType: number;
27
+ position: [number, number, number, number];
28
+ sliceMM?: number;
29
+ }
30
+ export interface SliceLayoutConfig {
31
+ label: string;
32
+ layout: SliceLayoutTile[];
33
+ }
34
+ /**
35
+ * Default slice layout: Axial as hero (80% height), coronal and sagittal below (20% height each, side by side)
36
+ */
37
+ export declare const defaultSliceLayout: SliceLayoutTile[];
38
+ /**
39
+ * Split view: sagittal left, coronal/axial stacked on the right.
40
+ */
41
+ export declare const splitSliceLayout: SliceLayoutTile[];
42
+ /**
43
+ * Tri-fan: three equal horizontal panels.
44
+ */
45
+ export declare const triSliceLayout: SliceLayoutTile[];
46
+ /**
47
+ * Stacked: three equal vertical stacks.
48
+ */
49
+ export declare const stackedSliceLayout: SliceLayoutTile[];
50
+ /**
51
+ * Quad: axial/coronal/sagittal with a render tile.
52
+ */
53
+ export declare const quadSliceLayout: SliceLayoutTile[];
54
+ /**
55
+ * Hero render with three small orthogonal slices below.
56
+ */
57
+ export declare const heroRenderSliceLayout: SliceLayoutTile[];
58
+ export declare const defaultSliceLayouts: Record<string, SliceLayoutConfig>;
59
+ type Listener = () => void;
60
+ export declare const defaultViewerOptions: Partial<NiiVueOptions>;
61
+ /**
62
+ * An NvSceneController is a declarative representation of what we want to render with Niivue.
63
+ *
64
+ * A scene can contain multiple Niivue instances. Each Niivue instance has its own
65
+ * canvas element for the WebGL2 context. All canvas elements are wrapped in container
66
+ * divs that are children of the main scene container element.
67
+ *
68
+ * Canvas elements are added/removed on-demand based on the scene definition.
69
+ *
70
+ * The scene layout controls the position of each canvas via layout functions that
71
+ * return absolute positioning styles. The scene container is responsive and maintains
72
+ * the requested layout proportionally.
73
+ */
74
+ export declare class NvSceneController {
75
+ containerElement: HTMLElement | null;
76
+ viewers: ViewerSlot[];
77
+ currentLayout: string;
78
+ slots: number;
79
+ layouts: Record<string, LayoutConfig>;
80
+ onViewerCreated?: NiivueCallback;
81
+ private listeners;
82
+ private snapshotCache;
83
+ private nextId;
84
+ private viewersById;
85
+ private broadcasting;
86
+ private broadcastOptions;
87
+ private viewerSliceLayouts;
88
+ private viewerDefaults;
89
+ private eventListeners;
90
+ private loadingCounts;
91
+ private viewerErrors;
92
+ constructor(layouts?: Record<string, LayoutConfig>, viewerDefaults?: Partial<NiiVueOptions>);
93
+ on<E extends keyof NvSceneEventMap>(event: E, cb: NvSceneEventMap[E]): () => void;
94
+ off<E extends keyof NvSceneEventMap>(event: E, cb: NvSceneEventMap[E]): void;
95
+ private emit;
96
+ subscribe: (listener: Listener) => (() => void);
97
+ getSnapshot: () => NvSceneControllerSnapshot;
98
+ private notify;
99
+ setContainerElement(element: HTMLElement | null): void;
100
+ setLayout(layoutName: string): void;
101
+ updateLayout(): void;
102
+ canAddViewer(): boolean;
103
+ getNiivue(index: number): NiiVue | undefined;
104
+ getAllNiivue(): NiiVue[];
105
+ forEachNiivue(callback: NiivueCallback): void;
106
+ private hasSyncableContent;
107
+ private safeBroadcastTo;
108
+ private rewireBroadcasting;
109
+ setBroadcasting(enabled: boolean, options?: Partial<BroadcastOptions>): void;
110
+ isBroadcasting(): boolean;
111
+ setViewerSliceLayout(index: number, layout: SliceLayoutTile[] | null): void;
112
+ getViewerSliceLayout(index: number): SliceLayoutTile[] | null;
113
+ private applySliceLayout;
114
+ getNiivueById(id: string): NiiVue | undefined;
115
+ getViewerById(id: string): ViewerSlot | undefined;
116
+ private waitForViewerReady;
117
+ loadVolume(index: number, opts: ImageFromUrlOptions): Promise<NVImage>;
118
+ loadVolumes(index: number, opts: ImageFromUrlOptions[]): Promise<NVImage[]>;
119
+ removeVolume(index: number, url: string): Promise<void>;
120
+ /**
121
+ * Look up the Niivue instance and NVImage at the given viewer and volume indices.
122
+ * Returns undefined if either index is out of bounds.
123
+ */
124
+ private findVolume;
125
+ /** Set the colormap for a volume at the given viewer and volume index. */
126
+ setColormap(viewerIndex: number, volumeIndex: number, colormap: string): Promise<void>;
127
+ /** Set the intensity range (calMin / calMax) for a volume at the given viewer and volume index. */
128
+ setCalMinMax(viewerIndex: number, volumeIndex: number, calMin: number, calMax: number): Promise<void>;
129
+ /** Set the opacity for a volume at the given viewer and volume index. */
130
+ setOpacity(viewerIndex: number, volumeIndex: number, opacity: number): Promise<void>;
131
+ private incrementLoading;
132
+ private decrementLoading;
133
+ private addError;
134
+ private getViewerIndex;
135
+ addViewer(options?: Partial<NiiVueOptions>): Promise<ViewerSlot>;
136
+ removeViewer(index: number, shouldNotify?: boolean): void;
137
+ private disposeViewer;
138
+ clearViewers(): void;
139
+ reset(): void;
140
+ }
@@ -0,0 +1,19 @@
1
+ import { default as NiiVue, ImageFromUrlOptions, NiiVueOptions, NVImage } from '@niivue/niivue';
2
+ export type { ImageFromUrlOptions, NiiVueOptions, NVImage };
3
+ export interface NvSceneEventMap {
4
+ viewerCreated: (nv: NiiVue, index: number) => void;
5
+ viewerRemoved: (index: number) => void;
6
+ locationChange: (viewerIndex: number, data: unknown) => void;
7
+ imageLoaded: (viewerIndex: number, volume: NVImage) => void;
8
+ error: (viewerIndex: number, error: unknown) => void;
9
+ volumeAdded: (viewerIndex: number, imageOptions: ImageFromUrlOptions, image: NVImage) => void;
10
+ volumeRemoved: (viewerIndex: number, url: string) => void;
11
+ colormapChanged: (viewerIndex: number, volumeIndex: number, colormap: string) => void;
12
+ intensityChanged: (viewerIndex: number, volumeIndex: number, cal_min: number, cal_max: number) => void;
13
+ opacityChanged: (viewerIndex: number, volumeIndex: number, opacity: number) => void;
14
+ }
15
+ export interface ViewerState {
16
+ id: string;
17
+ loading: number;
18
+ errors: unknown[];
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@niivue/nv-web-component",
3
- "version": "1.0.0-rc.2",
3
+ "version": "1.0.0-rc.21",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Web component bindings for NiiVue",
@@ -26,10 +26,10 @@
26
26
  "test": "bun test"
27
27
  },
28
28
  "peerDependencies": {
29
- "@niivue/niivue": "1.0.0-rc.4"
29
+ "@niivue/niivue": "1.0.0-rc.23"
30
30
  },
31
31
  "devDependencies": {
32
- "@niivue/niivue": "1.0.0-rc.4",
32
+ "@niivue/niivue": "1.0.0-rc.23",
33
33
  "@types/bun": "^1.3.12",
34
34
  "typescript": "^5.9.3",
35
35
  "vite": "^8.0.9",