Skip to content

Commit 1eafcfc

Browse files
Mermaid 다이어그램 초기화 및 테마 설정 간소화
- Mermaid 초기화 로직을 간소화하고 기본 테마를 'default'로 설정 - 불필요한 다크모드 감지 및 테마 변경 감지 코드를 제거하여 코드 간결성 향상 - 폰트 패밀리를 'noto-sans-kr'로 변경하여 한국어 지원 개선
1 parent 1ede14c commit 1eafcfc

File tree

1 file changed

+12
-131
lines changed

1 file changed

+12
-131
lines changed

_includes/mermaid.html

Lines changed: 12 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -2,100 +2,18 @@
22
<script type="module">
33
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
44

5-
6-
7-
// 다크모드 감지 함수
8-
const detectDarkMode = () => {
9-
return window.matchMedia('(prefers-color-scheme: dark)').matches ||
10-
document.documentElement.getAttribute('data-theme') === 'dark' ||
11-
document.body.classList.contains('dark') ||
12-
document.documentElement.classList.contains('dark');
13-
};
14-
15-
// 초기 테마 감지
16-
let isDarkMode = detectDarkMode();
17-
18-
// Mermaid 초기화 함수 (기본 테마 사용)
19-
const initializeMermaid = (isDark) => {
20-
mermaid.initialize({
21-
startOnLoad: true,
22-
theme: isDark ? 'dark' : 'default',
23-
securityLevel: 'loose',
24-
fontFamily: 'Inter, -apple-system, BlinkMacSystemFont, sans-serif',
25-
26-
// 각 다이어그램별 세부 설정
27-
flowchart: {
28-
curve: 'basis',
29-
padding: 20
30-
},
31-
32-
sequence: {
33-
diagramMarginX: 50,
34-
diagramMarginY: 10,
35-
actorMargin: 50,
36-
width: 150,
37-
height: 65,
38-
boxMargin: 10,
39-
boxTextMargin: 5,
40-
noteMargin: 10,
41-
messageMargin: 35
42-
},
43-
44-
gantt: {
45-
numberSectionStyles: 4,
46-
axisFormat: '%m/%d',
47-
gridLineStartPadding: 350,
48-
fontSize: 11,
49-
sectionFontSize: 12,
50-
bottomPadding: 25,
51-
leftPadding: 75,
52-
rightPadding: 50
53-
}
54-
});
55-
};
56-
57-
// 초기 Mermaid 설정
58-
initializeMermaid(isDarkMode);
59-
60-
// 테마 변경 감지 및 다이어그램 다시 렌더링
61-
const handleThemeChange = async () => {
62-
const newIsDarkMode = detectDarkMode();
63-
if (newIsDarkMode !== isDarkMode) {
64-
isDarkMode = newIsDarkMode;
65-
66-
// Mermaid 재초기화
67-
initializeMermaid(isDarkMode);
68-
69-
// 기존 다이어그램 다시 렌더링
70-
const mermaidElements = document.querySelectorAll('.mermaid');
71-
for (const element of mermaidElements) {
72-
if (element.getAttribute('data-processed')) {
73-
element.removeAttribute('data-processed');
74-
const originalText = element.getAttribute('data-original-text');
75-
if (originalText) {
76-
element.textContent = originalText;
77-
await mermaid.run({
78-
querySelector: `#${element.id || Math.random().toString(36).substr(2, 9)}`,
79-
nodes: [element]
80-
});
81-
}
82-
}
83-
}
5+
// Mermaid 초기화
6+
mermaid.initialize({
7+
startOnLoad: true,
8+
theme: 'default',
9+
securityLevel: 'loose',
10+
fontFamily: 'noto-sans-kr, -apple-system, BlinkMacSystemFont, sans-serif',
11+
themeVariables: {
12+
primaryColor: '#667eea',
13+
secondaryColor: '#764ba2',
14+
tertiaryColor: '#8b7cf8',
15+
quaternaryColor: '#a78bfa',
8416
}
85-
};
86-
87-
// 테마 변경 감지를 위한 이벤트 리스너
88-
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', handleThemeChange);
89-
90-
// DOM 변경 감지 (data-theme 속성 변경 등)
91-
const themeObserver = new MutationObserver(handleThemeChange);
92-
themeObserver.observe(document.documentElement, {
93-
attributes: true,
94-
attributeFilter: ['data-theme', 'class']
95-
});
96-
themeObserver.observe(document.body, {
97-
attributes: true,
98-
attributeFilter: ['class']
9917
});
10018

10119
// 페이지 로드 완료 후 실행
@@ -122,41 +40,4 @@
12240
querySelector: '.mermaid',
12341
});
12442
});
125-
</script>
126-
127-
<!-- 기본 Mermaid 스타일 -->
128-
<style>
129-
.mermaid {
130-
text-align: center;
131-
margin: 2rem 0;
132-
background: transparent;
133-
border: 1px solid var(--border, #e2e8f0);
134-
border-radius: var(--radius-lg, 0.75rem);
135-
padding: 1.5rem;
136-
box-shadow: 0 2px 8px var(--shadow, rgba(0, 0, 0, 0.1));
137-
}
138-
139-
.mermaid svg {
140-
max-width: 100%;
141-
height: auto;
142-
display: block;
143-
margin: 0 auto;
144-
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
145-
}
146-
147-
/* 다크모드 테두리 조정 */
148-
[data-theme="dark"] .mermaid {
149-
border-color: var(--dark-border, #374151);
150-
box-shadow: 0 2px 8px var(--dark-shadow, rgba(0, 0, 0, 0.3));
151-
}
152-
153-
/* 반응형 */
154-
@media (max-width: 768px) {
155-
.mermaid {
156-
margin: 1.5rem 0;
157-
padding: 1rem;
158-
}
159-
}
160-
</style>
161-
162-
43+
</script>

0 commit comments

Comments
 (0)