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.
@@ -1,4 +1,4 @@
1
- import { JssmTransition, JssmCompileSe, JssmCompileSeStart, JssmParseTree, JssmGenericConfig, JssmGroupRegistry, FslSourceLocation } from './jssm_types.js';
1
+ import { JssmTransition, JssmCompileSe, JssmCompileSeStart, JssmParseTree, JssmParseOptions, JssmGenericConfig, JssmGroupRegistry, FslSourceLocation } from './jssm_types.js';
2
2
  /*********
3
3
  *
4
4
  * Returns the source span of the `n`-th parse-tree node (1-based) matching
@@ -123,14 +123,31 @@ declare function makeTransition<StateType, mDT>(this_se: JssmCompileSe<StateType
123
123
  * `wrap_parse` itself is an internal convenience method for alting out an
124
124
  * object as the options call. Not generally meant for external use.
125
125
  *
126
+ * @typeParam StateType The type of state names in the resulting tree; the
127
+ * grammar itself always produces `string`s, so only
128
+ * override this when threading a caller's own state
129
+ * naming through to {@link compile}.
130
+ * @typeParam mDT The type of the machine data member; usually omitted.
131
+ *
126
132
  * @param input The FSL code to be evaluated
127
133
  *
128
- * @param options Things to control about the instance. Pass
134
+ * @param options Things to control about the parse. Pass
129
135
  * `{ locations: true }` to enable opt-in source location
130
- * tracking on every AST node.
136
+ * tracking on every AST node. When omitted, an empty options
137
+ * object is passed through to the parser.
138
+ *
139
+ * @returns The machine's intermediate representation: a flat
140
+ * {@link JssmParseTree} with one node per top-level FSL statement.
141
+ *
142
+ * @throws {SyntaxError} The generated PEG.js parser's `SyntaxError` when
143
+ * `input` is not valid FSL.
144
+ *
145
+ * @see {@link compile}
146
+ * @see {@link make}
147
+ * @see {@link JssmParseOptions}
131
148
  *
132
149
  */
133
- declare function wrap_parse(input: string, options?: object): any;
150
+ declare function wrap_parse<StateType = string, mDT = unknown>(input: string, options?: JssmParseOptions): JssmParseTree<StateType, mDT>;
134
151
  /*********
135
152
  *
136
153
  * Builds the ordered {@link JssmGroupRegistry} from every `named_list` node
@@ -407,6 +407,32 @@ type FslSourceLocation = {
407
407
  start: FslSourcePoint;
408
408
  end: FslSourcePoint;
409
409
  };
410
+ /**
411
+ * Options accepted by the FSL parser and its {@link wrap_parse} wrapper
412
+ * (exported from the package as `parse`). Exists so the two-argument parse
413
+ * call is typed against what the parser actually reads, instead of a bare
414
+ * `object`.
415
+ *
416
+ * - `locations` — when `true`, the grammar attaches a `loc` field of type
417
+ * {@link FslSourceLocation} (plus curated `*_loc` token sub-spans) to every
418
+ * AST node. When absent or `false`, the tree is byte-for-byte identical to
419
+ * the historical location-free output.
420
+ *
421
+ * - `startRule` — honored by the generated PEG.js boilerplate, which throws
422
+ * on any rule name it doesn't expose. This grammar exposes only its
423
+ * default rule, `Document`, so the field is only useful for explicitness.
424
+ *
425
+ * ```typescript
426
+ * const [t] = parse('a -> b;', { locations: true });
427
+ * // t.loc === { start: { offset: 0, line: 1, column: 1 },
428
+ * // end: { offset: 7, line: 1, column: 8 } }
429
+ * ```
430
+ * @see FslSourceLocation
431
+ */
432
+ type JssmParseOptions = {
433
+ locations?: boolean;
434
+ startRule?: 'Document';
435
+ };
410
436
  /**
411
437
  * A single key/value pair from an FSL `state X: { ... };` block, in the
412
438
  * raw form produced by the parser before being condensed into a
@@ -1345,4 +1371,4 @@ type JssmEventHandler<mDT, Ev extends JssmEventName> = (detail: JssmEventDetailM
1345
1371
  * removes the subscription. Calling it more than once is a no-op.
1346
1372
  */
1347
1373
  type JssmUnsubscribe = () => void;
1348
- export { JssmColor, JssmShape, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmEditorConfig, JssmStochasticMode, JssmStochasticOptions, JssmStochasticRun, JssmStochasticSummary, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmStateConfig, JssmStateStyleKey, JssmStateStyleKeyList, JssmGraphDefaultEdgeColor, JssmTransitionStyleKey, JssmTransitionConfig, JssmGraphAliasKey, JssmGraphStyleKey, JssmGraphConfig, JssmBaseTheme, JssmTheme, JssmLayout, JssmHistory, JssmSerialization, JssmPropertyDefinition, JssmAllowsOverride, JssmAllowIslands, JssmDefaultSize, JssmParsedSemver, JssmGroupRef, JssmGroupMemberRef, JssmGroupRegistry, JssmHookDeclaration, JssmBoundaryHooks, JssmGroupHooks, JssmStateHooks, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirections, FslDirection, FslThemes, FslTheme, FslSourcePoint, FslSourceLocation, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult, EverythingHookContext, EverythingHookHandler, PostEverythingHookHandler, HookPhase, HookTargetScope, HookTarget, HookBoundaryKind, HookRegistryEntry, HookQuery, JssmEventName, JssmEventDetailMap, JssmEventFilterMap, JssmEventFilter, JssmEventHandler, JssmUnsubscribe, JssmTransitionEventDetail, JssmRejectionEventDetail, JssmActionEventDetail, JssmEntryEventDetail, JssmExitEventDetail, JssmTerminalEventDetail, JssmCompleteEventDetail, JssmErrorEventDetail, JssmDataChangeEventDetail, JssmOverrideEventDetail, JssmTimeoutEventDetail, JssmHookLifecycleEventDetail, JssmRng };
1374
+ export { JssmColor, JssmShape, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmEditorConfig, JssmStochasticMode, JssmStochasticOptions, JssmStochasticRun, JssmStochasticSummary, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmParseOptions, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmStateConfig, JssmStateStyleKey, JssmStateStyleKeyList, JssmGraphDefaultEdgeColor, JssmTransitionStyleKey, JssmTransitionConfig, JssmGraphAliasKey, JssmGraphStyleKey, JssmGraphConfig, JssmBaseTheme, JssmTheme, JssmLayout, JssmHistory, JssmSerialization, JssmPropertyDefinition, JssmAllowsOverride, JssmAllowIslands, JssmDefaultSize, JssmParsedSemver, JssmGroupRef, JssmGroupMemberRef, JssmGroupRegistry, JssmHookDeclaration, JssmBoundaryHooks, JssmGroupHooks, JssmStateHooks, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirections, FslDirection, FslThemes, FslTheme, FslSourcePoint, FslSourceLocation, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult, EverythingHookContext, EverythingHookHandler, PostEverythingHookHandler, HookPhase, HookTargetScope, HookTarget, HookBoundaryKind, HookRegistryEntry, HookQuery, JssmEventName, JssmEventDetailMap, JssmEventFilterMap, JssmEventFilter, JssmEventHandler, JssmUnsubscribe, JssmTransitionEventDetail, JssmRejectionEventDetail, JssmActionEventDetail, JssmEntryEventDetail, JssmExitEventDetail, JssmTerminalEventDetail, JssmCompleteEventDetail, JssmErrorEventDetail, JssmDataChangeEventDetail, JssmOverrideEventDetail, JssmTimeoutEventDetail, JssmHookLifecycleEventDetail, JssmRng };
@@ -16,11 +16,48 @@ import type { JssmGroupMemberRef, JssmTransitionConfig, JssmGraphConfig } from '
16
16
  */
17
17
  type RenderGroups = 'cluster' | 'chips' | 'off';
18
18
  /**
19
- * Inject runtime configuration for jssm/viz. Currently only accepts a
20
- * custom `DOMParser` constructor for use by `*_svg_element` functions in
21
- * environments that do not provide one globally (e.g. Node + jsdom).
19
+ * The Graphviz engine surface jssm/viz actually consumes: one ready-to-use
20
+ * object with a `renderString(dot, options)` method. This is the contract
21
+ * for {@link configure}`({ viz })` injection a *direct adapter*, not a
22
+ * factory: the caller instantiates (and, if needed, awaits) their engine
23
+ * themselves, then hands over the finished object. `renderString` receives
24
+ * the dot source and an options object whose members jssm/viz uses are
25
+ * `format` (always `'svg'`) and `engine` (a Graphviz layout engine name,
26
+ * when the caller of a render function supplied one); it may return the
27
+ * output string synchronously (like `@viz-js/viz`) or as a promise (like
28
+ * asm.js `viz.js` 2.x), and jssm/viz awaits either.
22
29
  *
23
- * Idempotent — last call wins. No-op if called with no recognized keys.
30
+ * ```typescript
31
+ * import { instance } from '@viz-js/viz';
32
+ * configure({ viz: await instance() }); // the default engine, injected by hand
33
+ * ```
34
+ * @see configure
35
+ */
36
+ type VizEngine = {
37
+ renderString: (dot: string, options?: {
38
+ format?: string;
39
+ engine?: string;
40
+ }) => string | Promise<string>;
41
+ };
42
+ /**
43
+ * Inject runtime configuration for jssm/viz — a custom `DOMParser`
44
+ * constructor for the `*_svg_element` functions, a replacement Graphviz
45
+ * engine for every render path, or both.
46
+ *
47
+ * Each key is handled independently. Idempotent — last call wins per key;
48
+ * an omitted (or `undefined`) key leaves any earlier injection for that key
49
+ * in place, so neither injection can be un-set. No-op if called with no
50
+ * recognized keys.
51
+ *
52
+ * Precedence differs by key, on purpose:
53
+ *
54
+ * - `DOMParser` is a *fallback* — `globalThis.DOMParser` (browsers, jsdom
55
+ * test environments) still wins when present.
56
+ * - `viz` is an *override* — once injected it is used for every render, and
57
+ * the default `@viz-js/viz` import is never even attempted. This is what
58
+ * lets WASM-hostile environments (strict-CSP webviews such as VS Code's
59
+ * markdown preview) supply an asm.js Graphviz build at runtime, without
60
+ * bundler aliasing. See {@link VizEngine} for the exact contract.
24
61
  *
25
62
  * ```typescript
26
63
  * // Node, with jsdom:
@@ -30,13 +67,27 @@ type RenderGroups = 'cluster' | 'chips' | 'off';
30
67
  * configure({ DOMParser: new JSDOM().window.DOMParser });
31
68
  * const el = await fsl_to_svg_element('a -> b;');
32
69
  * ```
70
+ *
71
+ * ```typescript
72
+ * // strict-CSP webview, with an asm.js Graphviz:
73
+ * import { configure, fsl_to_svg_string } from 'jssm/viz';
74
+ *
75
+ * configure({ viz: my_asm_graphviz }); // anything with renderString(dot, opts)
76
+ * const svg = await fsl_to_svg_string('a -> b;');
77
+ * ```
33
78
  * @param opts Configuration overrides.
34
79
  * @param opts.DOMParser Constructor compatible with the WHATWG `DOMParser`
35
80
  * interface. Used as a fallback when `globalThis.DOMParser` is undefined.
81
+ * @param opts.viz A ready-to-use Graphviz engine implementing
82
+ * {@link VizEngine} (`renderString(dot, opts)`). Overrides the default
83
+ * `@viz-js/viz` engine for all subsequent renders.
36
84
  * @throws {JssmError} if `DOMParser` is provided and is not a constructor.
85
+ * @throws {JssmError} if `viz` is provided and lacks a callable `renderString`.
86
+ * @see VizEngine
37
87
  */
38
88
  declare function configure(opts: {
39
89
  DOMParser?: typeof globalThis.DOMParser;
90
+ viz?: VizEngine;
40
91
  }): void;
41
92
  /**
42
93
  * Look up a color from the default viz palette by key, returning empty
@@ -94,9 +145,14 @@ declare function undoublequote(txt: string): string;
94
145
  * slug_for('!!!'); // ''
95
146
  * slug_for(' Foo Bar '); // 'foo-bar'
96
147
  * ```
148
+ * Exported so consumers which must match rendered SVG node `<title>`s back
149
+ * to state names (notably `FslViz.highlightTrace`, fsl#1935) can slug with
150
+ * the *same* function the dot generator used, rather than a drifting copy.
151
+ *
97
152
  * @param state The state name to slugify.
98
153
  * @returns The lowercase hyphen-separated slug, or empty string if none of
99
154
  * the characters were retainable.
155
+ * @see slug_states
100
156
  * @internal
101
157
  */
102
158
  declare function slug_for(state: string): string;
@@ -534,9 +590,10 @@ declare function machine_to_dot<T>(u_jssm: jssm.Machine<T>, opts?: VizRenderOpts
534
590
  */
535
591
  declare function fsl_to_dot(fsl: string, opts?: VizRenderOpts): string;
536
592
  /**
537
- * Render a graphviz dot source string to SVG using `@viz-js/viz`. The
538
- * underlying viz instance is lazy-initialized on first call and cached for
539
- * the lifetime of the module.
593
+ * Render a graphviz dot source string to SVG using `@viz-js/viz`, or the
594
+ * engine injected via {@link configure}`({ viz })` when one is set. The
595
+ * default viz instance is lazy-initialized on first call and cached for
596
+ * the lifetime of the module; an injected engine bypasses it entirely.
540
597
  *
541
598
  * ```typescript
542
599
  * const svg = await dot_to_svg('digraph G { a -> b }');
@@ -593,8 +650,8 @@ declare function machine_to_svg_element<T>(u_jssm: jssm.Machine<T>, opts?: VizRe
593
650
  * @deprecated Use {@link machine_to_dot} instead.
594
651
  */
595
652
  declare function dot<T>(machine: jssm.Machine<T>): string;
596
- export { configure, dot, dot_to_svg, fsl_to_dot, fsl_to_svg_string, fsl_to_svg_element, machine_to_dot, machine_to_svg_string, machine_to_svg_element, state_svg_label_texts, };
597
- export type { VizRenderOpts, RenderGroups };
653
+ export { configure, dot, dot_to_svg, fsl_to_dot, fsl_to_svg_string, fsl_to_svg_element, machine_to_dot, machine_to_svg_string, machine_to_svg_element, state_svg_label_texts, slug_for, };
654
+ export type { VizRenderOpts, RenderGroups, VizEngine };
598
655
  /** @internal */
599
656
  export declare const _test: {
600
657
  doublequote: typeof doublequote;
@@ -22444,11 +22444,28 @@ function makeTransition(this_se, from, to, isRight, _wasList, _wasIndex) {
22444
22444
  * `wrap_parse` itself is an internal convenience method for alting out an
22445
22445
  * object as the options call. Not generally meant for external use.
22446
22446
  *
22447
+ * @typeParam StateType The type of state names in the resulting tree; the
22448
+ * grammar itself always produces `string`s, so only
22449
+ * override this when threading a caller's own state
22450
+ * naming through to {@link compile}.
22451
+ * @typeParam mDT The type of the machine data member; usually omitted.
22452
+ *
22447
22453
  * @param input The FSL code to be evaluated
22448
22454
  *
22449
- * @param options Things to control about the instance. Pass
22455
+ * @param options Things to control about the parse. Pass
22450
22456
  * `{ locations: true }` to enable opt-in source location
22451
- * tracking on every AST node.
22457
+ * tracking on every AST node. When omitted, an empty options
22458
+ * object is passed through to the parser.
22459
+ *
22460
+ * @returns The machine's intermediate representation: a flat
22461
+ * {@link JssmParseTree} with one node per top-level FSL statement.
22462
+ *
22463
+ * @throws {SyntaxError} The generated PEG.js parser's `SyntaxError` when
22464
+ * `input` is not valid FSL.
22465
+ *
22466
+ * @see {@link compile}
22467
+ * @see {@link make}
22468
+ * @see {@link JssmParseOptions}
22452
22469
  *
22453
22470
  */
22454
22471
  function wrap_parse(input, options) {
@@ -24206,7 +24223,7 @@ function fslSemanticSpans(text) {
24206
24223
  * Useful for runtime diagnostics and for embedding in serialized machine
24207
24224
  * snapshots so that deserializers can detect version-skew.
24208
24225
  */
24209
- const version = "5.162.12";
24226
+ const version = "5.162.13";
24210
24227
 
24211
24228
  /**
24212
24229
  * The FSL Markdown fence convention parser — pure, host-agnostic logic that
@@ -24252,7 +24269,7 @@ const INTERACTIVE_PARTS$1 = new Set(['editor', 'actions', 'toolbar', 'info-panel
24252
24269
  /**
24253
24270
  * Parse a dimension value like `300`, `120px`, or `100%` into a
24254
24271
  * {@link FenceDimension}. A bare number is pixels.
24255
- * @param raw The value portion of a `width=`/`height=` token.
24272
+ * @param raw The value portion of a `width=`/`height=`/`max-width=`/`max-height=` token.
24256
24273
  * @returns The parsed dimension, or `null` if malformed.
24257
24274
  * @example parse_dimension('300') // => { value: 300, unit: 'px' }
24258
24275
  * @example parse_dimension('100%') // => { value: 100, unit: 'percent' }
@@ -24270,13 +24287,18 @@ const IDE_LAYOUT = ['title', 'image', 'actions', 'info-panel', 'toolbar', 'edito
24270
24287
  /**
24271
24288
  * Parse a fence info string into a {@link FenceDescriptor}. The first token is
24272
24289
  * the (already-validated) language and is ignored; remaining tokens are
24273
- * classified as parts, image formats, the `ide` macro, or `width`/`height`
24274
- * options. Unrecognized or conflicting tokens are dropped and recorded in
24290
+ * classified as parts, image formats, the `ide` macro, or the dimension
24291
+ * options `width`/`height` (exact size) and `max-width`/`max-height`
24292
+ * (upper bounds on natural size — see {@link FenceDescriptor} for the
24293
+ * precedence rule when both appear on one axis). All four dimension tokens
24294
+ * share one value syntax: a bare number (pixels), `<n>px`, or `<n>%`.
24295
+ * Unrecognized or conflicting tokens are dropped and recorded in
24275
24296
  * `notes` rather than throwing, so a host can render forward-compatibly.
24276
24297
  * @param info The full fence info string, e.g. `'fsl image code width=300'`.
24277
24298
  * @returns The validated descriptor; `notes` lists anything ignored or overridden.
24278
24299
  * @example parse_fence_info('fsl').parts // => ['image', 'code']
24279
24300
  * @example parse_fence_info('fsl code image').parts // => ['code', 'image']
24301
+ * @example parse_fence_info('fsl image max-width=300 max-height=50%').max_width // => { value: 300, unit: 'px' }
24280
24302
  */
24281
24303
  function parse_fence_info(info) {
24282
24304
  const tokens = info.trim().split(/\s+/).filter(Boolean);
@@ -24285,9 +24307,14 @@ function parse_fence_info(info) {
24285
24307
  const notes = [];
24286
24308
  let format = 'svg';
24287
24309
  let format_set = false;
24288
- let width = null;
24289
- let height = null;
24290
24310
  let ide = false;
24311
+ // the four dimension tokens share one assignment path, keyed by token name
24312
+ const dims = {
24313
+ 'width': null,
24314
+ 'height': null,
24315
+ 'max-width': null,
24316
+ 'max-height': null,
24317
+ };
24291
24318
  for (const arg of args) {
24292
24319
  if (arg === 'ide') {
24293
24320
  ide = true;
@@ -24313,7 +24340,7 @@ function parse_fence_info(info) {
24313
24340
  }
24314
24341
  continue;
24315
24342
  }
24316
- if (arg.startsWith('width=') || arg.startsWith('height=')) {
24343
+ if (arg.startsWith('width=') || arg.startsWith('height=') || arg.startsWith('max-width=') || arg.startsWith('max-height=')) {
24317
24344
  const eq = arg.indexOf('=');
24318
24345
  const key = arg.slice(0, eq);
24319
24346
  const raw = arg.slice(eq + 1);
@@ -24321,11 +24348,8 @@ function parse_fence_info(info) {
24321
24348
  if (dim === null) {
24322
24349
  notes.push(`invalid ${key} value "${raw}" ignored`);
24323
24350
  }
24324
- else if (key === 'width') {
24325
- width = dim;
24326
- }
24327
24351
  else {
24328
- height = dim;
24352
+ dims[key] = dim;
24329
24353
  }
24330
24354
  continue;
24331
24355
  }
@@ -24350,8 +24374,10 @@ function parse_fence_info(info) {
24350
24374
  parts,
24351
24375
  ide,
24352
24376
  format,
24353
- width,
24354
- height,
24377
+ width: dims.width,
24378
+ height: dims.height,
24379
+ max_width: dims['max-width'],
24380
+ max_height: dims['max-height'],
24355
24381
  interactive,
24356
24382
  notes
24357
24383
  };
@@ -29895,8 +29921,12 @@ const default_viz_colors = {
29895
29921
  */
29896
29922
  let viz_instance = null;
29897
29923
  /**
29898
- * Returns a cached @viz-js/viz instance, lazily instantiated on first call.
29899
- * Internal helper for the rendering functions.
29924
+ * Returns the Graphviz engine the render path should use: the engine
29925
+ * injected via {@link configure}`({ viz })` when one is set (checked
29926
+ * *before* the default import, so the `@viz-js/viz` WASM module is never
29927
+ * even loaded in environments that injected their own); otherwise a cached
29928
+ * `@viz-js/viz` instance, lazily instantiated on first call. Internal
29929
+ * helper for the rendering functions.
29900
29930
  * @internal
29901
29931
  */
29902
29932
  async function get_viz() {
@@ -29970,9 +30000,14 @@ function undoublequote(txt) {
29970
30000
  * slug_for('!!!'); // ''
29971
30001
  * slug_for(' Foo Bar '); // 'foo-bar'
29972
30002
  * ```
30003
+ * Exported so consumers which must match rendered SVG node `<title>`s back
30004
+ * to state names (notably `FslViz.highlightTrace`, fsl#1935) can slug with
30005
+ * the *same* function the dot generator used, rather than a drifting copy.
30006
+ *
29973
30007
  * @param state The state name to slugify.
29974
30008
  * @returns The lowercase hyphen-separated slug, or empty string if none of
29975
30009
  * the characters were retainable.
30010
+ * @see slug_states
29976
30011
  * @internal
29977
30012
  */
29978
30013
  function slug_for(state) {
@@ -30994,9 +31029,10 @@ function fsl_to_dot(fsl, opts = {}) {
30994
31029
  return machine_to_dot(sm `${fsl}`, opts);
30995
31030
  }
30996
31031
  /**
30997
- * Render a graphviz dot source string to SVG using `@viz-js/viz`. The
30998
- * underlying viz instance is lazy-initialized on first call and cached for
30999
- * the lifetime of the module.
31032
+ * Render a graphviz dot source string to SVG using `@viz-js/viz`, or the
31033
+ * engine injected via {@link configure}`({ viz })` when one is set. The
31034
+ * default viz instance is lazy-initialized on first call and cached for
31035
+ * the lifetime of the module; an injected engine bypasses it entirely.
31000
31036
  *
31001
31037
  * ```typescript
31002
31038
  * const svg = await dot_to_svg('digraph G { a -> b }');