@docx4j/core-ts 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +4 -0
- package/README.md +34 -3
- package/dist/html/convert.mjs +40 -15
- package/dist/html/elements.mjs +2 -1
- package/dist/model/color/ColorMath.d.mts +29 -0
- package/dist/model/color/ColorMath.mjs +146 -0
- package/dist/model/color/ColorTables.d.mts +6 -0
- package/dist/model/color/ColorTables.mjs +83 -0
- package/dist/model/color/DrawingMLColors.d.mts +52 -0
- package/dist/model/color/DrawingMLColors.mjs +374 -0
- package/dist/model/color/ResolvedColor.d.mts +36 -0
- package/dist/model/color/ResolvedColor.mjs +65 -0
- package/dist/model/color/SpreadsheetColors.d.mts +36 -0
- package/dist/model/color/SpreadsheetColors.mjs +84 -0
- package/dist/model/color/StyleFill.d.mts +28 -0
- package/dist/model/color/StyleFill.mjs +21 -0
- package/dist/model/color/ThemeColors.d.mts +86 -0
- package/dist/model/color/ThemeColors.mjs +304 -0
- package/dist/model/color/WordColors.d.mts +71 -0
- package/dist/model/color/WordColors.mjs +121 -0
- package/dist/model/color/index.d.mts +6 -0
- package/dist/model/color/index.mjs +30 -0
- package/dist/model/content/Body.d.mts +153 -19
- package/dist/model/content/Body.mjs +570 -131
- package/dist/model/content/Comment.d.mts +21 -3
- package/dist/model/content/Comment.mjs +202 -19
- package/dist/model/content/ContentControl.d.mts +197 -18
- package/dist/model/content/ContentControl.mjs +664 -95
- package/dist/model/content/Font.d.mts +67 -17
- package/dist/model/content/Font.mjs +114 -35
- package/dist/model/content/InlinePicture.d.mts +82 -7
- package/dist/model/content/InlinePicture.mjs +221 -28
- package/dist/model/content/List.mjs +13 -1
- package/dist/model/content/Paragraph.d.mts +213 -14
- package/dist/model/content/Paragraph.mjs +936 -100
- package/dist/model/content/Range.d.mts +242 -11
- package/dist/model/content/Range.mjs +975 -119
- package/dist/model/content/ResolvedView.d.mts +104 -0
- package/dist/model/content/ResolvedView.mjs +596 -0
- package/dist/model/content/Table.d.mts +29 -3
- package/dist/model/content/Table.mjs +109 -33
- package/dist/model/content/TrackedChange.d.mts +301 -16
- package/dist/model/content/TrackedChange.mjs +1284 -158
- package/dist/model/content/binder.d.mts +2 -1
- package/dist/model/content/binder.mjs +48 -1
- package/dist/model/content/comments.d.mts +20 -6
- package/dist/model/content/comments.mjs +67 -57
- package/dist/model/content/generalException.d.mts +18 -0
- package/dist/model/content/generalException.mjs +24 -0
- package/dist/model/content/index.d.mts +8 -3
- package/dist/model/content/index.mjs +7 -2
- package/dist/model/content/mathText.d.mts +21 -0
- package/dist/model/content/mathText.mjs +267 -0
- package/dist/model/content/officeText.d.mts +27 -0
- package/dist/model/content/officeText.mjs +74 -0
- package/dist/model/content/outline.d.mts +5 -0
- package/dist/model/content/outline.mjs +13 -0
- package/dist/model/content/placeholders.d.mts +110 -0
- package/dist/model/content/placeholders.mjs +253 -0
- package/dist/model/content/relationships.d.mts +30 -0
- package/dist/model/content/relationships.mjs +133 -0
- package/dist/model/content/search.d.mts +72 -0
- package/dist/model/content/search.mjs +204 -2
- package/dist/model/content/spanEdits.d.mts +159 -0
- package/dist/model/content/spanEdits.mjs +728 -0
- package/dist/model/content/story.d.mts +44 -0
- package/dist/model/content/story.mjs +92 -0
- package/dist/model/content/tableColumns.d.mts +1 -1
- package/dist/model/content/tableColumns.mjs +108 -80
- package/dist/model/content/tableRevisions.d.mts +11 -3
- package/dist/model/content/tableRevisions.mjs +72 -42
- package/dist/model/content/tableRules.d.mts +30 -0
- package/dist/model/content/tableRules.mjs +100 -0
- package/dist/model/content/textBoxes.d.mts +18 -0
- package/dist/model/content/textBoxes.mjs +105 -0
- package/dist/model/content/trackedChangeFilter.d.mts +39 -0
- package/dist/model/content/trackedChangeFilter.mjs +81 -0
- package/dist/model/content/tracking.d.mts +28 -0
- package/dist/model/content/tracking.mjs +149 -10
- package/dist/model/content/tree.d.mts +212 -13
- package/dist/model/content/tree.mjs +356 -35
- package/dist/model/customxml/CustomXmlPartCollection.d.mts +8 -0
- package/dist/model/customxml/CustomXmlPartCollection.mjs +34 -11
- package/dist/model/customxml/XmlMapping.d.mts +1 -1
- package/dist/model/customxml/XmlMapping.mjs +11 -0
- package/dist/model/customxml/bindings.d.mts +21 -2
- package/dist/model/customxml/bindings.mjs +76 -32
- package/dist/model/customxml/kinds.d.mts +8 -3
- package/dist/model/customxml/kinds.mjs +26 -5
- package/dist/model/customxml/picturePlaceholder.d.mts +17 -0
- package/dist/model/customxml/picturePlaceholder.mjs +32 -0
- package/dist/model/customxml/pictures.d.mts +9 -5
- package/dist/model/customxml/pictures.mjs +31 -13
- package/dist/model/customxml/xhtml.mjs +8 -2
- package/dist/model/fonts/families.generated.mjs +2 -2
- package/dist/model/fonts/registry.mjs +7 -1
- package/dist/model/fonts/substitutions.generated.mjs +2 -2
- package/dist/model/fonts/themes.generated.mjs +1 -1
- package/dist/model/index.d.mts +2 -0
- package/dist/model/index.mjs +4 -0
- package/dist/model/listnumbering/Emulator.d.mts +37 -5
- package/dist/model/listnumbering/Emulator.mjs +63 -9
- package/dist/model/listnumbering/definitions.mjs +18 -0
- package/dist/model/properties/PropertyResolver.d.mts +87 -7
- package/dist/model/properties/PropertyResolver.mjs +197 -17
- package/dist/model/properties/catalogue.d.mts +32 -4
- package/dist/model/properties/catalogue.mjs +115 -36
- package/dist/model/properties/log.d.mts +1 -1
- package/dist/model/properties/log.mjs +5 -5
- package/dist/model/properties/table.d.mts +16 -2
- package/dist/model/properties/table.mjs +17 -5
- package/dist/model/text/Extractor.d.mts +289 -0
- package/dist/model/text/Extractor.mjs +2162 -0
- package/dist/model/text/LinkTargets.d.mts +45 -0
- package/dist/model/text/LinkTargets.mjs +170 -0
- package/dist/model/text/MarkdownExporter.d.mts +140 -0
- package/dist/model/text/MarkdownExporter.mjs +255 -0
- package/dist/model/text/PlainText.d.mts +29 -0
- package/dist/model/text/PlainText.mjs +539 -0
- package/dist/model/text/TextContext.d.mts +161 -0
- package/dist/model/text/TextContext.mjs +425 -0
- package/dist/model/text/TextOptions.d.mts +150 -0
- package/dist/model/text/TextOptions.mjs +278 -0
- package/dist/model/text/TextResult.d.mts +504 -0
- package/dist/model/text/TextResult.mjs +526 -0
- package/dist/model/text/Texts.d.mts +99 -0
- package/dist/model/text/Texts.mjs +187 -0
- package/dist/model/text/WmlToMarkdown.d.mts +120 -0
- package/dist/model/text/WmlToMarkdown.mjs +911 -0
- package/dist/model/text/commonmark.d.mts +121 -0
- package/dist/model/text/commonmark.mjs +655 -0
- package/dist/model/text/index.d.mts +7 -0
- package/dist/model/text/index.mjs +8 -0
- package/dist/model/text/normalize.d.mts +8 -0
- package/dist/model/text/normalize.mjs +13 -0
- package/dist/model/text/outline.d.mts +4 -0
- package/dist/model/text/outline.mjs +71 -0
- package/dist/office-js/fragment.d.mts +7 -5
- package/dist/office-js/fragment.mjs +63 -14
- package/dist/office-js/proxy.d.mts +8 -0
- package/dist/office-js/proxy.mjs +29 -0
- package/dist/office-js/run.mjs +2 -0
- package/dist/office-js/supported.generated.mjs +16 -0
- package/dist/office-js/toApiScript.mjs +21 -5
- package/dist/opc/Load.d.mts +9 -2
- package/dist/opc/Save.d.mts +17 -0
- package/dist/opc/Save.mjs +12 -2
- package/dist/opc/index.d.mts +3 -3
- package/dist/opc/index.mjs +2 -2
- package/dist/opc/mce/preprocessor.d.mts +88 -7
- package/dist/opc/mce/preprocessor.mjs +144 -37
- package/dist/opc/mce/understood.d.mts +34 -0
- package/dist/opc/mce/understood.mjs +55 -3
- package/dist/packages/OpcPackage.d.mts +20 -0
- package/dist/packages/OpcPackage.mjs +16 -3
- package/dist/packages/WordprocessingMLPackage.d.mts +77 -7
- package/dist/packages/WordprocessingMLPackage.mjs +242 -11
- package/dist/parts/DefaultXmlPart.mjs +2 -2
- package/dist/parts/Part.d.mts +10 -2
- package/dist/parts/XmlPart.d.mts +35 -32
- package/dist/parts/XmlPart.mjs +107 -107
- package/dist/parts/wml/comments.mjs +30 -0
- package/dist/parts/wml/index.mjs +12 -0
- package/dist/xml/dom.d.mts +7 -0
- package/dist/xml/dom.mjs +18 -0
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type * as wml from '@docx4j/generated-objects-ts/modules/org_docx4j_wml';
|
|
2
|
-
import { type UnderlineType } from '@docx4j/generated-objects-ts/builders/wml';
|
|
2
|
+
import { type RunOptions, type RunFormatting, type UnderlineType } from '@docx4j/generated-objects-ts/builders/wml';
|
|
3
3
|
import type { ChangeTracker } from './tracking.mjs';
|
|
4
|
+
import type { ThemeColors } from '../color/ThemeColors.mjs';
|
|
4
5
|
export type { UnderlineType };
|
|
5
6
|
/** Something with run properties: a run, or the paragraph mark. */
|
|
6
7
|
export interface RPrHolder {
|
|
@@ -12,13 +13,33 @@ export interface FontTracking {
|
|
|
12
13
|
/** The runs that are this author's own insertion: Word changes those in place, with no w:rPrChange. */
|
|
13
14
|
ownInsertions: ReadonlySet<object>;
|
|
14
15
|
}
|
|
16
|
+
/** A run's formatting as a `Font` reads it: its properties, and its document font's name. */
|
|
17
|
+
export interface RunReading {
|
|
18
|
+
formatting: RunFormatting;
|
|
19
|
+
name: string;
|
|
20
|
+
}
|
|
21
|
+
/** A paragraph mark's run properties as a `Font` reads them: `w:pPr/w:rPr` without the mark's own revisions. */
|
|
22
|
+
export declare function markHolderOf(p: wml.P): RPrHolder;
|
|
23
|
+
/**
|
|
24
|
+
* A run's reading from its properties: in the effective view a theme colour the colour Word draws, given the
|
|
25
|
+
* document's theme colours (`w:themeColor`, tint and shade, over the `w:val` beside it, which is a cache: check 53,
|
|
26
|
+
* CR-008 phase 2), and an automatic colour (`w:val="auto"`, or none) `#000000`, as Office JS reads them (CR-002
|
|
27
|
+
* section 59); and `name` its document font where one is given.
|
|
28
|
+
*/
|
|
29
|
+
export declare function readingOf(rPr: wml.RPr | undefined, effective: boolean, name?: string, themeColors?: ThemeColors): RunReading;
|
|
15
30
|
/**
|
|
16
31
|
* A subset of Office JS `Word.Font` over the run properties (`w:rPr`) of one or more runs.
|
|
17
32
|
*
|
|
18
|
-
* **Reads report effective formatting** (CR-001 Phase B step 2):
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
33
|
+
* **Reads report effective formatting** (CR-001 Phase B step 2): each run in scope resolved through
|
|
34
|
+
* the document defaults, the paragraph style and the character style. Pass an `effective` supplier
|
|
35
|
+
* for that; without one the view reads direct formatting, which is what `getFont({ direct: true })`
|
|
36
|
+
* asks for. Where the runs differ a property reads as Office JS reads it (Word 365, checks 52 and 53;
|
|
37
|
+
* CR-002 section 59): `null`, `''` for the name, the colour and the highlight, and `Mixed` for the
|
|
38
|
+
* underline. Office JS's own types say `boolean` and `number` there, and so do these. With no run in
|
|
39
|
+
* scope, a paragraph with no text reads its mark's run properties (`w:pPr/w:rPr`, check 52 case 60),
|
|
40
|
+
* and an empty range its paragraph's style. An automatic colour (`w:val="auto"`, or none) reads
|
|
41
|
+
* `#000000` in the effective view, and a theme colour the colour Word draws (CR-008 phase 2), as Office JS reads them
|
|
42
|
+
* (check 53).
|
|
22
43
|
*
|
|
23
44
|
* **Writes are always direct**, and apply to every run in scope. Both directions go through
|
|
24
45
|
* the objects package's one name-to-`w:rPr` mapping (`builders/wml` applyRunOptions /
|
|
@@ -31,27 +52,40 @@ export interface FontTracking {
|
|
|
31
52
|
* package whose selector has not been built yet falls back to that.
|
|
32
53
|
*/
|
|
33
54
|
export declare class Font {
|
|
55
|
+
/** The runs in scope; `write` is true for a write, which may split runs to have them, and false for a read, which must not. */
|
|
34
56
|
private readonly holders;
|
|
35
57
|
/** The change tracker and this author's own insertions, when the package is tracking changes. */
|
|
36
58
|
private readonly tracking?;
|
|
37
|
-
/** The effective `w:rPr` of
|
|
59
|
+
/** The effective `w:rPr` of a run in scope; absent for a direct-formatting view. */
|
|
38
60
|
private readonly effective?;
|
|
39
61
|
/** The document font of that effective `w:rPr` with its theme reference resolved
|
|
40
62
|
* (`RunFontSelector.asciiFontName`); absent for a direct-formatting view, and undefined
|
|
41
63
|
* where the package has no selector yet. */
|
|
42
64
|
private readonly asciiFontName?;
|
|
43
|
-
|
|
65
|
+
/** The paragraph mark, read where no run is in scope: a paragraph with no text (CR-002 section 59). */
|
|
66
|
+
private readonly mark?;
|
|
67
|
+
/** The document's theme colours, which a theme colour is read through (CR-008 phase 2); absent for a direct view. */
|
|
68
|
+
private readonly themeColors?;
|
|
69
|
+
constructor(
|
|
70
|
+
/** The runs in scope; `write` is true for a write, which may split runs to have them, and false for a read, which must not. */
|
|
71
|
+
holders: (write: boolean) => RPrHolder[],
|
|
44
72
|
/** The change tracker and this author's own insertions, when the package is tracking changes. */
|
|
45
73
|
tracking?: (() => FontTracking | undefined) | undefined,
|
|
46
|
-
/** The effective `w:rPr` of
|
|
74
|
+
/** The effective `w:rPr` of a run in scope; absent for a direct-formatting view. */
|
|
47
75
|
effective?: ((rPr: wml.RPr | undefined) => wml.RPr | undefined) | undefined,
|
|
48
76
|
/** The document font of that effective `w:rPr` with its theme reference resolved
|
|
49
77
|
* (`RunFontSelector.asciiFontName`); absent for a direct-formatting view, and undefined
|
|
50
78
|
* where the package has no selector yet. */
|
|
51
|
-
asciiFontName?: ((rPr: wml.RPr | undefined) => string | undefined) | undefined
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
79
|
+
asciiFontName?: ((rPr: wml.RPr | undefined) => string | undefined) | undefined,
|
|
80
|
+
/** The paragraph mark, read where no run is in scope: a paragraph with no text (CR-002 section 59). */
|
|
81
|
+
mark?: (() => RPrHolder | undefined) | undefined,
|
|
82
|
+
/** The document's theme colours, which a theme colour is read through (CR-008 phase 2); absent for a direct view. */
|
|
83
|
+
themeColors?: (() => ThemeColors | undefined) | undefined);
|
|
84
|
+
/** Each run in scope, read; the mark's properties where there is none, else the paragraph's style's. */
|
|
85
|
+
protected readings(): RunReading[];
|
|
86
|
+
/** A property every reading agrees on, else `null` (also where nothing is read). */
|
|
87
|
+
private value;
|
|
88
|
+
protected apply(opts: RunOptions): void;
|
|
55
89
|
get bold(): boolean;
|
|
56
90
|
set bold(v: boolean);
|
|
57
91
|
get italic(): boolean;
|
|
@@ -69,18 +103,34 @@ export declare class Font {
|
|
|
69
103
|
/**
|
|
70
104
|
* The document font formatting this run's Latin text: `w:rFonts/@w:ascii` of the effective
|
|
71
105
|
* properties, the face `w:asciiTheme` names, else `w:hAnsi`, else the document default
|
|
72
|
-
* (docx4j `RunFontSelector.asciiFontName`). ''
|
|
73
|
-
* `w:ascii`, or where the package's `RunFontSelector` has not been built yet.
|
|
106
|
+
* (docx4j `RunFontSelector.asciiFontName`). '' where the runs differ, in a direct-formatting
|
|
107
|
+
* view with no `w:ascii`, or where the package's `RunFontSelector` has not been built yet.
|
|
74
108
|
*/
|
|
75
109
|
get name(): string;
|
|
76
110
|
set name(v: string);
|
|
77
|
-
/** Size in points (w:sz is half-points); 0 only in a direct-formatting view with no w:sz. */
|
|
111
|
+
/** Size in points (w:sz is half-points); 0 only in a direct-formatting view with no w:sz; `null` where the runs differ. */
|
|
78
112
|
get size(): number;
|
|
79
113
|
set size(v: number);
|
|
80
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* '#RRGGBB': in the effective view the colour Word draws, so a theme colour (`w:themeColor`, with its tint or shade)
|
|
116
|
+
* through the document's theme, as Office JS reads it (check 53; CR-008 phase 2), and `#000000` for automatic; in
|
|
117
|
+
* the direct view `w:val` as written, '' when not set; the raw value where it is not a hex triple and no theme
|
|
118
|
+
* colour applies; '' where the runs differ.
|
|
119
|
+
*/
|
|
81
120
|
get color(): string;
|
|
82
121
|
set color(v: string);
|
|
83
|
-
/** '#RRGGBB' of the highlight, or null when there is none. */
|
|
122
|
+
/** '#RRGGBB' of the highlight, or null when there is none; '' where the runs differ. */
|
|
84
123
|
get highlightColor(): string | null;
|
|
85
124
|
set highlightColor(v: string | null);
|
|
86
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* The `Font` of a range across paragraphs (CR-014): each run read in its own paragraph, as `Font` reads them. A write
|
|
128
|
+
* goes to `write` (phase 2: every run and mark in the range, as Word formats them).
|
|
129
|
+
*/
|
|
130
|
+
export declare class MixedFont extends Font {
|
|
131
|
+
private readonly reads;
|
|
132
|
+
private readonly write;
|
|
133
|
+
constructor(reads: () => RunReading[], write: (opts: RunOptions) => void);
|
|
134
|
+
protected readings(): RunReading[];
|
|
135
|
+
protected apply(opts: RunOptions): void;
|
|
136
|
+
}
|
|
@@ -1,11 +1,47 @@
|
|
|
1
1
|
import { applyRunOptions, readRunOptions } from '@docx4j/generated-objects-ts/builders/wml';
|
|
2
|
+
import { WordColors } from '../color/WordColors.mjs';
|
|
3
|
+
/** A paragraph mark's run properties as a `Font` reads them: `w:pPr/w:rPr` without the mark's own revisions. */
|
|
4
|
+
export function markHolderOf(p) {
|
|
5
|
+
var _a;
|
|
6
|
+
const rPr = (_a = p.pPr) === null || _a === void 0 ? void 0 : _a.rPr;
|
|
7
|
+
if (!rPr)
|
|
8
|
+
return {};
|
|
9
|
+
const { ins: _ins, del: _del, moveFrom: _from, moveTo: _to, rPrChange: _change, ...rest } = rPr;
|
|
10
|
+
return { rPr: { ...rest, TYPE_NAME: 'org_docx4j_wml.RPr' } };
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A run's reading from its properties: in the effective view a theme colour the colour Word draws, given the
|
|
14
|
+
* document's theme colours (`w:themeColor`, tint and shade, over the `w:val` beside it, which is a cache: check 53,
|
|
15
|
+
* CR-008 phase 2), and an automatic colour (`w:val="auto"`, or none) `#000000`, as Office JS reads them (CR-002
|
|
16
|
+
* section 59); and `name` its document font where one is given.
|
|
17
|
+
*/
|
|
18
|
+
export function readingOf(rPr, effective, name, themeColors) {
|
|
19
|
+
var _a;
|
|
20
|
+
const formatting = readRunOptions(rPr);
|
|
21
|
+
if (effective) {
|
|
22
|
+
const themed = (_a = rPr === null || rPr === void 0 ? void 0 : rPr.color) === null || _a === void 0 ? void 0 : _a.themeColor;
|
|
23
|
+
const drawn = themed === undefined || themed === null || themed === 'none' || themeColors === undefined
|
|
24
|
+
? undefined : WordColors.of(rPr.color, themeColors);
|
|
25
|
+
if (drawn !== undefined)
|
|
26
|
+
formatting.color = `#${drawn.toHex()}`;
|
|
27
|
+
else if (formatting.color === '' || formatting.color === 'auto')
|
|
28
|
+
formatting.color = '#000000';
|
|
29
|
+
}
|
|
30
|
+
return { formatting, name: name !== null && name !== void 0 ? name : formatting.name };
|
|
31
|
+
}
|
|
2
32
|
/**
|
|
3
33
|
* A subset of Office JS `Word.Font` over the run properties (`w:rPr`) of one or more runs.
|
|
4
34
|
*
|
|
5
|
-
* **Reads report effective formatting** (CR-001 Phase B step 2):
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
35
|
+
* **Reads report effective formatting** (CR-001 Phase B step 2): each run in scope resolved through
|
|
36
|
+
* the document defaults, the paragraph style and the character style. Pass an `effective` supplier
|
|
37
|
+
* for that; without one the view reads direct formatting, which is what `getFont({ direct: true })`
|
|
38
|
+
* asks for. Where the runs differ a property reads as Office JS reads it (Word 365, checks 52 and 53;
|
|
39
|
+
* CR-002 section 59): `null`, `''` for the name, the colour and the highlight, and `Mixed` for the
|
|
40
|
+
* underline. Office JS's own types say `boolean` and `number` there, and so do these. With no run in
|
|
41
|
+
* scope, a paragraph with no text reads its mark's run properties (`w:pPr/w:rPr`, check 52 case 60),
|
|
42
|
+
* and an empty range its paragraph's style. An automatic colour (`w:val="auto"`, or none) reads
|
|
43
|
+
* `#000000` in the effective view, and a theme colour the colour Word draws (CR-008 phase 2), as Office JS reads them
|
|
44
|
+
* (check 53).
|
|
9
45
|
*
|
|
10
46
|
* **Writes are always direct**, and apply to every run in scope. Both directions go through
|
|
11
47
|
* the objects package's one name-to-`w:rPr` mapping (`builders/wml` applyRunOptions /
|
|
@@ -18,32 +54,52 @@ import { applyRunOptions, readRunOptions } from '@docx4j/generated-objects-ts/bu
|
|
|
18
54
|
* package whose selector has not been built yet falls back to that.
|
|
19
55
|
*/
|
|
20
56
|
export class Font {
|
|
21
|
-
constructor(
|
|
57
|
+
constructor(
|
|
58
|
+
/** The runs in scope; `write` is true for a write, which may split runs to have them, and false for a read, which must not. */
|
|
59
|
+
holders,
|
|
22
60
|
/** The change tracker and this author's own insertions, when the package is tracking changes. */
|
|
23
61
|
tracking,
|
|
24
|
-
/** The effective `w:rPr` of
|
|
62
|
+
/** The effective `w:rPr` of a run in scope; absent for a direct-formatting view. */
|
|
25
63
|
effective,
|
|
26
64
|
/** The document font of that effective `w:rPr` with its theme reference resolved
|
|
27
65
|
* (`RunFontSelector.asciiFontName`); absent for a direct-formatting view, and undefined
|
|
28
66
|
* where the package has no selector yet. */
|
|
29
|
-
asciiFontName
|
|
67
|
+
asciiFontName,
|
|
68
|
+
/** The paragraph mark, read where no run is in scope: a paragraph with no text (CR-002 section 59). */
|
|
69
|
+
mark,
|
|
70
|
+
/** The document's theme colours, which a theme colour is read through (CR-008 phase 2); absent for a direct view. */
|
|
71
|
+
themeColors) {
|
|
30
72
|
this.holders = holders;
|
|
31
73
|
this.tracking = tracking;
|
|
32
74
|
this.effective = effective;
|
|
33
75
|
this.asciiFontName = asciiFontName;
|
|
76
|
+
this.mark = mark;
|
|
77
|
+
this.themeColors = themeColors;
|
|
34
78
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
79
|
+
/** Each run in scope, read; the mark's properties where there is none, else the paragraph's style's. */
|
|
80
|
+
readings() {
|
|
81
|
+
var _a, _b, _c;
|
|
82
|
+
let holders = this.holders(false);
|
|
83
|
+
if (holders.length === 0)
|
|
84
|
+
holders = [(_b = (_a = this.mark) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : {}];
|
|
85
|
+
const themeColors = this.effective ? (_c = this.themeColors) === null || _c === void 0 ? void 0 : _c.call(this) : undefined;
|
|
86
|
+
return holders.map((h) => {
|
|
87
|
+
var _a;
|
|
88
|
+
const rPr = this.effective ? this.effective(h.rPr) : h.rPr;
|
|
89
|
+
return readingOf(rPr, this.effective !== undefined, (_a = this.asciiFontName) === null || _a === void 0 ? void 0 : _a.call(this, rPr), themeColors);
|
|
90
|
+
});
|
|
39
91
|
}
|
|
40
|
-
read
|
|
41
|
-
|
|
92
|
+
/** A property every reading agrees on, else `null` (also where nothing is read). */
|
|
93
|
+
value(key) {
|
|
94
|
+
const all = this.readings().map((r) => r.formatting[key]);
|
|
95
|
+
if (all.length === 0)
|
|
96
|
+
return null;
|
|
97
|
+
return all.every((v) => v === all[0]) ? all[0] : null;
|
|
42
98
|
}
|
|
43
99
|
apply(opts) {
|
|
44
100
|
var _a, _b;
|
|
45
101
|
const tracking = (_a = this.tracking) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
46
|
-
for (const h of this.holders()) {
|
|
102
|
+
for (const h of this.holders(true)) {
|
|
47
103
|
(_b = h.rPr) !== null && _b !== void 0 ? _b : (h.rPr = { TYPE_NAME: 'org_docx4j_wml.RPr' });
|
|
48
104
|
// the properties as they are now become w:rPrChange, unless this run is our own insertion
|
|
49
105
|
if (tracking && !tracking.ownInsertions.has(h))
|
|
@@ -53,42 +109,65 @@ export class Font {
|
|
|
53
109
|
tracking.tracker.settleRPrChange(h);
|
|
54
110
|
}
|
|
55
111
|
}
|
|
56
|
-
get bold() { return this.
|
|
112
|
+
get bold() { return this.value('bold'); }
|
|
57
113
|
set bold(v) { this.apply({ bold: v }); }
|
|
58
|
-
get italic() { return this.
|
|
114
|
+
get italic() { return this.value('italic'); }
|
|
59
115
|
set italic(v) { this.apply({ italic: v }); }
|
|
60
|
-
get underline() { return this.
|
|
116
|
+
get underline() { var _a; return ((_a = this.value('underline')) !== null && _a !== void 0 ? _a : 'Mixed'); }
|
|
61
117
|
set underline(v) { this.apply({ underline: v }); }
|
|
62
|
-
get strikeThrough() { return this.
|
|
118
|
+
get strikeThrough() { return this.value('strikeThrough'); }
|
|
63
119
|
set strikeThrough(v) { this.apply({ strikeThrough: v }); }
|
|
64
|
-
get doubleStrikeThrough() { return this.
|
|
120
|
+
get doubleStrikeThrough() { return this.value('doubleStrikeThrough'); }
|
|
65
121
|
set doubleStrikeThrough(v) { this.apply({ doubleStrikeThrough: v }); }
|
|
66
|
-
get subscript() { return this.
|
|
122
|
+
get subscript() { return this.value('subscript'); }
|
|
67
123
|
set subscript(v) { this.apply({ subscript: v }); }
|
|
68
|
-
get superscript() { return this.
|
|
124
|
+
get superscript() { return this.value('superscript'); }
|
|
69
125
|
set superscript(v) { this.apply({ superscript: v }); }
|
|
70
126
|
/**
|
|
71
127
|
* The document font formatting this run's Latin text: `w:rFonts/@w:ascii` of the effective
|
|
72
128
|
* properties, the face `w:asciiTheme` names, else `w:hAnsi`, else the document default
|
|
73
|
-
* (docx4j `RunFontSelector.asciiFontName`). ''
|
|
74
|
-
* `w:ascii`, or where the package's `RunFontSelector` has not been built yet.
|
|
129
|
+
* (docx4j `RunFontSelector.asciiFontName`). '' where the runs differ, in a direct-formatting
|
|
130
|
+
* view with no `w:ascii`, or where the package's `RunFontSelector` has not been built yet.
|
|
75
131
|
*/
|
|
76
132
|
get name() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (resolved !== undefined)
|
|
80
|
-
return resolved;
|
|
81
|
-
}
|
|
82
|
-
return this.read().name;
|
|
133
|
+
const all = this.readings().map((r) => r.name);
|
|
134
|
+
return all.length > 0 && all.every((n) => n === all[0]) ? all[0] : '';
|
|
83
135
|
}
|
|
84
136
|
set name(v) { this.apply({ name: v }); }
|
|
85
|
-
/** Size in points (w:sz is half-points); 0 only in a direct-formatting view with no w:sz. */
|
|
86
|
-
get size() { return this.
|
|
137
|
+
/** Size in points (w:sz is half-points); 0 only in a direct-formatting view with no w:sz; `null` where the runs differ. */
|
|
138
|
+
get size() { return this.value('size'); }
|
|
87
139
|
set size(v) { this.apply({ size: v }); }
|
|
88
|
-
/**
|
|
89
|
-
|
|
140
|
+
/**
|
|
141
|
+
* '#RRGGBB': in the effective view the colour Word draws, so a theme colour (`w:themeColor`, with its tint or shade)
|
|
142
|
+
* through the document's theme, as Office JS reads it (check 53; CR-008 phase 2), and `#000000` for automatic; in
|
|
143
|
+
* the direct view `w:val` as written, '' when not set; the raw value where it is not a hex triple and no theme
|
|
144
|
+
* colour applies; '' where the runs differ.
|
|
145
|
+
*/
|
|
146
|
+
get color() { var _a; return ((_a = this.value('color')) !== null && _a !== void 0 ? _a : ''); }
|
|
90
147
|
set color(v) { this.apply({ color: v }); }
|
|
91
|
-
/** '#RRGGBB' of the highlight, or null when there is none. */
|
|
92
|
-
get highlightColor() {
|
|
148
|
+
/** '#RRGGBB' of the highlight, or null when there is none; '' where the runs differ. */
|
|
149
|
+
get highlightColor() {
|
|
150
|
+
const all = this.readings().map((r) => r.formatting.highlightColor);
|
|
151
|
+
if (all.length === 0)
|
|
152
|
+
return null;
|
|
153
|
+
return all.every((v) => v === all[0]) ? all[0] : '';
|
|
154
|
+
}
|
|
93
155
|
set highlightColor(v) { this.apply({ highlightColor: v }); }
|
|
94
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* The `Font` of a range across paragraphs (CR-014): each run read in its own paragraph, as `Font` reads them. A write
|
|
159
|
+
* goes to `write` (phase 2: every run and mark in the range, as Word formats them).
|
|
160
|
+
*/
|
|
161
|
+
export class MixedFont extends Font {
|
|
162
|
+
constructor(reads, write) {
|
|
163
|
+
super(() => []);
|
|
164
|
+
this.reads = reads;
|
|
165
|
+
this.write = write;
|
|
166
|
+
}
|
|
167
|
+
readings() {
|
|
168
|
+
return this.reads();
|
|
169
|
+
}
|
|
170
|
+
apply(opts) {
|
|
171
|
+
this.write(opts);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type * as wml from '@docx4j/generated-objects-ts/modules/org_docx4j_wml';
|
|
2
|
+
import type * as dml from '@docx4j/generated-objects-ts/modules/org_docx4j_dml';
|
|
2
3
|
import type * as wp from '@docx4j/generated-objects-ts/modules/org_docx4j_dml_wordprocessingDrawing';
|
|
3
4
|
import { IMAGE_CONTENT_TYPES_BY_EXTENSION } from '../../opc/ContentTypes.mjs';
|
|
4
5
|
import { ImagePart } from '../../parts/BinaryPart.mjs';
|
|
@@ -70,11 +71,42 @@ export declare function addImagePart(source: Part, base64: string): NewImagePart
|
|
|
70
71
|
* that shows it. docx4j: `BinaryPartAbstractImage.createImagePart` then `createImageInline`.
|
|
71
72
|
*/
|
|
72
73
|
export declare function addImage(source: Part, base64: string, scope: object, maxCx: number | undefined, options?: InlinePictureOptions): NewPicture;
|
|
74
|
+
/**
|
|
75
|
+
* The run showing an image already related from the part as `relId`, an inline picture `cx` by `cy` EMU, its drawing id
|
|
76
|
+
* the next free one in `scope` and named `Picture <id>`, as `addImage` names one.
|
|
77
|
+
*/
|
|
78
|
+
export declare function imageRunOf(relId: string, scope: object, cx: number, cy: number): Element<wml.R>;
|
|
73
79
|
/** The writable width of a section in EMU (page width less the margins), for scaling. */
|
|
74
80
|
export declare function writableWidthEmu(container: object): number | undefined;
|
|
81
|
+
/** The `asvg:svgBlip` in a blip's `a:extLst`, if any: an SVG picture's SVG (CR-002 section 52). */
|
|
82
|
+
export declare function svgBlipOf(blip: dml.CTBlip | undefined): {
|
|
83
|
+
embed?: string;
|
|
84
|
+
} | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* Points a blip at a new image the way Word's own picture binding does (test/README.md checks 46 and
|
|
87
|
+
* 47; CR-002 section 52). The blip's effects and other extensions stay.
|
|
88
|
+
* - A raster image goes in `r:embed`, and an `asvg:svgBlip` is taken away. Left in place, Word would go
|
|
89
|
+
* on drawing its old SVG, and would replace the new image with a PNG of that SVG when it saves.
|
|
90
|
+
* - An SVG goes under the `asvg:svgBlip`, and `r:embed` is taken away. Word puts a PNG of the SVG it
|
|
91
|
+
* makes itself in `r:embed`, which this package cannot make, and Word 365 draws the SVG without one.
|
|
92
|
+
* `r:link` is left as it was.
|
|
93
|
+
*/
|
|
94
|
+
export declare function setBlipImage(blip: dml.CTBlip, relId: string, svg: boolean): void;
|
|
95
|
+
/**
|
|
96
|
+
* The inline pictures a run's item holds: the item itself when it is a `w:drawing` whose `wp:inline`
|
|
97
|
+
* holds a `pic:pic`, and those in a kept `mc:AlternateContent`'s selected branch (`selectedBranchOf`,
|
|
98
|
+
* CR-010 phase 3). A drawing of anything else, such as a chart, a text box, a group or SmartArt, is no
|
|
99
|
+
* inline picture: Office JS lists none for an inline text box (CR-010 section 12.6, test/README.md
|
|
100
|
+
* check 42).
|
|
101
|
+
*/
|
|
102
|
+
export declare function picturesIn(item: Element): Element<wml.Drawing>[];
|
|
75
103
|
/**
|
|
76
|
-
* A subset of Office JS `Word.InlinePicture` over a `w:drawing` holding a `wp:inline
|
|
77
|
-
* the drawing, the run it is in and the paragraph. Sizes are points, as Office JS reports them.
|
|
104
|
+
* A subset of Office JS `Word.InlinePicture` over a `w:drawing` holding a `wp:inline` with a `pic:pic`.
|
|
105
|
+
* A view: the drawing, the run it is in and the paragraph. Sizes are points, as Office JS reports them.
|
|
106
|
+
*
|
|
107
|
+
* A picture in a kept `mc:AlternateContent`'s selected branch has the element as its `holder`. Reads and
|
|
108
|
+
* the setters are the selected branch's drawing; `delete` removes the element whole, every branch with
|
|
109
|
+
* it (CR-010 phase 3).
|
|
78
110
|
*/
|
|
79
111
|
export declare class InlinePicture {
|
|
80
112
|
/** The `w:drawing` element pair. */
|
|
@@ -82,11 +114,15 @@ export declare class InlinePicture {
|
|
|
82
114
|
/** The run holding the drawing, and the array holding the run. */
|
|
83
115
|
readonly run: Element<wml.R>;
|
|
84
116
|
readonly paragraph: Paragraph;
|
|
117
|
+
/** The run's item the drawing stands in, where that is not the drawing: a kept `mc:AlternateContent`. */
|
|
118
|
+
readonly holder?: Element | undefined;
|
|
85
119
|
constructor(
|
|
86
120
|
/** The `w:drawing` element pair. */
|
|
87
121
|
element: Element<wml.Drawing>,
|
|
88
122
|
/** The run holding the drawing, and the array holding the run. */
|
|
89
|
-
run: Element<wml.R>, paragraph: Paragraph
|
|
123
|
+
run: Element<wml.R>, paragraph: Paragraph,
|
|
124
|
+
/** The run's item the drawing stands in, where that is not the drawing: a kept `mc:AlternateContent`. */
|
|
125
|
+
holder?: Element | undefined);
|
|
90
126
|
/** The wp:inline; a floating picture (wp:anchor) is not an InlinePicture, and throws. */
|
|
91
127
|
get inline(): wp.Inline;
|
|
92
128
|
/** Width in points, as Office JS. */
|
|
@@ -100,19 +136,58 @@ export declare class InlinePicture {
|
|
|
100
136
|
/** wp:docPr/@title (typed since objects 0.1.3; before that the attribute was not marshalled, CR-002 section 8). */
|
|
101
137
|
get altTextTitle(): string;
|
|
102
138
|
set altTextTitle(text: string);
|
|
103
|
-
/**
|
|
139
|
+
/**
|
|
140
|
+
* The kind of image, from the content type of the part `getBase64` reads: `Svg` for an SVG picture
|
|
141
|
+
* (`svgImagePart`), else the `a:blip`'s part's. Office JS gives `null` for an SVG picture, though its
|
|
142
|
+
* typings declare the property non-null and `Word.ImageFormat` has `Svg` (test/README.md check 45);
|
|
143
|
+
* this package gives `Svg`, a departure (CR-002 section 52).
|
|
144
|
+
*/
|
|
104
145
|
get imageFormat(): ImageFormat;
|
|
105
146
|
/** The relationship id of the embedded image (r:embed), if any (extension). */
|
|
106
147
|
get relId(): string | undefined;
|
|
107
|
-
/**
|
|
148
|
+
/**
|
|
149
|
+
* The relationship id of the SVG the picture embeds beside its image, if any (extension): the
|
|
150
|
+
* `r:embed` of an `asvg:svgBlip` in the `a:blip`'s `a:extLst`, as Office 2016 and later write an SVG
|
|
151
|
+
* picture, with the `a:blip`'s own image a PNG of it for readers that don't understand SVG.
|
|
152
|
+
*/
|
|
153
|
+
get svgRelId(): string | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* The image's bytes as base64 (Office JS getBase64ImageSrc). For an SVG picture, the SVG
|
|
156
|
+
* (`svgImagePart`), as Office JS gives it (test/README.md check 43); else the `a:blip`'s image.
|
|
157
|
+
*/
|
|
108
158
|
getBase64(): Promise<string>;
|
|
109
159
|
/** Office JS's name for `getBase64()`. */
|
|
110
160
|
getBase64ImageSrc(): Promise<string>;
|
|
111
|
-
/** The image part this picture embeds (extension). */
|
|
161
|
+
/** The image part this picture embeds: the `a:blip`'s, which is an SVG picture's PNG (extension). */
|
|
112
162
|
imagePart(): ImagePart | undefined;
|
|
113
|
-
/**
|
|
163
|
+
/** The SVG part an SVG picture embeds beside its image (`svgRelId`), if any (extension). */
|
|
164
|
+
svgImagePart(): ImagePart | undefined;
|
|
165
|
+
private partFor;
|
|
166
|
+
/**
|
|
167
|
+
* Removes the picture; the run goes too when the picture was all it held. A picture in a kept
|
|
168
|
+
* `mc:AlternateContent` takes the element with it, every branch (`holder`).
|
|
169
|
+
*
|
|
170
|
+
* While the package tracks changes it is marked deleted instead: its run goes into a `w:del`, and
|
|
171
|
+
* when the run held more than the picture, the picture is first given a run of its own with the
|
|
172
|
+
* same properties, so the deletion holds it alone. Accepting the deletion then takes it, and its
|
|
173
|
+
* image part with it (CR-002 section 46). A picture its author inserted under tracking is taken
|
|
174
|
+
* back, as `Paragraph.delete` takes back its own text, and one inside a deletion is refused.
|
|
175
|
+
*
|
|
176
|
+
* A picture removed outright (tracking off, or taken back) queues its image relationship on the
|
|
177
|
+
* package. On save the relationship goes if nothing then references it, and the image part with it
|
|
178
|
+
* when nothing else targets it. Waiting for the save lets a picture cut and pasted back keep its
|
|
179
|
+
* image.
|
|
180
|
+
*/
|
|
114
181
|
delete(): void;
|
|
182
|
+
/** The picture's run in a `w:del`, the picture split into a run of its own when the run held more. */
|
|
183
|
+
private markDeleted;
|
|
115
184
|
private pic;
|
|
185
|
+
/**
|
|
186
|
+
* Refuses a write to a picture in a paragraph in a branch of a kept block-, row- or cell-level
|
|
187
|
+
* `mc:AlternateContent` (CR-013 D4). A picture in a run-level element's branch is the run's own, and
|
|
188
|
+
* deleting it removes the element (CR-010 phase 3).
|
|
189
|
+
*/
|
|
190
|
+
private assertWritable;
|
|
116
191
|
private resize;
|
|
117
192
|
}
|
|
118
193
|
export { IMAGE_CONTENT_TYPES_BY_EXTENSION };
|