@zombie-mermaid/mermaid-parser 3.1.0 → 4.0.0

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.
@@ -0,0 +1,136 @@
1
+ import type { Direction, Point } from '@zombie-mermaid/core'
2
+
3
+ // ============================================================================
4
+ // C4 diagram model (C4Context / C4Container / C4Component / C4Dynamic /
5
+ // C4Deployment). Prior art: lukilabs/beautiful-mermaid#34 and #71
6
+ // (kristjanakkermann, devx) — see the changeset for attribution.
7
+ // ============================================================================
8
+
9
+ export type C4Variant =
10
+ 'context' | 'container' | 'component' | 'dynamic' | 'deployment'
11
+
12
+ export type C4ElementKind = 'person' | 'system' | 'container' | 'component'
13
+
14
+ /** Visual variant of an element: plain box, database cylinder, or queue. */
15
+ export type C4ElementShape = 'default' | 'db' | 'queue'
16
+
17
+ export interface C4Element {
18
+ alias: string
19
+ kind: C4ElementKind
20
+ shape: C4ElementShape
21
+ /** `*_Ext` variants: outside the system being described. */
22
+ external: boolean
23
+ label: string
24
+ technology?: string
25
+ description?: string
26
+ }
27
+
28
+ export interface C4Boundary {
29
+ alias: string
30
+ label: string
31
+ /** Boundary type (`Boundary(a, "x", "type")`) or deployment node type. */
32
+ type?: string
33
+ description?: string
34
+ /** Aliases of elements declared directly inside this boundary. */
35
+ elementAliases: string[]
36
+ children: C4Boundary[]
37
+ }
38
+
39
+ /**
40
+ * Layout placement hint carried by `Rel_U`/`Rel_D`/`Rel_L`/`Rel_R` (and their
41
+ * long-form aliases): where `to` should sit relative to `from`. Plain `Rel`,
42
+ * `BiRel`, `RelIndex` and `Rel_Back` carry none.
43
+ */
44
+ export type C4LayoutHint = 'up' | 'down' | 'left' | 'right'
45
+
46
+ export interface C4Relationship {
47
+ from: string
48
+ to: string
49
+ label: string
50
+ technology?: string
51
+ /** `BiRel`: arrowheads at both ends. */
52
+ bidirectional: boolean
53
+ /**
54
+ * `Rel_Back`: the arrowhead points at `from` instead of `to`. `from`/`to`
55
+ * stay as declared, so layout and placement hints still follow them.
56
+ */
57
+ reversed?: boolean
58
+ /** `RelIndex(n, ...)` in C4Dynamic diagrams. */
59
+ index?: string
60
+ /** Placement hint from a directional `Rel_*` macro; see `C4LayoutHint`. */
61
+ layout?: C4LayoutHint
62
+ }
63
+
64
+ export interface C4Diagram {
65
+ variant: C4Variant
66
+ /**
67
+ * Top-level layout direction. Never set by the parser (C4 sources have no
68
+ * direction statement); only `RenderOptions.direction` sets it, via
69
+ * `withDirectionOverride`. Unset lays out top-to-bottom.
70
+ */
71
+ direction?: Direction
72
+ title?: string
73
+ /** Every element in declaration order, wherever it is nested. */
74
+ elements: C4Element[]
75
+ /** Top-level boundaries; elements outside any boundary are not listed. */
76
+ boundaries: C4Boundary[]
77
+ relationships: C4Relationship[]
78
+ }
79
+
80
+ // ----------------------------------------------------------------------------
81
+ // Positioned model (SVG layout output)
82
+ // ----------------------------------------------------------------------------
83
+
84
+ export interface PositionedC4Element extends C4Element {
85
+ x: number
86
+ y: number
87
+ width: number
88
+ height: number
89
+ /** Name wrapped to the box width, one entry per line. */
90
+ nameLines: string[]
91
+ /** Description wrapped to the box width, one entry per line. */
92
+ descriptionLines: string[]
93
+ }
94
+
95
+ export interface PositionedC4Boundary {
96
+ alias: string
97
+ label: string
98
+ type?: string
99
+ description?: string
100
+ x: number
101
+ y: number
102
+ width: number
103
+ height: number
104
+ /** Nesting depth, 0 for a top-level boundary. */
105
+ depth: number
106
+ /** Centre line of the title, below the frame's top edge (Mermaid's layout). */
107
+ labelY?: number
108
+ /** Centre line of the `[type]` text, below the frame's top edge. */
109
+ typeY?: number
110
+ /** Centre line of the description (deployment nodes), below the top edge. */
111
+ descrY?: number
112
+ }
113
+
114
+ export interface PositionedC4Relationship extends C4Relationship {
115
+ /** The start and end of the line (a straight chord when `curve` is unset). */
116
+ points: Point[]
117
+ /** Control point of a quadratic curve from the first to the last point. */
118
+ curve?: Point
119
+ /** Centre of the label block, when the relationship has label text. */
120
+ labelPosition?: Point
121
+ /** Centre x of the `[technology]` line, which Mermaid lays out on its own. */
122
+ technologyX?: number
123
+ }
124
+
125
+ export interface PositionedC4Diagram {
126
+ variant: C4Variant
127
+ title?: string
128
+ width: number
129
+ height: number
130
+ /** Where the title baseline sits (centre x, y), when there is a title. */
131
+ titlePosition?: Point
132
+ elements: PositionedC4Element[]
133
+ /** Outer boundaries first, so inner ones paint on top. */
134
+ boundaries: PositionedC4Boundary[]
135
+ relationships: PositionedC4Relationship[]
136
+ }
@@ -478,19 +478,14 @@ function parseMember(
478
478
  }
479
479
  }
480
480
 
481
- // It's an attribute: [Type] name or name Type
482
- // Common patterns: "String name", "+int age", "name"
483
- const parts = parseGenericTypes(rest).split(/\s+/)
484
- let name: string
485
- let type: string | undefined
486
-
487
- if (parts.length >= 2) {
488
- // "Type name" pattern
489
- type = parts[0]
490
- name = parts.slice(1).join(' ')
491
- } else {
492
- name = parts[0] ?? rest
493
- }
481
+ // It's an attribute. Mermaid renders attribute text verbatim (its
482
+ // ClassMember keeps everything after the visibility marker as one id and
483
+ // only splits methods into name/params/return type), so `String name`,
484
+ // `name Type` and `name: Type` all display as written. Splitting two
485
+ // tokens into Type + name guessed the order and flipped `-data Map` into
486
+ // `- Map: data` (#1265).
487
+ const name = parseGenericTypes(rest)
488
+ const type: string | undefined = undefined
494
489
 
495
490
  const isStatic = name.endsWith('$')
496
491
  const isAbstract = name.endsWith('*')
@@ -110,6 +110,19 @@ export interface PositionedClassDiagram {
110
110
  classes: PositionedClassNode[]
111
111
  relationships: PositionedClassRelationship[]
112
112
  notes: PositionedClassNote[]
113
+ /** Namespace frames, drawn behind their member classes */
114
+ namespaces: PositionedClassNamespace[]
115
+ }
116
+
117
+ /** A `namespace Name { ... }` block's frame, in diagram coordinates */
118
+ export interface PositionedClassNamespace {
119
+ name: string
120
+ /** Ids of the member classes the frame encloses */
121
+ classIds: string[]
122
+ x: number
123
+ y: number
124
+ width: number
125
+ height: number
113
126
  }
114
127
 
115
128
  export interface PositionedClassNote {
package/src/index.ts CHANGED
@@ -28,6 +28,14 @@
28
28
  // creating a cycle — see `packages/core/src/direction.ts`'s header.
29
29
  // ============================================================================
30
30
 
31
+ export * from './architecture/parser.ts'
32
+ export * from './architecture/types.ts'
33
+ export * from './architecture/to-graph.ts'
34
+
35
+ export * from './c4/parser.ts'
36
+ export * from './c4/types.ts'
37
+ export * from './c4/format.ts'
38
+
31
39
  export * from './class/parser.ts'
32
40
  export * from './class/types.ts'
33
41
  export * from './class/format.ts'
@@ -216,6 +216,8 @@ export interface Activation {
216
216
  topY: number
217
217
  bottomY: number
218
218
  width: number
219
+ /** Nesting level on this actor's lifeline: 0 for the outermost bar, 1 for a bar opened while one is already active, and so on */
220
+ depth: number
219
221
  }
220
222
 
221
223
  export interface PositionedBlock {
@@ -4,7 +4,9 @@
4
4
  // Generates monochromatic shades from the theme accent color.
5
5
  // Series 0 = accent (or blue fallback). Series 1+ are darker/lighter
6
6
  // shades of the same hue with subtle hue drift to stay in the same
7
- // color family (like navy ↔ cyan from blue).
7
+ // color family (like navy ↔ cyan from blue). Hue drifts toward navy for
8
+ // darker shades and toward cyan for lighter ones, so neighbouring series
9
+ // do not collapse into two near-identical blues (#1244).
8
10
  //
9
11
  // Used by both the SVG and ASCII renderers.
10
12
  // ============================================================================
@@ -101,7 +103,7 @@ export function isDarkBackground(bgHex: string): boolean {
101
103
  * Get the hex color for a series index.
102
104
  * Index 0 returns the accent color as-is.
103
105
  * Index 1+ alternate between darker and lighter shades of the same hue
104
- * with subtle hue drift (±8-12° per tier) to stay in the same family.
106
+ * with subtle hue drift (-8° per tier for darker, -12° for lighter) to stay in the same family.
105
107
  *
106
108
  * When `bgColor` is provided, shade direction adapts to the background:
107
109
  * - Light bg: odd = darker, even = lighter (default)
@@ -128,8 +130,12 @@ export function getSeriesColor(
128
130
  const dark = safeBg && isDarkBackground(safeBg) ? !oddIndex : oddIndex
129
131
  const l = dark ? Math.max(25, 48 - tier * 13) : Math.min(78, 55 + tier * 11)
130
132
 
131
- // Subtle hue drift: darker shades shift slightly negative, lighter shift positive
132
- const hShift = (dark ? -8 : 12) * tier
133
+ // Subtle hue drift: darker shades shift slightly negative (toward navy),
134
+ // lighter shades shift negative too (toward sky/cyan). The lighter shade
135
+ // used to drift positive (toward indigo), which landed series 2 within a
136
+ // few ΔE of series 0 (#1244); drifting the other way keeps the three first
137
+ // series distinct in hue as well as lightness.
138
+ const hShift = (dark ? -8 : -12) * tier
133
139
  const newH = (((h + hShift) % 360) + 360) % 360
134
140
 
135
141
  return hslToHex(newH, chartS, l)