@statewalker/fsm-charts 0.0.4 → 0.0.6
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/StateChart-pFSQIvtE.d.ts +77 -0
- package/dist/{chunk-DX2ZO7QN.js → chunk-FYTJYHEQ.js} +24 -14
- package/dist/{chunk-ASIV3YDZ.js → chunk-IT7GBMYV.js} +1 -1
- package/dist/chunk-X2UPWZLX.js +4 -0
- package/dist/chunk-XEO3YXBM.js +8 -0
- package/dist/index-layout.d.ts +3 -28
- package/dist/index-layout.js +2 -1
- package/dist/index-runtime.d.ts +5 -0
- package/dist/index-runtime.js +2 -0
- package/dist/{index-svg-DW8Cf450.d.ts → index-svg-DCwEyX8X.d.ts} +1 -1
- package/dist/index-svg.d.ts +2 -2
- package/dist/index-svg.js +2 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -2
- package/package.json +1 -1
- package/src/index-layout.ts +1 -0
- package/src/index-runtime.ts +2 -0
- package/src/index-svg.ts +1 -0
- package/src/index.ts +4 -2
- package/src/layout/buildCharts.ts +5 -13
- package/src/layout/buildFlatCharts.ts +9 -8
- package/src/layout/getGraphParamsProvider.ts +4 -3
- package/src/layout/getLabelDimensions.ts +2 -2
- package/src/layout/index.ts +0 -10
- package/src/runtime/index.ts +211 -0
- package/src/svg/buildStatechartStyles.ts +3 -0
- package/src/svg/buildStatechartSvg.ts +1 -1
- package/src/svg/buildStatechartsPanel.ts +12 -6
- package/src/types/FsmStateConfig.ts +7 -0
- package/src/{layout → types}/StateChart.ts +1 -2
- package/src/{layout → types}/StateGraphEdge.ts +2 -2
- package/src/{layout → types}/StateGraphNode.ts +2 -2
- package/src/types/TransitionsGraph.ts +13 -0
- package/src/types/index.ts +10 -0
- package/src/utils/getPadding.ts +1 -1
- package/dist/StateChart-DNGQd1XG.d.ts +0 -53
- package/src/FsmStateConfig.ts +0 -5
- package/src/layout/TransitionsGraph.ts +0 -13
- /package/src/{layout → types}/Dimensions.ts +0 -0
- /package/src/{layout → types}/GraphParamsProvider.ts +0 -0
- /package/src/{layout → types}/Padding.ts +0 -0
- /package/src/{layout → types}/Position.ts +0 -0
- /package/src/{layout → types}/Transition.ts +0 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Visual element dimensions.
|
|
3
|
+
* @typedef {Object} Dimensions
|
|
4
|
+
*/
|
|
5
|
+
type Dimensions = {
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A transition from one state to another.
|
|
12
|
+
* Contains the state before the transition, the event that triggers the transition, and the state after the transition.
|
|
13
|
+
*/
|
|
14
|
+
type Transition = [string, string, string];
|
|
15
|
+
|
|
16
|
+
type FsmStateConfig = {
|
|
17
|
+
key: string;
|
|
18
|
+
transitions: Transition[];
|
|
19
|
+
states?: FsmStateConfig[];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Provides default functions measuring dimensions for state nodes and transition edges in the graph.
|
|
24
|
+
*/
|
|
25
|
+
type GraphParamsProvider = {
|
|
26
|
+
getStateParams: (stateKey: string, state?: string) => Dimensions & Record<string, any>;
|
|
27
|
+
getTransitionParams: (fromStateKey: string, event: string, toStateKey: string) => Dimensions & Record<string, any>;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Padding type.
|
|
32
|
+
*/
|
|
33
|
+
type Padding = [number, number, number, number] | [number, number] | number;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* X/Y position of a node in the graph.
|
|
37
|
+
*/
|
|
38
|
+
type Position = {
|
|
39
|
+
x: number;
|
|
40
|
+
y: number;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Information about a state graph edge.
|
|
45
|
+
*/
|
|
46
|
+
type StateGraphEdge = Dimensions & Position & {
|
|
47
|
+
id: string;
|
|
48
|
+
from: string;
|
|
49
|
+
event: string;
|
|
50
|
+
to: string;
|
|
51
|
+
points: Position[];
|
|
52
|
+
} & Record<string, any>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Information about a state node in the graph.
|
|
56
|
+
*/
|
|
57
|
+
type StateGraphNode = Dimensions & Position & {
|
|
58
|
+
id: string;
|
|
59
|
+
key: string;
|
|
60
|
+
state: string;
|
|
61
|
+
} & Record<string, any>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Coordinates for state nodes and endges corresponding to state transitions.
|
|
65
|
+
*/
|
|
66
|
+
type TransitionsGraph = Position & Dimensions & {
|
|
67
|
+
nodes: StateGraphNode[];
|
|
68
|
+
edges: StateGraphEdge[];
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
type StateChart = TransitionsGraph & {
|
|
72
|
+
id: string;
|
|
73
|
+
key: string;
|
|
74
|
+
children?: StateChart[];
|
|
75
|
+
} & Record<string, any>;
|
|
76
|
+
|
|
77
|
+
export type { Dimensions as D, FsmStateConfig as F, GraphParamsProvider as G, Padding as P, StateChart as S, Transition as T, Position as a, StateGraphEdge as b, StateGraphNode as c, TransitionsGraph as d };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getPadding } from './chunk-NXWOFQMO.js';
|
|
2
|
+
import { __publicField } from './chunk-XEO3YXBM.js';
|
|
2
3
|
|
|
3
4
|
// src/utils/toKebabCase.ts
|
|
4
5
|
function toKebabCase2(str) {
|
|
@@ -141,12 +142,14 @@ function buildStatechartStyles({
|
|
|
141
142
|
fill: "var(--transition-background-color, rgba(255,255,255,0.7))",
|
|
142
143
|
stroke: "var(--transition-border-color, none)",
|
|
143
144
|
strokeWidth: "var(--transition-border-width, 1px)",
|
|
144
|
-
borderRadius: "0.5em"
|
|
145
|
+
borderRadius: "0.5em",
|
|
146
|
+
cursor: "pointer"
|
|
145
147
|
},
|
|
146
148
|
".transition__label": {
|
|
147
149
|
fill: "var(--transition-label-color, currentColor)",
|
|
148
150
|
fontSize: "var(--transition-label-font-size, 12px)",
|
|
149
|
-
fontFamily: "var(--transition-label-font-family, sans-serif)"
|
|
151
|
+
fontFamily: "var(--transition-label-font-family, sans-serif)",
|
|
152
|
+
cursor: "pointer"
|
|
150
153
|
},
|
|
151
154
|
// ----------------------------------------------
|
|
152
155
|
// States
|
|
@@ -181,7 +184,8 @@ function buildStatechartStyles({
|
|
|
181
184
|
fill: "var(--state-background-color, white)",
|
|
182
185
|
stroke: "var(--state-border-color, currentColor)",
|
|
183
186
|
strokeWidth: "var(--state-border-width, 1px)",
|
|
184
|
-
borderRadius: "0.5em"
|
|
187
|
+
borderRadius: "0.5em",
|
|
188
|
+
cursor: "pointer"
|
|
185
189
|
},
|
|
186
190
|
".state__label": {
|
|
187
191
|
color: "var(--state-label-color, currentColor)",
|
|
@@ -239,14 +243,14 @@ function serializeAttrs(attrs = {}, {
|
|
|
239
243
|
|
|
240
244
|
// src/utils/BasisCurve.ts
|
|
241
245
|
var BasisCurve = class {
|
|
242
|
-
_context;
|
|
243
|
-
_x0 = 0;
|
|
244
|
-
_y0 = 0;
|
|
245
|
-
_x1 = 0;
|
|
246
|
-
_y1 = 0;
|
|
247
|
-
_point = 0;
|
|
248
|
-
_line = 0;
|
|
249
246
|
constructor(context) {
|
|
247
|
+
__publicField(this, "_context");
|
|
248
|
+
__publicField(this, "_x0", 0);
|
|
249
|
+
__publicField(this, "_y0", 0);
|
|
250
|
+
__publicField(this, "_x1", 0);
|
|
251
|
+
__publicField(this, "_y1", 0);
|
|
252
|
+
__publicField(this, "_point", 0);
|
|
253
|
+
__publicField(this, "_line", 0);
|
|
250
254
|
this._context = context;
|
|
251
255
|
}
|
|
252
256
|
$point(x, y) {
|
|
@@ -506,12 +510,18 @@ function buildStatechartsPanel({
|
|
|
506
510
|
}) {
|
|
507
511
|
render(statechart, println);
|
|
508
512
|
function render(statechart2, println2) {
|
|
509
|
-
println2(
|
|
510
|
-
|
|
511
|
-
|
|
513
|
+
println2(
|
|
514
|
+
` <details class="state-details" data-state-id="${statechart2.id}">`
|
|
515
|
+
);
|
|
516
|
+
println2(
|
|
517
|
+
` <summary class="state-details__label">${statechart2.key}</summary>`
|
|
518
|
+
);
|
|
519
|
+
println2(
|
|
520
|
+
` <div class="state-details__description"><div class="state-details__chart">`
|
|
521
|
+
);
|
|
512
522
|
const printChildren = (str) => println2(` ${str}`);
|
|
513
523
|
buildStatechartSvg({
|
|
514
|
-
graph: statechart2
|
|
524
|
+
graph: statechart2,
|
|
515
525
|
newId,
|
|
516
526
|
println: printChildren,
|
|
517
527
|
initialStateKey,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { __publicField };
|
package/dist/index-layout.d.ts
CHANGED
|
@@ -1,24 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Provides default functions measuring dimensions for state nodes and transition edges in the graph.
|
|
6
|
-
*/
|
|
7
|
-
type GraphParamsProvider = {
|
|
8
|
-
getStateParams: (stateKey: string, state?: string) => Dimensions & Record<string, any>;
|
|
9
|
-
getTransitionParams: (fromStateKey: string, event: string, toStateKey: string) => Dimensions & Record<string, any>;
|
|
10
|
-
};
|
|
11
|
-
|
|
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
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Padding type.
|
|
20
|
-
*/
|
|
21
|
-
type Padding = [number, number, number, number] | [number, number] | number;
|
|
1
|
+
import { T as Transition, P as Padding, G as GraphParamsProvider, d as TransitionsGraph, F as FsmStateConfig, S as StateChart } from './StateChart-pFSQIvtE.js';
|
|
2
|
+
export { D as Dimensions, a as Position, b as StateGraphEdge, c as StateGraphNode } from './StateChart-pFSQIvtE.js';
|
|
22
3
|
|
|
23
4
|
/**
|
|
24
5
|
* Build graphs corresponding to the specified transitions.
|
|
@@ -41,12 +22,6 @@ declare function buildFlatCharts({ lodash, transitions, newId, getStateParams, g
|
|
|
41
22
|
padding?: Padding;
|
|
42
23
|
} & GraphParamsProvider): TransitionsGraph;
|
|
43
24
|
|
|
44
|
-
type FsmStateConfig = {
|
|
45
|
-
key: string;
|
|
46
|
-
transitions: [string, string, string][];
|
|
47
|
-
states?: FsmStateConfig[];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
25
|
/**
|
|
51
26
|
* Build graphs corresponding to the specified transitions.
|
|
52
27
|
* @param config - State configuration with transitions and sub-states.
|
|
@@ -93,4 +68,4 @@ lineGap, }?: {
|
|
|
93
68
|
height: number;
|
|
94
69
|
};
|
|
95
70
|
|
|
96
|
-
export {
|
|
71
|
+
export { FsmStateConfig, GraphParamsProvider, Padding, StateChart, Transition, TransitionsGraph, buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions };
|
package/dist/index-layout.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './chunk-
|
|
1
|
+
export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './chunk-IT7GBMYV.js';
|
|
2
2
|
import './chunk-NXWOFQMO.js';
|
|
3
|
+
import './chunk-XEO3YXBM.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { D as Dimensions, F as FsmStateConfig, G as GraphParamsProvider, P as Padding, a as Position, S as StateChart, b as StateGraphEdge, c as StateGraphNode, T as Transition, d as TransitionsGraph } from './StateChart-pFSQIvtE.js';
|
|
2
|
+
|
|
3
|
+
declare const a = "a";
|
|
4
|
+
|
|
5
|
+
export { a };
|
package/dist/index-svg.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { b as
|
|
2
|
-
|
|
1
|
+
export { D as Dimensions, F as FsmStateConfig, G as GraphParamsProvider, P as Padding, a as Position, S as StateChart, b as StateGraphEdge, c as StateGraphNode, T as Transition, d as TransitionsGraph } from './StateChart-pFSQIvtE.js';
|
|
2
|
+
export { b as buildStatechartCss, c as buildStatechartStyles, d as buildStatechartSvg, a as buildStatechartsPanel } from './index-svg-DCwEyX8X.js';
|
package/dist/index-svg.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { buildStatechartCss, buildStatechartStyles, buildStatechartSvg, buildStatechartsPanel } from './chunk-
|
|
1
|
+
export { buildStatechartCss, buildStatechartStyles, buildStatechartSvg, buildStatechartsPanel } from './chunk-FYTJYHEQ.js';
|
|
2
2
|
import './chunk-NXWOFQMO.js';
|
|
3
|
+
import './chunk-XEO3YXBM.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { GraphParamsProvider, Padding,
|
|
2
|
-
export {
|
|
3
|
-
export { C as CssTree, b as buildStatechartCss, c as buildStatechartStyles, d as buildStatechartSvg, a as buildStatechartsPanel, s as serializeCss } from './index-svg-
|
|
1
|
+
export { D as Dimensions, F as FsmStateConfig, G as GraphParamsProvider, P as Padding, a as Position, S as StateChart, b as StateGraphEdge, c as StateGraphNode, T as Transition, d as TransitionsGraph } from './StateChart-pFSQIvtE.js';
|
|
2
|
+
export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './index-layout.js';
|
|
3
|
+
export { C as CssTree, b as buildStatechartCss, c as buildStatechartStyles, d as buildStatechartSvg, a as buildStatechartsPanel, s as serializeCss } from './index-svg-DCwEyX8X.js';
|
|
4
|
+
export { a } from './index-runtime.js';
|
|
4
5
|
|
|
5
6
|
declare function toKebabCase(str: string): string;
|
|
6
7
|
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './chunk-
|
|
2
|
-
export { buildStatechartCss, buildStatechartStyles, buildStatechartSvg, buildStatechartsPanel, serializeCss, toKebabCase } from './chunk-
|
|
1
|
+
export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './chunk-IT7GBMYV.js';
|
|
2
|
+
export { buildStatechartCss, buildStatechartStyles, buildStatechartSvg, buildStatechartsPanel, serializeCss, toKebabCase } from './chunk-FYTJYHEQ.js';
|
|
3
3
|
import './chunk-NXWOFQMO.js';
|
|
4
|
+
export { a } from './chunk-X2UPWZLX.js';
|
|
5
|
+
import './chunk-XEO3YXBM.js';
|
package/package.json
CHANGED
package/src/index-layout.ts
CHANGED
package/src/index-svg.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export * from "./index
|
|
2
|
-
export * from "./index
|
|
1
|
+
export * from "./types/index.ts";
|
|
2
|
+
export * from "./layout/index.ts";
|
|
3
|
+
export * from "./svg/index.ts";
|
|
4
|
+
export * from "./runtime/index.ts";
|
|
3
5
|
export * from "./utils/toKebabCase.ts";
|
|
4
6
|
export * from "./utils/serializeCss.ts";
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import type { GraphParamsProvider } from "
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type { Position } from "./Position.ts";
|
|
6
|
-
import type { Dimensions } from "./Dimensions.ts";
|
|
7
|
-
import type { FsmStateConfig } from "../FsmStateConfig.ts";
|
|
8
|
-
import type { StateChart } from "./StateChart.ts";
|
|
1
|
+
import type { GraphParamsProvider } from "../types/GraphParamsProvider.ts";
|
|
2
|
+
import type { Padding } from "../types/Padding.ts";
|
|
3
|
+
import type { FsmStateConfig } from "../types/FsmStateConfig.ts";
|
|
4
|
+
import type { StateChart } from "../types/StateChart.ts";
|
|
9
5
|
|
|
10
|
-
import { layout } from "../dagre/layout.js";
|
|
11
|
-
import { Graph } from "../graphlib/graph.js";
|
|
12
|
-
import { getPadding } from "../utils/getPadding.ts";
|
|
13
|
-
import { getLodash, setLodash } from "../lodash-es/index.ts";
|
|
14
6
|
import { buildFlatCharts } from "./buildFlatCharts.ts";
|
|
15
7
|
/**
|
|
16
8
|
* Build graphs corresponding to the specified transitions.
|
|
@@ -67,7 +59,7 @@ export function buildCharts({
|
|
|
67
59
|
return {
|
|
68
60
|
id,
|
|
69
61
|
key: config.key,
|
|
70
|
-
graph,
|
|
62
|
+
...graph,
|
|
71
63
|
children,
|
|
72
64
|
};
|
|
73
65
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { layout } from "../dagre/layout.js";
|
|
2
2
|
import { Graph } from "../graphlib/graph.js";
|
|
3
3
|
|
|
4
|
-
import type { GraphParamsProvider } from "
|
|
5
|
-
import type { Transition } from "
|
|
6
|
-
import type { TransitionsGraph } from "
|
|
7
|
-
import type { StateGraphNode } from "
|
|
8
|
-
import type { StateGraphEdge } from "
|
|
9
|
-
import { Padding } from "
|
|
4
|
+
import type { GraphParamsProvider } from "../types/GraphParamsProvider.ts";
|
|
5
|
+
import type { Transition } from "../types/Transition.ts";
|
|
6
|
+
import type { TransitionsGraph } from "../types/TransitionsGraph.ts";
|
|
7
|
+
import type { StateGraphNode } from "../types/StateGraphNode.ts";
|
|
8
|
+
import type { StateGraphEdge } from "../types/StateGraphEdge.ts";
|
|
9
|
+
import type { Padding } from "../types/Padding.ts";
|
|
10
|
+
import type { Position } from "../types/Position.ts";
|
|
11
|
+
import type { Dimensions } from "../types/Dimensions.ts";
|
|
12
|
+
|
|
10
13
|
import { getPadding } from "../utils/getPadding.ts";
|
|
11
|
-
import { Position } from "./Position.ts";
|
|
12
|
-
import { Dimensions } from "./Dimensions.ts";
|
|
13
14
|
import { getLodash, setLodash } from "../lodash-es/index.ts";
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { Dimensions } from "
|
|
1
|
+
import type { Dimensions } from "../types/Dimensions.ts";
|
|
2
|
+
import type { GraphParamsProvider } from "../types/GraphParamsProvider.ts";
|
|
3
|
+
import type { Padding } from "../types/Padding.ts";
|
|
4
|
+
|
|
2
5
|
import { getLabelDimensions } from "./getLabelDimensions.ts";
|
|
3
6
|
import { getPadding } from "../utils/getPadding.ts";
|
|
4
|
-
import type { GraphParamsProvider } from "./GraphParamsProvider.ts";
|
|
5
|
-
import type { Padding } from "./Padding.ts";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Provides default functions measuring dimensions for state nodes and transition edges in the graph.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Dimensions } from "
|
|
2
|
-
import type { Padding } from "
|
|
1
|
+
import type { Dimensions } from "../types/Dimensions.ts";
|
|
2
|
+
import type { Padding } from "../types/Padding.ts";
|
|
3
3
|
import { getPadding } from "../utils/getPadding.ts";
|
|
4
4
|
|
|
5
5
|
export function getLabelDimensions(
|
package/src/layout/index.ts
CHANGED
|
@@ -3,13 +3,3 @@ export * from "./buildFlatCharts.ts";
|
|
|
3
3
|
export * from "./buildCharts.ts";
|
|
4
4
|
export * from "./getGraphParamsProvider.ts";
|
|
5
5
|
export * from "./getLabelDimensions.ts";
|
|
6
|
-
|
|
7
|
-
// Types
|
|
8
|
-
export * from "./Dimensions.ts";
|
|
9
|
-
export * from "./GraphParamsProvider.ts";
|
|
10
|
-
export * from "./Padding.ts";
|
|
11
|
-
export * from "./Position.ts";
|
|
12
|
-
export * from "./StateGraphEdge.ts";
|
|
13
|
-
export * from "./StateGraphNode.ts";
|
|
14
|
-
export * from "./Transition.ts";
|
|
15
|
-
export * from "./TransitionsGraph.ts";
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
export const a = "a";
|
|
2
|
+
|
|
3
|
+
// class RuntimeStatechartsApi {
|
|
4
|
+
// constructor({ element, statechart }) {
|
|
5
|
+
// this.element = element;
|
|
6
|
+
// this.statechart = statechart;
|
|
7
|
+
// // this._statesIndex = {};
|
|
8
|
+
// // this._transitionsIndex = {};
|
|
9
|
+
// // this._buildIndexes(this.statechart);
|
|
10
|
+
// }
|
|
11
|
+
|
|
12
|
+
// _applyStateModifier(cssSelector, modifier = "selected", apply) {
|
|
13
|
+
// const detailsModifier = `state-details--${modifier}`;
|
|
14
|
+
// const stateLabelsModifier = `state-details__label--${modifier}`;
|
|
15
|
+
// const stateModifier = `state--${modifier}`;
|
|
16
|
+
// [...this.element.querySelectorAll(cssSelector)].forEach((elm) => {
|
|
17
|
+
// if (elm.tagName.toLowerCase() === "details") {
|
|
18
|
+
// apply(elm, detailsModifier);
|
|
19
|
+
// const labelElm = elm.querySelector(".state-details__label");
|
|
20
|
+
// if (labelElm) apply(labelElm, stateLabelsModifier);
|
|
21
|
+
// } else {
|
|
22
|
+
// apply(elm, stateModifier);
|
|
23
|
+
// }
|
|
24
|
+
// });
|
|
25
|
+
// }
|
|
26
|
+
|
|
27
|
+
// _applyTransitionsModifier(cssSelector, modifier = "selected", action) {}
|
|
28
|
+
|
|
29
|
+
// deselectAllTransitions() {
|
|
30
|
+
// const removeClass = (elm, cls) => elm.classList.remove(cls);
|
|
31
|
+
// this._applyTransitionsModifier(
|
|
32
|
+
// "[data-transition-id]",
|
|
33
|
+
// "selected",
|
|
34
|
+
// removeClass
|
|
35
|
+
// );
|
|
36
|
+
// }
|
|
37
|
+
// deselectTransitions(...ids) {
|
|
38
|
+
// const removeClass = (elm, cls) => elm.classList.remove(cls);
|
|
39
|
+
// for (const id of ids) {
|
|
40
|
+
// this._applyTransitionsModifier(
|
|
41
|
+
// `[data-transition-id="${id}"]`,
|
|
42
|
+
// "selected",
|
|
43
|
+
// removeClass
|
|
44
|
+
// );
|
|
45
|
+
// }
|
|
46
|
+
// }
|
|
47
|
+
// selectTransitions(...ids) {
|
|
48
|
+
// const addClass = (elm, cls) => elm.classList.add(cls);
|
|
49
|
+
// for (const id of ids) {
|
|
50
|
+
// this._applyTransitionsModifier(
|
|
51
|
+
// `[data-transition-id="${id}"]`,
|
|
52
|
+
// "selected",
|
|
53
|
+
// addClass
|
|
54
|
+
// );
|
|
55
|
+
// }
|
|
56
|
+
// }
|
|
57
|
+
|
|
58
|
+
// deselectAllStates() {
|
|
59
|
+
// const removeClass = (elm, cls) => elm.classList.remove(cls);
|
|
60
|
+
// this._applyStateModifier("[data-state-id]", "selected", removeClass);
|
|
61
|
+
// }
|
|
62
|
+
// deselectStates(...ids) {
|
|
63
|
+
// const removeClass = (elm, cls) => elm.classList.remove(cls);
|
|
64
|
+
// for (const id of ids) {
|
|
65
|
+
// this._applyStateModifier(
|
|
66
|
+
// `[data-state-id="${id}"]`,
|
|
67
|
+
// "selected",
|
|
68
|
+
// removeClass
|
|
69
|
+
// );
|
|
70
|
+
// }
|
|
71
|
+
// }
|
|
72
|
+
// selectStates(...ids) {
|
|
73
|
+
// const addClass = (elm, cls) => elm.classList.add(cls);
|
|
74
|
+
// for (const id of ids) {
|
|
75
|
+
// this._applyStateModifier(`[data-state-id="${id}"]`, "selected", addClass);
|
|
76
|
+
// }
|
|
77
|
+
// }
|
|
78
|
+
|
|
79
|
+
// // -----------------------------------------------
|
|
80
|
+
// // Access to charts data
|
|
81
|
+
// // - get state ids by stack of state keys
|
|
82
|
+
// // - get stack of states by state id
|
|
83
|
+
// // - get transitionId by stateId + event
|
|
84
|
+
// // - get targetId, sourceId, event by transitionId
|
|
85
|
+
// getStatesIds(...stack) {
|
|
86
|
+
// let statechart = this.statechart;
|
|
87
|
+
// let result = [];
|
|
88
|
+
// if (statechart.key === stack[0]) {
|
|
89
|
+
// result.push(statechart.id);
|
|
90
|
+
// for (let i = 1; i < stack.length; i++) {
|
|
91
|
+
// const key = stack[i];
|
|
92
|
+
// let id = statechart.graph.nodes.find((node) => node.key === key)?.id;
|
|
93
|
+
// if (!id) break;
|
|
94
|
+
// result.push(id);
|
|
95
|
+
// statechart = (statechart.children || []).find(
|
|
96
|
+
// (child) => child.key === key
|
|
97
|
+
// );
|
|
98
|
+
// }
|
|
99
|
+
// }
|
|
100
|
+
// return result.length === stack.length ? result : [];
|
|
101
|
+
// }
|
|
102
|
+
|
|
103
|
+
// getStackByStateId(id) {
|
|
104
|
+
// return this._getStack(id, ({ id, key }) => key);
|
|
105
|
+
// }
|
|
106
|
+
|
|
107
|
+
// getTransition(stateId, event) {
|
|
108
|
+
// const stack = this._getStack(stateId);
|
|
109
|
+
// const state = stack.pop();
|
|
110
|
+
// if (!state || !stack.length) return;
|
|
111
|
+
// const parent = stack[stack.length - 1];
|
|
112
|
+
// const t = parent.graph.edges.find(
|
|
113
|
+
// (t) => t.from === state.key && t.event === event
|
|
114
|
+
// );
|
|
115
|
+
// if (!t) return;
|
|
116
|
+
// const to = parent.graph.nodes.find((n) => n.key === t.to);
|
|
117
|
+
// return to && { id: t.id, fromId: state.id, event: t.event, toId: to.id };
|
|
118
|
+
// }
|
|
119
|
+
|
|
120
|
+
// _getStack(id, get = (d) => d) {
|
|
121
|
+
// return findById(this.statechart, id, get);
|
|
122
|
+
|
|
123
|
+
// function findById(statechart, id, get, stack = []) {
|
|
124
|
+
// try {
|
|
125
|
+
// stack.push(get(statechart));
|
|
126
|
+
// if (statechart.id === id) {
|
|
127
|
+
// return [...stack];
|
|
128
|
+
// } else {
|
|
129
|
+
// let node = statechart.graph.nodes.find((node) => node.id === id);
|
|
130
|
+
// if (node) {
|
|
131
|
+
// return [...stack, get(node)];
|
|
132
|
+
// } else {
|
|
133
|
+
// let result;
|
|
134
|
+
// if (statechart.children) {
|
|
135
|
+
// for (const child of statechart.children) {
|
|
136
|
+
// result = findById(child, id, get, stack);
|
|
137
|
+
// if (result) break;
|
|
138
|
+
// }
|
|
139
|
+
// }
|
|
140
|
+
// return result;
|
|
141
|
+
// }
|
|
142
|
+
// }
|
|
143
|
+
// } finally {
|
|
144
|
+
// stack.pop();
|
|
145
|
+
// }
|
|
146
|
+
// }
|
|
147
|
+
// }
|
|
148
|
+
|
|
149
|
+
// // getTransitionId(stateId, event) {
|
|
150
|
+
// // }
|
|
151
|
+
|
|
152
|
+
// // const stateInfo = this._statesIndex[stateId];
|
|
153
|
+
// // if (!stateInfo) return;
|
|
154
|
+
// // if (stateInfo.parent) return ;
|
|
155
|
+
// // const targetState = stateInfo.parent.
|
|
156
|
+
// // const fromId = stateIds.pop();
|
|
157
|
+
// // const parentId = stateIds.pop();
|
|
158
|
+
// // const parent = parentId ? this._statesIndex[parentId] : null;
|
|
159
|
+
// // return parent
|
|
160
|
+
// // ? parent.graph?.edges.find(
|
|
161
|
+
// // (edge) => edge.from === fromId && edge.event === event
|
|
162
|
+
// // )
|
|
163
|
+
// // : undefined;
|
|
164
|
+
// // }
|
|
165
|
+
|
|
166
|
+
// // _getInfo(index, id, create) {
|
|
167
|
+
// // let info = index[id];
|
|
168
|
+
// // if (!info && create) {
|
|
169
|
+
// // info = index[id] = { id };
|
|
170
|
+
// // }
|
|
171
|
+
// // return info;
|
|
172
|
+
// // }
|
|
173
|
+
// // _getStateInfo(id, create) {
|
|
174
|
+
// // return this._getInfo(this._statesIndex, id, create);
|
|
175
|
+
// // }
|
|
176
|
+
// // _getTransitionInfo(id, create) {
|
|
177
|
+
// // return this._getInfo(this._transitionsIndex, id, create);
|
|
178
|
+
// // }
|
|
179
|
+
// // _buildIndexes(statechart) {
|
|
180
|
+
// // const { id, key } = statechart;
|
|
181
|
+
// // const stateInfo = this._getStateInfo(id, true);
|
|
182
|
+
// // stateInfo.key = key;
|
|
183
|
+
// // stateInfo.detailsElement = this.element.querySelector(
|
|
184
|
+
// // `details[data-state-id="${id}"]`
|
|
185
|
+
// // );
|
|
186
|
+
// // for (const node of statechart.graph?.nodes || []) {
|
|
187
|
+
// // const info = this._getStateInfo(node.id, true);
|
|
188
|
+
// // info.parent = stateInfo;
|
|
189
|
+
// // // info.parentId = id;
|
|
190
|
+
// // info.node = node;
|
|
191
|
+
// // info.key = node.key;
|
|
192
|
+
// // info.svgGroupElement = this.element.querySelector(
|
|
193
|
+
// // `g[data-state-id="${info.id}"]`
|
|
194
|
+
// // );
|
|
195
|
+
// // }
|
|
196
|
+
// // for (const edge of statechart.graph?.edges || []) {
|
|
197
|
+
// // const info = this._getTransitionInfo(edge.id, true);
|
|
198
|
+
// // info.transition = edge;
|
|
199
|
+
// // info.from = edge.from;
|
|
200
|
+
// // info.event = edge.event;
|
|
201
|
+
// // info.to = edge.to;
|
|
202
|
+
// // info.svgGroupElement = this.element.querySelector(
|
|
203
|
+
// // `g[data-transition-id="${info.id}"]`
|
|
204
|
+
// // );
|
|
205
|
+
// // }
|
|
206
|
+
|
|
207
|
+
// // for (const child of statechart.children) {
|
|
208
|
+
// // this._buildIndexes(child);
|
|
209
|
+
// // }
|
|
210
|
+
// // }
|
|
211
|
+
// }
|
|
@@ -102,11 +102,13 @@ export function buildStatechartStyles({
|
|
|
102
102
|
stroke: "var(--transition-border-color, none)",
|
|
103
103
|
strokeWidth: "var(--transition-border-width, 1px)",
|
|
104
104
|
borderRadius: "0.5em",
|
|
105
|
+
cursor: "pointer",
|
|
105
106
|
},
|
|
106
107
|
".transition__label": {
|
|
107
108
|
fill: "var(--transition-label-color, currentColor)",
|
|
108
109
|
fontSize: "var(--transition-label-font-size, 12px)",
|
|
109
110
|
fontFamily: "var(--transition-label-font-family, sans-serif)",
|
|
111
|
+
cursor: "pointer",
|
|
110
112
|
},
|
|
111
113
|
|
|
112
114
|
// ----------------------------------------------
|
|
@@ -147,6 +149,7 @@ export function buildStatechartStyles({
|
|
|
147
149
|
stroke: "var(--state-border-color, currentColor)",
|
|
148
150
|
strokeWidth: "var(--state-border-width, 1px)",
|
|
149
151
|
borderRadius: "0.5em",
|
|
152
|
+
cursor: "pointer",
|
|
150
153
|
},
|
|
151
154
|
".state__label": {
|
|
152
155
|
color: "var(--state-label-color, currentColor)",
|
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
Padding,
|
|
4
4
|
Position,
|
|
5
5
|
TransitionsGraph,
|
|
6
|
-
} from "../
|
|
6
|
+
} from "../types/index.ts";
|
|
7
7
|
import { getPadding } from "../utils/getPadding.ts";
|
|
8
8
|
import { serializeAttrs } from "../utils/serializeAttrs.ts";
|
|
9
9
|
import { BasisCurve } from "../utils/BasisCurve.ts";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { buildStatechartSvg } from "./buildStatechartSvg.ts";
|
|
2
|
-
import type { StateChart } from "../
|
|
2
|
+
import type { StateChart } from "../types/StateChart.ts";
|
|
3
3
|
|
|
4
4
|
export function buildStatechartsPanel({
|
|
5
5
|
statechart,
|
|
@@ -13,16 +13,22 @@ export function buildStatechartsPanel({
|
|
|
13
13
|
println: (str: string) => void;
|
|
14
14
|
initialStateKey?: string;
|
|
15
15
|
finalStateKey?: string;
|
|
16
|
-
})
|
|
16
|
+
}): void {
|
|
17
17
|
render(statechart, println);
|
|
18
18
|
|
|
19
19
|
function render(statechart: StateChart, println: (str: string) => void) {
|
|
20
|
-
println(
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
println(
|
|
21
|
+
` <details class="state-details" data-state-id="${statechart.id}">`
|
|
22
|
+
);
|
|
23
|
+
println(
|
|
24
|
+
` <summary class="state-details__label">${statechart.key}</summary>`
|
|
25
|
+
);
|
|
26
|
+
println(
|
|
27
|
+
` <div class="state-details__description"><div class="state-details__chart">`
|
|
28
|
+
);
|
|
23
29
|
const printChildren = (str: string) => println(` ${str}`);
|
|
24
30
|
buildStatechartSvg({
|
|
25
|
-
graph: statechart
|
|
31
|
+
graph: statechart,
|
|
26
32
|
newId,
|
|
27
33
|
println: printChildren,
|
|
28
34
|
initialStateKey,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Dimensions } from "./Dimensions.ts";
|
|
2
|
+
import type { Position } from "./Position.ts";
|
|
3
|
+
import type { StateGraphEdge } from "./StateGraphEdge.ts";
|
|
4
|
+
import type { StateGraphNode } from "./StateGraphNode.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Coordinates for state nodes and endges corresponding to state transitions.
|
|
8
|
+
*/
|
|
9
|
+
export type TransitionsGraph = Position &
|
|
10
|
+
Dimensions & {
|
|
11
|
+
nodes: StateGraphNode[];
|
|
12
|
+
edges: StateGraphEdge[];
|
|
13
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./Dimensions.ts";
|
|
2
|
+
export * from "./FsmStateConfig.ts";
|
|
3
|
+
export * from "./GraphParamsProvider.ts";
|
|
4
|
+
export * from "./Padding.ts";
|
|
5
|
+
export * from "./Position.ts";
|
|
6
|
+
export * from "./StateChart.ts";
|
|
7
|
+
export * from "./StateGraphEdge.ts";
|
|
8
|
+
export * from "./StateGraphNode.ts";
|
|
9
|
+
export * from "./Transition.ts";
|
|
10
|
+
export * from "./TransitionsGraph.ts";
|
package/src/utils/getPadding.ts
CHANGED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Visual element dimensions.
|
|
3
|
-
* @typedef {Object} Dimensions
|
|
4
|
-
*/
|
|
5
|
-
type Dimensions = {
|
|
6
|
-
width: number;
|
|
7
|
-
height: number;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* X/Y position of a node in the graph.
|
|
12
|
-
*/
|
|
13
|
-
type Position = {
|
|
14
|
-
x: number;
|
|
15
|
-
y: number;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Information about a state graph edge.
|
|
20
|
-
*/
|
|
21
|
-
type StateGraphEdge = Dimensions & Position & {
|
|
22
|
-
id: string;
|
|
23
|
-
from: string;
|
|
24
|
-
event: string;
|
|
25
|
-
to: string;
|
|
26
|
-
points: Position[];
|
|
27
|
-
} & Record<string, any>;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Information about a state node in the graph.
|
|
31
|
-
*/
|
|
32
|
-
type StateGraphNode = Dimensions & Position & {
|
|
33
|
-
id: string;
|
|
34
|
-
key: string;
|
|
35
|
-
state: string;
|
|
36
|
-
} & Record<string, any>;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Coordinates for state nodes and endges corresponding to state transitions.
|
|
40
|
-
*/
|
|
41
|
-
type TransitionsGraph = Position & Dimensions & {
|
|
42
|
-
nodes: StateGraphNode[];
|
|
43
|
-
edges: StateGraphEdge[];
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
type StateChart = {
|
|
47
|
-
id: string;
|
|
48
|
-
key: string;
|
|
49
|
-
children?: StateChart[];
|
|
50
|
-
graph: TransitionsGraph;
|
|
51
|
-
} & Record<string, any>;
|
|
52
|
-
|
|
53
|
-
export type { Dimensions as D, Position as P, StateGraphEdge as S, TransitionsGraph as T, StateGraphNode as a, StateChart as b };
|
package/src/FsmStateConfig.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Dimensions } from "./Dimensions.ts";
|
|
2
|
-
import { Position } from "./Position.ts";
|
|
3
|
-
import { StateGraphEdge } from "./StateGraphEdge.ts";
|
|
4
|
-
import { StateGraphNode } from "./StateGraphNode.ts";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Coordinates for state nodes and endges corresponding to state transitions.
|
|
8
|
-
*/
|
|
9
|
-
export type TransitionsGraph = Position &
|
|
10
|
-
Dimensions & {
|
|
11
|
-
nodes: StateGraphNode[];
|
|
12
|
-
edges: StateGraphEdge[];
|
|
13
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|