@docen/docx 0.3.1 → 0.3.2

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 (109) hide show
  1. package/dist/converters/docx.d.mts +199 -1
  2. package/dist/converters/docx.mjs +1273 -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 +84 -1
  12. package/dist/converters/styles.mjs +284 -1
  13. package/dist/core-C9VunJ8o.d.mts +174 -0
  14. package/dist/core-DT9IrTzN.mjs +670 -0
  15. package/dist/core.d.mts +1 -1
  16. package/dist/core.mjs +1 -1
  17. package/dist/editor.d.mts +20 -1
  18. package/dist/editor.mjs +20 -1
  19. package/dist/extensions/blockquote.d.mts +1 -1
  20. package/dist/extensions/blockquote.mjs +30 -2
  21. package/dist/extensions/code-block.d.mts +1 -1
  22. package/dist/extensions/code-block.mjs +22 -1
  23. package/dist/extensions/column-break.d.mts +1 -1
  24. package/dist/extensions/column-break.mjs +1 -1
  25. package/dist/extensions/details.d.mts +1 -1
  26. package/dist/extensions/details.mjs +17 -2
  27. package/dist/extensions/document.mjs +49 -1
  28. package/dist/extensions/extensions.d.mts +3 -4
  29. package/dist/extensions/extensions.mjs +13 -14
  30. package/dist/extensions/formatting-marks.d.mts +7 -1
  31. package/dist/extensions/formatting-marks.mjs +1 -1
  32. package/dist/extensions/heading.mjs +165 -1
  33. package/dist/extensions/image.d.mts +1 -1
  34. package/dist/extensions/image.mjs +395 -1
  35. package/dist/extensions/index.d.mts +3 -2
  36. package/dist/extensions/index.mjs +4 -3
  37. package/dist/extensions/mention.d.mts +1 -1
  38. package/dist/extensions/mention.mjs +43 -2
  39. package/dist/extensions/ordered-list.d.mts +1 -1
  40. package/dist/extensions/ordered-list.mjs +40 -2
  41. package/dist/extensions/page-break.d.mts +1 -33
  42. package/dist/extensions/page-break.mjs +1 -1
  43. package/dist/extensions/paragraph.mjs +150 -1
  44. package/dist/extensions/passthrough.d.mts +1 -1
  45. package/dist/extensions/passthrough.mjs +1 -1
  46. package/dist/extensions/section-break.d.mts +19 -2
  47. package/dist/extensions/section-break.mjs +1 -1
  48. package/dist/extensions/strike.mjs +49 -1
  49. package/dist/extensions/table-cell.mjs +111 -1
  50. package/dist/extensions/table-header.mjs +111 -1
  51. package/dist/extensions/table-row.mjs +83 -1
  52. package/dist/extensions/table.mjs +159 -1
  53. package/dist/extensions/task-item.d.mts +1 -1
  54. package/dist/extensions/task-item.mjs +36 -2
  55. package/dist/extensions/text-style.mjs +150 -1
  56. package/dist/extensions/tiptap.d.mts +2 -2
  57. package/dist/extensions/tiptap.mjs +31 -2
  58. package/dist/extensions/utils.d.mts +2 -62
  59. package/dist/extensions/utils.mjs +499 -2
  60. package/dist/extensions/wpg-group.d.mts +2 -0
  61. package/dist/extensions/wpg-group.mjs +2 -0
  62. package/dist/extensions/wps-shape.d.mts +2 -0
  63. package/dist/extensions/wps-shape.mjs +2 -0
  64. package/dist/index.d.mts +86 -27
  65. package/dist/index.mjs +13 -10
  66. package/dist/{tiptap-TErPjuNJ.d.mts → tiptap-pZsNPsvV.d.mts} +1 -3
  67. package/dist/utils-D87vukzp.d.mts +128 -0
  68. package/package.json +39 -40
  69. package/dist/blockquote-Ky9xD_Q-.mjs +0 -31
  70. package/dist/code-block-BgNjhADy.mjs +0 -23
  71. package/dist/core-DEqBHRzE.mjs +0 -406
  72. package/dist/core-fBMCCj4D.d.mts +0 -97
  73. package/dist/details-Dh8luWb2.mjs +0 -18
  74. package/dist/dist-B6B3HnVZ.mjs +0 -1838
  75. package/dist/document-CvTym-FM.mjs +0 -50
  76. package/dist/docx-C5wyjI-0.d.mts +0 -200
  77. package/dist/docx-CONyAedl.mjs +0 -1231
  78. package/dist/editor-Bf3CxQnY.mjs +0 -21
  79. package/dist/editor-DReY3Rb9.d.mts +0 -21
  80. package/dist/emoji-BZ1dJD7d.d.mts +0 -17
  81. package/dist/emoji-C2OsTWR7.mjs +0 -27
  82. package/dist/extensions/emoji.d.mts +0 -2
  83. package/dist/extensions/emoji.mjs +0 -2
  84. package/dist/extensions/image-group.d.mts +0 -6
  85. package/dist/extensions/image-group.mjs +0 -2
  86. package/dist/heading-DAubgJJN.mjs +0 -166
  87. package/dist/html-DCC_DSHv.d.mts +0 -18
  88. package/dist/html-DedDWPoO.mjs +0 -66
  89. package/dist/image-CuEIXoZl.mjs +0 -334
  90. package/dist/markdown-BzJmRsBs.mjs +0 -18
  91. package/dist/markdown-D0k0sRYS.d.mts +0 -13
  92. package/dist/mention-C-dTR6MK.mjs +0 -44
  93. package/dist/ordered-list-V-3xFQmV.mjs +0 -41
  94. package/dist/paragraph-BrWH-BOV.mjs +0 -147
  95. package/dist/patch-Cdp5WKJz.d.mts +0 -53
  96. package/dist/patch-IZ13tXTu.mjs +0 -36
  97. package/dist/prepare-Bdk8Cjkf.mjs +0 -122
  98. package/dist/prepare-CPAvcv6q.d.mts +0 -63
  99. package/dist/strike-hWxShOgb.mjs +0 -50
  100. package/dist/styles-QSX3RhxK.mjs +0 -285
  101. package/dist/styles-ugspkrxz.d.mts +0 -85
  102. package/dist/table-DrA12lxX.mjs +0 -159
  103. package/dist/table-cell-DmkfYwDc.mjs +0 -112
  104. package/dist/table-header-Bwr5GKWg.mjs +0 -112
  105. package/dist/table-row-vew1y7WH.mjs +0 -84
  106. package/dist/task-item-BnlXGrIG.mjs +0 -37
  107. package/dist/text-style-tMeBq5XQ.mjs +0 -151
  108. package/dist/tiptap-D7pl4I5U.mjs +0 -33
  109. package/dist/utils-BPT4tjcn.mjs +0 -333
@@ -1,2 +1,499 @@
1
- import { S as twipToCss, _ as shadingFromElement, a as characterSpacingFromCss, b as sizeToCss, c as indentFromElement, d as renderBorderCSS, f as renderParagraphStyles, g as shadingFromCss, h as resolveFontName, i as bordersFromElement, l as lineSpacingToCss, m as renderTableCellStyles, n as alignmentFromElement, o as characterSpacingToCss, p as renderRunStyles, r as alignmentToCss, s as cssToTwip, t as alignmentFromCss, u as normalizeColorToHex, v as shadingToCss, x as spacingFromElement, y as sizeFromCss } from "../utils-BPT4tjcn.mjs";
2
- export { alignmentFromCss, alignmentFromElement, alignmentToCss, bordersFromElement, characterSpacingFromCss, characterSpacingToCss, cssToTwip, indentFromElement, lineSpacingToCss, normalizeColorToHex, renderBorderCSS, renderParagraphStyles, renderRunStyles, renderTableCellStyles, resolveFontName, shadingFromCss, shadingFromElement, shadingToCss, sizeFromCss, sizeToCss, spacingFromElement, twipToCss };
1
+ import { sectionMarginDefaults, sectionPageSizeDefaults } from "@office-open/docx";
2
+ //#region src/extensions/utils.ts
3
+ /** Common CSS named colors → hex */
4
+ const CSS_COLORS = {
5
+ black: "#000000",
6
+ white: "#FFFFFF",
7
+ red: "#FF0000",
8
+ green: "#008000",
9
+ blue: "#0000FF",
10
+ yellow: "#FFFF00",
11
+ cyan: "#00FFFF",
12
+ magenta: "#FF00FF",
13
+ gray: "#808080",
14
+ grey: "#808080",
15
+ orange: "#FFA500",
16
+ purple: "#800080",
17
+ pink: "#FFC0CB",
18
+ brown: "#A52A2A",
19
+ lime: "#00FF00",
20
+ navy: "#000080",
21
+ teal: "#008080",
22
+ silver: "#C0C0C0",
23
+ maroon: "#800000",
24
+ olive: "#808000",
25
+ aqua: "#00FFFF",
26
+ fuchsia: "#FF00FF",
27
+ indigo: "#4B0082",
28
+ violet: "#EE82EE",
29
+ coral: "#FF7F50",
30
+ gold: "#FFD700",
31
+ salmon: "#FA8072",
32
+ tomato: "#FF6347"
33
+ };
34
+ /** Normalize a CSS color value to hex (e.g., "red" → "#FF0000", "#ff0000" → "#FF0000").
35
+ * Accepts a string (CSS name/hex or bare OOXML hex), or an OOXML ColorOptions
36
+ * object ({ val, themeColor, themeTint, themeShade }) — the object form
37
+ * resolves to its val (the RGB fallback Word stores alongside themeColor) for
38
+ * CSS rendering. The themeColor/tint/shade are preserved verbatim in the attrs
39
+ * and round-trip back to the DOCX (see text-style/paragraph parseDocx), so
40
+ * theme semantics survive even though only val is rendered here. A pure theme
41
+ * reference with no val (rare — Word usually stores both) would need theme.xml
42
+ * to resolve and is left unset. */
43
+ function normalizeColorToHex(color) {
44
+ if (!color) return void 0;
45
+ if (typeof color === "object") {
46
+ const { val } = color;
47
+ return val ? normalizeColorToHex(val) : void 0;
48
+ }
49
+ if (typeof color !== "string") return void 0;
50
+ if (color === "auto") return void 0;
51
+ if (color.startsWith("#")) return color.length === 4 ? `#${color[1]}${color[1]}${color[2]}${color[2]}${color[3]}${color[3]}`.toUpperCase() : color.toUpperCase();
52
+ if (/^[0-9A-Fa-f]{6}$/.test(color)) return `#${color.toUpperCase()}`;
53
+ if (/^[0-9A-Fa-f]{3}$/.test(color)) return `#${color[0]}${color[0]}${color[1]}${color[1]}${color[2]}${color[2]}`.toUpperCase();
54
+ return CSS_COLORS[color.toLowerCase()] ?? void 0;
55
+ }
56
+ /** Resolve a font value (string or OOXML rFonts { ascii, eastAsia, hAnsi, cs }) to a CSS family name. */
57
+ function resolveFontName(font) {
58
+ if (!font) return null;
59
+ if (typeof font === "string") return font;
60
+ if (typeof font === "object") {
61
+ const f = font;
62
+ return f.ascii || f.hAnsi || f.eastAsia || null;
63
+ }
64
+ return null;
65
+ }
66
+ /** Resolve a font value to a CSS font-family list with an eastAsia fallback.
67
+ * Mirrors Word's per-Unicode-range font selection (MS-OE376): Basic Latin uses
68
+ * the ascii font, CJK Ideographs use eastAsia. CSS can't split a run by range,
69
+ * so list ascii first (it carries Basic Latin glyphs) then eastAsia — the
70
+ * browser falls back to eastAsia for CJK chars the ascii font lacks. Without
71
+ * this, CJK text renders in the ascii font (e.g. Times) instead of the
72
+ * document's CJK font (e.g. SimSun). Use this for font-family rendering;
73
+ * resolveFontName (single name) stays for UI/parse. */
74
+ function resolveFontFamilyCss(font) {
75
+ if (!font) return null;
76
+ if (typeof font === "string") return font;
77
+ if (typeof font === "object") {
78
+ const f = font;
79
+ const ascii = f.ascii || f.hAnsi;
80
+ const ea = f.eastAsia;
81
+ if (ascii && ea && ascii !== ea) return `"${ascii}","${ea}"`;
82
+ return ascii || ea || null;
83
+ }
84
+ return null;
85
+ }
86
+ /** CSS value (e.g., "18pt") → twip number. 1 pt = 20 twips, 1 px = 15 twips (96 DPI). */
87
+ function cssToTwip(value) {
88
+ if (!value) return void 0;
89
+ const match = value.match(/^([\d.]+)(pt|px|em|cm|in)?$/);
90
+ if (!match) return void 0;
91
+ const num = parseFloat(match[1]);
92
+ switch (match[2] ?? "pt") {
93
+ case "pt": return Math.round(num * 20);
94
+ case "px": return Math.round(num * 15);
95
+ case "in": return Math.round(num * 1440);
96
+ case "cm": return Math.round(num * 567);
97
+ case "em": return Math.round(num * 240);
98
+ default: return Math.round(num * 20);
99
+ }
100
+ }
101
+ /** Twip value → CSS string (e.g., 360 → "18pt"). */
102
+ function twipToCss(value) {
103
+ if (value == null) return null;
104
+ if (typeof value === "string") return value;
105
+ return `${value / 20}pt`;
106
+ }
107
+ const ALIGNMENT_TO_CSS = {
108
+ left: "left",
109
+ center: "center",
110
+ right: "right",
111
+ start: "start",
112
+ end: "end",
113
+ both: "justify",
114
+ distribute: "justify"
115
+ };
116
+ const CSS_TO_ALIGNMENT = {
117
+ left: "left",
118
+ center: "center",
119
+ right: "right",
120
+ start: "start",
121
+ end: "end",
122
+ justify: "both"
123
+ };
124
+ /** OOXML alignment → CSS text-align. */
125
+ function alignmentToCss(alignment) {
126
+ if (!alignment) return null;
127
+ return ALIGNMENT_TO_CSS[alignment] ?? null;
128
+ }
129
+ /** CSS text-align → OOXML alignment. */
130
+ function alignmentFromCss(css) {
131
+ if (!css) return null;
132
+ return CSS_TO_ALIGNMENT[css] ?? null;
133
+ }
134
+ /** Shading.fill → CSS background-color hex. */
135
+ function shadingToCss(shading) {
136
+ if (!shading?.fill) return null;
137
+ return normalizeColorToHex(shading.fill) ?? null;
138
+ }
139
+ /** CSS background-color → ShadingAttributesProperties (fill normalized to hex). */
140
+ function shadingFromCss(css) {
141
+ const hex = normalizeColorToHex(css ?? void 0);
142
+ return hex ? {
143
+ fill: hex,
144
+ type: "clear"
145
+ } : null;
146
+ }
147
+ function lineSpacingToCss(spacing, snapToGrid = null) {
148
+ if (!spacing?.line) return null;
149
+ const rule = spacing.lineRule;
150
+ if (rule === "exact" || rule === "exactly" || rule === "atLeast") return `${Number(spacing.line) / 20}pt`;
151
+ if (snapToGrid === false) return `calc(var(--docen-font-metric, 1.2) * ${Number((Number(spacing.line) / 240).toFixed(2))} * var(--docen-line-base, 1em))`;
152
+ return `calc(var(--docen-font-metric, 1.2) * var(--docen-line-base, 1em) + var(--docen-line-pitch, 0pt))`;
153
+ }
154
+ /** twips → mm (1 in = 1440 tw = 25.4 mm), 2dp string. */
155
+ function twipsToMm(twips) {
156
+ return `${(twips / 1440 * 25.4).toFixed(2)}mm`;
157
+ }
158
+ /** Resolve a section's printable page dimensions (twips), honoring orientation.
159
+ * A landscape section commonly stores portrait dims (w<h) with
160
+ * `orientation: "landscape"` — swap width/height so width is the larger edge.
161
+ * Falls back to the engine's default page size (@office-open/docx
162
+ * `sectionPageSizeDefaults` = A4) when the size is absent or non-numeric — the
163
+ * engine's `stringifySectionPropertiesXml` fills an empty sectPr the same way,
164
+ * so edit-time geometry matches render/measure/generate/export. */
165
+ function resolvePageSize(size) {
166
+ const fallback = {
167
+ width: sectionPageSizeDefaults.WIDTH,
168
+ height: sectionPageSizeDefaults.HEIGHT
169
+ };
170
+ if (!size || typeof size !== "object") return fallback;
171
+ const s = size;
172
+ const w = typeof s.width === "number" ? s.width : void 0;
173
+ const h = typeof s.height === "number" ? s.height : void 0;
174
+ if (w == null || h == null) return fallback;
175
+ return s.orientation === "landscape" && w < h ? {
176
+ width: h,
177
+ height: w
178
+ } : {
179
+ width: w,
180
+ height: h
181
+ };
182
+ }
183
+ /** Page margin (twips) → CSS padding. Sides absent or non-numeric fall back to
184
+ * the engine's default margins (@office-open/docx `sectionMarginDefaults`:
185
+ * top/bottom 1440tw, left/right 1800tw — MS Office zh-CN "Normal"), matching
186
+ * the page-size fallback above and the engine's empty-sectPr behavior. Margins
187
+ * are left as-is: office-open returns them already rotated for a landscape
188
+ * section. */
189
+ function sectionMarginCss(margin) {
190
+ const def = sectionMarginDefaults;
191
+ const m = margin && typeof margin === "object" ? margin : {};
192
+ const num = (v, d) => typeof v === "number" ? v : d;
193
+ return `padding:${[
194
+ num(m.top, def.TOP),
195
+ num(m.right, def.RIGHT),
196
+ num(m.bottom, def.BOTTOM),
197
+ num(m.left, def.LEFT)
198
+ ].map(twipsToMm).join(" ")}`;
199
+ }
200
+ /** Document grid linePitch (twips) → container CSS line-height.
201
+ * Per ECMA-376 snapToGrid, the grid linePitch is ADDED to each line (single-
202
+ * line paragraphs inherit it). So the container line-height (inherited by
203
+ * paragraphs without their own spacing) is the font's `normal` metric + the
204
+ * grid pitch, set only when the grid type enables line-snapping (not
205
+ * "default"). The --docen-line-pitch var carries the pitch so per-paragraph
206
+ * lineSpacingToCss can add the same pitch; --docen-font-metric is injected per
207
+ * paragraph by the editor; 1.2 is the fallback for static HTML export. */
208
+ function sectionLinePitchCss(grid) {
209
+ if (!grid || typeof grid !== "object") return [];
210
+ const g = grid;
211
+ if (!g.type || g.type === "default" || typeof g.linePitch !== "number" || !g.linePitch) return [];
212
+ const pitch = `${(g.linePitch / 20).toFixed(2)}pt`;
213
+ return [`line-height:calc(var(--docen-font-metric, 1.2) * 1em + ${pitch})`, `--docen-line-pitch:${pitch}`];
214
+ }
215
+ function sizeToCss(size) {
216
+ if (size == null) return null;
217
+ return `${size}pt`;
218
+ }
219
+ function sizeFromCss(css) {
220
+ if (!css) return null;
221
+ const m = css.match(/^([\d.]+)(pt|px)?$/);
222
+ if (!m) return null;
223
+ const num = parseFloat(m[1]);
224
+ return (m[2] ?? "pt") === "px" ? num * .75 : num;
225
+ }
226
+ function characterSpacingToCss(spacing) {
227
+ if (spacing == null) return null;
228
+ return `${spacing / 20}pt`;
229
+ }
230
+ function characterSpacingFromCss(css) {
231
+ if (!css) return null;
232
+ const m = css.match(/^(-?[\d.]+)pt$/);
233
+ return m ? Math.round(parseFloat(m[1]) * 20) : null;
234
+ }
235
+ /** Render a BorderOptions to CSS string. OOXML border.size is in eighths of a point. */
236
+ function renderBorderCSS(border) {
237
+ if (!border || !border.style || border.style === "none" || border.style === "nil") return null;
238
+ const size = border.size != null ? `${border.size / 8}pt` : "1pt";
239
+ const cssStyle = {
240
+ single: "solid",
241
+ dashed: "dashed",
242
+ dotted: "dotted",
243
+ double: "double",
244
+ dotDash: "dashed",
245
+ dotDotDash: "dotted",
246
+ dashSmallGap: "dashed"
247
+ }[border.style || "single"] || "solid";
248
+ const hex = border.color && border.color !== "auto" ? normalizeColorToHex(border.color) : null;
249
+ return hex ? `${cssStyle} ${size} ${hex}` : `${cssStyle} ${size}`;
250
+ }
251
+ const EMU_PER_PX = 9525;
252
+ const EMU_PER_PT = 12700;
253
+ /**
254
+ * Render a drawing's Floating anchor (wp:anchor) to CSS — shared by Image and
255
+ * WpgGroup so anchored drawings render consistently:
256
+ * - wrapNone (type 0): position:absolute at the EMU offset (text does not flow
257
+ * around it — "in front of text" / "behind text"); z-index lifts it above or
258
+ * below the text layer per behindDocument.
259
+ * - topAndBottom (3): float + clear:both.
260
+ * - square/tight/through (1/2/4): with an hPos.offset, float:right pulled to
261
+ * the offset via margin-right so text wraps beside it with no overlap;
262
+ * otherwise float on the wrap side (tight/through add shape-outside, src).
263
+ * Wrap margins (wp:distT/B/L/R) are EMU, rendered as pt.
264
+ */
265
+ function floatingToStyles(floating, src, width) {
266
+ const f = floating;
267
+ if (!f) return [];
268
+ const styles = [];
269
+ styles.push(`z-index:${f.behindDocument ? -1 : f.zIndex ?? 1}`);
270
+ const wrapType = f.wrap?.type ?? 0;
271
+ const hOff = f.horizontalPosition?.offset;
272
+ const vOff = f.verticalPosition?.offset;
273
+ if (wrapType === 0) {
274
+ styles.push("position:absolute");
275
+ if (hOff != null) styles.push(`left:${(hOff / EMU_PER_PX).toFixed(1)}px`);
276
+ if (vOff != null) styles.push(`top:${(vOff / EMU_PER_PX).toFixed(1)}px`);
277
+ } else if (wrapType !== 3 && hOff != null && width != null) {
278
+ const offPx = (hOff / EMU_PER_PX).toFixed(1);
279
+ styles.push("float:right", `margin-right:calc(100% - ${offPx}px - ${width}px)`);
280
+ if (vOff != null) styles.push(`margin-top:${(vOff / EMU_PER_PX).toFixed(1)}px`);
281
+ const m = f.margins;
282
+ if (m?.left) styles.push(`margin-left:${(m.left / EMU_PER_PT).toFixed(1)}pt`);
283
+ } else if (wrapType === 3) styles.push("float:left", "clear:both");
284
+ else {
285
+ const side = f.wrap?.side;
286
+ const floatSide = side === "right" || side === "outside" ? "right" : "left";
287
+ styles.push(`float:${floatSide}`);
288
+ if ((wrapType === 2 || wrapType === 4) && src) styles.push(`shape-outside:url(${src})`);
289
+ }
290
+ if (!(wrapType !== 0 && wrapType !== 3 && hOff != null && width != null) && wrapType !== 0) {
291
+ const m = f.margins;
292
+ if (m) {
293
+ if (m.top) styles.push(`margin-top:${(m.top / EMU_PER_PT).toFixed(1)}pt`);
294
+ if (m.bottom) styles.push(`margin-bottom:${(m.bottom / EMU_PER_PT).toFixed(1)}pt`);
295
+ if (m.left) styles.push(`margin-left:${(m.left / EMU_PER_PT).toFixed(1)}pt`);
296
+ if (m.right) styles.push(`margin-right:${(m.right / EMU_PER_PT).toFixed(1)}pt`);
297
+ }
298
+ }
299
+ return styles;
300
+ }
301
+ /**
302
+ * Where a wrapNone floating drawing's absolute top/left should resolve from.
303
+ *
304
+ * verticalPosition.relative (OOXML vRelativeFrom) defaults to "paragraph"
305
+ * (also "line"); "page"/"margin"/"column" scope to the page box. The drawing is
306
+ * position:absolute, so its offsetParent decides the origin: a
307
+ * paragraph-anchored drawing must sit inside a position:relative <p> (the editor
308
+ * CSS adds that via p:has([data-float-anchor])), otherwise top/left measure
309
+ * from the page top and the drawing floats over the heading/body instead of
310
+ * its own blank paragraph (verified on sample anchored drawing groups). Only
311
+ * relevant for wrapNone (type 0); the float-based wraps stay inline.
312
+ */
313
+ function floatAnchorScope(floating) {
314
+ const vRel = floating?.verticalPosition?.relative;
315
+ if (vRel === "page" || vRel === "margin" || vRel === "column") return "page";
316
+ return "paragraph";
317
+ }
318
+ /**
319
+ * Compute all paragraph-level CSS styles from nested attrs.
320
+ * Shared by Paragraph and Heading extensions for node-level renderHTML.
321
+ * Attrs store office-open native values; mappers here convert to CSS.
322
+ */
323
+ function renderParagraphStyles(attrs, opts) {
324
+ const a = attrs;
325
+ const styles = [];
326
+ const align = alignmentToCss(a.alignment);
327
+ if (align) styles.push(`text-align:${align}`);
328
+ if (a.indent) {
329
+ const left = twipToCss(a.indent.left);
330
+ if (left) styles.push(`margin-left:${left}`);
331
+ const right = twipToCss(a.indent.right);
332
+ if (right) styles.push(`margin-right:${right}`);
333
+ if (a.indent.firstLine != null) {
334
+ const fl = twipToCss(a.indent.firstLine);
335
+ if (fl) styles.push(`text-indent:${fl}`);
336
+ } else if (a.indent.hanging != null) {
337
+ const h = twipToCss(a.indent.hanging);
338
+ if (h) styles.push(`text-indent:-${h}`);
339
+ } else if (a.indent.firstLineChars != null) styles.push(`text-indent:${a.indent.firstLineChars / 100}em`);
340
+ }
341
+ const markLineHeight = a.run?.size != null ? sizeToCss(a.run.size) : null;
342
+ if (markLineHeight) styles.push(`line-height:${markLineHeight}`);
343
+ if (a.spacing) {
344
+ const before = twipToCss(a.spacing.before);
345
+ if (before) styles.push(`margin-top:${before}`);
346
+ const after = twipToCss(a.spacing.after);
347
+ if (after) styles.push(`margin-bottom:${after}`);
348
+ const lh = lineSpacingToCss(a.spacing, opts?.empty ? false : a.snapToGrid);
349
+ if (lh) styles.push(`line-height:${lh}`);
350
+ }
351
+ const bg = shadingToCss(a.shading);
352
+ if (bg) styles.push(`background-color:${bg}`, `color:contrast-color(${bg})`);
353
+ if (a.border) {
354
+ const sides = [
355
+ ["top", a.border.top],
356
+ ["bottom", a.border.bottom],
357
+ ["left", a.border.left],
358
+ ["right", a.border.right]
359
+ ];
360
+ for (const [side, b] of sides) {
361
+ const css = b ? renderBorderCSS(b) : null;
362
+ if (css) styles.push(`border-${side}:${css}`);
363
+ }
364
+ }
365
+ return styles;
366
+ }
367
+ /**
368
+ * Compute run-level CSS (font/size/color/weight/…) from office-open run attrs.
369
+ * Shared by text-style marks and the styles→CSS generator (stylesToCss).
370
+ */
371
+ function renderRunStyles(attrs) {
372
+ const a = attrs;
373
+ const styles = [];
374
+ if (a.bold) styles.push("font-weight:bold");
375
+ if (a.italic) styles.push("font-style:italic");
376
+ if (a.smallCaps) styles.push("font-variant:small-caps");
377
+ if (a.allCaps) styles.push("text-transform:uppercase");
378
+ const deco = [];
379
+ if (a.underline) deco.push("underline");
380
+ if (a.strike || a.doubleStrike) deco.push("line-through");
381
+ if (deco.length) styles.push(`text-decoration:${deco.join(" ")}`);
382
+ const font = resolveFontFamilyCss(a.font);
383
+ if (font) styles.push(`font-family:${font}`);
384
+ const size = sizeToCss(a.size);
385
+ if (size) styles.push(`font-size:${size}`);
386
+ const color = a.color === "auto" ? void 0 : normalizeColorToHex(a.color);
387
+ if (color) styles.push(`color:${color}`);
388
+ const spacing = characterSpacingToCss(a.characterSpacing);
389
+ if (spacing) styles.push(`letter-spacing:${spacing}`);
390
+ if (a.highlight) {
391
+ const hl = normalizeColorToHex(typeof a.highlight === "string" ? a.highlight : null);
392
+ if (hl) styles.push(`background-color:${hl}`, `color:contrast-color(${hl})`);
393
+ }
394
+ return styles;
395
+ }
396
+ /**
397
+ * Compute table cell CSS styles from nested attrs.
398
+ * Shared by TableCell and TableHeader extensions.
399
+ */
400
+ function renderTableCellStyles(attrs) {
401
+ const a = attrs;
402
+ const styles = [];
403
+ if (a.noWrap) styles.push("white-space:nowrap");
404
+ const bg = shadingToCss(a.shading);
405
+ if (bg) styles.push(`background-color:${bg}`, `color:contrast-color(${bg})`);
406
+ if (a.verticalAlign) styles.push(`vertical-align:${a.verticalAlign}`);
407
+ if (a.margins) {
408
+ const m = a.margins;
409
+ const side = (s) => s && typeof s.size === "number" ? twipToCss(s.size) ?? "0pt" : "0pt";
410
+ styles.push(`padding:${side(m.top)} ${side(m.right)} ${side(m.bottom)} ${side(m.left)}`);
411
+ }
412
+ if (a.borders) for (const side of [
413
+ "top",
414
+ "right",
415
+ "bottom",
416
+ "left"
417
+ ]) {
418
+ const b = a.borders[side];
419
+ if (!b) continue;
420
+ styles.push(`border-${side}:${renderBorderCSS(b) ?? "none"}`);
421
+ }
422
+ return styles;
423
+ }
424
+ /** Parse text-align → OOXML alignment. */
425
+ function alignmentFromElement(el) {
426
+ return alignmentFromCss(el.style.textAlign || null);
427
+ }
428
+ /** Parse margin-left/right + text-indent → OOXML indent (twips). */
429
+ function indentFromElement(el) {
430
+ const indent = {};
431
+ const left = cssToTwip(el.style.marginLeft);
432
+ if (left) indent.left = left;
433
+ const right = cssToTwip(el.style.marginRight);
434
+ if (right) indent.right = right;
435
+ const ti = el.style.textIndent;
436
+ if (ti) if (ti.startsWith("-")) {
437
+ const h = cssToTwip(ti.slice(1));
438
+ if (h) indent.hanging = h;
439
+ } else {
440
+ const f = cssToTwip(ti);
441
+ if (f) indent.firstLine = f;
442
+ }
443
+ return Object.keys(indent).length > 0 ? indent : null;
444
+ }
445
+ /** Parse margin-top/bottom + line-height → OOXML spacing (twips). */
446
+ function spacingFromElement(el) {
447
+ const spacing = {};
448
+ const before = cssToTwip(el.style.marginTop);
449
+ if (before) spacing.before = before;
450
+ const after = cssToTwip(el.style.marginBottom);
451
+ if (after) spacing.after = after;
452
+ const lh = el.style.lineHeight;
453
+ if (lh) {
454
+ const m = lh.match(/^([\d.]+)(pt|px)?$/);
455
+ if (m) {
456
+ const num = parseFloat(m[1]);
457
+ if (m[2]) {
458
+ spacing.line = Math.round(num * (m[2] === "px" ? 15 : 20));
459
+ spacing.lineRule = "exact";
460
+ } else {
461
+ spacing.line = Math.round(num * 240);
462
+ spacing.lineRule = "auto";
463
+ }
464
+ }
465
+ }
466
+ return Object.keys(spacing).length > 0 ? spacing : null;
467
+ }
468
+ /** Parse border-* → OOXML BordersOptions. */
469
+ function bordersFromElement(el) {
470
+ const borders = {};
471
+ const sides = [
472
+ ["top", el.style.borderTop],
473
+ ["bottom", el.style.borderBottom],
474
+ ["left", el.style.borderLeft],
475
+ ["right", el.style.borderRight]
476
+ ];
477
+ for (const [side, css] of sides) {
478
+ if (!css || css === "initial" || css === "none") continue;
479
+ const m = css.match(/^(none|solid|dashed|dotted|double)\s+([\d.]+pt)\s+(.+)$/);
480
+ if (!m) continue;
481
+ borders[side] = {
482
+ style: {
483
+ solid: "single",
484
+ dashed: "dashed",
485
+ dotted: "dotted",
486
+ double: "double"
487
+ }[m[1]] ?? "single",
488
+ size: Math.round(parseFloat(m[2]) * 8),
489
+ color: m[3]
490
+ };
491
+ }
492
+ return Object.keys(borders).length > 0 ? borders : null;
493
+ }
494
+ /** Parse background-color → OOXML shading. */
495
+ function shadingFromElement(el) {
496
+ return shadingFromCss(el.style.backgroundColor || null);
497
+ }
498
+ //#endregion
499
+ export { alignmentFromCss, alignmentFromElement, alignmentToCss, bordersFromElement, characterSpacingFromCss, characterSpacingToCss, cssToTwip, floatAnchorScope, floatingToStyles, indentFromElement, lineSpacingToCss, normalizeColorToHex, renderBorderCSS, renderParagraphStyles, renderRunStyles, renderTableCellStyles, resolveFontFamilyCss, resolveFontName, resolvePageSize, sectionLinePitchCss, sectionMarginCss, shadingFromCss, shadingFromElement, shadingToCss, sizeFromCss, sizeToCss, spacingFromElement, twipToCss, twipsToMm };
@@ -0,0 +1,2 @@
1
+ import { _ as WpgGroup, b as renderWpsText, v as WpsData, y as renderWpsInterior } from "../core-C9VunJ8o.mjs";
2
+ export { WpgGroup, WpsData, renderWpsInterior, renderWpsText };
@@ -0,0 +1,2 @@
1
+ import { d as WpgGroup, f as renderWpsInterior, p as renderWpsText } from "../core-DT9IrTzN.mjs";
2
+ export { WpgGroup, renderWpsInterior, renderWpsText };
@@ -0,0 +1,2 @@
1
+ import { g as WpsShape } from "../core-C9VunJ8o.mjs";
2
+ export { WpsShape };
@@ -0,0 +1,2 @@
1
+ import { u as WpsShape } from "../core-DT9IrTzN.mjs";
2
+ export { WpsShape };