@stll/docx-core 0.17.3 → 0.19.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/README.md +5 -3
- package/dist/{document-C4ms2O35.d.ts → document-CR8P25Qh.d.ts} +26 -16
- package/dist/{document-BPDUWV3O.js → document-Cj4uqQEw.js} +22 -1
- package/dist/docx_kernel_bg.wasm +0 -0
- package/dist/index.d.ts +31 -2
- package/dist/index.js +766 -312
- package/dist/model/document.d.ts +2 -2
- package/dist/model/document.js +2 -2
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -4,8 +4,9 @@ A typed OOXML/DOCX document model with parsing, validation, and serialization.
|
|
|
4
4
|
|
|
5
5
|
The package exposes a structured document model (paragraphs, runs, tables,
|
|
6
6
|
styles, section properties) together with the tools to produce and check DOCX
|
|
7
|
-
packages, plus a legal-source compiler that turns a
|
|
8
|
-
model or a finished DOCX file
|
|
7
|
+
packages, plus a legal-source compiler that turns a legal draft (GFM markdown
|
|
8
|
+
plus `@` directives) into that model or a finished DOCX file, and a plain
|
|
9
|
+
markdown reader (`compileMarkdownToContent`) that shares its parser.
|
|
9
10
|
|
|
10
11
|
```ts
|
|
11
12
|
import { compileLegalSourceToDocx, validateDocxPackage } from "@stll/docx-core";
|
|
@@ -30,7 +31,8 @@ bun add @stll/docx-core
|
|
|
30
31
|
|
|
31
32
|
- `.` — the document model types, the legal-source compiler
|
|
32
33
|
(`parseLegalSource`, `compileLegalSourceToDocument`,
|
|
33
|
-
`compileLegalSourceToDocx`, `validateLegalDraft`),
|
|
34
|
+
`compileLegalSourceToDocx`, `validateLegalDraft`), the markdown reader
|
|
35
|
+
(`compileMarkdownToContent`, `sanitizeExternalUrl`), DOCX serialization
|
|
34
36
|
(`serializeDocumentToDocx`), and validation (`validateDocxPackage`,
|
|
35
37
|
`validateDocumentModel`, `assertValidDocumentModel`).
|
|
36
38
|
- `./model` — the document model types only.
|
|
@@ -1303,6 +1303,8 @@ type PropertyChangeInfo = {
|
|
|
1303
1303
|
/** Optional revision session ID */
|
|
1304
1304
|
rsid?: string;
|
|
1305
1305
|
} & TrackedChangeInfo;
|
|
1306
|
+
/** Inline content that may sit inside a run-level tracked-change wrapper. */
|
|
1307
|
+
type TrackedRunContent = Run | Hyperlink | BookmarkStart | BookmarkEnd | SimpleField | ComplexField | TrackedRunChange;
|
|
1306
1308
|
/**
|
|
1307
1309
|
* Insertion wrapper (w:ins) — runs inserted by tracked changes
|
|
1308
1310
|
*/
|
|
@@ -1311,7 +1313,7 @@ type Insertion = {
|
|
|
1311
1313
|
/** Tracked change metadata */
|
|
1312
1314
|
info: TrackedChangeInfo;
|
|
1313
1315
|
/** Inserted content */
|
|
1314
|
-
content:
|
|
1316
|
+
content: TrackedRunContent[];
|
|
1315
1317
|
};
|
|
1316
1318
|
/**
|
|
1317
1319
|
* Deletion wrapper (w:del) — runs deleted by tracked changes
|
|
@@ -1321,7 +1323,7 @@ type Deletion = {
|
|
|
1321
1323
|
/** Tracked change metadata */
|
|
1322
1324
|
info: TrackedChangeInfo;
|
|
1323
1325
|
/** Deleted content */
|
|
1324
|
-
content:
|
|
1326
|
+
content: TrackedRunContent[];
|
|
1325
1327
|
};
|
|
1326
1328
|
/**
|
|
1327
1329
|
* Move-from wrapper (w:moveFrom) — content moved away from this position
|
|
@@ -1331,7 +1333,7 @@ type MoveFrom = {
|
|
|
1331
1333
|
/** Tracked change metadata */
|
|
1332
1334
|
info: TrackedChangeInfo;
|
|
1333
1335
|
/** Moved content */
|
|
1334
|
-
content:
|
|
1336
|
+
content: TrackedRunContent[];
|
|
1335
1337
|
};
|
|
1336
1338
|
/**
|
|
1337
1339
|
* Move-to wrapper (w:moveTo) — content moved into this position
|
|
@@ -1341,7 +1343,7 @@ type MoveTo = {
|
|
|
1341
1343
|
/** Tracked change metadata */
|
|
1342
1344
|
info: TrackedChangeInfo;
|
|
1343
1345
|
/** Moved content */
|
|
1344
|
-
content:
|
|
1346
|
+
content: TrackedRunContent[];
|
|
1345
1347
|
};
|
|
1346
1348
|
/**
|
|
1347
1349
|
* Move-from range start marker (w:moveFromRangeStart) — ECMA-376 §17.13.5.22
|
|
@@ -1579,21 +1581,29 @@ type BlockSdt = {
|
|
|
1579
1581
|
*/
|
|
1580
1582
|
type ParagraphContent = Run | Hyperlink | BookmarkStart | BookmarkEnd | SimpleField | ComplexField | InlineSdt | CommentRangeStart | CommentRangeEnd | CommentReference | Insertion | Deletion | MoveFrom | MoveTo | MoveFromRangeStart | MoveFromRangeEnd | MoveToRangeStart | MoveToRangeEnd | MathEquation;
|
|
1581
1583
|
/**
|
|
1582
|
-
*
|
|
1583
|
-
*/
|
|
1584
|
-
/**
|
|
1585
|
-
* Paragraph-mark tracked-change marker (ECMA-376 §17.13.5).
|
|
1584
|
+
* The kinds a paragraph-mark tracked change can be (ECMA-376 §17.13.5).
|
|
1586
1585
|
*
|
|
1587
|
-
*
|
|
1588
|
-
*
|
|
1589
|
-
*
|
|
1590
|
-
*
|
|
1591
|
-
*
|
|
1592
|
-
|
|
1586
|
+
* Written as a child of `<w:pPr><w:rPr>` — `<w:ins/>` when the paragraph
|
|
1587
|
+
* break itself was inserted in track-changes mode (the user pressed Enter
|
|
1588
|
+
* mid-paragraph), `<w:del/>` when the paragraph break is pending deletion
|
|
1589
|
+
* (Backspace at paragraph start or Delete at paragraph end). The mark is
|
|
1590
|
+
* independent of the inline runs the paragraph carries.
|
|
1591
|
+
*
|
|
1592
|
+
* A relocated paragraph's break is `<w:moveFrom/>` at the source and
|
|
1593
|
+
* `<w:moveTo/>` at the destination. They resolve exactly as `del` and `ins`
|
|
1594
|
+
* do — a move is a deletion and an insertion that a reader is told belong
|
|
1595
|
+
* together — but they are not those kinds: writing `w:del` on a moved
|
|
1596
|
+
* paragraph's mark reports the relocation as a deletion as well.
|
|
1597
|
+
*/
|
|
1598
|
+
declare const PARAGRAPH_MARK_CHANGE_KINDS: readonly ["moveFrom", "moveTo", "ins", "del"];
|
|
1599
|
+
/** One of {@link PARAGRAPH_MARK_CHANGE_KINDS}. */
|
|
1600
|
+
type ParagraphMarkChangeKind = (typeof PARAGRAPH_MARK_CHANGE_KINDS)[number];
|
|
1601
|
+
/** A paragraph-mark tracked change, written under `<w:pPr><w:rPr>`. */
|
|
1593
1602
|
type ParagraphMarkChange = {
|
|
1594
|
-
kind:
|
|
1603
|
+
kind: ParagraphMarkChangeKind;
|
|
1595
1604
|
info: TrackedChangeInfo;
|
|
1596
1605
|
};
|
|
1606
|
+
/** Paragraph (w:p) */
|
|
1597
1607
|
type Paragraph = {
|
|
1598
1608
|
type: "paragraph";
|
|
1599
1609
|
/** Unique paragraph ID */
|
|
@@ -2308,4 +2318,4 @@ type Document = {
|
|
|
2308
2318
|
warnings?: string[];
|
|
2309
2319
|
};
|
|
2310
2320
|
//#endregion
|
|
2311
|
-
export { ImagePosition as $,
|
|
2321
|
+
export { ImagePosition as $, TableRowPropertyChange as $t, ComplexField as A, TableBorders as An, RunPropertyChange as At, FieldCharContent as B, UnderlineStyle as Bn, ShapeGeometryAdjustment as Bt, BookmarkStart as C, LineSpacingRule as Cn, ParagraphMarkChangeKind as Ct, CommentRangeEnd as D, TabLeader as Dn, PropertyChangeInfo as Dt, Comment as E, SpacingExplicit as En, PositionalTab as Et, DrawingRawXmlMode as F, TableMeasurement as Fn, SectionPropertyChange as Ft, FootnoteProperties as G, ThemeColorSlot as Gn, SoftHyphenContent as Gt, FooterReference as H, ColorValue as Hn, ShapeTextBody as Ht, Endnote as I, TableRowFormatting as In, SectionStart as It, HeaderReference as J, Table as Jt, HeaderFooter as K, SymbolContent as Kt, EndnotePosition as L, TableWidthType as Ln, Shape as Lt, Deletion as M, TableCellFormatting as Mn, SdtType as Mt, DocumentBody as N, TableFormatting as Nn, Section as Nt, CommentRangeStart as O, TabStop as On, Run as Ot, DrawingContent as P, TableLook as Pn, SectionProperties as Pt, ImagePadding as Q, TableRow as Qt, EndnoteProperties as R, TextEffect as Rn, ShapeContent as Rt, BookmarkEnd as S, FloatingTableProperties as Sn, ParagraphMarkChange as St, Column as T, ParagraphFormatting as Tn, PictureWatermark as Tt, Footnote as U, KnownBorderStyle as Un, ShapeType as Ut, FieldType as V, BorderSpec as Vn, ShapeOutline as Vt, FootnotePosition as W, ShadingProperties as Wn, SimpleField as Wt, Image as X, TableCellPropertyChange as Xt, Hyperlink as Y, TableCell as Yt, ImageCrop as Z, TablePropertyChange as Zt, ThemeColorScheme as _, NumberingDefinitions as _n, NoteReferenceContent as _t, DocxPackage as a, TrackedRunChange as an, InstrTextContent as at, BlockContent as b, ConditionalFormatStyle as bn, Paragraph as bt, FontTable as c, Watermark as cn, MathEquation as ct, RelationshipMap as d, AbstractNumbering as dn, MoveFromRangeStart as dt, TableStructuralChangeInfo as en, ImageSize as et, RelationshipType as f, LevelSuffix as fn, MoveTo as ft, Theme as g, NumberFormat as gn, NoteNumberRestart as gt, StyleType as h, ListRendering as hn, NoBreakHyphenContent as ht, DocxConformanceClass as i, TrackedChangeInfo as in, Insertion as it, DRAWING_RAW_XML_MODES as j, TableCellBorders as jn, SdtProperties as jt, CommentReference as k, TabStopAlignment as kn, RunContent as kt, MediaFile as l, isOoxmlSymbolCharacter as ln, MoveFrom as lt, StyleDefinitions as m, ListMarkerFormatting as mn, MoveToRangeStart as mt, Document as n, TextContent as nn, ImageWrap as nt, DocDefaults as o, TrackedRunContent as on, LineNumberRestart as ot, Style as p, ListLevel as pn, MoveToRangeEnd as pt, HeaderFooterType as q, TabContent as qt, DocumentSettings as r, TextWatermark as rn, InlineSdt as rt, FontInfo as s, VerticalAlign as sn, MAX_REVISION_ID as st, DOCX_CONFORMANCE_CLASSES as t, TextBox as tn, ImageTransform as tt, Relationship as u, normalizeRevisionId as un, MoveFromRangeEnd as ut, ThemeFont as v, NumberingInstance as vn, PARAGRAPH_MARK_CHANGE_KINDS as vt, BreakContent as w, ParagraphAlignment as wn, ParagraphPropertyChange as wt, BlockSdt as x, EmphasisMark as xn, ParagraphContent as xt, ThemeFontScheme as y, CellMargins as yn, PageOrientation as yt, Field as z, TextFormatting as zn, ShapeFill as zt };
|
|
@@ -28,6 +28,27 @@ function normalizeRevisionId(id) {
|
|
|
28
28
|
if (id > 2147483647) return id % 2147483648;
|
|
29
29
|
return id;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* The kinds a paragraph-mark tracked change can be (ECMA-376 §17.13.5).
|
|
33
|
+
*
|
|
34
|
+
* Written as a child of `<w:pPr><w:rPr>` — `<w:ins/>` when the paragraph
|
|
35
|
+
* break itself was inserted in track-changes mode (the user pressed Enter
|
|
36
|
+
* mid-paragraph), `<w:del/>` when the paragraph break is pending deletion
|
|
37
|
+
* (Backspace at paragraph start or Delete at paragraph end). The mark is
|
|
38
|
+
* independent of the inline runs the paragraph carries.
|
|
39
|
+
*
|
|
40
|
+
* A relocated paragraph's break is `<w:moveFrom/>` at the source and
|
|
41
|
+
* `<w:moveTo/>` at the destination. They resolve exactly as `del` and `ins`
|
|
42
|
+
* do — a move is a deletion and an insertion that a reader is told belong
|
|
43
|
+
* together — but they are not those kinds: writing `w:del` on a moved
|
|
44
|
+
* paragraph's mark reports the relocation as a deletion as well.
|
|
45
|
+
*/
|
|
46
|
+
const PARAGRAPH_MARK_CHANGE_KINDS = Object.freeze([
|
|
47
|
+
"moveFrom",
|
|
48
|
+
"moveTo",
|
|
49
|
+
"ins",
|
|
50
|
+
"del"
|
|
51
|
+
]);
|
|
31
52
|
//#endregion
|
|
32
53
|
//#region src/model/document.ts
|
|
33
54
|
/** DOCX package conformance classes. */
|
|
@@ -37,4 +58,4 @@ const DOCX_CONFORMANCE_CLASSES = Object.freeze({
|
|
|
37
58
|
UNKNOWN: "unknown"
|
|
38
59
|
});
|
|
39
60
|
//#endregion
|
|
40
|
-
export {
|
|
61
|
+
export { isOoxmlSymbolCharacter as a, PARAGRAPH_MARK_CHANGE_KINDS as i, DRAWING_RAW_XML_MODES as n, normalizeRevisionId as o, MAX_REVISION_ID as r, DOCX_CONFORMANCE_CLASSES as t };
|
package/dist/docx_kernel_bg.wasm
CHANGED
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Et as PositionalTab, Jt as Table, N as DocumentBody, Ot as Run, Pt as SectionProperties, Qt as TableRow, Yt as TableCell, _n as NumberingDefinitions, a as DocxPackage, b as BlockContent, bt as Paragraph, i as DocxConformanceClass, kt as RunContent, n as Document, nn as TextContent, p as Style, t as DOCX_CONFORMANCE_CLASSES, w as BreakContent, xt as ParagraphContent } from "./document-CR8P25Qh.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";
|
|
@@ -24,6 +24,12 @@ type LegalSignatureParty = {
|
|
|
24
24
|
signatory?: string;
|
|
25
25
|
title?: string;
|
|
26
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* A parsed draft block. Every `text`, `heading`, paragraph, list item, and
|
|
29
|
+
* table cell string keeps its inline GFM markdown (`**bold**`, `*italic*`,
|
|
30
|
+
* `[link](https://…)`, `` `code` ``) and `[[placeholder]]` markers; the
|
|
31
|
+
* compiler renders them into runs.
|
|
32
|
+
*/
|
|
27
33
|
type LegalDraftBlock = {
|
|
28
34
|
type: "title";
|
|
29
35
|
text: string;
|
|
@@ -114,6 +120,29 @@ declare const validateLegalDraft: (draft: LegalDraft) => LegalDraftDiagnostic[];
|
|
|
114
120
|
//#region src/legal-source/index.d.ts
|
|
115
121
|
declare const compileLegalSourceToDocx: (source: string, options?: LegalSourceCompileOptions) => Promise<LegalSourceDocxCompileResult>;
|
|
116
122
|
//#endregion
|
|
123
|
+
//#region src/markdown/content.d.ts
|
|
124
|
+
/** Block content and the numbering definitions its list paragraphs reference. */
|
|
125
|
+
type MarkdownContent = {
|
|
126
|
+
content: BlockContent[];
|
|
127
|
+
/** Present only when the markdown contained at least one list. */
|
|
128
|
+
numbering?: NumberingDefinitions;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Parse GFM markdown into document blocks plus the numbering its lists need.
|
|
132
|
+
* Synchronous. The caller places the blocks into a `Document` of its own
|
|
133
|
+
* (page geometry, styles, and presets are the host's decision).
|
|
134
|
+
*/
|
|
135
|
+
declare const compileMarkdownToContent: (markdown: string) => MarkdownContent;
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/markdown/href.d.ts
|
|
138
|
+
/**
|
|
139
|
+
* Keep only http(s), mailto, and tel URLs, normalised through the URL parser.
|
|
140
|
+
* Anything else (javascript:, data:, relative paths, malformed input) drops to
|
|
141
|
+
* `undefined` so a markdown link degrades to its text instead of carrying an
|
|
142
|
+
* executable target into the document.
|
|
143
|
+
*/
|
|
144
|
+
declare const sanitizeExternalUrl: (rawUrl: string | undefined) => string | undefined;
|
|
145
|
+
//#endregion
|
|
117
146
|
//#region src/serialize/docx.d.ts
|
|
118
147
|
type SerializeDocumentOptions = {
|
|
119
148
|
/** BCP-47 language tag (e.g. "en", "cs", "cs-CZ"); used for footer labels. */
|
|
@@ -150,4 +179,4 @@ declare const validateDocxPackage: (buffer: ArrayBuffer | Uint8Array) => Promise
|
|
|
150
179
|
declare const validateDocumentModel: (document: Document) => ValidateDocumentModelResult;
|
|
151
180
|
declare const assertValidDocumentModel: (document: Document) => void;
|
|
152
181
|
//#endregion
|
|
153
|
-
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 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, parseLegalSource, serializeDocumentToDocx, validateDocumentModel, validateDocxPackage, validateLegalDraft };
|
|
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 };
|