@diagrammo/dgmo 0.8.4 → 0.8.6
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/.claude/commands/dgmo.md +300 -0
- package/.cursorrules +20 -2
- package/.github/copilot-instructions.md +20 -2
- package/.windsurfrules +20 -2
- package/AGENTS.md +23 -3
- package/dist/cli.cjs +191 -189
- package/dist/editor.cjs +5 -18
- package/dist/editor.cjs.map +1 -1
- package/dist/editor.js +5 -18
- package/dist/editor.js.map +1 -1
- package/dist/highlight.cjs +543 -0
- package/dist/highlight.cjs.map +1 -0
- package/dist/highlight.d.cts +32 -0
- package/dist/highlight.d.ts +32 -0
- package/dist/highlight.js +513 -0
- package/dist/highlight.js.map +1 -0
- package/dist/index.cjs +3253 -3356
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +77 -56
- package/dist/index.d.ts +77 -56
- package/dist/index.js +3247 -3349
- package/dist/index.js.map +1 -1
- package/docs/ai-integration.md +1 -1
- package/docs/language-reference.md +113 -33
- package/gallery/fixtures/boxes-and-lines.dgmo +64 -0
- package/gallery/fixtures/slope.dgmo +7 -6
- package/package.json +26 -6
- package/src/boxes-and-lines/collapse.ts +78 -0
- package/src/boxes-and-lines/layout.ts +319 -0
- package/src/boxes-and-lines/parser.ts +694 -0
- package/src/boxes-and-lines/renderer.ts +848 -0
- package/src/boxes-and-lines/types.ts +40 -0
- package/src/c4/parser.ts +10 -5
- package/src/c4/renderer.ts +232 -56
- package/src/chart.ts +9 -4
- package/src/cli.ts +49 -6
- package/src/completion.ts +25 -33
- package/src/d3.ts +187 -46
- package/src/dgmo-router.ts +3 -7
- package/src/echarts.ts +38 -2
- package/src/editor/highlight-api.ts +444 -0
- package/src/editor/keywords.ts +6 -19
- package/src/er/parser.ts +10 -4
- package/src/gantt/parser.ts +7 -4
- package/src/gantt/renderer.ts +3 -5
- package/src/index.ts +106 -50
- package/src/infra/parser.ts +7 -5
- package/src/infra/renderer.ts +2 -2
- package/src/kanban/parser.ts +7 -5
- package/src/kanban/renderer.ts +43 -18
- package/src/org/parser.ts +7 -4
- package/src/org/renderer.ts +40 -29
- package/src/sequence/parser.ts +11 -5
- package/src/sequence/renderer.ts +114 -45
- package/src/sitemap/parser.ts +8 -4
- package/src/sitemap/renderer.ts +137 -57
- package/src/utils/legend-svg.ts +44 -20
- package/src/utils/parsing.ts +1 -1
- package/src/utils/tag-groups.ts +21 -1
- package/gallery/fixtures/initiative-status-full.dgmo +0 -46
- package/gallery/fixtures/initiative-status-phases.dgmo +0 -29
- package/gallery/fixtures/initiative-status.dgmo +0 -9
- package/src/initiative-status/collapse.ts +0 -76
- package/src/initiative-status/filter.ts +0 -63
- package/src/initiative-status/layout.ts +0 -650
- package/src/initiative-status/parser.ts +0 -629
- package/src/initiative-status/renderer.ts +0 -1199
- package/src/initiative-status/types.ts +0 -57
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone DGMO syntax highlighter — no CodeMirror dependency.
|
|
3
|
+
*
|
|
4
|
+
* Exports:
|
|
5
|
+
* - `highlightDgmo(source)` → `HighlightToken[]` (consumer-agnostic)
|
|
6
|
+
* - `NORD_ROLE_STYLES` — inline style objects keyed by role (for React/Astro)
|
|
7
|
+
* - `ROLE_TO_ANSI` — ANSI escape codes keyed by role (for CLI)
|
|
8
|
+
*
|
|
9
|
+
* Uses the raw Lezer parser directly — keyword specialization is wired into
|
|
10
|
+
* the grammar, so `parser.parse()` runs it automatically.
|
|
11
|
+
*
|
|
12
|
+
* @module @diagrammo/dgmo/highlight
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { parser } from './dgmo.grammar.js';
|
|
16
|
+
|
|
17
|
+
// ============================================================
|
|
18
|
+
// Types
|
|
19
|
+
// ============================================================
|
|
20
|
+
|
|
21
|
+
export interface HighlightToken {
|
|
22
|
+
text: string;
|
|
23
|
+
role: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ============================================================
|
|
27
|
+
// NODE_TO_ROLE — keep in sync with highlight.ts
|
|
28
|
+
// ============================================================
|
|
29
|
+
|
|
30
|
+
const NODE_TO_ROLE: Record<string, string> = {
|
|
31
|
+
Comment: 'comment',
|
|
32
|
+
ChartType: 'chartType',
|
|
33
|
+
TagKeyword: 'definitionKeyword',
|
|
34
|
+
DirectiveKeyword: 'keyword',
|
|
35
|
+
ControlKeyword: 'controlKeyword',
|
|
36
|
+
ModifierKeyword: 'modifier',
|
|
37
|
+
SyncArrow: 'operator',
|
|
38
|
+
AsyncArrow: 'operator',
|
|
39
|
+
Dash: 'operator',
|
|
40
|
+
Tilde: 'operator',
|
|
41
|
+
Star: 'operator',
|
|
42
|
+
Question: 'operator',
|
|
43
|
+
Duration: 'number',
|
|
44
|
+
DateLiteral: 'number',
|
|
45
|
+
Number: 'number',
|
|
46
|
+
Percentage: 'number',
|
|
47
|
+
SectionMarker: 'heading',
|
|
48
|
+
Url: 'url',
|
|
49
|
+
ColorAnnotation: 'colorAnnotation',
|
|
50
|
+
OpenBracket: 'bracket',
|
|
51
|
+
CloseBracket: 'bracket',
|
|
52
|
+
OpenParen: 'bracket',
|
|
53
|
+
CloseParen: 'bracket',
|
|
54
|
+
OpenAngle: 'bracket',
|
|
55
|
+
CloseAngle: 'bracket',
|
|
56
|
+
Pipe: 'separator',
|
|
57
|
+
Colon: 'separator',
|
|
58
|
+
Plus: 'separator',
|
|
59
|
+
Comma: 'punctuation',
|
|
60
|
+
Punct: 'punctuation',
|
|
61
|
+
Identifier: 'default',
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// ============================================================
|
|
65
|
+
// Entity detection — keep in sync with entity-highlight.ts
|
|
66
|
+
// ============================================================
|
|
67
|
+
|
|
68
|
+
/** Tokens that have grammar-level styling which should be overridden in labels. */
|
|
69
|
+
const OVERRIDE_IN_LABEL = new Set([
|
|
70
|
+
'ChartType',
|
|
71
|
+
'TagKeyword',
|
|
72
|
+
'DirectiveKeyword',
|
|
73
|
+
'ControlKeyword',
|
|
74
|
+
'ModifierKeyword',
|
|
75
|
+
'Number',
|
|
76
|
+
'Percentage',
|
|
77
|
+
'Duration',
|
|
78
|
+
'DateLiteral',
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
/** Lines starting with these are keyword-led — not entity declarations. */
|
|
82
|
+
const KEYWORD_STARTS = new Set([
|
|
83
|
+
'TagKeyword',
|
|
84
|
+
'DirectiveKeyword',
|
|
85
|
+
'ControlKeyword',
|
|
86
|
+
'ModifierKeyword',
|
|
87
|
+
'SectionMarker',
|
|
88
|
+
'Comment',
|
|
89
|
+
'Duration',
|
|
90
|
+
'DateLiteral',
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
// ============================================================
|
|
94
|
+
// Core: highlightDgmo()
|
|
95
|
+
// ============================================================
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Tokenize DGMO source into annotated highlight spans.
|
|
99
|
+
*
|
|
100
|
+
* Guarantees lossless round-trip:
|
|
101
|
+
* `highlightDgmo(src).map(t => t.text).join('') === src`
|
|
102
|
+
*/
|
|
103
|
+
export function highlightDgmo(source: string): HighlightToken[] {
|
|
104
|
+
const tree = parser.parse(source);
|
|
105
|
+
const tokens: HighlightToken[] = [];
|
|
106
|
+
|
|
107
|
+
// Phase 1: Walk tree cursor, collect leaf tokens with gap filling
|
|
108
|
+
let pos = 0;
|
|
109
|
+
const cursor = tree.cursor();
|
|
110
|
+
|
|
111
|
+
// Descend to leaves, process them, then advance via next() or parent+next()
|
|
112
|
+
function descend(): void {
|
|
113
|
+
for (;;) {
|
|
114
|
+
// Try to go deeper
|
|
115
|
+
if (cursor.firstChild()) continue;
|
|
116
|
+
|
|
117
|
+
// At a leaf — emit it
|
|
118
|
+
emitLeaf();
|
|
119
|
+
|
|
120
|
+
// Try to advance to next sibling or ascend
|
|
121
|
+
while (!cursor.nextSibling()) {
|
|
122
|
+
if (!cursor.parent()) return; // back at root — done
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Now at next sibling — loop will try to descend into it
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function emitLeaf(): void {
|
|
130
|
+
const from = cursor.from;
|
|
131
|
+
const to = cursor.to;
|
|
132
|
+
|
|
133
|
+
// Fill gap before this node
|
|
134
|
+
if (from > pos) {
|
|
135
|
+
tokens.push({ text: source.slice(pos, from), role: 'default' });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Emit this leaf node
|
|
139
|
+
if (to > from) {
|
|
140
|
+
const role = NODE_TO_ROLE[cursor.name] ?? 'default';
|
|
141
|
+
tokens.push({ text: source.slice(from, to), role });
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
pos = to;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
descend();
|
|
148
|
+
|
|
149
|
+
// Fill trailing gap
|
|
150
|
+
if (pos < source.length) {
|
|
151
|
+
tokens.push({ text: source.slice(pos, source.length), role: 'default' });
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Phase 2: Post-process — entity detection (label override only)
|
|
155
|
+
applyLabelOverrides(tokens);
|
|
156
|
+
|
|
157
|
+
// Phase 3: Post-process — note content detection
|
|
158
|
+
applyNoteContent(tokens);
|
|
159
|
+
|
|
160
|
+
return tokens;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// ============================================================
|
|
164
|
+
// Post-processing: label overrides
|
|
165
|
+
// ============================================================
|
|
166
|
+
|
|
167
|
+
interface LineTokenRef {
|
|
168
|
+
/** Index into the flat token array. */
|
|
169
|
+
idx: number;
|
|
170
|
+
/** Grammar node name (looked up from role + NODE_TO_ROLE reverse). */
|
|
171
|
+
nodeName: string;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Override keyword/number tokens in message-label positions to `default` role.
|
|
176
|
+
*
|
|
177
|
+
* A "label" is the span between the first Dash/Tilde and the last arrow on a
|
|
178
|
+
* content line. Tokens in OVERRIDE_IN_LABEL within that zone get their role
|
|
179
|
+
* set to `default` so they render as plain text.
|
|
180
|
+
*
|
|
181
|
+
* Also handles ChartType tokens on non-first content lines — they become
|
|
182
|
+
* `default` in labels.
|
|
183
|
+
*/
|
|
184
|
+
function applyLabelOverrides(tokens: HighlightToken[]): void {
|
|
185
|
+
// Build reverse map: role → possible node names (for override detection)
|
|
186
|
+
const ROLE_TO_NODES: Record<string, string[]> = {};
|
|
187
|
+
for (const [node, role] of Object.entries(NODE_TO_ROLE)) {
|
|
188
|
+
(ROLE_TO_NODES[role] ??= []).push(node);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Split tokens into lines
|
|
192
|
+
const lines: LineTokenRef[][] = [[]];
|
|
193
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
194
|
+
const t = tokens[i];
|
|
195
|
+
// If the token contains newlines, it belongs to the current line
|
|
196
|
+
// but signals the start of a new line after it
|
|
197
|
+
const currentLine = lines[lines.length - 1];
|
|
198
|
+
const role = t.role;
|
|
199
|
+
|
|
200
|
+
// Determine which node name this token likely had
|
|
201
|
+
let nodeName = '';
|
|
202
|
+
for (const [node, r] of Object.entries(NODE_TO_ROLE)) {
|
|
203
|
+
if (r === role) {
|
|
204
|
+
nodeName = node;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// For roles mapping to multiple nodes, refine
|
|
209
|
+
if (role === 'operator') {
|
|
210
|
+
const text = t.text;
|
|
211
|
+
if (text === '->' || text.endsWith('->')) nodeName = 'SyncArrow';
|
|
212
|
+
else if (text === '~>' || text.endsWith('~>')) nodeName = 'AsyncArrow';
|
|
213
|
+
else if (text === '-') nodeName = 'Dash';
|
|
214
|
+
else if (text === '~') nodeName = 'Tilde';
|
|
215
|
+
else if (text === '*') nodeName = 'Star';
|
|
216
|
+
else if (text === '?') nodeName = 'Question';
|
|
217
|
+
} else if (role === 'number') {
|
|
218
|
+
const text = t.text;
|
|
219
|
+
if (/^\d+[smhd]$/i.test(text)) nodeName = 'Duration';
|
|
220
|
+
else if (/^\d{4}-\d{2}-\d{2}/.test(text)) nodeName = 'DateLiteral';
|
|
221
|
+
else if (text.endsWith('%')) nodeName = 'Percentage';
|
|
222
|
+
else nodeName = 'Number';
|
|
223
|
+
} else if (role === 'bracket') {
|
|
224
|
+
const text = t.text;
|
|
225
|
+
if (text === '[') nodeName = 'OpenBracket';
|
|
226
|
+
else if (text === ']') nodeName = 'CloseBracket';
|
|
227
|
+
else if (text === '(') nodeName = 'OpenParen';
|
|
228
|
+
else if (text === ')') nodeName = 'CloseParen';
|
|
229
|
+
else if (text === '<') nodeName = 'OpenAngle';
|
|
230
|
+
else if (text === '>') nodeName = 'CloseAngle';
|
|
231
|
+
} else if (role === 'separator') {
|
|
232
|
+
if (t.text === '|') nodeName = 'Pipe';
|
|
233
|
+
else if (t.text === ':') nodeName = 'Colon';
|
|
234
|
+
else if (t.text === '+') nodeName = 'Plus';
|
|
235
|
+
} else if (role === 'punctuation') {
|
|
236
|
+
if (t.text === ',') nodeName = 'Comma';
|
|
237
|
+
else nodeName = 'Punct';
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
currentLine.push({ idx: i, nodeName });
|
|
241
|
+
|
|
242
|
+
// Check if token text ends with newline — start a new line
|
|
243
|
+
if (t.text.includes('\n')) {
|
|
244
|
+
lines.push([]);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Track first content line (for ChartType handling)
|
|
249
|
+
let seenFirstContent = false;
|
|
250
|
+
|
|
251
|
+
for (const line of lines) {
|
|
252
|
+
// Skip empty lines and whitespace-only
|
|
253
|
+
const nonWs = line.filter((ref) => tokens[ref.idx].text.trim().length > 0);
|
|
254
|
+
if (nonWs.length === 0) continue;
|
|
255
|
+
|
|
256
|
+
const firstTok = nonWs[0];
|
|
257
|
+
|
|
258
|
+
// Skip keyword-led lines
|
|
259
|
+
if (KEYWORD_STARTS.has(firstTok.nodeName)) continue;
|
|
260
|
+
|
|
261
|
+
// First-line chart type — skip
|
|
262
|
+
if (firstTok.nodeName === 'ChartType' && !seenFirstContent) {
|
|
263
|
+
seenFirstContent = true;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
seenFirstContent = true;
|
|
267
|
+
|
|
268
|
+
// Find structural boundaries within this line
|
|
269
|
+
let firstDashTildeIdx = -1;
|
|
270
|
+
let lastArrowIdx = -1;
|
|
271
|
+
|
|
272
|
+
for (let li = 0; li < nonWs.length; li++) {
|
|
273
|
+
const ref = nonWs[li];
|
|
274
|
+
if (
|
|
275
|
+
(ref.nodeName === 'Dash' || ref.nodeName === 'Tilde') &&
|
|
276
|
+
firstDashTildeIdx < 0
|
|
277
|
+
) {
|
|
278
|
+
firstDashTildeIdx = li;
|
|
279
|
+
}
|
|
280
|
+
if (ref.nodeName === 'SyncArrow' || ref.nodeName === 'AsyncArrow') {
|
|
281
|
+
lastArrowIdx = li;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const hasArrow = firstDashTildeIdx >= 0 && lastArrowIdx > firstDashTildeIdx;
|
|
286
|
+
|
|
287
|
+
if (!hasArrow) continue;
|
|
288
|
+
|
|
289
|
+
// Override tokens in label zone (between first dash/tilde and last arrow)
|
|
290
|
+
for (let li = firstDashTildeIdx + 1; li < lastArrowIdx; li++) {
|
|
291
|
+
const ref = nonWs[li];
|
|
292
|
+
if (OVERRIDE_IN_LABEL.has(ref.nodeName)) {
|
|
293
|
+
tokens[ref.idx].role = 'default';
|
|
294
|
+
}
|
|
295
|
+
// ChartType in label also overridden
|
|
296
|
+
if (ref.nodeName === 'ChartType') {
|
|
297
|
+
tokens[ref.idx].role = 'default';
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// ============================================================
|
|
304
|
+
// Post-processing: note content detection
|
|
305
|
+
// ============================================================
|
|
306
|
+
|
|
307
|
+
const NOTE_HEAD_RE = /^note(\s|$)/i;
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Detect `note` keyword lines and mark indented followers as `noteContent`.
|
|
311
|
+
*/
|
|
312
|
+
function applyNoteContent(tokens: HighlightToken[]): void {
|
|
313
|
+
// Reconstruct lines from token text
|
|
314
|
+
const fullText = tokens.map((t) => t.text).join('');
|
|
315
|
+
const lines = fullText.split('\n');
|
|
316
|
+
|
|
317
|
+
let inNote = false;
|
|
318
|
+
let noteIndent = 0;
|
|
319
|
+
let charOffset = 0;
|
|
320
|
+
|
|
321
|
+
for (const lineText of lines) {
|
|
322
|
+
const lineStart = charOffset;
|
|
323
|
+
const lineEnd = charOffset + lineText.length;
|
|
324
|
+
const trimmed = lineText.trimStart();
|
|
325
|
+
const indent = lineText.length - trimmed.length;
|
|
326
|
+
|
|
327
|
+
if (NOTE_HEAD_RE.test(trimmed)) {
|
|
328
|
+
inNote = true;
|
|
329
|
+
noteIndent = indent;
|
|
330
|
+
} else if (inNote) {
|
|
331
|
+
if (trimmed.length === 0) {
|
|
332
|
+
// Blank line — stays in note block
|
|
333
|
+
} else if (indent > noteIndent) {
|
|
334
|
+
// Mark all tokens within this line range as noteContent
|
|
335
|
+
markTokensInRange(tokens, lineStart, lineEnd, 'noteContent');
|
|
336
|
+
} else {
|
|
337
|
+
inNote = false;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
charOffset = lineEnd + 1; // +1 for the \n
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Set the role of all tokens overlapping [from, to) to the given role.
|
|
347
|
+
*/
|
|
348
|
+
function markTokensInRange(
|
|
349
|
+
tokens: HighlightToken[],
|
|
350
|
+
from: number,
|
|
351
|
+
to: number,
|
|
352
|
+
role: string
|
|
353
|
+
): void {
|
|
354
|
+
let pos = 0;
|
|
355
|
+
for (const token of tokens) {
|
|
356
|
+
const tokenEnd = pos + token.text.length;
|
|
357
|
+
// Token overlaps range and is not just whitespace
|
|
358
|
+
if (tokenEnd > from && pos < to && token.text.trim().length > 0) {
|
|
359
|
+
token.role = role;
|
|
360
|
+
}
|
|
361
|
+
pos = tokenEnd;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// ============================================================
|
|
366
|
+
// NORD_ROLE_STYLES — hardcoded Nord dark palette for static contexts
|
|
367
|
+
// ============================================================
|
|
368
|
+
|
|
369
|
+
export const NORD_ROLE_STYLES: Record<string, Record<string, string>> = {
|
|
370
|
+
keyword: { color: '#81A1C1', fontWeight: 'bold' }, // nord9
|
|
371
|
+
controlKeyword: { color: '#B48EAD', fontWeight: 'bold' }, // nord15
|
|
372
|
+
definitionKeyword: { color: '#5E81AC', fontWeight: 'bold' }, // nord10
|
|
373
|
+
modifier: { color: '#B48EAD' }, // nord15
|
|
374
|
+
chartType: { color: '#D08770', fontWeight: 'bold' }, // nord12
|
|
375
|
+
operator: { color: '#BF616A', fontWeight: 'bold' }, // nord11
|
|
376
|
+
number: { color: '#B48EAD' }, // nord15
|
|
377
|
+
comment: { color: '#616E88', fontStyle: 'italic' },
|
|
378
|
+
heading: { color: '#D08770', fontWeight: 'bold' }, // nord12
|
|
379
|
+
bracket: { color: '#5E81AC' }, // nord10
|
|
380
|
+
separator: { color: '#88C0D0' }, // nord8
|
|
381
|
+
url: { color: '#88C0D0', textDecoration: 'underline' }, // nord8
|
|
382
|
+
colorAnnotation: { color: '#D08770', fontStyle: 'italic' }, // nord12
|
|
383
|
+
punctuation: { color: '#616E88' },
|
|
384
|
+
noteContent: { color: '#616E88', fontStyle: 'italic' },
|
|
385
|
+
default: {},
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
// ============================================================
|
|
389
|
+
// ROLE_TO_ANSI — ANSI escape codes for CLI output
|
|
390
|
+
// ============================================================
|
|
391
|
+
|
|
392
|
+
export const ROLE_TO_ANSI: Record<string, string> = {
|
|
393
|
+
comment: '\x1b[3;90m', // italic dim
|
|
394
|
+
keyword: '\x1b[1;34m', // bold blue
|
|
395
|
+
controlKeyword: '\x1b[1;35m', // bold magenta
|
|
396
|
+
definitionKeyword: '\x1b[1;34m', // bold blue
|
|
397
|
+
modifier: '\x1b[35m', // magenta
|
|
398
|
+
chartType: '\x1b[1;33m', // bold yellow
|
|
399
|
+
operator: '\x1b[1;31m', // bold red
|
|
400
|
+
number: '\x1b[35m', // magenta
|
|
401
|
+
heading: '\x1b[1;33m', // bold yellow
|
|
402
|
+
bracket: '\x1b[34m', // blue
|
|
403
|
+
separator: '\x1b[36m', // cyan
|
|
404
|
+
url: '\x1b[4;36m', // underline cyan
|
|
405
|
+
colorAnnotation: '\x1b[3;33m', // italic yellow
|
|
406
|
+
punctuation: '\x1b[90m', // dim
|
|
407
|
+
noteContent: '\x1b[3;90m', // italic dim
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
const ANSI_RESET = '\x1b[0m';
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Render highlighted tokens to an ANSI string for terminal display.
|
|
414
|
+
*/
|
|
415
|
+
export function renderAnsi(
|
|
416
|
+
tokens: HighlightToken[],
|
|
417
|
+
useColor: boolean
|
|
418
|
+
): string {
|
|
419
|
+
if (!useColor) {
|
|
420
|
+
return tokens.map((t) => t.text).join('');
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
let out = '';
|
|
424
|
+
let inStyled = false;
|
|
425
|
+
|
|
426
|
+
for (const token of tokens) {
|
|
427
|
+
const ansi = ROLE_TO_ANSI[token.role];
|
|
428
|
+
if (ansi) {
|
|
429
|
+
if (inStyled) out += ANSI_RESET;
|
|
430
|
+
out += ansi + token.text;
|
|
431
|
+
inStyled = true;
|
|
432
|
+
} else {
|
|
433
|
+
if (inStyled) {
|
|
434
|
+
out += ANSI_RESET;
|
|
435
|
+
inStyled = false;
|
|
436
|
+
}
|
|
437
|
+
out += token.text;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// Final reset to prevent terminal style leakage
|
|
442
|
+
out += ANSI_RESET;
|
|
443
|
+
return out;
|
|
444
|
+
}
|
package/src/editor/keywords.ts
CHANGED
|
@@ -8,11 +8,11 @@ export const CHART_TYPES = new Set([
|
|
|
8
8
|
'org',
|
|
9
9
|
'kanban',
|
|
10
10
|
'c4',
|
|
11
|
-
'initiative-status',
|
|
12
11
|
'state',
|
|
13
12
|
'sitemap',
|
|
14
13
|
'infra',
|
|
15
14
|
'gantt',
|
|
15
|
+
'boxes-and-lines',
|
|
16
16
|
// Data chart types
|
|
17
17
|
'bar',
|
|
18
18
|
'line',
|
|
@@ -86,6 +86,8 @@ export const DIRECTIVE_KEYWORDS = new Set([
|
|
|
86
86
|
'import',
|
|
87
87
|
'active-tag',
|
|
88
88
|
'hide',
|
|
89
|
+
'mode',
|
|
90
|
+
'direction',
|
|
89
91
|
// ER
|
|
90
92
|
'notation',
|
|
91
93
|
// Class
|
|
@@ -134,6 +136,8 @@ export const DIRECTIVE_KEYWORDS = new Set([
|
|
|
134
136
|
'no-label-name',
|
|
135
137
|
'no-label-value',
|
|
136
138
|
'no-label-percent',
|
|
139
|
+
// Slope
|
|
140
|
+
'period',
|
|
137
141
|
// Quadrant
|
|
138
142
|
'x-axis',
|
|
139
143
|
'y-axis',
|
|
@@ -144,8 +148,6 @@ export const DIRECTIVE_KEYWORDS = new Set([
|
|
|
144
148
|
// Layout
|
|
145
149
|
'direction-tb',
|
|
146
150
|
'direction-lr',
|
|
147
|
-
// Initiative-status
|
|
148
|
-
'contains',
|
|
149
151
|
// Data chart metadata
|
|
150
152
|
'title',
|
|
151
153
|
'series',
|
|
@@ -170,7 +172,7 @@ export const CONTROL_KEYWORDS = new Set([
|
|
|
170
172
|
'note',
|
|
171
173
|
]);
|
|
172
174
|
|
|
173
|
-
/** Status keywords —
|
|
175
|
+
/** Status keywords — kanban. */
|
|
174
176
|
export const STATUS_KEYWORDS = new Set([
|
|
175
177
|
'na',
|
|
176
178
|
'todo',
|
|
@@ -188,21 +190,6 @@ export const MODIFIER_KEYWORDS = new Set([
|
|
|
188
190
|
'aka',
|
|
189
191
|
'position',
|
|
190
192
|
'default',
|
|
191
|
-
// Sequence participant types
|
|
192
|
-
'actor',
|
|
193
|
-
'service',
|
|
194
|
-
'database',
|
|
195
|
-
'queue',
|
|
196
|
-
'cache',
|
|
197
|
-
'gateway',
|
|
198
|
-
'external',
|
|
199
|
-
'networking',
|
|
200
|
-
'frontend',
|
|
201
|
-
// C4 element types
|
|
202
|
-
'system',
|
|
203
|
-
'person',
|
|
204
|
-
'container',
|
|
205
|
-
'component',
|
|
206
193
|
// ER column modifiers
|
|
207
194
|
'pk',
|
|
208
195
|
'fk',
|
package/src/er/parser.ts
CHANGED
|
@@ -8,7 +8,11 @@ import {
|
|
|
8
8
|
parseFirstLine,
|
|
9
9
|
OPTION_NOCOLON_RE,
|
|
10
10
|
} from '../utils/parsing';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
matchTagBlockHeading,
|
|
13
|
+
validateTagValues,
|
|
14
|
+
stripDefaultModifier,
|
|
15
|
+
} from '../utils/tag-groups';
|
|
12
16
|
import type { TagGroup } from '../utils/tag-groups';
|
|
13
17
|
import type {
|
|
14
18
|
ParsedERDiagram,
|
|
@@ -273,7 +277,8 @@ export function parseERDiagram(
|
|
|
273
277
|
|
|
274
278
|
// Tag group entries (indented under tag heading)
|
|
275
279
|
if (currentTagGroup && !contentStarted && indent > 0) {
|
|
276
|
-
const {
|
|
280
|
+
const { text: cleanEntry, isDefault } = stripDefaultModifier(trimmed);
|
|
281
|
+
const { label, color } = extractColor(cleanEntry, palette);
|
|
277
282
|
if (!color) {
|
|
278
283
|
result.diagnostics.push(
|
|
279
284
|
makeDgmoError(
|
|
@@ -284,8 +289,9 @@ export function parseERDiagram(
|
|
|
284
289
|
);
|
|
285
290
|
continue;
|
|
286
291
|
}
|
|
287
|
-
|
|
288
|
-
|
|
292
|
+
if (isDefault) {
|
|
293
|
+
currentTagGroup.defaultValue = label;
|
|
294
|
+
} else if (currentTagGroup.entries.length === 0) {
|
|
289
295
|
currentTagGroup.defaultValue = label;
|
|
290
296
|
}
|
|
291
297
|
currentTagGroup.entries.push({ value: label, color, lineNumber });
|
package/src/gantt/parser.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { makeDgmoError, formatDgmoError } from '../diagnostics';
|
|
6
6
|
import type { DgmoError } from '../diagnostics';
|
|
7
7
|
import type { TagGroup } from '../utils/tag-groups';
|
|
8
|
-
import { matchTagBlockHeading } from '../utils/tag-groups';
|
|
8
|
+
import { matchTagBlockHeading, stripDefaultModifier } from '../utils/tag-groups';
|
|
9
9
|
import {
|
|
10
10
|
measureIndent,
|
|
11
11
|
extractColor,
|
|
@@ -357,9 +357,10 @@ export function parseGantt(
|
|
|
357
357
|
// fall through to process this line normally
|
|
358
358
|
} else {
|
|
359
359
|
// Parse tag entry: `Value(color)` or `Value`
|
|
360
|
-
// First entry is the default
|
|
360
|
+
// First entry is the default unless another is marked `default`
|
|
361
361
|
if (COMMENT_RE.test(line)) continue;
|
|
362
|
-
const
|
|
362
|
+
const { text: cleanEntry, isDefault } = stripDefaultModifier(line);
|
|
363
|
+
const extracted = extractColor(cleanEntry, palette);
|
|
363
364
|
const color =
|
|
364
365
|
extracted.color ||
|
|
365
366
|
seriesColors[currentTagGroup.entries.length % seriesColors.length] ||
|
|
@@ -370,7 +371,9 @@ export function parseGantt(
|
|
|
370
371
|
color,
|
|
371
372
|
lineNumber,
|
|
372
373
|
});
|
|
373
|
-
if (
|
|
374
|
+
if (isDefault) {
|
|
375
|
+
currentTagGroup.defaultValue = extracted.label;
|
|
376
|
+
} else if (isFirstEntry) {
|
|
374
377
|
currentTagGroup.defaultValue = extracted.label;
|
|
375
378
|
}
|
|
376
379
|
continue;
|
package/src/gantt/renderer.ts
CHANGED
|
@@ -298,7 +298,7 @@ export function renderGantt(
|
|
|
298
298
|
.append('g')
|
|
299
299
|
.attr('transform', `translate(${leftMargin}, ${marginTop})`);
|
|
300
300
|
|
|
301
|
-
// ── Title (y=30, consistent with timeline
|
|
301
|
+
// ── Title (y=30, consistent with timeline) ──
|
|
302
302
|
|
|
303
303
|
if (title) {
|
|
304
304
|
svg
|
|
@@ -1952,9 +1952,7 @@ function renderTagLegend(
|
|
|
1952
1952
|
measureLegendText(group.name, LEGEND_PILL_FONT_SIZE) +
|
|
1953
1953
|
LEGEND_PILL_PAD +
|
|
1954
1954
|
iconReserve;
|
|
1955
|
-
const pillH =
|
|
1956
|
-
? LEGEND_HEIGHT - LEGEND_CAPSULE_PAD * 2
|
|
1957
|
-
: LEGEND_HEIGHT;
|
|
1955
|
+
const pillH = LEGEND_HEIGHT - LEGEND_CAPSULE_PAD * 2;
|
|
1958
1956
|
const groupW = groupWidths[i];
|
|
1959
1957
|
|
|
1960
1958
|
const gEl = legendRow
|
|
@@ -1979,7 +1977,7 @@ function renderTagLegend(
|
|
|
1979
1977
|
}
|
|
1980
1978
|
|
|
1981
1979
|
const pillXOff = isActive ? LEGEND_CAPSULE_PAD : 0;
|
|
1982
|
-
const pillYOff =
|
|
1980
|
+
const pillYOff = LEGEND_CAPSULE_PAD;
|
|
1983
1981
|
|
|
1984
1982
|
// Pill background
|
|
1985
1983
|
gEl
|