@weasel-js/labkit 0.1.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.
- package/README.md +72 -0
- package/dist/_dts/fitViewToBounds-rWrBI4a6.d.ts +870 -0
- package/dist/_dts/index-C6Yze7sQ.d.ts +93 -0
- package/dist/_dts/types-Si4Fw-1F.d.ts +48 -0
- package/dist/_dts/useExperimentState-eSvpwV_P.d.ts +102 -0
- package/dist/canvas/index.d.ts +34 -0
- package/dist/canvas/index.js +4 -0
- package/dist/canvas/index.js.map +1 -0
- package/dist/chunk-2QNYYL3V.js +86 -0
- package/dist/chunk-2QNYYL3V.js.map +1 -0
- package/dist/chunk-54IQ2DX7.js +222 -0
- package/dist/chunk-54IQ2DX7.js.map +1 -0
- package/dist/chunk-6FO7G5BB.js +6095 -0
- package/dist/chunk-6FO7G5BB.js.map +1 -0
- package/dist/chunk-7BKDG73Z.js +54 -0
- package/dist/chunk-7BKDG73Z.js.map +1 -0
- package/dist/chunk-B5ZUYRKN.js +23330 -0
- package/dist/chunk-B5ZUYRKN.js.map +1 -0
- package/dist/chunk-HXZHVU4G.js +126 -0
- package/dist/chunk-HXZHVU4G.js.map +1 -0
- package/dist/chunk-PWC7AQZM.js +8 -0
- package/dist/chunk-PWC7AQZM.js.map +1 -0
- package/dist/chunk-SD3HDXR7.js +161 -0
- package/dist/chunk-SD3HDXR7.js.map +1 -0
- package/dist/chunk-SSMHPMDV.js +350 -0
- package/dist/chunk-SSMHPMDV.js.map +1 -0
- package/dist/chunk-VLAHRJOC.js +201 -0
- package/dist/chunk-VLAHRJOC.js.map +1 -0
- package/dist/controls/index.d.ts +13 -0
- package/dist/controls/index.js +3 -0
- package/dist/controls/index.js.map +1 -0
- package/dist/dragdrop/index.d.ts +3 -0
- package/dist/dragdrop/index.js +3 -0
- package/dist/dragdrop/index.js.map +1 -0
- package/dist/fonts/oswald-latin-variable.woff2 +0 -0
- package/dist/index.d.ts +410 -0
- package/dist/index.js +1425 -0
- package/dist/index.js.map +1 -0
- package/dist/layers/index.d.ts +17 -0
- package/dist/layers/index.js +3 -0
- package/dist/layers/index.js.map +1 -0
- package/dist/passthrough/weasel-canvas.d.ts +258 -0
- package/dist/passthrough/weasel-canvas.js +3 -0
- package/dist/passthrough/weasel-canvas.js.map +1 -0
- package/dist/passthrough/weasel-ui.d.ts +2826 -0
- package/dist/passthrough/weasel-ui.js +4 -0
- package/dist/passthrough/weasel-ui.js.map +1 -0
- package/dist/primitives/index.d.ts +57 -0
- package/dist/primitives/index.js +4 -0
- package/dist/primitives/index.js.map +1 -0
- package/dist/state/index.d.ts +33 -0
- package/dist/state/index.js +34 -0
- package/dist/state/index.js.map +1 -0
- package/dist/styles.css +1224 -0
- package/dist/theme-interstellar.css +25 -0
- package/dist/theme-light.css +13 -0
- package/dist/ui/layers/index.d.ts +42 -0
- package/dist/ui/layers/index.js +5 -0
- package/dist/ui/layers/index.js.map +1 -0
- package/dist/undo/index.d.ts +30 -0
- package/dist/undo/index.js +3 -0
- package/dist/undo/index.js.map +1 -0
- package/package.json +99 -0
- package/src/canvas/AGENTS.md +72 -0
- package/src/canvas/CanvasStack.less +22 -0
- package/src/canvas/CanvasStack.stories.tsx +63 -0
- package/src/canvas/CanvasStack.test.tsx +82 -0
- package/src/canvas/CanvasStack.tsx +108 -0
- package/src/canvas/CanvasStackContext.ts +8 -0
- package/src/canvas/canvasCoords.test.ts +30 -0
- package/src/canvas/canvasCoords.ts +15 -0
- package/src/canvas/index.ts +6 -0
- package/src/canvas/useLayerScheduler.ts +72 -0
- package/src/canvas/usePanZoom.ts +98 -0
- package/src/controls/ControlPanel.less +61 -0
- package/src/controls/ControlPanel.stories.tsx +77 -0
- package/src/controls/ControlPanel.test.tsx +149 -0
- package/src/controls/ControlPanel.tsx +249 -0
- package/src/controls/index.ts +12 -0
- package/src/controls/types.ts +61 -0
- package/src/dragdrop/DragDropRuntime.tsx +135 -0
- package/src/dragdrop/DragGhost.less +17 -0
- package/src/dragdrop/DragGhost.tsx +24 -0
- package/src/dragdrop/Palette.less +34 -0
- package/src/dragdrop/Palette.tsx +27 -0
- package/src/dragdrop/dragDrop.test.tsx +145 -0
- package/src/dragdrop/index.ts +1 -0
- package/src/fonts/oswald-latin-variable.woff2 +0 -0
- package/src/index.ts +70 -0
- package/src/instrument/SineWave.smoke.test.tsx +94 -0
- package/src/instrument/capabilityDetector.test.ts +64 -0
- package/src/instrument/capabilityDetector.ts +17 -0
- package/src/instrument/defineInstrument.test.ts +27 -0
- package/src/instrument/defineInstrument.ts +5 -0
- package/src/instrument/index.ts +19 -0
- package/src/instrument/types.ts +65 -0
- package/src/instrument/validateConfigSchema.test.ts +125 -0
- package/src/instrument/validateConfigSchema.ts +65 -0
- package/src/lab/Lab.less +3 -0
- package/src/lab/Lab.stories.tsx +51 -0
- package/src/lab/Lab.test.tsx +126 -0
- package/src/lab/Lab.tsx +196 -0
- package/src/lab/LabContext.test.ts +11 -0
- package/src/lab/LabContext.ts +28 -0
- package/src/lab/LabShell.less +45 -0
- package/src/lab/LabShell.stories.tsx +39 -0
- package/src/lab/LabShell.test.tsx +59 -0
- package/src/lab/LabShell.tsx +33 -0
- package/src/lab/WorkspaceGrid.less +8 -0
- package/src/lab/WorkspaceGrid.stories.tsx +61 -0
- package/src/lab/WorkspaceGrid.test.tsx +40 -0
- package/src/lab/WorkspaceGrid.tsx +20 -0
- package/src/lab/gridDims.test.ts +35 -0
- package/src/lab/gridDims.ts +11 -0
- package/src/lab/index.ts +10 -0
- package/src/layers/AGENTS.md +65 -0
- package/src/layers/LayerList.less +53 -0
- package/src/layers/LayerList.test.tsx +49 -0
- package/src/layers/LayerList.tsx +105 -0
- package/src/layers/index.ts +3 -0
- package/src/passthrough/weasel-canvas.test.ts +30 -0
- package/src/passthrough/weasel-canvas.ts +23 -0
- package/src/passthrough/weasel-ui.test.ts +79 -0
- package/src/passthrough/weasel-ui.ts +150 -0
- package/src/primitives/FpsMeter.less +14 -0
- package/src/primitives/FpsMeter.stories.tsx +14 -0
- package/src/primitives/FpsMeter.test.tsx +38 -0
- package/src/primitives/FpsMeter.tsx +36 -0
- package/src/primitives/ScaleIndicator.less +25 -0
- package/src/primitives/ScaleIndicator.stories.tsx +16 -0
- package/src/primitives/ScaleIndicator.test.tsx +46 -0
- package/src/primitives/ScaleIndicator.tsx +48 -0
- package/src/primitives/Sidebar.less +57 -0
- package/src/primitives/Sidebar.stories.tsx +38 -0
- package/src/primitives/Sidebar.test.tsx +74 -0
- package/src/primitives/Sidebar.tsx +32 -0
- package/src/primitives/StatusBar.less +21 -0
- package/src/primitives/StatusBar.stories.tsx +24 -0
- package/src/primitives/StatusBar.test.tsx +25 -0
- package/src/primitives/StatusBar.tsx +18 -0
- package/src/primitives/Toolbar.less +43 -0
- package/src/primitives/Toolbar.stories.tsx +36 -0
- package/src/primitives/Toolbar.test.tsx +65 -0
- package/src/primitives/Toolbar.tsx +44 -0
- package/src/primitives/fpsAverage.test.ts +21 -0
- package/src/primitives/fpsAverage.ts +5 -0
- package/src/primitives/index.ts +9 -0
- package/src/state/SingletonExperiment.test.tsx +101 -0
- package/src/state/SingletonExperiment.tsx +52 -0
- package/src/state/adapters.test.ts +94 -0
- package/src/state/adapters.ts +102 -0
- package/src/state/context.tsx +42 -0
- package/src/state/helpers.test.ts +89 -0
- package/src/state/helpers.ts +61 -0
- package/src/state/index.ts +40 -0
- package/src/state/store.test.ts +243 -0
- package/src/state/store.ts +225 -0
- package/src/state/types.ts +53 -0
- package/src/state/useExperimentState.test.tsx +102 -0
- package/src/state/useExperimentState.ts +28 -0
- package/src/styles.less +20 -0
- package/src/test-setup.ts +17 -0
- package/src/theme/Interstellar.stories.less +92 -0
- package/src/theme/Interstellar.stories.tsx +243 -0
- package/src/theme/base.less +122 -0
- package/src/theme/interstellar.less +34 -0
- package/src/theme/light.less +14 -0
- package/src/theme/tokens.less +85 -0
- package/src/ui/format.ts +19 -0
- package/src/ui/layers/LayerStack.less +143 -0
- package/src/ui/layers/LayerStack.stories.tsx +45 -0
- package/src/ui/layers/LayerStack.test.tsx +170 -0
- package/src/ui/layers/LayerStack.tsx +215 -0
- package/src/ui/layers/index.ts +1 -0
- package/src/ui/properties/CheckboxRow.stories.tsx +27 -0
- package/src/ui/properties/ColorRow.stories.tsx +106 -0
- package/src/ui/properties/CurveField.less +48 -0
- package/src/ui/properties/CurveField.stories.tsx +20 -0
- package/src/ui/properties/CurveField.test.tsx +127 -0
- package/src/ui/properties/CurveField.tsx +181 -0
- package/src/ui/properties/EffectCard.tsx +312 -0
- package/src/ui/properties/Gallery.stories.tsx +178 -0
- package/src/ui/properties/NumberRow.stories.tsx +65 -0
- package/src/ui/properties/PropertyGroup.less +50 -0
- package/src/ui/properties/PropertyGroup.stories.tsx +34 -0
- package/src/ui/properties/PropertyGroup.test.tsx +33 -0
- package/src/ui/properties/PropertyGroup.tsx +44 -0
- package/src/ui/properties/PropertyList.stories.tsx +83 -0
- package/src/ui/properties/PropertyPanel.less +592 -0
- package/src/ui/properties/PropertyPanel.stories.tsx +191 -0
- package/src/ui/properties/PropertyPanel.test.tsx +193 -0
- package/src/ui/properties/PropertyPanel.tsx +441 -0
- package/src/ui/properties/PropertyRow.stories.tsx +53 -0
- package/src/ui/properties/SelectRow.stories.tsx +58 -0
- package/src/ui/properties/SliderRow.stories.tsx +74 -0
- package/src/ui/properties/SpeechBalloonPanels.stories.tsx +396 -0
- package/src/ui/properties/TextRow.stories.tsx +62 -0
- package/src/ui/properties/ToggleRow.stories.tsx +57 -0
- package/src/ui/properties/index.ts +39 -0
- package/src/ui/properties/storyLayouts.tsx +36 -0
- package/src/undo/eventBus.test.ts +49 -0
- package/src/undo/eventBus.ts +32 -0
- package/src/undo/index.ts +5 -0
- package/src/undo/undoStack.test.ts +70 -0
- package/src/undo/undoStack.ts +38 -0
- package/src/workspace/DefaultSidebar.tsx +26 -0
- package/src/workspace/DefaultStatusBar.tsx +15 -0
- package/src/workspace/DefaultToolbar.tsx +88 -0
- package/src/workspace/Workspace.less +58 -0
- package/src/workspace/Workspace.stories.tsx +78 -0
- package/src/workspace/Workspace.test.tsx +186 -0
- package/src/workspace/Workspace.tsx +255 -0
- package/src/workspace/WorkspaceChrome.tsx +150 -0
- package/src/workspace/index.ts +24 -0
- package/src/workspace/slotTypes.ts +44 -0
- package/src/workspace/workspaceOps.test.ts +142 -0
- package/src/workspace/workspaceOps.ts +78 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ze as ActionBar, ti as ActionsBar, mr as Badge, gr as Button, ai as Checkbox, ha as ComboBox, ga as ComboBoxItem, ao as CurveEditor, vr as DataGrid, Ai as Dialog, xn as EDGE_PROFILES, li as Field, di as Input, Cr as KeyCap, wr as KeySequence, jr as MINUS_SIGN, pi as NumberField, Yr as OptionsBar, Fa as Plot2D, co as PointPlotter, ri as Powerline, gi as Radio, hi as RadioGroup, vi as RangeSlider, yi as Select, bi as SelectItem, Ji as Sidebar, Yi as SidebarPanel, Lr as Slider, Si as Switch, fa as Tab, da as TabList, pa as TabPanel, ua as Tabs, Ur as ToggleBar, Zi as ToolButton, $i as ToolGroup, ca as ToolPalette, po as chromaAt, Dr as detectPlatform, Ae as dlog, K as fieldClasses, Mr as formatNumber, na as formatShortcut, ta as formatShortcutParts, Sr as inferKeycapKind, ke as isDebugEnabled, Tr as keyGlyph, Ar as keySpecFromKey, Or as keySpecsFromMods, fo as oklchToHex, uo as paintGradientTrack, _r as useReorderDragList } from '../chunk-6FO7G5BB.js';
|
|
2
|
+
import '../chunk-B5ZUYRKN.js';
|
|
3
|
+
//# sourceMappingURL=weasel-ui.js.map
|
|
4
|
+
//# sourceMappingURL=weasel-ui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"weasel-ui.js"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode, MouseEventHandler } from 'react';
|
|
3
|
+
|
|
4
|
+
declare function FpsMeter(): react_jsx_runtime.JSX.Element;
|
|
5
|
+
|
|
6
|
+
interface ScaleIndicatorProps {
|
|
7
|
+
/** Current view zoom factor. If omitted, reads from CanvasStackContext. Defaults to 1. */
|
|
8
|
+
zoom?: number;
|
|
9
|
+
/** World pixels per unit at zoom=1. Default: 1. */
|
|
10
|
+
pixelsPerUnit?: number;
|
|
11
|
+
/** Unit label. Default: 'px'. */
|
|
12
|
+
unit?: string;
|
|
13
|
+
/** Target bar width in display pixels. Default: 100. */
|
|
14
|
+
targetWidth?: number;
|
|
15
|
+
}
|
|
16
|
+
declare function ScaleIndicator({ zoom, pixelsPerUnit, unit, targetWidth, }: ScaleIndicatorProps): react_jsx_runtime.JSX.Element;
|
|
17
|
+
|
|
18
|
+
interface SidebarProps {
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
title?: string;
|
|
21
|
+
collapsed?: boolean;
|
|
22
|
+
onToggle?: () => void;
|
|
23
|
+
}
|
|
24
|
+
declare function Sidebar({ children, title, collapsed, onToggle }: SidebarProps): react_jsx_runtime.JSX.Element;
|
|
25
|
+
|
|
26
|
+
interface StatusBarProps {
|
|
27
|
+
children: ReactNode;
|
|
28
|
+
}
|
|
29
|
+
declare function StatusBar({ children }: StatusBarProps): react_jsx_runtime.JSX.Element;
|
|
30
|
+
declare namespace StatusBar {
|
|
31
|
+
var Section: ({ children }: SectionProps) => react_jsx_runtime.JSX.Element;
|
|
32
|
+
}
|
|
33
|
+
interface SectionProps {
|
|
34
|
+
children: ReactNode;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface ToolbarProps {
|
|
38
|
+
children: ReactNode;
|
|
39
|
+
}
|
|
40
|
+
declare function Toolbar({ children }: ToolbarProps): react_jsx_runtime.JSX.Element;
|
|
41
|
+
declare namespace Toolbar {
|
|
42
|
+
var Title: ({ children }: TitleProps) => react_jsx_runtime.JSX.Element;
|
|
43
|
+
var Button: ({ children, onClick, disabled, title }: ButtonProps) => react_jsx_runtime.JSX.Element;
|
|
44
|
+
var Spacer: () => react_jsx_runtime.JSX.Element;
|
|
45
|
+
}
|
|
46
|
+
interface TitleProps {
|
|
47
|
+
children: ReactNode;
|
|
48
|
+
}
|
|
49
|
+
interface ButtonProps {
|
|
50
|
+
children: ReactNode;
|
|
51
|
+
onClick: MouseEventHandler<HTMLButtonElement>;
|
|
52
|
+
disabled?: boolean;
|
|
53
|
+
title?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { FpsMeter, ScaleIndicator, Sidebar, StatusBar, Toolbar };
|
|
57
|
+
export type { ScaleIndicatorProps, SidebarProps, StatusBarProps, ToolbarProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { I as InstrumentSerializers, W as WorkspaceRecord, U as UndoStack, S as StorageAdapter } from '../_dts/useExperimentState-eSvpwV_P.js';
|
|
2
|
+
export { C as CreateLabStoreOptions, E as ExperimentStateHandle, L as LabStore, a as LabStoreActions, b as LabStoreContext, c as LabStoreProvider, d as LabStoreState, e as SavedSnapshot, f as WorkspaceIdContext, g as WorkspaceIdProvider, h as createLabStore, i as createMemoryAdapter, l as localStorageAdapter, n as noneAdapter, s as sessionStorageAdapter, u as urlHashAdapter, j as useExperimentState, k as useLabStore, m as useWorkspaceId } from '../_dts/useExperimentState-eSvpwV_P.js';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
import 'zustand/vanilla';
|
|
6
|
+
|
|
7
|
+
declare function labStorageKey(storageKey: string, bucket: 'workspaces' | 'saves' | 'theme'): string;
|
|
8
|
+
declare function encodeUrlHash(value: string): string;
|
|
9
|
+
declare function decodeUrlHash(hash: string): string | null;
|
|
10
|
+
declare function emptyUndoStack(): UndoStack;
|
|
11
|
+
declare function serializeWorkspaces(workspaces: WorkspaceRecord[], serializers: InstrumentSerializers): string;
|
|
12
|
+
declare function deserializeWorkspaces(raw: string, deserializers: InstrumentSerializers): WorkspaceRecord[];
|
|
13
|
+
|
|
14
|
+
interface SingletonExperimentProviderProps<TS, TC> {
|
|
15
|
+
/** Stable id for the synthetic workspace; also doubles as the
|
|
16
|
+
* WorkspaceIdContext value. */
|
|
17
|
+
id: string;
|
|
18
|
+
initialConfig: TC;
|
|
19
|
+
initialState: TS;
|
|
20
|
+
storage: StorageAdapter;
|
|
21
|
+
storageKey: string;
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* One-workspace `<Lab>` substitute for single-screen experiments. Mounts
|
|
26
|
+
* a `LabStoreProvider` + `WorkspaceIdProvider` with one synthetic
|
|
27
|
+
* workspace, so `useExperimentState` works without going through the
|
|
28
|
+
* full `<Lab instruments={...}>` runtime.
|
|
29
|
+
*/
|
|
30
|
+
declare function SingletonExperimentProvider<TS, TC>({ id, initialConfig, initialState, storage, storageKey, children, }: SingletonExperimentProviderProps<TS, TC>): react_jsx_runtime.JSX.Element;
|
|
31
|
+
|
|
32
|
+
export { InstrumentSerializers, SingletonExperimentProvider, StorageAdapter, UndoStack, WorkspaceRecord, decodeUrlHash, deserializeWorkspaces, emptyUndoStack, encodeUrlHash, labStorageKey, serializeWorkspaces };
|
|
33
|
+
export type { SingletonExperimentProviderProps };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createLabStore, LabStoreProvider, WorkspaceIdProvider } from '../chunk-SSMHPMDV.js';
|
|
2
|
+
export { LabStoreContext, LabStoreProvider, WorkspaceIdContext, WorkspaceIdProvider, createLabStore, createMemoryAdapter, decodeUrlHash, deserializeWorkspaces, emptyUndoStack, encodeUrlHash, labStorageKey, localStorageAdapter, noneAdapter, serializeWorkspaces, sessionStorageAdapter, urlHashAdapter, useExperimentState, useLabStore, useWorkspaceId } from '../chunk-SSMHPMDV.js';
|
|
3
|
+
import { useRef } from 'react';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
var SINGLETON_INSTRUMENT = "__singleton__";
|
|
7
|
+
function SingletonExperimentProvider({
|
|
8
|
+
id,
|
|
9
|
+
initialConfig,
|
|
10
|
+
initialState,
|
|
11
|
+
storage,
|
|
12
|
+
storageKey,
|
|
13
|
+
children
|
|
14
|
+
}) {
|
|
15
|
+
const storeRef = useRef(null);
|
|
16
|
+
if (storeRef.current === null) {
|
|
17
|
+
const store = createLabStore({ storageKey, storage });
|
|
18
|
+
if (!store.getState().workspaces.some((w) => w.id === id)) {
|
|
19
|
+
store.getState().addWorkspace({
|
|
20
|
+
id,
|
|
21
|
+
instrumentName: SINGLETON_INSTRUMENT,
|
|
22
|
+
config: initialConfig,
|
|
23
|
+
state: initialState,
|
|
24
|
+
view: { zoom: 1, pan: { x: 0, y: 0 } }
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
storeRef.current = store;
|
|
28
|
+
}
|
|
29
|
+
return /* @__PURE__ */ jsx(LabStoreProvider, { store: storeRef.current, children: /* @__PURE__ */ jsx(WorkspaceIdProvider, { workspaceId: id, children }) });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { SingletonExperimentProvider };
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/state/SingletonExperiment.tsx"],"names":[],"mappings":";;;;;AAKA,IAAM,oBAAA,GAAuB,eAAA;AAmBtB,SAAS,2BAAA,CAAoC;AAAA,EAClD,EAAA;AAAA,EACA,aAAA;AAAA,EACA,YAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAAA,EAA6C;AAC3C,EAAA,MAAM,QAAA,GAAW,OAAwB,IAAI,CAAA;AAC7C,EAAA,IAAI,QAAA,CAAS,YAAY,IAAA,EAAM;AAC7B,IAAA,MAAM,KAAA,GAAQ,cAAA,CAAe,EAAE,UAAA,EAAY,SAAS,CAAA;AACpD,IAAA,IAAI,CAAC,KAAA,CAAM,QAAA,EAAS,CAAE,UAAA,CAAW,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,EAAA,KAAO,EAAE,CAAA,EAAG;AACzD,MAAA,KAAA,CAAM,QAAA,GAAW,YAAA,CAAa;AAAA,QAC5B,EAAA;AAAA,QACA,cAAA,EAAgB,oBAAA;AAAA,QAChB,MAAA,EAAQ,aAAA;AAAA,QACR,KAAA,EAAO,YAAA;AAAA,QACP,IAAA,EAAM,EAAE,IAAA,EAAM,CAAA,EAAG,GAAA,EAAK,EAAE,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAE;AAAE,OACtC,CAAA;AAAA,IACH;AACA,IAAA,QAAA,CAAS,OAAA,GAAU,KAAA;AAAA,EACrB;AACA,EAAA,uBACE,GAAA,CAAC,gBAAA,EAAA,EAAiB,KAAA,EAAO,QAAA,CAAS,OAAA,EAChC,8BAAC,mBAAA,EAAA,EAAoB,WAAA,EAAa,EAAA,EAAK,QAAA,EAAS,CAAA,EAClD,CAAA;AAEJ","file":"index.js","sourcesContent":["import { type ReactNode, useRef } from 'react';\nimport { LabStoreProvider, WorkspaceIdProvider } from './context';\nimport { createLabStore, type LabStore } from './store';\nimport type { StorageAdapter } from './types';\n\nconst SINGLETON_INSTRUMENT = '__singleton__';\n\nexport interface SingletonExperimentProviderProps<TS, TC> {\n /** Stable id for the synthetic workspace; also doubles as the\n * WorkspaceIdContext value. */\n id: string;\n initialConfig: TC;\n initialState: TS;\n storage: StorageAdapter;\n storageKey: string;\n children: ReactNode;\n}\n\n/**\n * One-workspace `<Lab>` substitute for single-screen experiments. Mounts\n * a `LabStoreProvider` + `WorkspaceIdProvider` with one synthetic\n * workspace, so `useExperimentState` works without going through the\n * full `<Lab instruments={...}>` runtime.\n */\nexport function SingletonExperimentProvider<TS, TC>({\n id,\n initialConfig,\n initialState,\n storage,\n storageKey,\n children,\n}: SingletonExperimentProviderProps<TS, TC>) {\n const storeRef = useRef<LabStore | null>(null);\n if (storeRef.current === null) {\n const store = createLabStore({ storageKey, storage });\n if (!store.getState().workspaces.some((w) => w.id === id)) {\n store.getState().addWorkspace({\n id,\n instrumentName: SINGLETON_INSTRUMENT,\n config: initialConfig,\n state: initialState,\n view: { zoom: 1, pan: { x: 0, y: 0 } },\n });\n }\n storeRef.current = store;\n }\n return (\n <LabStoreProvider store={storeRef.current}>\n <WorkspaceIdProvider workspaceId={id}>{children}</WorkspaceIdProvider>\n </LabStoreProvider>\n );\n}\n"]}
|