@json-to-office/core-docx 4.1.0 → 4.3.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
@@ -9673,6 +9673,11 @@ function compileList(component, scope, referencePrefix = "list", explicitLevels)
9673
9673
  const props = component.props ?? {};
9674
9674
  const items = props.items ?? [];
9675
9675
  if (items.length === 0) return [];
9676
+ const base = runFormatting3(
9677
+ props.font ?? {},
9678
+ props,
9679
+ ctx
9680
+ );
9676
9681
  const notes = createNoteBinding(props.footnotes, props.endnotes, ctx);
9677
9682
  const reference = declareNumbering(
9678
9683
  props,
@@ -9708,17 +9713,21 @@ function compileList(component, scope, referencePrefix = "list", explicitLevels)
9708
9713
  paragraphNode(
9709
9714
  { ctx, path: itemPath, id: `${scope.id}:i${index}` },
9710
9715
  revision === void 0 ? parseInline(text, {
9711
- base: {},
9716
+ base,
9712
9717
  hyperlinks: true,
9713
9718
  ...notes ? { resolveNote: notes.resolve } : {},
9714
9719
  resolvePlaceholder: placeholderResolver(ctx),
9715
9720
  resolveCrossReference: crossReferenceResolver(ctx, itemPath)
9716
- }) : compileRevision(revision, {}, ctx),
9721
+ }) : compileRevision(revision, base, ctx),
9717
9722
  {
9718
9723
  styleId: "Normal",
9719
9724
  formatting: {
9720
9725
  alignment: compileAlignment(props.alignment) ?? "left",
9721
- spacing: itemSpacing(props.spacing, index, items.length)
9726
+ spacing: itemSpacing(props.spacing, index, items.length),
9727
+ // Every item carries the flags, not just the first: keeping a list
9728
+ // with what introduces it means keeping it whole.
9729
+ ...props.keepNext !== void 0 ? { keepNext: props.keepNext } : {},
9730
+ ...props.keepLines !== void 0 ? { keepLines: props.keepLines } : {}
9722
9731
  },
9723
9732
  ...commentIds && index === firstRendered ? { commentOpen: commentIds } : {},
9724
9733
  ...commentIds && index === lastRendered ? { commentClose: commentIds } : {},
@@ -12398,6 +12407,12 @@ init_defaults();
12398
12407
  init_widthUtils();
12399
12408
 
12400
12409
  // src/quality/text-inventory.ts
12410
+ function tocDepth(depth) {
12411
+ const range = asRecord(depth) ?? {};
12412
+ const from = typeof range.from === "number" ? range.from : 1;
12413
+ const to = typeof range.to === "number" ? range.to : 3;
12414
+ return { from, to };
12415
+ }
12401
12416
  function asRecord(value) {
12402
12417
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
12403
12418
  }
@@ -12418,10 +12433,14 @@ function collectDocxTextInventory(children, basePath = "/children") {
12418
12433
  path: path4,
12419
12434
  text,
12420
12435
  role,
12421
- order: entries.length,
12436
+ // Renumbered once the walk is done: contents entries are spliced in.
12437
+ order: -1,
12422
12438
  ...extra
12423
12439
  });
12424
12440
  };
12441
+ const headings = [];
12442
+ const tocs = [];
12443
+ let sectionCount = 0;
12425
12444
  const visitCell = (cell, path4, role, inherited) => {
12426
12445
  const cellRole = inherited.repeats ? "chrome" : role;
12427
12446
  const extra = inherited.repeats ? { repeats: true } : {};
@@ -12436,11 +12455,13 @@ function collectDocxTextInventory(children, basePath = "/children") {
12436
12455
  add(`${path4}/content`, rec.content, cellRole, extra);
12437
12456
  else {
12438
12457
  const inner = asRecord(rec.content);
12439
- if (inner) visitNode(inner, `${path4}/content`, inherited);
12458
+ if (inner)
12459
+ visitNode(inner, `${path4}/content`, { ...inherited, inCell: true });
12440
12460
  }
12441
12461
  return;
12442
12462
  }
12443
- if (typeof rec.name === "string") visitNode(rec, path4, inherited);
12463
+ if (typeof rec.name === "string")
12464
+ visitNode(rec, path4, { ...inherited, inCell: true });
12444
12465
  };
12445
12466
  const visitNode = (node, path4, inherited) => {
12446
12467
  if (node.enabled === false) return;
@@ -12449,6 +12470,7 @@ function collectDocxTextInventory(children, basePath = "/children") {
12449
12470
  const extra = {
12450
12471
  ...inherited.repeats && { repeats: true }
12451
12472
  };
12473
+ const scope = name === "section" ? { ...inherited, section: ++sectionCount } : inherited;
12452
12474
  switch (name) {
12453
12475
  case "heading": {
12454
12476
  if (inherited.repeats) {
@@ -12457,6 +12479,27 @@ function collectDocxTextInventory(children, basePath = "/children") {
12457
12479
  }
12458
12480
  const level = typeof props.level === "number" && Number.isFinite(props.level) ? props.level : 1;
12459
12481
  add(`${path4}/props/text`, props.text, "heading", { ...extra, level });
12482
+ if (typeof props.text === "string" && props.text.trim() !== "" && !scope.inCell) {
12483
+ headings.push({ text: props.text, level, section: scope.section });
12484
+ }
12485
+ break;
12486
+ }
12487
+ case "toc": {
12488
+ add(`${path4}/props/title`, props.title, "toc-entry", extra);
12489
+ const styles = /* @__PURE__ */ new Set();
12490
+ if (Array.isArray(props.styles)) {
12491
+ for (const mapping of props.styles) {
12492
+ const id = asRecord(mapping)?.styleId;
12493
+ if (typeof id === "string") styles.add(id);
12494
+ }
12495
+ }
12496
+ tocs.push({
12497
+ at: entries.length,
12498
+ path: path4,
12499
+ depth: tocDepth(props.depth),
12500
+ styles,
12501
+ section: props.scope === "document" ? void 0 : scope.section
12502
+ });
12460
12503
  break;
12461
12504
  }
12462
12505
  case "paragraph": {
@@ -12470,6 +12513,13 @@ function collectDocxTextInventory(children, basePath = "/children") {
12470
12513
  ...frame && { frame }
12471
12514
  }
12472
12515
  );
12516
+ if (typeof props.themeStyle === "string" && typeof props.text === "string" && props.text.trim() !== "" && !scope.inCell) {
12517
+ headings.push({
12518
+ text: props.text,
12519
+ themeStyle: props.themeStyle,
12520
+ section: scope.section
12521
+ });
12522
+ }
12473
12523
  break;
12474
12524
  }
12475
12525
  case "list": {
@@ -12522,8 +12572,28 @@ function collectDocxTextInventory(children, basePath = "/children") {
12522
12572
  add(`${path4}/props/description`, props.description, "statistic", extra);
12523
12573
  break;
12524
12574
  }
12575
+ case "chart": {
12576
+ if (props.showTitle !== false) {
12577
+ add(`${path4}/props/title`, props.title, "caption", extra);
12578
+ }
12579
+ if (props.type !== "pie" && props.type !== "doughnut") {
12580
+ add(
12581
+ `${path4}/props/catAxisTitle`,
12582
+ props.catAxisTitle,
12583
+ "caption",
12584
+ extra
12585
+ );
12586
+ add(
12587
+ `${path4}/props/valAxisTitle`,
12588
+ props.valAxisTitle,
12589
+ "caption",
12590
+ extra
12591
+ );
12592
+ }
12593
+ add(`${path4}/props/caption`, props.caption, "caption", extra);
12594
+ break;
12595
+ }
12525
12596
  case "image":
12526
- case "chart":
12527
12597
  case "highcharts":
12528
12598
  case "visual":
12529
12599
  case "visual-native": {
@@ -12551,7 +12621,7 @@ function collectDocxTextInventory(children, basePath = "/children") {
12551
12621
  if (Array.isArray(node.children)) {
12552
12622
  node.children.forEach((child, index) => {
12553
12623
  const rec = asRecord(child);
12554
- if (rec) visitNode(rec, `${path4}/children/${index}`, inherited);
12624
+ if (rec) visitNode(rec, `${path4}/children/${index}`, scope);
12555
12625
  });
12556
12626
  }
12557
12627
  };
@@ -12559,6 +12629,29 @@ function collectDocxTextInventory(children, basePath = "/children") {
12559
12629
  const rec = asRecord(child);
12560
12630
  if (rec) visitNode(rec, `${basePath}/${index}`, {});
12561
12631
  });
12632
+ for (const toc of [...tocs].reverse()) {
12633
+ const collected = headings.filter(
12634
+ (heading) => (toc.section === void 0 || heading.section === toc.section) && (heading.level !== void 0 ? heading.level >= toc.depth.from && heading.level <= toc.depth.to : heading.themeStyle !== void 0 && toc.styles.has(heading.themeStyle))
12635
+ );
12636
+ entries.splice(
12637
+ toc.at,
12638
+ 0,
12639
+ ...collected.map(
12640
+ (heading, index) => ({
12641
+ id: `docx:text:${toc.path}:entry:${index}`,
12642
+ kind: "docx/text",
12643
+ path: toc.path,
12644
+ text: heading.text,
12645
+ role: "toc-entry",
12646
+ order: 0,
12647
+ optional: true
12648
+ })
12649
+ )
12650
+ );
12651
+ }
12652
+ entries.forEach((entry, index) => {
12653
+ entry.order = index;
12654
+ });
12562
12655
  return entries;
12563
12656
  }
12564
12657