@miadi/stateloom-canvas 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/LICENSE +21 -0
- package/README.md +91 -0
- package/dist/StateMachineCanvas.d.ts +103 -0
- package/dist/StateMachineCanvas.js +932 -0
- package/dist/drill.d.ts +32 -0
- package/dist/drill.js +70 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +21 -0
- package/dist/styles.css +404 -0
- package/dist/theme.d.ts +61 -0
- package/dist/theme.js +59 -0
- package/package.json +61 -0
package/dist/drill.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which states the board is showing right now.
|
|
3
|
+
*
|
|
4
|
+
* A machine is a tree, but a canvas draws one level of it: a parent's direct
|
|
5
|
+
* children, with the arrows that run between them. Drilling into a composite
|
|
6
|
+
* is nothing more than moving the parent one step down that tree, which is why
|
|
7
|
+
* the whole of navigation here is a path of names and these three functions.
|
|
8
|
+
*
|
|
9
|
+
* Pure: no React, no DOM. The same path over the same definition always names
|
|
10
|
+
* the same level.
|
|
11
|
+
*/
|
|
12
|
+
import type { StateDef, StateMachineDefinition } from "@miadi/stateloom-protocol";
|
|
13
|
+
/** A state's direct children — its `states`, or its parallel regions. */
|
|
14
|
+
export declare function childrenOf(state: StateDef): StateDef[];
|
|
15
|
+
/** A named child of `parent`, one level down only. */
|
|
16
|
+
export declare function childByName(parent: StateDef, name: string): StateDef | null;
|
|
17
|
+
/** Anywhere in the subtree. Used to answer "what did the user just select?". */
|
|
18
|
+
export declare function findState(root: StateDef, name: string): StateDef | null;
|
|
19
|
+
/**
|
|
20
|
+
* The state whose children the canvas draws: `root` walked down `path`.
|
|
21
|
+
*
|
|
22
|
+
* A path naming something that no longer exists — a state renamed under a
|
|
23
|
+
* breadcrumb still pointing at it — resolves to the deepest level that does,
|
|
24
|
+
* so the board falls back toward the root instead of going blank.
|
|
25
|
+
*/
|
|
26
|
+
export declare function parentAt(root: StateDef, path: readonly string[]): StateDef;
|
|
27
|
+
/** The boxes drawn at `path`. */
|
|
28
|
+
export declare function childStatesAt(root: StateDef, path: readonly string[]): StateDef[];
|
|
29
|
+
/** How much of `path` still resolves — what the breadcrumb may honestly show. */
|
|
30
|
+
export declare function livePath(root: StateDef, path: readonly string[]): string[];
|
|
31
|
+
/** Every event id the definition declares, in declaration order, deduplicated. */
|
|
32
|
+
export declare function definedEvents(definition: StateMachineDefinition): string[];
|
package/dist/drill.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** A state's direct children — its `states`, or its parallel regions. */
|
|
2
|
+
export function childrenOf(state) {
|
|
3
|
+
if (state.parallel)
|
|
4
|
+
return state.parallel.states;
|
|
5
|
+
return state.states ?? [];
|
|
6
|
+
}
|
|
7
|
+
/** A named child of `parent`, one level down only. */
|
|
8
|
+
export function childByName(parent, name) {
|
|
9
|
+
return childrenOf(parent).find((child) => child.name === name) ?? null;
|
|
10
|
+
}
|
|
11
|
+
/** Anywhere in the subtree. Used to answer "what did the user just select?". */
|
|
12
|
+
export function findState(root, name) {
|
|
13
|
+
if (root.name === name)
|
|
14
|
+
return root;
|
|
15
|
+
for (const child of childrenOf(root)) {
|
|
16
|
+
const found = findState(child, name);
|
|
17
|
+
if (found)
|
|
18
|
+
return found;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The state whose children the canvas draws: `root` walked down `path`.
|
|
24
|
+
*
|
|
25
|
+
* A path naming something that no longer exists — a state renamed under a
|
|
26
|
+
* breadcrumb still pointing at it — resolves to the deepest level that does,
|
|
27
|
+
* so the board falls back toward the root instead of going blank.
|
|
28
|
+
*/
|
|
29
|
+
export function parentAt(root, path) {
|
|
30
|
+
let current = root;
|
|
31
|
+
for (const name of path) {
|
|
32
|
+
const next = childByName(current, name);
|
|
33
|
+
if (!next)
|
|
34
|
+
return current;
|
|
35
|
+
current = next;
|
|
36
|
+
}
|
|
37
|
+
return current;
|
|
38
|
+
}
|
|
39
|
+
/** The boxes drawn at `path`. */
|
|
40
|
+
export function childStatesAt(root, path) {
|
|
41
|
+
return childrenOf(parentAt(root, path));
|
|
42
|
+
}
|
|
43
|
+
/** How much of `path` still resolves — what the breadcrumb may honestly show. */
|
|
44
|
+
export function livePath(root, path) {
|
|
45
|
+
const live = [];
|
|
46
|
+
let current = root;
|
|
47
|
+
for (const name of path) {
|
|
48
|
+
const next = childByName(current, name);
|
|
49
|
+
if (!next)
|
|
50
|
+
break;
|
|
51
|
+
live.push(name);
|
|
52
|
+
current = next;
|
|
53
|
+
}
|
|
54
|
+
return live;
|
|
55
|
+
}
|
|
56
|
+
/** Every event id the definition declares, in declaration order, deduplicated. */
|
|
57
|
+
export function definedEvents(definition) {
|
|
58
|
+
const seen = new Set();
|
|
59
|
+
const ids = [];
|
|
60
|
+
for (const source of definition.events ?? []) {
|
|
61
|
+
for (const event of source.events ?? []) {
|
|
62
|
+
if (seen.has(event.id))
|
|
63
|
+
continue;
|
|
64
|
+
seen.add(event.id);
|
|
65
|
+
ids.push(event.id);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return ids;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=drill.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @miadi/stateloom-canvas
|
|
3
|
+
*
|
|
4
|
+
* The SMDF design surface as a mountable React component: pan, zoom, drill,
|
|
5
|
+
* drag, routed edges, settled labels, touch gestures and a navigation HUD —
|
|
6
|
+
* driven entirely by props, styled entirely by CSS variables.
|
|
7
|
+
*
|
|
8
|
+
* import { StateMachineCanvas } from "@miadi/stateloom-canvas";
|
|
9
|
+
* import "@miadi/stateloom-canvas/styles.css";
|
|
10
|
+
*
|
|
11
|
+
* The arithmetic underneath (`autoLayout`, `routeEdges`, `placeLabels`, the
|
|
12
|
+
* viewport transforms) lives in `@miadi/stateloom-protocol` and is re-exported
|
|
13
|
+
* here, so a host needs one dependency to draw a board rather than two.
|
|
14
|
+
*/
|
|
15
|
+
export { StateMachineCanvas, default } from "./StateMachineCanvas.js";
|
|
16
|
+
export type { CanvasSelection, CanvasTarget, DrawMode, StateMachineCanvasHandle, StateMachineCanvasProps, } from "./StateMachineCanvas.js";
|
|
17
|
+
export { themeStyle, CANVAS_THEME_VARS } from "./theme.js";
|
|
18
|
+
export type { CanvasTheme } from "./theme.js";
|
|
19
|
+
export { childByName, childStatesAt, childrenOf, definedEvents, findState, livePath, parentAt, } from "./drill.js";
|
|
20
|
+
export { autoLayout, AUTO_LAYOUT_DEFAULTS, IDENTITY_VIEWPORT, VIEWPORT_LIMITS, clampScale, fitToBoxes, normalizeViewport, panBy, sameViewport, screenDeltaToWorld, screenToWorld, viewportTransform, worldToScreen, zoomAt, zoomTo, routeEdges, placeLabels, eventGlyph, guardText, } from "@miadi/stateloom-protocol";
|
|
21
|
+
export type { AutoLayoutOptions, Box, FitOptions, LayoutBox, Point, ScaleLimits, StateDef, StateMachineDefinition, TransitionDef, Viewport, } from "@miadi/stateloom-protocol";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @miadi/stateloom-canvas
|
|
3
|
+
*
|
|
4
|
+
* The SMDF design surface as a mountable React component: pan, zoom, drill,
|
|
5
|
+
* drag, routed edges, settled labels, touch gestures and a navigation HUD —
|
|
6
|
+
* driven entirely by props, styled entirely by CSS variables.
|
|
7
|
+
*
|
|
8
|
+
* import { StateMachineCanvas } from "@miadi/stateloom-canvas";
|
|
9
|
+
* import "@miadi/stateloom-canvas/styles.css";
|
|
10
|
+
*
|
|
11
|
+
* The arithmetic underneath (`autoLayout`, `routeEdges`, `placeLabels`, the
|
|
12
|
+
* viewport transforms) lives in `@miadi/stateloom-protocol` and is re-exported
|
|
13
|
+
* here, so a host needs one dependency to draw a board rather than two.
|
|
14
|
+
*/
|
|
15
|
+
export { StateMachineCanvas, default } from "./StateMachineCanvas.js";
|
|
16
|
+
export { themeStyle, CANVAS_THEME_VARS } from "./theme.js";
|
|
17
|
+
export { childByName, childStatesAt, childrenOf, definedEvents, findState, livePath, parentAt, } from "./drill.js";
|
|
18
|
+
// The geometry and the model, re-exported at the address a host reaching for a
|
|
19
|
+
// canvas is already looking at.
|
|
20
|
+
export { autoLayout, AUTO_LAYOUT_DEFAULTS, IDENTITY_VIEWPORT, VIEWPORT_LIMITS, clampScale, fitToBoxes, normalizeViewport, panBy, sameViewport, screenDeltaToWorld, screenToWorld, viewportTransform, worldToScreen, zoomAt, zoomTo, routeEdges, placeLabels, eventGlyph, guardText, } from "@miadi/stateloom-protocol";
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @miadi/stateloom-canvas — the board's own stylesheet.
|
|
3
|
+
*
|
|
4
|
+
* Import once, anywhere in the host app:
|
|
5
|
+
*
|
|
6
|
+
* import "@miadi/stateloom-canvas/styles.css";
|
|
7
|
+
*
|
|
8
|
+
* Every colour is read from a `--slc-*` variable declared on `.slc-pane`, so a
|
|
9
|
+
* host re-skins the entire surface by redeclaring those variables on any
|
|
10
|
+
* ancestor — or by handing a partial `theme` object to the component, which
|
|
11
|
+
* writes them inline. Nothing here depends on a CSS framework.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
.slc-pane {
|
|
15
|
+
/* Material */
|
|
16
|
+
--slc-surface: #030712;
|
|
17
|
+
--slc-node-fill: #0f172a;
|
|
18
|
+
--slc-node-stroke: #475569;
|
|
19
|
+
--slc-composite-fill: #0c1020;
|
|
20
|
+
--slc-final-fill: #1e293b;
|
|
21
|
+
|
|
22
|
+
/* Meaning */
|
|
23
|
+
--slc-accent: #3b82f6;
|
|
24
|
+
--slc-accent-fill: #1e3a5f;
|
|
25
|
+
--slc-accent-ink: #93c5fd;
|
|
26
|
+
--slc-danger: #ef4444;
|
|
27
|
+
--slc-draw-source: #f59e0b;
|
|
28
|
+
--slc-active: #22c55e;
|
|
29
|
+
|
|
30
|
+
/* Lines and chips */
|
|
31
|
+
--slc-edge: #94a3b8;
|
|
32
|
+
--slc-chip-fill: #1e293b;
|
|
33
|
+
--slc-chip-stroke: #334155;
|
|
34
|
+
|
|
35
|
+
/* Ink */
|
|
36
|
+
--slc-label: #e2e8f0;
|
|
37
|
+
--slc-muted: #94a3b8;
|
|
38
|
+
--slc-faint: #64748b;
|
|
39
|
+
--slc-entry: #22c55e;
|
|
40
|
+
--slc-exit: #f97316;
|
|
41
|
+
--slc-composite: #6366f1;
|
|
42
|
+
|
|
43
|
+
/* Floating chrome */
|
|
44
|
+
--slc-panel-bg: rgb(17 24 39 / 0.9);
|
|
45
|
+
--slc-panel-border: #374151;
|
|
46
|
+
--slc-panel-hover: #1f2937;
|
|
47
|
+
|
|
48
|
+
position: relative;
|
|
49
|
+
width: 100%;
|
|
50
|
+
height: 100%;
|
|
51
|
+
/* Nothing in this pane scrolls, and the SVG's refusal of the browser's own
|
|
52
|
+
gestures has to extend to the overlays sitting on top of it — a pinch that
|
|
53
|
+
opens with a finger on the zoom bar would otherwise be a page zoom. */
|
|
54
|
+
touch-action: none;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.slc-surface {
|
|
58
|
+
width: 100%;
|
|
59
|
+
height: 100%;
|
|
60
|
+
display: block;
|
|
61
|
+
background: var(--slc-surface);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* ─── States ──────────────────────────────────────────────────────────────── */
|
|
65
|
+
|
|
66
|
+
.slc-node {
|
|
67
|
+
fill: var(--slc-node-fill);
|
|
68
|
+
stroke: var(--slc-node-stroke);
|
|
69
|
+
stroke-width: 1.5;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.slc-node--final { fill: var(--slc-final-fill); }
|
|
73
|
+
.slc-node--composite { fill: var(--slc-composite-fill); }
|
|
74
|
+
|
|
75
|
+
.slc-node--source {
|
|
76
|
+
fill: var(--slc-accent-fill);
|
|
77
|
+
stroke: var(--slc-draw-source);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.slc-node--error {
|
|
81
|
+
stroke: var(--slc-danger);
|
|
82
|
+
stroke-width: 2;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* Selection is the last word on the outline: it comes after error on purpose,
|
|
86
|
+
so the box the user is looking at is always the box that is outlined. */
|
|
87
|
+
.slc-node--selected {
|
|
88
|
+
stroke: var(--slc-accent);
|
|
89
|
+
stroke-width: 2.5;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.slc-node-name {
|
|
93
|
+
fill: var(--slc-label);
|
|
94
|
+
font-size: 14px;
|
|
95
|
+
font-weight: 600;
|
|
96
|
+
pointer-events: none;
|
|
97
|
+
user-select: none;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.slc-node-kind {
|
|
101
|
+
fill: var(--slc-faint);
|
|
102
|
+
font-size: 10px;
|
|
103
|
+
pointer-events: none;
|
|
104
|
+
user-select: none;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.slc-node-entry { fill: var(--slc-entry); font-size: 9px; pointer-events: none; user-select: none; }
|
|
108
|
+
.slc-node-exit { fill: var(--slc-exit); font-size: 9px; pointer-events: none; user-select: none; }
|
|
109
|
+
.slc-node-warn { fill: var(--slc-danger); font-size: 12px; pointer-events: none; user-select: none; }
|
|
110
|
+
.slc-node-drill { fill: var(--slc-composite); font-size: 9px; pointer-events: none; user-select: none; }
|
|
111
|
+
|
|
112
|
+
/* What the pointer says a box will do. */
|
|
113
|
+
.slc-node--drawing { cursor: crosshair; }
|
|
114
|
+
.slc-node--drillable { cursor: pointer; }
|
|
115
|
+
.slc-node--draggable { cursor: grab; }
|
|
116
|
+
.slc-node--draggable:active { cursor: grabbing; }
|
|
117
|
+
.slc-node--static { cursor: default; }
|
|
118
|
+
|
|
119
|
+
/* ─── Edges ───────────────────────────────────────────────────────────────── */
|
|
120
|
+
|
|
121
|
+
.slc-edge {
|
|
122
|
+
fill: none;
|
|
123
|
+
stroke: var(--slc-edge);
|
|
124
|
+
stroke-width: 1.5;
|
|
125
|
+
cursor: pointer;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.slc-edge:hover { stroke: var(--slc-accent-ink); }
|
|
129
|
+
|
|
130
|
+
.slc-edge--selected {
|
|
131
|
+
stroke: var(--slc-accent);
|
|
132
|
+
stroke-width: 2.5;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.slc-arrowhead { fill: var(--slc-edge); }
|
|
136
|
+
.slc-arrowhead--selected { fill: var(--slc-accent); }
|
|
137
|
+
|
|
138
|
+
/* ─── Event chips ─────────────────────────────────────────────────────────── */
|
|
139
|
+
|
|
140
|
+
.slc-chip { cursor: pointer; }
|
|
141
|
+
|
|
142
|
+
.slc-chip-plate {
|
|
143
|
+
fill: var(--slc-chip-fill);
|
|
144
|
+
stroke: var(--slc-chip-stroke);
|
|
145
|
+
stroke-width: 1;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.slc-chip-plate--selected {
|
|
149
|
+
fill: var(--slc-accent-fill);
|
|
150
|
+
stroke: var(--slc-accent);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.slc-chip-text {
|
|
154
|
+
fill: var(--slc-muted);
|
|
155
|
+
font-size: 11px;
|
|
156
|
+
font-weight: 500;
|
|
157
|
+
pointer-events: none;
|
|
158
|
+
user-select: none;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.slc-chip-text--selected { fill: var(--slc-accent-ink); }
|
|
162
|
+
|
|
163
|
+
.slc-chip-guard {
|
|
164
|
+
fill: var(--slc-faint);
|
|
165
|
+
font-size: 9px;
|
|
166
|
+
user-select: none;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.slc-chip-leader {
|
|
170
|
+
stroke: var(--slc-chip-stroke);
|
|
171
|
+
stroke-width: 1;
|
|
172
|
+
stroke-dasharray: 2 3;
|
|
173
|
+
pointer-events: none;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.slc-chip-leader--selected { stroke: var(--slc-accent); }
|
|
177
|
+
|
|
178
|
+
.slc-glyph {
|
|
179
|
+
fill: none;
|
|
180
|
+
stroke: #7c93b0;
|
|
181
|
+
stroke-linecap: round;
|
|
182
|
+
stroke-linejoin: round;
|
|
183
|
+
pointer-events: none;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.slc-glyph--selected { stroke: var(--slc-accent-ink); }
|
|
187
|
+
.slc-glyph .slc-glyph-dot { fill: #7c93b0; }
|
|
188
|
+
.slc-glyph--selected .slc-glyph-dot { fill: var(--slc-accent-ink); }
|
|
189
|
+
|
|
190
|
+
/* ─── Hints ───────────────────────────────────────────────────────────────── */
|
|
191
|
+
|
|
192
|
+
.slc-draw-hint {
|
|
193
|
+
fill: var(--slc-draw-source);
|
|
194
|
+
font-size: 13px;
|
|
195
|
+
pointer-events: none;
|
|
196
|
+
user-select: none;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.slc-empty {
|
|
200
|
+
fill: var(--slc-faint);
|
|
201
|
+
font-size: 16px;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/* ─── Breadcrumb ──────────────────────────────────────────────────────────── */
|
|
205
|
+
|
|
206
|
+
.slc-crumbs {
|
|
207
|
+
position: absolute;
|
|
208
|
+
top: 0.5rem;
|
|
209
|
+
left: 0.5rem;
|
|
210
|
+
z-index: 10;
|
|
211
|
+
display: flex;
|
|
212
|
+
align-items: center;
|
|
213
|
+
gap: 0.25rem;
|
|
214
|
+
padding: 0.375rem 0.75rem;
|
|
215
|
+
border: 1px solid var(--slc-panel-border);
|
|
216
|
+
border-radius: 0.5rem;
|
|
217
|
+
background: var(--slc-panel-bg);
|
|
218
|
+
font-size: 0.8125rem;
|
|
219
|
+
line-height: 1.25;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.slc-crumb-item { display: flex; align-items: center; gap: 0.25rem; }
|
|
223
|
+
.slc-crumb-sep { color: var(--slc-faint); }
|
|
224
|
+
|
|
225
|
+
.slc-crumb {
|
|
226
|
+
background: none;
|
|
227
|
+
border: 0;
|
|
228
|
+
padding: 0;
|
|
229
|
+
cursor: pointer;
|
|
230
|
+
color: var(--slc-muted);
|
|
231
|
+
font: inherit;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.slc-crumb:hover { color: var(--slc-accent-ink); }
|
|
235
|
+
|
|
236
|
+
.slc-crumb--current {
|
|
237
|
+
color: var(--slc-accent-ink);
|
|
238
|
+
font-weight: 600;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/* ─── Navigation HUD ──────────────────────────────────────────────────────── */
|
|
242
|
+
|
|
243
|
+
.slc-hud {
|
|
244
|
+
position: absolute;
|
|
245
|
+
bottom: 0.75rem;
|
|
246
|
+
left: 0.75rem;
|
|
247
|
+
z-index: 10;
|
|
248
|
+
display: flex;
|
|
249
|
+
align-items: center;
|
|
250
|
+
gap: 0.125rem;
|
|
251
|
+
padding: 0.25rem 0.375rem;
|
|
252
|
+
border: 1px solid var(--slc-panel-border);
|
|
253
|
+
border-radius: 0.5rem;
|
|
254
|
+
background: var(--slc-panel-bg);
|
|
255
|
+
font-size: 0.75rem;
|
|
256
|
+
color: var(--slc-muted);
|
|
257
|
+
user-select: none;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.slc-hud-btn {
|
|
261
|
+
background: none;
|
|
262
|
+
border: 0;
|
|
263
|
+
border-radius: 0.25rem;
|
|
264
|
+
padding: 0.125rem 0.375rem;
|
|
265
|
+
color: inherit;
|
|
266
|
+
font: inherit;
|
|
267
|
+
cursor: pointer;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.slc-hud-btn:hover:not(:disabled) {
|
|
271
|
+
background: var(--slc-panel-hover);
|
|
272
|
+
color: var(--slc-label);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.slc-hud-btn:disabled { opacity: 0.4; cursor: default; }
|
|
276
|
+
|
|
277
|
+
.slc-hud-btn--scale {
|
|
278
|
+
font-variant-numeric: tabular-nums;
|
|
279
|
+
min-width: 3.25rem;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/* A thumb needs the padding a cursor does not. */
|
|
283
|
+
.slc-hud--coarse .slc-hud-btn { padding: 0.5rem 0.75rem; }
|
|
284
|
+
|
|
285
|
+
.slc-hud-sep { color: var(--slc-panel-border); padding: 0 0.125rem; }
|
|
286
|
+
|
|
287
|
+
.slc-hud-hint {
|
|
288
|
+
padding: 0 0.25rem;
|
|
289
|
+
font-size: 0.625rem;
|
|
290
|
+
color: var(--slc-faint);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/* ─── Event picker ────────────────────────────────────────────────────────── */
|
|
294
|
+
|
|
295
|
+
.slc-picker {
|
|
296
|
+
position: absolute;
|
|
297
|
+
z-index: 50;
|
|
298
|
+
min-width: 160px;
|
|
299
|
+
padding: 0.5rem;
|
|
300
|
+
border: 1px solid var(--slc-panel-border);
|
|
301
|
+
border-radius: 0.5rem;
|
|
302
|
+
background: var(--slc-panel-bg);
|
|
303
|
+
box-shadow: 0 10px 25px rgb(0 0 0 / 0.45);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
.slc-picker-title { font-size: 0.75rem; color: var(--slc-muted); padding: 0 0.25rem 0.25rem; }
|
|
307
|
+
.slc-picker-sub { font-size: 0.75rem; color: var(--slc-faint); padding: 0 0.25rem 0.25rem; }
|
|
308
|
+
.slc-picker-empty { font-size: 0.75rem; color: var(--slc-faint); padding: 0.5rem 0.25rem; }
|
|
309
|
+
|
|
310
|
+
.slc-picker-item {
|
|
311
|
+
display: block;
|
|
312
|
+
width: 100%;
|
|
313
|
+
text-align: left;
|
|
314
|
+
background: none;
|
|
315
|
+
border: 0;
|
|
316
|
+
border-radius: 0.25rem;
|
|
317
|
+
padding: 0.25rem 0.5rem;
|
|
318
|
+
color: var(--slc-label);
|
|
319
|
+
font: inherit;
|
|
320
|
+
font-size: 0.875rem;
|
|
321
|
+
cursor: pointer;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
.slc-picker-item:hover { background: var(--slc-panel-hover); }
|
|
325
|
+
|
|
326
|
+
.slc-picker-cancel {
|
|
327
|
+
display: block;
|
|
328
|
+
width: 100%;
|
|
329
|
+
text-align: left;
|
|
330
|
+
margin-top: 0.25rem;
|
|
331
|
+
padding: 0.25rem 0.5rem;
|
|
332
|
+
border: 0;
|
|
333
|
+
border-top: 1px solid var(--slc-panel-border);
|
|
334
|
+
background: none;
|
|
335
|
+
color: var(--slc-faint);
|
|
336
|
+
font: inherit;
|
|
337
|
+
font-size: 0.75rem;
|
|
338
|
+
cursor: pointer;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
.slc-picker-cancel:hover { color: var(--slc-label); }
|
|
342
|
+
|
|
343
|
+
/* ─── Live animation ──────────────────────────────────────────────────────── */
|
|
344
|
+
|
|
345
|
+
/* Node bloom-in: fade + scale from ~0.92 to 1 around the node's own center. */
|
|
346
|
+
@keyframes slc-node-in {
|
|
347
|
+
from { opacity: 0; transform: scale(0.92); }
|
|
348
|
+
to { opacity: 1; transform: scale(1); }
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/* Node fade-out: fade + scale down as the state leaves the definition. */
|
|
352
|
+
@keyframes slc-node-out {
|
|
353
|
+
from { opacity: 1; transform: scale(1); }
|
|
354
|
+
to { opacity: 0; transform: scale(0.9); }
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/* Edge draw-on: reveal the stroke (pathLength=1 normalises the dash units). */
|
|
358
|
+
@keyframes slc-edge-draw {
|
|
359
|
+
from { stroke-dashoffset: 1; opacity: 0; }
|
|
360
|
+
to { stroke-dashoffset: 0; opacity: 1; }
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/* Runtime-active pulse: a glow that layers over any stroke. */
|
|
364
|
+
@keyframes slc-pulse {
|
|
365
|
+
0%, 100% { filter: drop-shadow(0 0 1px rgb(34 197 94 / 0.55)); }
|
|
366
|
+
50% { filter: drop-shadow(0 0 6px rgb(34 197 94 / 0.95)); }
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
.slc-node-enter {
|
|
370
|
+
transform-box: fill-box;
|
|
371
|
+
transform-origin: center;
|
|
372
|
+
animation: slc-node-in 220ms ease-out both;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
.slc-node-exit-group {
|
|
376
|
+
transform-box: fill-box;
|
|
377
|
+
transform-origin: center;
|
|
378
|
+
pointer-events: none;
|
|
379
|
+
animation: slc-node-out 200ms ease-in forwards;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
.slc-edge-enter {
|
|
383
|
+
stroke-dasharray: 1;
|
|
384
|
+
animation: slc-edge-draw 260ms ease-out both;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
.slc-node--active {
|
|
388
|
+
stroke: var(--slc-active);
|
|
389
|
+
animation: slc-pulse 1.2s ease-in-out infinite;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
@media (prefers-reduced-motion: reduce) {
|
|
393
|
+
.slc-node-enter,
|
|
394
|
+
.slc-edge-enter { animation: none; }
|
|
395
|
+
/* Keep exit near-instant so onAnimationEnd still fires and the node is
|
|
396
|
+
cleaned up from the exiting layer. */
|
|
397
|
+
.slc-node-exit-group { animation-duration: 1ms; }
|
|
398
|
+
/* Drop the infinite motion but keep a static glow so active states stay
|
|
399
|
+
distinguishable without relying on motion. */
|
|
400
|
+
.slc-node--active {
|
|
401
|
+
animation: none;
|
|
402
|
+
filter: drop-shadow(0 0 4px rgb(34 197 94 / 0.85));
|
|
403
|
+
}
|
|
404
|
+
}
|
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the canvas looks like, expressed as CSS custom properties.
|
|
3
|
+
*
|
|
4
|
+
* Every colour the board paints is read from a `--slc-*` variable declared on
|
|
5
|
+
* the canvas pane, never written into an SVG `fill=` attribute. That single
|
|
6
|
+
* rule is what makes the surface portable: the stylesheet ships one dark
|
|
7
|
+
* default set, and a host application re-skins the entire board — nodes,
|
|
8
|
+
* edges, chips, HUD — by declaring the same variables on any ancestor, or by
|
|
9
|
+
* handing a partial `theme` to the component.
|
|
10
|
+
*
|
|
11
|
+
* The names are the contract. They are stable, and a host that overrides one
|
|
12
|
+
* it does not recognise simply has no effect rather than an error.
|
|
13
|
+
*/
|
|
14
|
+
export interface CanvasTheme {
|
|
15
|
+
/** The board itself. */
|
|
16
|
+
surface: string;
|
|
17
|
+
/** Ordinary state box fill / stroke. */
|
|
18
|
+
nodeFill: string;
|
|
19
|
+
nodeStroke: string;
|
|
20
|
+
/** A state that owns children. */
|
|
21
|
+
compositeFill: string;
|
|
22
|
+
/** A final state. */
|
|
23
|
+
finalFill: string;
|
|
24
|
+
/** The selected element — box outline, edge, chip. */
|
|
25
|
+
accent: string;
|
|
26
|
+
accentFill: string;
|
|
27
|
+
accentInk: string;
|
|
28
|
+
/** A state failing validation. */
|
|
29
|
+
danger: string;
|
|
30
|
+
/** The state a transition is being drawn from. */
|
|
31
|
+
drawSource: string;
|
|
32
|
+
/** Edges and their arrowheads. */
|
|
33
|
+
edge: string;
|
|
34
|
+
/** Chip plate under an event label. */
|
|
35
|
+
chipFill: string;
|
|
36
|
+
chipStroke: string;
|
|
37
|
+
/** Text. */
|
|
38
|
+
label: string;
|
|
39
|
+
muted: string;
|
|
40
|
+
faint: string;
|
|
41
|
+
/** `onEntry` / `onExit` markers on a box. */
|
|
42
|
+
entry: string;
|
|
43
|
+
exit: string;
|
|
44
|
+
/** The drill-down hint under a composite. */
|
|
45
|
+
composite: string;
|
|
46
|
+
/** Runtime-active glow. */
|
|
47
|
+
active: string;
|
|
48
|
+
/** Floating chrome: HUD, breadcrumb, event picker. */
|
|
49
|
+
panelBg: string;
|
|
50
|
+
panelBorder: string;
|
|
51
|
+
panelHover: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Turn a partial theme into the inline style that carries it.
|
|
55
|
+
*
|
|
56
|
+
* Only the keys given are emitted, so anything left out keeps whatever the
|
|
57
|
+
* stylesheet — or an ancestor's own declaration — already says.
|
|
58
|
+
*/
|
|
59
|
+
export declare function themeStyle(theme?: Partial<CanvasTheme>): Record<string, string>;
|
|
60
|
+
/** The variable names, for a host that would rather write CSS than props. */
|
|
61
|
+
export declare const CANVAS_THEME_VARS: Readonly<Record<keyof CanvasTheme, string>>;
|
package/dist/theme.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the canvas looks like, expressed as CSS custom properties.
|
|
3
|
+
*
|
|
4
|
+
* Every colour the board paints is read from a `--slc-*` variable declared on
|
|
5
|
+
* the canvas pane, never written into an SVG `fill=` attribute. That single
|
|
6
|
+
* rule is what makes the surface portable: the stylesheet ships one dark
|
|
7
|
+
* default set, and a host application re-skins the entire board — nodes,
|
|
8
|
+
* edges, chips, HUD — by declaring the same variables on any ancestor, or by
|
|
9
|
+
* handing a partial `theme` to the component.
|
|
10
|
+
*
|
|
11
|
+
* The names are the contract. They are stable, and a host that overrides one
|
|
12
|
+
* it does not recognise simply has no effect rather than an error.
|
|
13
|
+
*/
|
|
14
|
+
/** The variable name a theme key is written to. */
|
|
15
|
+
const VAR = {
|
|
16
|
+
surface: "--slc-surface",
|
|
17
|
+
nodeFill: "--slc-node-fill",
|
|
18
|
+
nodeStroke: "--slc-node-stroke",
|
|
19
|
+
compositeFill: "--slc-composite-fill",
|
|
20
|
+
finalFill: "--slc-final-fill",
|
|
21
|
+
accent: "--slc-accent",
|
|
22
|
+
accentFill: "--slc-accent-fill",
|
|
23
|
+
accentInk: "--slc-accent-ink",
|
|
24
|
+
danger: "--slc-danger",
|
|
25
|
+
drawSource: "--slc-draw-source",
|
|
26
|
+
edge: "--slc-edge",
|
|
27
|
+
chipFill: "--slc-chip-fill",
|
|
28
|
+
chipStroke: "--slc-chip-stroke",
|
|
29
|
+
label: "--slc-label",
|
|
30
|
+
muted: "--slc-muted",
|
|
31
|
+
faint: "--slc-faint",
|
|
32
|
+
entry: "--slc-entry",
|
|
33
|
+
exit: "--slc-exit",
|
|
34
|
+
composite: "--slc-composite",
|
|
35
|
+
active: "--slc-active",
|
|
36
|
+
panelBg: "--slc-panel-bg",
|
|
37
|
+
panelBorder: "--slc-panel-border",
|
|
38
|
+
panelHover: "--slc-panel-hover",
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Turn a partial theme into the inline style that carries it.
|
|
42
|
+
*
|
|
43
|
+
* Only the keys given are emitted, so anything left out keeps whatever the
|
|
44
|
+
* stylesheet — or an ancestor's own declaration — already says.
|
|
45
|
+
*/
|
|
46
|
+
export function themeStyle(theme) {
|
|
47
|
+
const style = {};
|
|
48
|
+
if (!theme)
|
|
49
|
+
return style;
|
|
50
|
+
for (const [key, value] of Object.entries(theme)) {
|
|
51
|
+
const name = VAR[key];
|
|
52
|
+
if (name && typeof value === "string")
|
|
53
|
+
style[name] = value;
|
|
54
|
+
}
|
|
55
|
+
return style;
|
|
56
|
+
}
|
|
57
|
+
/** The variable names, for a host that would rather write CSS than props. */
|
|
58
|
+
export const CANVAS_THEME_VARS = VAR;
|
|
59
|
+
//# sourceMappingURL=theme.js.map
|