@weasel-js/labkit 1.5.0 → 1.5.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.
Files changed (206) hide show
  1. package/README.md +41 -4
  2. package/dist/_dts/{CanvasStackContext-CqkxkFJW.d.ts → CanvasStackContext-CMMo180l.d.ts} +1 -1
  3. package/dist/_dts/{PrefsForm.d-DDHFANkc.d.ts → PrefsForm.d-DPy9I8It.d.ts} +4 -0
  4. package/dist/_dts/Select.d-ZTiwzYyT.d.ts +479 -0
  5. package/dist/_dts/{frac-8R6UmlvN.d.ts → frac-B4hFJMiN.d.ts} +54 -6
  6. package/dist/_dts/{index-retnAut7.d.ts → index-8LiKe3A-.d.ts} +77 -10
  7. package/dist/_dts/{index-B8uu2ba7.d.ts → index-DlKolEIZ.d.ts} +20 -8
  8. package/dist/_dts/{types-Ca2LCnPq.d.ts → types-Db-3NNk1.d.ts} +28 -4
  9. package/dist/_dts/{usePanZoom-nS798rOF.d.ts → usePanZoom-SSTZe410.d.ts} +4 -47
  10. package/dist/_dts/{useTrialState-jcx_TdU6.d.ts → useTrialState-pnAE-UBD.d.ts} +1 -1
  11. package/dist/canvas/index.d.ts +5 -5
  12. package/dist/canvas/index.js +1 -1
  13. package/dist/chrome/index.d.ts +4 -4
  14. package/dist/chrome/index.js +7 -7
  15. package/dist/chunk-6BUQ77ZV.js +18 -0
  16. package/dist/chunk-6BUQ77ZV.js.map +1 -0
  17. package/dist/{chunk-KJALCDWE.js → chunk-753Y6HE6.js} +9 -9
  18. package/dist/chunk-753Y6HE6.js.map +1 -0
  19. package/dist/{chunk-6ZDGOZQV.js → chunk-A2ACAGW6.js} +72 -20
  20. package/dist/chunk-A2ACAGW6.js.map +1 -0
  21. package/dist/{chunk-NS64DXMN.js → chunk-CKUKF72R.js} +44 -21
  22. package/dist/chunk-CKUKF72R.js.map +1 -0
  23. package/dist/{chunk-MUKOW3TC.js → chunk-D35PFTS7.js} +4 -4
  24. package/dist/{chunk-MUKOW3TC.js.map → chunk-D35PFTS7.js.map} +1 -1
  25. package/dist/{chunk-UU3NJO6N.js → chunk-EMXAIRUJ.js} +3 -3
  26. package/dist/{chunk-UU3NJO6N.js.map → chunk-EMXAIRUJ.js.map} +1 -1
  27. package/dist/{chunk-ZPH5WTWF.js → chunk-ERFMC6WU.js} +142 -66
  28. package/dist/chunk-ERFMC6WU.js.map +1 -0
  29. package/dist/chunk-FKLT3ITC.js +590 -0
  30. package/dist/chunk-FKLT3ITC.js.map +1 -0
  31. package/dist/{chunk-QLSV2N3G.js → chunk-IJJUK4FU.js} +25 -13
  32. package/dist/chunk-IJJUK4FU.js.map +1 -0
  33. package/dist/{chunk-EKIICY6X.js → chunk-KJCUERQF.js} +37 -25
  34. package/dist/chunk-KJCUERQF.js.map +1 -0
  35. package/dist/chunk-LASCBWW7.js +13456 -0
  36. package/dist/chunk-LASCBWW7.js.map +1 -0
  37. package/dist/{chunk-67SJLMC7.js → chunk-LRI3MBGR.js} +45 -12
  38. package/dist/chunk-LRI3MBGR.js.map +1 -0
  39. package/dist/chunk-REOBGYMC.js +150 -0
  40. package/dist/chunk-REOBGYMC.js.map +1 -0
  41. package/dist/{chunk-PGETSEDK.js → chunk-TT5C5S6R.js} +11 -90
  42. package/dist/chunk-TT5C5S6R.js.map +1 -0
  43. package/dist/{chunk-NDRYLVOW.js → chunk-Z76KEZAX.js} +2 -2
  44. package/dist/chunk-Z76KEZAX.js.map +1 -0
  45. package/dist/config/index.d.ts +62 -19
  46. package/dist/config/index.js +6 -4
  47. package/dist/controls/index.d.ts +3 -3
  48. package/dist/controls/index.js +4 -4
  49. package/dist/dragdrop/index.d.ts +3 -3
  50. package/dist/index.d.ts +230 -62
  51. package/dist/index.js +1367 -1698
  52. package/dist/index.js.map +1 -1
  53. package/dist/layers/index.d.ts +4 -4
  54. package/dist/layers/index.js +2 -2
  55. package/dist/loupe/index.d.ts +67 -16
  56. package/dist/loupe/index.js +1 -1
  57. package/dist/passthrough/weasel-ui.d.ts +57 -230
  58. package/dist/passthrough/weasel-ui.js +1 -1
  59. package/dist/primitives/index.d.ts +3 -1
  60. package/dist/primitives/index.js +3 -3
  61. package/dist/state/index.d.ts +5 -5
  62. package/dist/state/index.js +5 -3
  63. package/dist/state/index.js.map +1 -1
  64. package/dist/styles.css +266 -57
  65. package/dist/surface/index.js +1 -1
  66. package/dist/ui/layers/index.js +1 -1
  67. package/dist/undo/index.d.ts +3 -3
  68. package/package.json +9 -9
  69. package/src/annotations/AnnotationOverlay.tsx +3 -0
  70. package/src/annotations/Annotations.less +4 -0
  71. package/src/annotations/Annotations.overlay.test.tsx +20 -0
  72. package/src/annotations/svgNodes.ts +1 -0
  73. package/src/annotations/toolMap.test.ts +9 -5
  74. package/src/annotations/toolMap.ts +3 -0
  75. package/src/canvas/CanvasStack.stories.tsx +1 -1
  76. package/src/canvas/index.ts +0 -9
  77. package/src/canvas/usePanZoom.test.ts +28 -0
  78. package/src/canvas/usePanZoom.ts +11 -4
  79. package/src/chrome/ChromeRegions.stories.tsx +1 -1
  80. package/src/chrome/LabChrome.tsx +21 -5
  81. package/src/chrome/builtins.test.ts +1 -0
  82. package/src/chrome/builtins.tsx +1 -0
  83. package/src/chrome/index.ts +1 -0
  84. package/src/chrome/labTypes.ts +3 -3
  85. package/src/chrome/regions/PaletteRegion.test.tsx +18 -0
  86. package/src/chrome/regions/PaletteRegion.tsx +6 -10
  87. package/src/chrome/regions/SidebarRegion.stories.tsx +44 -0
  88. package/src/chrome/regions/TitleBarRegion.tsx +1 -1
  89. package/src/chrome/regions/ToolbarRegion.tsx +11 -7
  90. package/src/chrome/types.ts +11 -2
  91. package/src/config/auto.test.ts +12 -0
  92. package/src/config/auto.ts +15 -0
  93. package/src/config/autoConfig.test.ts +107 -0
  94. package/src/config/autoConfig.ts +153 -0
  95. package/src/config/builder.test.ts +38 -0
  96. package/src/config/builder.ts +55 -11
  97. package/src/config/index.ts +3 -0
  98. package/src/config/path.ts +7 -2
  99. package/src/config/resolve.test.ts +25 -0
  100. package/src/config/resolve.ts +17 -1
  101. package/src/config/types.ts +32 -2
  102. package/src/config/useResolvedConfig.ts +26 -0
  103. package/src/controls/AutoControls.stories.tsx +88 -0
  104. package/src/controls/ControlPanel.less +23 -0
  105. package/src/controls/ControlPanel.stories.tsx +83 -1
  106. package/src/controls/ControlPanel.test.tsx +457 -4
  107. package/src/controls/ControlPanel.tsx +534 -73
  108. package/src/index.test.ts +0 -2
  109. package/src/index.ts +33 -11
  110. package/src/instrument/serializers.ts +29 -1
  111. package/src/lab/Lab.chrome.test.tsx +16 -0
  112. package/src/lab/Lab.stories.tsx +1 -1
  113. package/src/lab/Lab.surface.test.tsx +7 -2
  114. package/src/lab/Lab.test.tsx +79 -1
  115. package/src/lab/Lab.tsx +124 -16
  116. package/src/lab/LabContext.ts +8 -0
  117. package/src/lab/LabFit.stories.tsx +4 -4
  118. package/src/lab/LabFullChrome.stories.tsx +1 -1
  119. package/src/lab/LabHeader.tsx +0 -1
  120. package/src/lab/LabRoot.test.tsx +56 -0
  121. package/src/lab/LabRoot.tsx +47 -0
  122. package/src/lab/LabShell.less +24 -3
  123. package/src/lab/LabShell.stories.tsx +50 -1
  124. package/src/lab/LabShell.tsx +18 -27
  125. package/src/lab/LabSwitcher.less +10 -10
  126. package/src/lab/LabSwitcher.test.tsx +14 -9
  127. package/src/lab/LabSwitcher.tsx +8 -4
  128. package/src/lab/Workspace.less +1 -1
  129. package/src/lab/Workspace.stories.tsx +1 -1
  130. package/src/lab/Workspace.surface.test.tsx +1 -1
  131. package/src/lab/index.ts +2 -0
  132. package/src/layers/LayerList.less +1 -1
  133. package/src/layers/LayerList.stories.tsx +2 -2
  134. package/src/loupe/AGENTS.md +16 -4
  135. package/src/loupe/LoupeGestures.tsx +67 -0
  136. package/src/loupe/TrialLoupe.tsx +43 -28
  137. package/src/loupe/index.ts +4 -0
  138. package/src/loupe/loupeActions.ts +98 -0
  139. package/src/loupe/useLoupe.test.tsx +59 -2
  140. package/src/loupe/useLoupe.ts +28 -48
  141. package/src/passthrough/weasel-ui.ts +3 -3
  142. package/src/primitives/FloatingPanel.stories.tsx +1 -1
  143. package/src/primitives/FpsMeter.less +6 -1
  144. package/src/primitives/FpsMeter.stories.tsx +1 -1
  145. package/src/primitives/FpsMeter.test.tsx +12 -4
  146. package/src/primitives/FpsMeter.tsx +6 -1
  147. package/src/primitives/JobProgress.stories.tsx +2 -2
  148. package/src/primitives/Legend.stories.tsx +1 -1
  149. package/src/primitives/ScaleIndicator.stories.tsx +1 -1
  150. package/src/primitives/Sidebar.less +7 -0
  151. package/src/primitives/Sidebar.stories.tsx +1 -1
  152. package/src/primitives/Split.test.tsx +25 -0
  153. package/src/primitives/Split.tsx +36 -20
  154. package/src/primitives/StatusBar.less +6 -0
  155. package/src/primitives/StatusBar.stories.tsx +1 -1
  156. package/src/primitives/Toolbar.stories.tsx +1 -1
  157. package/src/specimen/Specimen.less +95 -0
  158. package/src/specimen/Specimen.stories.tsx +13 -0
  159. package/src/specimen/Specimen.test.tsx +13 -0
  160. package/src/specimen/Specimen.tsx +888 -0
  161. package/src/state/Persistence.stories.tsx +4 -4
  162. package/src/state/store.test.ts +65 -0
  163. package/src/state/store.ts +32 -8
  164. package/src/state/types.ts +31 -2
  165. package/src/state/useTrialState.test.tsx +85 -0
  166. package/src/state/useTrialState.ts +9 -1
  167. package/src/state/view.test.ts +4 -4
  168. package/src/styles.less +1 -0
  169. package/src/surface/index.ts +1 -1
  170. package/src/surface/useSurfaceTile.test.tsx +1 -1
  171. package/src/surface/useTiledSurface.test.tsx +65 -10
  172. package/src/surface/useTiledSurface.ts +23 -11
  173. package/src/theme/Interstellar.stories.tsx +2 -2
  174. package/src/theme/interstellar.test.ts +16 -5
  175. package/src/theme/interstellar.theme.json +180 -0
  176. package/src/theme/interstellar.ts +8 -5
  177. package/src/tools/labTool.ts +3 -3
  178. package/src/trial/Trial.annotations.test.tsx +13 -4
  179. package/src/trial/Trial.canvas.test.tsx +36 -0
  180. package/src/trial/Trial.config.test.tsx +75 -2
  181. package/src/trial/Trial.less +4 -0
  182. package/src/trial/Trial.stories.tsx +4 -1
  183. package/src/trial/Trial.test.tsx +3 -0
  184. package/src/trial/Trial.tsx +21 -14
  185. package/src/trial/TrialChrome.tsx +17 -3
  186. package/src/trial/trialOps.test.ts +101 -1
  187. package/src/trial/trialOps.ts +62 -4
  188. package/dist/_dts/ToggleBar.d-DbHoWKIA.d.ts +0 -116
  189. package/dist/chunk-67SJLMC7.js.map +0 -1
  190. package/dist/chunk-6ZDGOZQV.js.map +0 -1
  191. package/dist/chunk-E44SU6XS.js +0 -50
  192. package/dist/chunk-E44SU6XS.js.map +0 -1
  193. package/dist/chunk-EKIICY6X.js.map +0 -1
  194. package/dist/chunk-KJALCDWE.js.map +0 -1
  195. package/dist/chunk-NDRYLVOW.js.map +0 -1
  196. package/dist/chunk-NS64DXMN.js.map +0 -1
  197. package/dist/chunk-PGETSEDK.js.map +0 -1
  198. package/dist/chunk-QLSV2N3G.js.map +0 -1
  199. package/dist/chunk-S2SHZRD7.js +0 -7681
  200. package/dist/chunk-S2SHZRD7.js.map +0 -1
  201. package/dist/chunk-TQBBYTAF.js +0 -280
  202. package/dist/chunk-TQBBYTAF.js.map +0 -1
  203. package/dist/chunk-ZPH5WTWF.js.map +0 -1
  204. package/src/canvas/useOrbit.test.ts +0 -167
  205. package/src/canvas/useOrbit.ts +0 -156
  206. package/src/theme/interstellar.tokens.json +0 -61
@@ -1,3 +1,4 @@
1
+ import { WeaselProvider } from '@weasel-js/core';
1
2
  import { type RefObject, useContext, useMemo } from 'react';
2
3
  import { CanvasStackContext } from '../canvas/CanvasStackContext';
3
4
  import type { WorldSpec } from '../canvas/worldSpec';
@@ -6,6 +7,7 @@ import { CanvasLoupe } from './CanvasLoupe';
6
7
  import { sampleStack } from './canvasLens';
7
8
  import { DomLoupe } from './DomLoupe';
8
9
  import { LoupeBubble } from './LoupeBubble';
10
+ import { LoupeGestures } from './LoupeGestures';
9
11
  import type { ResolvedLoupe } from './types';
10
12
  import { useHostSize } from './useHostSize';
11
13
  import { useLoupe } from './useLoupe';
@@ -59,35 +61,48 @@ export function TrialLoupe({
59
61
  const measured = useHostSize(host);
60
62
  const size = surface?.size ?? measured;
61
63
 
62
- if (!loupe.visible) return null;
64
+ // The gestures mount outside the visibility gate: hold-to-peek is what
65
+ // raises a lens that is down, so its binding has to be live while it is.
66
+ // One isolated scope per loupe, for the reason `<AnnotationOverlay>` gives
67
+ // — an actions registry holds one dispatcher.
68
+ const gestures = (
69
+ <WeaselProvider isolate>
70
+ <LoupeGestures hostRef={host} input={loupe.input} peekKey={capability.peekKey ?? null} />
71
+ </WeaselProvider>
72
+ );
73
+
74
+ if (!loupe.visible) return gestures;
63
75
 
64
76
  return (
65
- <LoupeBubble aim={loupe.aim} diameter={capability.diameter}>
66
- {capability.render ? (
67
- <DomLoupe
68
- aim={loupe.aim}
69
- factor={loupe.factor}
70
- mode={loupe.mode}
71
- diameter={capability.diameter}
72
- size={size}
73
- view={view}
74
- frame={stack?.frame}
75
- state={state}
76
- config={config}
77
- render={capability.render}
78
- />
79
- ) : surface && stack ? (
80
- <CanvasLoupe
81
- aim={loupe.aim}
82
- factor={loupe.factor}
83
- mode={loupe.mode}
84
- diameter={capability.diameter}
85
- surface={surface}
86
- view={stack.view}
87
- frame={stack.frame}
88
- worldSpec={worldSpec}
89
- />
90
- ) : null}
91
- </LoupeBubble>
77
+ <>
78
+ {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>
106
+ </>
92
107
  );
93
108
  }
@@ -6,6 +6,10 @@ export type { DomLoupeProps } from './DomLoupe';
6
6
  export { DomLoupe } from './DomLoupe';
7
7
  export type { LoupeBubbleProps } from './LoupeBubble';
8
8
  export { LoupeBubble } from './LoupeBubble';
9
+ export type { LoupeGesturesProps } from './LoupeGestures';
10
+ export { LoupeGestures } from './LoupeGestures';
11
+ export type { LoupeInputApi } from './loupeActions';
12
+ export { createLoupeActions, LOUPE_MAGNIFY_ID, LOUPE_PEEK_ID } from './loupeActions';
9
13
  export type { TrialLoupeProps } from './TrialLoupe';
10
14
  export { TrialLoupe } from './TrialLoupe';
11
15
  export type {
@@ -0,0 +1,98 @@
1
+ /**
2
+ * The loupe's two bindable interactions, as `Action` descriptors the gesture
3
+ * dispatcher routes: hold a key to peek, and walk the magnification with the
4
+ * wheel.
5
+ *
6
+ * Free of React so the routing can be tested without a DOM.
7
+ */
8
+ import type { Action } from '@weasel-js/core';
9
+
10
+ /** Canonical id of the hold-to-peek action. */
11
+ export const LOUPE_PEEK_ID = 'loupe.peek';
12
+ /** Canonical id of the wheel-magnify action. */
13
+ export const LOUPE_MAGNIFY_ID = 'loupe.magnify';
14
+
15
+ /** How fast the wheel walks the magnification. Gentler than the pan-zoom
16
+ * wheel: the lens' whole range is one order of magnitude. */
17
+ export const WHEEL_RATE = 0.002;
18
+
19
+ /** What the actions do to a live loupe. Every member is read through the
20
+ * object on each invocation, so one stable instance serves the life of the
21
+ * registration. */
22
+ export interface LoupeInputApi {
23
+ /** Whether the lens is up. The wheel belongs to the loupe only while it is;
24
+ * otherwise `loupe.magnify` declines and the dispatcher leaves the event
25
+ * unhandled, which is what hands it back to the lab's own pan/zoom. */
26
+ shown: () => boolean;
27
+ /** Raise or drop the hold-to-peek flag. */
28
+ setPeeking: (on: boolean) => void;
29
+ /** Multiply the magnification by one wheel notch of `deltaY`. */
30
+ magnifyBy: (deltaY: number) => void;
31
+ }
32
+
33
+ /**
34
+ * Build the loupe's actions. `peekKey` is a `KeyboardEvent.key`; passing
35
+ * `null` omits `loupe.peek` entirely rather than registering a binding no key
36
+ * can match.
37
+ */
38
+ export function createLoupeActions(
39
+ input: LoupeInputApi,
40
+ peekKey: string | null,
41
+ ): readonly Action[] {
42
+ const magnify: Action = {
43
+ id: LOUPE_MAGNIFY_ID,
44
+ label: 'Magnify (loupe)',
45
+ group: 'loupe',
46
+ // Every modifier optional: the lens claims the wheel whenever it is up,
47
+ // which is what the hand-rolled capture-phase listener did. A bare spec
48
+ // would forbid modifiers and hand Cmd+wheel back to the lab mid-peek.
49
+ defaultBinding: [
50
+ {
51
+ spec: {
52
+ kind: 'wheel',
53
+ mods: { alt: 'optional', ctrl: 'optional', meta: 'optional', shift: 'optional' },
54
+ },
55
+ opts: {},
56
+ },
57
+ ],
58
+ enabled: () => (input.shown() ? true : 'not-applicable'),
59
+ invoker: {
60
+ timing: 'immediate',
61
+ run(_deps, params) {
62
+ input.magnifyBy((params?.deltaY as number | undefined) ?? 0);
63
+ },
64
+ },
65
+ };
66
+
67
+ if (peekKey === null) return [magnify];
68
+
69
+ const peek: Action = {
70
+ id: LOUPE_PEEK_ID,
71
+ label: 'Peek (loupe)',
72
+ group: 'loupe',
73
+ // Hotkey scope: peeking must beat whatever the lab's active tool binds to
74
+ // the same key, the way every other held-key trigger does.
75
+ scope: 'hotkey',
76
+ // Every modifier optional because the peek key may BE one: the keydown
77
+ // that carries `Alt` — the default — also reports `altKey: true`, and the
78
+ // matcher forbids any modifier a spec does not name.
79
+ defaultBinding: [
80
+ {
81
+ spec: {
82
+ kind: 'key-held',
83
+ key: peekKey,
84
+ mods: { alt: 'optional', ctrl: 'optional', meta: 'optional', shift: 'optional' },
85
+ },
86
+ opts: {},
87
+ },
88
+ ],
89
+ invoker: {
90
+ timing: 'ongoing',
91
+ start() {
92
+ input.setPeeking(true);
93
+ return { onEnd: () => input.setPeeking(false) };
94
+ },
95
+ },
96
+ };
97
+ return [peek, magnify];
98
+ }
@@ -1,6 +1,8 @@
1
1
  import { act, fireEvent, render, screen } from '@testing-library/react';
2
+ import { WeaselProvider } from '@weasel-js/core';
2
3
  import { type RefObject, StrictMode, useRef } from 'react';
3
4
  import { describe, expect, it, vi } from 'vitest';
5
+ import { LoupeGestures } from './LoupeGestures';
4
6
  import { resolveLoupe } from './types';
5
7
  import { type LoupeState, useLoupe } from './useLoupe';
6
8
 
@@ -15,18 +17,29 @@ interface HarnessProps {
15
17
  }
16
18
 
17
19
  /** Reports the loupe's state as text, which is every assertion jsdom can make
18
- * about a magnifier — that the lens shows the right region is a screenshot. */
20
+ * about a magnifier — that the lens shows the right region is a screenshot.
21
+ *
22
+ * Mounts `<LoupeGestures>` the way `<TrialLoupe>` does, so the key and wheel
23
+ * cases below exercise the real dispatcher route rather than a stand-in. */
19
24
  function Harness({ enabled = true, seen, sample, ...rest }: HarnessProps) {
20
25
  const hostRef = useRef<HTMLDivElement | null>(null);
26
+ const capability = resolveLoupe(rest);
21
27
  const loupe = useLoupe({
22
28
  hostRef: hostRef as RefObject<HTMLElement | null>,
23
29
  enabled,
24
30
  sample,
25
- capability: resolveLoupe(rest),
31
+ capability,
26
32
  });
27
33
  seen?.(loupe);
28
34
  return (
29
35
  <div ref={hostRef} data-testid="host">
36
+ <WeaselProvider isolate>
37
+ <LoupeGestures
38
+ hostRef={hostRef as RefObject<HTMLElement | null>}
39
+ input={loupe.input}
40
+ peekKey={capability.peekKey ?? null}
41
+ />
42
+ </WeaselProvider>
30
43
  <span data-testid="visible">{String(loupe.visible)}</span>
31
44
  <span data-testid="aim">{`${loupe.aim.x},${loupe.aim.y}`}</span>
32
45
  <span data-testid="factor">{loupe.factor}</span>
@@ -94,6 +107,7 @@ describe('useLoupe', () => {
94
107
  act(() => {
95
108
  fireEvent.keyDown(window, { key: 'Alt' });
96
109
  });
110
+ expect(read('visible')).toBe('true');
97
111
  act(() => {
98
112
  fireEvent.blur(window);
99
113
  });
@@ -148,6 +162,49 @@ describe('useLoupe', () => {
148
162
  expect(wheel.defaultPrevented).toBe(true);
149
163
  });
150
164
 
165
+ it('stops a claimed wheel reaching the pan-zoom handler above it', () => {
166
+ // The real handler is React's, delegated to the root container, so what
167
+ // decides whether pan-zoom runs is whether the event bubbles past the
168
+ // host — `defaultPrevented` says nothing about that. A listener on an
169
+ // ancestor is the proxy for React's root one.
170
+ const above = vi.fn();
171
+ const { container } = render(<Harness />);
172
+ container.addEventListener('wheel', above);
173
+
174
+ const host = screen.getByTestId('host');
175
+ move(40, 25);
176
+ act(() => {
177
+ host.dispatchEvent(
178
+ new WheelEvent('wheel', { deltaY: -100, bubbles: true, cancelable: true }),
179
+ );
180
+ });
181
+ expect(above).not.toHaveBeenCalled();
182
+
183
+ fireEvent.pointerLeave(host);
184
+ act(() => {
185
+ host.dispatchEvent(
186
+ new WheelEvent('wheel', { deltaY: -100, bubbles: true, cancelable: true }),
187
+ );
188
+ });
189
+ expect(above).toHaveBeenCalledTimes(1);
190
+ });
191
+
192
+ it('leaves the native context menu and file drops to the lab', () => {
193
+ // The dispatcher suppresses `contextmenu` unconditionally and makes its
194
+ // element a drop target; the loupe mounts with both channels off, so a
195
+ // lab that turns a magnifier on keeps its right-click and its drops.
196
+ render(<Harness />);
197
+ const host = screen.getByTestId('host');
198
+ move(40, 25);
199
+
200
+ const menu = new MouseEvent('contextmenu', { bubbles: true, cancelable: true });
201
+ act(() => {
202
+ host.dispatchEvent(menu);
203
+ });
204
+ expect(menu.defaultPrevented).toBe(false);
205
+ expect(host.classList.contains('weasel-dropover')).toBe(false);
206
+ });
207
+
151
208
  it('reports the color under the aim', () => {
152
209
  const onColorChange = vi.fn();
153
210
  render(
@@ -5,6 +5,8 @@ import {
5
5
  type LoupePoint,
6
6
  } from '@weasel-js/loupe';
7
7
  import { type RefObject, useCallback, useEffect, useReducer, useRef } from 'react';
8
+ import type { LoupeInputApi } from './loupeActions';
9
+ import { WHEEL_RATE } from './loupeActions';
8
10
  import type { ResolvedLoupe } from './types';
9
11
 
10
12
  /** Options for {@link useLoupe}. */
@@ -32,21 +34,21 @@ export interface LoupeState {
32
34
  setFactor: (factor: number) => void;
33
35
  /** Sample what the lens shows at a point inside it. */
34
36
  pick: (p?: LoupePoint) => string | null;
37
+ /** What `<LoupeGestures>` drives the lens through. Stable for the life of
38
+ * the hook, so registering the actions on it does not churn. */
39
+ input: LoupeInputApi;
35
40
  }
36
41
 
37
- /** How fast the wheel walks the magnification. Gentler than the pan-zoom
38
- * wheel: the lens' whole range is one order of magnitude. */
39
- const WHEEL_RATE = 0.002;
40
-
41
42
  /**
42
- * Binds `@weasel-js/loupe`'s model to a host element and drives it from the
43
- * pointer, the peek key and the wheel.
43
+ * Binds `@weasel-js/loupe`'s model to a host element and tracks the pointer
44
+ * across it.
44
45
  *
45
- * These are plain listeners rather than gesture bindings because labkit trials
46
- * do not route input through the dispatcher — see the loupe entry under
47
- * "Selection, actions & UI panels" in `docs/TODO.md`. They are all in this one
48
- * hook so that when trial input does go through it, this is the only file to
49
- * rewrite.
46
+ * The peek key and the wheel are not here: they are `loupe.peek` and
47
+ * `loupe.magnify`, routed through the gesture dispatcher that
48
+ * `<LoupeGestures>` mounts on the same host. Aiming stays a plain listener
49
+ * because a hover is not a gesture the grammar names — `GESTURE_DESCRIPTORS`
50
+ * has no continuous-motion entry, and inventing one to carry the lens' aim
51
+ * would be an input taxonomy change, not a loupe change.
50
52
  */
51
53
  export function useLoupe({ capability, hostRef, enabled, sample }: UseLoupeOptions): LoupeState {
52
54
  const [, bump] = useReducer((n: number) => n + 1, 0);
@@ -128,53 +130,30 @@ export function useLoupe({ capability, hostRef, enabled, sample }: UseLoupeOptio
128
130
  overRef.current = false;
129
131
  bump();
130
132
  };
131
- const onWheel = (e: WheelEvent): void => {
132
- if (!shown()) return;
133
- // Ahead of the stack's own pan-zoom, which is a React handler on this same
134
- // element: capture runs first, and stopping propagation keeps the event
135
- // from reaching React's root listener at all.
136
- e.preventDefault();
137
- e.stopPropagation();
138
- model.setFactor(model.factor * Math.exp(-e.deltaY * WHEEL_RATE));
139
- };
140
133
 
141
134
  host.addEventListener('pointermove', onPointerMove);
142
135
  host.addEventListener('pointerleave', onPointerLeave);
143
- host.addEventListener('wheel', onWheel, { capture: true, passive: false });
144
136
  return () => {
145
137
  host.removeEventListener('pointermove', onPointerMove);
146
138
  host.removeEventListener('pointerleave', onPointerLeave);
147
- host.removeEventListener('wheel', onWheel, { capture: true });
148
139
  };
149
140
  }, [hostRef, model, shown]);
150
141
 
151
- const peekKey = capability.peekKey;
152
- useEffect(() => {
153
- if (peekKey == null) return;
154
- const setPeeking = (next: boolean): void => {
155
- if (peekingRef.current === next) return;
156
- peekingRef.current = next;
157
- bump();
158
- };
159
- const onKeyDown = (e: KeyboardEvent): void => {
160
- if (e.key === peekKey) setPeeking(true);
161
- };
162
- const onKeyUp = (e: KeyboardEvent): void => {
163
- if (e.key === peekKey) setPeeking(false);
164
- };
165
- // A key held while the window loses focus never sends its keyup, so the
166
- // peek would stay on until the key was pressed and released again.
167
- const onBlur = (): void => setPeeking(false);
168
-
169
- window.addEventListener('keydown', onKeyDown);
170
- window.addEventListener('keyup', onKeyUp);
171
- window.addEventListener('blur', onBlur);
172
- return () => {
173
- window.removeEventListener('keydown', onKeyDown);
174
- window.removeEventListener('keyup', onKeyUp);
175
- window.removeEventListener('blur', onBlur);
142
+ const inputRef = useRef<LoupeInputApi | null>(null);
143
+ if (inputRef.current === null) {
144
+ inputRef.current = {
145
+ shown,
146
+ setPeeking: (on) => {
147
+ if (peekingRef.current === on) return;
148
+ peekingRef.current = on;
149
+ bump();
150
+ },
151
+ magnifyBy: (deltaY) => {
152
+ const m = modelRef.current;
153
+ if (m) m.setFactor(m.factor * Math.exp(-deltaY * WHEEL_RATE));
154
+ },
176
155
  };
177
- }, [peekKey]);
156
+ }
178
157
 
179
158
  return {
180
159
  visible: shown(),
@@ -185,5 +164,6 @@ export function useLoupe({ capability, hostRef, enabled, sample }: UseLoupeOptio
185
164
  setMode: model.setMode,
186
165
  setFactor: model.setFactor,
187
166
  pick: model.pick,
167
+ input: inputRef.current,
188
168
  };
189
169
  }
@@ -15,6 +15,8 @@ export {
15
15
  type ActionsBarVariant,
16
16
  type AddPointMode,
17
17
  type AnchorRenderProps,
18
+ type AsyncOption,
19
+ type AsyncOptionsResult,
18
20
  type AxesSettings,
19
21
  Badge,
20
22
  type BadgeProps,
@@ -191,12 +193,10 @@ export {
191
193
  ToolPalette,
192
194
  type ToolPaletteProps,
193
195
  type TrackCtx,
196
+ type UseAsyncOptionsProps,
194
197
  type UseReorderDragListOptions,
195
198
  type UseRovingTabIndexOptions,
196
199
  useAsyncOptions,
197
- type AsyncOption,
198
- type AsyncOptionsResult,
199
- type UseAsyncOptionsProps,
200
200
  useReorderDragList,
201
201
  useRovingTabIndex,
202
202
  visiblePrefSubtree,
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from '@storybook/react-vite';
1
+ import type { Meta, StoryObj } from '@weasel-js/forge';
2
2
  import { localStorageAdapter } from '../state/adapters';
3
3
  import { Persistence } from '../state/Persistence';
4
4
  import { FloatingPanel } from './FloatingPanel';
@@ -1,6 +1,7 @@
1
1
  .lk-fps-meter {
2
2
  display: inline-flex;
3
3
  align-items: center;
4
+ white-space: nowrap;
4
5
  gap: var(--wzl-space-xs);
5
6
  font-family: var(--wzl-font-mono);
6
7
  font-size: var(--wzl-font-size-sm);
@@ -9,6 +10,10 @@
9
10
 
10
11
  .lk-fps-meter-value {
11
12
  color: var(--wzl-fg);
12
- min-width: 2.5ch;
13
+ /* Sized for the widest rate it can hold rather than the one it holds now:
14
+ a 240Hz display reads three digits, and a readout that grows into them
15
+ pushes whatever shares its row. */
16
+ min-width: 3ch;
17
+ font-variant-numeric: tabular-nums;
13
18
  text-align: right;
14
19
  }
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from '@storybook/react-vite';
1
+ import type { Meta, StoryObj } from '@weasel-js/forge';
2
2
  import { FpsMeter } from './FpsMeter';
3
3
 
4
4
  const meta: Meta<typeof FpsMeter> = {
@@ -9,9 +9,17 @@ describe('FpsMeter', () => {
9
9
 
10
10
  test('renders an FPS label', () => {
11
11
  render(<FpsMeter />);
12
- expect(screen.getByText(/fps/i)).toBeInTheDocument();
12
+ expect(screen.getByText('FPS')).toBeInTheDocument();
13
13
  });
14
14
 
15
+ /* The label and the rate are separate elements so the rate can hold a fixed
16
+ width; a text query spanning both would go back to matching one box. */
17
+ const rate = (): HTMLElement => {
18
+ const el = document.querySelector('.lk-fps-meter-value');
19
+ if (!el) throw new Error('no rate readout');
20
+ return el as HTMLElement;
21
+ };
22
+
15
23
  test('uses lk-fps-meter class', () => {
16
24
  const { container } = render(<FpsMeter />);
17
25
  expect((container.firstChild as HTMLElement).className).toBe('lk-fps-meter');
@@ -31,7 +39,7 @@ describe('FpsMeter', () => {
31
39
  raf?.(16.67);
32
40
  raf?.(33.34);
33
41
  });
34
- expect(screen.getByText(/FPS\s+\d+/)).toBeInTheDocument();
42
+ expect(rate().textContent).toMatch(/^\d+$/);
35
43
 
36
44
  vi.unstubAllGlobals();
37
45
  });
@@ -59,7 +67,7 @@ describe('FpsMeter', () => {
59
67
  run(16.67);
60
68
  run(33.34);
61
69
  });
62
- const before = screen.getByText(/FPS\s+\d+/).textContent;
70
+ const before = rate().textContent;
63
71
 
64
72
  // An hour hidden. The frame that lands on resume is not a 60-minute frame,
65
73
  // and must not enter the rolling average as one.
@@ -74,7 +82,7 @@ describe('FpsMeter', () => {
74
82
  run(3_600_016.67);
75
83
  });
76
84
 
77
- expect(screen.getByText(/FPS\s+\d+/).textContent).toBe(before);
85
+ expect(rate().textContent).toBe(before);
78
86
 
79
87
  setHidden(false);
80
88
  vi.unstubAllGlobals();
@@ -42,7 +42,12 @@ export function FpsMeter() {
42
42
 
43
43
  return (
44
44
  <div className="lk-fps-meter" ref={rootRef}>
45
- <span className="lk-fps-meter-value">FPS {fps}</span>
45
+ <span className="lk-fps-meter-label">FPS</span>
46
+ {/* The number is its own cell because it is the only part that changes:
47
+ in one box with the label, every digit it gains or loses resizes the
48
+ readout, and the status bar it sits in wraps to a second line and
49
+ back — which in a small trial resizes the window. */}
50
+ <span className="lk-fps-meter-value">{fps}</span>
46
51
  </div>
47
52
  );
48
53
  }
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from '@storybook/react-vite';
1
+ import type { Meta, StoryObj } from '@weasel-js/forge';
2
2
  import type { JobHandle } from '../job/types';
3
3
  import { JobProgress } from './JobProgress';
4
4
 
@@ -13,7 +13,7 @@ const base: JobHandle = {
13
13
  };
14
14
 
15
15
  const meta: Meta<typeof JobProgress> = {
16
- title: 'labkit/primitives/JobProgress',
16
+ title: 'labkit/Primitives/JobProgress',
17
17
  component: JobProgress,
18
18
  };
19
19
  export default meta;
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from '@storybook/react-vite';
1
+ import type { Meta, StoryObj } from '@weasel-js/forge';
2
2
  import { Legend } from './Legend';
3
3
 
4
4
  const meta: Meta<typeof Legend> = {
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from '@storybook/react-vite';
1
+ import type { Meta, StoryObj } from '@weasel-js/forge';
2
2
  import { ScaleIndicator } from './ScaleIndicator';
3
3
 
4
4
  const meta: Meta<typeof ScaleIndicator> = {
@@ -60,6 +60,13 @@
60
60
 
61
61
  .lk-sidebar-section {
62
62
  border-bottom: var(--wzl-border-w) solid var(--wzl-line-subtle);
63
+
64
+ // The last section runs to the bottom of its pane. Stopped at its content,
65
+ // its rule and the bare pane under it read as a second, empty zone.
66
+ &:last-child {
67
+ flex-grow: 1;
68
+ border-bottom: 0;
69
+ }
63
70
  }
64
71
 
65
72
  .lk-sidebar-section__bar {
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from '@storybook/react-vite';
1
+ import type { Meta, StoryObj } from '@weasel-js/forge';
2
2
  import { useState } from 'react';
3
3
  import { Sidebar } from './Sidebar';
4
4
 
@@ -83,6 +83,31 @@ describe('Split', () => {
83
83
  expect(container.querySelector('.lk-x__main')?.textContent).toBe('main');
84
84
  });
85
85
 
86
+ it('puts the sidebar after the content on the end side, where dragging the seam left widens it', () => {
87
+ const onWidthChange = vi.fn();
88
+ const { container } = render(
89
+ <Split
90
+ viewport={VIEWPORT}
91
+ side="end"
92
+ width={320}
93
+ sidebarClassName="lk-x__side"
94
+ contentClassName="lk-x__main"
95
+ sidebar={<p>side</p>}
96
+ onWidthChange={onWidthChange}
97
+ >
98
+ <p>main</p>
99
+ </Split>,
100
+ );
101
+ const side = container.querySelector('.lk-x__side') as HTMLElement;
102
+ const main = container.querySelector('.lk-x__main') as HTMLElement;
103
+ expect(main.compareDocumentPosition(side) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
104
+ const seam = screen.getByRole('separator');
105
+ fireEvent.pointerDown(seam, { clientX: 480, clientY: 100 });
106
+ fireEvent.pointerMove(seam, { clientX: 420, clientY: 100 });
107
+ fireEvent.pointerUp(seam, { clientX: 420, clientY: 100 });
108
+ expect(onWidthChange).toHaveBeenLastCalledWith(380);
109
+ });
110
+
86
111
  it('names its seam after the sidebar label', () => {
87
112
  render(
88
113
  <Split viewport={VIEWPORT} label="Stories" sidebar={<p>side</p>}>