@statewalker/fsm-charts 0.2.5 → 0.2.7
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 +213 -1
- package/dist/StateChart-cXyVRcs-.d.ts +94 -0
- package/dist/StateChart-cXyVRcs-.d.ts.map +1 -0
- package/dist/StateChartIndex-BK2315qj.d.ts +142 -0
- package/dist/StateChartIndex-BK2315qj.d.ts.map +1 -0
- package/dist/StateChartIndex-BOIrc_nq.js +355 -0
- package/dist/StateChartIndex-BOIrc_nq.js.map +1 -0
- package/dist/buildStatechartsPanel-BX7e0GzA.js +494 -0
- package/dist/buildStatechartsPanel-BX7e0GzA.js.map +1 -0
- package/dist/buildStatechartsPanel-hCtZbdiF.d.ts +79 -0
- package/dist/buildStatechartsPanel-hCtZbdiF.d.ts.map +1 -0
- package/dist/defineProperty-C0rC37pP.js +39 -0
- package/dist/description-panels-DI2MNlbK.js +184 -0
- package/dist/description-panels-DI2MNlbK.js.map +1 -0
- package/dist/getLabelDimensions-BY0q7j3D.d.ts +79 -0
- package/dist/getLabelDimensions-BY0q7j3D.d.ts.map +1 -0
- package/dist/getPadding-Cw0e7G2v.js +25 -0
- package/dist/getPadding-Cw0e7G2v.js.map +1 -0
- package/dist/index-config.d.ts +3 -12
- package/dist/index-config.js +2 -2
- package/dist/index-dom.d.ts +2 -49
- package/dist/index-dom.js +2 -2
- package/dist/index-html.d.ts +3 -2
- package/dist/index-html.js +2 -3
- package/dist/index-layout.d.ts +3 -77
- package/dist/index-layout.js +2 -3
- package/dist/index-runtime.d.ts +3 -141
- package/dist/index-runtime.js +2 -2
- package/dist/index.d.ts +11 -10
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -7
- package/dist/layout-Dp671N6q.js +2465 -0
- package/dist/layout-Dp671N6q.js.map +1 -0
- package/dist/newTreeBuilder-CvtLDjGj.d.ts +54 -0
- package/dist/newTreeBuilder-CvtLDjGj.d.ts.map +1 -0
- package/dist/toFsmStateConfig-DlJkyZni.js +135 -0
- package/dist/toFsmStateConfig-DlJkyZni.js.map +1 -0
- package/dist/toFsmStateConfig-DmOlTRjv.d.ts +15 -0
- package/dist/toFsmStateConfig-DmOlTRjv.d.ts.map +1 -0
- package/package.json +52 -27
- package/src/config/concatTransitionsToString.ts +2 -2
- package/src/config/splitTransitionString.ts +1 -3
- package/src/config/toFsmStateConfig.ts +2 -9
- package/src/dom/buildSections.ts +3 -11
- package/src/dom/description-panels.ts +2 -4
- package/src/dom/getStatesDescriptions.ts +3 -9
- package/src/html/buildStatechartStyles.ts +4 -14
- package/src/html/buildStatechartSvg.ts +2 -14
- package/src/html/buildStatechartsPanel.ts +1 -3
- package/src/layout/buildCharts.ts +1 -2
- package/src/layout/buildFlatCharts.ts +6 -8
- package/src/layout/getGraphParamsProvider.ts +3 -12
- package/src/runtime/RuntimeStatechartApi.ts +10 -32
- package/src/runtime/StateChartIndex.ts +6 -23
- package/src/types/GraphParamsProvider.ts +1 -4
- package/src/utils/BasisCurve.ts +5 -14
- package/src/utils/domToText.ts +2 -6
- package/src/utils/getPadding.ts +1 -2
- package/src/utils/newId.ts +2 -1
- package/src/utils/newRegistry.ts +12 -12
- package/src/utils/serializeAttrs.ts +3 -13
- package/src/utils/serializeCss.ts +1 -5
- package/src/utils/serializeStyle.ts +1 -4
- package/src/utils/toKebabCase.ts +1 -4
- package/dist/StateChart-BYBjTmC2.d.ts +0 -82
- package/dist/chunk-2LFUT2C6.js +0 -2691
- package/dist/chunk-ARZYBFNA.js +0 -133
- package/dist/chunk-CR2M4445.js +0 -608
- package/dist/chunk-FIQDLBWD.js +0 -9
- package/dist/chunk-GW2Z65BN.js +0 -429
- package/dist/chunk-PKBMQBKP.js +0 -5
- package/dist/chunk-RZ4FP6JB.js +0 -233
- package/dist/index-html-BBQqYoST.d.ts +0 -75
- package/src/full/index.ts +0 -1
- package/src/full/toFsmStateCharts.ts +0 -119
package/README.md
CHANGED
|
@@ -1 +1,213 @@
|
|
|
1
|
-
# @statewalker/fsm-charts
|
|
1
|
+
# @statewalker/fsm-charts
|
|
2
|
+
|
|
3
|
+
## What it is: statechart layout and rendering for HFSM configurations
|
|
4
|
+
|
|
5
|
+
Turns a hierarchical state machine (HFSM) configuration (`{ key, transitions, states }`,
|
|
6
|
+
the format `@statewalker/fsm` runs) into a statechart. It lays the chart out with a
|
|
7
|
+
vendored copy of dagre, writes SVG/HTML and CSS as strings, and provides a runtime API
|
|
8
|
+
that highlights states and transitions on the rendered chart. `@statewalker/fsm-viewer`
|
|
9
|
+
builds a ready-made browser viewer on top of it.
|
|
10
|
+
|
|
11
|
+
## Why it exists: a nested state machine is hard to read as JSON
|
|
12
|
+
|
|
13
|
+
A configuration with several levels of nested states and wildcard transitions is hard to
|
|
14
|
+
follow as text. This package draws each composite state as its own chart, nested the same
|
|
15
|
+
way the states are, so the structure and the transitions out of every state are visible.
|
|
16
|
+
It works from the configuration alone and does not import `@statewalker/fsm`, so drawing
|
|
17
|
+
a machine does not require running it.
|
|
18
|
+
|
|
19
|
+
## How to use: lay out, render to strings, then bind to the DOM
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
pnpm add @statewalker/fsm-charts lodash-es
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The package has no runtime dependencies, but the layout functions need a lodash object
|
|
26
|
+
passed in as the `lodash` option. Either `lodash` or `lodash-es` works.
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
FsmStateConfig --buildCharts--> StateChart --buildStatechartsPanel--> HTML + SVG strings
|
|
30
|
+
| --buildStatechartCss-----> CSS string
|
|
31
|
+
|
|
|
32
|
+
+--> StateChartIndex (key <-> id lookups)
|
|
33
|
+
+--> RuntimeStatechartApi (highlight, panels, clicks on the DOM)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The main entry point is the package root, `@statewalker/fsm-charts` (`dist/index.js` with
|
|
37
|
+
`.d.ts` types; sources are published in `src/`); each area also has its own subpath entry
|
|
38
|
+
(see [Internals](#internals-vendored-layout-injected-lodash)). It is ESM only.
|
|
39
|
+
|
|
40
|
+
The `config`, `layout` and `html` functions produce plain strings and objects and run
|
|
41
|
+
anywhere, including Node.js. The `dom` helpers and `RuntimeStatechartApi` work on DOM
|
|
42
|
+
elements and need a browser or a DOM implementation such as jsdom.
|
|
43
|
+
|
|
44
|
+
### What each export is for
|
|
45
|
+
|
|
46
|
+
**Config**
|
|
47
|
+
|
|
48
|
+
- `serializeProcessConfig(config)` - format a configuration as JSON text with one
|
|
49
|
+
transition per line.
|
|
50
|
+
- `splitTransitionString(str)` - parse a chain such as `"Idle -play-> Active -stop-> Idle"`
|
|
51
|
+
into `[from, event, to]` tuples; `concatTransitionsToString(transitions)` does the
|
|
52
|
+
reverse.
|
|
53
|
+
- `toFsmStateConfig(json)` - normalize a loosely written configuration (transitions as
|
|
54
|
+
strings or arrays, duplicates removed) into an `FsmStateConfig` (`undefined` when `json`
|
|
55
|
+
has no string `key`).
|
|
56
|
+
|
|
57
|
+
**Layout**
|
|
58
|
+
|
|
59
|
+
- `buildCharts({ lodash, config, newId, ...graphParams })` - lay out the whole state
|
|
60
|
+
tree. Returns a `StateChart` (nested charts with nodes, edges, sizes). Options:
|
|
61
|
+
`direction`, `vertical`, `padding`, `getStateLabel`, `initialStateKey`
|
|
62
|
+
(default `"<initial>"`), `finalStateKey` (default `"<final>"`).
|
|
63
|
+
- `buildFlatCharts(...)` - lay out one flat transition graph (a `TransitionsGraph`).
|
|
64
|
+
- `getGraphParamsProvider({ fontSize, stateFontSize, stateTextPadding, transitionsFontSize, transitionsTextPadding, ... })`
|
|
65
|
+
- default `getStateParams` / `getTransitionParams` functions that size nodes and
|
|
66
|
+
edges from their labels.
|
|
67
|
+
- `getLabelDimensions(label, options)` - estimate label size from font size and
|
|
68
|
+
character width.
|
|
69
|
+
|
|
70
|
+
**HTML and CSS**
|
|
71
|
+
|
|
72
|
+
- `buildStatechartsPanel({ statechart, newId, println })` - write nested `<details>`
|
|
73
|
+
panels, one per state (the root and every nested `states` entry), with an SVG chart in
|
|
74
|
+
each state that has transitions.
|
|
75
|
+
- `buildStatechartSvg({ graph, newId, println, ... })` - write the SVG of one chart.
|
|
76
|
+
- `buildStatechartCss({ prefix })` - the stylesheet for the charts, scoped to `prefix`
|
|
77
|
+
(default `:root`). `buildStatechartStyles`, `buildStatechartStylesWithModifier`,
|
|
78
|
+
`buildStateDetailsStyle`, `buildStateDetailsStyleWithModifier` and the
|
|
79
|
+
`activeStatesStyle` / `activeTransitionsStyle` / `selectedStatesStyle` /
|
|
80
|
+
`selectedTransitionsStyle` objects are its building blocks.
|
|
81
|
+
- `serializeCss(tree)` and `toKebabCase(str)` - CSS helpers.
|
|
82
|
+
|
|
83
|
+
**DOM** (browser)
|
|
84
|
+
|
|
85
|
+
- `buildSections`, `visitSectionNodes`, `vistSections`, `findSection`, `visitDom`,
|
|
86
|
+
`toDomNodesIterator`, `isDomElement` - split a document into sections by headings.
|
|
87
|
+
- `getStatesDescriptions({ element, rootStateKey })`, `visitStateDescriptions` - read
|
|
88
|
+
per-state descriptions from a document section whose heading matches the root state.
|
|
89
|
+
- `getStateDescriptionRenderer`, `renderSections`, `newTreeBuilder` - helpers to render
|
|
90
|
+
those descriptions.
|
|
91
|
+
|
|
92
|
+
**Runtime**
|
|
93
|
+
|
|
94
|
+
- `StateChartIndex({ statechart })` - lookups over a built chart: `getStatesIds(...keys)`,
|
|
95
|
+
`getStackByStateId(id)`, `getTransitions(stateId)`, `getEdgeById(id)`,
|
|
96
|
+
`getStateNodes()` and more.
|
|
97
|
+
- `RuntimeStatechartApi({ element, statechart })` - acts on the rendered chart:
|
|
98
|
+
`selectState` / `deselectState(s)`, `selectTransition` / `deselectTransition(s)`
|
|
99
|
+
with a modifier (`"selected"` by default, `"active"` for the running state),
|
|
100
|
+
`openStatePanel` / `closeStatePanel(s)`, `setStateDescription`, `onStateClick`,
|
|
101
|
+
`onTransitionClick`, `close()`.
|
|
102
|
+
|
|
103
|
+
Types such as `StateChart`, `StateGraphNode`, `StateGraphEdge`, `FsmStateConfig` and
|
|
104
|
+
`GraphParamsProvider` are exported as well.
|
|
105
|
+
|
|
106
|
+
## Examples
|
|
107
|
+
|
|
108
|
+
### Draw a configuration and highlight a state
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
import * as lodash from "lodash-es";
|
|
112
|
+
import {
|
|
113
|
+
buildCharts,
|
|
114
|
+
buildStatechartCss,
|
|
115
|
+
buildStatechartsPanel,
|
|
116
|
+
getGraphParamsProvider,
|
|
117
|
+
RuntimeStatechartApi,
|
|
118
|
+
StateChartIndex,
|
|
119
|
+
} from "@statewalker/fsm-charts";
|
|
120
|
+
|
|
121
|
+
let counter = 0;
|
|
122
|
+
const newId = (prefix) => `${prefix}-${++counter}`;
|
|
123
|
+
|
|
124
|
+
const config = {
|
|
125
|
+
key: "Player",
|
|
126
|
+
transitions: [
|
|
127
|
+
["", "*", "Idle"],
|
|
128
|
+
["Idle", "play", "Active"],
|
|
129
|
+
["*", "stop", "Idle"],
|
|
130
|
+
],
|
|
131
|
+
states: [
|
|
132
|
+
{ key: "Idle" },
|
|
133
|
+
{
|
|
134
|
+
key: "Active",
|
|
135
|
+
transitions: [
|
|
136
|
+
["", "*", "Playing"],
|
|
137
|
+
["Playing", "pause", "Paused"],
|
|
138
|
+
["Paused", "play", "Playing"],
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// 1. Layout: nested charts with node and edge geometry.
|
|
145
|
+
const statechart = buildCharts({
|
|
146
|
+
lodash,
|
|
147
|
+
config,
|
|
148
|
+
newId,
|
|
149
|
+
direction: "lr", // "tb" | "bt" | "lr" | "rl"
|
|
150
|
+
...getGraphParamsProvider({ fontSize: 12 }),
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// 2. Render: HTML (nested <details> panels with SVG charts) and CSS.
|
|
154
|
+
const lines = [];
|
|
155
|
+
buildStatechartsPanel({ statechart, newId, println: (line) => lines.push(line) });
|
|
156
|
+
const element = document.createElement("div");
|
|
157
|
+
element.id = "chart";
|
|
158
|
+
element.innerHTML = lines.join("\n");
|
|
159
|
+
const style = document.createElement("style");
|
|
160
|
+
style.textContent = buildStatechartCss({ prefix: "#chart" });
|
|
161
|
+
element.append(style);
|
|
162
|
+
document.body.append(element);
|
|
163
|
+
|
|
164
|
+
// 3. Runtime: map state keys to chart ids and highlight them.
|
|
165
|
+
const index = new StateChartIndex({ statechart });
|
|
166
|
+
const api = new RuntimeStatechartApi({ element, statechart });
|
|
167
|
+
for (const id of index.getStatesIds("Player", "Active", "Playing")) {
|
|
168
|
+
api.selectState(id, "active");
|
|
169
|
+
api.openStatePanel(id);
|
|
170
|
+
}
|
|
171
|
+
api.onStateClick((stateId) => console.log(index.getStackByStateId(stateId)));
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Print a configuration compactly
|
|
175
|
+
|
|
176
|
+
```js
|
|
177
|
+
import { serializeProcessConfig, splitTransitionString } from "@statewalker/fsm-charts";
|
|
178
|
+
|
|
179
|
+
console.log(serializeProcessConfig(config)); // JSON text, one transition per line
|
|
180
|
+
console.log(splitTransitionString("Idle -play-> Active -stop-> Idle"));
|
|
181
|
+
// [["Idle", "play", "Active"], ["Active", "stop", "Idle"]]
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Internals: vendored layout, injected lodash
|
|
185
|
+
|
|
186
|
+
- **Layout.** `buildCharts` walks the state tree and lays out each composite state as a
|
|
187
|
+
separate flat graph with `buildFlatCharts`, which uses the vendored dagre and graphlib
|
|
188
|
+
sources in `src/dagre` and `src/graphlib`. Pseudo-states are drawn as `"<initial>"` and
|
|
189
|
+
`"<final>"` nodes (a `"*"` source becomes a node keyed `"*"`); both keys can be changed
|
|
190
|
+
with `initialStateKey` / `finalStateKey`, and the same values must then be passed to
|
|
191
|
+
`buildStatechartsPanel` / `buildStatechartSvg` and `StateChartIndex`, which default to
|
|
192
|
+
the same two keys.
|
|
193
|
+
- **Rendering is string output.** `buildStatechartsPanel` and `buildStatechartSvg` write
|
|
194
|
+
lines through a `println` callback instead of creating DOM nodes, so the same code
|
|
195
|
+
renders in a browser, in Node.js, or into a file.
|
|
196
|
+
- **Styling is by CSS variables and modifiers.** `buildStatechartCss` emits rules for the
|
|
197
|
+
`selected` and `active` modifiers that `RuntimeStatechartApi` toggles, scoped to a
|
|
198
|
+
`prefix` selector so several charts can share a page.
|
|
199
|
+
- **lodash is injected.** The vendored dagre code calls lodash through a module-level
|
|
200
|
+
holder that `buildFlatCharts` sets from the `lodash` option, so the host decides which
|
|
201
|
+
lodash build ends up in its bundle. Without it, layout fails with
|
|
202
|
+
`TypeError: Cannot read properties of undefined (reading 'has')`.
|
|
203
|
+
- **Entry points by area.** Besides the package root (everything, including the
|
|
204
|
+
`serializeCss` / `toKebabCase` helpers, which no subpath exports), each area is its own
|
|
205
|
+
entry: `@statewalker/fsm-charts/config`, `/layout`, `/html`, `/dom` and `/runtime`. Layout
|
|
206
|
+
and HTML generation import no DOM code, so a Node.js or worker build can take
|
|
207
|
+
`/layout` and `/html` alone.
|
|
208
|
+
- **Dependencies.** Zero runtime dependencies. dagre and graphlib are vendored; lodash
|
|
209
|
+
comes from the caller.
|
|
210
|
+
|
|
211
|
+
## License
|
|
212
|
+
|
|
213
|
+
MIT.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
//#region src/types/Dimensions.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Visual element dimensions.
|
|
4
|
+
* @typedef {Object} Dimensions
|
|
5
|
+
*/
|
|
6
|
+
type Dimensions = {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/types/Transition.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* A transition from one state to another.
|
|
14
|
+
* Contains the state before the transition, the event that triggers the transition, and the state after the transition.
|
|
15
|
+
*/
|
|
16
|
+
type Transition = [string, string, string];
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/types/FsmStateConfig.d.ts
|
|
19
|
+
type FsmStateConfig = {
|
|
20
|
+
key: string;
|
|
21
|
+
transitions?: Transition[];
|
|
22
|
+
states?: FsmStateConfig[];
|
|
23
|
+
} & Record<string, any>;
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/types/Label.d.ts
|
|
26
|
+
/**
|
|
27
|
+
* Human-readable label
|
|
28
|
+
*/
|
|
29
|
+
type Label = {
|
|
30
|
+
text: string;
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/types/GraphParamsProvider.d.ts
|
|
34
|
+
/**
|
|
35
|
+
* Provides default functions measuring dimensions for state nodes and transition edges in the graph.
|
|
36
|
+
*/
|
|
37
|
+
type GraphParamsProvider = {
|
|
38
|
+
getStateParams: (stateKey: string, state?: string) => Dimensions & Label & Record<string, any>;
|
|
39
|
+
getTransitionParams: (fromStateKey: string, event: string, toStateKey: string) => Dimensions & Label & Record<string, any>;
|
|
40
|
+
};
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/types/Padding.d.ts
|
|
43
|
+
/**
|
|
44
|
+
* Padding type.
|
|
45
|
+
*/
|
|
46
|
+
type Padding = [number, number, number, number] | [number, number] | number;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/types/Position.d.ts
|
|
49
|
+
/**
|
|
50
|
+
* X/Y position of a node in the graph.
|
|
51
|
+
*/
|
|
52
|
+
type Position = {
|
|
53
|
+
x: number;
|
|
54
|
+
y: number;
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/types/StateGraphNode.d.ts
|
|
58
|
+
/**
|
|
59
|
+
* Information about a state node in the graph.
|
|
60
|
+
*/
|
|
61
|
+
type StateGraphNode = Dimensions & Position & {
|
|
62
|
+
id: string;
|
|
63
|
+
key: string;
|
|
64
|
+
text: string;
|
|
65
|
+
} & Record<string, any>;
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/types/StateGraphEdge.d.ts
|
|
68
|
+
/**
|
|
69
|
+
* Information about a state graph edge.
|
|
70
|
+
*/
|
|
71
|
+
type StateGraphEdge = Dimensions & Position & {
|
|
72
|
+
id: string;
|
|
73
|
+
from: string;
|
|
74
|
+
event: string;
|
|
75
|
+
to: string;
|
|
76
|
+
points: Position[];
|
|
77
|
+
} & Record<string, any>;
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/types/TransitionsGraph.d.ts
|
|
80
|
+
/**
|
|
81
|
+
* Coordinates for state nodes and endges corresponding to state transitions.
|
|
82
|
+
*/
|
|
83
|
+
type TransitionsGraph = Position & Dimensions & {
|
|
84
|
+
nodes: StateGraphNode[];
|
|
85
|
+
edges: StateGraphEdge[];
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/types/StateChart.d.ts
|
|
89
|
+
type StateChart = TransitionsGraph & StateGraphNode & {
|
|
90
|
+
children?: StateChart[];
|
|
91
|
+
} & Record<string, any>;
|
|
92
|
+
//#endregion
|
|
93
|
+
export { Position as a, Label as c, Dimensions as d, StateGraphNode as i, FsmStateConfig as l, TransitionsGraph as n, Padding as o, StateGraphEdge as r, GraphParamsProvider as s, StateChart as t, Transition as u };
|
|
94
|
+
//# sourceMappingURL=StateChart-cXyVRcs-.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StateChart-cXyVRcs-.d.ts","names":[],"sources":["../src/types/Dimensions.ts","../src/types/Transition.ts","../src/types/FsmStateConfig.ts","../src/types/Label.ts","../src/types/GraphParamsProvider.ts","../src/types/Padding.ts","../src/types/Position.ts","../src/types/StateGraphNode.ts","../src/types/StateGraphEdge.ts","../src/types/TransitionsGraph.ts","../src/types/StateChart.ts"],"mappings":";;;;;KAIY;EACV;EACA;;;;;;;;KCFU;;;KCOA;EACV;EACA,cAAc;EACd,SAAS;IACP;;;;;;KCZQ;EAEV;;;;;;;KCCU;EACV,iBAAiB,kBAAkB,mBAAmB,aAAa,QAAQ;EAC3E,sBACE,sBACA,eACA,uBACG,aAAa,QAAQ;;;;;;;KCThB;;;;;;KCAA;EAAa;EAAW;;;;;;;KCGxB,iBAAiB,aAC3B;EACE;EACA;EACA;IAEE;;;;;;KCNM,iBAAiB,aAC3B;EACE;EACA;EACA;EACA;EACA,QAAQ;IACN;;;;;;KCLM,mBAAmB,WAC7B;EACE,OAAO;EACP,OAAO;;;;KCRC,aAAa,mBACvB;EACE,WAAW;IACT"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { i as StateGraphNode, r as StateGraphEdge, t as StateChart } from "./StateChart-cXyVRcs-.js";
|
|
2
|
+
//#region src/runtime/RuntimeStatechartApi.d.ts
|
|
3
|
+
type RuntimeListener = (id: string) => void;
|
|
4
|
+
declare class RuntimeStatechartApi {
|
|
5
|
+
element: HTMLElement;
|
|
6
|
+
statechart: StateChart;
|
|
7
|
+
_listenersCounter: number;
|
|
8
|
+
_transitionsClickListeners: Record<number, RuntimeListener>;
|
|
9
|
+
_statesClickListeners: Record<number, RuntimeListener>;
|
|
10
|
+
_registry: Record<number, () => void>;
|
|
11
|
+
constructor({ element, statechart }: {
|
|
12
|
+
element: HTMLElement;
|
|
13
|
+
statechart: StateChart;
|
|
14
|
+
});
|
|
15
|
+
close(): void;
|
|
16
|
+
onStateClick(listener: RuntimeListener): () => void;
|
|
17
|
+
onTransitionClick(listener: RuntimeListener): () => void;
|
|
18
|
+
openStatePanels(): void;
|
|
19
|
+
closeStatePanels(): void;
|
|
20
|
+
isStatePanelOpen(stateId: string): boolean;
|
|
21
|
+
toggleState(...stateIds: string[]): boolean;
|
|
22
|
+
activateStates(...stateIds: string[]): void;
|
|
23
|
+
focusStates(...stateIds: string[]): void;
|
|
24
|
+
setStateDescription(stateId: string, description: Node | string | undefined): void;
|
|
25
|
+
closeStatePanel(stateId: string): void;
|
|
26
|
+
openStatePanel(stateId: string): void;
|
|
27
|
+
deselectTransitions(modifier?: string): void;
|
|
28
|
+
deselectTransition(id: string, modifier?: string): void;
|
|
29
|
+
selectTransition(id: string, modifier?: string): void;
|
|
30
|
+
toggleTransition(id: string, modifier?: string): void;
|
|
31
|
+
isTransitionSelected(id: string, modifier?: string): boolean;
|
|
32
|
+
deselectStates(modifier?: string): void;
|
|
33
|
+
isStateSelected(id: string, modifier?: string): boolean;
|
|
34
|
+
deselectState(id: string, modifier?: string): void;
|
|
35
|
+
selectState(id: string, modifier?: string): void;
|
|
36
|
+
_addListener<T = Function>(index: Record<string, T>, listener: T): () => void;
|
|
37
|
+
_bindListeners(): void;
|
|
38
|
+
_setStatePanelStatus(selector: string, open: boolean): void;
|
|
39
|
+
_addStateModifier(cssSelector: string, modifier?: string): void;
|
|
40
|
+
_removeStateModifier(cssSelector: string, modifier?: string): void;
|
|
41
|
+
_applyStateModifier(cssSelector: string, modifier: string | undefined, apply: (elm: Element | null, className: string) => void): void;
|
|
42
|
+
_addTransitionsModifier(cssSelector: string, modifier?: string): void;
|
|
43
|
+
_removeTransitionsModifier(cssSelector: string, modifier?: string): void;
|
|
44
|
+
_applyTransitionsModifier(cssSelector: string, modifier: string | undefined, apply: (elm: Element | null, className: string) => void): void;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/runtime/StateChartIndex.d.ts
|
|
48
|
+
declare class StateChartIndex {
|
|
49
|
+
statechart: StateChart;
|
|
50
|
+
_chartsIndex: Record<string, StateChart>;
|
|
51
|
+
_nodesIndex: Record<string, StateGraphNode>;
|
|
52
|
+
_nodesParentsIndex: Record<string, string>;
|
|
53
|
+
_edgeIndex: Record<string, StateGraphEdge>;
|
|
54
|
+
_edgesParentsIndex: Record<string, string>;
|
|
55
|
+
initialStateKey: string;
|
|
56
|
+
finalStateKey: string;
|
|
57
|
+
constructor({ statechart, initialStateKey, finalStateKey }: {
|
|
58
|
+
statechart: StateChart;
|
|
59
|
+
initialStateKey?: string;
|
|
60
|
+
finalStateKey?: string;
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* Returns a state node or a chart by the specified identifier.
|
|
64
|
+
* @param id the id of a state node or a chart
|
|
65
|
+
* @returns a state node or a chart
|
|
66
|
+
*/
|
|
67
|
+
getNodeById(id: string): StateGraphNode | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Returns a chart by the specified identifier.
|
|
70
|
+
* @param id the id of a state node or a chart
|
|
71
|
+
* @returns a state node or a chart
|
|
72
|
+
*/
|
|
73
|
+
getChartById(id: string): StateChart | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Returns an edge by the specified identifier.
|
|
76
|
+
* @param id the id of a graph edge
|
|
77
|
+
* @returns a graph edge
|
|
78
|
+
*/
|
|
79
|
+
getEdgeById(id: string): StateGraphEdge | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Returns a list of all nodes in this chart.
|
|
82
|
+
* @return a list of all nodes
|
|
83
|
+
*/
|
|
84
|
+
getAllNodes(): StateGraphNode[];
|
|
85
|
+
/**
|
|
86
|
+
* Returns a list of all non-empty state nodes in this chart.
|
|
87
|
+
* The result excludes nodes for initial and fina states.
|
|
88
|
+
* @return a list of all non-empty state nodes
|
|
89
|
+
*/
|
|
90
|
+
getStateNodes(): StateGraphNode[];
|
|
91
|
+
/**
|
|
92
|
+
* Transforms a stack of state keys to the corresponding identifiers.
|
|
93
|
+
* If a key in the stack was not found then this method returns
|
|
94
|
+
* an empty stack.
|
|
95
|
+
* @param stack a stack of state keys
|
|
96
|
+
* @returns a stack of state identifiers for the given states
|
|
97
|
+
*/
|
|
98
|
+
getStatesIds(...stack: string[]): string[];
|
|
99
|
+
/**
|
|
100
|
+
* Returns graph nodes for the specified identifier.
|
|
101
|
+
* @param id the id of a node
|
|
102
|
+
* @returns a stack of nodes
|
|
103
|
+
*/
|
|
104
|
+
getStackByStateId(id?: string): StateGraphNode[];
|
|
105
|
+
/**
|
|
106
|
+
* Returns an edge object corresponding to the transition from the state
|
|
107
|
+
* @param stateId identifier of the source state
|
|
108
|
+
* @param event an event triggering the transition
|
|
109
|
+
* @returns graph edge
|
|
110
|
+
*/
|
|
111
|
+
getTransition(stateId?: string, event?: string): StateGraphEdge | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* Returns a list of edge objects corresponding to all transitions from the state
|
|
114
|
+
* @param stateId identifier of the source state
|
|
115
|
+
* @returns a list of graph edges
|
|
116
|
+
*/
|
|
117
|
+
getTransitions(stateId?: string): StateGraphEdge[];
|
|
118
|
+
/**
|
|
119
|
+
* Returns a graph node corresponding to the specified state id.
|
|
120
|
+
* @param stateId identifier of the state
|
|
121
|
+
* @returns graph node
|
|
122
|
+
* @see getStateChart
|
|
123
|
+
*/
|
|
124
|
+
getStateNode(stateId?: string): StateGraphNode | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* Returns a chart corresponding to the specified state id.
|
|
127
|
+
* @param stateId identifier of the state
|
|
128
|
+
* @returns graph node
|
|
129
|
+
* @see getStateNode
|
|
130
|
+
*/
|
|
131
|
+
getStateChart(stateId?: string): StateChart | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* Returns ids of the previous and next state for the specified transition
|
|
134
|
+
* @param transition a graph edge instance defining transition
|
|
135
|
+
* @returns an array with two identifiers - [sourceStateId, targetStateId] - the source state id and target state id
|
|
136
|
+
*/
|
|
137
|
+
getTransitionStateIds(transition?: StateGraphEdge): [string | undefined, string | undefined];
|
|
138
|
+
_buildIndexes(): void;
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
export { RuntimeListener as n, RuntimeStatechartApi as r, StateChartIndex as t };
|
|
142
|
+
//# sourceMappingURL=StateChartIndex-BK2315qj.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StateChartIndex-BK2315qj.d.ts","names":[],"sources":["../src/runtime/RuntimeStatechartApi.ts","../src/runtime/StateChartIndex.ts"],"mappings":";;KAEY,mBAAmB;cAClB;EACX,SAAS;EACT,YAAY;EACZ;EACA,4BAA4B,eAAe;EAC3C,uBAAuB,eAAe;EACtC,WAAW;EAEX,cACE,SACA;IAEA,SAAS;IACT,YAAY;;EAOd;EAOA,aAAa,UAAU;EAGvB,kBAAkB,UAAU;EAI5B;EAGA;EAGA,iBAAiB;EAOjB,eAAe;EAaf,kBAAkB;EAQlB,eAAe;EAUf,oBAAoB,iBAAiB,aAAa;EAUlD,gBAAgB;EAGhB,eAAe;EAIf,oBAAoB;EAGpB,mBAAmB,YAAY;EAG/B,iBAAiB,YAAY;EAG7B,iBAAiB,YAAY;EAS7B,qBAAqB,YAAY;EAMjC,eAAe;EAGf,gBAAgB,YAAY;EAK5B,cAAc,YAAY;EAG1B,YAAY,YAAY;EAMxB,aAAa,IAAI,UAAU,OAAO,eAAe,IAAI,UAAU;EAQ/D;EA+BA,qBAAqB,kBAAkB;EAOvC,kBAAkB,qBAAqB;EAGvC,qBAAqB,qBAAqB;EAG1C,oBACE,qBACA,8BACA,QAAQ,KAAK,gBAAgB;EAgB/B,wBAAwB,qBAAqB;EAG7C,2BAA2B,qBAAqB;EAGhD,0BACE,qBACA,8BACA,QAAQ,KAAK,gBAAgB;;;;cCzNpB;EACX,YAAY;EACZ,cAAc,eAAe;EAC7B,aAAa,eAAe;EAC5B,oBAAoB;EACpB,YAAY,eAAe;EAC3B,oBAAoB;EACpB;EACA;EAEA,cACE,YACA,iBACA;IAEA,YAAY;IACZ;IACA;;;;;;;EAcF,YAAY,aAAa;;;;;;EASzB,aAAa,aAAa;;;;;;EAS1B,YAAY,aAAa;;;;;EAQzB,eAAe;;;;;;EASf,iBAAiB;;;;;;;;EAajB,gBAAgB;;;;;;EAkBhB,kBAAkB,cAAc;;;;;;;EAqBhC,cAAc,kBAAkB,iBAAiB;;;;;;EAcjD,eAAe,mBAAmB;;;;;;;EAclC,aAAa,mBAAmB;;;;;;;EAUhC,cAAc,mBAAmB;;;;;;EASjC,sBAAsB,aAAa;EAoBnC"}
|