jssm 5.162.12 → 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
@@ -4737,4 +4797,4 @@ declare function compareVersions(v1: string, v2: string): number;
4737
4797
  declare function deserialize<mDT>(machine_string: string, ser: JssmSerialization<mDT>): Machine<mDT>;
4738
4798
 
4739
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 };
4740
- export type { FenceDescriptor, FenceDimension, FenceDimensionUnit, FenceImageFormat, FencePart };
4800
+ export type { FenceDescriptor, FenceDimension, FenceDimensionUnit, FenceImageFormat, FencePart, JssmParseOptions };
@@ -3761,11 +3761,48 @@ declare class Machine<mDT> {
3761
3761
  */
3762
3762
  type RenderGroups = 'cluster' | 'chips' | 'off';
3763
3763
  /**
3764
- * Inject runtime configuration for jssm/viz. Currently only accepts a
3765
- * custom `DOMParser` constructor for use by `*_svg_element` functions in
3766
- * 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.
3767
3774
  *
3768
- * Idempotent — last call wins. No-op if called with no recognized keys.
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.
3791
+ *
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.
3769
3806
  *
3770
3807
  * ```typescript
3771
3808
  * // Node, with jsdom:
@@ -3775,13 +3812,27 @@ type RenderGroups = 'cluster' | 'chips' | 'off';
3775
3812
  * configure({ DOMParser: new JSDOM().window.DOMParser });
3776
3813
  * const el = await fsl_to_svg_element('a -> b;');
3777
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
+ * ```
3778
3823
  * @param opts Configuration overrides.
3779
3824
  * @param opts.DOMParser Constructor compatible with the WHATWG `DOMParser`
3780
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.
3781
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
3782
3832
  */
3783
3833
  declare function configure(opts: {
3784
3834
  DOMParser?: typeof globalThis.DOMParser;
3835
+ viz?: VizEngine;
3785
3836
  }): void;
3786
3837
  /**
3787
3838
  * Look up a color from the default viz palette by key, returning empty
@@ -3839,9 +3890,14 @@ declare function undoublequote(txt: string): string;
3839
3890
  * slug_for('!!!'); // ''
3840
3891
  * slug_for(' Foo Bar '); // 'foo-bar'
3841
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
+ *
3842
3897
  * @param state The state name to slugify.
3843
3898
  * @returns The lowercase hyphen-separated slug, or empty string if none of
3844
3899
  * the characters were retainable.
3900
+ * @see slug_states
3845
3901
  * @internal
3846
3902
  */
3847
3903
  declare function slug_for(state: string): string;
@@ -4279,9 +4335,10 @@ declare function machine_to_dot<T>(u_jssm: Machine<T>, opts?: VizRenderOpts): st
4279
4335
  */
4280
4336
  declare function fsl_to_dot(fsl: string, opts?: VizRenderOpts): string;
4281
4337
  /**
4282
- * Render a graphviz dot source string to SVG using `@viz-js/viz`. The
4283
- * underlying viz instance is lazy-initialized on first call and cached for
4284
- * 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.
4285
4342
  *
4286
4343
  * ```typescript
4287
4344
  * const svg = await dot_to_svg('digraph G { a -> b }');
@@ -4369,5 +4426,5 @@ declare const _test: {
4369
4426
  graph_bg_color_from_config: typeof graph_bg_color_from_config;
4370
4427
  };
4371
4428
 
4372
- 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 };
4373
- 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
@@ -3761,11 +3761,48 @@ declare class Machine<mDT> {
3761
3761
  */
3762
3762
  type RenderGroups = 'cluster' | 'chips' | 'off';
3763
3763
  /**
3764
- * Inject runtime configuration for jssm/viz. Currently only accepts a
3765
- * custom `DOMParser` constructor for use by `*_svg_element` functions in
3766
- * 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.
3767
3774
  *
3768
- * Idempotent — last call wins. No-op if called with no recognized keys.
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.
3791
+ *
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.
3769
3806
  *
3770
3807
  * ```typescript
3771
3808
  * // Node, with jsdom:
@@ -3775,13 +3812,27 @@ type RenderGroups = 'cluster' | 'chips' | 'off';
3775
3812
  * configure({ DOMParser: new JSDOM().window.DOMParser });
3776
3813
  * const el = await fsl_to_svg_element('a -> b;');
3777
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
+ * ```
3778
3823
  * @param opts Configuration overrides.
3779
3824
  * @param opts.DOMParser Constructor compatible with the WHATWG `DOMParser`
3780
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.
3781
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
3782
3832
  */
3783
3833
  declare function configure(opts: {
3784
3834
  DOMParser?: typeof globalThis.DOMParser;
3835
+ viz?: VizEngine;
3785
3836
  }): void;
3786
3837
  /**
3787
3838
  * Look up a color from the default viz palette by key, returning empty
@@ -3839,9 +3890,14 @@ declare function undoublequote(txt: string): string;
3839
3890
  * slug_for('!!!'); // ''
3840
3891
  * slug_for(' Foo Bar '); // 'foo-bar'
3841
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
+ *
3842
3897
  * @param state The state name to slugify.
3843
3898
  * @returns The lowercase hyphen-separated slug, or empty string if none of
3844
3899
  * the characters were retainable.
3900
+ * @see slug_states
3845
3901
  * @internal
3846
3902
  */
3847
3903
  declare function slug_for(state: string): string;
@@ -4279,9 +4335,10 @@ declare function machine_to_dot<T>(u_jssm: Machine<T>, opts?: VizRenderOpts): st
4279
4335
  */
4280
4336
  declare function fsl_to_dot(fsl: string, opts?: VizRenderOpts): string;
4281
4337
  /**
4282
- * Render a graphviz dot source string to SVG using `@viz-js/viz`. The
4283
- * underlying viz instance is lazy-initialized on first call and cached for
4284
- * 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.
4285
4342
  *
4286
4343
  * ```typescript
4287
4344
  * const svg = await dot_to_svg('digraph G { a -> b }');
@@ -4369,5 +4426,5 @@ declare const _test: {
4369
4426
  graph_bg_color_from_config: typeof graph_bg_color_from_config;
4370
4427
  };
4371
4428
 
4372
- 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 };
4373
- 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.12",
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",