@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
package/src/renderer/main.ts
DELETED
|
@@ -1,678 +0,0 @@
|
|
|
1
|
-
import { createEditor, getMarkdown, getHTML, getLiveHTML, setMarkdown, togglePluginMode } from './editor/editor'
|
|
2
|
-
import { applyTheme, loadSavedTheme, setCachedCustomTheme } from './editor/plugins/themes/theme-manager'
|
|
3
|
-
import { getAllPlugins, togglePlugin, findPluginBySelector, findExportCapabilities } from './editor/plugins'
|
|
4
|
-
import './editor/plugins/math-plugin'
|
|
5
|
-
import './editor/plugins/mermaid-plugin'
|
|
6
|
-
import { createCapacitorAPI } from './capacitor-api'
|
|
7
|
-
import './editor/plugins/themes/base.css'
|
|
8
|
-
import './mobile.css'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Show a brief toast notification. Used for save/export feedback.
|
|
12
|
-
*/
|
|
13
|
-
function showToast(message: string, duration = 2000): void {
|
|
14
|
-
const existing = document.querySelector('.cola-toast')
|
|
15
|
-
if (existing) existing.remove()
|
|
16
|
-
|
|
17
|
-
const toast = document.createElement('div')
|
|
18
|
-
toast.className = 'cola-toast'
|
|
19
|
-
toast.textContent = message
|
|
20
|
-
toast.style.cssText =
|
|
21
|
-
'position:fixed;top:56px;left:50%;transform:translateX(-50%);' +
|
|
22
|
-
'background:rgba(0,0,0,0.8);color:#fff;padding:10px 20px;' +
|
|
23
|
-
'border-radius:8px;font-size:14px;z-index:9999;pointer-events:none;'
|
|
24
|
-
document.body.appendChild(toast)
|
|
25
|
-
|
|
26
|
-
setTimeout(() => {
|
|
27
|
-
toast.style.opacity = '0'
|
|
28
|
-
toast.style.transition = 'opacity 0.3s'
|
|
29
|
-
setTimeout(() => toast.remove(), 300)
|
|
30
|
-
}, duration)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 调用原生桥接层检查是否有通过文件管理器 Intent 待打开的文件。
|
|
35
|
-
* 使用 pull 模式:JS 主动向 Java 查询,避免注入时序问题。
|
|
36
|
-
*/
|
|
37
|
-
function checkAndOpenPendingFile(api?: any): void {
|
|
38
|
-
const bridge = (window as any).ColaMDNative
|
|
39
|
-
if (!bridge || typeof bridge.checkPendingFile !== 'function') return
|
|
40
|
-
try {
|
|
41
|
-
const result = bridge.checkPendingFile()
|
|
42
|
-
if (result && result !== 'null') {
|
|
43
|
-
const data = JSON.parse(result)
|
|
44
|
-
if (data && data.content) {
|
|
45
|
-
setContent(data.content)
|
|
46
|
-
if (data.name && api?.setCurrentFile) {
|
|
47
|
-
api.setCurrentFile(data.name)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
} catch (e) { /* ignore */ }
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 轮询原生桥接层,获取待打开的文件。
|
|
56
|
-
* Android onNewIntent 在 WebView 重载前触发,需要轮询等待。
|
|
57
|
-
*/
|
|
58
|
-
function processPendingIntentFile(api?: any): void {
|
|
59
|
-
checkAndOpenPendingFile(api)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Eagerly load all plugin modules for side-effect registration (registerPluginModule)
|
|
63
|
-
const _pluginRegistry = import.meta.glob<{ default?: unknown }>('./editor/plugins/*-plugin.ts', { eager: true })
|
|
64
|
-
Object.keys(_pluginRegistry)
|
|
65
|
-
|
|
66
|
-
/** Call ensureRendered on all enabled plugins that support it. Used before export. */
|
|
67
|
-
async function ensureAllPluginsRendered(): Promise<void> {
|
|
68
|
-
for (const p of getAllPlugins()) {
|
|
69
|
-
if (p.enabled && p.ensureRendered) await p.ensureRendered()
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** Re-render nodes of plugins that react to theme changes (e.g. mermaid). */
|
|
74
|
-
function refreshThemeSensitivePlugins(): void {
|
|
75
|
-
for (const p of getAllPlugins()) {
|
|
76
|
-
if (p.enabled && p.nodeTypes && p.onThemeChange) {
|
|
77
|
-
togglePluginMode(p.nodeTypes, 'raw')
|
|
78
|
-
requestAnimationFrame(() => togglePluginMode(p.nodeTypes, 'rendered'))
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function isSlidesContent(content: string): boolean {
|
|
84
|
-
return /^---\s*\n[\s\S]*?(kicker|chip):/m.test(content)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
let sourceModeActive = false
|
|
88
|
-
const editorEl = () => document.getElementById('editor') as HTMLElement
|
|
89
|
-
const sourceEl = () => document.getElementById('source-editor') as HTMLTextAreaElement
|
|
90
|
-
const slidesBtnEl = () => document.getElementById('slides-btn') as HTMLButtonElement
|
|
91
|
-
|
|
92
|
-
function enterSourceMode(content: string): void {
|
|
93
|
-
sourceModeActive = true
|
|
94
|
-
editorEl().classList.add('hidden')
|
|
95
|
-
const ta = sourceEl()
|
|
96
|
-
ta.classList.add('visible')
|
|
97
|
-
ta.value = content
|
|
98
|
-
slidesBtnEl().classList.add('visible')
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function exitSourceMode(): void {
|
|
102
|
-
sourceModeActive = false
|
|
103
|
-
editorEl().classList.remove('hidden')
|
|
104
|
-
sourceEl().classList.remove('visible')
|
|
105
|
-
slidesBtnEl().classList.remove('visible')
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function setContent(content: string): void {
|
|
109
|
-
if (isSlidesContent(content)) {
|
|
110
|
-
enterSourceMode(content)
|
|
111
|
-
} else {
|
|
112
|
-
exitSourceMode()
|
|
113
|
-
setMarkdown(content)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function getContent(): string {
|
|
118
|
-
if (sourceModeActive) return sourceEl().value
|
|
119
|
-
return getMarkdown()
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function syncRawEdits(): void {
|
|
123
|
-
document.querySelectorAll('.math-block-raw, .math-inline-raw, .mermaid-source').forEach((el) => {
|
|
124
|
-
if ((el as HTMLElement).matches(':focus')) (el as HTMLElement).blur()
|
|
125
|
-
})
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function restoreRenderedMode(api: any): void {
|
|
129
|
-
for (const p of getAllPlugins()) {
|
|
130
|
-
if (!p.enabled) {
|
|
131
|
-
p.enabled = true
|
|
132
|
-
togglePluginMode(p.nodeTypes || [], 'rendered')
|
|
133
|
-
api.syncPluginState(p.id, true)
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async function init(): Promise<void> {
|
|
139
|
-
const api = window.electronAPI || await createCapacitorAPI()
|
|
140
|
-
|
|
141
|
-
let editorReady = false
|
|
142
|
-
let pendingFileContent: string | null = null
|
|
143
|
-
|
|
144
|
-
// Register file-open listener AS EARLY AS POSSIBLE
|
|
145
|
-
api.onFileOpened((data) => {
|
|
146
|
-
if (editorReady) {
|
|
147
|
-
setContent(data.content)
|
|
148
|
-
} else {
|
|
149
|
-
pendingFileContent = data.content
|
|
150
|
-
}
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
let savedTheme = loadSavedTheme()
|
|
154
|
-
|
|
155
|
-
try {
|
|
156
|
-
if (savedTheme.startsWith('custom:')) {
|
|
157
|
-
const fileName = savedTheme.slice(7)
|
|
158
|
-
const css = await api.loadThemeCSS(fileName)
|
|
159
|
-
if (css) {
|
|
160
|
-
setCachedCustomTheme(fileName, css)
|
|
161
|
-
applyTheme(savedTheme)
|
|
162
|
-
} else {
|
|
163
|
-
applyTheme('elegant')
|
|
164
|
-
}
|
|
165
|
-
} else {
|
|
166
|
-
applyTheme(savedTheme)
|
|
167
|
-
}
|
|
168
|
-
} catch (e) {
|
|
169
|
-
console.error('Theme initialization failed, falling back to elegant:', e)
|
|
170
|
-
applyTheme('elegant')
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
try {
|
|
174
|
-
await createEditor('editor')
|
|
175
|
-
} catch (e) {
|
|
176
|
-
console.error('Editor initialization failed:', e)
|
|
177
|
-
}
|
|
178
|
-
editorReady = true
|
|
179
|
-
|
|
180
|
-
if (pendingFileContent !== null) {
|
|
181
|
-
setContent(pendingFileContent)
|
|
182
|
-
pendingFileContent = null
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
for (const p of getAllPlugins()) p.onInit?.()
|
|
186
|
-
checkAndOpenPendingFile(api)
|
|
187
|
-
|
|
188
|
-
api.registerPlugins(getAllPlugins().map((p) => ({ id: p.id, name: p.name, enabled: p.enabled })))
|
|
189
|
-
|
|
190
|
-
api.onMenuTogglePlugin((id) => {
|
|
191
|
-
const p = getAllPlugins().find((x) => x.id === id)
|
|
192
|
-
if (p) {
|
|
193
|
-
togglePlugin(id, !p.enabled)
|
|
194
|
-
const mode = p.enabled ? 'rendered' : 'raw'
|
|
195
|
-
togglePluginMode(p.nodeTypes || [], mode)
|
|
196
|
-
api.syncPluginState(p.id, p.enabled)
|
|
197
|
-
}
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
// ─── Mobile menu setup ───
|
|
201
|
-
setupMobileMenu(api, savedTheme)
|
|
202
|
-
|
|
203
|
-
// Continuously check for Intent files (Android only, APP already running)
|
|
204
|
-
if (!window.electronAPI) {
|
|
205
|
-
setInterval(() => processPendingIntentFile(api), 3000)
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Slides button — open as slides
|
|
209
|
-
slidesBtnEl().addEventListener('click', () => api.openAsSlides(getContent()))
|
|
210
|
-
|
|
211
|
-
api.onMenuOpen(async () => {
|
|
212
|
-
const result = await api.openFile()
|
|
213
|
-
if (result) setContent(result.content)
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
api.onMenuSave(async () => {
|
|
217
|
-
syncRawEdits()
|
|
218
|
-
const ok = await api.saveFile(getContent())
|
|
219
|
-
if (ok) {
|
|
220
|
-
showToast('Saved')
|
|
221
|
-
restoreRenderedMode(api)
|
|
222
|
-
} else {
|
|
223
|
-
showToast('Save failed')
|
|
224
|
-
}
|
|
225
|
-
})
|
|
226
|
-
api.onMenuSaveAs(async () => {
|
|
227
|
-
syncRawEdits()
|
|
228
|
-
const ok = await api.saveFileAs(getContent())
|
|
229
|
-
if (ok) {
|
|
230
|
-
showToast('Saved')
|
|
231
|
-
restoreRenderedMode(api)
|
|
232
|
-
} else {
|
|
233
|
-
showToast('Save cancelled or failed')
|
|
234
|
-
}
|
|
235
|
-
})
|
|
236
|
-
api.onMenuExportPDF(async () => {
|
|
237
|
-
syncRawEdits()
|
|
238
|
-
restoreRenderedMode(api)
|
|
239
|
-
await ensureAllPluginsRendered()
|
|
240
|
-
await new Promise(r => setTimeout(r, 300))
|
|
241
|
-
await api.exportPDF(buildExportHTML())
|
|
242
|
-
setTimeout(() => {
|
|
243
|
-
document.querySelectorAll('.mermaid-loading, .mermaid-error')
|
|
244
|
-
.forEach(el => (el as HTMLElement).style.display = 'none')
|
|
245
|
-
}, 1000)
|
|
246
|
-
})
|
|
247
|
-
api.onMenuExportHTML(async () => {
|
|
248
|
-
syncRawEdits()
|
|
249
|
-
restoreRenderedMode(api)
|
|
250
|
-
await ensureAllPluginsRendered()
|
|
251
|
-
await new Promise(r => setTimeout(r, 200))
|
|
252
|
-
|
|
253
|
-
const s = getComputedStyle(document.body)
|
|
254
|
-
const v = (name: string) => s.getPropertyValue(name).trim()
|
|
255
|
-
const bgColor = v('--bg-color')
|
|
256
|
-
const textColor = v('--text-color')
|
|
257
|
-
const textMuted = v('--text-muted')
|
|
258
|
-
const borderColor = v('--border-color')
|
|
259
|
-
const linkColor = v('--link-color')
|
|
260
|
-
const codeBg = v('--code-bg')
|
|
261
|
-
const codeBlockBg = v('--code-block-bg')
|
|
262
|
-
const codeBlockText = v('--code-block-text') || textColor
|
|
263
|
-
const mermaidBg = v('--mermaid-background') || bgColor
|
|
264
|
-
const blockquoteBorder = v('--blockquote-border')
|
|
265
|
-
const blockquoteBg = v('--blockquote-bg') || 'transparent'
|
|
266
|
-
const tableHeaderBg = v('--table-header-bg')
|
|
267
|
-
const selectionBg = v('--selection-bg')
|
|
268
|
-
|
|
269
|
-
const editor = document.querySelector('#editor .ProseMirror')
|
|
270
|
-
const fontFamily = editor ? getComputedStyle(editor).fontFamily : '-apple-system,BlinkMacSystemFont,sans-serif'
|
|
271
|
-
|
|
272
|
-
const getElColor = (selector: string, fallback: string): string => {
|
|
273
|
-
const el = document.querySelector(`#editor .ProseMirror ${selector}`)
|
|
274
|
-
return el ? getComputedStyle(el).color : fallback
|
|
275
|
-
}
|
|
276
|
-
const strongColor = getElColor('strong', textColor)
|
|
277
|
-
const codeColor = getElColor('code', textColor)
|
|
278
|
-
|
|
279
|
-
const html = `<!DOCTYPE html>
|
|
280
|
-
<html><head><meta charset="utf-8"><title>ColaMD Export</title>
|
|
281
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.46/dist/katex.min.css">
|
|
282
|
-
<style>
|
|
283
|
-
body{max-width:780px;margin:40px auto;padding:20px;font-family:${fontFamily};line-height:1.75;background:${bgColor};color:${textColor}}
|
|
284
|
-
h1{font-size:2em;font-weight:700;border-bottom:1px solid ${borderColor};padding-bottom:.3em}
|
|
285
|
-
h2{font-size:1.5em;font-weight:600;border-bottom:1px solid ${borderColor};padding-bottom:.25em}
|
|
286
|
-
h3{font-size:1.25em;font-weight:600}
|
|
287
|
-
strong{color:${strongColor}}
|
|
288
|
-
a{color:${linkColor};text-decoration:none}
|
|
289
|
-
code{background:${codeBg};color:${codeColor};padding:2px 6px;border-radius:3px;font-size:.875em;font-family:'SF Mono','Fira Code',Menlo,monospace}
|
|
290
|
-
pre{background:${codeBlockBg};color:${codeBlockText};padding:16px;border-radius:6px;overflow-x:auto;margin:1em 0}
|
|
291
|
-
pre code{background:none;padding:0;color:inherit}
|
|
292
|
-
blockquote{border-left:4px solid ${blockquoteBorder};background:${blockquoteBg};padding-left:16px;margin:1em 0;color:${textMuted}}
|
|
293
|
-
table{border-collapse:collapse;width:100%;margin:1em 0}
|
|
294
|
-
th,td{border:1px solid ${borderColor};padding:8px 12px}
|
|
295
|
-
th{background:${tableHeaderBg};font-weight:600}
|
|
296
|
-
hr{border:none;border-top:2px solid ${borderColor};margin:2em 0}
|
|
297
|
-
img{max-width:100%}
|
|
298
|
-
::selection{background:${selectionBg}}
|
|
299
|
-
.math-inline{display:inline;padding:2px 4px;border-radius:3px;background:${mermaidBg}}
|
|
300
|
-
.math-block{display:block;padding:16px;margin:1em 0;border-radius:6px;background:${mermaidBg};text-align:center;overflow-x:auto}
|
|
301
|
-
.mermaid-block{display:block;padding:16px;margin:1em 0;border-radius:6px;background:${mermaidBg};border:1px solid ${borderColor}}
|
|
302
|
-
.mermaid-preview{display:flex;justify-content:center;align-items:center}
|
|
303
|
-
.mermaid-preview svg{max-width:100%;height:auto}
|
|
304
|
-
.mermaid-preview svg .label text,.mermaid-preview svg .nodeLabel text,.mermaid-preview svg .state-title,.mermaid-preview svg .state-description,.mermaid-preview svg .pieTitleText,.mermaid-preview svg .titleText{transform:translateY(-2px)}.mermaid-preview svg .nodeLabel,.mermaid-preview svg .edgeLabel{display:inline-block;position:relative;top:-2px}
|
|
305
|
-
</style>
|
|
306
|
-
</head><body>${getLiveHTML()}</body></html>`
|
|
307
|
-
api.exportHTML(html)
|
|
308
|
-
})
|
|
309
|
-
|
|
310
|
-
api.onNewFile(() => { exitSourceMode(); setMarkdown('') })
|
|
311
|
-
api.onFileChanged((content) => {
|
|
312
|
-
if (sourceModeActive) {
|
|
313
|
-
sourceEl().value = content
|
|
314
|
-
} else {
|
|
315
|
-
setMarkdown(content)
|
|
316
|
-
}
|
|
317
|
-
})
|
|
318
|
-
let pendingThemeChange: string | null = null
|
|
319
|
-
let themeChangeTimer: ReturnType<typeof setTimeout> | null = null
|
|
320
|
-
|
|
321
|
-
function applyThemeChange(theme: string): void {
|
|
322
|
-
pendingThemeChange = null
|
|
323
|
-
applyTheme(theme)
|
|
324
|
-
for (const p of getAllPlugins()) p.onThemeChange?.(theme)
|
|
325
|
-
refreshThemeSensitivePlugins()
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
api.onSetTheme((theme) => {
|
|
329
|
-
if (themeChangeTimer) clearTimeout(themeChangeTimer)
|
|
330
|
-
pendingThemeChange = theme
|
|
331
|
-
themeChangeTimer = setTimeout(() => {
|
|
332
|
-
if (pendingThemeChange) applyThemeChange(pendingThemeChange)
|
|
333
|
-
}, 50)
|
|
334
|
-
})
|
|
335
|
-
api.onSetCustomCSS((css) => {
|
|
336
|
-
const theme = pendingThemeChange || loadSavedTheme()
|
|
337
|
-
applyTheme(theme, css)
|
|
338
|
-
})
|
|
339
|
-
|
|
340
|
-
api.onMenuNewSlides(async () => {
|
|
341
|
-
await api.newSlides()
|
|
342
|
-
})
|
|
343
|
-
|
|
344
|
-
api.onNewSlidesContent((content) => {
|
|
345
|
-
enterSourceMode(content)
|
|
346
|
-
})
|
|
347
|
-
|
|
348
|
-
api.onMenuOpenAsSlides(async () => {
|
|
349
|
-
await api.openAsSlides(getContent())
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
api.onMenuExportSlides(async () => {
|
|
353
|
-
await api.exportSlides(getContent())
|
|
354
|
-
})
|
|
355
|
-
|
|
356
|
-
api.onMenuImportTheme(async () => {
|
|
357
|
-
const result = await api.loadCustomTheme()
|
|
358
|
-
if (result) {
|
|
359
|
-
setCachedCustomTheme(result.name, result.css)
|
|
360
|
-
applyTheme(`custom:${result.name}`)
|
|
361
|
-
}
|
|
362
|
-
})
|
|
363
|
-
|
|
364
|
-
const agentDot = document.getElementById('agent-dot')
|
|
365
|
-
api.onAgentActivity((state) => {
|
|
366
|
-
if (agentDot) agentDot.className = state === 'idle' ? '' : state
|
|
367
|
-
})
|
|
368
|
-
|
|
369
|
-
// --- Export via plugin capabilities (context menu) ---
|
|
370
|
-
let exportTarget: HTMLElement | null = null
|
|
371
|
-
let exportCapability: import('./editor/plugins').ExportCapability | null = null
|
|
372
|
-
let contextMenu: HTMLDivElement | null = null
|
|
373
|
-
|
|
374
|
-
function getContextMenu(): HTMLDivElement {
|
|
375
|
-
if (!contextMenu) {
|
|
376
|
-
contextMenu = document.createElement('div')
|
|
377
|
-
contextMenu.id = 'cola-context-menu'
|
|
378
|
-
document.body.appendChild(contextMenu)
|
|
379
|
-
}
|
|
380
|
-
return contextMenu
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
function hideContextMenu(): void {
|
|
384
|
-
if (contextMenu) contextMenu.style.display = 'none'
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
async function executeExport(cap: import('./editor/plugins').ExportCapability): Promise<void> {
|
|
388
|
-
const target = exportTarget
|
|
389
|
-
if (!target) return
|
|
390
|
-
hideContextMenu()
|
|
391
|
-
try {
|
|
392
|
-
const dataUrl = await cap.execute(target)
|
|
393
|
-
if (!dataUrl) return
|
|
394
|
-
await api.exportFile(dataUrl, cap.defaultName)
|
|
395
|
-
} catch (err) {
|
|
396
|
-
console.error('Export failed:', err)
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
document.addEventListener('contextmenu', (e) => {
|
|
401
|
-
if ((e.target as Element).matches('textarea, input, [contenteditable="true"]')) return
|
|
402
|
-
const target = (e.target as Element).closest('.mermaid-block, .math-block') as HTMLElement | null
|
|
403
|
-
if (!target) return
|
|
404
|
-
const capabilities = findExportCapabilities(target.className)
|
|
405
|
-
if (!capabilities.length) return
|
|
406
|
-
e.preventDefault()
|
|
407
|
-
exportTarget = target
|
|
408
|
-
|
|
409
|
-
const menu = getContextMenu()
|
|
410
|
-
menu.innerHTML = capabilities.map((cap) =>
|
|
411
|
-
`<div class="cola-menu-item" data-export="${cap.label}">${cap.label}</div>`
|
|
412
|
-
).join('')
|
|
413
|
-
menu.style.left = e.clientX + 'px'
|
|
414
|
-
menu.style.top = e.clientY + 'px'
|
|
415
|
-
menu.style.display = 'block'
|
|
416
|
-
|
|
417
|
-
menu.querySelectorAll('.cola-menu-item').forEach((item) => {
|
|
418
|
-
item.addEventListener('click', (ev) => {
|
|
419
|
-
ev.preventDefault()
|
|
420
|
-
ev.stopPropagation()
|
|
421
|
-
const cap = capabilities.find((c) => c.label === (ev.target as HTMLElement).dataset.export)
|
|
422
|
-
if (cap) executeExport(cap)
|
|
423
|
-
})
|
|
424
|
-
})
|
|
425
|
-
})
|
|
426
|
-
|
|
427
|
-
document.addEventListener('mousedown', (e) => {
|
|
428
|
-
if (contextMenu && !contextMenu.contains(e.target as Node)) {
|
|
429
|
-
hideContextMenu()
|
|
430
|
-
}
|
|
431
|
-
}, true)
|
|
432
|
-
|
|
433
|
-
document.addEventListener('dragover', (e) => e.preventDefault())
|
|
434
|
-
document.addEventListener('drop', async (e) => {
|
|
435
|
-
e.preventDefault()
|
|
436
|
-
const file = e.dataTransfer?.files[0]
|
|
437
|
-
if (!file) return
|
|
438
|
-
const filePath = api.getPathForFile(file)
|
|
439
|
-
if (!filePath) return
|
|
440
|
-
const result = await api.openFilePath(filePath)
|
|
441
|
-
if (result) setContent(result.content)
|
|
442
|
-
})
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* 初始化移动端侧边栏菜单的交互逻辑。
|
|
447
|
-
* 包括菜单开关、主题切换、插件开关、文件操作等。
|
|
448
|
-
* @param api 平台 API(Electron 或 Capacitor)
|
|
449
|
-
* @param currentTheme 当前激活的主题名称
|
|
450
|
-
*/
|
|
451
|
-
function setupMobileMenu(api: any, currentTheme: string): void {
|
|
452
|
-
const menuEl = document.getElementById('mobile-menu')!
|
|
453
|
-
const menuBtn = document.getElementById('menu-btn')!
|
|
454
|
-
const closeBtn = document.getElementById('menu-close-btn')
|
|
455
|
-
const overlay = document.getElementById('menu-overlay')
|
|
456
|
-
if (!menuEl || !menuBtn) return
|
|
457
|
-
|
|
458
|
-
function openMenu(): void {
|
|
459
|
-
menuEl.classList.add('open')
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
function closeMenu(): void {
|
|
463
|
-
menuEl.classList.remove('open')
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
menuBtn.addEventListener('click', openMenu)
|
|
467
|
-
closeBtn?.addEventListener('click', closeMenu)
|
|
468
|
-
overlay?.addEventListener('click', closeMenu)
|
|
469
|
-
|
|
470
|
-
// 主题列表
|
|
471
|
-
const themes = [
|
|
472
|
-
{ key: 'light', label: 'Light' },
|
|
473
|
-
{ key: 'dark', label: 'Dark' },
|
|
474
|
-
{ key: 'elegant', label: 'Elegant' },
|
|
475
|
-
{ key: 'newsprint', label: 'Newsprint' },
|
|
476
|
-
]
|
|
477
|
-
|
|
478
|
-
const themeListEl = document.getElementById('menu-theme-list')
|
|
479
|
-
if (themeListEl) {
|
|
480
|
-
themeListEl.innerHTML = themes.map((t) =>
|
|
481
|
-
`<div class="menu-theme-item${t.key === currentTheme ? ' active' : ''}" data-theme="${t.key}">${t.label}</div>`
|
|
482
|
-
).join('')
|
|
483
|
-
|
|
484
|
-
themeListEl.querySelectorAll('.menu-theme-item').forEach((el) => {
|
|
485
|
-
el.addEventListener('click', () => {
|
|
486
|
-
const theme = (el as HTMLElement).dataset.theme!
|
|
487
|
-
applyTheme(theme)
|
|
488
|
-
for (const p of getAllPlugins()) p.onThemeChange?.(theme)
|
|
489
|
-
refreshThemeSensitivePlugins()
|
|
490
|
-
themeListEl.querySelectorAll('.menu-theme-item').forEach((e) => e.classList.remove('active'))
|
|
491
|
-
el.classList.add('active')
|
|
492
|
-
closeMenu()
|
|
493
|
-
})
|
|
494
|
-
})
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
// 插件列表
|
|
498
|
-
const pluginsSection = document.getElementById('menu-plugins-section')
|
|
499
|
-
const pluginListEl = document.getElementById('menu-plugin-list')
|
|
500
|
-
const plugins = getAllPlugins()
|
|
501
|
-
if (pluginsSection && pluginListEl && plugins.length > 0) {
|
|
502
|
-
pluginsSection.style.display = ''
|
|
503
|
-
pluginListEl.innerHTML = plugins.map((p) =>
|
|
504
|
-
`<div class="menu-plugin-item" data-plugin-id="${p.id}"><span>${p.name}</span><div class="menu-plugin-toggle${p.enabled ? ' on' : ''}"></div></div>`
|
|
505
|
-
).join('')
|
|
506
|
-
|
|
507
|
-
pluginListEl.querySelectorAll('.menu-plugin-item').forEach((el) => {
|
|
508
|
-
el.addEventListener('click', () => {
|
|
509
|
-
const id = (el as HTMLElement).dataset.pluginId!
|
|
510
|
-
const p = getAllPlugins().find((x) => x.id === id)
|
|
511
|
-
if (p) {
|
|
512
|
-
togglePlugin(id, !p.enabled)
|
|
513
|
-
const mode = p.enabled ? 'rendered' : 'raw'
|
|
514
|
-
togglePluginMode(p.nodeTypes || [], mode)
|
|
515
|
-
api.syncPluginState(p.id, p.enabled)
|
|
516
|
-
const toggle = el.querySelector('.menu-plugin-toggle')
|
|
517
|
-
toggle?.classList.toggle('on', p.enabled)
|
|
518
|
-
}
|
|
519
|
-
})
|
|
520
|
-
})
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
// 菜单操作按钮
|
|
524
|
-
menuEl.querySelectorAll('.menu-item').forEach((el) => {
|
|
525
|
-
el.addEventListener('click', async () => {
|
|
526
|
-
const action = (el as HTMLElement).dataset.action
|
|
527
|
-
if (!action) return
|
|
528
|
-
closeMenu()
|
|
529
|
-
|
|
530
|
-
switch (action) {
|
|
531
|
-
case 'new':
|
|
532
|
-
exitSourceMode()
|
|
533
|
-
setMarkdown('')
|
|
534
|
-
break
|
|
535
|
-
case 'open': {
|
|
536
|
-
const result = await api.openFile()
|
|
537
|
-
if (result) setContent(result.content)
|
|
538
|
-
break
|
|
539
|
-
}
|
|
540
|
-
case 'save':
|
|
541
|
-
syncRawEdits()
|
|
542
|
-
{
|
|
543
|
-
const ok = await api.saveFile(getContent())
|
|
544
|
-
if (ok) {
|
|
545
|
-
showToast('Saved')
|
|
546
|
-
restoreRenderedMode(api)
|
|
547
|
-
} else {
|
|
548
|
-
showToast('Save failed')
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
break
|
|
552
|
-
case 'save-as':
|
|
553
|
-
syncRawEdits()
|
|
554
|
-
{
|
|
555
|
-
const ok = await api.saveFileAs(getContent())
|
|
556
|
-
if (ok) {
|
|
557
|
-
showToast('Saved')
|
|
558
|
-
restoreRenderedMode(api)
|
|
559
|
-
} else {
|
|
560
|
-
showToast('Save cancelled or failed')
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
break
|
|
564
|
-
case 'export-pdf':
|
|
565
|
-
syncRawEdits()
|
|
566
|
-
restoreRenderedMode(api)
|
|
567
|
-
await ensureAllPluginsRendered()
|
|
568
|
-
await new Promise(r => setTimeout(r, 300))
|
|
569
|
-
await api.exportPDF(buildExportHTML())
|
|
570
|
-
setTimeout(() => {
|
|
571
|
-
document.querySelectorAll('.mermaid-loading, .mermaid-error')
|
|
572
|
-
.forEach(el => (el as HTMLElement).style.display = 'none')
|
|
573
|
-
}, 1000)
|
|
574
|
-
break
|
|
575
|
-
case 'export-html':
|
|
576
|
-
syncRawEdits()
|
|
577
|
-
restoreRenderedMode(api)
|
|
578
|
-
await ensureAllPluginsRendered()
|
|
579
|
-
await new Promise(r => setTimeout(r, 200))
|
|
580
|
-
api.exportHTML(buildExportHTML())
|
|
581
|
-
break
|
|
582
|
-
case 'export-slides':
|
|
583
|
-
await api.exportSlides(getContent())
|
|
584
|
-
break
|
|
585
|
-
case 'new-slides': {
|
|
586
|
-
const template = await api.newSlides()
|
|
587
|
-
if (template) enterSourceMode(template)
|
|
588
|
-
break
|
|
589
|
-
}
|
|
590
|
-
case 'open-as-slides':
|
|
591
|
-
await api.openAsSlides(getContent())
|
|
592
|
-
break
|
|
593
|
-
case 'import-theme': {
|
|
594
|
-
const result = await api.loadCustomTheme()
|
|
595
|
-
if (result) {
|
|
596
|
-
setCachedCustomTheme(result.name, result.css)
|
|
597
|
-
applyTheme(`custom:${result.name}`)
|
|
598
|
-
}
|
|
599
|
-
break
|
|
600
|
-
}
|
|
601
|
-
case 'about':
|
|
602
|
-
api.openExternal('https://github.com/byteuser1977/ColaMD-extend')
|
|
603
|
-
break
|
|
604
|
-
case 'exit':
|
|
605
|
-
try {
|
|
606
|
-
const { App } = await import('@capacitor/app')
|
|
607
|
-
await App.exitApp()
|
|
608
|
-
} catch {
|
|
609
|
-
window.close()
|
|
610
|
-
}
|
|
611
|
-
break
|
|
612
|
-
}
|
|
613
|
-
})
|
|
614
|
-
})
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
/**
|
|
618
|
-
* 构建导出用的 HTML 字符串,包含当前主题样式。
|
|
619
|
-
* @returns 完整的 HTML 文档字符串
|
|
620
|
-
*/
|
|
621
|
-
function buildExportHTML(): string {
|
|
622
|
-
const s = getComputedStyle(document.body)
|
|
623
|
-
const v = (name: string) => s.getPropertyValue(name).trim()
|
|
624
|
-
const bgColor = v('--bg-color')
|
|
625
|
-
const textColor = v('--text-color')
|
|
626
|
-
const textMuted = v('--text-muted')
|
|
627
|
-
const borderColor = v('--border-color')
|
|
628
|
-
const linkColor = v('--link-color')
|
|
629
|
-
const codeBg = v('--code-bg')
|
|
630
|
-
const codeBlockBg = v('--code-block-bg')
|
|
631
|
-
const codeBlockText = v('--code-block-text') || textColor
|
|
632
|
-
const mermaidBg = v('--mermaid-background') || bgColor
|
|
633
|
-
const blockquoteBorder = v('--blockquote-border')
|
|
634
|
-
const blockquoteBg = v('--blockquote-bg') || 'transparent'
|
|
635
|
-
const tableHeaderBg = v('--table-header-bg')
|
|
636
|
-
const selectionBg = v('--selection-bg')
|
|
637
|
-
|
|
638
|
-
const editor = document.querySelector('#editor .ProseMirror')
|
|
639
|
-
const fontFamily = editor ? getComputedStyle(editor).fontFamily : '-apple-system,BlinkMacSystemFont,sans-serif'
|
|
640
|
-
|
|
641
|
-
const getElColor = (selector: string, fallback: string): string => {
|
|
642
|
-
const el = document.querySelector(`#editor .ProseMirror ${selector}`)
|
|
643
|
-
return el ? getComputedStyle(el).color : fallback
|
|
644
|
-
}
|
|
645
|
-
const strongColor = getElColor('strong', textColor)
|
|
646
|
-
const codeColor = getElColor('code', textColor)
|
|
647
|
-
|
|
648
|
-
return `<!DOCTYPE html>
|
|
649
|
-
<html><head><meta charset="utf-8"><title>ColaMD Export</title>
|
|
650
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.46/dist/katex.min.css">
|
|
651
|
-
<style>
|
|
652
|
-
body{max-width:780px;margin:40px auto;padding:20px;font-family:${fontFamily};line-height:1.75;background:${bgColor};color:${textColor}}
|
|
653
|
-
h1{font-size:2em;font-weight:700;border-bottom:1px solid ${borderColor};padding-bottom:.3em}
|
|
654
|
-
h2{font-size:1.5em;font-weight:600;border-bottom:1px solid ${borderColor};padding-bottom:.25em}
|
|
655
|
-
h3{font-size:1.25em;font-weight:600}
|
|
656
|
-
strong{color:${strongColor}}
|
|
657
|
-
a{color:${linkColor};text-decoration:none}
|
|
658
|
-
code{background:${codeBg};color:${codeColor};padding:2px 6px;border-radius:3px;font-size:.875em;font-family:'SF Mono','Fira Code',Menlo,monospace}
|
|
659
|
-
pre{background:${codeBlockBg};color:${codeBlockText};padding:16px;border-radius:6px;overflow-x:auto;margin:1em 0}
|
|
660
|
-
pre code{background:none;padding:0;color:inherit}
|
|
661
|
-
blockquote{border-left:4px solid ${blockquoteBorder};background:${blockquoteBg};padding-left:16px;margin:1em 0;color:${textMuted}}
|
|
662
|
-
table{border-collapse:collapse;width:100%;margin:1em 0}
|
|
663
|
-
th,td{border:1px solid ${borderColor};padding:8px 12px}
|
|
664
|
-
th{background:${tableHeaderBg};font-weight:600}
|
|
665
|
-
hr{border:none;border-top:2px solid ${borderColor};margin:2em 0}
|
|
666
|
-
img{max-width:100%}
|
|
667
|
-
::selection{background:${selectionBg}}
|
|
668
|
-
.math-inline{display:inline;padding:2px 4px;border-radius:3px;background:${codeBg}}
|
|
669
|
-
.math-block{display:block;padding:16px;margin:1em 0;border-radius:6px;background:${codeBlockBg};text-align:center;overflow-x:auto}
|
|
670
|
-
.mermaid-block{display:block;padding:16px;margin:1em 0;border-radius:6px;background:${mermaidBg};border:1px solid ${borderColor}}
|
|
671
|
-
.mermaid-preview{display:flex;justify-content:center;align-items:center}
|
|
672
|
-
.mermaid-preview svg{max-width:100%;height:auto}
|
|
673
|
-
@page{margin:15mm;size:A4}
|
|
674
|
-
@media print{body{max-width:none;margin:0;padding:20px}#editor{position:static!important;overflow:visible!important}}
|
|
675
|
-
</style>
|
|
676
|
-
</head><body>${getLiveHTML()}</body></html>`
|
|
677
|
-
}
|
|
678
|
-
init().catch((e) => console.error('ColaMD init failed:', e))
|