jssm 5.162.9 → 5.162.11

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.
@@ -69,6 +69,27 @@ type JssmDefaultSize = {
69
69
  width?: number;
70
70
  height?: number;
71
71
  };
72
+ /**
73
+ * A parsed semantic-version breakdown, as produced by the FSL parser for
74
+ * version-valued directives (`machine_version`, `fsl_version`). `major`,
75
+ * `minor`, and `patch` are the three numeric components; `full` preserves
76
+ * the exact source text of the version. `loc` is present only when the
77
+ * source was parsed with `{ locations: true }`.
78
+ *
79
+ * ```typescript
80
+ * const m = sm`machine_version: 1.2.3; a -> b;`;
81
+ * m.machine_version(); // { major: 1, minor: 2, patch: 3, full: '1.2.3' }
82
+ * ```
83
+ * @see Machine.machine_version
84
+ * @see Machine.fsl_version
85
+ */
86
+ type JssmParsedSemver = {
87
+ major: number;
88
+ minor: number;
89
+ patch: number;
90
+ full: string;
91
+ loc?: FslSourceLocation;
92
+ };
72
93
  /**
73
94
  * Runtime-iterable list of valid `flow` directions for FSL diagrams.
74
95
  * Use this when you need to enumerate directions; for the type itself
@@ -559,10 +580,10 @@ type JssmGenericConfig<StateType, DataType> = {
559
580
  machine_language?: string;
560
581
  machine_license?: string;
561
582
  machine_name?: string;
562
- machine_version?: string;
583
+ machine_version?: JssmParsedSemver;
563
584
  npm_name?: string;
564
585
  default_size?: JssmDefaultSize;
565
- fsl_version?: string;
586
+ fsl_version?: JssmParsedSemver;
566
587
  auto_api?: boolean | string;
567
588
  instance_name?: string | undefined;
568
589
  default_state_config?: JssmStateStyleKeyList;
@@ -1225,10 +1246,10 @@ declare class Machine<mDT> {
1225
1246
  _machine_language?: string;
1226
1247
  _machine_license?: string;
1227
1248
  _machine_name?: string;
1228
- _machine_version?: string;
1249
+ _machine_version?: JssmParsedSemver;
1229
1250
  _npm_name?: string;
1230
1251
  _default_size?: JssmDefaultSize;
1231
- _fsl_version?: string;
1252
+ _fsl_version?: JssmParsedSemver;
1232
1253
  _raw_state_declaration?: Array<object>;
1233
1254
  _state_declarations: Map<StateType, JssmStateDeclaration>;
1234
1255
  _data?: mDT;
@@ -1851,10 +1872,18 @@ declare class Machine<mDT> {
1851
1872
  */
1852
1873
  default_size(): JssmDefaultSize | undefined;
1853
1874
  /**
1854
- * Get the machine's version string. Set via the FSL `machine_version` directive.
1855
- * @returns The version string.
1875
+ * Get the machine's declared version, parsed. Set via the FSL
1876
+ * `machine_version` directive, which takes a semver triple; the parser
1877
+ * breaks it into numeric `major`/`minor`/`patch` fields and keeps the
1878
+ * exact source text in `full`. Returns `undefined` when the directive
1879
+ * was not given.
1880
+ * @returns The parsed {@link JssmParsedSemver}, or `undefined` if unset.
1881
+ * @example
1882
+ * const m = sm`machine_version: 1.2.3; a -> b;`;
1883
+ * m.machine_version(); // => { major: 1, minor: 2, patch: 3, full: '1.2.3' }
1884
+ * @see fsl_version
1856
1885
  */
1857
- machine_version(): string;
1886
+ machine_version(): JssmParsedSemver | undefined;
1858
1887
  /**
1859
1888
  * Get the raw state declaration objects as parsed from the FSL source.
1860
1889
  * @returns An array of raw state declaration objects.
@@ -1872,10 +1901,18 @@ declare class Machine<mDT> {
1872
1901
  */
1873
1902
  state_declarations(): Map<StateType, JssmStateDeclaration>;
1874
1903
  /**
1875
- * Get the FSL language version this machine was compiled under.
1876
- * @returns The FSL version string.
1904
+ * Get the FSL language version this machine declares, parsed. Set via
1905
+ * the FSL `fsl_version` directive, which takes a semver triple; the
1906
+ * parser breaks it into numeric `major`/`minor`/`patch` fields and keeps
1907
+ * the exact source text in `full`. Returns `undefined` when the
1908
+ * directive was not given.
1909
+ * @returns The parsed {@link JssmParsedSemver}, or `undefined` if unset.
1910
+ * @example
1911
+ * const m = sm`fsl_version: 1.0.0; a -> b;`;
1912
+ * m.fsl_version(); // => { major: 1, minor: 0, patch: 0, full: '1.0.0' }
1913
+ * @see machine_version
1877
1914
  */
1878
- fsl_version(): string;
1915
+ fsl_version(): JssmParsedSemver | undefined;
1879
1916
  /**
1880
1917
  * Get the complete internal state of the machine as a serializable
1881
1918
  * structure. Includes actions, edges, edge map, named transitions,
@@ -2078,7 +2115,19 @@ declare class Machine<mDT> {
2078
2115
  get themes(): FslTheme | FslTheme[];
2079
2116
  /**
2080
2117
  * Set the active theme(s). Accepts a single theme name or an array.
2118
+ * Also drops every memoized static state config, so styles resolved
2119
+ * before the change re-resolve under the new theme stack.
2120
+ *
2121
+ * ```typescript
2122
+ * const m = sm`a -> b;`;
2123
+ * m.style_for('b'); // resolved under the default theme
2124
+ * m.themes = 'ocean';
2125
+ * m.style_for('b').backgroundColor; // 'cadetblue1' — ocean, not a stale default
2126
+ * ```
2127
+ *
2081
2128
  * @param to - A theme name or array of theme names to apply.
2129
+ *
2130
+ * @see resolve_state_config
2082
2131
  */
2083
2132
  set themes(to: FslTheme | FslTheme[]);
2084
2133
  /**
@@ -2188,10 +2237,34 @@ declare class Machine<mDT> {
2188
2237
  * @throws {JssmError} If the state does not exist.
2189
2238
  */
2190
2239
  probable_exits_for(whichState: StateType): Array<JssmTransition<StateType, mDT>>;
2240
+ /**
2241
+ * Guard for the random-selection paths ({@link Machine.probabilistic_transition},
2242
+ * {@link Machine.stochastic_runs}): rejects a candidate pool whose total
2243
+ * selectable weight is zero, because weighted selection over an all-zero
2244
+ * pool has no meaningful answer (StoneCypher/fsl#1248). Undeclared
2245
+ * probabilities count as weight 1, matching {@link weighted_rand_select}.
2246
+ * An empty pool is not this guard's concern (terminality is handled by the
2247
+ * callers) and passes through untouched.
2248
+ *
2249
+ * ```typescript
2250
+ * const m = sm`a 0% -> b; a 0% -> c;`;
2251
+ * m.probabilistic_transition(); // throws JssmError — every exit is 0%
2252
+ * ```
2253
+ * @param whichState - The state the pool exits from, named in the error.
2254
+ * @param exits - The candidate pool, as built by {@link Machine.probable_exits_for}.
2255
+ * @throws {JssmError} If the pool is non-empty and every candidate edge
2256
+ * has probability 0 — including the case where explicit `0%` edges
2257
+ * excluded their unweighted sibling edges from the candidate pool.
2258
+ * @see probable_exits_for
2259
+ */
2260
+ private _assert_selectable_exit_pool;
2191
2261
  /**
2192
2262
  * Take a single random transition from the current state, weighted by
2193
2263
  * edge probabilities.
2194
2264
  * @returns `true` if a transition was taken, `false` otherwise.
2265
+ * @throws {JssmError} If the candidate exit pool is non-empty but its
2266
+ * total weight is zero — every candidate declares `0%` — per
2267
+ * StoneCypher/fsl#1248.
2195
2268
  */
2196
2269
  probabilistic_transition(): boolean;
2197
2270
  /**
@@ -2199,6 +2272,8 @@ declare class Machine<mDT> {
2199
2272
  * of states visited (before each transition).
2200
2273
  * @param n - Number of steps to walk.
2201
2274
  * @returns An array of state names visited during the walk.
2275
+ * @throws {JssmError} If a visited state's candidate exit pool is
2276
+ * non-empty but all-zero-weight (StoneCypher/fsl#1248).
2202
2277
  */
2203
2278
  probabilistic_walk(n: number): Array<StateType>;
2204
2279
  /**
@@ -2206,6 +2281,8 @@ declare class Machine<mDT> {
2206
2281
  * each state was visited.
2207
2282
  * @param n - Number of steps to walk.
2208
2283
  * @returns A `Map` from state name to visit count.
2284
+ * @throws {JssmError} If a visited state's candidate exit pool is
2285
+ * non-empty but all-zero-weight (StoneCypher/fsl#1248).
2209
2286
  */
2210
2287
  probabilistic_histo_walk(n: number): Map<StateType, number>;
2211
2288
  /**
@@ -2225,6 +2302,9 @@ declare class Machine<mDT> {
2225
2302
  * the derived arrays — RNG draw order is untouched, so seeded walks
2226
2303
  * reproduce exactly.
2227
2304
  * @returns The {@link JssmStochasticRun} for this walk.
2305
+ * @throws {JssmError} If a visited state's candidate exit pool is
2306
+ * non-empty but all-zero-weight — see
2307
+ * {@link Machine._assert_selectable_exit_pool} (StoneCypher/fsl#1248).
2228
2308
  */
2229
2309
  private _stochastic_one_walk;
2230
2310
  /**
@@ -3391,8 +3471,12 @@ declare class Machine<mDT> {
3391
3471
  * For any state OTHER than the current one, this returns the memoized static
3392
3472
  * resolution (tiers 1–5; see `_compose_state_config`) — theme →
3393
3473
  * `default_state_config` → per-kind defaults → depth-ordered group metadata →
3394
- * per-state config. The cache is keyed by state and never invalidated, since
3395
- * those tiers do not depend on which state is current.
3474
+ * per-state config. The cache is keyed by state; those tiers do not depend
3475
+ * on which state is current, so it survives transitions, but the mutable
3476
+ * cascade inputs each clear it when they change — hook registration and
3477
+ * removal ({@link Machine.set_hook}, {@link Machine.remove_hook}; the
3478
+ * hooked layer) and theme assignment (the `themes` setter; tier 1 and the
3479
+ * per-kind theme layers).
3396
3480
  *
3397
3481
  * For the machine's CURRENTLY-occupied state the result is recomputed each
3398
3482
  * call (never cached) and additionally carries the dynamic `active_state`
package/jssm_viz.es6.d.ts CHANGED
@@ -69,6 +69,27 @@ type JssmDefaultSize = {
69
69
  width?: number;
70
70
  height?: number;
71
71
  };
72
+ /**
73
+ * A parsed semantic-version breakdown, as produced by the FSL parser for
74
+ * version-valued directives (`machine_version`, `fsl_version`). `major`,
75
+ * `minor`, and `patch` are the three numeric components; `full` preserves
76
+ * the exact source text of the version. `loc` is present only when the
77
+ * source was parsed with `{ locations: true }`.
78
+ *
79
+ * ```typescript
80
+ * const m = sm`machine_version: 1.2.3; a -> b;`;
81
+ * m.machine_version(); // { major: 1, minor: 2, patch: 3, full: '1.2.3' }
82
+ * ```
83
+ * @see Machine.machine_version
84
+ * @see Machine.fsl_version
85
+ */
86
+ type JssmParsedSemver = {
87
+ major: number;
88
+ minor: number;
89
+ patch: number;
90
+ full: string;
91
+ loc?: FslSourceLocation;
92
+ };
72
93
  /**
73
94
  * Runtime-iterable list of valid `flow` directions for FSL diagrams.
74
95
  * Use this when you need to enumerate directions; for the type itself
@@ -559,10 +580,10 @@ type JssmGenericConfig<StateType, DataType> = {
559
580
  machine_language?: string;
560
581
  machine_license?: string;
561
582
  machine_name?: string;
562
- machine_version?: string;
583
+ machine_version?: JssmParsedSemver;
563
584
  npm_name?: string;
564
585
  default_size?: JssmDefaultSize;
565
- fsl_version?: string;
586
+ fsl_version?: JssmParsedSemver;
566
587
  auto_api?: boolean | string;
567
588
  instance_name?: string | undefined;
568
589
  default_state_config?: JssmStateStyleKeyList;
@@ -1225,10 +1246,10 @@ declare class Machine<mDT> {
1225
1246
  _machine_language?: string;
1226
1247
  _machine_license?: string;
1227
1248
  _machine_name?: string;
1228
- _machine_version?: string;
1249
+ _machine_version?: JssmParsedSemver;
1229
1250
  _npm_name?: string;
1230
1251
  _default_size?: JssmDefaultSize;
1231
- _fsl_version?: string;
1252
+ _fsl_version?: JssmParsedSemver;
1232
1253
  _raw_state_declaration?: Array<object>;
1233
1254
  _state_declarations: Map<StateType, JssmStateDeclaration>;
1234
1255
  _data?: mDT;
@@ -1851,10 +1872,18 @@ declare class Machine<mDT> {
1851
1872
  */
1852
1873
  default_size(): JssmDefaultSize | undefined;
1853
1874
  /**
1854
- * Get the machine's version string. Set via the FSL `machine_version` directive.
1855
- * @returns The version string.
1875
+ * Get the machine's declared version, parsed. Set via the FSL
1876
+ * `machine_version` directive, which takes a semver triple; the parser
1877
+ * breaks it into numeric `major`/`minor`/`patch` fields and keeps the
1878
+ * exact source text in `full`. Returns `undefined` when the directive
1879
+ * was not given.
1880
+ * @returns The parsed {@link JssmParsedSemver}, or `undefined` if unset.
1881
+ * @example
1882
+ * const m = sm`machine_version: 1.2.3; a -> b;`;
1883
+ * m.machine_version(); // => { major: 1, minor: 2, patch: 3, full: '1.2.3' }
1884
+ * @see fsl_version
1856
1885
  */
1857
- machine_version(): string;
1886
+ machine_version(): JssmParsedSemver | undefined;
1858
1887
  /**
1859
1888
  * Get the raw state declaration objects as parsed from the FSL source.
1860
1889
  * @returns An array of raw state declaration objects.
@@ -1872,10 +1901,18 @@ declare class Machine<mDT> {
1872
1901
  */
1873
1902
  state_declarations(): Map<StateType, JssmStateDeclaration>;
1874
1903
  /**
1875
- * Get the FSL language version this machine was compiled under.
1876
- * @returns The FSL version string.
1904
+ * Get the FSL language version this machine declares, parsed. Set via
1905
+ * the FSL `fsl_version` directive, which takes a semver triple; the
1906
+ * parser breaks it into numeric `major`/`minor`/`patch` fields and keeps
1907
+ * the exact source text in `full`. Returns `undefined` when the
1908
+ * directive was not given.
1909
+ * @returns The parsed {@link JssmParsedSemver}, or `undefined` if unset.
1910
+ * @example
1911
+ * const m = sm`fsl_version: 1.0.0; a -> b;`;
1912
+ * m.fsl_version(); // => { major: 1, minor: 0, patch: 0, full: '1.0.0' }
1913
+ * @see machine_version
1877
1914
  */
1878
- fsl_version(): string;
1915
+ fsl_version(): JssmParsedSemver | undefined;
1879
1916
  /**
1880
1917
  * Get the complete internal state of the machine as a serializable
1881
1918
  * structure. Includes actions, edges, edge map, named transitions,
@@ -2078,7 +2115,19 @@ declare class Machine<mDT> {
2078
2115
  get themes(): FslTheme | FslTheme[];
2079
2116
  /**
2080
2117
  * Set the active theme(s). Accepts a single theme name or an array.
2118
+ * Also drops every memoized static state config, so styles resolved
2119
+ * before the change re-resolve under the new theme stack.
2120
+ *
2121
+ * ```typescript
2122
+ * const m = sm`a -> b;`;
2123
+ * m.style_for('b'); // resolved under the default theme
2124
+ * m.themes = 'ocean';
2125
+ * m.style_for('b').backgroundColor; // 'cadetblue1' — ocean, not a stale default
2126
+ * ```
2127
+ *
2081
2128
  * @param to - A theme name or array of theme names to apply.
2129
+ *
2130
+ * @see resolve_state_config
2082
2131
  */
2083
2132
  set themes(to: FslTheme | FslTheme[]);
2084
2133
  /**
@@ -2188,10 +2237,34 @@ declare class Machine<mDT> {
2188
2237
  * @throws {JssmError} If the state does not exist.
2189
2238
  */
2190
2239
  probable_exits_for(whichState: StateType): Array<JssmTransition<StateType, mDT>>;
2240
+ /**
2241
+ * Guard for the random-selection paths ({@link Machine.probabilistic_transition},
2242
+ * {@link Machine.stochastic_runs}): rejects a candidate pool whose total
2243
+ * selectable weight is zero, because weighted selection over an all-zero
2244
+ * pool has no meaningful answer (StoneCypher/fsl#1248). Undeclared
2245
+ * probabilities count as weight 1, matching {@link weighted_rand_select}.
2246
+ * An empty pool is not this guard's concern (terminality is handled by the
2247
+ * callers) and passes through untouched.
2248
+ *
2249
+ * ```typescript
2250
+ * const m = sm`a 0% -> b; a 0% -> c;`;
2251
+ * m.probabilistic_transition(); // throws JssmError — every exit is 0%
2252
+ * ```
2253
+ * @param whichState - The state the pool exits from, named in the error.
2254
+ * @param exits - The candidate pool, as built by {@link Machine.probable_exits_for}.
2255
+ * @throws {JssmError} If the pool is non-empty and every candidate edge
2256
+ * has probability 0 — including the case where explicit `0%` edges
2257
+ * excluded their unweighted sibling edges from the candidate pool.
2258
+ * @see probable_exits_for
2259
+ */
2260
+ private _assert_selectable_exit_pool;
2191
2261
  /**
2192
2262
  * Take a single random transition from the current state, weighted by
2193
2263
  * edge probabilities.
2194
2264
  * @returns `true` if a transition was taken, `false` otherwise.
2265
+ * @throws {JssmError} If the candidate exit pool is non-empty but its
2266
+ * total weight is zero — every candidate declares `0%` — per
2267
+ * StoneCypher/fsl#1248.
2195
2268
  */
2196
2269
  probabilistic_transition(): boolean;
2197
2270
  /**
@@ -2199,6 +2272,8 @@ declare class Machine<mDT> {
2199
2272
  * of states visited (before each transition).
2200
2273
  * @param n - Number of steps to walk.
2201
2274
  * @returns An array of state names visited during the walk.
2275
+ * @throws {JssmError} If a visited state's candidate exit pool is
2276
+ * non-empty but all-zero-weight (StoneCypher/fsl#1248).
2202
2277
  */
2203
2278
  probabilistic_walk(n: number): Array<StateType>;
2204
2279
  /**
@@ -2206,6 +2281,8 @@ declare class Machine<mDT> {
2206
2281
  * each state was visited.
2207
2282
  * @param n - Number of steps to walk.
2208
2283
  * @returns A `Map` from state name to visit count.
2284
+ * @throws {JssmError} If a visited state's candidate exit pool is
2285
+ * non-empty but all-zero-weight (StoneCypher/fsl#1248).
2209
2286
  */
2210
2287
  probabilistic_histo_walk(n: number): Map<StateType, number>;
2211
2288
  /**
@@ -2225,6 +2302,9 @@ declare class Machine<mDT> {
2225
2302
  * the derived arrays — RNG draw order is untouched, so seeded walks
2226
2303
  * reproduce exactly.
2227
2304
  * @returns The {@link JssmStochasticRun} for this walk.
2305
+ * @throws {JssmError} If a visited state's candidate exit pool is
2306
+ * non-empty but all-zero-weight — see
2307
+ * {@link Machine._assert_selectable_exit_pool} (StoneCypher/fsl#1248).
2228
2308
  */
2229
2309
  private _stochastic_one_walk;
2230
2310
  /**
@@ -3391,8 +3471,12 @@ declare class Machine<mDT> {
3391
3471
  * For any state OTHER than the current one, this returns the memoized static
3392
3472
  * resolution (tiers 1–5; see `_compose_state_config`) — theme →
3393
3473
  * `default_state_config` → per-kind defaults → depth-ordered group metadata →
3394
- * per-state config. The cache is keyed by state and never invalidated, since
3395
- * those tiers do not depend on which state is current.
3474
+ * per-state config. The cache is keyed by state; those tiers do not depend
3475
+ * on which state is current, so it survives transitions, but the mutable
3476
+ * cascade inputs each clear it when they change — hook registration and
3477
+ * removal ({@link Machine.set_hook}, {@link Machine.remove_hook}; the
3478
+ * hooked layer) and theme assignment (the `themes` setter; tier 1 and the
3479
+ * per-kind theme layers).
3396
3480
  *
3397
3481
  * For the machine's CURRENTLY-occupied state the result is recomputed each
3398
3482
  * call (never cached) and additionally carries the dynamic `active_state`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jssm",
3
- "version": "5.162.9",
3
+ "version": "5.162.11",
4
4
  "engines": {
5
5
  "node": ">=10.0.0"
6
6
  },