state-machine-cat 12.0.20 → 12.0.22

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016-2024 Sander Verweij
3
+ Copyright (c) 2016-2025 Sander Verweij
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -5,7 +5,7 @@ const LICENSE = `
5
5
 
6
6
  The MIT License (MIT)
7
7
 
8
- Copyright (c) 2016-2024 Sander Verweij
8
+ Copyright (c) 2016-2025 Sander Verweij
9
9
 
10
10
  Permission is hereby granted, free of charge, to any person obtaining
11
11
  a copy of this software and associated documentation files (the
package/dist/counter.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  export class Counter {
2
- _lHWM = 0;
2
+ #lHWM = 0;
3
3
  constructor(pStart = 0) {
4
- this._lHWM = pStart;
4
+ this.#lHWM = pStart;
5
5
  }
6
6
  next() {
7
- return ++this._lHWM;
7
+ return ++this.#lHWM;
8
8
  }
9
9
  }
@@ -1,4 +1,4 @@
1
- import fastxml from "fast-xml-parser";
1
+ import { XMLParser } from "fast-xml-parser";
2
2
  import he from "he";
3
3
  import traverse from "neotraverse";
4
4
  import { Counter } from "../../counter.mjs";
@@ -160,7 +160,7 @@ export function parse(pSCXMLString) {
160
160
  const lTrimmedSCXMLString = pSCXMLString.trim();
161
161
  const lAttributeNamePrefix = "@_";
162
162
  let lXMLAsJSON = {};
163
- const lXMLParser = new fastxml.XMLParser({
163
+ const lXMLParser = new XMLParser({
164
164
  attributeNamePrefix: lAttributeNamePrefix,
165
165
  ignoreAttributes: false,
166
166
  parseTagValue: true,
@@ -16,7 +16,6 @@ import {
16
16
  normalizeState,
17
17
  stateNote,
18
18
  } from "./utl.mjs";
19
- let gRenderedTransitions = new Set();
20
19
  function initial(pState, pIndent) {
21
20
  const lActiveAttribute = pState.active ? " penwidth=3.0" : "";
22
21
  return `${pIndent} "${pState.name}" [shape=circle style=filled class="${pState.class}" color="${pState.color}" fillcolor="${pState.color}" fixedsize=true height=0.15 label=""${lActiveAttribute}]${pState.noteText}`;
@@ -61,7 +60,13 @@ ${pIndent} </table>`;
61
60
  return `${pIndent} "${pState.name}" [margin=0 class="${pState.class}" label= <${lLabelTag}
62
61
  ${pIndent} >${pState.colorAttribute}${pState.fontColorAttribute}${lActiveAttribute}]${pState.noteText}`;
63
62
  }
64
- function compositeRegular(pState, pIndent, pOptions, pModel) {
63
+ function compositeRegular(
64
+ pState,
65
+ pIndent,
66
+ pOptions,
67
+ pModel,
68
+ pRenderedTransitions,
69
+ ) {
65
70
  const lPenWidth = pState.isParallelArea
66
71
  ? "1.0"
67
72
  : pState.active
@@ -85,12 +90,18 @@ ${pIndent} class="${pState.class}" label= <
85
90
  ${lLabelTag}
86
91
  ${pIndent} > style=${lStyle} penwidth=${lPenWidth}${pState.colorAttribute}${pState.fontColorAttribute}
87
92
  ${pIndent} "${pState.name}" [shape=point style=invis margin=0 width=0 height=0 fixedsize=true]
88
- ${states(pState?.statemachine?.states ?? [], `${pIndent} `, pOptions, pModel)}
93
+ ${states(pState?.statemachine?.states ?? [], `${pIndent} `, pOptions, pModel, pRenderedTransitions)}
89
94
  ${pIndent} }${pState.noteText}`;
90
95
  }
91
- function regular(pState, pIndent, pOptions, pModel) {
96
+ function regular(pState, pIndent, pOptions, pModel, pRenderedTransitions) {
92
97
  if (pState.statemachine) {
93
- return compositeRegular(pState, pIndent, pOptions, pModel);
98
+ return compositeRegular(
99
+ pState,
100
+ pIndent,
101
+ pOptions,
102
+ pModel,
103
+ pRenderedTransitions,
104
+ );
94
105
  }
95
106
  return atomicRegular(pState, pIndent);
96
107
  }
@@ -163,14 +174,14 @@ const STATE_TYPE2FUNCTION = new Map([
163
174
  ["terminate", terminate],
164
175
  ["final", final],
165
176
  ]);
166
- function state(pState, pIndent, pOptions, pModel) {
177
+ function state(pState, pIndent, pOptions, pModel, pRenderedTransitions) {
167
178
  const lState = normalizeState(pState, pOptions, pIndent);
168
179
  const lCandidateTransitions = pModel.findTransitionsToSiblings(
169
180
  pState.name,
170
- gRenderedTransitions,
181
+ pRenderedTransitions,
171
182
  );
172
183
  lCandidateTransitions.forEach((pTransition) => {
173
- gRenderedTransitions.add(pTransition.id);
184
+ pRenderedTransitions.add(pTransition.id);
174
185
  });
175
186
  const lTransitions = transitions(
176
187
  lCandidateTransitions,
@@ -184,14 +195,17 @@ function state(pState, pIndent, pOptions, pModel) {
184
195
  pIndent,
185
196
  pOptions,
186
197
  pModel,
198
+ pRenderedTransitions,
187
199
  ) +
188
200
  lTransitions +
189
201
  "\n"
190
202
  );
191
203
  }
192
- function states(pStates, pIndent, pOptions, pModel) {
204
+ function states(pStates, pIndent, pOptions, pModel, pRenderedTransitions) {
193
205
  return pStates
194
- .map((pState) => state(pState, pIndent, pOptions, pModel))
206
+ .map((pState) =>
207
+ state(pState, pIndent, pOptions, pModel, pRenderedTransitions),
208
+ )
195
209
  .join("");
196
210
  }
197
211
  function transition(pTransition, pIndent, pOptions, pModel) {
@@ -256,17 +270,22 @@ export default function renderDot(pStateMachine, pOptions = {}, pIndent = "") {
256
270
  const lNodeAttributes = buildNodeAttributes(pOptions.dotNodeAttrs || []);
257
271
  const lEdgeAttributes = buildEdgeAttributes(pOptions.dotEdgeAttrs || []);
258
272
  const lModel = new StateMachineModel(pStateMachine);
259
- gRenderedTransitions = new Set();
260
- const lStates = states(pStateMachine.states, pIndent, pOptions, lModel);
273
+ const lRenderedTransitions = new Set();
274
+ const lStates = states(
275
+ pStateMachine.states,
276
+ pIndent,
277
+ pOptions,
278
+ lModel,
279
+ lRenderedTransitions,
280
+ );
261
281
  const lRemainingTransitions = transitions(
262
282
  lModel.flattenedTransitions.filter(
263
- (pTransition) => !gRenderedTransitions.has(pTransition.id),
283
+ (pTransition) => !lRenderedTransitions.has(pTransition.id),
264
284
  ),
265
285
  pIndent,
266
286
  pOptions,
267
287
  lModel,
268
288
  );
269
- gRenderedTransitions = new Set();
270
289
  return `digraph "state transitions" {
271
290
  ${lGraphAttributes}
272
291
  node [${lNodeAttributes}]
@@ -32,26 +32,26 @@ function flattenTransitions(pStateMachine) {
32
32
  return lTransitions;
33
33
  }
34
34
  export default class StateMachineModel {
35
- _flattenedTransitions;
36
- _flattenedStates;
35
+ #flattenedTransitions;
36
+ #flattenedStates;
37
37
  constructor(pStateMachine) {
38
- this._flattenedStates = new Map();
39
- flattenStatesToMap(pStateMachine.states ?? [], this._flattenedStates);
40
- this._flattenedTransitions = flattenTransitions(pStateMachine);
38
+ this.#flattenedStates = new Map();
39
+ flattenStatesToMap(pStateMachine.states ?? [], this.#flattenedStates);
40
+ this.#flattenedTransitions = flattenTransitions(pStateMachine);
41
41
  }
42
42
  get flattenedTransitions() {
43
- return this._flattenedTransitions;
43
+ return this.#flattenedTransitions;
44
44
  }
45
45
  findStateByName(pName) {
46
- return this._flattenedStates.get(pName);
46
+ return this.#flattenedStates.get(pName);
47
47
  }
48
48
  findStatesByTypes(pTypes) {
49
- return Array.from(this._flattenedStates.values()).filter((pState) =>
49
+ return Array.from(this.#flattenedStates.values()).filter((pState) =>
50
50
  pTypes.includes(pState.type),
51
51
  );
52
52
  }
53
53
  findExternalSelfTransitions(pStateName) {
54
- return this._flattenedTransitions.filter(
54
+ return this.#flattenedTransitions.filter(
55
55
  (pTransition) =>
56
56
  pTransition.from === pStateName &&
57
57
  pTransition.to === pStateName &&
@@ -59,25 +59,25 @@ export default class StateMachineModel {
59
59
  );
60
60
  }
61
61
  findTransitionsByFrom(pFromStateName) {
62
- return this._flattenedTransitions.filter(
62
+ return this.#flattenedTransitions.filter(
63
63
  (pTransition) => pTransition.from === pFromStateName,
64
64
  );
65
65
  }
66
66
  findTransitionsByTo(pToStateName) {
67
- return this._flattenedTransitions.filter(
67
+ return this.#flattenedTransitions.filter(
68
68
  (pTransition) => pTransition.to === pToStateName,
69
69
  );
70
70
  }
71
71
  getMaximumTransitionId() {
72
- return Math.max(...this._flattenedTransitions.map(({ id }) => id));
72
+ return Math.max(...this.#flattenedTransitions.map(({ id }) => id));
73
73
  }
74
74
  findTransitionsToSiblings(pStateName, pExcludeIds) {
75
- return this._flattenedTransitions.filter(
75
+ return this.#flattenedTransitions.filter(
76
76
  (pTransition) =>
77
77
  !pExcludeIds.has(pTransition.id) &&
78
78
  pTransition.from === pStateName &&
79
- this._flattenedStates.get(pTransition.to)?.parent ===
80
- this._flattenedStates.get(pStateName)?.parent,
79
+ this.#flattenedStates.get(pTransition.to)?.parent ===
80
+ this.#flattenedStates.get(pStateName)?.parent,
81
81
  );
82
82
  }
83
83
  }
package/dist/version.mjs CHANGED
@@ -1 +1 @@
1
- export const version = "12.0.20";
1
+ export const version = "12.0.22";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "state-machine-cat",
3
- "version": "12.0.20",
3
+ "version": "12.0.22",
4
4
  "description": "write beautiful state charts",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.mjs",
@@ -42,7 +42,7 @@
42
42
  "dependencies": {
43
43
  "@hpcc-js/wasm-graphviz": "1.7.0",
44
44
  "ajv": "8.17.1",
45
- "fast-xml-parser": "4.5.1",
45
+ "fast-xml-parser": "5.2.0",
46
46
  "he": "1.2.0",
47
47
  "neotraverse": "0.6.18"
48
48
  },