jssm 5.104.2 → 5.112.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATING-jssm-viz.md +67 -0
- package/README.md +179 -882
- package/dist/deno/README.md +347 -0
- package/dist/{es6 → deno}/jssm.d.ts +773 -39
- package/dist/deno/jssm.js +1 -0
- package/{jssm_compiler.d.ts → dist/deno/jssm_compiler.d.ts} +17 -2
- package/dist/deno/jssm_constants.d.ts +37 -0
- package/dist/deno/jssm_error.d.ts +27 -0
- package/dist/deno/jssm_theme.d.ts +15 -0
- package/dist/{es6 → deno}/jssm_types.d.ts +327 -8
- package/dist/deno/jssm_util.d.ts +258 -0
- package/dist/deno/jssm_viz.d.ts +175 -0
- package/dist/deno/jssm_viz_colors.d.ts +63 -0
- package/dist/jssm.es5.cjs +1 -1
- package/dist/jssm.es5.iife.js +1 -0
- package/dist/jssm.es6.mjs +1 -1
- package/dist/jssm_viz.cjs +1 -0
- package/dist/jssm_viz.iife.cjs +1 -0
- package/dist/jssm_viz.mjs +1 -0
- package/jssm.es5.d.cts +1191 -43
- package/jssm.es6.d.ts +1191 -43
- package/jssm_viz.es5.d.cts +2341 -0
- package/jssm_viz.es6.d.ts +2341 -0
- package/package.json +73 -24
- package/.clocignore +0 -1
- package/.codeclimate.yml +0 -22
- package/.editorconfig +0 -12
- package/.eslintrc +0 -20
- package/.gitattributes +0 -6
- package/.nycrc +0 -6
- package/.travis.yml +0 -9
- package/CHANGELOG.md +0 -178
- package/dist/es6/fsl_parser.js +0 -1
- package/dist/es6/jssm.js +0 -2488
- package/dist/es6/jssm_arrow.js +0 -187
- package/dist/es6/jssm_compiler.d.ts +0 -135
- package/dist/es6/jssm_compiler.js +0 -366
- package/dist/es6/jssm_constants.d.ts +0 -5
- package/dist/es6/jssm_constants.js +0 -94
- package/dist/es6/jssm_error.d.ts +0 -8
- package/dist/es6/jssm_error.js +0 -28
- package/dist/es6/jssm_theme.d.ts +0 -4
- package/dist/es6/jssm_theme.js +0 -13
- package/dist/es6/jssm_types.js +0 -3
- package/dist/es6/jssm_util.d.ts +0 -106
- package/dist/es6/jssm_util.js +0 -180
- package/dist/es6/themes/jssm_base_stylesheet.d.ts +0 -11
- package/dist/es6/themes/jssm_base_stylesheet.js +0 -58
- package/dist/es6/themes/jssm_theme_bold.d.ts +0 -11
- package/dist/es6/themes/jssm_theme_bold.js +0 -58
- package/dist/es6/themes/jssm_theme_default.d.ts +0 -11
- package/dist/es6/themes/jssm_theme_default.js +0 -58
- package/dist/es6/themes/jssm_theme_modern.d.ts +0 -11
- package/dist/es6/themes/jssm_theme_modern.js +0 -58
- package/dist/es6/themes/jssm_theme_ocean.d.ts +0 -11
- package/dist/es6/themes/jssm_theme_ocean.js +0 -56
- package/dist/es6/themes/jssm_theme_plain.d.ts +0 -11
- package/dist/es6/themes/jssm_theme_plain.js +0 -70
- package/dist/es6/version.js +0 -2
- package/dist/jssm.es5.iife.cjs +0 -1
- package/dist/jssm.es5.iife.nonmin.cjs +0 -23180
- package/dist/jssm.es5.nonmin.cjs +0 -23175
- package/dist/jssm.es6.nonmin.cjs +0 -23144
- package/fsl_parser.d.ts +0 -6
- package/jest-dragon.config.cjs +0 -33
- package/jest-spec.config.cjs +0 -33
- package/jest-stoch.config.cjs +0 -33
- package/jest-unicode.config.cjs +0 -33
- package/jssm.d.ts +0 -1141
- package/jssm_arrow.d.ts +0 -53
- 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/rollup.config.deno.js +0 -44
- package/rollup.config.es5.js +0 -52
- package/rollup.config.es6.js +0 -55
- package/tutorial_learn_testing.md +0 -168
- package/typedoc-options.cjs +0 -68
- package/version.d.ts +0 -2
- /package/dist/{es6 → deno}/fsl_parser.d.ts +0 -0
- /package/dist/{es6 → deno}/jssm_arrow.d.ts +0 -0
- /package/dist/{es6 → deno}/version.d.ts +0 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/*******
|
|
2
|
+
*
|
|
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`.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
65
|
+
declare const weighted_rand_select: Function;
|
|
66
|
+
/*******
|
|
67
|
+
*
|
|
68
|
+
* Returns, for a non-negative integer argument `n`, the series `[0 .. n]`.
|
|
69
|
+
*
|
|
70
|
+
* ```typescript
|
|
71
|
+
* import { seq } from './jssm';
|
|
72
|
+
*
|
|
73
|
+
* seq(5); // [0, 1, 2, 3, 4]
|
|
74
|
+
* seq(0); // []
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
*/
|
|
78
|
+
declare function seq(n: number): number[];
|
|
79
|
+
/*******
|
|
80
|
+
*
|
|
81
|
+
* Returns the histograph of an array as a `Map`. Makes no attempt to cope
|
|
82
|
+
* with deep equality; will fail for complex contents, as such.
|
|
83
|
+
*
|
|
84
|
+
* ```typescript
|
|
85
|
+
* import { histograph } from './jssm';
|
|
86
|
+
*
|
|
87
|
+
* histograph( [0, 0, 1, 1, 2, 2, 1] ); // Map()
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
143
|
+
declare const weighted_histo_key: Function;
|
|
144
|
+
/*******
|
|
145
|
+
*
|
|
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.
|
|
159
|
+
*
|
|
160
|
+
*/
|
|
161
|
+
declare function name_bind_prop_and_state(prop: string, state: string): string;
|
|
162
|
+
/*******
|
|
163
|
+
*
|
|
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.
|
|
176
|
+
*
|
|
177
|
+
*/
|
|
178
|
+
declare const hook_name: (from: string, to: string) => string;
|
|
179
|
+
/*******
|
|
180
|
+
*
|
|
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.
|
|
194
|
+
*
|
|
195
|
+
*/
|
|
196
|
+
declare const named_hook_name: (from: string, to: string, action: string) => string;
|
|
197
|
+
/*******
|
|
198
|
+
*
|
|
199
|
+
* Creates a SplitMix32 random generator. Used by the randomness test suite.
|
|
200
|
+
*
|
|
201
|
+
* Sourced from `bryc`: https://github.com/bryc/code/blob/master/jshash/PRNGs.md#splitmix32
|
|
202
|
+
*
|
|
203
|
+
* Replaces the Mulberry generator, which was found to have problems
|
|
204
|
+
*
|
|
205
|
+
*/
|
|
206
|
+
declare function gen_splitmix32(a?: number | undefined): () => number;
|
|
207
|
+
/*******
|
|
208
|
+
*
|
|
209
|
+
* Reduces an array to its unique contents. Compares with `===` and makes no
|
|
210
|
+
* effort to deep-compare contents; two matching arrays or objects contained
|
|
211
|
+
* will be treated as distinct, according to javascript rules. This also means
|
|
212
|
+
* that `NaNs` will be ***dropped***, because they do not self-compare.
|
|
213
|
+
*
|
|
214
|
+
* ```typescript
|
|
215
|
+
* unique( [] ); // []
|
|
216
|
+
* unique( [0,0] ); // [0]
|
|
217
|
+
* unique( [0,1,2, 0,1,2, 0,1,2] ); // [0,1,2]
|
|
218
|
+
* unique( [ [1], [1] ] ); // [ [1], [1] ] because arrays don't match
|
|
219
|
+
* unique( [0,NaN,2] ); // [0,2]
|
|
220
|
+
* ```
|
|
221
|
+
*
|
|
222
|
+
*/
|
|
223
|
+
declare const unique: <T>(arr: T[]) => T[];
|
|
224
|
+
/*******
|
|
225
|
+
*
|
|
226
|
+
* Lists all repeated items in an array along with their counts. Subject to
|
|
227
|
+
* matching rules of Map. `NaN` is manually removed because of conflict rules
|
|
228
|
+
* around {@link unique}. Because these are compared with `===` and because
|
|
229
|
+
* arrays and objects never match that way unless they're the same object,
|
|
230
|
+
* arrays and objects are never considered repeats.
|
|
231
|
+
*
|
|
232
|
+
* ```typescript
|
|
233
|
+
* find_repeated<string>([ ]); // []
|
|
234
|
+
* find_repeated<string>([ "one" ]); // []
|
|
235
|
+
* find_repeated<string>([ "one", "two" ]); // []
|
|
236
|
+
* find_repeated<string>([ "one", "one" ]); // [ ["one", 2] ]
|
|
237
|
+
* find_repeated<string>([ "one", "two", "one" ]); // [ ["one", 2] ]
|
|
238
|
+
* find_repeated<number>([ 0, NaN, 0, NaN ]); // [ [0, 2] ]
|
|
239
|
+
* ```
|
|
240
|
+
*
|
|
241
|
+
*/
|
|
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
|
+
*/
|
|
257
|
+
declare function sleep(ms: number): Promise<unknown>;
|
|
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 };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import * as jssm from './jssm';
|
|
2
|
+
import { version, build_time } from './version';
|
|
3
|
+
/**
|
|
4
|
+
* Inject runtime configuration for jssm/viz. Currently only accepts a
|
|
5
|
+
* custom `DOMParser` constructor for use by `*_svg_element` functions in
|
|
6
|
+
* environments that do not provide one globally (e.g. Node + jsdom).
|
|
7
|
+
*
|
|
8
|
+
* Idempotent — last call wins. No-op if called with no recognized keys.
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Node, with jsdom:
|
|
12
|
+
* import { JSDOM } from 'jsdom';
|
|
13
|
+
* import { configure, fsl_to_svg_element } from 'jssm/viz';
|
|
14
|
+
*
|
|
15
|
+
* configure({ DOMParser: new JSDOM().window.DOMParser });
|
|
16
|
+
* const el = await fsl_to_svg_element('a -> b;');
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param opts Configuration overrides.
|
|
20
|
+
* @param opts.DOMParser Constructor compatible with the WHATWG `DOMParser`
|
|
21
|
+
* interface. Used as a fallback when `globalThis.DOMParser` is undefined.
|
|
22
|
+
*
|
|
23
|
+
* @throws {JssmError} if `DOMParser` is provided and is not a constructor.
|
|
24
|
+
*/
|
|
25
|
+
declare function configure(opts: {
|
|
26
|
+
DOMParser?: typeof globalThis.DOMParser;
|
|
27
|
+
}): void;
|
|
28
|
+
/**
|
|
29
|
+
* Look up a color from the default viz palette by key, returning empty
|
|
30
|
+
* string if the key is unknown (so it disappears in feature concatenation).
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
declare function vc(col: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Build a graphviz-safe node identifier for a state, by index. Accepts
|
|
37
|
+
* either a `string[]` (used historically; O(n) per call) or a
|
|
38
|
+
* precomputed `Map<state, index>` (used by rendering hot paths; O(1)
|
|
39
|
+
* per call). The map form is used during dot generation; the array
|
|
40
|
+
* form is retained for direct test access via `_test`.
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
declare function node_of(state: string, state_index: string[] | Map<string, number>): string;
|
|
45
|
+
/**
|
|
46
|
+
* Convert an 8-channel hex color (`#RRGGBBAA`) to a 6-channel hex color
|
|
47
|
+
* (`#RRGGBB`), discarding the alpha channel. Throws if the input is not
|
|
48
|
+
* a 9-character `#`-prefixed string.
|
|
49
|
+
*
|
|
50
|
+
* Graphviz dot does not support alpha; this is a lossy projection.
|
|
51
|
+
*
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
declare function color8to6(color8: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Variant of {@link color8to6} that passes `undefined` through.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
declare function u_color8to6(color8?: string): string | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Read the graphviz shape for a state through {@link jssm.Machine.style_for},
|
|
63
|
+
* so theme-supplied shapes are honoured along with per-state declarations.
|
|
64
|
+
* Returns `undefined` if neither a theme nor a state declaration supplies a
|
|
65
|
+
* shape.
|
|
66
|
+
*
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
declare function shape_for_state<T>(u_jssm: jssm.Machine<T>, state: string): string | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Read the image filename for a state through {@link jssm.Machine.style_for},
|
|
72
|
+
* so theme-supplied images are honoured along with per-state declarations.
|
|
73
|
+
* Returns `undefined` if neither a theme nor a state declaration supplies an
|
|
74
|
+
* image.
|
|
75
|
+
*
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
declare function image_for_state<T>(u_jssm: jssm.Machine<T>, state: string): string | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Compose a graphviz `style` string for a state by looking up its merged
|
|
81
|
+
* style via {@link jssm.Machine.style_for}, then delegating to
|
|
82
|
+
* {@link compose_style_string}. Theme-supplied `corners` and `lineStyle`
|
|
83
|
+
* are honoured along with per-state declarations.
|
|
84
|
+
*
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
declare function style_for_state<T>(u_jssm: jssm.Machine<T>, state: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* Render a {@link jssm.Machine} as a graphviz dot string.
|
|
90
|
+
*
|
|
91
|
+
* ```typescript
|
|
92
|
+
* import { sm } from 'jssm';
|
|
93
|
+
* import { machine_to_dot } from 'jssm/viz';
|
|
94
|
+
*
|
|
95
|
+
* const dot = machine_to_dot(sm`a -> b;`);
|
|
96
|
+
* // 'digraph G { ... }'
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @param u_jssm The machine to render.
|
|
100
|
+
* @returns A complete graphviz dot source string.
|
|
101
|
+
*/
|
|
102
|
+
declare function machine_to_dot<T>(u_jssm: jssm.Machine<T>): string;
|
|
103
|
+
/**
|
|
104
|
+
* Render an FSL string directly to graphviz dot source.
|
|
105
|
+
*
|
|
106
|
+
* ```typescript
|
|
107
|
+
* import { fsl_to_dot } from 'jssm/viz';
|
|
108
|
+
* const dot = fsl_to_dot('a -> b;');
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @param fsl The FSL source.
|
|
112
|
+
* @returns A complete graphviz dot source string.
|
|
113
|
+
*/
|
|
114
|
+
declare function fsl_to_dot(fsl: string): string;
|
|
115
|
+
/**
|
|
116
|
+
* Render a graphviz dot source string to SVG using `@viz-js/viz`. The
|
|
117
|
+
* underlying viz instance is lazy-initialized on first call and cached for
|
|
118
|
+
* the lifetime of the module.
|
|
119
|
+
*
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const svg = await dot_to_svg('digraph G { a -> b }');
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @param dot Graphviz dot source.
|
|
125
|
+
* @returns A promise resolving to an SVG XML string.
|
|
126
|
+
*/
|
|
127
|
+
declare function dot_to_svg(dot: string): Promise<string>;
|
|
128
|
+
/**
|
|
129
|
+
* Render an FSL string directly to SVG.
|
|
130
|
+
*
|
|
131
|
+
* @param fsl The FSL source.
|
|
132
|
+
* @returns A promise resolving to an SVG XML string.
|
|
133
|
+
*/
|
|
134
|
+
declare function fsl_to_svg_string(fsl: string): Promise<string>;
|
|
135
|
+
/**
|
|
136
|
+
* Render a {@link jssm.Machine} to SVG.
|
|
137
|
+
*
|
|
138
|
+
* @param u_jssm The machine to render.
|
|
139
|
+
* @returns A promise resolving to an SVG XML string.
|
|
140
|
+
*/
|
|
141
|
+
declare function machine_to_svg_string<T>(u_jssm: jssm.Machine<T>): Promise<string>;
|
|
142
|
+
/**
|
|
143
|
+
* Render an FSL string directly to a parsed `SVGSVGElement`.
|
|
144
|
+
*
|
|
145
|
+
* @param fsl The FSL source.
|
|
146
|
+
* @returns A promise resolving to a parsed `SVGSVGElement`.
|
|
147
|
+
* @throws {JssmError} if no `DOMParser` is available (Node without `configure`).
|
|
148
|
+
*/
|
|
149
|
+
declare function fsl_to_svg_element(fsl: string): Promise<SVGSVGElement>;
|
|
150
|
+
/**
|
|
151
|
+
* Render a {@link jssm.Machine} to a parsed `SVGSVGElement`.
|
|
152
|
+
*
|
|
153
|
+
* @param u_jssm The machine to render.
|
|
154
|
+
* @returns A promise resolving to a parsed `SVGSVGElement`.
|
|
155
|
+
* @throws {JssmError} if no `DOMParser` is available (Node without `configure`).
|
|
156
|
+
*/
|
|
157
|
+
declare function machine_to_svg_element<T>(u_jssm: jssm.Machine<T>): Promise<SVGSVGElement>;
|
|
158
|
+
/**
|
|
159
|
+
* Compatibility wrapper for {@link machine_to_dot}, retained from
|
|
160
|
+
* jssm-viz. Will be removed in the next major.
|
|
161
|
+
*
|
|
162
|
+
* @deprecated Use {@link machine_to_dot} instead.
|
|
163
|
+
*/
|
|
164
|
+
declare function dot<T>(machine: jssm.Machine<T>): string;
|
|
165
|
+
export { configure, dot, dot_to_svg, fsl_to_dot, fsl_to_svg_string, fsl_to_svg_element, machine_to_dot, machine_to_svg_string, machine_to_svg_element, version, build_time };
|
|
166
|
+
/** @internal — test-only access to private helpers. */
|
|
167
|
+
export declare const _test: {
|
|
168
|
+
color8to6: typeof color8to6;
|
|
169
|
+
u_color8to6: typeof u_color8to6;
|
|
170
|
+
vc: typeof vc;
|
|
171
|
+
node_of: typeof node_of;
|
|
172
|
+
shape_for_state: typeof shape_for_state;
|
|
173
|
+
image_for_state: typeof image_for_state;
|
|
174
|
+
style_for_state: typeof style_for_state;
|
|
175
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default color palette for jssm/viz dot/svg output. Used by the graphviz
|
|
3
|
+
* rendering helpers in jssm_viz.ts to colorize nodes and edges based on
|
|
4
|
+
* state type (terminal/final/complete/normal) and arrow kind
|
|
5
|
+
* (legal/main/forced).
|
|
6
|
+
*
|
|
7
|
+
* Keys are flat strings of the form `<arrow_kind>_<modifier>_<position>`
|
|
8
|
+
* (e.g. `legal_final_solo`, `main_terminal_2`); also the special node fill
|
|
9
|
+
* colors (`fill_final`, `fill_terminal`, `fill_complete`) and the graph
|
|
10
|
+
* background.
|
|
11
|
+
*/
|
|
12
|
+
declare const default_viz_colors: {
|
|
13
|
+
graph_bg_color: string;
|
|
14
|
+
fill_final: string;
|
|
15
|
+
fill_terminal: string;
|
|
16
|
+
fill_complete: string;
|
|
17
|
+
legal_1: string;
|
|
18
|
+
legal_2: string;
|
|
19
|
+
legal_solo: string;
|
|
20
|
+
legal_final_1: string;
|
|
21
|
+
legal_final_2: string;
|
|
22
|
+
legal_final_solo: string;
|
|
23
|
+
legal_terminal_1: string;
|
|
24
|
+
legal_terminal_2: string;
|
|
25
|
+
legal_terminal_solo: string;
|
|
26
|
+
legal_complete_1: string;
|
|
27
|
+
legal_complete_2: string;
|
|
28
|
+
legal_complete_solo: string;
|
|
29
|
+
main_1: string;
|
|
30
|
+
main_2: string;
|
|
31
|
+
main_solo: string;
|
|
32
|
+
main_final_1: string;
|
|
33
|
+
main_final_2: string;
|
|
34
|
+
main_final_solo: string;
|
|
35
|
+
main_terminal_1: string;
|
|
36
|
+
main_terminal_2: string;
|
|
37
|
+
main_terminal_solo: string;
|
|
38
|
+
main_complete_1: string;
|
|
39
|
+
main_complete_2: string;
|
|
40
|
+
main_complete_solo: string;
|
|
41
|
+
forced_1: string;
|
|
42
|
+
forced_2: string;
|
|
43
|
+
forced_solo: string;
|
|
44
|
+
forced_final_1: string;
|
|
45
|
+
forced_final_2: string;
|
|
46
|
+
forced_final_solo: string;
|
|
47
|
+
forced_terminal_1: string;
|
|
48
|
+
forced_terminal_2: string;
|
|
49
|
+
forced_terminal_solo: string;
|
|
50
|
+
forced_complete_1: string;
|
|
51
|
+
forced_complete_2: string;
|
|
52
|
+
forced_complete_solo: string;
|
|
53
|
+
text_final_1: string;
|
|
54
|
+
text_final_2: string;
|
|
55
|
+
text_final_solo: string;
|
|
56
|
+
text_terminal_1: string;
|
|
57
|
+
text_terminal_2: string;
|
|
58
|
+
text_terminal_solo: string;
|
|
59
|
+
text_complete_1: string;
|
|
60
|
+
text_complete_2: string;
|
|
61
|
+
text_complete_solo: string;
|
|
62
|
+
};
|
|
63
|
+
export { default_viz_colors };
|