@docen/docx 0.3.0 → 0.3.1
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 +2 -3
- package/dist/blockquote-Ky9xD_Q-.mjs +31 -0
- package/dist/code-block-BgNjhADy.mjs +23 -0
- package/dist/converters/docx.d.mts +1 -109
- package/dist/converters/docx.mjs +1 -623
- package/dist/converters/html.d.mts +1 -13
- package/dist/converters/html.mjs +1 -17
- package/dist/converters/markdown.d.mts +1 -12
- package/dist/converters/markdown.mjs +1 -17
- package/dist/converters/patch.d.mts +1 -52
- package/dist/converters/patch.mjs +1 -36
- package/dist/converters/prepare.d.mts +2 -51
- package/dist/converters/prepare.mjs +2 -76
- package/dist/converters/styles.d.mts +2 -0
- package/dist/converters/styles.mjs +2 -0
- package/dist/core-DEqBHRzE.mjs +406 -0
- package/dist/core-fBMCCj4D.d.mts +97 -0
- package/dist/core.d.mts +1 -1
- package/dist/core.mjs +1 -1
- package/dist/details-Dh8luWb2.mjs +18 -0
- package/dist/dist-B6B3HnVZ.mjs +1838 -0
- package/dist/document-BH1y4qHM.d.mts +6 -0
- package/dist/document-CvTym-FM.mjs +50 -0
- package/dist/docx-C5wyjI-0.d.mts +200 -0
- package/dist/docx-CONyAedl.mjs +1231 -0
- package/dist/editor-Bf3CxQnY.mjs +21 -0
- package/dist/editor-DReY3Rb9.d.mts +21 -0
- package/dist/editor.d.mts +1 -20
- package/dist/editor.mjs +1 -19
- package/dist/emoji-BZ1dJD7d.d.mts +17 -0
- package/dist/emoji-C2OsTWR7.mjs +27 -0
- package/dist/extensions/blockquote.d.mts +23 -0
- package/dist/extensions/blockquote.mjs +3 -0
- package/dist/extensions/code-block.d.mts +19 -0
- package/dist/extensions/code-block.mjs +2 -0
- package/dist/extensions/column-break.d.mts +31 -0
- package/dist/extensions/column-break.mjs +2 -0
- package/dist/extensions/details.d.mts +19 -0
- package/dist/extensions/details.mjs +3 -0
- package/dist/extensions/document.d.mts +2 -0
- package/dist/extensions/document.mjs +2 -0
- package/dist/extensions/emoji.d.mts +2 -0
- package/dist/extensions/emoji.mjs +2 -0
- package/dist/extensions/extensions.d.mts +6 -5
- package/dist/extensions/extensions.mjs +14 -12
- package/dist/extensions/formatting-marks.d.mts +32 -0
- package/dist/extensions/formatting-marks.mjs +2 -0
- package/dist/extensions/heading.mjs +1 -144
- package/dist/extensions/image-group.d.mts +6 -0
- package/dist/extensions/image-group.mjs +2 -0
- package/dist/extensions/image.d.mts +2 -2
- package/dist/extensions/image.mjs +1 -200
- package/dist/extensions/index.d.mts +3 -2
- package/dist/extensions/index.mjs +3 -2
- package/dist/extensions/mention.d.mts +25 -0
- package/dist/extensions/mention.mjs +3 -0
- package/dist/extensions/ordered-list.d.mts +25 -0
- package/dist/extensions/ordered-list.mjs +3 -0
- package/dist/extensions/page-break.d.mts +34 -0
- package/dist/extensions/page-break.mjs +2 -0
- package/dist/extensions/paragraph.d.mts +1 -1
- package/dist/extensions/paragraph.mjs +1 -115
- package/dist/extensions/passthrough.d.mts +2 -0
- package/dist/extensions/passthrough.mjs +2 -0
- package/dist/extensions/section-break.d.mts +27 -0
- package/dist/extensions/section-break.mjs +2 -0
- package/dist/extensions/strike.mjs +1 -49
- package/dist/extensions/table-cell.mjs +1 -111
- package/dist/extensions/table-header.mjs +1 -111
- package/dist/extensions/table-row.mjs +1 -83
- package/dist/extensions/table.mjs +1 -133
- package/dist/extensions/task-item.d.mts +27 -0
- package/dist/extensions/task-item.mjs +3 -0
- package/dist/extensions/text-style.mjs +1 -133
- package/dist/extensions/tiptap.mjs +1 -32
- package/dist/extensions/types.d.mts +7 -5
- package/dist/extensions/utils.d.mts +16 -3
- package/dist/extensions/utils.mjs +2 -289
- package/dist/heading-DAubgJJN.mjs +166 -0
- package/dist/html-DCC_DSHv.d.mts +18 -0
- package/dist/html-DedDWPoO.mjs +66 -0
- package/dist/image-CuEIXoZl.mjs +334 -0
- package/dist/index.d.mts +68 -18
- package/dist/index.mjs +10 -8
- package/dist/markdown-BzJmRsBs.mjs +18 -0
- package/dist/markdown-D0k0sRYS.d.mts +13 -0
- package/dist/mention-C-dTR6MK.mjs +44 -0
- package/dist/ordered-list-V-3xFQmV.mjs +41 -0
- package/dist/paragraph-BrWH-BOV.mjs +147 -0
- package/dist/paragraph-D8mpHo_o.d.mts +8 -0
- package/dist/patch-Cdp5WKJz.d.mts +53 -0
- package/dist/patch-IZ13tXTu.mjs +36 -0
- package/dist/prepare-Bdk8Cjkf.mjs +122 -0
- package/dist/prepare-CPAvcv6q.d.mts +63 -0
- package/dist/strike-hWxShOgb.mjs +50 -0
- package/dist/styles-QSX3RhxK.mjs +285 -0
- package/dist/styles-ugspkrxz.d.mts +85 -0
- package/dist/table-DrA12lxX.mjs +159 -0
- package/dist/table-cell-DmkfYwDc.mjs +112 -0
- package/dist/table-header-Bwr5GKWg.mjs +112 -0
- package/dist/table-row-vew1y7WH.mjs +84 -0
- package/dist/task-item-BnlXGrIG.mjs +37 -0
- package/dist/text-style-tMeBq5XQ.mjs +151 -0
- package/dist/tiptap-D7pl4I5U.mjs +33 -0
- package/dist/utils-BPT4tjcn.mjs +333 -0
- package/package.json +3 -2
- package/dist/core-CFIQVRfx.mjs +0 -88
- package/dist/core-omBKMRtl.d.mts +0 -34
- package/dist/image-Ge1y6uam.d.mts +0 -47
- package/dist/paragraph-fhEXtAN2.d.mts +0 -16
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
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 shell with the turnkey `<docen-document>` super-component.
|
|
10
|
+
|
|
9
11
|
## Features
|
|
10
12
|
|
|
11
13
|
- 📝 **Tiptap Editor** — Full-featured WYSIWYG editor with DOCX-aware extensions
|
|
@@ -142,9 +144,6 @@ Standalone Functions (core)
|
|
|
142
144
|
↕ used by
|
|
143
145
|
Tiptap Extension Commands (thin wrappers)
|
|
144
146
|
editor.commands.importDocx() / exportDocx()
|
|
145
|
-
↕ used by
|
|
146
|
-
@docen/ui (Fluent UI Web Components)
|
|
147
|
-
<docx-editor> toolbar / ribbon / menus
|
|
148
147
|
```
|
|
149
148
|
|
|
150
149
|
- **Runtime model**: Tiptap JSON with DOCX-rich attributes via custom extensions
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import "./tiptap-D7pl4I5U.mjs";
|
|
2
|
+
//#region src/extensions/blockquote.ts
|
|
3
|
+
/**
|
|
4
|
+
* Blockquote extension — owns the DOCX expression of a blockquote.
|
|
5
|
+
*
|
|
6
|
+
* DOCX has no blockquote element; the convention is a left indent plus a left
|
|
7
|
+
* border on each contained paragraph. This module owns that signature; the
|
|
8
|
+
* DocxManager walks the blockquote's child paragraphs and applies it to each.
|
|
9
|
+
*/
|
|
10
|
+
/** Left indent (twips, ~0.5 inch) marking a blockquote. */
|
|
11
|
+
const BLOCKQUOTE_INDENT_LEFT = 720;
|
|
12
|
+
/** Left border marking a blockquote. */
|
|
13
|
+
const BLOCKQUOTE_BORDER = {
|
|
14
|
+
style: "single",
|
|
15
|
+
size: 18,
|
|
16
|
+
space: 12,
|
|
17
|
+
color: "CCCCCC"
|
|
18
|
+
};
|
|
19
|
+
/** Apply the blockquote signature (left indent + left border) to paragraph opts. */
|
|
20
|
+
function applyBlockquoteStyle(paraObj) {
|
|
21
|
+
paraObj.indent = {
|
|
22
|
+
...paraObj.indent ?? {},
|
|
23
|
+
left: 720
|
|
24
|
+
};
|
|
25
|
+
paraObj.border = {
|
|
26
|
+
...paraObj.border ?? {},
|
|
27
|
+
left: BLOCKQUOTE_BORDER
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { BLOCKQUOTE_INDENT_LEFT as n, applyBlockquoteStyle as r, BLOCKQUOTE_BORDER as t };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { a as CodeBlockLowlight } from "./tiptap-D7pl4I5U.mjs";
|
|
2
|
+
//#region src/extensions/code-block.ts
|
|
3
|
+
/**
|
|
4
|
+
* CodeBlock extension — CodeBlockLowlight with a DOCX renderDocx.
|
|
5
|
+
*
|
|
6
|
+
* DOCX has no dedicated code-block element. A code block maps to a single
|
|
7
|
+
* paragraph styled "Code" with a monospace run font. Inline marks (syntax-
|
|
8
|
+
* highlight tokens) and line breaks (`\n` → `<w:br/>`) are handled by
|
|
9
|
+
* DocxManager's shared inline-content compilation; resolveCodeBlock reassembles
|
|
10
|
+
* the text. This module owns only the paragraph-level style.
|
|
11
|
+
*
|
|
12
|
+
* `language` has no OOXML carrier and is intentionally dropped (known lossy).
|
|
13
|
+
*/
|
|
14
|
+
/** codeBlock node → paragraph properties (style "Code" + monospace font). */
|
|
15
|
+
function renderDocx(_node) {
|
|
16
|
+
return {
|
|
17
|
+
style: "Code",
|
|
18
|
+
run: { font: "Consolas" }
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const CodeBlock = CodeBlockLowlight.extend({ renderDocx });
|
|
22
|
+
//#endregion
|
|
23
|
+
export { renderDocx as n, CodeBlock as t };
|
|
@@ -1,110 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
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
|
-
compile(json: JSONContent): DocumentOptions;
|
|
14
|
-
resolve(docOpts: DocumentOptions): JSONContent;
|
|
15
|
-
private compileSectionChild;
|
|
16
|
-
private compileParagraphNode;
|
|
17
|
-
private compileHeadingNode;
|
|
18
|
-
private compileCodeBlock;
|
|
19
|
-
/** Simple text optimization: merge plain runs into text field */
|
|
20
|
-
private simplifyParagraph;
|
|
21
|
-
private compileTableNode;
|
|
22
|
-
/** Count grid columns from the first table row (summing colspan). */
|
|
23
|
-
private getTableColumnCount;
|
|
24
|
-
/**
|
|
25
|
-
* Compute tblGrid column widths (twips) from first-row cell colwidth attrs.
|
|
26
|
-
* Returns columnWidths array and the appropriate tableWidth.
|
|
27
|
-
*/
|
|
28
|
-
private computeColumnWidths;
|
|
29
|
-
private compileTableCellNode;
|
|
30
|
-
private compileListFromNode;
|
|
31
|
-
private compileInlineContent;
|
|
32
|
-
private compileTextNode;
|
|
33
|
-
private resolveSectionChild;
|
|
34
|
-
private resolveParagraph;
|
|
35
|
-
private resolveListItem;
|
|
36
|
-
private resolveTable;
|
|
37
|
-
/**
|
|
38
|
-
* Resolve a paragraph's inline content. @office-open collapses a plain-text
|
|
39
|
-
* paragraph (a single run with no properties) to a bare string or a `{ text }`
|
|
40
|
-
* object with no `children` — recover that text here so it round-trips back to
|
|
41
|
-
* a text node instead of being dropped.
|
|
42
|
-
*/
|
|
43
|
-
private resolveInlineContent;
|
|
44
|
-
private resolveParagraphChildren;
|
|
45
|
-
private resolveParagraphChild;
|
|
46
|
-
private resolveRun;
|
|
47
|
-
private resolveMarks;
|
|
48
|
-
private resolveImage;
|
|
49
|
-
private resolveHyperlink;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Parse a DOCX file into Tiptap JSON (runtime model).
|
|
53
|
-
*
|
|
54
|
-
* Combines @office-open/docx's `parseDocument` (DOCX binary → DocumentOptions)
|
|
55
|
-
* with `DocxManager.resolve` (DocumentOptions → Tiptap JSON).
|
|
56
|
-
*/
|
|
57
|
-
declare function parseDOCX(data: Parameters<typeof parseDocument>[0]): JSONContent;
|
|
58
|
-
/**
|
|
59
|
-
* Options for {@link generateDOCX} / {@link generateDOCXStream}.
|
|
60
|
-
*/
|
|
61
|
-
interface DocxGenerateOptions<T extends OutputType = "nodebuffer"> {
|
|
62
|
-
/**
|
|
63
|
-
* Pre-compilation steps run on the JSON in place (default: `prepareImages()`).
|
|
64
|
-
* - `true` / `undefined`: default image pre-fetch (http(s) → embedded data URL)
|
|
65
|
-
* - `false`: skip preparation
|
|
66
|
-
* - `PrepareStep[]`: custom steps
|
|
67
|
-
*
|
|
68
|
-
* Required for http image URLs — image `renderDocx` drops images without
|
|
69
|
-
* embedded data (see extensions/image.ts). Mutates the JSON, like `prepareDocument`.
|
|
70
|
-
*/
|
|
71
|
-
prepare?: boolean | PrepareStep[];
|
|
72
|
-
/** Packer options; `type` controls the output format (default `"nodebuffer"` → Buffer). */
|
|
73
|
-
packer?: PackerOptions<T>;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Generate a DOCX file from Tiptap JSON (runtime model), asynchronously.
|
|
77
|
-
*
|
|
78
|
-
* Pipeline: `prepareDocument` (default: fetch http images, in place) →
|
|
79
|
-
* `DocxManager.compile` → @office-open/docx's `generateDocument`. `packer.type`
|
|
80
|
-
* controls the output format (default: `"nodebuffer"` → Buffer). Non-blocking
|
|
81
|
-
* (fflate Web Workers). With the default `prepare`, the input `json` is mutated
|
|
82
|
-
* in place (http image URLs become embedded data URLs).
|
|
83
|
-
*/
|
|
84
|
-
declare function generateDOCX<T extends OutputType = "nodebuffer">(json: JSONContent, options?: DocxGenerateOptions<T>): Promise<OutputByType[T]>;
|
|
85
|
-
/**
|
|
86
|
-
* Generate a DOCX file synchronously — fastest throughput, blocks the event loop.
|
|
87
|
-
*
|
|
88
|
-
* Pipeline: `DocxManager.compile` → `generateDocumentSync`. Does **not** run
|
|
89
|
-
* `prepareDocument` (it is async); call `await prepareDocument(json)` first
|
|
90
|
-
* when http images need embedding.
|
|
91
|
-
*/
|
|
92
|
-
declare function generateDOCXSync<T extends OutputType = "nodebuffer">(json: JSONContent, packerOptions?: PackerOptions<T>): OutputByType[T];
|
|
93
|
-
/**
|
|
94
|
-
* Generate a DOCX file as a `ReadableStream<Uint8Array>` — for large documents
|
|
95
|
-
* or streaming HTTP responses.
|
|
96
|
-
*
|
|
97
|
-
* Pipeline: `prepareDocument` (default: fetch http images, in place) →
|
|
98
|
-
* `DocxManager.compile` → `generateDocumentStream`. Async due to preparation.
|
|
99
|
-
*/
|
|
100
|
-
declare function generateDOCXStream(json: JSONContent, options?: DocxGenerateOptions): Promise<ReadableStream<Uint8Array>>;
|
|
101
|
-
/**
|
|
102
|
-
* Convert DocumentOptions (persistence model) to Tiptap JSON (runtime model).
|
|
103
|
-
*/
|
|
104
|
-
declare function resolveDocument(docOpts: DocumentOptions): JSONContent;
|
|
105
|
-
/**
|
|
106
|
-
* Convert Tiptap JSON (runtime model) to DocumentOptions (persistence model).
|
|
107
|
-
*/
|
|
108
|
-
declare function compileDocument(json: JSONContent): DocumentOptions;
|
|
109
|
-
//#endregion
|
|
1
|
+
import { a as generateDOCX, c as parseDOCX, i as compileDocument, l as resolveDocument, n as DocxGenerateOptions, o as generateDOCXStream, r as DocxManager, s as generateDOCXSync, t as DocumentOptions } from "../docx-C5wyjI-0.mjs";
|
|
110
2
|
export { type DocumentOptions, DocxGenerateOptions, DocxManager, compileDocument, generateDOCX, generateDOCXStream, generateDOCXSync, parseDOCX, resolveDocument };
|