@json-to-office/core-docx 7.3.0 → 7.4.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 +397 -38
- package/dist/index.js.map +1 -1
- package/dist/ir/chartValues.d.ts +7 -5
- package/dist/ir/chartValues.d.ts.map +1 -1
- package/dist/ir/compiler.d.ts.map +1 -1
- package/dist/plugin/example/index.js +397 -38
- package/dist/plugin/example/index.js.map +1 -1
- package/dist/renderers/docxjs/docxSubpath.d.ts +4 -4
- package/dist/renderers/docxjs/docxSubpath.d.ts.map +1 -1
- package/dist/renderers/docxjs/emit.d.ts +5 -0
- package/dist/renderers/docxjs/emit.d.ts.map +1 -1
- package/dist/renderers/docxjs/index.d.ts +5 -3
- package/dist/renderers/docxjs/index.d.ts.map +1 -1
- package/dist/renderers/docxjs/pageNumbers.d.ts +113 -0
- package/dist/renderers/docxjs/pageNumbers.d.ts.map +1 -0
- package/dist/renderers/office-open/emit.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2876,12 +2876,28 @@ var init_units = __esm({
|
|
|
2876
2876
|
});
|
|
2877
2877
|
|
|
2878
2878
|
// src/ir/chartValues.ts
|
|
2879
|
+
function numericLabelValue(label) {
|
|
2880
|
+
const value = label.trim();
|
|
2881
|
+
return NUMERIC_LABEL.test(value) ? Number(value) : void 0;
|
|
2882
|
+
}
|
|
2879
2883
|
function isNumericLabel(label) {
|
|
2880
|
-
|
|
2884
|
+
const value = numericLabelValue(label);
|
|
2885
|
+
return value !== void 0 && Number.isFinite(value);
|
|
2886
|
+
}
|
|
2887
|
+
function isOutOfRangeNumericLabel(label) {
|
|
2888
|
+
const value = numericLabelValue(label);
|
|
2889
|
+
return value !== void 0 && !Number.isFinite(value);
|
|
2881
2890
|
}
|
|
2882
2891
|
function scatterX(labels, index) {
|
|
2883
2892
|
const label = labels[index];
|
|
2884
|
-
|
|
2893
|
+
const value = label === void 0 ? void 0 : numericLabelValue(label);
|
|
2894
|
+
if (value === void 0) return index + 1;
|
|
2895
|
+
if (!Number.isFinite(value)) {
|
|
2896
|
+
throw new RangeError(
|
|
2897
|
+
`Scatter x label ${JSON.stringify(label)} is not finite.`
|
|
2898
|
+
);
|
|
2899
|
+
}
|
|
2900
|
+
return value;
|
|
2885
2901
|
}
|
|
2886
2902
|
var NUMERIC_LABEL;
|
|
2887
2903
|
var init_chartValues = __esm({
|
|
@@ -2914,7 +2930,7 @@ var init_chartText = __esm({
|
|
|
2914
2930
|
});
|
|
2915
2931
|
|
|
2916
2932
|
// src/renderers/docxjs/docxSubpath.ts
|
|
2917
|
-
function docxSubpath(specifier, component, importer) {
|
|
2933
|
+
function docxSubpath(specifier, component, importer, since = "9.8.0") {
|
|
2918
2934
|
let module;
|
|
2919
2935
|
let failure;
|
|
2920
2936
|
let loading;
|
|
@@ -2938,7 +2954,7 @@ function docxSubpath(specifier, component, importer) {
|
|
|
2938
2954
|
const { reason } = failure;
|
|
2939
2955
|
const detail = reason instanceof Error ? reason.message : String(reason);
|
|
2940
2956
|
throw new Error(
|
|
2941
|
-
`The docx \`${component}\` component needs docx
|
|
2957
|
+
`The docx \`${component}\` component needs docx ${since} or later: the \`${specifier}\` entry could not be loaded (${detail})`
|
|
2942
2958
|
);
|
|
2943
2959
|
}
|
|
2944
2960
|
throw new Error(
|
|
@@ -3535,8 +3551,19 @@ function emitBlock(block2, resources = /* @__PURE__ */ new Map()) {
|
|
|
3535
3551
|
return assertNever2(block2, "DocxIrBlock");
|
|
3536
3552
|
}
|
|
3537
3553
|
}
|
|
3554
|
+
function emitOutsideBody(emit) {
|
|
3555
|
+
const was = outsideBody;
|
|
3556
|
+
outsideBody = true;
|
|
3557
|
+
try {
|
|
3558
|
+
return emit();
|
|
3559
|
+
} finally {
|
|
3560
|
+
outsideBody = was;
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3538
3563
|
function emitToc(block2) {
|
|
3539
|
-
|
|
3564
|
+
const cached = outsideBody && block2.cachedEntries?.length;
|
|
3565
|
+
const Field = cached ? ThemedTableOfContents : TableOfContents;
|
|
3566
|
+
return new Field(block2.alias ?? "Table of Contents", {
|
|
3540
3567
|
...block2.hyperlink !== void 0 ? { hyperlink: block2.hyperlink } : {},
|
|
3541
3568
|
...block2.headingRange ? {
|
|
3542
3569
|
headingStyleRange: `${block2.headingRange.from}-${block2.headingRange.to}`
|
|
@@ -3549,7 +3576,7 @@ function emitToc(block2) {
|
|
|
3549
3576
|
pageNumbersEntryLevelsRange: block2.omitPageNumbersForLevels.map((range) => `${range.from}-${range.to}`).join(",")
|
|
3550
3577
|
} : {},
|
|
3551
3578
|
...block2.entrySeparator !== void 0 ? { entryAndPageNumberSeparator: block2.entrySeparator } : {},
|
|
3552
|
-
...
|
|
3579
|
+
...cached ? {
|
|
3553
3580
|
cachedEntries: block2.cachedEntries.map((entry) => ({
|
|
3554
3581
|
title: entry.text,
|
|
3555
3582
|
level: entry.level
|
|
@@ -3672,7 +3699,7 @@ function emitBorder(border3) {
|
|
|
3672
3699
|
...border3.spacePoints !== void 0 ? { space: border3.spacePoints } : {}
|
|
3673
3700
|
};
|
|
3674
3701
|
}
|
|
3675
|
-
var ALIGNMENT2, PAGE_FIELDS, isSequenceField, WRAP_TYPE, ThemedTableOfContents, VERTICAL_ALIGN, TABLE_ANCHOR, HORIZONTAL_POSITION, VERTICAL_POSITION;
|
|
3702
|
+
var ALIGNMENT2, PAGE_FIELDS, isSequenceField, WRAP_TYPE, ThemedTableOfContents, outsideBody, VERTICAL_ALIGN, TABLE_ANCHOR, HORIZONTAL_POSITION, VERTICAL_POSITION;
|
|
3676
3703
|
var init_emit = __esm({
|
|
3677
3704
|
"src/renderers/docxjs/emit.ts"() {
|
|
3678
3705
|
"use strict";
|
|
@@ -3698,6 +3725,7 @@ var init_emit = __esm({
|
|
|
3698
3725
|
Object.defineProperty(ThemedTableOfContents.prototype, "getTabStopsForLevel", {
|
|
3699
3726
|
value: () => []
|
|
3700
3727
|
});
|
|
3728
|
+
outsideBody = false;
|
|
3701
3729
|
VERTICAL_ALIGN = {
|
|
3702
3730
|
top: VerticalAlign.TOP,
|
|
3703
3731
|
center: VerticalAlign.CENTER,
|
|
@@ -3885,6 +3913,318 @@ var init_styles2 = __esm({
|
|
|
3885
3913
|
}
|
|
3886
3914
|
});
|
|
3887
3915
|
|
|
3916
|
+
// src/renderers/docxjs/pageNumbers.ts
|
|
3917
|
+
import {
|
|
3918
|
+
Tab as Tab2
|
|
3919
|
+
} from "docx";
|
|
3920
|
+
function needsPageNumbers(ir) {
|
|
3921
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3922
|
+
const visit = (value) => {
|
|
3923
|
+
if (typeof value !== "object" || value === null) return false;
|
|
3924
|
+
if (ArrayBuffer.isView(value) || seen.has(value)) return false;
|
|
3925
|
+
seen.add(value);
|
|
3926
|
+
if (Array.isArray(value)) return value.some(visit);
|
|
3927
|
+
if (value.kind === "toc") return true;
|
|
3928
|
+
return Object.values(value).some(visit);
|
|
3929
|
+
};
|
|
3930
|
+
return ir.sections.some((section2) => visit(section2.children));
|
|
3931
|
+
}
|
|
3932
|
+
async function createPageNumberEstimator(ir) {
|
|
3933
|
+
await layout.load();
|
|
3934
|
+
const cached = cachedContentsEntries(ir);
|
|
3935
|
+
const separators = contentsSeparators(ir);
|
|
3936
|
+
const estimate = layout.loaded() ? layout.get().estimatePageNumbersWith({ guess: true }) : void 0;
|
|
3937
|
+
return (body, context) => {
|
|
3938
|
+
renumberContentsBookmarks(body);
|
|
3939
|
+
restoreEntryNumbers(body, cached, separators);
|
|
3940
|
+
dropContentsEntryTabs(body);
|
|
3941
|
+
writeSeparatorTabs(body, context);
|
|
3942
|
+
endContentsInLastEntry(body);
|
|
3943
|
+
if (!estimate) {
|
|
3944
|
+
unavailable(
|
|
3945
|
+
`the \`docx/layout\` entry could not be loaded (${failureOf(() => layout.get())})`
|
|
3946
|
+
);
|
|
3947
|
+
return { bookmarks: /* @__PURE__ */ new Map() };
|
|
3948
|
+
}
|
|
3949
|
+
try {
|
|
3950
|
+
const estimated = estimate(body, context);
|
|
3951
|
+
if (complete(estimated)) clearUpdateFields(context.file);
|
|
3952
|
+
return estimated;
|
|
3953
|
+
} catch (error) {
|
|
3954
|
+
unavailable(error instanceof Error ? error.message : String(error));
|
|
3955
|
+
return { bookmarks: /* @__PURE__ */ new Map() };
|
|
3956
|
+
}
|
|
3957
|
+
};
|
|
3958
|
+
}
|
|
3959
|
+
function unavailable(reason) {
|
|
3960
|
+
reportWarning(
|
|
3961
|
+
"toc",
|
|
3962
|
+
PAGE_NUMBERS_UNAVAILABLE,
|
|
3963
|
+
`The table of contents is written without page numbers: laying the pages out failed (${reason}). Word fills them in when it updates the fields on open.`
|
|
3964
|
+
);
|
|
3965
|
+
}
|
|
3966
|
+
function failureOf(get) {
|
|
3967
|
+
try {
|
|
3968
|
+
get();
|
|
3969
|
+
return "unknown";
|
|
3970
|
+
} catch (error) {
|
|
3971
|
+
return error instanceof Error ? error.message : String(error);
|
|
3972
|
+
}
|
|
3973
|
+
}
|
|
3974
|
+
function complete(estimated) {
|
|
3975
|
+
return estimated.pageCount !== void 0 && (estimated.guesses ?? []).length === 0;
|
|
3976
|
+
}
|
|
3977
|
+
function clearUpdateFields(file) {
|
|
3978
|
+
const root = file?.Settings?.root;
|
|
3979
|
+
if (!root) return;
|
|
3980
|
+
const at = root.findIndex(
|
|
3981
|
+
(element) => element?.rootKey === "w:updateFields"
|
|
3982
|
+
);
|
|
3983
|
+
if (at >= 0) root.splice(at, 1);
|
|
3984
|
+
}
|
|
3985
|
+
function isContentsField(sdt) {
|
|
3986
|
+
let found = false;
|
|
3987
|
+
const visit = (element) => {
|
|
3988
|
+
if (found) return;
|
|
3989
|
+
if (nameOf(element) === "w:instrText") {
|
|
3990
|
+
found = childrenOf(element).some(
|
|
3991
|
+
(child) => typeof child === "string" && /^\s*TOC\b/.test(child)
|
|
3992
|
+
);
|
|
3993
|
+
return;
|
|
3994
|
+
}
|
|
3995
|
+
childrenOf(element).forEach(visit);
|
|
3996
|
+
};
|
|
3997
|
+
visit(sdt);
|
|
3998
|
+
return found;
|
|
3999
|
+
}
|
|
4000
|
+
function contentsFields(body) {
|
|
4001
|
+
const found = [];
|
|
4002
|
+
const visit = (element) => {
|
|
4003
|
+
const name = nameOf(element);
|
|
4004
|
+
if (name === void 0 || name === "_attr") return;
|
|
4005
|
+
if (name === "w:sdt" && isContentsField(element)) {
|
|
4006
|
+
found.push(element);
|
|
4007
|
+
return;
|
|
4008
|
+
}
|
|
4009
|
+
childrenOf(element).forEach(visit);
|
|
4010
|
+
};
|
|
4011
|
+
visit(body);
|
|
4012
|
+
return found;
|
|
4013
|
+
}
|
|
4014
|
+
function entryParagraphs(field) {
|
|
4015
|
+
return childrenOf(field).filter((content) => nameOf(content) === "w:sdtContent").flatMap(
|
|
4016
|
+
(content) => childrenOf(content).filter((paragraph2) => nameOf(paragraph2) === "w:p")
|
|
4017
|
+
);
|
|
4018
|
+
}
|
|
4019
|
+
function dropContentsEntryTabs(body) {
|
|
4020
|
+
for (const field of contentsFields(body)) {
|
|
4021
|
+
for (const paragraph2 of entryParagraphs(field)) {
|
|
4022
|
+
for (const properties of childrenOf(paragraph2)) {
|
|
4023
|
+
if (nameOf(properties) !== "w:pPr") continue;
|
|
4024
|
+
properties["w:pPr"] = childrenOf(properties).filter(
|
|
4025
|
+
(child) => nameOf(child) !== "w:tabs"
|
|
4026
|
+
);
|
|
4027
|
+
}
|
|
4028
|
+
}
|
|
4029
|
+
}
|
|
4030
|
+
}
|
|
4031
|
+
function endContentsInLastEntry(body) {
|
|
4032
|
+
for (const field of contentsFields(body)) {
|
|
4033
|
+
for (const content of childrenOf(field)) {
|
|
4034
|
+
if (nameOf(content) !== "w:sdtContent") continue;
|
|
4035
|
+
const paragraphs = childrenOf(content);
|
|
4036
|
+
const last = paragraphs[paragraphs.length - 1];
|
|
4037
|
+
const entry = paragraphs[paragraphs.length - 2];
|
|
4038
|
+
if (nameOf(last) !== "w:p" || nameOf(entry) !== "w:p") continue;
|
|
4039
|
+
const runs = childrenOf(last);
|
|
4040
|
+
const onlyTheEnd = runs.length === 1 && nameOf(runs[0]) === "w:r" && childrenOf(runs[0]).every(
|
|
4041
|
+
(child) => nameOf(child) === "w:fldChar" && attributesOf(child)?.["w:fldCharType"] === "end"
|
|
4042
|
+
);
|
|
4043
|
+
const entries = paragraphs.filter(
|
|
4044
|
+
(paragraph2) => textNodes(paragraph2).length > 0
|
|
4045
|
+
);
|
|
4046
|
+
if (!onlyTheEnd || entries.length < 2 || textNodes(entry).length === 0)
|
|
4047
|
+
continue;
|
|
4048
|
+
childrenOf(entry).push(runs[0]);
|
|
4049
|
+
paragraphs.pop();
|
|
4050
|
+
}
|
|
4051
|
+
}
|
|
4052
|
+
}
|
|
4053
|
+
function writeSeparatorTabs(body, context) {
|
|
4054
|
+
const tab = () => new Tab2().prepForXml(context);
|
|
4055
|
+
const visit = (element) => {
|
|
4056
|
+
const name = nameOf(element);
|
|
4057
|
+
if (name === void 0 || name === "_attr") return;
|
|
4058
|
+
if (name === "w:r") {
|
|
4059
|
+
const children = childrenOf(element);
|
|
4060
|
+
children.forEach((child, index) => {
|
|
4061
|
+
if (nameOf(child) !== "w:t") return;
|
|
4062
|
+
const text = childrenOf(child).filter(
|
|
4063
|
+
(part) => typeof part === "string"
|
|
4064
|
+
);
|
|
4065
|
+
if (text.length === 1 && text[0] === " ") children[index] = tab();
|
|
4066
|
+
});
|
|
4067
|
+
return;
|
|
4068
|
+
}
|
|
4069
|
+
childrenOf(element).forEach(visit);
|
|
4070
|
+
};
|
|
4071
|
+
for (const field of contentsFields(body))
|
|
4072
|
+
entryParagraphs(field).forEach(visit);
|
|
4073
|
+
}
|
|
4074
|
+
function textNodes(element) {
|
|
4075
|
+
const name = nameOf(element);
|
|
4076
|
+
if (name === void 0 || name === "_attr" || name === "w:instrText")
|
|
4077
|
+
return [];
|
|
4078
|
+
const children = childrenOf(element);
|
|
4079
|
+
if (name === "w:t")
|
|
4080
|
+
return children.flatMap(
|
|
4081
|
+
(child, index) => typeof child === "string" ? [{ parent: children, index }] : []
|
|
4082
|
+
);
|
|
4083
|
+
return children.flatMap(textNodes);
|
|
4084
|
+
}
|
|
4085
|
+
function contentsSeparators(ir) {
|
|
4086
|
+
const separators = [];
|
|
4087
|
+
const visit = (value) => {
|
|
4088
|
+
if (typeof value !== "object" || value === null) return;
|
|
4089
|
+
if (ArrayBuffer.isView(value)) return;
|
|
4090
|
+
if (Array.isArray(value)) {
|
|
4091
|
+
value.forEach(visit);
|
|
4092
|
+
return;
|
|
4093
|
+
}
|
|
4094
|
+
if (value.kind === "toc") {
|
|
4095
|
+
separators.push(value.entrySeparator);
|
|
4096
|
+
return;
|
|
4097
|
+
}
|
|
4098
|
+
Object.values(value).forEach(visit);
|
|
4099
|
+
};
|
|
4100
|
+
for (const section2 of ir.sections) visit(section2.children);
|
|
4101
|
+
return separators;
|
|
4102
|
+
}
|
|
4103
|
+
function cachedContentsEntries(ir) {
|
|
4104
|
+
const fields = [];
|
|
4105
|
+
const visit = (value) => {
|
|
4106
|
+
if (typeof value !== "object" || value === null) return;
|
|
4107
|
+
if (ArrayBuffer.isView(value)) return;
|
|
4108
|
+
if (Array.isArray(value)) {
|
|
4109
|
+
value.forEach(visit);
|
|
4110
|
+
return;
|
|
4111
|
+
}
|
|
4112
|
+
if (value.kind === "toc") {
|
|
4113
|
+
const toc = value;
|
|
4114
|
+
fields.push(toc.cachedEntries?.map((entry) => entry.text));
|
|
4115
|
+
return;
|
|
4116
|
+
}
|
|
4117
|
+
Object.values(value).forEach(visit);
|
|
4118
|
+
};
|
|
4119
|
+
for (const section2 of ir.sections) visit(section2.children);
|
|
4120
|
+
return fields;
|
|
4121
|
+
}
|
|
4122
|
+
function restoreEntryNumbers(body, cached, separators = []) {
|
|
4123
|
+
contentsFields(body).forEach((field, index) => {
|
|
4124
|
+
const texts = cached[index];
|
|
4125
|
+
const paragraphs = entryParagraphs(field).filter(
|
|
4126
|
+
(paragraph2) => textNodes(paragraph2).length > 0
|
|
4127
|
+
);
|
|
4128
|
+
if (!texts || texts.length !== paragraphs.length) return;
|
|
4129
|
+
paragraphs.forEach((paragraph2, entry) => {
|
|
4130
|
+
const nodes = textNodes(paragraph2);
|
|
4131
|
+
let title = nodes.map(({ parent, index: at }) => parent[at]).join("");
|
|
4132
|
+
const separator = separators[index];
|
|
4133
|
+
if (separator && title.endsWith(separator))
|
|
4134
|
+
title = title.slice(0, -separator.length);
|
|
4135
|
+
const text = texts[entry];
|
|
4136
|
+
if (title === "" || text === title || !text.endsWith(title)) return;
|
|
4137
|
+
const [first] = nodes;
|
|
4138
|
+
first.parent[first.index] = text.slice(0, text.length - title.length) + first.parent[first.index];
|
|
4139
|
+
});
|
|
4140
|
+
});
|
|
4141
|
+
}
|
|
4142
|
+
function renumberContentsBookmarks(body) {
|
|
4143
|
+
const names = /* @__PURE__ */ new Map();
|
|
4144
|
+
const paragraphs = (element) => {
|
|
4145
|
+
const name = nameOf(element);
|
|
4146
|
+
if (name === void 0 || name === "_attr") return;
|
|
4147
|
+
if (name !== "w:p") {
|
|
4148
|
+
childrenOf(element).forEach(paragraphs);
|
|
4149
|
+
return;
|
|
4150
|
+
}
|
|
4151
|
+
const children = childrenOf(element);
|
|
4152
|
+
for (const start of children) {
|
|
4153
|
+
if (nameOf(start) !== "w:bookmarkStart") continue;
|
|
4154
|
+
const attributes = attributesOf(start);
|
|
4155
|
+
const old = attributes?.["w:name"];
|
|
4156
|
+
if (typeof old !== "string" || !CONTENTS_BOOKMARK.test(old)) continue;
|
|
4157
|
+
const ordinal = names.size + 1;
|
|
4158
|
+
const renamed2 = `_Toc${ordinal}`;
|
|
4159
|
+
const id = CONTENTS_BOOKMARK_ID_BASE + ordinal;
|
|
4160
|
+
names.set(old, renamed2);
|
|
4161
|
+
const oldId = attributes["w:id"];
|
|
4162
|
+
attributes["w:name"] = renamed2;
|
|
4163
|
+
attributes["w:id"] = id;
|
|
4164
|
+
const end = [...children].reverse().find(
|
|
4165
|
+
(child) => nameOf(child) === "w:bookmarkEnd" && String(attributesOf(child)?.["w:id"]) === String(oldId)
|
|
4166
|
+
);
|
|
4167
|
+
if (end) attributesOf(end)["w:id"] = id;
|
|
4168
|
+
}
|
|
4169
|
+
};
|
|
4170
|
+
paragraphs(body);
|
|
4171
|
+
if (names.size === 0) return;
|
|
4172
|
+
const references = (element) => {
|
|
4173
|
+
const name = nameOf(element);
|
|
4174
|
+
if (name === void 0) return;
|
|
4175
|
+
if (name === "w:hyperlink") {
|
|
4176
|
+
const attributes = attributesOf(element);
|
|
4177
|
+
const anchor = attributes?.["w:anchor"];
|
|
4178
|
+
if (typeof anchor === "string" && names.has(anchor))
|
|
4179
|
+
attributes["w:anchor"] = names.get(anchor);
|
|
4180
|
+
}
|
|
4181
|
+
if (name === "w:instrText") {
|
|
4182
|
+
const children = childrenOf(element);
|
|
4183
|
+
children.forEach((child, index) => {
|
|
4184
|
+
if (typeof child !== "string") return;
|
|
4185
|
+
children[index] = child.replace(
|
|
4186
|
+
/\b(PAGEREF\s+)(_Toc\d+)\b/g,
|
|
4187
|
+
(match, field, bookmark) => names.has(bookmark) ? `${field}${names.get(bookmark)}` : match
|
|
4188
|
+
);
|
|
4189
|
+
});
|
|
4190
|
+
element[name] = children;
|
|
4191
|
+
return;
|
|
4192
|
+
}
|
|
4193
|
+
if (name === "_attr") return;
|
|
4194
|
+
childrenOf(element).forEach(references);
|
|
4195
|
+
};
|
|
4196
|
+
references(body);
|
|
4197
|
+
}
|
|
4198
|
+
function attributesOf(element) {
|
|
4199
|
+
const attributes = childrenOf(element).find(
|
|
4200
|
+
(child) => nameOf(child) === "_attr"
|
|
4201
|
+
);
|
|
4202
|
+
return attributes?._attr;
|
|
4203
|
+
}
|
|
4204
|
+
var PAGE_NUMBERS_UNAVAILABLE, layout, nameOf, childrenOf, CONTENTS_BOOKMARK_ID_BASE, CONTENTS_BOOKMARK;
|
|
4205
|
+
var init_pageNumbers = __esm({
|
|
4206
|
+
"src/renderers/docxjs/pageNumbers.ts"() {
|
|
4207
|
+
"use strict";
|
|
4208
|
+
init_generationContext();
|
|
4209
|
+
init_docxSubpath();
|
|
4210
|
+
PAGE_NUMBERS_UNAVAILABLE = "W_DOCX_PAGE_NUMBERS_UNAVAILABLE";
|
|
4211
|
+
layout = docxSubpath(
|
|
4212
|
+
"docx/layout",
|
|
4213
|
+
"toc",
|
|
4214
|
+
() => import("docx/layout"),
|
|
4215
|
+
"9.9.0"
|
|
4216
|
+
);
|
|
4217
|
+
nameOf = (element) => typeof element === "object" && element !== null && !Array.isArray(element) ? Object.keys(element)[0] : void 0;
|
|
4218
|
+
childrenOf = (element) => {
|
|
4219
|
+
const name = nameOf(element);
|
|
4220
|
+
const content = name === void 0 ? void 0 : element[name];
|
|
4221
|
+
return Array.isArray(content) ? content : content === void 0 ? [] : [content];
|
|
4222
|
+
};
|
|
4223
|
+
CONTENTS_BOOKMARK_ID_BASE = 3e6;
|
|
4224
|
+
CONTENTS_BOOKMARK = /^_Toc\d+$/;
|
|
4225
|
+
}
|
|
4226
|
+
});
|
|
4227
|
+
|
|
3888
4228
|
// src/utils/normalizeTextCase.ts
|
|
3889
4229
|
function normalizeTextCase(zip) {
|
|
3890
4230
|
let changed = false;
|
|
@@ -4666,7 +5006,8 @@ function createDocxJsRenderer() {
|
|
|
4666
5006
|
)
|
|
4667
5007
|
});
|
|
4668
5008
|
}
|
|
4669
|
-
const
|
|
5009
|
+
const pageNumbers = needsPageNumbers(ir) ? await createPageNumberEstimator(ir) : void 0;
|
|
5010
|
+
const document = buildDocument(ir, resources, pageNumbers);
|
|
4670
5011
|
const packed = await Packer.toBuffer(document);
|
|
4671
5012
|
const fixed = fixFloatingImageIdsInBuffer(packed);
|
|
4672
5013
|
const repaired = markers ? repairDrawingGroupsInBuffer(fixed, markers) : fixed;
|
|
@@ -4684,13 +5025,12 @@ function createDocxJsRenderer() {
|
|
|
4684
5025
|
}
|
|
4685
5026
|
};
|
|
4686
5027
|
}
|
|
4687
|
-
function buildDocument(ir, resources = /* @__PURE__ */ new Map()) {
|
|
5028
|
+
function buildDocument(ir, resources = /* @__PURE__ */ new Map(), pageNumbers) {
|
|
4688
5029
|
return new Document({
|
|
5030
|
+
...pageNumbers ? { pageNumbers } : {},
|
|
4689
5031
|
styles: emitStyles(ir.styles),
|
|
4690
5032
|
...ir.theme ? { theme: themeOptions(ir.theme) } : {},
|
|
4691
|
-
sections: ir.sections.map(
|
|
4692
|
-
(section2, index) => sectionOptions(section2, resources, index === ir.sections.length - 1)
|
|
4693
|
-
),
|
|
5033
|
+
sections: ir.sections.map((section2) => sectionOptions(section2, resources)),
|
|
4694
5034
|
...coreProperties(ir),
|
|
4695
5035
|
features: {
|
|
4696
5036
|
updateFields: ir.settings.updateFields,
|
|
@@ -4709,8 +5049,8 @@ function buildDocument(ir, resources = /* @__PURE__ */ new Map()) {
|
|
|
4709
5049
|
author: comment.author,
|
|
4710
5050
|
...comment.initials ? { initials: comment.initials } : {},
|
|
4711
5051
|
date: new Date(comment.date),
|
|
4712
|
-
children:
|
|
4713
|
-
(block2) => emitBlock(block2, resources)
|
|
5052
|
+
children: emitOutsideBody(
|
|
5053
|
+
() => comment.children.map((block2) => emitBlock(block2, resources))
|
|
4714
5054
|
),
|
|
4715
5055
|
...comment.parentId !== void 0 ? { parentId: comment.parentId } : {},
|
|
4716
5056
|
...comment.resolved !== void 0 ? { resolved: comment.resolved } : {}
|
|
@@ -4738,8 +5078,8 @@ function noteBodies(notes, resources) {
|
|
|
4738
5078
|
const bodies = {};
|
|
4739
5079
|
for (const note of notes) {
|
|
4740
5080
|
bodies[String(note.id)] = {
|
|
4741
|
-
children:
|
|
4742
|
-
(block2) => emitBlock(block2, resources)
|
|
5081
|
+
children: emitOutsideBody(
|
|
5082
|
+
() => note.children.map((block2) => emitBlock(block2, resources))
|
|
4743
5083
|
)
|
|
4744
5084
|
};
|
|
4745
5085
|
}
|
|
@@ -4900,7 +5240,7 @@ function collectImagePlacements(ir) {
|
|
|
4900
5240
|
}
|
|
4901
5241
|
return { placements, drawingGroups };
|
|
4902
5242
|
}
|
|
4903
|
-
function sectionOptions(section2, resources
|
|
5243
|
+
function sectionOptions(section2, resources) {
|
|
4904
5244
|
const { page, columns } = section2.properties;
|
|
4905
5245
|
const options = {
|
|
4906
5246
|
properties: {
|
|
@@ -4939,7 +5279,7 @@ function sectionOptions(section2, resources, closesDocument = false) {
|
|
|
4939
5279
|
}
|
|
4940
5280
|
} : {}
|
|
4941
5281
|
},
|
|
4942
|
-
children: sectionChildren(section2, resources
|
|
5282
|
+
children: sectionChildren(section2, resources)
|
|
4943
5283
|
};
|
|
4944
5284
|
const headers = chromeSlots(section2.headers, Header, resources);
|
|
4945
5285
|
if (headers) options.headers = headers;
|
|
@@ -4953,7 +5293,9 @@ function chromeSlots(set, Part, resources) {
|
|
|
4953
5293
|
for (const slot of ["default", "first", "even"]) {
|
|
4954
5294
|
const part = set[slot];
|
|
4955
5295
|
if (part) {
|
|
4956
|
-
out[slot] = new Part({
|
|
5296
|
+
out[slot] = new Part({
|
|
5297
|
+
children: emitOutsideBody(() => partChildren(part, resources))
|
|
5298
|
+
});
|
|
4957
5299
|
}
|
|
4958
5300
|
}
|
|
4959
5301
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
@@ -4961,10 +5303,10 @@ function chromeSlots(set, Part, resources) {
|
|
|
4961
5303
|
function partChildren(part, resources) {
|
|
4962
5304
|
return part.children.map((block2) => emitBlock(block2, resources));
|
|
4963
5305
|
}
|
|
4964
|
-
function sectionChildren(section2, resources
|
|
5306
|
+
function sectionChildren(section2, resources) {
|
|
4965
5307
|
const blocks = section2.children.map((block2) => emitBlock(block2, resources));
|
|
4966
5308
|
const bookmark = section2.bookmark;
|
|
4967
|
-
const endsInFrame =
|
|
5309
|
+
const endsInFrame = lastBlockIsFrame(section2);
|
|
4968
5310
|
if (!bookmark && !endsInFrame) return blocks;
|
|
4969
5311
|
const out = [...blocks];
|
|
4970
5312
|
if (bookmark?.opens) {
|
|
@@ -5017,6 +5359,7 @@ var init_docxjs = __esm({
|
|
|
5017
5359
|
"use strict";
|
|
5018
5360
|
init_styles2();
|
|
5019
5361
|
init_charts();
|
|
5362
|
+
init_pageNumbers();
|
|
5020
5363
|
init_imageUtils();
|
|
5021
5364
|
init_packageDocument();
|
|
5022
5365
|
init_fixFloatingImageIds();
|
|
@@ -6203,7 +6546,7 @@ function sectionChildren2(value, ctx, closesDocument = false) {
|
|
|
6203
6546
|
const blocks = value.children.map((child) => block(child, ctx));
|
|
6204
6547
|
const last = value.children[value.children.length - 1];
|
|
6205
6548
|
const bookmark = value.bookmark;
|
|
6206
|
-
if (bookmark?.closes && last?.kind !== "paragraph" ||
|
|
6549
|
+
if (bookmark?.closes && last?.kind !== "paragraph" || last?.kind === "paragraph" && last.frame !== void 0 && (closesDocument || !bookmark?.closes))
|
|
6207
6550
|
blocks.push({
|
|
6208
6551
|
paragraph: {
|
|
6209
6552
|
children: [],
|
|
@@ -10284,9 +10627,9 @@ function schemeHex(token, theme) {
|
|
|
10284
10627
|
// src/ir/compiler.ts
|
|
10285
10628
|
var CONTENT_BOOKMARK_ID_BASE = 2e6;
|
|
10286
10629
|
var SINGLE_LINE_TWIPS = 240;
|
|
10287
|
-
function compileDocument(structure,
|
|
10630
|
+
function compileDocument(structure, layout2, warnings = [], images = /* @__PURE__ */ new Map(), options = {}) {
|
|
10288
10631
|
const styles = createDocumentStyles(structure.theme, structure.language);
|
|
10289
|
-
const outline = collectOutline(
|
|
10632
|
+
const outline = collectOutline(layout2, warnings);
|
|
10290
10633
|
const ctx = {
|
|
10291
10634
|
theme: structure.theme,
|
|
10292
10635
|
themeName: structure.themeName,
|
|
@@ -10321,10 +10664,10 @@ function compileDocument(structure, layout, warnings = [], images = /* @__PURE__
|
|
|
10321
10664
|
};
|
|
10322
10665
|
ctx.features.require("paragraphs", "sections");
|
|
10323
10666
|
ctx.features.require("styles", "styles");
|
|
10324
|
-
if (
|
|
10325
|
-
const ordinals = computeSectionOrdinals(
|
|
10326
|
-
const chrome = resolveSectionChrome(
|
|
10327
|
-
const sections =
|
|
10667
|
+
if (layout2.sections.length > 1) ctx.features.require("sections", "sections");
|
|
10668
|
+
const ordinals = computeSectionOrdinals(layout2.sections);
|
|
10669
|
+
const chrome = resolveSectionChrome(layout2.sections);
|
|
10670
|
+
const sections = layout2.sections.map(
|
|
10328
10671
|
(section2, index) => compileSection(section2, index, ordinals[index], chrome[index], ctx)
|
|
10329
10672
|
);
|
|
10330
10673
|
if (ctx.hasResolvedComment && !ctx.comments.some((comment) => comment.parentId !== void 0)) {
|
|
@@ -10402,9 +10745,9 @@ function separateFromTables(blocks, bodyAfterTwips) {
|
|
|
10402
10745
|
}
|
|
10403
10746
|
}
|
|
10404
10747
|
}
|
|
10405
|
-
function collectOutline(
|
|
10748
|
+
function collectOutline(layout2, warnings) {
|
|
10406
10749
|
try {
|
|
10407
|
-
return collectDocumentOutline(
|
|
10750
|
+
return collectDocumentOutline(layout2.sections);
|
|
10408
10751
|
} catch (error) {
|
|
10409
10752
|
warnings.push({
|
|
10410
10753
|
component: "document",
|
|
@@ -12446,11 +12789,21 @@ function compileChart(component, scope) {
|
|
|
12446
12789
|
);
|
|
12447
12790
|
}
|
|
12448
12791
|
}
|
|
12792
|
+
if (props.type === "scatter") {
|
|
12793
|
+
for (const [index, entry] of series.entries()) {
|
|
12794
|
+
const at = entry.labels.findIndex(isOutOfRangeNumericLabel);
|
|
12795
|
+
if (at !== -1) {
|
|
12796
|
+
throw new Error(
|
|
12797
|
+
`Chart series "${entry.name ?? `series ${index}`}" at ${path4} has an x label ${JSON.stringify(entry.labels[at])} outside the finite number range.`
|
|
12798
|
+
);
|
|
12799
|
+
}
|
|
12800
|
+
}
|
|
12801
|
+
}
|
|
12449
12802
|
if (props.type === "scatter" && series.some((entry) => entry.labels.some((label) => !isNumericLabel(label)))) {
|
|
12450
12803
|
warnOnce(
|
|
12451
12804
|
ctx,
|
|
12452
12805
|
"chart",
|
|
12453
|
-
`Chart at ${path4} is a scatter chart whose labels are not all numbers;
|
|
12806
|
+
`Chart at ${path4} is a scatter chart whose labels are not all finite numbers; labels that do not read as finite numbers use their 1-based positions for x.`
|
|
12454
12807
|
);
|
|
12455
12808
|
}
|
|
12456
12809
|
if ((props.type === "pie" || props.type === "doughnut") && (typeof props.catAxisTitle === "string" || typeof props.valAxisTitle === "string")) {
|
|
@@ -12940,13 +13293,19 @@ function compileTableRow(row, columnTwips, spacing, baseStyle, scope) {
|
|
|
12940
13293
|
...scope.cantSplit !== void 0 ? { cantSplit: scope.cantSplit } : {}
|
|
12941
13294
|
};
|
|
12942
13295
|
}
|
|
13296
|
+
var NORMAL_TABLE_CELL_MARGINS = {
|
|
13297
|
+
topTwips: 0,
|
|
13298
|
+
bottomTwips: 0,
|
|
13299
|
+
leftTwips: 108,
|
|
13300
|
+
rightTwips: 108
|
|
13301
|
+
};
|
|
12943
13302
|
function compileTableCell(cell, columnTwips, spacing, baseStyle, keepNext, partScope, rowRevision, markRevision) {
|
|
12944
|
-
const margins =
|
|
13303
|
+
const margins = cell.missing ? void 0 : cell.padding ? {
|
|
12945
13304
|
topTwips: pointsToTwips2(cell.padding.top),
|
|
12946
13305
|
bottomTwips: pointsToTwips2(cell.padding.bottom),
|
|
12947
13306
|
leftTwips: pointsToTwips2(cell.padding.left),
|
|
12948
13307
|
rightTwips: pointsToTwips2(cell.padding.right)
|
|
12949
|
-
} :
|
|
13308
|
+
} : NORMAL_TABLE_CELL_MARGINS;
|
|
12950
13309
|
const scope = {
|
|
12951
13310
|
...partScope,
|
|
12952
13311
|
measureTwips: cellMeasureTwips(columnTwips, margins)
|
|
@@ -13451,8 +13810,8 @@ function hasPageBreak(component) {
|
|
|
13451
13810
|
}
|
|
13452
13811
|
return false;
|
|
13453
13812
|
}
|
|
13454
|
-
function getColumnSettings(
|
|
13455
|
-
switch (
|
|
13813
|
+
function getColumnSettings(layout2) {
|
|
13814
|
+
switch (layout2) {
|
|
13456
13815
|
case "multi-column":
|
|
13457
13816
|
return {
|
|
13458
13817
|
count: 2,
|
|
@@ -15895,19 +16254,19 @@ async function compileDocumentScoped(document, options, warnings) {
|
|
|
15895
16254
|
context.themeName,
|
|
15896
16255
|
resolveGenerationDate(options)
|
|
15897
16256
|
);
|
|
15898
|
-
const
|
|
16257
|
+
const layout2 = applyLayout(
|
|
15899
16258
|
structure.sections,
|
|
15900
16259
|
context.theme,
|
|
15901
16260
|
context.themeName
|
|
15902
16261
|
);
|
|
15903
16262
|
const images = await loadImageResources(
|
|
15904
|
-
|
|
16263
|
+
layout2.sections.flatMap((section2) => [
|
|
15905
16264
|
...section2.components,
|
|
15906
16265
|
...Array.isArray(section2.header) ? section2.header : [],
|
|
15907
16266
|
...Array.isArray(section2.footer) ? section2.footer : []
|
|
15908
16267
|
])
|
|
15909
16268
|
);
|
|
15910
|
-
const compiled = compileDocument(structure,
|
|
16269
|
+
const compiled = compileDocument(structure, layout2, warnings, images, {
|
|
15911
16270
|
// A caller that collects nothing still needs to hear about a dropped
|
|
15912
16271
|
// value, so warnings go to the console when there is no collector.
|
|
15913
16272
|
echoWarnings: options.warnings === void 0
|