@stll/docx-core 0.21.0 → 0.23.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/dist/document-CKwRw-01.js +153 -0
- package/dist/{document-Bu82QPAC.d.ts → document-o2RiAASq.d.ts} +292 -38
- package/dist/docx_kernel_bg.wasm +0 -0
- package/dist/index.d.ts +77 -2
- package/dist/index.js +202 -39
- package/dist/model/document.d.ts +2 -2
- package/dist/model/document.js +2 -2
- package/package.json +1 -1
- package/dist/document-D6wZrAko.js +0 -66
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
//#region src/model/parseWarning.ts
|
|
2
|
+
/**
|
|
3
|
+
* What folio normalised to open a document, as data rather than as prose.
|
|
4
|
+
*
|
|
5
|
+
* Word accepts input the schema does not describe, so folio accepts it too and
|
|
6
|
+
* normalises at the parse boundary. Every such decision is recorded here: a
|
|
7
|
+
* stable `code`, the part it happened in, the best position that part can
|
|
8
|
+
* name, and the value folio declined to read. A host can count them, group
|
|
9
|
+
* them, or decide on one; the human-readable string the parser has always
|
|
10
|
+
* exposed is derived from this, never written by hand at the call site, so the
|
|
11
|
+
* two cannot drift.
|
|
12
|
+
*
|
|
13
|
+
* It lives beside `Document` because it is part of the parsed document, and a
|
|
14
|
+
* `Document` may be produced by anything that builds this model.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Every normalisation the parse boundary is allowed to make.
|
|
18
|
+
*
|
|
19
|
+
* Adding a member without also giving it a message is a type error: the
|
|
20
|
+
* formatter map over this union is total.
|
|
21
|
+
*/
|
|
22
|
+
const PARSE_WARNING_CODES = {
|
|
23
|
+
/** A package opened from encrypted storage; a save writes it unencrypted. */
|
|
24
|
+
packageDecrypted: "package-decrypted",
|
|
25
|
+
/** The archive reader reported something about the package it opened. */
|
|
26
|
+
packageArchive: "package-archive",
|
|
27
|
+
/** The main document part is missing; the body is empty. */
|
|
28
|
+
documentPartMissing: "document-part-missing",
|
|
29
|
+
/** The model validator reported an issue the parse did not treat as fatal. */
|
|
30
|
+
documentModelIssue: "document-model-issue",
|
|
31
|
+
/** A later `w:comment` repeating a `w:id` an earlier one defines. */
|
|
32
|
+
duplicateCommentId: "duplicate-comment-id",
|
|
33
|
+
/** A `w:comment` with no readable `w:id`; it can anchor nothing. */
|
|
34
|
+
missingCommentId: "missing-comment-id",
|
|
35
|
+
/** A later `w:footnote`/`w:endnote` repeating an id an earlier one defines. */
|
|
36
|
+
duplicateNoteId: "duplicate-note-id",
|
|
37
|
+
/** A comment marker naming a comment `comments.xml` never defines. */
|
|
38
|
+
danglingCommentReference: "dangling-comment-reference",
|
|
39
|
+
/** A comment range with no matching start or end, re-anchored as a point. */
|
|
40
|
+
unbalancedCommentRange: "unbalanced-comment-range",
|
|
41
|
+
/** A `w:headerReference` naming a header part the package does not carry. */
|
|
42
|
+
danglingHeaderReference: "dangling-header-reference",
|
|
43
|
+
/** A `w:footerReference` naming a footer part the package does not carry. */
|
|
44
|
+
danglingFooterReference: "dangling-footer-reference",
|
|
45
|
+
/** A `r:id` naming a relationship the part's `.rels` does not define. */
|
|
46
|
+
danglingRelationshipId: "dangling-relationship-id",
|
|
47
|
+
/** A paragraph naming a `w:num` the numbering part never defines. */
|
|
48
|
+
unnumberedParagraph: "unnumbered-paragraph",
|
|
49
|
+
/** A style naming a `w:num` the numbering part never defines. */
|
|
50
|
+
unnumberedStyle: "unnumbered-style",
|
|
51
|
+
/** A tracked move range with no matching start or end. */
|
|
52
|
+
unbalancedMoveRange: "unbalanced-move-range",
|
|
53
|
+
/** A `w:type` outside `ST_HdrFtr`, read as the enumeration's default. */
|
|
54
|
+
headerFooterTypeOutsideEnum: "header-footer-type-outside-enum",
|
|
55
|
+
/** A value outside `ST_OnOff`'s six spellings. */
|
|
56
|
+
unrecognisedOnOffValue: "unrecognised-on-off-value",
|
|
57
|
+
/** A `CT_Border` with no `w:val`, which has no border style to read. */
|
|
58
|
+
borderWithoutValue: "border-without-value",
|
|
59
|
+
/** A style set defining two styles under one id. */
|
|
60
|
+
styleSetDuplicateStyleId: "style-set-duplicate-style-id",
|
|
61
|
+
/** A style set naming an initial paragraph style it does not contain. */
|
|
62
|
+
styleSetInitialStyleMissing: "style-set-initial-style-missing"
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* The cap on retained warnings per code.
|
|
66
|
+
*
|
|
67
|
+
* A generated document can repeat one defect on every paragraph, and a host
|
|
68
|
+
* that only wants to know a defect occurred should not pay for a hundred
|
|
69
|
+
* thousand records. Occurrences past the cap are counted, not kept.
|
|
70
|
+
*/
|
|
71
|
+
const MAX_RETAINED_PARSE_WARNINGS_PER_CODE = 20;
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/model/content.ts
|
|
74
|
+
const OOXML_SYMBOL_CHARACTER_PATTERN = /^[\dA-Fa-f]{4}$/u;
|
|
75
|
+
/** Whether a symbol character is exactly four hexadecimal digits. */
|
|
76
|
+
const isOoxmlSymbolCharacter = (value) => OOXML_SYMBOL_CHARACTER_PATTERN.test(value);
|
|
77
|
+
/** Raw XML handling modes for drawings that Folio cannot model completely. */
|
|
78
|
+
const DRAWING_RAW_XML_MODES = {
|
|
79
|
+
PRESERVE_ONLY: "preserveOnly",
|
|
80
|
+
/** The modeled image is a rendered preview of richer markup, so regeneration cannot reproduce the drawing. */
|
|
81
|
+
PREVIEW_ONLY: "previewOnly"
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Largest value a revision id (`w:id`) may carry: 2^31 - 1.
|
|
85
|
+
*
|
|
86
|
+
* `w:id` on `<w:ins>`/`<w:del>` comes from `CT_Markup`, typed
|
|
87
|
+
* `ST_DecimalNumber` — which ECMA-376 defines as an unbounded integer. The
|
|
88
|
+
* bound below is an implementation limit: conforming consumers read
|
|
89
|
+
* `ST_DecimalNumber` into a signed 32-bit int, and a value past this bound
|
|
90
|
+
* overflows on load and surfaces as an unreadable document. Port of
|
|
91
|
+
* eigenpal/docx-editor#1093.
|
|
92
|
+
*/
|
|
93
|
+
const MAX_REVISION_ID = 2147483647;
|
|
94
|
+
/**
|
|
95
|
+
* Coerce any revision id — including one parsed from an untrusted DOCX — into
|
|
96
|
+
* the range serialized `w:id` attributes may occupy.
|
|
97
|
+
*
|
|
98
|
+
* - Malformed (negative, fractional, `NaN`, `Infinity`): collapse to `0`.
|
|
99
|
+
* - Well-formed but out of range: fold modulo the range (not clamp) so a
|
|
100
|
+
* contiguous run of overflowing ids stays distinguishable.
|
|
101
|
+
*/
|
|
102
|
+
function normalizeRevisionId(id) {
|
|
103
|
+
if (!Number.isInteger(id) || id < 0) return 0;
|
|
104
|
+
if (id > 2147483647) return id % 2147483648;
|
|
105
|
+
return id;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Which Unicode bidirectional control a `w:bdo`/`w:dir` wrapper is.
|
|
109
|
+
*
|
|
110
|
+
* `w:dir` is an embedding: the run of text inside it is laid out in the given
|
|
111
|
+
* direction and the bidirectional algorithm still resolves the characters
|
|
112
|
+
* within it. `w:bdo` is an override: the algorithm is switched off inside and
|
|
113
|
+
* every character is laid out in the given direction, which is what makes a
|
|
114
|
+
* Latin word inside an `rtl` override read backwards. CSS spells the pair
|
|
115
|
+
* `unicode-bidi: embed` and `unicode-bidi: bidi-override`, and HTML gives the
|
|
116
|
+
* second an element of its own, `<bdo>`.
|
|
117
|
+
*/
|
|
118
|
+
const BIDI_CONTROLS = {
|
|
119
|
+
embedding: "embedding",
|
|
120
|
+
override: "override"
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* The kinds a paragraph-mark tracked change can be (ECMA-376 §17.13.5).
|
|
124
|
+
*
|
|
125
|
+
* Written as a child of `<w:pPr><w:rPr>` — `<w:ins/>` when the paragraph
|
|
126
|
+
* break itself was inserted in track-changes mode (the user pressed Enter
|
|
127
|
+
* mid-paragraph), `<w:del/>` when the paragraph break is pending deletion
|
|
128
|
+
* (Backspace at paragraph start or Delete at paragraph end). The mark is
|
|
129
|
+
* independent of the inline runs the paragraph carries.
|
|
130
|
+
*
|
|
131
|
+
* A relocated paragraph's break is `<w:moveFrom/>` at the source and
|
|
132
|
+
* `<w:moveTo/>` at the destination. They resolve exactly as `del` and `ins`
|
|
133
|
+
* do — a move is a deletion and an insertion that a reader is told belong
|
|
134
|
+
* together — but they are not those kinds: writing `w:del` on a moved
|
|
135
|
+
* paragraph's mark reports the relocation as a deletion as well.
|
|
136
|
+
*/
|
|
137
|
+
const PARAGRAPH_MARK_CHANGE_KINDS = Object.freeze([
|
|
138
|
+
"moveFrom",
|
|
139
|
+
"moveTo",
|
|
140
|
+
"ins",
|
|
141
|
+
"del"
|
|
142
|
+
]);
|
|
143
|
+
const REVIEW_CARRIERS = { TERMINAL_TABLE: "terminal-table" };
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/model/document.ts
|
|
146
|
+
/** DOCX package conformance classes. */
|
|
147
|
+
const DOCX_CONFORMANCE_CLASSES = Object.freeze({
|
|
148
|
+
STRICT: "strict",
|
|
149
|
+
TRANSITIONAL: "transitional",
|
|
150
|
+
UNKNOWN: "unknown"
|
|
151
|
+
});
|
|
152
|
+
//#endregion
|
|
153
|
+
export { PARAGRAPH_MARK_CHANGE_KINDS as a, normalizeRevisionId as c, MAX_REVISION_ID as i, MAX_RETAINED_PARSE_WARNINGS_PER_CODE as l, BIDI_CONTROLS as n, REVIEW_CARRIERS as o, DRAWING_RAW_XML_MODES as r, isOoxmlSymbolCharacter as s, DOCX_CONFORMANCE_CLASSES as t, PARSE_WARNING_CODES as u };
|
|
@@ -277,6 +277,16 @@ type ParagraphFormatting = {
|
|
|
277
277
|
numId?: number;
|
|
278
278
|
ilvl?: number;
|
|
279
279
|
};
|
|
280
|
+
/**
|
|
281
|
+
* The `w:numberingChange` inside the paragraph's `w:numPr`, verbatim.
|
|
282
|
+
*
|
|
283
|
+
* It records the numbering a paragraph carried before a reviewer changed it,
|
|
284
|
+
* with the author and date of that change. Nothing in the current model
|
|
285
|
+
* derives it, and a rebuilt `w:numPr` that omits it discards a tracked
|
|
286
|
+
* revision without telling anyone. The element is a historical snapshot, so
|
|
287
|
+
* it travels as markup rather than as a parsed shape.
|
|
288
|
+
*/
|
|
289
|
+
numberingChangeXml?: string;
|
|
280
290
|
/** Outline level 0-9 (w:outlineLvl) */
|
|
281
291
|
outlineLevel?: number;
|
|
282
292
|
/** Paragraph style ID (w:pStyle) */
|
|
@@ -351,9 +361,23 @@ type CellMargins = {
|
|
|
351
361
|
right?: TableMeasurement;
|
|
352
362
|
};
|
|
353
363
|
/**
|
|
354
|
-
*
|
|
364
|
+
* `w:tblLook`: which of a table style's conditional formats the table asks for.
|
|
365
|
+
*
|
|
366
|
+
* Every flag is tri-state, because `CT_TblLook` states the same six facts twice
|
|
367
|
+
* and the two spellings are not interchangeable. Absent means the author wrote
|
|
368
|
+
* no such attribute, so the flag falls back to the matching bit of {@link
|
|
369
|
+
* TableLook.val} and then to off; an explicit `false` states the region off and
|
|
370
|
+
* overrides the bit. Writing only the true flags back turns the second and
|
|
371
|
+
* third into the first, which is a different document.
|
|
372
|
+
*
|
|
373
|
+
* Read one with `resolveTableLook`, never on its own.
|
|
355
374
|
*/
|
|
356
375
|
type TableLook = {
|
|
376
|
+
/**
|
|
377
|
+
* `w:val`, the legacy `ST_ShortHexNumber` bitmask, kept as the author spelled
|
|
378
|
+
* it. Producers older than the attribute form write only this.
|
|
379
|
+
*/
|
|
380
|
+
val?: string;
|
|
357
381
|
firstColumn?: boolean;
|
|
358
382
|
firstRow?: boolean;
|
|
359
383
|
lastColumn?: boolean;
|
|
@@ -416,11 +440,21 @@ type TableFormatting = {
|
|
|
416
440
|
*
|
|
417
441
|
* The grid is a sibling of `w:tblPr` rather than a child of it, but it is
|
|
418
442
|
* the table's own property set that travels through the editable model, so
|
|
419
|
-
* it rides along here.
|
|
420
|
-
*
|
|
421
|
-
*
|
|
443
|
+
* it rides along here. It is replayed only while the column widths still
|
|
444
|
+
* agree with it; {@link gridChangeXml} carries the part of it that a rebuild
|
|
445
|
+
* must not drop.
|
|
422
446
|
*/
|
|
423
447
|
gridSourceXml?: string;
|
|
448
|
+
/**
|
|
449
|
+
* The grid's `w:tblGridChange`, verbatim.
|
|
450
|
+
*
|
|
451
|
+
* It records the grid as it stood before a reviewer resized a column, so it
|
|
452
|
+
* is history: nothing in the current model derives it, and rebuilding the
|
|
453
|
+
* grid from the column widths would accept the revision silently. The
|
|
454
|
+
* element is a snapshot of columns rather than a description of them, so it
|
|
455
|
+
* travels as markup rather than as a parsed shape.
|
|
456
|
+
*/
|
|
457
|
+
gridChangeXml?: string;
|
|
424
458
|
/**
|
|
425
459
|
* The element this formatting was parsed from, verbatim.
|
|
426
460
|
*
|
|
@@ -709,8 +743,6 @@ type TextContent = {
|
|
|
709
743
|
type: "text";
|
|
710
744
|
/** The text string */
|
|
711
745
|
text: string;
|
|
712
|
-
/** Preserve whitespace (xml:space="preserve") */
|
|
713
|
-
preserveSpace?: boolean;
|
|
714
746
|
};
|
|
715
747
|
/**
|
|
716
748
|
* Tab character
|
|
@@ -882,26 +914,56 @@ type Hyperlink = {
|
|
|
882
914
|
children: (Run | BookmarkStart | BookmarkEnd)[];
|
|
883
915
|
};
|
|
884
916
|
/**
|
|
885
|
-
*
|
|
917
|
+
* Which side of a `w:customXml` element a range marker was displaced to
|
|
918
|
+
* (`w:displacedByCustomXml`, ST_DisplacedByCustomXml).
|
|
886
919
|
*/
|
|
887
|
-
type
|
|
888
|
-
|
|
889
|
-
|
|
920
|
+
type DisplacedByCustomXml = "next" | "prev";
|
|
921
|
+
/**
|
|
922
|
+
* The attributes of `CT_MarkupRange`, the base type of every range marker:
|
|
923
|
+
* bookmarks, comment ranges, move ranges and their ends.
|
|
924
|
+
*
|
|
925
|
+
* The three types below mirror the schema's own derivation chain
|
|
926
|
+
* (`CT_MarkupRange` → `CT_Bookmark` → `CT_MoveBookmark`) so a marker's model
|
|
927
|
+
* is the element's attribute set rather than a hand-picked subset of it. Every
|
|
928
|
+
* marker that lost attributes on save lost them by declaring its own fields.
|
|
929
|
+
*/
|
|
930
|
+
type MarkupRangeMarker = {
|
|
931
|
+
/** Pairs a start with its end (`w:id`). */
|
|
890
932
|
id: number;
|
|
891
|
-
|
|
933
|
+
displacedByCustomXml?: DisplacedByCustomXml;
|
|
934
|
+
};
|
|
935
|
+
/** `CT_Bookmark`: a named range, optionally scoped to table columns. */
|
|
936
|
+
type BookmarkRangeMarker = MarkupRangeMarker & {
|
|
892
937
|
name: string;
|
|
893
938
|
/** Column index for table bookmarks */
|
|
894
939
|
colFirst?: number;
|
|
895
940
|
colLast?: number;
|
|
896
941
|
};
|
|
942
|
+
/**
|
|
943
|
+
* `CT_MoveBookmark`: a bookmark range attributed to the move that created it.
|
|
944
|
+
*
|
|
945
|
+
* The schema makes `w:author` required, so the field is not optional: a marker
|
|
946
|
+
* that cannot name an author cannot be written at all, and the parser supplies
|
|
947
|
+
* the same `Unknown` fallback a tracked change gets. `w:date` is required too,
|
|
948
|
+
* but a date folio does not have is not a date it may invent, so a document
|
|
949
|
+
* that arrived without one keeps arriving without one.
|
|
950
|
+
*/
|
|
951
|
+
type MoveBookmarkMarker = BookmarkRangeMarker & {
|
|
952
|
+
author: string;
|
|
953
|
+
date?: string;
|
|
954
|
+
};
|
|
955
|
+
/**
|
|
956
|
+
* Bookmark start marker (w:bookmarkStart)
|
|
957
|
+
*/
|
|
958
|
+
type BookmarkStart = {
|
|
959
|
+
type: "bookmarkStart";
|
|
960
|
+
} & BookmarkRangeMarker;
|
|
897
961
|
/**
|
|
898
962
|
* Bookmark end marker (w:bookmarkEnd)
|
|
899
963
|
*/
|
|
900
964
|
type BookmarkEnd = {
|
|
901
965
|
type: "bookmarkEnd";
|
|
902
|
-
|
|
903
|
-
id: number;
|
|
904
|
-
};
|
|
966
|
+
} & MarkupRangeMarker;
|
|
905
967
|
/**
|
|
906
968
|
* Known field types
|
|
907
969
|
*/
|
|
@@ -1040,8 +1102,15 @@ type Image = {
|
|
|
1040
1102
|
type: "image";
|
|
1041
1103
|
/** Unique ID */
|
|
1042
1104
|
id?: string;
|
|
1043
|
-
/**
|
|
1044
|
-
|
|
1105
|
+
/**
|
|
1106
|
+
* Relationship id for the image data, absent when the drawing carries none.
|
|
1107
|
+
*
|
|
1108
|
+
* A `w:drawing` whose graphic is not a picture — a chart, a diagram, an OLE
|
|
1109
|
+
* frame — and one with no `a:graphic` at all have no `a:blip`, so there is no
|
|
1110
|
+
* id to record. Absence is spelled `undefined` rather than `""` so it can
|
|
1111
|
+
* never reach a relationship lookup as a key.
|
|
1112
|
+
*/
|
|
1113
|
+
rId?: string;
|
|
1045
1114
|
/** Resolved image data (base64 or blob URL) */
|
|
1046
1115
|
src?: string;
|
|
1047
1116
|
/** Image MIME type */
|
|
@@ -1089,8 +1158,26 @@ type Image = {
|
|
|
1089
1158
|
* preserves the author's intent; undefined means "use the spec default".
|
|
1090
1159
|
*/
|
|
1091
1160
|
allowOverlap?: boolean;
|
|
1092
|
-
/**
|
|
1161
|
+
/**
|
|
1162
|
+
* The image carries no information a reader needs, so assistive technology
|
|
1163
|
+
* skips it. Word writes this as an extension on `wp:docPr`
|
|
1164
|
+
* (`{C183D7F6-B498-43B3-948B-1728B52AA6E4}` holding
|
|
1165
|
+
* `adec:decorative val="1"`), not as an attribute: `CT_NonVisualDrawingProps`
|
|
1166
|
+
* has no `@decorative`.
|
|
1167
|
+
*
|
|
1168
|
+
* Not `hidden`. A decorative image is displayed and skipped by a screen
|
|
1169
|
+
* reader; a hidden one is not displayed at all.
|
|
1170
|
+
*/
|
|
1093
1171
|
decorative?: boolean;
|
|
1172
|
+
/** `wp:docPr @hidden`: the drawing is not displayed. */
|
|
1173
|
+
hidden?: boolean;
|
|
1174
|
+
/**
|
|
1175
|
+
* The `a:ext` entries of the `wp:docPr` extension list that folio does not
|
|
1176
|
+
* model — a creation id, a local-DPI hint — captured as XML in source order.
|
|
1177
|
+
* Written back beside the decorative extension so an extension folio has no
|
|
1178
|
+
* opinion about still survives a save.
|
|
1179
|
+
*/
|
|
1180
|
+
docPrExtensions?: string[];
|
|
1094
1181
|
/** Hyperlink URL for clickable image */
|
|
1095
1182
|
hlinkHref?: string;
|
|
1096
1183
|
/** Relationship ID for the clickable image hyperlink */
|
|
@@ -1211,8 +1298,12 @@ type Shape = {
|
|
|
1211
1298
|
geometryAdjustments?: ShapeGeometryAdjustment[];
|
|
1212
1299
|
/** Unique ID */
|
|
1213
1300
|
id?: string;
|
|
1214
|
-
/**
|
|
1301
|
+
/** Authored non-visual drawing name (`wp:docPr@name` / `wps:cNvPr@name`) */
|
|
1215
1302
|
name?: string;
|
|
1303
|
+
/** Alt text for accessibility (`wp:docPr@descr` / `wps:cNvPr@descr`) */
|
|
1304
|
+
alt?: string;
|
|
1305
|
+
/** Authored non-visual drawing title (`wp:docPr@title` / `wps:cNvPr@title`) */
|
|
1306
|
+
title?: string;
|
|
1216
1307
|
/** Size in EMUs */
|
|
1217
1308
|
size: ImageSize;
|
|
1218
1309
|
/** Position for floating shapes */
|
|
@@ -1237,6 +1328,12 @@ type TextBox = {
|
|
|
1237
1328
|
type: "textBox";
|
|
1238
1329
|
/** Unique ID */
|
|
1239
1330
|
id?: string;
|
|
1331
|
+
/** Authored non-visual drawing name (`wp:docPr@name` / `wps:cNvPr@name`) */
|
|
1332
|
+
name?: string;
|
|
1333
|
+
/** Alt text for accessibility (`wp:docPr@descr` / `wps:cNvPr@descr`) */
|
|
1334
|
+
alt?: string;
|
|
1335
|
+
/** Authored non-visual drawing title (`wp:docPr@title` / `wps:cNvPr@title`) */
|
|
1336
|
+
title?: string;
|
|
1240
1337
|
/** Size */
|
|
1241
1338
|
size: ImageSize;
|
|
1242
1339
|
/** Position */
|
|
@@ -1308,7 +1405,7 @@ type Table = {
|
|
|
1308
1405
|
columnWidths?: number[];
|
|
1309
1406
|
/** Table rows */
|
|
1310
1407
|
rows: TableRow[];
|
|
1311
|
-
};
|
|
1408
|
+
} & BlockRangeMarkerCapture;
|
|
1312
1409
|
/**
|
|
1313
1410
|
* A comment (w:comment) from comments.xml
|
|
1314
1411
|
*/
|
|
@@ -1335,15 +1432,13 @@ type Comment = {
|
|
|
1335
1432
|
*/
|
|
1336
1433
|
type CommentRangeStart = {
|
|
1337
1434
|
type: "commentRangeStart";
|
|
1338
|
-
|
|
1339
|
-
};
|
|
1435
|
+
} & MarkupRangeMarker;
|
|
1340
1436
|
/**
|
|
1341
1437
|
* Comment range end marker in paragraph content
|
|
1342
1438
|
*/
|
|
1343
1439
|
type CommentRangeEnd = {
|
|
1344
1440
|
type: "commentRangeEnd";
|
|
1345
|
-
|
|
1346
|
-
};
|
|
1441
|
+
} & MarkupRangeMarker;
|
|
1347
1442
|
/**
|
|
1348
1443
|
* Point comment reference (w:commentReference without an explicit range).
|
|
1349
1444
|
* Word sometimes stores comments this way; we anchor them to nearby text for display.
|
|
@@ -1459,38 +1554,63 @@ type MoveTo = {
|
|
|
1459
1554
|
/** Moved content */
|
|
1460
1555
|
content: TrackedRunContent[];
|
|
1461
1556
|
};
|
|
1557
|
+
/**
|
|
1558
|
+
* Which Unicode bidirectional control a `w:bdo`/`w:dir` wrapper is.
|
|
1559
|
+
*
|
|
1560
|
+
* `w:dir` is an embedding: the run of text inside it is laid out in the given
|
|
1561
|
+
* direction and the bidirectional algorithm still resolves the characters
|
|
1562
|
+
* within it. `w:bdo` is an override: the algorithm is switched off inside and
|
|
1563
|
+
* every character is laid out in the given direction, which is what makes a
|
|
1564
|
+
* Latin word inside an `rtl` override read backwards. CSS spells the pair
|
|
1565
|
+
* `unicode-bidi: embed` and `unicode-bidi: bidi-override`, and HTML gives the
|
|
1566
|
+
* second an element of its own, `<bdo>`.
|
|
1567
|
+
*/
|
|
1568
|
+
declare const BIDI_CONTROLS: {
|
|
1569
|
+
readonly embedding: "embedding";
|
|
1570
|
+
readonly override: "override";
|
|
1571
|
+
};
|
|
1572
|
+
type BidiControl = (typeof BIDI_CONTROLS)[keyof typeof BIDI_CONTROLS];
|
|
1573
|
+
/**
|
|
1574
|
+
* A bidirectional embedding or override (w:dir, w:bdo) — ECMA-376 §17.3.2.8, §17.3.2.3.
|
|
1575
|
+
*
|
|
1576
|
+
* A transparent inline wrapper: it changes how its content is laid out and
|
|
1577
|
+
* nothing else, so it nests, it may hold anything paragraph content may hold,
|
|
1578
|
+
* and dropping it changes what the reader sees rather than only what the file
|
|
1579
|
+
* says.
|
|
1580
|
+
*/
|
|
1581
|
+
type BidiWrapper = {
|
|
1582
|
+
type: "bidiWrapper";
|
|
1583
|
+
control: BidiControl;
|
|
1584
|
+
/** `w:val`; absent in the source means the wrapper states no direction. */
|
|
1585
|
+
direction?: "ltr" | "rtl";
|
|
1586
|
+
content: ParagraphContent[];
|
|
1587
|
+
};
|
|
1462
1588
|
/**
|
|
1463
1589
|
* Move-from range start marker (w:moveFromRangeStart) — ECMA-376 §17.13.5.22
|
|
1464
1590
|
* Pairs with moveFromRangeEnd to delimit the source of a move in the document.
|
|
1465
1591
|
*/
|
|
1466
1592
|
type MoveFromRangeStart = {
|
|
1467
1593
|
type: "moveFromRangeStart";
|
|
1468
|
-
|
|
1469
|
-
name: string;
|
|
1470
|
-
};
|
|
1594
|
+
} & MoveBookmarkMarker;
|
|
1471
1595
|
/**
|
|
1472
1596
|
* Move-from range end marker (w:moveFromRangeEnd)
|
|
1473
1597
|
*/
|
|
1474
1598
|
type MoveFromRangeEnd = {
|
|
1475
1599
|
type: "moveFromRangeEnd";
|
|
1476
|
-
|
|
1477
|
-
};
|
|
1600
|
+
} & MarkupRangeMarker;
|
|
1478
1601
|
/**
|
|
1479
1602
|
* Move-to range start marker (w:moveToRangeStart) — ECMA-376 §17.13.5.24
|
|
1480
1603
|
* Pairs with moveToRangeEnd to delimit the destination of a move.
|
|
1481
1604
|
*/
|
|
1482
1605
|
type MoveToRangeStart = {
|
|
1483
1606
|
type: "moveToRangeStart";
|
|
1484
|
-
|
|
1485
|
-
name: string;
|
|
1486
|
-
};
|
|
1607
|
+
} & MoveBookmarkMarker;
|
|
1487
1608
|
/**
|
|
1488
1609
|
* Move-to range end marker (w:moveToRangeEnd)
|
|
1489
1610
|
*/
|
|
1490
1611
|
type MoveToRangeEnd = {
|
|
1491
1612
|
type: "moveToRangeEnd";
|
|
1492
|
-
|
|
1493
|
-
};
|
|
1613
|
+
} & MarkupRangeMarker;
|
|
1494
1614
|
/**
|
|
1495
1615
|
* Run-level tracked wrappers represented in WordprocessingML.
|
|
1496
1616
|
*/
|
|
@@ -1694,11 +1814,11 @@ type BlockSdt = {
|
|
|
1694
1814
|
properties: SdtProperties;
|
|
1695
1815
|
/** Block content inside the control. */
|
|
1696
1816
|
content: BlockContent[];
|
|
1697
|
-
};
|
|
1817
|
+
} & BlockRangeMarkerCapture;
|
|
1698
1818
|
/**
|
|
1699
1819
|
* Paragraph content types
|
|
1700
1820
|
*/
|
|
1701
|
-
type ParagraphContent = Run | Hyperlink | BookmarkStart | BookmarkEnd | SimpleField | ComplexField | InlineSdt | CommentRangeStart | CommentRangeEnd | CommentReference | Insertion | Deletion | MoveFrom | MoveTo | MoveFromRangeStart | MoveFromRangeEnd | MoveToRangeStart | MoveToRangeEnd | MathEquation;
|
|
1821
|
+
type ParagraphContent = Run | Hyperlink | BookmarkStart | BookmarkEnd | SimpleField | ComplexField | InlineSdt | CommentRangeStart | CommentRangeEnd | CommentReference | Insertion | Deletion | MoveFrom | MoveTo | MoveFromRangeStart | MoveFromRangeEnd | MoveToRangeStart | MoveToRangeEnd | BidiWrapper | MathEquation;
|
|
1702
1822
|
/**
|
|
1703
1823
|
* The kinds a paragraph-mark tracked change can be (ECMA-376 §17.13.5).
|
|
1704
1824
|
*
|
|
@@ -1750,7 +1870,7 @@ type Paragraph = {
|
|
|
1750
1870
|
renderedPageBreakBefore?: boolean;
|
|
1751
1871
|
/** Section properties (if this paragraph ends a section) */
|
|
1752
1872
|
sectionProperties?: SectionProperties;
|
|
1753
|
-
};
|
|
1873
|
+
} & BlockRangeMarkerCapture;
|
|
1754
1874
|
/**
|
|
1755
1875
|
* Header/footer type
|
|
1756
1876
|
*/
|
|
@@ -2078,6 +2198,22 @@ type SectionProperties = {
|
|
|
2078
2198
|
/** Section-level tracked property changes (w:sectPrChange) */
|
|
2079
2199
|
propertyChanges?: SectionPropertyChange[];
|
|
2080
2200
|
};
|
|
2201
|
+
/**
|
|
2202
|
+
* Range markers captured verbatim from between two blocks.
|
|
2203
|
+
*
|
|
2204
|
+
* `w:permStart`, `w:customXml*Range*`, and a comment or move range that opens
|
|
2205
|
+
* or closes between blocks are all legal children of `w:body`, `w:tc` and a
|
|
2206
|
+
* header. folio has no model for most of them, and their position is the whole
|
|
2207
|
+
* of their meaning: a protected range that spans three paragraphs is defined
|
|
2208
|
+
* by where its `w:permStart` sits. So they ride on the block they precede or
|
|
2209
|
+
* follow and are replayed there.
|
|
2210
|
+
*/
|
|
2211
|
+
type BlockRangeMarkerCapture = {
|
|
2212
|
+
/** Markup that stood immediately before this block. */
|
|
2213
|
+
rawMarkersBefore?: string;
|
|
2214
|
+
/** Markup that stood after this block, which only the last block can carry. */
|
|
2215
|
+
rawMarkersAfter?: string;
|
|
2216
|
+
};
|
|
2081
2217
|
/**
|
|
2082
2218
|
* Block-level content types
|
|
2083
2219
|
*/
|
|
@@ -2109,6 +2245,105 @@ type DocumentBody = {
|
|
|
2109
2245
|
comments?: Comment[];
|
|
2110
2246
|
};
|
|
2111
2247
|
//#endregion
|
|
2248
|
+
//#region src/model/parseWarning.d.ts
|
|
2249
|
+
/**
|
|
2250
|
+
* What folio normalised to open a document, as data rather than as prose.
|
|
2251
|
+
*
|
|
2252
|
+
* Word accepts input the schema does not describe, so folio accepts it too and
|
|
2253
|
+
* normalises at the parse boundary. Every such decision is recorded here: a
|
|
2254
|
+
* stable `code`, the part it happened in, the best position that part can
|
|
2255
|
+
* name, and the value folio declined to read. A host can count them, group
|
|
2256
|
+
* them, or decide on one; the human-readable string the parser has always
|
|
2257
|
+
* exposed is derived from this, never written by hand at the call site, so the
|
|
2258
|
+
* two cannot drift.
|
|
2259
|
+
*
|
|
2260
|
+
* It lives beside `Document` because it is part of the parsed document, and a
|
|
2261
|
+
* `Document` may be produced by anything that builds this model.
|
|
2262
|
+
*/
|
|
2263
|
+
/**
|
|
2264
|
+
* Every normalisation the parse boundary is allowed to make.
|
|
2265
|
+
*
|
|
2266
|
+
* Adding a member without also giving it a message is a type error: the
|
|
2267
|
+
* formatter map over this union is total.
|
|
2268
|
+
*/
|
|
2269
|
+
declare const PARSE_WARNING_CODES: {
|
|
2270
|
+
/** A package opened from encrypted storage; a save writes it unencrypted. */
|
|
2271
|
+
readonly packageDecrypted: "package-decrypted";
|
|
2272
|
+
/** The archive reader reported something about the package it opened. */
|
|
2273
|
+
readonly packageArchive: "package-archive";
|
|
2274
|
+
/** The main document part is missing; the body is empty. */
|
|
2275
|
+
readonly documentPartMissing: "document-part-missing";
|
|
2276
|
+
/** The model validator reported an issue the parse did not treat as fatal. */
|
|
2277
|
+
readonly documentModelIssue: "document-model-issue";
|
|
2278
|
+
/** A later `w:comment` repeating a `w:id` an earlier one defines. */
|
|
2279
|
+
readonly duplicateCommentId: "duplicate-comment-id";
|
|
2280
|
+
/** A `w:comment` with no readable `w:id`; it can anchor nothing. */
|
|
2281
|
+
readonly missingCommentId: "missing-comment-id";
|
|
2282
|
+
/** A later `w:footnote`/`w:endnote` repeating an id an earlier one defines. */
|
|
2283
|
+
readonly duplicateNoteId: "duplicate-note-id";
|
|
2284
|
+
/** A comment marker naming a comment `comments.xml` never defines. */
|
|
2285
|
+
readonly danglingCommentReference: "dangling-comment-reference";
|
|
2286
|
+
/** A comment range with no matching start or end, re-anchored as a point. */
|
|
2287
|
+
readonly unbalancedCommentRange: "unbalanced-comment-range";
|
|
2288
|
+
/** A `w:headerReference` naming a header part the package does not carry. */
|
|
2289
|
+
readonly danglingHeaderReference: "dangling-header-reference";
|
|
2290
|
+
/** A `w:footerReference` naming a footer part the package does not carry. */
|
|
2291
|
+
readonly danglingFooterReference: "dangling-footer-reference";
|
|
2292
|
+
/** A `r:id` naming a relationship the part's `.rels` does not define. */
|
|
2293
|
+
readonly danglingRelationshipId: "dangling-relationship-id";
|
|
2294
|
+
/** A paragraph naming a `w:num` the numbering part never defines. */
|
|
2295
|
+
readonly unnumberedParagraph: "unnumbered-paragraph";
|
|
2296
|
+
/** A style naming a `w:num` the numbering part never defines. */
|
|
2297
|
+
readonly unnumberedStyle: "unnumbered-style";
|
|
2298
|
+
/** A tracked move range with no matching start or end. */
|
|
2299
|
+
readonly unbalancedMoveRange: "unbalanced-move-range";
|
|
2300
|
+
/** A `w:type` outside `ST_HdrFtr`, read as the enumeration's default. */
|
|
2301
|
+
readonly headerFooterTypeOutsideEnum: "header-footer-type-outside-enum";
|
|
2302
|
+
/** A value outside `ST_OnOff`'s six spellings. */
|
|
2303
|
+
readonly unrecognisedOnOffValue: "unrecognised-on-off-value";
|
|
2304
|
+
/** A `CT_Border` with no `w:val`, which has no border style to read. */
|
|
2305
|
+
readonly borderWithoutValue: "border-without-value";
|
|
2306
|
+
/** A style set defining two styles under one id. */
|
|
2307
|
+
readonly styleSetDuplicateStyleId: "style-set-duplicate-style-id";
|
|
2308
|
+
/** A style set naming an initial paragraph style it does not contain. */
|
|
2309
|
+
readonly styleSetInitialStyleMissing: "style-set-initial-style-missing";
|
|
2310
|
+
};
|
|
2311
|
+
type ParseWarningCode = (typeof PARSE_WARNING_CODES)[keyof typeof PARSE_WARNING_CODES];
|
|
2312
|
+
/** Where a warning happened, as precisely as the part can say. */
|
|
2313
|
+
type ParseWarningLocation = {
|
|
2314
|
+
/** The package part, e.g. `word/document.xml`. `package` for the container. */
|
|
2315
|
+
part: string;
|
|
2316
|
+
/** The element as written, prefix included, when one is known. */
|
|
2317
|
+
element?: string;
|
|
2318
|
+
/**
|
|
2319
|
+
* The best position the part can name: `paragraph 12`, `style "Heading1"`,
|
|
2320
|
+
* `w:id 4`. Free-form because what identifies a place differs per part, and
|
|
2321
|
+
* a byte offset is not available once the tree is built.
|
|
2322
|
+
*/
|
|
2323
|
+
at?: string;
|
|
2324
|
+
};
|
|
2325
|
+
type ParseWarning = {
|
|
2326
|
+
code: ParseWarningCode;
|
|
2327
|
+
location: ParseWarningLocation;
|
|
2328
|
+
/** The value folio declined to read, exactly as the source wrote it. */
|
|
2329
|
+
value?: string;
|
|
2330
|
+
/** How many occurrences this entry stands for; at least 1. */
|
|
2331
|
+
count: number;
|
|
2332
|
+
/**
|
|
2333
|
+
* Text from the owner that produced it, for the codes that pass a message
|
|
2334
|
+
* through from the archive reader or the model validator.
|
|
2335
|
+
*/
|
|
2336
|
+
detail?: string;
|
|
2337
|
+
};
|
|
2338
|
+
/**
|
|
2339
|
+
* The cap on retained warnings per code.
|
|
2340
|
+
*
|
|
2341
|
+
* A generated document can repeat one defect on every paragraph, and a host
|
|
2342
|
+
* that only wants to know a defect occurred should not pay for a hundred
|
|
2343
|
+
* thousand records. Occurrences past the cap are counted, not kept.
|
|
2344
|
+
*/
|
|
2345
|
+
declare const MAX_RETAINED_PARSE_WARNINGS_PER_CODE = 20;
|
|
2346
|
+
//#endregion
|
|
2112
2347
|
//#region src/model/styles.d.ts
|
|
2113
2348
|
/**
|
|
2114
2349
|
* Style type
|
|
@@ -2328,6 +2563,23 @@ type MediaFile = {
|
|
|
2328
2563
|
dataUrl?: string;
|
|
2329
2564
|
};
|
|
2330
2565
|
//#endregion
|
|
2566
|
+
//#region src/model/exhaustiveFields.d.ts
|
|
2567
|
+
/**
|
|
2568
|
+
* Compile-time totality over every field of a model type.
|
|
2569
|
+
*
|
|
2570
|
+
* `ExhaustiveFields<Source, Classified>` resolves to `Source` while
|
|
2571
|
+
* `Classified` names every key of `Source`, and to `never` otherwise. Alias it
|
|
2572
|
+
* next to a table that must decide something per field, and a field added to
|
|
2573
|
+
* the model without a decision turns the alias into `never`, so the module
|
|
2574
|
+
* stops compiling instead of silently dropping the field.
|
|
2575
|
+
*
|
|
2576
|
+
* ```ts
|
|
2577
|
+
* type ClassifiedBorderField = "style" | "color" | "size";
|
|
2578
|
+
* type ExhaustiveBorder = ExhaustiveFields<BorderSpec, ClassifiedBorderField>;
|
|
2579
|
+
* ```
|
|
2580
|
+
*/
|
|
2581
|
+
type ExhaustiveFields<Source, Classified extends keyof Source> = Exclude<keyof Source, Classified> extends never ? Source : never;
|
|
2582
|
+
//#endregion
|
|
2331
2583
|
//#region src/model/document.d.ts
|
|
2332
2584
|
/**
|
|
2333
2585
|
* Document-wide settings parsed from `word/settings.xml`.
|
|
@@ -2460,8 +2712,10 @@ type Document = {
|
|
|
2460
2712
|
templateVariables?: string[];
|
|
2461
2713
|
/** Font families referenced in the document (extracted during parsing for deferred loading) */
|
|
2462
2714
|
requiredFonts?: string[];
|
|
2463
|
-
/** Parsing warnings/errors */
|
|
2715
|
+
/** Parsing warnings/errors, each one rendered from `parseWarnings`. */
|
|
2464
2716
|
warnings?: string[];
|
|
2717
|
+
/** The same warnings as data: a stable code, a location, and the value. */
|
|
2718
|
+
parseWarnings?: ParseWarning[];
|
|
2465
2719
|
};
|
|
2466
2720
|
//#endregion
|
|
2467
|
-
export {
|
|
2721
|
+
export { FieldType as $, TableRowFormatting as $n, SectionStart as $t, BlockRangeMarkerCapture as A, ListLevel as An, NoBreakHyphenContent as At, CommentReference as B, LineSpacingRule as Bn, PictureWatermark as Bt, ParseWarning as C, TrackedRunContent as Cn, MoveBookmarkMarker as Ct, BidiControl as D, normalizeRevisionId as Dn, MoveTo as Dt, BIDI_CONTROLS as E, isOoxmlSymbolCharacter as En, MoveFromRangeStart as Et, BreakContent as F, NumberingInstance as Fn, Paragraph as Ft, DocumentBody as G, TabStop as Gn, Run as Gt, DRAWING_RAW_XML_MODES as H, ParagraphFormatting as Hn, PropertyChangeInfo as Ht, Column as I, CellMargins as In, ParagraphContent as It, Endnote as J, TableCellBorders as Jn, SdtProperties as Jt, DrawingContent as K, TabStopAlignment as Kn, RunContent as Kt, Comment as L, ConditionalFormatStyle as Ln, ParagraphMarkChange as Lt, BookmarkEnd as M, ListRendering as Mn, NoteReferenceContent as Mt, BookmarkRangeMarker as N, NumberFormat as Nn, PARAGRAPH_MARK_CHANGE_KINDS as Nt, BidiWrapper as O, AbstractNumbering as On, MoveToRangeEnd as Ot, BookmarkStart as P, NumberingDefinitions as Pn, PageOrientation as Pt, FieldCharContent as Q, TableMeasurement as Qn, SectionPropertyChange as Qt, CommentRangeEnd as R, EmphasisMark as Rn, ParagraphMarkChangeKind as Rt, PARSE_WARNING_CODES as S, TrackedRunChange as Sn, MathEquation as St, ParseWarningLocation as T, Watermark as Tn, MoveFromRangeEnd as Tt, Deletion as U, SpacingExplicit as Un, REVIEW_CARRIERS as Ut, ComplexField as V, ParagraphAlignment as Vn, PositionalTab as Vt, DisplacedByCustomXml as W, TabLeader as Wn, ReviewCarrier as Wt, EndnoteProperties as X, TableFormatting as Xn, Section as Xt, EndnotePosition as Y, TableCellFormatting as Yn, SdtType as Yt, Field as Z, TableLook as Zn, SectionProperties as Zt, Theme as _, TableStructuralChangeInfo as _n, Insertion as _t, DocxPackage as a, ShapeTextBody as an, ColorValue as ar, HeaderFooterType as at, ThemeFontScheme as b, TextWatermark as bn, MAX_REVISION_ID as bt, FontInfo as c, SoftHyphenContent as cn, ThemeColorSlot as cr, Image as ct, Relationship as d, Table as dn, ImagePadding as dt, Shape as en, TableWidthType as er, FooterReference as et, RelationshipMap as f, TableCell as fn, ImagePosition as ft, StyleType as g, TableRowPropertyChange as gn, InlineSdt as gt, StyleDefinitions as h, TableRow as hn, ImageWrap as ht, DocxConformanceClass as i, ShapeOutline as in, BorderSpec as ir, HeaderFooter as it, BlockSdt as j, ListMarkerFormatting as jn, NoteNumberRestart as jt, BlockContent as k, LevelSuffix as kn, MoveToRangeStart as kt, FontTable as l, SymbolContent as ln, ImageCrop as lt, Style as m, TablePropertyChange as mn, ImageTransform as mt, Document as n, ShapeFill as nn, TextFormatting as nr, FootnotePosition as nt, ExhaustiveFields as o, ShapeType as on, KnownBorderStyle as or, HeaderReference as ot, RelationshipType as p, TableCellPropertyChange as pn, ImageSize as pt, DrawingRawXmlMode as q, TableBorders as qn, RunPropertyChange as qt, DocumentSettings as r, ShapeGeometryAdjustment as rn, UnderlineStyle as rr, FootnoteProperties as rt, DocDefaults as s, SimpleField as sn, ShadingProperties as sr, Hyperlink as st, DOCX_CONFORMANCE_CLASSES as t, ShapeContent as tn, TextEffect as tr, Footnote as tt, MediaFile as u, TabContent as un, ImageFrameLocks as ut, ThemeColorScheme as v, TextBox as vn, InstrTextContent as vt, ParseWarningCode as w, VerticalAlign as wn, MoveFrom as wt, MAX_RETAINED_PARSE_WARNINGS_PER_CODE as x, TrackedChangeInfo as xn, MarkupRangeMarker as xt, ThemeFont as y, TextContent as yn, LineNumberRestart as yt, CommentRangeStart as z, FloatingTableProperties as zn, ParagraphPropertyChange as zt };
|
package/dist/docx_kernel_bg.wasm
CHANGED
|
Binary file
|