@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,549 +0,0 @@
1
- import { centerOn, zoomAt } from './chunk-JVBYV6TL.js';
2
- import { screenToWorld } from './chunk-AWQG7FCC.js';
3
- import { CameraContext, CameraScope } from './chunk-DWMSB4CA.js';
4
- import { resolveFrame, DEFAULT_FRAME } from './chunk-24W5VEJW.js';
5
- import { CanvasStackContext } from './chunk-CQLQPQ4P.js';
6
- import { useVisibleRaf, useActionsRegistry, useGestureDispatcher, normalizeZoom } from '@weasel-js/core';
7
- import { useRef, useEffect, useContext, useReducer, useCallback, useMemo, useState } from 'react';
8
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
9
-
10
- // src/loupe/canvasLens.ts
11
- function lensCamera(aim, outer, outerFrame, factor, diameter, worldSpec) {
12
- const size = { width: diameter, height: diameter };
13
- const frame = resolveFrame(worldSpec, size);
14
- const world = screenToWorld(aim, outer, outerFrame);
15
- return { view: centerOn(world, outer.zoom * factor, size, frame), frame };
16
- }
17
- function lensSourceRect(aim, factor, diameter, dpr) {
18
- const span = diameter / factor;
19
- return {
20
- sx: (aim.x - span / 2) * dpr,
21
- sy: (aim.y - span / 2) * dpr,
22
- sw: span * dpr,
23
- sh: span * dpr
24
- };
25
- }
26
- function sampleStack(layers, canvases, p, dpr) {
27
- for (let i = layers.length - 1; i >= 0; i--) {
28
- const layer = layers[i];
29
- if (!layer.visible) continue;
30
- const canvas = canvases.get(layer.id);
31
- if (!canvas) continue;
32
- const ctx = canvas.getContext("2d", { willReadFrequently: true });
33
- if (!ctx) continue;
34
- const x = Math.floor(p.x * dpr);
35
- const y = Math.floor(p.y * dpr);
36
- if (x < 0 || y < 0 || x >= canvas.width || y >= canvas.height) continue;
37
- const [r, g, b, a] = ctx.getImageData(x, y, 1, 1).data;
38
- if (a === 0) continue;
39
- return `#${[r, g, b].map((c) => c.toString(16).padStart(2, "0")).join("")}`;
40
- }
41
- return null;
42
- }
43
- function drawCanvasLens(ctx, opts) {
44
- const { aim, factor, diameter, dpr, mode, outer, layers, canvases } = opts;
45
- ctx.save();
46
- ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
47
- ctx.clearRect(0, 0, diameter, diameter);
48
- if (mode === "pixel") {
49
- const { sx, sy, sw, sh } = lensSourceRect(aim, factor, diameter, dpr);
50
- ctx.imageSmoothingEnabled = false;
51
- for (const layer of layers) {
52
- if (!layer.visible) continue;
53
- const canvas = canvases.get(layer.id);
54
- if (!canvas || canvas.width === 0 || canvas.height === 0) continue;
55
- ctx.drawImage(canvas, sx, sy, sw, sh, 0, 0, diameter, diameter);
56
- }
57
- ctx.restore();
58
- return;
59
- }
60
- const lens = lensCamera(
61
- aim,
62
- outer,
63
- opts.outerFrame ?? DEFAULT_FRAME,
64
- factor,
65
- diameter,
66
- opts.worldSpec
67
- );
68
- for (const layer of layers) {
69
- if (!layer.visible) continue;
70
- ctx.save();
71
- layer.render(ctx, lens.view, lens.frame);
72
- ctx.restore();
73
- }
74
- ctx.restore();
75
- }
76
- function CanvasLoupe({
77
- aim,
78
- factor,
79
- mode,
80
- diameter,
81
- surface,
82
- view,
83
- frame,
84
- worldSpec
85
- }) {
86
- const canvasRef = useRef(null);
87
- const dpr = surface.size.dpr;
88
- const args = { aim, factor, mode, diameter, dpr, view, frame, worldSpec, surface };
89
- const argsRef = useRef(args);
90
- argsRef.current = args;
91
- const loop = useVisibleRaf(
92
- () => {
93
- loop.request();
94
- const canvas = canvasRef.current;
95
- const ctx = canvas?.getContext("2d");
96
- const canvases = argsRef.current.surface.canvases.current;
97
- if (!ctx || !canvases) return;
98
- const a = argsRef.current;
99
- drawCanvasLens(ctx, {
100
- aim: a.aim,
101
- factor: a.factor,
102
- diameter: a.diameter,
103
- dpr: a.dpr,
104
- mode: a.mode,
105
- outer: a.view,
106
- outerFrame: a.frame,
107
- worldSpec: a.worldSpec,
108
- layers: a.surface.layers,
109
- canvases
110
- });
111
- },
112
- { target: canvasRef }
113
- );
114
- useEffect(() => {
115
- loop.request();
116
- return () => loop.cancel();
117
- }, [loop]);
118
- return /* @__PURE__ */ jsx(
119
- "canvas",
120
- {
121
- ref: canvasRef,
122
- className: "lk-loupe__canvas",
123
- width: Math.max(1, Math.round(diameter * dpr)),
124
- height: Math.max(1, Math.round(diameter * dpr))
125
- }
126
- );
127
- }
128
- function DomLoupe({
129
- aim,
130
- factor,
131
- mode,
132
- diameter,
133
- size,
134
- view,
135
- frame,
136
- state,
137
- config,
138
- render
139
- }) {
140
- const style = {
141
- width: `${size.width}px`,
142
- height: `${size.height}px`,
143
- transform: `translate(${diameter / 2 - aim.x}px, ${diameter / 2 - aim.y}px)`
144
- };
145
- return /* @__PURE__ */ jsx("div", { className: "lk-loupe__stage", style, children: render({
146
- state,
147
- config,
148
- view: zoomAt(view, factor, aim, { frame }),
149
- factor,
150
- mode,
151
- size
152
- }) });
153
- }
154
- function LoupeBubble({ aim, diameter, hostRef, children }) {
155
- const style = {
156
- width: `${diameter}px`,
157
- height: `${diameter}px`,
158
- transform: `translate(${aim.x - diameter / 2}px, ${aim.y - diameter / 2}px)`
159
- };
160
- return /* @__PURE__ */ jsx("div", { ref: hostRef, className: "lk-loupe", style, "aria-hidden": "true", children });
161
- }
162
-
163
- // src/loupe/loupeActions.ts
164
- var LOUPE_PEEK_ID = "loupe.peek";
165
- var LOUPE_MAGNIFY_ID = "loupe.magnify";
166
- var WHEEL_RATE = 2e-3;
167
- function createLoupeActions(input, peekKey) {
168
- const magnify = {
169
- id: LOUPE_MAGNIFY_ID,
170
- label: "Magnify (loupe)",
171
- group: "loupe",
172
- // Hotkey scope, so while the lens is up it outranks the trial camera's
173
- // wheel zoom on the same dispatcher; while it is down `enabled` declines
174
- // and the zoom runs.
175
- scope: "hotkey",
176
- // Every modifier optional: the lens claims the wheel whenever it is up,
177
- // which is what the hand-rolled capture-phase listener did. A bare spec
178
- // would forbid modifiers and hand Cmd+wheel back to the lab mid-peek.
179
- defaultBinding: [
180
- {
181
- spec: {
182
- kind: "wheel",
183
- mods: { alt: "optional", ctrl: "optional", meta: "optional", shift: "optional" }
184
- },
185
- opts: {}
186
- }
187
- ],
188
- enabled: () => input.shown() ? true : "not-applicable",
189
- invoker: {
190
- timing: "immediate",
191
- run(_deps, params) {
192
- input.magnifyBy(params?.deltaY ?? 0);
193
- }
194
- }
195
- };
196
- if (peekKey === null) return [magnify];
197
- const peek = {
198
- id: LOUPE_PEEK_ID,
199
- label: "Peek (loupe)",
200
- group: "loupe",
201
- // Hotkey scope: peeking must beat whatever the lab's active tool binds to
202
- // the same key, the way every other held-key trigger does.
203
- scope: "hotkey",
204
- // Every modifier optional because the peek key may BE one: the keydown
205
- // that carries `Alt` — the default — also reports `altKey: true`, and the
206
- // matcher forbids any modifier a spec does not name.
207
- defaultBinding: [
208
- {
209
- spec: {
210
- kind: "key-held",
211
- key: peekKey,
212
- mods: { alt: "optional", ctrl: "optional", meta: "optional", shift: "optional" }
213
- },
214
- opts: {}
215
- }
216
- ],
217
- invoker: {
218
- timing: "ongoing",
219
- start() {
220
- input.setPeeking(true);
221
- return { onEnd: () => input.setPeeking(false) };
222
- }
223
- }
224
- };
225
- return [peek, magnify];
226
- }
227
- var NO_TOOLS = /* @__PURE__ */ new Map();
228
- var CHANNELS = { pointer: false, contextMenu: false, ingest: false };
229
- function LoupeDispatch({
230
- hostRef,
231
- input,
232
- peekKey,
233
- registry,
234
- ownDispatcher
235
- }) {
236
- const actions = useMemo(() => createLoupeActions(input, peekKey), [input, peekKey]);
237
- useEffect(() => {
238
- const offs = actions.map((a) => registry.register(a));
239
- return () => {
240
- for (const off of offs) off();
241
- };
242
- }, [registry, actions]);
243
- useGestureDispatcher({
244
- canvasRef: hostRef,
245
- actions: registry,
246
- toolsById: NO_TOOLS,
247
- channels: CHANNELS,
248
- enabled: ownDispatcher
249
- });
250
- return null;
251
- }
252
- function LoupeGestures(props) {
253
- const registry = useActionsRegistry();
254
- const camera = useContext(CameraContext);
255
- if (!registry) return null;
256
- return /* @__PURE__ */ jsx(LoupeDispatch, { ...props, registry, ownDispatcher: camera === null });
257
- }
258
- var ZERO = { width: 0, height: 0 };
259
- function useHostSize(ref) {
260
- const [size, setSize] = useState(ZERO);
261
- useEffect(() => {
262
- const el = ref.current;
263
- if (!el) return;
264
- const update = () => {
265
- const rect = el.getBoundingClientRect();
266
- setSize(
267
- (prev) => prev.width === rect.width && prev.height === rect.height ? prev : { width: rect.width, height: rect.height }
268
- );
269
- };
270
- update();
271
- if (typeof ResizeObserver === "undefined") return;
272
- const ro = new ResizeObserver(update);
273
- ro.observe(el);
274
- return () => ro.disconnect();
275
- }, [ref]);
276
- return size;
277
- }
278
- function loupeSourcePoint(p, rect, aim, factor) {
279
- return {
280
- x: aim.x + (p.x - (rect.x + rect.w / 2)) / factor,
281
- y: aim.y + (p.y - (rect.y + rect.h / 2)) / factor
282
- };
283
- }
284
- function createLoupeModel(opts) {
285
- const { surface } = opts;
286
- let mode = opts.mode ?? "vector";
287
- let factor = normalizeZoom(opts.factor ?? 8);
288
- let aim = { x: 0, y: 0 };
289
- let color = null;
290
- let disposed = false;
291
- let aimUnsampled = false;
292
- const clamp = (n) => normalizeZoom(Math.min(
293
- opts.maxFactor ?? Number.POSITIVE_INFINITY,
294
- Math.max(opts.minFactor ?? Number.NEGATIVE_INFINITY, n)
295
- ));
296
- const sampleColor = () => {
297
- const hex = surface.sample(aim);
298
- if (hex === null || hex === color) return;
299
- color = hex;
300
- opts.onColorChange?.(hex);
301
- };
302
- const unsubscribeFrame = surface.subscribeFrame?.(() => {
303
- if (!aimUnsampled) return;
304
- aimUnsampled = false;
305
- sampleColor();
306
- });
307
- const teardown = () => {
308
- if (disposed) return;
309
- disposed = true;
310
- unsubscribeFrame?.();
311
- opts.onDispose?.();
312
- };
313
- return {
314
- get mode() {
315
- return mode;
316
- },
317
- get factor() {
318
- return factor;
319
- },
320
- get aim() {
321
- return aim;
322
- },
323
- get color() {
324
- return color;
325
- },
326
- setMode(next) {
327
- if (disposed || next === mode) return;
328
- mode = next;
329
- surface.changed();
330
- },
331
- setFactor(next) {
332
- if (disposed) return;
333
- factor = clamp(next);
334
- surface.changed();
335
- },
336
- aimAt(p) {
337
- if (disposed) return;
338
- if (surface.gone()) {
339
- teardown();
340
- return;
341
- }
342
- if (surface.hidden()) return;
343
- if (surface.covers(p)) return;
344
- aim = p;
345
- if (unsubscribeFrame) aimUnsampled = true;
346
- else sampleColor();
347
- surface.changed();
348
- },
349
- pick(p) {
350
- if (disposed) return null;
351
- let at = aim;
352
- if (p) {
353
- const rect = surface.lens();
354
- if (!rect) return null;
355
- at = loupeSourcePoint(p, rect, aim, factor);
356
- if (surface.covers(at)) return null;
357
- }
358
- const hex = surface.sample(at);
359
- if (hex !== null) opts.onPick?.(hex);
360
- return hex;
361
- },
362
- dispose: teardown
363
- };
364
- }
365
- function useLoupe({ capability, hostRef, enabled, sample }) {
366
- const [, bump] = useReducer((n) => n + 1, 0);
367
- const overRef = useRef(false);
368
- const peekingRef = useRef(false);
369
- const enabledRef = useRef(enabled);
370
- enabledRef.current = enabled;
371
- const sampleRef = useRef(sample);
372
- sampleRef.current = sample;
373
- const onColorChangeRef = useRef(capability.onColorChange);
374
- onColorChangeRef.current = capability.onColorChange;
375
- const shown = useCallback(
376
- () => overRef.current && (enabledRef.current || peekingRef.current),
377
- []
378
- );
379
- const modelRef = useRef(null);
380
- if (modelRef.current === null) {
381
- modelRef.current = createLoupeModel({
382
- mode: capability.mode,
383
- factor: capability.factor,
384
- minFactor: capability.minFactor,
385
- maxFactor: capability.maxFactor,
386
- onColorChange: (hex) => onColorChangeRef.current?.(hex),
387
- surface: {
388
- lens: () => {
389
- const d = diameterRef.current;
390
- const { x, y } = modelRef.current?.aim ?? { x: 0, y: 0 };
391
- return { x: x - d / 2, y: y - d / 2, w: d, h: d };
392
- },
393
- // The lens follows the pointer and is painted over the host rather than
394
- // into it, so it is never part of the picture being magnified.
395
- covers: () => false,
396
- sample: (p) => sampleRef.current?.(p) ?? null,
397
- hidden: () => !shown(),
398
- gone: () => goneRef.current,
399
- changed: bump
400
- }
401
- });
402
- }
403
- const model = modelRef.current;
404
- const diameterRef = useRef(capability.diameter);
405
- diameterRef.current = capability.diameter;
406
- const goneRef = useRef(false);
407
- useEffect(() => {
408
- goneRef.current = false;
409
- return () => {
410
- goneRef.current = true;
411
- };
412
- }, []);
413
- useEffect(() => {
414
- if (!enabled && !peekingRef.current) bump();
415
- }, [enabled]);
416
- useEffect(() => {
417
- const host = hostRef.current;
418
- if (!host) return;
419
- const onPointerMove = (e) => {
420
- overRef.current = true;
421
- const rect = host.getBoundingClientRect();
422
- model.aimAt({ x: e.clientX - rect.left, y: e.clientY - rect.top });
423
- if (!shown()) return;
424
- bump();
425
- };
426
- const onPointerLeave = () => {
427
- overRef.current = false;
428
- bump();
429
- };
430
- host.addEventListener("pointermove", onPointerMove);
431
- host.addEventListener("pointerleave", onPointerLeave);
432
- return () => {
433
- host.removeEventListener("pointermove", onPointerMove);
434
- host.removeEventListener("pointerleave", onPointerLeave);
435
- };
436
- }, [hostRef, model, shown]);
437
- const inputRef = useRef(null);
438
- if (inputRef.current === null) {
439
- inputRef.current = {
440
- shown,
441
- setPeeking: (on) => {
442
- if (peekingRef.current === on) return;
443
- peekingRef.current = on;
444
- bump();
445
- },
446
- magnifyBy: (deltaY) => {
447
- const m = modelRef.current;
448
- if (m) m.setFactor(m.factor * Math.exp(-deltaY * WHEEL_RATE));
449
- }
450
- };
451
- }
452
- return {
453
- visible: shown(),
454
- aim: model.aim,
455
- factor: model.factor,
456
- mode: model.mode,
457
- color: model.color,
458
- setMode: model.setMode,
459
- setFactor: model.setFactor,
460
- pick: model.pick,
461
- input: inputRef.current
462
- };
463
- }
464
- var NO_HOST = { current: null };
465
- function TrialLoupe({
466
- capability,
467
- enabled,
468
- state,
469
- config,
470
- view,
471
- worldSpec,
472
- hostRef
473
- }) {
474
- const stack = useContext(CanvasStackContext);
475
- const surface = capability.render ? void 0 : stack?.surface;
476
- const host = surface?.element ?? hostRef ?? NO_HOST;
477
- const sample = useMemo(() => {
478
- if (!surface) return void 0;
479
- return (p) => {
480
- const canvases = surface.canvases.current;
481
- return canvases ? sampleStack(surface.layers, canvases, p, surface.size.dpr) : null;
482
- };
483
- }, [surface]);
484
- const loupe = useLoupe({ capability, hostRef: host, enabled, sample });
485
- const measured = useHostSize(host);
486
- const size = surface?.size ?? measured;
487
- const gestures = /* @__PURE__ */ jsx(CameraScope, { children: /* @__PURE__ */ jsx(LoupeGestures, { hostRef: host, input: loupe.input, peekKey: capability.peekKey ?? null }) });
488
- if (!loupe.visible) return gestures;
489
- return /* @__PURE__ */ jsxs(Fragment, { children: [
490
- gestures,
491
- /* @__PURE__ */ jsx(LoupeBubble, { aim: loupe.aim, diameter: capability.diameter, children: capability.render ? /* @__PURE__ */ jsx(
492
- DomLoupe,
493
- {
494
- aim: loupe.aim,
495
- factor: loupe.factor,
496
- mode: loupe.mode,
497
- diameter: capability.diameter,
498
- size,
499
- view,
500
- frame: stack?.frame,
501
- state,
502
- config,
503
- render: capability.render
504
- }
505
- ) : surface && stack ? /* @__PURE__ */ jsx(
506
- CanvasLoupe,
507
- {
508
- aim: loupe.aim,
509
- factor: loupe.factor,
510
- mode: loupe.mode,
511
- diameter: capability.diameter,
512
- surface,
513
- view: stack.view,
514
- frame: stack.frame,
515
- worldSpec
516
- }
517
- ) : null })
518
- ] });
519
- }
520
-
521
- // src/loupe/types.ts
522
- var LOUPE_DEFAULTS = {
523
- factor: 6,
524
- minFactor: 2,
525
- maxFactor: 32,
526
- mode: "vector",
527
- diameter: 200,
528
- peekKey: "Alt"
529
- };
530
- function resolveLoupe(declared) {
531
- const cap = declared === true ? {} : declared;
532
- const minFactor = cap.minFactor ?? LOUPE_DEFAULTS.minFactor;
533
- const maxFactor = cap.maxFactor ?? LOUPE_DEFAULTS.maxFactor;
534
- return {
535
- render: cap.render,
536
- onColorChange: cap.onColorChange,
537
- minFactor,
538
- maxFactor,
539
- factor: Math.min(maxFactor, Math.max(minFactor, cap.factor ?? LOUPE_DEFAULTS.factor)),
540
- diameter: cap.diameter ?? LOUPE_DEFAULTS.diameter,
541
- peekKey: cap.peekKey === void 0 ? LOUPE_DEFAULTS.peekKey : cap.peekKey,
542
- // A DOM loupe has no framebuffer, so `pixel` would have nothing to enlarge.
543
- mode: cap.render ? "vector" : cap.mode ?? LOUPE_DEFAULTS.mode
544
- };
545
- }
546
-
547
- export { CanvasLoupe, DomLoupe, LOUPE_DEFAULTS, LOUPE_MAGNIFY_ID, LOUPE_PEEK_ID, LoupeBubble, LoupeGestures, TrialLoupe, createLoupeActions, drawCanvasLens, lensCamera, lensSourceRect, resolveLoupe, sampleStack, useLoupe };
548
- //# sourceMappingURL=chunk-S4NCI32V.js.map
549
- //# sourceMappingURL=chunk-S4NCI32V.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/loupe/canvasLens.ts","../src/loupe/CanvasLoupe.tsx","../src/loupe/DomLoupe.tsx","../src/loupe/LoupeBubble.tsx","../src/loupe/loupeActions.ts","../src/loupe/LoupeGestures.tsx","../src/loupe/useHostSize.ts","../../loupe/src/geometry.ts","../../loupe/src/model.ts","../src/loupe/useLoupe.ts","../src/loupe/TrialLoupe.tsx","../src/loupe/types.ts"],"names":["jsx","useEffect","useRef","useContext","useMemo"],"mappings":";;;;;;;;;;AAqBO,SAAS,WACd,GAAA,EACA,KAAA,EACA,UAAA,EACA,MAAA,EACA,UACA,SAAA,EACY;AACZ,EAAA,MAAM,IAAA,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AAe,UAAU,GAAA,CAAI,OAAA;AAAA;AAAA,IAElE,MAAM,GAAA,CAAI,MAAA,GAAS,QAAA,GAAY,GAAA,CAAI,QAAQ,cAAA,CAAe;AAAA,GAC5D;AACF","file":"chunk-S4NCI32V.js","sourcesContent":["import type { LoupePoint } from '@weasel-js/loupe';\nimport { centerOn } from '../canvas/camera';\nimport { screenToWorld } from '../canvas/canvasCoords';\nimport type { CanvasLayerDescriptor } from '../canvas/useLayerScheduler';\nimport { DEFAULT_FRAME, resolveFrame, type WorldFrame, type WorldSpec } from '../canvas/worldSpec';\nimport type { ViewTransform } from '../instrument/types';\n\n/** The camera a round lens of `diameter` shows a magnified region through, and\n * the coordinate system it is read in — the instrument's own `WorldSpec`,\n * resolved against the lens rather than the stack. */\nexport interface LensCamera {\n view: ViewTransform;\n frame: WorldFrame;\n}\n\n/**\n * What a lens aimed at `aim` renders the stack's layers through.\n *\n * The lens is its own viewport, so the world spec resolves against its box: an\n * instrument centred on its viewport is centred in the lens too.\n */\nexport function lensCamera(\n aim: LoupePoint,\n outer: ViewTransform,\n outerFrame: WorldFrame,\n factor: number,\n diameter: number,\n worldSpec?: WorldSpec,\n): LensCamera {\n const size = { width: diameter, height: diameter };\n const frame = resolveFrame(worldSpec, size);\n const world = screenToWorld(aim, outer, outerFrame);\n return { view: centerOn(world, outer.zoom * factor, size, frame), frame };\n}\n\n/** A rectangle in a backing store's own device pixels. */\nexport interface SourceRect {\n sx: number;\n sy: number;\n sw: number;\n sh: number;\n}\n\n/**\n * The region a pixel-mode lens copies out of a presented canvas: the `diameter\n * / factor` CSS px around `aim`, in that canvas' backing-store pixels.\n */\nexport function lensSourceRect(\n aim: LoupePoint,\n factor: number,\n diameter: number,\n dpr: number,\n): SourceRect {\n const span = diameter / factor;\n return {\n sx: (aim.x - span / 2) * dpr,\n sy: (aim.y - span / 2) * dpr,\n sw: span * dpr,\n sh: span * dpr,\n };\n}\n\n/**\n * The color a stack presents at a point: the topmost visible layer with\n * anything opaque there, or `null` when every layer is transparent — which is\n * the honest answer for a point showing nothing but the workspace behind.\n */\nexport function sampleStack(\n layers: readonly CanvasLayerDescriptor[],\n canvases: Map<string, HTMLCanvasElement>,\n p: LoupePoint,\n dpr: number,\n): string | null {\n for (let i = layers.length - 1; i >= 0; i--) {\n const layer = layers[i];\n if (!layer.visible) continue;\n const canvas = canvases.get(layer.id);\n if (!canvas) continue;\n const ctx = canvas.getContext('2d', { willReadFrequently: true });\n if (!ctx) continue;\n const x = Math.floor(p.x * dpr);\n const y = Math.floor(p.y * dpr);\n if (x < 0 || y < 0 || x >= canvas.width || y >= canvas.height) continue;\n const [r, g, b, a] = ctx.getImageData(x, y, 1, 1).data;\n if (a === 0) continue;\n return `#${[r, g, b].map((c) => c.toString(16).padStart(2, '0')).join('')}`;\n }\n return null;\n}\n\n/** Redraw the stack into a lens' own canvas. `mode` decides whether the layers\n * are re-run at the lens camera or their presented pixels are enlarged. */\nexport function drawCanvasLens(\n ctx: CanvasRenderingContext2D,\n opts: {\n aim: LoupePoint;\n factor: number;\n diameter: number;\n dpr: number;\n mode: 'vector' | 'pixel';\n outer: ViewTransform;\n outerFrame?: WorldFrame;\n worldSpec?: WorldSpec;\n layers: readonly CanvasLayerDescriptor[];\n canvases: Map<string, HTMLCanvasElement>;\n },\n): void {\n const { aim, factor, diameter, dpr, mode, outer, layers, canvases } = opts;\n ctx.save();\n ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n ctx.clearRect(0, 0, diameter, diameter);\n\n if (mode === 'pixel') {\n const { sx, sy, sw, sh } = lensSourceRect(aim, factor, diameter, dpr);\n ctx.imageSmoothingEnabled = false;\n for (const layer of layers) {\n if (!layer.visible) continue;\n const canvas = canvases.get(layer.id);\n if (!canvas || canvas.width === 0 || canvas.height === 0) continue;\n ctx.drawImage(canvas, sx, sy, sw, sh, 0, 0, diameter, diameter);\n }\n ctx.restore();\n return;\n }\n\n const lens = lensCamera(\n aim,\n outer,\n opts.outerFrame ?? DEFAULT_FRAME,\n factor,\n diameter,\n opts.worldSpec,\n );\n for (const layer of layers) {\n if (!layer.visible) continue;\n ctx.save();\n layer.render(ctx, lens.view, lens.frame);\n ctx.restore();\n }\n ctx.restore();\n}\n","import { useVisibleRaf } from '@weasel-js/core';\nimport type { LoupeMode, LoupePoint } from '@weasel-js/loupe';\nimport { useEffect, useRef } from 'react';\nimport type { CanvasStackSurface } from '../canvas/CanvasStackContext';\nimport type { WorldFrame, WorldSpec } from '../canvas/worldSpec';\nimport type { ViewTransform } from '../instrument/types';\nimport { drawCanvasLens } from './canvasLens';\n\n/** Props for `<CanvasLoupe>`. */\nexport interface CanvasLoupeProps {\n aim: LoupePoint;\n factor: number;\n mode: LoupeMode;\n diameter: number;\n /** The stack being magnified: its layers, its pixels, and its measured box. */\n surface: CanvasStackSurface;\n view: ViewTransform;\n frame: WorldFrame;\n worldSpec?: WorldSpec;\n}\n\n/**\n * Paints a lens over a `<CanvasStack>` by re-drawing the stack's layers through\n * a zoomed camera — so the magnified content is as sharp as the original, at\n * any factor. `pixel` mode enlarges what the stack presented instead.\n */\nexport function CanvasLoupe({\n aim,\n factor,\n mode,\n diameter,\n surface,\n view,\n frame,\n worldSpec,\n}: CanvasLoupeProps) {\n const canvasRef = useRef<HTMLCanvasElement | null>(null);\n const dpr = surface.size.dpr;\n\n // Whatever the stack redraws every frame, the lens has to redraw too — an\n // instrument that animates from its own loop never re-renders this component.\n const args = { aim, factor, mode, diameter, dpr, view, frame, worldSpec, surface };\n const argsRef = useRef(args);\n argsRef.current = args;\n\n const loop = useVisibleRaf(\n () => {\n loop.request();\n const canvas = canvasRef.current;\n const ctx = canvas?.getContext('2d');\n const canvases = argsRef.current.surface.canvases.current;\n if (!ctx || !canvases) return;\n const a = argsRef.current;\n drawCanvasLens(ctx, {\n aim: a.aim,\n factor: a.factor,\n diameter: a.diameter,\n dpr: a.dpr,\n mode: a.mode,\n outer: a.view,\n outerFrame: a.frame,\n worldSpec: a.worldSpec,\n layers: a.surface.layers,\n canvases,\n });\n },\n { target: canvasRef },\n );\n\n useEffect(() => {\n loop.request();\n return () => loop.cancel();\n }, [loop]);\n\n return (\n <canvas\n ref={canvasRef}\n className=\"lk-loupe__canvas\"\n width={Math.max(1, Math.round(diameter * dpr))}\n height={Math.max(1, Math.round(diameter * dpr))}\n />\n );\n}\n","import type { LoupeMode, LoupePoint } from '@weasel-js/loupe';\nimport type { CSSProperties } from 'react';\nimport { zoomAt } from '../canvas/camera';\nimport type { ViewportSize, WorldFrame } from '../canvas/worldSpec';\nimport type { ViewTransform } from '../instrument/types';\nimport type { LoupeRenderArgs } from './types';\n\n/** Props for `<DomLoupe>`. */\nexport interface DomLoupeProps {\n aim: LoupePoint;\n factor: number;\n mode: LoupeMode;\n diameter: number;\n /** The host the instrument draws into, which the stage reproduces. */\n size: ViewportSize;\n /** The trial's own camera. */\n view: ViewTransform;\n frame?: WorldFrame;\n state: unknown;\n config: unknown;\n render: (args: LoupeRenderArgs) => React.ReactNode;\n}\n\n/**\n * Paints a lens over DOM content by asking the instrument to draw itself again\n * at a magnified camera.\n *\n * The stage is a full copy of the host, so the instrument's own layout still\n * holds; the camera is composed about the aimed point, which keeps that point\n * where it already was, and the stage is then slid by `diameter / 2 - aim` to\n * bring it to the middle of the lens.\n */\nexport function DomLoupe({\n aim,\n factor,\n mode,\n diameter,\n size,\n view,\n frame,\n state,\n config,\n render,\n}: DomLoupeProps) {\n const style: CSSProperties = {\n width: `${size.width}px`,\n height: `${size.height}px`,\n transform: `translate(${diameter / 2 - aim.x}px, ${diameter / 2 - aim.y}px)`,\n };\n return (\n <div className=\"lk-loupe__stage\" style={style}>\n {render({\n state,\n config,\n view: zoomAt(view, factor, aim, { frame }),\n factor,\n mode,\n size,\n })}\n </div>\n );\n}\n","import type { LoupePoint } from '@weasel-js/loupe';\nimport type { CSSProperties, ReactNode, RefObject } from 'react';\n\n/** Props for `<LoupeBubble>`. */\nexport interface LoupeBubbleProps {\n /** Where the lens is aimed, in its container's own pixels. */\n aim: LoupePoint;\n diameter: number;\n hostRef?: RefObject<HTMLDivElement | null>;\n children: ReactNode;\n}\n\n/**\n * The lens itself: a circle centred on the aimed point, clipping whatever a\n * painter draws into it.\n *\n * It takes no pointer events, so the pan, the wheel and anything underneath\n * keep working while it is up — and it is `aria-hidden`, since it magnifies\n * content already on the page rather than adding any.\n */\nexport function LoupeBubble({ aim, diameter, hostRef, children }: LoupeBubbleProps) {\n const style: CSSProperties = {\n width: `${diameter}px`,\n height: `${diameter}px`,\n transform: `translate(${aim.x - diameter / 2}px, ${aim.y - diameter / 2}px)`,\n };\n return (\n <div ref={hostRef} className=\"lk-loupe\" style={style} aria-hidden=\"true\">\n {children}\n </div>\n );\n}\n","/**\n * The loupe's two bindable interactions, as `Action` descriptors the gesture\n * dispatcher routes: hold a key to peek, and walk the magnification with the\n * wheel.\n *\n * Free of React so the routing can be tested without a DOM.\n */\nimport type { Action } from '@weasel-js/core';\n\n/** Canonical id of the hold-to-peek action. */\nexport const LOUPE_PEEK_ID = 'loupe.peek';\n/** Canonical id of the wheel-magnify action. */\nexport const LOUPE_MAGNIFY_ID = 'loupe.magnify';\n\n/** How fast the wheel walks the magnification. Gentler than the pan-zoom\n * wheel: the lens' whole range is one order of magnitude. */\nexport const WHEEL_RATE = 0.002;\n\n/** What the actions do to a live loupe. Every member is read through the\n * object on each invocation, so one stable instance serves the life of the\n * registration. */\nexport interface LoupeInputApi {\n /** Whether the lens is up. The wheel belongs to the loupe only while it is;\n * otherwise `loupe.magnify` declines and the dispatcher falls through to\n * the trial camera's zoom. */\n shown: () => boolean;\n /** Raise or drop the hold-to-peek flag. */\n setPeeking: (on: boolean) => void;\n /** Multiply the magnification by one wheel notch of `deltaY`. */\n magnifyBy: (deltaY: number) => void;\n}\n\n/**\n * Build the loupe's actions. `peekKey` is a `KeyboardEvent.key`; passing\n * `null` omits `loupe.peek` entirely rather than registering a binding no key\n * can match.\n */\nexport function createLoupeActions(\n input: LoupeInputApi,\n peekKey: string | null,\n): readonly Action[] {\n const magnify: Action = {\n id: LOUPE_MAGNIFY_ID,\n label: 'Magnify (loupe)',\n group: 'loupe',\n // Hotkey scope, so while the lens is up it outranks the trial camera's\n // wheel zoom on the same dispatcher; while it is down `enabled` declines\n // and the zoom runs.\n scope: 'hotkey',\n // Every modifier optional: the lens claims the wheel whenever it is up,\n // which is what the hand-rolled capture-phase listener did. A bare spec\n // would forbid modifiers and hand Cmd+wheel back to the lab mid-peek.\n defaultBinding: [\n {\n spec: {\n kind: 'wheel',\n mods: { alt: 'optional', ctrl: 'optional', meta: 'optional', shift: 'optional' },\n },\n opts: {},\n },\n ],\n enabled: () => (input.shown() ? true : 'not-applicable'),\n invoker: {\n timing: 'immediate',\n run(_deps, params) {\n input.magnifyBy((params?.deltaY as number | undefined) ?? 0);\n },\n },\n };\n\n if (peekKey === null) return [magnify];\n\n const peek: Action = {\n id: LOUPE_PEEK_ID,\n label: 'Peek (loupe)',\n group: 'loupe',\n // Hotkey scope: peeking must beat whatever the lab's active tool binds to\n // the same key, the way every other held-key trigger does.\n scope: 'hotkey',\n // Every modifier optional because the peek key may BE one: the keydown\n // that carries `Alt` — the default — also reports `altKey: true`, and the\n // matcher forbids any modifier a spec does not name.\n defaultBinding: [\n {\n spec: {\n kind: 'key-held',\n key: peekKey,\n mods: { alt: 'optional', ctrl: 'optional', meta: 'optional', shift: 'optional' },\n },\n opts: {},\n },\n ],\n invoker: {\n timing: 'ongoing',\n start() {\n input.setPeeking(true);\n return { onEnd: () => input.setPeeking(false) };\n },\n },\n };\n return [peek, magnify];\n}\n","/**\n * Registers the loupe's actions, and mounts the gesture dispatcher on the\n * loupe's host when no camera already has one there, so the peek key and the\n * wheel route the way every other weasel binding does.\n *\n * Three of the dispatcher's four element channels are off. Only `wheel` is\n * wanted here; `contextMenu` suppresses the native menu unconditionally and\n * `ingest` makes the host a file-drop target, neither of which a lab asked\n * for by turning a magnifier on.\n */\nimport {\n type ActionsRegistry,\n type Tool,\n useActionsRegistry,\n useGestureDispatcher,\n} from '@weasel-js/core';\nimport { type RefObject, useContext, useEffect, useMemo } from 'react';\nimport { CameraContext } from '../canvas/CameraInput';\nimport { createLoupeActions, type LoupeInputApi } from './loupeActions';\n\n/** Props for `<LoupeGestures>`. */\nexport interface LoupeGesturesProps {\n /** The element the dispatcher listens on — the same one the lens tracks. */\n hostRef: RefObject<HTMLElement | null>;\n input: LoupeInputApi;\n /** `KeyboardEvent.key` for hold-to-peek, or `null` for no peek binding. */\n peekKey: string | null;\n}\n\nconst NO_TOOLS: ReadonlyMap<string, Tool> = new Map();\n\nconst CHANNELS = { pointer: false, contextMenu: false, ingest: false } as const;\n\nfunction LoupeDispatch({\n hostRef,\n input,\n peekKey,\n registry,\n ownDispatcher,\n}: LoupeGesturesProps & { registry: ActionsRegistry; ownDispatcher: boolean }) {\n const actions = useMemo(() => createLoupeActions(input, peekKey), [input, peekKey]);\n\n useEffect(() => {\n const offs = actions.map((a) => registry.register(a));\n return () => {\n for (const off of offs) off();\n };\n }, [registry, actions]);\n\n useGestureDispatcher({\n canvasRef: hostRef,\n actions: registry,\n toolsById: NO_TOOLS,\n channels: CHANNELS,\n enabled: ownDispatcher,\n });\n\n return null;\n}\n\n/**\n * The loupe's input, routed. Inside a camera (`<CanvasStack>`, `<Stage>`) its\n * actions join the camera's dispatcher, which already listens on the host;\n * elsewhere it mounts a dispatcher of its own. With no registry in scope it\n * renders nothing rather than registering actions that could never fire.\n */\nexport function LoupeGestures(props: LoupeGesturesProps) {\n const registry = useActionsRegistry();\n const camera = useContext(CameraContext);\n if (!registry) return null;\n return <LoupeDispatch {...props} registry={registry} ownDispatcher={camera === null} />;\n}\n","import { type RefObject, useEffect, useState } from 'react';\nimport type { ViewportSize } from '../canvas/worldSpec';\n\nconst ZERO: ViewportSize = { width: 0, height: 0 };\n\n/** An element's CSS-pixel box, kept current. `{0, 0}` until it is measured, and\n * wherever `ResizeObserver` is absent. */\nexport function useHostSize(ref: RefObject<HTMLElement | null>): ViewportSize {\n const [size, setSize] = useState<ViewportSize>(ZERO);\n\n useEffect(() => {\n const el = ref.current;\n if (!el) return;\n const update = (): void => {\n const rect = el.getBoundingClientRect();\n setSize((prev) =>\n prev.width === rect.width && prev.height === rect.height\n ? prev\n : { width: rect.width, height: rect.height },\n );\n };\n update();\n if (typeof ResizeObserver === 'undefined') return;\n const ro = new ResizeObserver(update);\n ro.observe(el);\n return () => ro.disconnect();\n }, [ref]);\n\n return size;\n}\n","import type { View } from '@weasel-js/core';\n\n/** A point on the magnified surface, in its own CSS pixels. */\nexport interface LoupePoint {\n x: number;\n y: number;\n}\n\n/** The lens' rectangle on that surface. */\nexport interface LoupeRect extends LoupePoint {\n w: number;\n h: number;\n}\n\n/**\n * The inner `View` a loupe renders its content through: the outer view's\n * magnification times `factor`, positioned so `target` sits at the center of\n * a viewport the size of `rect`.\n */\nexport function loupeInnerView(\n target: LoupePoint,\n outer: View,\n rect: LoupeRect,\n factor: number,\n): View {\n const scale = { x: outer.scale.x * factor, y: outer.scale.y * factor };\n return {\n x: target.x - rect.w / 2 / scale.x,\n y: target.y - rect.h / 2 / scale.y,\n scale,\n };\n}\n\n/**\n * Where on the outer surface a point inside the lens is looking, in\n * screen-space CSS px.\n *\n * The inverse of {@link loupeInnerView}: the lens centers `aim` in `rect` and\n * magnifies by `factor`, and the outer view's own scale cancels out of the\n * round trip — so this needs no `View`.\n */\nexport function loupeSourcePoint(\n p: LoupePoint,\n rect: LoupeRect,\n aim: LoupePoint,\n factor: number,\n): LoupePoint {\n return {\n x: aim.x + (p.x - (rect.x + rect.w / 2)) / factor,\n y: aim.y + (p.y - (rect.y + rect.h / 2)) / factor,\n };\n}\n","import { normalizeZoom } from '@weasel-js/core';\nimport { type LoupePoint, type LoupeRect, loupeSourcePoint } from './geometry';\n\n/** How a loupe magnifies. `'vector'` re-renders the source through a zoomed-in\n * view, so content stays sharp at any factor; `'pixel'` blows up the actual\n * pixels the surface presented. */\nexport type LoupeMode = 'vector' | 'pixel';\n\n/**\n * What a loupe needs from the surface it magnifies. A painter implements it,\n * and the model asks nothing about how the lens is drawn — only where it is,\n * what colour is under a point, and whether anyone can still see it.\n */\nexport interface LoupeSurface {\n /** The lens' rectangle, or `null` while it has none. */\n lens(): LoupeRect | null;\n /**\n * Does the lens itself cover this point? A stationary lens does over its own\n * frame, which is what the freeze rule below is for; a lens that follows the\n * pointer never covers it and answers `false`.\n */\n covers(p: LoupePoint): boolean;\n /** Hex colour at a surface point, or `null` when the surface cannot say. */\n sample(p: LoupePoint): string | null;\n /** Is the lens off screen? Aims are ignored while it is. */\n hidden(): boolean;\n /** Is the lens gone for good? The model tears itself down when it is. */\n gone(): boolean;\n /** Something the painter must redraw for has changed. */\n changed(): void;\n /**\n * Run `fn` after each frame the surface lands; returns an unsubscribe.\n * Implement it when `sample` reads pixels that only show an aim once a\n * frame has painted — a framebuffer read back. The model then samples the\n * aim on the next landed frame, so `color` settles a frame after the aim.\n * Omit it when `sample` can answer for a fresh aim right away.\n */\n subscribeFrame?(fn: () => void): () => void;\n}\n\n/** Options for {@link createLoupeModel}. */\nexport interface LoupeModelOptions {\n surface: LoupeSurface;\n mode?: LoupeMode;\n /** Magnification. Default 8. Always positive and finite: a factor that is\n * not becomes `ZOOM_FLOOR`, the same rule a view's zoom follows. */\n factor?: number;\n /** Bounds `setFactor` clamps to. Unset means bounded only by that rule. */\n minFactor?: number;\n maxFactor?: number;\n /** Called with the hex colour under the aim point whenever it changes. */\n onColorChange?: (hex: string) => void;\n /** Called when a pick lands — an eyedropper on the magnified surface. Where\n * the colour goes is the consumer's business. */\n onPick?: (hex: string) => void;\n /** Called when the model tears itself down because the surface reported the\n * lens gone, so the painter can drop what it was holding. */\n onDispose?: () => void;\n}\n\n/** Where a loupe is aimed, how far it magnifies, and what colour it is over. */\nexport interface LoupeModel {\n readonly mode: LoupeMode;\n readonly factor: number;\n /** Last aimed point, in the surface's CSS px. */\n readonly aim: LoupePoint;\n /** Hex colour under the aim point. `null` until something answers. */\n readonly color: string | null;\n setMode(mode: LoupeMode): void;\n setFactor(factor: number): void;\n /** Aim at a surface point. Ignored while the lens covers it, is hidden, or\n * the model is disposed. */\n aimAt(p: LoupePoint): void;\n /** Sample what the lens shows at `p`, a point inside it, and report that to\n * `onPick`. Omit `p` to pick at the aim point. Leaves the aim, and `color`,\n * alone. */\n pick(p?: LoupePoint): string | null;\n dispose(): void;\n}\n\n/**\n * Build the loupe's model over a surface. It holds the state a magnifier has —\n * aim, factor, mode, colour — and none of the drawing.\n */\nexport function createLoupeModel(opts: LoupeModelOptions): LoupeModel {\n const { surface } = opts;\n let mode: LoupeMode = opts.mode ?? 'vector';\n let factor = normalizeZoom(opts.factor ?? 8);\n let aim: LoupePoint = { x: 0, y: 0 };\n let color: string | null = null;\n let disposed = false;\n let aimUnsampled = false;\n\n const clamp = (n: number): number =>\n normalizeZoom(Math.min(opts.maxFactor ?? Number.POSITIVE_INFINITY,\n Math.max(opts.minFactor ?? Number.NEGATIVE_INFINITY, n)));\n\n const sampleColor = () => {\n const hex = surface.sample(aim);\n if (hex === null || hex === color) return;\n color = hex;\n opts.onColorChange?.(hex);\n };\n\n const unsubscribeFrame = surface.subscribeFrame?.(() => {\n if (!aimUnsampled) return;\n aimUnsampled = false;\n sampleColor();\n });\n\n const teardown = () => {\n if (disposed) return;\n disposed = true;\n unsubscribeFrame?.();\n opts.onDispose?.();\n };\n\n return {\n get mode() { return mode; },\n get factor() { return factor; },\n get aim() { return aim; },\n get color() { return color; },\n\n setMode(next) {\n if (disposed || next === mode) return;\n mode = next;\n surface.changed();\n },\n\n setFactor(next) {\n if (disposed) return;\n factor = clamp(next);\n surface.changed();\n },\n\n aimAt(p) {\n if (disposed) return;\n // A lens can be taken away by whatever owns it, without coming back\n // through `dispose`. Follow it down rather than keep sampling for a\n // magnifier nobody can see.\n if (surface.gone()) { teardown(); return; }\n if (surface.hidden()) return;\n if (surface.covers(p)) return;\n aim = p;\n if (unsubscribeFrame) aimUnsampled = true;\n else sampleColor();\n surface.changed();\n },\n\n pick(p) {\n if (disposed) return null;\n let at = aim;\n if (p) {\n const rect = surface.lens();\n if (!rect) return null;\n at = loupeSourcePoint(p, rect, aim, factor);\n // The lens is part of the picture the surface presents. A point near\n // its frame maps back underneath it, and sampling there reports the\n // lens' own chrome as artwork.\n if (surface.covers(at)) return null;\n }\n const hex = surface.sample(at);\n if (hex !== null) opts.onPick?.(hex);\n return hex;\n },\n\n dispose: teardown,\n };\n}\n","import {\n createLoupeModel,\n type LoupeMode,\n type LoupeModel,\n type LoupePoint,\n} from '@weasel-js/loupe';\nimport { type RefObject, useCallback, useEffect, useReducer, useRef } from 'react';\nimport type { LoupeInputApi } from './loupeActions';\nimport { WHEEL_RATE } from './loupeActions';\nimport type { ResolvedLoupe } from './types';\n\n/** Options for {@link useLoupe}. */\nexport interface UseLoupeOptions {\n capability: ResolvedLoupe;\n /** The element the lens tracks the pointer across. */\n hostRef: RefObject<HTMLElement | null>;\n /** Whether the loupe is turned on. Hold-to-peek shows it regardless. */\n enabled: boolean;\n /** Hex color at a host point. Omitted, the loupe reports no color — which\n * is the honest answer for a surface with no pixels to read. */\n sample?: (p: LoupePoint) => string | null;\n}\n\n/** A loupe as a React view reads it. */\nexport interface LoupeState {\n /** Whether the lens should be drawn. */\n visible: boolean;\n /** Where it is aimed, in the host's own pixels. */\n aim: LoupePoint;\n factor: number;\n mode: LoupeMode;\n color: string | null;\n setMode: (mode: LoupeMode) => void;\n setFactor: (factor: number) => void;\n /** Sample what the lens shows at a point inside it. */\n pick: (p?: LoupePoint) => string | null;\n /** What `<LoupeGestures>` drives the lens through. Stable for the life of\n * the hook, so registering the actions on it does not churn. */\n input: LoupeInputApi;\n}\n\n/**\n * Binds `@weasel-js/loupe`'s model to a host element and tracks the pointer\n * across it.\n *\n * The peek key and the wheel are not here: they are `loupe.peek` and\n * `loupe.magnify`, routed through the gesture dispatcher that\n * `<LoupeGestures>` mounts on the same host. Aiming stays a plain listener\n * because a hover is not a gesture the grammar names — `GESTURE_DESCRIPTORS`\n * has no continuous-motion entry, and inventing one to carry the lens' aim\n * would be an input taxonomy change, not a loupe change.\n */\nexport function useLoupe({ capability, hostRef, enabled, sample }: UseLoupeOptions): LoupeState {\n const [, bump] = useReducer((n: number) => n + 1, 0);\n\n const overRef = useRef(false);\n const peekingRef = useRef(false);\n const enabledRef = useRef(enabled);\n enabledRef.current = enabled;\n const sampleRef = useRef(sample);\n sampleRef.current = sample;\n const onColorChangeRef = useRef(capability.onColorChange);\n onColorChangeRef.current = capability.onColorChange;\n\n // Reads nothing but refs, so it is stable and an effect may depend on it.\n const shown = useCallback(\n (): boolean => overRef.current && (enabledRef.current || peekingRef.current),\n [],\n );\n\n const modelRef = useRef<LoupeModel | null>(null);\n if (modelRef.current === null) {\n modelRef.current = createLoupeModel({\n mode: capability.mode,\n factor: capability.factor,\n minFactor: capability.minFactor,\n maxFactor: capability.maxFactor,\n onColorChange: (hex) => onColorChangeRef.current?.(hex),\n surface: {\n lens: () => {\n const d = diameterRef.current;\n const { x, y } = modelRef.current?.aim ?? { x: 0, y: 0 };\n return { x: x - d / 2, y: y - d / 2, w: d, h: d };\n },\n // The lens follows the pointer and is painted over the host rather than\n // into it, so it is never part of the picture being magnified.\n covers: () => false,\n sample: (p) => sampleRef.current?.(p) ?? null,\n hidden: () => !shown(),\n gone: () => goneRef.current,\n changed: bump,\n },\n });\n }\n const model = modelRef.current;\n\n const diameterRef = useRef(capability.diameter);\n diameterRef.current = capability.diameter;\n const goneRef = useRef(false);\n\n // The model holds no resources, and `dispose` is one-way — so unmounting only\n // reports the lens gone. Disposing here instead leaves React's mount / unmount\n // / remount in StrictMode with a permanently dead model that silently ignores\n // every aim.\n useEffect(() => {\n goneRef.current = false;\n return () => {\n goneRef.current = true;\n };\n }, []);\n\n // Turning the loupe off with the pointer still inside must put the lens away,\n // and the model only reconsiders on an aim.\n useEffect(() => {\n if (!enabled && !peekingRef.current) bump();\n }, [enabled]);\n\n useEffect(() => {\n const host = hostRef.current;\n if (!host) return;\n\n const onPointerMove = (e: PointerEvent): void => {\n overRef.current = true;\n const rect = host.getBoundingClientRect();\n model.aimAt({ x: e.clientX - rect.left, y: e.clientY - rect.top });\n if (!shown()) return;\n bump();\n };\n const onPointerLeave = (): void => {\n overRef.current = false;\n bump();\n };\n\n host.addEventListener('pointermove', onPointerMove);\n host.addEventListener('pointerleave', onPointerLeave);\n return () => {\n host.removeEventListener('pointermove', onPointerMove);\n host.removeEventListener('pointerleave', onPointerLeave);\n };\n }, [hostRef, model, shown]);\n\n const inputRef = useRef<LoupeInputApi | null>(null);\n if (inputRef.current === null) {\n inputRef.current = {\n shown,\n setPeeking: (on) => {\n if (peekingRef.current === on) return;\n peekingRef.current = on;\n bump();\n },\n magnifyBy: (deltaY) => {\n const m = modelRef.current;\n if (m) m.setFactor(m.factor * Math.exp(-deltaY * WHEEL_RATE));\n },\n };\n }\n\n return {\n visible: shown(),\n aim: model.aim,\n factor: model.factor,\n mode: model.mode,\n color: model.color,\n setMode: model.setMode,\n setFactor: model.setFactor,\n pick: model.pick,\n input: inputRef.current,\n };\n}\n","import { type RefObject, useContext, useMemo } from 'react';\nimport { CameraScope } from '../canvas/CameraInput';\nimport { CanvasStackContext } from '../canvas/CanvasStackContext';\nimport type { WorldSpec } from '../canvas/worldSpec';\nimport type { ViewTransform } from '../instrument/types';\nimport { CanvasLoupe } from './CanvasLoupe';\nimport { sampleStack } from './canvasLens';\nimport { DomLoupe } from './DomLoupe';\nimport { LoupeBubble } from './LoupeBubble';\nimport { LoupeGestures } from './LoupeGestures';\nimport type { ResolvedLoupe } from './types';\nimport { useHostSize } from './useHostSize';\nimport { useLoupe } from './useLoupe';\n\n/** Props for `<TrialLoupe>`. */\nexport interface TrialLoupeProps {\n capability: ResolvedLoupe;\n /** Whether the trial's loupe is turned on. Hold-to-peek shows it anyway. */\n enabled: boolean;\n state: unknown;\n config: unknown;\n /** The trial's own camera. */\n view: ViewTransform;\n worldSpec?: WorldSpec;\n /** The element the lens tracks. A loupe mounted inside a `<CanvasStack>`\n * takes the stack's own element instead, and this goes unused. */\n hostRef?: RefObject<HTMLElement | null>;\n}\n\n/** Stable stand-in, so a loupe with nothing to track does not re-bind its\n * listeners on every render. */\nconst NO_HOST: RefObject<HTMLElement | null> = { current: null };\n\n/**\n * A trial's loupe, painted by whichever painter suits its content: the canvas\n * stack it is mounted inside, or the instrument's own `render` at a magnified\n * camera.\n */\nexport function TrialLoupe({\n capability,\n enabled,\n state,\n config,\n view,\n worldSpec,\n hostRef,\n}: TrialLoupeProps) {\n const stack = useContext(CanvasStackContext);\n const surface = capability.render ? undefined : stack?.surface;\n const host = surface?.element ?? hostRef ?? NO_HOST;\n\n const sample = useMemo(() => {\n if (!surface) return undefined;\n return (p: { x: number; y: number }): string | null => {\n const canvases = surface.canvases.current;\n return canvases ? sampleStack(surface.layers, canvases, p, surface.size.dpr) : null;\n };\n }, [surface]);\n\n const loupe = useLoupe({ capability, hostRef: host, enabled, sample });\n const measured = useHostSize(host);\n const size = surface?.size ?? measured;\n\n // The gestures mount outside the visibility gate: hold-to-peek is what\n // raises a lens that is down, so its binding has to be live while it is.\n // In a trial they join the trial's scope, and with it the camera's\n // dispatcher; outside one, `<CameraScope>` gives them an isolated scope.\n const gestures = (\n <CameraScope>\n <LoupeGestures hostRef={host} input={loupe.input} peekKey={capability.peekKey ?? null} />\n </CameraScope>\n );\n\n if (!loupe.visible) return gestures;\n\n return (\n <>\n {gestures}\n <LoupeBubble aim={loupe.aim} diameter={capability.diameter}>\n {capability.render ? (\n <DomLoupe\n aim={loupe.aim}\n factor={loupe.factor}\n mode={loupe.mode}\n diameter={capability.diameter}\n size={size}\n view={view}\n frame={stack?.frame}\n state={state}\n config={config}\n render={capability.render}\n />\n ) : surface && stack ? (\n <CanvasLoupe\n aim={loupe.aim}\n factor={loupe.factor}\n mode={loupe.mode}\n diameter={capability.diameter}\n surface={surface}\n view={stack.view}\n frame={stack.frame}\n worldSpec={worldSpec}\n />\n ) : null}\n </LoupeBubble>\n </>\n );\n}\n","import type { LoupeMode } from '@weasel-js/loupe';\nimport type { ReactNode } from 'react';\nimport type { ViewportSize } from '../canvas/worldSpec';\nimport type { ViewTransform } from '../instrument/types';\n\n/** What a DOM instrument's loupe `render` is handed: the same data its own\n * `render` gets, and the camera to draw it through. */\nexport interface LoupeRenderArgs<TS = unknown, TC = unknown> {\n state: TS;\n config: TC;\n /** The trial's own camera composed with the magnification, about the aimed\n * point — so drawing the same content through it magnifies in place. */\n view: ViewTransform;\n /** The magnification on its own, for whatever must not scale with the\n * camera. */\n factor: number;\n mode: LoupeMode;\n /** The size of the viewport `view` is written for: the trial's content well,\n * not the lens. The lens shows a circle cut out of it. */\n size: ViewportSize;\n}\n\n/**\n * Declares that an instrument can be magnified.\n *\n * With no `render`, the loupe re-draws the instrument's canvas layers through a\n * zoomed camera, so it stays sharp at any factor. An instrument whose content is\n * DOM supplies `render` instead: given a camera, draw me again.\n */\nexport interface LoupeCapability<TS = unknown, TC = unknown> {\n render?: (args: LoupeRenderArgs<TS, TC>) => ReactNode;\n /** Opening magnification, clamped to the bounds below. Default 6. */\n factor?: number;\n /** What the wheel clamps to. Defaults 2 and 32. */\n minFactor?: number;\n maxFactor?: number;\n /** `'vector'` (default) re-renders the content magnified; `'pixel'` blows up\n * the pixels the instrument presented. A `render` loupe is always vector —\n * DOM has no framebuffer to enlarge. */\n mode?: LoupeMode;\n /** Lens diameter in CSS px. Default 200. */\n diameter?: number;\n /** Held for a momentary peek while the loupe is off. Default `'Alt'`; `null`\n * turns hold-to-peek off. Matched against `KeyboardEvent.key`. */\n peekKey?: string | null;\n /** Called with the color under the aim, wherever the surface can say. The\n * canvas painter reads it back; a DOM loupe has no pixels to sample. */\n onColorChange?: (hex: string) => void;\n}\n\n/** An instrument's loupe declaration. `true` takes every default. */\nexport type LoupeDeclaration<TS = unknown, TC = unknown> = true | LoupeCapability<TS, TC>;\n\n/** A {@link LoupeCapability} with every default filled in. */\nexport interface ResolvedLoupe<TS = unknown, TC = unknown> {\n render?: (args: LoupeRenderArgs<TS, TC>) => ReactNode;\n onColorChange?: (hex: string) => void;\n factor: number;\n minFactor: number;\n maxFactor: number;\n mode: LoupeMode;\n diameter: number;\n peekKey: string | null;\n}\n\nexport const LOUPE_DEFAULTS = {\n factor: 6,\n minFactor: 2,\n maxFactor: 32,\n mode: 'vector',\n diameter: 200,\n peekKey: 'Alt',\n} as const satisfies Omit<ResolvedLoupe, 'render' | 'onColorChange'>;\n\nexport function resolveLoupe<TS, TC>(declared: LoupeDeclaration<TS, TC>): ResolvedLoupe<TS, TC> {\n const cap = declared === true ? {} : declared;\n const minFactor = cap.minFactor ?? LOUPE_DEFAULTS.minFactor;\n const maxFactor = cap.maxFactor ?? LOUPE_DEFAULTS.maxFactor;\n return {\n render: cap.render,\n onColorChange: cap.onColorChange,\n minFactor,\n maxFactor,\n factor: Math.min(maxFactor, Math.max(minFactor, cap.factor ?? LOUPE_DEFAULTS.factor)),\n diameter: cap.diameter ?? LOUPE_DEFAULTS.diameter,\n peekKey: cap.peekKey === undefined ? LOUPE_DEFAULTS.peekKey : cap.peekKey,\n // A DOM loupe has no framebuffer, so `pixel` would have nothing to enlarge.\n mode: cap.render ? 'vector' : (cap.mode ?? LOUPE_DEFAULTS.mode),\n };\n}\n"]}