documents.js 3.0.3 → 3.0.4

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.
@@ -35,6 +35,9 @@ function isDrawPageGroupWrapper(wrapper) {
35
35
  function isHeadingGroup(group) {
36
36
  return group.node.headingLevel !== void 0;
37
37
  }
38
+ function isConstructGroup(child) {
39
+ return "node" in child && "children" in child && child.node.kind !== "paragraph";
40
+ }
38
41
  function assemblePackage(content, pages) {
39
42
  const envelope = {
40
43
  metadata: content.metadata,
@@ -328,11 +331,13 @@ function rebuildSectionGroup(group, chain, state) {
328
331
  };
329
332
  }
330
333
  function rebuildSectionChild(child, chain, state) {
334
+ if (isConstructGroup(child)) return rebuildSectionConstructGroup(child, chain, state);
331
335
  if ("node" in child && "children" in child) return isHeadingGroup(child) ? rebuildHeadingGroup(child, chain, state, rebuildSectionChild) : rebuildListGroup(child, chain, state, rebuildListChild);
332
336
  if (child.kind === "paragraph") return rebuildParagraph(child, chain);
333
337
  return child;
334
338
  }
335
339
  function rebuildListChild(child, chain, state) {
340
+ if (isConstructGroup(child)) return rebuildShapeConstructGroup(child, chain, state);
336
341
  if ("node" in child && "children" in child) return rebuildListGroup(child, chain, state, rebuildListChild);
337
342
  if (child.kind === "paragraph") return rebuildParagraph(child, chain);
338
343
  return child;
@@ -347,6 +352,26 @@ function rebuildShapeGroup(group, chain, state) {
347
352
  children
348
353
  };
349
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
+ }
350
375
  function rebuildHeadingGroup(group, chain, state, rebuildChild) {
351
376
  const inner = innerChain(group, chain, state);
352
377
  const anchor = rebuildParagraph(group.node, inner);
@@ -407,3 +432,4 @@ function stripRunKeys(run, keys) {
407
432
  //#endregion
408
433
  exports.assemblePackage = assemblePackage;
409
434
  exports.factorStyles = factorStyles;
435
+ exports.mint = mint;
@@ -2,5 +2,6 @@ import { ContentDocument, DocumentPackage, PageSize } from "document-schema.js";
2
2
  //#region src/convert/factor-styles.d.ts
3
3
  declare function assemblePackage(content: ContentDocument, pages?: readonly PageSize[]): DocumentPackage;
4
4
  declare function factorStyles(pkg: DocumentPackage): DocumentPackage;
5
+ declare function mint(pkg: DocumentPackage): DocumentPackage;
5
6
  //#endregion
6
- export { assemblePackage, factorStyles };
7
+ export { assemblePackage, factorStyles, mint };
@@ -2,5 +2,6 @@ import { ContentDocument, DocumentPackage, PageSize } from "document-schema.js";
2
2
  //#region src/convert/factor-styles.d.ts
3
3
  declare function assemblePackage(content: ContentDocument, pages?: readonly PageSize[]): DocumentPackage;
4
4
  declare function factorStyles(pkg: DocumentPackage): DocumentPackage;
5
+ declare function mint(pkg: DocumentPackage): DocumentPackage;
5
6
  //#endregion
6
- export { assemblePackage, factorStyles };
7
+ export { assemblePackage, factorStyles, mint };
@@ -34,6 +34,9 @@ function isDrawPageGroupWrapper(wrapper) {
34
34
  function isHeadingGroup(group) {
35
35
  return group.node.headingLevel !== void 0;
36
36
  }
37
+ function isConstructGroup(child) {
38
+ return "node" in child && "children" in child && child.node.kind !== "paragraph";
39
+ }
37
40
  function assemblePackage(content, pages) {
38
41
  const envelope = {
39
42
  metadata: content.metadata,
@@ -327,11 +330,13 @@ function rebuildSectionGroup(group, chain, state) {
327
330
  };
328
331
  }
329
332
  function rebuildSectionChild(child, chain, state) {
333
+ if (isConstructGroup(child)) return rebuildSectionConstructGroup(child, chain, state);
330
334
  if ("node" in child && "children" in child) return isHeadingGroup(child) ? rebuildHeadingGroup(child, chain, state, rebuildSectionChild) : rebuildListGroup(child, chain, state, rebuildListChild);
331
335
  if (child.kind === "paragraph") return rebuildParagraph(child, chain);
332
336
  return child;
333
337
  }
334
338
  function rebuildListChild(child, chain, state) {
339
+ if (isConstructGroup(child)) return rebuildShapeConstructGroup(child, chain, state);
335
340
  if ("node" in child && "children" in child) return rebuildListGroup(child, chain, state, rebuildListChild);
336
341
  if (child.kind === "paragraph") return rebuildParagraph(child, chain);
337
342
  return child;
@@ -346,6 +351,26 @@ function rebuildShapeGroup(group, chain, state) {
346
351
  children
347
352
  };
348
353
  }
354
+ function rebuildSectionConstructGroup(group, chain, state) {
355
+ const inner = innerChain(group, chain, state);
356
+ const children = group.children.map((child) => rebuildSectionChild(child, inner, state));
357
+ const ref = state.wrapperRefs.get(group);
358
+ return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
359
+ node: group.node,
360
+ ...ref !== void 0 ? { style: ref } : {},
361
+ children
362
+ };
363
+ }
364
+ function rebuildShapeConstructGroup(group, chain, state) {
365
+ const inner = innerChain(group, chain, state);
366
+ const children = group.children.map((child) => rebuildListChild(child, inner, state));
367
+ const ref = state.wrapperRefs.get(group);
368
+ return ref === void 0 && children.every((child, index) => child === group.children[index]) ? group : {
369
+ node: group.node,
370
+ ...ref !== void 0 ? { style: ref } : {},
371
+ children
372
+ };
373
+ }
349
374
  function rebuildHeadingGroup(group, chain, state, rebuildChild) {
350
375
  const inner = innerChain(group, chain, state);
351
376
  const anchor = rebuildParagraph(group.node, inner);
@@ -404,4 +429,4 @@ function stripRunKeys(run, keys) {
404
429
  return copy;
405
430
  }
406
431
  //#endregion
407
- export { assemblePackage, factorStyles };
432
+ export { assemblePackage, factorStyles, mint };
@@ -98,6 +98,7 @@ function flattenShape(styles, chain, group) {
98
98
  blocks: flattenListChildren(styles, chainWithRef(chain, group), group.children)
99
99
  };
100
100
  }
101
+ const CONSTRUCT_GROUP_UNFLATTENABLE = "flattenPackage: cannot flatten a construct group -- ContentBlock has no construct carrier yet (see document-schema.js#22)";
101
102
  function flattenSectionChildren(styles, chain, children) {
102
103
  const blocks = [];
103
104
  for (const child of children) if (isHeadingGroup(child)) {
@@ -106,7 +107,8 @@ function flattenSectionChildren(styles, chain, children) {
106
107
  } else if (isListGroup(child)) {
107
108
  const own = chainWithRef(chain, child);
108
109
  blocks.push(resolveAnchor(styles, own, child.node), ...flattenListChildren(styles, own, child.children));
109
- } else if (child.kind === "paragraph") {
110
+ } else if (isConstructGroup(child)) throw new Error(CONSTRUCT_GROUP_UNFLATTENABLE);
111
+ else if (child.kind === "paragraph") {
110
112
  const entry = entryOf(styles, chain);
111
113
  blocks.push(entry === void 0 ? child : applyEntry(entry, child));
112
114
  } else blocks.push(child);
@@ -117,7 +119,8 @@ function flattenListChildren(styles, chain, children) {
117
119
  for (const child of children) if (isListGroup(child)) {
118
120
  const own = chainWithRef(chain, child);
119
121
  blocks.push(resolveAnchor(styles, own, child.node), ...flattenListChildren(styles, own, child.children));
120
- } else if (child.kind === "paragraph") {
122
+ } else if (isConstructGroup(child)) throw new Error(CONSTRUCT_GROUP_UNFLATTENABLE);
123
+ else if (child.kind === "paragraph") {
121
124
  const entry = entryOf(styles, chain);
122
125
  blocks.push(entry === void 0 ? child : applyEntry(entry, child));
123
126
  } else blocks.push(child);
@@ -129,6 +132,9 @@ function isHeadingGroup(child) {
129
132
  function isListGroup(child) {
130
133
  return "node" in child && "children" in child && child.node.kind === "paragraph" && child.node.list !== void 0;
131
134
  }
135
+ function isConstructGroup(child) {
136
+ return "node" in child && "children" in child && child.node.kind !== "paragraph";
137
+ }
132
138
  function resolveAnchor(styles, chain, anchor) {
133
139
  const entry = entryOf(styles, chain);
134
140
  if (entry === void 0) return anchor;
@@ -97,6 +97,7 @@ function flattenShape(styles, chain, group) {
97
97
  blocks: flattenListChildren(styles, chainWithRef(chain, group), group.children)
98
98
  };
99
99
  }
100
+ const CONSTRUCT_GROUP_UNFLATTENABLE = "flattenPackage: cannot flatten a construct group -- ContentBlock has no construct carrier yet (see document-schema.js#22)";
100
101
  function flattenSectionChildren(styles, chain, children) {
101
102
  const blocks = [];
102
103
  for (const child of children) if (isHeadingGroup(child)) {
@@ -105,7 +106,8 @@ function flattenSectionChildren(styles, chain, children) {
105
106
  } else if (isListGroup(child)) {
106
107
  const own = chainWithRef(chain, child);
107
108
  blocks.push(resolveAnchor(styles, own, child.node), ...flattenListChildren(styles, own, child.children));
108
- } else if (child.kind === "paragraph") {
109
+ } else if (isConstructGroup(child)) throw new Error(CONSTRUCT_GROUP_UNFLATTENABLE);
110
+ else if (child.kind === "paragraph") {
109
111
  const entry = entryOf(styles, chain);
110
112
  blocks.push(entry === void 0 ? child : applyEntry(entry, child));
111
113
  } else blocks.push(child);
@@ -116,7 +118,8 @@ function flattenListChildren(styles, chain, children) {
116
118
  for (const child of children) if (isListGroup(child)) {
117
119
  const own = chainWithRef(chain, child);
118
120
  blocks.push(resolveAnchor(styles, own, child.node), ...flattenListChildren(styles, own, child.children));
119
- } else if (child.kind === "paragraph") {
121
+ } else if (isConstructGroup(child)) throw new Error(CONSTRUCT_GROUP_UNFLATTENABLE);
122
+ else if (child.kind === "paragraph") {
120
123
  const entry = entryOf(styles, chain);
121
124
  blocks.push(entry === void 0 ? child : applyEntry(entry, child));
122
125
  } else blocks.push(child);
@@ -128,6 +131,9 @@ function isHeadingGroup(child) {
128
131
  function isListGroup(child) {
129
132
  return "node" in child && "children" in child && child.node.kind === "paragraph" && child.node.list !== void 0;
130
133
  }
134
+ function isConstructGroup(child) {
135
+ return "node" in child && "children" in child && child.node.kind !== "paragraph";
136
+ }
131
137
  function resolveAnchor(styles, chain, anchor) {
132
138
  const entry = entryOf(styles, chain);
133
139
  if (entry === void 0) return anchor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "documents.js",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
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": {
@@ -84,7 +84,7 @@
84
84
  "packageManager": "pnpm@11.6.0",
85
85
  "dependencies": {
86
86
  "byte-codec": "^1.1.9",
87
- "document-schema.js": "^4.0.0",
87
+ "document-schema.js": "^4.1.0",
88
88
  "fflate": "^0.8.3",
89
89
  "markdown-codec": "^3.0.1",
90
90
  "odf.js": "^4.0.1",