Skip to content

Commit 07185df

Browse files
committed
feat(markdown): enhance mermaid plugin with zoom, tabs, pan, and export controls
1 parent f921394 commit 07185df

5 files changed

Lines changed: 619 additions & 32 deletions

File tree

‎docs/src/content/docs/components/markdown.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import MarkdownCustomPluginDemo from "../../../examples/markdown-custom-plugin-d
1717
## Installation
1818

1919
```bash
20-
pnpm add markdown-it markdown-it-highlightjs markdown-it-mermaid mermaid markdown-it-katex katex markdown-it-smiles markdown-it-anchor markdown-it-table-of-contents markdown-it-footnote markdown-it-emoji markdown-it-task-lists markdown-it-deflist markdown-it-ins markdown-it-del markdown-it-mark markdown-it-container markdown-it-link-attributes markdown-it-collapsible markdown-it-sanitizer @traptitech/markdown-it-spoiler
20+
pnpm add markdown-it markdown-it-highlightjs markdown-it-mermaid mermaid svg-pan-zoom markdown-it-katex katex markdown-it-smiles markdown-it-anchor markdown-it-table-of-contents markdown-it-footnote markdown-it-emoji markdown-it-task-lists markdown-it-deflist markdown-it-ins markdown-it-del markdown-it-mark markdown-it-container markdown-it-link-attributes markdown-it-collapsible markdown-it-sanitizer @traptitech/markdown-it-spoiler
2121
```
2222

2323
## Usage

‎package.json‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
"bugs": {
1414
"url": "https://github.com/vgerbot-libraries/shadcn-solid-components/issues"
1515
},
16-
"files": [
17-
"src",
18-
"bin"
19-
],
16+
"files": ["src", "bin"],
2017
"private": false,
2118
"sideEffects": false,
2219
"type": "module",
@@ -228,6 +225,7 @@
228225
"qrcode": "^1.5.4",
229226
"shadcn": "^3.7.0",
230227
"smiles-drawer": "^2.3.0",
228+
"svg-pan-zoom": "^3.6.2",
231229
"solid-js": "^1.6.0",
232230
"somoto": "^0.0.2",
233231
"tabulator-tables": "^6.3.1",
@@ -343,6 +341,9 @@
343341
"smiles-drawer": {
344342
"optional": true
345343
},
344+
"svg-pan-zoom": {
345+
"optional": true
346+
},
346347
"shadcn": {
347348
"optional": true
348349
},
@@ -382,6 +383,7 @@
382383
"markdown-it-task-lists": "^2.1.1",
383384
"qrcode": "^1.5.4",
384385
"smiles-drawer": "^2.3.0",
386+
"svg-pan-zoom": "^3.6.2",
385387
"solid-devtools": "^0.34.5",
386388
"solid-js": "^1.8.17",
387389
"solid-sonner": "^0.3.1",
@@ -394,9 +396,7 @@
394396
"vite-tsconfig-paths": "^6.0.5",
395397
"vitest": "^1.6.0"
396398
},
397-
"keywords": [
398-
"solid"
399-
],
399+
"keywords": ["solid"],
400400
"packageManager": "pnpm@9.1.1",
401401
"engines": {
402402
"node": ">=18",

‎src/components/markdown/modules.d.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,8 @@ declare module 'mermaid' {
128128

129129
export default mermaid
130130
}
131+
132+
declare module 'svg-pan-zoom' {
133+
const svgPanZoom: any
134+
export default svgPanZoom
135+
}
Lines changed: 103 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,117 @@
1-
.mermaid {
2-
margin: 1rem 0;
3-
overflow-x: auto;
1+
@reference "../../../../themes/base.css";
2+
3+
button {
4+
@apply border-0;
5+
}
6+
7+
.markdown-mermaid {
8+
@apply my-4;
9+
}
10+
11+
.markdown-mermaid__root {
12+
@apply border border-[rgb(148_163_184/0.3)] rounded-xl bg-[rgb(15_23_42/0.04)] overflow-hidden;
13+
}
14+
15+
.markdown-mermaid__header {
16+
@apply flex items-center justify-between gap-3 px-3 py-2 border-b border-b-[rgb(148_163_184/0.22)] bg-[rgb(15_23_42/0.03)];
17+
}
18+
19+
.markdown-mermaid__tabs,
20+
.markdown-mermaid__actions {
21+
@apply inline-flex items-center gap-1.5 flex-wrap;
22+
}
23+
24+
.markdown-mermaid__tabs {
25+
@apply bg-muted text-muted-foreground ring-muted relative h-[calc(var(--spacing)*7.5)] w-fit justify-center rounded-component ring-[3px];
26+
@apply gap-0;
27+
}
28+
29+
.markdown-mermaid__tab {
30+
@apply text-muted-foreground dark:text-muted-foreground relative z-10 inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 px-2 py-1 text-sm font-medium whitespace-nowrap bg-transparent transition-[color];
31+
@apply focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] focus-visible:outline-none;
32+
@apply disabled:pointer-events-none disabled:opacity-50;
33+
@apply cursor-pointer;
34+
}
35+
36+
.markdown-mermaid__action-button {
37+
@apply text-foreground inline-flex size-8 items-center justify-center rounded-component p-0 outline-none transition-all;
38+
@apply hover:bg-accent hover:text-accent-foreground hover:dark:bg-accent/50;
39+
@apply focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px];
40+
@apply disabled:pointer-events-none disabled:opacity-50;
41+
@apply cursor-pointer;
42+
}
43+
44+
.markdown-mermaid__tab.is-active {
45+
@apply text-foreground;
46+
}
47+
48+
.markdown-mermaid__tab-indicator {
49+
@apply bg-background dark:bg-input/30 dark:border-input absolute inset-0 border border-transparent shadow-sm rounded-component;
50+
@apply transition-[box-shadow,transform,width,height] duration-200;
51+
}
52+
53+
.markdown-mermaid__action-button svg {
54+
@apply size-4;
55+
}
56+
57+
.markdown-mermaid__body {
58+
@apply relative min-h-[220px];
59+
}
60+
61+
.markdown-mermaid__code,
62+
.markdown-mermaid__image {
63+
@apply m-0 min-h-[220px] p-3;
64+
}
65+
66+
.markdown-mermaid__code {
67+
@apply overflow-auto whitespace-pre font-mono text-[0.8125rem] leading-[1.6];
68+
}
69+
70+
.markdown-mermaid__image {
71+
@apply flex h-[220px] items-stretch justify-stretch overflow-hidden;
72+
}
73+
74+
.markdown-mermaid__image-inner {
75+
@apply flex-1 w-full h-[220px] min-h-[220px] flex items-center justify-center overflow-hidden;
76+
}
77+
78+
.markdown-mermaid__image-inner svg {
79+
@apply w-full max-w-full h-full max-h-[70vh];
80+
}
81+
82+
.markdown-mermaid__root[data-view="image"] .markdown-mermaid__code {
83+
@apply hidden;
84+
}
85+
86+
.markdown-mermaid__root[data-view="code"] .markdown-mermaid__image {
87+
@apply hidden;
88+
}
89+
90+
.markdown-mermaid__image:fullscreen {
91+
@apply h-full bg-[rgb(15_23_42/0.92)] p-5;
92+
}
93+
94+
.markdown-mermaid__image:fullscreen .markdown-mermaid__image-inner {
95+
@apply h-full;
96+
}
97+
98+
.markdown-mermaid__image:fullscreen .markdown-mermaid__image-inner svg {
99+
@apply max-h-[calc(100vh-2.5rem)];
4100
}
5101

6102
.markdown-mermaid-error {
7-
margin: 1rem 0;
8-
border: 1px solid rgb(248 113 113 / 0.4);
9-
border-radius: 0.5rem;
10-
background: rgb(127 29 29 / 0.08);
11-
padding: 0.75rem;
12-
color: rgb(185 28 28);
13-
font-size: 0.875rem;
14-
line-height: 1.5;
103+
@apply my-4 border border-[rgb(248_113_113/0.4)] rounded-lg bg-[rgb(127_29_29/0.08)] p-3 text-[rgb(185_28_28)] text-sm leading-6;
15104
}
16105

17106
.markdown-mermaid-error-title {
18-
font-weight: 600;
107+
@apply font-semibold;
19108
}
20109

21110
.markdown-mermaid-error-message,
22111
.markdown-mermaid-error-source {
23-
margin: 0.5rem 0 0;
24-
white-space: pre-wrap;
25-
word-break: break-word;
26-
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
112+
@apply mt-2 whitespace-pre-wrap break-words font-mono;
27113
}
28114

29115
.markdown-mermaid-error details {
30-
margin-top: 0.5rem;
116+
@apply mt-2;
31117
}

0 commit comments

Comments
 (0)