gbpptx 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +253 -253
  3. package/package.json +48 -47
  4. package/src/index.js +29 -29
  5. package/src/kernel/model.js +651 -651
  6. package/src/kernel/parts.js +173 -173
  7. package/src/kernel/pptx.js +72 -72
  8. package/src/kernel/print.js +76 -76
  9. package/src/kernel/read.js +1018 -1018
  10. package/src/kernel/roundtrip.js +174 -174
  11. package/src/kernel/text.js +278 -278
  12. package/src/kernel/write.js +385 -385
  13. package/web/app/main.js +8 -8
  14. package/web/app/slides/arrange.js +101 -101
  15. package/web/app/slides/clipboard.js +93 -93
  16. package/web/app/slides/file.js +240 -240
  17. package/web/app/slides/find.js +201 -201
  18. package/web/app/slides/history.js +100 -100
  19. package/web/app/slides/keys.js +187 -187
  20. package/web/app/slides/menus.js +105 -105
  21. package/web/app/slides/objects.js +254 -254
  22. package/web/app/slides/render.js +183 -183
  23. package/web/app/slides/shared.js +85 -85
  24. package/web/app/slides/slides.js +103 -103
  25. package/web/app/slides/table.js +102 -102
  26. package/web/app/slides/text.js +418 -418
  27. package/web/app/slides/view.js +182 -182
  28. package/web/app/slides-app.js +354 -354
  29. package/web/app/ui/canvas.js +769 -769
  30. package/web/app/ui/color-panel.js +58 -58
  31. package/web/app/ui/dialogs.js +120 -120
  32. package/web/app/ui/file-io.js +116 -116
  33. package/web/app/ui/format-pane.js +427 -427
  34. package/web/app/ui/icons.js +241 -133
  35. package/web/app/ui/menu.js +77 -75
  36. package/web/app/ui/notify.js +45 -45
  37. package/web/app/ui/page-view.js +221 -221
  38. package/web/app/ui/popup.js +80 -80
  39. package/web/app/ui/present.js +292 -292
  40. package/web/app/ui/ribbon.js +855 -855
  41. package/web/app/ui/slide-pane.js +197 -197
  42. package/web/app/ui/statusbar.js +93 -93
  43. package/web/app/ui/text-styles.js +84 -84
  44. package/web/app/ui/titlebar.js +253 -250
  45. package/web/app/ui/transition.js +30 -30
  46. package/web/index.html +30 -29
  47. package/web/serve.mjs +26 -23
  48. package/web/styles/office.css +463 -463
  49. package/web/styles/slides.css +97 -97
  50. package/web/styles/tokens.css +154 -154
@@ -1,173 +1,173 @@
1
- // [文件] gbpptx·固定部件 —— 母版 / 版式 / 主题 / 文档属性 / 备注页的 XML(移植 Go parts.go)
2
- // [设计] 母版与版式只出一份「空白」版式:所有图形写在页内 spTree 上,不继承占位符,
3
- // 因此导入导出都不需要解析 sldLayout 的占位符几何——代价是导出后的页不套用模板版式(所见即所得)。
4
-
5
- import { hexColor, LINK_COLOR, pxToEmu, xmlEscape } from 'gbooxml';
6
- import { SLIDE_H, SLIDE_W, THEME_ORDER, THEMES_HEX, DEFAULT_THEME, isThemeKey, themeOfHex } from './pptx.js';
7
-
8
- /* ---------- 命名空间 ---------- */
9
-
10
- export const NS_DRAWING_M = 'http://schemas.openxmlformats.org/drawingml/2006/main';
11
- export const NS_REL_ATTR = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';
12
- export const NS_PRES_ML = 'http://schemas.openxmlformats.org/presentationml/2006/main';
13
-
14
- export const NS_DECL = `xmlns:a="${NS_DRAWING_M}" xmlns:r="${NS_REL_ATTR}" xmlns:p="${NS_PRES_ML}"`;
15
-
16
- /* ---------- 部件路径 ---------- */
17
-
18
- export const PART_PRESENTATION = 'ppt/presentation.xml';
19
- export const PART_MASTER = 'ppt/slideMasters/slideMaster1.xml';
20
- export const PART_LAYOUT = 'ppt/slideLayouts/slideLayout1.xml';
21
- export const PART_THEME = 'ppt/theme/theme1.xml';
22
- export const PART_CORE_PROPS = 'docProps/core.xml';
23
- export const PART_APP_PROPS = 'docProps/app.xml';
24
-
25
- /* ---------- 关系类型 ---------- */
26
-
27
- const REL_BASE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/';
28
- export const REL_OFFICE_DOC = `${REL_BASE}officeDocument`;
29
- export const REL_SLIDE = `${REL_BASE}slide`;
30
- export const REL_NOTES = `${REL_BASE}notesSlide`;
31
- export const REL_MASTER = `${REL_BASE}slideMaster`;
32
- export const REL_LAYOUT = `${REL_BASE}slideLayout`;
33
- export const REL_THEME = `${REL_BASE}theme`;
34
- export const REL_IMAGE = `${REL_BASE}image`;
35
- export const REL_CORE_PROPS = 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties';
36
- export const REL_APP_PROPS = `${REL_BASE}extended-properties`;
37
-
38
- /* ---------- 内容类型 ---------- */
39
-
40
- export const CT_PRESENTATION = 'application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml';
41
- export const CT_MASTER = 'application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml';
42
- export const CT_LAYOUT = 'application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml';
43
- export const CT_THEME = 'application/vnd.openxmlformats-officedocument.theme+xml';
44
- export const CT_SLIDE = 'application/vnd.openxmlformats-officedocument.presentationml.slide+xml';
45
- export const CT_NOTES = 'application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml';
46
- export const CT_CORE_PROPS = 'application/vnd.openxmlformats-package.core-properties+xml';
47
- export const CT_APP_PROPS = 'application/vnd.openxmlformats-officedocument.extended-properties+xml';
48
-
49
- export const XML_HEAD = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
50
-
51
- /** 主题键借主题名往返(PowerPoint 只把它当显示名) */
52
- export const THEME_NAME_PREFIX = 'Guabi ';
53
-
54
- /** 主题的正文/标题字体族 */
55
- const UI_FONT = 'Segoe UI';
56
-
57
- /* ---------- 文件/路径命名 ---------- */
58
-
59
- export const slideFileName = (n) => `slide${n}.xml`;
60
- export const notesFileName = (n) => `notesSlide${n}.xml`;
61
- export const slidePath = (n) => `ppt/slides/${slideFileName(n)}`;
62
- export const notesPath = (n) => `ppt/notesSlides/${notesFileName(n)}`;
63
-
64
- /* ---------- 结构片段 ---------- */
65
-
66
- /** spTree 图形树:母版、版式、页三处的组属性完全一致,只有内部元素不同 */
67
- export const spTree = (children) =>
68
- `<p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>` +
69
- `<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>` +
70
- `${children}</p:spTree>`;
71
-
72
- /** 母版必备的角色映射 */
73
- const CLR_MAP = '<p:clrMap bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1" accent2="accent2"' +
74
- ' accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" hlink="hlink" folHlink="folHlink"/>';
75
-
76
- /** 格式方案:fill/line/effect/bgFill 四张列表各至少一项,实际效果一律由页内元素指定 */
77
- const FMT_SCHEME = '<a:fmtScheme name="Guabi"><a:fillStyleLst>' +
78
- '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
79
- '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
80
- '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
81
- '</a:fillStyleLst><a:lnStyleLst>' +
82
- '<a:ln w="6350" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln>' +
83
- '<a:ln w="12700" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln>' +
84
- '<a:ln w="19050" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln>' +
85
- '</a:lnStyleLst><a:effectStyleLst>' +
86
- '<a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle>' +
87
- '</a:effectStyleLst><a:bgFillStyleLst>' +
88
- '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
89
- '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
90
- '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
91
- '</a:bgFillStyleLst></a:fmtScheme>';
92
-
93
- /** 演示文稿主部件(页 id 从 256 起、母版 id 固定 2^31——PowerPoint 的隐含要求) */
94
- export const presentationPart = (slideIDs, size = { w: SLIDE_W, h: SLIDE_H }) =>
95
- XML_HEAD + `<p:presentation ${NS_DECL}>` +
96
- '<p:sldMasterIdLst><p:sldMasterId id="2147483648" r:id="rId1"/></p:sldMasterIdLst>' +
97
- `<p:sldIdLst>${slideIDs}</p:sldIdLst>` +
98
- `<p:sldSz cx="${pxToEmu(size.w)}" cy="${pxToEmu(size.h)}"/>` +
99
- '<p:notesSz cx="6858000" cy="9144000"/>' +
100
- '</p:presentation>';
101
-
102
- /** 页条目(id 从 256 起,rId 指向该页的关系) */
103
- export const slideID = (n, rid, hidden = false) => `<p:sldId id="${255 + n}" r:id="${rid}"${hidden ? ' show="0"' : ''}/>`;
104
-
105
- /** 母版:空图形树 + 一个空白版式 */
106
- export const slideMasterPart = () =>
107
- XML_HEAD + `<p:sldMaster ${NS_DECL}><p:cSld>` +
108
- `<p:bg><p:bgPr><a:solidFill><a:srgbClr val="${themeOfHex(DEFAULT_THEME).bg}"/></a:solidFill><a:effectLst/></p:bgPr></p:bg>` +
109
- `${spTree('')}</p:cSld>${CLR_MAP}` +
110
- '<p:sldLayoutIdLst><p:sldLayoutId id="2147483649" r:id="rId1"/></p:sldLayoutIdLst></p:sldMaster>';
111
-
112
- /** 版式:空白版式,页内元素一概不继承占位符 */
113
- export const slideLayoutPart = () =>
114
- XML_HEAD + `<p:sldLayout ${NS_DECL} type="blank"><p:cSld name="Blank">${spTree('')}` +
115
- '</p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:sldLayout>';
116
-
117
- /** 主题部件(色板由主题表推导,主题键写在 name 上供回读) */
118
- export const themePart = (key) => {
119
- const themeKey = isThemeKey(key) ? key : DEFAULT_THEME;
120
- let accents = '';
121
- THEME_ORDER.forEach((k, i) => {
122
- accents += `<a:accent${i + 1}><a:srgbClr val="${THEMES_HEX[k].accent}"/></a:accent${i + 1}>`;
123
- });
124
- const clrScheme = '<a:clrScheme name="Guabi">' +
125
- `<a:dk1><a:srgbClr val="${THEMES_HEX[DEFAULT_THEME].text}"/></a:dk1>` +
126
- `<a:lt1><a:srgbClr val="${THEMES_HEX[DEFAULT_THEME].bg}"/></a:lt1>` +
127
- `<a:dk2><a:srgbClr val="${THEMES_HEX.midnight.bg}"/></a:dk2>` +
128
- `<a:lt2><a:srgbClr val="${THEMES_HEX.paper.bg}"/></a:lt2>` +
129
- accents +
130
- `<a:hlink><a:srgbClr val="${hexColor(LINK_COLOR, '1D6FD4')}"/></a:hlink>` +
131
- `<a:folHlink><a:srgbClr val="${THEMES_HEX.paper.accent}"/></a:folHlink>` +
132
- '</a:clrScheme>';
133
- const fontScheme = '<a:fontScheme name="Guabi">' +
134
- `<a:majorFont><a:latin typeface="${UI_FONT}"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont>` +
135
- `<a:minorFont><a:latin typeface="${UI_FONT}"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont>` +
136
- '</a:fontScheme>';
137
- return XML_HEAD + `<a:theme xmlns:a="${NS_DRAWING_M}" name="${THEME_NAME_PREFIX}${themeKey}">` +
138
- `<a:themeElements>${clrScheme}${fontScheme}${FMT_SCHEME}</a:themeElements></a:theme>`;
139
- };
140
-
141
- /** 文档属性(标题随演示文稿名走) */
142
- export const coreProps = (title) =>
143
- XML_HEAD + '<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" ' +
144
- 'xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" ' +
145
- `xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><dc:title>${xmlEscape(title || '')}` +
146
- '</dc:title><dc:creator>Guabi Slides</dc:creator><cp:lastModifiedBy>Guabi Slides</cp:lastModifiedBy></cp:coreProperties>';
147
-
148
- /** 扩展属性 */
149
- export const appProps = () =>
150
- XML_HEAD + '<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" ' +
151
- 'xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">' +
152
- '<Application>Guabi Slides</Application></Properties>';
153
-
154
- /** 备注页(两个形状是 PowerPoint 的要求,少一个打开时会提示修复) */
155
- export const notesSlidePart = (notes) => {
156
- let body = '';
157
- for (const line of String(notes ?? '').split('\n')) {
158
- body += `<a:p><a:r><a:rPr lang="zh-CN" dirty="0"/><a:t>${xmlEscape(line)}</a:t></a:r></a:p>`;
159
- }
160
- if (body === '') body = '<a:p><a:endParaRPr lang="zh-CN" dirty="0"/></a:p>';
161
- return XML_HEAD + `<p:notes ${NS_DECL} xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main"><p:cSld>` +
162
- spTree('<p:sp><p:nvSpPr><p:cNvPr id="2" name="Slide Image Placeholder 1"/>' +
163
- '<p:cNvSpPr><a:spLocks noGrp="1" noRot="1" noChangeAspect="1" noMove="1" noResize="1"/></p:cNvSpPr>' +
164
- '<p:nvPr><p:extLst><p:ext uri="{FF2B5EF4-FFF2-40B4-BE79-F238E27FC236}"><p14:modId val="1"/></p:ext></p:extLst></p:nvPr></p:nvSpPr>' +
165
- '<p:spPr><a:xfrm><a:off x="838200" y="1143000"/><a:ext cx="5029200" cy="3429000"/></a:xfrm>' +
166
- '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></p:spPr></p:sp>' +
167
- '<p:sp><p:nvSpPr><p:cNvPr id="3" name="Notes Placeholder 2"/><p:cNvSpPr><a:spLocks noGrp="1"/></p:cNvSpPr>' +
168
- '<p:nvPr><p:ph type="notes" idx="1"/></p:nvPr></p:nvSpPr>' +
169
- '<p:spPr><a:xfrm><a:off x="685800" y="4572000"/><a:ext cx="5486400" cy="3600450"/></a:xfrm>' +
170
- '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></p:spPr>' +
171
- `<p:txBody><a:bodyPr/><a:lstStyle/>${body}</p:txBody></p:sp>`) +
172
- '</p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:notes>';
173
- };
1
+ // [文件] gbpptx·固定部件 —— 母版 / 版式 / 主题 / 文档属性 / 备注页的 XML(移植 Go parts.go)
2
+ // [设计] 母版与版式只出一份「空白」版式:所有图形写在页内 spTree 上,不继承占位符,
3
+ // 因此导入导出都不需要解析 sldLayout 的占位符几何——代价是导出后的页不套用模板版式(所见即所得)。
4
+
5
+ import { hexColor, LINK_COLOR, pxToEmu, xmlEscape } from 'gbooxml';
6
+ import { SLIDE_H, SLIDE_W, THEME_ORDER, THEMES_HEX, DEFAULT_THEME, isThemeKey, themeOfHex } from './pptx.js';
7
+
8
+ /* ---------- 命名空间 ---------- */
9
+
10
+ export const NS_DRAWING_M = 'http://schemas.openxmlformats.org/drawingml/2006/main';
11
+ export const NS_REL_ATTR = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';
12
+ export const NS_PRES_ML = 'http://schemas.openxmlformats.org/presentationml/2006/main';
13
+
14
+ export const NS_DECL = `xmlns:a="${NS_DRAWING_M}" xmlns:r="${NS_REL_ATTR}" xmlns:p="${NS_PRES_ML}"`;
15
+
16
+ /* ---------- 部件路径 ---------- */
17
+
18
+ export const PART_PRESENTATION = 'ppt/presentation.xml';
19
+ export const PART_MASTER = 'ppt/slideMasters/slideMaster1.xml';
20
+ export const PART_LAYOUT = 'ppt/slideLayouts/slideLayout1.xml';
21
+ export const PART_THEME = 'ppt/theme/theme1.xml';
22
+ export const PART_CORE_PROPS = 'docProps/core.xml';
23
+ export const PART_APP_PROPS = 'docProps/app.xml';
24
+
25
+ /* ---------- 关系类型 ---------- */
26
+
27
+ const REL_BASE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/';
28
+ export const REL_OFFICE_DOC = `${REL_BASE}officeDocument`;
29
+ export const REL_SLIDE = `${REL_BASE}slide`;
30
+ export const REL_NOTES = `${REL_BASE}notesSlide`;
31
+ export const REL_MASTER = `${REL_BASE}slideMaster`;
32
+ export const REL_LAYOUT = `${REL_BASE}slideLayout`;
33
+ export const REL_THEME = `${REL_BASE}theme`;
34
+ export const REL_IMAGE = `${REL_BASE}image`;
35
+ export const REL_CORE_PROPS = 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties';
36
+ export const REL_APP_PROPS = `${REL_BASE}extended-properties`;
37
+
38
+ /* ---------- 内容类型 ---------- */
39
+
40
+ export const CT_PRESENTATION = 'application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml';
41
+ export const CT_MASTER = 'application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml';
42
+ export const CT_LAYOUT = 'application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml';
43
+ export const CT_THEME = 'application/vnd.openxmlformats-officedocument.theme+xml';
44
+ export const CT_SLIDE = 'application/vnd.openxmlformats-officedocument.presentationml.slide+xml';
45
+ export const CT_NOTES = 'application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml';
46
+ export const CT_CORE_PROPS = 'application/vnd.openxmlformats-package.core-properties+xml';
47
+ export const CT_APP_PROPS = 'application/vnd.openxmlformats-officedocument.extended-properties+xml';
48
+
49
+ export const XML_HEAD = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
50
+
51
+ /** 主题键借主题名往返(PowerPoint 只把它当显示名) */
52
+ export const THEME_NAME_PREFIX = 'Guabi ';
53
+
54
+ /** 主题的正文/标题字体族 */
55
+ const UI_FONT = 'Segoe UI';
56
+
57
+ /* ---------- 文件/路径命名 ---------- */
58
+
59
+ export const slideFileName = (n) => `slide${n}.xml`;
60
+ export const notesFileName = (n) => `notesSlide${n}.xml`;
61
+ export const slidePath = (n) => `ppt/slides/${slideFileName(n)}`;
62
+ export const notesPath = (n) => `ppt/notesSlides/${notesFileName(n)}`;
63
+
64
+ /* ---------- 结构片段 ---------- */
65
+
66
+ /** spTree 图形树:母版、版式、页三处的组属性完全一致,只有内部元素不同 */
67
+ export const spTree = (children) =>
68
+ `<p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>` +
69
+ `<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>` +
70
+ `${children}</p:spTree>`;
71
+
72
+ /** 母版必备的角色映射 */
73
+ const CLR_MAP = '<p:clrMap bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1" accent2="accent2"' +
74
+ ' accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" hlink="hlink" folHlink="folHlink"/>';
75
+
76
+ /** 格式方案:fill/line/effect/bgFill 四张列表各至少一项,实际效果一律由页内元素指定 */
77
+ const FMT_SCHEME = '<a:fmtScheme name="Guabi"><a:fillStyleLst>' +
78
+ '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
79
+ '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
80
+ '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
81
+ '</a:fillStyleLst><a:lnStyleLst>' +
82
+ '<a:ln w="6350" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln>' +
83
+ '<a:ln w="12700" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln>' +
84
+ '<a:ln w="19050" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln>' +
85
+ '</a:lnStyleLst><a:effectStyleLst>' +
86
+ '<a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle>' +
87
+ '</a:effectStyleLst><a:bgFillStyleLst>' +
88
+ '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
89
+ '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
90
+ '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
91
+ '</a:bgFillStyleLst></a:fmtScheme>';
92
+
93
+ /** 演示文稿主部件(页 id 从 256 起、母版 id 固定 2^31——PowerPoint 的隐含要求) */
94
+ export const presentationPart = (slideIDs, size = { w: SLIDE_W, h: SLIDE_H }) =>
95
+ XML_HEAD + `<p:presentation ${NS_DECL}>` +
96
+ '<p:sldMasterIdLst><p:sldMasterId id="2147483648" r:id="rId1"/></p:sldMasterIdLst>' +
97
+ `<p:sldIdLst>${slideIDs}</p:sldIdLst>` +
98
+ `<p:sldSz cx="${pxToEmu(size.w)}" cy="${pxToEmu(size.h)}"/>` +
99
+ '<p:notesSz cx="6858000" cy="9144000"/>' +
100
+ '</p:presentation>';
101
+
102
+ /** 页条目(id 从 256 起,rId 指向该页的关系) */
103
+ export const slideID = (n, rid, hidden = false) => `<p:sldId id="${255 + n}" r:id="${rid}"${hidden ? ' show="0"' : ''}/>`;
104
+
105
+ /** 母版:空图形树 + 一个空白版式 */
106
+ export const slideMasterPart = () =>
107
+ XML_HEAD + `<p:sldMaster ${NS_DECL}><p:cSld>` +
108
+ `<p:bg><p:bgPr><a:solidFill><a:srgbClr val="${themeOfHex(DEFAULT_THEME).bg}"/></a:solidFill><a:effectLst/></p:bgPr></p:bg>` +
109
+ `${spTree('')}</p:cSld>${CLR_MAP}` +
110
+ '<p:sldLayoutIdLst><p:sldLayoutId id="2147483649" r:id="rId1"/></p:sldLayoutIdLst></p:sldMaster>';
111
+
112
+ /** 版式:空白版式,页内元素一概不继承占位符 */
113
+ export const slideLayoutPart = () =>
114
+ XML_HEAD + `<p:sldLayout ${NS_DECL} type="blank"><p:cSld name="Blank">${spTree('')}` +
115
+ '</p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:sldLayout>';
116
+
117
+ /** 主题部件(色板由主题表推导,主题键写在 name 上供回读) */
118
+ export const themePart = (key) => {
119
+ const themeKey = isThemeKey(key) ? key : DEFAULT_THEME;
120
+ let accents = '';
121
+ THEME_ORDER.forEach((k, i) => {
122
+ accents += `<a:accent${i + 1}><a:srgbClr val="${THEMES_HEX[k].accent}"/></a:accent${i + 1}>`;
123
+ });
124
+ const clrScheme = '<a:clrScheme name="Guabi">' +
125
+ `<a:dk1><a:srgbClr val="${THEMES_HEX[DEFAULT_THEME].text}"/></a:dk1>` +
126
+ `<a:lt1><a:srgbClr val="${THEMES_HEX[DEFAULT_THEME].bg}"/></a:lt1>` +
127
+ `<a:dk2><a:srgbClr val="${THEMES_HEX.midnight.bg}"/></a:dk2>` +
128
+ `<a:lt2><a:srgbClr val="${THEMES_HEX.paper.bg}"/></a:lt2>` +
129
+ accents +
130
+ `<a:hlink><a:srgbClr val="${hexColor(LINK_COLOR, '1D6FD4')}"/></a:hlink>` +
131
+ `<a:folHlink><a:srgbClr val="${THEMES_HEX.paper.accent}"/></a:folHlink>` +
132
+ '</a:clrScheme>';
133
+ const fontScheme = '<a:fontScheme name="Guabi">' +
134
+ `<a:majorFont><a:latin typeface="${UI_FONT}"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont>` +
135
+ `<a:minorFont><a:latin typeface="${UI_FONT}"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont>` +
136
+ '</a:fontScheme>';
137
+ return XML_HEAD + `<a:theme xmlns:a="${NS_DRAWING_M}" name="${THEME_NAME_PREFIX}${themeKey}">` +
138
+ `<a:themeElements>${clrScheme}${fontScheme}${FMT_SCHEME}</a:themeElements></a:theme>`;
139
+ };
140
+
141
+ /** 文档属性(标题随演示文稿名走) */
142
+ export const coreProps = (title) =>
143
+ XML_HEAD + '<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" ' +
144
+ 'xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" ' +
145
+ `xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><dc:title>${xmlEscape(title || '')}` +
146
+ '</dc:title><dc:creator>Guabi Slides</dc:creator><cp:lastModifiedBy>Guabi Slides</cp:lastModifiedBy></cp:coreProperties>';
147
+
148
+ /** 扩展属性 */
149
+ export const appProps = () =>
150
+ XML_HEAD + '<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" ' +
151
+ 'xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">' +
152
+ '<Application>Guabi Slides</Application></Properties>';
153
+
154
+ /** 备注页(两个形状是 PowerPoint 的要求,少一个打开时会提示修复) */
155
+ export const notesSlidePart = (notes) => {
156
+ let body = '';
157
+ for (const line of String(notes ?? '').split('\n')) {
158
+ body += `<a:p><a:r><a:rPr lang="zh-CN" dirty="0"/><a:t>${xmlEscape(line)}</a:t></a:r></a:p>`;
159
+ }
160
+ if (body === '') body = '<a:p><a:endParaRPr lang="zh-CN" dirty="0"/></a:p>';
161
+ return XML_HEAD + `<p:notes ${NS_DECL} xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main"><p:cSld>` +
162
+ spTree('<p:sp><p:nvSpPr><p:cNvPr id="2" name="Slide Image Placeholder 1"/>' +
163
+ '<p:cNvSpPr><a:spLocks noGrp="1" noRot="1" noChangeAspect="1" noMove="1" noResize="1"/></p:cNvSpPr>' +
164
+ '<p:nvPr><p:extLst><p:ext uri="{FF2B5EF4-FFF2-40B4-BE79-F238E27FC236}"><p14:modId val="1"/></p:ext></p:extLst></p:nvPr></p:nvSpPr>' +
165
+ '<p:spPr><a:xfrm><a:off x="838200" y="1143000"/><a:ext cx="5029200" cy="3429000"/></a:xfrm>' +
166
+ '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></p:spPr></p:sp>' +
167
+ '<p:sp><p:nvSpPr><p:cNvPr id="3" name="Notes Placeholder 2"/><p:cNvSpPr><a:spLocks noGrp="1"/></p:cNvSpPr>' +
168
+ '<p:nvPr><p:ph type="notes" idx="1"/></p:nvPr></p:nvSpPr>' +
169
+ '<p:spPr><a:xfrm><a:off x="685800" y="4572000"/><a:ext cx="5486400" cy="3600450"/></a:xfrm>' +
170
+ '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></p:spPr>' +
171
+ `<p:txBody><a:bodyPr/><a:lstStyle/>${body}</p:txBody></p:sp>`) +
172
+ '</p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:notes>';
173
+ };
@@ -1,72 +1,72 @@
1
- // [文件] gbpptx·转换引擎常量 —— 模型⇄PresentationML 的主题表、字号/几何换算与图形预设映射(移植 Go pptx.go)
2
-
3
- import { SHAPE_KINDS, SLIDE_H, SLIDE_W, THEMES, THEME_KEYS, themeOf } from './model.js';
4
-
5
- /** 幻灯片逻辑坐标(16:9),与前端画布、放映、打印同一坐标系 */
6
- export { SLIDE_W, SLIDE_H };
7
-
8
- /** 主题表(大写裸十六进制形式):由 model.js 的 THEMES 派生,禁另立第二份色值(改一处必漏一处) */
9
- const toHex = (css) => String(css).replace('#', '').toUpperCase();
10
- export const THEMES_HEX = Object.fromEntries(
11
- THEME_KEYS.map((k) => [k, { bg: toHex(THEMES[k].bg), text: toHex(THEMES[k].text), accent: toHex(THEMES[k].accent) }]),
12
- );
13
-
14
- /** 主题在主题部件里的位次(clrScheme 的 accent1~accent6),声明顺序即 model.js 的主题顺序 */
15
- export const THEME_ORDER = [...THEME_KEYS];
16
-
17
- /** 认不出的主题键一律回落它 */
18
- export const DEFAULT_THEME = 'clean';
19
-
20
- /** 图形默认填充:等于 clean 主题的强调色,与 model.js 的 createShapeObject 初始 fill 同值 */
21
- export const DEFAULT_SHAPE_FILL = THEMES.clean.accent;
22
-
23
- /** 主题键 → 大写色表(认不出回落默认) */
24
- export const themeOfHex = (key) => THEMES_HEX[key] || THEMES_HEX[DEFAULT_THEME];
25
-
26
- /** 主题键是否有效 */
27
- export const isThemeKey = (key) => Object.prototype.hasOwnProperty.call(THEMES_HEX, key);
28
-
29
- /* ---------- 换算 ---------- */
30
-
31
- /** CSS px → PresentationML 的百分之一磅(w:sz) */
32
- export const fontSizeToSz = (px) => {
33
- const v = px > 0 ? px : 24;
34
- return Math.round(v * 0.75 * 100);
35
- };
36
-
37
- /** 反向:百分之一磅 → CSS px */
38
- export const szToFontSize = (sz) => (sz > 0 ? sz / 100 / 0.75 : 0);
39
-
40
- export const maxF = (a, b) => (a > b ? a : b);
41
-
42
- export const boolAttr = (b) => (b ? '1' : '0');
43
-
44
- /** 主题键在编辑器侧的中文名(属性面板/主题下拉用) */
45
- export const themeLabel = (key) => themeOf(key).label;
46
-
47
- /* ---------- 图形预设映射 ---------- */
48
-
49
- /** 编辑器 kind → PresentationML prst(唯一来源:model.js 的形状库) */
50
- export const KIND_TO_PRST = Object.fromEntries(SHAPE_KINDS.map((k) => [k.kind, k.prst]));
51
-
52
- /** PresentationML prst → 编辑器 kind;不认识的预设按最接近的可编辑形状收口 */
53
- export const PRST_TO_KIND = {
54
- ...Object.fromEntries(SHAPE_KINDS.map((k) => [k.prst, k.kind])),
55
- flowChartProcess: 'rect',
56
- flowChartAlternateProcess: 'round',
57
- flowChartDecision: 'diamond',
58
- flowChartTerminator: 'round',
59
- flowChartDocument: 'rect',
60
- flowChartPredefinedProcess: 'rect',
61
- flowChartConnector: 'ellipse',
62
- wedgeRectCallout: 'rect',
63
- wedgeRoundRectCallout: 'round',
64
- wedgeEllipseCallout: 'ellipse',
65
- };
66
-
67
- /** 是否像 pptx(OPC 包一律是 zip;旧版 .ppt 是 OLE 复合文档,魔数 D0CF) */
68
- export function isPptx(data) {
69
- const b = data instanceof Uint8Array ? data : new Uint8Array(data || []);
70
- if (b.length > 8 && b[0] === 0xd0 && b[1] === 0xcf) return false;
71
- return b.length > 4 && b[0] === 0x50 && b[1] === 0x4b && b[2] === 3 && b[3] === 4;
72
- }
1
+ // [文件] gbpptx·转换引擎常量 —— 模型⇄PresentationML 的主题表、字号/几何换算与图形预设映射(移植 Go pptx.go)
2
+
3
+ import { SHAPE_KINDS, SLIDE_H, SLIDE_W, THEMES, THEME_KEYS, themeOf } from './model.js';
4
+
5
+ /** 幻灯片逻辑坐标(16:9),与前端画布、放映、打印同一坐标系 */
6
+ export { SLIDE_W, SLIDE_H };
7
+
8
+ /** 主题表(大写裸十六进制形式):由 model.js 的 THEMES 派生,禁另立第二份色值(改一处必漏一处) */
9
+ const toHex = (css) => String(css).replace('#', '').toUpperCase();
10
+ export const THEMES_HEX = Object.fromEntries(
11
+ THEME_KEYS.map((k) => [k, { bg: toHex(THEMES[k].bg), text: toHex(THEMES[k].text), accent: toHex(THEMES[k].accent) }]),
12
+ );
13
+
14
+ /** 主题在主题部件里的位次(clrScheme 的 accent1~accent6),声明顺序即 model.js 的主题顺序 */
15
+ export const THEME_ORDER = [...THEME_KEYS];
16
+
17
+ /** 认不出的主题键一律回落它 */
18
+ export const DEFAULT_THEME = 'clean';
19
+
20
+ /** 图形默认填充:等于 clean 主题的强调色,与 model.js 的 createShapeObject 初始 fill 同值 */
21
+ export const DEFAULT_SHAPE_FILL = THEMES.clean.accent;
22
+
23
+ /** 主题键 → 大写色表(认不出回落默认) */
24
+ export const themeOfHex = (key) => THEMES_HEX[key] || THEMES_HEX[DEFAULT_THEME];
25
+
26
+ /** 主题键是否有效 */
27
+ export const isThemeKey = (key) => Object.prototype.hasOwnProperty.call(THEMES_HEX, key);
28
+
29
+ /* ---------- 换算 ---------- */
30
+
31
+ /** CSS px → PresentationML 的百分之一磅(w:sz) */
32
+ export const fontSizeToSz = (px) => {
33
+ const v = px > 0 ? px : 24;
34
+ return Math.round(v * 0.75 * 100);
35
+ };
36
+
37
+ /** 反向:百分之一磅 → CSS px */
38
+ export const szToFontSize = (sz) => (sz > 0 ? sz / 100 / 0.75 : 0);
39
+
40
+ export const maxF = (a, b) => (a > b ? a : b);
41
+
42
+ export const boolAttr = (b) => (b ? '1' : '0');
43
+
44
+ /** 主题键在编辑器侧的中文名(属性面板/主题下拉用) */
45
+ export const themeLabel = (key) => themeOf(key).label;
46
+
47
+ /* ---------- 图形预设映射 ---------- */
48
+
49
+ /** 编辑器 kind → PresentationML prst(唯一来源:model.js 的形状库) */
50
+ export const KIND_TO_PRST = Object.fromEntries(SHAPE_KINDS.map((k) => [k.kind, k.prst]));
51
+
52
+ /** PresentationML prst → 编辑器 kind;不认识的预设按最接近的可编辑形状收口 */
53
+ export const PRST_TO_KIND = {
54
+ ...Object.fromEntries(SHAPE_KINDS.map((k) => [k.prst, k.kind])),
55
+ flowChartProcess: 'rect',
56
+ flowChartAlternateProcess: 'round',
57
+ flowChartDecision: 'diamond',
58
+ flowChartTerminator: 'round',
59
+ flowChartDocument: 'rect',
60
+ flowChartPredefinedProcess: 'rect',
61
+ flowChartConnector: 'ellipse',
62
+ wedgeRectCallout: 'rect',
63
+ wedgeRoundRectCallout: 'round',
64
+ wedgeEllipseCallout: 'ellipse',
65
+ };
66
+
67
+ /** 是否像 pptx(OPC 包一律是 zip;旧版 .ppt 是 OLE 复合文档,魔数 D0CF) */
68
+ export function isPptx(data) {
69
+ const b = data instanceof Uint8Array ? data : new Uint8Array(data || []);
70
+ if (b.length > 8 && b[0] === 0xd0 && b[1] === 0xcf) return false;
71
+ return b.length > 4 && b[0] === 0x50 && b[1] === 0x4b && b[2] === 3 && b[3] === 4;
72
+ }