@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,73 @@
1
+ import { r as PreservedMarkup } from "../preservedMarkup-G8XjWhs2.js";
2
+ //#region src/schema/sequenceChildren.gen.d.ts
3
+ /**
4
+ * GENERATED FILE — do not edit.
5
+ *
6
+ * The containers whose content model declares one order for its children, with
7
+ * the children written in it, derived from the committed schema graph by
8
+ * `scripts/generate-container-children.ts`.
9
+ *
10
+ * It lives in the lower package because two packages write a property set and
11
+ * the dependency runs one way: `@stll/docx-core` compiles a `w:rPr` from a
12
+ * legal source and cannot import `@stll/folio-core`. folio-core's
13
+ * declared-child table spreads this one in, so both write the same order and
14
+ * neither restates it.
15
+ *
16
+ * Regenerate with:
17
+ *
18
+ * bun run generate:container-children
19
+ */
20
+ declare const SEQUENCE_CHILDREN: {
21
+ readonly "w:numbering": readonly ["numPicBullet", "abstractNum", "num", "numIdMacAtCleanup"];
22
+ readonly "w:abstractNum": readonly ["nsid", "multiLevelType", "tmpl", "name", "styleLink", "numStyleLink", "lvl"];
23
+ readonly "w:lvl": readonly ["start", "numFmt", "lvlRestart", "pStyle", "isLgl", "suff", "lvlText", "lvlPicBulletId", "legacy", "lvlJc", "pPr", "rPr"];
24
+ readonly "w:num": readonly ["abstractNumId", "lvlOverride"];
25
+ readonly "w:lvlOverride": readonly ["startOverride", "lvl"];
26
+ readonly "paragraph-properties": readonly ["pStyle", "keepNext", "keepLines", "pageBreakBefore", "framePr", "widowControl", "numPr", "suppressLineNumbers", "pBdr", "shd", "tabs", "suppressAutoHyphens", "kinsoku", "wordWrap", "overflowPunct", "topLinePunct", "autoSpaceDE", "autoSpaceDN", "bidi", "adjustRightInd", "snapToGrid", "spacing", "ind", "contextualSpacing", "mirrorIndents", "suppressOverlap", "jc", "textDirection", "textAlignment", "textboxTightWrap", "outlineLvl", "divId", "cnfStyle", "rPr", "sectPr", "pPrChange"];
27
+ readonly "table-properties": readonly ["tblStyle", "tblpPr", "tblOverlap", "bidiVisual", "tblStyleRowBandSize", "tblStyleColBandSize", "tblW", "jc", "tblCellSpacing", "tblInd", "tblBorders", "shd", "tblLayout", "tblCellMar", "tblLook", "tblCaption", "tblDescription", "tblPrChange"];
28
+ readonly "table-property-exceptions": readonly ["tblW", "jc", "tblCellSpacing", "tblInd", "tblBorders", "shd", "tblLayout", "tblCellMar", "tblLook", "tblPrExChange"];
29
+ readonly "row-properties": readonly ["cnfStyle", "divId", "gridBefore", "gridAfter", "wBefore", "wAfter", "cantSplit", "trHeight", "tblHeader", "tblCellSpacing", "jc", "hidden", "ins", "del", "trPrChange"];
30
+ readonly "cell-properties": readonly ["cnfStyle", "tcW", "gridSpan", "hMerge", "vMerge", "tcBorders", "shd", "noWrap", "tcMar", "textDirection", "tcFitText", "vAlign", "hideMark", "headers", "cellIns", "cellDel", "cellMerge", "tcPrChange"];
31
+ readonly "run-properties": readonly ["ins", "del", "moveFrom", "moveTo", "rStyle", "rFonts", "b", "bCs", "i", "iCs", "caps", "smallCaps", "strike", "dstrike", "outline", "shadow", "emboss", "imprint", "noProof", "snapToGrid", "vanish", "webHidden", "color", "spacing", "w", "kern", "position", "sz", "szCs", "highlight", "u", "effect", "bdr", "shd", "fitText", "vertAlign", "rtl", "cs", "em", "lang", "eastAsianLayout", "specVanish", "oMath", "rPrChange"];
32
+ readonly "content-control-properties": readonly ["rPr", "alias", "tag", "id", "lock", "placeholder", "temporary", "showingPlcHdr", "dataBinding", "label", "tabIndex", "equation", "comboBox", "date", "docPartObj", "docPartList", "dropDownList", "picture", "richText", "text", "citation", "group", "bibliography"];
33
+ readonly "section-properties": readonly ["headerReference", "footerReference", "footnotePr", "endnotePr", "type", "pgSz", "pgMar", "paperSrc", "pgBorders", "lnNumType", "pgNumType", "cols", "formProt", "vAlign", "noEndnote", "titlePg", "textDirection", "bidi", "rtlGutter", "docGrid", "printerSettings", "sectPrChange"];
34
+ };
35
+ /** A container whose declared children have an order. */
36
+ type SequenceContainer = keyof typeof SEQUENCE_CHILDREN;
37
+ /** Every child the schema declares for `Container`, in declaration order. */
38
+ type SequenceChild<Container extends SequenceContainer> = (typeof SEQUENCE_CHILDREN)[Container][number];
39
+ //#endregion
40
+ //#region src/schema/sequenceChildren.d.ts
41
+ type SerializeSequenceChildrenOptions<Container extends SequenceContainer> = {
42
+ container: Container;
43
+ /**
44
+ * The modelled children keyed by element name rather than pre-ordered, so
45
+ * the caller cannot state an order of its own.
46
+ *
47
+ * An empty string means the caller wrote nothing for that child.
48
+ */
49
+ modelled: ReadonlyArray<readonly [name: SequenceChild<Container>, xml: string]>;
50
+ /**
51
+ * The container's unmodelled markup, each capture carrying the schema
52
+ * ordinal it was read at, so it lands between the same two neighbours.
53
+ *
54
+ * A caller that builds a document from scratch has none.
55
+ */
56
+ preserved?: PreservedMarkup | undefined;
57
+ };
58
+ /** Whether a captured child is exactly one bounded, well-formed XML element. */
59
+ declare const isSafePreservedChildXml: (xml: string) => boolean;
60
+ /** Whether a capture collection stays within its aggregate resource budget. */
61
+ declare const isWithinPreservedMarkupBudget: (children: readonly unknown[]) => boolean;
62
+ /** Reject unsafe captured children before a caller performs any transformation. */
63
+ declare const assertSafePreservedMarkup: (preserved: PreservedMarkup | undefined) => void;
64
+ /**
65
+ * A property set's children, modelled and captured, in schema order.
66
+ *
67
+ * Ties are only possible between a declared child and a capture sharing its
68
+ * slot — an undeclared name takes the place of the last declared child before
69
+ * it. The sort is stable and the modelled child leads.
70
+ */
71
+ declare const serializeSequenceChildren: <Container extends SequenceContainer>({ container, modelled, preserved }: SerializeSequenceChildrenOptions<Container>) => string[];
72
+ //#endregion
73
+ export { SEQUENCE_CHILDREN, type SequenceChild, type SequenceContainer, assertSafePreservedMarkup, isSafePreservedChildXml, isWithinPreservedMarkupBudget, serializeSequenceChildren };
@@ -0,0 +1,2 @@
1
+ import { a as SEQUENCE_CHILDREN, i as serializeSequenceChildren, n as isSafePreservedChildXml, r as isWithinPreservedMarkupBudget, t as assertSafePreservedMarkup } from "../sequenceChildren-DlUb7FZG.js";
2
+ export { SEQUENCE_CHILDREN, assertSafePreservedMarkup, isSafePreservedChildXml, isWithinPreservedMarkupBudget, serializeSequenceChildren };
@@ -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.23.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",