jssm 5.79.16 → 5.80.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.
- package/CHANGELOG.md +45 -40
- package/README.md +2 -2
- package/dist/es6/jssm-dot.js +1 -1
- package/dist/es6/jssm.d.ts +222 -5
- package/dist/es6/jssm.js +371 -10
- package/dist/es6/jssm_base_stylesheet.d.ts +10 -0
- package/dist/es6/jssm_base_stylesheet.js +33 -0
- package/dist/es6/jssm_types.d.ts +39 -2
- package/dist/es6/version.js +1 -1
- package/dist/jssm.es5.cjs.js +1 -1
- package/dist/jssm.es5.iife.js +1 -1
- package/jssm.d.ts +222 -5
- package/jssm_base_stylesheet.d.ts +10 -0
- package/jssm_types.d.ts +39 -2
- package/package.json +1 -1
package/dist/es6/jssm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// whargarbl lots of these return arrays could/should be sets
|
|
2
2
|
import { reduce as reduce_to_639 } from 'reduce-to-639-1';
|
|
3
3
|
import { circular_buffer } from 'circular_buffer_js';
|
|
4
|
+
import { base_state_style, base_start_state_style, base_end_state_style, base_terminal_state_style, base_active_state_style } from './jssm_base_stylesheet';
|
|
4
5
|
import { seq, unique, find_repeated, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key, array_box_if_string, name_bind_prop_and_state, hook_name, named_hook_name } from './jssm_util';
|
|
5
6
|
import * as constants from './jssm_constants';
|
|
6
7
|
const { shapes, gviz_shapes, named_colors } = constants;
|
|
@@ -379,7 +380,9 @@ function compile_rule_handler(rule) {
|
|
|
379
380
|
'graph_layout', 'start_states', 'end_states', 'machine_name', 'machine_version',
|
|
380
381
|
'machine_comment', 'machine_author', 'machine_contributor', 'machine_definition',
|
|
381
382
|
'machine_reference', 'machine_license', 'fsl_version', 'state_config', 'theme',
|
|
382
|
-
'flow', 'dot_preamble'
|
|
383
|
+
'flow', 'dot_preamble', 'default_state_config', 'default_start_state_config',
|
|
384
|
+
'default_end_state_config', 'default_hooked_state_config',
|
|
385
|
+
'default_active_state_config', 'default_terminal_state_config'
|
|
383
386
|
];
|
|
384
387
|
if (tautologies.includes(rule.key)) {
|
|
385
388
|
return { agg_as: rule.key, val: rule.value };
|
|
@@ -462,7 +465,13 @@ function compile(tree) {
|
|
|
462
465
|
arrange_declaration: [],
|
|
463
466
|
arrange_start_declaration: [],
|
|
464
467
|
arrange_end_declaration: [],
|
|
465
|
-
machine_version: []
|
|
468
|
+
machine_version: [],
|
|
469
|
+
default_state_config: [],
|
|
470
|
+
default_active_state_config: [],
|
|
471
|
+
default_hooked_state_config: [],
|
|
472
|
+
default_terminal_state_config: [],
|
|
473
|
+
default_start_state_config: [],
|
|
474
|
+
default_end_state_config: [],
|
|
466
475
|
};
|
|
467
476
|
tree.map((tr) => {
|
|
468
477
|
const rule = compile_rule_handler(tr), agg_as = rule.agg_as, val = rule.val; // TODO FIXME no any
|
|
@@ -475,8 +484,9 @@ function compile(tree) {
|
|
|
475
484
|
const assembled_transitions = [].concat(...results['transition']);
|
|
476
485
|
const result_cfg = {
|
|
477
486
|
start_states: results.start_states.length ? results.start_states : [assembled_transitions[0].from],
|
|
487
|
+
end_states: results.end_states,
|
|
478
488
|
transitions: assembled_transitions,
|
|
479
|
-
state_property: []
|
|
489
|
+
state_property: [],
|
|
480
490
|
};
|
|
481
491
|
const oneOnlyKeys = [
|
|
482
492
|
'graph_layout', 'machine_name', 'machine_version', 'machine_comment',
|
|
@@ -495,7 +505,10 @@ function compile(tree) {
|
|
|
495
505
|
});
|
|
496
506
|
['arrange_declaration', 'arrange_start_declaration', 'arrange_end_declaration',
|
|
497
507
|
'machine_author', 'machine_contributor', 'machine_reference',
|
|
498
|
-
'state_declaration', 'property_definition'
|
|
508
|
+
'state_declaration', 'property_definition', 'default_state_config',
|
|
509
|
+
'default_start_state_config', 'default_end_state_config',
|
|
510
|
+
'default_hooked_state_config', 'default_terminal_state_config',
|
|
511
|
+
'default_active_state_config'].map((multiKey) => {
|
|
499
512
|
if (results[multiKey].length) {
|
|
500
513
|
result_cfg[multiKey] = results[multiKey];
|
|
501
514
|
}
|
|
@@ -552,8 +565,8 @@ function transfer_state_properties(state_decl) {
|
|
|
552
565
|
case 'corners':
|
|
553
566
|
state_decl.corners = d.value;
|
|
554
567
|
break;
|
|
555
|
-
case '
|
|
556
|
-
state_decl.
|
|
568
|
+
case 'line-style':
|
|
569
|
+
state_decl.lineStyle = d.value;
|
|
557
570
|
break;
|
|
558
571
|
case 'text-color':
|
|
559
572
|
state_decl.textColor = d.value;
|
|
@@ -572,10 +585,74 @@ function transfer_state_properties(state_decl) {
|
|
|
572
585
|
});
|
|
573
586
|
return state_decl;
|
|
574
587
|
}
|
|
588
|
+
function state_style_condense(jssk) {
|
|
589
|
+
const state_style = {};
|
|
590
|
+
if (Array.isArray(jssk)) {
|
|
591
|
+
jssk.forEach((key, i) => {
|
|
592
|
+
if (typeof key !== 'object') {
|
|
593
|
+
throw new JssmError(this, `invalid state item ${i} in state_style_condense list: ${JSON.stringify(key)}`);
|
|
594
|
+
}
|
|
595
|
+
switch (key.key) {
|
|
596
|
+
case 'shape':
|
|
597
|
+
if (state_style.shape !== undefined) {
|
|
598
|
+
throw new JssmError(this, `cannot redefine 'shape' in state_style_condense, already defined`);
|
|
599
|
+
}
|
|
600
|
+
state_style.shape = key.value;
|
|
601
|
+
break;
|
|
602
|
+
case 'color':
|
|
603
|
+
if (state_style.color !== undefined) {
|
|
604
|
+
throw new JssmError(this, `cannot redefine 'color' in state_style_condense, already defined`);
|
|
605
|
+
}
|
|
606
|
+
state_style.color = key.value;
|
|
607
|
+
break;
|
|
608
|
+
case 'text-color':
|
|
609
|
+
if (state_style.textColor !== undefined) {
|
|
610
|
+
throw new JssmError(this, `cannot redefine 'text-color' in state_style_condense, already defined`);
|
|
611
|
+
}
|
|
612
|
+
state_style.textColor = key.value;
|
|
613
|
+
break;
|
|
614
|
+
case 'corners':
|
|
615
|
+
if (state_style.corners !== undefined) {
|
|
616
|
+
throw new JssmError(this, `cannot redefine 'corners' in state_style_condense, already defined`);
|
|
617
|
+
}
|
|
618
|
+
state_style.corners = key.value;
|
|
619
|
+
break;
|
|
620
|
+
case 'line-style':
|
|
621
|
+
if (state_style.lineStyle !== undefined) {
|
|
622
|
+
throw new JssmError(this, `cannot redefine 'line-style' in state_style_condense, already defined`);
|
|
623
|
+
}
|
|
624
|
+
state_style.lineStyle = key.value;
|
|
625
|
+
break;
|
|
626
|
+
case 'background-color':
|
|
627
|
+
if (state_style.backgroundColor !== undefined) {
|
|
628
|
+
throw new JssmError(this, `cannot redefine 'background-color' in state_style_condense, already defined`);
|
|
629
|
+
}
|
|
630
|
+
state_style.backgroundColor = key.value;
|
|
631
|
+
break;
|
|
632
|
+
case 'border-color':
|
|
633
|
+
if (state_style.borderColor !== undefined) {
|
|
634
|
+
throw new JssmError(this, `cannot redefine 'border-color' in state_style_condense, already defined`);
|
|
635
|
+
}
|
|
636
|
+
state_style.borderColor = key.value;
|
|
637
|
+
break;
|
|
638
|
+
default:
|
|
639
|
+
// TODO do that <never> trick to assert this list is complete
|
|
640
|
+
throw new JssmError(this, `unknown state style key in condense: ${key.key}`);
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
else if (jssk === undefined) {
|
|
645
|
+
// do nothing, undefined is legal and means we should return the empty container above
|
|
646
|
+
}
|
|
647
|
+
else {
|
|
648
|
+
throw new JssmError(this, 'state_style_condense received a non-array');
|
|
649
|
+
}
|
|
650
|
+
return state_style;
|
|
651
|
+
}
|
|
575
652
|
// TODO add a lotta docblock here
|
|
576
653
|
class Machine {
|
|
577
654
|
// whargarbl this badly needs to be broken up, monolith master
|
|
578
|
-
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 = undefined, arrange_declaration = [], arrange_start_declaration = [], arrange_end_declaration = [], theme = 'default', flow = 'down', graph_layout = 'dot', instance_name, history, data }) {
|
|
655
|
+
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 = undefined, arrange_declaration = [], arrange_start_declaration = [], arrange_end_declaration = [], theme = 'default', flow = 'down', graph_layout = 'dot', 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 }) {
|
|
579
656
|
this._instance_name = instance_name;
|
|
580
657
|
this._state = start_states[0];
|
|
581
658
|
this._states = new Map();
|
|
@@ -586,6 +663,8 @@ class Machine {
|
|
|
586
663
|
this._actions = new Map();
|
|
587
664
|
this._reverse_actions = new Map();
|
|
588
665
|
this._reverse_action_targets = new Map(); // todo
|
|
666
|
+
this._start_states = new Set(start_states);
|
|
667
|
+
this._end_states = new Set(end_states); // todo consider what to do about incorporating complete too
|
|
589
668
|
this._machine_author = array_box_if_string(machine_author);
|
|
590
669
|
this._machine_comment = machine_comment;
|
|
591
670
|
this._machine_contributor = array_box_if_string(machine_contributor);
|
|
@@ -644,6 +723,12 @@ class Machine {
|
|
|
644
723
|
this._default_properties = new Map();
|
|
645
724
|
this._state_properties = new Map();
|
|
646
725
|
this._required_properties = new Set();
|
|
726
|
+
this._state_style = state_style_condense(default_state_config);
|
|
727
|
+
this._active_state_style = state_style_condense(default_active_state_config);
|
|
728
|
+
this._hooked_state_style = state_style_condense(default_hooked_state_config);
|
|
729
|
+
this._terminal_state_style = state_style_condense(default_terminal_state_config);
|
|
730
|
+
this._start_state_style = state_style_condense(default_start_state_config);
|
|
731
|
+
this._end_state_style = state_style_condense(default_end_state_config);
|
|
647
732
|
this._history_length = history || 0;
|
|
648
733
|
this._history = new circular_buffer(this._history_length);
|
|
649
734
|
if (state_declaration) {
|
|
@@ -1008,6 +1093,60 @@ class Machine {
|
|
|
1008
1093
|
known_props() {
|
|
1009
1094
|
return [...this._property_keys];
|
|
1010
1095
|
}
|
|
1096
|
+
/********
|
|
1097
|
+
*
|
|
1098
|
+
* Check whether a given state is a valid start state (either because it was
|
|
1099
|
+
* explicitly named as such, or because it was the first mentioned state.)
|
|
1100
|
+
*
|
|
1101
|
+
* ```typescript
|
|
1102
|
+
* import { sm, is_start_state } from 'jssm';
|
|
1103
|
+
*
|
|
1104
|
+
* const example = sm`a -> b;`;
|
|
1105
|
+
*
|
|
1106
|
+
* console.log( final_test.is_start_state('a') ); // true
|
|
1107
|
+
* console.log( final_test.is_start_state('b') ); // false
|
|
1108
|
+
*
|
|
1109
|
+
* const example = sm`start_states: [a b]; a -> b;`;
|
|
1110
|
+
*
|
|
1111
|
+
* console.log( final_test.is_start_state('a') ); // true
|
|
1112
|
+
* console.log( final_test.is_start_state('b') ); // true
|
|
1113
|
+
* ```
|
|
1114
|
+
*
|
|
1115
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1116
|
+
*
|
|
1117
|
+
* @param whichState The name of the state to check
|
|
1118
|
+
*
|
|
1119
|
+
*/
|
|
1120
|
+
is_start_state(whichState) {
|
|
1121
|
+
return this._start_states.has(whichState);
|
|
1122
|
+
}
|
|
1123
|
+
/********
|
|
1124
|
+
*
|
|
1125
|
+
* Check whether a given state is a valid start state (either because it was
|
|
1126
|
+
* explicitly named as such, or because it was the first mentioned state.)
|
|
1127
|
+
*
|
|
1128
|
+
* ```typescript
|
|
1129
|
+
* import { sm, is_end_state } from 'jssm';
|
|
1130
|
+
*
|
|
1131
|
+
* const example = sm`a -> b;`;
|
|
1132
|
+
*
|
|
1133
|
+
* console.log( final_test.is_start_state('a') ); // false
|
|
1134
|
+
* console.log( final_test.is_start_state('b') ); // true
|
|
1135
|
+
*
|
|
1136
|
+
* const example = sm`end_states: [a b]; a -> b;`;
|
|
1137
|
+
*
|
|
1138
|
+
* console.log( final_test.is_start_state('a') ); // true
|
|
1139
|
+
* console.log( final_test.is_start_state('b') ); // true
|
|
1140
|
+
* ```
|
|
1141
|
+
*
|
|
1142
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1143
|
+
*
|
|
1144
|
+
* @param whichState The name of the state to check
|
|
1145
|
+
*
|
|
1146
|
+
*/
|
|
1147
|
+
is_end_state(whichState) {
|
|
1148
|
+
return this._end_states.has(whichState);
|
|
1149
|
+
}
|
|
1011
1150
|
/********
|
|
1012
1151
|
*
|
|
1013
1152
|
* Check whether a given state is final (either has no exits or is marked
|
|
@@ -1028,7 +1167,7 @@ class Machine {
|
|
|
1028
1167
|
*
|
|
1029
1168
|
*/
|
|
1030
1169
|
state_is_final(whichState) {
|
|
1031
|
-
return ((this.state_is_terminal(whichState))
|
|
1170
|
+
return ((this.state_is_terminal(whichState)) || (this.state_is_complete(whichState)));
|
|
1032
1171
|
}
|
|
1033
1172
|
/********
|
|
1034
1173
|
*
|
|
@@ -1036,7 +1175,7 @@ class Machine {
|
|
|
1036
1175
|
* `complete`.)
|
|
1037
1176
|
*
|
|
1038
1177
|
* ```typescript
|
|
1039
|
-
* import { sm,
|
|
1178
|
+
* import { sm, is_final } from 'jssm';
|
|
1040
1179
|
*
|
|
1041
1180
|
* const final_test = sm`first -> second;`;
|
|
1042
1181
|
*
|
|
@@ -2003,6 +2142,228 @@ class Machine {
|
|
|
2003
2142
|
action(actionName, newData) {
|
|
2004
2143
|
return this.transition_impl(actionName, newData, false, true);
|
|
2005
2144
|
}
|
|
2145
|
+
/********
|
|
2146
|
+
*
|
|
2147
|
+
* Get the standard style for a single state. ***Does not*** include
|
|
2148
|
+
* composition from an applied theme, or things from the underlying base
|
|
2149
|
+
* stylesheet; only the modifications applied by this machine.
|
|
2150
|
+
*
|
|
2151
|
+
* ```typescript
|
|
2152
|
+
* const light = sm`a -> b;`;
|
|
2153
|
+
* console.log(light.standard_state_style);
|
|
2154
|
+
* // {}
|
|
2155
|
+
*
|
|
2156
|
+
* const light = sm`a -> b; state: { shape: circle; };`;
|
|
2157
|
+
* console.log(light.standard_state_style);
|
|
2158
|
+
* // { shape: 'circle' }
|
|
2159
|
+
* ```
|
|
2160
|
+
*
|
|
2161
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
2162
|
+
*
|
|
2163
|
+
*/
|
|
2164
|
+
get standard_state_style() {
|
|
2165
|
+
return this._state_style;
|
|
2166
|
+
}
|
|
2167
|
+
/********
|
|
2168
|
+
*
|
|
2169
|
+
* Get the hooked state style. ***Does not*** include
|
|
2170
|
+
* composition from an applied theme, or things from the underlying base
|
|
2171
|
+
* stylesheet; only the modifications applied by this machine.
|
|
2172
|
+
*
|
|
2173
|
+
* The hooked style is only applied to nodes which have a named hook in the
|
|
2174
|
+
* graph. Open hooks set through the external API aren't graphed, because
|
|
2175
|
+
* that would be literally every node.
|
|
2176
|
+
*
|
|
2177
|
+
* ```typescript
|
|
2178
|
+
* const light = sm`a -> b;`;
|
|
2179
|
+
* console.log(light.hooked_state_style);
|
|
2180
|
+
* // {}
|
|
2181
|
+
*
|
|
2182
|
+
* const light = sm`a -> b; hooked_state: { shape: circle; };`;
|
|
2183
|
+
* console.log(light.hooked_state_style);
|
|
2184
|
+
* // { shape: 'circle' }
|
|
2185
|
+
* ```
|
|
2186
|
+
*
|
|
2187
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
2188
|
+
*
|
|
2189
|
+
*/
|
|
2190
|
+
get hooked_state_style() {
|
|
2191
|
+
return this._hooked_state_style;
|
|
2192
|
+
}
|
|
2193
|
+
/********
|
|
2194
|
+
*
|
|
2195
|
+
* Get the start state style. ***Does not*** include composition from an
|
|
2196
|
+
* applied theme, or things from the underlying base stylesheet; only the
|
|
2197
|
+
* modifications applied by this machine.
|
|
2198
|
+
*
|
|
2199
|
+
* Start states are defined by the directive `start_states`, or in absentia,
|
|
2200
|
+
* are the first mentioned state.
|
|
2201
|
+
*
|
|
2202
|
+
* ```typescript
|
|
2203
|
+
* const light = sm`a -> b;`;
|
|
2204
|
+
* console.log(light.start_state_style);
|
|
2205
|
+
* // {}
|
|
2206
|
+
*
|
|
2207
|
+
* const light = sm`a -> b; start_state: { shape: circle; };`;
|
|
2208
|
+
* console.log(light.start_state_style);
|
|
2209
|
+
* // { shape: 'circle' }
|
|
2210
|
+
* ```
|
|
2211
|
+
*
|
|
2212
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
2213
|
+
*
|
|
2214
|
+
*/
|
|
2215
|
+
get start_state_style() {
|
|
2216
|
+
return this._start_state_style;
|
|
2217
|
+
}
|
|
2218
|
+
/********
|
|
2219
|
+
*
|
|
2220
|
+
* Get the end state style. ***Does not*** include
|
|
2221
|
+
* composition from an applied theme, or things from the underlying base
|
|
2222
|
+
* stylesheet; only the modifications applied by this machine.
|
|
2223
|
+
*
|
|
2224
|
+
* End states are defined in the directive `end_states`, and are distinct
|
|
2225
|
+
* from terminal states. End states are voluntary successful endpoints for a
|
|
2226
|
+
* process. Terminal states are states that cannot be exited. By example,
|
|
2227
|
+
* most error states are terminal states, but not end states. Also, since
|
|
2228
|
+
* some end states can be exited and are determined by hooks, such as
|
|
2229
|
+
* recursive or iterative nodes, there is such a thing as an end state that
|
|
2230
|
+
* is not a terminal state.
|
|
2231
|
+
*
|
|
2232
|
+
* ```typescript
|
|
2233
|
+
* const light = sm`a -> b;`;
|
|
2234
|
+
* console.log(light.standard_state_style);
|
|
2235
|
+
* // {}
|
|
2236
|
+
*
|
|
2237
|
+
* const light = sm`a -> b; end_state: { shape: circle; };`;
|
|
2238
|
+
* console.log(light.standard_state_style);
|
|
2239
|
+
* // { shape: 'circle' }
|
|
2240
|
+
* ```
|
|
2241
|
+
*
|
|
2242
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
2243
|
+
*
|
|
2244
|
+
*/
|
|
2245
|
+
get end_state_style() {
|
|
2246
|
+
return this._end_state_style;
|
|
2247
|
+
}
|
|
2248
|
+
/********
|
|
2249
|
+
*
|
|
2250
|
+
* Get the terminal state style. ***Does not*** include
|
|
2251
|
+
* composition from an applied theme, or things from the underlying base
|
|
2252
|
+
* stylesheet; only the modifications applied by this machine.
|
|
2253
|
+
*
|
|
2254
|
+
* Terminal state styles are automatically determined by the machine. Any
|
|
2255
|
+
* state without a valid exit transition is terminal.
|
|
2256
|
+
*
|
|
2257
|
+
* ```typescript
|
|
2258
|
+
* const light = sm`a -> b;`;
|
|
2259
|
+
* console.log(light.terminal_state_style);
|
|
2260
|
+
* // {}
|
|
2261
|
+
*
|
|
2262
|
+
* const light = sm`a -> b; terminal_state: { shape: circle; };`;
|
|
2263
|
+
* console.log(light.terminal_state_style);
|
|
2264
|
+
* // { shape: 'circle' }
|
|
2265
|
+
* ```
|
|
2266
|
+
*
|
|
2267
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
2268
|
+
*
|
|
2269
|
+
*/
|
|
2270
|
+
get terminal_state_style() {
|
|
2271
|
+
return this._terminal_state_style;
|
|
2272
|
+
}
|
|
2273
|
+
/********
|
|
2274
|
+
*
|
|
2275
|
+
* Get the style for the active state. ***Does not*** include
|
|
2276
|
+
* composition from an applied theme, or things from the underlying base
|
|
2277
|
+
* stylesheet; only the modifications applied by this machine.
|
|
2278
|
+
*
|
|
2279
|
+
* ```typescript
|
|
2280
|
+
* const light = sm`a -> b;`;
|
|
2281
|
+
* console.log(light.active_state_style);
|
|
2282
|
+
* // {}
|
|
2283
|
+
*
|
|
2284
|
+
* const light = sm`a -> b; active_state: { shape: circle; };`;
|
|
2285
|
+
* console.log(light.active_state_style);
|
|
2286
|
+
* // { shape: 'circle' }
|
|
2287
|
+
* ```
|
|
2288
|
+
*
|
|
2289
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
2290
|
+
*
|
|
2291
|
+
*/
|
|
2292
|
+
get active_state_style() {
|
|
2293
|
+
return this._active_state_style;
|
|
2294
|
+
}
|
|
2295
|
+
/********
|
|
2296
|
+
*
|
|
2297
|
+
* Gets the composite style for a specific node by individually imposing the
|
|
2298
|
+
* style layers on a given object, after determining which layers are
|
|
2299
|
+
* appropriate.
|
|
2300
|
+
*
|
|
2301
|
+
* The order of composition is base, then theme, then user content. Each
|
|
2302
|
+
* item in the stack will be composited independently. First, the base state
|
|
2303
|
+
* style, then the theme state style, then the user state style.
|
|
2304
|
+
*
|
|
2305
|
+
* After the three state styles, we'll composite the hooked styles; then the
|
|
2306
|
+
* terminal styles; then the start styles; then the end styles; finally, the
|
|
2307
|
+
* active styles. Remember, last wins.
|
|
2308
|
+
*
|
|
2309
|
+
* The base state style must exist. All other styles are optional.
|
|
2310
|
+
*
|
|
2311
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
2312
|
+
*
|
|
2313
|
+
*/
|
|
2314
|
+
style_for(state) {
|
|
2315
|
+
// basic state style
|
|
2316
|
+
const layers = [base_state_style];
|
|
2317
|
+
// if (theme.state_style) { layers.push(theme.state_style); }
|
|
2318
|
+
if (this._state_style) {
|
|
2319
|
+
layers.push(this._state_style);
|
|
2320
|
+
}
|
|
2321
|
+
/*
|
|
2322
|
+
// hooked state style
|
|
2323
|
+
if (this.has_hooks(state)) {
|
|
2324
|
+
layers.push(base_hooked_state_style);
|
|
2325
|
+
// if (theme.hooked_state_style) { layers.push(theme.hooked_state_style); }
|
|
2326
|
+
if (this._hooked_state_style) { layers.push(this._hooked_state_style); }
|
|
2327
|
+
}
|
|
2328
|
+
*/
|
|
2329
|
+
// terminal state style
|
|
2330
|
+
if (this.state_is_terminal(state)) {
|
|
2331
|
+
layers.push(base_terminal_state_style);
|
|
2332
|
+
// if (theme.terminal_state_style) { layers.push(theme.terminal_state_style); }
|
|
2333
|
+
if (this._terminal_state_style) {
|
|
2334
|
+
layers.push(this._terminal_state_style);
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
// start state style
|
|
2338
|
+
if (this.is_start_state(state)) {
|
|
2339
|
+
layers.push(base_start_state_style);
|
|
2340
|
+
// if (theme.start_state_style) { layers.push(theme.start_state_style); }
|
|
2341
|
+
if (this._start_state_style) {
|
|
2342
|
+
layers.push(this._start_state_style);
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
// end state style
|
|
2346
|
+
if (this.is_end_state(state)) {
|
|
2347
|
+
layers.push(base_end_state_style);
|
|
2348
|
+
// if (theme.end_state_style) { layers.push(theme.end_state_style); }
|
|
2349
|
+
if (this._end_state_style) {
|
|
2350
|
+
layers.push(this._end_state_style);
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
// active state style
|
|
2354
|
+
if (this.state() === state) {
|
|
2355
|
+
layers.push(base_active_state_style);
|
|
2356
|
+
// if (theme.active_state_style) { layers.push(theme.active_state_style); }
|
|
2357
|
+
if (this._active_state_style) {
|
|
2358
|
+
layers.push(this._active_state_style);
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
return layers.reduce((acc, cur) => {
|
|
2362
|
+
const composite_state = acc;
|
|
2363
|
+
Object.keys(cur).forEach(key => composite_state[key] = cur[key]);
|
|
2364
|
+
return composite_state;
|
|
2365
|
+
}, {});
|
|
2366
|
+
}
|
|
2006
2367
|
/********
|
|
2007
2368
|
*
|
|
2008
2369
|
* Instruct the machine to complete an action. Synonym for {@link action}.
|
|
@@ -2277,4 +2638,4 @@ function deserialize(machine_string, ser) {
|
|
|
2277
2638
|
}
|
|
2278
2639
|
export { version, transfer_state_properties, Machine, deserialize, make, wrap_parse as parse, compile, sm, from, arrow_direction, arrow_left_kind, arrow_right_kind,
|
|
2279
2640
|
// WHARGARBL TODO these should be exported to a utility library
|
|
2280
|
-
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 };
|
|
2641
|
+
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 };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { JssmStateConfig } from './jssm_types';
|
|
2
|
+
declare const base_state_style: JssmStateConfig;
|
|
3
|
+
declare const base_active_state_style: JssmStateConfig;
|
|
4
|
+
declare const base_terminal_state_style: JssmStateConfig;
|
|
5
|
+
declare const base_active_terminal_state_style: JssmStateConfig;
|
|
6
|
+
declare const base_start_state_style: JssmStateConfig;
|
|
7
|
+
declare const base_active_start_state_style: JssmStateConfig;
|
|
8
|
+
declare const base_end_state_style: JssmStateConfig;
|
|
9
|
+
declare const base_active_end_state_style: JssmStateConfig;
|
|
10
|
+
export { base_state_style, base_active_state_style, base_terminal_state_style, base_active_terminal_state_style, base_start_state_style, base_active_start_state_style, base_end_state_style, base_active_end_state_style };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const base_state_style = {
|
|
2
|
+
shape: 'rectangle',
|
|
3
|
+
backgroundColor: 'khaki',
|
|
4
|
+
textColor: 'black',
|
|
5
|
+
borderColor: 'black'
|
|
6
|
+
};
|
|
7
|
+
const base_active_state_style = {
|
|
8
|
+
textColor: 'white',
|
|
9
|
+
backgroundColor: 'dodgerblue4'
|
|
10
|
+
};
|
|
11
|
+
const base_terminal_state_style = {
|
|
12
|
+
textColor: 'white',
|
|
13
|
+
backgroundColor: 'crimson'
|
|
14
|
+
};
|
|
15
|
+
const base_active_terminal_state_style = {
|
|
16
|
+
textColor: 'white',
|
|
17
|
+
backgroundColor: 'indigo'
|
|
18
|
+
};
|
|
19
|
+
const base_start_state_style = {
|
|
20
|
+
backgroundColor: 'yellow'
|
|
21
|
+
};
|
|
22
|
+
const base_active_start_state_style = {
|
|
23
|
+
backgroundColor: 'yellowgreen'
|
|
24
|
+
};
|
|
25
|
+
const base_end_state_style = {
|
|
26
|
+
textColor: 'white',
|
|
27
|
+
backgroundColor: 'darkolivegreen'
|
|
28
|
+
};
|
|
29
|
+
const base_active_end_state_style = {
|
|
30
|
+
textColor: 'white',
|
|
31
|
+
backgroundColor: 'darkgreen'
|
|
32
|
+
};
|
|
33
|
+
export { base_state_style, base_active_state_style, base_terminal_state_style, base_active_terminal_state_style, base_start_state_style, base_active_start_state_style, base_end_state_style, base_active_end_state_style };
|
package/dist/es6/jssm_types.d.ts
CHANGED
|
@@ -105,7 +105,7 @@ declare type JssmStateDeclaration = {
|
|
|
105
105
|
shape?: JssmShape;
|
|
106
106
|
color?: JssmColor;
|
|
107
107
|
corners?: JssmCorner;
|
|
108
|
-
|
|
108
|
+
lineStyle?: JssmLineStyle;
|
|
109
109
|
textColor?: JssmColor;
|
|
110
110
|
backgroundColor?: JssmColor;
|
|
111
111
|
borderColor?: JssmColor;
|
|
@@ -115,6 +115,37 @@ declare type JssmStateDeclaration = {
|
|
|
115
115
|
value: unknown;
|
|
116
116
|
};
|
|
117
117
|
};
|
|
118
|
+
declare type JssmStateConfig = Partial<JssmStateDeclaration>;
|
|
119
|
+
declare type JssmStateStyleShape = {
|
|
120
|
+
key: 'shape';
|
|
121
|
+
value: JssmShape;
|
|
122
|
+
};
|
|
123
|
+
declare type JssmStateStyleColor = {
|
|
124
|
+
key: 'color';
|
|
125
|
+
value: JssmColor;
|
|
126
|
+
};
|
|
127
|
+
declare type JssmStateStyleTextColor = {
|
|
128
|
+
key: 'text-color';
|
|
129
|
+
value: JssmColor;
|
|
130
|
+
};
|
|
131
|
+
declare type JssmStateStyleCorners = {
|
|
132
|
+
key: 'corners';
|
|
133
|
+
value: JssmCorner;
|
|
134
|
+
};
|
|
135
|
+
declare type JssmStateStyleLineStyle = {
|
|
136
|
+
key: 'line-style';
|
|
137
|
+
value: JssmLineStyle;
|
|
138
|
+
};
|
|
139
|
+
declare type JssmStateStyleBackgroundColor = {
|
|
140
|
+
key: 'background-color';
|
|
141
|
+
value: JssmColor;
|
|
142
|
+
};
|
|
143
|
+
declare type JssmStateStyleBorderColor = {
|
|
144
|
+
key: 'border-color';
|
|
145
|
+
value: JssmColor;
|
|
146
|
+
};
|
|
147
|
+
declare type JssmStateStyleKey = JssmStateStyleShape | JssmStateStyleColor | JssmStateStyleTextColor | JssmStateStyleCorners | JssmStateStyleLineStyle | JssmStateStyleBackgroundColor | JssmStateStyleBorderColor;
|
|
148
|
+
declare type JssmStateStyleKeyList = JssmStateStyleKey[];
|
|
118
149
|
declare type JssmGenericConfig<DataType> = {
|
|
119
150
|
graph_layout?: JssmLayout;
|
|
120
151
|
complete?: Array<StateType>;
|
|
@@ -152,6 +183,12 @@ declare type JssmGenericConfig<DataType> = {
|
|
|
152
183
|
fsl_version?: string;
|
|
153
184
|
auto_api?: boolean | string;
|
|
154
185
|
instance_name?: string | undefined;
|
|
186
|
+
default_state_config?: JssmStateStyleKeyList;
|
|
187
|
+
default_start_state_config?: JssmStateStyleKeyList;
|
|
188
|
+
default_end_state_config?: JssmStateStyleKeyList;
|
|
189
|
+
default_hooked_state_config?: JssmStateStyleKeyList;
|
|
190
|
+
default_terminal_state_config?: JssmStateStyleKeyList;
|
|
191
|
+
default_active_state_config?: JssmStateStyleKeyList;
|
|
155
192
|
};
|
|
156
193
|
declare type JssmCompileRule = {
|
|
157
194
|
agg_as: string;
|
|
@@ -290,4 +327,4 @@ declare type JssmErrorExtendedInfo = {
|
|
|
290
327
|
requested_state?: StateType | undefined;
|
|
291
328
|
};
|
|
292
329
|
declare type JssmHistory<mDT> = circular_buffer<[StateType, mDT]>;
|
|
293
|
-
export { JssmColor, JssmShape, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmLayout, JssmHistory, JssmSerialization, JssmPropertyDefinition, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirection, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult };
|
|
330
|
+
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, JssmLayout, JssmHistory, JssmSerialization, JssmPropertyDefinition, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirection, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult };
|
package/dist/es6/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = "5.
|
|
1
|
+
const version = "5.80.0";
|
|
2
2
|
export { version };
|