jssm 5.79.18 → 5.81.0

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.
@@ -1,6 +1,6 @@
1
1
  declare type StateType = string;
2
- import { JssmGenericState, JssmGenericConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
3
- JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult } from './jssm_types';
2
+ import { JssmGenericState, JssmGenericConfig, JssmStateConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
3
+ JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmStateStyleKeyList, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult } from './jssm_types';
4
4
  import { seq, unique, find_repeated, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
5
5
  import * as constants from './jssm_constants';
6
6
  declare const shapes: string[], gviz_shapes: string[], named_colors: string[];
@@ -94,7 +94,7 @@ declare function arrow_right_kind(arrow: JssmArrow): JssmArrowKind;
94
94
  * ```typescript
95
95
  * import { sm } from 'jssm';
96
96
  *
97
- * const switch = sm`on <=> off;`;
97
+ * const lswitch = sm`on <=> off;`;
98
98
  * ```
99
99
  *
100
100
  * Method {@link from}:
@@ -149,7 +149,7 @@ declare function wrap_parse(input: string, options?: Object): any;
149
149
  * ```typescript
150
150
  * import { sm } from 'jssm';
151
151
  *
152
- * const switch = sm`on <=> off;`;
152
+ * const lswitch = sm`on <=> off;`;
153
153
  * ```
154
154
  *
155
155
  * Method {@link from}:
@@ -188,6 +188,7 @@ declare function make<mDT>(plan: string): JssmGenericConfig<mDT>;
188
188
  *
189
189
  */
190
190
  declare function transfer_state_properties(state_decl: JssmStateDeclaration): JssmStateDeclaration;
191
+ declare function state_style_condense(jssk: JssmStateStyleKeyList): JssmStateConfig;
191
192
  declare class Machine<mDT> {
192
193
  _state: StateType;
193
194
  _states: Map<StateType, JssmGenericState>;
@@ -197,6 +198,8 @@ declare class Machine<mDT> {
197
198
  _actions: Map<StateType, Map<StateType, number>>;
198
199
  _reverse_actions: Map<StateType, Map<StateType, number>>;
199
200
  _reverse_action_targets: Map<StateType, Map<StateType, number>>;
201
+ _start_states: Set<StateType>;
202
+ _end_states: Set<StateType>;
200
203
  _machine_author?: Array<string>;
201
204
  _machine_comment?: string;
202
205
  _machine_contributor?: Array<string>;
@@ -257,7 +260,14 @@ declare class Machine<mDT> {
257
260
  _required_properties: Set<string>;
258
261
  _history: JssmHistory<mDT>;
259
262
  _history_length: number;
260
- constructor({ start_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data }: JssmGenericConfig<mDT>);
263
+ _state_style: JssmStateConfig;
264
+ _active_state_style: JssmStateConfig;
265
+ _hooked_state_style: JssmStateConfig;
266
+ _terminal_state_style: JssmStateConfig;
267
+ _start_state_style: JssmStateConfig;
268
+ _end_state_style: JssmStateConfig;
269
+ _state_labels: Map<string, string>;
270
+ constructor({ start_states, end_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config }: JssmGenericConfig<mDT>);
261
271
  /********
262
272
  *
263
273
  * Internal method for fabricating states. Not meant for external use.
@@ -273,17 +283,32 @@ declare class Machine<mDT> {
273
283
  * ```typescript
274
284
  * import * as jssm from 'jssm';
275
285
  *
276
- * const switch = jssm.from('on <=> off;');
277
- * console.log( switch.state() ); // 'on'
286
+ * const lswitch = jssm.from('on <=> off;');
287
+ * console.log( lswitch.state() ); // 'on'
278
288
  *
279
- * switch.transition('off');
280
- * console.log( switch.state() ); // 'off'
289
+ * lswitch.transition('off');
290
+ * console.log( lswitch.state() ); // 'off'
281
291
  * ```
282
292
  *
283
293
  * @typeparam mDT The type of the machine data member; usually omitted
284
294
  *
285
295
  */
286
296
  state(): StateType;
297
+ /*********
298
+ *
299
+ * Get the label for a given state, if any; return `undefined` otherwise.
300
+ *
301
+ * ```typescript
302
+ * import * as jssm from 'jssm';
303
+ *
304
+ * const lswitch = jssm.from('a -> b; state a: { label: "Foo!"; };');
305
+ * console.log( lswitch.label_for('a') ); // 'Foo!'
306
+ * ```
307
+ *
308
+ * @typeparam mDT The type of the machine data member; usually omitted
309
+ *
310
+ */
311
+ label_for(state: StateType): string;
287
312
  /*********
288
313
  *
289
314
  * Get the current data of a machine.
@@ -291,8 +316,8 @@ declare class Machine<mDT> {
291
316
  * ```typescript
292
317
  * import * as jssm from 'jssm';
293
318
  *
294
- * const switch = jssm.from('on <=> off;', {data: 1});
295
- * console.log( switch.data() ); // 1
319
+ * const lswitch = jssm.from('on <=> off;', {data: 1});
320
+ * console.log( lswitch.data() ); // 1
296
321
  * ```
297
322
  *
298
323
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -415,6 +440,56 @@ declare class Machine<mDT> {
415
440
  *
416
441
  */
417
442
  known_props(): string[];
443
+ /********
444
+ *
445
+ * Check whether a given state is a valid start state (either because it was
446
+ * explicitly named as such, or because it was the first mentioned state.)
447
+ *
448
+ * ```typescript
449
+ * import { sm, is_start_state } from 'jssm';
450
+ *
451
+ * const example = sm`a -> b;`;
452
+ *
453
+ * console.log( final_test.is_start_state('a') ); // true
454
+ * console.log( final_test.is_start_state('b') ); // false
455
+ *
456
+ * const example = sm`start_states: [a b]; a -> b;`;
457
+ *
458
+ * console.log( final_test.is_start_state('a') ); // true
459
+ * console.log( final_test.is_start_state('b') ); // true
460
+ * ```
461
+ *
462
+ * @typeparam mDT The type of the machine data member; usually omitted
463
+ *
464
+ * @param whichState The name of the state to check
465
+ *
466
+ */
467
+ is_start_state(whichState: StateType): boolean;
468
+ /********
469
+ *
470
+ * Check whether a given state is a valid start state (either because it was
471
+ * explicitly named as such, or because it was the first mentioned state.)
472
+ *
473
+ * ```typescript
474
+ * import { sm, is_end_state } from 'jssm';
475
+ *
476
+ * const example = sm`a -> b;`;
477
+ *
478
+ * console.log( final_test.is_start_state('a') ); // false
479
+ * console.log( final_test.is_start_state('b') ); // true
480
+ *
481
+ * const example = sm`end_states: [a b]; a -> b;`;
482
+ *
483
+ * console.log( final_test.is_start_state('a') ); // true
484
+ * console.log( final_test.is_start_state('b') ); // true
485
+ * ```
486
+ *
487
+ * @typeparam mDT The type of the machine data member; usually omitted
488
+ *
489
+ * @param whichState The name of the state to check
490
+ *
491
+ */
492
+ is_end_state(whichState: StateType): boolean;
418
493
  /********
419
494
  *
420
495
  * Check whether a given state is final (either has no exits or is marked
@@ -441,7 +516,7 @@ declare class Machine<mDT> {
441
516
  * `complete`.)
442
517
  *
443
518
  * ```typescript
444
- * import { sm, state_is_final } from 'jssm';
519
+ * import { sm, is_final } from 'jssm';
445
520
  *
446
521
  * const final_test = sm`first -> second;`;
447
522
  *
@@ -486,8 +561,8 @@ declare class Machine<mDT> {
486
561
  * ```typescript
487
562
  * import * as jssm from 'jssm';
488
563
  *
489
- * const switch = jssm.from('on <=> off;');
490
- * console.log( switch.states() ); // ['on', 'off']
564
+ * const lswitch = jssm.from('on <=> off;');
565
+ * console.log( lswitch.states() ); // ['on', 'off']
491
566
  * ```
492
567
  *
493
568
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -502,10 +577,10 @@ declare class Machine<mDT> {
502
577
  * ```typescript
503
578
  * import * as jssm from 'jssm';
504
579
  *
505
- * const switch = jssm.from('on <=> off;');
580
+ * const lswitch = jssm.from('on <=> off;');
506
581
  *
507
- * console.log( switch.has_state('off') ); // true
508
- * console.log( switch.has_state('dance') ); // false
582
+ * console.log( lswitch.has_state('off') ); // true
583
+ * console.log( lswitch.has_state('dance') ); // false
509
584
  * ```
510
585
  *
511
586
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -812,6 +887,164 @@ declare class Machine<mDT> {
812
887
  *
813
888
  */
814
889
  action(actionName: StateType, newData?: mDT): boolean;
890
+ /********
891
+ *
892
+ * Get the standard style for a single state. ***Does not*** include
893
+ * composition from an applied theme, or things from the underlying base
894
+ * stylesheet; only the modifications applied by this machine.
895
+ *
896
+ * ```typescript
897
+ * const light = sm`a -> b;`;
898
+ * console.log(light.standard_state_style);
899
+ * // {}
900
+ *
901
+ * const light = sm`a -> b; state: { shape: circle; };`;
902
+ * console.log(light.standard_state_style);
903
+ * // { shape: 'circle' }
904
+ * ```
905
+ *
906
+ * @typeparam mDT The type of the machine data member; usually omitted
907
+ *
908
+ */
909
+ get standard_state_style(): JssmStateConfig;
910
+ /********
911
+ *
912
+ * Get the hooked state style. ***Does not*** include
913
+ * composition from an applied theme, or things from the underlying base
914
+ * stylesheet; only the modifications applied by this machine.
915
+ *
916
+ * The hooked style is only applied to nodes which have a named hook in the
917
+ * graph. Open hooks set through the external API aren't graphed, because
918
+ * that would be literally every node.
919
+ *
920
+ * ```typescript
921
+ * const light = sm`a -> b;`;
922
+ * console.log(light.hooked_state_style);
923
+ * // {}
924
+ *
925
+ * const light = sm`a -> b; hooked_state: { shape: circle; };`;
926
+ * console.log(light.hooked_state_style);
927
+ * // { shape: 'circle' }
928
+ * ```
929
+ *
930
+ * @typeparam mDT The type of the machine data member; usually omitted
931
+ *
932
+ */
933
+ get hooked_state_style(): JssmStateConfig;
934
+ /********
935
+ *
936
+ * Get the start state style. ***Does not*** include composition from an
937
+ * applied theme, or things from the underlying base stylesheet; only the
938
+ * modifications applied by this machine.
939
+ *
940
+ * Start states are defined by the directive `start_states`, or in absentia,
941
+ * are the first mentioned state.
942
+ *
943
+ * ```typescript
944
+ * const light = sm`a -> b;`;
945
+ * console.log(light.start_state_style);
946
+ * // {}
947
+ *
948
+ * const light = sm`a -> b; start_state: { shape: circle; };`;
949
+ * console.log(light.start_state_style);
950
+ * // { shape: 'circle' }
951
+ * ```
952
+ *
953
+ * @typeparam mDT The type of the machine data member; usually omitted
954
+ *
955
+ */
956
+ get start_state_style(): JssmStateConfig;
957
+ /********
958
+ *
959
+ * Get the end state style. ***Does not*** include
960
+ * composition from an applied theme, or things from the underlying base
961
+ * stylesheet; only the modifications applied by this machine.
962
+ *
963
+ * End states are defined in the directive `end_states`, and are distinct
964
+ * from terminal states. End states are voluntary successful endpoints for a
965
+ * process. Terminal states are states that cannot be exited. By example,
966
+ * most error states are terminal states, but not end states. Also, since
967
+ * some end states can be exited and are determined by hooks, such as
968
+ * recursive or iterative nodes, there is such a thing as an end state that
969
+ * is not a terminal state.
970
+ *
971
+ * ```typescript
972
+ * const light = sm`a -> b;`;
973
+ * console.log(light.standard_state_style);
974
+ * // {}
975
+ *
976
+ * const light = sm`a -> b; end_state: { shape: circle; };`;
977
+ * console.log(light.standard_state_style);
978
+ * // { shape: 'circle' }
979
+ * ```
980
+ *
981
+ * @typeparam mDT The type of the machine data member; usually omitted
982
+ *
983
+ */
984
+ get end_state_style(): JssmStateConfig;
985
+ /********
986
+ *
987
+ * Get the terminal state style. ***Does not*** include
988
+ * composition from an applied theme, or things from the underlying base
989
+ * stylesheet; only the modifications applied by this machine.
990
+ *
991
+ * Terminal state styles are automatically determined by the machine. Any
992
+ * state without a valid exit transition is terminal.
993
+ *
994
+ * ```typescript
995
+ * const light = sm`a -> b;`;
996
+ * console.log(light.terminal_state_style);
997
+ * // {}
998
+ *
999
+ * const light = sm`a -> b; terminal_state: { shape: circle; };`;
1000
+ * console.log(light.terminal_state_style);
1001
+ * // { shape: 'circle' }
1002
+ * ```
1003
+ *
1004
+ * @typeparam mDT The type of the machine data member; usually omitted
1005
+ *
1006
+ */
1007
+ get terminal_state_style(): JssmStateConfig;
1008
+ /********
1009
+ *
1010
+ * Get the style for the active state. ***Does not*** include
1011
+ * composition from an applied theme, or things from the underlying base
1012
+ * stylesheet; only the modifications applied by this machine.
1013
+ *
1014
+ * ```typescript
1015
+ * const light = sm`a -> b;`;
1016
+ * console.log(light.active_state_style);
1017
+ * // {}
1018
+ *
1019
+ * const light = sm`a -> b; active_state: { shape: circle; };`;
1020
+ * console.log(light.active_state_style);
1021
+ * // { shape: 'circle' }
1022
+ * ```
1023
+ *
1024
+ * @typeparam mDT The type of the machine data member; usually omitted
1025
+ *
1026
+ */
1027
+ get active_state_style(): JssmStateConfig;
1028
+ /********
1029
+ *
1030
+ * Gets the composite style for a specific node by individually imposing the
1031
+ * style layers on a given object, after determining which layers are
1032
+ * appropriate.
1033
+ *
1034
+ * The order of composition is base, then theme, then user content. Each
1035
+ * item in the stack will be composited independently. First, the base state
1036
+ * style, then the theme state style, then the user state style.
1037
+ *
1038
+ * After the three state styles, we'll composite the hooked styles; then the
1039
+ * terminal styles; then the start styles; then the end styles; finally, the
1040
+ * active styles. Remember, last wins.
1041
+ *
1042
+ * The base state style must exist. All other styles are optional.
1043
+ *
1044
+ * @typeparam mDT The type of the machine data member; usually omitted
1045
+ *
1046
+ */
1047
+ style_for(state: StateType): JssmStateConfig;
815
1048
  /********
816
1049
  *
817
1050
  * Instruct the machine to complete an action. Synonym for {@link action}.
@@ -938,7 +1171,7 @@ declare class Machine<mDT> {
938
1171
  * ```typescript
939
1172
  * import * as jssm from 'jssm';
940
1173
  *
941
- * const switch = jssm.from('on <=> off;');
1174
+ * const lswitch = jssm.from('on <=> off;');
942
1175
  * ```
943
1176
  *
944
1177
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -961,7 +1194,7 @@ declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: a
961
1194
  * ```typescript
962
1195
  * import * as jssm from 'jssm';
963
1196
  *
964
- * const switch = jssm.from('on <=> off;');
1197
+ * const lswitch = jssm.from('on <=> off;');
965
1198
  * ```
966
1199
  *
967
1200
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -976,4 +1209,4 @@ declare function is_hook_complex_result<mDT>(hr: unknown): hr is HookComplexResu
976
1209
  declare function is_hook_rejection<mDT>(hr: HookResult<mDT>): boolean;
977
1210
  declare function abstract_hook_step<mDT>(maybe_hook: HookHandler<mDT> | undefined, hook_args: HookContext<mDT>): HookComplexResult<mDT>;
978
1211
  declare function deserialize<mDT>(machine_string: string, ser: JssmSerialization<mDT>): Machine<mDT>;
979
- export { version, transfer_state_properties, Machine, deserialize, make, wrap_parse as parse, compile, sm, from, arrow_direction, arrow_left_kind, arrow_right_kind, seq, unique, find_repeated, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key, constants, shapes, gviz_shapes, named_colors, is_hook_rejection, is_hook_complex_result, abstract_hook_step };
1212
+ export { version, transfer_state_properties, Machine, deserialize, make, wrap_parse as parse, compile, sm, from, arrow_direction, arrow_left_kind, arrow_right_kind, seq, unique, find_repeated, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key, constants, shapes, gviz_shapes, named_colors, is_hook_rejection, is_hook_complex_result, abstract_hook_step, state_style_condense };