@docen/docx 0.3.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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +156 -0
  3. package/dist/converters/docx.d.mts +110 -0
  4. package/dist/converters/docx.mjs +624 -0
  5. package/dist/converters/html.d.mts +14 -0
  6. package/dist/converters/html.mjs +18 -0
  7. package/dist/converters/markdown.d.mts +13 -0
  8. package/dist/converters/markdown.mjs +18 -0
  9. package/dist/converters/patch.d.mts +53 -0
  10. package/dist/converters/patch.mjs +37 -0
  11. package/dist/converters/prepare.d.mts +51 -0
  12. package/dist/converters/prepare.mjs +76 -0
  13. package/dist/core-CFIQVRfx.mjs +88 -0
  14. package/dist/core-omBKMRtl.d.mts +34 -0
  15. package/dist/core.d.mts +2 -0
  16. package/dist/core.mjs +2 -0
  17. package/dist/editor.d.mts +21 -0
  18. package/dist/editor.mjs +20 -0
  19. package/dist/extensions/extensions.d.mts +12 -0
  20. package/dist/extensions/extensions.mjs +12 -0
  21. package/dist/extensions/heading.d.mts +2 -0
  22. package/dist/extensions/heading.mjs +145 -0
  23. package/dist/extensions/image.d.mts +2 -0
  24. package/dist/extensions/image.mjs +201 -0
  25. package/dist/extensions/index.d.mts +2 -0
  26. package/dist/extensions/index.mjs +2 -0
  27. package/dist/extensions/paragraph.d.mts +2 -0
  28. package/dist/extensions/paragraph.mjs +116 -0
  29. package/dist/extensions/strike.d.mts +2 -0
  30. package/dist/extensions/strike.mjs +50 -0
  31. package/dist/extensions/table-cell.d.mts +2 -0
  32. package/dist/extensions/table-cell.mjs +112 -0
  33. package/dist/extensions/table-header.d.mts +2 -0
  34. package/dist/extensions/table-header.mjs +112 -0
  35. package/dist/extensions/table-row.d.mts +2 -0
  36. package/dist/extensions/table-row.mjs +84 -0
  37. package/dist/extensions/table.d.mts +2 -0
  38. package/dist/extensions/table.mjs +134 -0
  39. package/dist/extensions/text-style.d.mts +2 -0
  40. package/dist/extensions/text-style.mjs +134 -0
  41. package/dist/extensions/tiptap.d.mts +2 -0
  42. package/dist/extensions/tiptap.mjs +33 -0
  43. package/dist/extensions/types.d.mts +30 -0
  44. package/dist/extensions/utils.d.mts +49 -0
  45. package/dist/extensions/utils.mjs +289 -0
  46. package/dist/heading-BvqBD2zX.d.mts +8 -0
  47. package/dist/image-Ge1y6uam.d.mts +47 -0
  48. package/dist/index.d.mts +213 -0
  49. package/dist/index.mjs +8 -0
  50. package/dist/paragraph-fhEXtAN2.d.mts +16 -0
  51. package/dist/strike-BgWGvjKr.d.mts +33 -0
  52. package/dist/table-BFkfeRp9.d.mts +9 -0
  53. package/dist/table-cell-D_FV4D2h.d.mts +8 -0
  54. package/dist/table-header-KGQ2aEkP.d.mts +8 -0
  55. package/dist/table-row-kgzYkZlW.d.mts +9 -0
  56. package/dist/text-style-BHdtXkMb.d.mts +8 -0
  57. package/dist/tiptap-TErPjuNJ.d.mts +33 -0
  58. package/package.json +106 -0
@@ -0,0 +1,289 @@
1
+ //#region src/extensions/utils.ts
2
+ /** Common CSS named colors → hex */
3
+ const CSS_COLORS = {
4
+ black: "#000000",
5
+ white: "#FFFFFF",
6
+ red: "#FF0000",
7
+ green: "#008000",
8
+ blue: "#0000FF",
9
+ yellow: "#FFFF00",
10
+ cyan: "#00FFFF",
11
+ magenta: "#FF00FF",
12
+ gray: "#808080",
13
+ grey: "#808080",
14
+ orange: "#FFA500",
15
+ purple: "#800080",
16
+ pink: "#FFC0CB",
17
+ brown: "#A52A2A",
18
+ lime: "#00FF00",
19
+ navy: "#000080",
20
+ teal: "#008080",
21
+ silver: "#C0C0C0",
22
+ maroon: "#800000",
23
+ olive: "#808000",
24
+ aqua: "#00FFFF",
25
+ fuchsia: "#FF00FF",
26
+ indigo: "#4B0082",
27
+ violet: "#EE82EE",
28
+ coral: "#FF7F50",
29
+ gold: "#FFD700",
30
+ salmon: "#FA8072",
31
+ tomato: "#FF6347"
32
+ };
33
+ /** Normalize a CSS color value to hex (e.g., "red" → "#FF0000", "#ff0000" → "#FF0000"). */
34
+ function normalizeColorToHex(color) {
35
+ if (!color) return void 0;
36
+ if (color.startsWith("#")) return color.length === 4 ? `#${color[1]}${color[1]}${color[2]}${color[2]}${color[3]}${color[3]}`.toUpperCase() : color.toUpperCase();
37
+ if (/^[0-9A-Fa-f]{6}$/.test(color)) return `#${color.toUpperCase()}`;
38
+ if (/^[0-9A-Fa-f]{3}$/.test(color)) return `#${color[0]}${color[0]}${color[1]}${color[1]}${color[2]}${color[2]}`.toUpperCase();
39
+ return CSS_COLORS[color.toLowerCase()] ?? void 0;
40
+ }
41
+ /** Resolve a font value (string or OOXML rFonts { ascii, eastAsia, hAnsi, cs }) to a CSS family name. */
42
+ function resolveFontName(font) {
43
+ if (!font) return null;
44
+ if (typeof font === "string") return font;
45
+ if (typeof font === "object") {
46
+ const f = font;
47
+ return f.ascii || f.hAnsi || f.eastAsia || null;
48
+ }
49
+ return null;
50
+ }
51
+ /** CSS value (e.g., "18pt") → twip number. 1 pt = 20 twips, 1 px = 15 twips (96 DPI). */
52
+ function cssToTwip(value) {
53
+ if (!value) return void 0;
54
+ const match = value.match(/^([\d.]+)(pt|px|em|cm|in)?$/);
55
+ if (!match) return void 0;
56
+ const num = parseFloat(match[1]);
57
+ switch (match[2] ?? "pt") {
58
+ case "pt": return Math.round(num * 20);
59
+ case "px": return Math.round(num * 15);
60
+ case "in": return Math.round(num * 1440);
61
+ case "cm": return Math.round(num * 567);
62
+ case "em": return Math.round(num * 240);
63
+ default: return Math.round(num * 20);
64
+ }
65
+ }
66
+ /** Twip value → CSS string (e.g., 360 → "18pt"). */
67
+ function twipToCss(value) {
68
+ if (value == null) return null;
69
+ if (typeof value === "string") return value;
70
+ return `${value / 20}pt`;
71
+ }
72
+ const ALIGNMENT_TO_CSS = {
73
+ left: "left",
74
+ center: "center",
75
+ right: "right",
76
+ start: "start",
77
+ end: "end",
78
+ both: "justify",
79
+ distribute: "justify"
80
+ };
81
+ const CSS_TO_ALIGNMENT = {
82
+ left: "left",
83
+ center: "center",
84
+ right: "right",
85
+ start: "start",
86
+ end: "end",
87
+ justify: "both"
88
+ };
89
+ /** OOXML alignment → CSS text-align. */
90
+ function alignmentToCss(alignment) {
91
+ if (!alignment) return null;
92
+ return ALIGNMENT_TO_CSS[alignment] ?? null;
93
+ }
94
+ /** CSS text-align → OOXML alignment. */
95
+ function alignmentFromCss(css) {
96
+ if (!css) return null;
97
+ return CSS_TO_ALIGNMENT[css] ?? null;
98
+ }
99
+ /** Shading.fill → CSS background-color hex. */
100
+ function shadingToCss(shading) {
101
+ if (!shading?.fill) return null;
102
+ return normalizeColorToHex(shading.fill) ?? null;
103
+ }
104
+ /** CSS background-color → ShadingAttributesProperties (fill normalized to hex). */
105
+ function shadingFromCss(css) {
106
+ const hex = normalizeColorToHex(css ?? void 0);
107
+ return hex ? {
108
+ fill: hex,
109
+ type: "clear"
110
+ } : null;
111
+ }
112
+ function lineSpacingToCss(spacing) {
113
+ if (!spacing?.line) return null;
114
+ const rule = spacing.lineRule;
115
+ if (rule === "exact" || rule === "exactly" || rule === "atLeast") return `${spacing.line / 20}pt`;
116
+ const multiple = Number((spacing.line / 240).toFixed(2));
117
+ return String(multiple);
118
+ }
119
+ function sizeToCss(size) {
120
+ if (size == null) return null;
121
+ return `${size}pt`;
122
+ }
123
+ function sizeFromCss(css) {
124
+ if (!css) return null;
125
+ const m = css.match(/^([\d.]+)(pt|px)?$/);
126
+ if (!m) return null;
127
+ const num = parseFloat(m[1]);
128
+ return (m[2] ?? "pt") === "px" ? num * .75 : num;
129
+ }
130
+ function characterSpacingToCss(spacing) {
131
+ if (spacing == null) return null;
132
+ return `${spacing / 20}pt`;
133
+ }
134
+ function characterSpacingFromCss(css) {
135
+ if (!css) return null;
136
+ const m = css.match(/^(-?[\d.]+)pt$/);
137
+ return m ? Math.round(parseFloat(m[1]) * 20) : null;
138
+ }
139
+ /** Render a BorderOptions to CSS string. OOXML border.size is in eighths of a point. */
140
+ function renderBorderCSS(border) {
141
+ if (!border || border.style === "none") return null;
142
+ const size = border.size != null ? `${border.size / 8}pt` : "1pt";
143
+ const cssStyle = {
144
+ single: "solid",
145
+ dashed: "dashed",
146
+ dotted: "dotted",
147
+ double: "double",
148
+ dotDash: "dashed",
149
+ dotDotDash: "dotted"
150
+ }[border.style || "single"] || "solid";
151
+ const hex = border.color && border.color !== "auto" ? normalizeColorToHex(border.color) : null;
152
+ return hex ? `${cssStyle} ${size} ${hex}` : `${cssStyle} ${size}`;
153
+ }
154
+ /**
155
+ * Compute all paragraph-level CSS styles from nested attrs.
156
+ * Shared by Paragraph and Heading extensions for node-level renderHTML.
157
+ * Attrs store office-open native values; mappers here convert to CSS.
158
+ */
159
+ function renderParagraphStyles(attrs) {
160
+ const a = attrs;
161
+ const styles = [];
162
+ const align = alignmentToCss(a.alignment);
163
+ if (align) styles.push(`text-align:${align}`);
164
+ if (a.indent) {
165
+ const left = twipToCss(a.indent.left);
166
+ if (left) styles.push(`margin-left:${left}`);
167
+ const right = twipToCss(a.indent.right);
168
+ if (right) styles.push(`margin-right:${right}`);
169
+ if (a.indent.firstLine != null) {
170
+ const fl = twipToCss(a.indent.firstLine);
171
+ if (fl) styles.push(`text-indent:${fl}`);
172
+ } else if (a.indent.hanging != null) {
173
+ const h = twipToCss(a.indent.hanging);
174
+ if (h) styles.push(`text-indent:-${h}`);
175
+ } else if (a.indent.firstLineChars != null) styles.push(`text-indent:${a.indent.firstLineChars / 100}em`);
176
+ }
177
+ if (a.spacing) {
178
+ const before = twipToCss(a.spacing.before);
179
+ if (before) styles.push(`margin-top:${before}`);
180
+ const after = twipToCss(a.spacing.after);
181
+ if (after) styles.push(`margin-bottom:${after}`);
182
+ const lh = lineSpacingToCss(a.spacing);
183
+ if (lh) styles.push(`line-height:${lh}`);
184
+ }
185
+ const bg = shadingToCss(a.shading);
186
+ if (bg) styles.push(`background-color:${bg}`);
187
+ if (a.border) {
188
+ const sides = [
189
+ ["top", a.border.top],
190
+ ["bottom", a.border.bottom],
191
+ ["left", a.border.left],
192
+ ["right", a.border.right]
193
+ ];
194
+ for (const [side, b] of sides) {
195
+ const css = b ? renderBorderCSS(b) : null;
196
+ if (css) styles.push(`border-${side}:${css}`);
197
+ }
198
+ }
199
+ return styles;
200
+ }
201
+ /**
202
+ * Compute table cell CSS styles from nested attrs.
203
+ * Shared by TableCell and TableHeader extensions.
204
+ */
205
+ function renderTableCellStyles(attrs) {
206
+ const a = attrs;
207
+ const styles = [];
208
+ if (a.noWrap) styles.push("white-space:nowrap");
209
+ const bg = shadingToCss(a.shading);
210
+ if (bg) styles.push(`background-color:${bg}`);
211
+ if (a.verticalAlign) styles.push(`vertical-align:${a.verticalAlign}`);
212
+ return styles;
213
+ }
214
+ /** Parse text-align → OOXML alignment. */
215
+ function alignmentFromElement(el) {
216
+ return alignmentFromCss(el.style.textAlign || null);
217
+ }
218
+ /** Parse margin-left/right + text-indent → OOXML indent (twips). */
219
+ function indentFromElement(el) {
220
+ const indent = {};
221
+ const left = cssToTwip(el.style.marginLeft);
222
+ if (left) indent.left = left;
223
+ const right = cssToTwip(el.style.marginRight);
224
+ if (right) indent.right = right;
225
+ const ti = el.style.textIndent;
226
+ if (ti) if (ti.startsWith("-")) {
227
+ const h = cssToTwip(ti.slice(1));
228
+ if (h) indent.hanging = h;
229
+ } else {
230
+ const f = cssToTwip(ti);
231
+ if (f) indent.firstLine = f;
232
+ }
233
+ return Object.keys(indent).length > 0 ? indent : null;
234
+ }
235
+ /** Parse margin-top/bottom + line-height → OOXML spacing (twips). */
236
+ function spacingFromElement(el) {
237
+ const spacing = {};
238
+ const before = cssToTwip(el.style.marginTop);
239
+ if (before) spacing.before = before;
240
+ const after = cssToTwip(el.style.marginBottom);
241
+ if (after) spacing.after = after;
242
+ const lh = el.style.lineHeight;
243
+ if (lh) {
244
+ const m = lh.match(/^([\d.]+)(pt|px)?$/);
245
+ if (m) {
246
+ const num = parseFloat(m[1]);
247
+ if (m[2]) {
248
+ spacing.line = Math.round(num * (m[2] === "px" ? 15 : 20));
249
+ spacing.lineRule = "exact";
250
+ } else {
251
+ spacing.line = Math.round(num * 240);
252
+ spacing.lineRule = "auto";
253
+ }
254
+ }
255
+ }
256
+ return Object.keys(spacing).length > 0 ? spacing : null;
257
+ }
258
+ /** Parse border-* → OOXML BordersOptions. */
259
+ function bordersFromElement(el) {
260
+ const borders = {};
261
+ const sides = [
262
+ ["top", el.style.borderTop],
263
+ ["bottom", el.style.borderBottom],
264
+ ["left", el.style.borderLeft],
265
+ ["right", el.style.borderRight]
266
+ ];
267
+ for (const [side, css] of sides) {
268
+ if (!css || css === "initial" || css === "none") continue;
269
+ const m = css.match(/^(none|solid|dashed|dotted|double)\s+([\d.]+pt)\s+(.+)$/);
270
+ if (!m) continue;
271
+ borders[side] = {
272
+ style: {
273
+ solid: "single",
274
+ dashed: "dashed",
275
+ dotted: "dotted",
276
+ double: "double"
277
+ }[m[1]] ?? "single",
278
+ size: Math.round(parseFloat(m[2]) * 8),
279
+ color: m[3]
280
+ };
281
+ }
282
+ return Object.keys(borders).length > 0 ? borders : null;
283
+ }
284
+ /** Parse background-color → OOXML shading. */
285
+ function shadingFromElement(el) {
286
+ return shadingFromCss(el.style.backgroundColor || null);
287
+ }
288
+ //#endregion
289
+ export { alignmentFromCss, alignmentFromElement, alignmentToCss, bordersFromElement, characterSpacingFromCss, characterSpacingToCss, cssToTwip, indentFromElement, lineSpacingToCss, normalizeColorToHex, renderBorderCSS, renderParagraphStyles, renderTableCellStyles, resolveFontName, shadingFromCss, shadingFromElement, shadingToCss, sizeFromCss, sizeToCss, spacingFromElement, twipToCss };
@@ -0,0 +1,8 @@
1
+ import { JSONContent } from "@tiptap/core";
2
+
3
+ //#region src/extensions/heading.d.ts
4
+ declare function renderDocx(node: JSONContent): Record<string, unknown>;
5
+ declare function parseDocx(opts: Record<string, unknown>): Record<string, unknown>;
6
+ declare const Heading: import("@tiptap/core").Node<import("@tiptap/extension-heading").HeadingOptions, any>;
7
+ //#endregion
8
+ export { parseDocx as n, renderDocx as r, Heading as t };
@@ -0,0 +1,47 @@
1
+ import { JSONContent } from "@tiptap/core";
2
+
3
+ //#region src/extensions/image.d.ts
4
+ type CropRect = {
5
+ left?: number;
6
+ top?: number;
7
+ right?: number;
8
+ bottom?: number;
9
+ };
10
+ /**
11
+ * Custom Image extension with node-level renderHTML + renderDocx/parseDocx.
12
+ *
13
+ * Attrs:
14
+ * - src/alt/title/width/height: Tiptap structural names (kept verbatim so base
15
+ * image commands work).
16
+ * - rotation: editor display only (CSS transform) but also carried through DOCX
17
+ * via transformation.rotation (MediaTransformation.rotation).
18
+ * - floating/outline: nested office-open objects (Floating / OutlineOptions).
19
+ * - crop: nested office-open SourceRectangleOptions (srcRect).
20
+ * - display: editor-only display hint, no OOXML equivalent.
21
+ *
22
+ * DOCX round-trip is near-identity: renderDocx packs attrs into CoreImageOptions;
23
+ * parseDocx unpacks them back. src is a data URL ↔ { type, data } base64.
24
+ * Node-level renderHTML solves the style merge problem (rotation + floating).
25
+ */
26
+ /**
27
+ * Tiptap JSON image node → CoreImageOptions-shaped object.
28
+ *
29
+ * Returns `{ image: ImageOptions }` (structural wrapper) or null when no
30
+ * embedded image data is available (external URLs need pre-fetching).
31
+ * rotation is carried via transformation.rotation (not dropped).
32
+ */
33
+ declare function renderDocx(node: JSONContent): Record<string, unknown> | null;
34
+ /**
35
+ * ImageOptions-shaped object → Tiptap attrs.
36
+ *
37
+ * Near-identity unpack: transformation → width/height/rotation, altText → alt/title,
38
+ * floating/srcRect(→crop)/outline passed through verbatim. src is reconstructed by
39
+ * DocxManager from the image data bytes (kept out of parseDocx).
40
+ */
41
+ declare function parseDocx(imageOpts: Record<string, unknown>): Record<string, unknown>;
42
+ declare function renderCropAttrs(crop: Record<string, unknown> | CropRect): {
43
+ style: string;
44
+ };
45
+ declare const Image: import("@tiptap/core").Node<import("@tiptap/extension-image").ImageOptions, any>;
46
+ //#endregion
47
+ export { renderDocx as i, parseDocx as n, renderCropAttrs as r, Image as t };
@@ -0,0 +1,213 @@
1
+ import { a as JSONContent, c as StarterKit, d as docxExtensions, f as tiptapMarkExtensions, l as StarterKitOptions, p as tiptapNodeExtensions, t as AnyExtension } from "./core-omBKMRtl.mjs";
2
+ import { ImageFetchHandler, PrepareStep, fetchImageHandler, prepareDocument, prepareImages } from "./converters/prepare.mjs";
3
+ import { DocxGenerateOptions, DocxManager, compileDocument, generateDOCX, generateDOCXStream, generateDOCXSync, parseDOCX, resolveDocument } from "./converters/docx.mjs";
4
+ import { generateHTML, parseHTML } from "./converters/html.mjs";
5
+ import { generateMarkdown, parseMarkdown } from "./converters/markdown.mjs";
6
+ import { DocxPatchContent, DocxPatchOptions, patchDOCX } from "./converters/patch.mjs";
7
+ import { DocxEditorOptions, createDocxEditor } from "./editor.mjs";
8
+ import { JSONContent as TiptapJSONContent } from "@tiptap/core";
9
+ import { AlignmentType, BookmarkOptions, BorderOptions, BordersOptions, DocumentOptions, EmphasisMarkType, ExternalHyperlinkOptions, Floating, FontAttributesProperties, FrameOptions, HeadingLevel, HeightRule, HighlightColor, ImageChild, ImageOptions, IndentAttributesProperties, InternalHyperlinkOptions, LeaderType, LevelParagraphStylePropertiesOptions, LineRuleType, Margins, MathChild, MathInput, MediaTransformation, ParagraphChild, ParagraphOptions, ParagraphPropertiesOptions, ParagraphPropertiesOptionsBase, ParagraphPropertiesOptionsBase as ParagraphPropertiesOptionsBase$1, ParagraphRunPropertiesOptions, ParagraphStylePropertiesOptions, RubyOptions, RunOptions, RunPropertiesOptions, RunStylePropertiesOptions, RunStylePropertiesOptions as RunStylePropertiesOptions$1, SectionChild, SectionOptions, ShadingAttributesProperties, SpacingProperties, TabStopDefinition, TabStopPosition, TabStopType, TableBordersOptions, TableCellBordersOptions, TableCellOptions, TableCellOptions as TableCellOptions$1, TableFloatOptions, TableLayoutType, TableLookOptions, TableOptions, TableOptions as TableOptions$1, TableRowOptions, TableRowPropertiesOptionsBase, TableRowPropertiesOptionsBase as TableRowPropertiesOptionsBase$1, TableVerticalAlign, TableWidthProperties, TextAlignmentType, UnderlineType, WidthType } from "@office-open/docx";
10
+
11
+ //#region src/types.d.ts
12
+ /**
13
+ * Make every property of T nullable and required.
14
+ * ProseMirror stores every declared attr; explicit null matches that model.
15
+ */
16
+ type AttrNullable<T> = { [K in keyof T]-?: T[K] | null };
17
+ /**
18
+ * Paragraph and heading attrs — mirrors ParagraphPropertiesOptionsBase.
19
+ *
20
+ * indent/spacing/border/run/frame are nested objects (matching office-open),
21
+ * so one `indent` attr replaces 13 flattened indent attrs.
22
+ */
23
+ type ParagraphAttrs = AttrNullable<ParagraphPropertiesOptionsBase$1>;
24
+ /**
25
+ * Text style mark attrs — mirrors RunStylePropertiesOptions.
26
+ *
27
+ * Omits properties handled by dedicated marks (bold, italic, strike,
28
+ * doubleStrike, subScript, superScript). `size` is in POINTS.
29
+ */
30
+ type TextStyleAttrs = AttrNullable<Omit<RunStylePropertiesOptions$1, "bold" | "boldComplexScript" | "italic" | "italicComplexScript" | "strike" | "doubleStrike" | "subScript" | "superScript">>;
31
+ /**
32
+ * Link mark attrs.
33
+ */
34
+ interface LinkAttrs {
35
+ href: string | null;
36
+ target: string | null;
37
+ rel: string | null;
38
+ class: string | null;
39
+ title: string | null;
40
+ }
41
+ /**
42
+ * Table attrs — mirrors TableOptions (minus `rows`, which is structural).
43
+ */
44
+ type TableAttrs = AttrNullable<Omit<TableOptions$1, "rows">>;
45
+ /**
46
+ * Table row attrs — mirrors TableRowPropertiesOptionsBase.
47
+ * height is nested { value, rule } matching office-open.
48
+ */
49
+ type TableRowAttrs = AttrNullable<TableRowPropertiesOptionsBase$1>;
50
+ /**
51
+ * Table cell / header attrs — mirrors TableCellOptions.
52
+ *
53
+ * colspan/rowspan/colwidth kept as Tiptap structural names (base extension
54
+ * dependent); office-open columnSpan/rowSpan are mapped in renderDocx.
55
+ */
56
+ type TableCellAttrs = AttrNullable<Omit<TableCellOptions$1, "children" | "columnSpan" | "rowSpan">> & {
57
+ /** Horizontal span (Tiptap base name; maps to office-open columnSpan). */colspan: number; /** Vertical span (Tiptap base name; maps to office-open rowSpan). */
58
+ rowspan: number; /** Column width in pixels per cell (Tiptap base name). */
59
+ colwidth: number[] | null;
60
+ };
61
+ /**
62
+ * Image attrs.
63
+ * src/alt/title kept as Tiptap structural names.
64
+ * width/height are pixel dimensions for editor display.
65
+ */
66
+ interface ImageAttrs {
67
+ src: string;
68
+ alt: string | null;
69
+ title: string | null;
70
+ width: number | null;
71
+ height: number | null;
72
+ rotation: number | null;
73
+ floating: Record<string, unknown> | null;
74
+ outline: Record<string, unknown> | null;
75
+ crop: Record<string, unknown> | null;
76
+ display: string | null;
77
+ }
78
+ /**
79
+ * Strike mark attrs.
80
+ */
81
+ interface StrikeAttrs {
82
+ doubleStrike: boolean | null;
83
+ }
84
+ interface TextNode {
85
+ type: "text";
86
+ text: string;
87
+ marks?: Mark[];
88
+ }
89
+ interface HardBreakNode {
90
+ type: "hardBreak";
91
+ marks?: Mark[];
92
+ }
93
+ type Mark = {
94
+ type: "bold";
95
+ } | {
96
+ type: "italic";
97
+ } | {
98
+ type: "underline";
99
+ } | {
100
+ type: "strike";
101
+ attrs?: StrikeAttrs;
102
+ } | {
103
+ type: "code";
104
+ } | {
105
+ type: "subscript";
106
+ } | {
107
+ type: "superscript";
108
+ } | {
109
+ type: "highlight";
110
+ attrs?: {
111
+ color?: string;
112
+ };
113
+ } | {
114
+ type: "textStyle";
115
+ attrs?: TextStyleAttrs;
116
+ } | {
117
+ type: "link";
118
+ attrs?: LinkAttrs;
119
+ };
120
+ interface ParagraphNode extends TiptapJSONContent {
121
+ type: "paragraph";
122
+ attrs?: ParagraphAttrs;
123
+ content?: Array<TextNode | HardBreakNode | ImageNode>;
124
+ }
125
+ interface HeadingNode extends TiptapJSONContent {
126
+ type: "heading";
127
+ attrs: {
128
+ level: 1 | 2 | 3 | 4 | 5 | 6;
129
+ } & ParagraphAttrs;
130
+ content?: Array<TextNode | HardBreakNode>;
131
+ }
132
+ interface BlockquoteNode extends TiptapJSONContent {
133
+ type: "blockquote";
134
+ content?: Array<ParagraphNode>;
135
+ }
136
+ interface CodeBlockNode extends TiptapJSONContent {
137
+ type: "codeBlock";
138
+ attrs?: {
139
+ language?: string;
140
+ };
141
+ content?: Array<TextNode>;
142
+ }
143
+ interface HorizontalRuleNode extends TiptapJSONContent {
144
+ type: "horizontalRule";
145
+ }
146
+ interface BulletListNode extends TiptapJSONContent {
147
+ type: "bulletList";
148
+ content?: Array<ListItemNode>;
149
+ }
150
+ interface OrderedListNode extends TiptapJSONContent {
151
+ type: "orderedList";
152
+ attrs?: {
153
+ start?: number;
154
+ order?: number;
155
+ type?: string | null;
156
+ };
157
+ content?: Array<ListItemNode>;
158
+ }
159
+ interface TaskListNode extends TiptapJSONContent {
160
+ type: "taskList";
161
+ content?: Array<TaskItemNode>;
162
+ }
163
+ interface ListItemNode extends TiptapJSONContent {
164
+ type: "listItem";
165
+ content?: Array<ParagraphNode>;
166
+ }
167
+ interface TaskItemNode extends TiptapJSONContent {
168
+ type: "taskItem";
169
+ attrs?: {
170
+ checked?: boolean;
171
+ };
172
+ content?: Array<ParagraphNode>;
173
+ }
174
+ interface TableNode extends TiptapJSONContent {
175
+ type: "table";
176
+ attrs?: TableAttrs;
177
+ content?: Array<TableRowNode>;
178
+ }
179
+ interface TableRowNode extends TiptapJSONContent {
180
+ type: "tableRow";
181
+ attrs?: TableRowAttrs;
182
+ content?: Array<TableCellNode | TableHeaderNode>;
183
+ }
184
+ interface TableCellNode extends TiptapJSONContent {
185
+ type: "tableCell";
186
+ attrs?: TableCellAttrs;
187
+ content?: Array<ParagraphNode>;
188
+ }
189
+ interface TableHeaderNode extends TiptapJSONContent {
190
+ type: "tableHeader";
191
+ attrs?: TableCellAttrs;
192
+ content?: Array<ParagraphNode>;
193
+ }
194
+ interface ImageNode extends TiptapJSONContent {
195
+ type: "image";
196
+ attrs?: ImageAttrs;
197
+ }
198
+ interface DetailsNode extends TiptapJSONContent {
199
+ type: "details";
200
+ content?: Array<DetailsSummaryNode | DetailsContentNode>;
201
+ }
202
+ interface DetailsSummaryNode extends TiptapJSONContent {
203
+ type: "detailsSummary";
204
+ content?: Array<TextNode | HardBreakNode>;
205
+ }
206
+ interface DetailsContentNode extends TiptapJSONContent {
207
+ type: "detailsContent";
208
+ content?: Array<BlockNode>;
209
+ }
210
+ type InlineContent = TextNode | HardBreakNode;
211
+ type BlockNode = ParagraphNode | HeadingNode | BlockquoteNode | CodeBlockNode | HorizontalRuleNode | BulletListNode | OrderedListNode | TaskListNode | TableNode | ImageNode | DetailsNode;
212
+ //#endregion
213
+ export { type AlignmentType, type AnyExtension, type AttrNullable, type BlockNode, type BlockquoteNode, type BookmarkOptions, type BorderOptions, type BordersOptions, type BulletListNode, type CodeBlockNode, type DetailsContentNode, type DetailsNode, type DetailsSummaryNode, type DocumentOptions, type DocxEditorOptions, type DocxGenerateOptions, DocxManager, type DocxPatchContent, type DocxPatchOptions, type EmphasisMarkType, type ExternalHyperlinkOptions, type Floating, type FontAttributesProperties, type FrameOptions, type HardBreakNode, type HeadingLevel, type HeadingNode, type HeightRule, type HighlightColor, type HorizontalRuleNode, type ImageAttrs, type ImageChild, type ImageFetchHandler, type ImageNode, type ImageOptions, type IndentAttributesProperties, type InlineContent, type InternalHyperlinkOptions, type JSONContent, type LeaderType, type LevelParagraphStylePropertiesOptions, type LineRuleType, type LinkAttrs, type ListItemNode, type Margins, type Mark, type MathChild, type MathInput, type MediaTransformation, type OrderedListNode, type ParagraphAttrs, type ParagraphChild, type ParagraphNode, type ParagraphOptions, type ParagraphPropertiesOptions, type ParagraphPropertiesOptionsBase, type ParagraphRunPropertiesOptions, type ParagraphStylePropertiesOptions, type PrepareStep, type RubyOptions, type RunOptions, type RunPropertiesOptions, type RunStylePropertiesOptions, type SectionChild, type SectionOptions, type ShadingAttributesProperties, type SpacingProperties, StarterKit, type StarterKitOptions, type StrikeAttrs, type TabStopDefinition, type TabStopPosition, type TabStopType, type TableAttrs, type TableBordersOptions, type TableCellAttrs, type TableCellBordersOptions, type TableCellNode, type TableCellOptions, type TableFloatOptions, type TableHeaderNode, type TableLayoutType, type TableLookOptions, type TableNode, type TableOptions, type TableRowAttrs, type TableRowNode, type TableRowOptions, type TableRowPropertiesOptionsBase, type TableVerticalAlign, type TableWidthProperties, type TaskItemNode, type TaskListNode, type TextAlignmentType, type TextNode, type TextStyleAttrs, type UnderlineType, type WidthType, compileDocument, createDocxEditor, docxExtensions, fetchImageHandler, generateDOCX, generateDOCXStream, generateDOCXSync, generateHTML, generateMarkdown, parseDOCX, parseHTML, parseMarkdown, patchDOCX, prepareDocument, prepareImages, resolveDocument, tiptapMarkExtensions, tiptapNodeExtensions };
package/dist/index.mjs ADDED
@@ -0,0 +1,8 @@
1
+ import { a as StarterKit, c as tiptapMarkExtensions, l as tiptapNodeExtensions, s as docxExtensions } from "./core-CFIQVRfx.mjs";
2
+ import { createDocxEditor } from "./editor.mjs";
3
+ import { fetchImageHandler, prepareDocument, prepareImages } from "./converters/prepare.mjs";
4
+ import { DocxManager, compileDocument, generateDOCX, generateDOCXStream, generateDOCXSync, parseDOCX, resolveDocument } from "./converters/docx.mjs";
5
+ import { patchDOCX } from "./converters/patch.mjs";
6
+ import { generateHTML, parseHTML } from "./converters/html.mjs";
7
+ import { generateMarkdown, parseMarkdown } from "./converters/markdown.mjs";
8
+ export { DocxManager, StarterKit, compileDocument, createDocxEditor, docxExtensions, fetchImageHandler, generateDOCX, generateDOCXStream, generateDOCXSync, generateHTML, generateMarkdown, parseDOCX, parseHTML, parseMarkdown, patchDOCX, prepareDocument, prepareImages, resolveDocument, tiptapMarkExtensions, tiptapNodeExtensions };
@@ -0,0 +1,16 @@
1
+ import { JSONContent } from "@tiptap/core";
2
+
3
+ //#region src/extensions/paragraph.d.ts
4
+ /**
5
+ * Paragraph extension with nested office-open attrs.
6
+ *
7
+ * Attrs mirror ParagraphPropertiesOptionsBase (alignment/indent/spacing/border/
8
+ * shading/frame as nested objects + scalar OOXML properties). DOCX round-trip is
9
+ * near-identity: renderDocx/parseDocx pass attrs through; CSS conversion happens
10
+ * only in renderHTML via utils mappers.
11
+ */
12
+ declare function renderDocx(node: JSONContent): Record<string, unknown>;
13
+ declare function parseDocx(opts: Record<string, unknown>): Record<string, unknown>;
14
+ declare const Paragraph: import("@tiptap/core").Node<import("@tiptap/extension-paragraph").ParagraphOptions, any>;
15
+ //#endregion
16
+ export { parseDocx as n, renderDocx as r, Paragraph as t };
@@ -0,0 +1,33 @@
1
+ import { RunOptions } from "@office-open/docx";
2
+
3
+ //#region src/extensions/strike.d.ts
4
+ /**
5
+ * Strike mark extension with nested office-open attrs.
6
+ *
7
+ * OOXML represents strikethrough on a run via two mutually exclusive booleans:
8
+ * `strike` (single) and `doubleStrike` (double). The mark itself is "single
9
+ * strikethrough"; the `doubleStrike` attr flips it to double. DOCX round-trip
10
+ * is near-identity for the doubleStrike flag; `strike` itself is implied by the
11
+ * mark's presence and handled in renderDocx/parseDocx.
12
+ *
13
+ * Mark attribute-level renderHTML is delegated to the base Strike extension
14
+ * (renders `<s>`); only the DOCX flag needs custom handling.
15
+ */
16
+ /**
17
+ * attrs → run properties.
18
+ *
19
+ * The mark presence itself means single strikethrough. When `doubleStrike` is
20
+ * set, emit the OOXML double-strike flag instead (the two are mutually
21
+ * exclusive in OOXML). DocxManager calls this with `mark.attrs`.
22
+ */
23
+ declare function renderDocx(attrs: Record<string, unknown>): Partial<RunOptions>;
24
+ /**
25
+ * run properties → attrs.
26
+ *
27
+ * Only the `doubleStrike` flag needs to round-trip; single strike is implied by
28
+ * the mark's existence. `strike` is structural/semantic (the mark) and skipped.
29
+ */
30
+ declare function parseDocx(runOpts: RunOptions): Record<string, unknown>;
31
+ declare const Strike: import("@tiptap/core").Mark<import("@tiptap/extension-strike").StrikeOptions, any>;
32
+ //#endregion
33
+ export { parseDocx as n, renderDocx as r, Strike as t };
@@ -0,0 +1,9 @@
1
+ import { JSONContent } from "@tiptap/core";
2
+ import { TableOptions } from "@office-open/docx";
3
+
4
+ //#region src/extensions/table.d.ts
5
+ declare function renderDocx(node: JSONContent): Partial<TableOptions>;
6
+ declare function parseDocx(opts: Record<string, unknown>): Record<string, unknown>;
7
+ declare const Table: import("@tiptap/core").Node<import("@tiptap/extension-table").TableOptions, any>;
8
+ //#endregion
9
+ export { parseDocx as n, renderDocx as r, Table as t };
@@ -0,0 +1,8 @@
1
+ import { JSONContent } from "@tiptap/core";
2
+
3
+ //#region src/extensions/table-cell.d.ts
4
+ declare function renderDocx(node: JSONContent): Record<string, unknown>;
5
+ declare function parseDocx(opts: Record<string, unknown>): Record<string, unknown>;
6
+ declare const TableCell: import("@tiptap/core").Node<import("@tiptap/extension-table").TableCellOptions, any>;
7
+ //#endregion
8
+ export { parseDocx as n, renderDocx as r, TableCell as t };
@@ -0,0 +1,8 @@
1
+ import { JSONContent } from "@tiptap/core";
2
+
3
+ //#region src/extensions/table-header.d.ts
4
+ declare function renderDocx(node: JSONContent): Record<string, unknown>;
5
+ declare function parseDocx(opts: Record<string, unknown>): Record<string, unknown>;
6
+ declare const TableHeader: import("@tiptap/core").Node<import("@tiptap/extension-table").TableHeaderOptions, any>;
7
+ //#endregion
8
+ export { parseDocx as n, renderDocx as r, TableHeader as t };
@@ -0,0 +1,9 @@
1
+ import { JSONContent } from "@tiptap/core";
2
+ import { TableRowPropertiesOptionsBase } from "@office-open/docx";
3
+
4
+ //#region src/extensions/table-row.d.ts
5
+ declare function renderDocx(node: JSONContent): Partial<TableRowPropertiesOptionsBase>;
6
+ declare function parseDocx(opts: Record<string, unknown>): Record<string, unknown>;
7
+ declare const TableRow: import("@tiptap/core").Node<import("@tiptap/extension-table").TableRowOptions, any>;
8
+ //#endregion
9
+ export { parseDocx as n, renderDocx as r, TableRow as t };
@@ -0,0 +1,8 @@
1
+ import { RunOptions } from "@office-open/docx";
2
+
3
+ //#region src/extensions/text-style.d.ts
4
+ declare function renderDocx(attrs: Record<string, unknown>): Partial<RunOptions>;
5
+ declare function parseDocx(opts: RunOptions): Record<string, unknown>;
6
+ declare const TextStyle: import("@tiptap/core").Mark<import("@tiptap/extension-text-style").TextStyleOptions, any>;
7
+ //#endregion
8
+ export { parseDocx as n, renderDocx as r, TextStyle as t };