jssm 5.104.2 → 5.112.3
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/.gitattributes +17 -6
- package/.log-progress.json +9 -0
- package/CHANGELOG.md +130 -45
- package/CLAUDE.md +11 -0
- package/MIGRATING-jssm-viz.md +67 -0
- package/README.md +179 -882
- package/dist/es6/fsl_parser.js +1 -1
- package/dist/es6/jssm.d.ts +773 -39
- package/dist/es6/jssm.js +921 -89
- package/dist/es6/jssm_arrow.js +24 -0
- package/dist/es6/jssm_compiler.d.ts +17 -2
- package/dist/es6/jssm_compiler.js +17 -3
- package/dist/es6/jssm_constants.d.ts +27 -0
- package/dist/es6/jssm_constants.js +27 -0
- package/dist/es6/jssm_error.d.ts +19 -0
- package/dist/es6/jssm_error.js +19 -0
- package/dist/es6/jssm_theme.d.ts +11 -0
- package/dist/es6/jssm_theme.js +11 -0
- package/dist/es6/jssm_types.d.ts +29 -3
- package/dist/es6/jssm_util.d.ts +161 -9
- package/dist/es6/jssm_util.js +174 -17
- package/dist/es6/jssm_viz.d.ts +175 -0
- package/dist/es6/jssm_viz.js +560 -0
- package/dist/es6/jssm_viz_colors.d.ts +63 -0
- package/dist/es6/jssm_viz_colors.js +63 -0
- package/dist/es6/version.js +1 -1
- package/dist/jssm.es5.cjs +1 -1
- package/dist/jssm.es5.iife.js +1 -0
- package/dist/jssm.es5.nonmin.cjs +2201 -870
- package/dist/jssm.es6.mjs +1 -1
- package/dist/jssm.es6.nonmin.cjs +2200 -871
- package/dist/jssm_viz.cjs +1 -0
- package/dist/{jssm.es5.iife.nonmin.cjs → jssm_viz.es5.iife.nonmin.cjs} +2589 -1090
- package/dist/jssm_viz.es5.nonmin.cjs +24674 -0
- package/dist/jssm_viz.es6.nonmin.cjs +24661 -0
- package/dist/jssm_viz.iife.cjs +1 -0
- package/dist/jssm_viz.mjs +1 -0
- package/jest-dragon.config.cjs +4 -1
- package/jest-spec.config.cjs +9 -6
- package/jest-stoch.config.cjs +4 -1
- package/jest-unicode.config.cjs +4 -1
- package/jssm.es5.d.cts +950 -41
- package/jssm.es6.d.ts +950 -41
- package/jssm_viz.es5.d.cts +2127 -0
- package/jssm_viz.es6.d.ts +2127 -0
- package/log-progress.data.json +28 -0
- package/package.json +56 -23
- package/rollup.config.viz.es5.js +46 -0
- package/rollup.config.viz.es6.js +46 -0
- package/rollup.config.viz.iife.js +36 -0
- package/typedoc-options.cjs +4 -3
- package/dist/jssm.es5.iife.cjs +0 -1
- package/fsl_parser.d.ts +0 -6
- package/jssm.d.ts +0 -1141
- package/jssm_arrow.d.ts +0 -53
- package/jssm_compiler.d.ts +0 -135
- package/jssm_constants.d.ts +0 -5
- package/jssm_error.d.ts +0 -8
- package/jssm_theme.d.ts +0 -4
- package/jssm_types.d.ts +0 -378
- package/jssm_util.d.ts +0 -106
- package/version.d.ts +0 -2
|
@@ -0,0 +1,2127 @@
|
|
|
1
|
+
import { circular_buffer } from 'circular_buffer_js';
|
|
2
|
+
|
|
3
|
+
declare type StateType$1 = string; /** Composite type composing whether or not a result was successful */
|
|
4
|
+
declare type JssmColor = string;
|
|
5
|
+
declare type JssmPermittedOpt = 'required' | 'disallowed' | 'optional';
|
|
6
|
+
declare type JssmArrow = '->' | '<-' | '<->' | '<=->' | '<~->' | '=>' | '<=' | '<=>' | '<-=>' | '<~=>' | '~>' | '<~' | '<~>' | '<-~>' | '<=~>';
|
|
7
|
+
/**
|
|
8
|
+
* A type teaching Typescript the various supported shapes for nodes, mostly inherited from GraphViz
|
|
9
|
+
*/
|
|
10
|
+
declare type JssmShape = "box" | "polygon" | "ellipse" | "oval" | "circle" | "point" | "egg" | "triangle" | "plaintext" | "plain" | "diamond" | "trapezium" | "parallelogram" | "house" | "pentagon" | "hexagon" | "septagon" | "octagon" | "doublecircle" | "doubleoctagon" | "tripleoctagon" | "invtriangle" | "invtrapezium" | "invhouse" | "Mdiamond" | "Msquare" | "Mcircle" | "rect" | "rectangle" | "square" | "star" | "none" | "underline" | "cylinder" | "note" | "tab" | "folder" | "box3d" | "component" | "promoter" | "cds" | "terminator" | "utr" | "primersite" | "restrictionsite" | "fivepoverhang" | "threepoverhang" | "noverhang" | "assembly" | "signature" | "insulator" | "ribosite" | "rnastab" | "proteasesite" | "proteinstab" | "rpromoter" | "rarrow" | "larrow" | "lpromoter" | "record";
|
|
11
|
+
declare type JssmArrowKind = 'none' | 'legal' | 'main' | 'forced';
|
|
12
|
+
declare type JssmLayout = 'dot' | 'circo' | 'twopi' | 'fdp' | 'neato';
|
|
13
|
+
declare type JssmCorner = 'regular' | 'rounded' | 'lined';
|
|
14
|
+
declare type JssmLineStyle = 'solid' | 'dashed' | 'dotted';
|
|
15
|
+
declare type JssmAllowsOverride = true | false | undefined;
|
|
16
|
+
declare const FslDirections: readonly ["up", "right", "down", "left"];
|
|
17
|
+
declare type FslDirection = typeof FslDirections[number];
|
|
18
|
+
declare const FslThemes: readonly ["default", "ocean", "modern", "plain", "bold"];
|
|
19
|
+
declare type FslTheme = typeof FslThemes[number];
|
|
20
|
+
declare type JssmSerialization<DataType> = {
|
|
21
|
+
jssm_version: string;
|
|
22
|
+
timestamp: number;
|
|
23
|
+
comment?: string | undefined;
|
|
24
|
+
state: StateType$1;
|
|
25
|
+
history: [string, DataType][];
|
|
26
|
+
history_capacity: number;
|
|
27
|
+
data: DataType;
|
|
28
|
+
};
|
|
29
|
+
declare type JssmPropertyDefinition = {
|
|
30
|
+
name: string;
|
|
31
|
+
default_value?: any;
|
|
32
|
+
required?: boolean;
|
|
33
|
+
};
|
|
34
|
+
declare type JssmTransitionPermitter<DataType> = (OldState: StateType$1, NewState: StateType$1, OldData: DataType, NewData: DataType) => boolean;
|
|
35
|
+
declare type JssmTransitionPermitterMaybeArray<DataType> = JssmTransitionPermitter<DataType> | Array<JssmTransitionPermitter<DataType>>;
|
|
36
|
+
declare type JssmTransition<StateType, DataType> = {
|
|
37
|
+
from: StateType;
|
|
38
|
+
to: StateType;
|
|
39
|
+
after_time?: number;
|
|
40
|
+
se?: JssmCompileSe<StateType, DataType>;
|
|
41
|
+
name?: StateType;
|
|
42
|
+
action?: StateType;
|
|
43
|
+
check?: JssmTransitionPermitterMaybeArray<DataType>;
|
|
44
|
+
probability?: number;
|
|
45
|
+
kind: JssmArrowKind;
|
|
46
|
+
forced_only: boolean;
|
|
47
|
+
main_path: boolean;
|
|
48
|
+
};
|
|
49
|
+
declare type JssmTransitions<StateType, DataType> = JssmTransition<StateType, DataType>[];
|
|
50
|
+
declare type JssmTransitionList = {
|
|
51
|
+
entrances: Array<StateType$1>;
|
|
52
|
+
exits: Array<StateType$1>;
|
|
53
|
+
};
|
|
54
|
+
declare type JssmGenericState = {
|
|
55
|
+
from: Array<StateType$1>;
|
|
56
|
+
name: StateType$1;
|
|
57
|
+
to: Array<StateType$1>;
|
|
58
|
+
complete: boolean;
|
|
59
|
+
};
|
|
60
|
+
declare type JssmMachineInternalState<DataType> = {
|
|
61
|
+
internal_state_impl_version: 1;
|
|
62
|
+
state: StateType$1;
|
|
63
|
+
states: Map<StateType$1, JssmGenericState>;
|
|
64
|
+
named_transitions: Map<StateType$1, number>;
|
|
65
|
+
edge_map: Map<StateType$1, Map<StateType$1, number>>;
|
|
66
|
+
actions: Map<StateType$1, Map<StateType$1, number>>;
|
|
67
|
+
reverse_actions: Map<StateType$1, Map<StateType$1, number>>;
|
|
68
|
+
edges: Array<JssmTransition<StateType$1, DataType>>;
|
|
69
|
+
};
|
|
70
|
+
declare type JssmStatePermitter<DataType> = (OldState: StateType$1, NewState: StateType$1, OldData: DataType, NewData: DataType) => boolean;
|
|
71
|
+
declare type JssmStatePermitterMaybeArray<DataType> = JssmStatePermitter<DataType> | Array<JssmStatePermitter<DataType>>;
|
|
72
|
+
declare type JssmStateDeclarationRule = {
|
|
73
|
+
key: string;
|
|
74
|
+
value: any;
|
|
75
|
+
name?: string;
|
|
76
|
+
};
|
|
77
|
+
declare type JssmStateDeclaration = {
|
|
78
|
+
declarations: Array<JssmStateDeclarationRule>;
|
|
79
|
+
shape?: JssmShape;
|
|
80
|
+
color?: JssmColor;
|
|
81
|
+
corners?: JssmCorner;
|
|
82
|
+
lineStyle?: JssmLineStyle;
|
|
83
|
+
stateLabel?: string;
|
|
84
|
+
textColor?: JssmColor;
|
|
85
|
+
backgroundColor?: JssmColor;
|
|
86
|
+
borderColor?: JssmColor;
|
|
87
|
+
image?: string;
|
|
88
|
+
state: StateType$1;
|
|
89
|
+
property?: {
|
|
90
|
+
name: string;
|
|
91
|
+
value: unknown;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
declare type JssmStateConfig = Partial<JssmStateDeclaration>;
|
|
95
|
+
declare type JssmStateStyleShape = {
|
|
96
|
+
key: 'shape';
|
|
97
|
+
value: JssmShape;
|
|
98
|
+
};
|
|
99
|
+
declare type JssmStateStyleColor = {
|
|
100
|
+
key: 'color';
|
|
101
|
+
value: JssmColor;
|
|
102
|
+
};
|
|
103
|
+
declare type JssmStateStyleTextColor = {
|
|
104
|
+
key: 'text-color';
|
|
105
|
+
value: JssmColor;
|
|
106
|
+
};
|
|
107
|
+
declare type JssmStateStyleCorners = {
|
|
108
|
+
key: 'corners';
|
|
109
|
+
value: JssmCorner;
|
|
110
|
+
};
|
|
111
|
+
declare type JssmStateStyleLineStyle = {
|
|
112
|
+
key: 'line-style';
|
|
113
|
+
value: JssmLineStyle;
|
|
114
|
+
};
|
|
115
|
+
declare type JssmStateStyleStateLabel = {
|
|
116
|
+
key: 'state-label';
|
|
117
|
+
value: string;
|
|
118
|
+
};
|
|
119
|
+
declare type JssmStateStyleBackgroundColor = {
|
|
120
|
+
key: 'background-color';
|
|
121
|
+
value: JssmColor;
|
|
122
|
+
};
|
|
123
|
+
declare type JssmStateStyleBorderColor = {
|
|
124
|
+
key: 'border-color';
|
|
125
|
+
value: JssmColor;
|
|
126
|
+
};
|
|
127
|
+
declare type JssmStateStyleImage = {
|
|
128
|
+
key: 'image';
|
|
129
|
+
value: string;
|
|
130
|
+
};
|
|
131
|
+
declare type JssmStateStyleKey = JssmStateStyleShape | JssmStateStyleColor | JssmStateStyleTextColor | JssmStateStyleCorners | JssmStateStyleLineStyle | JssmStateStyleBackgroundColor | JssmStateStyleStateLabel | JssmStateStyleBorderColor | JssmStateStyleImage;
|
|
132
|
+
declare type JssmStateStyleKeyList = JssmStateStyleKey[];
|
|
133
|
+
declare type JssmGenericConfig<StateType, DataType> = {
|
|
134
|
+
graph_layout?: JssmLayout;
|
|
135
|
+
complete?: Array<StateType>;
|
|
136
|
+
transitions: JssmTransitions<StateType, DataType>;
|
|
137
|
+
theme?: FslTheme[];
|
|
138
|
+
flow?: FslDirection;
|
|
139
|
+
name?: string;
|
|
140
|
+
data?: DataType;
|
|
141
|
+
nodes?: Array<StateType>;
|
|
142
|
+
check?: JssmStatePermitterMaybeArray<DataType>;
|
|
143
|
+
history?: number;
|
|
144
|
+
min_exits?: number;
|
|
145
|
+
max_exits?: number;
|
|
146
|
+
allow_islands?: false;
|
|
147
|
+
allow_force?: false;
|
|
148
|
+
actions?: JssmPermittedOpt;
|
|
149
|
+
simplify_bidi?: boolean;
|
|
150
|
+
allows_override?: JssmAllowsOverride;
|
|
151
|
+
config_allows_override?: JssmAllowsOverride;
|
|
152
|
+
dot_preamble?: string;
|
|
153
|
+
start_states: Array<StateType>;
|
|
154
|
+
end_states?: Array<StateType>;
|
|
155
|
+
initial_state?: StateType;
|
|
156
|
+
start_states_no_enforce?: boolean;
|
|
157
|
+
state_declaration?: Object[];
|
|
158
|
+
property_definition?: JssmPropertyDefinition[];
|
|
159
|
+
state_property?: JssmPropertyDefinition[];
|
|
160
|
+
arrange_declaration?: Array<Array<StateType>>;
|
|
161
|
+
arrange_start_declaration?: Array<Array<StateType>>;
|
|
162
|
+
arrange_end_declaration?: Array<Array<StateType>>;
|
|
163
|
+
machine_author?: string | Array<string>;
|
|
164
|
+
machine_comment?: string;
|
|
165
|
+
machine_contributor?: string | Array<string>;
|
|
166
|
+
machine_definition?: string;
|
|
167
|
+
machine_language?: string;
|
|
168
|
+
machine_license?: string;
|
|
169
|
+
machine_name?: string;
|
|
170
|
+
machine_version?: string;
|
|
171
|
+
fsl_version?: string;
|
|
172
|
+
auto_api?: boolean | string;
|
|
173
|
+
instance_name?: string | undefined;
|
|
174
|
+
default_state_config?: JssmStateStyleKeyList;
|
|
175
|
+
default_start_state_config?: JssmStateStyleKeyList;
|
|
176
|
+
default_end_state_config?: JssmStateStyleKeyList;
|
|
177
|
+
default_hooked_state_config?: JssmStateStyleKeyList;
|
|
178
|
+
default_terminal_state_config?: JssmStateStyleKeyList;
|
|
179
|
+
default_active_state_config?: JssmStateStyleKeyList;
|
|
180
|
+
rng_seed?: number | undefined;
|
|
181
|
+
time_source?: () => number;
|
|
182
|
+
timeout_source?: (Function: any, number: any) => number;
|
|
183
|
+
clear_timeout_source?: (number: any) => void;
|
|
184
|
+
};
|
|
185
|
+
declare type JssmCompileSe<StateType, mDT> = {
|
|
186
|
+
to: StateType;
|
|
187
|
+
se?: JssmCompileSe<StateType, mDT>;
|
|
188
|
+
kind: JssmArrow;
|
|
189
|
+
l_action?: StateType;
|
|
190
|
+
r_action?: StateType;
|
|
191
|
+
l_probability: number;
|
|
192
|
+
r_probability: number;
|
|
193
|
+
l_after?: number;
|
|
194
|
+
r_after?: number;
|
|
195
|
+
};
|
|
196
|
+
declare type BasicHookDescription<mDT> = {
|
|
197
|
+
kind: 'hook';
|
|
198
|
+
from: string;
|
|
199
|
+
to: string;
|
|
200
|
+
handler: HookHandler<mDT>;
|
|
201
|
+
};
|
|
202
|
+
declare type HookDescriptionWithAction<mDT> = {
|
|
203
|
+
kind: 'named';
|
|
204
|
+
from: string;
|
|
205
|
+
to: string;
|
|
206
|
+
action: string;
|
|
207
|
+
handler: HookHandler<mDT>;
|
|
208
|
+
};
|
|
209
|
+
declare type StandardTransitionHook<mDT> = {
|
|
210
|
+
kind: 'standard transition';
|
|
211
|
+
handler: HookHandler<mDT>;
|
|
212
|
+
};
|
|
213
|
+
declare type MainTransitionHook<mDT> = {
|
|
214
|
+
kind: 'main transition';
|
|
215
|
+
handler: HookHandler<mDT>;
|
|
216
|
+
};
|
|
217
|
+
declare type ForcedTransitionHook<mDT> = {
|
|
218
|
+
kind: 'forced transition';
|
|
219
|
+
handler: HookHandler<mDT>;
|
|
220
|
+
};
|
|
221
|
+
declare type AnyTransitionHook<mDT> = {
|
|
222
|
+
kind: 'any transition';
|
|
223
|
+
handler: HookHandler<mDT>;
|
|
224
|
+
};
|
|
225
|
+
declare type GlobalActionHook<mDT> = {
|
|
226
|
+
kind: 'global action';
|
|
227
|
+
action: string;
|
|
228
|
+
handler: HookHandler<mDT>;
|
|
229
|
+
};
|
|
230
|
+
declare type AnyActionHook<mDT> = {
|
|
231
|
+
kind: 'any action';
|
|
232
|
+
handler: HookHandler<mDT>;
|
|
233
|
+
};
|
|
234
|
+
declare type EntryHook<mDT> = {
|
|
235
|
+
kind: 'entry';
|
|
236
|
+
to: string;
|
|
237
|
+
handler: HookHandler<mDT>;
|
|
238
|
+
};
|
|
239
|
+
declare type ExitHook<mDT> = {
|
|
240
|
+
kind: 'exit';
|
|
241
|
+
from: string;
|
|
242
|
+
handler: HookHandler<mDT>;
|
|
243
|
+
};
|
|
244
|
+
declare type AfterHook<mDT> = {
|
|
245
|
+
kind: 'after';
|
|
246
|
+
from: string;
|
|
247
|
+
handler: HookHandler<mDT>;
|
|
248
|
+
};
|
|
249
|
+
declare type PostBasicHookDescription<mDT> = {
|
|
250
|
+
kind: 'post hook';
|
|
251
|
+
from: string;
|
|
252
|
+
to: string;
|
|
253
|
+
handler: PostHookHandler<mDT>;
|
|
254
|
+
};
|
|
255
|
+
declare type PostHookDescriptionWithAction<mDT> = {
|
|
256
|
+
kind: 'post named';
|
|
257
|
+
from: string;
|
|
258
|
+
to: string;
|
|
259
|
+
action: string;
|
|
260
|
+
handler: PostHookHandler<mDT>;
|
|
261
|
+
};
|
|
262
|
+
declare type PostStandardTransitionHook<mDT> = {
|
|
263
|
+
kind: 'post standard transition';
|
|
264
|
+
handler: PostHookHandler<mDT>;
|
|
265
|
+
};
|
|
266
|
+
declare type PostMainTransitionHook<mDT> = {
|
|
267
|
+
kind: 'post main transition';
|
|
268
|
+
handler: PostHookHandler<mDT>;
|
|
269
|
+
};
|
|
270
|
+
declare type PostForcedTransitionHook<mDT> = {
|
|
271
|
+
kind: 'post forced transition';
|
|
272
|
+
handler: PostHookHandler<mDT>;
|
|
273
|
+
};
|
|
274
|
+
declare type PostAnyTransitionHook<mDT> = {
|
|
275
|
+
kind: 'post any transition';
|
|
276
|
+
handler: PostHookHandler<mDT>;
|
|
277
|
+
};
|
|
278
|
+
declare type PostGlobalActionHook<mDT> = {
|
|
279
|
+
kind: 'post global action';
|
|
280
|
+
action: string;
|
|
281
|
+
handler: PostHookHandler<mDT>;
|
|
282
|
+
};
|
|
283
|
+
declare type PostAnyActionHook<mDT> = {
|
|
284
|
+
kind: 'post any action';
|
|
285
|
+
handler: PostHookHandler<mDT>;
|
|
286
|
+
};
|
|
287
|
+
declare type PostEntryHook<mDT> = {
|
|
288
|
+
kind: 'post entry';
|
|
289
|
+
to: string;
|
|
290
|
+
handler: PostHookHandler<mDT>;
|
|
291
|
+
};
|
|
292
|
+
declare type PostExitHook<mDT> = {
|
|
293
|
+
kind: 'post exit';
|
|
294
|
+
from: string;
|
|
295
|
+
handler: PostHookHandler<mDT>;
|
|
296
|
+
};
|
|
297
|
+
declare type PreEverythingHook<mDT> = {
|
|
298
|
+
kind: 'pre everything';
|
|
299
|
+
handler: EverythingHookHandler<mDT>;
|
|
300
|
+
};
|
|
301
|
+
declare type EverythingHook<mDT> = {
|
|
302
|
+
kind: 'everything';
|
|
303
|
+
handler: EverythingHookHandler<mDT>;
|
|
304
|
+
};
|
|
305
|
+
declare type PrePostEverythingHook<mDT> = {
|
|
306
|
+
kind: 'pre post everything';
|
|
307
|
+
handler: PostEverythingHookHandler<mDT>;
|
|
308
|
+
};
|
|
309
|
+
declare type PostEverythingHook<mDT> = {
|
|
310
|
+
kind: 'post everything';
|
|
311
|
+
handler: PostEverythingHookHandler<mDT>;
|
|
312
|
+
};
|
|
313
|
+
declare type HookDescription<mDT> = BasicHookDescription<mDT> | HookDescriptionWithAction<mDT> | GlobalActionHook<mDT> | AnyActionHook<mDT> | StandardTransitionHook<mDT> | MainTransitionHook<mDT> | ForcedTransitionHook<mDT> | AnyTransitionHook<mDT> | EntryHook<mDT> | ExitHook<mDT> | AfterHook<mDT> | PostBasicHookDescription<mDT> | PostHookDescriptionWithAction<mDT> | PostGlobalActionHook<mDT> | PostAnyActionHook<mDT> | PostStandardTransitionHook<mDT> | PostMainTransitionHook<mDT> | PostForcedTransitionHook<mDT> | PostAnyTransitionHook<mDT> | PostEntryHook<mDT> | PostExitHook<mDT> | PreEverythingHook<mDT> | EverythingHook<mDT> | PrePostEverythingHook<mDT> | PostEverythingHook<mDT>;
|
|
314
|
+
declare type HookComplexResult<mDT> = {
|
|
315
|
+
pass: boolean;
|
|
316
|
+
state?: StateType$1;
|
|
317
|
+
data?: mDT;
|
|
318
|
+
next_data?: mDT;
|
|
319
|
+
};
|
|
320
|
+
declare type HookResult<mDT> = true | false | undefined | void | HookComplexResult<mDT>; /** Documents whether a hook succeeded, either with a primitive or a reference to the hook complex object */
|
|
321
|
+
declare type HookContext<mDT> = {
|
|
322
|
+
data: mDT;
|
|
323
|
+
next_data: mDT;
|
|
324
|
+
};
|
|
325
|
+
declare type EverythingHookContext<mDT> = HookContext<mDT> & {
|
|
326
|
+
hook_name: string;
|
|
327
|
+
};
|
|
328
|
+
declare type HookHandler<mDT> = (hook_context: HookContext<mDT>) => HookResult<mDT>;
|
|
329
|
+
declare type PostHookHandler<mDT> = (hook_context: HookContext<mDT>) => void;
|
|
330
|
+
declare type EverythingHookHandler<mDT> = (hook_context: EverythingHookContext<mDT>) => HookResult<mDT>;
|
|
331
|
+
declare type PostEverythingHookHandler<mDT> = (hook_context: EverythingHookContext<mDT>) => void;
|
|
332
|
+
declare type JssmHistory<mDT> = circular_buffer<[StateType$1, mDT]>;
|
|
333
|
+
declare type JssmRng = () => number;
|
|
334
|
+
|
|
335
|
+
declare const version: string;
|
|
336
|
+
declare const build_time: number;
|
|
337
|
+
|
|
338
|
+
declare type StateType = string;
|
|
339
|
+
|
|
340
|
+
/*******
|
|
341
|
+
*
|
|
342
|
+
* Core finite state machine class. Holds the full graph of states and
|
|
343
|
+
* transitions, the current state, hooks, data, properties, and all runtime
|
|
344
|
+
* behavior. Typically created via the {@link sm} tagged template literal
|
|
345
|
+
* rather than constructed directly.
|
|
346
|
+
*
|
|
347
|
+
* ```typescript
|
|
348
|
+
* import { sm } from 'jssm';
|
|
349
|
+
*
|
|
350
|
+
* const light = sm`Red 'next' => Green 'next' => Yellow 'next' => Red;`;
|
|
351
|
+
* light.state(); // 'Red'
|
|
352
|
+
* light.action('next'); // true
|
|
353
|
+
* light.state(); // 'Green'
|
|
354
|
+
* ```
|
|
355
|
+
*
|
|
356
|
+
* @typeparam mDT The machine data type — the type of the value stored in
|
|
357
|
+
* `.data()`. Defaults to `undefined` when no data is used.
|
|
358
|
+
*
|
|
359
|
+
*/
|
|
360
|
+
declare class Machine<mDT> {
|
|
361
|
+
_state: StateType;
|
|
362
|
+
_states: Map<StateType, JssmGenericState>;
|
|
363
|
+
_edges: Array<JssmTransition<StateType, mDT>>;
|
|
364
|
+
_edge_map: Map<StateType, Map<StateType, number>>;
|
|
365
|
+
_named_transitions: Map<StateType, number>;
|
|
366
|
+
_actions: Map<StateType, Map<StateType, number>>;
|
|
367
|
+
_reverse_actions: Map<StateType, Map<StateType, number>>;
|
|
368
|
+
_reverse_action_targets: Map<StateType, Map<StateType, number>>;
|
|
369
|
+
_start_states: Set<StateType>;
|
|
370
|
+
_end_states: Set<StateType>;
|
|
371
|
+
_machine_author?: Array<string>;
|
|
372
|
+
_machine_comment?: string;
|
|
373
|
+
_machine_contributor?: Array<string>;
|
|
374
|
+
_machine_definition?: string;
|
|
375
|
+
_machine_language?: string;
|
|
376
|
+
_machine_license?: string;
|
|
377
|
+
_machine_name?: string;
|
|
378
|
+
_machine_version?: string;
|
|
379
|
+
_fsl_version?: string;
|
|
380
|
+
_raw_state_declaration?: Array<Object>;
|
|
381
|
+
_state_declarations: Map<StateType, JssmStateDeclaration>;
|
|
382
|
+
_data?: mDT;
|
|
383
|
+
_instance_name: string;
|
|
384
|
+
_rng_seed: number;
|
|
385
|
+
_rng: JssmRng;
|
|
386
|
+
_graph_layout: JssmLayout;
|
|
387
|
+
_dot_preamble: string;
|
|
388
|
+
_arrange_declaration: Array<Array<StateType>>;
|
|
389
|
+
_arrange_start_declaration: Array<Array<StateType>>;
|
|
390
|
+
_arrange_end_declaration: Array<Array<StateType>>;
|
|
391
|
+
_themes: FslTheme[];
|
|
392
|
+
_flow: FslDirection;
|
|
393
|
+
_has_hooks: boolean;
|
|
394
|
+
_has_basic_hooks: boolean;
|
|
395
|
+
_has_named_hooks: boolean;
|
|
396
|
+
_has_entry_hooks: boolean;
|
|
397
|
+
_has_exit_hooks: boolean;
|
|
398
|
+
_has_after_hooks: boolean;
|
|
399
|
+
_has_global_action_hooks: boolean;
|
|
400
|
+
_has_transition_hooks: boolean;
|
|
401
|
+
_has_forced_transitions: boolean;
|
|
402
|
+
_hooks: Map<string, HookHandler<mDT>>;
|
|
403
|
+
_named_hooks: Map<string, HookHandler<mDT>>;
|
|
404
|
+
_entry_hooks: Map<string, HookHandler<mDT>>;
|
|
405
|
+
_exit_hooks: Map<string, HookHandler<mDT>>;
|
|
406
|
+
_after_hooks: Map<string, HookHandler<mDT>>;
|
|
407
|
+
_global_action_hooks: Map<string, HookHandler<mDT>>;
|
|
408
|
+
_any_action_hook: HookHandler<mDT> | undefined;
|
|
409
|
+
_standard_transition_hook: HookHandler<mDT> | undefined;
|
|
410
|
+
_main_transition_hook: HookHandler<mDT> | undefined;
|
|
411
|
+
_forced_transition_hook: HookHandler<mDT> | undefined;
|
|
412
|
+
_any_transition_hook: HookHandler<mDT> | undefined;
|
|
413
|
+
_has_post_hooks: boolean;
|
|
414
|
+
_has_post_basic_hooks: boolean;
|
|
415
|
+
_has_post_named_hooks: boolean;
|
|
416
|
+
_has_post_entry_hooks: boolean;
|
|
417
|
+
_has_post_exit_hooks: boolean;
|
|
418
|
+
_has_post_global_action_hooks: boolean;
|
|
419
|
+
_has_post_transition_hooks: boolean;
|
|
420
|
+
_code_allows_override: JssmAllowsOverride;
|
|
421
|
+
_config_allows_override: JssmAllowsOverride;
|
|
422
|
+
_post_hooks: Map<string, HookHandler<mDT>>;
|
|
423
|
+
_post_named_hooks: Map<string, HookHandler<mDT>>;
|
|
424
|
+
_post_entry_hooks: Map<string, HookHandler<mDT>>;
|
|
425
|
+
_post_exit_hooks: Map<string, HookHandler<mDT>>;
|
|
426
|
+
_post_global_action_hooks: Map<string, HookHandler<mDT>>;
|
|
427
|
+
_post_any_action_hook: HookHandler<mDT> | undefined;
|
|
428
|
+
_post_standard_transition_hook: HookHandler<mDT> | undefined;
|
|
429
|
+
_post_main_transition_hook: HookHandler<mDT> | undefined;
|
|
430
|
+
_post_forced_transition_hook: HookHandler<mDT> | undefined;
|
|
431
|
+
_post_any_transition_hook: HookHandler<mDT> | undefined;
|
|
432
|
+
_pre_everything_hook: EverythingHookHandler<mDT> | undefined;
|
|
433
|
+
_everything_hook: EverythingHookHandler<mDT> | undefined;
|
|
434
|
+
_pre_post_everything_hook: PostEverythingHookHandler<mDT> | undefined;
|
|
435
|
+
_post_everything_hook: PostEverythingHookHandler<mDT> | undefined;
|
|
436
|
+
_property_keys: Set<string>;
|
|
437
|
+
_default_properties: Map<string, any>;
|
|
438
|
+
_state_properties: Map<string, any>;
|
|
439
|
+
_required_properties: Set<string>;
|
|
440
|
+
_history: JssmHistory<mDT>;
|
|
441
|
+
_history_length: number;
|
|
442
|
+
_state_style: JssmStateConfig;
|
|
443
|
+
_active_state_style: JssmStateConfig;
|
|
444
|
+
_hooked_state_style: JssmStateConfig;
|
|
445
|
+
_terminal_state_style: JssmStateConfig;
|
|
446
|
+
_start_state_style: JssmStateConfig;
|
|
447
|
+
_end_state_style: JssmStateConfig;
|
|
448
|
+
_state_labels: Map<string, string>;
|
|
449
|
+
_time_source: () => number;
|
|
450
|
+
_create_started: number;
|
|
451
|
+
_created: number;
|
|
452
|
+
_after_mapping: Map<string, [string, number]>;
|
|
453
|
+
_timeout_source: (Function: any, number: any) => number;
|
|
454
|
+
_clear_timeout_source: (h: any) => void;
|
|
455
|
+
_timeout_handle: number | undefined;
|
|
456
|
+
_timeout_target: string | undefined;
|
|
457
|
+
_timeout_target_time: number | undefined;
|
|
458
|
+
constructor({ start_states, end_states, initial_state, start_states_no_enforce, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override, rng_seed, time_source, timeout_source, clear_timeout_source }: JssmGenericConfig<StateType, mDT>);
|
|
459
|
+
/********
|
|
460
|
+
*
|
|
461
|
+
* Internal method for fabricating states. Not meant for external use.
|
|
462
|
+
*
|
|
463
|
+
* @internal
|
|
464
|
+
*
|
|
465
|
+
*/
|
|
466
|
+
_new_state(state_config: JssmGenericState): StateType;
|
|
467
|
+
/*********
|
|
468
|
+
*
|
|
469
|
+
* Get the current state of a machine.
|
|
470
|
+
*
|
|
471
|
+
* ```typescript
|
|
472
|
+
* import * as jssm from 'jssm';
|
|
473
|
+
*
|
|
474
|
+
* const lswitch = jssm.from('on <=> off;');
|
|
475
|
+
* console.log( lswitch.state() ); // 'on'
|
|
476
|
+
*
|
|
477
|
+
* lswitch.transition('off');
|
|
478
|
+
* console.log( lswitch.state() ); // 'off'
|
|
479
|
+
* ```
|
|
480
|
+
*
|
|
481
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
482
|
+
*
|
|
483
|
+
* @returns The current state name.
|
|
484
|
+
*
|
|
485
|
+
*/
|
|
486
|
+
state(): StateType;
|
|
487
|
+
/*********
|
|
488
|
+
*
|
|
489
|
+
* Get the label for a given state, if any; return `undefined` otherwise.
|
|
490
|
+
*
|
|
491
|
+
* ```typescript
|
|
492
|
+
* import * as jssm from 'jssm';
|
|
493
|
+
*
|
|
494
|
+
* const lswitch = jssm.from('a -> b; state a: { label: "Foo!"; };');
|
|
495
|
+
* console.log( lswitch.label_for('a') ); // 'Foo!'
|
|
496
|
+
* console.log( lswitch.label_for('b') ); // undefined
|
|
497
|
+
* ```
|
|
498
|
+
*
|
|
499
|
+
* See also {@link display_text}.
|
|
500
|
+
*
|
|
501
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
502
|
+
*
|
|
503
|
+
* @param state The state to get the label for.
|
|
504
|
+
*
|
|
505
|
+
* @returns The label string, or `undefined` if no label is set.
|
|
506
|
+
*
|
|
507
|
+
*/
|
|
508
|
+
label_for(state: StateType): string;
|
|
509
|
+
/*********
|
|
510
|
+
*
|
|
511
|
+
* Get whatever the node should show as text.
|
|
512
|
+
*
|
|
513
|
+
* Currently, this means to get the label for a given state, if any;
|
|
514
|
+
* otherwise to return the node's name. However, this definition is expected
|
|
515
|
+
* to grow with time, and it is currently considered ill-advised to manually
|
|
516
|
+
* parse this text.
|
|
517
|
+
*
|
|
518
|
+
* See also {@link label_for}.
|
|
519
|
+
*
|
|
520
|
+
* ```typescript
|
|
521
|
+
* import * as jssm from 'jssm';
|
|
522
|
+
*
|
|
523
|
+
* const lswitch = jssm.from('a -> b; state a: { label: "Foo!"; };');
|
|
524
|
+
* console.log( lswitch.display_text('a') ); // 'Foo!'
|
|
525
|
+
* console.log( lswitch.display_text('b') ); // 'b'
|
|
526
|
+
* ```
|
|
527
|
+
*
|
|
528
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
529
|
+
*
|
|
530
|
+
* @param state The state to get display text for.
|
|
531
|
+
*
|
|
532
|
+
* @returns The label if one exists, otherwise the state's name.
|
|
533
|
+
*
|
|
534
|
+
*/
|
|
535
|
+
display_text(state: StateType): string;
|
|
536
|
+
/*********
|
|
537
|
+
*
|
|
538
|
+
* Get the current data of a machine.
|
|
539
|
+
*
|
|
540
|
+
* ```typescript
|
|
541
|
+
* import * as jssm from 'jssm';
|
|
542
|
+
*
|
|
543
|
+
* const lswitch = jssm.from('on <=> off;', {data: 1});
|
|
544
|
+
* console.log( lswitch.data() ); // 1
|
|
545
|
+
* ```
|
|
546
|
+
*
|
|
547
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
548
|
+
*
|
|
549
|
+
* @returns A deep clone of the machine's current data value.
|
|
550
|
+
*
|
|
551
|
+
*/
|
|
552
|
+
data(): mDT;
|
|
553
|
+
/*********
|
|
554
|
+
*
|
|
555
|
+
* Get the current value of a given property name. Checks the current
|
|
556
|
+
* state's properties first, then falls back to the global default.
|
|
557
|
+
* Returns `undefined` if neither exists. For a throwing variant, see
|
|
558
|
+
* {@link strict_prop}.
|
|
559
|
+
*
|
|
560
|
+
* ```typescript
|
|
561
|
+
* const m = sm`property color default "grey"; a -> b;
|
|
562
|
+
* state b: { property color "blue"; };`;
|
|
563
|
+
*
|
|
564
|
+
* m.prop('color'); // 'grey' (default, because state is 'a')
|
|
565
|
+
* m.go('b');
|
|
566
|
+
* m.prop('color'); // 'blue' (state 'b' overrides the default)
|
|
567
|
+
* m.prop('size'); // undefined (no such property)
|
|
568
|
+
* ```
|
|
569
|
+
*
|
|
570
|
+
* @param name The relevant property name to look up.
|
|
571
|
+
*
|
|
572
|
+
* @returns The value behind the prop name, or `undefined` if not defined.
|
|
573
|
+
*
|
|
574
|
+
*/
|
|
575
|
+
prop(name: string): any;
|
|
576
|
+
/*********
|
|
577
|
+
*
|
|
578
|
+
* Get the current value of a given property name. If missing on the state
|
|
579
|
+
* and without a global default, throws a {@link JssmError}, unlike
|
|
580
|
+
* {@link prop}, which would return `undefined` instead.
|
|
581
|
+
*
|
|
582
|
+
* ```typescript
|
|
583
|
+
* const m = sm`property color default "grey"; a -> b;`;
|
|
584
|
+
*
|
|
585
|
+
* m.strict_prop('color'); // 'grey'
|
|
586
|
+
* m.strict_prop('size'); // throws JssmError
|
|
587
|
+
* ```
|
|
588
|
+
*
|
|
589
|
+
* @param name The relevant property name to look up.
|
|
590
|
+
*
|
|
591
|
+
* @returns The value behind the prop name.
|
|
592
|
+
*
|
|
593
|
+
* @throws {JssmError} If the property is not defined on the current state
|
|
594
|
+
* and has no default.
|
|
595
|
+
*
|
|
596
|
+
*/
|
|
597
|
+
strict_prop(name: string): any;
|
|
598
|
+
/*********
|
|
599
|
+
*
|
|
600
|
+
* Get the current value of every prop, as an object. If no current definition
|
|
601
|
+
* exists for a prop — that is, if the prop was defined without a default and
|
|
602
|
+
* the current state also doesn't define the prop — then that prop will be listed
|
|
603
|
+
* in the returned object with a value of `undefined`.
|
|
604
|
+
*
|
|
605
|
+
* ```typescript
|
|
606
|
+
* const traffic_light = sm`
|
|
607
|
+
*
|
|
608
|
+
* property can_go default true;
|
|
609
|
+
* property hesitate default true;
|
|
610
|
+
* property stop_first default false;
|
|
611
|
+
*
|
|
612
|
+
* Off -> Red => Green => Yellow => Red;
|
|
613
|
+
* [Red Yellow Green] ~> [Off FlashingRed];
|
|
614
|
+
* FlashingRed -> Red;
|
|
615
|
+
*
|
|
616
|
+
* state Red: { property stop_first true; property can_go false; };
|
|
617
|
+
* state Off: { property stop_first true; };
|
|
618
|
+
* state FlashingRed: { property stop_first true; };
|
|
619
|
+
* state Green: { property hesitate false; };
|
|
620
|
+
*
|
|
621
|
+
* `;
|
|
622
|
+
*
|
|
623
|
+
* traffic_light.state(); // Off
|
|
624
|
+
* traffic_light.props(); // { can_go: true, hesitate: true, stop_first: true; }
|
|
625
|
+
*
|
|
626
|
+
* traffic_light.go('Red');
|
|
627
|
+
* traffic_light.props(); // { can_go: false, hesitate: true, stop_first: true; }
|
|
628
|
+
*
|
|
629
|
+
* traffic_light.go('Green');
|
|
630
|
+
* traffic_light.props(); // { can_go: true, hesitate: false, stop_first: false; }
|
|
631
|
+
* ```
|
|
632
|
+
*
|
|
633
|
+
* @returns An object mapping every known property name to its current value
|
|
634
|
+
* (or `undefined` if the property has no default and the current state
|
|
635
|
+
* doesn't define it).
|
|
636
|
+
*
|
|
637
|
+
*/
|
|
638
|
+
props(): object;
|
|
639
|
+
/*********
|
|
640
|
+
*
|
|
641
|
+
* Check whether a given string is a known property's name.
|
|
642
|
+
*
|
|
643
|
+
* ```typescript
|
|
644
|
+
* const example = sm`property foo default 1; a->b;`;
|
|
645
|
+
*
|
|
646
|
+
* example.known_prop('foo'); // true
|
|
647
|
+
* example.known_prop('bar'); // false
|
|
648
|
+
* ```
|
|
649
|
+
*
|
|
650
|
+
* @param prop_name The relevant property name to look up
|
|
651
|
+
*
|
|
652
|
+
*/
|
|
653
|
+
known_prop(prop_name: string): boolean;
|
|
654
|
+
/*********
|
|
655
|
+
*
|
|
656
|
+
* List all known property names. If you'd also like values, use
|
|
657
|
+
* {@link props} instead. The order of the properties is not defined, and
|
|
658
|
+
* the properties generally will not be sorted.
|
|
659
|
+
*
|
|
660
|
+
* ```typescript
|
|
661
|
+
* const m = sm`property color default "grey"; property size default 1; a -> b;`;
|
|
662
|
+
*
|
|
663
|
+
* m.known_props(); // ['color', 'size']
|
|
664
|
+
* ```
|
|
665
|
+
*
|
|
666
|
+
* @returns An array of all property name strings defined on this machine.
|
|
667
|
+
*
|
|
668
|
+
*/
|
|
669
|
+
known_props(): string[];
|
|
670
|
+
/********
|
|
671
|
+
*
|
|
672
|
+
* Check whether a given state is a valid start state (either because it was
|
|
673
|
+
* explicitly named as such, or because it was the first mentioned state.)
|
|
674
|
+
*
|
|
675
|
+
* ```typescript
|
|
676
|
+
* import { sm, is_start_state } from 'jssm';
|
|
677
|
+
*
|
|
678
|
+
* const example = sm`a -> b;`;
|
|
679
|
+
*
|
|
680
|
+
* console.log( final_test.is_start_state('a') ); // true
|
|
681
|
+
* console.log( final_test.is_start_state('b') ); // false
|
|
682
|
+
*
|
|
683
|
+
* const example = sm`start_states: [a b]; a -> b;`;
|
|
684
|
+
*
|
|
685
|
+
* console.log( final_test.is_start_state('a') ); // true
|
|
686
|
+
* console.log( final_test.is_start_state('b') ); // true
|
|
687
|
+
* ```
|
|
688
|
+
*
|
|
689
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
690
|
+
*
|
|
691
|
+
* @param whichState The name of the state to check
|
|
692
|
+
*
|
|
693
|
+
*/
|
|
694
|
+
is_start_state(whichState: StateType): boolean;
|
|
695
|
+
/********
|
|
696
|
+
*
|
|
697
|
+
* Check whether a given state is a valid start state (either because it was
|
|
698
|
+
* explicitly named as such, or because it was the first mentioned state.)
|
|
699
|
+
*
|
|
700
|
+
* ```typescript
|
|
701
|
+
* import { sm, is_end_state } from 'jssm';
|
|
702
|
+
*
|
|
703
|
+
* const example = sm`a -> b;`;
|
|
704
|
+
*
|
|
705
|
+
* console.log( final_test.is_start_state('a') ); // false
|
|
706
|
+
* console.log( final_test.is_start_state('b') ); // true
|
|
707
|
+
*
|
|
708
|
+
* const example = sm`end_states: [a b]; a -> b;`;
|
|
709
|
+
*
|
|
710
|
+
* console.log( final_test.is_start_state('a') ); // true
|
|
711
|
+
* console.log( final_test.is_start_state('b') ); // true
|
|
712
|
+
* ```
|
|
713
|
+
*
|
|
714
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
715
|
+
*
|
|
716
|
+
* @param whichState The name of the state to check
|
|
717
|
+
*
|
|
718
|
+
*/
|
|
719
|
+
is_end_state(whichState: StateType): boolean;
|
|
720
|
+
/********
|
|
721
|
+
*
|
|
722
|
+
* Check whether a given state is final (either has no exits or is marked
|
|
723
|
+
* `complete`.)
|
|
724
|
+
*
|
|
725
|
+
* ```typescript
|
|
726
|
+
* import { sm, state_is_final } from 'jssm';
|
|
727
|
+
*
|
|
728
|
+
* const final_test = sm`first -> second;`;
|
|
729
|
+
*
|
|
730
|
+
* console.log( final_test.state_is_final('first') ); // false
|
|
731
|
+
* console.log( final_test.state_is_final('second') ); // true
|
|
732
|
+
* ```
|
|
733
|
+
*
|
|
734
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
735
|
+
*
|
|
736
|
+
* @param whichState The name of the state to check for finality
|
|
737
|
+
*
|
|
738
|
+
*/
|
|
739
|
+
state_is_final(whichState: StateType): boolean;
|
|
740
|
+
/********
|
|
741
|
+
*
|
|
742
|
+
* Check whether the current state is final (either has no exits or is marked
|
|
743
|
+
* `complete`.)
|
|
744
|
+
*
|
|
745
|
+
* ```typescript
|
|
746
|
+
* import { sm, is_final } from 'jssm';
|
|
747
|
+
*
|
|
748
|
+
* const final_test = sm`first -> second;`;
|
|
749
|
+
*
|
|
750
|
+
* console.log( final_test.is_final() ); // false
|
|
751
|
+
* state.transition('second');
|
|
752
|
+
* console.log( final_test.is_final() ); // true
|
|
753
|
+
* ```
|
|
754
|
+
*
|
|
755
|
+
*/
|
|
756
|
+
is_final(): boolean;
|
|
757
|
+
/********
|
|
758
|
+
*
|
|
759
|
+
* Serialize the current machine, including all defining state but not the
|
|
760
|
+
* machine string, to a structure. This means you will need the machine
|
|
761
|
+
* string to recreate (to not waste repeated space;) if you want the machine
|
|
762
|
+
* string embedded, call {@link serialize_with_string} instead.
|
|
763
|
+
*
|
|
764
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
765
|
+
*
|
|
766
|
+
* @param comment An optional comment string to embed in the serialized
|
|
767
|
+
* output for identification or debugging.
|
|
768
|
+
*
|
|
769
|
+
* @returns A {@link JssmSerialization} object containing the machine's
|
|
770
|
+
* current state, data, and timestamp.
|
|
771
|
+
*
|
|
772
|
+
*/
|
|
773
|
+
serialize(comment?: string | undefined): JssmSerialization<mDT>;
|
|
774
|
+
/** Get the graph layout direction (e.g. `'LR'`, `'TB'`). Set via the
|
|
775
|
+
* FSL `graph_layout` directive.
|
|
776
|
+
* @returns The layout string, or the default if not set.
|
|
777
|
+
*/
|
|
778
|
+
graph_layout(): string;
|
|
779
|
+
/** Get the Graphviz DOT preamble string, injected before the graph body
|
|
780
|
+
* during visualization. Set via the FSL `dot_preamble` directive.
|
|
781
|
+
* @returns The preamble string.
|
|
782
|
+
*/
|
|
783
|
+
dot_preamble(): string;
|
|
784
|
+
/** Get the machine's author list. Set via the FSL `machine_author` directive.
|
|
785
|
+
* @returns An array of author name strings.
|
|
786
|
+
*/
|
|
787
|
+
machine_author(): Array<string>;
|
|
788
|
+
/** Get the machine's comment string. Set via the FSL `machine_comment` directive.
|
|
789
|
+
* @returns The comment string.
|
|
790
|
+
*/
|
|
791
|
+
machine_comment(): string;
|
|
792
|
+
/** Get the machine's contributor list. Set via the FSL `machine_contributor` directive.
|
|
793
|
+
* @returns An array of contributor name strings.
|
|
794
|
+
*/
|
|
795
|
+
machine_contributor(): Array<string>;
|
|
796
|
+
/** Get the machine's definition string. Set via the FSL `machine_definition` directive.
|
|
797
|
+
* @returns The definition string.
|
|
798
|
+
*/
|
|
799
|
+
machine_definition(): string;
|
|
800
|
+
/** Get the machine's language (ISO 639-1). Set via the FSL `machine_language` directive.
|
|
801
|
+
* @returns The language code string.
|
|
802
|
+
*/
|
|
803
|
+
machine_language(): string;
|
|
804
|
+
/** Get the machine's license string. Set via the FSL `machine_license` directive.
|
|
805
|
+
* @returns The license string.
|
|
806
|
+
*/
|
|
807
|
+
machine_license(): string;
|
|
808
|
+
/** Get the machine's name. Set via the FSL `machine_name` directive.
|
|
809
|
+
* @returns The machine name string.
|
|
810
|
+
*/
|
|
811
|
+
machine_name(): string;
|
|
812
|
+
/** Get the machine's version string. Set via the FSL `machine_version` directive.
|
|
813
|
+
* @returns The version string.
|
|
814
|
+
*/
|
|
815
|
+
machine_version(): string;
|
|
816
|
+
/** Get the raw state declaration objects as parsed from the FSL source.
|
|
817
|
+
* @returns An array of raw state declaration objects.
|
|
818
|
+
*/
|
|
819
|
+
raw_state_declarations(): Array<Object>;
|
|
820
|
+
/** Get the processed state declaration for a specific state.
|
|
821
|
+
* @param which - The state to look up.
|
|
822
|
+
* @returns The {@link JssmStateDeclaration} for the given state.
|
|
823
|
+
*/
|
|
824
|
+
state_declaration(which: StateType): JssmStateDeclaration;
|
|
825
|
+
/** Get all processed state declarations as a Map.
|
|
826
|
+
* @returns A `Map` from state name to {@link JssmStateDeclaration}.
|
|
827
|
+
*/
|
|
828
|
+
state_declarations(): Map<StateType, JssmStateDeclaration>;
|
|
829
|
+
/** Get the FSL language version this machine was compiled under.
|
|
830
|
+
* @returns The FSL version string.
|
|
831
|
+
*/
|
|
832
|
+
fsl_version(): string;
|
|
833
|
+
/** Get the complete internal state of the machine as a serializable
|
|
834
|
+
* structure. Includes actions, edges, edge map, named transitions,
|
|
835
|
+
* reverse actions, current state, and states map.
|
|
836
|
+
* @returns A {@link JssmMachineInternalState} snapshot.
|
|
837
|
+
*/
|
|
838
|
+
machine_state(): JssmMachineInternalState<mDT>;
|
|
839
|
+
/*********
|
|
840
|
+
*
|
|
841
|
+
* List all the states known by the machine. Please note that the order of
|
|
842
|
+
* these states is not guaranteed.
|
|
843
|
+
*
|
|
844
|
+
* ```typescript
|
|
845
|
+
* import * as jssm from 'jssm';
|
|
846
|
+
*
|
|
847
|
+
* const lswitch = jssm.from('on <=> off;');
|
|
848
|
+
* console.log( lswitch.states() ); // ['on', 'off']
|
|
849
|
+
* ```
|
|
850
|
+
*
|
|
851
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
852
|
+
*
|
|
853
|
+
* @returns An array of all state names in the machine.
|
|
854
|
+
*
|
|
855
|
+
*/
|
|
856
|
+
states(): Array<StateType>;
|
|
857
|
+
/** Get the internal state descriptor for a given state name.
|
|
858
|
+
* @param whichState - The state to look up.
|
|
859
|
+
* @returns The {@link JssmGenericState} descriptor.
|
|
860
|
+
* @throws {JssmError} If the state does not exist.
|
|
861
|
+
*/
|
|
862
|
+
state_for(whichState: StateType): JssmGenericState;
|
|
863
|
+
/*********
|
|
864
|
+
*
|
|
865
|
+
* Check whether the machine knows a given state.
|
|
866
|
+
*
|
|
867
|
+
* ```typescript
|
|
868
|
+
* import * as jssm from 'jssm';
|
|
869
|
+
*
|
|
870
|
+
* const lswitch = jssm.from('on <=> off;');
|
|
871
|
+
*
|
|
872
|
+
* console.log( lswitch.has_state('off') ); // true
|
|
873
|
+
* console.log( lswitch.has_state('dance') ); // false
|
|
874
|
+
* ```
|
|
875
|
+
*
|
|
876
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
877
|
+
*
|
|
878
|
+
* @param whichState The state to be checked for existence.
|
|
879
|
+
*
|
|
880
|
+
* @returns `true` if the state exists, `false` otherwise.
|
|
881
|
+
*
|
|
882
|
+
*/
|
|
883
|
+
has_state(whichState: StateType): boolean;
|
|
884
|
+
/*********
|
|
885
|
+
*
|
|
886
|
+
* Lists all edges of a machine.
|
|
887
|
+
*
|
|
888
|
+
* ```typescript
|
|
889
|
+
* import { sm } from 'jssm';
|
|
890
|
+
*
|
|
891
|
+
* const lswitch = sm`on 'toggle' <=> 'toggle' off;`;
|
|
892
|
+
*
|
|
893
|
+
* lswitch.list_edges();
|
|
894
|
+
* [
|
|
895
|
+
* {
|
|
896
|
+
* from: 'on',
|
|
897
|
+
* to: 'off',
|
|
898
|
+
* kind: 'main',
|
|
899
|
+
* forced_only: false,
|
|
900
|
+
* main_path: true,
|
|
901
|
+
* action: 'toggle'
|
|
902
|
+
* },
|
|
903
|
+
* {
|
|
904
|
+
* from: 'off',
|
|
905
|
+
* to: 'on',
|
|
906
|
+
* kind: 'main',
|
|
907
|
+
* forced_only: false,
|
|
908
|
+
* main_path: true,
|
|
909
|
+
* action: 'toggle'
|
|
910
|
+
* }
|
|
911
|
+
* ]
|
|
912
|
+
* ```
|
|
913
|
+
*
|
|
914
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
915
|
+
*
|
|
916
|
+
* @returns An array of all {@link JssmTransition} edge objects.
|
|
917
|
+
*
|
|
918
|
+
*/
|
|
919
|
+
list_edges(): Array<JssmTransition<StateType, mDT>>;
|
|
920
|
+
/** Get the map of named transitions (transitions with explicit names).
|
|
921
|
+
* @returns A `Map` from transition name to edge index.
|
|
922
|
+
*/
|
|
923
|
+
list_named_transitions(): Map<StateType, number>;
|
|
924
|
+
/** List all distinct action names defined anywhere in the machine.
|
|
925
|
+
* @returns An array of action name strings.
|
|
926
|
+
*/
|
|
927
|
+
list_actions(): Array<StateType>;
|
|
928
|
+
/** Whether any actions are defined on this machine.
|
|
929
|
+
* @returns `true` if the machine has at least one action.
|
|
930
|
+
*/
|
|
931
|
+
get uses_actions(): boolean;
|
|
932
|
+
/** Whether any forced (`~>`) transitions exist in this machine.
|
|
933
|
+
* @returns `true` if at least one forced transition is defined.
|
|
934
|
+
*/
|
|
935
|
+
get uses_forced_transitions(): boolean;
|
|
936
|
+
/*********
|
|
937
|
+
*
|
|
938
|
+
* Check if the code that built the machine allows overriding state and data.
|
|
939
|
+
*
|
|
940
|
+
* @returns The override permission from the FSL source code.
|
|
941
|
+
*
|
|
942
|
+
*/
|
|
943
|
+
get code_allows_override(): JssmAllowsOverride;
|
|
944
|
+
/*********
|
|
945
|
+
*
|
|
946
|
+
* Check if the machine config allows overriding state and data.
|
|
947
|
+
*
|
|
948
|
+
* @returns The override permission from the runtime config.
|
|
949
|
+
*
|
|
950
|
+
*/
|
|
951
|
+
get config_allows_override(): JssmAllowsOverride;
|
|
952
|
+
/*********
|
|
953
|
+
*
|
|
954
|
+
* Check if a machine allows overriding state and data. Resolves the
|
|
955
|
+
* combined effect of code and config permissions — config may not be
|
|
956
|
+
* less strict than code.
|
|
957
|
+
*
|
|
958
|
+
* @returns The effective override permission.
|
|
959
|
+
*
|
|
960
|
+
*/
|
|
961
|
+
get allows_override(): JssmAllowsOverride;
|
|
962
|
+
/** List all available theme names.
|
|
963
|
+
* @returns An array of theme name strings.
|
|
964
|
+
*/
|
|
965
|
+
all_themes(): FslTheme[];
|
|
966
|
+
/** Get the active theme(s) for this machine. Always stored as an array
|
|
967
|
+
* internally; the union return type exists for setter compatibility.
|
|
968
|
+
* @returns The current theme or array of themes.
|
|
969
|
+
*/
|
|
970
|
+
get themes(): FslTheme | FslTheme[];
|
|
971
|
+
/** Set the active theme(s). Accepts a single theme name or an array.
|
|
972
|
+
* @param to - A theme name or array of theme names to apply.
|
|
973
|
+
*/
|
|
974
|
+
set themes(to: FslTheme | FslTheme[]);
|
|
975
|
+
/** Get the flow direction for graph layout (e.g. `'right'`, `'down'`).
|
|
976
|
+
* Set via the FSL `flow` directive.
|
|
977
|
+
* @returns The current flow direction.
|
|
978
|
+
*/
|
|
979
|
+
flow(): FslDirection;
|
|
980
|
+
/** Look up a transition's edge index by source and target state names.
|
|
981
|
+
* @param from - Source state name.
|
|
982
|
+
* @param to - Target state name.
|
|
983
|
+
* @returns The edge index in the edges array, or `undefined` if no
|
|
984
|
+
* such transition exists.
|
|
985
|
+
*/
|
|
986
|
+
get_transition_by_state_names(from: StateType, to: StateType): number;
|
|
987
|
+
/** Look up the full transition object for a given source→target pair.
|
|
988
|
+
* @param from - Source state name.
|
|
989
|
+
* @param to - Target state name.
|
|
990
|
+
* @returns The {@link JssmTransition} object, or `undefined` if none exists.
|
|
991
|
+
*/
|
|
992
|
+
lookup_transition_for(from: StateType, to: StateType): JssmTransition<StateType, mDT>;
|
|
993
|
+
/********
|
|
994
|
+
*
|
|
995
|
+
* List all transitions attached to the current state, sorted by entrance and
|
|
996
|
+
* exit. The order of each sublist is not defined. A node could appear in
|
|
997
|
+
* both lists.
|
|
998
|
+
*
|
|
999
|
+
* ```typescript
|
|
1000
|
+
* import { sm } from 'jssm';
|
|
1001
|
+
*
|
|
1002
|
+
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
|
|
1003
|
+
*
|
|
1004
|
+
* light.state(); // 'red'
|
|
1005
|
+
* light.list_transitions(); // { entrances: [ 'yellow', 'off' ], exits: [ 'green', 'off' ] }
|
|
1006
|
+
* ```
|
|
1007
|
+
*
|
|
1008
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1009
|
+
*
|
|
1010
|
+
* @param whichState The state whose transitions to have listed
|
|
1011
|
+
*
|
|
1012
|
+
*/
|
|
1013
|
+
list_transitions(whichState?: StateType): JssmTransitionList;
|
|
1014
|
+
/********
|
|
1015
|
+
*
|
|
1016
|
+
* List all entrances attached to the current state. Please note that the
|
|
1017
|
+
* order of the list is not defined. This list includes both unforced and
|
|
1018
|
+
* forced entrances; if this isn't desired, consider
|
|
1019
|
+
* {@link list_unforced_entrances} or {@link list_forced_entrances} as
|
|
1020
|
+
* appropriate.
|
|
1021
|
+
*
|
|
1022
|
+
* ```typescript
|
|
1023
|
+
* import { sm } from 'jssm';
|
|
1024
|
+
*
|
|
1025
|
+
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
|
|
1026
|
+
*
|
|
1027
|
+
* light.state(); // 'red'
|
|
1028
|
+
* light.list_entrances(); // [ 'yellow', 'off' ]
|
|
1029
|
+
* ```
|
|
1030
|
+
*
|
|
1031
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1032
|
+
*
|
|
1033
|
+
* @param whichState The state whose entrances to have listed
|
|
1034
|
+
*
|
|
1035
|
+
*/
|
|
1036
|
+
list_entrances(whichState?: StateType): Array<StateType>;
|
|
1037
|
+
/********
|
|
1038
|
+
*
|
|
1039
|
+
* List all exits attached to the current state. Please note that the order
|
|
1040
|
+
* of the list is not defined. This list includes both unforced and forced
|
|
1041
|
+
* exits; if this isn't desired, consider {@link list_unforced_exits} or
|
|
1042
|
+
* {@link list_forced_exits} as appropriate.
|
|
1043
|
+
*
|
|
1044
|
+
* ```typescript
|
|
1045
|
+
* import { sm } from 'jssm';
|
|
1046
|
+
*
|
|
1047
|
+
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
|
|
1048
|
+
*
|
|
1049
|
+
* light.state(); // 'red'
|
|
1050
|
+
* light.list_exits(); // [ 'green', 'off' ]
|
|
1051
|
+
* ```
|
|
1052
|
+
*
|
|
1053
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1054
|
+
*
|
|
1055
|
+
* @param whichState The state whose exits to have listed
|
|
1056
|
+
*
|
|
1057
|
+
*/
|
|
1058
|
+
list_exits(whichState?: StateType): Array<StateType>;
|
|
1059
|
+
/** Get the transitions available from a state, filtered to those with
|
|
1060
|
+
* probability data. Used by the probabilistic walk system.
|
|
1061
|
+
* @param whichState - The state to inspect.
|
|
1062
|
+
* @returns An array of {@link JssmTransition} edges exiting the state.
|
|
1063
|
+
* @throws {JssmError} If the state does not exist.
|
|
1064
|
+
*/
|
|
1065
|
+
probable_exits_for(whichState: StateType): Array<JssmTransition<StateType, mDT>>;
|
|
1066
|
+
/** Take a single random transition from the current state, weighted by
|
|
1067
|
+
* edge probabilities.
|
|
1068
|
+
* @returns `true` if a transition was taken, `false` otherwise.
|
|
1069
|
+
*/
|
|
1070
|
+
probabilistic_transition(): boolean;
|
|
1071
|
+
/** Take `n` consecutive probabilistic transitions and return the sequence
|
|
1072
|
+
* of states visited (before each transition).
|
|
1073
|
+
* @param n - Number of steps to walk.
|
|
1074
|
+
* @returns An array of state names visited during the walk.
|
|
1075
|
+
*/
|
|
1076
|
+
probabilistic_walk(n: number): Array<StateType>;
|
|
1077
|
+
/** Take `n` probabilistic steps and return a histograph of how many times
|
|
1078
|
+
* each state was visited.
|
|
1079
|
+
* @param n - Number of steps to walk.
|
|
1080
|
+
* @returns A `Map` from state name to visit count.
|
|
1081
|
+
*/
|
|
1082
|
+
probabilistic_histo_walk(n: number): Map<StateType, number>;
|
|
1083
|
+
/********
|
|
1084
|
+
*
|
|
1085
|
+
* List all actions available from this state. Please note that the order of
|
|
1086
|
+
* the actions is not guaranteed.
|
|
1087
|
+
*
|
|
1088
|
+
* ```typescript
|
|
1089
|
+
* import { sm } from 'jssm';
|
|
1090
|
+
*
|
|
1091
|
+
* const machine = sm`
|
|
1092
|
+
* red 'next' -> green 'next' -> yellow 'next' -> red;
|
|
1093
|
+
* [red yellow green] 'shutdown' ~> off 'start' -> red;
|
|
1094
|
+
* `;
|
|
1095
|
+
*
|
|
1096
|
+
* console.log( machine.state() ); // logs 'red'
|
|
1097
|
+
* console.log( machine.actions() ); // logs ['next', 'shutdown']
|
|
1098
|
+
*
|
|
1099
|
+
* machine.action('next'); // true
|
|
1100
|
+
* console.log( machine.state() ); // logs 'green'
|
|
1101
|
+
* console.log( machine.actions() ); // logs ['next', 'shutdown']
|
|
1102
|
+
*
|
|
1103
|
+
* machine.action('shutdown'); // true
|
|
1104
|
+
* console.log( machine.state() ); // logs 'off'
|
|
1105
|
+
* console.log( machine.actions() ); // logs ['start']
|
|
1106
|
+
*
|
|
1107
|
+
* machine.action('start'); // true
|
|
1108
|
+
* console.log( machine.state() ); // logs 'red'
|
|
1109
|
+
* console.log( machine.actions() ); // logs ['next', 'shutdown']
|
|
1110
|
+
* ```
|
|
1111
|
+
*
|
|
1112
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1113
|
+
*
|
|
1114
|
+
* @param whichState The state whose actions to list. Defaults to the
|
|
1115
|
+
* current state.
|
|
1116
|
+
*
|
|
1117
|
+
* @returns An array of action names available from the given state.
|
|
1118
|
+
*
|
|
1119
|
+
*/
|
|
1120
|
+
actions(whichState?: StateType): Array<StateType>;
|
|
1121
|
+
/********
|
|
1122
|
+
*
|
|
1123
|
+
* List all states that have a specific action attached. Please note that
|
|
1124
|
+
* the order of the states is not guaranteed.
|
|
1125
|
+
*
|
|
1126
|
+
* ```typescript
|
|
1127
|
+
* import { sm } from 'jssm';
|
|
1128
|
+
*
|
|
1129
|
+
* const machine = sm`
|
|
1130
|
+
* red 'next' -> green 'next' -> yellow 'next' -> red;
|
|
1131
|
+
* [red yellow green] 'shutdown' ~> off 'start' -> red;
|
|
1132
|
+
* `;
|
|
1133
|
+
*
|
|
1134
|
+
* console.log( machine.list_states_having_action('next') ); // ['red', 'green', 'yellow']
|
|
1135
|
+
* console.log( machine.list_states_having_action('start') ); // ['off']
|
|
1136
|
+
* ```
|
|
1137
|
+
*
|
|
1138
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1139
|
+
*
|
|
1140
|
+
* @param whichState The action to be checked for associated states
|
|
1141
|
+
*
|
|
1142
|
+
*/
|
|
1143
|
+
list_states_having_action(whichState: StateType): Array<StateType>;
|
|
1144
|
+
/** List all action names available as exits from a given state.
|
|
1145
|
+
* @param whichState - The state to inspect. Defaults to the current state.
|
|
1146
|
+
* @returns An array of action name strings.
|
|
1147
|
+
* @throws {JssmError} If the state does not exist.
|
|
1148
|
+
*/
|
|
1149
|
+
list_exit_actions(whichState?: StateType): Array<StateType>;
|
|
1150
|
+
/** List all action exits from a state with their probabilities.
|
|
1151
|
+
* @param whichState - The state to inspect. Defaults to the current state.
|
|
1152
|
+
* @returns An array of `{ action, probability }` objects.
|
|
1153
|
+
* @throws {JssmError} If the state does not exist.
|
|
1154
|
+
*/
|
|
1155
|
+
probable_action_exits(whichState?: StateType): Array<any>;
|
|
1156
|
+
/** Check whether a state has no incoming transitions (unreachable after start).
|
|
1157
|
+
* @param whichState - The state to check.
|
|
1158
|
+
* @returns `true` if the state has zero entrances.
|
|
1159
|
+
* @throws {JssmError} If the state does not exist.
|
|
1160
|
+
*/
|
|
1161
|
+
is_unenterable(whichState: StateType): boolean;
|
|
1162
|
+
/** Check whether any state in the machine is unenterable.
|
|
1163
|
+
* @returns `true` if at least one state has no incoming transitions.
|
|
1164
|
+
*/
|
|
1165
|
+
has_unenterables(): boolean;
|
|
1166
|
+
/** Check whether the current state is terminal (has no exits).
|
|
1167
|
+
* @returns `true` if the current state has zero exits.
|
|
1168
|
+
*/
|
|
1169
|
+
is_terminal(): boolean;
|
|
1170
|
+
/** Check whether a specific state is terminal (has no exits).
|
|
1171
|
+
* @param whichState - The state to check.
|
|
1172
|
+
* @returns `true` if the state has zero exits.
|
|
1173
|
+
* @throws {JssmError} If the state does not exist.
|
|
1174
|
+
*/
|
|
1175
|
+
state_is_terminal(whichState: StateType): boolean;
|
|
1176
|
+
/** Check whether any state in the machine is terminal.
|
|
1177
|
+
* @returns `true` if at least one state has no exits.
|
|
1178
|
+
*/
|
|
1179
|
+
has_terminals(): boolean;
|
|
1180
|
+
/** Check whether the current state is complete (every exit has an action).
|
|
1181
|
+
* @returns `true` if the current state is complete.
|
|
1182
|
+
*/
|
|
1183
|
+
is_complete(): boolean;
|
|
1184
|
+
/** Check whether a specific state is complete (every exit has an action).
|
|
1185
|
+
* @param whichState - The state to check.
|
|
1186
|
+
* @returns `true` if the state is complete.
|
|
1187
|
+
* @throws {JssmError} If the state does not exist.
|
|
1188
|
+
*/
|
|
1189
|
+
state_is_complete(whichState: StateType): boolean;
|
|
1190
|
+
/** Check whether any state in the machine is complete.
|
|
1191
|
+
* @returns `true` if at least one state is complete.
|
|
1192
|
+
*/
|
|
1193
|
+
has_completes(): boolean;
|
|
1194
|
+
/** Low-level hook registration. Installs a handler described by a
|
|
1195
|
+
* {@link HookDescription} into the appropriate internal map. Prefer the
|
|
1196
|
+
* convenience wrappers ({@link hook}, {@link hook_entry}, etc.) over
|
|
1197
|
+
* calling this directly.
|
|
1198
|
+
* @param HookDesc - A hook descriptor specifying kind, states, and handler.
|
|
1199
|
+
*/
|
|
1200
|
+
set_hook(HookDesc: HookDescription<mDT>): void;
|
|
1201
|
+
/** Register a pre-transition hook on a specific edge. Fires before
|
|
1202
|
+
* transitioning from `from` to `to`. If the handler returns `false`, the
|
|
1203
|
+
* transition is blocked.
|
|
1204
|
+
*
|
|
1205
|
+
* ```typescript
|
|
1206
|
+
* const m = sm`a -> b -> c;`;
|
|
1207
|
+
* m.hook('a', 'b', () => console.log('a->b'));
|
|
1208
|
+
* ```
|
|
1209
|
+
*
|
|
1210
|
+
* @param from - Source state name.
|
|
1211
|
+
* @param to - Target state name.
|
|
1212
|
+
* @param handler - Callback invoked before the transition.
|
|
1213
|
+
* @returns `this` for chaining.
|
|
1214
|
+
*/
|
|
1215
|
+
hook(from: string, to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1216
|
+
/** Register a pre-transition hook on a specific action-labeled edge.
|
|
1217
|
+
* @param from - Source state name.
|
|
1218
|
+
* @param to - Target state name.
|
|
1219
|
+
* @param action - The action label that triggers this hook.
|
|
1220
|
+
* @param handler - Callback invoked before the transition.
|
|
1221
|
+
* @returns `this` for chaining.
|
|
1222
|
+
*/
|
|
1223
|
+
hook_action(from: string, to: string, action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1224
|
+
/** Register a pre-transition hook on any edge triggered by a specific action.
|
|
1225
|
+
* @param action - The action name to hook.
|
|
1226
|
+
* @param handler - Callback invoked before any transition with this action.
|
|
1227
|
+
* @returns `this` for chaining.
|
|
1228
|
+
*/
|
|
1229
|
+
hook_global_action(action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1230
|
+
/** Register a pre-transition hook on any action-driven transition.
|
|
1231
|
+
* @param handler - Callback invoked before any action transition.
|
|
1232
|
+
* @returns `this` for chaining.
|
|
1233
|
+
*/
|
|
1234
|
+
hook_any_action(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1235
|
+
/** Register a pre-transition hook on any standard (`->`) transition.
|
|
1236
|
+
* @param handler - Callback invoked before any legal transition.
|
|
1237
|
+
* @returns `this` for chaining.
|
|
1238
|
+
*/
|
|
1239
|
+
hook_standard_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1240
|
+
/** Register a pre-transition hook on any main-path (`=>`) transition.
|
|
1241
|
+
* @param handler - Callback invoked before any main transition.
|
|
1242
|
+
* @returns `this` for chaining.
|
|
1243
|
+
*/
|
|
1244
|
+
hook_main_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1245
|
+
/** Register a pre-transition hook on any forced (`~>`) transition.
|
|
1246
|
+
* @param handler - Callback invoked before any forced transition.
|
|
1247
|
+
* @returns `this` for chaining.
|
|
1248
|
+
*/
|
|
1249
|
+
hook_forced_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1250
|
+
/** Register a pre-transition hook on any transition regardless of kind.
|
|
1251
|
+
* @param handler - Callback invoked before every transition.
|
|
1252
|
+
* @returns `this` for chaining.
|
|
1253
|
+
*/
|
|
1254
|
+
hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1255
|
+
/** Register a hook that fires when entering a specific state.
|
|
1256
|
+
* @param to - The state being entered.
|
|
1257
|
+
* @param handler - Callback invoked on entry.
|
|
1258
|
+
* @returns `this` for chaining.
|
|
1259
|
+
*/
|
|
1260
|
+
hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1261
|
+
/** Register a hook that fires when leaving a specific state.
|
|
1262
|
+
* @param from - The state being exited.
|
|
1263
|
+
* @param handler - Callback invoked on exit.
|
|
1264
|
+
* @returns `this` for chaining.
|
|
1265
|
+
*/
|
|
1266
|
+
hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1267
|
+
/** Register a hook that fires after leaving a specific state (post-exit).
|
|
1268
|
+
* @param from - The state that was exited.
|
|
1269
|
+
* @param handler - Callback invoked after exit completes.
|
|
1270
|
+
* @returns `this` for chaining.
|
|
1271
|
+
*/
|
|
1272
|
+
hook_after(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1273
|
+
/** Post-transition hook on a specific edge. Fires after the transition
|
|
1274
|
+
* from `from` to `to` has completed. Cannot block the transition.
|
|
1275
|
+
* @param from - Source state name.
|
|
1276
|
+
* @param to - Target state name.
|
|
1277
|
+
* @param handler - Callback invoked after the transition.
|
|
1278
|
+
* @returns `this` for chaining.
|
|
1279
|
+
*/
|
|
1280
|
+
post_hook(from: string, to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1281
|
+
/** Post-transition hook on a specific action-labeled edge.
|
|
1282
|
+
* @param from - Source state name.
|
|
1283
|
+
* @param to - Target state name.
|
|
1284
|
+
* @param action - The action label.
|
|
1285
|
+
* @param handler - Callback invoked after the transition.
|
|
1286
|
+
* @returns `this` for chaining.
|
|
1287
|
+
*/
|
|
1288
|
+
post_hook_action(from: string, to: string, action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1289
|
+
/** Post-transition hook on any edge triggered by a specific action.
|
|
1290
|
+
* @param action - The action name.
|
|
1291
|
+
* @param handler - Callback invoked after any transition with this action.
|
|
1292
|
+
* @returns `this` for chaining.
|
|
1293
|
+
*/
|
|
1294
|
+
post_hook_global_action(action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1295
|
+
/** Post-transition hook on any action-driven transition.
|
|
1296
|
+
* @param handler - Callback invoked after any action transition.
|
|
1297
|
+
* @returns `this` for chaining.
|
|
1298
|
+
*/
|
|
1299
|
+
post_hook_any_action(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1300
|
+
/** Post-transition hook on any standard (`->`) transition.
|
|
1301
|
+
* @param handler - Callback invoked after any legal transition.
|
|
1302
|
+
* @returns `this` for chaining.
|
|
1303
|
+
*/
|
|
1304
|
+
post_hook_standard_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1305
|
+
/** Post-transition hook on any main-path (`=>`) transition.
|
|
1306
|
+
* @param handler - Callback invoked after any main transition.
|
|
1307
|
+
* @returns `this` for chaining.
|
|
1308
|
+
*/
|
|
1309
|
+
post_hook_main_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1310
|
+
/** Post-transition hook on any forced (`~>`) transition.
|
|
1311
|
+
* @param handler - Callback invoked after any forced transition.
|
|
1312
|
+
* @returns `this` for chaining.
|
|
1313
|
+
*/
|
|
1314
|
+
post_hook_forced_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1315
|
+
/** Post-transition hook on any transition regardless of kind.
|
|
1316
|
+
* @param handler - Callback invoked after every transition.
|
|
1317
|
+
* @returns `this` for chaining.
|
|
1318
|
+
*/
|
|
1319
|
+
post_hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1320
|
+
/** Post-transition hook that fires after entering a specific state.
|
|
1321
|
+
* @param to - The state that was entered.
|
|
1322
|
+
* @param handler - Callback invoked after entry.
|
|
1323
|
+
* @returns `this` for chaining.
|
|
1324
|
+
*/
|
|
1325
|
+
post_hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1326
|
+
/** Post-transition hook that fires after leaving a specific state.
|
|
1327
|
+
* @param from - The state that was exited.
|
|
1328
|
+
* @param handler - Callback invoked after exit.
|
|
1329
|
+
* @returns `this` for chaining.
|
|
1330
|
+
*/
|
|
1331
|
+
post_hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1332
|
+
/** Register a pre-transition hook that fires **before** all other pre-hooks
|
|
1333
|
+
* on every transition. If the handler returns `false`, the transition is
|
|
1334
|
+
* blocked. The handler receives an {@link EverythingHookContext} whose
|
|
1335
|
+
* `hook_name` is `'pre everything'`.
|
|
1336
|
+
*
|
|
1337
|
+
* ```typescript
|
|
1338
|
+
* const m = sm`a -> b -> c;`;
|
|
1339
|
+
* m.hook_pre_everything(({ hook_name }) => {
|
|
1340
|
+
* console.log(`${hook_name} fired`);
|
|
1341
|
+
* return true;
|
|
1342
|
+
* });
|
|
1343
|
+
* ```
|
|
1344
|
+
*
|
|
1345
|
+
* @param handler - Callback invoked before all other pre-hooks.
|
|
1346
|
+
* @returns `this` for chaining.
|
|
1347
|
+
*/
|
|
1348
|
+
hook_pre_everything(handler: EverythingHookHandler<mDT>): Machine<mDT>;
|
|
1349
|
+
/** Register a pre-transition hook that fires **after** all other pre-hooks
|
|
1350
|
+
* on every transition. If the handler returns `false`, the transition is
|
|
1351
|
+
* blocked. The handler receives an {@link EverythingHookContext} whose
|
|
1352
|
+
* `hook_name` is `'everything'`.
|
|
1353
|
+
*
|
|
1354
|
+
* ```typescript
|
|
1355
|
+
* const m = sm`a -> b -> c;`;
|
|
1356
|
+
* m.hook_everything(({ hook_name }) => {
|
|
1357
|
+
* console.log(`${hook_name} fired`);
|
|
1358
|
+
* return true;
|
|
1359
|
+
* });
|
|
1360
|
+
* ```
|
|
1361
|
+
*
|
|
1362
|
+
* @param handler - Callback invoked after all other pre-hooks.
|
|
1363
|
+
* @returns `this` for chaining.
|
|
1364
|
+
*/
|
|
1365
|
+
hook_everything(handler: EverythingHookHandler<mDT>): Machine<mDT>;
|
|
1366
|
+
/** Register a post-transition hook that fires **after** all other
|
|
1367
|
+
* post-hooks on every transition. Cannot block the transition. The
|
|
1368
|
+
* handler receives an {@link EverythingHookContext} whose `hook_name` is
|
|
1369
|
+
* `'post everything'`.
|
|
1370
|
+
*
|
|
1371
|
+
* ```typescript
|
|
1372
|
+
* const m = sm`a -> b -> c;`;
|
|
1373
|
+
* m.hook_post_everything(({ hook_name }) => {
|
|
1374
|
+
* console.log(`${hook_name} fired`);
|
|
1375
|
+
* });
|
|
1376
|
+
* ```
|
|
1377
|
+
*
|
|
1378
|
+
* @param handler - Callback invoked after all other post-hooks.
|
|
1379
|
+
* @returns `this` for chaining.
|
|
1380
|
+
*/
|
|
1381
|
+
hook_post_everything(handler: PostEverythingHookHandler<mDT>): Machine<mDT>;
|
|
1382
|
+
/** Register a post-transition hook that fires **before** all other
|
|
1383
|
+
* post-hooks on every transition. Cannot block the transition. The
|
|
1384
|
+
* handler receives an {@link EverythingHookContext} whose `hook_name` is
|
|
1385
|
+
* `'pre post everything'`.
|
|
1386
|
+
*
|
|
1387
|
+
* ```typescript
|
|
1388
|
+
* const m = sm`a -> b -> c;`;
|
|
1389
|
+
* m.hook_pre_post_everything(({ hook_name }) => {
|
|
1390
|
+
* console.log(`${hook_name} fired`);
|
|
1391
|
+
* });
|
|
1392
|
+
* ```
|
|
1393
|
+
*
|
|
1394
|
+
* @param handler - Callback invoked before all other post-hooks.
|
|
1395
|
+
* @returns `this` for chaining.
|
|
1396
|
+
*/
|
|
1397
|
+
hook_pre_post_everything(handler: PostEverythingHookHandler<mDT>): Machine<mDT>;
|
|
1398
|
+
/** Get the current RNG seed used for probabilistic transitions.
|
|
1399
|
+
* @returns The numeric seed value.
|
|
1400
|
+
*/
|
|
1401
|
+
get rng_seed(): number;
|
|
1402
|
+
/** Set the RNG seed. Pass `undefined` to reseed from the current time.
|
|
1403
|
+
* Resets the internal PRNG so subsequent probabilistic operations use the
|
|
1404
|
+
* new seed.
|
|
1405
|
+
* @param to - The seed value, or `undefined` for time-based seeding.
|
|
1406
|
+
*/
|
|
1407
|
+
set rng_seed(to: number | undefined);
|
|
1408
|
+
/** Get all edges between two states (there can be multiple with
|
|
1409
|
+
* different actions).
|
|
1410
|
+
* @param from - Source state name.
|
|
1411
|
+
* @param to - Target state name.
|
|
1412
|
+
* @returns An array of matching {@link JssmTransition} objects.
|
|
1413
|
+
*/
|
|
1414
|
+
edges_between(from: string, to: string): JssmTransition<StateType, mDT>[];
|
|
1415
|
+
/*********
|
|
1416
|
+
*
|
|
1417
|
+
* Replace the current state and data with no regard to the graph.
|
|
1418
|
+
*
|
|
1419
|
+
* ```typescript
|
|
1420
|
+
* import { sm } from 'jssm';
|
|
1421
|
+
*
|
|
1422
|
+
* const machine = sm`a -> b -> c;`;
|
|
1423
|
+
* console.log( machine.state() ); // 'a'
|
|
1424
|
+
*
|
|
1425
|
+
* machine.go('b');
|
|
1426
|
+
* machine.go('c');
|
|
1427
|
+
* console.log( machine.state() ); // 'c'
|
|
1428
|
+
*
|
|
1429
|
+
* machine.override('a');
|
|
1430
|
+
* console.log( machine.state() ); // 'a'
|
|
1431
|
+
* ```
|
|
1432
|
+
*
|
|
1433
|
+
*/
|
|
1434
|
+
override(newState: StateType, newData?: mDT | undefined): void;
|
|
1435
|
+
/*********
|
|
1436
|
+
*
|
|
1437
|
+
* Shared transition core used by {@link transition}, {@link force_transition},
|
|
1438
|
+
* and {@link action}. Runs validation, fires the full hook pipeline (pre-
|
|
1439
|
+
* everything, any-action, after, any-transition, exit, named, basic,
|
|
1440
|
+
* edge-type, entry, everything), commits the new state if nothing
|
|
1441
|
+
* rejected, and returns whether the transition succeeded.
|
|
1442
|
+
*
|
|
1443
|
+
* Not meant for external use. Call one of the public wrappers instead:
|
|
1444
|
+
* - `transition` for an ordinary legal transition
|
|
1445
|
+
* - `force_transition` to bypass the legality check
|
|
1446
|
+
* - `action` to dispatch by action name rather than target state
|
|
1447
|
+
*
|
|
1448
|
+
* @remarks
|
|
1449
|
+
* Known sharp edges, carried over from the original `// TODO` comments:
|
|
1450
|
+
* - The forced-ness behavior needs to be cleaned up a lot here.
|
|
1451
|
+
* - The callbacks are not fully correct across the forced / action / plain
|
|
1452
|
+
* cases and should be revisited.
|
|
1453
|
+
* - When multiple edges exist between two states with different `kind`
|
|
1454
|
+
* values, only the first edge's kind is used to pick the edge-type hook.
|
|
1455
|
+
*
|
|
1456
|
+
* @typeparam mDT The type of the machine data member; usually omitted.
|
|
1457
|
+
*
|
|
1458
|
+
* @param newStateOrAction The target state name (for a plain or forced
|
|
1459
|
+
* transition) or the action name (when `wasAction` is true).
|
|
1460
|
+
*
|
|
1461
|
+
* @param newData Optional replacement machine data to install alongside
|
|
1462
|
+
* the transition. Hooks may further override this via complex results.
|
|
1463
|
+
*
|
|
1464
|
+
* @param wasForced `true` if the caller invoked `force_transition`, in
|
|
1465
|
+
* which case legality is checked against `valid_force_transition` rather
|
|
1466
|
+
* than `valid_transition`.
|
|
1467
|
+
*
|
|
1468
|
+
* @param wasAction `true` if the caller invoked `action`, in which case
|
|
1469
|
+
* `newStateOrAction` is an action name and the target state is looked up
|
|
1470
|
+
* via the current action edge.
|
|
1471
|
+
*
|
|
1472
|
+
* @returns `true` if the transition was valid and every hook passed;
|
|
1473
|
+
* `false` if the transition was invalid or any hook rejected.
|
|
1474
|
+
*
|
|
1475
|
+
* @internal
|
|
1476
|
+
*
|
|
1477
|
+
*/
|
|
1478
|
+
transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
|
|
1479
|
+
/** If the current state has an `after` timeout configured, schedule it.
|
|
1480
|
+
* Called internally after each transition.
|
|
1481
|
+
*/
|
|
1482
|
+
auto_set_state_timeout(): void;
|
|
1483
|
+
/*********
|
|
1484
|
+
*
|
|
1485
|
+
* Get a truncated history of the recent states and data of the machine.
|
|
1486
|
+
* Turned off by default; configure with `.from('...', {data: 5})` by length,
|
|
1487
|
+
* or set `.history_length` at runtime.
|
|
1488
|
+
*
|
|
1489
|
+
* History *does not contain the current state*. If you want that, call
|
|
1490
|
+
* `.history_inclusive` instead.
|
|
1491
|
+
*
|
|
1492
|
+
* ```typescript
|
|
1493
|
+
* const foo = jssm.from(
|
|
1494
|
+
* "a 'next' -> b 'next' -> c 'next' -> d 'next' -> e;",
|
|
1495
|
+
* { history: 3 }
|
|
1496
|
+
* );
|
|
1497
|
+
*
|
|
1498
|
+
* foo.action('next');
|
|
1499
|
+
* foo.action('next');
|
|
1500
|
+
* foo.action('next');
|
|
1501
|
+
* foo.action('next');
|
|
1502
|
+
*
|
|
1503
|
+
* foo.history; // [ ['b',undefined], ['c',undefined], ['d',undefined] ]
|
|
1504
|
+
* ```
|
|
1505
|
+
*
|
|
1506
|
+
* Notice that the machine's current state, `e`, is not in the returned list.
|
|
1507
|
+
*
|
|
1508
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1509
|
+
*
|
|
1510
|
+
*/
|
|
1511
|
+
get history(): [string, mDT][];
|
|
1512
|
+
/*********
|
|
1513
|
+
*
|
|
1514
|
+
* Get a truncated history of the recent states and data of the machine,
|
|
1515
|
+
* including the current state. Turned off by default; configure with
|
|
1516
|
+
* `.from('...', {data: 5})` by length, or set `.history_length` at runtime.
|
|
1517
|
+
*
|
|
1518
|
+
* History inclusive contains the current state. If you only want past
|
|
1519
|
+
* states, call `.history` instead.
|
|
1520
|
+
*
|
|
1521
|
+
* The list returned will be one longer than the history buffer kept, as the
|
|
1522
|
+
* history buffer kept gets the current state added to it to produce this
|
|
1523
|
+
* list.
|
|
1524
|
+
*
|
|
1525
|
+
* ```typescript
|
|
1526
|
+
* const foo = jssm.from(
|
|
1527
|
+
* "a 'next' -> b 'next' -> c 'next' -> d 'next' -> e;",
|
|
1528
|
+
* { history: 3 }
|
|
1529
|
+
* );
|
|
1530
|
+
*
|
|
1531
|
+
* foo.action('next');
|
|
1532
|
+
* foo.action('next');
|
|
1533
|
+
* foo.action('next');
|
|
1534
|
+
* foo.action('next');
|
|
1535
|
+
*
|
|
1536
|
+
* foo.history_inclusive; // [ ['b',undefined], ['c',undefined], ['d',undefined], ['e',undefined] ]
|
|
1537
|
+
* ```
|
|
1538
|
+
*
|
|
1539
|
+
* Notice that the machine's current state, `e`, is in the returned list.
|
|
1540
|
+
*
|
|
1541
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1542
|
+
*
|
|
1543
|
+
*/
|
|
1544
|
+
get history_inclusive(): [string, mDT][];
|
|
1545
|
+
/*********
|
|
1546
|
+
*
|
|
1547
|
+
* Find out how long a history this machine is keeping. Defaults to zero.
|
|
1548
|
+
* Settable directly.
|
|
1549
|
+
*
|
|
1550
|
+
* ```typescript
|
|
1551
|
+
* const foo = jssm.from("a -> b;");
|
|
1552
|
+
* foo.history_length; // 0
|
|
1553
|
+
*
|
|
1554
|
+
* const bar = jssm.from("a -> b;", { history: 3 });
|
|
1555
|
+
* foo.history_length; // 3
|
|
1556
|
+
* foo.history_length = 5;
|
|
1557
|
+
* foo.history_length; // 5
|
|
1558
|
+
* ```
|
|
1559
|
+
*
|
|
1560
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1561
|
+
*
|
|
1562
|
+
*/
|
|
1563
|
+
get history_length(): number;
|
|
1564
|
+
set history_length(to: number);
|
|
1565
|
+
/********
|
|
1566
|
+
*
|
|
1567
|
+
* Instruct the machine to complete an action. Synonym for {@link do}.
|
|
1568
|
+
*
|
|
1569
|
+
* ```typescript
|
|
1570
|
+
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
|
|
1571
|
+
*
|
|
1572
|
+
* light.state(); // 'red'
|
|
1573
|
+
* light.action('next'); // true
|
|
1574
|
+
* light.state(); // 'green'
|
|
1575
|
+
* ```
|
|
1576
|
+
*
|
|
1577
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1578
|
+
*
|
|
1579
|
+
* @param actionName The action to engage
|
|
1580
|
+
*
|
|
1581
|
+
* @param newData The data change to insert during the action
|
|
1582
|
+
*
|
|
1583
|
+
* @returns `true` if the action was valid and the transition occurred,
|
|
1584
|
+
* `false` otherwise.
|
|
1585
|
+
*
|
|
1586
|
+
*/
|
|
1587
|
+
action(actionName: StateType, newData?: mDT): boolean;
|
|
1588
|
+
/********
|
|
1589
|
+
*
|
|
1590
|
+
* Get the standard style for a single state. ***Does not*** include
|
|
1591
|
+
* composition from an applied theme, or things from the underlying base
|
|
1592
|
+
* stylesheet; only the modifications applied by this machine.
|
|
1593
|
+
*
|
|
1594
|
+
* ```typescript
|
|
1595
|
+
* const light = sm`a -> b;`;
|
|
1596
|
+
* console.log(light.standard_state_style);
|
|
1597
|
+
* // {}
|
|
1598
|
+
*
|
|
1599
|
+
* const light = sm`a -> b; state: { shape: circle; };`;
|
|
1600
|
+
* console.log(light.standard_state_style);
|
|
1601
|
+
* // { shape: 'circle' }
|
|
1602
|
+
* ```
|
|
1603
|
+
*
|
|
1604
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1605
|
+
*
|
|
1606
|
+
* @returns The {@link JssmStateConfig} for standard states.
|
|
1607
|
+
*
|
|
1608
|
+
*/
|
|
1609
|
+
get standard_state_style(): JssmStateConfig;
|
|
1610
|
+
/********
|
|
1611
|
+
*
|
|
1612
|
+
* Get the hooked state style. ***Does not*** include
|
|
1613
|
+
* composition from an applied theme, or things from the underlying base
|
|
1614
|
+
* stylesheet; only the modifications applied by this machine.
|
|
1615
|
+
*
|
|
1616
|
+
* The hooked style is only applied to nodes which have a named hook in the
|
|
1617
|
+
* graph. Open hooks set through the external API aren't graphed, because
|
|
1618
|
+
* that would be literally every node.
|
|
1619
|
+
*
|
|
1620
|
+
* ```typescript
|
|
1621
|
+
* const light = sm`a -> b;`;
|
|
1622
|
+
* console.log(light.hooked_state_style);
|
|
1623
|
+
* // {}
|
|
1624
|
+
*
|
|
1625
|
+
* const light = sm`a -> b; hooked_state: { shape: circle; };`;
|
|
1626
|
+
* console.log(light.hooked_state_style);
|
|
1627
|
+
* // { shape: 'circle' }
|
|
1628
|
+
* ```
|
|
1629
|
+
*
|
|
1630
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1631
|
+
*
|
|
1632
|
+
* @returns The {@link JssmStateConfig} for hooked states.
|
|
1633
|
+
*
|
|
1634
|
+
*/
|
|
1635
|
+
get hooked_state_style(): JssmStateConfig;
|
|
1636
|
+
/********
|
|
1637
|
+
*
|
|
1638
|
+
* Get the start state style. ***Does not*** include composition from an
|
|
1639
|
+
* applied theme, or things from the underlying base stylesheet; only the
|
|
1640
|
+
* modifications applied by this machine.
|
|
1641
|
+
*
|
|
1642
|
+
* Start states are defined by the directive `start_states`, or in absentia,
|
|
1643
|
+
* are the first mentioned state.
|
|
1644
|
+
*
|
|
1645
|
+
* ```typescript
|
|
1646
|
+
* const light = sm`a -> b;`;
|
|
1647
|
+
* console.log(light.start_state_style);
|
|
1648
|
+
* // {}
|
|
1649
|
+
*
|
|
1650
|
+
* const light = sm`a -> b; start_state: { shape: circle; };`;
|
|
1651
|
+
* console.log(light.start_state_style);
|
|
1652
|
+
* // { shape: 'circle' }
|
|
1653
|
+
* ```
|
|
1654
|
+
*
|
|
1655
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1656
|
+
*
|
|
1657
|
+
* @returns The {@link JssmStateConfig} for start states.
|
|
1658
|
+
*
|
|
1659
|
+
*/
|
|
1660
|
+
get start_state_style(): JssmStateConfig;
|
|
1661
|
+
/********
|
|
1662
|
+
*
|
|
1663
|
+
* Get the end state style. ***Does not*** include
|
|
1664
|
+
* composition from an applied theme, or things from the underlying base
|
|
1665
|
+
* stylesheet; only the modifications applied by this machine.
|
|
1666
|
+
*
|
|
1667
|
+
* End states are defined in the directive `end_states`, and are distinct
|
|
1668
|
+
* from terminal states. End states are voluntary successful endpoints for a
|
|
1669
|
+
* process. Terminal states are states that cannot be exited. By example,
|
|
1670
|
+
* most error states are terminal states, but not end states. Also, since
|
|
1671
|
+
* some end states can be exited and are determined by hooks, such as
|
|
1672
|
+
* recursive or iterative nodes, there is such a thing as an end state that
|
|
1673
|
+
* is not a terminal state.
|
|
1674
|
+
*
|
|
1675
|
+
* ```typescript
|
|
1676
|
+
* const light = sm`a -> b;`;
|
|
1677
|
+
* console.log(light.standard_state_style);
|
|
1678
|
+
* // {}
|
|
1679
|
+
*
|
|
1680
|
+
* const light = sm`a -> b; end_state: { shape: circle; };`;
|
|
1681
|
+
* console.log(light.standard_state_style);
|
|
1682
|
+
* // { shape: 'circle' }
|
|
1683
|
+
* ```
|
|
1684
|
+
*
|
|
1685
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1686
|
+
*
|
|
1687
|
+
* @returns The {@link JssmStateConfig} for end states.
|
|
1688
|
+
*
|
|
1689
|
+
*/
|
|
1690
|
+
get end_state_style(): JssmStateConfig;
|
|
1691
|
+
/********
|
|
1692
|
+
*
|
|
1693
|
+
* Get the terminal state style. ***Does not*** include
|
|
1694
|
+
* composition from an applied theme, or things from the underlying base
|
|
1695
|
+
* stylesheet; only the modifications applied by this machine.
|
|
1696
|
+
*
|
|
1697
|
+
* Terminal state styles are automatically determined by the machine. Any
|
|
1698
|
+
* state without a valid exit transition is terminal.
|
|
1699
|
+
*
|
|
1700
|
+
* ```typescript
|
|
1701
|
+
* const light = sm`a -> b;`;
|
|
1702
|
+
* console.log(light.terminal_state_style);
|
|
1703
|
+
* // {}
|
|
1704
|
+
*
|
|
1705
|
+
* const light = sm`a -> b; terminal_state: { shape: circle; };`;
|
|
1706
|
+
* console.log(light.terminal_state_style);
|
|
1707
|
+
* // { shape: 'circle' }
|
|
1708
|
+
* ```
|
|
1709
|
+
*
|
|
1710
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1711
|
+
*
|
|
1712
|
+
* @returns The {@link JssmStateConfig} for terminal states.
|
|
1713
|
+
*
|
|
1714
|
+
*/
|
|
1715
|
+
get terminal_state_style(): JssmStateConfig;
|
|
1716
|
+
/********
|
|
1717
|
+
*
|
|
1718
|
+
* Get the style for the active state. ***Does not*** include
|
|
1719
|
+
* composition from an applied theme, or things from the underlying base
|
|
1720
|
+
* stylesheet; only the modifications applied by this machine.
|
|
1721
|
+
*
|
|
1722
|
+
* ```typescript
|
|
1723
|
+
* const light = sm`a -> b;`;
|
|
1724
|
+
* console.log(light.active_state_style);
|
|
1725
|
+
* // {}
|
|
1726
|
+
*
|
|
1727
|
+
* const light = sm`a -> b; active_state: { shape: circle; };`;
|
|
1728
|
+
* console.log(light.active_state_style);
|
|
1729
|
+
* // { shape: 'circle' }
|
|
1730
|
+
* ```
|
|
1731
|
+
*
|
|
1732
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1733
|
+
*
|
|
1734
|
+
* @returns The {@link JssmStateConfig} for the active state.
|
|
1735
|
+
*
|
|
1736
|
+
*/
|
|
1737
|
+
get active_state_style(): JssmStateConfig;
|
|
1738
|
+
/********
|
|
1739
|
+
*
|
|
1740
|
+
* Gets the composite style for a specific node by individually imposing the
|
|
1741
|
+
* style layers on a given object, after determining which layers are
|
|
1742
|
+
* appropriate.
|
|
1743
|
+
*
|
|
1744
|
+
* The order of composition is base, then theme, then user content. Each
|
|
1745
|
+
* item in the stack will be composited independently. First, the base state
|
|
1746
|
+
* style, then the theme state style, then the user state style.
|
|
1747
|
+
*
|
|
1748
|
+
* After the three state styles, we'll composite the hooked styles; then the
|
|
1749
|
+
* terminal styles; then the start styles; then the end styles; finally, the
|
|
1750
|
+
* active styles. Remember, last wins.
|
|
1751
|
+
*
|
|
1752
|
+
* The base state style must exist. All other styles are optional.
|
|
1753
|
+
*
|
|
1754
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1755
|
+
*
|
|
1756
|
+
* @param state The state to compute the composite style for.
|
|
1757
|
+
*
|
|
1758
|
+
* @returns The fully composited {@link JssmStateConfig} for the given state.
|
|
1759
|
+
*
|
|
1760
|
+
*/
|
|
1761
|
+
style_for(state: StateType): JssmStateConfig;
|
|
1762
|
+
/********
|
|
1763
|
+
*
|
|
1764
|
+
* Instruct the machine to complete an action. Synonym for {@link action}.
|
|
1765
|
+
*
|
|
1766
|
+
* ```typescript
|
|
1767
|
+
* const light = sm`
|
|
1768
|
+
* off 'start' -> red;
|
|
1769
|
+
* red 'next' -> green 'next' -> yellow 'next' -> red;
|
|
1770
|
+
* [red yellow green] 'shutdown' ~> off;
|
|
1771
|
+
* `;
|
|
1772
|
+
*
|
|
1773
|
+
* light.state(); // 'off'
|
|
1774
|
+
* light.do('start'); // true
|
|
1775
|
+
* light.state(); // 'red'
|
|
1776
|
+
* light.do('next'); // true
|
|
1777
|
+
* light.state(); // 'green'
|
|
1778
|
+
* light.do('next'); // true
|
|
1779
|
+
* light.state(); // 'yellow'
|
|
1780
|
+
* light.do('dance'); // !! false - no such action
|
|
1781
|
+
* light.state(); // 'yellow'
|
|
1782
|
+
* light.do('start'); // !! false - yellow does not have the action start
|
|
1783
|
+
* light.state(); // 'yellow'
|
|
1784
|
+
* ```
|
|
1785
|
+
*
|
|
1786
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1787
|
+
*
|
|
1788
|
+
* @param actionName The action to engage
|
|
1789
|
+
*
|
|
1790
|
+
* @param newData The data change to insert during the action
|
|
1791
|
+
*
|
|
1792
|
+
* @returns `true` if the action was valid and the transition occurred,
|
|
1793
|
+
* `false` otherwise.
|
|
1794
|
+
*
|
|
1795
|
+
*/
|
|
1796
|
+
do(actionName: StateType, newData?: mDT): boolean;
|
|
1797
|
+
/********
|
|
1798
|
+
*
|
|
1799
|
+
* Instruct the machine to complete a transition. Synonym for {@link go}.
|
|
1800
|
+
*
|
|
1801
|
+
* ```typescript
|
|
1802
|
+
* const light = sm`
|
|
1803
|
+
* off 'start' -> red;
|
|
1804
|
+
* red 'next' -> green 'next' -> yellow 'next' -> red;
|
|
1805
|
+
* [red yellow green] 'shutdown' ~> off;
|
|
1806
|
+
* `;
|
|
1807
|
+
*
|
|
1808
|
+
* light.state(); // 'off'
|
|
1809
|
+
* light.go('red'); // true
|
|
1810
|
+
* light.state(); // 'red'
|
|
1811
|
+
* light.go('green'); // true
|
|
1812
|
+
* light.state(); // 'green'
|
|
1813
|
+
* light.go('blue'); // !! false - no such state
|
|
1814
|
+
* light.state(); // 'green'
|
|
1815
|
+
* light.go('red'); // !! false - green may not go directly to red, only to yellow
|
|
1816
|
+
* light.state(); // 'green'
|
|
1817
|
+
* ```
|
|
1818
|
+
*
|
|
1819
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1820
|
+
*
|
|
1821
|
+
* @param newState The state to switch to
|
|
1822
|
+
*
|
|
1823
|
+
* @param newData The data change to insert during the transition
|
|
1824
|
+
*
|
|
1825
|
+
* @returns `true` if the transition was legal and occurred, `false` otherwise.
|
|
1826
|
+
*
|
|
1827
|
+
*/
|
|
1828
|
+
transition(newState: StateType, newData?: mDT): boolean;
|
|
1829
|
+
/********
|
|
1830
|
+
*
|
|
1831
|
+
* Instruct the machine to complete a transition. Synonym for {@link transition}.
|
|
1832
|
+
*
|
|
1833
|
+
* ```typescript
|
|
1834
|
+
* const light = sm`red -> green -> yellow -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
|
|
1835
|
+
*
|
|
1836
|
+
* light.state(); // 'red'
|
|
1837
|
+
* light.go('green'); // true
|
|
1838
|
+
* light.state(); // 'green'
|
|
1839
|
+
* ```
|
|
1840
|
+
*
|
|
1841
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1842
|
+
*
|
|
1843
|
+
* @param newState The state to switch to
|
|
1844
|
+
*
|
|
1845
|
+
* @param newData The data change to insert during the transition
|
|
1846
|
+
*
|
|
1847
|
+
* @returns `true` if the transition was legal and occurred, `false` otherwise.
|
|
1848
|
+
*
|
|
1849
|
+
*/
|
|
1850
|
+
go(newState: StateType, newData?: mDT): boolean;
|
|
1851
|
+
/********
|
|
1852
|
+
*
|
|
1853
|
+
* Instruct the machine to complete a forced transition (which will reject if
|
|
1854
|
+
* called with a normal {@link transition} call.)
|
|
1855
|
+
*
|
|
1856
|
+
* ```typescript
|
|
1857
|
+
* const light = sm`red -> green -> yellow -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
|
|
1858
|
+
*
|
|
1859
|
+
* light.state(); // 'red'
|
|
1860
|
+
* light.transition('off'); // false
|
|
1861
|
+
* light.state(); // 'red'
|
|
1862
|
+
* light.force_transition('off'); // true
|
|
1863
|
+
* light.state(); // 'off'
|
|
1864
|
+
* ```
|
|
1865
|
+
*
|
|
1866
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1867
|
+
*
|
|
1868
|
+
* @param newState The state to switch to
|
|
1869
|
+
*
|
|
1870
|
+
* @param newData The data change to insert during the transition
|
|
1871
|
+
*
|
|
1872
|
+
* @returns `true` if a transition (forced or otherwise) existed and occurred,
|
|
1873
|
+
* `false` otherwise.
|
|
1874
|
+
*
|
|
1875
|
+
*/
|
|
1876
|
+
force_transition(newState: StateType, newData?: mDT): boolean;
|
|
1877
|
+
/** Get the edge index for an action from the current state.
|
|
1878
|
+
* @param action - The action name.
|
|
1879
|
+
* @returns The edge index, or `undefined` if the action is not available.
|
|
1880
|
+
*/
|
|
1881
|
+
current_action_for(action: StateType): number;
|
|
1882
|
+
/** Get the full transition object for an action from the current state.
|
|
1883
|
+
* @param action - The action name.
|
|
1884
|
+
* @returns The {@link JssmTransition} object.
|
|
1885
|
+
* @throws {JssmError} If the action is not available from the current state.
|
|
1886
|
+
*/
|
|
1887
|
+
current_action_edge_for(action: StateType): JssmTransition<StateType, mDT>;
|
|
1888
|
+
/** Check whether an action is available from the current state.
|
|
1889
|
+
* @param action - The action name to check.
|
|
1890
|
+
* @param _newData - Reserved for future data validation.
|
|
1891
|
+
* @returns `true` if the action can be taken.
|
|
1892
|
+
*/
|
|
1893
|
+
valid_action(action: StateType, _newData?: mDT): boolean;
|
|
1894
|
+
/** Check whether a transition to a given state is legal (non-forced) from
|
|
1895
|
+
* the current state.
|
|
1896
|
+
* @param newState - The target state.
|
|
1897
|
+
* @param _newData - Reserved for future data validation.
|
|
1898
|
+
* @returns `true` if the transition is legal.
|
|
1899
|
+
*/
|
|
1900
|
+
valid_transition(newState: StateType, _newData?: mDT): boolean;
|
|
1901
|
+
/** Check whether a forced transition to a given state exists from the
|
|
1902
|
+
* current state.
|
|
1903
|
+
* @param newState - The target state.
|
|
1904
|
+
* @param _newData - Reserved for future data validation.
|
|
1905
|
+
* @returns `true` if a forced (or any) transition exists.
|
|
1906
|
+
*/
|
|
1907
|
+
valid_force_transition(newState: StateType, _newData?: mDT): boolean;
|
|
1908
|
+
/** Get the instance name of this machine, if one was assigned at creation.
|
|
1909
|
+
* @returns The instance name string, or `undefined`.
|
|
1910
|
+
*/
|
|
1911
|
+
instance_name(): string | undefined;
|
|
1912
|
+
/** Get the creation date of this machine as a `Date` object.
|
|
1913
|
+
* @returns A `Date` representing when the machine was created.
|
|
1914
|
+
*/
|
|
1915
|
+
get creation_date(): Date;
|
|
1916
|
+
/** Get the creation timestamp (milliseconds since epoch).
|
|
1917
|
+
* @returns The timestamp as a number.
|
|
1918
|
+
*/
|
|
1919
|
+
get creation_timestamp(): number;
|
|
1920
|
+
/** Get the timestamp when construction began (before parsing).
|
|
1921
|
+
* @returns The start-of-construction timestamp as a number.
|
|
1922
|
+
*/
|
|
1923
|
+
get create_start_time(): number;
|
|
1924
|
+
/** Schedule an automatic transition to `next_state` after `after_time`
|
|
1925
|
+
* milliseconds. Only one timeout may be active at a time.
|
|
1926
|
+
* @param next_state - The state to transition to when the timer fires.
|
|
1927
|
+
* @param after_time - Delay in milliseconds.
|
|
1928
|
+
* @throws {JssmError} If a timeout is already pending.
|
|
1929
|
+
*/
|
|
1930
|
+
set_state_timeout(next_state: StateType, after_time: number): void;
|
|
1931
|
+
/** Cancel any pending state timeout. Safe to call when no timeout is active.
|
|
1932
|
+
*/
|
|
1933
|
+
clear_state_timeout(): void;
|
|
1934
|
+
/** Get the configured `after` timeout for a given state, if any.
|
|
1935
|
+
* @param which_state - The state to look up.
|
|
1936
|
+
* @returns A `[targetState, delayMs]` tuple, or `undefined` if no timeout
|
|
1937
|
+
* is configured for that state.
|
|
1938
|
+
*/
|
|
1939
|
+
state_timeout_for(which_state: StateType): [StateType, number] | undefined;
|
|
1940
|
+
/** Get the configured `after` timeout for the current state, if any.
|
|
1941
|
+
* @returns A `[targetState, delayMs]` tuple, or `undefined`.
|
|
1942
|
+
*/
|
|
1943
|
+
current_state_timeout(): [StateType, number] | undefined;
|
|
1944
|
+
/** Convenience method to create a new machine from a tagged template literal.
|
|
1945
|
+
* Equivalent to calling the top-level `sm` function.
|
|
1946
|
+
* @param template_strings - The template string array.
|
|
1947
|
+
* @param remainder - Interpolated values.
|
|
1948
|
+
* @returns A new {@link Machine} instance.
|
|
1949
|
+
*/
|
|
1950
|
+
sm(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>;
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
/**
|
|
1954
|
+
* Inject runtime configuration for jssm/viz. Currently only accepts a
|
|
1955
|
+
* custom `DOMParser` constructor for use by `*_svg_element` functions in
|
|
1956
|
+
* environments that do not provide one globally (e.g. Node + jsdom).
|
|
1957
|
+
*
|
|
1958
|
+
* Idempotent — last call wins. No-op if called with no recognized keys.
|
|
1959
|
+
*
|
|
1960
|
+
* ```typescript
|
|
1961
|
+
* // Node, with jsdom:
|
|
1962
|
+
* import { JSDOM } from 'jsdom';
|
|
1963
|
+
* import { configure, fsl_to_svg_element } from 'jssm/viz';
|
|
1964
|
+
*
|
|
1965
|
+
* configure({ DOMParser: new JSDOM().window.DOMParser });
|
|
1966
|
+
* const el = await fsl_to_svg_element('a -> b;');
|
|
1967
|
+
* ```
|
|
1968
|
+
*
|
|
1969
|
+
* @param opts Configuration overrides.
|
|
1970
|
+
* @param opts.DOMParser Constructor compatible with the WHATWG `DOMParser`
|
|
1971
|
+
* interface. Used as a fallback when `globalThis.DOMParser` is undefined.
|
|
1972
|
+
*
|
|
1973
|
+
* @throws {JssmError} if `DOMParser` is provided and is not a constructor.
|
|
1974
|
+
*/
|
|
1975
|
+
declare function configure(opts: {
|
|
1976
|
+
DOMParser?: typeof globalThis.DOMParser;
|
|
1977
|
+
}): void;
|
|
1978
|
+
/**
|
|
1979
|
+
* Look up a color from the default viz palette by key, returning empty
|
|
1980
|
+
* string if the key is unknown (so it disappears in feature concatenation).
|
|
1981
|
+
*
|
|
1982
|
+
* @internal
|
|
1983
|
+
*/
|
|
1984
|
+
declare function vc(col: string): string;
|
|
1985
|
+
/**
|
|
1986
|
+
* Build a graphviz-safe node identifier for a state, by index. Accepts
|
|
1987
|
+
* either a `string[]` (used historically; O(n) per call) or a
|
|
1988
|
+
* precomputed `Map<state, index>` (used by rendering hot paths; O(1)
|
|
1989
|
+
* per call). The map form is used during dot generation; the array
|
|
1990
|
+
* form is retained for direct test access via `_test`.
|
|
1991
|
+
*
|
|
1992
|
+
* @internal
|
|
1993
|
+
*/
|
|
1994
|
+
declare function node_of(state: string, state_index: string[] | Map<string, number>): string;
|
|
1995
|
+
/**
|
|
1996
|
+
* Convert an 8-channel hex color (`#RRGGBBAA`) to a 6-channel hex color
|
|
1997
|
+
* (`#RRGGBB`), discarding the alpha channel. Throws if the input is not
|
|
1998
|
+
* a 9-character `#`-prefixed string.
|
|
1999
|
+
*
|
|
2000
|
+
* Graphviz dot does not support alpha; this is a lossy projection.
|
|
2001
|
+
*
|
|
2002
|
+
* @internal
|
|
2003
|
+
*/
|
|
2004
|
+
declare function color8to6(color8: string): string;
|
|
2005
|
+
/**
|
|
2006
|
+
* Variant of {@link color8to6} that passes `undefined` through.
|
|
2007
|
+
*
|
|
2008
|
+
* @internal
|
|
2009
|
+
*/
|
|
2010
|
+
declare function u_color8to6(color8?: string): string | undefined;
|
|
2011
|
+
/**
|
|
2012
|
+
* Read the graphviz shape for a state through {@link jssm.Machine.style_for},
|
|
2013
|
+
* so theme-supplied shapes are honoured along with per-state declarations.
|
|
2014
|
+
* Returns `undefined` if neither a theme nor a state declaration supplies a
|
|
2015
|
+
* shape.
|
|
2016
|
+
*
|
|
2017
|
+
* @internal
|
|
2018
|
+
*/
|
|
2019
|
+
declare function shape_for_state<T>(u_jssm: Machine<T>, state: string): string | undefined;
|
|
2020
|
+
/**
|
|
2021
|
+
* Read the image filename for a state through {@link jssm.Machine.style_for},
|
|
2022
|
+
* so theme-supplied images are honoured along with per-state declarations.
|
|
2023
|
+
* Returns `undefined` if neither a theme nor a state declaration supplies an
|
|
2024
|
+
* image.
|
|
2025
|
+
*
|
|
2026
|
+
* @internal
|
|
2027
|
+
*/
|
|
2028
|
+
declare function image_for_state<T>(u_jssm: Machine<T>, state: string): string | undefined;
|
|
2029
|
+
/**
|
|
2030
|
+
* Compose a graphviz `style` string for a state by looking up its merged
|
|
2031
|
+
* style via {@link jssm.Machine.style_for}, then delegating to
|
|
2032
|
+
* {@link compose_style_string}. Theme-supplied `corners` and `lineStyle`
|
|
2033
|
+
* are honoured along with per-state declarations.
|
|
2034
|
+
*
|
|
2035
|
+
* @internal
|
|
2036
|
+
*/
|
|
2037
|
+
declare function style_for_state<T>(u_jssm: Machine<T>, state: string): string;
|
|
2038
|
+
/**
|
|
2039
|
+
* Render a {@link jssm.Machine} as a graphviz dot string.
|
|
2040
|
+
*
|
|
2041
|
+
* ```typescript
|
|
2042
|
+
* import { sm } from 'jssm';
|
|
2043
|
+
* import { machine_to_dot } from 'jssm/viz';
|
|
2044
|
+
*
|
|
2045
|
+
* const dot = machine_to_dot(sm`a -> b;`);
|
|
2046
|
+
* // 'digraph G { ... }'
|
|
2047
|
+
* ```
|
|
2048
|
+
*
|
|
2049
|
+
* @param u_jssm The machine to render.
|
|
2050
|
+
* @returns A complete graphviz dot source string.
|
|
2051
|
+
*/
|
|
2052
|
+
declare function machine_to_dot<T>(u_jssm: Machine<T>): string;
|
|
2053
|
+
/**
|
|
2054
|
+
* Render an FSL string directly to graphviz dot source.
|
|
2055
|
+
*
|
|
2056
|
+
* ```typescript
|
|
2057
|
+
* import { fsl_to_dot } from 'jssm/viz';
|
|
2058
|
+
* const dot = fsl_to_dot('a -> b;');
|
|
2059
|
+
* ```
|
|
2060
|
+
*
|
|
2061
|
+
* @param fsl The FSL source.
|
|
2062
|
+
* @returns A complete graphviz dot source string.
|
|
2063
|
+
*/
|
|
2064
|
+
declare function fsl_to_dot(fsl: string): string;
|
|
2065
|
+
/**
|
|
2066
|
+
* Render a graphviz dot source string to SVG using `@viz-js/viz`. The
|
|
2067
|
+
* underlying viz instance is lazy-initialized on first call and cached for
|
|
2068
|
+
* the lifetime of the module.
|
|
2069
|
+
*
|
|
2070
|
+
* ```typescript
|
|
2071
|
+
* const svg = await dot_to_svg('digraph G { a -> b }');
|
|
2072
|
+
* ```
|
|
2073
|
+
*
|
|
2074
|
+
* @param dot Graphviz dot source.
|
|
2075
|
+
* @returns A promise resolving to an SVG XML string.
|
|
2076
|
+
*/
|
|
2077
|
+
declare function dot_to_svg(dot: string): Promise<string>;
|
|
2078
|
+
/**
|
|
2079
|
+
* Render an FSL string directly to SVG.
|
|
2080
|
+
*
|
|
2081
|
+
* @param fsl The FSL source.
|
|
2082
|
+
* @returns A promise resolving to an SVG XML string.
|
|
2083
|
+
*/
|
|
2084
|
+
declare function fsl_to_svg_string(fsl: string): Promise<string>;
|
|
2085
|
+
/**
|
|
2086
|
+
* Render a {@link jssm.Machine} to SVG.
|
|
2087
|
+
*
|
|
2088
|
+
* @param u_jssm The machine to render.
|
|
2089
|
+
* @returns A promise resolving to an SVG XML string.
|
|
2090
|
+
*/
|
|
2091
|
+
declare function machine_to_svg_string<T>(u_jssm: Machine<T>): Promise<string>;
|
|
2092
|
+
/**
|
|
2093
|
+
* Render an FSL string directly to a parsed `SVGSVGElement`.
|
|
2094
|
+
*
|
|
2095
|
+
* @param fsl The FSL source.
|
|
2096
|
+
* @returns A promise resolving to a parsed `SVGSVGElement`.
|
|
2097
|
+
* @throws {JssmError} if no `DOMParser` is available (Node without `configure`).
|
|
2098
|
+
*/
|
|
2099
|
+
declare function fsl_to_svg_element(fsl: string): Promise<SVGSVGElement>;
|
|
2100
|
+
/**
|
|
2101
|
+
* Render a {@link jssm.Machine} to a parsed `SVGSVGElement`.
|
|
2102
|
+
*
|
|
2103
|
+
* @param u_jssm The machine to render.
|
|
2104
|
+
* @returns A promise resolving to a parsed `SVGSVGElement`.
|
|
2105
|
+
* @throws {JssmError} if no `DOMParser` is available (Node without `configure`).
|
|
2106
|
+
*/
|
|
2107
|
+
declare function machine_to_svg_element<T>(u_jssm: Machine<T>): Promise<SVGSVGElement>;
|
|
2108
|
+
/**
|
|
2109
|
+
* Compatibility wrapper for {@link machine_to_dot}, retained from
|
|
2110
|
+
* jssm-viz. Will be removed in the next major.
|
|
2111
|
+
*
|
|
2112
|
+
* @deprecated Use {@link machine_to_dot} instead.
|
|
2113
|
+
*/
|
|
2114
|
+
declare function dot<T>(machine: Machine<T>): string;
|
|
2115
|
+
|
|
2116
|
+
/** @internal — test-only access to private helpers. */
|
|
2117
|
+
declare const _test: {
|
|
2118
|
+
color8to6: typeof color8to6;
|
|
2119
|
+
u_color8to6: typeof u_color8to6;
|
|
2120
|
+
vc: typeof vc;
|
|
2121
|
+
node_of: typeof node_of;
|
|
2122
|
+
shape_for_state: typeof shape_for_state;
|
|
2123
|
+
image_for_state: typeof image_for_state;
|
|
2124
|
+
style_for_state: typeof style_for_state;
|
|
2125
|
+
};
|
|
2126
|
+
|
|
2127
|
+
export { _test, build_time, configure, dot, dot_to_svg, fsl_to_dot, fsl_to_svg_element, fsl_to_svg_string, machine_to_dot, machine_to_svg_element, machine_to_svg_string, version };
|