@docen/docx 0.3.1 → 0.3.2
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/converters/docx.d.mts +199 -1
- package/dist/converters/docx.mjs +1273 -1
- package/dist/converters/html.d.mts +28 -1
- package/dist/converters/html.mjs +103 -1
- package/dist/converters/markdown.d.mts +12 -1
- package/dist/converters/markdown.mjs +17 -1
- package/dist/converters/patch.d.mts +52 -1
- package/dist/converters/patch.mjs +35 -1
- package/dist/converters/prepare.d.mts +62 -1
- package/dist/converters/prepare.mjs +121 -1
- package/dist/converters/styles.d.mts +84 -1
- package/dist/converters/styles.mjs +284 -1
- package/dist/core-C9VunJ8o.d.mts +174 -0
- package/dist/core-DT9IrTzN.mjs +670 -0
- package/dist/core.d.mts +1 -1
- package/dist/core.mjs +1 -1
- package/dist/editor.d.mts +20 -1
- package/dist/editor.mjs +20 -1
- package/dist/extensions/blockquote.d.mts +1 -1
- package/dist/extensions/blockquote.mjs +30 -2
- package/dist/extensions/code-block.d.mts +1 -1
- package/dist/extensions/code-block.mjs +22 -1
- package/dist/extensions/column-break.d.mts +1 -1
- package/dist/extensions/column-break.mjs +1 -1
- package/dist/extensions/details.d.mts +1 -1
- package/dist/extensions/details.mjs +17 -2
- package/dist/extensions/document.mjs +49 -1
- package/dist/extensions/extensions.d.mts +3 -4
- package/dist/extensions/extensions.mjs +13 -14
- package/dist/extensions/formatting-marks.d.mts +7 -1
- package/dist/extensions/formatting-marks.mjs +1 -1
- package/dist/extensions/heading.mjs +165 -1
- package/dist/extensions/image.d.mts +1 -1
- package/dist/extensions/image.mjs +395 -1
- package/dist/extensions/index.d.mts +3 -2
- package/dist/extensions/index.mjs +4 -3
- package/dist/extensions/mention.d.mts +1 -1
- package/dist/extensions/mention.mjs +43 -2
- package/dist/extensions/ordered-list.d.mts +1 -1
- package/dist/extensions/ordered-list.mjs +40 -2
- package/dist/extensions/page-break.d.mts +1 -33
- package/dist/extensions/page-break.mjs +1 -1
- package/dist/extensions/paragraph.mjs +150 -1
- package/dist/extensions/passthrough.d.mts +1 -1
- package/dist/extensions/passthrough.mjs +1 -1
- package/dist/extensions/section-break.d.mts +19 -2
- package/dist/extensions/section-break.mjs +1 -1
- package/dist/extensions/strike.mjs +49 -1
- package/dist/extensions/table-cell.mjs +111 -1
- package/dist/extensions/table-header.mjs +111 -1
- package/dist/extensions/table-row.mjs +83 -1
- package/dist/extensions/table.mjs +159 -1
- package/dist/extensions/task-item.d.mts +1 -1
- package/dist/extensions/task-item.mjs +36 -2
- package/dist/extensions/text-style.mjs +150 -1
- package/dist/extensions/tiptap.d.mts +2 -2
- package/dist/extensions/tiptap.mjs +31 -2
- package/dist/extensions/utils.d.mts +2 -62
- package/dist/extensions/utils.mjs +499 -2
- package/dist/extensions/wpg-group.d.mts +2 -0
- package/dist/extensions/wpg-group.mjs +2 -0
- package/dist/extensions/wps-shape.d.mts +2 -0
- package/dist/extensions/wps-shape.mjs +2 -0
- package/dist/index.d.mts +86 -27
- package/dist/index.mjs +13 -10
- package/dist/{tiptap-TErPjuNJ.d.mts → tiptap-pZsNPsvV.d.mts} +1 -3
- package/dist/utils-D87vukzp.d.mts +128 -0
- package/package.json +39 -40
- package/dist/blockquote-Ky9xD_Q-.mjs +0 -31
- package/dist/code-block-BgNjhADy.mjs +0 -23
- package/dist/core-DEqBHRzE.mjs +0 -406
- package/dist/core-fBMCCj4D.d.mts +0 -97
- package/dist/details-Dh8luWb2.mjs +0 -18
- package/dist/dist-B6B3HnVZ.mjs +0 -1838
- package/dist/document-CvTym-FM.mjs +0 -50
- package/dist/docx-C5wyjI-0.d.mts +0 -200
- package/dist/docx-CONyAedl.mjs +0 -1231
- package/dist/editor-Bf3CxQnY.mjs +0 -21
- package/dist/editor-DReY3Rb9.d.mts +0 -21
- package/dist/emoji-BZ1dJD7d.d.mts +0 -17
- package/dist/emoji-C2OsTWR7.mjs +0 -27
- package/dist/extensions/emoji.d.mts +0 -2
- package/dist/extensions/emoji.mjs +0 -2
- package/dist/extensions/image-group.d.mts +0 -6
- package/dist/extensions/image-group.mjs +0 -2
- package/dist/heading-DAubgJJN.mjs +0 -166
- package/dist/html-DCC_DSHv.d.mts +0 -18
- package/dist/html-DedDWPoO.mjs +0 -66
- package/dist/image-CuEIXoZl.mjs +0 -334
- package/dist/markdown-BzJmRsBs.mjs +0 -18
- package/dist/markdown-D0k0sRYS.d.mts +0 -13
- package/dist/mention-C-dTR6MK.mjs +0 -44
- package/dist/ordered-list-V-3xFQmV.mjs +0 -41
- package/dist/paragraph-BrWH-BOV.mjs +0 -147
- package/dist/patch-Cdp5WKJz.d.mts +0 -53
- package/dist/patch-IZ13tXTu.mjs +0 -36
- package/dist/prepare-Bdk8Cjkf.mjs +0 -122
- package/dist/prepare-CPAvcv6q.d.mts +0 -63
- package/dist/strike-hWxShOgb.mjs +0 -50
- package/dist/styles-QSX3RhxK.mjs +0 -285
- package/dist/styles-ugspkrxz.d.mts +0 -85
- package/dist/table-DrA12lxX.mjs +0 -159
- package/dist/table-cell-DmkfYwDc.mjs +0 -112
- package/dist/table-header-Bwr5GKWg.mjs +0 -112
- package/dist/table-row-vew1y7WH.mjs +0 -84
- package/dist/task-item-BnlXGrIG.mjs +0 -37
- package/dist/text-style-tMeBq5XQ.mjs +0 -151
- package/dist/tiptap-D7pl4I5U.mjs +0 -33
- package/dist/utils-BPT4tjcn.mjs +0 -333
|
@@ -1,2 +1,200 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as JSONContent } from "../core-C9VunJ8o.mjs";
|
|
2
|
+
import { PrepareStep } from "./prepare.mjs";
|
|
3
|
+
import { DocumentOptions, OutputByType, OutputType, PackerOptions, parseDocument } from "@office-open/docx";
|
|
4
|
+
|
|
5
|
+
//#region src/converters/docx.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Manages DOCX serialization (Tiptap JSON ↔ DocumentOptions).
|
|
8
|
+
*
|
|
9
|
+
* Each extension provides renderDocx/parseDocx for its own attrs mapping.
|
|
10
|
+
* DocxManager handles tree walking, child assembly, and dispatching.
|
|
11
|
+
*/
|
|
12
|
+
declare class DocxManager {
|
|
13
|
+
private numberingConfigs;
|
|
14
|
+
private orderedInstanceCounter;
|
|
15
|
+
private resolveStyles;
|
|
16
|
+
compile(json: JSONContent): DocumentOptions;
|
|
17
|
+
/** Assemble a SectionOptions from compiled children + optional layout/headers/footers. */
|
|
18
|
+
private buildSection;
|
|
19
|
+
/**
|
|
20
|
+
* Compile resolved header/footer slots (JSONContent[] per slot) back into
|
|
21
|
+
* SectionChild[] per slot. Returns undefined when no slot has content.
|
|
22
|
+
*/
|
|
23
|
+
private compileHeaderFooter;
|
|
24
|
+
/**
|
|
25
|
+
* Resolve a section's header/footer group (SectionChild[] per slot) into
|
|
26
|
+
* Tiptap JSON slots. Returns null when no slot has content.
|
|
27
|
+
*/
|
|
28
|
+
private resolveHeaderFooter;
|
|
29
|
+
resolve(docOpts: DocumentOptions): JSONContent;
|
|
30
|
+
private compileSectionChild;
|
|
31
|
+
private compileParagraphNode;
|
|
32
|
+
private compileHeadingNode;
|
|
33
|
+
/** Simple text optimization: merge plain runs into text field */
|
|
34
|
+
private simplifyParagraph;
|
|
35
|
+
private compileTableNode;
|
|
36
|
+
/** Count grid columns from the first table row (summing colspan). */
|
|
37
|
+
private getTableColumnCount;
|
|
38
|
+
/**
|
|
39
|
+
* Compute tblGrid column widths (twips) from first-row cell colwidth attrs.
|
|
40
|
+
* Returns columnWidths array and the appropriate tableWidth.
|
|
41
|
+
*/
|
|
42
|
+
private computeColumnWidths;
|
|
43
|
+
private compileTableCellNode;
|
|
44
|
+
private compileListFromNode;
|
|
45
|
+
/**
|
|
46
|
+
* Register (or reuse) an abstractNum for an ordered list's `start`, and
|
|
47
|
+
* return a fresh instance so this list counts independently of other lists
|
|
48
|
+
* that share the same definition.
|
|
49
|
+
*/
|
|
50
|
+
private registerOrderedNumbering;
|
|
51
|
+
/**
|
|
52
|
+
* Prepend an inline checkbox SDT to a task paragraph. The SDT is tagged
|
|
53
|
+
* "docen-task" so resolve can tell task items apart from ordinary paragraphs
|
|
54
|
+
* that happen to contain an SDT.
|
|
55
|
+
*/
|
|
56
|
+
private injectTaskCheckbox;
|
|
57
|
+
/**
|
|
58
|
+
* details → block-level group-SDT. The summary paragraph is tagged with a
|
|
59
|
+
* fixed style so resolve can split it back out; content blocks flatten in
|
|
60
|
+
* after it. (No native collapse in DOCX — structure round-trips, the view
|
|
61
|
+
* stays expanded.)
|
|
62
|
+
*/
|
|
63
|
+
private compileDetailsNode;
|
|
64
|
+
private compileInlineContent;
|
|
65
|
+
private compileTextNode;
|
|
66
|
+
/** Emit a single run for `text` with all inline marks applied. */
|
|
67
|
+
private compileTextRun;
|
|
68
|
+
private resolveSectionChild;
|
|
69
|
+
/** Wrap an opaque SectionChild in a passthrough atom (attrs.data = JSON). */
|
|
70
|
+
private resolvePassthrough;
|
|
71
|
+
/**
|
|
72
|
+
* Resolve a details group-SDT: the summary-style paragraph becomes
|
|
73
|
+
* detailsSummary, the remaining blocks fold into detailsContent.
|
|
74
|
+
*/
|
|
75
|
+
private resolveDetailsSdt;
|
|
76
|
+
private resolveParagraph;
|
|
77
|
+
/** Look up a paragraph style's NAME from its styleId, via the styles table
|
|
78
|
+
* carried on the current resolve(). Returns undefined outside resolve. */
|
|
79
|
+
private styleNameOf;
|
|
80
|
+
/** reference → level-0 format/start, for classifying numbering paragraphs. */
|
|
81
|
+
private buildNumberingLookup;
|
|
82
|
+
/**
|
|
83
|
+
* Walk section children, grouping consecutive list paragraphs into nested
|
|
84
|
+
* Tiptap lists. Non-list children resolve individually. DOCX flattens lists
|
|
85
|
+
* to a paragraph sequence (depth carried by `level`); this rebuilds the tree.
|
|
86
|
+
*/
|
|
87
|
+
private resolveSectionChildren;
|
|
88
|
+
/** Classify a paragraph as a list item, or null if it isn't one. */
|
|
89
|
+
private detectList;
|
|
90
|
+
/**
|
|
91
|
+
* Rebuild nested Tiptap lists from a flat run of list paragraphs. Stack-based:
|
|
92
|
+
* each frame is an active list at a given depth; the `key` (level:type:
|
|
93
|
+
* reference) decides whether a paragraph continues the top list, starts a
|
|
94
|
+
* nested list, or splits off a new sibling list.
|
|
95
|
+
*/
|
|
96
|
+
private buildListTree;
|
|
97
|
+
/** Classify a paragraph as a blockquote member by its signature. */
|
|
98
|
+
private detectBlockquote;
|
|
99
|
+
/**
|
|
100
|
+
* Rebuild a blockquote node from a run of signature-carrying paragraphs,
|
|
101
|
+
* stripping the indent/border signature so child paragraphs render clean.
|
|
102
|
+
*/
|
|
103
|
+
private buildBlockquote;
|
|
104
|
+
/**
|
|
105
|
+
* Resolve a list-item paragraph to a Tiptap paragraph/heading node, stripping
|
|
106
|
+
* the list marker (bullet/numbering) and the leading task checkbox — those
|
|
107
|
+
* are expressed at the list/item level, not inside the paragraph.
|
|
108
|
+
*/
|
|
109
|
+
private resolveListItemParagraph;
|
|
110
|
+
/** Return a copy of `para` with its leading docen-task checkbox SDT removed. */
|
|
111
|
+
private stripTaskCheckbox;
|
|
112
|
+
private resolveCodeBlock;
|
|
113
|
+
private resolveTable;
|
|
114
|
+
/**
|
|
115
|
+
* Resolve a paragraph's inline content. @office-open collapses a plain-text
|
|
116
|
+
* paragraph (a single run with no properties) to a bare string or a `{ text }`
|
|
117
|
+
* object with no `children` — recover that text here so it round-trips back to
|
|
118
|
+
* a text node instead of being dropped.
|
|
119
|
+
*/
|
|
120
|
+
private resolveInlineContent;
|
|
121
|
+
private resolveParagraphChildren;
|
|
122
|
+
private resolveParagraphChild;
|
|
123
|
+
/** Resolve an inline SDT (mention carrier; other inline SDTs unsupported). */
|
|
124
|
+
private resolveInlineSdt;
|
|
125
|
+
private resolveRun;
|
|
126
|
+
private resolveMarks;
|
|
127
|
+
private resolveImage;
|
|
128
|
+
private resolveHyperlink;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Parse a DOCX file into Tiptap JSON (runtime model).
|
|
132
|
+
*
|
|
133
|
+
* Combines @office-open/docx's `parseDocument` (DOCX binary → DocumentOptions)
|
|
134
|
+
* with `DocxManager.resolve` (DocumentOptions → Tiptap JSON).
|
|
135
|
+
*/
|
|
136
|
+
declare function parseDOCX(data: Parameters<typeof parseDocument>[0]): JSONContent;
|
|
137
|
+
/**
|
|
138
|
+
* Options for {@link generateDOCX} / {@link generateDOCXStream}.
|
|
139
|
+
*/
|
|
140
|
+
interface DocxGenerateOptions<T extends OutputType = "nodebuffer"> {
|
|
141
|
+
/**
|
|
142
|
+
* Pre-compilation steps run on the JSON in place (default: `prepareImages()`).
|
|
143
|
+
* - `true` / `undefined`: default image pre-fetch (http(s) → embedded data URL)
|
|
144
|
+
* - `false`: skip preparation
|
|
145
|
+
* - `PrepareStep[]`: custom steps
|
|
146
|
+
*
|
|
147
|
+
* Required for http image URLs — image `renderDocx` drops images without
|
|
148
|
+
* embedded data (see extensions/image.ts). Mutates the JSON, like `prepareDocument`.
|
|
149
|
+
*/
|
|
150
|
+
prepare?: boolean | PrepareStep[];
|
|
151
|
+
/** Packer options; `type` controls the output format (default `"nodebuffer"` → Buffer). */
|
|
152
|
+
packer?: PackerOptions<T>;
|
|
153
|
+
/**
|
|
154
|
+
* Document-level options injected into the compiled `DocumentOptions` — core
|
|
155
|
+
* properties (`title`/`creator`/`description`/…), `styles`/`externalStyles`,
|
|
156
|
+
* `background`, `features`, `fonts`, etc. Excludes `sections` (always compiled
|
|
157
|
+
* from the JSON) and `numbering` (collected from ordered-list nodes).
|
|
158
|
+
*
|
|
159
|
+
* `styles`/`externalStyles` here take precedence over any `styles` carried on
|
|
160
|
+
* `json.attrs.styles` (e.g. from a prior `parseDOCX`); the two are mutually
|
|
161
|
+
* exclusive, so specifying `externalStyles` drops the compiled `styles`.
|
|
162
|
+
*/
|
|
163
|
+
document?: Omit<Partial<DocumentOptions>, "sections" | "numbering">;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Generate a DOCX file from Tiptap JSON (runtime model), asynchronously.
|
|
167
|
+
*
|
|
168
|
+
* Pipeline: `prepareDocument` (default: fetch http images, in place) →
|
|
169
|
+
* `DocxManager.compile` → @office-open/docx's `generateDocument`. `packer.type`
|
|
170
|
+
* controls the output format (default: `"nodebuffer"` → Buffer). Non-blocking
|
|
171
|
+
* (fflate Web Workers). With the default `prepare`, the input `json` is mutated
|
|
172
|
+
* in place (http image URLs become embedded data URLs).
|
|
173
|
+
*/
|
|
174
|
+
declare function generateDOCX<T extends OutputType = "nodebuffer">(json: JSONContent, options?: DocxGenerateOptions<T>): Promise<OutputByType[T]>;
|
|
175
|
+
/**
|
|
176
|
+
* Generate a DOCX file synchronously — fastest throughput, blocks the event loop.
|
|
177
|
+
*
|
|
178
|
+
* Pipeline: `DocxManager.compile` → `generateDocumentSync`. Does **not** run
|
|
179
|
+
* `prepareDocument` (it is async); call `await prepareDocument(json)` first
|
|
180
|
+
* when http images need embedding. `options.document` is still applied.
|
|
181
|
+
*/
|
|
182
|
+
declare function generateDOCXSync<T extends OutputType = "nodebuffer">(json: JSONContent, options?: DocxGenerateOptions<T>): OutputByType[T];
|
|
183
|
+
/**
|
|
184
|
+
* Generate a DOCX file as a `ReadableStream<Uint8Array>` — for large documents
|
|
185
|
+
* or streaming HTTP responses.
|
|
186
|
+
*
|
|
187
|
+
* Pipeline: `prepareDocument` (default: fetch http images, in place) →
|
|
188
|
+
* `DocxManager.compile` → `generateDocumentStream`. Async due to preparation.
|
|
189
|
+
*/
|
|
190
|
+
declare function generateDOCXStream(json: JSONContent, options?: DocxGenerateOptions): Promise<ReadableStream<Uint8Array>>;
|
|
191
|
+
/**
|
|
192
|
+
* Convert DocumentOptions (persistence model) to Tiptap JSON (runtime model).
|
|
193
|
+
*/
|
|
194
|
+
declare function resolveDocument(docOpts: DocumentOptions): JSONContent;
|
|
195
|
+
/**
|
|
196
|
+
* Convert Tiptap JSON (runtime model) to DocumentOptions (persistence model).
|
|
197
|
+
*/
|
|
198
|
+
declare function compileDocument(json: JSONContent): DocumentOptions;
|
|
199
|
+
//#endregion
|
|
2
200
|
export { type DocumentOptions, DocxGenerateOptions, DocxManager, compileDocument, generateDOCX, generateDOCXStream, generateDOCXSync, parseDOCX, resolveDocument };
|