state-machine-cat 12.0.20 → 12.0.21
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 +1 -1
- package/dist/cli/actions.mjs +1 -1
- package/dist/counter.mjs +3 -3
- package/dist/render/dot/index.mjs +33 -14
- package/dist/state-machine-model.mjs +15 -15
- package/dist/version.mjs +1 -1
- package/package.json +1 -1
package/LICENSE
CHANGED
package/dist/cli/actions.mjs
CHANGED
|
@@ -5,7 +5,7 @@ const LICENSE = `
|
|
|
5
5
|
|
|
6
6
|
The MIT License (MIT)
|
|
7
7
|
|
|
8
|
-
Copyright (c) 2016-
|
|
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
|
@@ -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(
|
|
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(
|
|
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
|
-
|
|
181
|
+
pRenderedTransitions,
|
|
171
182
|
);
|
|
172
183
|
lCandidateTransitions.forEach((pTransition) => {
|
|
173
|
-
|
|
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) =>
|
|
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
|
-
|
|
260
|
-
const lStates = states(
|
|
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) => !
|
|
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
|
-
|
|
36
|
-
|
|
35
|
+
#flattenedTransitions;
|
|
36
|
+
#flattenedStates;
|
|
37
37
|
constructor(pStateMachine) {
|
|
38
|
-
this
|
|
39
|
-
flattenStatesToMap(pStateMachine.states ?? [], this
|
|
40
|
-
this
|
|
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
|
|
43
|
+
return this.#flattenedTransitions;
|
|
44
44
|
}
|
|
45
45
|
findStateByName(pName) {
|
|
46
|
-
return this.
|
|
46
|
+
return this.#flattenedStates.get(pName);
|
|
47
47
|
}
|
|
48
48
|
findStatesByTypes(pTypes) {
|
|
49
|
-
return Array.from(this.
|
|
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.
|
|
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.
|
|
62
|
+
return this.#flattenedTransitions.filter(
|
|
63
63
|
(pTransition) => pTransition.from === pFromStateName,
|
|
64
64
|
);
|
|
65
65
|
}
|
|
66
66
|
findTransitionsByTo(pToStateName) {
|
|
67
|
-
return this.
|
|
67
|
+
return this.#flattenedTransitions.filter(
|
|
68
68
|
(pTransition) => pTransition.to === pToStateName,
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
71
|
getMaximumTransitionId() {
|
|
72
|
-
return Math.max(...this.
|
|
72
|
+
return Math.max(...this.#flattenedTransitions.map(({ id }) => id));
|
|
73
73
|
}
|
|
74
74
|
findTransitionsToSiblings(pStateName, pExcludeIds) {
|
|
75
|
-
return this.
|
|
75
|
+
return this.#flattenedTransitions.filter(
|
|
76
76
|
(pTransition) =>
|
|
77
77
|
!pExcludeIds.has(pTransition.id) &&
|
|
78
78
|
pTransition.from === pStateName &&
|
|
79
|
-
this.
|
|
80
|
-
this.
|
|
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.
|
|
1
|
+
export const version = "12.0.21";
|