jssm 5.104.2 → 5.112.4

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.
Files changed (84) hide show
  1. package/MIGRATING-jssm-viz.md +67 -0
  2. package/README.md +179 -882
  3. package/dist/deno/README.md +347 -0
  4. package/dist/{es6 → deno}/jssm.d.ts +773 -39
  5. package/dist/deno/jssm.js +1 -0
  6. package/{jssm_compiler.d.ts → dist/deno/jssm_compiler.d.ts} +17 -2
  7. package/dist/deno/jssm_constants.d.ts +37 -0
  8. package/dist/deno/jssm_error.d.ts +27 -0
  9. package/dist/deno/jssm_theme.d.ts +15 -0
  10. package/dist/{es6 → deno}/jssm_types.d.ts +327 -8
  11. package/dist/deno/jssm_util.d.ts +258 -0
  12. package/dist/deno/jssm_viz.d.ts +175 -0
  13. package/dist/deno/jssm_viz_colors.d.ts +63 -0
  14. package/dist/jssm.es5.cjs +1 -1
  15. package/dist/jssm.es5.iife.js +1 -0
  16. package/dist/jssm.es6.mjs +1 -1
  17. package/dist/jssm_viz.cjs +1 -0
  18. package/dist/jssm_viz.iife.cjs +1 -0
  19. package/dist/jssm_viz.mjs +1 -0
  20. package/jssm.es5.d.cts +1191 -43
  21. package/jssm.es6.d.ts +1191 -43
  22. package/jssm_viz.es5.d.cts +2341 -0
  23. package/jssm_viz.es6.d.ts +2341 -0
  24. package/package.json +73 -24
  25. package/.clocignore +0 -1
  26. package/.codeclimate.yml +0 -22
  27. package/.editorconfig +0 -12
  28. package/.eslintrc +0 -20
  29. package/.gitattributes +0 -6
  30. package/.nycrc +0 -6
  31. package/.travis.yml +0 -9
  32. package/CHANGELOG.md +0 -178
  33. package/dist/es6/fsl_parser.js +0 -1
  34. package/dist/es6/jssm.js +0 -2488
  35. package/dist/es6/jssm_arrow.js +0 -187
  36. package/dist/es6/jssm_compiler.d.ts +0 -135
  37. package/dist/es6/jssm_compiler.js +0 -366
  38. package/dist/es6/jssm_constants.d.ts +0 -5
  39. package/dist/es6/jssm_constants.js +0 -94
  40. package/dist/es6/jssm_error.d.ts +0 -8
  41. package/dist/es6/jssm_error.js +0 -28
  42. package/dist/es6/jssm_theme.d.ts +0 -4
  43. package/dist/es6/jssm_theme.js +0 -13
  44. package/dist/es6/jssm_types.js +0 -3
  45. package/dist/es6/jssm_util.d.ts +0 -106
  46. package/dist/es6/jssm_util.js +0 -180
  47. package/dist/es6/themes/jssm_base_stylesheet.d.ts +0 -11
  48. package/dist/es6/themes/jssm_base_stylesheet.js +0 -58
  49. package/dist/es6/themes/jssm_theme_bold.d.ts +0 -11
  50. package/dist/es6/themes/jssm_theme_bold.js +0 -58
  51. package/dist/es6/themes/jssm_theme_default.d.ts +0 -11
  52. package/dist/es6/themes/jssm_theme_default.js +0 -58
  53. package/dist/es6/themes/jssm_theme_modern.d.ts +0 -11
  54. package/dist/es6/themes/jssm_theme_modern.js +0 -58
  55. package/dist/es6/themes/jssm_theme_ocean.d.ts +0 -11
  56. package/dist/es6/themes/jssm_theme_ocean.js +0 -56
  57. package/dist/es6/themes/jssm_theme_plain.d.ts +0 -11
  58. package/dist/es6/themes/jssm_theme_plain.js +0 -70
  59. package/dist/es6/version.js +0 -2
  60. package/dist/jssm.es5.iife.cjs +0 -1
  61. package/dist/jssm.es5.iife.nonmin.cjs +0 -23180
  62. package/dist/jssm.es5.nonmin.cjs +0 -23175
  63. package/dist/jssm.es6.nonmin.cjs +0 -23144
  64. package/fsl_parser.d.ts +0 -6
  65. package/jest-dragon.config.cjs +0 -33
  66. package/jest-spec.config.cjs +0 -33
  67. package/jest-stoch.config.cjs +0 -33
  68. package/jest-unicode.config.cjs +0 -33
  69. package/jssm.d.ts +0 -1141
  70. package/jssm_arrow.d.ts +0 -53
  71. package/jssm_constants.d.ts +0 -5
  72. package/jssm_error.d.ts +0 -8
  73. package/jssm_theme.d.ts +0 -4
  74. package/jssm_types.d.ts +0 -378
  75. package/jssm_util.d.ts +0 -106
  76. package/rollup.config.deno.js +0 -44
  77. package/rollup.config.es5.js +0 -52
  78. package/rollup.config.es6.js +0 -55
  79. package/tutorial_learn_testing.md +0 -168
  80. package/typedoc-options.cjs +0 -68
  81. package/version.d.ts +0 -2
  82. /package/dist/{es6 → deno}/fsl_parser.d.ts +0 -0
  83. /package/dist/{es6 → deno}/jssm_arrow.d.ts +0 -0
  84. /package/dist/{es6 → deno}/version.d.ts +0 -0
package/jssm.es5.d.cts CHANGED
@@ -1,23 +1,87 @@
1
1
  import { circular_buffer } from 'circular_buffer_js';
2
2
 
3
- declare type StateType$1 = string; /** Composite type composing whether or not a result was successful */
3
+ declare type StateType$1 = string;
4
+ /**
5
+ * A color value accepted by jssm-viz for state and arrow styling. Currently
6
+ * any string, validated downstream by Graphviz / the named-colors list.
7
+ * Intended to be narrowed to `#RRGGBB` / `#RRGGBBAA` and CSS named colors
8
+ * in a future release.
9
+ */
4
10
  declare type JssmColor = string;
11
+ /**
12
+ * Three-state policy flag: `'required'`, `'disallowed'`, or `'optional'`.
13
+ * Used by machine configuration where a default-permissive middle ground
14
+ * is meaningful (for example, the `actions` config key).
15
+ */
5
16
  declare type JssmPermittedOpt = 'required' | 'disallowed' | 'optional';
17
+ /**
18
+ * The set of ASCII arrow tokens recognized by the FSL grammar. Each arrow
19
+ * encodes a direction (one-way left/right, or two-way) and a "kind" for
20
+ * each direction (`-` legal, `=` main path, `~` forced-only). See the
21
+ * Language Reference docs for the full semantic table.
22
+ */
6
23
  declare type JssmArrow = '->' | '<-' | '<->' | '<=->' | '<~->' | '=>' | '<=' | '<=>' | '<-=>' | '<~=>' | '~>' | '<~' | '<~>' | '<-~>' | '<=~>';
7
24
  /**
8
25
  * A type teaching Typescript the various supported shapes for nodes, mostly inherited from GraphViz
9
26
  */
10
27
  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";
28
+ /**
29
+ * Direction polarity of an arrow: pointing only `'left'`, only `'right'`,
30
+ * or `'both'` (a bidirectional arrow).
31
+ */
11
32
  declare type JssmArrowDirection = 'left' | 'right' | 'both';
33
+ /**
34
+ * Semantic category of an arrow's transition. `'legal'` is a normal
35
+ * transition, `'main'` is part of the machine's primary path, `'forced'`
36
+ * may only be taken via {@link Machine.force_transition}, and `'none'`
37
+ * means no transition exists in that direction.
38
+ */
12
39
  declare type JssmArrowKind = 'none' | 'legal' | 'main' | 'forced';
40
+ /**
41
+ * Graphviz layout engine selector. Controls how jssm-viz lays out the
42
+ * rendered diagram; `'dot'` is the default and most useful for state
43
+ * machines. See the Graphviz documentation for the differences.
44
+ */
13
45
  declare type JssmLayout = 'dot' | 'circo' | 'twopi' | 'fdp' | 'neato';
14
46
  declare type JssmCorner = 'regular' | 'rounded' | 'lined';
15
47
  declare type JssmLineStyle = 'solid' | 'dashed' | 'dotted';
48
+ /**
49
+ * Tristate flag for whether a property may be overridden at runtime.
50
+ * `true` permits overrides, `false` forbids them, and `undefined` defers
51
+ * the decision to the surrounding configuration's default.
52
+ */
16
53
  declare type JssmAllowsOverride = true | false | undefined;
54
+ /**
55
+ * Runtime-iterable list of valid `flow` directions for FSL diagrams.
56
+ * Use this when you need to enumerate directions; for the type itself
57
+ * see {@link FslDirection}.
58
+ */
17
59
  declare const FslDirections: readonly ["up", "right", "down", "left"];
60
+ /**
61
+ * String literal type of the four supported FSL flow directions. This is
62
+ * the type of the `flow` config key on a machine.
63
+ */
18
64
  declare type FslDirection = typeof FslDirections[number];
65
+ /**
66
+ * Runtime-iterable list of the built-in theme names that ship with jssm-viz.
67
+ * Use this when you need to enumerate themes; for the type itself see
68
+ * {@link FslTheme}.
69
+ */
19
70
  declare const FslThemes: readonly ["default", "ocean", "modern", "plain", "bold"];
71
+ /**
72
+ * String literal type of the built-in theme names. This is the element
73
+ * type of the `theme` config key (which accepts an array so that themes
74
+ * can be layered).
75
+ */
20
76
  declare type FslTheme = typeof FslThemes[number];
77
+ /**
78
+ * Persistable snapshot of a Machine produced by {@link Machine.serialize}
79
+ * and consumed by {@link deserialize}. Carries the current state, the
80
+ * associated machine data, the recent history (subject to the configured
81
+ * capacity), and metadata to detect version-skew on rehydration.
82
+ *
83
+ * @typeParam DataType - The type of the user-supplied data payload (`mDT`).
84
+ */
21
85
  declare type JssmSerialization<DataType> = {
22
86
  jssm_version: string;
23
87
  timestamp: number;
@@ -27,6 +91,11 @@ declare type JssmSerialization<DataType> = {
27
91
  history_capacity: number;
28
92
  data: DataType;
29
93
  };
94
+ /**
95
+ * Declaration of a named property that a machine's states may carry.
96
+ * Set `required: true` to force every state to define the property, or
97
+ * provide `default_value` to fall back when the state does not specify it.
98
+ */
30
99
  declare type JssmPropertyDefinition = {
31
100
  name: string;
32
101
  default_value?: any;
@@ -34,6 +103,17 @@ declare type JssmPropertyDefinition = {
34
103
  };
35
104
  declare type JssmTransitionPermitter<DataType> = (OldState: StateType$1, NewState: StateType$1, OldData: DataType, NewData: DataType) => boolean;
36
105
  declare type JssmTransitionPermitterMaybeArray<DataType> = JssmTransitionPermitter<DataType> | Array<JssmTransitionPermitter<DataType>>;
106
+ /**
107
+ * A single directed transition (edge) within a state machine. Captures
108
+ * both the topology (`from` / `to`), the FSL semantics (`kind`,
109
+ * `forced_only`, `main_path`), and any optional metadata such as a
110
+ * per-edge `name`, an action label, a guard `check`, a transition
111
+ * `probability` for stochastic models, and an `after_time` for timed
112
+ * transitions.
113
+ *
114
+ * @typeParam StateType - The state-name type (usually `string`).
115
+ * @typeParam DataType - The machine's data payload type (`mDT`).
116
+ */
37
117
  declare type JssmTransition<StateType, DataType> = {
38
118
  from: StateType;
39
119
  to: StateType;
@@ -47,17 +127,34 @@ declare type JssmTransition<StateType, DataType> = {
47
127
  forced_only: boolean;
48
128
  main_path: boolean;
49
129
  };
130
+ /** A list of {@link JssmTransition}s — the edge set of a machine. */
50
131
  declare type JssmTransitions<StateType, DataType> = JssmTransition<StateType, DataType>[];
132
+ /**
133
+ * The set of states that can immediately precede or follow a given state.
134
+ * Returned by jssm helpers that report a state's connectivity in the graph.
135
+ */
51
136
  declare type JssmTransitionList = {
52
137
  entrances: Array<StateType$1>;
53
138
  exits: Array<StateType$1>;
54
139
  };
140
+ /**
141
+ * Topology record for one node in a compiled machine: its name, the set of
142
+ * states it can be reached from, the set of states it can transition to,
143
+ * and whether reaching it constitutes "completing" the machine.
144
+ */
55
145
  declare type JssmGenericState = {
56
146
  from: Array<StateType$1>;
57
147
  name: StateType$1;
58
148
  to: Array<StateType$1>;
59
149
  complete: boolean;
60
150
  };
151
+ /**
152
+ * The full internal bookkeeping snapshot of a {@link Machine}, exposed for
153
+ * advanced introspection. Contains the current state, the state map, the
154
+ * edge map and reverse-action map, and the original edge list. The
155
+ * `internal_state_impl_version` field exists so that consumers can detect
156
+ * shape changes if this representation evolves.
157
+ */
61
158
  declare type JssmMachineInternalState<DataType> = {
62
159
  internal_state_impl_version: 1;
63
160
  state: StateType$1;
@@ -70,11 +167,21 @@ declare type JssmMachineInternalState<DataType> = {
70
167
  };
71
168
  declare type JssmStatePermitter<DataType> = (OldState: StateType$1, NewState: StateType$1, OldData: DataType, NewData: DataType) => boolean;
72
169
  declare type JssmStatePermitterMaybeArray<DataType> = JssmStatePermitter<DataType> | Array<JssmStatePermitter<DataType>>;
170
+ /**
171
+ * A single key/value pair from an FSL `state X: { ... };` block, in the
172
+ * raw form produced by the parser before being condensed into a
173
+ * {@link JssmStateDeclaration}.
174
+ */
73
175
  declare type JssmStateDeclarationRule = {
74
176
  key: string;
75
177
  value: any;
76
178
  name?: string;
77
179
  };
180
+ /**
181
+ * The fully-condensed declaration for a single state, including its raw
182
+ * rule list (`declarations`) and the well-known styling fields jssm-viz
183
+ * understands. Returned by {@link Machine.state_declaration}.
184
+ */
78
185
  declare type JssmStateDeclaration = {
79
186
  declarations: Array<JssmStateDeclarationRule>;
80
187
  shape?: JssmShape;
@@ -85,12 +192,18 @@ declare type JssmStateDeclaration = {
85
192
  textColor?: JssmColor;
86
193
  backgroundColor?: JssmColor;
87
194
  borderColor?: JssmColor;
195
+ image?: string;
88
196
  state: StateType$1;
89
197
  property?: {
90
198
  name: string;
91
199
  value: unknown;
92
200
  };
93
201
  };
202
+ /**
203
+ * A loosened version of {@link JssmStateDeclaration} where every field is
204
+ * optional. Used as the value type for theme entries and for default
205
+ * state configuration where most fields will be inherited or merged.
206
+ */
94
207
  declare type JssmStateConfig = Partial<JssmStateDeclaration>;
95
208
  declare type JssmStateStyleShape = {
96
209
  key: 'shape';
@@ -124,8 +237,35 @@ declare type JssmStateStyleBorderColor = {
124
237
  key: 'border-color';
125
238
  value: JssmColor;
126
239
  };
127
- declare type JssmStateStyleKey = JssmStateStyleShape | JssmStateStyleColor | JssmStateStyleTextColor | JssmStateStyleCorners | JssmStateStyleLineStyle | JssmStateStyleBackgroundColor | JssmStateStyleStateLabel | JssmStateStyleBorderColor;
240
+ declare type JssmStateStyleImage = {
241
+ key: 'image';
242
+ value: string;
243
+ };
244
+ /**
245
+ * Tagged union of all individual style key/value pairs that may appear in
246
+ * a state's style configuration. The `key` discriminator selects which
247
+ * member, and the `value` is typed accordingly.
248
+ */
249
+ declare type JssmStateStyleKey = JssmStateStyleShape | JssmStateStyleColor | JssmStateStyleTextColor | JssmStateStyleCorners | JssmStateStyleLineStyle | JssmStateStyleBackgroundColor | JssmStateStyleStateLabel | JssmStateStyleBorderColor | JssmStateStyleImage;
250
+ /**
251
+ * An ordered list of {@link JssmStateStyleKey} entries. Used by the
252
+ * `default_*_state_config` machine config options to provide a fallback
253
+ * style stack.
254
+ */
128
255
  declare type JssmStateStyleKeyList = JssmStateStyleKey[];
256
+ /**
257
+ * Full configuration object accepted by the {@link Machine} constructor and
258
+ * by {@link from}. Carries the transition list and the optional knobs
259
+ * governing layout, theming, history, start/end states, property
260
+ * definitions, machine metadata (author, license, version, ...) and the
261
+ * runtime hook surfaces (`time_source`, `timeout_source`, ...).
262
+ *
263
+ * Most users never construct one of these directly — the `sm` tagged
264
+ * template literal and {@link from} produce one from FSL source.
265
+ *
266
+ * @typeParam StateType - The state-name type (usually `string`).
267
+ * @typeParam DataType - The user-supplied data payload type (`mDT`).
268
+ */
129
269
  declare type JssmGenericConfig<StateType, DataType> = {
130
270
  graph_layout?: JssmLayout;
131
271
  complete?: Array<StateType>;
@@ -178,6 +318,15 @@ declare type JssmGenericConfig<StateType, DataType> = {
178
318
  timeout_source?: (Function: any, number: any) => number;
179
319
  clear_timeout_source?: (number: any) => void;
180
320
  };
321
+ /**
322
+ * Internal compiler intermediate: one link in a chained transition
323
+ * expression (an "s-expression" segment). Carries both directions of an
324
+ * arrow with optional per-direction action labels, probabilities, and
325
+ * after-times. The recursive `se` field allows the parser to chain
326
+ * arrows of the form `A -> B -> C`. Not intended for end-user code.
327
+ *
328
+ * @internal
329
+ */
181
330
  declare type JssmCompileSe<StateType, mDT> = {
182
331
  to: StateType;
183
332
  se?: JssmCompileSe<StateType, mDT>;
@@ -189,6 +338,15 @@ declare type JssmCompileSe<StateType, mDT> = {
189
338
  l_after?: number;
190
339
  r_after?: number;
191
340
  };
341
+ /**
342
+ * Internal compiler intermediate: the root of a chained transition
343
+ * expression, anchored at a `from` state. Also doubles as the carrier
344
+ * for non-transition rules (state declarations, property definitions,
345
+ * machine metadata) via its `key`/`value`/`name`/`state` fields. Not
346
+ * intended for end-user code.
347
+ *
348
+ * @internal
349
+ */
192
350
  declare type JssmCompileSeStart<StateType, DataType> = {
193
351
  from: StateType;
194
352
  se: JssmCompileSe<StateType, DataType>;
@@ -199,6 +357,13 @@ declare type JssmCompileSeStart<StateType, DataType> = {
199
357
  default_value?: any;
200
358
  required?: boolean;
201
359
  };
360
+ /**
361
+ * The output shape of the FSL parser: a flat array of
362
+ * {@link JssmCompileSeStart} entries, one per top-level rule in the
363
+ * source. Consumed by the compiler to build a machine configuration.
364
+ *
365
+ * @internal
366
+ */
202
367
  declare type JssmParseTree<StateType, mDT> = Array<JssmCompileSeStart<StateType, mDT>>;
203
368
  declare type BasicHookDescription<mDT> = {
204
369
  kind: 'hook';
@@ -301,21 +466,116 @@ declare type PostExitHook<mDT> = {
301
466
  from: string;
302
467
  handler: PostHookHandler<mDT>;
303
468
  };
304
- 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>;
469
+ declare type PreEverythingHook<mDT> = {
470
+ kind: 'pre everything';
471
+ handler: EverythingHookHandler<mDT>;
472
+ };
473
+ declare type EverythingHook<mDT> = {
474
+ kind: 'everything';
475
+ handler: EverythingHookHandler<mDT>;
476
+ };
477
+ declare type PrePostEverythingHook<mDT> = {
478
+ kind: 'pre post everything';
479
+ handler: PostEverythingHookHandler<mDT>;
480
+ };
481
+ declare type PostEverythingHook<mDT> = {
482
+ kind: 'post everything';
483
+ handler: PostEverythingHookHandler<mDT>;
484
+ };
485
+ /**
486
+ * Discriminated union of every kind of hook registration jssm understands,
487
+ * pre-transition and post-transition. The `kind` field selects the
488
+ * variant; remaining fields describe which transitions / states / actions
489
+ * the hook is bound to and supply the {@link HookHandler} or
490
+ * {@link PostHookHandler} to invoke.
491
+ *
492
+ * Pre-transition variants (`'hook'`, `'named'`, `'standard transition'`,
493
+ * `'main transition'`, `'forced transition'`, `'any transition'`,
494
+ * `'global action'`, `'any action'`, `'entry'`, `'exit'`, `'after'`)
495
+ * may return a falsy value to veto a transition. Post-transition
496
+ * variants (`'post *'`) cannot veto and are invoked only after a
497
+ * successful transition.
498
+ */
499
+ 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>;
500
+ /**
501
+ * Richer hook return value used when a hook needs to do more than just
502
+ * accept or veto a transition. `pass` is the required accept/veto flag
503
+ * (kept non-optional so that returning a stray object doesn't accidentally
504
+ * veto everything). The optional `state` overrides the destination state,
505
+ * `data` overrides the data observed by other hooks in the same chain,
506
+ * and `next_data` overrides the data committed after the transition.
507
+ */
305
508
  declare type HookComplexResult<mDT> = {
306
509
  pass: boolean;
307
510
  state?: StateType$1;
308
511
  data?: mDT;
309
512
  next_data?: mDT;
310
513
  };
311
- 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 */
514
+ /**
515
+ * Return value from a {@link HookHandler}. May be a plain boolean to
516
+ * accept (`true`/`undefined`/`void`) or veto (`false`) the transition, or
517
+ * a {@link HookComplexResult} that additionally rewrites the next state
518
+ * and/or the next data payload.
519
+ */
520
+ declare type HookResult<mDT> = true | false | undefined | void | HookComplexResult<mDT>;
521
+ /**
522
+ * Context object passed to every {@link HookHandler}. `data` is the
523
+ * data payload as it stands before the transition, and `next_data` is
524
+ * the payload that will be committed if the transition is accepted —
525
+ * handlers may inspect or mutate the latter via a
526
+ * {@link HookComplexResult} return value.
527
+ */
312
528
  declare type HookContext<mDT> = {
313
529
  data: mDT;
314
530
  next_data: mDT;
315
531
  };
532
+ /**
533
+ * Context object passed to "everything" hooks ({@link EverythingHookHandler}
534
+ * and {@link PostEverythingHookHandler}). Extends the usual
535
+ * {@link HookContext} with `hook_name`, which identifies which specific
536
+ * hook fired so a single handler can route on it.
537
+ */
538
+ declare type EverythingHookContext<mDT> = HookContext<mDT> & {
539
+ hook_name: string;
540
+ };
541
+ /**
542
+ * Signature of a pre-transition hook handler. Receives the current and
543
+ * proposed-next data payloads via a {@link HookContext} and returns a
544
+ * {@link HookResult}: a falsy result vetoes the transition, a truthy
545
+ * result allows it, and a {@link HookComplexResult} can additionally
546
+ * rewrite the next state or next data.
547
+ */
316
548
  declare type HookHandler<mDT> = (hook_context: HookContext<mDT>) => HookResult<mDT>;
549
+ /**
550
+ * Signature of a post-transition hook handler. Invoked after a successful
551
+ * transition has been committed; the return value is ignored (the
552
+ * transition cannot be undone).
553
+ */
317
554
  declare type PostHookHandler<mDT> = (hook_context: HookContext<mDT>) => void;
555
+ /**
556
+ * Signature of an "everything" pre-transition hook handler. Like
557
+ * {@link HookHandler} but receives an {@link EverythingHookContext} so the
558
+ * handler can dispatch on `hook_name`.
559
+ */
560
+ declare type EverythingHookHandler<mDT> = (hook_context: EverythingHookContext<mDT>) => HookResult<mDT>;
561
+ /**
562
+ * Signature of an "everything" post-transition hook handler. Like
563
+ * {@link PostHookHandler} but receives an {@link EverythingHookContext}.
564
+ * The return value is ignored.
565
+ */
566
+ declare type PostEverythingHookHandler<mDT> = (hook_context: EverythingHookContext<mDT>) => void;
567
+ /**
568
+ * Bounded history of recently-visited states paired with the data payload
569
+ * observed in each. Backed by `circular_buffer_js`, so the oldest entry
570
+ * is dropped silently once the configured capacity is exceeded.
571
+ */
318
572
  declare type JssmHistory<mDT> = circular_buffer<[StateType$1, mDT]>;
573
+ /**
574
+ * Pluggable random-number-generator function shape. Must return a value
575
+ * in `[0, 1)` exactly as `Math.random` does. Supplied via the
576
+ * `rng_seed`-aware machine configuration so that stochastic models can be
577
+ * made reproducible.
578
+ */
319
579
  declare type JssmRng = () => number;
320
580
 
321
581
  /*********
@@ -493,6 +753,33 @@ declare function compile<StateType, mDT>(tree: JssmParseTree<StateType, mDT>): J
493
753
  */
494
754
  declare function make<StateType, mDT>(plan: string): JssmGenericConfig<StateType, mDT>;
495
755
 
756
+ /*******
757
+ *
758
+ * Selects a single item from a weighted array of objects using cumulative
759
+ * probability. Each object in the array should have a numeric property
760
+ * indicating its relative weight (defaults to `'probability'`). Objects
761
+ * missing the property are treated as weight 1.
762
+ *
763
+ * ```typescript
764
+ * const opts = [
765
+ * { value: 'common', probability: 0.8 },
766
+ * { value: 'rare', probability: 0.2 }
767
+ * ];
768
+ *
769
+ * weighted_rand_select(opts); // most often { value: 'common', ... }
770
+ * ```
771
+ *
772
+ * @param options - Non-empty array of objects to choose from.
773
+ * @param probability_property - Name of the numeric weight property on each
774
+ * object. Defaults to `'probability'`.
775
+ * @param rng - Optional random number generator `() => number`
776
+ * in `[0, 1)`. Defaults to `Math.random`.
777
+ *
778
+ * @returns One element from `options`, chosen by weighted random selection.
779
+ *
780
+ * @throws {TypeError} If `options` is not a non-empty array of objects.
781
+ *
782
+ */
496
783
  declare const weighted_rand_select: Function;
497
784
  /*******
498
785
  *
@@ -520,8 +807,68 @@ declare function seq(n: number): number[];
520
807
  *
521
808
  */
522
809
  declare const histograph: Function;
810
+ /*******
811
+ *
812
+ * Draws `n` weighted random samples from an array of objects. Each draw is
813
+ * independent (with replacement), delegating to {@link weighted_rand_select}.
814
+ *
815
+ * ```typescript
816
+ * const opts = [
817
+ * { value: 'a', probability: 0.9 },
818
+ * { value: 'b', probability: 0.1 }
819
+ * ];
820
+ *
821
+ * weighted_sample_select(3, opts, 'probability');
822
+ * // e.g. [ { value: 'a', ... }, { value: 'a', ... }, { value: 'b', ... } ]
823
+ * ```
824
+ *
825
+ * @param n - Number of samples to draw.
826
+ * @param options - Non-empty array of weighted objects.
827
+ * @param probability_property - Name of the numeric weight property.
828
+ * @param rng - Optional random number generator.
829
+ *
830
+ * @returns An array of `n` independently selected items.
831
+ *
832
+ */
523
833
  declare const weighted_sample_select: Function;
834
+ /*******
835
+ *
836
+ * Draws `n` weighted random samples, extracts a named key from each, and
837
+ * returns a histograph (`Map`) of how often each key value appeared. Useful
838
+ * for validating that a probabilistic transition distribution is roughly
839
+ * correct over many trials.
840
+ *
841
+ * ```typescript
842
+ * const opts = [
843
+ * { to: 'a', probability: 0.7 },
844
+ * { to: 'b', probability: 0.3 }
845
+ * ];
846
+ *
847
+ * weighted_histo_key(1000, opts, 'probability', 'to');
848
+ * // Map { 'a' => ~700, 'b' => ~300 }
849
+ * ```
850
+ *
851
+ * @param n - Number of samples to draw.
852
+ * @param opts - Non-empty array of weighted objects.
853
+ * @param prob_prop - Name of the numeric weight property.
854
+ * @param extract - Name of the property to extract from each sample for
855
+ * histogramming.
856
+ * @param rng - Optional random number generator.
857
+ *
858
+ * @returns A `Map` from extracted key values to their occurrence counts.
859
+ *
860
+ */
524
861
  declare const weighted_histo_key: Function;
862
+ /*******
863
+ *
864
+ * Creates a SplitMix32 random generator. Used by the randomness test suite.
865
+ *
866
+ * Sourced from `bryc`: https://github.com/bryc/code/blob/master/jshash/PRNGs.md#splitmix32
867
+ *
868
+ * Replaces the Mulberry generator, which was found to have problems
869
+ *
870
+ */
871
+ declare function gen_splitmix32(a?: number | undefined): () => number;
525
872
  /*******
526
873
  *
527
874
  * Reduces an array to its unique contents. Compares with `===` and makes no
@@ -538,7 +885,7 @@ declare const weighted_histo_key: Function;
538
885
  * ```
539
886
  *
540
887
  */
541
- declare const unique: <T>(arr?: T[]) => T[];
888
+ declare const unique: <T>(arr: T[]) => T[];
542
889
  /*******
543
890
  *
544
891
  * Lists all repeated items in an array along with their counts. Subject to
@@ -558,8 +905,33 @@ declare const unique: <T>(arr?: T[]) => T[];
558
905
  *
559
906
  */
560
907
  declare function find_repeated<T>(arr: T[]): [T, number][];
908
+ /*******
909
+ *
910
+ * Returns a `Promise` that resolves after `ms` milliseconds. Useful for
911
+ * inserting delays in async test flows or demos.
912
+ *
913
+ * ```typescript
914
+ * await sleep(100); // pauses execution for 100ms
915
+ * ```
916
+ *
917
+ * @param ms - Number of milliseconds to wait before resolving.
918
+ *
919
+ * @returns A `Promise<void>` that resolves after the timeout.
920
+ *
921
+ */
561
922
  declare function sleep(ms: number): Promise<unknown>;
562
923
 
924
+ /*******
925
+ *
926
+ * Convenience aliases for common mathematical and numeric constants from
927
+ * `Number` and `Math`. Re-exported so that FSL data expressions and tests
928
+ * can reference them without importing `Math` directly.
929
+ *
930
+ * Includes: `NegInfinity`, `PosInfinity`, `Epsilon`, `Pi`, `E`, `Root2`,
931
+ * `RootHalf`, `Ln2`, `Ln10`, `Log2E`, `Log10E`, `MaxSafeInt`, `MinSafeInt`,
932
+ * `MaxPosNum`, `MinPosNum`, `Phi` (golden ratio), `EulerC` (Euler–Mascheroni).
933
+ *
934
+ */
563
935
  declare const NegInfinity: number;
564
936
  declare const PosInfinity: number;
565
937
  declare const Epsilon: number;
@@ -577,8 +949,29 @@ declare const MaxPosNum: number;
577
949
  declare const MinPosNum: number;
578
950
  declare const Phi = 1.618033988749895;
579
951
  declare const EulerC = 0.5772156649015329;
952
+ /*******
953
+ *
954
+ * Complete list of node shapes supported by Graphviz. Used by jssm-viz to
955
+ * validate and render state shapes in FSL `state ... : { shape: ... }` blocks.
956
+ *
957
+ * `shapes` is an alias for `gviz_shapes`.
958
+ *
959
+ */
580
960
  declare const gviz_shapes$1: string[];
961
+ /**
962
+ * Public alias for {@link gviz_shapes}. The list of node shapes supported
963
+ * by Graphviz that jssm-viz accepts in FSL `state ... : { shape: ... }`
964
+ * declarations.
965
+ */
581
966
  declare const shapes$1: string[];
967
+ /*******
968
+ *
969
+ * List of CSS/SVG named colors accepted by jssm-viz for state styling
970
+ * properties like `background-color` and `text-color`. Case-insensitive
971
+ * matching is done at parse time; the canonical casing here follows the
972
+ * CSS specification.
973
+ *
974
+ */
582
975
  declare const named_colors$1: string[];
583
976
 
584
977
  declare const jssm_constants_d_E: typeof E;
@@ -599,7 +992,28 @@ declare const jssm_constants_d_PosInfinity: typeof PosInfinity;
599
992
  declare const jssm_constants_d_Root2: typeof Root2;
600
993
  declare const jssm_constants_d_RootHalf: typeof RootHalf;
601
994
  declare namespace jssm_constants_d {
602
- export { jssm_constants_d_E as E, jssm_constants_d_Epsilon as Epsilon, jssm_constants_d_EulerC as EulerC, jssm_constants_d_Ln10 as Ln10, jssm_constants_d_Ln2 as Ln2, jssm_constants_d_Log10E as Log10E, jssm_constants_d_Log2E as Log2E, jssm_constants_d_MaxPosNum as MaxPosNum, jssm_constants_d_MaxSafeInt as MaxSafeInt, jssm_constants_d_MinPosNum as MinPosNum, jssm_constants_d_MinSafeInt as MinSafeInt, jssm_constants_d_NegInfinity as NegInfinity, jssm_constants_d_Phi as Phi, jssm_constants_d_Pi as Pi, jssm_constants_d_PosInfinity as PosInfinity, jssm_constants_d_Root2 as Root2, jssm_constants_d_RootHalf as RootHalf, gviz_shapes$1 as gviz_shapes, named_colors$1 as named_colors, shapes$1 as shapes };
995
+ export {
996
+ jssm_constants_d_E as E,
997
+ jssm_constants_d_Epsilon as Epsilon,
998
+ jssm_constants_d_EulerC as EulerC,
999
+ jssm_constants_d_Ln10 as Ln10,
1000
+ jssm_constants_d_Ln2 as Ln2,
1001
+ jssm_constants_d_Log10E as Log10E,
1002
+ jssm_constants_d_Log2E as Log2E,
1003
+ jssm_constants_d_MaxPosNum as MaxPosNum,
1004
+ jssm_constants_d_MaxSafeInt as MaxSafeInt,
1005
+ jssm_constants_d_MinPosNum as MinPosNum,
1006
+ jssm_constants_d_MinSafeInt as MinSafeInt,
1007
+ jssm_constants_d_NegInfinity as NegInfinity,
1008
+ jssm_constants_d_Phi as Phi,
1009
+ jssm_constants_d_Pi as Pi,
1010
+ jssm_constants_d_PosInfinity as PosInfinity,
1011
+ jssm_constants_d_Root2 as Root2,
1012
+ jssm_constants_d_RootHalf as RootHalf,
1013
+ gviz_shapes$1 as gviz_shapes,
1014
+ named_colors$1 as named_colors,
1015
+ shapes$1 as shapes,
1016
+ };
603
1017
  }
604
1018
 
605
1019
  declare const version: string;
@@ -621,7 +1035,69 @@ declare const named_colors: string[];
621
1035
  *
622
1036
  */
623
1037
  declare function transfer_state_properties(state_decl: JssmStateDeclaration): JssmStateDeclaration;
624
- declare function state_style_condense(jssk: JssmStateStyleKeyList): JssmStateConfig;
1038
+ /**
1039
+ *
1040
+ * Collapse a list of individual state-style key/value pairs into a single
1041
+ * {@link JssmStateConfig} object, remapping FSL-style kebab-case keys to the
1042
+ * camelCase field names the runtime uses.
1043
+ *
1044
+ * The parser emits state styling as a flat array like
1045
+ * `[{ key: 'color', value: 'red' }, { key: 'line-style', value: 'dashed' }]`
1046
+ * because that is the most natural shape for the grammar to produce. This
1047
+ * helper runs once per style bucket during `Machine` construction to turn
1048
+ * those arrays into the compact `{ color, lineStyle, ... }` objects the
1049
+ * graph-rendering code expects.
1050
+ *
1051
+ * ```typescript
1052
+ * state_style_condense([
1053
+ * { key: 'color', value: 'red' },
1054
+ * { key: 'shape', value: 'oval' },
1055
+ * { key: 'line-style', value: 'dashed' }
1056
+ * ]);
1057
+ * // => { color: 'red', shape: 'oval', lineStyle: 'dashed' }
1058
+ *
1059
+ * state_style_condense(undefined);
1060
+ * // => {}
1061
+ * ```
1062
+ *
1063
+ * @param jssk The list of style keys to condense. `undefined` is accepted
1064
+ * and yields an empty config.
1065
+ *
1066
+ * @param machine Optional `Machine` reference, used only so that any
1067
+ * {@link JssmError} thrown can point at the offending machine in its
1068
+ * diagnostic message.
1069
+ *
1070
+ * @returns A `JssmStateConfig` object containing every key from `jssk`
1071
+ * remapped into its camelCase field.
1072
+ *
1073
+ * @throws {JssmError} If `jssk` is neither an array nor `undefined`, if any
1074
+ * element is not an object, if the same key appears more than once, or if a
1075
+ * key is not one of the recognized style names.
1076
+ *
1077
+ * @internal
1078
+ *
1079
+ */
1080
+ declare function state_style_condense(jssk: JssmStateStyleKeyList, machine?: any): JssmStateConfig;
1081
+ /*******
1082
+ *
1083
+ * Core finite state machine class. Holds the full graph of states and
1084
+ * transitions, the current state, hooks, data, properties, and all runtime
1085
+ * behavior. Typically created via the {@link sm} tagged template literal
1086
+ * rather than constructed directly.
1087
+ *
1088
+ * ```typescript
1089
+ * import { sm } from 'jssm';
1090
+ *
1091
+ * const light = sm`Red 'next' => Green 'next' => Yellow 'next' => Red;`;
1092
+ * light.state(); // 'Red'
1093
+ * light.action('next'); // true
1094
+ * light.state(); // 'Green'
1095
+ * ```
1096
+ *
1097
+ * @typeparam mDT The machine data type — the type of the value stored in
1098
+ * `.data()`. Defaults to `undefined` when no data is used.
1099
+ *
1100
+ */
625
1101
  declare class Machine<mDT> {
626
1102
  _state: StateType;
627
1103
  _states: Map<StateType, JssmGenericState>;
@@ -694,6 +1170,10 @@ declare class Machine<mDT> {
694
1170
  _post_main_transition_hook: HookHandler<mDT> | undefined;
695
1171
  _post_forced_transition_hook: HookHandler<mDT> | undefined;
696
1172
  _post_any_transition_hook: HookHandler<mDT> | undefined;
1173
+ _pre_everything_hook: EverythingHookHandler<mDT> | undefined;
1174
+ _everything_hook: EverythingHookHandler<mDT> | undefined;
1175
+ _pre_post_everything_hook: PostEverythingHookHandler<mDT> | undefined;
1176
+ _post_everything_hook: PostEverythingHookHandler<mDT> | undefined;
697
1177
  _property_keys: Set<string>;
698
1178
  _default_properties: Map<string, any>;
699
1179
  _state_properties: Map<string, any>;
@@ -741,6 +1221,8 @@ declare class Machine<mDT> {
741
1221
  *
742
1222
  * @typeparam mDT The type of the machine data member; usually omitted
743
1223
  *
1224
+ * @returns The current state name.
1225
+ *
744
1226
  */
745
1227
  state(): StateType;
746
1228
  /*********
@@ -759,6 +1241,10 @@ declare class Machine<mDT> {
759
1241
  *
760
1242
  * @typeparam mDT The type of the machine data member; usually omitted
761
1243
  *
1244
+ * @param state The state to get the label for.
1245
+ *
1246
+ * @returns The label string, or `undefined` if no label is set.
1247
+ *
762
1248
  */
763
1249
  label_for(state: StateType): string;
764
1250
  /*********
@@ -782,6 +1268,10 @@ declare class Machine<mDT> {
782
1268
  *
783
1269
  * @typeparam mDT The type of the machine data member; usually omitted
784
1270
  *
1271
+ * @param state The state to get display text for.
1272
+ *
1273
+ * @returns The label if one exists, otherwise the state's name.
1274
+ *
785
1275
  */
786
1276
  display_text(state: StateType): string;
787
1277
  /*********
@@ -797,45 +1287,60 @@ declare class Machine<mDT> {
797
1287
  *
798
1288
  * @typeparam mDT The type of the machine data member; usually omitted
799
1289
  *
1290
+ * @returns A deep clone of the machine's current data value.
1291
+ *
800
1292
  */
801
1293
  data(): mDT;
802
1294
  /*********
803
1295
  *
804
- * Get the current value of a given property name.
1296
+ * Get the current value of a given property name. Checks the current
1297
+ * state's properties first, then falls back to the global default.
1298
+ * Returns `undefined` if neither exists. For a throwing variant, see
1299
+ * {@link strict_prop}.
805
1300
  *
806
1301
  * ```typescript
1302
+ * const m = sm`property color default "grey"; a -> b;
1303
+ * state b: { property color "blue"; };`;
807
1304
  *
1305
+ * m.prop('color'); // 'grey' (default, because state is 'a')
1306
+ * m.go('b');
1307
+ * m.prop('color'); // 'blue' (state 'b' overrides the default)
1308
+ * m.prop('size'); // undefined (no such property)
808
1309
  * ```
809
1310
  *
810
- * @param name The relevant property name to look up
1311
+ * @param name The relevant property name to look up.
811
1312
  *
812
- * @returns The value behind the prop name. Because functional props are
813
- * evaluated as getters, this can be anything.
1313
+ * @returns The value behind the prop name, or `undefined` if not defined.
814
1314
  *
815
1315
  */
816
1316
  prop(name: string): any;
817
1317
  /*********
818
1318
  *
819
1319
  * Get the current value of a given property name. If missing on the state
820
- * and without a global default, throw, unlike {@link prop}, which would
821
- * return `undefined` instead.
1320
+ * and without a global default, throws a {@link JssmError}, unlike
1321
+ * {@link prop}, which would return `undefined` instead.
822
1322
  *
823
1323
  * ```typescript
1324
+ * const m = sm`property color default "grey"; a -> b;`;
824
1325
  *
1326
+ * m.strict_prop('color'); // 'grey'
1327
+ * m.strict_prop('size'); // throws JssmError
825
1328
  * ```
826
1329
  *
827
- * @param name The relevant property name to look up
1330
+ * @param name The relevant property name to look up.
828
1331
  *
829
- * @returns The value behind the prop name. Because functional props are
830
- * evaluated as getters, this can be anything.
1332
+ * @returns The value behind the prop name.
1333
+ *
1334
+ * @throws {JssmError} If the property is not defined on the current state
1335
+ * and has no default.
831
1336
  *
832
1337
  */
833
1338
  strict_prop(name: string): any;
834
1339
  /*********
835
1340
  *
836
1341
  * Get the current value of every prop, as an object. If no current definition
837
- * exists for a prop - that is, if the prop was defined without a default and
838
- * the current state also doesn't define the prop - then that prop will be listed
1342
+ * exists for a prop that is, if the prop was defined without a default and
1343
+ * the current state also doesn't define the prop then that prop will be listed
839
1344
  * in the returned object with a value of `undefined`.
840
1345
  *
841
1346
  * ```typescript
@@ -866,29 +1371,12 @@ declare class Machine<mDT> {
866
1371
  * traffic_light.props(); // { can_go: true, hesitate: false, stop_first: false; }
867
1372
  * ```
868
1373
  *
869
- */
870
- props(): object;
871
- /*********
872
- *
873
- * Get the current value of every prop, as an object. Compare
874
- * {@link prop_map}, which returns a `Map`.
875
- *
876
- * ```typescript
877
- *
878
- * ```
879
- *
880
- */
881
- /*********
882
- *
883
- * Get the current value of every prop, as an object. Compare
884
- * {@link prop_map}, which returns a `Map`. Akin to {@link strict_prop},
885
- * this throws if a required prop is missing.
886
- *
887
- * ```typescript
888
- *
889
- * ```
1374
+ * @returns An object mapping every known property name to its current value
1375
+ * (or `undefined` if the property has no default and the current state
1376
+ * doesn't define it).
890
1377
  *
891
1378
  */
1379
+ props(): object;
892
1380
  /*********
893
1381
  *
894
1382
  * Check whether a given string is a known property's name.
@@ -911,8 +1399,13 @@ declare class Machine<mDT> {
911
1399
  * the properties generally will not be sorted.
912
1400
  *
913
1401
  * ```typescript
1402
+ * const m = sm`property color default "grey"; property size default 1; a -> b;`;
1403
+ *
1404
+ * m.known_props(); // ['color', 'size']
914
1405
  * ```
915
1406
  *
1407
+ * @returns An array of all property name strings defined on this machine.
1408
+ *
916
1409
  */
917
1410
  known_props(): string[];
918
1411
  /********
@@ -1011,22 +1504,78 @@ declare class Machine<mDT> {
1011
1504
  *
1012
1505
  * @typeparam mDT The type of the machine data member; usually omitted
1013
1506
  *
1507
+ * @param comment An optional comment string to embed in the serialized
1508
+ * output for identification or debugging.
1509
+ *
1510
+ * @returns A {@link JssmSerialization} object containing the machine's
1511
+ * current state, data, and timestamp.
1512
+ *
1014
1513
  */
1015
1514
  serialize(comment?: string | undefined): JssmSerialization<mDT>;
1515
+ /** Get the graph layout direction (e.g. `'LR'`, `'TB'`). Set via the
1516
+ * FSL `graph_layout` directive.
1517
+ * @returns The layout string, or the default if not set.
1518
+ */
1016
1519
  graph_layout(): string;
1520
+ /** Get the Graphviz DOT preamble string, injected before the graph body
1521
+ * during visualization. Set via the FSL `dot_preamble` directive.
1522
+ * @returns The preamble string.
1523
+ */
1017
1524
  dot_preamble(): string;
1525
+ /** Get the machine's author list. Set via the FSL `machine_author` directive.
1526
+ * @returns An array of author name strings.
1527
+ */
1018
1528
  machine_author(): Array<string>;
1529
+ /** Get the machine's comment string. Set via the FSL `machine_comment` directive.
1530
+ * @returns The comment string.
1531
+ */
1019
1532
  machine_comment(): string;
1533
+ /** Get the machine's contributor list. Set via the FSL `machine_contributor` directive.
1534
+ * @returns An array of contributor name strings.
1535
+ */
1020
1536
  machine_contributor(): Array<string>;
1537
+ /** Get the machine's definition string. Set via the FSL `machine_definition` directive.
1538
+ * @returns The definition string.
1539
+ */
1021
1540
  machine_definition(): string;
1541
+ /** Get the machine's language (ISO 639-1). Set via the FSL `machine_language` directive.
1542
+ * @returns The language code string.
1543
+ */
1022
1544
  machine_language(): string;
1545
+ /** Get the machine's license string. Set via the FSL `machine_license` directive.
1546
+ * @returns The license string.
1547
+ */
1023
1548
  machine_license(): string;
1549
+ /** Get the machine's name. Set via the FSL `machine_name` directive.
1550
+ * @returns The machine name string.
1551
+ */
1024
1552
  machine_name(): string;
1553
+ /** Get the machine's version string. Set via the FSL `machine_version` directive.
1554
+ * @returns The version string.
1555
+ */
1025
1556
  machine_version(): string;
1557
+ /** Get the raw state declaration objects as parsed from the FSL source.
1558
+ * @returns An array of raw state declaration objects.
1559
+ */
1026
1560
  raw_state_declarations(): Array<Object>;
1561
+ /** Get the processed state declaration for a specific state.
1562
+ * @param which - The state to look up.
1563
+ * @returns The {@link JssmStateDeclaration} for the given state.
1564
+ */
1027
1565
  state_declaration(which: StateType): JssmStateDeclaration;
1566
+ /** Get all processed state declarations as a Map.
1567
+ * @returns A `Map` from state name to {@link JssmStateDeclaration}.
1568
+ */
1028
1569
  state_declarations(): Map<StateType, JssmStateDeclaration>;
1570
+ /** Get the FSL language version this machine was compiled under.
1571
+ * @returns The FSL version string.
1572
+ */
1029
1573
  fsl_version(): string;
1574
+ /** Get the complete internal state of the machine as a serializable
1575
+ * structure. Includes actions, edges, edge map, named transitions,
1576
+ * reverse actions, current state, and states map.
1577
+ * @returns A {@link JssmMachineInternalState} snapshot.
1578
+ */
1030
1579
  machine_state(): JssmMachineInternalState<mDT>;
1031
1580
  /*********
1032
1581
  *
@@ -1042,8 +1591,15 @@ declare class Machine<mDT> {
1042
1591
  *
1043
1592
  * @typeparam mDT The type of the machine data member; usually omitted
1044
1593
  *
1594
+ * @returns An array of all state names in the machine.
1595
+ *
1045
1596
  */
1046
1597
  states(): Array<StateType>;
1598
+ /** Get the internal state descriptor for a given state name.
1599
+ * @param whichState - The state to look up.
1600
+ * @returns The {@link JssmGenericState} descriptor.
1601
+ * @throws {JssmError} If the state does not exist.
1602
+ */
1047
1603
  state_for(whichState: StateType): JssmGenericState;
1048
1604
  /*********
1049
1605
  *
@@ -1060,7 +1616,9 @@ declare class Machine<mDT> {
1060
1616
  *
1061
1617
  * @typeparam mDT The type of the machine data member; usually omitted
1062
1618
  *
1063
- * @param whichState The state to be checked for extance
1619
+ * @param whichState The state to be checked for existence.
1620
+ *
1621
+ * @returns `true` if the state exists, `false` otherwise.
1064
1622
  *
1065
1623
  */
1066
1624
  has_state(whichState: StateType): boolean;
@@ -1096,35 +1654,82 @@ declare class Machine<mDT> {
1096
1654
  *
1097
1655
  * @typeparam mDT The type of the machine data member; usually omitted
1098
1656
  *
1657
+ * @returns An array of all {@link JssmTransition} edge objects.
1658
+ *
1099
1659
  */
1100
1660
  list_edges(): Array<JssmTransition<StateType, mDT>>;
1661
+ /** Get the map of named transitions (transitions with explicit names).
1662
+ * @returns A `Map` from transition name to edge index.
1663
+ */
1101
1664
  list_named_transitions(): Map<StateType, number>;
1665
+ /** List all distinct action names defined anywhere in the machine.
1666
+ * @returns An array of action name strings.
1667
+ */
1102
1668
  list_actions(): Array<StateType>;
1669
+ /** Whether any actions are defined on this machine.
1670
+ * @returns `true` if the machine has at least one action.
1671
+ */
1103
1672
  get uses_actions(): boolean;
1673
+ /** Whether any forced (`~>`) transitions exist in this machine.
1674
+ * @returns `true` if at least one forced transition is defined.
1675
+ */
1104
1676
  get uses_forced_transitions(): boolean;
1105
1677
  /*********
1106
1678
  *
1107
1679
  * Check if the code that built the machine allows overriding state and data.
1108
1680
  *
1681
+ * @returns The override permission from the FSL source code.
1682
+ *
1109
1683
  */
1110
1684
  get code_allows_override(): JssmAllowsOverride;
1111
1685
  /*********
1112
1686
  *
1113
1687
  * Check if the machine config allows overriding state and data.
1114
1688
  *
1689
+ * @returns The override permission from the runtime config.
1690
+ *
1115
1691
  */
1116
1692
  get config_allows_override(): JssmAllowsOverride;
1117
1693
  /*********
1118
1694
  *
1119
- * Check if a machine allows overriding state and data.
1695
+ * Check if a machine allows overriding state and data. Resolves the
1696
+ * combined effect of code and config permissions — config may not be
1697
+ * less strict than code.
1698
+ *
1699
+ * @returns The effective override permission.
1120
1700
  *
1121
1701
  */
1122
1702
  get allows_override(): JssmAllowsOverride;
1703
+ /** List all available theme names.
1704
+ * @returns An array of theme name strings.
1705
+ */
1123
1706
  all_themes(): FslTheme[];
1707
+ /** Get the active theme(s) for this machine. Always stored as an array
1708
+ * internally; the union return type exists for setter compatibility.
1709
+ * @returns The current theme or array of themes.
1710
+ */
1124
1711
  get themes(): FslTheme | FslTheme[];
1712
+ /** Set the active theme(s). Accepts a single theme name or an array.
1713
+ * @param to - A theme name or array of theme names to apply.
1714
+ */
1125
1715
  set themes(to: FslTheme | FslTheme[]);
1716
+ /** Get the flow direction for graph layout (e.g. `'right'`, `'down'`).
1717
+ * Set via the FSL `flow` directive.
1718
+ * @returns The current flow direction.
1719
+ */
1126
1720
  flow(): FslDirection;
1721
+ /** Look up a transition's edge index by source and target state names.
1722
+ * @param from - Source state name.
1723
+ * @param to - Target state name.
1724
+ * @returns The edge index in the edges array, or `undefined` if no
1725
+ * such transition exists.
1726
+ */
1127
1727
  get_transition_by_state_names(from: StateType, to: StateType): number;
1728
+ /** Look up the full transition object for a given source→target pair.
1729
+ * @param from - Source state name.
1730
+ * @param to - Target state name.
1731
+ * @returns The {@link JssmTransition} object, or `undefined` if none exists.
1732
+ */
1128
1733
  lookup_transition_for(from: StateType, to: StateType): JssmTransition<StateType, mDT>;
1129
1734
  /********
1130
1735
  *
@@ -1192,9 +1797,29 @@ declare class Machine<mDT> {
1192
1797
  *
1193
1798
  */
1194
1799
  list_exits(whichState?: StateType): Array<StateType>;
1800
+ /** Get the transitions available from a state, filtered to those with
1801
+ * probability data. Used by the probabilistic walk system.
1802
+ * @param whichState - The state to inspect.
1803
+ * @returns An array of {@link JssmTransition} edges exiting the state.
1804
+ * @throws {JssmError} If the state does not exist.
1805
+ */
1195
1806
  probable_exits_for(whichState: StateType): Array<JssmTransition<StateType, mDT>>;
1807
+ /** Take a single random transition from the current state, weighted by
1808
+ * edge probabilities.
1809
+ * @returns `true` if a transition was taken, `false` otherwise.
1810
+ */
1196
1811
  probabilistic_transition(): boolean;
1812
+ /** Take `n` consecutive probabilistic transitions and return the sequence
1813
+ * of states visited (before each transition).
1814
+ * @param n - Number of steps to walk.
1815
+ * @returns An array of state names visited during the walk.
1816
+ */
1197
1817
  probabilistic_walk(n: number): Array<StateType>;
1818
+ /** Take `n` probabilistic steps and return a histograph of how many times
1819
+ * each state was visited.
1820
+ * @param n - Number of steps to walk.
1821
+ * @returns A `Map` from state name to visit count.
1822
+ */
1198
1823
  probabilistic_histo_walk(n: number): Map<StateType, number>;
1199
1824
  /********
1200
1825
  *
@@ -1227,7 +1852,10 @@ declare class Machine<mDT> {
1227
1852
  *
1228
1853
  * @typeparam mDT The type of the machine data member; usually omitted
1229
1854
  *
1230
- * @param whichState The state whose actions to have listed
1855
+ * @param whichState The state whose actions to list. Defaults to the
1856
+ * current state.
1857
+ *
1858
+ * @returns An array of action names available from the given state.
1231
1859
  *
1232
1860
  */
1233
1861
  actions(whichState?: StateType): Array<StateType>;
@@ -1254,40 +1882,276 @@ declare class Machine<mDT> {
1254
1882
  *
1255
1883
  */
1256
1884
  list_states_having_action(whichState: StateType): Array<StateType>;
1885
+ /** List all action names available as exits from a given state.
1886
+ * @param whichState - The state to inspect. Defaults to the current state.
1887
+ * @returns An array of action name strings.
1888
+ * @throws {JssmError} If the state does not exist.
1889
+ */
1257
1890
  list_exit_actions(whichState?: StateType): Array<StateType>;
1891
+ /** List all action exits from a state with their probabilities.
1892
+ * @param whichState - The state to inspect. Defaults to the current state.
1893
+ * @returns An array of `{ action, probability }` objects.
1894
+ * @throws {JssmError} If the state does not exist.
1895
+ */
1258
1896
  probable_action_exits(whichState?: StateType): Array<any>;
1897
+ /** Check whether a state has no incoming transitions (unreachable after start).
1898
+ * @param whichState - The state to check.
1899
+ * @returns `true` if the state has zero entrances.
1900
+ * @throws {JssmError} If the state does not exist.
1901
+ */
1259
1902
  is_unenterable(whichState: StateType): boolean;
1903
+ /** Check whether any state in the machine is unenterable.
1904
+ * @returns `true` if at least one state has no incoming transitions.
1905
+ */
1260
1906
  has_unenterables(): boolean;
1907
+ /** Check whether the current state is terminal (has no exits).
1908
+ * @returns `true` if the current state has zero exits.
1909
+ */
1261
1910
  is_terminal(): boolean;
1911
+ /** Check whether a specific state is terminal (has no exits).
1912
+ * @param whichState - The state to check.
1913
+ * @returns `true` if the state has zero exits.
1914
+ * @throws {JssmError} If the state does not exist.
1915
+ */
1262
1916
  state_is_terminal(whichState: StateType): boolean;
1917
+ /** Check whether any state in the machine is terminal.
1918
+ * @returns `true` if at least one state has no exits.
1919
+ */
1263
1920
  has_terminals(): boolean;
1921
+ /** Check whether the current state is complete (every exit has an action).
1922
+ * @returns `true` if the current state is complete.
1923
+ */
1264
1924
  is_complete(): boolean;
1925
+ /** Check whether a specific state is complete (every exit has an action).
1926
+ * @param whichState - The state to check.
1927
+ * @returns `true` if the state is complete.
1928
+ * @throws {JssmError} If the state does not exist.
1929
+ */
1265
1930
  state_is_complete(whichState: StateType): boolean;
1931
+ /** Check whether any state in the machine is complete.
1932
+ * @returns `true` if at least one state is complete.
1933
+ */
1266
1934
  has_completes(): boolean;
1935
+ /** Low-level hook registration. Installs a handler described by a
1936
+ * {@link HookDescription} into the appropriate internal map. Prefer the
1937
+ * convenience wrappers ({@link hook}, {@link hook_entry}, etc.) over
1938
+ * calling this directly.
1939
+ * @param HookDesc - A hook descriptor specifying kind, states, and handler.
1940
+ */
1267
1941
  set_hook(HookDesc: HookDescription<mDT>): void;
1942
+ /** Register a pre-transition hook on a specific edge. Fires before
1943
+ * transitioning from `from` to `to`. If the handler returns `false`, the
1944
+ * transition is blocked.
1945
+ *
1946
+ * ```typescript
1947
+ * const m = sm`a -> b -> c;`;
1948
+ * m.hook('a', 'b', () => console.log('a->b'));
1949
+ * ```
1950
+ *
1951
+ * @param from - Source state name.
1952
+ * @param to - Target state name.
1953
+ * @param handler - Callback invoked before the transition.
1954
+ * @returns `this` for chaining.
1955
+ */
1268
1956
  hook(from: string, to: string, handler: HookHandler<mDT>): Machine<mDT>;
1957
+ /** Register a pre-transition hook on a specific action-labeled edge.
1958
+ * @param from - Source state name.
1959
+ * @param to - Target state name.
1960
+ * @param action - The action label that triggers this hook.
1961
+ * @param handler - Callback invoked before the transition.
1962
+ * @returns `this` for chaining.
1963
+ */
1269
1964
  hook_action(from: string, to: string, action: string, handler: HookHandler<mDT>): Machine<mDT>;
1965
+ /** Register a pre-transition hook on any edge triggered by a specific action.
1966
+ * @param action - The action name to hook.
1967
+ * @param handler - Callback invoked before any transition with this action.
1968
+ * @returns `this` for chaining.
1969
+ */
1270
1970
  hook_global_action(action: string, handler: HookHandler<mDT>): Machine<mDT>;
1971
+ /** Register a pre-transition hook on any action-driven transition.
1972
+ * @param handler - Callback invoked before any action transition.
1973
+ * @returns `this` for chaining.
1974
+ */
1271
1975
  hook_any_action(handler: HookHandler<mDT>): Machine<mDT>;
1976
+ /** Register a pre-transition hook on any standard (`->`) transition.
1977
+ * @param handler - Callback invoked before any legal transition.
1978
+ * @returns `this` for chaining.
1979
+ */
1272
1980
  hook_standard_transition(handler: HookHandler<mDT>): Machine<mDT>;
1981
+ /** Register a pre-transition hook on any main-path (`=>`) transition.
1982
+ * @param handler - Callback invoked before any main transition.
1983
+ * @returns `this` for chaining.
1984
+ */
1273
1985
  hook_main_transition(handler: HookHandler<mDT>): Machine<mDT>;
1986
+ /** Register a pre-transition hook on any forced (`~>`) transition.
1987
+ * @param handler - Callback invoked before any forced transition.
1988
+ * @returns `this` for chaining.
1989
+ */
1274
1990
  hook_forced_transition(handler: HookHandler<mDT>): Machine<mDT>;
1991
+ /** Register a pre-transition hook on any transition regardless of kind.
1992
+ * @param handler - Callback invoked before every transition.
1993
+ * @returns `this` for chaining.
1994
+ */
1275
1995
  hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
1996
+ /** Register a hook that fires when entering a specific state.
1997
+ * @param to - The state being entered.
1998
+ * @param handler - Callback invoked on entry.
1999
+ * @returns `this` for chaining.
2000
+ */
1276
2001
  hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
2002
+ /** Register a hook that fires when leaving a specific state.
2003
+ * @param from - The state being exited.
2004
+ * @param handler - Callback invoked on exit.
2005
+ * @returns `this` for chaining.
2006
+ */
1277
2007
  hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
2008
+ /** Register a hook that fires after leaving a specific state (post-exit).
2009
+ * @param from - The state that was exited.
2010
+ * @param handler - Callback invoked after exit completes.
2011
+ * @returns `this` for chaining.
2012
+ */
1278
2013
  hook_after(from: string, handler: HookHandler<mDT>): Machine<mDT>;
2014
+ /** Post-transition hook on a specific edge. Fires after the transition
2015
+ * from `from` to `to` has completed. Cannot block the transition.
2016
+ * @param from - Source state name.
2017
+ * @param to - Target state name.
2018
+ * @param handler - Callback invoked after the transition.
2019
+ * @returns `this` for chaining.
2020
+ */
1279
2021
  post_hook(from: string, to: string, handler: HookHandler<mDT>): Machine<mDT>;
2022
+ /** Post-transition hook on a specific action-labeled edge.
2023
+ * @param from - Source state name.
2024
+ * @param to - Target state name.
2025
+ * @param action - The action label.
2026
+ * @param handler - Callback invoked after the transition.
2027
+ * @returns `this` for chaining.
2028
+ */
1280
2029
  post_hook_action(from: string, to: string, action: string, handler: HookHandler<mDT>): Machine<mDT>;
2030
+ /** Post-transition hook on any edge triggered by a specific action.
2031
+ * @param action - The action name.
2032
+ * @param handler - Callback invoked after any transition with this action.
2033
+ * @returns `this` for chaining.
2034
+ */
1281
2035
  post_hook_global_action(action: string, handler: HookHandler<mDT>): Machine<mDT>;
2036
+ /** Post-transition hook on any action-driven transition.
2037
+ * @param handler - Callback invoked after any action transition.
2038
+ * @returns `this` for chaining.
2039
+ */
1282
2040
  post_hook_any_action(handler: HookHandler<mDT>): Machine<mDT>;
2041
+ /** Post-transition hook on any standard (`->`) transition.
2042
+ * @param handler - Callback invoked after any legal transition.
2043
+ * @returns `this` for chaining.
2044
+ */
1283
2045
  post_hook_standard_transition(handler: HookHandler<mDT>): Machine<mDT>;
2046
+ /** Post-transition hook on any main-path (`=>`) transition.
2047
+ * @param handler - Callback invoked after any main transition.
2048
+ * @returns `this` for chaining.
2049
+ */
1284
2050
  post_hook_main_transition(handler: HookHandler<mDT>): Machine<mDT>;
2051
+ /** Post-transition hook on any forced (`~>`) transition.
2052
+ * @param handler - Callback invoked after any forced transition.
2053
+ * @returns `this` for chaining.
2054
+ */
1285
2055
  post_hook_forced_transition(handler: HookHandler<mDT>): Machine<mDT>;
2056
+ /** Post-transition hook on any transition regardless of kind.
2057
+ * @param handler - Callback invoked after every transition.
2058
+ * @returns `this` for chaining.
2059
+ */
1286
2060
  post_hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
2061
+ /** Post-transition hook that fires after entering a specific state.
2062
+ * @param to - The state that was entered.
2063
+ * @param handler - Callback invoked after entry.
2064
+ * @returns `this` for chaining.
2065
+ */
1287
2066
  post_hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
2067
+ /** Post-transition hook that fires after leaving a specific state.
2068
+ * @param from - The state that was exited.
2069
+ * @param handler - Callback invoked after exit.
2070
+ * @returns `this` for chaining.
2071
+ */
1288
2072
  post_hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
2073
+ /** Register a pre-transition hook that fires **before** all other pre-hooks
2074
+ * on every transition. If the handler returns `false`, the transition is
2075
+ * blocked. The handler receives an {@link EverythingHookContext} whose
2076
+ * `hook_name` is `'pre everything'`.
2077
+ *
2078
+ * ```typescript
2079
+ * const m = sm`a -> b -> c;`;
2080
+ * m.hook_pre_everything(({ hook_name }) => {
2081
+ * console.log(`${hook_name} fired`);
2082
+ * return true;
2083
+ * });
2084
+ * ```
2085
+ *
2086
+ * @param handler - Callback invoked before all other pre-hooks.
2087
+ * @returns `this` for chaining.
2088
+ */
2089
+ hook_pre_everything(handler: EverythingHookHandler<mDT>): Machine<mDT>;
2090
+ /** Register a pre-transition hook that fires **after** all other pre-hooks
2091
+ * on every transition. If the handler returns `false`, the transition is
2092
+ * blocked. The handler receives an {@link EverythingHookContext} whose
2093
+ * `hook_name` is `'everything'`.
2094
+ *
2095
+ * ```typescript
2096
+ * const m = sm`a -> b -> c;`;
2097
+ * m.hook_everything(({ hook_name }) => {
2098
+ * console.log(`${hook_name} fired`);
2099
+ * return true;
2100
+ * });
2101
+ * ```
2102
+ *
2103
+ * @param handler - Callback invoked after all other pre-hooks.
2104
+ * @returns `this` for chaining.
2105
+ */
2106
+ hook_everything(handler: EverythingHookHandler<mDT>): Machine<mDT>;
2107
+ /** Register a post-transition hook that fires **after** all other
2108
+ * post-hooks on every transition. Cannot block the transition. The
2109
+ * handler receives an {@link EverythingHookContext} whose `hook_name` is
2110
+ * `'post everything'`.
2111
+ *
2112
+ * ```typescript
2113
+ * const m = sm`a -> b -> c;`;
2114
+ * m.hook_post_everything(({ hook_name }) => {
2115
+ * console.log(`${hook_name} fired`);
2116
+ * });
2117
+ * ```
2118
+ *
2119
+ * @param handler - Callback invoked after all other post-hooks.
2120
+ * @returns `this` for chaining.
2121
+ */
2122
+ hook_post_everything(handler: PostEverythingHookHandler<mDT>): Machine<mDT>;
2123
+ /** Register a post-transition hook that fires **before** all other
2124
+ * post-hooks on every transition. Cannot block the transition. The
2125
+ * handler receives an {@link EverythingHookContext} whose `hook_name` is
2126
+ * `'pre post everything'`.
2127
+ *
2128
+ * ```typescript
2129
+ * const m = sm`a -> b -> c;`;
2130
+ * m.hook_pre_post_everything(({ hook_name }) => {
2131
+ * console.log(`${hook_name} fired`);
2132
+ * });
2133
+ * ```
2134
+ *
2135
+ * @param handler - Callback invoked before all other post-hooks.
2136
+ * @returns `this` for chaining.
2137
+ */
2138
+ hook_pre_post_everything(handler: PostEverythingHookHandler<mDT>): Machine<mDT>;
2139
+ /** Get the current RNG seed used for probabilistic transitions.
2140
+ * @returns The numeric seed value.
2141
+ */
1289
2142
  get rng_seed(): number;
2143
+ /** Set the RNG seed. Pass `undefined` to reseed from the current time.
2144
+ * Resets the internal PRNG so subsequent probabilistic operations use the
2145
+ * new seed.
2146
+ * @param to - The seed value, or `undefined` for time-based seeding.
2147
+ */
1290
2148
  set rng_seed(to: number | undefined);
2149
+ /** Get all edges between two states (there can be multiple with
2150
+ * different actions).
2151
+ * @param from - Source state name.
2152
+ * @param to - Target state name.
2153
+ * @returns An array of matching {@link JssmTransition} objects.
2154
+ */
1291
2155
  edges_between(from: string, to: string): JssmTransition<StateType, mDT>[];
1292
2156
  /*********
1293
2157
  *
@@ -1309,7 +2173,53 @@ declare class Machine<mDT> {
1309
2173
  *
1310
2174
  */
1311
2175
  override(newState: StateType, newData?: mDT | undefined): void;
2176
+ /*********
2177
+ *
2178
+ * Shared transition core used by {@link transition}, {@link force_transition},
2179
+ * and {@link action}. Runs validation, fires the full hook pipeline (pre-
2180
+ * everything, any-action, after, any-transition, exit, named, basic,
2181
+ * edge-type, entry, everything), commits the new state if nothing
2182
+ * rejected, and returns whether the transition succeeded.
2183
+ *
2184
+ * Not meant for external use. Call one of the public wrappers instead:
2185
+ * - `transition` for an ordinary legal transition
2186
+ * - `force_transition` to bypass the legality check
2187
+ * - `action` to dispatch by action name rather than target state
2188
+ *
2189
+ * @remarks
2190
+ * Known sharp edges, carried over from the original `// TODO` comments:
2191
+ * - The forced-ness behavior needs to be cleaned up a lot here.
2192
+ * - The callbacks are not fully correct across the forced / action / plain
2193
+ * cases and should be revisited.
2194
+ * - When multiple edges exist between two states with different `kind`
2195
+ * values, only the first edge's kind is used to pick the edge-type hook.
2196
+ *
2197
+ * @typeparam mDT The type of the machine data member; usually omitted.
2198
+ *
2199
+ * @param newStateOrAction The target state name (for a plain or forced
2200
+ * transition) or the action name (when `wasAction` is true).
2201
+ *
2202
+ * @param newData Optional replacement machine data to install alongside
2203
+ * the transition. Hooks may further override this via complex results.
2204
+ *
2205
+ * @param wasForced `true` if the caller invoked `force_transition`, in
2206
+ * which case legality is checked against `valid_force_transition` rather
2207
+ * than `valid_transition`.
2208
+ *
2209
+ * @param wasAction `true` if the caller invoked `action`, in which case
2210
+ * `newStateOrAction` is an action name and the target state is looked up
2211
+ * via the current action edge.
2212
+ *
2213
+ * @returns `true` if the transition was valid and every hook passed;
2214
+ * `false` if the transition was invalid or any hook rejected.
2215
+ *
2216
+ * @internal
2217
+ *
2218
+ */
1312
2219
  transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
2220
+ /** If the current state has an `after` timeout configured, schedule it.
2221
+ * Called internally after each transition.
2222
+ */
1313
2223
  auto_set_state_timeout(): void;
1314
2224
  /*********
1315
2225
  *
@@ -1411,6 +2321,9 @@ declare class Machine<mDT> {
1411
2321
  *
1412
2322
  * @param newData The data change to insert during the action
1413
2323
  *
2324
+ * @returns `true` if the action was valid and the transition occurred,
2325
+ * `false` otherwise.
2326
+ *
1414
2327
  */
1415
2328
  action(actionName: StateType, newData?: mDT): boolean;
1416
2329
  /********
@@ -1431,6 +2344,8 @@ declare class Machine<mDT> {
1431
2344
  *
1432
2345
  * @typeparam mDT The type of the machine data member; usually omitted
1433
2346
  *
2347
+ * @returns The {@link JssmStateConfig} for standard states.
2348
+ *
1434
2349
  */
1435
2350
  get standard_state_style(): JssmStateConfig;
1436
2351
  /********
@@ -1455,6 +2370,8 @@ declare class Machine<mDT> {
1455
2370
  *
1456
2371
  * @typeparam mDT The type of the machine data member; usually omitted
1457
2372
  *
2373
+ * @returns The {@link JssmStateConfig} for hooked states.
2374
+ *
1458
2375
  */
1459
2376
  get hooked_state_style(): JssmStateConfig;
1460
2377
  /********
@@ -1478,6 +2395,8 @@ declare class Machine<mDT> {
1478
2395
  *
1479
2396
  * @typeparam mDT The type of the machine data member; usually omitted
1480
2397
  *
2398
+ * @returns The {@link JssmStateConfig} for start states.
2399
+ *
1481
2400
  */
1482
2401
  get start_state_style(): JssmStateConfig;
1483
2402
  /********
@@ -1506,6 +2425,8 @@ declare class Machine<mDT> {
1506
2425
  *
1507
2426
  * @typeparam mDT The type of the machine data member; usually omitted
1508
2427
  *
2428
+ * @returns The {@link JssmStateConfig} for end states.
2429
+ *
1509
2430
  */
1510
2431
  get end_state_style(): JssmStateConfig;
1511
2432
  /********
@@ -1529,6 +2450,8 @@ declare class Machine<mDT> {
1529
2450
  *
1530
2451
  * @typeparam mDT The type of the machine data member; usually omitted
1531
2452
  *
2453
+ * @returns The {@link JssmStateConfig} for terminal states.
2454
+ *
1532
2455
  */
1533
2456
  get terminal_state_style(): JssmStateConfig;
1534
2457
  /********
@@ -1549,6 +2472,8 @@ declare class Machine<mDT> {
1549
2472
  *
1550
2473
  * @typeparam mDT The type of the machine data member; usually omitted
1551
2474
  *
2475
+ * @returns The {@link JssmStateConfig} for the active state.
2476
+ *
1552
2477
  */
1553
2478
  get active_state_style(): JssmStateConfig;
1554
2479
  /********
@@ -1569,6 +2494,10 @@ declare class Machine<mDT> {
1569
2494
  *
1570
2495
  * @typeparam mDT The type of the machine data member; usually omitted
1571
2496
  *
2497
+ * @param state The state to compute the composite style for.
2498
+ *
2499
+ * @returns The fully composited {@link JssmStateConfig} for the given state.
2500
+ *
1572
2501
  */
1573
2502
  style_for(state: StateType): JssmStateConfig;
1574
2503
  /********
@@ -1601,6 +2530,9 @@ declare class Machine<mDT> {
1601
2530
  *
1602
2531
  * @param newData The data change to insert during the action
1603
2532
  *
2533
+ * @returns `true` if the action was valid and the transition occurred,
2534
+ * `false` otherwise.
2535
+ *
1604
2536
  */
1605
2537
  do(actionName: StateType, newData?: mDT): boolean;
1606
2538
  /********
@@ -1631,6 +2563,8 @@ declare class Machine<mDT> {
1631
2563
  *
1632
2564
  * @param newData The data change to insert during the transition
1633
2565
  *
2566
+ * @returns `true` if the transition was legal and occurred, `false` otherwise.
2567
+ *
1634
2568
  */
1635
2569
  transition(newState: StateType, newData?: mDT): boolean;
1636
2570
  /********
@@ -1651,6 +2585,8 @@ declare class Machine<mDT> {
1651
2585
  *
1652
2586
  * @param newData The data change to insert during the transition
1653
2587
  *
2588
+ * @returns `true` if the transition was legal and occurred, `false` otherwise.
2589
+ *
1654
2590
  */
1655
2591
  go(newState: StateType, newData?: mDT): boolean;
1656
2592
  /********
@@ -1674,21 +2610,84 @@ declare class Machine<mDT> {
1674
2610
  *
1675
2611
  * @param newData The data change to insert during the transition
1676
2612
  *
2613
+ * @returns `true` if a transition (forced or otherwise) existed and occurred,
2614
+ * `false` otherwise.
2615
+ *
1677
2616
  */
1678
2617
  force_transition(newState: StateType, newData?: mDT): boolean;
2618
+ /** Get the edge index for an action from the current state.
2619
+ * @param action - The action name.
2620
+ * @returns The edge index, or `undefined` if the action is not available.
2621
+ */
1679
2622
  current_action_for(action: StateType): number;
2623
+ /** Get the full transition object for an action from the current state.
2624
+ * @param action - The action name.
2625
+ * @returns The {@link JssmTransition} object.
2626
+ * @throws {JssmError} If the action is not available from the current state.
2627
+ */
1680
2628
  current_action_edge_for(action: StateType): JssmTransition<StateType, mDT>;
2629
+ /** Check whether an action is available from the current state.
2630
+ * @param action - The action name to check.
2631
+ * @param _newData - Reserved for future data validation.
2632
+ * @returns `true` if the action can be taken.
2633
+ */
1681
2634
  valid_action(action: StateType, _newData?: mDT): boolean;
2635
+ /** Check whether a transition to a given state is legal (non-forced) from
2636
+ * the current state.
2637
+ * @param newState - The target state.
2638
+ * @param _newData - Reserved for future data validation.
2639
+ * @returns `true` if the transition is legal.
2640
+ */
1682
2641
  valid_transition(newState: StateType, _newData?: mDT): boolean;
2642
+ /** Check whether a forced transition to a given state exists from the
2643
+ * current state.
2644
+ * @param newState - The target state.
2645
+ * @param _newData - Reserved for future data validation.
2646
+ * @returns `true` if a forced (or any) transition exists.
2647
+ */
1683
2648
  valid_force_transition(newState: StateType, _newData?: mDT): boolean;
2649
+ /** Get the instance name of this machine, if one was assigned at creation.
2650
+ * @returns The instance name string, or `undefined`.
2651
+ */
1684
2652
  instance_name(): string | undefined;
2653
+ /** Get the creation date of this machine as a `Date` object.
2654
+ * @returns A `Date` representing when the machine was created.
2655
+ */
1685
2656
  get creation_date(): Date;
2657
+ /** Get the creation timestamp (milliseconds since epoch).
2658
+ * @returns The timestamp as a number.
2659
+ */
1686
2660
  get creation_timestamp(): number;
2661
+ /** Get the timestamp when construction began (before parsing).
2662
+ * @returns The start-of-construction timestamp as a number.
2663
+ */
1687
2664
  get create_start_time(): number;
2665
+ /** Schedule an automatic transition to `next_state` after `after_time`
2666
+ * milliseconds. Only one timeout may be active at a time.
2667
+ * @param next_state - The state to transition to when the timer fires.
2668
+ * @param after_time - Delay in milliseconds.
2669
+ * @throws {JssmError} If a timeout is already pending.
2670
+ */
1688
2671
  set_state_timeout(next_state: StateType, after_time: number): void;
2672
+ /** Cancel any pending state timeout. Safe to call when no timeout is active.
2673
+ */
1689
2674
  clear_state_timeout(): void;
2675
+ /** Get the configured `after` timeout for a given state, if any.
2676
+ * @param which_state - The state to look up.
2677
+ * @returns A `[targetState, delayMs]` tuple, or `undefined` if no timeout
2678
+ * is configured for that state.
2679
+ */
1690
2680
  state_timeout_for(which_state: StateType): [StateType, number] | undefined;
2681
+ /** Get the configured `after` timeout for the current state, if any.
2682
+ * @returns A `[targetState, delayMs]` tuple, or `undefined`.
2683
+ */
1691
2684
  current_state_timeout(): [StateType, number] | undefined;
2685
+ /** Convenience method to create a new machine from a tagged template literal.
2686
+ * Equivalent to calling the top-level `sm` function.
2687
+ * @param template_strings - The template string array.
2688
+ * @param remainder - Interpolated values.
2689
+ * @returns A new {@link Machine} instance.
2690
+ */
1692
2691
  sm(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>;
1693
2692
  }
1694
2693
  /*********
@@ -1738,9 +2737,158 @@ declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: a
1738
2737
  *
1739
2738
  */
1740
2739
  declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<StateType, mDT>> | undefined): Machine<mDT>;
2740
+ /**
2741
+ *
2742
+ * Type guard that narrows an unknown value to a {@link HookComplexResult}.
2743
+ *
2744
+ * A hook complex result is an object with at minimum a boolean `pass` field,
2745
+ * and may optionally also carry replacement `data` / `next_data` fields that
2746
+ * the machine should adopt if the hook passes. This helper is used by the
2747
+ * hook-dispatch machinery to tell "hook returned a complex object" from
2748
+ * "hook returned a bare boolean / null / undefined".
2749
+ *
2750
+ * ```typescript
2751
+ * is_hook_complex_result({ pass: true }); // true
2752
+ * is_hook_complex_result({ pass: false, data: { x: 1 }}); // true
2753
+ * is_hook_complex_result(true); // false
2754
+ * is_hook_complex_result(null); // false
2755
+ * is_hook_complex_result({ other: 'thing' }); // false
2756
+ * ```
2757
+ *
2758
+ * @typeparam mDT The type of the machine data member; usually omitted.
2759
+ *
2760
+ * @param hr The value to test.
2761
+ *
2762
+ * @returns `true` if `hr` is a non-null object with a boolean `pass` field;
2763
+ * `false` otherwise. When `true`, TypeScript narrows `hr` to
2764
+ * `HookComplexResult<mDT>`.
2765
+ *
2766
+ */
1741
2767
  declare function is_hook_complex_result<mDT>(hr: unknown): hr is HookComplexResult<mDT>;
2768
+ /**
2769
+ *
2770
+ * Normalize any legal hook return value to a single "did it reject?" boolean.
2771
+ *
2772
+ * Hooks in jssm may return any of the following to indicate success:
2773
+ * `true`, `undefined`, or a complex result whose `pass` field is `true`.
2774
+ * They may return any of the following to indicate rejection:
2775
+ * `false`, or a complex result whose `pass` field is `false`. This helper
2776
+ * collapses all of those shapes into one boolean so callers don't have to
2777
+ * re-implement the matrix.
2778
+ *
2779
+ * ```typescript
2780
+ * is_hook_rejection(true); // false (pass)
2781
+ * is_hook_rejection(undefined); // false (pass)
2782
+ * is_hook_rejection(false); // true (reject)
2783
+ * is_hook_rejection({ pass: true }); // false (pass)
2784
+ * is_hook_rejection({ pass: false }); // true (reject)
2785
+ * ```
2786
+ *
2787
+ * @typeparam mDT The type of the machine data member; usually omitted.
2788
+ *
2789
+ * @param hr A hook result of any legal shape.
2790
+ *
2791
+ * @returns `true` if the hook rejected the transition; `false` if it passed.
2792
+ *
2793
+ * @throws {TypeError} If `hr` is not a recognized hook result shape (for
2794
+ * example, a number or a plain object without a `pass` field).
2795
+ *
2796
+ */
1742
2797
  declare function is_hook_rejection<mDT>(hr: HookResult<mDT>): boolean;
2798
+ /**
2799
+ *
2800
+ * Invoke an optional transition/action hook and normalize its return value
2801
+ * into a {@link HookComplexResult}.
2802
+ *
2803
+ * This is the central adapter the transition pipeline uses to run every
2804
+ * non-"everything" hook kind (basic, named, entry, exit, after, action, etc).
2805
+ * It accepts `undefined` for the hook slot because most hooks are not set on
2806
+ * most machines; when no hook is installed the step is a no-op pass.
2807
+ *
2808
+ * The valid return shapes from a hook and their normalized meanings are:
2809
+ * - `undefined` → `{ pass: true }`
2810
+ * - `true` → `{ pass: true }`
2811
+ * - `false` → `{ pass: false }`
2812
+ * - `null` → `{ pass: false }`
2813
+ * - a complex result object → returned as-is
2814
+ *
2815
+ * Anything else is a programmer error and throws.
2816
+ *
2817
+ * @typeparam mDT The type of the machine data member; usually omitted.
2818
+ *
2819
+ * @param maybe_hook The hook handler to call, or `undefined` for the
2820
+ * "no hook installed" case.
2821
+ *
2822
+ * @param hook_args The context object passed to the hook. Includes the
2823
+ * current and proposed state, current and proposed data, action name, and
2824
+ * transition kind.
2825
+ *
2826
+ * @returns A {@link HookComplexResult} describing whether the hook passed
2827
+ * and, optionally, any data replacements it requested.
2828
+ *
2829
+ * @throws {TypeError} If the hook returns a value that is not one of the
2830
+ * legal shapes listed above.
2831
+ *
2832
+ * @internal
2833
+ *
2834
+ */
1743
2835
  declare function abstract_hook_step<mDT>(maybe_hook: HookHandler<mDT> | undefined, hook_args: HookContext<mDT>): HookComplexResult<mDT>;
2836
+ /**
2837
+ *
2838
+ * Invoke an optional "everything" hook and normalize its return value into
2839
+ * a {@link HookComplexResult}.
2840
+ *
2841
+ * Mechanically identical to {@link abstract_hook_step}, but typed for the
2842
+ * everything-hook family (`pre_everything_hook` and `everything_hook`),
2843
+ * whose context object carries an extra `hook_name` field identifying which
2844
+ * bracket of the pipeline is firing. Separated from `abstract_hook_step`
2845
+ * so TypeScript can enforce that the hook handler and the context object
2846
+ * agree on shape.
2847
+ *
2848
+ * The valid return shapes and their meanings are the same as for
2849
+ * `abstract_hook_step`:
2850
+ * - `undefined` or `true` → `{ pass: true }`
2851
+ * - `false` or `null` → `{ pass: false }`
2852
+ * - a complex result → returned as-is
2853
+ *
2854
+ * @typeparam mDT The type of the machine data member; usually omitted.
2855
+ *
2856
+ * @param maybe_hook The everything-hook handler, or `undefined` when none
2857
+ * is installed.
2858
+ *
2859
+ * @param hook_args The everything-hook context object. Differs from a
2860
+ * normal hook context in that it also includes `hook_name`.
2861
+ *
2862
+ * @returns A {@link HookComplexResult} describing whether the hook passed
2863
+ * and any data replacements it requested.
2864
+ *
2865
+ * @throws {TypeError} If the hook returns a value outside the legal shapes.
2866
+ *
2867
+ * @internal
2868
+ *
2869
+ */
2870
+ declare function abstract_everything_hook_step<mDT>(maybe_hook: EverythingHookHandler<mDT> | undefined, hook_args: EverythingHookContext<mDT>): HookComplexResult<mDT>;
2871
+ /**
2872
+ * Deserializes a previously serialized machine state.
2873
+ *
2874
+ * This function recreates a machine from a serialization object, restoring its
2875
+ * state, data, and history. For security and compatibility reasons, it will
2876
+ * refuse to deserialize data from future versions of the library.
2877
+ *
2878
+ * @typeparam mDT - The type of the machine data member
2879
+ *
2880
+ * @param {string} machine_string - The FSL string defining the machine structure
2881
+ * @param {JssmSerialization<mDT>} ser - The serialization object to restore from
2882
+ *
2883
+ * @returns {Machine<mDT>} - The restored machine instance
2884
+ *
2885
+ * @throws {Error} If the serialization is from a future version
2886
+ *
2887
+ * @example
2888
+ * const machine = jssm.from("a -> b;");
2889
+ * const serialized = machine.serialize();
2890
+ * const restored = jssm.deserialize("a -> b;", serialized);
2891
+ */
1744
2892
  declare function deserialize<mDT>(machine_string: string, ser: JssmSerialization<mDT>): Machine<mDT>;
1745
2893
 
1746
- export { FslDirections, Machine, abstract_hook_step, arrow_direction, arrow_left_kind, arrow_right_kind, build_time, compile, jssm_constants_d as constants, deserialize, find_repeated, from, gviz_shapes, histograph, is_hook_complex_result, is_hook_rejection, make, named_colors, wrap_parse as parse, seq, shapes, sleep, sm, state_style_condense, transfer_state_properties, unique, version, weighted_histo_key, weighted_rand_select, weighted_sample_select };
2894
+ export { FslDirections, Machine, abstract_everything_hook_step, abstract_hook_step, arrow_direction, arrow_left_kind, arrow_right_kind, build_time, compile, jssm_constants_d as constants, deserialize, find_repeated, from, gen_splitmix32, gviz_shapes, histograph, is_hook_complex_result, is_hook_rejection, make, named_colors, wrap_parse as parse, seq, shapes, sleep, sm, state_style_condense, transfer_state_properties, unique, version, weighted_histo_key, weighted_rand_select, weighted_sample_select };