@json-to-office/core-docx 6.8.0 → 6.8.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.
@@ -3764,7 +3764,9 @@ function createDocxJsRenderer() {
3764
3764
  function buildDocument(ir, resources = /* @__PURE__ */ new Map()) {
3765
3765
  return new Document({
3766
3766
  styles: emitStyles(ir.styles),
3767
- sections: ir.sections.map((section2) => sectionOptions(section2, resources)),
3767
+ sections: ir.sections.map(
3768
+ (section2, index) => sectionOptions(section2, resources, index === ir.sections.length - 1)
3769
+ ),
3768
3770
  ...coreProperties(ir),
3769
3771
  features: {
3770
3772
  updateFields: ir.settings.updateFields,
@@ -3920,7 +3922,7 @@ function collectImagePlacements(ir) {
3920
3922
  }
3921
3923
  return placements;
3922
3924
  }
3923
- function sectionOptions(section2, resources) {
3925
+ function sectionOptions(section2, resources, closesDocument = false) {
3924
3926
  const { page, columns } = section2.properties;
3925
3927
  const options = {
3926
3928
  properties: {
@@ -3959,7 +3961,7 @@ function sectionOptions(section2, resources) {
3959
3961
  }
3960
3962
  } : {}
3961
3963
  },
3962
- children: sectionChildren(section2, resources)
3964
+ children: sectionChildren(section2, resources, closesDocument)
3963
3965
  };
3964
3966
  const headers = chromeSlots(section2.headers, Header, resources);
3965
3967
  if (headers) options.headers = headers;
@@ -3981,12 +3983,13 @@ function chromeSlots(set, Part, resources) {
3981
3983
  function partChildren(part, resources) {
3982
3984
  return part.children.map((block2) => emitBlock(block2, resources));
3983
3985
  }
3984
- function sectionChildren(section2, resources) {
3986
+ function sectionChildren(section2, resources, closesDocument = false) {
3985
3987
  const blocks = section2.children.map((block2) => emitBlock(block2, resources));
3986
3988
  const bookmark = section2.bookmark;
3987
- if (!bookmark) return blocks;
3989
+ const endsInFrame = closesDocument && lastBlockIsFrame(section2);
3990
+ if (!bookmark && !endsInFrame) return blocks;
3988
3991
  const out = [...blocks];
3989
- if (bookmark.opens) {
3992
+ if (bookmark?.opens) {
3990
3993
  const start = new BookmarkStart2(bookmark.name, bookmark.id);
3991
3994
  const first = out[0];
3992
3995
  if (first instanceof Paragraph2) {
@@ -3995,20 +3998,26 @@ function sectionChildren(section2, resources) {
3995
3998
  out.unshift(anchorParagraph(start));
3996
3999
  }
3997
4000
  }
3998
- if (bookmark.closes) {
4001
+ if (bookmark?.closes) {
3999
4002
  const end = new BookmarkEnd2(bookmark.id);
4000
4003
  const last = out[out.length - 1];
4001
- if (last instanceof Paragraph2) {
4004
+ if (last instanceof Paragraph2 && !endsInFrame) {
4002
4005
  last.addChildElement(end);
4003
4006
  } else {
4004
4007
  out.push(anchorParagraph(end));
4005
4008
  }
4009
+ } else if (endsInFrame) {
4010
+ out.push(anchorParagraph());
4006
4011
  }
4007
4012
  return out;
4008
4013
  }
4014
+ function lastBlockIsFrame(section2) {
4015
+ const last = section2.children[section2.children.length - 1];
4016
+ return last?.kind === "paragraph" && last.frame !== void 0;
4017
+ }
4009
4018
  function anchorParagraph(anchor) {
4010
4019
  return new Paragraph2({
4011
- children: [anchor],
4020
+ children: anchor ? [anchor] : [],
4012
4021
  spacing: { before: 0, after: 0, line: 20, lineRule: LineRuleType2.EXACT }
4013
4022
  });
4014
4023
  }
@@ -4827,7 +4836,7 @@ function borders2(value) {
4827
4836
  }
4828
4837
  return out;
4829
4838
  }
4830
- function section(value, ctx) {
4839
+ function section(value, ctx, closesDocument = false) {
4831
4840
  const { page, columns } = value.properties;
4832
4841
  return {
4833
4842
  properties: {
@@ -4879,7 +4888,7 @@ function section(value, ctx) {
4879
4888
  }
4880
4889
  } : {}
4881
4890
  },
4882
- children: sectionChildren2(value, ctx),
4891
+ children: sectionChildren2(value, ctx, closesDocument),
4883
4892
  ...value.headers ? { headers: headerFooterSet(value.headers, ctx) } : {},
4884
4893
  ...value.footers ? { footers: headerFooterSet(value.footers, ctx) } : {}
4885
4894
  };
@@ -4892,8 +4901,16 @@ function headerFooterSet(set, ctx) {
4892
4901
  }
4893
4902
  return out;
4894
4903
  }
4895
- function sectionChildren2(value, ctx) {
4904
+ function sectionChildren2(value, ctx, closesDocument = false) {
4896
4905
  const blocks = value.children.map((child) => block(child, ctx));
4906
+ const last = value.children[value.children.length - 1];
4907
+ if (closesDocument && last?.kind === "paragraph" && last.frame !== void 0)
4908
+ blocks.push({
4909
+ paragraph: {
4910
+ children: [],
4911
+ spacing: { before: 0, after: 0, line: 20, lineRule: "exact" }
4912
+ }
4913
+ });
4897
4914
  const bookmark = value.bookmark;
4898
4915
  if (!bookmark) return blocks;
4899
4916
  return [
@@ -5062,7 +5079,9 @@ async function buildDocumentOptions(ir, charts = [], svgRasterFallback) {
5062
5079
  };
5063
5080
  return {
5064
5081
  styles: emitStyles2(ir.styles),
5065
- sections: ir.sections.map((value) => section(value, ctx)),
5082
+ sections: ir.sections.map(
5083
+ (value, index) => section(value, ctx, index === ir.sections.length - 1)
5084
+ ),
5066
5085
  ...coreProperties2(ir),
5067
5086
  features: {
5068
5087
  updateFields: ir.settings.updateFields,