@json-to-office/core-docx 6.6.0 → 6.8.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.
@@ -13755,6 +13755,55 @@ function textSizeFact(node, props, path3, typography, role) {
13755
13755
  ...size.authored && { sizePath: `${path3}/props/font/size` }
13756
13756
  };
13757
13757
  }
13758
+ function statisticSizeFacts(props, path3, typography) {
13759
+ const named = STATISTIC_SIZE_POINTS[String(props.size)];
13760
+ const styled = (id) => finiteNumber(asRecord2(typography.styles[id])?.size);
13761
+ const numberPoints = named ?? STATISTIC_SIZE_POINTS.medium;
13762
+ const painted = props.size === "small" || props.size === "large" ? numberPoints : styled("StatisticNumber") ?? numberPoints;
13763
+ const present = (value) => value !== void 0 && value !== null && String(value).trim() !== "";
13764
+ const facts = [];
13765
+ const add = (suffix, role, fontSizePt) => facts.push({
13766
+ id: `docx:text-size:${path3}:${suffix}`,
13767
+ kind: "docx/text-size",
13768
+ path: path3,
13769
+ role,
13770
+ fontSizePt,
13771
+ authored: false
13772
+ });
13773
+ if (present(props.number)) add("number", "statistic", painted);
13774
+ if (present(props.unit) || present(props.trend) || present(props.trendValue))
13775
+ add(
13776
+ "suffix",
13777
+ "statistic-suffix",
13778
+ Math.max(12, Math.round(numberPoints)) / 2
13779
+ );
13780
+ if (present(props.description))
13781
+ add(
13782
+ "description",
13783
+ "statistic-description",
13784
+ styled("StatisticDescription") ?? 10
13785
+ );
13786
+ return facts;
13787
+ }
13788
+ function tocSizeFacts(props, path3, typography) {
13789
+ const depth = asRecord2(props.depth);
13790
+ const from = finiteNumber(depth?.from) ?? 1;
13791
+ const to = finiteNumber(depth?.to) ?? 3;
13792
+ const facts = [];
13793
+ for (let level = from; level <= to; level++) {
13794
+ const size = finiteNumber(asRecord2(typography.styles[`TOC${level}`])?.size);
13795
+ if (size === void 0) continue;
13796
+ facts.push({
13797
+ id: `docx:text-size:${path3}:toc${level}`,
13798
+ kind: "docx/text-size",
13799
+ path: path3,
13800
+ role: `toc${level}`,
13801
+ fontSizePt: size,
13802
+ authored: false
13803
+ });
13804
+ }
13805
+ return facts;
13806
+ }
13758
13807
  function tableTextSizeFacts(props, authored, path3, typography, page) {
13759
13808
  const facts = [];
13760
13809
  const sizeOf = (holder) => finiteNumber(asRecord2(asRecord2(holder)?.font)?.size);
@@ -13968,6 +14017,16 @@ function prepareDocxQualityDocument(document, options = {}) {
13968
14017
  (value) => `#${resolveDesignColor2(value, visualColors)}`
13969
14018
  ) ?? SERIES_COLOR_TOKENS.filter((token) => paletteHexes[token] !== void 0);
13970
14019
  const authoredPropsAt = (pointer) => asRecord2(asRecord2(nodeAtPointer(context.document, pointer))?.props);
14020
+ const ownSize = (fact) => {
14021
+ if (!fact?.sizePath) return fact;
14022
+ const written = finiteNumber(
14023
+ asRecord2(authoredPropsAt(fact.path)?.font)?.size
14024
+ );
14025
+ if (written !== void 0) return fact;
14026
+ const inherited2 = { ...fact, authored: false };
14027
+ delete inherited2.sizePath;
14028
+ return inherited2;
14029
+ };
13971
14030
  const roleSizesPt = {};
13972
14031
  for (const key of Object.keys(typography.styles)) {
13973
14032
  const size = effectiveFontSize(
@@ -14121,10 +14180,22 @@ function prepareDocxQualityDocument(document, options = {}) {
14121
14180
  const fact = lineBoxFact(node, props, path3, typography, context.document);
14122
14181
  if (fact) addFact(fact);
14123
14182
  if (typeof props.text === "string" && props.text.trim() !== "") {
14124
- const fact2 = textSizeFact(node, props, path3, typography);
14183
+ const fact2 = ownSize(textSizeFact(node, props, path3, typography));
14125
14184
  if (fact2) addFact({ ...fact2, generated: authoredPath(path3) !== path3 });
14126
14185
  }
14127
14186
  }
14187
+ if (node.name === "list" && Array.isArray(props.items) && props.items.length > 0) {
14188
+ const fact = ownSize(textSizeFact(node, props, path3, typography, "list"));
14189
+ if (fact) addFact({ ...fact, generated: authoredPath(path3) !== path3 });
14190
+ }
14191
+ if (node.name === "statistic") {
14192
+ for (const fact of statisticSizeFacts(props, path3, typography))
14193
+ addFact({ ...fact, generated: authoredPath(path3) !== path3 });
14194
+ }
14195
+ if (node.name === "toc") {
14196
+ for (const fact of tocSizeFacts(props, path3, typography))
14197
+ addFact({ ...fact, generated: authoredPath(path3) !== path3 });
14198
+ }
14128
14199
  if (node.name === "image" || node.name === "visual") {
14129
14200
  for (const fact of svgTextFacts(props, path3)) addFact(fact);
14130
14201
  const drawn = drawnRatio(props);
@@ -14149,6 +14220,7 @@ function prepareDocxQualityDocument(document, options = {}) {
14149
14220
  kind: "docx/heading",
14150
14221
  path: `${path3}/props/level`,
14151
14222
  level,
14223
+ generated: authoredPath(path3) !== path3,
14152
14224
  keepNext: props.keepNext === true || props.keepNext === void 0 && styleKeepNext === true,
14153
14225
  ...previousHeadingLevel !== void 0 && {
14154
14226
  previousLevel: previousHeadingLevel
@@ -14189,7 +14261,10 @@ function prepareDocxQualityDocument(document, options = {}) {
14189
14261
  index,
14190
14262
  words: texts.filter((fact) => bodyRoles.has(fact.role)).reduce((total, fact) => total + wordsOf(fact.text), 0),
14191
14263
  exhibits: own.filter((fact) => exhibitKinds.has(fact.kind)).length,
14192
- headings: texts.filter((fact) => fact.role === "heading").length
14264
+ headings: texts.filter((fact) => fact.role === "heading").length,
14265
+ // Anything the reader sees on the section's own pages: a heading, a
14266
+ // contents field, body copy. Running heads repeat onto any page.
14267
+ rendersText: texts.some((fact) => fact.role !== "chrome")
14193
14268
  });
14194
14269
  if (hasColumnsComponent(rec)) return;
14195
14270
  const page = pageBox(
@@ -14265,10 +14340,15 @@ function isCaptioned(facts, image) {
14265
14340
  return facts.some((fact) => {
14266
14341
  if (fact.kind !== "docx/text") return false;
14267
14342
  const text = fact;
14268
- const near = siblingOf(text.path) === siblingOf(image) || text.path.startsWith(`${image}/`) || image.startsWith(`${text.path}/`);
14343
+ const node = text.path.replace(/\/props(?:\/.*)?$/, "");
14344
+ const beside = siblingOf(node) === siblingOf(image) && Math.abs(indexIn(node) - indexIn(image)) === 1;
14345
+ const near = beside || text.path.startsWith(`${image}/`) || image.startsWith(`${node}/`);
14269
14346
  return near && (text.role === "caption" || CAPTION_LABEL.test(text.text));
14270
14347
  });
14271
14348
  }
14349
+ function indexIn(pointer) {
14350
+ return Number(pointer.slice(pointer.lastIndexOf("/") + 1));
14351
+ }
14272
14352
  function siblingOf(pointer) {
14273
14353
  return pointer.slice(0, pointer.lastIndexOf("/"));
14274
14354
  }