@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.
@@ -0,0 +1,1200 @@
1
+ import { panic } from "better-result";
2
+ //#region src/model/parseWarning.ts
3
+ /**
4
+ * What folio normalised to open a document, as data rather than as prose.
5
+ *
6
+ * Word accepts input the schema does not describe, so folio accepts it too and
7
+ * normalises at the parse boundary. Every such decision is recorded here: a
8
+ * stable `code`, the part it happened in, the best position that part can
9
+ * name, and the value folio declined to read. A host can count them, group
10
+ * them, or decide on one; the human-readable string the parser has always
11
+ * exposed is derived from this, never written by hand at the call site, so the
12
+ * two cannot drift.
13
+ *
14
+ * It lives beside `Document` because it is part of the parsed document, and a
15
+ * `Document` may be produced by anything that builds this model.
16
+ */
17
+ /**
18
+ * Every normalisation the parse boundary is allowed to make.
19
+ *
20
+ * Adding a member without also giving it a message is a type error: the
21
+ * formatter map over this union is total.
22
+ */
23
+ const PARSE_WARNING_CODES = {
24
+ /** A package opened from encrypted storage; a save writes it unencrypted. */
25
+ packageDecrypted: "package-decrypted",
26
+ /** The archive reader reported something about the package it opened. */
27
+ packageArchive: "package-archive",
28
+ /** The main document part is missing; the body is empty. */
29
+ documentPartMissing: "document-part-missing",
30
+ /** The model validator reported an issue the parse did not treat as fatal. */
31
+ documentModelIssue: "document-model-issue",
32
+ /** A later `w:comment` repeating a `w:id` an earlier one defines. */
33
+ duplicateCommentId: "duplicate-comment-id",
34
+ /** A `w:comment` with no readable `w:id`; it can anchor nothing. */
35
+ missingCommentId: "missing-comment-id",
36
+ /** A later `w:footnote`/`w:endnote` repeating an id an earlier one defines. */
37
+ duplicateNoteId: "duplicate-note-id",
38
+ /** A comment marker naming a comment `comments.xml` never defines. */
39
+ danglingCommentReference: "dangling-comment-reference",
40
+ /** A comment range with no matching start or end, re-anchored as a point. */
41
+ unbalancedCommentRange: "unbalanced-comment-range",
42
+ /** A `w:headerReference` naming a header part the package does not carry. */
43
+ danglingHeaderReference: "dangling-header-reference",
44
+ /** A `w:footerReference` naming a footer part the package does not carry. */
45
+ danglingFooterReference: "dangling-footer-reference",
46
+ /** A `r:id` naming a relationship the part's `.rels` does not define. */
47
+ danglingRelationshipId: "dangling-relationship-id",
48
+ /** A paragraph naming a `w:num` the numbering part never defines. */
49
+ unnumberedParagraph: "unnumbered-paragraph",
50
+ /** A style naming a `w:num` the numbering part never defines. */
51
+ unnumberedStyle: "unnumbered-style",
52
+ /** A tracked move range with no matching start or end. */
53
+ unbalancedMoveRange: "unbalanced-move-range",
54
+ /** A `w:type` outside `ST_HdrFtr`, read as the enumeration's default. */
55
+ headerFooterTypeOutsideEnum: "header-footer-type-outside-enum",
56
+ /** A value outside `ST_OnOff`'s six spellings. */
57
+ unrecognisedOnOffValue: "unrecognised-on-off-value",
58
+ /** A theme-colour token outside `ST_ThemeColor`, kept but not painted. */
59
+ unrecognisedThemeColor: "unrecognised-theme-color",
60
+ /** A `CT_Border` with no `w:val`, which has no border style to read. */
61
+ borderWithoutValue: "border-without-value",
62
+ /** A `w:val` outside `ST_Border`, kept verbatim rather than read as a style. */
63
+ borderStyleOutsideEnum: "border-style-outside-enum",
64
+ /** An `a:prstDash@val` outside `ST_PresetLineDashVal`, kept verbatim. */
65
+ outlineDashOutsideEnum: "outline-dash-outside-enum",
66
+ /** A style set defining two styles under one id. */
67
+ styleSetDuplicateStyleId: "style-set-duplicate-style-id",
68
+ /** A style set naming an initial paragraph style it does not contain. */
69
+ styleSetInitialStyleMissing: "style-set-initial-style-missing",
70
+ /** An explicit page-break run the editable model lays out approximately. */
71
+ pageBreakProjectionApproximated: "page-break-projection-approximated"
72
+ };
73
+ /**
74
+ * The cap on retained warnings per code.
75
+ *
76
+ * A generated document can repeat one defect on every paragraph, and a host
77
+ * that only wants to know a defect occurred should not pay for a hundred
78
+ * thousand records. Occurrences past the cap are counted, not kept.
79
+ */
80
+ const MAX_RETAINED_PARSE_WARNINGS_PER_CODE = 20;
81
+ //#endregion
82
+ //#region src/model/paragraphNumbering.ts
83
+ /**
84
+ * `w:numPr`: what a tier states about a paragraph's numbering, and what the
85
+ * cascade resolves that to.
86
+ *
87
+ * Two facts shape the types, and the old `{ numId?: number; ilvl?: number }`
88
+ * pair expressed neither.
89
+ *
90
+ * **`w:numId` and `w:ilvl` inherit independently** (ECMA-376 17.3.1.19). A tier
91
+ * that states only the level keeps the id it inherits, which is what Word
92
+ * writes whenever a styled list paragraph is demoted, so a direct `w:numPr` is
93
+ * a partial override rather than a whole replacement. That is the `levelOnly`
94
+ * arm, and it is why the override type has three arms and not two.
95
+ *
96
+ * **`w:numId w:val="0"` is reserved** (17.9.18): it names no `w:num`, it
97
+ * switches numbering off, and on a style it cancels the numbering the style
98
+ * would otherwise inherit through `w:basedOn`. It is the `none` arm, and a
99
+ * `reference` therefore cannot carry it — which is the whole point, because
100
+ * the sentinel used to read as "this paragraph is in list 0" in the layout and
101
+ * marker tiers while the sanctioned reader said it was in no list at all.
102
+ */
103
+ /** The reserved `w:numId` value that means "no numbering". */
104
+ const NO_NUMBERING_NUM_ID = 0;
105
+ /**
106
+ * Whether a `w:numId` names a numbering definition to resolve.
107
+ *
108
+ * Still the reader for the raw ids the numbering part itself carries
109
+ * (`w:num@numId`, a style's own reference before it is read into the union).
110
+ * A paragraph's numbering no longer goes through it: after
111
+ * {@link paragraphNumberingFromSlots} the sentinel has no representation.
112
+ */
113
+ const isNumberingReference = (numId) => numId !== void 0 && numId !== 0;
114
+ /** The arm a `w:numId w:val="0"` reads as, and the arm a cascade cancels to. */
115
+ const NO_PARAGRAPH_NUMBERING = { kind: "none" };
116
+ /** The level an absent `w:ilvl` stands for. */
117
+ const IMPLICIT_NUMBERING_LEVEL = 0;
118
+ /** Mint a reference after excluding the reserved id from the model. */
119
+ const paragraphNumberingReference = ({ numId, ilvl }) => {
120
+ if (!isNumberingReference(numId)) return panic(`Paragraph numbering reference cannot use reserved numId ${numId}`);
121
+ return ilvl === void 0 ? {
122
+ kind: "reference",
123
+ numId
124
+ } : {
125
+ kind: "reference",
126
+ numId,
127
+ ilvl
128
+ };
129
+ };
130
+ /**
131
+ * The one mapping from a `<w:numPr>`'s two slots onto the union.
132
+ *
133
+ * `undefined` is an element that states neither slot, which states nothing.
134
+ * Every parse boundary goes through this, which is what stops the reserved id
135
+ * reaching the model at all.
136
+ */
137
+ const paragraphNumberingFromSlots = ({ numId, ilvl }) => {
138
+ if (numId === 0) return NO_PARAGRAPH_NUMBERING;
139
+ if (numId !== void 0) return paragraphNumberingReference({
140
+ numId,
141
+ ilvl
142
+ });
143
+ return ilvl === void 0 ? void 0 : {
144
+ kind: "levelOnly",
145
+ ilvl
146
+ };
147
+ };
148
+ /**
149
+ * The slots to write back for a stated override, so the emit has one owner
150
+ * too. `none` writes the reserved id, because deleting the element would
151
+ * uncover the tier below and hand the paragraph its numbering back.
152
+ */
153
+ const paragraphNumberingSlots = (numbering) => {
154
+ switch (numbering.kind) {
155
+ case "none": return { numId: 0 };
156
+ case "reference": return numbering.ilvl === void 0 ? { numId: numbering.numId } : {
157
+ numId: numbering.numId,
158
+ ilvl: numbering.ilvl
159
+ };
160
+ case "levelOnly": return { ilvl: numbering.ilvl };
161
+ default: return panic(`Unhandled paragraph numbering ${JSON.stringify(numbering)}`);
162
+ }
163
+ };
164
+ /**
165
+ * Fold one tier over the tier beneath it, direct over style.
166
+ *
167
+ * This is ECMA-376 17.3.1.19's independent inheritance written once. Before
168
+ * the union it was four object spreads in three languages, each of them a
169
+ * comment saying what the spread happened to do.
170
+ */
171
+ const mergeParagraphNumbering = (inherited, stated) => {
172
+ if (stated === void 0) return inherited;
173
+ switch (stated.kind) {
174
+ case "none": return stated;
175
+ case "reference": {
176
+ if (stated.ilvl !== void 0 || inherited === void 0 || inherited.kind === "none") return stated;
177
+ const inheritedLevel = inherited.ilvl;
178
+ return inheritedLevel === void 0 ? stated : paragraphNumberingReference({
179
+ numId: stated.numId,
180
+ ilvl: inheritedLevel
181
+ });
182
+ }
183
+ case "levelOnly":
184
+ if (inherited === void 0) return stated;
185
+ switch (inherited.kind) {
186
+ case "none": return NO_PARAGRAPH_NUMBERING;
187
+ case "levelOnly": return stated;
188
+ case "reference": return paragraphNumberingReference({
189
+ numId: inherited.numId,
190
+ ilvl: stated.ilvl
191
+ });
192
+ default: return panic(`Unhandled inherited numbering ${JSON.stringify(inherited)}`);
193
+ }
194
+ default: return panic(`Unhandled stated numbering ${JSON.stringify(stated)}`);
195
+ }
196
+ };
197
+ /**
198
+ * Collapse a stated override to what renders.
199
+ *
200
+ * A `levelOnly` that nothing supplied an id for numbers nothing, the same as a
201
+ * cancellation does, which is why the resolved type has two arms.
202
+ */
203
+ const resolveParagraphNumbering = (numbering) => {
204
+ if (numbering === void 0) return NO_PARAGRAPH_NUMBERING;
205
+ switch (numbering.kind) {
206
+ case "none":
207
+ case "levelOnly": return NO_PARAGRAPH_NUMBERING;
208
+ case "reference": return paragraphNumberingReference({
209
+ numId: numbering.numId,
210
+ ilvl: numbering.ilvl ?? IMPLICIT_NUMBERING_LEVEL
211
+ });
212
+ default: return panic(`Unhandled paragraph numbering ${JSON.stringify(numbering)}`);
213
+ }
214
+ };
215
+ /** The level a stated override renders at, absent `w:ilvl` read as zero. */
216
+ const paragraphNumberingLevel = (numbering) => {
217
+ if (numbering === void 0) return;
218
+ switch (numbering.kind) {
219
+ case "none": return;
220
+ case "levelOnly": return numbering.ilvl;
221
+ case "reference": return numbering.ilvl ?? IMPLICIT_NUMBERING_LEVEL;
222
+ default: return panic(`Unhandled paragraph numbering ${JSON.stringify(numbering)}`);
223
+ }
224
+ };
225
+ /** The numbering definition a stated override names, or undefined for none. */
226
+ const paragraphNumberingReferenceId = (numbering) => numbering?.kind === "reference" ? numbering.numId : void 0;
227
+ /**
228
+ * Whether two stated overrides say the same thing, byte for byte: an absent
229
+ * `w:ilvl` is not a stated `w:val="0"` here, which is what keeps an untouched
230
+ * save from stating something its source did not.
231
+ */
232
+ const sameStatedParagraphNumbering = (left, right) => {
233
+ if (left === void 0 || right === void 0) return left === right;
234
+ switch (left.kind) {
235
+ case "none": return right.kind === "none";
236
+ case "reference": return right.kind === "reference" && left.numId === right.numId && left.ilvl === right.ilvl;
237
+ case "levelOnly": return right.kind === "levelOnly" && left.ilvl === right.ilvl;
238
+ default: return panic(`Unhandled paragraph numbering ${JSON.stringify(left)}`);
239
+ }
240
+ };
241
+ /** Whether two stated overrides render the same, an absent `w:ilvl` read as zero. */
242
+ const sameEffectiveParagraphNumbering = (left, right) => {
243
+ if (left === void 0 || right === void 0) return left === right;
244
+ const resolvedLeft = resolveParagraphNumbering(left);
245
+ const resolvedRight = resolveParagraphNumbering(right);
246
+ if (resolvedLeft.kind === "none" || resolvedRight.kind === "none") return resolvedLeft.kind === resolvedRight.kind;
247
+ return resolvedLeft.numId === resolvedRight.numId && resolvedLeft.ilvl === resolvedRight.ilvl;
248
+ };
249
+ //#endregion
250
+ //#region src/model/outlineLevel.ts
251
+ /**
252
+ * `w:outlineLvl`: nine heading levels and one reserved "not a heading".
253
+ *
254
+ * ECMA-376 17.3.1.20 gives `w:val` the range 0..9 "where 9 specifically
255
+ * indicates that there is no outline level specifically applied to this
256
+ * paragraph". Nine is therefore a sentinel, not a tenth level, and a model
257
+ * that stores the raw number lets every consumer decide that for itself: the
258
+ * PDF outline nested a `TOC Heading` nine deep, the TOC listed it, and the
259
+ * lint could not see the mistake because the comparison was against
260
+ * `undefined` rather than against the literal.
261
+ *
262
+ * The union removes the decision. `9` has no representation as a heading, an
263
+ * out-of-range value has none at all, and absence stays absence — a paragraph
264
+ * that states no level inherits one, which is a third state neither arm may
265
+ * stand in for.
266
+ */
267
+ /** The `w:outlineLvl w:val` values that name a heading, zero-based. */
268
+ const HEADING_OUTLINE_LEVELS = [
269
+ 0,
270
+ 1,
271
+ 2,
272
+ 3,
273
+ 4,
274
+ 5,
275
+ 6,
276
+ 7,
277
+ 8
278
+ ];
279
+ /** The reserved `w:outlineLvl w:val="9"`: outlined as body text, not as a heading. */
280
+ const BODY_TEXT_OUTLINE_LEVEL = { kind: "bodyText" };
281
+ /** The `w:val` the body-text arm is written as. */
282
+ const BODY_TEXT_OUTLINE_LEVEL_VALUE = 9;
283
+ const OUTLINE_LEVEL_BY_STATED_VALUE = new Map([...HEADING_OUTLINE_LEVELS.map((level) => [level, {
284
+ kind: "heading",
285
+ level
286
+ }]), [BODY_TEXT_OUTLINE_LEVEL_VALUE, BODY_TEXT_OUTLINE_LEVEL]]);
287
+ /**
288
+ * The one reader over a stated `w:outlineLvl w:val`.
289
+ *
290
+ * `undefined` is a value outside 0..9, which the format does not define. The
291
+ * Rust kernel rejects those outright (`MAXIMUM_OUTLINE_LEVEL`); the TypeScript
292
+ * parse boundary drops them and warns instead, because a corpus document that
293
+ * Word opens must still open here.
294
+ */
295
+ const outlineLevelFromStatedValue = (value) => OUTLINE_LEVEL_BY_STATED_VALUE.get(value);
296
+ /** The heading arm for a zero-based level, or undefined outside 0..8. */
297
+ const headingOutlineLevel = (level) => {
298
+ const outlineLevel = OUTLINE_LEVEL_BY_STATED_VALUE.get(level);
299
+ return outlineLevel?.kind === "heading" ? outlineLevel : void 0;
300
+ };
301
+ /** The `w:val` to write for a stated outline level. */
302
+ const outlineLevelStatedValue = (outlineLevel) => {
303
+ switch (outlineLevel.kind) {
304
+ case "bodyText": return BODY_TEXT_OUTLINE_LEVEL_VALUE;
305
+ case "heading": return outlineLevel.level;
306
+ default: return panic(`Unhandled outline level ${JSON.stringify(outlineLevel)}`);
307
+ }
308
+ };
309
+ /**
310
+ * The zero-based heading level a stated outline level names, or undefined when
311
+ * it names none. Body text and an absent level answer the same thing, which is
312
+ * what every heading consumer wants; the two are distinguished only where the
313
+ * cascade still has a tier left to ask.
314
+ */
315
+ const headingLevelOf = (outlineLevel) => outlineLevel?.kind === "heading" ? outlineLevel.level : void 0;
316
+ //#endregion
317
+ //#region src/model/relationshipId.ts
318
+ /**
319
+ * Whether a string names a relationship. The refinement is a type predicate
320
+ * rather than a cast, so no site that mints an id needs an assertion.
321
+ */
322
+ const isRelationshipId = (value) => value.length > 0;
323
+ /**
324
+ * The relationship a reference names, or `undefined` when it names none.
325
+ *
326
+ * Takes what a reader hands back (a missing attribute, an attribute present
327
+ * and empty, a reference) and answers in the one spelling the model has for
328
+ * absence.
329
+ */
330
+ const relationshipIdOf = (value) => value === void 0 || value === null || !isRelationshipId(value) ? void 0 : value;
331
+ /**
332
+ * The id a save gives a part it added, from the ordinal it allocated.
333
+ *
334
+ * A mint is not a read, so it has no absent case to report: `rId` followed by
335
+ * a number names something by construction, and a build where it does not is
336
+ * one where the refinement has stopped describing the type.
337
+ */
338
+ const mintRelationshipId = (ordinal) => {
339
+ const id = `rId${ordinal}`;
340
+ return isRelationshipId(id) ? id : panic("A minted relationship id names nothing.");
341
+ };
342
+ //#endregion
343
+ //#region src/model/themeColor.gen.ts
344
+ /**
345
+ * GENERATED FILE — do not edit.
346
+ *
347
+ * The colour enumerations a theme reference passes through.
348
+ *
349
+ * Derived from `specifications/generated/docx-transitional-schema.gen.json`.
350
+ * Regenerate with:
351
+ *
352
+ * bun run generate:theme-colors
353
+ */
354
+ /**
355
+ * `ST_ThemeColor`: every token a WordprocessingML `w:themeColor`,
356
+ * `w:themeFill` or `w:clrSchemeMapping` value may carry.
357
+ *
358
+ * Spelled in full words (`dark1`, `hyperlink`), unlike the DrawingML slot
359
+ * names below. `none` is a reserved member that cancels an inherited theme
360
+ * colour rather than naming one.
361
+ */
362
+ const THEME_COLORS = [
363
+ "dark1",
364
+ "light1",
365
+ "dark2",
366
+ "light2",
367
+ "accent1",
368
+ "accent2",
369
+ "accent3",
370
+ "accent4",
371
+ "accent5",
372
+ "accent6",
373
+ "hyperlink",
374
+ "followedHyperlink",
375
+ "none",
376
+ "background1",
377
+ "text1",
378
+ "background2",
379
+ "text2"
380
+ ];
381
+ /**
382
+ * `ST_SchemeColorVal`: every token an `a:schemeClr/@val` reference may carry.
383
+ *
384
+ * A superset of {@link SCHEME_COLOR_SLOTS}: it adds the four mapped spellings
385
+ * (`bg1`, `tx1`, `bg2`, `tx2`) and `phClr`, the placeholder a style
386
+ * definition resolves against its instantiating context.
387
+ */
388
+ const SCHEME_COLOR_VALUES = [
389
+ "bg1",
390
+ "tx1",
391
+ "bg2",
392
+ "tx2",
393
+ "accent1",
394
+ "accent2",
395
+ "accent3",
396
+ "accent4",
397
+ "accent5",
398
+ "accent6",
399
+ "hlink",
400
+ "folHlink",
401
+ "phClr",
402
+ "dk1",
403
+ "lt1",
404
+ "dk2",
405
+ "lt2"
406
+ ];
407
+ //#endregion
408
+ //#region src/model/themeColor.ts
409
+ /**
410
+ * The one mapping between a WordprocessingML theme reference and a theme slot.
411
+ *
412
+ * `w:themeColor` names a colour in `ST_ThemeColor`'s spelling; a theme part
413
+ * declares its slots in DrawingML's. Three kinds of member, per ECMA-376
414
+ * §17.18.97:
415
+ *
416
+ * direct `dark1`, `hyperlink`, `accent3` name a slot outright
417
+ * mapped `background1`, `text1`, … name a `w:clrSchemeMapping` key,
418
+ * which `settings.xml` points at a
419
+ * slot (§17.15.1.20)
420
+ * cancel `none` states that no theme colour
421
+ * applies, overriding an inherited
422
+ * one
423
+ *
424
+ * Every consumer reads the same map, so the DrawingML spelling appears once.
425
+ */
426
+ const slot = (value) => ({
427
+ kind: "slot",
428
+ slot: value
429
+ });
430
+ const mapped = (value) => ({
431
+ kind: "mapped",
432
+ mapping: value
433
+ });
434
+ /**
435
+ * Total over `ST_ThemeColor`: a token added by a schema refresh cannot land
436
+ * without a decision about which slot it paints.
437
+ */
438
+ const THEME_COLOR_TARGETS = {
439
+ dark1: slot("dk1"),
440
+ light1: slot("lt1"),
441
+ dark2: slot("dk2"),
442
+ light2: slot("lt2"),
443
+ accent1: slot("accent1"),
444
+ accent2: slot("accent2"),
445
+ accent3: slot("accent3"),
446
+ accent4: slot("accent4"),
447
+ accent5: slot("accent5"),
448
+ accent6: slot("accent6"),
449
+ hyperlink: slot("hlink"),
450
+ followedHyperlink: slot("folHlink"),
451
+ none: { kind: "cancel" },
452
+ background1: mapped("bg1"),
453
+ text1: mapped("t1"),
454
+ background2: mapped("bg2"),
455
+ text2: mapped("t2")
456
+ };
457
+ /**
458
+ * The mapping a document carries when `settings.xml` declares none.
459
+ *
460
+ * Word writes `w:clrSchemeMapping` with exactly these pairs into every new
461
+ * document, so it is the mapping a reader assumes rather than a folio default.
462
+ * Reading the element itself is a separate change: it belongs with the
463
+ * `settings.xml` part, and `themeColorSlot` takes no mapping argument until
464
+ * something can supply one.
465
+ */
466
+ const DEFAULT_CLR_SCHEME_MAPPING = {
467
+ bg1: "lt1",
468
+ t1: "dk1",
469
+ bg2: "lt2",
470
+ t2: "dk2",
471
+ accent1: "accent1",
472
+ accent2: "accent2",
473
+ accent3: "accent3",
474
+ accent4: "accent4",
475
+ accent5: "accent5",
476
+ accent6: "accent6",
477
+ hyperlink: "hlink",
478
+ followedHyperlink: "folHlink"
479
+ };
480
+ /**
481
+ * The `a:schemeClr/@val` spelling of each theme colour.
482
+ *
483
+ * DrawingML keeps the mapped colours as their own tokens (`bg1`, `tx1`) rather
484
+ * than resolving them, so the two vocabularies differ only in spelling. `none`
485
+ * has no DrawingML equivalent: a scheme reference that paints nothing is
486
+ * written by omitting the fill, not by naming a colour.
487
+ */
488
+ const SCHEME_COLOR_VALUE_BY_THEME_COLOR = {
489
+ dark1: "dk1",
490
+ light1: "lt1",
491
+ dark2: "dk2",
492
+ light2: "lt2",
493
+ accent1: "accent1",
494
+ accent2: "accent2",
495
+ accent3: "accent3",
496
+ accent4: "accent4",
497
+ accent5: "accent5",
498
+ accent6: "accent6",
499
+ hyperlink: "hlink",
500
+ followedHyperlink: "folHlink",
501
+ none: null,
502
+ background1: "bg1",
503
+ text1: "tx1",
504
+ background2: "bg2",
505
+ text2: "tx2"
506
+ };
507
+ /**
508
+ * The inverse: how an `a:schemeClr/@val` reads as a WordprocessingML theme
509
+ * colour. `phClr` is the placeholder a style definition resolves against its
510
+ * instantiating context, which no `w:themeColor` can name.
511
+ */
512
+ const THEME_COLOR_BY_SCHEME_COLOR_VALUE = {
513
+ bg1: "background1",
514
+ tx1: "text1",
515
+ bg2: "background2",
516
+ tx2: "text2",
517
+ accent1: "accent1",
518
+ accent2: "accent2",
519
+ accent3: "accent3",
520
+ accent4: "accent4",
521
+ accent5: "accent5",
522
+ accent6: "accent6",
523
+ hlink: "hyperlink",
524
+ folHlink: "followedHyperlink",
525
+ phClr: null,
526
+ dk1: "dark1",
527
+ lt1: "light1",
528
+ dk2: "dark2",
529
+ lt2: "light2"
530
+ };
531
+ const THEME_COLOR_SET = new Set(THEME_COLORS);
532
+ const isThemeColor = (value) => THEME_COLOR_SET.has(value);
533
+ const SCHEME_COLOR_VALUE_SET = new Set(SCHEME_COLOR_VALUES);
534
+ const isSchemeColorValue = (value) => SCHEME_COLOR_VALUE_SET.has(value);
535
+ /**
536
+ * Read an attribute as a theme colour, or `undefined` when it is absent.
537
+ *
538
+ * An unrecognised token is captured rather than refused; the caller decides
539
+ * whether to report it.
540
+ */
541
+ const readThemeColor = (raw) => {
542
+ if (raw === null || raw === void 0 || raw === "") return;
543
+ return isThemeColor(raw) ? raw : {
544
+ kind: "unrecognised",
545
+ raw
546
+ };
547
+ };
548
+ /** The token to write back, whether or not the schema enumerates it. */
549
+ const themeColorToken = (value) => typeof value === "string" ? value : value.raw;
550
+ /** The schema token, or `undefined` for one the model only carries verbatim. */
551
+ const knownThemeColor = (value) => typeof value === "string" ? value : void 0;
552
+ /**
553
+ * The theme slot a reference paints with, or `undefined` when it names none.
554
+ *
555
+ * `undefined` covers both `none`, which cancels an inherited theme colour, and
556
+ * a token the schema does not enumerate.
557
+ */
558
+ const themeColorSlot = (value) => {
559
+ const known = knownThemeColor(value);
560
+ if (known === void 0) return;
561
+ const target = THEME_COLOR_TARGETS[known];
562
+ switch (target.kind) {
563
+ case "slot": return target.slot;
564
+ case "mapped": return DEFAULT_CLR_SCHEME_MAPPING[target.mapping];
565
+ case "cancel": return;
566
+ default: return target;
567
+ }
568
+ };
569
+ //#endregion
570
+ //#region src/model/ooxmlEnumerations.gen.ts
571
+ /**
572
+ * GENERATED FILE — do not edit.
573
+ *
574
+ * The model enumerations that mirror an OOXML simple type, member for
575
+ * member, so a token the format declares cannot go unspelled.
576
+ *
577
+ * Derived from `specifications/generated/docx-transitional-schema.gen.json`.
578
+ * Regenerate with:
579
+ *
580
+ * bun run generate:ooxml-enumerations
581
+ */
582
+ /**
583
+ * `ST_Jc`: every token a `w:jc/@w:val` may carry.
584
+ *
585
+ * `start` and `end` are the direction-aware alignments, distinct from
586
+ * `left` and `right`: in a right-to-left paragraph `start` sits at the
587
+ * right margin. They are members in their own right, not spellings of
588
+ * `left` and `right`, and the layout resolves them against the
589
+ * paragraph's direction. `numTab` aligns to the list number's tab stop.
590
+ */
591
+ const PARAGRAPH_ALIGNMENTS = [
592
+ "start",
593
+ "center",
594
+ "end",
595
+ "both",
596
+ "mediumKashida",
597
+ "distribute",
598
+ "numTab",
599
+ "highKashida",
600
+ "lowKashida",
601
+ "thaiDistribute",
602
+ "left",
603
+ "right"
604
+ ];
605
+ /**
606
+ * `ST_TabJc`: every token a `w:tab/@w:val` may carry.
607
+ *
608
+ * `start` and `end` are the direction-aware members, the same distinction
609
+ * `ST_Jc` draws; `clear` removes an inherited stop rather than declaring
610
+ * one, and `num` is the stop a numbered paragraph's text hangs from.
611
+ */
612
+ const TAB_STOP_ALIGNMENTS = [
613
+ "clear",
614
+ "start",
615
+ "center",
616
+ "end",
617
+ "decimal",
618
+ "bar",
619
+ "num",
620
+ "left",
621
+ "right"
622
+ ];
623
+ /**
624
+ * `ST_JcTable`: every token a table's or a row's `w:jc/@w:val` may carry.
625
+ *
626
+ * A narrower vocabulary than `ST_Jc`: a table is placed, not justified, so
627
+ * there is no `both`. `start` and `end` are the direction-aware members,
628
+ * the same distinction `ST_Jc` draws, resolved against the table's own
629
+ * `w:bidiVisual` rather than a paragraph's direction.
630
+ */
631
+ const TABLE_ALIGNMENTS = [
632
+ "center",
633
+ "end",
634
+ "left",
635
+ "right",
636
+ "start"
637
+ ];
638
+ /**
639
+ * `ST_TextDirection`: every token a `w:textDirection/@w:val` may carry, on
640
+ * a table cell, a section or a paragraph.
641
+ *
642
+ * Twelve tokens for six flows: each flow has a short spelling and a long one
643
+ * naming the character and line progressions in full.
644
+ * {@link TEXT_DIRECTION_FLOWS} is the six, and
645
+ * {@link TEXT_DIRECTION_FLOW_BY_TOKEN} pairs each token with its flow.
646
+ */
647
+ const TEXT_DIRECTIONS = [
648
+ "tb",
649
+ "rl",
650
+ "lr",
651
+ "tbV",
652
+ "rlV",
653
+ "lrV",
654
+ "btLr",
655
+ "lrTb",
656
+ "lrTbV",
657
+ "tbLrV",
658
+ "tbRl",
659
+ "tbRlV"
660
+ ];
661
+ /**
662
+ * The six text flows `ST_TextDirection` names, spelled the Strict way.
663
+ *
664
+ * Strict's `ST_TextDirection` (ECMA-376 Part 1 §17.18.93) enumerates exactly
665
+ * these six; Transitional adds a second spelling of each (Part 4 §14.11.7).
666
+ * Rendering is decided per flow, so a cell written `tbRl` and its Strict twin
667
+ * written `rl` paint the same.
668
+ */
669
+ const TEXT_DIRECTION_FLOWS = [
670
+ "tb",
671
+ "rl",
672
+ "lr",
673
+ "tbV",
674
+ "rlV",
675
+ "lrV"
676
+ ];
677
+ /**
678
+ * The flow each `ST_TextDirection` token names.
679
+ *
680
+ * ECMA-376 Part 4 §14.11.7 gives each Transitional-only token as semantically
681
+ * equivalent to a Strict one: `btLr` to `lr`, `lrTb` to `tb`, `lrTbV`
682
+ * to `tbV`, `tbLrV` to `lrV`, `tbRl` to `rl` and `tbRlV` to `rlV`.
683
+ * A reader keeps the token as authored and a writer writes it back; only
684
+ * rendering goes through the flow.
685
+ */
686
+ const TEXT_DIRECTION_FLOW_BY_TOKEN = {
687
+ tb: "tb",
688
+ rl: "rl",
689
+ lr: "lr",
690
+ tbV: "tbV",
691
+ rlV: "rlV",
692
+ lrV: "lrV",
693
+ btLr: "lr",
694
+ lrTb: "tb",
695
+ lrTbV: "tbV",
696
+ tbLrV: "lrV",
697
+ tbRl: "rl",
698
+ tbRlV: "rlV"
699
+ };
700
+ /**
701
+ * `ST_NumberFormat`: every token a `w:numFmt/@w:val` may carry, on a
702
+ * numbering level, a note's properties or a section's page numbers.
703
+ *
704
+ * `custom` counts by the token list in the sibling `@w:format` rather
705
+ * than by a vocabulary of its own; `none` prints no counter at all.
706
+ */
707
+ const NUMBER_FORMATS = [
708
+ "decimal",
709
+ "upperRoman",
710
+ "lowerRoman",
711
+ "upperLetter",
712
+ "lowerLetter",
713
+ "ordinal",
714
+ "cardinalText",
715
+ "ordinalText",
716
+ "hex",
717
+ "chicago",
718
+ "ideographDigital",
719
+ "japaneseCounting",
720
+ "aiueo",
721
+ "iroha",
722
+ "decimalFullWidth",
723
+ "decimalHalfWidth",
724
+ "japaneseLegal",
725
+ "japaneseDigitalTenThousand",
726
+ "decimalEnclosedCircle",
727
+ "decimalFullWidth2",
728
+ "aiueoFullWidth",
729
+ "irohaFullWidth",
730
+ "decimalZero",
731
+ "bullet",
732
+ "ganada",
733
+ "chosung",
734
+ "decimalEnclosedFullstop",
735
+ "decimalEnclosedParen",
736
+ "decimalEnclosedCircleChinese",
737
+ "ideographEnclosedCircle",
738
+ "ideographTraditional",
739
+ "ideographZodiac",
740
+ "ideographZodiacTraditional",
741
+ "taiwaneseCounting",
742
+ "ideographLegalTraditional",
743
+ "taiwaneseCountingThousand",
744
+ "taiwaneseDigital",
745
+ "chineseCounting",
746
+ "chineseLegalSimplified",
747
+ "chineseCountingThousand",
748
+ "koreanDigital",
749
+ "koreanCounting",
750
+ "koreanLegal",
751
+ "koreanDigital2",
752
+ "vietnameseCounting",
753
+ "russianLower",
754
+ "russianUpper",
755
+ "none",
756
+ "numberInDash",
757
+ "hebrew1",
758
+ "hebrew2",
759
+ "arabicAlpha",
760
+ "arabicAbjad",
761
+ "hindiVowels",
762
+ "hindiConsonants",
763
+ "hindiNumbers",
764
+ "hindiCounting",
765
+ "thaiLetters",
766
+ "thaiNumbers",
767
+ "thaiCounting",
768
+ "bahtText",
769
+ "dollarText",
770
+ "custom"
771
+ ];
772
+ //#endregion
773
+ //#region src/model/borderStyle.gen.ts
774
+ /**
775
+ * GENERATED FILE — do not edit.
776
+ *
777
+ * The `ST_Border` enumeration, in schema order, derived from
778
+ * `specifications/generated/docx-transitional-schema.gen.json` by
779
+ * `scripts/generate-border-styles.ts`. Regenerate with:
780
+ *
781
+ * bun run generate:border-styles
782
+ *
783
+ * The first 27 members are line styles; the rest are the page-border art
784
+ * glyphs `w:pgBorders` may name. `nil` and `none` are distinct: `none`
785
+ * cancels a border inherited from the container, `nil` states no border. Read
786
+ * either through `isBorderNone`/`isBorderNil` in `./borderStyle`, never by
787
+ * comparing the string.
788
+ */
789
+ /** Every `ST_Border` member, in schema order. */
790
+ const BORDER_STYLES = [
791
+ "nil",
792
+ "none",
793
+ "single",
794
+ "thick",
795
+ "double",
796
+ "dotted",
797
+ "dashed",
798
+ "dotDash",
799
+ "dotDotDash",
800
+ "triple",
801
+ "thinThickSmallGap",
802
+ "thickThinSmallGap",
803
+ "thinThickThinSmallGap",
804
+ "thinThickMediumGap",
805
+ "thickThinMediumGap",
806
+ "thinThickThinMediumGap",
807
+ "thinThickLargeGap",
808
+ "thickThinLargeGap",
809
+ "thinThickThinLargeGap",
810
+ "wave",
811
+ "doubleWave",
812
+ "dashSmallGap",
813
+ "dashDotStroked",
814
+ "threeDEmboss",
815
+ "threeDEngrave",
816
+ "outset",
817
+ "inset",
818
+ "apples",
819
+ "archedScallops",
820
+ "babyPacifier",
821
+ "babyRattle",
822
+ "balloons3Colors",
823
+ "balloonsHotAir",
824
+ "basicBlackDashes",
825
+ "basicBlackDots",
826
+ "basicBlackSquares",
827
+ "basicThinLines",
828
+ "basicWhiteDashes",
829
+ "basicWhiteDots",
830
+ "basicWhiteSquares",
831
+ "basicWideInline",
832
+ "basicWideMidline",
833
+ "basicWideOutline",
834
+ "bats",
835
+ "birds",
836
+ "birdsFlight",
837
+ "cabins",
838
+ "cakeSlice",
839
+ "candyCorn",
840
+ "celticKnotwork",
841
+ "certificateBanner",
842
+ "chainLink",
843
+ "champagneBottle",
844
+ "checkedBarBlack",
845
+ "checkedBarColor",
846
+ "checkered",
847
+ "christmasTree",
848
+ "circlesLines",
849
+ "circlesRectangles",
850
+ "classicalWave",
851
+ "clocks",
852
+ "compass",
853
+ "confetti",
854
+ "confettiGrays",
855
+ "confettiOutline",
856
+ "confettiStreamers",
857
+ "confettiWhite",
858
+ "cornerTriangles",
859
+ "couponCutoutDashes",
860
+ "couponCutoutDots",
861
+ "crazyMaze",
862
+ "creaturesButterfly",
863
+ "creaturesFish",
864
+ "creaturesInsects",
865
+ "creaturesLadyBug",
866
+ "crossStitch",
867
+ "cup",
868
+ "decoArch",
869
+ "decoArchColor",
870
+ "decoBlocks",
871
+ "diamondsGray",
872
+ "doubleD",
873
+ "doubleDiamonds",
874
+ "earth1",
875
+ "earth2",
876
+ "earth3",
877
+ "eclipsingSquares1",
878
+ "eclipsingSquares2",
879
+ "eggsBlack",
880
+ "fans",
881
+ "film",
882
+ "firecrackers",
883
+ "flowersBlockPrint",
884
+ "flowersDaisies",
885
+ "flowersModern1",
886
+ "flowersModern2",
887
+ "flowersPansy",
888
+ "flowersRedRose",
889
+ "flowersRoses",
890
+ "flowersTeacup",
891
+ "flowersTiny",
892
+ "gems",
893
+ "gingerbreadMan",
894
+ "gradient",
895
+ "handmade1",
896
+ "handmade2",
897
+ "heartBalloon",
898
+ "heartGray",
899
+ "hearts",
900
+ "heebieJeebies",
901
+ "holly",
902
+ "houseFunky",
903
+ "hypnotic",
904
+ "iceCreamCones",
905
+ "lightBulb",
906
+ "lightning1",
907
+ "lightning2",
908
+ "mapPins",
909
+ "mapleLeaf",
910
+ "mapleMuffins",
911
+ "marquee",
912
+ "marqueeToothed",
913
+ "moons",
914
+ "mosaic",
915
+ "musicNotes",
916
+ "northwest",
917
+ "ovals",
918
+ "packages",
919
+ "palmsBlack",
920
+ "palmsColor",
921
+ "paperClips",
922
+ "papyrus",
923
+ "partyFavor",
924
+ "partyGlass",
925
+ "pencils",
926
+ "people",
927
+ "peopleWaving",
928
+ "peopleHats",
929
+ "poinsettias",
930
+ "postageStamp",
931
+ "pumpkin1",
932
+ "pushPinNote2",
933
+ "pushPinNote1",
934
+ "pyramids",
935
+ "pyramidsAbove",
936
+ "quadrants",
937
+ "rings",
938
+ "safari",
939
+ "sawtooth",
940
+ "sawtoothGray",
941
+ "scaredCat",
942
+ "seattle",
943
+ "shadowedSquares",
944
+ "sharksTeeth",
945
+ "shorebirdTracks",
946
+ "skyrocket",
947
+ "snowflakeFancy",
948
+ "snowflakes",
949
+ "sombrero",
950
+ "southwest",
951
+ "stars",
952
+ "starsTop",
953
+ "stars3d",
954
+ "starsBlack",
955
+ "starsShadowed",
956
+ "sun",
957
+ "swirligig",
958
+ "tornPaper",
959
+ "tornPaperBlack",
960
+ "trees",
961
+ "triangleParty",
962
+ "triangles",
963
+ "triangle1",
964
+ "triangle2",
965
+ "triangleCircle1",
966
+ "triangleCircle2",
967
+ "shapes1",
968
+ "shapes2",
969
+ "twistedLines1",
970
+ "twistedLines2",
971
+ "vine",
972
+ "waveline",
973
+ "weavingAngles",
974
+ "weavingBraid",
975
+ "weavingRibbon",
976
+ "weavingStrips",
977
+ "whiteFlowers",
978
+ "woodwork",
979
+ "xIllusions",
980
+ "zanyTriangles",
981
+ "zigZag",
982
+ "zigZagStitch",
983
+ "custom"
984
+ ];
985
+ //#endregion
986
+ //#region src/model/borderStyle.ts
987
+ /**
988
+ * The one place a `CT_Border` `w:val` is decided.
989
+ *
990
+ * `ST_Border` carries two distinct "no border" members. `none` cancels a
991
+ * border the container would otherwise pass down — a table's `w:tblBorders`
992
+ * grid, a paragraph style's `w:pBdr`, a section's `w:pgBorders`; `nil` states
993
+ * that no border is set. Word round-trips whichever the author wrote, and a
994
+ * consumer that folds one into the other loses the cancellation, so both are
995
+ * union members and every consumer asks {@link statesNoBorder} rather than
996
+ * comparing the token. `specifications/reserved-values` records the decision
997
+ * and the lint enforces the ownership.
998
+ *
999
+ * A `w:val` outside the enumeration is kept as {@link UnrecognisedBorderStyle}
1000
+ * and written back exactly as it was read, so the union can be closed without
1001
+ * the model becoming a place content goes to die.
1002
+ */
1003
+ const DECLARED$1 = new Set(BORDER_STYLES);
1004
+ /** Whether the schema declares this token. */
1005
+ const isBorderStyle = (value) => DECLARED$1.has(value);
1006
+ /** Read a `w:val` into the model, keeping an undeclared token verbatim. */
1007
+ const borderStyleFrom = (value) => isBorderStyle(value) ? value : {
1008
+ kind: "unrecognised",
1009
+ raw: value
1010
+ };
1011
+ /** The token to write back, whether or not the schema declares it. */
1012
+ const borderStyleToken = (style) => typeof style === "string" ? style : style.raw;
1013
+ /** `none`: the author cancelled a border inherited from the container. */
1014
+ const isBorderNone = (style) => style === "none";
1015
+ /** `nil`: the author stated no border. */
1016
+ const isBorderNil = (style) => style === "nil";
1017
+ /**
1018
+ * Whether the edge paints nothing, by either reserved member.
1019
+ *
1020
+ * This is what a renderer, a measurer and a collapse rule want: the two
1021
+ * members differ in what they do to an inherited border, not in what they
1022
+ * draw. Which one was written still matters on the way back out, which is why
1023
+ * the value keeps it.
1024
+ */
1025
+ const statesNoBorder = (style) => isBorderNone(style) || isBorderNil(style);
1026
+ //#endregion
1027
+ //#region src/model/presetLineDash.gen.ts
1028
+ /**
1029
+ * GENERATED FILE — do not edit.
1030
+ *
1031
+ * The `ST_PresetLineDashVal` enumeration, in schema order, derived from
1032
+ * `specifications/generated/docx-transitional-schema.gen.json` by
1033
+ * `scripts/generate-preset-line-dash.ts`. Regenerate with:
1034
+ *
1035
+ * bun run generate:preset-line-dash
1036
+ *
1037
+ * It is the dash vocabulary of `a:ln/a:prstDash@val`, and only that: the
1038
+ * spellings it shares with CSS `border-style` (`solid`, `dash`, `dot`)
1039
+ * name different patterns there. Read it through `./presetLineDash`.
1040
+ */
1041
+ /** Every `ST_PresetLineDashVal` member, in schema order. */
1042
+ const PRESET_LINE_DASH_VALS = [
1043
+ "solid",
1044
+ "dot",
1045
+ "dash",
1046
+ "lgDash",
1047
+ "dashDot",
1048
+ "lgDashDot",
1049
+ "lgDashDotDot",
1050
+ "sysDash",
1051
+ "sysDot",
1052
+ "sysDashDot",
1053
+ "sysDashDotDot"
1054
+ ];
1055
+ //#endregion
1056
+ //#region src/model/presetLineDash.ts
1057
+ /**
1058
+ * The one place an `a:ln/a:prstDash` `@val` is decided.
1059
+ *
1060
+ * `ST_PresetLineDashVal` is DrawingML's own dash vocabulary. Three of its
1061
+ * spellings (`solid`, `dash`, `dot`) also occur in CSS `border-style` and in
1062
+ * `text-decoration-style`, where they name different patterns, so an outline
1063
+ * dash is kept in its own type and resolved against its own table rather than
1064
+ * matched by string against whatever vocabulary a consumer happens to hold.
1065
+ *
1066
+ * A `@val` outside the enumeration is kept as {@link UnrecognisedPresetLineDash}
1067
+ * and written back exactly as it was read, the way an undeclared `ST_Border`
1068
+ * `w:val` is.
1069
+ *
1070
+ * `a:custDash` is not this attribute and is not modelled: an outline that
1071
+ * carries one keeps it through `ShapeOutline.rawXml`, which the serializer
1072
+ * replays verbatim, so the custom stop list survives a save without the dash
1073
+ * field pretending to describe it.
1074
+ */
1075
+ const DECLARED = new Set(PRESET_LINE_DASH_VALS);
1076
+ /** Whether the schema declares this token. */
1077
+ const isPresetLineDashVal = (value) => DECLARED.has(value);
1078
+ /** Read a `@val` into the model, keeping an undeclared token verbatim. */
1079
+ const presetLineDashFrom = (value) => isPresetLineDashVal(value) ? value : {
1080
+ kind: "unrecognised",
1081
+ raw: value
1082
+ };
1083
+ /** The token to write back, whether or not the schema declares it. */
1084
+ const presetLineDashToken = (dash) => typeof dash === "string" ? dash : dash.raw;
1085
+ //#endregion
1086
+ //#region src/model/lists.ts
1087
+ /**
1088
+ * What the marker renderer counts in: folio's own vocabulary, not the format's.
1089
+ *
1090
+ * It is `ST_NumberFormat` plus the zero-padded widths a `custom` format
1091
+ * resolves to. Those three used to sit in {@link NumberFormat} itself, which
1092
+ * meant the model held tokens `w:numFmt/@w:val` does not declare and a save
1093
+ * could write one; they belong here, on the render side, where nothing is
1094
+ * serialized.
1095
+ */
1096
+ const COUNTER_FORMATS = [
1097
+ ...NUMBER_FORMATS,
1098
+ "decimalZero3",
1099
+ "decimalZero4",
1100
+ "decimalZero5"
1101
+ ];
1102
+ //#endregion
1103
+ //#region src/model/content.ts
1104
+ const OOXML_SYMBOL_CHARACTER_PATTERN = /^[\dA-Fa-f]{4}$/u;
1105
+ /** Whether a symbol character is exactly four hexadecimal digits. */
1106
+ const isOoxmlSymbolCharacter = (value) => OOXML_SYMBOL_CHARACTER_PATTERN.test(value);
1107
+ /** Raw XML handling modes for drawings that Folio cannot model completely. */
1108
+ const DRAWING_RAW_XML_MODES = {
1109
+ PRESERVE_ONLY: "preserveOnly",
1110
+ /** The modeled image is a rendered preview of richer markup, so regeneration cannot reproduce the drawing. */
1111
+ PREVIEW_ONLY: "previewOnly"
1112
+ };
1113
+ /**
1114
+ * Largest value a revision id (`w:id`) may carry: 2^31 - 1.
1115
+ *
1116
+ * `w:id` on `<w:ins>`/`<w:del>` comes from `CT_Markup`, typed
1117
+ * `ST_DecimalNumber` — which ECMA-376 defines as an unbounded integer. The
1118
+ * bound below is an implementation limit: conforming consumers read
1119
+ * `ST_DecimalNumber` into a signed 32-bit int, and a value past this bound
1120
+ * overflows on load and surfaces as an unreadable document. Port of
1121
+ * eigenpal/docx-editor#1093.
1122
+ */
1123
+ const MAX_REVISION_ID = 2147483647;
1124
+ /**
1125
+ * Coerce any revision id — including one parsed from an untrusted DOCX — into
1126
+ * the range serialized `w:id` attributes may occupy.
1127
+ *
1128
+ * - Malformed (negative, fractional, `NaN`, `Infinity`): collapse to `0`.
1129
+ * - Well-formed but out of range: fold modulo the range (not clamp) so a
1130
+ * contiguous run of overflowing ids stays distinguishable.
1131
+ */
1132
+ function normalizeRevisionId(id) {
1133
+ if (!Number.isInteger(id) || id < 0) return 0;
1134
+ if (id > 2147483647) return id % 2147483648;
1135
+ return id;
1136
+ }
1137
+ /**
1138
+ * Which Unicode bidirectional control a `w:bdo`/`w:dir` wrapper is.
1139
+ *
1140
+ * `w:dir` is an embedding: the run of text inside it is laid out in the given
1141
+ * direction and the bidirectional algorithm still resolves the characters
1142
+ * within it. `w:bdo` is an override: the algorithm is switched off inside and
1143
+ * every character is laid out in the given direction, which is what makes a
1144
+ * Latin word inside an `rtl` override read backwards. CSS spells the pair
1145
+ * `unicode-bidi: embed` and `unicode-bidi: bidi-override`, and HTML gives the
1146
+ * second an element of its own, `<bdo>`.
1147
+ */
1148
+ const BIDI_CONTROLS = {
1149
+ embedding: "embedding",
1150
+ override: "override"
1151
+ };
1152
+ /**
1153
+ * Runtime census of {@link PropertyChange}'s discriminators.
1154
+ *
1155
+ * It is the one place the set is written down. Every consumer that resolves,
1156
+ * lists or compares a property revision is total over it
1157
+ * (`satisfies Record<PropertyRevisionKind, …>`), so a revision the model gains
1158
+ * is a compile error at each of those sites rather than a branch nobody wrote.
1159
+ */
1160
+ const PROPERTY_REVISION_KINDS = Object.freeze({
1161
+ runPropertyChange: "runPropertyChange",
1162
+ paragraphPropertyChange: "paragraphPropertyChange",
1163
+ sectionPropertyChange: "sectionPropertyChange",
1164
+ tablePropertyChange: "tablePropertyChange",
1165
+ tablePropertyExceptionChange: "tablePropertyExceptionChange",
1166
+ tableRowPropertyChange: "tableRowPropertyChange",
1167
+ tableCellPropertyChange: "tableCellPropertyChange"
1168
+ });
1169
+ /**
1170
+ * The kinds a paragraph-mark tracked change can be (ECMA-376 §17.13.5).
1171
+ *
1172
+ * Written as a child of `<w:pPr><w:rPr>` — `<w:ins/>` when the paragraph
1173
+ * break itself was inserted in track-changes mode (the user pressed Enter
1174
+ * mid-paragraph), `<w:del/>` when the paragraph break is pending deletion
1175
+ * (Backspace at paragraph start or Delete at paragraph end). The mark is
1176
+ * independent of the inline runs the paragraph carries.
1177
+ *
1178
+ * A relocated paragraph's break is `<w:moveFrom/>` at the source and
1179
+ * `<w:moveTo/>` at the destination. They resolve exactly as `del` and `ins`
1180
+ * do — a move is a deletion and an insertion that a reader is told belong
1181
+ * together — but they are not those kinds: writing `w:del` on a moved
1182
+ * paragraph's mark reports the relocation as a deletion as well.
1183
+ */
1184
+ const PARAGRAPH_MARK_CHANGE_KINDS = Object.freeze([
1185
+ "moveFrom",
1186
+ "moveTo",
1187
+ "ins",
1188
+ "del"
1189
+ ]);
1190
+ const REVIEW_CARRIERS = { TERMINAL_TABLE: "terminal-table" };
1191
+ //#endregion
1192
+ //#region src/model/document.ts
1193
+ /** DOCX package conformance classes. */
1194
+ const DOCX_CONFORMANCE_CLASSES = Object.freeze({
1195
+ STRICT: "strict",
1196
+ TRANSITIONAL: "transitional",
1197
+ UNKNOWN: "unknown"
1198
+ });
1199
+ //#endregion
1200
+ export { paragraphNumberingSlots as $, THEME_COLOR_BY_SCHEME_COLOR_VALUE as A, BODY_TEXT_OUTLINE_LEVEL as B, PARAGRAPH_ALIGNMENTS as C, TEXT_DIRECTION_FLOWS as D, TEXT_DIRECTIONS as E, themeColorSlot as F, NO_NUMBERING_NUM_ID as G, headingOutlineLevel as H, themeColorToken as I, mergeParagraphNumbering as J, NO_PARAGRAPH_NUMBERING as K, THEME_COLORS as L, isThemeColor as M, knownThemeColor as N, TEXT_DIRECTION_FLOW_BY_TOKEN as O, readThemeColor as P, paragraphNumberingReferenceId as Q, mintRelationshipId as R, NUMBER_FORMATS as S, TAB_STOP_ALIGNMENTS as T, outlineLevelFromStatedValue as U, headingLevelOf as V, outlineLevelStatedValue as W, paragraphNumberingLevel as X, paragraphNumberingFromSlots as Y, paragraphNumberingReference as Z, isBorderNil as _, PARAGRAPH_MARK_CHANGE_KINDS as a, statesNoBorder as b, isOoxmlSymbolCharacter as c, isPresetLineDashVal as d, resolveParagraphNumbering as et, presetLineDashFrom as f, borderStyleToken as g, borderStyleFrom as h, MAX_REVISION_ID as i, PARSE_WARNING_CODES as it, isSchemeColorValue as j, SCHEME_COLOR_VALUE_BY_THEME_COLOR as k, normalizeRevisionId as l, PRESET_LINE_DASH_VALS as m, BIDI_CONTROLS as n, sameStatedParagraphNumbering as nt, PROPERTY_REVISION_KINDS as o, presetLineDashToken as p, isNumberingReference as q, DRAWING_RAW_XML_MODES as r, MAX_RETAINED_PARSE_WARNINGS_PER_CODE as rt, REVIEW_CARRIERS as s, DOCX_CONFORMANCE_CLASSES as t, sameEffectiveParagraphNumbering as tt, COUNTER_FORMATS as u, isBorderNone as v, TABLE_ALIGNMENTS as w, BORDER_STYLES as x, isBorderStyle as y, relationshipIdOf as z };