@zyro-sec/merman 0.0.0-stage → 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 +29 -4
- package/script/layout-audit.ts +98 -0
- package/src/core/canvas.ts +228 -0
- package/src/core/color/style.ts +56 -0
- package/src/core/drawing.ts +301 -0
- package/src/core/geometry.ts +347 -0
- package/src/core/mermaid.ts +38 -0
- package/src/core/render-grid.ts +51 -0
- package/src/core/spatial.ts +243 -0
- package/src/core/text-lines.ts +32 -0
- package/src/core/text.ts +44 -0
- package/src/detect.ts +17 -0
- package/src/diagnostics.ts +16 -0
- package/src/flowchart/drawing.ts +340 -0
- package/src/flowchart/labels.ts +144 -0
- package/src/flowchart/layout.ts +1427 -0
- package/src/flowchart/options.ts +12 -0
- package/src/flowchart/parser.ts +467 -0
- package/src/flowchart/render.ts +10 -0
- package/src/flowchart/routing.ts +1542 -0
- package/src/flowchart/style.ts +79 -0
- package/src/flowchart/types.ts +65 -0
- package/src/gantt/diagram.ts +8 -0
- package/src/gantt/drawing.ts +191 -0
- package/src/gantt/parser.ts +161 -0
- package/src/gantt/render-grid.ts +17 -0
- package/src/gantt/style.ts +36 -0
- package/src/gantt/types.ts +44 -0
- package/src/gitgraph/diagram.ts +8 -0
- package/src/gitgraph/drawing.ts +234 -0
- package/src/gitgraph/parser.ts +219 -0
- package/src/gitgraph/render-grid.ts +17 -0
- package/src/gitgraph/style.ts +37 -0
- package/src/gitgraph/types.ts +36 -0
- package/src/markdown.ts +336 -0
- package/src/palette.ts +75 -0
- package/src/plugin.ts +15 -0
- package/src/sequence/diagram.ts +8 -0
- package/src/sequence/drawing.ts +287 -0
- package/src/sequence/options.ts +8 -0
- package/src/sequence/parser.ts +282 -0
- package/src/sequence/placement.ts +684 -0
- package/src/sequence/render-grid.ts +22 -0
- package/src/sequence/style.ts +81 -0
- package/src/sequence/types.ts +74 -0
- package/src/state/diagram.ts +8 -0
- package/src/state/drawing.ts +360 -0
- package/src/state/endpoint.ts +15 -0
- package/src/state/layout.ts +1134 -0
- package/src/state/note.ts +59 -0
- package/src/state/options.ts +11 -0
- package/src/state/parser.ts +224 -0
- package/src/state/render-grid.ts +22 -0
- package/src/state/routing.ts +1522 -0
- package/src/state/search.ts +103 -0
- package/src/state/style.ts +52 -0
- package/src/state/types.ts +63 -0
- package/src/state/visible-model.ts +77 -0
- package/src/test/diagram.ts +32 -0
- package/src/test/layout-audit/fixtures.ts +538 -0
- package/src/test/layout-audit/harness.ts +522 -0
- package/src/timeline/diagram.ts +8 -0
- package/src/timeline/drawing.ts +109 -0
- package/src/timeline/parser.ts +119 -0
- package/src/timeline/render-grid.ts +17 -0
- package/src/timeline/style.ts +36 -0
- package/src/timeline/types.ts +31 -0
- package/tsconfig.json +10 -0
- package/README.md +0 -3
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { firstMeaningfulMermaidLine, meaningfulNumberedMermaidLines, stripMermaidQuotes } from "../core/mermaid.js"
|
|
2
|
+
import { MermaidSyntaxError } from "../diagnostics.js"
|
|
3
|
+
import type { TimelineDiagram, TimelineDirection, TimelineEntry, TimelinePeriod, TimelineSection } from "./types.js"
|
|
4
|
+
|
|
5
|
+
const HEADER_RE = /^timeline(?:\s+(TD|LR))?$/i
|
|
6
|
+
const TITLE_RE = /^title(?:\s+(.+))?$/i
|
|
7
|
+
const SECTION_RE = /^section(?:\s+(.+))?$/i
|
|
8
|
+
const ACCESSIBILITY_RE = /^acc(?:Title|Descr)(?::|\s|$)/i
|
|
9
|
+
|
|
10
|
+
export function isMermaidTimelineDiagram(content: string): boolean {
|
|
11
|
+
return HEADER_RE.test(firstMeaningfulMermaidLine(content) ?? "")
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function parseMermaidTimelineDiagram(content: string): TimelineDiagram {
|
|
15
|
+
const sections: TimelineSection[] = []
|
|
16
|
+
const periods: TimelinePeriod[] = []
|
|
17
|
+
const entries: TimelineEntry[] = []
|
|
18
|
+
let direction: TimelineDirection = "LR"
|
|
19
|
+
let title: string | undefined
|
|
20
|
+
let currentPeriod: TimelinePeriod | undefined
|
|
21
|
+
let inAccessibilityDescription = false
|
|
22
|
+
|
|
23
|
+
for (const source of meaningfulNumberedMermaidLines(content)) {
|
|
24
|
+
const line = stripTimelineComment(source.text)
|
|
25
|
+
if (inAccessibilityDescription) {
|
|
26
|
+
if (line === "}") inAccessibilityDescription = false
|
|
27
|
+
continue
|
|
28
|
+
}
|
|
29
|
+
if (/^accDescr\s*\{$/i.test(line)) {
|
|
30
|
+
inAccessibilityDescription = true
|
|
31
|
+
continue
|
|
32
|
+
}
|
|
33
|
+
if (!line || line.startsWith("#") || ACCESSIBILITY_RE.test(line)) continue
|
|
34
|
+
const header = line.match(HEADER_RE)
|
|
35
|
+
if (header) {
|
|
36
|
+
direction = (header[1]?.toUpperCase() as TimelineDirection | undefined) ?? "LR"
|
|
37
|
+
continue
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const titleMatch = line.match(TITLE_RE)
|
|
41
|
+
if (titleMatch) {
|
|
42
|
+
if (!titleMatch[1]) throw syntaxError(source.lineNumber, line, "Timeline title cannot be empty")
|
|
43
|
+
title = stripMermaidQuotes(titleMatch[1])
|
|
44
|
+
continue
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const sectionMatch = line.match(SECTION_RE)
|
|
48
|
+
if (sectionMatch) {
|
|
49
|
+
if (!sectionMatch[1]) throw syntaxError(source.lineNumber, line, "Timeline section cannot be empty")
|
|
50
|
+
const section = { label: stripMermaidQuotes(sectionMatch[1]) }
|
|
51
|
+
sections.push(section)
|
|
52
|
+
entries.push({ type: "section", section })
|
|
53
|
+
currentPeriod = undefined
|
|
54
|
+
continue
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (line.startsWith(":")) {
|
|
58
|
+
if (!currentPeriod) {
|
|
59
|
+
throw syntaxError(source.lineNumber, line, "Timeline continuation requires a preceding period")
|
|
60
|
+
}
|
|
61
|
+
currentPeriod.events.push(...parseEvents(line.slice(1), source.lineNumber, line))
|
|
62
|
+
continue
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const fields = splitEventFields(line)
|
|
66
|
+
const periodLabel = stripMermaidQuotes(fields.shift()!)
|
|
67
|
+
if (!periodLabel) throw syntaxError(source.lineNumber, line, "Timeline period cannot be empty")
|
|
68
|
+
const period = {
|
|
69
|
+
period: periodLabel,
|
|
70
|
+
events: fields.length === 0 ? [] : parseEventFields(fields, source.lineNumber, line),
|
|
71
|
+
}
|
|
72
|
+
periods.push(period)
|
|
73
|
+
entries.push({ type: "period", period })
|
|
74
|
+
currentPeriod = period
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return { direction, ...(title === undefined ? {} : { title }), sections, periods, entries }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function parseEvents(value: string, lineNumber: number, sourceLine: string): string[] {
|
|
81
|
+
return parseEventFields(splitEventFields(value), lineNumber, sourceLine)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function parseEventFields(fields: string[], lineNumber: number, sourceLine: string): string[] {
|
|
85
|
+
const events = fields.map(stripMermaidQuotes)
|
|
86
|
+
if (events.length === 0 || events.some((event) => event.length === 0)) {
|
|
87
|
+
throw syntaxError(lineNumber, sourceLine, "Timeline event cannot be empty")
|
|
88
|
+
}
|
|
89
|
+
return events
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function splitEventFields(value: string): string[] {
|
|
93
|
+
const fields: string[] = []
|
|
94
|
+
let quote: '"' | "'" | undefined
|
|
95
|
+
let start = 0
|
|
96
|
+
for (let index = 0; index < value.length; index++) {
|
|
97
|
+
const char = value[index]
|
|
98
|
+
if (char === '"' || char === "'") {
|
|
99
|
+
if (quote === char) quote = undefined
|
|
100
|
+
else if (quote === undefined && value.slice(start, index).trim() === "") quote = char
|
|
101
|
+
continue
|
|
102
|
+
}
|
|
103
|
+
const next = value[index + 1]
|
|
104
|
+
if (char !== ":" || quote !== undefined || (next !== undefined && !/\s/.test(next))) continue
|
|
105
|
+
fields.push(value.slice(start, index))
|
|
106
|
+
start = index + 1
|
|
107
|
+
}
|
|
108
|
+
fields.push(value.slice(start))
|
|
109
|
+
return fields
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function stripTimelineComment(value: string): string {
|
|
113
|
+
const comment = value.indexOf("%%")
|
|
114
|
+
return (comment < 0 ? value : value.slice(0, comment)).trim()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function syntaxError(lineNumber: number, sourceLine: string, reason?: string): MermaidSyntaxError {
|
|
118
|
+
return new MermaidSyntaxError("timeline", lineNumber, sourceLine, reason)
|
|
119
|
+
}
|
|
@@ -0,0 +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 { TimelineStyleColors } from "./style.js"
|
|
5
|
+
import type { TimelineCellStyle } from "./types.js"
|
|
6
|
+
|
|
7
|
+
export type TimelineGrid = DiagramCanvas<TimelineCellStyle>
|
|
8
|
+
|
|
9
|
+
export function renderTimelineGridText(grid: TimelineGrid): string {
|
|
10
|
+
return grid.toString({ trimBottom: true })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function renderTimelineGridStyledText(grid: TimelineGrid, colors: TimelineStyleColors): StyledText {
|
|
14
|
+
return renderDiagramGridStyledText(grid, (run) => (run.style ? colors[run.style] : undefined), undefined, {
|
|
15
|
+
trimBottom: true,
|
|
16
|
+
})
|
|
17
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { RGBA } from "@opentui/core"
|
|
2
|
+
import { blendColor, numberedStyleKeys, rgba, type DiagramRgb } from "../core/color/style.js"
|
|
3
|
+
import type { TimelineBaseCellStyle, TimelineCellStyle } from "./types.js"
|
|
4
|
+
|
|
5
|
+
const DEFAULT_THEME_RGB = {
|
|
6
|
+
title: [228, 239, 232],
|
|
7
|
+
section: [154, 184, 169],
|
|
8
|
+
period: [230, 177, 126],
|
|
9
|
+
spine: [111, 138, 126],
|
|
10
|
+
event: [134, 225, 200],
|
|
11
|
+
} as const satisfies Record<TimelineBaseCellStyle, DiagramRgb>
|
|
12
|
+
|
|
13
|
+
export type TimelineStyleColors = Required<Record<TimelineCellStyle, RGBA>>
|
|
14
|
+
export const TIMELINE_SECTION_FADE_STYLES = numberedStyleKeys("sectionFade", [1, 2, 3] as const)
|
|
15
|
+
export const TIMELINE_PERIOD_FADE_STYLES = numberedStyleKeys("periodFade", [1, 2, 3] as const)
|
|
16
|
+
|
|
17
|
+
export function resolveTimelineStyleColors(
|
|
18
|
+
colors: Partial<Record<TimelineBaseCellStyle, RGBA | undefined>> = {},
|
|
19
|
+
): TimelineStyleColors {
|
|
20
|
+
const section = colors.section ?? rgba(DEFAULT_THEME_RGB.section)
|
|
21
|
+
const period = colors.period ?? rgba(DEFAULT_THEME_RGB.period)
|
|
22
|
+
const spine = colors.spine ?? rgba(DEFAULT_THEME_RGB.spine)
|
|
23
|
+
return {
|
|
24
|
+
title: colors.title ?? rgba(DEFAULT_THEME_RGB.title),
|
|
25
|
+
section,
|
|
26
|
+
period,
|
|
27
|
+
spine,
|
|
28
|
+
event: colors.event ?? rgba(DEFAULT_THEME_RGB.event),
|
|
29
|
+
sectionFade1: blendColor(section, spine, 0.5),
|
|
30
|
+
sectionFade2: blendColor(section, spine, 0.67),
|
|
31
|
+
sectionFade3: blendColor(section, spine, 0.83),
|
|
32
|
+
periodFade1: blendColor(period, spine, 0.5),
|
|
33
|
+
periodFade2: blendColor(period, spine, 0.67),
|
|
34
|
+
periodFade3: blendColor(period, spine, 0.83),
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type TimelineDirection = "TD" | "LR"
|
|
2
|
+
|
|
3
|
+
export interface TimelineSection {
|
|
4
|
+
label: string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface TimelinePeriod {
|
|
8
|
+
period: string
|
|
9
|
+
events: string[]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type TimelineEntry = { type: "section"; section: TimelineSection } | { type: "period"; period: TimelinePeriod }
|
|
13
|
+
|
|
14
|
+
export interface TimelineDiagram {
|
|
15
|
+
direction: TimelineDirection
|
|
16
|
+
title?: string
|
|
17
|
+
sections: TimelineSection[]
|
|
18
|
+
periods: TimelinePeriod[]
|
|
19
|
+
entries: TimelineEntry[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface TimelineDiagramRenderOptions {
|
|
23
|
+
/** Parsed for Mermaid compatibility. Timeline diagrams always use a vertical terminal layout. */
|
|
24
|
+
direction?: TimelineDirection
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type TimelineBaseCellStyle = "title" | "section" | "period" | "spine" | "event"
|
|
28
|
+
export type TimelineFadeStep = 1 | 2 | 3
|
|
29
|
+
export type TimelineSectionFadeStyle = `sectionFade${TimelineFadeStep}`
|
|
30
|
+
export type TimelinePeriodFadeStyle = `periodFade${TimelineFadeStep}`
|
|
31
|
+
export type TimelineCellStyle = TimelineBaseCellStyle | TimelineSectionFadeStyle | TimelinePeriodFadeStyle
|
package/tsconfig.json
ADDED
package/README.md
DELETED