jssm 5.80.0 → 5.81.2

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.
@@ -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}:
@@ -266,6 +266,7 @@ declare class Machine<mDT> {
266
266
  _terminal_state_style: JssmStateConfig;
267
267
  _start_state_style: JssmStateConfig;
268
268
  _end_state_style: JssmStateConfig;
269
+ _state_labels: Map<string, string>;
269
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>);
270
271
  /********
271
272
  *
@@ -282,17 +283,32 @@ declare class Machine<mDT> {
282
283
  * ```typescript
283
284
  * import * as jssm from 'jssm';
284
285
  *
285
- * const switch = jssm.from('on <=> off;');
286
- * console.log( switch.state() ); // 'on'
286
+ * const lswitch = jssm.from('on <=> off;');
287
+ * console.log( lswitch.state() ); // 'on'
287
288
  *
288
- * switch.transition('off');
289
- * console.log( switch.state() ); // 'off'
289
+ * lswitch.transition('off');
290
+ * console.log( lswitch.state() ); // 'off'
290
291
  * ```
291
292
  *
292
293
  * @typeparam mDT The type of the machine data member; usually omitted
293
294
  *
294
295
  */
295
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;
296
312
  /*********
297
313
  *
298
314
  * Get the current data of a machine.
@@ -300,8 +316,8 @@ declare class Machine<mDT> {
300
316
  * ```typescript
301
317
  * import * as jssm from 'jssm';
302
318
  *
303
- * const switch = jssm.from('on <=> off;', {data: 1});
304
- * console.log( switch.data() ); // 1
319
+ * const lswitch = jssm.from('on <=> off;', {data: 1});
320
+ * console.log( lswitch.data() ); // 1
305
321
  * ```
306
322
  *
307
323
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -545,8 +561,8 @@ declare class Machine<mDT> {
545
561
  * ```typescript
546
562
  * import * as jssm from 'jssm';
547
563
  *
548
- * const switch = jssm.from('on <=> off;');
549
- * console.log( switch.states() ); // ['on', 'off']
564
+ * const lswitch = jssm.from('on <=> off;');
565
+ * console.log( lswitch.states() ); // ['on', 'off']
550
566
  * ```
551
567
  *
552
568
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -561,10 +577,10 @@ declare class Machine<mDT> {
561
577
  * ```typescript
562
578
  * import * as jssm from 'jssm';
563
579
  *
564
- * const switch = jssm.from('on <=> off;');
580
+ * const lswitch = jssm.from('on <=> off;');
565
581
  *
566
- * console.log( switch.has_state('off') ); // true
567
- * console.log( switch.has_state('dance') ); // false
582
+ * console.log( lswitch.has_state('off') ); // true
583
+ * console.log( lswitch.has_state('dance') ); // false
568
584
  * ```
569
585
  *
570
586
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -1155,7 +1171,7 @@ declare class Machine<mDT> {
1155
1171
  * ```typescript
1156
1172
  * import * as jssm from 'jssm';
1157
1173
  *
1158
- * const switch = jssm.from('on <=> off;');
1174
+ * const lswitch = jssm.from('on <=> off;');
1159
1175
  * ```
1160
1176
  *
1161
1177
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -1178,7 +1194,7 @@ declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: a
1178
1194
  * ```typescript
1179
1195
  * import * as jssm from 'jssm';
1180
1196
  *
1181
- * const switch = jssm.from('on <=> off;');
1197
+ * const lswitch = jssm.from('on <=> off;');
1182
1198
  * ```
1183
1199
  *
1184
1200
  * @typeparam mDT The type of the machine data member; usually omitted
package/dist/es6/jssm.js CHANGED
@@ -272,7 +272,7 @@ function makeTransition(this_se, from, to, isRight, _wasList, _wasIndex) {
272
272
  * ```typescript
273
273
  * import { sm } from 'jssm';
274
274
  *
275
- * const switch = sm`on <=> off;`;
275
+ * const lswitch = sm`on <=> off;`;
276
276
  * ```
277
277
  *
278
278
  * Method {@link from}:
@@ -424,7 +424,7 @@ function compile_rule_handler(rule) {
424
424
  * ```typescript
425
425
  * import { sm } from 'jssm';
426
426
  *
427
- * const switch = sm`on <=> off;`;
427
+ * const lswitch = sm`on <=> off;`;
428
428
  * ```
429
429
  *
430
430
  * Method {@link from}:
@@ -574,6 +574,9 @@ function transfer_state_properties(state_decl) {
574
574
  case 'background-color':
575
575
  state_decl.backgroundColor = d.value;
576
576
  break;
577
+ case 'state-label':
578
+ state_decl.stateLabel = d.value;
579
+ break;
577
580
  case 'border-color':
578
581
  state_decl.borderColor = d.value;
579
582
  break;
@@ -629,6 +632,12 @@ function state_style_condense(jssk) {
629
632
  }
630
633
  state_style.backgroundColor = key.value;
631
634
  break;
635
+ case 'state-label':
636
+ if (state_style.stateLabel !== undefined) {
637
+ throw new JssmError(this, `cannot redefine 'state-label' in state_style_condense, already defined`);
638
+ }
639
+ state_style.stateLabel = key.value;
640
+ break;
632
641
  case 'border-color':
633
642
  if (state_style.borderColor !== undefined) {
634
643
  throw new JssmError(this, `cannot redefine 'border-color' in state_style_condense, already defined`);
@@ -731,6 +740,8 @@ class Machine {
731
740
  this._end_state_style = state_style_condense(default_end_state_config);
732
741
  this._history_length = history || 0;
733
742
  this._history = new circular_buffer(this._history_length);
743
+ this._state_labels = new Map();
744
+ // consolidate the state declarations
734
745
  if (state_declaration) {
735
746
  state_declaration.map((state_decl) => {
736
747
  if (this._state_declarations.has(state_decl.state)) { // no repeats
@@ -739,6 +750,17 @@ class Machine {
739
750
  this._state_declarations.set(state_decl.state, transfer_state_properties(state_decl));
740
751
  });
741
752
  }
753
+ // walk the decls for labels; aggregate them when found
754
+ [...this._state_declarations].map(sd => {
755
+ const [key, decl] = sd, labelled = decl.declarations.filter(d => d.key === 'state-label');
756
+ if (labelled.length > 1) {
757
+ throw new JssmError(this, `state ${key} may only have one state-label; has ${labelled.length}`);
758
+ }
759
+ if (labelled.length === 1) {
760
+ this._state_labels.set(key, labelled[0].value);
761
+ }
762
+ });
763
+ // walk the transitions
742
764
  transitions.map((tr) => {
743
765
  if (tr.from === undefined) {
744
766
  throw new JssmError(this, `transition must define 'from': ${JSON.stringify(tr)}`);
@@ -890,11 +912,11 @@ class Machine {
890
912
  * ```typescript
891
913
  * import * as jssm from 'jssm';
892
914
  *
893
- * const switch = jssm.from('on <=> off;');
894
- * console.log( switch.state() ); // 'on'
915
+ * const lswitch = jssm.from('on <=> off;');
916
+ * console.log( lswitch.state() ); // 'on'
895
917
  *
896
- * switch.transition('off');
897
- * console.log( switch.state() ); // 'off'
918
+ * lswitch.transition('off');
919
+ * console.log( lswitch.state() ); // 'off'
898
920
  * ```
899
921
  *
900
922
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -903,13 +925,23 @@ class Machine {
903
925
  state() {
904
926
  return this._state;
905
927
  }
906
- /* whargarbl todo major
907
- when we reimplement this, reintroduce this change to the is_final call
908
-
909
- is_changing(): boolean {
910
- return true; // todo whargarbl
911
- }
912
- */
928
+ /*********
929
+ *
930
+ * Get the label for a given state, if any; return `undefined` otherwise.
931
+ *
932
+ * ```typescript
933
+ * import * as jssm from 'jssm';
934
+ *
935
+ * const lswitch = jssm.from('a -> b; state a: { label: "Foo!"; };');
936
+ * console.log( lswitch.label_for('a') ); // 'Foo!'
937
+ * ```
938
+ *
939
+ * @typeparam mDT The type of the machine data member; usually omitted
940
+ *
941
+ */
942
+ label_for(state) {
943
+ return this._state_labels.get(state);
944
+ }
913
945
  /*********
914
946
  *
915
947
  * Get the current data of a machine.
@@ -917,8 +949,8 @@ class Machine {
917
949
  * ```typescript
918
950
  * import * as jssm from 'jssm';
919
951
  *
920
- * const switch = jssm.from('on <=> off;', {data: 1});
921
- * console.log( switch.data() ); // 1
952
+ * const lswitch = jssm.from('on <=> off;', {data: 1});
953
+ * console.log( lswitch.data() ); // 1
922
954
  * ```
923
955
  *
924
956
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -927,13 +959,6 @@ class Machine {
927
959
  data() {
928
960
  return this._data;
929
961
  }
930
- /* whargarbl todo major
931
- when we reimplement this, reintroduce this change to the is_final call
932
-
933
- is_changing(): boolean {
934
- return true; // todo whargarbl
935
- }
936
- */
937
962
  // NEEDS_DOCS
938
963
  /*********
939
964
  *
@@ -1273,8 +1298,8 @@ class Machine {
1273
1298
  * ```typescript
1274
1299
  * import * as jssm from 'jssm';
1275
1300
  *
1276
- * const switch = jssm.from('on <=> off;');
1277
- * console.log( switch.states() ); // ['on', 'off']
1301
+ * const lswitch = jssm.from('on <=> off;');
1302
+ * console.log( lswitch.states() ); // ['on', 'off']
1278
1303
  * ```
1279
1304
  *
1280
1305
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -1299,10 +1324,10 @@ class Machine {
1299
1324
  * ```typescript
1300
1325
  * import * as jssm from 'jssm';
1301
1326
  *
1302
- * const switch = jssm.from('on <=> off;');
1327
+ * const lswitch = jssm.from('on <=> off;');
1303
1328
  *
1304
- * console.log( switch.has_state('off') ); // true
1305
- * console.log( switch.has_state('dance') ); // false
1329
+ * console.log( lswitch.has_state('off') ); // true
1330
+ * console.log( lswitch.has_state('dance') ); // false
1306
1331
  * ```
1307
1332
  *
1308
1333
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -2358,9 +2383,18 @@ class Machine {
2358
2383
  layers.push(this._active_state_style);
2359
2384
  }
2360
2385
  }
2386
+ const individual_style = {}, decl = this._state_declarations.get(state);
2387
+ individual_style.color = decl === null || decl === void 0 ? void 0 : decl.color;
2388
+ individual_style.textColor = decl === null || decl === void 0 ? void 0 : decl.textColor;
2389
+ individual_style.borderColor = decl === null || decl === void 0 ? void 0 : decl.borderColor;
2390
+ individual_style.backgroundColor = decl === null || decl === void 0 ? void 0 : decl.backgroundColor;
2391
+ individual_style.lineStyle = decl === null || decl === void 0 ? void 0 : decl.lineStyle;
2392
+ individual_style.corners = decl === null || decl === void 0 ? void 0 : decl.corners;
2393
+ individual_style.shape = decl === null || decl === void 0 ? void 0 : decl.shape;
2394
+ layers.push(individual_style);
2361
2395
  return layers.reduce((acc, cur) => {
2362
2396
  const composite_state = acc;
2363
- Object.keys(cur).forEach(key => composite_state[key] = cur[key]);
2397
+ Object.keys(cur).forEach(key => { var _a; return composite_state[key] = (_a = cur[key]) !== null && _a !== void 0 ? _a : composite_state[key]; });
2364
2398
  return composite_state;
2365
2399
  }, {});
2366
2400
  }
@@ -2534,7 +2568,7 @@ class Machine {
2534
2568
  * ```typescript
2535
2569
  * import * as jssm from 'jssm';
2536
2570
  *
2537
- * const switch = jssm.from('on <=> off;');
2571
+ * const lswitch = jssm.from('on <=> off;');
2538
2572
  * ```
2539
2573
  *
2540
2574
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -2569,7 +2603,7 @@ function sm(template_strings, ...remainder /* , arguments */) {
2569
2603
  * ```typescript
2570
2604
  * import * as jssm from 'jssm';
2571
2605
  *
2572
- * const switch = jssm.from('on <=> off;');
2606
+ * const lswitch = jssm.from('on <=> off;');
2573
2607
  * ```
2574
2608
  *
2575
2609
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -1,4 +1,4 @@
1
- import { JssmStateConfig } from './jssm_types';
1
+ import { JssmStateConfig, JssmBaseTheme } from './jssm_types';
2
2
  declare const base_state_style: JssmStateConfig;
3
3
  declare const base_active_state_style: JssmStateConfig;
4
4
  declare const base_terminal_state_style: JssmStateConfig;
@@ -7,4 +7,5 @@ declare const base_start_state_style: JssmStateConfig;
7
7
  declare const base_active_start_state_style: JssmStateConfig;
8
8
  declare const base_end_state_style: JssmStateConfig;
9
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 };
10
+ declare const base_theme: JssmBaseTheme;
11
+ 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, base_theme };
@@ -8,6 +8,9 @@ const base_active_state_style = {
8
8
  textColor: 'white',
9
9
  backgroundColor: 'dodgerblue4'
10
10
  };
11
+ const base_hooked_state_style = {
12
+ shape: 'component'
13
+ };
11
14
  const base_terminal_state_style = {
12
15
  textColor: 'white',
13
16
  backgroundColor: 'crimson'
@@ -22,6 +25,9 @@ const base_start_state_style = {
22
25
  const base_active_start_state_style = {
23
26
  backgroundColor: 'yellowgreen'
24
27
  };
28
+ const base_active_hooked_state_style = {
29
+ backgroundColor: 'yellowgreen'
30
+ };
25
31
  const base_end_state_style = {
26
32
  textColor: 'white',
27
33
  backgroundColor: 'darkolivegreen'
@@ -30,4 +36,22 @@ const base_active_end_state_style = {
30
36
  textColor: 'white',
31
37
  backgroundColor: 'darkgreen'
32
38
  };
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 };
39
+ const base_theme = {
40
+ state: base_state_style,
41
+ start: base_start_state_style,
42
+ end: base_end_state_style,
43
+ terminal: base_terminal_state_style,
44
+ hooked: base_hooked_state_style,
45
+ active: base_active_state_style,
46
+ active_start: base_active_start_state_style,
47
+ active_end: base_active_end_state_style,
48
+ active_terminal: base_active_terminal_state_style,
49
+ active_hooked: base_active_hooked_state_style,
50
+ legal: undefined,
51
+ main: undefined,
52
+ forced: undefined,
53
+ action: undefined,
54
+ graph: undefined,
55
+ title: undefined // TODO FIXME
56
+ };
57
+ 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, base_theme };
@@ -106,6 +106,7 @@ declare type JssmStateDeclaration = {
106
106
  color?: JssmColor;
107
107
  corners?: JssmCorner;
108
108
  lineStyle?: JssmLineStyle;
109
+ stateLabel?: string;
109
110
  textColor?: JssmColor;
110
111
  backgroundColor?: JssmColor;
111
112
  borderColor?: JssmColor;
@@ -136,6 +137,10 @@ declare type JssmStateStyleLineStyle = {
136
137
  key: 'line-style';
137
138
  value: JssmLineStyle;
138
139
  };
140
+ declare type JssmStateStyleStateLabel = {
141
+ key: 'state-label';
142
+ value: string;
143
+ };
139
144
  declare type JssmStateStyleBackgroundColor = {
140
145
  key: 'background-color';
141
146
  value: JssmColor;
@@ -144,8 +149,27 @@ declare type JssmStateStyleBorderColor = {
144
149
  key: 'border-color';
145
150
  value: JssmColor;
146
151
  };
147
- declare type JssmStateStyleKey = JssmStateStyleShape | JssmStateStyleColor | JssmStateStyleTextColor | JssmStateStyleCorners | JssmStateStyleLineStyle | JssmStateStyleBackgroundColor | JssmStateStyleBorderColor;
152
+ declare type JssmStateStyleKey = JssmStateStyleShape | JssmStateStyleColor | JssmStateStyleTextColor | JssmStateStyleCorners | JssmStateStyleLineStyle | JssmStateStyleBackgroundColor | JssmStateStyleStateLabel | JssmStateStyleBorderColor;
148
153
  declare type JssmStateStyleKeyList = JssmStateStyleKey[];
154
+ declare type JssmBaseTheme = {
155
+ state: JssmStateConfig;
156
+ hooked: JssmStateConfig;
157
+ start: JssmStateConfig;
158
+ end: JssmStateConfig;
159
+ terminal: JssmStateConfig;
160
+ active: JssmStateConfig;
161
+ active_hooked: JssmStateConfig;
162
+ active_start: JssmStateConfig;
163
+ active_end: JssmStateConfig;
164
+ active_terminal: JssmStateConfig;
165
+ graph: undefined;
166
+ legal: undefined;
167
+ main: undefined;
168
+ forced: undefined;
169
+ action: undefined;
170
+ title: undefined;
171
+ };
172
+ declare type JssmTheme = Partial<JssmBaseTheme>;
149
173
  declare type JssmGenericConfig<DataType> = {
150
174
  graph_layout?: JssmLayout;
151
175
  complete?: Array<StateType>;
@@ -327,4 +351,4 @@ declare type JssmErrorExtendedInfo = {
327
351
  requested_state?: StateType | undefined;
328
352
  };
329
353
  declare type JssmHistory<mDT> = circular_buffer<[StateType, mDT]>;
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 };
354
+ 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, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirection, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult };
@@ -1,2 +1,2 @@
1
- const version = "5.80.0";
1
+ const version = "5.81.2";
2
2
  export { version };