documents.js 1.32.0 → 1.33.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +136 -30
- package/dist/index.cjs +134 -1246
- package/dist/index.d.cts +141 -53
- package/dist/index.d.ts +141 -53
- package/dist/index.js +74 -1222
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,154 +1,7 @@
|
|
|
1
|
-
import { AttributeSchema, BinaryPartSchema, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, DefinedNameSchema, PackageSchema, PartSchema, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, attr as attr$1, base64ToBytes, base64ToBytes as base64ToBytes$1, buildXml, bytesToBase64, bytesToBase64 as bytesToBase64$1, childrenWithTag,
|
|
1
|
+
import { AlignmentSchema, AttributeSchema, BinaryPartSchema, BoxSchema, COLOR_BLACK, ColorSchema as LayoutColorSchema, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, DefinedNameSchema, MarginsSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PackageSchema, PageSizeSchema, PartSchema, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, attr as attr$1, base64ToBytes, base64ToBytes as base64ToBytes$1, buildXml, bytesToBase64, bytesToBase64 as bytesToBase64$1, childrenWithTag, colorToRgbHex, compactCodec, compactPackageCodec, decodeCompactPackage, decodeEntities, decodePackage, decodePackage as decodePackage$1, elementsWithTag, encodeCompactPackage, encodePackage, encodePackage as encodePackage$1, fromCompact, isCompactXmlNode, isXmlNode, packageCodec, parsePackage, parseXml, readDocx, readPptx, resolveRelationships, resolveRelationships as resolveRelationships$1, rgbHexToColor, rootElement, rootElement as rootElement$1, serializePackage, textContent, textContent as textContent$1, toCompact, unzipPackage, walk, xmlCodec, zipPackage } from "ooxml.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { Unzlib, inflateSync, unzlibSync, zlibSync } from "fflate";
|
|
4
|
-
//#region src/model/color.ts
|
|
5
|
-
const LayoutColorSchema = z.object({
|
|
6
|
-
r: z.number().min(0).max(1),
|
|
7
|
-
g: z.number().min(0).max(1),
|
|
8
|
-
b: z.number().min(0).max(1)
|
|
9
|
-
});
|
|
10
|
-
const COLOR_BLACK = {
|
|
11
|
-
r: 0,
|
|
12
|
-
g: 0,
|
|
13
|
-
b: 0
|
|
14
|
-
};
|
|
15
|
-
const HEX_COLOR_PATTERN = /^#?([0-9a-fA-F]{6})$/;
|
|
16
|
-
const HEX_BYTE_MAX = 255;
|
|
17
|
-
function rgbHexToColor(hex) {
|
|
18
|
-
const match = HEX_COLOR_PATTERN.exec(hex);
|
|
19
|
-
if (match === null) throw new Error(`not a 6-digit hex colour: ${hex}`);
|
|
20
|
-
const digits = match[1];
|
|
21
|
-
if (digits === void 0) throw new Error(`not a 6-digit hex colour: ${hex}`);
|
|
22
|
-
const r = Number.parseInt(digits.slice(0, 2), 16);
|
|
23
|
-
const g = Number.parseInt(digits.slice(2, 4), 16);
|
|
24
|
-
const b = Number.parseInt(digits.slice(4, 6), 16);
|
|
25
|
-
return {
|
|
26
|
-
r: r / HEX_BYTE_MAX,
|
|
27
|
-
g: g / HEX_BYTE_MAX,
|
|
28
|
-
b: b / HEX_BYTE_MAX
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function toHexByte(component) {
|
|
32
|
-
return Math.round(component * HEX_BYTE_MAX).toString(16).padStart(2, "0");
|
|
33
|
-
}
|
|
34
|
-
function colorToRgbHex(color) {
|
|
35
|
-
return `${toHexByte(color.r)}${toHexByte(color.g)}${toHexByte(color.b)}`;
|
|
36
|
-
}
|
|
37
|
-
const OOXML_PERCENT_SCALE = 1e5;
|
|
38
|
-
function clamp01(x) {
|
|
39
|
-
return Math.max(0, Math.min(1, x));
|
|
40
|
-
}
|
|
41
|
-
function srgbToLinear(c) {
|
|
42
|
-
return c <= .04045 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4;
|
|
43
|
-
}
|
|
44
|
-
function linearToSrgb(c) {
|
|
45
|
-
return c <= .0031308 ? c * 12.92 : 1.055 * c ** (1 / 2.4) - .055;
|
|
46
|
-
}
|
|
47
|
-
function applyShadeOrTint(color, kind, value) {
|
|
48
|
-
const pct = value / OOXML_PERCENT_SCALE;
|
|
49
|
-
const transform = kind === "shade" ? (linear) => linear * pct : (linear) => 1 - (1 - linear) * pct;
|
|
50
|
-
return {
|
|
51
|
-
r: clamp01(linearToSrgb(transform(srgbToLinear(color.r)))),
|
|
52
|
-
g: clamp01(linearToSrgb(transform(srgbToLinear(color.g)))),
|
|
53
|
-
b: clamp01(linearToSrgb(transform(srgbToLinear(color.b))))
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
function rgbToHsl(color) {
|
|
57
|
-
const { r, g, b } = color;
|
|
58
|
-
const max = Math.max(r, g, b);
|
|
59
|
-
const min = Math.min(r, g, b);
|
|
60
|
-
const l = (max + min) / 2;
|
|
61
|
-
if (max === min) return {
|
|
62
|
-
h: 0,
|
|
63
|
-
s: 0,
|
|
64
|
-
l
|
|
65
|
-
};
|
|
66
|
-
const d = max - min;
|
|
67
|
-
const s = l > .5 ? d / (2 - max - min) : d / (max + min);
|
|
68
|
-
let h;
|
|
69
|
-
if (max === r) h = (g - b) / d + (g < b ? 6 : 0);
|
|
70
|
-
else if (max === g) h = (b - r) / d + 2;
|
|
71
|
-
else h = (r - g) / d + 4;
|
|
72
|
-
return {
|
|
73
|
-
h: h * 60,
|
|
74
|
-
s,
|
|
75
|
-
l
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
function hueToRgbComponent(p, q, hue) {
|
|
79
|
-
let t = hue;
|
|
80
|
-
if (t < 0) t += 1;
|
|
81
|
-
if (t > 1) t -= 1;
|
|
82
|
-
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
83
|
-
if (t < 1 / 2) return q;
|
|
84
|
-
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
85
|
-
return p;
|
|
86
|
-
}
|
|
87
|
-
function hslToRgb(hsl) {
|
|
88
|
-
const { h, s, l } = hsl;
|
|
89
|
-
if (s === 0) return {
|
|
90
|
-
r: l,
|
|
91
|
-
g: l,
|
|
92
|
-
b: l
|
|
93
|
-
};
|
|
94
|
-
const q = l < .5 ? l * (1 + s) : l + s - l * s;
|
|
95
|
-
const p = 2 * l - q;
|
|
96
|
-
const hk = h / 360;
|
|
97
|
-
return {
|
|
98
|
-
r: clamp01(hueToRgbComponent(p, q, hk + 1 / 3)),
|
|
99
|
-
g: clamp01(hueToRgbComponent(p, q, hk)),
|
|
100
|
-
b: clamp01(hueToRgbComponent(p, q, hk - 1 / 3))
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
function applyLumModOrOff(color, kind, value) {
|
|
104
|
-
const hsl = rgbToHsl(color);
|
|
105
|
-
const pct = value / OOXML_PERCENT_SCALE;
|
|
106
|
-
const l = clamp01(kind === "lumMod" ? hsl.l * pct : hsl.l + pct);
|
|
107
|
-
return hslToRgb({
|
|
108
|
-
...hsl,
|
|
109
|
-
l
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
function applyColorTransforms(base, transforms) {
|
|
113
|
-
let color = base;
|
|
114
|
-
for (const t of transforms) if (t.kind === "shade" || t.kind === "tint") color = applyShadeOrTint(color, t.kind, t.value);
|
|
115
|
-
for (const t of transforms) if (t.kind === "lumMod" || t.kind === "lumOff") color = applyLumModOrOff(color, t.kind, t.value);
|
|
116
|
-
return color;
|
|
117
|
-
}
|
|
118
|
-
//#endregion
|
|
119
4
|
//#region src/model/geometry.ts
|
|
120
|
-
const BoxSchema = z.object({
|
|
121
|
-
xPt: z.number(),
|
|
122
|
-
yPt: z.number(),
|
|
123
|
-
widthPt: z.number().nonnegative(),
|
|
124
|
-
heightPt: z.number().nonnegative()
|
|
125
|
-
});
|
|
126
|
-
const PageSizeSchema = z.object({
|
|
127
|
-
widthPt: z.number().positive(),
|
|
128
|
-
heightPt: z.number().positive()
|
|
129
|
-
});
|
|
130
|
-
const MarginsSchema = z.object({
|
|
131
|
-
topPt: z.number().nonnegative(),
|
|
132
|
-
rightPt: z.number().nonnegative(),
|
|
133
|
-
bottomPt: z.number().nonnegative(),
|
|
134
|
-
leftPt: z.number().nonnegative()
|
|
135
|
-
});
|
|
136
|
-
const PAGE_SIZE_LETTER = {
|
|
137
|
-
widthPt: 612,
|
|
138
|
-
heightPt: 792
|
|
139
|
-
};
|
|
140
|
-
const PAGE_SIZE_A4 = {
|
|
141
|
-
widthPt: 595.28,
|
|
142
|
-
heightPt: 841.89
|
|
143
|
-
};
|
|
144
|
-
const SLIDE_SIZE_WIDESCREEN = {
|
|
145
|
-
widthPt: 960,
|
|
146
|
-
heightPt: 540
|
|
147
|
-
};
|
|
148
|
-
const SLIDE_SIZE_STANDARD = {
|
|
149
|
-
widthPt: 720,
|
|
150
|
-
heightPt: 540
|
|
151
|
-
};
|
|
152
5
|
function flipY(box, containerHeightPt) {
|
|
153
6
|
return {
|
|
154
7
|
xPt: box.xPt,
|
|
@@ -169,12 +22,6 @@ const DEFAULT_LAYOUT_FONT = {
|
|
|
169
22
|
weight: "normal",
|
|
170
23
|
style: "normal"
|
|
171
24
|
};
|
|
172
|
-
const AlignmentSchema = z.enum([
|
|
173
|
-
"left",
|
|
174
|
-
"center",
|
|
175
|
-
"right",
|
|
176
|
-
"justify"
|
|
177
|
-
]);
|
|
178
25
|
//#endregion
|
|
179
26
|
//#region src/model/layout.ts
|
|
180
27
|
const LAYOUT_FORMAT_VERSION = 1;
|
|
@@ -269,7 +116,7 @@ const LayoutMetadataSchema = z.object({
|
|
|
269
116
|
createdIso: z.string().optional(),
|
|
270
117
|
modifiedIso: z.string().optional()
|
|
271
118
|
});
|
|
272
|
-
z.object({
|
|
119
|
+
const LayoutDocumentSchema = z.object({
|
|
273
120
|
formatVersion: z.literal(1),
|
|
274
121
|
metadata: LayoutMetadataSchema,
|
|
275
122
|
pages: z.array(LayoutPageSchema),
|
|
@@ -385,6 +232,45 @@ const ContentDocumentSchema = z.discriminatedUnion("kind", [z.object({
|
|
|
385
232
|
slides: z.array(ContentSlideSchema)
|
|
386
233
|
})]);
|
|
387
234
|
//#endregion
|
|
235
|
+
//#region src/model/bytes.ts
|
|
236
|
+
const ZIP_LOCAL_FILE_HEADER = [
|
|
237
|
+
80,
|
|
238
|
+
75,
|
|
239
|
+
3,
|
|
240
|
+
4
|
|
241
|
+
];
|
|
242
|
+
const PDF_HEADER = [
|
|
243
|
+
37,
|
|
244
|
+
80,
|
|
245
|
+
68,
|
|
246
|
+
70,
|
|
247
|
+
45
|
|
248
|
+
];
|
|
249
|
+
const PDF_HEADER_SEARCH_WINDOW = 1024;
|
|
250
|
+
function startsWithBytes(bytes, signature) {
|
|
251
|
+
if (bytes.length < signature.length) return false;
|
|
252
|
+
for (let i = 0; i < signature.length; i++) if (bytes[i] !== signature[i]) return false;
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
function containsBytesWithin(bytes, signature, window) {
|
|
256
|
+
const limit = Math.min(bytes.length - signature.length, window);
|
|
257
|
+
for (let start = 0; start <= limit; start++) {
|
|
258
|
+
let matched = true;
|
|
259
|
+
for (let i = 0; i < signature.length; i++) if (bytes[start + i] !== signature[i]) {
|
|
260
|
+
matched = false;
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
if (matched) return true;
|
|
264
|
+
}
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
function zipBytesSchema(label) {
|
|
268
|
+
return z.instanceof(Uint8Array).refine((bytes) => startsWithBytes(bytes, ZIP_LOCAL_FILE_HEADER), { message: `not a valid ${label} file: missing the ZIP local-file-header signature` });
|
|
269
|
+
}
|
|
270
|
+
const DocxBytesSchema = zipBytesSchema("docx");
|
|
271
|
+
const PptxBytesSchema = zipBytesSchema("pptx");
|
|
272
|
+
const PdfBytesSchema = z.instanceof(Uint8Array).refine((bytes) => containsBytesWithin(bytes, PDF_HEADER, PDF_HEADER_SEARCH_WINDOW), { message: "not a valid PDF file: missing the %PDF- header" });
|
|
273
|
+
//#endregion
|
|
388
274
|
//#region src/xml/fragment.ts
|
|
389
275
|
function el(tag, attrs = {}, children = []) {
|
|
390
276
|
return {
|
|
@@ -462,9 +348,6 @@ function emuToPt(emu) {
|
|
|
462
348
|
function ptToEmu(pt) {
|
|
463
349
|
return Math.round(pt * EMU_PER_POINT);
|
|
464
350
|
}
|
|
465
|
-
function twipsToPt(twips) {
|
|
466
|
-
return twips / 20;
|
|
467
|
-
}
|
|
468
351
|
function ptToTwips(pt) {
|
|
469
352
|
return Math.round(pt * 20);
|
|
470
353
|
}
|
|
@@ -474,12 +357,6 @@ function halfPointsToPt(halfPoints) {
|
|
|
474
357
|
function ptToHalfPoints(pt) {
|
|
475
358
|
return Math.round(pt * 2);
|
|
476
359
|
}
|
|
477
|
-
function drawingMlFontSizeToPt(hundredths) {
|
|
478
|
-
return hundredths / 100;
|
|
479
|
-
}
|
|
480
|
-
function lineUnitsToMultiplier(lineUnits) {
|
|
481
|
-
return lineUnits / 240;
|
|
482
|
-
}
|
|
483
360
|
//#endregion
|
|
484
361
|
//#region src/opc/paths.ts
|
|
485
362
|
function relsPathFor(partPath) {
|
|
@@ -1252,16 +1129,16 @@ function buildTable(init) {
|
|
|
1252
1129
|
}
|
|
1253
1130
|
//#endregion
|
|
1254
1131
|
//#region src/edit/docx/editor.ts
|
|
1255
|
-
const DOCUMENT_PART_PATH
|
|
1132
|
+
const DOCUMENT_PART_PATH = "word/document.xml";
|
|
1256
1133
|
const MEDIA_DIR$1 = "word/media";
|
|
1257
1134
|
function findDocumentRoot(pkg) {
|
|
1258
|
-
const root = rootElement$1(pkg.parts[DOCUMENT_PART_PATH
|
|
1259
|
-
if (root === void 0) throw new Error(`package has no root element at ${DOCUMENT_PART_PATH
|
|
1135
|
+
const root = rootElement$1(pkg.parts[DOCUMENT_PART_PATH]);
|
|
1136
|
+
if (root === void 0) throw new Error(`package has no root element at ${DOCUMENT_PART_PATH}`);
|
|
1260
1137
|
return root;
|
|
1261
1138
|
}
|
|
1262
1139
|
function findBody(documentRoot) {
|
|
1263
1140
|
for (const child of documentRoot.children) if (child.type === "element" && child.tag === "w:body") return child;
|
|
1264
|
-
throw new Error(`${DOCUMENT_PART_PATH
|
|
1141
|
+
throw new Error(`${DOCUMENT_PART_PATH} has no w:body element`);
|
|
1265
1142
|
}
|
|
1266
1143
|
function bodyInsertionPoint(body) {
|
|
1267
1144
|
const sectPrIndex = body.children.findIndex((c) => c.type === "element" && c.tag === "w:sectPr");
|
|
@@ -1315,7 +1192,7 @@ var DocxEditor = class {
|
|
|
1315
1192
|
documentRoot,
|
|
1316
1193
|
media: {
|
|
1317
1194
|
pkg,
|
|
1318
|
-
partPath: DOCUMENT_PART_PATH
|
|
1195
|
+
partPath: DOCUMENT_PART_PATH,
|
|
1319
1196
|
mediaDir: MEDIA_DIR$1
|
|
1320
1197
|
}
|
|
1321
1198
|
};
|
|
@@ -1329,7 +1206,7 @@ var DocxEditor = class {
|
|
|
1329
1206
|
documentRoot,
|
|
1330
1207
|
media: {
|
|
1331
1208
|
pkg: this.pkg,
|
|
1332
|
-
partPath: DOCUMENT_PART_PATH
|
|
1209
|
+
partPath: DOCUMENT_PART_PATH,
|
|
1333
1210
|
mediaDir: MEDIA_DIR$1
|
|
1334
1211
|
}
|
|
1335
1212
|
};
|
|
@@ -4733,7 +4610,7 @@ function createFontResolver(context) {
|
|
|
4733
4610
|
}
|
|
4734
4611
|
//#endregion
|
|
4735
4612
|
//#region src/image/png-encode.ts
|
|
4736
|
-
const PNG_SIGNATURE$
|
|
4613
|
+
const PNG_SIGNATURE$1 = new Uint8Array([
|
|
4737
4614
|
137,
|
|
4738
4615
|
80,
|
|
4739
4616
|
78,
|
|
@@ -4782,7 +4659,7 @@ function encodePng(image, options = {}) {
|
|
|
4782
4659
|
ihdr[11] = 0;
|
|
4783
4660
|
ihdr[12] = 0;
|
|
4784
4661
|
const writer = new ByteWriter();
|
|
4785
|
-
writer.writeBytes(PNG_SIGNATURE$
|
|
4662
|
+
writer.writeBytes(PNG_SIGNATURE$1);
|
|
4786
4663
|
writeChunk(writer, "IHDR", ihdr);
|
|
4787
4664
|
writeChunk(writer, "IDAT", compressed);
|
|
4788
4665
|
writeChunk(writer, "IEND", /* @__PURE__ */ new Uint8Array(0));
|
|
@@ -6015,7 +5892,7 @@ function readMetadata(trailer, resolver) {
|
|
|
6015
5892
|
}
|
|
6016
5893
|
//#endregion
|
|
6017
5894
|
//#region src/image/png-decode.ts
|
|
6018
|
-
const PNG_SIGNATURE
|
|
5895
|
+
const PNG_SIGNATURE = [
|
|
6019
5896
|
137,
|
|
6020
5897
|
80,
|
|
6021
5898
|
78,
|
|
@@ -6031,7 +5908,7 @@ function requireDataView(bytes) {
|
|
|
6031
5908
|
function readChunks(bytes, onWarning) {
|
|
6032
5909
|
const chunks = [];
|
|
6033
5910
|
const view = requireDataView(bytes);
|
|
6034
|
-
let offset = PNG_SIGNATURE
|
|
5911
|
+
let offset = PNG_SIGNATURE.length;
|
|
6035
5912
|
while (offset + 8 <= bytes.length) {
|
|
6036
5913
|
const length = view.getUint32(offset);
|
|
6037
5914
|
const typeBytes = bytes.subarray(offset + 4, offset + 8);
|
|
@@ -6106,7 +5983,7 @@ function scaleToByte(sample, bitDepth) {
|
|
|
6106
5983
|
return Math.round(sample * 255 / maxSample);
|
|
6107
5984
|
}
|
|
6108
5985
|
function decodePng(bytes, options = {}) {
|
|
6109
|
-
for (let i = 0; i < PNG_SIGNATURE
|
|
5986
|
+
for (let i = 0; i < PNG_SIGNATURE.length; i++) if (bytes[i] !== PNG_SIGNATURE[i]) throw new Error("not a valid PNG file: bad signature");
|
|
6110
5987
|
const chunks = readChunks(bytes, options.onWarning);
|
|
6111
5988
|
const ihdrChunk = chunks[0];
|
|
6112
5989
|
if (ihdrChunk?.type !== "IHDR") throw new Error("PNG file does not begin with an IHDR chunk");
|
|
@@ -6736,1066 +6613,31 @@ function writePdf(doc, options = {}) {
|
|
|
6736
6613
|
return writer.toBytes();
|
|
6737
6614
|
}
|
|
6738
6615
|
//#endregion
|
|
6739
|
-
//#region src/
|
|
6740
|
-
const
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
const element = childrenWithTag$1(root, tag)[0];
|
|
6745
|
-
if (element === void 0) return;
|
|
6746
|
-
const text = textContent$1(element);
|
|
6747
|
-
return text.length > 0 ? text : void 0;
|
|
6748
|
-
}
|
|
6749
|
-
function readKeywords(core) {
|
|
6750
|
-
const raw = firstElementText(core, "cp:keywords");
|
|
6751
|
-
if (raw === void 0) return;
|
|
6752
|
-
const parts = raw.split(",").map((part) => part.trim()).filter((part) => part.length > 0);
|
|
6753
|
-
return parts.length > 0 ? parts : void 0;
|
|
6754
|
-
}
|
|
6755
|
-
function readCoreProperties(pkg) {
|
|
6756
|
-
const core = rootElement$1(pkg.parts[CORE_PROPERTIES_PATH]);
|
|
6757
|
-
const app = rootElement$1(pkg.parts[APP_PROPERTIES_PATH]);
|
|
6758
|
-
return {
|
|
6759
|
-
title: firstElementText(core, "dc:title"),
|
|
6760
|
-
author: firstElementText(core, "dc:creator"),
|
|
6761
|
-
subject: firstElementText(core, "dc:subject"),
|
|
6762
|
-
keywords: readKeywords(core),
|
|
6763
|
-
creator: firstElementText(app, "Application"),
|
|
6764
|
-
createdIso: firstElementText(core, "dcterms:created"),
|
|
6765
|
-
modifiedIso: firstElementText(core, "dcterms:modified")
|
|
6766
|
-
};
|
|
6767
|
-
}
|
|
6768
|
-
//#endregion
|
|
6769
|
-
//#region src/ooxml/drawingml.ts
|
|
6770
|
-
const ROTATION_UNITS_PER_DEGREE = 6e4;
|
|
6771
|
-
function readXfrm(xfrm) {
|
|
6772
|
-
if (xfrm === void 0) return;
|
|
6773
|
-
const off = childrenWithTag$1(xfrm, "a:off")[0];
|
|
6774
|
-
const ext = childrenWithTag$1(xfrm, "a:ext")[0];
|
|
6775
|
-
if (off === void 0 || ext === void 0) return;
|
|
6776
|
-
const x = attr$1(off, "x");
|
|
6777
|
-
const y = attr$1(off, "y");
|
|
6778
|
-
const cx = attr$1(ext, "cx");
|
|
6779
|
-
const cy = attr$1(ext, "cy");
|
|
6780
|
-
if (x === void 0 || y === void 0 || cx === void 0 || cy === void 0) return;
|
|
6781
|
-
const rot = attr$1(xfrm, "rot");
|
|
6782
|
-
return {
|
|
6783
|
-
xPt: emuToPt(Number(x)),
|
|
6784
|
-
yPt: emuToPt(Number(y)),
|
|
6785
|
-
widthPt: emuToPt(Number(cx)),
|
|
6786
|
-
heightPt: emuToPt(Number(cy)),
|
|
6787
|
-
rotationDeg: rot === void 0 ? 0 : Number(rot) / ROTATION_UNITS_PER_DEGREE,
|
|
6788
|
-
flipH: attr$1(xfrm, "flipH") === "1",
|
|
6789
|
-
flipV: attr$1(xfrm, "flipV") === "1"
|
|
6790
|
-
};
|
|
6791
|
-
}
|
|
6792
|
-
const CLR_SCHEME_SLOTS = [
|
|
6793
|
-
"dk1",
|
|
6794
|
-
"lt1",
|
|
6795
|
-
"dk2",
|
|
6796
|
-
"lt2",
|
|
6797
|
-
"accent1",
|
|
6798
|
-
"accent2",
|
|
6799
|
-
"accent3",
|
|
6800
|
-
"accent4",
|
|
6801
|
-
"accent5",
|
|
6802
|
-
"accent6",
|
|
6803
|
-
"hlink",
|
|
6804
|
-
"folHlink"
|
|
6805
|
-
];
|
|
6806
|
-
function readThemeSlotColor(colorEl) {
|
|
6807
|
-
if (colorEl.tag === "a:srgbClr") {
|
|
6808
|
-
const val = attr$1(colorEl, "val");
|
|
6809
|
-
return val === void 0 ? void 0 : rgbHexToColor(val);
|
|
6810
|
-
}
|
|
6811
|
-
if (colorEl.tag === "a:sysClr") {
|
|
6812
|
-
const lastClr = attr$1(colorEl, "lastClr");
|
|
6813
|
-
if (lastClr !== void 0) return rgbHexToColor(lastClr);
|
|
6814
|
-
return attr$1(colorEl, "val") === "window" ? {
|
|
6815
|
-
r: 1,
|
|
6816
|
-
g: 1,
|
|
6817
|
-
b: 1
|
|
6818
|
-
} : {
|
|
6819
|
-
r: 0,
|
|
6820
|
-
g: 0,
|
|
6821
|
-
b: 0
|
|
6822
|
-
};
|
|
6823
|
-
}
|
|
6824
|
-
}
|
|
6825
|
-
function readClrScheme(clrSchemeEl) {
|
|
6826
|
-
const map = /* @__PURE__ */ new Map();
|
|
6827
|
-
for (const slot of CLR_SCHEME_SLOTS) {
|
|
6828
|
-
const wrapper = childrenWithTag$1(clrSchemeEl, `a:${slot}`)[0];
|
|
6829
|
-
if (wrapper === void 0) continue;
|
|
6830
|
-
const colorEl = wrapper.children.find((c) => c.type === "element");
|
|
6831
|
-
if (colorEl === void 0) continue;
|
|
6832
|
-
const color = readThemeSlotColor(colorEl);
|
|
6833
|
-
if (color !== void 0) map.set(slot, color);
|
|
6834
|
-
}
|
|
6835
|
-
return map;
|
|
6836
|
-
}
|
|
6837
|
-
function readSchemeFont(fontSchemeEl, tag) {
|
|
6838
|
-
if (fontSchemeEl === void 0) return;
|
|
6839
|
-
const fontEl = childrenWithTag$1(fontSchemeEl, tag)[0];
|
|
6840
|
-
const latin = fontEl === void 0 ? void 0 : childrenWithTag$1(fontEl, "a:latin")[0];
|
|
6841
|
-
return latin === void 0 ? void 0 : attr$1(latin, "typeface");
|
|
6842
|
-
}
|
|
6843
|
-
const DEFAULT_THEME_FONT = "Calibri";
|
|
6844
|
-
const EMPTY_THEME = {
|
|
6845
|
-
colorScheme: /* @__PURE__ */ new Map(),
|
|
6846
|
-
majorFont: DEFAULT_THEME_FONT,
|
|
6847
|
-
minorFont: DEFAULT_THEME_FONT
|
|
6848
|
-
};
|
|
6849
|
-
function readTheme(themeRoot) {
|
|
6850
|
-
const clrSchemeEl = elementsWithTag$1([themeRoot], "a:clrScheme")[0];
|
|
6851
|
-
const colorScheme = clrSchemeEl === void 0 ? /* @__PURE__ */ new Map() : readClrScheme(clrSchemeEl);
|
|
6852
|
-
const fontSchemeEl = elementsWithTag$1([themeRoot], "a:fontScheme")[0];
|
|
6853
|
-
return {
|
|
6854
|
-
colorScheme,
|
|
6855
|
-
majorFont: readSchemeFont(fontSchemeEl, "a:majorFont") ?? DEFAULT_THEME_FONT,
|
|
6856
|
-
minorFont: readSchemeFont(fontSchemeEl, "a:minorFont") ?? DEFAULT_THEME_FONT
|
|
6857
|
-
};
|
|
6858
|
-
}
|
|
6859
|
-
function resolveThemeFontReference(typeface, theme) {
|
|
6860
|
-
if (typeface === "+mj-lt") return theme.majorFont;
|
|
6861
|
-
if (typeface === "+mn-lt") return theme.minorFont;
|
|
6862
|
-
return typeface;
|
|
6863
|
-
}
|
|
6864
|
-
function readColorMap(clrMapEl) {
|
|
6865
|
-
const map = /* @__PURE__ */ new Map();
|
|
6866
|
-
if (clrMapEl === void 0) return map;
|
|
6867
|
-
for (const a of clrMapEl.attributes) map.set(a.name, a.value);
|
|
6868
|
-
return map;
|
|
6869
|
-
}
|
|
6870
|
-
function resolveSchemeColorSlot(schemeVal, colorMap) {
|
|
6871
|
-
return colorMap.get(schemeVal) ?? schemeVal;
|
|
6872
|
-
}
|
|
6873
|
-
const COLOR_TRANSFORM_TAGS = /* @__PURE__ */ new Map([
|
|
6874
|
-
["a:shade", "shade"],
|
|
6875
|
-
["a:tint", "tint"],
|
|
6876
|
-
["a:lumMod", "lumMod"],
|
|
6877
|
-
["a:lumOff", "lumOff"]
|
|
6878
|
-
]);
|
|
6879
|
-
function readColorTransforms(container) {
|
|
6880
|
-
const transforms = [];
|
|
6881
|
-
for (const child of container.children) {
|
|
6882
|
-
if (child.type !== "element") continue;
|
|
6883
|
-
const kind = COLOR_TRANSFORM_TAGS.get(child.tag);
|
|
6884
|
-
if (kind === void 0) continue;
|
|
6885
|
-
const val = attr$1(child, "val");
|
|
6886
|
-
if (val === void 0) continue;
|
|
6887
|
-
transforms.push({
|
|
6888
|
-
kind,
|
|
6889
|
-
value: Number(val)
|
|
6890
|
-
});
|
|
6891
|
-
}
|
|
6892
|
-
return transforms;
|
|
6893
|
-
}
|
|
6894
|
-
function readSchemeColor(schemeClrEl, colorMap, theme) {
|
|
6895
|
-
const val = attr$1(schemeClrEl, "val");
|
|
6896
|
-
if (val === void 0) return;
|
|
6897
|
-
const base = theme.colorScheme.get(resolveSchemeColorSlot(val, colorMap));
|
|
6898
|
-
return base === void 0 ? void 0 : applyColorTransforms(base, readColorTransforms(schemeClrEl));
|
|
6899
|
-
}
|
|
6900
|
-
function readSrgbColor(srgbClrEl) {
|
|
6901
|
-
const val = attr$1(srgbClrEl, "val");
|
|
6902
|
-
return val === void 0 ? void 0 : applyColorTransforms(rgbHexToColor(val), readColorTransforms(srgbClrEl));
|
|
6903
|
-
}
|
|
6904
|
-
function readSolidFillColor(solidFillEl, colorMap, theme) {
|
|
6905
|
-
if (solidFillEl === void 0) return;
|
|
6906
|
-
const schemeClr = childrenWithTag$1(solidFillEl, "a:schemeClr")[0];
|
|
6907
|
-
if (schemeClr !== void 0) return readSchemeColor(schemeClr, colorMap, theme);
|
|
6908
|
-
const srgbClr = childrenWithTag$1(solidFillEl, "a:srgbClr")[0];
|
|
6909
|
-
return srgbClr === void 0 ? void 0 : readSrgbColor(srgbClr);
|
|
6910
|
-
}
|
|
6911
|
-
function readGroupXfrm(xfrm) {
|
|
6912
|
-
const base = readXfrm(xfrm);
|
|
6913
|
-
if (base === void 0 || xfrm === void 0) return;
|
|
6914
|
-
const chOff = childrenWithTag$1(xfrm, "a:chOff")[0];
|
|
6915
|
-
const chExt = childrenWithTag$1(xfrm, "a:chExt")[0];
|
|
6916
|
-
if (chOff === void 0 || chExt === void 0) return;
|
|
6917
|
-
const cx = attr$1(chOff, "x");
|
|
6918
|
-
const cy = attr$1(chOff, "y");
|
|
6919
|
-
const ccx = attr$1(chExt, "cx");
|
|
6920
|
-
const ccy = attr$1(chExt, "cy");
|
|
6921
|
-
if (cx === void 0 || cy === void 0 || ccx === void 0 || ccy === void 0) return;
|
|
6922
|
-
return {
|
|
6923
|
-
offXPt: base.xPt,
|
|
6924
|
-
offYPt: base.yPt,
|
|
6925
|
-
extWidthPt: base.widthPt,
|
|
6926
|
-
extHeightPt: base.heightPt,
|
|
6927
|
-
childOffXPt: emuToPt(Number(cx)),
|
|
6928
|
-
childOffYPt: emuToPt(Number(cy)),
|
|
6929
|
-
childExtWidthPt: emuToPt(Number(ccx)),
|
|
6930
|
-
childExtHeightPt: emuToPt(Number(ccy))
|
|
6931
|
-
};
|
|
6932
|
-
}
|
|
6933
|
-
function applyGroupTransform(group, childFrame) {
|
|
6934
|
-
const scaleX = group.childExtWidthPt === 0 ? 1 : group.extWidthPt / group.childExtWidthPt;
|
|
6935
|
-
const scaleY = group.childExtHeightPt === 0 ? 1 : group.extHeightPt / group.childExtHeightPt;
|
|
6936
|
-
return {
|
|
6937
|
-
xPt: group.offXPt + (childFrame.xPt - group.childOffXPt) * scaleX,
|
|
6938
|
-
yPt: group.offYPt + (childFrame.yPt - group.childOffYPt) * scaleY,
|
|
6939
|
-
widthPt: childFrame.widthPt * scaleX,
|
|
6940
|
-
heightPt: childFrame.heightPt * scaleY
|
|
6941
|
-
};
|
|
6942
|
-
}
|
|
6943
|
-
//#endregion
|
|
6944
|
-
//#region src/ooxml/docx/styles.ts
|
|
6945
|
-
function mergeParagraphLayer(base, layer) {
|
|
6946
|
-
return {
|
|
6947
|
-
alignment: layer.alignment ?? base.alignment,
|
|
6948
|
-
spacingBeforePt: layer.spacingBeforePt ?? base.spacingBeforePt,
|
|
6949
|
-
spacingAfterPt: layer.spacingAfterPt ?? base.spacingAfterPt,
|
|
6950
|
-
lineSpacing: layer.lineSpacing ?? base.lineSpacing,
|
|
6951
|
-
indentLeftPt: layer.indentLeftPt ?? base.indentLeftPt,
|
|
6952
|
-
indentFirstLinePt: layer.indentFirstLinePt ?? base.indentFirstLinePt
|
|
6953
|
-
};
|
|
6954
|
-
}
|
|
6955
|
-
function mergeRunLayer(base, layer) {
|
|
6956
|
-
return {
|
|
6957
|
-
bold: layer.bold ?? base.bold,
|
|
6958
|
-
italic: layer.italic ?? base.italic,
|
|
6959
|
-
underline: layer.underline ?? base.underline,
|
|
6960
|
-
strike: layer.strike ?? base.strike,
|
|
6961
|
-
fontFamily: layer.fontFamily ?? base.fontFamily,
|
|
6962
|
-
sizePt: layer.sizePt ?? base.sizePt,
|
|
6963
|
-
color: layer.color ?? base.color
|
|
6964
|
-
};
|
|
6965
|
-
}
|
|
6966
|
-
function readToggle$1(el) {
|
|
6967
|
-
if (el === void 0) return;
|
|
6968
|
-
const val = attr$1(el, "w:val");
|
|
6969
|
-
return val === void 0 || val !== "0" && val !== "false" && val !== "off";
|
|
6970
|
-
}
|
|
6971
|
-
function readUnderline(u) {
|
|
6972
|
-
if (u === void 0) return;
|
|
6973
|
-
const val = attr$1(u, "w:val");
|
|
6974
|
-
return val !== void 0 && val !== "none";
|
|
6975
|
-
}
|
|
6976
|
-
function readRunColor(colorEl) {
|
|
6977
|
-
if (colorEl === void 0) return;
|
|
6978
|
-
const val = attr$1(colorEl, "w:val");
|
|
6979
|
-
return val === void 0 || val === "auto" ? void 0 : rgbHexToColor(val);
|
|
6980
|
-
}
|
|
6981
|
-
function readRunFontFamily(rFonts, theme) {
|
|
6982
|
-
if (rFonts === void 0) return;
|
|
6983
|
-
const ascii = attr$1(rFonts, "w:ascii");
|
|
6984
|
-
if (ascii !== void 0) return ascii;
|
|
6985
|
-
const asciiTheme = attr$1(rFonts, "w:asciiTheme");
|
|
6986
|
-
if (asciiTheme === "majorHAnsi" || asciiTheme === "majorAscii") return theme.majorFont;
|
|
6987
|
-
if (asciiTheme === "minorHAnsi" || asciiTheme === "minorAscii") return theme.minorFont;
|
|
6988
|
-
}
|
|
6989
|
-
function readRunPropertiesLayer(rPr, theme) {
|
|
6990
|
-
if (rPr === void 0) return {};
|
|
6991
|
-
const sz = childrenWithTag$1(rPr, "w:sz")[0];
|
|
6992
|
-
const szVal = sz === void 0 ? void 0 : attr$1(sz, "w:val");
|
|
6993
|
-
return {
|
|
6994
|
-
bold: readToggle$1(childrenWithTag$1(rPr, "w:b")[0]),
|
|
6995
|
-
italic: readToggle$1(childrenWithTag$1(rPr, "w:i")[0]),
|
|
6996
|
-
underline: readUnderline(childrenWithTag$1(rPr, "w:u")[0]),
|
|
6997
|
-
strike: readToggle$1(childrenWithTag$1(rPr, "w:strike")[0]),
|
|
6998
|
-
fontFamily: readRunFontFamily(childrenWithTag$1(rPr, "w:rFonts")[0], theme),
|
|
6999
|
-
sizePt: szVal === void 0 ? void 0 : halfPointsToPt(Number(szVal)),
|
|
7000
|
-
color: readRunColor(childrenWithTag$1(rPr, "w:color")[0])
|
|
7001
|
-
};
|
|
7002
|
-
}
|
|
7003
|
-
function readAlignment$1(jc) {
|
|
7004
|
-
const val = jc === void 0 ? void 0 : attr$1(jc, "w:val");
|
|
7005
|
-
if (val === "left" || val === "start") return "left";
|
|
7006
|
-
if (val === "center") return "center";
|
|
7007
|
-
if (val === "right" || val === "end") return "right";
|
|
7008
|
-
if (val === "both" || val === "distribute") return "justify";
|
|
7009
|
-
}
|
|
7010
|
-
function readParagraphPropertiesLayer(pPr) {
|
|
7011
|
-
if (pPr === void 0) return {};
|
|
7012
|
-
const spacing = childrenWithTag$1(pPr, "w:spacing")[0];
|
|
7013
|
-
const before = spacing === void 0 ? void 0 : attr$1(spacing, "w:before");
|
|
7014
|
-
const after = spacing === void 0 ? void 0 : attr$1(spacing, "w:after");
|
|
7015
|
-
const line = spacing === void 0 ? void 0 : attr$1(spacing, "w:line");
|
|
7016
|
-
const lineRule = spacing === void 0 ? void 0 : attr$1(spacing, "w:lineRule");
|
|
7017
|
-
const ind = childrenWithTag$1(pPr, "w:ind")[0];
|
|
7018
|
-
const left = ind === void 0 ? void 0 : attr$1(ind, "w:left") ?? attr$1(ind, "w:start");
|
|
7019
|
-
const firstLine = ind === void 0 ? void 0 : attr$1(ind, "w:firstLine");
|
|
7020
|
-
const hanging = ind === void 0 ? void 0 : attr$1(ind, "w:hanging");
|
|
7021
|
-
return {
|
|
7022
|
-
alignment: readAlignment$1(childrenWithTag$1(pPr, "w:jc")[0]),
|
|
7023
|
-
spacingBeforePt: before === void 0 ? void 0 : twipsToPt(Number(before)),
|
|
7024
|
-
spacingAfterPt: after === void 0 ? void 0 : twipsToPt(Number(after)),
|
|
7025
|
-
lineSpacing: line === void 0 || lineRule === "exact" || lineRule === "atLeast" ? void 0 : lineUnitsToMultiplier(Number(line)),
|
|
7026
|
-
indentLeftPt: left === void 0 ? void 0 : twipsToPt(Number(left)),
|
|
7027
|
-
indentFirstLinePt: firstLine !== void 0 ? twipsToPt(Number(firstLine)) : hanging !== void 0 ? -twipsToPt(Number(hanging)) : void 0
|
|
7028
|
-
};
|
|
7029
|
-
}
|
|
7030
|
-
function findStyle(stylesRoot, styleId, type) {
|
|
7031
|
-
return elementsWithTag$1([stylesRoot], "w:style").find((s) => attr$1(s, "w:type") === type && attr$1(s, "w:styleId") === styleId);
|
|
7032
|
-
}
|
|
7033
|
-
function findDefaultStyle(stylesRoot, type) {
|
|
7034
|
-
return elementsWithTag$1([stylesRoot], "w:style").find((s) => attr$1(s, "w:type") === type && attr$1(s, "w:default") === "1");
|
|
7035
|
-
}
|
|
7036
|
-
function resolveBasedOnChain(stylesRoot, styleId, type) {
|
|
7037
|
-
const chain = [];
|
|
7038
|
-
const visited = /* @__PURE__ */ new Set();
|
|
7039
|
-
let currentId = styleId;
|
|
7040
|
-
while (currentId !== void 0 && !visited.has(currentId)) {
|
|
7041
|
-
visited.add(currentId);
|
|
7042
|
-
const style = findStyle(stylesRoot, currentId, type);
|
|
7043
|
-
if (style === void 0) break;
|
|
7044
|
-
chain.unshift(style);
|
|
7045
|
-
const basedOn = childrenWithTag$1(style, "w:basedOn")[0];
|
|
7046
|
-
currentId = basedOn === void 0 ? void 0 : attr$1(basedOn, "w:val");
|
|
7047
|
-
}
|
|
7048
|
-
return chain;
|
|
7049
|
-
}
|
|
7050
|
-
function docDefaultsElement(stylesRoot, wrapperTag, innerTag) {
|
|
7051
|
-
const docDefaults = stylesRoot === void 0 ? void 0 : childrenWithTag$1(stylesRoot, "w:docDefaults")[0];
|
|
7052
|
-
const wrapper = docDefaults === void 0 ? void 0 : childrenWithTag$1(docDefaults, wrapperTag)[0];
|
|
7053
|
-
return wrapper === void 0 ? void 0 : childrenWithTag$1(wrapper, innerTag)[0];
|
|
7054
|
-
}
|
|
7055
|
-
function resolveParagraphProperties(paragraph, context) {
|
|
7056
|
-
const pPr = childrenWithTag$1(paragraph, "w:pPr")[0];
|
|
7057
|
-
const pStyleEl = pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "w:pStyle")[0];
|
|
7058
|
-
const styleId = pStyleEl === void 0 ? void 0 : attr$1(pStyleEl, "w:val");
|
|
7059
|
-
let resolved = readParagraphPropertiesLayer(docDefaultsElement(context.stylesRoot, "w:pPrDefault", "w:pPr"));
|
|
7060
|
-
if (context.stylesRoot !== void 0) {
|
|
7061
|
-
const defaultStyle = findDefaultStyle(context.stylesRoot, "paragraph");
|
|
7062
|
-
if (defaultStyle !== void 0) resolved = mergeParagraphLayer(resolved, readParagraphPropertiesLayer(childrenWithTag$1(defaultStyle, "w:pPr")[0]));
|
|
7063
|
-
if (styleId !== void 0) for (const style of resolveBasedOnChain(context.stylesRoot, styleId, "paragraph")) resolved = mergeParagraphLayer(resolved, readParagraphPropertiesLayer(childrenWithTag$1(style, "w:pPr")[0]));
|
|
7064
|
-
}
|
|
7065
|
-
return mergeParagraphLayer(resolved, readParagraphPropertiesLayer(pPr));
|
|
7066
|
-
}
|
|
7067
|
-
function resolveRunProperties(run, paragraph, context) {
|
|
7068
|
-
const pPr = childrenWithTag$1(paragraph, "w:pPr")[0];
|
|
7069
|
-
const pStyleEl = pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "w:pStyle")[0];
|
|
7070
|
-
const pStyleId = pStyleEl === void 0 ? void 0 : attr$1(pStyleEl, "w:val");
|
|
7071
|
-
let resolved = readRunPropertiesLayer(docDefaultsElement(context.stylesRoot, "w:rPrDefault", "w:rPr"), context.theme);
|
|
7072
|
-
if (context.stylesRoot !== void 0) {
|
|
7073
|
-
const defaultStyle = findDefaultStyle(context.stylesRoot, "paragraph");
|
|
7074
|
-
if (defaultStyle !== void 0) resolved = mergeRunLayer(resolved, readRunPropertiesLayer(childrenWithTag$1(defaultStyle, "w:rPr")[0], context.theme));
|
|
7075
|
-
if (pStyleId !== void 0) for (const style of resolveBasedOnChain(context.stylesRoot, pStyleId, "paragraph")) resolved = mergeRunLayer(resolved, readRunPropertiesLayer(childrenWithTag$1(style, "w:rPr")[0], context.theme));
|
|
7076
|
-
}
|
|
7077
|
-
const paragraphMarkRPr = pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "w:rPr")[0];
|
|
7078
|
-
resolved = mergeRunLayer(resolved, readRunPropertiesLayer(paragraphMarkRPr, context.theme));
|
|
7079
|
-
const rPr = childrenWithTag$1(run, "w:rPr")[0];
|
|
7080
|
-
const rStyleEl = rPr === void 0 ? void 0 : childrenWithTag$1(rPr, "w:rStyle")[0];
|
|
7081
|
-
const rStyleId = rStyleEl === void 0 ? void 0 : attr$1(rStyleEl, "w:val");
|
|
7082
|
-
if (context.stylesRoot !== void 0 && rStyleId !== void 0) for (const style of resolveBasedOnChain(context.stylesRoot, rStyleId, "character")) resolved = mergeRunLayer(resolved, readRunPropertiesLayer(childrenWithTag$1(style, "w:rPr")[0], context.theme));
|
|
7083
|
-
return mergeRunLayer(resolved, readRunPropertiesLayer(rPr, context.theme));
|
|
7084
|
-
}
|
|
6616
|
+
//#region src/pdf/codec.ts
|
|
6617
|
+
const pdfCodec = z.codec(PdfBytesSchema, LayoutDocumentSchema, {
|
|
6618
|
+
decode: (bytes) => readPdf(bytes),
|
|
6619
|
+
encode: (doc) => writePdf(doc)
|
|
6620
|
+
});
|
|
7085
6621
|
//#endregion
|
|
7086
6622
|
//#region src/ooxml/docx/read.ts
|
|
7087
|
-
const DOCUMENT_PART_PATH = "word/document.xml";
|
|
7088
|
-
const STYLES_PART_PATH = "word/styles.xml";
|
|
7089
|
-
const THEME_REL_SUFFIX$1 = "/theme";
|
|
7090
|
-
const DEFAULT_MARGIN_PT = 72;
|
|
7091
|
-
const DEFAULT_MARGINS = {
|
|
7092
|
-
topPt: DEFAULT_MARGIN_PT,
|
|
7093
|
-
rightPt: DEFAULT_MARGIN_PT,
|
|
7094
|
-
bottomPt: DEFAULT_MARGIN_PT,
|
|
7095
|
-
leftPt: DEFAULT_MARGIN_PT
|
|
7096
|
-
};
|
|
7097
|
-
function readPageSize(sectPr) {
|
|
7098
|
-
const pgSz = childrenWithTag$1(sectPr, "w:pgSz")[0];
|
|
7099
|
-
const w = pgSz === void 0 ? void 0 : attr$1(pgSz, "w:w");
|
|
7100
|
-
const h = pgSz === void 0 ? void 0 : attr$1(pgSz, "w:h");
|
|
7101
|
-
return w === void 0 || h === void 0 ? PAGE_SIZE_LETTER : {
|
|
7102
|
-
widthPt: twipsToPt(Number(w)),
|
|
7103
|
-
heightPt: twipsToPt(Number(h))
|
|
7104
|
-
};
|
|
7105
|
-
}
|
|
7106
|
-
function readMargins(sectPr) {
|
|
7107
|
-
const pgMar = childrenWithTag$1(sectPr, "w:pgMar")[0];
|
|
7108
|
-
if (pgMar === void 0) return DEFAULT_MARGINS;
|
|
7109
|
-
const top = attr$1(pgMar, "w:top");
|
|
7110
|
-
const right = attr$1(pgMar, "w:right");
|
|
7111
|
-
const bottom = attr$1(pgMar, "w:bottom");
|
|
7112
|
-
const left = attr$1(pgMar, "w:left");
|
|
7113
|
-
return {
|
|
7114
|
-
topPt: top === void 0 ? DEFAULT_MARGIN_PT : twipsToPt(Number(top)),
|
|
7115
|
-
rightPt: right === void 0 ? DEFAULT_MARGIN_PT : twipsToPt(Number(right)),
|
|
7116
|
-
bottomPt: bottom === void 0 ? DEFAULT_MARGIN_PT : twipsToPt(Number(bottom)),
|
|
7117
|
-
leftPt: left === void 0 ? DEFAULT_MARGIN_PT : twipsToPt(Number(left))
|
|
7118
|
-
};
|
|
7119
|
-
}
|
|
7120
|
-
function readListMembership(pPr) {
|
|
7121
|
-
const numPr = pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "w:numPr")[0];
|
|
7122
|
-
if (numPr === void 0) return;
|
|
7123
|
-
const numIdEl = childrenWithTag$1(numPr, "w:numId")[0];
|
|
7124
|
-
const numId = numIdEl === void 0 ? void 0 : attr$1(numIdEl, "w:val");
|
|
7125
|
-
if (numId === void 0) return;
|
|
7126
|
-
const ilvlEl = childrenWithTag$1(numPr, "w:ilvl")[0];
|
|
7127
|
-
const ilvlVal = ilvlEl === void 0 ? void 0 : attr$1(ilvlEl, "w:val");
|
|
7128
|
-
return {
|
|
7129
|
-
numId,
|
|
7130
|
-
level: ilvlVal === void 0 ? 0 : Number(ilvlVal)
|
|
7131
|
-
};
|
|
7132
|
-
}
|
|
7133
|
-
function readToggle(el) {
|
|
7134
|
-
if (el === void 0) return false;
|
|
7135
|
-
const val = attr$1(el, "w:val");
|
|
7136
|
-
return val === void 0 || val !== "0" && val !== "false" && val !== "off";
|
|
7137
|
-
}
|
|
7138
|
-
function hasPageBreakBefore(paragraph) {
|
|
7139
|
-
const pPr = childrenWithTag$1(paragraph, "w:pPr")[0];
|
|
7140
|
-
return readToggle(pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "w:pageBreakBefore")[0]);
|
|
7141
|
-
}
|
|
7142
|
-
function readRunText(run) {
|
|
7143
|
-
let text = "";
|
|
7144
|
-
for (const child of run.children) {
|
|
7145
|
-
if (child.type !== "element") continue;
|
|
7146
|
-
if (child.tag === "w:t") text += textContent$1(child);
|
|
7147
|
-
else if (child.tag === "w:tab") text += " ";
|
|
7148
|
-
else if (child.tag === "w:br" || child.tag === "w:cr") text += "\n";
|
|
7149
|
-
}
|
|
7150
|
-
return text;
|
|
7151
|
-
}
|
|
7152
|
-
function readRun$1(run, paragraph, context) {
|
|
7153
|
-
const props = resolveRunProperties(run, paragraph, context);
|
|
7154
|
-
return {
|
|
7155
|
-
text: readRunText(run),
|
|
7156
|
-
bold: props.bold,
|
|
7157
|
-
italic: props.italic,
|
|
7158
|
-
underline: props.underline,
|
|
7159
|
-
strike: props.strike,
|
|
7160
|
-
fontFamily: props.fontFamily,
|
|
7161
|
-
sizePt: props.sizePt,
|
|
7162
|
-
color: props.color
|
|
7163
|
-
};
|
|
7164
|
-
}
|
|
7165
|
-
function readParagraphRuns(paragraph, context, rels) {
|
|
7166
|
-
const runs = [];
|
|
7167
|
-
let fieldState = "none";
|
|
7168
|
-
function walk(nodes, hyperlinkTarget) {
|
|
7169
|
-
for (const node of nodes) {
|
|
7170
|
-
if (node.type !== "element") continue;
|
|
7171
|
-
if (node.tag === "w:r") {
|
|
7172
|
-
const fldChar = childrenWithTag$1(node, "w:fldChar")[0];
|
|
7173
|
-
if (fldChar !== void 0) {
|
|
7174
|
-
const type = attr$1(fldChar, "w:fldCharType");
|
|
7175
|
-
if (type === "begin") fieldState = "code";
|
|
7176
|
-
else if (type === "separate") fieldState = "result";
|
|
7177
|
-
else if (type === "end") fieldState = "none";
|
|
7178
|
-
continue;
|
|
7179
|
-
}
|
|
7180
|
-
if (fieldState === "code") continue;
|
|
7181
|
-
const run = readRun$1(node, paragraph, context);
|
|
7182
|
-
runs.push(hyperlinkTarget === void 0 ? run : {
|
|
7183
|
-
...run,
|
|
7184
|
-
hyperlink: hyperlinkTarget
|
|
7185
|
-
});
|
|
7186
|
-
} else if (node.tag === "w:fldSimple") walk(node.children, hyperlinkTarget);
|
|
7187
|
-
else if (node.tag === "w:hyperlink") {
|
|
7188
|
-
const rId = attr$1(node, "r:id");
|
|
7189
|
-
const target = rId === void 0 ? void 0 : rels.get(rId)?.target;
|
|
7190
|
-
walk(node.children, target ?? hyperlinkTarget);
|
|
7191
|
-
} else if (node.tag === "w:ins") walk(node.children, hyperlinkTarget);
|
|
7192
|
-
}
|
|
7193
|
-
}
|
|
7194
|
-
walk(paragraph.children, void 0);
|
|
7195
|
-
return runs;
|
|
7196
|
-
}
|
|
7197
|
-
function readParagraph$1(paragraph, context, rels) {
|
|
7198
|
-
const pPr = childrenWithTag$1(paragraph, "w:pPr")[0];
|
|
7199
|
-
const pStyleEl = pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "w:pStyle")[0];
|
|
7200
|
-
const props = resolveParagraphProperties(paragraph, context);
|
|
7201
|
-
return {
|
|
7202
|
-
kind: "paragraph",
|
|
7203
|
-
runs: readParagraphRuns(paragraph, context, rels),
|
|
7204
|
-
styleId: pStyleEl === void 0 ? void 0 : attr$1(pStyleEl, "w:val"),
|
|
7205
|
-
alignment: props.alignment,
|
|
7206
|
-
list: readListMembership(pPr),
|
|
7207
|
-
spacingBeforePt: props.spacingBeforePt,
|
|
7208
|
-
spacingAfterPt: props.spacingAfterPt,
|
|
7209
|
-
lineSpacing: props.lineSpacing,
|
|
7210
|
-
indentLeftPt: props.indentLeftPt,
|
|
7211
|
-
indentFirstLinePt: props.indentFirstLinePt
|
|
7212
|
-
};
|
|
7213
|
-
}
|
|
7214
|
-
function readCellShading(tcPr) {
|
|
7215
|
-
const shd = tcPr === void 0 ? void 0 : childrenWithTag$1(tcPr, "w:shd")[0];
|
|
7216
|
-
const fill = shd === void 0 ? void 0 : attr$1(shd, "w:fill");
|
|
7217
|
-
return fill === void 0 || fill === "auto" || fill === "none" ? void 0 : rgbHexToColor(fill);
|
|
7218
|
-
}
|
|
7219
|
-
function readRawCell(tc, context, rels) {
|
|
7220
|
-
const tcPr = childrenWithTag$1(tc, "w:tcPr")[0];
|
|
7221
|
-
const gridSpanEl = tcPr === void 0 ? void 0 : childrenWithTag$1(tcPr, "w:gridSpan")[0];
|
|
7222
|
-
const gridSpanVal = gridSpanEl === void 0 ? void 0 : attr$1(gridSpanEl, "w:val");
|
|
7223
|
-
const vMerge = tcPr === void 0 ? void 0 : childrenWithTag$1(tcPr, "w:vMerge")[0];
|
|
7224
|
-
const vMergeVal = vMerge === void 0 ? void 0 : attr$1(vMerge, "w:val") ?? "continue";
|
|
7225
|
-
return {
|
|
7226
|
-
gridSpan: gridSpanVal === void 0 ? 1 : Number(gridSpanVal),
|
|
7227
|
-
isVMergeContinuation: vMergeVal === "continue",
|
|
7228
|
-
background: readCellShading(tcPr),
|
|
7229
|
-
blocks: readBodyBlocks(tc.children, context, rels)
|
|
7230
|
-
};
|
|
7231
|
-
}
|
|
7232
|
-
function readTable$1(tbl, context, rels) {
|
|
7233
|
-
const tblGrid = childrenWithTag$1(tbl, "w:tblGrid")[0];
|
|
7234
|
-
const columnWidthsPt = tblGrid === void 0 ? [] : childrenWithTag$1(tblGrid, "w:gridCol").map((col) => twipsToPt(Number(attr$1(col, "w:w") ?? "0")));
|
|
7235
|
-
const rawRows = childrenWithTag$1(tbl, "w:tr").map((tr) => childrenWithTag$1(tr, "w:tc").map((tc) => readRawCell(tc, context, rels)));
|
|
7236
|
-
const rowColumnIndices = rawRows.map((row) => {
|
|
7237
|
-
const indices = [];
|
|
7238
|
-
let col = 0;
|
|
7239
|
-
for (const cell of row) {
|
|
7240
|
-
indices.push(col);
|
|
7241
|
-
col += cell.gridSpan;
|
|
7242
|
-
}
|
|
7243
|
-
return indices;
|
|
7244
|
-
});
|
|
7245
|
-
return {
|
|
7246
|
-
kind: "table",
|
|
7247
|
-
columnWidthsPt,
|
|
7248
|
-
rows: rawRows.map((row, rowIndex) => ({ cells: row.map((cell, cellIndex) => {
|
|
7249
|
-
if (cell.isVMergeContinuation) return { blocks: [] };
|
|
7250
|
-
const colIndex = rowColumnIndices[rowIndex][cellIndex];
|
|
7251
|
-
let rowSpan = 1;
|
|
7252
|
-
for (let r = rowIndex + 1; r < rawRows.length; r++) {
|
|
7253
|
-
const matchIndex = rowColumnIndices[r].indexOf(colIndex);
|
|
7254
|
-
if (!(matchIndex === -1 ? void 0 : rawRows[r][matchIndex])?.isVMergeContinuation) break;
|
|
7255
|
-
rowSpan++;
|
|
7256
|
-
}
|
|
7257
|
-
return {
|
|
7258
|
-
blocks: cell.blocks,
|
|
7259
|
-
colSpan: cell.gridSpan > 1 ? cell.gridSpan : void 0,
|
|
7260
|
-
rowSpan: rowSpan > 1 ? rowSpan : void 0,
|
|
7261
|
-
background: cell.background
|
|
7262
|
-
};
|
|
7263
|
-
}) }))
|
|
7264
|
-
};
|
|
7265
|
-
}
|
|
7266
|
-
function readBodyBlocks(nodes, context, rels) {
|
|
7267
|
-
const blocks = [];
|
|
7268
|
-
for (const node of nodes) {
|
|
7269
|
-
if (node.type !== "element") continue;
|
|
7270
|
-
if (node.tag === "w:p") {
|
|
7271
|
-
if (hasPageBreakBefore(node)) blocks.push({ kind: "pageBreak" });
|
|
7272
|
-
blocks.push(readParagraph$1(node, context, rels));
|
|
7273
|
-
} else if (node.tag === "w:tbl") blocks.push(readTable$1(node, context, rels));
|
|
7274
|
-
else if (node.tag === "w:sdt") {
|
|
7275
|
-
const sdtContent = childrenWithTag$1(node, "w:sdtContent")[0];
|
|
7276
|
-
if (sdtContent !== void 0) blocks.push(...readBodyBlocks(sdtContent.children, context, rels));
|
|
7277
|
-
} else if (node.tag === "w:ins") blocks.push(...readBodyBlocks(node.children, context, rels));
|
|
7278
|
-
else if (node.tag === "mc:AlternateContent") {
|
|
7279
|
-
const target = childrenWithTag$1(node, "mc:Fallback")[0] ?? childrenWithTag$1(node, "mc:Choice")[0];
|
|
7280
|
-
if (target !== void 0) blocks.push(...readBodyBlocks(target.children, context, rels));
|
|
7281
|
-
}
|
|
7282
|
-
}
|
|
7283
|
-
return blocks;
|
|
7284
|
-
}
|
|
7285
|
-
function readSections(body, context, rels) {
|
|
7286
|
-
const sections = [];
|
|
7287
|
-
let currentBlocks = [];
|
|
7288
|
-
for (const node of body.children) {
|
|
7289
|
-
if (node.type !== "element") continue;
|
|
7290
|
-
if (node.tag === "w:sectPr") {
|
|
7291
|
-
sections.push({
|
|
7292
|
-
pageSize: readPageSize(node),
|
|
7293
|
-
margins: readMargins(node),
|
|
7294
|
-
blocks: currentBlocks
|
|
7295
|
-
});
|
|
7296
|
-
currentBlocks = [];
|
|
7297
|
-
continue;
|
|
7298
|
-
}
|
|
7299
|
-
if (node.tag === "w:p") {
|
|
7300
|
-
const pPr = childrenWithTag$1(node, "w:pPr")[0];
|
|
7301
|
-
const sectPr = pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "w:sectPr")[0];
|
|
7302
|
-
if (hasPageBreakBefore(node)) currentBlocks.push({ kind: "pageBreak" });
|
|
7303
|
-
currentBlocks.push(readParagraph$1(node, context, rels));
|
|
7304
|
-
if (sectPr !== void 0) {
|
|
7305
|
-
sections.push({
|
|
7306
|
-
pageSize: readPageSize(sectPr),
|
|
7307
|
-
margins: readMargins(sectPr),
|
|
7308
|
-
blocks: currentBlocks
|
|
7309
|
-
});
|
|
7310
|
-
currentBlocks = [];
|
|
7311
|
-
}
|
|
7312
|
-
continue;
|
|
7313
|
-
}
|
|
7314
|
-
currentBlocks.push(...readBodyBlocks([node], context, rels));
|
|
7315
|
-
}
|
|
7316
|
-
if (currentBlocks.length > 0 || sections.length === 0) sections.push({
|
|
7317
|
-
pageSize: PAGE_SIZE_LETTER,
|
|
7318
|
-
margins: DEFAULT_MARGINS,
|
|
7319
|
-
blocks: currentBlocks
|
|
7320
|
-
});
|
|
7321
|
-
return sections;
|
|
7322
|
-
}
|
|
7323
|
-
function readDocumentTheme(pkg, docRels) {
|
|
7324
|
-
for (const rel of docRels.values()) if (rel.type.endsWith(THEME_REL_SUFFIX$1)) {
|
|
7325
|
-
const themeRoot = rootElement$1(pkg.parts[rel.target]);
|
|
7326
|
-
if (themeRoot !== void 0) return readTheme(themeRoot);
|
|
7327
|
-
}
|
|
7328
|
-
return EMPTY_THEME;
|
|
7329
|
-
}
|
|
7330
6623
|
function readDocxContent(pkg) {
|
|
7331
|
-
const
|
|
7332
|
-
if (documentRoot === void 0) throw new Error(`package has no ${DOCUMENT_PART_PATH} part`);
|
|
7333
|
-
const body = childrenWithTag$1(documentRoot, "w:body")[0];
|
|
7334
|
-
if (body === void 0) throw new Error(`${DOCUMENT_PART_PATH} has no w:body element`);
|
|
7335
|
-
const docRels = resolveRelationships$1(pkg, DOCUMENT_PART_PATH);
|
|
7336
|
-
const context = {
|
|
7337
|
-
stylesRoot: rootElement$1(pkg.parts[STYLES_PART_PATH]),
|
|
7338
|
-
theme: readDocumentTheme(pkg, docRels)
|
|
7339
|
-
};
|
|
6624
|
+
const docxDoc = readDocx(pkg);
|
|
7340
6625
|
return {
|
|
7341
6626
|
kind: "wordprocessing",
|
|
7342
6627
|
formatVersion: 1,
|
|
7343
|
-
metadata:
|
|
7344
|
-
sections:
|
|
6628
|
+
metadata: { ...docxDoc.metadata },
|
|
6629
|
+
sections: docxDoc.sections
|
|
7345
6630
|
};
|
|
7346
6631
|
}
|
|
7347
6632
|
//#endregion
|
|
7348
|
-
//#region src/image/sniff.ts
|
|
7349
|
-
const PNG_SIGNATURE = [
|
|
7350
|
-
137,
|
|
7351
|
-
80,
|
|
7352
|
-
78,
|
|
7353
|
-
71,
|
|
7354
|
-
13,
|
|
7355
|
-
10,
|
|
7356
|
-
26,
|
|
7357
|
-
10
|
|
7358
|
-
];
|
|
7359
|
-
const JPEG_SIGNATURE = [
|
|
7360
|
-
255,
|
|
7361
|
-
216,
|
|
7362
|
-
255
|
|
7363
|
-
];
|
|
7364
|
-
function startsWith(bytes, signature) {
|
|
7365
|
-
if (bytes.length < signature.length) return false;
|
|
7366
|
-
for (let i = 0; i < signature.length; i++) if (bytes[i] !== signature[i]) return false;
|
|
7367
|
-
return true;
|
|
7368
|
-
}
|
|
7369
|
-
function sniffImageFormat(bytes) {
|
|
7370
|
-
if (startsWith(bytes, PNG_SIGNATURE)) return "png";
|
|
7371
|
-
if (startsWith(bytes, JPEG_SIGNATURE)) return "jpeg";
|
|
7372
|
-
}
|
|
7373
|
-
//#endregion
|
|
7374
|
-
//#region src/ooxml/pptx/inherit.ts
|
|
7375
|
-
const SLIDE_LAYOUT_REL_SUFFIX = "/slideLayout";
|
|
7376
|
-
const SLIDE_MASTER_REL_SUFFIX = "/slideMaster";
|
|
7377
|
-
const THEME_REL_SUFFIX = "/theme";
|
|
7378
|
-
function findRelTarget(pkg, partPath, typeSuffix) {
|
|
7379
|
-
for (const rel of resolveRelationships$1(pkg, partPath).values()) if (rel.type.endsWith(typeSuffix)) return rel.target;
|
|
7380
|
-
}
|
|
7381
|
-
function resolveSlideInheritance(pkg, slidePath) {
|
|
7382
|
-
const layoutPath = findRelTarget(pkg, slidePath, SLIDE_LAYOUT_REL_SUFFIX);
|
|
7383
|
-
const layoutRoot = layoutPath === void 0 ? void 0 : rootElement$1(pkg.parts[layoutPath]);
|
|
7384
|
-
const masterPath = layoutPath === void 0 ? void 0 : findRelTarget(pkg, layoutPath, SLIDE_MASTER_REL_SUFFIX);
|
|
7385
|
-
const masterRoot = masterPath === void 0 ? void 0 : rootElement$1(pkg.parts[masterPath]);
|
|
7386
|
-
const themePath = masterPath === void 0 ? void 0 : findRelTarget(pkg, masterPath, THEME_REL_SUFFIX);
|
|
7387
|
-
const themeRoot = themePath === void 0 ? void 0 : rootElement$1(pkg.parts[themePath]);
|
|
7388
|
-
return {
|
|
7389
|
-
layoutRoot,
|
|
7390
|
-
masterRoot,
|
|
7391
|
-
theme: themeRoot === void 0 ? EMPTY_THEME : readTheme(themeRoot),
|
|
7392
|
-
colorMap: readColorMap(masterRoot === void 0 ? void 0 : childrenWithTag$1(masterRoot, "p:clrMap")[0])
|
|
7393
|
-
};
|
|
7394
|
-
}
|
|
7395
|
-
const TYPE_NORMALIZATION = /* @__PURE__ */ new Map([["ctrTitle", "title"], ["subTitle", "body"]]);
|
|
7396
|
-
function normalizePlaceholderType(type) {
|
|
7397
|
-
return type === void 0 ? void 0 : TYPE_NORMALIZATION.get(type) ?? type;
|
|
7398
|
-
}
|
|
7399
|
-
function readPlaceholderKey(shape) {
|
|
7400
|
-
const ph = elementsWithTag$1([shape], "p:ph")[0];
|
|
7401
|
-
return ph === void 0 ? void 0 : {
|
|
7402
|
-
type: attr$1(ph, "type"),
|
|
7403
|
-
idx: attr$1(ph, "idx")
|
|
7404
|
-
};
|
|
7405
|
-
}
|
|
7406
|
-
function shapesOf(root) {
|
|
7407
|
-
return root === void 0 ? [] : elementsWithTag$1([root], "p:sp");
|
|
7408
|
-
}
|
|
7409
|
-
function findMatchingPlaceholder(root, key) {
|
|
7410
|
-
const shapes = shapesOf(root);
|
|
7411
|
-
if (key.idx !== void 0) {
|
|
7412
|
-
const byIdx = shapes.find((shape) => readPlaceholderKey(shape)?.idx === key.idx);
|
|
7413
|
-
if (byIdx !== void 0) return byIdx;
|
|
7414
|
-
}
|
|
7415
|
-
const normalizedTarget = normalizePlaceholderType(key.type);
|
|
7416
|
-
if (normalizedTarget === void 0) return;
|
|
7417
|
-
return shapes.find((shape) => normalizePlaceholderType(readPlaceholderKey(shape)?.type) === normalizedTarget);
|
|
7418
|
-
}
|
|
7419
|
-
function shapeXfrm(shape) {
|
|
7420
|
-
if (shape === void 0) return;
|
|
7421
|
-
const spPr = childrenWithTag$1(shape, "p:spPr")[0];
|
|
7422
|
-
return spPr === void 0 ? void 0 : readXfrm(childrenWithTag$1(spPr, "a:xfrm")[0]);
|
|
7423
|
-
}
|
|
7424
|
-
function resolvePlaceholderXfrm(key, context) {
|
|
7425
|
-
return shapeXfrm(findMatchingPlaceholder(context.layoutRoot, key)) ?? shapeXfrm(findMatchingPlaceholder(context.masterRoot, key));
|
|
7426
|
-
}
|
|
7427
|
-
function readRunPropertiesFromElement(rPr, context) {
|
|
7428
|
-
const sz = attr$1(rPr, "sz");
|
|
7429
|
-
const latin = childrenWithTag$1(rPr, "a:latin")[0];
|
|
7430
|
-
const typeface = latin === void 0 ? void 0 : attr$1(latin, "typeface");
|
|
7431
|
-
const solidFill = childrenWithTag$1(rPr, "a:solidFill")[0];
|
|
7432
|
-
const bold = attr$1(rPr, "b");
|
|
7433
|
-
const italic = attr$1(rPr, "i");
|
|
7434
|
-
return {
|
|
7435
|
-
fontFamily: typeface === void 0 ? void 0 : resolveThemeFontReference(typeface, context.theme),
|
|
7436
|
-
sizePt: sz === void 0 ? void 0 : drawingMlFontSizeToPt(Number(sz)),
|
|
7437
|
-
bold: bold === void 0 ? void 0 : bold === "1",
|
|
7438
|
-
italic: italic === void 0 ? void 0 : italic === "1",
|
|
7439
|
-
color: readSolidFillColor(solidFill, context.colorMap, context.theme)
|
|
7440
|
-
};
|
|
7441
|
-
}
|
|
7442
|
-
function txStyleTagFor(placeholderType) {
|
|
7443
|
-
const normalized = normalizePlaceholderType(placeholderType);
|
|
7444
|
-
if (normalized === "title") return "p:titleStyle";
|
|
7445
|
-
if (normalized === "body") return "p:bodyStyle";
|
|
7446
|
-
return "p:otherStyle";
|
|
7447
|
-
}
|
|
7448
|
-
function levelTag(level) {
|
|
7449
|
-
return `a:lvl${Math.min(Math.max(level, 0), 8) + 1}pPr`;
|
|
7450
|
-
}
|
|
7451
|
-
function resolveDefaultRunProperties(placeholderType, level, context) {
|
|
7452
|
-
if (context.masterRoot === void 0) return {};
|
|
7453
|
-
const txStyles = childrenWithTag$1(context.masterRoot, "p:txStyles")[0];
|
|
7454
|
-
const styleEl = txStyles === void 0 ? void 0 : childrenWithTag$1(txStyles, txStyleTagFor(placeholderType))[0];
|
|
7455
|
-
const lvlPPr = styleEl === void 0 ? void 0 : childrenWithTag$1(styleEl, levelTag(level))[0];
|
|
7456
|
-
const defRPr = lvlPPr === void 0 ? void 0 : childrenWithTag$1(lvlPPr, "a:defRPr")[0];
|
|
7457
|
-
return defRPr === void 0 ? {} : readRunPropertiesFromElement(defRPr, context);
|
|
7458
|
-
}
|
|
7459
|
-
//#endregion
|
|
7460
6633
|
//#region src/ooxml/pptx/read.ts
|
|
7461
|
-
const PRESENTATION_PATH = "ppt/presentation.xml";
|
|
7462
|
-
const TABLE_GRAPHIC_URI = "http://schemas.openxmlformats.org/drawingml/2006/table";
|
|
7463
|
-
function readSlideSize(presentationRoot) {
|
|
7464
|
-
const sldSz = presentationRoot === void 0 ? void 0 : childrenWithTag$1(presentationRoot, "p:sldSz")[0];
|
|
7465
|
-
const cx = sldSz === void 0 ? void 0 : attr$1(sldSz, "cx");
|
|
7466
|
-
const cy = sldSz === void 0 ? void 0 : attr$1(sldSz, "cy");
|
|
7467
|
-
return cx === void 0 || cy === void 0 ? SLIDE_SIZE_WIDESCREEN : {
|
|
7468
|
-
widthPt: emuToPt(Number(cx)),
|
|
7469
|
-
heightPt: emuToPt(Number(cy))
|
|
7470
|
-
};
|
|
7471
|
-
}
|
|
7472
|
-
function readSlidePathsInOrder(pkg, presentationRoot) {
|
|
7473
|
-
if (presentationRoot === void 0) return [];
|
|
7474
|
-
const sldIdLst = childrenWithTag$1(presentationRoot, "p:sldIdLst")[0];
|
|
7475
|
-
if (sldIdLst === void 0) return [];
|
|
7476
|
-
const presentationRels = resolveRelationships$1(pkg, PRESENTATION_PATH);
|
|
7477
|
-
const paths = [];
|
|
7478
|
-
for (const sldId of childrenWithTag$1(sldIdLst, "p:sldId")) {
|
|
7479
|
-
const rId = attr$1(sldId, "r:id");
|
|
7480
|
-
const rel = rId === void 0 ? void 0 : presentationRels.get(rId);
|
|
7481
|
-
if (rel !== void 0) paths.push(rel.target);
|
|
7482
|
-
}
|
|
7483
|
-
return paths;
|
|
7484
|
-
}
|
|
7485
|
-
function shapeName(shape) {
|
|
7486
|
-
const cNvPr = elementsWithTag$1([shape], "p:cNvPr")[0];
|
|
7487
|
-
return cNvPr === void 0 ? void 0 : attr$1(cNvPr, "name");
|
|
7488
|
-
}
|
|
7489
|
-
function mergeRunProperties(base, override) {
|
|
7490
|
-
return {
|
|
7491
|
-
fontFamily: override.fontFamily ?? base.fontFamily,
|
|
7492
|
-
sizePt: override.sizePt ?? base.sizePt,
|
|
7493
|
-
bold: override.bold ?? base.bold,
|
|
7494
|
-
italic: override.italic ?? base.italic,
|
|
7495
|
-
color: override.color ?? base.color
|
|
7496
|
-
};
|
|
7497
|
-
}
|
|
7498
|
-
function isUnderlined(rPr) {
|
|
7499
|
-
if (rPr === void 0) return;
|
|
7500
|
-
const u = attr$1(rPr, "u");
|
|
7501
|
-
return u === void 0 ? void 0 : u !== "none";
|
|
7502
|
-
}
|
|
7503
|
-
function isStrikethrough(rPr) {
|
|
7504
|
-
if (rPr === void 0) return;
|
|
7505
|
-
const strike = attr$1(rPr, "strike");
|
|
7506
|
-
return strike === void 0 ? void 0 : strike !== "noStrike";
|
|
7507
|
-
}
|
|
7508
|
-
function readHyperlink(rPr, slideRels) {
|
|
7509
|
-
if (rPr === void 0) return;
|
|
7510
|
-
const hlink = childrenWithTag$1(rPr, "a:hlinkClick")[0];
|
|
7511
|
-
const rId = hlink === void 0 ? void 0 : attr$1(hlink, "r:id");
|
|
7512
|
-
const rel = rId === void 0 ? void 0 : slideRels.get(rId);
|
|
7513
|
-
return rel?.targetMode === "External" ? rel.target : void 0;
|
|
7514
|
-
}
|
|
7515
|
-
function readRun(runEl, cascadeBase, context, slideRels) {
|
|
7516
|
-
const rPr = childrenWithTag$1(runEl, "a:rPr")[0];
|
|
7517
|
-
const merged = mergeRunProperties(cascadeBase, rPr === void 0 ? {} : readRunPropertiesFromElement(rPr, context));
|
|
7518
|
-
const tEl = childrenWithTag$1(runEl, "a:t")[0];
|
|
7519
|
-
return {
|
|
7520
|
-
text: tEl === void 0 ? "" : textContent$1(tEl),
|
|
7521
|
-
bold: merged.bold,
|
|
7522
|
-
italic: merged.italic,
|
|
7523
|
-
underline: isUnderlined(rPr),
|
|
7524
|
-
strike: isStrikethrough(rPr),
|
|
7525
|
-
fontFamily: merged.fontFamily,
|
|
7526
|
-
sizePt: merged.sizePt,
|
|
7527
|
-
color: merged.color,
|
|
7528
|
-
hyperlink: readHyperlink(rPr, slideRels)
|
|
7529
|
-
};
|
|
7530
|
-
}
|
|
7531
|
-
function readAlignment(algn) {
|
|
7532
|
-
if (algn === "l") return "left";
|
|
7533
|
-
if (algn === "ctr") return "center";
|
|
7534
|
-
if (algn === "r") return "right";
|
|
7535
|
-
if (algn === "just" || algn === "justLow") return "justify";
|
|
7536
|
-
}
|
|
7537
|
-
function readAbsoluteSpacingPt(spc) {
|
|
7538
|
-
if (spc === void 0) return;
|
|
7539
|
-
const pts = childrenWithTag$1(spc, "a:spcPts")[0];
|
|
7540
|
-
const val = pts === void 0 ? void 0 : attr$1(pts, "val");
|
|
7541
|
-
return val === void 0 ? void 0 : drawingMlFontSizeToPt(Number(val));
|
|
7542
|
-
}
|
|
7543
|
-
function readLineSpacingMultiplier(pPr) {
|
|
7544
|
-
const lnSpc = pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "a:lnSpc")[0];
|
|
7545
|
-
const pct = lnSpc === void 0 ? void 0 : childrenWithTag$1(lnSpc, "a:spcPct")[0];
|
|
7546
|
-
const val = pct === void 0 ? void 0 : attr$1(pct, "val");
|
|
7547
|
-
return val === void 0 ? void 0 : Number(val) / 1e5;
|
|
7548
|
-
}
|
|
7549
|
-
function readParagraph(pEl, placeholderType, context, slideRels) {
|
|
7550
|
-
const pPr = childrenWithTag$1(pEl, "a:pPr")[0];
|
|
7551
|
-
const masterDefaults = resolveDefaultRunProperties(placeholderType, pPr === void 0 ? 0 : Number(attr$1(pPr, "lvl") ?? "0"), context);
|
|
7552
|
-
const pPrDefRPr = pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "a:defRPr")[0];
|
|
7553
|
-
const paragraphDefaults = pPrDefRPr === void 0 ? masterDefaults : mergeRunProperties(masterDefaults, readRunPropertiesFromElement(pPrDefRPr, context));
|
|
7554
|
-
const runs = [];
|
|
7555
|
-
for (const child of pEl.children) {
|
|
7556
|
-
if (child.type !== "element") continue;
|
|
7557
|
-
if (child.tag === "a:r" || child.tag === "a:fld") runs.push(readRun(child, paragraphDefaults, context, slideRels));
|
|
7558
|
-
else if (child.tag === "a:br") runs.push({ text: "\n" });
|
|
7559
|
-
}
|
|
7560
|
-
const marL = pPr === void 0 ? void 0 : attr$1(pPr, "marL");
|
|
7561
|
-
const indent = pPr === void 0 ? void 0 : attr$1(pPr, "indent");
|
|
7562
|
-
return {
|
|
7563
|
-
kind: "paragraph",
|
|
7564
|
-
runs,
|
|
7565
|
-
alignment: pPr === void 0 ? void 0 : readAlignment(attr$1(pPr, "algn")),
|
|
7566
|
-
spacingBeforePt: readAbsoluteSpacingPt(pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "a:spcBef")[0]),
|
|
7567
|
-
spacingAfterPt: readAbsoluteSpacingPt(pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "a:spcAft")[0]),
|
|
7568
|
-
lineSpacing: readLineSpacingMultiplier(pPr),
|
|
7569
|
-
indentLeftPt: marL === void 0 ? void 0 : emuToPt(Number(marL)),
|
|
7570
|
-
indentFirstLinePt: indent === void 0 ? void 0 : emuToPt(Number(indent))
|
|
7571
|
-
};
|
|
7572
|
-
}
|
|
7573
|
-
function textBodyParagraphs(txBody, placeholderType, context, slideRels) {
|
|
7574
|
-
return txBody === void 0 ? [] : childrenWithTag$1(txBody, "a:p").map((p) => readParagraph(p, placeholderType, context, slideRels));
|
|
7575
|
-
}
|
|
7576
|
-
const DEFAULT_INSET_LEFT_RIGHT_EMU = 91440;
|
|
7577
|
-
const DEFAULT_INSET_TOP_BOTTOM_EMU = 45720;
|
|
7578
|
-
const NO_TEXT_BODY_EXTRAS = {
|
|
7579
|
-
insetLeftPt: 0,
|
|
7580
|
-
insetTopPt: 0,
|
|
7581
|
-
insetRightPt: 0,
|
|
7582
|
-
insetBottomPt: 0,
|
|
7583
|
-
fontScale: void 0,
|
|
7584
|
-
lineSpacingReduction: void 0
|
|
7585
|
-
};
|
|
7586
|
-
function readShapeTextExtras(txBody) {
|
|
7587
|
-
if (txBody === void 0) return NO_TEXT_BODY_EXTRAS;
|
|
7588
|
-
const bodyPr = childrenWithTag$1(txBody, "a:bodyPr")[0];
|
|
7589
|
-
const lIns = bodyPr === void 0 ? void 0 : attr$1(bodyPr, "lIns");
|
|
7590
|
-
const tIns = bodyPr === void 0 ? void 0 : attr$1(bodyPr, "tIns");
|
|
7591
|
-
const rIns = bodyPr === void 0 ? void 0 : attr$1(bodyPr, "rIns");
|
|
7592
|
-
const bIns = bodyPr === void 0 ? void 0 : attr$1(bodyPr, "bIns");
|
|
7593
|
-
const normAutofit = bodyPr === void 0 ? void 0 : childrenWithTag$1(bodyPr, "a:normAutofit")[0];
|
|
7594
|
-
const fontScale = normAutofit === void 0 ? void 0 : attr$1(normAutofit, "fontScale");
|
|
7595
|
-
const lnSpcReduction = normAutofit === void 0 ? void 0 : attr$1(normAutofit, "lnSpcReduction");
|
|
7596
|
-
return {
|
|
7597
|
-
insetLeftPt: emuToPt(lIns === void 0 ? DEFAULT_INSET_LEFT_RIGHT_EMU : Number(lIns)),
|
|
7598
|
-
insetTopPt: emuToPt(tIns === void 0 ? DEFAULT_INSET_TOP_BOTTOM_EMU : Number(tIns)),
|
|
7599
|
-
insetRightPt: emuToPt(rIns === void 0 ? DEFAULT_INSET_LEFT_RIGHT_EMU : Number(rIns)),
|
|
7600
|
-
insetBottomPt: emuToPt(bIns === void 0 ? DEFAULT_INSET_TOP_BOTTOM_EMU : Number(bIns)),
|
|
7601
|
-
fontScale: fontScale === void 0 ? void 0 : Number(fontScale) / 1e5,
|
|
7602
|
-
lineSpacingReduction: lnSpcReduction === void 0 ? void 0 : Number(lnSpcReduction) / 1e5
|
|
7603
|
-
};
|
|
7604
|
-
}
|
|
7605
|
-
function resolveShapeFrame(shape, context, parentTransform) {
|
|
7606
|
-
const key = readPlaceholderKey(shape);
|
|
7607
|
-
const spPr = childrenWithTag$1(shape, "p:spPr")[0];
|
|
7608
|
-
const xfrm = (spPr === void 0 ? void 0 : readXfrm(childrenWithTag$1(spPr, "a:xfrm")[0])) ?? (key === void 0 ? void 0 : resolvePlaceholderXfrm(key, context));
|
|
7609
|
-
if (xfrm === void 0) return;
|
|
7610
|
-
const localFrame = {
|
|
7611
|
-
xPt: xfrm.xPt,
|
|
7612
|
-
yPt: xfrm.yPt,
|
|
7613
|
-
widthPt: xfrm.widthPt,
|
|
7614
|
-
heightPt: xfrm.heightPt
|
|
7615
|
-
};
|
|
7616
|
-
return {
|
|
7617
|
-
frame: parentTransform === void 0 ? localFrame : applyGroupTransform(parentTransform, localFrame),
|
|
7618
|
-
rotationDeg: xfrm.rotationDeg === 0 ? void 0 : xfrm.rotationDeg
|
|
7619
|
-
};
|
|
7620
|
-
}
|
|
7621
|
-
function readSpShape(sp, context, slideRels, parentTransform) {
|
|
7622
|
-
const resolved = resolveShapeFrame(sp, context, parentTransform);
|
|
7623
|
-
if (resolved === void 0) return;
|
|
7624
|
-
const key = readPlaceholderKey(sp);
|
|
7625
|
-
const txBody = childrenWithTag$1(sp, "p:txBody")[0];
|
|
7626
|
-
const blocks = textBodyParagraphs(txBody, key?.type, context, slideRels);
|
|
7627
|
-
const extras = readShapeTextExtras(txBody);
|
|
7628
|
-
return {
|
|
7629
|
-
name: shapeName(sp),
|
|
7630
|
-
frame: resolved.frame,
|
|
7631
|
-
rotationDeg: resolved.rotationDeg,
|
|
7632
|
-
...extras,
|
|
7633
|
-
blocks
|
|
7634
|
-
};
|
|
7635
|
-
}
|
|
7636
|
-
function readPicShape(pic, context, slideRels, pkg, parentTransform) {
|
|
7637
|
-
const resolved = resolveShapeFrame(pic, context, parentTransform);
|
|
7638
|
-
if (resolved === void 0) return;
|
|
7639
|
-
const blipFill = childrenWithTag$1(pic, "p:blipFill")[0];
|
|
7640
|
-
const blip = blipFill === void 0 ? void 0 : childrenWithTag$1(blipFill, "a:blip")[0];
|
|
7641
|
-
const rId = blip === void 0 ? void 0 : attr$1(blip, "r:embed");
|
|
7642
|
-
const rel = rId === void 0 ? void 0 : slideRels.get(rId);
|
|
7643
|
-
const mediaPart = rel === void 0 ? void 0 : pkg.parts[rel.target];
|
|
7644
|
-
const blocks = [];
|
|
7645
|
-
if (mediaPart?.kind === "binary") {
|
|
7646
|
-
const format = sniffImageFormat(base64ToBytes$1(mediaPart.base64));
|
|
7647
|
-
if (format !== void 0) {
|
|
7648
|
-
const image = {
|
|
7649
|
-
kind: "image",
|
|
7650
|
-
format,
|
|
7651
|
-
base64: mediaPart.base64,
|
|
7652
|
-
widthPt: resolved.frame.widthPt,
|
|
7653
|
-
heightPt: resolved.frame.heightPt
|
|
7654
|
-
};
|
|
7655
|
-
blocks.push(image);
|
|
7656
|
-
}
|
|
7657
|
-
}
|
|
7658
|
-
return {
|
|
7659
|
-
name: shapeName(pic),
|
|
7660
|
-
frame: resolved.frame,
|
|
7661
|
-
rotationDeg: resolved.rotationDeg,
|
|
7662
|
-
...NO_TEXT_BODY_EXTRAS,
|
|
7663
|
-
blocks
|
|
7664
|
-
};
|
|
7665
|
-
}
|
|
7666
|
-
function readTableCell(tc, context, slideRels) {
|
|
7667
|
-
const hMerge = attr$1(tc, "hMerge");
|
|
7668
|
-
const vMerge = attr$1(tc, "vMerge");
|
|
7669
|
-
if (hMerge === "1" || vMerge === "1") return { blocks: [] };
|
|
7670
|
-
const tcPr = childrenWithTag$1(tc, "a:tcPr")[0];
|
|
7671
|
-
const background = readSolidFillColor(tcPr === void 0 ? void 0 : childrenWithTag$1(tcPr, "a:solidFill")[0], context.colorMap, context.theme);
|
|
7672
|
-
const txBody = childrenWithTag$1(tc, "a:txBody")[0];
|
|
7673
|
-
const gridSpan = attr$1(tc, "gridSpan");
|
|
7674
|
-
const rowSpan = attr$1(tc, "rowSpan");
|
|
7675
|
-
return {
|
|
7676
|
-
blocks: textBodyParagraphs(txBody, void 0, context, slideRels),
|
|
7677
|
-
colSpan: gridSpan === void 0 ? void 0 : Number(gridSpan),
|
|
7678
|
-
rowSpan: rowSpan === void 0 ? void 0 : Number(rowSpan),
|
|
7679
|
-
background
|
|
7680
|
-
};
|
|
7681
|
-
}
|
|
7682
|
-
function readTable(tbl, context, slideRels) {
|
|
7683
|
-
const tblGrid = childrenWithTag$1(tbl, "a:tblGrid")[0];
|
|
7684
|
-
const columnWidthsPt = tblGrid === void 0 ? [] : childrenWithTag$1(tblGrid, "a:gridCol").map((col) => emuToPt(Number(attr$1(col, "w") ?? "0")));
|
|
7685
|
-
return {
|
|
7686
|
-
kind: "table",
|
|
7687
|
-
rows: childrenWithTag$1(tbl, "a:tr").map((tr) => {
|
|
7688
|
-
const h = attr$1(tr, "h");
|
|
7689
|
-
return {
|
|
7690
|
-
cells: childrenWithTag$1(tr, "a:tc").map((tc) => readTableCell(tc, context, slideRels)),
|
|
7691
|
-
heightPt: h === void 0 ? void 0 : emuToPt(Number(h))
|
|
7692
|
-
};
|
|
7693
|
-
}),
|
|
7694
|
-
columnWidthsPt
|
|
7695
|
-
};
|
|
7696
|
-
}
|
|
7697
|
-
function readGraphicFrameShape(gf, context, slideRels, parentTransform) {
|
|
7698
|
-
const xfrm = readXfrm(childrenWithTag$1(gf, "p:xfrm")[0]);
|
|
7699
|
-
if (xfrm === void 0) return;
|
|
7700
|
-
const localFrame = {
|
|
7701
|
-
xPt: xfrm.xPt,
|
|
7702
|
-
yPt: xfrm.yPt,
|
|
7703
|
-
widthPt: xfrm.widthPt,
|
|
7704
|
-
heightPt: xfrm.heightPt
|
|
7705
|
-
};
|
|
7706
|
-
const frame = parentTransform === void 0 ? localFrame : applyGroupTransform(parentTransform, localFrame);
|
|
7707
|
-
const rotationDeg = xfrm.rotationDeg === 0 ? void 0 : xfrm.rotationDeg;
|
|
7708
|
-
const graphic = childrenWithTag$1(gf, "a:graphic")[0];
|
|
7709
|
-
const graphicData = graphic === void 0 ? void 0 : childrenWithTag$1(graphic, "a:graphicData")[0];
|
|
7710
|
-
const tbl = (graphicData === void 0 ? void 0 : attr$1(graphicData, "uri")) === TABLE_GRAPHIC_URI && graphicData !== void 0 ? childrenWithTag$1(graphicData, "a:tbl")[0] : void 0;
|
|
7711
|
-
const blocks = tbl === void 0 ? [] : [readTable(tbl, context, slideRels)];
|
|
7712
|
-
return {
|
|
7713
|
-
name: shapeName(gf),
|
|
7714
|
-
frame,
|
|
7715
|
-
rotationDeg,
|
|
7716
|
-
...NO_TEXT_BODY_EXTRAS,
|
|
7717
|
-
blocks
|
|
7718
|
-
};
|
|
7719
|
-
}
|
|
7720
|
-
function walkShapeTreeChildren(children, parentTransform, context, slideRels, pkg, out) {
|
|
7721
|
-
for (const node of children) {
|
|
7722
|
-
if (node.type !== "element") continue;
|
|
7723
|
-
if (node.tag === "p:sp") {
|
|
7724
|
-
const shape = readSpShape(node, context, slideRels, parentTransform);
|
|
7725
|
-
if (shape !== void 0) out.push(shape);
|
|
7726
|
-
} else if (node.tag === "p:pic") {
|
|
7727
|
-
const shape = readPicShape(node, context, slideRels, pkg, parentTransform);
|
|
7728
|
-
if (shape !== void 0) out.push(shape);
|
|
7729
|
-
} else if (node.tag === "p:graphicFrame") {
|
|
7730
|
-
const shape = readGraphicFrameShape(node, context, slideRels, parentTransform);
|
|
7731
|
-
if (shape !== void 0) out.push(shape);
|
|
7732
|
-
} else if (node.tag === "p:grpSp") {
|
|
7733
|
-
const grpSpPr = childrenWithTag$1(node, "p:grpSpPr")[0];
|
|
7734
|
-
const composed = composeGroupTransform(readGroupXfrm(grpSpPr === void 0 ? void 0 : childrenWithTag$1(grpSpPr, "a:xfrm")[0]), parentTransform);
|
|
7735
|
-
walkShapeTreeChildren(node.children, composed, context, slideRels, pkg, out);
|
|
7736
|
-
}
|
|
7737
|
-
}
|
|
7738
|
-
}
|
|
7739
|
-
function composeGroupTransform(own, parent) {
|
|
7740
|
-
if (own === void 0) return;
|
|
7741
|
-
if (parent === void 0) return own;
|
|
7742
|
-
const absolute = applyGroupTransform(parent, {
|
|
7743
|
-
xPt: own.offXPt,
|
|
7744
|
-
yPt: own.offYPt,
|
|
7745
|
-
widthPt: own.extWidthPt,
|
|
7746
|
-
heightPt: own.extHeightPt
|
|
7747
|
-
});
|
|
7748
|
-
return {
|
|
7749
|
-
...own,
|
|
7750
|
-
offXPt: absolute.xPt,
|
|
7751
|
-
offYPt: absolute.yPt,
|
|
7752
|
-
extWidthPt: absolute.widthPt,
|
|
7753
|
-
extHeightPt: absolute.heightPt
|
|
7754
|
-
};
|
|
7755
|
-
}
|
|
7756
|
-
const NOTES_SLIDE_REL_SUFFIX = "/notesSlide";
|
|
7757
|
-
function readNotes(pkg, slidePath) {
|
|
7758
|
-
let notesPath;
|
|
7759
|
-
for (const rel of resolveRelationships$1(pkg, slidePath).values()) if (rel.type.endsWith(NOTES_SLIDE_REL_SUFFIX)) {
|
|
7760
|
-
notesPath = rel.target;
|
|
7761
|
-
break;
|
|
7762
|
-
}
|
|
7763
|
-
if (notesPath === void 0) return "";
|
|
7764
|
-
const notesRoot = rootElement$1(pkg.parts[notesPath]);
|
|
7765
|
-
if (notesRoot === void 0) return "";
|
|
7766
|
-
const bodyShape = elementsWithTag$1([notesRoot], "p:sp").find((shape) => {
|
|
7767
|
-
const key = readPlaceholderKey(shape);
|
|
7768
|
-
return key !== void 0 && (key.type === void 0 || key.type === "body");
|
|
7769
|
-
});
|
|
7770
|
-
if (bodyShape !== void 0) {
|
|
7771
|
-
const txBody = childrenWithTag$1(bodyShape, "p:txBody")[0];
|
|
7772
|
-
if (txBody !== void 0) return elementsWithTag$1(txBody.children, "a:t").map(textContent$1).join("");
|
|
7773
|
-
}
|
|
7774
|
-
return elementsWithTag$1([notesRoot], "a:t").map(textContent$1).join("");
|
|
7775
|
-
}
|
|
7776
|
-
function readSlide(pkg, slidePath, size) {
|
|
7777
|
-
const slideRoot = rootElement$1(pkg.parts[slidePath]);
|
|
7778
|
-
const context = resolveSlideInheritance(pkg, slidePath);
|
|
7779
|
-
const slideRels = resolveRelationships$1(pkg, slidePath);
|
|
7780
|
-
const cSld = slideRoot === void 0 ? void 0 : childrenWithTag$1(slideRoot, "p:cSld")[0];
|
|
7781
|
-
const spTree = cSld === void 0 ? void 0 : childrenWithTag$1(cSld, "p:spTree")[0];
|
|
7782
|
-
const shapes = [];
|
|
7783
|
-
if (spTree !== void 0) walkShapeTreeChildren(spTree.children, void 0, context, slideRels, pkg, shapes);
|
|
7784
|
-
return {
|
|
7785
|
-
size,
|
|
7786
|
-
shapes,
|
|
7787
|
-
notes: readNotes(pkg, slidePath)
|
|
7788
|
-
};
|
|
7789
|
-
}
|
|
7790
6634
|
function readPptxContent(pkg) {
|
|
7791
|
-
const
|
|
7792
|
-
const size = readSlideSize(presentationRoot);
|
|
7793
|
-
const slides = readSlidePathsInOrder(pkg, presentationRoot).map((slidePath) => readSlide(pkg, slidePath, size));
|
|
6635
|
+
const pptxDoc = readPptx(pkg);
|
|
7794
6636
|
return {
|
|
7795
6637
|
kind: "presentation",
|
|
7796
6638
|
formatVersion: 1,
|
|
7797
|
-
metadata:
|
|
7798
|
-
slides
|
|
6639
|
+
metadata: { ...pptxDoc.metadata },
|
|
6640
|
+
slides: pptxDoc.slides
|
|
7799
6641
|
};
|
|
7800
6642
|
}
|
|
7801
6643
|
//#endregion
|
|
@@ -8781,6 +7623,16 @@ function pdfToPptx(bytes, options) {
|
|
|
8781
7623
|
return encodePackage$1(buildPptxPackage(content));
|
|
8782
7624
|
}
|
|
8783
7625
|
//#endregion
|
|
7626
|
+
//#region src/convert/codec.ts
|
|
7627
|
+
const docxPdfCodec = z.codec(DocxBytesSchema, PdfBytesSchema, {
|
|
7628
|
+
decode: (docxBytes) => docxToPdf(docxBytes),
|
|
7629
|
+
encode: (pdfBytes) => pdfToDocx(pdfBytes)
|
|
7630
|
+
});
|
|
7631
|
+
const pptxPdfCodec = z.codec(PptxBytesSchema, PdfBytesSchema, {
|
|
7632
|
+
decode: (pptxBytes) => pptxToPdf(pptxBytes),
|
|
7633
|
+
encode: (pdfBytes) => pdfToPptx(pdfBytes)
|
|
7634
|
+
});
|
|
7635
|
+
//#endregion
|
|
8784
7636
|
//#region src/convert/local.ts
|
|
8785
7637
|
const SUPPORTED_CONVERSIONS = [
|
|
8786
7638
|
{
|
|
@@ -8886,4 +7738,4 @@ function fixedClock(date) {
|
|
|
8886
7738
|
return { now: () => date };
|
|
8887
7739
|
}
|
|
8888
7740
|
//#endregion
|
|
8889
|
-
export { AttributeSchema, BinaryPartSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, ContentBlockSchema, ContentDocumentSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSlideSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, DEFAULT_LAYOUT_FONT, DefinedNameSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, LAYOUT_FORMAT_VERSION, NOOP_DIAGNOSTIC_SINK, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PackageSchema, PartSchema, PdfEncryptedError, PdfParseError, PptxEditor, PptxShape, PptxSlide, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertPresentationToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, openDocx, openPptx, packageCodec, parsePackage, parseXml, pdfToDocx, pdfToPptx, pptxToPdf, readDocxContent, readPdf, readPptxContent, reconstructPresentation, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };
|
|
7741
|
+
export { AttributeSchema, BinaryPartSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, ContentBlockSchema, ContentDocumentSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSlideSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, DEFAULT_LAYOUT_FONT, DefinedNameSchema, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, LAYOUT_FORMAT_VERSION, NOOP_DIAGNOSTIC_SINK, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PackageSchema, PartSchema, PdfBytesSchema, PdfEncryptedError, PdfParseError, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertPresentationToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, openDocx, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readPdf, readPptxContent, reconstructPresentation, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };
|