@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.
- package/package.json +2 -2
- package/script/layout-audit.ts +98 -98
- package/src/core/canvas.ts +228 -228
- package/src/core/color/style.ts +56 -56
- package/src/core/drawing.ts +301 -301
- package/src/core/geometry.ts +347 -347
- package/src/core/mermaid.ts +38 -38
- package/src/core/render-grid.ts +51 -51
- package/src/core/spatial.ts +243 -243
- package/src/core/text-lines.ts +32 -32
- package/src/core/text.ts +44 -44
- package/src/detect.ts +17 -17
- package/src/diagnostics.ts +16 -16
- package/src/flowchart/drawing.ts +340 -340
- package/src/flowchart/labels.ts +144 -144
- package/src/flowchart/layout.ts +1427 -1427
- package/src/flowchart/options.ts +12 -12
- package/src/flowchart/parser.ts +467 -467
- package/src/flowchart/render.ts +10 -10
- package/src/flowchart/routing.ts +1542 -1542
- package/src/flowchart/style.ts +79 -79
- package/src/flowchart/types.ts +65 -65
- package/src/gantt/diagram.ts +8 -8
- package/src/gantt/drawing.ts +191 -191
- package/src/gantt/parser.ts +161 -161
- package/src/gantt/render-grid.ts +17 -17
- package/src/gantt/style.ts +36 -36
- package/src/gantt/types.ts +44 -44
- package/src/gitgraph/diagram.ts +8 -8
- package/src/gitgraph/drawing.ts +234 -234
- package/src/gitgraph/parser.ts +219 -219
- package/src/gitgraph/render-grid.ts +17 -17
- package/src/gitgraph/style.ts +37 -37
- package/src/gitgraph/types.ts +36 -36
- package/src/markdown.ts +336 -336
- package/src/palette.ts +75 -75
- package/src/plugin.ts +15 -15
- package/src/sequence/diagram.ts +8 -8
- package/src/sequence/drawing.ts +287 -287
- package/src/sequence/options.ts +8 -8
- package/src/sequence/parser.ts +282 -282
- package/src/sequence/placement.ts +684 -684
- package/src/sequence/render-grid.ts +22 -22
- package/src/sequence/style.ts +81 -81
- package/src/sequence/types.ts +74 -74
- package/src/state/diagram.ts +8 -8
- package/src/state/drawing.ts +360 -360
- package/src/state/endpoint.ts +15 -15
- package/src/state/layout.ts +1134 -1134
- package/src/state/note.ts +59 -59
- package/src/state/options.ts +11 -11
- package/src/state/parser.ts +224 -224
- package/src/state/render-grid.ts +22 -22
- package/src/state/routing.ts +1522 -1522
- package/src/state/search.ts +103 -103
- package/src/state/style.ts +52 -52
- package/src/state/types.ts +63 -63
- package/src/state/visible-model.ts +77 -77
- package/src/test/diagram.ts +32 -32
- package/src/test/layout-audit/fixtures.ts +538 -538
- package/src/test/layout-audit/harness.ts +522 -522
- package/src/timeline/diagram.ts +8 -8
- package/src/timeline/drawing.ts +109 -109
- package/src/timeline/parser.ts +119 -119
- package/src/timeline/render-grid.ts +17 -17
- package/src/timeline/style.ts +36 -36
- package/src/timeline/types.ts +31 -31
- package/tsconfig.json +10 -10
- package/src/core/canvas.test.ts +0 -203
- package/src/core/color/style.test.ts +0 -24
- package/src/core/drawing.test.ts +0 -116
- package/src/core/geometry.test.ts +0 -112
- package/src/core/spatial.test.ts +0 -87
- package/src/core/text.test.ts +0 -33
- package/src/flowchart/flowchart.test.ts +0 -2800
- package/src/flowchart/labels.test.ts +0 -127
- package/src/flowchart/routing.test.ts +0 -368
- package/src/gantt/diagram.test.ts +0 -124
- package/src/gitgraph/diagram.test.ts +0 -183
- package/src/layout-audit.test.ts +0 -92
- package/src/palette.test.ts +0 -103
- package/src/sequence/diagram.test.ts +0 -757
- package/src/sequence/placement.test.ts +0 -219
- package/src/state/diagram.test.ts +0 -1386
- package/src/state/layout.test.ts +0 -314
- package/src/state/routing.test.ts +0 -693
- package/src/state/style.test.ts +0 -113
- package/src/state/visible-model.test.ts +0 -84
- package/src/test/diagnostics.test.ts +0 -129
- package/src/test/markdown.test.ts +0 -474
- package/src/timeline/diagram.test.ts +0 -188
package/src/gantt/parser.ts
CHANGED
|
@@ -1,161 +1,161 @@
|
|
|
1
|
-
import { firstMeaningfulMermaidLine, meaningfulNumberedMermaidLines, stripMermaidQuotes } from "../core/mermaid.js"
|
|
2
|
-
import { MermaidSyntaxError } from "../diagnostics.js"
|
|
3
|
-
import type { GanttDiagram, GanttEntry, GanttSection, GanttTask, GanttTaskState } from "./types.js"
|
|
4
|
-
|
|
5
|
-
const HEADER_RE = /^gantt$/i
|
|
6
|
-
const DIRECTIVE_RE = /^(title|dateFormat|axisFormat|tickInterval|excludes|todayMarker)\s+(.+)$/i
|
|
7
|
-
const SECTION_RE = /^section(?:\s+(.+))?$/i
|
|
8
|
-
const ACCESSIBILITY_RE = /^acc(?:Title|Descr)(?::|\s|$)/i
|
|
9
|
-
const TASK_STATES = new Set(["active", "done", "crit", "milestone", "vert"])
|
|
10
|
-
|
|
11
|
-
export function isMermaidGanttDiagram(content: string): boolean {
|
|
12
|
-
return HEADER_RE.test(firstMeaningfulMermaidLine(content) ?? "")
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function parseMermaidGanttDiagram(content: string): GanttDiagram {
|
|
16
|
-
const tasks: GanttTask[] = []
|
|
17
|
-
const entries: GanttEntry[] = []
|
|
18
|
-
const tasksById = new Map<string, GanttTask>()
|
|
19
|
-
let title: string | undefined
|
|
20
|
-
let dateFormat = "YYYY-MM-DD"
|
|
21
|
-
let axisFormat = "%Y-%m-%d"
|
|
22
|
-
let section: GanttSection | undefined
|
|
23
|
-
let headerSeen = false
|
|
24
|
-
let inAccessibilityDescription = false
|
|
25
|
-
|
|
26
|
-
for (const source of meaningfulNumberedMermaidLines(content)) {
|
|
27
|
-
const line = stripComment(source.text)
|
|
28
|
-
if (inAccessibilityDescription) {
|
|
29
|
-
if (line === "}") inAccessibilityDescription = false
|
|
30
|
-
continue
|
|
31
|
-
}
|
|
32
|
-
if (/^accDescr\s*\{$/i.test(line)) {
|
|
33
|
-
inAccessibilityDescription = true
|
|
34
|
-
continue
|
|
35
|
-
}
|
|
36
|
-
if (ACCESSIBILITY_RE.test(line)) continue
|
|
37
|
-
if (!line) continue
|
|
38
|
-
if (HEADER_RE.test(line)) {
|
|
39
|
-
if (headerSeen) throw syntaxError(source.lineNumber, line, "Gantt header can only appear once")
|
|
40
|
-
headerSeen = true
|
|
41
|
-
continue
|
|
42
|
-
}
|
|
43
|
-
if (!headerSeen) throw syntaxError(source.lineNumber, line, "Gantt header is required")
|
|
44
|
-
|
|
45
|
-
const sectionMatch = line.match(SECTION_RE)
|
|
46
|
-
if (sectionMatch) {
|
|
47
|
-
if (!sectionMatch[1]) throw syntaxError(source.lineNumber, line, "Gantt section cannot be empty")
|
|
48
|
-
section = { label: stripMermaidQuotes(sectionMatch[1]) }
|
|
49
|
-
entries.push({ type: "section", section })
|
|
50
|
-
continue
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const directive = line.match(DIRECTIVE_RE)
|
|
54
|
-
if (directive) {
|
|
55
|
-
const name = directive[1]!.toLowerCase()
|
|
56
|
-
const value = directive[2]!.trim()
|
|
57
|
-
if (name === "title") title = stripMermaidQuotes(value)
|
|
58
|
-
if (name === "dateformat") dateFormat = value
|
|
59
|
-
if (name === "axisformat") axisFormat = value
|
|
60
|
-
if (!["title", "dateformat", "axisformat"].includes(name)) {
|
|
61
|
-
throw syntaxError(source.lineNumber, line, `${directive[1]} is not supported`)
|
|
62
|
-
}
|
|
63
|
-
continue
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const separator = line.indexOf(":")
|
|
67
|
-
if (separator < 1) throw syntaxError(source.lineNumber, line)
|
|
68
|
-
const label = stripMermaidQuotes(line.slice(0, separator))
|
|
69
|
-
const fields = line
|
|
70
|
-
.slice(separator + 1)
|
|
71
|
-
.split(",")
|
|
72
|
-
.map((field) => field.trim())
|
|
73
|
-
.filter(Boolean)
|
|
74
|
-
const flags = new Set<string>()
|
|
75
|
-
while (fields[0] && TASK_STATES.has(fields[0].toLowerCase())) flags.add(fields.shift()!.toLowerCase())
|
|
76
|
-
if (fields.length < 2 || fields.length > 3) {
|
|
77
|
-
throw syntaxError(source.lineNumber, line, "Gantt tasks require a start and end or duration")
|
|
78
|
-
}
|
|
79
|
-
const id = fields.length === 3 ? fields.shift() : undefined
|
|
80
|
-
if (id && tasksById.has(id)) throw syntaxError(source.lineNumber, line, `Duplicate task id "${id}"`)
|
|
81
|
-
const start = parseStart(fields[0]!, dateFormat, tasksById, source.lineNumber, line)
|
|
82
|
-
const end = parseEnd(fields[1]!, start, dateFormat, source.lineNumber, line)
|
|
83
|
-
if (end < start) throw syntaxError(source.lineNumber, line, "Gantt task cannot end before it starts")
|
|
84
|
-
const task: GanttTask = {
|
|
85
|
-
label,
|
|
86
|
-
...(id ? { id } : {}),
|
|
87
|
-
...(section ? { section } : {}),
|
|
88
|
-
start,
|
|
89
|
-
end,
|
|
90
|
-
state: taskState(flags),
|
|
91
|
-
}
|
|
92
|
-
tasks.push(task)
|
|
93
|
-
entries.push({ type: "task", task })
|
|
94
|
-
if (id) tasksById.set(id, task)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (!headerSeen) throw new MermaidSyntaxError("gantt", 1, "", "Gantt header is required")
|
|
98
|
-
return { ...(title === undefined ? {} : { title }), dateFormat, axisFormat, tasks, entries }
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function parseStart(
|
|
102
|
-
value: string,
|
|
103
|
-
format: string,
|
|
104
|
-
tasksById: Map<string, GanttTask>,
|
|
105
|
-
lineNumber: number,
|
|
106
|
-
sourceLine: string,
|
|
107
|
-
): number {
|
|
108
|
-
if (!/^after\s+/i.test(value)) return parseDate(value, format, lineNumber, sourceLine)
|
|
109
|
-
const dependencies = value
|
|
110
|
-
.replace(/^after\s+/i, "")
|
|
111
|
-
.trim()
|
|
112
|
-
.split(/\s+/)
|
|
113
|
-
const tasks = dependencies.map((id) => tasksById.get(id))
|
|
114
|
-
const missing = dependencies.find((_, index) => !tasks[index])
|
|
115
|
-
if (missing) throw syntaxError(lineNumber, sourceLine, `Unknown Gantt task id "${missing}"`)
|
|
116
|
-
return Math.max(...tasks.map((task) => task!.end))
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function parseEnd(value: string, start: number, format: string, lineNumber: number, sourceLine: string): number {
|
|
120
|
-
const duration = value.match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h|d|w)$/i)
|
|
121
|
-
if (!duration) return parseDate(value, format, lineNumber, sourceLine)
|
|
122
|
-
const units = { ms: 1, s: 1_000, m: 60_000, h: 3_600_000, d: 86_400_000, w: 604_800_000 }
|
|
123
|
-
return start + Number(duration[1]) * units[duration[2]!.toLowerCase() as keyof typeof units]
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function parseDate(value: string, format: string, lineNumber: number, sourceLine: string): number {
|
|
127
|
-
const numeric = Number(value)
|
|
128
|
-
if (format === "s" && Number.isFinite(numeric)) return numeric * 1_000
|
|
129
|
-
if (format === "X" && Number.isFinite(numeric)) return numeric * 1_000
|
|
130
|
-
if (format === "x" && Number.isFinite(numeric)) return numeric
|
|
131
|
-
|
|
132
|
-
const calendar = value.match(/^(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/)
|
|
133
|
-
if (calendar && ["YYYY-MM-DD", "YYYY-MM-DD HH:mm", "YYYY-MM-DD HH:mm:ss"].includes(format)) {
|
|
134
|
-
return Date.UTC(
|
|
135
|
-
Number(calendar[1]),
|
|
136
|
-
Number(calendar[2]) - 1,
|
|
137
|
-
Number(calendar[3]),
|
|
138
|
-
Number(calendar[4] ?? 0),
|
|
139
|
-
Number(calendar[5] ?? 0),
|
|
140
|
-
Number(calendar[6] ?? 0),
|
|
141
|
-
)
|
|
142
|
-
}
|
|
143
|
-
throw syntaxError(lineNumber, sourceLine, `Unsupported date "${value}" for dateFormat ${format}`)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function taskState(flags: Set<string>): GanttTaskState {
|
|
147
|
-
if (flags.has("milestone")) return "milestone"
|
|
148
|
-
if (flags.has("crit")) return "critical"
|
|
149
|
-
if (flags.has("done")) return "done"
|
|
150
|
-
if (flags.has("active")) return "active"
|
|
151
|
-
return "task"
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function stripComment(value: string): string {
|
|
155
|
-
const comment = value.indexOf("%%")
|
|
156
|
-
return (comment < 0 ? value : value.slice(0, comment)).trim()
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function syntaxError(lineNumber: number, sourceLine: string, reason?: string): MermaidSyntaxError {
|
|
160
|
-
return new MermaidSyntaxError("gantt", lineNumber, sourceLine, reason)
|
|
161
|
-
}
|
|
1
|
+
import { firstMeaningfulMermaidLine, meaningfulNumberedMermaidLines, stripMermaidQuotes } from "../core/mermaid.js"
|
|
2
|
+
import { MermaidSyntaxError } from "../diagnostics.js"
|
|
3
|
+
import type { GanttDiagram, GanttEntry, GanttSection, GanttTask, GanttTaskState } from "./types.js"
|
|
4
|
+
|
|
5
|
+
const HEADER_RE = /^gantt$/i
|
|
6
|
+
const DIRECTIVE_RE = /^(title|dateFormat|axisFormat|tickInterval|excludes|todayMarker)\s+(.+)$/i
|
|
7
|
+
const SECTION_RE = /^section(?:\s+(.+))?$/i
|
|
8
|
+
const ACCESSIBILITY_RE = /^acc(?:Title|Descr)(?::|\s|$)/i
|
|
9
|
+
const TASK_STATES = new Set(["active", "done", "crit", "milestone", "vert"])
|
|
10
|
+
|
|
11
|
+
export function isMermaidGanttDiagram(content: string): boolean {
|
|
12
|
+
return HEADER_RE.test(firstMeaningfulMermaidLine(content) ?? "")
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function parseMermaidGanttDiagram(content: string): GanttDiagram {
|
|
16
|
+
const tasks: GanttTask[] = []
|
|
17
|
+
const entries: GanttEntry[] = []
|
|
18
|
+
const tasksById = new Map<string, GanttTask>()
|
|
19
|
+
let title: string | undefined
|
|
20
|
+
let dateFormat = "YYYY-MM-DD"
|
|
21
|
+
let axisFormat = "%Y-%m-%d"
|
|
22
|
+
let section: GanttSection | undefined
|
|
23
|
+
let headerSeen = false
|
|
24
|
+
let inAccessibilityDescription = false
|
|
25
|
+
|
|
26
|
+
for (const source of meaningfulNumberedMermaidLines(content)) {
|
|
27
|
+
const line = stripComment(source.text)
|
|
28
|
+
if (inAccessibilityDescription) {
|
|
29
|
+
if (line === "}") inAccessibilityDescription = false
|
|
30
|
+
continue
|
|
31
|
+
}
|
|
32
|
+
if (/^accDescr\s*\{$/i.test(line)) {
|
|
33
|
+
inAccessibilityDescription = true
|
|
34
|
+
continue
|
|
35
|
+
}
|
|
36
|
+
if (ACCESSIBILITY_RE.test(line)) continue
|
|
37
|
+
if (!line) continue
|
|
38
|
+
if (HEADER_RE.test(line)) {
|
|
39
|
+
if (headerSeen) throw syntaxError(source.lineNumber, line, "Gantt header can only appear once")
|
|
40
|
+
headerSeen = true
|
|
41
|
+
continue
|
|
42
|
+
}
|
|
43
|
+
if (!headerSeen) throw syntaxError(source.lineNumber, line, "Gantt header is required")
|
|
44
|
+
|
|
45
|
+
const sectionMatch = line.match(SECTION_RE)
|
|
46
|
+
if (sectionMatch) {
|
|
47
|
+
if (!sectionMatch[1]) throw syntaxError(source.lineNumber, line, "Gantt section cannot be empty")
|
|
48
|
+
section = { label: stripMermaidQuotes(sectionMatch[1]) }
|
|
49
|
+
entries.push({ type: "section", section })
|
|
50
|
+
continue
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const directive = line.match(DIRECTIVE_RE)
|
|
54
|
+
if (directive) {
|
|
55
|
+
const name = directive[1]!.toLowerCase()
|
|
56
|
+
const value = directive[2]!.trim()
|
|
57
|
+
if (name === "title") title = stripMermaidQuotes(value)
|
|
58
|
+
if (name === "dateformat") dateFormat = value
|
|
59
|
+
if (name === "axisformat") axisFormat = value
|
|
60
|
+
if (!["title", "dateformat", "axisformat"].includes(name)) {
|
|
61
|
+
throw syntaxError(source.lineNumber, line, `${directive[1]} is not supported`)
|
|
62
|
+
}
|
|
63
|
+
continue
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const separator = line.indexOf(":")
|
|
67
|
+
if (separator < 1) throw syntaxError(source.lineNumber, line)
|
|
68
|
+
const label = stripMermaidQuotes(line.slice(0, separator))
|
|
69
|
+
const fields = line
|
|
70
|
+
.slice(separator + 1)
|
|
71
|
+
.split(",")
|
|
72
|
+
.map((field) => field.trim())
|
|
73
|
+
.filter(Boolean)
|
|
74
|
+
const flags = new Set<string>()
|
|
75
|
+
while (fields[0] && TASK_STATES.has(fields[0].toLowerCase())) flags.add(fields.shift()!.toLowerCase())
|
|
76
|
+
if (fields.length < 2 || fields.length > 3) {
|
|
77
|
+
throw syntaxError(source.lineNumber, line, "Gantt tasks require a start and end or duration")
|
|
78
|
+
}
|
|
79
|
+
const id = fields.length === 3 ? fields.shift() : undefined
|
|
80
|
+
if (id && tasksById.has(id)) throw syntaxError(source.lineNumber, line, `Duplicate task id "${id}"`)
|
|
81
|
+
const start = parseStart(fields[0]!, dateFormat, tasksById, source.lineNumber, line)
|
|
82
|
+
const end = parseEnd(fields[1]!, start, dateFormat, source.lineNumber, line)
|
|
83
|
+
if (end < start) throw syntaxError(source.lineNumber, line, "Gantt task cannot end before it starts")
|
|
84
|
+
const task: GanttTask = {
|
|
85
|
+
label,
|
|
86
|
+
...(id ? { id } : {}),
|
|
87
|
+
...(section ? { section } : {}),
|
|
88
|
+
start,
|
|
89
|
+
end,
|
|
90
|
+
state: taskState(flags),
|
|
91
|
+
}
|
|
92
|
+
tasks.push(task)
|
|
93
|
+
entries.push({ type: "task", task })
|
|
94
|
+
if (id) tasksById.set(id, task)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!headerSeen) throw new MermaidSyntaxError("gantt", 1, "", "Gantt header is required")
|
|
98
|
+
return { ...(title === undefined ? {} : { title }), dateFormat, axisFormat, tasks, entries }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function parseStart(
|
|
102
|
+
value: string,
|
|
103
|
+
format: string,
|
|
104
|
+
tasksById: Map<string, GanttTask>,
|
|
105
|
+
lineNumber: number,
|
|
106
|
+
sourceLine: string,
|
|
107
|
+
): number {
|
|
108
|
+
if (!/^after\s+/i.test(value)) return parseDate(value, format, lineNumber, sourceLine)
|
|
109
|
+
const dependencies = value
|
|
110
|
+
.replace(/^after\s+/i, "")
|
|
111
|
+
.trim()
|
|
112
|
+
.split(/\s+/)
|
|
113
|
+
const tasks = dependencies.map((id) => tasksById.get(id))
|
|
114
|
+
const missing = dependencies.find((_, index) => !tasks[index])
|
|
115
|
+
if (missing) throw syntaxError(lineNumber, sourceLine, `Unknown Gantt task id "${missing}"`)
|
|
116
|
+
return Math.max(...tasks.map((task) => task!.end))
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function parseEnd(value: string, start: number, format: string, lineNumber: number, sourceLine: string): number {
|
|
120
|
+
const duration = value.match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h|d|w)$/i)
|
|
121
|
+
if (!duration) return parseDate(value, format, lineNumber, sourceLine)
|
|
122
|
+
const units = { ms: 1, s: 1_000, m: 60_000, h: 3_600_000, d: 86_400_000, w: 604_800_000 }
|
|
123
|
+
return start + Number(duration[1]) * units[duration[2]!.toLowerCase() as keyof typeof units]
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function parseDate(value: string, format: string, lineNumber: number, sourceLine: string): number {
|
|
127
|
+
const numeric = Number(value)
|
|
128
|
+
if (format === "s" && Number.isFinite(numeric)) return numeric * 1_000
|
|
129
|
+
if (format === "X" && Number.isFinite(numeric)) return numeric * 1_000
|
|
130
|
+
if (format === "x" && Number.isFinite(numeric)) return numeric
|
|
131
|
+
|
|
132
|
+
const calendar = value.match(/^(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/)
|
|
133
|
+
if (calendar && ["YYYY-MM-DD", "YYYY-MM-DD HH:mm", "YYYY-MM-DD HH:mm:ss"].includes(format)) {
|
|
134
|
+
return Date.UTC(
|
|
135
|
+
Number(calendar[1]),
|
|
136
|
+
Number(calendar[2]) - 1,
|
|
137
|
+
Number(calendar[3]),
|
|
138
|
+
Number(calendar[4] ?? 0),
|
|
139
|
+
Number(calendar[5] ?? 0),
|
|
140
|
+
Number(calendar[6] ?? 0),
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
throw syntaxError(lineNumber, sourceLine, `Unsupported date "${value}" for dateFormat ${format}`)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function taskState(flags: Set<string>): GanttTaskState {
|
|
147
|
+
if (flags.has("milestone")) return "milestone"
|
|
148
|
+
if (flags.has("crit")) return "critical"
|
|
149
|
+
if (flags.has("done")) return "done"
|
|
150
|
+
if (flags.has("active")) return "active"
|
|
151
|
+
return "task"
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function stripComment(value: string): string {
|
|
155
|
+
const comment = value.indexOf("%%")
|
|
156
|
+
return (comment < 0 ? value : value.slice(0, comment)).trim()
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function syntaxError(lineNumber: number, sourceLine: string, reason?: string): MermaidSyntaxError {
|
|
160
|
+
return new MermaidSyntaxError("gantt", lineNumber, sourceLine, reason)
|
|
161
|
+
}
|
package/src/gantt/render-grid.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { StyledText } from "@opentui/core"
|
|
2
|
-
import type { DiagramCanvas } from "../core/canvas.js"
|
|
3
|
-
import { renderDiagramGridStyledText } from "../core/render-grid.js"
|
|
4
|
-
import type { GanttStyleColors } from "./style.js"
|
|
5
|
-
import type { GanttCellStyle } from "./types.js"
|
|
6
|
-
|
|
7
|
-
export type GanttGrid = DiagramCanvas<GanttCellStyle>
|
|
8
|
-
|
|
9
|
-
export function renderGanttGridText(grid: GanttGrid): string {
|
|
10
|
-
return grid.toString({ trimBottom: true })
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function renderGanttGridStyledText(grid: GanttGrid, colors: GanttStyleColors): StyledText {
|
|
14
|
-
return renderDiagramGridStyledText(grid, (run) => (run.style ? colors[run.style] : undefined), undefined, {
|
|
15
|
-
trimBottom: true,
|
|
16
|
-
})
|
|
17
|
-
}
|
|
1
|
+
import type { StyledText } from "@opentui/core"
|
|
2
|
+
import type { DiagramCanvas } from "../core/canvas.js"
|
|
3
|
+
import { renderDiagramGridStyledText } from "../core/render-grid.js"
|
|
4
|
+
import type { GanttStyleColors } from "./style.js"
|
|
5
|
+
import type { GanttCellStyle } from "./types.js"
|
|
6
|
+
|
|
7
|
+
export type GanttGrid = DiagramCanvas<GanttCellStyle>
|
|
8
|
+
|
|
9
|
+
export function renderGanttGridText(grid: GanttGrid): string {
|
|
10
|
+
return grid.toString({ trimBottom: true })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function renderGanttGridStyledText(grid: GanttGrid, colors: GanttStyleColors): StyledText {
|
|
14
|
+
return renderDiagramGridStyledText(grid, (run) => (run.style ? colors[run.style] : undefined), undefined, {
|
|
15
|
+
trimBottom: true,
|
|
16
|
+
})
|
|
17
|
+
}
|
package/src/gantt/style.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { RGBA } from "@opentui/core"
|
|
2
|
-
import { blendColor, rgba, type DiagramRgb } from "../core/color/style.js"
|
|
3
|
-
import type { GanttBaseCellStyle, GanttCellStyle } from "./types.js"
|
|
4
|
-
|
|
5
|
-
const DEFAULT_THEME_RGB = {
|
|
6
|
-
title: [228, 239, 232],
|
|
7
|
-
axis: [111, 138, 126],
|
|
8
|
-
section: [154, 184, 169],
|
|
9
|
-
task: [134, 225, 200],
|
|
10
|
-
active: [134, 225, 200],
|
|
11
|
-
critical: [230, 177, 126],
|
|
12
|
-
done: [111, 138, 126],
|
|
13
|
-
milestone: [198, 160, 246],
|
|
14
|
-
} as const satisfies Record<GanttBaseCellStyle, DiagramRgb>
|
|
15
|
-
|
|
16
|
-
export type GanttStyleColors = Required<Record<GanttCellStyle, RGBA>>
|
|
17
|
-
|
|
18
|
-
export function resolveGanttStyleColors(
|
|
19
|
-
colors: Partial<Record<GanttBaseCellStyle | "background", RGBA | undefined>> = {},
|
|
20
|
-
): GanttStyleColors {
|
|
21
|
-
const axis = colors.axis ?? rgba(DEFAULT_THEME_RGB.axis)
|
|
22
|
-
const background = colors.background ?? rgba([13, 17, 23])
|
|
23
|
-
return {
|
|
24
|
-
title: colors.title ?? rgba(DEFAULT_THEME_RGB.title),
|
|
25
|
-
axis,
|
|
26
|
-
section: colors.section ?? rgba(DEFAULT_THEME_RGB.section),
|
|
27
|
-
task: colors.task ?? rgba(DEFAULT_THEME_RGB.task),
|
|
28
|
-
active: colors.active ?? rgba(DEFAULT_THEME_RGB.active),
|
|
29
|
-
critical: colors.critical ?? rgba(DEFAULT_THEME_RGB.critical),
|
|
30
|
-
done: colors.done ?? rgba(DEFAULT_THEME_RGB.done),
|
|
31
|
-
milestone: colors.milestone ?? rgba(DEFAULT_THEME_RGB.milestone),
|
|
32
|
-
trackMedium: blendColor(axis, background, 0.35),
|
|
33
|
-
trackDim: blendColor(axis, background, 0.55),
|
|
34
|
-
trackFaint: blendColor(axis, background, 0.72),
|
|
35
|
-
}
|
|
36
|
-
}
|
|
1
|
+
import { RGBA } from "@opentui/core"
|
|
2
|
+
import { blendColor, rgba, type DiagramRgb } from "../core/color/style.js"
|
|
3
|
+
import type { GanttBaseCellStyle, GanttCellStyle } from "./types.js"
|
|
4
|
+
|
|
5
|
+
const DEFAULT_THEME_RGB = {
|
|
6
|
+
title: [228, 239, 232],
|
|
7
|
+
axis: [111, 138, 126],
|
|
8
|
+
section: [154, 184, 169],
|
|
9
|
+
task: [134, 225, 200],
|
|
10
|
+
active: [134, 225, 200],
|
|
11
|
+
critical: [230, 177, 126],
|
|
12
|
+
done: [111, 138, 126],
|
|
13
|
+
milestone: [198, 160, 246],
|
|
14
|
+
} as const satisfies Record<GanttBaseCellStyle, DiagramRgb>
|
|
15
|
+
|
|
16
|
+
export type GanttStyleColors = Required<Record<GanttCellStyle, RGBA>>
|
|
17
|
+
|
|
18
|
+
export function resolveGanttStyleColors(
|
|
19
|
+
colors: Partial<Record<GanttBaseCellStyle | "background", RGBA | undefined>> = {},
|
|
20
|
+
): GanttStyleColors {
|
|
21
|
+
const axis = colors.axis ?? rgba(DEFAULT_THEME_RGB.axis)
|
|
22
|
+
const background = colors.background ?? rgba([13, 17, 23])
|
|
23
|
+
return {
|
|
24
|
+
title: colors.title ?? rgba(DEFAULT_THEME_RGB.title),
|
|
25
|
+
axis,
|
|
26
|
+
section: colors.section ?? rgba(DEFAULT_THEME_RGB.section),
|
|
27
|
+
task: colors.task ?? rgba(DEFAULT_THEME_RGB.task),
|
|
28
|
+
active: colors.active ?? rgba(DEFAULT_THEME_RGB.active),
|
|
29
|
+
critical: colors.critical ?? rgba(DEFAULT_THEME_RGB.critical),
|
|
30
|
+
done: colors.done ?? rgba(DEFAULT_THEME_RGB.done),
|
|
31
|
+
milestone: colors.milestone ?? rgba(DEFAULT_THEME_RGB.milestone),
|
|
32
|
+
trackMedium: blendColor(axis, background, 0.35),
|
|
33
|
+
trackDim: blendColor(axis, background, 0.55),
|
|
34
|
+
trackFaint: blendColor(axis, background, 0.72),
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/gantt/types.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
export type GanttTaskState = "task" | "active" | "critical" | "done" | "milestone"
|
|
2
|
-
|
|
3
|
-
export interface GanttSection {
|
|
4
|
-
label: string
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface GanttTask {
|
|
8
|
-
label: string
|
|
9
|
-
id?: string
|
|
10
|
-
section?: GanttSection
|
|
11
|
-
start: number
|
|
12
|
-
end: number
|
|
13
|
-
state: GanttTaskState
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type GanttEntry = { type: "section"; section: GanttSection } | { type: "task"; task: GanttTask }
|
|
17
|
-
|
|
18
|
-
export interface GanttDiagram {
|
|
19
|
-
title?: string
|
|
20
|
-
dateFormat: string
|
|
21
|
-
axisFormat: string
|
|
22
|
-
tasks: GanttTask[]
|
|
23
|
-
entries: GanttEntry[]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface GanttDiagramRenderOptions {
|
|
27
|
-
layoutMaxWidth?: number
|
|
28
|
-
style?: GanttRenderStyle
|
|
29
|
-
track?: "dots" | "line"
|
|
30
|
-
endpoints?: "plain" | "points"
|
|
31
|
-
line?: GanttLineStyle
|
|
32
|
-
labels?: GanttLabelLayout
|
|
33
|
-
sections?: "compact" | "spaced"
|
|
34
|
-
trackTone?: GanttTrackTone
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export type GanttRenderStyle = "rail" | "block" | "capsule" | "points" | "track"
|
|
38
|
-
export type GanttLineStyle = "heavy" | "thin" | "double" | "dashed"
|
|
39
|
-
export type GanttLabelLayout = "right" | "left" | "tree"
|
|
40
|
-
export type GanttTrackTone = "medium" | "dim" | "faint"
|
|
41
|
-
|
|
42
|
-
export type GanttBaseCellStyle = "title" | "axis" | "section" | GanttTaskState
|
|
43
|
-
export type GanttTrackCellStyle = "trackMedium" | "trackDim" | "trackFaint"
|
|
44
|
-
export type GanttCellStyle = GanttBaseCellStyle | GanttTrackCellStyle
|
|
1
|
+
export type GanttTaskState = "task" | "active" | "critical" | "done" | "milestone"
|
|
2
|
+
|
|
3
|
+
export interface GanttSection {
|
|
4
|
+
label: string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface GanttTask {
|
|
8
|
+
label: string
|
|
9
|
+
id?: string
|
|
10
|
+
section?: GanttSection
|
|
11
|
+
start: number
|
|
12
|
+
end: number
|
|
13
|
+
state: GanttTaskState
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type GanttEntry = { type: "section"; section: GanttSection } | { type: "task"; task: GanttTask }
|
|
17
|
+
|
|
18
|
+
export interface GanttDiagram {
|
|
19
|
+
title?: string
|
|
20
|
+
dateFormat: string
|
|
21
|
+
axisFormat: string
|
|
22
|
+
tasks: GanttTask[]
|
|
23
|
+
entries: GanttEntry[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface GanttDiagramRenderOptions {
|
|
27
|
+
layoutMaxWidth?: number
|
|
28
|
+
style?: GanttRenderStyle
|
|
29
|
+
track?: "dots" | "line"
|
|
30
|
+
endpoints?: "plain" | "points"
|
|
31
|
+
line?: GanttLineStyle
|
|
32
|
+
labels?: GanttLabelLayout
|
|
33
|
+
sections?: "compact" | "spaced"
|
|
34
|
+
trackTone?: GanttTrackTone
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type GanttRenderStyle = "rail" | "block" | "capsule" | "points" | "track"
|
|
38
|
+
export type GanttLineStyle = "heavy" | "thin" | "double" | "dashed"
|
|
39
|
+
export type GanttLabelLayout = "right" | "left" | "tree"
|
|
40
|
+
export type GanttTrackTone = "medium" | "dim" | "faint"
|
|
41
|
+
|
|
42
|
+
export type GanttBaseCellStyle = "title" | "axis" | "section" | GanttTaskState
|
|
43
|
+
export type GanttTrackCellStyle = "trackMedium" | "trackDim" | "trackFaint"
|
|
44
|
+
export type GanttCellStyle = GanttBaseCellStyle | GanttTrackCellStyle
|
package/src/gitgraph/diagram.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { drawGitGraphDiagramGrid } from "./drawing.js"
|
|
2
|
-
import { parseMermaidGitGraphDiagram } from "./parser.js"
|
|
3
|
-
import { renderGitGraphGridText } from "./render-grid.js"
|
|
4
|
-
import type { GitGraphDiagramRenderOptions } from "./types.js"
|
|
5
|
-
|
|
6
|
-
export function renderGitGraphDiagram(content: string, options: GitGraphDiagramRenderOptions = {}): string {
|
|
7
|
-
return renderGitGraphGridText(drawGitGraphDiagramGrid(parseMermaidGitGraphDiagram(content), options))
|
|
8
|
-
}
|
|
1
|
+
import { drawGitGraphDiagramGrid } from "./drawing.js"
|
|
2
|
+
import { parseMermaidGitGraphDiagram } from "./parser.js"
|
|
3
|
+
import { renderGitGraphGridText } from "./render-grid.js"
|
|
4
|
+
import type { GitGraphDiagramRenderOptions } from "./types.js"
|
|
5
|
+
|
|
6
|
+
export function renderGitGraphDiagram(content: string, options: GitGraphDiagramRenderOptions = {}): string {
|
|
7
|
+
return renderGitGraphGridText(drawGitGraphDiagramGrid(parseMermaidGitGraphDiagram(content), options))
|
|
8
|
+
}
|