forked from mermaid-js/mermaid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
styles.ts
85 lines (73 loc) · 1.72 KB
/
styles.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import type { FlowChartStyleOptions } from './diagrams/flowchart/styles.js';
import { log } from './logger.js';
const themes: Record<string, (options?: any) => string> = {};
const getStyles = (
type: string,
userStyles: string,
options: {
fontFamily: string;
fontSize: string;
textColor: string;
errorBkgColor: string;
errorTextColor: string;
lineColor: string;
} & FlowChartStyleOptions
) => {
let diagramStyles = '';
if (type in themes && themes[type as keyof typeof themes]) {
diagramStyles = themes[type as keyof typeof themes](options);
} else {
log.warn(`No theme found for ${type}`);
}
return ` & {
font-family: ${options.fontFamily};
font-size: ${options.fontSize};
fill: ${options.textColor}
}
/* Classes common for multiple diagrams */
& .error-icon {
fill: ${options.errorBkgColor};
}
& .error-text {
fill: ${options.errorTextColor};
stroke: ${options.errorTextColor};
}
& .edge-thickness-normal {
stroke-width: 2px;
}
& .edge-thickness-thick {
stroke-width: 3.5px
}
& .edge-pattern-solid {
stroke-dasharray: 0;
}
& .edge-pattern-dashed{
stroke-dasharray: 3;
}
.edge-pattern-dotted {
stroke-dasharray: 2;
}
& .marker {
fill: ${options.lineColor};
stroke: ${options.lineColor};
}
& .marker.cross {
stroke: ${options.lineColor};
}
& svg {
font-family: ${options.fontFamily};
font-size: ${options.fontSize};
}
${diagramStyles}
${userStyles}
`;
};
export const addStylesForDiagram = (
type: string,
diagramTheme?: (options?: any) => string
): void => {
if (diagramTheme !== undefined) {
themes[type] = (options) => diagramTheme(options);
}
};
export default getStyles;