@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/flowchart/labels.ts
CHANGED
|
@@ -1,144 +1,144 @@
|
|
|
1
|
-
import {
|
|
2
|
-
clampPoint,
|
|
3
|
-
centeredSpanStart,
|
|
4
|
-
insetSpan,
|
|
5
|
-
midpoint,
|
|
6
|
-
point,
|
|
7
|
-
pointOnSegment,
|
|
8
|
-
segmentBetween,
|
|
9
|
-
segmentSpan,
|
|
10
|
-
shiftPoint,
|
|
11
|
-
spanCapacity,
|
|
12
|
-
type DiagramSegment,
|
|
13
|
-
} from "../core/geometry.js"
|
|
14
|
-
import { measureDiagramLabelWidth, padDiagramLabelLine, splitDiagramLines } from "../core/text.js"
|
|
15
|
-
import type { FlowchartEdgeRoute, FlowchartPoint } from "./types.js"
|
|
16
|
-
|
|
17
|
-
const LABEL_BUS_CLEARANCE = 3
|
|
18
|
-
const LABEL_NODE_CLEARANCE = 2
|
|
19
|
-
const LABEL_LINE_CLEARANCE = 2
|
|
20
|
-
const LABEL_TERMINAL_CLEARANCE = 1
|
|
21
|
-
|
|
22
|
-
export interface FlowchartEdgeLabelLayout {
|
|
23
|
-
lines: string[]
|
|
24
|
-
point: FlowchartPoint
|
|
25
|
-
width: number
|
|
26
|
-
height: number
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function flowchartLabelText(label: string): string {
|
|
30
|
-
return padDiagramLabelLine(label)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function flowchartLabelWidth(label: string, measure: (text: string) => number): number {
|
|
34
|
-
return measureDiagramLabelWidth(label, measure)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function minimumInlineLabelLength(labelWidth: number): number {
|
|
38
|
-
return labelWidth + LABEL_LINE_CLEARANCE * 2 - 1
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function flowchartHorizontalLabelRankGap(labelWidth: number): number {
|
|
42
|
-
return minimumInlineLabelLength(labelWidth) + LABEL_BUS_CLEARANCE + 1
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function flowchartVerticalBranchLabelGap(labelWidth: number): number {
|
|
46
|
-
return minimumInlineLabelLength(labelWidth) + LABEL_BUS_CLEARANCE + LABEL_NODE_CLEARANCE
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function inlineLabelSlot(segment: DiagramSegment, labelWidth: number): { x: number; fits: boolean } {
|
|
50
|
-
const slot = insetSpan(segmentSpan(segment), LABEL_LINE_CLEARANCE)
|
|
51
|
-
return { x: centeredSpanStart(slot, labelWidth), fits: spanCapacity(slot) >= labelWidth }
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function segmentLabelPoint(segment: DiagramSegment, labelWidth: number, labelHeight: number): FlowchartPoint {
|
|
55
|
-
if (segment.axis === "x") {
|
|
56
|
-
const slot = inlineLabelSlot(segment, labelWidth)
|
|
57
|
-
if (labelHeight === 1 && slot.fits) return point(slot.x, segment.from.y)
|
|
58
|
-
|
|
59
|
-
if (labelHeight > 1) {
|
|
60
|
-
return shiftPoint(point(slot.x, segment.from.y), "up", labelHeight)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return clampPoint(shiftPoint(shiftPoint(segment.from, segment.direction, LABEL_LINE_CLEARANCE), "up", labelHeight))
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const slot = insetSpan(segmentSpan(segment), LABEL_TERMINAL_CLEARANCE)
|
|
67
|
-
if (spanCapacity(slot) >= labelHeight) {
|
|
68
|
-
return clampPoint(point(segment.from.x + 1, centeredSpanStart(slot, labelHeight)))
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const center = shiftPoint(pointOnSegment(segment, midpoint(segmentSpan(segment))), "right")
|
|
72
|
-
return clampPoint(shiftPoint(center, "up", Math.floor((labelHeight - 1) / 2)))
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function bestLabelSegment(
|
|
76
|
-
points: readonly FlowchartPoint[],
|
|
77
|
-
labelWidth: number,
|
|
78
|
-
preferredAxis?: DiagramSegment["axis"],
|
|
79
|
-
preferredSegment?: number,
|
|
80
|
-
): DiagramSegment | undefined {
|
|
81
|
-
const segments = points.slice(1).flatMap((to, index) => {
|
|
82
|
-
const segment = segmentBetween(points[index]!, to)
|
|
83
|
-
return segment ? [segment] : []
|
|
84
|
-
})
|
|
85
|
-
if (preferredSegment !== undefined && segments[preferredSegment]) return segments[preferredSegment]
|
|
86
|
-
const preferred = preferredAxis ? segments.find((segment) => segment.axis === preferredAxis) : undefined
|
|
87
|
-
if (preferred) return preferred
|
|
88
|
-
|
|
89
|
-
let roomyHorizontal: DiagramSegment | undefined
|
|
90
|
-
let verticalBus: DiagramSegment | undefined
|
|
91
|
-
let longest: DiagramSegment | undefined
|
|
92
|
-
|
|
93
|
-
for (const segment of segments) {
|
|
94
|
-
if (!roomyHorizontal && segment.axis === "x" && inlineLabelSlot(segment, labelWidth).fits) roomyHorizontal = segment
|
|
95
|
-
if (!verticalBus && segment.axis === "y") verticalBus = segment
|
|
96
|
-
if (!longest || segment.length > longest.length) longest = segment
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return roomyHorizontal ?? verticalBus ?? longest
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function flowchartLabelPoint(
|
|
103
|
-
points: readonly FlowchartPoint[],
|
|
104
|
-
labelWidth: number,
|
|
105
|
-
labelHeight: number,
|
|
106
|
-
preferredAxis?: DiagramSegment["axis"],
|
|
107
|
-
preferredSegment?: number,
|
|
108
|
-
): FlowchartPoint {
|
|
109
|
-
const segment = bestLabelSegment(points, labelWidth, preferredAxis, preferredSegment)
|
|
110
|
-
return segment ? segmentLabelPoint(segment, labelWidth, labelHeight) : (points[0] ?? point(0, 0))
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export function flowchartEdgeLabelLayout(
|
|
114
|
-
points: readonly FlowchartPoint[],
|
|
115
|
-
label: string,
|
|
116
|
-
measure: (text: string) => number,
|
|
117
|
-
preferredAxis?: DiagramSegment["axis"],
|
|
118
|
-
preferredSegment?: number,
|
|
119
|
-
): FlowchartEdgeLabelLayout {
|
|
120
|
-
const lines = splitDiagramLines(label).map(flowchartLabelText)
|
|
121
|
-
const width = flowchartLabelWidth(label, measure)
|
|
122
|
-
const height = lines.length
|
|
123
|
-
return {
|
|
124
|
-
lines,
|
|
125
|
-
point: flowchartLabelPoint(points, width, height, preferredAxis, preferredSegment),
|
|
126
|
-
width,
|
|
127
|
-
height,
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function flowchartRouteLabelLayout(
|
|
132
|
-
route: Pick<FlowchartEdgeRoute, "edge" | "points" | "labelAxis" | "labelPoint">,
|
|
133
|
-
measure: (text: string) => number,
|
|
134
|
-
): FlowchartEdgeLabelLayout {
|
|
135
|
-
const lines = splitDiagramLines(route.edge.label).map(flowchartLabelText)
|
|
136
|
-
const width = flowchartLabelWidth(route.edge.label, measure)
|
|
137
|
-
const height = lines.length
|
|
138
|
-
return {
|
|
139
|
-
lines,
|
|
140
|
-
point: route.labelPoint ?? flowchartLabelPoint(route.points, width, height, route.labelAxis),
|
|
141
|
-
width,
|
|
142
|
-
height,
|
|
143
|
-
}
|
|
144
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
clampPoint,
|
|
3
|
+
centeredSpanStart,
|
|
4
|
+
insetSpan,
|
|
5
|
+
midpoint,
|
|
6
|
+
point,
|
|
7
|
+
pointOnSegment,
|
|
8
|
+
segmentBetween,
|
|
9
|
+
segmentSpan,
|
|
10
|
+
shiftPoint,
|
|
11
|
+
spanCapacity,
|
|
12
|
+
type DiagramSegment,
|
|
13
|
+
} from "../core/geometry.js"
|
|
14
|
+
import { measureDiagramLabelWidth, padDiagramLabelLine, splitDiagramLines } from "../core/text.js"
|
|
15
|
+
import type { FlowchartEdgeRoute, FlowchartPoint } from "./types.js"
|
|
16
|
+
|
|
17
|
+
const LABEL_BUS_CLEARANCE = 3
|
|
18
|
+
const LABEL_NODE_CLEARANCE = 2
|
|
19
|
+
const LABEL_LINE_CLEARANCE = 2
|
|
20
|
+
const LABEL_TERMINAL_CLEARANCE = 1
|
|
21
|
+
|
|
22
|
+
export interface FlowchartEdgeLabelLayout {
|
|
23
|
+
lines: string[]
|
|
24
|
+
point: FlowchartPoint
|
|
25
|
+
width: number
|
|
26
|
+
height: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function flowchartLabelText(label: string): string {
|
|
30
|
+
return padDiagramLabelLine(label)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function flowchartLabelWidth(label: string, measure: (text: string) => number): number {
|
|
34
|
+
return measureDiagramLabelWidth(label, measure)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function minimumInlineLabelLength(labelWidth: number): number {
|
|
38
|
+
return labelWidth + LABEL_LINE_CLEARANCE * 2 - 1
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function flowchartHorizontalLabelRankGap(labelWidth: number): number {
|
|
42
|
+
return minimumInlineLabelLength(labelWidth) + LABEL_BUS_CLEARANCE + 1
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function flowchartVerticalBranchLabelGap(labelWidth: number): number {
|
|
46
|
+
return minimumInlineLabelLength(labelWidth) + LABEL_BUS_CLEARANCE + LABEL_NODE_CLEARANCE
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function inlineLabelSlot(segment: DiagramSegment, labelWidth: number): { x: number; fits: boolean } {
|
|
50
|
+
const slot = insetSpan(segmentSpan(segment), LABEL_LINE_CLEARANCE)
|
|
51
|
+
return { x: centeredSpanStart(slot, labelWidth), fits: spanCapacity(slot) >= labelWidth }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function segmentLabelPoint(segment: DiagramSegment, labelWidth: number, labelHeight: number): FlowchartPoint {
|
|
55
|
+
if (segment.axis === "x") {
|
|
56
|
+
const slot = inlineLabelSlot(segment, labelWidth)
|
|
57
|
+
if (labelHeight === 1 && slot.fits) return point(slot.x, segment.from.y)
|
|
58
|
+
|
|
59
|
+
if (labelHeight > 1) {
|
|
60
|
+
return shiftPoint(point(slot.x, segment.from.y), "up", labelHeight)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return clampPoint(shiftPoint(shiftPoint(segment.from, segment.direction, LABEL_LINE_CLEARANCE), "up", labelHeight))
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const slot = insetSpan(segmentSpan(segment), LABEL_TERMINAL_CLEARANCE)
|
|
67
|
+
if (spanCapacity(slot) >= labelHeight) {
|
|
68
|
+
return clampPoint(point(segment.from.x + 1, centeredSpanStart(slot, labelHeight)))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const center = shiftPoint(pointOnSegment(segment, midpoint(segmentSpan(segment))), "right")
|
|
72
|
+
return clampPoint(shiftPoint(center, "up", Math.floor((labelHeight - 1) / 2)))
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function bestLabelSegment(
|
|
76
|
+
points: readonly FlowchartPoint[],
|
|
77
|
+
labelWidth: number,
|
|
78
|
+
preferredAxis?: DiagramSegment["axis"],
|
|
79
|
+
preferredSegment?: number,
|
|
80
|
+
): DiagramSegment | undefined {
|
|
81
|
+
const segments = points.slice(1).flatMap((to, index) => {
|
|
82
|
+
const segment = segmentBetween(points[index]!, to)
|
|
83
|
+
return segment ? [segment] : []
|
|
84
|
+
})
|
|
85
|
+
if (preferredSegment !== undefined && segments[preferredSegment]) return segments[preferredSegment]
|
|
86
|
+
const preferred = preferredAxis ? segments.find((segment) => segment.axis === preferredAxis) : undefined
|
|
87
|
+
if (preferred) return preferred
|
|
88
|
+
|
|
89
|
+
let roomyHorizontal: DiagramSegment | undefined
|
|
90
|
+
let verticalBus: DiagramSegment | undefined
|
|
91
|
+
let longest: DiagramSegment | undefined
|
|
92
|
+
|
|
93
|
+
for (const segment of segments) {
|
|
94
|
+
if (!roomyHorizontal && segment.axis === "x" && inlineLabelSlot(segment, labelWidth).fits) roomyHorizontal = segment
|
|
95
|
+
if (!verticalBus && segment.axis === "y") verticalBus = segment
|
|
96
|
+
if (!longest || segment.length > longest.length) longest = segment
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return roomyHorizontal ?? verticalBus ?? longest
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function flowchartLabelPoint(
|
|
103
|
+
points: readonly FlowchartPoint[],
|
|
104
|
+
labelWidth: number,
|
|
105
|
+
labelHeight: number,
|
|
106
|
+
preferredAxis?: DiagramSegment["axis"],
|
|
107
|
+
preferredSegment?: number,
|
|
108
|
+
): FlowchartPoint {
|
|
109
|
+
const segment = bestLabelSegment(points, labelWidth, preferredAxis, preferredSegment)
|
|
110
|
+
return segment ? segmentLabelPoint(segment, labelWidth, labelHeight) : (points[0] ?? point(0, 0))
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function flowchartEdgeLabelLayout(
|
|
114
|
+
points: readonly FlowchartPoint[],
|
|
115
|
+
label: string,
|
|
116
|
+
measure: (text: string) => number,
|
|
117
|
+
preferredAxis?: DiagramSegment["axis"],
|
|
118
|
+
preferredSegment?: number,
|
|
119
|
+
): FlowchartEdgeLabelLayout {
|
|
120
|
+
const lines = splitDiagramLines(label).map(flowchartLabelText)
|
|
121
|
+
const width = flowchartLabelWidth(label, measure)
|
|
122
|
+
const height = lines.length
|
|
123
|
+
return {
|
|
124
|
+
lines,
|
|
125
|
+
point: flowchartLabelPoint(points, width, height, preferredAxis, preferredSegment),
|
|
126
|
+
width,
|
|
127
|
+
height,
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function flowchartRouteLabelLayout(
|
|
132
|
+
route: Pick<FlowchartEdgeRoute, "edge" | "points" | "labelAxis" | "labelPoint">,
|
|
133
|
+
measure: (text: string) => number,
|
|
134
|
+
): FlowchartEdgeLabelLayout {
|
|
135
|
+
const lines = splitDiagramLines(route.edge.label).map(flowchartLabelText)
|
|
136
|
+
const width = flowchartLabelWidth(route.edge.label, measure)
|
|
137
|
+
const height = lines.length
|
|
138
|
+
return {
|
|
139
|
+
lines,
|
|
140
|
+
point: route.labelPoint ?? flowchartLabelPoint(route.points, width, height, route.labelAxis),
|
|
141
|
+
width,
|
|
142
|
+
height,
|
|
143
|
+
}
|
|
144
|
+
}
|