vscode-colaview 0.3.2 → 0.4.0
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/.vscode/settings.json +1 -1
- package/CHANGELOG.md +30 -0
- package/README.md +311 -279
- package/README_CN.md +311 -279
- package/RELEASE_NOTES.md +56 -0
- package/esbuild.js +2 -0
- package/package.json +58 -19
- package/package.nls.json +14 -0
- package/package.nls.zh-cn.json +14 -0
- package/src/commands/commands.ts +48 -0
- package/src/docx/docx-builder.ts +241 -0
- package/src/export/docx-exporter.ts +961 -961
- package/src/export/html-exporter.ts +8 -2
- package/src/export/pdf-exporter.ts +65 -0
- package/src/export/pptx-exporter.ts +63 -0
- package/src/export/render-export-images.ts +386 -372
- package/src/export/theme-style.ts +195 -155
- package/src/pptx/pptx-builder.ts +249 -0
- package/src/pptx/zip.ts +158 -0
- package/src/present/presenter.ts +64 -0
- package/src/preview/preview-manager.ts +783 -541
- package/src/preview/webview/app.ts +588 -366
- package/src/preview/webview/index.html +167 -134
- package/src/slides/deck.ts +397 -0
- package/src/slides/markdown.ts +393 -0
- package/src/slides/render.ts +484 -0
- package/src/slides/slides.css +1082 -0
- package/src/themes/built-in/bear.css +89 -38
- package/src/themes/built-in/dark.css +87 -20
- package/src/themes/built-in/dracula.css +93 -38
- package/src/themes/built-in/elegant.css +109 -52
- package/src/themes/built-in/gruvbox.css +97 -42
- package/src/themes/built-in/light.css +80 -20
- package/src/themes/built-in/midnight.css +93 -31
- package/src/themes/built-in/nord.css +93 -38
- package/src/themes/built-in/notion.css +98 -48
- package/src/themes/built-in/sepia.css +99 -47
- package/src/themes/built-in/solarized-dark.css +94 -35
- package/src/themes/built-in/writer.css +99 -44
- package/src/themes/theme-manager.ts +207 -180
- package/src/types/colamd-renderer.d.ts +47 -47
- package/patches/@bytechain.cn+colamd+2.7.11.patch +0 -22
|
@@ -1,156 +1,196 @@
|
|
|
1
|
-
// 从「预览所用主题 CSS」中抽取令牌,并把它翻译成导出文档可用的语义样式。
|
|
2
|
-
//
|
|
3
|
-
// 背景:预览里主题的排版/强调色通过 `#editor .cm-content .cm-md-*` 选择器生效;
|
|
4
|
-
// 而 buildExportHTML 会把内容序列化成 `<article class="colamd-document">` 语义 HTML
|
|
5
|
-
// (<h1>/<strong>/<em>/<code>/<table>/<blockquote>…),并只把 `:root` 变量带过去。
|
|
6
|
-
// 结果:颜色令牌能跟过去,但主题的字体、加粗/行内代码强调色、表格表头下划线等丢光。
|
|
7
|
-
// 这里把主题 CSS 的编辑器选择器改写成语义选择器,再注入导出 HTML / Word 样式。
|
|
8
|
-
|
|
9
|
-
/** .cm-md-* 装饰类 → 导出文档里的语义标签映射(顺序敏感,长的先)。 */
|
|
10
|
-
const CLASS_TO_TAG: Array<[RegExp, string]> = [
|
|
11
|
-
[/\.cm-md-atxheading([1-6])\b/g, 'h$1'],
|
|
12
|
-
[/\.cm-md-strong\b/g, 'strong'],
|
|
13
|
-
[/\.cm-md-em\b/g, 'em'],
|
|
14
|
-
[/\.cm-md-strike\b/g, 's'],
|
|
15
|
-
[/\.cm-md-inlinecode\b/g, 'code'],
|
|
16
|
-
[/\.cm-md-highlight\b/g, 'mark'],
|
|
17
|
-
[/\.cm-md-link\b/g, 'a'],
|
|
18
|
-
[/\.cm-md-url\b/g, 'a'],
|
|
19
|
-
[/\.cm-md-blockquote\b/g, 'blockquote'],
|
|
20
|
-
[/\.cm-md-codeblock(?:-first|-last)?\b/g, 'pre'],
|
|
21
|
-
[/\.cm-md-codeinfo\b/g, 'pre'],
|
|
22
|
-
[/\.cm-md-table-widget\b/g, 'table'],
|
|
23
|
-
[/\.cm-md-table\b/g, 'table'],
|
|
24
|
-
[/\.cm-md-hr\b/g, 'hr'],
|
|
25
|
-
[/\.cm-md-task-checked\b/g, 'li'],
|
|
26
|
-
[/\.cm-md-task\b/g, 'li'],
|
|
27
|
-
[/\.cm-md-li-[0-6]\b/g, 'li'],
|
|
28
|
-
[/\.cm-md-footnote-ref\b/g, 'sup'],
|
|
29
|
-
[/\.cm-md-footnote-def\b/g, 'section'],
|
|
30
|
-
[/\.cm-md-image\b/g, 'img'],
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
interface ThemeTokens {
|
|
34
|
-
vars: Record<string, string>;
|
|
35
|
-
fontFamily: string;
|
|
36
|
-
lineHeight: number | null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** 解析主题 CSS 里的 `:root {}` 变量与 `.cm-content` 上的字体/行高。 */
|
|
40
|
-
function parseThemeTokens(themeCss: string): ThemeTokens {
|
|
41
|
-
const vars: Record<string, string> = {};
|
|
42
|
-
const rootMatch = /:root\s*\{([^}]*)\}/s.exec(themeCss);
|
|
43
|
-
if (rootMatch) {
|
|
44
|
-
const declRe = /(--[a-zA-Z0-9-]+)\s*:\s*([^;]+)/g;
|
|
45
|
-
let m: RegExpExecArray | null;
|
|
46
|
-
while ((m = declRe.exec(rootMatch[1]))) {
|
|
47
|
-
vars[m[1]] = m[2].trim();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 遍历所有 `.cm-content { … }` 块:字体/行高可能不在第一个块里,
|
|
52
|
-
// 优先取含 font-family 的那个(如 writer 主题的整站等宽字体)。
|
|
53
|
-
let fontFamily = '';
|
|
54
|
-
let lineHeight: number | null = null;
|
|
55
|
-
const blockRe = /([^{}]*\.cm-content\b[^{}]*)\{([^}]*)\}/gs;
|
|
56
|
-
let firstBlock: string | null = null;
|
|
57
|
-
let m: RegExpExecArray | null;
|
|
58
|
-
while ((m = blockRe.exec(themeCss))) {
|
|
59
|
-
const body = m[2];
|
|
60
|
-
if (firstBlock === null) firstBlock = body;
|
|
61
|
-
const fontMatch = /font-family\s*:\s*([^;]+)/i.exec(body);
|
|
62
|
-
if (fontMatch) {
|
|
63
|
-
fontFamily = fontMatch[1].trim();
|
|
64
|
-
const lineMatch = /line-height\s*:\s*([0-9.]+)/i.exec(body);
|
|
65
|
-
if (lineMatch) lineHeight = parseFloat(lineMatch[1]);
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (fontFamily === '' && firstBlock !== null) {
|
|
70
|
-
const lineMatch = /line-height\s*:\s*([0-9.]+)/i.exec(firstBlock);
|
|
71
|
-
if (lineMatch) lineHeight = parseFloat(lineMatch[1]);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return { vars, fontFamily, lineHeight };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* 把主题 CSS 中针对编辑器 DOM 的规则翻译成导出文档(`.colamd-document` 语义结构)能命中的规则。
|
|
79
|
-
* 返回纯 CSS 文本(不含 <style> 包裹),供注入导出 HTML。
|
|
80
|
-
*/
|
|
81
|
-
export function translateThemeCssForExport(themeCss: string): string {
|
|
82
|
-
if (!themeCss) return '';
|
|
83
|
-
|
|
84
|
-
// 保留 :root 变量块:导出 HTML 里的 :root 是渲染端收集的「运行时变量」,
|
|
85
|
-
// 当 webview body 缺主题类时会退回 colamd 的浅色默认值。注入的样式排在
|
|
86
|
-
// 最后,同特异性下后者胜,能让主题变量稳定覆盖默认值(自定义主题的唯一变量来源)。
|
|
87
|
-
let css = themeCss;
|
|
88
|
-
|
|
89
|
-
// 导出的 <body> 即原编辑器 #editor 容器。
|
|
90
|
-
css = css.replace(/#editor\b/g, 'body');
|
|
91
|
-
|
|
92
|
-
// 编辑器内容容器 → 导出文档容器。
|
|
93
|
-
css = css.replace(/\.cm-content\b/g, '.colamd-document');
|
|
94
|
-
|
|
95
|
-
// 编辑器装饰类 → 语义标签。
|
|
96
|
-
for (const [re, tag] of CLASS_TO_TAG) {
|
|
97
|
-
css = css.replace(re, tag);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return css.trim();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* 从 colamd.css(引擎内置样式)里提取主题作用域的正文规则并翻译成导出可用的语义选择器。
|
|
105
|
-
*
|
|
106
|
-
* 背景:各主题的正文差异化规则(加粗/行内代码/标题配色、表格表头、引用块等)以
|
|
107
|
-
* `body.theme-x .cm-content .cm-md-*` 形式写在引擎的 colamd.css 里,导出 HTML 虽然原样
|
|
108
|
-
* 内联了 colamd.css,但导出文档是语义化结构(.colamd-document strong 等),这些规则
|
|
109
|
-
* 全部无法命中 —— 表现为导出的加粗、行内代码等颜色与预览/ColaMD-extend 不一致。
|
|
110
|
-
* 这里按主题抽出这些规则,套用与 translateThemeCssForExport 相同的映射翻译后返回。
|
|
111
|
-
*/
|
|
112
|
-
export function translateEngineThemeCssForExport(colamdCss: string): string {
|
|
113
|
-
if (!colamdCss) return '';
|
|
114
|
-
|
|
115
|
-
// 抽出所有 body.theme-* 作用域、且作用于编辑器内容层的规则块
|
|
116
|
-
const ruleRe = /body\.theme-[a-z0-9-]+[^{}]*\.cm-content[^{}]*\{[^}]*\}/g;
|
|
117
|
-
const rules = colamdCss.match(ruleRe);
|
|
118
|
-
if (!rules || rules.length === 0) return '';
|
|
119
|
-
|
|
120
|
-
const out = rules.join('\n');
|
|
121
|
-
return translateThemeCssForExport(out);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return
|
|
1
|
+
// 从「预览所用主题 CSS」中抽取令牌,并把它翻译成导出文档可用的语义样式。
|
|
2
|
+
//
|
|
3
|
+
// 背景:预览里主题的排版/强调色通过 `#editor .cm-content .cm-md-*` 选择器生效;
|
|
4
|
+
// 而 buildExportHTML 会把内容序列化成 `<article class="colamd-document">` 语义 HTML
|
|
5
|
+
// (<h1>/<strong>/<em>/<code>/<table>/<blockquote>…),并只把 `:root` 变量带过去。
|
|
6
|
+
// 结果:颜色令牌能跟过去,但主题的字体、加粗/行内代码强调色、表格表头下划线等丢光。
|
|
7
|
+
// 这里把主题 CSS 的编辑器选择器改写成语义选择器,再注入导出 HTML / Word 样式。
|
|
8
|
+
|
|
9
|
+
/** .cm-md-* 装饰类 → 导出文档里的语义标签映射(顺序敏感,长的先)。 */
|
|
10
|
+
const CLASS_TO_TAG: Array<[RegExp, string]> = [
|
|
11
|
+
[/\.cm-md-atxheading([1-6])\b/g, 'h$1'],
|
|
12
|
+
[/\.cm-md-strong\b/g, 'strong'],
|
|
13
|
+
[/\.cm-md-em\b/g, 'em'],
|
|
14
|
+
[/\.cm-md-strike\b/g, 's'],
|
|
15
|
+
[/\.cm-md-inlinecode\b/g, 'code'],
|
|
16
|
+
[/\.cm-md-highlight\b/g, 'mark'],
|
|
17
|
+
[/\.cm-md-link\b/g, 'a'],
|
|
18
|
+
[/\.cm-md-url\b/g, 'a'],
|
|
19
|
+
[/\.cm-md-blockquote\b/g, 'blockquote'],
|
|
20
|
+
[/\.cm-md-codeblock(?:-first|-last)?\b/g, 'pre'],
|
|
21
|
+
[/\.cm-md-codeinfo\b/g, 'pre'],
|
|
22
|
+
[/\.cm-md-table-widget\b/g, 'table'],
|
|
23
|
+
[/\.cm-md-table\b/g, 'table'],
|
|
24
|
+
[/\.cm-md-hr\b/g, 'hr'],
|
|
25
|
+
[/\.cm-md-task-checked\b/g, 'li'],
|
|
26
|
+
[/\.cm-md-task\b/g, 'li'],
|
|
27
|
+
[/\.cm-md-li-[0-6]\b/g, 'li'],
|
|
28
|
+
[/\.cm-md-footnote-ref\b/g, 'sup'],
|
|
29
|
+
[/\.cm-md-footnote-def\b/g, 'section'],
|
|
30
|
+
[/\.cm-md-image\b/g, 'img'],
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
interface ThemeTokens {
|
|
34
|
+
vars: Record<string, string>;
|
|
35
|
+
fontFamily: string;
|
|
36
|
+
lineHeight: number | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 解析主题 CSS 里的 `:root {}` 变量与 `.cm-content` 上的字体/行高。 */
|
|
40
|
+
function parseThemeTokens(themeCss: string): ThemeTokens {
|
|
41
|
+
const vars: Record<string, string> = {};
|
|
42
|
+
const rootMatch = /:root\s*\{([^}]*)\}/s.exec(themeCss);
|
|
43
|
+
if (rootMatch) {
|
|
44
|
+
const declRe = /(--[a-zA-Z0-9-]+)\s*:\s*([^;]+)/g;
|
|
45
|
+
let m: RegExpExecArray | null;
|
|
46
|
+
while ((m = declRe.exec(rootMatch[1]))) {
|
|
47
|
+
vars[m[1]] = m[2].trim();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 遍历所有 `.cm-content { … }` 块:字体/行高可能不在第一个块里,
|
|
52
|
+
// 优先取含 font-family 的那个(如 writer 主题的整站等宽字体)。
|
|
53
|
+
let fontFamily = '';
|
|
54
|
+
let lineHeight: number | null = null;
|
|
55
|
+
const blockRe = /([^{}]*\.cm-content\b[^{}]*)\{([^}]*)\}/gs;
|
|
56
|
+
let firstBlock: string | null = null;
|
|
57
|
+
let m: RegExpExecArray | null;
|
|
58
|
+
while ((m = blockRe.exec(themeCss))) {
|
|
59
|
+
const body = m[2];
|
|
60
|
+
if (firstBlock === null) firstBlock = body;
|
|
61
|
+
const fontMatch = /font-family\s*:\s*([^;]+)/i.exec(body);
|
|
62
|
+
if (fontMatch) {
|
|
63
|
+
fontFamily = fontMatch[1].trim();
|
|
64
|
+
const lineMatch = /line-height\s*:\s*([0-9.]+)/i.exec(body);
|
|
65
|
+
if (lineMatch) lineHeight = parseFloat(lineMatch[1]);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (fontFamily === '' && firstBlock !== null) {
|
|
70
|
+
const lineMatch = /line-height\s*:\s*([0-9.]+)/i.exec(firstBlock);
|
|
71
|
+
if (lineMatch) lineHeight = parseFloat(lineMatch[1]);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return { vars, fontFamily, lineHeight };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 把主题 CSS 中针对编辑器 DOM 的规则翻译成导出文档(`.colamd-document` 语义结构)能命中的规则。
|
|
79
|
+
* 返回纯 CSS 文本(不含 <style> 包裹),供注入导出 HTML。
|
|
80
|
+
*/
|
|
81
|
+
export function translateThemeCssForExport(themeCss: string): string {
|
|
82
|
+
if (!themeCss) return '';
|
|
83
|
+
|
|
84
|
+
// 保留 :root 变量块:导出 HTML 里的 :root 是渲染端收集的「运行时变量」,
|
|
85
|
+
// 当 webview body 缺主题类时会退回 colamd 的浅色默认值。注入的样式排在
|
|
86
|
+
// 最后,同特异性下后者胜,能让主题变量稳定覆盖默认值(自定义主题的唯一变量来源)。
|
|
87
|
+
let css = themeCss;
|
|
88
|
+
|
|
89
|
+
// 导出的 <body> 即原编辑器 #editor 容器。
|
|
90
|
+
css = css.replace(/#editor\b/g, 'body');
|
|
91
|
+
|
|
92
|
+
// 编辑器内容容器 → 导出文档容器。
|
|
93
|
+
css = css.replace(/\.cm-content\b/g, '.colamd-document');
|
|
94
|
+
|
|
95
|
+
// 编辑器装饰类 → 语义标签。
|
|
96
|
+
for (const [re, tag] of CLASS_TO_TAG) {
|
|
97
|
+
css = css.replace(re, tag);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return css.trim();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 从 colamd.css(引擎内置样式)里提取主题作用域的正文规则并翻译成导出可用的语义选择器。
|
|
105
|
+
*
|
|
106
|
+
* 背景:各主题的正文差异化规则(加粗/行内代码/标题配色、表格表头、引用块等)以
|
|
107
|
+
* `body.theme-x .cm-content .cm-md-*` 形式写在引擎的 colamd.css 里,导出 HTML 虽然原样
|
|
108
|
+
* 内联了 colamd.css,但导出文档是语义化结构(.colamd-document strong 等),这些规则
|
|
109
|
+
* 全部无法命中 —— 表现为导出的加粗、行内代码等颜色与预览/ColaMD-extend 不一致。
|
|
110
|
+
* 这里按主题抽出这些规则,套用与 translateThemeCssForExport 相同的映射翻译后返回。
|
|
111
|
+
*/
|
|
112
|
+
export function translateEngineThemeCssForExport(colamdCss: string): string {
|
|
113
|
+
if (!colamdCss) return '';
|
|
114
|
+
|
|
115
|
+
// 抽出所有 body.theme-* 作用域、且作用于编辑器内容层的规则块
|
|
116
|
+
const ruleRe = /body\.theme-[a-z0-9-]+[^{}]*\.cm-content[^{}]*\{[^}]*\}/g;
|
|
117
|
+
const rules = colamdCss.match(ruleRe);
|
|
118
|
+
if (!rules || rules.length === 0) return '';
|
|
119
|
+
|
|
120
|
+
const out = rules.join('\n');
|
|
121
|
+
return translateThemeCssForExport(out);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 深色主题导出 Word 时回落的浅色板,字段与 docx-exporter 的 DEFAULT_STYLE 一致。
|
|
126
|
+
* Word 是白纸,深色主题的浅色正文直接搬过去会看不见(镜像 colamd-extend
|
|
127
|
+
* docx-style.ts 的 LIGHT 常量:浅色跟随主题、深色整体回落浅色)。
|
|
128
|
+
*/
|
|
129
|
+
const LIGHT_TOKENS: Record<string, string> = {
|
|
130
|
+
text: '24292F',
|
|
131
|
+
secondaryText: '656D76',
|
|
132
|
+
link: '0969DA',
|
|
133
|
+
inlineCodeBackground: 'EFF1F3',
|
|
134
|
+
codeBlockBackground: 'F6F8FA',
|
|
135
|
+
codeBlockText: '24292F',
|
|
136
|
+
highlightBackground: 'FFF3BF',
|
|
137
|
+
blockquoteBorder: 'D0D7DE',
|
|
138
|
+
border: 'D0D7DE',
|
|
139
|
+
tableHeaderBackground: 'F6F8FA',
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/** 取 #rgb / #rrggbb / #rrggbbaa 的主色,取不到返回 null。入参可带 `#`。 */
|
|
143
|
+
function themeHex(value: string | undefined): string | null {
|
|
144
|
+
if (!value) return null;
|
|
145
|
+
const raw = value.trim().replace(/^#/, '');
|
|
146
|
+
if (/^[0-9a-f]{6}$/i.test(raw)) return raw.toUpperCase();
|
|
147
|
+
if (/^[0-9a-f]{3}$/i.test(raw)) return raw.split('').map((digit) => digit + digit).join('').toUpperCase();
|
|
148
|
+
if (/^[0-9a-f]{8}$/i.test(raw)) return raw.slice(0, 6).toUpperCase();
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** 感知亮度,用来判断主题底色是深是浅。入参不带 `#`。 */
|
|
153
|
+
function hexLuminance(hex: string): number {
|
|
154
|
+
const channel = (index: number): number => (Number.parseInt(hex.slice(index, index + 2), 16) || 0) / 255;
|
|
155
|
+
return 0.2126 * channel(0) + 0.7152 * channel(2) + 0.0722 * channel(4);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* 从主题 CSS 构造 Word 导出用的样式令牌(docx 的 DocxStyle)。只覆盖能可靠取到的字段,
|
|
160
|
+
* 其余由 markdownToDocx 的 normalizeStyle 回退到默认浅色样式。颜色返回原始值(hex),
|
|
161
|
+
* 由 docx-exporter 的 hexColor 归一化。
|
|
162
|
+
*
|
|
163
|
+
* 深色主题(--bg-color 亮度 < 0.5)整体回落浅色板,与 Mermaid 导出挑浅色配色是同一条规则。
|
|
164
|
+
*/
|
|
165
|
+
export function buildDocxStyleFromThemeCss(themeCss: string): Record<string, string | number | null> {
|
|
166
|
+
const { vars, fontFamily, lineHeight } = parseThemeTokens(themeCss);
|
|
167
|
+
|
|
168
|
+
const bg = themeHex(vars['--bg-color']);
|
|
169
|
+
const isDarkTheme = bg !== null && hexLuminance(bg) < 0.5;
|
|
170
|
+
const style: Record<string, string | number | null> = isDarkTheme ? { ...LIGHT_TOKENS } : {};
|
|
171
|
+
if (!isDarkTheme) {
|
|
172
|
+
const put = (key: string, varName: string) => {
|
|
173
|
+
if (vars[varName]) style[key] = vars[varName];
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
put('text', '--text-color');
|
|
177
|
+
put('secondaryText', '--text-secondary');
|
|
178
|
+
put('link', '--link-color');
|
|
179
|
+
put('inlineCodeBackground', '--code-bg');
|
|
180
|
+
put('codeBlockBackground', '--code-block-bg');
|
|
181
|
+
put('codeBlockText', '--code-block-text');
|
|
182
|
+
put('highlightBackground', '--highlight-bg');
|
|
183
|
+
put('blockquoteBorder', '--blockquote-border');
|
|
184
|
+
put('blockquoteBackground', '--blockquote-bg');
|
|
185
|
+
put('border', '--border-color');
|
|
186
|
+
put('tableHeaderBackground', '--table-header-bg');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// 主题若显式定义了等宽字体栈(如自定义 .themes 主题),一并带上
|
|
190
|
+
if (vars['--font-mono']) style.monoFontStack = vars['--font-mono'];
|
|
191
|
+
|
|
192
|
+
if (fontFamily) style.bodyFontStack = fontFamily;
|
|
193
|
+
if (lineHeight !== null && Number.isFinite(lineHeight)) style.lineHeight = lineHeight;
|
|
194
|
+
|
|
195
|
+
return style;
|
|
156
196
|
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
// 最小 OOXML 生成器 — 纯同步、零依赖,产出真正的 .pptx。
|
|
2
|
+
//
|
|
3
|
+
// PresentationML 里给出 master + 单个 blank layout + theme,每页用显式文本框
|
|
4
|
+
// 排标题、正文与代码块。单位:DrawingML 用 EMU(914400 = 1 英寸),字号写百分
|
|
5
|
+
// 之一磅(`a:rPr@sz`)。
|
|
6
|
+
import { zipStore } from './zip';
|
|
7
|
+
|
|
8
|
+
/** 一页 PPT 的内容(由幻灯片 AST 转换而来)。 */
|
|
9
|
+
export interface PptxSlide {
|
|
10
|
+
kicker?: string;
|
|
11
|
+
title?: string;
|
|
12
|
+
paragraphs?: string[];
|
|
13
|
+
bullets?: string[];
|
|
14
|
+
code?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** 版式与字体覆盖项;缺省值见 buildPptx。 */
|
|
18
|
+
export interface PptxMeta {
|
|
19
|
+
/** 主色,形如 `#b0401f`。 */
|
|
20
|
+
accent?: string;
|
|
21
|
+
/** 正文字体,例如 `Source Han Serif SC`。 */
|
|
22
|
+
fontBody?: string;
|
|
23
|
+
/** 等宽字体,例如 `JetBrains Mono`。 */
|
|
24
|
+
fontMono?: string;
|
|
25
|
+
/** 文档标题,写入 core.xml。 */
|
|
26
|
+
title?: string;
|
|
27
|
+
widthEmu?: number;
|
|
28
|
+
heightEmu?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const XML_DECL = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
32
|
+
/** 所有 zip 条目共用的固定时间戳,保证同一输入产出同一字节。 */
|
|
33
|
+
const FIXED_DATE = new Date(Date.UTC(2024, 0, 1));
|
|
34
|
+
const DEFAULT_ACCENT = 'B0401F';
|
|
35
|
+
const DEFAULT_FONT_BODY = 'Calibri';
|
|
36
|
+
const DEFAULT_FONT_MONO = 'Consolas';
|
|
37
|
+
|
|
38
|
+
const A_NS = 'http://schemas.openxmlformats.org/drawingml/2006/main';
|
|
39
|
+
const R_NS = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';
|
|
40
|
+
const P_NS = 'http://schemas.openxmlformats.org/presentationml/2006/main';
|
|
41
|
+
const PKG_REL_NS = 'http://schemas.openxmlformats.org/package/2006/relationships';
|
|
42
|
+
const CT_NS = 'http://schemas.openxmlformats.org/package/2006/content-types';
|
|
43
|
+
|
|
44
|
+
/** 转义 XML 文本/属性,并剔除 XML 1.0 不接受的控制字符。 */
|
|
45
|
+
function esc(value: string): string {
|
|
46
|
+
return value
|
|
47
|
+
.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g, '')
|
|
48
|
+
.replace(/&/g, '&')
|
|
49
|
+
.replace(/</g, '<')
|
|
50
|
+
.replace(/>/g, '>')
|
|
51
|
+
.replace(/"/g, '"')
|
|
52
|
+
.replace(/'/g, ''');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 把 `#b0401f` / `b0401f` 规范成大写六位 RGB;非法值退回 fallback。 */
|
|
56
|
+
function hex(value: string | undefined, fallback: string): string {
|
|
57
|
+
if (value === undefined) return fallback;
|
|
58
|
+
const raw = value.trim().replace(/^#/, '');
|
|
59
|
+
return /^[0-9a-fA-F]{6}$/.test(raw) ? raw.toUpperCase() : fallback;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function font(value: string | undefined, fallback: string): string {
|
|
63
|
+
const name = (value ?? '').trim();
|
|
64
|
+
return name === '' ? fallback : name;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function pack(files: ReadonlyArray<readonly [string, string]>): Uint8Array {
|
|
68
|
+
const encoder = new TextEncoder();
|
|
69
|
+
return zipStore(files.map(([path, text]) => ({ path, data: encoder.encode(text), date: FIXED_DATE })));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface Box {
|
|
73
|
+
x: number;
|
|
74
|
+
y: number;
|
|
75
|
+
cx: number;
|
|
76
|
+
cy: number;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 16:9 版式坐标(EMU):标题、正文、底部代码框。 */
|
|
80
|
+
const TITLE_BOX: Box = { x: 838200, y: 457200, cx: 10515600, cy: 914400 };
|
|
81
|
+
const KICKER_BOX: Box = { x: 838200, y: 274320, cx: 10515600, cy: 274320 };
|
|
82
|
+
const BODY_BOX: Box = { x: 838200, y: 1600200, cx: 10515600, cy: 4572000 };
|
|
83
|
+
const CODE_BOX: Box = { x: 838200, y: 5486400, cx: 10515600, cy: 1005840 };
|
|
84
|
+
|
|
85
|
+
interface RunStyle {
|
|
86
|
+
size: number;
|
|
87
|
+
color: string;
|
|
88
|
+
fontFace: string;
|
|
89
|
+
bold?: boolean;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** DrawingML run:始终带 latin/ea/cs 字体,避免回退到主题字体。 */
|
|
93
|
+
function aRun(text: string, style: RunStyle): string {
|
|
94
|
+
const bold = style.bold === true ? ' b="1"' : '';
|
|
95
|
+
return `<a:r><a:rPr lang="zh-CN" altLang="en-US" sz="${style.size}"${bold} dirty="0"><a:solidFill><a:srgbClr val="${style.color}"/></a:solidFill><a:latin typeface="${esc(style.fontFace)}"/><a:ea typeface="${esc(style.fontFace)}"/><a:cs typeface="${esc(style.fontFace)}"/></a:rPr><a:t>${esc(text)}</a:t></a:r>`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** 一个 a:p;多行文本按 `a:br` 拆行,bullet 时加项目符号。 */
|
|
99
|
+
function aParagraph(text: string, style: RunStyle, bullet = false): string {
|
|
100
|
+
const pPr = bullet
|
|
101
|
+
? '<a:pPr marL="285750" indent="-285750"><a:lnSpc><a:spcPct val="125000"/></a:lnSpc><a:spcBef><a:spcPts val="600"/></a:spcBef><a:buFont typeface="Arial"/><a:buChar char="•"/></a:pPr>'
|
|
102
|
+
: '<a:pPr><a:lnSpc><a:spcPct val="125000"/></a:lnSpc><a:spcBef><a:spcPts val="600"/></a:spcBef></a:pPr>';
|
|
103
|
+
const runs = text
|
|
104
|
+
.replace(/\r\n?/g, '\n')
|
|
105
|
+
.split('\n')
|
|
106
|
+
.map((line, i) => `${i > 0 ? '<a:br/>' : ''}${aRun(line, style)}`)
|
|
107
|
+
.join('');
|
|
108
|
+
return `<a:p>${pPr}${runs}</a:p>`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** 一个显式文本框(txBox),可选纯色底。 */
|
|
112
|
+
function textBox(id: number, name: string, box: Box, paragraphs: string, fill?: string): string {
|
|
113
|
+
const fillXml = fill === undefined ? '<a:noFill/>' : `<a:solidFill><a:srgbClr val="${fill}"/></a:solidFill>`;
|
|
114
|
+
const lineXml = fill === undefined ? '' : '<a:ln w="12700"><a:noFill/></a:ln>';
|
|
115
|
+
const inset = fill === undefined ? 91440 : 137160;
|
|
116
|
+
return `<p:sp><p:nvSpPr><p:cNvPr id="${id}" name="${esc(name)}"/><p:cNvSpPr txBox="1"/><p:nvPr/></p:nvSpPr><p:spPr><a:xfrm><a:off x="${box.x}" y="${box.y}"/><a:ext cx="${box.cx}" cy="${box.cy}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom>${fillXml}${lineXml}</p:spPr><p:txBody><a:bodyPr wrap="square" lIns="${inset}" tIns="${inset}" rIns="${inset}" bIns="${inset}" anchor="t"/><a:lstStyle/>${paragraphs}</p:txBody></p:sp>`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const EMPTY_TREE =
|
|
120
|
+
'<p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr>';
|
|
121
|
+
|
|
122
|
+
/** 主题:色板以 accent 为 accent1,major/minor 字体都取 fontBody。 */
|
|
123
|
+
function themeXml(accent: string, bodyFont: string): string {
|
|
124
|
+
const solid = (val: string): string => `<a:solidFill><a:srgbClr val="${val}"/></a:solidFill>`;
|
|
125
|
+
const scheme = (val: string): string => `<a:solidFill><a:schemeClr val="${val}"/></a:solidFill>`;
|
|
126
|
+
return `${XML_DECL}<a:theme xmlns:a="${A_NS}" name="ColaView"><a:themeElements><a:clrScheme name="ColaView"><a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1><a:dk2>${solid('1F1F1F')}</a:dk2><a:lt2>${solid('F5F3EF')}</a:lt2><a:accent1>${solid(accent)}</a:accent1><a:accent2>${solid('2F5D62')}</a:accent2><a:accent3>${solid('8C6A3F')}</a:accent3><a:accent4>${solid('3F6C8C')}</a:accent4><a:accent5>${solid('6C3F8C')}</a:accent5><a:accent6>${solid('3F8C5A')}</a:accent6><a:hlink>${solid('1F5C99')}</a:hlink><a:folHlink>${solid('7A3F8C')}</a:folHlink></a:clrScheme><a:fontScheme name="ColaView"><a:majorFont><a:latin typeface="${esc(bodyFont)}"/><a:ea typeface="${esc(bodyFont)}"/><a:cs typeface=""/></a:majorFont><a:minorFont><a:latin typeface="${esc(bodyFont)}"/><a:ea typeface="${esc(bodyFont)}"/><a:cs typeface=""/></a:minorFont></a:fontScheme><a:fmtScheme name="ColaView"><a:fillStyleLst>${scheme('phClr')}<a:solidFill><a:schemeClr val="phClr"><a:tint val="50000"/></a:schemeClr></a:solidFill><a:solidFill><a:schemeClr val="phClr"><a:shade val="80000"/></a:schemeClr></a:solidFill></a:fillStyleLst><a:lnStyleLst><a:ln w="9525" cap="flat" cmpd="sng" algn="ctr">${scheme('phClr')}<a:prstDash val="solid"/><a:miter lim="800000"/></a:ln><a:ln w="19050" cap="flat" cmpd="sng" algn="ctr">${scheme('phClr')}<a:prstDash val="solid"/><a:miter lim="800000"/></a:ln><a:ln w="28575" cap="flat" cmpd="sng" algn="ctr">${scheme('phClr')}<a:prstDash val="solid"/><a:miter lim="800000"/></a:ln></a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst>${scheme('phClr')}<a:solidFill><a:schemeClr val="phClr"><a:tint val="95000"/></a:schemeClr></a:solidFill><a:solidFill><a:schemeClr val="phClr"><a:shade val="90000"/></a:schemeClr></a:solidFill></a:bgFillStyleLst></a:fmtScheme></a:themeElements><a:objectDefaults/><a:extraClrSchemeLst/></a:theme>`;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function slideMasterXml(): string {
|
|
130
|
+
return `${XML_DECL}<p:sldMaster xmlns:a="${A_NS}" xmlns:r="${R_NS}" xmlns:p="${P_NS}"><p:cSld><p:bg><p:bgPr><a:solidFill><a:schemeClr val="bg1"/></a:solidFill><a:effectLst/></p:bgPr></p:bg><p:spTree>${EMPTY_TREE}</p:spTree></p:cSld><p:clrMap bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1" accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" hlink="hlink" folHlink="folHlink"/><p:sldLayoutIdLst><p:sldLayoutId id="2147483649" r:id="rId1"/></p:sldLayoutIdLst><p:txStyles><p:titleStyle><a:lvl1pPr><a:defRPr sz="3200" b="1"/></a:lvl1pPr></p:titleStyle><p:bodyStyle><a:lvl1pPr><a:defRPr sz="1800"/></a:lvl1pPr></p:bodyStyle><p:otherStyle><a:lvl1pPr><a:defRPr sz="1800"/></a:lvl1pPr></p:otherStyle></p:txStyles></p:sldMaster>`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function slideLayoutXml(): string {
|
|
134
|
+
return `${XML_DECL}<p:sldLayout xmlns:a="${A_NS}" xmlns:r="${R_NS}" xmlns:p="${P_NS}" type="blank" preserve="1"><p:cSld name="Blank"><p:spTree>${EMPTY_TREE}</p:spTree></p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:sldLayout>`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** 一页幻灯片:标题 + 正文(段落/项目符号)+ 可选底部代码框。 */
|
|
138
|
+
function slideXml(
|
|
139
|
+
slide: PptxSlide,
|
|
140
|
+
meta: { accent: string; bodyFont: string; monoFont: string; ink: string }
|
|
141
|
+
): string {
|
|
142
|
+
const shapes: string[] = [];
|
|
143
|
+
let id = 2;
|
|
144
|
+
if (slide.kicker !== undefined && slide.kicker !== '') {
|
|
145
|
+
shapes.push(
|
|
146
|
+
textBox(
|
|
147
|
+
id++,
|
|
148
|
+
'Kicker',
|
|
149
|
+
KICKER_BOX,
|
|
150
|
+
`<a:p>${aRun(slide.kicker.toUpperCase(), { size: 1200, bold: false, color: meta.accent, fontFace: meta.monoFont })}</a:p>`
|
|
151
|
+
)
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
if (slide.title !== undefined && slide.title !== '') {
|
|
155
|
+
shapes.push(
|
|
156
|
+
textBox(
|
|
157
|
+
id++,
|
|
158
|
+
'Title',
|
|
159
|
+
TITLE_BOX,
|
|
160
|
+
`<a:p>${aRun(slide.title, { size: 3200, bold: true, color: meta.accent, fontFace: meta.bodyFont })}</a:p>`
|
|
161
|
+
)
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
const bodyParts: string[] = [];
|
|
165
|
+
for (const text of slide.paragraphs ?? []) {
|
|
166
|
+
bodyParts.push(aParagraph(text, { size: 1800, color: meta.ink, fontFace: meta.bodyFont }));
|
|
167
|
+
}
|
|
168
|
+
for (const text of slide.bullets ?? []) {
|
|
169
|
+
bodyParts.push(aParagraph(text, { size: 1600, color: meta.ink, fontFace: meta.bodyFont }, true));
|
|
170
|
+
}
|
|
171
|
+
if (bodyParts.length > 0) shapes.push(textBox(id++, 'Body', BODY_BOX, bodyParts.join('')));
|
|
172
|
+
if (slide.code !== undefined && slide.code !== '') {
|
|
173
|
+
const codeParts = slide.code
|
|
174
|
+
.replace(/\r\n?/g, '\n')
|
|
175
|
+
.replace(/\t/g, ' ')
|
|
176
|
+
.split('\n')
|
|
177
|
+
.map(
|
|
178
|
+
(line) =>
|
|
179
|
+
`<a:p><a:pPr><a:lnSpc><a:spcPct val="100000"/></a:lnSpc></a:pPr>${aRun(line, { size: 1200, color: 'FFFFFF', fontFace: meta.monoFont })}</a:p>`
|
|
180
|
+
);
|
|
181
|
+
shapes.push(textBox(id++, 'Code', CODE_BOX, codeParts.join(''), '1F1F1F'));
|
|
182
|
+
}
|
|
183
|
+
return `${XML_DECL}<p:sld xmlns:a="${A_NS}" xmlns:r="${R_NS}" xmlns:p="${P_NS}"><p:cSld><p:spTree>${EMPTY_TREE}${shapes.join('')}</p:spTree></p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:sld>`;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function coreXml(title: string): string {
|
|
187
|
+
return `${XML_DECL}<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><dc:title>${esc(title)}</dc:title><dc:creator>ColaView</dc:creator><cp:lastModifiedBy>ColaView</cp:lastModifiedBy><dcterms:created xsi:type="dcterms:W3CDTF">2024-01-01T00:00:00Z</dcterms:created><dcterms:modified xsi:type="dcterms:W3CDTF">2024-01-01T00:00:00Z</dcterms:modified></cp:coreProperties>`;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function appXml(slides: number): string {
|
|
191
|
+
const extra = `<PresentationFormat>Widescreen</PresentationFormat><Slides>${slides}</Slides><Notes>0</Notes><HiddenSlides>0</HiddenSlides><MMClips>0</MMClips>`;
|
|
192
|
+
return `${XML_DECL}<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"><Application>ColaView</Application>${extra}<DocSecurity>0</DocSecurity><ScaleCrop>false</ScaleCrop><Company></Company><LinksUpToDate>false</LinksUpToDate><SharedDoc>false</SharedDoc><HyperlinksChanged>false</HyperlinksChanged><AppVersion>16.0000</AppVersion></Properties>`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 生成一份 PowerPoint 演示文稿(16:9)。
|
|
197
|
+
*
|
|
198
|
+
* 包内只有 1 个 slideMaster、1 个 blank slideLayout 和 1 份 theme;每页的内容都是
|
|
199
|
+
* 显式文本框,因此不依赖占位符继承。
|
|
200
|
+
*/
|
|
201
|
+
export function buildPptx(input: { slides: PptxSlide[]; meta?: PptxMeta }): Uint8Array {
|
|
202
|
+
const meta = input.meta ?? {};
|
|
203
|
+
const accent = hex(meta.accent, DEFAULT_ACCENT);
|
|
204
|
+
const bodyFont = font(meta.fontBody, DEFAULT_FONT_BODY);
|
|
205
|
+
const monoFont = font(meta.fontMono, DEFAULT_FONT_MONO);
|
|
206
|
+
const title = meta.title ?? 'ColaView Presentation';
|
|
207
|
+
const width = meta.widthEmu !== undefined && meta.widthEmu > 0 ? Math.round(meta.widthEmu) : 12192000;
|
|
208
|
+
const height = meta.heightEmu !== undefined && meta.heightEmu > 0 ? Math.round(meta.heightEmu) : 6858000;
|
|
209
|
+
const slides = input.slides.length > 0 ? input.slides : [{}];
|
|
210
|
+
const ink = '262626';
|
|
211
|
+
|
|
212
|
+
const slideRels = `${XML_DECL}<Relationships xmlns="${PKG_REL_NS}"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayout1.xml"/></Relationships>`;
|
|
213
|
+
const masterRels = `${XML_DECL}<Relationships xmlns="${PKG_REL_NS}"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayout1.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="../theme/theme1.xml"/></Relationships>`;
|
|
214
|
+
const layoutRels = `${XML_DECL}<Relationships xmlns="${PKG_REL_NS}"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster" Target="../slideMasters/slideMaster1.xml"/></Relationships>`;
|
|
215
|
+
|
|
216
|
+
const presentationRels = `${XML_DECL}<Relationships xmlns="${PKG_REL_NS}"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster" Target="slideMasters/slideMaster1.xml"/>${slides.map((_, i) => `<Relationship Id="rId${i + 2}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="slides/slide${i + 1}.xml"/>`).join('')}<Relationship Id="rId${slides.length + 2}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/presProps" Target="presProps.xml"/></Relationships>`;
|
|
217
|
+
|
|
218
|
+
const slideIds = slides.map((_, i) => `<p:sldId id="${256 + i}" r:id="rId${i + 2}"/>`).join('');
|
|
219
|
+
const presentation = `${XML_DECL}<p:presentation xmlns:a="${A_NS}" xmlns:r="${R_NS}" xmlns:p="${P_NS}" saveSubsetFonts="1"><p:sldMasterIdLst><p:sldMasterId id="2147483648" r:id="rId1"/></p:sldMasterIdLst><p:sldIdLst>${slideIds}</p:sldIdLst><p:sldSz cx="${width}" cy="${height}" type="screen16x9"/><p:notesSz cx="6858000" cy="9144000"/><p:defaultTextStyle><a:lvl1pPr><a:defRPr sz="1800"/></a:lvl1pPr></p:defaultTextStyle></p:presentation>`;
|
|
220
|
+
|
|
221
|
+
const slideOverrides = slides
|
|
222
|
+
.map(
|
|
223
|
+
(_, i) =>
|
|
224
|
+
`<Override PartName="/ppt/slides/slide${i + 1}.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slide+xml"/>`
|
|
225
|
+
)
|
|
226
|
+
.join('');
|
|
227
|
+
const contentTypes = `${XML_DECL}<Types xmlns="${CT_NS}"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/><Override PartName="/ppt/slideMasters/slideMaster1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml"/><Override PartName="/ppt/slideLayouts/slideLayout1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml"/><Override PartName="/ppt/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/><Override PartName="/ppt/presProps.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presProps+xml"/>${slideOverrides}<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/><Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/></Types>`;
|
|
228
|
+
const rootRels = `${XML_DECL}<Relationships xmlns="${PKG_REL_NS}"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="ppt/presentation.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/></Relationships>`;
|
|
229
|
+
|
|
230
|
+
const files: Array<readonly [string, string]> = [
|
|
231
|
+
['[Content_Types].xml', contentTypes],
|
|
232
|
+
['_rels/.rels', rootRels],
|
|
233
|
+
['docProps/core.xml', coreXml(title)],
|
|
234
|
+
['docProps/app.xml', appXml(slides.length)],
|
|
235
|
+
['ppt/presentation.xml', presentation],
|
|
236
|
+
['ppt/_rels/presentation.xml.rels', presentationRels],
|
|
237
|
+
['ppt/presProps.xml', `${XML_DECL}<p:presentationPr xmlns:a="${A_NS}" xmlns:r="${R_NS}" xmlns:p="${P_NS}"/>`],
|
|
238
|
+
['ppt/slideMasters/slideMaster1.xml', slideMasterXml()],
|
|
239
|
+
['ppt/slideMasters/_rels/slideMaster1.xml.rels', masterRels],
|
|
240
|
+
['ppt/slideLayouts/slideLayout1.xml', slideLayoutXml()],
|
|
241
|
+
['ppt/slideLayouts/_rels/slideLayout1.xml.rels', layoutRels],
|
|
242
|
+
['ppt/theme/theme1.xml', themeXml(accent, bodyFont)],
|
|
243
|
+
];
|
|
244
|
+
slides.forEach((slide, i) => {
|
|
245
|
+
files.push([`ppt/slides/slide${i + 1}.xml`, slideXml(slide, { accent, bodyFont, monoFont, ink })]);
|
|
246
|
+
files.push([`ppt/slides/_rels/slide${i + 1}.xml.rels`, slideRels]);
|
|
247
|
+
});
|
|
248
|
+
return pack(files);
|
|
249
|
+
}
|