document-model.js 4.2.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/README.md +30 -4
- package/dist/canonicalise.cjs +20 -0
- package/dist/canonicalise.d.cts +5 -0
- package/dist/canonicalise.d.ts +5 -0
- package/dist/canonicalise.js +18 -0
- package/dist/decompose.cjs +186 -0
- package/dist/decompose.d.cts +18 -0
- package/dist/decompose.d.ts +18 -0
- package/dist/decompose.js +177 -0
- package/dist/factor-styles.cjs +435 -0
- package/dist/factor-styles.d.cts +9 -0
- package/dist/factor-styles.d.ts +9 -0
- package/dist/factor-styles.js +432 -0
- package/dist/flatten.cjs +154 -0
- package/dist/flatten.d.cts +6 -0
- package/dist/flatten.d.ts +6 -0
- package/dist/flatten.js +153 -0
- package/dist/index.cjs +8 -0
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +4 -1
- package/dist/schema-io.cjs +2 -2
- package/dist/schema-io.js +2 -2
- package/package.json +2 -2
- package/schemas/content-document.schema.json +3 -3
- package/schemas/document-package.schema.json +3 -3
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_canonicalise = require("./canonicalise.cjs");
|
|
3
|
+
const require_decompose = require("./decompose.cjs");
|
|
4
|
+
const require_flatten = require("./flatten.cjs");
|
|
5
|
+
//#region src/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 isConstructGroup(child) {
|
|
39
|
+
return "node" in child && "children" in child && child.node.kind !== "paragraph";
|
|
40
|
+
}
|
|
41
|
+
function assemblePackage(content, pages) {
|
|
42
|
+
const envelope = {
|
|
43
|
+
metadata: content.metadata,
|
|
44
|
+
...content.symbolTable !== void 0 ? { symbolTable: content.symbolTable } : {},
|
|
45
|
+
...pages !== void 0 ? { pages: [...pages] } : {}
|
|
46
|
+
};
|
|
47
|
+
switch (content.kind) {
|
|
48
|
+
case "wordprocessing": return mint({
|
|
49
|
+
kind: "wordprocessing",
|
|
50
|
+
...envelope,
|
|
51
|
+
children: content.sections.map(require_decompose.decomposeSection)
|
|
52
|
+
});
|
|
53
|
+
case "presentation": return mint({
|
|
54
|
+
kind: "presentation",
|
|
55
|
+
...envelope,
|
|
56
|
+
children: content.slides.map(require_decompose.decomposeSlide)
|
|
57
|
+
});
|
|
58
|
+
case "spreadsheet": return mint({
|
|
59
|
+
kind: "spreadsheet",
|
|
60
|
+
...envelope,
|
|
61
|
+
children: content.sheets.map(require_decompose.decomposeSheet)
|
|
62
|
+
});
|
|
63
|
+
case "drawing": return mint({
|
|
64
|
+
kind: "drawing",
|
|
65
|
+
...envelope,
|
|
66
|
+
children: content.pages.map(require_decompose.decomposeDrawPage)
|
|
67
|
+
});
|
|
68
|
+
case "formula": return mint({
|
|
69
|
+
kind: "formula",
|
|
70
|
+
...envelope,
|
|
71
|
+
children: [content.formula]
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function factorStyles(pkg) {
|
|
76
|
+
const reassembled = assemblePackage(require_flatten.flattenPackage(pkg), pkg.pages);
|
|
77
|
+
if (pkg.definitions === void 0) return reassembled;
|
|
78
|
+
return {
|
|
79
|
+
...reassembled,
|
|
80
|
+
definitions: pkg.definitions
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function extentOf(wrapper) {
|
|
84
|
+
if (isShapeGroupWrapper(wrapper)) return flowExtent(wrapper.children);
|
|
85
|
+
if (isAnchorGroupWrapper(wrapper)) return [wrapper.node, ...flowExtent(wrapper.children)];
|
|
86
|
+
if (isSlideGroupWrapper(wrapper)) return wrapper.children.flatMap(extentOf);
|
|
87
|
+
if (isDrawPageGroupWrapper(wrapper)) {
|
|
88
|
+
const paragraphs = [];
|
|
89
|
+
for (const child of wrapper.children) if ("node" in child) paragraphs.push(...extentOf(child));
|
|
90
|
+
return paragraphs;
|
|
91
|
+
}
|
|
92
|
+
return flowExtent(wrapper.children);
|
|
93
|
+
}
|
|
94
|
+
function flowExtent(children) {
|
|
95
|
+
const paragraphs = [];
|
|
96
|
+
for (const child of children) if ("node" in child && "children" in child) paragraphs.push(...extentOf(child));
|
|
97
|
+
else if (child.kind === "paragraph") paragraphs.push(child);
|
|
98
|
+
return paragraphs;
|
|
99
|
+
}
|
|
100
|
+
function paragraphTuple(paragraph, keys) {
|
|
101
|
+
const tuple = {};
|
|
102
|
+
for (const key of keys) if (paragraph[key] !== void 0) tuple[key] = paragraph[key];
|
|
103
|
+
return tuple;
|
|
104
|
+
}
|
|
105
|
+
function runTuple(run, keys) {
|
|
106
|
+
const tuple = {};
|
|
107
|
+
for (const key of keys) if (run[key] !== void 0) tuple[key] = run[key];
|
|
108
|
+
return tuple;
|
|
109
|
+
}
|
|
110
|
+
function commonParagraphKeys(extent, frozen) {
|
|
111
|
+
return PARAGRAPH_STYLE_KEYS.filter((key) => !frozen.has(key) && extent.every((paragraph) => paragraph[key] !== void 0));
|
|
112
|
+
}
|
|
113
|
+
function commonRunKeys(extent, frozen) {
|
|
114
|
+
const runs = extent.flatMap((paragraph) => paragraph.runs);
|
|
115
|
+
if (runs.length === 0) return [];
|
|
116
|
+
return RUN_STYLE_KEYS.filter((key) => !frozen.has(key) && runs.every((run) => run[key] !== void 0));
|
|
117
|
+
}
|
|
118
|
+
function bestParagraphCandidate(extent, keys, factored) {
|
|
119
|
+
const groups = /* @__PURE__ */ new Map();
|
|
120
|
+
for (const paragraph of extent) {
|
|
121
|
+
if (factored.has(paragraph)) continue;
|
|
122
|
+
const tuple = paragraphTuple(paragraph, keys);
|
|
123
|
+
if (Object.keys(tuple).length === 0) continue;
|
|
124
|
+
const key = require_canonicalise.canonicalKey(tuple);
|
|
125
|
+
const existing = groups.get(key);
|
|
126
|
+
if (existing === void 0) groups.set(key, {
|
|
127
|
+
tuple,
|
|
128
|
+
keys,
|
|
129
|
+
positions: [paragraph]
|
|
130
|
+
});
|
|
131
|
+
else existing.positions.push(paragraph);
|
|
132
|
+
}
|
|
133
|
+
return bestGroup(groups);
|
|
134
|
+
}
|
|
135
|
+
function bestRunCandidate(extent, keys, factored) {
|
|
136
|
+
const groups = /* @__PURE__ */ new Map();
|
|
137
|
+
for (const paragraph of extent) for (const run of paragraph.runs) {
|
|
138
|
+
if (factored.has(run)) continue;
|
|
139
|
+
const tuple = runTuple(run, keys);
|
|
140
|
+
if (Object.keys(tuple).length === 0) continue;
|
|
141
|
+
const key = require_canonicalise.canonicalKey(tuple);
|
|
142
|
+
const existing = groups.get(key);
|
|
143
|
+
if (existing === void 0) groups.set(key, {
|
|
144
|
+
tuple,
|
|
145
|
+
keys,
|
|
146
|
+
positions: [run]
|
|
147
|
+
});
|
|
148
|
+
else existing.positions.push(run);
|
|
149
|
+
}
|
|
150
|
+
return bestGroup(groups);
|
|
151
|
+
}
|
|
152
|
+
function bestGroup(groups) {
|
|
153
|
+
let best;
|
|
154
|
+
for (const group of groups.values()) {
|
|
155
|
+
if (group.positions.length < 2) continue;
|
|
156
|
+
if (best === void 0 || group.positions.length > best.positions.length) best = group;
|
|
157
|
+
}
|
|
158
|
+
return best;
|
|
159
|
+
}
|
|
160
|
+
function plan(wrapper, visit, branch, state, entries) {
|
|
161
|
+
const extent = extentOf(wrapper);
|
|
162
|
+
const paragraphCandidate = extent.length > 0 ? bestParagraphCandidate(extent, commonParagraphKeys(extent, branch.frozenParagraphs), branch.factoredParagraphs) : void 0;
|
|
163
|
+
const runCandidate = extent.length > 0 ? bestRunCandidate(extent, commonRunKeys(extent, branch.frozenRuns), branch.factoredRuns) : void 0;
|
|
164
|
+
const nextFrozenParagraphs = new Set(branch.frozenParagraphs);
|
|
165
|
+
const nextFrozenRuns = new Set(branch.frozenRuns);
|
|
166
|
+
const nextFactoredParagraphs = new Set(branch.factoredParagraphs);
|
|
167
|
+
const nextFactoredRuns = new Set(branch.factoredRuns);
|
|
168
|
+
if (paragraphCandidate !== void 0 || runCandidate !== void 0) {
|
|
169
|
+
const content = {
|
|
170
|
+
...paragraphCandidate !== void 0 ? { paragraph: paragraphCandidate.tuple } : {},
|
|
171
|
+
...runCandidate !== void 0 ? { run: runCandidate.tuple } : {}
|
|
172
|
+
};
|
|
173
|
+
const contentKey = require_canonicalise.canonicalKey(content);
|
|
174
|
+
const existing = entries.get(contentKey);
|
|
175
|
+
if (existing === void 0) entries.set(contentKey, {
|
|
176
|
+
content,
|
|
177
|
+
wrappers: [wrapper],
|
|
178
|
+
frequency: (paragraphCandidate?.positions.length ?? 0) + (runCandidate?.positions.length ?? 0),
|
|
179
|
+
firstVisit: visit.index
|
|
180
|
+
});
|
|
181
|
+
else {
|
|
182
|
+
existing.wrappers.push(wrapper);
|
|
183
|
+
existing.frequency += (paragraphCandidate?.positions.length ?? 0) + (runCandidate?.positions.length ?? 0);
|
|
184
|
+
}
|
|
185
|
+
const strips = {
|
|
186
|
+
paragraphs: /* @__PURE__ */ new Map(),
|
|
187
|
+
runs: /* @__PURE__ */ new Map()
|
|
188
|
+
};
|
|
189
|
+
if (paragraphCandidate !== void 0) {
|
|
190
|
+
for (const paragraph of paragraphCandidate.positions) {
|
|
191
|
+
nextFactoredParagraphs.add(paragraph);
|
|
192
|
+
strips.paragraphs.set(paragraph, paragraphCandidate.keys);
|
|
193
|
+
}
|
|
194
|
+
for (const key of paragraphCandidate.keys) nextFrozenParagraphs.add(key);
|
|
195
|
+
}
|
|
196
|
+
if (runCandidate !== void 0) {
|
|
197
|
+
for (const run of runCandidate.positions) {
|
|
198
|
+
nextFactoredRuns.add(run);
|
|
199
|
+
strips.runs.set(run, runCandidate.keys);
|
|
200
|
+
}
|
|
201
|
+
for (const key of runCandidate.keys) nextFrozenRuns.add(key);
|
|
202
|
+
}
|
|
203
|
+
state.wrapperStrips.set(wrapper, strips);
|
|
204
|
+
}
|
|
205
|
+
visit.index += 1;
|
|
206
|
+
const next = {
|
|
207
|
+
frozenParagraphs: nextFrozenParagraphs,
|
|
208
|
+
frozenRuns: nextFrozenRuns,
|
|
209
|
+
factoredParagraphs: nextFactoredParagraphs,
|
|
210
|
+
factoredRuns: nextFactoredRuns
|
|
211
|
+
};
|
|
212
|
+
for (const child of childWrappers(wrapper)) plan(child, visit, next, state, entries);
|
|
213
|
+
}
|
|
214
|
+
function childWrappers(wrapper) {
|
|
215
|
+
if (isShapeGroupWrapper(wrapper) || isAnchorGroupWrapper(wrapper)) {
|
|
216
|
+
const wrappers = [];
|
|
217
|
+
for (const child of wrapper.children) if ("node" in child && "children" in child) wrappers.push(child);
|
|
218
|
+
return wrappers;
|
|
219
|
+
}
|
|
220
|
+
if (isSlideGroupWrapper(wrapper)) return [...wrapper.children];
|
|
221
|
+
if (isDrawPageGroupWrapper(wrapper)) {
|
|
222
|
+
const shapes = [];
|
|
223
|
+
for (const child of wrapper.children) if ("node" in child) shapes.push(child);
|
|
224
|
+
return shapes;
|
|
225
|
+
}
|
|
226
|
+
const wrappers = [];
|
|
227
|
+
for (const child of wrapper.children) if ("node" in child && "children" in child) wrappers.push(child);
|
|
228
|
+
return wrappers;
|
|
229
|
+
}
|
|
230
|
+
function mint(pkg) {
|
|
231
|
+
const state = {
|
|
232
|
+
wrapperRefs: /* @__PURE__ */ new Map(),
|
|
233
|
+
wrapperStrips: /* @__PURE__ */ new Map()
|
|
234
|
+
};
|
|
235
|
+
const entries = /* @__PURE__ */ new Map();
|
|
236
|
+
const visit = { index: 0 };
|
|
237
|
+
const rootBranch = {
|
|
238
|
+
frozenParagraphs: /* @__PURE__ */ new Set(),
|
|
239
|
+
frozenRuns: /* @__PURE__ */ new Set(),
|
|
240
|
+
factoredParagraphs: /* @__PURE__ */ new Set(),
|
|
241
|
+
factoredRuns: /* @__PURE__ */ new Set()
|
|
242
|
+
};
|
|
243
|
+
switch (pkg.kind) {
|
|
244
|
+
case "wordprocessing":
|
|
245
|
+
for (const root of pkg.children) plan(root, visit, rootBranch, state, entries);
|
|
246
|
+
break;
|
|
247
|
+
case "presentation":
|
|
248
|
+
for (const root of pkg.children) plan(root, visit, rootBranch, state, entries);
|
|
249
|
+
break;
|
|
250
|
+
case "drawing": for (const root of pkg.children) plan(root, visit, rootBranch, state, entries);
|
|
251
|
+
}
|
|
252
|
+
if (entries.size === 0) return pkg;
|
|
253
|
+
const ordered = [...entries.values()].sort((a, b) => b.frequency - a.frequency || a.firstVisit - b.firstVisit);
|
|
254
|
+
const styles = {};
|
|
255
|
+
ordered.forEach((entry, index) => {
|
|
256
|
+
const id = `s${index + 1}`;
|
|
257
|
+
styles[id] = entry.content;
|
|
258
|
+
for (const wrapper of entry.wrappers) state.wrapperRefs.set(wrapper, id);
|
|
259
|
+
});
|
|
260
|
+
switch (pkg.kind) {
|
|
261
|
+
case "wordprocessing": return {
|
|
262
|
+
...pkg,
|
|
263
|
+
styles,
|
|
264
|
+
children: pkg.children.map((group) => rebuildSectionGroup(group, [], state))
|
|
265
|
+
};
|
|
266
|
+
case "presentation": return {
|
|
267
|
+
...pkg,
|
|
268
|
+
styles,
|
|
269
|
+
children: pkg.children.map((group) => rebuildSlideGroup(group, [], state))
|
|
270
|
+
};
|
|
271
|
+
case "drawing": return {
|
|
272
|
+
...pkg,
|
|
273
|
+
styles,
|
|
274
|
+
children: pkg.children.map((group) => rebuildDrawPageGroup(group, [], state))
|
|
275
|
+
};
|
|
276
|
+
case "spreadsheet":
|
|
277
|
+
case "formula": return {
|
|
278
|
+
...pkg,
|
|
279
|
+
styles
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function innerChain(group, chain, state) {
|
|
284
|
+
const own = state.wrapperStrips.get(group);
|
|
285
|
+
return own === void 0 ? chain : [...chain, own];
|
|
286
|
+
}
|
|
287
|
+
function paragraphStripsOf(chain, paragraph) {
|
|
288
|
+
let result;
|
|
289
|
+
for (const strips of chain) {
|
|
290
|
+
const found = strips.paragraphs.get(paragraph);
|
|
291
|
+
if (found !== void 0) result = found;
|
|
292
|
+
}
|
|
293
|
+
return result;
|
|
294
|
+
}
|
|
295
|
+
function runStripsOf(chain, run) {
|
|
296
|
+
let result;
|
|
297
|
+
for (const strips of chain) {
|
|
298
|
+
const found = strips.runs.get(run);
|
|
299
|
+
if (found !== void 0) result = found;
|
|
300
|
+
}
|
|
301
|
+
return result;
|
|
302
|
+
}
|
|
303
|
+
function rebuildSlideGroup(group, chain, state) {
|
|
304
|
+
const inner = innerChain(group, chain, state);
|
|
305
|
+
const children = group.children.map((shape) => rebuildShapeGroup(shape, inner, state));
|
|
306
|
+
const ref = state.wrapperRefs.get(group);
|
|
307
|
+
return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
|
|
308
|
+
node: group.node,
|
|
309
|
+
...ref !== void 0 ? { style: ref } : {},
|
|
310
|
+
children
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function rebuildDrawPageGroup(group, chain, state) {
|
|
314
|
+
const inner = innerChain(group, chain, state);
|
|
315
|
+
const children = group.children.map((child) => "node" in child ? rebuildShapeGroup(child, inner, state) : child);
|
|
316
|
+
const ref = state.wrapperRefs.get(group);
|
|
317
|
+
return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
|
|
318
|
+
node: group.node,
|
|
319
|
+
...ref !== void 0 ? { style: ref } : {},
|
|
320
|
+
children
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
function rebuildSectionGroup(group, chain, state) {
|
|
324
|
+
const inner = innerChain(group, chain, state);
|
|
325
|
+
const children = group.children.map((child) => rebuildSectionChild(child, inner, state));
|
|
326
|
+
const ref = state.wrapperRefs.get(group);
|
|
327
|
+
return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
|
|
328
|
+
node: group.node,
|
|
329
|
+
...ref !== void 0 ? { style: ref } : {},
|
|
330
|
+
children
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function rebuildSectionChild(child, chain, state) {
|
|
334
|
+
if (isConstructGroup(child)) return rebuildSectionConstructGroup(child, chain, state);
|
|
335
|
+
if ("node" in child && "children" in child) return isHeadingGroup(child) ? rebuildHeadingGroup(child, chain, state, rebuildSectionChild) : rebuildListGroup(child, chain, state, rebuildListChild);
|
|
336
|
+
if (child.kind === "paragraph") return rebuildParagraph(child, chain);
|
|
337
|
+
return child;
|
|
338
|
+
}
|
|
339
|
+
function rebuildListChild(child, chain, state) {
|
|
340
|
+
if (isConstructGroup(child)) return rebuildShapeConstructGroup(child, chain, state);
|
|
341
|
+
if ("node" in child && "children" in child) return rebuildListGroup(child, chain, state, rebuildListChild);
|
|
342
|
+
if (child.kind === "paragraph") return rebuildParagraph(child, chain);
|
|
343
|
+
return child;
|
|
344
|
+
}
|
|
345
|
+
function rebuildShapeGroup(group, chain, state) {
|
|
346
|
+
const inner = innerChain(group, chain, state);
|
|
347
|
+
const children = group.children.map((child) => rebuildListChild(child, inner, state));
|
|
348
|
+
const ref = state.wrapperRefs.get(group);
|
|
349
|
+
return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
|
|
350
|
+
node: group.node,
|
|
351
|
+
...ref !== void 0 ? { style: ref } : {},
|
|
352
|
+
children
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function rebuildSectionConstructGroup(group, chain, state) {
|
|
356
|
+
const inner = innerChain(group, chain, state);
|
|
357
|
+
const children = group.children.map((child) => rebuildSectionChild(child, inner, state));
|
|
358
|
+
const ref = state.wrapperRefs.get(group);
|
|
359
|
+
return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
|
|
360
|
+
node: group.node,
|
|
361
|
+
...ref !== void 0 ? { style: ref } : {},
|
|
362
|
+
children
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function rebuildShapeConstructGroup(group, chain, state) {
|
|
366
|
+
const inner = innerChain(group, chain, state);
|
|
367
|
+
const children = group.children.map((child) => rebuildListChild(child, inner, state));
|
|
368
|
+
const ref = state.wrapperRefs.get(group);
|
|
369
|
+
return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
|
|
370
|
+
node: group.node,
|
|
371
|
+
...ref !== void 0 ? { style: ref } : {},
|
|
372
|
+
children
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function rebuildHeadingGroup(group, chain, state, rebuildChild) {
|
|
376
|
+
const inner = innerChain(group, chain, state);
|
|
377
|
+
const anchor = rebuildParagraph(group.node, inner);
|
|
378
|
+
assertHeadingAnchor(anchor);
|
|
379
|
+
const children = group.children.map((child) => rebuildChild(child, inner, state));
|
|
380
|
+
const ref = state.wrapperRefs.get(group);
|
|
381
|
+
return ref === void 0 && anchor === group.node && children.every((child, index) => child === group.children[index]) ? group : {
|
|
382
|
+
node: anchor,
|
|
383
|
+
...ref !== void 0 ? { style: ref } : {},
|
|
384
|
+
children
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
function rebuildListGroup(group, chain, state, rebuildChild) {
|
|
388
|
+
const inner = innerChain(group, chain, state);
|
|
389
|
+
const anchor = rebuildParagraph(group.node, inner);
|
|
390
|
+
assertListAnchor(anchor);
|
|
391
|
+
const children = group.children.map((child) => rebuildChild(child, inner, state));
|
|
392
|
+
const ref = state.wrapperRefs.get(group);
|
|
393
|
+
return ref === void 0 && anchor === group.node && children.every((child, index) => child === group.children[index]) ? group : {
|
|
394
|
+
node: anchor,
|
|
395
|
+
...ref !== void 0 ? { style: ref } : {},
|
|
396
|
+
children
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
function assertHeadingAnchor(paragraph) {
|
|
400
|
+
if (paragraph.headingLevel === void 0) throw new Error("factorStyles: stripping dropped a heading anchor's headingLevel");
|
|
401
|
+
}
|
|
402
|
+
function assertListAnchor(paragraph) {
|
|
403
|
+
if (paragraph.list === void 0) throw new Error("factorStyles: stripping dropped a list anchor's list membership");
|
|
404
|
+
}
|
|
405
|
+
function rebuildParagraph(paragraph, chain) {
|
|
406
|
+
const strips = paragraphStripsOf(chain, paragraph);
|
|
407
|
+
const base = strips === void 0 ? paragraph : stripParagraphKeys(paragraph, strips);
|
|
408
|
+
let changed = base !== paragraph;
|
|
409
|
+
const runs = [];
|
|
410
|
+
for (const run of base.runs) {
|
|
411
|
+
const runStrips = runStripsOf(chain, run);
|
|
412
|
+
const rebuilt = runStrips === void 0 ? run : stripRunKeys(run, runStrips);
|
|
413
|
+
changed ||= rebuilt !== run;
|
|
414
|
+
runs.push(rebuilt);
|
|
415
|
+
}
|
|
416
|
+
if (!changed) return paragraph;
|
|
417
|
+
return {
|
|
418
|
+
...base,
|
|
419
|
+
runs
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
function stripParagraphKeys(paragraph, keys) {
|
|
423
|
+
const copy = { ...paragraph };
|
|
424
|
+
for (const key of keys) delete copy[key];
|
|
425
|
+
return copy;
|
|
426
|
+
}
|
|
427
|
+
function stripRunKeys(run, keys) {
|
|
428
|
+
const copy = { ...run };
|
|
429
|
+
for (const key of keys) delete copy[key];
|
|
430
|
+
return copy;
|
|
431
|
+
}
|
|
432
|
+
//#endregion
|
|
433
|
+
exports.assemblePackage = assemblePackage;
|
|
434
|
+
exports.factorStyles = factorStyles;
|
|
435
|
+
exports.mint = mint;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { l as PageSize } from "./geometry-CvcjSwnA.cjs";
|
|
2
|
+
import { m as ContentDocument } from "./content-BmqzegMG.cjs";
|
|
3
|
+
import { DocumentPackage } from "./package.cjs";
|
|
4
|
+
//#region src/factor-styles.d.ts
|
|
5
|
+
declare function assemblePackage(content: ContentDocument, pages?: readonly PageSize[]): DocumentPackage;
|
|
6
|
+
declare function factorStyles(pkg: DocumentPackage): DocumentPackage;
|
|
7
|
+
declare function mint(pkg: DocumentPackage): DocumentPackage;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { assemblePackage, factorStyles, mint };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { l as PageSize } from "./geometry-CvcjSwnA.js";
|
|
2
|
+
import { m as ContentDocument } from "./content-CIwPb_yh.js";
|
|
3
|
+
import { DocumentPackage } from "./package.js";
|
|
4
|
+
//#region src/factor-styles.d.ts
|
|
5
|
+
declare function assemblePackage(content: ContentDocument, pages?: readonly PageSize[]): DocumentPackage;
|
|
6
|
+
declare function factorStyles(pkg: DocumentPackage): DocumentPackage;
|
|
7
|
+
declare function mint(pkg: DocumentPackage): DocumentPackage;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { assemblePackage, factorStyles, mint };
|