pptx-craft 0.1.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/LICENSE +24 -0
- package/README.md +166 -0
- package/README.zh-CN.md +166 -0
- package/dist/index.cjs +3933 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1795 -0
- package/dist/index.d.ts +1795 -0
- package/dist/index.js +3878 -0
- package/dist/index.js.map +1 -0
- package/package.json +70 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3878 @@
|
|
|
1
|
+
// src/core/registry.ts
|
|
2
|
+
var Registry = class {
|
|
3
|
+
serializers = /* @__PURE__ */ new Map();
|
|
4
|
+
registerElement(type, serializer) {
|
|
5
|
+
this.serializers.set(type, serializer);
|
|
6
|
+
}
|
|
7
|
+
getSerializer(type) {
|
|
8
|
+
return this.serializers.get(type);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/core/theme.ts
|
|
13
|
+
var defaultColorScheme = {
|
|
14
|
+
dk1: "000000",
|
|
15
|
+
lt1: "FFFFFF",
|
|
16
|
+
dk2: "44546A",
|
|
17
|
+
lt2: "E7E6E6",
|
|
18
|
+
accent1: "4472C4",
|
|
19
|
+
accent2: "ED7D31",
|
|
20
|
+
accent3: "A5A5A5",
|
|
21
|
+
accent4: "FFC000",
|
|
22
|
+
accent5: "5B9BD5",
|
|
23
|
+
accent6: "70AD47",
|
|
24
|
+
hlink: "0563C1",
|
|
25
|
+
folHlink: "954F72"
|
|
26
|
+
};
|
|
27
|
+
var defaultFontScheme = {
|
|
28
|
+
majorFont: "Calibri Light",
|
|
29
|
+
minorFont: "Calibri"
|
|
30
|
+
};
|
|
31
|
+
var defaultTheme = {
|
|
32
|
+
name: "Office Theme",
|
|
33
|
+
colors: defaultColorScheme,
|
|
34
|
+
fonts: defaultFontScheme
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/core/slide-master.ts
|
|
38
|
+
var SlideMaster = class {
|
|
39
|
+
name;
|
|
40
|
+
background;
|
|
41
|
+
elements;
|
|
42
|
+
constructor(def) {
|
|
43
|
+
this.name = def.name;
|
|
44
|
+
this.background = def.background;
|
|
45
|
+
this.elements = def.elements ?? [];
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/core/slide-layout.ts
|
|
50
|
+
var SlideLayout = class {
|
|
51
|
+
name;
|
|
52
|
+
type;
|
|
53
|
+
placeholders;
|
|
54
|
+
constructor(def) {
|
|
55
|
+
this.name = def.name;
|
|
56
|
+
this.type = def.type ?? "blank";
|
|
57
|
+
this.placeholders = def.placeholders ?? [];
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var builtinLayouts = {
|
|
61
|
+
blank: {
|
|
62
|
+
name: "Blank",
|
|
63
|
+
type: "blank",
|
|
64
|
+
placeholders: []
|
|
65
|
+
},
|
|
66
|
+
title: {
|
|
67
|
+
name: "Title Slide",
|
|
68
|
+
type: "title",
|
|
69
|
+
placeholders: [
|
|
70
|
+
{ type: "ctrTitle", placement: { x: 0.69, y: 1.65, w: 8.63, h: 2.13 }, idx: 0 },
|
|
71
|
+
{ type: "subTitle", placement: { x: 1.36, y: 4.08, w: 7.29, h: 1.68 }, idx: 1 }
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
titleAndContent: {
|
|
75
|
+
name: "Title and Content",
|
|
76
|
+
type: "titleAndContent",
|
|
77
|
+
placeholders: [
|
|
78
|
+
{ type: "title", placement: { x: 0.5, y: 0.28, w: 9, h: 1 }, idx: 0 },
|
|
79
|
+
{ type: "body", placement: { x: 0.5, y: 1.53, w: 9, h: 5.47 }, idx: 1 }
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
sectionHeader: {
|
|
83
|
+
name: "Section Header",
|
|
84
|
+
type: "sectionHeader",
|
|
85
|
+
placeholders: [
|
|
86
|
+
{ type: "title", placement: { x: 0.69, y: 1.65, w: 8.63, h: 2.13 }, idx: 0 },
|
|
87
|
+
{ type: "body", placement: { x: 0.69, y: 4.08, w: 8.63, h: 1.68 }, idx: 1 }
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
twoContent: {
|
|
91
|
+
name: "Two Content",
|
|
92
|
+
type: "twoContent",
|
|
93
|
+
placeholders: [
|
|
94
|
+
{ type: "title", placement: { x: 0.5, y: 0.28, w: 9, h: 1 }, idx: 0 },
|
|
95
|
+
{ type: "body", placement: { x: 0.5, y: 1.53, w: 4.25, h: 5.47 }, idx: 1 },
|
|
96
|
+
{ type: "body", placement: { x: 5.25, y: 1.53, w: 4.25, h: 5.47 }, idx: 2 }
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// src/core/notes-master.ts
|
|
102
|
+
var NotesMaster = class {
|
|
103
|
+
name;
|
|
104
|
+
constructor(def) {
|
|
105
|
+
this.name = def?.name ?? "Default Notes Master";
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/core/handout-master.ts
|
|
110
|
+
var HandoutMaster = class {
|
|
111
|
+
name;
|
|
112
|
+
constructor(def) {
|
|
113
|
+
this.name = def?.name ?? "Default Handout Master";
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// src/ooxml/xml.ts
|
|
118
|
+
var AMP = /&/g;
|
|
119
|
+
var LT = /</g;
|
|
120
|
+
var GT = />/g;
|
|
121
|
+
var QUOT = /"/g;
|
|
122
|
+
var APOS = /'/g;
|
|
123
|
+
function escapeXml(s) {
|
|
124
|
+
return s.replace(AMP, "&").replace(LT, "<").replace(GT, ">").replace(QUOT, """).replace(APOS, "'");
|
|
125
|
+
}
|
|
126
|
+
function tag(name, attrs, children) {
|
|
127
|
+
let s = `<${name}`;
|
|
128
|
+
if (attrs) {
|
|
129
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
130
|
+
if (v !== void 0) {
|
|
131
|
+
s += ` ${k}="${escapeXml(String(v))}"`;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (children !== void 0 && children !== "") {
|
|
136
|
+
s += `>${children}</${name}>`;
|
|
137
|
+
} else {
|
|
138
|
+
s += "/>";
|
|
139
|
+
}
|
|
140
|
+
return s;
|
|
141
|
+
}
|
|
142
|
+
function openTag(name, attrs) {
|
|
143
|
+
let s = `<${name}`;
|
|
144
|
+
if (attrs) {
|
|
145
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
146
|
+
if (v !== void 0) {
|
|
147
|
+
s += ` ${k}="${escapeXml(String(v))}"`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
s += ">";
|
|
152
|
+
return s;
|
|
153
|
+
}
|
|
154
|
+
function closeTag(name) {
|
|
155
|
+
return `</${name}>`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/ooxml/units.ts
|
|
159
|
+
var EMU_PER_INCH = 914400;
|
|
160
|
+
var EMU_PER_PT = 12700;
|
|
161
|
+
function inchesToEmu(inches) {
|
|
162
|
+
return Math.round(inches * EMU_PER_INCH);
|
|
163
|
+
}
|
|
164
|
+
function ptToEmu(pt) {
|
|
165
|
+
return Math.round(pt * EMU_PER_PT);
|
|
166
|
+
}
|
|
167
|
+
function ptToHundredths(pt) {
|
|
168
|
+
return Math.round(pt * 100);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/ooxml/constants.ts
|
|
172
|
+
var NAMESPACE = {
|
|
173
|
+
a: "http://schemas.openxmlformats.org/drawingml/2006/main",
|
|
174
|
+
r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
|
175
|
+
p: "http://schemas.openxmlformats.org/presentationml/2006/main"
|
|
176
|
+
};
|
|
177
|
+
var CONTENT_TYPE = {
|
|
178
|
+
presentation: "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml",
|
|
179
|
+
slide: "application/vnd.openxmlformats-officedocument.presentationml.slide+xml",
|
|
180
|
+
slideLayout: "application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml",
|
|
181
|
+
slideMaster: "application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml",
|
|
182
|
+
theme: "application/vnd.openxmlformats-officedocument.theme+xml",
|
|
183
|
+
rels: "application/vnd.openxmlformats-package.relationships+xml",
|
|
184
|
+
coreProps: "application/vnd.openxmlformats-package.core-properties+xml",
|
|
185
|
+
appProps: "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
|
186
|
+
presProps: "application/vnd.openxmlformats-officedocument.presentationml.presProps+xml",
|
|
187
|
+
viewProps: "application/vnd.openxmlformats-officedocument.presentationml.viewProps+xml",
|
|
188
|
+
notesMaster: "application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml",
|
|
189
|
+
notesSlide: "application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml",
|
|
190
|
+
commentAuthors: "application/vnd.openxmlformats-officedocument.presentationml.commentAuthors+xml",
|
|
191
|
+
comments: "application/vnd.openxmlformats-officedocument.presentationml.comments+xml",
|
|
192
|
+
handoutMaster: "application/vnd.openxmlformats-officedocument.presentationml.handoutMaster+xml",
|
|
193
|
+
tags: "application/vnd.openxmlformats-officedocument.presentationml.tags+xml",
|
|
194
|
+
slideUpdateInfo: "application/vnd.openxmlformats-officedocument.presentationml.slideUpdateInfo+xml",
|
|
195
|
+
png: "image/png",
|
|
196
|
+
jpeg: "image/jpeg",
|
|
197
|
+
gif: "image/gif",
|
|
198
|
+
svg: "image/svg+xml"
|
|
199
|
+
};
|
|
200
|
+
var REL_TYPE = {
|
|
201
|
+
slide: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide",
|
|
202
|
+
slideMaster: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster",
|
|
203
|
+
slideLayout: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout",
|
|
204
|
+
theme: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",
|
|
205
|
+
image: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
|
206
|
+
officeDocument: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
|
|
207
|
+
coreProperties: "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties",
|
|
208
|
+
extendedProperties: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties",
|
|
209
|
+
presProps: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/presProps",
|
|
210
|
+
viewProps: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/viewProps",
|
|
211
|
+
notesMaster: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster",
|
|
212
|
+
notesSlide: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide",
|
|
213
|
+
commentAuthors: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/commentAuthors",
|
|
214
|
+
comments: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
|
|
215
|
+
handoutMaster: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/handoutMaster",
|
|
216
|
+
tags: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/tags",
|
|
217
|
+
slideUpdateInfo: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideUpdateInfo",
|
|
218
|
+
htmlPubSaveAs: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/htmlPubSaveAs",
|
|
219
|
+
slideUpdateUrl: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideUpdateUrl"
|
|
220
|
+
};
|
|
221
|
+
var DEFAULT_SLIDE_WIDTH = 10;
|
|
222
|
+
var DEFAULT_SLIDE_HEIGHT = 7.5;
|
|
223
|
+
|
|
224
|
+
// src/ooxml/serializers/shared.ts
|
|
225
|
+
import { readFileSync } from "fs";
|
|
226
|
+
|
|
227
|
+
// src/ooxml/serializers/color.ts
|
|
228
|
+
function isSchemeColor(c) {
|
|
229
|
+
return typeof c === "object" && "scheme" in c;
|
|
230
|
+
}
|
|
231
|
+
function isSystemColor(c) {
|
|
232
|
+
return typeof c === "object" && "sys" in c;
|
|
233
|
+
}
|
|
234
|
+
function isPresetColor(c) {
|
|
235
|
+
return typeof c === "object" && "preset" in c;
|
|
236
|
+
}
|
|
237
|
+
function isHslColor(c) {
|
|
238
|
+
return typeof c === "object" && "hue" in c && "sat" in c && "lum" in c;
|
|
239
|
+
}
|
|
240
|
+
function isSrgbColor(c) {
|
|
241
|
+
return typeof c === "object" && "hex" in c;
|
|
242
|
+
}
|
|
243
|
+
function serializeTransforms(t) {
|
|
244
|
+
let xml = "";
|
|
245
|
+
if (t.tint !== void 0) xml += tag("a:tint", { val: t.tint });
|
|
246
|
+
if (t.shade !== void 0) xml += tag("a:shade", { val: t.shade });
|
|
247
|
+
if (t.satMod !== void 0) xml += tag("a:satMod", { val: t.satMod });
|
|
248
|
+
if (t.satOff !== void 0) xml += tag("a:satOff", { val: t.satOff });
|
|
249
|
+
if (t.lumMod !== void 0) xml += tag("a:lumMod", { val: t.lumMod });
|
|
250
|
+
if (t.lumOff !== void 0) xml += tag("a:lumOff", { val: t.lumOff });
|
|
251
|
+
if (t.hueMod !== void 0) xml += tag("a:hueMod", { val: t.hueMod });
|
|
252
|
+
if (t.hueOff !== void 0) xml += tag("a:hueOff", { val: t.hueOff });
|
|
253
|
+
if (t.alpha !== void 0) xml += tag("a:alpha", { val: Math.round(t.alpha * 1e3) });
|
|
254
|
+
if (t.alphaOff !== void 0) xml += tag("a:alphaOff", { val: Math.round(t.alphaOff * 1e3) });
|
|
255
|
+
return xml;
|
|
256
|
+
}
|
|
257
|
+
function serializeColor(color) {
|
|
258
|
+
if (typeof color === "string") {
|
|
259
|
+
return tag("a:srgbClr", { val: color });
|
|
260
|
+
}
|
|
261
|
+
if (isSchemeColor(color)) {
|
|
262
|
+
const children = color.transforms ? serializeTransforms(color.transforms) : void 0;
|
|
263
|
+
return tag("a:schemeClr", { val: color.scheme }, children);
|
|
264
|
+
}
|
|
265
|
+
if (isSystemColor(color)) {
|
|
266
|
+
const attrs = { val: color.sys };
|
|
267
|
+
if (color.lastClr) attrs.lastClr = color.lastClr;
|
|
268
|
+
const children = color.transforms ? serializeTransforms(color.transforms) : void 0;
|
|
269
|
+
return tag("a:sysClr", attrs, children);
|
|
270
|
+
}
|
|
271
|
+
if (isPresetColor(color)) {
|
|
272
|
+
const children = color.transforms ? serializeTransforms(color.transforms) : void 0;
|
|
273
|
+
return tag("a:prstClr", { val: color.preset }, children);
|
|
274
|
+
}
|
|
275
|
+
if (isHslColor(color)) {
|
|
276
|
+
const children = color.transforms ? serializeTransforms(color.transforms) : void 0;
|
|
277
|
+
return tag(
|
|
278
|
+
"a:hslClr",
|
|
279
|
+
{
|
|
280
|
+
hue: Math.round(color.hue * 6e4),
|
|
281
|
+
sat: Math.round(color.sat * 1e3),
|
|
282
|
+
lum: Math.round(color.lum * 1e3)
|
|
283
|
+
},
|
|
284
|
+
children
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
if (isSrgbColor(color)) {
|
|
288
|
+
const children = color.transforms ? serializeTransforms(color.transforms) : void 0;
|
|
289
|
+
return tag("a:srgbClr", { val: color.hex }, children);
|
|
290
|
+
}
|
|
291
|
+
return tag("a:srgbClr", { val: "000000" });
|
|
292
|
+
}
|
|
293
|
+
function serializeSolidFill(color) {
|
|
294
|
+
return tag("a:solidFill", void 0, serializeColor(color));
|
|
295
|
+
}
|
|
296
|
+
function serializeColorWithAlpha(color, alpha) {
|
|
297
|
+
if (alpha === void 0 || alpha >= 100) return serializeColor(color);
|
|
298
|
+
const alphaChild = tag("a:alpha", { val: Math.round(alpha * 1e3) });
|
|
299
|
+
if (typeof color === "string") {
|
|
300
|
+
return tag("a:srgbClr", { val: color }, alphaChild);
|
|
301
|
+
}
|
|
302
|
+
if (isSrgbColor(color)) {
|
|
303
|
+
let children = color.transforms ? serializeTransforms(color.transforms) : "";
|
|
304
|
+
children += alphaChild;
|
|
305
|
+
return tag("a:srgbClr", { val: color.hex }, children);
|
|
306
|
+
}
|
|
307
|
+
if (isSchemeColor(color)) {
|
|
308
|
+
let children = color.transforms ? serializeTransforms(color.transforms) : "";
|
|
309
|
+
children += alphaChild;
|
|
310
|
+
return tag("a:schemeClr", { val: color.scheme }, children);
|
|
311
|
+
}
|
|
312
|
+
if (isSystemColor(color)) {
|
|
313
|
+
const attrs = { val: color.sys };
|
|
314
|
+
if (color.lastClr) attrs.lastClr = color.lastClr;
|
|
315
|
+
let children = color.transforms ? serializeTransforms(color.transforms) : "";
|
|
316
|
+
children += alphaChild;
|
|
317
|
+
return tag("a:sysClr", attrs, children);
|
|
318
|
+
}
|
|
319
|
+
if (isPresetColor(color)) {
|
|
320
|
+
let children = color.transforms ? serializeTransforms(color.transforms) : "";
|
|
321
|
+
children += alphaChild;
|
|
322
|
+
return tag("a:prstClr", { val: color.preset }, children);
|
|
323
|
+
}
|
|
324
|
+
if (isHslColor(color)) {
|
|
325
|
+
let children = color.transforms ? serializeTransforms(color.transforms) : "";
|
|
326
|
+
children += alphaChild;
|
|
327
|
+
return tag(
|
|
328
|
+
"a:hslClr",
|
|
329
|
+
{
|
|
330
|
+
hue: Math.round(color.hue * 6e4),
|
|
331
|
+
sat: Math.round(color.sat * 1e3),
|
|
332
|
+
lum: Math.round(color.lum * 1e3)
|
|
333
|
+
},
|
|
334
|
+
children
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
return tag("a:srgbClr", { val: "000000" }, alphaChild);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// src/ooxml/serializers/shared.ts
|
|
341
|
+
function isGradientFill(fill) {
|
|
342
|
+
return typeof fill === "object" && "stops" in fill && "type" in fill;
|
|
343
|
+
}
|
|
344
|
+
function isPatternFill(fill) {
|
|
345
|
+
return typeof fill === "object" && "pattern" in fill;
|
|
346
|
+
}
|
|
347
|
+
function isPictureFill(fill) {
|
|
348
|
+
return typeof fill === "object" && !isGradientFill(fill) && !isPatternFill(fill) && ("path" in fill || "data" in fill);
|
|
349
|
+
}
|
|
350
|
+
function serializeFill(fill, ctx) {
|
|
351
|
+
if (typeof fill === "string" || typeof fill === "object" && ("scheme" in fill || "sys" in fill || "preset" in fill || "hex" in fill || "hue" in fill && "sat" in fill && "lum" in fill)) {
|
|
352
|
+
return serializeSolidFill(fill);
|
|
353
|
+
}
|
|
354
|
+
if (isGradientFill(fill)) {
|
|
355
|
+
let stopsXml = "";
|
|
356
|
+
for (const stop of fill.stops) {
|
|
357
|
+
const pos = Math.round(stop.position * 1e3);
|
|
358
|
+
const clrXml = serializeColorWithAlpha(stop.color, stop.alpha);
|
|
359
|
+
stopsXml += tag("a:gs", { pos }, clrXml);
|
|
360
|
+
}
|
|
361
|
+
let dirChild = "";
|
|
362
|
+
if (fill.type === "linear") {
|
|
363
|
+
dirChild = tag("a:lin", { ang: Math.round((fill.angle ?? 0) * 6e4), scaled: "1" });
|
|
364
|
+
} else if (fill.type === "radial" || fill.type === "path") {
|
|
365
|
+
dirChild = tag(
|
|
366
|
+
"a:path",
|
|
367
|
+
{ path: fill.type === "radial" ? "circle" : "rect" },
|
|
368
|
+
tag("a:fillToRect", { l: "50000", t: "50000", r: "50000", b: "50000" })
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
return tag("a:gradFill", void 0, tag("a:gsLst", void 0, stopsXml) + dirChild);
|
|
372
|
+
}
|
|
373
|
+
if (isPatternFill(fill)) {
|
|
374
|
+
return tag(
|
|
375
|
+
"a:pattFill",
|
|
376
|
+
{ prst: fill.pattern },
|
|
377
|
+
tag("a:fgClr", void 0, serializeColor(fill.foreground)) + tag("a:bgClr", void 0, serializeColor(fill.background))
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
if (isPictureFill(fill) && ctx) {
|
|
381
|
+
let data = fill.data;
|
|
382
|
+
if (!data && fill.path) {
|
|
383
|
+
data = readFileSync(fill.path);
|
|
384
|
+
}
|
|
385
|
+
if (!data) return "";
|
|
386
|
+
const ct = fill.contentType ?? "image/png";
|
|
387
|
+
const ext = ct.split("/")[1] ?? "png";
|
|
388
|
+
const fileName = `fill_${Date.now()}.${ext}`;
|
|
389
|
+
const target = `../media/${fileName}`;
|
|
390
|
+
const rId = ctx.addRelationship(REL_TYPE.image, target, data);
|
|
391
|
+
let content = tag("a:blip", { "r:embed": rId });
|
|
392
|
+
if (fill.tile) {
|
|
393
|
+
content += tag("a:tile", {
|
|
394
|
+
sx: fill.tile.sx,
|
|
395
|
+
sy: fill.tile.sy,
|
|
396
|
+
tx: fill.tile.tx,
|
|
397
|
+
ty: fill.tile.ty
|
|
398
|
+
});
|
|
399
|
+
} else {
|
|
400
|
+
content += tag("a:stretch", void 0, tag("a:fillRect"));
|
|
401
|
+
}
|
|
402
|
+
return tag("a:blipFill", void 0, content);
|
|
403
|
+
}
|
|
404
|
+
return "";
|
|
405
|
+
}
|
|
406
|
+
function serializeLine(line) {
|
|
407
|
+
const attrs = {};
|
|
408
|
+
if (line.width) attrs.w = ptToEmu(line.width);
|
|
409
|
+
if (line.cap) attrs.cap = line.cap === "square" ? "sq" : line.cap;
|
|
410
|
+
if (line.compound) attrs.cmpd = line.compound;
|
|
411
|
+
if (line.alignment) attrs.algn = line.alignment;
|
|
412
|
+
let children = "";
|
|
413
|
+
if (line.fill) {
|
|
414
|
+
children += serializeFill(line.fill);
|
|
415
|
+
} else if (line.color) {
|
|
416
|
+
children += tag("a:solidFill", void 0, serializeColorWithAlpha(line.color, line.opacity));
|
|
417
|
+
}
|
|
418
|
+
if (line.customDash && line.customDash.length > 0) {
|
|
419
|
+
let dashChildren = "";
|
|
420
|
+
for (const seg of line.customDash) {
|
|
421
|
+
dashChildren += tag("a:ds", { d: seg.d, sp: seg.sp });
|
|
422
|
+
}
|
|
423
|
+
children += tag("a:custDash", void 0, dashChildren);
|
|
424
|
+
} else if (line.dash && line.dash !== "solid") {
|
|
425
|
+
children += tag("a:prstDash", { val: line.dash });
|
|
426
|
+
}
|
|
427
|
+
if (line.join) {
|
|
428
|
+
if (line.join === "round") children += tag("a:round");
|
|
429
|
+
else if (line.join === "bevel") children += tag("a:bevel");
|
|
430
|
+
else children += tag("a:miter", { lim: "800000" });
|
|
431
|
+
}
|
|
432
|
+
if (line.headEnd) {
|
|
433
|
+
const hAttrs = {};
|
|
434
|
+
if (line.headEnd.type) hAttrs.type = line.headEnd.type;
|
|
435
|
+
if (line.headEnd.width) hAttrs.w = line.headEnd.width;
|
|
436
|
+
if (line.headEnd.length) hAttrs.len = line.headEnd.length;
|
|
437
|
+
children += tag("a:headEnd", hAttrs);
|
|
438
|
+
}
|
|
439
|
+
if (line.tailEnd) {
|
|
440
|
+
const tAttrs = {};
|
|
441
|
+
if (line.tailEnd.type) tAttrs.type = line.tailEnd.type;
|
|
442
|
+
if (line.tailEnd.width) tAttrs.w = line.tailEnd.width;
|
|
443
|
+
if (line.tailEnd.length) tAttrs.len = line.tailEnd.length;
|
|
444
|
+
children += tag("a:tailEnd", tAttrs);
|
|
445
|
+
}
|
|
446
|
+
return tag("a:ln", attrs, children || void 0);
|
|
447
|
+
}
|
|
448
|
+
function serializeShadow(shadow) {
|
|
449
|
+
const isInner = shadow.type === "inner";
|
|
450
|
+
const elName = isInner ? "a:innerShdw" : "a:outerShdw";
|
|
451
|
+
const attrs = {};
|
|
452
|
+
if (shadow.blur) attrs.blurRad = ptToEmu(shadow.blur);
|
|
453
|
+
if (shadow.offset) attrs.dist = ptToEmu(shadow.offset);
|
|
454
|
+
if (shadow.angle !== void 0) attrs.dir = Math.round(shadow.angle * 6e4);
|
|
455
|
+
const color = shadow.color ?? "000000";
|
|
456
|
+
return tag(elName, attrs, serializeColorWithAlpha(color, shadow.alpha));
|
|
457
|
+
}
|
|
458
|
+
function serializeGlow(glow) {
|
|
459
|
+
const attrs = {};
|
|
460
|
+
if (glow.radius) attrs.rad = ptToEmu(glow.radius);
|
|
461
|
+
const color = glow.color ?? "FFC000";
|
|
462
|
+
return tag("a:glow", attrs, serializeColorWithAlpha(color, glow.alpha));
|
|
463
|
+
}
|
|
464
|
+
function serializeReflection(refl) {
|
|
465
|
+
const attrs = {};
|
|
466
|
+
if (refl.blur) attrs.blurRad = ptToEmu(refl.blur);
|
|
467
|
+
if (refl.startAlpha !== void 0) attrs.stA = Math.round(refl.startAlpha * 1e3);
|
|
468
|
+
if (refl.endAlpha !== void 0) attrs.endA = Math.round(refl.endAlpha * 1e3);
|
|
469
|
+
if (refl.distance) attrs.dist = ptToEmu(refl.distance);
|
|
470
|
+
if (refl.direction !== void 0) attrs.dir = Math.round(refl.direction * 6e4);
|
|
471
|
+
if (refl.fadeDirection !== void 0) attrs.fadeDir = Math.round(refl.fadeDirection * 6e4);
|
|
472
|
+
return tag("a:reflection", attrs);
|
|
473
|
+
}
|
|
474
|
+
function serializeSoftEdge(se) {
|
|
475
|
+
const attrs = {};
|
|
476
|
+
if (se.radius) attrs.rad = ptToEmu(se.radius);
|
|
477
|
+
return tag("a:softEdge", attrs);
|
|
478
|
+
}
|
|
479
|
+
function serializeEffects(effects) {
|
|
480
|
+
let children = "";
|
|
481
|
+
if (effects.glow) children += serializeGlow(effects.glow);
|
|
482
|
+
if (effects.shadow) children += serializeShadow(effects.shadow);
|
|
483
|
+
if (effects.reflection) children += serializeReflection(effects.reflection);
|
|
484
|
+
if (effects.softEdge) children += serializeSoftEdge(effects.softEdge);
|
|
485
|
+
if (!children) return "";
|
|
486
|
+
return tag("a:effectLst", void 0, children);
|
|
487
|
+
}
|
|
488
|
+
function serializeTransform(placement, transform) {
|
|
489
|
+
const xfrmAttrs = {};
|
|
490
|
+
const rot = placement.rotation ?? transform?.rotation;
|
|
491
|
+
if (rot) xfrmAttrs.rot = Math.round(rot * 6e4);
|
|
492
|
+
if (transform?.flipH) xfrmAttrs.flipH = "1";
|
|
493
|
+
if (transform?.flipV) xfrmAttrs.flipV = "1";
|
|
494
|
+
return tag(
|
|
495
|
+
"a:xfrm",
|
|
496
|
+
Object.keys(xfrmAttrs).length > 0 ? xfrmAttrs : void 0,
|
|
497
|
+
tag("a:off", { x: inchesToEmu(placement.x), y: inchesToEmu(placement.y) }) + tag("a:ext", { cx: inchesToEmu(placement.w), cy: inchesToEmu(placement.h) })
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
var HYPERLINK_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
|
|
501
|
+
function serializeHyperlink(link, ctx) {
|
|
502
|
+
if (link.url) {
|
|
503
|
+
const rId = ctx.addRelationship(HYPERLINK_REL_TYPE, link.url);
|
|
504
|
+
const attrs = { "r:id": rId };
|
|
505
|
+
if (link.tooltip) attrs.tooltip = link.tooltip;
|
|
506
|
+
return tag("a:hlinkClick", attrs);
|
|
507
|
+
}
|
|
508
|
+
if (link.email) {
|
|
509
|
+
const rId = ctx.addRelationship(HYPERLINK_REL_TYPE, `mailto:${link.email}`);
|
|
510
|
+
const attrs = { "r:id": rId };
|
|
511
|
+
if (link.tooltip) attrs.tooltip = link.tooltip;
|
|
512
|
+
return tag("a:hlinkClick", attrs);
|
|
513
|
+
}
|
|
514
|
+
if (link.file) {
|
|
515
|
+
const rId = ctx.addRelationship(HYPERLINK_REL_TYPE, link.file);
|
|
516
|
+
const attrs = { "r:id": rId };
|
|
517
|
+
if (link.tooltip) attrs.tooltip = link.tooltip;
|
|
518
|
+
return tag("a:hlinkClick", attrs);
|
|
519
|
+
}
|
|
520
|
+
if (link.action) {
|
|
521
|
+
const attrs = { action: link.action };
|
|
522
|
+
if (link.tooltip) attrs.tooltip = link.tooltip;
|
|
523
|
+
return tag("a:hlinkClick", attrs);
|
|
524
|
+
}
|
|
525
|
+
if (link.slide !== void 0) {
|
|
526
|
+
const attrs = { action: "ppaction://hlinksldjump" };
|
|
527
|
+
if (link.tooltip) attrs.tooltip = link.tooltip;
|
|
528
|
+
return tag("a:hlinkClick", attrs);
|
|
529
|
+
}
|
|
530
|
+
return "";
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// src/ooxml/serializers/scene3d.ts
|
|
534
|
+
function serializeScene3D(scene) {
|
|
535
|
+
let children = "";
|
|
536
|
+
if (scene.camera) {
|
|
537
|
+
const attrs = {
|
|
538
|
+
prst: scene.camera.preset ?? "orthographicFront"
|
|
539
|
+
};
|
|
540
|
+
if (scene.camera.fov !== void 0) attrs.fov = Math.round(scene.camera.fov * 6e4);
|
|
541
|
+
children += tag("a:camera", attrs);
|
|
542
|
+
} else {
|
|
543
|
+
children += tag("a:camera", { prst: "orthographicFront" });
|
|
544
|
+
}
|
|
545
|
+
if (scene.lightRig) {
|
|
546
|
+
const attrs = {
|
|
547
|
+
rig: scene.lightRig.type ?? "threePt",
|
|
548
|
+
dir: scene.lightRig.direction ?? "t"
|
|
549
|
+
};
|
|
550
|
+
children += tag("a:lightRig", attrs);
|
|
551
|
+
} else {
|
|
552
|
+
children += tag("a:lightRig", { rig: "threePt", dir: "t" });
|
|
553
|
+
}
|
|
554
|
+
return tag("a:scene3d", void 0, children);
|
|
555
|
+
}
|
|
556
|
+
function serializeShape3D(sp3d) {
|
|
557
|
+
const attrs = {};
|
|
558
|
+
if (sp3d.extrusionHeight !== void 0)
|
|
559
|
+
attrs.extrusionH = Math.round(sp3d.extrusionHeight * 12700);
|
|
560
|
+
if (sp3d.contourWidth !== void 0) attrs.contourW = Math.round(sp3d.contourWidth * 12700);
|
|
561
|
+
if (sp3d.material) attrs.prstMaterial = sp3d.material;
|
|
562
|
+
let children = "";
|
|
563
|
+
if (sp3d.bevelTop) {
|
|
564
|
+
const bAttrs = {};
|
|
565
|
+
if (sp3d.bevelTop.width !== void 0) bAttrs.w = Math.round(sp3d.bevelTop.width * 12700);
|
|
566
|
+
if (sp3d.bevelTop.height !== void 0) bAttrs.h = Math.round(sp3d.bevelTop.height * 12700);
|
|
567
|
+
if (sp3d.bevelTop.preset) bAttrs.prst = sp3d.bevelTop.preset;
|
|
568
|
+
children += tag("a:bevelT", bAttrs);
|
|
569
|
+
}
|
|
570
|
+
if (sp3d.bevelBottom) {
|
|
571
|
+
const bAttrs = {};
|
|
572
|
+
if (sp3d.bevelBottom.width !== void 0) bAttrs.w = Math.round(sp3d.bevelBottom.width * 12700);
|
|
573
|
+
if (sp3d.bevelBottom.height !== void 0)
|
|
574
|
+
bAttrs.h = Math.round(sp3d.bevelBottom.height * 12700);
|
|
575
|
+
if (sp3d.bevelBottom.preset) bAttrs.prst = sp3d.bevelBottom.preset;
|
|
576
|
+
children += tag("a:bevelB", bAttrs);
|
|
577
|
+
}
|
|
578
|
+
if (sp3d.extrusionColor) {
|
|
579
|
+
children += tag("a:extrusionClr", void 0, serializeColor(sp3d.extrusionColor));
|
|
580
|
+
}
|
|
581
|
+
if (sp3d.contourColor) {
|
|
582
|
+
children += tag("a:contourClr", void 0, serializeColor(sp3d.contourColor));
|
|
583
|
+
}
|
|
584
|
+
return tag("a:sp3d", Object.keys(attrs).length > 0 ? attrs : void 0, children || void 0);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// src/ooxml/serializers/text.ts
|
|
588
|
+
function serializeSpacing(val) {
|
|
589
|
+
if (typeof val === "number") {
|
|
590
|
+
return tag("a:spcPts", { val: ptToHundredths(val) });
|
|
591
|
+
}
|
|
592
|
+
if (val.unit === "pct") {
|
|
593
|
+
return tag("a:spcPct", { val: Math.round(val.value * 1e3) });
|
|
594
|
+
}
|
|
595
|
+
return tag("a:spcPts", { val: ptToHundredths(val.value) });
|
|
596
|
+
}
|
|
597
|
+
function serializeRunProps(run, ctx) {
|
|
598
|
+
const o = run.options;
|
|
599
|
+
if (!o) return "";
|
|
600
|
+
const attrs = {};
|
|
601
|
+
if (o.fontSize) attrs.sz = ptToHundredths(o.fontSize);
|
|
602
|
+
if (o.bold) attrs.b = "1";
|
|
603
|
+
if (o.italic) attrs.i = "1";
|
|
604
|
+
if (o.underline) attrs.u = "sng";
|
|
605
|
+
if (o.strikethrough) {
|
|
606
|
+
attrs.strike = o.strikethrough === "double" ? "dblStrike" : "sngStrike";
|
|
607
|
+
}
|
|
608
|
+
if (o.caps === "small") attrs.cap = "small";
|
|
609
|
+
else if (o.caps === "all") attrs.cap = "all";
|
|
610
|
+
if (o.letterSpacing) attrs.spc = Math.round(o.letterSpacing * 100);
|
|
611
|
+
if (o.lang) attrs.lang = o.lang;
|
|
612
|
+
if (o.altLang) attrs.altLang = o.altLang;
|
|
613
|
+
if (o.subscript) attrs.baseline = "-40000";
|
|
614
|
+
else if (o.superscript) attrs.baseline = "30000";
|
|
615
|
+
else if (o.baseline !== void 0) attrs.baseline = String(Math.round(o.baseline * 1e3));
|
|
616
|
+
let children = "";
|
|
617
|
+
if (o.color) children += serializeSolidFill(o.color);
|
|
618
|
+
if (o.highlight) children += tag("a:highlight", void 0, serializeColor(o.highlight));
|
|
619
|
+
if (o.fontFace) children += tag("a:latin", { typeface: o.fontFace });
|
|
620
|
+
if (o.eastAsianFont) children += tag("a:ea", { typeface: o.eastAsianFont });
|
|
621
|
+
if (o.complexScriptFont) children += tag("a:cs", { typeface: o.complexScriptFont });
|
|
622
|
+
if (o.outline) children += serializeLine(o.outline);
|
|
623
|
+
if (o.shadow) {
|
|
624
|
+
const sAttrs = {};
|
|
625
|
+
if (o.shadow.blur) sAttrs.blurRad = ptToEmu(o.shadow.blur);
|
|
626
|
+
if (o.shadow.offset) sAttrs.dist = ptToEmu(o.shadow.offset);
|
|
627
|
+
if (o.shadow.angle !== void 0) sAttrs.dir = Math.round(o.shadow.angle * 6e4);
|
|
628
|
+
const sc = o.shadow.color ?? "000000";
|
|
629
|
+
children += tag(
|
|
630
|
+
"a:effectLst",
|
|
631
|
+
void 0,
|
|
632
|
+
tag("a:outerShdw", sAttrs, serializeColorWithAlpha(sc, o.shadow.alpha))
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
if (o.hyperlink) children += serializeHyperlink(o.hyperlink, ctx);
|
|
636
|
+
if (children) return tag("a:rPr", attrs, children);
|
|
637
|
+
if (Object.keys(attrs).length > 0) return tag("a:rPr", attrs);
|
|
638
|
+
return "";
|
|
639
|
+
}
|
|
640
|
+
function serializeDefRunProps(o) {
|
|
641
|
+
const attrs = {};
|
|
642
|
+
if (o.fontSize) attrs.sz = ptToHundredths(o.fontSize);
|
|
643
|
+
if (o.bold) attrs.b = "1";
|
|
644
|
+
if (o.italic) attrs.i = "1";
|
|
645
|
+
let children = "";
|
|
646
|
+
if (o.color) children += serializeSolidFill(o.color);
|
|
647
|
+
if (o.fontFace) children += tag("a:latin", { typeface: o.fontFace });
|
|
648
|
+
return tag("a:defRPr", attrs, children || void 0);
|
|
649
|
+
}
|
|
650
|
+
function serializeParagraph(para, ctx) {
|
|
651
|
+
let xml = openTag("a:p");
|
|
652
|
+
const pOpts = para.options;
|
|
653
|
+
if (pOpts) {
|
|
654
|
+
const attrs = {};
|
|
655
|
+
if (pOpts.align) {
|
|
656
|
+
const map = { left: "l", center: "ctr", right: "r", justify: "just" };
|
|
657
|
+
attrs.algn = map[pOpts.align] ?? "l";
|
|
658
|
+
}
|
|
659
|
+
if (pOpts.level !== void 0) attrs.lvl = pOpts.level;
|
|
660
|
+
if (pOpts.indent) attrs.indent = ptToEmu(pOpts.indent);
|
|
661
|
+
if (pOpts.marginLeft) attrs.marL = ptToEmu(pOpts.marginLeft);
|
|
662
|
+
if (pOpts.rtl) attrs.rtl = "1";
|
|
663
|
+
let pPrChildren = "";
|
|
664
|
+
if (pOpts.lineSpacing) {
|
|
665
|
+
pPrChildren += tag("a:lnSpc", void 0, serializeSpacing(pOpts.lineSpacing));
|
|
666
|
+
}
|
|
667
|
+
if (pOpts.spaceBefore) {
|
|
668
|
+
pPrChildren += tag("a:spcBef", void 0, serializeSpacing(pOpts.spaceBefore));
|
|
669
|
+
}
|
|
670
|
+
if (pOpts.spaceAfter) {
|
|
671
|
+
pPrChildren += tag("a:spcAft", void 0, serializeSpacing(pOpts.spaceAfter));
|
|
672
|
+
}
|
|
673
|
+
if (pOpts.bullet) {
|
|
674
|
+
if (pOpts.bullet === true) {
|
|
675
|
+
pPrChildren += tag("a:buChar", { char: "\u2022" });
|
|
676
|
+
} else {
|
|
677
|
+
if (pOpts.bullet.color) {
|
|
678
|
+
pPrChildren += tag("a:buClr", void 0, serializeColor(pOpts.bullet.color));
|
|
679
|
+
}
|
|
680
|
+
if (pOpts.bullet.size) {
|
|
681
|
+
pPrChildren += tag("a:buSzPct", { val: Math.round(pOpts.bullet.size * 1e3) });
|
|
682
|
+
}
|
|
683
|
+
if (pOpts.bullet.font) {
|
|
684
|
+
pPrChildren += tag("a:buFont", { typeface: pOpts.bullet.font });
|
|
685
|
+
}
|
|
686
|
+
if (pOpts.bullet.type === "auto") {
|
|
687
|
+
pPrChildren += tag("a:buAutoNum", { type: "arabicPeriod" });
|
|
688
|
+
} else {
|
|
689
|
+
pPrChildren += tag("a:buChar", { char: pOpts.bullet.char ?? "\u2022" });
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
} else if (pOpts.numbering) {
|
|
693
|
+
if (pOpts.numbering.color) {
|
|
694
|
+
pPrChildren += tag("a:buClr", void 0, serializeColor(pOpts.numbering.color));
|
|
695
|
+
}
|
|
696
|
+
if (pOpts.numbering.size) {
|
|
697
|
+
pPrChildren += tag("a:buSzPct", { val: Math.round(pOpts.numbering.size * 1e3) });
|
|
698
|
+
}
|
|
699
|
+
if (pOpts.numbering.font) {
|
|
700
|
+
pPrChildren += tag("a:buFont", { typeface: pOpts.numbering.font });
|
|
701
|
+
}
|
|
702
|
+
const numAttrs = {
|
|
703
|
+
type: pOpts.numbering.type ?? "arabicPeriod"
|
|
704
|
+
};
|
|
705
|
+
if (pOpts.numbering.startAt) numAttrs.startAt = pOpts.numbering.startAt;
|
|
706
|
+
pPrChildren += tag("a:buAutoNum", numAttrs);
|
|
707
|
+
}
|
|
708
|
+
if (pOpts.tabStops) {
|
|
709
|
+
let tabsXml = "";
|
|
710
|
+
for (const ts of pOpts.tabStops) {
|
|
711
|
+
const tsAttrs = { pos: ptToEmu(ts.position) };
|
|
712
|
+
if (ts.alignment) tsAttrs.algn = ts.alignment;
|
|
713
|
+
tabsXml += tag("a:tab", tsAttrs);
|
|
714
|
+
}
|
|
715
|
+
pPrChildren += tag("a:tabLst", void 0, tabsXml);
|
|
716
|
+
}
|
|
717
|
+
if (pOpts.defaultRunOptions) {
|
|
718
|
+
pPrChildren += serializeDefRunProps(pOpts.defaultRunOptions);
|
|
719
|
+
}
|
|
720
|
+
xml += tag("a:pPr", attrs, pPrChildren || void 0);
|
|
721
|
+
}
|
|
722
|
+
for (const run of para.runs) {
|
|
723
|
+
xml += openTag("a:r");
|
|
724
|
+
xml += serializeRunProps(run, ctx);
|
|
725
|
+
xml += tag("a:t", void 0, run.text);
|
|
726
|
+
xml += closeTag("a:r");
|
|
727
|
+
}
|
|
728
|
+
xml += closeTag("a:p");
|
|
729
|
+
return xml;
|
|
730
|
+
}
|
|
731
|
+
function serializeBodyPr(bodyOpts) {
|
|
732
|
+
const attrs = { wrap: "square", rtlCol: "0" };
|
|
733
|
+
if (bodyOpts) {
|
|
734
|
+
if (bodyOpts.verticalAlign) {
|
|
735
|
+
const map = { top: "t", middle: "ctr", bottom: "b" };
|
|
736
|
+
attrs.anchor = map[bodyOpts.verticalAlign] ?? "t";
|
|
737
|
+
}
|
|
738
|
+
if (bodyOpts.textDirection) {
|
|
739
|
+
const map = {
|
|
740
|
+
horz: "horz",
|
|
741
|
+
vert: "vert",
|
|
742
|
+
vert270: "vert270",
|
|
743
|
+
wordArtVert: "wordArtVert"
|
|
744
|
+
};
|
|
745
|
+
if (map[bodyOpts.textDirection]) attrs.vert = map[bodyOpts.textDirection];
|
|
746
|
+
}
|
|
747
|
+
if (bodyOpts.wordWrap === false) attrs.wrap = "none";
|
|
748
|
+
if (bodyOpts.columns && bodyOpts.columns > 1) attrs.numCol = bodyOpts.columns;
|
|
749
|
+
if (bodyOpts.columnSpacing) attrs.spcCol = ptToEmu(bodyOpts.columnSpacing);
|
|
750
|
+
if (bodyOpts.margin) {
|
|
751
|
+
if (bodyOpts.margin.top !== void 0) attrs.tIns = ptToEmu(bodyOpts.margin.top);
|
|
752
|
+
if (bodyOpts.margin.bottom !== void 0) attrs.bIns = ptToEmu(bodyOpts.margin.bottom);
|
|
753
|
+
if (bodyOpts.margin.left !== void 0) attrs.lIns = ptToEmu(bodyOpts.margin.left);
|
|
754
|
+
if (bodyOpts.margin.right !== void 0) attrs.rIns = ptToEmu(bodyOpts.margin.right);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
let children = "";
|
|
758
|
+
if (bodyOpts?.autoFit === true || bodyOpts?.autoFit === "shrink") {
|
|
759
|
+
children += tag("a:normAutofit");
|
|
760
|
+
} else if (bodyOpts?.autoFit === "none") {
|
|
761
|
+
children += tag("a:noAutofit");
|
|
762
|
+
}
|
|
763
|
+
if (bodyOpts?.textPath) {
|
|
764
|
+
children += tag("a:prstTxWarp", { prst: bodyOpts.textPath.preset }, tag("a:avLst"));
|
|
765
|
+
}
|
|
766
|
+
return tag("a:bodyPr", attrs, children || void 0);
|
|
767
|
+
}
|
|
768
|
+
var textSerializer = {
|
|
769
|
+
type: "text",
|
|
770
|
+
serialize(element, ctx) {
|
|
771
|
+
const p = element.placement;
|
|
772
|
+
let xml = openTag("p:sp");
|
|
773
|
+
xml += tag(
|
|
774
|
+
"p:nvSpPr",
|
|
775
|
+
void 0,
|
|
776
|
+
tag("p:cNvPr", { id: "0", name: element.name ?? "" }) + tag("p:cNvSpPr", { txBox: "1" }) + tag("p:nvPr")
|
|
777
|
+
);
|
|
778
|
+
xml += openTag("p:spPr");
|
|
779
|
+
xml += serializeTransform(p, element.transform);
|
|
780
|
+
xml += tag("a:prstGeom", { prst: "rect" }, tag("a:avLst"));
|
|
781
|
+
if (element.fill) xml += serializeFill(element.fill, ctx);
|
|
782
|
+
if (element.line) xml += serializeLine(element.line);
|
|
783
|
+
if (element.effects) xml += serializeEffects(element.effects);
|
|
784
|
+
if (element.scene3d) xml += serializeScene3D(element.scene3d);
|
|
785
|
+
if (element.shape3d) xml += serializeShape3D(element.shape3d);
|
|
786
|
+
xml += closeTag("p:spPr");
|
|
787
|
+
xml += openTag("p:txBody");
|
|
788
|
+
xml += serializeBodyPr(element.bodyOptions);
|
|
789
|
+
xml += tag("a:lstStyle");
|
|
790
|
+
for (const para of element.paragraphs) {
|
|
791
|
+
xml += serializeParagraph(para, ctx);
|
|
792
|
+
}
|
|
793
|
+
xml += closeTag("p:txBody");
|
|
794
|
+
xml += closeTag("p:sp");
|
|
795
|
+
return xml;
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
// src/ooxml/serializers/image.ts
|
|
800
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
801
|
+
var imageCounter = 0;
|
|
802
|
+
var imageSerializer = {
|
|
803
|
+
type: "image",
|
|
804
|
+
serialize(element, ctx) {
|
|
805
|
+
imageCounter++;
|
|
806
|
+
const ext = element.contentType.split("/")[1] ?? "png";
|
|
807
|
+
const fileName = `image${imageCounter}.${ext}`;
|
|
808
|
+
const target = `../media/${fileName}`;
|
|
809
|
+
let data = element.data;
|
|
810
|
+
if (!data && element.path) {
|
|
811
|
+
data = readFileSync2(element.path);
|
|
812
|
+
}
|
|
813
|
+
if (!data) throw new Error("Image element must have data or path");
|
|
814
|
+
const rId = ctx.addRelationship(REL_TYPE.image, target, data);
|
|
815
|
+
const p = element.placement;
|
|
816
|
+
let xml = openTag("p:pic");
|
|
817
|
+
let cNvPrChildren = "";
|
|
818
|
+
if (element.hyperlink) {
|
|
819
|
+
cNvPrChildren = serializeHyperlink(element.hyperlink, ctx);
|
|
820
|
+
}
|
|
821
|
+
const lockAspect = element.lockAspectRatio !== false;
|
|
822
|
+
xml += tag(
|
|
823
|
+
"p:nvPicPr",
|
|
824
|
+
void 0,
|
|
825
|
+
tag("p:cNvPr", { id: "0", name: element.name ?? fileName }, cNvPrChildren || void 0) + tag(
|
|
826
|
+
"p:cNvPicPr",
|
|
827
|
+
void 0,
|
|
828
|
+
tag("a:picLocks", { noChangeAspect: lockAspect ? "1" : "0" })
|
|
829
|
+
) + tag("p:nvPr")
|
|
830
|
+
);
|
|
831
|
+
let blipChildren = "";
|
|
832
|
+
if (element.opacity !== void 0 && element.opacity < 100) {
|
|
833
|
+
blipChildren += tag("a:alphaModFix", { amt: Math.round(element.opacity * 1e3) });
|
|
834
|
+
}
|
|
835
|
+
if (element.brightness !== void 0 || element.contrast !== void 0) {
|
|
836
|
+
const lumAttrs = {};
|
|
837
|
+
if (element.brightness !== void 0) lumAttrs.bright = element.brightness * 1e3;
|
|
838
|
+
if (element.contrast !== void 0) lumAttrs.contrast = element.contrast * 1e3;
|
|
839
|
+
blipChildren += tag("a:lum", lumAttrs);
|
|
840
|
+
}
|
|
841
|
+
if (element.saturation !== void 0) {
|
|
842
|
+
blipChildren += tag("a:saturation", { sat: Math.round(element.saturation * 1e3) });
|
|
843
|
+
}
|
|
844
|
+
if (element.duotone) {
|
|
845
|
+
blipChildren += tag(
|
|
846
|
+
"a:duotone",
|
|
847
|
+
void 0,
|
|
848
|
+
serializeColor(element.duotone.color1) + serializeColor(element.duotone.color2)
|
|
849
|
+
);
|
|
850
|
+
}
|
|
851
|
+
let fillContent = tag("a:blip", { "r:embed": rId }, blipChildren || void 0);
|
|
852
|
+
if (element.crop) {
|
|
853
|
+
const cropAttrs = {};
|
|
854
|
+
if (element.crop.top) cropAttrs.t = Math.round(element.crop.top * 1e3);
|
|
855
|
+
if (element.crop.bottom) cropAttrs.b = Math.round(element.crop.bottom * 1e3);
|
|
856
|
+
if (element.crop.left) cropAttrs.l = Math.round(element.crop.left * 1e3);
|
|
857
|
+
if (element.crop.right) cropAttrs.r = Math.round(element.crop.right * 1e3);
|
|
858
|
+
fillContent += tag("a:srcRect", cropAttrs);
|
|
859
|
+
}
|
|
860
|
+
fillContent += tag("a:stretch", void 0, tag("a:fillRect"));
|
|
861
|
+
xml += tag("p:blipFill", void 0, fillContent);
|
|
862
|
+
xml += openTag("p:spPr");
|
|
863
|
+
xml += serializeTransform(p, element.transform);
|
|
864
|
+
xml += tag("a:prstGeom", { prst: element.cropShape ?? "rect" }, tag("a:avLst"));
|
|
865
|
+
if (element.border) xml += serializeLine(element.border);
|
|
866
|
+
if (element.effects) xml += serializeEffects(element.effects);
|
|
867
|
+
if (element.scene3d) xml += serializeScene3D(element.scene3d);
|
|
868
|
+
if (element.shape3d) xml += serializeShape3D(element.shape3d);
|
|
869
|
+
xml += closeTag("p:spPr");
|
|
870
|
+
xml += closeTag("p:pic");
|
|
871
|
+
return xml;
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
|
|
875
|
+
// src/ooxml/serializers/shape.ts
|
|
876
|
+
var GEOMETRY_MAP = {
|
|
877
|
+
rect: "rect",
|
|
878
|
+
roundRect: "roundRect",
|
|
879
|
+
ellipse: "ellipse",
|
|
880
|
+
triangle: "triangle",
|
|
881
|
+
diamond: "diamond",
|
|
882
|
+
line: "line",
|
|
883
|
+
arrow: "rightArrow",
|
|
884
|
+
star5: "star5",
|
|
885
|
+
heart: "heart"
|
|
886
|
+
};
|
|
887
|
+
function serializeCustomGeometry(geom) {
|
|
888
|
+
let pathLst = "";
|
|
889
|
+
for (const path of geom.paths) {
|
|
890
|
+
const pathAttrs = {};
|
|
891
|
+
if (path.w !== void 0) pathAttrs.w = path.w;
|
|
892
|
+
if (path.h !== void 0) pathAttrs.h = path.h;
|
|
893
|
+
let cmds = "";
|
|
894
|
+
for (const cmd of path.commands) {
|
|
895
|
+
switch (cmd.type) {
|
|
896
|
+
case "moveTo":
|
|
897
|
+
cmds += tag("a:moveTo", void 0, tag("a:pt", { x: cmd.x, y: cmd.y }));
|
|
898
|
+
break;
|
|
899
|
+
case "lineTo":
|
|
900
|
+
cmds += tag("a:lnTo", void 0, tag("a:pt", { x: cmd.x, y: cmd.y }));
|
|
901
|
+
break;
|
|
902
|
+
case "arcTo":
|
|
903
|
+
cmds += tag("a:arcTo", { wR: cmd.wR, hR: cmd.hR, stAng: cmd.stAng, swAng: cmd.swAng });
|
|
904
|
+
break;
|
|
905
|
+
case "cubicBezTo":
|
|
906
|
+
cmds += tag(
|
|
907
|
+
"a:cubicBezTo",
|
|
908
|
+
void 0,
|
|
909
|
+
tag("a:pt", { x: cmd.x1, y: cmd.y1 }) + tag("a:pt", { x: cmd.x2, y: cmd.y2 }) + tag("a:pt", { x: cmd.x, y: cmd.y })
|
|
910
|
+
);
|
|
911
|
+
break;
|
|
912
|
+
case "close":
|
|
913
|
+
cmds += tag("a:close");
|
|
914
|
+
break;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
pathLst += tag("a:path", Object.keys(pathAttrs).length > 0 ? pathAttrs : void 0, cmds);
|
|
918
|
+
}
|
|
919
|
+
return tag("a:custGeom", void 0, tag("a:avLst") + tag("a:pathLst", void 0, pathLst));
|
|
920
|
+
}
|
|
921
|
+
function serializeShapeLocks(locks) {
|
|
922
|
+
const attrs = {};
|
|
923
|
+
if (locks.noGroup) attrs.noGrp = "1";
|
|
924
|
+
if (locks.noRotation) attrs.noRot = "1";
|
|
925
|
+
if (locks.noMove) attrs.noMove = "1";
|
|
926
|
+
if (locks.noResize) attrs.noResize = "1";
|
|
927
|
+
if (locks.noSelect) attrs.noSelect = "1";
|
|
928
|
+
if (locks.noTextEdit) attrs.noTextEdit = "1";
|
|
929
|
+
return tag("a:spLocks", attrs);
|
|
930
|
+
}
|
|
931
|
+
var shapeSerializer = {
|
|
932
|
+
type: "shape",
|
|
933
|
+
serialize(element, ctx) {
|
|
934
|
+
const p = element.placement;
|
|
935
|
+
const prst = GEOMETRY_MAP[element.geometry] ?? element.geometry;
|
|
936
|
+
let xml = openTag("p:sp");
|
|
937
|
+
let cNvPrChildren = "";
|
|
938
|
+
if (element.hyperlink) {
|
|
939
|
+
cNvPrChildren = serializeHyperlink(element.hyperlink, ctx);
|
|
940
|
+
}
|
|
941
|
+
let cNvSpPrChildren = "";
|
|
942
|
+
if (element.locks) {
|
|
943
|
+
cNvSpPrChildren = serializeShapeLocks(element.locks);
|
|
944
|
+
}
|
|
945
|
+
xml += tag(
|
|
946
|
+
"p:nvSpPr",
|
|
947
|
+
void 0,
|
|
948
|
+
tag("p:cNvPr", { id: "0", name: element.name ?? "" }, cNvPrChildren || void 0) + tag("p:cNvSpPr", void 0, cNvSpPrChildren || void 0) + tag("p:nvPr")
|
|
949
|
+
);
|
|
950
|
+
xml += openTag("p:spPr");
|
|
951
|
+
xml += serializeTransform(p, element.transform);
|
|
952
|
+
if (element.customGeometry) {
|
|
953
|
+
xml += serializeCustomGeometry(element.customGeometry);
|
|
954
|
+
} else {
|
|
955
|
+
let avLstXml = "";
|
|
956
|
+
if (element.adjustValues) {
|
|
957
|
+
for (const [name, val] of Object.entries(element.adjustValues)) {
|
|
958
|
+
avLstXml += tag("a:gd", { name, fmla: `val ${val}` });
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
xml += tag(
|
|
962
|
+
"a:prstGeom",
|
|
963
|
+
{ prst },
|
|
964
|
+
avLstXml ? tag("a:avLst", void 0, avLstXml) : tag("a:avLst")
|
|
965
|
+
);
|
|
966
|
+
}
|
|
967
|
+
if (element.fill) {
|
|
968
|
+
xml += serializeFill(element.fill, ctx);
|
|
969
|
+
}
|
|
970
|
+
if (element.line) {
|
|
971
|
+
xml += serializeLine(element.line);
|
|
972
|
+
}
|
|
973
|
+
if (element.effects) {
|
|
974
|
+
xml += serializeEffects(element.effects);
|
|
975
|
+
}
|
|
976
|
+
if (element.scene3d) {
|
|
977
|
+
xml += serializeScene3D(element.scene3d);
|
|
978
|
+
}
|
|
979
|
+
if (element.shape3d) {
|
|
980
|
+
xml += serializeShape3D(element.shape3d);
|
|
981
|
+
}
|
|
982
|
+
xml += closeTag("p:spPr");
|
|
983
|
+
if (element.text) {
|
|
984
|
+
xml += openTag("p:txBody");
|
|
985
|
+
const bodyAttrs = { wrap: "square", rtlCol: "0" };
|
|
986
|
+
if (element.textOptions) {
|
|
987
|
+
if (element.textOptions.verticalAlign) {
|
|
988
|
+
const map = { top: "t", middle: "ctr", bottom: "b" };
|
|
989
|
+
bodyAttrs.anchor = map[element.textOptions.verticalAlign] ?? "t";
|
|
990
|
+
}
|
|
991
|
+
if (element.textOptions.wordWrap === false) bodyAttrs.wrap = "none";
|
|
992
|
+
if (element.textOptions.margin) {
|
|
993
|
+
if (element.textOptions.margin.top !== void 0)
|
|
994
|
+
bodyAttrs.tIns = ptToEmu(element.textOptions.margin.top);
|
|
995
|
+
if (element.textOptions.margin.bottom !== void 0)
|
|
996
|
+
bodyAttrs.bIns = ptToEmu(element.textOptions.margin.bottom);
|
|
997
|
+
if (element.textOptions.margin.left !== void 0)
|
|
998
|
+
bodyAttrs.lIns = ptToEmu(element.textOptions.margin.left);
|
|
999
|
+
if (element.textOptions.margin.right !== void 0)
|
|
1000
|
+
bodyAttrs.rIns = ptToEmu(element.textOptions.margin.right);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
let bodyChildren = "";
|
|
1004
|
+
if (element.textOptions?.autoFit === true || element.textOptions?.autoFit === "shrink") {
|
|
1005
|
+
bodyChildren = tag("a:normAutofit");
|
|
1006
|
+
} else if (element.textOptions?.autoFit === "none") {
|
|
1007
|
+
bodyChildren = tag("a:noAutofit");
|
|
1008
|
+
}
|
|
1009
|
+
xml += tag("a:bodyPr", bodyAttrs, bodyChildren || void 0);
|
|
1010
|
+
xml += tag("a:lstStyle");
|
|
1011
|
+
const lines = element.text.split("\n");
|
|
1012
|
+
for (const line of lines) {
|
|
1013
|
+
xml += serializeParagraph(
|
|
1014
|
+
{
|
|
1015
|
+
runs: [{ text: line, options: element.textRunOptions }],
|
|
1016
|
+
options: element.textParagraphOptions
|
|
1017
|
+
},
|
|
1018
|
+
ctx
|
|
1019
|
+
);
|
|
1020
|
+
}
|
|
1021
|
+
xml += closeTag("p:txBody");
|
|
1022
|
+
}
|
|
1023
|
+
xml += closeTag("p:sp");
|
|
1024
|
+
return xml;
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
|
|
1028
|
+
// src/ooxml/serializers/table.ts
|
|
1029
|
+
function serializeBorderLine(b, defaultWidth) {
|
|
1030
|
+
const bw = b.width ? ptToEmu(b.width) : defaultWidth ?? 12700;
|
|
1031
|
+
const bc = b.color ?? "000000";
|
|
1032
|
+
return tag("a:ln", { w: bw }, serializeSolidFill(bc));
|
|
1033
|
+
}
|
|
1034
|
+
function serializeCellBorders(cell, _tableBorder) {
|
|
1035
|
+
const o = cell.options;
|
|
1036
|
+
let xml = "";
|
|
1037
|
+
const sides = [
|
|
1038
|
+
{ cellKey: "borderLeft", tblKey: "left", elName: "a:lnL" },
|
|
1039
|
+
{ cellKey: "borderRight", tblKey: "right", elName: "a:lnR" },
|
|
1040
|
+
{ cellKey: "borderTop", tblKey: "top", elName: "a:lnT" },
|
|
1041
|
+
{ cellKey: "borderBottom", tblKey: "bottom", elName: "a:lnB" }
|
|
1042
|
+
];
|
|
1043
|
+
for (const side of sides) {
|
|
1044
|
+
const cellBorder = o?.[side.cellKey];
|
|
1045
|
+
if (cellBorder) {
|
|
1046
|
+
xml += tag(side.elName, void 0, serializeBorderLine(cellBorder));
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
return xml;
|
|
1050
|
+
}
|
|
1051
|
+
function serializeCell(cell, tableBorder, ctx) {
|
|
1052
|
+
const o = cell.options;
|
|
1053
|
+
const tcAttrs = {};
|
|
1054
|
+
if (o?.colSpan && o.colSpan > 1) tcAttrs.gridSpan = o.colSpan;
|
|
1055
|
+
if (o?.rowSpan && o.rowSpan > 1) tcAttrs.rowSpan = o.rowSpan;
|
|
1056
|
+
let xml = openTag("a:tc", Object.keys(tcAttrs).length > 0 ? tcAttrs : void 0);
|
|
1057
|
+
xml += openTag("a:txBody");
|
|
1058
|
+
{
|
|
1059
|
+
const bodyAttrs = {};
|
|
1060
|
+
if (o?.textBody) {
|
|
1061
|
+
if (o.textBody.verticalAlign) {
|
|
1062
|
+
const m = { top: "t", middle: "ctr", bottom: "b" };
|
|
1063
|
+
bodyAttrs.anchor = m[o.textBody.verticalAlign] ?? "t";
|
|
1064
|
+
}
|
|
1065
|
+
if (o.textBody.wordWrap === false) bodyAttrs.wrap = "none";
|
|
1066
|
+
if (o.textBody.margin) {
|
|
1067
|
+
if (o.textBody.margin.top !== void 0) bodyAttrs.tIns = ptToEmu(o.textBody.margin.top);
|
|
1068
|
+
if (o.textBody.margin.bottom !== void 0)
|
|
1069
|
+
bodyAttrs.bIns = ptToEmu(o.textBody.margin.bottom);
|
|
1070
|
+
if (o.textBody.margin.left !== void 0) bodyAttrs.lIns = ptToEmu(o.textBody.margin.left);
|
|
1071
|
+
if (o.textBody.margin.right !== void 0)
|
|
1072
|
+
bodyAttrs.rIns = ptToEmu(o.textBody.margin.right);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
xml += tag("a:bodyPr", Object.keys(bodyAttrs).length > 0 ? bodyAttrs : void 0);
|
|
1076
|
+
}
|
|
1077
|
+
xml += tag("a:lstStyle");
|
|
1078
|
+
xml += openTag("a:p");
|
|
1079
|
+
if (o?.align) {
|
|
1080
|
+
const map = { left: "l", center: "ctr", right: "r", justify: "just" };
|
|
1081
|
+
xml += tag("a:pPr", { algn: map[o.align] ?? "l" });
|
|
1082
|
+
}
|
|
1083
|
+
xml += openTag("a:r");
|
|
1084
|
+
const rAttrs = {};
|
|
1085
|
+
if (o?.fontSize) rAttrs.sz = ptToHundredths(o.fontSize);
|
|
1086
|
+
if (o?.bold) rAttrs.b = "1";
|
|
1087
|
+
if (o?.italic) rAttrs.i = "1";
|
|
1088
|
+
if (o?.underline) rAttrs.u = "sng";
|
|
1089
|
+
if (o?.strikethrough) {
|
|
1090
|
+
rAttrs.strike = o.strikethrough === "double" ? "dblStrike" : "sngStrike";
|
|
1091
|
+
}
|
|
1092
|
+
let rPrChildren = "";
|
|
1093
|
+
if (o?.color) rPrChildren += serializeSolidFill(o.color);
|
|
1094
|
+
if (o?.fontFace) rPrChildren += tag("a:latin", { typeface: o.fontFace });
|
|
1095
|
+
xml += tag("a:rPr", { lang: "en-US", ...rAttrs }, rPrChildren || void 0);
|
|
1096
|
+
xml += tag("a:t", void 0, cell.text);
|
|
1097
|
+
xml += closeTag("a:r");
|
|
1098
|
+
xml += closeTag("a:p");
|
|
1099
|
+
xml += closeTag("a:txBody");
|
|
1100
|
+
let tcPr = "";
|
|
1101
|
+
const tcPrAttrs = {};
|
|
1102
|
+
if (o?.verticalAlign) {
|
|
1103
|
+
const map = {
|
|
1104
|
+
top: "t",
|
|
1105
|
+
middle: "ctr",
|
|
1106
|
+
bottom: "b",
|
|
1107
|
+
distributed: "dist"
|
|
1108
|
+
};
|
|
1109
|
+
tcPrAttrs.anchor = map[o.verticalAlign] ?? "t";
|
|
1110
|
+
}
|
|
1111
|
+
tcPr += serializeCellBorders(cell, tableBorder);
|
|
1112
|
+
if (o?.fill) {
|
|
1113
|
+
tcPr += serializeFill(o.fill, ctx);
|
|
1114
|
+
}
|
|
1115
|
+
if (o?.margin) {
|
|
1116
|
+
if (o.margin.top !== void 0) tcPrAttrs.marT = String(ptToEmu(o.margin.top));
|
|
1117
|
+
if (o.margin.bottom !== void 0) tcPrAttrs.marB = String(ptToEmu(o.margin.bottom));
|
|
1118
|
+
if (o.margin.left !== void 0) tcPrAttrs.marL = String(ptToEmu(o.margin.left));
|
|
1119
|
+
if (o.margin.right !== void 0) tcPrAttrs.marR = String(ptToEmu(o.margin.right));
|
|
1120
|
+
}
|
|
1121
|
+
xml += tag(
|
|
1122
|
+
"a:tcPr",
|
|
1123
|
+
Object.keys(tcPrAttrs).length > 0 ? tcPrAttrs : void 0,
|
|
1124
|
+
tcPr || void 0
|
|
1125
|
+
);
|
|
1126
|
+
xml += closeTag("a:tc");
|
|
1127
|
+
return xml;
|
|
1128
|
+
}
|
|
1129
|
+
function serializeTableBorders(border) {
|
|
1130
|
+
const bw = border.width ? ptToEmu(border.width) : 12700;
|
|
1131
|
+
const bc = border.color ?? "000000";
|
|
1132
|
+
const defaultLine = tag("a:ln", { w: bw }, serializeSolidFill(bc));
|
|
1133
|
+
const sides = [
|
|
1134
|
+
{ key: "left", elName: "a:left" },
|
|
1135
|
+
{ key: "right", elName: "a:right" },
|
|
1136
|
+
{ key: "top", elName: "a:top" },
|
|
1137
|
+
{ key: "bottom", elName: "a:bottom" },
|
|
1138
|
+
{ key: "insideH", elName: "a:insideH" },
|
|
1139
|
+
{ key: "insideV", elName: "a:insideV" }
|
|
1140
|
+
];
|
|
1141
|
+
let xml = "";
|
|
1142
|
+
for (const side of sides) {
|
|
1143
|
+
const override = border[side.key];
|
|
1144
|
+
if (typeof override === "object" && override !== null && "color" in override) {
|
|
1145
|
+
xml += tag(side.elName, void 0, serializeBorderLine(override));
|
|
1146
|
+
} else {
|
|
1147
|
+
xml += tag(side.elName, void 0, defaultLine);
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
return xml;
|
|
1151
|
+
}
|
|
1152
|
+
var tableSerializer = {
|
|
1153
|
+
type: "table",
|
|
1154
|
+
serialize(element, ctx) {
|
|
1155
|
+
const p = element.placement;
|
|
1156
|
+
const numCols = element.rows[0]?.length ?? 0;
|
|
1157
|
+
let xml = openTag("p:graphicFrame");
|
|
1158
|
+
xml += tag(
|
|
1159
|
+
"p:nvGraphicFramePr",
|
|
1160
|
+
void 0,
|
|
1161
|
+
tag("p:cNvPr", { id: "0", name: element.name ?? "Table" }) + tag("p:cNvGraphicFramePr", void 0, tag("a:graphicFrameLocks", { noGrp: "1" })) + tag("p:nvPr")
|
|
1162
|
+
);
|
|
1163
|
+
xml += tag(
|
|
1164
|
+
"p:xfrm",
|
|
1165
|
+
void 0,
|
|
1166
|
+
tag("a:off", { x: inchesToEmu(p.x), y: inchesToEmu(p.y) }) + tag("a:ext", { cx: inchesToEmu(p.w), cy: inchesToEmu(p.h) })
|
|
1167
|
+
);
|
|
1168
|
+
xml += openTag("a:graphic");
|
|
1169
|
+
xml += openTag("a:graphicData", {
|
|
1170
|
+
uri: "http://schemas.openxmlformats.org/drawingml/2006/table"
|
|
1171
|
+
});
|
|
1172
|
+
xml += openTag("a:tbl");
|
|
1173
|
+
const tblPrAttrs = {
|
|
1174
|
+
firstRow: element.firstRow ? "1" : "0",
|
|
1175
|
+
lastRow: element.lastRow ? "1" : "0",
|
|
1176
|
+
firstCol: element.firstCol ? "1" : "0",
|
|
1177
|
+
lastCol: element.lastCol ? "1" : "0",
|
|
1178
|
+
bandRow: element.bandRow ? "1" : "0",
|
|
1179
|
+
bandCol: element.bandCol ? "1" : "0"
|
|
1180
|
+
};
|
|
1181
|
+
let tblPrChildren = "";
|
|
1182
|
+
if (element.fill) {
|
|
1183
|
+
tblPrChildren += serializeFill(element.fill, ctx);
|
|
1184
|
+
}
|
|
1185
|
+
if (element.border) {
|
|
1186
|
+
tblPrChildren += serializeTableBorders(element.border);
|
|
1187
|
+
}
|
|
1188
|
+
if (element.tableStyleId) {
|
|
1189
|
+
tblPrChildren += tag("a:tblStyle", { val: element.tableStyleId });
|
|
1190
|
+
}
|
|
1191
|
+
xml += tag("a:tblPr", tblPrAttrs, tblPrChildren || void 0);
|
|
1192
|
+
xml += openTag("a:tblGrid");
|
|
1193
|
+
const defaultColWidth = p.w / numCols;
|
|
1194
|
+
for (let i = 0; i < numCols; i++) {
|
|
1195
|
+
const w = element.colWidths?.[i] ?? defaultColWidth;
|
|
1196
|
+
xml += tag("a:gridCol", { w: inchesToEmu(w) });
|
|
1197
|
+
}
|
|
1198
|
+
xml += closeTag("a:tblGrid");
|
|
1199
|
+
const defaultRowHeight = p.h / element.rows.length;
|
|
1200
|
+
for (let r = 0; r < element.rows.length; r++) {
|
|
1201
|
+
const h = element.rowHeights?.[r] ?? defaultRowHeight;
|
|
1202
|
+
xml += openTag("a:tr", { h: inchesToEmu(h) });
|
|
1203
|
+
for (const cell of element.rows[r]) {
|
|
1204
|
+
xml += serializeCell(cell, element.border, ctx);
|
|
1205
|
+
}
|
|
1206
|
+
xml += closeTag("a:tr");
|
|
1207
|
+
}
|
|
1208
|
+
xml += closeTag("a:tbl");
|
|
1209
|
+
xml += closeTag("a:graphicData");
|
|
1210
|
+
xml += closeTag("a:graphic");
|
|
1211
|
+
xml += closeTag("p:graphicFrame");
|
|
1212
|
+
return xml;
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
|
|
1216
|
+
// src/ooxml/serializers/chart.ts
|
|
1217
|
+
function serializeTrendline(t) {
|
|
1218
|
+
let xml = openTag("c:trendline");
|
|
1219
|
+
xml += tag("c:trendlineType", { val: t.type ?? "linear" });
|
|
1220
|
+
if (t.order !== void 0) xml += tag("c:order", { val: t.order });
|
|
1221
|
+
if (t.period !== void 0) xml += tag("c:period", { val: t.period });
|
|
1222
|
+
if (t.forward !== void 0) xml += tag("c:forward", { val: t.forward });
|
|
1223
|
+
if (t.backward !== void 0) xml += tag("c:backward", { val: t.backward });
|
|
1224
|
+
if (t.intercept !== void 0) xml += tag("c:intercept", { val: t.intercept });
|
|
1225
|
+
if (t.displayEquation) xml += tag("c:dispEq", { val: "1" });
|
|
1226
|
+
if (t.displayRSquared) xml += tag("c:dispRSqr", { val: "1" });
|
|
1227
|
+
if (t.color || t.width || t.dash) {
|
|
1228
|
+
let spPr = "";
|
|
1229
|
+
const lnAttrs = {};
|
|
1230
|
+
if (t.width) lnAttrs.w = ptToEmu(t.width);
|
|
1231
|
+
let lnChildren = "";
|
|
1232
|
+
if (t.color) lnChildren += serializeSolidFill(t.color);
|
|
1233
|
+
if (t.dash && t.dash !== "solid") lnChildren += tag("a:prstDash", { val: t.dash });
|
|
1234
|
+
spPr += tag(
|
|
1235
|
+
"a:ln",
|
|
1236
|
+
Object.keys(lnAttrs).length > 0 ? lnAttrs : void 0,
|
|
1237
|
+
lnChildren || void 0
|
|
1238
|
+
);
|
|
1239
|
+
xml += tag("c:spPr", void 0, spPr);
|
|
1240
|
+
}
|
|
1241
|
+
xml += closeTag("c:trendline");
|
|
1242
|
+
return xml;
|
|
1243
|
+
}
|
|
1244
|
+
function serializeErrorBars(e) {
|
|
1245
|
+
let xml = openTag("c:errBars");
|
|
1246
|
+
xml += tag("c:errDir", { val: e.direction ?? "y" });
|
|
1247
|
+
xml += tag("c:errBarType", { val: e.type ?? "both" });
|
|
1248
|
+
xml += tag("c:errValType", { val: e.valueType ?? "fixedVal" });
|
|
1249
|
+
if (e.noEndCap) xml += tag("c:noEndCap", { val: "1" });
|
|
1250
|
+
if (e.value !== void 0) xml += tag("c:val", { val: e.value });
|
|
1251
|
+
if (e.color || e.width) {
|
|
1252
|
+
let spPr = "";
|
|
1253
|
+
const lnAttrs = {};
|
|
1254
|
+
if (e.width) lnAttrs.w = ptToEmu(e.width);
|
|
1255
|
+
let lnChildren = "";
|
|
1256
|
+
if (e.color) lnChildren += serializeSolidFill(e.color);
|
|
1257
|
+
spPr += tag(
|
|
1258
|
+
"a:ln",
|
|
1259
|
+
Object.keys(lnAttrs).length > 0 ? lnAttrs : void 0,
|
|
1260
|
+
lnChildren || void 0
|
|
1261
|
+
);
|
|
1262
|
+
xml += tag("c:spPr", void 0, spPr);
|
|
1263
|
+
}
|
|
1264
|
+
xml += closeTag("c:errBars");
|
|
1265
|
+
return xml;
|
|
1266
|
+
}
|
|
1267
|
+
function serializeDataLabels(dl) {
|
|
1268
|
+
let xml = openTag("c:dLbls");
|
|
1269
|
+
if (dl.position) xml += tag("c:dLblPos", { val: dl.position });
|
|
1270
|
+
if (dl.numberFormat) {
|
|
1271
|
+
xml += tag("c:numFmt", { formatCode: dl.numberFormat, sourceLinked: "0" });
|
|
1272
|
+
}
|
|
1273
|
+
if (dl.fontSize || dl.fontFace || dl.color) {
|
|
1274
|
+
let rPrChildren = "";
|
|
1275
|
+
if (dl.color) rPrChildren += serializeSolidFill(dl.color);
|
|
1276
|
+
if (dl.fontFace) rPrChildren += tag("a:latin", { typeface: dl.fontFace });
|
|
1277
|
+
const rPrAttrs = {};
|
|
1278
|
+
if (dl.fontSize) rPrAttrs.sz = ptToHundredths(dl.fontSize);
|
|
1279
|
+
xml += tag(
|
|
1280
|
+
"c:txPr",
|
|
1281
|
+
void 0,
|
|
1282
|
+
tag("a:bodyPr") + tag("a:lstStyle") + tag(
|
|
1283
|
+
"a:p",
|
|
1284
|
+
void 0,
|
|
1285
|
+
tag(
|
|
1286
|
+
"a:pPr",
|
|
1287
|
+
void 0,
|
|
1288
|
+
tag(
|
|
1289
|
+
"a:defRPr",
|
|
1290
|
+
Object.keys(rPrAttrs).length > 0 ? rPrAttrs : void 0,
|
|
1291
|
+
rPrChildren || void 0
|
|
1292
|
+
)
|
|
1293
|
+
)
|
|
1294
|
+
)
|
|
1295
|
+
);
|
|
1296
|
+
}
|
|
1297
|
+
if (dl.separator) xml += tag("c:separator", void 0, dl.separator);
|
|
1298
|
+
xml += tag("c:showVal", { val: dl.showValue !== false ? "1" : "0" });
|
|
1299
|
+
xml += tag("c:showCatName", { val: dl.showCategory ? "1" : "0" });
|
|
1300
|
+
xml += tag("c:showSerName", { val: dl.showSeriesName ? "1" : "0" });
|
|
1301
|
+
xml += tag("c:showPercent", { val: dl.showPercent ? "1" : "0" });
|
|
1302
|
+
xml += closeTag("c:dLbls");
|
|
1303
|
+
return xml;
|
|
1304
|
+
}
|
|
1305
|
+
var chartCounter = 0;
|
|
1306
|
+
var CHART_NS = "http://schemas.openxmlformats.org/drawingml/2006/chart";
|
|
1307
|
+
var CHART_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart";
|
|
1308
|
+
var DEFAULT_COLORS = [
|
|
1309
|
+
"4472C4",
|
|
1310
|
+
"ED7D31",
|
|
1311
|
+
"A5A5A5",
|
|
1312
|
+
"FFC000",
|
|
1313
|
+
"5B9BD5",
|
|
1314
|
+
"70AD47",
|
|
1315
|
+
"264478",
|
|
1316
|
+
"9B57A2",
|
|
1317
|
+
"636363",
|
|
1318
|
+
"EB6B0A"
|
|
1319
|
+
];
|
|
1320
|
+
function serializeAxis(axisTag, axId, crossAxId, position, opts, showGridLines) {
|
|
1321
|
+
let xml = openTag(axisTag);
|
|
1322
|
+
xml += tag("c:axId", void 0, axId);
|
|
1323
|
+
let scalingChildren = tag("c:orientation", { val: opts?.orientation ?? "minMax" });
|
|
1324
|
+
if (opts?.min !== void 0) scalingChildren += tag("c:min", { val: opts.min });
|
|
1325
|
+
if (opts?.max !== void 0) scalingChildren += tag("c:max", { val: opts.max });
|
|
1326
|
+
if (opts?.logBase !== void 0) scalingChildren += tag("c:logBase", { val: opts.logBase });
|
|
1327
|
+
xml += tag("c:scaling", void 0, scalingChildren);
|
|
1328
|
+
xml += tag("c:delete", { val: opts?.delete ? "1" : "0" });
|
|
1329
|
+
xml += tag("c:axPos", { val: opts?.position ?? position });
|
|
1330
|
+
if (opts?.format) {
|
|
1331
|
+
xml += tag("c:numFmt", { formatCode: opts.format, sourceLinked: "0" });
|
|
1332
|
+
}
|
|
1333
|
+
const showMajor = opts?.majorGridlines ?? (axisTag === "c:valAx" && showGridLines);
|
|
1334
|
+
if (showMajor) {
|
|
1335
|
+
if (typeof showMajor === "object") {
|
|
1336
|
+
const glAttrs = {};
|
|
1337
|
+
if (showMajor.width) glAttrs.w = ptToEmu(showMajor.width);
|
|
1338
|
+
let glChildren = "";
|
|
1339
|
+
if (showMajor.color) {
|
|
1340
|
+
glChildren = serializeSolidFill(showMajor.color);
|
|
1341
|
+
}
|
|
1342
|
+
xml += tag(
|
|
1343
|
+
"c:majorGridlines",
|
|
1344
|
+
void 0,
|
|
1345
|
+
tag("c:spPr", void 0, tag("a:ln", glAttrs, glChildren || void 0))
|
|
1346
|
+
);
|
|
1347
|
+
} else {
|
|
1348
|
+
xml += tag("c:majorGridlines");
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
if (opts?.minorGridlines) {
|
|
1352
|
+
if (typeof opts.minorGridlines === "object") {
|
|
1353
|
+
const glAttrs = {};
|
|
1354
|
+
if (opts.minorGridlines.width) glAttrs.w = ptToEmu(opts.minorGridlines.width);
|
|
1355
|
+
let glChildren = "";
|
|
1356
|
+
if (opts.minorGridlines.color) {
|
|
1357
|
+
glChildren = serializeSolidFill(opts.minorGridlines.color);
|
|
1358
|
+
}
|
|
1359
|
+
xml += tag(
|
|
1360
|
+
"c:minorGridlines",
|
|
1361
|
+
void 0,
|
|
1362
|
+
tag("c:spPr", void 0, tag("a:ln", glAttrs, glChildren || void 0))
|
|
1363
|
+
);
|
|
1364
|
+
} else {
|
|
1365
|
+
xml += tag("c:minorGridlines");
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
if (opts?.title) {
|
|
1369
|
+
const titleRPrAttrs = { lang: "en-US" };
|
|
1370
|
+
if (opts.titleFontSize) titleRPrAttrs.sz = ptToHundredths(opts.titleFontSize);
|
|
1371
|
+
xml += tag(
|
|
1372
|
+
"c:title",
|
|
1373
|
+
void 0,
|
|
1374
|
+
tag(
|
|
1375
|
+
"c:tx",
|
|
1376
|
+
void 0,
|
|
1377
|
+
tag(
|
|
1378
|
+
"c:rich",
|
|
1379
|
+
void 0,
|
|
1380
|
+
tag("a:bodyPr") + tag("a:lstStyle") + tag(
|
|
1381
|
+
"a:p",
|
|
1382
|
+
void 0,
|
|
1383
|
+
tag("a:pPr", void 0, tag("a:defRPr", titleRPrAttrs)) + tag(
|
|
1384
|
+
"a:r",
|
|
1385
|
+
void 0,
|
|
1386
|
+
tag("a:rPr", titleRPrAttrs) + tag("a:t", void 0, escapeXml(opts.title))
|
|
1387
|
+
)
|
|
1388
|
+
)
|
|
1389
|
+
)
|
|
1390
|
+
) + tag("c:overlay", { val: "0" })
|
|
1391
|
+
);
|
|
1392
|
+
}
|
|
1393
|
+
if (opts?.majorUnit) xml += tag("c:majorUnit", { val: opts.majorUnit });
|
|
1394
|
+
if (opts?.minorUnit) xml += tag("c:minorUnit", { val: opts.minorUnit });
|
|
1395
|
+
if (opts?.labelFontSize || opts?.labelColor || opts?.labelRotation !== void 0) {
|
|
1396
|
+
const bodyAttrs = {};
|
|
1397
|
+
if (opts?.labelRotation !== void 0) bodyAttrs.rot = Math.round(opts.labelRotation * 6e4);
|
|
1398
|
+
const rPrAttrs = {};
|
|
1399
|
+
if (opts?.labelFontSize) rPrAttrs.sz = ptToHundredths(opts.labelFontSize);
|
|
1400
|
+
let rPrChildren = "";
|
|
1401
|
+
if (opts?.labelColor) rPrChildren = serializeSolidFill(opts.labelColor);
|
|
1402
|
+
xml += tag(
|
|
1403
|
+
"c:txPr",
|
|
1404
|
+
void 0,
|
|
1405
|
+
tag("a:bodyPr", bodyAttrs) + tag("a:lstStyle") + tag(
|
|
1406
|
+
"a:p",
|
|
1407
|
+
void 0,
|
|
1408
|
+
tag("a:pPr", void 0, tag("a:defRPr", rPrAttrs, rPrChildren || void 0))
|
|
1409
|
+
)
|
|
1410
|
+
);
|
|
1411
|
+
}
|
|
1412
|
+
xml += tag("c:crossAx", void 0, crossAxId);
|
|
1413
|
+
if (opts?.crossesAt !== void 0) {
|
|
1414
|
+
if (opts.crossesAt === "min") xml += tag("c:crosses", { val: "min" });
|
|
1415
|
+
else if (opts.crossesAt === "max") xml += tag("c:crosses", { val: "max" });
|
|
1416
|
+
else if (opts.crossesAt === "auto") xml += tag("c:crosses", { val: "autoZero" });
|
|
1417
|
+
else xml += tag("c:crossesAt", { val: opts.crossesAt });
|
|
1418
|
+
}
|
|
1419
|
+
xml += closeTag(axisTag);
|
|
1420
|
+
return xml;
|
|
1421
|
+
}
|
|
1422
|
+
function serializeSeriesData(data, chartType, showDataLabels) {
|
|
1423
|
+
let xml = "";
|
|
1424
|
+
const isScatter = chartType === "scatter";
|
|
1425
|
+
for (let i = 0; i < data.series.length; i++) {
|
|
1426
|
+
const s = data.series[i];
|
|
1427
|
+
const color = s.color ?? DEFAULT_COLORS[i % DEFAULT_COLORS.length];
|
|
1428
|
+
xml += openTag("c:ser");
|
|
1429
|
+
xml += tag("c:idx", { val: i });
|
|
1430
|
+
xml += tag("c:order", { val: i });
|
|
1431
|
+
xml += tag(
|
|
1432
|
+
"c:tx",
|
|
1433
|
+
void 0,
|
|
1434
|
+
tag(
|
|
1435
|
+
"c:strRef",
|
|
1436
|
+
void 0,
|
|
1437
|
+
tag("c:f", void 0, `Sheet1!$B$1`) + tag(
|
|
1438
|
+
"c:strCache",
|
|
1439
|
+
void 0,
|
|
1440
|
+
tag("c:ptCount", { val: "1" }) + tag("c:pt", { idx: "0" }, tag("c:v", void 0, escapeXml(s.name)))
|
|
1441
|
+
)
|
|
1442
|
+
)
|
|
1443
|
+
);
|
|
1444
|
+
let spPrChildren = serializeSolidFill(color);
|
|
1445
|
+
if (s.lineWidth || s.lineDash) {
|
|
1446
|
+
const lnAttrs = {};
|
|
1447
|
+
if (s.lineWidth) lnAttrs.w = ptToEmu(s.lineWidth);
|
|
1448
|
+
let lnChildren = serializeSolidFill(color);
|
|
1449
|
+
if (s.lineDash && s.lineDash !== "solid") {
|
|
1450
|
+
lnChildren += tag("a:prstDash", { val: s.lineDash });
|
|
1451
|
+
}
|
|
1452
|
+
spPrChildren += tag("a:ln", lnAttrs, lnChildren);
|
|
1453
|
+
}
|
|
1454
|
+
if (s.opacity !== void 0 && s.opacity < 100) {
|
|
1455
|
+
spPrChildren = tag(
|
|
1456
|
+
"a:solidFill",
|
|
1457
|
+
void 0,
|
|
1458
|
+
serializeColorWithAlpha(s.fill ?? color, s.opacity)
|
|
1459
|
+
);
|
|
1460
|
+
}
|
|
1461
|
+
xml += tag("c:spPr", void 0, spPrChildren);
|
|
1462
|
+
if (s.marker) {
|
|
1463
|
+
let markerXml = "";
|
|
1464
|
+
markerXml += tag("c:symbol", { val: s.marker.type ?? "circle" });
|
|
1465
|
+
if (s.marker.size) markerXml += tag("c:size", { val: s.marker.size });
|
|
1466
|
+
let markerSpPr = "";
|
|
1467
|
+
if (s.marker.fill) {
|
|
1468
|
+
markerSpPr += serializeSolidFill(s.marker.fill);
|
|
1469
|
+
}
|
|
1470
|
+
if (s.marker.border) {
|
|
1471
|
+
let lnChildren = "";
|
|
1472
|
+
if (s.marker.border.color) {
|
|
1473
|
+
lnChildren = serializeSolidFill(s.marker.border.color);
|
|
1474
|
+
}
|
|
1475
|
+
const lnAttrs = {};
|
|
1476
|
+
if (s.marker.border.width) lnAttrs.w = ptToEmu(s.marker.border.width);
|
|
1477
|
+
markerSpPr += tag("a:ln", lnAttrs, lnChildren || void 0);
|
|
1478
|
+
}
|
|
1479
|
+
if (markerSpPr) markerXml += tag("c:spPr", void 0, markerSpPr);
|
|
1480
|
+
xml += tag("c:marker", void 0, markerXml);
|
|
1481
|
+
}
|
|
1482
|
+
if (s.colors && s.colors.length > 0) {
|
|
1483
|
+
for (let j = 0; j < s.colors.length; j++) {
|
|
1484
|
+
xml += tag(
|
|
1485
|
+
"c:dPt",
|
|
1486
|
+
void 0,
|
|
1487
|
+
tag("c:idx", { val: j }) + tag("c:spPr", void 0, serializeSolidFill(s.colors[j]))
|
|
1488
|
+
);
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
if (showDataLabels) {
|
|
1492
|
+
xml += tag(
|
|
1493
|
+
"c:dLbls",
|
|
1494
|
+
void 0,
|
|
1495
|
+
tag("c:showVal", { val: "1" }) + tag("c:showCatName", { val: "0" }) + tag("c:showSerName", { val: "0" })
|
|
1496
|
+
);
|
|
1497
|
+
} else if (s.dataLabels) {
|
|
1498
|
+
xml += serializeDataLabels(s.dataLabels);
|
|
1499
|
+
}
|
|
1500
|
+
if (s.trendline) {
|
|
1501
|
+
xml += serializeTrendline(s.trendline);
|
|
1502
|
+
}
|
|
1503
|
+
if (s.errorBars) {
|
|
1504
|
+
xml += serializeErrorBars(s.errorBars);
|
|
1505
|
+
}
|
|
1506
|
+
if (s.explosion !== void 0) {
|
|
1507
|
+
xml += tag("c:explosion", { val: s.explosion });
|
|
1508
|
+
}
|
|
1509
|
+
if (s.smooth) {
|
|
1510
|
+
xml += tag("c:smooth", { val: "1" });
|
|
1511
|
+
}
|
|
1512
|
+
if (data.categories && !isScatter) {
|
|
1513
|
+
xml += openTag("c:cat");
|
|
1514
|
+
xml += openTag("c:strRef");
|
|
1515
|
+
xml += tag("c:f", void 0, "Sheet1!$A$2:$A$" + (data.categories.length + 1));
|
|
1516
|
+
xml += openTag("c:strCache");
|
|
1517
|
+
xml += tag("c:ptCount", { val: data.categories.length });
|
|
1518
|
+
for (let j = 0; j < data.categories.length; j++) {
|
|
1519
|
+
xml += tag("c:pt", { idx: j }, tag("c:v", void 0, escapeXml(data.categories[j])));
|
|
1520
|
+
}
|
|
1521
|
+
xml += closeTag("c:strCache");
|
|
1522
|
+
xml += closeTag("c:strRef");
|
|
1523
|
+
xml += closeTag("c:cat");
|
|
1524
|
+
}
|
|
1525
|
+
if (isScatter && data.xValues) {
|
|
1526
|
+
xml += openTag("c:xVal");
|
|
1527
|
+
xml += openTag("c:numRef");
|
|
1528
|
+
xml += tag("c:f", void 0, `Sheet1!$A$2:$A$${data.xValues.length + 1}`);
|
|
1529
|
+
xml += openTag("c:numCache");
|
|
1530
|
+
xml += tag("c:formatCode", void 0, "General");
|
|
1531
|
+
xml += tag("c:ptCount", { val: data.xValues.length });
|
|
1532
|
+
for (let j = 0; j < data.xValues.length; j++) {
|
|
1533
|
+
xml += tag("c:pt", { idx: j }, tag("c:v", void 0, String(data.xValues[j])));
|
|
1534
|
+
}
|
|
1535
|
+
xml += closeTag("c:numCache");
|
|
1536
|
+
xml += closeTag("c:numRef");
|
|
1537
|
+
xml += closeTag("c:xVal");
|
|
1538
|
+
xml += openTag("c:yVal");
|
|
1539
|
+
} else {
|
|
1540
|
+
xml += openTag("c:val");
|
|
1541
|
+
}
|
|
1542
|
+
xml += openTag("c:numRef");
|
|
1543
|
+
xml += tag("c:f", void 0, `Sheet1!$B$2:$B$${s.values.length + 1}`);
|
|
1544
|
+
xml += openTag("c:numCache");
|
|
1545
|
+
xml += tag("c:formatCode", void 0, "General");
|
|
1546
|
+
xml += tag("c:ptCount", { val: s.values.length });
|
|
1547
|
+
for (let j = 0; j < s.values.length; j++) {
|
|
1548
|
+
xml += tag("c:pt", { idx: j }, tag("c:v", void 0, String(s.values[j])));
|
|
1549
|
+
}
|
|
1550
|
+
xml += closeTag("c:numCache");
|
|
1551
|
+
xml += closeTag("c:numRef");
|
|
1552
|
+
xml += closeTag(isScatter ? "c:yVal" : "c:val");
|
|
1553
|
+
if (chartType === "bubble" && data.bubbleSizes) {
|
|
1554
|
+
xml += openTag("c:bubbleSize");
|
|
1555
|
+
xml += openTag("c:numRef");
|
|
1556
|
+
xml += tag("c:f", void 0, `Sheet1!$C$2:$C$${data.bubbleSizes.length + 1}`);
|
|
1557
|
+
xml += openTag("c:numCache");
|
|
1558
|
+
xml += tag("c:formatCode", void 0, "General");
|
|
1559
|
+
xml += tag("c:ptCount", { val: data.bubbleSizes.length });
|
|
1560
|
+
for (let j = 0; j < data.bubbleSizes.length; j++) {
|
|
1561
|
+
xml += tag("c:pt", { idx: j }, tag("c:v", void 0, String(data.bubbleSizes[j])));
|
|
1562
|
+
}
|
|
1563
|
+
xml += closeTag("c:numCache");
|
|
1564
|
+
xml += closeTag("c:numRef");
|
|
1565
|
+
xml += closeTag("c:bubbleSize");
|
|
1566
|
+
}
|
|
1567
|
+
xml += closeTag("c:ser");
|
|
1568
|
+
}
|
|
1569
|
+
return xml;
|
|
1570
|
+
}
|
|
1571
|
+
function getOoxmlChartTag(chartType) {
|
|
1572
|
+
const map = {
|
|
1573
|
+
bar: "c:barChart",
|
|
1574
|
+
col: "c:barChart",
|
|
1575
|
+
line: "c:lineChart",
|
|
1576
|
+
pie: "c:pieChart",
|
|
1577
|
+
area: "c:areaChart",
|
|
1578
|
+
scatter: "c:scatterChart",
|
|
1579
|
+
doughnut: "c:doughnutChart",
|
|
1580
|
+
radar: "c:radarChart",
|
|
1581
|
+
bubble: "c:bubbleChart",
|
|
1582
|
+
stock: "c:stockChart",
|
|
1583
|
+
surface: "c:surfaceChart",
|
|
1584
|
+
bar3D: "c:bar3DChart",
|
|
1585
|
+
col3D: "c:bar3DChart",
|
|
1586
|
+
line3D: "c:line3DChart",
|
|
1587
|
+
pie3D: "c:pie3DChart",
|
|
1588
|
+
area3D: "c:area3DChart"
|
|
1589
|
+
};
|
|
1590
|
+
return map[chartType];
|
|
1591
|
+
}
|
|
1592
|
+
function serializeChartXml(element) {
|
|
1593
|
+
const { chartType, data, title, showLegend, showDataLabels, showGridLines } = element;
|
|
1594
|
+
const chartTag = getOoxmlChartTag(chartType);
|
|
1595
|
+
const noAxesTypes = ["pie", "doughnut", "pie3D"];
|
|
1596
|
+
const hasAxes = !noAxesTypes.includes(chartType);
|
|
1597
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
1598
|
+
xml += openTag("c:chartSpace", {
|
|
1599
|
+
"xmlns:c": CHART_NS,
|
|
1600
|
+
"xmlns:a": NAMESPACE.a,
|
|
1601
|
+
"xmlns:r": NAMESPACE.r
|
|
1602
|
+
});
|
|
1603
|
+
xml += openTag("c:chart");
|
|
1604
|
+
if (title) {
|
|
1605
|
+
const titleRPrAttrs = { lang: "en-US" };
|
|
1606
|
+
if (element.titleFontSize) titleRPrAttrs.sz = ptToHundredths(element.titleFontSize);
|
|
1607
|
+
let titleRPrChildren = "";
|
|
1608
|
+
if (element.titleColor) {
|
|
1609
|
+
titleRPrChildren = serializeSolidFill(element.titleColor);
|
|
1610
|
+
}
|
|
1611
|
+
xml += tag(
|
|
1612
|
+
"c:title",
|
|
1613
|
+
void 0,
|
|
1614
|
+
tag(
|
|
1615
|
+
"c:tx",
|
|
1616
|
+
void 0,
|
|
1617
|
+
tag(
|
|
1618
|
+
"c:rich",
|
|
1619
|
+
void 0,
|
|
1620
|
+
tag("a:bodyPr") + tag("a:lstStyle") + tag(
|
|
1621
|
+
"a:p",
|
|
1622
|
+
void 0,
|
|
1623
|
+
tag(
|
|
1624
|
+
"a:pPr",
|
|
1625
|
+
void 0,
|
|
1626
|
+
tag("a:defRPr", titleRPrAttrs, titleRPrChildren || void 0)
|
|
1627
|
+
) + tag(
|
|
1628
|
+
"a:r",
|
|
1629
|
+
void 0,
|
|
1630
|
+
tag("a:rPr", titleRPrAttrs, titleRPrChildren || void 0) + tag("a:t", void 0, escapeXml(title))
|
|
1631
|
+
)
|
|
1632
|
+
)
|
|
1633
|
+
)
|
|
1634
|
+
) + tag("c:overlay", { val: "0" })
|
|
1635
|
+
);
|
|
1636
|
+
} else {
|
|
1637
|
+
xml += tag("c:autoTitleDeleted", { val: "1" });
|
|
1638
|
+
}
|
|
1639
|
+
if (element.view3D) {
|
|
1640
|
+
let v3d = "";
|
|
1641
|
+
if (element.view3D.rotX !== void 0) v3d += tag("c:rotX", { val: element.view3D.rotX });
|
|
1642
|
+
if (element.view3D.rotY !== void 0) v3d += tag("c:rotY", { val: element.view3D.rotY });
|
|
1643
|
+
if (element.view3D.depthPercent !== void 0)
|
|
1644
|
+
v3d += tag("c:depthPercent", { val: element.view3D.depthPercent });
|
|
1645
|
+
if (element.view3D.rAngAx !== void 0)
|
|
1646
|
+
v3d += tag("c:rAngAx", { val: element.view3D.rAngAx ? "1" : "0" });
|
|
1647
|
+
if (element.view3D.perspective !== void 0)
|
|
1648
|
+
v3d += tag("c:perspective", { val: element.view3D.perspective });
|
|
1649
|
+
xml += tag("c:view3D", void 0, v3d);
|
|
1650
|
+
}
|
|
1651
|
+
xml += openTag("c:plotArea");
|
|
1652
|
+
xml += tag("c:layout");
|
|
1653
|
+
xml += openTag(chartTag);
|
|
1654
|
+
if (chartType === "bar" || chartType === "bar3D") {
|
|
1655
|
+
xml += tag("c:barDir", { val: "bar" });
|
|
1656
|
+
xml += tag("c:grouping", { val: element.barGrouping ?? "clustered" });
|
|
1657
|
+
} else if (chartType === "col" || chartType === "col3D") {
|
|
1658
|
+
xml += tag("c:barDir", { val: "col" });
|
|
1659
|
+
xml += tag("c:grouping", { val: element.barGrouping ?? "clustered" });
|
|
1660
|
+
} else if (chartType === "line" || chartType === "line3D") {
|
|
1661
|
+
xml += tag("c:grouping", { val: element.lineGrouping ?? "standard" });
|
|
1662
|
+
} else if (chartType === "area" || chartType === "area3D") {
|
|
1663
|
+
xml += tag("c:grouping", { val: element.areaGrouping ?? "standard" });
|
|
1664
|
+
} else if (chartType === "scatter") {
|
|
1665
|
+
xml += tag("c:scatterStyle", { val: element.scatterStyle ?? "lineMarker" });
|
|
1666
|
+
} else if (chartType === "radar") {
|
|
1667
|
+
xml += tag("c:radarStyle", { val: element.radarStyle ?? "marker" });
|
|
1668
|
+
}
|
|
1669
|
+
xml += serializeSeriesData(data, chartType, showDataLabels);
|
|
1670
|
+
if (chartType === "pie" || chartType === "pie3D") {
|
|
1671
|
+
if (element.pieExplosion) {
|
|
1672
|
+
for (let i = 0; i < data.series[0]?.values.length; i++) {
|
|
1673
|
+
xml += tag(
|
|
1674
|
+
"c:dPt",
|
|
1675
|
+
void 0,
|
|
1676
|
+
tag("c:idx", { val: i }) + tag("c:explosion", { val: element.pieExplosion })
|
|
1677
|
+
);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
if (chartType === "doughnut") {
|
|
1682
|
+
xml += tag("c:holeSize", { val: element.doughnutHoleSize ?? 50 });
|
|
1683
|
+
}
|
|
1684
|
+
if ((chartType === "bar" || chartType === "col" || chartType === "bar3D" || chartType === "col3D") && element.barGapWidth !== void 0) {
|
|
1685
|
+
xml += tag("c:gapWidth", { val: element.barGapWidth });
|
|
1686
|
+
}
|
|
1687
|
+
if ((chartType === "bar" || chartType === "col" || chartType === "bar3D" || chartType === "col3D") && element.barOverlap !== void 0) {
|
|
1688
|
+
xml += tag("c:overlap", { val: element.barOverlap });
|
|
1689
|
+
}
|
|
1690
|
+
if (hasAxes) {
|
|
1691
|
+
xml += tag("c:axId", { val: "1" });
|
|
1692
|
+
xml += tag("c:axId", { val: "2" });
|
|
1693
|
+
}
|
|
1694
|
+
xml += closeTag(chartTag);
|
|
1695
|
+
if (hasAxes) {
|
|
1696
|
+
xml += serializeAxis("c:catAx", "1", "2", "b", element.catAxis, showGridLines);
|
|
1697
|
+
xml += serializeAxis("c:valAx", "2", "1", "l", element.valAxis, showGridLines);
|
|
1698
|
+
if (element.secondaryValAxis) {
|
|
1699
|
+
xml += serializeAxis("c:valAx", "3", "1", "r", element.secondaryValAxis, false);
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
if (element.plotArea) {
|
|
1703
|
+
let plotSpPr = "";
|
|
1704
|
+
if (element.plotArea.fill) {
|
|
1705
|
+
plotSpPr += serializeSolidFill(element.plotArea.fill);
|
|
1706
|
+
}
|
|
1707
|
+
if (plotSpPr) {
|
|
1708
|
+
xml += tag("c:spPr", void 0, plotSpPr);
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
xml += closeTag("c:plotArea");
|
|
1712
|
+
if (showLegend) {
|
|
1713
|
+
xml += tag(
|
|
1714
|
+
"c:legend",
|
|
1715
|
+
void 0,
|
|
1716
|
+
tag("c:legendPos", { val: element.legendPosition ?? "b" }) + tag("c:overlay", { val: "0" })
|
|
1717
|
+
);
|
|
1718
|
+
}
|
|
1719
|
+
xml += tag("c:plotVisOnly", { val: "1" });
|
|
1720
|
+
xml += closeTag("c:chart");
|
|
1721
|
+
if (element.fill) {
|
|
1722
|
+
xml += tag("c:spPr", void 0, serializeSolidFill(element.fill));
|
|
1723
|
+
}
|
|
1724
|
+
xml += closeTag("c:chartSpace");
|
|
1725
|
+
return xml;
|
|
1726
|
+
}
|
|
1727
|
+
var chartSerializer = {
|
|
1728
|
+
type: "chart",
|
|
1729
|
+
serialize(element, ctx) {
|
|
1730
|
+
chartCounter++;
|
|
1731
|
+
const chartFileName = `chart${chartCounter}.xml`;
|
|
1732
|
+
const target = `../charts/${chartFileName}`;
|
|
1733
|
+
const chartXml = serializeChartXml(element);
|
|
1734
|
+
const encoder2 = new TextEncoder();
|
|
1735
|
+
const rId = ctx.addRelationship(CHART_REL_TYPE, target, encoder2.encode(chartXml));
|
|
1736
|
+
const p = element.placement;
|
|
1737
|
+
let xml = openTag("p:graphicFrame");
|
|
1738
|
+
xml += tag(
|
|
1739
|
+
"p:nvGraphicFramePr",
|
|
1740
|
+
void 0,
|
|
1741
|
+
tag("p:cNvPr", { id: "0", name: element.name ?? "Chart" }) + tag("p:cNvGraphicFramePr") + tag("p:nvPr")
|
|
1742
|
+
);
|
|
1743
|
+
xml += tag(
|
|
1744
|
+
"p:xfrm",
|
|
1745
|
+
void 0,
|
|
1746
|
+
tag("a:off", { x: inchesToEmu(p.x), y: inchesToEmu(p.y) }) + tag("a:ext", { cx: inchesToEmu(p.w), cy: inchesToEmu(p.h) })
|
|
1747
|
+
);
|
|
1748
|
+
xml += tag(
|
|
1749
|
+
"a:graphic",
|
|
1750
|
+
void 0,
|
|
1751
|
+
tag("a:graphicData", { uri: CHART_NS }, tag("c:chart", { "xmlns:c": CHART_NS, "r:id": rId }))
|
|
1752
|
+
);
|
|
1753
|
+
xml += closeTag("p:graphicFrame");
|
|
1754
|
+
return xml;
|
|
1755
|
+
}
|
|
1756
|
+
};
|
|
1757
|
+
|
|
1758
|
+
// src/ooxml/serializers/media.ts
|
|
1759
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
1760
|
+
var mediaCounter = 0;
|
|
1761
|
+
var MEDIA_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/video";
|
|
1762
|
+
var AUDIO_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/audio";
|
|
1763
|
+
function extFromContentType(ct) {
|
|
1764
|
+
const map = {
|
|
1765
|
+
"video/mp4": "mp4",
|
|
1766
|
+
"video/webm": "webm",
|
|
1767
|
+
"video/avi": "avi",
|
|
1768
|
+
"audio/mpeg": "mp3",
|
|
1769
|
+
"audio/mp3": "mp3",
|
|
1770
|
+
"audio/wav": "wav",
|
|
1771
|
+
"audio/ogg": "ogg"
|
|
1772
|
+
};
|
|
1773
|
+
return map[ct] ?? ct.split("/")[1] ?? "bin";
|
|
1774
|
+
}
|
|
1775
|
+
var mediaSerializer = {
|
|
1776
|
+
type: "media",
|
|
1777
|
+
serialize(element, ctx) {
|
|
1778
|
+
mediaCounter++;
|
|
1779
|
+
const ext = extFromContentType(element.contentType);
|
|
1780
|
+
const fileName = `media${mediaCounter}.${ext}`;
|
|
1781
|
+
const target = `../media/${fileName}`;
|
|
1782
|
+
const relType = element.mediaType === "audio" ? AUDIO_REL_TYPE : MEDIA_REL_TYPE;
|
|
1783
|
+
let data = element.data;
|
|
1784
|
+
if (!data && element.path) {
|
|
1785
|
+
data = readFileSync3(element.path);
|
|
1786
|
+
}
|
|
1787
|
+
if (!data) throw new Error("Media element must have data or path");
|
|
1788
|
+
const rId = ctx.addRelationship(relType, target, data);
|
|
1789
|
+
const p = element.placement;
|
|
1790
|
+
if (element.mediaType === "audio") {
|
|
1791
|
+
let xml2 = openTag("p:sp");
|
|
1792
|
+
xml2 += tag(
|
|
1793
|
+
"p:nvSpPr",
|
|
1794
|
+
void 0,
|
|
1795
|
+
tag("p:cNvPr", { id: "0", name: element.name ?? "Audio" }) + tag("p:cNvSpPr") + tag("p:nvPr", void 0, tag("a:audioFile", { "r:link": rId }))
|
|
1796
|
+
);
|
|
1797
|
+
xml2 += openTag("p:spPr");
|
|
1798
|
+
xml2 += serializeTransform(p, element.transform);
|
|
1799
|
+
xml2 += tag("a:prstGeom", { prst: "rect" }, tag("a:avLst"));
|
|
1800
|
+
if (element.effects) xml2 += serializeEffects(element.effects);
|
|
1801
|
+
xml2 += closeTag("p:spPr");
|
|
1802
|
+
xml2 += closeTag("p:sp");
|
|
1803
|
+
return xml2;
|
|
1804
|
+
}
|
|
1805
|
+
let posterRId;
|
|
1806
|
+
if (element.poster) {
|
|
1807
|
+
let posterData = element.poster.data;
|
|
1808
|
+
if (!posterData && element.poster.path) {
|
|
1809
|
+
posterData = readFileSync3(element.poster.path);
|
|
1810
|
+
}
|
|
1811
|
+
if (posterData) {
|
|
1812
|
+
const pCt = element.poster.contentType ?? "image/png";
|
|
1813
|
+
const pExt = pCt.split("/")[1] ?? "png";
|
|
1814
|
+
const posterFile = `poster${mediaCounter}.${pExt}`;
|
|
1815
|
+
posterRId = ctx.addRelationship(REL_TYPE.image, `../media/${posterFile}`, posterData);
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
let xml = openTag("p:pic");
|
|
1819
|
+
xml += tag(
|
|
1820
|
+
"p:nvPicPr",
|
|
1821
|
+
void 0,
|
|
1822
|
+
tag("p:cNvPr", { id: "0", name: element.name ?? "Video" }) + tag("p:cNvPicPr", void 0, tag("a:picLocks", { noChangeAspect: "1" })) + tag("p:nvPr", void 0, tag("a:videoFile", { "r:link": rId }))
|
|
1823
|
+
);
|
|
1824
|
+
xml += tag(
|
|
1825
|
+
"p:blipFill",
|
|
1826
|
+
void 0,
|
|
1827
|
+
tag("a:blip", posterRId ? { "r:embed": posterRId } : void 0) + tag("a:stretch", void 0, tag("a:fillRect"))
|
|
1828
|
+
);
|
|
1829
|
+
xml += openTag("p:spPr");
|
|
1830
|
+
xml += serializeTransform(p, element.transform);
|
|
1831
|
+
xml += tag("a:prstGeom", { prst: "rect" }, tag("a:avLst"));
|
|
1832
|
+
if (element.effects) xml += serializeEffects(element.effects);
|
|
1833
|
+
xml += closeTag("p:spPr");
|
|
1834
|
+
xml += closeTag("p:pic");
|
|
1835
|
+
return xml;
|
|
1836
|
+
}
|
|
1837
|
+
};
|
|
1838
|
+
|
|
1839
|
+
// src/ooxml/serializers/group.ts
|
|
1840
|
+
function createGroupSerializer(registry) {
|
|
1841
|
+
return {
|
|
1842
|
+
type: "group",
|
|
1843
|
+
serialize(element, ctx) {
|
|
1844
|
+
const p = element.placement;
|
|
1845
|
+
let xml = openTag("p:grpSp");
|
|
1846
|
+
xml += tag(
|
|
1847
|
+
"p:nvGrpSpPr",
|
|
1848
|
+
void 0,
|
|
1849
|
+
tag("p:cNvPr", { id: "0", name: element.name ?? "" }) + tag("p:cNvGrpSpPr") + tag("p:nvPr")
|
|
1850
|
+
);
|
|
1851
|
+
xml += tag(
|
|
1852
|
+
"p:grpSpPr",
|
|
1853
|
+
void 0,
|
|
1854
|
+
tag(
|
|
1855
|
+
"a:xfrm",
|
|
1856
|
+
void 0,
|
|
1857
|
+
tag("a:off", { x: inchesToEmu(p.x), y: inchesToEmu(p.y) }) + tag("a:ext", { cx: inchesToEmu(p.w), cy: inchesToEmu(p.h) }) + tag("a:chOff", { x: inchesToEmu(p.x), y: inchesToEmu(p.y) }) + tag("a:chExt", { cx: inchesToEmu(p.w), cy: inchesToEmu(p.h) })
|
|
1858
|
+
)
|
|
1859
|
+
);
|
|
1860
|
+
for (const child of element.children) {
|
|
1861
|
+
const serializer = registry.getSerializer(child.type);
|
|
1862
|
+
if (serializer) {
|
|
1863
|
+
xml += serializer.serialize(child, ctx);
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
xml += closeTag("p:grpSp");
|
|
1867
|
+
return xml;
|
|
1868
|
+
}
|
|
1869
|
+
};
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
// src/ooxml/serializers/connector.ts
|
|
1873
|
+
var CONNECTOR_GEOM = {
|
|
1874
|
+
straight: "straightConnector1",
|
|
1875
|
+
elbow: "bentConnector3",
|
|
1876
|
+
curved: "curvedConnector3"
|
|
1877
|
+
};
|
|
1878
|
+
var connectorSerializer = {
|
|
1879
|
+
type: "connector",
|
|
1880
|
+
serialize(element, _ctx) {
|
|
1881
|
+
const p = element.placement;
|
|
1882
|
+
const prst = CONNECTOR_GEOM[element.connectorType] ?? "straightConnector1";
|
|
1883
|
+
let xml = openTag("p:cxnSp");
|
|
1884
|
+
xml += tag(
|
|
1885
|
+
"p:nvCxnSpPr",
|
|
1886
|
+
void 0,
|
|
1887
|
+
tag("p:cNvPr", { id: "0", name: element.name ?? "" }) + tag("p:cNvCxnSpPr") + tag("p:nvPr")
|
|
1888
|
+
);
|
|
1889
|
+
xml += openTag("p:spPr");
|
|
1890
|
+
xml += serializeTransform(p);
|
|
1891
|
+
xml += tag("a:prstGeom", { prst }, tag("a:avLst"));
|
|
1892
|
+
if (element.line) {
|
|
1893
|
+
xml += serializeLine(element.line);
|
|
1894
|
+
} else {
|
|
1895
|
+
let defaultLn = serializeSolidFill("000000");
|
|
1896
|
+
if (element.startArrow) {
|
|
1897
|
+
const hAttrs = {};
|
|
1898
|
+
if (element.startArrow.type) hAttrs.type = element.startArrow.type;
|
|
1899
|
+
if (element.startArrow.width) hAttrs.w = element.startArrow.width;
|
|
1900
|
+
if (element.startArrow.length) hAttrs.len = element.startArrow.length;
|
|
1901
|
+
defaultLn += tag("a:headEnd", hAttrs);
|
|
1902
|
+
}
|
|
1903
|
+
if (element.endArrow) {
|
|
1904
|
+
const tAttrs = {};
|
|
1905
|
+
if (element.endArrow.type) tAttrs.type = element.endArrow.type;
|
|
1906
|
+
if (element.endArrow.width) tAttrs.w = element.endArrow.width;
|
|
1907
|
+
if (element.endArrow.length) tAttrs.len = element.endArrow.length;
|
|
1908
|
+
defaultLn += tag("a:tailEnd", tAttrs);
|
|
1909
|
+
}
|
|
1910
|
+
xml += tag("a:ln", { w: "12700" }, defaultLn);
|
|
1911
|
+
}
|
|
1912
|
+
xml += closeTag("p:spPr");
|
|
1913
|
+
xml += closeTag("p:cxnSp");
|
|
1914
|
+
return xml;
|
|
1915
|
+
}
|
|
1916
|
+
};
|
|
1917
|
+
|
|
1918
|
+
// src/io/writer.ts
|
|
1919
|
+
import { zipSync } from "fflate";
|
|
1920
|
+
|
|
1921
|
+
// src/core/relationships.ts
|
|
1922
|
+
var RelationshipManager = class {
|
|
1923
|
+
counter = 0;
|
|
1924
|
+
rels = [];
|
|
1925
|
+
add(type, target, data, external) {
|
|
1926
|
+
this.counter++;
|
|
1927
|
+
const id = `rId${this.counter}`;
|
|
1928
|
+
this.rels.push({ id, type, target, data, external });
|
|
1929
|
+
return id;
|
|
1930
|
+
}
|
|
1931
|
+
getAll() {
|
|
1932
|
+
return this.rels;
|
|
1933
|
+
}
|
|
1934
|
+
toXml() {
|
|
1935
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
1936
|
+
xml += '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">';
|
|
1937
|
+
for (const rel of this.rels) {
|
|
1938
|
+
const attrs = {
|
|
1939
|
+
Id: rel.id,
|
|
1940
|
+
Type: rel.type,
|
|
1941
|
+
Target: rel.target
|
|
1942
|
+
};
|
|
1943
|
+
if (rel.external) {
|
|
1944
|
+
attrs.TargetMode = "External";
|
|
1945
|
+
}
|
|
1946
|
+
xml += tag("Relationship", attrs);
|
|
1947
|
+
}
|
|
1948
|
+
xml += "</Relationships>";
|
|
1949
|
+
return xml;
|
|
1950
|
+
}
|
|
1951
|
+
};
|
|
1952
|
+
|
|
1953
|
+
// src/ooxml/serializers/slide.ts
|
|
1954
|
+
function serializeTransition(t) {
|
|
1955
|
+
const attrs = {};
|
|
1956
|
+
if (t.durationMs !== void 0) {
|
|
1957
|
+
attrs.dur = t.durationMs;
|
|
1958
|
+
} else if (t.duration) {
|
|
1959
|
+
attrs.spd = t.duration <= 500 ? "fast" : t.duration <= 1500 ? "med" : "slow";
|
|
1960
|
+
}
|
|
1961
|
+
if (t.advanceOnClick === false) attrs.advClick = "0";
|
|
1962
|
+
if (t.advanceAfter !== void 0) {
|
|
1963
|
+
attrs.advTm = t.advanceAfter;
|
|
1964
|
+
}
|
|
1965
|
+
const type = t.type ?? "fade";
|
|
1966
|
+
let child = "";
|
|
1967
|
+
const transMap = {
|
|
1968
|
+
fade: "p:fade",
|
|
1969
|
+
push: "p:push",
|
|
1970
|
+
wipe: "p:wipe",
|
|
1971
|
+
split: "p:split",
|
|
1972
|
+
cover: "p:cover",
|
|
1973
|
+
uncover: "p:uncover",
|
|
1974
|
+
strips: "p:strips",
|
|
1975
|
+
blinds: "p:blinds",
|
|
1976
|
+
checker: "p:checker",
|
|
1977
|
+
dissolve: "p:dissolve",
|
|
1978
|
+
comb: "p:comb",
|
|
1979
|
+
newsflash: "p:newsflash",
|
|
1980
|
+
randomBars: "p:randomBar",
|
|
1981
|
+
circle: "p:circle",
|
|
1982
|
+
diamond: "p:diamond",
|
|
1983
|
+
plus: "p:plus",
|
|
1984
|
+
wedge: "p:wedge",
|
|
1985
|
+
wheel: "p:wheel",
|
|
1986
|
+
zoom: "p:zoom",
|
|
1987
|
+
cut: "p:cut",
|
|
1988
|
+
random: "p:random"
|
|
1989
|
+
};
|
|
1990
|
+
const elName = transMap[type];
|
|
1991
|
+
if (elName && type !== "none") {
|
|
1992
|
+
const dirAttrs = {};
|
|
1993
|
+
if (t.direction) dirAttrs.dir = t.direction;
|
|
1994
|
+
child = tag(elName, Object.keys(dirAttrs).length > 0 ? dirAttrs : void 0);
|
|
1995
|
+
}
|
|
1996
|
+
return tag("p:transition", attrs, child || void 0);
|
|
1997
|
+
}
|
|
1998
|
+
function serializeAnimations(animations) {
|
|
1999
|
+
let tnLstXml = "";
|
|
2000
|
+
for (let i = 0; i < animations.length; i++) {
|
|
2001
|
+
const anim = animations[i];
|
|
2002
|
+
const dur = anim.duration ?? 500;
|
|
2003
|
+
const delay = anim.delay ?? 0;
|
|
2004
|
+
const spTgtId = String(anim.elementIndex + 2);
|
|
2005
|
+
let nodeType;
|
|
2006
|
+
if (anim.trigger === "withPrevious") nodeType = "withEffect";
|
|
2007
|
+
else if (anim.trigger === "afterPrevious") nodeType = "afterEffect";
|
|
2008
|
+
else nodeType = "clickEffect";
|
|
2009
|
+
const cTnAttrs = {
|
|
2010
|
+
id: String((i + 1) * 10 + 1),
|
|
2011
|
+
dur: String(dur),
|
|
2012
|
+
fill: "hold"
|
|
2013
|
+
};
|
|
2014
|
+
if (anim.acceleration !== void 0) cTnAttrs.accel = Math.round(anim.acceleration * 1e3);
|
|
2015
|
+
if (anim.deceleration !== void 0) cTnAttrs.decel = Math.round(anim.deceleration * 1e3);
|
|
2016
|
+
const tgtEl = tag("p:tgtEl", void 0, tag("p:spTgt", { spid: spTgtId }));
|
|
2017
|
+
const stCond = tag("p:stCondLst", void 0, tag("p:cond", { delay: String(delay) }));
|
|
2018
|
+
let animEffect;
|
|
2019
|
+
if (anim.motionPath) {
|
|
2020
|
+
animEffect = tag(
|
|
2021
|
+
"p:animMotion",
|
|
2022
|
+
{ origin: "layout", path: anim.motionPath, pathEditMode: "relative" },
|
|
2023
|
+
tag("p:cBhvr", void 0, tag("p:cTn", cTnAttrs, stCond) + tgtEl)
|
|
2024
|
+
);
|
|
2025
|
+
} else if (anim.effect === "appear") {
|
|
2026
|
+
const setCTn = { ...cTnAttrs, dur: "1" };
|
|
2027
|
+
animEffect = tag(
|
|
2028
|
+
"p:set",
|
|
2029
|
+
void 0,
|
|
2030
|
+
tag("p:cBhvr", void 0, tag("p:cTn", setCTn, stCond) + tgtEl) + tag("p:to", void 0, tag("p:strVal", { val: "visible" }))
|
|
2031
|
+
);
|
|
2032
|
+
} else {
|
|
2033
|
+
animEffect = tag(
|
|
2034
|
+
"p:animEffect",
|
|
2035
|
+
{ transition: anim.category === "exit" ? "out" : "in", filter: anim.effect },
|
|
2036
|
+
tag("p:cBhvr", void 0, tag("p:cTn", cTnAttrs, stCond) + tgtEl)
|
|
2037
|
+
);
|
|
2038
|
+
}
|
|
2039
|
+
const childTnXml = tag(
|
|
2040
|
+
"p:par",
|
|
2041
|
+
void 0,
|
|
2042
|
+
tag(
|
|
2043
|
+
"p:cTn",
|
|
2044
|
+
{ id: String((i + 1) * 10), fill: "hold", nodeType },
|
|
2045
|
+
tag("p:stCondLst", void 0, tag("p:cond", { delay: "0" })) + tag("p:childTnLst", void 0, animEffect)
|
|
2046
|
+
)
|
|
2047
|
+
);
|
|
2048
|
+
tnLstXml += childTnXml;
|
|
2049
|
+
}
|
|
2050
|
+
const mainSeq = tag(
|
|
2051
|
+
"p:seq",
|
|
2052
|
+
{ concurrent: "1", nextAc: "seek" },
|
|
2053
|
+
tag(
|
|
2054
|
+
"p:cTn",
|
|
2055
|
+
{ id: "1", dur: "indefinite", nodeType: "mainSeq" },
|
|
2056
|
+
tag("p:childTnLst", void 0, tnLstXml)
|
|
2057
|
+
) + tag(
|
|
2058
|
+
"p:prevCondLst",
|
|
2059
|
+
void 0,
|
|
2060
|
+
tag("p:cond", { evt: "onPrev", delay: "0" }, tag("p:tgtEl", void 0, tag("p:sldTgt")))
|
|
2061
|
+
) + tag(
|
|
2062
|
+
"p:nextCondLst",
|
|
2063
|
+
void 0,
|
|
2064
|
+
tag("p:cond", { evt: "onNext", delay: "0" }, tag("p:tgtEl", void 0, tag("p:sldTgt")))
|
|
2065
|
+
)
|
|
2066
|
+
);
|
|
2067
|
+
return tag("p:timing", void 0, tag("p:tnLst", void 0, mainSeq));
|
|
2068
|
+
}
|
|
2069
|
+
function serializeSlide(elements, slideIndex, theme, registry, _layoutRId, transition, animations, background) {
|
|
2070
|
+
const relManager = new RelationshipManager();
|
|
2071
|
+
const media = /* @__PURE__ */ new Map();
|
|
2072
|
+
const mediaRels = [];
|
|
2073
|
+
relManager.add(
|
|
2074
|
+
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout",
|
|
2075
|
+
"../slideLayouts/slideLayout1.xml"
|
|
2076
|
+
);
|
|
2077
|
+
const ctx = {
|
|
2078
|
+
addRelationship(type, target, data) {
|
|
2079
|
+
const rId = relManager.add(type, target);
|
|
2080
|
+
mediaRels.push({ type, target });
|
|
2081
|
+
if (data) {
|
|
2082
|
+
const fileName = target.split("/").pop() ?? "file";
|
|
2083
|
+
if (target.includes("/charts/")) {
|
|
2084
|
+
media.set(`ppt/charts/${fileName}`, data);
|
|
2085
|
+
} else {
|
|
2086
|
+
media.set(`ppt/media/${fileName}`, data);
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
return rId;
|
|
2090
|
+
},
|
|
2091
|
+
theme,
|
|
2092
|
+
slideIndex
|
|
2093
|
+
};
|
|
2094
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
2095
|
+
xml += openTag("p:sld", {
|
|
2096
|
+
"xmlns:a": NAMESPACE.a,
|
|
2097
|
+
"xmlns:r": NAMESPACE.r,
|
|
2098
|
+
"xmlns:p": NAMESPACE.p
|
|
2099
|
+
});
|
|
2100
|
+
xml += openTag("p:cSld");
|
|
2101
|
+
if (background) {
|
|
2102
|
+
let bgXml = "";
|
|
2103
|
+
if (background.color) {
|
|
2104
|
+
bgXml = tag("p:bgPr", void 0, serializeSolidFill(background.color) + tag("a:effectLst"));
|
|
2105
|
+
} else if (background.fill) {
|
|
2106
|
+
bgXml = tag("p:bgPr", void 0, serializeFill(background.fill, ctx) + tag("a:effectLst"));
|
|
2107
|
+
}
|
|
2108
|
+
if (bgXml) xml += tag("p:bg", void 0, bgXml);
|
|
2109
|
+
}
|
|
2110
|
+
xml += openTag("p:spTree");
|
|
2111
|
+
xml += tag(
|
|
2112
|
+
"p:nvGrpSpPr",
|
|
2113
|
+
void 0,
|
|
2114
|
+
tag("p:cNvPr", { id: "1", name: "" }) + tag("p:cNvGrpSpPr") + tag("p:nvPr")
|
|
2115
|
+
);
|
|
2116
|
+
xml += tag(
|
|
2117
|
+
"p:grpSpPr",
|
|
2118
|
+
void 0,
|
|
2119
|
+
tag(
|
|
2120
|
+
"a:xfrm",
|
|
2121
|
+
void 0,
|
|
2122
|
+
tag("a:off", { x: "0", y: "0" }) + tag("a:ext", { cx: "0", cy: "0" }) + tag("a:chOff", { x: "0", y: "0" }) + tag("a:chExt", { cx: "0", cy: "0" })
|
|
2123
|
+
)
|
|
2124
|
+
);
|
|
2125
|
+
for (const el of elements) {
|
|
2126
|
+
const serializer = registry.getSerializer(el.type);
|
|
2127
|
+
if (!serializer) {
|
|
2128
|
+
throw new Error(`No serializer registered for element type: ${el.type}`);
|
|
2129
|
+
}
|
|
2130
|
+
xml += serializer.serialize(el, ctx);
|
|
2131
|
+
}
|
|
2132
|
+
xml += closeTag("p:spTree");
|
|
2133
|
+
xml += closeTag("p:cSld");
|
|
2134
|
+
if (transition) {
|
|
2135
|
+
xml += serializeTransition(transition);
|
|
2136
|
+
}
|
|
2137
|
+
if (animations && animations.length > 0) {
|
|
2138
|
+
xml += serializeAnimations(animations);
|
|
2139
|
+
}
|
|
2140
|
+
xml += closeTag("p:sld");
|
|
2141
|
+
return {
|
|
2142
|
+
slideXml: xml,
|
|
2143
|
+
relsXml: relManager.toXml(),
|
|
2144
|
+
media,
|
|
2145
|
+
mediaRels
|
|
2146
|
+
};
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
// src/ooxml/serializers/presentation.ts
|
|
2150
|
+
function serializePresentation(slideCount, slideRIds, slideSize) {
|
|
2151
|
+
const sldW = slideSize?.width ?? DEFAULT_SLIDE_WIDTH;
|
|
2152
|
+
const sldH = slideSize?.height ?? DEFAULT_SLIDE_HEIGHT;
|
|
2153
|
+
const sldType = slideSize?.type ?? "custom";
|
|
2154
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
2155
|
+
xml += openTag("p:presentation", {
|
|
2156
|
+
"xmlns:a": NAMESPACE.a,
|
|
2157
|
+
"xmlns:r": NAMESPACE.r,
|
|
2158
|
+
"xmlns:p": NAMESPACE.p,
|
|
2159
|
+
saveSubsetFonts: "1"
|
|
2160
|
+
});
|
|
2161
|
+
xml += tag(
|
|
2162
|
+
"p:sldMasterIdLst",
|
|
2163
|
+
void 0,
|
|
2164
|
+
tag("p:sldMasterId", { id: "2147483648", "r:id": "rId1" })
|
|
2165
|
+
);
|
|
2166
|
+
xml += openTag("p:sldIdLst");
|
|
2167
|
+
for (let i = 0; i < slideCount; i++) {
|
|
2168
|
+
xml += tag("p:sldId", { id: String(256 + i), "r:id": slideRIds[i] });
|
|
2169
|
+
}
|
|
2170
|
+
xml += closeTag("p:sldIdLst");
|
|
2171
|
+
xml += tag("p:sldSz", {
|
|
2172
|
+
cx: inchesToEmu(sldW),
|
|
2173
|
+
cy: inchesToEmu(sldH),
|
|
2174
|
+
type: sldType
|
|
2175
|
+
});
|
|
2176
|
+
xml += tag("p:notesSz", {
|
|
2177
|
+
cx: inchesToEmu(sldW),
|
|
2178
|
+
cy: inchesToEmu(sldH)
|
|
2179
|
+
});
|
|
2180
|
+
xml += closeTag("p:presentation");
|
|
2181
|
+
return xml;
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2184
|
+
// src/ooxml/serializers/theme.ts
|
|
2185
|
+
function serializeTheme(theme) {
|
|
2186
|
+
const c = theme.colors;
|
|
2187
|
+
const f = theme.fonts;
|
|
2188
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
2189
|
+
xml += openTag("a:theme", {
|
|
2190
|
+
"xmlns:a": NAMESPACE.a,
|
|
2191
|
+
name: theme.name
|
|
2192
|
+
});
|
|
2193
|
+
xml += openTag("a:themeElements");
|
|
2194
|
+
xml += openTag("a:clrScheme", { name: theme.name });
|
|
2195
|
+
const colorEntries = [
|
|
2196
|
+
["a:dk1", c.dk1],
|
|
2197
|
+
["a:lt1", c.lt1],
|
|
2198
|
+
["a:dk2", c.dk2],
|
|
2199
|
+
["a:lt2", c.lt2],
|
|
2200
|
+
["a:accent1", c.accent1],
|
|
2201
|
+
["a:accent2", c.accent2],
|
|
2202
|
+
["a:accent3", c.accent3],
|
|
2203
|
+
["a:accent4", c.accent4],
|
|
2204
|
+
["a:accent5", c.accent5],
|
|
2205
|
+
["a:accent6", c.accent6],
|
|
2206
|
+
["a:hlink", c.hlink],
|
|
2207
|
+
["a:folHlink", c.folHlink]
|
|
2208
|
+
];
|
|
2209
|
+
for (const [tagName, val] of colorEntries) {
|
|
2210
|
+
xml += tag(tagName, void 0, serializeColor(val));
|
|
2211
|
+
}
|
|
2212
|
+
xml += closeTag("a:clrScheme");
|
|
2213
|
+
xml += openTag("a:fontScheme", { name: theme.name });
|
|
2214
|
+
xml += tag(
|
|
2215
|
+
"a:majorFont",
|
|
2216
|
+
void 0,
|
|
2217
|
+
tag("a:latin", { typeface: f.majorFont }) + tag("a:ea", { typeface: f.majorEastAsian ?? "" }) + tag("a:cs", { typeface: f.majorComplexScript ?? "" })
|
|
2218
|
+
);
|
|
2219
|
+
xml += tag(
|
|
2220
|
+
"a:minorFont",
|
|
2221
|
+
void 0,
|
|
2222
|
+
tag("a:latin", { typeface: f.minorFont }) + tag("a:ea", { typeface: f.minorEastAsian ?? "" }) + tag("a:cs", { typeface: f.minorComplexScript ?? "" })
|
|
2223
|
+
);
|
|
2224
|
+
xml += closeTag("a:fontScheme");
|
|
2225
|
+
xml += openTag("a:fmtScheme", { name: theme.name });
|
|
2226
|
+
xml += tag(
|
|
2227
|
+
"a:fillStyleLst",
|
|
2228
|
+
void 0,
|
|
2229
|
+
tag("a:solidFill", void 0, tag("a:schemeClr", { val: "phClr" })) + tag("a:solidFill", void 0, tag("a:schemeClr", { val: "phClr" })) + tag("a:solidFill", void 0, tag("a:schemeClr", { val: "phClr" }))
|
|
2230
|
+
);
|
|
2231
|
+
xml += tag(
|
|
2232
|
+
"a:lnStyleLst",
|
|
2233
|
+
void 0,
|
|
2234
|
+
tag(
|
|
2235
|
+
"a:ln",
|
|
2236
|
+
{ w: "6350", cap: "flat", cmpd: "sng", algn: "ctr" },
|
|
2237
|
+
tag("a:solidFill", void 0, tag("a:schemeClr", { val: "phClr" }))
|
|
2238
|
+
) + tag(
|
|
2239
|
+
"a:ln",
|
|
2240
|
+
{ w: "12700", cap: "flat", cmpd: "sng", algn: "ctr" },
|
|
2241
|
+
tag("a:solidFill", void 0, tag("a:schemeClr", { val: "phClr" }))
|
|
2242
|
+
) + tag(
|
|
2243
|
+
"a:ln",
|
|
2244
|
+
{ w: "19050", cap: "flat", cmpd: "sng", algn: "ctr" },
|
|
2245
|
+
tag("a:solidFill", void 0, tag("a:schemeClr", { val: "phClr" }))
|
|
2246
|
+
)
|
|
2247
|
+
);
|
|
2248
|
+
xml += tag(
|
|
2249
|
+
"a:effectStyleLst",
|
|
2250
|
+
void 0,
|
|
2251
|
+
tag("a:effectStyle", void 0, tag("a:effectLst")) + tag("a:effectStyle", void 0, tag("a:effectLst")) + tag("a:effectStyle", void 0, tag("a:effectLst"))
|
|
2252
|
+
);
|
|
2253
|
+
xml += tag(
|
|
2254
|
+
"a:bgFillStyleLst",
|
|
2255
|
+
void 0,
|
|
2256
|
+
tag("a:solidFill", void 0, tag("a:schemeClr", { val: "phClr" })) + tag("a:solidFill", void 0, tag("a:schemeClr", { val: "phClr" })) + tag("a:solidFill", void 0, tag("a:schemeClr", { val: "phClr" }))
|
|
2257
|
+
);
|
|
2258
|
+
xml += closeTag("a:fmtScheme");
|
|
2259
|
+
xml += closeTag("a:themeElements");
|
|
2260
|
+
xml += tag("a:objectDefaults");
|
|
2261
|
+
if (theme.extraColorSchemes && theme.extraColorSchemes.length > 0) {
|
|
2262
|
+
let extraXml = "";
|
|
2263
|
+
for (let i = 0; i < theme.extraColorSchemes.length; i++) {
|
|
2264
|
+
const ec = theme.extraColorSchemes[i];
|
|
2265
|
+
let schemeXml = "";
|
|
2266
|
+
const extraEntries = [
|
|
2267
|
+
["a:dk1", ec.dk1],
|
|
2268
|
+
["a:lt1", ec.lt1],
|
|
2269
|
+
["a:dk2", ec.dk2],
|
|
2270
|
+
["a:lt2", ec.lt2],
|
|
2271
|
+
["a:accent1", ec.accent1],
|
|
2272
|
+
["a:accent2", ec.accent2],
|
|
2273
|
+
["a:accent3", ec.accent3],
|
|
2274
|
+
["a:accent4", ec.accent4],
|
|
2275
|
+
["a:accent5", ec.accent5],
|
|
2276
|
+
["a:accent6", ec.accent6],
|
|
2277
|
+
["a:hlink", ec.hlink],
|
|
2278
|
+
["a:folHlink", ec.folHlink]
|
|
2279
|
+
];
|
|
2280
|
+
for (const [tagName, val] of extraEntries) {
|
|
2281
|
+
schemeXml += tag(tagName, void 0, serializeColor(val));
|
|
2282
|
+
}
|
|
2283
|
+
extraXml += tag(
|
|
2284
|
+
"a:extraClrScheme",
|
|
2285
|
+
void 0,
|
|
2286
|
+
tag("a:clrScheme", { name: `Extra ${i + 1}` }, schemeXml)
|
|
2287
|
+
);
|
|
2288
|
+
}
|
|
2289
|
+
xml += tag("a:extraClrSchemeLst", void 0, extraXml);
|
|
2290
|
+
} else {
|
|
2291
|
+
xml += tag("a:extraClrSchemeLst");
|
|
2292
|
+
}
|
|
2293
|
+
xml += closeTag("a:theme");
|
|
2294
|
+
return xml;
|
|
2295
|
+
}
|
|
2296
|
+
|
|
2297
|
+
// src/ooxml/serializers/slide-master.ts
|
|
2298
|
+
function serializeSlideMaster(master, layoutCount) {
|
|
2299
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
2300
|
+
xml += openTag("p:sldMaster", {
|
|
2301
|
+
"xmlns:a": NAMESPACE.a,
|
|
2302
|
+
"xmlns:r": NAMESPACE.r,
|
|
2303
|
+
"xmlns:p": NAMESPACE.p
|
|
2304
|
+
});
|
|
2305
|
+
xml += openTag("p:cSld");
|
|
2306
|
+
if (master.background) {
|
|
2307
|
+
xml += tag(
|
|
2308
|
+
"p:bg",
|
|
2309
|
+
void 0,
|
|
2310
|
+
tag("p:bgPr", void 0, serializeSolidFill(master.background) + tag("a:effectLst"))
|
|
2311
|
+
);
|
|
2312
|
+
} else {
|
|
2313
|
+
xml += tag(
|
|
2314
|
+
"p:bg",
|
|
2315
|
+
void 0,
|
|
2316
|
+
tag("p:bgRef", { idx: "1001" }, tag("a:schemeClr", { val: "bg1" }))
|
|
2317
|
+
);
|
|
2318
|
+
}
|
|
2319
|
+
xml += openTag("p:spTree");
|
|
2320
|
+
xml += tag(
|
|
2321
|
+
"p:nvGrpSpPr",
|
|
2322
|
+
void 0,
|
|
2323
|
+
tag("p:cNvPr", { id: "1", name: "" }) + tag("p:cNvGrpSpPr") + tag("p:nvPr")
|
|
2324
|
+
);
|
|
2325
|
+
xml += tag(
|
|
2326
|
+
"p:grpSpPr",
|
|
2327
|
+
void 0,
|
|
2328
|
+
tag(
|
|
2329
|
+
"a:xfrm",
|
|
2330
|
+
void 0,
|
|
2331
|
+
tag("a:off", { x: "0", y: "0" }) + tag("a:ext", { cx: "0", cy: "0" }) + tag("a:chOff", { x: "0", y: "0" }) + tag("a:chExt", { cx: "0", cy: "0" })
|
|
2332
|
+
)
|
|
2333
|
+
);
|
|
2334
|
+
xml += closeTag("p:spTree");
|
|
2335
|
+
xml += closeTag("p:cSld");
|
|
2336
|
+
xml += openTag("p:clrMap", {
|
|
2337
|
+
bg1: "lt1",
|
|
2338
|
+
tx1: "dk1",
|
|
2339
|
+
bg2: "lt2",
|
|
2340
|
+
tx2: "dk2",
|
|
2341
|
+
accent1: "accent1",
|
|
2342
|
+
accent2: "accent2",
|
|
2343
|
+
accent3: "accent3",
|
|
2344
|
+
accent4: "accent4",
|
|
2345
|
+
accent5: "accent5",
|
|
2346
|
+
accent6: "accent6",
|
|
2347
|
+
hlink: "hlink",
|
|
2348
|
+
folHlink: "folHlink"
|
|
2349
|
+
});
|
|
2350
|
+
xml += closeTag("p:clrMap");
|
|
2351
|
+
xml += openTag("p:sldLayoutIdLst");
|
|
2352
|
+
for (let i = 0; i < layoutCount; i++) {
|
|
2353
|
+
xml += tag("p:sldLayoutId", { id: String(2147483649 + i), "r:id": `rId${i + 1}` });
|
|
2354
|
+
}
|
|
2355
|
+
xml += closeTag("p:sldLayoutIdLst");
|
|
2356
|
+
xml += closeTag("p:sldMaster");
|
|
2357
|
+
return xml;
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
// src/ooxml/serializers/slide-layout.ts
|
|
2361
|
+
function serializeSlideLayout(layout) {
|
|
2362
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
2363
|
+
xml += openTag("p:sldLayout", {
|
|
2364
|
+
"xmlns:a": NAMESPACE.a,
|
|
2365
|
+
"xmlns:r": NAMESPACE.r,
|
|
2366
|
+
"xmlns:p": NAMESPACE.p,
|
|
2367
|
+
type: layout.type === "title" ? "title" : layout.type === "blank" ? "blank" : "obj",
|
|
2368
|
+
preserve: "1"
|
|
2369
|
+
});
|
|
2370
|
+
xml += openTag("p:cSld", { name: layout.name });
|
|
2371
|
+
xml += openTag("p:spTree");
|
|
2372
|
+
xml += tag(
|
|
2373
|
+
"p:nvGrpSpPr",
|
|
2374
|
+
void 0,
|
|
2375
|
+
tag("p:cNvPr", { id: "1", name: "" }) + tag("p:cNvGrpSpPr") + tag("p:nvPr")
|
|
2376
|
+
);
|
|
2377
|
+
xml += tag(
|
|
2378
|
+
"p:grpSpPr",
|
|
2379
|
+
void 0,
|
|
2380
|
+
tag(
|
|
2381
|
+
"a:xfrm",
|
|
2382
|
+
void 0,
|
|
2383
|
+
tag("a:off", { x: "0", y: "0" }) + tag("a:ext", { cx: "0", cy: "0" }) + tag("a:chOff", { x: "0", y: "0" }) + tag("a:chExt", { cx: "0", cy: "0" })
|
|
2384
|
+
)
|
|
2385
|
+
);
|
|
2386
|
+
let spId = 2;
|
|
2387
|
+
for (const ph of layout.placeholders) {
|
|
2388
|
+
const p = ph.placement;
|
|
2389
|
+
xml += openTag("p:sp");
|
|
2390
|
+
xml += tag(
|
|
2391
|
+
"p:nvSpPr",
|
|
2392
|
+
void 0,
|
|
2393
|
+
tag("p:cNvPr", { id: String(spId), name: `${ph.type} ${ph.idx ?? spId}` }) + tag("p:cNvSpPr", void 0, tag("a:spLocks", { noGrp: "1" })) + tag(
|
|
2394
|
+
"p:nvPr",
|
|
2395
|
+
void 0,
|
|
2396
|
+
tag("p:ph", {
|
|
2397
|
+
type: ph.type,
|
|
2398
|
+
...ph.idx !== void 0 ? { idx: String(ph.idx) } : {}
|
|
2399
|
+
})
|
|
2400
|
+
)
|
|
2401
|
+
);
|
|
2402
|
+
xml += tag(
|
|
2403
|
+
"p:spPr",
|
|
2404
|
+
void 0,
|
|
2405
|
+
tag(
|
|
2406
|
+
"a:xfrm",
|
|
2407
|
+
void 0,
|
|
2408
|
+
tag("a:off", { x: inchesToEmu(p.x), y: inchesToEmu(p.y) }) + tag("a:ext", { cx: inchesToEmu(p.w), cy: inchesToEmu(p.h) })
|
|
2409
|
+
)
|
|
2410
|
+
);
|
|
2411
|
+
xml += closeTag("p:sp");
|
|
2412
|
+
spId++;
|
|
2413
|
+
}
|
|
2414
|
+
xml += closeTag("p:spTree");
|
|
2415
|
+
xml += closeTag("p:cSld");
|
|
2416
|
+
xml += closeTag("p:sldLayout");
|
|
2417
|
+
return xml;
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
// src/core/content-types.ts
|
|
2421
|
+
var ContentTypesBuilder = class {
|
|
2422
|
+
defaults = /* @__PURE__ */ new Map();
|
|
2423
|
+
overrides = /* @__PURE__ */ new Map();
|
|
2424
|
+
addDefault(extension, contentType) {
|
|
2425
|
+
this.defaults.set(extension, contentType);
|
|
2426
|
+
}
|
|
2427
|
+
addOverride(partName, contentType) {
|
|
2428
|
+
this.overrides.set(partName, contentType);
|
|
2429
|
+
}
|
|
2430
|
+
toXml() {
|
|
2431
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
2432
|
+
xml += '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">';
|
|
2433
|
+
for (const [ext, ct] of this.defaults) {
|
|
2434
|
+
xml += tag("Default", { Extension: ext, ContentType: ct });
|
|
2435
|
+
}
|
|
2436
|
+
for (const [pn, ct] of this.overrides) {
|
|
2437
|
+
xml += tag("Override", { PartName: pn, ContentType: ct });
|
|
2438
|
+
}
|
|
2439
|
+
xml += "</Types>";
|
|
2440
|
+
return xml;
|
|
2441
|
+
}
|
|
2442
|
+
};
|
|
2443
|
+
|
|
2444
|
+
// src/ooxml/serializers/content-types.ts
|
|
2445
|
+
function buildContentTypes(opts) {
|
|
2446
|
+
const { slideCount, imageExtensions, chartCount, notesCount, layoutCount } = opts;
|
|
2447
|
+
const ct = new ContentTypesBuilder();
|
|
2448
|
+
ct.addDefault("rels", CONTENT_TYPE.rels);
|
|
2449
|
+
ct.addDefault("xml", "application/xml");
|
|
2450
|
+
for (const ext of imageExtensions) {
|
|
2451
|
+
const map = {
|
|
2452
|
+
png: CONTENT_TYPE.png,
|
|
2453
|
+
jpeg: CONTENT_TYPE.jpeg,
|
|
2454
|
+
jpg: CONTENT_TYPE.jpeg,
|
|
2455
|
+
gif: CONTENT_TYPE.gif,
|
|
2456
|
+
svg: CONTENT_TYPE.svg
|
|
2457
|
+
};
|
|
2458
|
+
if (map[ext]) ct.addDefault(ext, map[ext]);
|
|
2459
|
+
}
|
|
2460
|
+
ct.addOverride("/ppt/presentation.xml", CONTENT_TYPE.presentation);
|
|
2461
|
+
ct.addOverride("/ppt/theme/theme1.xml", CONTENT_TYPE.theme);
|
|
2462
|
+
ct.addOverride("/ppt/slideMasters/slideMaster1.xml", CONTENT_TYPE.slideMaster);
|
|
2463
|
+
ct.addOverride("/ppt/presProps.xml", CONTENT_TYPE.presProps);
|
|
2464
|
+
ct.addOverride("/ppt/viewProps.xml", CONTENT_TYPE.viewProps);
|
|
2465
|
+
for (let i = 1; i <= layoutCount; i++) {
|
|
2466
|
+
ct.addOverride(`/ppt/slideLayouts/slideLayout${i}.xml`, CONTENT_TYPE.slideLayout);
|
|
2467
|
+
}
|
|
2468
|
+
for (let i = 1; i <= slideCount; i++) {
|
|
2469
|
+
ct.addOverride(`/ppt/slides/slide${i}.xml`, CONTENT_TYPE.slide);
|
|
2470
|
+
}
|
|
2471
|
+
for (let i = 1; i <= chartCount; i++) {
|
|
2472
|
+
ct.addOverride(
|
|
2473
|
+
`/ppt/charts/chart${i}.xml`,
|
|
2474
|
+
"application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
|
|
2475
|
+
);
|
|
2476
|
+
}
|
|
2477
|
+
for (let i = 1; i <= notesCount; i++) {
|
|
2478
|
+
ct.addOverride(`/ppt/notesSlides/notesSlide${i}.xml`, CONTENT_TYPE.notesSlide);
|
|
2479
|
+
}
|
|
2480
|
+
if (opts.hasNotesMaster) {
|
|
2481
|
+
ct.addOverride("/ppt/notesMasters/notesMaster1.xml", CONTENT_TYPE.notesMaster);
|
|
2482
|
+
}
|
|
2483
|
+
if (opts.hasHandoutMaster) {
|
|
2484
|
+
ct.addOverride("/ppt/handoutMasters/handoutMaster1.xml", CONTENT_TYPE.handoutMaster);
|
|
2485
|
+
}
|
|
2486
|
+
if (opts.hasCommentAuthors) {
|
|
2487
|
+
ct.addOverride("/ppt/commentAuthors.xml", CONTENT_TYPE.commentAuthors);
|
|
2488
|
+
}
|
|
2489
|
+
const commentCount = opts.commentCount ?? 0;
|
|
2490
|
+
for (let i = 1; i <= commentCount; i++) {
|
|
2491
|
+
ct.addOverride(`/ppt/comments/comment${i}.xml`, CONTENT_TYPE.comments);
|
|
2492
|
+
}
|
|
2493
|
+
const tagCount = opts.tagCount ?? 0;
|
|
2494
|
+
for (let i = 1; i <= tagCount; i++) {
|
|
2495
|
+
ct.addOverride(`/ppt/tags/tag${i}.xml`, CONTENT_TYPE.tags);
|
|
2496
|
+
}
|
|
2497
|
+
const syncDataCount = opts.syncDataCount ?? 0;
|
|
2498
|
+
for (let i = 1; i <= syncDataCount; i++) {
|
|
2499
|
+
ct.addOverride(`/ppt/slideUpdateInfo/slideUpdateInfo${i}.xml`, CONTENT_TYPE.slideUpdateInfo);
|
|
2500
|
+
}
|
|
2501
|
+
return ct.toXml();
|
|
2502
|
+
}
|
|
2503
|
+
|
|
2504
|
+
// src/ooxml/serializers/notes.ts
|
|
2505
|
+
function serializeNotesSlide(notes) {
|
|
2506
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
2507
|
+
xml += openTag("p:notes", {
|
|
2508
|
+
"xmlns:a": NAMESPACE.a,
|
|
2509
|
+
"xmlns:r": NAMESPACE.r,
|
|
2510
|
+
"xmlns:p": NAMESPACE.p
|
|
2511
|
+
});
|
|
2512
|
+
xml += openTag("p:cSld");
|
|
2513
|
+
xml += openTag("p:spTree");
|
|
2514
|
+
xml += tag(
|
|
2515
|
+
"p:nvGrpSpPr",
|
|
2516
|
+
void 0,
|
|
2517
|
+
tag("p:cNvPr", { id: "1", name: "" }) + tag("p:cNvGrpSpPr") + tag("p:nvPr")
|
|
2518
|
+
);
|
|
2519
|
+
xml += tag(
|
|
2520
|
+
"p:grpSpPr",
|
|
2521
|
+
void 0,
|
|
2522
|
+
tag(
|
|
2523
|
+
"a:xfrm",
|
|
2524
|
+
void 0,
|
|
2525
|
+
tag("a:off", { x: "0", y: "0" }) + tag("a:ext", { cx: "0", cy: "0" }) + tag("a:chOff", { x: "0", y: "0" }) + tag("a:chExt", { cx: "0", cy: "0" })
|
|
2526
|
+
)
|
|
2527
|
+
);
|
|
2528
|
+
xml += openTag("p:sp");
|
|
2529
|
+
xml += tag(
|
|
2530
|
+
"p:nvSpPr",
|
|
2531
|
+
void 0,
|
|
2532
|
+
tag("p:cNvPr", { id: "2", name: "Slide Image Placeholder" }) + tag(
|
|
2533
|
+
"p:cNvSpPr",
|
|
2534
|
+
void 0,
|
|
2535
|
+
tag("a:spLocks", { noGrp: "1", noRot: "1", noChangeAspect: "1" })
|
|
2536
|
+
) + tag("p:nvPr", void 0, tag("p:ph", { type: "sldImg" }))
|
|
2537
|
+
);
|
|
2538
|
+
xml += tag("p:spPr");
|
|
2539
|
+
xml += closeTag("p:sp");
|
|
2540
|
+
xml += openTag("p:sp");
|
|
2541
|
+
xml += tag(
|
|
2542
|
+
"p:nvSpPr",
|
|
2543
|
+
void 0,
|
|
2544
|
+
tag("p:cNvPr", { id: "3", name: "Notes Placeholder" }) + tag("p:cNvSpPr", void 0, tag("a:spLocks", { noGrp: "1" })) + tag("p:nvPr", void 0, tag("p:ph", { type: "body", idx: "1" }))
|
|
2545
|
+
);
|
|
2546
|
+
xml += tag("p:spPr");
|
|
2547
|
+
xml += openTag("p:txBody");
|
|
2548
|
+
xml += tag("a:bodyPr");
|
|
2549
|
+
xml += tag("a:lstStyle");
|
|
2550
|
+
const lines = notes.split("\n");
|
|
2551
|
+
for (const line of lines) {
|
|
2552
|
+
xml += tag(
|
|
2553
|
+
"a:p",
|
|
2554
|
+
void 0,
|
|
2555
|
+
tag(
|
|
2556
|
+
"a:r",
|
|
2557
|
+
void 0,
|
|
2558
|
+
tag("a:rPr", { lang: "en-US" }) + tag("a:t", void 0, escapeXml(line))
|
|
2559
|
+
)
|
|
2560
|
+
);
|
|
2561
|
+
}
|
|
2562
|
+
xml += closeTag("p:txBody");
|
|
2563
|
+
xml += closeTag("p:sp");
|
|
2564
|
+
xml += closeTag("p:spTree");
|
|
2565
|
+
xml += closeTag("p:cSld");
|
|
2566
|
+
xml += closeTag("p:notes");
|
|
2567
|
+
return xml;
|
|
2568
|
+
}
|
|
2569
|
+
|
|
2570
|
+
// src/ooxml/serializers/pres-props.ts
|
|
2571
|
+
function serializePresProps(props) {
|
|
2572
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
2573
|
+
xml += openTag("p:presentationPr", {
|
|
2574
|
+
"xmlns:a": NAMESPACE.a,
|
|
2575
|
+
"xmlns:r": NAMESPACE.r,
|
|
2576
|
+
"xmlns:p": NAMESPACE.p
|
|
2577
|
+
});
|
|
2578
|
+
if (props?.slideShow) {
|
|
2579
|
+
const s = props.slideShow;
|
|
2580
|
+
const attrs = {};
|
|
2581
|
+
if (s.loop != null) attrs.loop = s.loop ? "1" : "0";
|
|
2582
|
+
if (s.showNarration != null) attrs.showNarration = s.showNarration ? "1" : "0";
|
|
2583
|
+
if (s.showAnimation != null) attrs.showAnimation = s.showAnimation ? "1" : "0";
|
|
2584
|
+
if (s.useTimings != null) attrs.useTimings = s.useTimings ? "1" : "0";
|
|
2585
|
+
xml += tag("p:showPr", attrs);
|
|
2586
|
+
}
|
|
2587
|
+
if (props?.print) {
|
|
2588
|
+
const p = props.print;
|
|
2589
|
+
const attrs = {};
|
|
2590
|
+
if (p.frameSlides != null) attrs.frameSlides = p.frameSlides ? "1" : "0";
|
|
2591
|
+
if (p.hiddenSlides != null) attrs.prnWhat = p.hiddenSlides ? "slides" : "slides";
|
|
2592
|
+
xml += tag("p:prnPr", attrs);
|
|
2593
|
+
}
|
|
2594
|
+
xml += closeTag("p:presentationPr");
|
|
2595
|
+
return xml;
|
|
2596
|
+
}
|
|
2597
|
+
|
|
2598
|
+
// src/ooxml/serializers/view-props.ts
|
|
2599
|
+
function serializeViewProps(props) {
|
|
2600
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
2601
|
+
const attrs = {
|
|
2602
|
+
"xmlns:a": NAMESPACE.a,
|
|
2603
|
+
"xmlns:r": NAMESPACE.r,
|
|
2604
|
+
"xmlns:p": NAMESPACE.p
|
|
2605
|
+
};
|
|
2606
|
+
if (props?.lastView) {
|
|
2607
|
+
attrs.lastView = props.lastView;
|
|
2608
|
+
}
|
|
2609
|
+
xml += openTag("p:viewPr", attrs);
|
|
2610
|
+
xml += closeTag("p:viewPr");
|
|
2611
|
+
return xml;
|
|
2612
|
+
}
|
|
2613
|
+
|
|
2614
|
+
// src/ooxml/serializers/notes-master.ts
|
|
2615
|
+
function serializeNotesMaster() {
|
|
2616
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
2617
|
+
xml += openTag("p:notesMaster", {
|
|
2618
|
+
"xmlns:a": NAMESPACE.a,
|
|
2619
|
+
"xmlns:r": NAMESPACE.r,
|
|
2620
|
+
"xmlns:p": NAMESPACE.p
|
|
2621
|
+
});
|
|
2622
|
+
xml += openTag("p:cSld");
|
|
2623
|
+
xml += openTag("p:spTree");
|
|
2624
|
+
xml += tag(
|
|
2625
|
+
"p:nvGrpSpPr",
|
|
2626
|
+
void 0,
|
|
2627
|
+
tag("p:cNvPr", { id: "1", name: "" }) + tag("p:cNvGrpSpPr") + tag("p:nvPr")
|
|
2628
|
+
);
|
|
2629
|
+
xml += tag(
|
|
2630
|
+
"p:grpSpPr",
|
|
2631
|
+
void 0,
|
|
2632
|
+
tag(
|
|
2633
|
+
"a:xfrm",
|
|
2634
|
+
void 0,
|
|
2635
|
+
tag("a:off", { x: "0", y: "0" }) + tag("a:ext", { cx: "0", cy: "0" }) + tag("a:chOff", { x: "0", y: "0" }) + tag("a:chExt", { cx: "0", cy: "0" })
|
|
2636
|
+
)
|
|
2637
|
+
);
|
|
2638
|
+
xml += closeTag("p:spTree");
|
|
2639
|
+
xml += closeTag("p:cSld");
|
|
2640
|
+
xml += tag("p:clrMap", {
|
|
2641
|
+
bg1: "lt1",
|
|
2642
|
+
tx1: "dk1",
|
|
2643
|
+
bg2: "lt2",
|
|
2644
|
+
tx2: "dk2",
|
|
2645
|
+
accent1: "accent1",
|
|
2646
|
+
accent2: "accent2",
|
|
2647
|
+
accent3: "accent3",
|
|
2648
|
+
accent4: "accent4",
|
|
2649
|
+
accent5: "accent5",
|
|
2650
|
+
accent6: "accent6",
|
|
2651
|
+
hlink: "hlink",
|
|
2652
|
+
folHlink: "folHlink"
|
|
2653
|
+
});
|
|
2654
|
+
xml += closeTag("p:notesMaster");
|
|
2655
|
+
return xml;
|
|
2656
|
+
}
|
|
2657
|
+
|
|
2658
|
+
// src/ooxml/serializers/comment-authors.ts
|
|
2659
|
+
function serializeCommentAuthors(authors) {
|
|
2660
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
2661
|
+
xml += openTag("p:cmAuthorLst", {
|
|
2662
|
+
"xmlns:a": NAMESPACE.a,
|
|
2663
|
+
"xmlns:r": NAMESPACE.r,
|
|
2664
|
+
"xmlns:p": NAMESPACE.p
|
|
2665
|
+
});
|
|
2666
|
+
for (const author of authors) {
|
|
2667
|
+
xml += tag("p:cmAuthor", {
|
|
2668
|
+
id: String(author.id),
|
|
2669
|
+
name: author.name,
|
|
2670
|
+
initials: author.initials,
|
|
2671
|
+
lastIdx: String(author.lastIdx),
|
|
2672
|
+
clrIdx: String(author.clrIdx)
|
|
2673
|
+
});
|
|
2674
|
+
}
|
|
2675
|
+
xml += closeTag("p:cmAuthorLst");
|
|
2676
|
+
return xml;
|
|
2677
|
+
}
|
|
2678
|
+
|
|
2679
|
+
// src/ooxml/serializers/comments.ts
|
|
2680
|
+
function serializeComments(comments) {
|
|
2681
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
2682
|
+
xml += openTag("p:cmLst", {
|
|
2683
|
+
"xmlns:a": NAMESPACE.a,
|
|
2684
|
+
"xmlns:r": NAMESPACE.r,
|
|
2685
|
+
"xmlns:p": NAMESPACE.p
|
|
2686
|
+
});
|
|
2687
|
+
for (const comment of comments) {
|
|
2688
|
+
const attrs = {
|
|
2689
|
+
authorId: String(comment.authorId),
|
|
2690
|
+
idx: String(comment.index ?? 1)
|
|
2691
|
+
};
|
|
2692
|
+
if (comment.date) {
|
|
2693
|
+
attrs.dt = comment.date;
|
|
2694
|
+
}
|
|
2695
|
+
let body = "";
|
|
2696
|
+
if (comment.position) {
|
|
2697
|
+
body += tag("p:pos", {
|
|
2698
|
+
x: String(inchesToEmu(comment.position.x)),
|
|
2699
|
+
y: String(inchesToEmu(comment.position.y))
|
|
2700
|
+
});
|
|
2701
|
+
} else {
|
|
2702
|
+
body += tag("p:pos", { x: "0", y: "0" });
|
|
2703
|
+
}
|
|
2704
|
+
body += tag("p:text", void 0, comment.text);
|
|
2705
|
+
xml += tag("p:cm", attrs, body);
|
|
2706
|
+
}
|
|
2707
|
+
xml += closeTag("p:cmLst");
|
|
2708
|
+
return xml;
|
|
2709
|
+
}
|
|
2710
|
+
|
|
2711
|
+
// src/ooxml/serializers/handout-master.ts
|
|
2712
|
+
function serializeHandoutMaster() {
|
|
2713
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
2714
|
+
xml += openTag("p:handoutMaster", {
|
|
2715
|
+
"xmlns:a": NAMESPACE.a,
|
|
2716
|
+
"xmlns:r": NAMESPACE.r,
|
|
2717
|
+
"xmlns:p": NAMESPACE.p
|
|
2718
|
+
});
|
|
2719
|
+
xml += openTag("p:cSld");
|
|
2720
|
+
xml += openTag("p:spTree");
|
|
2721
|
+
xml += tag(
|
|
2722
|
+
"p:nvGrpSpPr",
|
|
2723
|
+
void 0,
|
|
2724
|
+
tag("p:cNvPr", { id: "1", name: "" }) + tag("p:cNvGrpSpPr") + tag("p:nvPr")
|
|
2725
|
+
);
|
|
2726
|
+
xml += tag(
|
|
2727
|
+
"p:grpSpPr",
|
|
2728
|
+
void 0,
|
|
2729
|
+
tag(
|
|
2730
|
+
"a:xfrm",
|
|
2731
|
+
void 0,
|
|
2732
|
+
tag("a:off", { x: "0", y: "0" }) + tag("a:ext", { cx: "0", cy: "0" }) + tag("a:chOff", { x: "0", y: "0" }) + tag("a:chExt", { cx: "0", cy: "0" })
|
|
2733
|
+
)
|
|
2734
|
+
);
|
|
2735
|
+
xml += closeTag("p:spTree");
|
|
2736
|
+
xml += closeTag("p:cSld");
|
|
2737
|
+
xml += tag("p:clrMap", {
|
|
2738
|
+
bg1: "lt1",
|
|
2739
|
+
tx1: "dk1",
|
|
2740
|
+
bg2: "lt2",
|
|
2741
|
+
tx2: "dk2",
|
|
2742
|
+
accent1: "accent1",
|
|
2743
|
+
accent2: "accent2",
|
|
2744
|
+
accent3: "accent3",
|
|
2745
|
+
accent4: "accent4",
|
|
2746
|
+
accent5: "accent5",
|
|
2747
|
+
accent6: "accent6",
|
|
2748
|
+
hlink: "hlink",
|
|
2749
|
+
folHlink: "folHlink"
|
|
2750
|
+
});
|
|
2751
|
+
xml += closeTag("p:handoutMaster");
|
|
2752
|
+
return xml;
|
|
2753
|
+
}
|
|
2754
|
+
|
|
2755
|
+
// src/ooxml/serializers/tags.ts
|
|
2756
|
+
function serializeTags(tags) {
|
|
2757
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
2758
|
+
xml += openTag("p:tagLst", {
|
|
2759
|
+
"xmlns:a": NAMESPACE.a,
|
|
2760
|
+
"xmlns:r": NAMESPACE.r,
|
|
2761
|
+
"xmlns:p": NAMESPACE.p
|
|
2762
|
+
});
|
|
2763
|
+
for (const t of tags) {
|
|
2764
|
+
xml += tag("p:tag", { name: t.name, val: t.value });
|
|
2765
|
+
}
|
|
2766
|
+
xml += closeTag("p:tagLst");
|
|
2767
|
+
return xml;
|
|
2768
|
+
}
|
|
2769
|
+
|
|
2770
|
+
// src/ooxml/serializers/slide-update-info.ts
|
|
2771
|
+
function serializeSlideUpdateInfo(data) {
|
|
2772
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
2773
|
+
xml += openTag("p:sldSyncPr", {
|
|
2774
|
+
"xmlns:a": NAMESPACE.a,
|
|
2775
|
+
"xmlns:r": NAMESPACE.r,
|
|
2776
|
+
"xmlns:p": NAMESPACE.p,
|
|
2777
|
+
serverSldId: data.serverSldId,
|
|
2778
|
+
serverSldModifiedTime: data.serverSldModifiedTime,
|
|
2779
|
+
clientInsertedTime: data.clientInsertedTime
|
|
2780
|
+
});
|
|
2781
|
+
xml += closeTag("p:sldSyncPr");
|
|
2782
|
+
return xml;
|
|
2783
|
+
}
|
|
2784
|
+
|
|
2785
|
+
// src/ooxml/serializers/core-props.ts
|
|
2786
|
+
function serializeCoreProperties(props) {
|
|
2787
|
+
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
2788
|
+
xml += openTag("cp:coreProperties", {
|
|
2789
|
+
"xmlns:cp": "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
|
|
2790
|
+
"xmlns:dc": "http://purl.org/dc/elements/1.1/",
|
|
2791
|
+
"xmlns:dcterms": "http://purl.org/dc/terms/",
|
|
2792
|
+
"xmlns:dcmitype": "http://purl.org/dc/dcmitype/",
|
|
2793
|
+
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance"
|
|
2794
|
+
});
|
|
2795
|
+
if (props.title) xml += tag("dc:title", void 0, props.title);
|
|
2796
|
+
if (props.creator) xml += tag("dc:creator", void 0, props.creator);
|
|
2797
|
+
if (props.subject) xml += tag("dc:subject", void 0, props.subject);
|
|
2798
|
+
if (props.description) xml += tag("dc:description", void 0, props.description);
|
|
2799
|
+
if (props.keywords) xml += tag("cp:keywords", void 0, props.keywords);
|
|
2800
|
+
if (props.category) xml += tag("cp:category", void 0, props.category);
|
|
2801
|
+
xml += closeTag("cp:coreProperties");
|
|
2802
|
+
return xml;
|
|
2803
|
+
}
|
|
2804
|
+
|
|
2805
|
+
// src/io/writer.ts
|
|
2806
|
+
var encoder = new TextEncoder();
|
|
2807
|
+
function writePresentation(input) {
|
|
2808
|
+
const { slides, theme, registry, masters, layouts } = input;
|
|
2809
|
+
const files = {};
|
|
2810
|
+
const allMedia = /* @__PURE__ */ new Map();
|
|
2811
|
+
const imageExtensions = /* @__PURE__ */ new Set();
|
|
2812
|
+
const presRels = new RelationshipManager();
|
|
2813
|
+
presRels.add(REL_TYPE.slideMaster, "slideMasters/slideMaster1.xml");
|
|
2814
|
+
presRels.add(REL_TYPE.theme, "theme/theme1.xml");
|
|
2815
|
+
const slideRIds = [];
|
|
2816
|
+
for (let i = 0; i < slides.length; i++) {
|
|
2817
|
+
const rId = presRels.add(REL_TYPE.slide, `slides/slide${i + 1}.xml`);
|
|
2818
|
+
slideRIds.push(rId);
|
|
2819
|
+
}
|
|
2820
|
+
presRels.add(REL_TYPE.presProps, "presProps.xml");
|
|
2821
|
+
files["ppt/presProps.xml"] = encoder.encode(serializePresProps(input.presProps));
|
|
2822
|
+
presRels.add(REL_TYPE.viewProps, "viewProps.xml");
|
|
2823
|
+
files["ppt/viewProps.xml"] = encoder.encode(serializeViewProps(input.viewProps));
|
|
2824
|
+
let chartCount = 0;
|
|
2825
|
+
let notesCount = 0;
|
|
2826
|
+
let commentCount = 0;
|
|
2827
|
+
let tagCount = 0;
|
|
2828
|
+
const hasNotes = slides.some((s) => s.notes);
|
|
2829
|
+
const hasComments = input.commentAuthors && input.commentAuthors.length > 0 && slides.some((s) => s.comments?.length);
|
|
2830
|
+
if (hasNotes) {
|
|
2831
|
+
presRels.add(REL_TYPE.notesMaster, "notesMasters/notesMaster1.xml");
|
|
2832
|
+
files["ppt/notesMasters/notesMaster1.xml"] = encoder.encode(serializeNotesMaster());
|
|
2833
|
+
const notesMasterRels = new RelationshipManager();
|
|
2834
|
+
notesMasterRels.add(REL_TYPE.theme, "../theme/theme1.xml");
|
|
2835
|
+
files["ppt/notesMasters/_rels/notesMaster1.xml.rels"] = encoder.encode(notesMasterRels.toXml());
|
|
2836
|
+
}
|
|
2837
|
+
if (input.handoutMaster) {
|
|
2838
|
+
presRels.add(REL_TYPE.handoutMaster, "handoutMasters/handoutMaster1.xml");
|
|
2839
|
+
files["ppt/handoutMasters/handoutMaster1.xml"] = encoder.encode(serializeHandoutMaster());
|
|
2840
|
+
const handoutMasterRels = new RelationshipManager();
|
|
2841
|
+
handoutMasterRels.add(REL_TYPE.theme, "../theme/theme1.xml");
|
|
2842
|
+
files["ppt/handoutMasters/_rels/handoutMaster1.xml.rels"] = encoder.encode(
|
|
2843
|
+
handoutMasterRels.toXml()
|
|
2844
|
+
);
|
|
2845
|
+
}
|
|
2846
|
+
if (hasComments && input.commentAuthors) {
|
|
2847
|
+
presRels.add(REL_TYPE.commentAuthors, "commentAuthors.xml");
|
|
2848
|
+
files["ppt/commentAuthors.xml"] = encoder.encode(serializeCommentAuthors(input.commentAuthors));
|
|
2849
|
+
}
|
|
2850
|
+
if (input.tags && input.tags.length > 0) {
|
|
2851
|
+
tagCount++;
|
|
2852
|
+
presRels.add(REL_TYPE.tags, `tags/tag${tagCount}.xml`);
|
|
2853
|
+
files[`ppt/tags/tag${tagCount}.xml`] = encoder.encode(serializeTags(input.tags));
|
|
2854
|
+
}
|
|
2855
|
+
if (input.htmlPublishUri) {
|
|
2856
|
+
presRels.add(REL_TYPE.htmlPubSaveAs, input.htmlPublishUri, void 0, true);
|
|
2857
|
+
}
|
|
2858
|
+
for (let i = 0; i < slides.length; i++) {
|
|
2859
|
+
const layoutIdx = slides[i].layoutIndex ?? 0;
|
|
2860
|
+
const result = serializeSlide(
|
|
2861
|
+
slides[i].elements,
|
|
2862
|
+
i,
|
|
2863
|
+
theme,
|
|
2864
|
+
registry,
|
|
2865
|
+
`rId1`,
|
|
2866
|
+
slides[i].transition,
|
|
2867
|
+
slides[i].animations,
|
|
2868
|
+
slides[i].background
|
|
2869
|
+
);
|
|
2870
|
+
files[`ppt/slides/slide${i + 1}.xml`] = encoder.encode(result.slideXml);
|
|
2871
|
+
for (const [path, data] of result.media) {
|
|
2872
|
+
allMedia.set(path, data);
|
|
2873
|
+
if (path.startsWith("ppt/charts/")) {
|
|
2874
|
+
chartCount++;
|
|
2875
|
+
} else {
|
|
2876
|
+
const ext = path.split(".").pop() ?? "bin";
|
|
2877
|
+
imageExtensions.add(ext);
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
const slideRelManager = new RelationshipManager();
|
|
2881
|
+
slideRelManager.add(REL_TYPE.slideLayout, `../slideLayouts/slideLayout${layoutIdx + 1}.xml`);
|
|
2882
|
+
if (slides[i].notes) {
|
|
2883
|
+
notesCount++;
|
|
2884
|
+
const notesRel = new RelationshipManager();
|
|
2885
|
+
notesRel.add(REL_TYPE.slide, `../slides/slide${i + 1}.xml`);
|
|
2886
|
+
notesRel.add(REL_TYPE.notesMaster, "../notesMasters/notesMaster1.xml");
|
|
2887
|
+
const notesXml = serializeNotesSlide(slides[i].notes ?? "");
|
|
2888
|
+
files[`ppt/notesSlides/notesSlide${notesCount}.xml`] = encoder.encode(notesXml);
|
|
2889
|
+
files[`ppt/notesSlides/_rels/notesSlide${notesCount}.xml.rels`] = encoder.encode(
|
|
2890
|
+
notesRel.toXml()
|
|
2891
|
+
);
|
|
2892
|
+
slideRelManager.add(REL_TYPE.notesSlide, `../notesSlides/notesSlide${notesCount}.xml`);
|
|
2893
|
+
}
|
|
2894
|
+
const slideComments = slides[i].comments;
|
|
2895
|
+
if (slideComments && slideComments.length > 0) {
|
|
2896
|
+
commentCount++;
|
|
2897
|
+
slideRelManager.add(REL_TYPE.comments, `../comments/comment${commentCount}.xml`);
|
|
2898
|
+
files[`ppt/comments/comment${commentCount}.xml`] = encoder.encode(
|
|
2899
|
+
serializeComments(slideComments)
|
|
2900
|
+
);
|
|
2901
|
+
}
|
|
2902
|
+
const slideTags = slides[i].tags;
|
|
2903
|
+
if (slideTags && slideTags.length > 0) {
|
|
2904
|
+
tagCount++;
|
|
2905
|
+
slideRelManager.add(REL_TYPE.tags, `../tags/tag${tagCount}.xml`);
|
|
2906
|
+
files[`ppt/tags/tag${tagCount}.xml`] = encoder.encode(serializeTags(slideTags));
|
|
2907
|
+
}
|
|
2908
|
+
const syncData = slides[i].syncData;
|
|
2909
|
+
if (syncData) {
|
|
2910
|
+
slideRelManager.add(
|
|
2911
|
+
REL_TYPE.slideUpdateInfo,
|
|
2912
|
+
`../slideUpdateInfo/slideUpdateInfo${i + 1}.xml`
|
|
2913
|
+
);
|
|
2914
|
+
files[`ppt/slideUpdateInfo/slideUpdateInfo${i + 1}.xml`] = encoder.encode(
|
|
2915
|
+
serializeSlideUpdateInfo(syncData)
|
|
2916
|
+
);
|
|
2917
|
+
if (input.slideUpdateUrl) {
|
|
2918
|
+
const syncRels = new RelationshipManager();
|
|
2919
|
+
syncRels.add(REL_TYPE.slideUpdateUrl, input.slideUpdateUrl, void 0, true);
|
|
2920
|
+
files[`ppt/slideUpdateInfo/_rels/slideUpdateInfo${i + 1}.xml.rels`] = encoder.encode(
|
|
2921
|
+
syncRels.toXml()
|
|
2922
|
+
);
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
for (const rel of result.mediaRels) {
|
|
2926
|
+
slideRelManager.add(rel.type, rel.target);
|
|
2927
|
+
}
|
|
2928
|
+
files[`ppt/slides/_rels/slide${i + 1}.xml.rels`] = encoder.encode(slideRelManager.toXml());
|
|
2929
|
+
}
|
|
2930
|
+
files["ppt/theme/theme1.xml"] = encoder.encode(serializeTheme(theme));
|
|
2931
|
+
for (let i = 0; i < masters.length; i++) {
|
|
2932
|
+
files[`ppt/slideMasters/slideMaster${i + 1}.xml`] = encoder.encode(
|
|
2933
|
+
serializeSlideMaster(masters[i], layouts.length)
|
|
2934
|
+
);
|
|
2935
|
+
const masterRels = new RelationshipManager();
|
|
2936
|
+
for (let j = 0; j < layouts.length; j++) {
|
|
2937
|
+
masterRels.add(REL_TYPE.slideLayout, `../slideLayouts/slideLayout${j + 1}.xml`);
|
|
2938
|
+
}
|
|
2939
|
+
masterRels.add(REL_TYPE.theme, "../theme/theme1.xml");
|
|
2940
|
+
files[`ppt/slideMasters/_rels/slideMaster${i + 1}.xml.rels`] = encoder.encode(
|
|
2941
|
+
masterRels.toXml()
|
|
2942
|
+
);
|
|
2943
|
+
}
|
|
2944
|
+
for (let i = 0; i < layouts.length; i++) {
|
|
2945
|
+
files[`ppt/slideLayouts/slideLayout${i + 1}.xml`] = encoder.encode(
|
|
2946
|
+
serializeSlideLayout(layouts[i])
|
|
2947
|
+
);
|
|
2948
|
+
const layoutRels = new RelationshipManager();
|
|
2949
|
+
layoutRels.add(REL_TYPE.slideMaster, "../slideMasters/slideMaster1.xml");
|
|
2950
|
+
files[`ppt/slideLayouts/_rels/slideLayout${i + 1}.xml.rels`] = encoder.encode(
|
|
2951
|
+
layoutRels.toXml()
|
|
2952
|
+
);
|
|
2953
|
+
}
|
|
2954
|
+
files["[Content_Types].xml"] = encoder.encode(
|
|
2955
|
+
buildContentTypes({
|
|
2956
|
+
slideCount: slides.length,
|
|
2957
|
+
imageExtensions,
|
|
2958
|
+
chartCount,
|
|
2959
|
+
notesCount,
|
|
2960
|
+
layoutCount: layouts.length,
|
|
2961
|
+
hasNotesMaster: hasNotes,
|
|
2962
|
+
hasHandoutMaster: !!input.handoutMaster,
|
|
2963
|
+
commentCount,
|
|
2964
|
+
hasCommentAuthors: !!hasComments,
|
|
2965
|
+
tagCount,
|
|
2966
|
+
syncDataCount: slides.filter((s) => s.syncData).length
|
|
2967
|
+
})
|
|
2968
|
+
);
|
|
2969
|
+
files["ppt/presentation.xml"] = encoder.encode(
|
|
2970
|
+
serializePresentation(slides.length, slideRIds, input.slideSize)
|
|
2971
|
+
);
|
|
2972
|
+
files["ppt/_rels/presentation.xml.rels"] = encoder.encode(presRels.toXml());
|
|
2973
|
+
if (input.coreProperties) {
|
|
2974
|
+
files["docProps/core.xml"] = encoder.encode(serializeCoreProperties(input.coreProperties));
|
|
2975
|
+
}
|
|
2976
|
+
const rootRels = new RelationshipManager();
|
|
2977
|
+
rootRels.add(REL_TYPE.officeDocument, "ppt/presentation.xml");
|
|
2978
|
+
if (input.coreProperties) {
|
|
2979
|
+
rootRels.add(
|
|
2980
|
+
"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties",
|
|
2981
|
+
"docProps/core.xml"
|
|
2982
|
+
);
|
|
2983
|
+
}
|
|
2984
|
+
files["_rels/.rels"] = encoder.encode(rootRels.toXml());
|
|
2985
|
+
for (const [path, data] of allMedia) {
|
|
2986
|
+
files[path] = data;
|
|
2987
|
+
}
|
|
2988
|
+
return zipSync(files);
|
|
2989
|
+
}
|
|
2990
|
+
|
|
2991
|
+
// src/elements/base.ts
|
|
2992
|
+
var BaseElement = class {
|
|
2993
|
+
/** Position and size of the element on the slide. */
|
|
2994
|
+
placement;
|
|
2995
|
+
/** Optional human-readable name for the element. */
|
|
2996
|
+
name;
|
|
2997
|
+
constructor(placement, name) {
|
|
2998
|
+
this.placement = placement;
|
|
2999
|
+
this.name = name;
|
|
3000
|
+
}
|
|
3001
|
+
};
|
|
3002
|
+
|
|
3003
|
+
// src/elements/text.ts
|
|
3004
|
+
var TextElement = class _TextElement extends BaseElement {
|
|
3005
|
+
/** Element type discriminator. */
|
|
3006
|
+
type = "text";
|
|
3007
|
+
/** Paragraphs that make up the text content. */
|
|
3008
|
+
paragraphs;
|
|
3009
|
+
/** Options controlling the text body (margins, wrapping, auto-fit, etc.). */
|
|
3010
|
+
bodyOptions;
|
|
3011
|
+
/** Background fill for the text box. */
|
|
3012
|
+
fill;
|
|
3013
|
+
/** Outline/border properties for the text box. */
|
|
3014
|
+
line;
|
|
3015
|
+
/** Visual effects (shadow, glow, etc.). */
|
|
3016
|
+
effects;
|
|
3017
|
+
/** 2-D transform (rotation, flip). */
|
|
3018
|
+
transform;
|
|
3019
|
+
/** 3D scene (camera + lighting). */
|
|
3020
|
+
scene3d;
|
|
3021
|
+
/** 3D shape (extrusion, bevels, material). */
|
|
3022
|
+
shape3d;
|
|
3023
|
+
constructor(paragraphs, placement, name, opts) {
|
|
3024
|
+
super(placement, name);
|
|
3025
|
+
this.paragraphs = paragraphs;
|
|
3026
|
+
this.bodyOptions = opts?.bodyOptions;
|
|
3027
|
+
this.fill = opts?.fill;
|
|
3028
|
+
this.line = opts?.line;
|
|
3029
|
+
this.effects = opts?.effects;
|
|
3030
|
+
this.transform = opts?.transform;
|
|
3031
|
+
this.scene3d = opts?.scene3d;
|
|
3032
|
+
this.shape3d = opts?.shape3d;
|
|
3033
|
+
}
|
|
3034
|
+
/**
|
|
3035
|
+
* Creates a TextElement from a plain string, splitting on newlines into paragraphs.
|
|
3036
|
+
* @param text - Plain text content (newlines become paragraph breaks).
|
|
3037
|
+
* @param placement - Position and size on the slide.
|
|
3038
|
+
* @param runOptions - Optional formatting for all text runs.
|
|
3039
|
+
* @param paraOptions - Optional paragraph-level formatting.
|
|
3040
|
+
* @param bodyOptions - Optional text body options.
|
|
3041
|
+
* @returns A new TextElement instance.
|
|
3042
|
+
*/
|
|
3043
|
+
static fromString(text, placement, runOptions, paraOptions, bodyOptions) {
|
|
3044
|
+
const lines = text.split("\n");
|
|
3045
|
+
const paragraphs = lines.map((line) => ({
|
|
3046
|
+
runs: [{ text: line, options: runOptions }],
|
|
3047
|
+
options: paraOptions
|
|
3048
|
+
}));
|
|
3049
|
+
return new _TextElement(paragraphs, placement, void 0, { bodyOptions });
|
|
3050
|
+
}
|
|
3051
|
+
};
|
|
3052
|
+
|
|
3053
|
+
// src/elements/image.ts
|
|
3054
|
+
var ImageElement = class extends BaseElement {
|
|
3055
|
+
/** Element type discriminator. */
|
|
3056
|
+
type = "image";
|
|
3057
|
+
/** File system path to the image (mutually exclusive with `data`). */
|
|
3058
|
+
path;
|
|
3059
|
+
/** Raw image bytes (mutually exclusive with `path`). */
|
|
3060
|
+
data;
|
|
3061
|
+
/** MIME type of the image (defaults to 'image/png'). */
|
|
3062
|
+
contentType;
|
|
3063
|
+
/** Border/outline properties for the image. */
|
|
3064
|
+
border;
|
|
3065
|
+
/** Visual effects (shadow, glow, etc.). */
|
|
3066
|
+
effects;
|
|
3067
|
+
/** 2-D transform (rotation, flip). */
|
|
3068
|
+
transform;
|
|
3069
|
+
/** Image opacity, 0-100. */
|
|
3070
|
+
opacity;
|
|
3071
|
+
/** Crop offsets as fractions (0-1) from each edge. */
|
|
3072
|
+
crop;
|
|
3073
|
+
/** Hyperlink attached to the image. */
|
|
3074
|
+
hyperlink;
|
|
3075
|
+
/** Whether to lock the aspect ratio when resizing. */
|
|
3076
|
+
lockAspectRatio;
|
|
3077
|
+
/** 3D scene (camera + lighting). */
|
|
3078
|
+
scene3d;
|
|
3079
|
+
/** 3D shape (extrusion, bevels, material). */
|
|
3080
|
+
shape3d;
|
|
3081
|
+
brightness;
|
|
3082
|
+
contrast;
|
|
3083
|
+
saturation;
|
|
3084
|
+
duotone;
|
|
3085
|
+
cropShape;
|
|
3086
|
+
constructor(placement, opts) {
|
|
3087
|
+
super(placement);
|
|
3088
|
+
this.path = opts.path;
|
|
3089
|
+
this.data = opts.data;
|
|
3090
|
+
this.contentType = opts.contentType ?? "image/png";
|
|
3091
|
+
this.border = opts.border;
|
|
3092
|
+
this.effects = opts.effects;
|
|
3093
|
+
this.transform = opts.transform;
|
|
3094
|
+
this.opacity = opts.opacity;
|
|
3095
|
+
this.crop = opts.crop;
|
|
3096
|
+
this.hyperlink = opts.hyperlink;
|
|
3097
|
+
this.lockAspectRatio = opts.lockAspectRatio;
|
|
3098
|
+
this.scene3d = opts.scene3d;
|
|
3099
|
+
this.shape3d = opts.shape3d;
|
|
3100
|
+
this.brightness = opts.brightness;
|
|
3101
|
+
this.contrast = opts.contrast;
|
|
3102
|
+
this.saturation = opts.saturation;
|
|
3103
|
+
this.duotone = opts.duotone;
|
|
3104
|
+
this.cropShape = opts.cropShape;
|
|
3105
|
+
}
|
|
3106
|
+
};
|
|
3107
|
+
|
|
3108
|
+
// src/elements/shape.ts
|
|
3109
|
+
var ShapeElement = class extends BaseElement {
|
|
3110
|
+
/** Element type discriminator. */
|
|
3111
|
+
type = "shape";
|
|
3112
|
+
/** Preset geometry type (e.g. 'rect', 'ellipse', 'roundRect'). */
|
|
3113
|
+
geometry;
|
|
3114
|
+
/** Background fill for the shape. */
|
|
3115
|
+
fill;
|
|
3116
|
+
/** Outline/border properties. */
|
|
3117
|
+
line;
|
|
3118
|
+
/** Visual effects (shadow, glow, etc.). */
|
|
3119
|
+
effects;
|
|
3120
|
+
/** 2-D transform (rotation, flip). */
|
|
3121
|
+
transform;
|
|
3122
|
+
/** Shape opacity, 0-100. */
|
|
3123
|
+
opacity;
|
|
3124
|
+
/** Plain text content rendered inside the shape. */
|
|
3125
|
+
text;
|
|
3126
|
+
/** Text body options for text rendered inside the shape. */
|
|
3127
|
+
textOptions;
|
|
3128
|
+
/** Run-level formatting for the shape's text. */
|
|
3129
|
+
textRunOptions;
|
|
3130
|
+
/** Paragraph-level formatting for the shape's text. */
|
|
3131
|
+
textParagraphOptions;
|
|
3132
|
+
/** Geometry adjustment values keyed by handle name. */
|
|
3133
|
+
adjustValues;
|
|
3134
|
+
/** Hyperlink attached to the shape. */
|
|
3135
|
+
hyperlink;
|
|
3136
|
+
/** 3D scene (camera + lighting). */
|
|
3137
|
+
scene3d;
|
|
3138
|
+
/** 3D shape (extrusion, bevels, material). */
|
|
3139
|
+
shape3d;
|
|
3140
|
+
/** Custom geometry (overrides preset). */
|
|
3141
|
+
customGeometry;
|
|
3142
|
+
/** Shape protection locks. */
|
|
3143
|
+
locks;
|
|
3144
|
+
constructor(geometry, placement, opts) {
|
|
3145
|
+
super(placement);
|
|
3146
|
+
this.geometry = geometry;
|
|
3147
|
+
this.fill = opts?.fill;
|
|
3148
|
+
this.line = opts?.line;
|
|
3149
|
+
this.effects = opts?.effects;
|
|
3150
|
+
this.transform = opts?.transform;
|
|
3151
|
+
this.opacity = opts?.opacity;
|
|
3152
|
+
this.text = opts?.text;
|
|
3153
|
+
this.textOptions = opts?.textOptions;
|
|
3154
|
+
this.textRunOptions = opts?.textRunOptions;
|
|
3155
|
+
this.textParagraphOptions = opts?.textParagraphOptions;
|
|
3156
|
+
this.adjustValues = opts?.adjustValues;
|
|
3157
|
+
this.hyperlink = opts?.hyperlink;
|
|
3158
|
+
this.scene3d = opts?.scene3d;
|
|
3159
|
+
this.shape3d = opts?.shape3d;
|
|
3160
|
+
this.customGeometry = opts?.customGeometry;
|
|
3161
|
+
this.locks = opts?.locks;
|
|
3162
|
+
}
|
|
3163
|
+
};
|
|
3164
|
+
|
|
3165
|
+
// src/elements/table.ts
|
|
3166
|
+
var TableElement = class extends BaseElement {
|
|
3167
|
+
/** Element type discriminator. */
|
|
3168
|
+
type = "table";
|
|
3169
|
+
/** Row data including cells and per-row options. */
|
|
3170
|
+
rows;
|
|
3171
|
+
/** Column widths in EMUs. */
|
|
3172
|
+
colWidths;
|
|
3173
|
+
/** Row heights in EMUs. */
|
|
3174
|
+
rowHeights;
|
|
3175
|
+
/** Border configuration for the table. */
|
|
3176
|
+
border;
|
|
3177
|
+
/** Default background fill for cells. */
|
|
3178
|
+
fill;
|
|
3179
|
+
/** Apply special formatting to the first row. */
|
|
3180
|
+
firstRow;
|
|
3181
|
+
/** Apply special formatting to the last row. */
|
|
3182
|
+
lastRow;
|
|
3183
|
+
/** Apply special formatting to the first column. */
|
|
3184
|
+
firstCol;
|
|
3185
|
+
/** Apply special formatting to the last column. */
|
|
3186
|
+
lastCol;
|
|
3187
|
+
/** Enable row banding (alternating row colors). */
|
|
3188
|
+
bandRow;
|
|
3189
|
+
/** Enable column banding (alternating column colors). */
|
|
3190
|
+
bandCol;
|
|
3191
|
+
/** Pair of colors for alternating row bands. */
|
|
3192
|
+
bandRowColors;
|
|
3193
|
+
/** Visual effects (shadow, glow, etc.). */
|
|
3194
|
+
effects;
|
|
3195
|
+
/** 2-D transform (rotation, flip). */
|
|
3196
|
+
transform;
|
|
3197
|
+
/** Built-in table style GUID. */
|
|
3198
|
+
tableStyleId;
|
|
3199
|
+
constructor(rows, placement, opts) {
|
|
3200
|
+
super(placement);
|
|
3201
|
+
this.rows = rows;
|
|
3202
|
+
this.colWidths = opts?.colWidths;
|
|
3203
|
+
this.rowHeights = opts?.rowHeights;
|
|
3204
|
+
this.border = opts?.border;
|
|
3205
|
+
this.fill = opts?.fill;
|
|
3206
|
+
this.firstRow = opts?.firstRow;
|
|
3207
|
+
this.lastRow = opts?.lastRow;
|
|
3208
|
+
this.firstCol = opts?.firstCol;
|
|
3209
|
+
this.lastCol = opts?.lastCol;
|
|
3210
|
+
this.bandRow = opts?.bandRow;
|
|
3211
|
+
this.bandCol = opts?.bandCol;
|
|
3212
|
+
this.bandRowColors = opts?.bandRowColors;
|
|
3213
|
+
this.effects = opts?.effects;
|
|
3214
|
+
this.transform = opts?.transform;
|
|
3215
|
+
this.tableStyleId = opts?.tableStyleId;
|
|
3216
|
+
}
|
|
3217
|
+
};
|
|
3218
|
+
|
|
3219
|
+
// src/elements/chart.ts
|
|
3220
|
+
var ChartElement = class extends BaseElement {
|
|
3221
|
+
/** Element type discriminator. */
|
|
3222
|
+
type = "chart";
|
|
3223
|
+
/** The kind of chart to render (e.g. 'bar', 'line', 'pie'). */
|
|
3224
|
+
chartType;
|
|
3225
|
+
/** Series and category data for the chart. */
|
|
3226
|
+
data;
|
|
3227
|
+
/** Optional chart title text. */
|
|
3228
|
+
title;
|
|
3229
|
+
/** Whether to display the legend (defaults to true). */
|
|
3230
|
+
showLegend;
|
|
3231
|
+
/** Whether to show data labels on data points (defaults to false). */
|
|
3232
|
+
showDataLabels;
|
|
3233
|
+
/** Whether to display grid lines (defaults to true). */
|
|
3234
|
+
showGridLines;
|
|
3235
|
+
/** Font size for the chart title, in points. */
|
|
3236
|
+
titleFontSize;
|
|
3237
|
+
/** Color for the chart title. */
|
|
3238
|
+
titleColor;
|
|
3239
|
+
/** Position of the legend relative to the chart. */
|
|
3240
|
+
legendPosition;
|
|
3241
|
+
/** Category (horizontal) axis options. */
|
|
3242
|
+
catAxis;
|
|
3243
|
+
/** Primary value (vertical) axis options. */
|
|
3244
|
+
valAxis;
|
|
3245
|
+
/** Secondary value axis options (for combo charts). */
|
|
3246
|
+
secondaryValAxis;
|
|
3247
|
+
/** Plot area background fill and border. */
|
|
3248
|
+
plotArea;
|
|
3249
|
+
/** Gap width between bar groups, as a percentage. */
|
|
3250
|
+
barGapWidth;
|
|
3251
|
+
/** Overlap between bars in a group, as a percentage (-100 to 100). */
|
|
3252
|
+
barOverlap;
|
|
3253
|
+
/** Grouping mode for bar/column charts. */
|
|
3254
|
+
barGrouping;
|
|
3255
|
+
/** Explosion distance for pie slices, as a percentage. */
|
|
3256
|
+
pieExplosion;
|
|
3257
|
+
/** Hole size for doughnut charts, as a percentage (0-90). */
|
|
3258
|
+
doughnutHoleSize;
|
|
3259
|
+
/** Grouping mode for line charts. */
|
|
3260
|
+
lineGrouping;
|
|
3261
|
+
/** Grouping mode for area charts. */
|
|
3262
|
+
areaGrouping;
|
|
3263
|
+
/** Rendering style for scatter charts. */
|
|
3264
|
+
scatterStyle;
|
|
3265
|
+
/** Rendering style for radar charts. */
|
|
3266
|
+
radarStyle;
|
|
3267
|
+
/** Chart border/outline properties. */
|
|
3268
|
+
border;
|
|
3269
|
+
/** Chart background fill color. */
|
|
3270
|
+
fill;
|
|
3271
|
+
/** Chart-level data label configuration. */
|
|
3272
|
+
dataLabels;
|
|
3273
|
+
/** 3-D view settings for the chart. */
|
|
3274
|
+
view3D;
|
|
3275
|
+
constructor(chartType, data, placement, opts) {
|
|
3276
|
+
super(placement);
|
|
3277
|
+
this.chartType = chartType;
|
|
3278
|
+
this.data = data;
|
|
3279
|
+
this.title = opts?.title;
|
|
3280
|
+
this.showLegend = opts?.showLegend ?? true;
|
|
3281
|
+
this.showDataLabels = opts?.showDataLabels ?? false;
|
|
3282
|
+
this.showGridLines = opts?.showGridLines ?? true;
|
|
3283
|
+
this.titleFontSize = opts?.titleFontSize;
|
|
3284
|
+
this.titleColor = opts?.titleColor;
|
|
3285
|
+
this.legendPosition = opts?.legendPosition;
|
|
3286
|
+
this.catAxis = opts?.catAxis;
|
|
3287
|
+
this.valAxis = opts?.valAxis;
|
|
3288
|
+
this.secondaryValAxis = opts?.secondaryValAxis;
|
|
3289
|
+
this.plotArea = opts?.plotArea;
|
|
3290
|
+
this.barGapWidth = opts?.barGapWidth;
|
|
3291
|
+
this.barOverlap = opts?.barOverlap;
|
|
3292
|
+
this.barGrouping = opts?.barGrouping;
|
|
3293
|
+
this.pieExplosion = opts?.pieExplosion;
|
|
3294
|
+
this.doughnutHoleSize = opts?.doughnutHoleSize;
|
|
3295
|
+
this.lineGrouping = opts?.lineGrouping;
|
|
3296
|
+
this.areaGrouping = opts?.areaGrouping;
|
|
3297
|
+
this.scatterStyle = opts?.scatterStyle;
|
|
3298
|
+
this.radarStyle = opts?.radarStyle;
|
|
3299
|
+
this.border = opts?.border;
|
|
3300
|
+
this.fill = opts?.fill;
|
|
3301
|
+
this.dataLabels = opts?.dataLabels;
|
|
3302
|
+
this.view3D = opts?.view3D;
|
|
3303
|
+
}
|
|
3304
|
+
};
|
|
3305
|
+
|
|
3306
|
+
// src/elements/media.ts
|
|
3307
|
+
var MediaElement = class extends BaseElement {
|
|
3308
|
+
/** Element type discriminator. */
|
|
3309
|
+
type = "media";
|
|
3310
|
+
/** Whether this is a video or audio element. */
|
|
3311
|
+
mediaType;
|
|
3312
|
+
/** File system path to the media file (mutually exclusive with `data`). */
|
|
3313
|
+
path;
|
|
3314
|
+
/** Raw media bytes (mutually exclusive with `path`). */
|
|
3315
|
+
data;
|
|
3316
|
+
/** MIME type (defaults to 'video/mp4' or 'audio/mpeg' based on mediaType). */
|
|
3317
|
+
contentType;
|
|
3318
|
+
/** Poster/thumbnail image displayed before playback. */
|
|
3319
|
+
poster;
|
|
3320
|
+
/** Playback settings (autoplay, loop, etc.). */
|
|
3321
|
+
playback;
|
|
3322
|
+
/** Visual effects (shadow, glow, etc.). */
|
|
3323
|
+
effects;
|
|
3324
|
+
/** 2-D transform (rotation, flip). */
|
|
3325
|
+
transform;
|
|
3326
|
+
constructor(mediaType, placement, opts) {
|
|
3327
|
+
super(placement);
|
|
3328
|
+
this.mediaType = mediaType;
|
|
3329
|
+
this.path = opts.path;
|
|
3330
|
+
this.data = opts.data;
|
|
3331
|
+
this.contentType = opts.contentType ?? (mediaType === "video" ? "video/mp4" : "audio/mpeg");
|
|
3332
|
+
this.poster = opts.poster;
|
|
3333
|
+
this.playback = opts.playback;
|
|
3334
|
+
this.effects = opts.effects;
|
|
3335
|
+
this.transform = opts.transform;
|
|
3336
|
+
}
|
|
3337
|
+
};
|
|
3338
|
+
|
|
3339
|
+
// src/elements/group.ts
|
|
3340
|
+
var GroupElement = class extends BaseElement {
|
|
3341
|
+
/** Element type discriminator. */
|
|
3342
|
+
type = "group";
|
|
3343
|
+
/** Child elements contained within this group. */
|
|
3344
|
+
children;
|
|
3345
|
+
constructor(children, placement, name) {
|
|
3346
|
+
super(placement, name);
|
|
3347
|
+
this.children = children;
|
|
3348
|
+
}
|
|
3349
|
+
};
|
|
3350
|
+
|
|
3351
|
+
// src/elements/connector.ts
|
|
3352
|
+
var ConnectorElement = class extends BaseElement {
|
|
3353
|
+
/** Element type discriminator. */
|
|
3354
|
+
type = "connector";
|
|
3355
|
+
/** The connector routing style (defaults to 'straight'). */
|
|
3356
|
+
connectorType;
|
|
3357
|
+
/** Line formatting (color, width, dash style, etc.). */
|
|
3358
|
+
line;
|
|
3359
|
+
/** Arrowhead properties for the start of the connector. */
|
|
3360
|
+
startArrow;
|
|
3361
|
+
/** Arrowhead properties for the end of the connector. */
|
|
3362
|
+
endArrow;
|
|
3363
|
+
constructor(placement, opts) {
|
|
3364
|
+
super(placement);
|
|
3365
|
+
this.connectorType = opts?.type ?? "straight";
|
|
3366
|
+
this.line = opts?.line;
|
|
3367
|
+
this.startArrow = opts?.startArrow;
|
|
3368
|
+
this.endArrow = opts?.endArrow;
|
|
3369
|
+
}
|
|
3370
|
+
};
|
|
3371
|
+
|
|
3372
|
+
// src/builder/slide-builder.ts
|
|
3373
|
+
function placementFromOpts(opts) {
|
|
3374
|
+
return {
|
|
3375
|
+
x: opts.x ?? 0,
|
|
3376
|
+
y: opts.y ?? 0,
|
|
3377
|
+
w: opts.w ?? 5,
|
|
3378
|
+
h: opts.h ?? 1
|
|
3379
|
+
};
|
|
3380
|
+
}
|
|
3381
|
+
var SlideBuilder = class {
|
|
3382
|
+
data;
|
|
3383
|
+
commentAuthors;
|
|
3384
|
+
constructor(data, commentAuthors) {
|
|
3385
|
+
this.data = data;
|
|
3386
|
+
this.commentAuthors = commentAuthors;
|
|
3387
|
+
}
|
|
3388
|
+
/** Adds a text box to the slide. Placement dimensions are in inches. */
|
|
3389
|
+
addText(text, opts = {}) {
|
|
3390
|
+
const placement = placementFromOpts(opts);
|
|
3391
|
+
const element = TextElement.fromString(
|
|
3392
|
+
text,
|
|
3393
|
+
placement,
|
|
3394
|
+
{
|
|
3395
|
+
bold: opts.bold,
|
|
3396
|
+
italic: opts.italic,
|
|
3397
|
+
underline: opts.underline,
|
|
3398
|
+
strikethrough: opts.strikethrough,
|
|
3399
|
+
fontSize: opts.fontSize,
|
|
3400
|
+
fontFace: opts.fontFace,
|
|
3401
|
+
color: opts.color,
|
|
3402
|
+
subscript: opts.subscript,
|
|
3403
|
+
superscript: opts.superscript,
|
|
3404
|
+
highlight: opts.highlight,
|
|
3405
|
+
letterSpacing: opts.letterSpacing,
|
|
3406
|
+
baseline: opts.baseline,
|
|
3407
|
+
hyperlink: opts.hyperlink,
|
|
3408
|
+
outline: opts.outline,
|
|
3409
|
+
shadow: opts.shadow,
|
|
3410
|
+
caps: opts.caps,
|
|
3411
|
+
lang: opts.lang
|
|
3412
|
+
},
|
|
3413
|
+
{
|
|
3414
|
+
align: opts.align,
|
|
3415
|
+
lineSpacing: opts.lineSpacing,
|
|
3416
|
+
spaceBefore: opts.spaceBefore,
|
|
3417
|
+
spaceAfter: opts.spaceAfter,
|
|
3418
|
+
indent: opts.indent,
|
|
3419
|
+
marginLeft: opts.marginLeft,
|
|
3420
|
+
level: opts.level,
|
|
3421
|
+
rtl: opts.rtl,
|
|
3422
|
+
bullet: opts.bullet,
|
|
3423
|
+
numbering: opts.numbering,
|
|
3424
|
+
tabStops: opts.tabStops,
|
|
3425
|
+
defaultRunOptions: opts.defaultRunOptions
|
|
3426
|
+
},
|
|
3427
|
+
{
|
|
3428
|
+
verticalAlign: opts.verticalAlign,
|
|
3429
|
+
textDirection: opts.textDirection,
|
|
3430
|
+
wordWrap: opts.wordWrap,
|
|
3431
|
+
autoFit: opts.autoFit,
|
|
3432
|
+
margin: opts.margin,
|
|
3433
|
+
columns: opts.columns,
|
|
3434
|
+
columnSpacing: opts.columnSpacing
|
|
3435
|
+
}
|
|
3436
|
+
);
|
|
3437
|
+
if (opts.fill) element.fill = opts.fill;
|
|
3438
|
+
if (opts.line) element.line = opts.line;
|
|
3439
|
+
if (opts.effects) element.effects = opts.effects;
|
|
3440
|
+
if (opts.transform) element.transform = opts.transform;
|
|
3441
|
+
if (opts.scene3d) element.scene3d = opts.scene3d;
|
|
3442
|
+
if (opts.shape3d) element.shape3d = opts.shape3d;
|
|
3443
|
+
this.data.elements.push(element);
|
|
3444
|
+
return this;
|
|
3445
|
+
}
|
|
3446
|
+
/** Adds an image to the slide from a file path or binary data. */
|
|
3447
|
+
addImage(opts) {
|
|
3448
|
+
const placement = placementFromOpts(opts);
|
|
3449
|
+
const element = new ImageElement(placement, {
|
|
3450
|
+
path: opts.path,
|
|
3451
|
+
data: opts.data,
|
|
3452
|
+
contentType: opts.contentType,
|
|
3453
|
+
border: opts.border,
|
|
3454
|
+
effects: opts.effects,
|
|
3455
|
+
transform: opts.transform,
|
|
3456
|
+
opacity: opts.opacity,
|
|
3457
|
+
crop: opts.crop,
|
|
3458
|
+
hyperlink: opts.hyperlink,
|
|
3459
|
+
lockAspectRatio: opts.lockAspectRatio,
|
|
3460
|
+
scene3d: opts.scene3d,
|
|
3461
|
+
shape3d: opts.shape3d,
|
|
3462
|
+
brightness: opts.brightness,
|
|
3463
|
+
contrast: opts.contrast,
|
|
3464
|
+
saturation: opts.saturation,
|
|
3465
|
+
duotone: opts.duotone,
|
|
3466
|
+
cropShape: opts.cropShape
|
|
3467
|
+
});
|
|
3468
|
+
this.data.elements.push(element);
|
|
3469
|
+
return this;
|
|
3470
|
+
}
|
|
3471
|
+
/** Adds a preset geometry shape to the slide. */
|
|
3472
|
+
addShape(geometry, opts = {}) {
|
|
3473
|
+
const placement = placementFromOpts(opts);
|
|
3474
|
+
const element = new ShapeElement(geometry, placement, {
|
|
3475
|
+
fill: opts.fill,
|
|
3476
|
+
line: opts.line,
|
|
3477
|
+
effects: opts.effects,
|
|
3478
|
+
transform: opts.transform,
|
|
3479
|
+
opacity: opts.opacity,
|
|
3480
|
+
text: opts.text,
|
|
3481
|
+
textOptions: opts.textOptions,
|
|
3482
|
+
textRunOptions: opts.textRunOptions,
|
|
3483
|
+
textParagraphOptions: opts.textParagraphOptions,
|
|
3484
|
+
adjustValues: opts.adjustValues,
|
|
3485
|
+
hyperlink: opts.hyperlink,
|
|
3486
|
+
scene3d: opts.scene3d,
|
|
3487
|
+
shape3d: opts.shape3d,
|
|
3488
|
+
customGeometry: opts.customGeometry,
|
|
3489
|
+
locks: opts.locks
|
|
3490
|
+
});
|
|
3491
|
+
this.data.elements.push(element);
|
|
3492
|
+
return this;
|
|
3493
|
+
}
|
|
3494
|
+
/** Adds a table to the slide. */
|
|
3495
|
+
addTable(rows, opts = {}) {
|
|
3496
|
+
const placement = placementFromOpts(opts);
|
|
3497
|
+
const element = new TableElement(rows, placement, {
|
|
3498
|
+
colWidths: opts.colWidths,
|
|
3499
|
+
rowHeights: opts.rowHeights,
|
|
3500
|
+
border: opts.border,
|
|
3501
|
+
fill: opts.fill,
|
|
3502
|
+
firstRow: opts.firstRow,
|
|
3503
|
+
lastRow: opts.lastRow,
|
|
3504
|
+
firstCol: opts.firstCol,
|
|
3505
|
+
lastCol: opts.lastCol,
|
|
3506
|
+
bandRow: opts.bandRow,
|
|
3507
|
+
bandCol: opts.bandCol,
|
|
3508
|
+
bandRowColors: opts.bandRowColors,
|
|
3509
|
+
effects: opts.effects,
|
|
3510
|
+
transform: opts.transform,
|
|
3511
|
+
tableStyleId: opts.tableStyleId
|
|
3512
|
+
});
|
|
3513
|
+
this.data.elements.push(element);
|
|
3514
|
+
return this;
|
|
3515
|
+
}
|
|
3516
|
+
/** Adds a chart to the slide. Defaults to 6x4 inches if width/height are not specified. */
|
|
3517
|
+
addChart(type, data, opts = {}) {
|
|
3518
|
+
const placement = placementFromOpts({ ...opts, w: opts.w ?? 6, h: opts.h ?? 4 });
|
|
3519
|
+
const element = new ChartElement(type, data, placement, {
|
|
3520
|
+
title: opts.title,
|
|
3521
|
+
showLegend: opts.showLegend,
|
|
3522
|
+
showDataLabels: opts.showDataLabels,
|
|
3523
|
+
showGridLines: opts.showGridLines,
|
|
3524
|
+
titleFontSize: opts.titleFontSize,
|
|
3525
|
+
titleColor: opts.titleColor,
|
|
3526
|
+
legendPosition: opts.legendPosition,
|
|
3527
|
+
catAxis: opts.catAxis,
|
|
3528
|
+
valAxis: opts.valAxis,
|
|
3529
|
+
secondaryValAxis: opts.secondaryValAxis,
|
|
3530
|
+
plotArea: opts.plotArea,
|
|
3531
|
+
barGapWidth: opts.barGapWidth,
|
|
3532
|
+
barOverlap: opts.barOverlap,
|
|
3533
|
+
barGrouping: opts.barGrouping,
|
|
3534
|
+
pieExplosion: opts.pieExplosion,
|
|
3535
|
+
doughnutHoleSize: opts.doughnutHoleSize,
|
|
3536
|
+
lineGrouping: opts.lineGrouping,
|
|
3537
|
+
areaGrouping: opts.areaGrouping,
|
|
3538
|
+
scatterStyle: opts.scatterStyle,
|
|
3539
|
+
radarStyle: opts.radarStyle,
|
|
3540
|
+
border: opts.border,
|
|
3541
|
+
fill: opts.fill,
|
|
3542
|
+
dataLabels: opts.dataLabels,
|
|
3543
|
+
view3D: opts.view3D
|
|
3544
|
+
});
|
|
3545
|
+
this.data.elements.push(element);
|
|
3546
|
+
return this;
|
|
3547
|
+
}
|
|
3548
|
+
/** Sets speaker notes text for this slide. */
|
|
3549
|
+
setNotes(notes) {
|
|
3550
|
+
this.data.notes = notes;
|
|
3551
|
+
return this;
|
|
3552
|
+
}
|
|
3553
|
+
/** Adds a video element to the slide. Defaults to 6x4 inches. */
|
|
3554
|
+
addVideo(opts) {
|
|
3555
|
+
const placement = placementFromOpts({ ...opts, w: opts.w ?? 6, h: opts.h ?? 4 });
|
|
3556
|
+
const element = new MediaElement("video", placement, {
|
|
3557
|
+
path: opts.path,
|
|
3558
|
+
data: opts.data,
|
|
3559
|
+
contentType: opts.contentType,
|
|
3560
|
+
poster: opts.poster,
|
|
3561
|
+
playback: opts.playback,
|
|
3562
|
+
effects: opts.effects,
|
|
3563
|
+
transform: opts.transform
|
|
3564
|
+
});
|
|
3565
|
+
this.data.elements.push(element);
|
|
3566
|
+
return this;
|
|
3567
|
+
}
|
|
3568
|
+
/** Adds an audio element to the slide. Defaults to 1x1 inch. */
|
|
3569
|
+
addAudio(opts) {
|
|
3570
|
+
const placement = placementFromOpts({ ...opts, w: opts.w ?? 1, h: opts.h ?? 1 });
|
|
3571
|
+
const element = new MediaElement("audio", placement, {
|
|
3572
|
+
path: opts.path,
|
|
3573
|
+
data: opts.data,
|
|
3574
|
+
contentType: opts.contentType,
|
|
3575
|
+
poster: opts.poster,
|
|
3576
|
+
playback: opts.playback,
|
|
3577
|
+
effects: opts.effects,
|
|
3578
|
+
transform: opts.transform
|
|
3579
|
+
});
|
|
3580
|
+
this.data.elements.push(element);
|
|
3581
|
+
return this;
|
|
3582
|
+
}
|
|
3583
|
+
/** Adds a pre-built element directly to the slide. */
|
|
3584
|
+
addElement(element) {
|
|
3585
|
+
this.data.elements.push(element);
|
|
3586
|
+
return this;
|
|
3587
|
+
}
|
|
3588
|
+
/**
|
|
3589
|
+
* Adds a comment to the slide.
|
|
3590
|
+
* @param authorId - ID returned by {@link Presentation.defineCommentAuthor}.
|
|
3591
|
+
*/
|
|
3592
|
+
addComment(text, authorId, opts) {
|
|
3593
|
+
if (!this.data.comments) this.data.comments = [];
|
|
3594
|
+
if (this.commentAuthors) {
|
|
3595
|
+
const author = this.commentAuthors.find((a) => a.id === authorId);
|
|
3596
|
+
if (author) author.lastIdx++;
|
|
3597
|
+
}
|
|
3598
|
+
this.data.comments.push({
|
|
3599
|
+
authorId,
|
|
3600
|
+
text,
|
|
3601
|
+
date: opts?.date,
|
|
3602
|
+
position: opts?.position,
|
|
3603
|
+
index: this.data.comments.length + 1
|
|
3604
|
+
});
|
|
3605
|
+
return this;
|
|
3606
|
+
}
|
|
3607
|
+
/** Sets user-defined tags on this slide as key-value pairs. */
|
|
3608
|
+
setTags(tags) {
|
|
3609
|
+
this.data.tags = Object.entries(tags).map(([name, value]) => ({ name, value }));
|
|
3610
|
+
return this;
|
|
3611
|
+
}
|
|
3612
|
+
/** Sets synchronization data for collaborative slide updates. */
|
|
3613
|
+
setSyncData(data) {
|
|
3614
|
+
this.data.syncData = data;
|
|
3615
|
+
return this;
|
|
3616
|
+
}
|
|
3617
|
+
/** Sets the transition effect for this slide. */
|
|
3618
|
+
setTransition(transition) {
|
|
3619
|
+
this.data.transition = transition;
|
|
3620
|
+
return this;
|
|
3621
|
+
}
|
|
3622
|
+
/** Adds an animation to the slide's animation sequence. */
|
|
3623
|
+
addAnimation(anim) {
|
|
3624
|
+
if (!this.data.animations) this.data.animations = [];
|
|
3625
|
+
this.data.animations.push(anim);
|
|
3626
|
+
return this;
|
|
3627
|
+
}
|
|
3628
|
+
/** Sets the background fill or image for this slide. */
|
|
3629
|
+
setBackground(bg) {
|
|
3630
|
+
this.data.background = bg;
|
|
3631
|
+
return this;
|
|
3632
|
+
}
|
|
3633
|
+
/**
|
|
3634
|
+
* Adds a group of elements that are positioned and transformed together.
|
|
3635
|
+
* @param buildFn - Callback receiving a {@link GroupBuilder} to populate the group.
|
|
3636
|
+
*/
|
|
3637
|
+
addGroup(buildFn, opts = {}) {
|
|
3638
|
+
const placement = placementFromOpts(opts);
|
|
3639
|
+
const children = [];
|
|
3640
|
+
const groupBuilder = new GroupBuilder(children);
|
|
3641
|
+
buildFn(groupBuilder);
|
|
3642
|
+
const element = new GroupElement(children, placement);
|
|
3643
|
+
this.data.elements.push(element);
|
|
3644
|
+
return this;
|
|
3645
|
+
}
|
|
3646
|
+
/** Adds a connector line between points on the slide. */
|
|
3647
|
+
addConnector(opts) {
|
|
3648
|
+
const placement = placementFromOpts(opts);
|
|
3649
|
+
const element = new ConnectorElement(placement, {
|
|
3650
|
+
type: opts.type,
|
|
3651
|
+
line: opts.line,
|
|
3652
|
+
startArrow: opts.startArrow,
|
|
3653
|
+
endArrow: opts.endArrow
|
|
3654
|
+
});
|
|
3655
|
+
this.data.elements.push(element);
|
|
3656
|
+
return this;
|
|
3657
|
+
}
|
|
3658
|
+
};
|
|
3659
|
+
var GroupBuilder = class {
|
|
3660
|
+
children;
|
|
3661
|
+
constructor(children) {
|
|
3662
|
+
this.children = children;
|
|
3663
|
+
}
|
|
3664
|
+
/** Adds a shape to the group. */
|
|
3665
|
+
addShape(geometry, opts = {}) {
|
|
3666
|
+
const placement = placementFromOpts(opts);
|
|
3667
|
+
this.children.push(
|
|
3668
|
+
new ShapeElement(geometry, placement, {
|
|
3669
|
+
fill: opts.fill,
|
|
3670
|
+
line: opts.line,
|
|
3671
|
+
effects: opts.effects,
|
|
3672
|
+
transform: opts.transform,
|
|
3673
|
+
text: opts.text,
|
|
3674
|
+
textOptions: opts.textOptions,
|
|
3675
|
+
textRunOptions: opts.textRunOptions,
|
|
3676
|
+
textParagraphOptions: opts.textParagraphOptions,
|
|
3677
|
+
adjustValues: opts.adjustValues,
|
|
3678
|
+
hyperlink: opts.hyperlink
|
|
3679
|
+
})
|
|
3680
|
+
);
|
|
3681
|
+
return this;
|
|
3682
|
+
}
|
|
3683
|
+
/** Adds a text box to the group. */
|
|
3684
|
+
addText(text, opts = {}) {
|
|
3685
|
+
const placement = placementFromOpts(opts);
|
|
3686
|
+
this.children.push(
|
|
3687
|
+
TextElement.fromString(
|
|
3688
|
+
text,
|
|
3689
|
+
placement,
|
|
3690
|
+
{
|
|
3691
|
+
bold: opts.bold,
|
|
3692
|
+
italic: opts.italic,
|
|
3693
|
+
underline: opts.underline,
|
|
3694
|
+
fontSize: opts.fontSize,
|
|
3695
|
+
fontFace: opts.fontFace,
|
|
3696
|
+
color: opts.color
|
|
3697
|
+
},
|
|
3698
|
+
{ align: opts.align }
|
|
3699
|
+
)
|
|
3700
|
+
);
|
|
3701
|
+
return this;
|
|
3702
|
+
}
|
|
3703
|
+
/** Adds an image to the group. */
|
|
3704
|
+
addImage(opts) {
|
|
3705
|
+
const placement = placementFromOpts(opts);
|
|
3706
|
+
this.children.push(
|
|
3707
|
+
new ImageElement(placement, {
|
|
3708
|
+
path: opts.path,
|
|
3709
|
+
data: opts.data,
|
|
3710
|
+
contentType: opts.contentType
|
|
3711
|
+
})
|
|
3712
|
+
);
|
|
3713
|
+
return this;
|
|
3714
|
+
}
|
|
3715
|
+
/** Adds a pre-built element directly to the group. */
|
|
3716
|
+
addElement(element) {
|
|
3717
|
+
this.children.push(element);
|
|
3718
|
+
return this;
|
|
3719
|
+
}
|
|
3720
|
+
};
|
|
3721
|
+
|
|
3722
|
+
// src/builder/presentation-builder.ts
|
|
3723
|
+
var Presentation = class {
|
|
3724
|
+
slides = [];
|
|
3725
|
+
registry;
|
|
3726
|
+
theme;
|
|
3727
|
+
masters;
|
|
3728
|
+
layouts;
|
|
3729
|
+
layoutNameMap = /* @__PURE__ */ new Map();
|
|
3730
|
+
presProps = {};
|
|
3731
|
+
viewProps = {};
|
|
3732
|
+
notesMaster;
|
|
3733
|
+
handoutMaster;
|
|
3734
|
+
commentAuthors = [];
|
|
3735
|
+
authorNameMap = /* @__PURE__ */ new Map();
|
|
3736
|
+
presTags = [];
|
|
3737
|
+
opts;
|
|
3738
|
+
/** Creates a new presentation with optional configuration. */
|
|
3739
|
+
constructor(opts) {
|
|
3740
|
+
this.opts = opts ?? {};
|
|
3741
|
+
this.theme = {
|
|
3742
|
+
...defaultTheme,
|
|
3743
|
+
...opts?.theme,
|
|
3744
|
+
colors: { ...defaultTheme.colors, ...opts?.theme?.colors },
|
|
3745
|
+
fonts: { ...defaultTheme.fonts, ...opts?.theme?.fonts }
|
|
3746
|
+
};
|
|
3747
|
+
this.registry = new Registry();
|
|
3748
|
+
this.registry.registerElement("text", textSerializer);
|
|
3749
|
+
this.registry.registerElement("image", imageSerializer);
|
|
3750
|
+
this.registry.registerElement("shape", shapeSerializer);
|
|
3751
|
+
this.registry.registerElement("table", tableSerializer);
|
|
3752
|
+
this.registry.registerElement("chart", chartSerializer);
|
|
3753
|
+
this.registry.registerElement("media", mediaSerializer);
|
|
3754
|
+
this.registry.registerElement("group", createGroupSerializer(this.registry));
|
|
3755
|
+
this.registry.registerElement("connector", connectorSerializer);
|
|
3756
|
+
this.masters = [new SlideMaster({ name: "Default Master" })];
|
|
3757
|
+
this.layouts = [new SlideLayout(builtinLayouts.blank)];
|
|
3758
|
+
this.layoutNameMap.set("blank", 0);
|
|
3759
|
+
}
|
|
3760
|
+
/** Registers a plugin to extend serialization capabilities. */
|
|
3761
|
+
use(plugin) {
|
|
3762
|
+
plugin.install(this.registry);
|
|
3763
|
+
return this;
|
|
3764
|
+
}
|
|
3765
|
+
/** Defines or replaces the default slide master. */
|
|
3766
|
+
defineSlideMaster(def) {
|
|
3767
|
+
this.masters[0] = new SlideMaster(def);
|
|
3768
|
+
return this;
|
|
3769
|
+
}
|
|
3770
|
+
/** Registers a new slide layout that can be referenced by name when adding slides. */
|
|
3771
|
+
defineLayout(def) {
|
|
3772
|
+
const idx = this.layouts.length;
|
|
3773
|
+
this.layouts.push(new SlideLayout(def));
|
|
3774
|
+
this.layoutNameMap.set(def.name, idx);
|
|
3775
|
+
return this;
|
|
3776
|
+
}
|
|
3777
|
+
/** Defines the notes master for speaker notes formatting. */
|
|
3778
|
+
defineNotesMaster(def) {
|
|
3779
|
+
this.notesMaster = new NotesMaster(def);
|
|
3780
|
+
return this;
|
|
3781
|
+
}
|
|
3782
|
+
/** Defines the handout master for printed handout formatting. */
|
|
3783
|
+
defineHandoutMaster(def) {
|
|
3784
|
+
this.handoutMaster = new HandoutMaster(def);
|
|
3785
|
+
return this;
|
|
3786
|
+
}
|
|
3787
|
+
/** Configures slideshow playback properties (e.g., loop, timing). */
|
|
3788
|
+
setShowProperties(props) {
|
|
3789
|
+
this.presProps.slideShow = props;
|
|
3790
|
+
return this;
|
|
3791
|
+
}
|
|
3792
|
+
/** Configures print-related properties. */
|
|
3793
|
+
setPrintProperties(props) {
|
|
3794
|
+
this.presProps.print = props;
|
|
3795
|
+
return this;
|
|
3796
|
+
}
|
|
3797
|
+
/** Sets the default view properties (e.g., normal, slide sorter). */
|
|
3798
|
+
setViewProperties(props) {
|
|
3799
|
+
this.viewProps = props;
|
|
3800
|
+
return this;
|
|
3801
|
+
}
|
|
3802
|
+
/**
|
|
3803
|
+
* Registers a comment author. Returns the author ID, reusing an existing one if the name matches.
|
|
3804
|
+
* @param name - Display name of the author.
|
|
3805
|
+
* @param initials - Author initials shown in comment badges.
|
|
3806
|
+
*/
|
|
3807
|
+
defineCommentAuthor(name, initials) {
|
|
3808
|
+
const existing = this.authorNameMap.get(name);
|
|
3809
|
+
if (existing != null) return existing;
|
|
3810
|
+
const id = this.commentAuthors.length;
|
|
3811
|
+
this.commentAuthors.push({ id, name, initials, lastIdx: 0, clrIdx: id });
|
|
3812
|
+
this.authorNameMap.set(name, id);
|
|
3813
|
+
return id;
|
|
3814
|
+
}
|
|
3815
|
+
/** Sets user-defined tags on the presentation as key-value pairs. */
|
|
3816
|
+
setTags(tags) {
|
|
3817
|
+
this.presTags = Object.entries(tags).map(([name, value]) => ({ name, value }));
|
|
3818
|
+
return this;
|
|
3819
|
+
}
|
|
3820
|
+
/**
|
|
3821
|
+
* Adds a new slide and returns a builder for populating it.
|
|
3822
|
+
* @param layoutName - Name of a previously defined layout; defaults to "blank".
|
|
3823
|
+
*/
|
|
3824
|
+
addSlide(layoutName) {
|
|
3825
|
+
const layoutIndex = layoutName ? this.layoutNameMap.get(layoutName) ?? 0 : 0;
|
|
3826
|
+
const slideData = { elements: [], layoutIndex };
|
|
3827
|
+
this.slides.push(slideData);
|
|
3828
|
+
return new SlideBuilder(slideData, this.commentAuthors);
|
|
3829
|
+
}
|
|
3830
|
+
/** Serializes the presentation to a PPTX file in memory and returns the raw bytes. */
|
|
3831
|
+
toBuffer() {
|
|
3832
|
+
return writePresentation({
|
|
3833
|
+
slides: this.slides,
|
|
3834
|
+
theme: this.theme,
|
|
3835
|
+
registry: this.registry,
|
|
3836
|
+
masters: this.masters,
|
|
3837
|
+
layouts: this.layouts,
|
|
3838
|
+
presProps: this.presProps,
|
|
3839
|
+
viewProps: this.viewProps,
|
|
3840
|
+
notesMaster: this.notesMaster,
|
|
3841
|
+
commentAuthors: this.commentAuthors.length > 0 ? this.commentAuthors : void 0,
|
|
3842
|
+
handoutMaster: this.handoutMaster,
|
|
3843
|
+
tags: this.presTags.length > 0 ? this.presTags : void 0,
|
|
3844
|
+
htmlPublishUri: this.opts.htmlPublishUri,
|
|
3845
|
+
slideUpdateUrl: this.opts.slideUpdateUrl,
|
|
3846
|
+
slideSize: this.opts.slideSize,
|
|
3847
|
+
coreProperties: this.opts.coreProperties
|
|
3848
|
+
});
|
|
3849
|
+
}
|
|
3850
|
+
/** Writes the presentation as a .pptx file to disk (Node.js only). */
|
|
3851
|
+
async toFile(path) {
|
|
3852
|
+
const { writeFile } = await import("fs/promises");
|
|
3853
|
+
const buf = this.toBuffer();
|
|
3854
|
+
await writeFile(path, buf);
|
|
3855
|
+
}
|
|
3856
|
+
};
|
|
3857
|
+
export {
|
|
3858
|
+
ChartElement,
|
|
3859
|
+
ConnectorElement,
|
|
3860
|
+
GroupElement,
|
|
3861
|
+
HandoutMaster,
|
|
3862
|
+
ImageElement,
|
|
3863
|
+
MediaElement,
|
|
3864
|
+
NotesMaster,
|
|
3865
|
+
Presentation,
|
|
3866
|
+
Registry,
|
|
3867
|
+
ShapeElement,
|
|
3868
|
+
SlideBuilder,
|
|
3869
|
+
SlideLayout,
|
|
3870
|
+
SlideMaster,
|
|
3871
|
+
TableElement,
|
|
3872
|
+
TextElement,
|
|
3873
|
+
builtinLayouts,
|
|
3874
|
+
defaultColorScheme,
|
|
3875
|
+
defaultFontScheme,
|
|
3876
|
+
defaultTheme
|
|
3877
|
+
};
|
|
3878
|
+
//# sourceMappingURL=index.js.map
|