@stll/docx-core 0.4.0 → 0.5.1
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.
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/model/content.ts
|
|
2
|
+
/**
|
|
3
|
+
* Largest value a revision id (`w:id`) may carry: 2^31 - 1.
|
|
4
|
+
*
|
|
5
|
+
* `w:id` on `<w:ins>`/`<w:del>` comes from `CT_Markup`, typed
|
|
6
|
+
* `ST_DecimalNumber` — which ECMA-376 defines as an unbounded integer. The
|
|
7
|
+
* bound below is an implementation limit: conforming consumers read
|
|
8
|
+
* `ST_DecimalNumber` into a signed 32-bit int, and a value past this bound
|
|
9
|
+
* overflows on load and surfaces as an unreadable document. Port of
|
|
10
|
+
* eigenpal/docx-editor#1093.
|
|
11
|
+
*/
|
|
12
|
+
const MAX_REVISION_ID = 2147483647;
|
|
13
|
+
/**
|
|
14
|
+
* Coerce any revision id — including one parsed from an untrusted DOCX — into
|
|
15
|
+
* the range serialized `w:id` attributes may occupy.
|
|
16
|
+
*
|
|
17
|
+
* - Malformed (negative, fractional, `NaN`, `Infinity`): collapse to `0`.
|
|
18
|
+
* - Well-formed but out of range: fold modulo the range (not clamp) so a
|
|
19
|
+
* contiguous run of overflowing ids stays distinguishable.
|
|
20
|
+
*/
|
|
21
|
+
function normalizeRevisionId(id) {
|
|
22
|
+
if (!Number.isInteger(id) || id < 0) return 0;
|
|
23
|
+
if (id > 2147483647) return id % 2147483648;
|
|
24
|
+
return id;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/model/document.ts
|
|
28
|
+
/** DOCX package conformance classes. */
|
|
29
|
+
const DOCX_CONFORMANCE_CLASSES = Object.freeze({
|
|
30
|
+
STRICT: "strict",
|
|
31
|
+
TRANSITIONAL: "transitional",
|
|
32
|
+
UNKNOWN: "unknown"
|
|
33
|
+
});
|
|
34
|
+
//#endregion
|
|
35
|
+
export { MAX_REVISION_ID as n, normalizeRevisionId as r, DOCX_CONFORMANCE_CLASSES as t };
|