state-machine-cat 12.0.3 → 12.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016-2023 Sander Verweij
3
+ Copyright (c) 2016-2024 Sander Verweij
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -403,7 +403,12 @@ the tape player is on:
403
403
  ```
404
404
  initial,
405
405
  "tape player off",
406
- "tape player on" {
406
+ "tape player on":
407
+ entry/ LED on
408
+ exit/ LED off
409
+ {
410
+ stopped, playing, paused;
411
+
407
412
  stopped => playing : play;
408
413
  playing => stopped : stop;
409
414
  playing => paused : pause;
@@ -414,8 +419,13 @@ initial,
414
419
  initial => "tape player off";
415
420
  "tape player off" => stopped : power;
416
421
  "tape player on" => "tape player off" : power;
422
+
417
423
  ```
418
424
 
425
+ As you can see in this sample you can use activities (like entry and exit
426
+ triggers) in the composite state declaration, just as you'd do for state that
427
+ does not contain a state machine.
428
+
419
429
  <img width="653" alt="tape player rendition" src="https://raw.githubusercontent.com/sverweij/state-machine-cat/main/docs/pics/05tape_player.png">
420
430
 
421
431
  #### parallel states
@@ -630,7 +640,8 @@ The values you can use for the `type` of a state:
630
640
  #### grammar
631
641
 
632
642
  I made the parser with peggy - you can find it at
633
- [src/parse/peg/smcat-parser.peggy](src/parse/smcat/peg/smcat-parser.peggy)
643
+ [src/parse/peg/smcat-parser.peggy](src/parse/smcat/peg/smcat-parser.peggy), and
644
+ railroad diagrams generated from these on [state-machine-cat.js.org/grammar.html](https://state-machine-cat.js.org/grammar.html)
634
645
 
635
646
  ## Status
636
647
 
@@ -5,7 +5,7 @@ const LICENSE = `
5
5
 
6
6
  The MIT License (MIT)
7
7
 
8
- Copyright (c) 2016-2023 Sander Verweij
8
+ Copyright (c) 2016-2024 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/version.mjs CHANGED
@@ -1 +1 @@
1
- export const version = "12.0.3";
1
+ export const version = "12.0.5";
package/package.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "name": "state-machine-cat",
3
- "version": "12.0.3",
3
+ "version": "12.0.5",
4
4
  "description": "write beautiful state charts",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.mjs",
7
7
  "exports": {
8
8
  ".": [
9
9
  {
10
+ "types": "./types/state-machine-cat.d.mts",
10
11
  "import": "./dist/index.mjs"
11
12
  }
12
13
  ]
13
14
  },
15
+ "types": "types/state-machine-cat.d.mts",
14
16
  "imports": {
15
17
  "#*": "./src/*"
16
18
  },
@@ -48,10 +50,10 @@
48
50
  "state-machine-cat": "bin/smcat.mjs"
49
51
  },
50
52
  "dependencies": {
51
- "@hpcc-js/wasm": "2.15.1",
53
+ "@hpcc-js/wasm": "2.15.3",
52
54
  "ajv": "8.12.0",
53
- "commander": "11.1.0",
54
- "fast-xml-parser": "4.3.2",
55
+ "commander": "12.0.0",
56
+ "fast-xml-parser": "4.3.4",
55
57
  "handlebars": "4.7.8",
56
58
  "he": "1.2.0",
57
59
  "semver": "^7.5.4",
@@ -60,7 +62,6 @@
60
62
  "engines": {
61
63
  "node": "^18.17||>=20"
62
64
  },
63
- "types": "types/state-machine-cat.d.ts",
64
65
  "homepage": "https://state-machine-cat.js.org",
65
66
  "repository": {
66
67
  "type": "git",
@@ -68,5 +69,8 @@
68
69
  },
69
70
  "bugs": {
70
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"
71
75
  }
72
- }
76
+ }
@@ -0,0 +1,296 @@
1
+ export type StateType =
2
+ | "regular"
3
+ | "initial"
4
+ | "final"
5
+ | "parallel"
6
+ | "choice"
7
+ | "fork"
8
+ | "forkjoin"
9
+ | "history"
10
+ | "deephistory"
11
+ | "join"
12
+ | "junction"
13
+ | "terminate";
14
+
15
+ export type TransitionType = "external" | "internal";
16
+
17
+ export type ActionTypeType = "activity" | "entry" | "exit";
18
+
19
+ export interface IActionType {
20
+ body: string;
21
+ type: ActionTypeType;
22
+ }
23
+
24
+ export interface IState {
25
+ /**
26
+ * The name and identifier of the state. Unique within the root state machine.
27
+ */
28
+ name: string;
29
+ /**
30
+ * What kind of state (or pseudo state) this state is. E.g. 'regular'
31
+ * for normal states or 'initial', 'final', 'choice' etc for pseudo states
32
+ */
33
+ type: StateType;
34
+ /**
35
+ * The display label of the state. If it's not present, most renderers
36
+ * will use the states' name in stead
37
+ */
38
+ label?: string;
39
+ /**
40
+ * A series of actions and their types. The type describe when the action
41
+ * takes place (on entry, exit, or otherwise ('activity'))
42
+ */
43
+ actions?: IActionType[];
44
+ /**
45
+ * State machine nested within the state.
46
+ */
47
+ // eslint-disable-next-line no-use-before-define
48
+ statemachine?: IStateMachine;
49
+ /**
50
+ * If true the state is considered to be active and rendered as such.
51
+ */
52
+ active?: boolean;
53
+ /**
54
+ * Color to use for rendering the state. Accepts all css color names
55
+ * (\"blue\") and hex notation - with (\"#0000FF77\") or without
56
+ * (\"#0000FF\") transparency.
57
+ */
58
+ color?: string;
59
+ /**
60
+ * Class name to give the state in dot and svg output.
61
+ */
62
+ class?: string;
63
+ /**
64
+ * Comments related to this state. Some renderers will use the note
65
+ * attribute to render a note (i.e. as a post-it) attached to the
66
+ * state.
67
+ */
68
+ note?: string[];
69
+ /**
70
+ * convenience, derived attribute - set to true if there's a state
71
+ * machine inside the state; false in all other cases. For internal
72
+ * use - @deprecated
73
+ */
74
+ isComposite?: boolean;
75
+ /**
76
+ * The default parser derives the `type` from the `name` with inband
77
+ * signaling. The user can override that behavior by explicitly setting
78
+ * the `type`. This attribute is there to express that (and make sure
79
+ * that on next parses & processing it doesn't get accidentily
80
+ * re-derived from the name again)
81
+ */
82
+ typeExplicitlySet?: boolean;
83
+ }
84
+
85
+ export interface ITransition {
86
+ /**
87
+ * The name of the IState the transition is from
88
+ */
89
+ from: string;
90
+ /**
91
+ * The name of the IState the transition is to
92
+ */
93
+ to: string;
94
+ /**
95
+ * A display label to represent this transition. Parsers can parse this
96
+ * label into events conditions and actions.
97
+ */
98
+ label?: string;
99
+ /**
100
+ * Event triggering the transition
101
+ */
102
+ event?: string;
103
+ /**
104
+ * Condition for the transition to occur.
105
+ */
106
+ cond?: string;
107
+ /**
108
+ * Action to execute when the transition occurs.
109
+ */
110
+ action?: string;
111
+ /**
112
+ * Comments related to this transition. Some renderers will use the note
113
+ * attribute to render a note attached to the transition.
114
+ */
115
+ note?: string[];
116
+ /**
117
+ * Color to use for rendering the transition. Accepts all css color
118
+ * names (\"blue\") and hex notation - with (\"#0000FF77\") or without
119
+ * (\"#0000FF\") transparency.
120
+ */
121
+ color?: string;
122
+ /**
123
+ * The line width to use for rendering the transition
124
+ */
125
+ width?: number;
126
+ /**
127
+ * Class name to give the transition in dot and svg output.
128
+ */
129
+ class?: string;
130
+ /**
131
+ * Whether the transition is "external" (the default) or "internal".
132
+ * See https://www.w3.org/TR/scxml/#transition for details.
133
+ */
134
+ type?: TransitionType;
135
+ }
136
+
137
+ export interface IStateMachine {
138
+ states: IState[];
139
+ transitions?: ITransition[];
140
+ }
141
+
142
+ /**
143
+ * The current (semver compliant) version number string of
144
+ * state machine cat
145
+ *
146
+ * @type {string}
147
+ */
148
+ // eslint-disable-next-line init-declarations
149
+ export const version: string;
150
+
151
+ export interface IAllowedValue {
152
+ default: string;
153
+ values: {
154
+ name: string;
155
+ }[];
156
+ }
157
+
158
+ export interface IAllowedBooleanValue {
159
+ default: boolean;
160
+ values: {
161
+ name: boolean;
162
+ }[];
163
+ }
164
+ export interface IAllowedValues {
165
+ inputType: IAllowedValue;
166
+ outputType: IAllowedValue;
167
+ engine: IAllowedValue;
168
+ direction: IAllowedValue;
169
+ desugar: IAllowedBooleanValue;
170
+ }
171
+
172
+ /**
173
+ * @returns An object with for each of the options you can pass to
174
+ * the render function:
175
+ * - the default value
176
+ * - the possible values in an array of objects, each of which
177
+ * has the properties:
178
+ * - name: the value
179
+ *
180
+ */
181
+ export function getAllowedValues(): IAllowedValues;
182
+
183
+ export type InputType = "smcat" | "json" | "scxml";
184
+
185
+ export type OutputType =
186
+ | "ast"
187
+ | "dot"
188
+ | "eps"
189
+ | "json"
190
+ | "oldeps"
191
+ | "oldps"
192
+ | "oldps2"
193
+ | "oldsvg"
194
+ | "pdf"
195
+ | "png"
196
+ | "ps"
197
+ | "ps2"
198
+ | "scjson"
199
+ | "scxml"
200
+ | "smcat"
201
+ | "svg";
202
+
203
+ export type EngineType = "dot" | "circo" | "fdp" | "neato" | "osage" | "twopi";
204
+
205
+ export type DirectionType =
206
+ | "top-down"
207
+ | "bottom-top"
208
+ | "left-right"
209
+ | "right-left";
210
+
211
+ export type dotAttributesType = {
212
+ name: string;
213
+ value: string;
214
+ }[];
215
+
216
+ export interface IBaseRenderOptions {
217
+ /**
218
+ * How to interpret the input (defaults to 'smcat')
219
+ */
220
+ inputType?: InputType;
221
+ /**
222
+ * What renderer to use (defaults to 'svg')
223
+ */
224
+ outputType?: OutputType;
225
+ /**
226
+ * For the 'dot' renderer: what engine to use (defaults to 'dot')
227
+ */
228
+ engine?: EngineType;
229
+ /**
230
+ * For the 'dot' renderer: in what direction to plot the states
231
+ * (defaults to 'top-down')
232
+ */
233
+ direction?: DirectionType;
234
+ /**
235
+ * If true state machine cat will replace 'sugar' pseudo states
236
+ * (choice, forks and junctions) with their equivalent meaning
237
+ * (defaults to false).
238
+ *
239
+ * For details: https://github.com/sverweij/state-machine-cat/blob/main/docs/desugar.md
240
+ */
241
+ desugar?: boolean;
242
+ }
243
+
244
+ export interface IRenderOptions extends IBaseRenderOptions {
245
+ /**
246
+ * For the 'dot' renderer: Graph attributes to the engine
247
+ */
248
+ dotGraphAttrs?: dotAttributesType;
249
+ /**
250
+ * For the 'dot' renderer: Node attributes to the engine
251
+ */
252
+ dotNodeAttrs?: dotAttributesType;
253
+ /**
254
+ * For the 'dot' renderer: Edge attributes to the engine
255
+ */
256
+ dotEdgeAttrs?: dotAttributesType;
257
+ /**
258
+ * On nodejs don't display the warning that GraphViz 'dot'
259
+ * can't be found and we're falling back to wasm
260
+ */
261
+ noDotNativeWarning?: boolean;
262
+ }
263
+
264
+ export type StringRenderFunctionType = (
265
+ pStateMachine: IStateMachine,
266
+ pOptions?: IRenderOptions,
267
+ ) => string;
268
+
269
+ export type WhateverRenderFunctionType = (
270
+ pStateMachine: IStateMachine,
271
+ pOptions?: IRenderOptions,
272
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
273
+ ) => any;
274
+
275
+ export type RenderFunctionType =
276
+ | StringRenderFunctionType
277
+ | WhateverRenderFunctionType;
278
+
279
+ /**
280
+ * Translates the input script to an output script.
281
+ *
282
+ * @param pScript The script to translate
283
+ * @param pOptions options influencing parsing & rendering.
284
+ * See below for the complete list.
285
+ * @return the string with the rendered content if
286
+ * no error was found
287
+ * @throws {Error} If an error occurred and no callback
288
+ * function was passed: the error
289
+ *
290
+ * Options: see https://github.com/sverweij/state-machine-cat/docs/api.md
291
+ *
292
+ */
293
+ export function render(
294
+ pScript: IStateMachine | string,
295
+ pOptions: IRenderOptions,
296
+ ): string;