jssm 5.162.7 → 5.162.8
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/README.md +7 -7
- package/custom-elements.json +47 -47
- package/dist/cdn/instance.js +5 -3
- package/dist/cdn/viz.js +1 -1
- package/dist/cli/fsl-export-system-prompt.cjs +27 -24
- package/dist/cli/fsl-render.cjs +1 -1
- package/dist/cli/fsl.cjs +1 -1
- package/dist/cli/lib.cjs +1 -1
- package/dist/cli/lib.mjs +1 -1
- package/dist/cm6/fsl_language.js +10 -14
- package/dist/deno/README.md +7 -7
- package/dist/deno/fence.d.ts +0 -1
- package/dist/deno/fsl_fence_highlight.d.ts +0 -4
- package/dist/deno/fsl_fence_render.d.ts +0 -8
- package/dist/deno/fsl_gif.d.ts +0 -8
- package/dist/deno/fsl_markdown_fence.d.ts +0 -5
- package/dist/deno/fsl_svg_patch.d.ts +0 -6
- package/dist/deno/fsl_walk.d.ts +0 -2
- package/dist/deno/jssm.d.ts +214 -503
- package/dist/deno/jssm.js +1 -1
- package/dist/deno/jssm_compiler.d.ts +1 -1
- package/dist/deno/jssm_constants.d.ts +0 -3
- package/dist/deno/jssm_intern.d.ts +0 -15
- package/dist/deno/jssm_theme.d.ts +2 -2
- package/dist/deno/jssm_types.d.ts +13 -34
- package/dist/deno/jssm_util.d.ts +20 -6
- package/dist/deno/jssm_viz.d.ts +5 -51
- package/dist/es6/cm6/fsl_language.d.ts +0 -2
- package/dist/fence/fence.js +1651 -1833
- package/dist/jssm.es5.cjs +1 -1
- package/dist/jssm.es5.iife.js +1 -1
- package/dist/jssm.es6.mjs +1 -1
- package/dist/jssm_viz.cjs +1 -1
- package/dist/jssm_viz.iife.cjs +1 -1
- package/dist/jssm_viz.mjs +1 -1
- package/dist/wc/docs.define.js +0 -5
- package/dist/wc/docs.js +79 -43
- package/dist/wc/editor.define.js +0 -5
- package/dist/wc/editor.js +1 -7
- package/dist/wc/instance.define.js +0 -6
- package/dist/wc/instance.js +93 -115
- package/dist/wc/viz.define.js +0 -6
- package/dist/wc/viz.js +22 -36
- package/dist/wc/widgets.define.js +0 -5
- package/dist/wc/widgets.js +117 -95
- package/jssm.cli.d.cts +0 -8
- package/jssm.cli.d.ts +0 -8
- package/jssm.es5.d.cts +449 -808
- package/jssm.es6.d.ts +449 -808
- package/jssm.fence.d.ts +213 -508
- package/jssm_viz.es5.d.cts +216 -529
- package/jssm_viz.es6.d.ts +216 -529
- package/package.json +16 -10
package/jssm.es6.d.ts
CHANGED
|
@@ -68,7 +68,6 @@ type JssmAllowIslands = true | false | 'with_start';
|
|
|
68
68
|
* - `{ height }` — height-only form (`default_size: height 600;`)
|
|
69
69
|
*
|
|
70
70
|
* This is a *hint*, not a hard constraint. Renderers may ignore it.
|
|
71
|
-
*
|
|
72
71
|
* @see Machine.default_size
|
|
73
72
|
*/
|
|
74
73
|
type JssmDefaultSize = {
|
|
@@ -103,8 +102,7 @@ type FslTheme = typeof FslThemes[number];
|
|
|
103
102
|
* and consumed by {@link jssm!deserialize}. Carries the current state, the
|
|
104
103
|
* associated machine data, the recent history (subject to the configured
|
|
105
104
|
* capacity), and metadata to detect version-skew on rehydration.
|
|
106
|
-
*
|
|
107
|
-
* @typeParam DataType - The type of the user-supplied data payload (`mDT`).
|
|
105
|
+
* @template DataType - The type of the user-supplied data payload (`mDT`).
|
|
108
106
|
*/
|
|
109
107
|
type JssmSerialization<DataType> = {
|
|
110
108
|
jssm_version: string;
|
|
@@ -130,7 +128,6 @@ type JssmSerialization<DataType> = {
|
|
|
130
128
|
* // [ { kind: 'group', name: 'inner', mode: 'nest' },
|
|
131
129
|
* // { kind: 'state', name: 'x' } ]
|
|
132
130
|
* ```
|
|
133
|
-
*
|
|
134
131
|
* @see JssmGroupRef
|
|
135
132
|
* @see JssmGroupRegistry
|
|
136
133
|
*/
|
|
@@ -157,7 +154,6 @@ type JssmGroupMemberRef = {
|
|
|
157
154
|
* // registry.get('outer') === [ { kind:'group', name:'inner', mode:'nest' },
|
|
158
155
|
* // { kind:'state', name:'c' } ]
|
|
159
156
|
* ```
|
|
160
|
-
*
|
|
161
157
|
* @see JssmGroupMemberRef
|
|
162
158
|
*/
|
|
163
159
|
type JssmGroupRegistry = Map<string, JssmGroupMemberRef[]>;
|
|
@@ -167,7 +163,6 @@ type JssmGroupRegistry = Map<string, JssmGroupMemberRef[]>;
|
|
|
167
163
|
* Each is optional so a subject may declare only one direction; the compiler
|
|
168
164
|
* merges an `enter` and an `exit` declaration for the same subject into one
|
|
169
165
|
* of these.
|
|
170
|
-
*
|
|
171
166
|
* @see JssmHookDeclaration
|
|
172
167
|
*/
|
|
173
168
|
type JssmBoundaryHooks = {
|
|
@@ -178,7 +173,6 @@ type JssmBoundaryHooks = {
|
|
|
178
173
|
* Maps each group name that has at least one boundary hook to its merged
|
|
179
174
|
* {@link JssmBoundaryHooks}. Carried on {@link JssmGenericConfig} for the
|
|
180
175
|
* runtime to consume; depth-aware firing is a later task.
|
|
181
|
-
*
|
|
182
176
|
* @see JssmHookDeclaration
|
|
183
177
|
*/
|
|
184
178
|
type JssmGroupHooks = Map<string, JssmBoundaryHooks>;
|
|
@@ -186,7 +180,6 @@ type JssmGroupHooks = Map<string, JssmBoundaryHooks>;
|
|
|
186
180
|
* Maps each plain state name that has at least one boundary hook to its
|
|
187
181
|
* merged {@link JssmBoundaryHooks}. The state-subject analogue of
|
|
188
182
|
* {@link JssmGroupHooks}.
|
|
189
|
-
*
|
|
190
183
|
* @see JssmHookDeclaration
|
|
191
184
|
*/
|
|
192
185
|
type JssmStateHooks = Map<string, JssmBoundaryHooks>;
|
|
@@ -218,9 +211,8 @@ type JssmTransitionPermitterMaybeArray<DataType> = JssmTransitionPermitter<DataT
|
|
|
218
211
|
* per-edge `name`, an action label, a guard `check`, a transition
|
|
219
212
|
* `probability` for stochastic models, and an `after_time` for timed
|
|
220
213
|
* transitions.
|
|
221
|
-
*
|
|
222
|
-
* @
|
|
223
|
-
* @typeParam DataType - The machine's data payload type (`mDT`).
|
|
214
|
+
* @template StateType - The state-name type (usually `string`).
|
|
215
|
+
* @template DataType - The machine's data payload type (`mDT`).
|
|
224
216
|
*/
|
|
225
217
|
type JssmTransition<StateType, DataType> = {
|
|
226
218
|
from: StateType;
|
|
@@ -404,7 +396,6 @@ type JssmGraphDefaultEdgeColor = {
|
|
|
404
396
|
* reuses the per-state style items (so `color: red;` works inside a
|
|
405
397
|
* `transition:` block exactly as inside a `state:` block) plus the
|
|
406
398
|
* edge-scoped {@link JssmGraphDefaultEdgeColor} default.
|
|
407
|
-
*
|
|
408
399
|
* @see JssmTransitionConfig
|
|
409
400
|
*/
|
|
410
401
|
type JssmTransitionStyleKey = JssmStateStyleKey | JssmGraphDefaultEdgeColor;
|
|
@@ -419,7 +410,6 @@ type JssmTransitionStyleKey = JssmStateStyleKey | JssmGraphDefaultEdgeColor;
|
|
|
419
410
|
* const cfg = compile(parse('a -> b; transition: { color: red; };'));
|
|
420
411
|
* // cfg.default_transition_config === [ { key: 'color', value: '#ff0000ff' } ]
|
|
421
412
|
* ```
|
|
422
|
-
*
|
|
423
413
|
* @see JssmGraphConfig
|
|
424
414
|
*/
|
|
425
415
|
type JssmTransitionConfig = JssmTransitionStyleKey[];
|
|
@@ -430,7 +420,7 @@ type JssmTransitionConfig = JssmTransitionStyleKey[];
|
|
|
430
420
|
* default) into the consolidated `graph: {}` config. Each carries the
|
|
431
421
|
* legacy parse key so downstream consumers can disambiguate.
|
|
432
422
|
*/
|
|
433
|
-
type JssmGraphAliasKey = {
|
|
423
|
+
type JssmGraphAliasKey = JssmGraphDefaultEdgeColor | {
|
|
434
424
|
key: 'graph_layout';
|
|
435
425
|
value: JssmLayout;
|
|
436
426
|
} | {
|
|
@@ -445,13 +435,12 @@ type JssmGraphAliasKey = {
|
|
|
445
435
|
} | {
|
|
446
436
|
key: 'flow';
|
|
447
437
|
value: FslDirection;
|
|
448
|
-
}
|
|
438
|
+
};
|
|
449
439
|
/**
|
|
450
440
|
* A single item inside a `graph: {}` default-config block. For v1 this
|
|
451
441
|
* reuses the per-state style items plus the graph-scope alias items
|
|
452
442
|
* ({@link JssmGraphAliasKey}) folded in from the deprecated top-level
|
|
453
443
|
* graph keywords.
|
|
454
|
-
*
|
|
455
444
|
* @see JssmGraphConfig
|
|
456
445
|
*/
|
|
457
446
|
type JssmGraphStyleKey = JssmStateStyleKey | JssmGraphAliasKey;
|
|
@@ -468,40 +457,9 @@ type JssmGraphStyleKey = JssmStateStyleKey | JssmGraphAliasKey;
|
|
|
468
457
|
* // `background-color` item, so:
|
|
469
458
|
* // cfg.default_graph_config includes { key: 'background-color', value: '#ffffffff' }
|
|
470
459
|
* ```
|
|
471
|
-
*
|
|
472
460
|
* @see JssmTransitionConfig
|
|
473
461
|
*/
|
|
474
462
|
type JssmGraphConfig = JssmGraphStyleKey[];
|
|
475
|
-
/**
|
|
476
|
-
* Complete shape of a jssm-viz theme. A theme provides a style block for
|
|
477
|
-
* each kind of state (`state`, `hooked`, `start`, `end`, `terminal`) as
|
|
478
|
-
* well as a matching `active_*` variant used while that state is current.
|
|
479
|
-
*
|
|
480
|
-
* The `graph`, `legal`, `main`, `forced`, `action`, and `title` slots are
|
|
481
|
-
* reserved for future use and currently typed as `undefined`.
|
|
482
|
-
*
|
|
483
|
-
* Most user-defined themes should be typed as {@link JssmTheme} (the
|
|
484
|
-
* `Partial` of this) so that omitted fields fall back to the base theme.
|
|
485
|
-
*/
|
|
486
|
-
type JssmBaseTheme = {
|
|
487
|
-
name: string;
|
|
488
|
-
state: JssmStateConfig;
|
|
489
|
-
hooked: JssmStateConfig;
|
|
490
|
-
start: JssmStateConfig;
|
|
491
|
-
end: JssmStateConfig;
|
|
492
|
-
terminal: JssmStateConfig;
|
|
493
|
-
active: JssmStateConfig;
|
|
494
|
-
active_hooked: JssmStateConfig;
|
|
495
|
-
active_start: JssmStateConfig;
|
|
496
|
-
active_end: JssmStateConfig;
|
|
497
|
-
active_terminal: JssmStateConfig;
|
|
498
|
-
graph: undefined;
|
|
499
|
-
legal: undefined;
|
|
500
|
-
main: undefined;
|
|
501
|
-
forced: undefined;
|
|
502
|
-
action: undefined;
|
|
503
|
-
title: undefined;
|
|
504
|
-
};
|
|
505
463
|
/**
|
|
506
464
|
* Full configuration object accepted by the {@link jssm!Machine} constructor and
|
|
507
465
|
* by {@link from}. Carries the transition list and the optional knobs
|
|
@@ -511,9 +469,8 @@ type JssmBaseTheme = {
|
|
|
511
469
|
*
|
|
512
470
|
* Most users never construct one of these directly — the `sm` tagged
|
|
513
471
|
* template literal and {@link from} produce one from FSL source.
|
|
514
|
-
*
|
|
515
|
-
* @
|
|
516
|
-
* @typeParam DataType - The user-supplied data payload type (`mDT`).
|
|
472
|
+
* @template StateType - The state-name type (usually `string`).
|
|
473
|
+
* @template DataType - The user-supplied data payload type (`mDT`).
|
|
517
474
|
*/
|
|
518
475
|
/**
|
|
519
476
|
* Editor/panel defaults an FSL machine declares in an `editor: {}` block
|
|
@@ -573,7 +530,6 @@ type JssmGenericConfig<StateType, DataType> = {
|
|
|
573
530
|
*
|
|
574
531
|
* Defaults to `100`. Raise it for legitimate pipelines that genuinely nest
|
|
575
532
|
* more than 100 transitions via boundary hooks.
|
|
576
|
-
*
|
|
577
533
|
* @see Machine._boundary_depth_limit
|
|
578
534
|
* @see Machine._fire_boundary_actions
|
|
579
535
|
*/
|
|
@@ -593,7 +549,7 @@ type JssmGenericConfig<StateType, DataType> = {
|
|
|
593
549
|
failed_outputs?: Array<StateType>;
|
|
594
550
|
initial_state?: StateType;
|
|
595
551
|
start_states_no_enforce?: boolean;
|
|
596
|
-
state_declaration?:
|
|
552
|
+
state_declaration?: object[];
|
|
597
553
|
property_definition?: JssmPropertyDefinition[];
|
|
598
554
|
state_property?: JssmPropertyDefinition[];
|
|
599
555
|
arrange_declaration?: Array<Array<StateType>>;
|
|
@@ -657,7 +613,6 @@ type JssmGenericConfig<StateType, DataType> = {
|
|
|
657
613
|
* arrow with optional per-direction action labels, probabilities, and
|
|
658
614
|
* after-times. The recursive `se` field allows the parser to chain
|
|
659
615
|
* arrows of the form `A -> B -> C`. Not intended for end-user code.
|
|
660
|
-
*
|
|
661
616
|
* @internal
|
|
662
617
|
*/
|
|
663
618
|
type JssmCompileSe<StateType, mDT> = {
|
|
@@ -681,7 +636,6 @@ type JssmCompileSe<StateType, mDT> = {
|
|
|
681
636
|
* for non-transition rules (state declarations, property definitions,
|
|
682
637
|
* machine metadata) via its `key`/`value`/`name`/`state` fields. Not
|
|
683
638
|
* intended for end-user code.
|
|
684
|
-
*
|
|
685
639
|
* @internal
|
|
686
640
|
*/
|
|
687
641
|
type JssmCompileSeStart<StateType, DataType> = {
|
|
@@ -702,7 +656,6 @@ type JssmCompileSeStart<StateType, DataType> = {
|
|
|
702
656
|
* The output shape of the FSL parser: a flat array of
|
|
703
657
|
* {@link JssmCompileSeStart} entries, one per top-level rule in the
|
|
704
658
|
* source. Consumed by the compiler to build a machine configuration.
|
|
705
|
-
*
|
|
706
659
|
* @internal
|
|
707
660
|
*/
|
|
708
661
|
type JssmParseTree<StateType, mDT> = Array<JssmCompileSeStart<StateType, mDT>>;
|
|
@@ -997,7 +950,6 @@ type JssmRng = () => number;
|
|
|
997
950
|
* All event names that {@link jssm!Machine.on} accepts. These are observation
|
|
998
951
|
* events fired by the machine in addition to (not in place of) the hook
|
|
999
952
|
* system. Hooks intercept; events observe.
|
|
1000
|
-
*
|
|
1001
953
|
* @see Machine.on
|
|
1002
954
|
*/
|
|
1003
955
|
type JssmEventName = 'transition' | 'rejection' | 'action' | 'entry' | 'exit' | 'terminal' | 'complete' | 'error' | 'data-change' | 'override' | 'timeout' | 'hook-registration' | 'hook-removal';
|
|
@@ -1091,7 +1043,7 @@ type JssmErrorEventDetail = {
|
|
|
1091
1043
|
error: unknown;
|
|
1092
1044
|
source_event: JssmEventName;
|
|
1093
1045
|
source_detail: unknown;
|
|
1094
|
-
handler:
|
|
1046
|
+
handler: JssmEventHandler<unknown, JssmEventName>;
|
|
1095
1047
|
};
|
|
1096
1048
|
/**
|
|
1097
1049
|
* Detail payload fired with a `data-change` event. Fires whenever the
|
|
@@ -1186,15 +1138,15 @@ type JssmEventFilterMap<mDT> = {
|
|
|
1186
1138
|
/**
|
|
1187
1139
|
* Per-event filter object (as passed to {@link jssm!Machine.on}). Use
|
|
1188
1140
|
* `JssmEventDetailMap<mDT>[Ev]` to find the matching detail type.
|
|
1189
|
-
* @
|
|
1190
|
-
* @
|
|
1141
|
+
* @template mDT The type of the machine data member.
|
|
1142
|
+
* @template Ev The event name.
|
|
1191
1143
|
*/
|
|
1192
1144
|
type JssmEventFilter<mDT, Ev extends JssmEventName> = JssmEventFilterMap<mDT>[Ev];
|
|
1193
1145
|
/**
|
|
1194
1146
|
* Per-event handler signature. Receives a detail object typed by event
|
|
1195
1147
|
* name, so `e.action` (etc.) only exist where they're meaningful.
|
|
1196
|
-
* @
|
|
1197
|
-
* @
|
|
1148
|
+
* @template mDT The type of the machine data member.
|
|
1149
|
+
* @template Ev The event name.
|
|
1198
1150
|
*/
|
|
1199
1151
|
type JssmEventHandler<mDT, Ev extends JssmEventName> = (detail: JssmEventDetailMap<mDT>[Ev]) => void;
|
|
1200
1152
|
/**
|
|
@@ -1203,6 +1155,221 @@ type JssmEventHandler<mDT, Ev extends JssmEventName> = (detail: JssmEventDetailM
|
|
|
1203
1155
|
*/
|
|
1204
1156
|
type JssmUnsubscribe = () => void;
|
|
1205
1157
|
|
|
1158
|
+
/**
|
|
1159
|
+
* String interning support for the jssm machine internals.
|
|
1160
|
+
*
|
|
1161
|
+
* State and action names are interned to dense integer ids at machine
|
|
1162
|
+
* construction so that per-transition dispatch can use numeric map keys
|
|
1163
|
+
* (integer hashing) instead of repeated string-keyed lookups. Internal
|
|
1164
|
+
* machinery only — deliberately not re-exported from the `jssm` public
|
|
1165
|
+
* surface, so the public API is unchanged.
|
|
1166
|
+
* @internal
|
|
1167
|
+
*/
|
|
1168
|
+
/**
|
|
1169
|
+
* A string↔integer bimap. Assigns dense ids (0, 1, 2, …) in first-seen
|
|
1170
|
+
* order; lookups are O(1) both directions. Grows monotonically — there is
|
|
1171
|
+
* no removal, matching machine semantics (states and actions are fixed
|
|
1172
|
+
* after construction; late interning only happens for never-matching
|
|
1173
|
+
* lookups such as hook registrations naming unknown states).
|
|
1174
|
+
* @example
|
|
1175
|
+
* const i = new Interner();
|
|
1176
|
+
* i.intern('red'); // 0
|
|
1177
|
+
* i.intern('green'); // 1
|
|
1178
|
+
* i.intern('red'); // 0 (idempotent)
|
|
1179
|
+
* i.id_of('green'); // 1
|
|
1180
|
+
* i.name_of(0); // 'red'
|
|
1181
|
+
* @see pair_key
|
|
1182
|
+
*/
|
|
1183
|
+
declare class Interner {
|
|
1184
|
+
private readonly ids;
|
|
1185
|
+
private readonly names;
|
|
1186
|
+
constructor();
|
|
1187
|
+
/**
|
|
1188
|
+
* Return the id for `name`, assigning the next dense id if the name has
|
|
1189
|
+
* not been seen before.
|
|
1190
|
+
* @param name - The string to intern.
|
|
1191
|
+
* @returns The (possibly newly assigned) integer id.
|
|
1192
|
+
* @example
|
|
1193
|
+
* interner.intern('red'); // 0 on first call, 0 on every later call
|
|
1194
|
+
*/
|
|
1195
|
+
intern(name: string): number;
|
|
1196
|
+
/**
|
|
1197
|
+
* Return the id for `name` without interning, or `undefined` when the
|
|
1198
|
+
* name has never been interned. This is the hot-path probe for
|
|
1199
|
+
* user-supplied names.
|
|
1200
|
+
* @param name - The string to look up.
|
|
1201
|
+
* @example
|
|
1202
|
+
* interner.id_of('mauve'); // undefined — never interned
|
|
1203
|
+
*/
|
|
1204
|
+
id_of(name: string): number | undefined;
|
|
1205
|
+
/**
|
|
1206
|
+
* Return the name for `id`, or `undefined` for an id never assigned.
|
|
1207
|
+
* @param id - The integer id to invert.
|
|
1208
|
+
* @example
|
|
1209
|
+
* interner.name_of(0); // 'red'
|
|
1210
|
+
*/
|
|
1211
|
+
name_of(id: number): string | undefined;
|
|
1212
|
+
/** The count of distinct interned names. */
|
|
1213
|
+
get size(): number;
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
/**
|
|
1217
|
+
* Editor-agnostic data types for the FSL language service.
|
|
1218
|
+
*
|
|
1219
|
+
* These are the neutral contract every editor adapter (CodeMirror, VS Code, a
|
|
1220
|
+
* future LSP server) converts to/from. Shapes are kept aligned with LSP types so
|
|
1221
|
+
* an LSP wrapper is a near-mechanical mapping.
|
|
1222
|
+
*/
|
|
1223
|
+
/** A character-offset range in the FSL source. */
|
|
1224
|
+
interface Range {
|
|
1225
|
+
from: number;
|
|
1226
|
+
to: number;
|
|
1227
|
+
}
|
|
1228
|
+
/** Diagnostic severity, aligned with LSP severities. */
|
|
1229
|
+
type DiagnosticSeverity = 'error' | 'warning' | 'info' | 'hint';
|
|
1230
|
+
/** An editor-agnostic diagnostic (one parse/compile problem). */
|
|
1231
|
+
interface Diagnostic {
|
|
1232
|
+
range: Range;
|
|
1233
|
+
severity: DiagnosticSeverity;
|
|
1234
|
+
message: string;
|
|
1235
|
+
}
|
|
1236
|
+
/** What a completion item suggests, so adapters can pick an icon. */
|
|
1237
|
+
type CompletionKind = 'key' | 'value-color' | 'value-shape' | 'value-enum';
|
|
1238
|
+
/** An editor-agnostic completion suggestion. */
|
|
1239
|
+
interface CompletionItem {
|
|
1240
|
+
label: string;
|
|
1241
|
+
kind: CompletionKind;
|
|
1242
|
+
detail?: string;
|
|
1243
|
+
}
|
|
1244
|
+
/** Parser-derived semantic role of a source span. */
|
|
1245
|
+
type SemanticSpanKind = 'color' | 'state' | 'enum';
|
|
1246
|
+
/** An editor-agnostic semantic span (for decorations / semantic tokens). */
|
|
1247
|
+
interface SemanticSpan extends Range {
|
|
1248
|
+
kind: SemanticSpanKind;
|
|
1249
|
+
value?: string;
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
/**
|
|
1253
|
+
* Editor-agnostic FSL diagnostics: parse then compile, reporting problems as
|
|
1254
|
+
* neutral {@link Diagnostic}s. Adapters map these to CodeMirror lint diagnostics,
|
|
1255
|
+
* VS Code markers, or LSP `Diagnostic`s.
|
|
1256
|
+
*
|
|
1257
|
+
* Parse errors (peg.js) carry `.location`; compile errors carry
|
|
1258
|
+
* `.source_location` *when they reference a parsed node* — but machine-level
|
|
1259
|
+
* compile errors (e.g. an empty machine, an unknown machine rule) have none, so
|
|
1260
|
+
* the location is treated as optional and falls back to the whole document.
|
|
1261
|
+
*
|
|
1262
|
+
* Some validity checks (e.g. a `required` property that no state defines) live
|
|
1263
|
+
* in the {@link Machine} constructor, a stage past `compile`. We therefore also
|
|
1264
|
+
* construct the machine so the editor surfaces those construction-time errors
|
|
1265
|
+
* instead of calling such a machine valid. The `Machine` import closes a cycle
|
|
1266
|
+
* (`jssm` re-exports this module), but it is only referenced at call time inside
|
|
1267
|
+
* {@link fslDiagnostics}, never during module initialization, so the cycle is
|
|
1268
|
+
* benign.
|
|
1269
|
+
*/
|
|
1270
|
+
|
|
1271
|
+
/**
|
|
1272
|
+
* Parse then compile `text`, returning a list of diagnostics — empty when the
|
|
1273
|
+
* machine parses and compiles cleanly.
|
|
1274
|
+
* @example
|
|
1275
|
+
* fslDiagnostics('a -> b;'); // => []
|
|
1276
|
+
* fslDiagnostics('a -> ;')[0].severity; // => 'error'
|
|
1277
|
+
* // a `required` property no state defines is a construction-time error:
|
|
1278
|
+
* fslDiagnostics('property p required; a -> b;')[0].severity; // => 'error'
|
|
1279
|
+
*/
|
|
1280
|
+
declare function fslDiagnostics(text: string): Diagnostic[];
|
|
1281
|
+
|
|
1282
|
+
/**
|
|
1283
|
+
* Context-aware, editor-agnostic FSL completions. Value suggestions after a
|
|
1284
|
+
* `key:`, key suggestions at a statement start (top-level vs inside a `{ }`
|
|
1285
|
+
* block, by brace depth). Adapters convert {@link CompletionItem}s to their own
|
|
1286
|
+
* completion type. Value vocab is jssm's own (`gviz_shapes`, `named_colors`,
|
|
1287
|
+
* `FslDirections`), so it cannot drift from the renderer.
|
|
1288
|
+
*/
|
|
1289
|
+
|
|
1290
|
+
/**
|
|
1291
|
+
* Completions for the caret at `offset` in `text`.
|
|
1292
|
+
* @example
|
|
1293
|
+
* fslCompletions('state x : { color: ', 19)[0].kind; // => 'value-color'
|
|
1294
|
+
*/
|
|
1295
|
+
declare function fslCompletions(text: string, offset: number): CompletionItem[];
|
|
1296
|
+
|
|
1297
|
+
/**
|
|
1298
|
+
* Parser-derived semantic spans for FSL: color values (with resolved hex),
|
|
1299
|
+
* state names, and shape-enum values. Returns `[]` if the document does not
|
|
1300
|
+
* parse. Editor-agnostic — adapters map spans to decorations or semantic
|
|
1301
|
+
* tokens. Logic is a verified port of the sketch's `semantic_overlay.mjs`.
|
|
1302
|
+
*/
|
|
1303
|
+
|
|
1304
|
+
/**
|
|
1305
|
+
* Collect color / state / shape-enum semantic spans from `text`. State spans
|
|
1306
|
+
* cover transition endpoints, state-declaration subjects, group-list members
|
|
1307
|
+
* (`&G : [a b c];` — but not the group's own name, nor `&`/`...&` nested
|
|
1308
|
+
* group references), and plain-label hook subjects (`on enter x do 'act';` —
|
|
1309
|
+
* but not `&group` subjects). Every state span's `value` is the parser's
|
|
1310
|
+
* resolved name (unquoted, unescaped), while `from`/`to` cover the source
|
|
1311
|
+
* spelling including any quotes.
|
|
1312
|
+
* @example
|
|
1313
|
+
* fslSemanticSpans('state s : { color: crimson; };')
|
|
1314
|
+
* .find(s => s.kind === 'color')?.value; // => '#dc143cff'
|
|
1315
|
+
* @example
|
|
1316
|
+
* fslSemanticSpans('&G : [a b];\na -> b;')
|
|
1317
|
+
* .filter(s => s.kind === 'state').length; // => 4 (two members + two endpoints)
|
|
1318
|
+
*/
|
|
1319
|
+
declare function fslSemanticSpans(text: string): SemanticSpan[];
|
|
1320
|
+
|
|
1321
|
+
/**
|
|
1322
|
+
* The FSL Markdown fence convention parser — pure, host-agnostic logic that
|
|
1323
|
+
* turns a fenced-code-block info string into a {@link FenceDescriptor}. Hosts
|
|
1324
|
+
* (a VS Code preview plugin, a static-site generator, …) each interpret the
|
|
1325
|
+
* descriptor according to their capabilities.
|
|
1326
|
+
* @see notes/superpowers/specs/2026-06-23-fsl-markdown-fence-convention-design.md
|
|
1327
|
+
*/
|
|
1328
|
+
/** A single renderable part of a fence block (stacks in listed order, first on top). */
|
|
1329
|
+
type FencePart = 'image' | 'code' | 'dot' | 'editor' | 'actions' | 'info-panel' | 'toolbar' | 'title' | 'footer';
|
|
1330
|
+
/** An image output format for the `image` part. */
|
|
1331
|
+
type FenceImageFormat = 'svg' | 'png' | 'jpeg' | 'gif';
|
|
1332
|
+
/** The unit of a {@link FenceDimension} (`%` is represented as `'percent'`). */
|
|
1333
|
+
type FenceDimensionUnit = 'px' | 'percent';
|
|
1334
|
+
/** A parsed `width=`/`height=` value with its unit. */
|
|
1335
|
+
interface FenceDimension {
|
|
1336
|
+
value: number;
|
|
1337
|
+
unit: FenceDimensionUnit;
|
|
1338
|
+
}
|
|
1339
|
+
/** The fully-parsed, validated description of one FSL Markdown fence block. */
|
|
1340
|
+
interface FenceDescriptor {
|
|
1341
|
+
parts: FencePart[];
|
|
1342
|
+
ide: boolean;
|
|
1343
|
+
format: FenceImageFormat;
|
|
1344
|
+
width: FenceDimension | null;
|
|
1345
|
+
height: FenceDimension | null;
|
|
1346
|
+
interactive: boolean;
|
|
1347
|
+
notes: string[];
|
|
1348
|
+
}
|
|
1349
|
+
/**
|
|
1350
|
+
* Canonical fence language for an info string, or `null` if the block is not
|
|
1351
|
+
* an FSL fence. Reads only the first whitespace-delimited token,
|
|
1352
|
+
* case-insensitively.
|
|
1353
|
+
* @param info The full fence info string (everything after the opening fence).
|
|
1354
|
+
* @returns `'fsl'` or `'jssm'` for our fences; `null` otherwise.
|
|
1355
|
+
* @example fsl_fence_lang('fsl image code') // => 'fsl'
|
|
1356
|
+
* @example fsl_fence_lang('JSSM') // => 'jssm'
|
|
1357
|
+
* @example fsl_fence_lang('mermaid') // => null
|
|
1358
|
+
*/
|
|
1359
|
+
declare function fsl_fence_lang(info: string): 'fsl' | 'jssm' | null;
|
|
1360
|
+
/**
|
|
1361
|
+
* Parse a fence info string into a {@link FenceDescriptor}. The first token is
|
|
1362
|
+
* the (already-validated) language and is ignored; remaining tokens are
|
|
1363
|
+
* classified as parts, image formats, the `ide` macro, or `width`/`height`
|
|
1364
|
+
* options. Unrecognized or conflicting tokens are dropped and recorded in
|
|
1365
|
+
* `notes` rather than throwing, so a host can render forward-compatibly.
|
|
1366
|
+
* @param info The full fence info string, e.g. `'fsl image code width=300'`.
|
|
1367
|
+
* @returns The validated descriptor; `notes` lists anything ignored or overridden.
|
|
1368
|
+
* @example parse_fence_info('fsl').parts // => ['image', 'code']
|
|
1369
|
+
* @example parse_fence_info('fsl code image').parts // => ['code', 'image']
|
|
1370
|
+
*/
|
|
1371
|
+
declare function parse_fence_info(info: string): FenceDescriptor;
|
|
1372
|
+
|
|
1206
1373
|
/*********
|
|
1207
1374
|
*
|
|
1208
1375
|
* Return the direction of an arrow - `right`, `left`, or `both`.
|
|
@@ -1342,7 +1509,7 @@ declare function arrow_right_kind(arrow: JssmArrow): JssmArrowKind;
|
|
|
1342
1509
|
* tracking on every AST node.
|
|
1343
1510
|
*
|
|
1344
1511
|
*/
|
|
1345
|
-
declare function wrap_parse(input: string, options?:
|
|
1512
|
+
declare function wrap_parse(input: string, options?: object): any;
|
|
1346
1513
|
/*********
|
|
1347
1514
|
*
|
|
1348
1515
|
* Compile a machine's JSON intermediate representation to a config object. If
|
|
@@ -1469,7 +1636,7 @@ declare function make<StateType, mDT>(plan: string): JssmGenericConfig<StateType
|
|
|
1469
1636
|
* @throws {TypeError} If `options` is not a non-empty array of objects.
|
|
1470
1637
|
*
|
|
1471
1638
|
*/
|
|
1472
|
-
declare const weighted_rand_select:
|
|
1639
|
+
declare const weighted_rand_select: (options: Array<any>, probability_property: string, rng: JssmRng) => any;
|
|
1473
1640
|
/*******
|
|
1474
1641
|
*
|
|
1475
1642
|
* Returns, for a non-negative integer argument `n`, the series `[0 .. n]`.
|
|
@@ -1495,7 +1662,7 @@ declare function seq(n: number): number[];
|
|
|
1495
1662
|
* ```
|
|
1496
1663
|
*
|
|
1497
1664
|
*/
|
|
1498
|
-
declare const histograph:
|
|
1665
|
+
declare const histograph: (ar: any[]) => Map<any, number>;
|
|
1499
1666
|
/*******
|
|
1500
1667
|
*
|
|
1501
1668
|
* Draws `n` weighted random samples from an array of objects. Each draw is
|
|
@@ -1519,7 +1686,7 @@ declare const histograph: Function;
|
|
|
1519
1686
|
* @returns An array of `n` independently selected items.
|
|
1520
1687
|
*
|
|
1521
1688
|
*/
|
|
1522
|
-
declare const weighted_sample_select:
|
|
1689
|
+
declare const weighted_sample_select: (n: number, options: Array<any>, probability_property: string, rng?: JssmRng) => Array<any>;
|
|
1523
1690
|
/*******
|
|
1524
1691
|
*
|
|
1525
1692
|
* Draws `n` weighted random samples, extracts a named key from each, and
|
|
@@ -1547,7 +1714,7 @@ declare const weighted_sample_select: Function;
|
|
|
1547
1714
|
* @returns A `Map` from extracted key values to their occurrence counts.
|
|
1548
1715
|
*
|
|
1549
1716
|
*/
|
|
1550
|
-
declare const weighted_histo_key:
|
|
1717
|
+
declare const weighted_histo_key: (n: number, opts: Array<any>, prob_prop: string, extract: string, rng?: JssmRng) => Map<any, number>;
|
|
1551
1718
|
/*******
|
|
1552
1719
|
*
|
|
1553
1720
|
* Creates a SplitMix32 random generator. Used by the randomness test suite.
|
|
@@ -1557,7 +1724,7 @@ declare const weighted_histo_key: Function;
|
|
|
1557
1724
|
* Replaces the Mulberry generator, which was found to have problems
|
|
1558
1725
|
*
|
|
1559
1726
|
*/
|
|
1560
|
-
declare function gen_splitmix32(a?: number
|
|
1727
|
+
declare function gen_splitmix32(a?: number): () => number;
|
|
1561
1728
|
/*******
|
|
1562
1729
|
*
|
|
1563
1730
|
* Reduces an array to its unique contents. Compares with `===` and makes no
|
|
@@ -1611,71 +1778,18 @@ declare function find_repeated<T>(arr: T[]): [T, number][];
|
|
|
1611
1778
|
declare function sleep(ms: number): Promise<unknown>;
|
|
1612
1779
|
|
|
1613
1780
|
/**
|
|
1614
|
-
*
|
|
1615
|
-
*
|
|
1616
|
-
*
|
|
1617
|
-
*
|
|
1618
|
-
* (integer hashing) instead of repeated string-keyed lookups. Internal
|
|
1619
|
-
* machinery only — deliberately not re-exported from the `jssm` public
|
|
1620
|
-
* surface, so the public API is unchanged.
|
|
1621
|
-
*
|
|
1622
|
-
* @internal
|
|
1781
|
+
* The published semantic version of the jssm package this build was cut from.
|
|
1782
|
+
* Mirrored from `package.json` by `src/buildjs/makever.cjs` at build time.
|
|
1783
|
+
* Useful for runtime diagnostics and for embedding in serialized machine
|
|
1784
|
+
* snapshots so that deserializers can detect version-skew.
|
|
1623
1785
|
*/
|
|
1786
|
+
declare const version: string;
|
|
1624
1787
|
/**
|
|
1625
|
-
*
|
|
1626
|
-
*
|
|
1627
|
-
*
|
|
1628
|
-
* after construction; late interning only happens for never-matching
|
|
1629
|
-
* lookups such as hook registrations naming unknown states).
|
|
1630
|
-
*
|
|
1631
|
-
* @example
|
|
1632
|
-
* const i = new Interner();
|
|
1633
|
-
* i.intern('red'); // 0
|
|
1634
|
-
* i.intern('green'); // 1
|
|
1635
|
-
* i.intern('red'); // 0 (idempotent)
|
|
1636
|
-
* i.id_of('green'); // 1
|
|
1637
|
-
* i.name_of(0); // 'red'
|
|
1638
|
-
*
|
|
1639
|
-
* @see pair_key
|
|
1788
|
+
* The Unix epoch timestamp (in milliseconds) at which this build was produced,
|
|
1789
|
+
* written by `src/buildjs/makever.cjs`. Useful for distinguishing builds
|
|
1790
|
+
* with the same `version` string during development, and for diagnostic logs.
|
|
1640
1791
|
*/
|
|
1641
|
-
declare
|
|
1642
|
-
private readonly ids;
|
|
1643
|
-
private readonly names;
|
|
1644
|
-
constructor();
|
|
1645
|
-
/**
|
|
1646
|
-
* Return the id for `name`, assigning the next dense id if the name has
|
|
1647
|
-
* not been seen before.
|
|
1648
|
-
*
|
|
1649
|
-
* @param name - The string to intern.
|
|
1650
|
-
* @returns The (possibly newly assigned) integer id.
|
|
1651
|
-
*
|
|
1652
|
-
* @example
|
|
1653
|
-
* interner.intern('red'); // 0 on first call, 0 on every later call
|
|
1654
|
-
*/
|
|
1655
|
-
intern(name: string): number;
|
|
1656
|
-
/**
|
|
1657
|
-
* Return the id for `name` without interning, or `undefined` when the
|
|
1658
|
-
* name has never been interned. This is the hot-path probe for
|
|
1659
|
-
* user-supplied names.
|
|
1660
|
-
*
|
|
1661
|
-
* @param name - The string to look up.
|
|
1662
|
-
*
|
|
1663
|
-
* @example
|
|
1664
|
-
* interner.id_of('mauve'); // undefined — never interned
|
|
1665
|
-
*/
|
|
1666
|
-
id_of(name: string): number | undefined;
|
|
1667
|
-
/**
|
|
1668
|
-
* Return the name for `id`, or `undefined` for an id never assigned.
|
|
1669
|
-
*
|
|
1670
|
-
* @param id - The integer id to invert.
|
|
1671
|
-
*
|
|
1672
|
-
* @example
|
|
1673
|
-
* interner.name_of(0); // 'red'
|
|
1674
|
-
*/
|
|
1675
|
-
name_of(id: number): string | undefined;
|
|
1676
|
-
/** The count of distinct interned names. */
|
|
1677
|
-
get size(): number;
|
|
1678
|
-
}
|
|
1792
|
+
declare const build_time: number;
|
|
1679
1793
|
|
|
1680
1794
|
/*******
|
|
1681
1795
|
*
|
|
@@ -1747,7 +1861,6 @@ declare const named_colors$1: string[];
|
|
|
1747
1861
|
* Includes ASCII digits/letters and the symbols
|
|
1748
1862
|
* `.`, `+`, `_`, `^`, `(`, `)`, `*`, `&`, `$`, `#`, `@`, `!`, `?`, `,`,
|
|
1749
1863
|
* plus the high-Unicode range `U+0080`–`U+FFFF`.
|
|
1750
|
-
*
|
|
1751
1864
|
* @example
|
|
1752
1865
|
* import { state_name_chars } from 'jssm';
|
|
1753
1866
|
* state_name_chars.some(r => 'A' >= r.from && 'A' <= r.to); // => true
|
|
@@ -1763,7 +1876,6 @@ declare const state_name_chars$1: ReadonlyArray<{
|
|
|
1763
1876
|
* Notably narrower than {@link state_name_chars}: omits `+`, `(`, `)`, `&`,
|
|
1764
1877
|
* `#`, `@`. Includes ASCII digits/letters, `.`, `_`, `!`, `$`, `^`, `*`,
|
|
1765
1878
|
* `?`, `,`, and the high-Unicode range `U+0080`–`U+FFFF`.
|
|
1766
|
-
*
|
|
1767
1879
|
* @example
|
|
1768
1880
|
* import { state_name_first_chars } from 'jssm';
|
|
1769
1881
|
* state_name_first_chars.some(r => '+' >= r.from && '+' <= r.to); // => false
|
|
@@ -1779,7 +1891,6 @@ declare const state_name_first_chars$1: ReadonlyArray<{
|
|
|
1779
1891
|
* excluded since it terminates the label.
|
|
1780
1892
|
*
|
|
1781
1893
|
* Three ranges: `U+0020`–`U+0026`, `U+0028`–`U+005B`, `U+005D`–`U+FFFF`.
|
|
1782
|
-
*
|
|
1783
1894
|
* @example
|
|
1784
1895
|
* import { action_label_chars } from 'jssm';
|
|
1785
1896
|
* action_label_chars.some(r => ' ' >= r.from && ' ' <= r.to); // => true
|
|
@@ -1835,186 +1946,6 @@ declare namespace jssm_constants_d {
|
|
|
1835
1946
|
};
|
|
1836
1947
|
}
|
|
1837
1948
|
|
|
1838
|
-
/**
|
|
1839
|
-
* Editor-agnostic data types for the FSL language service.
|
|
1840
|
-
*
|
|
1841
|
-
* These are the neutral contract every editor adapter (CodeMirror, VS Code, a
|
|
1842
|
-
* future LSP server) converts to/from. Shapes are kept aligned with LSP types so
|
|
1843
|
-
* an LSP wrapper is a near-mechanical mapping.
|
|
1844
|
-
*/
|
|
1845
|
-
/** A character-offset range in the FSL source. */
|
|
1846
|
-
interface Range {
|
|
1847
|
-
from: number;
|
|
1848
|
-
to: number;
|
|
1849
|
-
}
|
|
1850
|
-
/** Diagnostic severity, aligned with LSP severities. */
|
|
1851
|
-
type DiagnosticSeverity = 'error' | 'warning' | 'info' | 'hint';
|
|
1852
|
-
/** An editor-agnostic diagnostic (one parse/compile problem). */
|
|
1853
|
-
interface Diagnostic {
|
|
1854
|
-
range: Range;
|
|
1855
|
-
severity: DiagnosticSeverity;
|
|
1856
|
-
message: string;
|
|
1857
|
-
}
|
|
1858
|
-
/** What a completion item suggests, so adapters can pick an icon. */
|
|
1859
|
-
type CompletionKind = 'key' | 'value-color' | 'value-shape' | 'value-enum';
|
|
1860
|
-
/** An editor-agnostic completion suggestion. */
|
|
1861
|
-
interface CompletionItem {
|
|
1862
|
-
label: string;
|
|
1863
|
-
kind: CompletionKind;
|
|
1864
|
-
detail?: string;
|
|
1865
|
-
}
|
|
1866
|
-
/** Parser-derived semantic role of a source span. */
|
|
1867
|
-
type SemanticSpanKind = 'color' | 'state' | 'enum';
|
|
1868
|
-
/** An editor-agnostic semantic span (for decorations / semantic tokens). */
|
|
1869
|
-
interface SemanticSpan extends Range {
|
|
1870
|
-
kind: SemanticSpanKind;
|
|
1871
|
-
value?: string;
|
|
1872
|
-
}
|
|
1873
|
-
|
|
1874
|
-
/**
|
|
1875
|
-
* Editor-agnostic FSL diagnostics: parse then compile, reporting problems as
|
|
1876
|
-
* neutral {@link Diagnostic}s. Adapters map these to CodeMirror lint diagnostics,
|
|
1877
|
-
* VS Code markers, or LSP `Diagnostic`s.
|
|
1878
|
-
*
|
|
1879
|
-
* Parse errors (peg.js) carry `.location`; compile errors carry
|
|
1880
|
-
* `.source_location` *when they reference a parsed node* — but machine-level
|
|
1881
|
-
* compile errors (e.g. an empty machine, an unknown machine rule) have none, so
|
|
1882
|
-
* the location is treated as optional and falls back to the whole document.
|
|
1883
|
-
*
|
|
1884
|
-
* Some validity checks (e.g. a `required` property that no state defines) live
|
|
1885
|
-
* in the {@link Machine} constructor, a stage past `compile`. We therefore also
|
|
1886
|
-
* construct the machine so the editor surfaces those construction-time errors
|
|
1887
|
-
* instead of calling such a machine valid. The `Machine` import closes a cycle
|
|
1888
|
-
* (`jssm` re-exports this module), but it is only referenced at call time inside
|
|
1889
|
-
* {@link fslDiagnostics}, never during module initialization, so the cycle is
|
|
1890
|
-
* benign.
|
|
1891
|
-
*/
|
|
1892
|
-
|
|
1893
|
-
/**
|
|
1894
|
-
* Parse then compile `text`, returning a list of diagnostics — empty when the
|
|
1895
|
-
* machine parses and compiles cleanly.
|
|
1896
|
-
*
|
|
1897
|
-
* @example
|
|
1898
|
-
* fslDiagnostics('a -> b;'); // => []
|
|
1899
|
-
* fslDiagnostics('a -> ;')[0].severity; // => 'error'
|
|
1900
|
-
* // a `required` property no state defines is a construction-time error:
|
|
1901
|
-
* fslDiagnostics('property p required; a -> b;')[0].severity; // => 'error'
|
|
1902
|
-
*/
|
|
1903
|
-
declare function fslDiagnostics(text: string): Diagnostic[];
|
|
1904
|
-
|
|
1905
|
-
/**
|
|
1906
|
-
* Context-aware, editor-agnostic FSL completions. Value suggestions after a
|
|
1907
|
-
* `key:`, key suggestions at a statement start (top-level vs inside a `{ }`
|
|
1908
|
-
* block, by brace depth). Adapters convert {@link CompletionItem}s to their own
|
|
1909
|
-
* completion type. Value vocab is jssm's own (`gviz_shapes`, `named_colors`,
|
|
1910
|
-
* `FslDirections`), so it cannot drift from the renderer.
|
|
1911
|
-
*/
|
|
1912
|
-
|
|
1913
|
-
/**
|
|
1914
|
-
* Completions for the caret at `offset` in `text`.
|
|
1915
|
-
*
|
|
1916
|
-
* @example
|
|
1917
|
-
* fslCompletions('state x : { color: ', 19)[0].kind; // => 'value-color'
|
|
1918
|
-
*/
|
|
1919
|
-
declare function fslCompletions(text: string, offset: number): CompletionItem[];
|
|
1920
|
-
|
|
1921
|
-
/**
|
|
1922
|
-
* Parser-derived semantic spans for FSL: color values (with resolved hex),
|
|
1923
|
-
* state names, and shape-enum values. Returns `[]` if the document does not
|
|
1924
|
-
* parse. Editor-agnostic — adapters map spans to decorations or semantic
|
|
1925
|
-
* tokens. Logic is a verified port of the sketch's `semantic_overlay.mjs`.
|
|
1926
|
-
*/
|
|
1927
|
-
|
|
1928
|
-
/**
|
|
1929
|
-
* Collect color / state / shape-enum semantic spans from `text`. State spans
|
|
1930
|
-
* cover transition endpoints, state-declaration subjects, group-list members
|
|
1931
|
-
* (`&G : [a b c];` — but not the group's own name, nor `&`/`...&` nested
|
|
1932
|
-
* group references), and plain-label hook subjects (`on enter x do 'act';` —
|
|
1933
|
-
* but not `&group` subjects). Every state span's `value` is the parser's
|
|
1934
|
-
* resolved name (unquoted, unescaped), while `from`/`to` cover the source
|
|
1935
|
-
* spelling including any quotes.
|
|
1936
|
-
*
|
|
1937
|
-
* @example
|
|
1938
|
-
* fslSemanticSpans('state s : { color: crimson; };')
|
|
1939
|
-
* .find(s => s.kind === 'color')?.value; // => '#dc143cff'
|
|
1940
|
-
*
|
|
1941
|
-
* @example
|
|
1942
|
-
* fslSemanticSpans('&G : [a b];\na -> b;')
|
|
1943
|
-
* .filter(s => s.kind === 'state').length; // => 4 (two members + two endpoints)
|
|
1944
|
-
*/
|
|
1945
|
-
declare function fslSemanticSpans(text: string): SemanticSpan[];
|
|
1946
|
-
|
|
1947
|
-
/**
|
|
1948
|
-
* The published semantic version of the jssm package this build was cut from.
|
|
1949
|
-
* Mirrored from `package.json` by `src/buildjs/makever.cjs` at build time.
|
|
1950
|
-
* Useful for runtime diagnostics and for embedding in serialized machine
|
|
1951
|
-
* snapshots so that deserializers can detect version-skew.
|
|
1952
|
-
*/
|
|
1953
|
-
declare const version: string;
|
|
1954
|
-
/**
|
|
1955
|
-
* The Unix epoch timestamp (in milliseconds) at which this build was produced,
|
|
1956
|
-
* written by `src/buildjs/makever.cjs`. Useful for distinguishing builds
|
|
1957
|
-
* with the same `version` string during development, and for diagnostic logs.
|
|
1958
|
-
*/
|
|
1959
|
-
declare const build_time: number;
|
|
1960
|
-
|
|
1961
|
-
/**
|
|
1962
|
-
* The FSL Markdown fence convention parser — pure, host-agnostic logic that
|
|
1963
|
-
* turns a fenced-code-block info string into a {@link FenceDescriptor}. Hosts
|
|
1964
|
-
* (a VS Code preview plugin, a static-site generator, …) each interpret the
|
|
1965
|
-
* descriptor according to their capabilities.
|
|
1966
|
-
*
|
|
1967
|
-
* @see notes/superpowers/specs/2026-06-23-fsl-markdown-fence-convention-design.md
|
|
1968
|
-
*/
|
|
1969
|
-
/** A single renderable part of a fence block (stacks in listed order, first on top). */
|
|
1970
|
-
type FencePart = 'image' | 'code' | 'dot' | 'editor' | 'actions' | 'info-panel' | 'toolbar' | 'title' | 'footer';
|
|
1971
|
-
/** An image output format for the `image` part. */
|
|
1972
|
-
type FenceImageFormat = 'svg' | 'png' | 'jpeg' | 'gif';
|
|
1973
|
-
/** The unit of a {@link FenceDimension} (`%` is represented as `'percent'`). */
|
|
1974
|
-
type FenceDimensionUnit = 'px' | 'percent';
|
|
1975
|
-
/** A parsed `width=`/`height=` value with its unit. */
|
|
1976
|
-
interface FenceDimension {
|
|
1977
|
-
value: number;
|
|
1978
|
-
unit: FenceDimensionUnit;
|
|
1979
|
-
}
|
|
1980
|
-
/** The fully-parsed, validated description of one FSL Markdown fence block. */
|
|
1981
|
-
interface FenceDescriptor {
|
|
1982
|
-
parts: FencePart[];
|
|
1983
|
-
ide: boolean;
|
|
1984
|
-
format: FenceImageFormat;
|
|
1985
|
-
width: FenceDimension | null;
|
|
1986
|
-
height: FenceDimension | null;
|
|
1987
|
-
interactive: boolean;
|
|
1988
|
-
notes: string[];
|
|
1989
|
-
}
|
|
1990
|
-
/**
|
|
1991
|
-
* Canonical fence language for an info string, or `null` if the block is not
|
|
1992
|
-
* an FSL fence. Reads only the first whitespace-delimited token,
|
|
1993
|
-
* case-insensitively.
|
|
1994
|
-
*
|
|
1995
|
-
* @param info The full fence info string (everything after the opening fence).
|
|
1996
|
-
* @returns `'fsl'` or `'jssm'` for our fences; `null` otherwise.
|
|
1997
|
-
*
|
|
1998
|
-
* @example fsl_fence_lang('fsl image code') // => 'fsl'
|
|
1999
|
-
* @example fsl_fence_lang('JSSM') // => 'jssm'
|
|
2000
|
-
* @example fsl_fence_lang('mermaid') // => null
|
|
2001
|
-
*/
|
|
2002
|
-
declare function fsl_fence_lang(info: string): 'fsl' | 'jssm' | null;
|
|
2003
|
-
/**
|
|
2004
|
-
* Parse a fence info string into a {@link FenceDescriptor}. The first token is
|
|
2005
|
-
* the (already-validated) language and is ignored; remaining tokens are
|
|
2006
|
-
* classified as parts, image formats, the `ide` macro, or `width`/`height`
|
|
2007
|
-
* options. Unrecognized or conflicting tokens are dropped and recorded in
|
|
2008
|
-
* `notes` rather than throwing, so a host can render forward-compatibly.
|
|
2009
|
-
*
|
|
2010
|
-
* @param info The full fence info string, e.g. `'fsl image code width=300'`.
|
|
2011
|
-
* @returns The validated descriptor; `notes` lists anything ignored or overridden.
|
|
2012
|
-
*
|
|
2013
|
-
* @example parse_fence_info('fsl').parts // => ['image', 'code']
|
|
2014
|
-
* @example parse_fence_info('fsl code image').parts // => ['code', 'image']
|
|
2015
|
-
*/
|
|
2016
|
-
declare function parse_fence_info(info: string): FenceDescriptor;
|
|
2017
|
-
|
|
2018
1949
|
type StateType = string;
|
|
2019
1950
|
|
|
2020
1951
|
declare const shapes: string[];
|
|
@@ -2037,7 +1968,6 @@ declare const action_label_chars: readonly {
|
|
|
2037
1968
|
* Internal record holding a single registered event subscription: the
|
|
2038
1969
|
* handler, its optional filter, and a flag for `once` semantics. Not
|
|
2039
1970
|
* exported.
|
|
2040
|
-
*
|
|
2041
1971
|
* @internal
|
|
2042
1972
|
*/
|
|
2043
1973
|
type JssmEventEntry<mDT, Ev extends JssmEventName> = {
|
|
@@ -2055,63 +1985,14 @@ type JssmEventEntry<mDT, Ev extends JssmEventName> = {
|
|
|
2055
1985
|
*
|
|
2056
1986
|
*/
|
|
2057
1987
|
declare function transfer_state_properties(state_decl: JssmStateDeclaration): JssmStateDeclaration;
|
|
2058
|
-
/**
|
|
2059
|
-
*
|
|
2060
|
-
* Collapse a list of individual state-style key/value pairs into a single
|
|
2061
|
-
* {@link JssmStateConfig} object, remapping FSL-style kebab-case keys to the
|
|
2062
|
-
* camelCase field names the runtime uses.
|
|
2063
|
-
*
|
|
2064
|
-
* The parser emits state styling as a flat array like
|
|
2065
|
-
* `[{ key: 'color', value: 'red' }, { key: 'line-style', value: 'dashed' }]`
|
|
2066
|
-
* because that is the most natural shape for the grammar to produce. This
|
|
2067
|
-
* helper runs once per style bucket during `Machine` construction to turn
|
|
2068
|
-
* those arrays into the compact `{ color, lineStyle, ... }` objects the
|
|
2069
|
-
* graph-rendering code expects.
|
|
2070
|
-
*
|
|
2071
|
-
* ```typescript
|
|
2072
|
-
* state_style_condense([
|
|
2073
|
-
* { key: 'color', value: 'red' },
|
|
2074
|
-
* { key: 'shape', value: 'oval' },
|
|
2075
|
-
* { key: 'line-style', value: 'dashed' }
|
|
2076
|
-
* ]);
|
|
2077
|
-
* // => { color: 'red', shape: 'oval', lineStyle: 'dashed' }
|
|
2078
|
-
*
|
|
2079
|
-
* state_style_condense(undefined);
|
|
2080
|
-
* // => {}
|
|
2081
|
-
* ```
|
|
2082
|
-
*
|
|
2083
|
-
* @param jssk The list of style keys to condense. `undefined` is accepted
|
|
2084
|
-
* and yields an empty config.
|
|
2085
|
-
*
|
|
2086
|
-
* @param machine Optional `Machine` reference, used only so that any
|
|
2087
|
-
* {@link JssmError} thrown can point at the offending machine in its
|
|
2088
|
-
* diagnostic message.
|
|
2089
|
-
*
|
|
2090
|
-
* @returns A `JssmStateConfig` object containing every key from `jssk`
|
|
2091
|
-
* remapped into its camelCase field.
|
|
2092
|
-
*
|
|
2093
|
-
* @throws {JssmError} If `jssk` is neither an array nor `undefined`, if any
|
|
2094
|
-
* element is not an object, if the same key appears more than once, or if a
|
|
2095
|
-
* key is not one of the recognized style names.
|
|
2096
|
-
*
|
|
2097
|
-
* @internal
|
|
2098
|
-
*
|
|
2099
|
-
*/
|
|
2100
1988
|
declare function state_style_condense(jssk: JssmStateStyleKeyList, machine?: any): JssmStateConfig;
|
|
2101
1989
|
/** Default number of independent Monte-Carlo runs when none is declared. */
|
|
2102
1990
|
declare const STOCHASTIC_DEFAULT_RUNS = 1000;
|
|
2103
1991
|
/** Default per-run step cap (montecarlo) / walk length (steady_state). */
|
|
2104
1992
|
declare const STOCHASTIC_DEFAULT_MAX_STEPS = 1000;
|
|
2105
1993
|
declare class Machine<mDT> {
|
|
1994
|
+
#private;
|
|
2106
1995
|
_state: StateType;
|
|
2107
|
-
_states: Map<StateType, JssmGenericState>;
|
|
2108
|
-
_edges: Array<JssmTransition<StateType, mDT>>;
|
|
2109
|
-
_edge_map: Map<StateType, Map<StateType, number>>;
|
|
2110
|
-
_outbound_edge_ids: Map<StateType, Array<number>>;
|
|
2111
|
-
_named_transitions: Map<StateType, number>;
|
|
2112
|
-
_actions: Map<StateType, Map<StateType, number>>;
|
|
2113
|
-
_reverse_actions: Map<StateType, Map<StateType, number>>;
|
|
2114
|
-
_reverse_action_targets: Map<StateType, Map<StateType, number>>;
|
|
2115
1996
|
_state_interner: Interner;
|
|
2116
1997
|
_action_interner: Interner;
|
|
2117
1998
|
_state_id: number;
|
|
@@ -2132,7 +2013,7 @@ declare class Machine<mDT> {
|
|
|
2132
2013
|
_npm_name?: string;
|
|
2133
2014
|
_default_size?: JssmDefaultSize;
|
|
2134
2015
|
_fsl_version?: string;
|
|
2135
|
-
_raw_state_declaration?: Array<
|
|
2016
|
+
_raw_state_declaration?: Array<object>;
|
|
2136
2017
|
_state_declarations: Map<StateType, JssmStateDeclaration>;
|
|
2137
2018
|
_data?: mDT;
|
|
2138
2019
|
_instance_name: string;
|
|
@@ -2220,8 +2101,8 @@ declare class Machine<mDT> {
|
|
|
2220
2101
|
_create_started: number;
|
|
2221
2102
|
_created: number;
|
|
2222
2103
|
_after_mapping: Map<string, [string, number]>;
|
|
2223
|
-
_timeout_source: (
|
|
2224
|
-
_clear_timeout_source: (h:
|
|
2104
|
+
_timeout_source: (f: () => void, a: number) => number;
|
|
2105
|
+
_clear_timeout_source: (h: number) => void;
|
|
2225
2106
|
_timeout_handle: number | undefined;
|
|
2226
2107
|
_timeout_target: string | undefined;
|
|
2227
2108
|
_timeout_target_time: number | undefined;
|
|
@@ -2374,9 +2255,7 @@ declare class Machine<mDT> {
|
|
|
2374
2255
|
* const m = jssm.from('on <=> off;', { data: { a: { b: 1 } } });
|
|
2375
2256
|
* m._data_ref().a.b; // 1, zero-copy
|
|
2376
2257
|
* ```
|
|
2377
|
-
*
|
|
2378
2258
|
* @returns The live data value; treat as read-only.
|
|
2379
|
-
*
|
|
2380
2259
|
* @see Machine.data
|
|
2381
2260
|
* @internal
|
|
2382
2261
|
*/
|
|
@@ -2634,18 +2513,21 @@ declare class Machine<mDT> {
|
|
|
2634
2513
|
* current state, data, and timestamp.
|
|
2635
2514
|
*
|
|
2636
2515
|
*/
|
|
2637
|
-
serialize(comment?: string
|
|
2638
|
-
/**
|
|
2516
|
+
serialize(comment?: string): JssmSerialization<mDT>;
|
|
2517
|
+
/**
|
|
2518
|
+
* Get the graph layout direction (e.g. `'LR'`, `'TB'`). Set via the
|
|
2639
2519
|
* FSL `graph_layout` directive.
|
|
2640
2520
|
* @returns The layout string, or the default if not set.
|
|
2641
2521
|
*/
|
|
2642
2522
|
graph_layout(): string;
|
|
2643
|
-
/**
|
|
2523
|
+
/**
|
|
2524
|
+
* Get the Graphviz DOT preamble string, injected before the graph body
|
|
2644
2525
|
* during visualization. Set via the FSL `dot_preamble` directive.
|
|
2645
2526
|
* @returns The preamble string.
|
|
2646
2527
|
*/
|
|
2647
2528
|
dot_preamble(): string;
|
|
2648
|
-
/**
|
|
2529
|
+
/**
|
|
2530
|
+
* Get the consolidated `transition: {}` default-config block: the ordered,
|
|
2649
2531
|
* de-duplicated `{ key, value }[]` list of edge-default style items compiled
|
|
2650
2532
|
* from a `transition: {}` block (e.g. `transition: { color: blue; }`). The
|
|
2651
2533
|
* viz layer projects this onto a Graphviz `edge [ … ]` default statement so
|
|
@@ -2656,13 +2538,13 @@ declare class Machine<mDT> {
|
|
|
2656
2538
|
* sm`a -> b; transition: { color: blue; };`.default_transition_config();
|
|
2657
2539
|
* // [ { key: 'color', value: '#0000ffff' } ]
|
|
2658
2540
|
* ```
|
|
2659
|
-
*
|
|
2660
2541
|
* @returns The transition-config item list, or `undefined` if the machine
|
|
2661
2542
|
* declared no `transition: {}` block.
|
|
2662
2543
|
* @see default_graph_config
|
|
2663
2544
|
*/
|
|
2664
2545
|
default_transition_config(): JssmTransitionConfig | undefined;
|
|
2665
|
-
/**
|
|
2546
|
+
/**
|
|
2547
|
+
* Get the consolidated `graph: {}` default-config block: the ordered,
|
|
2666
2548
|
* de-duplicated `{ key, value }[]` list of graph-scope style items. The
|
|
2667
2549
|
* compiler folds the deprecated top-level graph keywords
|
|
2668
2550
|
* (`graph_bg_color` → `background-color`, plus `graph_layout`, `theme`,
|
|
@@ -2676,29 +2558,33 @@ declare class Machine<mDT> {
|
|
|
2676
2558
|
* sm`a -> b; graph: { background-color: #ffffff; };`.default_graph_config();
|
|
2677
2559
|
* // [ { key: 'background-color', value: '#ffffffff' } ]
|
|
2678
2560
|
* ```
|
|
2679
|
-
*
|
|
2680
2561
|
* @returns The graph-config item list, or `undefined` if the machine has no
|
|
2681
2562
|
* graph config (no `graph: {}` block and no deprecated graph keyword).
|
|
2682
2563
|
* @see default_transition_config
|
|
2683
2564
|
*/
|
|
2684
2565
|
default_graph_config(): JssmGraphConfig | undefined;
|
|
2685
|
-
/**
|
|
2566
|
+
/**
|
|
2567
|
+
* Get the machine's author list. Set via the FSL `machine_author` directive.
|
|
2686
2568
|
* @returns An array of author name strings.
|
|
2687
2569
|
*/
|
|
2688
2570
|
machine_author(): Array<string>;
|
|
2689
|
-
/**
|
|
2571
|
+
/**
|
|
2572
|
+
* Get the machine's comment string. Set via the FSL `machine_comment` directive.
|
|
2690
2573
|
* @returns The comment string.
|
|
2691
2574
|
*/
|
|
2692
2575
|
machine_comment(): string;
|
|
2693
|
-
/**
|
|
2576
|
+
/**
|
|
2577
|
+
* Get the machine's contributor list. Set via the FSL `machine_contributor` directive.
|
|
2694
2578
|
* @returns An array of contributor name strings.
|
|
2695
2579
|
*/
|
|
2696
2580
|
machine_contributor(): Array<string>;
|
|
2697
|
-
/**
|
|
2581
|
+
/**
|
|
2582
|
+
* Get the machine's definition string. Set via the FSL `machine_definition` directive.
|
|
2698
2583
|
* @returns The definition string.
|
|
2699
2584
|
*/
|
|
2700
2585
|
machine_definition(): string;
|
|
2701
|
-
/**
|
|
2586
|
+
/**
|
|
2587
|
+
* Get the machine's natural language as an ISO 639-1 code. Set via the FSL
|
|
2702
2588
|
* `machine_language` directive, which accepts a language name or code, or a
|
|
2703
2589
|
* BCP-47 tag whose region subtag is dropped (`en-us` -> `en`). Unrecognized
|
|
2704
2590
|
* values resolve to `undefined`.
|
|
@@ -2706,32 +2592,35 @@ declare class Machine<mDT> {
|
|
|
2706
2592
|
* supplied value did not resolve to a known language.
|
|
2707
2593
|
*/
|
|
2708
2594
|
machine_language(): string;
|
|
2709
|
-
/**
|
|
2595
|
+
/**
|
|
2596
|
+
* Get the machine's license string. Set via the FSL `machine_license` directive.
|
|
2710
2597
|
* @returns The license string.
|
|
2711
2598
|
*/
|
|
2712
2599
|
machine_license(): string;
|
|
2713
|
-
/**
|
|
2600
|
+
/**
|
|
2601
|
+
* Get the machine's name. Set via the FSL `machine_name` directive.
|
|
2714
2602
|
* @returns The machine name string.
|
|
2715
2603
|
*/
|
|
2716
2604
|
machine_name(): string;
|
|
2717
|
-
/**
|
|
2605
|
+
/**
|
|
2606
|
+
* The editor/panel defaults declared in the FSL `editor: {}` block, or
|
|
2718
2607
|
* `undefined` when none was given. Read by the all-widgets web control
|
|
2719
2608
|
* (fsl#1334) — `panels` drives `request` panel mode.
|
|
2720
|
-
*
|
|
2721
2609
|
* @returns `{ stochastic_run_count?, panels? }`, or `undefined`.
|
|
2722
|
-
*
|
|
2723
2610
|
* @example
|
|
2724
2611
|
* const m = sm`editor: { panels: [history]; }; a -> b;`;
|
|
2725
2612
|
* m.editor_config(); // => { panels: ['history'] }
|
|
2726
2613
|
*/
|
|
2727
2614
|
editor_config(): JssmEditorConfig | undefined;
|
|
2728
|
-
/**
|
|
2615
|
+
/**
|
|
2616
|
+
* Get the npm package name associated with the machine. Set via the FSL `npm_name` directive.
|
|
2729
2617
|
* Returns `undefined` when not present.
|
|
2730
2618
|
* @returns The npm package name string, or `undefined`.
|
|
2731
2619
|
* @see machine_name
|
|
2732
2620
|
*/
|
|
2733
2621
|
npm_name(): string;
|
|
2734
|
-
/**
|
|
2622
|
+
/**
|
|
2623
|
+
* Get the render-size hint for the machine's visualization. Set via the
|
|
2735
2624
|
* FSL `default_size` directive. Returns `undefined` when not present.
|
|
2736
2625
|
*
|
|
2737
2626
|
* The three FSL forms each produce a different subset of fields:
|
|
@@ -2741,33 +2630,38 @@ declare class Machine<mDT> {
|
|
|
2741
2630
|
* - `default_size: height 600;` → `{ height: 600 }`
|
|
2742
2631
|
*
|
|
2743
2632
|
* This is a hint, not a hard constraint. Renderers may ignore it.
|
|
2744
|
-
*
|
|
2745
2633
|
* @returns The size-hint object, or `undefined` if not set.
|
|
2746
2634
|
* @see npm_name
|
|
2747
2635
|
*/
|
|
2748
2636
|
default_size(): JssmDefaultSize | undefined;
|
|
2749
|
-
/**
|
|
2637
|
+
/**
|
|
2638
|
+
* Get the machine's version string. Set via the FSL `machine_version` directive.
|
|
2750
2639
|
* @returns The version string.
|
|
2751
2640
|
*/
|
|
2752
2641
|
machine_version(): string;
|
|
2753
|
-
/**
|
|
2642
|
+
/**
|
|
2643
|
+
* Get the raw state declaration objects as parsed from the FSL source.
|
|
2754
2644
|
* @returns An array of raw state declaration objects.
|
|
2755
2645
|
*/
|
|
2756
|
-
raw_state_declarations(): Array<
|
|
2757
|
-
/**
|
|
2646
|
+
raw_state_declarations(): Array<object>;
|
|
2647
|
+
/**
|
|
2648
|
+
* Get the processed state declaration for a specific state.
|
|
2758
2649
|
* @param which - The state to look up.
|
|
2759
2650
|
* @returns The {@link JssmStateDeclaration} for the given state.
|
|
2760
2651
|
*/
|
|
2761
2652
|
state_declaration(which: StateType): JssmStateDeclaration;
|
|
2762
|
-
/**
|
|
2653
|
+
/**
|
|
2654
|
+
* Get all processed state declarations as a Map.
|
|
2763
2655
|
* @returns A `Map` from state name to {@link JssmStateDeclaration}.
|
|
2764
2656
|
*/
|
|
2765
2657
|
state_declarations(): Map<StateType, JssmStateDeclaration>;
|
|
2766
|
-
/**
|
|
2658
|
+
/**
|
|
2659
|
+
* Get the FSL language version this machine was compiled under.
|
|
2767
2660
|
* @returns The FSL version string.
|
|
2768
2661
|
*/
|
|
2769
2662
|
fsl_version(): string;
|
|
2770
|
-
/**
|
|
2663
|
+
/**
|
|
2664
|
+
* Get the complete internal state of the machine as a serializable
|
|
2771
2665
|
* structure. Includes actions, edges, edge map, named transitions,
|
|
2772
2666
|
* reverse actions, current state, and states map.
|
|
2773
2667
|
* @returns A {@link JssmMachineInternalState} snapshot.
|
|
@@ -2791,7 +2685,8 @@ declare class Machine<mDT> {
|
|
|
2791
2685
|
*
|
|
2792
2686
|
*/
|
|
2793
2687
|
states(): Array<StateType>;
|
|
2794
|
-
/**
|
|
2688
|
+
/**
|
|
2689
|
+
* Get the internal state descriptor for a given state name.
|
|
2795
2690
|
* @param whichState - The state to look up.
|
|
2796
2691
|
* @returns The {@link JssmGenericState} descriptor.
|
|
2797
2692
|
* @throws {JssmError} If the state does not exist.
|
|
@@ -2854,19 +2749,23 @@ declare class Machine<mDT> {
|
|
|
2854
2749
|
*
|
|
2855
2750
|
*/
|
|
2856
2751
|
list_edges(): Array<JssmTransition<StateType, mDT>>;
|
|
2857
|
-
/**
|
|
2752
|
+
/**
|
|
2753
|
+
* Get the map of named transitions (transitions with explicit names).
|
|
2858
2754
|
* @returns A `Map` from transition name to edge index.
|
|
2859
2755
|
*/
|
|
2860
2756
|
list_named_transitions(): Map<StateType, number>;
|
|
2861
|
-
/**
|
|
2757
|
+
/**
|
|
2758
|
+
* List all distinct action names defined anywhere in the machine.
|
|
2862
2759
|
* @returns An array of action name strings.
|
|
2863
2760
|
*/
|
|
2864
2761
|
list_actions(): Array<StateType>;
|
|
2865
|
-
/**
|
|
2762
|
+
/**
|
|
2763
|
+
* Whether any actions are defined on this machine.
|
|
2866
2764
|
* @returns `true` if the machine has at least one action.
|
|
2867
2765
|
*/
|
|
2868
2766
|
get uses_actions(): boolean;
|
|
2869
|
-
/**
|
|
2767
|
+
/**
|
|
2768
|
+
* Whether any forced (`~>`) transitions exist in this machine.
|
|
2870
2769
|
* @returns `true` if at least one forced transition is defined.
|
|
2871
2770
|
*/
|
|
2872
2771
|
get uses_forced_transitions(): boolean;
|
|
@@ -2907,16 +2806,16 @@ declare class Machine<mDT> {
|
|
|
2907
2806
|
*
|
|
2908
2807
|
*/
|
|
2909
2808
|
get allow_islands(): JssmAllowIslands;
|
|
2910
|
-
/**
|
|
2809
|
+
/**
|
|
2810
|
+
* List all available theme names.
|
|
2911
2811
|
* @returns An array of theme name strings.
|
|
2912
2812
|
*/
|
|
2913
2813
|
all_themes(): FslTheme[];
|
|
2914
|
-
/**
|
|
2814
|
+
/**
|
|
2815
|
+
* List the character ranges accepted by the FSL grammar in any but the
|
|
2915
2816
|
* first position of a state name (atom). Each entry is an inclusive
|
|
2916
2817
|
* `{from, to}` range of single Unicode characters.
|
|
2917
|
-
*
|
|
2918
2818
|
* @returns An array of `{from, to}` inclusive character ranges.
|
|
2919
|
-
*
|
|
2920
2819
|
* @example
|
|
2921
2820
|
* import { sm } from 'jssm';
|
|
2922
2821
|
* const m = sm`a -> b;`;
|
|
@@ -2926,12 +2825,11 @@ declare class Machine<mDT> {
|
|
|
2926
2825
|
from: string;
|
|
2927
2826
|
to: string;
|
|
2928
2827
|
}>;
|
|
2929
|
-
/**
|
|
2828
|
+
/**
|
|
2829
|
+
* List the character ranges accepted by the FSL grammar in the first
|
|
2930
2830
|
* position of a state name (atom). Narrower than
|
|
2931
2831
|
* {@link all_state_name_chars}: notably omits `+`, `(`, `)`, `&`, `#`, `@`.
|
|
2932
|
-
*
|
|
2933
2832
|
* @returns An array of `{from, to}` inclusive character ranges.
|
|
2934
|
-
*
|
|
2935
2833
|
* @example
|
|
2936
2834
|
* import { sm } from 'jssm';
|
|
2937
2835
|
* const m = sm`a -> b;`;
|
|
@@ -2941,12 +2839,11 @@ declare class Machine<mDT> {
|
|
|
2941
2839
|
from: string;
|
|
2942
2840
|
to: string;
|
|
2943
2841
|
}>;
|
|
2944
|
-
/**
|
|
2842
|
+
/**
|
|
2843
|
+
* List the character ranges accepted inside a single-quoted FSL action
|
|
2945
2844
|
* label without escaping. Space is allowed; the apostrophe `'` is
|
|
2946
2845
|
* explicitly excluded since it terminates the label.
|
|
2947
|
-
*
|
|
2948
2846
|
* @returns An array of `{from, to}` inclusive character ranges.
|
|
2949
|
-
*
|
|
2950
2847
|
* @example
|
|
2951
2848
|
* import { sm } from 'jssm';
|
|
2952
2849
|
* const m = sm`a -> b;`;
|
|
@@ -2957,28 +2854,33 @@ declare class Machine<mDT> {
|
|
|
2957
2854
|
from: string;
|
|
2958
2855
|
to: string;
|
|
2959
2856
|
}>;
|
|
2960
|
-
/**
|
|
2857
|
+
/**
|
|
2858
|
+
* Get the active theme(s) for this machine. Always stored as an array
|
|
2961
2859
|
* internally; the union return type exists for setter compatibility.
|
|
2962
2860
|
* @returns The current theme or array of themes.
|
|
2963
2861
|
*/
|
|
2964
2862
|
get themes(): FslTheme | FslTheme[];
|
|
2965
|
-
/**
|
|
2863
|
+
/**
|
|
2864
|
+
* Set the active theme(s). Accepts a single theme name or an array.
|
|
2966
2865
|
* @param to - A theme name or array of theme names to apply.
|
|
2967
2866
|
*/
|
|
2968
2867
|
set themes(to: FslTheme | FslTheme[]);
|
|
2969
|
-
/**
|
|
2868
|
+
/**
|
|
2869
|
+
* Get the flow direction for graph layout (e.g. `'right'`, `'down'`).
|
|
2970
2870
|
* Set via the FSL `flow` directive.
|
|
2971
2871
|
* @returns The current flow direction.
|
|
2972
2872
|
*/
|
|
2973
2873
|
flow(): FslDirection;
|
|
2974
|
-
/**
|
|
2874
|
+
/**
|
|
2875
|
+
* Look up a transition's edge index by source and target state names.
|
|
2975
2876
|
* @param from - Source state name.
|
|
2976
2877
|
* @param to - Target state name.
|
|
2977
2878
|
* @returns The edge index in the edges array, or `undefined` if no
|
|
2978
2879
|
* such transition exists.
|
|
2979
2880
|
*/
|
|
2980
2881
|
get_transition_by_state_names(from: StateType, to: StateType): number;
|
|
2981
|
-
/**
|
|
2882
|
+
/**
|
|
2883
|
+
* Look up the full transition object for a given source→target pair.
|
|
2982
2884
|
* @param from - Source state name.
|
|
2983
2885
|
* @param to - Target state name.
|
|
2984
2886
|
* @returns The {@link JssmTransition} object, or `undefined` if none exists.
|
|
@@ -3050,7 +2952,8 @@ declare class Machine<mDT> {
|
|
|
3050
2952
|
*
|
|
3051
2953
|
*/
|
|
3052
2954
|
list_exits(whichState?: StateType): Array<StateType>;
|
|
3053
|
-
/**
|
|
2955
|
+
/**
|
|
2956
|
+
* Get the transitions available from a state for use by the probabilistic
|
|
3054
2957
|
* walk system.
|
|
3055
2958
|
*
|
|
3056
2959
|
* If any exit declares a `probability`, only those probability-bearing
|
|
@@ -3063,37 +2966,39 @@ declare class Machine<mDT> {
|
|
|
3063
2966
|
* Fixes StoneCypher/fsl#1325, in which the function previously returned
|
|
3064
2967
|
* every exit unconditionally — including forced-only exits and exits
|
|
3065
2968
|
* with no `probability`, which distorted the weighted distribution.
|
|
3066
|
-
*
|
|
3067
2969
|
* @param whichState - The state to inspect.
|
|
3068
2970
|
* @returns An array of {@link JssmTransition} edges exiting the state,
|
|
3069
2971
|
* filtered as described above. May be empty.
|
|
3070
2972
|
* @throws {JssmError} If the state does not exist.
|
|
3071
2973
|
*/
|
|
3072
2974
|
probable_exits_for(whichState: StateType): Array<JssmTransition<StateType, mDT>>;
|
|
3073
|
-
/**
|
|
2975
|
+
/**
|
|
2976
|
+
* Take a single random transition from the current state, weighted by
|
|
3074
2977
|
* edge probabilities.
|
|
3075
2978
|
* @returns `true` if a transition was taken, `false` otherwise.
|
|
3076
2979
|
*/
|
|
3077
2980
|
probabilistic_transition(): boolean;
|
|
3078
|
-
/**
|
|
2981
|
+
/**
|
|
2982
|
+
* Take `n` consecutive probabilistic transitions and return the sequence
|
|
3079
2983
|
* of states visited (before each transition).
|
|
3080
2984
|
* @param n - Number of steps to walk.
|
|
3081
2985
|
* @returns An array of state names visited during the walk.
|
|
3082
2986
|
*/
|
|
3083
2987
|
probabilistic_walk(n: number): Array<StateType>;
|
|
3084
|
-
/**
|
|
2988
|
+
/**
|
|
2989
|
+
* Take `n` probabilistic steps and return a histograph of how many times
|
|
3085
2990
|
* each state was visited.
|
|
3086
2991
|
* @param n - Number of steps to walk.
|
|
3087
2992
|
* @returns A `Map` from state name to visit count.
|
|
3088
2993
|
*/
|
|
3089
2994
|
probabilistic_histo_walk(n: number): Map<StateType, number>;
|
|
3090
|
-
/**
|
|
2995
|
+
/**
|
|
2996
|
+
* One non-destructive weighted-random walk over the graph from `start`.
|
|
3091
2997
|
*
|
|
3092
2998
|
* Reads the graph and advances the PRNG only — it never calls
|
|
3093
2999
|
* {@link Machine.transition}, so it fires no hooks, mutates no machine
|
|
3094
3000
|
* state, and touches no `data`. A state with no probabilistic exits
|
|
3095
3001
|
* (a terminal, or a forced-only `~>` state) ends the walk.
|
|
3096
|
-
*
|
|
3097
3002
|
* @param start - State to begin the walk from.
|
|
3098
3003
|
* @param max_steps - Maximum transitions before the walk is step-capped.
|
|
3099
3004
|
* @param exit_memo - Per-run-set cache of {@link Machine.probable_exits_for}
|
|
@@ -3106,7 +3011,8 @@ declare class Machine<mDT> {
|
|
|
3106
3011
|
* @returns The {@link JssmStochasticRun} for this walk.
|
|
3107
3012
|
*/
|
|
3108
3013
|
private _stochastic_one_walk;
|
|
3109
|
-
/**
|
|
3014
|
+
/**
|
|
3015
|
+
* Lazily yield one {@link JssmStochasticRun} at a time.
|
|
3110
3016
|
*
|
|
3111
3017
|
* In `montecarlo` mode (default) yields `runs` independent walks from the
|
|
3112
3018
|
* current state, each ending at a terminal or after `max_steps`. In
|
|
@@ -3117,16 +3023,16 @@ declare class Machine<mDT> {
|
|
|
3117
3023
|
* Passing `seed` reseeds the machine for reproducible runs. Unlike
|
|
3118
3024
|
* {@link Machine.stochastic_summary}, the generator does NOT restore the
|
|
3119
3025
|
* prior seed afterward — a direct caller's machine is left reseeded.
|
|
3120
|
-
*
|
|
3121
3026
|
* @param opts - {@link JssmStochasticOptions}.
|
|
3027
|
+
* @yields One {@link JssmStochasticRun} per completed walk.
|
|
3122
3028
|
* @returns A generator of per-run results.
|
|
3123
|
-
*
|
|
3124
3029
|
* @example
|
|
3125
3030
|
* const m = sm`a 'go' -> b 'go' -> c;`;
|
|
3126
3031
|
* [...m.stochastic_runs({ runs: 2, seed: 1 })].length; // => 2
|
|
3127
3032
|
*/
|
|
3128
3033
|
stochastic_runs(opts?: JssmStochasticOptions): Generator<JssmStochasticRun>;
|
|
3129
|
-
/**
|
|
3034
|
+
/**
|
|
3035
|
+
* Run many weighted-random walks and return aggregate statistics.
|
|
3130
3036
|
*
|
|
3131
3037
|
* Honors `%` transition probabilities (via the existing probabilistic
|
|
3132
3038
|
* machinery). Non-destructive: the machine's current state and
|
|
@@ -3137,16 +3043,13 @@ declare class Machine<mDT> {
|
|
|
3137
3043
|
*
|
|
3138
3044
|
* Timing (`after`) decorations and data-guard conditions are not modeled
|
|
3139
3045
|
* by this sampler; it walks the probabilistic graph topology.
|
|
3140
|
-
*
|
|
3141
3046
|
* @param opts - {@link JssmStochasticOptions}. `runs` defaults to the
|
|
3142
3047
|
* machine's declared `editor: { stochastic_run_count }` (fsl#1334) when
|
|
3143
3048
|
* present, otherwise {@link STOCHASTIC_DEFAULT_RUNS}.
|
|
3144
3049
|
* @returns A {@link JssmStochasticSummary}.
|
|
3145
|
-
*
|
|
3146
3050
|
* @see Machine.stochastic_runs
|
|
3147
3051
|
* @see Machine.probabilistic_walk
|
|
3148
3052
|
* @see Machine.editor_config
|
|
3149
|
-
*
|
|
3150
3053
|
* @example
|
|
3151
3054
|
* const m = sm`a 'go' -> b 'go' -> c;`;
|
|
3152
3055
|
* const s = m.stochastic_summary({ runs: 100, seed: 1 });
|
|
@@ -3214,17 +3117,16 @@ declare class Machine<mDT> {
|
|
|
3214
3117
|
*
|
|
3215
3118
|
*/
|
|
3216
3119
|
list_states_having_action(whichState: StateType): Array<StateType>;
|
|
3217
|
-
/**
|
|
3120
|
+
/**
|
|
3121
|
+
* List all action names available as exits from a given state.
|
|
3218
3122
|
*
|
|
3219
3123
|
* Returns the empty array (does not throw) when `whichState` exists but has
|
|
3220
3124
|
* no action-named exits — including terminal states, states whose only
|
|
3221
3125
|
* exits are plain `->` transitions, and states in machines that use no
|
|
3222
3126
|
* actions at all. Only nonexistent states cause a throw.
|
|
3223
|
-
*
|
|
3224
3127
|
* @param whichState - The state to inspect. Defaults to the current state.
|
|
3225
3128
|
* @returns An array of action name strings, possibly empty.
|
|
3226
3129
|
* @throws {JssmError} If the state does not exist.
|
|
3227
|
-
*
|
|
3228
3130
|
* @example
|
|
3229
3131
|
* const m = sm`a 'go' -> b; b -> c;`;
|
|
3230
3132
|
* m.list_exit_actions('a'); // => ['go']
|
|
@@ -3233,33 +3135,39 @@ declare class Machine<mDT> {
|
|
|
3233
3135
|
* expect(() => m.list_exit_actions('z')).toThrow();
|
|
3234
3136
|
*/
|
|
3235
3137
|
list_exit_actions(whichState?: StateType): Array<StateType>;
|
|
3236
|
-
/**
|
|
3138
|
+
/**
|
|
3139
|
+
* List all action exits from a state with their probabilities.
|
|
3237
3140
|
* @param whichState - The state to inspect. Defaults to the current state.
|
|
3238
3141
|
* @returns An array of `{ action, probability }` objects.
|
|
3239
3142
|
* @throws {JssmError} If the state does not exist.
|
|
3240
3143
|
*/
|
|
3241
3144
|
probable_action_exits(whichState?: StateType): Array<any>;
|
|
3242
|
-
/**
|
|
3145
|
+
/**
|
|
3146
|
+
* Check whether a state has no incoming transitions (unreachable after start).
|
|
3243
3147
|
* @param whichState - The state to check.
|
|
3244
3148
|
* @returns `true` if the state has zero entrances.
|
|
3245
3149
|
* @throws {JssmError} If the state does not exist.
|
|
3246
3150
|
*/
|
|
3247
3151
|
is_unenterable(whichState: StateType): boolean;
|
|
3248
|
-
/**
|
|
3152
|
+
/**
|
|
3153
|
+
* Check whether any state in the machine is unenterable.
|
|
3249
3154
|
* @returns `true` if at least one state has no incoming transitions.
|
|
3250
3155
|
*/
|
|
3251
3156
|
has_unenterables(): boolean;
|
|
3252
|
-
/**
|
|
3157
|
+
/**
|
|
3158
|
+
* Check whether the current state is terminal (has no exits).
|
|
3253
3159
|
* @returns `true` if the current state has zero exits.
|
|
3254
3160
|
*/
|
|
3255
3161
|
is_terminal(): boolean;
|
|
3256
|
-
/**
|
|
3162
|
+
/**
|
|
3163
|
+
* Check whether a specific state is terminal (has no exits).
|
|
3257
3164
|
* @param whichState - The state to check.
|
|
3258
3165
|
* @returns `true` if the state has zero exits.
|
|
3259
3166
|
* @throws {JssmError} If the state does not exist.
|
|
3260
3167
|
*/
|
|
3261
3168
|
state_is_terminal(whichState: StateType): boolean;
|
|
3262
|
-
/**
|
|
3169
|
+
/**
|
|
3170
|
+
* Check whether any state in the machine is terminal.
|
|
3263
3171
|
* @returns `true` if at least one state has no exits.
|
|
3264
3172
|
*/
|
|
3265
3173
|
has_terminals(): boolean;
|
|
@@ -3371,17 +3279,20 @@ declare class Machine<mDT> {
|
|
|
3371
3279
|
*
|
|
3372
3280
|
*/
|
|
3373
3281
|
statesIn(groupName: string): Array<StateType>;
|
|
3374
|
-
/**
|
|
3282
|
+
/**
|
|
3283
|
+
* Check whether the current state is complete (every exit has an action).
|
|
3375
3284
|
* @returns `true` if the current state is complete.
|
|
3376
3285
|
*/
|
|
3377
3286
|
is_complete(): boolean;
|
|
3378
|
-
/**
|
|
3287
|
+
/**
|
|
3288
|
+
* Check whether a specific state is complete (every exit has an action).
|
|
3379
3289
|
* @param whichState - The state to check.
|
|
3380
3290
|
* @returns `true` if the state is complete.
|
|
3381
3291
|
* @throws {JssmError} If the state does not exist.
|
|
3382
3292
|
*/
|
|
3383
3293
|
state_is_complete(whichState: StateType): boolean;
|
|
3384
|
-
/**
|
|
3294
|
+
/**
|
|
3295
|
+
* Check whether any state in the machine is complete.
|
|
3385
3296
|
* @returns `true` if at least one state is complete.
|
|
3386
3297
|
*/
|
|
3387
3298
|
has_completes(): boolean;
|
|
@@ -3405,14 +3316,12 @@ declare class Machine<mDT> {
|
|
|
3405
3316
|
* const off = m.on('transition', () => {});
|
|
3406
3317
|
* off(); // unsubscribe
|
|
3407
3318
|
* ```
|
|
3408
|
-
*
|
|
3409
|
-
* @typeParam Ev The event name (drives the detail type).
|
|
3319
|
+
* @template Ev The event name (drives the detail type).
|
|
3410
3320
|
* @param name The event name to subscribe to.
|
|
3411
3321
|
* @param handler The handler invoked on each matching delivery. The
|
|
3412
3322
|
* three-argument `(name, filter, handler)` form inserts a
|
|
3413
3323
|
* filter object before the handler (see the example above).
|
|
3414
3324
|
* @returns A function that unsubscribes when called.
|
|
3415
|
-
*
|
|
3416
3325
|
* @see Machine.off
|
|
3417
3326
|
* @see Machine.once
|
|
3418
3327
|
*/
|
|
@@ -3426,15 +3335,13 @@ declare class Machine<mDT> {
|
|
|
3426
3335
|
* ```typescript
|
|
3427
3336
|
* m.once('terminal', e => console.log(`done at ${e.state}`));
|
|
3428
3337
|
* ```
|
|
3429
|
-
*
|
|
3430
|
-
* @typeParam Ev The event name.
|
|
3338
|
+
* @template Ev The event name.
|
|
3431
3339
|
* @param name The event name.
|
|
3432
3340
|
* @param handler The handler invoked on the first matching delivery. The
|
|
3433
3341
|
* three-argument `(name, filter, handler)` form inserts a
|
|
3434
3342
|
* filter object before the handler (same shapes as `on`).
|
|
3435
3343
|
* @returns A function that unsubscribes early if called before the
|
|
3436
3344
|
* handler has fired.
|
|
3437
|
-
*
|
|
3438
3345
|
* @see Machine.on
|
|
3439
3346
|
* @see Machine.off
|
|
3440
3347
|
*/
|
|
@@ -3452,112 +3359,11 @@ declare class Machine<mDT> {
|
|
|
3452
3359
|
* m.off('transition', fn); // true
|
|
3453
3360
|
* m.off('transition', fn); // false
|
|
3454
3361
|
* ```
|
|
3455
|
-
*
|
|
3456
3362
|
* @param name The event name.
|
|
3457
3363
|
* @param handler The handler reference to remove.
|
|
3458
3364
|
* @returns `true` if removed, `false` if no match was registered.
|
|
3459
3365
|
*/
|
|
3460
3366
|
off<Ev extends JssmEventName>(name: Ev, handler: JssmEventHandler<mDT, Ev>): boolean;
|
|
3461
|
-
/**
|
|
3462
|
-
* Remove one event-subscription entry from its set and keep
|
|
3463
|
-
* {@link Machine._event_listener_count} in sync. The count is decremented
|
|
3464
|
-
* only when the entry was actually present, so calling a stale unsubscribe
|
|
3465
|
-
* closure (or removing an already-fired `once` entry) is idempotent and
|
|
3466
|
-
* cannot drive the count negative.
|
|
3467
|
-
*
|
|
3468
|
-
* @param set The per-event-name subscription set.
|
|
3469
|
-
* @param entry The entry to remove.
|
|
3470
|
-
* @internal
|
|
3471
|
-
*/
|
|
3472
|
-
_unsubscribe_entry(set: Set<JssmEventEntry<any, any>>, entry: JssmEventEntry<any, any>): void;
|
|
3473
|
-
/**
|
|
3474
|
-
* Shared registration core used by {@link Machine.on} and
|
|
3475
|
-
* {@link Machine.once}. Normalizes the optional filter argument and
|
|
3476
|
-
* installs the entry into the per-event subscription set.
|
|
3477
|
-
*
|
|
3478
|
-
* @internal
|
|
3479
|
-
*/
|
|
3480
|
-
_subscribe<Ev extends JssmEventName>(name: Ev, filterOrFn: JssmEventFilter<mDT, Ev> | JssmEventHandler<mDT, Ev>, maybeFn: JssmEventHandler<mDT, Ev> | undefined, once: boolean): JssmUnsubscribe;
|
|
3481
|
-
/**
|
|
3482
|
-
* Invoke a single event-handler entry, respecting its filter, once-removal
|
|
3483
|
-
* semantics, and the error re-fire / recursion-guard logic. Extracted so
|
|
3484
|
-
* {@link _fire} can share identical behavior between the size-1 fast-path
|
|
3485
|
-
* and the general snapshotted loop.
|
|
3486
|
-
*
|
|
3487
|
-
* @param entry - The subscriber descriptor to invoke.
|
|
3488
|
-
* @param set - The live Set that owns `entry`; needed for once-removal.
|
|
3489
|
-
* @param name - The event name being dispatched (used in error re-fires).
|
|
3490
|
-
* @param detail - The event payload forwarded to the handler.
|
|
3491
|
-
*
|
|
3492
|
-
* @internal
|
|
3493
|
-
*/
|
|
3494
|
-
_fire_one<Ev extends JssmEventName>(entry: JssmEventEntry<mDT, Ev>, set: Set<JssmEventEntry<any, any>>, name: Ev, detail: JssmEventDetailMap<mDT>[Ev]): void;
|
|
3495
|
-
/**
|
|
3496
|
-
* Dispatch an event to every registered subscriber in registration
|
|
3497
|
-
* order. Filters are checked first; non-matching handlers are skipped
|
|
3498
|
-
* without invoking the handler. Exceptions thrown by a handler are
|
|
3499
|
-
* caught and re-emitted as an `error` event so subsequent handlers
|
|
3500
|
-
* still run.
|
|
3501
|
-
*
|
|
3502
|
-
* Re-entry into the `error` event itself is guarded — if an `error`
|
|
3503
|
-
* handler throws, the new exception is swallowed rather than rebroadcast
|
|
3504
|
-
* to avoid an infinite loop.
|
|
3505
|
-
*
|
|
3506
|
-
* When exactly one subscriber is registered the common case avoids the
|
|
3507
|
-
* `Array.from(set)` snapshot allocation by capturing the lone entry into a
|
|
3508
|
-
* local first — equivalent to a 1-element snapshot but allocation-free.
|
|
3509
|
-
* The general path still snapshots for re-entrancy safety.
|
|
3510
|
-
*
|
|
3511
|
-
* @internal
|
|
3512
|
-
*/
|
|
3513
|
-
/**
|
|
3514
|
-
* Whether at least one live subscriber is registered for `name`. Used by
|
|
3515
|
-
* the transition-commit observation block to skip building a detail
|
|
3516
|
-
* literal that {@link Machine._fire} would immediately discard — a panel
|
|
3517
|
-
* listening only to `'transition'` (fsl-bind, fsl-viz, fsl-info-panel)
|
|
3518
|
-
* previously paid for the exit/entry/data-change detail allocations on
|
|
3519
|
-
* every transition. Read at fire time, so a listener installed by a
|
|
3520
|
-
* pre-hook is still seen (#671).
|
|
3521
|
-
*
|
|
3522
|
-
* @param name The event name to probe.
|
|
3523
|
-
* @returns `true` when a subsequent `_fire(name, ...)` would reach at
|
|
3524
|
-
* least one handler.
|
|
3525
|
-
*
|
|
3526
|
-
* ```typescript
|
|
3527
|
-
* machine.on('transition', () => {});
|
|
3528
|
-
* machine._has_subscribers('transition'); // true
|
|
3529
|
-
* machine._has_subscribers('exit'); // false
|
|
3530
|
-
* ```
|
|
3531
|
-
*
|
|
3532
|
-
* @see Machine._fire
|
|
3533
|
-
* @internal
|
|
3534
|
-
*/
|
|
3535
|
-
_has_subscribers(name: JssmEventName): boolean;
|
|
3536
|
-
_fire<Ev extends JssmEventName>(name: Ev, detail: JssmEventDetailMap<mDT>[Ev]): void;
|
|
3537
|
-
/** Low-level hook registration. Installs a handler described by a
|
|
3538
|
-
* {@link HookDescription} into the appropriate internal map. Prefer the
|
|
3539
|
-
* convenience wrappers ({@link hook}, {@link hook_entry}, etc.) over
|
|
3540
|
-
* calling this directly.
|
|
3541
|
-
* @param HookDesc - A hook descriptor specifying kind, states, and handler.
|
|
3542
|
-
*/
|
|
3543
|
-
/**
|
|
3544
|
-
* Validate a {@link HookDescription} before registration. Every hook needs
|
|
3545
|
-
* a `handler` function, and each kind's identifying spatial fields
|
|
3546
|
-
* (`from`/`to`/`action`) must be exactly those `set_hook` reads for that
|
|
3547
|
-
* kind — present when required, absent otherwise. This turns a mis-shaped
|
|
3548
|
-
* descriptor into a thrown error instead of a silently dead hook keyed on
|
|
3549
|
-
* `undefined` (e.g. an `exit` hook handed `to` instead of `from`, #734).
|
|
3550
|
-
*
|
|
3551
|
-
* @param HookDesc - The descriptor about to be registered.
|
|
3552
|
-
* @throws JssmError if the kind is unknown, the handler is not a function, a
|
|
3553
|
-
* required field is missing, or an inapplicable field is present.
|
|
3554
|
-
*
|
|
3555
|
-
* @example
|
|
3556
|
-
* const m = sm`a -> b;`;
|
|
3557
|
-
* // an exit hook is keyed by `from`, so supplying `to` is rejected:
|
|
3558
|
-
* expect(() => m.set_hook({ kind: 'exit', to: 'a', handler: () => true })).toThrow();
|
|
3559
|
-
*/
|
|
3560
|
-
_validate_hook_description(HookDesc: HookDescription<mDT>): void;
|
|
3561
3367
|
set_hook(HookDesc: HookDescription<mDT>): void;
|
|
3562
3368
|
/**
|
|
3563
3369
|
* Remove a previously-registered hook described by a
|
|
@@ -3576,12 +3382,12 @@ declare class Machine<mDT> {
|
|
|
3576
3382
|
* m.set_hook({ kind: 'hook', from: 'a', to: 'b', handler: fn });
|
|
3577
3383
|
* m.remove_hook({ kind: 'hook', from: 'a', to: 'b', handler: fn });
|
|
3578
3384
|
* ```
|
|
3579
|
-
*
|
|
3580
3385
|
* @param HookDesc - A hook descriptor identifying the hook to remove.
|
|
3581
3386
|
* @returns `true` if a hook was removed, `false` otherwise.
|
|
3582
3387
|
*/
|
|
3583
3388
|
remove_hook(HookDesc: HookDescription<mDT>): boolean;
|
|
3584
|
-
/**
|
|
3389
|
+
/**
|
|
3390
|
+
* Register a pre-transition hook on a specific edge. Fires before
|
|
3585
3391
|
* transitioning from `from` to `to`. If the handler returns `false`, the
|
|
3586
3392
|
* transition is blocked.
|
|
3587
3393
|
*
|
|
@@ -3589,14 +3395,14 @@ declare class Machine<mDT> {
|
|
|
3589
3395
|
* const m = sm`a -> b -> c;`;
|
|
3590
3396
|
* m.hook('a', 'b', () => console.log('a->b'));
|
|
3591
3397
|
* ```
|
|
3592
|
-
*
|
|
3593
3398
|
* @param from - Source state name.
|
|
3594
3399
|
* @param to - Target state name.
|
|
3595
3400
|
* @param handler - Callback invoked before the transition.
|
|
3596
3401
|
* @returns `this` for chaining.
|
|
3597
3402
|
*/
|
|
3598
3403
|
hook(from: string, to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
3599
|
-
/**
|
|
3404
|
+
/**
|
|
3405
|
+
* Register a pre-transition hook on a specific action-labeled edge.
|
|
3600
3406
|
* @param from - Source state name.
|
|
3601
3407
|
* @param to - Target state name.
|
|
3602
3408
|
* @param action - The action label that triggers this hook.
|
|
@@ -3604,50 +3410,59 @@ declare class Machine<mDT> {
|
|
|
3604
3410
|
* @returns `this` for chaining.
|
|
3605
3411
|
*/
|
|
3606
3412
|
hook_action(from: string, to: string, action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
3607
|
-
/**
|
|
3413
|
+
/**
|
|
3414
|
+
* Register a pre-transition hook on any edge triggered by a specific action.
|
|
3608
3415
|
* @param action - The action name to hook.
|
|
3609
3416
|
* @param handler - Callback invoked before any transition with this action.
|
|
3610
3417
|
* @returns `this` for chaining.
|
|
3611
3418
|
*/
|
|
3612
3419
|
hook_global_action(action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
3613
|
-
/**
|
|
3420
|
+
/**
|
|
3421
|
+
* Register a pre-transition hook on any action-driven transition.
|
|
3614
3422
|
* @param handler - Callback invoked before any action transition.
|
|
3615
3423
|
* @returns `this` for chaining.
|
|
3616
3424
|
*/
|
|
3617
3425
|
hook_any_action(handler: HookHandler<mDT>): Machine<mDT>;
|
|
3618
|
-
/**
|
|
3426
|
+
/**
|
|
3427
|
+
* Register a pre-transition hook on any standard (`->`) transition.
|
|
3619
3428
|
* @param handler - Callback invoked before any legal transition.
|
|
3620
3429
|
* @returns `this` for chaining.
|
|
3621
3430
|
*/
|
|
3622
3431
|
hook_standard_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
3623
|
-
/**
|
|
3432
|
+
/**
|
|
3433
|
+
* Register a pre-transition hook on any main-path (`=>`) transition.
|
|
3624
3434
|
* @param handler - Callback invoked before any main transition.
|
|
3625
3435
|
* @returns `this` for chaining.
|
|
3626
3436
|
*/
|
|
3627
3437
|
hook_main_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
3628
|
-
/**
|
|
3438
|
+
/**
|
|
3439
|
+
* Register a pre-transition hook on any forced (`~>`) transition.
|
|
3629
3440
|
* @param handler - Callback invoked before any forced transition.
|
|
3630
3441
|
* @returns `this` for chaining.
|
|
3631
3442
|
*/
|
|
3632
3443
|
hook_forced_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
3633
|
-
/**
|
|
3444
|
+
/**
|
|
3445
|
+
* Register a pre-transition hook on any transition regardless of kind.
|
|
3634
3446
|
* @param handler - Callback invoked before every transition.
|
|
3635
3447
|
* @returns `this` for chaining.
|
|
3636
3448
|
*/
|
|
3637
3449
|
hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
3638
|
-
/**
|
|
3450
|
+
/**
|
|
3451
|
+
* Register a hook that fires when entering a specific state.
|
|
3639
3452
|
* @param to - The state being entered.
|
|
3640
3453
|
* @param handler - Callback invoked on entry.
|
|
3641
3454
|
* @returns `this` for chaining.
|
|
3642
3455
|
*/
|
|
3643
3456
|
hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
3644
|
-
/**
|
|
3457
|
+
/**
|
|
3458
|
+
* Register a hook that fires when leaving a specific state.
|
|
3645
3459
|
* @param from - The state being exited.
|
|
3646
3460
|
* @param handler - Callback invoked on exit.
|
|
3647
3461
|
* @returns `this` for chaining.
|
|
3648
3462
|
*/
|
|
3649
3463
|
hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
3650
|
-
/**
|
|
3464
|
+
/**
|
|
3465
|
+
* Register a hook that fires when a state's `after` timer elapses — the
|
|
3651
3466
|
* delay-over companion to `a after 5s -> b;` style time transitions. It
|
|
3652
3467
|
* does NOT fire when the state is entered or left by ordinary dispatch;
|
|
3653
3468
|
* use {@link hook_entry} / {@link hook_exit} for those. (Versions through
|
|
@@ -3658,7 +3473,6 @@ declare class Machine<mDT> {
|
|
|
3658
3473
|
* timed transition is taken; informational — its outcome
|
|
3659
3474
|
* cannot reject the transition.
|
|
3660
3475
|
* @returns `this` for chaining.
|
|
3661
|
-
*
|
|
3662
3476
|
* @example
|
|
3663
3477
|
* const m = sm`a after 1000 -> b; a -> c; c -> a;`;
|
|
3664
3478
|
* let calls = 0;
|
|
@@ -3668,13 +3482,13 @@ declare class Machine<mDT> {
|
|
|
3668
3482
|
* // ordinary dispatch never fires it; only the timer elapsing does:
|
|
3669
3483
|
* calls; // => 0
|
|
3670
3484
|
* m.clear_state_timeout();
|
|
3671
|
-
*
|
|
3672
3485
|
* @see hook_entry
|
|
3673
3486
|
* @see hook_exit
|
|
3674
3487
|
* @see set_state_timeout
|
|
3675
3488
|
*/
|
|
3676
3489
|
hook_after(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
3677
|
-
/**
|
|
3490
|
+
/**
|
|
3491
|
+
* Register a hook that fires when ANY state's `after` timer elapses — the
|
|
3678
3492
|
* whole-machine companion to {@link hook_after}, mirroring how
|
|
3679
3493
|
* {@link hook_any_transition} companions {@link hook}. When the elapsing
|
|
3680
3494
|
* state also has a specific {@link hook_after}, the specific hook fires
|
|
@@ -3685,7 +3499,6 @@ declare class Machine<mDT> {
|
|
|
3685
3499
|
* @param handler - Callback invoked whenever any `after` timer fires, just
|
|
3686
3500
|
* before the timed transition is taken.
|
|
3687
3501
|
* @returns `this` for chaining.
|
|
3688
|
-
*
|
|
3689
3502
|
* @example
|
|
3690
3503
|
* const m = sm`a after 1000 -> b; a -> c; c -> a;`;
|
|
3691
3504
|
* let calls = 0;
|
|
@@ -3695,13 +3508,13 @@ declare class Machine<mDT> {
|
|
|
3695
3508
|
* // ordinary dispatch never fires it; only a timer elapsing does:
|
|
3696
3509
|
* calls; // => 0
|
|
3697
3510
|
* m.clear_state_timeout();
|
|
3698
|
-
*
|
|
3699
3511
|
* @see hook_after
|
|
3700
3512
|
* @see hook_any_transition
|
|
3701
3513
|
* @see set_state_timeout
|
|
3702
3514
|
*/
|
|
3703
3515
|
hook_after_any(handler: HookHandler<mDT>): Machine<mDT>;
|
|
3704
|
-
/**
|
|
3516
|
+
/**
|
|
3517
|
+
* Post-transition hook on a specific edge. Fires after the transition
|
|
3705
3518
|
* from `from` to `to` has completed. Cannot block the transition.
|
|
3706
3519
|
* @param from - Source state name.
|
|
3707
3520
|
* @param to - Target state name.
|
|
@@ -3709,7 +3522,8 @@ declare class Machine<mDT> {
|
|
|
3709
3522
|
* @returns `this` for chaining.
|
|
3710
3523
|
*/
|
|
3711
3524
|
post_hook(from: string, to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
3712
|
-
/**
|
|
3525
|
+
/**
|
|
3526
|
+
* Post-transition hook on a specific action-labeled edge.
|
|
3713
3527
|
* @param from - Source state name.
|
|
3714
3528
|
* @param to - Target state name.
|
|
3715
3529
|
* @param action - The action label.
|
|
@@ -3717,50 +3531,59 @@ declare class Machine<mDT> {
|
|
|
3717
3531
|
* @returns `this` for chaining.
|
|
3718
3532
|
*/
|
|
3719
3533
|
post_hook_action(from: string, to: string, action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
3720
|
-
/**
|
|
3534
|
+
/**
|
|
3535
|
+
* Post-transition hook on any edge triggered by a specific action.
|
|
3721
3536
|
* @param action - The action name.
|
|
3722
3537
|
* @param handler - Callback invoked after any transition with this action.
|
|
3723
3538
|
* @returns `this` for chaining.
|
|
3724
3539
|
*/
|
|
3725
3540
|
post_hook_global_action(action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
3726
|
-
/**
|
|
3541
|
+
/**
|
|
3542
|
+
* Post-transition hook on any action-driven transition.
|
|
3727
3543
|
* @param handler - Callback invoked after any action transition.
|
|
3728
3544
|
* @returns `this` for chaining.
|
|
3729
3545
|
*/
|
|
3730
3546
|
post_hook_any_action(handler: HookHandler<mDT>): Machine<mDT>;
|
|
3731
|
-
/**
|
|
3547
|
+
/**
|
|
3548
|
+
* Post-transition hook on any standard (`->`) transition.
|
|
3732
3549
|
* @param handler - Callback invoked after any legal transition.
|
|
3733
3550
|
* @returns `this` for chaining.
|
|
3734
3551
|
*/
|
|
3735
3552
|
post_hook_standard_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
3736
|
-
/**
|
|
3553
|
+
/**
|
|
3554
|
+
* Post-transition hook on any main-path (`=>`) transition.
|
|
3737
3555
|
* @param handler - Callback invoked after any main transition.
|
|
3738
3556
|
* @returns `this` for chaining.
|
|
3739
3557
|
*/
|
|
3740
3558
|
post_hook_main_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
3741
|
-
/**
|
|
3559
|
+
/**
|
|
3560
|
+
* Post-transition hook on any forced (`~>`) transition.
|
|
3742
3561
|
* @param handler - Callback invoked after any forced transition.
|
|
3743
3562
|
* @returns `this` for chaining.
|
|
3744
3563
|
*/
|
|
3745
3564
|
post_hook_forced_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
3746
|
-
/**
|
|
3565
|
+
/**
|
|
3566
|
+
* Post-transition hook on any transition regardless of kind.
|
|
3747
3567
|
* @param handler - Callback invoked after every transition.
|
|
3748
3568
|
* @returns `this` for chaining.
|
|
3749
3569
|
*/
|
|
3750
3570
|
post_hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
3751
|
-
/**
|
|
3571
|
+
/**
|
|
3572
|
+
* Post-transition hook that fires after entering a specific state.
|
|
3752
3573
|
* @param to - The state that was entered.
|
|
3753
3574
|
* @param handler - Callback invoked after entry.
|
|
3754
3575
|
* @returns `this` for chaining.
|
|
3755
3576
|
*/
|
|
3756
3577
|
post_hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
3757
|
-
/**
|
|
3578
|
+
/**
|
|
3579
|
+
* Post-transition hook that fires after leaving a specific state.
|
|
3758
3580
|
* @param from - The state that was exited.
|
|
3759
3581
|
* @param handler - Callback invoked after exit.
|
|
3760
3582
|
* @returns `this` for chaining.
|
|
3761
3583
|
*/
|
|
3762
3584
|
post_hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
3763
|
-
/**
|
|
3585
|
+
/**
|
|
3586
|
+
* Register a pre-transition hook that fires **before** all other pre-hooks
|
|
3764
3587
|
* on every transition. If the handler returns `false`, the transition is
|
|
3765
3588
|
* blocked. The handler receives an {@link EverythingHookContext} whose
|
|
3766
3589
|
* `hook_name` is `'pre everything'`.
|
|
@@ -3772,12 +3595,12 @@ declare class Machine<mDT> {
|
|
|
3772
3595
|
* return true;
|
|
3773
3596
|
* });
|
|
3774
3597
|
* ```
|
|
3775
|
-
*
|
|
3776
3598
|
* @param handler - Callback invoked before all other pre-hooks.
|
|
3777
3599
|
* @returns `this` for chaining.
|
|
3778
3600
|
*/
|
|
3779
3601
|
hook_pre_everything(handler: EverythingHookHandler<mDT>): Machine<mDT>;
|
|
3780
|
-
/**
|
|
3602
|
+
/**
|
|
3603
|
+
* Register a pre-transition hook that fires **after** all other pre-hooks
|
|
3781
3604
|
* on every transition. If the handler returns `false`, the transition is
|
|
3782
3605
|
* blocked. The handler receives an {@link EverythingHookContext} whose
|
|
3783
3606
|
* `hook_name` is `'everything'`.
|
|
@@ -3789,12 +3612,12 @@ declare class Machine<mDT> {
|
|
|
3789
3612
|
* return true;
|
|
3790
3613
|
* });
|
|
3791
3614
|
* ```
|
|
3792
|
-
*
|
|
3793
3615
|
* @param handler - Callback invoked after all other pre-hooks.
|
|
3794
3616
|
* @returns `this` for chaining.
|
|
3795
3617
|
*/
|
|
3796
3618
|
hook_everything(handler: EverythingHookHandler<mDT>): Machine<mDT>;
|
|
3797
|
-
/**
|
|
3619
|
+
/**
|
|
3620
|
+
* Register a post-transition hook that fires **after** all other
|
|
3798
3621
|
* post-hooks on every transition. Cannot block the transition. The
|
|
3799
3622
|
* handler receives an {@link EverythingHookContext} whose `hook_name` is
|
|
3800
3623
|
* `'post everything'`.
|
|
@@ -3805,12 +3628,12 @@ declare class Machine<mDT> {
|
|
|
3805
3628
|
* console.log(`${hook_name} fired`);
|
|
3806
3629
|
* });
|
|
3807
3630
|
* ```
|
|
3808
|
-
*
|
|
3809
3631
|
* @param handler - Callback invoked after all other post-hooks.
|
|
3810
3632
|
* @returns `this` for chaining.
|
|
3811
3633
|
*/
|
|
3812
3634
|
hook_post_everything(handler: PostEverythingHookHandler<mDT>): Machine<mDT>;
|
|
3813
|
-
/**
|
|
3635
|
+
/**
|
|
3636
|
+
* Register a post-transition hook that fires **before** all other
|
|
3814
3637
|
* post-hooks on every transition. Cannot block the transition. The
|
|
3815
3638
|
* handler receives an {@link EverythingHookContext} whose `hook_name` is
|
|
3816
3639
|
* `'pre post everything'`.
|
|
@@ -3821,22 +3644,24 @@ declare class Machine<mDT> {
|
|
|
3821
3644
|
* console.log(`${hook_name} fired`);
|
|
3822
3645
|
* });
|
|
3823
3646
|
* ```
|
|
3824
|
-
*
|
|
3825
3647
|
* @param handler - Callback invoked before all other post-hooks.
|
|
3826
3648
|
* @returns `this` for chaining.
|
|
3827
3649
|
*/
|
|
3828
3650
|
hook_pre_post_everything(handler: PostEverythingHookHandler<mDT>): Machine<mDT>;
|
|
3829
|
-
/**
|
|
3651
|
+
/**
|
|
3652
|
+
* Get the current RNG seed used for probabilistic transitions.
|
|
3830
3653
|
* @returns The numeric seed value.
|
|
3831
3654
|
*/
|
|
3832
3655
|
get rng_seed(): number;
|
|
3833
|
-
/**
|
|
3656
|
+
/**
|
|
3657
|
+
* Set the RNG seed. Pass `undefined` to reseed from the current time.
|
|
3834
3658
|
* Resets the internal PRNG so subsequent probabilistic operations use the
|
|
3835
3659
|
* new seed.
|
|
3836
3660
|
* @param to - The seed value, or `undefined` for time-based seeding.
|
|
3837
3661
|
*/
|
|
3838
3662
|
set rng_seed(to: number | undefined);
|
|
3839
|
-
/**
|
|
3663
|
+
/**
|
|
3664
|
+
* Get all edges between two states (there can be multiple with
|
|
3840
3665
|
* different actions).
|
|
3841
3666
|
* @param from - Source state name.
|
|
3842
3667
|
* @param to - Target state name.
|
|
@@ -3878,82 +3703,7 @@ declare class Machine<mDT> {
|
|
|
3878
3703
|
* @see set_data
|
|
3879
3704
|
*
|
|
3880
3705
|
*/
|
|
3881
|
-
override(newState: StateType, newData?: mDT
|
|
3882
|
-
/*********
|
|
3883
|
-
*
|
|
3884
|
-
* Fire a `'rejection'` event caused by a hook vetoing a pending transition.
|
|
3885
|
-
* Extracted from the per-call closures inside {@link transition_impl} so
|
|
3886
|
-
* that it is allocated once at class-definition time rather than on every
|
|
3887
|
-
* hooked transition.
|
|
3888
|
-
*
|
|
3889
|
-
* @param hook_name Name of the hook that rejected (e.g. `'exit'`).
|
|
3890
|
-
* @param fromState State the machine was in when the transition was
|
|
3891
|
-
* attempted; used as the `from` field of the rejection event.
|
|
3892
|
-
* @param newState State that would have been entered had the hook
|
|
3893
|
-
* passed; used as the `to` field of the rejection event.
|
|
3894
|
-
* @param fromAction Action name when the transition was initiated by an
|
|
3895
|
-
* action call; `undefined` for plain state transitions.
|
|
3896
|
-
* @param oldData Machine data at the moment the transition was
|
|
3897
|
-
* attempted, before any hook mutations.
|
|
3898
|
-
* @param newData The `next_data` value passed to the transition call.
|
|
3899
|
-
* @param wasForced Whether the transition was attempted via
|
|
3900
|
-
* `force_transition`.
|
|
3901
|
-
*
|
|
3902
|
-
* @see transition_impl
|
|
3903
|
-
* @see _fire
|
|
3904
|
-
*
|
|
3905
|
-
* @internal
|
|
3906
|
-
*
|
|
3907
|
-
*/
|
|
3908
|
-
_fire_hook_rejection(hook_name: string, fromState: StateType, newState: StateType, fromAction: StateType | undefined, oldData: mDT, newData: mDT | undefined, wasForced: boolean): void;
|
|
3909
|
-
/*********
|
|
3910
|
-
*
|
|
3911
|
-
* Fire the FSL boundary-hook actions for a single, already-committed state
|
|
3912
|
-
* change. In FSL, `do` is a synonym for `action`, so `on enter &g do 'X';`
|
|
3913
|
-
* means "when the machine crosses INTO group `g`, dispatch machine action
|
|
3914
|
-
* `X`" — and likewise `on exit` / plain-state subjects. This is the runtime
|
|
3915
|
-
* that fires those parked hooks.
|
|
3916
|
-
*
|
|
3917
|
-
* Crossing semantics (statechart convention — exits before enters):
|
|
3918
|
-
*
|
|
3919
|
-
* 1. `prev_groups` / `next_groups` are the deep (transitive) group sets of
|
|
3920
|
-
* the old and new states, from `_state_to_groups`.
|
|
3921
|
-
* 2. **Exits** fire first: every group in `prev_groups \ next_groups` with an
|
|
3922
|
-
* `onExit`, plus the plain `prev_state`'s `onExit` (when the state name
|
|
3923
|
-
* actually changed).
|
|
3924
|
-
* 3. **Enters** fire next: every group in `next_groups \ prev_groups` with an
|
|
3925
|
-
* `onEnter`, plus the plain `next_state`'s `onEnter` (when the state name
|
|
3926
|
-
* changed).
|
|
3927
|
-
* 4. A group present in BOTH sets is a transition *within* that group and
|
|
3928
|
-
* fires neither of its boundary hooks. `prev_state === next_state` fires
|
|
3929
|
-
* nothing at all.
|
|
3930
|
-
* 5. "Fire its action" is `this.action(label)`. If that action is not valid
|
|
3931
|
-
* from the current state, `action` is a safe no-op (returns `false`) — an
|
|
3932
|
-
* inapplicable boundary action never throws.
|
|
3933
|
-
* 6. Multi-membership and nesting both fan out naturally: a state in groups
|
|
3934
|
-
* A and B fires both; crossing an inner and an outer boundary fires both
|
|
3935
|
-
* levels.
|
|
3936
|
-
*
|
|
3937
|
-
* Because firing an action can drive a further transition (which crosses
|
|
3938
|
-
* more boundaries, which fires more actions), this is a bounded
|
|
3939
|
-
* run-to-completion: `_boundary_depth` tracks the live cascade depth and a
|
|
3940
|
-
* cascade deeper than `_boundary_depth_limit` throws a {@link JssmError}
|
|
3941
|
-
* rather than overflowing the stack or hanging. The limit defaults to 100
|
|
3942
|
-
* and is configurable via the `boundary_depth_limit` constructor option.
|
|
3943
|
-
*
|
|
3944
|
-
* @param prev_state The state the machine was in before this commit.
|
|
3945
|
-
* @param next_state The state the machine is in now (already committed).
|
|
3946
|
-
*
|
|
3947
|
-
* @throws {JssmError} If cascaded boundary firing exceeds `_boundary_depth_limit`
|
|
3948
|
-
* (a probable infinite loop).
|
|
3949
|
-
*
|
|
3950
|
-
* @see action
|
|
3951
|
-
* @see transition_impl
|
|
3952
|
-
*
|
|
3953
|
-
* @internal
|
|
3954
|
-
*
|
|
3955
|
-
*/
|
|
3956
|
-
_fire_boundary_actions(prev_state: StateType, next_state: StateType): void;
|
|
3706
|
+
override(newState: StateType, newData?: mDT): void;
|
|
3957
3707
|
/*********
|
|
3958
3708
|
*
|
|
3959
3709
|
* Shared transition core used by {@link transition}, {@link force_transition},
|
|
@@ -4005,7 +3755,8 @@ declare class Machine<mDT> {
|
|
|
4005
3755
|
*
|
|
4006
3756
|
*/
|
|
4007
3757
|
transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean, dataProvided?: boolean): boolean;
|
|
4008
|
-
/**
|
|
3758
|
+
/**
|
|
3759
|
+
* If the current state has an `after` timeout configured, schedule it.
|
|
4009
3760
|
* Called internally after each transition.
|
|
4010
3761
|
*/
|
|
4011
3762
|
auto_set_state_timeout(): void;
|
|
@@ -4416,94 +4167,6 @@ declare class Machine<mDT> {
|
|
|
4416
4167
|
*
|
|
4417
4168
|
*/
|
|
4418
4169
|
state_has_hooks(state: StateType): boolean;
|
|
4419
|
-
/********
|
|
4420
|
-
*
|
|
4421
|
-
* Returns the list of resolved theme implementations for this machine, in
|
|
4422
|
-
* the order they should layer (outer/base-most first). Each declared theme
|
|
4423
|
-
* name is mapped through {@link theme_mapping}; unknown names are skipped.
|
|
4424
|
-
*
|
|
4425
|
-
* The list is reversed relative to declaration order to match the historical
|
|
4426
|
-
* layering of {@link style_for}: a later-declared theme layers under an
|
|
4427
|
-
* earlier-declared one.
|
|
4428
|
-
*
|
|
4429
|
-
* @returns The resolved {@link JssmBaseTheme} stack, base-most first.
|
|
4430
|
-
*
|
|
4431
|
-
* @internal
|
|
4432
|
-
*
|
|
4433
|
-
*/
|
|
4434
|
-
_resolved_themes(): JssmBaseTheme[];
|
|
4435
|
-
/********
|
|
4436
|
-
*
|
|
4437
|
-
* Reads the condensed per-state style fields (`color`, `shape`, …) out of a
|
|
4438
|
-
* state's declaration into a fresh {@link JssmStateConfig} — the tier-5
|
|
4439
|
-
* "`state foo : { … }`" contribution of the config cascade. A state with no
|
|
4440
|
-
* declaration yields an all-`undefined` config (which contributes nothing
|
|
4441
|
-
* once folded with `merge_state_config`).
|
|
4442
|
-
*
|
|
4443
|
-
* @param state The state whose per-state declared style is wanted.
|
|
4444
|
-
*
|
|
4445
|
-
* @returns The per-state style config (fields may be `undefined`).
|
|
4446
|
-
*
|
|
4447
|
-
* @internal
|
|
4448
|
-
*
|
|
4449
|
-
*/
|
|
4450
|
-
_individual_state_config(state: StateType): JssmStateConfig;
|
|
4451
|
-
/********
|
|
4452
|
-
*
|
|
4453
|
-
* Orders the groups a state belongs to by nesting depth for the config
|
|
4454
|
-
* cascade — outermost first, innermost last — so that, folded in order,
|
|
4455
|
-
* the innermost (nearest / smallest {@link membership_distance}) group's
|
|
4456
|
-
* metadata wins. Equal-distance groups are ordered by group declaration
|
|
4457
|
-
* order, so a later-declared group of the same depth wins the tie.
|
|
4458
|
-
*
|
|
4459
|
-
* Concretely: groups are sorted by descending membership distance (largest
|
|
4460
|
-
* distance applied first / wins least), and for equal distances by
|
|
4461
|
-
* ascending declaration index (later index applied last / wins most).
|
|
4462
|
-
*
|
|
4463
|
-
* @param state The state whose containing groups are being ordered.
|
|
4464
|
-
*
|
|
4465
|
-
* @returns The containing group names, ordered for outer→inner folding
|
|
4466
|
-
* (the last entry wins).
|
|
4467
|
-
*
|
|
4468
|
-
* @internal
|
|
4469
|
-
*
|
|
4470
|
-
*/
|
|
4471
|
-
_groups_by_depth(state: StateType): string[];
|
|
4472
|
-
/********
|
|
4473
|
-
*
|
|
4474
|
-
* Folds the static tiers 1–5 of the unified config cascade for a state, plus
|
|
4475
|
-
* — when `active` is set — the active-state THEME layers, which historically
|
|
4476
|
-
* sit just below the per-state config so that a `state foo : { … }` block
|
|
4477
|
-
* still overrides a theme's `active` styling. The user `active_state : { … }`
|
|
4478
|
-
* overlay (tier 6) is NOT applied here; it is layered on top by
|
|
4479
|
-
* {@link resolve_state_config} so it wins over per-state config.
|
|
4480
|
-
*
|
|
4481
|
-
* Tiers, folded least-specific → most-specific with `merge_state_config`
|
|
4482
|
-
* (later wins, never throwing on a cross-tier key collision):
|
|
4483
|
-
*
|
|
4484
|
-
* 1. theme defaults — `base_theme.state`, then each selected theme's
|
|
4485
|
-
* `.state` block.
|
|
4486
|
-
* 2. `default_state_config` (the implicit `state : { … }` root over every
|
|
4487
|
-
* state).
|
|
4488
|
-
* 3. static per-kind defaults selected by structural kind — terminal,
|
|
4489
|
-
* then start, then end — each contributing its `base_theme.<kind>`,
|
|
4490
|
-
* selected themes' `.<kind>`, and the machine's `default_<kind>_state_config`.
|
|
4491
|
-
* When `active`, the active-state theme layers (`base_theme.active` and
|
|
4492
|
-
* each selected theme's `.active`) are folded here too.
|
|
4493
|
-
* 4. group metadata, depth-ordered outer→inner (see {@link _groups_by_depth}),
|
|
4494
|
-
* each group's RAW `{ declarations }` already condensed at construction.
|
|
4495
|
-
* 5. the per-state `state foo : { … }` config.
|
|
4496
|
-
*
|
|
4497
|
-
* @param state The state to resolve config for.
|
|
4498
|
-
* @param active Whether to include the active-state theme layers (true only
|
|
4499
|
-
* for the machine's currently-occupied state).
|
|
4500
|
-
*
|
|
4501
|
-
* @returns The composited tiers-1–5 {@link JssmStateConfig} for the state.
|
|
4502
|
-
*
|
|
4503
|
-
* @internal
|
|
4504
|
-
*
|
|
4505
|
-
*/
|
|
4506
|
-
_compose_state_config(state: StateType, active: boolean): JssmStateConfig;
|
|
4507
4170
|
/********
|
|
4508
4171
|
*
|
|
4509
4172
|
* Resolves the full unified style/config cascade for a state — the runtime
|
|
@@ -4678,76 +4341,90 @@ declare class Machine<mDT> {
|
|
|
4678
4341
|
*
|
|
4679
4342
|
*/
|
|
4680
4343
|
force_transition(newState: StateType, newData?: mDT): boolean;
|
|
4681
|
-
/**
|
|
4344
|
+
/**
|
|
4345
|
+
* Get the edge index for an action from the current state.
|
|
4682
4346
|
* Interned dispatch: resolves via the numeric (action, from) index —
|
|
4683
4347
|
* unknown action names miss without throwing.
|
|
4684
4348
|
* @param action - The action name.
|
|
4685
4349
|
* @returns The edge index, or `undefined` if the action is not available.
|
|
4686
4350
|
*/
|
|
4687
4351
|
current_action_for(action: StateType): number;
|
|
4688
|
-
/**
|
|
4352
|
+
/**
|
|
4353
|
+
* Get the full transition object for an action from the current state.
|
|
4689
4354
|
* @param action - The action name.
|
|
4690
4355
|
* @returns The {@link JssmTransition} object.
|
|
4691
4356
|
* @throws {JssmError} If the action is not available from the current state.
|
|
4692
4357
|
*/
|
|
4693
4358
|
current_action_edge_for(action: StateType): JssmTransition<StateType, mDT>;
|
|
4694
|
-
/**
|
|
4359
|
+
/**
|
|
4360
|
+
* Check whether an action is available from the current state.
|
|
4695
4361
|
* @param action - The action name to check.
|
|
4696
4362
|
* @param _newData - Reserved for future data validation.
|
|
4697
4363
|
* @returns `true` if the action can be taken.
|
|
4698
4364
|
*/
|
|
4699
4365
|
valid_action(action: StateType, _newData?: mDT): boolean;
|
|
4700
|
-
/**
|
|
4366
|
+
/**
|
|
4367
|
+
* Check whether a transition to a given state is legal (non-forced) from
|
|
4701
4368
|
* the current state.
|
|
4702
4369
|
* @param newState - The target state.
|
|
4703
4370
|
* @param _newData - Reserved for future data validation.
|
|
4704
4371
|
* @returns `true` if the transition is legal.
|
|
4705
4372
|
*/
|
|
4706
4373
|
valid_transition(newState: StateType, _newData?: mDT): boolean;
|
|
4707
|
-
/**
|
|
4374
|
+
/**
|
|
4375
|
+
* Check whether a forced transition to a given state exists from the
|
|
4708
4376
|
* current state.
|
|
4709
4377
|
* @param newState - The target state.
|
|
4710
4378
|
* @param _newData - Reserved for future data validation.
|
|
4711
4379
|
* @returns `true` if a forced (or any) transition exists.
|
|
4712
4380
|
*/
|
|
4713
4381
|
valid_force_transition(newState: StateType, _newData?: mDT): boolean;
|
|
4714
|
-
/**
|
|
4382
|
+
/**
|
|
4383
|
+
* Get the instance name of this machine, if one was assigned at creation.
|
|
4715
4384
|
* @returns The instance name string, or `undefined`.
|
|
4716
4385
|
*/
|
|
4717
4386
|
instance_name(): string | undefined;
|
|
4718
|
-
/**
|
|
4387
|
+
/**
|
|
4388
|
+
* Get the creation date of this machine as a `Date` object.
|
|
4719
4389
|
* @returns A `Date` representing when the machine was created.
|
|
4720
4390
|
*/
|
|
4721
4391
|
get creation_date(): Date;
|
|
4722
|
-
/**
|
|
4392
|
+
/**
|
|
4393
|
+
* Get the creation timestamp (milliseconds since epoch).
|
|
4723
4394
|
* @returns The timestamp as a number.
|
|
4724
4395
|
*/
|
|
4725
4396
|
get creation_timestamp(): number;
|
|
4726
|
-
/**
|
|
4397
|
+
/**
|
|
4398
|
+
* Get the timestamp when construction began (before parsing).
|
|
4727
4399
|
* @returns The start-of-construction timestamp as a number.
|
|
4728
4400
|
*/
|
|
4729
4401
|
get create_start_time(): number;
|
|
4730
|
-
/**
|
|
4402
|
+
/**
|
|
4403
|
+
* Schedule an automatic transition to `next_state` after `after_time`
|
|
4731
4404
|
* milliseconds. Only one timeout may be active at a time.
|
|
4732
4405
|
* @param next_state - The state to transition to when the timer fires.
|
|
4733
4406
|
* @param after_time - Delay in milliseconds.
|
|
4734
4407
|
* @throws {JssmError} If a timeout is already pending.
|
|
4735
4408
|
*/
|
|
4736
4409
|
set_state_timeout(next_state: StateType, after_time: number): void;
|
|
4737
|
-
/**
|
|
4410
|
+
/**
|
|
4411
|
+
Cancel any pending state timeout. Safe to call when no timeout is active.
|
|
4738
4412
|
*/
|
|
4739
4413
|
clear_state_timeout(): void;
|
|
4740
|
-
/**
|
|
4414
|
+
/**
|
|
4415
|
+
* Get the configured `after` timeout for a given state, if any.
|
|
4741
4416
|
* @param which_state - The state to look up.
|
|
4742
4417
|
* @returns A `[targetState, delayMs]` tuple, or `undefined` if no timeout
|
|
4743
4418
|
* is configured for that state.
|
|
4744
4419
|
*/
|
|
4745
4420
|
state_timeout_for(which_state: StateType): [StateType, number] | undefined;
|
|
4746
|
-
/**
|
|
4421
|
+
/**
|
|
4422
|
+
* Get the configured `after` timeout for the current state, if any.
|
|
4747
4423
|
* @returns A `[targetState, delayMs]` tuple, or `undefined`.
|
|
4748
4424
|
*/
|
|
4749
4425
|
current_state_timeout(): [StateType, number] | undefined;
|
|
4750
|
-
/**
|
|
4426
|
+
/**
|
|
4427
|
+
* Convenience method to create a new machine from a tagged template literal.
|
|
4751
4428
|
* Equivalent to calling the top-level `sm` function.
|
|
4752
4429
|
* @param template_strings - The template string array.
|
|
4753
4430
|
* @param remainder - Interpolated values.
|
|
@@ -4801,7 +4478,7 @@ declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: a
|
|
|
4801
4478
|
* @param ExtraConstructorFields Extra non-code configuration to pass at creation time
|
|
4802
4479
|
*
|
|
4803
4480
|
*/
|
|
4804
|
-
declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<StateType, mDT>>
|
|
4481
|
+
declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<StateType, mDT>>): Machine<mDT>;
|
|
4805
4482
|
/**
|
|
4806
4483
|
*
|
|
4807
4484
|
* Type guard that narrows an unknown value to a {@link HookComplexResult}.
|
|
@@ -4819,15 +4496,11 @@ declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Par
|
|
|
4819
4496
|
* is_hook_complex_result(null); // false
|
|
4820
4497
|
* is_hook_complex_result({ other: 'thing' }); // false
|
|
4821
4498
|
* ```
|
|
4822
|
-
*
|
|
4823
|
-
* @typeParam mDT The type of the machine data member; usually omitted.
|
|
4824
|
-
*
|
|
4499
|
+
* @template mDT The type of the machine data member; usually omitted.
|
|
4825
4500
|
* @param hr The value to test.
|
|
4826
|
-
*
|
|
4827
4501
|
* @returns `true` if `hr` is a non-null object with a boolean `pass` field;
|
|
4828
4502
|
* `false` otherwise. When `true`, TypeScript narrows `hr` to
|
|
4829
4503
|
* `HookComplexResult<mDT>`.
|
|
4830
|
-
*
|
|
4831
4504
|
*/
|
|
4832
4505
|
declare function is_hook_complex_result<mDT>(hr: unknown): hr is HookComplexResult<mDT>;
|
|
4833
4506
|
/**
|
|
@@ -4848,16 +4521,11 @@ declare function is_hook_complex_result<mDT>(hr: unknown): hr is HookComplexResu
|
|
|
4848
4521
|
* is_hook_rejection({ pass: true }); // false (pass)
|
|
4849
4522
|
* is_hook_rejection({ pass: false }); // true (reject)
|
|
4850
4523
|
* ```
|
|
4851
|
-
*
|
|
4852
|
-
* @typeParam mDT The type of the machine data member; usually omitted.
|
|
4853
|
-
*
|
|
4524
|
+
* @template mDT The type of the machine data member; usually omitted.
|
|
4854
4525
|
* @param hr A hook result of any legal shape.
|
|
4855
|
-
*
|
|
4856
4526
|
* @returns `true` if the hook rejected the transition; `false` if it passed.
|
|
4857
|
-
*
|
|
4858
4527
|
* @throws {TypeError} If `hr` is not a recognized hook result shape (for
|
|
4859
4528
|
* example, a number or a plain object without a `pass` field).
|
|
4860
|
-
*
|
|
4861
4529
|
*/
|
|
4862
4530
|
declare function is_hook_rejection<mDT>(hr: HookResult<mDT>): boolean;
|
|
4863
4531
|
/**
|
|
@@ -4878,24 +4546,17 @@ declare function is_hook_rejection<mDT>(hr: HookResult<mDT>): boolean;
|
|
|
4878
4546
|
* - a complex result object → returned as-is
|
|
4879
4547
|
*
|
|
4880
4548
|
* Anything else is a programmer error and throws.
|
|
4881
|
-
*
|
|
4882
|
-
* @typeParam mDT The type of the machine data member; usually omitted.
|
|
4883
|
-
*
|
|
4549
|
+
* @template mDT The type of the machine data member; usually omitted.
|
|
4884
4550
|
* @param maybe_hook The hook handler to call, or `undefined` for the
|
|
4885
4551
|
* "no hook installed" case.
|
|
4886
|
-
*
|
|
4887
4552
|
* @param hook_args The context object passed to the hook. Includes the
|
|
4888
4553
|
* current and proposed state, current and proposed data, action name, and
|
|
4889
4554
|
* transition kind.
|
|
4890
|
-
*
|
|
4891
4555
|
* @returns A {@link HookComplexResult} describing whether the hook passed
|
|
4892
4556
|
* and, optionally, any data replacements it requested.
|
|
4893
|
-
*
|
|
4894
4557
|
* @throws {TypeError} If the hook returns a value that is not one of the
|
|
4895
4558
|
* legal shapes listed above.
|
|
4896
|
-
*
|
|
4897
4559
|
* @internal
|
|
4898
|
-
*
|
|
4899
4560
|
*/
|
|
4900
4561
|
declare function abstract_hook_step<mDT>(maybe_hook: HookHandler<mDT> | undefined, hook_args: HookContext<mDT>): HookComplexResult<mDT>;
|
|
4901
4562
|
/**
|
|
@@ -4915,22 +4576,15 @@ declare function abstract_hook_step<mDT>(maybe_hook: HookHandler<mDT> | undefine
|
|
|
4915
4576
|
* - `undefined` or `true` → `{ pass: true }`
|
|
4916
4577
|
* - `false` or `null` → `{ pass: false }`
|
|
4917
4578
|
* - a complex result → returned as-is
|
|
4918
|
-
*
|
|
4919
|
-
* @typeParam mDT The type of the machine data member; usually omitted.
|
|
4920
|
-
*
|
|
4579
|
+
* @template mDT The type of the machine data member; usually omitted.
|
|
4921
4580
|
* @param maybe_hook The everything-hook handler, or `undefined` when none
|
|
4922
4581
|
* is installed.
|
|
4923
|
-
*
|
|
4924
4582
|
* @param hook_args The everything-hook context object. Differs from a
|
|
4925
4583
|
* normal hook context in that it also includes `hook_name`.
|
|
4926
|
-
*
|
|
4927
4584
|
* @returns A {@link HookComplexResult} describing whether the hook passed
|
|
4928
4585
|
* and any data replacements it requested.
|
|
4929
|
-
*
|
|
4930
4586
|
* @throws {TypeError} If the hook returns a value outside the legal shapes.
|
|
4931
|
-
*
|
|
4932
4587
|
* @internal
|
|
4933
|
-
*
|
|
4934
4588
|
*/
|
|
4935
4589
|
declare function abstract_everything_hook_step<mDT>(maybe_hook: EverythingHookHandler<mDT> | undefined, hook_args: EverythingHookContext<mDT>): HookComplexResult<mDT>;
|
|
4936
4590
|
/**
|
|
@@ -4943,32 +4597,24 @@ declare function abstract_everything_hook_step<mDT>(maybe_hook: EverythingHookHa
|
|
|
4943
4597
|
* numeric identifiers numerically and below alphanumeric ones, alphanumeric
|
|
4944
4598
|
* identifiers in ASCII order, and a shorter identifier set precedes a longer
|
|
4945
4599
|
* one that it prefixes.
|
|
4946
|
-
*
|
|
4947
4600
|
* @param {string} v1 - First version string (e.g., "5.104.2" or "6.0.0-alpha.1")
|
|
4948
4601
|
* @param {string} v2 - Second version string (e.g., "5.103.1")
|
|
4949
|
-
*
|
|
4950
4602
|
* @returns {number} - Negative if v1 < v2, 0 if equal, positive if v1 > v2
|
|
4951
|
-
*
|
|
4952
4603
|
* @example
|
|
4953
4604
|
* import { compareVersions } from 'jssm';
|
|
4954
4605
|
* compareVersions("5.104.2", "5.103.1"); // => 1
|
|
4955
|
-
*
|
|
4956
4606
|
* @example
|
|
4957
4607
|
* import { compareVersions } from 'jssm';
|
|
4958
4608
|
* compareVersions("5.104.2", "6.0.0"); // => -1
|
|
4959
|
-
*
|
|
4960
4609
|
* @example
|
|
4961
4610
|
* import { compareVersions } from 'jssm';
|
|
4962
4611
|
* compareVersions("5.104.2", "5.104.2"); // => 0
|
|
4963
|
-
*
|
|
4964
4612
|
* @example
|
|
4965
4613
|
* import { compareVersions } from 'jssm';
|
|
4966
4614
|
* compareVersions("6.0.0-alpha.1", "6.0.0"); // => -1
|
|
4967
|
-
*
|
|
4968
4615
|
* @example
|
|
4969
4616
|
* import { compareVersions } from 'jssm';
|
|
4970
4617
|
* compareVersions("6.0.0-alpha.1", "6.0.0-alpha.2"); // => -1
|
|
4971
|
-
*
|
|
4972
4618
|
* @example
|
|
4973
4619
|
* import { compareVersions } from 'jssm';
|
|
4974
4620
|
* compareVersions("6.0.0-beta.1", "6.0.0-alpha.1"); // => 1
|
|
@@ -4980,16 +4626,11 @@ declare function compareVersions(v1: string, v2: string): number;
|
|
|
4980
4626
|
* This function recreates a machine from a serialization object, restoring its
|
|
4981
4627
|
* state, data, and history. For security and compatibility reasons, it will
|
|
4982
4628
|
* refuse to deserialize data from future versions of the library.
|
|
4983
|
-
*
|
|
4984
|
-
* @typeParam mDT - The type of the machine data member
|
|
4985
|
-
*
|
|
4629
|
+
* @template mDT - The type of the machine data member
|
|
4986
4630
|
* @param {string} machine_string - The FSL string defining the machine structure
|
|
4987
4631
|
* @param {JssmSerialization<mDT>} ser - The serialization object to restore from
|
|
4988
|
-
*
|
|
4989
4632
|
* @returns {Machine<mDT>} - The restored machine instance
|
|
4990
|
-
*
|
|
4991
4633
|
* @throws {Error} If the serialization is from a future version
|
|
4992
|
-
*
|
|
4993
4634
|
* @example
|
|
4994
4635
|
* import { from, deserialize } from 'jssm';
|
|
4995
4636
|
* const machine = from("a -> b;");
|