@docx4j/core-ts 0.1.0 → 0.1.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.
Files changed (172) hide show
  1. package/README.md +410 -10
  2. package/dist/model/content/Body.d.mts +109 -4
  3. package/dist/model/content/Body.mjs +300 -29
  4. package/dist/model/content/Comment.d.mts +78 -0
  5. package/dist/model/content/Comment.mjs +429 -0
  6. package/dist/model/content/ContentControl.d.mts +173 -0
  7. package/dist/model/content/ContentControl.mjs +638 -0
  8. package/dist/model/content/Font.d.mts +48 -8
  9. package/dist/model/content/Font.mjs +55 -13
  10. package/dist/model/content/InlinePicture.d.mts +103 -0
  11. package/dist/model/content/InlinePicture.mjs +361 -0
  12. package/dist/model/content/List.d.mts +253 -0
  13. package/dist/model/content/List.mjs +778 -0
  14. package/dist/model/content/Paragraph.d.mts +213 -16
  15. package/dist/model/content/Paragraph.mjs +611 -57
  16. package/dist/model/content/Range.d.mts +48 -4
  17. package/dist/model/content/Range.mjs +161 -4
  18. package/dist/model/content/Table.d.mts +130 -0
  19. package/dist/model/content/Table.mjs +429 -0
  20. package/dist/model/content/TrackedChange.d.mts +96 -0
  21. package/dist/model/content/TrackedChange.mjs +352 -0
  22. package/dist/model/content/comments.d.mts +122 -0
  23. package/dist/model/content/comments.mjs +248 -0
  24. package/dist/model/content/index.d.mts +13 -3
  25. package/dist/model/content/index.mjs +15 -3
  26. package/dist/model/content/ooxml.d.mts +17 -0
  27. package/dist/model/content/ooxml.mjs +214 -0
  28. package/dist/model/content/styles.d.mts +21 -0
  29. package/dist/model/content/styles.mjs +86 -0
  30. package/dist/model/content/tracking.d.mts +104 -0
  31. package/dist/model/content/tracking.mjs +313 -0
  32. package/dist/model/content/tree.d.mts +56 -9
  33. package/dist/model/content/tree.mjs +104 -31
  34. package/dist/model/customxml/CustomXmlPart.d.mts +158 -0
  35. package/dist/model/customxml/CustomXmlPart.mjs +415 -0
  36. package/dist/model/customxml/CustomXmlPartCollection.d.mts +68 -0
  37. package/dist/model/customxml/CustomXmlPartCollection.mjs +183 -0
  38. package/dist/model/customxml/XmlMapping.d.mts +46 -0
  39. package/dist/model/customxml/XmlMapping.mjs +98 -0
  40. package/dist/model/customxml/bindings.d.mts +41 -0
  41. package/dist/model/customxml/bindings.mjs +230 -0
  42. package/dist/model/customxml/index.d.mts +7 -0
  43. package/dist/model/customxml/index.mjs +9 -0
  44. package/dist/model/customxml/insert.d.mts +20 -0
  45. package/dist/model/customxml/insert.mjs +22 -0
  46. package/dist/model/customxml/kinds.d.mts +103 -0
  47. package/dist/model/customxml/kinds.mjs +267 -0
  48. package/dist/model/customxml/xpath.d.mts +52 -0
  49. package/dist/model/customxml/xpath.mjs +205 -0
  50. package/dist/model/fonts/CJKToEnglish.d.mts +2 -0
  51. package/dist/model/fonts/CJKToEnglish.mjs +16 -0
  52. package/dist/model/fonts/FontFallback.d.mts +58 -0
  53. package/dist/model/fonts/FontFallback.mjs +219 -0
  54. package/dist/model/fonts/IdentityPlusMapper.d.mts +7 -0
  55. package/dist/model/fonts/IdentityPlusMapper.mjs +19 -0
  56. package/dist/model/fonts/LanguageTagToScriptMapping.d.mts +7 -0
  57. package/dist/model/fonts/LanguageTagToScriptMapping.mjs +67 -0
  58. package/dist/model/fonts/Mapper.d.mts +190 -0
  59. package/dist/model/fonts/Mapper.mjs +481 -0
  60. package/dist/model/fonts/PhysicalFont.d.mts +34 -0
  61. package/dist/model/fonts/PhysicalFont.mjs +62 -0
  62. package/dist/model/fonts/RunFontSelector.d.mts +194 -0
  63. package/dist/model/fonts/RunFontSelector.mjs +441 -0
  64. package/dist/model/fonts/ThemeFonts.d.mts +17 -0
  65. package/dist/model/fonts/ThemeFonts.mjs +76 -0
  66. package/dist/model/fonts/defaultTheme.d.mts +37 -0
  67. package/dist/model/fonts/defaultTheme.mjs +57 -0
  68. package/dist/model/fonts/families.generated.d.mts +11 -0
  69. package/dist/model/fonts/families.generated.mjs +17 -0
  70. package/dist/model/fonts/fontsInUse.d.mts +39 -0
  71. package/dist/model/fonts/fontsInUse.mjs +183 -0
  72. package/dist/model/fonts/index.d.mts +14 -0
  73. package/dist/model/fonts/index.mjs +29 -0
  74. package/dist/model/fonts/lookup.d.mts +5 -0
  75. package/dist/model/fonts/lookup.mjs +12 -0
  76. package/dist/model/fonts/registry.d.mts +31 -0
  77. package/dist/model/fonts/registry.mjs +103 -0
  78. package/dist/model/fonts/scripts.d.mts +2 -0
  79. package/dist/model/fonts/scripts.mjs +78 -0
  80. package/dist/model/fonts/substitutions.generated.d.mts +30 -0
  81. package/dist/model/fonts/substitutions.generated.mjs +12 -0
  82. package/dist/model/fonts/themes.generated.d.mts +6 -0
  83. package/dist/model/fonts/themes.generated.mjs +11 -0
  84. package/dist/model/index.d.mts +5 -0
  85. package/dist/model/index.mjs +13 -1
  86. package/dist/model/listnumbering/Emulator.d.mts +187 -0
  87. package/dist/model/listnumbering/Emulator.mjs +332 -0
  88. package/dist/model/listnumbering/definitions.d.mts +251 -0
  89. package/dist/model/listnumbering/definitions.mjs +571 -0
  90. package/dist/model/listnumbering/formats.d.mts +25 -0
  91. package/dist/model/listnumbering/formats.mjs +320 -0
  92. package/dist/model/listnumbering/index.d.mts +4 -0
  93. package/dist/model/listnumbering/index.mjs +15 -0
  94. package/dist/model/listnumbering/state.d.mts +97 -0
  95. package/dist/model/listnumbering/state.mjs +179 -0
  96. package/dist/model/properties/PropertyResolver.d.mts +216 -0
  97. package/dist/model/properties/PropertyResolver.mjs +524 -0
  98. package/dist/model/properties/catalogue.d.mts +179 -0
  99. package/dist/model/properties/catalogue.mjs +860 -0
  100. package/dist/model/properties/index.d.mts +4 -0
  101. package/dist/model/properties/index.mjs +9 -0
  102. package/dist/model/properties/log.d.mts +7 -0
  103. package/dist/model/properties/log.mjs +25 -0
  104. package/dist/model/properties/styleUtil.d.mts +112 -0
  105. package/dist/model/properties/styleUtil.mjs +359 -0
  106. package/dist/node/index.d.mts +1 -0
  107. package/dist/node/index.mjs +12 -0
  108. package/dist/office-js/document.d.mts +111 -0
  109. package/dist/office-js/document.mjs +267 -0
  110. package/dist/office-js/enums.d.mts +187 -0
  111. package/dist/office-js/enums.mjs +176 -0
  112. package/dist/office-js/errors.d.mts +29 -0
  113. package/dist/office-js/errors.mjs +39 -0
  114. package/dist/office-js/extras.d.mts +5 -0
  115. package/dist/office-js/extras.mjs +29 -0
  116. package/dist/office-js/fragment.d.mts +10 -0
  117. package/dist/office-js/fragment.mjs +23 -0
  118. package/dist/office-js/index.d.mts +183 -0
  119. package/dist/office-js/index.mjs +54 -0
  120. package/dist/office-js/proxy.d.mts +72 -0
  121. package/dist/office-js/proxy.mjs +279 -0
  122. package/dist/office-js/run.d.mts +32 -0
  123. package/dist/office-js/run.mjs +66 -0
  124. package/dist/office-js/supported.d.mts +7 -0
  125. package/dist/office-js/supported.generated.d.mts +1 -0
  126. package/dist/office-js/supported.generated.mjs +235 -0
  127. package/dist/office-js/supported.mjs +53 -0
  128. package/dist/office-js/toApiScript.d.mts +25 -0
  129. package/dist/office-js/toApiScript.mjs +394 -0
  130. package/dist/opc/ContentTypes.d.mts +11 -0
  131. package/dist/opc/ContentTypes.mjs +14 -0
  132. package/dist/opc/DirectoryPartStore.d.mts +47 -0
  133. package/dist/opc/DirectoryPartStore.mjs +123 -0
  134. package/dist/opc/exceptions.d.mts +30 -0
  135. package/dist/opc/exceptions.mjs +38 -0
  136. package/dist/opc/index.d.mts +1 -1
  137. package/dist/opc/index.mjs +1 -1
  138. package/dist/packages/OpcPackage.d.mts +19 -1
  139. package/dist/packages/OpcPackage.mjs +29 -0
  140. package/dist/packages/PresentationMLPackage.d.mts +71 -1
  141. package/dist/packages/PresentationMLPackage.mjs +179 -0
  142. package/dist/packages/SpreadsheetMLPackage.d.mts +30 -1
  143. package/dist/packages/SpreadsheetMLPackage.mjs +78 -0
  144. package/dist/packages/WordprocessingMLPackage.d.mts +124 -2
  145. package/dist/packages/WordprocessingMLPackage.mjs +309 -2
  146. package/dist/packages/index.d.mts +1 -1
  147. package/dist/packages/index.mjs +1 -1
  148. package/dist/parts/DefaultXmlPart.d.mts +18 -0
  149. package/dist/parts/DefaultXmlPart.mjs +34 -5
  150. package/dist/parts/Namespaces.d.mts +18 -0
  151. package/dist/parts/Namespaces.mjs +20 -0
  152. package/dist/parts/Part.d.mts +6 -0
  153. package/dist/parts/Part.mjs +13 -0
  154. package/dist/parts/PartRegistry.mjs +13 -1
  155. package/dist/parts/XmlPart.d.mts +33 -0
  156. package/dist/parts/XmlPart.mjs +105 -2
  157. package/dist/parts/pml/defaults.d.mts +6 -0
  158. package/dist/parts/pml/defaults.mjs +53 -0
  159. package/dist/parts/pml/index.d.mts +66 -3
  160. package/dist/parts/pml/index.mjs +206 -7
  161. package/dist/parts/pml/placeholders.d.mts +71 -0
  162. package/dist/parts/pml/placeholders.mjs +141 -0
  163. package/dist/parts/sml/index.d.mts +80 -1
  164. package/dist/parts/sml/index.mjs +154 -1
  165. package/dist/parts/wml/comments.d.mts +1 -0
  166. package/dist/parts/wml/comments.mjs +179 -0
  167. package/dist/parts/wml/defaultNumbering.d.mts +1 -0
  168. package/dist/parts/wml/defaultNumbering.mjs +216 -0
  169. package/dist/parts/wml/index.d.mts +121 -0
  170. package/dist/parts/wml/index.mjs +291 -0
  171. package/dist/xml/dom.mjs +1 -2
  172. package/package.json +25 -4
@@ -91,6 +91,26 @@ export const Namespaces = {
91
91
  SPREADSHEETML_PIVOT_CACHE_DEFINITION: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition',
92
92
  SPREADSHEETML_PIVOT_CACHE_RECORDS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheRecords',
93
93
  SPREADSHEETML_EXTERNAL_LINK: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLink',
94
+ // The Excel 2010 and 2013 extension parts (CR-004): slicers and their caches are 2007,
95
+ // timelines 2011, the survey 2010; the rest are the officeDocument ones.
96
+ /** `/xl/slicerCaches/slicerCache1.xml`, from the workbook. */
97
+ SPREADSHEETML_SLICER_CACHE: 'http://schemas.microsoft.com/office/2007/relationships/slicerCache',
98
+ /** `/xl/slicers/slicer1.xml`, from a worksheet. */
99
+ SPREADSHEETML_SLICERS: 'http://schemas.microsoft.com/office/2007/relationships/slicer',
100
+ /** `/xl/timelineCaches/timelineCache1.xml`, from the workbook. */
101
+ SPREADSHEETML_TIMELINE_CACHE: 'http://schemas.microsoft.com/office/2011/relationships/timelineCache',
102
+ /** `/xl/timelines/timeline1.xml`, from a worksheet. */
103
+ SPREADSHEETML_TIMELINES: 'http://schemas.microsoft.com/office/2011/relationships/timeline',
104
+ /** `/xl/ctrlProps/ctrlProp1.xml`, from a worksheet, for one of its form controls. */
105
+ SPREADSHEETML_CONTROL_PROPERTIES: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/ctrlProp',
106
+ /** `/xl/customDataProps/customDataProps1.xml`, from the workbook. */
107
+ SPREADSHEETML_CUSTOM_DATA_PROPERTIES: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/customDataProps',
108
+ /** `/xl/customData/customData1.dat`, from its properties part. */
109
+ SPREADSHEETML_CUSTOM_DATA: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/customData',
110
+ /** `/xl/surveys/survey1.xml`, from the workbook. */
111
+ SPREADSHEETML_SURVEY: 'http://schemas.microsoft.com/office/2010/relationships/Survey',
112
+ /** `/xl/model/item.data` ([MS-XLDM]), from the workbook. */
113
+ SPREADSHEETML_DATA_MODEL: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/powerPivotData',
94
114
  WEB_EXTENSION_TASKPANES: 'http://schemas.microsoft.com/office/webextensions/taskpanes/2010/11',
95
115
  WEB_EXTENSION_WEBEXTENSION: 'http://schemas.microsoft.com/office/webextensions/webextension/2010/11',
96
116
  XML_EVENTS: 'http://www.w3.org/2001/xml-events',
@@ -39,6 +39,12 @@ export declare abstract class Part implements RelationshipSource {
39
39
  * its content type in the content type manager, and a relationship in this part's relationships.
40
40
  */
41
41
  addTargetPart(target: Part, mode?: AddPartBehaviour, proposedRelId?: string): Relationship;
42
+ /**
43
+ * This part's targets of one relationship type that are instances of a class, in relationship
44
+ * order: what a shortcut for a collection of parts (a sheet's slicers, a workbook's slicer
45
+ * caches) is made of.
46
+ */
47
+ protected partsByRelationshipType<T extends Part>(relationshipType: string, cls: abstract new (...args: never[]) => T): T[];
42
48
  /** Subclasses keep typed references to well-known targets (styles, numbering, ...); returns true when one was set. */
43
49
  setPartShortcut(_part: Part, _relationshipType: string): boolean;
44
50
  /** The bytes this part was loaded from, if it came from a container. Undefined for new parts. */
@@ -47,6 +47,19 @@ export class Part {
47
47
  this.setPartShortcut(target, target.relationshipType);
48
48
  return rel;
49
49
  }
50
+ /**
51
+ * This part's targets of one relationship type that are instances of a class, in relationship
52
+ * order: what a shortcut for a collection of parts (a sheet's slicers, a workbook's slicer
53
+ * caches) is made of.
54
+ */
55
+ partsByRelationshipType(relationshipType, cls) {
56
+ const rp = this.relationshipsPart;
57
+ if (!rp)
58
+ return [];
59
+ return rp.getRelationshipsByType(relationshipType)
60
+ .map((r) => rp.getPart(r))
61
+ .filter((p) => p instanceof cls);
62
+ }
50
63
  /** Subclasses keep typed references to well-known targets (styles, numbering, ...); returns true when one was set. */
51
64
  setPartShortcut(_part, _relationshipType) {
52
65
  return false;
@@ -61,6 +61,7 @@ export const defaultPartRegistry = new PartRegistry()
61
61
  .registerForRelationship(Namespaces.EMBEDDED_PKG, (n, ct) => new EmbeddedPackagePart(n, ct))
62
62
  .registerForRelationship(Namespaces.OLE_OBJECT, (n, ct) => new OleObjectBinaryPart(n, ct))
63
63
  .registerForRelationship(Namespaces.CUSTOM_XML_DATA_STORAGE, (n, ct) => new CustomXmlDataStoragePart(n, ct))
64
+ .registerForRelationship(Namespaces.SPREADSHEETML_CUSTOM_DATA, (n, ct) => new sml.CustomDataPart(n, ct))
64
65
  .register(ContentTypes.WORDPROCESSINGML_DOCUMENT, (n, ct) => new wml.MainDocumentPart(n, ct))
65
66
  .register(ContentTypes.WORDPROCESSINGML_DOCUMENT_MACROENABLED, (n, ct) => new wml.MainDocumentPart(n, ct))
66
67
  .register(ContentTypes.WORDPROCESSINGML_TEMPLATE, (n, ct) => new wml.MainDocumentPart(n, ct))
@@ -78,6 +79,7 @@ export const defaultPartRegistry = new PartRegistry()
78
79
  .register(ContentTypes.WORDPROCESSINGML_COMMENTS, (n) => new wml.CommentsPart(n))
79
80
  .register(ContentTypes.WORDPROCESSINGML_COMMENTS_EXTENDED, (n) => new wml.CommentsExtendedPart(n))
80
81
  .register(ContentTypes.WORDPROCESSINGML_COMMENTS_IDS, (n) => new wml.CommentsIdsPart(n))
82
+ .register(ContentTypes.WORDPROCESSINGML_COMMENTS_EXTENSIBLE, (n) => new wml.CommentsExtensiblePart(n))
81
83
  .register(ContentTypes.WORDPROCESSINGML_PEOPLE, (n) => new wml.PeoplePart(n))
82
84
  .register(ContentTypes.MS_WORD_KEYMAP, (n) => new wml.KeyMapCustomizationsPart(n))
83
85
  .register(ContentTypes.OFFICEDOCUMENT_VBA_DATA, (n) => new wml.VbaDataPart(n))
@@ -139,4 +141,14 @@ export const defaultPartRegistry = new PartRegistry()
139
141
  .register(ContentTypes.SPREADSHEETML_QUERY_TABLE, (n) => new sml.QueryTablePart(n))
140
142
  .register(ContentTypes.SPREADSHEETML_CONNECTIONS, (n) => new sml.ConnectionsPart(n))
141
143
  .register(ContentTypes.SPREADSHEETML_EXTERNAL_LINK, (n) => new sml.ExternalLinkPart(n))
142
- .register(ContentTypes.SPREADSHEETML_PRINTER_SETTINGS, (n) => new sml.PrinterSettingsPart(n));
144
+ .register(ContentTypes.SPREADSHEETML_PRINTER_SETTINGS, (n) => new sml.PrinterSettingsPart(n))
145
+ // The Excel 2010 and 2013 extension parts (CR-004). `CustomDataPart`'s content type is the
146
+ // generic `application/binary`, so it is registered by relationship type above instead.
147
+ .register(ContentTypes.SPREADSHEETML_SLICER_CACHE, (n) => new sml.SlicerCachePart(n))
148
+ .register(ContentTypes.SPREADSHEETML_SLICERS, (n) => new sml.SlicersPart(n))
149
+ .register(ContentTypes.SPREADSHEETML_TIMELINE_CACHE, (n) => new sml.TimelineCachePart(n))
150
+ .register(ContentTypes.SPREADSHEETML_TIMELINES, (n) => new sml.TimelinesPart(n))
151
+ .register(ContentTypes.SPREADSHEETML_CONTROL_PROPERTIES, (n) => new sml.ControlPropertiesPart(n))
152
+ .register(ContentTypes.SPREADSHEETML_CUSTOM_DATA_PROPERTIES, (n) => new sml.CustomDataPropertiesPart(n))
153
+ .register(ContentTypes.SPREADSHEETML_SURVEY, (n) => new sml.SurveyPart(n))
154
+ .register(ContentTypes.SPREADSHEETML_DATA_MODEL, (n) => new sml.DataModelPart(n));
@@ -21,6 +21,12 @@ export declare class XmlPart<T = unknown> extends Part {
21
21
  rootName: RootName | undefined;
22
22
  /** Runs over the DOM before unmarshalling; the package sets its MCE preprocessor here. */
23
23
  preprocessor: DomPreprocessor | undefined;
24
+ /**
25
+ * The namespace declarations the source root element carried, prefix to URI, recorded when the
26
+ * part was parsed. They are what `mc:Ignorable` prefixes the object model does not bind are
27
+ * re-declared from on marshal; see `declareIgnorablePrefixes`.
28
+ */
29
+ private sourceDeclarations;
24
30
  constructor(partName: PartName | string, contentType: string, relationshipType: string, rootName?: RootName);
25
31
  /** True once contents were unmarshalled or set; the part is then re-marshalled on save. */
26
32
  get isUnmarshalled(): boolean;
@@ -31,6 +37,16 @@ export declare class XmlPart<T = unknown> extends Part {
31
37
  get typedElement(): Jsonix.TypedNamedValue<T> | undefined;
32
38
  /** Unmarshals on first call (docx4j getContents()). */
33
39
  getContents(): Promise<T>;
40
+ /**
41
+ * The contents as a **private tree**, without marking the part unmarshalled - so a part read
42
+ * this way is still written back from its source bytes, byte for byte. The live tree is
43
+ * returned when the part is already unmarshalled, since then the part is re-marshalled
44
+ * anyway and a second copy would only go stale.
45
+ *
46
+ * This is what a reader that must not cost a part its round trip uses: `PropertyResolver`
47
+ * reads the styles and numbering parts of a document nobody has otherwise touched.
48
+ */
49
+ readContents(): Promise<T>;
34
50
  /** Replaces the contents (docx4j setJaxbElement / setContents). The root name defaults to the part's. */
35
51
  setContents(value: T, rootName?: RootName): void;
36
52
  /** Replaces the contents with raw XML bytes; they are unmarshalled on the next getContents(). */
@@ -43,4 +59,21 @@ export declare class XmlPart<T = unknown> extends Part {
43
59
  getBytes(): Promise<Uint8Array>;
44
60
  /** The root element as a DOM element (docx4j XmlUtils.marshaltoW3CDomDocument). */
45
61
  marshalToNode(): Promise<Element>;
62
+ /** The source root element's namespace declarations, prefix to URI (`xmlns=` is the empty prefix). */
63
+ private recordDeclarations;
64
+ /**
65
+ * Every prefix the marshalled root's `mc:Ignorable` names must be declared on that root
66
+ * (ECMA-376 Part 3 10.1.2; Word and Excel treat an undeclared one as a corrupt part and offer
67
+ * to repair the file). The object model binds only the namespaces it has modules for, so an
68
+ * `mc:Ignorable` prefix whose content was dropped on unmarshal - `xr6`, `xr10` and `xr2` on
69
+ * Excel's `xl/workbook.xml`, for instance - loses its declaration: the runtime declares one
70
+ * prefix per entry of the objects package's table and the facade can only *remove* unused
71
+ * declarations, never add one it never made (CR-001 section 17).
72
+ *
73
+ * So the part re-declares them itself: from what the source root declared, else from the
74
+ * objects package's `NAMESPACE_PREFIXES`. A prefix neither knows is dropped from
75
+ * `mc:Ignorable` - an undeclared prefix is the one thing that must not be written - and warned
76
+ * about once.
77
+ */
78
+ private declareIgnorablePrefixes;
46
79
  }
@@ -1,7 +1,23 @@
1
- import { unmarshalNode, marshalNode } from '@docx4j/generated-objects-ts';
1
+ import { unmarshalNode, marshalNode, NAMESPACE_PREFIXES } from '@docx4j/generated-objects-ts';
2
2
  import { Part } from './Part.mjs';
3
+ import { Namespaces } from './Namespaces.mjs';
3
4
  import { Docx4JException } from '../opc/exceptions.mjs';
4
5
  import { parseXml, serializeXml, encodeText, decodeXmlText, XML_DECLARATION } from '../xml/dom.mjs';
6
+ import { log } from '../model/properties/log.mjs';
7
+ const XMLNS_NS = 'http://www.w3.org/2000/xmlns/';
8
+ const MC_NS = Namespaces.MARKUP_COMPATIBILITY;
9
+ /** The objects package's prefix table the other way round, prefix to URI, built once. */
10
+ let prefixToUri;
11
+ function knownUriOf(prefix) {
12
+ if (prefixToUri === undefined) {
13
+ prefixToUri = new Map();
14
+ for (const [uri, p] of Object.entries(NAMESPACE_PREFIXES))
15
+ if (p !== '' && !prefixToUri.has(p))
16
+ prefixToUri.set(p, uri);
17
+ }
18
+ return prefixToUri.get(prefix);
19
+ }
20
+ const warnedPrefixes = new Set();
5
21
  /**
6
22
  * A part whose content is a typed element of the object model (docx4j JaxbXmlPart<E>). `T` is the
7
23
  * root element's value type (`Document`, `Styles`, ...). Contents are unmarshalled on first
@@ -38,6 +54,7 @@ export class XmlPart extends Part {
38
54
  if (bytes === undefined)
39
55
  throw new Docx4JException(`Part ${this.partName} has no content: set contents or load it from a container`);
40
56
  const doc = parseXml(decodeXmlText(bytes));
57
+ this.recordDeclarations(doc);
41
58
  (_b = this.preprocessor) === null || _b === void 0 ? void 0 : _b.call(this, doc, this);
42
59
  this.element = await unmarshalNode(doc);
43
60
  (_c = this.rootName) !== null && _c !== void 0 ? _c : (this.rootName = { namespaceURI: this.element.name.namespaceURI, localPart: this.element.name.localPart });
@@ -45,6 +62,27 @@ export class XmlPart extends Part {
45
62
  }
46
63
  return this.element.value;
47
64
  }
65
+ /**
66
+ * The contents as a **private tree**, without marking the part unmarshalled - so a part read
67
+ * this way is still written back from its source bytes, byte for byte. The live tree is
68
+ * returned when the part is already unmarshalled, since then the part is re-marshalled
69
+ * anyway and a second copy would only go stale.
70
+ *
71
+ * This is what a reader that must not cost a part its round trip uses: `PropertyResolver`
72
+ * reads the styles and numbering parts of a document nobody has otherwise touched.
73
+ */
74
+ async readContents() {
75
+ var _a, _b;
76
+ if (this.element !== undefined)
77
+ return this.element.value;
78
+ const bytes = (_a = this.bytes) !== null && _a !== void 0 ? _a : (await this.loadSourceBytes());
79
+ if (bytes === undefined)
80
+ throw new Docx4JException(`Part ${this.partName} has no content: set contents or load it from a container`);
81
+ const doc = parseXml(decodeXmlText(bytes));
82
+ this.recordDeclarations(doc);
83
+ (_b = this.preprocessor) === null || _b === void 0 ? void 0 : _b.call(this, doc, this);
84
+ return (await unmarshalNode(doc)).value;
85
+ }
48
86
  /** Replaces the contents (docx4j setJaxbElement / setContents). The root name defaults to the part's. */
49
87
  setContents(value, rootName) {
50
88
  var _a, _b;
@@ -82,6 +120,71 @@ export class XmlPart extends Part {
82
120
  async marshalToNode() {
83
121
  if (this.element === undefined)
84
122
  await this.getContents();
85
- return marshalNode(this.element);
123
+ const root = await marshalNode(this.element);
124
+ this.declareIgnorablePrefixes(root);
125
+ return root;
126
+ }
127
+ /** The source root element's namespace declarations, prefix to URI (`xmlns=` is the empty prefix). */
128
+ recordDeclarations(doc) {
129
+ var _a;
130
+ const root = doc.documentElement;
131
+ if (!root)
132
+ return;
133
+ const map = new Map();
134
+ for (const attr of Array.from(root.attributes)) {
135
+ if (attr.name === 'xmlns')
136
+ map.set('', attr.value);
137
+ else if (attr.namespaceURI === XMLNS_NS || attr.name.startsWith('xmlns:'))
138
+ map.set((_a = attr.localName) !== null && _a !== void 0 ? _a : attr.name.slice(6), attr.value);
139
+ }
140
+ this.sourceDeclarations = map;
141
+ }
142
+ /**
143
+ * Every prefix the marshalled root's `mc:Ignorable` names must be declared on that root
144
+ * (ECMA-376 Part 3 10.1.2; Word and Excel treat an undeclared one as a corrupt part and offer
145
+ * to repair the file). The object model binds only the namespaces it has modules for, so an
146
+ * `mc:Ignorable` prefix whose content was dropped on unmarshal - `xr6`, `xr10` and `xr2` on
147
+ * Excel's `xl/workbook.xml`, for instance - loses its declaration: the runtime declares one
148
+ * prefix per entry of the objects package's table and the facade can only *remove* unused
149
+ * declarations, never add one it never made (CR-001 section 17).
150
+ *
151
+ * So the part re-declares them itself: from what the source root declared, else from the
152
+ * objects package's `NAMESPACE_PREFIXES`. A prefix neither knows is dropped from
153
+ * `mc:Ignorable` - an undeclared prefix is the one thing that must not be written - and warned
154
+ * about once.
155
+ */
156
+ declareIgnorablePrefixes(root) {
157
+ var _a, _b;
158
+ const attr = Array.from(root.attributes).find((a) => { var _a; return a.namespaceURI === MC_NS && ((_a = a.localName) !== null && _a !== void 0 ? _a : a.name) === 'Ignorable'; });
159
+ if (!attr)
160
+ return;
161
+ const prefixes = attr.value.split(/\s+/).filter((p) => p !== '');
162
+ if (prefixes.length === 0)
163
+ return;
164
+ const kept = [];
165
+ let dropped = false;
166
+ for (const prefix of prefixes) {
167
+ if (root.getAttributeNS(XMLNS_NS, prefix) || root.getAttribute(`xmlns:${prefix}`)) {
168
+ kept.push(prefix);
169
+ continue;
170
+ }
171
+ const uri = (_b = (_a = this.sourceDeclarations) === null || _a === void 0 ? void 0 : _a.get(prefix)) !== null && _b !== void 0 ? _b : knownUriOf(prefix);
172
+ if (uri === undefined) {
173
+ dropped = true;
174
+ if (!warnedPrefixes.has(prefix)) {
175
+ warnedPrefixes.add(prefix);
176
+ log.warn(`${this.partName}: mc:Ignorable names the prefix "${prefix}", which nothing declares; dropping it (an undeclared prefix makes Word and Excel offer to repair the file)`);
177
+ }
178
+ continue;
179
+ }
180
+ root.setAttributeNS(XMLNS_NS, `xmlns:${prefix}`, uri);
181
+ kept.push(prefix);
182
+ }
183
+ if (!dropped)
184
+ return;
185
+ if (kept.length === 0)
186
+ root.removeAttributeNode(attr);
187
+ else
188
+ root.setAttributeNS(MC_NS, attr.name, kept.join(' '));
86
189
  }
87
190
  }
@@ -0,0 +1,6 @@
1
+ /** `/ppt/slideMasters/slideMaster1.xml` as docx4j's `SlideMasterPart.createSldMaster()` writes it. */
2
+ export declare const DEFAULT_SLIDE_MASTER_XML: string;
3
+ /** `/ppt/slideLayouts/slideLayout1.xml` as docx4j's `SlideLayoutPart.createSldLayout()` writes it. */
4
+ export declare const DEFAULT_SLIDE_LAYOUT_XML: string;
5
+ /** `/ppt/slides/slide1.xml` as docx4j's `SlidePart.createSld()` writes it. */
6
+ export declare const DEFAULT_SLIDE_XML: string;
@@ -0,0 +1,53 @@
1
+ // The template markup `PresentationMLPackage.createPackage()` starts a new presentation from, as
2
+ // docx4j builds it (docx4j VERSION_17_1_1 a58cf10b8):
3
+ //
4
+ // docx4j-core/src/main/java/org/docx4j/openpackaging/parts/PresentationML/JaxbPmlPart.java
5
+ // COMMON_SLIDE_DATA, COLOR_MAPPING
6
+ // .../PresentationML/SlideMasterPart.java createSldMaster()
7
+ // .../PresentationML/SlideLayoutPart.java createSldLayout() (cSld name "Title Slide")
8
+ // .../PresentationML/SlidePart.java createSld()
9
+ //
10
+ // docx4j unmarshals those fragments into a JAXB tree and marshals it back out; here they are the
11
+ // whole part, so a created slide, layout or master that nobody touches is written byte for byte
12
+ // as docx4j writes it. Generated content, not hand markup: do not edit without the Java.
13
+ //
14
+ // The placeholder shapes a created layout and slide also carry are not here either: they are
15
+ // built with the generated factories in `placeholders.mts`, because PowerPoint offers
16
+ // "Click to add title" only where the slide itself holds them (CR-001 section 17.2). So the
17
+ // layout and the slide are unmarshalled during creation and are no longer written byte for byte
18
+ // as they are below; the master still is.
19
+ //
20
+ // The theme part is not here: `createPackage()` uses the same embedded Office themes as
21
+ // `WordprocessingMLPackage.createPackage()` (`src/model/fonts/themes.generated.mts`), so which
22
+ // theme a new presentation carries follows `pkg.fonts.defaultTheme`, as it does for a new
23
+ // document. docx4j instead ships one fixed
24
+ // `org/docx4j/openpackaging/parts/PresentationML/theme.xml` (CR-001 section 16).
25
+ const XML_DECL = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
26
+ const NS = ' xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"'
27
+ + ' xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"'
28
+ + ' xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"';
29
+ /** docx4j `JaxbPmlPart.COMMON_SLIDE_DATA`: an empty shape tree. `name` is the `p:cSld/@name`. */
30
+ function commonSlideData(name) {
31
+ return `<p:cSld${name === undefined ? '' : ` name="${name}"`}>`
32
+ + '<p:spTree>'
33
+ + '<p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>'
34
+ + '<p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr>'
35
+ + '</p:spTree>'
36
+ + '</p:cSld>';
37
+ }
38
+ /** docx4j `JaxbPmlPart.COLOR_MAPPING`: the identity colour map a master needs. */
39
+ const COLOR_MAPPING = '<p:clrMap bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1"'
40
+ + ' accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6"'
41
+ + ' hlink="hlink" folHlink="folHlink"/>';
42
+ /** `/ppt/slideMasters/slideMaster1.xml` as docx4j's `SlideMasterPart.createSldMaster()` writes it. */
43
+ export const DEFAULT_SLIDE_MASTER_XML = `${XML_DECL}<p:sldMaster${NS}>`
44
+ + commonSlideData() + COLOR_MAPPING + '<p:sldLayoutIdLst/>'
45
+ + '</p:sldMaster>';
46
+ /** `/ppt/slideLayouts/slideLayout1.xml` as docx4j's `SlideLayoutPart.createSldLayout()` writes it. */
47
+ export const DEFAULT_SLIDE_LAYOUT_XML = `${XML_DECL}<p:sldLayout${NS}>`
48
+ + commonSlideData('Title Slide')
49
+ + '</p:sldLayout>';
50
+ /** `/ppt/slides/slide1.xml` as docx4j's `SlidePart.createSld()` writes it. */
51
+ export const DEFAULT_SLIDE_XML = `${XML_DECL}<p:sld${NS}>`
52
+ + commonSlideData()
53
+ + '</p:sld>';
@@ -4,21 +4,83 @@ import { XmlPart } from '../XmlPart.mjs';
4
4
  import { BinaryPart } from '../BinaryPart.mjs';
5
5
  import { Part } from '../Part.mjs';
6
6
  import { PartName } from '../../opc/PartName.mjs';
7
+ import type { AddPartBehaviour } from '../RelationshipsPart.mjs';
7
8
  import { ThemePart } from '../dml/index.mjs';
9
+ /**
10
+ * A new `p:sldId/@id` (docx4j `JaxbPmlPart.getSlideId()`, ECMA-376 4.8.17 ST_SlideId: 256 to
11
+ * 2147483647). Random, as docx4j's is: nothing in the package numbers them.
12
+ */
13
+ export declare function nextSlideId(): number;
14
+ /**
15
+ * A new `p:sldLayoutId/@id` or `p:sldMasterId/@id` (docx4j
16
+ * `JaxbPmlPart.getSlideLayoutOrMasterId()`, ECMA-376 4.8.18 and 4.8.20: above 2147483648).
17
+ */
18
+ export declare function nextSlideLayoutOrMasterId(): number;
8
19
  export declare class MainPresentationPart extends XmlPart<pml.Presentation> {
9
20
  themePart: ThemePart | undefined;
21
+ notesMasterPart: NotesMasterPart | undefined;
22
+ commentAuthorsPart: CommentAuthorsPart | undefined;
23
+ presentationPropertiesPart: PresentationPropertiesPart | undefined;
24
+ viewPropertiesPart: ViewPropertiesPart | undefined;
25
+ tableStylesPart: TableStylesPart | undefined;
10
26
  constructor(partName?: PartName | string, contentType?: string);
11
27
  setPartShortcut(part: Part, relationshipType: string): boolean;
28
+ /**
29
+ * The slides, in `p:sldIdLst` order (docx4j `getSlideParts()`), once the part is unmarshalled;
30
+ * before that, in relationship order, which is the order they were added in.
31
+ */
12
32
  get slideParts(): SlidePart[];
33
+ /** The slides in `p:sldIdLst` order, unmarshalling the part first (docx4j `getSlideParts()`). */
34
+ getSlideParts(): Promise<SlidePart[]>;
35
+ /** The slide masters, in `p:sldMasterIdLst` order once the part is unmarshalled. */
36
+ get slideMasterParts(): SlideMasterPart[];
37
+ /** The slide at an index of `p:sldIdLst` (docx4j `getSlide(int)`). */
38
+ getSlide(index: number): SlidePart;
39
+ /** docx4j `getSlideCount()`. */
40
+ get slideCount(): number;
41
+ /**
42
+ * Adds a slide part as a target and appends a `p:sldId` for it (docx4j
43
+ * `addSlideIdListEntry(SlidePart)`); the part must be unmarshalled.
44
+ */
45
+ addSlideIdListEntry(slidePart: SlidePart, mode?: AddPartBehaviour): pml.Presentation.SldIdLst.SldId;
46
+ /**
47
+ * docx4j `addSlide(SlidePart)` / `addSlide(int, SlidePart)`: appends the slide, or inserts it
48
+ * at `index`, renaming the part if the name is taken (PowerPoint cannot open a package in which
49
+ * two relationships target the same slide, so a slide is never added twice).
50
+ *
51
+ * `layoutPart`, when given, becomes the slide's layout relationship, as a slide needs one.
52
+ */
53
+ addSlide(slidePart: SlidePart, index?: number, layoutPart?: SlideLayoutPart): pml.Presentation.SldIdLst.SldId;
54
+ /** docx4j `addSlideMasterIdListEntry(SlideMasterPart)`. */
55
+ addSlideMasterIdListEntry(masterPart: SlideMasterPart): pml.Presentation.SldMasterIdLst.SldMasterId;
56
+ /** docx4j `removeSlide(int)`: the `p:sldId`, the relationship and the part. */
57
+ removeSlide(index: number): SlidePart;
58
+ private sldIdLst;
13
59
  }
14
60
  export declare class SlidePart extends XmlPart<pml.Sld> {
15
- constructor(partName: PartName | string);
61
+ slideLayoutPart: SlideLayoutPart | undefined;
62
+ notesSlidePart: NotesSlidePart | undefined;
63
+ commentsPart: PresentationCommentsPart | undefined;
64
+ constructor(partName?: PartName | string);
65
+ setPartShortcut(part: Part, relationshipType: string): boolean;
16
66
  }
17
67
  export declare class SlideLayoutPart extends XmlPart<pml.SldLayout> {
18
- constructor(partName: PartName | string);
68
+ /** docx4j `SlideLayoutPart.getSlideMasterPart()`. */
69
+ slideMasterPart: SlideMasterPart | undefined;
70
+ constructor(partName?: PartName | string);
71
+ setPartShortcut(part: Part, relationshipType: string): boolean;
19
72
  }
20
73
  export declare class SlideMasterPart extends XmlPart<pml.SldMaster> {
21
- constructor(partName: PartName | string);
74
+ themePart: ThemePart | undefined;
75
+ constructor(partName?: PartName | string);
76
+ setPartShortcut(part: Part, relationshipType: string): boolean;
77
+ /**
78
+ * Adds a layout part as a target and appends a `p:sldLayoutId` for it (docx4j
79
+ * `addSlideLayoutIdListEntry`); the master must be unmarshalled.
80
+ */
81
+ addSlideLayoutIdListEntry(slideLayoutPart: SlideLayoutPart): pml.SlideLayoutIdList.SldLayoutId;
82
+ /** This master's layouts, in `p:sldLayoutIdLst` order once the master is unmarshalled. */
83
+ get slideLayoutParts(): SlideLayoutPart[];
22
84
  }
23
85
  export declare class NotesSlidePart extends XmlPart<pml.Notes> {
24
86
  constructor(partName: PartName | string);
@@ -51,3 +113,4 @@ export declare class TagsPart extends XmlPart<pml.TagLst> {
51
113
  export declare class FontDataPart extends BinaryPart {
52
114
  constructor(partName: PartName | string);
53
115
  }
116
+ export { type SlideTextOptions, type Rect, placeholderGeometry, placeholderShape, slidePlaceholders, layoutPlaceholders, addShapes, bodyLines, placeholdersOf, slidePlaceholdersFor, } from './placeholders.mjs';