@stll/docx-core 0.21.0 → 0.22.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.
- package/dist/{document-Bu82QPAC.d.ts → document-BzVhjQZZ.d.ts} +262 -36
- package/dist/document-CKwRw-01.js +153 -0
- package/dist/docx_kernel_bg.wasm +0 -0
- package/dist/index.d.ts +15 -2
- package/dist/index.js +87 -21
- package/dist/model/document.d.ts +2 -2
- package/dist/model/document.js +2 -2
- package/package.json +1 -1
- package/dist/document-D6wZrAko.js +0 -66
|
@@ -277,6 +277,16 @@ type ParagraphFormatting = {
|
|
|
277
277
|
numId?: number;
|
|
278
278
|
ilvl?: number;
|
|
279
279
|
};
|
|
280
|
+
/**
|
|
281
|
+
* The `w:numberingChange` inside the paragraph's `w:numPr`, verbatim.
|
|
282
|
+
*
|
|
283
|
+
* It records the numbering a paragraph carried before a reviewer changed it,
|
|
284
|
+
* with the author and date of that change. Nothing in the current model
|
|
285
|
+
* derives it, and a rebuilt `w:numPr` that omits it discards a tracked
|
|
286
|
+
* revision without telling anyone. The element is a historical snapshot, so
|
|
287
|
+
* it travels as markup rather than as a parsed shape.
|
|
288
|
+
*/
|
|
289
|
+
numberingChangeXml?: string;
|
|
280
290
|
/** Outline level 0-9 (w:outlineLvl) */
|
|
281
291
|
outlineLevel?: number;
|
|
282
292
|
/** Paragraph style ID (w:pStyle) */
|
|
@@ -351,9 +361,23 @@ type CellMargins = {
|
|
|
351
361
|
right?: TableMeasurement;
|
|
352
362
|
};
|
|
353
363
|
/**
|
|
354
|
-
*
|
|
364
|
+
* `w:tblLook`: which of a table style's conditional formats the table asks for.
|
|
365
|
+
*
|
|
366
|
+
* Every flag is tri-state, because `CT_TblLook` states the same six facts twice
|
|
367
|
+
* and the two spellings are not interchangeable. Absent means the author wrote
|
|
368
|
+
* no such attribute, so the flag falls back to the matching bit of {@link
|
|
369
|
+
* TableLook.val} and then to off; an explicit `false` states the region off and
|
|
370
|
+
* overrides the bit. Writing only the true flags back turns the second and
|
|
371
|
+
* third into the first, which is a different document.
|
|
372
|
+
*
|
|
373
|
+
* Read one with `resolveTableLook`, never on its own.
|
|
355
374
|
*/
|
|
356
375
|
type TableLook = {
|
|
376
|
+
/**
|
|
377
|
+
* `w:val`, the legacy `ST_ShortHexNumber` bitmask, kept as the author spelled
|
|
378
|
+
* it. Producers older than the attribute form write only this.
|
|
379
|
+
*/
|
|
380
|
+
val?: string;
|
|
357
381
|
firstColumn?: boolean;
|
|
358
382
|
firstRow?: boolean;
|
|
359
383
|
lastColumn?: boolean;
|
|
@@ -416,11 +440,21 @@ type TableFormatting = {
|
|
|
416
440
|
*
|
|
417
441
|
* The grid is a sibling of `w:tblPr` rather than a child of it, but it is
|
|
418
442
|
* the table's own property set that travels through the editable model, so
|
|
419
|
-
* it rides along here.
|
|
420
|
-
*
|
|
421
|
-
*
|
|
443
|
+
* it rides along here. It is replayed only while the column widths still
|
|
444
|
+
* agree with it; {@link gridChangeXml} carries the part of it that a rebuild
|
|
445
|
+
* must not drop.
|
|
422
446
|
*/
|
|
423
447
|
gridSourceXml?: string;
|
|
448
|
+
/**
|
|
449
|
+
* The grid's `w:tblGridChange`, verbatim.
|
|
450
|
+
*
|
|
451
|
+
* It records the grid as it stood before a reviewer resized a column, so it
|
|
452
|
+
* is history: nothing in the current model derives it, and rebuilding the
|
|
453
|
+
* grid from the column widths would accept the revision silently. The
|
|
454
|
+
* element is a snapshot of columns rather than a description of them, so it
|
|
455
|
+
* travels as markup rather than as a parsed shape.
|
|
456
|
+
*/
|
|
457
|
+
gridChangeXml?: string;
|
|
424
458
|
/**
|
|
425
459
|
* The element this formatting was parsed from, verbatim.
|
|
426
460
|
*
|
|
@@ -709,8 +743,6 @@ type TextContent = {
|
|
|
709
743
|
type: "text";
|
|
710
744
|
/** The text string */
|
|
711
745
|
text: string;
|
|
712
|
-
/** Preserve whitespace (xml:space="preserve") */
|
|
713
|
-
preserveSpace?: boolean;
|
|
714
746
|
};
|
|
715
747
|
/**
|
|
716
748
|
* Tab character
|
|
@@ -882,26 +914,56 @@ type Hyperlink = {
|
|
|
882
914
|
children: (Run | BookmarkStart | BookmarkEnd)[];
|
|
883
915
|
};
|
|
884
916
|
/**
|
|
885
|
-
*
|
|
917
|
+
* Which side of a `w:customXml` element a range marker was displaced to
|
|
918
|
+
* (`w:displacedByCustomXml`, ST_DisplacedByCustomXml).
|
|
886
919
|
*/
|
|
887
|
-
type
|
|
888
|
-
|
|
889
|
-
|
|
920
|
+
type DisplacedByCustomXml = "next" | "prev";
|
|
921
|
+
/**
|
|
922
|
+
* The attributes of `CT_MarkupRange`, the base type of every range marker:
|
|
923
|
+
* bookmarks, comment ranges, move ranges and their ends.
|
|
924
|
+
*
|
|
925
|
+
* The three types below mirror the schema's own derivation chain
|
|
926
|
+
* (`CT_MarkupRange` → `CT_Bookmark` → `CT_MoveBookmark`) so a marker's model
|
|
927
|
+
* is the element's attribute set rather than a hand-picked subset of it. Every
|
|
928
|
+
* marker that lost attributes on save lost them by declaring its own fields.
|
|
929
|
+
*/
|
|
930
|
+
type MarkupRangeMarker = {
|
|
931
|
+
/** Pairs a start with its end (`w:id`). */
|
|
890
932
|
id: number;
|
|
891
|
-
|
|
933
|
+
displacedByCustomXml?: DisplacedByCustomXml;
|
|
934
|
+
};
|
|
935
|
+
/** `CT_Bookmark`: a named range, optionally scoped to table columns. */
|
|
936
|
+
type BookmarkRangeMarker = MarkupRangeMarker & {
|
|
892
937
|
name: string;
|
|
893
938
|
/** Column index for table bookmarks */
|
|
894
939
|
colFirst?: number;
|
|
895
940
|
colLast?: number;
|
|
896
941
|
};
|
|
942
|
+
/**
|
|
943
|
+
* `CT_MoveBookmark`: a bookmark range attributed to the move that created it.
|
|
944
|
+
*
|
|
945
|
+
* The schema makes `w:author` required, so the field is not optional: a marker
|
|
946
|
+
* that cannot name an author cannot be written at all, and the parser supplies
|
|
947
|
+
* the same `Unknown` fallback a tracked change gets. `w:date` is required too,
|
|
948
|
+
* but a date folio does not have is not a date it may invent, so a document
|
|
949
|
+
* that arrived without one keeps arriving without one.
|
|
950
|
+
*/
|
|
951
|
+
type MoveBookmarkMarker = BookmarkRangeMarker & {
|
|
952
|
+
author: string;
|
|
953
|
+
date?: string;
|
|
954
|
+
};
|
|
955
|
+
/**
|
|
956
|
+
* Bookmark start marker (w:bookmarkStart)
|
|
957
|
+
*/
|
|
958
|
+
type BookmarkStart = {
|
|
959
|
+
type: "bookmarkStart";
|
|
960
|
+
} & BookmarkRangeMarker;
|
|
897
961
|
/**
|
|
898
962
|
* Bookmark end marker (w:bookmarkEnd)
|
|
899
963
|
*/
|
|
900
964
|
type BookmarkEnd = {
|
|
901
965
|
type: "bookmarkEnd";
|
|
902
|
-
|
|
903
|
-
id: number;
|
|
904
|
-
};
|
|
966
|
+
} & MarkupRangeMarker;
|
|
905
967
|
/**
|
|
906
968
|
* Known field types
|
|
907
969
|
*/
|
|
@@ -1040,8 +1102,15 @@ type Image = {
|
|
|
1040
1102
|
type: "image";
|
|
1041
1103
|
/** Unique ID */
|
|
1042
1104
|
id?: string;
|
|
1043
|
-
/**
|
|
1044
|
-
|
|
1105
|
+
/**
|
|
1106
|
+
* Relationship id for the image data, absent when the drawing carries none.
|
|
1107
|
+
*
|
|
1108
|
+
* A `w:drawing` whose graphic is not a picture — a chart, a diagram, an OLE
|
|
1109
|
+
* frame — and one with no `a:graphic` at all have no `a:blip`, so there is no
|
|
1110
|
+
* id to record. Absence is spelled `undefined` rather than `""` so it can
|
|
1111
|
+
* never reach a relationship lookup as a key.
|
|
1112
|
+
*/
|
|
1113
|
+
rId?: string;
|
|
1045
1114
|
/** Resolved image data (base64 or blob URL) */
|
|
1046
1115
|
src?: string;
|
|
1047
1116
|
/** Image MIME type */
|
|
@@ -1308,7 +1377,7 @@ type Table = {
|
|
|
1308
1377
|
columnWidths?: number[];
|
|
1309
1378
|
/** Table rows */
|
|
1310
1379
|
rows: TableRow[];
|
|
1311
|
-
};
|
|
1380
|
+
} & BlockRangeMarkerCapture;
|
|
1312
1381
|
/**
|
|
1313
1382
|
* A comment (w:comment) from comments.xml
|
|
1314
1383
|
*/
|
|
@@ -1335,15 +1404,13 @@ type Comment = {
|
|
|
1335
1404
|
*/
|
|
1336
1405
|
type CommentRangeStart = {
|
|
1337
1406
|
type: "commentRangeStart";
|
|
1338
|
-
|
|
1339
|
-
};
|
|
1407
|
+
} & MarkupRangeMarker;
|
|
1340
1408
|
/**
|
|
1341
1409
|
* Comment range end marker in paragraph content
|
|
1342
1410
|
*/
|
|
1343
1411
|
type CommentRangeEnd = {
|
|
1344
1412
|
type: "commentRangeEnd";
|
|
1345
|
-
|
|
1346
|
-
};
|
|
1413
|
+
} & MarkupRangeMarker;
|
|
1347
1414
|
/**
|
|
1348
1415
|
* Point comment reference (w:commentReference without an explicit range).
|
|
1349
1416
|
* Word sometimes stores comments this way; we anchor them to nearby text for display.
|
|
@@ -1459,38 +1526,63 @@ type MoveTo = {
|
|
|
1459
1526
|
/** Moved content */
|
|
1460
1527
|
content: TrackedRunContent[];
|
|
1461
1528
|
};
|
|
1529
|
+
/**
|
|
1530
|
+
* Which Unicode bidirectional control a `w:bdo`/`w:dir` wrapper is.
|
|
1531
|
+
*
|
|
1532
|
+
* `w:dir` is an embedding: the run of text inside it is laid out in the given
|
|
1533
|
+
* direction and the bidirectional algorithm still resolves the characters
|
|
1534
|
+
* within it. `w:bdo` is an override: the algorithm is switched off inside and
|
|
1535
|
+
* every character is laid out in the given direction, which is what makes a
|
|
1536
|
+
* Latin word inside an `rtl` override read backwards. CSS spells the pair
|
|
1537
|
+
* `unicode-bidi: embed` and `unicode-bidi: bidi-override`, and HTML gives the
|
|
1538
|
+
* second an element of its own, `<bdo>`.
|
|
1539
|
+
*/
|
|
1540
|
+
declare const BIDI_CONTROLS: {
|
|
1541
|
+
readonly embedding: "embedding";
|
|
1542
|
+
readonly override: "override";
|
|
1543
|
+
};
|
|
1544
|
+
type BidiControl = (typeof BIDI_CONTROLS)[keyof typeof BIDI_CONTROLS];
|
|
1545
|
+
/**
|
|
1546
|
+
* A bidirectional embedding or override (w:dir, w:bdo) — ECMA-376 §17.3.2.8, §17.3.2.3.
|
|
1547
|
+
*
|
|
1548
|
+
* A transparent inline wrapper: it changes how its content is laid out and
|
|
1549
|
+
* nothing else, so it nests, it may hold anything paragraph content may hold,
|
|
1550
|
+
* and dropping it changes what the reader sees rather than only what the file
|
|
1551
|
+
* says.
|
|
1552
|
+
*/
|
|
1553
|
+
type BidiWrapper = {
|
|
1554
|
+
type: "bidiWrapper";
|
|
1555
|
+
control: BidiControl;
|
|
1556
|
+
/** `w:val`; absent in the source means the wrapper states no direction. */
|
|
1557
|
+
direction?: "ltr" | "rtl";
|
|
1558
|
+
content: ParagraphContent[];
|
|
1559
|
+
};
|
|
1462
1560
|
/**
|
|
1463
1561
|
* Move-from range start marker (w:moveFromRangeStart) — ECMA-376 §17.13.5.22
|
|
1464
1562
|
* Pairs with moveFromRangeEnd to delimit the source of a move in the document.
|
|
1465
1563
|
*/
|
|
1466
1564
|
type MoveFromRangeStart = {
|
|
1467
1565
|
type: "moveFromRangeStart";
|
|
1468
|
-
|
|
1469
|
-
name: string;
|
|
1470
|
-
};
|
|
1566
|
+
} & MoveBookmarkMarker;
|
|
1471
1567
|
/**
|
|
1472
1568
|
* Move-from range end marker (w:moveFromRangeEnd)
|
|
1473
1569
|
*/
|
|
1474
1570
|
type MoveFromRangeEnd = {
|
|
1475
1571
|
type: "moveFromRangeEnd";
|
|
1476
|
-
|
|
1477
|
-
};
|
|
1572
|
+
} & MarkupRangeMarker;
|
|
1478
1573
|
/**
|
|
1479
1574
|
* Move-to range start marker (w:moveToRangeStart) — ECMA-376 §17.13.5.24
|
|
1480
1575
|
* Pairs with moveToRangeEnd to delimit the destination of a move.
|
|
1481
1576
|
*/
|
|
1482
1577
|
type MoveToRangeStart = {
|
|
1483
1578
|
type: "moveToRangeStart";
|
|
1484
|
-
|
|
1485
|
-
name: string;
|
|
1486
|
-
};
|
|
1579
|
+
} & MoveBookmarkMarker;
|
|
1487
1580
|
/**
|
|
1488
1581
|
* Move-to range end marker (w:moveToRangeEnd)
|
|
1489
1582
|
*/
|
|
1490
1583
|
type MoveToRangeEnd = {
|
|
1491
1584
|
type: "moveToRangeEnd";
|
|
1492
|
-
|
|
1493
|
-
};
|
|
1585
|
+
} & MarkupRangeMarker;
|
|
1494
1586
|
/**
|
|
1495
1587
|
* Run-level tracked wrappers represented in WordprocessingML.
|
|
1496
1588
|
*/
|
|
@@ -1694,11 +1786,11 @@ type BlockSdt = {
|
|
|
1694
1786
|
properties: SdtProperties;
|
|
1695
1787
|
/** Block content inside the control. */
|
|
1696
1788
|
content: BlockContent[];
|
|
1697
|
-
};
|
|
1789
|
+
} & BlockRangeMarkerCapture;
|
|
1698
1790
|
/**
|
|
1699
1791
|
* Paragraph content types
|
|
1700
1792
|
*/
|
|
1701
|
-
type ParagraphContent = Run | Hyperlink | BookmarkStart | BookmarkEnd | SimpleField | ComplexField | InlineSdt | CommentRangeStart | CommentRangeEnd | CommentReference | Insertion | Deletion | MoveFrom | MoveTo | MoveFromRangeStart | MoveFromRangeEnd | MoveToRangeStart | MoveToRangeEnd | MathEquation;
|
|
1793
|
+
type ParagraphContent = Run | Hyperlink | BookmarkStart | BookmarkEnd | SimpleField | ComplexField | InlineSdt | CommentRangeStart | CommentRangeEnd | CommentReference | Insertion | Deletion | MoveFrom | MoveTo | MoveFromRangeStart | MoveFromRangeEnd | MoveToRangeStart | MoveToRangeEnd | BidiWrapper | MathEquation;
|
|
1702
1794
|
/**
|
|
1703
1795
|
* The kinds a paragraph-mark tracked change can be (ECMA-376 §17.13.5).
|
|
1704
1796
|
*
|
|
@@ -1750,7 +1842,7 @@ type Paragraph = {
|
|
|
1750
1842
|
renderedPageBreakBefore?: boolean;
|
|
1751
1843
|
/** Section properties (if this paragraph ends a section) */
|
|
1752
1844
|
sectionProperties?: SectionProperties;
|
|
1753
|
-
};
|
|
1845
|
+
} & BlockRangeMarkerCapture;
|
|
1754
1846
|
/**
|
|
1755
1847
|
* Header/footer type
|
|
1756
1848
|
*/
|
|
@@ -2078,6 +2170,22 @@ type SectionProperties = {
|
|
|
2078
2170
|
/** Section-level tracked property changes (w:sectPrChange) */
|
|
2079
2171
|
propertyChanges?: SectionPropertyChange[];
|
|
2080
2172
|
};
|
|
2173
|
+
/**
|
|
2174
|
+
* Range markers captured verbatim from between two blocks.
|
|
2175
|
+
*
|
|
2176
|
+
* `w:permStart`, `w:customXml*Range*`, and a comment or move range that opens
|
|
2177
|
+
* or closes between blocks are all legal children of `w:body`, `w:tc` and a
|
|
2178
|
+
* header. folio has no model for most of them, and their position is the whole
|
|
2179
|
+
* of their meaning: a protected range that spans three paragraphs is defined
|
|
2180
|
+
* by where its `w:permStart` sits. So they ride on the block they precede or
|
|
2181
|
+
* follow and are replayed there.
|
|
2182
|
+
*/
|
|
2183
|
+
type BlockRangeMarkerCapture = {
|
|
2184
|
+
/** Markup that stood immediately before this block. */
|
|
2185
|
+
rawMarkersBefore?: string;
|
|
2186
|
+
/** Markup that stood after this block, which only the last block can carry. */
|
|
2187
|
+
rawMarkersAfter?: string;
|
|
2188
|
+
};
|
|
2081
2189
|
/**
|
|
2082
2190
|
* Block-level content types
|
|
2083
2191
|
*/
|
|
@@ -2109,6 +2217,105 @@ type DocumentBody = {
|
|
|
2109
2217
|
comments?: Comment[];
|
|
2110
2218
|
};
|
|
2111
2219
|
//#endregion
|
|
2220
|
+
//#region src/model/parseWarning.d.ts
|
|
2221
|
+
/**
|
|
2222
|
+
* What folio normalised to open a document, as data rather than as prose.
|
|
2223
|
+
*
|
|
2224
|
+
* Word accepts input the schema does not describe, so folio accepts it too and
|
|
2225
|
+
* normalises at the parse boundary. Every such decision is recorded here: a
|
|
2226
|
+
* stable `code`, the part it happened in, the best position that part can
|
|
2227
|
+
* name, and the value folio declined to read. A host can count them, group
|
|
2228
|
+
* them, or decide on one; the human-readable string the parser has always
|
|
2229
|
+
* exposed is derived from this, never written by hand at the call site, so the
|
|
2230
|
+
* two cannot drift.
|
|
2231
|
+
*
|
|
2232
|
+
* It lives beside `Document` because it is part of the parsed document, and a
|
|
2233
|
+
* `Document` may be produced by anything that builds this model.
|
|
2234
|
+
*/
|
|
2235
|
+
/**
|
|
2236
|
+
* Every normalisation the parse boundary is allowed to make.
|
|
2237
|
+
*
|
|
2238
|
+
* Adding a member without also giving it a message is a type error: the
|
|
2239
|
+
* formatter map over this union is total.
|
|
2240
|
+
*/
|
|
2241
|
+
declare const PARSE_WARNING_CODES: {
|
|
2242
|
+
/** A package opened from encrypted storage; a save writes it unencrypted. */
|
|
2243
|
+
readonly packageDecrypted: "package-decrypted";
|
|
2244
|
+
/** The archive reader reported something about the package it opened. */
|
|
2245
|
+
readonly packageArchive: "package-archive";
|
|
2246
|
+
/** The main document part is missing; the body is empty. */
|
|
2247
|
+
readonly documentPartMissing: "document-part-missing";
|
|
2248
|
+
/** The model validator reported an issue the parse did not treat as fatal. */
|
|
2249
|
+
readonly documentModelIssue: "document-model-issue";
|
|
2250
|
+
/** A later `w:comment` repeating a `w:id` an earlier one defines. */
|
|
2251
|
+
readonly duplicateCommentId: "duplicate-comment-id";
|
|
2252
|
+
/** A `w:comment` with no readable `w:id`; it can anchor nothing. */
|
|
2253
|
+
readonly missingCommentId: "missing-comment-id";
|
|
2254
|
+
/** A later `w:footnote`/`w:endnote` repeating an id an earlier one defines. */
|
|
2255
|
+
readonly duplicateNoteId: "duplicate-note-id";
|
|
2256
|
+
/** A comment marker naming a comment `comments.xml` never defines. */
|
|
2257
|
+
readonly danglingCommentReference: "dangling-comment-reference";
|
|
2258
|
+
/** A comment range with no matching start or end, re-anchored as a point. */
|
|
2259
|
+
readonly unbalancedCommentRange: "unbalanced-comment-range";
|
|
2260
|
+
/** A `w:headerReference` naming a header part the package does not carry. */
|
|
2261
|
+
readonly danglingHeaderReference: "dangling-header-reference";
|
|
2262
|
+
/** A `w:footerReference` naming a footer part the package does not carry. */
|
|
2263
|
+
readonly danglingFooterReference: "dangling-footer-reference";
|
|
2264
|
+
/** A `r:id` naming a relationship the part's `.rels` does not define. */
|
|
2265
|
+
readonly danglingRelationshipId: "dangling-relationship-id";
|
|
2266
|
+
/** A paragraph naming a `w:num` the numbering part never defines. */
|
|
2267
|
+
readonly unnumberedParagraph: "unnumbered-paragraph";
|
|
2268
|
+
/** A style naming a `w:num` the numbering part never defines. */
|
|
2269
|
+
readonly unnumberedStyle: "unnumbered-style";
|
|
2270
|
+
/** A tracked move range with no matching start or end. */
|
|
2271
|
+
readonly unbalancedMoveRange: "unbalanced-move-range";
|
|
2272
|
+
/** A `w:type` outside `ST_HdrFtr`, read as the enumeration's default. */
|
|
2273
|
+
readonly headerFooterTypeOutsideEnum: "header-footer-type-outside-enum";
|
|
2274
|
+
/** A value outside `ST_OnOff`'s six spellings. */
|
|
2275
|
+
readonly unrecognisedOnOffValue: "unrecognised-on-off-value";
|
|
2276
|
+
/** A `CT_Border` with no `w:val`, which has no border style to read. */
|
|
2277
|
+
readonly borderWithoutValue: "border-without-value";
|
|
2278
|
+
/** A style set defining two styles under one id. */
|
|
2279
|
+
readonly styleSetDuplicateStyleId: "style-set-duplicate-style-id";
|
|
2280
|
+
/** A style set naming an initial paragraph style it does not contain. */
|
|
2281
|
+
readonly styleSetInitialStyleMissing: "style-set-initial-style-missing";
|
|
2282
|
+
};
|
|
2283
|
+
type ParseWarningCode = (typeof PARSE_WARNING_CODES)[keyof typeof PARSE_WARNING_CODES];
|
|
2284
|
+
/** Where a warning happened, as precisely as the part can say. */
|
|
2285
|
+
type ParseWarningLocation = {
|
|
2286
|
+
/** The package part, e.g. `word/document.xml`. `package` for the container. */
|
|
2287
|
+
part: string;
|
|
2288
|
+
/** The element as written, prefix included, when one is known. */
|
|
2289
|
+
element?: string;
|
|
2290
|
+
/**
|
|
2291
|
+
* The best position the part can name: `paragraph 12`, `style "Heading1"`,
|
|
2292
|
+
* `w:id 4`. Free-form because what identifies a place differs per part, and
|
|
2293
|
+
* a byte offset is not available once the tree is built.
|
|
2294
|
+
*/
|
|
2295
|
+
at?: string;
|
|
2296
|
+
};
|
|
2297
|
+
type ParseWarning = {
|
|
2298
|
+
code: ParseWarningCode;
|
|
2299
|
+
location: ParseWarningLocation;
|
|
2300
|
+
/** The value folio declined to read, exactly as the source wrote it. */
|
|
2301
|
+
value?: string;
|
|
2302
|
+
/** How many occurrences this entry stands for; at least 1. */
|
|
2303
|
+
count: number;
|
|
2304
|
+
/**
|
|
2305
|
+
* Text from the owner that produced it, for the codes that pass a message
|
|
2306
|
+
* through from the archive reader or the model validator.
|
|
2307
|
+
*/
|
|
2308
|
+
detail?: string;
|
|
2309
|
+
};
|
|
2310
|
+
/**
|
|
2311
|
+
* The cap on retained warnings per code.
|
|
2312
|
+
*
|
|
2313
|
+
* A generated document can repeat one defect on every paragraph, and a host
|
|
2314
|
+
* that only wants to know a defect occurred should not pay for a hundred
|
|
2315
|
+
* thousand records. Occurrences past the cap are counted, not kept.
|
|
2316
|
+
*/
|
|
2317
|
+
declare const MAX_RETAINED_PARSE_WARNINGS_PER_CODE = 20;
|
|
2318
|
+
//#endregion
|
|
2112
2319
|
//#region src/model/styles.d.ts
|
|
2113
2320
|
/**
|
|
2114
2321
|
* Style type
|
|
@@ -2328,6 +2535,23 @@ type MediaFile = {
|
|
|
2328
2535
|
dataUrl?: string;
|
|
2329
2536
|
};
|
|
2330
2537
|
//#endregion
|
|
2538
|
+
//#region src/model/exhaustiveFields.d.ts
|
|
2539
|
+
/**
|
|
2540
|
+
* Compile-time totality over every field of a model type.
|
|
2541
|
+
*
|
|
2542
|
+
* `ExhaustiveFields<Source, Classified>` resolves to `Source` while
|
|
2543
|
+
* `Classified` names every key of `Source`, and to `never` otherwise. Alias it
|
|
2544
|
+
* next to a table that must decide something per field, and a field added to
|
|
2545
|
+
* the model without a decision turns the alias into `never`, so the module
|
|
2546
|
+
* stops compiling instead of silently dropping the field.
|
|
2547
|
+
*
|
|
2548
|
+
* ```ts
|
|
2549
|
+
* type ClassifiedBorderField = "style" | "color" | "size";
|
|
2550
|
+
* type ExhaustiveBorder = ExhaustiveFields<BorderSpec, ClassifiedBorderField>;
|
|
2551
|
+
* ```
|
|
2552
|
+
*/
|
|
2553
|
+
type ExhaustiveFields<Source, Classified extends keyof Source> = Exclude<keyof Source, Classified> extends never ? Source : never;
|
|
2554
|
+
//#endregion
|
|
2331
2555
|
//#region src/model/document.d.ts
|
|
2332
2556
|
/**
|
|
2333
2557
|
* Document-wide settings parsed from `word/settings.xml`.
|
|
@@ -2460,8 +2684,10 @@ type Document = {
|
|
|
2460
2684
|
templateVariables?: string[];
|
|
2461
2685
|
/** Font families referenced in the document (extracted during parsing for deferred loading) */
|
|
2462
2686
|
requiredFonts?: string[];
|
|
2463
|
-
/** Parsing warnings/errors */
|
|
2687
|
+
/** Parsing warnings/errors, each one rendered from `parseWarnings`. */
|
|
2464
2688
|
warnings?: string[];
|
|
2689
|
+
/** The same warnings as data: a stable code, a location, and the value. */
|
|
2690
|
+
parseWarnings?: ParseWarning[];
|
|
2465
2691
|
};
|
|
2466
2692
|
//#endregion
|
|
2467
|
-
export {
|
|
2693
|
+
export { FieldType as $, TableRowFormatting as $n, SectionStart as $t, BlockRangeMarkerCapture as A, ListLevel as An, NoBreakHyphenContent as At, CommentReference as B, LineSpacingRule as Bn, PictureWatermark as Bt, ParseWarning as C, TrackedRunContent as Cn, MoveBookmarkMarker as Ct, BidiControl as D, normalizeRevisionId as Dn, MoveTo as Dt, BIDI_CONTROLS as E, isOoxmlSymbolCharacter as En, MoveFromRangeStart as Et, BreakContent as F, NumberingInstance as Fn, Paragraph as Ft, DocumentBody as G, TabStop as Gn, Run as Gt, DRAWING_RAW_XML_MODES as H, ParagraphFormatting as Hn, PropertyChangeInfo as Ht, Column as I, CellMargins as In, ParagraphContent as It, Endnote as J, TableCellBorders as Jn, SdtProperties as Jt, DrawingContent as K, TabStopAlignment as Kn, RunContent as Kt, Comment as L, ConditionalFormatStyle as Ln, ParagraphMarkChange as Lt, BookmarkEnd as M, ListRendering as Mn, NoteReferenceContent as Mt, BookmarkRangeMarker as N, NumberFormat as Nn, PARAGRAPH_MARK_CHANGE_KINDS as Nt, BidiWrapper as O, AbstractNumbering as On, MoveToRangeEnd as Ot, BookmarkStart as P, NumberingDefinitions as Pn, PageOrientation as Pt, FieldCharContent as Q, TableMeasurement as Qn, SectionPropertyChange as Qt, CommentRangeEnd as R, EmphasisMark as Rn, ParagraphMarkChangeKind as Rt, PARSE_WARNING_CODES as S, TrackedRunChange as Sn, MathEquation as St, ParseWarningLocation as T, Watermark as Tn, MoveFromRangeEnd as Tt, Deletion as U, SpacingExplicit as Un, REVIEW_CARRIERS as Ut, ComplexField as V, ParagraphAlignment as Vn, PositionalTab as Vt, DisplacedByCustomXml as W, TabLeader as Wn, ReviewCarrier as Wt, EndnoteProperties as X, TableFormatting as Xn, Section as Xt, EndnotePosition as Y, TableCellFormatting as Yn, SdtType as Yt, Field as Z, TableLook as Zn, SectionProperties as Zt, Theme as _, TableStructuralChangeInfo as _n, Insertion as _t, DocxPackage as a, ShapeTextBody as an, ColorValue as ar, HeaderFooterType as at, ThemeFontScheme as b, TextWatermark as bn, MAX_REVISION_ID as bt, FontInfo as c, SoftHyphenContent as cn, ThemeColorSlot as cr, Image as ct, Relationship as d, Table as dn, ImagePadding as dt, Shape as en, TableWidthType as er, FooterReference as et, RelationshipMap as f, TableCell as fn, ImagePosition as ft, StyleType as g, TableRowPropertyChange as gn, InlineSdt as gt, StyleDefinitions as h, TableRow as hn, ImageWrap as ht, DocxConformanceClass as i, ShapeOutline as in, BorderSpec as ir, HeaderFooter as it, BlockSdt as j, ListMarkerFormatting as jn, NoteNumberRestart as jt, BlockContent as k, LevelSuffix as kn, MoveToRangeStart as kt, FontTable as l, SymbolContent as ln, ImageCrop as lt, Style as m, TablePropertyChange as mn, ImageTransform as mt, Document as n, ShapeFill as nn, TextFormatting as nr, FootnotePosition as nt, ExhaustiveFields as o, ShapeType as on, KnownBorderStyle as or, HeaderReference as ot, RelationshipType as p, TableCellPropertyChange as pn, ImageSize as pt, DrawingRawXmlMode as q, TableBorders as qn, RunPropertyChange as qt, DocumentSettings as r, ShapeGeometryAdjustment as rn, UnderlineStyle as rr, FootnoteProperties as rt, DocDefaults as s, SimpleField as sn, ShadingProperties as sr, Hyperlink as st, DOCX_CONFORMANCE_CLASSES as t, ShapeContent as tn, TextEffect as tr, Footnote as tt, MediaFile as u, TabContent as un, ImageFrameLocks as ut, ThemeColorScheme as v, TextBox as vn, InstrTextContent as vt, ParseWarningCode as w, VerticalAlign as wn, MoveFrom as wt, MAX_RETAINED_PARSE_WARNINGS_PER_CODE as x, TrackedChangeInfo as xn, MarkupRangeMarker as xt, ThemeFont as y, TextContent as yn, LineNumberRestart as yt, CommentRangeStart as z, FloatingTableProperties as zn, ParagraphPropertyChange as zt };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
//#region src/model/parseWarning.ts
|
|
2
|
+
/**
|
|
3
|
+
* What folio normalised to open a document, as data rather than as prose.
|
|
4
|
+
*
|
|
5
|
+
* Word accepts input the schema does not describe, so folio accepts it too and
|
|
6
|
+
* normalises at the parse boundary. Every such decision is recorded here: a
|
|
7
|
+
* stable `code`, the part it happened in, the best position that part can
|
|
8
|
+
* name, and the value folio declined to read. A host can count them, group
|
|
9
|
+
* them, or decide on one; the human-readable string the parser has always
|
|
10
|
+
* exposed is derived from this, never written by hand at the call site, so the
|
|
11
|
+
* two cannot drift.
|
|
12
|
+
*
|
|
13
|
+
* It lives beside `Document` because it is part of the parsed document, and a
|
|
14
|
+
* `Document` may be produced by anything that builds this model.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Every normalisation the parse boundary is allowed to make.
|
|
18
|
+
*
|
|
19
|
+
* Adding a member without also giving it a message is a type error: the
|
|
20
|
+
* formatter map over this union is total.
|
|
21
|
+
*/
|
|
22
|
+
const PARSE_WARNING_CODES = {
|
|
23
|
+
/** A package opened from encrypted storage; a save writes it unencrypted. */
|
|
24
|
+
packageDecrypted: "package-decrypted",
|
|
25
|
+
/** The archive reader reported something about the package it opened. */
|
|
26
|
+
packageArchive: "package-archive",
|
|
27
|
+
/** The main document part is missing; the body is empty. */
|
|
28
|
+
documentPartMissing: "document-part-missing",
|
|
29
|
+
/** The model validator reported an issue the parse did not treat as fatal. */
|
|
30
|
+
documentModelIssue: "document-model-issue",
|
|
31
|
+
/** A later `w:comment` repeating a `w:id` an earlier one defines. */
|
|
32
|
+
duplicateCommentId: "duplicate-comment-id",
|
|
33
|
+
/** A `w:comment` with no readable `w:id`; it can anchor nothing. */
|
|
34
|
+
missingCommentId: "missing-comment-id",
|
|
35
|
+
/** A later `w:footnote`/`w:endnote` repeating an id an earlier one defines. */
|
|
36
|
+
duplicateNoteId: "duplicate-note-id",
|
|
37
|
+
/** A comment marker naming a comment `comments.xml` never defines. */
|
|
38
|
+
danglingCommentReference: "dangling-comment-reference",
|
|
39
|
+
/** A comment range with no matching start or end, re-anchored as a point. */
|
|
40
|
+
unbalancedCommentRange: "unbalanced-comment-range",
|
|
41
|
+
/** A `w:headerReference` naming a header part the package does not carry. */
|
|
42
|
+
danglingHeaderReference: "dangling-header-reference",
|
|
43
|
+
/** A `w:footerReference` naming a footer part the package does not carry. */
|
|
44
|
+
danglingFooterReference: "dangling-footer-reference",
|
|
45
|
+
/** A `r:id` naming a relationship the part's `.rels` does not define. */
|
|
46
|
+
danglingRelationshipId: "dangling-relationship-id",
|
|
47
|
+
/** A paragraph naming a `w:num` the numbering part never defines. */
|
|
48
|
+
unnumberedParagraph: "unnumbered-paragraph",
|
|
49
|
+
/** A style naming a `w:num` the numbering part never defines. */
|
|
50
|
+
unnumberedStyle: "unnumbered-style",
|
|
51
|
+
/** A tracked move range with no matching start or end. */
|
|
52
|
+
unbalancedMoveRange: "unbalanced-move-range",
|
|
53
|
+
/** A `w:type` outside `ST_HdrFtr`, read as the enumeration's default. */
|
|
54
|
+
headerFooterTypeOutsideEnum: "header-footer-type-outside-enum",
|
|
55
|
+
/** A value outside `ST_OnOff`'s six spellings. */
|
|
56
|
+
unrecognisedOnOffValue: "unrecognised-on-off-value",
|
|
57
|
+
/** A `CT_Border` with no `w:val`, which has no border style to read. */
|
|
58
|
+
borderWithoutValue: "border-without-value",
|
|
59
|
+
/** A style set defining two styles under one id. */
|
|
60
|
+
styleSetDuplicateStyleId: "style-set-duplicate-style-id",
|
|
61
|
+
/** A style set naming an initial paragraph style it does not contain. */
|
|
62
|
+
styleSetInitialStyleMissing: "style-set-initial-style-missing"
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* The cap on retained warnings per code.
|
|
66
|
+
*
|
|
67
|
+
* A generated document can repeat one defect on every paragraph, and a host
|
|
68
|
+
* that only wants to know a defect occurred should not pay for a hundred
|
|
69
|
+
* thousand records. Occurrences past the cap are counted, not kept.
|
|
70
|
+
*/
|
|
71
|
+
const MAX_RETAINED_PARSE_WARNINGS_PER_CODE = 20;
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/model/content.ts
|
|
74
|
+
const OOXML_SYMBOL_CHARACTER_PATTERN = /^[\dA-Fa-f]{4}$/u;
|
|
75
|
+
/** Whether a symbol character is exactly four hexadecimal digits. */
|
|
76
|
+
const isOoxmlSymbolCharacter = (value) => OOXML_SYMBOL_CHARACTER_PATTERN.test(value);
|
|
77
|
+
/** Raw XML handling modes for drawings that Folio cannot model completely. */
|
|
78
|
+
const DRAWING_RAW_XML_MODES = {
|
|
79
|
+
PRESERVE_ONLY: "preserveOnly",
|
|
80
|
+
/** The modeled image is a rendered preview of richer markup, so regeneration cannot reproduce the drawing. */
|
|
81
|
+
PREVIEW_ONLY: "previewOnly"
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Largest value a revision id (`w:id`) may carry: 2^31 - 1.
|
|
85
|
+
*
|
|
86
|
+
* `w:id` on `<w:ins>`/`<w:del>` comes from `CT_Markup`, typed
|
|
87
|
+
* `ST_DecimalNumber` — which ECMA-376 defines as an unbounded integer. The
|
|
88
|
+
* bound below is an implementation limit: conforming consumers read
|
|
89
|
+
* `ST_DecimalNumber` into a signed 32-bit int, and a value past this bound
|
|
90
|
+
* overflows on load and surfaces as an unreadable document. Port of
|
|
91
|
+
* eigenpal/docx-editor#1093.
|
|
92
|
+
*/
|
|
93
|
+
const MAX_REVISION_ID = 2147483647;
|
|
94
|
+
/**
|
|
95
|
+
* Coerce any revision id — including one parsed from an untrusted DOCX — into
|
|
96
|
+
* the range serialized `w:id` attributes may occupy.
|
|
97
|
+
*
|
|
98
|
+
* - Malformed (negative, fractional, `NaN`, `Infinity`): collapse to `0`.
|
|
99
|
+
* - Well-formed but out of range: fold modulo the range (not clamp) so a
|
|
100
|
+
* contiguous run of overflowing ids stays distinguishable.
|
|
101
|
+
*/
|
|
102
|
+
function normalizeRevisionId(id) {
|
|
103
|
+
if (!Number.isInteger(id) || id < 0) return 0;
|
|
104
|
+
if (id > 2147483647) return id % 2147483648;
|
|
105
|
+
return id;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Which Unicode bidirectional control a `w:bdo`/`w:dir` wrapper is.
|
|
109
|
+
*
|
|
110
|
+
* `w:dir` is an embedding: the run of text inside it is laid out in the given
|
|
111
|
+
* direction and the bidirectional algorithm still resolves the characters
|
|
112
|
+
* within it. `w:bdo` is an override: the algorithm is switched off inside and
|
|
113
|
+
* every character is laid out in the given direction, which is what makes a
|
|
114
|
+
* Latin word inside an `rtl` override read backwards. CSS spells the pair
|
|
115
|
+
* `unicode-bidi: embed` and `unicode-bidi: bidi-override`, and HTML gives the
|
|
116
|
+
* second an element of its own, `<bdo>`.
|
|
117
|
+
*/
|
|
118
|
+
const BIDI_CONTROLS = {
|
|
119
|
+
embedding: "embedding",
|
|
120
|
+
override: "override"
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* The kinds a paragraph-mark tracked change can be (ECMA-376 §17.13.5).
|
|
124
|
+
*
|
|
125
|
+
* Written as a child of `<w:pPr><w:rPr>` — `<w:ins/>` when the paragraph
|
|
126
|
+
* break itself was inserted in track-changes mode (the user pressed Enter
|
|
127
|
+
* mid-paragraph), `<w:del/>` when the paragraph break is pending deletion
|
|
128
|
+
* (Backspace at paragraph start or Delete at paragraph end). The mark is
|
|
129
|
+
* independent of the inline runs the paragraph carries.
|
|
130
|
+
*
|
|
131
|
+
* A relocated paragraph's break is `<w:moveFrom/>` at the source and
|
|
132
|
+
* `<w:moveTo/>` at the destination. They resolve exactly as `del` and `ins`
|
|
133
|
+
* do — a move is a deletion and an insertion that a reader is told belong
|
|
134
|
+
* together — but they are not those kinds: writing `w:del` on a moved
|
|
135
|
+
* paragraph's mark reports the relocation as a deletion as well.
|
|
136
|
+
*/
|
|
137
|
+
const PARAGRAPH_MARK_CHANGE_KINDS = Object.freeze([
|
|
138
|
+
"moveFrom",
|
|
139
|
+
"moveTo",
|
|
140
|
+
"ins",
|
|
141
|
+
"del"
|
|
142
|
+
]);
|
|
143
|
+
const REVIEW_CARRIERS = { TERMINAL_TABLE: "terminal-table" };
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/model/document.ts
|
|
146
|
+
/** DOCX package conformance classes. */
|
|
147
|
+
const DOCX_CONFORMANCE_CLASSES = Object.freeze({
|
|
148
|
+
STRICT: "strict",
|
|
149
|
+
TRANSITIONAL: "transitional",
|
|
150
|
+
UNKNOWN: "unknown"
|
|
151
|
+
});
|
|
152
|
+
//#endregion
|
|
153
|
+
export { PARAGRAPH_MARK_CHANGE_KINDS as a, normalizeRevisionId as c, MAX_REVISION_ID as i, MAX_RETAINED_PARSE_WARNINGS_PER_CODE as l, BIDI_CONTROLS as n, REVIEW_CARRIERS as o, DRAWING_RAW_XML_MODES as r, isOoxmlSymbolCharacter as s, DOCX_CONFORMANCE_CLASSES as t, PARSE_WARNING_CODES as u };
|
package/dist/docx_kernel_bg.wasm
CHANGED
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { F as BreakContent, Ft as Paragraph, G as DocumentBody, Gt as Run, It as ParagraphContent, Kt as RunContent, Pn as NumberingDefinitions, Vt as PositionalTab, Zt as SectionProperties, a as DocxPackage, dn as Table, fn as TableCell, hn as TableRow, i as DocxConformanceClass, k as BlockContent, m as Style, n as Document, t as DOCX_CONFORMANCE_CLASSES, yn as TextContent } from "./document-BzVhjQZZ.js";
|
|
2
2
|
import { Buffer } from "node:buffer";
|
|
3
3
|
//#region src/legal-source/types.d.ts
|
|
4
4
|
type LegalDocumentKind = "agreement" | "letter" | "memo" | "checklist" | "pleading" | "other";
|
|
@@ -150,6 +150,19 @@ type SerializeDocumentOptions = {
|
|
|
150
150
|
};
|
|
151
151
|
declare const serializeDocumentToDocx: (document: Document, options?: SerializeDocumentOptions) => Promise<ArrayBuffer>;
|
|
152
152
|
//#endregion
|
|
153
|
+
//#region src/serialize/textWhitespace.d.ts
|
|
154
|
+
/**
|
|
155
|
+
* Whether `<w:t>` needs `xml:space="preserve"` to render the text as written.
|
|
156
|
+
*
|
|
157
|
+
* Without the attribute an XML reader trims leading and trailing spaces and
|
|
158
|
+
* collapses runs of them, so the attribute is a pure function of the text: it
|
|
159
|
+
* is needed exactly when that normalisation would change what the reader sees.
|
|
160
|
+
* The model therefore keeps no flag of its own — a stored copy of a derived
|
|
161
|
+
* fact only drifts, and it did: the editor round trip dropped it whenever two
|
|
162
|
+
* runs merged, because ProseMirror has nowhere to carry it.
|
|
163
|
+
*/
|
|
164
|
+
declare const requiresXmlSpacePreserve: (text: string) => boolean;
|
|
165
|
+
//#endregion
|
|
153
166
|
//#region src/validate/docx.d.ts
|
|
154
167
|
declare const DOCX_PACKAGE_ISSUE_CODES: {
|
|
155
168
|
readonly ArchiveBoundsExceeded: "archive_bounds_exceeded";
|
|
@@ -179,4 +192,4 @@ declare const validateDocxPackage: (buffer: ArrayBuffer | Uint8Array) => Promise
|
|
|
179
192
|
declare const validateDocumentModel: (document: Document) => ValidateDocumentModelResult;
|
|
180
193
|
declare const assertValidDocumentModel: (document: Document) => void;
|
|
181
194
|
//#endregion
|
|
182
|
-
export { type Autofix, type BlockContent, type BreakContent, type CompiledLegalDocument, DOCX_CONFORMANCE_CLASSES, DOCX_PACKAGE_ISSUE_CODES, type Document, type DocumentBody, type DocxConformanceClass, type DocxPackage, type DocxPackageIssueCode, type LegalDraft, type LegalDraftBlock, type LegalDraftDiagnostic, type LegalSourceCompileOptions, type LegalSourceCompileResult, type LegalSourceDocxCompileResult, type LegalSourceParseResult, type MarkdownContent, type Paragraph, type ParagraphContent, type PositionalTab, type Run, type RunContent, type SectionProperties, type Style, type Table, type TableCell, type TableRow, type TextContent, type ValidateDocumentModelIssue, type ValidateDocumentModelResult, type ValidateDocxPackageResult, assertValidDocumentModel, compileLegalSourceToDocument, compileLegalSourceToDocx, compileMarkdownToContent, parseLegalSource, sanitizeExternalUrl, serializeDocumentToDocx, validateDocumentModel, validateDocxPackage, validateLegalDraft };
|
|
195
|
+
export { type Autofix, type BlockContent, type BreakContent, type CompiledLegalDocument, DOCX_CONFORMANCE_CLASSES, DOCX_PACKAGE_ISSUE_CODES, type Document, type DocumentBody, type DocxConformanceClass, type DocxPackage, type DocxPackageIssueCode, type LegalDraft, type LegalDraftBlock, type LegalDraftDiagnostic, type LegalSourceCompileOptions, type LegalSourceCompileResult, type LegalSourceDocxCompileResult, type LegalSourceParseResult, type MarkdownContent, type Paragraph, type ParagraphContent, type PositionalTab, type Run, type RunContent, type SectionProperties, type Style, type Table, type TableCell, type TableRow, type TextContent, type ValidateDocumentModelIssue, type ValidateDocumentModelResult, type ValidateDocxPackageResult, assertValidDocumentModel, compileLegalSourceToDocument, compileLegalSourceToDocx, compileMarkdownToContent, parseLegalSource, requiresXmlSpacePreserve, sanitizeExternalUrl, serializeDocumentToDocx, validateDocumentModel, validateDocxPackage, validateLegalDraft };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { s as isOoxmlSymbolCharacter, t as DOCX_CONFORMANCE_CLASSES } from "./document-CKwRw-01.js";
|
|
2
2
|
import JSZip from "jszip";
|
|
3
3
|
import { panic } from "better-result";
|
|
4
4
|
import { XMLParser, XMLValidator } from "fast-xml-parser";
|
|
5
5
|
import { Marked } from "marked";
|
|
6
|
+
//#region src/serialize/textWhitespace.ts
|
|
7
|
+
/**
|
|
8
|
+
* Whether `<w:t>` needs `xml:space="preserve"` to render the text as written.
|
|
9
|
+
*
|
|
10
|
+
* Without the attribute an XML reader trims leading and trailing spaces and
|
|
11
|
+
* collapses runs of them, so the attribute is a pure function of the text: it
|
|
12
|
+
* is needed exactly when that normalisation would change what the reader sees.
|
|
13
|
+
* The model therefore keeps no flag of its own — a stored copy of a derived
|
|
14
|
+
* fact only drifts, and it did: the editor round trip dropped it whenever two
|
|
15
|
+
* runs merged, because ProseMirror has nowhere to carry it.
|
|
16
|
+
*/
|
|
17
|
+
const requiresXmlSpacePreserve = (text) => text.startsWith(" ") || text.endsWith(" ") || text.includes(" ");
|
|
18
|
+
//#endregion
|
|
6
19
|
//#region src/serialize/xml.ts
|
|
7
20
|
const ILLEGAL_XML_CHARS_RE = /[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/gu;
|
|
8
21
|
const stripIllegalXmlChars = (value) => value.replace(ILLEGAL_XML_CHARS_RE, "");
|
|
@@ -161,6 +174,7 @@ const serializeParagraphContent = (content) => {
|
|
|
161
174
|
case "moveFromRangeEnd":
|
|
162
175
|
case "moveToRangeStart":
|
|
163
176
|
case "moveToRangeEnd":
|
|
177
|
+
case "bidiWrapper":
|
|
164
178
|
case "mathEquation": return "";
|
|
165
179
|
default: return "";
|
|
166
180
|
}
|
|
@@ -192,7 +206,7 @@ const serializeRunProperties = (formatting) => {
|
|
|
192
206
|
};
|
|
193
207
|
const serializeRunContent = (content) => {
|
|
194
208
|
switch (content.type) {
|
|
195
|
-
case "text": return `<w:t${content.
|
|
209
|
+
case "text": return `<w:t${requiresXmlSpacePreserve(content.text) ? " xml:space=\"preserve\"" : ""}>${escapeXml(content.text)}</w:t>`;
|
|
196
210
|
case "tab":
|
|
197
211
|
if (!content.positional) return "<w:tab/>";
|
|
198
212
|
return `<w:ptab${attr("w:relativeTo", content.positional.relativeTo)}${attr("w:alignment", content.positional.alignment)}${attr("w:leader", content.positional.leader)}/>`;
|
|
@@ -228,7 +242,7 @@ const serializeTable = (table) => {
|
|
|
228
242
|
};
|
|
229
243
|
const renderTableBorders = (table) => {
|
|
230
244
|
const borders = table.formatting?.borders;
|
|
231
|
-
if (!borders) return
|
|
245
|
+
if (!borders) return authoredTableGridXml();
|
|
232
246
|
return [
|
|
233
247
|
borderEdgeXml("w:top", borders.top),
|
|
234
248
|
borderEdgeXml("w:left", borders.left),
|
|
@@ -240,7 +254,7 @@ const renderTableBorders = (table) => {
|
|
|
240
254
|
};
|
|
241
255
|
const renderCellBorders = (table) => {
|
|
242
256
|
const borders = table.formatting?.borders;
|
|
243
|
-
if (!borders) return
|
|
257
|
+
if (!borders) return authoredTableGridXml();
|
|
244
258
|
return [
|
|
245
259
|
borderEdgeXml("w:top", borders.top),
|
|
246
260
|
borderEdgeXml("w:left", borders.left),
|
|
@@ -250,12 +264,36 @@ const renderCellBorders = (table) => {
|
|
|
250
264
|
};
|
|
251
265
|
const borderEdgeXml = (tag, spec) => {
|
|
252
266
|
if (!spec) return `<${tag} w:val="nil"/>`;
|
|
253
|
-
if (spec.style === "none" || spec.style === "nil") return `<${tag} w:val="
|
|
267
|
+
if (spec.style === "none" || spec.style === "nil") return `<${tag} w:val="${escapeXml(spec.style)}"/>`;
|
|
254
268
|
const sz = spec.size ?? 4;
|
|
255
269
|
const color = spec.color?.rgb ?? "CCCCCC";
|
|
256
270
|
return `<${tag} w:val="${escapeXml(spec.style)}" w:sz="${sz}" w:space="0" w:color="${escapeXml(color)}"/>`;
|
|
257
271
|
};
|
|
258
|
-
|
|
272
|
+
/**
|
|
273
|
+
* The grid this generator gives a table that declares no borders of its own.
|
|
274
|
+
*
|
|
275
|
+
* This is an authoring choice, not a round trip: `serializeDocumentToDocx`
|
|
276
|
+
* builds a package from a model assembled here (the legal-source compiler and
|
|
277
|
+
* markdown), where a table with no `formatting.borders` means "the author did
|
|
278
|
+
* not say", and a borderless table reads as a layout accident. A package parsed
|
|
279
|
+
* from a real DOCX never reaches this generator; it is re-serialized by
|
|
280
|
+
* `@stll/folio-core`, which writes back exactly the borders it read.
|
|
281
|
+
*/
|
|
282
|
+
const AUTHORED_TABLE_GRID_EDGE = {
|
|
283
|
+
style: "single",
|
|
284
|
+
size: 4,
|
|
285
|
+
space: 0,
|
|
286
|
+
color: { rgb: "CCCCCC" }
|
|
287
|
+
};
|
|
288
|
+
const AUTHORED_TABLE_GRID_EDGES = [
|
|
289
|
+
"w:top",
|
|
290
|
+
"w:left",
|
|
291
|
+
"w:bottom",
|
|
292
|
+
"w:right",
|
|
293
|
+
"w:insideH",
|
|
294
|
+
"w:insideV"
|
|
295
|
+
];
|
|
296
|
+
const authoredTableGridXml = () => AUTHORED_TABLE_GRID_EDGES.map((tag) => borderEdgeXml(tag, AUTHORED_TABLE_GRID_EDGE)).join("");
|
|
259
297
|
const serializeSectionProperties = (properties) => `<w:sectPr><w:footerReference w:type="default" r:id="${DEFAULT_FOOTER_REL_ID}"/><w:pgSz${attr("w:w", properties.pageWidth)}${attr("w:h", properties.pageHeight)}${attr("w:orient", properties.orientation === "landscape" ? "landscape" : void 0)}/><w:pgMar${attr("w:top", properties.marginTop)}${attr("w:right", properties.marginRight)}${attr("w:bottom", properties.marginBottom)}${attr("w:left", properties.marginLeft)}${attr("w:header", properties.headerDistance)}${attr("w:footer", properties.footerDistance)}${attr("w:gutter", properties.gutter ?? 0)}/></w:sectPr>`;
|
|
260
298
|
const serializeStyles = (styles) => {
|
|
261
299
|
const styleDefinitions = styles ?? { styles: [] };
|
|
@@ -653,6 +691,10 @@ const validateParagraphContent = (content, path, ctx) => {
|
|
|
653
691
|
increment(ctx.moveToEnds, content.id);
|
|
654
692
|
return;
|
|
655
693
|
}
|
|
694
|
+
if (content.type === "bidiWrapper") {
|
|
695
|
+
for (const [index, child] of content.content.entries()) validateParagraphContent(child, `${path}.content[${index}]`, ctx);
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
656
698
|
if (content.ommlXml.trim() === "") addError(ctx, `${path}.ommlXml`, "Math equation must preserve OMML XML.");
|
|
657
699
|
};
|
|
658
700
|
const validateFieldChild = (child, path, ctx) => {
|
|
@@ -683,8 +725,7 @@ const validateRunContent = (content, path, ctx) => {
|
|
|
683
725
|
return;
|
|
684
726
|
}
|
|
685
727
|
if (content.type === "symbol") {
|
|
686
|
-
if (content.
|
|
687
|
-
if (!isOoxmlSymbolCharacter(content.char)) addError(ctx, `${path}.char`, "Symbol character must be exactly four hexadecimal digits.");
|
|
728
|
+
if (content.char !== "" && !isOoxmlSymbolCharacter(content.char)) addError(ctx, `${path}.char`, "Symbol character must be exactly four hexadecimal digits.");
|
|
688
729
|
}
|
|
689
730
|
};
|
|
690
731
|
const validateHyperlink = (hyperlink, path, ctx) => {
|
|
@@ -980,14 +1021,12 @@ const textRun = (text, format = {}) => {
|
|
|
980
1021
|
if (index > 0) content.push({ type: "break" });
|
|
981
1022
|
if (segment.length > 0) content.push({
|
|
982
1023
|
type: "text",
|
|
983
|
-
text: segment
|
|
984
|
-
preserveSpace: true
|
|
1024
|
+
text: segment
|
|
985
1025
|
});
|
|
986
1026
|
}
|
|
987
1027
|
if (content.length === 0) content.push({
|
|
988
1028
|
type: "text",
|
|
989
|
-
text: ""
|
|
990
|
-
preserveSpace: true
|
|
1029
|
+
text: ""
|
|
991
1030
|
});
|
|
992
1031
|
return {
|
|
993
1032
|
type: "run",
|
|
@@ -2104,7 +2143,8 @@ const createStyleDefinitions = () => ({
|
|
|
2104
2143
|
pPr: {
|
|
2105
2144
|
keepNext: true,
|
|
2106
2145
|
spaceBefore: 360,
|
|
2107
|
-
spaceAfter: 160
|
|
2146
|
+
spaceAfter: 160,
|
|
2147
|
+
outlineLevel: 0
|
|
2108
2148
|
}
|
|
2109
2149
|
},
|
|
2110
2150
|
{
|
|
@@ -2121,7 +2161,8 @@ const createStyleDefinitions = () => ({
|
|
|
2121
2161
|
pPr: {
|
|
2122
2162
|
keepNext: true,
|
|
2123
2163
|
spaceBefore: 240,
|
|
2124
|
-
spaceAfter: 120
|
|
2164
|
+
spaceAfter: 120,
|
|
2165
|
+
outlineLevel: 1
|
|
2125
2166
|
}
|
|
2126
2167
|
},
|
|
2127
2168
|
{
|
|
@@ -2135,7 +2176,8 @@ const createStyleDefinitions = () => ({
|
|
|
2135
2176
|
pPr: {
|
|
2136
2177
|
keepNext: true,
|
|
2137
2178
|
spaceBefore: 160,
|
|
2138
|
-
spaceAfter: 120
|
|
2179
|
+
spaceAfter: 120,
|
|
2180
|
+
outlineLevel: 2
|
|
2139
2181
|
}
|
|
2140
2182
|
},
|
|
2141
2183
|
{
|
|
@@ -2450,13 +2492,37 @@ const listBlocks = (list, level, parentNumId, numIds) => {
|
|
|
2450
2492
|
}
|
|
2451
2493
|
return out;
|
|
2452
2494
|
};
|
|
2495
|
+
/**
|
|
2496
|
+
* The deepest heading the built-in style sets define, so a `#####` compiles to
|
|
2497
|
+
* a style the document actually has.
|
|
2498
|
+
*/
|
|
2453
2499
|
const MAX_HEADING_LEVEL = 4;
|
|
2500
|
+
/**
|
|
2501
|
+
* The style id for a markdown heading, plus the outline level it stands for.
|
|
2502
|
+
*
|
|
2503
|
+
* The id is English because the document this content lands in is one folio
|
|
2504
|
+
* created, and folio's style sets define `Heading1`…`HeadingN` under the
|
|
2505
|
+
* built-in name. The outline level is what makes the classification survive
|
|
2506
|
+
* anyway: a consumer reads `w:outlineLvl` first (see
|
|
2507
|
+
* `@stll/folio-core/docx/builtInStyles`), so the paragraph stays a heading
|
|
2508
|
+
* even when merged into a document whose own heading styles are localized and
|
|
2509
|
+
* this id resolves to nothing.
|
|
2510
|
+
*/
|
|
2511
|
+
const headingParagraph = (runs, depth) => {
|
|
2512
|
+
const level = Math.min(Math.max(depth, 1), MAX_HEADING_LEVEL);
|
|
2513
|
+
const paragraph = para(runs, `Heading${level}`);
|
|
2514
|
+
paragraph.formatting = {
|
|
2515
|
+
...paragraph.formatting,
|
|
2516
|
+
outlineLevel: level - 1
|
|
2517
|
+
};
|
|
2518
|
+
return paragraph;
|
|
2519
|
+
};
|
|
2520
|
+
/** The built-in a markdown blockquote compiles to. */
|
|
2521
|
+
const QUOTE_STYLE_ID = "Quote";
|
|
2454
2522
|
const blocksFromTokens = (tokens, numIds) => {
|
|
2455
2523
|
const blocks = [];
|
|
2456
|
-
for (const token of tokens ?? []) if (isTokenType(token, "heading"))
|
|
2457
|
-
|
|
2458
|
-
blocks.push(para(inlineTokensToRuns(token.tokens, token.text), `Heading${level}`));
|
|
2459
|
-
} else if (isTokenType(token, "paragraph")) blocks.push(para(inlineTokensToRuns(token.tokens, token.text)));
|
|
2524
|
+
for (const token of tokens ?? []) if (isTokenType(token, "heading")) blocks.push(headingParagraph(inlineTokensToRuns(token.tokens, token.text), token.depth));
|
|
2525
|
+
else if (isTokenType(token, "paragraph")) blocks.push(para(inlineTokensToRuns(token.tokens, token.text)));
|
|
2460
2526
|
else if (isTokenType(token, "list")) {
|
|
2461
2527
|
const numId = numIds.next++;
|
|
2462
2528
|
numIds.levels.set(numId, /* @__PURE__ */ new Map());
|
|
@@ -2468,7 +2534,7 @@ const blocksFromTokens = (tokens, numIds) => {
|
|
|
2468
2534
|
...inner,
|
|
2469
2535
|
formatting: {
|
|
2470
2536
|
...inner.formatting,
|
|
2471
|
-
styleId:
|
|
2537
|
+
styleId: QUOTE_STYLE_ID
|
|
2472
2538
|
}
|
|
2473
2539
|
} : inner;
|
|
2474
2540
|
blocks.push(styled);
|
|
@@ -2513,4 +2579,4 @@ const compileMarkdownToContent = (markdown) => {
|
|
|
2513
2579
|
};
|
|
2514
2580
|
};
|
|
2515
2581
|
//#endregion
|
|
2516
|
-
export { DOCX_CONFORMANCE_CLASSES, DOCX_PACKAGE_ISSUE_CODES, assertValidDocumentModel, compileLegalSourceToDocument, compileLegalSourceToDocx, compileMarkdownToContent, parseLegalSource, sanitizeExternalUrl, serializeDocumentToDocx, validateDocumentModel, validateDocxPackage, validateLegalDraft };
|
|
2582
|
+
export { DOCX_CONFORMANCE_CLASSES, DOCX_PACKAGE_ISSUE_CODES, assertValidDocumentModel, compileLegalSourceToDocument, compileLegalSourceToDocx, compileMarkdownToContent, parseLegalSource, requiresXmlSpacePreserve, sanitizeExternalUrl, serializeDocumentToDocx, validateDocumentModel, validateDocxPackage, validateLegalDraft };
|
package/dist/model/document.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
export { type AbstractNumbering, type BlockContent, type BlockSdt, type BookmarkEnd, type BookmarkStart, type BorderSpec, type BreakContent, type CellMargins, type ColorValue, type Column, type Comment, type CommentRangeEnd, type CommentRangeStart, type CommentReference, type ComplexField, type ConditionalFormatStyle, DOCX_CONFORMANCE_CLASSES, DRAWING_RAW_XML_MODES, type Deletion, type DocDefaults, Document, type DocumentBody, DocumentSettings, DocxConformanceClass, DocxPackage, type DrawingContent, type DrawingRawXmlMode, type EmphasisMark, type Endnote, type EndnotePosition, type EndnoteProperties, type Field, type FieldCharContent, type FieldType, type FloatingTableProperties, type FontInfo, type FontTable, type FooterReference, type Footnote, type FootnotePosition, type FootnoteProperties, type HeaderFooter, type HeaderFooterType, type HeaderReference, type Hyperlink, type Image, type ImageCrop, type ImageFrameLocks, type ImagePadding, type ImagePosition, type ImageSize, type ImageTransform, type ImageWrap, type InlineSdt, type Insertion, type InstrTextContent, type KnownBorderStyle, type LevelSuffix, type LineNumberRestart, type LineSpacingRule, type ListLevel, type ListMarkerFormatting, type ListRendering, MAX_REVISION_ID, type MathEquation, type MediaFile, type MoveFrom, type MoveFromRangeEnd, type MoveFromRangeStart, type MoveTo, type MoveToRangeEnd, type MoveToRangeStart, type NoBreakHyphenContent, type NoteNumberRestart, type NoteReferenceContent, type NumberFormat, type NumberingDefinitions, type NumberingInstance, PARAGRAPH_MARK_CHANGE_KINDS, type PageOrientation, type Paragraph, type ParagraphAlignment, type ParagraphContent, type ParagraphFormatting, type ParagraphMarkChange, type ParagraphMarkChangeKind, type ParagraphPropertyChange, type PictureWatermark, type PositionalTab, type PropertyChangeInfo, REVIEW_CARRIERS, type Relationship, type RelationshipMap, type RelationshipType, type ReviewCarrier, type Run, type RunContent, type RunPropertyChange, type SdtProperties, type SdtType, type Section, type SectionProperties, type SectionPropertyChange, type SectionStart, type ShadingProperties, type Shape, type ShapeContent, type ShapeFill, type ShapeGeometryAdjustment, type ShapeOutline, type ShapeTextBody, type ShapeType, type SimpleField, type SoftHyphenContent, type SpacingExplicit, type Style, type StyleDefinitions, type StyleType, type SymbolContent, type TabContent, type TabLeader, type TabStop, type TabStopAlignment, type Table, type TableBorders, type TableCell, type TableCellBorders, type TableCellFormatting, type TableCellPropertyChange, type TableFormatting, type TableLook, type TableMeasurement, type TablePropertyChange, type TableRow, type TableRowFormatting, type TableRowPropertyChange, type TableStructuralChangeInfo, type TableWidthType, type TextBox, type TextContent, type TextEffect, type TextFormatting, type TextWatermark, type Theme, type ThemeColorScheme, type ThemeColorSlot, type ThemeFont, type ThemeFontScheme, type TrackedChangeInfo, type TrackedRunChange, type TrackedRunContent, type UnderlineStyle, type VerticalAlign, type Watermark, isOoxmlSymbolCharacter, normalizeRevisionId };
|
|
1
|
+
import { $ as FieldType, $n as TableRowFormatting, $t as SectionStart, A as BlockRangeMarkerCapture, An as ListLevel, At as NoBreakHyphenContent, B as CommentReference, Bn as LineSpacingRule, Bt as PictureWatermark, C as ParseWarning, Cn as TrackedRunContent, Ct as MoveBookmarkMarker, D as BidiControl, Dn as normalizeRevisionId, Dt as MoveTo, E as BIDI_CONTROLS, En as isOoxmlSymbolCharacter, Et as MoveFromRangeStart, F as BreakContent, Fn as NumberingInstance, Ft as Paragraph, G as DocumentBody, Gn as TabStop, Gt as Run, H as DRAWING_RAW_XML_MODES, Hn as ParagraphFormatting, Ht as PropertyChangeInfo, I as Column, In as CellMargins, It as ParagraphContent, J as Endnote, Jn as TableCellBorders, Jt as SdtProperties, K as DrawingContent, Kn as TabStopAlignment, Kt as RunContent, L as Comment, Ln as ConditionalFormatStyle, Lt as ParagraphMarkChange, M as BookmarkEnd, Mn as ListRendering, Mt as NoteReferenceContent, N as BookmarkRangeMarker, Nn as NumberFormat, Nt as PARAGRAPH_MARK_CHANGE_KINDS, O as BidiWrapper, On as AbstractNumbering, Ot as MoveToRangeEnd, P as BookmarkStart, Pn as NumberingDefinitions, Pt as PageOrientation, Q as FieldCharContent, Qn as TableMeasurement, Qt as SectionPropertyChange, R as CommentRangeEnd, Rn as EmphasisMark, Rt as ParagraphMarkChangeKind, S as PARSE_WARNING_CODES, Sn as TrackedRunChange, St as MathEquation, T as ParseWarningLocation, Tn as Watermark, Tt as MoveFromRangeEnd, U as Deletion, Un as SpacingExplicit, Ut as REVIEW_CARRIERS, V as ComplexField, Vn as ParagraphAlignment, Vt as PositionalTab, W as DisplacedByCustomXml, Wn as TabLeader, Wt as ReviewCarrier, X as EndnoteProperties, Xn as TableFormatting, Xt as Section, Y as EndnotePosition, Yn as TableCellFormatting, Yt as SdtType, Z as Field, Zn as TableLook, Zt as SectionProperties, _ as Theme, _n as TableStructuralChangeInfo, _t as Insertion, a as DocxPackage, an as ShapeTextBody, ar as ColorValue, at as HeaderFooterType, b as ThemeFontScheme, bn as TextWatermark, bt as MAX_REVISION_ID, c as FontInfo, cn as SoftHyphenContent, cr as ThemeColorSlot, ct as Image, d as Relationship, dn as Table, dt as ImagePadding, en as Shape, er as TableWidthType, et as FooterReference, f as RelationshipMap, fn as TableCell, ft as ImagePosition, g as StyleType, gn as TableRowPropertyChange, gt as InlineSdt, h as StyleDefinitions, hn as TableRow, ht as ImageWrap, i as DocxConformanceClass, in as ShapeOutline, ir as BorderSpec, it as HeaderFooter, j as BlockSdt, jn as ListMarkerFormatting, jt as NoteNumberRestart, k as BlockContent, kn as LevelSuffix, kt as MoveToRangeStart, l as FontTable, ln as SymbolContent, lt as ImageCrop, m as Style, mn as TablePropertyChange, mt as ImageTransform, n as Document, nn as ShapeFill, nr as TextFormatting, nt as FootnotePosition, o as ExhaustiveFields, on as ShapeType, or as KnownBorderStyle, ot as HeaderReference, p as RelationshipType, pn as TableCellPropertyChange, pt as ImageSize, q as DrawingRawXmlMode, qn as TableBorders, qt as RunPropertyChange, r as DocumentSettings, rn as ShapeGeometryAdjustment, rr as UnderlineStyle, rt as FootnoteProperties, s as DocDefaults, sn as SimpleField, sr as ShadingProperties, st as Hyperlink, t as DOCX_CONFORMANCE_CLASSES, tn as ShapeContent, tr as TextEffect, tt as Footnote, u as MediaFile, un as TabContent, ut as ImageFrameLocks, v as ThemeColorScheme, vn as TextBox, vt as InstrTextContent, w as ParseWarningCode, wn as VerticalAlign, wt as MoveFrom, x as MAX_RETAINED_PARSE_WARNINGS_PER_CODE, xn as TrackedChangeInfo, xt as MarkupRangeMarker, y as ThemeFont, yn as TextContent, yt as LineNumberRestart, z as CommentRangeStart, zn as FloatingTableProperties, zt as ParagraphPropertyChange } from "../document-BzVhjQZZ.js";
|
|
2
|
+
export { type AbstractNumbering, BIDI_CONTROLS, type BidiControl, type BidiWrapper, type BlockContent, type BlockRangeMarkerCapture, type BlockSdt, type BookmarkEnd, type BookmarkRangeMarker, type BookmarkStart, type BorderSpec, type BreakContent, type CellMargins, type ColorValue, type Column, type Comment, type CommentRangeEnd, type CommentRangeStart, type CommentReference, type ComplexField, type ConditionalFormatStyle, DOCX_CONFORMANCE_CLASSES, DRAWING_RAW_XML_MODES, type Deletion, type DisplacedByCustomXml, type DocDefaults, Document, type DocumentBody, DocumentSettings, DocxConformanceClass, DocxPackage, type DrawingContent, type DrawingRawXmlMode, type EmphasisMark, type Endnote, type EndnotePosition, type EndnoteProperties, type ExhaustiveFields, type Field, type FieldCharContent, type FieldType, type FloatingTableProperties, type FontInfo, type FontTable, type FooterReference, type Footnote, type FootnotePosition, type FootnoteProperties, type HeaderFooter, type HeaderFooterType, type HeaderReference, type Hyperlink, type Image, type ImageCrop, type ImageFrameLocks, type ImagePadding, type ImagePosition, type ImageSize, type ImageTransform, type ImageWrap, type InlineSdt, type Insertion, type InstrTextContent, type KnownBorderStyle, type LevelSuffix, type LineNumberRestart, type LineSpacingRule, type ListLevel, type ListMarkerFormatting, type ListRendering, MAX_RETAINED_PARSE_WARNINGS_PER_CODE, MAX_REVISION_ID, type MarkupRangeMarker, type MathEquation, type MediaFile, type MoveBookmarkMarker, type MoveFrom, type MoveFromRangeEnd, type MoveFromRangeStart, type MoveTo, type MoveToRangeEnd, type MoveToRangeStart, type NoBreakHyphenContent, type NoteNumberRestart, type NoteReferenceContent, type NumberFormat, type NumberingDefinitions, type NumberingInstance, PARAGRAPH_MARK_CHANGE_KINDS, PARSE_WARNING_CODES, type PageOrientation, type Paragraph, type ParagraphAlignment, type ParagraphContent, type ParagraphFormatting, type ParagraphMarkChange, type ParagraphMarkChangeKind, type ParagraphPropertyChange, type ParseWarning, type ParseWarningCode, type ParseWarningLocation, type PictureWatermark, type PositionalTab, type PropertyChangeInfo, REVIEW_CARRIERS, type Relationship, type RelationshipMap, type RelationshipType, type ReviewCarrier, type Run, type RunContent, type RunPropertyChange, type SdtProperties, type SdtType, type Section, type SectionProperties, type SectionPropertyChange, type SectionStart, type ShadingProperties, type Shape, type ShapeContent, type ShapeFill, type ShapeGeometryAdjustment, type ShapeOutline, type ShapeTextBody, type ShapeType, type SimpleField, type SoftHyphenContent, type SpacingExplicit, type Style, type StyleDefinitions, type StyleType, type SymbolContent, type TabContent, type TabLeader, type TabStop, type TabStopAlignment, type Table, type TableBorders, type TableCell, type TableCellBorders, type TableCellFormatting, type TableCellPropertyChange, type TableFormatting, type TableLook, type TableMeasurement, type TablePropertyChange, type TableRow, type TableRowFormatting, type TableRowPropertyChange, type TableStructuralChangeInfo, type TableWidthType, type TextBox, type TextContent, type TextEffect, type TextFormatting, type TextWatermark, type Theme, type ThemeColorScheme, type ThemeColorSlot, type ThemeFont, type ThemeFontScheme, type TrackedChangeInfo, type TrackedRunChange, type TrackedRunContent, type UnderlineStyle, type VerticalAlign, type Watermark, isOoxmlSymbolCharacter, normalizeRevisionId };
|
package/dist/model/document.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { DOCX_CONFORMANCE_CLASSES, DRAWING_RAW_XML_MODES, MAX_REVISION_ID, PARAGRAPH_MARK_CHANGE_KINDS, REVIEW_CARRIERS, isOoxmlSymbolCharacter, normalizeRevisionId };
|
|
1
|
+
import { a as PARAGRAPH_MARK_CHANGE_KINDS, c as normalizeRevisionId, i as MAX_REVISION_ID, l as MAX_RETAINED_PARSE_WARNINGS_PER_CODE, n as BIDI_CONTROLS, o as REVIEW_CARRIERS, r as DRAWING_RAW_XML_MODES, s as isOoxmlSymbolCharacter, t as DOCX_CONFORMANCE_CLASSES, u as PARSE_WARNING_CODES } from "../document-CKwRw-01.js";
|
|
2
|
+
export { BIDI_CONTROLS, DOCX_CONFORMANCE_CLASSES, DRAWING_RAW_XML_MODES, MAX_RETAINED_PARSE_WARNINGS_PER_CODE, MAX_REVISION_ID, PARAGRAPH_MARK_CHANGE_KINDS, PARSE_WARNING_CODES, REVIEW_CARRIERS, isOoxmlSymbolCharacter, normalizeRevisionId };
|
package/package.json
CHANGED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
//#region src/model/content.ts
|
|
2
|
-
const OOXML_SYMBOL_CHARACTER_PATTERN = /^[\dA-Fa-f]{4}$/u;
|
|
3
|
-
/** Whether a symbol character is exactly four hexadecimal digits. */
|
|
4
|
-
const isOoxmlSymbolCharacter = (value) => OOXML_SYMBOL_CHARACTER_PATTERN.test(value);
|
|
5
|
-
/** Raw XML handling modes for drawings that Folio cannot model completely. */
|
|
6
|
-
const DRAWING_RAW_XML_MODES = {
|
|
7
|
-
PRESERVE_ONLY: "preserveOnly",
|
|
8
|
-
/** The modeled image is a rendered preview of richer markup, so regeneration cannot reproduce the drawing. */
|
|
9
|
-
PREVIEW_ONLY: "previewOnly"
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Largest value a revision id (`w:id`) may carry: 2^31 - 1.
|
|
13
|
-
*
|
|
14
|
-
* `w:id` on `<w:ins>`/`<w:del>` comes from `CT_Markup`, typed
|
|
15
|
-
* `ST_DecimalNumber` — which ECMA-376 defines as an unbounded integer. The
|
|
16
|
-
* bound below is an implementation limit: conforming consumers read
|
|
17
|
-
* `ST_DecimalNumber` into a signed 32-bit int, and a value past this bound
|
|
18
|
-
* overflows on load and surfaces as an unreadable document. Port of
|
|
19
|
-
* eigenpal/docx-editor#1093.
|
|
20
|
-
*/
|
|
21
|
-
const MAX_REVISION_ID = 2147483647;
|
|
22
|
-
/**
|
|
23
|
-
* Coerce any revision id — including one parsed from an untrusted DOCX — into
|
|
24
|
-
* the range serialized `w:id` attributes may occupy.
|
|
25
|
-
*
|
|
26
|
-
* - Malformed (negative, fractional, `NaN`, `Infinity`): collapse to `0`.
|
|
27
|
-
* - Well-formed but out of range: fold modulo the range (not clamp) so a
|
|
28
|
-
* contiguous run of overflowing ids stays distinguishable.
|
|
29
|
-
*/
|
|
30
|
-
function normalizeRevisionId(id) {
|
|
31
|
-
if (!Number.isInteger(id) || id < 0) return 0;
|
|
32
|
-
if (id > 2147483647) return id % 2147483648;
|
|
33
|
-
return id;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* The kinds a paragraph-mark tracked change can be (ECMA-376 §17.13.5).
|
|
37
|
-
*
|
|
38
|
-
* Written as a child of `<w:pPr><w:rPr>` — `<w:ins/>` when the paragraph
|
|
39
|
-
* break itself was inserted in track-changes mode (the user pressed Enter
|
|
40
|
-
* mid-paragraph), `<w:del/>` when the paragraph break is pending deletion
|
|
41
|
-
* (Backspace at paragraph start or Delete at paragraph end). The mark is
|
|
42
|
-
* independent of the inline runs the paragraph carries.
|
|
43
|
-
*
|
|
44
|
-
* A relocated paragraph's break is `<w:moveFrom/>` at the source and
|
|
45
|
-
* `<w:moveTo/>` at the destination. They resolve exactly as `del` and `ins`
|
|
46
|
-
* do — a move is a deletion and an insertion that a reader is told belong
|
|
47
|
-
* together — but they are not those kinds: writing `w:del` on a moved
|
|
48
|
-
* paragraph's mark reports the relocation as a deletion as well.
|
|
49
|
-
*/
|
|
50
|
-
const PARAGRAPH_MARK_CHANGE_KINDS = Object.freeze([
|
|
51
|
-
"moveFrom",
|
|
52
|
-
"moveTo",
|
|
53
|
-
"ins",
|
|
54
|
-
"del"
|
|
55
|
-
]);
|
|
56
|
-
const REVIEW_CARRIERS = { TERMINAL_TABLE: "terminal-table" };
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region src/model/document.ts
|
|
59
|
-
/** DOCX package conformance classes. */
|
|
60
|
-
const DOCX_CONFORMANCE_CLASSES = Object.freeze({
|
|
61
|
-
STRICT: "strict",
|
|
62
|
-
TRANSITIONAL: "transitional",
|
|
63
|
-
UNKNOWN: "unknown"
|
|
64
|
-
});
|
|
65
|
-
//#endregion
|
|
66
|
-
export { REVIEW_CARRIERS as a, PARAGRAPH_MARK_CHANGE_KINDS as i, DRAWING_RAW_XML_MODES as n, isOoxmlSymbolCharacter as o, MAX_REVISION_ID as r, normalizeRevisionId as s, DOCX_CONFORMANCE_CLASSES as t };
|