@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.
- package/CHANGELOG.md +159 -162
- package/README.md +79 -3
- package/README_CN.md +78 -3
- package/dist/main/index.js +14 -5
- package/dist/preload/index.js +1 -1
- package/dist/renderer/assets/{arc-CPdeInCG.js → arc-_lugyDzx.js} +1 -1
- package/dist/renderer/assets/{architectureDiagram-3BPJPVTR-BAbnaR9G.js → architectureDiagram-3BPJPVTR-DDfP-F9D.js} +2 -2
- package/dist/renderer/assets/{blockDiagram-GPEHLZMM-CYSWjnJg.js → blockDiagram-GPEHLZMM-DOETUKma.js} +4 -4
- package/dist/renderer/assets/{c4Diagram-AAUBKEIU-Rb1tstnr.js → c4Diagram-AAUBKEIU-kAmLfVtk.js} +2 -2
- package/dist/renderer/assets/{channel-DpG2A6fE.js → channel-CD4vJFwr.js} +1 -1
- package/dist/renderer/assets/{chunk-2J33WTMH-DFc0Jxy_.js → chunk-2J33WTMH-DkVrgw4l.js} +1 -1
- package/dist/renderer/assets/{chunk-4BX2VUAB-BhRxDTNn.js → chunk-4BX2VUAB-JTZ-VKNX.js} +1 -1
- package/dist/renderer/assets/{chunk-55IACEB6-DEgMVBk8.js → chunk-55IACEB6-Di_O5box.js} +1 -1
- package/dist/renderer/assets/{chunk-727SXJPM-bjBIfiz8.js → chunk-727SXJPM-BgKvwR8w.js} +5 -5
- package/dist/renderer/assets/{chunk-AQP2D5EJ-DwQMzTzD.js → chunk-AQP2D5EJ-DonSXCCQ.js} +3 -3
- package/dist/renderer/assets/{chunk-FMBD7UC4-CkphwJzs.js → chunk-FMBD7UC4-CsV8Lmy6.js} +1 -1
- package/dist/renderer/assets/{chunk-ND2GUHAM-oU09z4y4.js → chunk-ND2GUHAM-C_-_dlq7.js} +1 -1
- package/dist/renderer/assets/{chunk-QZHKN3VN-rCbVuPBn.js → chunk-QZHKN3VN-aCmcDsfu.js} +1 -1
- package/dist/renderer/assets/{classDiagram-v2-Q7XG4LA2-DGS2faoM.js → classDiagram-4FO5ZUOK-nuHQLjzM.js} +6 -6
- package/dist/renderer/assets/{classDiagram-4FO5ZUOK-DGS2faoM.js → classDiagram-v2-Q7XG4LA2-nuHQLjzM.js} +6 -6
- package/dist/renderer/assets/{cose-bilkent-S5V4N54A-iqY6-EwA.js → cose-bilkent-S5V4N54A-Di1_SXt9.js} +1 -1
- package/dist/renderer/assets/{dagre-BM42HDAG-5t3X5sDa.js → dagre-BM42HDAG-CqOUIYsL.js} +3 -3
- package/dist/renderer/assets/{diagram-2AECGRRQ-DzHiYDPh.js → diagram-2AECGRRQ-F-fP19TC.js} +2 -2
- package/dist/renderer/assets/{diagram-5GNKFQAL-BiNv6Keq.js → diagram-5GNKFQAL-BD5XZc8G.js} +3 -3
- package/dist/renderer/assets/{diagram-KO2AKTUF-ClzeDG6f.js → diagram-KO2AKTUF-Qa3ZxA67.js} +2 -2
- package/dist/renderer/assets/{diagram-LMA3HP47-CGkw7wII.js → diagram-LMA3HP47-DqDnw2RA.js} +2 -2
- package/dist/renderer/assets/{diagram-OG6HWLK6-Dl-Hyk1_.js → diagram-OG6HWLK6-BH4Elzby.js} +3 -3
- package/dist/renderer/assets/{erDiagram-TEJ5UH35-BxUN79Qb.js → erDiagram-TEJ5UH35-CaKZCewa.js} +4 -4
- package/dist/renderer/assets/{flowDiagram-I6XJVG4X-CzFk-KNI.js → flowDiagram-I6XJVG4X-C8znUgyL.js} +6 -6
- package/dist/renderer/assets/{ganttDiagram-6RSMTGT7-C2xl6Igx.js → ganttDiagram-6RSMTGT7-DnRvbMnU.js} +2 -2
- package/dist/renderer/assets/{gitGraphDiagram-PVQCEYII-_fn7XCa7.js → gitGraphDiagram-PVQCEYII-CZuRZzk4.js} +3 -3
- package/dist/renderer/assets/{graph-CDoHYrHm.js → graph-CYiEKt0j.js} +1 -1
- package/dist/renderer/assets/{index-DAlXyxzt.js → index-BX6JHKv6.js} +328 -143
- package/dist/renderer/assets/{index-CeFpoCKV.css → index-CcwAgVRi.css} +5 -6
- package/dist/renderer/assets/{infoDiagram-5YYISTIA-DL6XIxLz.js → infoDiagram-5YYISTIA-BlBUdqMb.js} +1 -1
- package/dist/renderer/assets/{ishikawaDiagram-YF4QCWOH-BUZLjRo-.js → ishikawaDiagram-YF4QCWOH-TeVytCrP.js} +1 -1
- package/dist/renderer/assets/{journeyDiagram-JHISSGLW-C4rH_mQM.js → journeyDiagram-JHISSGLW-BLZa3jnX.js} +4 -4
- package/dist/renderer/assets/{kanban-definition-UN3LZRKU-DRbrBcWV.js → kanban-definition-UN3LZRKU-foVxWrJn.js} +2 -2
- package/dist/renderer/assets/{layout-DZl4n4qu.js → layout-DOAlFUVb.js} +2 -2
- package/dist/renderer/assets/{linear-B0Krxg21.js → linear-BMBn6kVq.js} +1 -1
- package/dist/renderer/assets/{mindmap-definition-RKZ34NQL-DdmPsWrn.js → mindmap-definition-RKZ34NQL-5pGeNCcp.js} +3 -3
- package/dist/renderer/assets/{pieDiagram-4H26LBE5-BPZLqwG0.js → pieDiagram-4H26LBE5-N9aAUxfr.js} +3 -3
- package/dist/renderer/assets/{quadrantDiagram-W4KKPZXB-Dr-oWRk9.js → quadrantDiagram-W4KKPZXB-BPxbtjga.js} +2 -2
- package/dist/renderer/assets/{requirementDiagram-4Y6WPE33-B6QZd0lo.js → requirementDiagram-4Y6WPE33-CK1LrJyG.js} +3 -3
- package/dist/renderer/assets/{sankeyDiagram-5OEKKPKP-Cyl9ojEt.js → sankeyDiagram-5OEKKPKP-BNj7Sqii.js} +1 -1
- package/dist/renderer/assets/{sequenceDiagram-3UESZ5HK-D48Yr9T6.js → sequenceDiagram-3UESZ5HK-B-r7lNhI.js} +3 -3
- package/dist/renderer/assets/{stateDiagram-AJRCARHV-qyb8ETsa.js → stateDiagram-AJRCARHV-wrWE0MRa.js} +6 -6
- package/dist/renderer/assets/{stateDiagram-v2-BHNVJYJU-DmDOyyrJ.js → stateDiagram-v2-BHNVJYJU-CE-Lqo2d.js} +4 -4
- package/dist/renderer/assets/{timeline-definition-PNZ67QCA-C-KQxTi1.js → timeline-definition-PNZ67QCA-BkeMGH4J.js} +2 -2
- package/dist/renderer/assets/{vennDiagram-CIIHVFJN-BdaZlnH-.js → vennDiagram-CIIHVFJN-BTxVzto3.js} +1 -1
- package/dist/renderer/assets/{wardleyDiagram-YWT4CUSO-B2hBE-EE.js → wardleyDiagram-YWT4CUSO-D2r5dVGW.js} +2 -2
- package/dist/renderer/assets/{xychartDiagram-2RQKCTM6-CSvswDTY.js → xychartDiagram-2RQKCTM6-BHQdINVc.js} +2 -2
- package/dist/renderer/index.html +2 -2
- package/docs/RELEASE_NOTES_v1.5.1.md +382 -0
- package/docs/academic-demo.md +2 -1
- package/docs/theme-paradigm.md +141 -2
- package/package.json +1 -1
- package/src/main/index.ts +19 -5
- package/src/preload/index.ts +2 -2
- package/src/renderer/editor/editor.ts +40 -40
- package/src/renderer/editor/plugins/index.ts +18 -0
- package/src/renderer/editor/plugins/math-plugin.ts +8 -0
- package/src/renderer/editor/plugins/mermaid-plugin.ts +10 -0
- package/src/renderer/editor/plugins/themes/theme-manager.ts +41 -0
- package/src/renderer/main.ts +180 -83
- package/src/renderer/mobile.css +5 -6
- package/themes/README.md +18 -1
- package/themes/academic-paper-pt.css +1321 -0
- package/themes/academic-paper.css +192 -97
- package/tsconfig.renderer.tsbuildinfo +1 -1
- package/bytechain.cn-colamd-1.5.1-beta.2.tgz +0 -0
package/docs/academic-demo.md
CHANGED
|
@@ -61,7 +61,7 @@ ColaMD 项目正是为解决这一结构性矛盾而设计。其核心创新在
|
|
|
61
61
|
|
|
62
62
|
ColaMD 扩展版采用双平台分层架构设计。系统在运行时通过自动检测桥接层,根据运行环境(Electron 或 WebView)无缝切换底层 API 调用方式。整体架构如图 1 所示。
|
|
63
63
|
|
|
64
|
-
<div style="text-align: center; margin: 20px 0;"><svg width="
|
|
64
|
+
<div style="text-align: center; margin: 20px 0;"><svg width="540" height="285" viewBox="0 0 720 380" xmlns="http://www.w3.org/2000/svg" style="display: block; margin: 0 auto; font-family: 'SimSun', 'Microsoft YaHei', sans-serif;"><rect width="720" height="380" fill="#FAFBFC" rx="12"/><text x="360" y="30" fill="#1B2A4A" text-anchor="middle" font-size="16" font-weight="bold">图1 ColaMD 双平台分层架构</text><rect x="30" y="50" width="320" height="290" rx="8" fill="white" stroke="#357ABD" stroke-width="1.5"/><text x="190" y="78" fill="#357ABD" text-anchor="middle" font-size="14" font-weight="bold">桌面端运行栈 (Electron)</text><rect x="50" y="95" width="280" height="50" rx="5" fill="#E8F0FE" stroke="#357ABD" stroke-width="1"/><text x="190" y="118" fill="#333" text-anchor="middle" font-size="12" font-weight="bold">主进程 (Main Process)</text><text x="190" y="136" fill="#666" text-anchor="middle" font-size="10">窗口管理 · 文件系统 I/O · fs.watch 事件监听</text><line x1="190" y1="145" x2="190" y2="155" stroke="#357ABD" stroke-width="1.5"/><polygon points="190,160 185,150 195,150" fill="#357ABD"/><rect x="50" y="160" width="280" height="50" rx="5" fill="#E8F0FE" stroke="#357ABD" stroke-width="1"/><text x="190" y="183" fill="#333" text-anchor="middle" font-size="12" font-weight="bold">Preload 桥接层 (IPC Bridge)</text><text x="190" y="201" fill="#666" text-anchor="middle" font-size="10">安全的进程间通信 · contextBridge 暴露 API</text><line x1="190" y1="210" x2="190" y2="220" stroke="#357ABD" stroke-width="1.5"/><polygon points="190,225 185,215 195,215" fill="#357ABD"/><rect x="50" y="225" width="280" height="95" rx="5" fill="#E8F0FE" stroke="#357ABD" stroke-width="1"/><text x="190" y="248" fill="#333" text-anchor="middle" font-size="12" font-weight="bold">渲染进程 (Renderer Process)</text><line x1="70" y1="258" x2="310" y2="258" stroke="#BDC3C7" stroke-width="0.5"/><text x="190" y="275" fill="#555" text-anchor="middle" font-size="10">Milkdown 编辑器核心 (ProseMirror 底层)</text><text x="190" y="293" fill="#555" text-anchor="middle" font-size="10">├─ Math 显示插件 📐</text><text x="190" y="310" fill="#555" text-anchor="middle" font-size="10">└─ Mermaid 显示插件 🔀</text><line x1="350" y1="195" x2="370" y2="195" stroke="#999" stroke-width="1.5" stroke-dasharray="6,4"/><text x="360" y="188" fill="#666" text-anchor="middle" font-size="10">自动检测</text><rect x="370" y="50" width="320" height="290" rx="8" fill="white" stroke="#D35400" stroke-width="1.5"/><text x="530" y="78" fill="#D35400" text-anchor="middle" font-size="14" font-weight="bold">移动端运行栈 (Capacitor 6)</text><rect x="390" y="95" width="280" height="50" rx="5" fill="#FDF2E9" stroke="#D35400" stroke-width="1"/><text x="530" y="118" fill="#333" text-anchor="middle" font-size="12" font-weight="bold">Capacitor 运行时</text><text x="530" y="136" fill="#666" text-anchor="middle" font-size="10">Android WebView / iOS WKWebView 引擎</text><line x1="530" y1="145" x2="530" y2="155" stroke="#D35400" stroke-width="1.5"/><polygon points="530,160 525,150 535,150" fill="#D35400"/><rect x="390" y="160" width="280" height="50" rx="5" fill="#FDF2E9" stroke="#D35400" stroke-width="1"/><text x="530" y="183" fill="#333" text-anchor="middle" font-size="12" font-weight="bold">Capacitor 原生插件层</text><text x="530" y="201" fill="#666" text-anchor="middle" font-size="10">Filesystem · Share · App · StatusBar · Haptics</text><line x1="530" y1="210" x2="530" y2="220" stroke="#D35400" stroke-width="1.5"/><polygon points="530,225 525,215 535,215" fill="#D35400"/><rect x="390" y="225" width="280" height="95" rx="5" fill="#FDF2E9" stroke="#D35400" stroke-width="1"/><text x="530" y="248" fill="#333" text-anchor="middle" font-size="12" font-weight="bold">Web 渲染层 (共享代码)</text><line x1="410" y1="258" x2="650" y2="258" stroke="#BDC3C7" stroke-width="0.5"/><text x="530" y="275" fill="#555" text-anchor="middle" font-size="10">Milkdown 编辑器核心 (同一份代码)</text><text x="530" y="293" fill="#555" text-anchor="middle" font-size="10">├─ Math 显示插件 📐</text><text x="530" y="310" fill="#555" text-anchor="middle" font-size="10">└─ Mermaid 显示插件 🔀</text><rect x="160" y="350" width="400" height="22" rx="11" fill="#8E44AD" opacity="0.9"/><text x="360" y="365" fill="white" text-anchor="middle" font-size="11" font-weight="bold">桥接层抽象:const api = (isElectron) ? electronAPI : capacitorAPI</text></svg><div style="text-align: center;font-weight:bold;">
|
|
65
65
|
图1 ColaMD 双平台分层架构图
|
|
66
66
|
</div></div>
|
|
67
67
|
|
|
@@ -278,6 +278,7 @@ graph TD
|
|
|
278
278
|
<div style="text-align: center;font-weight:bold;">
|
|
279
279
|
表4 Mermaid 主题适配参数配置
|
|
280
280
|
</div>
|
|
281
|
+
|
|
281
282
|
### 4.4 关键实现特性
|
|
282
283
|
|
|
283
284
|
**(1)输入快捷转换**
|
package/docs/theme-paradigm.md
CHANGED
|
@@ -637,7 +637,145 @@ ColaMD 通过 Electron `printToPDF()` 生成 PDF,底层为 Chromium 打印引
|
|
|
637
637
|
|
|
638
638
|
---
|
|
639
639
|
|
|
640
|
-
##
|
|
640
|
+
## 9. 单位使用规范 (Unit Specification)
|
|
641
|
+
|
|
642
|
+
### 9.1 核心原则:统一使用 px 单位
|
|
643
|
+
|
|
644
|
+
**问题背景**:CSS 的 `pt` (point) 单位在不同渲染环境下的定义不一致:
|
|
645
|
+
- **CSS/屏幕渲染**:`1pt = 1/96 inch` (基于 96dpi)
|
|
646
|
+
- **PDF/PostScript**:`1pt = 1/72 inch` (基于 72dpi)
|
|
647
|
+
- **差异系数**:`72/96 = 0.75`,导致 PDF 导出时文字缩小约 **25%**
|
|
648
|
+
|
|
649
|
+
**解决方案**:所有主题文件必须统一使用 `px` (pixel) 单位。
|
|
650
|
+
|
|
651
|
+
#### Rule ID 级别规范
|
|
652
|
+
|
|
653
|
+
| Rule ID | 级别 | 规则 | 验证方法 |
|
|
654
|
+
|---------|------|------|---------|
|
|
655
|
+
| **UN-01** | MUST | 禁止使用 `pt` 单位定义字号、间距、边距等度量值 | 正则匹配:`\d+\.?\d*pt` 结果为空 |
|
|
656
|
+
| **UN-02** | MUST | 所有字号、间距、边距必须使用 `px` 单位 | 检查 `font-size`, `margin`, `padding`, `border-width` 等属性 |
|
|
657
|
+
| **UN-03** | SHOULD | px 值优先使用**偶数整数**(2, 4, 6, 8, ...) | 检查值为偶数 |
|
|
658
|
+
| **UN-04** | SHOULD NOT | 避免使用奇数 px 值(除非特殊需求如 1px 边框) | 奇数值数量 ≤ 总数量的 10% |
|
|
659
|
+
|
|
660
|
+
### 9.2 pt → px 转换规则
|
|
661
|
+
|
|
662
|
+
#### 转换公式
|
|
663
|
+
|
|
664
|
+
```python
|
|
665
|
+
def pt_to_px(pt_value):
|
|
666
|
+
"""将 pt 值转换为 px 并四舍五入到最近的偶数"""
|
|
667
|
+
px_value = pt_value * (96 / 72) # ≈ pt_value * 1.3333
|
|
668
|
+
rounded = round(px_value)
|
|
669
|
+
# 调整为偶数
|
|
670
|
+
if rounded % 2 != 0:
|
|
671
|
+
rounded += 1 if (rounded + 1 - px_value) < (rounded - 1 - px_value) else -1
|
|
672
|
+
return rounded
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
#### 常用字号转换对照表
|
|
676
|
+
|
|
677
|
+
| 原始值 (pt) | 计算值 (px) | 四舍五入 | 最终值 (px) | 用途说明 |
|
|
678
|
+
|-------------|-------------|---------|-------------|----------|
|
|
679
|
+
| 9 | 12.00 | 12 | **12** | 小五号/Mermaid 图表字 |
|
|
680
|
+
| 10.5 | 14.00 | 14 | **14** | 五号/代码块/表格/图题 |
|
|
681
|
+
| 11 | 14.67 | 15 | **14** | h5 标题 |
|
|
682
|
+
| 12 | 16.00 | 16 | **16** | 小四号/正文/h3-h4 |
|
|
683
|
+
| 14 | 18.67 | 19 | **18** | 四号/h2 |
|
|
684
|
+
| 16 | 21.33 | 21 | **22** | 三号/h1 |
|
|
685
|
+
| 18 | 24.00 | 24 | **24** | 二号 |
|
|
686
|
+
| 20 | 26.67 | 27 | **26** | 大间距 |
|
|
687
|
+
| 24 | 32.00 | 32 | **32** | 超大间距 |
|
|
688
|
+
|
|
689
|
+
### 9.3 各元素的 px 值推荐标准
|
|
690
|
+
|
|
691
|
+
#### 字号系统
|
|
692
|
+
|
|
693
|
+
| 元素 | 推荐值 (px) | 对应中文字号 | 说明 |
|
|
694
|
+
|------|------------|-------------|------|
|
|
695
|
+
| html/body 基础 | **16** | 小四号 (12pt) | 全局根字号 |
|
|
696
|
+
| h1 一级标题 | **22** | 三号 (16pt) | 论文题目 |
|
|
697
|
+
| h2 二级标题 | **18** | 四号 (14pt) | 一级节 |
|
|
698
|
+
| h3/h4 三四级标题 | **16** | 小四号 (12pt) | 二级节/三级节 |
|
|
699
|
+
| h5 五级标题 | **14** | 五号 (10.5pt) | - |
|
|
700
|
+
| h6 六级标题 | **14** | 五号 (10.5pt) | - |
|
|
701
|
+
| p 正文段落 | **16** | 小四号 (12pt) | 主要文本 |
|
|
702
|
+
| blockquote 引用块 | **14** | 五号 (10.5pt) | 引用内容 |
|
|
703
|
+
| pre/code 代码块 | **14** | 五号 (10.5pt) | 代码字体 |
|
|
704
|
+
| table 表格文字 | **14** | 五号 (10.5pt) | 表格内容 |
|
|
705
|
+
| figcaption 图题 | **14** | 五号 (10.5pt) | 图片/图表标题 |
|
|
706
|
+
| .mermaid Mermaid | **12** | 小五号 (9pt) | 图表内文字 |
|
|
707
|
+
| .footnotes 脚注 | **12** | 小五号 (9pt) | 脚注/参考文献 |
|
|
708
|
+
| .references 参考文献 | **12** | 小五号 (9pt) | 参考文献条目 |
|
|
709
|
+
|
|
710
|
+
#### 间距系统
|
|
711
|
+
|
|
712
|
+
| 元素 | 推荐值 (px) | 说明 |
|
|
713
|
+
|------|------------|------|
|
|
714
|
+
| margin-top (h1) | **32** | 一级标题段前 |
|
|
715
|
+
| margin-bottom (h1) | **24** | 一级标题段后 |
|
|
716
|
+
| margin-top (h2) | **26** | 二级标题段前 |
|
|
717
|
+
| margin-bottom (h2) | **14** | 二级标题段后 |
|
|
718
|
+
| margin-top (h3/h4) | **18** | 三四级标题段前 |
|
|
719
|
+
| margin-bottom (h3) | **10** | 三级标题段后 |
|
|
720
|
+
| margin-bottom (h4) | **8** | 四级标题段后 |
|
|
721
|
+
| margin (hr 分割线) | **32** | 分割线上下间距 |
|
|
722
|
+
| margin (blockquote) | **10** | 引用块上下间距 |
|
|
723
|
+
| margin (table) | **18** | 表格外边距 |
|
|
724
|
+
| margin (pre 代码块) | **16** | 代码块外边距 |
|
|
725
|
+
| margin (figure) | **16** | 图片外边距 |
|
|
726
|
+
| padding (th/td) | **8×10** | 表格单元格内边距 |
|
|
727
|
+
| border-width (三线表) | **2** | 表格顶线/底线/栏目线 |
|
|
728
|
+
| border-width (引用块左侧) | **3** | 引用块竖线宽度 |
|
|
729
|
+
|
|
730
|
+
### 9.4 特殊情况处理
|
|
731
|
+
|
|
732
|
+
#### 允许使用非 px 单位的场景
|
|
733
|
+
|
|
734
|
+
| 场景 | 允许的单位 | 示例 | 说明 |
|
|
735
|
+
|------|-----------|------|------|
|
|
736
|
+
| 页面尺寸 | `mm` | `max-width: 210mm` | A4 纸张规格 |
|
|
737
|
+
| 相对字号 | `em` | `font-size: 0.88em` | 内联代码相对正文缩小 |
|
|
738
|
+
| 百分比宽度 | `%` | `width: 100%` | 表格/容器宽度 |
|
|
739
|
+
| 无单位 | `0` | `margin: 0` | 零值无需单位 |
|
|
740
|
+
| 透明度/Alpha | 无单位 | `rgba(0,0,0,0.12)` | 颜色透明度 |
|
|
741
|
+
| 行高倍率 | 无单位 | `line-height: 1.5` | 相对行高 |
|
|
742
|
+
|
|
743
|
+
#### 必须保持为 1px 的场景
|
|
744
|
+
|
|
745
|
+
| 属性 | 值 | 说明 |
|
|
746
|
+
|------|-----|------|
|
|
747
|
+
| 细边框 | `1px solid` | 分割线、表格竖线(需最细效果) |
|
|
748
|
+
| 内联代码边框 | `border: none` 或 `1px` | 通常无边框或极细边框 |
|
|
749
|
+
|
|
750
|
+
### 9.5 迁移指南:从 pt 到 px
|
|
751
|
+
|
|
752
|
+
#### 自动化转换脚本
|
|
753
|
+
|
|
754
|
+
```bash
|
|
755
|
+
# 使用 sed 批量替换(示例)
|
|
756
|
+
sed -i 's/12pt/16px/g; s/10\.5pt/14px/g; s/9pt/12px/g' theme.css
|
|
757
|
+
```
|
|
758
|
+
|
|
759
|
+
#### 手动验证清单
|
|
760
|
+
|
|
761
|
+
- [ ] 运行 `grep -n "pt" theme.css` 确认无残留
|
|
762
|
+
- [ ] 在浏览器中预览确认视觉大小符合预期
|
|
763
|
+
- [ ] 导出 PDF 验证字号与屏幕显示一致
|
|
764
|
+
- [ ] 检查打印预览 (@media print) 是否同步更新
|
|
765
|
+
|
|
766
|
+
### 9.6 设计理由
|
|
767
|
+
|
|
768
|
+
采用 **px 偶数整数** 规范的理由:
|
|
769
|
+
|
|
770
|
+
1. **跨平台一致性**:px 在所有现代浏览器和 PDF 渲染引擎中的定义一致(1/96 inch)
|
|
771
|
+
2. **避免缩放损失**:消除 CSS→PDF 转换时的 25% 尺寸差异
|
|
772
|
+
3. **渲染优化**:偶数像素值在次像素渲染(sub-pixel rendering)中表现更优,避免模糊
|
|
773
|
+
4. **可维护性**:整数比小数更易读、易比较、易计算
|
|
774
|
+
5. **GB/T 7713 合规**:确保学术论文排版在屏幕和印刷品上的视觉效果一致
|
|
775
|
+
|
|
776
|
+
---
|
|
777
|
+
|
|
778
|
+
## 10. 现有主题对标
|
|
641
779
|
|
|
642
780
|
| 主题 | 行数 | 范式符合度 | 迁移建议 |
|
|
643
781
|
|------|------|-----------|---------|
|
|
@@ -649,10 +787,11 @@ ColaMD 通过 Electron `printToPDF()` 生成 PDF,底层为 Chromium 打印引
|
|
|
649
787
|
|
|
650
788
|
---
|
|
651
789
|
|
|
652
|
-
##
|
|
790
|
+
## 11. 版本历史
|
|
653
791
|
|
|
654
792
|
| 版本 | 日期 | 变更 |
|
|
655
793
|
|------|------|------|
|
|
794
|
+
| v3.3 | 2026-05-23 | 新增 Section 9「单位使用规范」:强制使用 px 单位、pt→px 转换公式、偶数整数推荐标准、迁移指南 |
|
|
656
795
|
| v3.2 | 2026-05-23 | 新增 Section 2「设计规范」:色彩空间、字体搭配、表面层次、线条边框的强制性约束(含 Rule ID、WCAG 对比度公式、色彩协调矩阵),支持 AI Agent 程序化验证 |
|
|
657
796
|
| v3.1 | 2026-05-23 | 新增「打印保真」原则与完整 `@media print` 规范(Section 6) |
|
|
658
797
|
| v3.0 | 2026-05-23 | 初始范式定义。提出种子色板 + 语义映射 + 内置继承的三层架构 |
|
package/package.json
CHANGED
package/src/main/index.ts
CHANGED
|
@@ -8,6 +8,17 @@ import { createServer as createHttpServer } from 'http'
|
|
|
8
8
|
// Custom themes directory
|
|
9
9
|
const themesDir = join(app.getPath('home'), '.colamd', 'themes')
|
|
10
10
|
|
|
11
|
+
// PDF 导出时注入的布局 CSS(insertCSS 引擎级注入,仅负责页面结构调整)
|
|
12
|
+
const BASE_PRINT_CSS = [
|
|
13
|
+
'html, body { height:auto !important; overflow:visible !important; -webkit-print-color-adjust:exact !important; print-color-adjust:exact !important; }',
|
|
14
|
+
'#titlebar, #slides-btn, #agent-dot { display:none !important; }',
|
|
15
|
+
'#editor { height:auto !important; overflow:visible !important; }',
|
|
16
|
+
'#editor .ProseMirror { min-height:auto !important; }',
|
|
17
|
+
'.mermaid-error, .mermaid-loading { display:none !important; }',
|
|
18
|
+
'svg .error-icon, svg .error-text { display:none !important; }',
|
|
19
|
+
'.math-inline-raw, .math-block-raw, textarea.mermaid-source { display:none !important; }',
|
|
20
|
+
].join('\n')
|
|
21
|
+
|
|
11
22
|
function ensureThemesDir(): void {
|
|
12
23
|
if (!existsSync(themesDir)) {
|
|
13
24
|
mkdir(themesDir, { recursive: true }).catch(() => {})
|
|
@@ -69,6 +80,8 @@ function createWindow(filePath?: string): BrowserWindow {
|
|
|
69
80
|
}
|
|
70
81
|
|
|
71
82
|
win.webContents.on('did-finish-load', () => {
|
|
83
|
+
// 开发环境自动打开 DevTools 方便调试
|
|
84
|
+
// win.webContents.openDevTools({ mode: 'bottom' })
|
|
72
85
|
if (filePath) {
|
|
73
86
|
loadFileInWindow(win, filePath)
|
|
74
87
|
}
|
|
@@ -378,7 +391,7 @@ ipcMain.handle('save-export-file', async (event, dataUrl: string, defaultName: s
|
|
|
378
391
|
})
|
|
379
392
|
|
|
380
393
|
|
|
381
|
-
ipcMain.handle('export-pdf', async (event) => {
|
|
394
|
+
ipcMain.handle('export-pdf', async (event, printCSS?: string) => {
|
|
382
395
|
const win = getWinFromEvent(event)
|
|
383
396
|
if (!win) return false
|
|
384
397
|
const defaultName = (suggestFileName(win) || 'colamd-print') + '.pdf'
|
|
@@ -389,9 +402,9 @@ ipcMain.handle('export-pdf', async (event) => {
|
|
|
389
402
|
if (result.canceled || !result.filePath) return false
|
|
390
403
|
|
|
391
404
|
try {
|
|
392
|
-
const cssKey = await win.webContents.insertCSS(
|
|
393
|
-
|
|
394
|
-
)
|
|
405
|
+
const cssKey = await win.webContents.insertCSS(BASE_PRINT_CSS + '\n' + (printCSS || ''))
|
|
406
|
+
// 等待样式重排完成(Chromium 需要一帧来应用注入的 CSS)
|
|
407
|
+
await new Promise(r => setTimeout(r, 200))
|
|
395
408
|
const pdfData = await Promise.race([
|
|
396
409
|
win.webContents.printToPDF({
|
|
397
410
|
printBackground: true,
|
|
@@ -402,7 +415,8 @@ ipcMain.handle('export-pdf', async (event) => {
|
|
|
402
415
|
await win.webContents.removeInsertedCSS(cssKey)
|
|
403
416
|
await writeFile(result.filePath, pdfData)
|
|
404
417
|
return true
|
|
405
|
-
} catch {
|
|
418
|
+
} catch (e) {
|
|
419
|
+
console.error('[export-pdf] PDF export failed:', e)
|
|
406
420
|
return false
|
|
407
421
|
}
|
|
408
422
|
})
|
package/src/preload/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ export interface ElectronAPI {
|
|
|
5
5
|
openFilePath: (path: string) => Promise<{ path: string; content: string } | null>
|
|
6
6
|
saveFile: (content: string) => Promise<boolean>
|
|
7
7
|
saveFileAs: (content: string) => Promise<boolean>
|
|
8
|
-
exportPDF: () => Promise<boolean>
|
|
8
|
+
exportPDF: (printCSS?: string) => Promise<boolean>
|
|
9
9
|
exportHTML: (html: string) => Promise<boolean>
|
|
10
10
|
newSlides: () => Promise<string | null>
|
|
11
11
|
openAsSlides: (content: string) => Promise<boolean>
|
|
@@ -41,7 +41,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
|
|
41
41
|
openFilePath: (path: string) => ipcRenderer.invoke('open-file-path', path),
|
|
42
42
|
saveFile: (content: string) => ipcRenderer.invoke('save-file', content),
|
|
43
43
|
saveFileAs: (content: string) => ipcRenderer.invoke('save-file-as', content),
|
|
44
|
-
exportPDF: () => ipcRenderer.invoke('export-pdf'),
|
|
44
|
+
exportPDF: (printCSS?: string) => ipcRenderer.invoke('export-pdf', printCSS),
|
|
45
45
|
exportHTML: (html: string) => ipcRenderer.invoke('export-html', html),
|
|
46
46
|
exportSlides: (content: string) => ipcRenderer.invoke('export-slides', content),
|
|
47
47
|
newSlides: () => ipcRenderer.invoke('new-slides'),
|
|
@@ -9,7 +9,7 @@ import { listener, listenerCtx } from '@milkdown/kit/plugin/listener'
|
|
|
9
9
|
import { clipboard } from '@milkdown/kit/plugin/clipboard'
|
|
10
10
|
import { replaceAll } from '@milkdown/kit/utils'
|
|
11
11
|
import { htmlView } from './html-view'
|
|
12
|
-
import { getAllPluginModules } from './plugins'
|
|
12
|
+
import { getAllPluginModules, getAllPlugins } from './plugins'
|
|
13
13
|
|
|
14
14
|
import '@milkdown/kit/prose/view/style/prosemirror.css'
|
|
15
15
|
|
|
@@ -54,19 +54,14 @@ function enhanceClipboard(e: ClipboardEvent): void {
|
|
|
54
54
|
;(el as HTMLElement).setAttribute('style', 'background:none;padding:0;font-size:.875em;line-height:1.6;font-family:Menlo,Monaco,monospace;')
|
|
55
55
|
})
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
;(el as HTMLElement).setAttribute('style', 'display:block;padding:16px;margin:1em 0;border-radius:6px;background:#f6f8fa;border:1px solid #d0d7de;')
|
|
66
|
-
})
|
|
67
|
-
doc.querySelectorAll('.mermaid-preview svg').forEach((el) => {
|
|
68
|
-
;(el as HTMLElement).setAttribute('style', 'max-width:100%;height:auto;')
|
|
69
|
-
})
|
|
57
|
+
for (const p of getAllPlugins()) {
|
|
58
|
+
if (!p.enabled || !p.clipboardStyles) continue
|
|
59
|
+
for (const [selector, style] of Object.entries(p.clipboardStyles)) {
|
|
60
|
+
doc.querySelectorAll(selector).forEach((el) => {
|
|
61
|
+
;(el as HTMLElement).setAttribute('style', style)
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
}
|
|
70
65
|
|
|
71
66
|
e.clipboardData?.setData('text/html', doc.body.innerHTML)
|
|
72
67
|
}
|
|
@@ -112,9 +107,12 @@ export async function createEditor(
|
|
|
112
107
|
try {
|
|
113
108
|
editorInstance = await builder.create()
|
|
114
109
|
} catch (e: any) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
const offendingModule = pluginModules.find((m) =>
|
|
111
|
+
m.info.nodeTypes?.some((nt) => e?.message?.includes(nt))
|
|
112
|
+
)
|
|
113
|
+
if (offendingModule) {
|
|
114
|
+
console.warn('[editor] Milkdown context error, retrying without plugin:', offendingModule.info.id, e.message)
|
|
115
|
+
const filteredModules = pluginModules.filter((m) => m !== offendingModule)
|
|
118
116
|
builder = Editor.make()
|
|
119
117
|
.config((ctx) => {
|
|
120
118
|
ctx.set(rootCtx, root)
|
|
@@ -148,7 +146,7 @@ export async function createEditor(
|
|
|
148
146
|
const fixed = nvs.map((nv: any, i: number) => {
|
|
149
147
|
if (nv[0] != null) return nv
|
|
150
148
|
const viewFn = nv[1]
|
|
151
|
-
const fallbackNames =
|
|
149
|
+
const fallbackNames = pluginModules.flatMap((m) => m.info.nodeTypes || [])
|
|
152
150
|
const name = fallbackNames[i - 1]
|
|
153
151
|
if (name && schema.nodes[name]) {
|
|
154
152
|
return [name, viewFn]
|
|
@@ -224,30 +222,32 @@ export function getLiveHTML(): string {
|
|
|
224
222
|
if (!editorDom) return ''
|
|
225
223
|
const clone = editorDom.cloneNode(true) as HTMLElement
|
|
226
224
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
if (val && clones[i]) (clones[i] as HTMLElement).style.setProperty(prop, val)
|
|
241
|
-
})
|
|
225
|
+
const plugins = getAllPlugins().filter((p) => p.enabled)
|
|
226
|
+
|
|
227
|
+
// Inline computed background colors from plugin-declared selectors
|
|
228
|
+
for (const p of plugins) {
|
|
229
|
+
if (!p.bgCaptureSelectors) continue
|
|
230
|
+
for (const selector of p.bgCaptureSelectors) {
|
|
231
|
+
const originals = editorDom.querySelectorAll(selector)
|
|
232
|
+
const clones = clone.querySelectorAll(selector)
|
|
233
|
+
originals.forEach((orig, i) => {
|
|
234
|
+
const val = getComputedStyle(orig).backgroundColor
|
|
235
|
+
if (val && clones[i]) (clones[i] as HTMLElement).style.backgroundColor = val
|
|
236
|
+
})
|
|
237
|
+
}
|
|
242
238
|
}
|
|
243
239
|
|
|
244
|
-
// Remove source
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
240
|
+
// Remove raw-source textareas declared by plugins
|
|
241
|
+
const rawSelectors = plugins.flatMap((p) => p.rawSelectors || [])
|
|
242
|
+
if (rawSelectors.length) {
|
|
243
|
+
clone.querySelectorAll(rawSelectors.join(',')).forEach((el) => el.remove())
|
|
244
|
+
}
|
|
245
|
+
// Hide loading/error placeholders declared by plugins
|
|
246
|
+
const hideSelectors = plugins.flatMap((p) => p.hideSelectors || [])
|
|
247
|
+
if (hideSelectors.length) {
|
|
248
|
+
clone.querySelectorAll(hideSelectors.join(',')).forEach((el) => (el as HTMLElement).style.display = 'none')
|
|
249
|
+
}
|
|
250
|
+
return `<div id="write">${clone.innerHTML}</div>`
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
export function getHTML(): string {
|
|
@@ -23,6 +23,16 @@ export interface RendererPlugin {
|
|
|
23
23
|
exportCapabilities?: ExportCapability[]
|
|
24
24
|
renderStatus?: (container: HTMLElement) => Promise<{ ok: number; fail: number; total: number }>
|
|
25
25
|
ensureRendered?: () => Promise<void>
|
|
26
|
+
/** Selector→inline-style pairs applied during clipboard copy/cut */
|
|
27
|
+
clipboardStyles?: Record<string, string>
|
|
28
|
+
/** CSS rules injected into HTML export (use var(--...) for theme colors) */
|
|
29
|
+
exportStyles?: string
|
|
30
|
+
/** Selectors for raw-source textareas/inputs (blurred on save, removed on export) */
|
|
31
|
+
rawSelectors?: string[]
|
|
32
|
+
/** Selectors for loading/error placeholder elements (hidden during export) */
|
|
33
|
+
hideSelectors?: string[]
|
|
34
|
+
/** Selectors for elements needing computed background-color captured during clone */
|
|
35
|
+
bgCaptureSelectors?: string[]
|
|
26
36
|
}
|
|
27
37
|
|
|
28
38
|
export interface PluginModule {
|
|
@@ -65,4 +75,12 @@ export function findExportCapabilities(className: string): ExportCapability[] {
|
|
|
65
75
|
export function togglePlugin(id: string, enabled: boolean): void {
|
|
66
76
|
const mod = modules.find((m) => m.info.id === id)
|
|
67
77
|
if (mod) mod.info.enabled = enabled
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Build a CSS selector matching all export-capable plugin block elements */
|
|
81
|
+
export function getContextMenuSelector(): string {
|
|
82
|
+
return getAllPlugins()
|
|
83
|
+
.filter((p) => p.exportCapabilities && p.exportCapabilities.length > 0)
|
|
84
|
+
.flatMap((p) => (p.nodeTypes || []).map((nt) => '.' + nt.replace(/_/g, '-')))
|
|
85
|
+
.join(', ')
|
|
68
86
|
}
|
|
@@ -272,6 +272,14 @@ export const mathPlugin: RendererPlugin = {
|
|
|
272
272
|
enabled: true,
|
|
273
273
|
remarkPlugin: { plugin: remarkMath, options: undefined },
|
|
274
274
|
nodeTypes: ['math_inline', 'math_block'],
|
|
275
|
+
clipboardStyles: {
|
|
276
|
+
'.math-inline': 'display:inline;padding:2px 4px;border-radius:3px;background:rgba(175,184,193,0.2);',
|
|
277
|
+
'.math-block': 'display:block;padding:16px;margin:1em 0;border-radius:6px;background:#f6f8fa;text-align:center;overflow-x:auto;',
|
|
278
|
+
},
|
|
279
|
+
exportStyles: `.math-inline{display:inline;padding:2px 4px;border-radius:3px;background:var(--code-bg)}
|
|
280
|
+
.math-block{display:block;padding:16px;margin:1em 0;border-radius:6px;background:var(--code-block-bg);text-align:center;overflow-x:auto}`,
|
|
281
|
+
rawSelectors: ['.math-inline-raw', '.math-block-raw'],
|
|
282
|
+
bgCaptureSelectors: ['.math-inline', '.math-block'],
|
|
275
283
|
// TODO: KaTeX CSS 在 SVG foreignObject 中丢失,导致导出 PNG 二次内容/空白
|
|
276
284
|
// 后续需解决样式注入问题后重新启用
|
|
277
285
|
// exportCapabilities: [
|
|
@@ -617,6 +617,16 @@ export const mermaidPlugin: RendererPlugin = {
|
|
|
617
617
|
enabled: true,
|
|
618
618
|
remarkPlugin: { plugin: remarkMermaid, options: undefined },
|
|
619
619
|
nodeTypes: ['mermaid_block'],
|
|
620
|
+
clipboardStyles: {
|
|
621
|
+
'.mermaid-block': 'display:block;padding:16px;margin:1em 0;border-radius:6px;background:#f6f8fa;border:1px solid #d0d7de;',
|
|
622
|
+
'.mermaid-preview svg': 'max-width:100%;height:auto;',
|
|
623
|
+
},
|
|
624
|
+
exportStyles: `.mermaid-block{display:block;padding:16px;margin:1em 0;border-radius:6px;background:var(--mermaid-background,var(--bg-color));border:1px solid var(--border-color)}
|
|
625
|
+
.mermaid-preview{display:flex;justify-content:center;align-items:center}
|
|
626
|
+
.mermaid-preview svg{max-width:100%;height:auto}`,
|
|
627
|
+
rawSelectors: ['textarea.mermaid-source'],
|
|
628
|
+
hideSelectors: ['.mermaid-loading', '.mermaid-error'],
|
|
629
|
+
bgCaptureSelectors: ['.mermaid-block'],
|
|
620
630
|
exportCapabilities: [
|
|
621
631
|
{
|
|
622
632
|
label: 'Save Diagram as PNG',
|
|
@@ -89,4 +89,45 @@ export function applyTheme(name: string, customCSS?: string): void {
|
|
|
89
89
|
|
|
90
90
|
export function loadSavedTheme(): string {
|
|
91
91
|
return localStorage.getItem('colamd-theme') || 'elegant'
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 获取当前激活的自定义主题 CSS 内容;非自定义主题返回 null */
|
|
95
|
+
export function getActiveCustomThemeCSS(): string | null {
|
|
96
|
+
const name = loadSavedTheme()
|
|
97
|
+
if (name.startsWith('custom:')) {
|
|
98
|
+
const key = name.slice(7)
|
|
99
|
+
return customThemeCache.get(key)?.css || null
|
|
100
|
+
}
|
|
101
|
+
return null
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 从缓存的原始 CSS 文本中提取 @media print 规则块。
|
|
106
|
+
* 使用字符串括号计数而非 CSSOM 序列化,避免 Chromium 对嵌套 at-rule
|
|
107
|
+
*(如 @page 内的 @bottom-center)的序列化丢失问题。
|
|
108
|
+
* @returns 完整的 @media print { ... } 规则文本,无自定义主题或无 print 块返回 null
|
|
109
|
+
*/
|
|
110
|
+
export function extractPrintCSSFromSheet(): string | null {
|
|
111
|
+
const name = loadSavedTheme()
|
|
112
|
+
if (!name.startsWith('custom:')) return null
|
|
113
|
+
const key = name.slice(7)
|
|
114
|
+
const cached = customThemeCache.get(key)
|
|
115
|
+
if (!cached) return null
|
|
116
|
+
|
|
117
|
+
const css = cached.css
|
|
118
|
+
const startIdx = css.indexOf('@media print')
|
|
119
|
+
if (startIdx === -1) return null
|
|
120
|
+
|
|
121
|
+
const openBrace = css.indexOf('{', startIdx)
|
|
122
|
+
if (openBrace === -1) return null
|
|
123
|
+
|
|
124
|
+
let depth = 1
|
|
125
|
+
let i = openBrace + 1
|
|
126
|
+
while (i < css.length && depth > 0) {
|
|
127
|
+
if (css[i] === '{') depth++
|
|
128
|
+
else if (css[i] === '}') depth--
|
|
129
|
+
i++
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return css.substring(startIdx, i)
|
|
92
133
|
}
|