copper3d 3.11.1 → 3.11.2

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
@@ -388,10 +388,16 @@ clears the undo stack each time a slice arrives.
388
388
  // Register once after initialization
389
389
  const callbackId = scene.addPreRenderCallbackFunction(nrrdTools.start);
390
390
 
391
- // Unregister on teardown
391
+ // Unregister on teardown, then release the instance
392
392
  scene.removePreRenderCallbackFunction(callbackId);
393
+ nrrdTools.dispose();
393
394
  ```
394
395
 
396
+ `dispose()` releases what the instance holds outside its own DOM subtree — the event router's
397
+ listeners (its window `blur` listener pins the whole engine graph), a pending slice step, and
398
+ the drawing-flag timer. Without it, an app that builds a viewer per case leaks one engine graph
399
+ per case. The instance must not be used afterwards; calling it twice is safe.
400
+
395
401
  ---
396
402
 
397
403
  ### 5. Drawing Setup
@@ -639,6 +645,7 @@ yourself. It throws on an unknown layer, or a channel outside `[1, 255]`.
639
645
  | | `switchAllSlicesArrayData(slices)` | Swap the series (resets view state) |
640
646
  | | `switchSlicesPreservingView(slices)` | Swap the series, keep slice index / zoom / pan |
641
647
  | **Render** | `start` | Frame callback — pass to render loop |
648
+ | **Lifecycle** | `dispose()` | Release the event router's listeners, a pending slice step and the drawing-flag timer. Instance unusable afterwards; safe to call twice |
642
649
  | **Layer** | `setActiveLayer(id)` | Switch drawing target layer |
643
650
  | | `getActiveLayer()` | Read current layer |
644
651
  | | `setLayerVisible(id, bool)` | Toggle layer in composite view |
@@ -371,6 +371,46 @@ function animate() {
371
371
  animate();
372
372
  ```
373
373
 
374
+ #### Teardown — `dispose()` <Badge type="tip" text="3.11.2" />
375
+
376
+ ```typescript
377
+ scene.removePreRenderCallbackFunction(callbackId);
378
+ nrrdTools.dispose();
379
+ container.remove(); // your DOM, your call
380
+ ```
381
+
382
+ `dispose()` releases what the instance holds **outside its own DOM subtree**, so a viewer that
383
+ is torn down can actually be garbage-collected:
384
+
385
+ | Released | Why it matters |
386
+ |----------|----------------|
387
+ | The event router's listeners | Its window `blur` listener closes over the router, which reaches the whole engine graph — one live listener pins the entire instance |
388
+ | A pending slice step | The `requestAnimationFrame` `setSliceMoving` coalesces into |
389
+ | The drawing-flag timer | The pending `setIsDrawFalse` timeout |
390
+
391
+ The instance must not be used afterwards. It is safe to call more than once, so an unmount
392
+ hook that may run twice needs no guard.
393
+
394
+ ::: warning It does not remove your container or free the volumes
395
+ `dispose()` deliberately stops at the boundary of what `NrrdTools` attached elsewhere. The
396
+ host element you passed to the constructor is yours to remove, and the `MaskVolume` buffers go
397
+ when the instance does. Drop your reference to `nrrdTools` after calling it.
398
+ :::
399
+
400
+ **Vue 3:**
401
+
402
+ ```typescript
403
+ import { onBeforeUnmount } from 'vue';
404
+
405
+ onBeforeUnmount(() => {
406
+ scene.removePreRenderCallbackFunction(callbackId);
407
+ nrrdTools.dispose();
408
+ });
409
+ ```
410
+
411
+ An app that builds a viewer per case and never calls this leaks one engine graph per case —
412
+ see [Scene Resources](./scene-resources) for the scene-level counterpart.
413
+
374
414
  ---
375
415
 
376
416
  ### 5. Drawing Setup
@@ -1726,6 +1766,7 @@ cap it below what the byte allows. Capping it lower is your product's call, not
1726
1766
  | | `switchAllSlicesArrayData(slices)` | Swap the loaded series (resets slice index / zoom / pan) |
1727
1767
  | | `switchSlicesPreservingView(slices)` | Swap the loaded series, keeping slice index, zoom and pan |
1728
1768
  | **Render** | `start` | Frame callback — pass to render loop |
1769
+ | **Lifecycle** | `dispose()` | Release the event router's listeners, a pending slice step and the drawing-flag timer. Instance unusable afterwards; safe to call twice |
1729
1770
  | **Layer** | `setActiveLayer(id)` | Switch drawing target layer |
1730
1771
  | | `getActiveLayer()` | Read current layer |
1731
1772
  | | `setLayerVisible(id, bool)` | Toggle layer in composite view |
@@ -130,6 +130,49 @@ scene class that has none (`disposeScene` calls it optionally).
130
130
 
131
131
  ---
132
132
 
133
+ ## 2b. `NrrdTools.dispose()` <Badge type="tip" text="3.11.2" />
134
+
135
+ ```ts
136
+ nrrdTools.dispose(): void
137
+ ```
138
+
139
+ The same idea one level up. A segmentation viewer also attaches things outside itself, and
140
+ `disposeScene()` knows nothing about it — `NrrdTools` is not a scene, so nothing calls this
141
+ for you.
142
+
143
+ | Released | Why |
144
+ |----------|-----|
145
+ | The event router's listeners | Its window `blur` listener closes over the router, which reaches the whole engine graph — canvases, `MaskVolume` buffers, undo stacks. One listener pins all of it |
146
+ | A pending slice step | The `requestAnimationFrame` that `setSliceMoving` coalesces into |
147
+ | The drawing-flag timer | The pending `setIsDrawFalse` timeout |
148
+
149
+ An app that builds a viewer per case and never calls it leaks one engine graph per case, and
150
+ each one's `blur` listener goes on firing for the life of the page — the same shape of leak as
151
+ the `resize` listener in §2a, with considerably more held behind it.
152
+
153
+ ```ts
154
+ scene.removePreRenderCallbackFunction(callbackId);
155
+ nrrdTools.dispose();
156
+ ```
157
+
158
+ The instance must not be used afterwards. Safe to call twice.
159
+
160
+ It stops at that boundary on purpose: the host element you passed to the constructor is yours
161
+ to remove, and the volumes go when the instance does. Drop your reference to it.
162
+
163
+ ::: tip Full teardown order, viewer plus scene
164
+ ```ts
165
+ scene.removePreRenderCallbackFunction(callbackId); // stop the frame callback first
166
+ nrrdTools.dispose(); // then the viewer's listeners/timers
167
+ renderer.disposeScene(sceneName); // then the scene contents
168
+ container.remove(); // finally your own DOM
169
+ ```
170
+ Unregistering the frame callback first means nothing can run against a half-disposed
171
+ instance.
172
+ :::
173
+
174
+ ---
175
+
133
176
  ## 3. Residency budget
134
177
 
135
178
  ```ts
@@ -534,6 +534,7 @@ nrrdTools.setCalculateDistanceSphere(200, 150, 42, 'skin');
534
534
  | Method | Description |
535
535
  |--------|-------------|
536
536
  | `drag(opts?)` | Enable drag-to-scroll slice navigation |
537
+ | `dispose()` | Teardown: `eventRouter.unbindAll()`, cancel the pending slice-step `requestAnimationFrame`, clear the `setIsDrawFalse` timer. Releases only what the instance attached outside its own DOM subtree — the window `blur` listener is the one that pins the whole engine graph. Instance unusable afterwards; idempotent |
537
538
  | `setAnnotationSuspended(bool)` | Block every input that can write into a mask, at `DrawToolCore.onCanvasPointerDown`. Slice scrubbing, zoom, pan and the crosshair stay live (see 7.1) |
538
539
  | `isAnnotationSuspended()` | Query the suspension state |
539
540
  | `setSliceOrientation(axis)` | Switch viewing axis. Calls `ensureAxisExtracted` for every loaded contrast first, so a narrowed-axes load can still switch planes |
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "copper3dVersion": "3.11.1",
4
- "generatedAt": "2026-09-29T01:00:06.303Z",
5
- "symbolCount": 1194,
3
+ "copper3dVersion": "3.11.2",
4
+ "generatedAt": "2026-09-29T21:39:47.021Z",
5
+ "symbolCount": 1195,
6
6
  "guides": [
7
7
  {
8
8
  "id": "4D-MRI-LV-rendering",
@@ -90,7 +90,7 @@
90
90
  "title": "NrrdTools Usage Guide",
91
91
  "summary": "Copper3D `NrrdTools` — Medical Image Segmentation Annotation Engine",
92
92
  "lang": "en",
93
- "bytes": 70593
93
+ "bytes": 72310
94
94
  },
95
95
  {
96
96
  "id": "on-demand-controls",
@@ -114,7 +114,7 @@
114
114
  "title": "copper3d — Scene Resources",
115
115
  "summary": "Freeing what a scene holds, bounding how much stays resident, and crossfading one model into another. All exported from the package entry (`copper3d`).",
116
116
  "lang": "en",
117
- "bytes": 9093
117
+ "bytes": 10866
118
118
  },
119
119
  {
120
120
  "id": "segmentation-module",
@@ -122,7 +122,7 @@
122
122
  "title": "Segmentation Module Documentation",
123
123
  "summary": "⚠️ **Note**: All line number references in this document are from historical versions. After multiple rounds of refactoring (State Management Refactor, NrrdTools God Class Split, inheritance → composition refactor), these references are ou…",
124
124
  "lang": "en",
125
- "bytes": 73632
125
+ "bytes": 73962
126
126
  },
127
127
  {
128
128
  "id": "surface-annotation-api",