@docen/extensions 0.1.3 → 0.2.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/dist/index.d.mts CHANGED
@@ -23,23 +23,6 @@ import { AnyExtension } from "@tiptap/core";
23
23
  declare const Heading: _$_tiptap_core0.Node<_$_tiptap_extension_heading0.HeadingOptions, any>;
24
24
  //#endregion
25
25
  //#region src/extends/image.d.ts
26
- /**
27
- * Custom Image extension based on @tiptap/extension-image
28
- *
29
- * Adds DOCX-specific attributes for round-trip conversion:
30
- * - rotation: Image rotation in degrees (rendered as CSS transform)
31
- * - floating: Image positioning options (stored as data-floating attribute)
32
- * - outline: Image border/outline options (stored as data-outline attribute)
33
- *
34
- * HTML serialization strategy:
35
- * - rotation: Mapped to CSS transform: rotate()
36
- * - floating: Preserved as data-floating JSON attribute (no CSS equivalent)
37
- * - outline: Preserved as data-outline JSON attribute (no CSS equivalent)
38
- *
39
- * Note: floating and outline are DOCX-specific features without direct CSS
40
- * equivalents. They're preserved in HTML for round-trip conversion but only
41
- * affect DOCX export/import.
42
- */
43
26
  declare const Image: _$_tiptap_core0.Node<_$_tiptap_extension_image0.ImageOptions, any>;
44
27
  //#endregion
45
28
  //#region src/extends/paragraph.d.ts
package/dist/index.mjs CHANGED
@@ -75,16 +75,30 @@ const Heading = Heading$1.extend({ addAttributes() {
75
75
  * - rotation: Image rotation in degrees (rendered as CSS transform)
76
76
  * - floating: Image positioning options (stored as data-floating attribute)
77
77
  * - outline: Image border/outline options (stored as data-outline attribute)
78
+ * - crop: Image crop rectangle (resized element + object-fit/position)
78
79
  *
79
80
  * HTML serialization strategy:
80
81
  * - rotation: Mapped to CSS transform: rotate()
81
82
  * - floating: Preserved as data-floating JSON attribute (no CSS equivalent)
82
83
  * - outline: Preserved as data-outline JSON attribute (no CSS equivalent)
83
- *
84
- * Note: floating and outline are DOCX-specific features without direct CSS
85
- * equivalents. They're preserved in HTML for round-trip conversion but only
86
- * affect DOCX export/import.
84
+ * - crop: object-fit: cover + object-position (element size already reflects crop)
85
+ */
86
+ /**
87
+ * Generate crop rendering attributes.
88
+ * Uses object-fit/position to show the correct portion within the element's
89
+ * existing dimensions (which already reflect the cropped bounding box from wp:extent).
87
90
  */
91
+ function renderCropAttrs(crop) {
92
+ const leftPct = (crop.left || 0) / 1e5;
93
+ const topPct = (crop.top || 0) / 1e5;
94
+ const rightPct = (crop.right || 0) / 1e5;
95
+ const bottomPct = (crop.bottom || 0) / 1e5;
96
+ const visibleWidthPct = 1 - leftPct - rightPct;
97
+ const visibleHeightPct = 1 - topPct - bottomPct;
98
+ const posX = visibleWidthPct > 0 ? leftPct / visibleWidthPct * 100 : 0;
99
+ const posY = visibleHeightPct > 0 ? topPct / visibleHeightPct * 100 : 0;
100
+ return { style: `object-fit:cover;object-position:${posX.toFixed(2)}% ${posY.toFixed(2)}%` };
101
+ }
88
102
  const Image = Image$1.extend({ addAttributes() {
89
103
  return {
90
104
  ...this.parent?.(),
@@ -135,6 +149,25 @@ const Image = Image$1.extend({ addAttributes() {
135
149
  if (!attributes.outline) return {};
136
150
  return { "data-outline": JSON.stringify(attributes.outline) };
137
151
  }
152
+ },
153
+ crop: {
154
+ default: null,
155
+ parseHTML: (element) => {
156
+ const dataCrop = element.getAttribute("data-crop");
157
+ if (!dataCrop) return null;
158
+ try {
159
+ return JSON.parse(dataCrop);
160
+ } catch {
161
+ return null;
162
+ }
163
+ },
164
+ renderHTML: (attributes) => {
165
+ if (!attributes.crop) return {};
166
+ return {
167
+ ...renderCropAttrs(attributes.crop),
168
+ "data-crop": JSON.stringify(attributes.crop)
169
+ };
170
+ }
138
171
  }
139
172
  };
140
173
  } });