@celestia-island/hikari 0.55.371 → 0.55.372

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celestia-island/hikari",
3
- "version": "0.55.371",
3
+ "version": "0.55.372",
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",
@@ -76,6 +76,7 @@
76
76
  "vue": "^3"
77
77
  },
78
78
  "dependencies": {
79
+ "@bytecodealliance/preview2-shim": "^0.31",
79
80
  "@celestia-island/tairitsu-transport": "^0.2",
80
81
  "@xterm/addon-fit": "^0.11",
81
82
  "@xterm/addon-image": "^0.10.0-beta.301",
@@ -86,7 +87,6 @@
86
87
  "marked": "^18"
87
88
  },
88
89
  "devDependencies": {
89
- "@bytecodealliance/preview2-shim": "^0.31",
90
90
  "@types/node": "^*",
91
91
  "@types/three": "^0.185",
92
92
  "@vitejs/plugin-vue": "^*",
@@ -0,0 +1,87 @@
1
+ // @vitest-environment node
2
+ // wasm↔TS equivalence tests: the wasm component and the TS reference
3
+ // implementation must produce the same output for the same inputs.
4
+ // These tests are the drift detector between the two implementations —
5
+ // the Rust side is the production path, the TS side is the oracle.
6
+
7
+ import { describe, expect, it } from "vitest";
8
+
9
+ import { parseMermaid } from "./parse";
10
+ import { wasmMermaidEngine } from "./wasmEngine";
11
+ import { buildFleetSceneSpec } from "../scene3d/holographicFleetSpec";
12
+ import { buildFleetSceneSpecWasm } from "../scene3d/wasmFleetSpec";
13
+ import type { FleetRowLike } from "../scene3d/holographicFleetSpec";
14
+
15
+ const GRAPH_CASES = [
16
+ "graph TD\n A --> B\n B --> C",
17
+ "flowchart LR\n Start[Start] --> Mid{Check} --> End",
18
+ "graph TD\n A[Label] -->|edge label| B(Label2)",
19
+ "graph TD\n X --> Y --> Z --> X",
20
+ ];
21
+
22
+ const SEQUENCE_CASES = [
23
+ "sequenceDiagram\n Alice->>Bob: Hello\n Bob-->>Alice: Hi",
24
+ "sequenceDiagram\n A->B: sync\n B-->C: async\n C->>A: reply",
25
+ ];
26
+
27
+ const PIE_CASES = [
28
+ 'pie\n title Sales\n "Alpha" : 40\n "Beta" : 60',
29
+ 'pie\n "X" : 1\n "Y" : 2',
30
+ ];
31
+
32
+ describe("wasm↔TS equivalence: mermaid", () => {
33
+ for (const src of GRAPH_CASES) {
34
+ it(`graph: ${src.split("\n")[0]}`, () => {
35
+ const ts = parseMermaid(src);
36
+ const wasm = wasmMermaidEngine.parse(src);
37
+ expect(wasm).toEqual(ts);
38
+ });
39
+ }
40
+
41
+ for (const src of SEQUENCE_CASES) {
42
+ it(`sequence: ${src.split("\n")[0]}`, () => {
43
+ const ts = parseMermaid(src);
44
+ const wasm = wasmMermaidEngine.parse(src);
45
+ expect(wasm).toEqual(ts);
46
+ });
47
+ }
48
+
49
+ for (const src of PIE_CASES) {
50
+ it(`pie: ${src.split("\n")[0]}`, () => {
51
+ const ts = parseMermaid(src);
52
+ const wasm = wasmMermaidEngine.parse(src);
53
+ expect(wasm).toEqual(ts);
54
+ });
55
+ }
56
+ });
57
+
58
+ const FLEET_ROWS: FleetRowLike[] = [
59
+ { node_id: "hub-a", tier: 3, station_count: 2, label: "Hub A" },
60
+ { node_id: "hub-b", tier: 3, station_count: 1, label: "Hub B" },
61
+ { node_id: "node-1", tier: 2, station_count: 5, label: "Node 1" },
62
+ { node_id: "node-2", tier: 2, station_count: 0, label: "Node 2" },
63
+ { node_id: "node-3", tier: 2, station_count: 8, label: "Node 3" },
64
+ ];
65
+
66
+ describe("wasm↔TS equivalence: scene3d", () => {
67
+ it("fleet scene spec produces identical stars and planets", () => {
68
+ const ts = buildFleetSceneSpec(FLEET_ROWS);
69
+ const wasm = buildFleetSceneSpecWasm(FLEET_ROWS);
70
+ expect(wasm.stars.length).toBe(ts.stars.length);
71
+ expect(wasm.planets.length).toBe(ts.planets.length);
72
+ expect(wasm.hasRegistryCore).toBe(ts.hasRegistryCore);
73
+ // Field-level drift detection on each star.
74
+ for (let i = 0; i < ts.stars.length; i++) {
75
+ expect(wasm.stars[i]!.id).toBe(ts.stars[i]!.id);
76
+ expect(wasm.stars[i]!.label).toBe(ts.stars[i]!.label);
77
+ expect(wasm.stars[i]!.radius).toBeCloseTo(ts.stars[i]!.radius, 4);
78
+ expect(wasm.stars[i]!.orbitRadius).toBeCloseTo(ts.stars[i]!.orbitRadius, 4);
79
+ }
80
+ // Field-level on each planet.
81
+ for (let i = 0; i < ts.planets.length; i++) {
82
+ expect(wasm.planets[i]!.id).toBe(ts.planets[i]!.id);
83
+ expect(wasm.planets[i]!.orbitRadius).toBeCloseTo(ts.planets[i]!.orbitRadius, 4);
84
+ expect(wasm.planets[i]!.orbitPeriodSec).toBeCloseTo(ts.planets[i]!.orbitPeriodSec, 3);
85
+ }
86
+ });
87
+ });
@@ -1,7 +1,7 @@
1
1
  // @vitest-environment node
2
2
  import { describe, expect, it } from "vitest";
3
3
 
4
- import type { MermaidGraphDoc } from "./types";
4
+ import type { MermaidClassDoc, MermaidGraphDoc, MermaidPieDoc, MermaidQuadrantDoc, MermaidSequenceDoc } from "./types";
5
5
  import { wasmMermaidEngine } from "./wasmEngine";
6
6
 
7
7
  describe("wasmMermaidEngine", () => {
@@ -26,11 +26,70 @@ describe("wasmMermaidEngine", () => {
26
26
  expect(wasmMermaidEngine.parse("this is not a diagram")).toBeNull();
27
27
  });
28
28
 
29
- it("falls through to the TS parser for sequence diagrams", () => {
29
+ it("parses a sequence diagram through the wasm component", () => {
30
30
  const doc = wasmMermaidEngine.parse(
31
31
  "sequenceDiagram\n Alice->>Bob: Hello\n Bob-->>Alice: Hi",
32
- );
32
+ ) as MermaidSequenceDoc;
33
33
  expect(doc).not.toBeNull();
34
34
  expect(doc!.kind).toBe("sequence");
35
+ expect(doc!.participants).toContain("Alice");
36
+ expect(doc!.messages).toHaveLength(2);
37
+ // Arrow kind mapping: ->> = solid-open, -->> = dotted-open.
38
+ expect(doc!.messages[0]!.arrowKind).toBe("solid-open");
39
+ expect(doc!.messages[1]!.arrowKind).toBe("dotted-open");
40
+ });
41
+
42
+ it("parses a pie chart through the wasm component", () => {
43
+ const doc = wasmMermaidEngine.parse(
44
+ 'pie\n title Sales\n "Alpha" : 40\n "Beta" : 60',
45
+ ) as MermaidPieDoc;
46
+ expect(doc).not.toBeNull();
47
+ expect(doc!.kind).toBe("pie");
48
+ expect(doc!.title).toBe("Sales");
49
+ expect(doc!.slices).toHaveLength(2);
50
+ // Slices serialize as objects with label/value, not tuples.
51
+ expect(doc!.slices[0]!.label).toBe("Alpha");
52
+ expect(doc!.slices[0]!.value).toBe(40);
53
+ });
54
+
55
+ it("parses a class diagram through the wasm component", () => {
56
+ const doc = wasmMermaidEngine.parse(
57
+ "classDiagram\n class Animal {\n +name: String\n +speak() void\n }\n Dog <|-- Animal",
58
+ ) as MermaidClassDoc;
59
+ expect(doc).not.toBeNull();
60
+ expect(doc!.kind).toBe("class");
61
+ expect(doc!.classes).toHaveLength(1);
62
+ expect(doc!.classes[0]!.name).toBe("Animal");
63
+ // Members split: +name is an attribute, +speak() is a method.
64
+ expect(doc!.classes[0]!.attributes).toHaveLength(1);
65
+ expect(doc!.classes[0]!.methods).toHaveLength(1);
66
+ expect(doc!.classes[0]!.methods[0]!.name).toBe("speak");
67
+ // Relationship: <|-- maps to inheritance.
68
+ expect(doc!.relationships).toHaveLength(1);
69
+ expect(doc!.relationships[0]!.relType).toBe("inheritance");
70
+ expect(doc!.relationships[0]!.from).toBe("Dog");
71
+ expect(doc!.relationships[0]!.to).toBe("Animal");
72
+ });
73
+
74
+ it("parses a quadrant chart through the wasm component", () => {
75
+ const doc = wasmMermaidEngine.parse(
76
+ "quadrantChart\n x-axis Low --> High\n y-axis Bottom --> Top\n quadrant-1 Growth\n Point A: [0.5, 0.7]",
77
+ ) as MermaidQuadrantDoc;
78
+ expect(doc).not.toBeNull();
79
+ expect(doc!.kind).toBe("quadrant");
80
+ expect(doc!.xAxisLeft).toBe("Low");
81
+ expect(doc!.xAxisRight).toBe("High");
82
+ expect(doc!.quadrants[0]).toBe("Growth");
83
+ expect(doc!.points).toHaveLength(1);
84
+ expect(doc!.points[0]!.label).toBe("Point A");
85
+ expect(doc!.points[0]!.x).toBeCloseTo(0.5, 5);
86
+ });
87
+
88
+ it("parses a gantt chart through the wasm component", () => {
89
+ const doc = wasmMermaidEngine.parse(
90
+ "gantt\n title Project\n section Design\n Task1 :a1, 5d",
91
+ );
92
+ expect(doc).not.toBeNull();
93
+ expect(doc!.kind).toBe("gantt");
35
94
  });
36
95
  });
@@ -15,8 +15,8 @@ import { parse } from "../wasm/mermaid/hikari_wasm_mermaid.js";
15
15
 
16
16
  /** Check whether the wasm component handles this diagram type. */
17
17
  function wasmHandles(source: string): boolean {
18
- // First wave: graph/flowchart only.
19
- return /^\s*(graph|flowchart)\b/i.test(source);
18
+ // Second wave: graph/flowchart + pie/gantt/sequence.
19
+ return /^\s*(graph|flowchart|pie|gantt|sequenceDiagram|classDiagram|quadrantChart)\b/i.test(source);
20
20
  }
21
21
 
22
22
  export const wasmMermaidEngine: MermaidParserEngine = {
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Packaging contract: every package imported at module top level by
3
+ * SHIPPED src/ must be a runtime dependency. The wasm wave shipped
4
+ * src/wasm/{qr,mermaid,scene3d} modules whose generated js imports
5
+ * @bytecodealliance/preview2-shim at top level while the package kept
6
+ * it in devDependencies — hikari's own gates install devDeps and
7
+ * stayed green, while every downstream consumer's resolver failed on
8
+ * the barrel import (0.55.371 field report: chest, 90 test files of
9
+ * ERR_MODULE_NOT_FOUND). The shim now lives in dependencies; this pin
10
+ * keeps it there (mutation: move it back → red).
11
+ */
12
+ import { describe, expect, it } from "vitest";
13
+ import { readFileSync } from "node:fs";
14
+ import { dirname, join } from "node:path";
15
+ import { fileURLToPath } from "node:url";
16
+
17
+ const here = dirname(fileURLToPath(import.meta.url));
18
+
19
+ const pkg = JSON.parse(readFileSync(join(here, "..", "package.json"), "utf-8"));
20
+
21
+ describe("packaging contract", () => {
22
+ it("keeps the wasm shim in dependencies (shipped src imports it)", () => {
23
+ expect(pkg.dependencies?.["@bytecodealliance/preview2-shim"]).toBe("^0.31");
24
+ expect(pkg.devDependencies?.["@bytecodealliance/preview2-shim"]).toBeUndefined();
25
+ });
26
+ });