@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/core/text-lines.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
export interface DiagramTextRun {
|
|
2
|
-
text: string
|
|
3
|
-
italic: boolean
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface DiagramTextLine {
|
|
7
|
-
text: string
|
|
8
|
-
runs: DiagramTextRun[]
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function parseDiagramTextLines(value: string): DiagramTextLine[] {
|
|
12
|
-
return value.split(/<br\s*\/?>/i).map((line) => {
|
|
13
|
-
const runs: DiagramTextRun[] = []
|
|
14
|
-
const source = line.trim()
|
|
15
|
-
const tag = /<\/?(?:i|em)\s*>/gi
|
|
16
|
-
let italic = false
|
|
17
|
-
let offset = 0
|
|
18
|
-
|
|
19
|
-
for (const match of source.matchAll(tag)) {
|
|
20
|
-
if (match.index > offset) runs.push({ text: source.slice(offset, match.index), italic })
|
|
21
|
-
italic = !match[0].startsWith("</")
|
|
22
|
-
offset = match.index + match[0].length
|
|
23
|
-
}
|
|
24
|
-
if (offset < source.length) runs.push({ text: source.slice(offset), italic })
|
|
25
|
-
|
|
26
|
-
return { text: runs.map((run) => run.text).join(""), runs }
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function splitDiagramLines(value: string): string[] {
|
|
31
|
-
return parseDiagramTextLines(value).map((line) => line.text)
|
|
32
|
-
}
|
|
1
|
+
export interface DiagramTextRun {
|
|
2
|
+
text: string
|
|
3
|
+
italic: boolean
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface DiagramTextLine {
|
|
7
|
+
text: string
|
|
8
|
+
runs: DiagramTextRun[]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function parseDiagramTextLines(value: string): DiagramTextLine[] {
|
|
12
|
+
return value.split(/<br\s*\/?>/i).map((line) => {
|
|
13
|
+
const runs: DiagramTextRun[] = []
|
|
14
|
+
const source = line.trim()
|
|
15
|
+
const tag = /<\/?(?:i|em)\s*>/gi
|
|
16
|
+
let italic = false
|
|
17
|
+
let offset = 0
|
|
18
|
+
|
|
19
|
+
for (const match of source.matchAll(tag)) {
|
|
20
|
+
if (match.index > offset) runs.push({ text: source.slice(offset, match.index), italic })
|
|
21
|
+
italic = !match[0].startsWith("</")
|
|
22
|
+
offset = match.index + match[0].length
|
|
23
|
+
}
|
|
24
|
+
if (offset < source.length) runs.push({ text: source.slice(offset), italic })
|
|
25
|
+
|
|
26
|
+
return { text: runs.map((run) => run.text).join(""), runs }
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function splitDiagramLines(value: string): string[] {
|
|
31
|
+
return parseDiagramTextLines(value).map((line) => line.text)
|
|
32
|
+
}
|
package/src/core/text.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import stringWidth from "string-width"
|
|
2
|
-
import { splitDiagramLines } from "./text-lines.js"
|
|
3
|
-
|
|
4
|
-
export { parseDiagramTextLines, splitDiagramLines } from "./text-lines.js"
|
|
5
|
-
|
|
6
|
-
export interface DiagramTextBoxSize {
|
|
7
|
-
width: number
|
|
8
|
-
height: number
|
|
9
|
-
lines: string[]
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function diagramTextWidth(value: string): number {
|
|
13
|
-
return stringWidth(value)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const DIAGRAM_LABEL_PADDING_X = 1
|
|
17
|
-
|
|
18
|
-
export function padDiagramLabelLine(value: string): string {
|
|
19
|
-
const padding = " ".repeat(DIAGRAM_LABEL_PADDING_X)
|
|
20
|
-
return `${padding}${value}${padding}`
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function measureDiagramLabelWidth(value: string, measure = diagramTextWidth): number {
|
|
24
|
-
return Math.max(...splitDiagramLines(value).map((line) => measure(line) + DIAGRAM_LABEL_PADDING_X * 2))
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" })
|
|
28
|
-
|
|
29
|
-
export function* diagramTextGraphemes(value: string): Generator<string> {
|
|
30
|
-
for (const { segment } of graphemeSegmenter.segment(value)) yield segment
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function measureDiagramTextBox(
|
|
34
|
-
value: string,
|
|
35
|
-
options: { paddingX?: number; paddingY?: number; minInnerWidth?: number } = {},
|
|
36
|
-
): DiagramTextBoxSize {
|
|
37
|
-
const lines = splitDiagramLines(value)
|
|
38
|
-
const innerWidth = Math.max(...lines.map(diagramTextWidth), options.minInnerWidth ?? 1)
|
|
39
|
-
return {
|
|
40
|
-
width: innerWidth + (options.paddingX ?? 0) * 2,
|
|
41
|
-
height: lines.length + (options.paddingY ?? 0) * 2,
|
|
42
|
-
lines,
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
import stringWidth from "string-width"
|
|
2
|
+
import { splitDiagramLines } from "./text-lines.js"
|
|
3
|
+
|
|
4
|
+
export { parseDiagramTextLines, splitDiagramLines } from "./text-lines.js"
|
|
5
|
+
|
|
6
|
+
export interface DiagramTextBoxSize {
|
|
7
|
+
width: number
|
|
8
|
+
height: number
|
|
9
|
+
lines: string[]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function diagramTextWidth(value: string): number {
|
|
13
|
+
return stringWidth(value)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const DIAGRAM_LABEL_PADDING_X = 1
|
|
17
|
+
|
|
18
|
+
export function padDiagramLabelLine(value: string): string {
|
|
19
|
+
const padding = " ".repeat(DIAGRAM_LABEL_PADDING_X)
|
|
20
|
+
return `${padding}${value}${padding}`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function measureDiagramLabelWidth(value: string, measure = diagramTextWidth): number {
|
|
24
|
+
return Math.max(...splitDiagramLines(value).map((line) => measure(line) + DIAGRAM_LABEL_PADDING_X * 2))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" })
|
|
28
|
+
|
|
29
|
+
export function* diagramTextGraphemes(value: string): Generator<string> {
|
|
30
|
+
for (const { segment } of graphemeSegmenter.segment(value)) yield segment
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function measureDiagramTextBox(
|
|
34
|
+
value: string,
|
|
35
|
+
options: { paddingX?: number; paddingY?: number; minInnerWidth?: number } = {},
|
|
36
|
+
): DiagramTextBoxSize {
|
|
37
|
+
const lines = splitDiagramLines(value)
|
|
38
|
+
const innerWidth = Math.max(...lines.map(diagramTextWidth), options.minInnerWidth ?? 1)
|
|
39
|
+
return {
|
|
40
|
+
width: innerWidth + (options.paddingX ?? 0) * 2,
|
|
41
|
+
height: lines.length + (options.paddingY ?? 0) * 2,
|
|
42
|
+
lines,
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/detect.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { MermaidDiagramKind } from "./diagnostics.js"
|
|
2
|
-
import { isMermaidFlowchartDiagram } from "./flowchart/parser.js"
|
|
3
|
-
import { isMermaidGanttDiagram } from "./gantt/parser.js"
|
|
4
|
-
import { isMermaidGitGraphDiagram } from "./gitgraph/parser.js"
|
|
5
|
-
import { isMermaidSequenceDiagram } from "./sequence/parser.js"
|
|
6
|
-
import { isMermaidStateDiagram } from "./state/parser.js"
|
|
7
|
-
import { isMermaidTimelineDiagram } from "./timeline/parser.js"
|
|
8
|
-
|
|
9
|
-
export function detectMermaidDiagram(content: string): MermaidDiagramKind | undefined {
|
|
10
|
-
if (isMermaidFlowchartDiagram(content)) return "flowchart"
|
|
11
|
-
if (isMermaidGanttDiagram(content)) return "gantt"
|
|
12
|
-
if (isMermaidGitGraphDiagram(content)) return "gitGraph"
|
|
13
|
-
if (isMermaidSequenceDiagram(content)) return "sequence"
|
|
14
|
-
if (isMermaidStateDiagram(content)) return "state"
|
|
15
|
-
if (isMermaidTimelineDiagram(content)) return "timeline"
|
|
16
|
-
return undefined
|
|
17
|
-
}
|
|
1
|
+
import type { MermaidDiagramKind } from "./diagnostics.js"
|
|
2
|
+
import { isMermaidFlowchartDiagram } from "./flowchart/parser.js"
|
|
3
|
+
import { isMermaidGanttDiagram } from "./gantt/parser.js"
|
|
4
|
+
import { isMermaidGitGraphDiagram } from "./gitgraph/parser.js"
|
|
5
|
+
import { isMermaidSequenceDiagram } from "./sequence/parser.js"
|
|
6
|
+
import { isMermaidStateDiagram } from "./state/parser.js"
|
|
7
|
+
import { isMermaidTimelineDiagram } from "./timeline/parser.js"
|
|
8
|
+
|
|
9
|
+
export function detectMermaidDiagram(content: string): MermaidDiagramKind | undefined {
|
|
10
|
+
if (isMermaidFlowchartDiagram(content)) return "flowchart"
|
|
11
|
+
if (isMermaidGanttDiagram(content)) return "gantt"
|
|
12
|
+
if (isMermaidGitGraphDiagram(content)) return "gitGraph"
|
|
13
|
+
if (isMermaidSequenceDiagram(content)) return "sequence"
|
|
14
|
+
if (isMermaidStateDiagram(content)) return "state"
|
|
15
|
+
if (isMermaidTimelineDiagram(content)) return "timeline"
|
|
16
|
+
return undefined
|
|
17
|
+
}
|
package/src/diagnostics.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export type MermaidDiagramKind = "flowchart" | "sequence" | "state" | "timeline" | "gitGraph" | "gantt"
|
|
2
|
-
|
|
3
|
-
/** An otherwise valid diagram contains syntax that this renderer does not support. */
|
|
4
|
-
export class MermaidSyntaxError extends Error {
|
|
5
|
-
readonly _tag = "MermaidSyntaxError"
|
|
6
|
-
|
|
7
|
-
constructor(
|
|
8
|
-
readonly kind: MermaidDiagramKind,
|
|
9
|
-
readonly lineNumber: number,
|
|
10
|
-
readonly sourceLine: string,
|
|
11
|
-
reason = "Unsupported syntax",
|
|
12
|
-
) {
|
|
13
|
-
super(`${reason} in ${kind} diagram at line ${lineNumber}: "${sourceLine}"`)
|
|
14
|
-
this.name = "MermaidSyntaxError"
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
export type MermaidDiagramKind = "flowchart" | "sequence" | "state" | "timeline" | "gitGraph" | "gantt"
|
|
2
|
+
|
|
3
|
+
/** An otherwise valid diagram contains syntax that this renderer does not support. */
|
|
4
|
+
export class MermaidSyntaxError extends Error {
|
|
5
|
+
readonly _tag = "MermaidSyntaxError"
|
|
6
|
+
|
|
7
|
+
constructor(
|
|
8
|
+
readonly kind: MermaidDiagramKind,
|
|
9
|
+
readonly lineNumber: number,
|
|
10
|
+
readonly sourceLine: string,
|
|
11
|
+
reason = "Unsupported syntax",
|
|
12
|
+
) {
|
|
13
|
+
super(`${reason} in ${kind} diagram at line ${lineNumber}: "${sourceLine}"`)
|
|
14
|
+
this.name = "MermaidSyntaxError"
|
|
15
|
+
}
|
|
16
|
+
}
|