jssm 5.104.2 → 5.112.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +17 -6
- package/.log-progress.json +9 -0
- package/CHANGELOG.md +130 -45
- package/CLAUDE.md +11 -0
- package/MIGRATING-jssm-viz.md +67 -0
- package/README.md +179 -882
- package/dist/es6/fsl_parser.js +1 -1
- package/dist/es6/jssm.d.ts +773 -39
- package/dist/es6/jssm.js +921 -89
- package/dist/es6/jssm_arrow.js +24 -0
- package/dist/es6/jssm_compiler.d.ts +17 -2
- package/dist/es6/jssm_compiler.js +17 -3
- package/dist/es6/jssm_constants.d.ts +27 -0
- package/dist/es6/jssm_constants.js +27 -0
- package/dist/es6/jssm_error.d.ts +19 -0
- package/dist/es6/jssm_error.js +19 -0
- package/dist/es6/jssm_theme.d.ts +11 -0
- package/dist/es6/jssm_theme.js +11 -0
- package/dist/es6/jssm_types.d.ts +29 -3
- package/dist/es6/jssm_util.d.ts +161 -9
- package/dist/es6/jssm_util.js +174 -17
- package/dist/es6/jssm_viz.d.ts +175 -0
- package/dist/es6/jssm_viz.js +560 -0
- package/dist/es6/jssm_viz_colors.d.ts +63 -0
- package/dist/es6/jssm_viz_colors.js +63 -0
- package/dist/es6/version.js +1 -1
- package/dist/jssm.es5.cjs +1 -1
- package/dist/jssm.es5.iife.js +1 -0
- package/dist/jssm.es5.nonmin.cjs +2201 -870
- package/dist/jssm.es6.mjs +1 -1
- package/dist/jssm.es6.nonmin.cjs +2200 -871
- package/dist/jssm_viz.cjs +1 -0
- package/dist/{jssm.es5.iife.nonmin.cjs → jssm_viz.es5.iife.nonmin.cjs} +2589 -1090
- package/dist/jssm_viz.es5.nonmin.cjs +24674 -0
- package/dist/jssm_viz.es6.nonmin.cjs +24661 -0
- package/dist/jssm_viz.iife.cjs +1 -0
- package/dist/jssm_viz.mjs +1 -0
- package/jest-dragon.config.cjs +4 -1
- package/jest-spec.config.cjs +9 -6
- package/jest-stoch.config.cjs +4 -1
- package/jest-unicode.config.cjs +4 -1
- package/jssm.es5.d.cts +950 -41
- package/jssm.es6.d.ts +950 -41
- package/jssm_viz.es5.d.cts +2127 -0
- package/jssm_viz.es6.d.ts +2127 -0
- package/log-progress.data.json +28 -0
- package/package.json +56 -23
- package/rollup.config.viz.es5.js +46 -0
- package/rollup.config.viz.es6.js +46 -0
- package/rollup.config.viz.iife.js +36 -0
- package/typedoc-options.cjs +4 -3
- package/dist/jssm.es5.iife.cjs +0 -1
- package/fsl_parser.d.ts +0 -6
- package/jssm.d.ts +0 -1141
- package/jssm_arrow.d.ts +0 -53
- package/jssm_compiler.d.ts +0 -135
- package/jssm_constants.d.ts +0 -5
- package/jssm_error.d.ts +0 -8
- package/jssm_theme.d.ts +0 -4
- package/jssm_types.d.ts +0 -378
- package/jssm_util.d.ts +0 -106
- package/version.d.ts +0 -2
package/dist/es6/jssm_arrow.js
CHANGED
|
@@ -99,8 +99,12 @@ function arrow_left_kind(arrow) {
|
|
|
99
99
|
case '↔':
|
|
100
100
|
case '<-=>':
|
|
101
101
|
case '←⇒':
|
|
102
|
+
case '←=>':
|
|
103
|
+
case '<-⇒':
|
|
102
104
|
case '<-~>':
|
|
103
105
|
case '←↛':
|
|
106
|
+
case '←~>':
|
|
107
|
+
case '<-↛':
|
|
104
108
|
return 'legal';
|
|
105
109
|
case '<=':
|
|
106
110
|
case '⇐':
|
|
@@ -108,8 +112,12 @@ function arrow_left_kind(arrow) {
|
|
|
108
112
|
case '⇔':
|
|
109
113
|
case '<=->':
|
|
110
114
|
case '⇐→':
|
|
115
|
+
case '⇐->':
|
|
116
|
+
case '<=→':
|
|
111
117
|
case '<=~>':
|
|
112
118
|
case '⇐↛':
|
|
119
|
+
case '⇐~>':
|
|
120
|
+
case '<=↛':
|
|
113
121
|
return 'main';
|
|
114
122
|
case '<~':
|
|
115
123
|
case '↚':
|
|
@@ -117,8 +125,12 @@ function arrow_left_kind(arrow) {
|
|
|
117
125
|
case '↮':
|
|
118
126
|
case '<~->':
|
|
119
127
|
case '↚→':
|
|
128
|
+
case '↚->':
|
|
129
|
+
case '<~→':
|
|
120
130
|
case '<~=>':
|
|
121
131
|
case '↚⇒':
|
|
132
|
+
case '↚=>':
|
|
133
|
+
case '<~⇒':
|
|
122
134
|
return 'forced';
|
|
123
135
|
default:
|
|
124
136
|
throw new JssmError(undefined, `arrow_direction: unknown arrow type ${arrow}`);
|
|
@@ -158,8 +170,12 @@ function arrow_right_kind(arrow) {
|
|
|
158
170
|
case '↔':
|
|
159
171
|
case '<=->':
|
|
160
172
|
case '⇐→':
|
|
173
|
+
case '⇐->':
|
|
174
|
+
case '<=→':
|
|
161
175
|
case '<~->':
|
|
162
176
|
case '↚→':
|
|
177
|
+
case '↚->':
|
|
178
|
+
case '<~→':
|
|
163
179
|
return 'legal';
|
|
164
180
|
case '=>':
|
|
165
181
|
case '⇒':
|
|
@@ -167,8 +183,12 @@ function arrow_right_kind(arrow) {
|
|
|
167
183
|
case '⇔':
|
|
168
184
|
case '<-=>':
|
|
169
185
|
case '←⇒':
|
|
186
|
+
case '←=>':
|
|
187
|
+
case '<-⇒':
|
|
170
188
|
case '<~=>':
|
|
171
189
|
case '↚⇒':
|
|
190
|
+
case '↚=>':
|
|
191
|
+
case '<~⇒':
|
|
172
192
|
return 'main';
|
|
173
193
|
case '~>':
|
|
174
194
|
case '↛':
|
|
@@ -176,8 +196,12 @@ function arrow_right_kind(arrow) {
|
|
|
176
196
|
case '↮':
|
|
177
197
|
case '<-~>':
|
|
178
198
|
case '←↛':
|
|
199
|
+
case '←~>':
|
|
200
|
+
case '<-↛':
|
|
179
201
|
case '<=~>':
|
|
180
202
|
case '⇐↛':
|
|
203
|
+
case '⇐~>':
|
|
204
|
+
case '<=↛':
|
|
181
205
|
return 'forced';
|
|
182
206
|
default:
|
|
183
207
|
throw new JssmError(undefined, `arrow_direction: unknown arrow type ${arrow}`);
|
|
@@ -2,11 +2,26 @@ import { JssmTransition, JssmCompileSe, JssmParseTree, JssmGenericConfig } from
|
|
|
2
2
|
/*********
|
|
3
3
|
*
|
|
4
4
|
* Internal method meant to perform factory assembly of an edge. Not meant for
|
|
5
|
-
* external use.
|
|
5
|
+
* external use. Constructs a {@link JssmTransition} from a parsed
|
|
6
|
+
* semi-edge (`this_se`), a source state, a target state, and directionality.
|
|
6
7
|
*
|
|
7
8
|
* @internal
|
|
8
9
|
*
|
|
9
|
-
* @typeparam
|
|
10
|
+
* @typeparam StateType The type of state names (usually `string`).
|
|
11
|
+
* @typeparam mDT The type of the machine data member; usually omitted.
|
|
12
|
+
*
|
|
13
|
+
* @param this_se - The parsed semi-edge containing kind, action, and
|
|
14
|
+
* probability metadata.
|
|
15
|
+
* @param from - The source state of the transition.
|
|
16
|
+
* @param to - The target state of the transition.
|
|
17
|
+
* @param isRight - `true` if this is a left-to-right transition, `false`
|
|
18
|
+
* for right-to-left. Determines which arrow kind
|
|
19
|
+
* extraction function is used.
|
|
20
|
+
* @param _wasList - If the transition was expanded from a list (e.g.
|
|
21
|
+
* `[A B C] -> D`), the original list of states.
|
|
22
|
+
* @param _wasIndex - The index of `from` within `_wasList`, if applicable.
|
|
23
|
+
*
|
|
24
|
+
* @returns A fully assembled {@link JssmTransition} edge object.
|
|
10
25
|
*
|
|
11
26
|
*/
|
|
12
27
|
declare function makeTransition<StateType, mDT>(this_se: JssmCompileSe<StateType, mDT>, from: StateType, to: StateType, isRight: boolean, _wasList?: Array<StateType>, _wasIndex?: number): JssmTransition<StateType, mDT>;
|
|
@@ -6,14 +6,28 @@ import { reduce as reduce_to_639 } from 'reduce-to-639-1';
|
|
|
6
6
|
/*********
|
|
7
7
|
*
|
|
8
8
|
* Internal method meant to perform factory assembly of an edge. Not meant for
|
|
9
|
-
* external use.
|
|
9
|
+
* external use. Constructs a {@link JssmTransition} from a parsed
|
|
10
|
+
* semi-edge (`this_se`), a source state, a target state, and directionality.
|
|
10
11
|
*
|
|
11
12
|
* @internal
|
|
12
13
|
*
|
|
13
|
-
* @typeparam
|
|
14
|
+
* @typeparam StateType The type of state names (usually `string`).
|
|
15
|
+
* @typeparam mDT The type of the machine data member; usually omitted.
|
|
16
|
+
*
|
|
17
|
+
* @param this_se - The parsed semi-edge containing kind, action, and
|
|
18
|
+
* probability metadata.
|
|
19
|
+
* @param from - The source state of the transition.
|
|
20
|
+
* @param to - The target state of the transition.
|
|
21
|
+
* @param isRight - `true` if this is a left-to-right transition, `false`
|
|
22
|
+
* for right-to-left. Determines which arrow kind
|
|
23
|
+
* extraction function is used.
|
|
24
|
+
* @param _wasList - If the transition was expanded from a list (e.g.
|
|
25
|
+
* `[A B C] -> D`), the original list of states.
|
|
26
|
+
* @param _wasIndex - The index of `from` within `_wasList`, if applicable.
|
|
27
|
+
*
|
|
28
|
+
* @returns A fully assembled {@link JssmTransition} edge object.
|
|
14
29
|
*
|
|
15
30
|
*/
|
|
16
|
-
// TODO add at-param to docblock
|
|
17
31
|
function makeTransition(this_se, from, to, isRight, _wasList, _wasIndex) {
|
|
18
32
|
const kind = isRight
|
|
19
33
|
? arrow_right_kind(this_se.kind)
|
|
@@ -1,5 +1,32 @@
|
|
|
1
|
+
/*******
|
|
2
|
+
*
|
|
3
|
+
* Convenience aliases for common mathematical and numeric constants from
|
|
4
|
+
* `Number` and `Math`. Re-exported so that FSL data expressions and tests
|
|
5
|
+
* can reference them without importing `Math` directly.
|
|
6
|
+
*
|
|
7
|
+
* Includes: `NegInfinity`, `PosInfinity`, `Epsilon`, `Pi`, `E`, `Root2`,
|
|
8
|
+
* `RootHalf`, `Ln2`, `Ln10`, `Log2E`, `Log10E`, `MaxSafeInt`, `MinSafeInt`,
|
|
9
|
+
* `MaxPosNum`, `MinPosNum`, `Phi` (golden ratio), `EulerC` (Euler–Mascheroni).
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
1
12
|
export declare const NegInfinity: number, PosInfinity: number, Epsilon: number, Pi: number, E: number, Root2: number, RootHalf: number, Ln2: number, Ln10: number, Log2E: number, Log10E: number, MaxSafeInt: number, MinSafeInt: number, MaxPosNum: number, MinPosNum: number, Phi = 1.618033988749895, EulerC = 0.5772156649015329;
|
|
13
|
+
/*******
|
|
14
|
+
*
|
|
15
|
+
* Complete list of node shapes supported by Graphviz. Used by jssm-viz to
|
|
16
|
+
* validate and render state shapes in FSL `state ... : { shape: ... }` blocks.
|
|
17
|
+
*
|
|
18
|
+
* `shapes` is an alias for `gviz_shapes`.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
2
21
|
declare const gviz_shapes: string[];
|
|
3
22
|
declare const shapes: string[];
|
|
23
|
+
/*******
|
|
24
|
+
*
|
|
25
|
+
* List of CSS/SVG named colors accepted by jssm-viz for state styling
|
|
26
|
+
* properties like `background-color` and `text-color`. Case-insensitive
|
|
27
|
+
* matching is done at parse time; the canonical casing here follows the
|
|
28
|
+
* CSS specification.
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
4
31
|
declare const named_colors: string[];
|
|
5
32
|
export { gviz_shapes, shapes, named_colors, };
|
|
@@ -1,4 +1,23 @@
|
|
|
1
|
+
/*******
|
|
2
|
+
*
|
|
3
|
+
* Convenience aliases for common mathematical and numeric constants from
|
|
4
|
+
* `Number` and `Math`. Re-exported so that FSL data expressions and tests
|
|
5
|
+
* can reference them without importing `Math` directly.
|
|
6
|
+
*
|
|
7
|
+
* Includes: `NegInfinity`, `PosInfinity`, `Epsilon`, `Pi`, `E`, `Root2`,
|
|
8
|
+
* `RootHalf`, `Ln2`, `Ln10`, `Log2E`, `Log10E`, `MaxSafeInt`, `MinSafeInt`,
|
|
9
|
+
* `MaxPosNum`, `MinPosNum`, `Phi` (golden ratio), `EulerC` (Euler–Mascheroni).
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
1
12
|
export const NegInfinity = Number.NEGATIVE_INFINITY, PosInfinity = Number.POSITIVE_INFINITY, Epsilon = Number.EPSILON, Pi = Math.PI, E = Math.E, Root2 = Math.SQRT2, RootHalf = Math.SQRT1_2, Ln2 = Math.LN2, Ln10 = Math.LN10, Log2E = Math.LOG2E, Log10E = Math.LOG10E, MaxSafeInt = Number.MAX_SAFE_INTEGER, MinSafeInt = Number.MIN_SAFE_INTEGER, MaxPosNum = Number.MAX_VALUE, MinPosNum = Number.MIN_VALUE, Phi = 1.61803398874989484820, EulerC = 0.57721566490153286060;
|
|
13
|
+
/*******
|
|
14
|
+
*
|
|
15
|
+
* Complete list of node shapes supported by Graphviz. Used by jssm-viz to
|
|
16
|
+
* validate and render state shapes in FSL `state ... : { shape: ... }` blocks.
|
|
17
|
+
*
|
|
18
|
+
* `shapes` is an alias for `gviz_shapes`.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
2
21
|
const gviz_shapes = [
|
|
3
22
|
"box3d",
|
|
4
23
|
"polygon",
|
|
@@ -62,6 +81,14 @@ const gviz_shapes = [
|
|
|
62
81
|
"record"
|
|
63
82
|
];
|
|
64
83
|
const shapes = gviz_shapes;
|
|
84
|
+
/*******
|
|
85
|
+
*
|
|
86
|
+
* List of CSS/SVG named colors accepted by jssm-viz for state styling
|
|
87
|
+
* properties like `background-color` and `text-color`. Case-insensitive
|
|
88
|
+
* matching is done at parse time; the canonical casing here follows the
|
|
89
|
+
* CSS specification.
|
|
90
|
+
*
|
|
91
|
+
*/
|
|
65
92
|
const named_colors = [
|
|
66
93
|
"AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige",
|
|
67
94
|
"Bisque", "Black", "BlanchedAlmond", "Blue", "BlueViolet", "Brown",
|
package/dist/es6/jssm_error.d.ts
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
import { JssmErrorExtendedInfo } from './jssm_types';
|
|
2
|
+
/*******
|
|
3
|
+
*
|
|
4
|
+
* Custom error class for jssm. Enriches the standard `Error` with
|
|
5
|
+
* machine context (current state, instance name) and an optional
|
|
6
|
+
* `requested_state` so that error messages are self-describing.
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* throw new JssmError(machine, 'no such state', { requested_state: 'Blue' });
|
|
10
|
+
* // JssmError: [[my-light]]: no such state (at "Red", requested "Blue")
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param machine - The `Machine` instance that raised the error, or
|
|
14
|
+
* `undefined` if no machine is available. Used to
|
|
15
|
+
* read `state()` and `instance_name()` for context.
|
|
16
|
+
* @param message - A human-readable description of the error.
|
|
17
|
+
* @param JEEI - Optional {@link JssmErrorExtendedInfo} with extra
|
|
18
|
+
* context such as `requested_state`.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
2
21
|
declare class JssmError extends Error {
|
|
3
22
|
message: string;
|
|
4
23
|
base_message: string;
|
package/dist/es6/jssm_error.js
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
/*******
|
|
2
|
+
*
|
|
3
|
+
* Custom error class for jssm. Enriches the standard `Error` with
|
|
4
|
+
* machine context (current state, instance name) and an optional
|
|
5
|
+
* `requested_state` so that error messages are self-describing.
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* throw new JssmError(machine, 'no such state', { requested_state: 'Blue' });
|
|
9
|
+
* // JssmError: [[my-light]]: no such state (at "Red", requested "Blue")
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @param machine - The `Machine` instance that raised the error, or
|
|
13
|
+
* `undefined` if no machine is available. Used to
|
|
14
|
+
* read `state()` and `instance_name()` for context.
|
|
15
|
+
* @param message - A human-readable description of the error.
|
|
16
|
+
* @param JEEI - Optional {@link JssmErrorExtendedInfo} with extra
|
|
17
|
+
* context such as `requested_state`.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
1
20
|
class JssmError extends Error {
|
|
2
21
|
constructor(machine, message, JEEI) {
|
|
3
22
|
const { requested_state } = (JEEI === undefined)
|
package/dist/es6/jssm_theme.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { FslTheme, JssmBaseTheme } from './jssm_types';
|
|
2
2
|
import { base_theme } from './themes/jssm_base_stylesheet';
|
|
3
|
+
/*******
|
|
4
|
+
*
|
|
5
|
+
* Registry mapping theme names to their stylesheet definitions. Each entry
|
|
6
|
+
* maps an {@link FslTheme} string (e.g. `'default'`, `'ocean'`) to a
|
|
7
|
+
* {@link JssmBaseTheme} object containing colors, shapes, and other visual
|
|
8
|
+
* defaults used by jssm-viz when rendering state machine diagrams.
|
|
9
|
+
*
|
|
10
|
+
* Add new themes by importing their definition and calling
|
|
11
|
+
* `theme_mapping.set(name, theme)`.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
3
14
|
declare const theme_mapping: Map<FslTheme, JssmBaseTheme>;
|
|
4
15
|
export { theme_mapping, base_theme };
|
package/dist/es6/jssm_theme.js
CHANGED
|
@@ -4,6 +4,17 @@ import { modern_theme } from './themes/jssm_theme_modern';
|
|
|
4
4
|
import { ocean_theme } from './themes/jssm_theme_ocean';
|
|
5
5
|
import { plain_theme } from './themes/jssm_theme_plain';
|
|
6
6
|
import { bold_theme } from './themes/jssm_theme_bold';
|
|
7
|
+
/*******
|
|
8
|
+
*
|
|
9
|
+
* Registry mapping theme names to their stylesheet definitions. Each entry
|
|
10
|
+
* maps an {@link FslTheme} string (e.g. `'default'`, `'ocean'`) to a
|
|
11
|
+
* {@link JssmBaseTheme} object containing colors, shapes, and other visual
|
|
12
|
+
* defaults used by jssm-viz when rendering state machine diagrams.
|
|
13
|
+
*
|
|
14
|
+
* Add new themes by importing their definition and calling
|
|
15
|
+
* `theme_mapping.set(name, theme)`.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
7
18
|
const theme_mapping = new Map();
|
|
8
19
|
theme_mapping.set('default', default_theme);
|
|
9
20
|
theme_mapping.set('modern', modern_theme);
|
package/dist/es6/jssm_types.d.ts
CHANGED
|
@@ -115,6 +115,7 @@ declare type JssmStateDeclaration = {
|
|
|
115
115
|
textColor?: JssmColor;
|
|
116
116
|
backgroundColor?: JssmColor;
|
|
117
117
|
borderColor?: JssmColor;
|
|
118
|
+
image?: string;
|
|
118
119
|
state: StateType;
|
|
119
120
|
property?: {
|
|
120
121
|
name: string;
|
|
@@ -154,7 +155,11 @@ declare type JssmStateStyleBorderColor = {
|
|
|
154
155
|
key: 'border-color';
|
|
155
156
|
value: JssmColor;
|
|
156
157
|
};
|
|
157
|
-
declare type
|
|
158
|
+
declare type JssmStateStyleImage = {
|
|
159
|
+
key: 'image';
|
|
160
|
+
value: string;
|
|
161
|
+
};
|
|
162
|
+
declare type JssmStateStyleKey = JssmStateStyleShape | JssmStateStyleColor | JssmStateStyleTextColor | JssmStateStyleCorners | JssmStateStyleLineStyle | JssmStateStyleBackgroundColor | JssmStateStyleStateLabel | JssmStateStyleBorderColor | JssmStateStyleImage;
|
|
158
163
|
declare type JssmStateStyleKeyList = JssmStateStyleKey[];
|
|
159
164
|
declare type JssmBaseTheme = {
|
|
160
165
|
name: string;
|
|
@@ -356,7 +361,23 @@ declare type PostExitHook<mDT> = {
|
|
|
356
361
|
from: string;
|
|
357
362
|
handler: PostHookHandler<mDT>;
|
|
358
363
|
};
|
|
359
|
-
declare type
|
|
364
|
+
declare type PreEverythingHook<mDT> = {
|
|
365
|
+
kind: 'pre everything';
|
|
366
|
+
handler: EverythingHookHandler<mDT>;
|
|
367
|
+
};
|
|
368
|
+
declare type EverythingHook<mDT> = {
|
|
369
|
+
kind: 'everything';
|
|
370
|
+
handler: EverythingHookHandler<mDT>;
|
|
371
|
+
};
|
|
372
|
+
declare type PrePostEverythingHook<mDT> = {
|
|
373
|
+
kind: 'pre post everything';
|
|
374
|
+
handler: PostEverythingHookHandler<mDT>;
|
|
375
|
+
};
|
|
376
|
+
declare type PostEverythingHook<mDT> = {
|
|
377
|
+
kind: 'post everything';
|
|
378
|
+
handler: PostEverythingHookHandler<mDT>;
|
|
379
|
+
};
|
|
380
|
+
declare type HookDescription<mDT> = BasicHookDescription<mDT> | HookDescriptionWithAction<mDT> | GlobalActionHook<mDT> | AnyActionHook<mDT> | StandardTransitionHook<mDT> | MainTransitionHook<mDT> | ForcedTransitionHook<mDT> | AnyTransitionHook<mDT> | EntryHook<mDT> | ExitHook<mDT> | AfterHook<mDT> | PostBasicHookDescription<mDT> | PostHookDescriptionWithAction<mDT> | PostGlobalActionHook<mDT> | PostAnyActionHook<mDT> | PostStandardTransitionHook<mDT> | PostMainTransitionHook<mDT> | PostForcedTransitionHook<mDT> | PostAnyTransitionHook<mDT> | PostEntryHook<mDT> | PostExitHook<mDT> | PreEverythingHook<mDT> | EverythingHook<mDT> | PrePostEverythingHook<mDT> | PostEverythingHook<mDT>;
|
|
360
381
|
declare type HookComplexResult<mDT> = {
|
|
361
382
|
pass: boolean;
|
|
362
383
|
state?: StateType;
|
|
@@ -368,11 +389,16 @@ declare type HookContext<mDT> = {
|
|
|
368
389
|
data: mDT;
|
|
369
390
|
next_data: mDT;
|
|
370
391
|
};
|
|
392
|
+
declare type EverythingHookContext<mDT> = HookContext<mDT> & {
|
|
393
|
+
hook_name: string;
|
|
394
|
+
};
|
|
371
395
|
declare type HookHandler<mDT> = (hook_context: HookContext<mDT>) => HookResult<mDT>;
|
|
372
396
|
declare type PostHookHandler<mDT> = (hook_context: HookContext<mDT>) => void;
|
|
397
|
+
declare type EverythingHookHandler<mDT> = (hook_context: EverythingHookContext<mDT>) => HookResult<mDT>;
|
|
398
|
+
declare type PostEverythingHookHandler<mDT> = (hook_context: EverythingHookContext<mDT>) => void;
|
|
373
399
|
declare type JssmErrorExtendedInfo = {
|
|
374
400
|
requested_state?: StateType | undefined;
|
|
375
401
|
};
|
|
376
402
|
declare type JssmHistory<mDT> = circular_buffer<[StateType, mDT]>;
|
|
377
403
|
declare type JssmRng = () => number;
|
|
378
|
-
export { JssmColor, JssmShape, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmStateConfig, JssmStateStyleKey, JssmStateStyleKeyList, JssmBaseTheme, JssmTheme, JssmLayout, JssmHistory, JssmSerialization, JssmPropertyDefinition, JssmAllowsOverride, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirections, FslDirection, FslThemes, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult, JssmRng };
|
|
404
|
+
export { JssmColor, JssmShape, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmStateConfig, JssmStateStyleKey, JssmStateStyleKeyList, JssmBaseTheme, JssmTheme, JssmLayout, JssmHistory, JssmSerialization, JssmPropertyDefinition, JssmAllowsOverride, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirections, FslDirection, FslThemes, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult, EverythingHookContext, EverythingHookHandler, PostEverythingHookHandler, JssmRng };
|
package/dist/es6/jssm_util.d.ts
CHANGED
|
@@ -1,11 +1,67 @@
|
|
|
1
1
|
/*******
|
|
2
2
|
*
|
|
3
|
-
* Predicate for validating an array for uniqueness.
|
|
4
|
-
*
|
|
3
|
+
* Predicate for validating an array for uniqueness. Returns `true` when
|
|
4
|
+
* `el` is the first occurrence in `source`, `false` otherwise. Intended
|
|
5
|
+
* for use as an `Array.filter` callback. Not generally meant for external
|
|
6
|
+
* use.
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* [1, 2, 2, 3].filter(arr_uniq_p); // [1, 2, 3]
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @param el - The current element being tested.
|
|
13
|
+
* @param i - The index of the current element.
|
|
14
|
+
* @param source - The full array being filtered.
|
|
15
|
+
*
|
|
16
|
+
* @returns `true` if `el` is the first occurrence in `source`.
|
|
5
17
|
*
|
|
6
18
|
*/
|
|
7
19
|
declare function arr_uniq_p<T>(el: T, i: number, source: T[]): boolean;
|
|
20
|
+
/*******
|
|
21
|
+
*
|
|
22
|
+
* Wraps a string in an array, or passes through if already non-string.
|
|
23
|
+
* Used to normalize arguments that accept either a single state name or
|
|
24
|
+
* an array of state names.
|
|
25
|
+
*
|
|
26
|
+
* ```typescript
|
|
27
|
+
* array_box_if_string('hello'); // ['hello']
|
|
28
|
+
* array_box_if_string(['a','b']); // ['a','b']
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @param n - A string to box, or a value to pass through unchanged.
|
|
32
|
+
*
|
|
33
|
+
* @returns The input wrapped in an array if it was a string, otherwise the
|
|
34
|
+
* input unchanged.
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
8
37
|
declare const array_box_if_string: (n: any) => any;
|
|
38
|
+
/*******
|
|
39
|
+
*
|
|
40
|
+
* Selects a single item from a weighted array of objects using cumulative
|
|
41
|
+
* probability. Each object in the array should have a numeric property
|
|
42
|
+
* indicating its relative weight (defaults to `'probability'`). Objects
|
|
43
|
+
* missing the property are treated as weight 1.
|
|
44
|
+
*
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const opts = [
|
|
47
|
+
* { value: 'common', probability: 0.8 },
|
|
48
|
+
* { value: 'rare', probability: 0.2 }
|
|
49
|
+
* ];
|
|
50
|
+
*
|
|
51
|
+
* weighted_rand_select(opts); // most often { value: 'common', ... }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @param options - Non-empty array of objects to choose from.
|
|
55
|
+
* @param probability_property - Name of the numeric weight property on each
|
|
56
|
+
* object. Defaults to `'probability'`.
|
|
57
|
+
* @param rng - Optional random number generator `() => number`
|
|
58
|
+
* in `[0, 1)`. Defaults to `Math.random`.
|
|
59
|
+
*
|
|
60
|
+
* @returns One element from `options`, chosen by weighted random selection.
|
|
61
|
+
*
|
|
62
|
+
* @throws {TypeError} If `options` is not a non-empty array of objects.
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
9
65
|
declare const weighted_rand_select: Function;
|
|
10
66
|
/*******
|
|
11
67
|
*
|
|
@@ -33,26 +89,108 @@ declare function seq(n: number): number[];
|
|
|
33
89
|
*
|
|
34
90
|
*/
|
|
35
91
|
declare const histograph: Function;
|
|
92
|
+
/*******
|
|
93
|
+
*
|
|
94
|
+
* Draws `n` weighted random samples from an array of objects. Each draw is
|
|
95
|
+
* independent (with replacement), delegating to {@link weighted_rand_select}.
|
|
96
|
+
*
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const opts = [
|
|
99
|
+
* { value: 'a', probability: 0.9 },
|
|
100
|
+
* { value: 'b', probability: 0.1 }
|
|
101
|
+
* ];
|
|
102
|
+
*
|
|
103
|
+
* weighted_sample_select(3, opts, 'probability');
|
|
104
|
+
* // e.g. [ { value: 'a', ... }, { value: 'a', ... }, { value: 'b', ... } ]
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* @param n - Number of samples to draw.
|
|
108
|
+
* @param options - Non-empty array of weighted objects.
|
|
109
|
+
* @param probability_property - Name of the numeric weight property.
|
|
110
|
+
* @param rng - Optional random number generator.
|
|
111
|
+
*
|
|
112
|
+
* @returns An array of `n` independently selected items.
|
|
113
|
+
*
|
|
114
|
+
*/
|
|
36
115
|
declare const weighted_sample_select: Function;
|
|
116
|
+
/*******
|
|
117
|
+
*
|
|
118
|
+
* Draws `n` weighted random samples, extracts a named key from each, and
|
|
119
|
+
* returns a histograph (`Map`) of how often each key value appeared. Useful
|
|
120
|
+
* for validating that a probabilistic transition distribution is roughly
|
|
121
|
+
* correct over many trials.
|
|
122
|
+
*
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const opts = [
|
|
125
|
+
* { to: 'a', probability: 0.7 },
|
|
126
|
+
* { to: 'b', probability: 0.3 }
|
|
127
|
+
* ];
|
|
128
|
+
*
|
|
129
|
+
* weighted_histo_key(1000, opts, 'probability', 'to');
|
|
130
|
+
* // Map { 'a' => ~700, 'b' => ~300 }
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @param n - Number of samples to draw.
|
|
134
|
+
* @param opts - Non-empty array of weighted objects.
|
|
135
|
+
* @param prob_prop - Name of the numeric weight property.
|
|
136
|
+
* @param extract - Name of the property to extract from each sample for
|
|
137
|
+
* histogramming.
|
|
138
|
+
* @param rng - Optional random number generator.
|
|
139
|
+
*
|
|
140
|
+
* @returns A `Map` from extracted key values to their occurrence counts.
|
|
141
|
+
*
|
|
142
|
+
*/
|
|
37
143
|
declare const weighted_histo_key: Function;
|
|
38
144
|
/*******
|
|
39
145
|
*
|
|
40
|
-
* Internal method generating
|
|
41
|
-
* meant for external use.
|
|
146
|
+
* Internal method generating composite keys for the hook lookup map by
|
|
147
|
+
* JSON-serializing a `[property, state]` pair. Not meant for external use.
|
|
148
|
+
*
|
|
149
|
+
* ```typescript
|
|
150
|
+
* name_bind_prop_and_state('color', 'Red'); // '["color","Red"]'
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* @param prop - The property name (e.g. a data key or hook category).
|
|
154
|
+
* @param state - The state name to bind to.
|
|
155
|
+
*
|
|
156
|
+
* @returns A deterministic JSON string key for the `[prop, state]` pair.
|
|
157
|
+
*
|
|
158
|
+
* @throws {JssmError} If either argument is not a string.
|
|
42
159
|
*
|
|
43
160
|
*/
|
|
44
161
|
declare function name_bind_prop_and_state(prop: string, state: string): string;
|
|
45
162
|
/*******
|
|
46
163
|
*
|
|
47
|
-
* Internal method generating
|
|
48
|
-
*
|
|
164
|
+
* Internal method generating composite keys for transition hooks by
|
|
165
|
+
* JSON-serializing a `[from, to]` state pair. Used to look up hooks
|
|
166
|
+
* registered on a specific edge. Not meant for external use.
|
|
167
|
+
*
|
|
168
|
+
* ```typescript
|
|
169
|
+
* hook_name('Red', 'Green'); // '["Red","Green"]'
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
172
|
+
* @param from - The source state name.
|
|
173
|
+
* @param to - The target state name.
|
|
174
|
+
*
|
|
175
|
+
* @returns A deterministic JSON string key for the `[from, to]` pair.
|
|
49
176
|
*
|
|
50
177
|
*/
|
|
51
178
|
declare const hook_name: (from: string, to: string) => string;
|
|
52
179
|
/*******
|
|
53
180
|
*
|
|
54
|
-
* Internal method generating
|
|
55
|
-
*
|
|
181
|
+
* Internal method generating composite keys for named-action hooks by
|
|
182
|
+
* JSON-serializing a `[from, to, action]` triple. Used to look up hooks
|
|
183
|
+
* registered on a specific action-labeled edge. Not meant for external use.
|
|
184
|
+
*
|
|
185
|
+
* ```typescript
|
|
186
|
+
* named_hook_name('Red', 'Green', 'next'); // '["Red","Green","next"]'
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @param from - The source state name.
|
|
190
|
+
* @param to - The target state name.
|
|
191
|
+
* @param action - The action label on the edge.
|
|
192
|
+
*
|
|
193
|
+
* @returns A deterministic JSON string key for the `[from, to, action]` triple.
|
|
56
194
|
*
|
|
57
195
|
*/
|
|
58
196
|
declare const named_hook_name: (from: string, to: string, action: string) => string;
|
|
@@ -82,7 +220,7 @@ declare function gen_splitmix32(a?: number | undefined): () => number;
|
|
|
82
220
|
* ```
|
|
83
221
|
*
|
|
84
222
|
*/
|
|
85
|
-
declare const unique: <T>(arr
|
|
223
|
+
declare const unique: <T>(arr: T[]) => T[];
|
|
86
224
|
/*******
|
|
87
225
|
*
|
|
88
226
|
* Lists all repeated items in an array along with their counts. Subject to
|
|
@@ -102,5 +240,19 @@ declare const unique: <T>(arr?: T[]) => T[];
|
|
|
102
240
|
*
|
|
103
241
|
*/
|
|
104
242
|
declare function find_repeated<T>(arr: T[]): [T, number][];
|
|
243
|
+
/*******
|
|
244
|
+
*
|
|
245
|
+
* Returns a `Promise` that resolves after `ms` milliseconds. Useful for
|
|
246
|
+
* inserting delays in async test flows or demos.
|
|
247
|
+
*
|
|
248
|
+
* ```typescript
|
|
249
|
+
* await sleep(100); // pauses execution for 100ms
|
|
250
|
+
* ```
|
|
251
|
+
*
|
|
252
|
+
* @param ms - Number of milliseconds to wait before resolving.
|
|
253
|
+
*
|
|
254
|
+
* @returns A `Promise<void>` that resolves after the timeout.
|
|
255
|
+
*
|
|
256
|
+
*/
|
|
105
257
|
declare function sleep(ms: number): Promise<unknown>;
|
|
106
258
|
export { seq, unique, find_repeated, arr_uniq_p, histograph, weighted_histo_key, weighted_rand_select, weighted_sample_select, array_box_if_string, name_bind_prop_and_state, hook_name, named_hook_name, gen_splitmix32, sleep };
|