document-model.js 4.2.0 → 4.3.1

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.
Files changed (46) hide show
  1. package/README.md +30 -4
  2. package/dist/canonicalise.cjs +20 -0
  3. package/dist/canonicalise.d.cts +5 -0
  4. package/dist/canonicalise.d.ts +5 -0
  5. package/dist/canonicalise.js +18 -0
  6. package/dist/codec.d.cts +1 -1
  7. package/dist/codec.d.ts +1 -1
  8. package/dist/{construct-CdQuI9f5.d.cts → construct-ETSlnMle.d.cts} +3 -3
  9. package/dist/{construct-CdQuI9f5.d.ts → construct-ETSlnMle.d.ts} +3 -3
  10. package/dist/construct.d.cts +1 -1
  11. package/dist/construct.d.ts +1 -1
  12. package/dist/{content-CIwPb_yh.d.ts → content-32bPQ3aj.d.ts} +1 -1
  13. package/dist/{content-BmqzegMG.d.cts → content-CFXL4jMV.d.cts} +1 -1
  14. package/dist/content.d.cts +1 -1
  15. package/dist/content.d.ts +1 -1
  16. package/dist/decompose.cjs +186 -0
  17. package/dist/decompose.d.cts +18 -0
  18. package/dist/decompose.d.ts +18 -0
  19. package/dist/decompose.js +177 -0
  20. package/dist/definitions.d.cts +1 -1
  21. package/dist/definitions.d.ts +1 -1
  22. package/dist/factor-styles.cjs +435 -0
  23. package/dist/factor-styles.d.cts +9 -0
  24. package/dist/factor-styles.d.ts +9 -0
  25. package/dist/factor-styles.js +432 -0
  26. package/dist/flatten.cjs +154 -0
  27. package/dist/flatten.d.cts +6 -0
  28. package/dist/flatten.d.ts +6 -0
  29. package/dist/flatten.js +153 -0
  30. package/dist/index.cjs +8 -0
  31. package/dist/index.d.cts +8 -5
  32. package/dist/index.d.ts +8 -5
  33. package/dist/index.js +4 -1
  34. package/dist/{package-node-C7RiYhyk.d.ts → package-node-0EHr6E1z.d.ts} +3 -3
  35. package/dist/{package-node-a9CyRaD3.d.cts → package-node-D3XGBWfs.d.cts} +3 -3
  36. package/dist/package-node.d.cts +1 -1
  37. package/dist/package-node.d.ts +1 -1
  38. package/dist/package.d.cts +1 -1
  39. package/dist/package.d.ts +1 -1
  40. package/dist/schema-io.cjs +2 -2
  41. package/dist/schema-io.d.cts +1 -1
  42. package/dist/schema-io.d.ts +1 -1
  43. package/dist/schema-io.js +2 -2
  44. package/package.json +3 -3
  45. package/schemas/content-document.schema.json +3 -3
  46. package/schemas/document-package.schema.json +3 -3
@@ -0,0 +1,177 @@
1
+ import { findConstructMarkerImbalance } from "./content.js";
2
+ //#region src/decompose.ts
3
+ function isHeadingParagraph(paragraph) {
4
+ return paragraph.headingLevel !== void 0;
5
+ }
6
+ function isListParagraph(paragraph) {
7
+ return paragraph.list !== void 0;
8
+ }
9
+ var ConstructMarkerImbalanceError = class extends Error {
10
+ imbalance;
11
+ constructor(imbalance) {
12
+ super(imbalance.kind === "unmatchedEnd" ? `decompose: the constructEnd marker at index ${imbalance.index} of this container's block flow closes no open construct` : `decompose: the constructStart marker at index ${imbalance.index} of this container's block flow is never closed`);
13
+ this.name = "ConstructMarkerImbalanceError";
14
+ this.imbalance = imbalance;
15
+ }
16
+ };
17
+ function decompose(content) {
18
+ switch (content.kind) {
19
+ case "wordprocessing": return content.sections.map(decomposeSection);
20
+ case "presentation": return content.slides.map(decomposeSlide);
21
+ case "spreadsheet": return content.sheets.map(decomposeSheet);
22
+ case "drawing": return content.pages.map(decomposeDrawPage);
23
+ case "formula": return [content.formula];
24
+ }
25
+ }
26
+ function decomposeSection(section) {
27
+ const { blocks, ...rest } = section;
28
+ return {
29
+ node: {
30
+ kind: "section",
31
+ ...rest
32
+ },
33
+ children: decomposeSectionBlocks(blocks)
34
+ };
35
+ }
36
+ function assertBalancedConstructMarkers(blocks) {
37
+ const imbalance = findConstructMarkerImbalance(blocks);
38
+ if (imbalance !== void 0) throw new ConstructMarkerImbalanceError(imbalance);
39
+ }
40
+ function decomposeSectionBlocks(blocks) {
41
+ assertBalancedConstructMarkers(blocks);
42
+ return walkSectionBlocks(blocks.values());
43
+ }
44
+ function walkSectionBlocks(cursor) {
45
+ const root = [];
46
+ const headingStack = [];
47
+ const listStack = [];
48
+ const headingScope = () => headingStack.at(-1)?.children ?? root;
49
+ for (let step = cursor.next(); step.done !== true; step = cursor.next()) {
50
+ const block = step.value;
51
+ if (block.kind === "constructEnd") return root;
52
+ if (block.kind === "constructStart") {
53
+ openConstructGroup(block.descriptor, cursor, listStack, headingScope());
54
+ continue;
55
+ }
56
+ if (block.kind !== "paragraph") {
57
+ const parent = listStack.at(-1);
58
+ (parent !== void 0 ? parent.children : headingScope()).push(block);
59
+ continue;
60
+ }
61
+ if (isHeadingParagraph(block)) {
62
+ listStack.length = 0;
63
+ const level = block.headingLevel;
64
+ for (let top = headingStack.at(-1); top !== void 0 && top.node.headingLevel >= level; top = headingStack.at(-1)) headingStack.pop();
65
+ const group = {
66
+ node: block,
67
+ children: []
68
+ };
69
+ const parent = headingStack.at(-1);
70
+ (parent !== void 0 ? parent.children : root).push(group);
71
+ headingStack.push(group);
72
+ } else if (isListParagraph(block)) openListGroup(listStack, headingScope(), block);
73
+ else {
74
+ listStack.length = 0;
75
+ headingScope().push(block);
76
+ }
77
+ }
78
+ return root;
79
+ }
80
+ function decomposeSlide(slide) {
81
+ const { shapes, ...rest } = slide;
82
+ return {
83
+ node: {
84
+ kind: "slide",
85
+ ...rest
86
+ },
87
+ children: shapes.map(decomposeShape)
88
+ };
89
+ }
90
+ function decomposeSheet(sheet) {
91
+ const { images, embeddedObjects, ...rest } = sheet;
92
+ const children = [...images, ...embeddedObjects ?? []];
93
+ return {
94
+ node: {
95
+ kind: "sheet",
96
+ ...rest
97
+ },
98
+ children
99
+ };
100
+ }
101
+ function decomposeDrawPage(page) {
102
+ const { shapes, vectors, ...rest } = page;
103
+ const children = [...shapes.map(decomposeShape), ...vectors];
104
+ return {
105
+ node: {
106
+ kind: "drawPage",
107
+ ...rest
108
+ },
109
+ children
110
+ };
111
+ }
112
+ function decomposeShape(shape) {
113
+ const { blocks, ...rest } = shape;
114
+ return {
115
+ node: rest,
116
+ children: decomposeShapeBlocks(blocks)
117
+ };
118
+ }
119
+ function decomposeShapeBlocks(blocks) {
120
+ assertBalancedConstructMarkers(blocks);
121
+ return walkShapeBlocks(blocks.values());
122
+ }
123
+ function walkShapeBlocks(cursor) {
124
+ const root = [];
125
+ const listStack = [];
126
+ for (let step = cursor.next(); step.done !== true; step = cursor.next()) {
127
+ const block = step.value;
128
+ if (block.kind === "constructEnd") return root;
129
+ if (block.kind === "constructStart") {
130
+ const parent = listStack.at(-1);
131
+ (parent !== void 0 ? parent.children : root).push({
132
+ node: block.descriptor,
133
+ children: walkShapeBlocks(cursor)
134
+ });
135
+ continue;
136
+ }
137
+ if (block.kind !== "paragraph") {
138
+ const parent = listStack.at(-1);
139
+ (parent !== void 0 ? parent.children : root).push(block);
140
+ continue;
141
+ }
142
+ if (isListParagraph(block)) {
143
+ openListGroup(listStack, root, block);
144
+ continue;
145
+ }
146
+ listStack.length = 0;
147
+ root.push(block);
148
+ }
149
+ return root;
150
+ }
151
+ function openConstructGroup(descriptor, cursor, listStack, headingScope) {
152
+ const parent = listStack.at(-1);
153
+ if (parent === void 0) {
154
+ headingScope.push({
155
+ node: descriptor,
156
+ children: walkSectionBlocks(cursor)
157
+ });
158
+ return;
159
+ }
160
+ parent.children.push({
161
+ node: descriptor,
162
+ children: walkShapeBlocks(cursor)
163
+ });
164
+ }
165
+ function openListGroup(listStack, scopeChildren, paragraph) {
166
+ const level = paragraph.list.level;
167
+ for (let top = listStack.at(-1); top !== void 0 && top.node.list.level >= level; top = listStack.at(-1)) listStack.pop();
168
+ const group = {
169
+ node: paragraph,
170
+ children: []
171
+ };
172
+ const parent = listStack.at(-1);
173
+ (parent !== void 0 ? parent.children : scopeChildren).push(group);
174
+ listStack.push(group);
175
+ }
176
+ //#endregion
177
+ export { ConstructMarkerImbalanceError, decompose, decomposeDrawPage, decomposeSection, decomposeShape, decomposeSheet, decomposeSlide, isHeadingParagraph, isListParagraph };
@@ -1,4 +1,4 @@
1
- import { L as ContentRun, j as ContentParagraph } from "./content-BmqzegMG.cjs";
1
+ import { L as ContentRun, j as ContentParagraph } from "./content-CFXL4jMV.cjs";
2
2
  import { z } from "zod";
3
3
  //#region src/definitions.d.ts
4
4
  declare const StyleParagraphPropertiesSchema: z.ZodObject<{
@@ -1,4 +1,4 @@
1
- import { L as ContentRun, j as ContentParagraph } from "./content-CIwPb_yh.js";
1
+ import { L as ContentRun, j as ContentParagraph } from "./content-32bPQ3aj.js";
2
2
  import { z } from "zod";
3
3
  //#region src/definitions.d.ts
4
4
  declare const StyleParagraphPropertiesSchema: z.ZodObject<{
@@ -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-CFXL4jMV.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-32bPQ3aj.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 };