jssm 5.158.2 → 5.159.1

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.
@@ -65,6 +65,24 @@ declare function vc(col: string): string;
65
65
  * @internal
66
66
  */
67
67
  declare function doublequote(txt: string): string;
68
+ /**
69
+ * Reverse {@link doublequote}: turn DOT's `\"` escape back into the literal
70
+ * `"` that graphviz renders into SVG `<text>` content. Used by
71
+ * {@link state_svg_label_texts} to reconstruct a node's on-screen label from
72
+ * the DOT label it was handed, so the fence renderer keys against exactly what
73
+ * was drawn.
74
+ *
75
+ * ```typescript
76
+ * undoublequote('a\\"b'); // 'a"b'
77
+ * undoublequote('safe'); // 'safe'
78
+ * ```
79
+ *
80
+ * @param txt A DOT-escaped attribute string (as produced by `doublequote`).
81
+ * @returns The string with every `\"` collapsed back to `"`.
82
+ *
83
+ * @internal
84
+ */
85
+ declare function undoublequote(txt: string): string;
68
86
  /**
69
87
  * Convert a state name into a URL-friendly slug suitable for use as the
70
88
  * body of a dot/SVG node identifier. The transformation is:
@@ -459,6 +477,50 @@ declare type VizRenderOpts = {
459
477
  * @internal
460
478
  */
461
479
  declare function node_block_for<T>(u_jssm: jssm.Machine<T>, l_states: string[], state_index: Map<string, string>, state_kinds: Map<string, StateKind>, hide_labels: boolean, mode: RenderGroups): string;
480
+ /**
481
+ * The per-state group-chip map that {@link node_block_for} appends to labels
482
+ * in a given render mode. Mirrors that function's mode dispatch and calls the
483
+ * very same chip sources — {@link chips_for_all_groups} for `'chips'`,
484
+ * {@link plan_cluster_groups} (with identical inputs) for `'cluster'` — so a
485
+ * reconstructed label can never disagree with the one graphviz was handed.
486
+ * `'off'`, and any machine that declares no groups, yields an empty map.
487
+ *
488
+ * @internal
489
+ */
490
+ declare function chips_for_render_mode<T>(u_jssm: jssm.Machine<T>, l_states: string[], mode: RenderGroups): Map<string, string[]>;
491
+ /**
492
+ * The exact text graphviz places in each state's SVG `<text>` element(s) when
493
+ * a machine is rendered via {@link machine_to_dot} / {@link fsl_to_svg_string}:
494
+ * the state's display text plus any group chips the node builder appends, with
495
+ * DOT's `\"` escaping undone (SVG carries the literal character). A label that
496
+ * wraps across lines becomes several `<text>` elements; this returns the lines
497
+ * joined by `\n`, exactly how {@link extract_state_fills} reads them back — so
498
+ * the derived key and the extracted key meet at the same string.
499
+ *
500
+ * This is the single source of truth the static fence renderer keys its
501
+ * highlight and recolor lookups against, so those lookups can never drift from
502
+ * what was actually drawn — plain labels, group chips, and multi-line wraps
503
+ * alike. It is built by running the node builder's own
504
+ * `label_with_chips(doublequote(display_text), chips)` and inverting the one
505
+ * escaping step, so it follows any change to the label format for free.
506
+ *
507
+ * @param u_jssm The machine being rendered.
508
+ * @param opts Render flags; only `render_groups` affects the label text
509
+ * (default `'cluster'`, matching `fsl_to_svg_string`).
510
+ * @returns A map from each state name to its rendered SVG label text.
511
+ *
512
+ * ```typescript
513
+ * import { sm } from 'jssm';
514
+ * import { state_svg_label_texts } from 'jssm/viz';
515
+ *
516
+ * // a state in two groups renders a chip suffix in its node label
517
+ * state_svg_label_texts(sm`&g1 : [a b]; &g2 : [a]; a -> b;`).get('a'); // 'a [g1]'
518
+ * state_svg_label_texts(sm`a -> b;`).get('a'); // 'a'
519
+ * ```
520
+ *
521
+ * @see extract_state_fills
522
+ */
523
+ declare function state_svg_label_texts<T>(u_jssm: jssm.Machine<T>, opts?: VizRenderOpts): Map<string, string>;
462
524
  /**
463
525
  * Render a {@link jssm.Machine} as a graphviz dot string.
464
526
  *
@@ -578,7 +640,7 @@ declare function machine_to_svg_element<T>(u_jssm: jssm.Machine<T>, opts?: VizRe
578
640
  * @deprecated Use {@link machine_to_dot} instead.
579
641
  */
580
642
  declare function dot<T>(machine: jssm.Machine<T>): string;
581
- 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, version, build_time };
643
+ 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, version, build_time };
582
644
  export type { VizRenderOpts, RenderGroups };
583
645
  /** @internal — test-only access to private helpers. */
584
646
  export declare const _test: {
@@ -594,6 +656,7 @@ export declare const _test: {
594
656
  style_for_state: typeof style_for_state;
595
657
  cluster_id_for: typeof cluster_id_for;
596
658
  label_with_chips: typeof label_with_chips;
659
+ undoublequote: typeof undoublequote;
597
660
  group_parent_map: typeof group_parent_map;
598
661
  group_ancestry: typeof group_ancestry;
599
662
  primary_group_for: typeof primary_group_for;
@@ -601,6 +664,7 @@ export declare const _test: {
601
664
  groups_to_subgraph_string: typeof groups_to_subgraph_string;
602
665
  chips_for_all_groups: typeof chips_for_all_groups;
603
666
  node_block_for: typeof node_block_for;
667
+ chips_for_render_mode: typeof chips_for_render_mode;
604
668
  edge_attr_for: typeof edge_attr_for;
605
669
  edge_defaults_body: typeof edge_defaults_body;
606
670
  graph_attr_for: typeof graph_attr_for;