@weasel-js/labkit 1.6.1 → 1.7.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 (256) hide show
  1. package/README.md +3 -3
  2. package/dist/_dts/{CanvasStackContext-Wo6OwIVM.d.ts → CanvasStackContext-Cjy6I-Iv.d.ts} +4 -1
  3. package/dist/_dts/{Stage-DWBBi8IU.d.ts → Stage-D6t7o0pF.d.ts} +59 -18
  4. package/dist/_dts/{index-CKyX0ME_.d.ts → index-BTmaRy6a.d.ts} +10 -6
  5. package/dist/_dts/{types-B7yBTTF9.d.ts → index-DCMA4Fy1.d.ts} +59 -113
  6. package/dist/_dts/{types-DTuViBvc.d.ts → types-BUBSIZuV.d.ts} +18 -8
  7. package/dist/_dts/{useTrialState-CMaV6UD4.d.ts → useTrialState-Bh8bzFgE.d.ts} +1 -1
  8. package/dist/canvas/index.d.ts +8 -6
  9. package/dist/canvas/index.js +6 -6
  10. package/dist/chrome/index.d.ts +6 -4
  11. package/dist/chrome/index.js +11 -10
  12. package/dist/chunk-2ES4W47N.js +8 -0
  13. package/dist/chunk-2ES4W47N.js.map +1 -0
  14. package/dist/{chunk-WPLAANH4.js → chunk-2N7UBSS2.js} +12 -12
  15. package/dist/chunk-2N7UBSS2.js.map +1 -0
  16. package/dist/chunk-4KSC7NXL.js +15491 -0
  17. package/dist/chunk-4KSC7NXL.js.map +1 -0
  18. package/dist/{chunk-SLAQPUI4.js → chunk-CEGFXTBD.js} +10 -63
  19. package/dist/chunk-CEGFXTBD.js.map +1 -0
  20. package/dist/chunk-CZZPXUOU.js +3 -0
  21. package/dist/{chunk-SBXNQW4G.js.map → chunk-CZZPXUOU.js.map} +1 -1
  22. package/dist/{chunk-QGMOA2YE.js → chunk-E23Q6A3Y.js} +296 -104
  23. package/dist/chunk-E23Q6A3Y.js.map +1 -0
  24. package/dist/{chunk-GHGO52SO.js → chunk-E6NARGU7.js} +5 -5
  25. package/dist/{chunk-GHGO52SO.js.map → chunk-E6NARGU7.js.map} +1 -1
  26. package/dist/{chunk-IJJUK4FU.js → chunk-EESJUSYR.js} +5 -6
  27. package/dist/chunk-EESJUSYR.js.map +1 -0
  28. package/dist/{chunk-HXXTULDN.js → chunk-EFXRM6XQ.js} +8 -11
  29. package/dist/chunk-EFXRM6XQ.js.map +1 -0
  30. package/dist/chunk-F4ACIK7Z.js +210 -0
  31. package/dist/chunk-F4ACIK7Z.js.map +1 -0
  32. package/dist/{chunk-6FLXL3I7.js → chunk-FB4MIZOO.js} +77 -45
  33. package/dist/chunk-FB4MIZOO.js.map +1 -0
  34. package/dist/{chunk-AWQG7FCC.js → chunk-FG3EXZDV.js} +3 -3
  35. package/dist/{chunk-AWQG7FCC.js.map → chunk-FG3EXZDV.js.map} +1 -1
  36. package/dist/{chunk-4TT3PNPR.js → chunk-GAHELLJT.js} +95 -95
  37. package/dist/chunk-GAHELLJT.js.map +1 -0
  38. package/dist/{chunk-HKV7LRHY.js → chunk-IBVRMHW5.js} +5 -5
  39. package/dist/{chunk-HKV7LRHY.js.map → chunk-IBVRMHW5.js.map} +1 -1
  40. package/dist/{chunk-ASOK76ZH.js → chunk-JFOJESJF.js} +72 -29
  41. package/dist/chunk-JFOJESJF.js.map +1 -0
  42. package/dist/{chunk-RWNDDKOH.js → chunk-PMLZP7RT.js} +18 -15
  43. package/dist/chunk-PMLZP7RT.js.map +1 -0
  44. package/dist/{chunk-TJ77A4A3.js → chunk-READTDQX.js} +5 -9
  45. package/dist/chunk-READTDQX.js.map +1 -0
  46. package/dist/{chunk-JVBYV6TL.js → chunk-ROGJWDQA.js} +3 -3
  47. package/dist/{chunk-JVBYV6TL.js.map → chunk-ROGJWDQA.js.map} +1 -1
  48. package/dist/{chunk-CGHF6RZV.js → chunk-T6DLGEJB.js} +18 -18
  49. package/dist/chunk-T6DLGEJB.js.map +1 -0
  50. package/dist/{chunk-24W5VEJW.js → chunk-ULYYNWGP.js} +2 -2
  51. package/dist/{chunk-24W5VEJW.js.map → chunk-ULYYNWGP.js.map} +1 -1
  52. package/dist/{chunk-DWMSB4CA.js → chunk-VYVGVBGY.js} +95 -32
  53. package/dist/chunk-VYVGVBGY.js.map +1 -0
  54. package/dist/{chunk-IRTGUQ5O.js → chunk-WLMDTI2Q.js} +16 -6
  55. package/dist/chunk-WLMDTI2Q.js.map +1 -0
  56. package/dist/{chunk-NEXR37YJ.js → chunk-XE5HJOPL.js} +6 -8
  57. package/dist/chunk-XE5HJOPL.js.map +1 -0
  58. package/dist/chunk-XVUKDSYV.js +38 -0
  59. package/dist/chunk-XVUKDSYV.js.map +1 -0
  60. package/dist/{chunk-O6FFFOHS.js → chunk-YCFKW5RX.js} +16 -8
  61. package/dist/chunk-YCFKW5RX.js.map +1 -0
  62. package/dist/{chunk-CQLQPQ4P.js → chunk-ZQIHJXP4.js} +2 -2
  63. package/dist/chunk-ZQIHJXP4.js.map +1 -0
  64. package/dist/config/index.d.ts +28 -13
  65. package/dist/config/index.js +4 -4
  66. package/dist/controls/index.d.ts +4 -7
  67. package/dist/controls/index.js +6 -5
  68. package/dist/dragdrop/index.d.ts +23 -3
  69. package/dist/dragdrop/index.js +4 -3
  70. package/dist/fonts/oswald-tabular-digits.woff2 +0 -0
  71. package/dist/index.d.ts +72 -487
  72. package/dist/index.js +603 -441
  73. package/dist/index.js.map +1 -1
  74. package/dist/job/index.d.ts +8 -0
  75. package/dist/job/index.js +1 -1
  76. package/dist/layers/index.d.ts +6 -5
  77. package/dist/layers/index.js +3 -2
  78. package/dist/loupe/index.d.ts +100 -30
  79. package/dist/loupe/index.js +585 -6
  80. package/dist/loupe/index.js.map +1 -1
  81. package/dist/overview/index.d.ts +4 -2
  82. package/dist/overview/index.js +20 -18
  83. package/dist/overview/index.js.map +1 -1
  84. package/dist/passthrough/weasel-canvas.d.ts +2 -0
  85. package/dist/passthrough/weasel-ui.d.ts +2 -2701
  86. package/dist/passthrough/weasel-ui.js +4 -3
  87. package/dist/primitives/index.d.ts +37 -2
  88. package/dist/primitives/index.js +9 -8
  89. package/dist/state/index.d.ts +7 -5
  90. package/dist/state/index.js +6 -6
  91. package/dist/styles.css +150 -126
  92. package/dist/surface/index.d.ts +10 -2
  93. package/dist/surface/index.js +1 -1
  94. package/dist/undo/index.d.ts +5 -3
  95. package/package.json +14 -13
  96. package/src/annotations/AnnotationOverlay.abandon.test.tsx +143 -0
  97. package/src/annotations/AnnotationOverlay.tsx +52 -33
  98. package/src/annotations/Annotations.less +0 -10
  99. package/src/annotations/Annotations.overlay.test.tsx +31 -0
  100. package/src/annotations/MarkList.tsx +4 -8
  101. package/src/annotations/capture.browser.test.ts +41 -0
  102. package/src/annotations/capture.ts +14 -7
  103. package/src/annotations/drawOne.ts +2 -2
  104. package/src/annotations/frac.test.ts +44 -1
  105. package/src/annotations/frac.ts +46 -18
  106. package/src/annotations/index.ts +1 -0
  107. package/src/annotations/paint.test.ts +76 -46
  108. package/src/annotations/paint.ts +65 -43
  109. package/src/annotations/store.test.ts +212 -2
  110. package/src/annotations/store.ts +130 -27
  111. package/src/annotations/svgNodes.test.ts +28 -19
  112. package/src/annotations/svgNodes.ts +6 -6
  113. package/src/annotations/types.ts +29 -10
  114. package/src/canvas/AGENTS.md +1 -0
  115. package/src/canvas/CameraInput.test.tsx +30 -0
  116. package/src/canvas/CameraInput.tsx +60 -48
  117. package/src/canvas/CanvasStack.tsx +11 -6
  118. package/src/canvas/CanvasStackContext.ts +4 -1
  119. package/src/canvas/LinkedCursor.less +1 -1
  120. package/src/canvas/Stage.test.tsx +33 -4
  121. package/src/canvas/Stage.tsx +9 -4
  122. package/src/canvas/cameraRegistry.test.ts +55 -0
  123. package/src/canvas/cameraRegistry.ts +87 -0
  124. package/src/canvas/cameraZoom.test.ts +46 -0
  125. package/src/canvas/cameraZoom.ts +24 -0
  126. package/src/canvas/index.ts +14 -2
  127. package/src/canvas/sharedScope.test.tsx +94 -0
  128. package/src/canvas/worldSpec.ts +3 -1
  129. package/src/chrome/ChromeRegions.stories.tsx +1 -0
  130. package/src/chrome/builtins.test.ts +7 -6
  131. package/src/chrome/builtins.tsx +5 -1
  132. package/src/chrome/index.ts +1 -1
  133. package/src/chrome/merge.test.ts +5 -0
  134. package/src/chrome/merge.ts +4 -2
  135. package/src/chrome/regions/PaletteRegion.less +0 -7
  136. package/src/chrome/regions/PaletteRegion.test.tsx +2 -3
  137. package/src/chrome/regions/PaletteRegion.tsx +3 -4
  138. package/src/chrome/regions/SidebarRegion.less +12 -2
  139. package/src/chrome/regions/ViewportRegion.browser.test.less +6 -0
  140. package/src/chrome/regions/ViewportRegion.browser.test.tsx +38 -0
  141. package/src/chrome/regions/ViewportRegion.less +6 -0
  142. package/src/chrome/regions/ViewportRegion.tsx +10 -4
  143. package/src/chrome/types.ts +4 -2
  144. package/src/config/auto.ts +1 -0
  145. package/src/config/builder.test.ts +2 -1
  146. package/src/config/builder.ts +18 -5
  147. package/src/config/fromConfigField.test.ts +14 -0
  148. package/src/config/fromConfigField.ts +18 -4
  149. package/src/config/path.ts +2 -5
  150. package/src/config/resolve.ts +4 -0
  151. package/src/config/types.ts +14 -9
  152. package/src/controls/ControlPanel.less +1 -1
  153. package/src/controls/ControlPanel.stories.tsx +3 -2
  154. package/src/controls/ControlPanel.test.tsx +98 -11
  155. package/src/controls/ControlPanel.tsx +61 -2
  156. package/src/dragdrop/DragDropRuntime.tsx +22 -13
  157. package/src/dragdrop/DragGhost.tsx +3 -0
  158. package/src/dragdrop/Palette.tsx +2 -0
  159. package/src/index.test.ts +5 -0
  160. package/src/index.ts +16 -2
  161. package/src/instrument/types.ts +0 -6
  162. package/src/job/useJob.ts +14 -9
  163. package/src/lab/Lab.tsx +88 -73
  164. package/src/lab/{LabFit.stories.less → LabFit.browser.test.less} +1 -1
  165. package/src/lab/{LabFit.stories.tsx → LabFit.browser.test.tsx} +41 -63
  166. package/src/lab/LabFullChrome.stories.tsx +1 -0
  167. package/src/lab/LabHeader.test.tsx +24 -14
  168. package/src/lab/LabHeader.tsx +11 -12
  169. package/src/lab/LabShell.less +9 -17
  170. package/src/lab/LabSwitcher.browser.test.tsx +27 -0
  171. package/src/lab/LabSwitcher.less +8 -6
  172. package/src/lab/LabZoom.test.tsx +223 -0
  173. package/src/lab/LabZoom.tsx +170 -0
  174. package/src/lab/Workspace.tsx +48 -52
  175. package/src/lab/index.ts +1 -0
  176. package/src/loupe/AGENTS.md +28 -15
  177. package/src/loupe/CanvasLoupe.tsx +2 -3
  178. package/src/loupe/DomLoupe.tsx +1 -7
  179. package/src/loupe/Loupe.less +16 -0
  180. package/src/loupe/LoupeGestures.tsx +1 -1
  181. package/src/loupe/TrialLoupe.tsx +120 -57
  182. package/src/loupe/index.ts +1 -6
  183. package/src/loupe/types.test.ts +3 -3
  184. package/src/loupe/types.ts +24 -27
  185. package/src/loupe/useLoupe.test.tsx +29 -4
  186. package/src/loupe/useLoupe.ts +20 -17
  187. package/src/overview/OverviewMarks.tsx +12 -4
  188. package/src/overview/TrialOverview.tsx +10 -8
  189. package/src/passthrough/weasel-ui.test.ts +2 -0
  190. package/src/passthrough/weasel-ui.ts +17 -5
  191. package/src/primitives/FloatingPanel.test.tsx +11 -0
  192. package/src/primitives/FloatingPanel.tsx +8 -7
  193. package/src/primitives/JobProgress.less +2 -1
  194. package/src/primitives/Legend.stories.tsx +1 -0
  195. package/src/primitives/Readout.browser.test.tsx +137 -0
  196. package/src/primitives/Readout.less +12 -0
  197. package/src/primitives/Readout.stories.tsx +58 -0
  198. package/src/primitives/Readout.test.tsx +93 -0
  199. package/src/primitives/Readout.tsx +56 -0
  200. package/src/primitives/Split.tsx +69 -41
  201. package/src/primitives/Toolbar.tsx +3 -3
  202. package/src/primitives/ZoomControl.less +1 -2
  203. package/src/primitives/index.ts +2 -0
  204. package/src/specimen/Specimen.stories.tsx +1 -0
  205. package/src/specimen/Specimen.tsx +2 -3
  206. package/src/state/Persistence.browser.test.tsx +47 -0
  207. package/src/state/store.test.ts +5 -1
  208. package/src/state/undock.ts +3 -0
  209. package/src/state/useOpenOnce.ts +20 -16
  210. package/src/state/usePersistedState.test.tsx +1 -1
  211. package/src/state/view.ts +1 -0
  212. package/src/styles.less +1 -0
  213. package/src/surface/index.ts +1 -1
  214. package/src/surface/useTiledSurface.test.tsx +14 -0
  215. package/src/surface/useTiledSurface.ts +11 -3
  216. package/src/theme/Interstellar.stories.tsx +3 -1
  217. package/src/theme/base.less +21 -47
  218. package/src/theme/interstellar.test.ts +1 -1
  219. package/src/theme/interstellar.theme.json +10 -3
  220. package/src/trial/Trial.annotations.test.tsx +73 -0
  221. package/src/trial/Trial.less +0 -29
  222. package/src/trial/Trial.loupe.test.tsx +28 -11
  223. package/src/trial/Trial.tsx +85 -67
  224. package/src/trial/TrialChrome.tsx +27 -6
  225. package/src/trial/index.ts +2 -0
  226. package/src/trial/loupeSwitch.ts +15 -0
  227. package/dist/_dts/LayerList.d-BoELAMsM.d.ts +0 -83
  228. package/dist/_dts/PrefsRow.d-DFpPIeIC.d.ts +0 -39
  229. package/dist/_dts/PropertyField.d-D0ndfIIt.d.ts +0 -404
  230. package/dist/_dts/Select.d-Cr8-zoup.d.ts +0 -569
  231. package/dist/chunk-4TT3PNPR.js.map +0 -1
  232. package/dist/chunk-6FLXL3I7.js.map +0 -1
  233. package/dist/chunk-ASOK76ZH.js.map +0 -1
  234. package/dist/chunk-CGHF6RZV.js.map +0 -1
  235. package/dist/chunk-CQLQPQ4P.js.map +0 -1
  236. package/dist/chunk-DWMSB4CA.js.map +0 -1
  237. package/dist/chunk-HXXTULDN.js.map +0 -1
  238. package/dist/chunk-IJJUK4FU.js.map +0 -1
  239. package/dist/chunk-IRTGUQ5O.js.map +0 -1
  240. package/dist/chunk-KHK5FGER.js +0 -145
  241. package/dist/chunk-KHK5FGER.js.map +0 -1
  242. package/dist/chunk-NEXR37YJ.js.map +0 -1
  243. package/dist/chunk-O6FFFOHS.js.map +0 -1
  244. package/dist/chunk-QGMOA2YE.js.map +0 -1
  245. package/dist/chunk-RWNDDKOH.js.map +0 -1
  246. package/dist/chunk-S4NCI32V.js +0 -549
  247. package/dist/chunk-S4NCI32V.js.map +0 -1
  248. package/dist/chunk-SBXNQW4G.js +0 -3
  249. package/dist/chunk-SLAQPUI4.js.map +0 -1
  250. package/dist/chunk-TJ77A4A3.js.map +0 -1
  251. package/dist/chunk-TYN6MLXX.js +0 -13864
  252. package/dist/chunk-TYN6MLXX.js.map +0 -1
  253. package/dist/chunk-WPLAANH4.js.map +0 -1
  254. package/src/primitives/useRovingTabIndex.test.ts +0 -48
  255. package/src/primitives/useRovingTabIndex.ts +0 -88
  256. package/src/state/Persistence.stories.tsx +0 -75
@@ -1,3 +1,4 @@
1
+ import { useLatest } from '@weasel-js/core';
1
2
  import {
2
3
  Children,
3
4
  type ReactNode,
@@ -33,6 +34,7 @@ export type TrialLayout = Record<
33
34
  { size?: { w?: number; h?: number }; span?: { cols?: number; rows?: number } }
34
35
  >;
35
36
 
37
+ /** Props for `Workspace`. */
36
38
  export interface WorkspaceProps {
37
39
  children: ReactNode;
38
40
  /**
@@ -61,7 +63,7 @@ export interface WorkspaceProps {
61
63
  padding?: number;
62
64
  /** Undocked sidebar panels to render alongside the trials. A `'tile'` panel
63
65
  * joins the grid as a peer of the trials; a `'floating'` one goes into the
64
- * floating zone above it. The body is portalled in by the trial that owns
66
+ * floating zone above it. The body is portaled in by the trial that owns
65
67
  * it, so all this renders is the frame and the host. */
66
68
  panels?: readonly PanelDescriptor[];
67
69
  /**
@@ -72,6 +74,26 @@ export interface WorkspaceProps {
72
74
  viewport?: { w: number; h: number };
73
75
  }
74
76
 
77
+ /** The layout store a workspace keeps for its lifetime: the tile grid, and the zone floating panels live in. */
78
+ function createWorkspaceStore(grid: { resizable: boolean; gap: number; padding: number }): Store {
79
+ const store = new Store();
80
+ store.registerNode(
81
+ createNode({
82
+ kind: 'zone',
83
+ id: ZONE_ID,
84
+ container: { strategyId: 'grid', config: grid },
85
+ }),
86
+ );
87
+ store.registerNode(
88
+ createNode({
89
+ kind: 'zone',
90
+ id: FLOAT_ZONE_ID,
91
+ container: { strategyId: 'floating', config: {} },
92
+ }),
93
+ );
94
+ return store;
95
+ }
96
+
75
97
  function extentOf(store: Store, id: NodeId): TrialLayout[string] | null {
76
98
  const p = store.getNode(id)?.membership?.placement as TrialLayout[string] | undefined;
77
99
  if (!p) return null;
@@ -81,21 +103,6 @@ function extentOf(store: Store, id: NodeId): TrialLayout[string] | null {
81
103
  return Object.keys(out).length > 0 ? out : null;
82
104
  }
83
105
 
84
- /**
85
- * Auto-balanced tiling of trials, `ceil(sqrt(n))` columns wide.
86
- *
87
- * Tiles are absolutely positioned at the rects `gridStrategy` computes, not
88
- * laid out by CSS — `windease/styles.css` (folded into
89
- * `@weasel-js/labkit/styles.css`) carries the rules that positioning depends on.
90
- *
91
- * `panels` are undocked sidebar sections. A `'tile'` panel is registered as a
92
- * peer of the trials under `PANEL_KIND`, so the grid places and resizes it like
93
- * one; a `'floating'` panel goes in the overlay above. Either way this renders
94
- * only the frame and an empty host: the section's content is portalled in by
95
- * the trial that owns it, which is what keeps a torn-out section inside its
96
- * trial's React tree instead of rebuilding it as a sibling.
97
- */
98
-
99
106
  /** The frame an undocked panel gets: a box, and the host element its trial
100
107
  * portals into. The title and the dock control come through the portal with
101
108
  * the body — the workspace knows a panel's key, not what is in it. */
@@ -116,6 +123,20 @@ export interface PanelDescriptor {
116
123
  as: 'tile' | 'floating';
117
124
  }
118
125
 
126
+ /**
127
+ * Auto-balanced tiling of trials, `ceil(sqrt(n))` columns wide.
128
+ *
129
+ * Tiles are absolutely positioned at the rects `gridStrategy` computes, not
130
+ * laid out by CSS — `windease/styles.css` (folded into
131
+ * `@weasel-js/labkit/styles.css`) carries the rules that positioning depends on.
132
+ *
133
+ * `panels` are undocked sidebar sections. A `'tile'` panel is registered as a
134
+ * peer of the trials under `PANEL_KIND`, so the grid places and resizes it like
135
+ * one; a `'floating'` panel goes in the overlay above. Either way this renders
136
+ * only the frame and an empty host: the section's content is portaled in by
137
+ * the trial that owns it, which is what keeps a torn-out section inside its
138
+ * trial's React tree instead of rebuilding it as a sibling.
139
+ */
119
140
  export function Workspace({
120
141
  children,
121
142
  ids,
@@ -134,50 +155,25 @@ export function Workspace({
134
155
  const floatPanels = useMemo(() => (panels ?? []).filter((p) => p.as === 'floating'), [panels]);
135
156
  // Identity has to be stable while the id *contents* are unchanged: the sync
136
157
  // effect below keys off it, and a fresh array every render would re-register
137
- // every tile forever. A ref keyed on the joined ids says that directly, where
138
- // a `useMemo` on the same key can only say it by suppressing both linters.
139
- const wantedIds = [
158
+ // every tile forever. So the ids are memoized on a serialized key, and read
159
+ // back from it.
160
+ const idKey = JSON.stringify([
140
161
  ...items.map((_, i) => ids?.[i] ?? `lk-ws-${i}`),
141
162
  ...tilePanels.map((p) => `lk-panel-${p.key}`),
142
- ];
143
- const idKey = wantedIds.join(',');
144
- const idKeyRef = useRef<string | null>(null);
145
- const nodeIdsRef = useRef<NodeId[]>([]);
146
- if (idKeyRef.current !== idKey) {
147
- idKeyRef.current = idKey;
148
- nodeIdsRef.current = wantedIds.map(asNodeId);
149
- }
150
- const nodeIds = nodeIdsRef.current;
163
+ ]);
164
+ const nodeIds = useMemo(() => (JSON.parse(idKey) as string[]).map(asNodeId), [idKey]);
151
165
 
152
166
  // Held in refs rather than depended on: a fresh object each render would
153
167
  // re-run the sync effect, and only a newly registered tile reads `layout`.
154
- const layoutRef = useRef(layout);
155
- layoutRef.current = layout;
156
- const onLayoutChangeRef = useRef(onLayoutChange);
157
- onLayoutChangeRef.current = onLayoutChange;
168
+ const layoutRef = useLatest(layout);
169
+ const onLayoutChangeRef = useLatest(onLayoutChange);
158
170
 
159
171
  // One store for the component's lifetime: a tile's dragged extent lives in
160
172
  // its node, so rebuilding the store on every add or close would silently
161
173
  // reset every pane.
162
174
  const storeRef = useRef<Store | null>(null);
163
- if (storeRef.current === null) {
164
- const store = new Store();
165
- store.registerNode(
166
- createNode({
167
- kind: 'zone',
168
- id: ZONE_ID,
169
- container: { strategyId: 'grid', config: { resizable, gap, padding } },
170
- }),
171
- );
172
- store.registerNode(
173
- createNode({
174
- kind: 'zone',
175
- id: FLOAT_ZONE_ID,
176
- container: { strategyId: 'floating', config: {} },
177
- }),
178
- );
179
- storeRef.current = store;
180
- }
175
+ if (storeRef.current === null)
176
+ storeRef.current = createWorkspaceStore({ resizable, gap, padding });
181
177
  const store = storeRef.current;
182
178
 
183
179
  // A tile that only moves reports nothing to a ResizeObserver, and only this
@@ -203,7 +199,7 @@ export function Workspace({
203
199
  if (saved) store.patchPlacement(id, saved);
204
200
  }
205
201
  store.setChildOrder(ZONE_ID, [...nodeIds]);
206
- }, [store, nodeIds]);
202
+ }, [store, nodeIds, layoutRef]);
207
203
 
208
204
  // biome-ignore lint/correctness/useExhaustiveDependencies: nodeIds is the signal that the tile set changed — a re-tile moves tiles without resizing any — not a value this reads
209
205
  useEffect(() => {
@@ -222,7 +218,7 @@ export function Workspace({
222
218
  }
223
219
  onLayoutChangeRef.current?.(next);
224
220
  });
225
- }, [store, onLayoutChange]);
221
+ }, [store, onLayoutChange, onLayoutChangeRef]);
226
222
 
227
223
  const commitOrder = useCallback(
228
224
  (nextIds: NodeId[]) => onReorder?.(nextIds.map(String)),
package/src/lab/index.ts CHANGED
@@ -11,5 +11,6 @@ export type { LabShellProps } from './LabShell';
11
11
  export { LabShell } from './LabShell';
12
12
  export type { LabPage, LabSwitcherProps } from './LabSwitcher';
13
13
  export { currentPage, LabSwitcher } from './LabSwitcher';
14
+ export { LabZoom } from './LabZoom';
14
15
  export type { PanelDescriptor, TrialLayout, WorkspaceProps } from './Workspace';
15
16
  export { Workspace } from './Workspace';
@@ -1,7 +1,9 @@
1
1
  # Loupe — Agent Guide
2
2
 
3
- `src/loupe/` is the `loupe` instrument capability: a magnifier a trial can turn
4
- on, painted by whichever painter suits the instrument's content.
3
+ `src/loupe/` is `@weasel-js/labkit/loupe`: `<TrialLoupe>`, a magnifier the
4
+ instrument mounts in its own content, painted by whichever painter suits it.
5
+ Its own bundle entry; nothing in the main bundle imports it, so a lab that
6
+ mounts no lens never loads it.
5
7
 
6
8
  The magnifier itself is not here. `@weasel-js/loupe` holds the model — aim,
7
9
  factor, mode, color, picking — over a `LoupeSurface` it asks five questions.
@@ -11,29 +13,40 @@ This directory binds that model to a labkit trial and draws it.
11
13
 
12
14
  | File | Role |
13
15
  |---|---|
14
- | `types.ts` | `LoupeCapability`, and `resolveLoupe` filling in every default |
16
+ | `types.ts` | `LoupeOptions`, and `resolveLoupe` filling in every default |
15
17
  | `useLoupe.ts` | The model over a host element, and pointer aiming |
16
18
  | `loupeActions.ts` | `loupe.peek` and `loupe.magnify`, as `Action` descriptors |
17
19
  | `LoupeGestures.tsx` | Registers those, and mounts a dispatcher on the host when no camera has one there |
18
- | `TrialLoupe.tsx` | Picks the painter and mounts the lens |
20
+ | `TrialLoupe.tsx` | Finds its host and the trial's switch, picks the painter, mounts the lens |
19
21
  | `LoupeBubble.tsx` | The circular clip, positioned on the aim |
20
22
  | `CanvasLoupe.tsx` | Painter for a `<CanvasStack>` |
21
23
  | `canvasLens.ts` | That painter's geometry and drawing, with no React in it |
22
24
  | `DomLoupe.tsx` | Painter for DOM content |
23
25
  | `useHostSize.ts` | The host's measured box, for the DOM stage |
24
26
 
25
- ## Which painter
27
+ ## How it reads the trial
28
+
29
+ Only through context, the way `<TrialOverview>` does. `CanvasStackContext`'s
30
+ `surface` gives the canvas painter the stack's layers, pixels and `worldSpec`;
31
+ `CameraContext` gives a lens in a `<Stage>` its element and camera. Outside
32
+ both, it tracks `hostRef`, or failing that wraps its `children` in a
33
+ `.lk-loupe-host` box of its own.
26
34
 
27
- `LoupeCapability.render` decides. Absent, the lens re-runs the instrument's own
28
- canvas layers through `lensCamera` — sharp at any factor, and `mode: 'pixel'`
29
- enlarges the presented pixels with smoothing off instead. Present, the
30
- instrument is handed a camera and draws itself again; a DOM loupe is always
31
- `vector`, since DOM has no framebuffer to enlarge.
35
+ The toolbar toggle is `LoupeSwitchContext` (`src/trial/loupeSwitch.ts`, main
36
+ bundle). A lens with no `enabled` prop calls `mount` and follows `on`; the
37
+ trial offers its Loupe toggle while any lens is mounted. `enabled` opts a lens
38
+ out of the switch entirely. Because the lens mounts after the trial's first
39
+ render, `loupe` is in `TRANSIENT_BUILTINS`, so suppressing it before then is
40
+ not a typo.
41
+
42
+ ## Which painter
32
43
 
33
- The canvas painter needs the stack's own pixels and layers, which is why
34
- `TrialLoupe` mounts *inside* `<CanvasStack>` for a drawing instrument and reads
35
- `CanvasStackContext`'s `surface`. A DOM instrument gets a
36
- `.lk-trial__loupe-host` wrapper from `Trial` and the lens tracks that.
44
+ `render` decides. Absent, the lens re-runs the stack's canvas layers through
45
+ `lensCamera` — sharp at any factor, and `mode: 'pixel'` enlarges the presented
46
+ pixels with smoothing off instead. Present, it is handed a camera and draws the
47
+ content again; a DOM loupe is always `vector`, since DOM has no framebuffer to
48
+ enlarge. The canvas painter needs the stack's own pixels, which is why a
49
+ drawing instrument mounts the lens in its `render`, inside `<CanvasStack>`.
37
50
 
38
51
  ## Traps
39
52
 
@@ -51,7 +64,7 @@ In a trial the loupe's actions join the camera's dispatcher (`CameraInput`).
51
64
  `loupe.magnify` sits in the hotkey tier, so while the lens is up it outranks
52
65
  the camera's wheel zoom; while it is down its `enabled` returns a disabled
53
66
  reason and the dispatcher falls through to the zoom. Outside a camera — the DOM
54
- `.lk-trial__loupe-host` — `<LoupeGestures>` mounts a dispatcher of its own.
67
+ `.lk-loupe-host` — `<LoupeGestures>` mounts a dispatcher of its own.
55
68
 
56
69
  **Aiming is a plain listener because a hover is not a gesture.**
57
70
  `GESTURE_DESCRIPTORS` names no continuous-motion gesture, so `pointermove` /
@@ -1,4 +1,4 @@
1
- import { useVisibleRaf } from '@weasel-js/core';
1
+ import { useLatest, useVisibleRaf } from '@weasel-js/core';
2
2
  import type { LoupeMode, LoupePoint } from '@weasel-js/loupe';
3
3
  import { useEffect, useRef } from 'react';
4
4
  import type { CanvasStackSurface } from '../canvas/CanvasStackContext';
@@ -40,8 +40,7 @@ export function CanvasLoupe({
40
40
  // Whatever the stack redraws every frame, the lens has to redraw too — an
41
41
  // instrument that animates from its own loop never re-renders this component.
42
42
  const args = { aim, factor, mode, diameter, dpr, view, frame, worldSpec, surface };
43
- const argsRef = useRef(args);
44
- argsRef.current = args;
43
+ const argsRef = useLatest(args);
45
44
 
46
45
  const loop = useVisibleRaf(
47
46
  () => {
@@ -16,13 +16,11 @@ export interface DomLoupeProps {
16
16
  /** The trial's own camera. */
17
17
  view: ViewTransform;
18
18
  frame?: WorldFrame;
19
- state: unknown;
20
- config: unknown;
21
19
  render: (args: LoupeRenderArgs) => React.ReactNode;
22
20
  }
23
21
 
24
22
  /**
25
- * Paints a lens over DOM content by asking the instrument to draw itself again
23
+ * Paints a lens over DOM content by asking its `render` to draw it again
26
24
  * at a magnified camera.
27
25
  *
28
26
  * The stage is a full copy of the host, so the instrument's own layout still
@@ -38,8 +36,6 @@ export function DomLoupe({
38
36
  size,
39
37
  view,
40
38
  frame,
41
- state,
42
- config,
43
39
  render,
44
40
  }: DomLoupeProps) {
45
41
  const style: CSSProperties = {
@@ -50,8 +46,6 @@ export function DomLoupe({
50
46
  return (
51
47
  <div className="lk-loupe__stage" style={style}>
52
48
  {render({
53
- state,
54
- config,
55
49
  view: zoomAt(view, factor, aim, { frame }),
56
50
  factor,
57
51
  mode,
@@ -36,3 +36,19 @@
36
36
  left: 0;
37
37
  transform-origin: 0 0;
38
38
  }
39
+
40
+ // The box a lens wraps around DOM content when nothing around it has one to
41
+ // track. Reproduces the content well's column so the content still stretches
42
+ // to it rather than collapsing to its intrinsic height.
43
+ .lk-loupe-host {
44
+ position: relative;
45
+ display: flex;
46
+ flex-direction: column;
47
+ min-height: 0;
48
+ height: 100%;
49
+
50
+ > * {
51
+ flex: 1 1 auto;
52
+ min-height: 0;
53
+ }
54
+ }
@@ -50,7 +50,7 @@ function LoupeDispatch({
50
50
  useGestureDispatcher({
51
51
  canvasRef: hostRef,
52
52
  actions: registry,
53
- toolsById: NO_TOOLS,
53
+ entriesById: NO_TOOLS,
54
54
  channels: CHANNELS,
55
55
  enabled: ownDispatcher,
56
56
  });
@@ -1,53 +1,97 @@
1
- import { type RefObject, useContext, useMemo } from 'react';
2
- import { CameraScope } from '../canvas/CameraInput';
1
+ import { type ReactNode, type RefObject, useContext, useEffect, useMemo, useRef } from 'react';
2
+ import { CameraContext, CameraScope } from '../canvas/CameraInput';
3
3
  import { CanvasStackContext } from '../canvas/CanvasStackContext';
4
- import type { WorldSpec } from '../canvas/worldSpec';
4
+ import { fromCameraView } from '../canvas/cameraView';
5
5
  import type { ViewTransform } from '../instrument/types';
6
+ import { LoupeSwitchContext } from '../trial/loupeSwitch';
6
7
  import { CanvasLoupe } from './CanvasLoupe';
7
8
  import { sampleStack } from './canvasLens';
8
9
  import { DomLoupe } from './DomLoupe';
9
10
  import { LoupeBubble } from './LoupeBubble';
10
11
  import { LoupeGestures } from './LoupeGestures';
11
- import type { ResolvedLoupe } from './types';
12
+ import { type LoupeOptions, resolveLoupe } from './types';
12
13
  import { useHostSize } from './useHostSize';
13
14
  import { useLoupe } from './useLoupe';
14
15
 
15
16
  /** Props for `<TrialLoupe>`. */
16
- export interface TrialLoupeProps {
17
- capability: ResolvedLoupe;
18
- /** Whether the trial's loupe is turned on. Hold-to-peek shows it anyway. */
19
- enabled: boolean;
20
- state: unknown;
21
- config: unknown;
22
- /** The trial's own camera. */
23
- view: ViewTransform;
24
- worldSpec?: WorldSpec;
25
- /** The element the lens tracks. A loupe mounted inside a `<CanvasStack>`
26
- * takes the stack's own element instead, and this goes unused. */
17
+ export interface TrialLoupeProps extends LoupeOptions {
18
+ /** Whether the lens is turned on. Omitted, it follows the trial's toolbar
19
+ * toggle, which the trial offers while a lens like this is mounted — and is
20
+ * off outside a trial. Hold-to-peek shows it either way. */
21
+ enabled?: boolean;
22
+ /** The camera a `render` lens composes its magnification onto. Defaults to
23
+ * the camera around it, and to the identity outside one. */
24
+ view?: ViewTransform;
25
+ /** The element the lens tracks. Defaults to the canvas stack or stage around
26
+ * it, and outside both to a box wrapped around `children`. */
27
27
  hostRef?: RefObject<HTMLElement | null>;
28
+ /** Content for the lens to sit over. Wrapped in a box of the lens's own only
29
+ * when nothing around it gives the lens an element to track. */
30
+ children?: ReactNode;
28
31
  }
29
32
 
30
- /** Stable stand-in, so a loupe with nothing to track does not re-bind its
31
- * listeners on every render. */
32
- const NO_HOST: RefObject<HTMLElement | null> = { current: null };
33
+ const IDENTITY: ViewTransform = { zoom: 1, pan: { x: 0, y: 0 } };
33
34
 
34
35
  /**
35
- * A trial's loupe, painted by whichever painter suits its content: the canvas
36
- * stack it is mounted inside, or the instrument's own `render` at a magnified
37
- * camera.
36
+ * A trial's magnifier, mounted by the instrument wherever its content is: in
37
+ * a canvas instrument's `render`, a stage's `overlay`, or around DOM content.
38
+ *
39
+ * With no `render` inside a `<CanvasStack>`, it re-draws the stack's own
40
+ * layers through a zoomed camera. With `render`, it asks for the content again
41
+ * at a magnified camera.
38
42
  */
39
43
  export function TrialLoupe({
40
- capability,
41
44
  enabled,
42
- state,
43
- config,
44
45
  view,
45
- worldSpec,
46
46
  hostRef,
47
+ children,
48
+ render,
49
+ factor,
50
+ minFactor,
51
+ maxFactor,
52
+ mode,
53
+ diameter,
54
+ peekKey,
55
+ onColorChange,
47
56
  }: TrialLoupeProps) {
57
+ const options = useMemo(
58
+ () =>
59
+ resolveLoupe({
60
+ render,
61
+ factor,
62
+ minFactor,
63
+ maxFactor,
64
+ mode,
65
+ diameter,
66
+ peekKey,
67
+ onColorChange,
68
+ }),
69
+ [render, factor, minFactor, maxFactor, mode, diameter, peekKey, onColorChange],
70
+ );
71
+
48
72
  const stack = useContext(CanvasStackContext);
49
- const surface = capability.render ? undefined : stack?.surface;
50
- const host = surface?.element ?? hostRef ?? NO_HOST;
73
+ const camera = useContext(CameraContext);
74
+ const loupeSwitch = useContext(LoupeSwitchContext);
75
+ const surface = options.render ? undefined : stack?.surface;
76
+
77
+ const ownHost = useRef<HTMLDivElement | null>(null);
78
+ const cameraHost = useMemo<RefObject<HTMLElement | null> | null>(
79
+ () =>
80
+ camera
81
+ ? {
82
+ get current() {
83
+ return camera.element();
84
+ },
85
+ }
86
+ : null,
87
+ [camera],
88
+ );
89
+ const host = surface?.element ?? hostRef ?? cameraHost ?? ownHost;
90
+ const wraps = host === ownHost;
91
+
92
+ // A lens told whether it is on has no use for the trial's toggle.
93
+ const mount = enabled === undefined ? loupeSwitch?.mount : undefined;
94
+ useEffect(() => mount?.(), [mount]);
51
95
 
52
96
  const sample = useMemo(() => {
53
97
  if (!surface) return undefined;
@@ -57,7 +101,12 @@ export function TrialLoupe({
57
101
  };
58
102
  }, [surface]);
59
103
 
60
- const loupe = useLoupe({ capability, hostRef: host, enabled, sample });
104
+ const loupe = useLoupe({
105
+ options,
106
+ hostRef: host,
107
+ enabled: enabled ?? loupeSwitch?.on ?? false,
108
+ sample,
109
+ });
61
110
  const measured = useHostSize(host);
62
111
  const size = surface?.size ?? measured;
63
112
 
@@ -67,42 +116,56 @@ export function TrialLoupe({
67
116
  // dispatcher; outside one, `<CameraScope>` gives them an isolated scope.
68
117
  const gestures = (
69
118
  <CameraScope>
70
- <LoupeGestures hostRef={host} input={loupe.input} peekKey={capability.peekKey ?? null} />
119
+ <LoupeGestures hostRef={host} input={loupe.input} peekKey={options.peekKey ?? null} />
71
120
  </CameraScope>
72
121
  );
73
122
 
74
- if (!loupe.visible) return gestures;
123
+ const lens = loupe.visible ? (
124
+ <LoupeBubble aim={loupe.aim} diameter={options.diameter}>
125
+ {options.render ? (
126
+ <DomLoupe
127
+ aim={loupe.aim}
128
+ factor={loupe.factor}
129
+ mode={loupe.mode}
130
+ diameter={options.diameter}
131
+ size={size}
132
+ view={
133
+ view ??
134
+ stack?.view ??
135
+ (camera ? fromCameraView(camera.view.get(), camera.frame) : IDENTITY)
136
+ }
137
+ frame={stack?.frame ?? camera?.frame}
138
+ render={options.render}
139
+ />
140
+ ) : surface && stack ? (
141
+ <CanvasLoupe
142
+ aim={loupe.aim}
143
+ factor={loupe.factor}
144
+ mode={loupe.mode}
145
+ diameter={options.diameter}
146
+ surface={surface}
147
+ view={stack.view}
148
+ frame={stack.frame}
149
+ worldSpec={surface.worldSpec}
150
+ />
151
+ ) : null}
152
+ </LoupeBubble>
153
+ ) : null;
75
154
 
155
+ if (wraps) {
156
+ return (
157
+ <div ref={ownHost} className="lk-loupe-host">
158
+ {children}
159
+ {gestures}
160
+ {lens}
161
+ </div>
162
+ );
163
+ }
76
164
  return (
77
165
  <>
166
+ {children}
78
167
  {gestures}
79
- <LoupeBubble aim={loupe.aim} diameter={capability.diameter}>
80
- {capability.render ? (
81
- <DomLoupe
82
- aim={loupe.aim}
83
- factor={loupe.factor}
84
- mode={loupe.mode}
85
- diameter={capability.diameter}
86
- size={size}
87
- view={view}
88
- frame={stack?.frame}
89
- state={state}
90
- config={config}
91
- render={capability.render}
92
- />
93
- ) : surface && stack ? (
94
- <CanvasLoupe
95
- aim={loupe.aim}
96
- factor={loupe.factor}
97
- mode={loupe.mode}
98
- diameter={capability.diameter}
99
- surface={surface}
100
- view={stack.view}
101
- frame={stack.frame}
102
- worldSpec={worldSpec}
103
- />
104
- ) : null}
105
- </LoupeBubble>
168
+ {lens}
106
169
  </>
107
170
  );
108
171
  }
@@ -13,12 +13,7 @@ export type { LoupeInputApi } from './loupeActions';
13
13
  export { createLoupeActions, LOUPE_MAGNIFY_ID, LOUPE_PEEK_ID } from './loupeActions';
14
14
  export type { TrialLoupeProps } from './TrialLoupe';
15
15
  export { TrialLoupe } from './TrialLoupe';
16
- export type {
17
- LoupeCapability,
18
- LoupeDeclaration,
19
- LoupeRenderArgs,
20
- ResolvedLoupe,
21
- } from './types';
16
+ export type { LoupeOptions, LoupeRenderArgs, ResolvedLoupe } from './types';
22
17
  export { LOUPE_DEFAULTS, resolveLoupe } from './types';
23
18
  export type { LoupeState, UseLoupeOptions } from './useLoupe';
24
19
  export { useLoupe } from './useLoupe';
@@ -2,11 +2,11 @@ import { describe, expect, it } from 'vitest';
2
2
  import { LOUPE_DEFAULTS, resolveLoupe } from './types';
3
3
 
4
4
  describe('resolveLoupe', () => {
5
- it('takes every default from a bare `true`', () => {
6
- expect(resolveLoupe(true)).toMatchObject(LOUPE_DEFAULTS);
5
+ it('takes every default when given nothing', () => {
6
+ expect(resolveLoupe()).toMatchObject(LOUPE_DEFAULTS);
7
7
  });
8
8
 
9
- it('keeps what the instrument declared', () => {
9
+ it('keeps what it was given', () => {
10
10
  const cap = resolveLoupe({ factor: 12, diameter: 320, minFactor: 1, maxFactor: 40 });
11
11
  expect(cap).toMatchObject({ factor: 12, diameter: 320, minFactor: 1, maxFactor: 40 });
12
12
  });