@bytechain.cn/colamd 1.5.1-beta.2 → 1.5.2
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/CHANGELOG.md +194 -162
- package/README.md +148 -5
- package/README_CN.md +163 -13
- package/dist/lib/colamd-renderer.js +193804 -0
- package/dist/lib/colamd-renderer.js.map +1 -0
- package/dist/lib/colamd.css +1810 -0
- package/dist/lib/editor/editor.d.ts +27 -0
- package/dist/lib/editor/html-view.d.ts +2 -0
- package/dist/lib/editor/lib.d.ts +49 -0
- package/dist/lib/editor/plugins/index.d.ts +56 -0
- package/dist/lib/editor/plugins/lib-entry.d.ts +10 -0
- package/dist/lib/editor/plugins/math-plugin.d.ts +9 -0
- package/dist/lib/editor/plugins/mermaid-plugin.d.ts +19 -0
- package/dist/lib/editor/plugins/themes/theme-manager.d.ts +30 -0
- package/dist/main/index.js +107 -37
- package/dist/preload/index.js +3 -2
- package/dist/renderer/assets/{arc-CPdeInCG.js → arc-CpIo2PoE.js} +1 -1
- package/dist/renderer/assets/{architectureDiagram-3BPJPVTR-BAbnaR9G.js → architectureDiagram-3BPJPVTR-T-4Cq0Bz.js} +2 -2
- package/dist/renderer/assets/{blockDiagram-GPEHLZMM-CYSWjnJg.js → blockDiagram-GPEHLZMM-C-SuR6eu.js} +4 -4
- package/dist/renderer/assets/{c4Diagram-AAUBKEIU-Rb1tstnr.js → c4Diagram-AAUBKEIU-PJp81cGm.js} +2 -2
- package/dist/renderer/assets/{channel-DpG2A6fE.js → channel-CtIHaaRI.js} +1 -1
- package/dist/renderer/assets/{chunk-2J33WTMH-DFc0Jxy_.js → chunk-2J33WTMH-BrchfQL6.js} +1 -1
- package/dist/renderer/assets/{chunk-4BX2VUAB-BhRxDTNn.js → chunk-4BX2VUAB-BCc3Ev_H.js} +1 -1
- package/dist/renderer/assets/{chunk-55IACEB6-DEgMVBk8.js → chunk-55IACEB6-B2M27HQo.js} +1 -1
- package/dist/renderer/assets/{chunk-727SXJPM-bjBIfiz8.js → chunk-727SXJPM-DXDHGECs.js} +5 -5
- package/dist/renderer/assets/{chunk-AQP2D5EJ-DwQMzTzD.js → chunk-AQP2D5EJ-BNb1lOQY.js} +3 -3
- package/dist/renderer/assets/{chunk-FMBD7UC4-CkphwJzs.js → chunk-FMBD7UC4-CzgfEH2z.js} +1 -1
- package/dist/renderer/assets/{chunk-ND2GUHAM-oU09z4y4.js → chunk-ND2GUHAM-BUFT_yOe.js} +1 -1
- package/dist/renderer/assets/{chunk-QZHKN3VN-rCbVuPBn.js → chunk-QZHKN3VN-C-zV7oBi.js} +1 -1
- package/dist/renderer/assets/{classDiagram-v2-Q7XG4LA2-DGS2faoM.js → classDiagram-4FO5ZUOK-CAyhGSvf.js} +6 -6
- package/dist/renderer/assets/{classDiagram-4FO5ZUOK-DGS2faoM.js → classDiagram-v2-Q7XG4LA2-CAyhGSvf.js} +6 -6
- package/dist/renderer/assets/{cose-bilkent-S5V4N54A-iqY6-EwA.js → cose-bilkent-S5V4N54A-ldu81kCk.js} +1 -1
- package/dist/renderer/assets/{dagre-BM42HDAG-5t3X5sDa.js → dagre-BM42HDAG-NJgy8CTw.js} +3 -3
- package/dist/renderer/assets/{diagram-2AECGRRQ-DzHiYDPh.js → diagram-2AECGRRQ-CuIcMpOn.js} +2 -2
- package/dist/renderer/assets/{diagram-5GNKFQAL-BiNv6Keq.js → diagram-5GNKFQAL-BJwFCroB.js} +3 -3
- package/dist/renderer/assets/{diagram-KO2AKTUF-ClzeDG6f.js → diagram-KO2AKTUF-C7NgQ8ju.js} +2 -2
- package/dist/renderer/assets/{diagram-LMA3HP47-CGkw7wII.js → diagram-LMA3HP47-B71v6MOq.js} +2 -2
- package/dist/renderer/assets/{diagram-OG6HWLK6-Dl-Hyk1_.js → diagram-OG6HWLK6-D2ZxkrSe.js} +3 -3
- package/dist/renderer/assets/{erDiagram-TEJ5UH35-BxUN79Qb.js → erDiagram-TEJ5UH35-4ToW0p3h.js} +4 -4
- package/dist/renderer/assets/{flowDiagram-I6XJVG4X-CzFk-KNI.js → flowDiagram-I6XJVG4X-DBkZLqwn.js} +6 -6
- package/dist/renderer/assets/{ganttDiagram-6RSMTGT7-C2xl6Igx.js → ganttDiagram-6RSMTGT7-G3xD2VXj.js} +2 -2
- package/dist/renderer/assets/{gitGraphDiagram-PVQCEYII-_fn7XCa7.js → gitGraphDiagram-PVQCEYII-BcTNiFfg.js} +3 -3
- package/dist/renderer/assets/{graph-CDoHYrHm.js → graph--Vhl4p4D.js} +1 -1
- package/dist/renderer/assets/{index-DAlXyxzt.js → index-C63bU7CF.js} +693 -162
- package/dist/renderer/assets/{index-CeFpoCKV.css → index-D8nA981z.css} +17 -6
- package/dist/renderer/assets/{infoDiagram-5YYISTIA-DL6XIxLz.js → infoDiagram-5YYISTIA-DjKa7Yv-.js} +1 -1
- package/dist/renderer/assets/{ishikawaDiagram-YF4QCWOH-BUZLjRo-.js → ishikawaDiagram-YF4QCWOH-xIWzW1pL.js} +1 -1
- package/dist/renderer/assets/{journeyDiagram-JHISSGLW-C4rH_mQM.js → journeyDiagram-JHISSGLW-DxMBkVOF.js} +4 -4
- package/dist/renderer/assets/{kanban-definition-UN3LZRKU-DRbrBcWV.js → kanban-definition-UN3LZRKU-DqJeL6E1.js} +2 -2
- package/dist/renderer/assets/{layout-DZl4n4qu.js → layout-B3giiMoK.js} +2 -2
- package/dist/renderer/assets/{linear-B0Krxg21.js → linear-Cqh3vVIf.js} +1 -1
- package/dist/renderer/assets/{mindmap-definition-RKZ34NQL-DdmPsWrn.js → mindmap-definition-RKZ34NQL-DUay02ma.js} +3 -3
- package/dist/renderer/assets/{pieDiagram-4H26LBE5-BPZLqwG0.js → pieDiagram-4H26LBE5-CVcfLtky.js} +3 -3
- package/dist/renderer/assets/{quadrantDiagram-W4KKPZXB-Dr-oWRk9.js → quadrantDiagram-W4KKPZXB-wDHffPOs.js} +2 -2
- package/dist/renderer/assets/{requirementDiagram-4Y6WPE33-B6QZd0lo.js → requirementDiagram-4Y6WPE33-C4pgGDGv.js} +3 -3
- package/dist/renderer/assets/{sankeyDiagram-5OEKKPKP-Cyl9ojEt.js → sankeyDiagram-5OEKKPKP-Jsf0rRMo.js} +1 -1
- package/dist/renderer/assets/{sequenceDiagram-3UESZ5HK-D48Yr9T6.js → sequenceDiagram-3UESZ5HK-e6QS7gt8.js} +3 -3
- package/dist/renderer/assets/{stateDiagram-AJRCARHV-qyb8ETsa.js → stateDiagram-AJRCARHV-DgYKZzDq.js} +6 -6
- package/dist/renderer/assets/{stateDiagram-v2-BHNVJYJU-DmDOyyrJ.js → stateDiagram-v2-BHNVJYJU-CUdmd_50.js} +4 -4
- package/dist/renderer/assets/{timeline-definition-PNZ67QCA-C-KQxTi1.js → timeline-definition-PNZ67QCA-S12e1Mp_.js} +2 -2
- package/dist/renderer/assets/{vennDiagram-CIIHVFJN-BdaZlnH-.js → vennDiagram-CIIHVFJN-CNDBG6A2.js} +1 -1
- package/dist/renderer/assets/{wardleyDiagram-YWT4CUSO-B2hBE-EE.js → wardleyDiagram-YWT4CUSO-CLlGQcof.js} +2 -2
- package/dist/renderer/assets/{xychartDiagram-2RQKCTM6-CSvswDTY.js → xychartDiagram-2RQKCTM6-CUtsHUQd.js} +2 -2
- package/dist/renderer/index.html +6 -2
- package/package.json +25 -1
- package/themes/README.md +18 -1
- package/themes/academic-paper-pt.css +1321 -0
- package/themes/academic-paper.css +192 -97
- package/.github/workflows/release.yml +0 -66
- package/.trae/specs/optimize-theme-loading/checklist.md +0 -20
- package/.trae/specs/optimize-theme-loading/spec.md +0 -103
- package/.trae/specs/optimize-theme-loading/tasks.md +0 -40
- package/CLAUDE.md +0 -143
- package/android/app/build/.npmkeep +0 -0
- package/android/app/build.gradle +0 -76
- package/android/app/capacitor.build.gradle +0 -24
- package/android/app/proguard-rules.pro +0 -21
- package/android/app/release.keystore +0 -0
- package/android/app/src/androidTest/java/com/getcapacitor/myapp/ExampleInstrumentedTest.java +0 -26
- package/android/app/src/main/AndroidManifest.xml +0 -64
- package/android/app/src/main/java/cn/bytechain/colamd/MainActivity.java +0 -180
- package/android/app/src/main/res/drawable/ic_launcher_background.xml +0 -170
- package/android/app/src/main/res/drawable/splash.png +0 -0
- package/android/app/src/main/res/drawable-land-hdpi/splash.png +0 -0
- package/android/app/src/main/res/drawable-land-mdpi/splash.png +0 -0
- package/android/app/src/main/res/drawable-land-xhdpi/splash.png +0 -0
- package/android/app/src/main/res/drawable-land-xxhdpi/splash.png +0 -0
- package/android/app/src/main/res/drawable-land-xxxhdpi/splash.png +0 -0
- package/android/app/src/main/res/drawable-port-hdpi/splash.png +0 -0
- package/android/app/src/main/res/drawable-port-mdpi/splash.png +0 -0
- package/android/app/src/main/res/drawable-port-xhdpi/splash.png +0 -0
- package/android/app/src/main/res/drawable-port-xxhdpi/splash.png +0 -0
- package/android/app/src/main/res/drawable-port-xxxhdpi/splash.png +0 -0
- package/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +0 -34
- package/android/app/src/main/res/layout/activity_main.xml +0 -12
- package/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +0 -5
- package/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +0 -5
- package/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png +0 -0
- package/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png +0 -0
- package/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png +0 -0
- package/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png +0 -0
- package/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png +0 -0
- package/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/android/app/src/main/res/values/ic_launcher_background.xml +0 -4
- package/android/app/src/main/res/values/strings.xml +0 -7
- package/android/app/src/main/res/values/styles.xml +0 -22
- package/android/app/src/main/res/xml/file_paths.xml +0 -5
- package/android/app/src/main/res/xml/network_security_config.xml +0 -8
- package/android/app/src/test/java/com/getcapacitor/myapp/ExampleUnitTest.java +0 -18
- package/android/build.gradle +0 -29
- package/android/capacitor.settings.gradle +0 -21
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -7
- package/android/gradle.properties +0 -22
- package/android/gradlew +0 -248
- package/android/gradlew.bat +0 -92
- package/android/settings.gradle +0 -5
- package/android/variables.gradle +0 -16
- package/bytechain.cn-colamd-1.5.1-beta.2.tgz +0 -0
- package/capacitor.config.js +0 -29
- package/capacitor.config.ts +0 -30
- package/demo.md +0 -193
- package/docs/academic-demo.md +0 -566
- package/docs/agent-diff-view.md +0 -48
- package/docs/demo.html +0 -748
- package/docs/demo.md +0 -546
- package/docs/demo.pdf +0 -0
- package/docs/theme-paradigm.md +0 -658
- package/electron-builder.yml +0 -64
- package/electron.vite.config.js +0 -31
- package/electron.vite.config.ts +0 -30
- package/ios/App/App/AppDelegate.swift +0 -49
- package/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-512@2x.png +0 -0
- package/ios/App/App/Assets.xcassets/AppIcon.appiconset/Contents.json +0 -14
- package/ios/App/App/Assets.xcassets/Contents.json +0 -6
- package/ios/App/App/Assets.xcassets/Splash.imageset/Contents.json +0 -23
- package/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732-1.png +0 -0
- package/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732-2.png +0 -0
- package/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732.png +0 -0
- package/ios/App/App/Base.lproj/LaunchScreen.storyboard +0 -32
- package/ios/App/App/Base.lproj/Main.storyboard +0 -19
- package/ios/App/App/Info.plist +0 -49
- package/ios/App/App.xcodeproj/project.pbxproj +0 -408
- package/ios/App/App.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/App/Podfile +0 -28
- package/resources/entitlements.mac.plist +0 -12
- package/resources/icon.icns +0 -0
- package/resources/icon.png +0 -0
- package/resources/icon.svg +0 -23
- package/resources/templates/slides/icon.png +0 -0
- package/resources/templates/slides/slides-template.md +0 -74
- package/resources/templates/slides/template-forest-ink.html +0 -540
- package/resources/templates/slides/template.html +0 -535
- package/scripts/afterPack.js +0 -13
- package/scripts/generate-icons.js +0 -102
- package/src/main/index.ts +0 -905
- package/src/preload/index.d.ts +0 -51
- package/src/preload/index.js +0 -70
- package/src/preload/index.ts +0 -110
- package/src/renderer/capacitor-api.ts +0 -713
- package/src/renderer/editor/editor.ts +0 -287
- package/src/renderer/editor/html-view.ts +0 -15
- package/src/renderer/editor/plugins/index.ts +0 -68
- package/src/renderer/editor/plugins/math-plugin.ts +0 -297
- package/src/renderer/editor/plugins/mermaid-plugin-custom.css +0 -46
- package/src/renderer/editor/plugins/mermaid-plugin-dark.css +0 -428
- package/src/renderer/editor/plugins/mermaid-plugin-elegant.css +0 -443
- package/src/renderer/editor/plugins/mermaid-plugin-newsprint.css +0 -208
- package/src/renderer/editor/plugins/mermaid-plugin.css +0 -111
- package/src/renderer/editor/plugins/mermaid-plugin.ts +0 -670
- package/src/renderer/editor/plugins/themes/base/dark.css +0 -23
- package/src/renderer/editor/plugins/themes/base/elegant.css +0 -32
- package/src/renderer/editor/plugins/themes/base/light.css +0 -20
- package/src/renderer/editor/plugins/themes/base/newsprint.css +0 -27
- package/src/renderer/editor/plugins/themes/base.css +0 -509
- package/src/renderer/editor/plugins/themes/components/mermaid/academic.css +0 -43
- package/src/renderer/editor/plugins/themes/components/mermaid/dark.css +0 -20
- package/src/renderer/editor/plugins/themes/components/mermaid/elegant.css +0 -24
- package/src/renderer/editor/plugins/themes/components/mermaid/light.css +0 -21
- package/src/renderer/editor/plugins/themes/components/mermaid/newsprint.css +0 -26
- package/src/renderer/editor/plugins/themes/components/mermaid/variables.css +0 -592
- package/src/renderer/editor/plugins/themes/foundation.css +0 -143
- package/src/renderer/editor/plugins/themes/theme-manager.ts +0 -92
- package/src/renderer/env.d.ts +0 -10
- package/src/renderer/index.html +0 -76
- package/src/renderer/main.ts +0 -678
- package/src/renderer/mobile.css +0 -429
- package/tsconfig.json +0 -14
- package/tsconfig.main.json +0 -12
- package/tsconfig.main.tsbuildinfo +0 -1
- package/tsconfig.preload.json +0 -12
- package/tsconfig.preload.tsbuildinfo +0 -1
- package/tsconfig.renderer.json +0 -13
- package/tsconfig.renderer.tsbuildinfo +0 -1
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,670 +0,0 @@
|
|
|
1
|
-
import { $nodeSchema, $view, $inputRule } from '@milkdown/utils'
|
|
2
|
-
import { InputRule } from '@milkdown/prose/inputrules'
|
|
3
|
-
import type { NodeViewConstructor } from '@milkdown/prose/view'
|
|
4
|
-
import type { Plugin } from 'unified'
|
|
5
|
-
import type { RendererPlugin } from './index'
|
|
6
|
-
import { registerPluginModule } from './index'
|
|
7
|
-
import mermaid from 'mermaid'
|
|
8
|
-
import './mermaid-plugin.css'
|
|
9
|
-
import './mermaid-plugin-dark.css'
|
|
10
|
-
import './mermaid-plugin-elegant.css'
|
|
11
|
-
import './mermaid-plugin-newsprint.css'
|
|
12
|
-
import './mermaid-plugin-custom.css'
|
|
13
|
-
// import './themes/components/mermaid/variables.css'
|
|
14
|
-
|
|
15
|
-
;(window as any).mermaid = mermaid
|
|
16
|
-
|
|
17
|
-
// Track pending mermaid render promises for export synchronization
|
|
18
|
-
const pendingRenders = new Set<Promise<void>>()
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Wait for all currently pending mermaid render() calls to settle.
|
|
22
|
-
* Called before PDF/HTML export to ensure all diagrams are rendered.
|
|
23
|
-
*/
|
|
24
|
-
export function awaitAllMermaidRenders(): Promise<void> {
|
|
25
|
-
const promises = Array.from(pendingRenders)
|
|
26
|
-
return Promise.allSettled(promises).then(() => {})
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function getMermaidTheme(): string {
|
|
30
|
-
const cls = document.body.className
|
|
31
|
-
if (cls.includes('theme-dark')) return 'dark'
|
|
32
|
-
if (cls.includes('theme-newsprint')) return 'neutral'
|
|
33
|
-
if (cls.includes('theme-custom')) {
|
|
34
|
-
const style = getComputedStyle(document.body)
|
|
35
|
-
if (style.getPropertyValue('--mermaid-dark-mode').trim() === 'true') return 'dark'
|
|
36
|
-
return 'base'
|
|
37
|
-
}
|
|
38
|
-
return 'default'
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function getCustomMermaidCSS(): CSSStyleDeclaration {
|
|
42
|
-
return getComputedStyle(document.body)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function readCustomVar(style: CSSStyleDeclaration, name: string, fallback: string): string {
|
|
46
|
-
return style.getPropertyValue(name).trim() || fallback
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function getCustomMermaidFontSize(): number {
|
|
50
|
-
const raw = getCustomMermaidCSS().getPropertyValue('--mermaid-font-size').trim()
|
|
51
|
-
const n = parseInt(raw, 10)
|
|
52
|
-
return Number.isFinite(n) && n > 0 ? n : 12
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function getCustomMermaidThemeVariables(): Record<string, string> {
|
|
56
|
-
const style = getCustomMermaidCSS()
|
|
57
|
-
const v = (name: string, fallback: string) => readCustomVar(style, name, fallback)
|
|
58
|
-
const baseFont = '-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif'
|
|
59
|
-
const font = v('--mermaid-font-family', baseFont)
|
|
60
|
-
const darkMode = v('--mermaid-dark-mode', 'false')
|
|
61
|
-
const result: Record<string, string> = {
|
|
62
|
-
darkMode,
|
|
63
|
-
background: v('--mermaid-background', v('--bg-color', '#ffffff')),
|
|
64
|
-
primaryColor: v('--mermaid-primary-color', v('--code-block-bg', '#f6f8fa')),
|
|
65
|
-
primaryBorderColor: v('--mermaid-node-stroke', v('--border-color', '#d0d7de')),
|
|
66
|
-
primaryTextColor: v('--mermaid-primary-text-color', v('--text-color', '#24292f')),
|
|
67
|
-
secondaryColor: v('--mermaid-secondary-color', v('--code-bg', '#f6f8fa')),
|
|
68
|
-
secondaryBorderColor: v('--mermaid-secondary-border-color', v('--border-color', '#d0d7de')),
|
|
69
|
-
secondaryTextColor: v('--mermaid-primary-text-color', v('--text-color', '#24292f')),
|
|
70
|
-
tertiaryColor: v('--mermaid-tertiary-color', v('--bg-color', '#ffffff')),
|
|
71
|
-
tertiaryBorderColor: v('--mermaid-tertiary-border-color', v('--border-color', '#d0d7de')),
|
|
72
|
-
tertiaryTextColor: v('--mermaid-tertiary-text-color', v('--text-color', '#24292f')),
|
|
73
|
-
lineColor: v('--mermaid-edge-stroke', v('--border-color', '#d0d7de')),
|
|
74
|
-
textColor: v('--mermaid-label-text', v('--text-color', '#24292f')),
|
|
75
|
-
mainBkg: v('--mermaid-main-bkg', v('--code-block-bg', '#f6f8fa')),
|
|
76
|
-
secondBkg: v('--mermaid-second-bkg', v('--code-bg', '#f6f8fa')),
|
|
77
|
-
mainContrastColor: v('--mermaid-primary-text-color', v('--text-color', '#24292f')),
|
|
78
|
-
labelBackground: v('--mermaid-label-background', v('--code-block-bg', '#f6f8fa')),
|
|
79
|
-
labelTextColor: v('--mermaid-label-text-color', v('--text-color', '#24292f')),
|
|
80
|
-
nodeBorder: v('--mermaid-node-stroke', v('--border-color', '#d0d7de')),
|
|
81
|
-
nodeBkg: v('--mermaid-node-bkg', v('--code-block-bg', '#f6f8fa')),
|
|
82
|
-
clusterBkg: v('--mermaid-cluster-bkg', v('--code-bg', '#f6f8fa')),
|
|
83
|
-
clusterBorder: v('--mermaid-cluster-stroke', v('--border-color', '#d0d7de')),
|
|
84
|
-
defaultLinkColor: v('--mermaid-edge-stroke', v('--border-color', '#d0d7de')),
|
|
85
|
-
edgeLabelBackground: v('--mermaid-edge-label-background', v('--code-block-bg', '#f6f8fa')),
|
|
86
|
-
arrowheadColor: v('--mermaid-edge-stroke', v('--border-color', '#d0d7de')),
|
|
87
|
-
personBorder: v('--mermaid-person-stroke', v('--border-color', '#d0d7de')),
|
|
88
|
-
personBkg: v('--mermaid-person-bkg', v('--code-block-bg', '#f6f8fa')),
|
|
89
|
-
fontFamily: font,
|
|
90
|
-
cScale0: v('--mermaid-cscale0', '#2d5f8a'),
|
|
91
|
-
cScale1: v('--mermaid-cscale1', '#3d7a5a'),
|
|
92
|
-
cScale2: v('--mermaid-cscale2', '#8a6b3c'),
|
|
93
|
-
cScale3: v('--mermaid-cscale3', '#6b4a7a'),
|
|
94
|
-
cScale4: v('--mermaid-cscale4', '#3c7a6b'),
|
|
95
|
-
cScale5: v('--mermaid-cscale5', '#7a4a4a'),
|
|
96
|
-
cScale6: v('--mermaid-cscale6', '#4a6b8a'),
|
|
97
|
-
cScale7: v('--mermaid-cscale7', '#5a7a3c'),
|
|
98
|
-
cScale8: v('--mermaid-cscale8', '#7a3c6b'),
|
|
99
|
-
cScale9: v('--mermaid-cscale9', '#3c8a5a'),
|
|
100
|
-
cScale10: v('--mermaid-cscale10', '#8a5a3c'),
|
|
101
|
-
cScale11: v('--mermaid-cscale11', '#3c5a8a'),
|
|
102
|
-
}
|
|
103
|
-
return result
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function getCustomMermaidC4Config(): Record<string, string> {
|
|
107
|
-
const style = getCustomMermaidCSS()
|
|
108
|
-
const v = (name: string, fallback: string) => readCustomVar(style, name, fallback)
|
|
109
|
-
const baseFont = '-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif'
|
|
110
|
-
const font = v('--mermaid-font-family', baseFont)
|
|
111
|
-
return {
|
|
112
|
-
personFontFamily: font,
|
|
113
|
-
systemFontFamily: font,
|
|
114
|
-
containerFontFamily: font,
|
|
115
|
-
componentFontFamily: font,
|
|
116
|
-
boundaryFontFamily: font,
|
|
117
|
-
messageFontFamily: font,
|
|
118
|
-
person_bg_color: v('--mermaid-c4-person-bg', '#2d5f8a'),
|
|
119
|
-
person_border_color: v('--mermaid-c4-person-stroke', '#4a7aaa'),
|
|
120
|
-
external_person_bg_color: v('--mermaid-c4-ext-person-bg', '#4a5568'),
|
|
121
|
-
external_person_border_color: v('--mermaid-c4-ext-person-stroke', '#6b7a8a'),
|
|
122
|
-
system_bg_color: v('--mermaid-c4-system-bg', '#3d7a5a'),
|
|
123
|
-
system_border_color: v('--mermaid-c4-system-stroke', '#5a9a7a'),
|
|
124
|
-
system_db_bg_color: v('--mermaid-c4-system-bg', '#3d7a5a'),
|
|
125
|
-
system_db_border_color: v('--mermaid-c4-system-stroke', '#5a9a7a'),
|
|
126
|
-
system_queue_bg_color: v('--mermaid-c4-system-bg', '#3d7a5a'),
|
|
127
|
-
system_queue_border_color: v('--mermaid-c4-system-stroke', '#5a9a7a'),
|
|
128
|
-
external_system_bg_color: v('--mermaid-c4-ext-system-bg', '#6b4a7a'),
|
|
129
|
-
external_system_border_color: v('--mermaid-c4-ext-system-stroke', '#8a6a9a'),
|
|
130
|
-
external_system_db_bg_color: v('--mermaid-c4-ext-system-bg', '#6b4a7a'),
|
|
131
|
-
external_system_db_border_color: v('--mermaid-c4-ext-system-stroke', '#8a6a9a'),
|
|
132
|
-
external_system_queue_bg_color: v('--mermaid-c4-ext-system-bg', '#6b4a7a'),
|
|
133
|
-
external_system_queue_border_color: v('--mermaid-c4-ext-system-stroke', '#8a6a9a'),
|
|
134
|
-
container_bg_color: v('--mermaid-c4-container-bg', '#8a6b3c'),
|
|
135
|
-
container_border_color: v('--mermaid-c4-container-stroke', '#aa8a5c'),
|
|
136
|
-
container_db_bg_color: v('--mermaid-c4-container-bg', '#8a6b3c'),
|
|
137
|
-
container_db_border_color: v('--mermaid-c4-container-stroke', '#aa8a5c'),
|
|
138
|
-
container_queue_bg_color: v('--mermaid-c4-container-bg', '#8a6b3c'),
|
|
139
|
-
container_queue_border_color: v('--mermaid-c4-container-stroke', '#aa8a5c'),
|
|
140
|
-
external_container_bg_color: v('--mermaid-c4-ext-container-bg', '#5a5a6a'),
|
|
141
|
-
external_container_border_color: v('--mermaid-c4-ext-container-stroke', '#7a7a8a'),
|
|
142
|
-
external_container_db_bg_color: v('--mermaid-c4-ext-container-bg', '#5a5a6a'),
|
|
143
|
-
external_container_db_border_color: v('--mermaid-c4-ext-container-stroke', '#7a7a8a'),
|
|
144
|
-
external_container_queue_bg_color: v('--mermaid-c4-ext-container-bg', '#5a5a6a'),
|
|
145
|
-
external_container_queue_border_color: v('--mermaid-c4-ext-container-stroke', '#7a7a8a'),
|
|
146
|
-
component_bg_color: v('--mermaid-c4-component-bg', '#3c7a6b'),
|
|
147
|
-
component_border_color: v('--mermaid-c4-component-stroke', '#5c9a8b'),
|
|
148
|
-
component_db_bg_color: v('--mermaid-c4-component-bg', '#3c7a6b'),
|
|
149
|
-
component_db_border_color: v('--mermaid-c4-component-stroke', '#5c9a8b'),
|
|
150
|
-
component_queue_bg_color: v('--mermaid-c4-component-bg', '#3c7a6b'),
|
|
151
|
-
component_queue_border_color: v('--mermaid-c4-component-stroke', '#5c9a8b'),
|
|
152
|
-
external_component_bg_color: v('--mermaid-c4-ext-component-bg', '#6a6a6a'),
|
|
153
|
-
external_component_border_color: v('--mermaid-c4-ext-component-stroke', '#8a8a8a'),
|
|
154
|
-
external_component_db_bg_color: v('--mermaid-c4-ext-component-bg', '#6a6a6a'),
|
|
155
|
-
external_component_db_border_color: v('--mermaid-c4-ext-component-stroke', '#8a8a8a'),
|
|
156
|
-
external_component_queue_bg_color: v('--mermaid-c4-ext-component-bg', '#6a6a6a'),
|
|
157
|
-
external_component_queue_border_color: v('--mermaid-c4-ext-component-stroke', '#8a8a8a'),
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function getMermaidThemeVariables(): Record<string, string> {
|
|
162
|
-
const cls = document.body.className
|
|
163
|
-
if (cls.includes('theme-dark')) {
|
|
164
|
-
return {
|
|
165
|
-
darkMode: 'true',
|
|
166
|
-
background: '#0d1117',
|
|
167
|
-
primaryColor: '#1c2128',
|
|
168
|
-
primaryBorderColor: '#8b949e',
|
|
169
|
-
primaryTextColor: '#e6edf3',
|
|
170
|
-
secondaryColor: '#21262d',
|
|
171
|
-
secondaryBorderColor: '#8b949e',
|
|
172
|
-
secondaryTextColor: '#e6edf3',
|
|
173
|
-
tertiaryColor: '#1c2128',
|
|
174
|
-
tertiaryBorderColor: '#8b949e',
|
|
175
|
-
tertiaryTextColor: '#e6edf3',
|
|
176
|
-
lineColor: '#8b949e',
|
|
177
|
-
textColor: '#e6edf3',
|
|
178
|
-
mainBkg: '#1c2128',
|
|
179
|
-
secondBkg: '#21262d',
|
|
180
|
-
mainContrastColor: '#e6edf3',
|
|
181
|
-
labelBackground: '#161b22',
|
|
182
|
-
labelTextColor: '#e6edf3',
|
|
183
|
-
nodeBorder: '#8b949e',
|
|
184
|
-
nodeBkg: '#1c2128',
|
|
185
|
-
clusterBkg: '#21262d',
|
|
186
|
-
clusterBorder: '#8b949e',
|
|
187
|
-
defaultLinkColor: '#8b949e',
|
|
188
|
-
edgeLabelBackground: '#161b22',
|
|
189
|
-
arrowheadColor: '#8b949e',
|
|
190
|
-
personBorder: '#8b949e',
|
|
191
|
-
personBkg: '#1c2128',
|
|
192
|
-
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif',
|
|
193
|
-
cScale0: '#2d5f8a',
|
|
194
|
-
cScale1: '#3d7a5a',
|
|
195
|
-
cScale2: '#8a6b3c',
|
|
196
|
-
cScale3: '#6b4a7a',
|
|
197
|
-
cScale4: '#3c7a6b',
|
|
198
|
-
cScale5: '#7a4a4a',
|
|
199
|
-
cScale6: '#4a6b8a',
|
|
200
|
-
cScale7: '#5a7a3c',
|
|
201
|
-
cScale8: '#7a3c6b',
|
|
202
|
-
cScale9: '#3c8a5a',
|
|
203
|
-
cScale10: '#8a5a3c',
|
|
204
|
-
cScale11: '#3c5a8a',
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (cls.includes('theme-elegant')) {
|
|
208
|
-
return {
|
|
209
|
-
darkMode: 'false',
|
|
210
|
-
background: '#e8e2db',
|
|
211
|
-
primaryColor: '#ddd5cb',
|
|
212
|
-
primaryBorderColor: '#b0a89f',
|
|
213
|
-
primaryTextColor: '#3d3530',
|
|
214
|
-
secondaryColor: '#e0d8cf',
|
|
215
|
-
secondaryBorderColor: '#c4bbb0',
|
|
216
|
-
secondaryTextColor: '#3d3530',
|
|
217
|
-
tertiaryColor: '#e8e2db',
|
|
218
|
-
tertiaryBorderColor: '#d0c8ba',
|
|
219
|
-
tertiaryTextColor: '#3d3530',
|
|
220
|
-
lineColor: '#b0a89f',
|
|
221
|
-
textColor: '#3d3530',
|
|
222
|
-
mainBkg: '#ddd5cb',
|
|
223
|
-
secondBkg: '#e0d8cf',
|
|
224
|
-
mainContrastColor: '#3d3530',
|
|
225
|
-
labelBackground: '#e8e2db',
|
|
226
|
-
labelTextColor: '#3d3530',
|
|
227
|
-
nodeBorder: '#b0a89f',
|
|
228
|
-
nodeBkg: '#ddd5cb',
|
|
229
|
-
clusterBkg: '#e0d8cf',
|
|
230
|
-
clusterBorder: '#b0a89f',
|
|
231
|
-
defaultLinkColor: '#b0a89f',
|
|
232
|
-
edgeLabelBackground: '#e8e2db',
|
|
233
|
-
arrowheadColor: '#b0a89f',
|
|
234
|
-
personBorder: '#b0a89f',
|
|
235
|
-
personBkg: '#ddd5cb',
|
|
236
|
-
fontFamily: '"LXGW WenKai", "Noto Serif SC", "Source Han Serif SC", "Songti SC", Georgia, serif',
|
|
237
|
-
cScale0: '#e8a898',
|
|
238
|
-
cScale1: '#c4b8a8',
|
|
239
|
-
cScale2: '#a8c4b8',
|
|
240
|
-
cScale3: '#c8b098',
|
|
241
|
-
cScale4: '#b8a8c4',
|
|
242
|
-
cScale5: '#98c4b0',
|
|
243
|
-
cScale6: '#d4a888',
|
|
244
|
-
cScale7: '#a8b8c8',
|
|
245
|
-
cScale8: '#c4a898',
|
|
246
|
-
cScale9: '#98b8a8',
|
|
247
|
-
cScale10: '#b8c4a8',
|
|
248
|
-
cScale11: '#a898b8',
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
if (cls.includes('theme-newsprint')) {
|
|
252
|
-
return {
|
|
253
|
-
fontFamily: '"PT Serif", Georgia, serif',
|
|
254
|
-
cScale0: '#2c5f8a',
|
|
255
|
-
cScale1: '#5a7a4a',
|
|
256
|
-
cScale2: '#8a6b3c',
|
|
257
|
-
cScale3: '#6b4a7a',
|
|
258
|
-
cScale4: '#3c7a6b',
|
|
259
|
-
cScale5: '#7a3c3c',
|
|
260
|
-
cScale6: '#4a6b8a',
|
|
261
|
-
cScale7: '#6b7a3c',
|
|
262
|
-
cScale8: '#5a3c7a',
|
|
263
|
-
cScale9: '#3c8a5a',
|
|
264
|
-
cScale10: '#8a5a3c',
|
|
265
|
-
cScale11: '#3c5a8a',
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
if (cls.includes('theme-custom')) {
|
|
269
|
-
return getCustomMermaidThemeVariables()
|
|
270
|
-
}
|
|
271
|
-
return {
|
|
272
|
-
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif',
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
function getMermaidC4Config(): Record<string, string> {
|
|
277
|
-
const cls = document.body.className
|
|
278
|
-
if (cls.includes('theme-custom')) {
|
|
279
|
-
return getCustomMermaidC4Config()
|
|
280
|
-
}
|
|
281
|
-
const font = cls.includes('theme-elegant')
|
|
282
|
-
? '"LXGW WenKai", "Noto Serif SC", Georgia, serif'
|
|
283
|
-
: cls.includes('theme-newsprint')
|
|
284
|
-
? '"PT Serif", Georgia, serif'
|
|
285
|
-
: '-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif'
|
|
286
|
-
if (cls.includes('theme-dark')) {
|
|
287
|
-
return {
|
|
288
|
-
personFontFamily: font,
|
|
289
|
-
systemFontFamily: font,
|
|
290
|
-
containerFontFamily: font,
|
|
291
|
-
componentFontFamily: font,
|
|
292
|
-
boundaryFontFamily: font,
|
|
293
|
-
messageFontFamily: font,
|
|
294
|
-
person_bg_color: '#2d5f8a',
|
|
295
|
-
person_border_color: '#4a7aaa',
|
|
296
|
-
external_person_bg_color: '#4a5568',
|
|
297
|
-
external_person_border_color: '#6b7a8a',
|
|
298
|
-
system_bg_color: '#3d7a5a',
|
|
299
|
-
system_border_color: '#5a9a7a',
|
|
300
|
-
system_db_bg_color: '#3d7a5a',
|
|
301
|
-
system_db_border_color: '#5a9a7a',
|
|
302
|
-
system_queue_bg_color: '#3d7a5a',
|
|
303
|
-
system_queue_border_color: '#5a9a7a',
|
|
304
|
-
external_system_bg_color: '#6b4a7a',
|
|
305
|
-
external_system_border_color: '#8a6a9a',
|
|
306
|
-
external_system_db_bg_color: '#6b4a7a',
|
|
307
|
-
external_system_db_border_color: '#8a6a9a',
|
|
308
|
-
external_system_queue_bg_color: '#6b4a7a',
|
|
309
|
-
external_system_queue_border_color: '#8a6a9a',
|
|
310
|
-
container_bg_color: '#8a6b3c',
|
|
311
|
-
container_border_color: '#aa8a5c',
|
|
312
|
-
container_db_bg_color: '#8a6b3c',
|
|
313
|
-
container_db_border_color: '#aa8a5c',
|
|
314
|
-
container_queue_bg_color: '#8a6b3c',
|
|
315
|
-
container_queue_border_color: '#aa8a5c',
|
|
316
|
-
external_container_bg_color: '#5a5a6a',
|
|
317
|
-
external_container_border_color: '#7a7a8a',
|
|
318
|
-
external_container_db_bg_color: '#5a5a6a',
|
|
319
|
-
external_container_db_border_color: '#7a7a8a',
|
|
320
|
-
external_container_queue_bg_color: '#5a5a6a',
|
|
321
|
-
external_container_queue_border_color: '#7a7a8a',
|
|
322
|
-
component_bg_color: '#3c7a6b',
|
|
323
|
-
component_border_color: '#5c9a8b',
|
|
324
|
-
component_db_bg_color: '#3c7a6b',
|
|
325
|
-
component_db_border_color: '#5c9a8b',
|
|
326
|
-
component_queue_bg_color: '#3c7a6b',
|
|
327
|
-
component_queue_border_color: '#5c9a8b',
|
|
328
|
-
external_component_bg_color: '#6a6a6a',
|
|
329
|
-
external_component_border_color: '#8a8a8a',
|
|
330
|
-
external_component_db_bg_color: '#6a6a6a',
|
|
331
|
-
external_component_db_border_color: '#8a8a8a',
|
|
332
|
-
external_component_queue_bg_color: '#6a6a6a',
|
|
333
|
-
external_component_queue_border_color: '#8a8a8a',
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
if (cls.includes('theme-elegant')) {
|
|
337
|
-
return {
|
|
338
|
-
personFontFamily: font,
|
|
339
|
-
systemFontFamily: font,
|
|
340
|
-
containerFontFamily: font,
|
|
341
|
-
componentFontFamily: font,
|
|
342
|
-
boundaryFontFamily: font,
|
|
343
|
-
messageFontFamily: font,
|
|
344
|
-
person_bg_color: '#c44b2b',
|
|
345
|
-
person_border_color: '#a03a1e',
|
|
346
|
-
external_person_bg_color: '#8b7b6a',
|
|
347
|
-
external_person_border_color: '#7a6a5a',
|
|
348
|
-
system_bg_color: '#5a7a6b',
|
|
349
|
-
system_border_color: '#4a6a5b',
|
|
350
|
-
system_db_bg_color: '#5a7a6b',
|
|
351
|
-
system_db_border_color: '#4a6a5b',
|
|
352
|
-
system_queue_bg_color: '#5a7a6b',
|
|
353
|
-
system_queue_border_color: '#4a6a5b',
|
|
354
|
-
external_system_bg_color: '#8b6b4a',
|
|
355
|
-
external_system_border_color: '#7a5a3a',
|
|
356
|
-
external_system_db_bg_color: '#8b6b4a',
|
|
357
|
-
external_system_db_border_color: '#7a5a3a',
|
|
358
|
-
external_system_queue_bg_color: '#8b6b4a',
|
|
359
|
-
external_system_queue_border_color: '#7a5a3a',
|
|
360
|
-
container_bg_color: '#6b5a7a',
|
|
361
|
-
container_border_color: '#5a4a6a',
|
|
362
|
-
container_db_bg_color: '#6b5a7a',
|
|
363
|
-
container_db_border_color: '#5a4a6a',
|
|
364
|
-
container_queue_bg_color: '#6b5a7a',
|
|
365
|
-
container_queue_border_color: '#5a4a6a',
|
|
366
|
-
external_container_bg_color: '#a09080',
|
|
367
|
-
external_container_border_color: '#8a7a6a',
|
|
368
|
-
external_container_db_bg_color: '#a09080',
|
|
369
|
-
external_container_db_border_color: '#8a7a6a',
|
|
370
|
-
external_container_queue_bg_color: '#a09080',
|
|
371
|
-
external_container_queue_border_color: '#8a7a6a',
|
|
372
|
-
component_bg_color: '#4a7a6b',
|
|
373
|
-
component_border_color: '#3a6a5b',
|
|
374
|
-
component_db_bg_color: '#4a7a6b',
|
|
375
|
-
component_db_border_color: '#3a6a5b',
|
|
376
|
-
component_queue_bg_color: '#4a7a6b',
|
|
377
|
-
component_queue_border_color: '#3a6a5b',
|
|
378
|
-
external_component_bg_color: '#9a8a7a',
|
|
379
|
-
external_component_border_color: '#8a7a6a',
|
|
380
|
-
external_component_db_bg_color: '#9a8a7a',
|
|
381
|
-
external_component_db_border_color: '#8a7a6a',
|
|
382
|
-
external_component_queue_bg_color: '#9a8a7a',
|
|
383
|
-
external_component_queue_border_color: '#8a7a6a',
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
return {
|
|
387
|
-
personFontFamily: font,
|
|
388
|
-
systemFontFamily: font,
|
|
389
|
-
containerFontFamily: font,
|
|
390
|
-
componentFontFamily: font,
|
|
391
|
-
boundaryFontFamily: font,
|
|
392
|
-
messageFontFamily: font,
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
let renderCounter = 0
|
|
397
|
-
|
|
398
|
-
function adjustNodeHeights(svg: SVGSVGElement): void {
|
|
399
|
-
const isCustom = document.body.className.includes('theme-custom')
|
|
400
|
-
const PAD = isCustom ? 8 : 6
|
|
401
|
-
svg.querySelectorAll('.node > rect').forEach((el) => {
|
|
402
|
-
const h = parseFloat(el.getAttribute('height') || '0')
|
|
403
|
-
if (h > 0) el.setAttribute('height', String(h + PAD))
|
|
404
|
-
})
|
|
405
|
-
svg.querySelectorAll('.label > foreignObject').forEach((el) => {
|
|
406
|
-
const h = parseFloat(el.getAttribute('height') || '0')
|
|
407
|
-
if (h > 0) el.setAttribute('height', String(h + PAD))
|
|
408
|
-
})
|
|
409
|
-
svg.querySelectorAll('.node > .label').forEach((el) => {
|
|
410
|
-
const t = el.getAttribute('transform') || ''
|
|
411
|
-
const m = t.match(/translate\(\s*([\d.]+)\s*,\s*([\d.]+)\s*\)/)
|
|
412
|
-
if (m) el.setAttribute('transform', `translate(${m[1]}, ${parseFloat(m[2]) - PAD / 2})`)
|
|
413
|
-
})
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
const remarkMermaid: Plugin = function () {
|
|
417
|
-
return (tree: any) => {
|
|
418
|
-
const walk = (node: any) => {
|
|
419
|
-
if (node.children) {
|
|
420
|
-
for (let i = 0; i < node.children.length; i++) {
|
|
421
|
-
const child = node.children[i]
|
|
422
|
-
if (child.type === 'code' && child.lang === 'mermaid') {
|
|
423
|
-
node.children[i] = {
|
|
424
|
-
type: 'mermaidCode',
|
|
425
|
-
value: child.value,
|
|
426
|
-
position: child.position,
|
|
427
|
-
}
|
|
428
|
-
} else {
|
|
429
|
-
walk(child)
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
walk(tree)
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
const mermaidBlockSchema = $nodeSchema('mermaid_block', () => ({
|
|
439
|
-
group: 'block',
|
|
440
|
-
atom: true,
|
|
441
|
-
priority: 60,
|
|
442
|
-
attrs: {
|
|
443
|
-
text: { default: '', validate: 'string' },
|
|
444
|
-
mode: { default: 'rendered' as 'rendered' | 'raw' },
|
|
445
|
-
},
|
|
446
|
-
parseDOM: [
|
|
447
|
-
{ tag: 'div.mermaid-block', getAttrs: (dom) => ({ text: (dom as HTMLElement).dataset.mermaid || '' }) },
|
|
448
|
-
{ tag: 'pre.mermaid-raw', getAttrs: (dom) => ({ text: (dom as HTMLElement).dataset.mermaid || '', mode: 'raw' }) },
|
|
449
|
-
],
|
|
450
|
-
toDOM: (node) => {
|
|
451
|
-
const container = document.createElement('div')
|
|
452
|
-
container.className = 'mermaid-block'
|
|
453
|
-
const text = (node.attrs.text as string || '').trim()
|
|
454
|
-
container.dataset.mermaid = text
|
|
455
|
-
|
|
456
|
-
if (node.attrs.mode === 'raw') {
|
|
457
|
-
const el = document.createElement('pre')
|
|
458
|
-
el.className = 'mermaid-raw'
|
|
459
|
-
el.dataset.mermaid = text
|
|
460
|
-
el.textContent = '```mermaid\n' + text + '\n```'
|
|
461
|
-
return { dom: el }
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
container.innerHTML = '<div class="mermaid-preview"><div class="mermaid-loading">Rendering...</div></div>'
|
|
465
|
-
return { dom: container }
|
|
466
|
-
},
|
|
467
|
-
parseMarkdown: {
|
|
468
|
-
match: (node) => node.type === 'mermaidCode',
|
|
469
|
-
runner: (state, node, type) => {
|
|
470
|
-
state.addNode(type, { text: (node.value as string) || '' })
|
|
471
|
-
},
|
|
472
|
-
},
|
|
473
|
-
toMarkdown: {
|
|
474
|
-
match: (node) => node.type.name === 'mermaid_block',
|
|
475
|
-
runner: (state, node) => {
|
|
476
|
-
state.addNode('code', undefined, node.attrs.text as string, { lang: 'mermaid' })
|
|
477
|
-
},
|
|
478
|
-
},
|
|
479
|
-
}))
|
|
480
|
-
|
|
481
|
-
const mermaidBlockInputRule = $inputRule((ctx) => {
|
|
482
|
-
return new InputRule(/^```mermaid[\s\n]$/, (state, _match, start, end) => {
|
|
483
|
-
const { tr } = state
|
|
484
|
-
tr.replaceWith(start, end, mermaidBlockSchema.type(ctx).create({ text: '' }))
|
|
485
|
-
return tr
|
|
486
|
-
})
|
|
487
|
-
})
|
|
488
|
-
|
|
489
|
-
function renderMermaidBlock(dom: HTMLElement, node: any, renderIdRef: { current: number }): void {
|
|
490
|
-
const text = (node.attrs.text as string || '').trim()
|
|
491
|
-
dom.dataset.mermaid = text
|
|
492
|
-
const currentRenderId = ++renderIdRef.current
|
|
493
|
-
|
|
494
|
-
dom.innerHTML = ''
|
|
495
|
-
|
|
496
|
-
if (node.attrs.mode === 'raw') {
|
|
497
|
-
const textarea = document.createElement('textarea')
|
|
498
|
-
textarea.className = 'mermaid-source'
|
|
499
|
-
textarea.dataset.mermaid = text
|
|
500
|
-
textarea.value = '```mermaid\n' + text + '\n```'
|
|
501
|
-
textarea.rows = Math.min(16, (text.match(/\n/g) || []).length + 3)
|
|
502
|
-
dom.appendChild(textarea)
|
|
503
|
-
return
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
if (!text) {
|
|
507
|
-
dom.innerHTML = '<div class="mermaid-preview"><div class="mermaid-loading">Empty diagram</div></div>'
|
|
508
|
-
return
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
const mermaidLib = (window as any).mermaid
|
|
512
|
-
if (!mermaidLib || typeof mermaidLib.render !== 'function') {
|
|
513
|
-
dom.innerHTML = '<div class="mermaid-preview"><div class="mermaid-error">Mermaid not loaded</div></div>'
|
|
514
|
-
return
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
dom.innerHTML = '<div class="mermaid-preview"><div class="mermaid-loading">Rendering...</div></div>'
|
|
518
|
-
const id = 'mermaid-' + (++renderCounter)
|
|
519
|
-
|
|
520
|
-
const renderPromise = mermaidLib.render(id, text).then((result: { svg: string; bindFunctions?: (el: Element) => void }) => {
|
|
521
|
-
if (currentRenderId !== renderIdRef.current) return
|
|
522
|
-
const preview = dom.querySelector('.mermaid-preview')
|
|
523
|
-
if (preview) {
|
|
524
|
-
preview.innerHTML = result.svg
|
|
525
|
-
const svg = preview.querySelector('svg') as SVGSVGElement | null
|
|
526
|
-
if (svg) adjustNodeHeights(svg)
|
|
527
|
-
if (result.bindFunctions) result.bindFunctions(dom)
|
|
528
|
-
}
|
|
529
|
-
}).catch((e: Error) => {
|
|
530
|
-
if (currentRenderId !== renderIdRef.current) return
|
|
531
|
-
const preview = dom.querySelector('.mermaid-preview')
|
|
532
|
-
if (preview) {
|
|
533
|
-
const msg = e.message.replace(/&/g, '&').replace(/</g, '<')
|
|
534
|
-
preview.innerHTML = '<div class="mermaid-error">Error: ' + msg + '</div>'
|
|
535
|
-
}
|
|
536
|
-
}).finally(() => { pendingRenders.delete(renderPromise) })
|
|
537
|
-
pendingRenders.add(renderPromise)
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
const mermaidBlockView = $view(mermaidBlockSchema, (_ctx): NodeViewConstructor => {
|
|
541
|
-
return (node, view, getPos) => {
|
|
542
|
-
const container = document.createElement('div')
|
|
543
|
-
container.className = 'mermaid-block'
|
|
544
|
-
const renderIdRef = { current: 0 }
|
|
545
|
-
renderMermaidBlock(container, node, renderIdRef)
|
|
546
|
-
|
|
547
|
-
container.addEventListener('focusout', (e) => {
|
|
548
|
-
const target = e.target as HTMLElement
|
|
549
|
-
if (!target.classList.contains('mermaid-source')) return
|
|
550
|
-
const rawValue = (target as HTMLTextAreaElement).value
|
|
551
|
-
const newText = rawValue.replace(/^```mermaid\s*\n?/, '').replace(/\n?\s*```$/, '').trim()
|
|
552
|
-
const pos = getPos()
|
|
553
|
-
if (pos != null && node.attrs.text !== newText) {
|
|
554
|
-
view.dispatch(view.state.tr.setNodeMarkup(pos, undefined, { ...node.attrs, text: newText }))
|
|
555
|
-
}
|
|
556
|
-
})
|
|
557
|
-
|
|
558
|
-
return {
|
|
559
|
-
dom: container,
|
|
560
|
-
update: (updatedNode) => {
|
|
561
|
-
if (updatedNode.type !== node.type) return false
|
|
562
|
-
if (updatedNode.sameMarkup(node)) return true
|
|
563
|
-
node = updatedNode
|
|
564
|
-
renderMermaidBlock(container, node, renderIdRef)
|
|
565
|
-
return true
|
|
566
|
-
},
|
|
567
|
-
stopEvent: (e) => {
|
|
568
|
-
return (e.target as HTMLElement).matches('input, textarea')
|
|
569
|
-
},
|
|
570
|
-
ignoreMutation: () => true,
|
|
571
|
-
destroy: () => { container.remove() },
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
})
|
|
575
|
-
|
|
576
|
-
function svgToPngDataUrl(svgEl: SVGSVGElement, scale = 2): Promise<string> {
|
|
577
|
-
const clone = svgEl.cloneNode(true) as SVGSVGElement
|
|
578
|
-
const vb = clone.getAttribute('viewBox')
|
|
579
|
-
let svgW = clone.getAttribute('width')
|
|
580
|
-
let svgH = clone.getAttribute('height')
|
|
581
|
-
if ((!svgW || !svgH) && vb) {
|
|
582
|
-
const parts = vb.split(/[\s,]+/)
|
|
583
|
-
if (parts.length === 4) {
|
|
584
|
-
if (!svgW) svgW = parts[2]
|
|
585
|
-
if (!svgH) svgH = parts[3]
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
if (svgW) clone.setAttribute('width', svgW)
|
|
589
|
-
if (svgH) clone.setAttribute('height', svgH)
|
|
590
|
-
clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg')
|
|
591
|
-
const svgData = new XMLSerializer().serializeToString(clone)
|
|
592
|
-
const svgBase64 = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svgData)))
|
|
593
|
-
return new Promise((resolve, reject) => {
|
|
594
|
-
const img = new Image()
|
|
595
|
-
img.onload = () => {
|
|
596
|
-
const w = img.naturalWidth || img.width || parseFloat(svgW || '0')
|
|
597
|
-
const h = img.naturalHeight || img.height || parseFloat(svgH || '0')
|
|
598
|
-
if (!w || !h) { reject(new Error('SVG image has zero dimensions')); return }
|
|
599
|
-
const canvas = document.createElement('canvas')
|
|
600
|
-
canvas.width = w * scale
|
|
601
|
-
canvas.height = h * scale
|
|
602
|
-
const ctx = canvas.getContext('2d')!
|
|
603
|
-
ctx.scale(scale, scale)
|
|
604
|
-
ctx.fillStyle = '#ffffff'
|
|
605
|
-
ctx.fillRect(0, 0, w, h)
|
|
606
|
-
ctx.drawImage(img, 0, 0)
|
|
607
|
-
resolve(canvas.toDataURL('image/png'))
|
|
608
|
-
}
|
|
609
|
-
img.onerror = () => { reject(new Error('Failed to load SVG as image')) }
|
|
610
|
-
img.src = svgBase64
|
|
611
|
-
})
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
export const mermaidPlugin: RendererPlugin = {
|
|
615
|
-
id: 'mermaid',
|
|
616
|
-
name: 'Mermaid Diagrams',
|
|
617
|
-
enabled: true,
|
|
618
|
-
remarkPlugin: { plugin: remarkMermaid, options: undefined },
|
|
619
|
-
nodeTypes: ['mermaid_block'],
|
|
620
|
-
exportCapabilities: [
|
|
621
|
-
{
|
|
622
|
-
label: 'Save Diagram as PNG',
|
|
623
|
-
defaultName: 'diagram.png',
|
|
624
|
-
filter: { name: 'PNG Image', extensions: ['png'] },
|
|
625
|
-
execute: async (element: HTMLElement): Promise<string | null> => {
|
|
626
|
-
const svg = element.querySelector('.mermaid-preview svg')
|
|
627
|
-
if (!svg) return null
|
|
628
|
-
return svgToPngDataUrl(svg as SVGSVGElement)
|
|
629
|
-
},
|
|
630
|
-
},
|
|
631
|
-
],
|
|
632
|
-
onInit: () => {
|
|
633
|
-
const cls = document.body.className
|
|
634
|
-
const isCustom = cls.includes('theme-custom')
|
|
635
|
-
const fontSize = isCustom ? getCustomMermaidFontSize() : 14
|
|
636
|
-
mermaid.initialize({
|
|
637
|
-
startOnLoad: false,
|
|
638
|
-
theme: getMermaidTheme() as any,
|
|
639
|
-
themeVariables: getMermaidThemeVariables(),
|
|
640
|
-
c4: getMermaidC4Config(),
|
|
641
|
-
securityLevel: 'loose',
|
|
642
|
-
logLevel: 'error',
|
|
643
|
-
suppressErrorRendering: true,
|
|
644
|
-
fontSize,
|
|
645
|
-
})
|
|
646
|
-
},
|
|
647
|
-
onThemeChange: () => {
|
|
648
|
-
const cls = document.body.className
|
|
649
|
-
const isCustom = cls.includes('theme-custom')
|
|
650
|
-
const fontSize = isCustom ? getCustomMermaidFontSize() : 16
|
|
651
|
-
mermaid.initialize({
|
|
652
|
-
startOnLoad: false,
|
|
653
|
-
theme: getMermaidTheme() as any,
|
|
654
|
-
themeVariables: getMermaidThemeVariables(),
|
|
655
|
-
c4: getMermaidC4Config(),
|
|
656
|
-
securityLevel: 'loose',
|
|
657
|
-
logLevel: 'error',
|
|
658
|
-
suppressErrorRendering: true,
|
|
659
|
-
fontSize,
|
|
660
|
-
})
|
|
661
|
-
},
|
|
662
|
-
ensureRendered: awaitAllMermaidRenders,
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
registerPluginModule({
|
|
666
|
-
info: mermaidPlugin,
|
|
667
|
-
milkdownPlugins: [mermaidBlockSchema, mermaidBlockInputRule, mermaidBlockView],
|
|
668
|
-
})
|
|
669
|
-
|
|
670
|
-
export { mermaidBlockSchema, mermaidBlockInputRule, mermaidBlockView, remarkMermaid }
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* ColaMD 主题系统:Dark 主题变量
|
|
3
|
-
* 依赖:foundation.css
|
|
4
|
-
*/
|
|
5
|
-
body.theme-dark {
|
|
6
|
-
--color-bg: #0d1117;
|
|
7
|
-
--color-text: #e6edf3;
|
|
8
|
-
--color-text-muted: #8b949e;
|
|
9
|
-
--color-border: #30363d;
|
|
10
|
-
--color-link: #58a6ff;
|
|
11
|
-
--color-accent: #58a6ff;
|
|
12
|
-
--color-accent-dark: #1f6feb;
|
|
13
|
-
--color-accent-light: rgba(88, 166, 255, 0.15);
|
|
14
|
-
--color-selection-bg: rgba(88, 166, 255, 0.2);
|
|
15
|
-
--code-bg: rgba(110, 118, 129, 0.3);
|
|
16
|
-
--code-block-bg: #161b22;
|
|
17
|
-
--code-block-text: #e6edf3;
|
|
18
|
-
--blockquote-border: #30363d;
|
|
19
|
-
--table-header-bg: #161b22;
|
|
20
|
-
--table-border: #30363d;
|
|
21
|
-
--scrollbar-thumb: #30363d;
|
|
22
|
-
--scrollbar-thumb-hover: #484f58;
|
|
23
|
-
}
|