@docx4j/core-ts 0.3.1 → 0.3.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/dist/model/content/Body.mjs +2 -1
- package/dist/model/content/ContentControl.d.mts +5 -1
- package/dist/model/content/ContentControl.mjs +18 -5
- package/dist/model/content/Paragraph.d.mts +11 -11
- package/dist/model/content/Paragraph.mjs +30 -43
- package/dist/model/content/Range.mjs +3 -2
- package/dist/model/content/stylesFacade.mjs +7 -4
- package/dist/model/content/tracking.d.mts +14 -0
- package/dist/model/content/tracking.mjs +19 -10
- package/dist/model/customxml/XmlMapping.d.mts +20 -4
- package/dist/model/customxml/XmlMapping.mjs +44 -6
- package/dist/model/customxml/bindings.d.mts +9 -2
- package/dist/model/customxml/bindings.mjs +18 -2
- package/dist/model/customxml/index.d.mts +1 -1
- package/dist/model/customxml/index.mjs +1 -1
- package/dist/model/customxml/insert.d.mts +10 -0
- package/dist/model/customxml/insert.mjs +13 -0
- package/dist/model/fonts/RunFontSelector.d.mts +8 -1
- package/dist/model/fonts/RunFontSelector.mjs +6 -5
- package/dist/model/properties/PropertyResolver.d.mts +110 -10
- package/dist/model/properties/PropertyResolver.mjs +300 -31
- package/dist/model/properties/index.d.mts +3 -0
- package/dist/model/properties/index.mjs +2 -0
- package/dist/model/properties/table.d.mts +155 -0
- package/dist/model/properties/table.mjs +315 -0
- package/dist/model/properties/tableStyleConditions.d.mts +101 -0
- package/dist/model/properties/tableStyleConditions.mjs +296 -0
- package/dist/parts/wml/placeholderStyle.d.mts +3 -0
- package/dist/parts/wml/placeholderStyle.mjs +13 -0
- package/package.json +2 -2
|
@@ -16,5 +16,15 @@ export declare function controlIdScope(body: {
|
|
|
16
16
|
part?: XmlPart<unknown> | undefined;
|
|
17
17
|
container: object;
|
|
18
18
|
}): object;
|
|
19
|
+
/**
|
|
20
|
+
* Lists `w15` in the `mc:Ignorable` of the body's part when the new control's `w:sdtPr` holds a
|
|
21
|
+
* `w15` element (a repeating section or its item): Word 2010 knows no `w15` and opens a part with
|
|
22
|
+
* one only when the prefix is ignorable (CR-002 section 40, `test/README.md` check 35).
|
|
23
|
+
*/
|
|
24
|
+
export declare function declareSdtExtensions(body: {
|
|
25
|
+
part?: XmlPart<unknown> | undefined;
|
|
26
|
+
}, sdt: {
|
|
27
|
+
value?: unknown;
|
|
28
|
+
}): void;
|
|
19
29
|
/** True for a run-level item (what a Range wraps). */
|
|
20
30
|
export declare function isRunLevel(element: Element): boolean;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { typeNameOf } from '../content/tree.mjs';
|
|
2
|
+
import { declareIgnorable } from '../content/tracking.mjs';
|
|
3
|
+
const W15_NS = 'http://schemas.microsoft.com/office/word/2012/wordml';
|
|
2
4
|
/**
|
|
3
5
|
* The kind the builders' `sdt` takes: Office JS's `Unknown` has no kind element, as `RichText`
|
|
4
6
|
* has none (Word reports an untyped control as rich text).
|
|
@@ -15,6 +17,17 @@ export function controlIdScope(body) {
|
|
|
15
17
|
const part = body.part;
|
|
16
18
|
return (part === null || part === void 0 ? void 0 : part.isUnmarshalled) ? part.contents : body.container;
|
|
17
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Lists `w15` in the `mc:Ignorable` of the body's part when the new control's `w:sdtPr` holds a
|
|
22
|
+
* `w15` element (a repeating section or its item): Word 2010 knows no `w15` and opens a part with
|
|
23
|
+
* one only when the prefix is ignorable (CR-002 section 40, `test/README.md` check 35).
|
|
24
|
+
*/
|
|
25
|
+
export function declareSdtExtensions(body, sdt) {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
const items = (_b = (_a = sdt.value) === null || _a === void 0 ? void 0 : _a.sdtPr) === null || _b === void 0 ? void 0 : _b.rPrOrAliasOrLock;
|
|
28
|
+
if (items === null || items === void 0 ? void 0 : items.some((item) => { var _a; return ((_a = item.name) === null || _a === void 0 ? void 0 : _a.namespaceURI) === W15_NS; }))
|
|
29
|
+
declareIgnorable(body.part, 'w15');
|
|
30
|
+
}
|
|
18
31
|
/** True for a run-level item (what a Range wraps). */
|
|
19
32
|
export function isRunLevel(element) {
|
|
20
33
|
const tn = typeNameOf(element);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type * as wml from '@docx4j/generated-objects-ts/modules/org_docx4j_wml';
|
|
2
2
|
import type { PropertyResolver } from '../properties/PropertyResolver.mjs';
|
|
3
|
+
import type { CellContext } from '../properties/table.mjs';
|
|
3
4
|
import { type ThemeFontLang, type ThemeSource } from './ThemeFonts.mjs';
|
|
4
5
|
import { type DefaultTheme } from './defaultTheme.mjs';
|
|
5
6
|
/** Word's built-in default where the document defaults name no font at all (docx4j CR-016
|
|
@@ -41,6 +42,11 @@ export interface RunFontSelectorSource {
|
|
|
41
42
|
export interface SpansOptions {
|
|
42
43
|
/** True where the caller has resolved the run's effective properties already. */
|
|
43
44
|
rPrIsEffective?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The paragraph's table context (`PropertyResolver.cellContextOf(p)`, or a tracker's), so a run
|
|
47
|
+
* in a table cell is resolved with its table style's formatting (CR-007; docx4j CR-030 phase 5).
|
|
48
|
+
*/
|
|
49
|
+
cellContext?: CellContext | undefined;
|
|
44
50
|
}
|
|
45
51
|
/** `w:cs` and `w:rtl` are `ST_OnOff`: present without `w:val` means true, `w:val="0"` false. */
|
|
46
52
|
export declare function isOn(value: wml.BooleanDefaultTrue | undefined): boolean;
|
|
@@ -149,8 +155,9 @@ export declare class RunFontSelector {
|
|
|
149
155
|
* at least.
|
|
150
156
|
*
|
|
151
157
|
* @param rPrIsEffective true where the caller has resolved the run's properties already
|
|
158
|
+
* @param cellContext the paragraph's table context, where it is in a table cell (CR-007)
|
|
152
159
|
*/
|
|
153
|
-
documentFontFor(pPr: wml.PPr | undefined, rPr: wml.RPr | undefined, codePoint: number, rPrIsEffective?: boolean): string;
|
|
160
|
+
documentFontFor(pPr: wml.PPr | undefined, rPr: wml.RPr | undefined, codePoint: number, rPrIsEffective?: boolean, cellContext?: CellContext | undefined): string;
|
|
154
161
|
/**
|
|
155
162
|
* The run's text folded into maximal stretches of one document font.
|
|
156
163
|
*
|
|
@@ -173,10 +173,10 @@ export class RunFontSelector {
|
|
|
173
173
|
return this.defaultFont;
|
|
174
174
|
}
|
|
175
175
|
/** The run's effective properties, never undefined. */
|
|
176
|
-
effectiveRPr(pPr, rPr, rPrIsEffective) {
|
|
176
|
+
effectiveRPr(pPr, rPr, rPrIsEffective, cellContext) {
|
|
177
177
|
var _a;
|
|
178
178
|
if (!rPrIsEffective && this.source.resolver !== undefined) {
|
|
179
|
-
return (_a = this.source.resolver.getEffectiveRPr(rPr, pPr)) !== null && _a !== void 0 ? _a : {};
|
|
179
|
+
return (_a = this.source.resolver.getEffectiveRPr(rPr, pPr, cellContext)) !== null && _a !== void 0 ? _a : {};
|
|
180
180
|
}
|
|
181
181
|
return rPr !== null && rPr !== void 0 ? rPr : {};
|
|
182
182
|
}
|
|
@@ -259,10 +259,11 @@ export class RunFontSelector {
|
|
|
259
259
|
* at least.
|
|
260
260
|
*
|
|
261
261
|
* @param rPrIsEffective true where the caller has resolved the run's properties already
|
|
262
|
+
* @param cellContext the paragraph's table context, where it is in a table cell (CR-007)
|
|
262
263
|
*/
|
|
263
|
-
documentFontFor(pPr, rPr, codePoint, rPrIsEffective = false) {
|
|
264
|
+
documentFontFor(pPr, rPr, codePoint, rPrIsEffective = false, cellContext) {
|
|
264
265
|
var _a;
|
|
265
|
-
const effective = this.effectiveRPr(pPr, rPr, rPrIsEffective);
|
|
266
|
+
const effective = this.effectiveRPr(pPr, rPr, rPrIsEffective, cellContext);
|
|
266
267
|
return (_a = this.fontOf(this.slotsOf(pPr, effective), codePoint)) !== null && _a !== void 0 ? _a : this.defaultFont;
|
|
267
268
|
}
|
|
268
269
|
/**
|
|
@@ -280,7 +281,7 @@ export class RunFontSelector {
|
|
|
280
281
|
const spans = [];
|
|
281
282
|
if (text === undefined || text === null || text.length === 0)
|
|
282
283
|
return spans;
|
|
283
|
-
const effective = this.effectiveRPr(pPr, rPr, options.rPrIsEffective === true);
|
|
284
|
+
const effective = this.effectiveRPr(pPr, rPr, options.rPrIsEffective === true, options.cellContext);
|
|
284
285
|
const bold = isOn(effective.b);
|
|
285
286
|
const italic = isOn(effective.i);
|
|
286
287
|
const cs = isOn(effective.cs);
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type * as wml from '@docx4j/generated-objects-ts/modules/org_docx4j_wml';
|
|
2
2
|
import { NumberingDefinitions } from '../listnumbering/definitions.mjs';
|
|
3
|
+
import { CellContext, TableContext } from './table.mjs';
|
|
3
4
|
/** The parts the resolver reads. Structural, so this module imports no part class. */
|
|
4
5
|
export interface ResolverSource {
|
|
5
6
|
/** The styles part's `w:styles`, or undefined when the package has none. */
|
|
6
7
|
styles?: wml.Styles;
|
|
7
8
|
/** The numbering part's `w:numbering`, or undefined. */
|
|
8
9
|
numbering?: wml.Numbering;
|
|
10
|
+
/**
|
|
11
|
+
* The settings part's `w:settings`, or undefined: read for the compatibility mode and
|
|
12
|
+
* `overrideTableStyleFontSizeAndJustification` (CR-007). A document with none is in mode 12.
|
|
13
|
+
*/
|
|
14
|
+
settings?: wml.CTSettings;
|
|
9
15
|
}
|
|
10
16
|
/** As much of an `XmlPart<T>` as the resolver uses. */
|
|
11
17
|
interface ReadablePart<T> {
|
|
@@ -18,6 +24,7 @@ interface PackageLike {
|
|
|
18
24
|
getMainDocumentPart(): {
|
|
19
25
|
styleDefinitionsPart?: ReadablePart<wml.Styles>;
|
|
20
26
|
numberingDefinitionsPart?: ReadablePart<wml.Numbering>;
|
|
27
|
+
documentSettingsPart?: ReadablePart<wml.CTSettings>;
|
|
21
28
|
};
|
|
22
29
|
}
|
|
23
30
|
/** 108 twips (0.08in): the left and right cell margin of Word's built-in Normal Table. */
|
|
@@ -44,6 +51,17 @@ export declare class PropertyResolver {
|
|
|
44
51
|
/** The document defaults with the chain applied over them: what the style overloads return. */
|
|
45
52
|
private readonly effectivePPrByStyle;
|
|
46
53
|
private readonly effectiveRPrByStyle;
|
|
54
|
+
/** Each table style's `w:basedOn` chain merged, by id; styles only, so `refresh()` clears it. */
|
|
55
|
+
private readonly tableStyleChains;
|
|
56
|
+
/**
|
|
57
|
+
* A paragraph style composed over a table level, document defaults included; by (paragraph
|
|
58
|
+
* style, table level). What the overloads with a context start from, as
|
|
59
|
+
* `getEffectivePPr(styleId)` is what they start from without one.
|
|
60
|
+
*/
|
|
61
|
+
private readonly composedPPrCache;
|
|
62
|
+
private readonly composedRPrCache;
|
|
63
|
+
/** See {@link appliesTableStyleSizeJcException}; read once per `refresh()`. */
|
|
64
|
+
private tableStyleSizeJcException;
|
|
47
65
|
/** Missing styles are logged once each per resolver. */
|
|
48
66
|
private readonly missingLogged;
|
|
49
67
|
private numberingDefinitions;
|
|
@@ -142,6 +160,15 @@ export declare class PropertyResolver {
|
|
|
142
160
|
* naming no style resolves as the default paragraph style does.
|
|
143
161
|
*/
|
|
144
162
|
getEffectivePPr(styleId: string | undefined): wml.PPr;
|
|
163
|
+
/**
|
|
164
|
+
* The paragraph properties which apply to a paragraph in a table cell: as
|
|
165
|
+
* `getEffectivePPr(pPr)`, with the table style's contribution (its own `w:pPr`, then the
|
|
166
|
+
* conditional formats the paragraph is under) between the document defaults and the
|
|
167
|
+
* paragraph's style, and [MS-DOCX]'s justification exception where it applies. An undefined
|
|
168
|
+
* context - a paragraph in no table - resolves exactly as `getEffectivePPr(pPr)`. A live
|
|
169
|
+
* object where the paragraph has no direct formatting: copy it before changing it.
|
|
170
|
+
*/
|
|
171
|
+
getEffectivePPr(pPr: wml.PPr | undefined, cellContext: CellContext | undefined): wml.PPr;
|
|
145
172
|
private effectivePPrOfStyle;
|
|
146
173
|
/**
|
|
147
174
|
* The run properties which apply to a run, given its own `w:rPr` and the `w:pPr` of the
|
|
@@ -158,6 +185,14 @@ export declare class PropertyResolver {
|
|
|
158
185
|
* what it contributes with nothing under it. Undefined when no such style exists.
|
|
159
186
|
*/
|
|
160
187
|
getEffectiveRPr(styleId: string): wml.RPr | undefined;
|
|
188
|
+
/**
|
|
189
|
+
* The run properties which apply to a run in a table cell: as `getEffectiveRPr(rPr, pPr)`,
|
|
190
|
+
* with the table style's run properties (its own, then its conditional formats') as a level
|
|
191
|
+
* of the style hierarchy beneath the paragraph style's - the toggle properties combine across
|
|
192
|
+
* the two (ECMA-376-1 17.7.3) - and [MS-DOCX]'s size exception where it applies. An undefined
|
|
193
|
+
* context resolves exactly as `getEffectiveRPr(rPr, pPr)`. A new object each call.
|
|
194
|
+
*/
|
|
195
|
+
getEffectiveRPr(rPr: wml.RPr | undefined, pPr: wml.PPr | undefined, cellContext: CellContext | undefined): wml.RPr;
|
|
161
196
|
private effectiveRPrOfStyle;
|
|
162
197
|
/**
|
|
163
198
|
* The character style's chain, then the direct formatting.
|
|
@@ -173,29 +208,94 @@ export declare class PropertyResolver {
|
|
|
173
208
|
* properties, then the `w:pPr`'s own `w:rPr`. What sizes an empty paragraph, and what a list
|
|
174
209
|
* label starts from.
|
|
175
210
|
*/
|
|
176
|
-
getEffectiveParagraphMarkRPr(pPr: wml.PPr | undefined): wml.RPr;
|
|
211
|
+
getEffectiveParagraphMarkRPr(pPr: wml.PPr | undefined, cellContext?: CellContext | undefined): wml.RPr;
|
|
177
212
|
/** Whether the run states any formatting of its own (docx4j's deprecated `hasDirectRPrFormatting`). */
|
|
178
213
|
hasDirectRPrFormatting(rPr: wml.RPr | undefined): boolean;
|
|
179
214
|
/**
|
|
180
215
|
* The table style which applies, merged root-first down its `w:basedOn` chain, then the
|
|
181
216
|
* table's own `w:tblPr` over it.
|
|
182
217
|
*
|
|
183
|
-
* Word's
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* starts from nothing
|
|
218
|
+
* Word goes by the style's **name** (measured, docx4j CR-030 probes T1, T2 and T7). A style
|
|
219
|
+
* named "Normal Table" is Word's built-in Normal Table (`w:tblInd` 0; cell margins 108 twips
|
|
220
|
+
* left and right, 0 top and bottom), whatever its own definition says and whether or not it is
|
|
221
|
+
* the document's default: the built-in stands in for it, and the walk up the chain ends there.
|
|
222
|
+
* Every other style applies as written, with nothing beneath it: a chain which reaches no style
|
|
223
|
+
* so named starts from nothing, and the document's default table style, where it is named
|
|
224
|
+
* otherwise, applies as written to a table naming no style. The built-in also stands in for a
|
|
225
|
+
* style which is missing, and where the document has no default table style. (Until CR-007 the
|
|
226
|
+
* built-in was decided by the default table style's *id*, as docx4j did until 17.3.1.)
|
|
189
227
|
*
|
|
190
228
|
* A new `Style` each call, with a non-null `w:tblPr`.
|
|
191
229
|
*/
|
|
192
230
|
getEffectiveTableStyle(tblPr: wml.CTTblPrBase | undefined): wml.Style;
|
|
193
231
|
/**
|
|
194
|
-
* Whether
|
|
195
|
-
* {@link getEffectiveTableStyle} decides
|
|
196
|
-
* style
|
|
232
|
+
* Whether Word's built-in Normal Table underlies a table - the flag
|
|
233
|
+
* {@link getEffectiveTableStyle} decides by: the table's style chain (its own `w:tblStyle`,
|
|
234
|
+
* else the default table style) reaches a style *named* "Normal Table", or the style is
|
|
235
|
+
* missing, or there is none. Decided by name since CR-007; the method keeps docx4j's name
|
|
236
|
+
* from when it was decided by the default style's id.
|
|
197
237
|
*/
|
|
198
238
|
reachesDefaultTableStyle(tblPr: wml.CTTblPrBase | undefined): boolean;
|
|
239
|
+
private builtInTableNormalUnderlies;
|
|
240
|
+
/**
|
|
241
|
+
* Whether [MS-DOCX]'s `overrideTableStyleFontSizeAndJustification` exception applies to this
|
|
242
|
+
* document: a default paragraph style's 12pt does not override the table style's size, nor its
|
|
243
|
+
* left justification the table style's, for paragraphs in tables. Measured with Word 365
|
|
244
|
+
* (docx4j CR-030 probes T5 and T6): it applies below compatibility mode 15 (a document stating
|
|
245
|
+
* no `compatibilityMode` is mode 12) where the setting is not on, and never in mode 15.
|
|
246
|
+
*/
|
|
247
|
+
appliesTableStyleSizeJcException(): boolean;
|
|
248
|
+
/**
|
|
249
|
+
* The id of the table style a table resolves to: its own `w:tblStyle`, else the document's
|
|
250
|
+
* `w:default` table style, whatever its name; undefined where the table names none and the
|
|
251
|
+
* document has no default. (Whether that style contributes anything is
|
|
252
|
+
* {@link getTableStyleChain}'s question.)
|
|
253
|
+
*/
|
|
254
|
+
getTableStyleIdOf(tblPr: wml.CTTblPrBase | undefined): string | undefined;
|
|
255
|
+
/**
|
|
256
|
+
* A table style's `w:basedOn` chain merged root-first, conditional formats merged per
|
|
257
|
+
* condition, as it gives the paragraphs of its tables their text formatting. Word goes by the
|
|
258
|
+
* style's *name*: a style named "Normal Table" is Word's built-in, which gives text nothing
|
|
259
|
+
* whatever its own definition says, so the walk up the chain ends below it; every other style
|
|
260
|
+
* applies as written, the default table style included.
|
|
261
|
+
*
|
|
262
|
+
* Cached per id, and shared: read it, do not change it. An empty style for undefined, for a
|
|
263
|
+
* missing style, and for a chain which is "Normal Table" all the way down.
|
|
264
|
+
*/
|
|
265
|
+
getTableStyleChain(styleId: string | undefined): wml.Style;
|
|
266
|
+
/**
|
|
267
|
+
* The context of a table, for the paragraphs in it: build one per table and hold it while
|
|
268
|
+
* walking the table (the resolver keeps none, since it reads the table's content).
|
|
269
|
+
*/
|
|
270
|
+
tableContext(tbl: wml.Tbl): TableContext;
|
|
271
|
+
/**
|
|
272
|
+
* The table context of one paragraph, found through its `PARENT` pointers: the nearest
|
|
273
|
+
* enclosing cell, its row and its table, through whatever lies between (`w:sdt`,
|
|
274
|
+
* `w:customXml`, `w:smartTag`). Undefined where the paragraph is in no table, where a story
|
|
275
|
+
* begins before a cell is reached (a text box, a footnote, endnote or comment, a header, a
|
|
276
|
+
* footer, the body), or where the pointers are not there (unmarshalled content, and content
|
|
277
|
+
* the content API inserted, has them: `linkParents`).
|
|
278
|
+
*
|
|
279
|
+
* Each call builds a {@link TableContext}, a walk of the table's rows. That is right for "what
|
|
280
|
+
* formatting does this paragraph have"; code resolving every paragraph of a document walks it
|
|
281
|
+
* with a `TableContextTracker` instead, since calling this for each paragraph of a large table
|
|
282
|
+
* is quadratic.
|
|
283
|
+
*/
|
|
284
|
+
cellContextOf(p: wml.P): CellContext | undefined;
|
|
285
|
+
private clearTableCaches;
|
|
286
|
+
/** The table level's `w:pPr`: the style's own, then its conditional formats'; undefined if none. */
|
|
287
|
+
private tableLevelPPr;
|
|
288
|
+
/** The table level's `w:rPr`: the style's own, then its conditional formats'; undefined if none. */
|
|
289
|
+
private tableLevelRPr;
|
|
290
|
+
private composedPPr;
|
|
291
|
+
private composedRPr;
|
|
292
|
+
/**
|
|
293
|
+
* [MS-DOCX]'s exception, for a paragraph in a table whose style states a size (or a
|
|
294
|
+
* justification): the paragraph's style gives way to it if the style is the default paragraph
|
|
295
|
+
* style, or states no size (justification) of its own, and resolves to 12pt (left). A style of
|
|
296
|
+
* the paragraph's own which states one keeps it.
|
|
297
|
+
*/
|
|
298
|
+
private paragraphStyleGivesWay;
|
|
199
299
|
/** Word's built-in Normal Table, as a style: what it applies whatever the document's own definition says. */
|
|
200
300
|
private builtInTableNormal;
|
|
201
301
|
/**
|