@docx4j/core-ts 0.6.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 (119) hide show
  1. package/README.md +60 -0
  2. package/dist/model/content/Body.mjs +6 -17
  3. package/dist/model/content/Comment.d.mts +2 -2
  4. package/dist/model/content/Comment.mjs +12 -7
  5. package/dist/model/content/ContentControl.d.mts +1 -1
  6. package/dist/model/content/ContentControl.mjs +8 -4
  7. package/dist/model/content/Font.d.mts +4 -1
  8. package/dist/model/content/Font.mjs +6 -2
  9. package/dist/model/content/List.d.mts +6 -3
  10. package/dist/model/content/List.mjs +15 -8
  11. package/dist/model/content/Paragraph.d.mts +12 -2
  12. package/dist/model/content/Paragraph.mjs +31 -11
  13. package/dist/model/content/Table.mjs +26 -16
  14. package/dist/model/content/TrackedChange.d.mts +2 -2
  15. package/dist/model/content/TrackedChange.mjs +6 -3
  16. package/dist/model/content/index.d.mts +3 -1
  17. package/dist/model/content/index.mjs +4 -1
  18. package/dist/model/content/ooxml.mjs +12 -1
  19. package/dist/model/content/paraIds.d.mts +5 -0
  20. package/dist/model/content/paraIds.mjs +54 -0
  21. package/dist/model/content/search.d.mts +2 -0
  22. package/dist/model/content/search.mjs +51 -7
  23. package/dist/model/content/story.d.mts +5 -2
  24. package/dist/model/content/story.mjs +6 -3
  25. package/dist/model/content/tableRules.mjs +2 -0
  26. package/dist/model/content/tracking.d.mts +35 -6
  27. package/dist/model/content/tracking.mjs +93 -12
  28. package/dist/model/content/tree.d.mts +7 -8
  29. package/dist/model/content/tree.mjs +7 -9
  30. package/dist/model/content/wordRange.d.mts +48 -0
  31. package/dist/model/content/wordRange.mjs +97 -0
  32. package/dist/model/customxml/CustomXmlPartCollection.d.mts +22 -1
  33. package/dist/model/customxml/CustomXmlPartCollection.mjs +48 -2
  34. package/dist/model/customxml/XmlMapping.d.mts +31 -7
  35. package/dist/model/customxml/XmlMapping.mjs +53 -10
  36. package/dist/model/customxml/bindings.d.mts +12 -2
  37. package/dist/model/customxml/bindings.mjs +98 -16
  38. package/dist/model/customxml/index.d.mts +1 -0
  39. package/dist/model/customxml/index.mjs +1 -0
  40. package/dist/model/customxml/opendope.d.mts +4 -1
  41. package/dist/model/customxml/opendope.mjs +9 -6
  42. package/dist/model/customxml/pictures.mjs +5 -3
  43. package/dist/model/customxml/storeItems.d.mts +57 -0
  44. package/dist/model/customxml/storeItems.mjs +122 -0
  45. package/dist/model/customxml/xhtml.mjs +15 -20
  46. package/dist/model/dateZone.d.mts +25 -0
  47. package/dist/model/dateZone.mjs +57 -0
  48. package/dist/model/index.d.mts +1 -0
  49. package/dist/model/index.mjs +1 -0
  50. package/dist/model/properties/PropertyResolver.d.mts +14 -1
  51. package/dist/model/properties/PropertyResolver.mjs +18 -3
  52. package/dist/model/properties/index.d.mts +1 -1
  53. package/dist/model/properties/log.mjs +2 -2
  54. package/dist/model/properties/styleUtil.d.mts +3 -1
  55. package/dist/model/properties/styleUtil.mjs +20 -24
  56. package/dist/model/text/CaseMapping.d.mts +38 -0
  57. package/dist/model/text/CaseMapping.mjs +86 -0
  58. package/dist/model/text/Extractor.d.mts +66 -6
  59. package/dist/model/text/Extractor.mjs +300 -56
  60. package/dist/model/text/PlainText.mjs +7 -4
  61. package/dist/model/text/TextContext.d.mts +103 -8
  62. package/dist/model/text/TextContext.mjs +228 -53
  63. package/dist/model/text/TextOptions.d.mts +88 -5
  64. package/dist/model/text/TextOptions.mjs +158 -17
  65. package/dist/model/text/TextResult.d.mts +126 -9
  66. package/dist/model/text/TextResult.mjs +115 -12
  67. package/dist/model/text/WmlToMarkdown.mjs +32 -7
  68. package/dist/model/text/caseMapping.generated.d.mts +7 -0
  69. package/dist/model/text/caseMapping.generated.mjs +214 -0
  70. package/dist/model/text/index.d.mts +3 -2
  71. package/dist/model/text/index.mjs +1 -0
  72. package/dist/model/wordIntegers.d.mts +29 -0
  73. package/dist/model/wordIntegers.mjs +78 -0
  74. package/dist/office-js/document.mjs +15 -1
  75. package/dist/office-js/toApiScript.mjs +8 -7
  76. package/dist/opc/DirectoryPartStore.d.mts +6 -2
  77. package/dist/opc/DirectoryPartStore.mjs +11 -4
  78. package/dist/opc/FlatOpcPartStore.d.mts +4 -2
  79. package/dist/opc/FlatOpcPartStore.mjs +11 -8
  80. package/dist/opc/Load.d.mts +32 -0
  81. package/dist/opc/Load.mjs +115 -5
  82. package/dist/opc/PartStore.d.mts +34 -1
  83. package/dist/opc/PartStore.mjs +71 -8
  84. package/dist/opc/Save.d.mts +17 -2
  85. package/dist/opc/Save.mjs +100 -4
  86. package/dist/opc/ZipPartStore.d.mts +4 -2
  87. package/dist/opc/ZipPartStore.mjs +12 -7
  88. package/dist/opc/exceptions.d.mts +140 -0
  89. package/dist/opc/exceptions.mjs +108 -0
  90. package/dist/opc/index.d.mts +7 -4
  91. package/dist/opc/index.mjs +5 -3
  92. package/dist/opc/mce/preprocessor.d.mts +121 -10
  93. package/dist/opc/mce/preprocessor.mjs +122 -21
  94. package/dist/opc/mce/understood.d.mts +3 -35
  95. package/dist/opc/mce/understood.mjs +27 -53
  96. package/dist/opc/repair/breaks.d.mts +23 -0
  97. package/dist/opc/repair/breaks.mjs +288 -0
  98. package/dist/opc/repair/hosts.d.mts +12 -0
  99. package/dist/opc/repair/hosts.mjs +33 -0
  100. package/dist/opc/repair/mainRoot.d.mts +19 -0
  101. package/dist/opc/repair/mainRoot.mjs +168 -0
  102. package/dist/opc/repair/unknownElements.d.mts +8 -0
  103. package/dist/opc/repair/unknownElements.mjs +180 -0
  104. package/dist/opc/repair/wmlNames.generated.d.mts +2 -0
  105. package/dist/opc/repair/wmlNames.generated.mjs +80 -0
  106. package/dist/opc/skipped.d.mts +50 -0
  107. package/dist/opc/skipped.mjs +140 -0
  108. package/dist/packages/OpcPackage.d.mts +98 -5
  109. package/dist/packages/OpcPackage.mjs +122 -7
  110. package/dist/packages/WordprocessingMLPackage.mjs +3 -1
  111. package/dist/packages/index.d.mts +1 -1
  112. package/dist/parts/Part.d.mts +5 -1
  113. package/dist/parts/RelationshipsPart.d.mts +15 -0
  114. package/dist/parts/RelationshipsPart.mjs +66 -1
  115. package/dist/parts/XmlPart.d.mts +54 -5
  116. package/dist/parts/XmlPart.mjs +203 -10
  117. package/dist/parts/wml/index.d.mts +12 -1
  118. package/dist/parts/wml/index.mjs +25 -1
  119. package/package.json +2 -2
@@ -1,3 +1,4 @@
1
+ import type { MisplacedContentWarning } from './mce/preprocessor.mjs';
1
2
  /** docx4j Docx4JException: anything the packaging layer cannot recover from. */
2
3
  export declare class Docx4JException extends Error {
3
4
  readonly cause: unknown;
@@ -11,6 +12,113 @@ export declare class InvalidFormatException extends Docx4JException {
11
12
  cause?: unknown;
12
13
  });
13
14
  }
15
+ /**
16
+ * A relationships part in another namespace, or in none, on its root or on any `Relationship` (CR-025 section 8, D10): refused when
17
+ * it is read, which is at the load, since the walk reads every relationships part it meets. Word reads such a part only through a
18
+ * repair, which reads every `Relationship` by its local name (the `rels-namespace` round), where the runtime here drops each one
19
+ * in a wrong namespace and with it the part it names, so a save would lose those parts with nothing said. `namespace` is the
20
+ * namespace found, `null` for none. The code is docx4j's and the WD's. `LoadOptions.repair: 'word'` reads such a part as Word's
21
+ * repair does, every `Relationship` by its local name (CR-031 section 2.3).
22
+ */
23
+ export declare class RelationshipsNamespaceException extends InvalidFormatException {
24
+ readonly partName: string;
25
+ readonly namespace: string | null;
26
+ /** The finding's code, the WD's, shared with docx4j and docx4j-python. */
27
+ readonly code = "package.relationships_namespace";
28
+ constructor(partName: string, namespace: string | null);
29
+ }
30
+ /**
31
+ * A package whose container holds two entries of one name, OPC part names compared without case (WD REQ-206; CR-024),
32
+ * refused when it is loaded, before anything is read. Word reads such a file only after a repair, and the readers that
33
+ * don't refuse read different copies. `entries` gives each duplicated name, as its first entry spells it, with the
34
+ * number of entries; `LoadOptions.repair: 'word'` reads the first copy of each instead (CR-031).
35
+ */
36
+ export declare class DuplicateEntryException extends InvalidFormatException {
37
+ readonly entries: Readonly<Record<string, number>>;
38
+ /** The finding's code, shared with docx4j-python (its CR-032). */
39
+ readonly code = "package.duplicate_entry";
40
+ constructor(entries: Readonly<Record<string, number>>);
41
+ }
42
+ /**
43
+ * Under `LoadOptions.repair: 'word'` or `'all'`, a name the container holds more than one entry of (WD REQ-206; CR-024):
44
+ * the first entry in the container's order is read, the rest ignored, and a save writes only the copy read, as Word's
45
+ * repaired save does. On `pkg.warnings`, ahead of the parts' warnings. The code and the fields are docx4j-python's (its
46
+ * CR-032): `entry`, the name as the first entry spells it (no leading '/'), and `count`, the entries of that name.
47
+ */
48
+ export interface DuplicateEntryWarning {
49
+ code: 'package.duplicate_entry';
50
+ entry: string;
51
+ count: number;
52
+ message: string;
53
+ }
54
+ /**
55
+ * A package whose package relationships hold more than one officeDocument relationship (WD REQ-206's statement, WD 0.100;
56
+ * CR-024 section 9), refused when it is loaded, as a duplicated entry is and for the same reason: Word reads such a file
57
+ * only through a repair, and which target it reads then alternates with each repaired open in a Word session. A
58
+ * transitional and a strict relationship are two, and so are two naming one target. An External one names no part and
59
+ * isn't counted. `targets` gives each as a part name (`/word/document.xml`), in the relationships' order.
60
+ * `LoadOptions.repair: 'word'` reads the last relationship's target instead, as a fresh Word does (CR-031).
61
+ */
62
+ export declare class MultipleMainPartsException extends InvalidFormatException {
63
+ readonly targets: readonly string[];
64
+ /** The finding's code, the WD's, shared with docx4j and docx4j-python. */
65
+ readonly code = "package.multiple_main_parts";
66
+ constructor(targets: readonly string[]);
67
+ }
68
+ /**
69
+ * Under `LoadOptions.repair: 'word'` or `'all'`, a package with more than one officeDocument relationship (WD REQ-206's
70
+ * statement; CR-024 section 9): the last relationship's target is read, as a fresh Word reads it, the other relationships
71
+ * go at the load, and a save writes the one main part. On `pkg.warnings`, after any `DuplicateEntryWarning` and ahead of
72
+ * the parts' warnings. The fields are docx4j-python's: `partName`, the part read (`/word/document.xml`), and `count`, the
73
+ * relationships there were.
74
+ */
75
+ export interface MultipleMainPartsWarning {
76
+ code: 'package.multiple_main_parts';
77
+ partName: string;
78
+ count: number;
79
+ message: string;
80
+ }
81
+ /**
82
+ * An `External` officeDocument relationship beside an internal one (WD REQ-206's NOTE, WD 0.102; CR-031 D3), refused at the load
83
+ * under `LoadOptions.repair` `'refuse'`, the default, and `'word'`, first or last alike: Word offers a repair and then fails
84
+ * (the `x-ext-*` rounds), so there is no reading of Word's to follow. `urls` gives each `External` relationship's target as
85
+ * written and `targets` each internal one's as a part name, in the relationships' order (docx4j-python's fields). The URL is
86
+ * never fetched. `repair: 'all'` reads the internal target instead, a repair of this package's own.
87
+ */
88
+ export declare class ExternalMainPartException extends InvalidFormatException {
89
+ readonly urls: readonly string[];
90
+ readonly targets: readonly string[];
91
+ /** The finding's code, the WD's, shared with docx4j and docx4j-python. */
92
+ readonly code = "package.external_main_part";
93
+ constructor(urls: readonly string[], targets: readonly string[]);
94
+ }
95
+ /**
96
+ * Under `LoadOptions.repair: 'all'`, an `External` officeDocument relationship beside an internal one (WD REQ-206's NOTE;
97
+ * CR-031 section 2.2): the internal target is read, every `External` officeDocument relationship goes at the load, so a save
98
+ * writes none, and the URL is never fetched. A repair of this package's own, so a reading's `repaired` is `own`. On
99
+ * `pkg.externalMainPart` and on `pkg.warnings`, after the other load warnings. `partName` is the part read, `urls` each URL
100
+ * as written, in the relationships' order (the text model's `detail` the first).
101
+ */
102
+ export interface ExternalMainPartWarning {
103
+ code: 'package.external_main_part';
104
+ partName: string;
105
+ urls: readonly string[];
106
+ message: string;
107
+ }
108
+ /**
109
+ * Under `LoadOptions.repair: 'word'` or `'all'`, a relationships part in another namespace, or in none, on its root or on any
110
+ * `Relationship` (CR-031 section 2.3; CR-025 section 8 refuses it otherwise): every `Relationship` is read by its local name,
111
+ * as Word's repair reads it, and a save writes the right namespace, so nothing is lost. On the relationships part's `warnings`
112
+ * and so on `pkg.warnings`. `partName` is the relationships part, `namespace` the first wrong one found (`null` for none),
113
+ * `count` the relationships read (the WD's `detail`, docx4j's).
114
+ */
115
+ export interface RelationshipsNamespaceWarning {
116
+ code: 'package.relationships_namespace';
117
+ partName: string;
118
+ namespace: string | null;
119
+ count: number;
120
+ message: string;
121
+ }
14
122
  /**
15
123
  * docx4j CyclicStylesException: a style's `w:basedOn` chain comes back to a style it already
16
124
  * holds, or goes deeper than docx4j's limit of 32. Thrown only when
@@ -70,3 +178,35 @@ export declare class PartUnmarshalException extends Docx4JException {
70
178
  readonly line: number | undefined;
71
179
  readonly column: number | undefined;
72
180
  }
181
+ /**
182
+ * A save refused for a child its container never admits (CR-016 D2): the part being marshalled holds a run straight in
183
+ * the body, a table in a paragraph, a string in a run, ..., which Word 365 refuses the file for or repairs by dropping
184
+ * content (check 72). Nothing was written. `findings` are the part's, each with its path and docx4j's message naming
185
+ * the fix; `pkg.checkContentOnSave = false` writes the file as held and reports them on `pkg.lastSave.misplaced` instead.
186
+ */
187
+ export declare class MisplacedContentException extends Docx4JException {
188
+ /** The part refused: `/word/document.xml`. */
189
+ readonly partName: string;
190
+ readonly findings: readonly MisplacedContentWarning[];
191
+ constructor(
192
+ /** The part refused: `/word/document.xml`. */
193
+ partName: string, findings: readonly MisplacedContentWarning[], options?: {
194
+ cause?: unknown;
195
+ });
196
+ }
197
+ /** One part a save would lose content from (CR-025 section 2.3). */
198
+ export interface ContentLoss {
199
+ partName: string;
200
+ kind: 'skipped';
201
+ /** The items its read dropped that Word's own save doesn't drop too: `part.skipped` with `onSave: 'lost'`, one each (CR-025 section 10). */
202
+ count: number;
203
+ }
204
+ /**
205
+ * A save refused because a part holding what its read dropped was changed, so a marshal would lose that (CR-025 section 2.3, the
206
+ * repair policy's P7). Nothing is written. The code and the wording are docx4j-python's, with this package's way past it.
207
+ */
208
+ export declare class SaveLossException extends Docx4JException {
209
+ readonly losses: readonly ContentLoss[];
210
+ readonly code = "save.content_lost";
211
+ constructor(losses: readonly ContentLoss[]);
212
+ }
@@ -13,6 +13,83 @@ export class InvalidFormatException extends Docx4JException {
13
13
  this.name = 'InvalidFormatException';
14
14
  }
15
15
  }
16
+ /**
17
+ * A relationships part in another namespace, or in none, on its root or on any `Relationship` (CR-025 section 8, D10): refused when
18
+ * it is read, which is at the load, since the walk reads every relationships part it meets. Word reads such a part only through a
19
+ * repair, which reads every `Relationship` by its local name (the `rels-namespace` round), where the runtime here drops each one
20
+ * in a wrong namespace and with it the part it names, so a save would lose those parts with nothing said. `namespace` is the
21
+ * namespace found, `null` for none. The code is docx4j's and the WD's. `LoadOptions.repair: 'word'` reads such a part as Word's
22
+ * repair does, every `Relationship` by its local name (CR-031 section 2.3).
23
+ */
24
+ export class RelationshipsNamespaceException extends InvalidFormatException {
25
+ constructor(partName, namespace) {
26
+ super(`${partName}: a relationships part in ${namespace === null ? 'no namespace' : `another namespace, ${namespace}`}, which Word reads `
27
+ + "only through a repair; refused, since its relationships would be lost with the parts they name. Load with { repair: 'word' } "
28
+ + 'to read every Relationship by its local name, as Word does (REQ-207)');
29
+ this.partName = partName;
30
+ this.namespace = namespace;
31
+ /** The finding's code, the WD's, shared with docx4j and docx4j-python. */
32
+ this.code = 'package.relationships_namespace';
33
+ this.name = 'RelationshipsNamespaceException';
34
+ }
35
+ }
36
+ /**
37
+ * A package whose container holds two entries of one name, OPC part names compared without case (WD REQ-206; CR-024),
38
+ * refused when it is loaded, before anything is read. Word reads such a file only after a repair, and the readers that
39
+ * don't refuse read different copies. `entries` gives each duplicated name, as its first entry spells it, with the
40
+ * number of entries; `LoadOptions.repair: 'word'` reads the first copy of each instead (CR-031).
41
+ */
42
+ export class DuplicateEntryException extends InvalidFormatException {
43
+ constructor(entries) {
44
+ const list = Object.entries(entries);
45
+ super(list.length === 1
46
+ ? `Duplicate entry ${list[0][0]} in this package: ${list[0][1]} entries (REQ-206). Load with { repair: 'word' } to read the first, as Word does (REQ-207)`
47
+ : `Duplicate entries in this package: ${list.map(([name, n]) => `${name}, ${n} entries`).join('; ')} (REQ-206). `
48
+ + "Load with { repair: 'word' } to read the first of each, as Word does (REQ-207)");
49
+ this.entries = entries;
50
+ /** The finding's code, shared with docx4j-python (its CR-032). */
51
+ this.code = 'package.duplicate_entry';
52
+ this.name = 'DuplicateEntryException';
53
+ }
54
+ }
55
+ /**
56
+ * A package whose package relationships hold more than one officeDocument relationship (WD REQ-206's statement, WD 0.100;
57
+ * CR-024 section 9), refused when it is loaded, as a duplicated entry is and for the same reason: Word reads such a file
58
+ * only through a repair, and which target it reads then alternates with each repaired open in a Word session. A
59
+ * transitional and a strict relationship are two, and so are two naming one target. An External one names no part and
60
+ * isn't counted. `targets` gives each as a part name (`/word/document.xml`), in the relationships' order.
61
+ * `LoadOptions.repair: 'word'` reads the last relationship's target instead, as a fresh Word does (CR-031).
62
+ */
63
+ export class MultipleMainPartsException extends InvalidFormatException {
64
+ constructor(targets) {
65
+ super(`${targets.length} officeDocument relationships in this package: ${targets.join(', ')} (REQ-206). `
66
+ + "Load with { repair: 'word' } to read the last, as a fresh Word does (REQ-207)");
67
+ this.targets = targets;
68
+ /** The finding's code, the WD's, shared with docx4j and docx4j-python. */
69
+ this.code = 'package.multiple_main_parts';
70
+ this.name = 'MultipleMainPartsException';
71
+ }
72
+ }
73
+ /**
74
+ * An `External` officeDocument relationship beside an internal one (WD REQ-206's NOTE, WD 0.102; CR-031 D3), refused at the load
75
+ * under `LoadOptions.repair` `'refuse'`, the default, and `'word'`, first or last alike: Word offers a repair and then fails
76
+ * (the `x-ext-*` rounds), so there is no reading of Word's to follow. `urls` gives each `External` relationship's target as
77
+ * written and `targets` each internal one's as a part name, in the relationships' order (docx4j-python's fields). The URL is
78
+ * never fetched. `repair: 'all'` reads the internal target instead, a repair of this package's own.
79
+ */
80
+ export class ExternalMainPartException extends InvalidFormatException {
81
+ constructor(urls, targets) {
82
+ super(`${urls.length === 1 ? 'An External officeDocument relationship' : `${urls.length} External officeDocument relationships`} in this package, `
83
+ + `to ${urls.join(', ')}, beside ${targets.length === 1 ? 'an internal one' : `${targets.length} internal ones`}, to ${targets.join(', ')} `
84
+ + "(REQ-206). Word refuses such a package, even through its repair. Load with { repair: 'all' } to read "
85
+ + `${targets[targets.length - 1]} and drop the External relationship, a repair of this package's own (REQ-207)`);
86
+ this.urls = urls;
87
+ this.targets = targets;
88
+ /** The finding's code, the WD's, shared with docx4j and docx4j-python. */
89
+ this.code = 'package.external_main_part';
90
+ this.name = 'ExternalMainPartException';
91
+ }
92
+ }
16
93
  /**
17
94
  * docx4j CyclicStylesException: a style's `w:basedOn` chain comes back to a style it already
18
95
  * holds, or goes deeper than docx4j's limit of 32. Thrown only when
@@ -78,3 +155,34 @@ export class PartUnmarshalException extends Docx4JException {
78
155
  this.column = options === null || options === void 0 ? void 0 : options.column;
79
156
  }
80
157
  }
158
+ /**
159
+ * A save refused for a child its container never admits (CR-016 D2): the part being marshalled holds a run straight in
160
+ * the body, a table in a paragraph, a string in a run, ..., which Word 365 refuses the file for or repairs by dropping
161
+ * content (check 72). Nothing was written. `findings` are the part's, each with its path and docx4j's message naming
162
+ * the fix; `pkg.checkContentOnSave = false` writes the file as held and reports them on `pkg.lastSave.misplaced` instead.
163
+ */
164
+ export class MisplacedContentException extends Docx4JException {
165
+ constructor(
166
+ /** The part refused: `/word/document.xml`. */
167
+ partName, findings, options) {
168
+ super(`Save refused: ${partName} holds ${findings.length === 1 ? 'a child its container never admits' : `${findings.length} children their containers never admit`}, `
169
+ + 'which Word 365 refuses the file for or repairs by dropping content (set pkg.checkContentOnSave = false to write it as held):\n'
170
+ + findings.map((f) => ` ${f.message}`).join('\n'), options);
171
+ this.partName = partName;
172
+ this.findings = findings;
173
+ this.name = 'MisplacedContentException';
174
+ }
175
+ }
176
+ /**
177
+ * A save refused because a part holding what its read dropped was changed, so a marshal would lose that (CR-025 section 2.3, the
178
+ * repair policy's P7). Nothing is written. The code and the wording are docx4j-python's, with this package's way past it.
179
+ */
180
+ export class SaveLossException extends Docx4JException {
181
+ constructor(losses) {
182
+ super(`Saving would lose content Word's own save keeps or isn't measured on: ${losses.map((l) => `${l.partName} holds ${l.count} item${l.count === 1 ? '' : 's'} the load skipped (part.skipped, onSave lost)`).join(', ')}. `
183
+ + `Set pkg.checkLossOnSave = false to write ${losses.length === 1 ? 'the part without it' : 'the parts without them'}.`);
184
+ this.losses = losses;
185
+ this.code = 'save.content_lost';
186
+ this.name = 'SaveLossException';
187
+ }
188
+ }
@@ -4,9 +4,12 @@ export { ContentTypeManager, CONTENT_TYPES_NS } from './ContentTypeManager.mjs';
4
4
  export { type PartStore, type PartSink, type PutOptions, MemoryPartStore, MemoryPartSink } from './PartStore.mjs';
5
5
  export { ZipPartStore, ZipPartSink } from './ZipPartStore.mjs';
6
6
  export { FlatOpcPartStore, FlatOpcPartSink, type FlatOpcSinkOptions, PKG_NS } from './FlatOpcPartStore.mjs';
7
- export { loadPackage, type LoadOptions } from './Load.mjs';
7
+ export { loadPackage, type LoadOptions, type RepairMode, REPAIR_MODES } from './Load.mjs';
8
8
  export { savePackage, type ValueNormalised, type SaveReport } from './Save.mjs';
9
- export { mceKeep, mcePreprocess, createMcePreprocessor, resolveAlternateContent, preprocessAlternateContent, MCE_NS, KEPT_HOSTS, type McePreprocessOptions, type McBranchesDifferWarning, type ValueKeptWarning, type PartWarning, type MceResult } from './mce/preprocessor.mjs';
10
- export { UNDERSTOOD_NAMESPACES, UNDERSTOOD_PREFIXES, READ_ONLY_UNDERSTOOD_NAMESPACES, READ_UNDERSTOOD_NAMESPACES, READ_UNDERSTOOD_PREFIXES } from './mce/understood.mjs';
11
- export { Docx4JException, InvalidFormatException, PartUnrecognisedException, PartUnmarshalException, CyclicStylesException, PropertyResolverNotCreatedException } from './exceptions.mjs';
9
+ export { mceKeep, mcePreprocess, createMcePreprocessor, resolveAlternateContent, preprocessAlternateContent, MCE_NS, KEPT_HOSTS, type McePreprocessOptions, type McBranchesDifferWarning, type McNothingSelectedWarning, type McUndeclaredPrefixWarning, type ValueKeptWarning, type ValueOutOfRangeWarning, type MisplacedContentWarning, type PartWarning, type MceResult } from './mce/preprocessor.mjs';
10
+ export { repairBreaksOutsideRuns, type BrOutsideRunWarning } from './repair/breaks.mjs';
11
+ export { readMainPartRoot, type UnexpectedRootWarning } from './repair/mainRoot.mjs';
12
+ export type { ContentSkippedWarning } from './skipped.mjs';
13
+ export { UNDERSTOOD_NAMESPACES, TRAVERSAL_NAMESPACES } from './mce/understood.mjs';
14
+ export { Docx4JException, InvalidFormatException, PartUnrecognisedException, PartUnmarshalException, MisplacedContentException, SaveLossException, type ContentLoss, DuplicateEntryException, type DuplicateEntryWarning, MultipleMainPartsException, type MultipleMainPartsWarning, RelationshipsNamespaceException, type RelationshipsNamespaceWarning, ExternalMainPartException, type ExternalMainPartWarning, CyclicStylesException, PropertyResolverNotCreatedException } from './exceptions.mjs';
12
15
  export { parseXml, serializeXml, serializeXmlPart, createDocument, encodeText, decodeXmlText, stripXmlDeclaration, base64Encode, base64Decode, childElements, XML_DECLARATION } from '../xml/dom.mjs';
@@ -5,9 +5,11 @@ export { ContentTypeManager, CONTENT_TYPES_NS } from './ContentTypeManager.mjs';
5
5
  export { MemoryPartStore, MemoryPartSink } from './PartStore.mjs';
6
6
  export { ZipPartStore, ZipPartSink } from './ZipPartStore.mjs';
7
7
  export { FlatOpcPartStore, FlatOpcPartSink, PKG_NS } from './FlatOpcPartStore.mjs';
8
- export { loadPackage } from './Load.mjs';
8
+ export { loadPackage, REPAIR_MODES } from './Load.mjs';
9
9
  export { savePackage } from './Save.mjs';
10
10
  export { mceKeep, mcePreprocess, createMcePreprocessor, resolveAlternateContent, preprocessAlternateContent, MCE_NS, KEPT_HOSTS } from './mce/preprocessor.mjs';
11
- export { UNDERSTOOD_NAMESPACES, UNDERSTOOD_PREFIXES, READ_ONLY_UNDERSTOOD_NAMESPACES, READ_UNDERSTOOD_NAMESPACES, READ_UNDERSTOOD_PREFIXES } from './mce/understood.mjs';
12
- export { Docx4JException, InvalidFormatException, PartUnrecognisedException, PartUnmarshalException, CyclicStylesException, PropertyResolverNotCreatedException } from './exceptions.mjs';
11
+ export { repairBreaksOutsideRuns } from './repair/breaks.mjs';
12
+ export { readMainPartRoot } from './repair/mainRoot.mjs';
13
+ export { UNDERSTOOD_NAMESPACES, TRAVERSAL_NAMESPACES } from './mce/understood.mjs';
14
+ export { Docx4JException, InvalidFormatException, PartUnrecognisedException, PartUnmarshalException, MisplacedContentException, SaveLossException, DuplicateEntryException, MultipleMainPartsException, RelationshipsNamespaceException, ExternalMainPartException, CyclicStylesException, PropertyResolverNotCreatedException } from './exceptions.mjs';
13
15
  export { parseXml, serializeXml, serializeXmlPart, createDocument, encodeText, decodeXmlText, stripXmlDeclaration, base64Encode, base64Decode, childElements, XML_DECLARATION } from '../xml/dom.mjs';
@@ -1,4 +1,8 @@
1
1
  import type { XmlPart } from '../../parts/XmlPart.mjs';
2
+ import type { BrOutsideRunWarning } from '../repair/breaks.mjs';
3
+ import type { UnexpectedRootWarning } from '../repair/mainRoot.mjs';
4
+ import type { ContentSkippedWarning } from '../skipped.mjs';
5
+ import type { RelationshipsNamespaceWarning } from '../exceptions.mjs';
2
6
  export declare const MCE_NS = "http://schemas.openxmlformats.org/markup-compatibility/2006";
3
7
  /**
4
8
  * The hosts whose mc:AlternateContent is kept whole on load, as `{namespace}localName`
@@ -6,7 +10,7 @@ export declare const MCE_NS = "http://schemas.openxmlformats.org/markup-compatib
6
10
  */
7
11
  export declare const KEPT_HOSTS: ReadonlySet<string>;
8
12
  export interface McePreprocessOptions {
9
- /** Namespaces counted as understood; defaults to `READ_UNDERSTOOD_NAMESPACES` (CR-013 D3). */
13
+ /** Namespaces counted as understood; defaults to `UNDERSTOOD_NAMESPACES`, the 114 Word 365 was measured to understand (WD REQ-306). */
10
14
  understood?: ReadonlySet<string>;
11
15
  /** Hosts, as `{namespace}localName`, whose mc:AlternateContent is left whole; defaults to `KEPT_HOSTS`. */
12
16
  keptHosts?: ReadonlySet<string>;
@@ -15,6 +19,12 @@ export interface McePreprocessOptions {
15
19
  * warnings, from the same elements, and no change to the DOM. Defaults to true.
16
20
  */
17
21
  resolve?: boolean;
22
+ /**
23
+ * Whether this is a word-processing part, where an element nothing can be selected from is reported and removed (WD
24
+ * REQ-305); in any other it is left whole and said nothing of (CR-029 D3). Defaults to true; the preprocessors read it
25
+ * from the part's content type.
26
+ */
27
+ wordProcessing?: boolean;
18
28
  }
19
29
  /**
20
30
  * What load reports about a part (CR-010 phase 1; the text extraction paper's warning channel).
@@ -36,14 +46,49 @@ export interface McBranchesDifferWarning {
36
46
  }[];
37
47
  message: string;
38
48
  }
49
+ /**
50
+ * `mce.nothing_selected` (WD REQ-305, CR-029): an mc:AlternateContent with Choices, none understood, and no Fallback, so
51
+ * that the element and all it holds are absent, as ISO and Word read it. `namespaces` gives what its Choices require, each
52
+ * once, in order, a prefix nothing binds having none. `removed` says a resolving load took it out; `root` that it is a part's
53
+ * root, which is left whole. A reader's walk meets neither, so the text model carries such a warning with no address.
54
+ */
55
+ export interface McNothingSelectedWarning {
56
+ code: 'mce.nothing_selected';
57
+ partName: string | undefined;
58
+ /** Where the element starts in the part, where the DOM records it (xmldom does; a browser's DOMParser does not). */
59
+ line?: number;
60
+ column?: number;
61
+ namespaces: string[];
62
+ removed: boolean;
63
+ root: boolean;
64
+ message: string;
65
+ }
66
+ /**
67
+ * `mce.undeclared_prefix` (WD REQ-323, CR-030): an `mc:Ignorable` listing a prefix with no namespace declaration in scope on the
68
+ * element carrying it. Such a prefix names no namespace, so it is read as though the list didn't hold it: nothing it seems to
69
+ * name is ignorable. Word repairs such a file and loses nothing (the `undeclared-ignorable` round). One warning a part, with
70
+ * every such prefix once, in document order. A declaration on a descendant doesn't put a prefix in scope. A save that writes
71
+ * the part anew holds none: the objects facade drops a prefix it doesn't know and declares one it does, and a part copied from
72
+ * its source keeps it as written.
73
+ */
74
+ export interface McUndeclaredPrefixWarning {
75
+ code: 'mce.undeclared_prefix';
76
+ partName: string | undefined;
77
+ prefixes: string[];
78
+ message: string;
79
+ }
39
80
  /**
40
81
  * An attribute value of Word's own WordprocessingML that its type refuses, read as Word 365 reads it
41
82
  * rather than failing the part (CR-015 D8; the objects facade's `wordInvalidValue`, its CR-013):
42
83
  * `value.kept.exact` where the text, trimmed of XML whitespace, is a form its type reads (`" false"`),
43
- * else `value.kept.invalid` (`"yes"`, `"Single"`). The names are docx4j-python CR-018's.
84
+ * else `value.kept.invalid` (`"yes"`, `"Single"`). The codes are this package's (CR-015 D8); the reasons, exact and invalid,
85
+ * are docx4j-python CR-018's (its `KeptValue.reason`). An integer attribute's value Word reads by its own rule (the objects
86
+ * package's CR-015, CR-017 P1): `value.truncated` for a decimal, cut toward zero as Word cuts it (`"720.5"` reads 720);
87
+ * `value.refused` for a form Word refuses a document for (`" 240 "`, `"0x10"`), dropped; `""` and the forms with no
88
+ * digit (`"."`, `"+"`) read as 0, `value.kept.invalid`.
44
89
  */
45
90
  export interface ValueKeptWarning {
46
- code: 'value.kept.exact' | 'value.kept.invalid';
91
+ code: 'value.kept.exact' | 'value.kept.invalid' | 'value.truncated' | 'value.refused';
47
92
  partName: string | undefined;
48
93
  /** Where the element starts in the part, where the DOM records it (xmldom does; a browser's DOMParser does not). */
49
94
  line?: number;
@@ -55,14 +100,80 @@ export interface ValueKeptWarning {
55
100
  text: string;
56
101
  /**
57
102
  * What the tree holds instead: `true` for an on/off value (Word reads only exactly `false`, `off` and
58
- * `0` as off), `'none'` for `w:u`'s on/off words, and undefined where the value was dropped, so the
59
- * attribute reads as absent (a style's value beneath shows).
103
+ * `0` as off), `'none'` for `w:u`'s on/off words, an integer Word's reading of a decimal or of `""`, and
104
+ * undefined where the value was dropped, so the attribute reads as absent (a style's value beneath shows).
60
105
  */
61
- value: boolean | string | undefined;
106
+ value: boolean | string | number | undefined;
107
+ message: string;
108
+ }
109
+ /**
110
+ * An integer attribute value Word 365 reads differently from the tree (CR-017 P2 and P3; the objects facade's
111
+ * `onOutOfRange`, its CR-016, docx4j CR-066's rounds 5 and 6): outside the width Word stores the attribute in, 16 bits
112
+ * for most, where Word reads it wrapped, sometimes then clamped, with no error or repair. The tree keeps the value as
113
+ * written, and a save writes it as held: the warning says what Word would show. The code and the fields are shared
114
+ * with docx4j-python (its CR-020 section 4.7, `word_reads` there), one name across the ports for the one condition
115
+ * (CR-017 E1). On load the warning is on the part, with the line and column where the DOM records them; on save it is
116
+ * on `pkg.lastSave.outOfRange`, with the `path` from the part's root.
117
+ */
118
+ export interface ValueOutOfRangeWarning {
119
+ code: 'value.out_of_range';
120
+ partName: string | undefined;
121
+ /** Where the element starts in the part, where the DOM records it (xmldom does; a browser's DOMParser does not). */
122
+ line?: number;
123
+ column?: number;
124
+ /** On save, the attribute's path from the part's root: `/w:document/w:body[1]/w:p[3]/w:pPr[1]/w:ind[1]/@w:left`. */
125
+ path?: string;
126
+ /** The element and the attribute as the part writes them (`w:ind`, `w:left`). */
127
+ element: string;
128
+ attribute: string;
129
+ /** The value the tree holds, and a save writes. */
130
+ value: number;
131
+ /** What Word reads for it, after the wrap and any clamp; null for an attribute no round measured. */
132
+ wordReads: number | null;
133
+ /** The attribute Word reads the value in, where the shared field's sign moved it: `w:hanging` for a `w:firstLine` of 32768. */
134
+ readAs?: string;
135
+ /** For a line, a row height or a frame's height, the rule Word reads with the value (`exact`, `atLeast`, `auto`). */
136
+ rule?: 'auto' | 'exact' | 'atLeast';
137
+ /** How Word stores the attribute, the objects package's wording: `int16`, `uint16, then 144..31681`, `int16, the sign the rule`, ... */
138
+ storage: string;
139
+ /** The values Word keeps as written there, `[min, max]` in the attribute's own unit (`keptRange`); null where none is known. */
140
+ range: readonly [number, number] | null;
141
+ message: string;
142
+ }
143
+ /**
144
+ * A child its container never admits (CR-016 D7, the objects facade's `onMisplaced`, its CR-017; docx4j CR-064's rules):
145
+ * a run straight in the body, a table in a paragraph, a cell beside a table's rows, a string in a run, or a name and
146
+ * value that disagree. On load, one per child the facade reports as it reads the part, the tree keeping what it read
147
+ * (a string in a run excepted, which the runtime drops: `text` carries it); on a save with `checkContentOnSave` off,
148
+ * one per child written as held, on `pkg.lastSave.misplaced`; with it on, the save is refused with them
149
+ * (`MisplacedContentException`). The code and the fields are docx4j-python's (its CR-020 section 11.12), one code across
150
+ * the ports; `rule`, `text` and `line` are this package's own.
151
+ */
152
+ export interface MisplacedContentWarning {
153
+ code: 'target.misplaced';
154
+ partName: string | undefined;
155
+ /** Where the child (else its container) starts in the part, where the DOM records it (xmldom does). */
156
+ line?: number;
157
+ column?: number;
158
+ /** On save, the child's path from the part's root (`/w:document/w:body[1]/w:p[1]/w:r[1]/w:tbl[1]`); the container's for a string. */
159
+ path?: string;
160
+ /** The container's class, docx4j's name (`P`, `R`, `Tbl`, `CTSdtContentRun`): the objects `TYPE_NAME`'s last segment. */
161
+ holder: string;
162
+ /** The child's position in the list holding it. */
163
+ index: number;
164
+ /** The child's class the same way (`Tbl`, `R`), where it has one; absent for a string. */
165
+ item?: string;
166
+ /** The child's element as the part writes it (`w:tbl`); absent for a string. */
167
+ element?: string;
168
+ /** `misplaced`, a class the container refuses; `name-value`, a value whose class isn't the one its name declares there. */
169
+ rule: 'misplaced' | 'name-value';
170
+ /** For a string in a container that admits none, the string (on load; a save never sees it). */
171
+ text?: string;
172
+ /** docx4j's wording, with the fix: "You can't add a run (w:r) directly to the body (w:body); ...", after the part and the place. */
62
173
  message: string;
63
174
  }
64
175
  /** A warning load records on a part. */
65
- export type PartWarning = McBranchesDifferWarning | ValueKeptWarning;
176
+ export type PartWarning = McBranchesDifferWarning | McNothingSelectedWarning | McUndeclaredPrefixWarning | ValueKeptWarning | ValueOutOfRangeWarning | MisplacedContentWarning | BrOutsideRunWarning | UnexpectedRootWarning | ContentSkippedWarning | RelationshipsNamespaceWarning;
66
177
  /**
67
178
  * What one pass over a DOM did. `kept` counts the elements it met and left whole; it doesn't enter a
68
179
  * branch the rule doesn't select, so an element nested there is not counted.
@@ -77,13 +188,13 @@ export interface MceResult {
77
188
  * warnings are what resolving would report. Returns them.
78
189
  */
79
190
  export declare function mceKeep(doc: Document, part?: XmlPart<unknown>): PartWarning[];
80
- /** The resolving preprocessor (`mcePreprocess: true`), over `READ_UNDERSTOOD_NAMESPACES`. Returns the part's warnings. */
191
+ /** The resolving preprocessor (`mcePreprocess: true`), over `UNDERSTOOD_NAMESPACES`. Returns the part's warnings. */
81
192
  export declare function mcePreprocess(doc: Document, part?: XmlPart<unknown>): PartWarning[];
82
193
  /** A preprocessor over a namespace set (or kept hosts) of your own. */
83
194
  export declare function createMcePreprocessor(options: McePreprocessOptions): (doc: Document, part?: XmlPart<unknown>) => PartWarning[];
84
195
  /**
85
- * Resolves every mc:AlternateContent under a node, outermost first, but those `KEPT_HOSTS` and the
86
- * nothing-selectable rule keep (see the file comment). Returns the number resolved.
196
+ * Resolves every mc:AlternateContent under a node, outermost first, but those the file comment keeps. Returns the number
197
+ * resolved, one nothing was selected from among them.
87
198
  */
88
199
  export declare function resolveAlternateContent(root: Node, understood?: ReadonlySet<string>): number;
89
200
  /**