@bytechain.cn/colamd 1.5.1-beta.2 → 1.5.1

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +159 -162
  2. package/README.md +79 -3
  3. package/README_CN.md +78 -3
  4. package/dist/main/index.js +14 -5
  5. package/dist/preload/index.js +1 -1
  6. package/dist/renderer/assets/{arc-CPdeInCG.js → arc-_lugyDzx.js} +1 -1
  7. package/dist/renderer/assets/{architectureDiagram-3BPJPVTR-BAbnaR9G.js → architectureDiagram-3BPJPVTR-DDfP-F9D.js} +2 -2
  8. package/dist/renderer/assets/{blockDiagram-GPEHLZMM-CYSWjnJg.js → blockDiagram-GPEHLZMM-DOETUKma.js} +4 -4
  9. package/dist/renderer/assets/{c4Diagram-AAUBKEIU-Rb1tstnr.js → c4Diagram-AAUBKEIU-kAmLfVtk.js} +2 -2
  10. package/dist/renderer/assets/{channel-DpG2A6fE.js → channel-CD4vJFwr.js} +1 -1
  11. package/dist/renderer/assets/{chunk-2J33WTMH-DFc0Jxy_.js → chunk-2J33WTMH-DkVrgw4l.js} +1 -1
  12. package/dist/renderer/assets/{chunk-4BX2VUAB-BhRxDTNn.js → chunk-4BX2VUAB-JTZ-VKNX.js} +1 -1
  13. package/dist/renderer/assets/{chunk-55IACEB6-DEgMVBk8.js → chunk-55IACEB6-Di_O5box.js} +1 -1
  14. package/dist/renderer/assets/{chunk-727SXJPM-bjBIfiz8.js → chunk-727SXJPM-BgKvwR8w.js} +5 -5
  15. package/dist/renderer/assets/{chunk-AQP2D5EJ-DwQMzTzD.js → chunk-AQP2D5EJ-DonSXCCQ.js} +3 -3
  16. package/dist/renderer/assets/{chunk-FMBD7UC4-CkphwJzs.js → chunk-FMBD7UC4-CsV8Lmy6.js} +1 -1
  17. package/dist/renderer/assets/{chunk-ND2GUHAM-oU09z4y4.js → chunk-ND2GUHAM-C_-_dlq7.js} +1 -1
  18. package/dist/renderer/assets/{chunk-QZHKN3VN-rCbVuPBn.js → chunk-QZHKN3VN-aCmcDsfu.js} +1 -1
  19. package/dist/renderer/assets/{classDiagram-v2-Q7XG4LA2-DGS2faoM.js → classDiagram-4FO5ZUOK-nuHQLjzM.js} +6 -6
  20. package/dist/renderer/assets/{classDiagram-4FO5ZUOK-DGS2faoM.js → classDiagram-v2-Q7XG4LA2-nuHQLjzM.js} +6 -6
  21. package/dist/renderer/assets/{cose-bilkent-S5V4N54A-iqY6-EwA.js → cose-bilkent-S5V4N54A-Di1_SXt9.js} +1 -1
  22. package/dist/renderer/assets/{dagre-BM42HDAG-5t3X5sDa.js → dagre-BM42HDAG-CqOUIYsL.js} +3 -3
  23. package/dist/renderer/assets/{diagram-2AECGRRQ-DzHiYDPh.js → diagram-2AECGRRQ-F-fP19TC.js} +2 -2
  24. package/dist/renderer/assets/{diagram-5GNKFQAL-BiNv6Keq.js → diagram-5GNKFQAL-BD5XZc8G.js} +3 -3
  25. package/dist/renderer/assets/{diagram-KO2AKTUF-ClzeDG6f.js → diagram-KO2AKTUF-Qa3ZxA67.js} +2 -2
  26. package/dist/renderer/assets/{diagram-LMA3HP47-CGkw7wII.js → diagram-LMA3HP47-DqDnw2RA.js} +2 -2
  27. package/dist/renderer/assets/{diagram-OG6HWLK6-Dl-Hyk1_.js → diagram-OG6HWLK6-BH4Elzby.js} +3 -3
  28. package/dist/renderer/assets/{erDiagram-TEJ5UH35-BxUN79Qb.js → erDiagram-TEJ5UH35-CaKZCewa.js} +4 -4
  29. package/dist/renderer/assets/{flowDiagram-I6XJVG4X-CzFk-KNI.js → flowDiagram-I6XJVG4X-C8znUgyL.js} +6 -6
  30. package/dist/renderer/assets/{ganttDiagram-6RSMTGT7-C2xl6Igx.js → ganttDiagram-6RSMTGT7-DnRvbMnU.js} +2 -2
  31. package/dist/renderer/assets/{gitGraphDiagram-PVQCEYII-_fn7XCa7.js → gitGraphDiagram-PVQCEYII-CZuRZzk4.js} +3 -3
  32. package/dist/renderer/assets/{graph-CDoHYrHm.js → graph-CYiEKt0j.js} +1 -1
  33. package/dist/renderer/assets/{index-DAlXyxzt.js → index-BX6JHKv6.js} +328 -143
  34. package/dist/renderer/assets/{index-CeFpoCKV.css → index-CcwAgVRi.css} +5 -6
  35. package/dist/renderer/assets/{infoDiagram-5YYISTIA-DL6XIxLz.js → infoDiagram-5YYISTIA-BlBUdqMb.js} +1 -1
  36. package/dist/renderer/assets/{ishikawaDiagram-YF4QCWOH-BUZLjRo-.js → ishikawaDiagram-YF4QCWOH-TeVytCrP.js} +1 -1
  37. package/dist/renderer/assets/{journeyDiagram-JHISSGLW-C4rH_mQM.js → journeyDiagram-JHISSGLW-BLZa3jnX.js} +4 -4
  38. package/dist/renderer/assets/{kanban-definition-UN3LZRKU-DRbrBcWV.js → kanban-definition-UN3LZRKU-foVxWrJn.js} +2 -2
  39. package/dist/renderer/assets/{layout-DZl4n4qu.js → layout-DOAlFUVb.js} +2 -2
  40. package/dist/renderer/assets/{linear-B0Krxg21.js → linear-BMBn6kVq.js} +1 -1
  41. package/dist/renderer/assets/{mindmap-definition-RKZ34NQL-DdmPsWrn.js → mindmap-definition-RKZ34NQL-5pGeNCcp.js} +3 -3
  42. package/dist/renderer/assets/{pieDiagram-4H26LBE5-BPZLqwG0.js → pieDiagram-4H26LBE5-N9aAUxfr.js} +3 -3
  43. package/dist/renderer/assets/{quadrantDiagram-W4KKPZXB-Dr-oWRk9.js → quadrantDiagram-W4KKPZXB-BPxbtjga.js} +2 -2
  44. package/dist/renderer/assets/{requirementDiagram-4Y6WPE33-B6QZd0lo.js → requirementDiagram-4Y6WPE33-CK1LrJyG.js} +3 -3
  45. package/dist/renderer/assets/{sankeyDiagram-5OEKKPKP-Cyl9ojEt.js → sankeyDiagram-5OEKKPKP-BNj7Sqii.js} +1 -1
  46. package/dist/renderer/assets/{sequenceDiagram-3UESZ5HK-D48Yr9T6.js → sequenceDiagram-3UESZ5HK-B-r7lNhI.js} +3 -3
  47. package/dist/renderer/assets/{stateDiagram-AJRCARHV-qyb8ETsa.js → stateDiagram-AJRCARHV-wrWE0MRa.js} +6 -6
  48. package/dist/renderer/assets/{stateDiagram-v2-BHNVJYJU-DmDOyyrJ.js → stateDiagram-v2-BHNVJYJU-CE-Lqo2d.js} +4 -4
  49. package/dist/renderer/assets/{timeline-definition-PNZ67QCA-C-KQxTi1.js → timeline-definition-PNZ67QCA-BkeMGH4J.js} +2 -2
  50. package/dist/renderer/assets/{vennDiagram-CIIHVFJN-BdaZlnH-.js → vennDiagram-CIIHVFJN-BTxVzto3.js} +1 -1
  51. package/dist/renderer/assets/{wardleyDiagram-YWT4CUSO-B2hBE-EE.js → wardleyDiagram-YWT4CUSO-D2r5dVGW.js} +2 -2
  52. package/dist/renderer/assets/{xychartDiagram-2RQKCTM6-CSvswDTY.js → xychartDiagram-2RQKCTM6-BHQdINVc.js} +2 -2
  53. package/dist/renderer/index.html +2 -2
  54. package/docs/RELEASE_NOTES_v1.5.1.md +382 -0
  55. package/docs/academic-demo.md +2 -1
  56. package/docs/theme-paradigm.md +141 -2
  57. package/package.json +1 -1
  58. package/src/main/index.ts +19 -5
  59. package/src/preload/index.ts +2 -2
  60. package/src/renderer/editor/editor.ts +40 -40
  61. package/src/renderer/editor/plugins/index.ts +18 -0
  62. package/src/renderer/editor/plugins/math-plugin.ts +8 -0
  63. package/src/renderer/editor/plugins/mermaid-plugin.ts +10 -0
  64. package/src/renderer/editor/plugins/themes/theme-manager.ts +41 -0
  65. package/src/renderer/main.ts +180 -83
  66. package/src/renderer/mobile.css +5 -6
  67. package/themes/README.md +18 -1
  68. package/themes/academic-paper-pt.css +1321 -0
  69. package/themes/academic-paper.css +192 -97
  70. package/tsconfig.renderer.tsbuildinfo +1 -1
  71. package/bytechain.cn-colamd-1.5.1-beta.2.tgz +0 -0
@@ -1,6 +1,6 @@
1
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'
2
+ import { applyTheme, loadSavedTheme, setCachedCustomTheme, getActiveCustomThemeCSS, extractPrintCSSFromSheet } from './editor/plugins/themes/theme-manager'
3
+ import { getAllPlugins, togglePlugin, findPluginBySelector, findExportCapabilities, getContextMenuSelector } from './editor/plugins'
4
4
  import './editor/plugins/math-plugin'
5
5
  import './editor/plugins/mermaid-plugin'
6
6
  import { createCapacitorAPI } from './capacitor-api'
@@ -120,9 +120,15 @@ function getContent(): string {
120
120
  }
121
121
 
122
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
- })
123
+ const selectors = getAllPlugins()
124
+ .filter((p) => p.enabled)
125
+ .flatMap((p) => p.rawSelectors || [])
126
+ .join(',')
127
+ if (selectors) {
128
+ document.querySelectorAll(selectors).forEach((el) => {
129
+ if ((el as HTMLElement).matches(':focus')) (el as HTMLElement).blur()
130
+ })
131
+ }
126
132
  }
127
133
 
128
134
  function restoreRenderedMode(api: any): void {
@@ -238,7 +244,19 @@ async function init(): Promise<void> {
238
244
  restoreRenderedMode(api)
239
245
  await ensureAllPluginsRendered()
240
246
  await new Promise(r => setTimeout(r, 300))
241
- await api.exportPDF(buildExportHTML())
247
+ // 从自定义主题 CSSOM 提取 @media print 规则,注入 DOM 供 printToPDF 使用
248
+ const printCSS = extractPrintCSSFromSheet()
249
+ let printStyleEl: HTMLStyleElement | null = null
250
+ if (printCSS) {
251
+ printStyleEl = document.createElement('style')
252
+ printStyleEl.textContent = printCSS
253
+ document.head.appendChild(printStyleEl)
254
+ // 等待样式生效再导出
255
+ await new Promise(r => requestAnimationFrame(r))
256
+ }
257
+ // 传递 CSS 到主进程作为保险(insertCSS 双重注入)
258
+ await api.exportPDF(printCSS || undefined)
259
+ if (printStyleEl) printStyleEl.remove()
242
260
  setTimeout(() => {
243
261
  document.querySelectorAll('.mermaid-loading, .mermaid-error')
244
262
  .forEach(el => (el as HTMLElement).style.display = 'none')
@@ -249,62 +267,7 @@ async function init(): Promise<void> {
249
267
  restoreRenderedMode(api)
250
268
  await ensureAllPluginsRendered()
251
269
  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)
270
+ api.exportHTML(buildExportHTML())
308
271
  })
309
272
 
310
273
  api.onNewFile(() => { exitSourceMode(); setMarkdown('') })
@@ -399,7 +362,7 @@ img{max-width:100%}
399
362
 
400
363
  document.addEventListener('contextmenu', (e) => {
401
364
  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
365
+ const target = (e.target as Element).closest(getContextMenuSelector()) as HTMLElement | null
403
366
  if (!target) return
404
367
  const capabilities = findExportCapabilities(target.className)
405
368
  if (!capabilities.length) return
@@ -566,7 +529,19 @@ function setupMobileMenu(api: any, currentTheme: string): void {
566
529
  restoreRenderedMode(api)
567
530
  await ensureAllPluginsRendered()
568
531
  await new Promise(r => setTimeout(r, 300))
569
- await api.exportPDF(buildExportHTML())
532
+ // 从自定义主题 CSSOM 提取 @media print 规则,注入 DOM 供 printToPDF 使用
533
+ const printCSS = extractPrintCSSFromSheet()
534
+ let printStyleEl: HTMLStyleElement | null = null
535
+ if (printCSS) {
536
+ printStyleEl = document.createElement('style')
537
+ printStyleEl.textContent = printCSS
538
+ document.head.appendChild(printStyleEl)
539
+ // 等待样式生效再导出
540
+ await new Promise(r => requestAnimationFrame(r))
541
+ }
542
+ // 传递 CSS 到主进程作为保险(insertCSS 双重注入)
543
+ await api.exportPDF(printCSS || undefined)
544
+ if (printStyleEl) printStyleEl.remove()
570
545
  setTimeout(() => {
571
546
  document.querySelectorAll('.mermaid-loading, .mermaid-error')
572
547
  .forEach(el => (el as HTMLElement).style.display = 'none')
@@ -615,12 +590,14 @@ function setupMobileMenu(api: any, currentTheme: string): void {
615
590
  }
616
591
 
617
592
  /**
618
- * 构建导出用的 HTML 字符串,包含当前主题样式。
593
+ * 构建导出用的 HTML 字符串,包含当前主题完整样式。
594
+ * 会自动注入自定义主题 CSS、计算实际字号、包含 Mermaid 样式。
619
595
  * @returns 完整的 HTML 文档字符串
620
596
  */
621
597
  function buildExportHTML(): string {
622
- const s = getComputedStyle(document.body)
623
- const v = (name: string) => s.getPropertyValue(name).trim()
598
+ const bodyStyle = getComputedStyle(document.body)
599
+ const v = (name: string) => bodyStyle.getPropertyValue(name).trim()
600
+
624
601
  const bgColor = v('--bg-color')
625
602
  const textColor = v('--text-color')
626
603
  const textMuted = v('--text-muted')
@@ -629,15 +606,26 @@ function buildExportHTML(): string {
629
606
  const codeBg = v('--code-bg')
630
607
  const codeBlockBg = v('--code-block-bg')
631
608
  const codeBlockText = v('--code-block-text') || textColor
632
- const mermaidBg = v('--mermaid-background') || bgColor
633
609
  const blockquoteBorder = v('--blockquote-border')
634
610
  const blockquoteBg = v('--blockquote-bg') || 'transparent'
635
611
  const tableHeaderBg = v('--table-header-bg')
636
612
  const selectionBg = v('--selection-bg')
637
613
 
614
+ // ── Read actual computed font metrics from editor ──
638
615
  const editor = document.querySelector('#editor .ProseMirror')
639
- const fontFamily = editor ? getComputedStyle(editor).fontFamily : '-apple-system,BlinkMacSystemFont,sans-serif'
640
-
616
+ const editorStyle = editor ? getComputedStyle(editor) : bodyStyle
617
+ const fontFamily = editorStyle.fontFamily || '-apple-system,BlinkMacSystemFont,sans-serif'
618
+ const bodyFontSize = editorStyle.fontSize || '16px'
619
+ const bodyLineHeight = editorStyle.lineHeight || '1.75'
620
+
621
+ const getElFontSize = (tag: string, fallback: string): string => {
622
+ const el = document.querySelector(`#editor .ProseMirror ${tag}`)
623
+ return el ? getComputedStyle(el).fontSize : fallback
624
+ }
625
+ const getElFontWeight = (tag: string, fallback: string): string => {
626
+ const el = document.querySelector(`#editor .ProseMirror ${tag}`)
627
+ return el ? getComputedStyle(el).fontWeight : fallback
628
+ }
641
629
  const getElColor = (selector: string, fallback: string): string => {
642
630
  const el = document.querySelector(`#editor .ProseMirror ${selector}`)
643
631
  return el ? getComputedStyle(el).color : fallback
@@ -645,14 +633,57 @@ function buildExportHTML(): string {
645
633
  const strongColor = getElColor('strong', textColor)
646
634
  const codeColor = getElColor('code', textColor)
647
635
 
636
+ // ── Collect CSS custom properties as :root block ──
637
+ const cssVarLines = collectExportCSSVariables(v)
638
+
639
+ // ── Collect plugin export styles ──
640
+ let pluginCSS = ''
641
+ for (const p of getAllPlugins()) {
642
+ if (p.enabled && p.exportStyles) {
643
+ pluginCSS += `\n/* === ${p.name} === */\n${p.exportStyles}\n`
644
+ }
645
+ }
646
+
647
+ // ── Collect active theme CSS ──
648
+ let themeCSS = ''
649
+ let bodyClass = ''
650
+
651
+ if (document.body.classList.contains('theme-custom')) {
652
+ bodyClass = 'theme-custom'
653
+ // Inject full custom theme CSS
654
+ const customCSS = getActiveCustomThemeCSS()
655
+ if (customCSS) {
656
+ themeCSS += `\n/* === Custom Theme: ${loadSavedTheme()} === */\n${customCSS}\n`
657
+ }
658
+ // Inject Mermaid custom theme text styling
659
+ themeCSS += `\n/* === Mermaid Custom Text Styles === */\n${getMermaidCustomCSS()}\n`
660
+ } else {
661
+ for (const cls of ['theme-light', 'theme-dark', 'theme-elegant', 'theme-newsprint']) {
662
+ if (document.body.classList.contains(cls)) {
663
+ bodyClass = cls
664
+ break
665
+ }
666
+ }
667
+ }
668
+ const isCustomTheme = bodyClass === 'theme-custom'
669
+
648
670
  return `<!DOCTYPE html>
649
671
  <html><head><meta charset="utf-8"><title>ColaMD Export</title>
650
672
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.46/dist/katex.min.css">
651
673
  <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}
674
+ :root {
675
+ ${cssVarLines}
676
+ }
677
+ ${themeCSS}
678
+ ${pluginCSS}
679
+ /* === Base Element Styles === */
680
+ body{max-width:780px;margin:40px auto;padding:20px;font-size:${bodyFontSize};font-family:${fontFamily};line-height:${bodyLineHeight};background:${bgColor};color:${textColor}}
681
+ ${isCustomTheme ? '' : `h1{font-size:${getElFontSize('h1', '2em')};font-weight:${getElFontWeight('h1', '700')};border-bottom:1px solid ${borderColor};padding-bottom:.3em}
682
+ h2{font-size:${getElFontSize('h2', '1.5em')};font-weight:${getElFontWeight('h2', '600')};border-bottom:1px solid ${borderColor};padding-bottom:.25em}
683
+ h3{font-size:${getElFontSize('h3', '1.25em')};font-weight:${getElFontWeight('h3', '600')}}
684
+ h4{font-size:${getElFontSize('h4', '1.1em')};font-weight:${getElFontWeight('h4', '600')}}
685
+ h5{font-size:${getElFontSize('h5', '1em')};font-weight:${getElFontWeight('h5', '600')}}
686
+ h6{font-size:${getElFontSize('h6', '0.9em')};font-weight:${getElFontWeight('h6', '600')}}
656
687
  strong{color:${strongColor}}
657
688
  a{color:${linkColor};text-decoration:none}
658
689
  code{background:${codeBg};color:${codeColor};padding:2px 6px;border-radius:3px;font-size:.875em;font-family:'SF Mono','Fira Code',Menlo,monospace}
@@ -662,17 +693,83 @@ blockquote{border-left:4px solid ${blockquoteBorder};background:${blockquoteBg};
662
693
  table{border-collapse:collapse;width:100%;margin:1em 0}
663
694
  th,td{border:1px solid ${borderColor};padding:8px 12px}
664
695
  th{background:${tableHeaderBg};font-weight:600}
665
- hr{border:none;border-top:2px solid ${borderColor};margin:2em 0}
696
+ hr{border:none;border-top:2px solid ${borderColor};margin:2em 0}`}
666
697
  img{max-width:100%}
667
698
  ::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}}
699
+ ${(() => {
700
+ if (isCustomTheme) {
701
+ console.log('[buildExportHTML] Custom theme — skipping hardcoded @page/@media print, using theme CSS rules')
702
+ return ''
703
+ }
704
+ console.log('[buildExportHTML] Built-in theme — emitting hardcoded @page/@media print fallback')
705
+ return `@page{margin:15mm;size:A4}
706
+ @media print{body{max-width:none;margin:0;padding:20px}#editor{position:static!important;overflow:visible!important}}`
707
+ })()}
675
708
  </style>
676
- </head><body>${getLiveHTML()}</body></html>`
709
+ </head><body class="${bodyClass}">${getLiveHTML()}</body></html>`
710
+ }
711
+
712
+ /** 收集当前主题的 CSS 自定义属性,作为 :root 兜底变量 */
713
+ function collectExportCSSVariables(v: (name: string) => string): string {
714
+ const varNames = [
715
+ '--seed-accent', '--seed-accent-light', '--seed-accent-dark',
716
+ '--seed-surface', '--seed-panel', '--seed-panel-alt',
717
+ '--seed-ink', '--seed-ink-muted', '--seed-ink-dim',
718
+ '--seed-border', '--seed-border-strong',
719
+ '--font-size-root',
720
+ '--font-scale-h1', '--font-scale-h2', '--font-scale-h3',
721
+ '--font-scale-h4', '--font-scale-h5', '--font-scale-h6',
722
+ '--font-size-mermaid',
723
+ '--line-height-body', '--line-height-heading', '--line-height-code',
724
+ '--bg-color', '--text-color', '--heading-color', '--text-muted', '--text-dim',
725
+ '--link-color', '--accent-color', '--accent-dark', '--accent-light', '--selection-bg',
726
+ '--border-color', '--blockquote-border', '--hr-color',
727
+ '--code-bg', '--code-color', '--code-block-bg', '--code-block-text',
728
+ '--blockquote-bg', '--table-header-bg', '--table-header-text', '--table-border',
729
+ '--scrollbar-thumb', '--scrollbar-thumb-hover',
730
+ '--surface-color', '--surface-alt',
731
+ '--mermaid-background', '--mermaid-border-color', '--mermaid-border-radius', '--mermaid-padding',
732
+ '--mermaid-font-family', '--mermaid-font-size',
733
+ '--mermaid-node-fill', '--mermaid-node-stroke', '--mermaid-node-stroke-width', '--mermaid-node-text',
734
+ '--mermaid-edge-stroke', '--mermaid-edge-stroke-width',
735
+ '--mermaid-cluster-fill', '--mermaid-cluster-stroke',
736
+ '--mermaid-label-text', '--mermaid-edge-label-text', '--mermaid-edge-label-bg',
737
+ '--mermaid-title-text', '--mermaid-axis-text', '--mermaid-highlight',
738
+ '--mermaid-person-stroke', '--mermaid-person-fill',
739
+ '--mermaid-label-offset-y',
740
+ '--radius-sm', '--radius-md', '--radius-lg', '--content-width'
741
+ ]
742
+ const lines: string[] = []
743
+ for (const name of varNames) {
744
+ const val = v(name)
745
+ if (val) lines.push(` ${name}: ${val};`)
746
+ }
747
+ return lines.join('\n')
748
+ }
749
+
750
+ /** Mermaid 自定义主题 SVG 文字样式,注入到导出 HTML 中 */
751
+ function getMermaidCustomCSS(): string {
752
+ return `.theme-custom .mermaid-preview svg text {
753
+ fill: var(--mermaid-text-color, var(--text-color)) !important;
754
+ font-family: var(--mermaid-font-family, inherit) !important;
755
+ font-size: var(--mermaid-font-size, 12px) !important;
756
+ }
757
+ .theme-custom .mermaid-preview svg foreignObject span {
758
+ color: var(--mermaid-text-color, var(--text-color)) !important;
759
+ font-family: var(--mermaid-font-family, inherit) !important;
760
+ font-size: var(--mermaid-font-size, 14px) !important;
761
+ }
762
+ .theme-custom .mermaid-preview svg .person-man text { fill: #ffffff !important; }
763
+ .theme-custom .mermaid-preview svg .person-man span { color: #ffffff !important; }
764
+ .theme-custom .mermaid-preview svg .label text,
765
+ .theme-custom .mermaid-preview svg .nodeLabel text,
766
+ .theme-custom .mermaid-preview svg .state-title,
767
+ .theme-custom .mermaid-preview svg .state-description,
768
+ .theme-custom .mermaid-preview svg .pieTitleText,
769
+ .theme-custom .mermaid-preview svg .titleText { transform: translateY(-3px) !important; }
770
+ .theme-custom .mermaid-preview svg .xychart .axis text { transform: translateY(0) !important; }
771
+ .theme-custom .mermaid-preview svg .nodeLabel,
772
+ .theme-custom .mermaid-preview svg .edgeLabel { display: inline-block !important; position: relative !important; top: -3px !important; }
773
+ `
677
774
  }
678
775
  init().catch((e) => console.error('ColaMD init failed:', e))
@@ -1,4 +1,4 @@
1
- @media (max-width: 768px) {
1
+ @media screen and (max-width: 768px) {
2
2
  :root {
3
3
  --mobile-header-height: 48px;
4
4
  }
@@ -366,7 +366,7 @@
366
366
  .visible { display: block !important; }
367
367
  }
368
368
 
369
- @media (min-width: 769px) {
369
+ @media screen and (min-width: 769px) {
370
370
  #menu-btn {
371
371
  display: none;
372
372
  }
@@ -376,7 +376,7 @@
376
376
  }
377
377
  }
378
378
 
379
- @media (max-width: 480px) {
379
+ @media screen and (max-width: 480px) {
380
380
  .ProseMirror { font-size: 15px !important; }
381
381
  .ProseMirror pre { font-size: 12px !important; padding: 10px !important; }
382
382
  #editor { padding: 12px !important; }
@@ -410,20 +410,19 @@
410
410
  #editor {
411
411
  position: static !important;
412
412
  overflow: visible !important;
413
- padding: 0 !important;
414
413
  }
415
414
 
416
415
  .ProseMirror {
417
416
  min-height: auto !important;
418
- font-size: 14px !important;
419
417
  }
420
418
 
421
419
  .mermaid-preview svg {
422
420
  max-height: none !important;
423
421
  }
424
422
 
423
+ /* 默认的边界设定, 可以根据需要调整 */
425
424
  @page {
426
- margin: 15mm;
425
+ margin: 10mm;
427
426
  size: A4;
428
427
  }
429
428
  }
package/themes/README.md CHANGED
@@ -9,8 +9,25 @@ Download any `.css` file and place it in `~/.colamd/themes/`, or use **Theme > I
9
9
  | [elegant.css](elegant.css) | Warm serif theme with terracotta accents and dark code blocks |
10
10
  | [guizang.css](guizang.css) | 古雅沉稳的归藏风格,赭石强调色、松烟墨代码块、宣纸底色 |
11
11
  | [forest-ink.css](forest-ink.css) | 森林墨主题,宣纸暖白底、松烟墨绿文字、森林绿强调色(灵感来自 wanhua-ppt Forest Ink 设计规范) |
12
- | [academic-paper.css](academic-paper.css) | 📄 **学术论文主题(增强版)** — 符合 GB/T 7713 中文学术论文排版规范,黑体(SimHei)标题 + 宋体(SimSun)正文及首行缩进,三线表格式(顶线 + 表头底线 + 底线),10.5pt 字号,打印优化的 Mermaid 图表(直角容器、灰度配色),脚注与参考文献样式,Typora 兼容选择器。完整示例见 [`docs/academic-demo.md`](../docs/academic-demo.md) |
12
+ | [academic-paper.css](academic-paper.css) | 📄 **学术论文主题** — 符合 GB/T 7713 中文学术论文排版规范,黑体(SimHei)标题 + 宋体(SimSun)正文及首行缩进,三线表格式(顶线 + 表头底线 + 底线),10.5pt 字号,打印优化的 Mermaid 图表(直角容器、灰度配色),脚注与参考文献样式,Typora 兼容选择器。完整示例见 [`docs/academic-demo.md`](../docs/academic-demo.md) |
13
+ | [academic-paper-pt.css](academic-paper-pt.css) | 📄 **学术论文主题(PT 单位版)** — 与 academic-paper.css 相同的 GB/T 7713 规范设计,但使用 pt 单位以适配特定打印场景需求 |
13
14
  | [pixso-design.css](pixso-design.css) | 🎨 Pixso 设计主题,现代设计系统风格 |
15
+ | [swiss-design.css](swiss-design.css) | 🇨🇭 **瑞士国际主义风格主题** — 纯黑白红三色体系,几何无衬线字体(Helvetica / Inter),网格化排版与充足留白,功能至上设计哲学,极简克制美学,完整的 Mermaid 图表集成(单色调 + 强调红) |
16
+ | [template.css](template.css) | 📝 **标准化模板** — 遵循 v3.0 主题开发范式的参考实现,包含完整的设计令牌、编辑器样式、代码块、引用块、表格、Mermaid 变量和打印样式,可作为创建自定义主题的起点 |
17
+
18
+ > ⚠️ **Theme Migration Notice**
19
+ >
20
+ > Starting from this version, **theme updates and maintenance have been migrated to the dedicated repository**:
21
+ >
22
+ > 🔗 **[https://github.com/byteuser1977/ColaMD-themes](https://github.com/byteuser1977/ColaMD-themes)**
23
+ >
24
+ > Future theme enhancements, bug fixes, and new theme submissions will be handled in the ColaMD-themes repository. This allows for:
25
+ > - Faster iteration and release cycles for theme-specific changes
26
+ > - Community contributions and theme submissions
27
+ > - Independent versioning from the core ColaMD application
28
+ > - Focused issue tracking for theme-related problems
29
+ >
30
+ > The themes included in this release will remain available for backward compatibility, but we recommend checking the dedicated repository for the latest versions and new themes.
14
31
 
15
32
  ## Creating Your Own Theme
16
33