@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
|
@@ -10,7 +10,8 @@ export interface Bound {
|
|
|
10
10
|
* The tree object: for an element, what a walk of the typed tree would hand you at that path,
|
|
11
11
|
* never a `{ name, value }` wrapper; for an attribute or a text node, the object of the element
|
|
12
12
|
* that owns it. Undefined for an element the model does not build - a wildcard child is its own
|
|
13
|
-
* object, so
|
|
13
|
+
* object, and so is each element inside one (the node at the same place in the tree), so this is
|
|
14
|
+
* undefined only above the root or for a node the marshal did not report.
|
|
14
15
|
*/
|
|
15
16
|
object: unknown;
|
|
16
17
|
/** Set when an attribute was selected: its qualified name on `object`'s element. */
|
|
@@ -33,11 +33,12 @@ export async function bindSnapshot(element) {
|
|
|
33
33
|
/** Turns selected nodes into `Bound`s against a snapshot, with one path cache for them all. */
|
|
34
34
|
export function boundsOf(nodes, snapshot) {
|
|
35
35
|
const paths = new Paths();
|
|
36
|
+
const indexes = new Map();
|
|
36
37
|
return nodes.map((node) => {
|
|
37
38
|
const owner = owningElement(node);
|
|
38
39
|
const bound = {
|
|
39
40
|
node,
|
|
40
|
-
object: owner === undefined ? undefined : snapshot.objects
|
|
41
|
+
object: owner === undefined ? undefined : objectOf(owner, snapshot.objects, indexes),
|
|
41
42
|
path: paths.of(node),
|
|
42
43
|
};
|
|
43
44
|
if (node.nodeType === 2)
|
|
@@ -45,6 +46,49 @@ export function boundsOf(nodes, snapshot) {
|
|
|
45
46
|
return bound;
|
|
46
47
|
});
|
|
47
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* The tree object behind a snapshot element. The marshal reports a wildcard child's imported copy
|
|
51
|
+
* but nothing inside it, so an element there maps to the node at the same place under the original:
|
|
52
|
+
* the copy is deep, so the child positions agree. Since CR-010 phase 4 a kept branch's DrawingML is
|
|
53
|
+
* DOM from the branch down (an `xdr:graphicFrame`, a `p:sp`), and a selection lands inside it.
|
|
54
|
+
* Below a typed ancestor an unreported element stays unmapped.
|
|
55
|
+
*/
|
|
56
|
+
function objectOf(element, objects, indexes) {
|
|
57
|
+
if (objects.has(element))
|
|
58
|
+
return objects.get(element);
|
|
59
|
+
const path = [];
|
|
60
|
+
let at = element;
|
|
61
|
+
while (!objects.has(at)) {
|
|
62
|
+
path.push(at);
|
|
63
|
+
const parent = at.parentNode;
|
|
64
|
+
if (parent === null || parent.nodeType !== 1)
|
|
65
|
+
return undefined;
|
|
66
|
+
at = parent;
|
|
67
|
+
}
|
|
68
|
+
let node = objects.get(at);
|
|
69
|
+
if (!isNode(node))
|
|
70
|
+
return undefined;
|
|
71
|
+
for (let k = path.length - 1; k >= 0; k--) {
|
|
72
|
+
node = node.childNodes[childIndex(path[k], indexes)];
|
|
73
|
+
if (node === undefined || node === null)
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
return node;
|
|
77
|
+
}
|
|
78
|
+
/** A node's position among its parent's child nodes, each parent's counted once. */
|
|
79
|
+
function childIndex(node, indexes) {
|
|
80
|
+
var _a;
|
|
81
|
+
const parent = node.parentNode;
|
|
82
|
+
let index = indexes.get(parent);
|
|
83
|
+
if (index === undefined) {
|
|
84
|
+
index = new Map();
|
|
85
|
+
let i = 0;
|
|
86
|
+
for (let child = parent.firstChild; child; child = child.nextSibling)
|
|
87
|
+
index.set(child, i++);
|
|
88
|
+
indexes.set(parent, index);
|
|
89
|
+
}
|
|
90
|
+
return (_a = index.get(node)) !== null && _a !== void 0 ? _a : -1;
|
|
91
|
+
}
|
|
48
92
|
/**
|
|
49
93
|
* The element an XPath result belongs to: itself for an element, its owner for an attribute, its
|
|
50
94
|
* parent for a text, comment or processing-instruction node. A document node has none.
|
|
@@ -123,6 +167,9 @@ class Paths {
|
|
|
123
167
|
return (_b = positions.get(element)) !== null && _b !== void 0 ? _b : 0;
|
|
124
168
|
}
|
|
125
169
|
}
|
|
170
|
+
function isNode(node) {
|
|
171
|
+
return typeof node === 'object' && node !== null && typeof node.nodeType === 'number';
|
|
172
|
+
}
|
|
126
173
|
function isElement(node) {
|
|
127
174
|
return typeof node === 'object' && node !== null && node.nodeType === 1;
|
|
128
175
|
}
|
|
@@ -3,7 +3,7 @@ import type * as w15 from '@docx4j/generated-objects-ts/modules/org_docx4j_w15';
|
|
|
3
3
|
import type * as w16cid from '@docx4j/generated-objects-ts/modules/org_docx4j_w16cid';
|
|
4
4
|
import type { XmlCalendar } from '@docx4j/generated-objects-ts';
|
|
5
5
|
import type { XmlPart } from '../../parts/XmlPart.mjs';
|
|
6
|
-
import { type Element } from './tree.mjs';
|
|
6
|
+
import { type BranchMode, type HiddenRuns, type Element } from './tree.mjs';
|
|
7
7
|
import type { Body } from './Body.mjs';
|
|
8
8
|
import type { Paragraph } from './Paragraph.mjs';
|
|
9
9
|
import type { Range } from './Range.mjs';
|
|
@@ -92,6 +92,14 @@ export interface CommentParts {
|
|
|
92
92
|
ensureCommentsEx(): w15.CTCommentsEx;
|
|
93
93
|
/** Loads and creates the side parts the bookkeeping needs (w15, w16cid; w16cex only if present). */
|
|
94
94
|
ensureAll(): Promise<CommentParts>;
|
|
95
|
+
/** Loads the side parts the document has, creating none: what removing a comment needs. */
|
|
96
|
+
loadExisting(): Promise<CommentParts>;
|
|
97
|
+
/**
|
|
98
|
+
* Takes the comments part and its commentsExtended, commentsIds and commentsExtensible parts out of
|
|
99
|
+
* the package, with their relationships, and the people part too when `people` is true. A part
|
|
100
|
+
* another relationship still targets stays.
|
|
101
|
+
*/
|
|
102
|
+
drop(people: boolean): void;
|
|
95
103
|
}
|
|
96
104
|
/** How the content API reaches the comment parts; implemented and registered by `src/parts/wml/comments.mts`. */
|
|
97
105
|
export interface CommentPartsAccess {
|
|
@@ -130,11 +138,13 @@ export interface CommentMarker {
|
|
|
130
138
|
}
|
|
131
139
|
/**
|
|
132
140
|
* Every comment marker under a container (a body, a cell, a paragraph), in document order.
|
|
133
|
-
* Deleted content (`w:del`) is not entered, as the text model does not enter it either.
|
|
141
|
+
* Deleted content (`w:del`) is not entered, as the text model does not enter it either. A kept
|
|
142
|
+
* `mc:AlternateContent` at block, row or cell level is read as `mode` says (CR-013 phase 2): a reader's
|
|
143
|
+
* walk takes its selected branch, an edit's (`removeMarkers`, the ids) every branch.
|
|
134
144
|
*/
|
|
135
|
-
export declare function markersOf(container: object): CommentMarker[];
|
|
136
|
-
/** The markers of one paragraph, with their offsets in its text. */
|
|
137
|
-
export declare function markersOfParagraph(element: Element<wml.P>, container: Element[]): CommentMarker[];
|
|
145
|
+
export declare function markersOf(container: object, hidden?: (p: wml.P) => HiddenRuns, mode?: BranchMode): CommentMarker[];
|
|
146
|
+
/** The markers of one paragraph, with their offsets in its text (`Paragraph.text` where `hidden` is its `hiddenRuns()`). */
|
|
147
|
+
export declare function markersOfParagraph(element: Element<wml.P>, container: Element[], hidden?: HiddenRuns): CommentMarker[];
|
|
138
148
|
/** The comment ids under a container, in document order, first occurrence first. */
|
|
139
149
|
export declare function commentIdsOf(container: object): number[];
|
|
140
150
|
/** Removes every marker of a comment from a body, and the reference run when nothing is left in it. */
|
|
@@ -143,7 +153,11 @@ export declare function removeMarkers(container: object, id: number): void;
|
|
|
143
153
|
export declare function nextCommentId(comments: wml.Comments, container: object): number;
|
|
144
154
|
/** An 8 hex digit id, as Word writes `w14:paraId` and `w16cid:durableId` (never 0, high bit clear). */
|
|
145
155
|
export declare function randomHexId(taken: (id: string) => boolean): string;
|
|
146
|
-
/**
|
|
156
|
+
/**
|
|
157
|
+
* The `w14:paraId` of a comment's first paragraph: the key of its w15 and w16cid entries. A kept
|
|
158
|
+
* `mc:AlternateContent` before any paragraph is read in its selected branch, as Word reads it (CR-013
|
|
159
|
+
* phase 3; docx4j's `Trees.lastParaId` looks into the branch the same way).
|
|
160
|
+
*/
|
|
147
161
|
export declare function commentParaId(comment: wml.Comments.Comment): string | undefined;
|
|
148
162
|
/** True when a paragraph id is already used by a comment or by a paragraph of the document. */
|
|
149
163
|
export declare function paraIdTaken(parts: CommentParts, container: object, id: string): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Docx4JException } from '../../opc/exceptions.mjs';
|
|
2
|
-
import { typeNameOf, childrenOf,
|
|
2
|
+
import { typeNameOf, childrenOf, segmentsOf, rowsOf, cellsOf, branchesOf, selectedBranchOf, ALTERNATE_CONTENT } from './tree.mjs';
|
|
3
3
|
/** The style Word gives a comment's paragraphs. */
|
|
4
4
|
export const COMMENT_TEXT_STYLE = 'CommentText';
|
|
5
5
|
/** The character style of the annotation reference run, in the comment and in the body. */
|
|
@@ -34,64 +34,51 @@ const COMMENT_RANGE_END = 'org_docx4j_wml.CommentRangeEnd';
|
|
|
34
34
|
const COMMENT_REFERENCE = 'org_docx4j_wml.R.CommentReference';
|
|
35
35
|
/**
|
|
36
36
|
* Every comment marker under a container (a body, a cell, a paragraph), in document order.
|
|
37
|
-
* Deleted content (`w:del`) is not entered, as the text model does not enter it either.
|
|
37
|
+
* Deleted content (`w:del`) is not entered, as the text model does not enter it either. A kept
|
|
38
|
+
* `mc:AlternateContent` at block, row or cell level is read as `mode` says (CR-013 phase 2): a reader's
|
|
39
|
+
* walk takes its selected branch, an edit's (`removeMarkers`, the ids) every branch.
|
|
38
40
|
*/
|
|
39
|
-
export function markersOf(container) {
|
|
41
|
+
export function markersOf(container, hidden, mode = 'read') {
|
|
40
42
|
const out = [];
|
|
41
|
-
collect(out, container);
|
|
43
|
+
collect(out, container, undefined, hidden, mode);
|
|
42
44
|
return out;
|
|
43
45
|
}
|
|
44
|
-
/** The markers of one paragraph, with their offsets in its text. */
|
|
45
|
-
export function markersOfParagraph(element, container) {
|
|
46
|
+
/** The markers of one paragraph, with their offsets in its text (`Paragraph.text` where `hidden` is its `hiddenRuns()`). */
|
|
47
|
+
export function markersOfParagraph(element, container, hidden) {
|
|
46
48
|
const out = [];
|
|
47
|
-
collect(out, undefined, { element, container });
|
|
49
|
+
collect(out, undefined, { element, container }, hidden === undefined ? undefined : () => hidden);
|
|
48
50
|
return out;
|
|
49
51
|
}
|
|
50
|
-
|
|
52
|
+
/**
|
|
53
|
+
* The walk behind both. A paragraph's markers are found by the same walk as its text (`segmentsOf`, in
|
|
54
|
+
* the accepted view: a `w:ins` and a `w:moveTo` hold text and markers, a `w:del` and a `w:moveFrom` hold
|
|
55
|
+
* neither), so that each offset is one in `Paragraph.text`, hidden runs left out where `hidden` says
|
|
56
|
+
* which they are, and a kept `mc:AlternateContent`'s selected branch read (CR-012 phase 4).
|
|
57
|
+
*/
|
|
58
|
+
function collect(out, container, paragraph, hidden, mode = 'read') {
|
|
51
59
|
var _a;
|
|
52
60
|
const visitParagraph = (element, blockContainer) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (!items)
|
|
57
|
-
return;
|
|
58
|
-
for (const el of items) {
|
|
61
|
+
segmentsOf(element.value, {
|
|
62
|
+
hidden: hidden === null || hidden === void 0 ? void 0 : hidden(element.value),
|
|
63
|
+
visit: (el, at, owner, run) => {
|
|
59
64
|
const tn = typeNameOf(el);
|
|
60
|
-
if (tn ===
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
id: item.value.id, kind: 'reference', item, owner: content,
|
|
66
|
-
run: el, runOwner: items, paragraph: element, paragraphContainer: blockContainer, offset: pos,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
else
|
|
70
|
-
pos += (_c = (_b = itemTextOf(item)) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
|
|
71
|
-
}
|
|
65
|
+
if (tn === COMMENT_REFERENCE && run) {
|
|
66
|
+
out.push({
|
|
67
|
+
id: el.value.id, kind: 'reference', item: el, owner,
|
|
68
|
+
run: run.element, runOwner: run.owner, paragraph: element, paragraphContainer: blockContainer, offset: at,
|
|
69
|
+
});
|
|
72
70
|
}
|
|
73
71
|
else if (tn === COMMENT_RANGE_START || tn === COMMENT_RANGE_END) {
|
|
74
72
|
out.push({
|
|
75
73
|
id: el.value.id, kind: tn === COMMENT_RANGE_START ? 'start' : 'end',
|
|
76
|
-
item: el, owner
|
|
74
|
+
item: el, owner, paragraph: element, paragraphContainer: blockContainer, offset: at,
|
|
77
75
|
});
|
|
78
76
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
// the accepted view, which is what the offsets are in: a w:ins and a w:moveTo hold text
|
|
84
|
-
// and markers, a w:del and a w:moveFrom hold neither (CR-002 phase F)
|
|
85
|
-
const kind = revisionKindOf(el);
|
|
86
|
-
if (kind === 'ins' || kind === 'moveTo')
|
|
87
|
-
visitRuns(runItemsOf(el.value));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
visitRuns(runItemsOf(element.value));
|
|
77
|
+
},
|
|
78
|
+
});
|
|
92
79
|
};
|
|
93
80
|
const visitBlocks = (items) => {
|
|
94
|
-
var _a, _b
|
|
81
|
+
var _a, _b;
|
|
95
82
|
for (const el of items) {
|
|
96
83
|
const tn = typeNameOf(el);
|
|
97
84
|
if (tn === 'org_docx4j_wml.P')
|
|
@@ -101,10 +88,14 @@ function collect(out, container, paragraph) {
|
|
|
101
88
|
}
|
|
102
89
|
else if (typeof el.value === 'object' && el.value !== null) {
|
|
103
90
|
if (tn === 'org_docx4j_wml.Tbl') {
|
|
104
|
-
for (const row of (
|
|
105
|
-
for (const cell of (
|
|
106
|
-
visitBlocks((
|
|
107
|
-
|
|
91
|
+
for (const row of rowsOf(el.value, mode))
|
|
92
|
+
for (const cell of cellsOf(row.element.value, mode))
|
|
93
|
+
visitBlocks((_a = childrenOf(cell.element.value)) !== null && _a !== void 0 ? _a : []);
|
|
94
|
+
}
|
|
95
|
+
else if (tn === ALTERNATE_CONTENT) {
|
|
96
|
+
const ac = el.value;
|
|
97
|
+
for (const branch of mode === 'every' ? branchesOf(ac) : [(_b = selectedBranchOf(ac)) !== null && _b !== void 0 ? _b : []])
|
|
98
|
+
visitBlocks(branch);
|
|
108
99
|
}
|
|
109
100
|
else {
|
|
110
101
|
const children = childrenOf(el.value);
|
|
@@ -133,7 +124,7 @@ export function commentIdsOf(container) {
|
|
|
133
124
|
/** Removes every marker of a comment from a body, and the reference run when nothing is left in it. */
|
|
134
125
|
export function removeMarkers(container, id) {
|
|
135
126
|
var _a;
|
|
136
|
-
for (const marker of markersOf(container)) {
|
|
127
|
+
for (const marker of markersOf(container, undefined, 'every')) {
|
|
137
128
|
if (marker.id !== id)
|
|
138
129
|
continue;
|
|
139
130
|
const i = marker.owner.indexOf(marker.item);
|
|
@@ -157,7 +148,7 @@ export function nextCommentId(comments, container) {
|
|
|
157
148
|
for (const c of (_a = comments.comment) !== null && _a !== void 0 ? _a : [])
|
|
158
149
|
if (typeof c.id === 'number' && c.id > max)
|
|
159
150
|
max = c.id;
|
|
160
|
-
for (const m of markersOf(container))
|
|
151
|
+
for (const m of markersOf(container, undefined, 'every'))
|
|
161
152
|
if (m.id > max)
|
|
162
153
|
max = m.id;
|
|
163
154
|
return max + 1;
|
|
@@ -171,13 +162,28 @@ export function randomHexId(taken) {
|
|
|
171
162
|
}
|
|
172
163
|
throw new Docx4JException('Could not allocate a paragraph id');
|
|
173
164
|
}
|
|
174
|
-
/**
|
|
165
|
+
/**
|
|
166
|
+
* The `w14:paraId` of a comment's first paragraph: the key of its w15 and w16cid entries. A kept
|
|
167
|
+
* `mc:AlternateContent` before any paragraph is read in its selected branch, as Word reads it (CR-013
|
|
168
|
+
* phase 3; docx4j's `Trees.lastParaId` looks into the branch the same way).
|
|
169
|
+
*/
|
|
175
170
|
export function commentParaId(comment) {
|
|
176
|
-
var _a;
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
171
|
+
var _a, _b;
|
|
172
|
+
const first = (items) => {
|
|
173
|
+
var _a;
|
|
174
|
+
for (const el of items) {
|
|
175
|
+
const tn = typeNameOf(el);
|
|
176
|
+
if (tn === 'org_docx4j_wml.P')
|
|
177
|
+
return el.value.paraId;
|
|
178
|
+
if (tn === ALTERNATE_CONTENT) {
|
|
179
|
+
const found = first((_a = selectedBranchOf(el.value)) !== null && _a !== void 0 ? _a : []);
|
|
180
|
+
if (found !== null)
|
|
181
|
+
return found;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
};
|
|
186
|
+
return (_b = first(((_a = comment.content) !== null && _a !== void 0 ? _a : []))) !== null && _b !== void 0 ? _b : undefined;
|
|
181
187
|
}
|
|
182
188
|
/** True when a paragraph id is already used by a comment or by a paragraph of the document. */
|
|
183
189
|
export function paraIdTaken(parts, container, id) {
|
|
@@ -189,7 +195,7 @@ export function paraIdTaken(parts, container, id) {
|
|
|
189
195
|
}
|
|
190
196
|
let found = false;
|
|
191
197
|
const visit = (items) => {
|
|
192
|
-
var _a
|
|
198
|
+
var _a;
|
|
193
199
|
for (const el of items) {
|
|
194
200
|
const tn = typeNameOf(el);
|
|
195
201
|
if (tn === 'org_docx4j_wml.P') {
|
|
@@ -198,9 +204,13 @@ export function paraIdTaken(parts, container, id) {
|
|
|
198
204
|
}
|
|
199
205
|
else if (typeof el.value === 'object' && el.value !== null) {
|
|
200
206
|
if (tn === 'org_docx4j_wml.Tbl') {
|
|
201
|
-
for (const row of (
|
|
202
|
-
for (const cell of (
|
|
203
|
-
visit((
|
|
207
|
+
for (const row of rowsOf(el.value, 'every'))
|
|
208
|
+
for (const cell of cellsOf(row.element.value, 'every'))
|
|
209
|
+
visit((_a = childrenOf(cell.element.value)) !== null && _a !== void 0 ? _a : []);
|
|
210
|
+
}
|
|
211
|
+
else if (tn === ALTERNATE_CONTENT) {
|
|
212
|
+
for (const branch of branchesOf(el.value))
|
|
213
|
+
visit(branch); // an id is every branch's (CR-013)
|
|
204
214
|
}
|
|
205
215
|
else {
|
|
206
216
|
const children = childrenOf(el.value);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Docx4JException } from '../../opc/exceptions.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* What Office JS throws where the host refuses an operation it has no answer for: its `code`, so that
|
|
4
|
+
* add-in code branching on `error.code` behaves the same here (check 19: a hyperlink set on an empty range;
|
|
5
|
+
* check 52: a range starting or ending inside a table deleted or replaced).
|
|
6
|
+
*/
|
|
7
|
+
export declare class GeneralException extends Docx4JException {
|
|
8
|
+
readonly code = "GeneralException";
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* What Office JS throws for an argument it won't take (`InvalidArgument`): its `code`, as `GeneralException` carries its
|
|
13
|
+
* own (check 56: `insertTable` into a bound block content control).
|
|
14
|
+
*/
|
|
15
|
+
export declare class InvalidArgument extends Docx4JException {
|
|
16
|
+
readonly code = "InvalidArgument";
|
|
17
|
+
constructor(message: string);
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Docx4JException } from '../../opc/exceptions.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* What Office JS throws where the host refuses an operation it has no answer for: its `code`, so that
|
|
4
|
+
* add-in code branching on `error.code` behaves the same here (check 19: a hyperlink set on an empty range;
|
|
5
|
+
* check 52: a range starting or ending inside a table deleted or replaced).
|
|
6
|
+
*/
|
|
7
|
+
export class GeneralException extends Docx4JException {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.code = 'GeneralException';
|
|
11
|
+
this.name = 'GeneralException';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* What Office JS throws for an argument it won't take (`InvalidArgument`): its `code`, as `GeneralException` carries its
|
|
16
|
+
* own (check 56: `insertTable` into a bound block content control).
|
|
17
|
+
*/
|
|
18
|
+
export class InvalidArgument extends Docx4JException {
|
|
19
|
+
constructor(message) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.code = 'InvalidArgument';
|
|
22
|
+
this.name = 'InvalidArgument';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -7,13 +7,18 @@ export { List, ListItem, ListItemNotFoundError, NumberingFacade, listsOf, listLa
|
|
|
7
7
|
export { type Author, type CommentContent, type CommentOptions, type CommentEntry, type CommentParts, type CommentPartsAccess, type CommentsExtensible, type CommentMarker, COMMENT_TEXT_STYLE, COMMENT_REFERENCE_STYLE, markersOf, markersOfParagraph, commentIdsOf } from './comments.mjs';
|
|
8
8
|
export { Font, type UnderlineType, type RPrHolder, type FontTracking } from './Font.mjs';
|
|
9
9
|
export { Table, TableRow, TableCell, cellOf } from './Table.mjs';
|
|
10
|
+
export { endsWithParagraph, endWithParagraph } from './tableRules.mjs';
|
|
10
11
|
export { layoutModeOf, textWidthTwips, gridWidthsOf, widthTypeOf, insertGridColumns, deleteGridColumns, gridRangeOf, type TableLayoutMode, type ColumnInsertion } from './tableColumns.mjs';
|
|
11
12
|
export { InlinePicture, imageInfoOf, naturalSizeEmu, addImage, addImagePart, writableWidthEmu, type ImageFormat, type ImageInfo, type InlinePictureOptions, type NewPicture, type NewImagePart } from './InlinePicture.mjs';
|
|
12
13
|
export { ContentControl, collectControls, collectRunControls, W14_NS, W15_NS, type ContentControlType, type ContentControlForm, type ContentControlAppearance } from './ContentControl.mjs';
|
|
13
14
|
export { contentOf, isFlatOpc, rewriteRelationshipIds, type OoxmlOptions } from './ooxml.mjs';
|
|
14
|
-
export { type SearchOptions, searchPattern, findAll, matchesOf, expandReplacement } from './search.mjs';
|
|
15
|
-
export { segmentsOf, runsOf, runItemsOf, childrenOf, rowsOf, cellsOf, BLOCK_LEVEL_TYPES, SDT_TYPES, runOf, paragraphOf, textOfView, revisionKindOf, type TextSegment, type Located, type TextView, type TextViewOptions, type RevisionKind, type RevisionHolder } from './tree.mjs';
|
|
16
|
-
export {
|
|
15
|
+
export { type SearchOptions, searchPattern, findAll, matchesOf, expandReplacement, officeMatches, type OfficeMatch, type SearchSegment } from './search.mjs';
|
|
16
|
+
export { segmentsOf, runsOf, runItemsOf, selectedBranchOf, isAlternateContent, childrenOf, rowsOf, cellsOf, BLOCK_LEVEL_TYPES, SDT_TYPES, runOf, paragraphOf, textOfView, revisionKindOf, officeItemText, hiddenRunsOf, type TextSegment, type Located, type TextView, type TextViewOptions, type SegmentOptions, type HiddenRuns, type AlternateLocation, type RevisionKind, type RevisionHolder } from './tree.mjs';
|
|
17
|
+
export { mathTextOf, mathLetter } from './mathText.mjs';
|
|
18
|
+
export { textBoxesOf, type AnchoredBox } from './textBoxes.mjs';
|
|
19
|
+
export { ResolvedView } from './ResolvedView.mjs';
|
|
20
|
+
export { TrackedChange, trackedChangesOfParagraph, trackedChangesOfRow, joinWithNext, type TrackedChangeType, type TrackedChangeKind, type TrackedChangeTarget, type NoteRemovals } from './TrackedChange.mjs';
|
|
21
|
+
export type { TrackedChangeFilter, TrackedChangeSelection } from './trackedChangeFilter.mjs';
|
|
17
22
|
export { ChangeTracker, trackerOf, calendarOf, dateOf, wordCalendarOf, revisionDateOf, copyRPr, markDeleted, markInserted, highestAnnotationId, MARKUP_TYPES, toDeletedText, toRestoredText, restoreRPr, restorePPr, trackInsertedParagraph, trackInsertedTable, trackInsertedBlocks, wrapNewRuns, wrapInsertedRuns, paraRPrOf, rowPrOf, pruneParagraphProperties, type ChangeTrackingMode, type TrackingHost, type TrackingScope, type TrackedPart, } from './tracking.mjs';
|
|
18
23
|
export { wml, wmlOne, p, r, t, br, tab, tbl, tr, tc, sdt, sdtPr, nextSdtId, sdtProperty, sdtKindOf, inlinePicture, rPrToElements, rPrFromElements, textOf, walk, walkAll, find, linkParents, applyRunOptions, readRunOptions, UNDERLINE_TO_WML, isElement, typeNameOf, W_NS, type Element, type Wrapper, type WmlOptions, type Raw, type Interpolated, type RunOptions, type RunFormatting, type ParagraphOptions, type TableOptions, type CellOptions, type SdtKind, type SdtForm, type SdtOptions } from '@docx4j/generated-objects-ts/builders/wml';
|
|
19
24
|
export { StylesFacade, type StylePackageLike } from './stylesFacade.mjs';
|
|
@@ -9,13 +9,18 @@ export { List, ListItem, ListItemNotFoundError, NumberingFacade, listsOf, listLa
|
|
|
9
9
|
export { COMMENT_TEXT_STYLE, COMMENT_REFERENCE_STYLE, markersOf, markersOfParagraph, commentIdsOf } from './comments.mjs';
|
|
10
10
|
export { Font } from './Font.mjs';
|
|
11
11
|
export { Table, TableRow, TableCell, cellOf } from './Table.mjs';
|
|
12
|
+
// Word's rule for what a cell holds (CR-002 section 55; docx4j's TableRules)
|
|
13
|
+
export { endsWithParagraph, endWithParagraph } from './tableRules.mjs';
|
|
12
14
|
export { layoutModeOf, textWidthTwips, gridWidthsOf, widthTypeOf, insertGridColumns, deleteGridColumns, gridRangeOf } from './tableColumns.mjs';
|
|
13
15
|
export { InlinePicture, imageInfoOf, naturalSizeEmu, addImage, addImagePart, writableWidthEmu } from './InlinePicture.mjs';
|
|
14
16
|
export { ContentControl, collectControls, collectRunControls, W14_NS, W15_NS } from './ContentControl.mjs';
|
|
15
17
|
export { contentOf, isFlatOpc, rewriteRelationshipIds } from './ooxml.mjs';
|
|
16
|
-
export { searchPattern, findAll, matchesOf, expandReplacement } from './search.mjs';
|
|
17
|
-
export { segmentsOf, runsOf, runItemsOf, childrenOf, rowsOf, cellsOf, BLOCK_LEVEL_TYPES, SDT_TYPES, runOf, paragraphOf, textOfView, revisionKindOf } from './tree.mjs';
|
|
18
|
+
export { searchPattern, findAll, matchesOf, expandReplacement, officeMatches } from './search.mjs';
|
|
19
|
+
export { segmentsOf, runsOf, runItemsOf, selectedBranchOf, isAlternateContent, childrenOf, rowsOf, cellsOf, BLOCK_LEVEL_TYPES, SDT_TYPES, runOf, paragraphOf, textOfView, revisionKindOf, officeItemText, hiddenRunsOf } from './tree.mjs';
|
|
20
|
+
export { mathTextOf, mathLetter } from './mathText.mjs';
|
|
21
|
+
export { textBoxesOf } from './textBoxes.mjs';
|
|
18
22
|
// change tracking (CR-002 phase F)
|
|
23
|
+
export { ResolvedView } from './ResolvedView.mjs';
|
|
19
24
|
export { TrackedChange, trackedChangesOfParagraph, trackedChangesOfRow, joinWithNext } from './TrackedChange.mjs';
|
|
20
25
|
export { ChangeTracker, trackerOf, calendarOf, dateOf, wordCalendarOf, revisionDateOf, copyRPr, markDeleted, markInserted, highestAnnotationId, MARKUP_TYPES, toDeletedText, toRestoredText, restoreRPr, restorePPr, trackInsertedParagraph, trackInsertedTable, trackInsertedBlocks, wrapNewRuns, wrapInsertedRuns, paraRPrOf, rowPrOf, pruneParagraphProperties, } from './tracking.mjs';
|
|
21
26
|
// The objects package's builders, re-exported so that one import serves the content API and the tree it works on.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Element } from '@docx4j/generated-objects-ts/builders/wml';
|
|
2
|
+
/** The two views a paragraph's text is read in. */
|
|
3
|
+
type View = 'accepted' | 'original';
|
|
4
|
+
/** True for an equation at run-holder level: `m:oMath` or `m:oMathPara`. */
|
|
5
|
+
export declare function isMath(el: Element): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* The text of an equation (`m:oMath`, `m:oMathPara`) in a view: the `m:t` of every math run in document
|
|
8
|
+
* order, a revision's runs as the view has them, a structure the view hides (its `m:ctrlPr`'s revision) left out
|
|
9
|
+
* whole, each letter mapped as Word draws it (`mathLetter`).
|
|
10
|
+
*/
|
|
11
|
+
export declare function mathTextOf(math: unknown, view?: View): string;
|
|
12
|
+
/**
|
|
13
|
+
* A character as Word draws it in a math run with this `m:sty` (`p`, `b`, `i`, `bi`; none is Word's default,
|
|
14
|
+
* italic) and `m:scr` (`roman`, the default, `script`, `fraktur`, `double-struck`, `sans-serif`,
|
|
15
|
+
* `monospace`), as check 51 measured: letters, Greek capitals, small letters and nabla alike, in the
|
|
16
|
+
* alphabet of the style and script; digits upright in the script's family (bold for bold or bold italic,
|
|
17
|
+
* sans-serif under sans-serif, none of their own in script or fraktur); a character no alphabet has is
|
|
18
|
+
* itself.
|
|
19
|
+
*/
|
|
20
|
+
export declare function mathLetter(c: string, sty: string | undefined, scr: string | undefined): string;
|
|
21
|
+
export {};
|