@docen/docx 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/dist/blockquote-Ky9xD_Q-.mjs +31 -0
- package/dist/code-block-BgNjhADy.mjs +23 -0
- package/dist/converters/docx.d.mts +1 -109
- package/dist/converters/docx.mjs +1 -623
- package/dist/converters/html.d.mts +1 -13
- package/dist/converters/html.mjs +1 -17
- package/dist/converters/markdown.d.mts +1 -12
- package/dist/converters/markdown.mjs +1 -17
- package/dist/converters/patch.d.mts +1 -52
- package/dist/converters/patch.mjs +1 -36
- package/dist/converters/prepare.d.mts +2 -51
- package/dist/converters/prepare.mjs +2 -76
- package/dist/converters/styles.d.mts +2 -0
- package/dist/converters/styles.mjs +2 -0
- package/dist/core-DEqBHRzE.mjs +406 -0
- package/dist/core-fBMCCj4D.d.mts +97 -0
- package/dist/core.d.mts +1 -1
- package/dist/core.mjs +1 -1
- package/dist/details-Dh8luWb2.mjs +18 -0
- package/dist/dist-B6B3HnVZ.mjs +1838 -0
- package/dist/document-BH1y4qHM.d.mts +6 -0
- package/dist/document-CvTym-FM.mjs +50 -0
- package/dist/docx-C5wyjI-0.d.mts +200 -0
- package/dist/docx-CONyAedl.mjs +1231 -0
- package/dist/editor-Bf3CxQnY.mjs +21 -0
- package/dist/editor-DReY3Rb9.d.mts +21 -0
- package/dist/editor.d.mts +1 -20
- package/dist/editor.mjs +1 -19
- package/dist/emoji-BZ1dJD7d.d.mts +17 -0
- package/dist/emoji-C2OsTWR7.mjs +27 -0
- package/dist/extensions/blockquote.d.mts +23 -0
- package/dist/extensions/blockquote.mjs +3 -0
- package/dist/extensions/code-block.d.mts +19 -0
- package/dist/extensions/code-block.mjs +2 -0
- package/dist/extensions/column-break.d.mts +31 -0
- package/dist/extensions/column-break.mjs +2 -0
- package/dist/extensions/details.d.mts +19 -0
- package/dist/extensions/details.mjs +3 -0
- package/dist/extensions/document.d.mts +2 -0
- package/dist/extensions/document.mjs +2 -0
- package/dist/extensions/emoji.d.mts +2 -0
- package/dist/extensions/emoji.mjs +2 -0
- package/dist/extensions/extensions.d.mts +6 -5
- package/dist/extensions/extensions.mjs +14 -12
- package/dist/extensions/formatting-marks.d.mts +32 -0
- package/dist/extensions/formatting-marks.mjs +2 -0
- package/dist/extensions/heading.mjs +1 -144
- package/dist/extensions/image-group.d.mts +6 -0
- package/dist/extensions/image-group.mjs +2 -0
- package/dist/extensions/image.d.mts +2 -2
- package/dist/extensions/image.mjs +1 -200
- package/dist/extensions/index.d.mts +3 -2
- package/dist/extensions/index.mjs +3 -2
- package/dist/extensions/mention.d.mts +25 -0
- package/dist/extensions/mention.mjs +3 -0
- package/dist/extensions/ordered-list.d.mts +25 -0
- package/dist/extensions/ordered-list.mjs +3 -0
- package/dist/extensions/page-break.d.mts +34 -0
- package/dist/extensions/page-break.mjs +2 -0
- package/dist/extensions/paragraph.d.mts +1 -1
- package/dist/extensions/paragraph.mjs +1 -115
- package/dist/extensions/passthrough.d.mts +2 -0
- package/dist/extensions/passthrough.mjs +2 -0
- package/dist/extensions/section-break.d.mts +27 -0
- package/dist/extensions/section-break.mjs +2 -0
- package/dist/extensions/strike.mjs +1 -49
- package/dist/extensions/table-cell.mjs +1 -111
- package/dist/extensions/table-header.mjs +1 -111
- package/dist/extensions/table-row.mjs +1 -83
- package/dist/extensions/table.mjs +1 -133
- package/dist/extensions/task-item.d.mts +27 -0
- package/dist/extensions/task-item.mjs +3 -0
- package/dist/extensions/text-style.mjs +1 -133
- package/dist/extensions/tiptap.mjs +1 -32
- package/dist/extensions/types.d.mts +7 -5
- package/dist/extensions/utils.d.mts +16 -3
- package/dist/extensions/utils.mjs +2 -289
- package/dist/heading-DAubgJJN.mjs +166 -0
- package/dist/html-DCC_DSHv.d.mts +18 -0
- package/dist/html-DedDWPoO.mjs +66 -0
- package/dist/image-CuEIXoZl.mjs +334 -0
- package/dist/index.d.mts +68 -18
- package/dist/index.mjs +10 -8
- package/dist/markdown-BzJmRsBs.mjs +18 -0
- package/dist/markdown-D0k0sRYS.d.mts +13 -0
- package/dist/mention-C-dTR6MK.mjs +44 -0
- package/dist/ordered-list-V-3xFQmV.mjs +41 -0
- package/dist/paragraph-BrWH-BOV.mjs +147 -0
- package/dist/paragraph-D8mpHo_o.d.mts +8 -0
- package/dist/patch-Cdp5WKJz.d.mts +53 -0
- package/dist/patch-IZ13tXTu.mjs +36 -0
- package/dist/prepare-Bdk8Cjkf.mjs +122 -0
- package/dist/prepare-CPAvcv6q.d.mts +63 -0
- package/dist/strike-hWxShOgb.mjs +50 -0
- package/dist/styles-QSX3RhxK.mjs +285 -0
- package/dist/styles-ugspkrxz.d.mts +85 -0
- package/dist/table-DrA12lxX.mjs +159 -0
- package/dist/table-cell-DmkfYwDc.mjs +112 -0
- package/dist/table-header-Bwr5GKWg.mjs +112 -0
- package/dist/table-row-vew1y7WH.mjs +84 -0
- package/dist/task-item-BnlXGrIG.mjs +37 -0
- package/dist/text-style-tMeBq5XQ.mjs +151 -0
- package/dist/tiptap-D7pl4I5U.mjs +33 -0
- package/dist/utils-BPT4tjcn.mjs +333 -0
- package/package.json +3 -2
- package/dist/core-CFIQVRfx.mjs +0 -88
- package/dist/core-omBKMRtl.d.mts +0 -34
- package/dist/image-Ge1y6uam.d.mts +0 -47
- package/dist/paragraph-fhEXtAN2.d.mts +0 -16
|
@@ -1,112 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { bordersFromElement, renderTableCellStyles, shadingFromElement } from "./utils.mjs";
|
|
3
|
-
//#region src/extensions/table-header.ts
|
|
4
|
-
/**
|
|
5
|
-
* Table header extension with nested office-open attrs (mirrors TableCell).
|
|
6
|
-
*
|
|
7
|
-
* Attrs mirror TableCellPropertiesOptionsBase (shading/margins/borders/width as
|
|
8
|
-
* nested objects + scalar OOXML properties) plus the inherited Tiptap structural
|
|
9
|
-
* names colspan/rowspan/colwidth/align (rendered: false for the OOXML-named ones).
|
|
10
|
-
* DOCX round-trip is near-identity: renderDocx/parseDocx pass OOXML-native attrs
|
|
11
|
-
* through and only map the Tiptap structural names colspan/rowspan/colwidth to
|
|
12
|
-
* OOXML columnSpan/rowSpan/width. CSS conversion happens solely in renderHTML via
|
|
13
|
-
* utils.renderTableCellStyles (consuming nested shading/verticalAlign/noWrap).
|
|
14
|
-
*/
|
|
15
|
-
/** Tiptap structural attrs expressed via OOXML structural fields, not passed through. */
|
|
16
|
-
const SKIP_KEYS = new Set([
|
|
17
|
-
"colspan",
|
|
18
|
-
"rowspan",
|
|
19
|
-
"colwidth",
|
|
20
|
-
"children"
|
|
21
|
-
]);
|
|
22
|
-
function renderDocx(node) {
|
|
23
|
-
const attrs = node.attrs ?? {};
|
|
24
|
-
const opts = {};
|
|
25
|
-
const colspan = attrs.colspan;
|
|
26
|
-
if (colspan && colspan > 1) opts.columnSpan = colspan;
|
|
27
|
-
const rowspan = attrs.rowspan;
|
|
28
|
-
if (rowspan && rowspan > 1) opts.rowSpan = rowspan;
|
|
29
|
-
const colwidth = attrs.colwidth;
|
|
30
|
-
if (colwidth && colwidth.length > 0) {
|
|
31
|
-
const totalPx = colwidth.reduce((sum, w) => sum + (w || 0), 0);
|
|
32
|
-
if (totalPx > 0) opts.width = {
|
|
33
|
-
size: totalPx * 15,
|
|
34
|
-
type: "dxa"
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
for (const [key, value] of Object.entries(attrs)) {
|
|
38
|
-
if (SKIP_KEYS.has(key)) continue;
|
|
39
|
-
if (value !== null && value !== void 0) opts[key] = value;
|
|
40
|
-
}
|
|
41
|
-
return opts;
|
|
42
|
-
}
|
|
43
|
-
function parseDocx(opts) {
|
|
44
|
-
const resolved = typeof opts === "string" ? { text: opts } : opts;
|
|
45
|
-
const attrs = {};
|
|
46
|
-
if (resolved.columnSpan != null) attrs.colspan = resolved.columnSpan;
|
|
47
|
-
if (resolved.rowSpan != null) attrs.rowspan = resolved.rowSpan;
|
|
48
|
-
if (resolved.width) {
|
|
49
|
-
const twips = resolved.width.size ?? 0;
|
|
50
|
-
if (twips) attrs.colwidth = [Math.round(twips / 15)];
|
|
51
|
-
}
|
|
52
|
-
for (const [key, value] of Object.entries(resolved)) {
|
|
53
|
-
if (key === "columnSpan" || key === "rowSpan" || key === "width" || key === "children") continue;
|
|
54
|
-
attrs[key] = value ?? null;
|
|
55
|
-
}
|
|
56
|
-
return attrs;
|
|
57
|
-
}
|
|
58
|
-
const attrNative = () => ({
|
|
59
|
-
default: null,
|
|
60
|
-
parseHTML: () => null,
|
|
61
|
-
rendered: false
|
|
62
|
-
});
|
|
63
|
-
const TableHeader = TableHeader$1.extend({
|
|
64
|
-
addAttributes() {
|
|
65
|
-
return {
|
|
66
|
-
...this.parent?.(),
|
|
67
|
-
shading: {
|
|
68
|
-
default: null,
|
|
69
|
-
rendered: false,
|
|
70
|
-
parseHTML: (el) => shadingFromElement(el)
|
|
71
|
-
},
|
|
72
|
-
borders: {
|
|
73
|
-
default: null,
|
|
74
|
-
rendered: false,
|
|
75
|
-
parseHTML: (el) => bordersFromElement(el)
|
|
76
|
-
},
|
|
77
|
-
verticalAlign: {
|
|
78
|
-
default: null,
|
|
79
|
-
rendered: false,
|
|
80
|
-
parseHTML: (el) => el.style.verticalAlign || null
|
|
81
|
-
},
|
|
82
|
-
textDirection: attrNative(),
|
|
83
|
-
width: attrNative(),
|
|
84
|
-
margins: attrNative(),
|
|
85
|
-
noWrap: {
|
|
86
|
-
default: null,
|
|
87
|
-
rendered: false,
|
|
88
|
-
parseHTML: (el) => el.style.whiteSpace === "nowrap" ? true : null
|
|
89
|
-
},
|
|
90
|
-
verticalMerge: attrNative(),
|
|
91
|
-
horizontalMerge: attrNative(),
|
|
92
|
-
fitText: attrNative(),
|
|
93
|
-
hideMark: attrNative(),
|
|
94
|
-
headers: attrNative(),
|
|
95
|
-
cnfStyle: attrNative()
|
|
96
|
-
};
|
|
97
|
-
},
|
|
98
|
-
renderHTML({ node, HTMLAttributes }) {
|
|
99
|
-
const styles = renderTableCellStyles(node.attrs);
|
|
100
|
-
const attrs = { ...HTMLAttributes };
|
|
101
|
-
if (styles.length > 0) attrs.style = styles.join(";");
|
|
102
|
-
return [
|
|
103
|
-
"th",
|
|
104
|
-
attrs,
|
|
105
|
-
0
|
|
106
|
-
];
|
|
107
|
-
},
|
|
108
|
-
renderDocx,
|
|
109
|
-
parseDocx
|
|
110
|
-
});
|
|
111
|
-
//#endregion
|
|
1
|
+
import { n as parseDocx, r as renderDocx, t as TableHeader } from "../table-header-Bwr5GKWg.mjs";
|
|
112
2
|
export { TableHeader, parseDocx, renderDocx };
|
|
@@ -1,84 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { cssToTwip } from "./utils.mjs";
|
|
3
|
-
//#region src/extensions/table-row.ts
|
|
4
|
-
/**
|
|
5
|
-
* Table row extension with nested office-open attrs.
|
|
6
|
-
*
|
|
7
|
-
* Attrs mirror TableRowPropertiesOptionsBase (cantSplit/tableHeader/hidden as
|
|
8
|
-
* booleans; height as a nested { value, rule } object; cellSpacing as a native
|
|
9
|
-
* value; widthBefore/widthAfter as TableWidthProperties; etc.). DOCX round-trip
|
|
10
|
-
* is near-identity: renderDocx/parseDocx pass attrs through (omitting the
|
|
11
|
-
* `cells` structural key that DocxManager owns). CSS conversion happens only
|
|
12
|
-
* in renderHTML.
|
|
13
|
-
*/
|
|
14
|
-
/** Structural keys filled by DocxManager (compileTableNode). */
|
|
15
|
-
const SKIP_KEYS = new Set(["cells"]);
|
|
16
|
-
function renderDocx(node) {
|
|
17
|
-
const attrs = node.attrs ?? {};
|
|
18
|
-
const opts = {};
|
|
19
|
-
for (const [key, value] of Object.entries(attrs)) {
|
|
20
|
-
if (SKIP_KEYS.has(key)) continue;
|
|
21
|
-
if (value !== null && value !== void 0) opts[key] = value;
|
|
22
|
-
}
|
|
23
|
-
return opts;
|
|
24
|
-
}
|
|
25
|
-
function parseDocx(opts) {
|
|
26
|
-
const attrs = {};
|
|
27
|
-
for (const [key, value] of Object.entries(opts)) {
|
|
28
|
-
if (SKIP_KEYS.has(key)) continue;
|
|
29
|
-
attrs[key] = value ?? null;
|
|
30
|
-
}
|
|
31
|
-
return attrs;
|
|
32
|
-
}
|
|
33
|
-
const attrNative = () => ({
|
|
34
|
-
default: null,
|
|
35
|
-
parseHTML: () => null,
|
|
36
|
-
rendered: false
|
|
37
|
-
});
|
|
38
|
-
const TableRow = TableRow$1.extend({
|
|
39
|
-
addAttributes() {
|
|
40
|
-
return {
|
|
41
|
-
...this.parent?.(),
|
|
42
|
-
height: {
|
|
43
|
-
default: null,
|
|
44
|
-
rendered: false,
|
|
45
|
-
parseHTML: (el) => {
|
|
46
|
-
const twips = cssToTwip(el.style.height || el.getAttribute("height") || "");
|
|
47
|
-
return twips != null ? {
|
|
48
|
-
value: twips,
|
|
49
|
-
rule: "atLeast"
|
|
50
|
-
} : null;
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
cantSplit: attrNative(),
|
|
54
|
-
tableHeader: attrNative(),
|
|
55
|
-
hidden: attrNative(),
|
|
56
|
-
divId: attrNative(),
|
|
57
|
-
gridBefore: attrNative(),
|
|
58
|
-
gridAfter: attrNative(),
|
|
59
|
-
rowAlignment: attrNative(),
|
|
60
|
-
cnfStyle: attrNative(),
|
|
61
|
-
cellSpacing: attrNative(),
|
|
62
|
-
widthBefore: attrNative(),
|
|
63
|
-
widthAfter: attrNative()
|
|
64
|
-
};
|
|
65
|
-
},
|
|
66
|
-
renderHTML({ node, HTMLAttributes }) {
|
|
67
|
-
const attrs = { ...HTMLAttributes };
|
|
68
|
-
const styles = [];
|
|
69
|
-
if (node.attrs.height && typeof node.attrs.height === "object") {
|
|
70
|
-
const h = node.attrs.height;
|
|
71
|
-
if (h.value != null) styles.push(`height:${h.value / 20}pt`);
|
|
72
|
-
}
|
|
73
|
-
if (styles.length > 0) attrs.style = styles.join(";");
|
|
74
|
-
return [
|
|
75
|
-
"tr",
|
|
76
|
-
attrs,
|
|
77
|
-
0
|
|
78
|
-
];
|
|
79
|
-
},
|
|
80
|
-
renderDocx,
|
|
81
|
-
parseDocx
|
|
82
|
-
});
|
|
83
|
-
//#endregion
|
|
1
|
+
import { n as parseDocx, r as renderDocx, t as TableRow } from "../table-row-vew1y7WH.mjs";
|
|
84
2
|
export { TableRow, parseDocx, renderDocx };
|
|
@@ -1,134 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { alignmentFromElement, alignmentToCss, bordersFromElement, renderBorderCSS, shadingFromElement, shadingToCss, twipToCss } from "./utils.mjs";
|
|
3
|
-
//#region src/extensions/table.ts
|
|
4
|
-
/**
|
|
5
|
-
* Table extension with nested office-open attrs.
|
|
6
|
-
*
|
|
7
|
-
* Attrs mirror TableOptions (width/float/layout/borders/alignment/margins/indent/
|
|
8
|
-
* cellSpacing/tableLook/columnWidths/etc.). DOCX round-trip is near-identity:
|
|
9
|
-
* renderDocx/parseDocx pass attrs through (omitting only `rows`, which DocxManager
|
|
10
|
-
* rebuilds from the row/cell nodes). CSS conversion happens only in renderHTML.
|
|
11
|
-
*/
|
|
12
|
-
/** Structural key rebuilt by DocxManager (compileTableNode walks the row nodes). */
|
|
13
|
-
const SKIP_KEYS = new Set(["rows", "columnWidthsRevision"]);
|
|
14
|
-
function renderDocx(node) {
|
|
15
|
-
const attrs = node.attrs ?? {};
|
|
16
|
-
const opts = {};
|
|
17
|
-
for (const [key, value] of Object.entries(attrs)) {
|
|
18
|
-
if (SKIP_KEYS.has(key)) continue;
|
|
19
|
-
if (value !== null && value !== void 0) opts[key] = value;
|
|
20
|
-
}
|
|
21
|
-
return opts;
|
|
22
|
-
}
|
|
23
|
-
function parseDocx(opts) {
|
|
24
|
-
const attrs = {};
|
|
25
|
-
for (const [key, value] of Object.entries(opts)) {
|
|
26
|
-
if (SKIP_KEYS.has(key)) continue;
|
|
27
|
-
attrs[key] = value ?? null;
|
|
28
|
-
}
|
|
29
|
-
return attrs;
|
|
30
|
-
}
|
|
31
|
-
const attrNative = () => ({
|
|
32
|
-
default: null,
|
|
33
|
-
parseHTML: () => null,
|
|
34
|
-
rendered: false
|
|
35
|
-
});
|
|
36
|
-
const Table = Table$1.extend({
|
|
37
|
-
addAttributes() {
|
|
38
|
-
return {
|
|
39
|
-
...this.parent?.(),
|
|
40
|
-
width: attrNative(),
|
|
41
|
-
columnWidths: attrNative(),
|
|
42
|
-
indent: attrNative(),
|
|
43
|
-
margins: attrNative(),
|
|
44
|
-
float: attrNative(),
|
|
45
|
-
borders: {
|
|
46
|
-
default: null,
|
|
47
|
-
rendered: false,
|
|
48
|
-
parseHTML: (el) => bordersFromElement(el)
|
|
49
|
-
},
|
|
50
|
-
shading: {
|
|
51
|
-
default: null,
|
|
52
|
-
rendered: false,
|
|
53
|
-
parseHTML: (el) => shadingFromElement(el)
|
|
54
|
-
},
|
|
55
|
-
alignment: {
|
|
56
|
-
default: null,
|
|
57
|
-
rendered: false,
|
|
58
|
-
parseHTML: (el) => alignmentFromElement(el)
|
|
59
|
-
},
|
|
60
|
-
layout: {
|
|
61
|
-
default: null,
|
|
62
|
-
rendered: false,
|
|
63
|
-
parseHTML: (el) => el.style.tableLayout === "fixed" ? "fixed" : null
|
|
64
|
-
},
|
|
65
|
-
style: attrNative(),
|
|
66
|
-
visuallyRightToLeft: attrNative(),
|
|
67
|
-
tableLook: attrNative(),
|
|
68
|
-
cellSpacing: attrNative(),
|
|
69
|
-
styleRowBandSize: attrNative(),
|
|
70
|
-
styleColBandSize: attrNative(),
|
|
71
|
-
caption: attrNative(),
|
|
72
|
-
description: attrNative()
|
|
73
|
-
};
|
|
74
|
-
},
|
|
75
|
-
renderHTML({ node, HTMLAttributes }) {
|
|
76
|
-
const a = node.attrs;
|
|
77
|
-
const attrs = { ...HTMLAttributes };
|
|
78
|
-
const styles = [];
|
|
79
|
-
const align = alignmentToCss(a.alignment);
|
|
80
|
-
if (align === "center") styles.push("margin-left:auto", "margin-right:auto");
|
|
81
|
-
else if (align === "right") styles.push("margin-left:auto", "margin-right:0");
|
|
82
|
-
else if (align) styles.push("margin-left:0", "margin-right:auto");
|
|
83
|
-
if (a.layout === "fixed") styles.push("table-layout:fixed");
|
|
84
|
-
if (a.width && typeof a.width === "object") {
|
|
85
|
-
const w = a.width;
|
|
86
|
-
const numSize = typeof w.size === "string" ? parseFloat(w.size) : w.size;
|
|
87
|
-
if (w.type === "pct") {
|
|
88
|
-
if (!Number.isNaN(numSize)) styles.push(`width:${numSize / 50}%`);
|
|
89
|
-
} else if (numSize != null) {
|
|
90
|
-
const css = twipToCss(numSize);
|
|
91
|
-
if (css) styles.push(`width:${css}`);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (a.indent && typeof a.indent === "object") {
|
|
95
|
-
const ind = a.indent;
|
|
96
|
-
if (ind.size != null) {
|
|
97
|
-
const css = twipToCss(ind.size);
|
|
98
|
-
if (css) styles.push(`margin-left:${css}`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (a.cellSpacing && typeof a.cellSpacing === "object") {
|
|
102
|
-
const cs = a.cellSpacing;
|
|
103
|
-
if (cs.value != null) {
|
|
104
|
-
const css = twipToCss(cs.value);
|
|
105
|
-
if (css) styles.push(`border-spacing:${css}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
const bg = shadingToCss(a.shading);
|
|
109
|
-
if (bg) styles.push(`background-color:${bg}`);
|
|
110
|
-
if (a.borders && typeof a.borders === "object") {
|
|
111
|
-
const b = a.borders;
|
|
112
|
-
const sides = [
|
|
113
|
-
["top", b.top],
|
|
114
|
-
["bottom", b.bottom],
|
|
115
|
-
["left", b.left],
|
|
116
|
-
["right", b.right]
|
|
117
|
-
];
|
|
118
|
-
for (const [side, border] of sides) {
|
|
119
|
-
const css = renderBorderCSS(border);
|
|
120
|
-
if (css) styles.push(`border-${side}:${css}`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (styles.length > 0) attrs.style = styles.join(";");
|
|
124
|
-
return [
|
|
125
|
-
"table",
|
|
126
|
-
attrs,
|
|
127
|
-
0
|
|
128
|
-
];
|
|
129
|
-
},
|
|
130
|
-
renderDocx,
|
|
131
|
-
parseDocx
|
|
132
|
-
});
|
|
133
|
-
//#endregion
|
|
1
|
+
import { n as parseDocx, r as renderDocx, t as Table } from "../table-DrA12lxX.mjs";
|
|
134
2
|
export { Table, parseDocx, renderDocx };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { N as TaskItem } from "../tiptap-TErPjuNJ.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/extensions/task-item.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* TaskItem extension — owns the DOCX expression of a task-list checkbox.
|
|
6
|
+
*
|
|
7
|
+
* DOCX has no native task list, but a clickable checkbox is reversible via an
|
|
8
|
+
* inline content-control SDT (w14:checkbox). Each task paragraph carries a
|
|
9
|
+
* leading checkbox SDT tagged "docen-task" so resolve can tell task items apart
|
|
10
|
+
* from ordinary paragraphs that happen to contain an SDT. The checked state
|
|
11
|
+
* round-trips through the SDT; DocxManager injects/strips the SDT at the
|
|
12
|
+
* paragraph boundary and rebuilds the taskList/taskItem tree.
|
|
13
|
+
*/
|
|
14
|
+
/** SDT tag marking our task-item checkbox content control. */
|
|
15
|
+
declare const TASK_CHECKBOX_TAG = "docen-task";
|
|
16
|
+
/**
|
|
17
|
+
* Inline checkbox SDT (w14:checkbox) for a task item, as a ParagraphChild.
|
|
18
|
+
* Tagged so resolve can distinguish task items from ordinary SDT-bearing
|
|
19
|
+
* paragraphs.
|
|
20
|
+
*/
|
|
21
|
+
declare function createTaskCheckbox(checked: boolean): Record<string, unknown>;
|
|
22
|
+
/** True if an inline ParagraphChild is our task checkbox SDT. */
|
|
23
|
+
declare function isTaskCheckbox(child: unknown): boolean;
|
|
24
|
+
/** Read the checked state of a task checkbox SDT child (false if not one). */
|
|
25
|
+
declare function readCheckboxState(child: unknown): boolean;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { TASK_CHECKBOX_TAG, TaskItem, createTaskCheckbox, isTaskCheckbox, readCheckboxState };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { N as TaskItem } from "../tiptap-D7pl4I5U.mjs";
|
|
2
|
+
import { i as readCheckboxState, n as createTaskCheckbox, r as isTaskCheckbox, t as TASK_CHECKBOX_TAG } from "../task-item-BnlXGrIG.mjs";
|
|
3
|
+
export { TASK_CHECKBOX_TAG, TaskItem, createTaskCheckbox, isTaskCheckbox, readCheckboxState };
|
|
@@ -1,134 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { characterSpacingFromCss, characterSpacingToCss, normalizeColorToHex, resolveFontName, shadingFromCss, shadingToCss, sizeFromCss, sizeToCss } from "./utils.mjs";
|
|
3
|
-
//#region src/extensions/text-style.ts
|
|
4
|
-
/**
|
|
5
|
-
* TextStyle mark with office-open attrs.
|
|
6
|
-
*
|
|
7
|
-
* Attrs mirror RunStylePropertiesOptions (bold/italic/strike/subScript/
|
|
8
|
-
* superScript handled by dedicated marks and therefore omitted). DOCX
|
|
9
|
-
* round-trip is near-identity: renderDocx/parseDocx pass attrs through;
|
|
10
|
-
* CSS conversion happens only in attribute-level renderHTML/parseHTML.
|
|
11
|
-
*/
|
|
12
|
-
/** Structural/semantic keys expressed elsewhere (run children/text, style name). */
|
|
13
|
-
const SKIP_KEYS = new Set([
|
|
14
|
-
"children",
|
|
15
|
-
"text",
|
|
16
|
-
"style",
|
|
17
|
-
"break",
|
|
18
|
-
"bold",
|
|
19
|
-
"italic",
|
|
20
|
-
"strike",
|
|
21
|
-
"doubleStrike",
|
|
22
|
-
"subScript",
|
|
23
|
-
"superScript"
|
|
24
|
-
]);
|
|
25
|
-
function renderDocx(attrs) {
|
|
26
|
-
const opts = {};
|
|
27
|
-
for (const [key, value] of Object.entries(attrs)) {
|
|
28
|
-
if (SKIP_KEYS.has(key)) continue;
|
|
29
|
-
if (value === null || value === void 0) continue;
|
|
30
|
-
opts[key] = value;
|
|
31
|
-
}
|
|
32
|
-
return opts;
|
|
33
|
-
}
|
|
34
|
-
function parseDocx(opts) {
|
|
35
|
-
const resolved = typeof opts === "string" ? { text: opts } : opts;
|
|
36
|
-
const attrs = {};
|
|
37
|
-
for (const [key, value] of Object.entries(resolved)) {
|
|
38
|
-
if (SKIP_KEYS.has(key)) continue;
|
|
39
|
-
attrs[key] = value ?? null;
|
|
40
|
-
}
|
|
41
|
-
return attrs;
|
|
42
|
-
}
|
|
43
|
-
const attrNative = () => ({
|
|
44
|
-
default: null,
|
|
45
|
-
parseHTML: () => null,
|
|
46
|
-
rendered: false
|
|
47
|
-
});
|
|
48
|
-
const TextStyle = TextStyle$1.extend({
|
|
49
|
-
addAttributes() {
|
|
50
|
-
return {
|
|
51
|
-
...this.parent?.(),
|
|
52
|
-
color: {
|
|
53
|
-
default: null,
|
|
54
|
-
parseHTML: (element) => normalizeColorToHex(element.style.color || void 0) ?? null,
|
|
55
|
-
renderHTML: (attributes) => {
|
|
56
|
-
const hex = normalizeColorToHex(attributes.color);
|
|
57
|
-
return hex ? { style: `color:${hex}` } : {};
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
characterSpacing: {
|
|
61
|
-
default: null,
|
|
62
|
-
parseHTML: (element) => characterSpacingFromCss(element.style.letterSpacing || null),
|
|
63
|
-
renderHTML: (attributes) => {
|
|
64
|
-
const css = characterSpacingToCss(attributes.characterSpacing);
|
|
65
|
-
return css ? { style: `letter-spacing:${css}` } : {};
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
font: {
|
|
69
|
-
default: null,
|
|
70
|
-
parseHTML: (element) => element.style.fontFamily || null,
|
|
71
|
-
renderHTML: (attributes) => {
|
|
72
|
-
const name = resolveFontName(attributes.font);
|
|
73
|
-
return name ? { style: `font-family:${name}` } : {};
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
rightToLeft: {
|
|
77
|
-
default: null,
|
|
78
|
-
parseHTML: (element) => element.dir === "rtl" ? true : null,
|
|
79
|
-
renderHTML: (attributes) => attributes.rightToLeft ? { style: "direction:rtl" } : {}
|
|
80
|
-
},
|
|
81
|
-
size: {
|
|
82
|
-
default: null,
|
|
83
|
-
parseHTML: (element) => sizeFromCss(element.style.fontSize),
|
|
84
|
-
renderHTML: (attributes) => {
|
|
85
|
-
const css = sizeToCss(attributes.size);
|
|
86
|
-
return css ? { style: `font-size:${css}` } : {};
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
shading: {
|
|
90
|
-
default: null,
|
|
91
|
-
parseHTML: (element) => shadingFromCss(element.style.backgroundColor),
|
|
92
|
-
renderHTML: (attributes) => {
|
|
93
|
-
const css = shadingToCss(attributes.shading);
|
|
94
|
-
return css ? { style: `background-color:${css}` } : {};
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
underline: attrNative(),
|
|
98
|
-
emphasisMark: attrNative(),
|
|
99
|
-
highlight: attrNative(),
|
|
100
|
-
smallCaps: attrNative(),
|
|
101
|
-
allCaps: attrNative(),
|
|
102
|
-
kern: attrNative(),
|
|
103
|
-
position: attrNative(),
|
|
104
|
-
effect: attrNative(),
|
|
105
|
-
noProof: attrNative(),
|
|
106
|
-
sizeComplexScript: attrNative(),
|
|
107
|
-
highlightComplexScript: attrNative(),
|
|
108
|
-
boldComplexScript: attrNative(),
|
|
109
|
-
italicComplexScript: attrNative(),
|
|
110
|
-
doubleStrike: attrNative(),
|
|
111
|
-
emboss: attrNative(),
|
|
112
|
-
imprint: attrNative(),
|
|
113
|
-
revision: attrNative(),
|
|
114
|
-
language: attrNative(),
|
|
115
|
-
border: attrNative(),
|
|
116
|
-
snapToGrid: attrNative(),
|
|
117
|
-
vanish: attrNative(),
|
|
118
|
-
specVanish: attrNative(),
|
|
119
|
-
scale: attrNative(),
|
|
120
|
-
math: attrNative(),
|
|
121
|
-
outline: attrNative(),
|
|
122
|
-
shadow: attrNative(),
|
|
123
|
-
webHidden: attrNative(),
|
|
124
|
-
fitText: attrNative(),
|
|
125
|
-
complexScript: attrNative(),
|
|
126
|
-
eastAsianLayout: attrNative(),
|
|
127
|
-
contentPartRId: attrNative()
|
|
128
|
-
};
|
|
129
|
-
},
|
|
130
|
-
renderDocx,
|
|
131
|
-
parseDocx
|
|
132
|
-
});
|
|
133
|
-
//#endregion
|
|
1
|
+
import { n as parseDocx, r as renderDocx, t as TextStyle } from "../text-style-tMeBq5XQ.mjs";
|
|
134
2
|
export { TextStyle, parseDocx, renderDocx };
|
|
@@ -1,33 +1,2 @@
|
|
|
1
|
-
import { Document } from "
|
|
2
|
-
import { Text } from "@tiptap/extension-text";
|
|
3
|
-
import { Paragraph } from "@tiptap/extension-paragraph";
|
|
4
|
-
import { Heading } from "@tiptap/extension-heading";
|
|
5
|
-
import { Blockquote } from "@tiptap/extension-blockquote";
|
|
6
|
-
import { HorizontalRule } from "@tiptap/extension-horizontal-rule";
|
|
7
|
-
import { CodeBlockLowlight } from "@tiptap/extension-code-block-lowlight";
|
|
8
|
-
import { BulletList } from "@tiptap/extension-bullet-list";
|
|
9
|
-
import { OrderedList } from "@tiptap/extension-ordered-list";
|
|
10
|
-
import { ListItem } from "@tiptap/extension-list-item";
|
|
11
|
-
import { TaskList } from "@tiptap/extension-task-list";
|
|
12
|
-
import { TaskItem } from "@tiptap/extension-task-item";
|
|
13
|
-
import { Table, TableCell, TableHeader, TableRow } from "@tiptap/extension-table";
|
|
14
|
-
import { Image } from "@tiptap/extension-image";
|
|
15
|
-
import { HardBreak } from "@tiptap/extension-hard-break";
|
|
16
|
-
import { Details, DetailsContent, DetailsSummary } from "@tiptap/extension-details";
|
|
17
|
-
import { Emoji } from "@tiptap/extension-emoji";
|
|
18
|
-
import { Mention } from "@tiptap/extension-mention";
|
|
19
|
-
import { Mathematics } from "@tiptap/extension-mathematics";
|
|
20
|
-
import { Bold } from "@tiptap/extension-bold";
|
|
21
|
-
import { Italic } from "@tiptap/extension-italic";
|
|
22
|
-
import { Underline } from "@tiptap/extension-underline";
|
|
23
|
-
import { Strike } from "@tiptap/extension-strike";
|
|
24
|
-
import { Code } from "@tiptap/extension-code";
|
|
25
|
-
import { Link } from "@tiptap/extension-link";
|
|
26
|
-
import { Highlight } from "@tiptap/extension-highlight";
|
|
27
|
-
import { Subscript } from "@tiptap/extension-subscript";
|
|
28
|
-
import { Superscript } from "@tiptap/extension-superscript";
|
|
29
|
-
import { TextStyle } from "@tiptap/extension-text-style";
|
|
30
|
-
import { TextAlign } from "@tiptap/extension-text-align";
|
|
31
|
-
import { Dropcursor, Gapcursor, TrailingNode, UndoRedo } from "@tiptap/extensions";
|
|
32
|
-
import { ListKeymap } from "@tiptap/extension-list";
|
|
1
|
+
import { A as TableCell, B as UndoRedo, C as Mention, D as Subscript, E as Strike, F as Text, I as TextAlign, L as TextStyle, M as TableRow, N as TaskItem, O as Superscript, P as TaskList, R as TrailingNode, S as Mathematics, T as Paragraph, _ as Image, a as CodeBlockLowlight, b as ListItem, c as DetailsSummary, d as Emoji, f as Gapcursor, g as HorizontalRule, h as Highlight, i as Code, j as TableHeader, k as Table, l as Document, m as Heading, n as Bold, o as Details, p as HardBreak, r as BulletList, s as DetailsContent, t as Blockquote, u as Dropcursor, v as Italic, w as OrderedList, x as ListKeymap, y as Link, z as Underline } from "../tiptap-D7pl4I5U.mjs";
|
|
33
2
|
export { Blockquote, Bold, BulletList, Code, CodeBlockLowlight, Details, DetailsContent, DetailsSummary, Document, Dropcursor, Emoji, Gapcursor, HardBreak, Heading, Highlight, HorizontalRule, Image, Italic, Link, ListItem, ListKeymap, Mathematics, Mention, OrderedList, Paragraph, Strike, Subscript, Superscript, Table, TableCell, TableHeader, TableRow, TaskItem, TaskList, Text, TextAlign, TextStyle, TrailingNode, Underline, UndoRedo };
|
|
@@ -3,19 +3,21 @@ import { RunOptions } from "@office-open/docx";
|
|
|
3
3
|
|
|
4
4
|
//#region src/extensions/types.d.ts
|
|
5
5
|
declare module "@tiptap/core" {
|
|
6
|
-
interface NodeConfig<Options, Storage> {
|
|
6
|
+
interface NodeConfig<Options = any, Storage = any> {
|
|
7
7
|
/**
|
|
8
|
-
* DOCX serialization: Tiptap JSON node → DOCX opts
|
|
9
|
-
*
|
|
8
|
+
* DOCX serialization: Tiptap JSON node → DOCX opts, or null when the node
|
|
9
|
+
* cannot be serialized (e.g. an image with no embedded data — DocxManager
|
|
10
|
+
* then drops it). Each node extension defines this to convert its attrs to
|
|
11
|
+
* DOCX properties.
|
|
10
12
|
*/
|
|
11
|
-
renderDocx?: (node: JSONContent) => Record<string, unknown
|
|
13
|
+
renderDocx?: (node: JSONContent) => Record<string, unknown> | null;
|
|
12
14
|
/**
|
|
13
15
|
* DOCX deserialization: DOCX opts → Tiptap JSON attrs.
|
|
14
16
|
* Each node extension defines this to convert DOCX properties back to attrs.
|
|
15
17
|
*/
|
|
16
18
|
parseDocx?: (opts: Record<string, unknown>) => Record<string, unknown>;
|
|
17
19
|
}
|
|
18
|
-
interface MarkConfig<Options, Storage> {
|
|
20
|
+
interface MarkConfig<Options = any, Storage = any> {
|
|
19
21
|
/**
|
|
20
22
|
* DOCX serialization: mark attrs → RunOptions properties.
|
|
21
23
|
* Each mark extension defines this to contribute run-level properties.
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { BorderOptions, BordersOptions, IndentAttributesProperties, ShadingAttributesProperties, SpacingProperties } from "@office-open/docx";
|
|
2
2
|
|
|
3
3
|
//#region src/extensions/utils.d.ts
|
|
4
|
-
/** Normalize a CSS color value to hex (e.g., "red" → "#FF0000", "#ff0000" → "#FF0000").
|
|
5
|
-
|
|
4
|
+
/** Normalize a CSS color value to hex (e.g., "red" → "#FF0000", "#ff0000" → "#FF0000").
|
|
5
|
+
* Accepts a string (CSS name/hex or bare OOXML hex), or an OOXML ColorOptions
|
|
6
|
+
* object ({ val, themeColor, themeTint, themeShade }) — the object form
|
|
7
|
+
* resolves to its val (the RGB fallback Word stores alongside themeColor) for
|
|
8
|
+
* CSS rendering. The themeColor/tint/shade are preserved verbatim in the attrs
|
|
9
|
+
* and round-trip back to the DOCX (see text-style/paragraph parseDocx), so
|
|
10
|
+
* theme semantics survive even though only val is rendered here. A pure theme
|
|
11
|
+
* reference with no val (rare — Word usually stores both) would need theme.xml
|
|
12
|
+
* to resolve and is left unset. */
|
|
13
|
+
declare function normalizeColorToHex(color: unknown): string | undefined;
|
|
6
14
|
/** Resolve a font value (string or OOXML rFonts { ascii, eastAsia, hAnsi, cs }) to a CSS family name. */
|
|
7
15
|
declare function resolveFontName(font: unknown): string | null;
|
|
8
16
|
/** CSS value (e.g., "18pt") → twip number. 1 pt = 20 twips, 1 px = 15 twips (96 DPI). */
|
|
@@ -30,6 +38,11 @@ declare function renderBorderCSS(border: BorderOptions): string | null;
|
|
|
30
38
|
* Attrs store office-open native values; mappers here convert to CSS.
|
|
31
39
|
*/
|
|
32
40
|
declare function renderParagraphStyles(attrs: Record<string, unknown>): string[];
|
|
41
|
+
/**
|
|
42
|
+
* Compute run-level CSS (font/size/color/weight/…) from office-open run attrs.
|
|
43
|
+
* Shared by text-style marks and the styles→CSS generator (stylesToCss).
|
|
44
|
+
*/
|
|
45
|
+
declare function renderRunStyles(attrs: Record<string, unknown>): string[];
|
|
33
46
|
/**
|
|
34
47
|
* Compute table cell CSS styles from nested attrs.
|
|
35
48
|
* Shared by TableCell and TableHeader extensions.
|
|
@@ -46,4 +59,4 @@ declare function bordersFromElement(el: HTMLElement): BordersOptions | null;
|
|
|
46
59
|
/** Parse background-color → OOXML shading. */
|
|
47
60
|
declare function shadingFromElement(el: HTMLElement): ShadingAttributesProperties | null;
|
|
48
61
|
//#endregion
|
|
49
|
-
export { alignmentFromCss, alignmentFromElement, alignmentToCss, bordersFromElement, characterSpacingFromCss, characterSpacingToCss, cssToTwip, indentFromElement, lineSpacingToCss, normalizeColorToHex, renderBorderCSS, renderParagraphStyles, renderTableCellStyles, resolveFontName, shadingFromCss, shadingFromElement, shadingToCss, sizeFromCss, sizeToCss, spacingFromElement, twipToCss };
|
|
62
|
+
export { alignmentFromCss, alignmentFromElement, alignmentToCss, bordersFromElement, characterSpacingFromCss, characterSpacingToCss, cssToTwip, indentFromElement, lineSpacingToCss, normalizeColorToHex, renderBorderCSS, renderParagraphStyles, renderRunStyles, renderTableCellStyles, resolveFontName, shadingFromCss, shadingFromElement, shadingToCss, sizeFromCss, sizeToCss, spacingFromElement, twipToCss };
|