@stll/docx-core 0.24.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.
@@ -0,0 +1,461 @@
1
+ import { TaggedError } from "better-result";
2
+ import { OOXML_NS } from "@stll/docx-utils";
3
+ import { XMLParser, XMLValidator } from "fast-xml-parser";
4
+ //#region src/schema/sequenceChildren.gen.ts
5
+ /**
6
+ * GENERATED FILE — do not edit.
7
+ *
8
+ * The containers whose content model declares one order for its children, with
9
+ * the children written in it, derived from the committed schema graph by
10
+ * `scripts/generate-container-children.ts`.
11
+ *
12
+ * It lives in the lower package because two packages write a property set and
13
+ * the dependency runs one way: `@stll/docx-core` compiles a `w:rPr` from a
14
+ * legal source and cannot import `@stll/folio-core`. folio-core's
15
+ * declared-child table spreads this one in, so both write the same order and
16
+ * neither restates it.
17
+ *
18
+ * Regenerate with:
19
+ *
20
+ * bun run generate:container-children
21
+ */
22
+ const SEQUENCE_CHILDREN = {
23
+ "w:numbering": [
24
+ "numPicBullet",
25
+ "abstractNum",
26
+ "num",
27
+ "numIdMacAtCleanup"
28
+ ],
29
+ "w:abstractNum": [
30
+ "nsid",
31
+ "multiLevelType",
32
+ "tmpl",
33
+ "name",
34
+ "styleLink",
35
+ "numStyleLink",
36
+ "lvl"
37
+ ],
38
+ "w:lvl": [
39
+ "start",
40
+ "numFmt",
41
+ "lvlRestart",
42
+ "pStyle",
43
+ "isLgl",
44
+ "suff",
45
+ "lvlText",
46
+ "lvlPicBulletId",
47
+ "legacy",
48
+ "lvlJc",
49
+ "pPr",
50
+ "rPr"
51
+ ],
52
+ "w:num": ["abstractNumId", "lvlOverride"],
53
+ "w:lvlOverride": ["startOverride", "lvl"],
54
+ "paragraph-properties": [
55
+ "pStyle",
56
+ "keepNext",
57
+ "keepLines",
58
+ "pageBreakBefore",
59
+ "framePr",
60
+ "widowControl",
61
+ "numPr",
62
+ "suppressLineNumbers",
63
+ "pBdr",
64
+ "shd",
65
+ "tabs",
66
+ "suppressAutoHyphens",
67
+ "kinsoku",
68
+ "wordWrap",
69
+ "overflowPunct",
70
+ "topLinePunct",
71
+ "autoSpaceDE",
72
+ "autoSpaceDN",
73
+ "bidi",
74
+ "adjustRightInd",
75
+ "snapToGrid",
76
+ "spacing",
77
+ "ind",
78
+ "contextualSpacing",
79
+ "mirrorIndents",
80
+ "suppressOverlap",
81
+ "jc",
82
+ "textDirection",
83
+ "textAlignment",
84
+ "textboxTightWrap",
85
+ "outlineLvl",
86
+ "divId",
87
+ "cnfStyle",
88
+ "rPr",
89
+ "sectPr",
90
+ "pPrChange"
91
+ ],
92
+ "table-properties": [
93
+ "tblStyle",
94
+ "tblpPr",
95
+ "tblOverlap",
96
+ "bidiVisual",
97
+ "tblStyleRowBandSize",
98
+ "tblStyleColBandSize",
99
+ "tblW",
100
+ "jc",
101
+ "tblCellSpacing",
102
+ "tblInd",
103
+ "tblBorders",
104
+ "shd",
105
+ "tblLayout",
106
+ "tblCellMar",
107
+ "tblLook",
108
+ "tblCaption",
109
+ "tblDescription",
110
+ "tblPrChange"
111
+ ],
112
+ "table-property-exceptions": [
113
+ "tblW",
114
+ "jc",
115
+ "tblCellSpacing",
116
+ "tblInd",
117
+ "tblBorders",
118
+ "shd",
119
+ "tblLayout",
120
+ "tblCellMar",
121
+ "tblLook",
122
+ "tblPrExChange"
123
+ ],
124
+ "row-properties": [
125
+ "cnfStyle",
126
+ "divId",
127
+ "gridBefore",
128
+ "gridAfter",
129
+ "wBefore",
130
+ "wAfter",
131
+ "cantSplit",
132
+ "trHeight",
133
+ "tblHeader",
134
+ "tblCellSpacing",
135
+ "jc",
136
+ "hidden",
137
+ "ins",
138
+ "del",
139
+ "trPrChange"
140
+ ],
141
+ "cell-properties": [
142
+ "cnfStyle",
143
+ "tcW",
144
+ "gridSpan",
145
+ "hMerge",
146
+ "vMerge",
147
+ "tcBorders",
148
+ "shd",
149
+ "noWrap",
150
+ "tcMar",
151
+ "textDirection",
152
+ "tcFitText",
153
+ "vAlign",
154
+ "hideMark",
155
+ "headers",
156
+ "cellIns",
157
+ "cellDel",
158
+ "cellMerge",
159
+ "tcPrChange"
160
+ ],
161
+ "run-properties": [
162
+ "ins",
163
+ "del",
164
+ "moveFrom",
165
+ "moveTo",
166
+ "rStyle",
167
+ "rFonts",
168
+ "b",
169
+ "bCs",
170
+ "i",
171
+ "iCs",
172
+ "caps",
173
+ "smallCaps",
174
+ "strike",
175
+ "dstrike",
176
+ "outline",
177
+ "shadow",
178
+ "emboss",
179
+ "imprint",
180
+ "noProof",
181
+ "snapToGrid",
182
+ "vanish",
183
+ "webHidden",
184
+ "color",
185
+ "spacing",
186
+ "w",
187
+ "kern",
188
+ "position",
189
+ "sz",
190
+ "szCs",
191
+ "highlight",
192
+ "u",
193
+ "effect",
194
+ "bdr",
195
+ "shd",
196
+ "fitText",
197
+ "vertAlign",
198
+ "rtl",
199
+ "cs",
200
+ "em",
201
+ "lang",
202
+ "eastAsianLayout",
203
+ "specVanish",
204
+ "oMath",
205
+ "rPrChange"
206
+ ],
207
+ "content-control-properties": [
208
+ "rPr",
209
+ "alias",
210
+ "tag",
211
+ "id",
212
+ "lock",
213
+ "placeholder",
214
+ "temporary",
215
+ "showingPlcHdr",
216
+ "dataBinding",
217
+ "label",
218
+ "tabIndex",
219
+ "equation",
220
+ "comboBox",
221
+ "date",
222
+ "docPartObj",
223
+ "docPartList",
224
+ "dropDownList",
225
+ "picture",
226
+ "richText",
227
+ "text",
228
+ "citation",
229
+ "group",
230
+ "bibliography"
231
+ ],
232
+ "section-properties": [
233
+ "headerReference",
234
+ "footerReference",
235
+ "footnotePr",
236
+ "endnotePr",
237
+ "type",
238
+ "pgSz",
239
+ "pgMar",
240
+ "paperSrc",
241
+ "pgBorders",
242
+ "lnNumType",
243
+ "pgNumType",
244
+ "cols",
245
+ "formProt",
246
+ "vAlign",
247
+ "noEndnote",
248
+ "titlePg",
249
+ "textDirection",
250
+ "bidi",
251
+ "rtlGutter",
252
+ "docGrid",
253
+ "printerSettings",
254
+ "sectPrChange"
255
+ ]
256
+ };
257
+ //#endregion
258
+ //#region src/schema/sequenceChildren.ts
259
+ const MAX_PRESERVED_CHILD_XML_CHARACTERS = 1024 * 1024;
260
+ const MAX_PRESERVED_CHILD_COUNT = 4096;
261
+ const MAX_PRESERVED_MARKUP_CHARACTERS = 4 * 1024 * 1024;
262
+ const PRESERVED_CHILD_WRAPPER = "folio-preserved-child-root";
263
+ const preservedChildParser = new XMLParser({
264
+ preserveOrder: true,
265
+ ignoreAttributes: false,
266
+ attributeNamePrefix: "",
267
+ trimValues: false,
268
+ parseTagValue: false,
269
+ parseAttributeValue: false,
270
+ ignoreDeclaration: false,
271
+ ignorePiTags: false,
272
+ processEntities: false,
273
+ htmlEntities: false
274
+ });
275
+ var InvalidPreservedChildXmlError = class extends TaggedError("InvalidPreservedChildXmlError") {};
276
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
277
+ const XML_NAMESPACE_URI = "http://www.w3.org/XML/1998/namespace";
278
+ const XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/";
279
+ const PREDEFINED_XML_ENTITIES = /* @__PURE__ */ new Set([
280
+ "amp",
281
+ "apos",
282
+ "gt",
283
+ "lt",
284
+ "quot"
285
+ ]);
286
+ const INHERITED_NAMESPACE_BINDINGS = new Map([...Object.entries(OOXML_NS), ["xml", XML_NAMESPACE_URI]]);
287
+ const isXmlCharacter = (codePoint) => codePoint === 9 || codePoint === 10 || codePoint === 13 || codePoint >= 32 && codePoint <= 55295 || codePoint >= 57344 && codePoint <= 65533 || codePoint >= 65536 && codePoint <= 1114111;
288
+ const isValidXmlReference = (reference) => {
289
+ if (PREDEFINED_XML_ENTITIES.has(reference)) return true;
290
+ if (/^#[0-9]+$/u.test(reference)) return isXmlCharacter(Number(reference.slice(1)));
291
+ if (/^#x[0-9a-fA-F]+$/u.test(reference)) return isXmlCharacter(Number.parseInt(reference.slice(2), 16));
292
+ return false;
293
+ };
294
+ /** Validate references only where XML treats them as references. */
295
+ const hasOnlyValidXmlReferences = (xml) => {
296
+ let index = 0;
297
+ while (index < xml.length) {
298
+ if (xml.startsWith("<![CDATA[", index)) {
299
+ const end = xml.indexOf("]]>", index + 9);
300
+ if (end === -1) return false;
301
+ index = end + 3;
302
+ continue;
303
+ }
304
+ if (xml.startsWith("<!--", index)) {
305
+ const end = xml.indexOf("-->", index + 4);
306
+ if (end === -1) return false;
307
+ index = end + 3;
308
+ continue;
309
+ }
310
+ if (xml.startsWith("<?", index)) {
311
+ const end = xml.indexOf("?>", index + 2);
312
+ if (end === -1) return false;
313
+ index = end + 2;
314
+ continue;
315
+ }
316
+ if (xml[index] !== "&") {
317
+ index += 1;
318
+ continue;
319
+ }
320
+ const end = xml.indexOf(";", index + 1);
321
+ if (end === -1 || !isValidXmlReference(xml.slice(index + 1, end))) return false;
322
+ index = end + 1;
323
+ }
324
+ return true;
325
+ };
326
+ const namespacePrefix = (qualifiedName) => {
327
+ const colon = qualifiedName.indexOf(":");
328
+ return colon > 0 ? qualifiedName.slice(0, colon) : void 0;
329
+ };
330
+ const applyNamespaceDeclarations = (attributes, inherited) => {
331
+ let bindings;
332
+ for (const [name, rawValue] of Object.entries(attributes)) {
333
+ if (name !== "xmlns" && !name.startsWith("xmlns:")) continue;
334
+ if (typeof rawValue !== "string") return;
335
+ const prefix = name === "xmlns" ? "" : name.slice(6);
336
+ const lowerPrefix = prefix.toLowerCase();
337
+ if (prefix === "xmlns" || lowerPrefix.startsWith("xml") && prefix !== "xml" || prefix === "xml" && rawValue !== XML_NAMESPACE_URI || prefix !== "xml" && rawValue === XML_NAMESPACE_URI || rawValue === XMLNS_NAMESPACE_URI || prefix !== "" && rawValue === "") return;
338
+ const protectedBinding = INHERITED_NAMESPACE_BINDINGS.get(prefix);
339
+ if (protectedBinding !== void 0 && protectedBinding !== rawValue) return;
340
+ bindings ??= new Map(inherited);
341
+ bindings.set(prefix, rawValue);
342
+ }
343
+ return bindings ?? inherited;
344
+ };
345
+ const hasValidNamespaces = (root, inherited) => {
346
+ const pending = [{
347
+ node: root,
348
+ bindings: inherited
349
+ }];
350
+ while (pending.length > 0) {
351
+ const current = pending.pop();
352
+ if (current === void 0) continue;
353
+ const { node, bindings: parentBindings } = current;
354
+ const nodeNames = Object.keys(node).filter((name) => name !== ":@");
355
+ const name = nodeNames[0];
356
+ if (nodeNames.length !== 1 || name === void 0) return false;
357
+ if (name.startsWith("#") || name.startsWith("?") || name.startsWith("!")) continue;
358
+ const rawAttributes = node[":@"];
359
+ const attributes = isRecord(rawAttributes) ? rawAttributes : {};
360
+ const bindings = applyNamespaceDeclarations(attributes, parentBindings);
361
+ if (bindings === void 0) return false;
362
+ const elementPrefix = namespacePrefix(name);
363
+ if (elementPrefix !== void 0 && !bindings.has(elementPrefix)) return false;
364
+ const expandedAttributeNames = /* @__PURE__ */ new Set();
365
+ for (const attributeName of Object.keys(attributes)) {
366
+ if (attributeName === "xmlns" || attributeName.startsWith("xmlns:")) continue;
367
+ const attributePrefix = namespacePrefix(attributeName);
368
+ if (attributePrefix !== void 0 && !bindings.has(attributePrefix)) return false;
369
+ const namespace = attributePrefix === void 0 ? "" : bindings.get(attributePrefix);
370
+ const colon = attributeName.indexOf(":");
371
+ const localName = colon === -1 ? attributeName : attributeName.slice(colon + 1);
372
+ const expandedName = `${namespace ?? ""}\u0000${localName}`;
373
+ if (expandedAttributeNames.has(expandedName)) return false;
374
+ expandedAttributeNames.add(expandedName);
375
+ }
376
+ const children = node[name];
377
+ if (!Array.isArray(children)) return false;
378
+ for (const child of children) {
379
+ if (!isRecord(child)) return false;
380
+ pending.push({
381
+ node: child,
382
+ bindings
383
+ });
384
+ }
385
+ }
386
+ return true;
387
+ };
388
+ /** Whether a captured child is exactly one bounded, well-formed XML element. */
389
+ const isSafePreservedChildXml = (xml) => {
390
+ const trimmed = xml.trim();
391
+ if (trimmed.length === 0 || trimmed.length > MAX_PRESERVED_CHILD_XML_CHARACTERS || /<!\s*(?:DOCTYPE|ENTITY)\b/iu.test(trimmed) || !hasOnlyValidXmlReferences(trimmed)) return false;
392
+ const wrapped = `<${PRESERVED_CHILD_WRAPPER}>${trimmed}</${PRESERVED_CHILD_WRAPPER}>`;
393
+ if (XMLValidator.validate(wrapped) !== true) return false;
394
+ let parsed;
395
+ try {
396
+ parsed = preservedChildParser.parse(wrapped);
397
+ } catch {
398
+ return false;
399
+ }
400
+ if (!Array.isArray(parsed) || parsed.length !== 1) return false;
401
+ const wrapper = parsed[0];
402
+ if (!isRecord(wrapper)) return false;
403
+ const children = wrapper[PRESERVED_CHILD_WRAPPER];
404
+ if (!Array.isArray(children) || children.length !== 1) return false;
405
+ const child = children[0];
406
+ if (!isRecord(child)) return false;
407
+ const nodeNames = Object.keys(child).filter((name) => name !== ":@");
408
+ const nodeName = nodeNames[0];
409
+ return nodeNames.length === 1 && nodeName !== void 0 && !nodeName.startsWith("#") && !nodeName.startsWith("?") && !nodeName.startsWith("!") && hasValidNamespaces(child, INHERITED_NAMESPACE_BINDINGS);
410
+ };
411
+ /** Whether a capture collection stays within its aggregate resource budget. */
412
+ const isWithinPreservedMarkupBudget = (children) => {
413
+ if (children.length > MAX_PRESERVED_CHILD_COUNT) return false;
414
+ let characters = 0;
415
+ for (const child of children) {
416
+ if (!isRecord(child)) continue;
417
+ const xml = child["xml"];
418
+ if (typeof xml !== "string") continue;
419
+ characters += xml.length;
420
+ if (characters > MAX_PRESERVED_MARKUP_CHARACTERS) return false;
421
+ }
422
+ return true;
423
+ };
424
+ /** Reject unsafe captured children before a caller performs any transformation. */
425
+ const assertSafePreservedMarkup = (preserved) => {
426
+ const children = preserved?.children ?? [];
427
+ if (!isWithinPreservedMarkupBudget(children)) throw new InvalidPreservedChildXmlError({
428
+ message: "Preserved container markup exceeds its aggregate resource budget",
429
+ index: -1
430
+ });
431
+ for (const { index, xml } of children) if (!isSafePreservedChildXml(xml)) throw new InvalidPreservedChildXmlError({
432
+ message: "Preserved container markup must be one bounded, well-formed XML element",
433
+ index
434
+ });
435
+ };
436
+ /**
437
+ * A property set's children, modelled and captured, in schema order.
438
+ *
439
+ * Ties are only possible between a declared child and a capture sharing its
440
+ * slot — an undeclared name takes the place of the last declared child before
441
+ * it. The sort is stable and the modelled child leads.
442
+ */
443
+ const serializeSequenceChildren = ({ container, modelled, preserved }) => {
444
+ const declared = SEQUENCE_CHILDREN[container];
445
+ const placed = [];
446
+ for (const [name, xml] of modelled) if (xml.length > 0) placed.push({
447
+ at: declared.indexOf(name),
448
+ rank: 0,
449
+ xml
450
+ });
451
+ const preservedChildren = preserved?.children ?? [];
452
+ assertSafePreservedMarkup(preserved);
453
+ for (const { index, xml } of preservedChildren) placed.push({
454
+ at: index,
455
+ rank: 1,
456
+ xml
457
+ });
458
+ return placed.sort((left, right) => left.at - right.at || left.rank - right.rank).map(({ xml }) => xml);
459
+ };
460
+ //#endregion
461
+ export { SEQUENCE_CHILDREN as a, serializeSequenceChildren as i, isSafePreservedChildXml as n, isWithinPreservedMarkupBudget as r, assertSafePreservedMarkup as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/docx-core",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "description": "Typed OOXML/DOCX model, validation, serialization, legal-source compilation, and browser-native package projection.",
5
5
  "keywords": [
6
6
  "document-model",
@@ -43,6 +43,10 @@
43
43
  "./projection": {
44
44
  "types": "./dist/projection.d.ts",
45
45
  "import": "./dist/projection.js"
46
+ },
47
+ "./schema": {
48
+ "types": "./dist/schema/sequenceChildren.d.ts",
49
+ "import": "./dist/schema/sequenceChildren.js"
46
50
  }
47
51
  },
48
52
  "publishConfig": {
@@ -60,6 +64,7 @@
60
64
  "prepack": "bun run build"
61
65
  },
62
66
  "dependencies": {
67
+ "@stll/docx-utils": "^0.1.0",
63
68
  "better-result": "3.0.1",
64
69
  "fast-xml-parser": "^5.10.1",
65
70
  "jszip": "3.10.1",
@@ -1,155 +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
- /** An explicit page-break run the editable model lays out approximately. */
64
- pageBreakProjectionApproximated: "page-break-projection-approximated"
65
- };
66
- /**
67
- * The cap on retained warnings per code.
68
- *
69
- * A generated document can repeat one defect on every paragraph, and a host
70
- * that only wants to know a defect occurred should not pay for a hundred
71
- * thousand records. Occurrences past the cap are counted, not kept.
72
- */
73
- const MAX_RETAINED_PARSE_WARNINGS_PER_CODE = 20;
74
- //#endregion
75
- //#region src/model/content.ts
76
- const OOXML_SYMBOL_CHARACTER_PATTERN = /^[\dA-Fa-f]{4}$/u;
77
- /** Whether a symbol character is exactly four hexadecimal digits. */
78
- const isOoxmlSymbolCharacter = (value) => OOXML_SYMBOL_CHARACTER_PATTERN.test(value);
79
- /** Raw XML handling modes for drawings that Folio cannot model completely. */
80
- const DRAWING_RAW_XML_MODES = {
81
- PRESERVE_ONLY: "preserveOnly",
82
- /** The modeled image is a rendered preview of richer markup, so regeneration cannot reproduce the drawing. */
83
- PREVIEW_ONLY: "previewOnly"
84
- };
85
- /**
86
- * Largest value a revision id (`w:id`) may carry: 2^31 - 1.
87
- *
88
- * `w:id` on `<w:ins>`/`<w:del>` comes from `CT_Markup`, typed
89
- * `ST_DecimalNumber` — which ECMA-376 defines as an unbounded integer. The
90
- * bound below is an implementation limit: conforming consumers read
91
- * `ST_DecimalNumber` into a signed 32-bit int, and a value past this bound
92
- * overflows on load and surfaces as an unreadable document. Port of
93
- * eigenpal/docx-editor#1093.
94
- */
95
- const MAX_REVISION_ID = 2147483647;
96
- /**
97
- * Coerce any revision id — including one parsed from an untrusted DOCX — into
98
- * the range serialized `w:id` attributes may occupy.
99
- *
100
- * - Malformed (negative, fractional, `NaN`, `Infinity`): collapse to `0`.
101
- * - Well-formed but out of range: fold modulo the range (not clamp) so a
102
- * contiguous run of overflowing ids stays distinguishable.
103
- */
104
- function normalizeRevisionId(id) {
105
- if (!Number.isInteger(id) || id < 0) return 0;
106
- if (id > 2147483647) return id % 2147483648;
107
- return id;
108
- }
109
- /**
110
- * Which Unicode bidirectional control a `w:bdo`/`w:dir` wrapper is.
111
- *
112
- * `w:dir` is an embedding: the run of text inside it is laid out in the given
113
- * direction and the bidirectional algorithm still resolves the characters
114
- * within it. `w:bdo` is an override: the algorithm is switched off inside and
115
- * every character is laid out in the given direction, which is what makes a
116
- * Latin word inside an `rtl` override read backwards. CSS spells the pair
117
- * `unicode-bidi: embed` and `unicode-bidi: bidi-override`, and HTML gives the
118
- * second an element of its own, `<bdo>`.
119
- */
120
- const BIDI_CONTROLS = {
121
- embedding: "embedding",
122
- override: "override"
123
- };
124
- /**
125
- * The kinds a paragraph-mark tracked change can be (ECMA-376 §17.13.5).
126
- *
127
- * Written as a child of `<w:pPr><w:rPr>` — `<w:ins/>` when the paragraph
128
- * break itself was inserted in track-changes mode (the user pressed Enter
129
- * mid-paragraph), `<w:del/>` when the paragraph break is pending deletion
130
- * (Backspace at paragraph start or Delete at paragraph end). The mark is
131
- * independent of the inline runs the paragraph carries.
132
- *
133
- * A relocated paragraph's break is `<w:moveFrom/>` at the source and
134
- * `<w:moveTo/>` at the destination. They resolve exactly as `del` and `ins`
135
- * do — a move is a deletion and an insertion that a reader is told belong
136
- * together — but they are not those kinds: writing `w:del` on a moved
137
- * paragraph's mark reports the relocation as a deletion as well.
138
- */
139
- const PARAGRAPH_MARK_CHANGE_KINDS = Object.freeze([
140
- "moveFrom",
141
- "moveTo",
142
- "ins",
143
- "del"
144
- ]);
145
- const REVIEW_CARRIERS = { TERMINAL_TABLE: "terminal-table" };
146
- //#endregion
147
- //#region src/model/document.ts
148
- /** DOCX package conformance classes. */
149
- const DOCX_CONFORMANCE_CLASSES = Object.freeze({
150
- STRICT: "strict",
151
- TRANSITIONAL: "transitional",
152
- UNKNOWN: "unknown"
153
- });
154
- //#endregion
155
- 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 };