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.cjs CHANGED
@@ -2,154 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let ooxml_js = require("ooxml.js");
3
3
  let zod = require("zod");
4
4
  let fflate = require("fflate");
5
- //#region src/model/color.ts
6
- const LayoutColorSchema = zod.z.object({
7
- r: zod.z.number().min(0).max(1),
8
- g: zod.z.number().min(0).max(1),
9
- b: zod.z.number().min(0).max(1)
10
- });
11
- const COLOR_BLACK = {
12
- r: 0,
13
- g: 0,
14
- b: 0
15
- };
16
- const HEX_COLOR_PATTERN = /^#?([0-9a-fA-F]{6})$/;
17
- const HEX_BYTE_MAX = 255;
18
- function rgbHexToColor(hex) {
19
- const match = HEX_COLOR_PATTERN.exec(hex);
20
- if (match === null) throw new Error(`not a 6-digit hex colour: ${hex}`);
21
- const digits = match[1];
22
- if (digits === void 0) throw new Error(`not a 6-digit hex colour: ${hex}`);
23
- const r = Number.parseInt(digits.slice(0, 2), 16);
24
- const g = Number.parseInt(digits.slice(2, 4), 16);
25
- const b = Number.parseInt(digits.slice(4, 6), 16);
26
- return {
27
- r: r / HEX_BYTE_MAX,
28
- g: g / HEX_BYTE_MAX,
29
- b: b / HEX_BYTE_MAX
30
- };
31
- }
32
- function toHexByte(component) {
33
- return Math.round(component * HEX_BYTE_MAX).toString(16).padStart(2, "0");
34
- }
35
- function colorToRgbHex(color) {
36
- return `${toHexByte(color.r)}${toHexByte(color.g)}${toHexByte(color.b)}`;
37
- }
38
- const OOXML_PERCENT_SCALE = 1e5;
39
- function clamp01(x) {
40
- return Math.max(0, Math.min(1, x));
41
- }
42
- function srgbToLinear(c) {
43
- return c <= .04045 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4;
44
- }
45
- function linearToSrgb(c) {
46
- return c <= .0031308 ? c * 12.92 : 1.055 * c ** (1 / 2.4) - .055;
47
- }
48
- function applyShadeOrTint(color, kind, value) {
49
- const pct = value / OOXML_PERCENT_SCALE;
50
- const transform = kind === "shade" ? (linear) => linear * pct : (linear) => 1 - (1 - linear) * pct;
51
- return {
52
- r: clamp01(linearToSrgb(transform(srgbToLinear(color.r)))),
53
- g: clamp01(linearToSrgb(transform(srgbToLinear(color.g)))),
54
- b: clamp01(linearToSrgb(transform(srgbToLinear(color.b))))
55
- };
56
- }
57
- function rgbToHsl(color) {
58
- const { r, g, b } = color;
59
- const max = Math.max(r, g, b);
60
- const min = Math.min(r, g, b);
61
- const l = (max + min) / 2;
62
- if (max === min) return {
63
- h: 0,
64
- s: 0,
65
- l
66
- };
67
- const d = max - min;
68
- const s = l > .5 ? d / (2 - max - min) : d / (max + min);
69
- let h;
70
- if (max === r) h = (g - b) / d + (g < b ? 6 : 0);
71
- else if (max === g) h = (b - r) / d + 2;
72
- else h = (r - g) / d + 4;
73
- return {
74
- h: h * 60,
75
- s,
76
- l
77
- };
78
- }
79
- function hueToRgbComponent(p, q, hue) {
80
- let t = hue;
81
- if (t < 0) t += 1;
82
- if (t > 1) t -= 1;
83
- if (t < 1 / 6) return p + (q - p) * 6 * t;
84
- if (t < 1 / 2) return q;
85
- if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
86
- return p;
87
- }
88
- function hslToRgb(hsl) {
89
- const { h, s, l } = hsl;
90
- if (s === 0) return {
91
- r: l,
92
- g: l,
93
- b: l
94
- };
95
- const q = l < .5 ? l * (1 + s) : l + s - l * s;
96
- const p = 2 * l - q;
97
- const hk = h / 360;
98
- return {
99
- r: clamp01(hueToRgbComponent(p, q, hk + 1 / 3)),
100
- g: clamp01(hueToRgbComponent(p, q, hk)),
101
- b: clamp01(hueToRgbComponent(p, q, hk - 1 / 3))
102
- };
103
- }
104
- function applyLumModOrOff(color, kind, value) {
105
- const hsl = rgbToHsl(color);
106
- const pct = value / OOXML_PERCENT_SCALE;
107
- const l = clamp01(kind === "lumMod" ? hsl.l * pct : hsl.l + pct);
108
- return hslToRgb({
109
- ...hsl,
110
- l
111
- });
112
- }
113
- function applyColorTransforms(base, transforms) {
114
- let color = base;
115
- for (const t of transforms) if (t.kind === "shade" || t.kind === "tint") color = applyShadeOrTint(color, t.kind, t.value);
116
- for (const t of transforms) if (t.kind === "lumMod" || t.kind === "lumOff") color = applyLumModOrOff(color, t.kind, t.value);
117
- return color;
118
- }
119
- //#endregion
120
5
  //#region src/model/geometry.ts
121
- const BoxSchema = zod.z.object({
122
- xPt: zod.z.number(),
123
- yPt: zod.z.number(),
124
- widthPt: zod.z.number().nonnegative(),
125
- heightPt: zod.z.number().nonnegative()
126
- });
127
- const PageSizeSchema = zod.z.object({
128
- widthPt: zod.z.number().positive(),
129
- heightPt: zod.z.number().positive()
130
- });
131
- const MarginsSchema = zod.z.object({
132
- topPt: zod.z.number().nonnegative(),
133
- rightPt: zod.z.number().nonnegative(),
134
- bottomPt: zod.z.number().nonnegative(),
135
- leftPt: zod.z.number().nonnegative()
136
- });
137
- const PAGE_SIZE_LETTER = {
138
- widthPt: 612,
139
- heightPt: 792
140
- };
141
- const PAGE_SIZE_A4 = {
142
- widthPt: 595.28,
143
- heightPt: 841.89
144
- };
145
- const SLIDE_SIZE_WIDESCREEN = {
146
- widthPt: 960,
147
- heightPt: 540
148
- };
149
- const SLIDE_SIZE_STANDARD = {
150
- widthPt: 720,
151
- heightPt: 540
152
- };
153
6
  function flipY(box, containerHeightPt) {
154
7
  return {
155
8
  xPt: box.xPt,
@@ -170,12 +23,6 @@ const DEFAULT_LAYOUT_FONT = {
170
23
  weight: "normal",
171
24
  style: "normal"
172
25
  };
173
- const AlignmentSchema = zod.z.enum([
174
- "left",
175
- "center",
176
- "right",
177
- "justify"
178
- ]);
179
26
  //#endregion
180
27
  //#region src/model/layout.ts
181
28
  const LAYOUT_FORMAT_VERSION = 1;
@@ -186,7 +33,7 @@ const LayoutTextSchema = zod.z.object({
186
33
  yPt: zod.z.number(),
187
34
  font: LayoutFontSchema,
188
35
  sizePt: zod.z.number().positive(),
189
- color: LayoutColorSchema,
36
+ color: ooxml_js.ColorSchema,
190
37
  widthPt: zod.z.number().nonnegative().optional(),
191
38
  rotationDeg: zod.z.number().optional(),
192
39
  underline: zod.z.boolean().optional()
@@ -206,9 +53,9 @@ const LayoutRectSchema = zod.z.object({
206
53
  yPt: zod.z.number(),
207
54
  widthPt: zod.z.number().nonnegative(),
208
55
  heightPt: zod.z.number().nonnegative(),
209
- fill: LayoutColorSchema.optional(),
56
+ fill: ooxml_js.ColorSchema.optional(),
210
57
  stroke: zod.z.object({
211
- color: LayoutColorSchema,
58
+ color: ooxml_js.ColorSchema,
212
59
  widthPt: zod.z.number().positive()
213
60
  }).optional()
214
61
  });
@@ -218,7 +65,7 @@ const LayoutLineSchema = zod.z.object({
218
65
  y1Pt: zod.z.number(),
219
66
  x2Pt: zod.z.number(),
220
67
  y2Pt: zod.z.number(),
221
- color: LayoutColorSchema,
68
+ color: ooxml_js.ColorSchema,
222
69
  widthPt: zod.z.number().positive()
223
70
  });
224
71
  const LayoutEllipseSchema = zod.z.object({
@@ -227,9 +74,9 @@ const LayoutEllipseSchema = zod.z.object({
227
74
  yPt: zod.z.number(),
228
75
  widthPt: zod.z.number().positive(),
229
76
  heightPt: zod.z.number().positive(),
230
- fill: LayoutColorSchema.optional(),
77
+ fill: ooxml_js.ColorSchema.optional(),
231
78
  stroke: zod.z.object({
232
- color: LayoutColorSchema,
79
+ color: ooxml_js.ColorSchema,
233
80
  widthPt: zod.z.number().positive()
234
81
  }).optional()
235
82
  });
@@ -287,7 +134,7 @@ const ContentRunSchema = zod.z.object({
287
134
  strike: zod.z.boolean().optional(),
288
135
  fontFamily: zod.z.string().optional(),
289
136
  sizePt: zod.z.number().positive().optional(),
290
- color: LayoutColorSchema.optional(),
137
+ color: ooxml_js.ColorSchema.optional(),
291
138
  hyperlink: zod.z.string().optional()
292
139
  });
293
140
  const ContentListMembershipSchema = zod.z.object({
@@ -298,7 +145,7 @@ const ContentParagraphSchema = zod.z.object({
298
145
  kind: zod.z.literal("paragraph"),
299
146
  runs: zod.z.array(ContentRunSchema),
300
147
  styleId: zod.z.string().optional(),
301
- alignment: AlignmentSchema.optional(),
148
+ alignment: ooxml_js.AlignmentSchema.optional(),
302
149
  list: ContentListMembershipSchema.optional(),
303
150
  spacingBeforePt: zod.z.number().optional(),
304
151
  spacingAfterPt: zod.z.number().optional(),
@@ -341,7 +188,7 @@ const ContentTableCellSchema = zod.z.object({
341
188
  blocks: zod.z.array(ContentBlockSchema),
342
189
  colSpan: zod.z.number().int().positive().optional(),
343
190
  rowSpan: zod.z.number().int().positive().optional(),
344
- background: LayoutColorSchema.optional()
191
+ background: ooxml_js.ColorSchema.optional()
345
192
  });
346
193
  const ContentTableRowSchema = zod.z.object({
347
194
  cells: zod.z.array(ContentTableCellSchema),
@@ -353,13 +200,13 @@ const ContentTableSchema = zod.z.object({
353
200
  columnWidthsPt: zod.z.array(zod.z.number().positive())
354
201
  });
355
202
  const ContentSectionSchema = zod.z.object({
356
- pageSize: PageSizeSchema,
357
- margins: MarginsSchema,
203
+ pageSize: ooxml_js.PageSizeSchema,
204
+ margins: ooxml_js.MarginsSchema,
358
205
  blocks: zod.z.array(ContentBlockSchema)
359
206
  });
360
207
  const ContentShapeSchema = zod.z.object({
361
208
  name: zod.z.string().optional(),
362
- frame: BoxSchema,
209
+ frame: ooxml_js.BoxSchema,
363
210
  rotationDeg: zod.z.number().optional(),
364
211
  insetLeftPt: zod.z.number().nonnegative(),
365
212
  insetTopPt: zod.z.number().nonnegative(),
@@ -370,7 +217,7 @@ const ContentShapeSchema = zod.z.object({
370
217
  blocks: zod.z.array(ContentBlockSchema)
371
218
  });
372
219
  const ContentSlideSchema = zod.z.object({
373
- size: PageSizeSchema,
220
+ size: ooxml_js.PageSizeSchema,
374
221
  shapes: zod.z.array(ContentShapeSchema),
375
222
  notes: zod.z.string()
376
223
  });
@@ -502,9 +349,6 @@ function emuToPt(emu) {
502
349
  function ptToEmu(pt) {
503
350
  return Math.round(pt * EMU_PER_POINT);
504
351
  }
505
- function twipsToPt(twips) {
506
- return twips / 20;
507
- }
508
352
  function ptToTwips(pt) {
509
353
  return Math.round(pt * 20);
510
354
  }
@@ -514,12 +358,6 @@ function halfPointsToPt(halfPoints) {
514
358
  function ptToHalfPoints(pt) {
515
359
  return Math.round(pt * 2);
516
360
  }
517
- function drawingMlFontSizeToPt(hundredths) {
518
- return hundredths / 100;
519
- }
520
- function lineUnitsToMultiplier(lineUnits) {
521
- return lineUnits / 240;
522
- }
523
361
  //#endregion
524
362
  //#region src/opc/paths.ts
525
363
  function relsPathFor(partPath) {
@@ -814,10 +652,10 @@ function getColor(rPr) {
814
652
  if (color === void 0) return;
815
653
  const val = (0, ooxml_js.attr)(color, "w:val");
816
654
  if (val === void 0 || val.toLowerCase() === "auto") return;
817
- return rgbHexToColor(val);
655
+ return (0, ooxml_js.rgbHexToColor)(val);
818
656
  }
819
657
  function setColor(rPr, color) {
820
- setAttr(getOrCreateChildElement(rPr, "w:color", RPR_ORDER, () => el("w:color")), "w:val", colorToRgbHex(color));
658
+ setAttr(getOrCreateChildElement(rPr, "w:color", RPR_ORDER, () => el("w:color")), "w:val", (0, ooxml_js.colorToRgbHex)(color));
821
659
  }
822
660
  function getStyleId(propsElement, tag) {
823
661
  if (propsElement === void 0) return;
@@ -970,7 +808,7 @@ function buildRun(init = {}) {
970
808
  const half = String(Math.round(init.sizePt * 2));
971
809
  rPrChildren.push(el("w:sz", { "w:val": half }), el("w:szCs", { "w:val": half }));
972
810
  }
973
- if (init.color !== void 0) rPrChildren.push(el("w:color", { "w:val": colorToRgbHex(init.color) }));
811
+ if (init.color !== void 0) rPrChildren.push(el("w:color", { "w:val": (0, ooxml_js.colorToRgbHex)(init.color) }));
974
812
  const run = el("w:r");
975
813
  if (rPrChildren.length > 0 || init.underline === true) {
976
814
  const rPr = el("w:rPr");
@@ -1292,16 +1130,16 @@ function buildTable(init) {
1292
1130
  }
1293
1131
  //#endregion
1294
1132
  //#region src/edit/docx/editor.ts
1295
- const DOCUMENT_PART_PATH$1 = "word/document.xml";
1133
+ const DOCUMENT_PART_PATH = "word/document.xml";
1296
1134
  const MEDIA_DIR$1 = "word/media";
1297
1135
  function findDocumentRoot(pkg) {
1298
- const root = (0, ooxml_js.rootElement)(pkg.parts[DOCUMENT_PART_PATH$1]);
1299
- if (root === void 0) throw new Error(`package has no root element at ${DOCUMENT_PART_PATH$1}`);
1136
+ const root = (0, ooxml_js.rootElement)(pkg.parts[DOCUMENT_PART_PATH]);
1137
+ if (root === void 0) throw new Error(`package has no root element at ${DOCUMENT_PART_PATH}`);
1300
1138
  return root;
1301
1139
  }
1302
1140
  function findBody(documentRoot) {
1303
1141
  for (const child of documentRoot.children) if (child.type === "element" && child.tag === "w:body") return child;
1304
- throw new Error(`${DOCUMENT_PART_PATH$1} has no w:body element`);
1142
+ throw new Error(`${DOCUMENT_PART_PATH} has no w:body element`);
1305
1143
  }
1306
1144
  function bodyInsertionPoint(body) {
1307
1145
  const sectPrIndex = body.children.findIndex((c) => c.type === "element" && c.tag === "w:sectPr");
@@ -1355,7 +1193,7 @@ var DocxEditor = class {
1355
1193
  documentRoot,
1356
1194
  media: {
1357
1195
  pkg,
1358
- partPath: DOCUMENT_PART_PATH$1,
1196
+ partPath: DOCUMENT_PART_PATH,
1359
1197
  mediaDir: MEDIA_DIR$1
1360
1198
  }
1361
1199
  };
@@ -1369,7 +1207,7 @@ var DocxEditor = class {
1369
1207
  documentRoot,
1370
1208
  media: {
1371
1209
  pkg: this.pkg,
1372
- partPath: DOCUMENT_PART_PATH$1,
1210
+ partPath: DOCUMENT_PART_PATH,
1373
1211
  mediaDir: MEDIA_DIR$1
1374
1212
  }
1375
1213
  };
@@ -4773,7 +4611,7 @@ function createFontResolver(context) {
4773
4611
  }
4774
4612
  //#endregion
4775
4613
  //#region src/image/png-encode.ts
4776
- const PNG_SIGNATURE$2 = new Uint8Array([
4614
+ const PNG_SIGNATURE$1 = new Uint8Array([
4777
4615
  137,
4778
4616
  80,
4779
4617
  78,
@@ -4822,7 +4660,7 @@ function encodePng(image, options = {}) {
4822
4660
  ihdr[11] = 0;
4823
4661
  ihdr[12] = 0;
4824
4662
  const writer = new ByteWriter();
4825
- writer.writeBytes(PNG_SIGNATURE$2);
4663
+ writer.writeBytes(PNG_SIGNATURE$1);
4826
4664
  writeChunk(writer, "IHDR", ihdr);
4827
4665
  writeChunk(writer, "IDAT", compressed);
4828
4666
  writeChunk(writer, "IEND", /* @__PURE__ */ new Uint8Array(0));
@@ -5437,8 +5275,8 @@ function interpretContentStream(bytes, resources, context) {
5437
5275
  const items = [];
5438
5276
  runContentStream(bytes, resources, {
5439
5277
  ctm: IDENTITY_MATRIX,
5440
- fillColor: COLOR_BLACK,
5441
- strokeColor: COLOR_BLACK
5278
+ fillColor: ooxml_js.COLOR_BLACK,
5279
+ strokeColor: ooxml_js.COLOR_BLACK
5442
5280
  }, context, items, 0);
5443
5281
  return items;
5444
5282
  }
@@ -6055,7 +5893,7 @@ function readMetadata(trailer, resolver) {
6055
5893
  }
6056
5894
  //#endregion
6057
5895
  //#region src/image/png-decode.ts
6058
- const PNG_SIGNATURE$1 = [
5896
+ const PNG_SIGNATURE = [
6059
5897
  137,
6060
5898
  80,
6061
5899
  78,
@@ -6071,7 +5909,7 @@ function requireDataView(bytes) {
6071
5909
  function readChunks(bytes, onWarning) {
6072
5910
  const chunks = [];
6073
5911
  const view = requireDataView(bytes);
6074
- let offset = PNG_SIGNATURE$1.length;
5912
+ let offset = PNG_SIGNATURE.length;
6075
5913
  while (offset + 8 <= bytes.length) {
6076
5914
  const length = view.getUint32(offset);
6077
5915
  const typeBytes = bytes.subarray(offset + 4, offset + 8);
@@ -6146,7 +5984,7 @@ function scaleToByte(sample, bitDepth) {
6146
5984
  return Math.round(sample * 255 / maxSample);
6147
5985
  }
6148
5986
  function decodePng(bytes, options = {}) {
6149
- 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");
5987
+ 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");
6150
5988
  const chunks = readChunks(bytes, options.onWarning);
6151
5989
  const ihdrChunk = chunks[0];
6152
5990
  if (ihdrChunk?.type !== "IHDR") throw new Error("PNG file does not begin with an IHDR chunk");
@@ -6782,1066 +6620,25 @@ const pdfCodec = zod.z.codec(PdfBytesSchema, LayoutDocumentSchema, {
6782
6620
  encode: (doc) => writePdf(doc)
6783
6621
  });
6784
6622
  //#endregion
6785
- //#region src/ooxml/core-properties.ts
6786
- const CORE_PROPERTIES_PATH = "docProps/core.xml";
6787
- const APP_PROPERTIES_PATH = "docProps/app.xml";
6788
- function firstElementText(root, tag) {
6789
- if (root === void 0) return;
6790
- const element = (0, ooxml_js.childrenWithTag)(root, tag)[0];
6791
- if (element === void 0) return;
6792
- const text = (0, ooxml_js.textContent)(element);
6793
- return text.length > 0 ? text : void 0;
6794
- }
6795
- function readKeywords(core) {
6796
- const raw = firstElementText(core, "cp:keywords");
6797
- if (raw === void 0) return;
6798
- const parts = raw.split(",").map((part) => part.trim()).filter((part) => part.length > 0);
6799
- return parts.length > 0 ? parts : void 0;
6800
- }
6801
- function readCoreProperties(pkg) {
6802
- const core = (0, ooxml_js.rootElement)(pkg.parts[CORE_PROPERTIES_PATH]);
6803
- const app = (0, ooxml_js.rootElement)(pkg.parts[APP_PROPERTIES_PATH]);
6804
- return {
6805
- title: firstElementText(core, "dc:title"),
6806
- author: firstElementText(core, "dc:creator"),
6807
- subject: firstElementText(core, "dc:subject"),
6808
- keywords: readKeywords(core),
6809
- creator: firstElementText(app, "Application"),
6810
- createdIso: firstElementText(core, "dcterms:created"),
6811
- modifiedIso: firstElementText(core, "dcterms:modified")
6812
- };
6813
- }
6814
- //#endregion
6815
- //#region src/ooxml/drawingml.ts
6816
- const ROTATION_UNITS_PER_DEGREE = 6e4;
6817
- function readXfrm(xfrm) {
6818
- if (xfrm === void 0) return;
6819
- const off = (0, ooxml_js.childrenWithTag)(xfrm, "a:off")[0];
6820
- const ext = (0, ooxml_js.childrenWithTag)(xfrm, "a:ext")[0];
6821
- if (off === void 0 || ext === void 0) return;
6822
- const x = (0, ooxml_js.attr)(off, "x");
6823
- const y = (0, ooxml_js.attr)(off, "y");
6824
- const cx = (0, ooxml_js.attr)(ext, "cx");
6825
- const cy = (0, ooxml_js.attr)(ext, "cy");
6826
- if (x === void 0 || y === void 0 || cx === void 0 || cy === void 0) return;
6827
- const rot = (0, ooxml_js.attr)(xfrm, "rot");
6828
- return {
6829
- xPt: emuToPt(Number(x)),
6830
- yPt: emuToPt(Number(y)),
6831
- widthPt: emuToPt(Number(cx)),
6832
- heightPt: emuToPt(Number(cy)),
6833
- rotationDeg: rot === void 0 ? 0 : Number(rot) / ROTATION_UNITS_PER_DEGREE,
6834
- flipH: (0, ooxml_js.attr)(xfrm, "flipH") === "1",
6835
- flipV: (0, ooxml_js.attr)(xfrm, "flipV") === "1"
6836
- };
6837
- }
6838
- const CLR_SCHEME_SLOTS = [
6839
- "dk1",
6840
- "lt1",
6841
- "dk2",
6842
- "lt2",
6843
- "accent1",
6844
- "accent2",
6845
- "accent3",
6846
- "accent4",
6847
- "accent5",
6848
- "accent6",
6849
- "hlink",
6850
- "folHlink"
6851
- ];
6852
- function readThemeSlotColor(colorEl) {
6853
- if (colorEl.tag === "a:srgbClr") {
6854
- const val = (0, ooxml_js.attr)(colorEl, "val");
6855
- return val === void 0 ? void 0 : rgbHexToColor(val);
6856
- }
6857
- if (colorEl.tag === "a:sysClr") {
6858
- const lastClr = (0, ooxml_js.attr)(colorEl, "lastClr");
6859
- if (lastClr !== void 0) return rgbHexToColor(lastClr);
6860
- return (0, ooxml_js.attr)(colorEl, "val") === "window" ? {
6861
- r: 1,
6862
- g: 1,
6863
- b: 1
6864
- } : {
6865
- r: 0,
6866
- g: 0,
6867
- b: 0
6868
- };
6869
- }
6870
- }
6871
- function readClrScheme(clrSchemeEl) {
6872
- const map = /* @__PURE__ */ new Map();
6873
- for (const slot of CLR_SCHEME_SLOTS) {
6874
- const wrapper = (0, ooxml_js.childrenWithTag)(clrSchemeEl, `a:${slot}`)[0];
6875
- if (wrapper === void 0) continue;
6876
- const colorEl = wrapper.children.find((c) => c.type === "element");
6877
- if (colorEl === void 0) continue;
6878
- const color = readThemeSlotColor(colorEl);
6879
- if (color !== void 0) map.set(slot, color);
6880
- }
6881
- return map;
6882
- }
6883
- function readSchemeFont(fontSchemeEl, tag) {
6884
- if (fontSchemeEl === void 0) return;
6885
- const fontEl = (0, ooxml_js.childrenWithTag)(fontSchemeEl, tag)[0];
6886
- const latin = fontEl === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(fontEl, "a:latin")[0];
6887
- return latin === void 0 ? void 0 : (0, ooxml_js.attr)(latin, "typeface");
6888
- }
6889
- const DEFAULT_THEME_FONT = "Calibri";
6890
- const EMPTY_THEME = {
6891
- colorScheme: /* @__PURE__ */ new Map(),
6892
- majorFont: DEFAULT_THEME_FONT,
6893
- minorFont: DEFAULT_THEME_FONT
6894
- };
6895
- function readTheme(themeRoot) {
6896
- const clrSchemeEl = (0, ooxml_js.elementsWithTag)([themeRoot], "a:clrScheme")[0];
6897
- const colorScheme = clrSchemeEl === void 0 ? /* @__PURE__ */ new Map() : readClrScheme(clrSchemeEl);
6898
- const fontSchemeEl = (0, ooxml_js.elementsWithTag)([themeRoot], "a:fontScheme")[0];
6899
- return {
6900
- colorScheme,
6901
- majorFont: readSchemeFont(fontSchemeEl, "a:majorFont") ?? DEFAULT_THEME_FONT,
6902
- minorFont: readSchemeFont(fontSchemeEl, "a:minorFont") ?? DEFAULT_THEME_FONT
6903
- };
6904
- }
6905
- function resolveThemeFontReference(typeface, theme) {
6906
- if (typeface === "+mj-lt") return theme.majorFont;
6907
- if (typeface === "+mn-lt") return theme.minorFont;
6908
- return typeface;
6909
- }
6910
- function readColorMap(clrMapEl) {
6911
- const map = /* @__PURE__ */ new Map();
6912
- if (clrMapEl === void 0) return map;
6913
- for (const a of clrMapEl.attributes) map.set(a.name, a.value);
6914
- return map;
6915
- }
6916
- function resolveSchemeColorSlot(schemeVal, colorMap) {
6917
- return colorMap.get(schemeVal) ?? schemeVal;
6918
- }
6919
- const COLOR_TRANSFORM_TAGS = /* @__PURE__ */ new Map([
6920
- ["a:shade", "shade"],
6921
- ["a:tint", "tint"],
6922
- ["a:lumMod", "lumMod"],
6923
- ["a:lumOff", "lumOff"]
6924
- ]);
6925
- function readColorTransforms(container) {
6926
- const transforms = [];
6927
- for (const child of container.children) {
6928
- if (child.type !== "element") continue;
6929
- const kind = COLOR_TRANSFORM_TAGS.get(child.tag);
6930
- if (kind === void 0) continue;
6931
- const val = (0, ooxml_js.attr)(child, "val");
6932
- if (val === void 0) continue;
6933
- transforms.push({
6934
- kind,
6935
- value: Number(val)
6936
- });
6937
- }
6938
- return transforms;
6939
- }
6940
- function readSchemeColor(schemeClrEl, colorMap, theme) {
6941
- const val = (0, ooxml_js.attr)(schemeClrEl, "val");
6942
- if (val === void 0) return;
6943
- const base = theme.colorScheme.get(resolveSchemeColorSlot(val, colorMap));
6944
- return base === void 0 ? void 0 : applyColorTransforms(base, readColorTransforms(schemeClrEl));
6945
- }
6946
- function readSrgbColor(srgbClrEl) {
6947
- const val = (0, ooxml_js.attr)(srgbClrEl, "val");
6948
- return val === void 0 ? void 0 : applyColorTransforms(rgbHexToColor(val), readColorTransforms(srgbClrEl));
6949
- }
6950
- function readSolidFillColor(solidFillEl, colorMap, theme) {
6951
- if (solidFillEl === void 0) return;
6952
- const schemeClr = (0, ooxml_js.childrenWithTag)(solidFillEl, "a:schemeClr")[0];
6953
- if (schemeClr !== void 0) return readSchemeColor(schemeClr, colorMap, theme);
6954
- const srgbClr = (0, ooxml_js.childrenWithTag)(solidFillEl, "a:srgbClr")[0];
6955
- return srgbClr === void 0 ? void 0 : readSrgbColor(srgbClr);
6956
- }
6957
- function readGroupXfrm(xfrm) {
6958
- const base = readXfrm(xfrm);
6959
- if (base === void 0 || xfrm === void 0) return;
6960
- const chOff = (0, ooxml_js.childrenWithTag)(xfrm, "a:chOff")[0];
6961
- const chExt = (0, ooxml_js.childrenWithTag)(xfrm, "a:chExt")[0];
6962
- if (chOff === void 0 || chExt === void 0) return;
6963
- const cx = (0, ooxml_js.attr)(chOff, "x");
6964
- const cy = (0, ooxml_js.attr)(chOff, "y");
6965
- const ccx = (0, ooxml_js.attr)(chExt, "cx");
6966
- const ccy = (0, ooxml_js.attr)(chExt, "cy");
6967
- if (cx === void 0 || cy === void 0 || ccx === void 0 || ccy === void 0) return;
6968
- return {
6969
- offXPt: base.xPt,
6970
- offYPt: base.yPt,
6971
- extWidthPt: base.widthPt,
6972
- extHeightPt: base.heightPt,
6973
- childOffXPt: emuToPt(Number(cx)),
6974
- childOffYPt: emuToPt(Number(cy)),
6975
- childExtWidthPt: emuToPt(Number(ccx)),
6976
- childExtHeightPt: emuToPt(Number(ccy))
6977
- };
6978
- }
6979
- function applyGroupTransform(group, childFrame) {
6980
- const scaleX = group.childExtWidthPt === 0 ? 1 : group.extWidthPt / group.childExtWidthPt;
6981
- const scaleY = group.childExtHeightPt === 0 ? 1 : group.extHeightPt / group.childExtHeightPt;
6982
- return {
6983
- xPt: group.offXPt + (childFrame.xPt - group.childOffXPt) * scaleX,
6984
- yPt: group.offYPt + (childFrame.yPt - group.childOffYPt) * scaleY,
6985
- widthPt: childFrame.widthPt * scaleX,
6986
- heightPt: childFrame.heightPt * scaleY
6987
- };
6988
- }
6989
- //#endregion
6990
- //#region src/ooxml/docx/styles.ts
6991
- function mergeParagraphLayer(base, layer) {
6992
- return {
6993
- alignment: layer.alignment ?? base.alignment,
6994
- spacingBeforePt: layer.spacingBeforePt ?? base.spacingBeforePt,
6995
- spacingAfterPt: layer.spacingAfterPt ?? base.spacingAfterPt,
6996
- lineSpacing: layer.lineSpacing ?? base.lineSpacing,
6997
- indentLeftPt: layer.indentLeftPt ?? base.indentLeftPt,
6998
- indentFirstLinePt: layer.indentFirstLinePt ?? base.indentFirstLinePt
6999
- };
7000
- }
7001
- function mergeRunLayer(base, layer) {
7002
- return {
7003
- bold: layer.bold ?? base.bold,
7004
- italic: layer.italic ?? base.italic,
7005
- underline: layer.underline ?? base.underline,
7006
- strike: layer.strike ?? base.strike,
7007
- fontFamily: layer.fontFamily ?? base.fontFamily,
7008
- sizePt: layer.sizePt ?? base.sizePt,
7009
- color: layer.color ?? base.color
7010
- };
7011
- }
7012
- function readToggle$1(el) {
7013
- if (el === void 0) return;
7014
- const val = (0, ooxml_js.attr)(el, "w:val");
7015
- return val === void 0 || val !== "0" && val !== "false" && val !== "off";
7016
- }
7017
- function readUnderline(u) {
7018
- if (u === void 0) return;
7019
- const val = (0, ooxml_js.attr)(u, "w:val");
7020
- return val !== void 0 && val !== "none";
7021
- }
7022
- function readRunColor(colorEl) {
7023
- if (colorEl === void 0) return;
7024
- const val = (0, ooxml_js.attr)(colorEl, "w:val");
7025
- return val === void 0 || val === "auto" ? void 0 : rgbHexToColor(val);
7026
- }
7027
- function readRunFontFamily(rFonts, theme) {
7028
- if (rFonts === void 0) return;
7029
- const ascii = (0, ooxml_js.attr)(rFonts, "w:ascii");
7030
- if (ascii !== void 0) return ascii;
7031
- const asciiTheme = (0, ooxml_js.attr)(rFonts, "w:asciiTheme");
7032
- if (asciiTheme === "majorHAnsi" || asciiTheme === "majorAscii") return theme.majorFont;
7033
- if (asciiTheme === "minorHAnsi" || asciiTheme === "minorAscii") return theme.minorFont;
7034
- }
7035
- function readRunPropertiesLayer(rPr, theme) {
7036
- if (rPr === void 0) return {};
7037
- const sz = (0, ooxml_js.childrenWithTag)(rPr, "w:sz")[0];
7038
- const szVal = sz === void 0 ? void 0 : (0, ooxml_js.attr)(sz, "w:val");
7039
- return {
7040
- bold: readToggle$1((0, ooxml_js.childrenWithTag)(rPr, "w:b")[0]),
7041
- italic: readToggle$1((0, ooxml_js.childrenWithTag)(rPr, "w:i")[0]),
7042
- underline: readUnderline((0, ooxml_js.childrenWithTag)(rPr, "w:u")[0]),
7043
- strike: readToggle$1((0, ooxml_js.childrenWithTag)(rPr, "w:strike")[0]),
7044
- fontFamily: readRunFontFamily((0, ooxml_js.childrenWithTag)(rPr, "w:rFonts")[0], theme),
7045
- sizePt: szVal === void 0 ? void 0 : halfPointsToPt(Number(szVal)),
7046
- color: readRunColor((0, ooxml_js.childrenWithTag)(rPr, "w:color")[0])
7047
- };
7048
- }
7049
- function readAlignment$1(jc) {
7050
- const val = jc === void 0 ? void 0 : (0, ooxml_js.attr)(jc, "w:val");
7051
- if (val === "left" || val === "start") return "left";
7052
- if (val === "center") return "center";
7053
- if (val === "right" || val === "end") return "right";
7054
- if (val === "both" || val === "distribute") return "justify";
7055
- }
7056
- function readParagraphPropertiesLayer(pPr) {
7057
- if (pPr === void 0) return {};
7058
- const spacing = (0, ooxml_js.childrenWithTag)(pPr, "w:spacing")[0];
7059
- const before = spacing === void 0 ? void 0 : (0, ooxml_js.attr)(spacing, "w:before");
7060
- const after = spacing === void 0 ? void 0 : (0, ooxml_js.attr)(spacing, "w:after");
7061
- const line = spacing === void 0 ? void 0 : (0, ooxml_js.attr)(spacing, "w:line");
7062
- const lineRule = spacing === void 0 ? void 0 : (0, ooxml_js.attr)(spacing, "w:lineRule");
7063
- const ind = (0, ooxml_js.childrenWithTag)(pPr, "w:ind")[0];
7064
- const left = ind === void 0 ? void 0 : (0, ooxml_js.attr)(ind, "w:left") ?? (0, ooxml_js.attr)(ind, "w:start");
7065
- const firstLine = ind === void 0 ? void 0 : (0, ooxml_js.attr)(ind, "w:firstLine");
7066
- const hanging = ind === void 0 ? void 0 : (0, ooxml_js.attr)(ind, "w:hanging");
7067
- return {
7068
- alignment: readAlignment$1((0, ooxml_js.childrenWithTag)(pPr, "w:jc")[0]),
7069
- spacingBeforePt: before === void 0 ? void 0 : twipsToPt(Number(before)),
7070
- spacingAfterPt: after === void 0 ? void 0 : twipsToPt(Number(after)),
7071
- lineSpacing: line === void 0 || lineRule === "exact" || lineRule === "atLeast" ? void 0 : lineUnitsToMultiplier(Number(line)),
7072
- indentLeftPt: left === void 0 ? void 0 : twipsToPt(Number(left)),
7073
- indentFirstLinePt: firstLine !== void 0 ? twipsToPt(Number(firstLine)) : hanging !== void 0 ? -twipsToPt(Number(hanging)) : void 0
7074
- };
7075
- }
7076
- function findStyle(stylesRoot, styleId, type) {
7077
- return (0, ooxml_js.elementsWithTag)([stylesRoot], "w:style").find((s) => (0, ooxml_js.attr)(s, "w:type") === type && (0, ooxml_js.attr)(s, "w:styleId") === styleId);
7078
- }
7079
- function findDefaultStyle(stylesRoot, type) {
7080
- return (0, ooxml_js.elementsWithTag)([stylesRoot], "w:style").find((s) => (0, ooxml_js.attr)(s, "w:type") === type && (0, ooxml_js.attr)(s, "w:default") === "1");
7081
- }
7082
- function resolveBasedOnChain(stylesRoot, styleId, type) {
7083
- const chain = [];
7084
- const visited = /* @__PURE__ */ new Set();
7085
- let currentId = styleId;
7086
- while (currentId !== void 0 && !visited.has(currentId)) {
7087
- visited.add(currentId);
7088
- const style = findStyle(stylesRoot, currentId, type);
7089
- if (style === void 0) break;
7090
- chain.unshift(style);
7091
- const basedOn = (0, ooxml_js.childrenWithTag)(style, "w:basedOn")[0];
7092
- currentId = basedOn === void 0 ? void 0 : (0, ooxml_js.attr)(basedOn, "w:val");
7093
- }
7094
- return chain;
7095
- }
7096
- function docDefaultsElement(stylesRoot, wrapperTag, innerTag) {
7097
- const docDefaults = stylesRoot === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(stylesRoot, "w:docDefaults")[0];
7098
- const wrapper = docDefaults === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(docDefaults, wrapperTag)[0];
7099
- return wrapper === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(wrapper, innerTag)[0];
7100
- }
7101
- function resolveParagraphProperties(paragraph, context) {
7102
- const pPr = (0, ooxml_js.childrenWithTag)(paragraph, "w:pPr")[0];
7103
- const pStyleEl = pPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(pPr, "w:pStyle")[0];
7104
- const styleId = pStyleEl === void 0 ? void 0 : (0, ooxml_js.attr)(pStyleEl, "w:val");
7105
- let resolved = readParagraphPropertiesLayer(docDefaultsElement(context.stylesRoot, "w:pPrDefault", "w:pPr"));
7106
- if (context.stylesRoot !== void 0) {
7107
- const defaultStyle = findDefaultStyle(context.stylesRoot, "paragraph");
7108
- if (defaultStyle !== void 0) resolved = mergeParagraphLayer(resolved, readParagraphPropertiesLayer((0, ooxml_js.childrenWithTag)(defaultStyle, "w:pPr")[0]));
7109
- if (styleId !== void 0) for (const style of resolveBasedOnChain(context.stylesRoot, styleId, "paragraph")) resolved = mergeParagraphLayer(resolved, readParagraphPropertiesLayer((0, ooxml_js.childrenWithTag)(style, "w:pPr")[0]));
7110
- }
7111
- return mergeParagraphLayer(resolved, readParagraphPropertiesLayer(pPr));
7112
- }
7113
- function resolveRunProperties(run, paragraph, context) {
7114
- const pPr = (0, ooxml_js.childrenWithTag)(paragraph, "w:pPr")[0];
7115
- const pStyleEl = pPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(pPr, "w:pStyle")[0];
7116
- const pStyleId = pStyleEl === void 0 ? void 0 : (0, ooxml_js.attr)(pStyleEl, "w:val");
7117
- let resolved = readRunPropertiesLayer(docDefaultsElement(context.stylesRoot, "w:rPrDefault", "w:rPr"), context.theme);
7118
- if (context.stylesRoot !== void 0) {
7119
- const defaultStyle = findDefaultStyle(context.stylesRoot, "paragraph");
7120
- if (defaultStyle !== void 0) resolved = mergeRunLayer(resolved, readRunPropertiesLayer((0, ooxml_js.childrenWithTag)(defaultStyle, "w:rPr")[0], context.theme));
7121
- if (pStyleId !== void 0) for (const style of resolveBasedOnChain(context.stylesRoot, pStyleId, "paragraph")) resolved = mergeRunLayer(resolved, readRunPropertiesLayer((0, ooxml_js.childrenWithTag)(style, "w:rPr")[0], context.theme));
7122
- }
7123
- const paragraphMarkRPr = pPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(pPr, "w:rPr")[0];
7124
- resolved = mergeRunLayer(resolved, readRunPropertiesLayer(paragraphMarkRPr, context.theme));
7125
- const rPr = (0, ooxml_js.childrenWithTag)(run, "w:rPr")[0];
7126
- const rStyleEl = rPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(rPr, "w:rStyle")[0];
7127
- const rStyleId = rStyleEl === void 0 ? void 0 : (0, ooxml_js.attr)(rStyleEl, "w:val");
7128
- if (context.stylesRoot !== void 0 && rStyleId !== void 0) for (const style of resolveBasedOnChain(context.stylesRoot, rStyleId, "character")) resolved = mergeRunLayer(resolved, readRunPropertiesLayer((0, ooxml_js.childrenWithTag)(style, "w:rPr")[0], context.theme));
7129
- return mergeRunLayer(resolved, readRunPropertiesLayer(rPr, context.theme));
7130
- }
7131
- //#endregion
7132
6623
  //#region src/ooxml/docx/read.ts
7133
- const DOCUMENT_PART_PATH = "word/document.xml";
7134
- const STYLES_PART_PATH = "word/styles.xml";
7135
- const THEME_REL_SUFFIX$1 = "/theme";
7136
- const DEFAULT_MARGIN_PT = 72;
7137
- const DEFAULT_MARGINS = {
7138
- topPt: DEFAULT_MARGIN_PT,
7139
- rightPt: DEFAULT_MARGIN_PT,
7140
- bottomPt: DEFAULT_MARGIN_PT,
7141
- leftPt: DEFAULT_MARGIN_PT
7142
- };
7143
- function readPageSize(sectPr) {
7144
- const pgSz = (0, ooxml_js.childrenWithTag)(sectPr, "w:pgSz")[0];
7145
- const w = pgSz === void 0 ? void 0 : (0, ooxml_js.attr)(pgSz, "w:w");
7146
- const h = pgSz === void 0 ? void 0 : (0, ooxml_js.attr)(pgSz, "w:h");
7147
- return w === void 0 || h === void 0 ? PAGE_SIZE_LETTER : {
7148
- widthPt: twipsToPt(Number(w)),
7149
- heightPt: twipsToPt(Number(h))
7150
- };
7151
- }
7152
- function readMargins(sectPr) {
7153
- const pgMar = (0, ooxml_js.childrenWithTag)(sectPr, "w:pgMar")[0];
7154
- if (pgMar === void 0) return DEFAULT_MARGINS;
7155
- const top = (0, ooxml_js.attr)(pgMar, "w:top");
7156
- const right = (0, ooxml_js.attr)(pgMar, "w:right");
7157
- const bottom = (0, ooxml_js.attr)(pgMar, "w:bottom");
7158
- const left = (0, ooxml_js.attr)(pgMar, "w:left");
7159
- return {
7160
- topPt: top === void 0 ? DEFAULT_MARGIN_PT : twipsToPt(Number(top)),
7161
- rightPt: right === void 0 ? DEFAULT_MARGIN_PT : twipsToPt(Number(right)),
7162
- bottomPt: bottom === void 0 ? DEFAULT_MARGIN_PT : twipsToPt(Number(bottom)),
7163
- leftPt: left === void 0 ? DEFAULT_MARGIN_PT : twipsToPt(Number(left))
7164
- };
7165
- }
7166
- function readListMembership(pPr) {
7167
- const numPr = pPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(pPr, "w:numPr")[0];
7168
- if (numPr === void 0) return;
7169
- const numIdEl = (0, ooxml_js.childrenWithTag)(numPr, "w:numId")[0];
7170
- const numId = numIdEl === void 0 ? void 0 : (0, ooxml_js.attr)(numIdEl, "w:val");
7171
- if (numId === void 0) return;
7172
- const ilvlEl = (0, ooxml_js.childrenWithTag)(numPr, "w:ilvl")[0];
7173
- const ilvlVal = ilvlEl === void 0 ? void 0 : (0, ooxml_js.attr)(ilvlEl, "w:val");
7174
- return {
7175
- numId,
7176
- level: ilvlVal === void 0 ? 0 : Number(ilvlVal)
7177
- };
7178
- }
7179
- function readToggle(el) {
7180
- if (el === void 0) return false;
7181
- const val = (0, ooxml_js.attr)(el, "w:val");
7182
- return val === void 0 || val !== "0" && val !== "false" && val !== "off";
7183
- }
7184
- function hasPageBreakBefore(paragraph) {
7185
- const pPr = (0, ooxml_js.childrenWithTag)(paragraph, "w:pPr")[0];
7186
- return readToggle(pPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(pPr, "w:pageBreakBefore")[0]);
7187
- }
7188
- function readRunText(run) {
7189
- let text = "";
7190
- for (const child of run.children) {
7191
- if (child.type !== "element") continue;
7192
- if (child.tag === "w:t") text += (0, ooxml_js.textContent)(child);
7193
- else if (child.tag === "w:tab") text += " ";
7194
- else if (child.tag === "w:br" || child.tag === "w:cr") text += "\n";
7195
- }
7196
- return text;
7197
- }
7198
- function readRun$1(run, paragraph, context) {
7199
- const props = resolveRunProperties(run, paragraph, context);
7200
- return {
7201
- text: readRunText(run),
7202
- bold: props.bold,
7203
- italic: props.italic,
7204
- underline: props.underline,
7205
- strike: props.strike,
7206
- fontFamily: props.fontFamily,
7207
- sizePt: props.sizePt,
7208
- color: props.color
7209
- };
7210
- }
7211
- function readParagraphRuns(paragraph, context, rels) {
7212
- const runs = [];
7213
- let fieldState = "none";
7214
- function walk(nodes, hyperlinkTarget) {
7215
- for (const node of nodes) {
7216
- if (node.type !== "element") continue;
7217
- if (node.tag === "w:r") {
7218
- const fldChar = (0, ooxml_js.childrenWithTag)(node, "w:fldChar")[0];
7219
- if (fldChar !== void 0) {
7220
- const type = (0, ooxml_js.attr)(fldChar, "w:fldCharType");
7221
- if (type === "begin") fieldState = "code";
7222
- else if (type === "separate") fieldState = "result";
7223
- else if (type === "end") fieldState = "none";
7224
- continue;
7225
- }
7226
- if (fieldState === "code") continue;
7227
- const run = readRun$1(node, paragraph, context);
7228
- runs.push(hyperlinkTarget === void 0 ? run : {
7229
- ...run,
7230
- hyperlink: hyperlinkTarget
7231
- });
7232
- } else if (node.tag === "w:fldSimple") walk(node.children, hyperlinkTarget);
7233
- else if (node.tag === "w:hyperlink") {
7234
- const rId = (0, ooxml_js.attr)(node, "r:id");
7235
- const target = rId === void 0 ? void 0 : rels.get(rId)?.target;
7236
- walk(node.children, target ?? hyperlinkTarget);
7237
- } else if (node.tag === "w:ins") walk(node.children, hyperlinkTarget);
7238
- }
7239
- }
7240
- walk(paragraph.children, void 0);
7241
- return runs;
7242
- }
7243
- function readParagraph$1(paragraph, context, rels) {
7244
- const pPr = (0, ooxml_js.childrenWithTag)(paragraph, "w:pPr")[0];
7245
- const pStyleEl = pPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(pPr, "w:pStyle")[0];
7246
- const props = resolveParagraphProperties(paragraph, context);
7247
- return {
7248
- kind: "paragraph",
7249
- runs: readParagraphRuns(paragraph, context, rels),
7250
- styleId: pStyleEl === void 0 ? void 0 : (0, ooxml_js.attr)(pStyleEl, "w:val"),
7251
- alignment: props.alignment,
7252
- list: readListMembership(pPr),
7253
- spacingBeforePt: props.spacingBeforePt,
7254
- spacingAfterPt: props.spacingAfterPt,
7255
- lineSpacing: props.lineSpacing,
7256
- indentLeftPt: props.indentLeftPt,
7257
- indentFirstLinePt: props.indentFirstLinePt
7258
- };
7259
- }
7260
- function readCellShading(tcPr) {
7261
- const shd = tcPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(tcPr, "w:shd")[0];
7262
- const fill = shd === void 0 ? void 0 : (0, ooxml_js.attr)(shd, "w:fill");
7263
- return fill === void 0 || fill === "auto" || fill === "none" ? void 0 : rgbHexToColor(fill);
7264
- }
7265
- function readRawCell(tc, context, rels) {
7266
- const tcPr = (0, ooxml_js.childrenWithTag)(tc, "w:tcPr")[0];
7267
- const gridSpanEl = tcPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(tcPr, "w:gridSpan")[0];
7268
- const gridSpanVal = gridSpanEl === void 0 ? void 0 : (0, ooxml_js.attr)(gridSpanEl, "w:val");
7269
- const vMerge = tcPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(tcPr, "w:vMerge")[0];
7270
- const vMergeVal = vMerge === void 0 ? void 0 : (0, ooxml_js.attr)(vMerge, "w:val") ?? "continue";
7271
- return {
7272
- gridSpan: gridSpanVal === void 0 ? 1 : Number(gridSpanVal),
7273
- isVMergeContinuation: vMergeVal === "continue",
7274
- background: readCellShading(tcPr),
7275
- blocks: readBodyBlocks(tc.children, context, rels)
7276
- };
7277
- }
7278
- function readTable$1(tbl, context, rels) {
7279
- const tblGrid = (0, ooxml_js.childrenWithTag)(tbl, "w:tblGrid")[0];
7280
- const columnWidthsPt = tblGrid === void 0 ? [] : (0, ooxml_js.childrenWithTag)(tblGrid, "w:gridCol").map((col) => twipsToPt(Number((0, ooxml_js.attr)(col, "w:w") ?? "0")));
7281
- const rawRows = (0, ooxml_js.childrenWithTag)(tbl, "w:tr").map((tr) => (0, ooxml_js.childrenWithTag)(tr, "w:tc").map((tc) => readRawCell(tc, context, rels)));
7282
- const rowColumnIndices = rawRows.map((row) => {
7283
- const indices = [];
7284
- let col = 0;
7285
- for (const cell of row) {
7286
- indices.push(col);
7287
- col += cell.gridSpan;
7288
- }
7289
- return indices;
7290
- });
7291
- return {
7292
- kind: "table",
7293
- columnWidthsPt,
7294
- rows: rawRows.map((row, rowIndex) => ({ cells: row.map((cell, cellIndex) => {
7295
- if (cell.isVMergeContinuation) return { blocks: [] };
7296
- const colIndex = rowColumnIndices[rowIndex][cellIndex];
7297
- let rowSpan = 1;
7298
- for (let r = rowIndex + 1; r < rawRows.length; r++) {
7299
- const matchIndex = rowColumnIndices[r].indexOf(colIndex);
7300
- if (!(matchIndex === -1 ? void 0 : rawRows[r][matchIndex])?.isVMergeContinuation) break;
7301
- rowSpan++;
7302
- }
7303
- return {
7304
- blocks: cell.blocks,
7305
- colSpan: cell.gridSpan > 1 ? cell.gridSpan : void 0,
7306
- rowSpan: rowSpan > 1 ? rowSpan : void 0,
7307
- background: cell.background
7308
- };
7309
- }) }))
7310
- };
7311
- }
7312
- function readBodyBlocks(nodes, context, rels) {
7313
- const blocks = [];
7314
- for (const node of nodes) {
7315
- if (node.type !== "element") continue;
7316
- if (node.tag === "w:p") {
7317
- if (hasPageBreakBefore(node)) blocks.push({ kind: "pageBreak" });
7318
- blocks.push(readParagraph$1(node, context, rels));
7319
- } else if (node.tag === "w:tbl") blocks.push(readTable$1(node, context, rels));
7320
- else if (node.tag === "w:sdt") {
7321
- const sdtContent = (0, ooxml_js.childrenWithTag)(node, "w:sdtContent")[0];
7322
- if (sdtContent !== void 0) blocks.push(...readBodyBlocks(sdtContent.children, context, rels));
7323
- } else if (node.tag === "w:ins") blocks.push(...readBodyBlocks(node.children, context, rels));
7324
- else if (node.tag === "mc:AlternateContent") {
7325
- const target = (0, ooxml_js.childrenWithTag)(node, "mc:Fallback")[0] ?? (0, ooxml_js.childrenWithTag)(node, "mc:Choice")[0];
7326
- if (target !== void 0) blocks.push(...readBodyBlocks(target.children, context, rels));
7327
- }
7328
- }
7329
- return blocks;
7330
- }
7331
- function readSections(body, context, rels) {
7332
- const sections = [];
7333
- let currentBlocks = [];
7334
- for (const node of body.children) {
7335
- if (node.type !== "element") continue;
7336
- if (node.tag === "w:sectPr") {
7337
- sections.push({
7338
- pageSize: readPageSize(node),
7339
- margins: readMargins(node),
7340
- blocks: currentBlocks
7341
- });
7342
- currentBlocks = [];
7343
- continue;
7344
- }
7345
- if (node.tag === "w:p") {
7346
- const pPr = (0, ooxml_js.childrenWithTag)(node, "w:pPr")[0];
7347
- const sectPr = pPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(pPr, "w:sectPr")[0];
7348
- if (hasPageBreakBefore(node)) currentBlocks.push({ kind: "pageBreak" });
7349
- currentBlocks.push(readParagraph$1(node, context, rels));
7350
- if (sectPr !== void 0) {
7351
- sections.push({
7352
- pageSize: readPageSize(sectPr),
7353
- margins: readMargins(sectPr),
7354
- blocks: currentBlocks
7355
- });
7356
- currentBlocks = [];
7357
- }
7358
- continue;
7359
- }
7360
- currentBlocks.push(...readBodyBlocks([node], context, rels));
7361
- }
7362
- if (currentBlocks.length > 0 || sections.length === 0) sections.push({
7363
- pageSize: PAGE_SIZE_LETTER,
7364
- margins: DEFAULT_MARGINS,
7365
- blocks: currentBlocks
7366
- });
7367
- return sections;
7368
- }
7369
- function readDocumentTheme(pkg, docRels) {
7370
- for (const rel of docRels.values()) if (rel.type.endsWith(THEME_REL_SUFFIX$1)) {
7371
- const themeRoot = (0, ooxml_js.rootElement)(pkg.parts[rel.target]);
7372
- if (themeRoot !== void 0) return readTheme(themeRoot);
7373
- }
7374
- return EMPTY_THEME;
7375
- }
7376
6624
  function readDocxContent(pkg) {
7377
- const documentRoot = (0, ooxml_js.rootElement)(pkg.parts[DOCUMENT_PART_PATH]);
7378
- if (documentRoot === void 0) throw new Error(`package has no ${DOCUMENT_PART_PATH} part`);
7379
- const body = (0, ooxml_js.childrenWithTag)(documentRoot, "w:body")[0];
7380
- if (body === void 0) throw new Error(`${DOCUMENT_PART_PATH} has no w:body element`);
7381
- const docRels = (0, ooxml_js.resolveRelationships)(pkg, DOCUMENT_PART_PATH);
7382
- const context = {
7383
- stylesRoot: (0, ooxml_js.rootElement)(pkg.parts[STYLES_PART_PATH]),
7384
- theme: readDocumentTheme(pkg, docRels)
7385
- };
6625
+ const docxDoc = (0, ooxml_js.readDocx)(pkg);
7386
6626
  return {
7387
6627
  kind: "wordprocessing",
7388
6628
  formatVersion: 1,
7389
- metadata: readCoreProperties(pkg),
7390
- sections: readSections(body, context, docRels)
7391
- };
7392
- }
7393
- //#endregion
7394
- //#region src/image/sniff.ts
7395
- const PNG_SIGNATURE = [
7396
- 137,
7397
- 80,
7398
- 78,
7399
- 71,
7400
- 13,
7401
- 10,
7402
- 26,
7403
- 10
7404
- ];
7405
- const JPEG_SIGNATURE = [
7406
- 255,
7407
- 216,
7408
- 255
7409
- ];
7410
- function startsWith(bytes, signature) {
7411
- if (bytes.length < signature.length) return false;
7412
- for (let i = 0; i < signature.length; i++) if (bytes[i] !== signature[i]) return false;
7413
- return true;
7414
- }
7415
- function sniffImageFormat(bytes) {
7416
- if (startsWith(bytes, PNG_SIGNATURE)) return "png";
7417
- if (startsWith(bytes, JPEG_SIGNATURE)) return "jpeg";
7418
- }
7419
- //#endregion
7420
- //#region src/ooxml/pptx/inherit.ts
7421
- const SLIDE_LAYOUT_REL_SUFFIX = "/slideLayout";
7422
- const SLIDE_MASTER_REL_SUFFIX = "/slideMaster";
7423
- const THEME_REL_SUFFIX = "/theme";
7424
- function findRelTarget(pkg, partPath, typeSuffix) {
7425
- for (const rel of (0, ooxml_js.resolveRelationships)(pkg, partPath).values()) if (rel.type.endsWith(typeSuffix)) return rel.target;
7426
- }
7427
- function resolveSlideInheritance(pkg, slidePath) {
7428
- const layoutPath = findRelTarget(pkg, slidePath, SLIDE_LAYOUT_REL_SUFFIX);
7429
- const layoutRoot = layoutPath === void 0 ? void 0 : (0, ooxml_js.rootElement)(pkg.parts[layoutPath]);
7430
- const masterPath = layoutPath === void 0 ? void 0 : findRelTarget(pkg, layoutPath, SLIDE_MASTER_REL_SUFFIX);
7431
- const masterRoot = masterPath === void 0 ? void 0 : (0, ooxml_js.rootElement)(pkg.parts[masterPath]);
7432
- const themePath = masterPath === void 0 ? void 0 : findRelTarget(pkg, masterPath, THEME_REL_SUFFIX);
7433
- const themeRoot = themePath === void 0 ? void 0 : (0, ooxml_js.rootElement)(pkg.parts[themePath]);
7434
- return {
7435
- layoutRoot,
7436
- masterRoot,
7437
- theme: themeRoot === void 0 ? EMPTY_THEME : readTheme(themeRoot),
7438
- colorMap: readColorMap(masterRoot === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(masterRoot, "p:clrMap")[0])
7439
- };
7440
- }
7441
- const TYPE_NORMALIZATION = /* @__PURE__ */ new Map([["ctrTitle", "title"], ["subTitle", "body"]]);
7442
- function normalizePlaceholderType(type) {
7443
- return type === void 0 ? void 0 : TYPE_NORMALIZATION.get(type) ?? type;
7444
- }
7445
- function readPlaceholderKey(shape) {
7446
- const ph = (0, ooxml_js.elementsWithTag)([shape], "p:ph")[0];
7447
- return ph === void 0 ? void 0 : {
7448
- type: (0, ooxml_js.attr)(ph, "type"),
7449
- idx: (0, ooxml_js.attr)(ph, "idx")
6629
+ metadata: { ...docxDoc.metadata },
6630
+ sections: docxDoc.sections
7450
6631
  };
7451
6632
  }
7452
- function shapesOf(root) {
7453
- return root === void 0 ? [] : (0, ooxml_js.elementsWithTag)([root], "p:sp");
7454
- }
7455
- function findMatchingPlaceholder(root, key) {
7456
- const shapes = shapesOf(root);
7457
- if (key.idx !== void 0) {
7458
- const byIdx = shapes.find((shape) => readPlaceholderKey(shape)?.idx === key.idx);
7459
- if (byIdx !== void 0) return byIdx;
7460
- }
7461
- const normalizedTarget = normalizePlaceholderType(key.type);
7462
- if (normalizedTarget === void 0) return;
7463
- return shapes.find((shape) => normalizePlaceholderType(readPlaceholderKey(shape)?.type) === normalizedTarget);
7464
- }
7465
- function shapeXfrm(shape) {
7466
- if (shape === void 0) return;
7467
- const spPr = (0, ooxml_js.childrenWithTag)(shape, "p:spPr")[0];
7468
- return spPr === void 0 ? void 0 : readXfrm((0, ooxml_js.childrenWithTag)(spPr, "a:xfrm")[0]);
7469
- }
7470
- function resolvePlaceholderXfrm(key, context) {
7471
- return shapeXfrm(findMatchingPlaceholder(context.layoutRoot, key)) ?? shapeXfrm(findMatchingPlaceholder(context.masterRoot, key));
7472
- }
7473
- function readRunPropertiesFromElement(rPr, context) {
7474
- const sz = (0, ooxml_js.attr)(rPr, "sz");
7475
- const latin = (0, ooxml_js.childrenWithTag)(rPr, "a:latin")[0];
7476
- const typeface = latin === void 0 ? void 0 : (0, ooxml_js.attr)(latin, "typeface");
7477
- const solidFill = (0, ooxml_js.childrenWithTag)(rPr, "a:solidFill")[0];
7478
- const bold = (0, ooxml_js.attr)(rPr, "b");
7479
- const italic = (0, ooxml_js.attr)(rPr, "i");
7480
- return {
7481
- fontFamily: typeface === void 0 ? void 0 : resolveThemeFontReference(typeface, context.theme),
7482
- sizePt: sz === void 0 ? void 0 : drawingMlFontSizeToPt(Number(sz)),
7483
- bold: bold === void 0 ? void 0 : bold === "1",
7484
- italic: italic === void 0 ? void 0 : italic === "1",
7485
- color: readSolidFillColor(solidFill, context.colorMap, context.theme)
7486
- };
7487
- }
7488
- function txStyleTagFor(placeholderType) {
7489
- const normalized = normalizePlaceholderType(placeholderType);
7490
- if (normalized === "title") return "p:titleStyle";
7491
- if (normalized === "body") return "p:bodyStyle";
7492
- return "p:otherStyle";
7493
- }
7494
- function levelTag(level) {
7495
- return `a:lvl${Math.min(Math.max(level, 0), 8) + 1}pPr`;
7496
- }
7497
- function resolveDefaultRunProperties(placeholderType, level, context) {
7498
- if (context.masterRoot === void 0) return {};
7499
- const txStyles = (0, ooxml_js.childrenWithTag)(context.masterRoot, "p:txStyles")[0];
7500
- const styleEl = txStyles === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(txStyles, txStyleTagFor(placeholderType))[0];
7501
- const lvlPPr = styleEl === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(styleEl, levelTag(level))[0];
7502
- const defRPr = lvlPPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(lvlPPr, "a:defRPr")[0];
7503
- return defRPr === void 0 ? {} : readRunPropertiesFromElement(defRPr, context);
7504
- }
7505
6633
  //#endregion
7506
6634
  //#region src/ooxml/pptx/read.ts
7507
- const PRESENTATION_PATH = "ppt/presentation.xml";
7508
- const TABLE_GRAPHIC_URI = "http://schemas.openxmlformats.org/drawingml/2006/table";
7509
- function readSlideSize(presentationRoot) {
7510
- const sldSz = presentationRoot === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(presentationRoot, "p:sldSz")[0];
7511
- const cx = sldSz === void 0 ? void 0 : (0, ooxml_js.attr)(sldSz, "cx");
7512
- const cy = sldSz === void 0 ? void 0 : (0, ooxml_js.attr)(sldSz, "cy");
7513
- return cx === void 0 || cy === void 0 ? SLIDE_SIZE_WIDESCREEN : {
7514
- widthPt: emuToPt(Number(cx)),
7515
- heightPt: emuToPt(Number(cy))
7516
- };
7517
- }
7518
- function readSlidePathsInOrder(pkg, presentationRoot) {
7519
- if (presentationRoot === void 0) return [];
7520
- const sldIdLst = (0, ooxml_js.childrenWithTag)(presentationRoot, "p:sldIdLst")[0];
7521
- if (sldIdLst === void 0) return [];
7522
- const presentationRels = (0, ooxml_js.resolveRelationships)(pkg, PRESENTATION_PATH);
7523
- const paths = [];
7524
- for (const sldId of (0, ooxml_js.childrenWithTag)(sldIdLst, "p:sldId")) {
7525
- const rId = (0, ooxml_js.attr)(sldId, "r:id");
7526
- const rel = rId === void 0 ? void 0 : presentationRels.get(rId);
7527
- if (rel !== void 0) paths.push(rel.target);
7528
- }
7529
- return paths;
7530
- }
7531
- function shapeName(shape) {
7532
- const cNvPr = (0, ooxml_js.elementsWithTag)([shape], "p:cNvPr")[0];
7533
- return cNvPr === void 0 ? void 0 : (0, ooxml_js.attr)(cNvPr, "name");
7534
- }
7535
- function mergeRunProperties(base, override) {
7536
- return {
7537
- fontFamily: override.fontFamily ?? base.fontFamily,
7538
- sizePt: override.sizePt ?? base.sizePt,
7539
- bold: override.bold ?? base.bold,
7540
- italic: override.italic ?? base.italic,
7541
- color: override.color ?? base.color
7542
- };
7543
- }
7544
- function isUnderlined(rPr) {
7545
- if (rPr === void 0) return;
7546
- const u = (0, ooxml_js.attr)(rPr, "u");
7547
- return u === void 0 ? void 0 : u !== "none";
7548
- }
7549
- function isStrikethrough(rPr) {
7550
- if (rPr === void 0) return;
7551
- const strike = (0, ooxml_js.attr)(rPr, "strike");
7552
- return strike === void 0 ? void 0 : strike !== "noStrike";
7553
- }
7554
- function readHyperlink(rPr, slideRels) {
7555
- if (rPr === void 0) return;
7556
- const hlink = (0, ooxml_js.childrenWithTag)(rPr, "a:hlinkClick")[0];
7557
- const rId = hlink === void 0 ? void 0 : (0, ooxml_js.attr)(hlink, "r:id");
7558
- const rel = rId === void 0 ? void 0 : slideRels.get(rId);
7559
- return rel?.targetMode === "External" ? rel.target : void 0;
7560
- }
7561
- function readRun(runEl, cascadeBase, context, slideRels) {
7562
- const rPr = (0, ooxml_js.childrenWithTag)(runEl, "a:rPr")[0];
7563
- const merged = mergeRunProperties(cascadeBase, rPr === void 0 ? {} : readRunPropertiesFromElement(rPr, context));
7564
- const tEl = (0, ooxml_js.childrenWithTag)(runEl, "a:t")[0];
7565
- return {
7566
- text: tEl === void 0 ? "" : (0, ooxml_js.textContent)(tEl),
7567
- bold: merged.bold,
7568
- italic: merged.italic,
7569
- underline: isUnderlined(rPr),
7570
- strike: isStrikethrough(rPr),
7571
- fontFamily: merged.fontFamily,
7572
- sizePt: merged.sizePt,
7573
- color: merged.color,
7574
- hyperlink: readHyperlink(rPr, slideRels)
7575
- };
7576
- }
7577
- function readAlignment(algn) {
7578
- if (algn === "l") return "left";
7579
- if (algn === "ctr") return "center";
7580
- if (algn === "r") return "right";
7581
- if (algn === "just" || algn === "justLow") return "justify";
7582
- }
7583
- function readAbsoluteSpacingPt(spc) {
7584
- if (spc === void 0) return;
7585
- const pts = (0, ooxml_js.childrenWithTag)(spc, "a:spcPts")[0];
7586
- const val = pts === void 0 ? void 0 : (0, ooxml_js.attr)(pts, "val");
7587
- return val === void 0 ? void 0 : drawingMlFontSizeToPt(Number(val));
7588
- }
7589
- function readLineSpacingMultiplier(pPr) {
7590
- const lnSpc = pPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(pPr, "a:lnSpc")[0];
7591
- const pct = lnSpc === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(lnSpc, "a:spcPct")[0];
7592
- const val = pct === void 0 ? void 0 : (0, ooxml_js.attr)(pct, "val");
7593
- return val === void 0 ? void 0 : Number(val) / 1e5;
7594
- }
7595
- function readParagraph(pEl, placeholderType, context, slideRels) {
7596
- const pPr = (0, ooxml_js.childrenWithTag)(pEl, "a:pPr")[0];
7597
- const masterDefaults = resolveDefaultRunProperties(placeholderType, pPr === void 0 ? 0 : Number((0, ooxml_js.attr)(pPr, "lvl") ?? "0"), context);
7598
- const pPrDefRPr = pPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(pPr, "a:defRPr")[0];
7599
- const paragraphDefaults = pPrDefRPr === void 0 ? masterDefaults : mergeRunProperties(masterDefaults, readRunPropertiesFromElement(pPrDefRPr, context));
7600
- const runs = [];
7601
- for (const child of pEl.children) {
7602
- if (child.type !== "element") continue;
7603
- if (child.tag === "a:r" || child.tag === "a:fld") runs.push(readRun(child, paragraphDefaults, context, slideRels));
7604
- else if (child.tag === "a:br") runs.push({ text: "\n" });
7605
- }
7606
- const marL = pPr === void 0 ? void 0 : (0, ooxml_js.attr)(pPr, "marL");
7607
- const indent = pPr === void 0 ? void 0 : (0, ooxml_js.attr)(pPr, "indent");
7608
- return {
7609
- kind: "paragraph",
7610
- runs,
7611
- alignment: pPr === void 0 ? void 0 : readAlignment((0, ooxml_js.attr)(pPr, "algn")),
7612
- spacingBeforePt: readAbsoluteSpacingPt(pPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(pPr, "a:spcBef")[0]),
7613
- spacingAfterPt: readAbsoluteSpacingPt(pPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(pPr, "a:spcAft")[0]),
7614
- lineSpacing: readLineSpacingMultiplier(pPr),
7615
- indentLeftPt: marL === void 0 ? void 0 : emuToPt(Number(marL)),
7616
- indentFirstLinePt: indent === void 0 ? void 0 : emuToPt(Number(indent))
7617
- };
7618
- }
7619
- function textBodyParagraphs(txBody, placeholderType, context, slideRels) {
7620
- return txBody === void 0 ? [] : (0, ooxml_js.childrenWithTag)(txBody, "a:p").map((p) => readParagraph(p, placeholderType, context, slideRels));
7621
- }
7622
- const DEFAULT_INSET_LEFT_RIGHT_EMU = 91440;
7623
- const DEFAULT_INSET_TOP_BOTTOM_EMU = 45720;
7624
- const NO_TEXT_BODY_EXTRAS = {
7625
- insetLeftPt: 0,
7626
- insetTopPt: 0,
7627
- insetRightPt: 0,
7628
- insetBottomPt: 0,
7629
- fontScale: void 0,
7630
- lineSpacingReduction: void 0
7631
- };
7632
- function readShapeTextExtras(txBody) {
7633
- if (txBody === void 0) return NO_TEXT_BODY_EXTRAS;
7634
- const bodyPr = (0, ooxml_js.childrenWithTag)(txBody, "a:bodyPr")[0];
7635
- const lIns = bodyPr === void 0 ? void 0 : (0, ooxml_js.attr)(bodyPr, "lIns");
7636
- const tIns = bodyPr === void 0 ? void 0 : (0, ooxml_js.attr)(bodyPr, "tIns");
7637
- const rIns = bodyPr === void 0 ? void 0 : (0, ooxml_js.attr)(bodyPr, "rIns");
7638
- const bIns = bodyPr === void 0 ? void 0 : (0, ooxml_js.attr)(bodyPr, "bIns");
7639
- const normAutofit = bodyPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(bodyPr, "a:normAutofit")[0];
7640
- const fontScale = normAutofit === void 0 ? void 0 : (0, ooxml_js.attr)(normAutofit, "fontScale");
7641
- const lnSpcReduction = normAutofit === void 0 ? void 0 : (0, ooxml_js.attr)(normAutofit, "lnSpcReduction");
7642
- return {
7643
- insetLeftPt: emuToPt(lIns === void 0 ? DEFAULT_INSET_LEFT_RIGHT_EMU : Number(lIns)),
7644
- insetTopPt: emuToPt(tIns === void 0 ? DEFAULT_INSET_TOP_BOTTOM_EMU : Number(tIns)),
7645
- insetRightPt: emuToPt(rIns === void 0 ? DEFAULT_INSET_LEFT_RIGHT_EMU : Number(rIns)),
7646
- insetBottomPt: emuToPt(bIns === void 0 ? DEFAULT_INSET_TOP_BOTTOM_EMU : Number(bIns)),
7647
- fontScale: fontScale === void 0 ? void 0 : Number(fontScale) / 1e5,
7648
- lineSpacingReduction: lnSpcReduction === void 0 ? void 0 : Number(lnSpcReduction) / 1e5
7649
- };
7650
- }
7651
- function resolveShapeFrame(shape, context, parentTransform) {
7652
- const key = readPlaceholderKey(shape);
7653
- const spPr = (0, ooxml_js.childrenWithTag)(shape, "p:spPr")[0];
7654
- const xfrm = (spPr === void 0 ? void 0 : readXfrm((0, ooxml_js.childrenWithTag)(spPr, "a:xfrm")[0])) ?? (key === void 0 ? void 0 : resolvePlaceholderXfrm(key, context));
7655
- if (xfrm === void 0) return;
7656
- const localFrame = {
7657
- xPt: xfrm.xPt,
7658
- yPt: xfrm.yPt,
7659
- widthPt: xfrm.widthPt,
7660
- heightPt: xfrm.heightPt
7661
- };
7662
- return {
7663
- frame: parentTransform === void 0 ? localFrame : applyGroupTransform(parentTransform, localFrame),
7664
- rotationDeg: xfrm.rotationDeg === 0 ? void 0 : xfrm.rotationDeg
7665
- };
7666
- }
7667
- function readSpShape(sp, context, slideRels, parentTransform) {
7668
- const resolved = resolveShapeFrame(sp, context, parentTransform);
7669
- if (resolved === void 0) return;
7670
- const key = readPlaceholderKey(sp);
7671
- const txBody = (0, ooxml_js.childrenWithTag)(sp, "p:txBody")[0];
7672
- const blocks = textBodyParagraphs(txBody, key?.type, context, slideRels);
7673
- const extras = readShapeTextExtras(txBody);
7674
- return {
7675
- name: shapeName(sp),
7676
- frame: resolved.frame,
7677
- rotationDeg: resolved.rotationDeg,
7678
- ...extras,
7679
- blocks
7680
- };
7681
- }
7682
- function readPicShape(pic, context, slideRels, pkg, parentTransform) {
7683
- const resolved = resolveShapeFrame(pic, context, parentTransform);
7684
- if (resolved === void 0) return;
7685
- const blipFill = (0, ooxml_js.childrenWithTag)(pic, "p:blipFill")[0];
7686
- const blip = blipFill === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(blipFill, "a:blip")[0];
7687
- const rId = blip === void 0 ? void 0 : (0, ooxml_js.attr)(blip, "r:embed");
7688
- const rel = rId === void 0 ? void 0 : slideRels.get(rId);
7689
- const mediaPart = rel === void 0 ? void 0 : pkg.parts[rel.target];
7690
- const blocks = [];
7691
- if (mediaPart?.kind === "binary") {
7692
- const format = sniffImageFormat((0, ooxml_js.base64ToBytes)(mediaPart.base64));
7693
- if (format !== void 0) {
7694
- const image = {
7695
- kind: "image",
7696
- format,
7697
- base64: mediaPart.base64,
7698
- widthPt: resolved.frame.widthPt,
7699
- heightPt: resolved.frame.heightPt
7700
- };
7701
- blocks.push(image);
7702
- }
7703
- }
7704
- return {
7705
- name: shapeName(pic),
7706
- frame: resolved.frame,
7707
- rotationDeg: resolved.rotationDeg,
7708
- ...NO_TEXT_BODY_EXTRAS,
7709
- blocks
7710
- };
7711
- }
7712
- function readTableCell(tc, context, slideRels) {
7713
- const hMerge = (0, ooxml_js.attr)(tc, "hMerge");
7714
- const vMerge = (0, ooxml_js.attr)(tc, "vMerge");
7715
- if (hMerge === "1" || vMerge === "1") return { blocks: [] };
7716
- const tcPr = (0, ooxml_js.childrenWithTag)(tc, "a:tcPr")[0];
7717
- const background = readSolidFillColor(tcPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(tcPr, "a:solidFill")[0], context.colorMap, context.theme);
7718
- const txBody = (0, ooxml_js.childrenWithTag)(tc, "a:txBody")[0];
7719
- const gridSpan = (0, ooxml_js.attr)(tc, "gridSpan");
7720
- const rowSpan = (0, ooxml_js.attr)(tc, "rowSpan");
7721
- return {
7722
- blocks: textBodyParagraphs(txBody, void 0, context, slideRels),
7723
- colSpan: gridSpan === void 0 ? void 0 : Number(gridSpan),
7724
- rowSpan: rowSpan === void 0 ? void 0 : Number(rowSpan),
7725
- background
7726
- };
7727
- }
7728
- function readTable(tbl, context, slideRels) {
7729
- const tblGrid = (0, ooxml_js.childrenWithTag)(tbl, "a:tblGrid")[0];
7730
- const columnWidthsPt = tblGrid === void 0 ? [] : (0, ooxml_js.childrenWithTag)(tblGrid, "a:gridCol").map((col) => emuToPt(Number((0, ooxml_js.attr)(col, "w") ?? "0")));
7731
- return {
7732
- kind: "table",
7733
- rows: (0, ooxml_js.childrenWithTag)(tbl, "a:tr").map((tr) => {
7734
- const h = (0, ooxml_js.attr)(tr, "h");
7735
- return {
7736
- cells: (0, ooxml_js.childrenWithTag)(tr, "a:tc").map((tc) => readTableCell(tc, context, slideRels)),
7737
- heightPt: h === void 0 ? void 0 : emuToPt(Number(h))
7738
- };
7739
- }),
7740
- columnWidthsPt
7741
- };
7742
- }
7743
- function readGraphicFrameShape(gf, context, slideRels, parentTransform) {
7744
- const xfrm = readXfrm((0, ooxml_js.childrenWithTag)(gf, "p:xfrm")[0]);
7745
- if (xfrm === void 0) return;
7746
- const localFrame = {
7747
- xPt: xfrm.xPt,
7748
- yPt: xfrm.yPt,
7749
- widthPt: xfrm.widthPt,
7750
- heightPt: xfrm.heightPt
7751
- };
7752
- const frame = parentTransform === void 0 ? localFrame : applyGroupTransform(parentTransform, localFrame);
7753
- const rotationDeg = xfrm.rotationDeg === 0 ? void 0 : xfrm.rotationDeg;
7754
- const graphic = (0, ooxml_js.childrenWithTag)(gf, "a:graphic")[0];
7755
- const graphicData = graphic === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(graphic, "a:graphicData")[0];
7756
- const tbl = (graphicData === void 0 ? void 0 : (0, ooxml_js.attr)(graphicData, "uri")) === TABLE_GRAPHIC_URI && graphicData !== void 0 ? (0, ooxml_js.childrenWithTag)(graphicData, "a:tbl")[0] : void 0;
7757
- const blocks = tbl === void 0 ? [] : [readTable(tbl, context, slideRels)];
7758
- return {
7759
- name: shapeName(gf),
7760
- frame,
7761
- rotationDeg,
7762
- ...NO_TEXT_BODY_EXTRAS,
7763
- blocks
7764
- };
7765
- }
7766
- function walkShapeTreeChildren(children, parentTransform, context, slideRels, pkg, out) {
7767
- for (const node of children) {
7768
- if (node.type !== "element") continue;
7769
- if (node.tag === "p:sp") {
7770
- const shape = readSpShape(node, context, slideRels, parentTransform);
7771
- if (shape !== void 0) out.push(shape);
7772
- } else if (node.tag === "p:pic") {
7773
- const shape = readPicShape(node, context, slideRels, pkg, parentTransform);
7774
- if (shape !== void 0) out.push(shape);
7775
- } else if (node.tag === "p:graphicFrame") {
7776
- const shape = readGraphicFrameShape(node, context, slideRels, parentTransform);
7777
- if (shape !== void 0) out.push(shape);
7778
- } else if (node.tag === "p:grpSp") {
7779
- const grpSpPr = (0, ooxml_js.childrenWithTag)(node, "p:grpSpPr")[0];
7780
- const composed = composeGroupTransform(readGroupXfrm(grpSpPr === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(grpSpPr, "a:xfrm")[0]), parentTransform);
7781
- walkShapeTreeChildren(node.children, composed, context, slideRels, pkg, out);
7782
- }
7783
- }
7784
- }
7785
- function composeGroupTransform(own, parent) {
7786
- if (own === void 0) return;
7787
- if (parent === void 0) return own;
7788
- const absolute = applyGroupTransform(parent, {
7789
- xPt: own.offXPt,
7790
- yPt: own.offYPt,
7791
- widthPt: own.extWidthPt,
7792
- heightPt: own.extHeightPt
7793
- });
7794
- return {
7795
- ...own,
7796
- offXPt: absolute.xPt,
7797
- offYPt: absolute.yPt,
7798
- extWidthPt: absolute.widthPt,
7799
- extHeightPt: absolute.heightPt
7800
- };
7801
- }
7802
- const NOTES_SLIDE_REL_SUFFIX = "/notesSlide";
7803
- function readNotes(pkg, slidePath) {
7804
- let notesPath;
7805
- for (const rel of (0, ooxml_js.resolveRelationships)(pkg, slidePath).values()) if (rel.type.endsWith(NOTES_SLIDE_REL_SUFFIX)) {
7806
- notesPath = rel.target;
7807
- break;
7808
- }
7809
- if (notesPath === void 0) return "";
7810
- const notesRoot = (0, ooxml_js.rootElement)(pkg.parts[notesPath]);
7811
- if (notesRoot === void 0) return "";
7812
- const bodyShape = (0, ooxml_js.elementsWithTag)([notesRoot], "p:sp").find((shape) => {
7813
- const key = readPlaceholderKey(shape);
7814
- return key !== void 0 && (key.type === void 0 || key.type === "body");
7815
- });
7816
- if (bodyShape !== void 0) {
7817
- const txBody = (0, ooxml_js.childrenWithTag)(bodyShape, "p:txBody")[0];
7818
- if (txBody !== void 0) return (0, ooxml_js.elementsWithTag)(txBody.children, "a:t").map(ooxml_js.textContent).join("");
7819
- }
7820
- return (0, ooxml_js.elementsWithTag)([notesRoot], "a:t").map(ooxml_js.textContent).join("");
7821
- }
7822
- function readSlide(pkg, slidePath, size) {
7823
- const slideRoot = (0, ooxml_js.rootElement)(pkg.parts[slidePath]);
7824
- const context = resolveSlideInheritance(pkg, slidePath);
7825
- const slideRels = (0, ooxml_js.resolveRelationships)(pkg, slidePath);
7826
- const cSld = slideRoot === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(slideRoot, "p:cSld")[0];
7827
- const spTree = cSld === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(cSld, "p:spTree")[0];
7828
- const shapes = [];
7829
- if (spTree !== void 0) walkShapeTreeChildren(spTree.children, void 0, context, slideRels, pkg, shapes);
7830
- return {
7831
- size,
7832
- shapes,
7833
- notes: readNotes(pkg, slidePath)
7834
- };
7835
- }
7836
6635
  function readPptxContent(pkg) {
7837
- const presentationRoot = (0, ooxml_js.rootElement)(pkg.parts[PRESENTATION_PATH]);
7838
- const size = readSlideSize(presentationRoot);
7839
- const slides = readSlidePathsInOrder(pkg, presentationRoot).map((slidePath) => readSlide(pkg, slidePath, size));
6636
+ const pptxDoc = (0, ooxml_js.readPptx)(pkg);
7840
6637
  return {
7841
6638
  kind: "presentation",
7842
6639
  formatVersion: 1,
7843
- metadata: readCoreProperties(pkg),
7844
- slides
6640
+ metadata: { ...pptxDoc.metadata },
6641
+ slides: pptxDoc.slides
7845
6642
  };
7846
6643
  }
7847
6644
  //#endregion
@@ -8069,7 +6866,7 @@ function toStyledRuns(runs, fontScale = 1) {
8069
6866
  text: run.text,
8070
6867
  font: runFont(run),
8071
6868
  sizePt: (run.sizePt ?? 18) * fontScale,
8072
- color: run.color ?? COLOR_BLACK,
6869
+ color: run.color ?? ooxml_js.COLOR_BLACK,
8073
6870
  underline: run.underline,
8074
6871
  hyperlink: run.hyperlink
8075
6872
  }));
@@ -8080,7 +6877,7 @@ function effectiveStyledRuns(runs, fontScale = 1) {
8080
6877
  text: "",
8081
6878
  font: DEFAULT_LAYOUT_FONT,
8082
6879
  sizePt: 18 * fontScale,
8083
- color: COLOR_BLACK
6880
+ color: ooxml_js.COLOR_BLACK
8084
6881
  }];
8085
6882
  }
8086
6883
  function lineNaturalHeightPt(line, measurer, fallback) {
@@ -8954,7 +7751,12 @@ Object.defineProperty(exports, "BinaryPartSchema", {
8954
7751
  return ooxml_js.BinaryPartSchema;
8955
7752
  }
8956
7753
  });
8957
- exports.COLOR_BLACK = COLOR_BLACK;
7754
+ Object.defineProperty(exports, "COLOR_BLACK", {
7755
+ enumerable: true,
7756
+ get: function() {
7757
+ return ooxml_js.COLOR_BLACK;
7758
+ }
7759
+ });
8958
7760
  exports.CONTENT_FORMAT_VERSION = CONTENT_FORMAT_VERSION;
8959
7761
  Object.defineProperty(exports, "CommentSchema", {
8960
7762
  enumerable: true,
@@ -9008,8 +7810,18 @@ exports.DocxTableCell = DocxTableCell;
9008
7810
  exports.DocxTableRow = DocxTableRow;
9009
7811
  exports.LAYOUT_FORMAT_VERSION = LAYOUT_FORMAT_VERSION;
9010
7812
  exports.NOOP_DIAGNOSTIC_SINK = NOOP_DIAGNOSTIC_SINK;
9011
- exports.PAGE_SIZE_A4 = PAGE_SIZE_A4;
9012
- exports.PAGE_SIZE_LETTER = PAGE_SIZE_LETTER;
7813
+ Object.defineProperty(exports, "PAGE_SIZE_A4", {
7814
+ enumerable: true,
7815
+ get: function() {
7816
+ return ooxml_js.PAGE_SIZE_A4;
7817
+ }
7818
+ });
7819
+ Object.defineProperty(exports, "PAGE_SIZE_LETTER", {
7820
+ enumerable: true,
7821
+ get: function() {
7822
+ return ooxml_js.PAGE_SIZE_LETTER;
7823
+ }
7824
+ });
9013
7825
  Object.defineProperty(exports, "PackageSchema", {
9014
7826
  enumerable: true,
9015
7827
  get: function() {
@@ -9029,8 +7841,18 @@ exports.PptxBytesSchema = PptxBytesSchema;
9029
7841
  exports.PptxEditor = PptxEditor;
9030
7842
  exports.PptxShape = PptxShape;
9031
7843
  exports.PptxSlide = PptxSlide;
9032
- exports.SLIDE_SIZE_STANDARD = SLIDE_SIZE_STANDARD;
9033
- exports.SLIDE_SIZE_WIDESCREEN = SLIDE_SIZE_WIDESCREEN;
7844
+ Object.defineProperty(exports, "SLIDE_SIZE_STANDARD", {
7845
+ enumerable: true,
7846
+ get: function() {
7847
+ return ooxml_js.SLIDE_SIZE_STANDARD;
7848
+ }
7849
+ });
7850
+ Object.defineProperty(exports, "SLIDE_SIZE_WIDESCREEN", {
7851
+ enumerable: true,
7852
+ get: function() {
7853
+ return ooxml_js.SLIDE_SIZE_WIDESCREEN;
7854
+ }
7855
+ });
9034
7856
  Object.defineProperty(exports, "XmlCdataSchema", {
9035
7857
  enumerable: true,
9036
7858
  get: function() {
@@ -9223,7 +8045,12 @@ Object.defineProperty(exports, "resolveRelationships", {
9223
8045
  return ooxml_js.resolveRelationships;
9224
8046
  }
9225
8047
  });
9226
- exports.rgbHexToColor = rgbHexToColor;
8048
+ Object.defineProperty(exports, "rgbHexToColor", {
8049
+ enumerable: true,
8050
+ get: function() {
8051
+ return ooxml_js.rgbHexToColor;
8052
+ }
8053
+ });
9227
8054
  Object.defineProperty(exports, "rootElement", {
9228
8055
  enumerable: true,
9229
8056
  get: function() {