@docen/extensions 0.2.5 → 0.2.6
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/index.mjs +35 -10
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -132,15 +132,15 @@ const Heading = Heading$1.extend({ addAttributes() {
|
|
|
132
132
|
*
|
|
133
133
|
* Adds DOCX-specific attributes for round-trip conversion:
|
|
134
134
|
* - rotation: Image rotation in degrees (rendered as CSS transform)
|
|
135
|
-
* - floating: Image positioning
|
|
135
|
+
* - floating: Image positioning and text wrapping (rendered as CSS float/position/z-index)
|
|
136
136
|
* - outline: Image border/outline options (stored as data-outline attribute)
|
|
137
137
|
* - crop: Image crop rectangle (resized element + object-fit/position)
|
|
138
138
|
*
|
|
139
139
|
* HTML serialization strategy:
|
|
140
|
-
* - rotation:
|
|
141
|
-
* - floating:
|
|
140
|
+
* - rotation: CSS transform merged into floating/crop renderHTML output
|
|
141
|
+
* - floating: CSS float/position/z-index/margin + preserved as data-floating JSON attribute
|
|
142
142
|
* - outline: Preserved as data-outline JSON attribute (no CSS equivalent)
|
|
143
|
-
* - crop: object-fit
|
|
143
|
+
* - crop: CSS object-fit/position (merged with floating style when both present)
|
|
144
144
|
*/
|
|
145
145
|
/**
|
|
146
146
|
* Generate crop rendering attributes.
|
|
@@ -164,7 +164,7 @@ const Image = Image$1.extend({ addAttributes() {
|
|
|
164
164
|
display: {
|
|
165
165
|
default: null,
|
|
166
166
|
parseHTML: () => this.options.inline ? "inline-block" : null,
|
|
167
|
-
renderHTML: () =>
|
|
167
|
+
renderHTML: () => ({})
|
|
168
168
|
},
|
|
169
169
|
rotation: {
|
|
170
170
|
default: null,
|
|
@@ -172,10 +172,7 @@ const Image = Image$1.extend({ addAttributes() {
|
|
|
172
172
|
const rotationMatch = (element.getAttribute("style") || "").match(/transform:\s*rotate\(([\d.]+)deg\)/);
|
|
173
173
|
return rotationMatch ? parseFloat(rotationMatch[1]) : null;
|
|
174
174
|
},
|
|
175
|
-
renderHTML: (
|
|
176
|
-
if (!attributes.rotation) return {};
|
|
177
|
-
return { style: `transform: rotate(${attributes.rotation}deg)` };
|
|
178
|
-
}
|
|
175
|
+
renderHTML: () => ({})
|
|
179
176
|
},
|
|
180
177
|
floating: {
|
|
181
178
|
default: null,
|
|
@@ -190,7 +187,35 @@ const Image = Image$1.extend({ addAttributes() {
|
|
|
190
187
|
},
|
|
191
188
|
renderHTML: (attributes) => {
|
|
192
189
|
if (!attributes.floating) return {};
|
|
193
|
-
|
|
190
|
+
const f = attributes.floating;
|
|
191
|
+
const styles = [];
|
|
192
|
+
if (attributes.rotation) styles.push(`transform:rotate(${attributes.rotation}deg)`);
|
|
193
|
+
styles.push(f.behindDocument ? "z-index:-1" : "z-index:1");
|
|
194
|
+
const wrapType = f.wrap?.type ?? 0;
|
|
195
|
+
if (wrapType === 0) styles.push("position:absolute");
|
|
196
|
+
else if (wrapType === 1) {
|
|
197
|
+
const align = f.horizontalPosition?.align;
|
|
198
|
+
if (align === "left" || align === "inside") styles.push("float:left");
|
|
199
|
+
else if (align === "right" || align === "outside") styles.push("float:right");
|
|
200
|
+
else styles.push("float:left");
|
|
201
|
+
} else if (wrapType === 2) {
|
|
202
|
+
styles.push("float:left");
|
|
203
|
+
styles.push("shape-outside:margin-box");
|
|
204
|
+
} else if (wrapType === 3) {
|
|
205
|
+
styles.push("display:block");
|
|
206
|
+
styles.push("clear:both");
|
|
207
|
+
} else styles.push("display:inline-block");
|
|
208
|
+
const m = f.margins;
|
|
209
|
+
if (m) {
|
|
210
|
+
if (m.top) styles.push(`margin-top:${(m.top * 96 / 1440).toFixed(1)}pt`);
|
|
211
|
+
if (m.bottom) styles.push(`margin-bottom:${(m.bottom * 96 / 1440).toFixed(1)}pt`);
|
|
212
|
+
if (m.left) styles.push(`margin-left:${(m.left * 96 / 1440).toFixed(1)}pt`);
|
|
213
|
+
if (m.right) styles.push(`margin-right:${(m.right * 96 / 1440).toFixed(1)}pt`);
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
style: styles.join(";"),
|
|
217
|
+
"data-floating": JSON.stringify(f)
|
|
218
|
+
};
|
|
194
219
|
}
|
|
195
220
|
},
|
|
196
221
|
outline: {
|