@zyro-sec/merman 1.0.2 → 1.0.3

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.
Files changed (91) hide show
  1. package/package.json +2 -2
  2. package/script/layout-audit.ts +98 -98
  3. package/src/core/canvas.ts +228 -228
  4. package/src/core/color/style.ts +56 -56
  5. package/src/core/drawing.ts +301 -301
  6. package/src/core/geometry.ts +347 -347
  7. package/src/core/mermaid.ts +38 -38
  8. package/src/core/render-grid.ts +51 -51
  9. package/src/core/spatial.ts +243 -243
  10. package/src/core/text-lines.ts +32 -32
  11. package/src/core/text.ts +44 -44
  12. package/src/detect.ts +17 -17
  13. package/src/diagnostics.ts +16 -16
  14. package/src/flowchart/drawing.ts +340 -340
  15. package/src/flowchart/labels.ts +144 -144
  16. package/src/flowchart/layout.ts +1427 -1427
  17. package/src/flowchart/options.ts +12 -12
  18. package/src/flowchart/parser.ts +467 -467
  19. package/src/flowchart/render.ts +10 -10
  20. package/src/flowchart/routing.ts +1542 -1542
  21. package/src/flowchart/style.ts +79 -79
  22. package/src/flowchart/types.ts +65 -65
  23. package/src/gantt/diagram.ts +8 -8
  24. package/src/gantt/drawing.ts +191 -191
  25. package/src/gantt/parser.ts +161 -161
  26. package/src/gantt/render-grid.ts +17 -17
  27. package/src/gantt/style.ts +36 -36
  28. package/src/gantt/types.ts +44 -44
  29. package/src/gitgraph/diagram.ts +8 -8
  30. package/src/gitgraph/drawing.ts +234 -234
  31. package/src/gitgraph/parser.ts +219 -219
  32. package/src/gitgraph/render-grid.ts +17 -17
  33. package/src/gitgraph/style.ts +37 -37
  34. package/src/gitgraph/types.ts +36 -36
  35. package/src/markdown.ts +336 -336
  36. package/src/palette.ts +75 -75
  37. package/src/plugin.ts +15 -15
  38. package/src/sequence/diagram.ts +8 -8
  39. package/src/sequence/drawing.ts +287 -287
  40. package/src/sequence/options.ts +8 -8
  41. package/src/sequence/parser.ts +282 -282
  42. package/src/sequence/placement.ts +684 -684
  43. package/src/sequence/render-grid.ts +22 -22
  44. package/src/sequence/style.ts +81 -81
  45. package/src/sequence/types.ts +74 -74
  46. package/src/state/diagram.ts +8 -8
  47. package/src/state/drawing.ts +360 -360
  48. package/src/state/endpoint.ts +15 -15
  49. package/src/state/layout.ts +1134 -1134
  50. package/src/state/note.ts +59 -59
  51. package/src/state/options.ts +11 -11
  52. package/src/state/parser.ts +224 -224
  53. package/src/state/render-grid.ts +22 -22
  54. package/src/state/routing.ts +1522 -1522
  55. package/src/state/search.ts +103 -103
  56. package/src/state/style.ts +52 -52
  57. package/src/state/types.ts +63 -63
  58. package/src/state/visible-model.ts +77 -77
  59. package/src/test/diagram.ts +32 -32
  60. package/src/test/layout-audit/fixtures.ts +538 -538
  61. package/src/test/layout-audit/harness.ts +522 -522
  62. package/src/timeline/diagram.ts +8 -8
  63. package/src/timeline/drawing.ts +109 -109
  64. package/src/timeline/parser.ts +119 -119
  65. package/src/timeline/render-grid.ts +17 -17
  66. package/src/timeline/style.ts +36 -36
  67. package/src/timeline/types.ts +31 -31
  68. package/tsconfig.json +10 -10
  69. package/src/core/canvas.test.ts +0 -203
  70. package/src/core/color/style.test.ts +0 -24
  71. package/src/core/drawing.test.ts +0 -116
  72. package/src/core/geometry.test.ts +0 -112
  73. package/src/core/spatial.test.ts +0 -87
  74. package/src/core/text.test.ts +0 -33
  75. package/src/flowchart/flowchart.test.ts +0 -2800
  76. package/src/flowchart/labels.test.ts +0 -127
  77. package/src/flowchart/routing.test.ts +0 -368
  78. package/src/gantt/diagram.test.ts +0 -124
  79. package/src/gitgraph/diagram.test.ts +0 -183
  80. package/src/layout-audit.test.ts +0 -92
  81. package/src/palette.test.ts +0 -103
  82. package/src/sequence/diagram.test.ts +0 -757
  83. package/src/sequence/placement.test.ts +0 -219
  84. package/src/state/diagram.test.ts +0 -1386
  85. package/src/state/layout.test.ts +0 -314
  86. package/src/state/routing.test.ts +0 -693
  87. package/src/state/style.test.ts +0 -113
  88. package/src/state/visible-model.test.ts +0 -84
  89. package/src/test/diagnostics.test.ts +0 -129
  90. package/src/test/markdown.test.ts +0 -474
  91. package/src/timeline/diagram.test.ts +0 -188
@@ -1,113 +0,0 @@
1
- import { describe, expect, test } from "bun:test"
2
- import { RGBA } from "@opentui/core"
3
- import { drawStateDiagramGrid } from "./drawing.js"
4
- import { parseMermaidStateDiagram } from "./parser.js"
5
- import { renderStateGridStyledText } from "./render-grid.js"
6
- import { resolveStateStyleColors } from "./style.js"
7
-
8
- describe("state note connector styles", () => {
9
- test("ramps the final connector cells into the note border", () => {
10
- const grid = drawStateDiagramGrid(
11
- parseMermaidStateDiagram(`stateDiagram-v2
12
- direction LR
13
- A --> B
14
- note right of A : note`),
15
- )
16
- const connectorStyles = grid.rows.flatMap((row) =>
17
- row.map((cell) => cell.style).filter((style) => style?.startsWith("noteConnectorRamp")),
18
- )
19
-
20
- expect(new Set(connectorStyles)).toEqual(
21
- new Set(["noteConnectorRamp1", "noteConnectorRamp2", "noteConnectorRamp3"]),
22
- )
23
- })
24
-
25
- test("resolves the ramp from connector color toward border color", () => {
26
- const colors = resolveStateStyleColors({
27
- noteConnector: RGBA.fromInts(0, 0, 0, 255),
28
- noteBorder: RGBA.fromInts(200, 200, 200, 255),
29
- })
30
- const reds = [
31
- colors.noteConnector.toInts()[0],
32
- colors.noteConnectorRamp1.toInts()[0],
33
- colors.noteConnectorRamp2.toInts()[0],
34
- colors.noteConnectorRamp3.toInts()[0],
35
- colors.noteBorder.toInts()[0],
36
- ]
37
-
38
- expect(reds).toEqual([...reds].sort((left, right) => left - right))
39
- expect(new Set(reds).size).toBe(5)
40
- })
41
- })
42
-
43
- describe("state transition departure styles", () => {
44
- test("ramps once from an ordinary state without restarting at a choice fork", () => {
45
- const grid = drawStateDiagramGrid(
46
- parseMermaidStateDiagram(`stateDiagram-v2
47
- Check --> Decision
48
- state Decision <<choice>>
49
- Decision --> Ready: yes
50
- Decision --> Failed: no`),
51
- )
52
- const rampStyles = grid.rows
53
- .flatMap((row) => row.map((cell) => cell.style))
54
- .filter((style) => style?.startsWith("stateDepartureRamp"))
55
-
56
- expect(rampStyles).toHaveLength(3)
57
- expect(new Set(rampStyles)).toEqual(new Set(["stateDepartureRamp1", "stateDepartureRamp2", "stateDepartureRamp3"]))
58
- })
59
- })
60
-
61
- describe("state component styles", () => {
62
- test("separates box and group text from their borders", () => {
63
- const grid = drawStateDiagramGrid(
64
- parseMermaidStateDiagram(`stateDiagram-v2
65
- state Group {
66
- A --> [*]
67
- }`),
68
- )
69
- const styles = grid.rows.flatMap((row) => row.map((cell) => cell.style))
70
-
71
- expect(styles).toContain("state")
72
- expect(styles).toContain("stateBorder")
73
- expect(styles).toContain("composite")
74
- expect(styles).toContain("compositeLabel")
75
- })
76
-
77
- test("resolves independent box and group text colors", () => {
78
- const state = RGBA.fromInts(10, 0, 0, 255)
79
- const stateBorder = RGBA.fromInts(20, 0, 0, 255)
80
- const composite = RGBA.fromInts(30, 0, 0, 255)
81
- const compositeLabel = RGBA.fromInts(40, 0, 0, 255)
82
- const colors = resolveStateStyleColors({ state, stateBorder, composite, compositeLabel })
83
-
84
- expect(colors.state).toBe(state)
85
- expect(colors.stateBorder).toBe(stateBorder)
86
- expect(colors.composite).toBe(composite)
87
- expect(colors.compositeLabel).toBe(compositeLabel)
88
- })
89
-
90
- test("renders transition labels with an independent background", () => {
91
- const background = RGBA.fromInts(30, 40, 50, 255)
92
- const grid = drawStateDiagramGrid(
93
- parseMermaidStateDiagram(`stateDiagram-v2
94
- A --> B: transition label`),
95
- )
96
- const styled = renderStateGridStyledText(grid, resolveStateStyleColors(), { label: background })
97
- const row = grid.rows.find((cells) =>
98
- cells
99
- .map((cell) => cell.char)
100
- .join("")
101
- .includes("transition label"),
102
- )!
103
- const start = row
104
- .map((cell) => cell.char)
105
- .join("")
106
- .indexOf("transition label")
107
-
108
- expect(styled.chunks.some((chunk) => chunk.text === " transition label " && chunk.bg === background)).toBe(true)
109
- expect(styled.chunks.some((chunk) => chunk.text.includes("A") && chunk.bg !== undefined)).toBe(false)
110
- expect(row[start - 1]?.style).toBe("label")
111
- expect(row[start + "transition label".length]?.style).toBe("label")
112
- })
113
- })
@@ -1,84 +0,0 @@
1
- import { describe, expect, test } from "bun:test"
2
- import { parseMermaidStateDiagram } from "./parser.js"
3
- import { prepareVisibleStateDiagram } from "./visible-model.js"
4
-
5
- describe("prepareVisibleStateDiagram", () => {
6
- test("collapses composite marker transitions", () => {
7
- const parsed = parseMermaidStateDiagram(`stateDiagram-v2
8
- [*] --> Authenticated: login
9
- state Authenticated {
10
- [*] --> Idle
11
- Idle --> Editing: open
12
- Editing --> [*]: save
13
- }
14
- Authenticated --> [*]: logout`)
15
-
16
- const visible = prepareVisibleStateDiagram(parsed)
17
- const entry = visible.transitions.find((transition) => transition.from === "__start")
18
- const exit = visible.transitions.find((transition) => transition.to === "__end")
19
-
20
- expect(visible.states.some((state) => state.id === "Authenticated.__start")).toBe(false)
21
- expect(visible.states.some((state) => state.id === "Authenticated.__end")).toBe(false)
22
- expect(entry).toMatchObject({ from: "__start", to: "Idle", label: "login" })
23
- expect(exit).toMatchObject({ from: "Editing", to: "__end", label: "save<br/>logout" })
24
- })
25
-
26
- test("collapses nested composite entry chains without retaining scoped markers", () => {
27
- const visible = prepareVisibleStateDiagram(
28
- parseMermaidStateDiagram(`stateDiagram-v2
29
- state Session {
30
- [*] --> Open
31
- state Open {
32
- [*] --> Clean
33
- Clean --> Dirty: edit
34
- Dirty --> Clean: save
35
- }
36
- Open --> [*]: close
37
- }
38
- [*] --> Session
39
- Session --> [*]`),
40
- )
41
-
42
- expect(visible.states.map((state) => state.id)).toEqual(["Clean", "Dirty", "__start", "__end"])
43
- expect(visible.transitions).toContainEqual({ from: "__start", to: "Clean", label: "" })
44
- expect(visible.transitions.some((transition) => transition.from.includes(".__start"))).toBe(false)
45
- expect(visible.transitions.some((transition) => transition.to.includes(".__start"))).toBe(false)
46
- })
47
-
48
- test("resolves an outgoing composite transition through its concrete exit state", () => {
49
- const visible = prepareVisibleStateDiagram(
50
- parseMermaidStateDiagram(`stateDiagram-v2
51
- state Session {
52
- [*] --> Open
53
- state Open {
54
- [*] --> Clean
55
- Clean --> Dirty: edit
56
- Dirty --> Clean: save
57
- Dirty --> [*]
58
- }
59
- Open --> Closing: request close
60
- Closing --> Open: cancel
61
- }
62
- [*] --> Session: hydrate`),
63
- )
64
-
65
- expect(visible.transitions).toContainEqual({ from: "Dirty", to: "Closing", label: "request close" })
66
- expect(visible.transitions).toContainEqual({ from: "Closing", to: "Clean", label: "cancel" })
67
- expect(visible.transitions.some((transition) => transition.from === "Open")).toBe(false)
68
- })
69
-
70
- test("preserves labels on both sides of collapsed composite markers", () => {
71
- const visible = prepareVisibleStateDiagram(
72
- parseMermaidStateDiagram(`stateDiagram-v2
73
- [*] --> Session: open session
74
- state Session {
75
- [*] --> Ready: initialize
76
- Ready --> [*]: finalize
77
- }
78
- Session --> [*]: close session`),
79
- )
80
-
81
- expect(visible.transitions).toContainEqual({ from: "__start", to: "Ready", label: "open session<br/>initialize" })
82
- expect(visible.transitions).toContainEqual({ from: "Ready", to: "__end", label: "finalize<br/>close session" })
83
- })
84
- })
@@ -1,129 +0,0 @@
1
- import { describe, expect, test } from "bun:test"
2
- import { MermaidSyntaxError } from "../diagnostics.js"
3
- import { renderGitGraphDiagram } from "../gitgraph/diagram.js"
4
- import { parseMermaidFlowchartDiagram } from "../flowchart/parser.js"
5
- import { parseMermaidSequenceDiagram } from "../sequence/parser.js"
6
- import { parseMermaidStateDiagram } from "../state/parser.js"
7
- import { renderTimelineDiagram } from "../timeline/diagram.js"
8
- import { renderSequenceDiagram } from "../sequence/diagram.js"
9
-
10
- describe("parser diagnostics", () => {
11
- test("ignores flowchart presentation directives that do not change terminal structure", () => {
12
- const diagram = parseMermaidFlowchartDiagram(`flowchart LR
13
- A[Start] --> B[Done]
14
- classDef highlight fill:#fff
15
- class A highlight
16
- style B fill:#000
17
- linkStyle 0 stroke:#fff`)
18
-
19
- expect(diagram.nodes.map((node) => node.id)).toEqual(["A", "B"])
20
- expect(diagram.edges).toHaveLength(1)
21
- })
22
-
23
- test("reports unsupported structural flowchart statements with source location", () => {
24
- expect(() =>
25
- parseMermaidFlowchartDiagram(`flowchart LR
26
- A[Start] --> B[Done]
27
- A --o B`),
28
- ).toThrow('Unsupported syntax in flowchart diagram at line 3: "A --o B"')
29
- })
30
-
31
- test("does not partially parse unsupported flowchart syntax", () => {
32
- for (const statement of ["A & --> C", "A((Start)) --> B", "A-->B; B-->C"]) {
33
- expect(() => parseMermaidFlowchartDiagram(`flowchart LR\n ${statement}`)).toThrow(MermaidSyntaxError)
34
- }
35
- })
36
-
37
- test("does not treat arrows inside flowchart node labels as edges", () => {
38
- const diagram = parseMermaidFlowchartDiagram(`flowchart LR
39
- A["send --> receive"] --> B`)
40
-
41
- expect(diagram.nodes.map((node) => node.id)).toEqual(["A", "B"])
42
- expect(diagram.nodes[0]?.label).toBe("send --> receive")
43
- expect(diagram.edges).toHaveLength(1)
44
- })
45
-
46
- test("rejects pathological flowchart statements before parsing edge operators", () => {
47
- const statement = "-.a".repeat(4_000)
48
- expect(() => parseMermaidFlowchartDiagram(`flowchart LR\n${statement}`)).toThrow("Flowchart statement is too long")
49
- })
50
-
51
- test("exposes structured syntax errors through top-level rendering", () => {
52
- try {
53
- renderSequenceDiagram(`sequenceDiagram
54
- A->>B: request
55
- opt retry`)
56
- throw new Error("expected render to reject unsupported syntax")
57
- } catch (error) {
58
- expect(error).toBeInstanceOf(MermaidSyntaxError)
59
- if (!(error instanceof MermaidSyntaxError)) return
60
- expect(error.kind).toBe("sequence")
61
- expect(error.lineNumber).toBe(3)
62
- expect(error.sourceLine).toBe("opt retry")
63
- }
64
- })
65
-
66
- test("rejects unsupported bidirectional sequence arrows without phantom participants", () => {
67
- for (const message of ["A<<->>B: hello", "A<<-->>B: hello"]) {
68
- expect(() => parseMermaidSequenceDiagram(`sequenceDiagram\n ${message}`)).toThrow(MermaidSyntaxError)
69
- }
70
- })
71
-
72
- test("rejects chained sequence and state transitions instead of creating phantom endpoints", () => {
73
- expect(() => parseMermaidSequenceDiagram("sequenceDiagram\n A->>B->>C: hello")).toThrow(MermaidSyntaxError)
74
- expect(() => parseMermaidStateDiagram("stateDiagram-v2\n A-->B-->C")).toThrow(MermaidSyntaxError)
75
- })
76
-
77
- test("reports unclosed state constructs at their opening line", () => {
78
- expect(() =>
79
- parseMermaidStateDiagram(`stateDiagram-v2
80
- state Running {
81
- [*] --> Ready`),
82
- ).toThrow('Unclosed composite state; expected "}" in state diagram at line 2: "state Running {"')
83
- })
84
-
85
- test("reports unsupported state statements", () => {
86
- expect(() => parseMermaidStateDiagram(`stateDiagram-v2\n hide empty description`)).toThrow(
87
- 'Unsupported syntax in state diagram at line 2: "hide empty description"',
88
- )
89
- })
90
-
91
- test("rejects unsupported composite-local state directions", () => {
92
- expect(() =>
93
- parseMermaidStateDiagram(`stateDiagram-v2
94
- direction LR
95
- state Parent {
96
- direction TB
97
- A --> B
98
- }`),
99
- ).toThrow("Composite-local direction is not supported")
100
- })
101
-
102
- test("reports malformed sequence block endings", () => {
103
- expect(() =>
104
- parseMermaidSequenceDiagram(`sequenceDiagram
105
- end`),
106
- ).toThrow('Unexpected "end" without an open block in sequence diagram at line 2: "end"')
107
- })
108
-
109
- test("reports malformed timeline continuations with timeline diagnostics", () => {
110
- expect(() => renderTimelineDiagram("timeline\n : orphan event")).toThrow(
111
- 'Timeline continuation requires a preceding period in timeline diagram at line 2: ": orphan event"',
112
- )
113
- })
114
-
115
- test("reports unsupported GitGraph operations with source diagnostics", () => {
116
- expect(() => renderGitGraphDiagram("gitGraph\n cherry-pick id: missing")).toThrow(
117
- 'Cherry-pick is not supported in gitGraph diagram at line 2: "cherry-pick id: missing"',
118
- )
119
- })
120
-
121
- test("does not attach else through an unclosed nested sequence block", () => {
122
- expect(() =>
123
- parseMermaidSequenceDiagram(`sequenceDiagram
124
- alt available
125
- loop retry
126
- else fallback`),
127
- ).toThrow('Unexpected "else" without an open "alt" block in sequence diagram at line 4: "else fallback"')
128
- })
129
- })