ooxml.js 3.0.1 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,7 @@ const require_typed_shared_drawingml = require("../shared/drawingml.cjs");
8
8
  const require_typed_shared_source_path = require("../shared/source-path.cjs");
9
9
  const require_typed_docx_styles = require("./styles.cjs");
10
10
  const require_typed_docx_numbering = require("./numbering.cjs");
11
+ const require_typed_docx_constructs = require("./constructs.cjs");
11
12
  let zod = require("zod");
12
13
  let document_schema_js = require("document-schema.js");
13
14
  //#region src/typed/docx/read.ts
@@ -87,13 +88,13 @@ function readRunText(run) {
87
88
  let text = "";
88
89
  for (const child of run.children) {
89
90
  if (child.type !== "element") continue;
90
- if (child.tag === "w:t") text += require_typed_util.textContent(child);
91
+ if (child.tag === "w:t" || child.tag === "w:delText") text += require_typed_util.textContent(child);
91
92
  else if (child.tag === "w:tab") text += " ";
92
93
  else if (child.tag === "w:br" || child.tag === "w:cr") text += "\n";
93
94
  }
94
95
  return text;
95
96
  }
96
- function readDrawingImage(drawing, rels, pkg) {
97
+ function readDrawingImage(drawing, ctx) {
97
98
  const container = require_typed_util.childrenWithTag(drawing, "wp:inline")[0] ?? require_typed_util.childrenWithTag(drawing, "wp:anchor")[0];
98
99
  if (container === void 0) return;
99
100
  const extent = require_typed_util.childrenWithTag(container, "wp:extent")[0];
@@ -104,8 +105,8 @@ function readDrawingImage(drawing, rels, pkg) {
104
105
  const altText = docPr === void 0 ? void 0 : require_typed_util.attr(docPr, "descr") ?? require_typed_util.attr(docPr, "title");
105
106
  const blip = require_typed_util.elementsWithTag(container.children, "a:blip")[0];
106
107
  const rId = blip === void 0 ? void 0 : require_typed_util.attr(blip, "r:embed");
107
- const rel = rId === void 0 ? void 0 : rels.get(rId);
108
- const mediaPart = rel === void 0 ? void 0 : pkg.parts[rel.target];
108
+ const rel = rId === void 0 ? void 0 : ctx.rels.get(rId);
109
+ const mediaPart = rel === void 0 ? void 0 : ctx.pkg.parts[rel.target];
109
110
  if (mediaPart?.kind !== "binary") return;
110
111
  const bytes = require_util_base64.base64ToBytes(mediaPart.base64);
111
112
  const format = require_image_sniff.sniffImageFormat(bytes);
@@ -117,26 +118,26 @@ function readDrawingImage(drawing, rels, pkg) {
117
118
  widthPt: require_typed_shared_units.emuToPt(Number(cx)),
118
119
  heightPt: require_typed_shared_units.emuToPt(Number(cy))
119
120
  };
120
- if (altText !== void 0) image.altText = altText;
121
+ if (altText !== void 0) image.altText = require_typed_util.decodeEntities(altText);
121
122
  return image;
122
123
  }
123
- function collectDrawings(nodes, out) {
124
+ function collectDrawings(nodes, carryDeletions, out) {
124
125
  for (const node of nodes) {
125
126
  if (node.type !== "element") continue;
126
- if (node.tag === "w:del") continue;
127
+ if (!carryDeletions && (node.tag === "w:del" || node.tag === "w:moveFrom")) continue;
127
128
  if (node.tag === "w:drawing") {
128
129
  out.push(node);
129
130
  continue;
130
131
  }
131
- collectDrawings(node.children, out);
132
+ collectDrawings(node.children, carryDeletions, out);
132
133
  }
133
134
  }
134
- function readParagraphImages(paragraph, rels, pkg) {
135
+ function readParagraphImages(paragraph, ctx, carryDeletions) {
135
136
  const drawings = [];
136
- collectDrawings(paragraph.children, drawings);
137
+ collectDrawings(paragraph.children, carryDeletions, drawings);
137
138
  const images = [];
138
139
  for (const drawing of drawings) {
139
- const image = readDrawingImage(drawing, rels, pkg);
140
+ const image = readDrawingImage(drawing, ctx);
140
141
  if (image !== void 0) images.push(image);
141
142
  }
142
143
  return images;
@@ -154,23 +155,22 @@ function readRun(run, paragraph, context) {
154
155
  color: props.color
155
156
  };
156
157
  }
157
- function readParagraphRuns(paragraph, context, rels) {
158
+ function readParagraphRuns(paragraph, ctx, carryDeletions) {
158
159
  const runs = [];
159
160
  let fieldState = "none";
160
161
  function walk(nodes, hyperlinkTarget) {
161
162
  for (const node of nodes) {
162
163
  if (node.type !== "element") continue;
163
164
  if (node.tag === "w:r") {
164
- const fldChar = require_typed_util.childrenWithTag(node, "w:fldChar")[0];
165
- if (fldChar !== void 0) {
166
- const type = require_typed_util.attr(fldChar, "w:fldCharType");
165
+ const type = require_typed_docx_constructs.fieldCharType(node);
166
+ if (type !== void 0) {
167
167
  if (type === "begin") fieldState = "code";
168
168
  else if (type === "separate") fieldState = "result";
169
169
  else if (type === "end") fieldState = "none";
170
170
  continue;
171
171
  }
172
172
  if (fieldState === "code") continue;
173
- const run = readRun(node, paragraph, context);
173
+ const run = readRun(node, paragraph, ctx.styles);
174
174
  runs.push(hyperlinkTarget === void 0 ? run : {
175
175
  ...run,
176
176
  hyperlink: hyperlinkTarget
@@ -178,21 +178,27 @@ function readParagraphRuns(paragraph, context, rels) {
178
178
  } else if (node.tag === "w:fldSimple") walk(node.children, hyperlinkTarget);
179
179
  else if (node.tag === "w:hyperlink") {
180
180
  const rId = require_typed_util.attr(node, "r:id");
181
- const target = rId === void 0 ? void 0 : rels.get(rId)?.target;
181
+ const target = rId === void 0 ? void 0 : ctx.rels.get(rId)?.target;
182
182
  walk(node.children, target ?? hyperlinkTarget);
183
- } else if (node.tag === "w:ins") walk(node.children, hyperlinkTarget);
183
+ } else if (node.tag === "w:ins" || node.tag === "w:moveTo") walk(node.children, hyperlinkTarget);
184
+ else if (node.tag === "w:del" || node.tag === "w:moveFrom") {
185
+ if (carryDeletions) walk(node.children, hyperlinkTarget);
186
+ } else if (node.tag === "w:sdt") {
187
+ const sdtContent = require_typed_util.childrenWithTag(node, "w:sdtContent")[0];
188
+ if (sdtContent !== void 0) walk(sdtContent.children, hyperlinkTarget);
189
+ }
184
190
  }
185
191
  }
186
192
  walk(paragraph.children, void 0);
187
193
  return runs;
188
194
  }
189
- function readParagraph(paragraph, context, rels) {
195
+ function readParagraph(paragraph, ctx, carryDeletions) {
190
196
  const pPr = require_typed_util.childrenWithTag(paragraph, "w:pPr")[0];
191
197
  const pStyleEl = pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "w:pStyle")[0];
192
- const props = require_typed_docx_styles.resolveParagraphProperties(paragraph, context);
198
+ const props = require_typed_docx_styles.resolveParagraphProperties(paragraph, ctx.styles);
193
199
  return {
194
200
  kind: "paragraph",
195
- runs: readParagraphRuns(paragraph, context, rels),
201
+ runs: readParagraphRuns(paragraph, ctx, carryDeletions),
196
202
  styleId: pStyleEl === void 0 ? void 0 : require_typed_util.attr(pStyleEl, "w:val"),
197
203
  headingLevel: props.outlineLvl === void 0 ? void 0 : (0, document_schema_js.clampHeadingLevel)(props.outlineLvl + 1),
198
204
  alignment: props.alignment,
@@ -253,7 +259,7 @@ function readCellBorders(tcPr) {
253
259
  if (bottom !== void 0) borders.bottom = bottom;
254
260
  return Object.keys(borders).length === 0 ? void 0 : borders;
255
261
  }
256
- function readRawCell(tc, context, rels, pkg) {
262
+ function readRawCell(tc, ctx, carryDeletions) {
257
263
  const tcPr = require_typed_util.childrenWithTag(tc, "w:tcPr")[0];
258
264
  const gridSpanEl = tcPr === void 0 ? void 0 : require_typed_util.childrenWithTag(tcPr, "w:gridSpan")[0];
259
265
  const gridSpanVal = gridSpanEl === void 0 ? void 0 : require_typed_util.attr(gridSpanEl, "w:val");
@@ -264,7 +270,7 @@ function readRawCell(tc, context, rels, pkg) {
264
270
  isVMergeContinuation: vMergeVal === "continue",
265
271
  background: readCellShading(tcPr),
266
272
  borders: readCellBorders(tcPr),
267
- blocks: readBodyBlocks(tc.children, context, rels, pkg)
273
+ blocks: readBlockScope(tc.children, ctx, carryDeletions)
268
274
  };
269
275
  }
270
276
  function readRowHeightPt(tr) {
@@ -274,11 +280,11 @@ function readRowHeightPt(tr) {
274
280
  const val = trHeight === void 0 ? void 0 : require_typed_util.attr(trHeight, "w:val");
275
281
  return val === void 0 ? void 0 : require_typed_shared_units.twipsToPt(Number(val));
276
282
  }
277
- function readTable(tbl, context, rels, pkg) {
283
+ function readTable(tbl, ctx, carryDeletions) {
278
284
  const tblGrid = require_typed_util.childrenWithTag(tbl, "w:tblGrid")[0];
279
285
  const columnWidthsPt = tblGrid === void 0 ? [] : require_typed_util.childrenWithTag(tblGrid, "w:gridCol").map((col) => require_typed_shared_units.twipsToPt(Number(require_typed_util.attr(col, "w:w") ?? "0")));
280
286
  const trs = require_typed_util.childrenWithTag(tbl, "w:tr");
281
- const rawRows = trs.map((tr) => require_typed_util.childrenWithTag(tr, "w:tc").map((tc) => readRawCell(tc, context, rels, pkg)));
287
+ const rawRows = trs.map((tr) => require_typed_util.childrenWithTag(tr, "w:tc").map((tc) => readRawCell(tc, ctx, carryDeletions)));
282
288
  const rowColumnIndices = rawRows.map((row) => {
283
289
  const indices = [];
284
290
  let col = 0;
@@ -313,63 +319,254 @@ function readTable(tbl, context, rels, pkg) {
313
319
  }))
314
320
  };
315
321
  }
316
- function readBodyBlocks(nodes, context, rels, pkg) {
317
- const blocks = [];
322
+ function newFlowState() {
323
+ return {
324
+ blocks: [],
325
+ extents: [],
326
+ sectionBreaks: [],
327
+ bookmarkEvents: [],
328
+ openFields: [],
329
+ order: 0
330
+ };
331
+ }
332
+ function resolveBookmarkExtents(events) {
333
+ const byId = /* @__PURE__ */ new Map();
334
+ for (const event of events) {
335
+ const existing = byId.get(event.id);
336
+ if (existing === void 0) byId.set(event.id, [event]);
337
+ else existing.push(event);
338
+ }
339
+ const extents = [];
340
+ for (const halves of byId.values()) {
341
+ const start = halves.filter((half) => half.kind === "start");
342
+ const end = halves.filter((half) => half.kind === "end");
343
+ const open = start[0];
344
+ const close = end[0];
345
+ if (start.length !== 1 || end.length !== 1 || open === void 0 || close === void 0) continue;
346
+ if (open.name === void 0 || !open.qualified || !close.qualified || close.index < open.index) continue;
347
+ extents.push({
348
+ startIndex: open.index,
349
+ endIndex: close.index,
350
+ order: open.order,
351
+ descriptor: require_typed_docx_constructs.bookmarkAnchorDescriptor(open.name)
352
+ });
353
+ }
354
+ return extents;
355
+ }
356
+ function wholeParagraphTrackedChange(index) {
357
+ const content = require_typed_docx_constructs.contentBearingChildren(index);
358
+ const first = content[0];
359
+ if (first === void 0) return;
360
+ const change = require_typed_docx_constructs.PROVENANCE_CHANGE_BY_TAG.get(first.tag);
361
+ if (change === void 0 || !content.every((child) => child.tag === first.tag)) return;
362
+ return {
363
+ element: first,
364
+ change
365
+ };
366
+ }
367
+ function recordParagraphBookmarks(index, paragraphIndex, endIndex, state) {
368
+ index.elements.forEach((element, position) => {
369
+ if (element.tag !== "w:bookmarkStart" && element.tag !== "w:bookmarkEnd") return;
370
+ const id = require_typed_util.attr(element, "w:id");
371
+ if (id === void 0) return;
372
+ const leading = index.firstContentIndex === -1 || position < index.firstContentIndex;
373
+ const trailing = index.lastContentIndex === -1 || position > index.lastContentIndex;
374
+ if (element.tag === "w:bookmarkStart") {
375
+ const name = require_typed_util.attr(element, "w:name");
376
+ state.bookmarkEvents.push({
377
+ id,
378
+ name: name === void 0 ? void 0 : require_typed_util.decodeEntities(name),
379
+ kind: "start",
380
+ index: leading ? paragraphIndex : endIndex,
381
+ qualified: leading || trailing,
382
+ order: state.order++
383
+ });
384
+ return;
385
+ }
386
+ state.bookmarkEvents.push({
387
+ id,
388
+ name: void 0,
389
+ kind: "end",
390
+ index: trailing ? endIndex : paragraphIndex,
391
+ qualified: leading || trailing,
392
+ order: state.order++
393
+ });
394
+ });
395
+ }
396
+ function scanParagraphFields(index, paragraphIndex, endIndex, state) {
397
+ const content = require_typed_docx_constructs.contentBearingChildren(index);
398
+ content.forEach((child, position) => {
399
+ if (child.tag === "w:fldSimple") {
400
+ if (content.length === 1) state.extents.push({
401
+ startIndex: paragraphIndex,
402
+ endIndex,
403
+ order: state.order++,
404
+ descriptor: {
405
+ kind: "field",
406
+ instruction: require_typed_util.decodeEntities(require_typed_util.attr(child, "w:instr") ?? "")
407
+ }
408
+ });
409
+ return;
410
+ }
411
+ if (child.tag !== "w:r") return;
412
+ const type = require_typed_docx_constructs.fieldCharType(child);
413
+ if (type === "begin") {
414
+ state.openFields.push({
415
+ instruction: "",
416
+ inCode: true,
417
+ startIndex: paragraphIndex,
418
+ qualifiedStart: position === 0,
419
+ order: state.order++
420
+ });
421
+ return;
422
+ }
423
+ if (type === "separate") {
424
+ const open = state.openFields[state.openFields.length - 1];
425
+ if (open !== void 0) open.inCode = false;
426
+ return;
427
+ }
428
+ if (type === "end") {
429
+ const open = state.openFields.pop();
430
+ if (open !== void 0 && open.qualifiedStart && position === content.length - 1) state.extents.push({
431
+ startIndex: open.startIndex,
432
+ endIndex,
433
+ order: open.order,
434
+ descriptor: {
435
+ kind: "field",
436
+ instruction: open.instruction
437
+ }
438
+ });
439
+ return;
440
+ }
441
+ const open = state.openFields[state.openFields.length - 1];
442
+ if (open?.inCode === true) open.instruction += require_typed_docx_constructs.runInstructionText(child);
443
+ });
444
+ }
445
+ function collectParagraph(paragraph, ctx, state, carryDeletions) {
446
+ const index = require_typed_docx_constructs.indexParagraphContent(paragraph);
447
+ const tracked = wholeParagraphTrackedChange(index);
448
+ const paragraphDeleted = carryDeletions || tracked !== void 0 && require_typed_docx_constructs.isDeletedChange(tracked.change);
449
+ if (hasPageBreakBefore(paragraph)) state.blocks.push({ kind: "pageBreak" });
450
+ const paragraphIndex = state.blocks.length;
451
+ state.blocks.push(readParagraph(paragraph, ctx, paragraphDeleted));
452
+ state.blocks.push(...readParagraphImages(paragraph, ctx, paragraphDeleted));
453
+ const endIndex = state.blocks.length;
454
+ if (tracked !== void 0) state.extents.push({
455
+ startIndex: paragraphIndex,
456
+ endIndex,
457
+ order: state.order++,
458
+ descriptor: require_typed_docx_constructs.readProvenanceDescriptor(tracked.element, tracked.change)
459
+ });
460
+ recordParagraphBookmarks(index, paragraphIndex, endIndex, state);
461
+ scanParagraphFields(index, paragraphIndex, endIndex, state);
462
+ const pPr = require_typed_util.childrenWithTag(paragraph, "w:pPr")[0];
463
+ const sectPr = pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "w:sectPr")[0];
464
+ if (sectPr !== void 0) state.sectionBreaks.push({
465
+ index: state.blocks.length,
466
+ sectPr
467
+ });
468
+ }
469
+ function collectFlowNodes(nodes, ctx, state, carryDeletions) {
318
470
  for (const node of nodes) {
319
471
  if (node.type !== "element") continue;
320
472
  if (node.tag === "w:p") {
321
- if (hasPageBreakBefore(node)) blocks.push({ kind: "pageBreak" });
322
- blocks.push(readParagraph(node, context, rels));
323
- blocks.push(...readParagraphImages(node, rels, pkg));
324
- } else if (node.tag === "w:tbl") blocks.push(readTable(node, context, rels, pkg));
325
- else if (node.tag === "w:sdt") {
473
+ collectParagraph(node, ctx, state, carryDeletions);
474
+ continue;
475
+ }
476
+ if (node.tag === "w:tbl") {
477
+ state.blocks.push(readTable(node, ctx, carryDeletions));
478
+ continue;
479
+ }
480
+ if (node.tag === "w:sdt") {
481
+ const order = state.order++;
482
+ const startIndex = state.blocks.length;
326
483
  const sdtContent = require_typed_util.childrenWithTag(node, "w:sdtContent")[0];
327
- if (sdtContent !== void 0) blocks.push(...readBodyBlocks(sdtContent.children, context, rels, pkg));
328
- } else if (node.tag === "w:ins") blocks.push(...readBodyBlocks(node.children, context, rels, pkg));
329
- else if (node.tag === "mc:AlternateContent") {
484
+ if (sdtContent !== void 0) collectFlowNodes(sdtContent.children, ctx, state, carryDeletions);
485
+ state.extents.push({
486
+ startIndex,
487
+ endIndex: state.blocks.length,
488
+ order,
489
+ descriptor: require_typed_docx_constructs.readContentControlDescriptor(node)
490
+ });
491
+ continue;
492
+ }
493
+ const change = require_typed_docx_constructs.PROVENANCE_CHANGE_BY_TAG.get(node.tag);
494
+ if (change !== void 0) {
495
+ const order = state.order++;
496
+ const startIndex = state.blocks.length;
497
+ collectFlowNodes(node.children, ctx, state, carryDeletions || require_typed_docx_constructs.isDeletedChange(change));
498
+ state.extents.push({
499
+ startIndex,
500
+ endIndex: state.blocks.length,
501
+ order,
502
+ descriptor: require_typed_docx_constructs.readProvenanceDescriptor(node, change)
503
+ });
504
+ continue;
505
+ }
506
+ if (node.tag === "mc:AlternateContent") {
330
507
  const target = require_typed_util.childrenWithTag(node, "mc:Fallback")[0] ?? require_typed_util.childrenWithTag(node, "mc:Choice")[0];
331
- if (target !== void 0) blocks.push(...readBodyBlocks(target.children, context, rels, pkg));
508
+ if (target !== void 0) collectFlowNodes(target.children, ctx, state, carryDeletions);
509
+ continue;
332
510
  }
333
- }
334
- return blocks;
335
- }
336
- function readSections(body, context, rels, pkg) {
337
- const sections = [];
338
- let currentBlocks = [];
339
- for (const node of body.children) {
340
- if (node.type !== "element") continue;
341
- if (node.tag === "w:sectPr") {
342
- sections.push({
343
- pageSize: readPageSize(node),
344
- margins: readMargins(node),
345
- blocks: currentBlocks
511
+ if (node.tag === "w:bookmarkStart") {
512
+ const id = require_typed_util.attr(node, "w:id");
513
+ const name = require_typed_util.attr(node, "w:name");
514
+ if (id !== void 0) state.bookmarkEvents.push({
515
+ id,
516
+ name: name === void 0 ? void 0 : require_typed_util.decodeEntities(name),
517
+ kind: "start",
518
+ index: state.blocks.length,
519
+ qualified: true,
520
+ order: state.order++
346
521
  });
347
- currentBlocks = [];
348
522
  continue;
349
523
  }
350
- if (node.tag === "w:p") {
351
- const pPr = require_typed_util.childrenWithTag(node, "w:pPr")[0];
352
- const sectPr = pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "w:sectPr")[0];
353
- if (hasPageBreakBefore(node)) currentBlocks.push({ kind: "pageBreak" });
354
- currentBlocks.push(readParagraph(node, context, rels));
355
- currentBlocks.push(...readParagraphImages(node, rels, pkg));
356
- if (sectPr !== void 0) {
357
- sections.push({
358
- pageSize: readPageSize(sectPr),
359
- margins: readMargins(sectPr),
360
- blocks: currentBlocks
361
- });
362
- currentBlocks = [];
363
- }
524
+ if (node.tag === "w:bookmarkEnd") {
525
+ const id = require_typed_util.attr(node, "w:id");
526
+ if (id !== void 0) state.bookmarkEvents.push({
527
+ id,
528
+ name: void 0,
529
+ kind: "end",
530
+ index: state.blocks.length,
531
+ qualified: true,
532
+ order: state.order++
533
+ });
364
534
  continue;
365
535
  }
366
- currentBlocks.push(...readBodyBlocks([node], context, rels, pkg));
536
+ if (node.tag === "w:sectPr") state.sectionBreaks.push({
537
+ index: state.blocks.length,
538
+ sectPr: node
539
+ });
367
540
  }
368
- if (currentBlocks.length > 0 || sections.length === 0) sections.push({
369
- pageSize: document_schema_js.PAGE_SIZE_LETTER,
370
- margins: DEFAULT_MARGINS,
371
- blocks: currentBlocks
372
- });
541
+ }
542
+ function readBlockScope(nodes, ctx, carryDeletions) {
543
+ const state = newFlowState();
544
+ collectFlowNodes(nodes, ctx, state, carryDeletions);
545
+ return require_typed_docx_constructs.insertConstructMarkers(state.blocks, [...state.extents, ...resolveBookmarkExtents(state.bookmarkEvents)]);
546
+ }
547
+ function readSections(body, ctx) {
548
+ const state = newFlowState();
549
+ collectFlowNodes(body.children, ctx, state, false);
550
+ const extents = [...state.extents, ...resolveBookmarkExtents(state.bookmarkEvents)];
551
+ function sliceSection(pageSize, margins, from, to) {
552
+ const contained = extents.filter((extent) => extent.startIndex >= from && extent.endIndex <= to).map((extent) => ({
553
+ ...extent,
554
+ startIndex: extent.startIndex - from,
555
+ endIndex: extent.endIndex - from
556
+ }));
557
+ return {
558
+ pageSize,
559
+ margins,
560
+ blocks: require_typed_docx_constructs.insertConstructMarkers(state.blocks.slice(from, to), contained)
561
+ };
562
+ }
563
+ const sections = [];
564
+ let from = 0;
565
+ for (const sectionBreak of state.sectionBreaks) {
566
+ sections.push(sliceSection(readPageSize(sectionBreak.sectPr), readMargins(sectionBreak.sectPr), from, sectionBreak.index));
567
+ from = sectionBreak.index;
568
+ }
569
+ if (from < state.blocks.length || sections.length === 0) sections.push(sliceSection(document_schema_js.PAGE_SIZE_LETTER, DEFAULT_MARGINS, from, state.blocks.length));
373
570
  sections.forEach((section, sectionIndex) => require_typed_shared_source_path.assignSourcePaths(section.blocks, `sections[${sectionIndex}]`));
374
571
  return sections;
375
572
  }
@@ -424,13 +621,17 @@ function readDocx(pkg) {
424
621
  const body = require_typed_util.childrenWithTag(documentRoot, "w:body")[0];
425
622
  if (body === void 0) throw new Error(`readDocx: ${DOCUMENT_PART_PATH} has no w:body element`);
426
623
  const docRels = require_typed_util.resolveRelationships(pkg, DOCUMENT_PART_PATH);
427
- const context = {
428
- stylesRoot: require_typed_util.rootElement(pkg.parts[STYLES_PART_PATH]),
429
- theme: readDocumentTheme(pkg, docRels)
624
+ const ctx = {
625
+ styles: {
626
+ stylesRoot: require_typed_util.rootElement(pkg.parts[STYLES_PART_PATH]),
627
+ theme: readDocumentTheme(pkg, docRels)
628
+ },
629
+ rels: docRels,
630
+ pkg
430
631
  };
431
632
  return {
432
633
  metadata: require_typed_shared_metadata.readCoreProperties(pkg),
433
- sections: readSections(body, context, docRels, pkg),
634
+ sections: readSections(body, ctx),
434
635
  comments: readComments(pkg),
435
636
  footnotes: readFootnotes(pkg),
436
637
  headers: readHeaderFooterText(pkg, "word/header"),