@json-to-office/core-docx 4.1.0 → 4.2.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 +89 -5
- package/dist/index.js.map +1 -1
- package/dist/plugin/example/index.js +89 -5
- package/dist/plugin/example/index.js.map +1 -1
- package/dist/quality/text-inventory.d.ts +14 -1
- package/dist/quality/text-inventory.d.ts.map +1 -1
- package/dist/templates/themes/index.d.ts +5 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -12484,6 +12484,12 @@ init_defaults();
|
|
|
12484
12484
|
init_widthUtils();
|
|
12485
12485
|
|
|
12486
12486
|
// src/quality/text-inventory.ts
|
|
12487
|
+
function tocDepth(depth) {
|
|
12488
|
+
const range = asRecord(depth) ?? {};
|
|
12489
|
+
const from = typeof range.from === "number" ? range.from : 1;
|
|
12490
|
+
const to = typeof range.to === "number" ? range.to : 3;
|
|
12491
|
+
return { from, to };
|
|
12492
|
+
}
|
|
12487
12493
|
function asRecord(value) {
|
|
12488
12494
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
12489
12495
|
}
|
|
@@ -12504,10 +12510,14 @@ function collectDocxTextInventory(children, basePath = "/children") {
|
|
|
12504
12510
|
path: path3,
|
|
12505
12511
|
text,
|
|
12506
12512
|
role,
|
|
12507
|
-
|
|
12513
|
+
// Renumbered once the walk is done: contents entries are spliced in.
|
|
12514
|
+
order: -1,
|
|
12508
12515
|
...extra
|
|
12509
12516
|
});
|
|
12510
12517
|
};
|
|
12518
|
+
const headings = [];
|
|
12519
|
+
const tocs = [];
|
|
12520
|
+
let sectionCount = 0;
|
|
12511
12521
|
const visitCell = (cell, path3, role, inherited) => {
|
|
12512
12522
|
const cellRole = inherited.repeats ? "chrome" : role;
|
|
12513
12523
|
const extra = inherited.repeats ? { repeats: true } : {};
|
|
@@ -12522,11 +12532,13 @@ function collectDocxTextInventory(children, basePath = "/children") {
|
|
|
12522
12532
|
add(`${path3}/content`, rec.content, cellRole, extra);
|
|
12523
12533
|
else {
|
|
12524
12534
|
const inner = asRecord(rec.content);
|
|
12525
|
-
if (inner)
|
|
12535
|
+
if (inner)
|
|
12536
|
+
visitNode(inner, `${path3}/content`, { ...inherited, inCell: true });
|
|
12526
12537
|
}
|
|
12527
12538
|
return;
|
|
12528
12539
|
}
|
|
12529
|
-
if (typeof rec.name === "string")
|
|
12540
|
+
if (typeof rec.name === "string")
|
|
12541
|
+
visitNode(rec, path3, { ...inherited, inCell: true });
|
|
12530
12542
|
};
|
|
12531
12543
|
const visitNode = (node, path3, inherited) => {
|
|
12532
12544
|
if (node.enabled === false) return;
|
|
@@ -12535,6 +12547,7 @@ function collectDocxTextInventory(children, basePath = "/children") {
|
|
|
12535
12547
|
const extra = {
|
|
12536
12548
|
...inherited.repeats && { repeats: true }
|
|
12537
12549
|
};
|
|
12550
|
+
const scope = name === "section" ? { ...inherited, section: ++sectionCount } : inherited;
|
|
12538
12551
|
switch (name) {
|
|
12539
12552
|
case "heading": {
|
|
12540
12553
|
if (inherited.repeats) {
|
|
@@ -12543,6 +12556,27 @@ function collectDocxTextInventory(children, basePath = "/children") {
|
|
|
12543
12556
|
}
|
|
12544
12557
|
const level = typeof props.level === "number" && Number.isFinite(props.level) ? props.level : 1;
|
|
12545
12558
|
add(`${path3}/props/text`, props.text, "heading", { ...extra, level });
|
|
12559
|
+
if (typeof props.text === "string" && props.text.trim() !== "" && !scope.inCell) {
|
|
12560
|
+
headings.push({ text: props.text, level, section: scope.section });
|
|
12561
|
+
}
|
|
12562
|
+
break;
|
|
12563
|
+
}
|
|
12564
|
+
case "toc": {
|
|
12565
|
+
add(`${path3}/props/title`, props.title, "toc-entry", extra);
|
|
12566
|
+
const styles = /* @__PURE__ */ new Set();
|
|
12567
|
+
if (Array.isArray(props.styles)) {
|
|
12568
|
+
for (const mapping of props.styles) {
|
|
12569
|
+
const id = asRecord(mapping)?.styleId;
|
|
12570
|
+
if (typeof id === "string") styles.add(id);
|
|
12571
|
+
}
|
|
12572
|
+
}
|
|
12573
|
+
tocs.push({
|
|
12574
|
+
at: entries.length,
|
|
12575
|
+
path: path3,
|
|
12576
|
+
depth: tocDepth(props.depth),
|
|
12577
|
+
styles,
|
|
12578
|
+
section: props.scope === "document" ? void 0 : scope.section
|
|
12579
|
+
});
|
|
12546
12580
|
break;
|
|
12547
12581
|
}
|
|
12548
12582
|
case "paragraph": {
|
|
@@ -12556,6 +12590,13 @@ function collectDocxTextInventory(children, basePath = "/children") {
|
|
|
12556
12590
|
...frame && { frame }
|
|
12557
12591
|
}
|
|
12558
12592
|
);
|
|
12593
|
+
if (typeof props.themeStyle === "string" && typeof props.text === "string" && props.text.trim() !== "" && !scope.inCell) {
|
|
12594
|
+
headings.push({
|
|
12595
|
+
text: props.text,
|
|
12596
|
+
themeStyle: props.themeStyle,
|
|
12597
|
+
section: scope.section
|
|
12598
|
+
});
|
|
12599
|
+
}
|
|
12559
12600
|
break;
|
|
12560
12601
|
}
|
|
12561
12602
|
case "list": {
|
|
@@ -12608,8 +12649,28 @@ function collectDocxTextInventory(children, basePath = "/children") {
|
|
|
12608
12649
|
add(`${path3}/props/description`, props.description, "statistic", extra);
|
|
12609
12650
|
break;
|
|
12610
12651
|
}
|
|
12652
|
+
case "chart": {
|
|
12653
|
+
if (props.showTitle !== false) {
|
|
12654
|
+
add(`${path3}/props/title`, props.title, "caption", extra);
|
|
12655
|
+
}
|
|
12656
|
+
if (props.type !== "pie" && props.type !== "doughnut") {
|
|
12657
|
+
add(
|
|
12658
|
+
`${path3}/props/catAxisTitle`,
|
|
12659
|
+
props.catAxisTitle,
|
|
12660
|
+
"caption",
|
|
12661
|
+
extra
|
|
12662
|
+
);
|
|
12663
|
+
add(
|
|
12664
|
+
`${path3}/props/valAxisTitle`,
|
|
12665
|
+
props.valAxisTitle,
|
|
12666
|
+
"caption",
|
|
12667
|
+
extra
|
|
12668
|
+
);
|
|
12669
|
+
}
|
|
12670
|
+
add(`${path3}/props/caption`, props.caption, "caption", extra);
|
|
12671
|
+
break;
|
|
12672
|
+
}
|
|
12611
12673
|
case "image":
|
|
12612
|
-
case "chart":
|
|
12613
12674
|
case "highcharts":
|
|
12614
12675
|
case "visual":
|
|
12615
12676
|
case "visual-native": {
|
|
@@ -12637,7 +12698,7 @@ function collectDocxTextInventory(children, basePath = "/children") {
|
|
|
12637
12698
|
if (Array.isArray(node.children)) {
|
|
12638
12699
|
node.children.forEach((child, index) => {
|
|
12639
12700
|
const rec = asRecord(child);
|
|
12640
|
-
if (rec) visitNode(rec, `${path3}/children/${index}`,
|
|
12701
|
+
if (rec) visitNode(rec, `${path3}/children/${index}`, scope);
|
|
12641
12702
|
});
|
|
12642
12703
|
}
|
|
12643
12704
|
};
|
|
@@ -12645,6 +12706,29 @@ function collectDocxTextInventory(children, basePath = "/children") {
|
|
|
12645
12706
|
const rec = asRecord(child);
|
|
12646
12707
|
if (rec) visitNode(rec, `${basePath}/${index}`, {});
|
|
12647
12708
|
});
|
|
12709
|
+
for (const toc of [...tocs].reverse()) {
|
|
12710
|
+
const collected = headings.filter(
|
|
12711
|
+
(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))
|
|
12712
|
+
);
|
|
12713
|
+
entries.splice(
|
|
12714
|
+
toc.at,
|
|
12715
|
+
0,
|
|
12716
|
+
...collected.map(
|
|
12717
|
+
(heading, index) => ({
|
|
12718
|
+
id: `docx:text:${toc.path}:entry:${index}`,
|
|
12719
|
+
kind: "docx/text",
|
|
12720
|
+
path: toc.path,
|
|
12721
|
+
text: heading.text,
|
|
12722
|
+
role: "toc-entry",
|
|
12723
|
+
order: 0,
|
|
12724
|
+
optional: true
|
|
12725
|
+
})
|
|
12726
|
+
)
|
|
12727
|
+
);
|
|
12728
|
+
}
|
|
12729
|
+
entries.forEach((entry, index) => {
|
|
12730
|
+
entry.order = index;
|
|
12731
|
+
});
|
|
12648
12732
|
return entries;
|
|
12649
12733
|
}
|
|
12650
12734
|
|