@statewalker/fsm-charts 0.2.4 → 0.2.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/README.md +206 -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-CxQlIwTh.js +494 -0
- package/dist/buildStatechartsPanel-CxQlIwTh.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 -1
- package/dist/index-dom.d.ts +2 -49
- package/dist/index-dom.js +2 -1
- package/dist/index-html.d.ts +3 -2
- package/dist/index-html.js +2 -2
- package/dist/index-layout.d.ts +3 -77
- package/dist/index-layout.js +2 -2
- package/dist/index-runtime.d.ts +3 -141
- package/dist/index-runtime.js +2 -1
- package/dist/index.d.ts +11 -10
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -6
- 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 +54 -28
- package/src/config/concatTransitionsToString.ts +4 -4
- package/src/config/index.ts +4 -4
- package/src/config/serializeProcessConfig.ts +3 -3
- package/src/config/splitTransitionString.ts +2 -4
- package/src/config/toFsmStateConfig.ts +5 -12
- package/src/dagre/acyclic.js +9 -10
- package/src/dagre/add-border-segments.js +11 -7
- package/src/dagre/coordinate-system.js +12 -12
- package/src/dagre/data/list.js +2 -2
- package/src/dagre/debug.d.ts +1 -1
- package/src/dagre/debug.js +11 -11
- package/src/dagre/greedy-fas.js +17 -21
- package/src/dagre/index.d.ts +4 -4
- package/src/dagre/index.js +4 -4
- package/src/dagre/layout.js +107 -96
- package/src/dagre/nesting-graph.js +13 -19
- package/src/dagre/normalize.js +7 -7
- package/src/dagre/order/add-subgraph-constraints.js +2 -2
- package/src/dagre/order/barycenter.d.ts +1 -1
- package/src/dagre/order/barycenter.js +4 -4
- package/src/dagre/order/build-layer-graph.d.ts +1 -1
- package/src/dagre/order/build-layer-graph.js +7 -9
- package/src/dagre/order/cross-count.js +14 -17
- package/src/dagre/order/index.js +19 -17
- package/src/dagre/order/init-order.js +5 -15
- package/src/dagre/order/resolve-conflicts.js +10 -14
- package/src/dagre/order/sort-subgraph.d.ts +1 -1
- package/src/dagre/order/sort-subgraph.js +13 -14
- package/src/dagre/order/sort.d.ts +1 -1
- package/src/dagre/order/sort.js +6 -10
- package/src/dagre/parent-dummy-chains.js +10 -4
- package/src/dagre/position/bk.d.ts +3 -3
- package/src/dagre/position/bk.js +84 -65
- package/src/dagre/position/index.js +7 -11
- package/src/dagre/rank/feasible-tree.d.ts +1 -1
- package/src/dagre/rank/feasible-tree.js +6 -6
- package/src/dagre/rank/index.js +6 -6
- package/src/dagre/rank/network-simplex.d.ts +0 -1
- package/src/dagre/rank/network-simplex.js +20 -25
- package/src/dagre/rank/util.js +2 -6
- package/src/dagre/util.d.ts +12 -6
- package/src/dagre/util.js +31 -37
- package/src/dom/buildSections.ts +15 -19
- package/src/dom/description-panels.ts +5 -7
- package/src/dom/getStatesDescriptions.ts +4 -10
- package/src/full/index.ts +1 -1
- package/src/full/toFsmStateCharts.ts +11 -11
- package/src/graphlib/alg/components.js +2 -2
- package/src/graphlib/alg/dfs.js +5 -5
- package/src/graphlib/alg/dijkstra-all.js +4 -4
- package/src/graphlib/alg/dijkstra.js +9 -12
- package/src/graphlib/alg/find-cycles.js +7 -5
- package/src/graphlib/alg/floyd-warshall.js +8 -11
- package/src/graphlib/alg/index.d.ts +11 -11
- package/src/graphlib/alg/index.js +11 -11
- package/src/graphlib/alg/is-acyclic.js +1 -1
- package/src/graphlib/alg/postorder.js +2 -2
- package/src/graphlib/alg/preorder.js +2 -2
- package/src/graphlib/alg/prim.d.ts +1 -1
- package/src/graphlib/alg/prim.js +5 -5
- package/src/graphlib/alg/tarjan.js +3 -3
- package/src/graphlib/alg/topsort.js +1 -1
- package/src/graphlib/data/priority-queue.js +8 -10
- package/src/graphlib/graph.js +53 -52
- package/src/graphlib/index.d.ts +2 -2
- package/src/graphlib/index.js +2 -2
- package/src/graphlib/json.d.ts +1 -1
- package/src/graphlib/json.js +6 -6
- package/src/html/buildStatechartCss.ts +2 -2
- package/src/html/buildStatechartStyles.ts +5 -15
- package/src/html/buildStatechartSvg.ts +8 -20
- package/src/html/buildStatechartsPanel.ts +3 -5
- package/src/html/index.ts +4 -4
- package/src/index-config.ts +2 -2
- package/src/index-dom.ts +1 -1
- package/src/index-html.ts +2 -2
- package/src/index-layout.ts +2 -2
- package/src/index-runtime.ts +2 -2
- package/src/index.ts +8 -8
- package/src/layout/buildCharts.ts +6 -7
- package/src/layout/buildFlatCharts.ts +17 -21
- package/src/layout/getGraphParamsProvider.ts +7 -19
- package/src/layout/getLabelDimensions.ts +5 -5
- package/src/layout/index.ts +5 -4
- package/src/lodash-es/index.ts +2 -2
- package/src/lodash-es/types.ts +37 -35
- package/src/runtime/RuntimeStatechartApi.ts +13 -46
- package/src/runtime/StateChartIndex.ts +7 -24
- package/src/runtime/index.ts +2 -2
- package/src/types/FsmStateConfig.ts +1 -1
- package/src/types/GraphParamsProvider.ts +3 -6
- package/src/types/Position.ts +1 -1
- package/src/types/StateChart.ts +2 -2
- package/src/types/StateGraphEdge.ts +2 -2
- package/src/types/StateGraphNode.ts +2 -2
- package/src/types/TransitionsGraph.ts +4 -4
- package/src/types/index.ts +11 -11
- package/src/utils/BasisCurve.ts +6 -15
- package/src/utils/domToText.ts +3 -7
- package/src/utils/getPadding.ts +2 -3
- package/src/utils/newId.ts +2 -1
- package/src/utils/newRegistry.ts +13 -13
- package/src/utils/serializeAttrs.ts +6 -14
- package/src/utils/serializeCss.ts +3 -7
- package/src/utils/serializeStyle.ts +2 -5
- package/src/utils/toKebabCase.ts +1 -4
- package/CHANGELOG.md +0 -1
- package/dist/StateChart-BYBjTmC2.d.ts +0 -82
- package/dist/chunk-36ZLXJVD.js +0 -606
- package/dist/chunk-AZBRQNTU.js +0 -2739
- package/dist/chunk-FIQDLBWD.js +0 -9
- package/dist/chunk-SVKVQY7B.js +0 -133
- package/dist/chunk-TZHCBZVP.js +0 -422
- package/dist/chunk-VILLJJJD.js +0 -231
- package/dist/index-html-DgSCNHkR.d.ts +0 -75
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { layout } from "../dagre/layout.js";
|
|
2
2
|
import { Graph } from "../graphlib/graph.js";
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import type { StateGraphEdge } from "../types/StateGraphEdge.
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
11
|
-
import type {
|
|
12
|
-
|
|
13
|
-
import { getPadding } from "../utils/getPadding.ts";
|
|
14
|
-
import { getLodash, setLodash } from "../lodash-es/index.ts";
|
|
3
|
+
import { getLodash, setLodash } from "../lodash-es/index.js";
|
|
4
|
+
import type { Dimensions } from "../types/Dimensions.js";
|
|
5
|
+
import type { GraphParamsProvider } from "../types/GraphParamsProvider.js";
|
|
6
|
+
import type { Padding } from "../types/Padding.js";
|
|
7
|
+
import type { Position } from "../types/Position.js";
|
|
8
|
+
import type { StateGraphEdge } from "../types/StateGraphEdge.js";
|
|
9
|
+
import type { StateGraphNode } from "../types/StateGraphNode.js";
|
|
10
|
+
import type { Transition } from "../types/Transition.js";
|
|
11
|
+
import type { TransitionsGraph } from "../types/TransitionsGraph.js";
|
|
12
|
+
import { getPadding } from "../utils/getPadding.js";
|
|
15
13
|
|
|
16
14
|
/**
|
|
17
15
|
* Build graphs corresponding to the specified transitions.
|
|
@@ -46,7 +44,7 @@ export function buildFlatCharts({
|
|
|
46
44
|
padding?: Padding;
|
|
47
45
|
direction?: "tb" | "bt" | "lr" | "rl";
|
|
48
46
|
} & GraphParamsProvider): TransitionsGraph {
|
|
49
|
-
|
|
47
|
+
const prevLodash = getLodash();
|
|
50
48
|
try {
|
|
51
49
|
setLodash(lodash);
|
|
52
50
|
const rankdir = direction || (vertical ? "tb" : "lr");
|
|
@@ -94,14 +92,12 @@ export function buildFlatCharts({
|
|
|
94
92
|
n.y += -n.height / 2;
|
|
95
93
|
return n;
|
|
96
94
|
});
|
|
97
|
-
const edges = graph
|
|
98
|
-
.
|
|
99
|
-
.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return e;
|
|
104
|
-
});
|
|
95
|
+
const edges = graph.edges().map(({ v, w, name }: { v: string; w: string; name: string }) => {
|
|
96
|
+
const e = graph.edge(v, w, name) as StateGraphEdge;
|
|
97
|
+
e.x += -e.width / 2;
|
|
98
|
+
e.y += -e.height / 2;
|
|
99
|
+
return e;
|
|
100
|
+
});
|
|
105
101
|
|
|
106
102
|
// Get the bounding box of the graph
|
|
107
103
|
let x = 0;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import { getLabelDimensions } from "./getLabelDimensions.ts";
|
|
6
|
-
import { getPadding } from "../utils/getPadding.ts";
|
|
7
|
-
import { Label } from "../types/Label.ts";
|
|
1
|
+
import type { GraphParamsProvider } from "../types/GraphParamsProvider.js";
|
|
2
|
+
import type { Padding } from "../types/Padding.js";
|
|
3
|
+
import { getPadding } from "../utils/getPadding.js";
|
|
4
|
+
import { getLabelDimensions } from "./getLabelDimensions.js";
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* Provides default functions measuring dimensions for state nodes and transition edges in the graph.
|
|
@@ -21,8 +18,7 @@ export function getGraphParamsProvider({
|
|
|
21
18
|
transitionsFontSize = fontSize,
|
|
22
19
|
transitionsTextPadding = 0,
|
|
23
20
|
getStateLabel = (state: string) => state,
|
|
24
|
-
getTransitionLabel = (
|
|
25
|
-
event,
|
|
21
|
+
getTransitionLabel = (_fromState: string, event: string, _toState: string) => event,
|
|
26
22
|
}: {
|
|
27
23
|
fontSize?: number;
|
|
28
24
|
stateFontSize?: number;
|
|
@@ -30,11 +26,7 @@ export function getGraphParamsProvider({
|
|
|
30
26
|
transitionsFontSize?: number;
|
|
31
27
|
transitionsTextPadding?: Padding;
|
|
32
28
|
getStateLabel?: (state: string) => string;
|
|
33
|
-
getTransitionLabel?: (
|
|
34
|
-
fromState: string,
|
|
35
|
-
event: string,
|
|
36
|
-
toState: string,
|
|
37
|
-
) => string;
|
|
29
|
+
getTransitionLabel?: (fromState: string, event: string, toState: string) => string;
|
|
38
30
|
} = {}): GraphParamsProvider {
|
|
39
31
|
return {
|
|
40
32
|
getStateParams: (stateKey: string, state: string = stateKey) => {
|
|
@@ -53,11 +45,7 @@ export function getGraphParamsProvider({
|
|
|
53
45
|
fontSize,
|
|
54
46
|
};
|
|
55
47
|
},
|
|
56
|
-
getTransitionParams: (
|
|
57
|
-
fromStateKey: string,
|
|
58
|
-
event: string,
|
|
59
|
-
toStateKey: string,
|
|
60
|
-
) => {
|
|
48
|
+
getTransitionParams: (fromStateKey: string, event: string, toStateKey: string) => {
|
|
61
49
|
const padding = getPadding(transitionsTextPadding);
|
|
62
50
|
const fontSize = transitionsFontSize;
|
|
63
51
|
const eventLabel = getTransitionLabel(fromStateKey, event, toStateKey);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Dimensions } from "../types/Dimensions.
|
|
2
|
-
import type { Padding } from "../types/Padding.
|
|
3
|
-
import { getPadding } from "../utils/getPadding.
|
|
1
|
+
import type { Dimensions } from "../types/Dimensions.js";
|
|
2
|
+
import type { Padding } from "../types/Padding.js";
|
|
3
|
+
import { getPadding } from "../utils/getPadding.js";
|
|
4
4
|
|
|
5
5
|
export function getLabelDimensions(
|
|
6
6
|
label: string,
|
|
@@ -14,7 +14,7 @@ export function getLabelDimensions(
|
|
|
14
14
|
fontSize?: number;
|
|
15
15
|
getCharWidth?: (char: string) => number;
|
|
16
16
|
lineGap?: number;
|
|
17
|
-
} = {}
|
|
17
|
+
} = {},
|
|
18
18
|
) {
|
|
19
19
|
const lines = [label]; // label.split("\n");
|
|
20
20
|
let dimensions: Dimensions = { width: 0, height: 0 };
|
|
@@ -27,7 +27,7 @@ export function getLabelDimensions(
|
|
|
27
27
|
line,
|
|
28
28
|
fontSize,
|
|
29
29
|
getCharWidth,
|
|
30
|
-
})
|
|
30
|
+
}),
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
33
|
const [top, right, bottom, left] = getPadding(padding);
|
package/src/layout/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Methods
|
|
2
|
-
|
|
3
|
-
export * from "./buildCharts.
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
2
|
+
|
|
3
|
+
export * from "./buildCharts.js";
|
|
4
|
+
export * from "./buildFlatCharts.js";
|
|
5
|
+
export * from "./getGraphParamsProvider.js";
|
|
6
|
+
export * from "./getLabelDimensions.js";
|
package/src/lodash-es/index.ts
CHANGED
package/src/lodash-es/types.ts
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
export type {
|
|
2
|
+
clone,
|
|
3
|
+
cloneDeep,
|
|
4
|
+
constant,
|
|
5
|
+
defaults,
|
|
6
|
+
each,
|
|
7
|
+
filter,
|
|
8
|
+
find,
|
|
9
|
+
flatten,
|
|
10
|
+
forEach,
|
|
11
|
+
forIn,
|
|
12
|
+
forOwn,
|
|
13
|
+
has,
|
|
14
|
+
isArray,
|
|
15
|
+
isEmpty,
|
|
16
|
+
isFunction,
|
|
17
|
+
isUndefined,
|
|
18
|
+
keys,
|
|
19
|
+
last,
|
|
20
|
+
map,
|
|
21
|
+
mapValues,
|
|
22
|
+
max,
|
|
23
|
+
merge,
|
|
24
|
+
min,
|
|
25
|
+
minBy,
|
|
26
|
+
now,
|
|
27
|
+
pick,
|
|
28
|
+
range,
|
|
29
|
+
reduce,
|
|
30
|
+
size,
|
|
31
|
+
sortBy,
|
|
32
|
+
transform,
|
|
33
|
+
union,
|
|
34
|
+
uniqueId,
|
|
35
|
+
values,
|
|
36
|
+
zipObject,
|
|
37
|
+
} from "lodash-es";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StateChart } from "../types/index.
|
|
1
|
+
import type { StateChart } from "../types/index.js";
|
|
2
2
|
|
|
3
3
|
export type RuntimeListener = (id: string) => void;
|
|
4
4
|
export class RuntimeStatechartApi {
|
|
@@ -22,7 +22,7 @@ export class RuntimeStatechartApi {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
close() {
|
|
25
|
-
Object.values(this._registry)
|
|
25
|
+
for (const r of Object.values(this._registry)) r?.();
|
|
26
26
|
this._registry = {};
|
|
27
27
|
this._transitionsClickListeners = {};
|
|
28
28
|
this._statesClickListeners = {};
|
|
@@ -68,23 +68,18 @@ export class RuntimeStatechartApi {
|
|
|
68
68
|
this.selectState(id);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
focusStates(...stateIds: string[]) {
|
|
73
73
|
for (let i = 0; i < stateIds.length; i++) {
|
|
74
74
|
const stateId = stateIds[i];
|
|
75
75
|
for (const tagName of ["details", "g"]) {
|
|
76
|
-
const elm = this.element.querySelector(
|
|
77
|
-
`${tagName}[data-state-id="${stateId}"]`,
|
|
78
|
-
);
|
|
76
|
+
const elm = this.element.querySelector(`${tagName}[data-state-id="${stateId}"]`);
|
|
79
77
|
elm?.scrollIntoView();
|
|
80
78
|
}
|
|
81
79
|
}
|
|
82
80
|
}
|
|
83
81
|
|
|
84
|
-
setStateDescription(
|
|
85
|
-
stateId: string,
|
|
86
|
-
description: Node | string | undefined,
|
|
87
|
-
) {
|
|
82
|
+
setStateDescription(stateId: string, description: Node | string | undefined) {
|
|
88
83
|
const descriptionContainer = this.element.querySelector(
|
|
89
84
|
`details[data-state-id="${stateId}"] .state-details__description`,
|
|
90
85
|
);
|
|
@@ -156,10 +151,7 @@ export class RuntimeStatechartApi {
|
|
|
156
151
|
dataField: string,
|
|
157
152
|
eventType: string,
|
|
158
153
|
) => {
|
|
159
|
-
function newEventListener(
|
|
160
|
-
index: Record<string, RuntimeListener>,
|
|
161
|
-
elm: Element,
|
|
162
|
-
) {
|
|
154
|
+
function newEventListener(index: Record<string, RuntimeListener>, elm: Element) {
|
|
163
155
|
return (ev: Event) => {
|
|
164
156
|
ev.preventDefault();
|
|
165
157
|
ev.stopPropagation();
|
|
@@ -177,17 +169,11 @@ export class RuntimeStatechartApi {
|
|
|
177
169
|
[...this.element.querySelectorAll(`[${dataField}]`)].forEach((elm) => {
|
|
178
170
|
const eventListener = newEventListener(index, elm);
|
|
179
171
|
elm.addEventListener(eventType, eventListener);
|
|
180
|
-
this._addListener(this._registry, () =>
|
|
181
|
-
elm.removeEventListener(eventType, eventListener),
|
|
182
|
-
);
|
|
172
|
+
this._addListener(this._registry, () => elm.removeEventListener(eventType, eventListener));
|
|
183
173
|
});
|
|
184
174
|
};
|
|
185
175
|
bindListeners(this._statesClickListeners, "data-state-id", "click");
|
|
186
|
-
bindListeners(
|
|
187
|
-
this._transitionsClickListeners,
|
|
188
|
-
"data-transition-id",
|
|
189
|
-
"click",
|
|
190
|
-
);
|
|
176
|
+
bindListeners(this._transitionsClickListeners, "data-transition-id", "click");
|
|
191
177
|
}
|
|
192
178
|
|
|
193
179
|
_setStatePanelStatus(selector: string, open: boolean) {
|
|
@@ -198,18 +184,10 @@ export class RuntimeStatechartApi {
|
|
|
198
184
|
}
|
|
199
185
|
|
|
200
186
|
_addStateModifier(cssSelector: string, modifier: string = "selected") {
|
|
201
|
-
this._applyStateModifier(
|
|
202
|
-
cssSelector,
|
|
203
|
-
modifier,
|
|
204
|
-
(elm, cls) => elm && elm.classList.add(cls),
|
|
205
|
-
);
|
|
187
|
+
this._applyStateModifier(cssSelector, modifier, (elm, cls) => elm?.classList.add(cls));
|
|
206
188
|
}
|
|
207
189
|
_removeStateModifier(cssSelector: string, modifier: string = "selected") {
|
|
208
|
-
this._applyStateModifier(
|
|
209
|
-
cssSelector,
|
|
210
|
-
modifier,
|
|
211
|
-
(elm, cls) => elm && elm.classList.remove(cls),
|
|
212
|
-
);
|
|
190
|
+
this._applyStateModifier(cssSelector, modifier, (elm, cls) => elm?.classList.remove(cls));
|
|
213
191
|
}
|
|
214
192
|
_applyStateModifier(
|
|
215
193
|
cssSelector: string,
|
|
@@ -231,21 +209,10 @@ export class RuntimeStatechartApi {
|
|
|
231
209
|
}
|
|
232
210
|
|
|
233
211
|
_addTransitionsModifier(cssSelector: string, modifier: string = "selected") {
|
|
234
|
-
this._applyTransitionsModifier(
|
|
235
|
-
cssSelector,
|
|
236
|
-
modifier,
|
|
237
|
-
(elm, cls) => elm && elm.classList.add(cls),
|
|
238
|
-
);
|
|
212
|
+
this._applyTransitionsModifier(cssSelector, modifier, (elm, cls) => elm?.classList.add(cls));
|
|
239
213
|
}
|
|
240
|
-
_removeTransitionsModifier(
|
|
241
|
-
cssSelector
|
|
242
|
-
modifier: string = "selected",
|
|
243
|
-
) {
|
|
244
|
-
this._applyTransitionsModifier(
|
|
245
|
-
cssSelector,
|
|
246
|
-
modifier,
|
|
247
|
-
(elm, cls) => elm && elm.classList.remove(cls),
|
|
248
|
-
);
|
|
214
|
+
_removeTransitionsModifier(cssSelector: string, modifier: string = "selected") {
|
|
215
|
+
this._applyTransitionsModifier(cssSelector, modifier, (elm, cls) => elm?.classList.remove(cls));
|
|
249
216
|
}
|
|
250
217
|
_applyTransitionsModifier(
|
|
251
218
|
cssSelector: string,
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
StateChart,
|
|
3
|
-
StateGraphNode,
|
|
4
|
-
StateGraphEdge,
|
|
5
|
-
} from "../types/index.ts";
|
|
1
|
+
import type { StateChart, StateGraphEdge, StateGraphNode } from "../types/index.js";
|
|
6
2
|
|
|
7
3
|
export class StateChartIndex {
|
|
8
4
|
statechart: StateChart;
|
|
@@ -62,12 +58,7 @@ export class StateChartIndex {
|
|
|
62
58
|
* @return a list of all nodes
|
|
63
59
|
*/
|
|
64
60
|
getAllNodes(): StateGraphNode[] {
|
|
65
|
-
return [
|
|
66
|
-
...new Set([
|
|
67
|
-
...Object.values(this._chartsIndex),
|
|
68
|
-
...Object.values(this._nodesIndex),
|
|
69
|
-
]),
|
|
70
|
-
];
|
|
61
|
+
return [...new Set([...Object.values(this._chartsIndex), ...Object.values(this._nodesIndex)])];
|
|
71
62
|
}
|
|
72
63
|
|
|
73
64
|
/**
|
|
@@ -77,8 +68,7 @@ export class StateChartIndex {
|
|
|
77
68
|
*/
|
|
78
69
|
getStateNodes(): StateGraphNode[] {
|
|
79
70
|
return this.getAllNodes().filter(
|
|
80
|
-
(node) =>
|
|
81
|
-
node.key !== this.initialStateKey && node.key !== this.finalStateKey,
|
|
71
|
+
(node) => node.key !== this.initialStateKey && node.key !== this.finalStateKey,
|
|
82
72
|
);
|
|
83
73
|
}
|
|
84
74
|
|
|
@@ -90,7 +80,7 @@ export class StateChartIndex {
|
|
|
90
80
|
* @returns a stack of state identifiers for the given states
|
|
91
81
|
*/
|
|
92
82
|
getStatesIds(...stack: string[]): string[] {
|
|
93
|
-
|
|
83
|
+
const result = [];
|
|
94
84
|
let list = [this.statechart] as (StateChart | StateGraphNode)[];
|
|
95
85
|
for (let i = 0; list?.length > 0 && i < stack.length; i++) {
|
|
96
86
|
const key = stack[i];
|
|
@@ -133,9 +123,7 @@ export class StateChartIndex {
|
|
|
133
123
|
const state = stack.pop();
|
|
134
124
|
if (!state || !stack.length) return;
|
|
135
125
|
const parent = stack[stack.length - 1];
|
|
136
|
-
const t = parent.edges.find(
|
|
137
|
-
(t: StateGraphEdge) => t.from === state.key && t.event === event,
|
|
138
|
-
);
|
|
126
|
+
const t = parent.edges.find((t: StateGraphEdge) => t.from === state.key && t.event === event);
|
|
139
127
|
return t;
|
|
140
128
|
}
|
|
141
129
|
|
|
@@ -177,13 +165,8 @@ export class StateChartIndex {
|
|
|
177
165
|
* @param transition a graph edge instance defining transition
|
|
178
166
|
* @returns an array with two identifiers - [sourceStateId, targetStateId] - the source state id and target state id
|
|
179
167
|
*/
|
|
180
|
-
getTransitionStateIds(
|
|
181
|
-
|
|
182
|
-
): [string | undefined, string | undefined] {
|
|
183
|
-
const result: [string | undefined, string | undefined] = [
|
|
184
|
-
undefined,
|
|
185
|
-
undefined,
|
|
186
|
-
];
|
|
168
|
+
getTransitionStateIds(transition?: StateGraphEdge): [string | undefined, string | undefined] {
|
|
169
|
+
const result: [string | undefined, string | undefined] = [undefined, undefined];
|
|
187
170
|
if (!transition) return result;
|
|
188
171
|
const parentId = this._edgesParentsIndex[transition.id];
|
|
189
172
|
if (!parentId) return result;
|
package/src/runtime/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./RuntimeStatechartApi.
|
|
2
|
-
export * from "./StateChartIndex.
|
|
1
|
+
export * from "./RuntimeStatechartApi.js";
|
|
2
|
+
export * from "./StateChartIndex.js";
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import type { Dimensions } from "./Dimensions.
|
|
2
|
-
import { Label } from "./Label.
|
|
1
|
+
import type { Dimensions } from "./Dimensions.js";
|
|
2
|
+
import type { Label } from "./Label.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Provides default functions measuring dimensions for state nodes and transition edges in the graph.
|
|
6
6
|
*/
|
|
7
7
|
export type GraphParamsProvider = {
|
|
8
|
-
getStateParams: (
|
|
9
|
-
stateKey: string,
|
|
10
|
-
state?: string,
|
|
11
|
-
) => Dimensions & Label & Record<string, any>;
|
|
8
|
+
getStateParams: (stateKey: string, state?: string) => Dimensions & Label & Record<string, any>;
|
|
12
9
|
getTransitionParams: (
|
|
13
10
|
fromStateKey: string,
|
|
14
11
|
event: string,
|
package/src/types/Position.ts
CHANGED
package/src/types/StateChart.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { StateGraphNode } from "./StateGraphNode.
|
|
2
|
-
import type { TransitionsGraph } from "./TransitionsGraph.
|
|
1
|
+
import type { StateGraphNode } from "./StateGraphNode.js";
|
|
2
|
+
import type { TransitionsGraph } from "./TransitionsGraph.js";
|
|
3
3
|
|
|
4
4
|
export type StateChart = TransitionsGraph &
|
|
5
5
|
StateGraphNode & {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Dimensions } from "./Dimensions.
|
|
2
|
-
import type { Position } from "./Position.
|
|
3
|
-
import type { StateGraphEdge } from "./StateGraphEdge.
|
|
4
|
-
import type { StateGraphNode } from "./StateGraphNode.
|
|
1
|
+
import type { Dimensions } from "./Dimensions.js";
|
|
2
|
+
import type { Position } from "./Position.js";
|
|
3
|
+
import type { StateGraphEdge } from "./StateGraphEdge.js";
|
|
4
|
+
import type { StateGraphNode } from "./StateGraphNode.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Coordinates for state nodes and endges corresponding to state transitions.
|
package/src/types/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export type * from "./Dimensions.
|
|
2
|
-
export type * from "./FsmStateConfig.
|
|
3
|
-
export type * from "./GraphParamsProvider.
|
|
4
|
-
export type * from "./Label.
|
|
5
|
-
export type * from "./Padding.
|
|
6
|
-
export type * from "./Position.
|
|
7
|
-
export type * from "./StateChart.
|
|
8
|
-
export type * from "./StateGraphEdge.
|
|
9
|
-
export type * from "./StateGraphNode.
|
|
10
|
-
export type * from "./Transition.
|
|
11
|
-
export type * from "./TransitionsGraph.
|
|
1
|
+
export type * from "./Dimensions.js";
|
|
2
|
+
export type * from "./FsmStateConfig.js";
|
|
3
|
+
export type * from "./GraphParamsProvider.js";
|
|
4
|
+
export type * from "./Label.js";
|
|
5
|
+
export type * from "./Padding.js";
|
|
6
|
+
export type * from "./Position.js";
|
|
7
|
+
export type * from "./StateChart.js";
|
|
8
|
+
export type * from "./StateGraphEdge.js";
|
|
9
|
+
export type * from "./StateGraphNode.js";
|
|
10
|
+
export type * from "./Transition.js";
|
|
11
|
+
export type * from "./TransitionsGraph.js";
|
package/src/utils/BasisCurve.ts
CHANGED
|
@@ -2,14 +2,7 @@
|
|
|
2
2
|
// copied from d3-shape/src/curve/basis.ts (Mike Bostock, MIT License)
|
|
3
3
|
|
|
4
4
|
export type DrawContext = {
|
|
5
|
-
bezierCurveTo(
|
|
6
|
-
x0: number,
|
|
7
|
-
y0: number,
|
|
8
|
-
x1: number,
|
|
9
|
-
y1: number,
|
|
10
|
-
x2: number,
|
|
11
|
-
y2: number
|
|
12
|
-
): void;
|
|
5
|
+
bezierCurveTo(x0: number, y0: number, x1: number, y1: number, x2: number, y2: number): void;
|
|
13
6
|
moveTo(x: number, y: number): void;
|
|
14
7
|
lineTo(x: number, y: number): void;
|
|
15
8
|
closePath(): void;
|
|
@@ -33,7 +26,7 @@ export class BasisCurve {
|
|
|
33
26
|
(this._x0 + 2 * this._x1) / 3,
|
|
34
27
|
(this._y0 + 2 * this._y1) / 3,
|
|
35
28
|
(this._x0 + 4 * this._x1 + x) / 6,
|
|
36
|
-
(this._y0 + 4 * this._y1 + y) / 6
|
|
29
|
+
(this._y0 + 4 * this._y1 + y) / 6,
|
|
37
30
|
);
|
|
38
31
|
}
|
|
39
32
|
|
|
@@ -52,14 +45,14 @@ export class BasisCurve {
|
|
|
52
45
|
|
|
53
46
|
lineEnd() {
|
|
54
47
|
switch (this._point) {
|
|
48
|
+
// biome-ignore lint/suspicious/noFallthroughSwitchClause: deliberate fall-through, as in the d3-shape basis curve this ports
|
|
55
49
|
case 3:
|
|
56
50
|
this.$point(this._x1, this._y1); // falls through
|
|
57
51
|
case 2:
|
|
58
52
|
this._context.lineTo(this._x1, this._y1);
|
|
59
53
|
break;
|
|
60
54
|
}
|
|
61
|
-
if (this._line || (this._line !== 0 && this._point === 1))
|
|
62
|
-
this._context.closePath();
|
|
55
|
+
if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
|
63
56
|
this._line = 1 - this._line;
|
|
64
57
|
}
|
|
65
58
|
|
|
@@ -73,12 +66,10 @@ export class BasisCurve {
|
|
|
73
66
|
case 1:
|
|
74
67
|
this._point = 2;
|
|
75
68
|
break;
|
|
69
|
+
// biome-ignore lint/suspicious/noFallthroughSwitchClause: deliberate fall-through, as in the d3-shape basis curve this ports
|
|
76
70
|
case 2:
|
|
77
71
|
this._point = 3;
|
|
78
|
-
this._context.lineTo(
|
|
79
|
-
(5 * this._x0 + this._x1) / 6,
|
|
80
|
-
(5 * this._y0 + this._y1) / 6
|
|
81
|
-
); // falls through
|
|
72
|
+
this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // falls through
|
|
82
73
|
default:
|
|
83
74
|
this.$point(x, y);
|
|
84
75
|
break;
|
package/src/utils/domToText.ts
CHANGED
|
@@ -4,11 +4,7 @@ export function domToText(elm: HTMLElement) {
|
|
|
4
4
|
if (node.nodeType === Node.TEXT_NODE) {
|
|
5
5
|
lines.push(node.textContent || "");
|
|
6
6
|
} else if (node.nodeType === Node.ELEMENT_NODE) {
|
|
7
|
-
if (
|
|
8
|
-
node.nodeName === "BR" ||
|
|
9
|
-
node.nodeName === "P" ||
|
|
10
|
-
node.nodeName === "DIV"
|
|
11
|
-
) {
|
|
7
|
+
if (node.nodeName === "BR" || node.nodeName === "P" || node.nodeName === "DIV") {
|
|
12
8
|
lines.push("\n");
|
|
13
9
|
}
|
|
14
10
|
}
|
|
@@ -16,11 +12,11 @@ export function domToText(elm: HTMLElement) {
|
|
|
16
12
|
return lines.join("");
|
|
17
13
|
|
|
18
14
|
function visit(el: HTMLElement, visitor: (node: Node) => void) {
|
|
19
|
-
for (
|
|
15
|
+
for (let i = 0; i < el.childNodes.length; i++) {
|
|
20
16
|
const child = el.childNodes[i];
|
|
21
17
|
const result = visitor(el.childNodes[i]);
|
|
22
18
|
if (child.nodeType !== Node.ELEMENT_NODE) continue;
|
|
23
|
-
if (result !== undefined && !
|
|
19
|
+
if (result !== undefined && !result) continue;
|
|
24
20
|
visit(child as HTMLElement, visitor);
|
|
25
21
|
}
|
|
26
22
|
}
|
package/src/utils/getPadding.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Padding } from "../types/Padding.
|
|
1
|
+
import type { Padding } from "../types/Padding.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Expands a padding value to a 4-element array: [top, right, bottom, left].
|
|
@@ -7,7 +7,6 @@ import type { Padding } from "../types/Padding.ts";
|
|
|
7
7
|
*/
|
|
8
8
|
export function getPadding(padding: Padding): [number, number, number, number] {
|
|
9
9
|
if (typeof padding === "number") return [padding, padding, padding, padding];
|
|
10
|
-
if (padding.length === 2)
|
|
11
|
-
return [padding[0], padding[1], padding[0], padding[1]];
|
|
10
|
+
if (padding.length === 2) return [padding[0], padding[1], padding[0], padding[1]];
|
|
12
11
|
return padding;
|
|
13
12
|
}
|
package/src/utils/newId.ts
CHANGED