@stll/docx-core 0.23.0 → 0.25.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.
@@ -1,153 +0,0 @@
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 };