@jhits/plugin-images 0.0.4 → 0.0.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.
@@ -0,0 +1,306 @@
1
+ /**
2
+ * Image setup and click handlers
3
+ */
4
+
5
+ import type { SelectedImage } from './types';
6
+ import { parseImageData } from './imageDetection';
7
+ import { parseScaleFromTransform, parsePositionFromTransform } from './transformParsing';
8
+ import { detectStyling } from './stylingDetection';
9
+
10
+ /**
11
+ * Setup click handlers and hover effects for all images
12
+ */
13
+ export function setupImageHandlers(
14
+ onImageClick: (image: SelectedImage) => void
15
+ ): () => void {
16
+ const cleanupFunctions: Array<() => void> = [];
17
+
18
+ const handleImageClick = (e: MouseEvent) => {
19
+ const target = e.target as HTMLElement;
20
+
21
+ // Only handle clicks on images that use the plugin components
22
+ let img = target.closest('img[data-image-id]') as HTMLImageElement | null;
23
+ let isBackground = false;
24
+ let element: HTMLElement | null = null;
25
+ let currentSrc = '';
26
+
27
+ if (img) {
28
+ // This is a plugin Image component
29
+ element = img;
30
+ currentSrc = img.src;
31
+ } else {
32
+ // Check if it's an element with background-image
33
+ let bgElement = target.closest('[data-background-image-component]') as HTMLElement | null;
34
+
35
+ if (bgElement) {
36
+ element = bgElement;
37
+ isBackground = true;
38
+
39
+ // Try to get image source from nested Image component first
40
+ const imgInside = bgElement.querySelector('img[data-image-id]') as HTMLImageElement | null;
41
+ if (imgInside) {
42
+ currentSrc = imgInside.src;
43
+ } else {
44
+ // Fallback to background-image CSS
45
+ const bgImage = window.getComputedStyle(bgElement).backgroundImage;
46
+ const urlMatch = bgImage.match(/url\(['"]?([^'"]+)['"]?\)/);
47
+ if (urlMatch && urlMatch[1]) {
48
+ currentSrc = urlMatch[1];
49
+ }
50
+ }
51
+ }
52
+ }
53
+
54
+ if (!element || !currentSrc) return;
55
+
56
+ // Don't handle images in modals or the editor itself
57
+ if (element.closest('[data-image-editor]') || element.closest('[role="dialog"]')) {
58
+ return;
59
+ }
60
+
61
+ e.preventDefault();
62
+ e.stopPropagation();
63
+
64
+ // Extract semantic ID from data attribute
65
+ let semanticId = element.getAttribute('data-image-id') || element.getAttribute('data-background-image-id');
66
+
67
+ // If not found, try to extract from the src URL
68
+ if (!semanticId && currentSrc.includes('/api/uploads/')) {
69
+ const urlPart = currentSrc.split('/api/uploads/')[1]?.split('?')[0];
70
+ // If it looks like a semantic ID (no extension or timestamp), use it
71
+ if (urlPart && !/^\d+-/.test(urlPart) && !/\.(jpg|jpeg|png|webp|gif|svg)$/i.test(urlPart)) {
72
+ semanticId = decodeURIComponent(urlPart);
73
+ }
74
+ }
75
+
76
+ // If still not found, generate one
77
+ if (!semanticId) {
78
+ semanticId = element.closest('[data-image-id]')?.getAttribute('data-image-id') ||
79
+ `image-${Date.now()}`;
80
+ }
81
+
82
+ // Parse image data
83
+ const filterStyle = element.style.filter || window.getComputedStyle(element).filter || '';
84
+ const dataBrightness = element.getAttribute('data-brightness');
85
+ const dataBlur = element.getAttribute('data-blur');
86
+
87
+ const currentBrightness = dataBrightness
88
+ ? parseInt(dataBrightness)
89
+ : parseInt(filterStyle.match(/brightness\((\d+)%\)/)?.[1] || '100');
90
+ const currentBlur = dataBlur
91
+ ? parseInt(dataBlur)
92
+ : parseInt(filterStyle.match(/blur\((\d+)px\)/)?.[1] || '0');
93
+
94
+ // Parse image data using the detection utility
95
+ const imageData = parseImageData(element, semanticId, currentBrightness, currentBlur);
96
+
97
+ if (!imageData) {
98
+ console.error('[GlobalImageEditor] Failed to parse image data');
99
+ return;
100
+ }
101
+
102
+ // Store semantic ID on element for later use
103
+ if (isBackground && !element.hasAttribute('data-background-image-id')) {
104
+ element.setAttribute('data-background-image-id', semanticId);
105
+ } else if (!isBackground && !element.hasAttribute('data-image-id')) {
106
+ element.setAttribute('data-image-id', semanticId);
107
+ }
108
+
109
+ onImageClick(imageData);
110
+ };
111
+
112
+ // Add click listeners and hover effects to all images
113
+ const images = document.querySelectorAll('img[data-image-id]:not([data-no-edit])') as NodeListOf<HTMLImageElement>;
114
+
115
+ // Find elements with BackgroundImage components
116
+ const bgElements: HTMLElement[] = [];
117
+ const backgroundImageComponents = document.querySelectorAll('[data-background-image-component]');
118
+ backgroundImageComponents.forEach(el => {
119
+ bgElements.push(el as HTMLElement);
120
+ });
121
+
122
+
123
+ images.forEach((img, index) => {
124
+ const originalPosition = img.style.position;
125
+
126
+ img.style.cursor = 'pointer';
127
+ img.setAttribute('data-editable-image', 'true');
128
+ img.addEventListener('click', handleImageClick as EventListener);
129
+
130
+ // Find the best container for the indicator
131
+ let indicatorContainer: HTMLElement = img;
132
+ let parent = img.parentElement;
133
+
134
+ if (parent && (parent.tagName === 'SPAN' || parent.tagName === 'DIV')) {
135
+ const parentStyle = window.getComputedStyle(parent);
136
+ if (parentStyle.position !== 'static' ||
137
+ (parentStyle.display !== 'inline' && parentStyle.display !== 'inline-block')) {
138
+ indicatorContainer = parent as HTMLElement;
139
+ }
140
+ }
141
+
142
+ // Ensure container has relative positioning
143
+ const containerStyle = window.getComputedStyle(indicatorContainer);
144
+ if (containerStyle.position === 'static') {
145
+ indicatorContainer.style.position = 'relative';
146
+ }
147
+
148
+ const indicator = document.createElement('div');
149
+ indicator.className = 'image-edit-indicator';
150
+ indicator.setAttribute('data-image-index', index.toString());
151
+ indicator.style.cssText = `
152
+ position: absolute;
153
+ top: 0;
154
+ left: 0;
155
+ width: 100%;
156
+ height: 100%;
157
+ background: rgba(0, 0, 0, 0.4);
158
+ display: flex;
159
+ align-items: center;
160
+ justify-content: center;
161
+ opacity: 0;
162
+ transition: opacity 0.2s ease;
163
+ pointer-events: none;
164
+ z-index: 10000;
165
+ border-radius: inherit;
166
+ box-sizing: border-box;
167
+ `;
168
+
169
+ const label = document.createElement('div');
170
+ label.style.cssText = `
171
+ background: rgba(0, 0, 0, 0.9);
172
+ color: white;
173
+ padding: 8px 16px;
174
+ border-radius: 8px;
175
+ font-size: 12px;
176
+ font-weight: bold;
177
+ text-transform: uppercase;
178
+ letter-spacing: 0.5px;
179
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
180
+ `;
181
+ label.textContent = 'Click to Edit';
182
+ indicator.appendChild(label);
183
+
184
+ indicatorContainer.appendChild(indicator);
185
+
186
+ const addHoverEffect = () => {
187
+ indicator.style.opacity = '1';
188
+ };
189
+
190
+ const removeHoverEffect = () => {
191
+ indicator.style.opacity = '0';
192
+ };
193
+
194
+ img.addEventListener('mouseenter', addHoverEffect);
195
+ img.addEventListener('mouseleave', removeHoverEffect);
196
+ if (indicatorContainer !== img) {
197
+ indicatorContainer.addEventListener('mouseenter', addHoverEffect);
198
+ indicatorContainer.addEventListener('mouseleave', removeHoverEffect);
199
+ }
200
+
201
+ cleanupFunctions.push(() => {
202
+ img.removeEventListener('click', handleImageClick as EventListener);
203
+ img.removeEventListener('mouseenter', addHoverEffect);
204
+ img.removeEventListener('mouseleave', removeHoverEffect);
205
+ if (indicatorContainer !== img) {
206
+ indicatorContainer.removeEventListener('mouseenter', addHoverEffect);
207
+ indicatorContainer.removeEventListener('mouseleave', removeHoverEffect);
208
+ if (indicatorContainer.style.position === 'relative') {
209
+ indicatorContainer.style.position = '';
210
+ }
211
+ }
212
+ img.removeAttribute('data-editable-image');
213
+ img.style.cursor = '';
214
+ img.style.position = originalPosition;
215
+ indicator.remove();
216
+ });
217
+ });
218
+
219
+ // Process background images - show a button instead of hover overlay
220
+ bgElements.forEach((bgEl, index) => {
221
+ if (bgEl.hasAttribute('data-background-image-component')) {
222
+ return; // Skip BackgroundImage components - they have their own edit button
223
+ }
224
+
225
+ const originalPosition = bgEl.style.position;
226
+ if (!bgEl.style.position || bgEl.style.position === 'static') {
227
+ bgEl.style.position = 'relative';
228
+ }
229
+
230
+ bgEl.setAttribute('data-editable-background', 'true');
231
+ bgEl.setAttribute('data-background-image', 'true');
232
+
233
+ const buttonContainer = document.createElement('div');
234
+ buttonContainer.className = 'background-edit-button-container';
235
+ buttonContainer.setAttribute('data-image-index', `bg-${index}`);
236
+ buttonContainer.style.cssText = `
237
+ position: absolute;
238
+ top: 12px;
239
+ right: 12px;
240
+ z-index: 10000;
241
+ pointer-events: auto;
242
+ `;
243
+
244
+ const editButton = document.createElement('button');
245
+ editButton.className = 'background-edit-button';
246
+ editButton.setAttribute('type', 'button');
247
+ editButton.style.cssText = `
248
+ background: rgba(0, 0, 0, 0.8);
249
+ color: white;
250
+ border: 2px solid rgba(255, 255, 255, 0.3);
251
+ padding: 10px 20px;
252
+ border-radius: 8px;
253
+ font-size: 12px;
254
+ font-weight: bold;
255
+ text-transform: uppercase;
256
+ letter-spacing: 0.5px;
257
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
258
+ cursor: pointer;
259
+ transition: all 0.2s ease;
260
+ display: flex;
261
+ align-items: center;
262
+ gap: 8px;
263
+ `;
264
+ editButton.innerHTML = `
265
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
266
+ <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path>
267
+ <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path>
268
+ </svg>
269
+ Edit Background
270
+ `;
271
+
272
+ editButton.addEventListener('mouseenter', () => {
273
+ editButton.style.background = 'rgba(0, 0, 0, 0.95)';
274
+ editButton.style.borderColor = 'rgba(255, 255, 255, 0.5)';
275
+ editButton.style.transform = 'translateY(-2px)';
276
+ editButton.style.boxShadow = '0 6px 16px rgba(0, 0, 0, 0.5)';
277
+ });
278
+
279
+ editButton.addEventListener('mouseleave', () => {
280
+ editButton.style.background = 'rgba(0, 0, 0, 0.8)';
281
+ editButton.style.borderColor = 'rgba(255, 255, 255, 0.3)';
282
+ editButton.style.transform = 'translateY(0)';
283
+ editButton.style.boxShadow = '0 4px 12px rgba(0, 0, 0, 0.4)';
284
+ });
285
+
286
+ editButton.addEventListener('click', (e) => {
287
+ e.preventDefault();
288
+ e.stopPropagation();
289
+ handleImageClick(e as any);
290
+ });
291
+
292
+ buttonContainer.appendChild(editButton);
293
+ bgEl.appendChild(buttonContainer);
294
+
295
+ cleanupFunctions.push(() => {
296
+ bgEl.removeAttribute('data-editable-background');
297
+ bgEl.removeAttribute('data-background-image');
298
+ bgEl.style.position = originalPosition;
299
+ buttonContainer.remove();
300
+ });
301
+ });
302
+
303
+ return () => {
304
+ cleanupFunctions.forEach(cleanup => cleanup());
305
+ };
306
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Save logic for image transforms and effects
3
+ */
4
+
5
+ import type { SelectedImage, PendingTransform } from './types';
6
+
7
+ /**
8
+ * Normalize position values - convert -50% (centering value) to 0
9
+ */
10
+ export function normalizePosition(position: number): number {
11
+ return position === -50 ? 0 : position;
12
+ }
13
+
14
+ /**
15
+ * Get filename from element or API
16
+ */
17
+ export async function getFilename(
18
+ semanticId: string,
19
+ selectedImage: SelectedImage
20
+ ): Promise<string | null> {
21
+ try {
22
+ const response = await fetch(`/api/plugin-images/resolve?id=${encodeURIComponent(semanticId)}`);
23
+ if (response.ok) {
24
+ const data = await response.json();
25
+ return data.filename || semanticId;
26
+ } else {
27
+ // If not found, try to extract from element
28
+ const { element } = selectedImage;
29
+ if (selectedImage.isBackground) {
30
+ const imgWrapper = element.querySelector('[data-image-id]');
31
+ if (imgWrapper) {
32
+ const img = imgWrapper.querySelector('img');
33
+ if (img && img.src) {
34
+ return img.src.split('/api/uploads/')[1]?.split('?')[0] || semanticId;
35
+ }
36
+ }
37
+ } else {
38
+ const img = element.tagName === 'IMG' ? element as HTMLImageElement : element.querySelector('img');
39
+ if (img && img.src) {
40
+ return img.src.split('/api/uploads/')[1]?.split('?')[0] || semanticId;
41
+ }
42
+ }
43
+ }
44
+ } catch (error) {
45
+ console.error('Failed to get filename:', error);
46
+ }
47
+ return null;
48
+ }
49
+
50
+ /**
51
+ * Save image transform to API
52
+ */
53
+ export async function saveTransformToAPI(
54
+ semanticId: string,
55
+ filename: string,
56
+ scale: number,
57
+ positionX: number,
58
+ positionY: number,
59
+ brightness: number,
60
+ blur: number
61
+ ): Promise<boolean> {
62
+ try {
63
+ const response = await fetch('/api/plugin-images/resolve', {
64
+ method: 'POST',
65
+ headers: { 'Content-Type': 'application/json' },
66
+ body: JSON.stringify({
67
+ id: semanticId,
68
+ filename,
69
+ brightness,
70
+ blur,
71
+ scale,
72
+ positionX: normalizePosition(positionX),
73
+ positionY: normalizePosition(positionY),
74
+ }),
75
+ });
76
+
77
+ if (response.ok) {
78
+ // Dispatch event to notify Image components
79
+ window.dispatchEvent(new CustomEvent('image-mapping-updated', {
80
+ detail: {
81
+ id: semanticId,
82
+ filename,
83
+ brightness,
84
+ blur,
85
+ scale,
86
+ positionX: normalizePosition(positionX),
87
+ positionY: normalizePosition(positionY),
88
+ }
89
+ }));
90
+ return true;
91
+ }
92
+ } catch (error) {
93
+ console.error('Failed to save transform:', error);
94
+ }
95
+ return false;
96
+ }
97
+
98
+ /**
99
+ * Flush pending save immediately
100
+ */
101
+ export async function flushPendingSave(
102
+ pending: PendingTransform,
103
+ selectedImage: SelectedImage
104
+ ): Promise<void> {
105
+ const normalizedPositionX = normalizePosition(pending.positionX);
106
+ const normalizedPositionY = normalizePosition(pending.positionY);
107
+
108
+ await saveTransformToAPI(
109
+ pending.semanticId,
110
+ pending.filename,
111
+ pending.scale,
112
+ normalizedPositionX,
113
+ normalizedPositionY,
114
+ selectedImage.brightness,
115
+ selectedImage.blur
116
+ );
117
+ }
118
+
119
+ /**
120
+ * Save image transform with debouncing support
121
+ * This is a wrapper that handles the debouncing logic
122
+ */
123
+ export async function saveImageTransform(
124
+ semanticId: string,
125
+ filename: string,
126
+ scale: number,
127
+ positionX: number,
128
+ positionY: number,
129
+ brightness: number,
130
+ blur: number
131
+ ): Promise<void> {
132
+ await saveTransformToAPI(semanticId, filename, scale, positionX, positionY, brightness, blur);
133
+ }
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Utilities for detecting styling from DOM elements
3
+ */
4
+
5
+ import type { DetectedStyling } from './types';
6
+
7
+ /**
8
+ * Detect styling properties from an element and its parent containers
9
+ */
10
+ export function detectStyling(
11
+ element: HTMLElement,
12
+ imgElement: HTMLImageElement | null
13
+ ): DetectedStyling {
14
+ // Find the container element (could be the element itself or a parent)
15
+ let container = element;
16
+ let parent = element.parentElement;
17
+
18
+ // Look for styling in parent containers (up to 3 levels)
19
+ for (let i = 0; i < 3 && parent; i++) {
20
+ const classes = parent.className || '';
21
+ const computedStyle = window.getComputedStyle(parent);
22
+
23
+ // Check for rounded-full (circular)
24
+ if (classes.includes('rounded-full')) {
25
+ container = parent;
26
+ break;
27
+ }
28
+ parent = parent.parentElement;
29
+ }
30
+
31
+ const containerClasses = container.className || '';
32
+ const containerStyle = window.getComputedStyle(container);
33
+ const imgStyle = imgElement ? window.getComputedStyle(imgElement) : null;
34
+
35
+ // Detect border radius
36
+ let borderRadius = 'rounded-xl'; // default
37
+ if (containerClasses.includes('rounded-full')) {
38
+ borderRadius = 'rounded-full';
39
+ } else if (containerClasses.includes('rounded-3xl')) {
40
+ borderRadius = 'rounded-3xl';
41
+ } else if (containerClasses.includes('rounded-2xl')) {
42
+ borderRadius = 'rounded-2xl';
43
+ } else if (containerClasses.includes('rounded-xl')) {
44
+ borderRadius = 'rounded-xl';
45
+ } else if (containerClasses.includes('rounded-lg')) {
46
+ borderRadius = 'rounded-lg';
47
+ }
48
+
49
+ // Detect aspect ratio
50
+ let aspectRatio = '16/9'; // default
51
+
52
+ // First check the container's computed style
53
+ const aspectRatioStyle = containerStyle.aspectRatio;
54
+ if (aspectRatioStyle && aspectRatioStyle !== 'auto') {
55
+ // Convert CSS aspect-ratio (e.g., "1 / 1") to our format ("1/1")
56
+ aspectRatio = aspectRatioStyle.replace(/\s+/g, '');
57
+ } else {
58
+ // Check for Tailwind aspect ratio classes in container or parents
59
+ let currentElement: HTMLElement | null = container;
60
+ let foundAspectRatio = false;
61
+
62
+ // Check up to 3 parent levels for aspect ratio
63
+ for (let i = 0; i < 3 && currentElement && !foundAspectRatio; i++) {
64
+ const classes = currentElement.className || '';
65
+ const computedStyle = window.getComputedStyle(currentElement);
66
+
67
+ // Check computed style first
68
+ if (computedStyle.aspectRatio && computedStyle.aspectRatio !== 'auto') {
69
+ aspectRatio = computedStyle.aspectRatio.replace(/\s+/g, '');
70
+ foundAspectRatio = true;
71
+ break;
72
+ }
73
+
74
+ // Check for Tailwind aspect ratio classes (aspect-*, aspect-square, aspect-video, etc.)
75
+ const aspectMatch = classes.match(/aspect-(\d+\/\d+)|aspect-square|aspect-video/);
76
+ if (aspectMatch) {
77
+ if (aspectMatch[1]) {
78
+ // Matched aspect-4/5, aspect-16/9, etc.
79
+ aspectRatio = aspectMatch[1];
80
+ } else if (aspectMatch[0] === 'aspect-square') {
81
+ aspectRatio = '1/1';
82
+ } else if (aspectMatch[0] === 'aspect-video') {
83
+ aspectRatio = '16/9';
84
+ }
85
+ foundAspectRatio = true;
86
+ break;
87
+ }
88
+
89
+ currentElement = currentElement.parentElement;
90
+ }
91
+
92
+ // Fallback checks
93
+ if (!foundAspectRatio) {
94
+ if (containerClasses.includes('rounded-full')) {
95
+ // Circular images are typically 1:1
96
+ aspectRatio = '1/1';
97
+ } else {
98
+ // Try to detect from size classes
99
+ if (containerClasses.includes('size-') || containerClasses.match(/w-\d+.*h-\d+/)) {
100
+ aspectRatio = '1/1';
101
+ }
102
+ }
103
+ }
104
+ }
105
+
106
+ // Detect object-fit
107
+ let objectFit: 'cover' | 'contain' | 'fill' | 'none' | 'scale-down' = 'cover';
108
+ if (imgStyle) {
109
+ const objectFitValue = imgStyle.objectFit || containerStyle.objectFit;
110
+ if (objectFitValue && ['cover', 'contain', 'fill', 'none', 'scale-down'].includes(objectFitValue)) {
111
+ objectFit = objectFitValue as 'cover' | 'contain' | 'fill' | 'none' | 'scale-down';
112
+ }
113
+ }
114
+
115
+ // Detect object-position
116
+ let objectPosition = 'center';
117
+ if (imgStyle) {
118
+ objectPosition = imgStyle.objectPosition || containerStyle.objectPosition || 'center';
119
+ }
120
+
121
+ return { aspectRatio, borderRadius, objectFit, objectPosition };
122
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Utilities for parsing CSS transforms to extract scale and position values
3
+ */
4
+
5
+ /**
6
+ * Parse scale from CSS transform string
7
+ */
8
+ export function parseScaleFromTransform(
9
+ transform: string,
10
+ container: HTMLElement | null,
11
+ imgElement: HTMLImageElement | null
12
+ ): number {
13
+ const scaleMatch = transform.match(/scale\(([\d.]+)\)/);
14
+ if (!scaleMatch) return 1.0;
15
+
16
+ const totalScale = parseFloat(scaleMatch[1]);
17
+
18
+ // If totalScale is very small (< 0.1), it's likely wrong
19
+ if (totalScale < 0.1) {
20
+ return 1.0;
21
+ }
22
+
23
+ // Calculate baseScale to extract the actual user scale
24
+ if (container && imgElement && imgElement.naturalWidth > 0 && imgElement.naturalHeight > 0) {
25
+ const containerWidth = container.clientWidth || container.offsetWidth;
26
+ const containerHeight = container.clientHeight || container.offsetHeight;
27
+
28
+ if (containerWidth > 0 && containerHeight > 0) {
29
+ const widthRatio = containerWidth / imgElement.naturalWidth;
30
+ const heightRatio = containerHeight / imgElement.naturalHeight;
31
+ const baseScale = Math.max(widthRatio, heightRatio);
32
+
33
+ if (baseScale > 0 && baseScale < 1) {
34
+ // Extract the actual scale by dividing totalScale by baseScale
35
+ const scale = totalScale / baseScale;
36
+ // Clamp to valid range
37
+ return Math.max(0.1, Math.min(5.0, scale));
38
+ }
39
+ }
40
+ }
41
+
42
+ return 1.0;
43
+ }
44
+
45
+ /**
46
+ * Parse position (X, Y) from CSS transform string
47
+ * Returns container-relative percentages
48
+ */
49
+ export function parsePositionFromTransform(transform: string): { x: number; y: number } {
50
+ // Match all translate() calls - skip the first one if it's the centering translate(-50%, -50%)
51
+ const allTranslates = transform.matchAll(/translate\(([-\d.]+)%,?\s*([-\d.]+)?%?\)/g);
52
+ const translateArray = Array.from(allTranslates);
53
+
54
+ let positionX = 0;
55
+ let positionY = 0;
56
+
57
+ if (translateArray.length > 1) {
58
+ // Use the second translate (the position offset)
59
+ const positionTranslate = translateArray[1];
60
+ const appliedX = parseFloat(positionTranslate[1] || '0');
61
+ const appliedY = parseFloat(positionTranslate[2] || '0');
62
+
63
+ // Only use if it's not the centering translate (safety check)
64
+ if (appliedX !== -50 || appliedY !== -50) {
65
+ // With new system, applied value IS the stored value (container-relative)
66
+ positionX = appliedX;
67
+ positionY = appliedY;
68
+ }
69
+ } else if (translateArray.length === 1) {
70
+ // Only one translate - check if it's the centering one
71
+ const translate = translateArray[0];
72
+ const appliedX = parseFloat(translate[1] || '0');
73
+ const appliedY = parseFloat(translate[2] || '0');
74
+
75
+ // If it's not the centering translate, use it as position
76
+ if (appliedX !== -50 || appliedY !== -50) {
77
+ positionX = appliedX;
78
+ positionY = appliedY;
79
+ }
80
+ }
81
+
82
+ return { x: positionX, y: positionY };
83
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Types for GlobalImageEditor component
3
+ */
4
+
5
+ export interface SelectedImage {
6
+ element: HTMLElement;
7
+ originalSrc: string;
8
+ brightness: number;
9
+ blur: number;
10
+ scale: number;
11
+ positionX: number;
12
+ positionY: number;
13
+ isBackground: boolean;
14
+ aspectRatio?: string;
15
+ borderRadius?: string;
16
+ objectFit?: 'cover' | 'contain' | 'fill' | 'none' | 'scale-down';
17
+ objectPosition?: string;
18
+ }
19
+
20
+ export interface PluginConfig {
21
+ enabled: boolean;
22
+ className?: string;
23
+ overlayClassName?: string;
24
+ }
25
+
26
+ export interface DetectedStyling {
27
+ aspectRatio: string;
28
+ borderRadius: string;
29
+ objectFit: 'cover' | 'contain' | 'fill' | 'none' | 'scale-down';
30
+ objectPosition: string;
31
+ }
32
+
33
+ export interface PendingTransform {
34
+ scale: number;
35
+ positionX: number;
36
+ positionY: number;
37
+ semanticId: string;
38
+ filename: string;
39
+ }