@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.
Files changed (155) hide show
  1. package/README.md +206 -1
  2. package/dist/StateChart-cXyVRcs-.d.ts +94 -0
  3. package/dist/StateChart-cXyVRcs-.d.ts.map +1 -0
  4. package/dist/StateChartIndex-BK2315qj.d.ts +142 -0
  5. package/dist/StateChartIndex-BK2315qj.d.ts.map +1 -0
  6. package/dist/StateChartIndex-BOIrc_nq.js +355 -0
  7. package/dist/StateChartIndex-BOIrc_nq.js.map +1 -0
  8. package/dist/buildStatechartsPanel-CxQlIwTh.js +494 -0
  9. package/dist/buildStatechartsPanel-CxQlIwTh.js.map +1 -0
  10. package/dist/buildStatechartsPanel-hCtZbdiF.d.ts +79 -0
  11. package/dist/buildStatechartsPanel-hCtZbdiF.d.ts.map +1 -0
  12. package/dist/defineProperty-C0rC37pP.js +39 -0
  13. package/dist/description-panels-DI2MNlbK.js +184 -0
  14. package/dist/description-panels-DI2MNlbK.js.map +1 -0
  15. package/dist/getLabelDimensions-BY0q7j3D.d.ts +79 -0
  16. package/dist/getLabelDimensions-BY0q7j3D.d.ts.map +1 -0
  17. package/dist/getPadding-Cw0e7G2v.js +25 -0
  18. package/dist/getPadding-Cw0e7G2v.js.map +1 -0
  19. package/dist/index-config.d.ts +3 -12
  20. package/dist/index-config.js +2 -1
  21. package/dist/index-dom.d.ts +2 -49
  22. package/dist/index-dom.js +2 -1
  23. package/dist/index-html.d.ts +3 -2
  24. package/dist/index-html.js +2 -2
  25. package/dist/index-layout.d.ts +3 -77
  26. package/dist/index-layout.js +2 -2
  27. package/dist/index-runtime.d.ts +3 -141
  28. package/dist/index-runtime.js +2 -1
  29. package/dist/index.d.ts +11 -10
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +6 -6
  32. package/dist/layout-Dp671N6q.js +2465 -0
  33. package/dist/layout-Dp671N6q.js.map +1 -0
  34. package/dist/newTreeBuilder-CvtLDjGj.d.ts +54 -0
  35. package/dist/newTreeBuilder-CvtLDjGj.d.ts.map +1 -0
  36. package/dist/toFsmStateConfig-DlJkyZni.js +135 -0
  37. package/dist/toFsmStateConfig-DlJkyZni.js.map +1 -0
  38. package/dist/toFsmStateConfig-DmOlTRjv.d.ts +15 -0
  39. package/dist/toFsmStateConfig-DmOlTRjv.d.ts.map +1 -0
  40. package/package.json +54 -28
  41. package/src/config/concatTransitionsToString.ts +4 -4
  42. package/src/config/index.ts +4 -4
  43. package/src/config/serializeProcessConfig.ts +3 -3
  44. package/src/config/splitTransitionString.ts +2 -4
  45. package/src/config/toFsmStateConfig.ts +5 -12
  46. package/src/dagre/acyclic.js +9 -10
  47. package/src/dagre/add-border-segments.js +11 -7
  48. package/src/dagre/coordinate-system.js +12 -12
  49. package/src/dagre/data/list.js +2 -2
  50. package/src/dagre/debug.d.ts +1 -1
  51. package/src/dagre/debug.js +11 -11
  52. package/src/dagre/greedy-fas.js +17 -21
  53. package/src/dagre/index.d.ts +4 -4
  54. package/src/dagre/index.js +4 -4
  55. package/src/dagre/layout.js +107 -96
  56. package/src/dagre/nesting-graph.js +13 -19
  57. package/src/dagre/normalize.js +7 -7
  58. package/src/dagre/order/add-subgraph-constraints.js +2 -2
  59. package/src/dagre/order/barycenter.d.ts +1 -1
  60. package/src/dagre/order/barycenter.js +4 -4
  61. package/src/dagre/order/build-layer-graph.d.ts +1 -1
  62. package/src/dagre/order/build-layer-graph.js +7 -9
  63. package/src/dagre/order/cross-count.js +14 -17
  64. package/src/dagre/order/index.js +19 -17
  65. package/src/dagre/order/init-order.js +5 -15
  66. package/src/dagre/order/resolve-conflicts.js +10 -14
  67. package/src/dagre/order/sort-subgraph.d.ts +1 -1
  68. package/src/dagre/order/sort-subgraph.js +13 -14
  69. package/src/dagre/order/sort.d.ts +1 -1
  70. package/src/dagre/order/sort.js +6 -10
  71. package/src/dagre/parent-dummy-chains.js +10 -4
  72. package/src/dagre/position/bk.d.ts +3 -3
  73. package/src/dagre/position/bk.js +84 -65
  74. package/src/dagre/position/index.js +7 -11
  75. package/src/dagre/rank/feasible-tree.d.ts +1 -1
  76. package/src/dagre/rank/feasible-tree.js +6 -6
  77. package/src/dagre/rank/index.js +6 -6
  78. package/src/dagre/rank/network-simplex.d.ts +0 -1
  79. package/src/dagre/rank/network-simplex.js +20 -25
  80. package/src/dagre/rank/util.js +2 -6
  81. package/src/dagre/util.d.ts +12 -6
  82. package/src/dagre/util.js +31 -37
  83. package/src/dom/buildSections.ts +15 -19
  84. package/src/dom/description-panels.ts +5 -7
  85. package/src/dom/getStatesDescriptions.ts +4 -10
  86. package/src/full/index.ts +1 -1
  87. package/src/full/toFsmStateCharts.ts +11 -11
  88. package/src/graphlib/alg/components.js +2 -2
  89. package/src/graphlib/alg/dfs.js +5 -5
  90. package/src/graphlib/alg/dijkstra-all.js +4 -4
  91. package/src/graphlib/alg/dijkstra.js +9 -12
  92. package/src/graphlib/alg/find-cycles.js +7 -5
  93. package/src/graphlib/alg/floyd-warshall.js +8 -11
  94. package/src/graphlib/alg/index.d.ts +11 -11
  95. package/src/graphlib/alg/index.js +11 -11
  96. package/src/graphlib/alg/is-acyclic.js +1 -1
  97. package/src/graphlib/alg/postorder.js +2 -2
  98. package/src/graphlib/alg/preorder.js +2 -2
  99. package/src/graphlib/alg/prim.d.ts +1 -1
  100. package/src/graphlib/alg/prim.js +5 -5
  101. package/src/graphlib/alg/tarjan.js +3 -3
  102. package/src/graphlib/alg/topsort.js +1 -1
  103. package/src/graphlib/data/priority-queue.js +8 -10
  104. package/src/graphlib/graph.js +53 -52
  105. package/src/graphlib/index.d.ts +2 -2
  106. package/src/graphlib/index.js +2 -2
  107. package/src/graphlib/json.d.ts +1 -1
  108. package/src/graphlib/json.js +6 -6
  109. package/src/html/buildStatechartCss.ts +2 -2
  110. package/src/html/buildStatechartStyles.ts +5 -15
  111. package/src/html/buildStatechartSvg.ts +8 -20
  112. package/src/html/buildStatechartsPanel.ts +3 -5
  113. package/src/html/index.ts +4 -4
  114. package/src/index-config.ts +2 -2
  115. package/src/index-dom.ts +1 -1
  116. package/src/index-html.ts +2 -2
  117. package/src/index-layout.ts +2 -2
  118. package/src/index-runtime.ts +2 -2
  119. package/src/index.ts +8 -8
  120. package/src/layout/buildCharts.ts +6 -7
  121. package/src/layout/buildFlatCharts.ts +17 -21
  122. package/src/layout/getGraphParamsProvider.ts +7 -19
  123. package/src/layout/getLabelDimensions.ts +5 -5
  124. package/src/layout/index.ts +5 -4
  125. package/src/lodash-es/index.ts +2 -2
  126. package/src/lodash-es/types.ts +37 -35
  127. package/src/runtime/RuntimeStatechartApi.ts +13 -46
  128. package/src/runtime/StateChartIndex.ts +7 -24
  129. package/src/runtime/index.ts +2 -2
  130. package/src/types/FsmStateConfig.ts +1 -1
  131. package/src/types/GraphParamsProvider.ts +3 -6
  132. package/src/types/Position.ts +1 -1
  133. package/src/types/StateChart.ts +2 -2
  134. package/src/types/StateGraphEdge.ts +2 -2
  135. package/src/types/StateGraphNode.ts +2 -2
  136. package/src/types/TransitionsGraph.ts +4 -4
  137. package/src/types/index.ts +11 -11
  138. package/src/utils/BasisCurve.ts +6 -15
  139. package/src/utils/domToText.ts +3 -7
  140. package/src/utils/getPadding.ts +2 -3
  141. package/src/utils/newId.ts +2 -1
  142. package/src/utils/newRegistry.ts +13 -13
  143. package/src/utils/serializeAttrs.ts +6 -14
  144. package/src/utils/serializeCss.ts +3 -7
  145. package/src/utils/serializeStyle.ts +2 -5
  146. package/src/utils/toKebabCase.ts +1 -4
  147. package/CHANGELOG.md +0 -1
  148. package/dist/StateChart-BYBjTmC2.d.ts +0 -82
  149. package/dist/chunk-36ZLXJVD.js +0 -606
  150. package/dist/chunk-AZBRQNTU.js +0 -2739
  151. package/dist/chunk-FIQDLBWD.js +0 -9
  152. package/dist/chunk-SVKVQY7B.js +0 -133
  153. package/dist/chunk-TZHCBZVP.js +0 -422
  154. package/dist/chunk-VILLJJJD.js +0 -231
  155. 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 { 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
-
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
- let prevLodash = getLodash();
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
- .edges()
99
- .map(({ v, w, name }: { v: string; w: string; name: string }) => {
100
- const e = graph.edge(v, w, name) as StateGraphEdge;
101
- e.x += -e.width / 2;
102
- e.y += -e.height / 2;
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 { Dimensions } from "../types/Dimensions.ts";
2
- import type { GraphParamsProvider } from "../types/GraphParamsProvider.ts";
3
- import type { Padding } from "../types/Padding.ts";
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 = (fromState: string, event: string, toState: string) =>
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.ts";
2
- import type { Padding } from "../types/Padding.ts";
3
- import { getPadding } from "../utils/getPadding.ts";
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);
@@ -1,5 +1,6 @@
1
1
  // Methods
2
- export * from "./buildFlatCharts.ts";
3
- export * from "./buildCharts.ts";
4
- export * from "./getGraphParamsProvider.ts";
5
- export * from "./getLabelDimensions.ts";
2
+
3
+ export * from "./buildCharts.js";
4
+ export * from "./buildFlatCharts.js";
5
+ export * from "./getGraphParamsProvider.js";
6
+ export * from "./getLabelDimensions.js";
@@ -2,8 +2,8 @@ export let _: any = {
2
2
  constant: (value: any) => () => value,
3
3
  };
4
4
  export function setLodash(lib: any) {
5
- _ = lib;
5
+ _ = lib;
6
6
  }
7
- export function getLodash() {
7
+ export function getLodash() {
8
8
  return _;
9
9
  }
@@ -1,35 +1,37 @@
1
- export type { constant } from "lodash-es";
2
- export type { clone } from "lodash-es";
3
- export type { cloneDeep } from "lodash-es";
4
- export type { defaults } from "lodash-es";
5
- export type { each } from "lodash-es";
6
- export type { forEach } from "lodash-es";
7
- export type { find } from "lodash-es";
8
- export type { filter } from "lodash-es";
9
- export type { flatten } from "lodash-es";
10
- export type { forIn } from "lodash-es";
11
- export type { forOwn } from "lodash-es";
12
- export type { has } from "lodash-es";
13
- export type { isArray } from "lodash-es";
14
- export type { isEmpty } from "lodash-es";
15
- export type { isFunction } from "lodash-es";
16
- export type { isUndefined } from "lodash-es";
17
- export type { keys } from "lodash-es";
18
- export type { last } from "lodash-es";
19
- export type { map } from "lodash-es";
20
- export type { mapValues } from "lodash-es";
21
- export type { max } from "lodash-es";
22
- export type { merge } from "lodash-es";
23
- export type { min } from "lodash-es";
24
- export type { minBy } from "lodash-es";
25
- export type { now } from "lodash-es";
26
- export type { pick } from "lodash-es";
27
- export type { range } from "lodash-es";
28
- export type { reduce } from "lodash-es";
29
- export type { sortBy } from "lodash-es";
30
- export type { size } from "lodash-es";
31
- export type { transform } from "lodash-es";
32
- export type { values } from "lodash-es";
33
- export type { uniqueId } from "lodash-es";
34
- export type { union } from "lodash-es";
35
- export type { zipObject } from "lodash-es";
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.ts";
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).forEach((r) => r && r());
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: string,
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
- let result = [];
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
- transition?: StateGraphEdge,
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;
@@ -1,2 +1,2 @@
1
- export * from "./RuntimeStatechartApi.ts";
2
- export * from "./StateChartIndex.ts";
1
+ export * from "./RuntimeStatechartApi.js";
2
+ export * from "./StateChartIndex.js";
@@ -1,4 +1,4 @@
1
- import type { Transition } from "./Transition.ts";
1
+ import type { Transition } from "./Transition.js";
2
2
 
3
3
  // export type FsmStateKey = string;
4
4
  // export type FsmEventKey = string;
@@ -1,14 +1,11 @@
1
- import type { Dimensions } from "./Dimensions.ts";
2
- import { Label } from "./Label.ts";
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,
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * X/Y position of a node in the graph.
3
3
  */
4
- export type Position = { x: number; y: number; };
4
+ export type Position = { x: number; y: number };
@@ -1,5 +1,5 @@
1
- import type { StateGraphNode } from "./StateGraphNode.ts";
2
- import type { TransitionsGraph } from "./TransitionsGraph.ts";
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,5 +1,5 @@
1
- import type { Dimensions } from "./Dimensions.ts";
2
- import type { Position } from "./Position.ts";
1
+ import type { Dimensions } from "./Dimensions.js";
2
+ import type { Position } from "./Position.js";
3
3
 
4
4
  /**
5
5
  * Information about a state graph edge.
@@ -1,5 +1,5 @@
1
- import type { Dimensions } from "./Dimensions.ts";
2
- import type { Position } from "./Position.ts";
1
+ import type { Dimensions } from "./Dimensions.js";
2
+ import type { Position } from "./Position.js";
3
3
 
4
4
  /**
5
5
  * Information about a state node in the graph.
@@ -1,7 +1,7 @@
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";
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.
@@ -1,11 +1,11 @@
1
- export type * from "./Dimensions.ts";
2
- export type * from "./FsmStateConfig.ts";
3
- export type * from "./GraphParamsProvider.ts";
4
- export type * from "./Label.ts";
5
- export type * from "./Padding.ts";
6
- export type * from "./Position.ts";
7
- export type * from "./StateChart.ts";
8
- export type * from "./StateGraphEdge.ts";
9
- export type * from "./StateGraphNode.ts";
10
- export type * from "./Transition.ts";
11
- export type * from "./TransitionsGraph.ts";
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";
@@ -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;
@@ -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 (var i = 0; i < el.childNodes.length; i++) {
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 && !Boolean(result)) continue;
19
+ if (result !== undefined && !result) continue;
24
20
  visit(child as HTMLElement, visitor);
25
21
  }
26
22
  }
@@ -1,4 +1,4 @@
1
- import type { Padding } from "../types/Padding.ts";
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
  }
@@ -1,5 +1,6 @@
1
1
  export function newId(prefix: string = "id"): string {
2
2
  const ns = newId as any;
3
- const id = (ns._idCounter = (ns._idCounter || 0) + 1);
3
+ ns._idCounter = (ns._idCounter || 0) + 1;
4
+ const id = ns._idCounter;
4
5
  return `${prefix}_${id}`;
5
6
  }