@json-to-office/core-docx 7.3.1 → 7.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2930,7 +2930,7 @@ var init_chartText = __esm({
2930
2930
  });
2931
2931
 
2932
2932
  // src/renderers/docxjs/docxSubpath.ts
2933
- function docxSubpath(specifier, component, importer) {
2933
+ function docxSubpath(specifier, component, importer, since = "9.8.0") {
2934
2934
  let module;
2935
2935
  let failure;
2936
2936
  let loading;
@@ -2954,7 +2954,7 @@ function docxSubpath(specifier, component, importer) {
2954
2954
  const { reason } = failure;
2955
2955
  const detail = reason instanceof Error ? reason.message : String(reason);
2956
2956
  throw new Error(
2957
- `The docx \`${component}\` component needs docx 9.8.0 or later: the \`${specifier}\` entry could not be loaded (${detail})`
2957
+ `The docx \`${component}\` component needs docx ${since} or later: the \`${specifier}\` entry could not be loaded (${detail})`
2958
2958
  );
2959
2959
  }
2960
2960
  throw new Error(
@@ -3551,8 +3551,19 @@ function emitBlock(block2, resources = /* @__PURE__ */ new Map()) {
3551
3551
  return assertNever2(block2, "DocxIrBlock");
3552
3552
  }
3553
3553
  }
3554
+ function emitOutsideBody(emit) {
3555
+ const was = outsideBody;
3556
+ outsideBody = true;
3557
+ try {
3558
+ return emit();
3559
+ } finally {
3560
+ outsideBody = was;
3561
+ }
3562
+ }
3554
3563
  function emitToc(block2) {
3555
- return new ThemedTableOfContents(block2.alias ?? "Table of Contents", {
3564
+ const cached = outsideBody && block2.cachedEntries?.length;
3565
+ const Field = cached ? ThemedTableOfContents : TableOfContents;
3566
+ return new Field(block2.alias ?? "Table of Contents", {
3556
3567
  ...block2.hyperlink !== void 0 ? { hyperlink: block2.hyperlink } : {},
3557
3568
  ...block2.headingRange ? {
3558
3569
  headingStyleRange: `${block2.headingRange.from}-${block2.headingRange.to}`
@@ -3565,7 +3576,7 @@ function emitToc(block2) {
3565
3576
  pageNumbersEntryLevelsRange: block2.omitPageNumbersForLevels.map((range) => `${range.from}-${range.to}`).join(",")
3566
3577
  } : {},
3567
3578
  ...block2.entrySeparator !== void 0 ? { entryAndPageNumberSeparator: block2.entrySeparator } : {},
3568
- ...block2.cachedEntries?.length ? {
3579
+ ...cached ? {
3569
3580
  cachedEntries: block2.cachedEntries.map((entry) => ({
3570
3581
  title: entry.text,
3571
3582
  level: entry.level
@@ -3688,7 +3699,7 @@ function emitBorder(border3) {
3688
3699
  ...border3.spacePoints !== void 0 ? { space: border3.spacePoints } : {}
3689
3700
  };
3690
3701
  }
3691
- var ALIGNMENT2, PAGE_FIELDS, isSequenceField, WRAP_TYPE, ThemedTableOfContents, VERTICAL_ALIGN, TABLE_ANCHOR, HORIZONTAL_POSITION, VERTICAL_POSITION;
3702
+ var ALIGNMENT2, PAGE_FIELDS, isSequenceField, WRAP_TYPE, ThemedTableOfContents, outsideBody, VERTICAL_ALIGN, TABLE_ANCHOR, HORIZONTAL_POSITION, VERTICAL_POSITION;
3692
3703
  var init_emit = __esm({
3693
3704
  "src/renderers/docxjs/emit.ts"() {
3694
3705
  "use strict";
@@ -3714,6 +3725,7 @@ var init_emit = __esm({
3714
3725
  Object.defineProperty(ThemedTableOfContents.prototype, "getTabStopsForLevel", {
3715
3726
  value: () => []
3716
3727
  });
3728
+ outsideBody = false;
3717
3729
  VERTICAL_ALIGN = {
3718
3730
  top: VerticalAlign.TOP,
3719
3731
  center: VerticalAlign.CENTER,
@@ -3901,6 +3913,318 @@ var init_styles2 = __esm({
3901
3913
  }
3902
3914
  });
3903
3915
 
3916
+ // src/renderers/docxjs/pageNumbers.ts
3917
+ import {
3918
+ Tab as Tab2
3919
+ } from "docx";
3920
+ function needsPageNumbers(ir) {
3921
+ const seen = /* @__PURE__ */ new Set();
3922
+ const visit = (value) => {
3923
+ if (typeof value !== "object" || value === null) return false;
3924
+ if (ArrayBuffer.isView(value) || seen.has(value)) return false;
3925
+ seen.add(value);
3926
+ if (Array.isArray(value)) return value.some(visit);
3927
+ if (value.kind === "toc") return true;
3928
+ return Object.values(value).some(visit);
3929
+ };
3930
+ return ir.sections.some((section2) => visit(section2.children));
3931
+ }
3932
+ async function createPageNumberEstimator(ir) {
3933
+ await layout.load();
3934
+ const cached = cachedContentsEntries(ir);
3935
+ const separators = contentsSeparators(ir);
3936
+ const estimate = layout.loaded() ? layout.get().estimatePageNumbersWith({ guess: true }) : void 0;
3937
+ return (body, context) => {
3938
+ renumberContentsBookmarks(body);
3939
+ restoreEntryNumbers(body, cached, separators);
3940
+ dropContentsEntryTabs(body);
3941
+ writeSeparatorTabs(body, context);
3942
+ endContentsInLastEntry(body);
3943
+ if (!estimate) {
3944
+ unavailable(
3945
+ `the \`docx/layout\` entry could not be loaded (${failureOf(() => layout.get())})`
3946
+ );
3947
+ return { bookmarks: /* @__PURE__ */ new Map() };
3948
+ }
3949
+ try {
3950
+ const estimated = estimate(body, context);
3951
+ if (complete(estimated)) clearUpdateFields(context.file);
3952
+ return estimated;
3953
+ } catch (error) {
3954
+ unavailable(error instanceof Error ? error.message : String(error));
3955
+ return { bookmarks: /* @__PURE__ */ new Map() };
3956
+ }
3957
+ };
3958
+ }
3959
+ function unavailable(reason) {
3960
+ reportWarning(
3961
+ "toc",
3962
+ PAGE_NUMBERS_UNAVAILABLE,
3963
+ `The table of contents is written without page numbers: laying the pages out failed (${reason}). Word fills them in when it updates the fields on open.`
3964
+ );
3965
+ }
3966
+ function failureOf(get) {
3967
+ try {
3968
+ get();
3969
+ return "unknown";
3970
+ } catch (error) {
3971
+ return error instanceof Error ? error.message : String(error);
3972
+ }
3973
+ }
3974
+ function complete(estimated) {
3975
+ return estimated.pageCount !== void 0 && (estimated.guesses ?? []).length === 0;
3976
+ }
3977
+ function clearUpdateFields(file) {
3978
+ const root = file?.Settings?.root;
3979
+ if (!root) return;
3980
+ const at = root.findIndex(
3981
+ (element) => element?.rootKey === "w:updateFields"
3982
+ );
3983
+ if (at >= 0) root.splice(at, 1);
3984
+ }
3985
+ function isContentsField(sdt) {
3986
+ let found = false;
3987
+ const visit = (element) => {
3988
+ if (found) return;
3989
+ if (nameOf(element) === "w:instrText") {
3990
+ found = childrenOf(element).some(
3991
+ (child) => typeof child === "string" && /^\s*TOC\b/.test(child)
3992
+ );
3993
+ return;
3994
+ }
3995
+ childrenOf(element).forEach(visit);
3996
+ };
3997
+ visit(sdt);
3998
+ return found;
3999
+ }
4000
+ function contentsFields(body) {
4001
+ const found = [];
4002
+ const visit = (element) => {
4003
+ const name = nameOf(element);
4004
+ if (name === void 0 || name === "_attr") return;
4005
+ if (name === "w:sdt" && isContentsField(element)) {
4006
+ found.push(element);
4007
+ return;
4008
+ }
4009
+ childrenOf(element).forEach(visit);
4010
+ };
4011
+ visit(body);
4012
+ return found;
4013
+ }
4014
+ function entryParagraphs(field) {
4015
+ return childrenOf(field).filter((content) => nameOf(content) === "w:sdtContent").flatMap(
4016
+ (content) => childrenOf(content).filter((paragraph2) => nameOf(paragraph2) === "w:p")
4017
+ );
4018
+ }
4019
+ function dropContentsEntryTabs(body) {
4020
+ for (const field of contentsFields(body)) {
4021
+ for (const paragraph2 of entryParagraphs(field)) {
4022
+ for (const properties of childrenOf(paragraph2)) {
4023
+ if (nameOf(properties) !== "w:pPr") continue;
4024
+ properties["w:pPr"] = childrenOf(properties).filter(
4025
+ (child) => nameOf(child) !== "w:tabs"
4026
+ );
4027
+ }
4028
+ }
4029
+ }
4030
+ }
4031
+ function endContentsInLastEntry(body) {
4032
+ for (const field of contentsFields(body)) {
4033
+ for (const content of childrenOf(field)) {
4034
+ if (nameOf(content) !== "w:sdtContent") continue;
4035
+ const paragraphs = childrenOf(content);
4036
+ const last = paragraphs[paragraphs.length - 1];
4037
+ const entry = paragraphs[paragraphs.length - 2];
4038
+ if (nameOf(last) !== "w:p" || nameOf(entry) !== "w:p") continue;
4039
+ const runs = childrenOf(last);
4040
+ const onlyTheEnd = runs.length === 1 && nameOf(runs[0]) === "w:r" && childrenOf(runs[0]).every(
4041
+ (child) => nameOf(child) === "w:fldChar" && attributesOf(child)?.["w:fldCharType"] === "end"
4042
+ );
4043
+ const entries = paragraphs.filter(
4044
+ (paragraph2) => textNodes(paragraph2).length > 0
4045
+ );
4046
+ if (!onlyTheEnd || entries.length < 2 || textNodes(entry).length === 0)
4047
+ continue;
4048
+ childrenOf(entry).push(runs[0]);
4049
+ paragraphs.pop();
4050
+ }
4051
+ }
4052
+ }
4053
+ function writeSeparatorTabs(body, context) {
4054
+ const tab = () => new Tab2().prepForXml(context);
4055
+ const visit = (element) => {
4056
+ const name = nameOf(element);
4057
+ if (name === void 0 || name === "_attr") return;
4058
+ if (name === "w:r") {
4059
+ const children = childrenOf(element);
4060
+ children.forEach((child, index) => {
4061
+ if (nameOf(child) !== "w:t") return;
4062
+ const text = childrenOf(child).filter(
4063
+ (part) => typeof part === "string"
4064
+ );
4065
+ if (text.length === 1 && text[0] === " ") children[index] = tab();
4066
+ });
4067
+ return;
4068
+ }
4069
+ childrenOf(element).forEach(visit);
4070
+ };
4071
+ for (const field of contentsFields(body))
4072
+ entryParagraphs(field).forEach(visit);
4073
+ }
4074
+ function textNodes(element) {
4075
+ const name = nameOf(element);
4076
+ if (name === void 0 || name === "_attr" || name === "w:instrText")
4077
+ return [];
4078
+ const children = childrenOf(element);
4079
+ if (name === "w:t")
4080
+ return children.flatMap(
4081
+ (child, index) => typeof child === "string" ? [{ parent: children, index }] : []
4082
+ );
4083
+ return children.flatMap(textNodes);
4084
+ }
4085
+ function contentsSeparators(ir) {
4086
+ const separators = [];
4087
+ const visit = (value) => {
4088
+ if (typeof value !== "object" || value === null) return;
4089
+ if (ArrayBuffer.isView(value)) return;
4090
+ if (Array.isArray(value)) {
4091
+ value.forEach(visit);
4092
+ return;
4093
+ }
4094
+ if (value.kind === "toc") {
4095
+ separators.push(value.entrySeparator);
4096
+ return;
4097
+ }
4098
+ Object.values(value).forEach(visit);
4099
+ };
4100
+ for (const section2 of ir.sections) visit(section2.children);
4101
+ return separators;
4102
+ }
4103
+ function cachedContentsEntries(ir) {
4104
+ const fields = [];
4105
+ const visit = (value) => {
4106
+ if (typeof value !== "object" || value === null) return;
4107
+ if (ArrayBuffer.isView(value)) return;
4108
+ if (Array.isArray(value)) {
4109
+ value.forEach(visit);
4110
+ return;
4111
+ }
4112
+ if (value.kind === "toc") {
4113
+ const toc = value;
4114
+ fields.push(toc.cachedEntries?.map((entry) => entry.text));
4115
+ return;
4116
+ }
4117
+ Object.values(value).forEach(visit);
4118
+ };
4119
+ for (const section2 of ir.sections) visit(section2.children);
4120
+ return fields;
4121
+ }
4122
+ function restoreEntryNumbers(body, cached, separators = []) {
4123
+ contentsFields(body).forEach((field, index) => {
4124
+ const texts = cached[index];
4125
+ const paragraphs = entryParagraphs(field).filter(
4126
+ (paragraph2) => textNodes(paragraph2).length > 0
4127
+ );
4128
+ if (!texts || texts.length !== paragraphs.length) return;
4129
+ paragraphs.forEach((paragraph2, entry) => {
4130
+ const nodes = textNodes(paragraph2);
4131
+ let title = nodes.map(({ parent, index: at }) => parent[at]).join("");
4132
+ const separator = separators[index];
4133
+ if (separator && title.endsWith(separator))
4134
+ title = title.slice(0, -separator.length);
4135
+ const text = texts[entry];
4136
+ if (title === "" || text === title || !text.endsWith(title)) return;
4137
+ const [first] = nodes;
4138
+ first.parent[first.index] = text.slice(0, text.length - title.length) + first.parent[first.index];
4139
+ });
4140
+ });
4141
+ }
4142
+ function renumberContentsBookmarks(body) {
4143
+ const names = /* @__PURE__ */ new Map();
4144
+ const paragraphs = (element) => {
4145
+ const name = nameOf(element);
4146
+ if (name === void 0 || name === "_attr") return;
4147
+ if (name !== "w:p") {
4148
+ childrenOf(element).forEach(paragraphs);
4149
+ return;
4150
+ }
4151
+ const children = childrenOf(element);
4152
+ for (const start of children) {
4153
+ if (nameOf(start) !== "w:bookmarkStart") continue;
4154
+ const attributes = attributesOf(start);
4155
+ const old = attributes?.["w:name"];
4156
+ if (typeof old !== "string" || !CONTENTS_BOOKMARK.test(old)) continue;
4157
+ const ordinal = names.size + 1;
4158
+ const renamed2 = `_Toc${ordinal}`;
4159
+ const id = CONTENTS_BOOKMARK_ID_BASE + ordinal;
4160
+ names.set(old, renamed2);
4161
+ const oldId = attributes["w:id"];
4162
+ attributes["w:name"] = renamed2;
4163
+ attributes["w:id"] = id;
4164
+ const end = [...children].reverse().find(
4165
+ (child) => nameOf(child) === "w:bookmarkEnd" && String(attributesOf(child)?.["w:id"]) === String(oldId)
4166
+ );
4167
+ if (end) attributesOf(end)["w:id"] = id;
4168
+ }
4169
+ };
4170
+ paragraphs(body);
4171
+ if (names.size === 0) return;
4172
+ const references = (element) => {
4173
+ const name = nameOf(element);
4174
+ if (name === void 0) return;
4175
+ if (name === "w:hyperlink") {
4176
+ const attributes = attributesOf(element);
4177
+ const anchor = attributes?.["w:anchor"];
4178
+ if (typeof anchor === "string" && names.has(anchor))
4179
+ attributes["w:anchor"] = names.get(anchor);
4180
+ }
4181
+ if (name === "w:instrText") {
4182
+ const children = childrenOf(element);
4183
+ children.forEach((child, index) => {
4184
+ if (typeof child !== "string") return;
4185
+ children[index] = child.replace(
4186
+ /\b(PAGEREF\s+)(_Toc\d+)\b/g,
4187
+ (match, field, bookmark) => names.has(bookmark) ? `${field}${names.get(bookmark)}` : match
4188
+ );
4189
+ });
4190
+ element[name] = children;
4191
+ return;
4192
+ }
4193
+ if (name === "_attr") return;
4194
+ childrenOf(element).forEach(references);
4195
+ };
4196
+ references(body);
4197
+ }
4198
+ function attributesOf(element) {
4199
+ const attributes = childrenOf(element).find(
4200
+ (child) => nameOf(child) === "_attr"
4201
+ );
4202
+ return attributes?._attr;
4203
+ }
4204
+ var PAGE_NUMBERS_UNAVAILABLE, layout, nameOf, childrenOf, CONTENTS_BOOKMARK_ID_BASE, CONTENTS_BOOKMARK;
4205
+ var init_pageNumbers = __esm({
4206
+ "src/renderers/docxjs/pageNumbers.ts"() {
4207
+ "use strict";
4208
+ init_generationContext();
4209
+ init_docxSubpath();
4210
+ PAGE_NUMBERS_UNAVAILABLE = "W_DOCX_PAGE_NUMBERS_UNAVAILABLE";
4211
+ layout = docxSubpath(
4212
+ "docx/layout",
4213
+ "toc",
4214
+ () => import("docx/layout"),
4215
+ "9.9.0"
4216
+ );
4217
+ nameOf = (element) => typeof element === "object" && element !== null && !Array.isArray(element) ? Object.keys(element)[0] : void 0;
4218
+ childrenOf = (element) => {
4219
+ const name = nameOf(element);
4220
+ const content = name === void 0 ? void 0 : element[name];
4221
+ return Array.isArray(content) ? content : content === void 0 ? [] : [content];
4222
+ };
4223
+ CONTENTS_BOOKMARK_ID_BASE = 3e6;
4224
+ CONTENTS_BOOKMARK = /^_Toc\d+$/;
4225
+ }
4226
+ });
4227
+
3904
4228
  // src/utils/normalizeTextCase.ts
3905
4229
  function normalizeTextCase(zip) {
3906
4230
  let changed = false;
@@ -4682,7 +5006,8 @@ function createDocxJsRenderer() {
4682
5006
  )
4683
5007
  });
4684
5008
  }
4685
- const document = buildDocument(ir, resources);
5009
+ const pageNumbers = needsPageNumbers(ir) ? await createPageNumberEstimator(ir) : void 0;
5010
+ const document = buildDocument(ir, resources, pageNumbers);
4686
5011
  const packed = await Packer.toBuffer(document);
4687
5012
  const fixed = fixFloatingImageIdsInBuffer(packed);
4688
5013
  const repaired = markers ? repairDrawingGroupsInBuffer(fixed, markers) : fixed;
@@ -4700,13 +5025,12 @@ function createDocxJsRenderer() {
4700
5025
  }
4701
5026
  };
4702
5027
  }
4703
- function buildDocument(ir, resources = /* @__PURE__ */ new Map()) {
5028
+ function buildDocument(ir, resources = /* @__PURE__ */ new Map(), pageNumbers) {
4704
5029
  return new Document({
5030
+ ...pageNumbers ? { pageNumbers } : {},
4705
5031
  styles: emitStyles(ir.styles),
4706
5032
  ...ir.theme ? { theme: themeOptions(ir.theme) } : {},
4707
- sections: ir.sections.map(
4708
- (section2, index) => sectionOptions(section2, resources, index === ir.sections.length - 1)
4709
- ),
5033
+ sections: ir.sections.map((section2) => sectionOptions(section2, resources)),
4710
5034
  ...coreProperties(ir),
4711
5035
  features: {
4712
5036
  updateFields: ir.settings.updateFields,
@@ -4725,8 +5049,8 @@ function buildDocument(ir, resources = /* @__PURE__ */ new Map()) {
4725
5049
  author: comment.author,
4726
5050
  ...comment.initials ? { initials: comment.initials } : {},
4727
5051
  date: new Date(comment.date),
4728
- children: comment.children.map(
4729
- (block2) => emitBlock(block2, resources)
5052
+ children: emitOutsideBody(
5053
+ () => comment.children.map((block2) => emitBlock(block2, resources))
4730
5054
  ),
4731
5055
  ...comment.parentId !== void 0 ? { parentId: comment.parentId } : {},
4732
5056
  ...comment.resolved !== void 0 ? { resolved: comment.resolved } : {}
@@ -4754,8 +5078,8 @@ function noteBodies(notes, resources) {
4754
5078
  const bodies = {};
4755
5079
  for (const note of notes) {
4756
5080
  bodies[String(note.id)] = {
4757
- children: note.children.map(
4758
- (block2) => emitBlock(block2, resources)
5081
+ children: emitOutsideBody(
5082
+ () => note.children.map((block2) => emitBlock(block2, resources))
4759
5083
  )
4760
5084
  };
4761
5085
  }
@@ -4916,7 +5240,7 @@ function collectImagePlacements(ir) {
4916
5240
  }
4917
5241
  return { placements, drawingGroups };
4918
5242
  }
4919
- function sectionOptions(section2, resources, closesDocument = false) {
5243
+ function sectionOptions(section2, resources) {
4920
5244
  const { page, columns } = section2.properties;
4921
5245
  const options = {
4922
5246
  properties: {
@@ -4955,7 +5279,7 @@ function sectionOptions(section2, resources, closesDocument = false) {
4955
5279
  }
4956
5280
  } : {}
4957
5281
  },
4958
- children: sectionChildren(section2, resources, closesDocument)
5282
+ children: sectionChildren(section2, resources)
4959
5283
  };
4960
5284
  const headers = chromeSlots(section2.headers, Header, resources);
4961
5285
  if (headers) options.headers = headers;
@@ -4969,7 +5293,9 @@ function chromeSlots(set, Part, resources) {
4969
5293
  for (const slot of ["default", "first", "even"]) {
4970
5294
  const part = set[slot];
4971
5295
  if (part) {
4972
- out[slot] = new Part({ children: partChildren(part, resources) });
5296
+ out[slot] = new Part({
5297
+ children: emitOutsideBody(() => partChildren(part, resources))
5298
+ });
4973
5299
  }
4974
5300
  }
4975
5301
  return Object.keys(out).length > 0 ? out : void 0;
@@ -4977,10 +5303,10 @@ function chromeSlots(set, Part, resources) {
4977
5303
  function partChildren(part, resources) {
4978
5304
  return part.children.map((block2) => emitBlock(block2, resources));
4979
5305
  }
4980
- function sectionChildren(section2, resources, closesDocument = false) {
5306
+ function sectionChildren(section2, resources) {
4981
5307
  const blocks = section2.children.map((block2) => emitBlock(block2, resources));
4982
5308
  const bookmark = section2.bookmark;
4983
- const endsInFrame = closesDocument && lastBlockIsFrame(section2);
5309
+ const endsInFrame = lastBlockIsFrame(section2);
4984
5310
  if (!bookmark && !endsInFrame) return blocks;
4985
5311
  const out = [...blocks];
4986
5312
  if (bookmark?.opens) {
@@ -5033,6 +5359,7 @@ var init_docxjs = __esm({
5033
5359
  "use strict";
5034
5360
  init_styles2();
5035
5361
  init_charts();
5362
+ init_pageNumbers();
5036
5363
  init_imageUtils();
5037
5364
  init_packageDocument();
5038
5365
  init_fixFloatingImageIds();
@@ -6219,7 +6546,7 @@ function sectionChildren2(value, ctx, closesDocument = false) {
6219
6546
  const blocks = value.children.map((child) => block(child, ctx));
6220
6547
  const last = value.children[value.children.length - 1];
6221
6548
  const bookmark = value.bookmark;
6222
- if (bookmark?.closes && last?.kind !== "paragraph" || closesDocument && last?.kind === "paragraph" && last.frame !== void 0)
6549
+ if (bookmark?.closes && last?.kind !== "paragraph" || last?.kind === "paragraph" && last.frame !== void 0 && (closesDocument || !bookmark?.closes))
6223
6550
  blocks.push({
6224
6551
  paragraph: {
6225
6552
  children: [],
@@ -10300,9 +10627,9 @@ function schemeHex(token, theme) {
10300
10627
  // src/ir/compiler.ts
10301
10628
  var CONTENT_BOOKMARK_ID_BASE = 2e6;
10302
10629
  var SINGLE_LINE_TWIPS = 240;
10303
- function compileDocument(structure, layout, warnings = [], images = /* @__PURE__ */ new Map(), options = {}) {
10630
+ function compileDocument(structure, layout2, warnings = [], images = /* @__PURE__ */ new Map(), options = {}) {
10304
10631
  const styles = createDocumentStyles(structure.theme, structure.language);
10305
- const outline = collectOutline(layout, warnings);
10632
+ const outline = collectOutline(layout2, warnings);
10306
10633
  const ctx = {
10307
10634
  theme: structure.theme,
10308
10635
  themeName: structure.themeName,
@@ -10337,10 +10664,10 @@ function compileDocument(structure, layout, warnings = [], images = /* @__PURE__
10337
10664
  };
10338
10665
  ctx.features.require("paragraphs", "sections");
10339
10666
  ctx.features.require("styles", "styles");
10340
- if (layout.sections.length > 1) ctx.features.require("sections", "sections");
10341
- const ordinals = computeSectionOrdinals(layout.sections);
10342
- const chrome = resolveSectionChrome(layout.sections);
10343
- const sections = layout.sections.map(
10667
+ if (layout2.sections.length > 1) ctx.features.require("sections", "sections");
10668
+ const ordinals = computeSectionOrdinals(layout2.sections);
10669
+ const chrome = resolveSectionChrome(layout2.sections);
10670
+ const sections = layout2.sections.map(
10344
10671
  (section2, index) => compileSection(section2, index, ordinals[index], chrome[index], ctx)
10345
10672
  );
10346
10673
  if (ctx.hasResolvedComment && !ctx.comments.some((comment) => comment.parentId !== void 0)) {
@@ -10418,9 +10745,9 @@ function separateFromTables(blocks, bodyAfterTwips) {
10418
10745
  }
10419
10746
  }
10420
10747
  }
10421
- function collectOutline(layout, warnings) {
10748
+ function collectOutline(layout2, warnings) {
10422
10749
  try {
10423
- return collectDocumentOutline(layout.sections);
10750
+ return collectDocumentOutline(layout2.sections);
10424
10751
  } catch (error) {
10425
10752
  warnings.push({
10426
10753
  component: "document",
@@ -12966,13 +13293,19 @@ function compileTableRow(row, columnTwips, spacing, baseStyle, scope) {
12966
13293
  ...scope.cantSplit !== void 0 ? { cantSplit: scope.cantSplit } : {}
12967
13294
  };
12968
13295
  }
13296
+ var NORMAL_TABLE_CELL_MARGINS = {
13297
+ topTwips: 0,
13298
+ bottomTwips: 0,
13299
+ leftTwips: 108,
13300
+ rightTwips: 108
13301
+ };
12969
13302
  function compileTableCell(cell, columnTwips, spacing, baseStyle, keepNext, partScope, rowRevision, markRevision) {
12970
- const margins = !cell.missing && cell.padding ? {
13303
+ const margins = cell.missing ? void 0 : cell.padding ? {
12971
13304
  topTwips: pointsToTwips2(cell.padding.top),
12972
13305
  bottomTwips: pointsToTwips2(cell.padding.bottom),
12973
13306
  leftTwips: pointsToTwips2(cell.padding.left),
12974
13307
  rightTwips: pointsToTwips2(cell.padding.right)
12975
- } : void 0;
13308
+ } : NORMAL_TABLE_CELL_MARGINS;
12976
13309
  const scope = {
12977
13310
  ...partScope,
12978
13311
  measureTwips: cellMeasureTwips(columnTwips, margins)
@@ -13477,8 +13810,8 @@ function hasPageBreak(component) {
13477
13810
  }
13478
13811
  return false;
13479
13812
  }
13480
- function getColumnSettings(layout) {
13481
- switch (layout) {
13813
+ function getColumnSettings(layout2) {
13814
+ switch (layout2) {
13482
13815
  case "multi-column":
13483
13816
  return {
13484
13817
  count: 2,
@@ -15921,19 +16254,19 @@ async function compileDocumentScoped(document, options, warnings) {
15921
16254
  context.themeName,
15922
16255
  resolveGenerationDate(options)
15923
16256
  );
15924
- const layout = applyLayout(
16257
+ const layout2 = applyLayout(
15925
16258
  structure.sections,
15926
16259
  context.theme,
15927
16260
  context.themeName
15928
16261
  );
15929
16262
  const images = await loadImageResources(
15930
- layout.sections.flatMap((section2) => [
16263
+ layout2.sections.flatMap((section2) => [
15931
16264
  ...section2.components,
15932
16265
  ...Array.isArray(section2.header) ? section2.header : [],
15933
16266
  ...Array.isArray(section2.footer) ? section2.footer : []
15934
16267
  ])
15935
16268
  );
15936
- const compiled = compileDocument(structure, layout, warnings, images, {
16269
+ const compiled = compileDocument(structure, layout2, warnings, images, {
15937
16270
  // A caller that collects nothing still needs to hear about a dropped
15938
16271
  // value, so warnings go to the console when there is no collector.
15939
16272
  echoWarnings: options.warnings === void 0