@diagrammo/dgmo 0.8.19 → 0.8.20

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.
@@ -1,220 +0,0 @@
1
- import type { PaletteColors } from './types';
2
- import { mute, tint, shade, contrastText } from './color-utils';
3
-
4
- // ============================================================
5
- // Mermaid Theme Variable Generator
6
- // ============================================================
7
-
8
- /**
9
- * Generates ~121 Mermaid theme variables from palette tokens.
10
- * Replaces the hardcoded lightThemeVars/darkThemeVars objects.
11
- *
12
- * Dark mode fills use `mute()` to derive desaturated variants
13
- * that are readable with light text.
14
- */
15
- export function buildMermaidThemeVars(
16
- colors: PaletteColors,
17
- isDark: boolean
18
- ): Record<string, string> {
19
- const c = colors.colors;
20
-
21
- // Ordered accent array for pie/cScale/fillType/actor slots
22
- const accentOrder = [
23
- c.blue,
24
- c.red,
25
- c.green,
26
- c.yellow,
27
- c.purple,
28
- c.orange,
29
- c.teal,
30
- c.cyan,
31
- colors.secondary,
32
- ];
33
-
34
- // Dark mode fills use muted variants for readability
35
- const fills = isDark ? accentOrder.map(mute) : accentOrder;
36
-
37
- return {
38
- // ── Backgrounds ──
39
- background: isDark ? colors.overlay : colors.border,
40
- mainBkg: colors.surface,
41
-
42
- // ── Primary/Secondary/Tertiary nodes ──
43
- primaryColor: isDark ? colors.primary : colors.surface,
44
- primaryTextColor: colors.text,
45
- primaryBorderColor: isDark ? colors.secondary : colors.border,
46
- secondaryColor: colors.secondary,
47
- secondaryTextColor: contrastText(colors.secondary, colors.text, colors.bg),
48
- secondaryBorderColor: colors.primary,
49
- tertiaryColor: colors.accent,
50
- tertiaryTextColor: contrastText(colors.accent, colors.text, colors.bg),
51
- tertiaryBorderColor: colors.border,
52
-
53
- // ── Lines & text ──
54
- lineColor: colors.textMuted,
55
- textColor: colors.text,
56
-
57
- // ── Clusters ──
58
- clusterBkg: colors.bg,
59
- clusterBorder: isDark ? colors.border : colors.textMuted,
60
- titleColor: colors.text,
61
-
62
- // ── Labels ──
63
- edgeLabelBackground: 'transparent',
64
-
65
- // ── Notes (sequence diagrams) ──
66
- noteBkgColor: colors.bg,
67
- noteTextColor: colors.text,
68
- noteBorderColor: isDark ? colors.border : colors.textMuted,
69
-
70
- // ── Actors (sequence diagrams) ──
71
- actorBkg: colors.surface,
72
- actorTextColor: colors.text,
73
- actorBorder: isDark ? colors.border : colors.textMuted,
74
- actorLineColor: colors.textMuted,
75
-
76
- // ── Signals (sequence diagrams) ──
77
- signalColor: colors.textMuted,
78
- signalTextColor: colors.text,
79
-
80
- // ── Labels ──
81
- labelColor: colors.text,
82
- labelTextColor: colors.text,
83
- labelBoxBkgColor: colors.surface,
84
- labelBoxBorderColor: isDark ? colors.border : colors.textMuted,
85
-
86
- // ── Loop boxes ──
87
- loopTextColor: colors.text,
88
-
89
- // ── Activation (sequence diagrams) ──
90
- activationBkgColor: isDark ? colors.overlay : colors.border,
91
- activationBorderColor: isDark ? colors.border : colors.textMuted,
92
-
93
- // ── Sequence numbers ──
94
- sequenceNumberColor: isDark ? colors.text : colors.bg,
95
-
96
- // ── State diagrams ──
97
- labelBackgroundColor: colors.surface,
98
-
99
- // ── Pie chart (9 slices) ──
100
- // Dark mode: use muted fills so light pieSectionTextColor stays readable
101
- ...Object.fromEntries(
102
- (isDark ? fills : accentOrder).map((col, i) => [`pie${i + 1}`, col])
103
- ),
104
- pieTitleTextColor: colors.text,
105
- pieSectionTextColor: isDark ? colors.text : colors.bg,
106
- pieLegendTextColor: colors.text,
107
- pieStrokeColor: 'transparent',
108
- pieOuterStrokeWidth: '0px',
109
- pieOuterStrokeColor: 'transparent',
110
-
111
- // ── cScale (9 tiers) — muted in dark mode ──
112
- ...Object.fromEntries(fills.map((f, i) => [`cScale${i}`, f])),
113
- ...Object.fromEntries(
114
- fills.map((_, i) => [
115
- `cScaleLabel${i}`,
116
- isDark ? colors.text : i < 2 || i > 6 ? colors.bg : colors.text,
117
- ])
118
- ),
119
-
120
- // ── fillType (8 slots) ──
121
- ...Object.fromEntries(
122
- [0, 1, 2, 3, 4, 5, 6, 7].map((i) => [
123
- `fillType${i}`,
124
- fills[i % fills.length],
125
- ])
126
- ),
127
-
128
- // ── Journey actors (6 slots) ──
129
- ...Object.fromEntries(
130
- [c.red, c.green, c.yellow, c.purple, c.orange, c.teal].map((color, i) => [
131
- `actor${i}`,
132
- color,
133
- ])
134
- ),
135
-
136
- // ── Flowchart ──
137
- nodeBorder: isDark ? colors.border : colors.textMuted,
138
- nodeTextColor: colors.text,
139
-
140
- // ── Gantt ──
141
- gridColor: isDark ? colors.textMuted : colors.border,
142
- doneTaskBkgColor: c.green,
143
- doneTaskBorderColor: isDark ? colors.border : colors.textMuted,
144
- activeTaskBkgColor: colors.secondary,
145
- activeTaskBorderColor: colors.primary,
146
- critBkgColor: c.orange,
147
- critBorderColor: c.red,
148
- taskBkgColor: colors.surface,
149
- taskBorderColor: isDark ? colors.border : colors.textMuted,
150
- taskTextColor: contrastText(colors.surface, colors.text, colors.bg),
151
- taskTextDarkColor: colors.bg,
152
- taskTextLightColor: colors.text,
153
- taskTextOutsideColor: colors.text,
154
- doneTaskTextColor: contrastText(c.green, colors.text, colors.bg),
155
- activeTaskTextColor: contrastText(colors.secondary, colors.text, colors.bg),
156
- critTaskTextColor: contrastText(c.orange, colors.text, colors.bg),
157
- sectionBkgColor: isDark
158
- ? shade(colors.primary, colors.bg, 0.6)
159
- : tint(colors.primary, 0.6),
160
- altSectionBkgColor: colors.bg,
161
- sectionBkgColor2: isDark
162
- ? shade(colors.primary, colors.bg, 0.6)
163
- : tint(colors.primary, 0.6),
164
- todayLineColor: c.yellow,
165
-
166
- // ── Quadrant ──
167
- quadrant1Fill: isDark
168
- ? shade(c.green, colors.bg, 0.75)
169
- : tint(c.green, 0.75),
170
- quadrant2Fill: isDark ? shade(c.blue, colors.bg, 0.75) : tint(c.blue, 0.75),
171
- quadrant3Fill: isDark ? shade(c.red, colors.bg, 0.75) : tint(c.red, 0.75),
172
- quadrant4Fill: isDark
173
- ? shade(c.yellow, colors.bg, 0.75)
174
- : tint(c.yellow, 0.75),
175
- quadrant1TextFill: colors.text,
176
- quadrant2TextFill: colors.text,
177
- quadrant3TextFill: colors.text,
178
- quadrant4TextFill: colors.text,
179
- quadrantPointFill: isDark ? c.cyan : c.blue,
180
- quadrantPointTextFill: colors.text,
181
- quadrantXAxisTextFill: colors.text,
182
- quadrantYAxisTextFill: colors.text,
183
- quadrantTitleFill: colors.text,
184
- quadrantInternalBorderStrokeFill: colors.border,
185
- quadrantExternalBorderStrokeFill: colors.border,
186
- };
187
- }
188
-
189
- // ============================================================
190
- // Mermaid Theme CSS Generator
191
- // ============================================================
192
-
193
- /**
194
- * Generates custom CSS overrides for Mermaid SVGs.
195
- * Handles git graph label backgrounds and dark-mode text readability.
196
- */
197
- export function buildThemeCSS(palette: PaletteColors, isDark: boolean): string {
198
- const base = `
199
- .branchLabelBkg { fill: transparent !important; stroke: transparent !important; }
200
- .commit-label-bkg { fill: transparent !important; stroke: transparent !important; }
201
- .tag-label-bkg { fill: transparent !important; stroke: transparent !important; }
202
-
203
- /* GitGraph: ensure commit and branch label text matches palette */
204
- .commit-label { fill: ${palette.text} !important; }
205
- .branch-label { fill: ${palette.text} !important; }
206
- .tag-label { fill: ${palette.text} !important; }
207
- `;
208
-
209
- if (!isDark) return base;
210
-
211
- return (
212
- base +
213
- `
214
- /* Flowchart: ensure node and edge label text is readable */
215
- .nodeLabel, .label { color: ${palette.text} !important; fill: ${palette.text} !important; }
216
- .edgeLabel { color: ${palette.text} !important; fill: ${palette.text} !important; }
217
- .edgeLabel .label { color: ${palette.text} !important; fill: ${palette.text} !important; }
218
- `
219
- );
220
- }