@docen/docx 0.3.5 → 0.4.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 +1 -1
- package/dist/{blockquote-DY80QC06.d.mts → blockquote-D-1aSxEn.d.mts} +5 -1
- package/dist/converters/docx.d.mts +40 -66
- package/dist/converters/docx.mjs +248 -665
- package/dist/converters/html.d.mts +1 -1
- package/dist/converters/html.mjs +3 -4
- package/dist/converters/markdown.d.mts +1 -1
- package/dist/converters/markdown.mjs +1 -1
- package/dist/converters/patch.d.mts +1 -1
- package/dist/converters/prepare.d.mts +1 -1
- package/dist/converters/styles.d.mts +58 -14
- package/dist/converters/styles.mjs +124 -16
- package/dist/{core-DC0_-WcE.d.mts → core-BqyLL84S.d.mts} +34 -13
- package/dist/{core-BnF8XhVE.mjs → core-wNNPJiKr.mjs} +357 -25
- package/dist/core.d.mts +1 -1
- package/dist/core.mjs +1 -1
- package/dist/details-DsJhDP5K.d.mts +31 -0
- package/dist/editor.d.mts +1 -1
- package/dist/editor.mjs +1 -1
- package/dist/extensions/blockquote.d.mts +2 -3
- package/dist/extensions/blockquote.mjs +50 -2
- package/dist/extensions/bullet-list.mjs +1 -1
- package/dist/extensions/code-block.d.mts +2 -2
- package/dist/extensions/code-block.mjs +51 -5
- package/dist/extensions/column-break.d.mts +2 -2
- package/dist/extensions/column-break.mjs +2 -2
- package/dist/extensions/details.d.mts +2 -3
- package/dist/extensions/details.mjs +48 -2
- package/dist/extensions/document.mjs +1 -1
- package/dist/extensions/extensions.d.mts +13 -9
- package/dist/extensions/extensions.mjs +7 -3
- package/dist/extensions/formatting-marks.d.mts +1 -1
- package/dist/extensions/formatting-marks.mjs +1 -1
- package/dist/extensions/heading.d.mts +2 -2
- package/dist/extensions/heading.mjs +61 -5
- package/dist/extensions/image.d.mts +2 -2
- package/dist/extensions/image.mjs +23 -4
- package/dist/extensions/index.d.mts +14 -10
- package/dist/extensions/index.mjs +8 -4
- package/dist/extensions/link.d.mts +2 -2
- package/dist/extensions/link.mjs +30 -2
- package/dist/extensions/list-aggregator.d.mts +8 -0
- package/dist/extensions/list-aggregator.mjs +2 -0
- package/dist/extensions/marks.d.mts +2 -0
- package/dist/extensions/marks.mjs +41 -0
- package/dist/extensions/mention.d.mts +2 -3
- package/dist/extensions/mention.mjs +16 -2
- package/dist/extensions/ordered-list.mjs +1 -1
- package/dist/extensions/page-break.d.mts +2 -2
- package/dist/extensions/page-break.mjs +2 -2
- package/dist/extensions/paragraph.mjs +3 -3
- package/dist/extensions/passthrough.d.mts +1 -1
- package/dist/extensions/passthrough.mjs +1 -1
- package/dist/extensions/scroll.d.mts +1 -1
- package/dist/extensions/scroll.mjs +30 -5
- package/dist/extensions/section-break.d.mts +1 -1
- package/dist/extensions/section-break.mjs +1 -1
- package/dist/extensions/strike.d.mts +2 -2
- package/dist/extensions/strike.mjs +5 -24
- package/dist/extensions/tab.d.mts +2 -2
- package/dist/extensions/tab.mjs +2 -2
- package/dist/extensions/table-cell.mjs +2 -2
- package/dist/extensions/table-header.mjs +2 -2
- package/dist/extensions/table-row.mjs +2 -2
- package/dist/extensions/table.d.mts +2 -2
- package/dist/extensions/table.mjs +122 -11
- package/dist/extensions/task-item.d.mts +2 -3
- package/dist/extensions/task-item.mjs +2 -2
- package/dist/extensions/text-style.d.mts +2 -2
- package/dist/extensions/text-style.mjs +27 -28
- package/dist/extensions/toc-field.d.mts +2 -2
- package/dist/extensions/toc-field.mjs +2 -2
- package/dist/extensions/track-change.d.mts +2 -0
- package/dist/extensions/track-change.mjs +2 -0
- package/dist/extensions/types.d.mts +127 -8
- package/dist/extensions/utils.d.mts +2 -2
- package/dist/extensions/utils.mjs +74 -1
- package/dist/extensions/wpg-group.d.mts +2 -2
- package/dist/extensions/wpg-group.mjs +2 -2
- package/dist/extensions/wps-shape.d.mts +2 -2
- package/dist/extensions/wps-shape.mjs +2 -2
- package/dist/heading-Bwpa8iZY.d.mts +24 -0
- package/dist/index.d.mts +29 -11
- package/dist/index.mjs +9 -5
- package/dist/{link-BawPjQZR.d.mts → link-gUqW45mE.d.mts} +3 -1
- package/dist/marks-Dz9Vb22Q.d.mts +10 -0
- package/dist/{mention-BGLzLVYw.d.mts → mention-CkONDrw9.d.mts} +5 -1
- package/dist/{scroll-ZNeThJsJ.d.mts → scroll-BARiZ5Gm.d.mts} +9 -3
- package/dist/strike-Brn9sWFy.d.mts +16 -0
- package/dist/table-CdcjR6HD.d.mts +18 -0
- package/dist/{task-item-B0ntvQ1Y.d.mts → task-item-CCAC4QLi.d.mts} +3 -1
- package/dist/text-style-BzfcbufI.d.mts +4 -0
- package/dist/{utils-BJwDQts7.d.mts → utils-CfwwOowz.d.mts} +25 -1
- package/package.json +1 -1
- package/dist/details-Dd5MqqmR.d.mts +0 -17
- package/dist/extensions/tiptap.d.mts +0 -2
- package/dist/extensions/tiptap.mjs +0 -31
- package/dist/heading-BvqBD2zX.d.mts +0 -8
- package/dist/strike-BgWGvjKr.d.mts +0 -33
- package/dist/table-BFkfeRp9.d.mts +0 -9
- package/dist/text-style-BHdtXkMb.d.mts +0 -8
- package/dist/tiptap-BKqn41uT.d.mts +0 -31
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
> DOCX editor and converter powered by @office-open/docx with Tiptap editing layer, supporting bidirectional conversion between DOCX, HTML, and Markdown.
|
|
8
8
|
|
|
9
|
-
> Need a ready-made visual editor? [`@docen/editor`](../editor/README.md) wraps this engine in a Fluent UI
|
|
9
|
+
> Need a ready-made visual editor? [`@docen/editor`](../editor/README.md) wraps this engine in a Fluent UI host with the turnkey `<docen-document>` web component.
|
|
10
10
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ParseAggregatorRule } from "./extensions/types.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/extensions/blockquote.d.ts
|
|
2
4
|
/**
|
|
3
5
|
* Blockquote extension — owns the DOCX expression of a blockquote.
|
|
@@ -17,5 +19,7 @@ declare const BLOCKQUOTE_BORDER: {
|
|
|
17
19
|
};
|
|
18
20
|
/** Apply the blockquote signature (left indent + left border) to paragraph opts. */
|
|
19
21
|
declare function applyBlockquoteStyle(paraObj: Record<string, unknown>): void;
|
|
22
|
+
declare const parseDocxAggregator: ParseAggregatorRule;
|
|
23
|
+
declare const Blockquote: import("@tiptap/core").Node<import("@tiptap/extension-blockquote").BlockquoteOptions, any>;
|
|
20
24
|
//#endregion
|
|
21
|
-
export { BLOCKQUOTE_INDENT_LEFT as n,
|
|
25
|
+
export { parseDocxAggregator as a, applyBlockquoteStyle as i, BLOCKQUOTE_INDENT_LEFT as n, Blockquote as r, BLOCKQUOTE_BORDER as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as JSONContent } from "../core-
|
|
1
|
+
import { a as JSONContent, i as Extensions } from "../core-BqyLL84S.mjs";
|
|
2
2
|
import { PrepareStep } from "./prepare.mjs";
|
|
3
3
|
import { DocumentOptions, OutputByType, OutputType, PackerOptions, parseDocument } from "@office-open/docx";
|
|
4
4
|
|
|
@@ -13,6 +13,21 @@ declare class DocxManager {
|
|
|
13
13
|
private numberingConfigs;
|
|
14
14
|
private orderedInstanceCounter;
|
|
15
15
|
private resolveStyles;
|
|
16
|
+
private resolveNumberingLookup;
|
|
17
|
+
private markRender;
|
|
18
|
+
private markParse;
|
|
19
|
+
private nodeRender;
|
|
20
|
+
private nodeParse;
|
|
21
|
+
private blockRules;
|
|
22
|
+
private inlineRules;
|
|
23
|
+
private paragraphRules;
|
|
24
|
+
private aggregatorRules;
|
|
25
|
+
private resolveCtx;
|
|
26
|
+
constructor(extensions?: Extensions);
|
|
27
|
+
/** Reflective node renderDocx lookup: the node's DOCX opts, or {} when the
|
|
28
|
+
* node type has no renderDocx hook (degrades to a plain paragraph). node.type
|
|
29
|
+
* is optional on JSONContent — an absent type simply misses the map. */
|
|
30
|
+
private renderNodeOpts;
|
|
16
31
|
compile(json: JSONContent): DocumentOptions;
|
|
17
32
|
/** Assemble a SectionOptions from compiled children + optional layout/headers/footers. */
|
|
18
33
|
private buildSection;
|
|
@@ -65,73 +80,30 @@ declare class DocxManager {
|
|
|
65
80
|
private compileTextNode;
|
|
66
81
|
/** Emit a single run for `text` with all inline marks applied. */
|
|
67
82
|
private compileTextRun;
|
|
83
|
+
/**
|
|
84
|
+
* Wrap a run back into a w:ins/w:del container — the reverse of
|
|
85
|
+
* resolveTrackedChange. A literal-key ternary (`{insertion: body}` /
|
|
86
|
+
* `{deletion: body}`) lets TS narrow to the ParagraphChild branch without a
|
|
87
|
+
* cast, and `typeof` guards read `attrs` type-safely (no `as number/string`).
|
|
88
|
+
* stringifyDeletedRun emits `<w:delText>` automatically for deletion children.
|
|
89
|
+
*/
|
|
90
|
+
private compileTrackedChangeRun;
|
|
68
91
|
private resolveSectionChild;
|
|
69
92
|
/** Wrap an opaque SectionChild in a passthrough atom (attrs.data = JSON). */
|
|
70
93
|
private resolvePassthrough;
|
|
71
|
-
/**
|
|
72
|
-
* Resolve a table of contents into an editable `tableOfContents` container:
|
|
73
|
-
* `attrs.options` carries the field switches, `content` is the entry
|
|
74
|
-
* paragraphs. Each entry's inner HYPERLINK field has content-less runs that
|
|
75
|
-
* office-open parses as `null`; resolving the entries through
|
|
76
|
-
* `resolveSectionChild` → `resolveParagraphChildren` drops those nulls, so the
|
|
77
|
-
* TOC no longer reaches the generate path as an opaque blob of nulls (the
|
|
78
|
-
* `stringifyRunInline(null).break` crash). When `entries` is absent/empty
|
|
79
|
-
* (a fresh, unrendered TOC), keep the node valid for `content: "block+"` with
|
|
80
|
-
* a placeholder empty paragraph.
|
|
81
|
-
*/
|
|
82
|
-
private resolveToc;
|
|
83
|
-
/**
|
|
84
|
-
* Resolve a details group-SDT: the summary-style paragraph becomes
|
|
85
|
-
* detailsSummary, the remaining blocks fold into detailsContent.
|
|
86
|
-
*/
|
|
87
|
-
private resolveDetailsSdt;
|
|
88
94
|
private resolveParagraph;
|
|
89
|
-
/** Heading level (1-9) for a paragraph, or undefined when it isn't a heading.
|
|
90
|
-
* DOCX marks a heading several ways, checked in priority order:
|
|
91
|
-
* 1. office-open lifts a HeadingLevel pStyle ("Heading1".."Title") into `heading`.
|
|
92
|
-
* 2. An explicit `outlineLevel` (0-8 → 1-9) — Word's outline/TOC key off this
|
|
93
|
-
* even without a heading pStyle; the Heading1-9 styles carry outlineLvl 0-8.
|
|
94
|
-
* 3. A pStyle that names a heading style: directly ("Heading7", which stays on
|
|
95
|
-
* `style` because office-open's HeadingLevel type caps at 6), by localized
|
|
96
|
-
* NAME ("heading 1"/"标题 1"), or via the `basedOn` chain (a custom style
|
|
97
|
-
* "MyTitle" basedOn="Heading1"). `heading` and `style` carry the same pStyle.
|
|
98
|
-
* `outlineLevel` is read loosely — office-open's public type omits the field
|
|
99
|
-
* even though it round-trips (w:outlineLvl) at runtime. */
|
|
100
|
-
private detectHeadingLevel;
|
|
101
95
|
/** reference → level-0 format/start, for classifying numbering paragraphs. */
|
|
102
96
|
private buildNumberingLookup;
|
|
103
97
|
/**
|
|
104
|
-
* Walk
|
|
105
|
-
*
|
|
106
|
-
*
|
|
98
|
+
* Walk a SectionChild[] block stream — a section's body, a header/footer
|
|
99
|
+
* slot, or a table cell's children (a cell is just another block stream). An
|
|
100
|
+
* aggregator rule (list/blockquote) claims consecutive paragraphs sharing its
|
|
101
|
+
* predicate and rebuilds them as a composite; everything else resolves
|
|
102
|
+
* individually via resolveSectionChild. The manager owns only the generic
|
|
103
|
+
* group-by loop — the predicate (belongs) + builder (build) come from each
|
|
104
|
+
* rule, so a custom composite plugs in by declaring parseDocxAggregator.
|
|
107
105
|
*/
|
|
108
106
|
private resolveSectionChildren;
|
|
109
|
-
/** Classify a paragraph as a list item, or null if it isn't one. */
|
|
110
|
-
private detectList;
|
|
111
|
-
/**
|
|
112
|
-
* Rebuild nested Tiptap lists from a flat run of list paragraphs. Stack-based:
|
|
113
|
-
* each frame is an active list at a given depth; the `key` (level:type:
|
|
114
|
-
* reference) decides whether a paragraph continues the top list, starts a
|
|
115
|
-
* nested list, or splits off a new sibling list.
|
|
116
|
-
*/
|
|
117
|
-
private buildListTree;
|
|
118
|
-
/** Classify a paragraph as a blockquote member by its signature. */
|
|
119
|
-
private detectBlockquote;
|
|
120
|
-
/**
|
|
121
|
-
* Rebuild a blockquote node from a run of signature-carrying paragraphs,
|
|
122
|
-
* stripping the indent/border signature so child paragraphs render clean.
|
|
123
|
-
*/
|
|
124
|
-
private buildBlockquote;
|
|
125
|
-
/**
|
|
126
|
-
* Resolve a list-item paragraph to a Tiptap paragraph/heading node, stripping
|
|
127
|
-
* the list marker (bullet/numbering) and the leading task checkbox — those
|
|
128
|
-
* are expressed at the list/item level, not inside the paragraph.
|
|
129
|
-
*/
|
|
130
|
-
private resolveListItemParagraph;
|
|
131
|
-
/** Return a copy of `para` with its leading docen-task checkbox SDT removed. */
|
|
132
|
-
private stripTaskCheckbox;
|
|
133
|
-
private resolveCodeBlock;
|
|
134
|
-
private resolveTable;
|
|
135
107
|
/**
|
|
136
108
|
* Resolve a paragraph's inline content. @office-open collapses a plain-text
|
|
137
109
|
* paragraph (a single run with no properties) to a bare string or a `{ text }`
|
|
@@ -141,12 +113,8 @@ declare class DocxManager {
|
|
|
141
113
|
private resolveInlineContent;
|
|
142
114
|
private resolveParagraphChildren;
|
|
143
115
|
private resolveParagraphChild;
|
|
144
|
-
/** Resolve an inline SDT (mention carrier; other inline SDTs unsupported). */
|
|
145
|
-
private resolveInlineSdt;
|
|
146
116
|
private resolveRun;
|
|
147
117
|
private resolveMarks;
|
|
148
|
-
private resolveImage;
|
|
149
|
-
private resolveHyperlink;
|
|
150
118
|
}
|
|
151
119
|
/**
|
|
152
120
|
* Parse a DOCX file into Tiptap JSON (runtime model).
|
|
@@ -154,7 +122,7 @@ declare class DocxManager {
|
|
|
154
122
|
* Combines @office-open/docx's `parseDocument` (DOCX binary → DocumentOptions)
|
|
155
123
|
* with `DocxManager.resolve` (DocumentOptions → Tiptap JSON).
|
|
156
124
|
*/
|
|
157
|
-
declare function parseDOCX(data: Parameters<typeof parseDocument>[0]): JSONContent;
|
|
125
|
+
declare function parseDOCX(data: Parameters<typeof parseDocument>[0], extensions?: Extensions): JSONContent;
|
|
158
126
|
/**
|
|
159
127
|
* Options for {@link generateDOCX} / {@link generateDOCXStream}.
|
|
160
128
|
*/
|
|
@@ -182,6 +150,12 @@ interface DocxGenerateOptions<T extends OutputType = "nodebuffer"> {
|
|
|
182
150
|
* exclusive, so specifying `externalStyles` drops the compiled `styles`.
|
|
183
151
|
*/
|
|
184
152
|
document?: Omit<Partial<DocumentOptions>, "sections" | "numbering">;
|
|
153
|
+
/**
|
|
154
|
+
* Extension list used to build the conversion registry (default:
|
|
155
|
+
* `docxExtensions`). Pass `[...docxExtensions, MyMark]` to plug a custom
|
|
156
|
+
* mark/node into compile/resolve via its renderDocx/parseDocx hooks.
|
|
157
|
+
*/
|
|
158
|
+
extensions?: Extensions;
|
|
185
159
|
}
|
|
186
160
|
/**
|
|
187
161
|
* Generate a DOCX file from Tiptap JSON (runtime model), asynchronously.
|
|
@@ -212,10 +186,10 @@ declare function generateDOCXStream(json: JSONContent, options?: DocxGenerateOpt
|
|
|
212
186
|
/**
|
|
213
187
|
* Convert DocumentOptions (persistence model) to Tiptap JSON (runtime model).
|
|
214
188
|
*/
|
|
215
|
-
declare function resolveDocument(docOpts: DocumentOptions): JSONContent;
|
|
189
|
+
declare function resolveDocument(docOpts: DocumentOptions, extensions?: Extensions): JSONContent;
|
|
216
190
|
/**
|
|
217
191
|
* Convert Tiptap JSON (runtime model) to DocumentOptions (persistence model).
|
|
218
192
|
*/
|
|
219
|
-
declare function compileDocument(json: JSONContent): DocumentOptions;
|
|
193
|
+
declare function compileDocument(json: JSONContent, extensions?: Extensions): DocumentOptions;
|
|
220
194
|
//#endregion
|
|
221
195
|
export { type DocumentOptions, DocxGenerateOptions, DocxManager, compileDocument, generateDOCX, generateDOCXStream, generateDOCXSync, parseDOCX, resolveDocument };
|