jssm 5.162.6 → 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 +1664 -1830
- 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/dist/deno/jssm.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
type StateType = string;
|
|
2
2
|
import { JssmGenericState, JssmGenericConfig, JssmStateConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
|
|
3
|
-
JssmMachineInternalState, JssmAllowsOverride, JssmAllowIslands, JssmEditorConfig, JssmStochasticOptions, JssmStochasticRun, JssmStochasticSummary, JssmDefaultSize, JssmStateDeclaration, JssmStateStyleKeyList, JssmTransitionConfig, JssmGraphConfig, JssmLayout, JssmHistory, JssmSerialization, FslDirection,
|
|
4
|
-
import { arrow_direction, arrow_left_kind, arrow_right_kind } from './jssm_arrow.js';
|
|
5
|
-
import { compile, make, wrap_parse } from './jssm_compiler.js';
|
|
6
|
-
import { seq, unique, find_repeated, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key, gen_splitmix32, sleep } from './jssm_util.js';
|
|
3
|
+
JssmMachineInternalState, JssmAllowsOverride, JssmAllowIslands, JssmEditorConfig, JssmStochasticOptions, JssmStochasticRun, JssmStochasticSummary, JssmDefaultSize, JssmStateDeclaration, JssmStateStyleKeyList, JssmTransitionConfig, JssmGraphConfig, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult, EverythingHookContext, EverythingHookHandler, PostEverythingHookHandler, HookPhase, HookRegistryEntry, HookQuery, JssmEventName, JssmEventFilter, JssmEventHandler, JssmUnsubscribe, JssmGroupRegistry, JssmGroupHooks, JssmStateHooks, JssmRng } from './jssm_types.js';
|
|
7
4
|
import { Interner } from './jssm_intern.js';
|
|
8
|
-
import * as constants from './jssm_constants.js';
|
|
9
5
|
declare const shapes: string[], gviz_shapes: string[], named_colors: string[], state_name_chars: readonly {
|
|
10
6
|
from: string;
|
|
11
7
|
to: string;
|
|
@@ -17,12 +13,10 @@ declare const shapes: string[], gviz_shapes: string[], named_colors: string[], s
|
|
|
17
13
|
to: string;
|
|
18
14
|
}[];
|
|
19
15
|
export { fslDiagnostics, fslCompletions, fslSemanticSpans } from './language_service/index.js';
|
|
20
|
-
import { version, build_time } from './version.js';
|
|
21
16
|
/**
|
|
22
17
|
* Internal record holding a single registered event subscription: the
|
|
23
18
|
* handler, its optional filter, and a flag for `once` semantics. Not
|
|
24
19
|
* exported.
|
|
25
|
-
*
|
|
26
20
|
* @internal
|
|
27
21
|
*/
|
|
28
22
|
type JssmEventEntry<mDT, Ev extends JssmEventName> = {
|
|
@@ -40,63 +34,14 @@ type JssmEventEntry<mDT, Ev extends JssmEventName> = {
|
|
|
40
34
|
*
|
|
41
35
|
*/
|
|
42
36
|
declare function transfer_state_properties(state_decl: JssmStateDeclaration): JssmStateDeclaration;
|
|
43
|
-
/**
|
|
44
|
-
*
|
|
45
|
-
* Collapse a list of individual state-style key/value pairs into a single
|
|
46
|
-
* {@link JssmStateConfig} object, remapping FSL-style kebab-case keys to the
|
|
47
|
-
* camelCase field names the runtime uses.
|
|
48
|
-
*
|
|
49
|
-
* The parser emits state styling as a flat array like
|
|
50
|
-
* `[{ key: 'color', value: 'red' }, { key: 'line-style', value: 'dashed' }]`
|
|
51
|
-
* because that is the most natural shape for the grammar to produce. This
|
|
52
|
-
* helper runs once per style bucket during `Machine` construction to turn
|
|
53
|
-
* those arrays into the compact `{ color, lineStyle, ... }` objects the
|
|
54
|
-
* graph-rendering code expects.
|
|
55
|
-
*
|
|
56
|
-
* ```typescript
|
|
57
|
-
* state_style_condense([
|
|
58
|
-
* { key: 'color', value: 'red' },
|
|
59
|
-
* { key: 'shape', value: 'oval' },
|
|
60
|
-
* { key: 'line-style', value: 'dashed' }
|
|
61
|
-
* ]);
|
|
62
|
-
* // => { color: 'red', shape: 'oval', lineStyle: 'dashed' }
|
|
63
|
-
*
|
|
64
|
-
* state_style_condense(undefined);
|
|
65
|
-
* // => {}
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
|
-
* @param jssk The list of style keys to condense. `undefined` is accepted
|
|
69
|
-
* and yields an empty config.
|
|
70
|
-
*
|
|
71
|
-
* @param machine Optional `Machine` reference, used only so that any
|
|
72
|
-
* {@link JssmError} thrown can point at the offending machine in its
|
|
73
|
-
* diagnostic message.
|
|
74
|
-
*
|
|
75
|
-
* @returns A `JssmStateConfig` object containing every key from `jssk`
|
|
76
|
-
* remapped into its camelCase field.
|
|
77
|
-
*
|
|
78
|
-
* @throws {JssmError} If `jssk` is neither an array nor `undefined`, if any
|
|
79
|
-
* element is not an object, if the same key appears more than once, or if a
|
|
80
|
-
* key is not one of the recognized style names.
|
|
81
|
-
*
|
|
82
|
-
* @internal
|
|
83
|
-
*
|
|
84
|
-
*/
|
|
85
37
|
declare function state_style_condense(jssk: JssmStateStyleKeyList, machine?: any): JssmStateConfig;
|
|
86
38
|
/** Default number of independent Monte-Carlo runs when none is declared. */
|
|
87
39
|
export declare const STOCHASTIC_DEFAULT_RUNS = 1000;
|
|
88
40
|
/** Default per-run step cap (montecarlo) / walk length (steady_state). */
|
|
89
41
|
export declare const STOCHASTIC_DEFAULT_MAX_STEPS = 1000;
|
|
90
42
|
declare class Machine<mDT> {
|
|
43
|
+
#private;
|
|
91
44
|
_state: StateType;
|
|
92
|
-
_states: Map<StateType, JssmGenericState>;
|
|
93
|
-
_edges: Array<JssmTransition<StateType, mDT>>;
|
|
94
|
-
_edge_map: Map<StateType, Map<StateType, number>>;
|
|
95
|
-
_outbound_edge_ids: Map<StateType, Array<number>>;
|
|
96
|
-
_named_transitions: Map<StateType, number>;
|
|
97
|
-
_actions: Map<StateType, Map<StateType, number>>;
|
|
98
|
-
_reverse_actions: Map<StateType, Map<StateType, number>>;
|
|
99
|
-
_reverse_action_targets: Map<StateType, Map<StateType, number>>;
|
|
100
45
|
_state_interner: Interner;
|
|
101
46
|
_action_interner: Interner;
|
|
102
47
|
_state_id: number;
|
|
@@ -117,7 +62,7 @@ declare class Machine<mDT> {
|
|
|
117
62
|
_npm_name?: string;
|
|
118
63
|
_default_size?: JssmDefaultSize;
|
|
119
64
|
_fsl_version?: string;
|
|
120
|
-
_raw_state_declaration?: Array<
|
|
65
|
+
_raw_state_declaration?: Array<object>;
|
|
121
66
|
_state_declarations: Map<StateType, JssmStateDeclaration>;
|
|
122
67
|
_data?: mDT;
|
|
123
68
|
_instance_name: string;
|
|
@@ -205,8 +150,8 @@ declare class Machine<mDT> {
|
|
|
205
150
|
_create_started: number;
|
|
206
151
|
_created: number;
|
|
207
152
|
_after_mapping: Map<string, [string, number]>;
|
|
208
|
-
_timeout_source: (
|
|
209
|
-
_clear_timeout_source: (h:
|
|
153
|
+
_timeout_source: (f: () => void, a: number) => number;
|
|
154
|
+
_clear_timeout_source: (h: number) => void;
|
|
210
155
|
_timeout_handle: number | undefined;
|
|
211
156
|
_timeout_target: string | undefined;
|
|
212
157
|
_timeout_target_time: number | undefined;
|
|
@@ -359,9 +304,7 @@ declare class Machine<mDT> {
|
|
|
359
304
|
* const m = jssm.from('on <=> off;', { data: { a: { b: 1 } } });
|
|
360
305
|
* m._data_ref().a.b; // 1, zero-copy
|
|
361
306
|
* ```
|
|
362
|
-
*
|
|
363
307
|
* @returns The live data value; treat as read-only.
|
|
364
|
-
*
|
|
365
308
|
* @see Machine.data
|
|
366
309
|
* @internal
|
|
367
310
|
*/
|
|
@@ -619,18 +562,21 @@ declare class Machine<mDT> {
|
|
|
619
562
|
* current state, data, and timestamp.
|
|
620
563
|
*
|
|
621
564
|
*/
|
|
622
|
-
serialize(comment?: string
|
|
623
|
-
/**
|
|
565
|
+
serialize(comment?: string): JssmSerialization<mDT>;
|
|
566
|
+
/**
|
|
567
|
+
* Get the graph layout direction (e.g. `'LR'`, `'TB'`). Set via the
|
|
624
568
|
* FSL `graph_layout` directive.
|
|
625
569
|
* @returns The layout string, or the default if not set.
|
|
626
570
|
*/
|
|
627
571
|
graph_layout(): string;
|
|
628
|
-
/**
|
|
572
|
+
/**
|
|
573
|
+
* Get the Graphviz DOT preamble string, injected before the graph body
|
|
629
574
|
* during visualization. Set via the FSL `dot_preamble` directive.
|
|
630
575
|
* @returns The preamble string.
|
|
631
576
|
*/
|
|
632
577
|
dot_preamble(): string;
|
|
633
|
-
/**
|
|
578
|
+
/**
|
|
579
|
+
* Get the consolidated `transition: {}` default-config block: the ordered,
|
|
634
580
|
* de-duplicated `{ key, value }[]` list of edge-default style items compiled
|
|
635
581
|
* from a `transition: {}` block (e.g. `transition: { color: blue; }`). The
|
|
636
582
|
* viz layer projects this onto a Graphviz `edge [ … ]` default statement so
|
|
@@ -641,13 +587,13 @@ declare class Machine<mDT> {
|
|
|
641
587
|
* sm`a -> b; transition: { color: blue; };`.default_transition_config();
|
|
642
588
|
* // [ { key: 'color', value: '#0000ffff' } ]
|
|
643
589
|
* ```
|
|
644
|
-
*
|
|
645
590
|
* @returns The transition-config item list, or `undefined` if the machine
|
|
646
591
|
* declared no `transition: {}` block.
|
|
647
592
|
* @see default_graph_config
|
|
648
593
|
*/
|
|
649
594
|
default_transition_config(): JssmTransitionConfig | undefined;
|
|
650
|
-
/**
|
|
595
|
+
/**
|
|
596
|
+
* Get the consolidated `graph: {}` default-config block: the ordered,
|
|
651
597
|
* de-duplicated `{ key, value }[]` list of graph-scope style items. The
|
|
652
598
|
* compiler folds the deprecated top-level graph keywords
|
|
653
599
|
* (`graph_bg_color` → `background-color`, plus `graph_layout`, `theme`,
|
|
@@ -661,29 +607,33 @@ declare class Machine<mDT> {
|
|
|
661
607
|
* sm`a -> b; graph: { background-color: #ffffff; };`.default_graph_config();
|
|
662
608
|
* // [ { key: 'background-color', value: '#ffffffff' } ]
|
|
663
609
|
* ```
|
|
664
|
-
*
|
|
665
610
|
* @returns The graph-config item list, or `undefined` if the machine has no
|
|
666
611
|
* graph config (no `graph: {}` block and no deprecated graph keyword).
|
|
667
612
|
* @see default_transition_config
|
|
668
613
|
*/
|
|
669
614
|
default_graph_config(): JssmGraphConfig | undefined;
|
|
670
|
-
/**
|
|
615
|
+
/**
|
|
616
|
+
* Get the machine's author list. Set via the FSL `machine_author` directive.
|
|
671
617
|
* @returns An array of author name strings.
|
|
672
618
|
*/
|
|
673
619
|
machine_author(): Array<string>;
|
|
674
|
-
/**
|
|
620
|
+
/**
|
|
621
|
+
* Get the machine's comment string. Set via the FSL `machine_comment` directive.
|
|
675
622
|
* @returns The comment string.
|
|
676
623
|
*/
|
|
677
624
|
machine_comment(): string;
|
|
678
|
-
/**
|
|
625
|
+
/**
|
|
626
|
+
* Get the machine's contributor list. Set via the FSL `machine_contributor` directive.
|
|
679
627
|
* @returns An array of contributor name strings.
|
|
680
628
|
*/
|
|
681
629
|
machine_contributor(): Array<string>;
|
|
682
|
-
/**
|
|
630
|
+
/**
|
|
631
|
+
* Get the machine's definition string. Set via the FSL `machine_definition` directive.
|
|
683
632
|
* @returns The definition string.
|
|
684
633
|
*/
|
|
685
634
|
machine_definition(): string;
|
|
686
|
-
/**
|
|
635
|
+
/**
|
|
636
|
+
* Get the machine's natural language as an ISO 639-1 code. Set via the FSL
|
|
687
637
|
* `machine_language` directive, which accepts a language name or code, or a
|
|
688
638
|
* BCP-47 tag whose region subtag is dropped (`en-us` -> `en`). Unrecognized
|
|
689
639
|
* values resolve to `undefined`.
|
|
@@ -691,32 +641,35 @@ declare class Machine<mDT> {
|
|
|
691
641
|
* supplied value did not resolve to a known language.
|
|
692
642
|
*/
|
|
693
643
|
machine_language(): string;
|
|
694
|
-
/**
|
|
644
|
+
/**
|
|
645
|
+
* Get the machine's license string. Set via the FSL `machine_license` directive.
|
|
695
646
|
* @returns The license string.
|
|
696
647
|
*/
|
|
697
648
|
machine_license(): string;
|
|
698
|
-
/**
|
|
649
|
+
/**
|
|
650
|
+
* Get the machine's name. Set via the FSL `machine_name` directive.
|
|
699
651
|
* @returns The machine name string.
|
|
700
652
|
*/
|
|
701
653
|
machine_name(): string;
|
|
702
|
-
/**
|
|
654
|
+
/**
|
|
655
|
+
* The editor/panel defaults declared in the FSL `editor: {}` block, or
|
|
703
656
|
* `undefined` when none was given. Read by the all-widgets web control
|
|
704
657
|
* (fsl#1334) — `panels` drives `request` panel mode.
|
|
705
|
-
*
|
|
706
658
|
* @returns `{ stochastic_run_count?, panels? }`, or `undefined`.
|
|
707
|
-
*
|
|
708
659
|
* @example
|
|
709
660
|
* const m = sm`editor: { panels: [history]; }; a -> b;`;
|
|
710
661
|
* m.editor_config(); // => { panels: ['history'] }
|
|
711
662
|
*/
|
|
712
663
|
editor_config(): JssmEditorConfig | undefined;
|
|
713
|
-
/**
|
|
664
|
+
/**
|
|
665
|
+
* Get the npm package name associated with the machine. Set via the FSL `npm_name` directive.
|
|
714
666
|
* Returns `undefined` when not present.
|
|
715
667
|
* @returns The npm package name string, or `undefined`.
|
|
716
668
|
* @see machine_name
|
|
717
669
|
*/
|
|
718
670
|
npm_name(): string;
|
|
719
|
-
/**
|
|
671
|
+
/**
|
|
672
|
+
* Get the render-size hint for the machine's visualization. Set via the
|
|
720
673
|
* FSL `default_size` directive. Returns `undefined` when not present.
|
|
721
674
|
*
|
|
722
675
|
* The three FSL forms each produce a different subset of fields:
|
|
@@ -726,33 +679,38 @@ declare class Machine<mDT> {
|
|
|
726
679
|
* - `default_size: height 600;` → `{ height: 600 }`
|
|
727
680
|
*
|
|
728
681
|
* This is a hint, not a hard constraint. Renderers may ignore it.
|
|
729
|
-
*
|
|
730
682
|
* @returns The size-hint object, or `undefined` if not set.
|
|
731
683
|
* @see npm_name
|
|
732
684
|
*/
|
|
733
685
|
default_size(): JssmDefaultSize | undefined;
|
|
734
|
-
/**
|
|
686
|
+
/**
|
|
687
|
+
* Get the machine's version string. Set via the FSL `machine_version` directive.
|
|
735
688
|
* @returns The version string.
|
|
736
689
|
*/
|
|
737
690
|
machine_version(): string;
|
|
738
|
-
/**
|
|
691
|
+
/**
|
|
692
|
+
* Get the raw state declaration objects as parsed from the FSL source.
|
|
739
693
|
* @returns An array of raw state declaration objects.
|
|
740
694
|
*/
|
|
741
|
-
raw_state_declarations(): Array<
|
|
742
|
-
/**
|
|
695
|
+
raw_state_declarations(): Array<object>;
|
|
696
|
+
/**
|
|
697
|
+
* Get the processed state declaration for a specific state.
|
|
743
698
|
* @param which - The state to look up.
|
|
744
699
|
* @returns The {@link JssmStateDeclaration} for the given state.
|
|
745
700
|
*/
|
|
746
701
|
state_declaration(which: StateType): JssmStateDeclaration;
|
|
747
|
-
/**
|
|
702
|
+
/**
|
|
703
|
+
* Get all processed state declarations as a Map.
|
|
748
704
|
* @returns A `Map` from state name to {@link JssmStateDeclaration}.
|
|
749
705
|
*/
|
|
750
706
|
state_declarations(): Map<StateType, JssmStateDeclaration>;
|
|
751
|
-
/**
|
|
707
|
+
/**
|
|
708
|
+
* Get the FSL language version this machine was compiled under.
|
|
752
709
|
* @returns The FSL version string.
|
|
753
710
|
*/
|
|
754
711
|
fsl_version(): string;
|
|
755
|
-
/**
|
|
712
|
+
/**
|
|
713
|
+
* Get the complete internal state of the machine as a serializable
|
|
756
714
|
* structure. Includes actions, edges, edge map, named transitions,
|
|
757
715
|
* reverse actions, current state, and states map.
|
|
758
716
|
* @returns A {@link JssmMachineInternalState} snapshot.
|
|
@@ -776,7 +734,8 @@ declare class Machine<mDT> {
|
|
|
776
734
|
*
|
|
777
735
|
*/
|
|
778
736
|
states(): Array<StateType>;
|
|
779
|
-
/**
|
|
737
|
+
/**
|
|
738
|
+
* Get the internal state descriptor for a given state name.
|
|
780
739
|
* @param whichState - The state to look up.
|
|
781
740
|
* @returns The {@link JssmGenericState} descriptor.
|
|
782
741
|
* @throws {JssmError} If the state does not exist.
|
|
@@ -839,19 +798,23 @@ declare class Machine<mDT> {
|
|
|
839
798
|
*
|
|
840
799
|
*/
|
|
841
800
|
list_edges(): Array<JssmTransition<StateType, mDT>>;
|
|
842
|
-
/**
|
|
801
|
+
/**
|
|
802
|
+
* Get the map of named transitions (transitions with explicit names).
|
|
843
803
|
* @returns A `Map` from transition name to edge index.
|
|
844
804
|
*/
|
|
845
805
|
list_named_transitions(): Map<StateType, number>;
|
|
846
|
-
/**
|
|
806
|
+
/**
|
|
807
|
+
* List all distinct action names defined anywhere in the machine.
|
|
847
808
|
* @returns An array of action name strings.
|
|
848
809
|
*/
|
|
849
810
|
list_actions(): Array<StateType>;
|
|
850
|
-
/**
|
|
811
|
+
/**
|
|
812
|
+
* Whether any actions are defined on this machine.
|
|
851
813
|
* @returns `true` if the machine has at least one action.
|
|
852
814
|
*/
|
|
853
815
|
get uses_actions(): boolean;
|
|
854
|
-
/**
|
|
816
|
+
/**
|
|
817
|
+
* Whether any forced (`~>`) transitions exist in this machine.
|
|
855
818
|
* @returns `true` if at least one forced transition is defined.
|
|
856
819
|
*/
|
|
857
820
|
get uses_forced_transitions(): boolean;
|
|
@@ -892,16 +855,16 @@ declare class Machine<mDT> {
|
|
|
892
855
|
*
|
|
893
856
|
*/
|
|
894
857
|
get allow_islands(): JssmAllowIslands;
|
|
895
|
-
/**
|
|
858
|
+
/**
|
|
859
|
+
* List all available theme names.
|
|
896
860
|
* @returns An array of theme name strings.
|
|
897
861
|
*/
|
|
898
862
|
all_themes(): FslTheme[];
|
|
899
|
-
/**
|
|
863
|
+
/**
|
|
864
|
+
* List the character ranges accepted by the FSL grammar in any but the
|
|
900
865
|
* first position of a state name (atom). Each entry is an inclusive
|
|
901
866
|
* `{from, to}` range of single Unicode characters.
|
|
902
|
-
*
|
|
903
867
|
* @returns An array of `{from, to}` inclusive character ranges.
|
|
904
|
-
*
|
|
905
868
|
* @example
|
|
906
869
|
* import { sm } from 'jssm';
|
|
907
870
|
* const m = sm`a -> b;`;
|
|
@@ -911,12 +874,11 @@ declare class Machine<mDT> {
|
|
|
911
874
|
from: string;
|
|
912
875
|
to: string;
|
|
913
876
|
}>;
|
|
914
|
-
/**
|
|
877
|
+
/**
|
|
878
|
+
* List the character ranges accepted by the FSL grammar in the first
|
|
915
879
|
* position of a state name (atom). Narrower than
|
|
916
880
|
* {@link all_state_name_chars}: notably omits `+`, `(`, `)`, `&`, `#`, `@`.
|
|
917
|
-
*
|
|
918
881
|
* @returns An array of `{from, to}` inclusive character ranges.
|
|
919
|
-
*
|
|
920
882
|
* @example
|
|
921
883
|
* import { sm } from 'jssm';
|
|
922
884
|
* const m = sm`a -> b;`;
|
|
@@ -926,12 +888,11 @@ declare class Machine<mDT> {
|
|
|
926
888
|
from: string;
|
|
927
889
|
to: string;
|
|
928
890
|
}>;
|
|
929
|
-
/**
|
|
891
|
+
/**
|
|
892
|
+
* List the character ranges accepted inside a single-quoted FSL action
|
|
930
893
|
* label without escaping. Space is allowed; the apostrophe `'` is
|
|
931
894
|
* explicitly excluded since it terminates the label.
|
|
932
|
-
*
|
|
933
895
|
* @returns An array of `{from, to}` inclusive character ranges.
|
|
934
|
-
*
|
|
935
896
|
* @example
|
|
936
897
|
* import { sm } from 'jssm';
|
|
937
898
|
* const m = sm`a -> b;`;
|
|
@@ -942,28 +903,33 @@ declare class Machine<mDT> {
|
|
|
942
903
|
from: string;
|
|
943
904
|
to: string;
|
|
944
905
|
}>;
|
|
945
|
-
/**
|
|
906
|
+
/**
|
|
907
|
+
* Get the active theme(s) for this machine. Always stored as an array
|
|
946
908
|
* internally; the union return type exists for setter compatibility.
|
|
947
909
|
* @returns The current theme or array of themes.
|
|
948
910
|
*/
|
|
949
911
|
get themes(): FslTheme | FslTheme[];
|
|
950
|
-
/**
|
|
912
|
+
/**
|
|
913
|
+
* Set the active theme(s). Accepts a single theme name or an array.
|
|
951
914
|
* @param to - A theme name or array of theme names to apply.
|
|
952
915
|
*/
|
|
953
916
|
set themes(to: FslTheme | FslTheme[]);
|
|
954
|
-
/**
|
|
917
|
+
/**
|
|
918
|
+
* Get the flow direction for graph layout (e.g. `'right'`, `'down'`).
|
|
955
919
|
* Set via the FSL `flow` directive.
|
|
956
920
|
* @returns The current flow direction.
|
|
957
921
|
*/
|
|
958
922
|
flow(): FslDirection;
|
|
959
|
-
/**
|
|
923
|
+
/**
|
|
924
|
+
* Look up a transition's edge index by source and target state names.
|
|
960
925
|
* @param from - Source state name.
|
|
961
926
|
* @param to - Target state name.
|
|
962
927
|
* @returns The edge index in the edges array, or `undefined` if no
|
|
963
928
|
* such transition exists.
|
|
964
929
|
*/
|
|
965
930
|
get_transition_by_state_names(from: StateType, to: StateType): number;
|
|
966
|
-
/**
|
|
931
|
+
/**
|
|
932
|
+
* Look up the full transition object for a given source→target pair.
|
|
967
933
|
* @param from - Source state name.
|
|
968
934
|
* @param to - Target state name.
|
|
969
935
|
* @returns The {@link JssmTransition} object, or `undefined` if none exists.
|
|
@@ -1035,7 +1001,8 @@ declare class Machine<mDT> {
|
|
|
1035
1001
|
*
|
|
1036
1002
|
*/
|
|
1037
1003
|
list_exits(whichState?: StateType): Array<StateType>;
|
|
1038
|
-
/**
|
|
1004
|
+
/**
|
|
1005
|
+
* Get the transitions available from a state for use by the probabilistic
|
|
1039
1006
|
* walk system.
|
|
1040
1007
|
*
|
|
1041
1008
|
* If any exit declares a `probability`, only those probability-bearing
|
|
@@ -1048,37 +1015,39 @@ declare class Machine<mDT> {
|
|
|
1048
1015
|
* Fixes StoneCypher/fsl#1325, in which the function previously returned
|
|
1049
1016
|
* every exit unconditionally — including forced-only exits and exits
|
|
1050
1017
|
* with no `probability`, which distorted the weighted distribution.
|
|
1051
|
-
*
|
|
1052
1018
|
* @param whichState - The state to inspect.
|
|
1053
1019
|
* @returns An array of {@link JssmTransition} edges exiting the state,
|
|
1054
1020
|
* filtered as described above. May be empty.
|
|
1055
1021
|
* @throws {JssmError} If the state does not exist.
|
|
1056
1022
|
*/
|
|
1057
1023
|
probable_exits_for(whichState: StateType): Array<JssmTransition<StateType, mDT>>;
|
|
1058
|
-
/**
|
|
1024
|
+
/**
|
|
1025
|
+
* Take a single random transition from the current state, weighted by
|
|
1059
1026
|
* edge probabilities.
|
|
1060
1027
|
* @returns `true` if a transition was taken, `false` otherwise.
|
|
1061
1028
|
*/
|
|
1062
1029
|
probabilistic_transition(): boolean;
|
|
1063
|
-
/**
|
|
1030
|
+
/**
|
|
1031
|
+
* Take `n` consecutive probabilistic transitions and return the sequence
|
|
1064
1032
|
* of states visited (before each transition).
|
|
1065
1033
|
* @param n - Number of steps to walk.
|
|
1066
1034
|
* @returns An array of state names visited during the walk.
|
|
1067
1035
|
*/
|
|
1068
1036
|
probabilistic_walk(n: number): Array<StateType>;
|
|
1069
|
-
/**
|
|
1037
|
+
/**
|
|
1038
|
+
* Take `n` probabilistic steps and return a histograph of how many times
|
|
1070
1039
|
* each state was visited.
|
|
1071
1040
|
* @param n - Number of steps to walk.
|
|
1072
1041
|
* @returns A `Map` from state name to visit count.
|
|
1073
1042
|
*/
|
|
1074
1043
|
probabilistic_histo_walk(n: number): Map<StateType, number>;
|
|
1075
|
-
/**
|
|
1044
|
+
/**
|
|
1045
|
+
* One non-destructive weighted-random walk over the graph from `start`.
|
|
1076
1046
|
*
|
|
1077
1047
|
* Reads the graph and advances the PRNG only — it never calls
|
|
1078
1048
|
* {@link Machine.transition}, so it fires no hooks, mutates no machine
|
|
1079
1049
|
* state, and touches no `data`. A state with no probabilistic exits
|
|
1080
1050
|
* (a terminal, or a forced-only `~>` state) ends the walk.
|
|
1081
|
-
*
|
|
1082
1051
|
* @param start - State to begin the walk from.
|
|
1083
1052
|
* @param max_steps - Maximum transitions before the walk is step-capped.
|
|
1084
1053
|
* @param exit_memo - Per-run-set cache of {@link Machine.probable_exits_for}
|
|
@@ -1091,7 +1060,8 @@ declare class Machine<mDT> {
|
|
|
1091
1060
|
* @returns The {@link JssmStochasticRun} for this walk.
|
|
1092
1061
|
*/
|
|
1093
1062
|
private _stochastic_one_walk;
|
|
1094
|
-
/**
|
|
1063
|
+
/**
|
|
1064
|
+
* Lazily yield one {@link JssmStochasticRun} at a time.
|
|
1095
1065
|
*
|
|
1096
1066
|
* In `montecarlo` mode (default) yields `runs` independent walks from the
|
|
1097
1067
|
* current state, each ending at a terminal or after `max_steps`. In
|
|
@@ -1102,16 +1072,16 @@ declare class Machine<mDT> {
|
|
|
1102
1072
|
* Passing `seed` reseeds the machine for reproducible runs. Unlike
|
|
1103
1073
|
* {@link Machine.stochastic_summary}, the generator does NOT restore the
|
|
1104
1074
|
* prior seed afterward — a direct caller's machine is left reseeded.
|
|
1105
|
-
*
|
|
1106
1075
|
* @param opts - {@link JssmStochasticOptions}.
|
|
1076
|
+
* @yields One {@link JssmStochasticRun} per completed walk.
|
|
1107
1077
|
* @returns A generator of per-run results.
|
|
1108
|
-
*
|
|
1109
1078
|
* @example
|
|
1110
1079
|
* const m = sm`a 'go' -> b 'go' -> c;`;
|
|
1111
1080
|
* [...m.stochastic_runs({ runs: 2, seed: 1 })].length; // => 2
|
|
1112
1081
|
*/
|
|
1113
1082
|
stochastic_runs(opts?: JssmStochasticOptions): Generator<JssmStochasticRun>;
|
|
1114
|
-
/**
|
|
1083
|
+
/**
|
|
1084
|
+
* Run many weighted-random walks and return aggregate statistics.
|
|
1115
1085
|
*
|
|
1116
1086
|
* Honors `%` transition probabilities (via the existing probabilistic
|
|
1117
1087
|
* machinery). Non-destructive: the machine's current state and
|
|
@@ -1122,16 +1092,13 @@ declare class Machine<mDT> {
|
|
|
1122
1092
|
*
|
|
1123
1093
|
* Timing (`after`) decorations and data-guard conditions are not modeled
|
|
1124
1094
|
* by this sampler; it walks the probabilistic graph topology.
|
|
1125
|
-
*
|
|
1126
1095
|
* @param opts - {@link JssmStochasticOptions}. `runs` defaults to the
|
|
1127
1096
|
* machine's declared `editor: { stochastic_run_count }` (fsl#1334) when
|
|
1128
1097
|
* present, otherwise {@link STOCHASTIC_DEFAULT_RUNS}.
|
|
1129
1098
|
* @returns A {@link JssmStochasticSummary}.
|
|
1130
|
-
*
|
|
1131
1099
|
* @see Machine.stochastic_runs
|
|
1132
1100
|
* @see Machine.probabilistic_walk
|
|
1133
1101
|
* @see Machine.editor_config
|
|
1134
|
-
*
|
|
1135
1102
|
* @example
|
|
1136
1103
|
* const m = sm`a 'go' -> b 'go' -> c;`;
|
|
1137
1104
|
* const s = m.stochastic_summary({ runs: 100, seed: 1 });
|
|
@@ -1199,17 +1166,16 @@ declare class Machine<mDT> {
|
|
|
1199
1166
|
*
|
|
1200
1167
|
*/
|
|
1201
1168
|
list_states_having_action(whichState: StateType): Array<StateType>;
|
|
1202
|
-
/**
|
|
1169
|
+
/**
|
|
1170
|
+
* List all action names available as exits from a given state.
|
|
1203
1171
|
*
|
|
1204
1172
|
* Returns the empty array (does not throw) when `whichState` exists but has
|
|
1205
1173
|
* no action-named exits — including terminal states, states whose only
|
|
1206
1174
|
* exits are plain `->` transitions, and states in machines that use no
|
|
1207
1175
|
* actions at all. Only nonexistent states cause a throw.
|
|
1208
|
-
*
|
|
1209
1176
|
* @param whichState - The state to inspect. Defaults to the current state.
|
|
1210
1177
|
* @returns An array of action name strings, possibly empty.
|
|
1211
1178
|
* @throws {JssmError} If the state does not exist.
|
|
1212
|
-
*
|
|
1213
1179
|
* @example
|
|
1214
1180
|
* const m = sm`a 'go' -> b; b -> c;`;
|
|
1215
1181
|
* m.list_exit_actions('a'); // => ['go']
|
|
@@ -1218,33 +1184,39 @@ declare class Machine<mDT> {
|
|
|
1218
1184
|
* expect(() => m.list_exit_actions('z')).toThrow();
|
|
1219
1185
|
*/
|
|
1220
1186
|
list_exit_actions(whichState?: StateType): Array<StateType>;
|
|
1221
|
-
/**
|
|
1187
|
+
/**
|
|
1188
|
+
* List all action exits from a state with their probabilities.
|
|
1222
1189
|
* @param whichState - The state to inspect. Defaults to the current state.
|
|
1223
1190
|
* @returns An array of `{ action, probability }` objects.
|
|
1224
1191
|
* @throws {JssmError} If the state does not exist.
|
|
1225
1192
|
*/
|
|
1226
1193
|
probable_action_exits(whichState?: StateType): Array<any>;
|
|
1227
|
-
/**
|
|
1194
|
+
/**
|
|
1195
|
+
* Check whether a state has no incoming transitions (unreachable after start).
|
|
1228
1196
|
* @param whichState - The state to check.
|
|
1229
1197
|
* @returns `true` if the state has zero entrances.
|
|
1230
1198
|
* @throws {JssmError} If the state does not exist.
|
|
1231
1199
|
*/
|
|
1232
1200
|
is_unenterable(whichState: StateType): boolean;
|
|
1233
|
-
/**
|
|
1201
|
+
/**
|
|
1202
|
+
* Check whether any state in the machine is unenterable.
|
|
1234
1203
|
* @returns `true` if at least one state has no incoming transitions.
|
|
1235
1204
|
*/
|
|
1236
1205
|
has_unenterables(): boolean;
|
|
1237
|
-
/**
|
|
1206
|
+
/**
|
|
1207
|
+
* Check whether the current state is terminal (has no exits).
|
|
1238
1208
|
* @returns `true` if the current state has zero exits.
|
|
1239
1209
|
*/
|
|
1240
1210
|
is_terminal(): boolean;
|
|
1241
|
-
/**
|
|
1211
|
+
/**
|
|
1212
|
+
* Check whether a specific state is terminal (has no exits).
|
|
1242
1213
|
* @param whichState - The state to check.
|
|
1243
1214
|
* @returns `true` if the state has zero exits.
|
|
1244
1215
|
* @throws {JssmError} If the state does not exist.
|
|
1245
1216
|
*/
|
|
1246
1217
|
state_is_terminal(whichState: StateType): boolean;
|
|
1247
|
-
/**
|
|
1218
|
+
/**
|
|
1219
|
+
* Check whether any state in the machine is terminal.
|
|
1248
1220
|
* @returns `true` if at least one state has no exits.
|
|
1249
1221
|
*/
|
|
1250
1222
|
has_terminals(): boolean;
|
|
@@ -1356,17 +1328,20 @@ declare class Machine<mDT> {
|
|
|
1356
1328
|
*
|
|
1357
1329
|
*/
|
|
1358
1330
|
statesIn(groupName: string): Array<StateType>;
|
|
1359
|
-
/**
|
|
1331
|
+
/**
|
|
1332
|
+
* Check whether the current state is complete (every exit has an action).
|
|
1360
1333
|
* @returns `true` if the current state is complete.
|
|
1361
1334
|
*/
|
|
1362
1335
|
is_complete(): boolean;
|
|
1363
|
-
/**
|
|
1336
|
+
/**
|
|
1337
|
+
* Check whether a specific state is complete (every exit has an action).
|
|
1364
1338
|
* @param whichState - The state to check.
|
|
1365
1339
|
* @returns `true` if the state is complete.
|
|
1366
1340
|
* @throws {JssmError} If the state does not exist.
|
|
1367
1341
|
*/
|
|
1368
1342
|
state_is_complete(whichState: StateType): boolean;
|
|
1369
|
-
/**
|
|
1343
|
+
/**
|
|
1344
|
+
* Check whether any state in the machine is complete.
|
|
1370
1345
|
* @returns `true` if at least one state is complete.
|
|
1371
1346
|
*/
|
|
1372
1347
|
has_completes(): boolean;
|
|
@@ -1390,14 +1365,12 @@ declare class Machine<mDT> {
|
|
|
1390
1365
|
* const off = m.on('transition', () => {});
|
|
1391
1366
|
* off(); // unsubscribe
|
|
1392
1367
|
* ```
|
|
1393
|
-
*
|
|
1394
|
-
* @typeParam Ev The event name (drives the detail type).
|
|
1368
|
+
* @template Ev The event name (drives the detail type).
|
|
1395
1369
|
* @param name The event name to subscribe to.
|
|
1396
1370
|
* @param handler The handler invoked on each matching delivery. The
|
|
1397
1371
|
* three-argument `(name, filter, handler)` form inserts a
|
|
1398
1372
|
* filter object before the handler (see the example above).
|
|
1399
1373
|
* @returns A function that unsubscribes when called.
|
|
1400
|
-
*
|
|
1401
1374
|
* @see Machine.off
|
|
1402
1375
|
* @see Machine.once
|
|
1403
1376
|
*/
|
|
@@ -1411,15 +1384,13 @@ declare class Machine<mDT> {
|
|
|
1411
1384
|
* ```typescript
|
|
1412
1385
|
* m.once('terminal', e => console.log(`done at ${e.state}`));
|
|
1413
1386
|
* ```
|
|
1414
|
-
*
|
|
1415
|
-
* @typeParam Ev The event name.
|
|
1387
|
+
* @template Ev The event name.
|
|
1416
1388
|
* @param name The event name.
|
|
1417
1389
|
* @param handler The handler invoked on the first matching delivery. The
|
|
1418
1390
|
* three-argument `(name, filter, handler)` form inserts a
|
|
1419
1391
|
* filter object before the handler (same shapes as `on`).
|
|
1420
1392
|
* @returns A function that unsubscribes early if called before the
|
|
1421
1393
|
* handler has fired.
|
|
1422
|
-
*
|
|
1423
1394
|
* @see Machine.on
|
|
1424
1395
|
* @see Machine.off
|
|
1425
1396
|
*/
|
|
@@ -1437,112 +1408,11 @@ declare class Machine<mDT> {
|
|
|
1437
1408
|
* m.off('transition', fn); // true
|
|
1438
1409
|
* m.off('transition', fn); // false
|
|
1439
1410
|
* ```
|
|
1440
|
-
*
|
|
1441
1411
|
* @param name The event name.
|
|
1442
1412
|
* @param handler The handler reference to remove.
|
|
1443
1413
|
* @returns `true` if removed, `false` if no match was registered.
|
|
1444
1414
|
*/
|
|
1445
1415
|
off<Ev extends JssmEventName>(name: Ev, handler: JssmEventHandler<mDT, Ev>): boolean;
|
|
1446
|
-
/**
|
|
1447
|
-
* Remove one event-subscription entry from its set and keep
|
|
1448
|
-
* {@link Machine._event_listener_count} in sync. The count is decremented
|
|
1449
|
-
* only when the entry was actually present, so calling a stale unsubscribe
|
|
1450
|
-
* closure (or removing an already-fired `once` entry) is idempotent and
|
|
1451
|
-
* cannot drive the count negative.
|
|
1452
|
-
*
|
|
1453
|
-
* @param set The per-event-name subscription set.
|
|
1454
|
-
* @param entry The entry to remove.
|
|
1455
|
-
* @internal
|
|
1456
|
-
*/
|
|
1457
|
-
_unsubscribe_entry(set: Set<JssmEventEntry<any, any>>, entry: JssmEventEntry<any, any>): void;
|
|
1458
|
-
/**
|
|
1459
|
-
* Shared registration core used by {@link Machine.on} and
|
|
1460
|
-
* {@link Machine.once}. Normalizes the optional filter argument and
|
|
1461
|
-
* installs the entry into the per-event subscription set.
|
|
1462
|
-
*
|
|
1463
|
-
* @internal
|
|
1464
|
-
*/
|
|
1465
|
-
_subscribe<Ev extends JssmEventName>(name: Ev, filterOrFn: JssmEventFilter<mDT, Ev> | JssmEventHandler<mDT, Ev>, maybeFn: JssmEventHandler<mDT, Ev> | undefined, once: boolean): JssmUnsubscribe;
|
|
1466
|
-
/**
|
|
1467
|
-
* Invoke a single event-handler entry, respecting its filter, once-removal
|
|
1468
|
-
* semantics, and the error re-fire / recursion-guard logic. Extracted so
|
|
1469
|
-
* {@link _fire} can share identical behavior between the size-1 fast-path
|
|
1470
|
-
* and the general snapshotted loop.
|
|
1471
|
-
*
|
|
1472
|
-
* @param entry - The subscriber descriptor to invoke.
|
|
1473
|
-
* @param set - The live Set that owns `entry`; needed for once-removal.
|
|
1474
|
-
* @param name - The event name being dispatched (used in error re-fires).
|
|
1475
|
-
* @param detail - The event payload forwarded to the handler.
|
|
1476
|
-
*
|
|
1477
|
-
* @internal
|
|
1478
|
-
*/
|
|
1479
|
-
_fire_one<Ev extends JssmEventName>(entry: JssmEventEntry<mDT, Ev>, set: Set<JssmEventEntry<any, any>>, name: Ev, detail: JssmEventDetailMap<mDT>[Ev]): void;
|
|
1480
|
-
/**
|
|
1481
|
-
* Dispatch an event to every registered subscriber in registration
|
|
1482
|
-
* order. Filters are checked first; non-matching handlers are skipped
|
|
1483
|
-
* without invoking the handler. Exceptions thrown by a handler are
|
|
1484
|
-
* caught and re-emitted as an `error` event so subsequent handlers
|
|
1485
|
-
* still run.
|
|
1486
|
-
*
|
|
1487
|
-
* Re-entry into the `error` event itself is guarded — if an `error`
|
|
1488
|
-
* handler throws, the new exception is swallowed rather than rebroadcast
|
|
1489
|
-
* to avoid an infinite loop.
|
|
1490
|
-
*
|
|
1491
|
-
* When exactly one subscriber is registered the common case avoids the
|
|
1492
|
-
* `Array.from(set)` snapshot allocation by capturing the lone entry into a
|
|
1493
|
-
* local first — equivalent to a 1-element snapshot but allocation-free.
|
|
1494
|
-
* The general path still snapshots for re-entrancy safety.
|
|
1495
|
-
*
|
|
1496
|
-
* @internal
|
|
1497
|
-
*/
|
|
1498
|
-
/**
|
|
1499
|
-
* Whether at least one live subscriber is registered for `name`. Used by
|
|
1500
|
-
* the transition-commit observation block to skip building a detail
|
|
1501
|
-
* literal that {@link Machine._fire} would immediately discard — a panel
|
|
1502
|
-
* listening only to `'transition'` (fsl-bind, fsl-viz, fsl-info-panel)
|
|
1503
|
-
* previously paid for the exit/entry/data-change detail allocations on
|
|
1504
|
-
* every transition. Read at fire time, so a listener installed by a
|
|
1505
|
-
* pre-hook is still seen (#671).
|
|
1506
|
-
*
|
|
1507
|
-
* @param name The event name to probe.
|
|
1508
|
-
* @returns `true` when a subsequent `_fire(name, ...)` would reach at
|
|
1509
|
-
* least one handler.
|
|
1510
|
-
*
|
|
1511
|
-
* ```typescript
|
|
1512
|
-
* machine.on('transition', () => {});
|
|
1513
|
-
* machine._has_subscribers('transition'); // true
|
|
1514
|
-
* machine._has_subscribers('exit'); // false
|
|
1515
|
-
* ```
|
|
1516
|
-
*
|
|
1517
|
-
* @see Machine._fire
|
|
1518
|
-
* @internal
|
|
1519
|
-
*/
|
|
1520
|
-
_has_subscribers(name: JssmEventName): boolean;
|
|
1521
|
-
_fire<Ev extends JssmEventName>(name: Ev, detail: JssmEventDetailMap<mDT>[Ev]): void;
|
|
1522
|
-
/** Low-level hook registration. Installs a handler described by a
|
|
1523
|
-
* {@link HookDescription} into the appropriate internal map. Prefer the
|
|
1524
|
-
* convenience wrappers ({@link hook}, {@link hook_entry}, etc.) over
|
|
1525
|
-
* calling this directly.
|
|
1526
|
-
* @param HookDesc - A hook descriptor specifying kind, states, and handler.
|
|
1527
|
-
*/
|
|
1528
|
-
/**
|
|
1529
|
-
* Validate a {@link HookDescription} before registration. Every hook needs
|
|
1530
|
-
* a `handler` function, and each kind's identifying spatial fields
|
|
1531
|
-
* (`from`/`to`/`action`) must be exactly those `set_hook` reads for that
|
|
1532
|
-
* kind — present when required, absent otherwise. This turns a mis-shaped
|
|
1533
|
-
* descriptor into a thrown error instead of a silently dead hook keyed on
|
|
1534
|
-
* `undefined` (e.g. an `exit` hook handed `to` instead of `from`, #734).
|
|
1535
|
-
*
|
|
1536
|
-
* @param HookDesc - The descriptor about to be registered.
|
|
1537
|
-
* @throws JssmError if the kind is unknown, the handler is not a function, a
|
|
1538
|
-
* required field is missing, or an inapplicable field is present.
|
|
1539
|
-
*
|
|
1540
|
-
* @example
|
|
1541
|
-
* const m = sm`a -> b;`;
|
|
1542
|
-
* // an exit hook is keyed by `from`, so supplying `to` is rejected:
|
|
1543
|
-
* expect(() => m.set_hook({ kind: 'exit', to: 'a', handler: () => true })).toThrow();
|
|
1544
|
-
*/
|
|
1545
|
-
_validate_hook_description(HookDesc: HookDescription<mDT>): void;
|
|
1546
1416
|
set_hook(HookDesc: HookDescription<mDT>): void;
|
|
1547
1417
|
/**
|
|
1548
1418
|
* Remove a previously-registered hook described by a
|
|
@@ -1561,12 +1431,12 @@ declare class Machine<mDT> {
|
|
|
1561
1431
|
* m.set_hook({ kind: 'hook', from: 'a', to: 'b', handler: fn });
|
|
1562
1432
|
* m.remove_hook({ kind: 'hook', from: 'a', to: 'b', handler: fn });
|
|
1563
1433
|
* ```
|
|
1564
|
-
*
|
|
1565
1434
|
* @param HookDesc - A hook descriptor identifying the hook to remove.
|
|
1566
1435
|
* @returns `true` if a hook was removed, `false` otherwise.
|
|
1567
1436
|
*/
|
|
1568
1437
|
remove_hook(HookDesc: HookDescription<mDT>): boolean;
|
|
1569
|
-
/**
|
|
1438
|
+
/**
|
|
1439
|
+
* Register a pre-transition hook on a specific edge. Fires before
|
|
1570
1440
|
* transitioning from `from` to `to`. If the handler returns `false`, the
|
|
1571
1441
|
* transition is blocked.
|
|
1572
1442
|
*
|
|
@@ -1574,14 +1444,14 @@ declare class Machine<mDT> {
|
|
|
1574
1444
|
* const m = sm`a -> b -> c;`;
|
|
1575
1445
|
* m.hook('a', 'b', () => console.log('a->b'));
|
|
1576
1446
|
* ```
|
|
1577
|
-
*
|
|
1578
1447
|
* @param from - Source state name.
|
|
1579
1448
|
* @param to - Target state name.
|
|
1580
1449
|
* @param handler - Callback invoked before the transition.
|
|
1581
1450
|
* @returns `this` for chaining.
|
|
1582
1451
|
*/
|
|
1583
1452
|
hook(from: string, to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1584
|
-
/**
|
|
1453
|
+
/**
|
|
1454
|
+
* Register a pre-transition hook on a specific action-labeled edge.
|
|
1585
1455
|
* @param from - Source state name.
|
|
1586
1456
|
* @param to - Target state name.
|
|
1587
1457
|
* @param action - The action label that triggers this hook.
|
|
@@ -1589,50 +1459,59 @@ declare class Machine<mDT> {
|
|
|
1589
1459
|
* @returns `this` for chaining.
|
|
1590
1460
|
*/
|
|
1591
1461
|
hook_action(from: string, to: string, action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1592
|
-
/**
|
|
1462
|
+
/**
|
|
1463
|
+
* Register a pre-transition hook on any edge triggered by a specific action.
|
|
1593
1464
|
* @param action - The action name to hook.
|
|
1594
1465
|
* @param handler - Callback invoked before any transition with this action.
|
|
1595
1466
|
* @returns `this` for chaining.
|
|
1596
1467
|
*/
|
|
1597
1468
|
hook_global_action(action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1598
|
-
/**
|
|
1469
|
+
/**
|
|
1470
|
+
* Register a pre-transition hook on any action-driven transition.
|
|
1599
1471
|
* @param handler - Callback invoked before any action transition.
|
|
1600
1472
|
* @returns `this` for chaining.
|
|
1601
1473
|
*/
|
|
1602
1474
|
hook_any_action(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1603
|
-
/**
|
|
1475
|
+
/**
|
|
1476
|
+
* Register a pre-transition hook on any standard (`->`) transition.
|
|
1604
1477
|
* @param handler - Callback invoked before any legal transition.
|
|
1605
1478
|
* @returns `this` for chaining.
|
|
1606
1479
|
*/
|
|
1607
1480
|
hook_standard_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1608
|
-
/**
|
|
1481
|
+
/**
|
|
1482
|
+
* Register a pre-transition hook on any main-path (`=>`) transition.
|
|
1609
1483
|
* @param handler - Callback invoked before any main transition.
|
|
1610
1484
|
* @returns `this` for chaining.
|
|
1611
1485
|
*/
|
|
1612
1486
|
hook_main_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1613
|
-
/**
|
|
1487
|
+
/**
|
|
1488
|
+
* Register a pre-transition hook on any forced (`~>`) transition.
|
|
1614
1489
|
* @param handler - Callback invoked before any forced transition.
|
|
1615
1490
|
* @returns `this` for chaining.
|
|
1616
1491
|
*/
|
|
1617
1492
|
hook_forced_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1618
|
-
/**
|
|
1493
|
+
/**
|
|
1494
|
+
* Register a pre-transition hook on any transition regardless of kind.
|
|
1619
1495
|
* @param handler - Callback invoked before every transition.
|
|
1620
1496
|
* @returns `this` for chaining.
|
|
1621
1497
|
*/
|
|
1622
1498
|
hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1623
|
-
/**
|
|
1499
|
+
/**
|
|
1500
|
+
* Register a hook that fires when entering a specific state.
|
|
1624
1501
|
* @param to - The state being entered.
|
|
1625
1502
|
* @param handler - Callback invoked on entry.
|
|
1626
1503
|
* @returns `this` for chaining.
|
|
1627
1504
|
*/
|
|
1628
1505
|
hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1629
|
-
/**
|
|
1506
|
+
/**
|
|
1507
|
+
* Register a hook that fires when leaving a specific state.
|
|
1630
1508
|
* @param from - The state being exited.
|
|
1631
1509
|
* @param handler - Callback invoked on exit.
|
|
1632
1510
|
* @returns `this` for chaining.
|
|
1633
1511
|
*/
|
|
1634
1512
|
hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1635
|
-
/**
|
|
1513
|
+
/**
|
|
1514
|
+
* Register a hook that fires when a state's `after` timer elapses — the
|
|
1636
1515
|
* delay-over companion to `a after 5s -> b;` style time transitions. It
|
|
1637
1516
|
* does NOT fire when the state is entered or left by ordinary dispatch;
|
|
1638
1517
|
* use {@link hook_entry} / {@link hook_exit} for those. (Versions through
|
|
@@ -1643,7 +1522,6 @@ declare class Machine<mDT> {
|
|
|
1643
1522
|
* timed transition is taken; informational — its outcome
|
|
1644
1523
|
* cannot reject the transition.
|
|
1645
1524
|
* @returns `this` for chaining.
|
|
1646
|
-
*
|
|
1647
1525
|
* @example
|
|
1648
1526
|
* const m = sm`a after 1000 -> b; a -> c; c -> a;`;
|
|
1649
1527
|
* let calls = 0;
|
|
@@ -1653,13 +1531,13 @@ declare class Machine<mDT> {
|
|
|
1653
1531
|
* // ordinary dispatch never fires it; only the timer elapsing does:
|
|
1654
1532
|
* calls; // => 0
|
|
1655
1533
|
* m.clear_state_timeout();
|
|
1656
|
-
*
|
|
1657
1534
|
* @see hook_entry
|
|
1658
1535
|
* @see hook_exit
|
|
1659
1536
|
* @see set_state_timeout
|
|
1660
1537
|
*/
|
|
1661
1538
|
hook_after(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1662
|
-
/**
|
|
1539
|
+
/**
|
|
1540
|
+
* Register a hook that fires when ANY state's `after` timer elapses — the
|
|
1663
1541
|
* whole-machine companion to {@link hook_after}, mirroring how
|
|
1664
1542
|
* {@link hook_any_transition} companions {@link hook}. When the elapsing
|
|
1665
1543
|
* state also has a specific {@link hook_after}, the specific hook fires
|
|
@@ -1670,7 +1548,6 @@ declare class Machine<mDT> {
|
|
|
1670
1548
|
* @param handler - Callback invoked whenever any `after` timer fires, just
|
|
1671
1549
|
* before the timed transition is taken.
|
|
1672
1550
|
* @returns `this` for chaining.
|
|
1673
|
-
*
|
|
1674
1551
|
* @example
|
|
1675
1552
|
* const m = sm`a after 1000 -> b; a -> c; c -> a;`;
|
|
1676
1553
|
* let calls = 0;
|
|
@@ -1680,13 +1557,13 @@ declare class Machine<mDT> {
|
|
|
1680
1557
|
* // ordinary dispatch never fires it; only a timer elapsing does:
|
|
1681
1558
|
* calls; // => 0
|
|
1682
1559
|
* m.clear_state_timeout();
|
|
1683
|
-
*
|
|
1684
1560
|
* @see hook_after
|
|
1685
1561
|
* @see hook_any_transition
|
|
1686
1562
|
* @see set_state_timeout
|
|
1687
1563
|
*/
|
|
1688
1564
|
hook_after_any(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1689
|
-
/**
|
|
1565
|
+
/**
|
|
1566
|
+
* Post-transition hook on a specific edge. Fires after the transition
|
|
1690
1567
|
* from `from` to `to` has completed. Cannot block the transition.
|
|
1691
1568
|
* @param from - Source state name.
|
|
1692
1569
|
* @param to - Target state name.
|
|
@@ -1694,7 +1571,8 @@ declare class Machine<mDT> {
|
|
|
1694
1571
|
* @returns `this` for chaining.
|
|
1695
1572
|
*/
|
|
1696
1573
|
post_hook(from: string, to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1697
|
-
/**
|
|
1574
|
+
/**
|
|
1575
|
+
* Post-transition hook on a specific action-labeled edge.
|
|
1698
1576
|
* @param from - Source state name.
|
|
1699
1577
|
* @param to - Target state name.
|
|
1700
1578
|
* @param action - The action label.
|
|
@@ -1702,50 +1580,59 @@ declare class Machine<mDT> {
|
|
|
1702
1580
|
* @returns `this` for chaining.
|
|
1703
1581
|
*/
|
|
1704
1582
|
post_hook_action(from: string, to: string, action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1705
|
-
/**
|
|
1583
|
+
/**
|
|
1584
|
+
* Post-transition hook on any edge triggered by a specific action.
|
|
1706
1585
|
* @param action - The action name.
|
|
1707
1586
|
* @param handler - Callback invoked after any transition with this action.
|
|
1708
1587
|
* @returns `this` for chaining.
|
|
1709
1588
|
*/
|
|
1710
1589
|
post_hook_global_action(action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1711
|
-
/**
|
|
1590
|
+
/**
|
|
1591
|
+
* Post-transition hook on any action-driven transition.
|
|
1712
1592
|
* @param handler - Callback invoked after any action transition.
|
|
1713
1593
|
* @returns `this` for chaining.
|
|
1714
1594
|
*/
|
|
1715
1595
|
post_hook_any_action(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1716
|
-
/**
|
|
1596
|
+
/**
|
|
1597
|
+
* Post-transition hook on any standard (`->`) transition.
|
|
1717
1598
|
* @param handler - Callback invoked after any legal transition.
|
|
1718
1599
|
* @returns `this` for chaining.
|
|
1719
1600
|
*/
|
|
1720
1601
|
post_hook_standard_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1721
|
-
/**
|
|
1602
|
+
/**
|
|
1603
|
+
* Post-transition hook on any main-path (`=>`) transition.
|
|
1722
1604
|
* @param handler - Callback invoked after any main transition.
|
|
1723
1605
|
* @returns `this` for chaining.
|
|
1724
1606
|
*/
|
|
1725
1607
|
post_hook_main_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1726
|
-
/**
|
|
1608
|
+
/**
|
|
1609
|
+
* Post-transition hook on any forced (`~>`) transition.
|
|
1727
1610
|
* @param handler - Callback invoked after any forced transition.
|
|
1728
1611
|
* @returns `this` for chaining.
|
|
1729
1612
|
*/
|
|
1730
1613
|
post_hook_forced_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1731
|
-
/**
|
|
1614
|
+
/**
|
|
1615
|
+
* Post-transition hook on any transition regardless of kind.
|
|
1732
1616
|
* @param handler - Callback invoked after every transition.
|
|
1733
1617
|
* @returns `this` for chaining.
|
|
1734
1618
|
*/
|
|
1735
1619
|
post_hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1736
|
-
/**
|
|
1620
|
+
/**
|
|
1621
|
+
* Post-transition hook that fires after entering a specific state.
|
|
1737
1622
|
* @param to - The state that was entered.
|
|
1738
1623
|
* @param handler - Callback invoked after entry.
|
|
1739
1624
|
* @returns `this` for chaining.
|
|
1740
1625
|
*/
|
|
1741
1626
|
post_hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1742
|
-
/**
|
|
1627
|
+
/**
|
|
1628
|
+
* Post-transition hook that fires after leaving a specific state.
|
|
1743
1629
|
* @param from - The state that was exited.
|
|
1744
1630
|
* @param handler - Callback invoked after exit.
|
|
1745
1631
|
* @returns `this` for chaining.
|
|
1746
1632
|
*/
|
|
1747
1633
|
post_hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1748
|
-
/**
|
|
1634
|
+
/**
|
|
1635
|
+
* Register a pre-transition hook that fires **before** all other pre-hooks
|
|
1749
1636
|
* on every transition. If the handler returns `false`, the transition is
|
|
1750
1637
|
* blocked. The handler receives an {@link EverythingHookContext} whose
|
|
1751
1638
|
* `hook_name` is `'pre everything'`.
|
|
@@ -1757,12 +1644,12 @@ declare class Machine<mDT> {
|
|
|
1757
1644
|
* return true;
|
|
1758
1645
|
* });
|
|
1759
1646
|
* ```
|
|
1760
|
-
*
|
|
1761
1647
|
* @param handler - Callback invoked before all other pre-hooks.
|
|
1762
1648
|
* @returns `this` for chaining.
|
|
1763
1649
|
*/
|
|
1764
1650
|
hook_pre_everything(handler: EverythingHookHandler<mDT>): Machine<mDT>;
|
|
1765
|
-
/**
|
|
1651
|
+
/**
|
|
1652
|
+
* Register a pre-transition hook that fires **after** all other pre-hooks
|
|
1766
1653
|
* on every transition. If the handler returns `false`, the transition is
|
|
1767
1654
|
* blocked. The handler receives an {@link EverythingHookContext} whose
|
|
1768
1655
|
* `hook_name` is `'everything'`.
|
|
@@ -1774,12 +1661,12 @@ declare class Machine<mDT> {
|
|
|
1774
1661
|
* return true;
|
|
1775
1662
|
* });
|
|
1776
1663
|
* ```
|
|
1777
|
-
*
|
|
1778
1664
|
* @param handler - Callback invoked after all other pre-hooks.
|
|
1779
1665
|
* @returns `this` for chaining.
|
|
1780
1666
|
*/
|
|
1781
1667
|
hook_everything(handler: EverythingHookHandler<mDT>): Machine<mDT>;
|
|
1782
|
-
/**
|
|
1668
|
+
/**
|
|
1669
|
+
* Register a post-transition hook that fires **after** all other
|
|
1783
1670
|
* post-hooks on every transition. Cannot block the transition. The
|
|
1784
1671
|
* handler receives an {@link EverythingHookContext} whose `hook_name` is
|
|
1785
1672
|
* `'post everything'`.
|
|
@@ -1790,12 +1677,12 @@ declare class Machine<mDT> {
|
|
|
1790
1677
|
* console.log(`${hook_name} fired`);
|
|
1791
1678
|
* });
|
|
1792
1679
|
* ```
|
|
1793
|
-
*
|
|
1794
1680
|
* @param handler - Callback invoked after all other post-hooks.
|
|
1795
1681
|
* @returns `this` for chaining.
|
|
1796
1682
|
*/
|
|
1797
1683
|
hook_post_everything(handler: PostEverythingHookHandler<mDT>): Machine<mDT>;
|
|
1798
|
-
/**
|
|
1684
|
+
/**
|
|
1685
|
+
* Register a post-transition hook that fires **before** all other
|
|
1799
1686
|
* post-hooks on every transition. Cannot block the transition. The
|
|
1800
1687
|
* handler receives an {@link EverythingHookContext} whose `hook_name` is
|
|
1801
1688
|
* `'pre post everything'`.
|
|
@@ -1806,22 +1693,24 @@ declare class Machine<mDT> {
|
|
|
1806
1693
|
* console.log(`${hook_name} fired`);
|
|
1807
1694
|
* });
|
|
1808
1695
|
* ```
|
|
1809
|
-
*
|
|
1810
1696
|
* @param handler - Callback invoked before all other post-hooks.
|
|
1811
1697
|
* @returns `this` for chaining.
|
|
1812
1698
|
*/
|
|
1813
1699
|
hook_pre_post_everything(handler: PostEverythingHookHandler<mDT>): Machine<mDT>;
|
|
1814
|
-
/**
|
|
1700
|
+
/**
|
|
1701
|
+
* Get the current RNG seed used for probabilistic transitions.
|
|
1815
1702
|
* @returns The numeric seed value.
|
|
1816
1703
|
*/
|
|
1817
1704
|
get rng_seed(): number;
|
|
1818
|
-
/**
|
|
1705
|
+
/**
|
|
1706
|
+
* Set the RNG seed. Pass `undefined` to reseed from the current time.
|
|
1819
1707
|
* Resets the internal PRNG so subsequent probabilistic operations use the
|
|
1820
1708
|
* new seed.
|
|
1821
1709
|
* @param to - The seed value, or `undefined` for time-based seeding.
|
|
1822
1710
|
*/
|
|
1823
1711
|
set rng_seed(to: number | undefined);
|
|
1824
|
-
/**
|
|
1712
|
+
/**
|
|
1713
|
+
* Get all edges between two states (there can be multiple with
|
|
1825
1714
|
* different actions).
|
|
1826
1715
|
* @param from - Source state name.
|
|
1827
1716
|
* @param to - Target state name.
|
|
@@ -1863,82 +1752,7 @@ declare class Machine<mDT> {
|
|
|
1863
1752
|
* @see set_data
|
|
1864
1753
|
*
|
|
1865
1754
|
*/
|
|
1866
|
-
override(newState: StateType, newData?: mDT
|
|
1867
|
-
/*********
|
|
1868
|
-
*
|
|
1869
|
-
* Fire a `'rejection'` event caused by a hook vetoing a pending transition.
|
|
1870
|
-
* Extracted from the per-call closures inside {@link transition_impl} so
|
|
1871
|
-
* that it is allocated once at class-definition time rather than on every
|
|
1872
|
-
* hooked transition.
|
|
1873
|
-
*
|
|
1874
|
-
* @param hook_name Name of the hook that rejected (e.g. `'exit'`).
|
|
1875
|
-
* @param fromState State the machine was in when the transition was
|
|
1876
|
-
* attempted; used as the `from` field of the rejection event.
|
|
1877
|
-
* @param newState State that would have been entered had the hook
|
|
1878
|
-
* passed; used as the `to` field of the rejection event.
|
|
1879
|
-
* @param fromAction Action name when the transition was initiated by an
|
|
1880
|
-
* action call; `undefined` for plain state transitions.
|
|
1881
|
-
* @param oldData Machine data at the moment the transition was
|
|
1882
|
-
* attempted, before any hook mutations.
|
|
1883
|
-
* @param newData The `next_data` value passed to the transition call.
|
|
1884
|
-
* @param wasForced Whether the transition was attempted via
|
|
1885
|
-
* `force_transition`.
|
|
1886
|
-
*
|
|
1887
|
-
* @see transition_impl
|
|
1888
|
-
* @see _fire
|
|
1889
|
-
*
|
|
1890
|
-
* @internal
|
|
1891
|
-
*
|
|
1892
|
-
*/
|
|
1893
|
-
_fire_hook_rejection(hook_name: string, fromState: StateType, newState: StateType, fromAction: StateType | undefined, oldData: mDT, newData: mDT | undefined, wasForced: boolean): void;
|
|
1894
|
-
/*********
|
|
1895
|
-
*
|
|
1896
|
-
* Fire the FSL boundary-hook actions for a single, already-committed state
|
|
1897
|
-
* change. In FSL, `do` is a synonym for `action`, so `on enter &g do 'X';`
|
|
1898
|
-
* means "when the machine crosses INTO group `g`, dispatch machine action
|
|
1899
|
-
* `X`" — and likewise `on exit` / plain-state subjects. This is the runtime
|
|
1900
|
-
* that fires those parked hooks.
|
|
1901
|
-
*
|
|
1902
|
-
* Crossing semantics (statechart convention — exits before enters):
|
|
1903
|
-
*
|
|
1904
|
-
* 1. `prev_groups` / `next_groups` are the deep (transitive) group sets of
|
|
1905
|
-
* the old and new states, from `_state_to_groups`.
|
|
1906
|
-
* 2. **Exits** fire first: every group in `prev_groups \ next_groups` with an
|
|
1907
|
-
* `onExit`, plus the plain `prev_state`'s `onExit` (when the state name
|
|
1908
|
-
* actually changed).
|
|
1909
|
-
* 3. **Enters** fire next: every group in `next_groups \ prev_groups` with an
|
|
1910
|
-
* `onEnter`, plus the plain `next_state`'s `onEnter` (when the state name
|
|
1911
|
-
* changed).
|
|
1912
|
-
* 4. A group present in BOTH sets is a transition *within* that group and
|
|
1913
|
-
* fires neither of its boundary hooks. `prev_state === next_state` fires
|
|
1914
|
-
* nothing at all.
|
|
1915
|
-
* 5. "Fire its action" is `this.action(label)`. If that action is not valid
|
|
1916
|
-
* from the current state, `action` is a safe no-op (returns `false`) — an
|
|
1917
|
-
* inapplicable boundary action never throws.
|
|
1918
|
-
* 6. Multi-membership and nesting both fan out naturally: a state in groups
|
|
1919
|
-
* A and B fires both; crossing an inner and an outer boundary fires both
|
|
1920
|
-
* levels.
|
|
1921
|
-
*
|
|
1922
|
-
* Because firing an action can drive a further transition (which crosses
|
|
1923
|
-
* more boundaries, which fires more actions), this is a bounded
|
|
1924
|
-
* run-to-completion: `_boundary_depth` tracks the live cascade depth and a
|
|
1925
|
-
* cascade deeper than `_boundary_depth_limit` throws a {@link JssmError}
|
|
1926
|
-
* rather than overflowing the stack or hanging. The limit defaults to 100
|
|
1927
|
-
* and is configurable via the `boundary_depth_limit` constructor option.
|
|
1928
|
-
*
|
|
1929
|
-
* @param prev_state The state the machine was in before this commit.
|
|
1930
|
-
* @param next_state The state the machine is in now (already committed).
|
|
1931
|
-
*
|
|
1932
|
-
* @throws {JssmError} If cascaded boundary firing exceeds `_boundary_depth_limit`
|
|
1933
|
-
* (a probable infinite loop).
|
|
1934
|
-
*
|
|
1935
|
-
* @see action
|
|
1936
|
-
* @see transition_impl
|
|
1937
|
-
*
|
|
1938
|
-
* @internal
|
|
1939
|
-
*
|
|
1940
|
-
*/
|
|
1941
|
-
_fire_boundary_actions(prev_state: StateType, next_state: StateType): void;
|
|
1755
|
+
override(newState: StateType, newData?: mDT): void;
|
|
1942
1756
|
/*********
|
|
1943
1757
|
*
|
|
1944
1758
|
* Shared transition core used by {@link transition}, {@link force_transition},
|
|
@@ -1990,7 +1804,8 @@ declare class Machine<mDT> {
|
|
|
1990
1804
|
*
|
|
1991
1805
|
*/
|
|
1992
1806
|
transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean, dataProvided?: boolean): boolean;
|
|
1993
|
-
/**
|
|
1807
|
+
/**
|
|
1808
|
+
* If the current state has an `after` timeout configured, schedule it.
|
|
1994
1809
|
* Called internally after each transition.
|
|
1995
1810
|
*/
|
|
1996
1811
|
auto_set_state_timeout(): void;
|
|
@@ -2401,94 +2216,6 @@ declare class Machine<mDT> {
|
|
|
2401
2216
|
*
|
|
2402
2217
|
*/
|
|
2403
2218
|
state_has_hooks(state: StateType): boolean;
|
|
2404
|
-
/********
|
|
2405
|
-
*
|
|
2406
|
-
* Returns the list of resolved theme implementations for this machine, in
|
|
2407
|
-
* the order they should layer (outer/base-most first). Each declared theme
|
|
2408
|
-
* name is mapped through {@link theme_mapping}; unknown names are skipped.
|
|
2409
|
-
*
|
|
2410
|
-
* The list is reversed relative to declaration order to match the historical
|
|
2411
|
-
* layering of {@link style_for}: a later-declared theme layers under an
|
|
2412
|
-
* earlier-declared one.
|
|
2413
|
-
*
|
|
2414
|
-
* @returns The resolved {@link JssmBaseTheme} stack, base-most first.
|
|
2415
|
-
*
|
|
2416
|
-
* @internal
|
|
2417
|
-
*
|
|
2418
|
-
*/
|
|
2419
|
-
_resolved_themes(): JssmBaseTheme[];
|
|
2420
|
-
/********
|
|
2421
|
-
*
|
|
2422
|
-
* Reads the condensed per-state style fields (`color`, `shape`, …) out of a
|
|
2423
|
-
* state's declaration into a fresh {@link JssmStateConfig} — the tier-5
|
|
2424
|
-
* "`state foo : { … }`" contribution of the config cascade. A state with no
|
|
2425
|
-
* declaration yields an all-`undefined` config (which contributes nothing
|
|
2426
|
-
* once folded with `merge_state_config`).
|
|
2427
|
-
*
|
|
2428
|
-
* @param state The state whose per-state declared style is wanted.
|
|
2429
|
-
*
|
|
2430
|
-
* @returns The per-state style config (fields may be `undefined`).
|
|
2431
|
-
*
|
|
2432
|
-
* @internal
|
|
2433
|
-
*
|
|
2434
|
-
*/
|
|
2435
|
-
_individual_state_config(state: StateType): JssmStateConfig;
|
|
2436
|
-
/********
|
|
2437
|
-
*
|
|
2438
|
-
* Orders the groups a state belongs to by nesting depth for the config
|
|
2439
|
-
* cascade — outermost first, innermost last — so that, folded in order,
|
|
2440
|
-
* the innermost (nearest / smallest {@link membership_distance}) group's
|
|
2441
|
-
* metadata wins. Equal-distance groups are ordered by group declaration
|
|
2442
|
-
* order, so a later-declared group of the same depth wins the tie.
|
|
2443
|
-
*
|
|
2444
|
-
* Concretely: groups are sorted by descending membership distance (largest
|
|
2445
|
-
* distance applied first / wins least), and for equal distances by
|
|
2446
|
-
* ascending declaration index (later index applied last / wins most).
|
|
2447
|
-
*
|
|
2448
|
-
* @param state The state whose containing groups are being ordered.
|
|
2449
|
-
*
|
|
2450
|
-
* @returns The containing group names, ordered for outer→inner folding
|
|
2451
|
-
* (the last entry wins).
|
|
2452
|
-
*
|
|
2453
|
-
* @internal
|
|
2454
|
-
*
|
|
2455
|
-
*/
|
|
2456
|
-
_groups_by_depth(state: StateType): string[];
|
|
2457
|
-
/********
|
|
2458
|
-
*
|
|
2459
|
-
* Folds the static tiers 1–5 of the unified config cascade for a state, plus
|
|
2460
|
-
* — when `active` is set — the active-state THEME layers, which historically
|
|
2461
|
-
* sit just below the per-state config so that a `state foo : { … }` block
|
|
2462
|
-
* still overrides a theme's `active` styling. The user `active_state : { … }`
|
|
2463
|
-
* overlay (tier 6) is NOT applied here; it is layered on top by
|
|
2464
|
-
* {@link resolve_state_config} so it wins over per-state config.
|
|
2465
|
-
*
|
|
2466
|
-
* Tiers, folded least-specific → most-specific with `merge_state_config`
|
|
2467
|
-
* (later wins, never throwing on a cross-tier key collision):
|
|
2468
|
-
*
|
|
2469
|
-
* 1. theme defaults — `base_theme.state`, then each selected theme's
|
|
2470
|
-
* `.state` block.
|
|
2471
|
-
* 2. `default_state_config` (the implicit `state : { … }` root over every
|
|
2472
|
-
* state).
|
|
2473
|
-
* 3. static per-kind defaults selected by structural kind — terminal,
|
|
2474
|
-
* then start, then end — each contributing its `base_theme.<kind>`,
|
|
2475
|
-
* selected themes' `.<kind>`, and the machine's `default_<kind>_state_config`.
|
|
2476
|
-
* When `active`, the active-state theme layers (`base_theme.active` and
|
|
2477
|
-
* each selected theme's `.active`) are folded here too.
|
|
2478
|
-
* 4. group metadata, depth-ordered outer→inner (see {@link _groups_by_depth}),
|
|
2479
|
-
* each group's RAW `{ declarations }` already condensed at construction.
|
|
2480
|
-
* 5. the per-state `state foo : { … }` config.
|
|
2481
|
-
*
|
|
2482
|
-
* @param state The state to resolve config for.
|
|
2483
|
-
* @param active Whether to include the active-state theme layers (true only
|
|
2484
|
-
* for the machine's currently-occupied state).
|
|
2485
|
-
*
|
|
2486
|
-
* @returns The composited tiers-1–5 {@link JssmStateConfig} for the state.
|
|
2487
|
-
*
|
|
2488
|
-
* @internal
|
|
2489
|
-
*
|
|
2490
|
-
*/
|
|
2491
|
-
_compose_state_config(state: StateType, active: boolean): JssmStateConfig;
|
|
2492
2219
|
/********
|
|
2493
2220
|
*
|
|
2494
2221
|
* Resolves the full unified style/config cascade for a state — the runtime
|
|
@@ -2663,76 +2390,90 @@ declare class Machine<mDT> {
|
|
|
2663
2390
|
*
|
|
2664
2391
|
*/
|
|
2665
2392
|
force_transition(newState: StateType, newData?: mDT): boolean;
|
|
2666
|
-
/**
|
|
2393
|
+
/**
|
|
2394
|
+
* Get the edge index for an action from the current state.
|
|
2667
2395
|
* Interned dispatch: resolves via the numeric (action, from) index —
|
|
2668
2396
|
* unknown action names miss without throwing.
|
|
2669
2397
|
* @param action - The action name.
|
|
2670
2398
|
* @returns The edge index, or `undefined` if the action is not available.
|
|
2671
2399
|
*/
|
|
2672
2400
|
current_action_for(action: StateType): number;
|
|
2673
|
-
/**
|
|
2401
|
+
/**
|
|
2402
|
+
* Get the full transition object for an action from the current state.
|
|
2674
2403
|
* @param action - The action name.
|
|
2675
2404
|
* @returns The {@link JssmTransition} object.
|
|
2676
2405
|
* @throws {JssmError} If the action is not available from the current state.
|
|
2677
2406
|
*/
|
|
2678
2407
|
current_action_edge_for(action: StateType): JssmTransition<StateType, mDT>;
|
|
2679
|
-
/**
|
|
2408
|
+
/**
|
|
2409
|
+
* Check whether an action is available from the current state.
|
|
2680
2410
|
* @param action - The action name to check.
|
|
2681
2411
|
* @param _newData - Reserved for future data validation.
|
|
2682
2412
|
* @returns `true` if the action can be taken.
|
|
2683
2413
|
*/
|
|
2684
2414
|
valid_action(action: StateType, _newData?: mDT): boolean;
|
|
2685
|
-
/**
|
|
2415
|
+
/**
|
|
2416
|
+
* Check whether a transition to a given state is legal (non-forced) from
|
|
2686
2417
|
* the current state.
|
|
2687
2418
|
* @param newState - The target state.
|
|
2688
2419
|
* @param _newData - Reserved for future data validation.
|
|
2689
2420
|
* @returns `true` if the transition is legal.
|
|
2690
2421
|
*/
|
|
2691
2422
|
valid_transition(newState: StateType, _newData?: mDT): boolean;
|
|
2692
|
-
/**
|
|
2423
|
+
/**
|
|
2424
|
+
* Check whether a forced transition to a given state exists from the
|
|
2693
2425
|
* current state.
|
|
2694
2426
|
* @param newState - The target state.
|
|
2695
2427
|
* @param _newData - Reserved for future data validation.
|
|
2696
2428
|
* @returns `true` if a forced (or any) transition exists.
|
|
2697
2429
|
*/
|
|
2698
2430
|
valid_force_transition(newState: StateType, _newData?: mDT): boolean;
|
|
2699
|
-
/**
|
|
2431
|
+
/**
|
|
2432
|
+
* Get the instance name of this machine, if one was assigned at creation.
|
|
2700
2433
|
* @returns The instance name string, or `undefined`.
|
|
2701
2434
|
*/
|
|
2702
2435
|
instance_name(): string | undefined;
|
|
2703
|
-
/**
|
|
2436
|
+
/**
|
|
2437
|
+
* Get the creation date of this machine as a `Date` object.
|
|
2704
2438
|
* @returns A `Date` representing when the machine was created.
|
|
2705
2439
|
*/
|
|
2706
2440
|
get creation_date(): Date;
|
|
2707
|
-
/**
|
|
2441
|
+
/**
|
|
2442
|
+
* Get the creation timestamp (milliseconds since epoch).
|
|
2708
2443
|
* @returns The timestamp as a number.
|
|
2709
2444
|
*/
|
|
2710
2445
|
get creation_timestamp(): number;
|
|
2711
|
-
/**
|
|
2446
|
+
/**
|
|
2447
|
+
* Get the timestamp when construction began (before parsing).
|
|
2712
2448
|
* @returns The start-of-construction timestamp as a number.
|
|
2713
2449
|
*/
|
|
2714
2450
|
get create_start_time(): number;
|
|
2715
|
-
/**
|
|
2451
|
+
/**
|
|
2452
|
+
* Schedule an automatic transition to `next_state` after `after_time`
|
|
2716
2453
|
* milliseconds. Only one timeout may be active at a time.
|
|
2717
2454
|
* @param next_state - The state to transition to when the timer fires.
|
|
2718
2455
|
* @param after_time - Delay in milliseconds.
|
|
2719
2456
|
* @throws {JssmError} If a timeout is already pending.
|
|
2720
2457
|
*/
|
|
2721
2458
|
set_state_timeout(next_state: StateType, after_time: number): void;
|
|
2722
|
-
/**
|
|
2459
|
+
/**
|
|
2460
|
+
Cancel any pending state timeout. Safe to call when no timeout is active.
|
|
2723
2461
|
*/
|
|
2724
2462
|
clear_state_timeout(): void;
|
|
2725
|
-
/**
|
|
2463
|
+
/**
|
|
2464
|
+
* Get the configured `after` timeout for a given state, if any.
|
|
2726
2465
|
* @param which_state - The state to look up.
|
|
2727
2466
|
* @returns A `[targetState, delayMs]` tuple, or `undefined` if no timeout
|
|
2728
2467
|
* is configured for that state.
|
|
2729
2468
|
*/
|
|
2730
2469
|
state_timeout_for(which_state: StateType): [StateType, number] | undefined;
|
|
2731
|
-
/**
|
|
2470
|
+
/**
|
|
2471
|
+
* Get the configured `after` timeout for the current state, if any.
|
|
2732
2472
|
* @returns A `[targetState, delayMs]` tuple, or `undefined`.
|
|
2733
2473
|
*/
|
|
2734
2474
|
current_state_timeout(): [StateType, number] | undefined;
|
|
2735
|
-
/**
|
|
2475
|
+
/**
|
|
2476
|
+
* Convenience method to create a new machine from a tagged template literal.
|
|
2736
2477
|
* Equivalent to calling the top-level `sm` function.
|
|
2737
2478
|
* @param template_strings - The template string array.
|
|
2738
2479
|
* @param remainder - Interpolated values.
|
|
@@ -2786,7 +2527,7 @@ declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: a
|
|
|
2786
2527
|
* @param ExtraConstructorFields Extra non-code configuration to pass at creation time
|
|
2787
2528
|
*
|
|
2788
2529
|
*/
|
|
2789
|
-
declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<StateType, mDT>>
|
|
2530
|
+
declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<StateType, mDT>>): Machine<mDT>;
|
|
2790
2531
|
/**
|
|
2791
2532
|
*
|
|
2792
2533
|
* Type guard that narrows an unknown value to a {@link HookComplexResult}.
|
|
@@ -2804,15 +2545,11 @@ declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Par
|
|
|
2804
2545
|
* is_hook_complex_result(null); // false
|
|
2805
2546
|
* is_hook_complex_result({ other: 'thing' }); // false
|
|
2806
2547
|
* ```
|
|
2807
|
-
*
|
|
2808
|
-
* @typeParam mDT The type of the machine data member; usually omitted.
|
|
2809
|
-
*
|
|
2548
|
+
* @template mDT The type of the machine data member; usually omitted.
|
|
2810
2549
|
* @param hr The value to test.
|
|
2811
|
-
*
|
|
2812
2550
|
* @returns `true` if `hr` is a non-null object with a boolean `pass` field;
|
|
2813
2551
|
* `false` otherwise. When `true`, TypeScript narrows `hr` to
|
|
2814
2552
|
* `HookComplexResult<mDT>`.
|
|
2815
|
-
*
|
|
2816
2553
|
*/
|
|
2817
2554
|
declare function is_hook_complex_result<mDT>(hr: unknown): hr is HookComplexResult<mDT>;
|
|
2818
2555
|
/**
|
|
@@ -2833,16 +2570,11 @@ declare function is_hook_complex_result<mDT>(hr: unknown): hr is HookComplexResu
|
|
|
2833
2570
|
* is_hook_rejection({ pass: true }); // false (pass)
|
|
2834
2571
|
* is_hook_rejection({ pass: false }); // true (reject)
|
|
2835
2572
|
* ```
|
|
2836
|
-
*
|
|
2837
|
-
* @typeParam mDT The type of the machine data member; usually omitted.
|
|
2838
|
-
*
|
|
2573
|
+
* @template mDT The type of the machine data member; usually omitted.
|
|
2839
2574
|
* @param hr A hook result of any legal shape.
|
|
2840
|
-
*
|
|
2841
2575
|
* @returns `true` if the hook rejected the transition; `false` if it passed.
|
|
2842
|
-
*
|
|
2843
2576
|
* @throws {TypeError} If `hr` is not a recognized hook result shape (for
|
|
2844
2577
|
* example, a number or a plain object without a `pass` field).
|
|
2845
|
-
*
|
|
2846
2578
|
*/
|
|
2847
2579
|
declare function is_hook_rejection<mDT>(hr: HookResult<mDT>): boolean;
|
|
2848
2580
|
/**
|
|
@@ -2863,24 +2595,17 @@ declare function is_hook_rejection<mDT>(hr: HookResult<mDT>): boolean;
|
|
|
2863
2595
|
* - a complex result object → returned as-is
|
|
2864
2596
|
*
|
|
2865
2597
|
* Anything else is a programmer error and throws.
|
|
2866
|
-
*
|
|
2867
|
-
* @typeParam mDT The type of the machine data member; usually omitted.
|
|
2868
|
-
*
|
|
2598
|
+
* @template mDT The type of the machine data member; usually omitted.
|
|
2869
2599
|
* @param maybe_hook The hook handler to call, or `undefined` for the
|
|
2870
2600
|
* "no hook installed" case.
|
|
2871
|
-
*
|
|
2872
2601
|
* @param hook_args The context object passed to the hook. Includes the
|
|
2873
2602
|
* current and proposed state, current and proposed data, action name, and
|
|
2874
2603
|
* transition kind.
|
|
2875
|
-
*
|
|
2876
2604
|
* @returns A {@link HookComplexResult} describing whether the hook passed
|
|
2877
2605
|
* and, optionally, any data replacements it requested.
|
|
2878
|
-
*
|
|
2879
2606
|
* @throws {TypeError} If the hook returns a value that is not one of the
|
|
2880
2607
|
* legal shapes listed above.
|
|
2881
|
-
*
|
|
2882
2608
|
* @internal
|
|
2883
|
-
*
|
|
2884
2609
|
*/
|
|
2885
2610
|
declare function abstract_hook_step<mDT>(maybe_hook: HookHandler<mDT> | undefined, hook_args: HookContext<mDT>): HookComplexResult<mDT>;
|
|
2886
2611
|
/**
|
|
@@ -2900,22 +2625,15 @@ declare function abstract_hook_step<mDT>(maybe_hook: HookHandler<mDT> | undefine
|
|
|
2900
2625
|
* - `undefined` or `true` → `{ pass: true }`
|
|
2901
2626
|
* - `false` or `null` → `{ pass: false }`
|
|
2902
2627
|
* - a complex result → returned as-is
|
|
2903
|
-
*
|
|
2904
|
-
* @typeParam mDT The type of the machine data member; usually omitted.
|
|
2905
|
-
*
|
|
2628
|
+
* @template mDT The type of the machine data member; usually omitted.
|
|
2906
2629
|
* @param maybe_hook The everything-hook handler, or `undefined` when none
|
|
2907
2630
|
* is installed.
|
|
2908
|
-
*
|
|
2909
2631
|
* @param hook_args The everything-hook context object. Differs from a
|
|
2910
2632
|
* normal hook context in that it also includes `hook_name`.
|
|
2911
|
-
*
|
|
2912
2633
|
* @returns A {@link HookComplexResult} describing whether the hook passed
|
|
2913
2634
|
* and any data replacements it requested.
|
|
2914
|
-
*
|
|
2915
2635
|
* @throws {TypeError} If the hook returns a value outside the legal shapes.
|
|
2916
|
-
*
|
|
2917
2636
|
* @internal
|
|
2918
|
-
*
|
|
2919
2637
|
*/
|
|
2920
2638
|
declare function abstract_everything_hook_step<mDT>(maybe_hook: EverythingHookHandler<mDT> | undefined, hook_args: EverythingHookContext<mDT>): HookComplexResult<mDT>;
|
|
2921
2639
|
/**
|
|
@@ -2928,32 +2646,24 @@ declare function abstract_everything_hook_step<mDT>(maybe_hook: EverythingHookHa
|
|
|
2928
2646
|
* numeric identifiers numerically and below alphanumeric ones, alphanumeric
|
|
2929
2647
|
* identifiers in ASCII order, and a shorter identifier set precedes a longer
|
|
2930
2648
|
* one that it prefixes.
|
|
2931
|
-
*
|
|
2932
2649
|
* @param {string} v1 - First version string (e.g., "5.104.2" or "6.0.0-alpha.1")
|
|
2933
2650
|
* @param {string} v2 - Second version string (e.g., "5.103.1")
|
|
2934
|
-
*
|
|
2935
2651
|
* @returns {number} - Negative if v1 < v2, 0 if equal, positive if v1 > v2
|
|
2936
|
-
*
|
|
2937
2652
|
* @example
|
|
2938
2653
|
* import { compareVersions } from 'jssm';
|
|
2939
2654
|
* compareVersions("5.104.2", "5.103.1"); // => 1
|
|
2940
|
-
*
|
|
2941
2655
|
* @example
|
|
2942
2656
|
* import { compareVersions } from 'jssm';
|
|
2943
2657
|
* compareVersions("5.104.2", "6.0.0"); // => -1
|
|
2944
|
-
*
|
|
2945
2658
|
* @example
|
|
2946
2659
|
* import { compareVersions } from 'jssm';
|
|
2947
2660
|
* compareVersions("5.104.2", "5.104.2"); // => 0
|
|
2948
|
-
*
|
|
2949
2661
|
* @example
|
|
2950
2662
|
* import { compareVersions } from 'jssm';
|
|
2951
2663
|
* compareVersions("6.0.0-alpha.1", "6.0.0"); // => -1
|
|
2952
|
-
*
|
|
2953
2664
|
* @example
|
|
2954
2665
|
* import { compareVersions } from 'jssm';
|
|
2955
2666
|
* compareVersions("6.0.0-alpha.1", "6.0.0-alpha.2"); // => -1
|
|
2956
|
-
*
|
|
2957
2667
|
* @example
|
|
2958
2668
|
* import { compareVersions } from 'jssm';
|
|
2959
2669
|
* compareVersions("6.0.0-beta.1", "6.0.0-alpha.1"); // => 1
|
|
@@ -2965,16 +2675,11 @@ declare function compareVersions(v1: string, v2: string): number;
|
|
|
2965
2675
|
* This function recreates a machine from a serialization object, restoring its
|
|
2966
2676
|
* state, data, and history. For security and compatibility reasons, it will
|
|
2967
2677
|
* refuse to deserialize data from future versions of the library.
|
|
2968
|
-
*
|
|
2969
|
-
* @typeParam mDT - The type of the machine data member
|
|
2970
|
-
*
|
|
2678
|
+
* @template mDT - The type of the machine data member
|
|
2971
2679
|
* @param {string} machine_string - The FSL string defining the machine structure
|
|
2972
2680
|
* @param {JssmSerialization<mDT>} ser - The serialization object to restore from
|
|
2973
|
-
*
|
|
2974
2681
|
* @returns {Machine<mDT>} - The restored machine instance
|
|
2975
|
-
*
|
|
2976
2682
|
* @throws {Error} If the serialization is from a future version
|
|
2977
|
-
*
|
|
2978
2683
|
* @example
|
|
2979
2684
|
* import { from, deserialize } from 'jssm';
|
|
2980
2685
|
* const machine = from("a -> b;");
|
|
@@ -2983,6 +2688,12 @@ declare function compareVersions(v1: string, v2: string): number;
|
|
|
2983
2688
|
* restored.state(); // => 'a'
|
|
2984
2689
|
*/
|
|
2985
2690
|
declare function deserialize<mDT>(machine_string: string, ser: JssmSerialization<mDT>): Machine<mDT>;
|
|
2986
|
-
export {
|
|
2691
|
+
export { transfer_state_properties, Machine, deserialize, compareVersions, sm, from, shapes, gviz_shapes, named_colors, state_name_chars, state_name_first_chars, action_label_chars, is_hook_rejection, is_hook_complex_result, abstract_hook_step, abstract_everything_hook_step, state_style_condense, };
|
|
2987
2692
|
export { fsl_fence_lang, parse_fence_info } from './fsl_markdown_fence';
|
|
2988
2693
|
export type { FencePart, FenceImageFormat, FenceDimensionUnit, FenceDimension, FenceDescriptor } from './fsl_markdown_fence';
|
|
2694
|
+
export { FslDirections } from './jssm_types.js';
|
|
2695
|
+
export { arrow_direction, arrow_left_kind, arrow_right_kind } from './jssm_arrow.js';
|
|
2696
|
+
export { compile, wrap_parse as parse, make } from './jssm_compiler.js';
|
|
2697
|
+
export { unique, find_repeated, weighted_sample_select, weighted_histo_key, sleep, seq, weighted_rand_select, histograph, gen_splitmix32 } from './jssm_util.js';
|
|
2698
|
+
export { build_time, version } from './version.js';
|
|
2699
|
+
export * as constants from './jssm_constants.js';
|