@docx4j/core-ts 0.5.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 +32 -4
- package/dist/html/convert.mjs +2 -1
- 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 +145 -23
- package/dist/model/content/Body.mjs +509 -141
- package/dist/model/content/Comment.d.mts +21 -3
- package/dist/model/content/Comment.mjs +195 -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 +11 -0
- package/dist/model/content/InlinePicture.mjs +21 -1
- package/dist/model/content/List.mjs +3 -0
- package/dist/model/content/Paragraph.d.mts +189 -13
- package/dist/model/content/Paragraph.mjs +870 -74
- package/dist/model/content/Range.d.mts +227 -12
- package/dist/model/content/Range.mjs +785 -59
- 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 +172 -13
- package/dist/model/content/TrackedChange.mjs +728 -167
- 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/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 +171 -22
- package/dist/model/content/tree.mjs +329 -53
- 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 +4 -3
- package/dist/model/customxml/pictures.mjs +18 -6
- package/dist/model/customxml/xhtml.mjs +8 -2
- 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/properties/PropertyResolver.d.mts +60 -1
- package/dist/model/properties/PropertyResolver.mjs +115 -2
- package/dist/model/properties/catalogue.d.mts +19 -5
- package/dist/model/properties/catalogue.mjs +41 -15
- package/dist/model/properties/log.d.mts +1 -1
- package/dist/model/properties/log.mjs +5 -5
- package/dist/model/properties/table.mjs +4 -2
- 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/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 +1 -1
- package/dist/opc/mce/preprocessor.d.mts +28 -3
- package/dist/opc/mce/preprocessor.mjs +4 -4
- package/dist/opc/mce/understood.d.mts +30 -6
- package/dist/opc/mce/understood.mjs +37 -7
- package/dist/packages/OpcPackage.d.mts +13 -0
- package/dist/packages/OpcPackage.mjs +1 -0
- package/dist/packages/WordprocessingMLPackage.d.mts +45 -8
- package/dist/packages/WordprocessingMLPackage.mjs +155 -20
- package/dist/parts/DefaultXmlPart.mjs +2 -2
- package/dist/parts/Part.d.mts +10 -2
- package/dist/parts/XmlPart.d.mts +12 -30
- package/dist/parts/XmlPart.mjs +44 -93
- 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
|
+
}
|
|
@@ -71,6 +71,11 @@ export declare function addImagePart(source: Part, base64: string): NewImagePart
|
|
|
71
71
|
* that shows it. docx4j: `BinaryPartAbstractImage.createImagePart` then `createImageInline`.
|
|
72
72
|
*/
|
|
73
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>;
|
|
74
79
|
/** The writable width of a section in EMU (page width less the margins), for scaling. */
|
|
75
80
|
export declare function writableWidthEmu(container: object): number | undefined;
|
|
76
81
|
/** The `asvg:svgBlip` in a blip's `a:extLst`, if any: an SVG picture's SVG (CR-002 section 52). */
|
|
@@ -177,6 +182,12 @@ export declare class InlinePicture {
|
|
|
177
182
|
/** The picture's run in a `w:del`, the picture split into a run of its own when the run held more. */
|
|
178
183
|
private markDeleted;
|
|
179
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;
|
|
180
191
|
private resize;
|
|
181
192
|
}
|
|
182
193
|
export { IMAGE_CONTENT_TYPES_BY_EXTENSION };
|
|
@@ -4,7 +4,7 @@ import { ContentTypes, IMAGE_CONTENT_TYPES_BY_EXTENSION } from '../../opc/Conten
|
|
|
4
4
|
import { base64Decode, base64Encode, decodeXmlText } from '../../xml/dom.mjs';
|
|
5
5
|
import { ImagePart } from '../../parts/BinaryPart.mjs';
|
|
6
6
|
import { PartName } from '../../opc/PartName.mjs';
|
|
7
|
-
import { find, runOf, linkParents, revisionKindOf, isElement, typeNameOf, isAlternateContent, selectedBranchOf } from './tree.mjs';
|
|
7
|
+
import { find, runOf, linkParents, revisionKindOf, isElement, typeNameOf, isAlternateContent, selectedBranchOf, assertOutsideBranch } from './tree.mjs';
|
|
8
8
|
import { copyRPr } from './tracking.mjs';
|
|
9
9
|
import { relationshipIdsIn, queueRelationshipRemovals } from './relationships.mjs';
|
|
10
10
|
/** English Metric Units per inch, and per twip (docx4j UnitsOfMeasurement). */
|
|
@@ -229,6 +229,14 @@ function freeImageName(pkg, extension) {
|
|
|
229
229
|
return name;
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* The run showing an image already related from the part as `relId`, an inline picture `cx` by `cy` EMU, its drawing id
|
|
234
|
+
* the next free one in `scope` and named `Picture <id>`, as `addImage` names one.
|
|
235
|
+
*/
|
|
236
|
+
export function imageRunOf(relId, scope, cx, cy) {
|
|
237
|
+
const id = nextDrawingId(scope);
|
|
238
|
+
return runOf([inlinePicture(relId, { cx, cy, id, name: `Picture ${id}`, descr: '' })]);
|
|
239
|
+
}
|
|
232
240
|
/** An id no other drawing in this part uses: wp:docPr and pic:cNvPr are the same type. */
|
|
233
241
|
function nextDrawingId(scope) {
|
|
234
242
|
let max = 0;
|
|
@@ -379,6 +387,7 @@ export class InlinePicture {
|
|
|
379
387
|
return (_a = this.inline.docPr.descr) !== null && _a !== void 0 ? _a : '';
|
|
380
388
|
}
|
|
381
389
|
set altTextDescription(text) {
|
|
390
|
+
this.assertWritable();
|
|
382
391
|
this.inline.docPr.descr = text;
|
|
383
392
|
const p = this.pic();
|
|
384
393
|
if (p)
|
|
@@ -390,6 +399,7 @@ export class InlinePicture {
|
|
|
390
399
|
return (_a = this.inline.docPr.title) !== null && _a !== void 0 ? _a : '';
|
|
391
400
|
}
|
|
392
401
|
set altTextTitle(text) {
|
|
402
|
+
this.assertWritable();
|
|
393
403
|
this.inline.docPr.title = text;
|
|
394
404
|
}
|
|
395
405
|
/**
|
|
@@ -466,6 +476,7 @@ export class InlinePicture {
|
|
|
466
476
|
*/
|
|
467
477
|
delete() {
|
|
468
478
|
var _a, _b;
|
|
479
|
+
this.assertWritable();
|
|
469
480
|
const place = placeOf(this.paragraph.p, this.run);
|
|
470
481
|
if (!place)
|
|
471
482
|
return;
|
|
@@ -530,8 +541,17 @@ export class InlinePicture {
|
|
|
530
541
|
const first = any === null || any === void 0 ? void 0 : any[0];
|
|
531
542
|
return first && typeof first === 'object' && 'value' in first ? first.value : undefined;
|
|
532
543
|
}
|
|
544
|
+
/**
|
|
545
|
+
* Refuses a write to a picture in a paragraph in a branch of a kept block-, row- or cell-level
|
|
546
|
+
* `mc:AlternateContent` (CR-013 D4). A picture in a run-level element's branch is the run's own, and
|
|
547
|
+
* deleting it removes the element (CR-010 phase 3).
|
|
548
|
+
*/
|
|
549
|
+
assertWritable() {
|
|
550
|
+
assertOutsideBranch(this.paragraph.p, 'InlinePicture', 'this picture');
|
|
551
|
+
}
|
|
533
552
|
resize(cx, cy) {
|
|
534
553
|
var _a, _b;
|
|
554
|
+
this.assertWritable();
|
|
535
555
|
const extent = this.inline.extent;
|
|
536
556
|
const ratio = extent.cy / extent.cx;
|
|
537
557
|
const w = cx !== null && cx !== void 0 ? cx : Math.max(1, Math.round(cy / ratio));
|
|
@@ -164,6 +164,9 @@ function nullObject(className) {
|
|
|
164
164
|
return () => ({ isNullObject: true });
|
|
165
165
|
if (prop === 'then')
|
|
166
166
|
return undefined;
|
|
167
|
+
// Office JS code loads a null object and syncs before reading isNullObject, as the shim's allows (CR-014 phase 1)
|
|
168
|
+
if (prop === 'load' || prop === 'track' || prop === 'untrack')
|
|
169
|
+
return () => proxy;
|
|
167
170
|
return fail(prop);
|
|
168
171
|
},
|
|
169
172
|
set(_target, prop) {
|