state-machine-cat 12.0.6 → 12.0.7

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 (45) hide show
  1. package/dist/cli/actions.mjs +34 -31
  2. package/dist/cli/attributes-parser.mjs +914 -889
  3. package/dist/cli/execute-command-line.mjs +98 -48
  4. package/dist/cli/file-name-to-stream.mjs +8 -8
  5. package/dist/cli/normalize.mjs +89 -70
  6. package/dist/cli/validations.mjs +72 -52
  7. package/dist/index-node.mjs +12 -9
  8. package/dist/index.mjs +10 -7
  9. package/dist/options.mjs +53 -53
  10. package/dist/parse/index.mjs +17 -17
  11. package/dist/parse/parser-helpers.mjs +159 -139
  12. package/dist/parse/scxml/index.mjs +152 -129
  13. package/dist/parse/scxml/normalize-machine.mjs +36 -35
  14. package/dist/parse/scxml/utl.mjs +1 -1
  15. package/dist/parse/smcat/smcat-parser.mjs +2794 -2844
  16. package/dist/parse/smcat-ast.schema.mjs +185 -168
  17. package/dist/render/dot/attributebuilder.mjs +40 -37
  18. package/dist/render/dot/counter.mjs +14 -14
  19. package/dist/render/dot/dot.states.template.js +1 -26
  20. package/dist/render/dot/dot.template.js +1 -14
  21. package/dist/render/dot/index.mjs +129 -82
  22. package/dist/render/dot/render-dot-from-ast.mjs +33 -16
  23. package/dist/render/dot/state-transformers.mjs +96 -85
  24. package/dist/render/dot/transition-transformers.mjs +39 -41
  25. package/dist/render/dot/utl.mjs +21 -19
  26. package/dist/render/index-node.mjs +16 -16
  27. package/dist/render/index.mjs +9 -9
  28. package/dist/render/scjson/index.mjs +111 -94
  29. package/dist/render/scjson/make-valid-event-names.mjs +21 -18
  30. package/dist/render/scjson/make-valid-xml-name.mjs +17 -13
  31. package/dist/render/scxml/index.mjs +2 -1
  32. package/dist/render/scxml/render-from-scjson.mjs +5 -2
  33. package/dist/render/scxml/scxml.states.template.js +1 -14
  34. package/dist/render/scxml/scxml.template.js +1 -6
  35. package/dist/render/smcat/index.mjs +54 -39
  36. package/dist/render/smcat/smcat.template.js +1 -13
  37. package/dist/render/vector/dot-to-vector-native.mjs +30 -26
  38. package/dist/render/vector/vector-native-dot-with-fallback.mjs +27 -20
  39. package/dist/render/vector/vector-with-wasm.mjs +13 -6
  40. package/dist/state-machine-model.mjs +67 -52
  41. package/dist/transform/desugar.mjs +115 -66
  42. package/dist/transform/utl.mjs +12 -12
  43. package/dist/version.mjs +1 -1
  44. package/package.json +74 -74
  45. package/types/state-machine-cat.d.mts +209 -209
@@ -1,58 +1,73 @@
1
1
  function flattenStates(pStates, pHasParent = false) {
2
- let lReturnValue = [];
3
- pStates
4
- .filter((pState) => Boolean(pState.statemachine))
5
- .forEach((pState) => {
6
- if (Object.prototype.hasOwnProperty.call(pState.statemachine, "states")) {
7
- lReturnValue = lReturnValue.concat(flattenStates(pState.statemachine.states, true));
8
- }
9
- });
10
- return lReturnValue.concat(pStates.map((pState) => ({
11
- name: pState.name,
12
- type: pState.type,
13
- statemachine: Boolean(pState.statemachine),
14
- hasParent: pHasParent,
15
- })));
2
+ let lReturnValue = [];
3
+ pStates
4
+ .filter((pState) => Boolean(pState.statemachine))
5
+ .forEach((pState) => {
6
+ if (Object.prototype.hasOwnProperty.call(pState.statemachine, "states")) {
7
+ lReturnValue = lReturnValue.concat(
8
+ flattenStates(pState.statemachine.states, true),
9
+ );
10
+ }
11
+ });
12
+ return lReturnValue.concat(
13
+ pStates.map((pState) => ({
14
+ name: pState.name,
15
+ type: pState.type,
16
+ statemachine: Boolean(pState.statemachine),
17
+ hasParent: pHasParent,
18
+ })),
19
+ );
16
20
  }
17
21
  function flattenTransitions(pStateMachine) {
18
- let lTransitions = [];
19
- if (Object.prototype.hasOwnProperty.call(pStateMachine, "transitions")) {
20
- lTransitions = pStateMachine.transitions;
21
- }
22
- if (Object.prototype.hasOwnProperty.call(pStateMachine, "states")) {
23
- pStateMachine.states
24
- .filter((pState) => Boolean(pState.statemachine))
25
- .forEach((pState) => {
26
- lTransitions = lTransitions.concat(flattenTransitions(pState.statemachine));
27
- });
28
- }
29
- return lTransitions;
22
+ let lTransitions = [];
23
+ if (Object.prototype.hasOwnProperty.call(pStateMachine, "transitions")) {
24
+ lTransitions = pStateMachine.transitions;
25
+ }
26
+ if (Object.prototype.hasOwnProperty.call(pStateMachine, "states")) {
27
+ pStateMachine.states
28
+ .filter((pState) => Boolean(pState.statemachine))
29
+ .forEach((pState) => {
30
+ lTransitions = lTransitions.concat(
31
+ flattenTransitions(pState.statemachine),
32
+ );
33
+ });
34
+ }
35
+ return lTransitions;
30
36
  }
31
37
  export default class StateMachineModel {
32
- _flattenedTransitions;
33
- _flattenedStates;
34
- constructor(pStateMachine) {
35
- this._flattenedStates = flattenStates(pStateMachine.states || []);
36
- this._flattenedTransitions = flattenTransitions(pStateMachine);
37
- }
38
- get flattenedTransitions() {
39
- return this._flattenedTransitions;
40
- }
41
- findStateByName(pName) {
42
- return this._flattenedStates.find((pState) => pState.name === pName);
43
- }
44
- findStatesByTypes(pTypes) {
45
- return this._flattenedStates.filter((pState) => pTypes.includes(pState.type));
46
- }
47
- findExternalSelfTransitions(pStateName) {
48
- return this._flattenedTransitions.filter((pTransition) => pTransition.from === pStateName &&
49
- pTransition.to === pStateName &&
50
- pTransition.type !== "internal");
51
- }
52
- findTransitionsByFrom(pFromStateName) {
53
- return this._flattenedTransitions.filter((pTransition) => pTransition.from === pFromStateName);
54
- }
55
- findTransitionsByTo(pToStateName) {
56
- return this._flattenedTransitions.filter((pTransition) => pTransition.to === pToStateName);
57
- }
38
+ _flattenedTransitions;
39
+ _flattenedStates;
40
+ constructor(pStateMachine) {
41
+ this._flattenedStates = flattenStates(pStateMachine.states || []);
42
+ this._flattenedTransitions = flattenTransitions(pStateMachine);
43
+ }
44
+ get flattenedTransitions() {
45
+ return this._flattenedTransitions;
46
+ }
47
+ findStateByName(pName) {
48
+ return this._flattenedStates.find((pState) => pState.name === pName);
49
+ }
50
+ findStatesByTypes(pTypes) {
51
+ return this._flattenedStates.filter((pState) =>
52
+ pTypes.includes(pState.type),
53
+ );
54
+ }
55
+ findExternalSelfTransitions(pStateName) {
56
+ return this._flattenedTransitions.filter(
57
+ (pTransition) =>
58
+ pTransition.from === pStateName &&
59
+ pTransition.to === pStateName &&
60
+ pTransition.type !== "internal",
61
+ );
62
+ }
63
+ findTransitionsByFrom(pFromStateName) {
64
+ return this._flattenedTransitions.filter(
65
+ (pTransition) => pTransition.from === pFromStateName,
66
+ );
67
+ }
68
+ findTransitionsByTo(pToStateName) {
69
+ return this._flattenedTransitions.filter(
70
+ (pTransition) => pTransition.to === pToStateName,
71
+ );
72
+ }
58
73
  }
@@ -1,77 +1,126 @@
1
1
  import StateMachineModel from "../state-machine-model.mjs";
2
2
  import utl from "./utl.mjs";
3
3
  function fuseTransitionAttribute(pIncomingThing, pOutgoingThing, pJoinChar) {
4
- return pIncomingThing
5
- ? `${pIncomingThing}${pJoinChar}${pOutgoingThing}`
6
- : pOutgoingThing;
4
+ return pIncomingThing
5
+ ? `${pIncomingThing}${pJoinChar}${pOutgoingThing}`
6
+ : pOutgoingThing;
7
7
  }
8
8
  function fuseIncomingToOutgoing(pIncomingTransition, pOutgoingTransition) {
9
- const lReturnValue = {
10
- ...pIncomingTransition,
11
- ...pOutgoingTransition,
12
- from: pIncomingTransition.from,
13
- to: pOutgoingTransition.to,
14
- };
15
- if (pOutgoingTransition.action) {
16
- lReturnValue.action = fuseTransitionAttribute(pIncomingTransition.action, pOutgoingTransition.action, "\n");
17
- }
18
- if (lReturnValue.event || lReturnValue.cond || lReturnValue.action) {
19
- lReturnValue.label = utl.formatLabel(lReturnValue.event, lReturnValue.cond, lReturnValue.action);
20
- }
21
- return lReturnValue;
9
+ const lReturnValue = {
10
+ ...pIncomingTransition,
11
+ ...pOutgoingTransition,
12
+ from: pIncomingTransition.from,
13
+ to: pOutgoingTransition.to,
14
+ };
15
+ if (pOutgoingTransition.action) {
16
+ lReturnValue.action = fuseTransitionAttribute(
17
+ pIncomingTransition.action,
18
+ pOutgoingTransition.action,
19
+ "\n",
20
+ );
21
+ }
22
+ if (lReturnValue.event || lReturnValue.cond || lReturnValue.action) {
23
+ lReturnValue.label = utl.formatLabel(
24
+ lReturnValue.event,
25
+ lReturnValue.cond,
26
+ lReturnValue.action,
27
+ );
28
+ }
29
+ return lReturnValue;
22
30
  }
23
- function fuseTransitions(pTransitions, pPseudoStateNames, pOutgoingTransitionMap) {
24
- return pTransitions.reduce((pAll, pTransition) => {
25
- pPseudoStateNames.forEach((pStateName, pIndex) => {
26
- if (pStateName === pTransition.to &&
27
- pOutgoingTransitionMap[pStateName]) {
28
- pAll = pAll.concat(pOutgoingTransitionMap[pStateName].map((pOutgoingTransition) => fuseIncomingToOutgoing(pTransition, pOutgoingTransition)));
29
- }
30
- else {
31
- pAll = pIndex === 0 ? pAll.concat(pTransition) : pAll;
32
- }
33
- });
34
- return pAll;
35
- }, []);
31
+ function fuseTransitions(
32
+ pTransitions,
33
+ pPseudoStateNames,
34
+ pOutgoingTransitionMap,
35
+ ) {
36
+ return pTransitions.reduce((pAll, pTransition) => {
37
+ pPseudoStateNames.forEach((pStateName, pIndex) => {
38
+ if (pStateName === pTransition.to && pOutgoingTransitionMap[pStateName]) {
39
+ pAll = pAll.concat(
40
+ pOutgoingTransitionMap[pStateName].map((pOutgoingTransition) =>
41
+ fuseIncomingToOutgoing(pTransition, pOutgoingTransition),
42
+ ),
43
+ );
44
+ } else {
45
+ pAll = pIndex === 0 ? pAll.concat(pTransition) : pAll;
46
+ }
47
+ });
48
+ return pAll;
49
+ }, []);
36
50
  }
37
- function deSugarPseudoStates(pMachine, pPseudoStateNames, pOutgoingTransitionMap) {
38
- const lMachine = structuredClone(pMachine);
39
- if (lMachine.transitions && pPseudoStateNames.length > 0) {
40
- lMachine.transitions = fuseTransitions(lMachine.transitions, pPseudoStateNames, pOutgoingTransitionMap);
41
- }
42
- lMachine.states = lMachine.states.map((pState) => pState.statemachine
43
- ? {
44
- ...pState,
45
- statemachine: deSugarPseudoStates(pState.statemachine, pPseudoStateNames, pOutgoingTransitionMap),
46
- }
47
- : pState);
48
- return lMachine;
51
+ function deSugarPseudoStates(
52
+ pMachine,
53
+ pPseudoStateNames,
54
+ pOutgoingTransitionMap,
55
+ ) {
56
+ const lMachine = structuredClone(pMachine);
57
+ if (lMachine.transitions && pPseudoStateNames.length > 0) {
58
+ lMachine.transitions = fuseTransitions(
59
+ lMachine.transitions,
60
+ pPseudoStateNames,
61
+ pOutgoingTransitionMap,
62
+ );
63
+ }
64
+ lMachine.states = lMachine.states.map((pState) =>
65
+ pState.statemachine
66
+ ? {
67
+ ...pState,
68
+ statemachine: deSugarPseudoStates(
69
+ pState.statemachine,
70
+ pPseudoStateNames,
71
+ pOutgoingTransitionMap,
72
+ ),
73
+ }
74
+ : pState,
75
+ );
76
+ return lMachine;
49
77
  }
50
78
  function removeStatesCascading(pMachine, pStateNames) {
51
- const lMachine = structuredClone(pMachine);
52
- if (lMachine.transitions) {
53
- lMachine.transitions = lMachine.transitions.filter((pTransition) => !pStateNames.some((pJunctionStateName) => pJunctionStateName === pTransition.from ||
54
- pJunctionStateName === pTransition.to));
55
- }
56
- lMachine.states = lMachine.states
57
- .filter((pState) => !pStateNames.includes(pState.name))
58
- .map((pState) => pState.statemachine
59
- ? {
60
- ...pState,
61
- statemachine: removeStatesCascading(pState.statemachine, pStateNames),
62
- }
63
- : pState);
64
- return lMachine;
79
+ const lMachine = structuredClone(pMachine);
80
+ if (lMachine.transitions) {
81
+ lMachine.transitions = lMachine.transitions.filter(
82
+ (pTransition) =>
83
+ !pStateNames.some(
84
+ (pJunctionStateName) =>
85
+ pJunctionStateName === pTransition.from ||
86
+ pJunctionStateName === pTransition.to,
87
+ ),
88
+ );
89
+ }
90
+ lMachine.states = lMachine.states
91
+ .filter((pState) => !pStateNames.includes(pState.name))
92
+ .map((pState) =>
93
+ pState.statemachine
94
+ ? {
95
+ ...pState,
96
+ statemachine: removeStatesCascading(
97
+ pState.statemachine,
98
+ pStateNames,
99
+ ),
100
+ }
101
+ : pState,
102
+ );
103
+ return lMachine;
65
104
  }
66
- export default (pMachine, pDesugarableStates = ["fork", "junction", "choice"]) => {
67
- const lModel = new StateMachineModel(pMachine);
68
- const lPseudoStateNames = lModel
69
- .findStatesByTypes(pDesugarableStates)
70
- .map(({ name }) => name);
71
- const lOutgoingTransitionMap = lPseudoStateNames.reduce((pAll, pStateName) => {
72
- pAll[pStateName] = lModel.findTransitionsByFrom(pStateName);
73
- return pAll;
74
- }, {});
75
- const lMachine = deSugarPseudoStates(pMachine, lPseudoStateNames, lOutgoingTransitionMap);
76
- return removeStatesCascading(lMachine, lPseudoStateNames);
105
+ export default (
106
+ pMachine,
107
+ pDesugarableStates = ["fork", "junction", "choice"],
108
+ ) => {
109
+ const lModel = new StateMachineModel(pMachine);
110
+ const lPseudoStateNames = lModel
111
+ .findStatesByTypes(pDesugarableStates)
112
+ .map(({ name }) => name);
113
+ const lOutgoingTransitionMap = lPseudoStateNames.reduce(
114
+ (pAll, pStateName) => {
115
+ pAll[pStateName] = lModel.findTransitionsByFrom(pStateName);
116
+ return pAll;
117
+ },
118
+ {},
119
+ );
120
+ const lMachine = deSugarPseudoStates(
121
+ pMachine,
122
+ lPseudoStateNames,
123
+ lOutgoingTransitionMap,
124
+ );
125
+ return removeStatesCascading(lMachine, lPseudoStateNames);
77
126
  };
@@ -1,16 +1,16 @@
1
1
  function formatLabel(pEvent, pCond, pActions) {
2
- let lReturnValue = "";
3
- if (pEvent) {
4
- lReturnValue += pEvent;
5
- }
6
- if (pCond) {
7
- lReturnValue += ` [${pCond}]`;
8
- }
9
- if (pActions) {
10
- lReturnValue += `/ ${pActions}`;
11
- }
12
- return lReturnValue.trim();
2
+ let lReturnValue = "";
3
+ if (pEvent) {
4
+ lReturnValue += pEvent;
5
+ }
6
+ if (pCond) {
7
+ lReturnValue += ` [${pCond}]`;
8
+ }
9
+ if (pActions) {
10
+ lReturnValue += `/ ${pActions}`;
11
+ }
12
+ return lReturnValue.trim();
13
13
  }
14
14
  export default {
15
- formatLabel,
15
+ formatLabel,
16
16
  };
package/dist/version.mjs CHANGED
@@ -1 +1 @@
1
- export const version = "12.0.6";
1
+ export const version = "12.0.7";
package/package.json CHANGED
@@ -1,76 +1,76 @@
1
1
  {
2
- "name": "state-machine-cat",
3
- "version": "12.0.6",
4
- "description": "write beautiful state charts",
5
- "main": "./dist/index.mjs",
6
- "module": "./dist/index.mjs",
7
- "exports": {
8
- ".": [
9
- {
10
- "types": "./types/state-machine-cat.d.mts",
11
- "import": "./dist/index.mjs"
12
- }
13
- ]
14
- },
15
- "types": "types/state-machine-cat.d.mts",
16
- "imports": {
17
- "#*": "./src/*"
18
- },
19
- "sideEffects": [
20
- "dist/render/smcat/smcat.template.js",
21
- "dist/render/dot/dot.states.template.js",
22
- "dist/render/dot/dot.template.js",
23
- "dist/render/scxml/scxml.states.template.js",
24
- "dist/render/scxml/scxml.template.js"
25
- ],
26
- "files": [
27
- "bin/",
28
- "dist/",
29
- "types/",
30
- "package.json",
31
- "README.md",
32
- "LICENSE"
33
- ],
34
- "keywords": [
35
- "state",
36
- "state chart",
37
- "state diagram",
38
- "state machine",
39
- "finite state machine",
40
- "fsm",
41
- "uml",
42
- "scxml"
43
- ],
44
- "author": "Sander Verweij",
45
- "license": "MIT",
46
- "bin": {
47
- "smcat": "bin/smcat.mjs",
48
- "sm-cat": "bin/smcat.mjs",
49
- "sm_cat": "bin/smcat.mjs",
50
- "state-machine-cat": "bin/smcat.mjs"
51
- },
52
- "dependencies": {
53
- "@hpcc-js/wasm": "2.16.0",
54
- "ajv": "8.12.0",
55
- "commander": "12.0.0",
56
- "fast-xml-parser": "4.3.5",
57
- "handlebars": "4.7.8",
58
- "he": "1.2.0",
59
- "semver": "^7.6.0",
60
- "traverse": "0.6.8"
61
- },
62
- "engines": {
63
- "node": "^18.17||>=20"
64
- },
65
- "homepage": "https://state-machine-cat.js.org",
66
- "repository": {
67
- "type": "git",
68
- "url": "git+https://github.com/sverweij/state-machine-cat.git"
69
- },
70
- "bugs": {
71
- "url": "https://github.com/sverweij/state-machine-cat/issues"
72
- },
73
- "scripts": {
74
- "test": "echo for test, build and static analysis scripts: see the github repository"
75
- }
2
+ "name": "state-machine-cat",
3
+ "version": "12.0.7",
4
+ "description": "write beautiful state charts",
5
+ "main": "./dist/index.mjs",
6
+ "module": "./dist/index.mjs",
7
+ "exports": {
8
+ ".": [
9
+ {
10
+ "types": "./types/state-machine-cat.d.mts",
11
+ "import": "./dist/index.mjs"
12
+ }
13
+ ]
14
+ },
15
+ "types": "types/state-machine-cat.d.mts",
16
+ "imports": {
17
+ "#*": "./src/*"
18
+ },
19
+ "sideEffects": [
20
+ "dist/render/smcat/smcat.template.js",
21
+ "dist/render/dot/dot.states.template.js",
22
+ "dist/render/dot/dot.template.js",
23
+ "dist/render/scxml/scxml.states.template.js",
24
+ "dist/render/scxml/scxml.template.js"
25
+ ],
26
+ "files": [
27
+ "bin/",
28
+ "dist/",
29
+ "types/",
30
+ "package.json",
31
+ "README.md",
32
+ "LICENSE"
33
+ ],
34
+ "keywords": [
35
+ "state",
36
+ "state chart",
37
+ "state diagram",
38
+ "state machine",
39
+ "finite state machine",
40
+ "fsm",
41
+ "uml",
42
+ "scxml"
43
+ ],
44
+ "author": "Sander Verweij",
45
+ "license": "MIT",
46
+ "bin": {
47
+ "smcat": "bin/smcat.mjs",
48
+ "sm-cat": "bin/smcat.mjs",
49
+ "sm_cat": "bin/smcat.mjs",
50
+ "state-machine-cat": "bin/smcat.mjs"
51
+ },
52
+ "dependencies": {
53
+ "@hpcc-js/wasm": "2.16.1",
54
+ "ajv": "8.12.0",
55
+ "commander": "12.0.0",
56
+ "fast-xml-parser": "4.3.6",
57
+ "handlebars": "4.7.8",
58
+ "he": "1.2.0",
59
+ "semver": "^7.6.0",
60
+ "traverse": "0.6.9"
61
+ },
62
+ "engines": {
63
+ "node": "^18.17||>=20"
64
+ },
65
+ "homepage": "https://state-machine-cat.js.org",
66
+ "repository": {
67
+ "type": "git",
68
+ "url": "git+https://github.com/sverweij/state-machine-cat.git"
69
+ },
70
+ "bugs": {
71
+ "url": "https://github.com/sverweij/state-machine-cat/issues"
72
+ },
73
+ "scripts": {
74
+ "test": "echo for test, build and static analysis scripts: see the github repository"
75
+ }
76
76
  }