@statewalker/fsm-charts 0.0.4 → 0.0.5

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.
Files changed (42) hide show
  1. package/dist/StateChart-pFSQIvtE.d.ts +77 -0
  2. package/dist/{chunk-DX2ZO7QN.js → chunk-3PNSXN5U.js} +16 -7
  3. package/dist/{chunk-ASIV3YDZ.js → chunk-IT7GBMYV.js} +1 -1
  4. package/dist/chunk-X2UPWZLX.js +4 -0
  5. package/dist/index-layout.d.ts +3 -28
  6. package/dist/index-layout.js +1 -1
  7. package/dist/index-runtime.d.ts +5 -0
  8. package/dist/index-runtime.js +1 -0
  9. package/dist/{index-svg-DW8Cf450.d.ts → index-svg-DCwEyX8X.d.ts} +1 -1
  10. package/dist/index-svg.d.ts +2 -2
  11. package/dist/index-svg.js +1 -1
  12. package/dist/index.d.ts +4 -3
  13. package/dist/index.js +3 -2
  14. package/package.json +1 -1
  15. package/src/index-layout.ts +1 -0
  16. package/src/index-runtime.ts +2 -0
  17. package/src/index-svg.ts +1 -0
  18. package/src/index.ts +4 -2
  19. package/src/layout/buildCharts.ts +5 -13
  20. package/src/layout/buildFlatCharts.ts +9 -8
  21. package/src/layout/getGraphParamsProvider.ts +4 -3
  22. package/src/layout/getLabelDimensions.ts +2 -2
  23. package/src/layout/index.ts +0 -10
  24. package/src/runtime/index.ts +211 -0
  25. package/src/svg/buildStatechartStyles.ts +3 -0
  26. package/src/svg/buildStatechartSvg.ts +1 -1
  27. package/src/svg/buildStatechartsPanel.ts +12 -6
  28. package/src/types/FsmStateConfig.ts +7 -0
  29. package/src/{layout → types}/StateChart.ts +1 -2
  30. package/src/{layout → types}/StateGraphEdge.ts +2 -2
  31. package/src/{layout → types}/StateGraphNode.ts +2 -2
  32. package/src/types/TransitionsGraph.ts +13 -0
  33. package/src/types/index.ts +10 -0
  34. package/src/utils/getPadding.ts +1 -1
  35. package/dist/StateChart-DNGQd1XG.d.ts +0 -53
  36. package/src/FsmStateConfig.ts +0 -5
  37. package/src/layout/TransitionsGraph.ts +0 -13
  38. /package/src/{layout → types}/Dimensions.ts +0 -0
  39. /package/src/{layout → types}/GraphParamsProvider.ts +0 -0
  40. /package/src/{layout → types}/Padding.ts +0 -0
  41. /package/src/{layout → types}/Position.ts +0 -0
  42. /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 };
@@ -141,12 +141,14 @@ function buildStatechartStyles({
141
141
  fill: "var(--transition-background-color, rgba(255,255,255,0.7))",
142
142
  stroke: "var(--transition-border-color, none)",
143
143
  strokeWidth: "var(--transition-border-width, 1px)",
144
- borderRadius: "0.5em"
144
+ borderRadius: "0.5em",
145
+ cursor: "pointer"
145
146
  },
146
147
  ".transition__label": {
147
148
  fill: "var(--transition-label-color, currentColor)",
148
149
  fontSize: "var(--transition-label-font-size, 12px)",
149
- fontFamily: "var(--transition-label-font-family, sans-serif)"
150
+ fontFamily: "var(--transition-label-font-family, sans-serif)",
151
+ cursor: "pointer"
150
152
  },
151
153
  // ----------------------------------------------
152
154
  // States
@@ -181,7 +183,8 @@ function buildStatechartStyles({
181
183
  fill: "var(--state-background-color, white)",
182
184
  stroke: "var(--state-border-color, currentColor)",
183
185
  strokeWidth: "var(--state-border-width, 1px)",
184
- borderRadius: "0.5em"
186
+ borderRadius: "0.5em",
187
+ cursor: "pointer"
185
188
  },
186
189
  ".state__label": {
187
190
  color: "var(--state-label-color, currentColor)",
@@ -506,12 +509,18 @@ function buildStatechartsPanel({
506
509
  }) {
507
510
  render(statechart, println);
508
511
  function render(statechart2, println2) {
509
- println2(` <details class="state-details" data-state-id="${statechart2.id}">`);
510
- println2(` <summary class="state-details__label">${statechart2.key}</summary>`);
511
- println2(` <div class="state-details__description"><div class="state-details__chart">`);
512
+ println2(
513
+ ` <details class="state-details" data-state-id="${statechart2.id}">`
514
+ );
515
+ println2(
516
+ ` <summary class="state-details__label">${statechart2.key}</summary>`
517
+ );
518
+ println2(
519
+ ` <div class="state-details__description"><div class="state-details__chart">`
520
+ );
512
521
  const printChildren = (str) => println2(` ${str}`);
513
522
  buildStatechartSvg({
514
- graph: statechart2.graph,
523
+ graph: statechart2,
515
524
  newId,
516
525
  println: printChildren,
517
526
  initialStateKey,
@@ -2589,7 +2589,7 @@ function buildCharts({
2589
2589
  return {
2590
2590
  id,
2591
2591
  key: config2.key,
2592
- graph,
2592
+ ...graph,
2593
2593
  children
2594
2594
  };
2595
2595
  }
@@ -0,0 +1,4 @@
1
+ // src/runtime/index.ts
2
+ var a = "a";
3
+
4
+ export { a };
@@ -1,24 +1,5 @@
1
- import { D as Dimensions, T as TransitionsGraph, b as StateChart } from './StateChart-DNGQd1XG.js';
2
- export { P as Position, S as StateGraphEdge, a as StateGraphNode } from './StateChart-DNGQd1XG.js';
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 { Dimensions, type GraphParamsProvider, type Padding, type Transition, TransitionsGraph, buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions };
71
+ export { FsmStateConfig, GraphParamsProvider, Padding, StateChart, Transition, TransitionsGraph, buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions };
@@ -1,2 +1,2 @@
1
- export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './chunk-ASIV3YDZ.js';
1
+ export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './chunk-IT7GBMYV.js';
2
2
  import './chunk-NXWOFQMO.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 };
@@ -0,0 +1 @@
1
+ export { a } from './chunk-X2UPWZLX.js';
@@ -1,4 +1,4 @@
1
- import { b as StateChart, T as TransitionsGraph } from './StateChart-DNGQd1XG.js';
1
+ import { S as StateChart, d as TransitionsGraph } from './StateChart-pFSQIvtE.js';
2
2
 
3
3
  declare function buildStatechartCss({ prefix }?: {
4
4
  prefix?: string | undefined;
@@ -1,2 +1,2 @@
1
- export { b as buildStatechartCss, c as buildStatechartStyles, d as buildStatechartSvg, a as buildStatechartsPanel } from './index-svg-DW8Cf450.js';
2
- import './StateChart-DNGQd1XG.js';
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,2 @@
1
- export { buildStatechartCss, buildStatechartStyles, buildStatechartSvg, buildStatechartsPanel } from './chunk-DX2ZO7QN.js';
1
+ export { buildStatechartCss, buildStatechartStyles, buildStatechartSvg, buildStatechartsPanel } from './chunk-3PNSXN5U.js';
2
2
  import './chunk-NXWOFQMO.js';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- export { GraphParamsProvider, Padding, Transition, buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './index-layout.js';
2
- export { D as Dimensions, P as Position, S as StateGraphEdge, a as StateGraphNode, T as TransitionsGraph } from './StateChart-DNGQd1XG.js';
3
- export { C as CssTree, b as buildStatechartCss, c as buildStatechartStyles, d as buildStatechartSvg, a as buildStatechartsPanel, s as serializeCss } from './index-svg-DW8Cf450.js';
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,4 @@
1
- export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './chunk-ASIV3YDZ.js';
2
- export { buildStatechartCss, buildStatechartStyles, buildStatechartSvg, buildStatechartsPanel, serializeCss, toKebabCase } from './chunk-DX2ZO7QN.js';
1
+ export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './chunk-IT7GBMYV.js';
2
+ export { buildStatechartCss, buildStatechartStyles, buildStatechartSvg, buildStatechartsPanel, serializeCss, toKebabCase } from './chunk-3PNSXN5U.js';
3
3
  import './chunk-NXWOFQMO.js';
4
+ export { a } from './chunk-X2UPWZLX.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statewalker/fsm-charts",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "HFSM Implementation",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/statewalker/statewalker-fsm-charts",
@@ -1 +1,2 @@
1
+ export * from "./types/index.ts";
1
2
  export * from "./layout/index.ts";
@@ -0,0 +1,2 @@
1
+ export * from "./types/index.ts";
2
+ export * from "./runtime/index.ts";
package/src/index-svg.ts CHANGED
@@ -1 +1,2 @@
1
+ export * from "./types/index.ts";
1
2
  export * from "./svg/index.ts";
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
- export * from "./index-layout.ts";
2
- export * from "./index-svg.ts";
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 "./GraphParamsProvider.ts";
2
- import type { StateGraphNode } from "./StateGraphNode.ts";
3
- import type { StateGraphEdge } from "./StateGraphEdge.ts";
4
- import type { Padding } from "./Padding.ts";
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 "./GraphParamsProvider.ts";
5
- import type { Transition } from "./Transition.ts";
6
- import type { TransitionsGraph } from "./TransitionsGraph.ts";
7
- import type { StateGraphNode } from "./StateGraphNode.ts";
8
- import type { StateGraphEdge } from "./StateGraphEdge.ts";
9
- import { Padding } from "./Padding.ts";
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 "./Dimensions.ts";
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 "./Dimensions.ts";
2
- import type { Padding } from "./Padding.ts";
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(
@@ -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 "../layout/index.ts";
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 "../layout/StateChart.ts";
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
- }) : void {
16
+ }): void {
17
17
  render(statechart, println);
18
18
 
19
19
  function render(statechart: StateChart, println: (str: string) => void) {
20
- println(` <details class="state-details" data-state-id="${statechart.id}">`);
21
- println(` <summary class="state-details__label">${statechart.key}</summary>`);
22
- println(` <div class="state-details__description"><div class="state-details__chart">`);
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.graph,
31
+ graph: statechart,
26
32
  newId,
27
33
  println: printChildren,
28
34
  initialStateKey,
@@ -0,0 +1,7 @@
1
+ import type { Transition } from "./Transition.ts";
2
+
3
+ export type FsmStateConfig = {
4
+ key: string;
5
+ transitions: Transition[];
6
+ states?: FsmStateConfig[];
7
+ };
@@ -1,8 +1,7 @@
1
1
  import type { TransitionsGraph } from "./TransitionsGraph.ts";
2
2
 
3
- export type StateChart = {
3
+ export type StateChart = TransitionsGraph & {
4
4
  id: string;
5
5
  key: string;
6
6
  children?: StateChart[];
7
- graph: TransitionsGraph;
8
7
  } & Record<string, any>;
@@ -1,5 +1,5 @@
1
- import { Dimensions } from "./Dimensions.ts";
2
- import { Position } from "./Position.ts";
1
+ import type { Dimensions } from "./Dimensions.ts";
2
+ import type { Position } from "./Position.ts";
3
3
 
4
4
  /**
5
5
  * Information about a state graph edge.
@@ -1,5 +1,5 @@
1
- import { Dimensions } from "./Dimensions";
2
- import { Position } from "./Position";
1
+ import type { Dimensions } from "./Dimensions.ts";
2
+ import type { Position } from "./Position.ts";
3
3
 
4
4
  /**
5
5
  * Information about a state node in the graph.
@@ -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";
@@ -1,4 +1,4 @@
1
- import { Padding } from "../layout/Padding.ts";
1
+ import type { Padding } from "../types/Padding.ts";
2
2
 
3
3
  /**
4
4
  * Expands a padding value to a 4-element array: [top, right, bottom, left].
@@ -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 };
@@ -1,5 +0,0 @@
1
- export type FsmStateConfig = {
2
- key : string;
3
- transitions: [string, string, string][];
4
- states?: FsmStateConfig[];
5
- }
@@ -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