@docen/docx 0.3.1 → 0.3.3

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 (114) hide show
  1. package/dist/converters/docx.d.mts +220 -1
  2. package/dist/converters/docx.mjs +1352 -1
  3. package/dist/converters/html.d.mts +28 -1
  4. package/dist/converters/html.mjs +103 -1
  5. package/dist/converters/markdown.d.mts +12 -1
  6. package/dist/converters/markdown.mjs +17 -1
  7. package/dist/converters/patch.d.mts +52 -1
  8. package/dist/converters/patch.mjs +35 -1
  9. package/dist/converters/prepare.d.mts +62 -1
  10. package/dist/converters/prepare.mjs +121 -1
  11. package/dist/converters/styles.d.mts +91 -2
  12. package/dist/converters/styles.mjs +308 -2
  13. package/dist/core-B8ba_FNi.mjs +717 -0
  14. package/dist/core-DRaLI8nd.d.mts +203 -0
  15. package/dist/core.d.mts +1 -1
  16. package/dist/core.mjs +1 -1
  17. package/dist/document-Cws7XTYL.d.mts +28 -0
  18. package/dist/editor.d.mts +20 -1
  19. package/dist/editor.mjs +20 -1
  20. package/dist/extensions/blockquote.d.mts +1 -1
  21. package/dist/extensions/blockquote.mjs +30 -2
  22. package/dist/extensions/code-block.d.mts +1 -1
  23. package/dist/extensions/code-block.mjs +22 -1
  24. package/dist/extensions/column-break.d.mts +1 -1
  25. package/dist/extensions/column-break.mjs +1 -1
  26. package/dist/extensions/details.d.mts +1 -1
  27. package/dist/extensions/details.mjs +17 -2
  28. package/dist/extensions/document.d.mts +1 -1
  29. package/dist/extensions/document.mjs +45 -1
  30. package/dist/extensions/extensions.d.mts +4 -5
  31. package/dist/extensions/extensions.mjs +13 -14
  32. package/dist/extensions/formatting-marks.d.mts +7 -1
  33. package/dist/extensions/formatting-marks.mjs +1 -1
  34. package/dist/extensions/heading.mjs +187 -1
  35. package/dist/extensions/image.d.mts +1 -1
  36. package/dist/extensions/image.mjs +395 -1
  37. package/dist/extensions/index.d.mts +4 -3
  38. package/dist/extensions/index.mjs +4 -3
  39. package/dist/extensions/mention.d.mts +1 -1
  40. package/dist/extensions/mention.mjs +43 -2
  41. package/dist/extensions/ordered-list.d.mts +1 -1
  42. package/dist/extensions/ordered-list.mjs +40 -2
  43. package/dist/extensions/page-break.d.mts +1 -33
  44. package/dist/extensions/page-break.mjs +1 -1
  45. package/dist/extensions/paragraph.mjs +145 -1
  46. package/dist/extensions/passthrough.d.mts +1 -1
  47. package/dist/extensions/passthrough.mjs +1 -1
  48. package/dist/extensions/section-break.d.mts +19 -2
  49. package/dist/extensions/section-break.mjs +1 -1
  50. package/dist/extensions/strike.mjs +45 -1
  51. package/dist/extensions/table-cell.mjs +106 -1
  52. package/dist/extensions/table-header.mjs +106 -1
  53. package/dist/extensions/table-row.mjs +78 -1
  54. package/dist/extensions/table.mjs +154 -1
  55. package/dist/extensions/task-item.d.mts +1 -1
  56. package/dist/extensions/task-item.mjs +36 -2
  57. package/dist/extensions/text-style.mjs +145 -1
  58. package/dist/extensions/tiptap.d.mts +2 -2
  59. package/dist/extensions/tiptap.mjs +31 -2
  60. package/dist/extensions/toc-field.d.mts +2 -0
  61. package/dist/extensions/toc-field.mjs +2 -0
  62. package/dist/extensions/utils.d.mts +2 -62
  63. package/dist/extensions/utils.mjs +508 -2
  64. package/dist/extensions/wpg-group.d.mts +2 -0
  65. package/dist/extensions/wpg-group.mjs +2 -0
  66. package/dist/extensions/wps-shape.d.mts +2 -0
  67. package/dist/extensions/wps-shape.mjs +2 -0
  68. package/dist/index.d.mts +101 -29
  69. package/dist/index.mjs +13 -10
  70. package/dist/{tiptap-TErPjuNJ.d.mts → tiptap-pZsNPsvV.d.mts} +1 -3
  71. package/dist/utils-BJwDQts7.d.mts +137 -0
  72. package/package.json +39 -40
  73. package/dist/blockquote-Ky9xD_Q-.mjs +0 -31
  74. package/dist/code-block-BgNjhADy.mjs +0 -23
  75. package/dist/core-DEqBHRzE.mjs +0 -406
  76. package/dist/core-fBMCCj4D.d.mts +0 -97
  77. package/dist/details-Dh8luWb2.mjs +0 -18
  78. package/dist/dist-B6B3HnVZ.mjs +0 -1838
  79. package/dist/document-BH1y4qHM.d.mts +0 -6
  80. package/dist/document-CvTym-FM.mjs +0 -50
  81. package/dist/docx-C5wyjI-0.d.mts +0 -200
  82. package/dist/docx-CONyAedl.mjs +0 -1231
  83. package/dist/editor-Bf3CxQnY.mjs +0 -21
  84. package/dist/editor-DReY3Rb9.d.mts +0 -21
  85. package/dist/emoji-BZ1dJD7d.d.mts +0 -17
  86. package/dist/emoji-C2OsTWR7.mjs +0 -27
  87. package/dist/extensions/emoji.d.mts +0 -2
  88. package/dist/extensions/emoji.mjs +0 -2
  89. package/dist/extensions/image-group.d.mts +0 -6
  90. package/dist/extensions/image-group.mjs +0 -2
  91. package/dist/heading-DAubgJJN.mjs +0 -166
  92. package/dist/html-DCC_DSHv.d.mts +0 -18
  93. package/dist/html-DedDWPoO.mjs +0 -66
  94. package/dist/image-CuEIXoZl.mjs +0 -334
  95. package/dist/markdown-BzJmRsBs.mjs +0 -18
  96. package/dist/markdown-D0k0sRYS.d.mts +0 -13
  97. package/dist/mention-C-dTR6MK.mjs +0 -44
  98. package/dist/ordered-list-V-3xFQmV.mjs +0 -41
  99. package/dist/paragraph-BrWH-BOV.mjs +0 -147
  100. package/dist/patch-Cdp5WKJz.d.mts +0 -53
  101. package/dist/patch-IZ13tXTu.mjs +0 -36
  102. package/dist/prepare-Bdk8Cjkf.mjs +0 -122
  103. package/dist/prepare-CPAvcv6q.d.mts +0 -63
  104. package/dist/strike-hWxShOgb.mjs +0 -50
  105. package/dist/styles-QSX3RhxK.mjs +0 -285
  106. package/dist/styles-ugspkrxz.d.mts +0 -85
  107. package/dist/table-DrA12lxX.mjs +0 -159
  108. package/dist/table-cell-DmkfYwDc.mjs +0 -112
  109. package/dist/table-header-Bwr5GKWg.mjs +0 -112
  110. package/dist/table-row-vew1y7WH.mjs +0 -84
  111. package/dist/task-item-BnlXGrIG.mjs +0 -37
  112. package/dist/text-style-tMeBq5XQ.mjs +0 -151
  113. package/dist/tiptap-D7pl4I5U.mjs +0 -33
  114. package/dist/utils-BPT4tjcn.mjs +0 -333
@@ -1,21 +0,0 @@
1
- import { s as docxExtensions, t as Editor } from "./core-DEqBHRzE.mjs";
2
- //#region src/editor.ts
3
- /**
4
- * Create a Tiptap editor configured for DOCX editing.
5
- */
6
- function createDocxEditor(options) {
7
- const { element, extensions: extraExtensions = [], content, spellcheck = true, editable = true } = options;
8
- const extraNames = new Set(extraExtensions.map((e) => e.name).filter(Boolean));
9
- return new Editor({
10
- element,
11
- extensions: [...docxExtensions.filter((e) => !extraNames.has(e.name)), ...extraExtensions],
12
- content: content ?? {
13
- type: "doc",
14
- content: [{ type: "paragraph" }]
15
- },
16
- editable,
17
- editorProps: { attributes: { spellcheck: spellcheck ? "true" : "false" } }
18
- });
19
- }
20
- //#endregion
21
- export { createDocxEditor as t };
@@ -1,21 +0,0 @@
1
- import { n as Editor, t as AnyExtension } from "./core-fBMCCj4D.mjs";
2
-
3
- //#region src/editor.d.ts
4
- interface DocxEditorOptions {
5
- /** DOM element to mount the editor */
6
- element: HTMLElement;
7
- /** Additional Tiptap extensions */
8
- extensions?: AnyExtension[];
9
- /** Initial content (Tiptap JSON or HTML string) */
10
- content?: Record<string, unknown> | string;
11
- /** Enable spellcheck (disable for large documents) */
12
- spellcheck?: boolean;
13
- /** Editor is editable */
14
- editable?: boolean;
15
- }
16
- /**
17
- * Create a Tiptap editor configured for DOCX editing.
18
- */
19
- declare function createDocxEditor(options: DocxEditorOptions): Editor;
20
- //#endregion
21
- export { createDocxEditor as n, DocxEditorOptions as t };
@@ -1,17 +0,0 @@
1
- //#region src/extensions/emoji.d.ts
2
- /**
3
- * Custom Emoji extension — caches the resolved glyph for DOCX export.
4
- *
5
- * Base `@tiptap/extension-emoji` stores only `name` (a shortcode); the glyph
6
- * itself is looked up from a dataset at render time. DOCX compile runs outside
7
- * the editor (no dataset available), so we cache the resolved character in
8
- * `attrs.emoji`, filled from the element's text content on `parseHTML`.
9
- *
10
- * DOCX has no emoji structure — a glyph is just a text run. Compile therefore
11
- * emits `attrs.emoji` (falling back to the `:name:` shortcode) as plain text;
12
- * resolve degrades DOCX text back to a text node (known lossy round-trip, like
13
- * codeBlock's dropped `language`). HTML rendering is inherited from the base.
14
- */
15
- declare const Emoji: import("@tiptap/core").Node<import("@tiptap/extension-emoji").EmojiOptions, import("@tiptap/extension-emoji").EmojiStorage>;
16
- //#endregion
17
- export { Emoji as t };
@@ -1,27 +0,0 @@
1
- import { d as Emoji$1 } from "./tiptap-D7pl4I5U.mjs";
2
- //#region src/extensions/emoji.ts
3
- /**
4
- * Custom Emoji extension — caches the resolved glyph for DOCX export.
5
- *
6
- * Base `@tiptap/extension-emoji` stores only `name` (a shortcode); the glyph
7
- * itself is looked up from a dataset at render time. DOCX compile runs outside
8
- * the editor (no dataset available), so we cache the resolved character in
9
- * `attrs.emoji`, filled from the element's text content on `parseHTML`.
10
- *
11
- * DOCX has no emoji structure — a glyph is just a text run. Compile therefore
12
- * emits `attrs.emoji` (falling back to the `:name:` shortcode) as plain text;
13
- * resolve degrades DOCX text back to a text node (known lossy round-trip, like
14
- * codeBlock's dropped `language`). HTML rendering is inherited from the base.
15
- */
16
- const Emoji = Emoji$1.extend({ addAttributes() {
17
- return {
18
- ...this.parent?.(),
19
- emoji: {
20
- default: null,
21
- rendered: false,
22
- parseHTML: (el) => el.textContent || null
23
- }
24
- };
25
- } });
26
- //#endregion
27
- export { Emoji as t };
@@ -1,2 +0,0 @@
1
- import { t as Emoji } from "../emoji-BZ1dJD7d.mjs";
2
- export { Emoji };
@@ -1,2 +0,0 @@
1
- import { t as Emoji } from "../emoji-C2OsTWR7.mjs";
2
- export { Emoji };
@@ -1,6 +0,0 @@
1
- import { s as Node } from "../core-fBMCCj4D.mjs";
2
-
3
- //#region src/extensions/image-group.d.ts
4
- declare const ImageGroup: Node<any, any>;
5
- //#endregion
6
- export { ImageGroup };
@@ -1,2 +0,0 @@
1
- import { p as ImageGroup } from "../core-DEqBHRzE.mjs";
2
- export { ImageGroup };
@@ -1,166 +0,0 @@
1
- import { m as Heading$1 } from "./tiptap-D7pl4I5U.mjs";
2
- import { _ as shadingFromElement, c as indentFromElement, f as renderParagraphStyles, i as bordersFromElement, n as alignmentFromElement, x as spacingFromElement } from "./utils-BPT4tjcn.mjs";
3
- //#region src/extensions/heading.ts
4
- /**
5
- * Heading extension with nested office-open attrs (mirrors Paragraph).
6
- *
7
- * Attrs mirror ParagraphPropertiesOptionsBase (alignment/indent/spacing/border/
8
- * shading/frame as nested objects + scalar OOXML properties) plus the inherited
9
- * Tiptap `level` (1-6, rendered: false). DOCX round-trip is near-identity:
10
- * renderDocx/parseDocx pass attrs through and only map `level` ↔ OOXML
11
- * `heading` (HeadingLevel literal). CSS conversion happens solely in
12
- * renderHTML via utils mappers.
13
- */
14
- const HEADING_COMPILE_MAP = {
15
- 1: "Heading1",
16
- 2: "Heading2",
17
- 3: "Heading3",
18
- 4: "Heading4",
19
- 5: "Heading5",
20
- 6: "Heading6"
21
- };
22
- const HEADING_PARSE_MAP = {
23
- Heading1: 1,
24
- Heading2: 2,
25
- Heading3: 3,
26
- Heading4: 4,
27
- Heading5: 5,
28
- Heading6: 6,
29
- Title: 1
30
- };
31
- /** HeadingLevel literals that office-open lifts from a pStyle into `heading`.
32
- * Used to round-trip the literal via styleId (covers "Title", which level 1
33
- * alone would collapse to "Heading1"). */
34
- const HEADING_STYLE_IDS = new Set(Object.keys(HEADING_PARSE_MAP));
35
- /** Runtime-only attrs the TableOfContents extension injects on each heading
36
- * (`id` / `data-toc-id`). They are regenerated on every load, so never persist
37
- * them to DOCX — skip them in renderDocx. */
38
- const TOC_RUNTIME_KEYS = new Set(["id", "data-toc-id"]);
39
- function renderDocx(node) {
40
- const attrs = node.attrs ?? {};
41
- const opts = {};
42
- const level = attrs.level;
43
- const styleId = attrs.styleId;
44
- if (styleId && HEADING_STYLE_IDS.has(styleId)) opts.heading = styleId;
45
- else if (level) opts.heading = HEADING_COMPILE_MAP[level] ?? "Heading1";
46
- for (const [key, value] of Object.entries(attrs)) {
47
- if (key === "level" || key === "styleId" || TOC_RUNTIME_KEYS.has(key)) continue;
48
- if (value !== null && value !== void 0) opts[key] = value;
49
- }
50
- return opts;
51
- }
52
- /** Structural/semantic keys expressed elsewhere (heading handled separately, list handling, run children). */
53
- const SKIP_KEYS = new Set([
54
- "heading",
55
- "style",
56
- "bullet",
57
- "numbering",
58
- "run",
59
- "children",
60
- "text",
61
- "thematicBreak"
62
- ]);
63
- function parseDocx(opts) {
64
- const resolved = typeof opts === "string" ? { text: opts } : opts;
65
- const attrs = {};
66
- if (resolved.heading) {
67
- const level = HEADING_PARSE_MAP[resolved.heading];
68
- if (level) attrs.level = level;
69
- attrs.styleId = resolved.heading;
70
- }
71
- if (resolved.style) attrs.styleId = resolved.style;
72
- for (const [key, value] of Object.entries(resolved)) {
73
- if (SKIP_KEYS.has(key)) continue;
74
- attrs[key] = value ?? null;
75
- }
76
- return attrs;
77
- }
78
- const attrNative = () => ({
79
- default: null,
80
- parseHTML: () => null,
81
- rendered: false
82
- });
83
- const Heading = Heading$1.extend({
84
- addAttributes() {
85
- return {
86
- ...this.parent?.(),
87
- styleId: {
88
- default: null,
89
- parseHTML: (el) => {
90
- const m = (el.getAttribute("class") || "").match(/(?:^|\s)docx-style-(\S+)/);
91
- return m ? m[1] : null;
92
- }
93
- },
94
- alignment: {
95
- default: null,
96
- rendered: false,
97
- parseHTML: (el) => alignmentFromElement(el)
98
- },
99
- indent: {
100
- default: null,
101
- rendered: false,
102
- parseHTML: (el) => indentFromElement(el)
103
- },
104
- spacing: {
105
- default: null,
106
- rendered: false,
107
- parseHTML: (el) => spacingFromElement(el)
108
- },
109
- shading: {
110
- default: null,
111
- rendered: false,
112
- parseHTML: (el) => shadingFromElement(el)
113
- },
114
- border: {
115
- default: null,
116
- rendered: false,
117
- parseHTML: (el) => bordersFromElement(el)
118
- },
119
- frame: attrNative(),
120
- keepNext: attrNative(),
121
- keepLines: attrNative(),
122
- pageBreakBefore: attrNative(),
123
- widowControl: attrNative(),
124
- contextualSpacing: attrNative(),
125
- bidirectional: attrNative(),
126
- outlineLevel: attrNative(),
127
- textDirection: attrNative(),
128
- textAlignment: attrNative(),
129
- suppressLineNumbers: attrNative(),
130
- wordWrap: attrNative(),
131
- overflowPunctuation: attrNative(),
132
- autoSpaceEastAsianText: attrNative(),
133
- suppressOverlap: attrNative(),
134
- suppressAutoHyphens: attrNative(),
135
- adjustRightInd: attrNative(),
136
- snapToGrid: attrNative(),
137
- mirrorIndents: attrNative(),
138
- kinsoku: attrNative(),
139
- topLinePunct: attrNative(),
140
- autoSpaceDE: attrNative(),
141
- textboxTightWrap: attrNative(),
142
- rightTabStop: attrNative(),
143
- leftTabStop: attrNative(),
144
- divId: attrNative(),
145
- tabStops: attrNative(),
146
- cnfStyle: attrNative()
147
- };
148
- },
149
- renderHTML({ node, HTMLAttributes }) {
150
- const styles = renderParagraphStyles(node.attrs);
151
- const level = node.attrs?.level ?? 1;
152
- const attrs = { ...HTMLAttributes };
153
- const styleId = node.attrs.styleId;
154
- if (styleId) attrs.class = `docx-style-${styleId}`;
155
- if (styles.length > 0) attrs.style = styles.join(";");
156
- return [
157
- `h${level}`,
158
- attrs,
159
- 0
160
- ];
161
- },
162
- renderDocx,
163
- parseDocx
164
- });
165
- //#endregion
166
- export { parseDocx as n, renderDocx as r, Heading as t };
@@ -1,18 +0,0 @@
1
- import { a as JSONContent, i as Extensions } from "./core-fBMCCj4D.mjs";
2
- import { ParseOptions } from "@tiptap/pm/model";
3
-
4
- //#region src/converters/html.d.ts
5
- /**
6
- * Parse HTML string to Tiptap JSON. Reads back the page background base color
7
- * from a generateHTML wrapper div (pattern image is lost — OOXML patterns have
8
- * no HTML equivalent; the DOCX round-trip preserves the full background).
9
- */
10
- declare function parseHTML(html: string, extensions?: Extensions, options?: ParseOptions): JSONContent;
11
- /**
12
- * Generate HTML string from Tiptap JSON. Wraps the content in a div carrying
13
- * the page background (color + pattern image) so the document background is
14
- * visible — Tiptap's DOMSerializer only serializes content nodes, not doc attrs.
15
- */
16
- declare function generateHTML(doc: JSONContent, extensions?: Extensions): string;
17
- //#endregion
18
- export { parseHTML as n, generateHTML as t };
@@ -1,66 +0,0 @@
1
- import { s as docxExtensions } from "./core-DEqBHRzE.mjs";
2
- import { t as encodeBase64 } from "./dist-B6B3HnVZ.mjs";
3
- import { generateHTML, generateJSON } from "@tiptap/html";
4
- //#region src/converters/html.ts
5
- const defaultExtensions = docxExtensions;
6
- /**
7
- * Normalize a media payload to Uint8Array — JSON round-trips byte arrays as
8
- * plain objects ({0:byte,...}), so rebuild before base64-encoding.
9
- */
10
- function toBytes(d) {
11
- if (!d) return null;
12
- if (d instanceof Uint8Array) return d;
13
- return new Uint8Array(Object.values(d));
14
- }
15
- /**
16
- * Build a CSS background style from DocumentBackgroundOptions. VML/rawXml page
17
- * backgrounds (base fill + pattern image) reduce to a solid color (the w:color
18
- * base fill) plus a tiled image (rawMedia) — OOXML pattern semantics can't be
19
- * expressed in CSS, but base color + tile gives a visually close result.
20
- */
21
- function extractBackgroundStyle(bg) {
22
- if (!bg || typeof bg !== "object") return void 0;
23
- const b = bg;
24
- let color;
25
- if (b.color) color = b.color;
26
- else if (b.rawXml) {
27
- const m = b.rawXml.match(/w:color="([0-9A-Fa-f]{6})"/);
28
- if (m) color = m[1];
29
- }
30
- const media = b.image?.data ?? b.rawMedia?.[0];
31
- const bytes = toBytes(media?.data);
32
- const styles = [];
33
- if (color) styles.push(`background-color:#${color}`);
34
- if (bytes) {
35
- const type = media?.type ?? "png";
36
- styles.push(`background-image:url(data:image/${type};base64,${encodeBase64(bytes)})`, "background-repeat:repeat");
37
- }
38
- return styles.length ? styles.join(";") : void 0;
39
- }
40
- /**
41
- * Parse HTML string to Tiptap JSON. Reads back the page background base color
42
- * from a generateHTML wrapper div (pattern image is lost — OOXML patterns have
43
- * no HTML equivalent; the DOCX round-trip preserves the full background).
44
- */
45
- function parseHTML(html, extensions, options) {
46
- const doc = generateJSON(html, extensions ?? defaultExtensions, options);
47
- const m = html.match(/<div style="background-color:#([0-9A-Fa-f]{6})/);
48
- if (m) {
49
- if (!doc.attrs) doc.attrs = {};
50
- doc.attrs.background = { color: m[1] };
51
- }
52
- return doc;
53
- }
54
- /**
55
- * Generate HTML string from Tiptap JSON. Wraps the content in a div carrying
56
- * the page background (color + pattern image) so the document background is
57
- * visible — Tiptap's DOMSerializer only serializes content nodes, not doc attrs.
58
- */
59
- function generateHTML$1(doc, extensions) {
60
- const html = generateHTML(doc, extensions ?? defaultExtensions);
61
- const style = extractBackgroundStyle(doc.attrs?.background);
62
- if (style) return `<div style="${style}">${html}</div>`;
63
- return html;
64
- }
65
- //#endregion
66
- export { parseHTML as n, generateHTML$1 as t };