documents.js 2.3.2 → 3.0.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/README.md +27 -14
- package/dist/codecs/registry.d.cts +8 -3
- package/dist/codecs/registry.d.ts +8 -3
- package/dist/convert/canonicalise.cjs +20 -0
- package/dist/convert/canonicalise.d.cts +5 -0
- package/dist/convert/canonicalise.d.ts +5 -0
- package/dist/convert/canonicalise.js +18 -0
- package/dist/convert/composition.cjs +29 -28
- package/dist/convert/composition.d.cts +1 -1
- package/dist/convert/composition.d.ts +1 -1
- package/dist/convert/composition.js +29 -28
- package/dist/convert/convert.cjs +14 -26
- package/dist/convert/convert.d.cts +1 -1
- package/dist/convert/convert.d.ts +1 -1
- package/dist/convert/convert.js +14 -26
- package/dist/convert/decompose.cjs +134 -0
- package/dist/convert/decompose.d.cts +13 -0
- package/dist/convert/decompose.d.ts +13 -0
- package/dist/convert/decompose.js +126 -0
- package/dist/convert/factor-styles.cjs +364 -0
- package/dist/convert/factor-styles.d.cts +6 -0
- package/dist/convert/factor-styles.d.ts +6 -0
- package/dist/convert/factor-styles.js +362 -0
- package/dist/convert/flatten.cjs +137 -0
- package/dist/convert/flatten.d.cts +5 -0
- package/dist/convert/flatten.d.ts +5 -0
- package/dist/convert/flatten.js +136 -0
- package/dist/convert/from-package.cjs +4 -3
- package/dist/convert/from-package.d.cts +2 -1
- package/dist/convert/from-package.d.ts +2 -1
- package/dist/convert/from-package.js +5 -4
- package/dist/convert/local.cjs +1 -1
- package/dist/convert/local.js +1 -1
- package/dist/convert/variant-bridges.cjs +0 -4
- package/dist/convert/variant-bridges.js +1 -5
- package/dist/csv/read.cjs +0 -1
- package/dist/csv/read.js +1 -2
- package/dist/edit/docx/numbering.d.cts +1 -1
- package/dist/edit/docx/numbering.d.ts +1 -1
- package/dist/edit/docx/paragraph.cjs +1 -0
- package/dist/edit/docx/paragraph.js +1 -0
- package/dist/edit/pdf/editor.cjs +1 -2
- package/dist/edit/pdf/editor.d.cts +2 -2
- package/dist/edit/pdf/editor.d.ts +2 -2
- package/dist/edit/pdf/editor.js +1 -2
- package/dist/edit/pdf/item.d.cts +1 -1
- package/dist/edit/pdf/item.d.ts +1 -1
- package/dist/edit/pdf/page.d.cts +2 -2
- package/dist/edit/pdf/page.d.ts +2 -2
- package/dist/edit/pdf/util.d.cts +1 -1
- package/dist/edit/pdf/util.d.ts +1 -1
- package/dist/fonts/registry.d.cts +1 -1
- package/dist/fonts/registry.d.ts +1 -1
- package/dist/index.cjs +10 -15
- package/dist/index.d.cts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +6 -3
- package/dist/{item-Dj6f1VTE.d.cts → item-D9vQKT0T.d.cts} +2 -1
- package/dist/{item-Dj6f1VTE.d.ts → item-D9vQKT0T.d.ts} +2 -1
- package/dist/latex/lint.cjs +3 -2
- package/dist/latex/lint.js +3 -2
- package/dist/layout/drawing.d.cts +2 -1
- package/dist/layout/drawing.d.ts +2 -1
- package/dist/layout/engine.cjs +8 -5
- package/dist/layout/engine.d.cts +2 -1
- package/dist/layout/engine.d.ts +2 -1
- package/dist/layout/engine.js +8 -5
- package/dist/layout/lattice.d.cts +1 -1
- package/dist/layout/lattice.d.ts +1 -1
- package/dist/layout/reconstruct.cjs +0 -5
- package/dist/layout/reconstruct.d.cts +2 -1
- package/dist/layout/reconstruct.d.ts +2 -1
- package/dist/layout/reconstruct.js +0 -5
- package/dist/layout/shared.cjs +2 -1
- package/dist/layout/shared.d.cts +2 -1
- package/dist/layout/shared.d.ts +2 -1
- package/dist/layout/shared.js +2 -1
- package/dist/layout/sheets.d.cts +2 -1
- package/dist/layout/sheets.d.ts +2 -1
- package/dist/layout/slides.d.cts +2 -1
- package/dist/layout/slides.d.ts +2 -1
- package/dist/markdown/render.cjs +0 -1
- package/dist/markdown/render.js +1 -2
- package/dist/model/embedded-drawing.cjs +5 -8
- package/dist/model/embedded-drawing.js +5 -8
- package/dist/model/formula.cjs +0 -2
- package/dist/model/formula.js +0 -2
- package/dist/odb/report/render.cjs +0 -1
- package/dist/odb/report/render.js +1 -2
- package/dist/odb/spreadsheet.cjs +0 -1
- package/dist/odb/spreadsheet.js +1 -2
- package/dist/odf/odg/read.cjs +0 -2
- package/dist/odf/odg/read.js +0 -2
- package/dist/odf/odp/read.cjs +0 -2
- package/dist/odf/odp/read.js +0 -2
- package/dist/odf/ods/read.cjs +0 -2
- package/dist/odf/ods/read.js +0 -2
- package/dist/odf/odt/read.cjs +0 -2
- package/dist/odf/odt/read.js +0 -2
- package/dist/ooxml/docx/read.cjs +0 -2
- package/dist/ooxml/docx/read.js +0 -2
- package/dist/ooxml/pptx/read.cjs +0 -2
- package/dist/ooxml/pptx/read.js +0 -2
- package/dist/svg/read.cjs +8 -11
- package/dist/svg/read.js +8 -11
- package/package.json +6 -6
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_convert_flatten = require("./flatten.cjs");
|
|
3
|
+
const require_convert_canonicalise = require("./canonicalise.cjs");
|
|
4
|
+
const require_convert_decompose = require("./decompose.cjs");
|
|
5
|
+
//#region src/convert/factor-styles.ts
|
|
6
|
+
const PARAGRAPH_STYLE_KEYS = [
|
|
7
|
+
"alignment",
|
|
8
|
+
"spacingBeforePt",
|
|
9
|
+
"spacingAfterPt",
|
|
10
|
+
"lineSpacing",
|
|
11
|
+
"indentLeftPt",
|
|
12
|
+
"indentFirstLinePt"
|
|
13
|
+
];
|
|
14
|
+
const RUN_STYLE_KEYS = [
|
|
15
|
+
"bold",
|
|
16
|
+
"italic",
|
|
17
|
+
"underline",
|
|
18
|
+
"strike",
|
|
19
|
+
"fontFamily",
|
|
20
|
+
"sizePt",
|
|
21
|
+
"color"
|
|
22
|
+
];
|
|
23
|
+
function isShapeGroupWrapper(wrapper) {
|
|
24
|
+
return !("kind" in wrapper.node);
|
|
25
|
+
}
|
|
26
|
+
function isAnchorGroupWrapper(wrapper) {
|
|
27
|
+
return "kind" in wrapper.node && wrapper.node.kind === "paragraph";
|
|
28
|
+
}
|
|
29
|
+
function isSlideGroupWrapper(wrapper) {
|
|
30
|
+
return "kind" in wrapper.node && wrapper.node.kind === "slide";
|
|
31
|
+
}
|
|
32
|
+
function isDrawPageGroupWrapper(wrapper) {
|
|
33
|
+
return "kind" in wrapper.node && wrapper.node.kind === "drawPage";
|
|
34
|
+
}
|
|
35
|
+
function isHeadingGroup(group) {
|
|
36
|
+
return group.node.headingLevel !== void 0;
|
|
37
|
+
}
|
|
38
|
+
function assemblePackage(content, pages) {
|
|
39
|
+
const envelope = {
|
|
40
|
+
metadata: content.metadata,
|
|
41
|
+
...content.symbolTable !== void 0 ? { symbolTable: content.symbolTable } : {},
|
|
42
|
+
...pages !== void 0 ? { pages: [...pages] } : {}
|
|
43
|
+
};
|
|
44
|
+
switch (content.kind) {
|
|
45
|
+
case "wordprocessing": return mint({
|
|
46
|
+
kind: "wordprocessing",
|
|
47
|
+
...envelope,
|
|
48
|
+
children: content.sections.map(require_convert_decompose.decomposeSection)
|
|
49
|
+
});
|
|
50
|
+
case "presentation": return mint({
|
|
51
|
+
kind: "presentation",
|
|
52
|
+
...envelope,
|
|
53
|
+
children: content.slides.map(require_convert_decompose.decomposeSlide)
|
|
54
|
+
});
|
|
55
|
+
case "spreadsheet": return mint({
|
|
56
|
+
kind: "spreadsheet",
|
|
57
|
+
...envelope,
|
|
58
|
+
children: content.sheets.map(require_convert_decompose.decomposeSheet)
|
|
59
|
+
});
|
|
60
|
+
case "drawing": return mint({
|
|
61
|
+
kind: "drawing",
|
|
62
|
+
...envelope,
|
|
63
|
+
children: content.pages.map(require_convert_decompose.decomposeDrawPage)
|
|
64
|
+
});
|
|
65
|
+
case "formula": return mint({
|
|
66
|
+
kind: "formula",
|
|
67
|
+
...envelope,
|
|
68
|
+
children: [content.formula]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function factorStyles(pkg) {
|
|
73
|
+
return assemblePackage(require_convert_flatten.flattenPackage(pkg), pkg.pages);
|
|
74
|
+
}
|
|
75
|
+
function extentOf(wrapper) {
|
|
76
|
+
if (isShapeGroupWrapper(wrapper)) return flowExtent(wrapper.children);
|
|
77
|
+
if (isAnchorGroupWrapper(wrapper)) return [wrapper.node, ...flowExtent(wrapper.children)];
|
|
78
|
+
if (isSlideGroupWrapper(wrapper)) return wrapper.children.flatMap(extentOf);
|
|
79
|
+
if (isDrawPageGroupWrapper(wrapper)) {
|
|
80
|
+
const paragraphs = [];
|
|
81
|
+
for (const child of wrapper.children) if ("node" in child) paragraphs.push(...extentOf(child));
|
|
82
|
+
return paragraphs;
|
|
83
|
+
}
|
|
84
|
+
return flowExtent(wrapper.children);
|
|
85
|
+
}
|
|
86
|
+
function flowExtent(children) {
|
|
87
|
+
const paragraphs = [];
|
|
88
|
+
for (const child of children) if ("node" in child && "children" in child) paragraphs.push(...extentOf(child));
|
|
89
|
+
else if (child.kind === "paragraph") paragraphs.push(child);
|
|
90
|
+
return paragraphs;
|
|
91
|
+
}
|
|
92
|
+
function paragraphTuple(paragraph, keys) {
|
|
93
|
+
const tuple = {};
|
|
94
|
+
for (const key of keys) if (paragraph[key] !== void 0) tuple[key] = paragraph[key];
|
|
95
|
+
return tuple;
|
|
96
|
+
}
|
|
97
|
+
function runTuple(run, keys) {
|
|
98
|
+
const tuple = {};
|
|
99
|
+
for (const key of keys) if (run[key] !== void 0) tuple[key] = run[key];
|
|
100
|
+
return tuple;
|
|
101
|
+
}
|
|
102
|
+
function commonParagraphKeys(extent, frozen) {
|
|
103
|
+
return PARAGRAPH_STYLE_KEYS.filter((key) => !frozen.has(key) && extent.every((paragraph) => paragraph[key] !== void 0));
|
|
104
|
+
}
|
|
105
|
+
function commonRunKeys(extent, frozen) {
|
|
106
|
+
const runs = extent.flatMap((paragraph) => paragraph.runs);
|
|
107
|
+
if (runs.length === 0) return [];
|
|
108
|
+
return RUN_STYLE_KEYS.filter((key) => !frozen.has(key) && runs.every((run) => run[key] !== void 0));
|
|
109
|
+
}
|
|
110
|
+
function bestParagraphCandidate(extent, keys, factored) {
|
|
111
|
+
const groups = /* @__PURE__ */ new Map();
|
|
112
|
+
for (const paragraph of extent) {
|
|
113
|
+
if (factored.has(paragraph)) continue;
|
|
114
|
+
const tuple = paragraphTuple(paragraph, keys);
|
|
115
|
+
if (Object.keys(tuple).length === 0) continue;
|
|
116
|
+
const key = require_convert_canonicalise.canonicalKey(tuple);
|
|
117
|
+
const existing = groups.get(key);
|
|
118
|
+
if (existing === void 0) groups.set(key, {
|
|
119
|
+
tuple,
|
|
120
|
+
keys,
|
|
121
|
+
positions: [paragraph]
|
|
122
|
+
});
|
|
123
|
+
else existing.positions.push(paragraph);
|
|
124
|
+
}
|
|
125
|
+
return bestGroup(groups);
|
|
126
|
+
}
|
|
127
|
+
function bestRunCandidate(extent, keys, factored) {
|
|
128
|
+
const groups = /* @__PURE__ */ new Map();
|
|
129
|
+
for (const paragraph of extent) for (const run of paragraph.runs) {
|
|
130
|
+
if (factored.has(run)) continue;
|
|
131
|
+
const tuple = runTuple(run, keys);
|
|
132
|
+
if (Object.keys(tuple).length === 0) continue;
|
|
133
|
+
const key = require_convert_canonicalise.canonicalKey(tuple);
|
|
134
|
+
const existing = groups.get(key);
|
|
135
|
+
if (existing === void 0) groups.set(key, {
|
|
136
|
+
tuple,
|
|
137
|
+
keys,
|
|
138
|
+
positions: [run]
|
|
139
|
+
});
|
|
140
|
+
else existing.positions.push(run);
|
|
141
|
+
}
|
|
142
|
+
return bestGroup(groups);
|
|
143
|
+
}
|
|
144
|
+
function bestGroup(groups) {
|
|
145
|
+
let best;
|
|
146
|
+
for (const group of groups.values()) {
|
|
147
|
+
if (group.positions.length < 2) continue;
|
|
148
|
+
if (best === void 0 || group.positions.length > best.positions.length) best = group;
|
|
149
|
+
}
|
|
150
|
+
return best;
|
|
151
|
+
}
|
|
152
|
+
function plan(wrapper, visit, frozenParagraphs, frozenRuns, state, entries) {
|
|
153
|
+
const extent = extentOf(wrapper);
|
|
154
|
+
const paragraphCandidate = extent.length > 0 ? bestParagraphCandidate(extent, commonParagraphKeys(extent, frozenParagraphs), state.factoredParagraphs) : void 0;
|
|
155
|
+
const runCandidate = extent.length > 0 ? bestRunCandidate(extent, commonRunKeys(extent, frozenRuns), state.factoredRuns) : void 0;
|
|
156
|
+
const nextFrozenParagraphs = new Set(frozenParagraphs);
|
|
157
|
+
const nextFrozenRuns = new Set(frozenRuns);
|
|
158
|
+
if (paragraphCandidate !== void 0 || runCandidate !== void 0) {
|
|
159
|
+
const content = {
|
|
160
|
+
...paragraphCandidate !== void 0 ? { paragraph: paragraphCandidate.tuple } : {},
|
|
161
|
+
...runCandidate !== void 0 ? { run: runCandidate.tuple } : {}
|
|
162
|
+
};
|
|
163
|
+
const contentKey = require_convert_canonicalise.canonicalKey(content);
|
|
164
|
+
const existing = entries.get(contentKey);
|
|
165
|
+
if (existing === void 0) entries.set(contentKey, {
|
|
166
|
+
content,
|
|
167
|
+
wrappers: [wrapper],
|
|
168
|
+
frequency: (paragraphCandidate?.positions.length ?? 0) + (runCandidate?.positions.length ?? 0),
|
|
169
|
+
firstVisit: visit.index
|
|
170
|
+
});
|
|
171
|
+
else {
|
|
172
|
+
existing.wrappers.push(wrapper);
|
|
173
|
+
existing.frequency += (paragraphCandidate?.positions.length ?? 0) + (runCandidate?.positions.length ?? 0);
|
|
174
|
+
}
|
|
175
|
+
if (paragraphCandidate !== void 0) {
|
|
176
|
+
for (const paragraph of paragraphCandidate.positions) {
|
|
177
|
+
state.factoredParagraphs.add(paragraph);
|
|
178
|
+
state.paragraphStrips.set(paragraph, paragraphCandidate.keys);
|
|
179
|
+
}
|
|
180
|
+
for (const key of paragraphCandidate.keys) nextFrozenParagraphs.add(key);
|
|
181
|
+
}
|
|
182
|
+
if (runCandidate !== void 0) {
|
|
183
|
+
for (const run of runCandidate.positions) {
|
|
184
|
+
state.factoredRuns.add(run);
|
|
185
|
+
state.runStrips.set(run, runCandidate.keys);
|
|
186
|
+
}
|
|
187
|
+
for (const key of runCandidate.keys) nextFrozenRuns.add(key);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
visit.index += 1;
|
|
191
|
+
for (const child of childWrappers(wrapper)) plan(child, visit, nextFrozenParagraphs, nextFrozenRuns, state, entries);
|
|
192
|
+
}
|
|
193
|
+
function childWrappers(wrapper) {
|
|
194
|
+
if (isShapeGroupWrapper(wrapper) || isAnchorGroupWrapper(wrapper)) {
|
|
195
|
+
const wrappers = [];
|
|
196
|
+
for (const child of wrapper.children) if ("node" in child && "children" in child) wrappers.push(child);
|
|
197
|
+
return wrappers;
|
|
198
|
+
}
|
|
199
|
+
if (isSlideGroupWrapper(wrapper)) return [...wrapper.children];
|
|
200
|
+
if (isDrawPageGroupWrapper(wrapper)) {
|
|
201
|
+
const shapes = [];
|
|
202
|
+
for (const child of wrapper.children) if ("node" in child) shapes.push(child);
|
|
203
|
+
return shapes;
|
|
204
|
+
}
|
|
205
|
+
const wrappers = [];
|
|
206
|
+
for (const child of wrapper.children) if ("node" in child && "children" in child) wrappers.push(child);
|
|
207
|
+
return wrappers;
|
|
208
|
+
}
|
|
209
|
+
function mint(pkg) {
|
|
210
|
+
const state = {
|
|
211
|
+
factoredParagraphs: /* @__PURE__ */ new Set(),
|
|
212
|
+
factoredRuns: /* @__PURE__ */ new Set(),
|
|
213
|
+
wrapperRefs: /* @__PURE__ */ new Map(),
|
|
214
|
+
paragraphStrips: /* @__PURE__ */ new Map(),
|
|
215
|
+
runStrips: /* @__PURE__ */ new Map()
|
|
216
|
+
};
|
|
217
|
+
const entries = /* @__PURE__ */ new Map();
|
|
218
|
+
const visit = { index: 0 };
|
|
219
|
+
const emptyParagraphs = /* @__PURE__ */ new Set();
|
|
220
|
+
const emptyRuns = /* @__PURE__ */ new Set();
|
|
221
|
+
switch (pkg.kind) {
|
|
222
|
+
case "wordprocessing":
|
|
223
|
+
for (const root of pkg.children) plan(root, visit, emptyParagraphs, emptyRuns, state, entries);
|
|
224
|
+
break;
|
|
225
|
+
case "presentation":
|
|
226
|
+
for (const root of pkg.children) plan(root, visit, emptyParagraphs, emptyRuns, state, entries);
|
|
227
|
+
break;
|
|
228
|
+
case "drawing": for (const root of pkg.children) plan(root, visit, emptyParagraphs, emptyRuns, state, entries);
|
|
229
|
+
}
|
|
230
|
+
if (entries.size === 0) return pkg;
|
|
231
|
+
const ordered = [...entries.values()].sort((a, b) => b.frequency - a.frequency || a.firstVisit - b.firstVisit || require_convert_canonicalise.canonicalKey(a.content).localeCompare(require_convert_canonicalise.canonicalKey(b.content)));
|
|
232
|
+
const styles = {};
|
|
233
|
+
ordered.forEach((entry, index) => {
|
|
234
|
+
const id = `s${index + 1}`;
|
|
235
|
+
styles[id] = entry.content;
|
|
236
|
+
for (const wrapper of entry.wrappers) state.wrapperRefs.set(wrapper, id);
|
|
237
|
+
});
|
|
238
|
+
switch (pkg.kind) {
|
|
239
|
+
case "wordprocessing": return {
|
|
240
|
+
...pkg,
|
|
241
|
+
styles,
|
|
242
|
+
children: pkg.children.map((group) => rebuildSectionGroup(group, state))
|
|
243
|
+
};
|
|
244
|
+
case "presentation": return {
|
|
245
|
+
...pkg,
|
|
246
|
+
styles,
|
|
247
|
+
children: pkg.children.map((group) => rebuildSlideGroup(group, state))
|
|
248
|
+
};
|
|
249
|
+
case "drawing": return {
|
|
250
|
+
...pkg,
|
|
251
|
+
styles,
|
|
252
|
+
children: pkg.children.map((group) => rebuildDrawPageGroup(group, state))
|
|
253
|
+
};
|
|
254
|
+
case "spreadsheet":
|
|
255
|
+
case "formula": return {
|
|
256
|
+
...pkg,
|
|
257
|
+
styles
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function rebuildSlideGroup(group, state) {
|
|
262
|
+
const children = group.children.map((shape) => rebuildShapeGroup(shape, state));
|
|
263
|
+
const ref = state.wrapperRefs.get(group);
|
|
264
|
+
return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
|
|
265
|
+
node: group.node,
|
|
266
|
+
...ref !== void 0 ? { style: ref } : {},
|
|
267
|
+
children
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
function rebuildDrawPageGroup(group, state) {
|
|
271
|
+
const children = group.children.map((child) => "node" in child ? rebuildShapeGroup(child, state) : child);
|
|
272
|
+
const ref = state.wrapperRefs.get(group);
|
|
273
|
+
return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
|
|
274
|
+
node: group.node,
|
|
275
|
+
...ref !== void 0 ? { style: ref } : {},
|
|
276
|
+
children
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function rebuildSectionGroup(group, state) {
|
|
280
|
+
const children = group.children.map((child) => rebuildSectionChild(child, state));
|
|
281
|
+
const ref = state.wrapperRefs.get(group);
|
|
282
|
+
return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
|
|
283
|
+
node: group.node,
|
|
284
|
+
...ref !== void 0 ? { style: ref } : {},
|
|
285
|
+
children
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function rebuildSectionChild(child, state) {
|
|
289
|
+
if ("node" in child && "children" in child) return isHeadingGroup(child) ? rebuildHeadingGroup(child, state, rebuildSectionChild) : rebuildListGroup(child, state, rebuildListChild);
|
|
290
|
+
if (child.kind === "paragraph") return rebuildParagraph(child, state);
|
|
291
|
+
return child;
|
|
292
|
+
}
|
|
293
|
+
function rebuildListChild(child, state) {
|
|
294
|
+
if ("node" in child && "children" in child) return rebuildListGroup(child, state, rebuildListChild);
|
|
295
|
+
if (child.kind === "paragraph") return rebuildParagraph(child, state);
|
|
296
|
+
return child;
|
|
297
|
+
}
|
|
298
|
+
function rebuildShapeGroup(group, state) {
|
|
299
|
+
const children = group.children.map((child) => rebuildListChild(child, state));
|
|
300
|
+
const ref = state.wrapperRefs.get(group);
|
|
301
|
+
return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
|
|
302
|
+
node: group.node,
|
|
303
|
+
...ref !== void 0 ? { style: ref } : {},
|
|
304
|
+
children
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
function rebuildHeadingGroup(group, state, rebuildChild) {
|
|
308
|
+
const anchor = rebuildParagraph(group.node, state);
|
|
309
|
+
assertHeadingAnchor(anchor);
|
|
310
|
+
const children = group.children.map((child) => rebuildChild(child, state));
|
|
311
|
+
const ref = state.wrapperRefs.get(group);
|
|
312
|
+
return ref === void 0 && anchor === group.node && children.every((child, index) => child === group.children[index]) ? group : {
|
|
313
|
+
node: anchor,
|
|
314
|
+
...ref !== void 0 ? { style: ref } : {},
|
|
315
|
+
children
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
function rebuildListGroup(group, state, rebuildChild) {
|
|
319
|
+
const anchor = rebuildParagraph(group.node, state);
|
|
320
|
+
assertListAnchor(anchor);
|
|
321
|
+
const children = group.children.map((child) => rebuildChild(child, state));
|
|
322
|
+
const ref = state.wrapperRefs.get(group);
|
|
323
|
+
return ref === void 0 && anchor === group.node && children.every((child, index) => child === group.children[index]) ? group : {
|
|
324
|
+
node: anchor,
|
|
325
|
+
...ref !== void 0 ? { style: ref } : {},
|
|
326
|
+
children
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function assertHeadingAnchor(paragraph) {
|
|
330
|
+
if (paragraph.headingLevel === void 0) throw new Error("factorStyles: stripping dropped a heading anchor's headingLevel");
|
|
331
|
+
}
|
|
332
|
+
function assertListAnchor(paragraph) {
|
|
333
|
+
if (paragraph.list === void 0) throw new Error("factorStyles: stripping dropped a list anchor's list membership");
|
|
334
|
+
}
|
|
335
|
+
function rebuildParagraph(paragraph, state) {
|
|
336
|
+
const strips = state.paragraphStrips.get(paragraph);
|
|
337
|
+
const base = strips === void 0 ? paragraph : stripParagraphKeys(paragraph, strips);
|
|
338
|
+
let changed = base !== paragraph;
|
|
339
|
+
const runs = [];
|
|
340
|
+
for (const run of base.runs) {
|
|
341
|
+
const runStrips = state.runStrips.get(run);
|
|
342
|
+
const rebuilt = runStrips === void 0 ? run : stripRunKeys(run, runStrips);
|
|
343
|
+
changed ||= rebuilt !== run;
|
|
344
|
+
runs.push(rebuilt);
|
|
345
|
+
}
|
|
346
|
+
if (!changed) return paragraph;
|
|
347
|
+
return {
|
|
348
|
+
...base,
|
|
349
|
+
runs
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function stripParagraphKeys(paragraph, keys) {
|
|
353
|
+
const copy = { ...paragraph };
|
|
354
|
+
for (const key of keys) delete copy[key];
|
|
355
|
+
return copy;
|
|
356
|
+
}
|
|
357
|
+
function stripRunKeys(run, keys) {
|
|
358
|
+
const copy = { ...run };
|
|
359
|
+
for (const key of keys) delete copy[key];
|
|
360
|
+
return copy;
|
|
361
|
+
}
|
|
362
|
+
//#endregion
|
|
363
|
+
exports.assemblePackage = assemblePackage;
|
|
364
|
+
exports.factorStyles = factorStyles;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ContentDocument, DocumentPackage, PageSize } from "document-schema.js";
|
|
2
|
+
//#region src/convert/factor-styles.d.ts
|
|
3
|
+
declare function assemblePackage(content: ContentDocument, pages?: readonly PageSize[]): DocumentPackage;
|
|
4
|
+
declare function factorStyles(pkg: DocumentPackage): DocumentPackage;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { assemblePackage, factorStyles };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ContentDocument, DocumentPackage, PageSize } from "document-schema.js";
|
|
2
|
+
//#region src/convert/factor-styles.d.ts
|
|
3
|
+
declare function assemblePackage(content: ContentDocument, pages?: readonly PageSize[]): DocumentPackage;
|
|
4
|
+
declare function factorStyles(pkg: DocumentPackage): DocumentPackage;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { assemblePackage, factorStyles };
|