@weasel-js/labkit 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_dts/{DrawCommand-CitWPxMY.d.ts → DrawCommand-uKHt4Vul.d.ts} +56 -0
- package/dist/_dts/{index-C6Yze7sQ.d.ts → index-CFlDPeZh.d.ts} +30 -1
- package/dist/_dts/{types-Si4Fw-1F.d.ts → types-x92Kfeme.d.ts} +14 -0
- package/dist/_dts/{useExperimentState-CJn2hHzd.d.ts → useExperimentState-vrttakTt.d.ts} +43 -0
- package/dist/canvas/index.d.ts +13 -2
- package/dist/canvas/index.js +2 -2
- package/dist/{chunk-ISEK5LXT.js → chunk-3WPOGKUP.js} +1603 -1670
- package/dist/chunk-3WPOGKUP.js.map +1 -0
- package/dist/{chunk-54IQ2DX7.js → chunk-574LJAV4.js} +3 -3
- package/dist/chunk-574LJAV4.js.map +1 -0
- package/dist/{chunk-VLAHRJOC.js → chunk-5R2ATYPJ.js} +2 -2
- package/dist/{chunk-VLAHRJOC.js.map → chunk-5R2ATYPJ.js.map} +1 -1
- package/dist/{chunk-EXBV7A6X.js → chunk-73PXCRCR.js} +3 -3
- package/dist/chunk-73PXCRCR.js.map +1 -0
- package/dist/{chunk-PWC7AQZM.js → chunk-CPUJ3QXL.js} +2 -2
- package/dist/chunk-CPUJ3QXL.js.map +1 -0
- package/dist/{chunk-NRD3TDNQ.js → chunk-N5KTQKQA.js} +1462 -1487
- package/dist/chunk-N5KTQKQA.js.map +1 -0
- package/dist/{chunk-HXZHVU4G.js → chunk-PMAU3SEE.js} +3 -3
- package/dist/chunk-PMAU3SEE.js.map +1 -0
- package/dist/{chunk-7BKDG73Z.js → chunk-RL2LOLNI.js} +2 -2
- package/dist/chunk-RL2LOLNI.js.map +1 -0
- package/dist/{chunk-2QNYYL3V.js → chunk-SFL7NFKN.js} +2 -2
- package/dist/chunk-SFL7NFKN.js.map +1 -0
- package/dist/{chunk-53XSBIUK.js → chunk-T7OKNJTY.js} +2 -2
- package/dist/chunk-T7OKNJTY.js.map +1 -0
- package/dist/controls/index.d.ts +4 -2
- package/dist/controls/index.js +1 -1
- package/dist/dragdrop/index.d.ts +2 -2
- package/dist/index.d.ts +122 -6
- package/dist/index.js +18 -18
- package/dist/index.js.map +1 -1
- package/dist/layers/index.d.ts +6 -3
- package/dist/layers/index.js +1 -1
- package/dist/passthrough/weasel-canvas.d.ts +5 -1
- package/dist/passthrough/weasel-canvas.js +1 -1
- package/dist/passthrough/weasel-ui.d.ts +514 -36
- package/dist/passthrough/weasel-ui.js +2 -2
- package/dist/primitives/index.d.ts +13 -0
- package/dist/primitives/index.js +2 -2
- package/dist/state/index.d.ts +15 -2
- package/dist/state/index.js +2 -2
- package/dist/state/index.js.map +1 -1
- package/dist/styles.css +147 -0
- package/dist/ui/layers/index.d.ts +5 -0
- package/dist/ui/layers/index.js +3 -3
- package/dist/undo/index.d.ts +17 -2
- package/dist/undo/index.js +1 -1
- package/package.json +2 -2
- package/src/canvas/CanvasStack.tsx +4 -0
- package/src/canvas/CanvasStackContext.ts +3 -0
- package/src/canvas/canvasCoords.ts +2 -0
- package/src/canvas/useLayerScheduler.ts +2 -0
- package/src/controls/ControlPanel.tsx +2 -0
- package/src/controls/types.ts +14 -0
- package/src/instrument/capabilityDetector.ts +3 -0
- package/src/instrument/defineInstrument.ts +2 -0
- package/src/instrument/types.ts +29 -0
- package/src/instrument/validateConfigSchema.ts +5 -0
- package/src/lab/Lab.tsx +3 -0
- package/src/lab/LabContext.ts +5 -0
- package/src/lab/LabShell.tsx +4 -0
- package/src/lab/WorkspaceGrid.tsx +2 -0
- package/src/lab/gridDims.ts +2 -0
- package/src/layers/LayerList.tsx +3 -0
- package/src/primitives/FpsMeter.tsx +1 -0
- package/src/primitives/ScaleIndicator.tsx +4 -0
- package/src/primitives/Sidebar.tsx +3 -0
- package/src/primitives/StatusBar.tsx +3 -0
- package/src/primitives/Toolbar.tsx +6 -0
- package/src/state/SingletonExperiment.tsx +1 -0
- package/src/state/adapters.ts +8 -0
- package/src/state/context.tsx +9 -0
- package/src/state/helpers.ts +12 -0
- package/src/state/store.ts +6 -0
- package/src/state/types.ts +17 -0
- package/src/state/useExperimentState.ts +3 -0
- package/src/ui/layers/LayerStack.tsx +5 -0
- package/src/ui/properties/CurveField.tsx +4 -1
- package/src/ui/properties/EffectCard.tsx +12 -0
- package/src/ui/properties/PropertyGroup.tsx +1 -0
- package/src/ui/properties/PropertyPanel.tsx +28 -0
- package/src/undo/eventBus.ts +4 -0
- package/src/undo/undoStack.ts +11 -0
- package/src/workspace/DefaultSidebar.tsx +3 -0
- package/src/workspace/DefaultStatusBar.tsx +3 -0
- package/src/workspace/DefaultToolbar.tsx +3 -0
- package/src/workspace/Workspace.tsx +3 -0
- package/src/workspace/WorkspaceChrome.tsx +4 -0
- package/src/workspace/slotTypes.ts +9 -0
- package/src/workspace/workspaceOps.ts +8 -0
- package/dist/chunk-2QNYYL3V.js.map +0 -1
- package/dist/chunk-53XSBIUK.js.map +0 -1
- package/dist/chunk-54IQ2DX7.js.map +0 -1
- package/dist/chunk-7BKDG73Z.js.map +0 -1
- package/dist/chunk-EXBV7A6X.js.map +0 -1
- package/dist/chunk-HXZHVU4G.js.map +0 -1
- package/dist/chunk-ISEK5LXT.js.map +0 -1
- package/dist/chunk-NRD3TDNQ.js.map +0 -1
- package/dist/chunk-PWC7AQZM.js.map +0 -1
|
@@ -5,12 +5,15 @@ import { type CSSProperties, type ReactNode, useState } from 'react';
|
|
|
5
5
|
// label flanked by a horizontal rule — no background, padding, or border;
|
|
6
6
|
// purely a typographic divider. Ported from speech-balloons styles.css:277-313.
|
|
7
7
|
|
|
8
|
+
/** Props for `<Subpanel>`. */
|
|
8
9
|
export interface SubpanelProps {
|
|
9
10
|
title: ReactNode;
|
|
10
11
|
children: ReactNode;
|
|
11
12
|
className?: string;
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
/** A typographic divider inside a property list: a small title flanked by a
|
|
16
|
+
* rule. Purely a heading — use `<PropertyGroup>` for a bordered section. */
|
|
14
17
|
export function Subpanel({ title, children, className }: SubpanelProps) {
|
|
15
18
|
const cls = className ? `lk-subpanel ${className}` : 'lk-subpanel';
|
|
16
19
|
return (
|
|
@@ -29,6 +32,7 @@ export function Subpanel({ title, children, className }: SubpanelProps) {
|
|
|
29
32
|
// per-instance recolors the title bar, border-left, and (via re-binding --wzl-accent
|
|
30
33
|
// inside the card) every descendant control that reads from the accent token.
|
|
31
34
|
|
|
35
|
+
/** Props for `<EffectCard>`. */
|
|
32
36
|
export interface EffectCardProps {
|
|
33
37
|
/** Card title rendered in the title bar (e.g. effect kind label or a select). */
|
|
34
38
|
title: ReactNode;
|
|
@@ -59,6 +63,9 @@ export interface EffectCardProps {
|
|
|
59
63
|
className?: string;
|
|
60
64
|
}
|
|
61
65
|
|
|
66
|
+
/** An accented, collapsible card for one item in a list of like things —
|
|
67
|
+
* effects, layers, tails. The accent color rebinds the theme accent token
|
|
68
|
+
* within the card, so its controls pick it up too. */
|
|
62
69
|
export function EffectCard({
|
|
63
70
|
title,
|
|
64
71
|
primary,
|
|
@@ -182,10 +189,12 @@ function DragHandleIcon() {
|
|
|
182
189
|
// onReorder fires with (sourceId, targetId, position) on drop. Mirrors the
|
|
183
190
|
// LayerStack pattern from speech-balloons Lab.tsx:630-707.
|
|
184
191
|
|
|
192
|
+
/** The minimum an item must carry to appear in an `<EffectCardList>`. */
|
|
185
193
|
export interface EffectCardListItem {
|
|
186
194
|
id: string | number;
|
|
187
195
|
}
|
|
188
196
|
|
|
197
|
+
/** Props for `<EffectCardList>`. */
|
|
189
198
|
export interface EffectCardListProps<T extends EffectCardListItem> {
|
|
190
199
|
items: ReadonlyArray<T>;
|
|
191
200
|
renderItem: (
|
|
@@ -217,6 +226,9 @@ export interface EffectCardListProps<T extends EffectCardListItem> {
|
|
|
217
226
|
defaultExpandedIds?: ReadonlyArray<T['id']>;
|
|
218
227
|
}
|
|
219
228
|
|
|
229
|
+
/** A drag-reorderable list of `<EffectCard>`s. Owns the expanded and dragging
|
|
230
|
+
* state and hands it back to `renderItem`, so the caller only supplies each
|
|
231
|
+
* card's contents. */
|
|
220
232
|
export function EffectCardList<T extends EffectCardListItem>({
|
|
221
233
|
items,
|
|
222
234
|
renderItem,
|
|
@@ -2,12 +2,15 @@ import { type ReactNode, useState } from 'react';
|
|
|
2
2
|
import { dlog } from '../../passthrough/weasel-ui';
|
|
3
3
|
import { formatNumber, parseSignedNumber } from '../format';
|
|
4
4
|
|
|
5
|
+
/** Props for `<PropertyPanel>`. */
|
|
5
6
|
export interface PropertyPanelProps {
|
|
6
7
|
title?: ReactNode;
|
|
7
8
|
children: ReactNode;
|
|
8
9
|
className?: string;
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
/** A titled panel holding property rows — the sidebar container the rest of
|
|
13
|
+
* this module's components fill. */
|
|
11
14
|
export function PropertyPanel({ title, children, className }: PropertyPanelProps) {
|
|
12
15
|
const cls = className ? `lk-property-panel ${className}` : 'lk-property-panel';
|
|
13
16
|
return (
|
|
@@ -18,8 +21,10 @@ export function PropertyPanel({ title, children, className }: PropertyPanelProps
|
|
|
18
21
|
);
|
|
19
22
|
}
|
|
20
23
|
|
|
24
|
+
/** How a property list packs its rows into two columns. */
|
|
21
25
|
export type PropertyListPack = 'auto-color' | 'pairs';
|
|
22
26
|
|
|
27
|
+
/** Props for `<PropertyList>`. */
|
|
23
28
|
export interface PropertyListProps {
|
|
24
29
|
children: ReactNode;
|
|
25
30
|
className?: string;
|
|
@@ -44,9 +49,12 @@ export function PropertyList({ children, className, pack = 'auto-color' }: Prope
|
|
|
44
49
|
return <div className={cls}>{children}</div>;
|
|
45
50
|
}
|
|
46
51
|
|
|
52
|
+
/** Which control shape a row holds, which decides its intrinsic layout. */
|
|
47
53
|
export type PropertyRowVariant = 'default' | 'color' | 'checkbox';
|
|
54
|
+
/** Whether a row's label sits above its control or beside it. */
|
|
48
55
|
export type PropertyRowLayout = 'block' | 'inline';
|
|
49
56
|
|
|
57
|
+
/** Props for `<PropertyRow>`. */
|
|
50
58
|
export interface PropertyRowProps {
|
|
51
59
|
label: ReactNode;
|
|
52
60
|
/** Right-aligned readout shown next to the label (e.g. current value). */
|
|
@@ -63,6 +71,8 @@ export interface PropertyRowProps {
|
|
|
63
71
|
className?: string;
|
|
64
72
|
}
|
|
65
73
|
|
|
74
|
+
/** The label-plus-control frame every typed row below is built from. Use it
|
|
75
|
+
* directly for a control this module does not cover. */
|
|
66
76
|
export function PropertyRow({
|
|
67
77
|
label,
|
|
68
78
|
readout,
|
|
@@ -91,6 +101,7 @@ export function PropertyRow({
|
|
|
91
101
|
|
|
92
102
|
// ── Row implementations ──────────────────────────────────────────────
|
|
93
103
|
|
|
104
|
+
/** Props for `<SliderRow>`. */
|
|
94
105
|
export interface SliderRowProps {
|
|
95
106
|
label: ReactNode;
|
|
96
107
|
value: number;
|
|
@@ -109,6 +120,8 @@ export interface SliderRowProps {
|
|
|
109
120
|
layout?: PropertyRowLayout;
|
|
110
121
|
}
|
|
111
122
|
|
|
123
|
+
/** A bounded number edited by dragging, with a live readout whose precision
|
|
124
|
+
* follows `step`. */
|
|
112
125
|
export function SliderRow({
|
|
113
126
|
label,
|
|
114
127
|
value,
|
|
@@ -237,6 +250,7 @@ function EditableReadout({ value, min, max, format, unit, onCommit }: EditableRe
|
|
|
237
250
|
);
|
|
238
251
|
}
|
|
239
252
|
|
|
253
|
+
/** Props for `<ColorRow>`. */
|
|
240
254
|
export interface ColorRowProps {
|
|
241
255
|
label: ReactNode;
|
|
242
256
|
value: string;
|
|
@@ -251,6 +265,7 @@ export interface ColorRowProps {
|
|
|
251
265
|
alphaDisabled?: boolean;
|
|
252
266
|
}
|
|
253
267
|
|
|
268
|
+
/** A color swatch, optionally with an alpha slider beneath it. */
|
|
254
269
|
export function ColorRow({
|
|
255
270
|
label,
|
|
256
271
|
value,
|
|
@@ -280,12 +295,14 @@ export function ColorRow({
|
|
|
280
295
|
);
|
|
281
296
|
}
|
|
282
297
|
|
|
298
|
+
/** Props for `<CheckboxRow>`. */
|
|
283
299
|
export interface CheckboxRowProps {
|
|
284
300
|
label: ReactNode;
|
|
285
301
|
value: boolean;
|
|
286
302
|
onChange: (next: boolean) => void;
|
|
287
303
|
}
|
|
288
304
|
|
|
305
|
+
/** A boolean checkbox. */
|
|
289
306
|
export function CheckboxRow({ label, value, onChange }: CheckboxRowProps) {
|
|
290
307
|
return (
|
|
291
308
|
<PropertyRow label={label} variant="checkbox">
|
|
@@ -294,6 +311,7 @@ export function CheckboxRow({ label, value, onChange }: CheckboxRowProps) {
|
|
|
294
311
|
);
|
|
295
312
|
}
|
|
296
313
|
|
|
314
|
+
/** Props for `<TextRow>`. */
|
|
297
315
|
export interface TextRowProps {
|
|
298
316
|
label: ReactNode;
|
|
299
317
|
value: string;
|
|
@@ -303,6 +321,7 @@ export interface TextRowProps {
|
|
|
303
321
|
layout?: PropertyRowLayout;
|
|
304
322
|
}
|
|
305
323
|
|
|
324
|
+
/** A single-line text input. */
|
|
306
325
|
export function TextRow({ label, value, onChange, placeholder, maxLength, layout }: TextRowProps) {
|
|
307
326
|
return (
|
|
308
327
|
<PropertyRow label={label} layout={layout}>
|
|
@@ -317,6 +336,7 @@ export function TextRow({ label, value, onChange, placeholder, maxLength, layout
|
|
|
317
336
|
);
|
|
318
337
|
}
|
|
319
338
|
|
|
339
|
+
/** Props for `<NumberRow>`. */
|
|
320
340
|
export interface NumberRowProps {
|
|
321
341
|
label: ReactNode;
|
|
322
342
|
value: number;
|
|
@@ -328,6 +348,8 @@ export interface NumberRowProps {
|
|
|
328
348
|
layout?: PropertyRowLayout;
|
|
329
349
|
}
|
|
330
350
|
|
|
351
|
+
/** A number typed directly. Reach for `<SliderRow>` when the range matters
|
|
352
|
+
* more than the exact value. */
|
|
331
353
|
export function NumberRow({
|
|
332
354
|
label,
|
|
333
355
|
value,
|
|
@@ -363,6 +385,7 @@ export interface SelectOption<T extends string> {
|
|
|
363
385
|
label: ReactNode;
|
|
364
386
|
}
|
|
365
387
|
|
|
388
|
+
/** Props for `<SelectRow>`. */
|
|
366
389
|
export interface SelectRowProps<T extends string> {
|
|
367
390
|
label: ReactNode;
|
|
368
391
|
value: T;
|
|
@@ -371,6 +394,8 @@ export interface SelectRowProps<T extends string> {
|
|
|
371
394
|
layout?: PropertyRowLayout;
|
|
372
395
|
}
|
|
373
396
|
|
|
397
|
+
/** A dropdown over a fixed set of choices. Prefer `<ToggleRow>` when there
|
|
398
|
+
* are only two or three and they should all stay visible. */
|
|
374
399
|
export function SelectRow<T extends string>({
|
|
375
400
|
label,
|
|
376
401
|
value,
|
|
@@ -399,6 +424,7 @@ export function SelectRow<T extends string>({
|
|
|
399
424
|
);
|
|
400
425
|
}
|
|
401
426
|
|
|
427
|
+
/** Props for `<ToggleRow>`. */
|
|
402
428
|
export interface ToggleRowProps<T extends string> {
|
|
403
429
|
label: ReactNode;
|
|
404
430
|
value: T;
|
|
@@ -407,6 +433,8 @@ export interface ToggleRowProps<T extends string> {
|
|
|
407
433
|
layout?: PropertyRowLayout;
|
|
408
434
|
}
|
|
409
435
|
|
|
436
|
+
/** A segmented control: the same choice as a select, with every option
|
|
437
|
+
* visible at once. */
|
|
410
438
|
export function ToggleRow<T extends string>({
|
|
411
439
|
label,
|
|
412
440
|
value,
|
package/src/undo/eventBus.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
/** A subscriber to a named event. */
|
|
1
2
|
export type EventListener = () => void;
|
|
2
3
|
|
|
4
|
+
/** Named-event pub/sub, the channel an instrument's `emit` writes to and undo
|
|
5
|
+
* snapshotting listens on. */
|
|
3
6
|
export interface EventBus {
|
|
4
7
|
on(event: string, listener: EventListener): () => void;
|
|
5
8
|
emit(event: string): void;
|
|
6
9
|
clear(): void;
|
|
7
10
|
}
|
|
8
11
|
|
|
12
|
+
/** Build an empty event bus. */
|
|
9
13
|
export function createEventBus(): EventBus {
|
|
10
14
|
const listeners = new Map<string, Set<EventListener>>();
|
|
11
15
|
return {
|
package/src/undo/undoStack.ts
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
+
/** Undo history as two stacks of state snapshots: what has been done, and
|
|
2
|
+
* what has been undone. The present state is held elsewhere, not here. */
|
|
1
3
|
export interface UndoStack {
|
|
2
4
|
past: unknown[];
|
|
3
5
|
future: unknown[];
|
|
4
6
|
}
|
|
5
7
|
|
|
8
|
+
/** A fresh, empty history. */
|
|
6
9
|
export function emptyStack(): UndoStack {
|
|
7
10
|
return { past: [], future: [] };
|
|
8
11
|
}
|
|
9
12
|
|
|
13
|
+
/** Record a new snapshot, discarding the redo branch and the oldest entry
|
|
14
|
+
* once `maxDepth` is reached. */
|
|
10
15
|
export function pushSnapshot(stack: UndoStack, snapshot: unknown, maxDepth: number): UndoStack {
|
|
11
16
|
const past = stack.past.length >= maxDepth ? stack.past.slice(1) : stack.past.slice();
|
|
12
17
|
past.push(snapshot);
|
|
13
18
|
return { past, future: [] };
|
|
14
19
|
}
|
|
15
20
|
|
|
21
|
+
/** Step back one snapshot, returning the new history and the state to restore.
|
|
22
|
+
* `null` when there is nothing to undo. The caller supplies `current` so it
|
|
23
|
+
* can be redone. */
|
|
16
24
|
export function undo(
|
|
17
25
|
stack: UndoStack,
|
|
18
26
|
current: unknown,
|
|
@@ -23,6 +31,8 @@ export function undo(
|
|
|
23
31
|
return { stack: { past, future: [...stack.future, current] }, snapshot };
|
|
24
32
|
}
|
|
25
33
|
|
|
34
|
+
/** Step forward one snapshot, returning the new history and the state to
|
|
35
|
+
* restore. `null` when there is nothing to redo. */
|
|
26
36
|
export function redo(
|
|
27
37
|
stack: UndoStack,
|
|
28
38
|
current: unknown,
|
|
@@ -33,6 +43,7 @@ export function redo(
|
|
|
33
43
|
return { stack: { past: [...stack.past, current], future }, snapshot };
|
|
34
44
|
}
|
|
35
45
|
|
|
46
|
+
/** Discard the whole history. */
|
|
36
47
|
export function clearUndo(_stack: UndoStack): UndoStack {
|
|
37
48
|
return emptyStack();
|
|
38
49
|
}
|
|
@@ -2,10 +2,13 @@ import { ControlPanel } from '../controls/ControlPanel';
|
|
|
2
2
|
import { Sidebar } from '../primitives/Sidebar';
|
|
3
3
|
import type { WorkspaceSidebarContext } from './slotTypes';
|
|
4
4
|
|
|
5
|
+
/** Props for `<DefaultSidebar>`. */
|
|
5
6
|
export interface DefaultSidebarProps {
|
|
6
7
|
ctx: WorkspaceSidebarContext;
|
|
7
8
|
}
|
|
8
9
|
|
|
10
|
+
/** The sidebar a workspace renders when no `sidebar` slot is supplied: a
|
|
11
|
+
* control panel over the instrument's config schema. */
|
|
9
12
|
export function DefaultSidebar({ ctx }: DefaultSidebarProps) {
|
|
10
13
|
if (ctx.configFields.length === 0) {
|
|
11
14
|
return (
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { StatusBar } from '../primitives/StatusBar';
|
|
2
2
|
import type { WorkspaceStatusBarContext } from './slotTypes';
|
|
3
3
|
|
|
4
|
+
/** Props for `<DefaultStatusBar>`. */
|
|
4
5
|
export interface DefaultStatusBarProps {
|
|
5
6
|
ctx: WorkspaceStatusBarContext;
|
|
6
7
|
}
|
|
7
8
|
|
|
9
|
+
/** The status bar a workspace renders when no `statusBar` slot is supplied:
|
|
10
|
+
* the instrument's name and the current zoom. */
|
|
8
11
|
export function DefaultStatusBar({ ctx }: DefaultStatusBarProps) {
|
|
9
12
|
return (
|
|
10
13
|
<StatusBar>
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { Toolbar } from '../primitives/Toolbar';
|
|
2
2
|
import type { WorkspaceToolbarContext } from './slotTypes';
|
|
3
3
|
|
|
4
|
+
/** Props for `<DefaultToolbar>`. */
|
|
4
5
|
export interface DefaultToolbarProps {
|
|
5
6
|
ctx: WorkspaceToolbarContext;
|
|
6
7
|
}
|
|
7
8
|
|
|
9
|
+
/** The toolbar a workspace renders when no `toolbar` slot is supplied. Only
|
|
10
|
+
* shows the controls the instrument's declared capabilities support. */
|
|
8
11
|
export function DefaultToolbar({ ctx }: DefaultToolbarProps) {
|
|
9
12
|
return (
|
|
10
13
|
<Toolbar>
|
|
@@ -21,10 +21,13 @@ import { pushSnapshot, redo as undoRedo, undo as undoUndo } from '../undo/undoSt
|
|
|
21
21
|
import type { UndoBindings } from './WorkspaceChrome';
|
|
22
22
|
import { WorkspaceChrome } from './WorkspaceChrome';
|
|
23
23
|
|
|
24
|
+
/** Props for `<Workspace>`. */
|
|
24
25
|
export interface WorkspaceProps {
|
|
25
26
|
id: string;
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
/** Renders one workspace from the lab store: looks up its record and
|
|
30
|
+
* instrument, and mounts the instrument inside the workspace chrome. */
|
|
28
31
|
export function Workspace({ id }: WorkspaceProps) {
|
|
29
32
|
const lab = useLabContext();
|
|
30
33
|
const storeCtx = useContext(LabStoreContext);
|
|
@@ -23,6 +23,7 @@ export interface UndoBindings {
|
|
|
23
23
|
redo: () => void;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/** Props for `<WorkspaceChrome>`. */
|
|
26
27
|
export interface WorkspaceChromeProps {
|
|
27
28
|
workspaceId: string;
|
|
28
29
|
record: WorkspaceRecord;
|
|
@@ -36,6 +37,9 @@ export interface WorkspaceChromeProps {
|
|
|
36
37
|
children: ReactNode;
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
/** The frame around a running instrument — toolbar, sidebar, status bar —
|
|
41
|
+
* each replaceable by a slot. Assembles the slot contexts and wires the undo
|
|
42
|
+
* keyboard shortcuts. */
|
|
39
43
|
export function WorkspaceChrome({
|
|
40
44
|
workspaceId,
|
|
41
45
|
record,
|
|
@@ -2,6 +2,8 @@ import type { ReactNode } from 'react';
|
|
|
2
2
|
import type { ConfigField } from '../controls/types';
|
|
3
3
|
import type { SavedSnapshot } from '../state/types';
|
|
4
4
|
|
|
5
|
+
/** What a workspace hands its toolbar: which instrument is running, the undo
|
|
6
|
+
* state and commands, the zoom controls, and the snapshot commands. */
|
|
5
7
|
export interface WorkspaceToolbarContext {
|
|
6
8
|
workspaceId: string;
|
|
7
9
|
instrumentName: string;
|
|
@@ -25,6 +27,8 @@ export interface WorkspaceToolbarContext {
|
|
|
25
27
|
isLastWorkspace: boolean;
|
|
26
28
|
}
|
|
27
29
|
|
|
30
|
+
/** What a workspace hands its sidebar: the instrument's config schema, its
|
|
31
|
+
* current values, and the setter. */
|
|
28
32
|
export interface WorkspaceSidebarContext {
|
|
29
33
|
workspaceId: string;
|
|
30
34
|
instrumentName: string;
|
|
@@ -33,12 +37,17 @@ export interface WorkspaceSidebarContext {
|
|
|
33
37
|
setConfig: (key: string, value: unknown) => void;
|
|
34
38
|
}
|
|
35
39
|
|
|
40
|
+
/** What a workspace hands its status bar. */
|
|
36
41
|
export interface WorkspaceStatusBarContext {
|
|
37
42
|
workspaceId: string;
|
|
38
43
|
instrumentName: string;
|
|
39
44
|
zoom: number;
|
|
40
45
|
}
|
|
41
46
|
|
|
47
|
+
/** Replaces a workspace's toolbar. Receives everything the default one uses,
|
|
48
|
+
* so a custom toolbar need not reach into the store. */
|
|
42
49
|
export type ToolbarSlot = (ctx: WorkspaceToolbarContext) => ReactNode;
|
|
50
|
+
/** Replaces a workspace's sidebar. */
|
|
43
51
|
export type SidebarSlot = (ctx: WorkspaceSidebarContext) => ReactNode;
|
|
52
|
+
/** Replaces a workspace's status bar. */
|
|
44
53
|
export type StatusBarSlot = (ctx: WorkspaceStatusBarContext) => ReactNode;
|
|
@@ -17,6 +17,8 @@ function initialView(instrument: Instrument): WorkspaceRecord['view'] {
|
|
|
17
17
|
: { ...DEFAULT_VIEW, pan: { ...DEFAULT_VIEW.pan } };
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/** Append a new workspace running `instrumentName`, at that instrument's
|
|
21
|
+
* default config and initial state. */
|
|
20
22
|
export function addWorkspace(
|
|
21
23
|
workspaces: WorkspaceRecord[],
|
|
22
24
|
instruments: Instrument[],
|
|
@@ -36,6 +38,8 @@ export function addWorkspace(
|
|
|
36
38
|
return [...workspaces, record];
|
|
37
39
|
}
|
|
38
40
|
|
|
41
|
+
/** Insert a deep copy of a workspace directly after it. The copy starts with
|
|
42
|
+
* an empty undo history — the original's is not shared. */
|
|
39
43
|
export function cloneWorkspace(workspaces: WorkspaceRecord[], id: string): WorkspaceRecord[] {
|
|
40
44
|
const sourceIdx = workspaces.findIndex((w) => w.id === id);
|
|
41
45
|
const source = workspaces[sourceIdx];
|
|
@@ -51,12 +55,16 @@ export function cloneWorkspace(workspaces: WorkspaceRecord[], id: string): Works
|
|
|
51
55
|
return [...workspaces.slice(0, sourceIdx + 1), clone, ...workspaces.slice(sourceIdx + 1)];
|
|
52
56
|
}
|
|
53
57
|
|
|
58
|
+
/** Remove a workspace, unless it is the last one — a lab always has at least
|
|
59
|
+
* one. */
|
|
54
60
|
export function closeWorkspace(workspaces: WorkspaceRecord[], id: string): WorkspaceRecord[] {
|
|
55
61
|
if (workspaces.length <= 1) return workspaces;
|
|
56
62
|
const next = workspaces.filter((w) => w.id !== id);
|
|
57
63
|
return next.length === workspaces.length ? workspaces : next;
|
|
58
64
|
}
|
|
59
65
|
|
|
66
|
+
/** Return a workspace to its instrument's defaults, keeping its id and its
|
|
67
|
+
* place in the list. */
|
|
60
68
|
export function resetWorkspace(
|
|
61
69
|
workspaces: WorkspaceRecord[],
|
|
62
70
|
id: string,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/layers/LayerList.tsx"],"names":[],"mappings":";;;;AAiBO,SAAS,UAAU,EAAE,MAAA,EAAQ,YAAY,SAAA,EAAW,QAAA,EAAU,WAAU,EAAmB;AAChG,EAAA,MAAM,cAAc,MAAA,CAAO,MAAA,CAAO,CAAC,CAAA,KAAM,CAAC,EAAE,QAAQ,CAAA;AACpD,EAAA,MAAM,SAAS,MAAA,CAAO,MAAA,CAAO,CAAC,CAAA,KAAM,EAAE,QAAQ,CAAA;AAC9C,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAA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H,CAAA;AAEJ","file":"chunk-2QNYYL3V.js","sourcesContent":["import { type PointerEvent, useRef, useState } from 'react';\nimport type { LayerDescriptor } from '../instrument/types';\n\nexport interface LayerListProps {\n layers: LayerDescriptor[];\n visibility: Record<string, boolean>;\n onReorder: (newOrder: LayerDescriptor[]) => void;\n onToggle: (id: string, visible: boolean) => void;\n className?: string;\n}\n\ninterface DragState {\n pointerId: number;\n fromIndex: number;\n startY: number;\n}\n\nexport function LayerList({ layers, visibility, onReorder, onToggle, className }: LayerListProps) {\n const reorderable = layers.filter((l) => !l.alwaysOn);\n const pinned = layers.filter((l) => l.alwaysOn);\n const [dragIndex, setDragIndex] = useState<number | null>(null);\n const dragRef = useRef<DragState | null>(null);\n\n if (layers.length === 0) {\n return (\n <div className={className ? `lk-layer-list ${className}` : 'lk-layer-list'}>\n <div className=\"lk-layer-list__empty\">No layers</div>\n </div>\n );\n }\n\n const startDrag = (e: PointerEvent<HTMLElement>, index: number) => {\n e.currentTarget.setPointerCapture(e.pointerId);\n dragRef.current = { pointerId: e.pointerId, fromIndex: index, startY: e.clientY };\n setDragIndex(index);\n };\n\n const moveDrag = (e: PointerEvent<HTMLElement>) => {\n const drag = dragRef.current;\n if (!drag || drag.pointerId !== e.pointerId) return;\n const rowHeight = 28;\n const delta = Math.round((e.clientY - drag.startY) / rowHeight);\n const target = Math.min(reorderable.length - 1, Math.max(0, drag.fromIndex + delta));\n setDragIndex(target);\n };\n\n const endDrag = (e: PointerEvent<HTMLElement>) => {\n const drag = dragRef.current;\n if (!drag || drag.pointerId !== e.pointerId) return;\n if (e.currentTarget.hasPointerCapture(e.pointerId)) {\n e.currentTarget.releasePointerCapture(e.pointerId);\n }\n if (dragIndex !== null && dragIndex !== drag.fromIndex) {\n const next = [...reorderable];\n const [moved] = next.splice(drag.fromIndex, 1);\n if (moved) next.splice(dragIndex, 0, moved);\n onReorder([...next, ...pinned]);\n }\n dragRef.current = null;\n setDragIndex(null);\n };\n\n return (\n <div className={className ? `lk-layer-list ${className}` : 'lk-layer-list'}>\n {reorderable.map((layer, i) => {\n const isDragging = dragIndex === i;\n return (\n <div\n key={layer.id}\n className={\n isDragging ? 'lk-layer-list__row lk-layer-list__row--dragging' : 'lk-layer-list__row'\n }\n >\n <button\n type=\"button\"\n className=\"lk-layer-list__handle\"\n aria-label={`Reorder ${layer.label}`}\n onPointerDown={(e) => startDrag(e, i)}\n onPointerMove={moveDrag}\n onPointerUp={endDrag}\n >\n ⋮⋮\n </button>\n <input\n className=\"lk-layer-list__check\"\n type=\"checkbox\"\n checked={visibility[layer.id] !== false}\n onChange={(e) => onToggle(layer.id, e.target.checked)}\n aria-label={`Toggle ${layer.label}`}\n />\n <span className=\"lk-layer-list__label\">{layer.label}</span>\n </div>\n );\n })}\n {pinned.map((layer) => (\n <div key={layer.id} className=\"lk-layer-list__row lk-layer-list__row--pinned\">\n <span className=\"lk-layer-list__lock\" role=\"img\" aria-label=\"Always on\">\n 🔒\n </span>\n <span className=\"lk-layer-list__label\">{layer.label}</span>\n </div>\n ))}\n </div>\n );\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/state/helpers.ts","../src/state/adapters.ts","../src/state/context.tsx","../src/state/store.ts","../src/state/useExperimentState.ts"],"names":["useContext","useStore"],"mappings":";;;;;;AAEO,SAAS,aAAA,CACd,YACA,MAAA,EACQ;AACR,EAAA,OAAO,CAAA,GAAA,EAAM,UAAU,CAAA,CAAA,EAAI,MAAM,CAAA,CAAA;AACnC;AAEO,SAAS,cAAc,KAAA,EAAuB;AACnD,EAAA,OAAO,IAAA,CAAK,kBAAA,CAAmB,KAAK,CAAC,CAAA;AACvC;AAEO,SAAS,cAAc,IAAA,EAA6B;AACzD,EAAA,IAAI,CAAC,MAAM,OAAO,IAAA;AAClB,EAAA,IAAI;AACF,IAAA,OAAO,kBAAA,CAAmB,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,EACtC,CAAA,CAAA,MAAQ;AACN,IAAA,OA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GAAA,EAAK,UAAU,qBAAA,CAAsB,WAAA,EAAa,KAAc,KAAc;AAAA,GAC5F;AACF","file":"chunk-53XSBIUK.js","sourcesContent":["import type { InstrumentSerializers, UndoStack, WorkspaceRecord } from './types';\n\nexport function labStorageKey(\n storageKey: string,\n bucket: 'workspaces' | 'saves' | 'theme',\n): string {\n return `lk:${storageKey}:${bucket}`;\n}\n\nexport function encodeUrlHash(value: string): string {\n return btoa(encodeURIComponent(value));\n}\n\nexport function decodeUrlHash(hash: string): string | null {\n if (!hash) return null;\n try {\n return decodeURIComponent(atob(hash));\n } catch {\n return null;\n }\n}\n\nexport function emptyUndoStack(): UndoStack {\n return { past: [], future: [] };\n}\n\ntype SerializedRecord = Omit<WorkspaceRecord, 'undoStack'>;\n\nexport function serializeWorkspaces(\n workspaces: WorkspaceRecord[],\n serializers: InstrumentSerializers,\n): string {\n const records: SerializedRecord[] = workspaces.map(({ undoStack: _undo, ...w }) => {\n const s = serializers[w.instrumentName];\n return {\n ...w,\n state: s?.serialize ? s.serialize(w.state) : w.state,\n };\n });\n return JSON.stringify(records);\n}\n\nexport function deserializeWorkspaces(\n raw: string,\n deserializers: InstrumentSerializers,\n): WorkspaceRecord[] {\n try {\n const records = JSON.parse(raw) as SerializedRecord[];\n return records.map((r) => {\n const d = deserializers[r.instrumentName];\n return {\n ...r,\n state: d?.deserialize ? d.deserialize(r.state) : r.state,\n undoStack: emptyUndoStack(),\n };\n });\n } catch {\n console.warn('[labkit] deserializeWorkspaces: failed to parse, returning empty list');\n return [];\n }\n}\n","import { decodeUrlHash, encodeUrlHash } from './helpers';\nimport type { StorageAdapter } from './types';\n\nexport const localStorageAdapter: StorageAdapter = {\n read: (key) => {\n try {\n return localStorage.getItem(key);\n } catch {\n return null;\n }\n },\n write: (key, value) => {\n try {\n localStorage.setItem(key, value);\n } catch (e) {\n console.warn('[labkit] localStorage write failed:', e);\n }\n },\n delete: (key) => {\n try {\n localStorage.removeItem(key);\n } catch {\n /* ignore */\n }\n },\n};\n\nexport const sessionStorageAdapter: StorageAdapter = {\n read: (key) => {\n try {\n return sessionStorage.getItem(key);\n } catch {\n return null;\n }\n },\n write: (key, value) => {\n try {\n sessionStorage.setItem(key, value);\n } catch (e) {\n console.warn('[labkit] sessionStorage write failed:', e);\n }\n },\n delete: (key) => {\n try {\n sessionStorage.removeItem(key);\n } catch {\n /* ignore */\n }\n },\n};\n\nconst URL_HASH_GUARD = typeof window !== 'undefined';\n\nfunction readHashMap(): Record<string, string> {\n if (!URL_HASH_GUARD) return {};\n const raw = decodeUrlHash(window.location.hash.replace(/^#/, ''));\n if (!raw) return {};\n try {\n return JSON.parse(raw) as Record<string, string>;\n } catch {\n return {};\n }\n}\n\nfunction writeHashMap(map: Record<string, string>): void {\n if (!URL_HASH_GUARD) return;\n const encoded = encodeUrlHash(JSON.stringify(map));\n window.history.replaceState(null, '', `#${encoded}`);\n}\n\nexport const urlHashAdapter: StorageAdapter = {\n read: (key) => readHashMap()[key] ?? null,\n write: (key, value) => {\n const map = readHashMap();\n map[key] = value;\n writeHashMap(map);\n },\n delete: (key) => {\n const map = readHashMap();\n delete map[key];\n writeHashMap(map);\n },\n};\n\nexport function createMemoryAdapter(): StorageAdapter {\n const store = new Map<string, string>();\n return {\n read: (key) => store.get(key) ?? null,\n write: (key, value) => {\n store.set(key, value);\n },\n delete: (key) => {\n store.delete(key);\n },\n };\n}\n\nexport const noneAdapter: StorageAdapter = {\n read: () => null,\n write: () => {},\n delete: () => {},\n};\n","import { createContext, type ReactElement, type ReactNode, useContext } from 'react';\nimport { useStore } from 'zustand/react';\nimport type { LabStore } from './store';\nimport type { LabStoreState } from './types';\n\ntype LabStoreCtx = { store: LabStore } | null;\n\nexport const LabStoreContext = createContext<LabStoreCtx>(null);\n\nexport function LabStoreProvider({\n store,\n children,\n}: {\n store: LabStore;\n children: ReactNode;\n}): ReactElement {\n return <LabStoreContext.Provider value={{ store }}>{children}</LabStoreContext.Provider>;\n}\n\nexport function useLabStore(): LabStoreState & ReturnType<LabStore['getState']> {\n const ctx = useContext(LabStoreContext);\n if (!ctx) throw new Error('[labkit] useLabStore must be used inside <LabStoreProvider>');\n return useStore(ctx.store);\n}\n\nexport const WorkspaceIdContext = createContext<string | null>(null);\n\nexport function WorkspaceIdProvider({\n workspaceId,\n children,\n}: {\n workspaceId: string;\n children: ReactNode;\n}): ReactElement {\n return <WorkspaceIdContext.Provider value={workspaceId}>{children}</WorkspaceIdContext.Provider>;\n}\n\nexport function useWorkspaceId(): string {\n const id = useContext(WorkspaceIdContext);\n if (!id) throw new Error('[labkit] useWorkspaceId must be used inside <WorkspaceIdProvider>');\n return id;\n}\n","import { createStore, type StoreApi } from 'zustand/vanilla';\nimport {\n deserializeWorkspaces,\n emptyUndoStack,\n labStorageKey,\n serializeWorkspaces,\n} from './helpers';\nimport type {\n CreateLabStoreOptions,\n InstrumentSerializers,\n LabMode,\n LabStoreState,\n SavedSnapshot,\n WorkspaceRecord,\n} from './types';\n\nexport interface LabStoreActions {\n addWorkspace: (record: Omit<WorkspaceRecord, 'undoStack'>) => void;\n removeWorkspace: (id: string) => void;\n updateWorkspaceState: <TS>(id: string, next: TS | ((prev: TS) => TS)) => void;\n updateWorkspaceConfig: <TC>(id: string, key: keyof TC, value: TC[keyof TC]) => void;\n updateWorkspaceView: (id: string, view: WorkspaceRecord['view']) => void;\n updateWorkspaceUndoStack: (\n id: string,\n next:\n | WorkspaceRecord['undoStack']\n | ((prev: WorkspaceRecord['undoStack']) => WorkspaceRecord['undoStack']),\n ) => void;\n setWorkspaceInstrument: (id: string, instrumentName: string) => void;\n saveSnapshot: (workspaceId: string, name: string) => void;\n loadSnapshot: (snapshotId: string, workspaceId: string) => void;\n deleteSnapshot: (snapshotId: string) => void;\n listSnapshots: (workspaceId?: string) => SavedSnapshot[];\n setMode: (mode: LabMode) => void;\n}\n\nexport type LabStore = StoreApi<LabStoreState & LabStoreActions> & {\n registerSerializers: (s: InstrumentSerializers) => void;\n};\n\nexport function createLabStore(options: CreateLabStoreOptions): LabStore {\n let serializers: InstrumentSerializers = {};\n let flushTimer: ReturnType<typeof setTimeout> | null = null;\n\n const workspacesRaw = options.storage.read(labStorageKey(options.storageKey, 'workspaces'));\n let hydratedWorkspaces: WorkspaceRecord[] = [];\n if (workspacesRaw) {\n hydratedWorkspaces = deserializeWorkspaces(workspacesRaw, serializers);\n }\n\n const savesRaw = options.storage.read(labStorageKey(options.storageKey, 'saves'));\n let hydratedSnapshots: SavedSnapshot[] = [];\n if (savesRaw) {\n try {\n hydratedSnapshots = JSON.parse(savesRaw) as SavedSnapshot[];\n } catch {\n console.warn('[labkit] failed to parse saved snapshots, starting empty');\n hydratedSnapshots = [];\n }\n }\n\n const modeRaw = options.storage.read(labStorageKey(options.storageKey, 'theme'));\n // `interstellar` was the dark mode's name back when it was a theme.\n const stored = modeRaw === 'interstellar' ? 'dark' : modeRaw;\n let hydratedMode: LabMode;\n if (stored === 'light' || stored === 'dark' || stored === 'auto') {\n hydratedMode = stored;\n } else {\n hydratedMode = options.initialMode ?? 'auto';\n }\n\n const store = createStore<LabStoreState & LabStoreActions>()((set, get) => ({\n workspaces: hydratedWorkspaces,\n savedSnapshots: hydratedSnapshots,\n mode: hydratedMode,\n\n addWorkspace: (record) => {\n set((s) => ({\n workspaces: [...s.workspaces, { ...record, undoStack: emptyUndoStack() }],\n }));\n scheduleFlush();\n },\n\n removeWorkspace: (id) => {\n set((s) => ({ workspaces: s.workspaces.filter((w) => w.id !== id) }));\n scheduleFlush();\n },\n\n updateWorkspaceState: (id, next) => {\n set((s) => ({\n workspaces: s.workspaces.map((w) => {\n if (w.id !== id) return w;\n const nextState =\n typeof next === 'function' ? (next as (prev: unknown) => unknown)(w.state) : next;\n return { ...w, state: nextState };\n }),\n }));\n scheduleFlush();\n },\n\n updateWorkspaceConfig: (id, key, value) => {\n set((s) => ({\n workspaces: s.workspaces.map((w) => {\n if (w.id !== id) return w;\n return {\n ...w,\n config: { ...(w.config as Record<string, unknown>), [key as string]: value },\n };\n }),\n }));\n scheduleFlush();\n },\n\n updateWorkspaceView: (id, view) => {\n set((s) => ({\n workspaces: s.workspaces.map((w) => (w.id === id ? { ...w, view } : w)),\n }));\n scheduleFlush();\n },\n\n updateWorkspaceUndoStack: (id, next) => {\n set((s) => ({\n workspaces: s.workspaces.map((w) => {\n if (w.id !== id) return w;\n const undoStack =\n typeof next === 'function'\n ? (next as (prev: WorkspaceRecord['undoStack']) => WorkspaceRecord['undoStack'])(\n w.undoStack,\n )\n : next;\n return { ...w, undoStack };\n }),\n }));\n },\n\n setWorkspaceInstrument: (id, instrumentName) => {\n set((s) => ({\n workspaces: s.workspaces.map((w) => (w.id === id ? { ...w, instrumentName } : w)),\n }));\n scheduleFlush();\n },\n\n saveSnapshot: (workspaceId, name) => {\n const workspace = get().workspaces.find((w) => w.id === workspaceId);\n if (!workspace) return;\n const reg = serializers[workspace.instrumentName];\n const serializedState = reg?.serialize\n ? reg.serialize(workspace.state)\n : structuredClone(workspace.state);\n const clonedConfig = structuredClone(workspace.config);\n const lastAt = get().savedSnapshots.reduce((m, sn) => (sn.savedAt > m ? sn.savedAt : m), 0);\n const savedAt = Math.max(Date.now(), lastAt + 1);\n const snapshot: SavedSnapshot = {\n id: crypto.randomUUID(),\n name,\n workspaceId,\n instrumentName: workspace.instrumentName,\n config: clonedConfig,\n state: serializedState,\n savedAt,\n };\n set((s) => ({ savedSnapshots: [...s.savedSnapshots, snapshot] }));\n scheduleFlush();\n },\n\n loadSnapshot: (snapshotId, workspaceId) => {\n const snapshot = get().savedSnapshots.find((sn) => sn.id === snapshotId);\n if (!snapshot) return;\n const workspace = get().workspaces.find((w) => w.id === workspaceId);\n if (!workspace) return;\n if (snapshot.instrumentName !== workspace.instrumentName) {\n console.warn(\n `[labkit] loadSnapshot: instrument mismatch (snapshot=${snapshot.instrumentName}, workspace=${workspace.instrumentName}); refusing to load`,\n );\n return;\n }\n const reg = serializers[snapshot.instrumentName];\n const restoredState = reg?.deserialize ? reg.deserialize(snapshot.state) : snapshot.state;\n set((s) => ({\n workspaces: s.workspaces.map((w) =>\n w.id === workspaceId ? { ...w, state: restoredState, config: snapshot.config } : w,\n ),\n }));\n scheduleFlush();\n },\n\n deleteSnapshot: (snapshotId) => {\n set((s) => ({\n savedSnapshots: s.savedSnapshots.filter((sn) => sn.id !== snapshotId),\n }));\n scheduleFlush();\n },\n\n listSnapshots: (workspaceId) => {\n const all = get().savedSnapshots;\n const filtered = workspaceId ? all.filter((sn) => sn.workspaceId === workspaceId) : all;\n return [...filtered].sort((a, b) => b.savedAt - a.savedAt);\n },\n\n setMode: (mode) => {\n set({ mode });\n scheduleFlush();\n },\n }));\n\n function scheduleFlush(): void {\n if (flushTimer) clearTimeout(flushTimer);\n flushTimer = setTimeout(() => {\n const s = store.getState();\n options.storage.write(\n labStorageKey(options.storageKey, 'workspaces'),\n serializeWorkspaces(s.workspaces, serializers),\n );\n options.storage.write(\n labStorageKey(options.storageKey, 'saves'),\n JSON.stringify(s.savedSnapshots),\n );\n options.storage.write(labStorageKey(options.storageKey, 'theme'), s.mode);\n flushTimer = null;\n }, 300);\n }\n\n return Object.assign(store, {\n registerSerializers(s: InstrumentSerializers) {\n serializers = s;\n },\n });\n}\n","import { useContext } from 'react';\nimport { useStore } from 'zustand/react';\nimport { LabStoreContext, WorkspaceIdContext } from './context';\nimport type { ExperimentStateHandle } from './types';\n\nexport function useExperimentState<TS = unknown, TC = unknown>(): ExperimentStateHandle<TS, TC> {\n const ctx = useContext(LabStoreContext);\n if (!ctx) throw new Error('[labkit] useExperimentState must be used inside <LabStoreProvider>');\n\n const workspaceId = useContext(WorkspaceIdContext);\n if (!workspaceId)\n throw new Error('[labkit] useExperimentState must be used inside <WorkspaceIdProvider>');\n\n const record = useStore(ctx.store, (s) => s.workspaces.find((w) => w.id === workspaceId));\n\n if (!record) throw new Error(`[labkit] No workspace found with id \"${workspaceId}\"`);\n\n const updateWorkspaceState = useStore(ctx.store, (s) => s.updateWorkspaceState);\n const updateWorkspaceConfig = useStore(ctx.store, (s) => s.updateWorkspaceConfig);\n\n return {\n state: record.state as TS,\n config: record.config as TC,\n setState: (next) =>\n updateWorkspaceState(workspaceId, next as Parameters<typeof updateWorkspaceState>[1]),\n setConfig: (key, value) => updateWorkspaceConfig(workspaceId, key as never, value as never),\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/canvas/canvasCoords.ts","../src/canvas/useLayerScheduler.ts","../src/canvas/usePanZoom.ts","../src/canvas/CanvasStack.tsx"],"names":["useRef","useEffect"],"mappings":";;;;;AAEO,SAAS,aAAA,CAAc,OAAc,IAAA,EAA4B;AACtE,EAAA,OAAO;AAAA,IACL,GAAG,KAAA,CAAM,CAAA,GAAI,IAAA,CAAK,IAAA,GAAO,KAAK,GAAA,CAAI,CAAA;AAAA,IAClC,GAAG,KAAA,CAAM,CAAA,GAAI,IAAA,CAAK,IAAA,GAAO,KAAK,GAAA,CAAI;AAAA,GACpC;AACF;AAEO,SAAS,aAAA,CAAc,QAAe,IAAA,EAA4B;AACvE,EAAA,OAAO;AAAA,IACL,IAAI,MAAA,CAAO,CAAA,GAAI,IAAA,CAAK,GAAA,CAAI,KAAK,IAAA,CAAK,IAAA;AAAA,IAClC,IAAI,MAAA,CAAO,CAAA,GAAI,IAAA,CAAK,GAAA,CAAI,KAAK,IAAA,CAAK;AAAA,GACpC;AACF;ACEO,SAAS,kBAAkB,EAAE,MAAA,EAAQ,IAAA,EAAM,UAAA,EAAY,MAAK,EAA2B;AAC5F,EAAA,MAAM,KAAA,GAAQ,MAAA,iBAAoB,IAAI,GAAA,EAAK,CAAA;AAC3C,EAAA,MAAM,KAAA,GAAQ,OAAsB,IAAI,CAAA;AACxC,EAAA,MAAM,aAAA,GAAgB,MAAA,iBAAqD,IAAI,GAAA,EAAK,CAAA;AAEpF,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,KAAA,MAAW,SAAS,MAAA,EAAQ;AAC1B,MAAA,MAAM,IAAA,GAAO,aA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MACxB,WAAA,EAAa,eAAA;AAAA,MAEZ,QAAA,EAAA;AAAA,QAAA,MAAA,CAAO,GAAA,CAAI,CAAC,KAAA,qBACX,GAAA;AAAA,UAAC,QAAA;AAAA,UAAA;AAAA,YAEC,KAAK,CAAC,EAAA,KAAO,YAAA,CAAa,KAAA,CAAM,IAAI,EAAE,CAAA;AAAA,YACtC,SAAA,EAAU,yBAAA;AAAA,YACV,OAAO,QAAA,CAAS,KAAA;AAAA,YAChB,QAAQ,QAAA,CAAS,MAAA;AAAA,YACjB,KAAA,EAAO,EAAE,GAAG,SAAA,EAAW,SAAS,KAAA,CAAM,OAAA,GAAU,UAAU,MAAA;AAAO,WAAA;AAAA,UAL5D,KAAA,CAAM;AAAA,SAOd,CAAA;AAAA,wBACD,GAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAU,0BAAA,EAA4B,QAAA,EAAS;AAAA;AAAA;AAAA,GACtD,EACF,CAAA;AAEJ","file":"chunk-54IQ2DX7.js","sourcesContent":["import type { Point, ViewTransform } from '../instrument/types';\n\nexport function worldToScreen(world: Point, view: ViewTransform): Point {\n return {\n x: world.x * view.zoom + view.pan.x,\n y: world.y * view.zoom + view.pan.y,\n };\n}\n\nexport function screenToWorld(screen: Point, view: ViewTransform): Point {\n return {\n x: (screen.x - view.pan.x) / view.zoom,\n y: (screen.y - view.pan.y) / view.zoom,\n };\n}\n","import { type RefObject, useEffect, useRef } from 'react';\nimport type { ViewTransform } from '../instrument/types';\n\nexport interface CanvasLayerDescriptor {\n id: string;\n visible: boolean;\n render: (ctx: CanvasRenderingContext2D, view: ViewTransform) => void;\n}\n\ninterface SchedulerOptions {\n layers: CanvasLayerDescriptor[];\n view: ViewTransform;\n canvasRefs: RefObject<Map<string, HTMLCanvasElement>>;\n size: { width: number; height: number; dpr: number };\n}\n\nexport function useLayerScheduler({ layers, view, canvasRefs, size }: SchedulerOptions): void {\n const dirty = useRef<Set<string>>(new Set());\n const rafId = useRef<number | null>(null);\n const lastRenderRef = useRef<Map<string, CanvasLayerDescriptor['render']>>(new Map());\n\n useEffect(() => {\n for (const layer of layers) {\n const prev = lastRenderRef.current.get(layer.id);\n if (prev !== layer.render) dirty.current.add(layer.id);\n lastRenderRef.current.set(layer.id, layer.render);\n }\n for (const id of [...lastRenderRef.current.keys()]) {\n if (!layers.find((l) => l.id === id)) lastRenderRef.current.delete(id);\n }\n }, [layers]);\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: re-mark dirty when view or size changes\n useEffect(() => {\n for (const layer of layers) dirty.current.add(layer.id);\n }, [view, size, layers]);\n\n useEffect(() => {\n const tick = () => {\n rafId.current = null;\n if (dirty.current.size === 0) return;\n const map = canvasRefs.current;\n if (!map) {\n dirty.current.clear();\n return;\n }\n for (const layer of layers) {\n if (!dirty.current.has(layer.id)) continue;\n if (!layer.visible) continue;\n const canvas = map.get(layer.id);\n if (!canvas) continue;\n const ctx = canvas.getContext('2d');\n if (!ctx) continue;\n ctx.save();\n ctx.setTransform(size.dpr, 0, 0, size.dpr, 0, 0);\n ctx.clearRect(0, 0, size.width, size.height);\n layer.render(ctx, view);\n ctx.restore();\n }\n dirty.current.clear();\n };\n if (dirty.current.size > 0 && rafId.current === null) {\n rafId.current = requestAnimationFrame(tick);\n }\n return () => {\n if (rafId.current !== null) {\n cancelAnimationFrame(rafId.current);\n rafId.current = null;\n }\n };\n });\n}\n","import { type PointerEvent, useCallback, useRef, type WheelEvent } from 'react';\nimport type { ViewTransform } from '../instrument/types';\n\nexport interface UsePanZoomOptions {\n view: ViewTransform;\n onViewChange: (v: ViewTransform) => void;\n minZoom?: number;\n maxZoom?: number;\n}\n\nexport interface PanZoomHandlers {\n onWheel: (e: WheelEvent<HTMLElement>) => void;\n onPointerDown: (e: PointerEvent<HTMLElement>) => void;\n onPointerMove: (e: PointerEvent<HTMLElement>) => void;\n onPointerUp: (e: PointerEvent<HTMLElement>) => void;\n isDragging: () => boolean;\n}\n\ninterface DragState {\n pointerId: number;\n startScreenX: number;\n startScreenY: number;\n startPan: { x: number; y: number };\n moved: boolean;\n}\n\nconst DRAG_THRESHOLD = 3;\n\nexport function usePanZoom({\n view,\n onViewChange,\n minZoom = 0.1,\n maxZoom = 32,\n}: UsePanZoomOptions): PanZoomHandlers {\n const dragRef = useRef<DragState | null>(null);\n const viewRef = useRef(view);\n viewRef.current = view;\n\n const onWheel = useCallback(\n (e: WheelEvent<HTMLElement>) => {\n e.preventDefault();\n const rect = e.currentTarget.getBoundingClientRect();\n const cursorX = e.clientX - rect.left;\n const cursorY = e.clientY - rect.top;\n const v = viewRef.current;\n const factor = Math.exp(-e.deltaY * 0.001);\n const nextZoom = Math.min(maxZoom, Math.max(minZoom, v.zoom * factor));\n const ratio = nextZoom / v.zoom;\n const nextPan = {\n x: cursorX - (cursorX - v.pan.x) * ratio,\n y: cursorY - (cursorY - v.pan.y) * ratio,\n };\n onViewChange({ zoom: nextZoom, pan: nextPan });\n },\n [onViewChange, minZoom, maxZoom],\n );\n\n const onPointerDown = useCallback((e: PointerEvent<HTMLElement>) => {\n if (e.button !== 0) return;\n e.currentTarget.setPointerCapture(e.pointerId);\n dragRef.current = {\n pointerId: e.pointerId,\n startScreenX: e.clientX,\n startScreenY: e.clientY,\n startPan: { ...viewRef.current.pan },\n moved: false,\n };\n }, []);\n\n const onPointerMove = useCallback(\n (e: PointerEvent<HTMLElement>) => {\n const drag = dragRef.current;\n if (!drag || drag.pointerId !== e.pointerId) return;\n const dx = e.clientX - drag.startScreenX;\n const dy = e.clientY - drag.startScreenY;\n if (!drag.moved && Math.hypot(dx, dy) < DRAG_THRESHOLD) return;\n drag.moved = true;\n onViewChange({\n zoom: viewRef.current.zoom,\n pan: { x: drag.startPan.x + dx, y: drag.startPan.y + dy },\n });\n },\n [onViewChange],\n );\n\n const onPointerUp = useCallback((e: PointerEvent<HTMLElement>) => {\n const drag = dragRef.current;\n if (!drag || drag.pointerId !== e.pointerId) return;\n if (e.currentTarget.hasPointerCapture(e.pointerId)) {\n e.currentTarget.releasePointerCapture(e.pointerId);\n }\n dragRef.current = null;\n }, []);\n\n const isDragging = useCallback(() => dragRef.current?.moved === true, []);\n\n return { onWheel, onPointerDown, onPointerMove, onPointerUp, isDragging };\n}\n","import { type CSSProperties, type ReactNode, useEffect, useMemo, useRef, useState } from 'react';\nimport type { Point, ViewTransform } from '../instrument/types';\nimport { CanvasStackContext } from './CanvasStackContext';\nimport { screenToWorld } from './canvasCoords';\nimport { type CanvasLayerDescriptor, useLayerScheduler } from './useLayerScheduler';\nimport { usePanZoom } from './usePanZoom';\n\nexport interface CanvasStackProps {\n layers: CanvasLayerDescriptor[];\n view: ViewTransform;\n onViewChange: (v: ViewTransform) => void;\n width?: number | string;\n height?: number | string;\n className?: string;\n onHitTest?: (worldPos: Point) => void;\n children?: ReactNode;\n}\n\nexport function CanvasStack({\n layers,\n view,\n onViewChange,\n width = '100%',\n height = '100%',\n className,\n onHitTest,\n children,\n}: CanvasStackProps) {\n const containerRef = useRef<HTMLDivElement | null>(null);\n const canvasMap = useRef<Map<string, HTMLCanvasElement>>(new Map());\n const [size, setSize] = useState({ width: 0, height: 0, dpr: 1 });\n\n const setCanvasRef = (id: string, el: HTMLCanvasElement | null): void => {\n if (el) canvasMap.current.set(id, el);\n else canvasMap.current.delete(id);\n };\n\n useEffect(() => {\n const el = containerRef.current;\n if (!el) return;\n const update = () => {\n const rect = el.getBoundingClientRect();\n const dpr = window.devicePixelRatio ?? 1;\n setSize((prev) => {\n if (prev.width === rect.width && prev.height === rect.height && prev.dpr === dpr) {\n return prev;\n }\n return { width: rect.width, height: rect.height, dpr };\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 }, []);\n\n const handlers = usePanZoom({ view, onViewChange });\n useLayerScheduler({ layers, view, canvasRefs: canvasMap, size });\n\n const ctxValue = useMemo(() => ({ view }), [view]);\n\n const containerStyle: CSSProperties = { width, height };\n const canvasPx = {\n width: Math.max(0, Math.round(size.width * size.dpr)),\n height: Math.max(0, Math.round(size.height * size.dpr)),\n };\n const canvasCss: CSSProperties = {\n width: size.width,\n height: size.height,\n };\n\n const handlePointerUp = (e: React.PointerEvent<HTMLDivElement>) => {\n const wasDragging = handlers.isDragging();\n handlers.onPointerUp(e);\n if (!wasDragging && onHitTest && containerRef.current) {\n const rect = containerRef.current.getBoundingClientRect();\n const screen = { x: e.clientX - rect.left, y: e.clientY - rect.top };\n onHitTest(screenToWorld(screen, view));\n }\n };\n\n return (\n <CanvasStackContext.Provider value={ctxValue}>\n <div\n ref={containerRef}\n className={className ? `lk-canvas-stack ${className}` : 'lk-canvas-stack'}\n style={containerStyle}\n onWheel={handlers.onWheel}\n onPointerDown={handlers.onPointerDown}\n onPointerMove={handlers.onPointerMove}\n onPointerUp={handlePointerUp}\n >\n {layers.map((layer) => (\n <canvas\n key={layer.id}\n ref={(el) => setCanvasRef(layer.id, el)}\n className=\"lk-canvas-stack__canvas\"\n width={canvasPx.width}\n height={canvasPx.height}\n style={{ ...canvasCss, display: layer.visible ? 'block' : 'none' }}\n />\n ))}\n <div className=\"lk-canvas-stack__overlay\">{children}</div>\n </div>\n </CanvasStackContext.Provider>\n );\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/undo/eventBus.ts","../src/undo/undoStack.ts"],"names":[],"mappings":";AAQO,SAAS,cAAA,GAA2B;AACzC,EAAA,MAAM,SAAA,uBAAgB,GAAA,EAAgC;AACtD,EAAA,OAAO;AAAA,IACL,EAAA,CAAG,OAAO,QAAA,EAAU;AAClB,MAAA,IAAI,GAAA,GAAM,SAAA,CAAU,GAAA,CAAI,KAAK,CAAA;AAC7B,MAAA,IAAI,CAAC,GAAA,EAAK;AACR,QAAA,GAAA,uBAAU,GAAA,EAAI;AACd,QAAA,SAAA,CAAU,GAAA,CAAI,OAAO,GAAG,CAAA;AAAA,MAC1B;AACA,MAAA,GAAA,CAAI,IAAI,QAAQ,CAAA;AAChB,MA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E;AAEO,SAAS,IAAA,CACd,OACA,OAAA,EACgD;AAChD,EAAA,IAAI,KAAA,CAAM,MAAA,CAAO,MAAA,KAAW,CAAA,EAAG,OAAO,IAAA;AACtC,EAAA,MAAM,MAAA,GAAS,KAAA,CAAM,MAAA,CAAO,KAAA,EAAM;AAClC,EAAA,MAAM,QAAA,GAAW,OAAO,GAAA,EAAI;AAC5B,EAAA,OAAO,EAAE,KAAA,EAAO,EAAE,IAAA,EAAM,CAAC,GAAG,KAAA,CAAM,IAAA,EAAM,OAAO,CAAA,EAAG,MAAA,EAAO,EAAG,QAAA,EAAS;AACvE;AAEO,SAAS,UAAU,MAAA,EAA8B;AACtD,EAAA,OAAO,UAAA,EAAW;AACpB","file":"chunk-7BKDG73Z.js","sourcesContent":["export type EventListener = () => void;\n\nexport interface EventBus {\n on(event: string, listener: EventListener): () => void;\n emit(event: string): void;\n clear(): void;\n}\n\nexport function createEventBus(): EventBus {\n const listeners = new Map<string, Set<EventListener>>();\n return {\n on(event, listener) {\n let set = listeners.get(event);\n if (!set) {\n set = new Set();\n listeners.set(event, set);\n }\n set.add(listener);\n return () => {\n set?.delete(listener);\n };\n },\n emit(event) {\n const set = listeners.get(event);\n if (!set) return;\n for (const fn of [...set]) fn();\n },\n clear() {\n listeners.clear();\n },\n };\n}\n","export interface UndoStack {\n past: unknown[];\n future: unknown[];\n}\n\nexport function emptyStack(): UndoStack {\n return { past: [], future: [] };\n}\n\nexport function pushSnapshot(stack: UndoStack, snapshot: unknown, maxDepth: number): UndoStack {\n const past = stack.past.length >= maxDepth ? stack.past.slice(1) : stack.past.slice();\n past.push(snapshot);\n return { past, future: [] };\n}\n\nexport function undo(\n stack: UndoStack,\n current: unknown,\n): { stack: UndoStack; snapshot: unknown } | null {\n if (stack.past.length === 0) return null;\n const past = stack.past.slice();\n const snapshot = past.pop();\n return { stack: { past, future: [...stack.future, current] }, snapshot };\n}\n\nexport function redo(\n stack: UndoStack,\n current: unknown,\n): { stack: UndoStack; snapshot: unknown } | null {\n if (stack.future.length === 0) return null;\n const future = stack.future.slice();\n const snapshot = future.pop();\n return { stack: { past: [...stack.past, current], future }, snapshot };\n}\n\nexport function clearUndo(_stack: UndoStack): UndoStack {\n return emptyStack();\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ui/layers/LayerStack.tsx"],"names":["s"],"mappings":";;;;AAwCO,SAAS,UAAA,CAAW;AAAA,EACzB,KAAA;AAAA,EACA,KAAA;AAAA,EACA,YAAA;AAAA,EACA,KAAA;AAAA,EACA,QAAA;AAAA,EACA,SAAA;AAAA,EACA,eAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAAA,EAAoB;AAClB,EAAA,MAAM,CAAC,WAAA,EAAa,cAAc,CAAA,GAAI,QAAA;AAAA,IACpC,MAAM,IAAI,GAAA,CAAI,KAAA,CAAM,MAAA,CAAO,CAAC,CAAA,KAAM,CAAA,CAAE,eAAA,KAAoB,KAAK,EAAE,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,EAAE,CAAC;AAAA,GACjF;AAEA,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,cAAA,CAAe,CAAC,IAAA,KAAS;AACvB,MAAA,IAAI,IAAA,GAAoC,IAAA;AACxC,MAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,QAAA,IAAI,IAAA,CAAK,oBAAoB,KAAA,EAAO;AACpC,QAAA,IAAI,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,EAAE,CAAA,EAAG;AACvB,QAAA,IAAI,IAAA,KAAS,IAAA,EAAM,IAAA,GAAO,IAAI,IAAI,IAAI,CAAA;AACtC,QAAA,IAAA,CAAK,GAAA,CAAI,KAAK,EAAE,CAAA;AAAA,MAClB;AACA,MAAA,OAAO,IAAA,IAAQ,IAAA;AAAA,IACjB,CAAC,CAAA;AAAA,EACH,CAAA,EAAG,CAAC,KAAK,CAAC,CAAA;AAEV,EAAA,MAAM,SAAA,GAAY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,EAAG,GAAA,EAAI,EAAA,EAAG,GAAA,EAAI,GAAE,KAAA,EAAM,CAAA;AAAA,wBAC7B,QAAA,EAAA,EAAO,EAAA,EAAG,KAAI,EAAA,EAAG,GAAA,EAAI,GAAE,KAAA,EAAM,CAAA;AAAA,wBAC7B,QAAA,EAAA,EAAO,EAAA,EAAG,KAAI,EAAA,EAAG,GAAA,EAAI,GAAE,KAAA,EAAM,CAAA;AAAA,wBAC7B,QAAA,EAAA,EAAO,EAAA,EAAG,KAAI,EAAA,EAAG,GAAA,EAAI,GAAE,KAAA,EAAM,CAAA;AAAA,wBAC7B,QAAA,EAAA,EAAO,EAAA,EAAG,KAAI,EAAA,EAAG,IAAA,EAAK,GAAE,KAAA,EAAM,CAAA;AAAA,wBAC9B,QAAA,EAAA,EAAO,EAAA,EAAG,KAAI,EAAA,EAAG,IAAA,EAAK,GAAE,KAAA,EAAM;AAAA,GAAA,EACjC,CAAA;AAEJ","file":"chunk-EXBV7A6X.js","sourcesContent":["import { type CSSProperties, type ReactNode, type RefCallback, useEffect, useState } from 'react';\nimport { dlog, useReorderDragList } from '../../passthrough/weasel-ui';\n\nexport interface LayerStackItem {\n /** Stable id used for keys, onRemove, onReorder. Numeric to match\n * common id-from-nextId conventions; string ids also work. */\n id: number | string;\n /** Short kind label rendered in the header when no primary select\n * is hoisted (e.g. \"shadow\", \"stroke\"). */\n kind: string;\n /** When present, hoist this select into the card header so the user\n * can switch mode/shape without expanding. */\n primaryValue?: string;\n primaryOptions?: string[];\n /** Accent CSS color used as the left border / index-badge fill. */\n accent?: string;\n /** Optional badge text rendered before the primary control\n * (e.g. tail index \"1\", \"2\", \"3\"). When omitted a drag handle\n * glyph renders in its place. */\n badge?: string;\n /** Initial expanded state. Defaults to true for newly-added items. */\n defaultExpanded?: boolean;\n}\n\nexport interface LayerStackProps {\n title: string;\n items: LayerStackItem[];\n /** Kinds the user can add via the header palette. */\n paletteKinds: string[];\n onAdd: (kind: string) => void;\n onRemove: (id: number | string) => void;\n onReorder: (orderedIds: Array<number | string>) => void;\n onPrimaryChange: (id: number | string, nextValue: string) => void;\n /** Render the body controls for each item. */\n renderBody: (item: LayerStackItem) => ReactNode;\n /** Hide the title + palette row (used when an outer wrap renders its\n * own head — see speech-balloons Tails panel). */\n hideHead?: boolean;\n}\n\nexport function LayerStack({\n title,\n items,\n paletteKinds,\n onAdd,\n onRemove,\n onReorder,\n onPrimaryChange,\n renderBody,\n hideHead,\n}: LayerStackProps) {\n const [expandedIds, setExpandedIds] = useState<Set<number | string>>(\n () => new Set(items.filter((i) => i.defaultExpanded !== false).map((i) => i.id)),\n );\n\n useEffect(() => {\n setExpandedIds((prev) => {\n let next: Set<number | string> | null = null;\n for (const item of items) {\n if (item.defaultExpanded === false) continue;\n if (prev.has(item.id)) continue;\n if (next === null) next = new Set(prev);\n next.add(item.id);\n }\n return next ?? prev;\n });\n }, [items]);\n\n const dragItems = items.map((it) => ({ id: String(it.id), label: it.kind }));\n const drag = useReorderDragList({\n items: dragItems,\n selectedIds: [],\n onReorder: (ids, targetIndex) => {\n dlog('layer-stack', 'onReorder', { ids, targetIndex });\n const orig = items.map((i) => i.id);\n const moving = new Set(ids);\n const remaining = orig.filter((id) => !moving.has(String(id)));\n const movedIds = items.map((i) => i.id).filter((id) => moving.has(String(id)));\n // weasel reports targetIndex against the original list (which includes\n // the dragged row). Each moved item that originally sat before\n // targetIndex needs to shift the insertion point left by one.\n const shift = orig.filter((id, idx) => moving.has(String(id)) && idx < targetIndex).length;\n const adjusted = targetIndex - shift;\n const out = [...remaining];\n out.splice(adjusted, 0, ...movedIds);\n onReorder(out);\n },\n });\n\n const toggleExpanded = (id: number | string) => {\n setExpandedIds((s) => {\n const n = new Set(s);\n if (n.has(id)) n.delete(id);\n else n.add(id);\n return n;\n });\n };\n\n return (\n <div className=\"lk-layer-stack\">\n {!hideHead && (\n <div className=\"lk-layer-stack__head\">\n <h2 className=\"lk-layer-stack__title\">{title}</h2>\n <div className=\"lk-layer-stack__palette\">\n {paletteKinds.map((k) => (\n <button\n key={k}\n type=\"button\"\n className=\"lk-layer-stack__add\"\n onClick={() => {\n dlog('layer-stack', 'onAdd', { kind: k });\n onAdd(k);\n }}\n aria-label={`Add ${k}`}\n >\n {k}\n </button>\n ))}\n </div>\n </div>\n )}\n <div\n className=\"lk-layer-stack__list\"\n ref={drag.containerProps.ref as RefCallback<HTMLDivElement>}\n onPointerMove={drag.containerProps.onPointerMove}\n onPointerUp={drag.containerProps.onPointerUp}\n onPointerCancel={drag.containerProps.onPointerCancel}\n >\n {items.map((item, i) => {\n const expanded = expandedIds.has(item.id);\n const draggedId = drag.state.draggedIds?.[0];\n const isDragging = draggedId === String(item.id);\n const showHintBefore = drag.state.targetIndex === i && draggedId !== String(item.id);\n const showHintAfter = drag.state.targetIndex === items.length && i === items.length - 1;\n const cardCls = [\n 'lk-layer-card',\n expanded ? 'is-expanded' : 'is-collapsed',\n isDragging ? 'is-dragging' : '',\n item.accent ? 'has-accent' : '',\n ]\n .filter(Boolean)\n .join(' ');\n const cardStyle = item.accent\n ? ({ '--lk-layer-card-accent': item.accent } as CSSProperties)\n : undefined;\n const { onPointerDown } = drag.rowProps(String(item.id), i);\n return (\n <div key={item.id} className=\"lk-layer-card-wrap\">\n {showHintBefore && <div className=\"lk-layer-stack__drop-hint\" />}\n <div className={cardCls} data-testid={`lk-layer-card-${item.id}`} style={cardStyle}>\n <div className=\"lk-layer-card__head\">\n <button\n type=\"button\"\n className=\"lk-layer-card__handle\"\n aria-label={`Drag to reorder layer ${item.id}`}\n onPointerDown={onPointerDown}\n onClick={() => toggleExpanded(item.id)}\n >\n {item.badge ?? <DragHandleGlyph />}\n </button>\n {item.primaryValue !== undefined && item.primaryOptions ? (\n <select\n className=\"lk-layer-card__primary\"\n value={item.primaryValue}\n aria-label={`Primary select for layer ${item.id}`}\n onChange={(e) => onPrimaryChange(item.id, e.target.value)}\n onClick={(e) => e.stopPropagation()}\n >\n {item.primaryOptions.map((o) => (\n <option key={o} value={o}>\n {o}\n </option>\n ))}\n </select>\n ) : (\n <span className=\"lk-layer-card__kind\">{item.kind}</span>\n )}\n <button\n type=\"button\"\n className=\"lk-layer-card__remove\"\n aria-label=\"Remove layer\"\n onClick={(e) => {\n e.stopPropagation();\n onRemove(item.id);\n }}\n >\n ✕\n </button>\n </div>\n {expanded && <div className=\"lk-layer-card__body\">{renderBody(item)}</div>}\n </div>\n {showHintAfter && <div className=\"lk-layer-stack__drop-hint\" />}\n </div>\n );\n })}\n {items.length === 0 && (\n <div className=\"lk-layer-stack__empty\">No layers — add one above.</div>\n )}\n </div>\n </div>\n );\n}\n\nfunction DragHandleGlyph() {\n return (\n <svg width=\"12\" height=\"16\" viewBox=\"0 0 8 16\" fill=\"currentColor\" aria-hidden=\"true\">\n <circle cx=\"2\" cy=\"3\" r=\"1.1\" />\n <circle cx=\"6\" cy=\"3\" r=\"1.1\" />\n <circle cx=\"2\" cy=\"8\" r=\"1.1\" />\n <circle cx=\"6\" cy=\"8\" r=\"1.1\" />\n <circle cx=\"2\" cy=\"13\" r=\"1.1\" />\n <circle cx=\"6\" cy=\"13\" r=\"1.1\" />\n </svg>\n );\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/primitives/fpsAverage.ts","../src/primitives/FpsMeter.tsx","../src/primitives/ScaleIndicator.tsx","../src/primitives/Sidebar.tsx","../src/primitives/StatusBar.tsx","../src/primitives/Toolbar.tsx"],"names":["jsxs","jsx"],"mappings":";;;;;AAAO,SAAS,eAAe,OAAA,EAAoC;AACjE,EAAA,IAAI,OAAA,CAAQ,MAAA,KAAW,CAAA,EAAG,OAAO,CAAA;AACjC,EAAA,MAAM,GAAA,GAAM,QAAQ,MAAA,CAAO,CAAC,KAAK,CAAA,KAAM,GAAA,GAAM,GAAG,CAAC,CAAA;AACjD,EAAA,OAAO,IAAA,CAAK,KAAA,CAAM,GAAA,GAAM,OAAA,CAAQ,MAAM,CAAA;AACxC;ACDA,IAAM,aAAA,G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B;AAC3C,EAAA,uBAAOA,GAAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,yBAAyB,QAAA,EAAS,CAAA;AAC3D;AAEA,SAAA,CAAU,OAAA,GAAU,OAAA;ACXb,SAAS,OAAA,CAAQ,EAAE,QAAA,EAAS,EAAiB;AAClD,EAAA,uBAAOA,GAAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAU,cAAc,QAAA,EAAS,CAAA;AAC/C;AAKA,SAAS,KAAA,CAAM,EAAE,QAAA,EAAS,EAAe;AACvC,EAAA,uBAAOA,GAAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,oBAAoB,QAAA,EAAS,CAAA;AACtD;AAQA,SAAS,OAAO,EAAE,QAAA,EAAU,OAAA,EAAS,QAAA,EAAU,OAAM,EAAgB;AACnE,EAAA,uBACEA,GAAAA;AAAA,IAAC,QAAA;AAAA,IAAA;AAAA,MACC,IAAA,EAAK,QAAA;AAAA,MACL,SAAA,EAAU,mBAAA;AAAA,MACV,OAAA;AAAA,MACA,QAAA;AAAA,MACA,KAAA;AAAA,MAEC;AAAA;AAAA,GACH;AAEJ;AAEA,SAAS,MAAA,GAAS;AAChB,EAAA,uBAAOA,GAAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,mBAAA,EAAoB,eAAY,MAAA,EAAO,CAAA;AAChE;AAEA,OAAA,CAAQ,KAAA,GAAQ,KAAA;AAChB,OAAA,CAAQ,MAAA,GAAS,MAAA;AACjB,OAAA,CAAQ,MAAA,GAAS,MAAA","file":"chunk-HXZHVU4G.js","sourcesContent":["export function rollingAverage(samples: readonly number[]): number {\n if (samples.length === 0) return 0;\n const sum = samples.reduce((acc, n) => acc + n, 0);\n return Math.round(sum / samples.length);\n}\n","import { useEffect, useRef, useState } from 'react';\nimport { rollingAverage } from './fpsAverage';\n\nconst SAMPLE_WINDOW = 30;\n\nexport function FpsMeter() {\n const [fps, setFps] = useState(0);\n const samplesRef = useRef<number[]>([]);\n const lastTimeRef = useRef<number | null>(null);\n\n useEffect(() => {\n let rafId = 0;\n const tick = (time: number) => {\n const last = lastTimeRef.current;\n if (last !== null) {\n const delta = time - last;\n if (delta > 0) {\n const samples = samplesRef.current;\n samples.push(1000 / delta);\n if (samples.length > SAMPLE_WINDOW) samples.shift();\n setFps(rollingAverage(samples));\n }\n }\n lastTimeRef.current = time;\n rafId = requestAnimationFrame(tick);\n };\n rafId = requestAnimationFrame(tick);\n return () => cancelAnimationFrame(rafId);\n }, []);\n\n return (\n <div className=\"lk-fps-meter\">\n <span className=\"lk-fps-meter-value\">FPS {fps}</span>\n </div>\n );\n}\n","import { useContext } from 'react';\nimport { CanvasStackContext } from '../canvas/CanvasStackContext';\n\nexport interface ScaleIndicatorProps {\n /** Current view zoom factor. If omitted, reads from CanvasStackContext. Defaults to 1. */\n zoom?: number;\n /** World pixels per unit at zoom=1. Default: 1. */\n pixelsPerUnit?: number;\n /** Unit label. Default: 'px'. */\n unit?: string;\n /** Target bar width in display pixels. Default: 100. */\n targetWidth?: number;\n}\n\n// Rounds n to a \"nice\" number — 1, 2, 5, 10, 20, 50, ...\nfunction niceNumber(n: number): number {\n if (n <= 0) return 1;\n const exp = Math.floor(Math.log10(n));\n const fraction = n / 10 ** exp;\n let nice: number;\n if (fraction < 1.5) nice = 1;\n else if (fraction < 3.5) nice = 2;\n else if (fraction < 7.5) nice = 5;\n else nice = 10;\n return nice * 10 ** exp;\n}\n\nexport function ScaleIndicator({\n zoom,\n pixelsPerUnit = 1,\n unit = 'px',\n targetWidth = 100,\n}: ScaleIndicatorProps) {\n const ctxValue = useContext(CanvasStackContext);\n const effectiveZoom = zoom ?? ctxValue?.view.zoom ?? 1;\n const effectivePxPerUnit = pixelsPerUnit * effectiveZoom;\n const targetUnits = targetWidth / effectivePxPerUnit;\n const niceUnits = niceNumber(targetUnits);\n const barWidth = niceUnits * effectivePxPerUnit;\n return (\n <div className=\"lk-scale-indicator\" role=\"img\" aria-label={`Scale: ${niceUnits} ${unit}`}>\n <div className=\"lk-scale-indicator-bar\" style={{ width: `${barWidth}px` }} />\n <span className=\"lk-scale-indicator-label\">\n {niceUnits} {unit}\n </span>\n </div>\n );\n}\n","import type { ReactNode } from 'react';\n\nexport interface SidebarProps {\n children: ReactNode;\n title?: string;\n collapsed?: boolean;\n onToggle?: () => void;\n}\n\nexport function Sidebar({ children, title, collapsed = false, onToggle }: SidebarProps) {\n const className = `lk-sidebar${collapsed ? ' lk-sidebar--collapsed' : ''}`;\n return (\n <aside className={className}>\n {(title || onToggle) && (\n <div className=\"lk-sidebar-header\">\n {title && <span className=\"lk-sidebar-title\">{title}</span>}\n {onToggle && (\n <button\n type=\"button\"\n className=\"lk-sidebar-toggle\"\n onClick={onToggle}\n aria-label={collapsed ? 'Expand sidebar' : 'Collapse sidebar'}\n >\n {collapsed ? '›' : '‹'}\n </button>\n )}\n </div>\n )}\n <div className=\"lk-sidebar-body\">{children}</div>\n </aside>\n );\n}\n","import type { ReactNode } from 'react';\n\nexport interface StatusBarProps {\n children: ReactNode;\n}\n\nexport function StatusBar({ children }: StatusBarProps) {\n return <div className=\"lk-status-bar\">{children}</div>;\n}\n\ninterface SectionProps {\n children: ReactNode;\n}\nfunction Section({ children }: SectionProps) {\n return <span className=\"lk-status-bar-section\">{children}</span>;\n}\n\nStatusBar.Section = Section;\n","import type { MouseEventHandler, ReactNode } from 'react';\n\nexport interface ToolbarProps {\n children: ReactNode;\n}\n\nexport function Toolbar({ children }: ToolbarProps) {\n return <div className=\"lk-toolbar\">{children}</div>;\n}\n\ninterface TitleProps {\n children: ReactNode;\n}\nfunction Title({ children }: TitleProps) {\n return <span className=\"lk-toolbar-title\">{children}</span>;\n}\n\ninterface ButtonProps {\n children: ReactNode;\n onClick: MouseEventHandler<HTMLButtonElement>;\n disabled?: boolean;\n title?: string;\n}\nfunction Button({ children, onClick, disabled, title }: ButtonProps) {\n return (\n <button\n type=\"button\"\n className=\"lk-toolbar-button\"\n onClick={onClick}\n disabled={disabled}\n title={title}\n >\n {children}\n </button>\n );\n}\n\nfunction Spacer() {\n return <span className=\"lk-toolbar-spacer\" aria-hidden=\"true\" />;\n}\n\nToolbar.Title = Title;\nToolbar.Button = Button;\nToolbar.Spacer = Spacer;\n"]}
|