@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.
- package/dist/converters/docx.d.mts +220 -1
- package/dist/converters/docx.mjs +1352 -1
- package/dist/converters/html.d.mts +28 -1
- package/dist/converters/html.mjs +103 -1
- package/dist/converters/markdown.d.mts +12 -1
- package/dist/converters/markdown.mjs +17 -1
- package/dist/converters/patch.d.mts +52 -1
- package/dist/converters/patch.mjs +35 -1
- package/dist/converters/prepare.d.mts +62 -1
- package/dist/converters/prepare.mjs +121 -1
- package/dist/converters/styles.d.mts +91 -2
- package/dist/converters/styles.mjs +308 -2
- package/dist/core-B8ba_FNi.mjs +717 -0
- package/dist/core-DRaLI8nd.d.mts +203 -0
- package/dist/core.d.mts +1 -1
- package/dist/core.mjs +1 -1
- package/dist/document-Cws7XTYL.d.mts +28 -0
- package/dist/editor.d.mts +20 -1
- package/dist/editor.mjs +20 -1
- package/dist/extensions/blockquote.d.mts +1 -1
- package/dist/extensions/blockquote.mjs +30 -2
- package/dist/extensions/code-block.d.mts +1 -1
- package/dist/extensions/code-block.mjs +22 -1
- package/dist/extensions/column-break.d.mts +1 -1
- package/dist/extensions/column-break.mjs +1 -1
- package/dist/extensions/details.d.mts +1 -1
- package/dist/extensions/details.mjs +17 -2
- package/dist/extensions/document.d.mts +1 -1
- package/dist/extensions/document.mjs +45 -1
- package/dist/extensions/extensions.d.mts +4 -5
- package/dist/extensions/extensions.mjs +13 -14
- package/dist/extensions/formatting-marks.d.mts +7 -1
- package/dist/extensions/formatting-marks.mjs +1 -1
- package/dist/extensions/heading.mjs +187 -1
- package/dist/extensions/image.d.mts +1 -1
- package/dist/extensions/image.mjs +395 -1
- package/dist/extensions/index.d.mts +4 -3
- package/dist/extensions/index.mjs +4 -3
- package/dist/extensions/mention.d.mts +1 -1
- package/dist/extensions/mention.mjs +43 -2
- package/dist/extensions/ordered-list.d.mts +1 -1
- package/dist/extensions/ordered-list.mjs +40 -2
- package/dist/extensions/page-break.d.mts +1 -33
- package/dist/extensions/page-break.mjs +1 -1
- package/dist/extensions/paragraph.mjs +145 -1
- package/dist/extensions/passthrough.d.mts +1 -1
- package/dist/extensions/passthrough.mjs +1 -1
- package/dist/extensions/section-break.d.mts +19 -2
- package/dist/extensions/section-break.mjs +1 -1
- package/dist/extensions/strike.mjs +45 -1
- package/dist/extensions/table-cell.mjs +106 -1
- package/dist/extensions/table-header.mjs +106 -1
- package/dist/extensions/table-row.mjs +78 -1
- package/dist/extensions/table.mjs +154 -1
- package/dist/extensions/task-item.d.mts +1 -1
- package/dist/extensions/task-item.mjs +36 -2
- package/dist/extensions/text-style.mjs +145 -1
- package/dist/extensions/tiptap.d.mts +2 -2
- package/dist/extensions/tiptap.mjs +31 -2
- package/dist/extensions/toc-field.d.mts +2 -0
- package/dist/extensions/toc-field.mjs +2 -0
- package/dist/extensions/utils.d.mts +2 -62
- package/dist/extensions/utils.mjs +508 -2
- package/dist/extensions/wpg-group.d.mts +2 -0
- package/dist/extensions/wpg-group.mjs +2 -0
- package/dist/extensions/wps-shape.d.mts +2 -0
- package/dist/extensions/wps-shape.mjs +2 -0
- package/dist/index.d.mts +101 -29
- package/dist/index.mjs +13 -10
- package/dist/{tiptap-TErPjuNJ.d.mts → tiptap-pZsNPsvV.d.mts} +1 -3
- package/dist/utils-BJwDQts7.d.mts +137 -0
- package/package.json +39 -40
- package/dist/blockquote-Ky9xD_Q-.mjs +0 -31
- package/dist/code-block-BgNjhADy.mjs +0 -23
- package/dist/core-DEqBHRzE.mjs +0 -406
- package/dist/core-fBMCCj4D.d.mts +0 -97
- package/dist/details-Dh8luWb2.mjs +0 -18
- package/dist/dist-B6B3HnVZ.mjs +0 -1838
- package/dist/document-BH1y4qHM.d.mts +0 -6
- package/dist/document-CvTym-FM.mjs +0 -50
- package/dist/docx-C5wyjI-0.d.mts +0 -200
- package/dist/docx-CONyAedl.mjs +0 -1231
- package/dist/editor-Bf3CxQnY.mjs +0 -21
- package/dist/editor-DReY3Rb9.d.mts +0 -21
- package/dist/emoji-BZ1dJD7d.d.mts +0 -17
- package/dist/emoji-C2OsTWR7.mjs +0 -27
- package/dist/extensions/emoji.d.mts +0 -2
- package/dist/extensions/emoji.mjs +0 -2
- package/dist/extensions/image-group.d.mts +0 -6
- package/dist/extensions/image-group.mjs +0 -2
- package/dist/heading-DAubgJJN.mjs +0 -166
- package/dist/html-DCC_DSHv.d.mts +0 -18
- package/dist/html-DedDWPoO.mjs +0 -66
- package/dist/image-CuEIXoZl.mjs +0 -334
- package/dist/markdown-BzJmRsBs.mjs +0 -18
- package/dist/markdown-D0k0sRYS.d.mts +0 -13
- package/dist/mention-C-dTR6MK.mjs +0 -44
- package/dist/ordered-list-V-3xFQmV.mjs +0 -41
- package/dist/paragraph-BrWH-BOV.mjs +0 -147
- package/dist/patch-Cdp5WKJz.d.mts +0 -53
- package/dist/patch-IZ13tXTu.mjs +0 -36
- package/dist/prepare-Bdk8Cjkf.mjs +0 -122
- package/dist/prepare-CPAvcv6q.d.mts +0 -63
- package/dist/strike-hWxShOgb.mjs +0 -50
- package/dist/styles-QSX3RhxK.mjs +0 -285
- package/dist/styles-ugspkrxz.d.mts +0 -85
- package/dist/table-DrA12lxX.mjs +0 -159
- package/dist/table-cell-DmkfYwDc.mjs +0 -112
- package/dist/table-header-Bwr5GKWg.mjs +0 -112
- package/dist/table-row-vew1y7WH.mjs +0 -84
- package/dist/task-item-BnlXGrIG.mjs +0 -37
- package/dist/text-style-tMeBq5XQ.mjs +0 -151
- package/dist/tiptap-D7pl4I5U.mjs +0 -33
- package/dist/utils-BPT4tjcn.mjs +0 -333
package/dist/utils-BPT4tjcn.mjs
DELETED
|
@@ -1,333 +0,0 @@
|
|
|
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
|
-
* Accepts a string (CSS name/hex or bare OOXML hex), or an OOXML ColorOptions
|
|
35
|
-
* object ({ val, themeColor, themeTint, themeShade }) — the object form
|
|
36
|
-
* resolves to its val (the RGB fallback Word stores alongside themeColor) for
|
|
37
|
-
* CSS rendering. The themeColor/tint/shade are preserved verbatim in the attrs
|
|
38
|
-
* and round-trip back to the DOCX (see text-style/paragraph parseDocx), so
|
|
39
|
-
* theme semantics survive even though only val is rendered here. A pure theme
|
|
40
|
-
* reference with no val (rare — Word usually stores both) would need theme.xml
|
|
41
|
-
* to resolve and is left unset. */
|
|
42
|
-
function normalizeColorToHex(color) {
|
|
43
|
-
if (!color) return void 0;
|
|
44
|
-
if (typeof color === "object") {
|
|
45
|
-
const { val } = color;
|
|
46
|
-
return val ? normalizeColorToHex(val) : void 0;
|
|
47
|
-
}
|
|
48
|
-
if (typeof color !== "string") return void 0;
|
|
49
|
-
if (color === "auto") return void 0;
|
|
50
|
-
if (color.startsWith("#")) return color.length === 4 ? `#${color[1]}${color[1]}${color[2]}${color[2]}${color[3]}${color[3]}`.toUpperCase() : color.toUpperCase();
|
|
51
|
-
if (/^[0-9A-Fa-f]{6}$/.test(color)) return `#${color.toUpperCase()}`;
|
|
52
|
-
if (/^[0-9A-Fa-f]{3}$/.test(color)) return `#${color[0]}${color[0]}${color[1]}${color[1]}${color[2]}${color[2]}`.toUpperCase();
|
|
53
|
-
return CSS_COLORS[color.toLowerCase()] ?? void 0;
|
|
54
|
-
}
|
|
55
|
-
/** Resolve a font value (string or OOXML rFonts { ascii, eastAsia, hAnsi, cs }) to a CSS family name. */
|
|
56
|
-
function resolveFontName(font) {
|
|
57
|
-
if (!font) return null;
|
|
58
|
-
if (typeof font === "string") return font;
|
|
59
|
-
if (typeof font === "object") {
|
|
60
|
-
const f = font;
|
|
61
|
-
return f.ascii || f.hAnsi || f.eastAsia || null;
|
|
62
|
-
}
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
/** CSS value (e.g., "18pt") → twip number. 1 pt = 20 twips, 1 px = 15 twips (96 DPI). */
|
|
66
|
-
function cssToTwip(value) {
|
|
67
|
-
if (!value) return void 0;
|
|
68
|
-
const match = value.match(/^([\d.]+)(pt|px|em|cm|in)?$/);
|
|
69
|
-
if (!match) return void 0;
|
|
70
|
-
const num = parseFloat(match[1]);
|
|
71
|
-
switch (match[2] ?? "pt") {
|
|
72
|
-
case "pt": return Math.round(num * 20);
|
|
73
|
-
case "px": return Math.round(num * 15);
|
|
74
|
-
case "in": return Math.round(num * 1440);
|
|
75
|
-
case "cm": return Math.round(num * 567);
|
|
76
|
-
case "em": return Math.round(num * 240);
|
|
77
|
-
default: return Math.round(num * 20);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/** Twip value → CSS string (e.g., 360 → "18pt"). */
|
|
81
|
-
function twipToCss(value) {
|
|
82
|
-
if (value == null) return null;
|
|
83
|
-
if (typeof value === "string") return value;
|
|
84
|
-
return `${value / 20}pt`;
|
|
85
|
-
}
|
|
86
|
-
const ALIGNMENT_TO_CSS = {
|
|
87
|
-
left: "left",
|
|
88
|
-
center: "center",
|
|
89
|
-
right: "right",
|
|
90
|
-
start: "start",
|
|
91
|
-
end: "end",
|
|
92
|
-
both: "justify",
|
|
93
|
-
distribute: "justify"
|
|
94
|
-
};
|
|
95
|
-
const CSS_TO_ALIGNMENT = {
|
|
96
|
-
left: "left",
|
|
97
|
-
center: "center",
|
|
98
|
-
right: "right",
|
|
99
|
-
start: "start",
|
|
100
|
-
end: "end",
|
|
101
|
-
justify: "both"
|
|
102
|
-
};
|
|
103
|
-
/** OOXML alignment → CSS text-align. */
|
|
104
|
-
function alignmentToCss(alignment) {
|
|
105
|
-
if (!alignment) return null;
|
|
106
|
-
return ALIGNMENT_TO_CSS[alignment] ?? null;
|
|
107
|
-
}
|
|
108
|
-
/** CSS text-align → OOXML alignment. */
|
|
109
|
-
function alignmentFromCss(css) {
|
|
110
|
-
if (!css) return null;
|
|
111
|
-
return CSS_TO_ALIGNMENT[css] ?? null;
|
|
112
|
-
}
|
|
113
|
-
/** Shading.fill → CSS background-color hex. */
|
|
114
|
-
function shadingToCss(shading) {
|
|
115
|
-
if (!shading?.fill) return null;
|
|
116
|
-
return normalizeColorToHex(shading.fill) ?? null;
|
|
117
|
-
}
|
|
118
|
-
/** CSS background-color → ShadingAttributesProperties (fill normalized to hex). */
|
|
119
|
-
function shadingFromCss(css) {
|
|
120
|
-
const hex = normalizeColorToHex(css ?? void 0);
|
|
121
|
-
return hex ? {
|
|
122
|
-
fill: hex,
|
|
123
|
-
type: "clear"
|
|
124
|
-
} : null;
|
|
125
|
-
}
|
|
126
|
-
function lineSpacingToCss(spacing) {
|
|
127
|
-
if (!spacing?.line) return null;
|
|
128
|
-
const rule = spacing.lineRule;
|
|
129
|
-
if (rule === "exact" || rule === "exactly" || rule === "atLeast") return `${spacing.line / 20}pt`;
|
|
130
|
-
return `calc(var(--docen-line-pitch, 1em) * ${Number((spacing.line / 240).toFixed(2))})`;
|
|
131
|
-
}
|
|
132
|
-
function sizeToCss(size) {
|
|
133
|
-
if (size == null) return null;
|
|
134
|
-
return `${size}pt`;
|
|
135
|
-
}
|
|
136
|
-
function sizeFromCss(css) {
|
|
137
|
-
if (!css) return null;
|
|
138
|
-
const m = css.match(/^([\d.]+)(pt|px)?$/);
|
|
139
|
-
if (!m) return null;
|
|
140
|
-
const num = parseFloat(m[1]);
|
|
141
|
-
return (m[2] ?? "pt") === "px" ? num * .75 : num;
|
|
142
|
-
}
|
|
143
|
-
function characterSpacingToCss(spacing) {
|
|
144
|
-
if (spacing == null) return null;
|
|
145
|
-
return `${spacing / 20}pt`;
|
|
146
|
-
}
|
|
147
|
-
function characterSpacingFromCss(css) {
|
|
148
|
-
if (!css) return null;
|
|
149
|
-
const m = css.match(/^(-?[\d.]+)pt$/);
|
|
150
|
-
return m ? Math.round(parseFloat(m[1]) * 20) : null;
|
|
151
|
-
}
|
|
152
|
-
/** Render a BorderOptions to CSS string. OOXML border.size is in eighths of a point. */
|
|
153
|
-
function renderBorderCSS(border) {
|
|
154
|
-
if (!border || !border.style || border.style === "none" || border.style === "nil") return null;
|
|
155
|
-
const size = border.size != null ? `${border.size / 8}pt` : "1pt";
|
|
156
|
-
const cssStyle = {
|
|
157
|
-
single: "solid",
|
|
158
|
-
dashed: "dashed",
|
|
159
|
-
dotted: "dotted",
|
|
160
|
-
double: "double",
|
|
161
|
-
dotDash: "dashed",
|
|
162
|
-
dotDotDash: "dotted"
|
|
163
|
-
}[border.style || "single"] || "solid";
|
|
164
|
-
const hex = border.color && border.color !== "auto" ? normalizeColorToHex(border.color) : null;
|
|
165
|
-
return hex ? `${cssStyle} ${size} ${hex}` : `${cssStyle} ${size}`;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Compute all paragraph-level CSS styles from nested attrs.
|
|
169
|
-
* Shared by Paragraph and Heading extensions for node-level renderHTML.
|
|
170
|
-
* Attrs store office-open native values; mappers here convert to CSS.
|
|
171
|
-
*/
|
|
172
|
-
function renderParagraphStyles(attrs) {
|
|
173
|
-
const a = attrs;
|
|
174
|
-
const styles = [];
|
|
175
|
-
const align = alignmentToCss(a.alignment);
|
|
176
|
-
if (align) styles.push(`text-align:${align}`);
|
|
177
|
-
if (a.indent) {
|
|
178
|
-
const left = twipToCss(a.indent.left);
|
|
179
|
-
if (left) styles.push(`margin-left:${left}`);
|
|
180
|
-
const right = twipToCss(a.indent.right);
|
|
181
|
-
if (right) styles.push(`margin-right:${right}`);
|
|
182
|
-
if (a.indent.firstLine != null) {
|
|
183
|
-
const fl = twipToCss(a.indent.firstLine);
|
|
184
|
-
if (fl) styles.push(`text-indent:${fl}`);
|
|
185
|
-
} else if (a.indent.hanging != null) {
|
|
186
|
-
const h = twipToCss(a.indent.hanging);
|
|
187
|
-
if (h) styles.push(`text-indent:-${h}`);
|
|
188
|
-
} else if (a.indent.firstLineChars != null) styles.push(`text-indent:${a.indent.firstLineChars / 100}em`);
|
|
189
|
-
}
|
|
190
|
-
const markLineHeight = a.run?.size != null ? sizeToCss(a.run.size) : null;
|
|
191
|
-
if (markLineHeight) styles.push(`line-height:${markLineHeight}`);
|
|
192
|
-
if (a.spacing) {
|
|
193
|
-
const before = twipToCss(a.spacing.before);
|
|
194
|
-
if (before) styles.push(`margin-top:${before}`);
|
|
195
|
-
const after = twipToCss(a.spacing.after);
|
|
196
|
-
if (after) styles.push(`margin-bottom:${after}`);
|
|
197
|
-
const lh = lineSpacingToCss(a.spacing);
|
|
198
|
-
if (lh) styles.push(`line-height:${lh}`);
|
|
199
|
-
}
|
|
200
|
-
const bg = shadingToCss(a.shading);
|
|
201
|
-
if (bg) styles.push(`background-color:${bg}`, `color:contrast-color(${bg})`);
|
|
202
|
-
if (a.border) {
|
|
203
|
-
const sides = [
|
|
204
|
-
["top", a.border.top],
|
|
205
|
-
["bottom", a.border.bottom],
|
|
206
|
-
["left", a.border.left],
|
|
207
|
-
["right", a.border.right]
|
|
208
|
-
];
|
|
209
|
-
for (const [side, b] of sides) {
|
|
210
|
-
const css = b ? renderBorderCSS(b) : null;
|
|
211
|
-
if (css) styles.push(`border-${side}:${css}`);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return styles;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Compute run-level CSS (font/size/color/weight/…) from office-open run attrs.
|
|
218
|
-
* Shared by text-style marks and the styles→CSS generator (stylesToCss).
|
|
219
|
-
*/
|
|
220
|
-
function renderRunStyles(attrs) {
|
|
221
|
-
const a = attrs;
|
|
222
|
-
const styles = [];
|
|
223
|
-
if (a.bold) styles.push("font-weight:bold");
|
|
224
|
-
if (a.italic) styles.push("font-style:italic");
|
|
225
|
-
if (a.smallCaps) styles.push("font-variant:small-caps");
|
|
226
|
-
if (a.allCaps) styles.push("text-transform:uppercase");
|
|
227
|
-
const deco = [];
|
|
228
|
-
if (a.underline) deco.push("underline");
|
|
229
|
-
if (a.strike || a.doubleStrike) deco.push("line-through");
|
|
230
|
-
if (deco.length) styles.push(`text-decoration:${deco.join(" ")}`);
|
|
231
|
-
const font = resolveFontName(a.font);
|
|
232
|
-
if (font) styles.push(`font-family:${font}`);
|
|
233
|
-
const size = sizeToCss(a.size);
|
|
234
|
-
if (size) styles.push(`font-size:${size}`);
|
|
235
|
-
const color = a.color === "auto" ? void 0 : normalizeColorToHex(a.color);
|
|
236
|
-
if (color) styles.push(`color:${color}`);
|
|
237
|
-
const spacing = characterSpacingToCss(a.characterSpacing);
|
|
238
|
-
if (spacing) styles.push(`letter-spacing:${spacing}`);
|
|
239
|
-
if (a.highlight) {
|
|
240
|
-
const hl = normalizeColorToHex(typeof a.highlight === "string" ? a.highlight : null);
|
|
241
|
-
if (hl) styles.push(`background-color:${hl}`, `color:contrast-color(${hl})`);
|
|
242
|
-
}
|
|
243
|
-
return styles;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Compute table cell CSS styles from nested attrs.
|
|
247
|
-
* Shared by TableCell and TableHeader extensions.
|
|
248
|
-
*/
|
|
249
|
-
function renderTableCellStyles(attrs) {
|
|
250
|
-
const a = attrs;
|
|
251
|
-
const styles = [];
|
|
252
|
-
if (a.noWrap) styles.push("white-space:nowrap");
|
|
253
|
-
const bg = shadingToCss(a.shading);
|
|
254
|
-
if (bg) styles.push(`background-color:${bg}`, `color:contrast-color(${bg})`);
|
|
255
|
-
if (a.verticalAlign) styles.push(`vertical-align:${a.verticalAlign}`);
|
|
256
|
-
return styles;
|
|
257
|
-
}
|
|
258
|
-
/** Parse text-align → OOXML alignment. */
|
|
259
|
-
function alignmentFromElement(el) {
|
|
260
|
-
return alignmentFromCss(el.style.textAlign || null);
|
|
261
|
-
}
|
|
262
|
-
/** Parse margin-left/right + text-indent → OOXML indent (twips). */
|
|
263
|
-
function indentFromElement(el) {
|
|
264
|
-
const indent = {};
|
|
265
|
-
const left = cssToTwip(el.style.marginLeft);
|
|
266
|
-
if (left) indent.left = left;
|
|
267
|
-
const right = cssToTwip(el.style.marginRight);
|
|
268
|
-
if (right) indent.right = right;
|
|
269
|
-
const ti = el.style.textIndent;
|
|
270
|
-
if (ti) if (ti.startsWith("-")) {
|
|
271
|
-
const h = cssToTwip(ti.slice(1));
|
|
272
|
-
if (h) indent.hanging = h;
|
|
273
|
-
} else {
|
|
274
|
-
const f = cssToTwip(ti);
|
|
275
|
-
if (f) indent.firstLine = f;
|
|
276
|
-
}
|
|
277
|
-
return Object.keys(indent).length > 0 ? indent : null;
|
|
278
|
-
}
|
|
279
|
-
/** Parse margin-top/bottom + line-height → OOXML spacing (twips). */
|
|
280
|
-
function spacingFromElement(el) {
|
|
281
|
-
const spacing = {};
|
|
282
|
-
const before = cssToTwip(el.style.marginTop);
|
|
283
|
-
if (before) spacing.before = before;
|
|
284
|
-
const after = cssToTwip(el.style.marginBottom);
|
|
285
|
-
if (after) spacing.after = after;
|
|
286
|
-
const lh = el.style.lineHeight;
|
|
287
|
-
if (lh) {
|
|
288
|
-
const m = lh.match(/^([\d.]+)(pt|px)?$/);
|
|
289
|
-
if (m) {
|
|
290
|
-
const num = parseFloat(m[1]);
|
|
291
|
-
if (m[2]) {
|
|
292
|
-
spacing.line = Math.round(num * (m[2] === "px" ? 15 : 20));
|
|
293
|
-
spacing.lineRule = "exact";
|
|
294
|
-
} else {
|
|
295
|
-
spacing.line = Math.round(num * 240);
|
|
296
|
-
spacing.lineRule = "auto";
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
return Object.keys(spacing).length > 0 ? spacing : null;
|
|
301
|
-
}
|
|
302
|
-
/** Parse border-* → OOXML BordersOptions. */
|
|
303
|
-
function bordersFromElement(el) {
|
|
304
|
-
const borders = {};
|
|
305
|
-
const sides = [
|
|
306
|
-
["top", el.style.borderTop],
|
|
307
|
-
["bottom", el.style.borderBottom],
|
|
308
|
-
["left", el.style.borderLeft],
|
|
309
|
-
["right", el.style.borderRight]
|
|
310
|
-
];
|
|
311
|
-
for (const [side, css] of sides) {
|
|
312
|
-
if (!css || css === "initial" || css === "none") continue;
|
|
313
|
-
const m = css.match(/^(none|solid|dashed|dotted|double)\s+([\d.]+pt)\s+(.+)$/);
|
|
314
|
-
if (!m) continue;
|
|
315
|
-
borders[side] = {
|
|
316
|
-
style: {
|
|
317
|
-
solid: "single",
|
|
318
|
-
dashed: "dashed",
|
|
319
|
-
dotted: "dotted",
|
|
320
|
-
double: "double"
|
|
321
|
-
}[m[1]] ?? "single",
|
|
322
|
-
size: Math.round(parseFloat(m[2]) * 8),
|
|
323
|
-
color: m[3]
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
return Object.keys(borders).length > 0 ? borders : null;
|
|
327
|
-
}
|
|
328
|
-
/** Parse background-color → OOXML shading. */
|
|
329
|
-
function shadingFromElement(el) {
|
|
330
|
-
return shadingFromCss(el.style.backgroundColor || null);
|
|
331
|
-
}
|
|
332
|
-
//#endregion
|
|
333
|
-
export { twipToCss as S, shadingFromElement as _, characterSpacingFromCss as a, sizeToCss as b, indentFromElement as c, renderBorderCSS as d, renderParagraphStyles as f, shadingFromCss as g, resolveFontName as h, bordersFromElement as i, lineSpacingToCss as l, renderTableCellStyles as m, alignmentFromElement as n, characterSpacingToCss as o, renderRunStyles as p, alignmentToCss as r, cssToTwip as s, alignmentFromCss as t, normalizeColorToHex as u, shadingToCss as v, spacingFromElement as x, sizeFromCss as y };
|