jssm 5.162.11 → 5.162.13

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/jssm.es6.d.ts CHANGED
@@ -308,6 +308,32 @@ type FslSourceLocation = {
308
308
  start: FslSourcePoint;
309
309
  end: FslSourcePoint;
310
310
  };
311
+ /**
312
+ * Options accepted by the FSL parser and its {@link wrap_parse} wrapper
313
+ * (exported from the package as `parse`). Exists so the two-argument parse
314
+ * call is typed against what the parser actually reads, instead of a bare
315
+ * `object`.
316
+ *
317
+ * - `locations` — when `true`, the grammar attaches a `loc` field of type
318
+ * {@link FslSourceLocation} (plus curated `*_loc` token sub-spans) to every
319
+ * AST node. When absent or `false`, the tree is byte-for-byte identical to
320
+ * the historical location-free output.
321
+ *
322
+ * - `startRule` — honored by the generated PEG.js boilerplate, which throws
323
+ * on any rule name it doesn't expose. This grammar exposes only its
324
+ * default rule, `Document`, so the field is only useful for explicitness.
325
+ *
326
+ * ```typescript
327
+ * const [t] = parse('a -> b;', { locations: true });
328
+ * // t.loc === { start: { offset: 0, line: 1, column: 1 },
329
+ * // end: { offset: 7, line: 1, column: 8 } }
330
+ * ```
331
+ * @see FslSourceLocation
332
+ */
333
+ type JssmParseOptions = {
334
+ locations?: boolean;
335
+ startRule?: 'Document';
336
+ };
311
337
  /**
312
338
  * A single key/value pair from an FSL `state X: { ... };` block, in the
313
339
  * raw form produced by the parser before being condensed into a
@@ -1357,13 +1383,25 @@ interface FenceDimension {
1357
1383
  value: number;
1358
1384
  unit: FenceDimensionUnit;
1359
1385
  }
1360
- /** The fully-parsed, validated description of one FSL Markdown fence block. */
1386
+ /**
1387
+ * The fully-parsed, validated description of one FSL Markdown fence block.
1388
+ *
1389
+ * Sizing semantics: `width`/`height` (from `width=`/`height=` tokens) are
1390
+ * *exact* dimensions — the host renders the block at that size.
1391
+ * `max_width`/`max_height` (from `max-width=`/`max-height=` tokens) are
1392
+ * *upper bounds* on natural sizing — the block renders at its natural size
1393
+ * but is capped on that axis. When both an exact and a max token are given
1394
+ * for the same axis, the exact dimension wins and the cap is moot. All four
1395
+ * are `null` when their token is absent.
1396
+ */
1361
1397
  interface FenceDescriptor {
1362
1398
  parts: FencePart[];
1363
1399
  ide: boolean;
1364
1400
  format: FenceImageFormat;
1365
1401
  width: FenceDimension | null;
1366
1402
  height: FenceDimension | null;
1403
+ max_width: FenceDimension | null;
1404
+ max_height: FenceDimension | null;
1367
1405
  interactive: boolean;
1368
1406
  notes: string[];
1369
1407
  }
@@ -1381,13 +1419,18 @@ declare function fsl_fence_lang(info: string): 'fsl' | 'jssm' | null;
1381
1419
  /**
1382
1420
  * Parse a fence info string into a {@link FenceDescriptor}. The first token is
1383
1421
  * the (already-validated) language and is ignored; remaining tokens are
1384
- * classified as parts, image formats, the `ide` macro, or `width`/`height`
1385
- * options. Unrecognized or conflicting tokens are dropped and recorded in
1422
+ * classified as parts, image formats, the `ide` macro, or the dimension
1423
+ * options `width`/`height` (exact size) and `max-width`/`max-height`
1424
+ * (upper bounds on natural size — see {@link FenceDescriptor} for the
1425
+ * precedence rule when both appear on one axis). All four dimension tokens
1426
+ * share one value syntax: a bare number (pixels), `<n>px`, or `<n>%`.
1427
+ * Unrecognized or conflicting tokens are dropped and recorded in
1386
1428
  * `notes` rather than throwing, so a host can render forward-compatibly.
1387
1429
  * @param info The full fence info string, e.g. `'fsl image code width=300'`.
1388
1430
  * @returns The validated descriptor; `notes` lists anything ignored or overridden.
1389
1431
  * @example parse_fence_info('fsl').parts // => ['image', 'code']
1390
1432
  * @example parse_fence_info('fsl code image').parts // => ['code', 'image']
1433
+ * @example parse_fence_info('fsl image max-width=300 max-height=50%').max_width // => { value: 300, unit: 'px' }
1391
1434
  */
1392
1435
  declare function parse_fence_info(info: string): FenceDescriptor;
1393
1436
 
@@ -1523,14 +1566,31 @@ declare function arrow_right_kind(arrow: JssmArrow): JssmArrowKind;
1523
1566
  * `wrap_parse` itself is an internal convenience method for alting out an
1524
1567
  * object as the options call. Not generally meant for external use.
1525
1568
  *
1569
+ * @typeParam StateType The type of state names in the resulting tree; the
1570
+ * grammar itself always produces `string`s, so only
1571
+ * override this when threading a caller's own state
1572
+ * naming through to {@link compile}.
1573
+ * @typeParam mDT The type of the machine data member; usually omitted.
1574
+ *
1526
1575
  * @param input The FSL code to be evaluated
1527
1576
  *
1528
- * @param options Things to control about the instance. Pass
1577
+ * @param options Things to control about the parse. Pass
1529
1578
  * `{ locations: true }` to enable opt-in source location
1530
- * tracking on every AST node.
1579
+ * tracking on every AST node. When omitted, an empty options
1580
+ * object is passed through to the parser.
1581
+ *
1582
+ * @returns The machine's intermediate representation: a flat
1583
+ * {@link JssmParseTree} with one node per top-level FSL statement.
1584
+ *
1585
+ * @throws {SyntaxError} The generated PEG.js parser's `SyntaxError` when
1586
+ * `input` is not valid FSL.
1587
+ *
1588
+ * @see {@link compile}
1589
+ * @see {@link make}
1590
+ * @see {@link JssmParseOptions}
1531
1591
  *
1532
1592
  */
1533
- declare function wrap_parse(input: string, options?: object): any;
1593
+ declare function wrap_parse<StateType = string, mDT = unknown>(input: string, options?: JssmParseOptions): JssmParseTree<StateType, mDT>;
1534
1594
  /*********
1535
1595
  *
1536
1596
  * Compile a machine's JSON intermediate representation to a config object. If
@@ -3076,6 +3136,12 @@ declare class Machine<mDT> {
3076
3136
  * {@link Machine.transition}, so it fires no hooks, mutates no machine
3077
3137
  * state, and touches no `data`. A state with no probabilistic exits
3078
3138
  * (a terminal, or a forced-only `~>` state) ends the walk.
3139
+ *
3140
+ * Terminality is checked before the first transition and after every
3141
+ * transition. A terminal start therefore completes with length zero even
3142
+ * when `max_steps` is zero, and a terminal reached on the final permitted
3143
+ * transition is completed rather than step-capped.
3144
+ *
3079
3145
  * @param start - State to begin the walk from.
3080
3146
  * @param max_steps - Maximum transitions before the walk is step-capped.
3081
3147
  * @param exit_memo - Per-run-set cache of {@link Machine.probable_exits_for}
@@ -3098,7 +3164,9 @@ declare class Machine<mDT> {
3098
3164
  * current state, each ending at a terminal or after `max_steps`. In
3099
3165
  * `steady_state` mode yields exactly one walk of `max_steps` steps. This
3100
3166
  * is the lazy engine behind {@link Machine.stochastic_summary}; the
3101
- * fsl-stochastic panel drives it across animation frames.
3167
+ * fsl-stochastic panel drives it across animation frames. A walk already
3168
+ * at a terminal is reported as terminated with length zero, including when
3169
+ * `max_steps` is zero.
3102
3170
  *
3103
3171
  * Passing `seed` reseeds the machine for reproducible runs. Unlike
3104
3172
  * {@link Machine.stochastic_summary}, the generator does NOT restore the
@@ -3121,6 +3189,10 @@ declare class Machine<mDT> {
3121
3189
  * per-run `path_lengths`, `terminal_reached`, and `capped`; `steady_state`
3122
3190
  * mode runs one long walk and omits those fields.
3123
3191
  *
3192
+ * Monte-Carlo runs count as `terminal_reached` when they start at a
3193
+ * terminal or reach one on the final permitted transition. Terminal
3194
+ * starts contribute zero to `path_lengths`, even when `max_steps` is zero.
3195
+ *
3124
3196
  * Timing (`after`) decorations and data-guard conditions are not modeled
3125
3197
  * by this sampler; it walks the probabilistic graph topology.
3126
3198
  * @param opts - {@link JssmStochasticOptions}. `runs` defaults to the
@@ -4725,4 +4797,4 @@ declare function compareVersions(v1: string, v2: string): number;
4725
4797
  declare function deserialize<mDT>(machine_string: string, ser: JssmSerialization<mDT>): Machine<mDT>;
4726
4798
 
4727
4799
  export { FslDirections, Machine, STOCHASTIC_DEFAULT_MAX_STEPS, STOCHASTIC_DEFAULT_RUNS, abstract_everything_hook_step, abstract_hook_step, action_label_chars, arrow_direction, arrow_left_kind, arrow_right_kind, build_time, compareVersions, compile, jssm_constants_d as constants, deserialize, find_repeated, from, fslCompletions, fslDiagnostics, fslSemanticSpans, fsl_fence_lang, gen_splitmix32, gviz_shapes, histograph, is_hook_complex_result, is_hook_rejection, make, named_colors, wrap_parse as parse, parse_fence_info, seq, shapes, sleep, sm, state_name_chars, state_name_first_chars, state_style_condense, transfer_state_properties, unique, version, weighted_histo_key, weighted_rand_select, weighted_sample_select };
4728
- export type { FenceDescriptor, FenceDimension, FenceDimensionUnit, FenceImageFormat, FencePart };
4800
+ export type { FenceDescriptor, FenceDimension, FenceDimensionUnit, FenceImageFormat, FencePart, JssmParseOptions };
package/jssm.fence.d.ts CHANGED
@@ -2419,6 +2419,12 @@ declare class Machine<mDT> {
2419
2419
  * {@link Machine.transition}, so it fires no hooks, mutates no machine
2420
2420
  * state, and touches no `data`. A state with no probabilistic exits
2421
2421
  * (a terminal, or a forced-only `~>` state) ends the walk.
2422
+ *
2423
+ * Terminality is checked before the first transition and after every
2424
+ * transition. A terminal start therefore completes with length zero even
2425
+ * when `max_steps` is zero, and a terminal reached on the final permitted
2426
+ * transition is completed rather than step-capped.
2427
+ *
2422
2428
  * @param start - State to begin the walk from.
2423
2429
  * @param max_steps - Maximum transitions before the walk is step-capped.
2424
2430
  * @param exit_memo - Per-run-set cache of {@link Machine.probable_exits_for}
@@ -2441,7 +2447,9 @@ declare class Machine<mDT> {
2441
2447
  * current state, each ending at a terminal or after `max_steps`. In
2442
2448
  * `steady_state` mode yields exactly one walk of `max_steps` steps. This
2443
2449
  * is the lazy engine behind {@link Machine.stochastic_summary}; the
2444
- * fsl-stochastic panel drives it across animation frames.
2450
+ * fsl-stochastic panel drives it across animation frames. A walk already
2451
+ * at a terminal is reported as terminated with length zero, including when
2452
+ * `max_steps` is zero.
2445
2453
  *
2446
2454
  * Passing `seed` reseeds the machine for reproducible runs. Unlike
2447
2455
  * {@link Machine.stochastic_summary}, the generator does NOT restore the
@@ -2464,6 +2472,10 @@ declare class Machine<mDT> {
2464
2472
  * per-run `path_lengths`, `terminal_reached`, and `capped`; `steady_state`
2465
2473
  * mode runs one long walk and omits those fields.
2466
2474
  *
2475
+ * Monte-Carlo runs count as `terminal_reached` when they start at a
2476
+ * terminal or reach one on the final permitted transition. Terminal
2477
+ * starts contribute zero to `path_lengths`, even when `max_steps` is zero.
2478
+ *
2467
2479
  * Timing (`after`) decorations and data-guard conditions are not modeled
2468
2480
  * by this sampler; it walks the probabilistic graph topology.
2469
2481
  * @param opts - {@link JssmStochasticOptions}. `runs` defaults to the
@@ -2292,6 +2292,12 @@ declare class Machine<mDT> {
2292
2292
  * {@link Machine.transition}, so it fires no hooks, mutates no machine
2293
2293
  * state, and touches no `data`. A state with no probabilistic exits
2294
2294
  * (a terminal, or a forced-only `~>` state) ends the walk.
2295
+ *
2296
+ * Terminality is checked before the first transition and after every
2297
+ * transition. A terminal start therefore completes with length zero even
2298
+ * when `max_steps` is zero, and a terminal reached on the final permitted
2299
+ * transition is completed rather than step-capped.
2300
+ *
2295
2301
  * @param start - State to begin the walk from.
2296
2302
  * @param max_steps - Maximum transitions before the walk is step-capped.
2297
2303
  * @param exit_memo - Per-run-set cache of {@link Machine.probable_exits_for}
@@ -2314,7 +2320,9 @@ declare class Machine<mDT> {
2314
2320
  * current state, each ending at a terminal or after `max_steps`. In
2315
2321
  * `steady_state` mode yields exactly one walk of `max_steps` steps. This
2316
2322
  * is the lazy engine behind {@link Machine.stochastic_summary}; the
2317
- * fsl-stochastic panel drives it across animation frames.
2323
+ * fsl-stochastic panel drives it across animation frames. A walk already
2324
+ * at a terminal is reported as terminated with length zero, including when
2325
+ * `max_steps` is zero.
2318
2326
  *
2319
2327
  * Passing `seed` reseeds the machine for reproducible runs. Unlike
2320
2328
  * {@link Machine.stochastic_summary}, the generator does NOT restore the
@@ -2337,6 +2345,10 @@ declare class Machine<mDT> {
2337
2345
  * per-run `path_lengths`, `terminal_reached`, and `capped`; `steady_state`
2338
2346
  * mode runs one long walk and omits those fields.
2339
2347
  *
2348
+ * Monte-Carlo runs count as `terminal_reached` when they start at a
2349
+ * terminal or reach one on the final permitted transition. Terminal
2350
+ * starts contribute zero to `path_lengths`, even when `max_steps` is zero.
2351
+ *
2340
2352
  * Timing (`after`) decorations and data-guard conditions are not modeled
2341
2353
  * by this sampler; it walks the probabilistic graph topology.
2342
2354
  * @param opts - {@link JssmStochasticOptions}. `runs` defaults to the
@@ -3749,11 +3761,48 @@ declare class Machine<mDT> {
3749
3761
  */
3750
3762
  type RenderGroups = 'cluster' | 'chips' | 'off';
3751
3763
  /**
3752
- * Inject runtime configuration for jssm/viz. Currently only accepts a
3753
- * custom `DOMParser` constructor for use by `*_svg_element` functions in
3754
- * environments that do not provide one globally (e.g. Node + jsdom).
3764
+ * The Graphviz engine surface jssm/viz actually consumes: one ready-to-use
3765
+ * object with a `renderString(dot, options)` method. This is the contract
3766
+ * for {@link configure}`({ viz })` injection a *direct adapter*, not a
3767
+ * factory: the caller instantiates (and, if needed, awaits) their engine
3768
+ * themselves, then hands over the finished object. `renderString` receives
3769
+ * the dot source and an options object whose members jssm/viz uses are
3770
+ * `format` (always `'svg'`) and `engine` (a Graphviz layout engine name,
3771
+ * when the caller of a render function supplied one); it may return the
3772
+ * output string synchronously (like `@viz-js/viz`) or as a promise (like
3773
+ * asm.js `viz.js` 2.x), and jssm/viz awaits either.
3774
+ *
3775
+ * ```typescript
3776
+ * import { instance } from '@viz-js/viz';
3777
+ * configure({ viz: await instance() }); // the default engine, injected by hand
3778
+ * ```
3779
+ * @see configure
3780
+ */
3781
+ type VizEngine = {
3782
+ renderString: (dot: string, options?: {
3783
+ format?: string;
3784
+ engine?: string;
3785
+ }) => string | Promise<string>;
3786
+ };
3787
+ /**
3788
+ * Inject runtime configuration for jssm/viz — a custom `DOMParser`
3789
+ * constructor for the `*_svg_element` functions, a replacement Graphviz
3790
+ * engine for every render path, or both.
3755
3791
  *
3756
- * Idempotent last call wins. No-op if called with no recognized keys.
3792
+ * Each key is handled independently. Idempotent last call wins per key;
3793
+ * an omitted (or `undefined`) key leaves any earlier injection for that key
3794
+ * in place, so neither injection can be un-set. No-op if called with no
3795
+ * recognized keys.
3796
+ *
3797
+ * Precedence differs by key, on purpose:
3798
+ *
3799
+ * - `DOMParser` is a *fallback* — `globalThis.DOMParser` (browsers, jsdom
3800
+ * test environments) still wins when present.
3801
+ * - `viz` is an *override* — once injected it is used for every render, and
3802
+ * the default `@viz-js/viz` import is never even attempted. This is what
3803
+ * lets WASM-hostile environments (strict-CSP webviews such as VS Code's
3804
+ * markdown preview) supply an asm.js Graphviz build at runtime, without
3805
+ * bundler aliasing. See {@link VizEngine} for the exact contract.
3757
3806
  *
3758
3807
  * ```typescript
3759
3808
  * // Node, with jsdom:
@@ -3763,13 +3812,27 @@ type RenderGroups = 'cluster' | 'chips' | 'off';
3763
3812
  * configure({ DOMParser: new JSDOM().window.DOMParser });
3764
3813
  * const el = await fsl_to_svg_element('a -> b;');
3765
3814
  * ```
3815
+ *
3816
+ * ```typescript
3817
+ * // strict-CSP webview, with an asm.js Graphviz:
3818
+ * import { configure, fsl_to_svg_string } from 'jssm/viz';
3819
+ *
3820
+ * configure({ viz: my_asm_graphviz }); // anything with renderString(dot, opts)
3821
+ * const svg = await fsl_to_svg_string('a -> b;');
3822
+ * ```
3766
3823
  * @param opts Configuration overrides.
3767
3824
  * @param opts.DOMParser Constructor compatible with the WHATWG `DOMParser`
3768
3825
  * interface. Used as a fallback when `globalThis.DOMParser` is undefined.
3826
+ * @param opts.viz A ready-to-use Graphviz engine implementing
3827
+ * {@link VizEngine} (`renderString(dot, opts)`). Overrides the default
3828
+ * `@viz-js/viz` engine for all subsequent renders.
3769
3829
  * @throws {JssmError} if `DOMParser` is provided and is not a constructor.
3830
+ * @throws {JssmError} if `viz` is provided and lacks a callable `renderString`.
3831
+ * @see VizEngine
3770
3832
  */
3771
3833
  declare function configure(opts: {
3772
3834
  DOMParser?: typeof globalThis.DOMParser;
3835
+ viz?: VizEngine;
3773
3836
  }): void;
3774
3837
  /**
3775
3838
  * Look up a color from the default viz palette by key, returning empty
@@ -3827,9 +3890,14 @@ declare function undoublequote(txt: string): string;
3827
3890
  * slug_for('!!!'); // ''
3828
3891
  * slug_for(' Foo Bar '); // 'foo-bar'
3829
3892
  * ```
3893
+ * Exported so consumers which must match rendered SVG node `<title>`s back
3894
+ * to state names (notably `FslViz.highlightTrace`, fsl#1935) can slug with
3895
+ * the *same* function the dot generator used, rather than a drifting copy.
3896
+ *
3830
3897
  * @param state The state name to slugify.
3831
3898
  * @returns The lowercase hyphen-separated slug, or empty string if none of
3832
3899
  * the characters were retainable.
3900
+ * @see slug_states
3833
3901
  * @internal
3834
3902
  */
3835
3903
  declare function slug_for(state: string): string;
@@ -4267,9 +4335,10 @@ declare function machine_to_dot<T>(u_jssm: Machine<T>, opts?: VizRenderOpts): st
4267
4335
  */
4268
4336
  declare function fsl_to_dot(fsl: string, opts?: VizRenderOpts): string;
4269
4337
  /**
4270
- * Render a graphviz dot source string to SVG using `@viz-js/viz`. The
4271
- * underlying viz instance is lazy-initialized on first call and cached for
4272
- * the lifetime of the module.
4338
+ * Render a graphviz dot source string to SVG using `@viz-js/viz`, or the
4339
+ * engine injected via {@link configure}`({ viz })` when one is set. The
4340
+ * default viz instance is lazy-initialized on first call and cached for
4341
+ * the lifetime of the module; an injected engine bypasses it entirely.
4273
4342
  *
4274
4343
  * ```typescript
4275
4344
  * const svg = await dot_to_svg('digraph G { a -> b }');
@@ -4357,5 +4426,5 @@ declare const _test: {
4357
4426
  graph_bg_color_from_config: typeof graph_bg_color_from_config;
4358
4427
  };
4359
4428
 
4360
- export { _test, build_time, configure, dot, dot_to_svg, fsl_to_dot, fsl_to_svg_element, fsl_to_svg_string, machine_to_dot, machine_to_svg_element, machine_to_svg_string, state_svg_label_texts, version };
4361
- export type { RenderGroups, VizRenderOpts };
4429
+ export { _test, build_time, configure, dot, dot_to_svg, fsl_to_dot, fsl_to_svg_element, fsl_to_svg_string, machine_to_dot, machine_to_svg_element, machine_to_svg_string, slug_for, state_svg_label_texts, version };
4430
+ export type { RenderGroups, VizEngine, VizRenderOpts };
package/jssm_viz.es6.d.ts CHANGED
@@ -2292,6 +2292,12 @@ declare class Machine<mDT> {
2292
2292
  * {@link Machine.transition}, so it fires no hooks, mutates no machine
2293
2293
  * state, and touches no `data`. A state with no probabilistic exits
2294
2294
  * (a terminal, or a forced-only `~>` state) ends the walk.
2295
+ *
2296
+ * Terminality is checked before the first transition and after every
2297
+ * transition. A terminal start therefore completes with length zero even
2298
+ * when `max_steps` is zero, and a terminal reached on the final permitted
2299
+ * transition is completed rather than step-capped.
2300
+ *
2295
2301
  * @param start - State to begin the walk from.
2296
2302
  * @param max_steps - Maximum transitions before the walk is step-capped.
2297
2303
  * @param exit_memo - Per-run-set cache of {@link Machine.probable_exits_for}
@@ -2314,7 +2320,9 @@ declare class Machine<mDT> {
2314
2320
  * current state, each ending at a terminal or after `max_steps`. In
2315
2321
  * `steady_state` mode yields exactly one walk of `max_steps` steps. This
2316
2322
  * is the lazy engine behind {@link Machine.stochastic_summary}; the
2317
- * fsl-stochastic panel drives it across animation frames.
2323
+ * fsl-stochastic panel drives it across animation frames. A walk already
2324
+ * at a terminal is reported as terminated with length zero, including when
2325
+ * `max_steps` is zero.
2318
2326
  *
2319
2327
  * Passing `seed` reseeds the machine for reproducible runs. Unlike
2320
2328
  * {@link Machine.stochastic_summary}, the generator does NOT restore the
@@ -2337,6 +2345,10 @@ declare class Machine<mDT> {
2337
2345
  * per-run `path_lengths`, `terminal_reached`, and `capped`; `steady_state`
2338
2346
  * mode runs one long walk and omits those fields.
2339
2347
  *
2348
+ * Monte-Carlo runs count as `terminal_reached` when they start at a
2349
+ * terminal or reach one on the final permitted transition. Terminal
2350
+ * starts contribute zero to `path_lengths`, even when `max_steps` is zero.
2351
+ *
2340
2352
  * Timing (`after`) decorations and data-guard conditions are not modeled
2341
2353
  * by this sampler; it walks the probabilistic graph topology.
2342
2354
  * @param opts - {@link JssmStochasticOptions}. `runs` defaults to the
@@ -3749,11 +3761,48 @@ declare class Machine<mDT> {
3749
3761
  */
3750
3762
  type RenderGroups = 'cluster' | 'chips' | 'off';
3751
3763
  /**
3752
- * Inject runtime configuration for jssm/viz. Currently only accepts a
3753
- * custom `DOMParser` constructor for use by `*_svg_element` functions in
3754
- * environments that do not provide one globally (e.g. Node + jsdom).
3764
+ * The Graphviz engine surface jssm/viz actually consumes: one ready-to-use
3765
+ * object with a `renderString(dot, options)` method. This is the contract
3766
+ * for {@link configure}`({ viz })` injection a *direct adapter*, not a
3767
+ * factory: the caller instantiates (and, if needed, awaits) their engine
3768
+ * themselves, then hands over the finished object. `renderString` receives
3769
+ * the dot source and an options object whose members jssm/viz uses are
3770
+ * `format` (always `'svg'`) and `engine` (a Graphviz layout engine name,
3771
+ * when the caller of a render function supplied one); it may return the
3772
+ * output string synchronously (like `@viz-js/viz`) or as a promise (like
3773
+ * asm.js `viz.js` 2.x), and jssm/viz awaits either.
3774
+ *
3775
+ * ```typescript
3776
+ * import { instance } from '@viz-js/viz';
3777
+ * configure({ viz: await instance() }); // the default engine, injected by hand
3778
+ * ```
3779
+ * @see configure
3780
+ */
3781
+ type VizEngine = {
3782
+ renderString: (dot: string, options?: {
3783
+ format?: string;
3784
+ engine?: string;
3785
+ }) => string | Promise<string>;
3786
+ };
3787
+ /**
3788
+ * Inject runtime configuration for jssm/viz — a custom `DOMParser`
3789
+ * constructor for the `*_svg_element` functions, a replacement Graphviz
3790
+ * engine for every render path, or both.
3755
3791
  *
3756
- * Idempotent last call wins. No-op if called with no recognized keys.
3792
+ * Each key is handled independently. Idempotent last call wins per key;
3793
+ * an omitted (or `undefined`) key leaves any earlier injection for that key
3794
+ * in place, so neither injection can be un-set. No-op if called with no
3795
+ * recognized keys.
3796
+ *
3797
+ * Precedence differs by key, on purpose:
3798
+ *
3799
+ * - `DOMParser` is a *fallback* — `globalThis.DOMParser` (browsers, jsdom
3800
+ * test environments) still wins when present.
3801
+ * - `viz` is an *override* — once injected it is used for every render, and
3802
+ * the default `@viz-js/viz` import is never even attempted. This is what
3803
+ * lets WASM-hostile environments (strict-CSP webviews such as VS Code's
3804
+ * markdown preview) supply an asm.js Graphviz build at runtime, without
3805
+ * bundler aliasing. See {@link VizEngine} for the exact contract.
3757
3806
  *
3758
3807
  * ```typescript
3759
3808
  * // Node, with jsdom:
@@ -3763,13 +3812,27 @@ type RenderGroups = 'cluster' | 'chips' | 'off';
3763
3812
  * configure({ DOMParser: new JSDOM().window.DOMParser });
3764
3813
  * const el = await fsl_to_svg_element('a -> b;');
3765
3814
  * ```
3815
+ *
3816
+ * ```typescript
3817
+ * // strict-CSP webview, with an asm.js Graphviz:
3818
+ * import { configure, fsl_to_svg_string } from 'jssm/viz';
3819
+ *
3820
+ * configure({ viz: my_asm_graphviz }); // anything with renderString(dot, opts)
3821
+ * const svg = await fsl_to_svg_string('a -> b;');
3822
+ * ```
3766
3823
  * @param opts Configuration overrides.
3767
3824
  * @param opts.DOMParser Constructor compatible with the WHATWG `DOMParser`
3768
3825
  * interface. Used as a fallback when `globalThis.DOMParser` is undefined.
3826
+ * @param opts.viz A ready-to-use Graphviz engine implementing
3827
+ * {@link VizEngine} (`renderString(dot, opts)`). Overrides the default
3828
+ * `@viz-js/viz` engine for all subsequent renders.
3769
3829
  * @throws {JssmError} if `DOMParser` is provided and is not a constructor.
3830
+ * @throws {JssmError} if `viz` is provided and lacks a callable `renderString`.
3831
+ * @see VizEngine
3770
3832
  */
3771
3833
  declare function configure(opts: {
3772
3834
  DOMParser?: typeof globalThis.DOMParser;
3835
+ viz?: VizEngine;
3773
3836
  }): void;
3774
3837
  /**
3775
3838
  * Look up a color from the default viz palette by key, returning empty
@@ -3827,9 +3890,14 @@ declare function undoublequote(txt: string): string;
3827
3890
  * slug_for('!!!'); // ''
3828
3891
  * slug_for(' Foo Bar '); // 'foo-bar'
3829
3892
  * ```
3893
+ * Exported so consumers which must match rendered SVG node `<title>`s back
3894
+ * to state names (notably `FslViz.highlightTrace`, fsl#1935) can slug with
3895
+ * the *same* function the dot generator used, rather than a drifting copy.
3896
+ *
3830
3897
  * @param state The state name to slugify.
3831
3898
  * @returns The lowercase hyphen-separated slug, or empty string if none of
3832
3899
  * the characters were retainable.
3900
+ * @see slug_states
3833
3901
  * @internal
3834
3902
  */
3835
3903
  declare function slug_for(state: string): string;
@@ -4267,9 +4335,10 @@ declare function machine_to_dot<T>(u_jssm: Machine<T>, opts?: VizRenderOpts): st
4267
4335
  */
4268
4336
  declare function fsl_to_dot(fsl: string, opts?: VizRenderOpts): string;
4269
4337
  /**
4270
- * Render a graphviz dot source string to SVG using `@viz-js/viz`. The
4271
- * underlying viz instance is lazy-initialized on first call and cached for
4272
- * the lifetime of the module.
4338
+ * Render a graphviz dot source string to SVG using `@viz-js/viz`, or the
4339
+ * engine injected via {@link configure}`({ viz })` when one is set. The
4340
+ * default viz instance is lazy-initialized on first call and cached for
4341
+ * the lifetime of the module; an injected engine bypasses it entirely.
4273
4342
  *
4274
4343
  * ```typescript
4275
4344
  * const svg = await dot_to_svg('digraph G { a -> b }');
@@ -4357,5 +4426,5 @@ declare const _test: {
4357
4426
  graph_bg_color_from_config: typeof graph_bg_color_from_config;
4358
4427
  };
4359
4428
 
4360
- export { _test, build_time, configure, dot, dot_to_svg, fsl_to_dot, fsl_to_svg_element, fsl_to_svg_string, machine_to_dot, machine_to_svg_element, machine_to_svg_string, state_svg_label_texts, version };
4361
- export type { RenderGroups, VizRenderOpts };
4429
+ export { _test, build_time, configure, dot, dot_to_svg, fsl_to_dot, fsl_to_svg_element, fsl_to_svg_string, machine_to_dot, machine_to_svg_element, machine_to_svg_string, slug_for, state_svg_label_texts, version };
4430
+ export type { RenderGroups, VizEngine, VizRenderOpts };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jssm",
3
- "version": "5.162.11",
3
+ "version": "5.162.13",
4
4
  "engines": {
5
5
  "node": ">=10.0.0"
6
6
  },
@@ -234,6 +234,7 @@
234
234
  "ci_test": "npm run vet && npm run make_ci && npm run vitest",
235
235
  "ci_test_runtime": "npm run make_ci && npm run vitest",
236
236
  "attw": "attw --pack .",
237
+ "decl_parity": "node src/buildjs/decl_parity.cjs",
237
238
  "minify": "mv dist/es6/fsl_parser.js dist/es6/fsl_parser.nonmin.js && terser dist/es6/fsl_parser.nonmin.js > dist/es6/fsl_parser.js",
238
239
  "min_iife": "mv dist/jssm.es5.iife.js dist/jssm.es5.iife.nonmin.js && terser dist/jssm.es5.iife.nonmin.js > dist/jssm.es5.iife.js && cp dist/jssm.es5.iife.nonmin.js ./src/tools/",
239
240
  "min_cjs": "mv dist/jssm.es5.cjs.js dist/jssm.es5.nonmin.cjs && terser dist/jssm.es5.nonmin.cjs > dist/jssm.es5.cjs",