gbpptx 0.1.0 → 0.2.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/README.md +214 -0
- package/package.json +14 -4
- package/src/index.js +16 -8
- package/src/kernel/model.js +396 -89
- package/src/kernel/parts.js +15 -11
- package/src/kernel/pptx.js +17 -12
- package/src/kernel/print.js +16 -14
- package/src/kernel/read.js +747 -157
- package/src/kernel/roundtrip.js +123 -19
- package/src/kernel/text.js +133 -28
- package/src/kernel/write.js +160 -49
- package/web/app/slides-app.js +2079 -477
- package/web/app/ui/backstage.js +255 -0
- package/web/app/ui/canvas.js +619 -141
- package/web/app/ui/color-panel.js +27 -9
- package/web/app/ui/dialogs.js +42 -3
- package/web/app/ui/file-io.js +66 -23
- package/web/app/ui/format-pane.js +427 -0
- package/web/app/ui/icons.js +129 -0
- package/web/app/ui/menu.js +26 -42
- package/web/app/ui/page-view.js +135 -64
- package/web/app/ui/present.js +257 -65
- package/web/app/ui/ribbon.js +878 -0
- package/web/app/ui/slide-pane.js +189 -0
- package/web/app/ui/statusbar.js +93 -0
- package/web/app/ui/titlebar.js +101 -0
- package/web/app/ui/transition.js +30 -0
- package/web/index.html +1 -0
- package/web/serve.mjs +1 -1
- package/web/styles/office.css +644 -0
- package/web/styles/slides.css +184 -177
- package/src/kernel/menus.js +0 -123
- package/web/app/ui/inspector.js +0 -209
- package/web/app/ui/slides-bar.js +0 -63
- package/web/app/ui/toolbar.js +0 -200
package/src/kernel/write.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
// [文件] gbpptx·生成 —— Presentation 序列化成 .pptx(页内 spTree 承载全部元素 + 内嵌媒体 +
|
|
2
|
-
// [设计]
|
|
1
|
+
// [文件] gbpptx·生成 —— Presentation 序列化成 .pptx(页内 spTree 承载全部元素 + 内嵌媒体 + 备注页)
|
|
2
|
+
// [设计] 逻辑画布按 96dpi 写成 EMU,画幅由快照 size 决定(16:9/4:3/自定义均原样保留)。
|
|
3
3
|
// [坑] 图片只认 data URL:前端插图一律 base64 内嵌,远程 URL 会被静默跳过(离线打开必然丢图)。
|
|
4
4
|
|
|
5
|
-
import { OpcPackage, decodeDataUrl, hexColor, pxToEmu, xmlEscape } from 'gbooxml';
|
|
6
|
-
import {
|
|
5
|
+
import { OpcPackage, decodeDataUrl, hexColor, pxToEmu, xmlEscape, xmlEscapeAttr } from 'gbooxml';
|
|
6
|
+
import { DEFAULT_THEME, THEMES_HEX, boolAttr, fontSizeToSz, maxF, themeOfHex } from './pptx.js';
|
|
7
|
+
import { DASH_STYLES, sizeOf, shapePreset, tableStyleColors, transitionOf } from './model.js';
|
|
7
8
|
import {
|
|
8
9
|
CT_APP_PROPS, CT_CORE_PROPS, CT_LAYOUT, CT_MASTER, CT_NOTES, CT_PRESENTATION, CT_SLIDE, CT_THEME,
|
|
9
10
|
PART_APP_PROPS, PART_CORE_PROPS, PART_LAYOUT, PART_MASTER, PART_PRESENTATION, PART_THEME,
|
|
@@ -11,26 +12,49 @@ import {
|
|
|
11
12
|
XML_HEAD, NS_DECL, NS_DRAWING_M, appProps, coreProps, notesFileName, notesPath, notesSlidePart,
|
|
12
13
|
presentationPart, slideFileName, slideID, slideLayoutPart, slideMasterPart, slidePath, spTree, themePart,
|
|
13
14
|
} from './parts.js';
|
|
14
|
-
import { htmlToParas, parasOfPlain
|
|
15
|
+
import { htmlToParas, parasOfPlain } from './text.js';
|
|
15
16
|
|
|
16
17
|
/* ---------- 元素级默认取值(与 model.js 工厂同值) ---------- */
|
|
17
18
|
const SHAPE_STROKE = '#333333';
|
|
18
19
|
const SHAPE_TEXT_COLOR = '#ffffff';
|
|
19
20
|
const TABLE_FONT_SIZE = 16;
|
|
20
21
|
const LINE_STROKE_W = 2;
|
|
22
|
+
const TABLE_BORDER_W = 1;
|
|
21
23
|
|
|
22
24
|
/** 模型里的颜色(CSS 形式)→ 部件属性要的大写裸十六进制 */
|
|
23
25
|
const xmlColor = (css) => hexColor(css, '');
|
|
24
26
|
|
|
27
|
+
/** 实心填充片段;空色一律 noFill(形状可无填充) */
|
|
28
|
+
const fillXML = (color, fallback = '') => {
|
|
29
|
+
const c = xmlColor(color || fallback);
|
|
30
|
+
return c ? `<a:solidFill><a:srgbClr val="${c}"/></a:solidFill>` : '<a:noFill/>';
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** 线条片段(宽度为 0 或没有颜色 → 无线条) */
|
|
34
|
+
function strokeXML(color, width, dash = 'solid') {
|
|
35
|
+
const c = xmlColor(color);
|
|
36
|
+
if (!c || !(width > 0)) return '<a:ln><a:noFill/></a:ln>';
|
|
37
|
+
let out = `<a:ln w="${pxToEmu(width)}" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:srgbClr val="${c}"/></a:solidFill>`;
|
|
38
|
+
if (dash && dash !== 'solid' && DASH_STYLES[dash]) out += `<a:prstDash val="${dash}"/>`;
|
|
39
|
+
return `${out}</a:ln>`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** 阴影效果(开关式;与渲染层的 drop-shadow 同口径) */
|
|
43
|
+
const shadowXML = (on) => (on
|
|
44
|
+
? '<a:effectLst><a:outerShdw blurRad="40000" dist="20000" dir="5400000" algn="ctr" rotWithShape="0">' +
|
|
45
|
+
'<a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst>'
|
|
46
|
+
: '<a:effectLst/>');
|
|
47
|
+
|
|
25
48
|
/**
|
|
26
49
|
* 把 Presentation 序列化为 .pptx 字节
|
|
27
|
-
* @param {object} p 快照({version,title,theme,slides[]})
|
|
50
|
+
* @param {object} p 快照({version,title,theme,size,slides[]})
|
|
28
51
|
* @returns {Promise<Uint8Array>}
|
|
29
52
|
*/
|
|
30
53
|
export async function buildPptx(p) {
|
|
31
54
|
if (!p) throw new Error('演示文稿为空');
|
|
32
55
|
const slides = (p.slides || []).filter(Boolean);
|
|
33
56
|
if (slides.length === 0) throw new Error('演示文稿没有幻灯片');
|
|
57
|
+
const size = sizeOf(p);
|
|
34
58
|
|
|
35
59
|
const pkg = new OpcPackage();
|
|
36
60
|
pkg.relAs('', 'rId1', REL_OFFICE_DOC, PART_PRESENTATION);
|
|
@@ -43,9 +67,9 @@ export async function buildPptx(p) {
|
|
|
43
67
|
slides.forEach((slide, i) => {
|
|
44
68
|
const rid = `rId${i + 2}`;
|
|
45
69
|
pkg.relAs(PART_PRESENTATION, rid, REL_SLIDE, `slides/${slideFileName(i + 1)}`);
|
|
46
|
-
slideIDs += slideID(i + 1, rid);
|
|
70
|
+
slideIDs += slideID(i + 1, rid, !!slide.hidden);
|
|
47
71
|
});
|
|
48
|
-
pkg.add(PART_PRESENTATION, CT_PRESENTATION, presentationPart(slideIDs));
|
|
72
|
+
pkg.add(PART_PRESENTATION, CT_PRESENTATION, presentationPart(slideIDs, size));
|
|
49
73
|
|
|
50
74
|
pkg.relAs(PART_MASTER, 'rId1', REL_LAYOUT, '../slideLayouts/slideLayout1.xml');
|
|
51
75
|
pkg.relAs(PART_MASTER, 'rId2', REL_THEME, '../theme/theme1.xml');
|
|
@@ -56,7 +80,7 @@ export async function buildPptx(p) {
|
|
|
56
80
|
pkg.add(PART_CORE_PROPS, CT_CORE_PROPS, coreProps(p.title));
|
|
57
81
|
pkg.add(PART_APP_PROPS, CT_APP_PROPS, appProps());
|
|
58
82
|
|
|
59
|
-
const t = themeOfHex(p.theme);
|
|
83
|
+
const t = { ...themeOfHex(p.theme), key: p.theme };
|
|
60
84
|
const em = new Emitter(pkg);
|
|
61
85
|
slides.forEach((slide, i) => {
|
|
62
86
|
const path = slidePath(i + 1);
|
|
@@ -95,20 +119,20 @@ class Emitter {
|
|
|
95
119
|
}
|
|
96
120
|
return XML_HEAD + `<p:sld ${NS_DECL}><p:cSld><p:bg><p:bgPr><a:solidFill><a:srgbClr val="${hexColor(bg, t.bg)}"/>` +
|
|
97
121
|
'</a:solidFill><a:effectLst/></p:bgPr></p:bg>' +
|
|
98
|
-
`${spTree(shapes)}</p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr
|
|
122
|
+
`${spTree(shapes)}</p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr>${transitionXML(slide)}</p:sld>`;
|
|
99
123
|
}
|
|
100
124
|
|
|
101
|
-
/**
|
|
125
|
+
/** 一个页内元素;未知类型返回空串(图片无效会直接抛错,避免静默丢图) */
|
|
102
126
|
objectXML(id, o, t) {
|
|
103
127
|
switch (o.type) {
|
|
104
128
|
case 'text': return textShapeXML(id, o, t);
|
|
105
129
|
case 'shape': return shapeXML(id, o);
|
|
106
130
|
case 'line': return lineXML(id, o);
|
|
107
|
-
case 'table': return tableFrameXML(id, o);
|
|
131
|
+
case 'table': return tableFrameXML(id, o, t);
|
|
108
132
|
case 'image': {
|
|
109
|
-
//
|
|
110
|
-
const decoded = decodeDataUrl(o.props.src
|
|
111
|
-
if (!decoded)
|
|
133
|
+
// 保留导入时的原始格式(png/jpeg/gif/svg/bmp/tiff/emf/wmf/webp),避免「打开再保存」丢图
|
|
134
|
+
const decoded = decodeDataUrl(o.props.src);
|
|
135
|
+
if (!decoded) throw new Error('图片数据无效或不是内嵌 data URL,无法写入 .pptx');
|
|
112
136
|
this.media += 1;
|
|
113
137
|
const name = `image${this.media}.${decoded.ext}`;
|
|
114
138
|
this.pkg.addMedia(`ppt/media/${name}`, decoded.data);
|
|
@@ -123,6 +147,28 @@ class Emitter {
|
|
|
123
147
|
/** 按层级升序(同级保持原顺序:稳定排序) */
|
|
124
148
|
const objectsByZ = (objects) => [...(objects || [])].filter(Boolean).sort((a, b) => (a.z || 0) - (b.z || 0));
|
|
125
149
|
|
|
150
|
+
/* ---------- 页切换 ---------- */
|
|
151
|
+
|
|
152
|
+
const TRANSITION_DIR = new Set(['l', 'r', 'u', 'd']);
|
|
153
|
+
|
|
154
|
+
function transitionXML(slide) {
|
|
155
|
+
const tr = transitionOf(slide);
|
|
156
|
+
if (!tr || tr.type === 'none') return '';
|
|
157
|
+
const spd = ['slow', 'med', 'fast'].includes(tr.speed) ? tr.speed : 'med';
|
|
158
|
+
const dir = TRANSITION_DIR.has(tr.dir) ? tr.dir : 'l';
|
|
159
|
+
let body = '';
|
|
160
|
+
switch (tr.type) {
|
|
161
|
+
case 'fade': body = '<p:fade/>'; break;
|
|
162
|
+
case 'push': body = `<p:push dir="${dir}"/>`; break;
|
|
163
|
+
case 'wipe': body = `<p:wipe dir="${dir}"/>`; break;
|
|
164
|
+
case 'cover': body = `<p:cover dir="${dir}"/>`; break;
|
|
165
|
+
case 'split': body = '<p:split orient="horz" dir="out"/>'; break;
|
|
166
|
+
case 'zoom': body = '<p:zoom dir="in"/>'; break;
|
|
167
|
+
default: return '';
|
|
168
|
+
}
|
|
169
|
+
return `<p:transition spd="${spd}">${body}</p:transition>`;
|
|
170
|
+
}
|
|
171
|
+
|
|
126
172
|
/* ---------- 页内元素 ---------- */
|
|
127
173
|
|
|
128
174
|
/** 位置与尺寸(旋转以 1/60000 度计) */
|
|
@@ -145,38 +191,72 @@ function algn(align) {
|
|
|
145
191
|
}
|
|
146
192
|
}
|
|
147
193
|
|
|
194
|
+
const anchorAttr = (anchor) => {
|
|
195
|
+
switch (anchor) {
|
|
196
|
+
case 'middle': return 'ctr';
|
|
197
|
+
case 'bottom': return 'b';
|
|
198
|
+
default: return 't';
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/** CSS 字体栈 → OOXML 只认的第一个字族 */
|
|
203
|
+
const fontName = (f) => String(f || '').split(',')[0].trim().replace(/^['"]|['"]$/g, '');
|
|
204
|
+
|
|
148
205
|
/** run 级属性;run 没给的字段回落到对象级基准 */
|
|
149
206
|
function runPr(r, b) {
|
|
150
|
-
const font = r.font || b.font;
|
|
207
|
+
const font = fontName(r.font || b.font);
|
|
151
208
|
const size = r.size > 0 ? r.size : b.size;
|
|
152
209
|
const color = r.color || b.color;
|
|
153
210
|
let sb = `<a:rPr lang="zh-CN" sz="${fontSizeToSz(size)}"`;
|
|
154
211
|
if (b.bold || r.bold) sb += ' b="1"';
|
|
155
212
|
if (b.italic || r.italic) sb += ' i="1"';
|
|
156
213
|
if (b.underline || r.underline) sb += ' u="sng"';
|
|
157
|
-
if (r.strike) sb += ' strike="sngStrike"';
|
|
214
|
+
if (b.strike || r.strike) sb += ' strike="sngStrike"';
|
|
158
215
|
sb += ' dirty="0">';
|
|
216
|
+
// CT_TextCharacterProperties 的子元素顺序:fill 必须在 latin/ea 之前
|
|
217
|
+
sb += `<a:solidFill><a:srgbClr val="${hexColor(color, THEMES_HEX[DEFAULT_THEME].text)}"/></a:solidFill>`;
|
|
159
218
|
if (font) {
|
|
160
219
|
const e = xmlEscape(font);
|
|
161
220
|
sb += `<a:latin typeface="${e}"/><a:ea typeface="${e}"/>`;
|
|
162
221
|
}
|
|
163
|
-
sb +=
|
|
222
|
+
sb += '</a:rPr>';
|
|
164
223
|
return sb;
|
|
165
224
|
}
|
|
166
225
|
|
|
226
|
+
/** 段落属性(对齐 + 行距 + 项目符号/编号) */
|
|
227
|
+
function paragraphPr(p, align, lineSpacing) {
|
|
228
|
+
const a = algn(p.align || align);
|
|
229
|
+
const level = Math.max(0, Math.min(8, Number(p.level) || 0));
|
|
230
|
+
const list = p.list === 'bullet' || p.list === 'number';
|
|
231
|
+
// 左对齐也显式写出:形状文字没有版式兜底,省略 algn 会让「左对齐」在回读时退回形状默认值
|
|
232
|
+
let attrs = ` algn="${a}"`;
|
|
233
|
+
if (list) {
|
|
234
|
+
attrs += ` marL="${pxToEmu(24 * (level + 1))}" indent="${pxToEmu(-24)}"`;
|
|
235
|
+
if (level > 0) attrs += ` lvl="${level}"`;
|
|
236
|
+
}
|
|
237
|
+
let body = '';
|
|
238
|
+
if (lineSpacing > 0 && Math.abs(lineSpacing - 1.0) > 0.001) {
|
|
239
|
+
body += `<a:lnSpc><a:spcPct val="${Math.round(lineSpacing * 100000)}"/></a:lnSpc>`;
|
|
240
|
+
}
|
|
241
|
+
if (p.list === 'bullet') {
|
|
242
|
+
body += '<a:buFont typeface="Arial"/><a:buChar char="•"/>';
|
|
243
|
+
} else if (p.list === 'number') {
|
|
244
|
+
body += '<a:buFont typeface="+mj-lt"/><a:buAutoNum type="arabicPeriod"/>';
|
|
245
|
+
}
|
|
246
|
+
return `<a:pPr${attrs}>${body}</a:pPr>`;
|
|
247
|
+
}
|
|
248
|
+
|
|
167
249
|
/** 段落序列 → <a:p> 串;空段落照出(空 <a:p> 代表一个空行) */
|
|
168
|
-
function parasXML(paras, b, align) {
|
|
169
|
-
const list = paras && paras.length ? paras : [{ align: '', runs: [] }];
|
|
250
|
+
function parasXML(paras, b, align, lineSpacing = 1.0) {
|
|
251
|
+
const list = paras && paras.length ? paras : [{ align: '', list: '', level: 0, runs: [] }];
|
|
170
252
|
let sb = '';
|
|
171
253
|
for (const p of list) {
|
|
172
|
-
|
|
173
|
-
sb += '<a:p>';
|
|
174
|
-
const v = algn(a);
|
|
175
|
-
if (v !== 'l') sb += `<a:pPr algn="${v}"/>`;
|
|
254
|
+
sb += `<a:p>${paragraphPr(p, align, lineSpacing)}`;
|
|
176
255
|
for (const r of p.runs) {
|
|
177
256
|
if (r.text === '') continue;
|
|
178
257
|
sb += `<a:r>${runPr(r, b)}<a:t>${xmlEscape(r.text)}</a:t></a:r>`;
|
|
179
258
|
}
|
|
259
|
+
if (!p.runs.some((r) => r.text !== '')) sb += '<a:endParaRPr lang="zh-CN" dirty="0"/>';
|
|
180
260
|
sb += '</a:p>';
|
|
181
261
|
}
|
|
182
262
|
return sb;
|
|
@@ -186,28 +266,37 @@ function parasXML(paras, b, align) {
|
|
|
186
266
|
function textShapeXML(id, o, t) {
|
|
187
267
|
const p = o.props;
|
|
188
268
|
const color = p.color || `#${t.text}`;
|
|
189
|
-
const base = {
|
|
269
|
+
const base = {
|
|
270
|
+
font: p.font, size: p.fontSize, color, bold: p.bold, italic: p.italic,
|
|
271
|
+
underline: p.underline, strike: p.strike,
|
|
272
|
+
};
|
|
273
|
+
const fill = p.fill ? fillXML(p.fill) : '<a:noFill/>';
|
|
274
|
+
const line = p.strokeW > 0 ? strokeXML(p.stroke, p.strokeW) : '<a:ln><a:noFill/></a:ln>';
|
|
190
275
|
return `<p:sp><p:nvSpPr><p:cNvPr id="${id}" name="TextBox ${id}"/><p:cNvSpPr txBox="1"/><p:nvPr/></p:nvSpPr>` +
|
|
191
|
-
`<p:spPr>${xfrm(o.x, o.y, o.w, o.h, o.rot, false, false)}<a:prstGeom prst="rect"><a:avLst/></a:prstGeom
|
|
192
|
-
`<p:txBody><a:bodyPr wrap="square" lIns="0" tIns="0" rIns="0" bIns="0"
|
|
276
|
+
`<p:spPr>${xfrm(o.x, o.y, o.w, o.h, o.rot, false, false)}<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>${fill}${line}</p:spPr>` +
|
|
277
|
+
`<p:txBody><a:bodyPr wrap="square" lIns="0" tIns="0" rIns="0" bIns="0" anchor="${anchorAttr(p.anchor)}"/><a:lstStyle/>` +
|
|
278
|
+
`${parasXML(htmlToParas(p.html), base, p.align, p.lineSpacing)}</p:txBody></p:sp>`;
|
|
193
279
|
}
|
|
194
280
|
|
|
195
281
|
/** 预设几何图形(含内文字) */
|
|
196
282
|
function shapeXML(id, o) {
|
|
197
283
|
const p = o.props;
|
|
198
|
-
const prst =
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
let text = '<p:txBody><a:bodyPr anchor="ctr" anchorCtr="0"/><a:lstStyle/><a:p><a:endParaRPr lang="zh-CN" dirty="0"/></a:p></p:txBody>';
|
|
284
|
+
const prst = shapePreset(p.kind);
|
|
285
|
+
const fill = fillXML(p.fill);
|
|
286
|
+
const stroke = p.strokeW > 0 ? strokeXML(p.stroke || SHAPE_STROKE, p.strokeW, p.dash) : '<a:ln><a:noFill/></a:ln>';
|
|
287
|
+
let text = `<p:txBody><a:bodyPr anchor="${anchorAttr(p.anchor)}" anchorCtr="0"/><a:lstStyle/><a:p><a:endParaRPr lang="zh-CN" dirty="0"/></a:p></p:txBody>`;
|
|
203
288
|
if (String(p.text || '').trim() !== '') {
|
|
204
289
|
const color = p.textColor || SHAPE_TEXT_COLOR;
|
|
205
|
-
const base = {
|
|
206
|
-
|
|
290
|
+
const base = {
|
|
291
|
+
font: p.font, size: p.fontSize, color, bold: p.bold, italic: p.italic,
|
|
292
|
+
underline: p.underline, strike: p.strike,
|
|
293
|
+
};
|
|
294
|
+
text = `<p:txBody><a:bodyPr anchor="${anchorAttr(p.anchor)}" anchorCtr="0"/><a:lstStyle/>` +
|
|
295
|
+
`${parasXML(parasOfPlain(p.text), base, p.align, p.lineSpacing)}</p:txBody>`;
|
|
207
296
|
}
|
|
208
297
|
return `<p:sp><p:nvSpPr><p:cNvPr id="${id}" name="Shape ${id}"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>` +
|
|
209
298
|
`<p:spPr>${xfrm(o.x, o.y, o.w, o.h, o.rot, false, false)}<a:prstGeom prst="${prst}"><a:avLst/></a:prstGeom>` +
|
|
210
|
-
|
|
299
|
+
`${fill}${stroke}${shadowXML(p.shadow)}</p:spPr>${text}</p:sp>`;
|
|
211
300
|
}
|
|
212
301
|
|
|
213
302
|
/** 直线连接符。编辑器存的是起点 + 向量,负向量靠翻转表达方向 */
|
|
@@ -222,9 +311,11 @@ function lineXML(id, o) {
|
|
|
222
311
|
if (w < 0) { x += w; w = -w; flipH = true; }
|
|
223
312
|
if (h < 0) { y += h; h = -h; flipV = true; }
|
|
224
313
|
const width = p.strokeW > 0 ? p.strokeW : LINE_STROKE_W;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if (p.
|
|
314
|
+
const color = hexColor(p.stroke, THEMES_HEX[DEFAULT_THEME].text);
|
|
315
|
+
let ln = `<a:ln w="${pxToEmu(width)}"><a:solidFill><a:srgbClr val="${color}"/></a:solidFill>`;
|
|
316
|
+
if (p.dash && p.dash !== 'solid' && DASH_STYLES[p.dash]) ln += `<a:prstDash val="${p.dash}"/>`;
|
|
317
|
+
if (p.arrowStart) ln += '<a:headEnd type="arrow" w="med" len="med"/>';
|
|
318
|
+
if (p.arrowEnd) ln += '<a:tailEnd type="arrow" w="med" len="med"/>';
|
|
228
319
|
ln += '</a:ln>';
|
|
229
320
|
return `<p:cxnSp><p:nvCxnSpPr><p:cNvPr id="${id}" name="Line ${id}"/><p:cNvCxnSpPr/><p:nvPr/></p:nvCxnSpPr>` +
|
|
230
321
|
`<p:spPr>${xfrm(x, y, w, h, 0, flipH, flipV)}<a:prstGeom prst="line"><a:avLst/></a:prstGeom>${ln}</p:spPr></p:cxnSp>`;
|
|
@@ -232,18 +323,27 @@ function lineXML(id, o) {
|
|
|
232
323
|
|
|
233
324
|
/** 图片 */
|
|
234
325
|
function pictureXML(id, o, rid) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
326
|
+
const p = o.props;
|
|
327
|
+
const crop = p.crop || {};
|
|
328
|
+
const rect = ['l', 't', 'r', 'b'].map((k) => Math.round(Math.max(0, Math.min(99, Number(crop[k]) || 0)) * 1000));
|
|
329
|
+
const srcRect = rect.some((v) => v > 0)
|
|
330
|
+
? `<a:srcRect l="${rect[0]}" t="${rect[1]}" r="${rect[2]}" b="${rect[3]}"/>`
|
|
331
|
+
: '';
|
|
332
|
+
const descr = p.alt ? ` descr="${xmlEscapeAttr(p.alt)}"` : '';
|
|
333
|
+
return `<p:pic><p:nvPicPr><p:cNvPr id="${id}" name="Picture ${id}"${descr}/><p:cNvPicPr/><p:nvPr/></p:nvPicPr>` +
|
|
334
|
+
`<p:blipFill><a:blip r:embed="${rid}"/>${srcRect}<a:stretch><a:fillRect/></a:stretch></p:blipFill>` +
|
|
335
|
+
`<p:spPr>${xfrm(o.x, o.y, o.w, o.h, o.rot, false, false)}<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>${shadowXML(p.shadow)}</p:spPr></p:pic>`;
|
|
238
336
|
}
|
|
239
337
|
|
|
240
|
-
/**
|
|
241
|
-
function tableFrameXML(id, o) {
|
|
338
|
+
/** 表格(列宽/行高按百分比分,首行加粗,样式落成显式单元格填充/边框) */
|
|
339
|
+
function tableFrameXML(id, o, t) {
|
|
242
340
|
const p = o.props;
|
|
243
|
-
|
|
244
|
-
|
|
341
|
+
const rows = p.rows && p.rows.length ? p.rows : [['']];
|
|
342
|
+
const cols = rows[0].length || 1;
|
|
245
343
|
const size = p.fontSize > 0 ? p.fontSize : TABLE_FONT_SIZE;
|
|
246
|
-
const
|
|
344
|
+
const style = tableStyleColors(p.tableStyle, t.key);
|
|
345
|
+
const bodyColor = p.color || style.bodyText || `#${t.text}`;
|
|
346
|
+
const border = xmlColor(style.border);
|
|
247
347
|
|
|
248
348
|
const totalW = pxToEmu(maxF(1, o.w));
|
|
249
349
|
const totalH = pxToEmu(maxF(1, o.h));
|
|
@@ -251,15 +351,25 @@ function tableFrameXML(id, o) {
|
|
|
251
351
|
'<p:cNvGraphicFramePr/><p:nvPr/></p:nvGraphicFramePr>';
|
|
252
352
|
sb += `<p:xfrm><a:off x="${pxToEmu(o.x)}" y="${pxToEmu(o.y)}"/><a:ext cx="${pxToEmu(maxF(1, o.w))}" cy="${pxToEmu(maxF(1, o.h))}"/></p:xfrm>`;
|
|
253
353
|
sb += `<a:graphic><a:graphicData uri="${NS_DRAWING_M}/table"><a:tbl>` +
|
|
254
|
-
`<a:tblPr firstRow="${boolAttr(p.headerRow)}" bandRow="
|
|
354
|
+
`<a:tblPr firstRow="${boolAttr(p.headerRow)}" bandRow="${boolAttr(p.bandedRows)}"/><a:tblGrid>`;
|
|
255
355
|
for (let c = 0; c < cols; c += 1) sb += `<a:gridCol w="${share(totalW, c, p.colW, cols)}"/>`;
|
|
256
356
|
sb += '</a:tblGrid>';
|
|
257
357
|
rows.forEach((row, ri) => {
|
|
358
|
+
const header = ri === 0 && p.headerRow;
|
|
359
|
+
const band = p.bandedRows && !header && (p.headerRow ? ri % 2 === 1 : ri % 2 === 0);
|
|
360
|
+
const cellFill = header ? style.headerFill : band ? style.bandFill : '';
|
|
361
|
+
const cellColor = header ? (style.headerText || bodyColor) : bodyColor;
|
|
258
362
|
sb += `<a:tr h="${share(totalH, ri, p.rowH, rows.length)}">`;
|
|
259
|
-
const base = { font: p.font, size, color, bold: !!p.headerRow &&
|
|
363
|
+
const base = { font: p.font, size, color: cellColor, bold: !!p.headerRow && header, italic: false, underline: false, strike: false };
|
|
260
364
|
for (let c = 0; c < cols; c += 1) {
|
|
261
365
|
const cell = c < row.length ? row[c] : '';
|
|
262
|
-
|
|
366
|
+
const fill = cellFill ? `<a:solidFill><a:srgbClr val="${xmlColor(cellFill)}"/></a:solidFill>` : '';
|
|
367
|
+
const borderXML = border
|
|
368
|
+
? ['L', 'R', 'T', 'B'].map((side) => `<a:ln${side} w="${pxToEmu(TABLE_BORDER_W)}" cap="flat" cmpd="sng" algn="ctr">` +
|
|
369
|
+
`<a:solidFill><a:srgbClr val="${border}"/></a:solidFill><a:prstDash val="solid"/></a:ln${side}>`).join('')
|
|
370
|
+
: '';
|
|
371
|
+
sb += `<a:tc><a:txBody><a:bodyPr/><a:lstStyle/>${parasXML(parasOfPlain(cell), base, '', 1.2)}</a:txBody>` +
|
|
372
|
+
`<a:tcPr>${borderXML}${fill}</a:tcPr></a:tc>`;
|
|
263
373
|
}
|
|
264
374
|
sb += '</a:tr>';
|
|
265
375
|
});
|
|
@@ -272,3 +382,4 @@ function share(total, i, pcts, count) {
|
|
|
272
382
|
if (Array.isArray(pcts) && i < pcts.length && pcts[i] > 0) return Math.trunc((total * pcts[i]) / 100);
|
|
273
383
|
return Math.trunc(total / count);
|
|
274
384
|
}
|
|
385
|
+
|