@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.
package/dist/index.js CHANGED
@@ -3792,7 +3792,9 @@ function createDocxJsRenderer() {
3792
3792
  function buildDocument(ir, resources = /* @__PURE__ */ new Map()) {
3793
3793
  return new Document({
3794
3794
  styles: emitStyles(ir.styles),
3795
- sections: ir.sections.map((section2) => sectionOptions(section2, resources)),
3795
+ sections: ir.sections.map(
3796
+ (section2, index) => sectionOptions(section2, resources, index === ir.sections.length - 1)
3797
+ ),
3796
3798
  ...coreProperties(ir),
3797
3799
  features: {
3798
3800
  updateFields: ir.settings.updateFields,
@@ -3948,7 +3950,7 @@ function collectImagePlacements(ir) {
3948
3950
  }
3949
3951
  return placements;
3950
3952
  }
3951
- function sectionOptions(section2, resources) {
3953
+ function sectionOptions(section2, resources, closesDocument = false) {
3952
3954
  const { page, columns } = section2.properties;
3953
3955
  const options = {
3954
3956
  properties: {
@@ -3987,7 +3989,7 @@ function sectionOptions(section2, resources) {
3987
3989
  }
3988
3990
  } : {}
3989
3991
  },
3990
- children: sectionChildren(section2, resources)
3992
+ children: sectionChildren(section2, resources, closesDocument)
3991
3993
  };
3992
3994
  const headers = chromeSlots(section2.headers, Header, resources);
3993
3995
  if (headers) options.headers = headers;
@@ -4009,12 +4011,13 @@ function chromeSlots(set, Part, resources) {
4009
4011
  function partChildren(part, resources) {
4010
4012
  return part.children.map((block2) => emitBlock(block2, resources));
4011
4013
  }
4012
- function sectionChildren(section2, resources) {
4014
+ function sectionChildren(section2, resources, closesDocument = false) {
4013
4015
  const blocks = section2.children.map((block2) => emitBlock(block2, resources));
4014
4016
  const bookmark = section2.bookmark;
4015
- if (!bookmark) return blocks;
4017
+ const endsInFrame = closesDocument && lastBlockIsFrame(section2);
4018
+ if (!bookmark && !endsInFrame) return blocks;
4016
4019
  const out = [...blocks];
4017
- if (bookmark.opens) {
4020
+ if (bookmark?.opens) {
4018
4021
  const start = new BookmarkStart2(bookmark.name, bookmark.id);
4019
4022
  const first = out[0];
4020
4023
  if (first instanceof Paragraph2) {
@@ -4023,20 +4026,26 @@ function sectionChildren(section2, resources) {
4023
4026
  out.unshift(anchorParagraph(start));
4024
4027
  }
4025
4028
  }
4026
- if (bookmark.closes) {
4029
+ if (bookmark?.closes) {
4027
4030
  const end = new BookmarkEnd2(bookmark.id);
4028
4031
  const last = out[out.length - 1];
4029
- if (last instanceof Paragraph2) {
4032
+ if (last instanceof Paragraph2 && !endsInFrame) {
4030
4033
  last.addChildElement(end);
4031
4034
  } else {
4032
4035
  out.push(anchorParagraph(end));
4033
4036
  }
4037
+ } else if (endsInFrame) {
4038
+ out.push(anchorParagraph());
4034
4039
  }
4035
4040
  return out;
4036
4041
  }
4042
+ function lastBlockIsFrame(section2) {
4043
+ const last = section2.children[section2.children.length - 1];
4044
+ return last?.kind === "paragraph" && last.frame !== void 0;
4045
+ }
4037
4046
  function anchorParagraph(anchor) {
4038
4047
  return new Paragraph2({
4039
- children: [anchor],
4048
+ children: anchor ? [anchor] : [],
4040
4049
  spacing: { before: 0, after: 0, line: 20, lineRule: LineRuleType2.EXACT }
4041
4050
  });
4042
4051
  }
@@ -4855,7 +4864,7 @@ function borders2(value) {
4855
4864
  }
4856
4865
  return out;
4857
4866
  }
4858
- function section(value, ctx) {
4867
+ function section(value, ctx, closesDocument = false) {
4859
4868
  const { page, columns } = value.properties;
4860
4869
  return {
4861
4870
  properties: {
@@ -4907,7 +4916,7 @@ function section(value, ctx) {
4907
4916
  }
4908
4917
  } : {}
4909
4918
  },
4910
- children: sectionChildren2(value, ctx),
4919
+ children: sectionChildren2(value, ctx, closesDocument),
4911
4920
  ...value.headers ? { headers: headerFooterSet(value.headers, ctx) } : {},
4912
4921
  ...value.footers ? { footers: headerFooterSet(value.footers, ctx) } : {}
4913
4922
  };
@@ -4920,8 +4929,16 @@ function headerFooterSet(set, ctx) {
4920
4929
  }
4921
4930
  return out;
4922
4931
  }
4923
- function sectionChildren2(value, ctx) {
4932
+ function sectionChildren2(value, ctx, closesDocument = false) {
4924
4933
  const blocks = value.children.map((child) => block(child, ctx));
4934
+ const last = value.children[value.children.length - 1];
4935
+ if (closesDocument && last?.kind === "paragraph" && last.frame !== void 0)
4936
+ blocks.push({
4937
+ paragraph: {
4938
+ children: [],
4939
+ spacing: { before: 0, after: 0, line: 20, lineRule: "exact" }
4940
+ }
4941
+ });
4925
4942
  const bookmark = value.bookmark;
4926
4943
  if (!bookmark) return blocks;
4927
4944
  return [
@@ -5090,7 +5107,9 @@ async function buildDocumentOptions(ir, charts = [], svgRasterFallback) {
5090
5107
  };
5091
5108
  return {
5092
5109
  styles: emitStyles2(ir.styles),
5093
- sections: ir.sections.map((value) => section(value, ctx)),
5110
+ sections: ir.sections.map(
5111
+ (value, index) => section(value, ctx, index === ir.sections.length - 1)
5112
+ ),
5094
5113
  ...coreProperties2(ir),
5095
5114
  features: {
5096
5115
  updateFields: ir.settings.updateFields,