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.
- package/dist/cli/actions.mjs +34 -31
- package/dist/cli/attributes-parser.mjs +914 -889
- package/dist/cli/execute-command-line.mjs +98 -48
- package/dist/cli/file-name-to-stream.mjs +8 -8
- package/dist/cli/normalize.mjs +89 -70
- package/dist/cli/validations.mjs +72 -52
- package/dist/index-node.mjs +12 -9
- package/dist/index.mjs +10 -7
- package/dist/options.mjs +53 -53
- package/dist/parse/index.mjs +17 -17
- package/dist/parse/parser-helpers.mjs +159 -139
- package/dist/parse/scxml/index.mjs +152 -129
- package/dist/parse/scxml/normalize-machine.mjs +36 -35
- package/dist/parse/scxml/utl.mjs +1 -1
- package/dist/parse/smcat/smcat-parser.mjs +2794 -2844
- package/dist/parse/smcat-ast.schema.mjs +185 -168
- package/dist/render/dot/attributebuilder.mjs +40 -37
- package/dist/render/dot/counter.mjs +14 -14
- package/dist/render/dot/dot.states.template.js +1 -26
- package/dist/render/dot/dot.template.js +1 -14
- package/dist/render/dot/index.mjs +129 -82
- package/dist/render/dot/render-dot-from-ast.mjs +33 -16
- package/dist/render/dot/state-transformers.mjs +96 -85
- package/dist/render/dot/transition-transformers.mjs +39 -41
- package/dist/render/dot/utl.mjs +21 -19
- package/dist/render/index-node.mjs +16 -16
- package/dist/render/index.mjs +9 -9
- package/dist/render/scjson/index.mjs +111 -94
- package/dist/render/scjson/make-valid-event-names.mjs +21 -18
- package/dist/render/scjson/make-valid-xml-name.mjs +17 -13
- package/dist/render/scxml/index.mjs +2 -1
- package/dist/render/scxml/render-from-scjson.mjs +5 -2
- package/dist/render/scxml/scxml.states.template.js +1 -14
- package/dist/render/scxml/scxml.template.js +1 -6
- package/dist/render/smcat/index.mjs +54 -39
- package/dist/render/smcat/smcat.template.js +1 -13
- package/dist/render/vector/dot-to-vector-native.mjs +30 -26
- package/dist/render/vector/vector-native-dot-with-fallback.mjs +27 -20
- package/dist/render/vector/vector-with-wasm.mjs +13 -6
- package/dist/state-machine-model.mjs +67 -52
- package/dist/transform/desugar.mjs +115 -66
- package/dist/transform/utl.mjs +12 -12
- package/dist/version.mjs +1 -1
- package/package.json +74 -74
- package/types/state-machine-cat.d.mts +209 -209
|
@@ -1,112 +1,123 @@
|
|
|
1
1
|
import utl from "./utl.mjs";
|
|
2
2
|
function isType(pString) {
|
|
3
|
-
|
|
3
|
+
return (pState) => pState.type === pString;
|
|
4
4
|
}
|
|
5
5
|
function isOneOfTypes(pStringArray) {
|
|
6
|
-
|
|
6
|
+
return (pState) => pStringArray.includes(pState.type);
|
|
7
7
|
}
|
|
8
8
|
function setLabel(pState) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const lState = structuredClone(pState);
|
|
10
|
+
lState.label = pState.label || pState.name;
|
|
11
|
+
return lState;
|
|
12
12
|
}
|
|
13
13
|
function nameNote(pState) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
if (pState.note) {
|
|
15
|
+
return {
|
|
16
|
+
noteName: `note_${pState.name}`,
|
|
17
|
+
...pState,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return pState;
|
|
21
21
|
}
|
|
22
22
|
function classifyState(pState) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
const lState = { ...pState };
|
|
24
|
+
const lClasses = ["state", pState.type];
|
|
25
|
+
if (pState.class) {
|
|
26
|
+
lClasses.push(pState.class.trim().replace(/[ ]{2,}/g, " "));
|
|
27
|
+
}
|
|
28
|
+
lState.class = lClasses.join(" ");
|
|
29
|
+
return lState;
|
|
30
30
|
}
|
|
31
31
|
function formatActionType(pString) {
|
|
32
|
-
|
|
32
|
+
return pString === "activity" ? "" : `${pString}/ `;
|
|
33
33
|
}
|
|
34
34
|
function flattenActions(pState) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
if (pState.actions) {
|
|
36
|
+
return {
|
|
37
|
+
...pState,
|
|
38
|
+
actionStrings: pState.actions.map(
|
|
39
|
+
(pAction) => `${formatActionType(pAction.type)}${pAction.body}`,
|
|
40
|
+
),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return pState;
|
|
42
44
|
}
|
|
43
45
|
function flattenNote(pState) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
if (pState.note) {
|
|
47
|
+
return {
|
|
48
|
+
...pState,
|
|
49
|
+
noteFlattened: pState.note.join(""),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return pState;
|
|
51
53
|
}
|
|
52
54
|
function recolor(pNodeAttributes) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
return (pState) => {
|
|
56
|
+
const lNodeColor = (pNodeAttributes || []).find(
|
|
57
|
+
(pAttribute) => pAttribute.name === "color",
|
|
58
|
+
)?.value;
|
|
59
|
+
if (
|
|
60
|
+
lNodeColor &&
|
|
61
|
+
!pState.color &&
|
|
62
|
+
isOneOfTypes([
|
|
63
|
+
"initial",
|
|
64
|
+
"fork",
|
|
65
|
+
"join",
|
|
66
|
+
"junction",
|
|
67
|
+
"forkjoin",
|
|
68
|
+
"final",
|
|
69
|
+
])(pState)
|
|
70
|
+
) {
|
|
71
|
+
pState.color = lNodeColor;
|
|
72
|
+
}
|
|
73
|
+
return pState;
|
|
74
|
+
};
|
|
69
75
|
}
|
|
70
76
|
function escapeStateStrings(pState) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
if (pState.note) {
|
|
78
|
+
return {
|
|
79
|
+
...pState,
|
|
80
|
+
note: pState.note.map(utl.escapeString),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return pState;
|
|
78
84
|
}
|
|
79
85
|
function tipForkJoinStates(pDirection) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
return (pState) => {
|
|
87
|
+
if (isOneOfTypes(["fork", "join", "forkjoin"])(pState)) {
|
|
88
|
+
return {
|
|
89
|
+
sizingExtras: utl.isVertical(pDirection) ? "height=0.1" : "width=0.1",
|
|
90
|
+
...pState,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return pState;
|
|
94
|
+
};
|
|
89
95
|
}
|
|
90
96
|
function flagParallelChildren(pState) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
if (
|
|
98
|
+
pState.type === "parallel" &&
|
|
99
|
+
pState.statemachine &&
|
|
100
|
+
pState.statemachine.states
|
|
101
|
+
) {
|
|
102
|
+
pState.statemachine.states = pState.statemachine.states.map(
|
|
103
|
+
(pChildState) =>
|
|
104
|
+
isType("regular")(pChildState)
|
|
105
|
+
? { ...pChildState, parentIsParallel: true }
|
|
106
|
+
: pChildState,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
return pState;
|
|
99
110
|
}
|
|
100
111
|
export default {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
isType,
|
|
113
|
+
isOneOfTypes,
|
|
114
|
+
setLabel,
|
|
115
|
+
classifyState,
|
|
116
|
+
nameNote,
|
|
117
|
+
flattenActions,
|
|
118
|
+
flattenNote,
|
|
119
|
+
recolor,
|
|
120
|
+
escapeStateStrings,
|
|
121
|
+
tipForkJoinStates,
|
|
122
|
+
flagParallelChildren,
|
|
112
123
|
};
|
|
@@ -1,49 +1,47 @@
|
|
|
1
1
|
import utl from "./utl.mjs";
|
|
2
2
|
function escapeTransitionStrings(pTransition) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
const lTransition = { ...pTransition };
|
|
4
|
+
if (lTransition.note) {
|
|
5
|
+
lTransition.note = lTransition.note.map(utl.escapeString);
|
|
6
|
+
}
|
|
7
|
+
if (lTransition.label) {
|
|
8
|
+
lTransition.label = utl.escapeLabelString(lTransition.label);
|
|
9
|
+
}
|
|
10
|
+
return lTransition;
|
|
11
11
|
}
|
|
12
12
|
function addPorts(pDirection) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return { ...pTransition, ...lAdditionalAttributes };
|
|
36
|
-
};
|
|
13
|
+
return (pTransition) => {
|
|
14
|
+
let lAdditionalAttributes = {};
|
|
15
|
+
if (pTransition.isCompositeSelf) {
|
|
16
|
+
if (utl.isVertical(pDirection)) {
|
|
17
|
+
lAdditionalAttributes = {
|
|
18
|
+
tailportflags: `tailport="e" headport="e"`,
|
|
19
|
+
headportflags: `tailport="w"`,
|
|
20
|
+
};
|
|
21
|
+
} else if (pTransition.hasParent) {
|
|
22
|
+
lAdditionalAttributes = {
|
|
23
|
+
tailportflags: `tailport="n" headport="n"`,
|
|
24
|
+
headportflags: `tailport="s"`,
|
|
25
|
+
};
|
|
26
|
+
} else {
|
|
27
|
+
lAdditionalAttributes = {
|
|
28
|
+
tailportflags: `tailport="s" headport="s"`,
|
|
29
|
+
headportflags: `tailport="n"`,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return { ...pTransition, ...lAdditionalAttributes };
|
|
34
|
+
};
|
|
37
35
|
}
|
|
38
36
|
function classifyTransition(pTransition) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
const lClasses = ["transition"];
|
|
38
|
+
if (pTransition.type) {
|
|
39
|
+
lClasses.push(pTransition.type);
|
|
40
|
+
}
|
|
41
|
+
if (pTransition.class) {
|
|
42
|
+
lClasses.push(pTransition.class.trim().replace(/[ ]{2,}/g, " "));
|
|
43
|
+
}
|
|
44
|
+
pTransition.class = lClasses.join(" ");
|
|
45
|
+
return pTransition;
|
|
48
46
|
}
|
|
49
47
|
export default { escapeTransitionStrings, addPorts, classifyTransition };
|
package/dist/render/dot/utl.mjs
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
function escapeString(pString) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
return pString
|
|
3
|
+
.replace(/\\/g, "\\\\")
|
|
4
|
+
.replace(/\n\s*/g, "\\l")
|
|
5
|
+
.replace(/"/g, '\\"')
|
|
6
|
+
.concat("\\l");
|
|
7
7
|
}
|
|
8
8
|
function escapeLabelString(pString) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
return pString
|
|
10
|
+
.replace(/\\/g, "\\\\")
|
|
11
|
+
.replace(/\n\s*/g, " \\l")
|
|
12
|
+
.replace(/"/g, '\\"')
|
|
13
|
+
.concat(" \\l");
|
|
14
14
|
}
|
|
15
15
|
function isVertical(pDirection) {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const lDirection = pDirection || "top-down";
|
|
17
|
+
return lDirection === "top-down" || lDirection === "bottom-top";
|
|
18
18
|
}
|
|
19
19
|
function isCompositeSelf(pStateMachineModel, pTransition) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
return (
|
|
21
|
+
pTransition.from === pTransition.to &&
|
|
22
|
+
pStateMachineModel.findStateByName(pTransition.from).statemachine &&
|
|
23
|
+
!(pTransition.type === "internal")
|
|
24
|
+
);
|
|
23
25
|
}
|
|
24
26
|
export default {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
escapeString,
|
|
28
|
+
escapeLabelString,
|
|
29
|
+
isVertical,
|
|
30
|
+
isCompositeSelf,
|
|
29
31
|
};
|
|
@@ -6,20 +6,20 @@ import scjson from "./scjson/index.mjs";
|
|
|
6
6
|
import scxml from "./scxml/index.mjs";
|
|
7
7
|
const smcat = smcatRendererAsImported;
|
|
8
8
|
export default function getRenderFunction(pOutputType) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
const lOutputType2RenderFunctionMap = new Map([
|
|
10
|
+
["smcat", smcat],
|
|
11
|
+
["dot", renderDot],
|
|
12
|
+
["svg", vector],
|
|
13
|
+
["eps", vector],
|
|
14
|
+
["ps", vector],
|
|
15
|
+
["ps2", vector],
|
|
16
|
+
["oldsvg", oldVector],
|
|
17
|
+
["oldps2", oldVector],
|
|
18
|
+
["oldeps", oldVector],
|
|
19
|
+
["pdf", vector],
|
|
20
|
+
["png", vector],
|
|
21
|
+
["scjson", scjson],
|
|
22
|
+
["scxml", scxml],
|
|
23
|
+
]);
|
|
24
|
+
return lOutputType2RenderFunctionMap.get(pOutputType) ?? ((pX) => pX);
|
|
25
25
|
}
|
package/dist/render/index.mjs
CHANGED
|
@@ -5,13 +5,13 @@ import scjson from "./scjson/index.mjs";
|
|
|
5
5
|
import scxml from "./scxml/index.mjs";
|
|
6
6
|
const smcat = smcatRendererAsImported;
|
|
7
7
|
export default function getRenderFunction(pOutputType) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
const lOutputType2RenderFunctionMap = new Map([
|
|
9
|
+
["smcat", smcat],
|
|
10
|
+
["dot", renderDot],
|
|
11
|
+
["svg", svg],
|
|
12
|
+
["oldsvg", svg],
|
|
13
|
+
["scjson", scjson],
|
|
14
|
+
["scxml", scxml],
|
|
15
|
+
]);
|
|
16
|
+
return lOutputType2RenderFunctionMap.get(pOutputType) ?? ((pX) => pX);
|
|
17
17
|
}
|
|
@@ -2,120 +2,137 @@ import StateMachineModel from "../../state-machine-model.mjs";
|
|
|
2
2
|
import makeValidXMLName from "./make-valid-xml-name.mjs";
|
|
3
3
|
import makeValidEventNames from "./make-valid-event-names.mjs";
|
|
4
4
|
const STATE_TYPE2SCXML_STATE_KIND = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
regular: "state",
|
|
6
|
+
initial: "initial",
|
|
7
|
+
final: "final",
|
|
8
|
+
terminate: "final",
|
|
9
|
+
parallel: "parallel",
|
|
10
|
+
history: "history",
|
|
11
|
+
deephistory: "history",
|
|
12
12
|
};
|
|
13
13
|
function stateType2SCXMLStateKind(pStateType) {
|
|
14
|
-
|
|
14
|
+
return STATE_TYPE2SCXML_STATE_KIND[pStateType] || "state";
|
|
15
15
|
}
|
|
16
16
|
function transformTransition(pTransition) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
17
|
+
const lReturnValue = {
|
|
18
|
+
target: makeValidXMLName(pTransition.to),
|
|
19
|
+
};
|
|
20
|
+
if (pTransition.event) {
|
|
21
|
+
lReturnValue.event = makeValidEventNames(pTransition.event);
|
|
22
|
+
}
|
|
23
|
+
if (pTransition.cond) {
|
|
24
|
+
lReturnValue.cond = pTransition.cond;
|
|
25
|
+
}
|
|
26
|
+
if (pTransition.action) {
|
|
27
|
+
lReturnValue.action = pTransition.action;
|
|
28
|
+
}
|
|
29
|
+
if (pTransition.type) {
|
|
30
|
+
lReturnValue.type = pTransition.type;
|
|
31
|
+
}
|
|
32
|
+
return lReturnValue;
|
|
33
33
|
}
|
|
34
34
|
function extractTriggers(pTriggers, pTriggerType) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
return pTriggers
|
|
36
|
+
.filter((pTrigger) => pTrigger.type === pTriggerType)
|
|
37
|
+
.map((pTrigger) => pTrigger.body);
|
|
38
38
|
}
|
|
39
39
|
function pullOutActionType(pReturnValue, pTriggersType, pActions, pActionType) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
const lTriggerArray = extractTriggers(pActions, pActionType);
|
|
41
|
+
if (lTriggerArray.length > 0) {
|
|
42
|
+
pReturnValue[pTriggersType] = (pReturnValue[pTriggersType] || []).concat(
|
|
43
|
+
lTriggerArray,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
44
46
|
}
|
|
45
47
|
function transformTriggers(pReturnValue, pState) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
if (pState.actions) {
|
|
49
|
+
pullOutActionType(pReturnValue, "onentries", pState.actions, "entry");
|
|
50
|
+
pullOutActionType(pReturnValue, "onentries", pState.actions, "activity");
|
|
51
|
+
pullOutActionType(pReturnValue, "onexits", pState.actions, "exit");
|
|
52
|
+
}
|
|
51
53
|
}
|
|
52
54
|
function transformTransitions(pReturnValue, pState, pTransitions) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
const lTransitions = pTransitions
|
|
56
|
+
.filter((pTransition) => pTransition.from === pState.name)
|
|
57
|
+
.map(transformTransition);
|
|
58
|
+
if (lTransitions.length > 0) {
|
|
59
|
+
pReturnValue.transitions = lTransitions;
|
|
60
|
+
}
|
|
59
61
|
}
|
|
60
62
|
function transformCompositeState(pReturnValue, pState, pTransitions) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
if (pState.statemachine) {
|
|
64
|
+
const lRenderedState = render(pState.statemachine, undefined, pTransitions);
|
|
65
|
+
pReturnValue.states = (pReturnValue.states || []).concat(
|
|
66
|
+
lRenderedState.states,
|
|
67
|
+
);
|
|
68
|
+
if (lRenderedState.initial) {
|
|
69
|
+
pReturnValue.initial = lRenderedState.initial;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
68
72
|
}
|
|
69
73
|
function transformState(pTransitions) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
74
|
+
pTransitions = pTransitions || [];
|
|
75
|
+
return (pState) => {
|
|
76
|
+
const lReturnValue = {
|
|
77
|
+
kind: stateType2SCXMLStateKind(pState.type),
|
|
78
|
+
id: makeValidXMLName(pState.name),
|
|
79
|
+
};
|
|
80
|
+
if (pState.type === "deephistory") {
|
|
81
|
+
lReturnValue.type = "deep";
|
|
82
|
+
}
|
|
83
|
+
transformTriggers(lReturnValue, pState);
|
|
84
|
+
transformTransitions(lReturnValue, pState, pTransitions);
|
|
85
|
+
transformCompositeState(lReturnValue, pState, pTransitions);
|
|
86
|
+
return lReturnValue;
|
|
87
|
+
};
|
|
84
88
|
}
|
|
85
89
|
function findInitialPseudoStateName(pStateMachine) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
const lInitial = pStateMachine.states.filter(
|
|
91
|
+
(pState) => pState.type === "initial",
|
|
92
|
+
);
|
|
93
|
+
if (lInitial.length > 0) {
|
|
94
|
+
return lInitial[0].name;
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
91
97
|
}
|
|
92
98
|
function findInitialStateName(pStateMachine, pInitialPseudoStateName) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
let lReturnValue = pInitialPseudoStateName;
|
|
100
|
+
if (pInitialPseudoStateName && pStateMachine.transitions) {
|
|
101
|
+
const lInitialTransitions = pStateMachine.transitions.filter(
|
|
102
|
+
(pTransition) => pTransition.from === pInitialPseudoStateName,
|
|
103
|
+
);
|
|
104
|
+
if (lInitialTransitions.length > 0 && !lInitialTransitions[0].action) {
|
|
105
|
+
lReturnValue = lInitialTransitions[0].to;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return lReturnValue;
|
|
101
109
|
}
|
|
102
110
|
export default function render(pStateMachine, _pOptions, pTransitions) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
111
|
+
const lInitialPseudoStateName = findInitialPseudoStateName(pStateMachine);
|
|
112
|
+
const lInitialStateName = findInitialStateName(
|
|
113
|
+
pStateMachine,
|
|
114
|
+
lInitialPseudoStateName,
|
|
115
|
+
);
|
|
116
|
+
const lReturnValue = {
|
|
117
|
+
states: pStateMachine.states
|
|
118
|
+
.filter((pState) => {
|
|
119
|
+
if (
|
|
120
|
+
lInitialStateName &&
|
|
121
|
+
lInitialStateName !== lInitialPseudoStateName
|
|
122
|
+
) {
|
|
123
|
+
return pState.type !== "initial";
|
|
124
|
+
}
|
|
125
|
+
return true;
|
|
126
|
+
})
|
|
127
|
+
.map(
|
|
128
|
+
transformState(
|
|
129
|
+
pTransitions ||
|
|
130
|
+
new StateMachineModel(pStateMachine).flattenedTransitions,
|
|
131
|
+
),
|
|
132
|
+
),
|
|
133
|
+
};
|
|
134
|
+
if (lInitialStateName) {
|
|
135
|
+
lReturnValue.initial = makeValidXMLName(lInitialStateName);
|
|
136
|
+
}
|
|
137
|
+
return lReturnValue;
|
|
121
138
|
}
|