@weasel-js/labkit 1.3.0-pre.0 → 1.4.0-pre.0

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 (259) hide show
  1. package/dist/_dts/CanvasStackContext-DtAn_3O-.d.ts +42 -0
  2. package/dist/_dts/DrawCommand-B3bskUsC.d.ts +564 -0
  3. package/dist/_dts/{PrefsForm-BYa6cWnO.d.ts → PrefsForm-BkUJZx0A.d.ts} +4 -1
  4. package/dist/_dts/fitViewToBounds-dZ2UDB6e.d.ts +21 -0
  5. package/dist/_dts/frac-Cp3NivlC.d.ts +728 -0
  6. package/dist/_dts/index-BDVzvRzQ.d.ts +236 -0
  7. package/dist/_dts/shapeKinds-Cx_rxwsa.d.ts +87 -0
  8. package/dist/_dts/{DrawCommand-DBB45NfN.d.ts → types-C-gh9Ap-.d.ts} +1 -582
  9. package/dist/_dts/{types-AHlQxBNN.d.ts → types-D6s4b7if.d.ts} +2 -2
  10. package/dist/_dts/{types-1Sdxy_Pv.d.ts → types-DYMaEvM5.d.ts} +26 -1
  11. package/dist/_dts/{useTrialState-CsGMjhu9.d.ts → useTrialState-gmMvZqPc.d.ts} +7 -2
  12. package/dist/canvas/index.d.ts +43 -25
  13. package/dist/canvas/index.js +5 -3
  14. package/dist/chrome/index.d.ts +9 -6
  15. package/dist/chrome/index.js +7 -6
  16. package/dist/chunk-2AYGEN57.js +32 -0
  17. package/dist/chunk-2AYGEN57.js.map +1 -0
  18. package/dist/{chunk-RVNN4CHQ.js → chunk-3P5TTTA7.js} +16 -8
  19. package/dist/chunk-3P5TTTA7.js.map +1 -0
  20. package/dist/{chunk-NS54R52R.js → chunk-3ZELRRBV.js} +45 -40
  21. package/dist/chunk-3ZELRRBV.js.map +1 -0
  22. package/dist/{chunk-HFDVGF4X.js → chunk-4EY67BKJ.js} +32 -7
  23. package/dist/chunk-4EY67BKJ.js.map +1 -0
  24. package/dist/chunk-5TCEVMPI.js +140 -0
  25. package/dist/chunk-5TCEVMPI.js.map +1 -0
  26. package/dist/{chunk-O7NVSCLN.js → chunk-6JMU56CU.js} +133 -134
  27. package/dist/chunk-6JMU56CU.js.map +1 -0
  28. package/dist/{chunk-CPUJ3QXL.js → chunk-CQLQPQ4P.js} +2 -2
  29. package/dist/chunk-CQLQPQ4P.js.map +1 -0
  30. package/dist/chunk-CTRKTLYZ.js +33 -0
  31. package/dist/chunk-CTRKTLYZ.js.map +1 -0
  32. package/dist/chunk-EQIB2PGC.js +458 -0
  33. package/dist/chunk-EQIB2PGC.js.map +1 -0
  34. package/dist/chunk-HEORBLVT.js +7128 -0
  35. package/dist/chunk-HEORBLVT.js.map +1 -0
  36. package/dist/{chunk-V7PRSIRQ.js → chunk-JDDIZSLL.js} +4 -4
  37. package/dist/chunk-JDDIZSLL.js.map +1 -0
  38. package/dist/chunk-LITE5YFB.js +669 -0
  39. package/dist/chunk-LITE5YFB.js.map +1 -0
  40. package/dist/{chunk-Z6HJ5FEM.js → chunk-ROQDRXKW.js} +732 -315
  41. package/dist/chunk-ROQDRXKW.js.map +1 -0
  42. package/dist/chunk-SBXNQW4G.js +3 -0
  43. package/dist/chunk-SBXNQW4G.js.map +1 -0
  44. package/dist/{chunk-4TMMVIDM.js → chunk-XJ6N32QP.js} +50 -6
  45. package/dist/chunk-XJ6N32QP.js.map +1 -0
  46. package/dist/chunk-YQJNT4XQ.js +293 -0
  47. package/dist/chunk-YQJNT4XQ.js.map +1 -0
  48. package/dist/controls/index.d.ts +4 -28
  49. package/dist/controls/index.js +3 -3
  50. package/dist/dragdrop/index.d.ts +50 -5
  51. package/dist/dragdrop/index.js +3 -1
  52. package/dist/index.d.ts +660 -302
  53. package/dist/index.js +1793 -587
  54. package/dist/index.js.map +1 -1
  55. package/dist/layers/index.d.ts +6 -5
  56. package/dist/layers/index.js +4 -2
  57. package/dist/loupe/index.d.ts +187 -0
  58. package/dist/loupe/index.js +7 -0
  59. package/dist/loupe/index.js.map +1 -0
  60. package/dist/passthrough/weasel-canvas.d.ts +3 -1
  61. package/dist/passthrough/weasel-canvas.js +1 -1
  62. package/dist/passthrough/weasel-ui.d.ts +151 -91
  63. package/dist/passthrough/weasel-ui.js +3 -2
  64. package/dist/primitives/index.d.ts +3 -1
  65. package/dist/primitives/index.js +6 -5
  66. package/dist/state/index.d.ts +3 -3
  67. package/dist/state/index.js +2 -2
  68. package/dist/styles.css +229 -703
  69. package/dist/surface/index.d.ts +18 -2
  70. package/dist/surface/index.js +2 -2
  71. package/dist/ui/layers/index.d.ts +8 -2
  72. package/dist/ui/layers/index.js +2 -4
  73. package/dist/undo/index.d.ts +5 -4
  74. package/package.json +14 -7
  75. package/src/annotations/AnnotationOverlay.tsx +205 -0
  76. package/src/annotations/AnnotationTargets.tsx +37 -0
  77. package/src/annotations/Annotations.less +129 -0
  78. package/src/annotations/Annotations.meaning.test.tsx +111 -0
  79. package/src/annotations/Annotations.overlay.test.tsx +142 -0
  80. package/src/annotations/AnnotationsContext.ts +49 -0
  81. package/src/annotations/ExportMenu.test.tsx +86 -0
  82. package/src/annotations/ExportMenu.tsx +182 -0
  83. package/src/annotations/MarkList.tsx +75 -0
  84. package/src/annotations/capture.test.ts +140 -0
  85. package/src/annotations/capture.ts +237 -0
  86. package/src/annotations/drawOne.test.ts +56 -0
  87. package/src/annotations/drawOne.ts +47 -0
  88. package/src/annotations/frac.test.ts +59 -0
  89. package/src/annotations/frac.ts +66 -0
  90. package/src/annotations/history.test.ts +82 -0
  91. package/src/annotations/history.ts +118 -0
  92. package/src/annotations/index.ts +37 -0
  93. package/src/annotations/paint.test.ts +125 -0
  94. package/src/annotations/paint.ts +130 -0
  95. package/src/annotations/staleness.test.ts +56 -0
  96. package/src/annotations/staleness.ts +41 -0
  97. package/src/annotations/store.test.ts +175 -0
  98. package/src/annotations/store.ts +317 -0
  99. package/src/annotations/svgNodes.test.ts +77 -0
  100. package/src/annotations/svgNodes.ts +74 -0
  101. package/src/annotations/toolMap.test.ts +36 -0
  102. package/src/annotations/toolMap.ts +54 -0
  103. package/src/annotations/types.ts +222 -0
  104. package/src/annotations/view.test.ts +37 -0
  105. package/src/annotations/view.ts +40 -0
  106. package/src/canvas/AGENTS.md +55 -5
  107. package/src/canvas/CanvasStack.test.tsx +27 -1
  108. package/src/canvas/CanvasStack.tsx +29 -4
  109. package/src/canvas/CanvasStackContext.ts +23 -4
  110. package/src/canvas/camera.test.ts +78 -0
  111. package/src/canvas/camera.ts +62 -0
  112. package/src/canvas/canvasCoords.test.ts +26 -0
  113. package/src/canvas/canvasCoords.ts +20 -7
  114. package/src/canvas/index.ts +5 -1
  115. package/src/canvas/useLayerScheduler.ts +7 -3
  116. package/src/canvas/usePanZoom.test.ts +36 -5
  117. package/src/canvas/usePanZoom.ts +20 -15
  118. package/src/canvas/worldSpec.test.ts +63 -0
  119. package/src/canvas/worldSpec.ts +48 -0
  120. package/src/chrome/builtins.test.ts +31 -1
  121. package/src/chrome/builtins.tsx +63 -19
  122. package/src/chrome/regions/PaletteRegion.test.tsx +22 -1
  123. package/src/chrome/regions/PaletteRegion.tsx +4 -0
  124. package/src/chrome/regions/SidebarRegion.tsx +37 -13
  125. package/src/chrome/regions/ToolbarRegion.tsx +2 -1
  126. package/src/chrome/regions/ViewportRegion.tsx +9 -1
  127. package/src/chrome/regions/regions.test.tsx +6 -1
  128. package/src/chrome/types.ts +20 -0
  129. package/src/config/builder.test.ts +7 -1
  130. package/src/config/builder.ts +1 -5
  131. package/src/config/resolve.test.ts +1 -2
  132. package/src/controls/ControlPanel.stories.tsx +41 -2
  133. package/src/controls/ControlPanel.test.tsx +69 -9
  134. package/src/controls/ControlPanel.tsx +106 -25
  135. package/src/dragdrop/DragDropRuntime.tsx +8 -2
  136. package/src/dragdrop/dragDrop.test.tsx +29 -2
  137. package/src/dragdrop/index.ts +11 -0
  138. package/src/index.test.ts +22 -0
  139. package/src/index.ts +136 -4
  140. package/src/instrument/SineWave.smoke.test.tsx +1 -0
  141. package/src/instrument/types.ts +24 -1
  142. package/src/lab/Lab.surface.test.tsx +162 -0
  143. package/src/lab/Lab.tsx +102 -17
  144. package/src/lab/Lab.undock.test.tsx +85 -0
  145. package/src/lab/LabFullChrome.stories.tsx +20 -0
  146. package/src/lab/LabShell.less +11 -0
  147. package/src/lab/Workspace.less +73 -0
  148. package/src/lab/Workspace.surface.test.tsx +2 -0
  149. package/src/lab/Workspace.tsx +97 -8
  150. package/src/lab/index.ts +1 -1
  151. package/src/lab/panelHost.ts +37 -0
  152. package/src/layers/AGENTS.md +1 -1
  153. package/src/layers/LayerList.tsx +1 -1
  154. package/src/loupe/AGENTS.md +49 -0
  155. package/src/loupe/CanvasLoupe.tsx +83 -0
  156. package/src/loupe/DomLoupe.tsx +62 -0
  157. package/src/loupe/Loupe.less +38 -0
  158. package/src/loupe/LoupeBubble.tsx +32 -0
  159. package/src/loupe/TrialLoupe.tsx +93 -0
  160. package/src/loupe/canvasLens.test.ts +205 -0
  161. package/src/loupe/canvasLens.ts +141 -0
  162. package/src/loupe/index.ts +19 -0
  163. package/src/loupe/types.test.ts +29 -0
  164. package/src/loupe/types.ts +90 -0
  165. package/src/loupe/useHostSize.ts +30 -0
  166. package/src/loupe/useLoupe.test.tsx +197 -0
  167. package/src/loupe/useLoupe.ts +189 -0
  168. package/src/passthrough/weasel-ui.ts +25 -17
  169. package/src/primitives/FloatingPanel.test.tsx +76 -1
  170. package/src/primitives/FloatingPanel.tsx +19 -3
  171. package/src/primitives/ScaleIndicator.test.tsx +7 -2
  172. package/src/primitives/Sidebar.less +18 -0
  173. package/src/primitives/Toolbar.less +8 -0
  174. package/src/primitives/Toolbar.tsx +5 -0
  175. package/src/primitives/useRovingTabIndex.test.ts +21 -0
  176. package/src/primitives/useRovingTabIndex.ts +26 -17
  177. package/src/state/document.test.ts +23 -0
  178. package/src/state/document.ts +14 -2
  179. package/src/state/index.ts +2 -0
  180. package/src/state/store.test.ts +24 -0
  181. package/src/state/store.ts +35 -1
  182. package/src/state/types.ts +11 -0
  183. package/src/state/undock.test.ts +40 -0
  184. package/src/state/undock.ts +39 -0
  185. package/src/styles.less +2 -4
  186. package/src/surface/SurfaceContext.ts +4 -0
  187. package/src/surface/index.ts +8 -3
  188. package/src/surface/useSurfaceTile.test.tsx +2 -0
  189. package/src/surface/useSurfaceTile.ts +7 -1
  190. package/src/surface/useTiledSurface.test.tsx +58 -0
  191. package/src/surface/useTiledSurface.ts +38 -3
  192. package/src/theme/Interstellar.stories.tsx +1 -1
  193. package/src/trial/Trial.annotations.persist.test.tsx +166 -0
  194. package/src/trial/Trial.annotations.test.tsx +121 -0
  195. package/src/trial/Trial.canvas.test.tsx +76 -1
  196. package/src/trial/Trial.config.test.tsx +3 -8
  197. package/src/trial/Trial.less +19 -0
  198. package/src/trial/Trial.loupe.test.tsx +128 -0
  199. package/src/trial/Trial.stories.tsx +1 -0
  200. package/src/trial/Trial.test.tsx +12 -0
  201. package/src/trial/Trial.trialId.test.tsx +36 -0
  202. package/src/trial/Trial.tsx +215 -40
  203. package/src/trial/TrialChrome.tsx +35 -0
  204. package/src/trial/UndockedSections.tsx +65 -0
  205. package/src/trial/trialOps.test.ts +21 -0
  206. package/src/trial/trialOps.ts +5 -3
  207. package/src/ui/layers/index.ts +5 -1
  208. package/dist/_dts/index-DgcNdEdh.d.ts +0 -314
  209. package/dist/chunk-4TMMVIDM.js.map +0 -1
  210. package/dist/chunk-CPUJ3QXL.js.map +0 -1
  211. package/dist/chunk-HFDVGF4X.js.map +0 -1
  212. package/dist/chunk-NS54R52R.js.map +0 -1
  213. package/dist/chunk-O2BULFHX.js +0 -152
  214. package/dist/chunk-O2BULFHX.js.map +0 -1
  215. package/dist/chunk-O7NVSCLN.js.map +0 -1
  216. package/dist/chunk-PO6L3NSH.js +0 -366
  217. package/dist/chunk-PO6L3NSH.js.map +0 -1
  218. package/dist/chunk-PQJ5B2U2.js +0 -27
  219. package/dist/chunk-PQJ5B2U2.js.map +0 -1
  220. package/dist/chunk-RVNN4CHQ.js.map +0 -1
  221. package/dist/chunk-TLGRYALP.js +0 -6151
  222. package/dist/chunk-TLGRYALP.js.map +0 -1
  223. package/dist/chunk-V7PRSIRQ.js.map +0 -1
  224. package/dist/chunk-Z6HJ5FEM.js.map +0 -1
  225. package/dist/chunk-ZZAYVX4X.js +0 -505
  226. package/dist/chunk-ZZAYVX4X.js.map +0 -1
  227. package/src/primitives/DragHandleGlyph.tsx +0 -29
  228. package/src/ui/format.test.ts +0 -33
  229. package/src/ui/format.ts +0 -30
  230. package/src/ui/layers/LayerStack.less +0 -143
  231. package/src/ui/layers/LayerStack.stories.tsx +0 -45
  232. package/src/ui/layers/LayerStack.test.tsx +0 -170
  233. package/src/ui/layers/LayerStack.tsx +0 -208
  234. package/src/ui/properties/CheckboxRow.stories.tsx +0 -27
  235. package/src/ui/properties/ColorRow.stories.tsx +0 -106
  236. package/src/ui/properties/CurveField.less +0 -48
  237. package/src/ui/properties/CurveField.stories.tsx +0 -20
  238. package/src/ui/properties/CurveField.test.tsx +0 -127
  239. package/src/ui/properties/CurveField.tsx +0 -184
  240. package/src/ui/properties/EffectCard.tsx +0 -324
  241. package/src/ui/properties/Gallery.stories.tsx +0 -178
  242. package/src/ui/properties/NumberRow.stories.tsx +0 -65
  243. package/src/ui/properties/PropertyGroup.less +0 -50
  244. package/src/ui/properties/PropertyGroup.stories.tsx +0 -34
  245. package/src/ui/properties/PropertyGroup.test.tsx +0 -33
  246. package/src/ui/properties/PropertyGroup.tsx +0 -45
  247. package/src/ui/properties/PropertyList.stories.tsx +0 -83
  248. package/src/ui/properties/PropertyPanel.less +0 -606
  249. package/src/ui/properties/PropertyPanel.stories.tsx +0 -190
  250. package/src/ui/properties/PropertyPanel.test.tsx +0 -193
  251. package/src/ui/properties/PropertyPanel.tsx +0 -469
  252. package/src/ui/properties/PropertyRow.stories.tsx +0 -53
  253. package/src/ui/properties/SelectRow.stories.tsx +0 -58
  254. package/src/ui/properties/SliderRow.stories.tsx +0 -74
  255. package/src/ui/properties/SpeechBalloonPanels.stories.tsx +0 -398
  256. package/src/ui/properties/TextRow.stories.tsx +0 -62
  257. package/src/ui/properties/ToggleRow.stories.tsx +0 -57
  258. package/src/ui/properties/index.ts +0 -39
  259. package/src/ui/properties/storyLayouts.tsx +0 -36
@@ -0,0 +1,669 @@
1
+ import { Toolbar, ZoomControl, ScaleIndicator, FpsMeter, useRovingTabIndex, StatusBar } from './chunk-6JMU56CU.js';
2
+ import { ControlPanel } from './chunk-YQJNT4XQ.js';
3
+ import { b, h2, D, O, B, k, x, A, p, _, v, j, y, n4, o3 } from './chunk-HEORBLVT.js';
4
+ import { SelectIcon, PencilIcon, LineIcon, ArrowIcon, RectIcon, EllipseIcon, TextIcon } from './chunk-ROQDRXKW.js';
5
+ import { createContext, useContext, useState, useId, useRef, useSyncExternalStore, useCallback } from 'react';
6
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
7
+
8
+ var AnnotationsContext = createContext(null);
9
+ function useMarkVersion(api) {
10
+ const version = useRef(0);
11
+ useSyncExternalStore(
12
+ useCallback(
13
+ (fn) => api?.subscribe(() => {
14
+ version.current += 1;
15
+ fn();
16
+ }) ?? (() => {
17
+ }),
18
+ [api]
19
+ ),
20
+ useCallback(() => version.current, []),
21
+ () => 0
22
+ );
23
+ }
24
+ function useAnnotations() {
25
+ const api = useContext(AnnotationsContext);
26
+ useMarkVersion(api);
27
+ if (!api) {
28
+ throw new Error(
29
+ "[labkit] useAnnotations requires an instrument that declares the `annotations` capability"
30
+ );
31
+ }
32
+ return api;
33
+ }
34
+ function useAnnotationsOptional() {
35
+ const api = useContext(AnnotationsContext);
36
+ useMarkVersion(api);
37
+ return api;
38
+ }
39
+ var SCALES = [1, 2, 4];
40
+ var FORMATS = [
41
+ { id: "png", label: "PNG" },
42
+ { id: "svg", label: "SVG" }
43
+ ];
44
+ function fileName(result) {
45
+ return `${result.target.replace(/[^a-z0-9._-]+/gi, "-")}.${result.format}`;
46
+ }
47
+ function download(result) {
48
+ const url = URL.createObjectURL(result.blob);
49
+ const a = document.createElement("a");
50
+ a.href = url;
51
+ a.download = fileName(result);
52
+ a.click();
53
+ setTimeout(() => URL.revokeObjectURL(url), 0);
54
+ }
55
+ async function copy(result) {
56
+ if (result.format === "svg") {
57
+ await navigator.clipboard.writeText(await result.blob.text());
58
+ return;
59
+ }
60
+ await navigator.clipboard.write([new ClipboardItem({ "image/png": result.blob })]);
61
+ }
62
+ function ExportMenu() {
63
+ const marks = useAnnotationsOptional();
64
+ const [anchor, setAnchor] = useState(null);
65
+ const [open, setOpen] = useState(false);
66
+ const [target, setTarget] = useState(null);
67
+ const [format, setFormat] = useState("png");
68
+ const [scale, setScale] = useState(2);
69
+ const [busy, setBusy] = useState(false);
70
+ const [error, setError] = useState(null);
71
+ const titleId = useId();
72
+ if (!marks) return null;
73
+ const targets = marks.targets();
74
+ const chosen = target ?? targets[0]?.id ?? null;
75
+ const run = async (then) => {
76
+ if (!chosen) return;
77
+ setBusy(true);
78
+ setError(null);
79
+ try {
80
+ await then(await marks.capture(chosen, { format, scale }));
81
+ setOpen(false);
82
+ } catch (err) {
83
+ setError(err instanceof Error ? err.message : String(err));
84
+ } finally {
85
+ setBusy(false);
86
+ }
87
+ };
88
+ return /* @__PURE__ */ jsxs("span", { className: "lk-export", ref: setAnchor, children: [
89
+ /* @__PURE__ */ jsx(
90
+ Toolbar.Button,
91
+ {
92
+ iconOnly: true,
93
+ pressed: open,
94
+ "aria-label": "Export",
95
+ title: "Export",
96
+ onClick: () => setOpen((was) => !was),
97
+ children: /* @__PURE__ */ jsx(b, { size: 16 })
98
+ }
99
+ ),
100
+ /* @__PURE__ */ jsx(
101
+ h2,
102
+ {
103
+ triggerRef: { current: anchor },
104
+ isOpen: open,
105
+ onOpenChange: setOpen,
106
+ onDismiss: () => setOpen(false),
107
+ placement: "bottom end",
108
+ UNSTABLE_portalContainer: anchor?.closest(".lk-root") ?? void 0,
109
+ "aria-labelledby": titleId,
110
+ children: /* @__PURE__ */ jsxs("div", { className: "lk-export__panel", children: [
111
+ /* @__PURE__ */ jsx("span", { className: "lk-export__title", id: titleId, children: "Export" }),
112
+ /* @__PURE__ */ jsxs("label", { className: "lk-export__row", children: [
113
+ /* @__PURE__ */ jsx("span", { children: "Target" }),
114
+ /* @__PURE__ */ jsx(
115
+ "select",
116
+ {
117
+ "aria-label": "Target",
118
+ value: chosen ?? "",
119
+ onChange: (e) => setTarget(e.target.value),
120
+ children: targets.map((t) => /* @__PURE__ */ jsx("option", { value: t.id, children: t.id }, t.id))
121
+ }
122
+ )
123
+ ] }),
124
+ /* @__PURE__ */ jsxs("div", { className: "lk-export__row", children: [
125
+ /* @__PURE__ */ jsx("span", { children: "Format" }),
126
+ /* @__PURE__ */ jsx("span", { className: "lk-export__choices", role: "radiogroup", "aria-label": "Format", children: FORMATS.map((f) => /* @__PURE__ */ jsxs("label", { children: [
127
+ /* @__PURE__ */ jsx(
128
+ "input",
129
+ {
130
+ type: "radio",
131
+ name: "lk-export-format",
132
+ checked: format === f.id,
133
+ onChange: () => setFormat(f.id)
134
+ }
135
+ ),
136
+ f.label
137
+ ] }, f.id)) })
138
+ ] }),
139
+ /* @__PURE__ */ jsxs("div", { className: "lk-export__row", children: [
140
+ /* @__PURE__ */ jsx("span", { children: "Scale" }),
141
+ /* @__PURE__ */ jsx("span", { className: "lk-export__choices", role: "radiogroup", "aria-label": "Scale", children: SCALES.map((s) => /* @__PURE__ */ jsxs("label", { children: [
142
+ /* @__PURE__ */ jsx(
143
+ "input",
144
+ {
145
+ type: "radio",
146
+ name: "lk-export-scale",
147
+ checked: scale === s,
148
+ onChange: () => setScale(s)
149
+ }
150
+ ),
151
+ s,
152
+ "\xD7"
153
+ ] }, s)) })
154
+ ] }),
155
+ /* @__PURE__ */ jsxs("div", { className: "lk-export__actions", children: [
156
+ /* @__PURE__ */ jsx("button", { type: "button", disabled: busy || !chosen, onClick: () => run(download), children: "Download" }),
157
+ /* @__PURE__ */ jsx("button", { type: "button", disabled: busy || !chosen, onClick: () => run(copy), children: "Copy" })
158
+ ] }),
159
+ error ? /* @__PURE__ */ jsx("p", { className: "lk-export__error", role: "alert", children: error }) : null
160
+ ] })
161
+ }
162
+ )
163
+ ] });
164
+ }
165
+ function MarkList({ meaning, config }) {
166
+ const marks = useAnnotations();
167
+ const all = marks.query();
168
+ const statuses = meaning?.statuses ?? [];
169
+ if (all.length === 0) {
170
+ return /* @__PURE__ */ jsx("div", { className: "lk-mark-list__empty", children: "No marks yet" });
171
+ }
172
+ return /* @__PURE__ */ jsx("ul", { className: "lk-mark-list", children: all.map((a) => {
173
+ const stale = marks.isStale(a, config);
174
+ return /* @__PURE__ */ jsxs("li", { className: "lk-mark-list__row", children: [
175
+ /* @__PURE__ */ jsxs("div", { className: "lk-mark-list__head", children: [
176
+ /* @__PURE__ */ jsx("span", { className: "lk-mark-list__kind", children: a.kind }),
177
+ /* @__PURE__ */ jsx("span", { className: "lk-mark-list__target", children: a.target }),
178
+ stale ? /* @__PURE__ */ jsx("span", { className: "lk-mark-list__stale", children: "stale" }) : null,
179
+ /* @__PURE__ */ jsx(
180
+ "button",
181
+ {
182
+ type: "button",
183
+ className: "lk-mark-list__drop",
184
+ "aria-label": `Remove ${a.kind} on ${a.target}`,
185
+ onClick: () => marks.remove(a.id),
186
+ children: "\xD7"
187
+ }
188
+ )
189
+ ] }),
190
+ /* @__PURE__ */ jsx(
191
+ "input",
192
+ {
193
+ className: "lk-mark-list__title",
194
+ "aria-label": `Title of ${a.kind} on ${a.target}`,
195
+ value: a.title ?? "",
196
+ placeholder: "Untitled",
197
+ onChange: (e) => marks.update(a.id, { title: e.target.value })
198
+ }
199
+ ),
200
+ statuses.length > 0 ? (
201
+ // A native select: it carries role, name and keyboard operability
202
+ // for free, and a sidebar row is not the place to rebuild them.
203
+ /* @__PURE__ */ jsxs(
204
+ "select",
205
+ {
206
+ className: "lk-mark-list__status",
207
+ "aria-label": `Status of ${a.kind} on ${a.target}`,
208
+ value: a.status ?? "",
209
+ onChange: (e) => marks.update(a.id, { status: e.target.value }),
210
+ children: [
211
+ /* @__PURE__ */ jsx("option", { value: "", children: "\u2014" }),
212
+ statuses.map((s) => /* @__PURE__ */ jsx("option", { value: s.id, children: s.label }, s.id))
213
+ ]
214
+ }
215
+ )
216
+ ) : null
217
+ ] }, a.id);
218
+ }) });
219
+ }
220
+
221
+ // src/annotations/toolMap.ts
222
+ var TOOLS = {
223
+ select: { weaselTool: "select" },
224
+ stroke: { weaselTool: "pencil", kind: "stroke" },
225
+ line: { weaselTool: "line", kind: "line" },
226
+ arrow: { weaselTool: "line", kind: "arrow" },
227
+ rect: { weaselTool: "rect", kind: "rect" },
228
+ ellipse: { weaselTool: "ellipse", kind: "ellipse" },
229
+ text: { weaselTool: "text", kind: "text" }
230
+ };
231
+ var ANNOTATION_TOOLS = [
232
+ { id: "select", label: "Select", icon: SelectIcon, group: "annotate" },
233
+ { id: "stroke", label: "Freehand", icon: PencilIcon, group: "annotate" },
234
+ { id: "line", label: "Line", icon: LineIcon, group: "annotate" },
235
+ { id: "arrow", label: "Arrow", icon: ArrowIcon, group: "annotate" },
236
+ { id: "rect", label: "Rectangle", icon: RectIcon, group: "annotate" },
237
+ { id: "ellipse", label: "Ellipse", icon: EllipseIcon, group: "annotate" },
238
+ { id: "text", label: "Text", icon: TextIcon, group: "annotate" }
239
+ ];
240
+ function annotationToolInfo(id) {
241
+ return id === null ? void 0 : TOOLS[id];
242
+ }
243
+ var ANNOTATION_WEASEL_TOOLS = [
244
+ ...new Set(Object.values(TOOLS).map((t) => t.weaselTool))
245
+ ];
246
+ var ZOOM_STEP = 1.25;
247
+ function builtinContributions(instrument, ctx, controls) {
248
+ const out = [];
249
+ const zoom = ctx.zoom;
250
+ if (instrument.undo != null || instrument.annotations != null) {
251
+ out.push({
252
+ id: "undo",
253
+ region: "toolbar",
254
+ group: "history",
255
+ item: {
256
+ icon: D,
257
+ label: "Undo",
258
+ shortcut: "Mod+Z",
259
+ disabled: !ctx.canUndo,
260
+ onActivate: ctx.undo
261
+ }
262
+ });
263
+ out.push({
264
+ id: "redo",
265
+ region: "toolbar",
266
+ group: "history",
267
+ item: {
268
+ icon: O,
269
+ label: "Redo",
270
+ shortcut: "Mod+Shift+Z",
271
+ disabled: !ctx.canRedo,
272
+ onActivate: ctx.redo
273
+ }
274
+ });
275
+ }
276
+ const tools = [
277
+ ...instrument.annotations ? ANNOTATION_TOOLS : [],
278
+ ...instrument.tools?.tools ?? []
279
+ ];
280
+ for (const t of tools) {
281
+ out.push({
282
+ id: t.id,
283
+ region: "palette",
284
+ group: t.group,
285
+ item: { icon: t.icon, label: t.label, shortcut: t.shortcut }
286
+ });
287
+ }
288
+ if (instrument.loupe != null) {
289
+ out.push({
290
+ id: "loupe",
291
+ region: "toolbar",
292
+ group: "view",
293
+ item: {
294
+ icon: B,
295
+ label: "Loupe",
296
+ pressed: ctx.loupeOn,
297
+ onActivate: ctx.toggleLoupe
298
+ }
299
+ });
300
+ }
301
+ if (instrument.canvas != null && zoom !== null) {
302
+ out.push({
303
+ id: "zoom-out",
304
+ region: "viewport",
305
+ group: "zoom",
306
+ item: {
307
+ icon: k,
308
+ label: "Zoom out",
309
+ onActivate: () => ctx.setZoom(zoom / ZOOM_STEP)
310
+ }
311
+ });
312
+ out.push({
313
+ id: "zoom-in",
314
+ region: "viewport",
315
+ group: "zoom",
316
+ item: {
317
+ icon: x,
318
+ label: "Zoom in",
319
+ onActivate: () => ctx.setZoom(zoom * ZOOM_STEP)
320
+ }
321
+ });
322
+ out.push({
323
+ id: "actual-size",
324
+ region: "viewport",
325
+ group: "zoom",
326
+ item: { icon: A, label: "Actual size", onActivate: () => ctx.setZoom(1) }
327
+ });
328
+ out.push({
329
+ id: "zoom-control",
330
+ region: "viewport",
331
+ group: "zoom",
332
+ render: (c) => /* @__PURE__ */ jsx(ZoomControl, { zoom: c.zoom ?? 1, onZoomChange: c.setZoom })
333
+ });
334
+ out.push({
335
+ id: "scale",
336
+ region: "status",
337
+ group: "view",
338
+ render: () => /* @__PURE__ */ jsx(ScaleIndicator, {})
339
+ });
340
+ out.push({
341
+ id: "fps",
342
+ region: "status",
343
+ group: "view",
344
+ end: true,
345
+ render: () => /* @__PURE__ */ jsx(FpsMeter, {})
346
+ });
347
+ }
348
+ if (instrument.annotations != null) {
349
+ out.push({
350
+ id: "export",
351
+ region: "toolbar",
352
+ group: "trial",
353
+ end: true,
354
+ render: () => /* @__PURE__ */ jsx(ExportMenu, {})
355
+ });
356
+ out.push({
357
+ id: "marks",
358
+ region: "sidebar",
359
+ item: {
360
+ title: "Marks",
361
+ body: /* @__PURE__ */ jsx(MarkList, { meaning: instrument.annotations.meaning, config: ctx.config })
362
+ }
363
+ });
364
+ }
365
+ if (Object.keys(ctx.configSchema.group.children).length > 0) {
366
+ out.push({
367
+ id: "settings",
368
+ region: "sidebar",
369
+ item: {
370
+ title: "Settings",
371
+ body: /* @__PURE__ */ jsx(
372
+ ControlPanel,
373
+ {
374
+ schema: ctx.configSchema,
375
+ config: ctx.config,
376
+ setConfig: (key, value) => ctx.setConfig(String(key), value),
377
+ renderers: controls
378
+ }
379
+ )
380
+ }
381
+ });
382
+ }
383
+ if (ctx.savedSnapshots.length > 0) {
384
+ out.push({
385
+ id: "snapshot-load",
386
+ region: "toolbar",
387
+ group: "trial",
388
+ end: true,
389
+ render: (c) => /* @__PURE__ */ jsx(
390
+ p,
391
+ {
392
+ className: "lk-toolbar__load-select",
393
+ "aria-label": "Load snapshot",
394
+ placeholder: "Load\u2026",
395
+ selectedKey: null,
396
+ options: c.savedSnapshots.map((sn) => ({ value: sn.id, label: sn.name })),
397
+ onSelectionChange: (id) => {
398
+ if (id != null) c.loadSnapshot(String(id));
399
+ }
400
+ }
401
+ )
402
+ });
403
+ }
404
+ out.push({
405
+ id: "clone",
406
+ region: "titlebar",
407
+ end: true,
408
+ item: { icon: _, label: "Clone trial", onActivate: ctx.clone }
409
+ });
410
+ out.push({
411
+ id: "reset",
412
+ region: "titlebar",
413
+ end: true,
414
+ item: { icon: v, label: "Reset trial", onActivate: ctx.reset }
415
+ });
416
+ out.push({
417
+ id: "snapshot",
418
+ region: "titlebar",
419
+ end: true,
420
+ item: {
421
+ icon: j,
422
+ label: "Save snapshot",
423
+ shortcut: "Mod+S",
424
+ onActivate: () => ctx.saveSnapshot()
425
+ }
426
+ });
427
+ out.push({
428
+ id: "close",
429
+ region: "titlebar",
430
+ end: true,
431
+ item: {
432
+ icon: y,
433
+ label: ctx.isLastTrial ? "Cannot close the last trial" : "Close trial",
434
+ danger: true,
435
+ disabled: ctx.isLastTrial,
436
+ onActivate: ctx.close
437
+ }
438
+ });
439
+ return out;
440
+ }
441
+
442
+ // src/chrome/merge.ts
443
+ function mergeContributions(...bundles) {
444
+ const out = [];
445
+ const seen = /* @__PURE__ */ new Set();
446
+ for (const bundle of bundles) {
447
+ for (const entry of bundle) {
448
+ if (seen.has(entry.id)) {
449
+ throw new Error(
450
+ `[labkit] mergeContributions: duplicate contribution id "${entry.id}". Two bundles registered the same id; rename one, or suppress the built-in before adding yours.`
451
+ );
452
+ }
453
+ seen.add(entry.id);
454
+ out.push(entry);
455
+ }
456
+ }
457
+ return out;
458
+ }
459
+ function suppressContributions(bundle, ids) {
460
+ const present = new Set(bundle.map((c) => c.id));
461
+ for (const id of ids) {
462
+ if (!present.has(id)) {
463
+ throw new Error(
464
+ `[labkit] cannot suppress "${id}": no contribution with that id. Present ids: ${[...present].join(", ")}`
465
+ );
466
+ }
467
+ }
468
+ const drop = new Set(ids);
469
+ return bundle.filter((c) => !drop.has(c.id));
470
+ }
471
+ function PaletteRegion({ contributions, ctx }) {
472
+ const { ref, onKeyDown } = useRovingTabIndex("vertical");
473
+ if (contributions.length === 0) return null;
474
+ return /* @__PURE__ */ jsx(
475
+ "div",
476
+ {
477
+ ref,
478
+ className: "lk-palette-region",
479
+ role: "toolbar",
480
+ "aria-label": "Tools",
481
+ "aria-orientation": "vertical",
482
+ onKeyDown,
483
+ children: /* @__PURE__ */ jsx(n4, { orientation: "vertical", children: contributions.map((c) => {
484
+ if (c.render) return /* @__PURE__ */ jsx("span", { children: c.render(ctx) }, c.id);
485
+ if (c.region !== "palette" || !c.item) return null;
486
+ const { icon: Icon, label, shortcut, disabled } = c.item;
487
+ return /* @__PURE__ */ jsx(
488
+ o3,
489
+ {
490
+ icon: /* @__PURE__ */ jsx(Icon, { size: 16 }),
491
+ label,
492
+ shortcut,
493
+ active: ctx.activeToolId === c.id,
494
+ disabled,
495
+ onClick: () => ctx.setActiveTool(c.id)
496
+ },
497
+ c.id
498
+ );
499
+ }) })
500
+ }
501
+ );
502
+ }
503
+ function Section({
504
+ title,
505
+ defaultCollapsed,
506
+ onUndock,
507
+ children
508
+ }) {
509
+ const [collapsed, setCollapsed] = useState(defaultCollapsed);
510
+ return /* @__PURE__ */ jsxs("section", { className: "lk-sidebar-section", children: [
511
+ /* @__PURE__ */ jsxs("div", { className: "lk-sidebar-section__bar", children: [
512
+ /* @__PURE__ */ jsx(
513
+ "button",
514
+ {
515
+ type: "button",
516
+ className: "lk-sidebar-section__head",
517
+ "aria-expanded": !collapsed,
518
+ onClick: () => setCollapsed((c) => !c),
519
+ children: title
520
+ }
521
+ ),
522
+ onUndock ? /* @__PURE__ */ jsx(
523
+ "button",
524
+ {
525
+ type: "button",
526
+ className: "lk-sidebar-section__undock",
527
+ "aria-label": `Undock ${title}`,
528
+ title: `Undock ${title}`,
529
+ onClick: onUndock,
530
+ children: "\u29C9"
531
+ }
532
+ ) : null
533
+ ] }),
534
+ collapsed ? null : /* @__PURE__ */ jsx("div", { className: "lk-sidebar-section__body", children })
535
+ ] });
536
+ }
537
+ function SidebarRegion({ contributions, ctx }) {
538
+ if (contributions.length === 0) return null;
539
+ return /* @__PURE__ */ jsx(Fragment, { children: contributions.map((c) => {
540
+ if (c.render) return /* @__PURE__ */ jsx("div", { children: c.render(ctx) }, c.id);
541
+ if (c.region !== "sidebar" || !c.item) return null;
542
+ if (ctx.undockedPanels.includes(c.id)) return null;
543
+ const item = c.item;
544
+ return /* @__PURE__ */ jsx(
545
+ Section,
546
+ {
547
+ title: item.title,
548
+ defaultCollapsed: item.defaultCollapsed ?? false,
549
+ onUndock: item.undockable === false ? void 0 : () => ctx.undockPanel(c.id, item.undockAs ?? "tile"),
550
+ children: item.body
551
+ },
552
+ c.id
553
+ );
554
+ }) });
555
+ }
556
+ function StatusRegion({ contributions, ctx }) {
557
+ if (contributions.length === 0) return null;
558
+ return /* @__PURE__ */ jsx(StatusBar, { children: contributions.map((c) => {
559
+ if (c.render)
560
+ return /* @__PURE__ */ jsx(StatusBar.Section, { end: c.end, children: c.render(ctx) }, c.id);
561
+ if (c.region !== "status" || !c.item) return null;
562
+ return /* @__PURE__ */ jsx(StatusBar.Section, { end: c.end, children: /* @__PURE__ */ jsx("span", { title: c.item.title, children: c.item.text }) }, c.id);
563
+ }) });
564
+ }
565
+ function renderEntry(c, ctx) {
566
+ if (c.render) return /* @__PURE__ */ jsx("span", { children: c.render(ctx) }, c.id);
567
+ if (c.region !== "titlebar" || !c.item) return null;
568
+ const { icon: Icon, label, shortcut, disabled, danger } = c.item;
569
+ return /* @__PURE__ */ jsx(
570
+ "button",
571
+ {
572
+ type: "button",
573
+ className: `lk-titlebar-button${danger ? " lk-titlebar-button--danger" : ""}`,
574
+ disabled,
575
+ "aria-label": label,
576
+ title: shortcut ? `${label} (${shortcut})` : label,
577
+ onClick: c.item.onActivate,
578
+ onPointerDown: (e) => e.stopPropagation(),
579
+ onMouseDown: (e) => e.stopPropagation(),
580
+ children: /* @__PURE__ */ jsx(Icon, { size: 14 })
581
+ },
582
+ c.id
583
+ );
584
+ }
585
+ function TitleBarRegion({ contributions, ctx }) {
586
+ if (contributions.length === 0) return null;
587
+ return /* @__PURE__ */ jsx("span", { className: "lk-trial__titlebar-actions", children: contributions.map((c) => renderEntry(c, ctx)) });
588
+ }
589
+ function groupsOf(contributions) {
590
+ const groups = [];
591
+ const byKey = /* @__PURE__ */ new Map();
592
+ for (const c of contributions) {
593
+ if (c.group == null) {
594
+ groups.push({ key: c.id, end: c.end ?? false, entries: [c] });
595
+ continue;
596
+ }
597
+ let g = byKey.get(c.group);
598
+ if (!g) {
599
+ g = { key: c.group, end: c.end ?? false, entries: [] };
600
+ byKey.set(c.group, g);
601
+ groups.push(g);
602
+ }
603
+ g.entries.push(c);
604
+ }
605
+ return groups;
606
+ }
607
+ function renderEntry2(c, ctx) {
608
+ if (c.render) return /* @__PURE__ */ jsx("span", { children: c.render(ctx) }, c.id);
609
+ if (c.region !== "toolbar" || !c.item) return null;
610
+ const { icon: Icon, label, shortcut, disabled, danger, showLabel, pressed } = c.item;
611
+ return /* @__PURE__ */ jsxs(
612
+ Toolbar.Button,
613
+ {
614
+ iconOnly: !showLabel,
615
+ variant: danger ? "danger" : "default",
616
+ disabled,
617
+ pressed,
618
+ "aria-label": label,
619
+ title: shortcut ? `${label} (${shortcut})` : label,
620
+ onClick: c.item.onActivate,
621
+ children: [
622
+ /* @__PURE__ */ jsx(Icon, { size: 16 }),
623
+ showLabel ? /* @__PURE__ */ jsx("span", { children: label }) : null
624
+ ]
625
+ },
626
+ c.id
627
+ );
628
+ }
629
+ function ToolbarRegion({ contributions, ctx }) {
630
+ if (contributions.length === 0) return null;
631
+ const groups = groupsOf(contributions);
632
+ return /* @__PURE__ */ jsx(Toolbar, { "aria-label": "Trial actions", children: groups.map((g) => /* @__PURE__ */ jsx(Toolbar.Group, { end: g.end, "aria-label": g.key, children: g.entries.map((c) => renderEntry2(c, ctx)) }, g.key)) });
633
+ }
634
+ function ViewportRegion({ contributions, ctx }) {
635
+ const { ref, onKeyDown } = useRovingTabIndex();
636
+ if (contributions.length === 0) return null;
637
+ return /* @__PURE__ */ jsx(
638
+ "div",
639
+ {
640
+ ref,
641
+ className: "lk-viewport-controls",
642
+ role: "toolbar",
643
+ "aria-label": "View",
644
+ onKeyDown,
645
+ children: contributions.map((c) => {
646
+ if (c.render) return /* @__PURE__ */ jsx("span", { children: c.render(ctx) }, c.id);
647
+ if (c.region !== "viewport" || !c.item) return null;
648
+ const { icon: Icon, label, disabled } = c.item;
649
+ return /* @__PURE__ */ jsx(
650
+ "button",
651
+ {
652
+ type: "button",
653
+ className: "lk-viewport-controls__button",
654
+ "aria-label": label,
655
+ title: label,
656
+ disabled,
657
+ onClick: c.item.onActivate,
658
+ children: /* @__PURE__ */ jsx(Icon, { size: 16 })
659
+ },
660
+ c.id
661
+ );
662
+ })
663
+ }
664
+ );
665
+ }
666
+
667
+ export { ANNOTATION_TOOLS, ANNOTATION_WEASEL_TOOLS, AnnotationsContext, ExportMenu, MarkList, PaletteRegion, SidebarRegion, StatusRegion, TitleBarRegion, ToolbarRegion, ViewportRegion, annotationToolInfo, builtinContributions, mergeContributions, suppressContributions, useAnnotations, useAnnotationsOptional };
668
+ //# sourceMappingURL=chunk-LITE5YFB.js.map
669
+ //# sourceMappingURL=chunk-LITE5YFB.js.map