vscode-colaview 0.4.0 → 0.4.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/.release-notes-v0.4.1.md +29 -0
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +45 -32
- package/README.md +13 -6
- package/README_CN.md +12 -5
- package/RELEASE_NOTES.md +46 -19
- package/package.json +204 -203
- package/src/export/pdf-exporter.ts +4 -0
- package/src/present/presenter.ts +25 -0
- package/src/preview/webview/app.ts +107 -0
- package/src/slides/deck.ts +11 -0
- package/src/slides/markdown.ts +27 -0
- package/src/slides/render.ts +106 -10
- package/src/themes/built-in/bear.css +89 -89
- package/src/themes/built-in/dark.css +87 -87
- package/src/themes/built-in/dracula.css +93 -93
- package/src/themes/built-in/elegant.css +109 -109
- package/src/themes/built-in/gruvbox.css +97 -97
- package/src/themes/built-in/light.css +80 -80
- package/src/themes/built-in/midnight.css +93 -93
- package/src/themes/built-in/nord.css +93 -93
- package/src/themes/built-in/notion.css +98 -98
- package/src/themes/built-in/sepia.css +99 -99
- package/src/themes/built-in/solarized-dark.css +94 -94
- package/src/themes/built-in/writer.css +99 -99
- package/src/types/pele-lazy.d.ts +21 -0
package/package.json
CHANGED
|
@@ -1,203 +1,204 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "vscode-colaview",
|
|
3
|
-
"displayName": "ColaView MD",
|
|
4
|
-
"version": "0.4.
|
|
5
|
-
"publisher": "bytechain",
|
|
6
|
-
"description": "ColaMD Preview — Rich Markdown Preview & PDF/HTML Export for VSCode",
|
|
7
|
-
"icon": "icon.png",
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "https://github.com/bytechain/vscode-colaview.git"
|
|
11
|
-
},
|
|
12
|
-
"license": "MIT",
|
|
13
|
-
"engines": {
|
|
14
|
-
"vscode": "^1.85.0"
|
|
15
|
-
},
|
|
16
|
-
"categories": [
|
|
17
|
-
"Other"
|
|
18
|
-
],
|
|
19
|
-
"activationEvents": [
|
|
20
|
-
"onLanguage:markdown",
|
|
21
|
-
"onCommand:colaview.showPreview",
|
|
22
|
-
"onCommand:colaview.showSlides",
|
|
23
|
-
"onCommand:colaview.presentDocument",
|
|
24
|
-
"onCommand:colaview.presentSlides",
|
|
25
|
-
"onCommand:colaview.exportPDF",
|
|
26
|
-
"onCommand:colaview.exportHTML",
|
|
27
|
-
"onCommand:colaview.exportWord",
|
|
28
|
-
"onCommand:colaview.exportSlidesPDF",
|
|
29
|
-
"onCommand:colaview.exportSlidesHTML",
|
|
30
|
-
"onCommand:colaview.exportPPTX"
|
|
31
|
-
],
|
|
32
|
-
"main": "./out/extension.js",
|
|
33
|
-
"contributes": {
|
|
34
|
-
"commands": [
|
|
35
|
-
{
|
|
36
|
-
"command": "colaview.showPreview",
|
|
37
|
-
"title": "%colaview.commands.showPreview%",
|
|
38
|
-
"icon": "$(open-preview)"
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
"command": "colaview.showSlides",
|
|
42
|
-
"title": "%colaview.commands.showSlides%",
|
|
43
|
-
"icon": "$(preview)"
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
"command": "colaview.presentDocument",
|
|
47
|
-
"title": "%colaview.commands.presentDocument%"
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
"command": "colaview.presentSlides",
|
|
51
|
-
"title": "%colaview.commands.presentSlides%"
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
"command": "colaview.exportPDF",
|
|
55
|
-
"title": "%colaview.commands.exportPDF%",
|
|
56
|
-
"icon": "$(export)"
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
"command": "colaview.exportHTML",
|
|
60
|
-
"title": "%colaview.commands.exportHTML%",
|
|
61
|
-
"icon": "$(export)"
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
"command": "colaview.exportWord",
|
|
65
|
-
"title": "%colaview.commands.exportWord%",
|
|
66
|
-
"icon": "$(export)"
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
"command": "colaview.exportSlidesPDF",
|
|
70
|
-
"title": "%colaview.commands.exportSlidesPDF%"
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
"command": "colaview.exportSlidesHTML",
|
|
74
|
-
"title": "%colaview.commands.exportSlidesHTML%"
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
"command": "colaview.exportPPTX",
|
|
78
|
-
"title": "%colaview.commands.exportPPTX%"
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
"command": "colaview.switchTheme",
|
|
82
|
-
"title": "%colaview.commands.switchTheme%"
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
"command": "colaview.importTheme",
|
|
86
|
-
"title": "%colaview.commands.importTheme%"
|
|
87
|
-
}
|
|
88
|
-
],
|
|
89
|
-
"menus": {
|
|
90
|
-
"editor/title": [
|
|
91
|
-
{
|
|
92
|
-
"command": "colaview.showPreview",
|
|
93
|
-
"group": "navigation"
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
"command": "colaview.showSlides",
|
|
97
|
-
"group": "navigation"
|
|
98
|
-
}
|
|
99
|
-
],
|
|
100
|
-
"editor/context": [
|
|
101
|
-
{
|
|
102
|
-
"command": "colaview.showPreview",
|
|
103
|
-
"group": "1_colaview"
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
"command": "colaview.showSlides",
|
|
107
|
-
"group": "1_colaview"
|
|
108
|
-
}
|
|
109
|
-
],
|
|
110
|
-
"explorer/context": [
|
|
111
|
-
{
|
|
112
|
-
"command": "colaview.exportPDF",
|
|
113
|
-
"group": "1_colaview"
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
"command": "colaview.exportHTML",
|
|
117
|
-
"group": "1_colaview"
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
"command": "colaview.exportWord",
|
|
121
|
-
"group": "1_colaview"
|
|
122
|
-
}
|
|
123
|
-
]
|
|
124
|
-
},
|
|
125
|
-
"configuration": {
|
|
126
|
-
"title": "ColaView MD",
|
|
127
|
-
"properties": {
|
|
128
|
-
"colaview.theme": {
|
|
129
|
-
"type": "string",
|
|
130
|
-
"default": "elegant",
|
|
131
|
-
"enum": [
|
|
132
|
-
"light",
|
|
133
|
-
"dark",
|
|
134
|
-
"elegant",
|
|
135
|
-
"sepia",
|
|
136
|
-
"notion",
|
|
137
|
-
"bear",
|
|
138
|
-
"writer",
|
|
139
|
-
"solarized-dark",
|
|
140
|
-
"nord",
|
|
141
|
-
"gruvbox",
|
|
142
|
-
"dracula",
|
|
143
|
-
"midnight"
|
|
144
|
-
],
|
|
145
|
-
"description": "Visual theme for preview and export"
|
|
146
|
-
},
|
|
147
|
-
"colaview.autoPreview": {
|
|
148
|
-
"type": "boolean",
|
|
149
|
-
"default": false,
|
|
150
|
-
"description": "Auto show preview on opening Markdown"
|
|
151
|
-
},
|
|
152
|
-
"colaview.scrollSync": {
|
|
153
|
-
"type": "boolean",
|
|
154
|
-
"default": false,
|
|
155
|
-
"description": "Enable scroll sync between editor and preview"
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
"keybindings": [
|
|
160
|
-
{
|
|
161
|
-
"command": "colaview.showPreview",
|
|
162
|
-
"key": "ctrl+alt+v",
|
|
163
|
-
"when": "editorLangId == markdown"
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
"command": "colaview.showSlides",
|
|
167
|
-
"key": "ctrl+alt+s",
|
|
168
|
-
"when": "editorLangId == markdown"
|
|
169
|
-
}
|
|
170
|
-
]
|
|
171
|
-
},
|
|
172
|
-
"scripts": {
|
|
173
|
-
"vscode:prepublish": "npm run esbuild-base -- --production",
|
|
174
|
-
"esbuild-base": "node esbuild.js",
|
|
175
|
-
"build": "node esbuild.js",
|
|
176
|
-
"watch": "node esbuild.js --watch",
|
|
177
|
-
"pretest": "npm run build",
|
|
178
|
-
"test": "node ./out/test/runTest.js",
|
|
179
|
-
"package": "vsce package",
|
|
180
|
-
"postinstall": "patch-package"
|
|
181
|
-
},
|
|
182
|
-
"dependencies": {
|
|
183
|
-
"@bytechain.cn/colamd": "2.8.2",
|
|
184
|
-
"docx": "^9.15.2",
|
|
185
|
-
"katex": "^0.16.47",
|
|
186
|
-
"mermaid": "^11.15.0",
|
|
187
|
-
"
|
|
188
|
-
"
|
|
189
|
-
"remark-
|
|
190
|
-
"
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
"@types/
|
|
195
|
-
"@types/
|
|
196
|
-
"@vscode
|
|
197
|
-
"@vscode/
|
|
198
|
-
"
|
|
199
|
-
"
|
|
200
|
-
"
|
|
201
|
-
"
|
|
202
|
-
|
|
203
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "vscode-colaview",
|
|
3
|
+
"displayName": "ColaView MD",
|
|
4
|
+
"version": "0.4.1",
|
|
5
|
+
"publisher": "bytechain",
|
|
6
|
+
"description": "ColaMD Preview — Rich Markdown Preview & PDF/HTML Export for VSCode",
|
|
7
|
+
"icon": "icon.png",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/bytechain/vscode-colaview.git"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"engines": {
|
|
14
|
+
"vscode": "^1.85.0"
|
|
15
|
+
},
|
|
16
|
+
"categories": [
|
|
17
|
+
"Other"
|
|
18
|
+
],
|
|
19
|
+
"activationEvents": [
|
|
20
|
+
"onLanguage:markdown",
|
|
21
|
+
"onCommand:colaview.showPreview",
|
|
22
|
+
"onCommand:colaview.showSlides",
|
|
23
|
+
"onCommand:colaview.presentDocument",
|
|
24
|
+
"onCommand:colaview.presentSlides",
|
|
25
|
+
"onCommand:colaview.exportPDF",
|
|
26
|
+
"onCommand:colaview.exportHTML",
|
|
27
|
+
"onCommand:colaview.exportWord",
|
|
28
|
+
"onCommand:colaview.exportSlidesPDF",
|
|
29
|
+
"onCommand:colaview.exportSlidesHTML",
|
|
30
|
+
"onCommand:colaview.exportPPTX"
|
|
31
|
+
],
|
|
32
|
+
"main": "./out/extension.js",
|
|
33
|
+
"contributes": {
|
|
34
|
+
"commands": [
|
|
35
|
+
{
|
|
36
|
+
"command": "colaview.showPreview",
|
|
37
|
+
"title": "%colaview.commands.showPreview%",
|
|
38
|
+
"icon": "$(open-preview)"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"command": "colaview.showSlides",
|
|
42
|
+
"title": "%colaview.commands.showSlides%",
|
|
43
|
+
"icon": "$(preview)"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"command": "colaview.presentDocument",
|
|
47
|
+
"title": "%colaview.commands.presentDocument%"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"command": "colaview.presentSlides",
|
|
51
|
+
"title": "%colaview.commands.presentSlides%"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"command": "colaview.exportPDF",
|
|
55
|
+
"title": "%colaview.commands.exportPDF%",
|
|
56
|
+
"icon": "$(export)"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"command": "colaview.exportHTML",
|
|
60
|
+
"title": "%colaview.commands.exportHTML%",
|
|
61
|
+
"icon": "$(export)"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"command": "colaview.exportWord",
|
|
65
|
+
"title": "%colaview.commands.exportWord%",
|
|
66
|
+
"icon": "$(export)"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"command": "colaview.exportSlidesPDF",
|
|
70
|
+
"title": "%colaview.commands.exportSlidesPDF%"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"command": "colaview.exportSlidesHTML",
|
|
74
|
+
"title": "%colaview.commands.exportSlidesHTML%"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"command": "colaview.exportPPTX",
|
|
78
|
+
"title": "%colaview.commands.exportPPTX%"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"command": "colaview.switchTheme",
|
|
82
|
+
"title": "%colaview.commands.switchTheme%"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"command": "colaview.importTheme",
|
|
86
|
+
"title": "%colaview.commands.importTheme%"
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"menus": {
|
|
90
|
+
"editor/title": [
|
|
91
|
+
{
|
|
92
|
+
"command": "colaview.showPreview",
|
|
93
|
+
"group": "navigation"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"command": "colaview.showSlides",
|
|
97
|
+
"group": "navigation"
|
|
98
|
+
}
|
|
99
|
+
],
|
|
100
|
+
"editor/context": [
|
|
101
|
+
{
|
|
102
|
+
"command": "colaview.showPreview",
|
|
103
|
+
"group": "1_colaview"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"command": "colaview.showSlides",
|
|
107
|
+
"group": "1_colaview"
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
"explorer/context": [
|
|
111
|
+
{
|
|
112
|
+
"command": "colaview.exportPDF",
|
|
113
|
+
"group": "1_colaview"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"command": "colaview.exportHTML",
|
|
117
|
+
"group": "1_colaview"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"command": "colaview.exportWord",
|
|
121
|
+
"group": "1_colaview"
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
"configuration": {
|
|
126
|
+
"title": "ColaView MD",
|
|
127
|
+
"properties": {
|
|
128
|
+
"colaview.theme": {
|
|
129
|
+
"type": "string",
|
|
130
|
+
"default": "elegant",
|
|
131
|
+
"enum": [
|
|
132
|
+
"light",
|
|
133
|
+
"dark",
|
|
134
|
+
"elegant",
|
|
135
|
+
"sepia",
|
|
136
|
+
"notion",
|
|
137
|
+
"bear",
|
|
138
|
+
"writer",
|
|
139
|
+
"solarized-dark",
|
|
140
|
+
"nord",
|
|
141
|
+
"gruvbox",
|
|
142
|
+
"dracula",
|
|
143
|
+
"midnight"
|
|
144
|
+
],
|
|
145
|
+
"description": "Visual theme for preview and export"
|
|
146
|
+
},
|
|
147
|
+
"colaview.autoPreview": {
|
|
148
|
+
"type": "boolean",
|
|
149
|
+
"default": false,
|
|
150
|
+
"description": "Auto show preview on opening Markdown"
|
|
151
|
+
},
|
|
152
|
+
"colaview.scrollSync": {
|
|
153
|
+
"type": "boolean",
|
|
154
|
+
"default": false,
|
|
155
|
+
"description": "Enable scroll sync between editor and preview"
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
"keybindings": [
|
|
160
|
+
{
|
|
161
|
+
"command": "colaview.showPreview",
|
|
162
|
+
"key": "ctrl+alt+v",
|
|
163
|
+
"when": "editorLangId == markdown"
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"command": "colaview.showSlides",
|
|
167
|
+
"key": "ctrl+alt+s",
|
|
168
|
+
"when": "editorLangId == markdown"
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
},
|
|
172
|
+
"scripts": {
|
|
173
|
+
"vscode:prepublish": "npm run esbuild-base -- --production",
|
|
174
|
+
"esbuild-base": "node esbuild.js",
|
|
175
|
+
"build": "node esbuild.js",
|
|
176
|
+
"watch": "node esbuild.js --watch",
|
|
177
|
+
"pretest": "npm run build",
|
|
178
|
+
"test": "node ./out/test/runTest.js",
|
|
179
|
+
"package": "vsce package",
|
|
180
|
+
"postinstall": "patch-package"
|
|
181
|
+
},
|
|
182
|
+
"dependencies": {
|
|
183
|
+
"@bytechain.cn/colamd": "2.8.2",
|
|
184
|
+
"docx": "^9.15.2",
|
|
185
|
+
"katex": "^0.16.47",
|
|
186
|
+
"mermaid": "^11.15.0",
|
|
187
|
+
"pele": "^1.13.0",
|
|
188
|
+
"puppeteer-core": "^25.1.0",
|
|
189
|
+
"remark-gfm": "^4.0.1",
|
|
190
|
+
"remark-parse": "^11.0.0",
|
|
191
|
+
"unified": "^11.0.5"
|
|
192
|
+
},
|
|
193
|
+
"devDependencies": {
|
|
194
|
+
"@types/katex": "^0.16.8",
|
|
195
|
+
"@types/node": "^20.0.0",
|
|
196
|
+
"@types/vscode": "^1.85.0",
|
|
197
|
+
"@vscode/test-electron": "^2.4.0",
|
|
198
|
+
"@vscode/vsce": "^3.0.0",
|
|
199
|
+
"esbuild": "^0.28.0",
|
|
200
|
+
"eslint": "^9.0.0",
|
|
201
|
+
"patch-package": "^8.0.1",
|
|
202
|
+
"typescript": "^5.7.0"
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -89,6 +89,10 @@ export async function exportSlidesPDF(document: vscode.TextDocument, fullHTML: s
|
|
|
89
89
|
// 打印媒体下的盒模型与屏幕略有差异(容器查询单位、分页),切过去再打。
|
|
90
90
|
await page.emulateMediaType('print');
|
|
91
91
|
await page.evaluate('document.fonts && document.fonts.ready ? document.fonts.ready.then(() => true) : true');
|
|
92
|
+
// 幻灯片文档的水合脚本(mermaid/KaTeX 从 CDN 加载)完成后才打印;
|
|
93
|
+
// 没有该脚本的文档立即返回。水合后再按 print 纸面逐页 fit。
|
|
94
|
+
await page.evaluate('window.__colaviewSlidesHydrated ? window.__colaviewSlidesHydrated.then(() => true) : true');
|
|
95
|
+
await page.evaluate('window.__colaviewFitSlides ? window.__colaviewFitSlides() : true');
|
|
92
96
|
await new Promise(r => setTimeout(r, 300));
|
|
93
97
|
|
|
94
98
|
const pdfBuffer = await page.pdf({
|
package/src/present/presenter.ts
CHANGED
|
@@ -5,6 +5,7 @@ import * as vscode from 'vscode';
|
|
|
5
5
|
import * as path from 'path';
|
|
6
6
|
import * as os from 'os';
|
|
7
7
|
import * as fs from 'fs';
|
|
8
|
+
import { exec } from 'child_process';
|
|
8
9
|
|
|
9
10
|
const PRESENT_DIR = path.join(os.tmpdir(), 'colaview-present');
|
|
10
11
|
const MAX_KEPT_FILES = 8;
|
|
@@ -37,6 +38,24 @@ function prunePresentDir(keep: string): void {
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
/**
|
|
42
|
+
* 用系统 shell 交给默认浏览器打开文件。
|
|
43
|
+
* `vscode.env.openExternal` 对 `file:` URI 在 Windows 上常报
|
|
44
|
+
* “系统找不到指定的文件”(ShellExecute 走 file:// 关联失败),所以直接走
|
|
45
|
+
* 平台 shell:Windows `start`、macOS `open`、Linux `xdg-open`。
|
|
46
|
+
*/
|
|
47
|
+
function openWithShell(filePath: string): Promise<void> {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
const command =
|
|
50
|
+
process.platform === 'win32'
|
|
51
|
+
? `start "" "${filePath}"`
|
|
52
|
+
: process.platform === 'darwin'
|
|
53
|
+
? `open "${filePath}"`
|
|
54
|
+
: `xdg-open "${filePath}"`;
|
|
55
|
+
exec(command, { timeout: 15000 }, (err) => (err ? reject(err) : resolve()));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
40
59
|
/**
|
|
41
60
|
* 用默认浏览器打开一份全屏演示文档。
|
|
42
61
|
* @param title 文档标题(用于文件名与提示)
|
|
@@ -50,6 +69,12 @@ export async function openPresentWindow(title: string, html: string): Promise<vo
|
|
|
50
69
|
prunePresentDir(name);
|
|
51
70
|
|
|
52
71
|
try {
|
|
72
|
+
try {
|
|
73
|
+
await openWithShell(filePath);
|
|
74
|
+
return;
|
|
75
|
+
} catch {
|
|
76
|
+
/* shell 打开失败时退回 VS Code 通道 */
|
|
77
|
+
}
|
|
53
78
|
const opened = await vscode.env.openExternal(vscode.Uri.file(filePath));
|
|
54
79
|
if (!opened) {
|
|
55
80
|
vscode.window.showWarningMessage(
|
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
* @bytechain.cn/colamd@2.7.9 适配
|
|
6
6
|
*/
|
|
7
7
|
import { createColaMDEditor, type ColaMDRendererHandle } from '@bytechain.cn/colamd/renderer';
|
|
8
|
+
/** KaTeX:幻灯片渲染层只输出占位容器,由这里水合成公式。 */
|
|
9
|
+
import katex from 'katex';
|
|
10
|
+
// mermaid 图走 pele 渲染(与 ColaMD-extend 同一实现):懒加载,按需 import。
|
|
11
|
+
|
|
12
|
+
/** 图内文字字体:测量与绘制必须同一套,否则 CJK 标签会被量窄、裁掉(上游 #94)。 */
|
|
13
|
+
const DIAGRAM_FONT = '"PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif';
|
|
14
|
+
const DIAGRAM_MONO_FONT = "'SF Mono', 'Fira Code', Menlo, Consolas, monospace";
|
|
8
15
|
|
|
9
16
|
// @ts-ignore — VSCode WebView API
|
|
10
17
|
const vscode = acquireVsCodeApi();
|
|
@@ -50,6 +57,105 @@ let labels: MenuLabels = {
|
|
|
50
57
|
/** 暗色内置主题集合,用于主题子菜单分组(亮色 = 内置全集 - 暗色)。 */
|
|
51
58
|
const DARK_BUILTIN_THEMES = new Set(['dark', 'solarized-dark', 'nord', 'gruvbox', 'dracula', 'midnight']);
|
|
52
59
|
|
|
60
|
+
/** 图内文字字体:测量与绘制必须同一套,否则 CJK 标签会被量窄、裁掉(上游 #94)。 */
|
|
61
|
+
|
|
62
|
+
let peleLoaded: Promise<typeof import('pele/lazy')> | null = null;
|
|
63
|
+
|
|
64
|
+
function loadPele(): Promise<typeof import('pele/lazy')> {
|
|
65
|
+
peleLoaded ??= import('pele/lazy');
|
|
66
|
+
return peleLoaded;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
let mermaidReady = false;
|
|
71
|
+
let mermaidSeq = 0;
|
|
72
|
+
|
|
73
|
+
/** 颜色混合:a 占比 t,与引擎 pele 令牌同一公式(18%/28%/45% 混合)。 */
|
|
74
|
+
function mixColor(a: string, b: string, t: number): string {
|
|
75
|
+
const parse = (c: string): [number, number, number] | null => {
|
|
76
|
+
const v = c.trim();
|
|
77
|
+
if (v.startsWith('#')) {
|
|
78
|
+
const hex = v.length === 4 ? '#' + v.slice(1).split('').map((x) => x + x).join('') : v;
|
|
79
|
+
return [parseInt(hex.slice(1, 3), 16), parseInt(hex.slice(3, 5), 16), parseInt(hex.slice(5, 7), 16)];
|
|
80
|
+
}
|
|
81
|
+
const m = /rgba?\(([^)]+)\)/.exec(v);
|
|
82
|
+
if (m) {
|
|
83
|
+
const parts = (m[1] ?? '').split(',').map((s) => parseFloat(s));
|
|
84
|
+
return [parts[0] ?? 128, parts[1] ?? 128, parts[2] ?? 128];
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
};
|
|
88
|
+
const pa = parse(a) ?? [128, 128, 128];
|
|
89
|
+
const pb = parse(b) ?? [255, 255, 255];
|
|
90
|
+
const r = Math.round(pa[0] * t + pb[0] * (1 - t));
|
|
91
|
+
const g = Math.round(pa[1] * t + pb[1] * (1 - t));
|
|
92
|
+
const bl = Math.round(pa[2] * t + pb[2] * (1 - t));
|
|
93
|
+
return `rgb(${r},${g},${bl})`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** 按当前主题推导 mermaid 配色(与文档模式的 pele 令牌一致:画在页面底色上)。 */
|
|
97
|
+
function mermaidThemeVariables(): Record<string, string> {
|
|
98
|
+
const style = getComputedStyle(document.body);
|
|
99
|
+
const bg = style.backgroundColor || '#ffffff';
|
|
100
|
+
const fg = style.color || '#1f1f1f';
|
|
101
|
+
const accentRaw = (style.getPropertyValue('--seed-accent') || style.getPropertyValue('--link-color') || '').trim();
|
|
102
|
+
const accent = /^#|^rgb/.test(accentRaw) ? accentRaw : mixColor(fg, bg, 0.45);
|
|
103
|
+
const borderRaw = (style.getPropertyValue('--border-color') || '').trim();
|
|
104
|
+
const border = /^#|^rgb/.test(borderRaw) ? borderRaw : mixColor(fg, bg, 0.45);
|
|
105
|
+
return {
|
|
106
|
+
background: bg,
|
|
107
|
+
primaryColor: mixColor(fg, bg, 0.18),
|
|
108
|
+
primaryTextColor: fg,
|
|
109
|
+
primaryBorderColor: accent,
|
|
110
|
+
lineColor: mixColor(fg, bg, 0.28),
|
|
111
|
+
secondaryColor: mixColor(fg, bg, 0.28),
|
|
112
|
+
tertiaryColor: mixColor(fg, bg, 0.18),
|
|
113
|
+
clusterBkg: mixColor(fg, bg, 0.08),
|
|
114
|
+
clusterBorder: border,
|
|
115
|
+
edgeLabelBackground: bg,
|
|
116
|
+
fontFamily: style.fontFamily,
|
|
117
|
+
fontSize: '28px',
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 水合幻灯片里的 mermaid 图与块级公式。
|
|
123
|
+
* 渲染层(src/slides/render.ts)把 ```mermaid 围栏输出为
|
|
124
|
+
* `<pre class="mermaid-src" hidden>`、`$$` 块输出为 `<span class="math-src" hidden>`,
|
|
125
|
+
* 由这里替换成 SVG / KaTeX HTML;失败时保留源码兜底。
|
|
126
|
+
*/
|
|
127
|
+
async function hydrateSlides(): Promise<void> {
|
|
128
|
+
const host = document.getElementById('slides-host');
|
|
129
|
+
if (!host) return;
|
|
130
|
+
|
|
131
|
+
for (const node of Array.from(host.querySelectorAll<HTMLElement>('pre.mermaid-src'))) {
|
|
132
|
+
const holder = node.parentElement;
|
|
133
|
+
if (!holder) continue;
|
|
134
|
+
try {
|
|
135
|
+
const { renderAsync } = await loadPele();
|
|
136
|
+
const { svg } = await renderAsync(node.textContent ?? '', {
|
|
137
|
+
fontFamily: DIAGRAM_FONT,
|
|
138
|
+
fontFamilyMono: DIAGRAM_MONO_FONT,
|
|
139
|
+
});
|
|
140
|
+
holder.innerHTML = svg;
|
|
141
|
+
node.remove();
|
|
142
|
+
} catch (e) {
|
|
143
|
+
console.error('[ColaView] slide mermaid render failed:', e);
|
|
144
|
+
/* 渲染失败保留源码 */
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
for (const node of Array.from(host.querySelectorAll<HTMLElement>('span.math-src'))) {
|
|
149
|
+
const holder = node.parentElement;
|
|
150
|
+
if (!holder) continue;
|
|
151
|
+
try {
|
|
152
|
+
katex.render(node.textContent ?? '', holder, { displayMode: true, throwOnError: false });
|
|
153
|
+
} catch (e) {
|
|
154
|
+
console.error('[ColaView] slide math render failed:', e);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
53
159
|
/** 幻灯片样式表只注入一次(几十 KB,逐键更新时不重复下发)。 */
|
|
54
160
|
function injectSlidesCss(css: string | undefined): void {
|
|
55
161
|
if (!css) return;
|
|
@@ -344,6 +450,7 @@ window.addEventListener('message', async (event: MessageEvent) => {
|
|
|
344
450
|
}
|
|
345
451
|
setMode('slides');
|
|
346
452
|
renderSlides(data.html || '');
|
|
453
|
+
void hydrateSlides();
|
|
347
454
|
break;
|
|
348
455
|
}
|
|
349
456
|
case 'update': {
|
package/src/slides/deck.ts
CHANGED
|
@@ -287,6 +287,11 @@ export function deckChrome(slides: readonly Slide[]): DeckChrome {
|
|
|
287
287
|
export function paginateDeck(slides: readonly Slide[], budget = 820): Slide[] {
|
|
288
288
|
const pages: Slide[] = [];
|
|
289
289
|
for (const slide of slides) {
|
|
290
|
+
// 过滤纯指令/空白页(与上游 deckPages 一致):无标题、lead、kicker 与
|
|
291
|
+
// 正文的页会在放映与打印里产出空白纸面。
|
|
292
|
+
if (slide.blocks.length === 0 && slide.title === '' && slide.lead === '' && slide.kicker === '') {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
290
295
|
const weight = blockWeights(slide.blocks);
|
|
291
296
|
if (weight <= budget) {
|
|
292
297
|
pages.push({ ...slide, pageStart: true });
|
|
@@ -332,6 +337,7 @@ function blockWeight(block: MdBlock): number {
|
|
|
332
337
|
if (block.kind === 'paragraph') return block.text.length + 24;
|
|
333
338
|
if (block.kind === 'quote') return block.text.length + 30;
|
|
334
339
|
if (block.kind === 'code') return block.text.split('\n').length * 34 + 40;
|
|
340
|
+
if (block.kind === 'math') return block.text.split('\n').length * 40 + 120;
|
|
335
341
|
if (block.kind === 'table') return (block.rows.length + 1) * 34 + 40;
|
|
336
342
|
if (block.kind === 'html') return 320;
|
|
337
343
|
if (block.kind === 'divider') return 30;
|
|
@@ -343,6 +349,11 @@ function blockWeights(blocks: readonly MdBlock[]): number {
|
|
|
343
349
|
}
|
|
344
350
|
|
|
345
351
|
function splitBlock(block: MdBlock, budget: number): MdBlock[] {
|
|
352
|
+
// mermaid 围栏不可按行切分:切开的每一段都是非法源码,水合时会报
|
|
353
|
+
// "Syntax error in text"。整块保留,超预算时独占一页。
|
|
354
|
+
if (block.kind === 'code' && block.lang.toLowerCase() === 'mermaid') {
|
|
355
|
+
return [block];
|
|
356
|
+
}
|
|
346
357
|
if (block.kind === 'code') {
|
|
347
358
|
const lines = block.text.split('\n');
|
|
348
359
|
const chunks: MdBlock[] = [];
|