@docx4j/core-ts 0.5.0 → 0.7.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.
Files changed (207) hide show
  1. package/NOTICE +4 -0
  2. package/README.md +92 -4
  3. package/dist/html/convert.mjs +2 -1
  4. package/dist/html/elements.mjs +2 -1
  5. package/dist/model/color/ColorMath.d.mts +29 -0
  6. package/dist/model/color/ColorMath.mjs +146 -0
  7. package/dist/model/color/ColorTables.d.mts +6 -0
  8. package/dist/model/color/ColorTables.mjs +83 -0
  9. package/dist/model/color/DrawingMLColors.d.mts +52 -0
  10. package/dist/model/color/DrawingMLColors.mjs +374 -0
  11. package/dist/model/color/ResolvedColor.d.mts +36 -0
  12. package/dist/model/color/ResolvedColor.mjs +65 -0
  13. package/dist/model/color/SpreadsheetColors.d.mts +36 -0
  14. package/dist/model/color/SpreadsheetColors.mjs +84 -0
  15. package/dist/model/color/StyleFill.d.mts +28 -0
  16. package/dist/model/color/StyleFill.mjs +21 -0
  17. package/dist/model/color/ThemeColors.d.mts +86 -0
  18. package/dist/model/color/ThemeColors.mjs +304 -0
  19. package/dist/model/color/WordColors.d.mts +71 -0
  20. package/dist/model/color/WordColors.mjs +121 -0
  21. package/dist/model/color/index.d.mts +6 -0
  22. package/dist/model/color/index.mjs +30 -0
  23. package/dist/model/content/Body.d.mts +145 -23
  24. package/dist/model/content/Body.mjs +507 -150
  25. package/dist/model/content/Comment.d.mts +23 -5
  26. package/dist/model/content/Comment.mjs +207 -26
  27. package/dist/model/content/ContentControl.d.mts +198 -19
  28. package/dist/model/content/ContentControl.mjs +672 -99
  29. package/dist/model/content/Font.d.mts +70 -17
  30. package/dist/model/content/Font.mjs +119 -36
  31. package/dist/model/content/InlinePicture.d.mts +11 -0
  32. package/dist/model/content/InlinePicture.mjs +21 -1
  33. package/dist/model/content/List.d.mts +6 -3
  34. package/dist/model/content/List.mjs +18 -8
  35. package/dist/model/content/Paragraph.d.mts +200 -14
  36. package/dist/model/content/Paragraph.mjs +898 -82
  37. package/dist/model/content/Range.d.mts +227 -12
  38. package/dist/model/content/Range.mjs +785 -59
  39. package/dist/model/content/ResolvedView.d.mts +104 -0
  40. package/dist/model/content/ResolvedView.mjs +596 -0
  41. package/dist/model/content/Table.d.mts +29 -3
  42. package/dist/model/content/Table.mjs +135 -49
  43. package/dist/model/content/TrackedChange.d.mts +174 -15
  44. package/dist/model/content/TrackedChange.mjs +734 -170
  45. package/dist/model/content/comments.d.mts +20 -6
  46. package/dist/model/content/comments.mjs +67 -57
  47. package/dist/model/content/generalException.d.mts +18 -0
  48. package/dist/model/content/generalException.mjs +24 -0
  49. package/dist/model/content/index.d.mts +10 -3
  50. package/dist/model/content/index.mjs +10 -2
  51. package/dist/model/content/mathText.d.mts +21 -0
  52. package/dist/model/content/mathText.mjs +267 -0
  53. package/dist/model/content/officeText.d.mts +27 -0
  54. package/dist/model/content/officeText.mjs +74 -0
  55. package/dist/model/content/ooxml.mjs +12 -1
  56. package/dist/model/content/outline.d.mts +5 -0
  57. package/dist/model/content/outline.mjs +13 -0
  58. package/dist/model/content/paraIds.d.mts +5 -0
  59. package/dist/model/content/paraIds.mjs +54 -0
  60. package/dist/model/content/placeholders.d.mts +110 -0
  61. package/dist/model/content/placeholders.mjs +253 -0
  62. package/dist/model/content/search.d.mts +74 -0
  63. package/dist/model/content/search.mjs +255 -9
  64. package/dist/model/content/spanEdits.d.mts +159 -0
  65. package/dist/model/content/spanEdits.mjs +728 -0
  66. package/dist/model/content/story.d.mts +47 -0
  67. package/dist/model/content/story.mjs +95 -0
  68. package/dist/model/content/tableColumns.d.mts +1 -1
  69. package/dist/model/content/tableColumns.mjs +108 -80
  70. package/dist/model/content/tableRevisions.d.mts +11 -3
  71. package/dist/model/content/tableRevisions.mjs +72 -42
  72. package/dist/model/content/tableRules.d.mts +30 -0
  73. package/dist/model/content/tableRules.mjs +102 -0
  74. package/dist/model/content/textBoxes.d.mts +18 -0
  75. package/dist/model/content/textBoxes.mjs +105 -0
  76. package/dist/model/content/trackedChangeFilter.d.mts +39 -0
  77. package/dist/model/content/trackedChangeFilter.mjs +81 -0
  78. package/dist/model/content/tracking.d.mts +63 -6
  79. package/dist/model/content/tracking.mjs +242 -22
  80. package/dist/model/content/tree.d.mts +172 -24
  81. package/dist/model/content/tree.mjs +328 -54
  82. package/dist/model/content/wordRange.d.mts +48 -0
  83. package/dist/model/content/wordRange.mjs +97 -0
  84. package/dist/model/customxml/CustomXmlPartCollection.d.mts +30 -1
  85. package/dist/model/customxml/CustomXmlPartCollection.mjs +81 -12
  86. package/dist/model/customxml/XmlMapping.d.mts +32 -8
  87. package/dist/model/customxml/XmlMapping.mjs +64 -10
  88. package/dist/model/customxml/bindings.d.mts +33 -4
  89. package/dist/model/customxml/bindings.mjs +171 -45
  90. package/dist/model/customxml/index.d.mts +1 -0
  91. package/dist/model/customxml/index.mjs +1 -0
  92. package/dist/model/customxml/kinds.d.mts +8 -3
  93. package/dist/model/customxml/kinds.mjs +26 -5
  94. package/dist/model/customxml/opendope.d.mts +4 -1
  95. package/dist/model/customxml/opendope.mjs +9 -6
  96. package/dist/model/customxml/picturePlaceholder.d.mts +17 -0
  97. package/dist/model/customxml/picturePlaceholder.mjs +32 -0
  98. package/dist/model/customxml/pictures.d.mts +4 -3
  99. package/dist/model/customxml/pictures.mjs +22 -8
  100. package/dist/model/customxml/storeItems.d.mts +57 -0
  101. package/dist/model/customxml/storeItems.mjs +122 -0
  102. package/dist/model/customxml/xhtml.mjs +23 -22
  103. package/dist/model/dateZone.d.mts +25 -0
  104. package/dist/model/dateZone.mjs +57 -0
  105. package/dist/model/index.d.mts +3 -0
  106. package/dist/model/index.mjs +5 -0
  107. package/dist/model/listnumbering/Emulator.d.mts +37 -5
  108. package/dist/model/listnumbering/Emulator.mjs +63 -9
  109. package/dist/model/properties/PropertyResolver.d.mts +74 -2
  110. package/dist/model/properties/PropertyResolver.mjs +133 -5
  111. package/dist/model/properties/catalogue.d.mts +19 -5
  112. package/dist/model/properties/catalogue.mjs +41 -15
  113. package/dist/model/properties/index.d.mts +1 -1
  114. package/dist/model/properties/log.d.mts +1 -1
  115. package/dist/model/properties/log.mjs +5 -5
  116. package/dist/model/properties/styleUtil.d.mts +3 -1
  117. package/dist/model/properties/styleUtil.mjs +20 -24
  118. package/dist/model/properties/table.mjs +4 -2
  119. package/dist/model/text/CaseMapping.d.mts +38 -0
  120. package/dist/model/text/CaseMapping.mjs +86 -0
  121. package/dist/model/text/Extractor.d.mts +349 -0
  122. package/dist/model/text/Extractor.mjs +2406 -0
  123. package/dist/model/text/LinkTargets.d.mts +45 -0
  124. package/dist/model/text/LinkTargets.mjs +170 -0
  125. package/dist/model/text/MarkdownExporter.d.mts +140 -0
  126. package/dist/model/text/MarkdownExporter.mjs +255 -0
  127. package/dist/model/text/PlainText.d.mts +29 -0
  128. package/dist/model/text/PlainText.mjs +542 -0
  129. package/dist/model/text/TextContext.d.mts +256 -0
  130. package/dist/model/text/TextContext.mjs +600 -0
  131. package/dist/model/text/TextOptions.d.mts +233 -0
  132. package/dist/model/text/TextOptions.mjs +419 -0
  133. package/dist/model/text/TextResult.d.mts +621 -0
  134. package/dist/model/text/TextResult.mjs +629 -0
  135. package/dist/model/text/Texts.d.mts +99 -0
  136. package/dist/model/text/Texts.mjs +187 -0
  137. package/dist/model/text/WmlToMarkdown.d.mts +120 -0
  138. package/dist/model/text/WmlToMarkdown.mjs +936 -0
  139. package/dist/model/text/caseMapping.generated.d.mts +7 -0
  140. package/dist/model/text/caseMapping.generated.mjs +214 -0
  141. package/dist/model/text/commonmark.d.mts +121 -0
  142. package/dist/model/text/commonmark.mjs +655 -0
  143. package/dist/model/text/index.d.mts +8 -0
  144. package/dist/model/text/index.mjs +9 -0
  145. package/dist/model/text/normalize.d.mts +8 -0
  146. package/dist/model/text/normalize.mjs +13 -0
  147. package/dist/model/text/outline.d.mts +4 -0
  148. package/dist/model/text/outline.mjs +71 -0
  149. package/dist/model/wordIntegers.d.mts +29 -0
  150. package/dist/model/wordIntegers.mjs +78 -0
  151. package/dist/office-js/document.mjs +15 -1
  152. package/dist/office-js/fragment.d.mts +7 -5
  153. package/dist/office-js/fragment.mjs +63 -14
  154. package/dist/office-js/proxy.d.mts +8 -0
  155. package/dist/office-js/proxy.mjs +29 -0
  156. package/dist/office-js/run.mjs +2 -0
  157. package/dist/office-js/supported.generated.mjs +16 -0
  158. package/dist/office-js/toApiScript.mjs +29 -12
  159. package/dist/opc/DirectoryPartStore.d.mts +6 -2
  160. package/dist/opc/DirectoryPartStore.mjs +11 -4
  161. package/dist/opc/FlatOpcPartStore.d.mts +4 -2
  162. package/dist/opc/FlatOpcPartStore.mjs +11 -8
  163. package/dist/opc/Load.d.mts +32 -0
  164. package/dist/opc/Load.mjs +115 -5
  165. package/dist/opc/PartStore.d.mts +34 -1
  166. package/dist/opc/PartStore.mjs +71 -8
  167. package/dist/opc/Save.d.mts +32 -0
  168. package/dist/opc/Save.mjs +110 -4
  169. package/dist/opc/ZipPartStore.d.mts +4 -2
  170. package/dist/opc/ZipPartStore.mjs +12 -7
  171. package/dist/opc/exceptions.d.mts +140 -0
  172. package/dist/opc/exceptions.mjs +108 -0
  173. package/dist/opc/index.d.mts +8 -5
  174. package/dist/opc/index.mjs +5 -3
  175. package/dist/opc/mce/preprocessor.d.mts +141 -5
  176. package/dist/opc/mce/preprocessor.mjs +119 -18
  177. package/dist/opc/mce/understood.d.mts +3 -11
  178. package/dist/opc/mce/understood.mjs +27 -23
  179. package/dist/opc/repair/breaks.d.mts +23 -0
  180. package/dist/opc/repair/breaks.mjs +288 -0
  181. package/dist/opc/repair/hosts.d.mts +12 -0
  182. package/dist/opc/repair/hosts.mjs +33 -0
  183. package/dist/opc/repair/mainRoot.d.mts +19 -0
  184. package/dist/opc/repair/mainRoot.mjs +168 -0
  185. package/dist/opc/repair/unknownElements.d.mts +8 -0
  186. package/dist/opc/repair/unknownElements.mjs +180 -0
  187. package/dist/opc/repair/wmlNames.generated.d.mts +2 -0
  188. package/dist/opc/repair/wmlNames.generated.mjs +80 -0
  189. package/dist/opc/skipped.d.mts +50 -0
  190. package/dist/opc/skipped.mjs +140 -0
  191. package/dist/packages/OpcPackage.d.mts +110 -4
  192. package/dist/packages/OpcPackage.mjs +123 -7
  193. package/dist/packages/WordprocessingMLPackage.d.mts +45 -8
  194. package/dist/packages/WordprocessingMLPackage.mjs +158 -21
  195. package/dist/packages/index.d.mts +1 -1
  196. package/dist/parts/DefaultXmlPart.mjs +2 -2
  197. package/dist/parts/Part.d.mts +14 -2
  198. package/dist/parts/RelationshipsPart.d.mts +15 -0
  199. package/dist/parts/RelationshipsPart.mjs +66 -1
  200. package/dist/parts/XmlPart.d.mts +63 -32
  201. package/dist/parts/XmlPart.mjs +240 -96
  202. package/dist/parts/wml/comments.mjs +30 -0
  203. package/dist/parts/wml/index.d.mts +12 -1
  204. package/dist/parts/wml/index.mjs +37 -1
  205. package/dist/xml/dom.d.mts +7 -0
  206. package/dist/xml/dom.mjs +18 -0
  207. package/package.json +2 -2
@@ -1,7 +1,16 @@
1
1
  import type { Relationship } from '@docx4j/generated-objects-ts/modules/org_docx4j_relationships';
2
+ import type { Normalisation, OutOfRange, MisplacedChild } from '@docx4j/generated-objects-ts';
2
3
  import { PartName } from '../opc/PartName.mjs';
3
4
  import type { RelationshipsPart, AddPartBehaviour } from './RelationshipsPart.mjs';
4
5
  import type { OpcPackage } from '../packages/OpcPackage.mjs';
6
+ /** What a save asks of a part's bytes (CR-015 D8): to be told of each value the objects facade's normaliser rewrote. */
7
+ export interface PartBytesOptions {
8
+ onNormalised?(normalisation: Normalisation): void;
9
+ /** Called for each integer attribute value written that Word 365 reads differently (CR-017 P3); the value is written as held. */
10
+ onOutOfRange?(report: OutOfRange): void;
11
+ /** Called for each child its container never admits, as the container is written (CR-016 D2); written as held unless the callback throws. */
12
+ onMisplaced?(report: MisplacedChild): void;
13
+ }
5
14
  /** Something that owns a relationships part: a part or the package (docx4j Base). */
6
15
  export interface RelationshipSource {
7
16
  readonly partName: PartName;
@@ -49,8 +58,11 @@ export declare abstract class Part implements RelationshipSource {
49
58
  setPartShortcut(_part: Part, _relationshipType: string): boolean;
50
59
  /** The bytes this part was loaded from, if it came from a container. Undefined for new parts. */
51
60
  protected loadSourceBytes(): Promise<Uint8Array | undefined>;
52
- /** The bytes to write on save. Untouched parts come back from the source container unchanged. */
53
- abstract getBytes(): Promise<Uint8Array>;
61
+ /**
62
+ * The bytes to write on save. Untouched parts come back from the source container unchanged. A part
63
+ * marshalled through the objects facade tells `options.onNormalised` of each value written in its normal form.
64
+ */
65
+ abstract getBytes(options?: PartBytesOptions): Promise<Uint8Array>;
54
66
  /** Whether the part carries content of its own (set or unmarshalled) rather than relying on the source container. */
55
67
  abstract get isLoaded(): boolean;
56
68
  }
@@ -2,6 +2,7 @@ import type { Relationships, Relationship } from '@docx4j/generated-objects-ts/m
2
2
  import { XmlPart } from './XmlPart.mjs';
3
3
  import { Part, type RelationshipSource } from './Part.mjs';
4
4
  import { PartName } from '../opc/PartName.mjs';
5
+ import type { PartWarning } from '../opc/mce/preprocessor.mjs';
5
6
  /** What `addPart` does when a part of the same name is already in the package (docx4j AddPartBehaviour). */
6
7
  export type AddPartBehaviour = 'OVERWRITE_IF_NAME_EXISTS' | 'REUSE_EXISTING' | 'RENAME_IF_NAME_EXISTS';
7
8
  export declare const RELATIONSHIPS_ROOT: {
@@ -22,6 +23,20 @@ export declare class RelationshipsPart extends XmlPart<Relationships> {
22
23
  static createPackageRels(): RelationshipsPart;
23
24
  /** A part's own, empty, relationships part. */
24
25
  static createRelationshipsPartForPart(source: RelationshipSource): RelationshipsPart;
26
+ /**
27
+ * Set by the load under `LoadOptions.repair` `'word'` or `'all'` (CR-031 section 2.3): a part in a wrong namespace is read
28
+ * as Word's repair reads it, not refused.
29
+ */
30
+ readsByLocalName: boolean;
31
+ /**
32
+ * Refuses a part in another namespace, or in none, on its root or on any `Relationship` (CR-025 section 8, D10), before the
33
+ * runtime drops what it can't bind. Under `readsByLocalName` (`repair: 'word'`, CR-031 section 2.3) the root and every
34
+ * `Relationship` are read by their local names instead, as Word's repair reads them, so the runtime binds them all and a
35
+ * save writes the right namespace, with one `package.relationships_namespace` warning. A root or a child with another
36
+ * local name is left to the runtime, as before: Word is unmeasured on both, and a child is then a `part.skipped` on this
37
+ * part, which `pkg.warnings` gathers (D12).
38
+ */
39
+ protected readRoot(doc: Document): readonly PartWarning[];
25
40
  /** The name of the part these relationships belong to; '/' for the package. */
26
41
  get sourceName(): PartName;
27
42
  get isPackageRelationshipPart(): boolean;
@@ -3,7 +3,7 @@ import { setRelationshipsPartFactory } from './Part.mjs';
3
3
  import { PartName } from '../opc/PartName.mjs';
4
4
  import { ContentTypes } from '../opc/ContentTypes.mjs';
5
5
  import { Namespaces } from './Namespaces.mjs';
6
- import { InvalidFormatException } from '../opc/exceptions.mjs';
6
+ import { InvalidFormatException, RelationshipsNamespaceException } from '../opc/exceptions.mjs';
7
7
  export const RELATIONSHIPS_ROOT = { namespaceURI: Namespaces.RELATIONSHIPS, localPart: 'Relationships' };
8
8
  const RELATIONSHIP_TYPE_NAME = 'org_docx4j_relationships.Relationship';
9
9
  /**
@@ -15,6 +15,11 @@ export class RelationshipsPart extends XmlPart {
15
15
  constructor(source, partName) {
16
16
  super(partName !== null && partName !== void 0 ? partName : (source ? PartName.relsFor(source.partName) : '/_rels/.rels'), ContentTypes.RELATIONSHIPS_PART, '', RELATIONSHIPS_ROOT);
17
17
  this.nextId = 1;
18
+ /**
19
+ * Set by the load under `LoadOptions.repair` `'word'` or `'all'` (CR-031 section 2.3): a part in a wrong namespace is read
20
+ * as Word's repair reads it, not refused.
21
+ */
22
+ this.readsByLocalName = false;
18
23
  this.sourceP = source;
19
24
  if (source)
20
25
  this.package = source.package;
@@ -31,6 +36,48 @@ export class RelationshipsPart extends XmlPart {
31
36
  rp.setContents({ relationship: [] });
32
37
  return rp;
33
38
  }
39
+ /**
40
+ * Refuses a part in another namespace, or in none, on its root or on any `Relationship` (CR-025 section 8, D10), before the
41
+ * runtime drops what it can't bind. Under `readsByLocalName` (`repair: 'word'`, CR-031 section 2.3) the root and every
42
+ * `Relationship` are read by their local names instead, as Word's repair reads them, so the runtime binds them all and a
43
+ * save writes the right namespace, with one `package.relationships_namespace` warning. A root or a child with another
44
+ * local name is left to the runtime, as before: Word is unmeasured on both, and a child is then a `part.skipped` on this
45
+ * part, which `pkg.warnings` gathers (D12).
46
+ */
47
+ readRoot(doc) {
48
+ var _a, _b;
49
+ const root = doc.documentElement;
50
+ if (!root || root.localName !== 'Relationships')
51
+ return [];
52
+ const isRelationship = (c) => c.nodeType === 1 && c.localName === 'Relationship';
53
+ let wrong = root.namespaceURI !== Namespaces.RELATIONSHIPS ? (_a = root.namespaceURI) !== null && _a !== void 0 ? _a : null : undefined;
54
+ for (let c = root.firstChild; c && wrong === undefined; c = c.nextSibling) {
55
+ if (isRelationship(c) && c.namespaceURI !== Namespaces.RELATIONSHIPS)
56
+ wrong = (_b = c.namespaceURI) !== null && _b !== void 0 ? _b : null;
57
+ }
58
+ if (wrong === undefined)
59
+ return [];
60
+ if (!this.readsByLocalName)
61
+ throw new RelationshipsNamespaceException(this.partName.name, wrong);
62
+ const fixed = inRelationshipsNamespace(doc, root);
63
+ let count = 0;
64
+ while (root.firstChild) {
65
+ const c = root.firstChild;
66
+ root.removeChild(c);
67
+ if (isRelationship(c))
68
+ count++;
69
+ fixed.appendChild(isRelationship(c) && c.namespaceURI !== Namespaces.RELATIONSHIPS ? inRelationshipsNamespace(doc, c) : c);
70
+ }
71
+ doc.replaceChild(fixed, root);
72
+ return [{
73
+ code: 'package.relationships_namespace',
74
+ partName: this.partName.name,
75
+ namespace: wrong,
76
+ count,
77
+ message: `${this.partName.name}: a relationships part in ${wrong === null ? 'no namespace' : `another namespace, ${wrong}`}, `
78
+ + `read as Word's repair reads it, its ${count} relationship${count === 1 ? '' : 's'} by local name (REQ-207)`,
79
+ }];
80
+ }
34
81
  /** The name of the part these relationships belong to; '/' for the package. */
35
82
  get sourceName() {
36
83
  var _a, _b;
@@ -218,6 +265,24 @@ export class RelationshipsPart extends XmlPart {
218
265
  }
219
266
  }
220
267
  }
268
+ /**
269
+ * `el` again, in the relationships namespace under its local name, with its attributes but not its namespace declarations,
270
+ * and with what it holds moved across (CR-031 section 2.3).
271
+ */
272
+ function inRelationshipsNamespace(doc, el) {
273
+ var _a;
274
+ const out = doc.createElementNS(Namespaces.RELATIONSHIPS, (_a = el.localName) !== null && _a !== void 0 ? _a : el.nodeName);
275
+ for (let i = 0; i < el.attributes.length; i++) {
276
+ const a = el.attributes.item(i);
277
+ if (a.name === 'xmlns' || a.name.startsWith('xmlns:'))
278
+ continue;
279
+ out.setAttributeNS(a.namespaceURI, a.name, a.value);
280
+ }
281
+ if (el.localName === 'Relationship')
282
+ while (el.firstChild)
283
+ out.appendChild(el.firstChild);
284
+ return out;
285
+ }
221
286
  export function isExternal(rel) {
222
287
  return rel.targetMode === 'External';
223
288
  }
@@ -1,8 +1,15 @@
1
- import { type Jsonix } from '@docx4j/generated-objects-ts';
2
- import { Part } from './Part.mjs';
1
+ import { type Jsonix, type OutOfRange, type MisplacedChild } from '@docx4j/generated-objects-ts';
2
+ import { Part, type PartBytesOptions } from './Part.mjs';
3
3
  import { PartName } from '../opc/PartName.mjs';
4
4
  import { type Bound } from '../model/content/binder.mjs';
5
- import type { PartWarning } from '../opc/mce/preprocessor.mjs';
5
+ import type { PartWarning, ValueOutOfRangeWarning, MisplacedContentWarning } from '../opc/mce/preprocessor.mjs';
6
+ import { type ContentSkippedWarning } from '../opc/skipped.mjs';
7
+ /**
8
+ * An integer attribute value Word 365 reads differently, as the objects facade reports it on read or on save, as a
9
+ * warning (CR-017 P2 and P3). The value stays as written; the message says what Word would read, the storage and the
10
+ * range Word keeps as written, from the table entry the report names (`storage`, `property` and `rule`, objects 0.7.0).
11
+ */
12
+ export declare function valueOutOfRange(report: OutOfRange, partName: string | undefined): ValueOutOfRangeWarning;
6
13
  /** What `selectObjects` needs: the engine to evaluate with, and any prefixes beyond the defaults. */
7
14
  export interface SelectOptions {
8
15
  /** The engine; `pkg.selectObjects` and `Body.select` pass the package's. It is readied on the snapshot. */
@@ -13,6 +20,13 @@ export interface SelectOptions {
13
20
  /** Prefixes added to (or overriding) the objects package's own table. */
14
21
  namespaces?: Record<string, string> | undefined;
15
22
  }
23
+ /**
24
+ * A child its container never admits, as the objects facade reports it on read or on save (its CR-017's
25
+ * `onMisplaced`), as a warning (CR-016 D7, D2): docx4j-python's code and fields (`target.misplaced`; `holder` and `item`
26
+ * docx4j's class names), docx4j's message after the part and the place (the path on save; the container, the child's
27
+ * place in its list and the line on read).
28
+ */
29
+ export declare function misplacedContent(report: MisplacedChild, partName: string | undefined): MisplacedContentWarning;
16
30
  /** A qualified name for a part's root element. */
17
31
  export interface RootName {
18
32
  namespaceURI: string;
@@ -36,13 +50,9 @@ export declare class XmlPart<T = unknown> extends Part {
36
50
  rootName: RootName | undefined;
37
51
  /** Runs over the DOM before unmarshalling; the package sets its MCE preprocessor here. */
38
52
  preprocessor: DomPreprocessor | undefined;
39
- /**
40
- * The namespace declarations the source root element carried, prefix to URI, recorded when the
41
- * part was parsed. They are what `mc:Ignorable` prefixes the object model does not bind are
42
- * re-declared from on marshal; see `declareIgnorablePrefixes`.
43
- */
44
- private sourceDeclarations;
45
53
  private parseWarnings;
54
+ /** The bytes given to `setBytes` that the tree was read from; undefined where it came from the source container. */
55
+ private parsedBytes;
46
56
  constructor(partName: PartName | string, contentType: string, relationshipType: string, rootName?: RootName);
47
57
  /** True once contents were unmarshalled or set; the part is then re-marshalled on save. */
48
58
  get isUnmarshalled(): boolean;
@@ -54,9 +64,14 @@ export declare class XmlPart<T = unknown> extends Part {
54
64
  */
55
65
  get isUntouched(): boolean;
56
66
  /**
57
- * What the preprocessor reported the last time this part was parsed (CR-010 phase 1): an
58
- * mc:AlternateContent whose branches' text differs (`mce.branches_differ`). Empty until the part
59
- * is parsed, by `getContents()` or a private read, and again once its contents are set.
67
+ * What the last parse of this part reported: an mc:AlternateContent whose branches' text differs
68
+ * (`mce.branches_differ`, CR-010 phase 1), each attribute value its type refuses that was read as
69
+ * Word 365 reads it (`value.kept.exact`, `value.kept.invalid`, `value.truncated`, `value.refused`: CR-015 D8,
70
+ * CR-017 P1), each integer attribute value past what Word stores, kept as written (`value.out_of_range`,
71
+ * CR-017 P2), and each child its container never admits, kept as read but a string the runtime drops
72
+ * (`target.misplaced`, CR-016 D7), and a w:br outside a w:r read as Word reads it (`br.outside_run`, CR-021).
73
+ * Empty until the part is parsed, by `getContents()` or a private read, and again
74
+ * once its contents are set.
60
75
  */
61
76
  get warnings(): readonly PartWarning[];
62
77
  /** The unmarshalled contents (docx4j getJaxbElement()); throws when not yet unmarshalled. */
@@ -75,17 +90,46 @@ export declare class XmlPart<T = unknown> extends Part {
75
90
  * reads the styles and numbering parts of a document nobody has otherwise touched.
76
91
  */
77
92
  readContents(): Promise<T>;
93
+ /** `readContents`'s typed element: the live one, else a private tree from the part's bytes. */
94
+ private readElement;
95
+ /**
96
+ * Every child the part holds that its container never admits (CR-016 D6, the check on request): what a save would
97
+ * refuse the part for, each with its path, the rule and docx4j's message naming the fix, found by the objects
98
+ * facade's walk over the tree (a marshal to nothing); the part is not changed, and one never unmarshalled stays
99
+ * untouched, read privately. `[]` for a part whose content is all in its place.
100
+ */
101
+ checkContent(): Promise<MisplacedContentWarning[]>;
102
+ /**
103
+ * The DOM before unmarshalling: a w:br outside a w:r put in a run, as Word reads it (CR-021: a reading of the file,
104
+ * not an option, so ahead of the package's hook, which sees the repaired DOM), then the hook.
105
+ */
78
106
  private preprocess;
107
+ /**
108
+ * Reads the part's root before anything else meets the DOM; nothing by default. A main document part reads a root other than
109
+ * `w:document` here (WD REQ-318 to REQ-320, CR-028), throwing for one Word refuses.
110
+ */
111
+ protected readRoot(_doc: Document): readonly PartWarning[];
112
+ private preprocessed;
79
113
  /** Replaces the contents (docx4j setJaxbElement / setContents). The root name defaults to the part's. */
80
114
  setContents(value: T, rootName?: RootName): void;
81
115
  /** Replaces the contents with raw XML bytes; they are unmarshalled on the next getContents(). */
82
116
  setBytes(bytes: Uint8Array): void;
117
+ /** What the read of the tree held now dropped (CR-025): nothing for a part not unmarshalled, or given contents. */
118
+ get skippedByRead(): readonly ContentSkippedWarning[];
119
+ /** The bytes the tree held now was read from. */
120
+ bytesRead(): Promise<Uint8Array | undefined>;
121
+ /**
122
+ * Whether the tree is still what its source reads as (CR-025 section 2.2): the source read again and the two marshalled
123
+ * alike. The save has no change log to ask, so this is for a part that holds skipped content, and only that: such a part,
124
+ * read and not changed, is copied, where a marshal would lose what the read dropped. What can't be compared counts as changed.
125
+ */
126
+ isUnchangedSinceRead(): Promise<boolean>;
83
127
  /** Replaces the contents with XML text (docx4j setContents from a string). */
84
128
  setXml(xml: string): void;
85
129
  /** The XML as it would be saved (docx4j XmlUtils.marshaltoString on the part). */
86
130
  getXml(): Promise<string>;
87
131
  /** Marshalled bytes when unmarshalled or set, else the source bytes untouched. */
88
- getBytes(): Promise<Uint8Array>;
132
+ getBytes(options?: PartBytesOptions): Promise<Uint8Array>;
89
133
  /**
90
134
  * The objects an XPath selects in this part, through a DOM marshalled for the purpose
91
135
  * (CR-006; docx4j `JaxbXmlPart.getJAXBNodesViaXPath`, which does it with a JAXB `Binder`).
@@ -104,8 +148,12 @@ export declare class XmlPart<T = unknown> extends Part {
104
148
  * (CR-002 section 31).
105
149
  */
106
150
  selectObjects(xpath: string, options?: SelectOptions): Promise<Bound[]>;
107
- /** The root element as a DOM element (docx4j XmlUtils.marshaltoW3CDomDocument). */
108
- marshalToNode(): Promise<Element>;
151
+ /**
152
+ * The root element as a DOM element (docx4j XmlUtils.marshaltoW3CDomDocument). Run properties are written in
153
+ * their normal form unless the package's `normaliseOnSave` (else the objects package's `setNormaliseOnSave`) is
154
+ * false (CR-015 D2, the objects facade's CR-013 phase C): the tree keeps what it read.
155
+ */
156
+ marshalToNode(options?: PartBytesOptions): Promise<Element>;
109
157
  /**
110
158
  * Parses the part's bytes, and names the part when the XML is not well-formed. xmldom's error
111
159
  * (Node) carries the line and column of the fault; a browser's says them in its text, which
@@ -124,21 +172,4 @@ export declare class XmlPart<T = unknown> extends Part {
124
172
  * locator).
125
173
  */
126
174
  private unmarshal;
127
- /** The source root element's namespace declarations, prefix to URI (`xmlns=` is the empty prefix). */
128
- private recordDeclarations;
129
- /**
130
- * Every prefix the marshalled root's `mc:Ignorable` names must be declared on that root
131
- * (ECMA-376 Part 3 10.1.2; Word and Excel treat an undeclared one as a corrupt part and offer
132
- * to repair the file). The object model binds only the namespaces it has modules for, so an
133
- * `mc:Ignorable` prefix whose content was dropped on unmarshal - `xr6`, `xr10` and `xr2` on
134
- * Excel's `xl/workbook.xml`, for instance - loses its declaration: the runtime declares one
135
- * prefix per entry of the objects package's table and the facade can only *remove* unused
136
- * declarations, never add one it never made (CR-001 section 17).
137
- *
138
- * So the part re-declares them itself: from what the source root declared, else from the
139
- * objects package's `NAMESPACE_PREFIXES`. A prefix neither knows is dropped from
140
- * `mc:Ignorable` - an undeclared prefix is the one thing that must not be written - and warned
141
- * about once.
142
- */
143
- private declareIgnorablePrefixes;
144
175
  }