js.documents 3.0.0 → 3.0.2

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.
@@ -70,7 +70,12 @@ function assemblePackage(content, pages) {
70
70
  }
71
71
  }
72
72
  function factorStyles(pkg) {
73
- return assemblePackage(require_convert_flatten.flattenPackage(pkg), pkg.pages);
73
+ const reassembled = assemblePackage(require_convert_flatten.flattenPackage(pkg), pkg.pages);
74
+ if (pkg.definitions === void 0) return reassembled;
75
+ return {
76
+ ...reassembled,
77
+ definitions: pkg.definitions
78
+ };
74
79
  }
75
80
  function extentOf(wrapper) {
76
81
  if (isShapeGroupWrapper(wrapper)) return flowExtent(wrapper.children);
@@ -149,12 +154,14 @@ function bestGroup(groups) {
149
154
  }
150
155
  return best;
151
156
  }
152
- function plan(wrapper, visit, frozenParagraphs, frozenRuns, state, entries) {
157
+ function plan(wrapper, visit, branch, state, entries) {
153
158
  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);
159
+ const paragraphCandidate = extent.length > 0 ? bestParagraphCandidate(extent, commonParagraphKeys(extent, branch.frozenParagraphs), branch.factoredParagraphs) : void 0;
160
+ const runCandidate = extent.length > 0 ? bestRunCandidate(extent, commonRunKeys(extent, branch.frozenRuns), branch.factoredRuns) : void 0;
161
+ const nextFrozenParagraphs = new Set(branch.frozenParagraphs);
162
+ const nextFrozenRuns = new Set(branch.frozenRuns);
163
+ const nextFactoredParagraphs = new Set(branch.factoredParagraphs);
164
+ const nextFactoredRuns = new Set(branch.factoredRuns);
158
165
  if (paragraphCandidate !== void 0 || runCandidate !== void 0) {
159
166
  const content = {
160
167
  ...paragraphCandidate !== void 0 ? { paragraph: paragraphCandidate.tuple } : {},
@@ -172,23 +179,34 @@ function plan(wrapper, visit, frozenParagraphs, frozenRuns, state, entries) {
172
179
  existing.wrappers.push(wrapper);
173
180
  existing.frequency += (paragraphCandidate?.positions.length ?? 0) + (runCandidate?.positions.length ?? 0);
174
181
  }
182
+ const strips = {
183
+ paragraphs: /* @__PURE__ */ new Map(),
184
+ runs: /* @__PURE__ */ new Map()
185
+ };
175
186
  if (paragraphCandidate !== void 0) {
176
187
  for (const paragraph of paragraphCandidate.positions) {
177
- state.factoredParagraphs.add(paragraph);
178
- state.paragraphStrips.set(paragraph, paragraphCandidate.keys);
188
+ nextFactoredParagraphs.add(paragraph);
189
+ strips.paragraphs.set(paragraph, paragraphCandidate.keys);
179
190
  }
180
191
  for (const key of paragraphCandidate.keys) nextFrozenParagraphs.add(key);
181
192
  }
182
193
  if (runCandidate !== void 0) {
183
194
  for (const run of runCandidate.positions) {
184
- state.factoredRuns.add(run);
185
- state.runStrips.set(run, runCandidate.keys);
195
+ nextFactoredRuns.add(run);
196
+ strips.runs.set(run, runCandidate.keys);
186
197
  }
187
198
  for (const key of runCandidate.keys) nextFrozenRuns.add(key);
188
199
  }
200
+ state.wrapperStrips.set(wrapper, strips);
189
201
  }
190
202
  visit.index += 1;
191
- for (const child of childWrappers(wrapper)) plan(child, visit, nextFrozenParagraphs, nextFrozenRuns, state, entries);
203
+ const next = {
204
+ frozenParagraphs: nextFrozenParagraphs,
205
+ frozenRuns: nextFrozenRuns,
206
+ factoredParagraphs: nextFactoredParagraphs,
207
+ factoredRuns: nextFactoredRuns
208
+ };
209
+ for (const child of childWrappers(wrapper)) plan(child, visit, next, state, entries);
192
210
  }
193
211
  function childWrappers(wrapper) {
194
212
  if (isShapeGroupWrapper(wrapper) || isAnchorGroupWrapper(wrapper)) {
@@ -208,27 +226,28 @@ function childWrappers(wrapper) {
208
226
  }
209
227
  function mint(pkg) {
210
228
  const state = {
211
- factoredParagraphs: /* @__PURE__ */ new Set(),
212
- factoredRuns: /* @__PURE__ */ new Set(),
213
229
  wrapperRefs: /* @__PURE__ */ new Map(),
214
- paragraphStrips: /* @__PURE__ */ new Map(),
215
- runStrips: /* @__PURE__ */ new Map()
230
+ wrapperStrips: /* @__PURE__ */ new Map()
216
231
  };
217
232
  const entries = /* @__PURE__ */ new Map();
218
233
  const visit = { index: 0 };
219
- const emptyParagraphs = /* @__PURE__ */ new Set();
220
- const emptyRuns = /* @__PURE__ */ new Set();
234
+ const rootBranch = {
235
+ frozenParagraphs: /* @__PURE__ */ new Set(),
236
+ frozenRuns: /* @__PURE__ */ new Set(),
237
+ factoredParagraphs: /* @__PURE__ */ new Set(),
238
+ factoredRuns: /* @__PURE__ */ new Set()
239
+ };
221
240
  switch (pkg.kind) {
222
241
  case "wordprocessing":
223
- for (const root of pkg.children) plan(root, visit, emptyParagraphs, emptyRuns, state, entries);
242
+ for (const root of pkg.children) plan(root, visit, rootBranch, state, entries);
224
243
  break;
225
244
  case "presentation":
226
- for (const root of pkg.children) plan(root, visit, emptyParagraphs, emptyRuns, state, entries);
245
+ for (const root of pkg.children) plan(root, visit, rootBranch, state, entries);
227
246
  break;
228
- case "drawing": for (const root of pkg.children) plan(root, visit, emptyParagraphs, emptyRuns, state, entries);
247
+ case "drawing": for (const root of pkg.children) plan(root, visit, rootBranch, state, entries);
229
248
  }
230
249
  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)));
250
+ const ordered = [...entries.values()].sort((a, b) => b.frequency - a.frequency || a.firstVisit - b.firstVisit);
232
251
  const styles = {};
233
252
  ordered.forEach((entry, index) => {
234
253
  const id = `s${index + 1}`;
@@ -239,17 +258,17 @@ function mint(pkg) {
239
258
  case "wordprocessing": return {
240
259
  ...pkg,
241
260
  styles,
242
- children: pkg.children.map((group) => rebuildSectionGroup(group, state))
261
+ children: pkg.children.map((group) => rebuildSectionGroup(group, [], state))
243
262
  };
244
263
  case "presentation": return {
245
264
  ...pkg,
246
265
  styles,
247
- children: pkg.children.map((group) => rebuildSlideGroup(group, state))
266
+ children: pkg.children.map((group) => rebuildSlideGroup(group, [], state))
248
267
  };
249
268
  case "drawing": return {
250
269
  ...pkg,
251
270
  styles,
252
- children: pkg.children.map((group) => rebuildDrawPageGroup(group, state))
271
+ children: pkg.children.map((group) => rebuildDrawPageGroup(group, [], state))
253
272
  };
254
273
  case "spreadsheet":
255
274
  case "formula": return {
@@ -258,8 +277,29 @@ function mint(pkg) {
258
277
  };
259
278
  }
260
279
  }
261
- function rebuildSlideGroup(group, state) {
262
- const children = group.children.map((shape) => rebuildShapeGroup(shape, state));
280
+ function innerChain(group, chain, state) {
281
+ const own = state.wrapperStrips.get(group);
282
+ return own === void 0 ? chain : [...chain, own];
283
+ }
284
+ function paragraphStripsOf(chain, paragraph) {
285
+ let result;
286
+ for (const strips of chain) {
287
+ const found = strips.paragraphs.get(paragraph);
288
+ if (found !== void 0) result = found;
289
+ }
290
+ return result;
291
+ }
292
+ function runStripsOf(chain, run) {
293
+ let result;
294
+ for (const strips of chain) {
295
+ const found = strips.runs.get(run);
296
+ if (found !== void 0) result = found;
297
+ }
298
+ return result;
299
+ }
300
+ function rebuildSlideGroup(group, chain, state) {
301
+ const inner = innerChain(group, chain, state);
302
+ const children = group.children.map((shape) => rebuildShapeGroup(shape, inner, state));
263
303
  const ref = state.wrapperRefs.get(group);
264
304
  return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
265
305
  node: group.node,
@@ -267,8 +307,9 @@ function rebuildSlideGroup(group, state) {
267
307
  children
268
308
  };
269
309
  }
270
- function rebuildDrawPageGroup(group, state) {
271
- const children = group.children.map((child) => "node" in child ? rebuildShapeGroup(child, state) : child);
310
+ function rebuildDrawPageGroup(group, chain, state) {
311
+ const inner = innerChain(group, chain, state);
312
+ const children = group.children.map((child) => "node" in child ? rebuildShapeGroup(child, inner, state) : child);
272
313
  const ref = state.wrapperRefs.get(group);
273
314
  return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
274
315
  node: group.node,
@@ -276,8 +317,9 @@ function rebuildDrawPageGroup(group, state) {
276
317
  children
277
318
  };
278
319
  }
279
- function rebuildSectionGroup(group, state) {
280
- const children = group.children.map((child) => rebuildSectionChild(child, state));
320
+ function rebuildSectionGroup(group, chain, state) {
321
+ const inner = innerChain(group, chain, state);
322
+ const children = group.children.map((child) => rebuildSectionChild(child, inner, state));
281
323
  const ref = state.wrapperRefs.get(group);
282
324
  return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
283
325
  node: group.node,
@@ -285,18 +327,19 @@ function rebuildSectionGroup(group, state) {
285
327
  children
286
328
  };
287
329
  }
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);
330
+ function rebuildSectionChild(child, chain, state) {
331
+ if ("node" in child && "children" in child) return isHeadingGroup(child) ? rebuildHeadingGroup(child, chain, state, rebuildSectionChild) : rebuildListGroup(child, chain, state, rebuildListChild);
332
+ if (child.kind === "paragraph") return rebuildParagraph(child, chain);
291
333
  return child;
292
334
  }
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);
335
+ function rebuildListChild(child, chain, state) {
336
+ if ("node" in child && "children" in child) return rebuildListGroup(child, chain, state, rebuildListChild);
337
+ if (child.kind === "paragraph") return rebuildParagraph(child, chain);
296
338
  return child;
297
339
  }
298
- function rebuildShapeGroup(group, state) {
299
- const children = group.children.map((child) => rebuildListChild(child, state));
340
+ function rebuildShapeGroup(group, chain, state) {
341
+ const inner = innerChain(group, chain, state);
342
+ const children = group.children.map((child) => rebuildListChild(child, inner, state));
300
343
  const ref = state.wrapperRefs.get(group);
301
344
  return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
302
345
  node: group.node,
@@ -304,10 +347,11 @@ function rebuildShapeGroup(group, state) {
304
347
  children
305
348
  };
306
349
  }
307
- function rebuildHeadingGroup(group, state, rebuildChild) {
308
- const anchor = rebuildParagraph(group.node, state);
350
+ function rebuildHeadingGroup(group, chain, state, rebuildChild) {
351
+ const inner = innerChain(group, chain, state);
352
+ const anchor = rebuildParagraph(group.node, inner);
309
353
  assertHeadingAnchor(anchor);
310
- const children = group.children.map((child) => rebuildChild(child, state));
354
+ const children = group.children.map((child) => rebuildChild(child, inner, state));
311
355
  const ref = state.wrapperRefs.get(group);
312
356
  return ref === void 0 && anchor === group.node && children.every((child, index) => child === group.children[index]) ? group : {
313
357
  node: anchor,
@@ -315,10 +359,11 @@ function rebuildHeadingGroup(group, state, rebuildChild) {
315
359
  children
316
360
  };
317
361
  }
318
- function rebuildListGroup(group, state, rebuildChild) {
319
- const anchor = rebuildParagraph(group.node, state);
362
+ function rebuildListGroup(group, chain, state, rebuildChild) {
363
+ const inner = innerChain(group, chain, state);
364
+ const anchor = rebuildParagraph(group.node, inner);
320
365
  assertListAnchor(anchor);
321
- const children = group.children.map((child) => rebuildChild(child, state));
366
+ const children = group.children.map((child) => rebuildChild(child, inner, state));
322
367
  const ref = state.wrapperRefs.get(group);
323
368
  return ref === void 0 && anchor === group.node && children.every((child, index) => child === group.children[index]) ? group : {
324
369
  node: anchor,
@@ -332,13 +377,13 @@ function assertHeadingAnchor(paragraph) {
332
377
  function assertListAnchor(paragraph) {
333
378
  if (paragraph.list === void 0) throw new Error("factorStyles: stripping dropped a list anchor's list membership");
334
379
  }
335
- function rebuildParagraph(paragraph, state) {
336
- const strips = state.paragraphStrips.get(paragraph);
380
+ function rebuildParagraph(paragraph, chain) {
381
+ const strips = paragraphStripsOf(chain, paragraph);
337
382
  const base = strips === void 0 ? paragraph : stripParagraphKeys(paragraph, strips);
338
383
  let changed = base !== paragraph;
339
384
  const runs = [];
340
385
  for (const run of base.runs) {
341
- const runStrips = state.runStrips.get(run);
386
+ const runStrips = runStripsOf(chain, run);
342
387
  const rebuilt = runStrips === void 0 ? run : stripRunKeys(run, runStrips);
343
388
  changed ||= rebuilt !== run;
344
389
  runs.push(rebuilt);
@@ -69,7 +69,12 @@ function assemblePackage(content, pages) {
69
69
  }
70
70
  }
71
71
  function factorStyles(pkg) {
72
- return assemblePackage(flattenPackage(pkg), pkg.pages);
72
+ const reassembled = assemblePackage(flattenPackage(pkg), pkg.pages);
73
+ if (pkg.definitions === void 0) return reassembled;
74
+ return {
75
+ ...reassembled,
76
+ definitions: pkg.definitions
77
+ };
73
78
  }
74
79
  function extentOf(wrapper) {
75
80
  if (isShapeGroupWrapper(wrapper)) return flowExtent(wrapper.children);
@@ -148,12 +153,14 @@ function bestGroup(groups) {
148
153
  }
149
154
  return best;
150
155
  }
151
- function plan(wrapper, visit, frozenParagraphs, frozenRuns, state, entries) {
156
+ function plan(wrapper, visit, branch, state, entries) {
152
157
  const extent = extentOf(wrapper);
153
- const paragraphCandidate = extent.length > 0 ? bestParagraphCandidate(extent, commonParagraphKeys(extent, frozenParagraphs), state.factoredParagraphs) : void 0;
154
- const runCandidate = extent.length > 0 ? bestRunCandidate(extent, commonRunKeys(extent, frozenRuns), state.factoredRuns) : void 0;
155
- const nextFrozenParagraphs = new Set(frozenParagraphs);
156
- const nextFrozenRuns = new Set(frozenRuns);
158
+ const paragraphCandidate = extent.length > 0 ? bestParagraphCandidate(extent, commonParagraphKeys(extent, branch.frozenParagraphs), branch.factoredParagraphs) : void 0;
159
+ const runCandidate = extent.length > 0 ? bestRunCandidate(extent, commonRunKeys(extent, branch.frozenRuns), branch.factoredRuns) : void 0;
160
+ const nextFrozenParagraphs = new Set(branch.frozenParagraphs);
161
+ const nextFrozenRuns = new Set(branch.frozenRuns);
162
+ const nextFactoredParagraphs = new Set(branch.factoredParagraphs);
163
+ const nextFactoredRuns = new Set(branch.factoredRuns);
157
164
  if (paragraphCandidate !== void 0 || runCandidate !== void 0) {
158
165
  const content = {
159
166
  ...paragraphCandidate !== void 0 ? { paragraph: paragraphCandidate.tuple } : {},
@@ -171,23 +178,34 @@ function plan(wrapper, visit, frozenParagraphs, frozenRuns, state, entries) {
171
178
  existing.wrappers.push(wrapper);
172
179
  existing.frequency += (paragraphCandidate?.positions.length ?? 0) + (runCandidate?.positions.length ?? 0);
173
180
  }
181
+ const strips = {
182
+ paragraphs: /* @__PURE__ */ new Map(),
183
+ runs: /* @__PURE__ */ new Map()
184
+ };
174
185
  if (paragraphCandidate !== void 0) {
175
186
  for (const paragraph of paragraphCandidate.positions) {
176
- state.factoredParagraphs.add(paragraph);
177
- state.paragraphStrips.set(paragraph, paragraphCandidate.keys);
187
+ nextFactoredParagraphs.add(paragraph);
188
+ strips.paragraphs.set(paragraph, paragraphCandidate.keys);
178
189
  }
179
190
  for (const key of paragraphCandidate.keys) nextFrozenParagraphs.add(key);
180
191
  }
181
192
  if (runCandidate !== void 0) {
182
193
  for (const run of runCandidate.positions) {
183
- state.factoredRuns.add(run);
184
- state.runStrips.set(run, runCandidate.keys);
194
+ nextFactoredRuns.add(run);
195
+ strips.runs.set(run, runCandidate.keys);
185
196
  }
186
197
  for (const key of runCandidate.keys) nextFrozenRuns.add(key);
187
198
  }
199
+ state.wrapperStrips.set(wrapper, strips);
188
200
  }
189
201
  visit.index += 1;
190
- for (const child of childWrappers(wrapper)) plan(child, visit, nextFrozenParagraphs, nextFrozenRuns, state, entries);
202
+ const next = {
203
+ frozenParagraphs: nextFrozenParagraphs,
204
+ frozenRuns: nextFrozenRuns,
205
+ factoredParagraphs: nextFactoredParagraphs,
206
+ factoredRuns: nextFactoredRuns
207
+ };
208
+ for (const child of childWrappers(wrapper)) plan(child, visit, next, state, entries);
191
209
  }
192
210
  function childWrappers(wrapper) {
193
211
  if (isShapeGroupWrapper(wrapper) || isAnchorGroupWrapper(wrapper)) {
@@ -207,27 +225,28 @@ function childWrappers(wrapper) {
207
225
  }
208
226
  function mint(pkg) {
209
227
  const state = {
210
- factoredParagraphs: /* @__PURE__ */ new Set(),
211
- factoredRuns: /* @__PURE__ */ new Set(),
212
228
  wrapperRefs: /* @__PURE__ */ new Map(),
213
- paragraphStrips: /* @__PURE__ */ new Map(),
214
- runStrips: /* @__PURE__ */ new Map()
229
+ wrapperStrips: /* @__PURE__ */ new Map()
215
230
  };
216
231
  const entries = /* @__PURE__ */ new Map();
217
232
  const visit = { index: 0 };
218
- const emptyParagraphs = /* @__PURE__ */ new Set();
219
- const emptyRuns = /* @__PURE__ */ new Set();
233
+ const rootBranch = {
234
+ frozenParagraphs: /* @__PURE__ */ new Set(),
235
+ frozenRuns: /* @__PURE__ */ new Set(),
236
+ factoredParagraphs: /* @__PURE__ */ new Set(),
237
+ factoredRuns: /* @__PURE__ */ new Set()
238
+ };
220
239
  switch (pkg.kind) {
221
240
  case "wordprocessing":
222
- for (const root of pkg.children) plan(root, visit, emptyParagraphs, emptyRuns, state, entries);
241
+ for (const root of pkg.children) plan(root, visit, rootBranch, state, entries);
223
242
  break;
224
243
  case "presentation":
225
- for (const root of pkg.children) plan(root, visit, emptyParagraphs, emptyRuns, state, entries);
244
+ for (const root of pkg.children) plan(root, visit, rootBranch, state, entries);
226
245
  break;
227
- case "drawing": for (const root of pkg.children) plan(root, visit, emptyParagraphs, emptyRuns, state, entries);
246
+ case "drawing": for (const root of pkg.children) plan(root, visit, rootBranch, state, entries);
228
247
  }
229
248
  if (entries.size === 0) return pkg;
230
- const ordered = [...entries.values()].sort((a, b) => b.frequency - a.frequency || a.firstVisit - b.firstVisit || canonicalKey(a.content).localeCompare(canonicalKey(b.content)));
249
+ const ordered = [...entries.values()].sort((a, b) => b.frequency - a.frequency || a.firstVisit - b.firstVisit);
231
250
  const styles = {};
232
251
  ordered.forEach((entry, index) => {
233
252
  const id = `s${index + 1}`;
@@ -238,17 +257,17 @@ function mint(pkg) {
238
257
  case "wordprocessing": return {
239
258
  ...pkg,
240
259
  styles,
241
- children: pkg.children.map((group) => rebuildSectionGroup(group, state))
260
+ children: pkg.children.map((group) => rebuildSectionGroup(group, [], state))
242
261
  };
243
262
  case "presentation": return {
244
263
  ...pkg,
245
264
  styles,
246
- children: pkg.children.map((group) => rebuildSlideGroup(group, state))
265
+ children: pkg.children.map((group) => rebuildSlideGroup(group, [], state))
247
266
  };
248
267
  case "drawing": return {
249
268
  ...pkg,
250
269
  styles,
251
- children: pkg.children.map((group) => rebuildDrawPageGroup(group, state))
270
+ children: pkg.children.map((group) => rebuildDrawPageGroup(group, [], state))
252
271
  };
253
272
  case "spreadsheet":
254
273
  case "formula": return {
@@ -257,8 +276,29 @@ function mint(pkg) {
257
276
  };
258
277
  }
259
278
  }
260
- function rebuildSlideGroup(group, state) {
261
- const children = group.children.map((shape) => rebuildShapeGroup(shape, state));
279
+ function innerChain(group, chain, state) {
280
+ const own = state.wrapperStrips.get(group);
281
+ return own === void 0 ? chain : [...chain, own];
282
+ }
283
+ function paragraphStripsOf(chain, paragraph) {
284
+ let result;
285
+ for (const strips of chain) {
286
+ const found = strips.paragraphs.get(paragraph);
287
+ if (found !== void 0) result = found;
288
+ }
289
+ return result;
290
+ }
291
+ function runStripsOf(chain, run) {
292
+ let result;
293
+ for (const strips of chain) {
294
+ const found = strips.runs.get(run);
295
+ if (found !== void 0) result = found;
296
+ }
297
+ return result;
298
+ }
299
+ function rebuildSlideGroup(group, chain, state) {
300
+ const inner = innerChain(group, chain, state);
301
+ const children = group.children.map((shape) => rebuildShapeGroup(shape, inner, state));
262
302
  const ref = state.wrapperRefs.get(group);
263
303
  return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
264
304
  node: group.node,
@@ -266,8 +306,9 @@ function rebuildSlideGroup(group, state) {
266
306
  children
267
307
  };
268
308
  }
269
- function rebuildDrawPageGroup(group, state) {
270
- const children = group.children.map((child) => "node" in child ? rebuildShapeGroup(child, state) : child);
309
+ function rebuildDrawPageGroup(group, chain, state) {
310
+ const inner = innerChain(group, chain, state);
311
+ const children = group.children.map((child) => "node" in child ? rebuildShapeGroup(child, inner, state) : child);
271
312
  const ref = state.wrapperRefs.get(group);
272
313
  return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
273
314
  node: group.node,
@@ -275,8 +316,9 @@ function rebuildDrawPageGroup(group, state) {
275
316
  children
276
317
  };
277
318
  }
278
- function rebuildSectionGroup(group, state) {
279
- const children = group.children.map((child) => rebuildSectionChild(child, state));
319
+ function rebuildSectionGroup(group, chain, state) {
320
+ const inner = innerChain(group, chain, state);
321
+ const children = group.children.map((child) => rebuildSectionChild(child, inner, state));
280
322
  const ref = state.wrapperRefs.get(group);
281
323
  return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
282
324
  node: group.node,
@@ -284,18 +326,19 @@ function rebuildSectionGroup(group, state) {
284
326
  children
285
327
  };
286
328
  }
287
- function rebuildSectionChild(child, state) {
288
- if ("node" in child && "children" in child) return isHeadingGroup(child) ? rebuildHeadingGroup(child, state, rebuildSectionChild) : rebuildListGroup(child, state, rebuildListChild);
289
- if (child.kind === "paragraph") return rebuildParagraph(child, state);
329
+ function rebuildSectionChild(child, chain, state) {
330
+ if ("node" in child && "children" in child) return isHeadingGroup(child) ? rebuildHeadingGroup(child, chain, state, rebuildSectionChild) : rebuildListGroup(child, chain, state, rebuildListChild);
331
+ if (child.kind === "paragraph") return rebuildParagraph(child, chain);
290
332
  return child;
291
333
  }
292
- function rebuildListChild(child, state) {
293
- if ("node" in child && "children" in child) return rebuildListGroup(child, state, rebuildListChild);
294
- if (child.kind === "paragraph") return rebuildParagraph(child, state);
334
+ function rebuildListChild(child, chain, state) {
335
+ if ("node" in child && "children" in child) return rebuildListGroup(child, chain, state, rebuildListChild);
336
+ if (child.kind === "paragraph") return rebuildParagraph(child, chain);
295
337
  return child;
296
338
  }
297
- function rebuildShapeGroup(group, state) {
298
- const children = group.children.map((child) => rebuildListChild(child, state));
339
+ function rebuildShapeGroup(group, chain, state) {
340
+ const inner = innerChain(group, chain, state);
341
+ const children = group.children.map((child) => rebuildListChild(child, inner, state));
299
342
  const ref = state.wrapperRefs.get(group);
300
343
  return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
301
344
  node: group.node,
@@ -303,10 +346,11 @@ function rebuildShapeGroup(group, state) {
303
346
  children
304
347
  };
305
348
  }
306
- function rebuildHeadingGroup(group, state, rebuildChild) {
307
- const anchor = rebuildParagraph(group.node, state);
349
+ function rebuildHeadingGroup(group, chain, state, rebuildChild) {
350
+ const inner = innerChain(group, chain, state);
351
+ const anchor = rebuildParagraph(group.node, inner);
308
352
  assertHeadingAnchor(anchor);
309
- const children = group.children.map((child) => rebuildChild(child, state));
353
+ const children = group.children.map((child) => rebuildChild(child, inner, state));
310
354
  const ref = state.wrapperRefs.get(group);
311
355
  return ref === void 0 && anchor === group.node && children.every((child, index) => child === group.children[index]) ? group : {
312
356
  node: anchor,
@@ -314,10 +358,11 @@ function rebuildHeadingGroup(group, state, rebuildChild) {
314
358
  children
315
359
  };
316
360
  }
317
- function rebuildListGroup(group, state, rebuildChild) {
318
- const anchor = rebuildParagraph(group.node, state);
361
+ function rebuildListGroup(group, chain, state, rebuildChild) {
362
+ const inner = innerChain(group, chain, state);
363
+ const anchor = rebuildParagraph(group.node, inner);
319
364
  assertListAnchor(anchor);
320
- const children = group.children.map((child) => rebuildChild(child, state));
365
+ const children = group.children.map((child) => rebuildChild(child, inner, state));
321
366
  const ref = state.wrapperRefs.get(group);
322
367
  return ref === void 0 && anchor === group.node && children.every((child, index) => child === group.children[index]) ? group : {
323
368
  node: anchor,
@@ -331,13 +376,13 @@ function assertHeadingAnchor(paragraph) {
331
376
  function assertListAnchor(paragraph) {
332
377
  if (paragraph.list === void 0) throw new Error("factorStyles: stripping dropped a list anchor's list membership");
333
378
  }
334
- function rebuildParagraph(paragraph, state) {
335
- const strips = state.paragraphStrips.get(paragraph);
379
+ function rebuildParagraph(paragraph, chain) {
380
+ const strips = paragraphStripsOf(chain, paragraph);
336
381
  const base = strips === void 0 ? paragraph : stripParagraphKeys(paragraph, strips);
337
382
  let changed = base !== paragraph;
338
383
  const runs = [];
339
384
  for (const run of base.runs) {
340
- const runStrips = state.runStrips.get(run);
385
+ const runStrips = runStripsOf(chain, run);
341
386
  const rebuilt = runStrips === void 0 ? run : stripRunKeys(run, runStrips);
342
387
  changed ||= rebuilt !== run;
343
388
  runs.push(rebuilt);
@@ -48,6 +48,7 @@ function flattenPackage(pkg) {
48
48
  kind: "spreadsheet",
49
49
  ...envelope,
50
50
  sheets: pkg.children.map((group) => {
51
+ if (group.style !== void 0) throw new Error("flattenPackage: a sheet group carries a style ref but a sheet holds no block flow to resolve it onto");
51
52
  const images = [];
52
53
  const embedded = [];
53
54
  for (const child of group.children) if ("kind" in child) images.push(child);
@@ -47,6 +47,7 @@ function flattenPackage(pkg) {
47
47
  kind: "spreadsheet",
48
48
  ...envelope,
49
49
  sheets: pkg.children.map((group) => {
50
+ if (group.style !== void 0) throw new Error("flattenPackage: a sheet group carries a style ref but a sheet holds no block flow to resolve it onto");
50
51
  const images = [];
51
52
  const embedded = [];
52
53
  for (const child of group.children) if ("kind" in child) images.push(child);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js.documents",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "Bidirectional docx/pptx <-> PDF conversion and a read+write editable OOXML document model, built on ooxml.js and Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -64,8 +64,8 @@
64
64
  "byte-codec": "^1.1.9",
65
65
  "document-schema.js": "^4.0.0",
66
66
  "fflate": "^0.8.3",
67
- "markdown-codec": "^3.0.0",
68
- "odf.js": "^4.0.0",
67
+ "markdown-codec": "^3.0.1",
68
+ "odf.js": "^4.0.1",
69
69
  "ooxml.js": "^3.0.0",
70
70
  "pdf-codec": "^3.0.0",
71
71
  "temml": "0.13.4",