@jhits/plugin-images 0.0.11 → 0.0.12

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 (76) hide show
  1. package/package.json +3 -2
  2. package/src/api/fallback/route.ts +69 -0
  3. package/src/api/index.ts +10 -0
  4. package/src/api/list/index.ts +96 -0
  5. package/src/api/resolve/route.ts +241 -0
  6. package/src/api/router.ts +85 -0
  7. package/src/api/upload/index.ts +88 -0
  8. package/src/api/uploads/[filename]/route.ts +93 -0
  9. package/src/api-server.ts +11 -0
  10. package/src/assets/noimagefound.jpg +0 -0
  11. package/src/components/BackgroundImage.d.ts +11 -0
  12. package/src/components/BackgroundImage.d.ts.map +1 -0
  13. package/src/components/BackgroundImage.tsx +92 -0
  14. package/src/components/GlobalImageEditor/config.d.ts +9 -0
  15. package/src/components/GlobalImageEditor/config.d.ts.map +1 -0
  16. package/src/components/GlobalImageEditor/config.ts +21 -0
  17. package/src/components/GlobalImageEditor/eventHandlers.d.ts +20 -0
  18. package/src/components/GlobalImageEditor/eventHandlers.d.ts.map +1 -0
  19. package/src/components/GlobalImageEditor/eventHandlers.ts +267 -0
  20. package/src/components/GlobalImageEditor/imageDetection.d.ts +16 -0
  21. package/src/components/GlobalImageEditor/imageDetection.d.ts.map +1 -0
  22. package/src/components/GlobalImageEditor/imageDetection.ts +160 -0
  23. package/src/components/GlobalImageEditor/imageSetup.d.ts +9 -0
  24. package/src/components/GlobalImageEditor/imageSetup.d.ts.map +1 -0
  25. package/src/components/GlobalImageEditor/imageSetup.ts +306 -0
  26. package/src/components/GlobalImageEditor/saveLogic.d.ts +26 -0
  27. package/src/components/GlobalImageEditor/saveLogic.d.ts.map +1 -0
  28. package/src/components/GlobalImageEditor/saveLogic.ts +133 -0
  29. package/src/components/GlobalImageEditor/stylingDetection.d.ts +9 -0
  30. package/src/components/GlobalImageEditor/stylingDetection.d.ts.map +1 -0
  31. package/src/components/GlobalImageEditor/stylingDetection.ts +122 -0
  32. package/src/components/GlobalImageEditor/transformParsing.d.ts +16 -0
  33. package/src/components/GlobalImageEditor/transformParsing.d.ts.map +1 -0
  34. package/src/components/GlobalImageEditor/transformParsing.ts +83 -0
  35. package/src/components/GlobalImageEditor/types.d.ts +36 -0
  36. package/src/components/GlobalImageEditor/types.d.ts.map +1 -0
  37. package/src/components/GlobalImageEditor/types.ts +39 -0
  38. package/src/components/GlobalImageEditor.d.ts +8 -0
  39. package/src/components/GlobalImageEditor.d.ts.map +1 -0
  40. package/src/components/GlobalImageEditor.tsx +327 -0
  41. package/src/components/Image.d.ts +22 -0
  42. package/src/components/Image.d.ts.map +1 -0
  43. package/src/components/Image.tsx +343 -0
  44. package/src/components/ImageBrowserModal.d.ts +13 -0
  45. package/src/components/ImageBrowserModal.d.ts.map +1 -0
  46. package/src/components/ImageBrowserModal.tsx +837 -0
  47. package/src/components/ImageEditor.d.ts +27 -0
  48. package/src/components/ImageEditor.d.ts.map +1 -0
  49. package/src/components/ImageEditor.tsx +323 -0
  50. package/src/components/ImageEffectsPanel.tsx +116 -0
  51. package/src/components/ImagePicker.d.ts +3 -0
  52. package/src/components/ImagePicker.d.ts.map +1 -0
  53. package/src/components/ImagePicker.tsx +265 -0
  54. package/src/components/ImagesPluginInit.d.ts +24 -0
  55. package/src/components/ImagesPluginInit.d.ts.map +1 -0
  56. package/src/components/ImagesPluginInit.tsx +31 -0
  57. package/src/components/index.ts +10 -0
  58. package/src/config.ts +179 -0
  59. package/src/hooks/useImagePicker.d.ts +20 -0
  60. package/src/hooks/useImagePicker.d.ts.map +1 -0
  61. package/src/hooks/useImagePicker.ts +344 -0
  62. package/src/index.server.ts +12 -0
  63. package/src/index.tsx +56 -0
  64. package/src/init.tsx +58 -0
  65. package/src/types/index.d.ts +80 -0
  66. package/src/types/index.d.ts.map +1 -0
  67. package/src/types/index.ts +84 -0
  68. package/src/utils/fallback.d.ts +27 -0
  69. package/src/utils/fallback.d.ts.map +1 -0
  70. package/src/utils/fallback.ts +73 -0
  71. package/src/utils/transforms.d.ts +26 -0
  72. package/src/utils/transforms.d.ts.map +1 -0
  73. package/src/utils/transforms.ts +54 -0
  74. package/src/views/ImageManager.d.ts +10 -0
  75. package/src/views/ImageManager.d.ts.map +1 -0
  76. package/src/views/ImageManager.tsx +30 -0
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Image detection and parsing utilities
3
+ */
4
+
5
+ import type { SelectedImage } from './types';
6
+ import { parseScaleFromTransform, parsePositionFromTransform } from './transformParsing';
7
+ import { detectStyling } from './stylingDetection';
8
+
9
+ /**
10
+ * Extract image source from element (handles Next.js Image wrapper)
11
+ */
12
+ export function getImageSource(element: HTMLElement, isBackground: boolean): {
13
+ currentSrc: string;
14
+ actualImgElement: HTMLImageElement | null;
15
+ } {
16
+ let currentSrc = '';
17
+ let actualImgElement: HTMLImageElement | null = null;
18
+
19
+ if (isBackground) {
20
+ // For background images, look for nested Image component
21
+ const imgWrapper = element.querySelector('[data-image-id]');
22
+ if (imgWrapper) {
23
+ actualImgElement = imgWrapper.querySelector('img') || null;
24
+ if (actualImgElement) {
25
+ currentSrc = actualImgElement.src;
26
+ } else {
27
+ // Fallback: try to get from background-image style
28
+ const bgImage = window.getComputedStyle(element).backgroundImage;
29
+ const urlMatch = bgImage.match(/url\(['"]?([^'"]+)['"]?\)/);
30
+ if (urlMatch && urlMatch[1]) {
31
+ currentSrc = urlMatch[1];
32
+ }
33
+ }
34
+ }
35
+ } else {
36
+ // For regular images, check if element is img or wrapper
37
+ if (element.tagName === 'IMG') {
38
+ actualImgElement = element as HTMLImageElement;
39
+ currentSrc = actualImgElement.src;
40
+ } else {
41
+ // Next.js Image wrapper - find the actual img element
42
+ actualImgElement = element.querySelector('img');
43
+ if (actualImgElement) {
44
+ currentSrc = actualImgElement.src;
45
+ }
46
+ }
47
+ }
48
+
49
+ return { currentSrc, actualImgElement };
50
+ }
51
+
52
+ /**
53
+ * Parse image data from element to create SelectedImage
54
+ */
55
+ export function parseImageData(
56
+ element: HTMLElement,
57
+ id: string,
58
+ currentBrightness?: number,
59
+ currentBlur?: number
60
+ ): SelectedImage | null {
61
+ const isBackground = element.hasAttribute('data-background-image-component') ||
62
+ element.hasAttribute('data-background-image-id');
63
+
64
+ const { currentSrc, actualImgElement } = getImageSource(element, isBackground);
65
+
66
+ if (!currentSrc) {
67
+ console.error('[GlobalImageEditor] No image source found for element');
68
+ return null;
69
+ }
70
+
71
+ // Get semantic ID
72
+ const semanticId = element.getAttribute('data-image-id') ||
73
+ element.getAttribute('data-background-image-id') ||
74
+ id;
75
+
76
+ // Parse brightness and blur from data attributes or filter style
77
+ let brightness = currentBrightness ?? 100;
78
+ let blur = currentBlur ?? 0;
79
+
80
+ const dataBrightness = element.getAttribute('data-brightness');
81
+ const dataBlur = element.getAttribute('data-blur');
82
+
83
+ if (dataBrightness) {
84
+ brightness = parseInt(dataBrightness);
85
+ } else if (actualImgElement) {
86
+ const filterStyle = actualImgElement.style.filter || window.getComputedStyle(actualImgElement).filter;
87
+ if (filterStyle && filterStyle !== 'none') {
88
+ const brightnessMatch = filterStyle.match(/brightness\((\d+)%\)/);
89
+ if (brightnessMatch) {
90
+ brightness = parseInt(brightnessMatch[1]);
91
+ }
92
+ }
93
+ }
94
+
95
+ if (dataBlur) {
96
+ blur = parseInt(dataBlur);
97
+ } else if (actualImgElement) {
98
+ const filterStyle = actualImgElement.style.filter || window.getComputedStyle(actualImgElement).filter;
99
+ if (filterStyle && filterStyle !== 'none') {
100
+ const blurMatch = filterStyle.match(/blur\((\d+)px\)/);
101
+ if (blurMatch) {
102
+ blur = parseInt(blurMatch[1]);
103
+ }
104
+ }
105
+ }
106
+
107
+ // Parse scale and position
108
+ let scale = 1.0;
109
+ let positionX = 0;
110
+ let positionY = 0;
111
+
112
+ const dataScale = element.getAttribute('data-scale');
113
+ const dataPositionX = element.getAttribute('data-position-x');
114
+ const dataPositionY = element.getAttribute('data-position-y');
115
+
116
+ if (dataScale) {
117
+ scale = parseFloat(dataScale);
118
+ } else if (actualImgElement) {
119
+ const imgTransform = actualImgElement.style.transform || window.getComputedStyle(actualImgElement).transform;
120
+ if (imgTransform && imgTransform !== 'none') {
121
+ // Find container for baseScale calculation
122
+ const container = actualImgElement.closest('[class*="relative"]') || actualImgElement.parentElement;
123
+ scale = parseScaleFromTransform(
124
+ imgTransform,
125
+ container as HTMLElement | null,
126
+ actualImgElement
127
+ );
128
+ }
129
+ }
130
+
131
+ if (dataPositionX) {
132
+ positionX = parseFloat(dataPositionX);
133
+ } else if (actualImgElement) {
134
+ const imgTransform = actualImgElement.style.transform || window.getComputedStyle(actualImgElement).transform;
135
+ if (imgTransform && imgTransform !== 'none') {
136
+ const position = parsePositionFromTransform(imgTransform);
137
+ positionX = position.x;
138
+ positionY = position.y;
139
+ }
140
+ }
141
+
142
+ if (dataPositionY) {
143
+ positionY = parseFloat(dataPositionY);
144
+ }
145
+
146
+ // Detect styling
147
+ const styling = detectStyling(element, actualImgElement);
148
+
149
+ return {
150
+ element,
151
+ originalSrc: currentSrc,
152
+ brightness,
153
+ blur,
154
+ scale,
155
+ positionX,
156
+ positionY,
157
+ isBackground,
158
+ ...styling,
159
+ };
160
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Image setup and click handlers
3
+ */
4
+ import type { SelectedImage } from './types';
5
+ /**
6
+ * Setup click handlers and hover effects for all images
7
+ */
8
+ export declare function setupImageHandlers(onImageClick: (image: SelectedImage) => void): () => void;
9
+ //# sourceMappingURL=imageSetup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imageSetup.d.ts","sourceRoot":"","sources":["imageSetup.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAK7C;;GAEG;AACH,wBAAgB,kBAAkB,CAC9B,YAAY,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,GAC7C,MAAM,IAAI,CAmSZ"}
@@ -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,26 @@
1
+ /**
2
+ * Save logic for image transforms and effects
3
+ */
4
+ import type { SelectedImage, PendingTransform } from './types';
5
+ /**
6
+ * Normalize position values - convert -50% (centering value) to 0
7
+ */
8
+ export declare function normalizePosition(position: number): number;
9
+ /**
10
+ * Get filename from element or API
11
+ */
12
+ export declare function getFilename(semanticId: string, selectedImage: SelectedImage): Promise<string | null>;
13
+ /**
14
+ * Save image transform to API
15
+ */
16
+ export declare function saveTransformToAPI(semanticId: string, filename: string, scale: number, positionX: number, positionY: number, brightness: number, blur: number): Promise<boolean>;
17
+ /**
18
+ * Flush pending save immediately
19
+ */
20
+ export declare function flushPendingSave(pending: PendingTransform, selectedImage: SelectedImage): Promise<void>;
21
+ /**
22
+ * Save image transform with debouncing support
23
+ * This is a wrapper that handles the debouncing logic
24
+ */
25
+ export declare function saveImageTransform(semanticId: string, filename: string, scale: number, positionX: number, positionY: number, brightness: number, blur: number): Promise<void>;
26
+ //# sourceMappingURL=saveLogic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saveLogic.d.ts","sourceRoot":"","sources":["saveLogic.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE/D;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED;;GAEG;AACH,wBAAsB,WAAW,CAC7B,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,aAAa,GAC7B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA4BxB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACpC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC,CAmClB;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAClC,OAAO,EAAE,gBAAgB,EACzB,aAAa,EAAE,aAAa,GAC7B,OAAO,CAAC,IAAI,CAAC,CAaf;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CACpC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAEf"}
@@ -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,9 @@
1
+ /**
2
+ * Utilities for detecting styling from DOM elements
3
+ */
4
+ import type { DetectedStyling } from './types';
5
+ /**
6
+ * Detect styling properties from an element and its parent containers
7
+ */
8
+ export declare function detectStyling(element: HTMLElement, imgElement: HTMLImageElement | null): DetectedStyling;
9
+ //# sourceMappingURL=stylingDetection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stylingDetection.d.ts","sourceRoot":"","sources":["stylingDetection.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;GAEG;AACH,wBAAgB,aAAa,CACzB,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,gBAAgB,GAAG,IAAI,GACpC,eAAe,CA6GjB"}