@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.
- package/README.md +410 -10
- package/dist/model/content/Body.d.mts +109 -4
- package/dist/model/content/Body.mjs +300 -29
- package/dist/model/content/Comment.d.mts +78 -0
- package/dist/model/content/Comment.mjs +429 -0
- package/dist/model/content/ContentControl.d.mts +173 -0
- package/dist/model/content/ContentControl.mjs +638 -0
- package/dist/model/content/Font.d.mts +48 -8
- package/dist/model/content/Font.mjs +55 -13
- package/dist/model/content/InlinePicture.d.mts +103 -0
- package/dist/model/content/InlinePicture.mjs +361 -0
- package/dist/model/content/List.d.mts +253 -0
- package/dist/model/content/List.mjs +778 -0
- package/dist/model/content/Paragraph.d.mts +213 -16
- package/dist/model/content/Paragraph.mjs +611 -57
- package/dist/model/content/Range.d.mts +48 -4
- package/dist/model/content/Range.mjs +161 -4
- package/dist/model/content/Table.d.mts +130 -0
- package/dist/model/content/Table.mjs +429 -0
- package/dist/model/content/TrackedChange.d.mts +96 -0
- package/dist/model/content/TrackedChange.mjs +352 -0
- package/dist/model/content/comments.d.mts +122 -0
- package/dist/model/content/comments.mjs +248 -0
- package/dist/model/content/index.d.mts +13 -3
- package/dist/model/content/index.mjs +15 -3
- package/dist/model/content/ooxml.d.mts +17 -0
- package/dist/model/content/ooxml.mjs +214 -0
- package/dist/model/content/styles.d.mts +21 -0
- package/dist/model/content/styles.mjs +86 -0
- package/dist/model/content/tracking.d.mts +104 -0
- package/dist/model/content/tracking.mjs +313 -0
- package/dist/model/content/tree.d.mts +56 -9
- package/dist/model/content/tree.mjs +104 -31
- package/dist/model/customxml/CustomXmlPart.d.mts +158 -0
- package/dist/model/customxml/CustomXmlPart.mjs +415 -0
- package/dist/model/customxml/CustomXmlPartCollection.d.mts +68 -0
- package/dist/model/customxml/CustomXmlPartCollection.mjs +183 -0
- package/dist/model/customxml/XmlMapping.d.mts +46 -0
- package/dist/model/customxml/XmlMapping.mjs +98 -0
- package/dist/model/customxml/bindings.d.mts +41 -0
- package/dist/model/customxml/bindings.mjs +230 -0
- package/dist/model/customxml/index.d.mts +7 -0
- package/dist/model/customxml/index.mjs +9 -0
- package/dist/model/customxml/insert.d.mts +20 -0
- package/dist/model/customxml/insert.mjs +22 -0
- package/dist/model/customxml/kinds.d.mts +103 -0
- package/dist/model/customxml/kinds.mjs +267 -0
- package/dist/model/customxml/xpath.d.mts +52 -0
- package/dist/model/customxml/xpath.mjs +205 -0
- package/dist/model/fonts/CJKToEnglish.d.mts +2 -0
- package/dist/model/fonts/CJKToEnglish.mjs +16 -0
- package/dist/model/fonts/FontFallback.d.mts +58 -0
- package/dist/model/fonts/FontFallback.mjs +219 -0
- package/dist/model/fonts/IdentityPlusMapper.d.mts +7 -0
- package/dist/model/fonts/IdentityPlusMapper.mjs +19 -0
- package/dist/model/fonts/LanguageTagToScriptMapping.d.mts +7 -0
- package/dist/model/fonts/LanguageTagToScriptMapping.mjs +67 -0
- package/dist/model/fonts/Mapper.d.mts +190 -0
- package/dist/model/fonts/Mapper.mjs +481 -0
- package/dist/model/fonts/PhysicalFont.d.mts +34 -0
- package/dist/model/fonts/PhysicalFont.mjs +62 -0
- package/dist/model/fonts/RunFontSelector.d.mts +194 -0
- package/dist/model/fonts/RunFontSelector.mjs +441 -0
- package/dist/model/fonts/ThemeFonts.d.mts +17 -0
- package/dist/model/fonts/ThemeFonts.mjs +76 -0
- package/dist/model/fonts/defaultTheme.d.mts +37 -0
- package/dist/model/fonts/defaultTheme.mjs +57 -0
- package/dist/model/fonts/families.generated.d.mts +11 -0
- package/dist/model/fonts/families.generated.mjs +17 -0
- package/dist/model/fonts/fontsInUse.d.mts +39 -0
- package/dist/model/fonts/fontsInUse.mjs +183 -0
- package/dist/model/fonts/index.d.mts +14 -0
- package/dist/model/fonts/index.mjs +29 -0
- package/dist/model/fonts/lookup.d.mts +5 -0
- package/dist/model/fonts/lookup.mjs +12 -0
- package/dist/model/fonts/registry.d.mts +31 -0
- package/dist/model/fonts/registry.mjs +103 -0
- package/dist/model/fonts/scripts.d.mts +2 -0
- package/dist/model/fonts/scripts.mjs +78 -0
- package/dist/model/fonts/substitutions.generated.d.mts +30 -0
- package/dist/model/fonts/substitutions.generated.mjs +12 -0
- package/dist/model/fonts/themes.generated.d.mts +6 -0
- package/dist/model/fonts/themes.generated.mjs +11 -0
- package/dist/model/index.d.mts +5 -0
- package/dist/model/index.mjs +13 -1
- package/dist/model/listnumbering/Emulator.d.mts +187 -0
- package/dist/model/listnumbering/Emulator.mjs +332 -0
- package/dist/model/listnumbering/definitions.d.mts +251 -0
- package/dist/model/listnumbering/definitions.mjs +571 -0
- package/dist/model/listnumbering/formats.d.mts +25 -0
- package/dist/model/listnumbering/formats.mjs +320 -0
- package/dist/model/listnumbering/index.d.mts +4 -0
- package/dist/model/listnumbering/index.mjs +15 -0
- package/dist/model/listnumbering/state.d.mts +97 -0
- package/dist/model/listnumbering/state.mjs +179 -0
- package/dist/model/properties/PropertyResolver.d.mts +216 -0
- package/dist/model/properties/PropertyResolver.mjs +524 -0
- package/dist/model/properties/catalogue.d.mts +179 -0
- package/dist/model/properties/catalogue.mjs +860 -0
- package/dist/model/properties/index.d.mts +4 -0
- package/dist/model/properties/index.mjs +9 -0
- package/dist/model/properties/log.d.mts +7 -0
- package/dist/model/properties/log.mjs +25 -0
- package/dist/model/properties/styleUtil.d.mts +112 -0
- package/dist/model/properties/styleUtil.mjs +359 -0
- package/dist/node/index.d.mts +1 -0
- package/dist/node/index.mjs +12 -0
- package/dist/office-js/document.d.mts +111 -0
- package/dist/office-js/document.mjs +267 -0
- package/dist/office-js/enums.d.mts +187 -0
- package/dist/office-js/enums.mjs +176 -0
- package/dist/office-js/errors.d.mts +29 -0
- package/dist/office-js/errors.mjs +39 -0
- package/dist/office-js/extras.d.mts +5 -0
- package/dist/office-js/extras.mjs +29 -0
- package/dist/office-js/fragment.d.mts +10 -0
- package/dist/office-js/fragment.mjs +23 -0
- package/dist/office-js/index.d.mts +183 -0
- package/dist/office-js/index.mjs +54 -0
- package/dist/office-js/proxy.d.mts +72 -0
- package/dist/office-js/proxy.mjs +279 -0
- package/dist/office-js/run.d.mts +32 -0
- package/dist/office-js/run.mjs +66 -0
- package/dist/office-js/supported.d.mts +7 -0
- package/dist/office-js/supported.generated.d.mts +1 -0
- package/dist/office-js/supported.generated.mjs +235 -0
- package/dist/office-js/supported.mjs +53 -0
- package/dist/office-js/toApiScript.d.mts +25 -0
- package/dist/office-js/toApiScript.mjs +394 -0
- package/dist/opc/ContentTypes.d.mts +11 -0
- package/dist/opc/ContentTypes.mjs +14 -0
- package/dist/opc/DirectoryPartStore.d.mts +47 -0
- package/dist/opc/DirectoryPartStore.mjs +123 -0
- package/dist/opc/exceptions.d.mts +30 -0
- package/dist/opc/exceptions.mjs +38 -0
- package/dist/opc/index.d.mts +1 -1
- package/dist/opc/index.mjs +1 -1
- package/dist/packages/OpcPackage.d.mts +19 -1
- package/dist/packages/OpcPackage.mjs +29 -0
- package/dist/packages/PresentationMLPackage.d.mts +71 -1
- package/dist/packages/PresentationMLPackage.mjs +179 -0
- package/dist/packages/SpreadsheetMLPackage.d.mts +30 -1
- package/dist/packages/SpreadsheetMLPackage.mjs +78 -0
- package/dist/packages/WordprocessingMLPackage.d.mts +124 -2
- package/dist/packages/WordprocessingMLPackage.mjs +309 -2
- package/dist/packages/index.d.mts +1 -1
- package/dist/packages/index.mjs +1 -1
- package/dist/parts/DefaultXmlPart.d.mts +18 -0
- package/dist/parts/DefaultXmlPart.mjs +34 -5
- package/dist/parts/Namespaces.d.mts +18 -0
- package/dist/parts/Namespaces.mjs +20 -0
- package/dist/parts/Part.d.mts +6 -0
- package/dist/parts/Part.mjs +13 -0
- package/dist/parts/PartRegistry.mjs +13 -1
- package/dist/parts/XmlPart.d.mts +33 -0
- package/dist/parts/XmlPart.mjs +105 -2
- package/dist/parts/pml/defaults.d.mts +6 -0
- package/dist/parts/pml/defaults.mjs +53 -0
- package/dist/parts/pml/index.d.mts +66 -3
- package/dist/parts/pml/index.mjs +206 -7
- package/dist/parts/pml/placeholders.d.mts +71 -0
- package/dist/parts/pml/placeholders.mjs +141 -0
- package/dist/parts/sml/index.d.mts +80 -1
- package/dist/parts/sml/index.mjs +154 -1
- package/dist/parts/wml/comments.d.mts +1 -0
- package/dist/parts/wml/comments.mjs +179 -0
- package/dist/parts/wml/defaultNumbering.d.mts +1 -0
- package/dist/parts/wml/defaultNumbering.mjs +216 -0
- package/dist/parts/wml/index.d.mts +121 -0
- package/dist/parts/wml/index.mjs +291 -0
- package/dist/xml/dom.mjs +1 -2
- package/package.json +25 -4
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { OpcPackage, type PackageSource } from './OpcPackage.mjs';
|
|
2
2
|
import type { LoadOptions } from '../opc/Load.mjs';
|
|
3
3
|
import type { Part } from '../parts/Part.mjs';
|
|
4
|
-
import { MainDocumentPart } from '../parts/wml/index.mjs';
|
|
4
|
+
import { MainDocumentPart, type NumberingDefinitionsPart } from '../parts/wml/index.mjs';
|
|
5
|
+
import { type FontSettings, type DefaultThemeValue } from '../model/fonts/defaultTheme.mjs';
|
|
5
6
|
import type { Body, Address, Outline, OutlineParagraph, OutlineTable } from '../model/content/Body.mjs';
|
|
6
7
|
import type { Paragraph } from '../model/content/Paragraph.mjs';
|
|
8
|
+
import type { Author } from '../model/content/comments.mjs';
|
|
9
|
+
import { CustomXmlPartCollection } from '../model/customxml/CustomXmlPartCollection.mjs';
|
|
10
|
+
import { type XPathEngine } from '../model/customxml/xpath.mjs';
|
|
11
|
+
import { ChangeTracker, type ChangeTrackingMode, type TrackingHost } from '../model/content/tracking.mjs';
|
|
12
|
+
import { PropertyResolver } from '../model/properties/PropertyResolver.mjs';
|
|
13
|
+
import type { Emulator } from '../model/listnumbering/Emulator.mjs';
|
|
14
|
+
import type { TrackedChange } from '../model/content/TrackedChange.mjs';
|
|
15
|
+
import type { PartSink } from '../opc/PartStore.mjs';
|
|
16
|
+
import '../parts/wml/comments.mjs';
|
|
7
17
|
/** The outline of a document: the body's paragraphs and tables, then each header's and footer's (loaded ones only). */
|
|
8
18
|
export interface DocumentOutline extends Outline {
|
|
9
19
|
headers: {
|
|
@@ -24,10 +34,41 @@ export type PageSizePaper = 'LETTER' | 'LEGAL' | 'A3' | 'A4' | 'A5' | 'B4JIS';
|
|
|
24
34
|
export interface CreatePackageOptions {
|
|
25
35
|
pageSize?: PageSizePaper;
|
|
26
36
|
landscape?: boolean;
|
|
37
|
+
/** Which Office theme the new package's theme part carries, and which its font references
|
|
38
|
+
* resolve against: `'2023'` (the default, Word 365's Aptos Display / Aptos), `'2013'`
|
|
39
|
+
* (Calibri Light / Calibri) or `'2007'` (Cambria / Calibri). Sets `pkg.fonts.defaultTheme`. */
|
|
40
|
+
defaultTheme?: DefaultThemeValue;
|
|
41
|
+
/** The `w:compat/w:compatSetting` value for `compatibilityMode`: `'15'` (the default) is what
|
|
42
|
+
* Word 2013 and later write, and is what keeps Word 365 out of compatibility mode. `''`
|
|
43
|
+
* leaves the setting out, which is docx4j's own `createPackage` behaviour. */
|
|
44
|
+
compatibilityMode?: string;
|
|
27
45
|
}
|
|
28
46
|
/** A docx (docx4j WordprocessingMLPackage). */
|
|
29
|
-
export declare class WordprocessingMLPackage extends OpcPackage {
|
|
47
|
+
export declare class WordprocessingMLPackage extends OpcPackage implements TrackingHost {
|
|
30
48
|
mainDocumentPart: MainDocumentPart | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Who this package's comments (CR-002 phase G) and its tracked changes (phase F) are by.
|
|
51
|
+
* There is no signed-in user here, so the package carries the identity; the initials default to
|
|
52
|
+
* the first letter of each word of the name and the email, when given, is written to `w:people`.
|
|
53
|
+
*/
|
|
54
|
+
author: Author;
|
|
55
|
+
/** A fixed date for new revisions; undefined means the moment each one is written (CR-002 phase F). */
|
|
56
|
+
trackedChangeDate: Date | undefined;
|
|
57
|
+
private trackingMode;
|
|
58
|
+
private tracker;
|
|
59
|
+
/** Set when `changeTrackingMode` was written but the settings part was not unmarshalled yet. */
|
|
60
|
+
private trackingPending;
|
|
61
|
+
/**
|
|
62
|
+
* The package's font settings (CR-001 Phase B step 4), docx4j's `docx4j.fonts.*` properties
|
|
63
|
+
* scoped to one package: `defaultTheme` says which Office theme a font reference resolves
|
|
64
|
+
* against where the package has **no theme part**, and which theme part `createPackage()`
|
|
65
|
+
* gives a new one. `'2023'` (Word 365's Aptos Display / Aptos) by default; `'2013'` is
|
|
66
|
+
* Calibri Light / Calibri and `'2007'` Cambria / Calibri.
|
|
67
|
+
*
|
|
68
|
+
* Set it before the first `getRunFontSelector()` or `createPackage()`; afterwards call
|
|
69
|
+
* `mainDocumentPart.refreshFonts()`.
|
|
70
|
+
*/
|
|
71
|
+
readonly fonts: FontSettings;
|
|
31
72
|
static load(source: PackageSource, options?: LoadOptions): Promise<WordprocessingMLPackage>;
|
|
32
73
|
/**
|
|
33
74
|
* A new document with a main document part (one section, the page size and 2.54 cm margins),
|
|
@@ -40,10 +81,91 @@ export declare class WordprocessingMLPackage extends OpcPackage {
|
|
|
40
81
|
/** Office JS `document.body`: the main document part's body; the part must be unmarshalled (`getBody()` does that). */
|
|
41
82
|
get body(): Body;
|
|
42
83
|
getBody(): Promise<Body>;
|
|
84
|
+
private resolver;
|
|
85
|
+
private resolverPending;
|
|
86
|
+
/**
|
|
87
|
+
* docx4j `MainDocumentPart.getPropertyResolver()`: the resolver of effective paragraph, run,
|
|
88
|
+
* paragraph-mark and table properties, built once and kept for the life of the package.
|
|
89
|
+
*
|
|
90
|
+
* Asynchronous because it unmarshals the styles and numbering parts; `propertyResolver` is
|
|
91
|
+
* the synchronous accessor afterwards. A style *added* to the styles part later is found; a
|
|
92
|
+
* style *modified* or *removed* needs `refresh()`.
|
|
93
|
+
*/
|
|
94
|
+
getPropertyResolver(): Promise<PropertyResolver>;
|
|
95
|
+
/**
|
|
96
|
+
* The resolver, which must already have been created: building it unmarshals parts, which
|
|
97
|
+
* cannot be done synchronously. Throws `PropertyResolverNotCreatedException` naming
|
|
98
|
+
* `getPropertyResolver()` otherwise.
|
|
99
|
+
*/
|
|
100
|
+
get propertyResolver(): PropertyResolver;
|
|
101
|
+
/** The resolver if it has been created, without throwing (what a read with a fallback wants). */
|
|
102
|
+
get propertyResolverOrUndefined(): PropertyResolver | undefined;
|
|
103
|
+
/** Tells the resolver, when there is one, that the styles part has changed. */
|
|
104
|
+
refreshPropertyResolver(): void;
|
|
105
|
+
/**
|
|
106
|
+
* Builds the resolver and the numbering definitions again, over the parts the package holds
|
|
107
|
+
* **now**: what docx4j's `getPropertyResolver(true)` does, and what a styles or numbering part
|
|
108
|
+
* *added* after the first resolver was built needs (`refreshPropertyResolver()` re-reads the
|
|
109
|
+
* parts the resolver already knows about, but cannot find new ones).
|
|
110
|
+
*/
|
|
111
|
+
refresh(): Promise<PropertyResolver>;
|
|
112
|
+
/** `/word/numbering.xml`, or undefined. docx4j `MainDocumentPart.getNumberingDefinitionsPart()`. */
|
|
113
|
+
get numberingDefinitionsPart(): NumberingDefinitionsPart | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* The numbering emulator over this package's numbering part, with its definitions read
|
|
116
|
+
* (docx4j `NumberingDefinitionsPart.getEmulator()`), or undefined where there is no numbering
|
|
117
|
+
* part. Asynchronous because reading the part is; `numberingDefinitionsPart.getEmulator()` is
|
|
118
|
+
* the synchronous accessor afterwards.
|
|
119
|
+
*/
|
|
120
|
+
getNumberingEmulator(): Promise<Emulator | undefined>;
|
|
121
|
+
/**
|
|
122
|
+
* Office JS `document.changeTrackingMode`, backed by `w:trackRevisions` in the settings part.
|
|
123
|
+
* While it is not `Off`, every mutation of the content API writes Word's revision markup with
|
|
124
|
+
* `author` and `trackedChangeDate` instead of editing in place.
|
|
125
|
+
*
|
|
126
|
+
* Reading is synchronous, so it reports `Off` for a loaded package whose settings part has not
|
|
127
|
+
* been unmarshalled; `getChangeTrackingMode()` unmarshals it and is the one to await. Writing
|
|
128
|
+
* is synchronous too and is written through to the settings part on save when the part is not
|
|
129
|
+
* unmarshalled yet (`setChangeTrackingMode()` does it there and then).
|
|
130
|
+
*/
|
|
131
|
+
get changeTrackingMode(): ChangeTrackingMode;
|
|
132
|
+
set changeTrackingMode(mode: ChangeTrackingMode);
|
|
133
|
+
/** The mode as the settings part has it, unmarshalling the part (docx4j's async counterpart of the getter). */
|
|
134
|
+
getChangeTrackingMode(): Promise<ChangeTrackingMode>;
|
|
135
|
+
/** Writes `w:trackRevisions`, unmarshalling the settings part, or creating it when there is none. */
|
|
136
|
+
setChangeTrackingMode(mode: ChangeTrackingMode): Promise<void>;
|
|
137
|
+
/** The settings part, created (with its relationship and content type) when the document has none. */
|
|
138
|
+
private settingsPart;
|
|
139
|
+
/**
|
|
140
|
+
* Office JS `document.getTrackedChanges()`: every tracked change in the main document part,
|
|
141
|
+
* in document order (headers and footers have their own `Body`). The part must be
|
|
142
|
+
* unmarshalled, as `body` needs it to be.
|
|
143
|
+
*/
|
|
144
|
+
getTrackedChanges(): TrackedChange[];
|
|
145
|
+
/** The tracker every content-API mutation asks for; undefined while the mode is `Off`. */
|
|
146
|
+
get changeTracker(): ChangeTracker | undefined;
|
|
147
|
+
/** TrackingHost: the trees a new revision id must be above, which is every part already unmarshalled. */
|
|
148
|
+
markupRoots(): object[];
|
|
149
|
+
/** A clone carries the identity, the tracking date, the theme setting and the XPath engine. */
|
|
150
|
+
protected copyPackageSettingsTo(target: OpcPackage): void;
|
|
151
|
+
saveTo<R>(sink: PartSink<R>): Promise<R>;
|
|
43
152
|
/** The paragraph at an address anywhere in the document: 'body/3', 'header:rId5/0', a paraId, or a text match. */
|
|
44
153
|
paragraphAt(address: Address): Promise<Paragraph | undefined>;
|
|
45
154
|
/** Every paragraph and table with its address, style and text (CR-002 section 3.3). Unmarshals the main part, headers and footers. */
|
|
46
155
|
outline(): Promise<DocumentOutline>;
|
|
47
156
|
private bodies;
|
|
157
|
+
/**
|
|
158
|
+
* The XPath engine the custom XML views use (CR-002 section 3.6): `document.evaluate` in a
|
|
159
|
+
* browser or an add-in, the optional `xpath` package in Node. Settable, so a consumer with
|
|
160
|
+
* another DOM (or one who wants no dynamic import) plugs in its own. Warmed once by
|
|
161
|
+
* `customXmlParts.load()`; every node call is synchronous afterwards.
|
|
162
|
+
*/
|
|
163
|
+
xpathEngine: XPathEngine;
|
|
164
|
+
/**
|
|
165
|
+
* Office JS `document.customXmlParts`: the custom XML data storage parts as views, with
|
|
166
|
+
* `add`, and docx4j's `applyBindings()` / `updateFromContentControls()` (CR-002 section 3.5).
|
|
167
|
+
*/
|
|
168
|
+
get customXmlParts(): CustomXmlPartCollection;
|
|
169
|
+
private customXmlPartCollection;
|
|
48
170
|
protected get progId(): string;
|
|
49
171
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createCTCompat, createCTCompatSetting } from '@docx4j/generated-objects-ts/factory/org_docx4j_wml';
|
|
1
2
|
import { OpcPackage } from './OpcPackage.mjs';
|
|
2
3
|
import { registerPackageClass } from './registry.mjs';
|
|
3
4
|
import { ContentTypes } from '../opc/ContentTypes.mjs';
|
|
@@ -6,7 +7,18 @@ import { Namespaces } from '../parts/Namespaces.mjs';
|
|
|
6
7
|
import { MainDocumentPart, StyleDefinitionsPart, DocumentSettingsPart } from '../parts/wml/index.mjs';
|
|
7
8
|
import { DocPropsCorePart, DocPropsExtendedPart } from '../parts/docProps/index.mjs';
|
|
8
9
|
import { DEFAULT_STYLES_XML } from '../parts/wml/defaultStyles.mjs';
|
|
10
|
+
import { ThemePart } from '../parts/dml/index.mjs';
|
|
11
|
+
import { newFontSettings, themeOfSettings, } from '../model/fonts/defaultTheme.mjs';
|
|
9
12
|
import { HeaderPart, FooterPart } from '../parts/wml/index.mjs';
|
|
13
|
+
import { CustomXmlPartCollection } from '../model/customxml/CustomXmlPartCollection.mjs';
|
|
14
|
+
import { DefaultXPathEngine } from '../model/customxml/xpath.mjs';
|
|
15
|
+
import { ChangeTracker } from '../model/content/tracking.mjs';
|
|
16
|
+
import { PropertyResolver } from '../model/properties/PropertyResolver.mjs';
|
|
17
|
+
import { PropertyResolverNotCreatedException } from '../opc/exceptions.mjs';
|
|
18
|
+
import { XmlPart } from '../parts/XmlPart.mjs';
|
|
19
|
+
// Registers the comment parts with the content API (CR-002 phase G); no cycle: the model half
|
|
20
|
+
// never imports a part, as packages/registry.mts does for the package classes.
|
|
21
|
+
import '../parts/wml/comments.mjs';
|
|
10
22
|
const MAIN_CONTENT_TYPES = [
|
|
11
23
|
ContentTypes.WORDPROCESSINGML_DOCUMENT,
|
|
12
24
|
ContentTypes.WORDPROCESSINGML_DOCUMENT_MACROENABLED,
|
|
@@ -22,8 +34,59 @@ const PAGE_SIZES = {
|
|
|
22
34
|
A5: [8391, 11907, 11],
|
|
23
35
|
B4JIS: [14572, 20639, 12],
|
|
24
36
|
};
|
|
37
|
+
/** The URI of Word's own compatibility settings (docx4j `DocumentSettingsPart.setWordCompatSetting`). */
|
|
38
|
+
const WORD_COMPAT_URI = 'http://schemas.microsoft.com/office/word';
|
|
39
|
+
/**
|
|
40
|
+
* The `w:compat/w:compatSetting`s a created document carries, in the order Word writes them.
|
|
41
|
+
* `compatibilityMode` 15 is what Word 2013 and later write and is what keeps Word 365 out of
|
|
42
|
+
* compatibility mode; `overrideTableStyleFontSizeAndJustification` is docx4j's own
|
|
43
|
+
* (`DocumentSettingsPart.setOverrideTableStyleFontSizeAndJustification`). Word 365 writes four
|
|
44
|
+
* more - `enableOpenTypeFeatures`, `doNotFlipMirrorIndents`, `differentiateMultirowTableHeaders`
|
|
45
|
+
* and `useWord2013TrackBottomHyphenation`, all 1 - plus a locale-dependent `w:themeFontLang`,
|
|
46
|
+
* which are deliberately left out for now (CR-001 section 17); adding them is one edit here.
|
|
47
|
+
*/
|
|
48
|
+
const DEFAULT_COMPAT_SETTINGS = [
|
|
49
|
+
// The six settings Word 365 writes for a new document, in its order; docx4j's
|
|
50
|
+
// DocumentSettingsPart.setCompatSettingsAsWord365 (9de10aac9) writes the same six.
|
|
51
|
+
{ name: 'compatibilityMode', val: '15' },
|
|
52
|
+
{ name: 'overrideTableStyleFontSizeAndJustification', val: '1' },
|
|
53
|
+
{ name: 'enableOpenTypeFeatures', val: '1' },
|
|
54
|
+
{ name: 'doNotFlipMirrorIndents', val: '1' },
|
|
55
|
+
{ name: 'differentiateMultirowTableHeaders', val: '1' },
|
|
56
|
+
{ name: 'useWord2013TrackBottomHyphenation', val: '1' },
|
|
57
|
+
];
|
|
25
58
|
/** A docx (docx4j WordprocessingMLPackage). */
|
|
26
59
|
export class WordprocessingMLPackage extends OpcPackage {
|
|
60
|
+
constructor() {
|
|
61
|
+
super(...arguments);
|
|
62
|
+
/**
|
|
63
|
+
* Who this package's comments (CR-002 phase G) and its tracked changes (phase F) are by.
|
|
64
|
+
* There is no signed-in user here, so the package carries the identity; the initials default to
|
|
65
|
+
* the first letter of each word of the name and the email, when given, is written to `w:people`.
|
|
66
|
+
*/
|
|
67
|
+
this.author = { name: 'docx4j' };
|
|
68
|
+
/** Set when `changeTrackingMode` was written but the settings part was not unmarshalled yet. */
|
|
69
|
+
this.trackingPending = false;
|
|
70
|
+
/**
|
|
71
|
+
* The package's font settings (CR-001 Phase B step 4), docx4j's `docx4j.fonts.*` properties
|
|
72
|
+
* scoped to one package: `defaultTheme` says which Office theme a font reference resolves
|
|
73
|
+
* against where the package has **no theme part**, and which theme part `createPackage()`
|
|
74
|
+
* gives a new one. `'2023'` (Word 365's Aptos Display / Aptos) by default; `'2013'` is
|
|
75
|
+
* Calibri Light / Calibri and `'2007'` Cambria / Calibri.
|
|
76
|
+
*
|
|
77
|
+
* Set it before the first `getRunFontSelector()` or `createPackage()`; afterwards call
|
|
78
|
+
* `mainDocumentPart.refreshFonts()`.
|
|
79
|
+
*/
|
|
80
|
+
this.fonts = newFontSettings();
|
|
81
|
+
// --- custom XML (CR-002 phase E) ---
|
|
82
|
+
/**
|
|
83
|
+
* The XPath engine the custom XML views use (CR-002 section 3.6): `document.evaluate` in a
|
|
84
|
+
* browser or an add-in, the optional `xpath` package in Node. Settable, so a consumer with
|
|
85
|
+
* another DOM (or one who wants no dynamic import) plugs in its own. Warmed once by
|
|
86
|
+
* `customXmlParts.load()`; every node call is synchronous afterwards.
|
|
87
|
+
*/
|
|
88
|
+
this.xpathEngine = new DefaultXPathEngine();
|
|
89
|
+
}
|
|
27
90
|
static async load(source, options) {
|
|
28
91
|
var _a, _b;
|
|
29
92
|
const pkg = await OpcPackage.load(source, options);
|
|
@@ -37,8 +100,10 @@ export class WordprocessingMLPackage extends OpcPackage {
|
|
|
37
100
|
* docx4j's default styles, settings, and core and extended properties (docx4j createPackage).
|
|
38
101
|
*/
|
|
39
102
|
static async createPackage(options = {}) {
|
|
40
|
-
var _a;
|
|
103
|
+
var _a, _b;
|
|
41
104
|
const pkg = new WordprocessingMLPackage();
|
|
105
|
+
if (options.defaultTheme !== undefined)
|
|
106
|
+
pkg.fonts.defaultTheme = options.defaultTheme;
|
|
42
107
|
const [pw, ph, code] = PAGE_SIZES[(_a = options.pageSize) !== null && _a !== void 0 ? _a : 'A4'];
|
|
43
108
|
const landscape = options.landscape === true;
|
|
44
109
|
const pgSz = { w: landscape ? ph : pw, h: landscape ? pw : ph, code };
|
|
@@ -52,8 +117,20 @@ export class WordprocessingMLPackage extends OpcPackage {
|
|
|
52
117
|
const styles = new StyleDefinitionsPart();
|
|
53
118
|
styles.setXml(DEFAULT_STYLES_XML);
|
|
54
119
|
main.addTargetPart(styles);
|
|
120
|
+
/* The settings part carries `w:compat/w:compatSetting compatibilityMode` 15, which Word 2013
|
|
121
|
+
* and later write into every document they create: without it Word 365 opens the document in
|
|
122
|
+
* compatibility mode ("Compatibility Mode" in the title bar, the pre-2013 layout rules).
|
|
123
|
+
* docx4j writes no mode at all (its `getCompatibilityMode()` answers 12 when the setting is
|
|
124
|
+
* absent, and says so), so this is a deliberate departure from it (CR-001 section 17);
|
|
125
|
+
* `{ compatibilityMode: '' }` leaves the setting out and gets docx4j's behaviour back. */
|
|
55
126
|
const settings = new DocumentSettingsPart();
|
|
56
|
-
|
|
127
|
+
const compatibilityMode = (_b = options.compatibilityMode) !== null && _b !== void 0 ? _b : '15';
|
|
128
|
+
const compatSetting = DEFAULT_COMPAT_SETTINGS
|
|
129
|
+
.filter((s) => s.name !== 'compatibilityMode' || compatibilityMode !== '')
|
|
130
|
+
.map((s) => createCTCompatSetting({
|
|
131
|
+
name: s.name, uri: WORD_COMPAT_URI, val: s.name === 'compatibilityMode' ? compatibilityMode : s.val,
|
|
132
|
+
}));
|
|
133
|
+
settings.setContents({ compat: createCTCompat({ compatSetting }) });
|
|
57
134
|
main.addTargetPart(settings);
|
|
58
135
|
const core = new DocPropsCorePart();
|
|
59
136
|
core.setContents({});
|
|
@@ -61,6 +138,18 @@ export class WordprocessingMLPackage extends OpcPackage {
|
|
|
61
138
|
const app = new DocPropsExtendedPart();
|
|
62
139
|
app.setContents({});
|
|
63
140
|
pkg.addTargetPart(app);
|
|
141
|
+
/* The theme part (/word/theme/theme1.xml), as Word puts one in every document it creates
|
|
142
|
+
* and as docx4j's createPackage has done since 17.1.1 (CR-001 section 14.6): without it,
|
|
143
|
+
* the default styles' docDefaults - which reference the theme fonts
|
|
144
|
+
* (w:rFonts w:asciiTheme="minorHAnsi" ...) - had nothing to resolve against, and every
|
|
145
|
+
* consumer had to guess the Office theme's faces for itself. Which theme it is, is
|
|
146
|
+
* `pkg.fonts.defaultTheme`; the same setting answers a themeless package's references. */
|
|
147
|
+
const theme = new ThemePart();
|
|
148
|
+
theme.setXml(themeOfSettings(pkg.fonts).xml);
|
|
149
|
+
main.addTargetPart(theme);
|
|
150
|
+
// so that `pkg.body`'s effective reads work without a further await: the default styles are
|
|
151
|
+
// XML bytes, so this is the one place the resolver has to be built before the caller asks
|
|
152
|
+
await pkg.getPropertyResolver();
|
|
64
153
|
return pkg;
|
|
65
154
|
}
|
|
66
155
|
setPartShortcut(part, relationshipType) {
|
|
@@ -83,6 +172,179 @@ export class WordprocessingMLPackage extends OpcPackage {
|
|
|
83
172
|
async getBody() {
|
|
84
173
|
return this.getMainDocumentPart().getBody();
|
|
85
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* docx4j `MainDocumentPart.getPropertyResolver()`: the resolver of effective paragraph, run,
|
|
177
|
+
* paragraph-mark and table properties, built once and kept for the life of the package.
|
|
178
|
+
*
|
|
179
|
+
* Asynchronous because it unmarshals the styles and numbering parts; `propertyResolver` is
|
|
180
|
+
* the synchronous accessor afterwards. A style *added* to the styles part later is found; a
|
|
181
|
+
* style *modified* or *removed* needs `refresh()`.
|
|
182
|
+
*/
|
|
183
|
+
async getPropertyResolver() {
|
|
184
|
+
var _a;
|
|
185
|
+
if (this.resolver)
|
|
186
|
+
return this.resolver;
|
|
187
|
+
(_a = this.resolverPending) !== null && _a !== void 0 ? _a : (this.resolverPending = PropertyResolver.create(this).then((resolver) => {
|
|
188
|
+
this.resolver = resolver;
|
|
189
|
+
this.resolverPending = undefined;
|
|
190
|
+
return resolver;
|
|
191
|
+
}));
|
|
192
|
+
return this.resolverPending;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The resolver, which must already have been created: building it unmarshals parts, which
|
|
196
|
+
* cannot be done synchronously. Throws `PropertyResolverNotCreatedException` naming
|
|
197
|
+
* `getPropertyResolver()` otherwise.
|
|
198
|
+
*/
|
|
199
|
+
get propertyResolver() {
|
|
200
|
+
if (!this.resolver)
|
|
201
|
+
throw new PropertyResolverNotCreatedException();
|
|
202
|
+
return this.resolver;
|
|
203
|
+
}
|
|
204
|
+
/** The resolver if it has been created, without throwing (what a read with a fallback wants). */
|
|
205
|
+
get propertyResolverOrUndefined() {
|
|
206
|
+
return this.resolver;
|
|
207
|
+
}
|
|
208
|
+
/** Tells the resolver, when there is one, that the styles part has changed. */
|
|
209
|
+
refreshPropertyResolver() {
|
|
210
|
+
var _a, _b, _c;
|
|
211
|
+
(_a = this.resolver) === null || _a === void 0 ? void 0 : _a.refresh();
|
|
212
|
+
(_c = (_b = this.mainDocumentPart) === null || _b === void 0 ? void 0 : _b.numberingDefinitionsPart) === null || _c === void 0 ? void 0 : _c.refreshDefinitions();
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Builds the resolver and the numbering definitions again, over the parts the package holds
|
|
216
|
+
* **now**: what docx4j's `getPropertyResolver(true)` does, and what a styles or numbering part
|
|
217
|
+
* *added* after the first resolver was built needs (`refreshPropertyResolver()` re-reads the
|
|
218
|
+
* parts the resolver already knows about, but cannot find new ones).
|
|
219
|
+
*/
|
|
220
|
+
async refresh() {
|
|
221
|
+
var _a, _b;
|
|
222
|
+
this.resolver = undefined;
|
|
223
|
+
this.resolverPending = undefined;
|
|
224
|
+
(_b = (_a = this.mainDocumentPart) === null || _a === void 0 ? void 0 : _a.numberingDefinitionsPart) === null || _b === void 0 ? void 0 : _b.refreshDefinitions();
|
|
225
|
+
return this.getPropertyResolver();
|
|
226
|
+
}
|
|
227
|
+
// --- list numbering (CR-001 Phase B step 3) --------------------------------------------
|
|
228
|
+
/** `/word/numbering.xml`, or undefined. docx4j `MainDocumentPart.getNumberingDefinitionsPart()`. */
|
|
229
|
+
get numberingDefinitionsPart() {
|
|
230
|
+
var _a;
|
|
231
|
+
return (_a = this.mainDocumentPart) === null || _a === void 0 ? void 0 : _a.numberingDefinitionsPart;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* The numbering emulator over this package's numbering part, with its definitions read
|
|
235
|
+
* (docx4j `NumberingDefinitionsPart.getEmulator()`), or undefined where there is no numbering
|
|
236
|
+
* part. Asynchronous because reading the part is; `numberingDefinitionsPart.getEmulator()` is
|
|
237
|
+
* the synchronous accessor afterwards.
|
|
238
|
+
*/
|
|
239
|
+
async getNumberingEmulator() {
|
|
240
|
+
const part = this.numberingDefinitionsPart;
|
|
241
|
+
if (part === undefined)
|
|
242
|
+
return undefined;
|
|
243
|
+
await this.getPropertyResolver();
|
|
244
|
+
await part.getDefinitions();
|
|
245
|
+
return part.getEmulator();
|
|
246
|
+
}
|
|
247
|
+
// --- change tracking (CR-002 phase F, section 3.7) --------------------------------------
|
|
248
|
+
/**
|
|
249
|
+
* Office JS `document.changeTrackingMode`, backed by `w:trackRevisions` in the settings part.
|
|
250
|
+
* While it is not `Off`, every mutation of the content API writes Word's revision markup with
|
|
251
|
+
* `author` and `trackedChangeDate` instead of editing in place.
|
|
252
|
+
*
|
|
253
|
+
* Reading is synchronous, so it reports `Off` for a loaded package whose settings part has not
|
|
254
|
+
* been unmarshalled; `getChangeTrackingMode()` unmarshals it and is the one to await. Writing
|
|
255
|
+
* is synchronous too and is written through to the settings part on save when the part is not
|
|
256
|
+
* unmarshalled yet (`setChangeTrackingMode()` does it there and then).
|
|
257
|
+
*/
|
|
258
|
+
get changeTrackingMode() {
|
|
259
|
+
var _a;
|
|
260
|
+
if (this.trackingMode !== undefined)
|
|
261
|
+
return this.trackingMode;
|
|
262
|
+
const settings = (_a = this.mainDocumentPart) === null || _a === void 0 ? void 0 : _a.documentSettingsPart;
|
|
263
|
+
if (settings === null || settings === void 0 ? void 0 : settings.isUnmarshalled)
|
|
264
|
+
return (this.trackingMode = modeOf(settings.contents));
|
|
265
|
+
return 'Off';
|
|
266
|
+
}
|
|
267
|
+
set changeTrackingMode(mode) {
|
|
268
|
+
this.trackingMode = mode;
|
|
269
|
+
this.tracker = undefined;
|
|
270
|
+
const settings = this.mainDocumentPart ? this.settingsPart() : undefined;
|
|
271
|
+
if (settings === null || settings === void 0 ? void 0 : settings.isUnmarshalled) {
|
|
272
|
+
writeTrackRevisions(settings.contents, mode);
|
|
273
|
+
this.trackingPending = false;
|
|
274
|
+
}
|
|
275
|
+
else
|
|
276
|
+
this.trackingPending = true;
|
|
277
|
+
}
|
|
278
|
+
/** The mode as the settings part has it, unmarshalling the part (docx4j's async counterpart of the getter). */
|
|
279
|
+
async getChangeTrackingMode() {
|
|
280
|
+
var _a, _b;
|
|
281
|
+
const settings = (_a = this.mainDocumentPart) === null || _a === void 0 ? void 0 : _a.documentSettingsPart;
|
|
282
|
+
if (!settings)
|
|
283
|
+
return (_b = this.trackingMode) !== null && _b !== void 0 ? _b : 'Off';
|
|
284
|
+
return (this.trackingMode = modeOf(await settings.getContents()));
|
|
285
|
+
}
|
|
286
|
+
/** Writes `w:trackRevisions`, unmarshalling the settings part, or creating it when there is none. */
|
|
287
|
+
async setChangeTrackingMode(mode) {
|
|
288
|
+
this.trackingMode = mode;
|
|
289
|
+
this.tracker = undefined;
|
|
290
|
+
this.trackingPending = false;
|
|
291
|
+
writeTrackRevisions(await this.settingsPart().getContents(), mode);
|
|
292
|
+
}
|
|
293
|
+
/** The settings part, created (with its relationship and content type) when the document has none. */
|
|
294
|
+
settingsPart() {
|
|
295
|
+
const main = this.getMainDocumentPart();
|
|
296
|
+
let settings = main.documentSettingsPart;
|
|
297
|
+
if (!settings) {
|
|
298
|
+
settings = new DocumentSettingsPart();
|
|
299
|
+
settings.setContents({});
|
|
300
|
+
main.addTargetPart(settings);
|
|
301
|
+
}
|
|
302
|
+
return settings;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Office JS `document.getTrackedChanges()`: every tracked change in the main document part,
|
|
306
|
+
* in document order (headers and footers have their own `Body`). The part must be
|
|
307
|
+
* unmarshalled, as `body` needs it to be.
|
|
308
|
+
*/
|
|
309
|
+
getTrackedChanges() {
|
|
310
|
+
return this.body.getTrackedChanges();
|
|
311
|
+
}
|
|
312
|
+
/** The tracker every content-API mutation asks for; undefined while the mode is `Off`. */
|
|
313
|
+
get changeTracker() {
|
|
314
|
+
const mode = this.changeTrackingMode;
|
|
315
|
+
if (mode === 'Off')
|
|
316
|
+
return undefined;
|
|
317
|
+
if (!this.tracker || this.tracker.mode !== mode)
|
|
318
|
+
this.tracker = new ChangeTracker(this, mode);
|
|
319
|
+
return this.tracker;
|
|
320
|
+
}
|
|
321
|
+
/** TrackingHost: the trees a new revision id must be above, which is every part already unmarshalled. */
|
|
322
|
+
markupRoots() {
|
|
323
|
+
const out = [];
|
|
324
|
+
for (const part of this.parts) {
|
|
325
|
+
if (part instanceof XmlPart && part.isUnmarshalled) {
|
|
326
|
+
const contents = part.contents;
|
|
327
|
+
if (typeof contents === 'object' && contents !== null)
|
|
328
|
+
out.push(contents);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return out;
|
|
332
|
+
}
|
|
333
|
+
/** A clone carries the identity, the tracking date, the theme setting and the XPath engine. */
|
|
334
|
+
copyPackageSettingsTo(target) {
|
|
335
|
+
if (!(target instanceof WordprocessingMLPackage))
|
|
336
|
+
return;
|
|
337
|
+
target.author = { ...this.author };
|
|
338
|
+
target.trackedChangeDate = this.trackedChangeDate;
|
|
339
|
+
target.fonts.defaultTheme = this.fonts.defaultTheme;
|
|
340
|
+
target.xpathEngine = this.xpathEngine;
|
|
341
|
+
}
|
|
342
|
+
async saveTo(sink) {
|
|
343
|
+
var _a;
|
|
344
|
+
if (this.trackingPending)
|
|
345
|
+
await this.setChangeTrackingMode((_a = this.trackingMode) !== null && _a !== void 0 ? _a : 'Off');
|
|
346
|
+
return super.saveTo(sink);
|
|
347
|
+
}
|
|
86
348
|
/** The paragraph at an address anywhere in the document: 'body/3', 'header:rId5/0', a paraId, or a text match. */
|
|
87
349
|
async paragraphAt(address) {
|
|
88
350
|
for (const body of await this.bodies(address)) {
|
|
@@ -123,8 +385,53 @@ export class WordprocessingMLPackage extends OpcPackage {
|
|
|
123
385
|
all.push(await part.getBody());
|
|
124
386
|
return all;
|
|
125
387
|
}
|
|
388
|
+
/**
|
|
389
|
+
* Office JS `document.customXmlParts`: the custom XML data storage parts as views, with
|
|
390
|
+
* `add`, and docx4j's `applyBindings()` / `updateFromContentControls()` (CR-002 section 3.5).
|
|
391
|
+
*/
|
|
392
|
+
get customXmlParts() {
|
|
393
|
+
var _a;
|
|
394
|
+
const pkg = this;
|
|
395
|
+
return ((_a = this.customXmlPartCollection) !== null && _a !== void 0 ? _a : (this.customXmlPartCollection = new CustomXmlPartCollection({
|
|
396
|
+
// a getter, so that setting pkg.xpathEngine later is seen by the collection
|
|
397
|
+
get xpathEngine() { return pkg.xpathEngine; },
|
|
398
|
+
customXmlDataStorageParts: this.customXmlDataStorageParts,
|
|
399
|
+
getBoundBodies: async () => {
|
|
400
|
+
const main = this.getMainDocumentPart();
|
|
401
|
+
const bodies = [await main.getBody()];
|
|
402
|
+
for (const part of [...main.headerParts, ...main.footerParts])
|
|
403
|
+
bodies.push(await part.getBody());
|
|
404
|
+
return bodies;
|
|
405
|
+
},
|
|
406
|
+
boundBodies: () => {
|
|
407
|
+
const main = this.mainDocumentPart;
|
|
408
|
+
if (!(main === null || main === void 0 ? void 0 : main.isUnmarshalled))
|
|
409
|
+
return [];
|
|
410
|
+
const bodies = [main.body];
|
|
411
|
+
for (const part of [...main.headerParts, ...main.footerParts])
|
|
412
|
+
if (part.isUnmarshalled)
|
|
413
|
+
bodies.push(part.body);
|
|
414
|
+
return bodies;
|
|
415
|
+
},
|
|
416
|
+
customXmlRelationshipSource: () => this.getMainDocumentPart(),
|
|
417
|
+
})));
|
|
418
|
+
}
|
|
126
419
|
get progId() {
|
|
127
420
|
return 'Word.Document';
|
|
128
421
|
}
|
|
129
422
|
}
|
|
423
|
+
/**
|
|
424
|
+
* `w:trackRevisions` is a flag, so a file cannot distinguish `TrackAll` from `TrackMineOnly`;
|
|
425
|
+
* a document that has it on reads as `TrackAll`, and either value writes it.
|
|
426
|
+
*/
|
|
427
|
+
function modeOf(settings) {
|
|
428
|
+
const flag = settings.trackRevisions;
|
|
429
|
+
return flag === undefined || flag.val === false ? 'Off' : 'TrackAll';
|
|
430
|
+
}
|
|
431
|
+
function writeTrackRevisions(settings, mode) {
|
|
432
|
+
if (mode === 'Off')
|
|
433
|
+
delete settings.trackRevisions;
|
|
434
|
+
else
|
|
435
|
+
settings.trackRevisions = {};
|
|
436
|
+
}
|
|
130
437
|
registerPackageClass(MAIN_CONTENT_TYPES, WordprocessingMLPackage);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { OpcPackage, type PackageSource } from './OpcPackage.mjs';
|
|
2
2
|
export { WordprocessingMLPackage, type PageSizePaper, type CreatePackageOptions } from './WordprocessingMLPackage.mjs';
|
|
3
|
-
export { PresentationMLPackage } from './PresentationMLPackage.mjs';
|
|
3
|
+
export { PresentationMLPackage, createSlideSize, type SlideSizesWellKnown, type CreatePresentationOptions, } from './PresentationMLPackage.mjs';
|
|
4
4
|
export { SpreadsheetMLPackage } from './SpreadsheetMLPackage.mjs';
|
|
5
5
|
export { registerPackageClass, createPackageForContentType, type PackageConstructor } from './registry.mjs';
|
package/dist/packages/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Packages: OpcPackage and the three Office kinds. Importing this module registers all four.
|
|
2
2
|
export { OpcPackage } from './OpcPackage.mjs';
|
|
3
3
|
export { WordprocessingMLPackage } from './WordprocessingMLPackage.mjs';
|
|
4
|
-
export { PresentationMLPackage } from './PresentationMLPackage.mjs';
|
|
4
|
+
export { PresentationMLPackage, createSlideSize, } from './PresentationMLPackage.mjs';
|
|
5
5
|
export { SpreadsheetMLPackage } from './SpreadsheetMLPackage.mjs';
|
|
6
6
|
export { registerPackageClass, createPackageForContentType } from './registry.mjs';
|
|
@@ -8,10 +8,28 @@ import { PartName } from '../opc/PartName.mjs';
|
|
|
8
8
|
export declare class DefaultXmlPart extends Part {
|
|
9
9
|
private document;
|
|
10
10
|
private bytes;
|
|
11
|
+
/**
|
|
12
|
+
* A DOM parsed for reading only (CR-002 phase E): the part still writes its source bytes on
|
|
13
|
+
* save, so reading a custom XML part does not cost its byte-for-byte round trip. `markModified`
|
|
14
|
+
* adopts it.
|
|
15
|
+
*/
|
|
16
|
+
private readDocument;
|
|
11
17
|
constructor(partName: PartName | string, contentType?: string, relationshipType?: string);
|
|
12
18
|
get isLoaded(): boolean;
|
|
19
|
+
/** Whether a DOM is parsed (for reading or as the part's content). */
|
|
13
20
|
get isParsed(): boolean;
|
|
21
|
+
/** The DOM as the part's own content: from here on it is re-marshalled on save (docx4j getDocument). */
|
|
14
22
|
getDocument(): Promise<Document>;
|
|
23
|
+
/**
|
|
24
|
+
* The DOM, parsed on first call, **without** adopting it: an untouched part still writes its
|
|
25
|
+
* source bytes (CR-001's rule). Call `markModified()` after editing the DOM in place. Extension
|
|
26
|
+
* of docx4j's DefaultXmlPart, for the custom XML views of CR-002 phase E.
|
|
27
|
+
*/
|
|
28
|
+
parseDocument(): Promise<Document>;
|
|
29
|
+
/** The DOM if it is already parsed, else undefined: what a synchronous view reads (extension). */
|
|
30
|
+
get parsedDocument(): Document | undefined;
|
|
31
|
+
/** Adopts the parsed DOM as the part's content, so that save re-marshals it (extension). */
|
|
32
|
+
markModified(): void;
|
|
15
33
|
setDocument(document: Document): void;
|
|
16
34
|
setXml(xml: string): void;
|
|
17
35
|
getXml(): Promise<string>;
|
|
@@ -15,27 +15,56 @@ export class DefaultXmlPart extends Part {
|
|
|
15
15
|
get isLoaded() {
|
|
16
16
|
return this.document !== undefined || this.bytes !== undefined;
|
|
17
17
|
}
|
|
18
|
+
/** Whether a DOM is parsed (for reading or as the part's content). */
|
|
18
19
|
get isParsed() {
|
|
19
|
-
return this.
|
|
20
|
+
return this.parsedDocument !== undefined;
|
|
20
21
|
}
|
|
22
|
+
/** The DOM as the part's own content: from here on it is re-marshalled on save (docx4j getDocument). */
|
|
21
23
|
async getDocument() {
|
|
24
|
+
const document = await this.parseDocument();
|
|
25
|
+
this.markModified();
|
|
26
|
+
return document;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The DOM, parsed on first call, **without** adopting it: an untouched part still writes its
|
|
30
|
+
* source bytes (CR-001's rule). Call `markModified()` after editing the DOM in place. Extension
|
|
31
|
+
* of docx4j's DefaultXmlPart, for the custom XML views of CR-002 phase E.
|
|
32
|
+
*/
|
|
33
|
+
async parseDocument() {
|
|
22
34
|
var _a;
|
|
23
|
-
if (this.document
|
|
35
|
+
if (this.document !== undefined)
|
|
36
|
+
return this.document;
|
|
37
|
+
if (this.readDocument === undefined) {
|
|
24
38
|
const bytes = (_a = this.bytes) !== null && _a !== void 0 ? _a : (await this.loadSourceBytes());
|
|
25
39
|
if (bytes === undefined)
|
|
26
40
|
throw new Docx4JException(`Part ${this.partName} has no content: set a document or load it from a container`);
|
|
27
|
-
this.
|
|
28
|
-
this.bytes = undefined;
|
|
41
|
+
this.readDocument = parseXml(decodeXmlText(bytes));
|
|
29
42
|
}
|
|
30
|
-
return this.
|
|
43
|
+
return this.readDocument;
|
|
44
|
+
}
|
|
45
|
+
/** The DOM if it is already parsed, else undefined: what a synchronous view reads (extension). */
|
|
46
|
+
get parsedDocument() {
|
|
47
|
+
var _a;
|
|
48
|
+
return (_a = this.document) !== null && _a !== void 0 ? _a : this.readDocument;
|
|
49
|
+
}
|
|
50
|
+
/** Adopts the parsed DOM as the part's content, so that save re-marshals it (extension). */
|
|
51
|
+
markModified() {
|
|
52
|
+
if (this.document !== undefined)
|
|
53
|
+
return;
|
|
54
|
+
if (this.readDocument === undefined)
|
|
55
|
+
throw new Docx4JException(`Part ${this.partName} has no parsed document to mark as modified`);
|
|
56
|
+
this.document = this.readDocument;
|
|
57
|
+
this.bytes = undefined;
|
|
31
58
|
}
|
|
32
59
|
setDocument(document) {
|
|
33
60
|
this.document = document;
|
|
61
|
+
this.readDocument = undefined;
|
|
34
62
|
this.bytes = undefined;
|
|
35
63
|
}
|
|
36
64
|
setXml(xml) {
|
|
37
65
|
this.bytes = encodeText(xml);
|
|
38
66
|
this.document = undefined;
|
|
67
|
+
this.readDocument = undefined;
|
|
39
68
|
}
|
|
40
69
|
async getXml() {
|
|
41
70
|
return decodeXmlText(await this.getBytes());
|
|
@@ -91,6 +91,24 @@ export declare const Namespaces: {
|
|
|
91
91
|
readonly SPREADSHEETML_PIVOT_CACHE_DEFINITION: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition";
|
|
92
92
|
readonly SPREADSHEETML_PIVOT_CACHE_RECORDS: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheRecords";
|
|
93
93
|
readonly SPREADSHEETML_EXTERNAL_LINK: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLink";
|
|
94
|
+
/** `/xl/slicerCaches/slicerCache1.xml`, from the workbook. */
|
|
95
|
+
readonly SPREADSHEETML_SLICER_CACHE: "http://schemas.microsoft.com/office/2007/relationships/slicerCache";
|
|
96
|
+
/** `/xl/slicers/slicer1.xml`, from a worksheet. */
|
|
97
|
+
readonly SPREADSHEETML_SLICERS: "http://schemas.microsoft.com/office/2007/relationships/slicer";
|
|
98
|
+
/** `/xl/timelineCaches/timelineCache1.xml`, from the workbook. */
|
|
99
|
+
readonly SPREADSHEETML_TIMELINE_CACHE: "http://schemas.microsoft.com/office/2011/relationships/timelineCache";
|
|
100
|
+
/** `/xl/timelines/timeline1.xml`, from a worksheet. */
|
|
101
|
+
readonly SPREADSHEETML_TIMELINES: "http://schemas.microsoft.com/office/2011/relationships/timeline";
|
|
102
|
+
/** `/xl/ctrlProps/ctrlProp1.xml`, from a worksheet, for one of its form controls. */
|
|
103
|
+
readonly SPREADSHEETML_CONTROL_PROPERTIES: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/ctrlProp";
|
|
104
|
+
/** `/xl/customDataProps/customDataProps1.xml`, from the workbook. */
|
|
105
|
+
readonly SPREADSHEETML_CUSTOM_DATA_PROPERTIES: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customDataProps";
|
|
106
|
+
/** `/xl/customData/customData1.dat`, from its properties part. */
|
|
107
|
+
readonly SPREADSHEETML_CUSTOM_DATA: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customData";
|
|
108
|
+
/** `/xl/surveys/survey1.xml`, from the workbook. */
|
|
109
|
+
readonly SPREADSHEETML_SURVEY: "http://schemas.microsoft.com/office/2010/relationships/Survey";
|
|
110
|
+
/** `/xl/model/item.data` ([MS-XLDM]), from the workbook. */
|
|
111
|
+
readonly SPREADSHEETML_DATA_MODEL: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/powerPivotData";
|
|
94
112
|
readonly WEB_EXTENSION_TASKPANES: "http://schemas.microsoft.com/office/webextensions/taskpanes/2010/11";
|
|
95
113
|
readonly WEB_EXTENSION_WEBEXTENSION: "http://schemas.microsoft.com/office/webextensions/webextension/2010/11";
|
|
96
114
|
readonly XML_EVENTS: "http://www.w3.org/2001/xml-events";
|