state-machine-cat 10.1.5 → 10.1.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/bin/smcat.mjs +5 -4
- package/dist/commonjs/bundle.js +67 -67
- package/{src → dist/esm}/cli/actions.mjs +24 -40
- package/dist/esm/cli/attributes-parser.mjs +981 -0
- package/dist/esm/cli/file-name-to-stream.mjs +13 -0
- package/dist/esm/cli/make-description.mjs +21 -0
- package/dist/esm/cli/normalize.mjs +95 -0
- package/dist/esm/cli/validations.mjs +70 -0
- package/dist/esm/index-node.mjs +16 -0
- package/dist/esm/index.mjs +19 -0
- package/dist/esm/options.mjs +61 -0
- package/dist/esm/parse/index.mjs +27 -0
- package/dist/esm/parse/parser-helpers.mjs +175 -0
- package/dist/esm/parse/scxml/index.mjs +136 -0
- package/dist/esm/parse/scxml/normalize-machine.mjs +44 -0
- package/dist/esm/parse/smcat/smcat-parser.mjs +2924 -0
- package/dist/esm/parse/smcat-ast.schema.mjs +170 -0
- package/dist/esm/render/dot/attributebuilder.mjs +51 -0
- package/dist/esm/render/dot/counter.mjs +16 -0
- package/dist/esm/render/dot/dot.states.template.js +26 -0
- package/dist/esm/render/dot/dot.template.js +14 -0
- package/dist/esm/render/dot/index.mjs +106 -0
- package/dist/esm/render/dot/render-dot-from-ast.js +29 -0
- package/dist/esm/render/dot/state-transformers.mjs +113 -0
- package/dist/esm/render/dot/transition-transformers.mjs +49 -0
- package/dist/esm/render/dot/utl.mjs +29 -0
- package/dist/esm/render/index-node.mjs +28 -0
- package/dist/esm/render/index.mjs +20 -0
- package/dist/esm/render/scjson/index.mjs +121 -0
- package/dist/esm/render/scjson/make-valid-event-names.mjs +27 -0
- package/dist/esm/render/scjson/make-valid-xml-name.mjs +19 -0
- package/dist/esm/render/scxml/index.mjs +4 -0
- package/dist/esm/render/scxml/render-from-scjson.js +9 -0
- package/dist/esm/render/scxml/scxml.states.template.js +14 -0
- package/dist/esm/render/scxml/scxml.template.js +6 -0
- package/dist/esm/render/smcat/index.js +63 -0
- package/dist/esm/render/smcat/smcat.template.js +13 -0
- package/dist/esm/render/vector/dot-to-vector-native.mjs +35 -0
- package/dist/esm/render/vector/vector-native-dot-with-fallback.mjs +37 -0
- package/dist/esm/render/vector/vector-with-viz-js.mjs +13 -0
- package/dist/esm/state-machine-model.mjs +58 -0
- package/dist/esm/transform/desugar.mjs +77 -0
- package/dist/esm/transform/utl.mjs +16 -0
- package/dist/esm/version.mjs +1 -0
- package/package.json +36 -45
- package/src/render/dot/dot.states.template.js +1 -1
- package/src/render/dot/index.mjs +14 -14
- package/types/state-machine-cat.d.ts +4 -4
- package/src/cli/file-name-to-stream.mjs +0 -25
- package/src/cli/make-description.mjs +0 -45
- package/src/cli/normalize.mjs +0 -204
- package/src/cli/validations.mjs +0 -140
- package/src/index-node.mjs +0 -55
- package/src/index.mjs +0 -58
- package/src/options.mjs +0 -78
- package/src/parse/index.mjs +0 -47
- package/src/parse/parser-helpers.mjs +0 -297
- package/src/parse/scxml/normalize-machine.mjs +0 -73
- package/src/parse/smcat-ast.schema.mjs +0 -187
- package/src/render/dot/attributebuilder.mjs +0 -68
- package/src/render/dot/counter.mjs +0 -33
- package/src/render/dot/render-dot-from-ast.js +0 -70
- package/src/render/dot/state-transformers.mjs +0 -128
- package/src/render/dot/transition-transformers.mjs +0 -52
- package/src/render/dot/utl.mjs +0 -56
- package/src/render/index-node.mjs +0 -36
- package/src/render/index.mjs +0 -22
- package/src/render/scjson/index.mjs +0 -175
- package/src/render/scjson/make-valid-event-names.mjs +0 -71
- package/src/render/scjson/make-valid-xml-name.mjs +0 -70
- package/src/render/scxml/index.mjs +0 -8
- package/src/render/smcat/index.js +0 -129
- package/src/render/vector/dot-to-vector-native.mjs +0 -60
- package/src/render/vector/vector-native-dot-with-fallback.mjs +0 -55
- package/src/render/vector/vector-with-viz-js.mjs +0 -18
- package/src/state-machine-model.mjs +0 -124
- package/src/transform/desugar.mjs +0 -222
- package/src/transform/utl.mjs +0 -26
- package/src/version.mjs +0 -2
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import utl from "./utl.mjs";
|
|
2
|
+
function escapeTransitionStrings(pTransition) {
|
|
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
|
+
}
|
|
12
|
+
function addPorts(pDirection) {
|
|
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
|
+
}
|
|
22
|
+
else if (pTransition.hasParent) {
|
|
23
|
+
lAdditionalAttributes = {
|
|
24
|
+
tailportflags: `tailport="n" headport="n"`,
|
|
25
|
+
headportflags: `tailport="s"`,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
lAdditionalAttributes = {
|
|
30
|
+
tailportflags: `tailport="s" headport="s"`,
|
|
31
|
+
headportflags: `tailport="n"`,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return { ...pTransition, ...lAdditionalAttributes };
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function classifyTransition(pTransition) {
|
|
39
|
+
const lClasses = ["transition"];
|
|
40
|
+
if (pTransition.type) {
|
|
41
|
+
lClasses.push(pTransition.type);
|
|
42
|
+
}
|
|
43
|
+
if (pTransition.class) {
|
|
44
|
+
lClasses.push(pTransition.class.trim().replace(/[ ]{2,}/g, " "));
|
|
45
|
+
}
|
|
46
|
+
pTransition.class = lClasses.join(" ");
|
|
47
|
+
return pTransition;
|
|
48
|
+
}
|
|
49
|
+
export default { escapeTransitionStrings, addPorts, classifyTransition };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function escapeString(pString) {
|
|
2
|
+
return pString
|
|
3
|
+
.replace(/\\/g, "\\\\")
|
|
4
|
+
.replace(/\n\s*/g, "\\l")
|
|
5
|
+
.replace(/"/g, '\\"')
|
|
6
|
+
.concat("\\l");
|
|
7
|
+
}
|
|
8
|
+
function escapeLabelString(pString) {
|
|
9
|
+
return pString
|
|
10
|
+
.replace(/\\/g, "\\\\")
|
|
11
|
+
.replace(/\n\s*/g, " \\l")
|
|
12
|
+
.replace(/"/g, '\\"')
|
|
13
|
+
.concat(" \\l");
|
|
14
|
+
}
|
|
15
|
+
function isVertical(pDirection) {
|
|
16
|
+
const lDirection = pDirection || "top-down";
|
|
17
|
+
return lDirection === "top-down" || lDirection === "bottom-top";
|
|
18
|
+
}
|
|
19
|
+
function isCompositeSelf(pStateMachineModel, pTransition) {
|
|
20
|
+
return (pTransition.from === pTransition.to &&
|
|
21
|
+
pStateMachineModel.findStateByName(pTransition.from).statemachine &&
|
|
22
|
+
!(pTransition.type === "internal"));
|
|
23
|
+
}
|
|
24
|
+
export default {
|
|
25
|
+
escapeString,
|
|
26
|
+
escapeLabelString,
|
|
27
|
+
isVertical,
|
|
28
|
+
isCompositeSelf,
|
|
29
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import has from "lodash/has.js";
|
|
2
|
+
import smcatRendererAsImported from "./smcat/index.js";
|
|
3
|
+
import renderDot from "./dot/index.mjs";
|
|
4
|
+
import vector from "./vector/vector-native-dot-with-fallback.mjs";
|
|
5
|
+
import oldVector from "./vector/vector-with-viz-js.mjs";
|
|
6
|
+
import scjson from "./scjson/index.mjs";
|
|
7
|
+
import scxml from "./scxml/index.mjs";
|
|
8
|
+
const smcat = smcatRendererAsImported;
|
|
9
|
+
export default function getRenderFunction(pOutputType) {
|
|
10
|
+
const lOutputType2RenderFunction = {
|
|
11
|
+
smcat,
|
|
12
|
+
dot: renderDot,
|
|
13
|
+
svg: vector,
|
|
14
|
+
eps: vector,
|
|
15
|
+
ps: vector,
|
|
16
|
+
ps2: vector,
|
|
17
|
+
oldsvg: oldVector,
|
|
18
|
+
oldps2: oldVector,
|
|
19
|
+
oldeps: oldVector,
|
|
20
|
+
pdf: vector,
|
|
21
|
+
png: vector,
|
|
22
|
+
scjson,
|
|
23
|
+
scxml,
|
|
24
|
+
};
|
|
25
|
+
return has(lOutputType2RenderFunction, pOutputType)
|
|
26
|
+
? lOutputType2RenderFunction[pOutputType]
|
|
27
|
+
: (pX) => pX;
|
|
28
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import has from "lodash/has.js";
|
|
2
|
+
import smcatRendererAsImported from "./smcat/index.js";
|
|
3
|
+
import renderDot from "./dot/index.mjs";
|
|
4
|
+
import svg from "./vector/vector-with-viz-js.mjs";
|
|
5
|
+
import scjson from "./scjson/index.mjs";
|
|
6
|
+
import scxml from "./scxml/index.mjs";
|
|
7
|
+
const smcat = smcatRendererAsImported;
|
|
8
|
+
export default function getRenderFunction(pOutputType) {
|
|
9
|
+
const lOutputType2RenderFunction = {
|
|
10
|
+
smcat,
|
|
11
|
+
dot: renderDot,
|
|
12
|
+
svg,
|
|
13
|
+
oldsvg: svg,
|
|
14
|
+
scjson,
|
|
15
|
+
scxml,
|
|
16
|
+
};
|
|
17
|
+
return has(lOutputType2RenderFunction, pOutputType)
|
|
18
|
+
? lOutputType2RenderFunction[pOutputType]
|
|
19
|
+
: (pX) => pX;
|
|
20
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import StateMachineModel from "../../state-machine-model.mjs";
|
|
2
|
+
import makeValidXMLName from "./make-valid-xml-name.mjs";
|
|
3
|
+
import makeValidEventNames from "./make-valid-event-names.mjs";
|
|
4
|
+
const STATE_TYPE2SCXML_STATE_KIND = {
|
|
5
|
+
regular: "state",
|
|
6
|
+
initial: "initial",
|
|
7
|
+
final: "final",
|
|
8
|
+
terminate: "final",
|
|
9
|
+
parallel: "parallel",
|
|
10
|
+
history: "history",
|
|
11
|
+
deephistory: "history",
|
|
12
|
+
};
|
|
13
|
+
function stateType2SCXMLStateKind(pStateType) {
|
|
14
|
+
return STATE_TYPE2SCXML_STATE_KIND[pStateType] || "state";
|
|
15
|
+
}
|
|
16
|
+
function transformTransition(pTransition) {
|
|
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
|
+
}
|
|
34
|
+
function extractTriggers(pTriggers, pTriggerType) {
|
|
35
|
+
return pTriggers
|
|
36
|
+
.filter((pTrigger) => pTrigger.type === pTriggerType)
|
|
37
|
+
.map((pTrigger) => pTrigger.body);
|
|
38
|
+
}
|
|
39
|
+
function pullOutActionType(pReturnValue, pTriggersType, pActions, pActionType) {
|
|
40
|
+
const lTriggerArray = extractTriggers(pActions, pActionType);
|
|
41
|
+
if (lTriggerArray.length > 0) {
|
|
42
|
+
pReturnValue[pTriggersType] = (pReturnValue[pTriggersType] || []).concat(lTriggerArray);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function transformTriggers(pReturnValue, pState) {
|
|
46
|
+
if (pState.actions) {
|
|
47
|
+
pullOutActionType(pReturnValue, "onentries", pState.actions, "entry");
|
|
48
|
+
pullOutActionType(pReturnValue, "onentries", pState.actions, "activity");
|
|
49
|
+
pullOutActionType(pReturnValue, "onexits", pState.actions, "exit");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function transformTransitions(pReturnValue, pState, pTransitions) {
|
|
53
|
+
const lTransitions = pTransitions
|
|
54
|
+
.filter((pTransition) => pTransition.from === pState.name)
|
|
55
|
+
.map(transformTransition);
|
|
56
|
+
if (lTransitions.length > 0) {
|
|
57
|
+
pReturnValue.transitions = lTransitions;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function transformCompositeState(pReturnValue, pState, pTransitions) {
|
|
61
|
+
if (pState.statemachine) {
|
|
62
|
+
const lRenderedState = render(pState.statemachine, undefined, pTransitions);
|
|
63
|
+
pReturnValue.states = (pReturnValue.states || []).concat(lRenderedState.states);
|
|
64
|
+
if (lRenderedState.initial) {
|
|
65
|
+
pReturnValue.initial = lRenderedState.initial;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function transformState(pTransitions) {
|
|
70
|
+
pTransitions = pTransitions || [];
|
|
71
|
+
return (pState) => {
|
|
72
|
+
const lReturnValue = {
|
|
73
|
+
kind: stateType2SCXMLStateKind(pState.type),
|
|
74
|
+
id: makeValidXMLName(pState.name),
|
|
75
|
+
};
|
|
76
|
+
if (pState.type === "deephistory") {
|
|
77
|
+
lReturnValue.type = "deep";
|
|
78
|
+
}
|
|
79
|
+
transformTriggers(lReturnValue, pState);
|
|
80
|
+
transformTransitions(lReturnValue, pState, pTransitions);
|
|
81
|
+
transformCompositeState(lReturnValue, pState, pTransitions);
|
|
82
|
+
return lReturnValue;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function findInitialPseudoStateName(pStateMachine) {
|
|
86
|
+
const lInitial = pStateMachine.states.filter((pState) => pState.type === "initial");
|
|
87
|
+
if (lInitial.length > 0) {
|
|
88
|
+
return lInitial[0].name;
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
function findInitialStateName(pStateMachine, pInitialPseudoStateName) {
|
|
93
|
+
let lReturnValue = pInitialPseudoStateName;
|
|
94
|
+
if (pInitialPseudoStateName && pStateMachine.transitions) {
|
|
95
|
+
const lInitialTransitions = pStateMachine.transitions.filter((pTransition) => pTransition.from === pInitialPseudoStateName);
|
|
96
|
+
if (lInitialTransitions.length > 0 && !lInitialTransitions[0].action) {
|
|
97
|
+
lReturnValue = lInitialTransitions[0].to;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return lReturnValue;
|
|
101
|
+
}
|
|
102
|
+
export default function render(pStateMachine, _pOptions, pTransitions) {
|
|
103
|
+
const lInitialPseudoStateName = findInitialPseudoStateName(pStateMachine);
|
|
104
|
+
const lInitialStateName = findInitialStateName(pStateMachine, lInitialPseudoStateName);
|
|
105
|
+
const lReturnValue = {
|
|
106
|
+
states: pStateMachine.states
|
|
107
|
+
.filter((pState) => {
|
|
108
|
+
if (lInitialStateName &&
|
|
109
|
+
lInitialStateName !== lInitialPseudoStateName) {
|
|
110
|
+
return pState.type !== "initial";
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
})
|
|
114
|
+
.map(transformState(pTransitions ||
|
|
115
|
+
new StateMachineModel(pStateMachine).flattenedTransitions)),
|
|
116
|
+
};
|
|
117
|
+
if (lInitialStateName) {
|
|
118
|
+
lReturnValue.initial = makeValidXMLName(lInitialStateName);
|
|
119
|
+
}
|
|
120
|
+
return lReturnValue;
|
|
121
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const EVENT_CHAR_FORBIDDEN_RE = /[\u00B7|\u0300-\u036F|\u203F-\u2040|\u0000-\u0029|\u002B-\u002C|\u002F|\u003B-\u0040|\u005B-\u0060|\u007B-\u00BF|\u00D7|\u00F7|\u0300-\u036F|\u037E|\u2000-\u200B|\u200E-\u206F|\u2190-\u2BFF|\u2FF0-\u3000|\uD800-\uF8FF|\uFDD0-\uFDEF|\uFFFE-\uFFFF]/g;
|
|
2
|
+
const START_EVENT_CHAR_FORBIDDEN_EXTRA_RE = /[.]/g;
|
|
3
|
+
function makeValidEventChar(pCandidateEventStringTail) {
|
|
4
|
+
return pCandidateEventStringTail.replace(EVENT_CHAR_FORBIDDEN_RE, "_");
|
|
5
|
+
}
|
|
6
|
+
function makeValidEventStartChar(pCandidateEventStringStart) {
|
|
7
|
+
let lReturnValue = makeValidEventChar(pCandidateEventStringStart);
|
|
8
|
+
if (lReturnValue.match(START_EVENT_CHAR_FORBIDDEN_EXTRA_RE)) {
|
|
9
|
+
lReturnValue = `_${pCandidateEventStringStart}`;
|
|
10
|
+
}
|
|
11
|
+
return lReturnValue;
|
|
12
|
+
}
|
|
13
|
+
function makeValidEventName(pCandidateEventName) {
|
|
14
|
+
pCandidateEventName = pCandidateEventName.replace(/\s+/g, " ").trim();
|
|
15
|
+
return makeValidEventStartChar(pCandidateEventName[0]).concat(makeValidEventChar(pCandidateEventName.slice(1)));
|
|
16
|
+
}
|
|
17
|
+
export default (pCandidateEventNames) => {
|
|
18
|
+
const lCandidateEventNames = pCandidateEventNames || "";
|
|
19
|
+
if (lCandidateEventNames.length === 0) {
|
|
20
|
+
return "empty";
|
|
21
|
+
}
|
|
22
|
+
return lCandidateEventNames
|
|
23
|
+
.split(/[\n\r]+/)
|
|
24
|
+
.filter((pCandidateEventName) => pCandidateEventName.length > 0)
|
|
25
|
+
.map(makeValidEventName)
|
|
26
|
+
.join(" ");
|
|
27
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const NAME_CHAR_FORBIDDEN_RE = /[\u0000-\u002C|\u002F|\u003B-\u0040|\u005B-\u0060|\u007B-\u00BF|\u00D7|\u00F7|\u0300-\u036F|\u037E|\u2000-\u200B|\u200E-\u206F|\u2190-\u2BFF|\u2FF0-\u3000|\uD800-\uF8FF|\uFDD0-\uFDEF|\uFFFE-\uFFFF]/g;
|
|
2
|
+
const START_NAME_CHAR_FORBIDDEN_EXTRA_RE = /[-|.|0-9|\u00B7|\u0300-\u036F|\u203F-\u2040]/g;
|
|
3
|
+
function makeValidNameChars(pCandidateNameTail) {
|
|
4
|
+
return pCandidateNameTail.replace(NAME_CHAR_FORBIDDEN_RE, "_");
|
|
5
|
+
}
|
|
6
|
+
function makeValidNameStartChar(pCandidateChar) {
|
|
7
|
+
let lReturnValue = makeValidNameChars(pCandidateChar);
|
|
8
|
+
if (lReturnValue.match(START_NAME_CHAR_FORBIDDEN_EXTRA_RE)) {
|
|
9
|
+
lReturnValue = `_${pCandidateChar}`;
|
|
10
|
+
}
|
|
11
|
+
return lReturnValue;
|
|
12
|
+
}
|
|
13
|
+
export default (pCandidateName) => {
|
|
14
|
+
pCandidateName = pCandidateName || "";
|
|
15
|
+
if (pCandidateName.length === 0) {
|
|
16
|
+
return `__empty`;
|
|
17
|
+
}
|
|
18
|
+
return makeValidNameStartChar(pCandidateName[0]).concat(makeValidNameChars(pCandidateName.slice(1)));
|
|
19
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Handlebars = require("handlebars/dist/handlebars.runtime.js");
|
|
4
|
+
require("./scxml.template.js");
|
|
5
|
+
require("./scxml.states.template.js");
|
|
6
|
+
Handlebars.registerPartial("scxml.states.template.hbs", Handlebars.templates["scxml.states.template.hbs"]);
|
|
7
|
+
module.exports = function renderSCXML(pSCJSON) {
|
|
8
|
+
return Handlebars.templates["scxml.template.hbs"](pSCJSON);
|
|
9
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var Handlebars = require("handlebars/dist/handlebars.runtime"), template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
|
|
4
|
+
templates["scxml.states.template.hbs"] = template({ 1: function (n, l, e, t, o) { var a, r, i = null != l ? l : n.nullContext || {}, u = n.hooks.helperMissing, c = "function", s = n.escapeExpression, p = n.lookupProperty || function (n, l) { if (Object.prototype.hasOwnProperty.call(n, l))
|
|
5
|
+
return n[l]; }; return " <" + s(typeof (r = null != (r = p(e, "kind") || (null != l ? p(l, "kind") : l)) ? r : u) == c ? r.call(i, { name: "kind", hash: {}, data: o, loc: { start: { line: 2, column: 5 }, end: { line: 2, column: 13 } } }) : r) + ' id="' + s(typeof (r = null != (r = p(e, "id") || (null != l ? p(l, "id") : l)) ? r : u) == c ? r.call(i, { name: "id", hash: {}, data: o, loc: { start: { line: 2, column: 18 }, end: { line: 2, column: 24 } } }) : r) + '"' + (null != (a = p(e, "if").call(i, null != l ? p(l, "initial") : l, { name: "if", hash: {}, fn: n.program(2, o, 0), inverse: n.noop, data: o, loc: { start: { line: 2, column: 25 }, end: { line: 2, column: 69 } } })) ? a : "") + (null != (a = p(e, "if").call(i, null != l ? p(l, "type") : l, { name: "if", hash: {}, fn: n.program(4, o, 0), inverse: n.noop, data: o, loc: { start: { line: 2, column: 69 }, end: { line: 2, column: 104 } } })) ? a : "") + ">\n" + (null != (a = n.invokePartial(p(t, "scxml.states.template.hbs"), l, { name: "scxml.states.template.hbs", data: o, indent: " ", helpers: e, partials: t, decorators: n.decorators })) ? a : "") + (null != (a = p(e, "each").call(i, null != l ? p(l, "onentries") : l, { name: "each", hash: {}, fn: n.program(6, o, 0), inverse: n.noop, data: o, loc: { start: { line: 4, column: 4 }, end: { line: 6, column: 13 } } })) ? a : "") + (null != (a = p(e, "each").call(i, null != l ? p(l, "onexits") : l, { name: "each", hash: {}, fn: n.program(8, o, 0), inverse: n.noop, data: o, loc: { start: { line: 7, column: 4 }, end: { line: 9, column: 13 } } })) ? a : "") + (null != (a = p(e, "each").call(i, null != l ? p(l, "transitions") : l, { name: "each", hash: {}, fn: n.program(10, o, 0), inverse: n.noop, data: o, loc: { start: { line: 10, column: 4 }, end: { line: 18, column: 13 } } })) ? a : "") + " </" + s(typeof (r = null != (r = p(e, "kind") || (null != l ? p(l, "kind") : l)) ? r : u) == c ? r.call(i, { name: "kind", hash: {}, data: o, loc: { start: { line: 19, column: 6 }, end: { line: 19, column: 14 } } }) : r) + ">\n"; }, 2: function (n, l, e, t, o) { var a = n.lookupProperty || function (n, l) { if (Object.prototype.hasOwnProperty.call(n, l))
|
|
6
|
+
return n[l]; }; return ' initial="' + n.escapeExpression("function" == typeof (e = null != (e = a(e, "initial") || (null != l ? a(l, "initial") : l)) ? e : n.hooks.helperMissing) ? e.call(null != l ? l : n.nullContext || {}, { name: "initial", hash: {}, data: o, loc: { start: { line: 2, column: 50 }, end: { line: 2, column: 61 } } }) : e) + '"'; }, 4: function (n, l, e, t, o) { var a = n.lookupProperty || function (n, l) { if (Object.prototype.hasOwnProperty.call(n, l))
|
|
7
|
+
return n[l]; }; return ' type="' + n.escapeExpression("function" == typeof (e = null != (e = a(e, "type") || (null != l ? a(l, "type") : l)) ? e : n.hooks.helperMissing) ? e.call(null != l ? l : n.nullContext || {}, { name: "type", hash: {}, data: o, loc: { start: { line: 2, column: 88 }, end: { line: 2, column: 96 } } }) : e) + '"'; }, 6: function (n, l, e, t, o) { return " <onentry>" + n.escapeExpression(n.lambda(l, l)) + "</onentry>\n"; }, 8: function (n, l, e, t, o) { return " <onexit>" + n.escapeExpression(n.lambda(l, l)) + "</onexit>\n"; }, 10: function (n, l, e, t, o) { var a = n.lookupProperty || function (n, l) { if (Object.prototype.hasOwnProperty.call(n, l))
|
|
8
|
+
return n[l]; }; return null != (e = a(e, "if").call(null != l ? l : n.nullContext || {}, null != l ? a(l, "action") : l, { name: "if", hash: {}, fn: n.program(11, o, 0), inverse: n.program(18, o, 0), data: o, loc: { start: { line: 11, column: 8 }, end: { line: 17, column: 15 } } })) ? e : ""; }, 11: function (n, l, e, t, o) { var a, r = null != l ? l : n.nullContext || {}, i = n.hooks.helperMissing, u = "function", c = n.escapeExpression, s = n.lookupProperty || function (n, l) { if (Object.prototype.hasOwnProperty.call(n, l))
|
|
9
|
+
return n[l]; }; return " <transition " + (null != (a = s(e, "if").call(r, null != l ? s(l, "event") : l, { name: "if", hash: {}, fn: n.program(12, o, 0), inverse: n.noop, data: o, loc: { start: { line: 12, column: 20 }, end: { line: 12, column: 58 } } })) ? a : "") + (null != (a = s(e, "if").call(r, null != l ? s(l, "cond") : l, { name: "if", hash: {}, fn: n.program(14, o, 0), inverse: n.noop, data: o, loc: { start: { line: 12, column: 58 }, end: { line: 12, column: 93 } } })) ? a : "") + (null != (a = s(e, "if").call(r, null != l ? s(l, "type") : l, { name: "if", hash: {}, fn: n.program(16, o, 0), inverse: n.noop, data: o, loc: { start: { line: 12, column: 93 }, end: { line: 12, column: 128 } } })) ? a : "") + 'target="' + c(typeof (n = null != (n = s(e, "target") || (null != l ? s(l, "target") : l)) ? n : i) == u ? n.call(r, { name: "target", hash: {}, data: o, loc: { start: { line: 12, column: 136 }, end: { line: 12, column: 146 } } }) : n) + '">\n ' + c(typeof (n = null != (n = s(e, "action") || (null != l ? s(l, "action") : l)) ? n : i) == u ? n.call(r, { name: "action", hash: {}, data: o, loc: { start: { line: 13, column: 12 }, end: { line: 13, column: 22 } } }) : n) + "\n </transition>\n"; }, 12: function (n, l, e, t, o) { var a = n.lookupProperty || function (n, l) { if (Object.prototype.hasOwnProperty.call(n, l))
|
|
10
|
+
return n[l]; }; return 'event="' + n.escapeExpression("function" == typeof (e = null != (e = a(e, "event") || (null != l ? a(l, "event") : l)) ? e : n.hooks.helperMissing) ? e.call(null != l ? l : n.nullContext || {}, { name: "event", hash: {}, data: o, loc: { start: { line: 12, column: 40 }, end: { line: 12, column: 49 } } }) : e) + '" '; }, 14: function (n, l, e, t, o) { var a = n.lookupProperty || function (n, l) { if (Object.prototype.hasOwnProperty.call(n, l))
|
|
11
|
+
return n[l]; }; return 'cond="' + n.escapeExpression("function" == typeof (e = null != (e = a(e, "cond") || (null != l ? a(l, "cond") : l)) ? e : n.hooks.helperMissing) ? e.call(null != l ? l : n.nullContext || {}, { name: "cond", hash: {}, data: o, loc: { start: { line: 12, column: 76 }, end: { line: 12, column: 84 } } }) : e) + '" '; }, 16: function (n, l, e, t, o) { var a = n.lookupProperty || function (n, l) { if (Object.prototype.hasOwnProperty.call(n, l))
|
|
12
|
+
return n[l]; }; return 'type="' + n.escapeExpression("function" == typeof (e = null != (e = a(e, "type") || (null != l ? a(l, "type") : l)) ? e : n.hooks.helperMissing) ? e.call(null != l ? l : n.nullContext || {}, { name: "type", hash: {}, data: o, loc: { start: { line: 12, column: 111 }, end: { line: 12, column: 119 } } }) : e) + '" '; }, 18: function (n, l, e, t, o) { var a, r = null != l ? l : n.nullContext || {}, i = n.lookupProperty || function (n, l) { if (Object.prototype.hasOwnProperty.call(n, l))
|
|
13
|
+
return n[l]; }; return " <transition " + (null != (a = i(e, "if").call(r, null != l ? i(l, "event") : l, { name: "if", hash: {}, fn: n.program(12, o, 0), inverse: n.noop, data: o, loc: { start: { line: 16, column: 20 }, end: { line: 16, column: 58 } } })) ? a : "") + (null != (a = i(e, "if").call(r, null != l ? i(l, "cond") : l, { name: "if", hash: {}, fn: n.program(14, o, 0), inverse: n.noop, data: o, loc: { start: { line: 16, column: 58 }, end: { line: 16, column: 93 } } })) ? a : "") + (null != (a = i(e, "if").call(r, null != l ? i(l, "type") : l, { name: "if", hash: {}, fn: n.program(16, o, 0), inverse: n.noop, data: o, loc: { start: { line: 16, column: 93 }, end: { line: 16, column: 128 } } })) ? a : "") + 'target="' + n.escapeExpression("function" == typeof (a = null != (a = i(e, "target") || (null != l ? i(l, "target") : l)) ? a : n.hooks.helperMissing) ? a.call(r, { name: "target", hash: {}, data: o, loc: { start: { line: 16, column: 136 }, end: { line: 16, column: 146 } } }) : a) + '"/>\n'; }, compiler: [8, ">= 4.3.0"], main: function (n, l, e, t, o) { var a = n.lookupProperty || function (n, l) { if (Object.prototype.hasOwnProperty.call(n, l))
|
|
14
|
+
return n[l]; }; return null != (e = a(e, "each").call(null != l ? l : n.nullContext || {}, null != l ? a(l, "states") : l, { name: "each", hash: {}, fn: n.program(1, o, 0), inverse: n.noop, data: o, loc: { start: { line: 1, column: 0 }, end: { line: 20, column: 9 } } })) ? e : ""; }, usePartial: !0, useData: !0 });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var Handlebars = require("handlebars/dist/handlebars.runtime"), template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
|
|
4
|
+
templates["scxml.template.hbs"] = template({ 1: function (e, l, t, n, a) { var r = e.lookupProperty || function (e, l) { if (Object.prototype.hasOwnProperty.call(e, l))
|
|
5
|
+
return e[l]; }; return 'initial="' + e.escapeExpression("function" == typeof (t = null != (t = r(t, "initial") || (null != l ? r(l, "initial") : l)) ? t : e.hooks.helperMissing) ? t.call(null != l ? l : e.nullContext || {}, { name: "initial", hash: {}, data: a, loc: { start: { line: 2, column: 71 }, end: { line: 2, column: 82 } } }) : t) + '" '; }, compiler: [8, ">= 4.3.0"], main: function (e, l, t, n, a) { var r, s = e.lookupProperty || function (e, l) { if (Object.prototype.hasOwnProperty.call(e, l))
|
|
6
|
+
return e[l]; }; return '<?xml version="1.0" encoding="UTF-8"?>\n<scxml xmlns="http://www.w3.org/2005/07/scxml" ' + (null != (r = s(t, "if").call(null != l ? l : e.nullContext || {}, null != l ? s(l, "initial") : l, { name: "if", hash: {}, fn: e.program(1, a, 0), inverse: e.noop, data: a, loc: { start: { line: 2, column: 47 }, end: { line: 2, column: 91 } } })) ? r : "") + 'version="1.0">\n' + (null != (r = e.invokePartial(s(n, "scxml.states.template.hbs"), l, { name: "scxml.states.template.hbs", data: a, helpers: t, partials: n, decorators: e.decorators })) ? r : "") + "</scxml>\n"; }, usePartial: !0, useData: !0 });
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Handlebars = require("handlebars/dist/handlebars.runtime.js");
|
|
4
|
+
const cloneDeep = require("lodash/cloneDeep.js");
|
|
5
|
+
require("./smcat.template.js");
|
|
6
|
+
const NAME_QUOTABLE = /;|,|{| |\[/;
|
|
7
|
+
const ACTIONS_QUOTABLE = /;|,|{/;
|
|
8
|
+
const LABEL_QUOTABLE = /;|{/;
|
|
9
|
+
function quoteIfNecessary(pRegExp, pString) {
|
|
10
|
+
return pRegExp.test(pString) ? `"${pString}"` : pString;
|
|
11
|
+
}
|
|
12
|
+
Handlebars.registerPartial("smcat.template.hbs", Handlebars.templates["smcat.template.hbs"]);
|
|
13
|
+
function formatActionType(pString) {
|
|
14
|
+
return pString === "activity" ? "" : `${pString}/ `;
|
|
15
|
+
}
|
|
16
|
+
function flattenActions(pState) {
|
|
17
|
+
return {
|
|
18
|
+
...pState,
|
|
19
|
+
actions: (pState.actions || [])
|
|
20
|
+
.map((pAction) => `${formatActionType(pAction.type)}${pAction.body}`)
|
|
21
|
+
.join("\n "),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function flagExtendedStateAttributes(pState) {
|
|
25
|
+
if (Object.prototype.hasOwnProperty.call(pState, "label") ||
|
|
26
|
+
Object.prototype.hasOwnProperty.call(pState, "typeExplicitlySet") ||
|
|
27
|
+
Object.prototype.hasOwnProperty.call(pState, "color") ||
|
|
28
|
+
Object.prototype.hasOwnProperty.call(pState, "active") ||
|
|
29
|
+
Object.prototype.hasOwnProperty.call(pState, "class")) {
|
|
30
|
+
pState.hasExtendedAttributes = true;
|
|
31
|
+
}
|
|
32
|
+
return pState;
|
|
33
|
+
}
|
|
34
|
+
function transformStates(pStates) {
|
|
35
|
+
pStates
|
|
36
|
+
.map(flagExtendedStateAttributes)
|
|
37
|
+
.filter((pState) => pState.statemachine)
|
|
38
|
+
.forEach((pState) => {
|
|
39
|
+
pState.statemachine.states = transformStates(pState.statemachine.states);
|
|
40
|
+
});
|
|
41
|
+
return pStates.map(flattenActions);
|
|
42
|
+
}
|
|
43
|
+
function flagExtendedTransitionAttributes(pTransition) {
|
|
44
|
+
if (Object.prototype.hasOwnProperty.call(pTransition, "type") ||
|
|
45
|
+
Object.prototype.hasOwnProperty.call(pTransition, "color") ||
|
|
46
|
+
Object.prototype.hasOwnProperty.call(pTransition, "class")) {
|
|
47
|
+
pTransition.hasExtendedAttributes = true;
|
|
48
|
+
}
|
|
49
|
+
return pTransition;
|
|
50
|
+
}
|
|
51
|
+
function transformTransitions(pTransitions) {
|
|
52
|
+
return pTransitions.map(flagExtendedTransitionAttributes);
|
|
53
|
+
}
|
|
54
|
+
Handlebars.registerHelper("quotifyState", (pItem) => quoteIfNecessary(NAME_QUOTABLE, pItem));
|
|
55
|
+
Handlebars.registerHelper("quotifyLabel", (pItem) => quoteIfNecessary(LABEL_QUOTABLE, pItem));
|
|
56
|
+
Handlebars.registerHelper("quotifyActions", (pItem) => quoteIfNecessary(ACTIONS_QUOTABLE, pItem));
|
|
57
|
+
module.exports = function renderSmcat(pStateMachine) {
|
|
58
|
+
return Handlebars.templates["smcat.template.hbs"]({
|
|
59
|
+
...pStateMachine,
|
|
60
|
+
states: transformStates(cloneDeep(pStateMachine.states)),
|
|
61
|
+
transitions: transformTransitions(cloneDeep(pStateMachine.transitions || [])),
|
|
62
|
+
});
|
|
63
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var Handlebars = require("handlebars/dist/handlebars.runtime"), template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
|
|
4
|
+
templates["smcat.template.hbs"] = template({ 1: function (l, n, e, t, o) { var a = null != n ? n : l.nullContext || {}, r = l.hooks.helperMissing, u = "function", i = l.hooks.blockHelperMissing, c = l.lookupProperty || function (l, n) { if (Object.prototype.hasOwnProperty.call(l, n))
|
|
5
|
+
return l[n]; }, s = "", p = null != (p = c(e, "note") || (null != n ? c(n, "note") : n)) ? p : r, m = { name: "note", hash: {}, fn: l.program(2, o, 0), inverse: l.noop, data: o, loc: { start: { line: 2, column: 0 }, end: { line: 4, column: 9 } } }, f = typeof p == u ? p.call(a, m) : p; return null != (f = c(e, "note") ? f : i.call(n, f, m)) && (s += f), s += null != (f = (c(e, "quotifyState") || n && c(n, "quotifyState") || r).call(a, null != n ? c(n, "name") : n, { name: "quotifyState", hash: {}, fn: l.program(4, o, 0), inverse: l.noop, data: o, loc: { start: { line: 5, column: 0 }, end: { line: 5, column: 40 } } })) ? f : "", p = null != (p = c(e, "hasExtendedAttributes") || (null != n ? c(n, "hasExtendedAttributes") : n)) ? p : r, m = { name: "hasExtendedAttributes", hash: {}, fn: l.program(6, o, 0), inverse: l.noop, data: o, loc: { start: { line: 6, column: 4 }, end: { line: 6, column: 270 } } }, f = typeof p == u ? p.call(a, m) : p, null != (f = c(e, "hasExtendedAttributes") ? f : i.call(n, f, m)) && (s += f), s += null != (f = c(e, "if").call(a, null != n ? c(n, "actions") : n, { name: "if", hash: {}, fn: l.program(18, o, 0), inverse: l.noop, data: o, loc: { start: { line: 7, column: 4 }, end: { line: 7, column: 28 } } })) ? f : "", p = null != (p = c(e, "actions") || (null != n ? c(n, "actions") : n)) ? p : r, m = { name: "actions", hash: {}, fn: l.program(20, o, 0), inverse: l.noop, data: o, loc: { start: { line: 7, column: 28 }, end: { line: 7, column: 93 } } }, f = typeof p == u ? p.call(a, m) : p, null != (f = c(e, "actions") ? f : i.call(n, f, m)) && (s += f), p = null != (p = c(e, "statemachine") || (null != n ? c(n, "statemachine") : n)) ? p : r, m = { name: "statemachine", hash: {}, fn: l.program(22, o, 0), inverse: l.noop, data: o, loc: { start: { line: 8, column: 4 }, end: { line: 10, column: 19 } } }, f = typeof p == u ? p.call(a, m) : p, null != (f = c(e, "statemachine") ? f : i.call(n, f, m)) && (s += f), s + (null != (f = c(e, "if").call(a, o && c(o, "last"), { name: "if", hash: {}, fn: l.program(24, o, 0), inverse: l.program(26, o, 0), data: o, loc: { start: { line: 11, column: 0 }, end: { line: 11, column: 30 } } })) ? f : "") + "\n"; }, 2: function (l, n, e, t, o) { return "# " + (null != (l = l.lambda(n, n)) ? l : "") + "\n"; }, 4: function (l, n, e, t, o) { return ""; }, 6: function (l, n, e, t, o) { var a = null != n ? n : l.nullContext || {}, r = l.hooks.helperMissing, u = "function", i = l.hooks.blockHelperMissing, c = l.lookupProperty || function (l, n) { if (Object.prototype.hasOwnProperty.call(l, n))
|
|
6
|
+
return l[n]; }, s = " [", p = null != (p = c(e, "typeExplicitlySet") || (null != n ? c(n, "typeExplicitlySet") : n)) ? p : r, m = { name: "typeExplicitlySet", hash: {}, fn: l.program(7, o, 0), inverse: l.noop, data: o, loc: { start: { line: 6, column: 32 }, end: { line: 6, column: 107 } } }, f = typeof p == u ? p.call(a, m) : p; return null != (f = c(e, "typeExplicitlySet") ? f : i.call(n, f, m)) && (s += f), p = null != (p = c(e, "label") || (null != n ? c(n, "label") : n)) ? p : r, m = { name: "label", hash: {}, fn: l.program(10, o, 0), inverse: l.noop, data: o, loc: { start: { line: 6, column: 107 }, end: { line: 6, column: 142 } } }, f = typeof p == u ? p.call(a, m) : p, null != (f = c(e, "label") ? f : i.call(n, f, m)) && (s += f), p = null != (p = c(e, "color") || (null != n ? c(n, "color") : n)) ? p : r, m = { name: "color", hash: {}, fn: l.program(12, o, 0), inverse: l.noop, data: o, loc: { start: { line: 6, column: 142 }, end: { line: 6, column: 178 } } }, f = typeof p == u ? p.call(a, m) : p, null != (f = c(e, "color") ? f : i.call(n, f, m)) && (s += f), p = null != (p = c(e, "class") || (null != n ? c(n, "class") : n)) ? p : r, m = { name: "class", hash: {}, fn: l.program(14, o, 0), inverse: l.noop, data: o, loc: { start: { line: 6, column: 178 }, end: { line: 6, column: 214 } } }, f = typeof p == u ? p.call(a, m) : p, null != (f = c(e, "class") ? f : i.call(n, f, m)) && (s += f), s + (null != (f = c(e, "if").call(a, null != n ? c(n, "active") : n, { name: "if", hash: {}, fn: l.program(16, o, 0), inverse: l.noop, data: o, loc: { start: { line: 6, column: 214 }, end: { line: 6, column: 242 } } })) ? f : "") + "]"; }, 7: function (l, n, e, t, o) { var a = l.lookupProperty || function (l, n) { if (Object.prototype.hasOwnProperty.call(l, n))
|
|
7
|
+
return l[n]; }, r = null != (r = a(e, "type") || (null != n ? a(n, "type") : n)) ? r : l.hooks.helperMissing, o = { name: "type", hash: {}, fn: l.program(8, o, 0), inverse: l.noop, data: o, loc: { start: { line: 6, column: 54 }, end: { line: 6, column: 85 } } }, r = "function" == typeof r ? r.call(null != n ? n : l.nullContext || {}, o) : r; return null != (r = a(e, "type") ? r : l.hooks.blockHelperMissing.call(n, r, o)) ? r : ""; }, 8: function (l, n, e, t, o) { return "type=" + (null != (l = l.lambda(n, n)) ? l : "") + " "; }, 10: function (l, n, e, t, o) { return 'label="' + (null != (l = l.lambda(n, n)) ? l : "") + '"'; }, 12: function (l, n, e, t, o) { return ' color="' + (null != (l = l.lambda(n, n)) ? l : "") + '"'; }, 14: function (l, n, e, t, o) { return ' class="' + (null != (l = l.lambda(n, n)) ? l : "") + '"'; }, 16: function (l, n, e, t, o) { return " active"; }, 18: function (l, n, e, t, o) { return ": "; }, 20: function (l, n, e, t, o) { var a = l.lookupProperty || function (l, n) { if (Object.prototype.hasOwnProperty.call(l, n))
|
|
8
|
+
return l[n]; }; return null != (e = (a(e, "quotifyActions") || n && a(n, "quotifyActions") || l.hooks.helperMissing).call(null != n ? n : l.nullContext || {}, n, { name: "quotifyActions", hash: {}, fn: l.program(4, o, 0), inverse: l.noop, data: o, loc: { start: { line: 7, column: 40 }, end: { line: 7, column: 80 } } })) ? e : ""; }, 22: function (l, n, e, t, o) { var a = l.lookupProperty || function (l, n) { if (Object.prototype.hasOwnProperty.call(l, n))
|
|
9
|
+
return l[n]; }; return " {\n" + (null != (a = l.invokePartial(a(t, "smcat.template.hbs"), n, { name: "smcat.template.hbs", data: o, indent: " ", helpers: e, partials: t, decorators: l.decorators })) ? a : "") + "}"; }, 24: function (l, n, e, t, o) { return ";"; }, 26: function (l, n, e, t, o) { return ","; }, 28: function (l, n, e, t, o) { var a = null != n ? n : l.nullContext || {}, r = l.hooks.helperMissing, u = "function", i = l.hooks.blockHelperMissing, c = l.lookupProperty || function (l, n) { if (Object.prototype.hasOwnProperty.call(l, n))
|
|
10
|
+
return l[n]; }, s = "", p = null != (p = c(e, "note") || (null != n ? c(n, "note") : n)) ? p : r, m = { name: "note", hash: {}, fn: l.program(2, o, 0), inverse: l.noop, data: o, loc: { start: { line: 15, column: 0 }, end: { line: 17, column: 9 } } }, f = typeof p == u ? p.call(a, m) : p; return null != (f = c(e, "note") ? f : i.call(n, f, m)) && (s += f), s += (null != (f = (c(e, "quotifyState") || n && c(n, "quotifyState") || r).call(a, null != n ? c(n, "from") : n, { name: "quotifyState", hash: {}, fn: l.program(4, o, 0), inverse: l.noop, data: o, loc: { start: { line: 18, column: 0 }, end: { line: 18, column: 39 } } })) ? f : "") + " => " + (null != (f = (c(e, "quotifyState") || n && c(n, "quotifyState") || r).call(a, null != n ? c(n, "to") : n, { name: "quotifyState", hash: {}, fn: l.program(4, o, 0), inverse: l.noop, data: o, loc: { start: { line: 18, column: 43 }, end: { line: 18, column: 81 } } })) ? f : ""), p = null != (p = c(e, "hasExtendedAttributes") || (null != n ? c(n, "hasExtendedAttributes") : n)) ? p : r, m = { name: "hasExtendedAttributes", hash: {}, fn: l.program(29, o, 0), inverse: l.noop, data: o, loc: { start: { line: 19, column: 4 }, end: { line: 19, column: 130 } } }, f = typeof p == u ? p.call(a, m) : p, null != (f = c(e, "hasExtendedAttributes") ? f : i.call(n, f, m)) && (s += f), p = null != (p = c(e, "label") || (null != n ? c(n, "label") : n)) ? p : r, m = { name: "label", hash: {}, fn: l.program(34, o, 0), inverse: l.noop, data: o, loc: { start: { line: 20, column: 4 }, end: { line: 20, column: 62 } } }, f = typeof p == u ? p.call(a, m) : p, null != (f = c(e, "label") ? f : i.call(n, f, m)) && (s += f), s + ";\n"; }, 29: function (l, n, e, t, o) { var a = null != n ? n : l.nullContext || {}, r = l.hooks.helperMissing, u = "function", i = l.hooks.blockHelperMissing, c = l.lookupProperty || function (l, n) { if (Object.prototype.hasOwnProperty.call(l, n))
|
|
11
|
+
return l[n]; }, s = " [", p = null != (p = c(e, "color") || (null != n ? c(n, "color") : n)) ? p : r, m = { name: "color", hash: {}, fn: l.program(30, o, 0), inverse: l.noop, data: o, loc: { start: { line: 19, column: 32 }, end: { line: 19, column: 68 } } }, f = typeof p == u ? p.call(a, m) : p; return null != (f = c(e, "color") ? f : i.call(n, f, m)) && (s += f), p = null != (p = c(e, "type") || (null != n ? c(n, "type") : n)) ? p : r, m = { name: "type", hash: {}, fn: l.program(32, o, 0), inverse: l.noop, data: o, loc: { start: { line: 19, column: 69 }, end: { line: 19, column: 102 } } }, f = typeof p == u ? p.call(a, m) : p, null != (f = c(e, "type") ? f : i.call(n, f, m)) && (s += f), s + "]"; }, 30: function (l, n, e, t, o) { return 'color="' + (null != (l = l.lambda(n, n)) ? l : "") + '"'; }, 32: function (l, n, e, t, o) { return " type=" + (null != (l = l.lambda(n, n)) ? l : ""); }, 34: function (l, n, e, t, o) { var a = l.lookupProperty || function (l, n) { if (Object.prototype.hasOwnProperty.call(l, n))
|
|
12
|
+
return l[n]; }; return ": " + (null != (e = (a(e, "quotifyLabel") || n && a(n, "quotifyLabel") || l.hooks.helperMissing).call(null != n ? n : l.nullContext || {}, n, { name: "quotifyLabel", hash: {}, fn: l.program(4, o, 0), inverse: l.noop, data: o, loc: { start: { line: 20, column: 16 }, end: { line: 20, column: 52 } } })) ? e : ""); }, compiler: [8, ">= 4.3.0"], main: function (l, n, e, t, o) { var a = null != n ? n : l.nullContext || {}, r = l.lookupProperty || function (l, n) { if (Object.prototype.hasOwnProperty.call(l, n))
|
|
13
|
+
return l[n]; }, u = (null != (c = r(e, "each").call(a, null != n ? r(n, "states") : n, { name: "each", hash: {}, fn: l.program(1, o, 0), inverse: l.noop, data: o, loc: { start: { line: 1, column: 0 }, end: { line: 12, column: 9 } } })) ? c : "") + "\n", i = null != (i = r(e, "transitions") || (null != n ? r(n, "transitions") : n)) ? i : l.hooks.helperMissing, o = { name: "transitions", hash: {}, fn: l.program(28, o, 0), inverse: l.noop, data: o, loc: { start: { line: 14, column: 0 }, end: { line: 21, column: 16 } } }, c = "function" == typeof i ? i.call(a, o) : i; return null != (c = r(e, "transitions") ? c : l.hooks.blockHelperMissing.call(n, c, o)) && (u += c), u; }, usePartial: !0, useData: !0 });
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
const DEFAULT_OPTIONS = {
|
|
3
|
+
exec: "dot",
|
|
4
|
+
format: "svg",
|
|
5
|
+
};
|
|
6
|
+
function convert(pDot, pOptions) {
|
|
7
|
+
const lOptions = {
|
|
8
|
+
...DEFAULT_OPTIONS,
|
|
9
|
+
...pOptions,
|
|
10
|
+
};
|
|
11
|
+
const { stdout, status, error } = spawnSync(lOptions.exec, [`-T${lOptions.format}`], {
|
|
12
|
+
input: pDot,
|
|
13
|
+
});
|
|
14
|
+
if (status === 0) {
|
|
15
|
+
return stdout.toString("binary");
|
|
16
|
+
}
|
|
17
|
+
else if (error) {
|
|
18
|
+
throw new Error(error);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
throw new Error(`Unexpected error occurred. Exit code ${status}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function isAvailable(pOptions) {
|
|
25
|
+
const lOptions = {
|
|
26
|
+
...DEFAULT_OPTIONS,
|
|
27
|
+
...pOptions,
|
|
28
|
+
};
|
|
29
|
+
const { status, stderr } = spawnSync(lOptions.exec, ["-V"]);
|
|
30
|
+
return (status === 0 && stderr.toString("utf8").startsWith("dot - graphviz version"));
|
|
31
|
+
}
|
|
32
|
+
export default {
|
|
33
|
+
convert,
|
|
34
|
+
isAvailable,
|
|
35
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import dotToSvgJs from "viz.js";
|
|
2
|
+
import indentString from "indent-string";
|
|
3
|
+
import wrapAnsi from "wrap-ansi";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import options from "../../options.mjs";
|
|
6
|
+
import ast2dot from "../dot/index.mjs";
|
|
7
|
+
import dotToVectorNative from "./dot-to-vector-native.mjs";
|
|
8
|
+
const DEFAULT_INDENT = 2;
|
|
9
|
+
const DOGMATIC_CONSOLE_WIDTH = 78;
|
|
10
|
+
const VIZ_JS_UNSUPPORTED_OUTPUT_FORMATS = ["pdf", "png"];
|
|
11
|
+
const renderVector = (pStateMachine, pOptions) => {
|
|
12
|
+
const lDotProgram = ast2dot(pStateMachine, pOptions);
|
|
13
|
+
const lDotOptions = {
|
|
14
|
+
engine: options.getOptionValue(pOptions, "engine"),
|
|
15
|
+
format: options.getOptionValue(pOptions, "outputType"),
|
|
16
|
+
};
|
|
17
|
+
if (dotToVectorNative.isAvailable(pOptions)) {
|
|
18
|
+
return dotToVectorNative.convert(lDotProgram, lDotOptions);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
if (VIZ_JS_UNSUPPORTED_OUTPUT_FORMATS.includes(lDotOptions.format)) {
|
|
22
|
+
throw new Error("GraphViz 'dot' executable not found. Falling back to viz.js.\n\n" +
|
|
23
|
+
"'viz.js' doesn't support the 'pdf' and 'png' output formats. Either " +
|
|
24
|
+
"select a format that it does support or install GraphViz " +
|
|
25
|
+
"(recommended), which has support for both formats.\n");
|
|
26
|
+
}
|
|
27
|
+
process.stderr.write(indentString(wrapAnsi(`\n${chalk.yellow("warning:")} GraphViz 'dot' executable not found. Falling back to viz.js.\n\n` +
|
|
28
|
+
"On node >=12 this fallback will trigger a warning from the " +
|
|
29
|
+
`node runtime:\n${chalk.italic("Invalid asm.js: Function definition doesn't match use")}.\n` +
|
|
30
|
+
"It's harmless and the svg will generate just fine. However, if " +
|
|
31
|
+
"you want to avoid the warning install GraphViz and make sure it's " +
|
|
32
|
+
"available in your path." +
|
|
33
|
+
"\n\n", DOGMATIC_CONSOLE_WIDTH), DEFAULT_INDENT));
|
|
34
|
+
return dotToSvgJs(lDotProgram, lDotOptions);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export default renderVector;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import viz from "viz.js";
|
|
2
|
+
import options from "../../options.mjs";
|
|
3
|
+
import ast2dot from "../dot/index.mjs";
|
|
4
|
+
const OUTPUT_TYPE2FORMAT = {
|
|
5
|
+
oldsvg: "svg",
|
|
6
|
+
oldps2: "ps2",
|
|
7
|
+
oldeps: "eps",
|
|
8
|
+
};
|
|
9
|
+
const renderVectorWithViz = (pStateMachine, pOptions) => viz(ast2dot(pStateMachine, pOptions), {
|
|
10
|
+
engine: options.getOptionValue(pOptions, "engine"),
|
|
11
|
+
format: OUTPUT_TYPE2FORMAT[options.getOptionValue(pOptions, "outputType")] || "svg",
|
|
12
|
+
});
|
|
13
|
+
export default renderVectorWithViz;
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
})));
|
|
16
|
+
}
|
|
17
|
+
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;
|
|
30
|
+
}
|
|
31
|
+
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
|
+
}
|
|
58
|
+
}
|