@celestia-island/hikari 0.55.503 → 0.55.505

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.
@@ -18,5 +18,21 @@ export declare const mermaidCapabilities: {
18
18
  interfaces: string[];
19
19
  wasiModules: string[];
20
20
  };
21
+ /**
22
+ * Rewrite a `stateDiagram` into the flowchart grammar the pest parser speaks.
23
+ *
24
+ * Two rewrites carry real semantics:
25
+ *
26
+ * - `[*]` is TWO different pseudostates — the initial marker and the final
27
+ * marker. The old blanket replace mapped both to one literal node, so a
28
+ * diagram read `… --> STATE_START_END` at the top AND at the bottom and the
29
+ * layout merged them into a single labelled box between the two (the audit
30
+ * recorded it as "«[*]» start and end collapse into one frame"). They now
31
+ * get distinct ids AND a circle shape with an empty label, which is what
32
+ * mermaid draws;
33
+ * - `A --> B : label` becomes `A -->|label| B` (the flowchart's caption form),
34
+ * which is the only shape the grammar can carry.
35
+ */
36
+ export declare function normalizeStateDiagram(source: string): string;
21
37
  export declare const wasmMermaidEngine: MermaidParserEngine;
22
38
  export { HostClientError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celestia-island/hikari",
3
- "version": "0.55.503",
3
+ "version": "0.55.505",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Hikari UI library, Vue 3 runtime — one design system for Vue 3 and Rust/WASM applications",
@@ -115,4 +115,36 @@ describe("stateDiagram", () => {
115
115
  expect(doc).not.toBeNull();
116
116
  expect(doc!.kind).toBe("graph");
117
117
  });
118
+
119
+ /// `[*]` is two DIFFERENT pseudostates (initial and final). The old blanket
120
+ /// replace mapped both to one literal node, so the layout merged them into a
121
+ /// single labelled box with every edge pointing at it.
122
+ /// MUT: collapsing either rewrite back to one id never passes — the two
123
+ /// circle assertions below catch it.
124
+ it("keeps the initial and final pseudostates apart, as circles", async () => {
125
+ await mermaidReady;
126
+ const doc = wasmMermaidEngine.parse("stateDiagram-v2\n [*] --> Idle\n Idle --> Running\n Running --> [*]");
127
+ expect(doc).not.toBeNull();
128
+ const g = doc as unknown as { nodes: Array<{ id: string; label: string; shape: string }>; edges: Array<{ source: string; target: string }> };
129
+ const circles = g.nodes.filter((n) => n.shape === "circle");
130
+ expect(circles.length, "one circle for the start and one for the end").toBe(2);
131
+ expect(new Set(circles.map((n) => n.id)).size).toBe(2);
132
+ // The pseudostates carry no text (mermaid draws a bare circle).
133
+ for (const c of circles) expect(c.label).toBe("");
134
+ // …and they are NOT the same node the transitions run through.
135
+ const ids = g.nodes.map((n) => n.id);
136
+ expect(ids).toContain("Idle");
137
+ expect(ids).toContain("Running");
138
+ // The start has no incoming edge; the end has no outgoing edge.
139
+ const sources = g.edges.map((e) => e.source);
140
+ const targets = g.edges.map((e) => e.target);
141
+ const [start, end] = [circles[0].id, circles[1].id].sort();
142
+ void start;
143
+ void end;
144
+ const startNode = circles.find((c) => !targets.includes(c.id));
145
+ const endNode = circles.find((c) => !sources.includes(c.id));
146
+ expect(startNode, "a start pseudostate with no incoming edge").toBeTruthy();
147
+ expect(endNode, "an end pseudostate with no outgoing edge").toBeTruthy();
148
+ expect(startNode!.id).not.toBe(endNode!.id);
149
+ });
118
150
  });
@@ -1,7 +1,7 @@
1
1
  <!doctype html>
2
2
  <html lang="en">
3
3
  <head>
4
- <meta name="hk-error-landing" content="v1 0.55.503 <dev>">
4
+ <meta name="hk-error-landing" content="v1 0.55.505 <dev>">
5
5
  <meta charset="utf-8" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1" />
7
7
  <meta name="robots" content="noindex" />
@@ -105,6 +105,37 @@ mermaidReady.catch(() => {
105
105
  // handles would be an unhandled rejection.
106
106
  });
107
107
 
108
+ /**
109
+ * Rewrite a `stateDiagram` into the flowchart grammar the pest parser speaks.
110
+ *
111
+ * Two rewrites carry real semantics:
112
+ *
113
+ * - `[*]` is TWO different pseudostates — the initial marker and the final
114
+ * marker. The old blanket replace mapped both to one literal node, so a
115
+ * diagram read `… --> STATE_START_END` at the top AND at the bottom and the
116
+ * layout merged them into a single labelled box between the two (the audit
117
+ * recorded it as "«[*]» start and end collapse into one frame"). They now
118
+ * get distinct ids AND a circle shape with an empty label, which is what
119
+ * mermaid draws;
120
+ * - `A --> B : label` becomes `A -->|label| B` (the flowchart's caption form),
121
+ * which is the only shape the grammar can carry.
122
+ */
123
+ export function normalizeStateDiagram(source: string): string {
124
+ const START = "__hk_state_start";
125
+ const END = "__hk_state_end";
126
+ return source
127
+ .replace(/^\s*stateDiagram(-v\d+)?/, "graph TD")
128
+ // `[*] --> X` is the initial marker; `X --> [*]` is the final one. Handle
129
+ // both directions BEFORE any leftover `[*]` so a line that has one on each
130
+ // side (`[*] --> [*]`) still yields two distinct pseudostates.
131
+ .replace(/\[\*\](\s*(?:-->|--)\s*)/g, `${START}((""))$1`)
132
+ .replace(/((?:-->|--)\s*)\[\*\]/g, `$1${END}((""))`)
133
+ // Any remaining `[*]` (a node named on its own line) becomes the start.
134
+ .replace(/\[\*\]/g, `${START}((""))`)
135
+ // State transition labels: `A --> B : label` → `A -->|label| B`
136
+ .replace(/^(\s*)(\S+)\s+(-->|--)\s+(\S+)\s*:\s*(.+)$/gm, "$1$2 $3|$5| $4");
137
+ }
138
+
108
139
  /** Check whether the wasm component handles this diagram type. */
109
140
  function wasmHandles(source: string): boolean {
110
141
  // Second wave: graph/flowchart + pie/gantt/sequence.
@@ -116,13 +147,7 @@ export const wasmMermaidEngine: MermaidParserEngine = {
116
147
  if (!surface) throw loadFailure ?? new MermaidNotReadyError();
117
148
  // State diagrams parse into the same graph shape; the pest grammar
118
149
  // only speaks "graph"/"flowchart", so rewrite the keyword.
119
- const normalized = /^\s*stateDiagram/i.test(source)
120
- ? source
121
- .replace(/^\s*stateDiagram(-v\d+)?/, "graph TD")
122
- .replace(/\[\*\]/g, "STATE_START_END")
123
- // State transition labels: `A --> B : label` → `A -->|label| B`
124
- .replace(/^(\s*)(\S+)\s+(-->|--)\s+(\S+)\s*:\s*(.+)$/gm, "$1$2 $3|$5| $4")
125
- : source;
150
+ const normalized = /^\s*stateDiagram/i.test(source) ? normalizeStateDiagram(source) : source;
126
151
  if (wasmHandles(normalized)) {
127
152
  // The record (not a result): an absent `json` means "not recognized".
128
153
  const result = surface.call<MermaidParseResult | undefined>("parse", normalized);