@jhits/plugin-images 0.0.6 → 0.0.7

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 (170) hide show
  1. package/dist/api/fallback/route.d.ts +7 -0
  2. package/dist/api/fallback/route.d.ts.map +1 -0
  3. package/dist/api/fallback/route.js +65 -0
  4. package/dist/api/index.d.ts +9 -0
  5. package/dist/api/index.d.ts.map +1 -0
  6. package/dist/api/index.js +8 -0
  7. package/dist/api/list/index.d.ts +21 -0
  8. package/dist/api/list/index.d.ts.map +1 -0
  9. package/dist/api/list/index.js +80 -0
  10. package/dist/api/resolve/route.d.ts +39 -0
  11. package/dist/api/resolve/route.d.ts.map +1 -0
  12. package/dist/api/resolve/route.js +213 -0
  13. package/dist/api/router.d.ts +14 -0
  14. package/dist/api/router.d.ts.map +1 -0
  15. package/dist/api/router.js +67 -0
  16. package/dist/api/upload/index.d.ts +20 -0
  17. package/dist/api/upload/index.d.ts.map +1 -0
  18. package/dist/api/upload/index.js +65 -0
  19. package/dist/api/uploads/[filename]/route.d.ts +21 -0
  20. package/dist/api/uploads/[filename]/route.d.ts.map +1 -0
  21. package/dist/api/uploads/[filename]/route.js +80 -0
  22. package/dist/api-server.d.ts +9 -0
  23. package/dist/api-server.d.ts.map +1 -0
  24. package/dist/api-server.js +9 -0
  25. package/dist/components/BackgroundImage.d.ts +11 -0
  26. package/dist/components/BackgroundImage.d.ts.map +1 -0
  27. package/dist/components/BackgroundImage.js +33 -0
  28. package/dist/components/GlobalImageEditor/config.d.ts +9 -0
  29. package/dist/components/GlobalImageEditor/config.d.ts.map +1 -0
  30. package/dist/components/GlobalImageEditor/config.js +17 -0
  31. package/dist/components/GlobalImageEditor/eventHandlers.d.ts +20 -0
  32. package/dist/components/GlobalImageEditor/eventHandlers.d.ts.map +1 -0
  33. package/dist/components/GlobalImageEditor/eventHandlers.js +210 -0
  34. package/dist/components/GlobalImageEditor/imageDetection.d.ts +16 -0
  35. package/dist/components/GlobalImageEditor/imageDetection.d.ts.map +1 -0
  36. package/dist/components/GlobalImageEditor/imageDetection.js +135 -0
  37. package/dist/components/GlobalImageEditor/imageSetup.d.ts +9 -0
  38. package/dist/components/GlobalImageEditor/imageSetup.d.ts.map +1 -0
  39. package/dist/components/GlobalImageEditor/imageSetup.js +260 -0
  40. package/dist/components/GlobalImageEditor/saveLogic.d.ts +26 -0
  41. package/dist/components/GlobalImageEditor/saveLogic.d.ts.map +1 -0
  42. package/dist/components/GlobalImageEditor/saveLogic.js +98 -0
  43. package/dist/components/GlobalImageEditor/stylingDetection.d.ts +9 -0
  44. package/dist/components/GlobalImageEditor/stylingDetection.d.ts.map +1 -0
  45. package/dist/components/GlobalImageEditor/stylingDetection.js +110 -0
  46. package/dist/components/GlobalImageEditor/transformParsing.d.ts +16 -0
  47. package/dist/components/GlobalImageEditor/transformParsing.d.ts.map +1 -0
  48. package/dist/components/GlobalImageEditor/transformParsing.js +68 -0
  49. package/dist/components/GlobalImageEditor/types.d.ts +36 -0
  50. package/dist/components/GlobalImageEditor/types.d.ts.map +1 -0
  51. package/dist/components/GlobalImageEditor/types.js +4 -0
  52. package/dist/components/GlobalImageEditor.d.ts +8 -0
  53. package/dist/components/GlobalImageEditor.d.ts.map +1 -0
  54. package/dist/components/GlobalImageEditor.js +232 -0
  55. package/dist/components/Image.d.ts +22 -0
  56. package/dist/components/Image.d.ts.map +1 -0
  57. package/dist/components/Image.js +227 -0
  58. package/dist/components/ImageBrowserModal.d.ts +13 -0
  59. package/dist/components/ImageBrowserModal.d.ts.map +1 -0
  60. package/dist/components/ImageBrowserModal.js +507 -0
  61. package/dist/components/ImageEditor.d.ts +27 -0
  62. package/dist/components/ImageEditor.d.ts.map +1 -0
  63. package/dist/components/ImageEditor.js +172 -0
  64. package/dist/components/ImageEffectsPanel.d.ts +10 -0
  65. package/dist/components/ImageEffectsPanel.d.ts.map +1 -0
  66. package/dist/components/ImageEffectsPanel.js +11 -0
  67. package/dist/components/ImagePicker.d.ts +3 -0
  68. package/dist/components/ImagePicker.d.ts.map +1 -0
  69. package/dist/components/ImagePicker.js +142 -0
  70. package/dist/components/ImagesPluginInit.d.ts +24 -0
  71. package/dist/components/ImagesPluginInit.d.ts.map +1 -0
  72. package/dist/components/ImagesPluginInit.js +28 -0
  73. package/dist/components/index.d.ts +9 -0
  74. package/dist/components/index.d.ts.map +1 -0
  75. package/dist/components/index.js +7 -0
  76. package/dist/config.d.ts +14 -0
  77. package/dist/config.d.ts.map +1 -0
  78. package/dist/config.js +172 -0
  79. package/dist/hooks/useImagePicker.d.ts +20 -0
  80. package/dist/hooks/useImagePicker.d.ts.map +1 -0
  81. package/dist/hooks/useImagePicker.js +320 -0
  82. package/dist/index.d.ts +23 -0
  83. package/dist/index.d.ts.map +1 -0
  84. package/dist/index.js +28 -0
  85. package/dist/index.server.d.ts +11 -0
  86. package/dist/index.server.d.ts.map +1 -0
  87. package/dist/index.server.js +10 -0
  88. package/dist/init.d.ts +33 -0
  89. package/dist/init.d.ts.map +1 -0
  90. package/dist/init.js +43 -0
  91. package/dist/types/index.d.ts +80 -0
  92. package/dist/types/index.d.ts.map +1 -0
  93. package/dist/types/index.js +4 -0
  94. package/dist/utils/fallback.d.ts +27 -0
  95. package/dist/utils/fallback.d.ts.map +1 -0
  96. package/dist/utils/fallback.js +63 -0
  97. package/dist/utils/transforms.d.ts +26 -0
  98. package/dist/utils/transforms.d.ts.map +1 -0
  99. package/dist/utils/transforms.js +38 -0
  100. package/dist/views/ImageManager.d.ts +10 -0
  101. package/dist/views/ImageManager.d.ts.map +1 -0
  102. package/dist/views/ImageManager.js +9 -0
  103. package/package.json +8 -8
  104. package/src/assets/noimagefound.jpg +0 -0
  105. package/src/components/BackgroundImage.d.ts +11 -0
  106. package/src/components/BackgroundImage.d.ts.map +1 -0
  107. package/src/components/BackgroundImage.js +35 -0
  108. package/src/components/GlobalImageEditor/config.d.ts +9 -0
  109. package/src/components/GlobalImageEditor/config.d.ts.map +1 -0
  110. package/src/components/GlobalImageEditor/config.js +18 -0
  111. package/src/components/GlobalImageEditor/eventHandlers.d.ts +20 -0
  112. package/src/components/GlobalImageEditor/eventHandlers.d.ts.map +1 -0
  113. package/src/components/GlobalImageEditor/eventHandlers.js +206 -0
  114. package/src/components/GlobalImageEditor/imageDetection.d.ts +16 -0
  115. package/src/components/GlobalImageEditor/imageDetection.d.ts.map +1 -0
  116. package/src/components/GlobalImageEditor/imageDetection.js +130 -0
  117. package/src/components/GlobalImageEditor/imageSetup.d.ts +9 -0
  118. package/src/components/GlobalImageEditor/imageSetup.d.ts.map +1 -0
  119. package/src/components/GlobalImageEditor/imageSetup.js +261 -0
  120. package/src/components/GlobalImageEditor/saveLogic.d.ts +26 -0
  121. package/src/components/GlobalImageEditor/saveLogic.d.ts.map +1 -0
  122. package/src/components/GlobalImageEditor/saveLogic.js +99 -0
  123. package/src/components/GlobalImageEditor/stylingDetection.d.ts +9 -0
  124. package/src/components/GlobalImageEditor/stylingDetection.d.ts.map +1 -0
  125. package/src/components/GlobalImageEditor/stylingDetection.js +110 -0
  126. package/src/components/GlobalImageEditor/transformParsing.d.ts +16 -0
  127. package/src/components/GlobalImageEditor/transformParsing.d.ts.map +1 -0
  128. package/src/components/GlobalImageEditor/transformParsing.js +68 -0
  129. package/src/components/GlobalImageEditor/types.d.ts +36 -0
  130. package/src/components/GlobalImageEditor/types.d.ts.map +1 -0
  131. package/src/components/GlobalImageEditor/types.js +4 -0
  132. package/src/components/GlobalImageEditor.d.ts +8 -0
  133. package/src/components/GlobalImageEditor.d.ts.map +1 -0
  134. package/src/components/GlobalImageEditor.js +227 -0
  135. package/src/components/Image.d.ts +22 -0
  136. package/src/components/Image.d.ts.map +1 -0
  137. package/src/components/Image.js +229 -0
  138. package/src/components/ImageBrowserModal.d.ts +13 -0
  139. package/src/components/ImageBrowserModal.d.ts.map +1 -0
  140. package/src/components/ImageBrowserModal.js +504 -0
  141. package/src/components/ImageEditor.d.ts +27 -0
  142. package/src/components/ImageEditor.d.ts.map +1 -0
  143. package/src/components/ImageEditor.js +173 -0
  144. package/src/components/ImagePicker.d.ts +3 -0
  145. package/src/components/ImagePicker.d.ts.map +1 -0
  146. package/src/components/ImagePicker.js +143 -0
  147. package/src/components/ImagesPluginInit.d.ts +24 -0
  148. package/src/components/ImagesPluginInit.d.ts.map +1 -0
  149. package/src/components/ImagesPluginInit.js +28 -0
  150. package/src/hooks/useImagePicker.d.ts +20 -0
  151. package/src/hooks/useImagePicker.d.ts.map +1 -0
  152. package/src/hooks/useImagePicker.js +322 -0
  153. package/src/index.d.ts +23 -0
  154. package/src/index.d.ts.map +1 -0
  155. package/src/index.js +28 -0
  156. package/src/init.d.ts +33 -0
  157. package/src/init.d.ts.map +1 -0
  158. package/src/init.js +43 -0
  159. package/src/types/index.d.ts +80 -0
  160. package/src/types/index.d.ts.map +1 -0
  161. package/src/types/index.js +4 -0
  162. package/src/utils/fallback.d.ts +27 -0
  163. package/src/utils/fallback.d.ts.map +1 -0
  164. package/src/utils/fallback.js +63 -0
  165. package/src/utils/transforms.d.ts +26 -0
  166. package/src/utils/transforms.d.ts.map +1 -0
  167. package/src/utils/transforms.js +38 -0
  168. package/src/views/ImageManager.d.ts +10 -0
  169. package/src/views/ImageManager.d.ts.map +1 -0
  170. package/src/views/ImageManager.js +9 -0
@@ -0,0 +1,206 @@
1
+ /**
2
+ * Event handlers for image changes and effects
3
+ */
4
+ import { getFilename, saveTransformToAPI, normalizePosition } from './saveLogic';
5
+ /**
6
+ * Apply image changes to DOM and save to API
7
+ */
8
+ export async function handleImageChange(image, selectedImage, onClose) {
9
+ var _a;
10
+ if (!image)
11
+ return;
12
+ const { element } = selectedImage;
13
+ const semanticId = element.getAttribute('data-image-id') ||
14
+ element.getAttribute('data-background-image-id');
15
+ if (!semanticId) {
16
+ console.error('[GlobalImageEditor] No semantic ID found for image');
17
+ return;
18
+ }
19
+ // Extract filename from image URL or use image.id
20
+ const filename = ((_a = image.url.split('/').pop()) === null || _a === void 0 ? void 0 : _a.split('?')[0]) || image.id;
21
+ const normalizedPositionX = normalizePosition(selectedImage.positionX);
22
+ const normalizedPositionY = normalizePosition(selectedImage.positionY);
23
+ // Save the mapping between semantic ID and filename, including effects and transforms
24
+ await saveTransformToAPI(semanticId, filename, selectedImage.scale, normalizedPositionX, normalizedPositionY, selectedImage.brightness, selectedImage.blur);
25
+ // Update image src immediately - handle background images differently
26
+ if (selectedImage.isBackground) {
27
+ updateBackgroundImage(element, image.url, selectedImage, normalizedPositionX, normalizedPositionY);
28
+ }
29
+ else {
30
+ updateRegularImage(element, image.url, semanticId, selectedImage, normalizedPositionX, normalizedPositionY);
31
+ }
32
+ // Dispatch a custom event to notify Image components to re-resolve
33
+ window.dispatchEvent(new CustomEvent('image-mapping-updated', {
34
+ detail: {
35
+ id: semanticId,
36
+ filename,
37
+ brightness: selectedImage.brightness,
38
+ blur: selectedImage.blur,
39
+ scale: selectedImage.scale,
40
+ positionX: selectedImage.positionX,
41
+ positionY: selectedImage.positionY,
42
+ }
43
+ }));
44
+ onClose();
45
+ }
46
+ /**
47
+ * Update background image element
48
+ */
49
+ function updateBackgroundImage(element, imageUrl, selectedImage, normalizedPositionX, normalizedPositionY) {
50
+ // For background images, update the nested Image component
51
+ const imgWrapper = element.querySelector('[data-image-id]');
52
+ if (imgWrapper) {
53
+ const img = imgWrapper.querySelector('img');
54
+ if (img) {
55
+ img.src = imageUrl;
56
+ img.setAttribute('data-edited-src', imageUrl);
57
+ img.style.transform = `scale(${selectedImage.scale}) translate(${normalizedPositionX}%, ${normalizedPositionY}%)`;
58
+ img.style.transformOrigin = 'center center';
59
+ }
60
+ }
61
+ else {
62
+ // Fallback: update background-image style if no nested Image component
63
+ const bgImage = window.getComputedStyle(element).backgroundImage;
64
+ if (bgImage && bgImage !== 'none') {
65
+ element.style.backgroundImage = `url(${imageUrl})`;
66
+ }
67
+ }
68
+ // Store attributes on the background container
69
+ const semanticId = element.getAttribute('data-image-id') || element.getAttribute('data-background-image-id') || '';
70
+ element.setAttribute('data-background-image-id', semanticId);
71
+ element.setAttribute('data-edited-src', imageUrl);
72
+ element.setAttribute('data-brightness', selectedImage.brightness.toString());
73
+ element.setAttribute('data-blur', selectedImage.blur.toString());
74
+ element.setAttribute('data-scale', selectedImage.scale.toString());
75
+ element.setAttribute('data-position-x', normalizedPositionX.toString());
76
+ element.setAttribute('data-position-y', normalizedPositionY.toString());
77
+ // Apply filter to the wrapper element
78
+ if (selectedImage.brightness !== 100 || selectedImage.blur !== 0) {
79
+ element.style.filter = `brightness(${selectedImage.brightness}%) blur(${selectedImage.blur}px)`;
80
+ }
81
+ else {
82
+ element.style.filter = '';
83
+ }
84
+ }
85
+ /**
86
+ * Update regular image element
87
+ */
88
+ function updateRegularImage(element, imageUrl, semanticId, selectedImage, normalizedPositionX, normalizedPositionY) {
89
+ if (element.tagName === 'IMG') {
90
+ element.src = imageUrl;
91
+ element.setAttribute('data-edited-src', imageUrl);
92
+ element.setAttribute('data-image-id', semanticId);
93
+ element.setAttribute('data-brightness', selectedImage.brightness.toString());
94
+ element.setAttribute('data-blur', selectedImage.blur.toString());
95
+ // Apply filter
96
+ if (selectedImage.brightness !== 100 || selectedImage.blur !== 0) {
97
+ element.style.filter = `brightness(${selectedImage.brightness}%) blur(${selectedImage.blur}px)`;
98
+ }
99
+ else {
100
+ element.style.filter = '';
101
+ }
102
+ }
103
+ else {
104
+ // Next.js Image wrapper - find the actual img element
105
+ const img = element.querySelector('img');
106
+ if (img) {
107
+ img.src = imageUrl;
108
+ img.setAttribute('data-edited-src', imageUrl);
109
+ img.style.transform = `scale(${selectedImage.scale}) translate(${normalizedPositionX}%, ${normalizedPositionY}%)`;
110
+ img.style.transformOrigin = 'center center';
111
+ }
112
+ element.setAttribute('data-image-id', semanticId);
113
+ element.setAttribute('data-edited-src', imageUrl);
114
+ element.setAttribute('data-brightness', selectedImage.brightness.toString());
115
+ element.setAttribute('data-blur', selectedImage.blur.toString());
116
+ element.setAttribute('data-scale', selectedImage.scale.toString());
117
+ element.setAttribute('data-position-x', normalizedPositionX.toString());
118
+ element.setAttribute('data-position-y', normalizedPositionY.toString());
119
+ // Apply filter to wrapper
120
+ if (selectedImage.brightness !== 100 || selectedImage.blur !== 0) {
121
+ element.style.filter = `brightness(${selectedImage.brightness}%) blur(${selectedImage.blur}px)`;
122
+ }
123
+ else {
124
+ element.style.filter = '';
125
+ }
126
+ }
127
+ }
128
+ /**
129
+ * Get filename from element for saving effects
130
+ */
131
+ async function getFilenameFromElement(semanticId, selectedImage) {
132
+ var _a, _b;
133
+ const filename = await getFilename(semanticId, selectedImage);
134
+ if (filename)
135
+ return filename;
136
+ const { element } = selectedImage;
137
+ if (selectedImage.isBackground) {
138
+ const bgImage = window.getComputedStyle(element).backgroundImage;
139
+ const urlMatch = bgImage.match(/url\(['"]?([^'"]+)['"]?\)/);
140
+ if (urlMatch && urlMatch[1]) {
141
+ return ((_a = urlMatch[1].split('/api/uploads/')[1]) === null || _a === void 0 ? void 0 : _a.split('?')[0]) || semanticId;
142
+ }
143
+ }
144
+ else {
145
+ let imgSrc = null;
146
+ if (element instanceof HTMLImageElement && element.src) {
147
+ imgSrc = element.src;
148
+ }
149
+ else {
150
+ const img = element.querySelector('img');
151
+ if (img === null || img === void 0 ? void 0 : img.src) {
152
+ imgSrc = img.src;
153
+ }
154
+ }
155
+ if (imgSrc) {
156
+ return ((_b = imgSrc.split('/api/uploads/')[1]) === null || _b === void 0 ? void 0 : _b.split('?')[0]) || semanticId;
157
+ }
158
+ }
159
+ return semanticId;
160
+ }
161
+ /**
162
+ * Handle brightness change
163
+ * @param saveImmediately - If true, save to API immediately. If false, only update state/DOM (for editor preview)
164
+ */
165
+ export async function handleBrightnessChange(brightness, selectedImage, setSelectedImage, saveImmediately = true) {
166
+ const { element } = selectedImage;
167
+ const semanticId = element.getAttribute('data-image-id') ||
168
+ element.getAttribute('data-background-image-id');
169
+ if (!semanticId)
170
+ return;
171
+ const currentFilter = element.style.filter || '';
172
+ const blurMatch = currentFilter.match(/blur\((\d+)px\)/);
173
+ const blur = blurMatch ? parseInt(blurMatch[1]) : selectedImage.blur;
174
+ // Update the selectedImage state
175
+ setSelectedImage(Object.assign(Object.assign({}, selectedImage), { brightness }));
176
+ element.style.filter = `brightness(${brightness}%) blur(${blur}px)`;
177
+ element.setAttribute('data-brightness', brightness.toString());
178
+ // Save the effect immediately only if requested (not when in editor)
179
+ if (saveImmediately) {
180
+ const filename = await getFilenameFromElement(semanticId, selectedImage);
181
+ await saveTransformToAPI(semanticId, filename, selectedImage.scale, selectedImage.positionX, selectedImage.positionY, brightness, blur);
182
+ }
183
+ }
184
+ /**
185
+ * Handle blur change
186
+ * @param saveImmediately - If true, save to API immediately. If false, only update state/DOM (for editor preview)
187
+ */
188
+ export async function handleBlurChange(blur, selectedImage, setSelectedImage, saveImmediately = true) {
189
+ const { element } = selectedImage;
190
+ const semanticId = element.getAttribute('data-image-id') ||
191
+ element.getAttribute('data-background-image-id');
192
+ if (!semanticId)
193
+ return;
194
+ const currentFilter = element.style.filter || '';
195
+ const brightnessMatch = currentFilter.match(/brightness\((\d+)%\)/);
196
+ const brightness = brightnessMatch ? parseInt(brightnessMatch[1]) : selectedImage.brightness;
197
+ // Update the selectedImage state
198
+ setSelectedImage(Object.assign(Object.assign({}, selectedImage), { blur }));
199
+ element.style.filter = `brightness(${brightness}%) blur(${blur}px)`;
200
+ element.setAttribute('data-blur', blur.toString());
201
+ // Save the effect immediately only if requested (not when in editor)
202
+ if (saveImmediately) {
203
+ const filename = await getFilenameFromElement(semanticId, selectedImage);
204
+ await saveTransformToAPI(semanticId, filename, selectedImage.scale, selectedImage.positionX, selectedImage.positionY, brightness, blur);
205
+ }
206
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Image detection and parsing utilities
3
+ */
4
+ import type { SelectedImage } from './types';
5
+ /**
6
+ * Extract image source from element (handles Next.js Image wrapper)
7
+ */
8
+ export declare function getImageSource(element: HTMLElement, isBackground: boolean): {
9
+ currentSrc: string;
10
+ actualImgElement: HTMLImageElement | null;
11
+ };
12
+ /**
13
+ * Parse image data from element to create SelectedImage
14
+ */
15
+ export declare function parseImageData(element: HTMLElement, id: string, currentBrightness?: number, currentBlur?: number): SelectedImage | null;
16
+ //# sourceMappingURL=imageDetection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imageDetection.d.ts","sourceRoot":"","sources":["imageDetection.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAI7C;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,GAAG;IACzE,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,gBAAgB,GAAG,IAAI,CAAC;CAC7C,CAmCA;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC1B,OAAO,EAAE,WAAW,EACpB,EAAE,EAAE,MAAM,EACV,iBAAiB,CAAC,EAAE,MAAM,EAC1B,WAAW,CAAC,EAAE,MAAM,GACrB,aAAa,GAAG,IAAI,CAoGtB"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Image detection and parsing utilities
3
+ */
4
+ import { parseScaleFromTransform, parsePositionFromTransform } from './transformParsing';
5
+ import { detectStyling } from './stylingDetection';
6
+ /**
7
+ * Extract image source from element (handles Next.js Image wrapper)
8
+ */
9
+ export function getImageSource(element, isBackground) {
10
+ let currentSrc = '';
11
+ let actualImgElement = null;
12
+ if (isBackground) {
13
+ // For background images, look for nested Image component
14
+ const imgWrapper = element.querySelector('[data-image-id]');
15
+ if (imgWrapper) {
16
+ actualImgElement = imgWrapper.querySelector('img') || null;
17
+ if (actualImgElement) {
18
+ currentSrc = actualImgElement.src;
19
+ }
20
+ else {
21
+ // Fallback: try to get from background-image style
22
+ const bgImage = window.getComputedStyle(element).backgroundImage;
23
+ const urlMatch = bgImage.match(/url\(['"]?([^'"]+)['"]?\)/);
24
+ if (urlMatch && urlMatch[1]) {
25
+ currentSrc = urlMatch[1];
26
+ }
27
+ }
28
+ }
29
+ }
30
+ else {
31
+ // For regular images, check if element is img or wrapper
32
+ if (element.tagName === 'IMG') {
33
+ actualImgElement = element;
34
+ currentSrc = actualImgElement.src;
35
+ }
36
+ else {
37
+ // Next.js Image wrapper - find the actual img element
38
+ actualImgElement = element.querySelector('img');
39
+ if (actualImgElement) {
40
+ currentSrc = actualImgElement.src;
41
+ }
42
+ }
43
+ }
44
+ return { currentSrc, actualImgElement };
45
+ }
46
+ /**
47
+ * Parse image data from element to create SelectedImage
48
+ */
49
+ export function parseImageData(element, id, currentBrightness, currentBlur) {
50
+ const isBackground = element.hasAttribute('data-background-image-component') ||
51
+ element.hasAttribute('data-background-image-id');
52
+ const { currentSrc, actualImgElement } = getImageSource(element, isBackground);
53
+ if (!currentSrc) {
54
+ console.error('[GlobalImageEditor] No image source found for element');
55
+ return null;
56
+ }
57
+ // Get semantic ID
58
+ const semanticId = element.getAttribute('data-image-id') ||
59
+ element.getAttribute('data-background-image-id') ||
60
+ id;
61
+ // Parse brightness and blur from data attributes or filter style
62
+ let brightness = currentBrightness !== null && currentBrightness !== void 0 ? currentBrightness : 100;
63
+ let blur = currentBlur !== null && currentBlur !== void 0 ? currentBlur : 0;
64
+ const dataBrightness = element.getAttribute('data-brightness');
65
+ const dataBlur = element.getAttribute('data-blur');
66
+ if (dataBrightness) {
67
+ brightness = parseInt(dataBrightness);
68
+ }
69
+ else if (actualImgElement) {
70
+ const filterStyle = actualImgElement.style.filter || window.getComputedStyle(actualImgElement).filter;
71
+ if (filterStyle && filterStyle !== 'none') {
72
+ const brightnessMatch = filterStyle.match(/brightness\((\d+)%\)/);
73
+ if (brightnessMatch) {
74
+ brightness = parseInt(brightnessMatch[1]);
75
+ }
76
+ }
77
+ }
78
+ if (dataBlur) {
79
+ blur = parseInt(dataBlur);
80
+ }
81
+ else if (actualImgElement) {
82
+ const filterStyle = actualImgElement.style.filter || window.getComputedStyle(actualImgElement).filter;
83
+ if (filterStyle && filterStyle !== 'none') {
84
+ const blurMatch = filterStyle.match(/blur\((\d+)px\)/);
85
+ if (blurMatch) {
86
+ blur = parseInt(blurMatch[1]);
87
+ }
88
+ }
89
+ }
90
+ // Parse scale and position
91
+ let scale = 1.0;
92
+ let positionX = 0;
93
+ let positionY = 0;
94
+ const dataScale = element.getAttribute('data-scale');
95
+ const dataPositionX = element.getAttribute('data-position-x');
96
+ const dataPositionY = element.getAttribute('data-position-y');
97
+ if (dataScale) {
98
+ scale = parseFloat(dataScale);
99
+ }
100
+ else if (actualImgElement) {
101
+ const imgTransform = actualImgElement.style.transform || window.getComputedStyle(actualImgElement).transform;
102
+ if (imgTransform && imgTransform !== 'none') {
103
+ // Find container for baseScale calculation
104
+ const container = actualImgElement.closest('[class*="relative"]') || actualImgElement.parentElement;
105
+ scale = parseScaleFromTransform(imgTransform, container, actualImgElement);
106
+ }
107
+ }
108
+ if (dataPositionX) {
109
+ positionX = parseFloat(dataPositionX);
110
+ }
111
+ else if (actualImgElement) {
112
+ const imgTransform = actualImgElement.style.transform || window.getComputedStyle(actualImgElement).transform;
113
+ if (imgTransform && imgTransform !== 'none') {
114
+ const position = parsePositionFromTransform(imgTransform);
115
+ positionX = position.x;
116
+ positionY = position.y;
117
+ }
118
+ }
119
+ if (dataPositionY) {
120
+ positionY = parseFloat(dataPositionY);
121
+ }
122
+ // Detect styling
123
+ const styling = detectStyling(element, actualImgElement);
124
+ return Object.assign({ element, originalSrc: currentSrc, brightness,
125
+ blur,
126
+ scale,
127
+ positionX,
128
+ positionY,
129
+ isBackground }, styling);
130
+ }
@@ -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,261 @@
1
+ /**
2
+ * Image setup and click handlers
3
+ */
4
+ import { parseImageData } from './imageDetection';
5
+ /**
6
+ * Setup click handlers and hover effects for all images
7
+ */
8
+ export function setupImageHandlers(onImageClick) {
9
+ const cleanupFunctions = [];
10
+ const handleImageClick = (e) => {
11
+ var _a, _b, _c, _d;
12
+ const target = e.target;
13
+ // Only handle clicks on images that use the plugin components
14
+ let img = target.closest('img[data-image-id]');
15
+ let isBackground = false;
16
+ let element = null;
17
+ let currentSrc = '';
18
+ if (img) {
19
+ // This is a plugin Image component
20
+ element = img;
21
+ currentSrc = img.src;
22
+ }
23
+ else {
24
+ // Check if it's an element with background-image
25
+ let bgElement = target.closest('[data-background-image-component]');
26
+ if (bgElement) {
27
+ element = bgElement;
28
+ isBackground = true;
29
+ // Try to get image source from nested Image component first
30
+ const imgInside = bgElement.querySelector('img[data-image-id]');
31
+ if (imgInside) {
32
+ currentSrc = imgInside.src;
33
+ }
34
+ else {
35
+ // Fallback to background-image CSS
36
+ const bgImage = window.getComputedStyle(bgElement).backgroundImage;
37
+ const urlMatch = bgImage.match(/url\(['"]?([^'"]+)['"]?\)/);
38
+ if (urlMatch && urlMatch[1]) {
39
+ currentSrc = urlMatch[1];
40
+ }
41
+ }
42
+ }
43
+ }
44
+ if (!element || !currentSrc)
45
+ return;
46
+ // Don't handle images in modals or the editor itself
47
+ if (element.closest('[data-image-editor]') || element.closest('[role="dialog"]')) {
48
+ return;
49
+ }
50
+ e.preventDefault();
51
+ e.stopPropagation();
52
+ // Extract semantic ID from data attribute
53
+ let semanticId = element.getAttribute('data-image-id') || element.getAttribute('data-background-image-id');
54
+ // If not found, try to extract from the src URL
55
+ if (!semanticId && currentSrc.includes('/api/uploads/')) {
56
+ const urlPart = (_a = currentSrc.split('/api/uploads/')[1]) === null || _a === void 0 ? void 0 : _a.split('?')[0];
57
+ // If it looks like a semantic ID (no extension or timestamp), use it
58
+ if (urlPart && !/^\d+-/.test(urlPart) && !/\.(jpg|jpeg|png|webp|gif|svg)$/i.test(urlPart)) {
59
+ semanticId = decodeURIComponent(urlPart);
60
+ }
61
+ }
62
+ // If still not found, generate one
63
+ if (!semanticId) {
64
+ semanticId = ((_b = element.closest('[data-image-id]')) === null || _b === void 0 ? void 0 : _b.getAttribute('data-image-id')) ||
65
+ `image-${Date.now()}`;
66
+ }
67
+ // Parse image data
68
+ const filterStyle = element.style.filter || window.getComputedStyle(element).filter || '';
69
+ const dataBrightness = element.getAttribute('data-brightness');
70
+ const dataBlur = element.getAttribute('data-blur');
71
+ const currentBrightness = dataBrightness
72
+ ? parseInt(dataBrightness)
73
+ : parseInt(((_c = filterStyle.match(/brightness\((\d+)%\)/)) === null || _c === void 0 ? void 0 : _c[1]) || '100');
74
+ const currentBlur = dataBlur
75
+ ? parseInt(dataBlur)
76
+ : parseInt(((_d = filterStyle.match(/blur\((\d+)px\)/)) === null || _d === void 0 ? void 0 : _d[1]) || '0');
77
+ // Parse image data using the detection utility
78
+ const imageData = parseImageData(element, semanticId, currentBrightness, currentBlur);
79
+ if (!imageData) {
80
+ console.error('[GlobalImageEditor] Failed to parse image data');
81
+ return;
82
+ }
83
+ // Store semantic ID on element for later use
84
+ if (isBackground && !element.hasAttribute('data-background-image-id')) {
85
+ element.setAttribute('data-background-image-id', semanticId);
86
+ }
87
+ else if (!isBackground && !element.hasAttribute('data-image-id')) {
88
+ element.setAttribute('data-image-id', semanticId);
89
+ }
90
+ onImageClick(imageData);
91
+ };
92
+ // Add click listeners and hover effects to all images
93
+ const images = document.querySelectorAll('img[data-image-id]:not([data-no-edit])');
94
+ // Find elements with BackgroundImage components
95
+ const bgElements = [];
96
+ const backgroundImageComponents = document.querySelectorAll('[data-background-image-component]');
97
+ backgroundImageComponents.forEach(el => {
98
+ bgElements.push(el);
99
+ });
100
+ images.forEach((img, index) => {
101
+ const originalPosition = img.style.position;
102
+ img.style.cursor = 'pointer';
103
+ img.setAttribute('data-editable-image', 'true');
104
+ img.addEventListener('click', handleImageClick);
105
+ // Find the best container for the indicator
106
+ let indicatorContainer = img;
107
+ let parent = img.parentElement;
108
+ if (parent && (parent.tagName === 'SPAN' || parent.tagName === 'DIV')) {
109
+ const parentStyle = window.getComputedStyle(parent);
110
+ if (parentStyle.position !== 'static' ||
111
+ (parentStyle.display !== 'inline' && parentStyle.display !== 'inline-block')) {
112
+ indicatorContainer = parent;
113
+ }
114
+ }
115
+ // Ensure container has relative positioning
116
+ const containerStyle = window.getComputedStyle(indicatorContainer);
117
+ if (containerStyle.position === 'static') {
118
+ indicatorContainer.style.position = 'relative';
119
+ }
120
+ const indicator = document.createElement('div');
121
+ indicator.className = 'image-edit-indicator';
122
+ indicator.setAttribute('data-image-index', index.toString());
123
+ indicator.style.cssText = `
124
+ position: absolute;
125
+ top: 0;
126
+ left: 0;
127
+ width: 100%;
128
+ height: 100%;
129
+ background: rgba(0, 0, 0, 0.4);
130
+ display: flex;
131
+ align-items: center;
132
+ justify-content: center;
133
+ opacity: 0;
134
+ transition: opacity 0.2s ease;
135
+ pointer-events: none;
136
+ z-index: 10000;
137
+ border-radius: inherit;
138
+ box-sizing: border-box;
139
+ `;
140
+ const label = document.createElement('div');
141
+ label.style.cssText = `
142
+ background: rgba(0, 0, 0, 0.9);
143
+ color: white;
144
+ padding: 8px 16px;
145
+ border-radius: 8px;
146
+ font-size: 12px;
147
+ font-weight: bold;
148
+ text-transform: uppercase;
149
+ letter-spacing: 0.5px;
150
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
151
+ `;
152
+ label.textContent = 'Click to Edit';
153
+ indicator.appendChild(label);
154
+ indicatorContainer.appendChild(indicator);
155
+ const addHoverEffect = () => {
156
+ indicator.style.opacity = '1';
157
+ };
158
+ const removeHoverEffect = () => {
159
+ indicator.style.opacity = '0';
160
+ };
161
+ img.addEventListener('mouseenter', addHoverEffect);
162
+ img.addEventListener('mouseleave', removeHoverEffect);
163
+ if (indicatorContainer !== img) {
164
+ indicatorContainer.addEventListener('mouseenter', addHoverEffect);
165
+ indicatorContainer.addEventListener('mouseleave', removeHoverEffect);
166
+ }
167
+ cleanupFunctions.push(() => {
168
+ img.removeEventListener('click', handleImageClick);
169
+ img.removeEventListener('mouseenter', addHoverEffect);
170
+ img.removeEventListener('mouseleave', removeHoverEffect);
171
+ if (indicatorContainer !== img) {
172
+ indicatorContainer.removeEventListener('mouseenter', addHoverEffect);
173
+ indicatorContainer.removeEventListener('mouseleave', removeHoverEffect);
174
+ if (indicatorContainer.style.position === 'relative') {
175
+ indicatorContainer.style.position = '';
176
+ }
177
+ }
178
+ img.removeAttribute('data-editable-image');
179
+ img.style.cursor = '';
180
+ img.style.position = originalPosition;
181
+ indicator.remove();
182
+ });
183
+ });
184
+ // Process background images - show a button instead of hover overlay
185
+ bgElements.forEach((bgEl, index) => {
186
+ if (bgEl.hasAttribute('data-background-image-component')) {
187
+ return; // Skip BackgroundImage components - they have their own edit button
188
+ }
189
+ const originalPosition = bgEl.style.position;
190
+ if (!bgEl.style.position || bgEl.style.position === 'static') {
191
+ bgEl.style.position = 'relative';
192
+ }
193
+ bgEl.setAttribute('data-editable-background', 'true');
194
+ bgEl.setAttribute('data-background-image', 'true');
195
+ const buttonContainer = document.createElement('div');
196
+ buttonContainer.className = 'background-edit-button-container';
197
+ buttonContainer.setAttribute('data-image-index', `bg-${index}`);
198
+ buttonContainer.style.cssText = `
199
+ position: absolute;
200
+ top: 12px;
201
+ right: 12px;
202
+ z-index: 10000;
203
+ pointer-events: auto;
204
+ `;
205
+ const editButton = document.createElement('button');
206
+ editButton.className = 'background-edit-button';
207
+ editButton.setAttribute('type', 'button');
208
+ editButton.style.cssText = `
209
+ background: rgba(0, 0, 0, 0.8);
210
+ color: white;
211
+ border: 2px solid rgba(255, 255, 255, 0.3);
212
+ padding: 10px 20px;
213
+ border-radius: 8px;
214
+ font-size: 12px;
215
+ font-weight: bold;
216
+ text-transform: uppercase;
217
+ letter-spacing: 0.5px;
218
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
219
+ cursor: pointer;
220
+ transition: all 0.2s ease;
221
+ display: flex;
222
+ align-items: center;
223
+ gap: 8px;
224
+ `;
225
+ editButton.innerHTML = `
226
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
227
+ <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path>
228
+ <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path>
229
+ </svg>
230
+ Edit Background
231
+ `;
232
+ editButton.addEventListener('mouseenter', () => {
233
+ editButton.style.background = 'rgba(0, 0, 0, 0.95)';
234
+ editButton.style.borderColor = 'rgba(255, 255, 255, 0.5)';
235
+ editButton.style.transform = 'translateY(-2px)';
236
+ editButton.style.boxShadow = '0 6px 16px rgba(0, 0, 0, 0.5)';
237
+ });
238
+ editButton.addEventListener('mouseleave', () => {
239
+ editButton.style.background = 'rgba(0, 0, 0, 0.8)';
240
+ editButton.style.borderColor = 'rgba(255, 255, 255, 0.3)';
241
+ editButton.style.transform = 'translateY(0)';
242
+ editButton.style.boxShadow = '0 4px 12px rgba(0, 0, 0, 0.4)';
243
+ });
244
+ editButton.addEventListener('click', (e) => {
245
+ e.preventDefault();
246
+ e.stopPropagation();
247
+ handleImageClick(e);
248
+ });
249
+ buttonContainer.appendChild(editButton);
250
+ bgEl.appendChild(buttonContainer);
251
+ cleanupFunctions.push(() => {
252
+ bgEl.removeAttribute('data-editable-background');
253
+ bgEl.removeAttribute('data-background-image');
254
+ bgEl.style.position = originalPosition;
255
+ buttonContainer.remove();
256
+ });
257
+ });
258
+ return () => {
259
+ cleanupFunctions.forEach(cleanup => cleanup());
260
+ };
261
+ }
@@ -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"}