documents.js 1.33.0 → 1.33.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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, childrenWithTag as childrenWithTag$1, compactCodec, compactPackageCodec, decodeCompactPackage, decodeEntities, decodePackage, decodePackage as decodePackage$1, elementsWithTag, elementsWithTag as elementsWithTag$1, encodeCompactPackage, encodePackage, encodePackage as encodePackage$1, fromCompact, isCompactXmlNode, isXmlNode, packageCodec, parsePackage, parseXml, resolveRelationships, resolveRelationships as resolveRelationships$1, rootElement, rootElement as rootElement$1, serializePackage, textContent, textContent as textContent$1, toCompact, unzipPackage, walk, xmlCodec, zipPackage } from "ooxml.js";
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;
@@ -501,9 +348,6 @@ function emuToPt(emu) {
501
348
  function ptToEmu(pt) {
502
349
  return Math.round(pt * EMU_PER_POINT);
503
350
  }
504
- function twipsToPt(twips) {
505
- return twips / 20;
506
- }
507
351
  function ptToTwips(pt) {
508
352
  return Math.round(pt * 20);
509
353
  }
@@ -513,12 +357,6 @@ function halfPointsToPt(halfPoints) {
513
357
  function ptToHalfPoints(pt) {
514
358
  return Math.round(pt * 2);
515
359
  }
516
- function drawingMlFontSizeToPt(hundredths) {
517
- return hundredths / 100;
518
- }
519
- function lineUnitsToMultiplier(lineUnits) {
520
- return lineUnits / 240;
521
- }
522
360
  //#endregion
523
361
  //#region src/opc/paths.ts
524
362
  function relsPathFor(partPath) {
@@ -1291,16 +1129,16 @@ function buildTable(init) {
1291
1129
  }
1292
1130
  //#endregion
1293
1131
  //#region src/edit/docx/editor.ts
1294
- const DOCUMENT_PART_PATH$1 = "word/document.xml";
1132
+ const DOCUMENT_PART_PATH = "word/document.xml";
1295
1133
  const MEDIA_DIR$1 = "word/media";
1296
1134
  function findDocumentRoot(pkg) {
1297
- const root = rootElement$1(pkg.parts[DOCUMENT_PART_PATH$1]);
1298
- if (root === void 0) throw new Error(`package has no root element at ${DOCUMENT_PART_PATH$1}`);
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}`);
1299
1137
  return root;
1300
1138
  }
1301
1139
  function findBody(documentRoot) {
1302
1140
  for (const child of documentRoot.children) if (child.type === "element" && child.tag === "w:body") return child;
1303
- throw new Error(`${DOCUMENT_PART_PATH$1} has no w:body element`);
1141
+ throw new Error(`${DOCUMENT_PART_PATH} has no w:body element`);
1304
1142
  }
1305
1143
  function bodyInsertionPoint(body) {
1306
1144
  const sectPrIndex = body.children.findIndex((c) => c.type === "element" && c.tag === "w:sectPr");
@@ -1354,7 +1192,7 @@ var DocxEditor = class {
1354
1192
  documentRoot,
1355
1193
  media: {
1356
1194
  pkg,
1357
- partPath: DOCUMENT_PART_PATH$1,
1195
+ partPath: DOCUMENT_PART_PATH,
1358
1196
  mediaDir: MEDIA_DIR$1
1359
1197
  }
1360
1198
  };
@@ -1368,7 +1206,7 @@ var DocxEditor = class {
1368
1206
  documentRoot,
1369
1207
  media: {
1370
1208
  pkg: this.pkg,
1371
- partPath: DOCUMENT_PART_PATH$1,
1209
+ partPath: DOCUMENT_PART_PATH,
1372
1210
  mediaDir: MEDIA_DIR$1
1373
1211
  }
1374
1212
  };
@@ -4772,7 +4610,7 @@ function createFontResolver(context) {
4772
4610
  }
4773
4611
  //#endregion
4774
4612
  //#region src/image/png-encode.ts
4775
- const PNG_SIGNATURE$2 = new Uint8Array([
4613
+ const PNG_SIGNATURE$1 = new Uint8Array([
4776
4614
  137,
4777
4615
  80,
4778
4616
  78,
@@ -4821,7 +4659,7 @@ function encodePng(image, options = {}) {
4821
4659
  ihdr[11] = 0;
4822
4660
  ihdr[12] = 0;
4823
4661
  const writer = new ByteWriter();
4824
- writer.writeBytes(PNG_SIGNATURE$2);
4662
+ writer.writeBytes(PNG_SIGNATURE$1);
4825
4663
  writeChunk(writer, "IHDR", ihdr);
4826
4664
  writeChunk(writer, "IDAT", compressed);
4827
4665
  writeChunk(writer, "IEND", /* @__PURE__ */ new Uint8Array(0));
@@ -6054,7 +5892,7 @@ function readMetadata(trailer, resolver) {
6054
5892
  }
6055
5893
  //#endregion
6056
5894
  //#region src/image/png-decode.ts
6057
- const PNG_SIGNATURE$1 = [
5895
+ const PNG_SIGNATURE = [
6058
5896
  137,
6059
5897
  80,
6060
5898
  78,
@@ -6070,7 +5908,7 @@ function requireDataView(bytes) {
6070
5908
  function readChunks(bytes, onWarning) {
6071
5909
  const chunks = [];
6072
5910
  const view = requireDataView(bytes);
6073
- let offset = PNG_SIGNATURE$1.length;
5911
+ let offset = PNG_SIGNATURE.length;
6074
5912
  while (offset + 8 <= bytes.length) {
6075
5913
  const length = view.getUint32(offset);
6076
5914
  const typeBytes = bytes.subarray(offset + 4, offset + 8);
@@ -6145,7 +5983,7 @@ function scaleToByte(sample, bitDepth) {
6145
5983
  return Math.round(sample * 255 / maxSample);
6146
5984
  }
6147
5985
  function decodePng(bytes, options = {}) {
6148
- for (let i = 0; i < PNG_SIGNATURE$1.length; i++) if (bytes[i] !== PNG_SIGNATURE$1[i]) throw new Error("not a valid PNG file: bad 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");
6149
5987
  const chunks = readChunks(bytes, options.onWarning);
6150
5988
  const ihdrChunk = chunks[0];
6151
5989
  if (ihdrChunk?.type !== "IHDR") throw new Error("PNG file does not begin with an IHDR chunk");
@@ -6781,1066 +6619,25 @@ const pdfCodec = z.codec(PdfBytesSchema, LayoutDocumentSchema, {
6781
6619
  encode: (doc) => writePdf(doc)
6782
6620
  });
6783
6621
  //#endregion
6784
- //#region src/ooxml/core-properties.ts
6785
- const CORE_PROPERTIES_PATH = "docProps/core.xml";
6786
- const APP_PROPERTIES_PATH = "docProps/app.xml";
6787
- function firstElementText(root, tag) {
6788
- if (root === void 0) return;
6789
- const element = childrenWithTag$1(root, tag)[0];
6790
- if (element === void 0) return;
6791
- const text = textContent$1(element);
6792
- return text.length > 0 ? text : void 0;
6793
- }
6794
- function readKeywords(core) {
6795
- const raw = firstElementText(core, "cp:keywords");
6796
- if (raw === void 0) return;
6797
- const parts = raw.split(",").map((part) => part.trim()).filter((part) => part.length > 0);
6798
- return parts.length > 0 ? parts : void 0;
6799
- }
6800
- function readCoreProperties(pkg) {
6801
- const core = rootElement$1(pkg.parts[CORE_PROPERTIES_PATH]);
6802
- const app = rootElement$1(pkg.parts[APP_PROPERTIES_PATH]);
6803
- return {
6804
- title: firstElementText(core, "dc:title"),
6805
- author: firstElementText(core, "dc:creator"),
6806
- subject: firstElementText(core, "dc:subject"),
6807
- keywords: readKeywords(core),
6808
- creator: firstElementText(app, "Application"),
6809
- createdIso: firstElementText(core, "dcterms:created"),
6810
- modifiedIso: firstElementText(core, "dcterms:modified")
6811
- };
6812
- }
6813
- //#endregion
6814
- //#region src/ooxml/drawingml.ts
6815
- const ROTATION_UNITS_PER_DEGREE = 6e4;
6816
- function readXfrm(xfrm) {
6817
- if (xfrm === void 0) return;
6818
- const off = childrenWithTag$1(xfrm, "a:off")[0];
6819
- const ext = childrenWithTag$1(xfrm, "a:ext")[0];
6820
- if (off === void 0 || ext === void 0) return;
6821
- const x = attr$1(off, "x");
6822
- const y = attr$1(off, "y");
6823
- const cx = attr$1(ext, "cx");
6824
- const cy = attr$1(ext, "cy");
6825
- if (x === void 0 || y === void 0 || cx === void 0 || cy === void 0) return;
6826
- const rot = attr$1(xfrm, "rot");
6827
- return {
6828
- xPt: emuToPt(Number(x)),
6829
- yPt: emuToPt(Number(y)),
6830
- widthPt: emuToPt(Number(cx)),
6831
- heightPt: emuToPt(Number(cy)),
6832
- rotationDeg: rot === void 0 ? 0 : Number(rot) / ROTATION_UNITS_PER_DEGREE,
6833
- flipH: attr$1(xfrm, "flipH") === "1",
6834
- flipV: attr$1(xfrm, "flipV") === "1"
6835
- };
6836
- }
6837
- const CLR_SCHEME_SLOTS = [
6838
- "dk1",
6839
- "lt1",
6840
- "dk2",
6841
- "lt2",
6842
- "accent1",
6843
- "accent2",
6844
- "accent3",
6845
- "accent4",
6846
- "accent5",
6847
- "accent6",
6848
- "hlink",
6849
- "folHlink"
6850
- ];
6851
- function readThemeSlotColor(colorEl) {
6852
- if (colorEl.tag === "a:srgbClr") {
6853
- const val = attr$1(colorEl, "val");
6854
- return val === void 0 ? void 0 : rgbHexToColor(val);
6855
- }
6856
- if (colorEl.tag === "a:sysClr") {
6857
- const lastClr = attr$1(colorEl, "lastClr");
6858
- if (lastClr !== void 0) return rgbHexToColor(lastClr);
6859
- return attr$1(colorEl, "val") === "window" ? {
6860
- r: 1,
6861
- g: 1,
6862
- b: 1
6863
- } : {
6864
- r: 0,
6865
- g: 0,
6866
- b: 0
6867
- };
6868
- }
6869
- }
6870
- function readClrScheme(clrSchemeEl) {
6871
- const map = /* @__PURE__ */ new Map();
6872
- for (const slot of CLR_SCHEME_SLOTS) {
6873
- const wrapper = childrenWithTag$1(clrSchemeEl, `a:${slot}`)[0];
6874
- if (wrapper === void 0) continue;
6875
- const colorEl = wrapper.children.find((c) => c.type === "element");
6876
- if (colorEl === void 0) continue;
6877
- const color = readThemeSlotColor(colorEl);
6878
- if (color !== void 0) map.set(slot, color);
6879
- }
6880
- return map;
6881
- }
6882
- function readSchemeFont(fontSchemeEl, tag) {
6883
- if (fontSchemeEl === void 0) return;
6884
- const fontEl = childrenWithTag$1(fontSchemeEl, tag)[0];
6885
- const latin = fontEl === void 0 ? void 0 : childrenWithTag$1(fontEl, "a:latin")[0];
6886
- return latin === void 0 ? void 0 : attr$1(latin, "typeface");
6887
- }
6888
- const DEFAULT_THEME_FONT = "Calibri";
6889
- const EMPTY_THEME = {
6890
- colorScheme: /* @__PURE__ */ new Map(),
6891
- majorFont: DEFAULT_THEME_FONT,
6892
- minorFont: DEFAULT_THEME_FONT
6893
- };
6894
- function readTheme(themeRoot) {
6895
- const clrSchemeEl = elementsWithTag$1([themeRoot], "a:clrScheme")[0];
6896
- const colorScheme = clrSchemeEl === void 0 ? /* @__PURE__ */ new Map() : readClrScheme(clrSchemeEl);
6897
- const fontSchemeEl = elementsWithTag$1([themeRoot], "a:fontScheme")[0];
6898
- return {
6899
- colorScheme,
6900
- majorFont: readSchemeFont(fontSchemeEl, "a:majorFont") ?? DEFAULT_THEME_FONT,
6901
- minorFont: readSchemeFont(fontSchemeEl, "a:minorFont") ?? DEFAULT_THEME_FONT
6902
- };
6903
- }
6904
- function resolveThemeFontReference(typeface, theme) {
6905
- if (typeface === "+mj-lt") return theme.majorFont;
6906
- if (typeface === "+mn-lt") return theme.minorFont;
6907
- return typeface;
6908
- }
6909
- function readColorMap(clrMapEl) {
6910
- const map = /* @__PURE__ */ new Map();
6911
- if (clrMapEl === void 0) return map;
6912
- for (const a of clrMapEl.attributes) map.set(a.name, a.value);
6913
- return map;
6914
- }
6915
- function resolveSchemeColorSlot(schemeVal, colorMap) {
6916
- return colorMap.get(schemeVal) ?? schemeVal;
6917
- }
6918
- const COLOR_TRANSFORM_TAGS = /* @__PURE__ */ new Map([
6919
- ["a:shade", "shade"],
6920
- ["a:tint", "tint"],
6921
- ["a:lumMod", "lumMod"],
6922
- ["a:lumOff", "lumOff"]
6923
- ]);
6924
- function readColorTransforms(container) {
6925
- const transforms = [];
6926
- for (const child of container.children) {
6927
- if (child.type !== "element") continue;
6928
- const kind = COLOR_TRANSFORM_TAGS.get(child.tag);
6929
- if (kind === void 0) continue;
6930
- const val = attr$1(child, "val");
6931
- if (val === void 0) continue;
6932
- transforms.push({
6933
- kind,
6934
- value: Number(val)
6935
- });
6936
- }
6937
- return transforms;
6938
- }
6939
- function readSchemeColor(schemeClrEl, colorMap, theme) {
6940
- const val = attr$1(schemeClrEl, "val");
6941
- if (val === void 0) return;
6942
- const base = theme.colorScheme.get(resolveSchemeColorSlot(val, colorMap));
6943
- return base === void 0 ? void 0 : applyColorTransforms(base, readColorTransforms(schemeClrEl));
6944
- }
6945
- function readSrgbColor(srgbClrEl) {
6946
- const val = attr$1(srgbClrEl, "val");
6947
- return val === void 0 ? void 0 : applyColorTransforms(rgbHexToColor(val), readColorTransforms(srgbClrEl));
6948
- }
6949
- function readSolidFillColor(solidFillEl, colorMap, theme) {
6950
- if (solidFillEl === void 0) return;
6951
- const schemeClr = childrenWithTag$1(solidFillEl, "a:schemeClr")[0];
6952
- if (schemeClr !== void 0) return readSchemeColor(schemeClr, colorMap, theme);
6953
- const srgbClr = childrenWithTag$1(solidFillEl, "a:srgbClr")[0];
6954
- return srgbClr === void 0 ? void 0 : readSrgbColor(srgbClr);
6955
- }
6956
- function readGroupXfrm(xfrm) {
6957
- const base = readXfrm(xfrm);
6958
- if (base === void 0 || xfrm === void 0) return;
6959
- const chOff = childrenWithTag$1(xfrm, "a:chOff")[0];
6960
- const chExt = childrenWithTag$1(xfrm, "a:chExt")[0];
6961
- if (chOff === void 0 || chExt === void 0) return;
6962
- const cx = attr$1(chOff, "x");
6963
- const cy = attr$1(chOff, "y");
6964
- const ccx = attr$1(chExt, "cx");
6965
- const ccy = attr$1(chExt, "cy");
6966
- if (cx === void 0 || cy === void 0 || ccx === void 0 || ccy === void 0) return;
6967
- return {
6968
- offXPt: base.xPt,
6969
- offYPt: base.yPt,
6970
- extWidthPt: base.widthPt,
6971
- extHeightPt: base.heightPt,
6972
- childOffXPt: emuToPt(Number(cx)),
6973
- childOffYPt: emuToPt(Number(cy)),
6974
- childExtWidthPt: emuToPt(Number(ccx)),
6975
- childExtHeightPt: emuToPt(Number(ccy))
6976
- };
6977
- }
6978
- function applyGroupTransform(group, childFrame) {
6979
- const scaleX = group.childExtWidthPt === 0 ? 1 : group.extWidthPt / group.childExtWidthPt;
6980
- const scaleY = group.childExtHeightPt === 0 ? 1 : group.extHeightPt / group.childExtHeightPt;
6981
- return {
6982
- xPt: group.offXPt + (childFrame.xPt - group.childOffXPt) * scaleX,
6983
- yPt: group.offYPt + (childFrame.yPt - group.childOffYPt) * scaleY,
6984
- widthPt: childFrame.widthPt * scaleX,
6985
- heightPt: childFrame.heightPt * scaleY
6986
- };
6987
- }
6988
- //#endregion
6989
- //#region src/ooxml/docx/styles.ts
6990
- function mergeParagraphLayer(base, layer) {
6991
- return {
6992
- alignment: layer.alignment ?? base.alignment,
6993
- spacingBeforePt: layer.spacingBeforePt ?? base.spacingBeforePt,
6994
- spacingAfterPt: layer.spacingAfterPt ?? base.spacingAfterPt,
6995
- lineSpacing: layer.lineSpacing ?? base.lineSpacing,
6996
- indentLeftPt: layer.indentLeftPt ?? base.indentLeftPt,
6997
- indentFirstLinePt: layer.indentFirstLinePt ?? base.indentFirstLinePt
6998
- };
6999
- }
7000
- function mergeRunLayer(base, layer) {
7001
- return {
7002
- bold: layer.bold ?? base.bold,
7003
- italic: layer.italic ?? base.italic,
7004
- underline: layer.underline ?? base.underline,
7005
- strike: layer.strike ?? base.strike,
7006
- fontFamily: layer.fontFamily ?? base.fontFamily,
7007
- sizePt: layer.sizePt ?? base.sizePt,
7008
- color: layer.color ?? base.color
7009
- };
7010
- }
7011
- function readToggle$1(el) {
7012
- if (el === void 0) return;
7013
- const val = attr$1(el, "w:val");
7014
- return val === void 0 || val !== "0" && val !== "false" && val !== "off";
7015
- }
7016
- function readUnderline(u) {
7017
- if (u === void 0) return;
7018
- const val = attr$1(u, "w:val");
7019
- return val !== void 0 && val !== "none";
7020
- }
7021
- function readRunColor(colorEl) {
7022
- if (colorEl === void 0) return;
7023
- const val = attr$1(colorEl, "w:val");
7024
- return val === void 0 || val === "auto" ? void 0 : rgbHexToColor(val);
7025
- }
7026
- function readRunFontFamily(rFonts, theme) {
7027
- if (rFonts === void 0) return;
7028
- const ascii = attr$1(rFonts, "w:ascii");
7029
- if (ascii !== void 0) return ascii;
7030
- const asciiTheme = attr$1(rFonts, "w:asciiTheme");
7031
- if (asciiTheme === "majorHAnsi" || asciiTheme === "majorAscii") return theme.majorFont;
7032
- if (asciiTheme === "minorHAnsi" || asciiTheme === "minorAscii") return theme.minorFont;
7033
- }
7034
- function readRunPropertiesLayer(rPr, theme) {
7035
- if (rPr === void 0) return {};
7036
- const sz = childrenWithTag$1(rPr, "w:sz")[0];
7037
- const szVal = sz === void 0 ? void 0 : attr$1(sz, "w:val");
7038
- return {
7039
- bold: readToggle$1(childrenWithTag$1(rPr, "w:b")[0]),
7040
- italic: readToggle$1(childrenWithTag$1(rPr, "w:i")[0]),
7041
- underline: readUnderline(childrenWithTag$1(rPr, "w:u")[0]),
7042
- strike: readToggle$1(childrenWithTag$1(rPr, "w:strike")[0]),
7043
- fontFamily: readRunFontFamily(childrenWithTag$1(rPr, "w:rFonts")[0], theme),
7044
- sizePt: szVal === void 0 ? void 0 : halfPointsToPt(Number(szVal)),
7045
- color: readRunColor(childrenWithTag$1(rPr, "w:color")[0])
7046
- };
7047
- }
7048
- function readAlignment$1(jc) {
7049
- const val = jc === void 0 ? void 0 : attr$1(jc, "w:val");
7050
- if (val === "left" || val === "start") return "left";
7051
- if (val === "center") return "center";
7052
- if (val === "right" || val === "end") return "right";
7053
- if (val === "both" || val === "distribute") return "justify";
7054
- }
7055
- function readParagraphPropertiesLayer(pPr) {
7056
- if (pPr === void 0) return {};
7057
- const spacing = childrenWithTag$1(pPr, "w:spacing")[0];
7058
- const before = spacing === void 0 ? void 0 : attr$1(spacing, "w:before");
7059
- const after = spacing === void 0 ? void 0 : attr$1(spacing, "w:after");
7060
- const line = spacing === void 0 ? void 0 : attr$1(spacing, "w:line");
7061
- const lineRule = spacing === void 0 ? void 0 : attr$1(spacing, "w:lineRule");
7062
- const ind = childrenWithTag$1(pPr, "w:ind")[0];
7063
- const left = ind === void 0 ? void 0 : attr$1(ind, "w:left") ?? attr$1(ind, "w:start");
7064
- const firstLine = ind === void 0 ? void 0 : attr$1(ind, "w:firstLine");
7065
- const hanging = ind === void 0 ? void 0 : attr$1(ind, "w:hanging");
7066
- return {
7067
- alignment: readAlignment$1(childrenWithTag$1(pPr, "w:jc")[0]),
7068
- spacingBeforePt: before === void 0 ? void 0 : twipsToPt(Number(before)),
7069
- spacingAfterPt: after === void 0 ? void 0 : twipsToPt(Number(after)),
7070
- lineSpacing: line === void 0 || lineRule === "exact" || lineRule === "atLeast" ? void 0 : lineUnitsToMultiplier(Number(line)),
7071
- indentLeftPt: left === void 0 ? void 0 : twipsToPt(Number(left)),
7072
- indentFirstLinePt: firstLine !== void 0 ? twipsToPt(Number(firstLine)) : hanging !== void 0 ? -twipsToPt(Number(hanging)) : void 0
7073
- };
7074
- }
7075
- function findStyle(stylesRoot, styleId, type) {
7076
- return elementsWithTag$1([stylesRoot], "w:style").find((s) => attr$1(s, "w:type") === type && attr$1(s, "w:styleId") === styleId);
7077
- }
7078
- function findDefaultStyle(stylesRoot, type) {
7079
- return elementsWithTag$1([stylesRoot], "w:style").find((s) => attr$1(s, "w:type") === type && attr$1(s, "w:default") === "1");
7080
- }
7081
- function resolveBasedOnChain(stylesRoot, styleId, type) {
7082
- const chain = [];
7083
- const visited = /* @__PURE__ */ new Set();
7084
- let currentId = styleId;
7085
- while (currentId !== void 0 && !visited.has(currentId)) {
7086
- visited.add(currentId);
7087
- const style = findStyle(stylesRoot, currentId, type);
7088
- if (style === void 0) break;
7089
- chain.unshift(style);
7090
- const basedOn = childrenWithTag$1(style, "w:basedOn")[0];
7091
- currentId = basedOn === void 0 ? void 0 : attr$1(basedOn, "w:val");
7092
- }
7093
- return chain;
7094
- }
7095
- function docDefaultsElement(stylesRoot, wrapperTag, innerTag) {
7096
- const docDefaults = stylesRoot === void 0 ? void 0 : childrenWithTag$1(stylesRoot, "w:docDefaults")[0];
7097
- const wrapper = docDefaults === void 0 ? void 0 : childrenWithTag$1(docDefaults, wrapperTag)[0];
7098
- return wrapper === void 0 ? void 0 : childrenWithTag$1(wrapper, innerTag)[0];
7099
- }
7100
- function resolveParagraphProperties(paragraph, context) {
7101
- const pPr = childrenWithTag$1(paragraph, "w:pPr")[0];
7102
- const pStyleEl = pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "w:pStyle")[0];
7103
- const styleId = pStyleEl === void 0 ? void 0 : attr$1(pStyleEl, "w:val");
7104
- let resolved = readParagraphPropertiesLayer(docDefaultsElement(context.stylesRoot, "w:pPrDefault", "w:pPr"));
7105
- if (context.stylesRoot !== void 0) {
7106
- const defaultStyle = findDefaultStyle(context.stylesRoot, "paragraph");
7107
- if (defaultStyle !== void 0) resolved = mergeParagraphLayer(resolved, readParagraphPropertiesLayer(childrenWithTag$1(defaultStyle, "w:pPr")[0]));
7108
- if (styleId !== void 0) for (const style of resolveBasedOnChain(context.stylesRoot, styleId, "paragraph")) resolved = mergeParagraphLayer(resolved, readParagraphPropertiesLayer(childrenWithTag$1(style, "w:pPr")[0]));
7109
- }
7110
- return mergeParagraphLayer(resolved, readParagraphPropertiesLayer(pPr));
7111
- }
7112
- function resolveRunProperties(run, paragraph, context) {
7113
- const pPr = childrenWithTag$1(paragraph, "w:pPr")[0];
7114
- const pStyleEl = pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "w:pStyle")[0];
7115
- const pStyleId = pStyleEl === void 0 ? void 0 : attr$1(pStyleEl, "w:val");
7116
- let resolved = readRunPropertiesLayer(docDefaultsElement(context.stylesRoot, "w:rPrDefault", "w:rPr"), context.theme);
7117
- if (context.stylesRoot !== void 0) {
7118
- const defaultStyle = findDefaultStyle(context.stylesRoot, "paragraph");
7119
- if (defaultStyle !== void 0) resolved = mergeRunLayer(resolved, readRunPropertiesLayer(childrenWithTag$1(defaultStyle, "w:rPr")[0], context.theme));
7120
- 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));
7121
- }
7122
- const paragraphMarkRPr = pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "w:rPr")[0];
7123
- resolved = mergeRunLayer(resolved, readRunPropertiesLayer(paragraphMarkRPr, context.theme));
7124
- const rPr = childrenWithTag$1(run, "w:rPr")[0];
7125
- const rStyleEl = rPr === void 0 ? void 0 : childrenWithTag$1(rPr, "w:rStyle")[0];
7126
- const rStyleId = rStyleEl === void 0 ? void 0 : attr$1(rStyleEl, "w:val");
7127
- 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));
7128
- return mergeRunLayer(resolved, readRunPropertiesLayer(rPr, context.theme));
7129
- }
7130
- //#endregion
7131
6622
  //#region src/ooxml/docx/read.ts
7132
- const DOCUMENT_PART_PATH = "word/document.xml";
7133
- const STYLES_PART_PATH = "word/styles.xml";
7134
- const THEME_REL_SUFFIX$1 = "/theme";
7135
- const DEFAULT_MARGIN_PT = 72;
7136
- const DEFAULT_MARGINS = {
7137
- topPt: DEFAULT_MARGIN_PT,
7138
- rightPt: DEFAULT_MARGIN_PT,
7139
- bottomPt: DEFAULT_MARGIN_PT,
7140
- leftPt: DEFAULT_MARGIN_PT
7141
- };
7142
- function readPageSize(sectPr) {
7143
- const pgSz = childrenWithTag$1(sectPr, "w:pgSz")[0];
7144
- const w = pgSz === void 0 ? void 0 : attr$1(pgSz, "w:w");
7145
- const h = pgSz === void 0 ? void 0 : attr$1(pgSz, "w:h");
7146
- return w === void 0 || h === void 0 ? PAGE_SIZE_LETTER : {
7147
- widthPt: twipsToPt(Number(w)),
7148
- heightPt: twipsToPt(Number(h))
7149
- };
7150
- }
7151
- function readMargins(sectPr) {
7152
- const pgMar = childrenWithTag$1(sectPr, "w:pgMar")[0];
7153
- if (pgMar === void 0) return DEFAULT_MARGINS;
7154
- const top = attr$1(pgMar, "w:top");
7155
- const right = attr$1(pgMar, "w:right");
7156
- const bottom = attr$1(pgMar, "w:bottom");
7157
- const left = attr$1(pgMar, "w:left");
7158
- return {
7159
- topPt: top === void 0 ? DEFAULT_MARGIN_PT : twipsToPt(Number(top)),
7160
- rightPt: right === void 0 ? DEFAULT_MARGIN_PT : twipsToPt(Number(right)),
7161
- bottomPt: bottom === void 0 ? DEFAULT_MARGIN_PT : twipsToPt(Number(bottom)),
7162
- leftPt: left === void 0 ? DEFAULT_MARGIN_PT : twipsToPt(Number(left))
7163
- };
7164
- }
7165
- function readListMembership(pPr) {
7166
- const numPr = pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "w:numPr")[0];
7167
- if (numPr === void 0) return;
7168
- const numIdEl = childrenWithTag$1(numPr, "w:numId")[0];
7169
- const numId = numIdEl === void 0 ? void 0 : attr$1(numIdEl, "w:val");
7170
- if (numId === void 0) return;
7171
- const ilvlEl = childrenWithTag$1(numPr, "w:ilvl")[0];
7172
- const ilvlVal = ilvlEl === void 0 ? void 0 : attr$1(ilvlEl, "w:val");
7173
- return {
7174
- numId,
7175
- level: ilvlVal === void 0 ? 0 : Number(ilvlVal)
7176
- };
7177
- }
7178
- function readToggle(el) {
7179
- if (el === void 0) return false;
7180
- const val = attr$1(el, "w:val");
7181
- return val === void 0 || val !== "0" && val !== "false" && val !== "off";
7182
- }
7183
- function hasPageBreakBefore(paragraph) {
7184
- const pPr = childrenWithTag$1(paragraph, "w:pPr")[0];
7185
- return readToggle(pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "w:pageBreakBefore")[0]);
7186
- }
7187
- function readRunText(run) {
7188
- let text = "";
7189
- for (const child of run.children) {
7190
- if (child.type !== "element") continue;
7191
- if (child.tag === "w:t") text += textContent$1(child);
7192
- else if (child.tag === "w:tab") text += " ";
7193
- else if (child.tag === "w:br" || child.tag === "w:cr") text += "\n";
7194
- }
7195
- return text;
7196
- }
7197
- function readRun$1(run, paragraph, context) {
7198
- const props = resolveRunProperties(run, paragraph, context);
7199
- return {
7200
- text: readRunText(run),
7201
- bold: props.bold,
7202
- italic: props.italic,
7203
- underline: props.underline,
7204
- strike: props.strike,
7205
- fontFamily: props.fontFamily,
7206
- sizePt: props.sizePt,
7207
- color: props.color
7208
- };
7209
- }
7210
- function readParagraphRuns(paragraph, context, rels) {
7211
- const runs = [];
7212
- let fieldState = "none";
7213
- function walk(nodes, hyperlinkTarget) {
7214
- for (const node of nodes) {
7215
- if (node.type !== "element") continue;
7216
- if (node.tag === "w:r") {
7217
- const fldChar = childrenWithTag$1(node, "w:fldChar")[0];
7218
- if (fldChar !== void 0) {
7219
- const type = attr$1(fldChar, "w:fldCharType");
7220
- if (type === "begin") fieldState = "code";
7221
- else if (type === "separate") fieldState = "result";
7222
- else if (type === "end") fieldState = "none";
7223
- continue;
7224
- }
7225
- if (fieldState === "code") continue;
7226
- const run = readRun$1(node, paragraph, context);
7227
- runs.push(hyperlinkTarget === void 0 ? run : {
7228
- ...run,
7229
- hyperlink: hyperlinkTarget
7230
- });
7231
- } else if (node.tag === "w:fldSimple") walk(node.children, hyperlinkTarget);
7232
- else if (node.tag === "w:hyperlink") {
7233
- const rId = attr$1(node, "r:id");
7234
- const target = rId === void 0 ? void 0 : rels.get(rId)?.target;
7235
- walk(node.children, target ?? hyperlinkTarget);
7236
- } else if (node.tag === "w:ins") walk(node.children, hyperlinkTarget);
7237
- }
7238
- }
7239
- walk(paragraph.children, void 0);
7240
- return runs;
7241
- }
7242
- function readParagraph$1(paragraph, context, rels) {
7243
- const pPr = childrenWithTag$1(paragraph, "w:pPr")[0];
7244
- const pStyleEl = pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "w:pStyle")[0];
7245
- const props = resolveParagraphProperties(paragraph, context);
7246
- return {
7247
- kind: "paragraph",
7248
- runs: readParagraphRuns(paragraph, context, rels),
7249
- styleId: pStyleEl === void 0 ? void 0 : attr$1(pStyleEl, "w:val"),
7250
- alignment: props.alignment,
7251
- list: readListMembership(pPr),
7252
- spacingBeforePt: props.spacingBeforePt,
7253
- spacingAfterPt: props.spacingAfterPt,
7254
- lineSpacing: props.lineSpacing,
7255
- indentLeftPt: props.indentLeftPt,
7256
- indentFirstLinePt: props.indentFirstLinePt
7257
- };
7258
- }
7259
- function readCellShading(tcPr) {
7260
- const shd = tcPr === void 0 ? void 0 : childrenWithTag$1(tcPr, "w:shd")[0];
7261
- const fill = shd === void 0 ? void 0 : attr$1(shd, "w:fill");
7262
- return fill === void 0 || fill === "auto" || fill === "none" ? void 0 : rgbHexToColor(fill);
7263
- }
7264
- function readRawCell(tc, context, rels) {
7265
- const tcPr = childrenWithTag$1(tc, "w:tcPr")[0];
7266
- const gridSpanEl = tcPr === void 0 ? void 0 : childrenWithTag$1(tcPr, "w:gridSpan")[0];
7267
- const gridSpanVal = gridSpanEl === void 0 ? void 0 : attr$1(gridSpanEl, "w:val");
7268
- const vMerge = tcPr === void 0 ? void 0 : childrenWithTag$1(tcPr, "w:vMerge")[0];
7269
- const vMergeVal = vMerge === void 0 ? void 0 : attr$1(vMerge, "w:val") ?? "continue";
7270
- return {
7271
- gridSpan: gridSpanVal === void 0 ? 1 : Number(gridSpanVal),
7272
- isVMergeContinuation: vMergeVal === "continue",
7273
- background: readCellShading(tcPr),
7274
- blocks: readBodyBlocks(tc.children, context, rels)
7275
- };
7276
- }
7277
- function readTable$1(tbl, context, rels) {
7278
- const tblGrid = childrenWithTag$1(tbl, "w:tblGrid")[0];
7279
- const columnWidthsPt = tblGrid === void 0 ? [] : childrenWithTag$1(tblGrid, "w:gridCol").map((col) => twipsToPt(Number(attr$1(col, "w:w") ?? "0")));
7280
- const rawRows = childrenWithTag$1(tbl, "w:tr").map((tr) => childrenWithTag$1(tr, "w:tc").map((tc) => readRawCell(tc, context, rels)));
7281
- const rowColumnIndices = rawRows.map((row) => {
7282
- const indices = [];
7283
- let col = 0;
7284
- for (const cell of row) {
7285
- indices.push(col);
7286
- col += cell.gridSpan;
7287
- }
7288
- return indices;
7289
- });
7290
- return {
7291
- kind: "table",
7292
- columnWidthsPt,
7293
- rows: rawRows.map((row, rowIndex) => ({ cells: row.map((cell, cellIndex) => {
7294
- if (cell.isVMergeContinuation) return { blocks: [] };
7295
- const colIndex = rowColumnIndices[rowIndex][cellIndex];
7296
- let rowSpan = 1;
7297
- for (let r = rowIndex + 1; r < rawRows.length; r++) {
7298
- const matchIndex = rowColumnIndices[r].indexOf(colIndex);
7299
- if (!(matchIndex === -1 ? void 0 : rawRows[r][matchIndex])?.isVMergeContinuation) break;
7300
- rowSpan++;
7301
- }
7302
- return {
7303
- blocks: cell.blocks,
7304
- colSpan: cell.gridSpan > 1 ? cell.gridSpan : void 0,
7305
- rowSpan: rowSpan > 1 ? rowSpan : void 0,
7306
- background: cell.background
7307
- };
7308
- }) }))
7309
- };
7310
- }
7311
- function readBodyBlocks(nodes, context, rels) {
7312
- const blocks = [];
7313
- for (const node of nodes) {
7314
- if (node.type !== "element") continue;
7315
- if (node.tag === "w:p") {
7316
- if (hasPageBreakBefore(node)) blocks.push({ kind: "pageBreak" });
7317
- blocks.push(readParagraph$1(node, context, rels));
7318
- } else if (node.tag === "w:tbl") blocks.push(readTable$1(node, context, rels));
7319
- else if (node.tag === "w:sdt") {
7320
- const sdtContent = childrenWithTag$1(node, "w:sdtContent")[0];
7321
- if (sdtContent !== void 0) blocks.push(...readBodyBlocks(sdtContent.children, context, rels));
7322
- } else if (node.tag === "w:ins") blocks.push(...readBodyBlocks(node.children, context, rels));
7323
- else if (node.tag === "mc:AlternateContent") {
7324
- const target = childrenWithTag$1(node, "mc:Fallback")[0] ?? childrenWithTag$1(node, "mc:Choice")[0];
7325
- if (target !== void 0) blocks.push(...readBodyBlocks(target.children, context, rels));
7326
- }
7327
- }
7328
- return blocks;
7329
- }
7330
- function readSections(body, context, rels) {
7331
- const sections = [];
7332
- let currentBlocks = [];
7333
- for (const node of body.children) {
7334
- if (node.type !== "element") continue;
7335
- if (node.tag === "w:sectPr") {
7336
- sections.push({
7337
- pageSize: readPageSize(node),
7338
- margins: readMargins(node),
7339
- blocks: currentBlocks
7340
- });
7341
- currentBlocks = [];
7342
- continue;
7343
- }
7344
- if (node.tag === "w:p") {
7345
- const pPr = childrenWithTag$1(node, "w:pPr")[0];
7346
- const sectPr = pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "w:sectPr")[0];
7347
- if (hasPageBreakBefore(node)) currentBlocks.push({ kind: "pageBreak" });
7348
- currentBlocks.push(readParagraph$1(node, context, rels));
7349
- if (sectPr !== void 0) {
7350
- sections.push({
7351
- pageSize: readPageSize(sectPr),
7352
- margins: readMargins(sectPr),
7353
- blocks: currentBlocks
7354
- });
7355
- currentBlocks = [];
7356
- }
7357
- continue;
7358
- }
7359
- currentBlocks.push(...readBodyBlocks([node], context, rels));
7360
- }
7361
- if (currentBlocks.length > 0 || sections.length === 0) sections.push({
7362
- pageSize: PAGE_SIZE_LETTER,
7363
- margins: DEFAULT_MARGINS,
7364
- blocks: currentBlocks
7365
- });
7366
- return sections;
7367
- }
7368
- function readDocumentTheme(pkg, docRels) {
7369
- for (const rel of docRels.values()) if (rel.type.endsWith(THEME_REL_SUFFIX$1)) {
7370
- const themeRoot = rootElement$1(pkg.parts[rel.target]);
7371
- if (themeRoot !== void 0) return readTheme(themeRoot);
7372
- }
7373
- return EMPTY_THEME;
7374
- }
7375
6623
  function readDocxContent(pkg) {
7376
- const documentRoot = rootElement$1(pkg.parts[DOCUMENT_PART_PATH]);
7377
- if (documentRoot === void 0) throw new Error(`package has no ${DOCUMENT_PART_PATH} part`);
7378
- const body = childrenWithTag$1(documentRoot, "w:body")[0];
7379
- if (body === void 0) throw new Error(`${DOCUMENT_PART_PATH} has no w:body element`);
7380
- const docRels = resolveRelationships$1(pkg, DOCUMENT_PART_PATH);
7381
- const context = {
7382
- stylesRoot: rootElement$1(pkg.parts[STYLES_PART_PATH]),
7383
- theme: readDocumentTheme(pkg, docRels)
7384
- };
6624
+ const docxDoc = readDocx(pkg);
7385
6625
  return {
7386
6626
  kind: "wordprocessing",
7387
6627
  formatVersion: 1,
7388
- metadata: readCoreProperties(pkg),
7389
- sections: readSections(body, context, docRels)
7390
- };
7391
- }
7392
- //#endregion
7393
- //#region src/image/sniff.ts
7394
- const PNG_SIGNATURE = [
7395
- 137,
7396
- 80,
7397
- 78,
7398
- 71,
7399
- 13,
7400
- 10,
7401
- 26,
7402
- 10
7403
- ];
7404
- const JPEG_SIGNATURE = [
7405
- 255,
7406
- 216,
7407
- 255
7408
- ];
7409
- function startsWith(bytes, signature) {
7410
- if (bytes.length < signature.length) return false;
7411
- for (let i = 0; i < signature.length; i++) if (bytes[i] !== signature[i]) return false;
7412
- return true;
7413
- }
7414
- function sniffImageFormat(bytes) {
7415
- if (startsWith(bytes, PNG_SIGNATURE)) return "png";
7416
- if (startsWith(bytes, JPEG_SIGNATURE)) return "jpeg";
7417
- }
7418
- //#endregion
7419
- //#region src/ooxml/pptx/inherit.ts
7420
- const SLIDE_LAYOUT_REL_SUFFIX = "/slideLayout";
7421
- const SLIDE_MASTER_REL_SUFFIX = "/slideMaster";
7422
- const THEME_REL_SUFFIX = "/theme";
7423
- function findRelTarget(pkg, partPath, typeSuffix) {
7424
- for (const rel of resolveRelationships$1(pkg, partPath).values()) if (rel.type.endsWith(typeSuffix)) return rel.target;
7425
- }
7426
- function resolveSlideInheritance(pkg, slidePath) {
7427
- const layoutPath = findRelTarget(pkg, slidePath, SLIDE_LAYOUT_REL_SUFFIX);
7428
- const layoutRoot = layoutPath === void 0 ? void 0 : rootElement$1(pkg.parts[layoutPath]);
7429
- const masterPath = layoutPath === void 0 ? void 0 : findRelTarget(pkg, layoutPath, SLIDE_MASTER_REL_SUFFIX);
7430
- const masterRoot = masterPath === void 0 ? void 0 : rootElement$1(pkg.parts[masterPath]);
7431
- const themePath = masterPath === void 0 ? void 0 : findRelTarget(pkg, masterPath, THEME_REL_SUFFIX);
7432
- const themeRoot = themePath === void 0 ? void 0 : rootElement$1(pkg.parts[themePath]);
7433
- return {
7434
- layoutRoot,
7435
- masterRoot,
7436
- theme: themeRoot === void 0 ? EMPTY_THEME : readTheme(themeRoot),
7437
- colorMap: readColorMap(masterRoot === void 0 ? void 0 : childrenWithTag$1(masterRoot, "p:clrMap")[0])
7438
- };
7439
- }
7440
- const TYPE_NORMALIZATION = /* @__PURE__ */ new Map([["ctrTitle", "title"], ["subTitle", "body"]]);
7441
- function normalizePlaceholderType(type) {
7442
- return type === void 0 ? void 0 : TYPE_NORMALIZATION.get(type) ?? type;
7443
- }
7444
- function readPlaceholderKey(shape) {
7445
- const ph = elementsWithTag$1([shape], "p:ph")[0];
7446
- return ph === void 0 ? void 0 : {
7447
- type: attr$1(ph, "type"),
7448
- idx: attr$1(ph, "idx")
6628
+ metadata: { ...docxDoc.metadata },
6629
+ sections: docxDoc.sections
7449
6630
  };
7450
6631
  }
7451
- function shapesOf(root) {
7452
- return root === void 0 ? [] : elementsWithTag$1([root], "p:sp");
7453
- }
7454
- function findMatchingPlaceholder(root, key) {
7455
- const shapes = shapesOf(root);
7456
- if (key.idx !== void 0) {
7457
- const byIdx = shapes.find((shape) => readPlaceholderKey(shape)?.idx === key.idx);
7458
- if (byIdx !== void 0) return byIdx;
7459
- }
7460
- const normalizedTarget = normalizePlaceholderType(key.type);
7461
- if (normalizedTarget === void 0) return;
7462
- return shapes.find((shape) => normalizePlaceholderType(readPlaceholderKey(shape)?.type) === normalizedTarget);
7463
- }
7464
- function shapeXfrm(shape) {
7465
- if (shape === void 0) return;
7466
- const spPr = childrenWithTag$1(shape, "p:spPr")[0];
7467
- return spPr === void 0 ? void 0 : readXfrm(childrenWithTag$1(spPr, "a:xfrm")[0]);
7468
- }
7469
- function resolvePlaceholderXfrm(key, context) {
7470
- return shapeXfrm(findMatchingPlaceholder(context.layoutRoot, key)) ?? shapeXfrm(findMatchingPlaceholder(context.masterRoot, key));
7471
- }
7472
- function readRunPropertiesFromElement(rPr, context) {
7473
- const sz = attr$1(rPr, "sz");
7474
- const latin = childrenWithTag$1(rPr, "a:latin")[0];
7475
- const typeface = latin === void 0 ? void 0 : attr$1(latin, "typeface");
7476
- const solidFill = childrenWithTag$1(rPr, "a:solidFill")[0];
7477
- const bold = attr$1(rPr, "b");
7478
- const italic = attr$1(rPr, "i");
7479
- return {
7480
- fontFamily: typeface === void 0 ? void 0 : resolveThemeFontReference(typeface, context.theme),
7481
- sizePt: sz === void 0 ? void 0 : drawingMlFontSizeToPt(Number(sz)),
7482
- bold: bold === void 0 ? void 0 : bold === "1",
7483
- italic: italic === void 0 ? void 0 : italic === "1",
7484
- color: readSolidFillColor(solidFill, context.colorMap, context.theme)
7485
- };
7486
- }
7487
- function txStyleTagFor(placeholderType) {
7488
- const normalized = normalizePlaceholderType(placeholderType);
7489
- if (normalized === "title") return "p:titleStyle";
7490
- if (normalized === "body") return "p:bodyStyle";
7491
- return "p:otherStyle";
7492
- }
7493
- function levelTag(level) {
7494
- return `a:lvl${Math.min(Math.max(level, 0), 8) + 1}pPr`;
7495
- }
7496
- function resolveDefaultRunProperties(placeholderType, level, context) {
7497
- if (context.masterRoot === void 0) return {};
7498
- const txStyles = childrenWithTag$1(context.masterRoot, "p:txStyles")[0];
7499
- const styleEl = txStyles === void 0 ? void 0 : childrenWithTag$1(txStyles, txStyleTagFor(placeholderType))[0];
7500
- const lvlPPr = styleEl === void 0 ? void 0 : childrenWithTag$1(styleEl, levelTag(level))[0];
7501
- const defRPr = lvlPPr === void 0 ? void 0 : childrenWithTag$1(lvlPPr, "a:defRPr")[0];
7502
- return defRPr === void 0 ? {} : readRunPropertiesFromElement(defRPr, context);
7503
- }
7504
6632
  //#endregion
7505
6633
  //#region src/ooxml/pptx/read.ts
7506
- const PRESENTATION_PATH = "ppt/presentation.xml";
7507
- const TABLE_GRAPHIC_URI = "http://schemas.openxmlformats.org/drawingml/2006/table";
7508
- function readSlideSize(presentationRoot) {
7509
- const sldSz = presentationRoot === void 0 ? void 0 : childrenWithTag$1(presentationRoot, "p:sldSz")[0];
7510
- const cx = sldSz === void 0 ? void 0 : attr$1(sldSz, "cx");
7511
- const cy = sldSz === void 0 ? void 0 : attr$1(sldSz, "cy");
7512
- return cx === void 0 || cy === void 0 ? SLIDE_SIZE_WIDESCREEN : {
7513
- widthPt: emuToPt(Number(cx)),
7514
- heightPt: emuToPt(Number(cy))
7515
- };
7516
- }
7517
- function readSlidePathsInOrder(pkg, presentationRoot) {
7518
- if (presentationRoot === void 0) return [];
7519
- const sldIdLst = childrenWithTag$1(presentationRoot, "p:sldIdLst")[0];
7520
- if (sldIdLst === void 0) return [];
7521
- const presentationRels = resolveRelationships$1(pkg, PRESENTATION_PATH);
7522
- const paths = [];
7523
- for (const sldId of childrenWithTag$1(sldIdLst, "p:sldId")) {
7524
- const rId = attr$1(sldId, "r:id");
7525
- const rel = rId === void 0 ? void 0 : presentationRels.get(rId);
7526
- if (rel !== void 0) paths.push(rel.target);
7527
- }
7528
- return paths;
7529
- }
7530
- function shapeName(shape) {
7531
- const cNvPr = elementsWithTag$1([shape], "p:cNvPr")[0];
7532
- return cNvPr === void 0 ? void 0 : attr$1(cNvPr, "name");
7533
- }
7534
- function mergeRunProperties(base, override) {
7535
- return {
7536
- fontFamily: override.fontFamily ?? base.fontFamily,
7537
- sizePt: override.sizePt ?? base.sizePt,
7538
- bold: override.bold ?? base.bold,
7539
- italic: override.italic ?? base.italic,
7540
- color: override.color ?? base.color
7541
- };
7542
- }
7543
- function isUnderlined(rPr) {
7544
- if (rPr === void 0) return;
7545
- const u = attr$1(rPr, "u");
7546
- return u === void 0 ? void 0 : u !== "none";
7547
- }
7548
- function isStrikethrough(rPr) {
7549
- if (rPr === void 0) return;
7550
- const strike = attr$1(rPr, "strike");
7551
- return strike === void 0 ? void 0 : strike !== "noStrike";
7552
- }
7553
- function readHyperlink(rPr, slideRels) {
7554
- if (rPr === void 0) return;
7555
- const hlink = childrenWithTag$1(rPr, "a:hlinkClick")[0];
7556
- const rId = hlink === void 0 ? void 0 : attr$1(hlink, "r:id");
7557
- const rel = rId === void 0 ? void 0 : slideRels.get(rId);
7558
- return rel?.targetMode === "External" ? rel.target : void 0;
7559
- }
7560
- function readRun(runEl, cascadeBase, context, slideRels) {
7561
- const rPr = childrenWithTag$1(runEl, "a:rPr")[0];
7562
- const merged = mergeRunProperties(cascadeBase, rPr === void 0 ? {} : readRunPropertiesFromElement(rPr, context));
7563
- const tEl = childrenWithTag$1(runEl, "a:t")[0];
7564
- return {
7565
- text: tEl === void 0 ? "" : textContent$1(tEl),
7566
- bold: merged.bold,
7567
- italic: merged.italic,
7568
- underline: isUnderlined(rPr),
7569
- strike: isStrikethrough(rPr),
7570
- fontFamily: merged.fontFamily,
7571
- sizePt: merged.sizePt,
7572
- color: merged.color,
7573
- hyperlink: readHyperlink(rPr, slideRels)
7574
- };
7575
- }
7576
- function readAlignment(algn) {
7577
- if (algn === "l") return "left";
7578
- if (algn === "ctr") return "center";
7579
- if (algn === "r") return "right";
7580
- if (algn === "just" || algn === "justLow") return "justify";
7581
- }
7582
- function readAbsoluteSpacingPt(spc) {
7583
- if (spc === void 0) return;
7584
- const pts = childrenWithTag$1(spc, "a:spcPts")[0];
7585
- const val = pts === void 0 ? void 0 : attr$1(pts, "val");
7586
- return val === void 0 ? void 0 : drawingMlFontSizeToPt(Number(val));
7587
- }
7588
- function readLineSpacingMultiplier(pPr) {
7589
- const lnSpc = pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "a:lnSpc")[0];
7590
- const pct = lnSpc === void 0 ? void 0 : childrenWithTag$1(lnSpc, "a:spcPct")[0];
7591
- const val = pct === void 0 ? void 0 : attr$1(pct, "val");
7592
- return val === void 0 ? void 0 : Number(val) / 1e5;
7593
- }
7594
- function readParagraph(pEl, placeholderType, context, slideRels) {
7595
- const pPr = childrenWithTag$1(pEl, "a:pPr")[0];
7596
- const masterDefaults = resolveDefaultRunProperties(placeholderType, pPr === void 0 ? 0 : Number(attr$1(pPr, "lvl") ?? "0"), context);
7597
- const pPrDefRPr = pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "a:defRPr")[0];
7598
- const paragraphDefaults = pPrDefRPr === void 0 ? masterDefaults : mergeRunProperties(masterDefaults, readRunPropertiesFromElement(pPrDefRPr, context));
7599
- const runs = [];
7600
- for (const child of pEl.children) {
7601
- if (child.type !== "element") continue;
7602
- if (child.tag === "a:r" || child.tag === "a:fld") runs.push(readRun(child, paragraphDefaults, context, slideRels));
7603
- else if (child.tag === "a:br") runs.push({ text: "\n" });
7604
- }
7605
- const marL = pPr === void 0 ? void 0 : attr$1(pPr, "marL");
7606
- const indent = pPr === void 0 ? void 0 : attr$1(pPr, "indent");
7607
- return {
7608
- kind: "paragraph",
7609
- runs,
7610
- alignment: pPr === void 0 ? void 0 : readAlignment(attr$1(pPr, "algn")),
7611
- spacingBeforePt: readAbsoluteSpacingPt(pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "a:spcBef")[0]),
7612
- spacingAfterPt: readAbsoluteSpacingPt(pPr === void 0 ? void 0 : childrenWithTag$1(pPr, "a:spcAft")[0]),
7613
- lineSpacing: readLineSpacingMultiplier(pPr),
7614
- indentLeftPt: marL === void 0 ? void 0 : emuToPt(Number(marL)),
7615
- indentFirstLinePt: indent === void 0 ? void 0 : emuToPt(Number(indent))
7616
- };
7617
- }
7618
- function textBodyParagraphs(txBody, placeholderType, context, slideRels) {
7619
- return txBody === void 0 ? [] : childrenWithTag$1(txBody, "a:p").map((p) => readParagraph(p, placeholderType, context, slideRels));
7620
- }
7621
- const DEFAULT_INSET_LEFT_RIGHT_EMU = 91440;
7622
- const DEFAULT_INSET_TOP_BOTTOM_EMU = 45720;
7623
- const NO_TEXT_BODY_EXTRAS = {
7624
- insetLeftPt: 0,
7625
- insetTopPt: 0,
7626
- insetRightPt: 0,
7627
- insetBottomPt: 0,
7628
- fontScale: void 0,
7629
- lineSpacingReduction: void 0
7630
- };
7631
- function readShapeTextExtras(txBody) {
7632
- if (txBody === void 0) return NO_TEXT_BODY_EXTRAS;
7633
- const bodyPr = childrenWithTag$1(txBody, "a:bodyPr")[0];
7634
- const lIns = bodyPr === void 0 ? void 0 : attr$1(bodyPr, "lIns");
7635
- const tIns = bodyPr === void 0 ? void 0 : attr$1(bodyPr, "tIns");
7636
- const rIns = bodyPr === void 0 ? void 0 : attr$1(bodyPr, "rIns");
7637
- const bIns = bodyPr === void 0 ? void 0 : attr$1(bodyPr, "bIns");
7638
- const normAutofit = bodyPr === void 0 ? void 0 : childrenWithTag$1(bodyPr, "a:normAutofit")[0];
7639
- const fontScale = normAutofit === void 0 ? void 0 : attr$1(normAutofit, "fontScale");
7640
- const lnSpcReduction = normAutofit === void 0 ? void 0 : attr$1(normAutofit, "lnSpcReduction");
7641
- return {
7642
- insetLeftPt: emuToPt(lIns === void 0 ? DEFAULT_INSET_LEFT_RIGHT_EMU : Number(lIns)),
7643
- insetTopPt: emuToPt(tIns === void 0 ? DEFAULT_INSET_TOP_BOTTOM_EMU : Number(tIns)),
7644
- insetRightPt: emuToPt(rIns === void 0 ? DEFAULT_INSET_LEFT_RIGHT_EMU : Number(rIns)),
7645
- insetBottomPt: emuToPt(bIns === void 0 ? DEFAULT_INSET_TOP_BOTTOM_EMU : Number(bIns)),
7646
- fontScale: fontScale === void 0 ? void 0 : Number(fontScale) / 1e5,
7647
- lineSpacingReduction: lnSpcReduction === void 0 ? void 0 : Number(lnSpcReduction) / 1e5
7648
- };
7649
- }
7650
- function resolveShapeFrame(shape, context, parentTransform) {
7651
- const key = readPlaceholderKey(shape);
7652
- const spPr = childrenWithTag$1(shape, "p:spPr")[0];
7653
- const xfrm = (spPr === void 0 ? void 0 : readXfrm(childrenWithTag$1(spPr, "a:xfrm")[0])) ?? (key === void 0 ? void 0 : resolvePlaceholderXfrm(key, context));
7654
- if (xfrm === void 0) return;
7655
- const localFrame = {
7656
- xPt: xfrm.xPt,
7657
- yPt: xfrm.yPt,
7658
- widthPt: xfrm.widthPt,
7659
- heightPt: xfrm.heightPt
7660
- };
7661
- return {
7662
- frame: parentTransform === void 0 ? localFrame : applyGroupTransform(parentTransform, localFrame),
7663
- rotationDeg: xfrm.rotationDeg === 0 ? void 0 : xfrm.rotationDeg
7664
- };
7665
- }
7666
- function readSpShape(sp, context, slideRels, parentTransform) {
7667
- const resolved = resolveShapeFrame(sp, context, parentTransform);
7668
- if (resolved === void 0) return;
7669
- const key = readPlaceholderKey(sp);
7670
- const txBody = childrenWithTag$1(sp, "p:txBody")[0];
7671
- const blocks = textBodyParagraphs(txBody, key?.type, context, slideRels);
7672
- const extras = readShapeTextExtras(txBody);
7673
- return {
7674
- name: shapeName(sp),
7675
- frame: resolved.frame,
7676
- rotationDeg: resolved.rotationDeg,
7677
- ...extras,
7678
- blocks
7679
- };
7680
- }
7681
- function readPicShape(pic, context, slideRels, pkg, parentTransform) {
7682
- const resolved = resolveShapeFrame(pic, context, parentTransform);
7683
- if (resolved === void 0) return;
7684
- const blipFill = childrenWithTag$1(pic, "p:blipFill")[0];
7685
- const blip = blipFill === void 0 ? void 0 : childrenWithTag$1(blipFill, "a:blip")[0];
7686
- const rId = blip === void 0 ? void 0 : attr$1(blip, "r:embed");
7687
- const rel = rId === void 0 ? void 0 : slideRels.get(rId);
7688
- const mediaPart = rel === void 0 ? void 0 : pkg.parts[rel.target];
7689
- const blocks = [];
7690
- if (mediaPart?.kind === "binary") {
7691
- const format = sniffImageFormat(base64ToBytes$1(mediaPart.base64));
7692
- if (format !== void 0) {
7693
- const image = {
7694
- kind: "image",
7695
- format,
7696
- base64: mediaPart.base64,
7697
- widthPt: resolved.frame.widthPt,
7698
- heightPt: resolved.frame.heightPt
7699
- };
7700
- blocks.push(image);
7701
- }
7702
- }
7703
- return {
7704
- name: shapeName(pic),
7705
- frame: resolved.frame,
7706
- rotationDeg: resolved.rotationDeg,
7707
- ...NO_TEXT_BODY_EXTRAS,
7708
- blocks
7709
- };
7710
- }
7711
- function readTableCell(tc, context, slideRels) {
7712
- const hMerge = attr$1(tc, "hMerge");
7713
- const vMerge = attr$1(tc, "vMerge");
7714
- if (hMerge === "1" || vMerge === "1") return { blocks: [] };
7715
- const tcPr = childrenWithTag$1(tc, "a:tcPr")[0];
7716
- const background = readSolidFillColor(tcPr === void 0 ? void 0 : childrenWithTag$1(tcPr, "a:solidFill")[0], context.colorMap, context.theme);
7717
- const txBody = childrenWithTag$1(tc, "a:txBody")[0];
7718
- const gridSpan = attr$1(tc, "gridSpan");
7719
- const rowSpan = attr$1(tc, "rowSpan");
7720
- return {
7721
- blocks: textBodyParagraphs(txBody, void 0, context, slideRels),
7722
- colSpan: gridSpan === void 0 ? void 0 : Number(gridSpan),
7723
- rowSpan: rowSpan === void 0 ? void 0 : Number(rowSpan),
7724
- background
7725
- };
7726
- }
7727
- function readTable(tbl, context, slideRels) {
7728
- const tblGrid = childrenWithTag$1(tbl, "a:tblGrid")[0];
7729
- const columnWidthsPt = tblGrid === void 0 ? [] : childrenWithTag$1(tblGrid, "a:gridCol").map((col) => emuToPt(Number(attr$1(col, "w") ?? "0")));
7730
- return {
7731
- kind: "table",
7732
- rows: childrenWithTag$1(tbl, "a:tr").map((tr) => {
7733
- const h = attr$1(tr, "h");
7734
- return {
7735
- cells: childrenWithTag$1(tr, "a:tc").map((tc) => readTableCell(tc, context, slideRels)),
7736
- heightPt: h === void 0 ? void 0 : emuToPt(Number(h))
7737
- };
7738
- }),
7739
- columnWidthsPt
7740
- };
7741
- }
7742
- function readGraphicFrameShape(gf, context, slideRels, parentTransform) {
7743
- const xfrm = readXfrm(childrenWithTag$1(gf, "p:xfrm")[0]);
7744
- if (xfrm === void 0) return;
7745
- const localFrame = {
7746
- xPt: xfrm.xPt,
7747
- yPt: xfrm.yPt,
7748
- widthPt: xfrm.widthPt,
7749
- heightPt: xfrm.heightPt
7750
- };
7751
- const frame = parentTransform === void 0 ? localFrame : applyGroupTransform(parentTransform, localFrame);
7752
- const rotationDeg = xfrm.rotationDeg === 0 ? void 0 : xfrm.rotationDeg;
7753
- const graphic = childrenWithTag$1(gf, "a:graphic")[0];
7754
- const graphicData = graphic === void 0 ? void 0 : childrenWithTag$1(graphic, "a:graphicData")[0];
7755
- 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;
7756
- const blocks = tbl === void 0 ? [] : [readTable(tbl, context, slideRels)];
7757
- return {
7758
- name: shapeName(gf),
7759
- frame,
7760
- rotationDeg,
7761
- ...NO_TEXT_BODY_EXTRAS,
7762
- blocks
7763
- };
7764
- }
7765
- function walkShapeTreeChildren(children, parentTransform, context, slideRels, pkg, out) {
7766
- for (const node of children) {
7767
- if (node.type !== "element") continue;
7768
- if (node.tag === "p:sp") {
7769
- const shape = readSpShape(node, context, slideRels, parentTransform);
7770
- if (shape !== void 0) out.push(shape);
7771
- } else if (node.tag === "p:pic") {
7772
- const shape = readPicShape(node, context, slideRels, pkg, parentTransform);
7773
- if (shape !== void 0) out.push(shape);
7774
- } else if (node.tag === "p:graphicFrame") {
7775
- const shape = readGraphicFrameShape(node, context, slideRels, parentTransform);
7776
- if (shape !== void 0) out.push(shape);
7777
- } else if (node.tag === "p:grpSp") {
7778
- const grpSpPr = childrenWithTag$1(node, "p:grpSpPr")[0];
7779
- const composed = composeGroupTransform(readGroupXfrm(grpSpPr === void 0 ? void 0 : childrenWithTag$1(grpSpPr, "a:xfrm")[0]), parentTransform);
7780
- walkShapeTreeChildren(node.children, composed, context, slideRels, pkg, out);
7781
- }
7782
- }
7783
- }
7784
- function composeGroupTransform(own, parent) {
7785
- if (own === void 0) return;
7786
- if (parent === void 0) return own;
7787
- const absolute = applyGroupTransform(parent, {
7788
- xPt: own.offXPt,
7789
- yPt: own.offYPt,
7790
- widthPt: own.extWidthPt,
7791
- heightPt: own.extHeightPt
7792
- });
7793
- return {
7794
- ...own,
7795
- offXPt: absolute.xPt,
7796
- offYPt: absolute.yPt,
7797
- extWidthPt: absolute.widthPt,
7798
- extHeightPt: absolute.heightPt
7799
- };
7800
- }
7801
- const NOTES_SLIDE_REL_SUFFIX = "/notesSlide";
7802
- function readNotes(pkg, slidePath) {
7803
- let notesPath;
7804
- for (const rel of resolveRelationships$1(pkg, slidePath).values()) if (rel.type.endsWith(NOTES_SLIDE_REL_SUFFIX)) {
7805
- notesPath = rel.target;
7806
- break;
7807
- }
7808
- if (notesPath === void 0) return "";
7809
- const notesRoot = rootElement$1(pkg.parts[notesPath]);
7810
- if (notesRoot === void 0) return "";
7811
- const bodyShape = elementsWithTag$1([notesRoot], "p:sp").find((shape) => {
7812
- const key = readPlaceholderKey(shape);
7813
- return key !== void 0 && (key.type === void 0 || key.type === "body");
7814
- });
7815
- if (bodyShape !== void 0) {
7816
- const txBody = childrenWithTag$1(bodyShape, "p:txBody")[0];
7817
- if (txBody !== void 0) return elementsWithTag$1(txBody.children, "a:t").map(textContent$1).join("");
7818
- }
7819
- return elementsWithTag$1([notesRoot], "a:t").map(textContent$1).join("");
7820
- }
7821
- function readSlide(pkg, slidePath, size) {
7822
- const slideRoot = rootElement$1(pkg.parts[slidePath]);
7823
- const context = resolveSlideInheritance(pkg, slidePath);
7824
- const slideRels = resolveRelationships$1(pkg, slidePath);
7825
- const cSld = slideRoot === void 0 ? void 0 : childrenWithTag$1(slideRoot, "p:cSld")[0];
7826
- const spTree = cSld === void 0 ? void 0 : childrenWithTag$1(cSld, "p:spTree")[0];
7827
- const shapes = [];
7828
- if (spTree !== void 0) walkShapeTreeChildren(spTree.children, void 0, context, slideRels, pkg, shapes);
7829
- return {
7830
- size,
7831
- shapes,
7832
- notes: readNotes(pkg, slidePath)
7833
- };
7834
- }
7835
6634
  function readPptxContent(pkg) {
7836
- const presentationRoot = rootElement$1(pkg.parts[PRESENTATION_PATH]);
7837
- const size = readSlideSize(presentationRoot);
7838
- const slides = readSlidePathsInOrder(pkg, presentationRoot).map((slidePath) => readSlide(pkg, slidePath, size));
6635
+ const pptxDoc = readPptx(pkg);
7839
6636
  return {
7840
6637
  kind: "presentation",
7841
6638
  formatVersion: 1,
7842
- metadata: readCoreProperties(pkg),
7843
- slides
6639
+ metadata: { ...pptxDoc.metadata },
6640
+ slides: pptxDoc.slides
7844
6641
  };
7845
6642
  }
7846
6643
  //#endregion