copper3d 4.1.2 → 4.1.3

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
@@ -491,8 +491,11 @@ nrrdTools.drag({
491
491
 
492
492
  ```typescript
493
493
  nrrdTools.draw({
494
- getMaskData: (sliceData, layerId, channelId, sliceIndex, axis, width, height, clearFlag?) => {
495
- sendSliceToBackend({ sliceData, layerId, channelId, sliceIndex, axis, width, height, clearFlag });
494
+ getMaskData: (sliceData, layerId, channelId, sliceIndex, axis, width, height, clearFlag, history) => {
495
+ // `history` is set only for undo/redo. On those, channelId is the *active* channel,
496
+ // which need not be the one that changed — history.channels is.
497
+ const channels = history ? history.channels : [channelId];
498
+ sendSliceToBackend({ sliceData, layerId, channels, sliceIndex, axis, width, height, clearFlag });
496
499
  },
497
500
  onClearLayerVolume: (layerId) => notifyBackendLayerCleared(layerId),
498
501
  getSphereData: (sphereOrigin, sphereRadius) => sendSphereToBackend({ sphereOrigin, sphereRadius }),
@@ -849,11 +852,18 @@ interface RGBAColor { r: number; g: number; b: number; a: number; } // 0-255
849
852
 
850
853
  type ChannelColorMap = Record<number, RGBAColor>; // key = channel number, 1-255
851
854
 
855
+ // What an undo or redo changed; getMaskData's last argument, set only for undo/redo
856
+ interface IMaskHistoryChange {
857
+ /** Channels whose voxels the undone or redone delta changed, ascending. */
858
+ channels: number[];
859
+ }
860
+
852
861
  interface IDrawOpts {
853
862
  getMaskData?: (
854
863
  sliceData: Uint8Array, layerId: string, channelId: number,
855
864
  sliceIndex: number, axis: 'x' | 'y' | 'z',
856
- width: number, height: number, clearFlag?: boolean
865
+ width: number, height: number, clearFlag?: boolean,
866
+ history?: IMaskHistoryChange
857
867
  ) => void;
858
868
  onClearLayerVolume?: (layerId: string) => void;
859
869
  getSphereData?: (sphereOrigin: number[], sphereRadius: number) => void;
@@ -99,10 +99,22 @@ All read-only.
99
99
 
100
100
  | Tool | What it does |
101
101
  |---|---|
102
- | `copper3d_search_api` | Search by name, module, summary or parameter type. Members are indexed on their own, so `aiApplyMask` finds `NrrdTools.aiApplyMask` |
103
- | `copper3d_get_symbol` | One symbol in full: signature, every parameter, return type, source location, related guides |
104
- | `copper3d_list_guides` | Table of contents for the hand-written guides |
105
- | `copper3d_get_guide` | Full markdown of one guide |
102
+ | `copper3d_search_api` | Search by name, module, summary or parameter type. Members are indexed on their own, so `aiApplyMask` finds `NrrdTools.aiApplyMask`. Several words are fine (`copperRenderer createScene`) — symbols matching all of them rank first. `limit` (or `max_results`) caps the results |
103
+ | `copper3d_get_symbol` | One symbol in full: signature, every parameter, return type, source location, related guides. On a class or interface, every member with its signature |
104
+ | `copper3d_list_guides` | Table of contents for the hand-written guides, with their sizes |
105
+ | `copper3d_get_guide` | Markdown of one guide. A guide over 20K characters comes back as its **outline**; pass `section` (`"4"`, `"4.2"`, or a title) to read one part |
106
+
107
+ ::: tip A miss is a miss, not proof of absence
108
+ The index holds names, signatures and summaries — not behaviour. When nothing matches, the
109
+ reply says so and points on to the type declarations and guides inside the installed package,
110
+ rather than letting an assistant conclude the API does not exist.
111
+ :::
112
+
113
+ ::: warning Replies stay under 20K characters
114
+ Claude Code refuses larger tool results, saving them to a file and leaving the assistant to
115
+ grep it. That is why a long guide is served as an outline plus sections rather than in one
116
+ piece.
117
+ :::
106
118
 
107
119
  ## Options
108
120
 
@@ -510,7 +510,8 @@ nrrdTools.draw({
510
510
  axis: 'x' | 'y' | 'z', // Current viewing axis
511
511
  width: number, // Slice width in voxels
512
512
  height: number, // Slice height in voxels
513
- clearFlag?: boolean // true if the user cleared the slice
513
+ clearFlag?: boolean, // true if the user cleared the slice
514
+ history?: IMaskHistoryChange // set only for undo/redo — see below
514
515
  ) => {
515
516
  sendSliceToBackend({ sliceData, layerId, channelId, sliceIndex, axis, width, height, clearFlag });
516
517
  },
@@ -552,6 +553,38 @@ nrrdTools.draw({
552
553
  });
553
554
  ```
554
555
 
556
+ ##### `history`: which channels an undo actually touched <Badge type="tip" text="4.1.3" />
557
+
558
+ `getMaskData` fires for undo and redo as well as for strokes. On those, **`channelId` is not
559
+ the channel that changed** — it is whatever channel happens to be active. The `history`
560
+ argument, set only for undo/redo, names the channels the restored delta really touched:
561
+
562
+ ```typescript
563
+ interface IMaskHistoryChange {
564
+ /** Channels whose voxels the undone or redone delta changed, ascending. */
565
+ channels: number[];
566
+ }
567
+ ```
568
+
569
+ ::: warning This matters if you sync per channel
570
+ A backend keyed on `channelId` attributes an undo to the active channel, which may have
571
+ nothing to do with it — undo channel 3's stroke while channel 1 is selected and the change
572
+ lands on channel 1. Branch on `history` instead:
573
+
574
+ ```typescript
575
+ getMaskData: (sliceData, layerId, channelId, sliceIndex, axis, w, h, clearFlag, history) => {
576
+ const channels = history ? history.channels : [channelId];
577
+ sendSliceToBackend({ sliceData, layerId, channels, sliceIndex, axis, w, h, clearFlag });
578
+ },
579
+ ```
580
+
581
+ `history.channels` can hold more than one channel — a single delta may have crossed several —
582
+ and it can be empty if the delta changed only background voxels.
583
+ :::
584
+
585
+ Because a voxel's value *is* its channel in a label volume, the set is computed by comparing
586
+ the slice before and after the delta, with background (`0`) excluded.
587
+
555
588
  #### 5.3 SphereTool — 3D Sphere Placement & Distance Calculator
556
589
 
557
590
  The SphereTool provides unified sphere placement with 4 sphere types controlled by `gui_states.mode.activeSphereType`. The active type determines which origin and color are used. The old separate "Calculator" mode has been merged into SphereTool.
@@ -1299,6 +1332,17 @@ window.addEventListener('keydown', (e) => {
1299
1332
  | Scroll:Zoom shortcut | `Ctrl+1` |
1300
1333
  | Scroll:Slice shortcut | `Ctrl+2` |
1301
1334
 
1335
+ Undo and redo are taken with `Ctrl` / `Meta` held: `Ctrl+Z`, and `Ctrl+Y` or `Ctrl+Shift+Z`.
1336
+
1337
+ ::: tip Undo and redo now cancel the browser default <Badge type="tip" text="4.1.3" />
1338
+ Both call `preventDefault()`. Without it the browser also ran its own page-level undo, which
1339
+ reverts the last text typed anywhere on the page and moves focus there — so a clinician
1340
+ undoing a stroke could find a form field behind the viewer silently rolled back instead.
1341
+
1342
+ This applies while shortcuts are active. `enterKeyboardConfig()` still suppresses the whole
1343
+ set, so a focused input keeps normal browser undo.
1344
+ :::
1345
+
1302
1346
  ::: warning Sphere mode no longer has a shortcut <Badge type="warning" text="breaking in 3.11.5" />
1303
1347
  The `sphere: "q"` binding is **gone**, and `sphere` has been removed from
1304
1348
  `IKeyBoardSettings`. Sphere mode is now entered only through `setMode("sphere")` — which is
@@ -1865,7 +1909,8 @@ interface IDrawOpts {
1865
1909
  axis: 'x' | 'y' | 'z',
1866
1910
  width: number,
1867
1911
  height: number,
1868
- clearFlag?: boolean
1912
+ clearFlag?: boolean,
1913
+ history?: IMaskHistoryChange // undo/redo only
1869
1914
  ) => void;
1870
1915
  onClearLayerVolume?: (layerId: string) => void;
1871
1916
  getSphereData?: (sphereOrigin: number[], sphereRadius: number) => void;
@@ -1901,6 +1946,12 @@ interface IKeyBoardSettings {
1901
1946
  }
1902
1947
 
1903
1948
  // 3D coordinate (used in sphere position callbacks)
1949
+ // What an undo or redo changed; passed as getMaskData's last argument
1950
+ interface IMaskHistoryChange {
1951
+ /** Channels whose voxels the undone or redone delta changed, ascending. */
1952
+ channels: number[];
1953
+ }
1954
+
1904
1955
  interface ICommXYZ {
1905
1956
  x: number;
1906
1957
  y: number;
@@ -818,12 +818,32 @@ onMaskChanged: (
818
818
  axis: "x" | "y" | "z", // Current axis
819
819
  width: number, // Slice width
820
820
  height: number, // Slice height
821
- clearFlag: boolean // Whether this is a clear operation
821
+ clearFlag: boolean, // Whether this is a clear operation
822
+ history?: IMaskHistoryChange // undo/redo only — see below
822
823
  ) => void
823
824
  ```
824
825
 
825
826
  **Called**: After each completed drawing stroke (mouseup), and after undo/redo.
826
827
 
828
+ #### `history` <Badge type="tip" text="4.1.3" />
829
+
830
+ ```ts
831
+ interface IMaskHistoryChange {
832
+ /** Channels whose voxels the undone or redone delta changed, ascending. */
833
+ channels: number[];
834
+ }
835
+ ```
836
+
837
+ Set **only** on undo/redo. It exists because `channelId` is the *active* channel on those
838
+ calls, which need not be the channel that changed — undoing a channel-3 stroke while channel
839
+ 1 is selected reports `channelId === 1`. A host that syncs per channel must read
840
+ `history.channels` when it is present and fall back to `[channelId]` when it is not.
841
+
842
+ `DrawToolCore.changedChannels(oldSlice, newSlice)` computes it by comparing the slice before
843
+ and after the delta and collecting every differing non-zero label — in a label volume a
844
+ voxel's value *is* its channel, so that set is exactly what the delta touched. It may hold
845
+ several channels, or none if only background changed.
846
+
827
847
  ### 4.2 onLayerVolumeCleared
828
848
 
829
849
  Storage location: `CanvasState.annotationCallbacks.onLayerVolumeCleared`
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "copper3dVersion": "4.1.2",
4
- "generatedAt": "2026-10-20T08:42:30.496Z",
5
- "symbolCount": 1204,
3
+ "copper3dVersion": "4.1.3",
4
+ "generatedAt": "2026-11-05T09:16:06.602Z",
5
+ "symbolCount": 1206,
6
6
  "guides": [
7
7
  {
8
8
  "id": "4D-MRI-LV-rendering",
@@ -82,7 +82,7 @@
82
82
  "title": "AI Coding Assistants (MCP) <Badge type=\"tip\" text=\"3.11.0\" />",
83
83
  "summary": "copper3d ships a machine-readable index of its own API and guides. Point your AI assistant at it through the [`copper3d-mcp`](https://www.npmjs.com/package/copper3d-mcp) server and it can look up real signatures instead of inventing them.",
84
84
  "lang": "en",
85
- "bytes": 4931
85
+ "bytes": 5813
86
86
  },
87
87
  {
88
88
  "id": "nrrd-tools",
@@ -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": 82294
93
+ "bytes": 84625
94
94
  },
95
95
  {
96
96
  "id": "on-demand-controls",
@@ -130,7 +130,7 @@
130
130
  "title": "Segmentation Module Documentation",
131
131
  "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…",
132
132
  "lang": "en",
133
- "bytes": 84465
133
+ "bytes": 85404
134
134
  },
135
135
  {
136
136
  "id": "surface-annotation-api",