@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSONContent } from "@tiptap/core";
|
|
2
|
-
import { RunOptions } from "@office-open/docx";
|
|
2
|
+
import { ParagraphChild, ParagraphOptions, RunOptions, SectionChild, StylesOptions } from "@office-open/docx";
|
|
3
3
|
|
|
4
4
|
//#region src/extensions/types.d.ts
|
|
5
5
|
declare module "@tiptap/core" {
|
|
@@ -16,17 +16,136 @@ declare module "@tiptap/core" {
|
|
|
16
16
|
* Each node extension defines this to convert DOCX properties back to attrs.
|
|
17
17
|
*/
|
|
18
18
|
parseDocx?: (opts: Record<string, unknown>) => Record<string, unknown>;
|
|
19
|
+
/**
|
|
20
|
+
* Declarative block parse rule: recognize a SectionChild shape this node
|
|
21
|
+
* owns and convert it to a JSONContent node. DocxManager walks every
|
|
22
|
+
* extension's rule (in docxExtensions declaration order) during resolve, so
|
|
23
|
+
* a custom block node plugs in by declaring this instead of forking
|
|
24
|
+
* DocxManager. `match` false → skipped; `convert` null after a positive
|
|
25
|
+
* match falls through to the next rule, then the paragraph/passthrough
|
|
26
|
+
* fallbacks.
|
|
27
|
+
*/
|
|
28
|
+
parseDocxBlock?: ParseBlockRule;
|
|
29
|
+
/**
|
|
30
|
+
* Declarative inline parse rule: recognize a ParagraphChild shape this
|
|
31
|
+
* node/mark owns and convert it to inline content (a node, text[], or
|
|
32
|
+
* null to fall through). DocxManager walks every extension's rule during
|
|
33
|
+
* resolve, so a custom inline shape plugs in by declaring this instead of
|
|
34
|
+
* forking DocxManager. Used by both Node extensions (image/tab/wpsShape/…)
|
|
35
|
+
* and Mark containers (hyperlink/insertion/deletion, which yield text
|
|
36
|
+
* nodes carrying the mark).
|
|
37
|
+
*/
|
|
38
|
+
parseDocxInline?: ParseInlineRule;
|
|
39
|
+
/**
|
|
40
|
+
* Declarative paragraph parse rule: recognize a paragraph subtype this node
|
|
41
|
+
* owns (heading/codeBlock) and convert it to a JSONContent node. DocxManager
|
|
42
|
+
* walks every extension's rule during resolve before the plain-paragraph
|
|
43
|
+
* fallback, so a custom paragraph subtype plugs in by declaring this instead
|
|
44
|
+
* of forking DocxManager. thematicBreak (→ horizontalRule) stays in the
|
|
45
|
+
* manager — it has no owning extension.
|
|
46
|
+
*/
|
|
47
|
+
parseDocxParagraph?: ParseParagraphRule;
|
|
48
|
+
/**
|
|
49
|
+
* Declarative aggregator: claims consecutive paragraphs that belong to a
|
|
50
|
+
* composite structure (a list tree, a blockquote) and rebuilds them as
|
|
51
|
+
* nested JSONContent. DocxManager keeps a generic group-by-predicate loop;
|
|
52
|
+
* the rule contributes the predicate (belongs) + the builder (build). A
|
|
53
|
+
* custom composite plugs in by declaring this instead of forking DocxManager.
|
|
54
|
+
*/
|
|
55
|
+
parseDocxAggregator?: ParseAggregatorRule;
|
|
56
|
+
}
|
|
57
|
+
interface ExtensionConfig<Options = any, Storage = any> {
|
|
58
|
+
/** Declarative aggregator on a plain Extension (e.g. a list-tree rebuilder
|
|
59
|
+
* that spans bullet/ordered/task lists). See NodeConfig.parseDocxAggregator. */
|
|
60
|
+
parseDocxAggregator?: ParseAggregatorRule;
|
|
19
61
|
}
|
|
20
62
|
interface MarkConfig<Options = any, Storage = any> {
|
|
21
63
|
/**
|
|
22
|
-
* DOCX serialization: mark attrs →
|
|
23
|
-
* Each mark extension defines this to contribute
|
|
64
|
+
* DOCX serialization: mark attrs → run-level properties (merged into the
|
|
65
|
+
* run's options). Each mark extension defines this to contribute rPr fields.
|
|
66
|
+
*/
|
|
67
|
+
renderDocx?: (attrs: Record<string, unknown>) => Record<string, unknown>;
|
|
68
|
+
/**
|
|
69
|
+
* DOCX deserialization: RunOptions → mark attrs, or null when the run does
|
|
70
|
+
* not carry this mark (DocxManager then skips emitting it). Each mark
|
|
71
|
+
* extension defines this to extract its attrs from run properties.
|
|
24
72
|
*/
|
|
25
|
-
|
|
73
|
+
parseDocx?: (opts: RunOptions) => Record<string, unknown> | null;
|
|
26
74
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
75
|
+
* Declarative inline parse rule (see NodeConfig.parseDocxInline). A Mark
|
|
76
|
+
* container such as hyperlink/insertion/deletion declares this to yield
|
|
77
|
+
* text nodes carrying the mark.
|
|
29
78
|
*/
|
|
30
|
-
|
|
79
|
+
parseDocxInline?: ParseInlineRule;
|
|
31
80
|
}
|
|
32
|
-
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Per-resolve façade handed to parse rules: read-only views over the
|
|
84
|
+
* DocumentOptions being resolved plus recursive entry points back into
|
|
85
|
+
* DocxManager — a table cell, a TOC entry, and a details body are themselves
|
|
86
|
+
* SectionChild[] block streams. Rule bodies must stay pure: getExtensionField
|
|
87
|
+
* binds no `this`, so a rule cannot read extension options/storage and reaches
|
|
88
|
+
* the manager only through this context.
|
|
89
|
+
*/
|
|
90
|
+
interface ResolveContext {
|
|
91
|
+
/** Walk a SectionChild[] block stream (a cell's children, a TOC's entries, a
|
|
92
|
+
* details body) — regroups consecutive numbering paragraphs into lists. */
|
|
93
|
+
resolveBlockStream(children: SectionChild[]): JSONContent[];
|
|
94
|
+
/** Resolve one SectionChild (a TOC entry, a details body block). */
|
|
95
|
+
resolveBlock(child: SectionChild): JSONContent | null;
|
|
96
|
+
/** Resolve a paragraph's inline content (handles the bare-string/{text}
|
|
97
|
+
* fallback office-open collapses a plain paragraph to). */
|
|
98
|
+
resolveInlineContent(para: ParagraphOptions): JSONContent[];
|
|
99
|
+
/** Walk a ParagraphChild[] inline stream (a hyperlink/track-change container's
|
|
100
|
+
* child runs) — the inline counterpart of resolveBlockStream. */
|
|
101
|
+
resolveInlineChildren(children: (ParagraphChild | string)[]): JSONContent[];
|
|
102
|
+
/** Resolve a paragraph (a wpsShape text-box body block). */
|
|
103
|
+
resolveParagraph(para: ParagraphOptions | string): JSONContent;
|
|
104
|
+
/** Reflective node attrs parse (table/tableRow/tableHeader/tableCell/…) —
|
|
105
|
+
* reuses the nodeParse registry so a block rule shares the attrs extraction
|
|
106
|
+
* the inline/compile paths use. */
|
|
107
|
+
parseNodeAttrs(type: string, opts: Record<string, unknown>): Record<string, unknown>;
|
|
108
|
+
/** Resolve run-level marks (bold/italic/…) for a RunOptions — used by
|
|
109
|
+
* code-block's resolveCodeBlock to recover inline marks on each run. */
|
|
110
|
+
resolveMarks(opts: RunOptions): JSONContent["marks"];
|
|
111
|
+
/** The document's styles.xml model. Table rules read tableStyles; paragraph
|
|
112
|
+
* rules (Phase 2) will read paragraphStyles. */
|
|
113
|
+
readonly styles: StylesOptions | undefined;
|
|
114
|
+
/** Numbering reference → level-0 format/start, for classifying list paragraphs
|
|
115
|
+
* (bullet vs ordered, start value). Read by the list aggregator. */
|
|
116
|
+
readonly numberingLookup: Map<string, {
|
|
117
|
+
format?: string;
|
|
118
|
+
start?: number;
|
|
119
|
+
}> | undefined;
|
|
120
|
+
}
|
|
121
|
+
/** A declarative block parse rule. `match` identifies the SectionChild shape
|
|
122
|
+
* this node owns; `convert` builds the JSONContent node (null falls through to
|
|
123
|
+
* the next rule). */
|
|
124
|
+
interface ParseBlockRule {
|
|
125
|
+
match(child: SectionChild, ctx: ResolveContext): boolean;
|
|
126
|
+
convert(child: SectionChild, ctx: ResolveContext): JSONContent | null;
|
|
127
|
+
}
|
|
128
|
+
/** A declarative inline parse rule. `match` identifies the ParagraphChild
|
|
129
|
+
* shape; `convert` builds inline content — a node, an array (hyperlink/
|
|
130
|
+
* track-change yield text[]), or null to fall through to the next rule. */
|
|
131
|
+
interface ParseInlineRule {
|
|
132
|
+
match(child: ParagraphChild, ctx: ResolveContext): boolean;
|
|
133
|
+
convert(child: ParagraphChild, ctx: ResolveContext): JSONContent | JSONContent[] | null;
|
|
134
|
+
}
|
|
135
|
+
/** A declarative paragraph parse rule. `match` identifies the paragraph
|
|
136
|
+
* subtype; `convert` builds the JSONContent node (null falls through to the
|
|
137
|
+
* next rule, then the plain-paragraph fallback). */
|
|
138
|
+
interface ParseParagraphRule {
|
|
139
|
+
match(para: ParagraphOptions, ctx: ResolveContext): boolean;
|
|
140
|
+
convert(para: ParagraphOptions, ctx: ResolveContext): JSONContent | null;
|
|
141
|
+
}
|
|
142
|
+
/** A declarative aggregator rule. `belongs` is the predicate grouping
|
|
143
|
+
* consecutive paragraphs into one composite; `build` turns the group into
|
|
144
|
+
* JSONContent[] (e.g. a nested list tree, a blockquote). The manager runs the
|
|
145
|
+
* generic group-by loop — the rule owns only the predicate + builder. */
|
|
146
|
+
interface ParseAggregatorRule {
|
|
147
|
+
belongs(para: ParagraphOptions, ctx: ResolveContext): boolean;
|
|
148
|
+
build(group: ParagraphOptions[], ctx: ResolveContext): JSONContent[];
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
export { ParseAggregatorRule, ParseBlockRule, ParseInlineRule, ParseParagraphRule, ResolveContext };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
export { alignmentFromCss, alignmentFromElement, alignmentToCss, attrNative, bordersFromElement, characterSpacingFromCss, characterSpacingToCss, cssToTwip, floatAnchorScope, floatingToStyles, indentFromElement, lineSpacingToCss, normalizeColorToHex, renderBorderCSS, renderParagraphStyles, renderRunStyles, renderTableCellStyles, resolveFontFamilyCss, resolveFontName, resolvePageSize, sectionLinePitchCss, sectionMarginCss, shadingFromCss, shadingFromElement, shadingToCss, sizeFromCss, sizeToCss, spacingFromElement, twipToCss, twipsToMm };
|
|
1
|
+
import { A as twipToCss, C as shadingFromCss, D as sizeToCss, E as sizeFromCss, O as spacingFromElement, S as sectionMarginCss, T as shadingToCss, _ as renderTableCellStyles, a as bordersFromElement, b as resolvePageSize, c as cssToTwip, d as indentFromElement, f as lineSpacingToCss, g as renderRunStyles, h as renderParagraphStyles, i as attrNative, j as twipsToMm, k as tableFloatToCss, l as floatAnchorScope, m as renderBorderCSS, n as alignmentFromElement, o as characterSpacingFromCss, p as normalizeColorToHex, r as alignmentToCss, s as characterSpacingToCss, t as alignmentFromCss, u as floatingToStyles, v as resolveFontFamilyCss, w as shadingFromElement, x as sectionLinePitchCss, y as resolveFontName } from "../utils-CfwwOowz.mjs";
|
|
2
|
+
export { alignmentFromCss, alignmentFromElement, alignmentToCss, attrNative, bordersFromElement, characterSpacingFromCss, characterSpacingToCss, cssToTwip, floatAnchorScope, floatingToStyles, indentFromElement, lineSpacingToCss, normalizeColorToHex, renderBorderCSS, renderParagraphStyles, renderRunStyles, renderTableCellStyles, resolveFontFamilyCss, resolveFontName, resolvePageSize, sectionLinePitchCss, sectionMarginCss, shadingFromCss, shadingFromElement, shadingToCss, sizeFromCss, sizeToCss, spacingFromElement, tableFloatToCss, twipToCss, twipsToMm };
|
|
@@ -282,6 +282,11 @@ function floatingToStyles(floating, src, width) {
|
|
|
282
282
|
if (wrapType === 0) {
|
|
283
283
|
styles.push("position:absolute");
|
|
284
284
|
if (hOff != null) styles.push(`left:${(hOff / EMU_PER_PX).toFixed(1)}px`);
|
|
285
|
+
else {
|
|
286
|
+
const hAlign = f.horizontalPosition?.align;
|
|
287
|
+
if (hAlign === "center") styles.push("left:50%", "transform:translateX(-50%)");
|
|
288
|
+
else if (hAlign === "right") styles.push("right:0");
|
|
289
|
+
}
|
|
285
290
|
if (vOff != null) styles.push(`top:${(vOff / EMU_PER_PX).toFixed(1)}px`);
|
|
286
291
|
} else if (wrapType !== 3 && hOff != null && width != null) {
|
|
287
292
|
const offPx = (hOff / EMU_PER_PX).toFixed(1);
|
|
@@ -325,6 +330,74 @@ function floatAnchorScope(floating) {
|
|
|
325
330
|
return "paragraph";
|
|
326
331
|
}
|
|
327
332
|
/**
|
|
333
|
+
* Render a table's float anchor (w:tblpPr → TableFloatOptions) to CSS.
|
|
334
|
+
*
|
|
335
|
+
* Unlike a drawing's Floating (wp:anchor, EMU offsets, wrap types), a floating
|
|
336
|
+
* table carries no wrap type — Word's "text wrapping" around a table is plain
|
|
337
|
+
* CSS float with margins. Twips (not EMU) throughout: tblpX/Y and the fromText
|
|
338
|
+
* gaps are dxa.
|
|
339
|
+
*
|
|
340
|
+
* Two render modes:
|
|
341
|
+
* - text-anchored wrap (horizontalAnchor=text) → CSS float + margins, so body
|
|
342
|
+
* text flows beside the table. tblpX → margin on the float side; fromText →
|
|
343
|
+
* the opposite side + top/bottom (mirrors floatingToStyles so the offset and
|
|
344
|
+
* the wrap gap never compete for the same margin edge).
|
|
345
|
+
* - page/margin anchor → position:absolute pinned to the page box, floating at
|
|
346
|
+
* the offset/alignment like Word's page-anchored table. .docen-page is
|
|
347
|
+
* position:relative and its padding box is the physical page (no border), so
|
|
348
|
+
* top:0/left:0 matches OOXML's page origin; symmetric page padding makes
|
|
349
|
+
* left:50% the content-box center too, so a margin anchor centers alike.
|
|
350
|
+
* - text-anchored center/inside/outside have no CSS float equivalent (and
|
|
351
|
+
* inside/outside need odd/even pages the editor lacks) → degraded to [].
|
|
352
|
+
* attrs still round-trip byte-faithful via renderDocx/parseDocx passthrough.
|
|
353
|
+
* - overlap (neverOverlap) has no CSS float equivalent; ignored.
|
|
354
|
+
*/
|
|
355
|
+
function tableFloatToCss(float) {
|
|
356
|
+
const f = float;
|
|
357
|
+
if (!f) return [];
|
|
358
|
+
const hAnchorPage = f.horizontalAnchor === "page" || f.horizontalAnchor === "margin";
|
|
359
|
+
const vAnchorPage = f.verticalAnchor === "page" || f.verticalAnchor === "margin";
|
|
360
|
+
if (hAnchorPage || vAnchorPage) {
|
|
361
|
+
const styles = ["position:absolute"];
|
|
362
|
+
if (vAnchorPage && f.absoluteVerticalPosition != null) {
|
|
363
|
+
const top = twipToCss(f.absoluteVerticalPosition);
|
|
364
|
+
if (top) styles.push(`top:${top}`);
|
|
365
|
+
}
|
|
366
|
+
if (hAnchorPage) {
|
|
367
|
+
const side = f.relativeHorizontalPosition;
|
|
368
|
+
if (f.absoluteHorizontalPosition != null) {
|
|
369
|
+
const left = twipToCss(f.absoluteHorizontalPosition);
|
|
370
|
+
if (left) styles.push(`left:${left}`);
|
|
371
|
+
} else if (side === "center") styles.push("left:50%", "transform:translateX(-50%)");
|
|
372
|
+
else if (side === "right") styles.push("right:0");
|
|
373
|
+
else styles.push("left:0");
|
|
374
|
+
}
|
|
375
|
+
return styles;
|
|
376
|
+
}
|
|
377
|
+
const side = f.relativeHorizontalPosition;
|
|
378
|
+
if (side === "center" || side === "inside" || side === "outside") return [];
|
|
379
|
+
const floatRight = side === "right";
|
|
380
|
+
const styles = [floatRight ? "float:right" : "float:left"];
|
|
381
|
+
if (f.absoluteHorizontalPosition != null) {
|
|
382
|
+
const off = twipToCss(f.absoluteHorizontalPosition);
|
|
383
|
+
if (off) styles.push(floatRight ? `margin-right:${off}` : `margin-left:${off}`);
|
|
384
|
+
}
|
|
385
|
+
const gapSide = floatRight ? f.leftFromText : f.rightFromText;
|
|
386
|
+
if (gapSide != null) {
|
|
387
|
+
const m = twipToCss(gapSide);
|
|
388
|
+
if (m) styles.push(floatRight ? `margin-left:${m}` : `margin-right:${m}`);
|
|
389
|
+
}
|
|
390
|
+
if (f.topFromText != null) {
|
|
391
|
+
const m = twipToCss(f.topFromText);
|
|
392
|
+
if (m) styles.push(`margin-top:${m}`);
|
|
393
|
+
}
|
|
394
|
+
if (f.bottomFromText != null) {
|
|
395
|
+
const m = twipToCss(f.bottomFromText);
|
|
396
|
+
if (m) styles.push(`margin-bottom:${m}`);
|
|
397
|
+
}
|
|
398
|
+
return styles;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
328
401
|
* Compute all paragraph-level CSS styles from nested attrs.
|
|
329
402
|
* Shared by Paragraph and Heading extensions for node-level renderHTML.
|
|
330
403
|
* Attrs store office-open native values; mappers here convert to CSS.
|
|
@@ -505,4 +578,4 @@ function shadingFromElement(el) {
|
|
|
505
578
|
return shadingFromCss(el.style.backgroundColor || null);
|
|
506
579
|
}
|
|
507
580
|
//#endregion
|
|
508
|
-
export { alignmentFromCss, alignmentFromElement, alignmentToCss, attrNative, bordersFromElement, characterSpacingFromCss, characterSpacingToCss, cssToTwip, floatAnchorScope, floatingToStyles, indentFromElement, lineSpacingToCss, normalizeColorToHex, renderBorderCSS, renderParagraphStyles, renderRunStyles, renderTableCellStyles, resolveFontFamilyCss, resolveFontName, resolvePageSize, sectionLinePitchCss, sectionMarginCss, shadingFromCss, shadingFromElement, shadingToCss, sizeFromCss, sizeToCss, spacingFromElement, twipToCss, twipsToMm };
|
|
581
|
+
export { alignmentFromCss, alignmentFromElement, alignmentToCss, attrNative, bordersFromElement, characterSpacingFromCss, characterSpacingToCss, cssToTwip, floatAnchorScope, floatingToStyles, indentFromElement, lineSpacingToCss, normalizeColorToHex, renderBorderCSS, renderParagraphStyles, renderRunStyles, renderTableCellStyles, resolveFontFamilyCss, resolveFontName, resolvePageSize, sectionLinePitchCss, sectionMarginCss, shadingFromCss, shadingFromElement, shadingToCss, sizeFromCss, sizeToCss, spacingFromElement, tableFloatToCss, twipToCss, twipsToMm };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { WpgGroup, WpsData, WpsShapeStandalone, WpsShapeStyles, renderWpsInterior, renderWpsText, wpsInnerStyle, wpsRotationVert, wpsShapeStyles };
|
|
1
|
+
import { A as WpgGroup, F as renderWpsInterior, I as renderWpsText, L as wpsInnerStyle, M as WpsShapeStandalone, N as WpsShapeStyles, P as parseDocxInline, R as wpsRotationVert, j as WpsData, z as wpsShapeStyles } from "../core-BqyLL84S.mjs";
|
|
2
|
+
export { WpgGroup, WpsData, WpsShapeStandalone, WpsShapeStyles, parseDocxInline, renderWpsInterior, renderWpsText, wpsInnerStyle, wpsRotationVert, wpsShapeStyles };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { WpgGroup, renderWpsInterior, renderWpsText, wpsInnerStyle, wpsRotationVert, wpsShapeStyles };
|
|
1
|
+
import { C as renderWpsText, E as wpsShapeStyles, S as renderWpsInterior, T as wpsRotationVert, b as WpgGroup, w as wpsInnerStyle, x as parseDocxInline } from "../core-wNNPJiKr.mjs";
|
|
2
|
+
export { WpgGroup, parseDocxInline, renderWpsInterior, renderWpsText, wpsInnerStyle, wpsRotationVert, wpsShapeStyles };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { WpsShape };
|
|
1
|
+
import { O as WpsShape, k as parseDocxInline } from "../core-BqyLL84S.mjs";
|
|
2
|
+
export { WpsShape, parseDocxInline };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { WpsShape };
|
|
1
|
+
import { v as WpsShape, y as parseDocxInline } from "../core-wNNPJiKr.mjs";
|
|
2
|
+
export { WpsShape, parseDocxInline };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ParseParagraphRule } from "./extensions/types.mjs";
|
|
2
|
+
import { JSONContent } from "@tiptap/core";
|
|
3
|
+
import { ParagraphOptions, StylesOptions } from "@office-open/docx";
|
|
4
|
+
|
|
5
|
+
//#region src/extensions/heading.d.ts
|
|
6
|
+
/** Heading level (1-9) for a paragraph, or undefined when it isn't a heading.
|
|
7
|
+
* DOCX marks a heading several ways, checked in priority order:
|
|
8
|
+
* 1. office-open lifts a HeadingLevel pStyle ("Heading1".."Title") into `heading`.
|
|
9
|
+
* 2. An explicit `outlineLevel` (0-8 → 1-9) — Word's outline/TOC key off this
|
|
10
|
+
* even without a heading pStyle; the Heading1-9 styles carry outlineLvl 0-8.
|
|
11
|
+
* 3. A pStyle that names a heading style: directly ("Heading7", which stays on
|
|
12
|
+
* `style` because office-open's HeadingLevel type caps at 6), by localized
|
|
13
|
+
* NAME ("heading 1"/"标题 1"), or via the `basedOn` chain (a custom style
|
|
14
|
+
* "MyTitle" basedOn="Heading1"). `heading` and `style` carry the same pStyle.
|
|
15
|
+
* `outlineLevel` is read loosely — office-open's public type omits the field
|
|
16
|
+
* even though it round-trips (w:outlineLvl) at runtime. Pure (no `this`):
|
|
17
|
+
* resolved + the document styles snapshot are all it reads. */
|
|
18
|
+
declare function detectHeadingLevel(resolved: ParagraphOptions, styles: StylesOptions | undefined): number | undefined;
|
|
19
|
+
declare const parseDocxParagraph: ParseParagraphRule;
|
|
20
|
+
declare function renderDocx(node: JSONContent): Record<string, unknown>;
|
|
21
|
+
declare function parseDocx(opts: Record<string, unknown>): Record<string, unknown>;
|
|
22
|
+
declare const Heading: import("@tiptap/core").Node<import("@tiptap/extension-heading").HeadingOptions, any>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { renderDocx as a, parseDocxParagraph as i, detectHeadingLevel as n, parseDocx as r, Heading as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as Subscript, i as Italic, n as Code, o as Superscript, r as Highlight, s as Underline, t as Bold } from "./marks-Dz9Vb22Q.mjs";
|
|
2
2
|
import { n as createDocument, t as Document } from "./document-Cws7XTYL.mjs";
|
|
3
3
|
import { t as Paragraph } from "./paragraph-D8mpHo_o.mjs";
|
|
4
|
-
import { t as Heading } from "./heading-
|
|
4
|
+
import { t as Heading } from "./heading-Bwpa8iZY.mjs";
|
|
5
|
+
import { r as Blockquote } from "./blockquote-D-1aSxEn.mjs";
|
|
5
6
|
import { t as BulletList } from "./bullet-list-DF60pnSL.mjs";
|
|
6
7
|
import { r as OrderedList } from "./ordered-list-DFAe-YEV.mjs";
|
|
7
|
-
import { A as
|
|
8
|
-
import {
|
|
8
|
+
import { A as WpgGroup, B as PageBreak, D as Passthrough, E as InlinePassthrough, H as FormattingMarks, K as Image, M as WpsShapeStandalone, N as WpsShapeStyles, O as WpsShape, Q as ColumnBreak, S as Tab, U as Deletion, W as Insertion, Z as SectionBreak, _ as Text, a as JSONContent, b as tiptapMarkExtensions, c as CodeBlockLowlight, d as Emoji, et as CodeBlock, f as HardBreak, g as TaskList, h as Mathematics, l as DocxKit, m as ListItem, p as HorizontalRule, t as AnyExtension, u as DocxKitOptions, v as TextAlign, w as TocField, x as tiptapNodeExtensions, y as docxExtensions, z as wpsShapeStyles } from "./core-BqyLL84S.mjs";
|
|
9
|
+
import { a as DetailsSummaryBase, i as DetailsContentBase, r as Details } from "./details-DsJhDP5K.mjs";
|
|
10
|
+
import { n as TaskItemBase } from "./task-item-CCAC4QLi.mjs";
|
|
11
|
+
import { n as Mention } from "./mention-CkONDrw9.mjs";
|
|
12
|
+
import { t as Table } from "./table-CdcjR6HD.mjs";
|
|
9
13
|
import { t as TableRow } from "./table-row-kgzYkZlW.mjs";
|
|
10
14
|
import { t as TableCell } from "./table-cell-D_FV4D2h.mjs";
|
|
11
15
|
import { t as TableHeader } from "./table-header-KGQ2aEkP.mjs";
|
|
12
|
-
import { t as Link } from "./link-
|
|
13
|
-
import { t as Strike } from "./strike-
|
|
14
|
-
import { t as TextStyle } from "./text-style-
|
|
15
|
-
import { n as scrollContainerOf, t as scrollCaretToTop } from "./scroll-
|
|
16
|
-
import {
|
|
16
|
+
import { t as Link } from "./link-gUqW45mE.mjs";
|
|
17
|
+
import { t as Strike } from "./strike-Brn9sWFy.mjs";
|
|
18
|
+
import { t as TextStyle } from "./text-style-BzfcbufI.mjs";
|
|
19
|
+
import { n as scrollContainerOf, t as scrollCaretToTop } from "./scroll-BARiZ5Gm.mjs";
|
|
20
|
+
import { S as sectionMarginCss, b as resolvePageSize, j as twipsToMm, x as sectionLinePitchCss, y as resolveFontName } from "./utils-CfwwOowz.mjs";
|
|
17
21
|
import { ImageFetchHandler, PrepareStep, fetchImageHandler, prepareDocument, prepareImages } from "./converters/prepare.mjs";
|
|
18
22
|
import { DocxGenerateOptions, DocxManager, compileDocument, generateDOCX, generateDOCXStream, generateDOCXSync, parseDOCX, resolveDocument } from "./converters/docx.mjs";
|
|
19
23
|
import { generateHTML, parseHTML } from "./converters/html.mjs";
|
|
@@ -153,6 +157,14 @@ interface HardBreakNode {
|
|
|
153
157
|
type: "hardBreak";
|
|
154
158
|
marks?: Mark[];
|
|
155
159
|
}
|
|
160
|
+
/** OOXML track-change metadata (w:ins / w:del). Mirrors office-open's
|
|
161
|
+
* ChangedAttributesProperties: `id` is the w:id (number), `author`/`date` are
|
|
162
|
+
* the revision author and timestamp. */
|
|
163
|
+
interface TrackChangeAttrs {
|
|
164
|
+
id: number | null;
|
|
165
|
+
author: string | null;
|
|
166
|
+
date: string | null;
|
|
167
|
+
}
|
|
156
168
|
type Mark = {
|
|
157
169
|
type: "bold";
|
|
158
170
|
} | {
|
|
@@ -179,6 +191,12 @@ type Mark = {
|
|
|
179
191
|
} | {
|
|
180
192
|
type: "link";
|
|
181
193
|
attrs?: LinkAttrs;
|
|
194
|
+
} | {
|
|
195
|
+
type: "insertion";
|
|
196
|
+
attrs?: TrackChangeAttrs;
|
|
197
|
+
} | {
|
|
198
|
+
type: "deletion";
|
|
199
|
+
attrs?: TrackChangeAttrs;
|
|
182
200
|
};
|
|
183
201
|
interface ParagraphNode extends TiptapJSONContent {
|
|
184
202
|
type: "paragraph";
|
|
@@ -269,7 +287,7 @@ interface ImageNode extends TiptapJSONContent {
|
|
|
269
287
|
/**
|
|
270
288
|
* Drawing group (wpg) carried as an opaque blob — the full WpgGroupRunOptions
|
|
271
289
|
* (pictures/shapes/nested groups + transform) round-trips verbatim. renderHTML
|
|
272
|
-
* lays out every child at its transformed position (
|
|
290
|
+
* lays out every child at its transformed position (Office-style group rendering).
|
|
273
291
|
*/
|
|
274
292
|
interface WpgGroupNode extends TiptapJSONContent {
|
|
275
293
|
type: "wpgGroup";
|
|
@@ -356,4 +374,4 @@ interface DetailsContentNode extends TiptapJSONContent {
|
|
|
356
374
|
type InlineContent = TextNode | HardBreakNode | ImageNode | EmojiNode | PageBreakNode | ColumnBreakNode | TabNode | MentionNode | InlineMathNode | InlinePassthroughNode;
|
|
357
375
|
type BlockNode = ParagraphNode | HeadingNode | BlockquoteNode | CodeBlockNode | HorizontalRuleNode | BulletListNode | OrderedListNode | TaskListNode | TableNode | WpsShapeNode | WpgGroupNode | DetailsNode | TocFieldNode | PassthroughNode | BlockMathNode;
|
|
358
376
|
//#endregion
|
|
359
|
-
export { type AlignmentType, type AnyExtension, type AttrNullable, type BlockMathNode, type BlockNode, Blockquote, type BlockquoteNode, Bold, type BookmarkOptions, type BorderOptions, type BordersOptions, BulletList, type BulletListNode, Code, CodeBlock, CodeBlockLowlight, type CodeBlockNode, ColumnBreak, type ColumnBreakNode, Details, DetailsContent, type DetailsContentNode, type DetailsNode, DetailsSummary, type DetailsSummaryNode, Document, type DocumentOptions, type DocxEditorOptions, type DocxGenerateOptions, DocxKit, DocxKitOptions, DocxManager, type DocxPatchContent, type DocxPatchOptions, Emoji, type EmojiAttrs, type EmojiNode, type EmphasisMarkType, type ExternalHyperlinkOptions, type Floating, type FontAttributesProperties, FormattingMarks, type FrameOptions, HardBreak, type HardBreakNode, type HeaderFooterSlots, Heading, type HeadingLevel, type HeadingNode, type HeightRule, Highlight, type HighlightColor, HorizontalRule, type HorizontalRuleNode, Image, type ImageAttrs, type ImageFetchHandler, type ImageNode, type ImageOptions, type IndentAttributesProperties, type InlineContent, type InlineMathNode, InlinePassthrough, type InlinePassthroughNode, type InternalHyperlinkOptions, Italic, type JSONContent, type LeaderType, type LevelParagraphStylePropertiesOptions, type LineRuleType, Link, type LinkAttrs, ListItem, type ListItemNode, type Margins, type Mark, type MathAttrs, type MathInput, Mathematics, type MediaTransformation, Mention, type MentionAttrs, type MentionNode, OrderedList, type OrderedListNode, PageBreak, type PageBreakNode, Paragraph, type ParagraphAttrs, type ParagraphChild, type ParagraphNode, type ParagraphOptions, type ParagraphPropertiesOptions, type ParagraphPropertiesOptionsBase, type ParagraphRunPropertiesOptions, type ParagraphStylePropertiesOptions, Passthrough, type PassthroughNode, type PrepareStep, type QuickStyleEntry, type RubyOptions, type RunOptions, type RunPropertiesOptions, type RunStylePropertiesOptions, SectionBreak, type SectionChild, type SectionOptions, type SectionPropertiesOptions, type ShadingAttributesProperties, type SpacingProperties, Strike, type StrikeAttrs, type StylesOptions, Subscript, Superscript, Tab, type TabNode, type TabStopDefinition, type TabStopPosition, type TabStopType, Table, type TableAttrs, type TableBordersOptions, TableCell, type TableCellAttrs, type TableCellBordersOptions, type TableCellNode, type TableCellOptions, type TableFloatOptions, TableHeader, type TableHeaderNode, type TableLayoutType, type TableLookOptions, type TableNode, type TableOptions, TableRow, type TableRowAttrs, type TableRowNode, type TableRowOptions, type TableRowPropertiesOptionsBase, type TableVerticalAlign, type TableWidthProperties, TaskItem, type TaskItemNode, TaskList, type TaskListNode, Text, TextAlign, type TextAlignmentType, type TextNode, TextStyle, type TextStyleAttrs, TocField, type TocFieldNode, Underline, type UnderlineType, type WidthType, WpgGroup, type WpgGroupNode, WpsShape, type WpsShapeNode, type WpsShapeStandalone, type WpsShapeStyles, compileDocument, convertMillimetersToTwip, createDocument, createDocxEditor, docxExtensions, effectiveRunProps, fetchImageHandler, generateDOCX, generateDOCXStream, generateDOCXSync, generateHTML, generateMarkdown, inlineStyles, parseDOCX, parseHTML, parseMarkdown, patchDOCX, prepareDocument, prepareImages, quickStyles, resolveDocument, resolveFontName, resolvePageSize, scrollCaretToTop, scrollContainerOf, sectionLinePitchCss, sectionMarginCss, sectionMarginDefaults, sectionPageSizeDefaults, stylesToCss, tiptapMarkExtensions, tiptapNodeExtensions, twipsToMm, wpsShapeStyles };
|
|
377
|
+
export { type AlignmentType, type AnyExtension, type AttrNullable, type BlockMathNode, type BlockNode, Blockquote, type BlockquoteNode, Bold, type BookmarkOptions, type BorderOptions, type BordersOptions, BulletList, type BulletListNode, Code, CodeBlock, CodeBlockLowlight, type CodeBlockNode, ColumnBreak, type ColumnBreakNode, Deletion, Details, DetailsContentBase as DetailsContent, type DetailsContentNode, type DetailsNode, DetailsSummaryBase as DetailsSummary, type DetailsSummaryNode, Document, type DocumentOptions, type DocxEditorOptions, type DocxGenerateOptions, DocxKit, DocxKitOptions, DocxManager, type DocxPatchContent, type DocxPatchOptions, Emoji, type EmojiAttrs, type EmojiNode, type EmphasisMarkType, type ExternalHyperlinkOptions, type Floating, type FontAttributesProperties, FormattingMarks, type FrameOptions, HardBreak, type HardBreakNode, type HeaderFooterSlots, Heading, type HeadingLevel, type HeadingNode, type HeightRule, Highlight, type HighlightColor, HorizontalRule, type HorizontalRuleNode, Image, type ImageAttrs, type ImageFetchHandler, type ImageNode, type ImageOptions, type IndentAttributesProperties, type InlineContent, type InlineMathNode, InlinePassthrough, type InlinePassthroughNode, Insertion, type InternalHyperlinkOptions, Italic, type JSONContent, type LeaderType, type LevelParagraphStylePropertiesOptions, type LineRuleType, Link, type LinkAttrs, ListItem, type ListItemNode, type Margins, type Mark, type MathAttrs, type MathInput, Mathematics, type MediaTransformation, Mention, type MentionAttrs, type MentionNode, OrderedList, type OrderedListNode, PageBreak, type PageBreakNode, Paragraph, type ParagraphAttrs, type ParagraphChild, type ParagraphNode, type ParagraphOptions, type ParagraphPropertiesOptions, type ParagraphPropertiesOptionsBase, type ParagraphRunPropertiesOptions, type ParagraphStylePropertiesOptions, Passthrough, type PassthroughNode, type PrepareStep, type QuickStyleEntry, type RubyOptions, type RunOptions, type RunPropertiesOptions, type RunStylePropertiesOptions, SectionBreak, type SectionChild, type SectionOptions, type SectionPropertiesOptions, type ShadingAttributesProperties, type SpacingProperties, Strike, type StrikeAttrs, type StylesOptions, Subscript, Superscript, Tab, type TabNode, type TabStopDefinition, type TabStopPosition, type TabStopType, Table, type TableAttrs, type TableBordersOptions, TableCell, type TableCellAttrs, type TableCellBordersOptions, type TableCellNode, type TableCellOptions, type TableFloatOptions, TableHeader, type TableHeaderNode, type TableLayoutType, type TableLookOptions, type TableNode, type TableOptions, TableRow, type TableRowAttrs, type TableRowNode, type TableRowOptions, type TableRowPropertiesOptionsBase, type TableVerticalAlign, type TableWidthProperties, TaskItemBase as TaskItem, type TaskItemNode, TaskList, type TaskListNode, Text, TextAlign, type TextAlignmentType, type TextNode, TextStyle, type TextStyleAttrs, TocField, type TocFieldNode, type TrackChangeAttrs, Underline, type UnderlineType, type WidthType, WpgGroup, type WpgGroupNode, WpsShape, type WpsShapeNode, type WpsShapeStandalone, type WpsShapeStyles, compileDocument, convertMillimetersToTwip, createDocument, createDocxEditor, docxExtensions, effectiveRunProps, fetchImageHandler, generateDOCX, generateDOCXStream, generateDOCXSync, generateHTML, generateMarkdown, inlineStyles, parseDOCX, parseHTML, parseMarkdown, patchDOCX, prepareDocument, prepareImages, quickStyles, resolveDocument, resolveFontName, resolvePageSize, scrollCaretToTop, scrollContainerOf, sectionLinePitchCss, sectionMarginCss, sectionMarginDefaults, sectionPageSizeDefaults, stylesToCss, tiptapMarkExtensions, tiptapNodeExtensions, twipsToMm, wpsShapeStyles };
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveFontName, resolvePageSize, sectionLinePitchCss, sectionMarginCss, twipsToMm } from "./extensions/utils.mjs";
|
|
2
|
+
import { effectiveRunProps, inlineStyles, quickStyles, stylesToCss } from "./converters/styles.mjs";
|
|
3
|
+
import { Blockquote } from "./extensions/blockquote.mjs";
|
|
2
4
|
import { BulletList } from "./extensions/bullet-list.mjs";
|
|
3
5
|
import { CodeBlock } from "./extensions/code-block.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
+
import { B as FormattingMarks, D as Deletion, E as wpsShapeStyles, F as Passthrough, I as PageBreak, N as SectionBreak, O as Insertion, P as InlinePassthrough, V as ColumnBreak, _ as tiptapNodeExtensions, a as CodeBlockLowlight, b as WpgGroup, c as HardBreak, d as Mathematics, f as TaskList, g as tiptapMarkExtensions, h as docxExtensions, j as Tab, k as TocField, l as HorizontalRule, m as TextAlign, o as DocxKit, p as Text, s as Emoji, u as ListItem, v as WpsShape } from "./core-wNNPJiKr.mjs";
|
|
7
|
+
import { Details, DetailsContent as DetailsContentBase, DetailsSummary as DetailsSummaryBase } from "./extensions/details.mjs";
|
|
6
8
|
import { Document, createDocument } from "./extensions/document.mjs";
|
|
7
9
|
import { Heading } from "./extensions/heading.mjs";
|
|
8
10
|
import { Image } from "./extensions/image.mjs";
|
|
9
11
|
import { scrollCaretToTop, scrollContainerOf } from "./extensions/scroll.mjs";
|
|
10
12
|
import { Link } from "./extensions/link.mjs";
|
|
13
|
+
import { TaskItem as TaskItemBase } from "./extensions/task-item.mjs";
|
|
14
|
+
import { Bold, Code, Highlight, Italic, Subscript, Superscript, Underline } from "./extensions/marks.mjs";
|
|
15
|
+
import { Mention } from "./extensions/mention.mjs";
|
|
11
16
|
import { OrderedList } from "./extensions/ordered-list.mjs";
|
|
12
17
|
import { Paragraph } from "./extensions/paragraph.mjs";
|
|
13
18
|
import { Strike } from "./extensions/strike.mjs";
|
|
@@ -18,11 +23,10 @@ import { TableRow } from "./extensions/table-row.mjs";
|
|
|
18
23
|
import { TextStyle } from "./extensions/text-style.mjs";
|
|
19
24
|
import { createDocxEditor } from "./editor.mjs";
|
|
20
25
|
import { fetchImageHandler, prepareDocument, prepareImages } from "./converters/prepare.mjs";
|
|
21
|
-
import { effectiveRunProps, inlineStyles, quickStyles, stylesToCss } from "./converters/styles.mjs";
|
|
22
26
|
import { DocxManager, compileDocument, generateDOCX, generateDOCXStream, generateDOCXSync, parseDOCX, resolveDocument } from "./converters/docx.mjs";
|
|
23
27
|
import { patchDOCX } from "./converters/patch.mjs";
|
|
24
28
|
import { generateHTML, parseHTML } from "./converters/html.mjs";
|
|
25
29
|
import { generateMarkdown, parseMarkdown } from "./converters/markdown.mjs";
|
|
26
30
|
import { sectionMarginDefaults, sectionPageSizeDefaults } from "@office-open/docx";
|
|
27
31
|
import { convertMillimetersToTwip } from "@office-open/core";
|
|
28
|
-
export { Blockquote, Bold, BulletList, Code, CodeBlock, CodeBlockLowlight, ColumnBreak, Details, DetailsContent, DetailsSummary, Document, DocxKit, DocxManager, Emoji, FormattingMarks, HardBreak, Heading, Highlight, HorizontalRule, Image, InlinePassthrough, Italic, Link, ListItem, Mathematics, Mention, OrderedList, PageBreak, Paragraph, Passthrough, SectionBreak, Strike, Subscript, Superscript, Tab, Table, TableCell, TableHeader, TableRow, TaskItem, TaskList, Text, TextAlign, TextStyle, TocField, Underline, WpgGroup, WpsShape, compileDocument, convertMillimetersToTwip, createDocument, createDocxEditor, docxExtensions, effectiveRunProps, fetchImageHandler, generateDOCX, generateDOCXStream, generateDOCXSync, generateHTML, generateMarkdown, inlineStyles, parseDOCX, parseHTML, parseMarkdown, patchDOCX, prepareDocument, prepareImages, quickStyles, resolveDocument, resolveFontName, resolvePageSize, scrollCaretToTop, scrollContainerOf, sectionLinePitchCss, sectionMarginCss, sectionMarginDefaults, sectionPageSizeDefaults, stylesToCss, tiptapMarkExtensions, tiptapNodeExtensions, twipsToMm, wpsShapeStyles };
|
|
32
|
+
export { Blockquote, Bold, BulletList, Code, CodeBlock, CodeBlockLowlight, ColumnBreak, Deletion, Details, DetailsContentBase as DetailsContent, DetailsSummaryBase as DetailsSummary, Document, DocxKit, DocxManager, Emoji, FormattingMarks, HardBreak, Heading, Highlight, HorizontalRule, Image, InlinePassthrough, Insertion, Italic, Link, ListItem, Mathematics, Mention, OrderedList, PageBreak, Paragraph, Passthrough, SectionBreak, Strike, Subscript, Superscript, Tab, Table, TableCell, TableHeader, TableRow, TaskItemBase as TaskItem, TaskList, Text, TextAlign, TextStyle, TocField, Underline, WpgGroup, WpsShape, compileDocument, convertMillimetersToTwip, createDocument, createDocxEditor, docxExtensions, effectiveRunProps, fetchImageHandler, generateDOCX, generateDOCXStream, generateDOCXSync, generateHTML, generateMarkdown, inlineStyles, parseDOCX, parseHTML, parseMarkdown, patchDOCX, prepareDocument, prepareImages, quickStyles, resolveDocument, resolveFontName, resolvePageSize, scrollCaretToTop, scrollContainerOf, sectionLinePitchCss, sectionMarginCss, sectionMarginDefaults, sectionPageSizeDefaults, stylesToCss, tiptapMarkExtensions, tiptapNodeExtensions, twipsToMm, wpsShapeStyles };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { ParseInlineRule } from "./extensions/types.mjs";
|
|
1
2
|
import { LinkOptions } from "@tiptap/extension-link";
|
|
2
3
|
|
|
3
4
|
//#region src/extensions/link.d.ts
|
|
5
|
+
declare const parseDocxInline: ParseInlineRule;
|
|
4
6
|
declare const Link$1: import("@tiptap/core").Mark<LinkOptions, any>;
|
|
5
7
|
//#endregion
|
|
6
|
-
export { Link$1 as t };
|
|
8
|
+
export { parseDocxInline as n, Link$1 as t };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/extensions/marks.d.ts
|
|
2
|
+
declare const Bold: import("@tiptap/core").Mark<import("@tiptap/extension-bold").BoldOptions, any>;
|
|
3
|
+
declare const Italic: import("@tiptap/core").Mark<import("@tiptap/extension-italic").ItalicOptions, any>;
|
|
4
|
+
declare const Underline: import("@tiptap/core").Mark<import("@tiptap/extension-underline").UnderlineOptions, any>;
|
|
5
|
+
declare const Code: import("@tiptap/core").Mark<import("@tiptap/extension-code").CodeOptions, any>;
|
|
6
|
+
declare const Highlight: import("@tiptap/core").Mark<import("@tiptap/extension-highlight").HighlightOptions, any>;
|
|
7
|
+
declare const Subscript: import("@tiptap/core").Mark<import("@tiptap/extension-subscript").SubscriptExtensionOptions, any>;
|
|
8
|
+
declare const Superscript: import("@tiptap/core").Mark<import("@tiptap/extension-superscript").SuperscriptExtensionOptions, any>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { Subscript as a, Italic as i, Code as n, Superscript as o, Highlight as r, Underline as s, Bold as t };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ParseInlineRule } from "./extensions/types.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/extensions/mention.d.ts
|
|
2
4
|
/**
|
|
3
5
|
* Mention extension — owns the DOCX expression of an inline mention.
|
|
@@ -19,5 +21,7 @@ declare function readMention(child: unknown): {
|
|
|
19
21
|
id: string;
|
|
20
22
|
label: string;
|
|
21
23
|
};
|
|
24
|
+
declare const parseDocxInline: ParseInlineRule;
|
|
25
|
+
declare const Mention: import("@tiptap/core").Node<import("@tiptap/extension-mention").MentionOptions<any, import("@tiptap/extension-mention").MentionNodeAttrs>, any>;
|
|
22
26
|
//#endregion
|
|
23
|
-
export {
|
|
27
|
+
export { parseDocxInline as a, isMention as i, Mention as n, readMention as o, createMention as r, MENTION_TAG as t };
|
|
@@ -5,14 +5,20 @@ import { EditorView } from "@tiptap/pm/view";
|
|
|
5
5
|
* Scroll helpers shared by the editor and the docx engine's link-click handler,
|
|
6
6
|
* so every "jump then scroll" path (outline heading, search result, find, TOC
|
|
7
7
|
* Ctrl+Click, post-reflow caret follow) scrolls the SAME way — to the top of the
|
|
8
|
-
* viewport,
|
|
8
|
+
* viewport, Office-style. ProseMirror's default `tr.scrollIntoView()` parks the
|
|
9
9
|
* caret at the bottom edge, which reads wrong for a page/heading/TOC jump.
|
|
10
10
|
*/
|
|
11
11
|
/** Nearest scrollable ancestor of the editor surface (e.g. the docen-canvas). */
|
|
12
12
|
declare function scrollContainerOf(view: EditorView): HTMLElement | null;
|
|
13
13
|
/** Scroll the caret to the TOP of the viewport when it has left the visible area
|
|
14
|
-
* (
|
|
15
|
-
* typing doesn't fight the user's scroll. Replaces PM's default scrollIntoView.
|
|
14
|
+
* (Office-style page follow). No-op while the caret stays in view, so normal
|
|
15
|
+
* typing doesn't fight the user's scroll. Replaces PM's default scrollIntoView.
|
|
16
|
+
*
|
|
17
|
+
* Follows the caret's PAGE, not the caret itself: a caret near a page's bottom
|
|
18
|
+
* edge (e.g. after a select-all delete leaves the caret at the end of an
|
|
19
|
+
* otherwise-empty page) would otherwise park that page's lower half in view,
|
|
20
|
+
* which reads as "scrolled to the bottom." Anchoring on the page top keeps the
|
|
21
|
+
* page's start in view. Falls back to the caret position outside C-route. */
|
|
16
22
|
declare function scrollCaretToTop(view: EditorView): void;
|
|
17
23
|
//#endregion
|
|
18
24
|
export { scrollContainerOf as n, scrollCaretToTop as t };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/extensions/strike.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Strike mark extension with nested office-open attrs.
|
|
4
|
+
*
|
|
5
|
+
* OOXML represents strikethrough on a run via two mutually exclusive booleans:
|
|
6
|
+
* `strike` (single) and `doubleStrike` (double). The mark itself is "single
|
|
7
|
+
* strikethrough"; the `doubleStrike` attr flips it to double. DOCX round-trip
|
|
8
|
+
* is near-identity for the doubleStrike flag; `strike` itself is implied by the
|
|
9
|
+
* mark's presence.
|
|
10
|
+
*
|
|
11
|
+
* Mark attribute-level renderHTML is delegated to the base Strike extension
|
|
12
|
+
* (renders `<s>`); only the DOCX flag needs custom handling.
|
|
13
|
+
*/
|
|
14
|
+
declare const Strike: import("@tiptap/core").Mark<import("@tiptap/extension-strike").StrikeOptions, any>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { Strike as t };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ParseBlockRule } from "./extensions/types.mjs";
|
|
2
|
+
import { JSONContent } from "@tiptap/core";
|
|
3
|
+
import { TableOptions } from "@office-open/docx";
|
|
4
|
+
|
|
5
|
+
//#region src/extensions/table.d.ts
|
|
6
|
+
declare function renderDocx(node: JSONContent): Partial<TableOptions>;
|
|
7
|
+
declare function parseDocx(opts: Record<string, unknown>): Record<string, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* Declarative block parse rule: recognize a table SectionChild and rebuild it
|
|
10
|
+
* as a Tiptap table node (rows/cells with colspan/rowspan recovered, the table
|
|
11
|
+
* style's tblBorders/tblCellMar merged in, insideH/V grid lines pushed onto
|
|
12
|
+
* cells, gridAfter as trailing nil-bordered cells). DocxManager dispatches
|
|
13
|
+
* every SectionChild through this rule before the paragraph/passthrough
|
|
14
|
+
* fallbacks. */
|
|
15
|
+
declare const parseDocxBlock: ParseBlockRule;
|
|
16
|
+
declare const Table: import("@tiptap/core").Node<import("@tiptap/extension-table").TableOptions, any>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { renderDocx as i, parseDocx as n, parseDocxBlock as r, Table as t };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { TaskItem as TaskItemBase } from "@tiptap/extension-task-item";
|
|
2
|
+
|
|
1
3
|
//#region src/extensions/task-item.d.ts
|
|
2
4
|
/**
|
|
3
5
|
* TaskItem extension — owns the DOCX expression of a task-list checkbox.
|
|
@@ -22,4 +24,4 @@ declare function isTaskCheckbox(child: unknown): boolean;
|
|
|
22
24
|
/** Read the checked state of a task checkbox SDT child (false if not one). */
|
|
23
25
|
declare function readCheckboxState(child: unknown): boolean;
|
|
24
26
|
//#endregion
|
|
25
|
-
export { readCheckboxState as i,
|
|
27
|
+
export { readCheckboxState as a, isTaskCheckbox as i, TaskItemBase as n, createTaskCheckbox as r, TASK_CHECKBOX_TAG as t };
|
|
@@ -105,6 +105,30 @@ declare function floatingToStyles(floating: unknown, src?: string, width?: numbe
|
|
|
105
105
|
* relevant for wrapNone (type 0); the float-based wraps stay inline.
|
|
106
106
|
*/
|
|
107
107
|
declare function floatAnchorScope(floating: unknown): "paragraph" | "page";
|
|
108
|
+
/**
|
|
109
|
+
* Render a table's float anchor (w:tblpPr → TableFloatOptions) to CSS.
|
|
110
|
+
*
|
|
111
|
+
* Unlike a drawing's Floating (wp:anchor, EMU offsets, wrap types), a floating
|
|
112
|
+
* table carries no wrap type — Word's "text wrapping" around a table is plain
|
|
113
|
+
* CSS float with margins. Twips (not EMU) throughout: tblpX/Y and the fromText
|
|
114
|
+
* gaps are dxa.
|
|
115
|
+
*
|
|
116
|
+
* Two render modes:
|
|
117
|
+
* - text-anchored wrap (horizontalAnchor=text) → CSS float + margins, so body
|
|
118
|
+
* text flows beside the table. tblpX → margin on the float side; fromText →
|
|
119
|
+
* the opposite side + top/bottom (mirrors floatingToStyles so the offset and
|
|
120
|
+
* the wrap gap never compete for the same margin edge).
|
|
121
|
+
* - page/margin anchor → position:absolute pinned to the page box, floating at
|
|
122
|
+
* the offset/alignment like Word's page-anchored table. .docen-page is
|
|
123
|
+
* position:relative and its padding box is the physical page (no border), so
|
|
124
|
+
* top:0/left:0 matches OOXML's page origin; symmetric page padding makes
|
|
125
|
+
* left:50% the content-box center too, so a margin anchor centers alike.
|
|
126
|
+
* - text-anchored center/inside/outside have no CSS float equivalent (and
|
|
127
|
+
* inside/outside need odd/even pages the editor lacks) → degraded to [].
|
|
128
|
+
* attrs still round-trip byte-faithful via renderDocx/parseDocx passthrough.
|
|
129
|
+
* - overlap (neverOverlap) has no CSS float equivalent; ignored.
|
|
130
|
+
*/
|
|
131
|
+
declare function tableFloatToCss(float: unknown): string[];
|
|
108
132
|
/**
|
|
109
133
|
* Compute all paragraph-level CSS styles from nested attrs.
|
|
110
134
|
* Shared by Paragraph and Heading extensions for node-level renderHTML.
|
|
@@ -134,4 +158,4 @@ declare function bordersFromElement(el: HTMLElement): BordersOptions | null;
|
|
|
134
158
|
/** Parse background-color → OOXML shading. */
|
|
135
159
|
declare function shadingFromElement(el: HTMLElement): ShadingAttributesProperties | null;
|
|
136
160
|
//#endregion
|
|
137
|
-
export {
|
|
161
|
+
export { twipToCss as A, shadingFromCss as C, sizeToCss as D, sizeFromCss as E, spacingFromElement as O, sectionMarginCss as S, shadingToCss as T, renderTableCellStyles as _, bordersFromElement as a, resolvePageSize as b, cssToTwip as c, indentFromElement as d, lineSpacingToCss as f, renderRunStyles as g, renderParagraphStyles as h, attrNative as i, twipsToMm as j, tableFloatToCss as k, floatAnchorScope as l, renderBorderCSS as m, alignmentFromElement as n, characterSpacingFromCss as o, normalizeColorToHex as p, alignmentToCss as r, characterSpacingToCss as s, alignmentFromCss as t, floatingToStyles as u, resolveFontFamilyCss as v, shadingFromElement as w, sectionLinePitchCss as x, resolveFontName as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docen/docx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "DOCX editor and converter powered by @office-open/docx with Tiptap editing layer, supporting bidirectional conversion between DOCX, HTML, and Markdown",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"converter",
|