@jhits/plugin-images 0.0.8 → 0.0.9
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/package.json +2 -3
- package/src/api/fallback/route.ts +0 -69
- package/src/api/index.ts +0 -10
- package/src/api/list/index.ts +0 -96
- package/src/api/resolve/route.ts +0 -241
- package/src/api/router.ts +0 -85
- package/src/api/upload/index.ts +0 -88
- package/src/api/uploads/[filename]/route.ts +0 -93
- package/src/api-server.ts +0 -11
- package/src/assets/noimagefound.jpg +0 -0
- package/src/components/BackgroundImage.d.ts +0 -11
- package/src/components/BackgroundImage.d.ts.map +0 -1
- package/src/components/BackgroundImage.js +0 -35
- package/src/components/BackgroundImage.tsx +0 -92
- package/src/components/GlobalImageEditor/config.d.ts +0 -9
- package/src/components/GlobalImageEditor/config.d.ts.map +0 -1
- package/src/components/GlobalImageEditor/config.js +0 -18
- package/src/components/GlobalImageEditor/config.ts +0 -21
- package/src/components/GlobalImageEditor/eventHandlers.d.ts +0 -20
- package/src/components/GlobalImageEditor/eventHandlers.d.ts.map +0 -1
- package/src/components/GlobalImageEditor/eventHandlers.js +0 -206
- package/src/components/GlobalImageEditor/eventHandlers.ts +0 -267
- package/src/components/GlobalImageEditor/imageDetection.d.ts +0 -16
- package/src/components/GlobalImageEditor/imageDetection.d.ts.map +0 -1
- package/src/components/GlobalImageEditor/imageDetection.js +0 -130
- package/src/components/GlobalImageEditor/imageDetection.ts +0 -160
- package/src/components/GlobalImageEditor/imageSetup.d.ts +0 -9
- package/src/components/GlobalImageEditor/imageSetup.d.ts.map +0 -1
- package/src/components/GlobalImageEditor/imageSetup.js +0 -261
- package/src/components/GlobalImageEditor/imageSetup.ts +0 -306
- package/src/components/GlobalImageEditor/saveLogic.d.ts +0 -26
- package/src/components/GlobalImageEditor/saveLogic.d.ts.map +0 -1
- package/src/components/GlobalImageEditor/saveLogic.js +0 -99
- package/src/components/GlobalImageEditor/saveLogic.ts +0 -133
- package/src/components/GlobalImageEditor/stylingDetection.d.ts +0 -9
- package/src/components/GlobalImageEditor/stylingDetection.d.ts.map +0 -1
- package/src/components/GlobalImageEditor/stylingDetection.js +0 -110
- package/src/components/GlobalImageEditor/stylingDetection.ts +0 -122
- package/src/components/GlobalImageEditor/transformParsing.d.ts +0 -16
- package/src/components/GlobalImageEditor/transformParsing.d.ts.map +0 -1
- package/src/components/GlobalImageEditor/transformParsing.js +0 -68
- package/src/components/GlobalImageEditor/transformParsing.ts +0 -83
- package/src/components/GlobalImageEditor/types.d.ts +0 -36
- package/src/components/GlobalImageEditor/types.d.ts.map +0 -1
- package/src/components/GlobalImageEditor/types.js +0 -4
- package/src/components/GlobalImageEditor/types.ts +0 -39
- package/src/components/GlobalImageEditor.d.ts +0 -8
- package/src/components/GlobalImageEditor.d.ts.map +0 -1
- package/src/components/GlobalImageEditor.js +0 -227
- package/src/components/GlobalImageEditor.tsx +0 -327
- package/src/components/Image.d.ts +0 -22
- package/src/components/Image.d.ts.map +0 -1
- package/src/components/Image.js +0 -229
- package/src/components/Image.tsx +0 -343
- package/src/components/ImageBrowserModal.d.ts +0 -13
- package/src/components/ImageBrowserModal.d.ts.map +0 -1
- package/src/components/ImageBrowserModal.js +0 -504
- package/src/components/ImageBrowserModal.tsx +0 -837
- package/src/components/ImageEditor.d.ts +0 -27
- package/src/components/ImageEditor.d.ts.map +0 -1
- package/src/components/ImageEditor.js +0 -173
- package/src/components/ImageEditor.tsx +0 -323
- package/src/components/ImageEffectsPanel.tsx +0 -116
- package/src/components/ImagePicker.d.ts +0 -3
- package/src/components/ImagePicker.d.ts.map +0 -1
- package/src/components/ImagePicker.js +0 -143
- package/src/components/ImagePicker.tsx +0 -265
- package/src/components/ImagesPluginInit.d.ts +0 -24
- package/src/components/ImagesPluginInit.d.ts.map +0 -1
- package/src/components/ImagesPluginInit.js +0 -28
- package/src/components/ImagesPluginInit.tsx +0 -31
- package/src/components/index.ts +0 -10
- package/src/config.ts +0 -179
- package/src/hooks/useImagePicker.d.ts +0 -20
- package/src/hooks/useImagePicker.d.ts.map +0 -1
- package/src/hooks/useImagePicker.js +0 -322
- package/src/hooks/useImagePicker.ts +0 -344
- package/src/index.d.ts +0 -23
- package/src/index.d.ts.map +0 -1
- package/src/index.js +0 -28
- package/src/index.server.ts +0 -12
- package/src/index.tsx +0 -56
- package/src/init.d.ts +0 -33
- package/src/init.d.ts.map +0 -1
- package/src/init.js +0 -43
- package/src/init.tsx +0 -58
- package/src/types/index.d.ts +0 -80
- package/src/types/index.d.ts.map +0 -1
- package/src/types/index.js +0 -4
- package/src/types/index.ts +0 -84
- package/src/utils/fallback.d.ts +0 -27
- package/src/utils/fallback.d.ts.map +0 -1
- package/src/utils/fallback.js +0 -63
- package/src/utils/fallback.ts +0 -73
- package/src/utils/transforms.d.ts +0 -26
- package/src/utils/transforms.d.ts.map +0 -1
- package/src/utils/transforms.js +0 -38
- package/src/utils/transforms.ts +0 -54
- package/src/views/ImageManager.d.ts +0 -10
- package/src/views/ImageManager.d.ts.map +0 -1
- package/src/views/ImageManager.js +0 -9
- package/src/views/ImageManager.tsx +0 -30
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Event handlers for image changes and effects
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { SelectedImage } from './types';
|
|
6
|
-
import type { ImageMetadata } from '../../types';
|
|
7
|
-
import { getFilename, saveTransformToAPI, normalizePosition } from './saveLogic';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Apply image changes to DOM and save to API
|
|
11
|
-
*/
|
|
12
|
-
export async function handleImageChange(
|
|
13
|
-
image: ImageMetadata | null,
|
|
14
|
-
selectedImage: SelectedImage,
|
|
15
|
-
onClose: () => void
|
|
16
|
-
): Promise<void> {
|
|
17
|
-
if (!image) return;
|
|
18
|
-
|
|
19
|
-
const { element } = selectedImage;
|
|
20
|
-
const semanticId = element.getAttribute('data-image-id') ||
|
|
21
|
-
element.getAttribute('data-background-image-id');
|
|
22
|
-
|
|
23
|
-
if (!semanticId) {
|
|
24
|
-
console.error('[GlobalImageEditor] No semantic ID found for image');
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Extract filename from image URL or use image.id
|
|
29
|
-
const filename = image.url.split('/').pop()?.split('?')[0] || image.id;
|
|
30
|
-
const normalizedPositionX = normalizePosition(selectedImage.positionX);
|
|
31
|
-
const normalizedPositionY = normalizePosition(selectedImage.positionY);
|
|
32
|
-
|
|
33
|
-
// Save the mapping between semantic ID and filename, including effects and transforms
|
|
34
|
-
await saveTransformToAPI(
|
|
35
|
-
semanticId,
|
|
36
|
-
filename,
|
|
37
|
-
selectedImage.scale,
|
|
38
|
-
normalizedPositionX,
|
|
39
|
-
normalizedPositionY,
|
|
40
|
-
selectedImage.brightness,
|
|
41
|
-
selectedImage.blur
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
// Update image src immediately - handle background images differently
|
|
45
|
-
if (selectedImage.isBackground) {
|
|
46
|
-
updateBackgroundImage(element, image.url, selectedImage, normalizedPositionX, normalizedPositionY);
|
|
47
|
-
} else {
|
|
48
|
-
updateRegularImage(element, image.url, semanticId, selectedImage, normalizedPositionX, normalizedPositionY);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Dispatch a custom event to notify Image components to re-resolve
|
|
52
|
-
window.dispatchEvent(new CustomEvent('image-mapping-updated', {
|
|
53
|
-
detail: {
|
|
54
|
-
id: semanticId,
|
|
55
|
-
filename,
|
|
56
|
-
brightness: selectedImage.brightness,
|
|
57
|
-
blur: selectedImage.blur,
|
|
58
|
-
scale: selectedImage.scale,
|
|
59
|
-
positionX: selectedImage.positionX,
|
|
60
|
-
positionY: selectedImage.positionY,
|
|
61
|
-
}
|
|
62
|
-
}));
|
|
63
|
-
|
|
64
|
-
onClose();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Update background image element
|
|
69
|
-
*/
|
|
70
|
-
function updateBackgroundImage(
|
|
71
|
-
element: HTMLElement,
|
|
72
|
-
imageUrl: string,
|
|
73
|
-
selectedImage: SelectedImage,
|
|
74
|
-
normalizedPositionX: number,
|
|
75
|
-
normalizedPositionY: number
|
|
76
|
-
): void {
|
|
77
|
-
// For background images, update the nested Image component
|
|
78
|
-
const imgWrapper = element.querySelector('[data-image-id]');
|
|
79
|
-
if (imgWrapper) {
|
|
80
|
-
const img = imgWrapper.querySelector('img');
|
|
81
|
-
if (img) {
|
|
82
|
-
img.src = imageUrl;
|
|
83
|
-
img.setAttribute('data-edited-src', imageUrl);
|
|
84
|
-
img.style.transform = `scale(${selectedImage.scale}) translate(${normalizedPositionX}%, ${normalizedPositionY}%)`;
|
|
85
|
-
img.style.transformOrigin = 'center center';
|
|
86
|
-
}
|
|
87
|
-
} else {
|
|
88
|
-
// Fallback: update background-image style if no nested Image component
|
|
89
|
-
const bgImage = window.getComputedStyle(element).backgroundImage;
|
|
90
|
-
if (bgImage && bgImage !== 'none') {
|
|
91
|
-
element.style.backgroundImage = `url(${imageUrl})`;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Store attributes on the background container
|
|
96
|
-
const semanticId = element.getAttribute('data-image-id') || element.getAttribute('data-background-image-id') || '';
|
|
97
|
-
element.setAttribute('data-background-image-id', semanticId);
|
|
98
|
-
element.setAttribute('data-edited-src', imageUrl);
|
|
99
|
-
element.setAttribute('data-brightness', selectedImage.brightness.toString());
|
|
100
|
-
element.setAttribute('data-blur', selectedImage.blur.toString());
|
|
101
|
-
element.setAttribute('data-scale', selectedImage.scale.toString());
|
|
102
|
-
element.setAttribute('data-position-x', normalizedPositionX.toString());
|
|
103
|
-
element.setAttribute('data-position-y', normalizedPositionY.toString());
|
|
104
|
-
|
|
105
|
-
// Apply filter to the wrapper element
|
|
106
|
-
if (selectedImage.brightness !== 100 || selectedImage.blur !== 0) {
|
|
107
|
-
element.style.filter = `brightness(${selectedImage.brightness}%) blur(${selectedImage.blur}px)`;
|
|
108
|
-
} else {
|
|
109
|
-
element.style.filter = '';
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Update regular image element
|
|
115
|
-
*/
|
|
116
|
-
function updateRegularImage(
|
|
117
|
-
element: HTMLElement,
|
|
118
|
-
imageUrl: string,
|
|
119
|
-
semanticId: string,
|
|
120
|
-
selectedImage: SelectedImage,
|
|
121
|
-
normalizedPositionX: number,
|
|
122
|
-
normalizedPositionY: number
|
|
123
|
-
): void {
|
|
124
|
-
if (element.tagName === 'IMG') {
|
|
125
|
-
(element as HTMLImageElement).src = imageUrl;
|
|
126
|
-
element.setAttribute('data-edited-src', imageUrl);
|
|
127
|
-
element.setAttribute('data-image-id', semanticId);
|
|
128
|
-
element.setAttribute('data-brightness', selectedImage.brightness.toString());
|
|
129
|
-
element.setAttribute('data-blur', selectedImage.blur.toString());
|
|
130
|
-
|
|
131
|
-
// Apply filter
|
|
132
|
-
if (selectedImage.brightness !== 100 || selectedImage.blur !== 0) {
|
|
133
|
-
element.style.filter = `brightness(${selectedImage.brightness}%) blur(${selectedImage.blur}px)`;
|
|
134
|
-
} else {
|
|
135
|
-
element.style.filter = '';
|
|
136
|
-
}
|
|
137
|
-
} else {
|
|
138
|
-
// Next.js Image wrapper - find the actual img element
|
|
139
|
-
const img = element.querySelector('img');
|
|
140
|
-
if (img) {
|
|
141
|
-
img.src = imageUrl;
|
|
142
|
-
img.setAttribute('data-edited-src', imageUrl);
|
|
143
|
-
img.style.transform = `scale(${selectedImage.scale}) translate(${normalizedPositionX}%, ${normalizedPositionY}%)`;
|
|
144
|
-
img.style.transformOrigin = 'center center';
|
|
145
|
-
}
|
|
146
|
-
element.setAttribute('data-image-id', semanticId);
|
|
147
|
-
element.setAttribute('data-edited-src', imageUrl);
|
|
148
|
-
element.setAttribute('data-brightness', selectedImage.brightness.toString());
|
|
149
|
-
element.setAttribute('data-blur', selectedImage.blur.toString());
|
|
150
|
-
element.setAttribute('data-scale', selectedImage.scale.toString());
|
|
151
|
-
element.setAttribute('data-position-x', normalizedPositionX.toString());
|
|
152
|
-
element.setAttribute('data-position-y', normalizedPositionY.toString());
|
|
153
|
-
|
|
154
|
-
// Apply filter to wrapper
|
|
155
|
-
if (selectedImage.brightness !== 100 || selectedImage.blur !== 0) {
|
|
156
|
-
element.style.filter = `brightness(${selectedImage.brightness}%) blur(${selectedImage.blur}px)`;
|
|
157
|
-
} else {
|
|
158
|
-
element.style.filter = '';
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Get filename from element for saving effects
|
|
165
|
-
*/
|
|
166
|
-
async function getFilenameFromElement(
|
|
167
|
-
semanticId: string,
|
|
168
|
-
selectedImage: SelectedImage
|
|
169
|
-
): Promise<string> {
|
|
170
|
-
const filename = await getFilename(semanticId, selectedImage);
|
|
171
|
-
if (filename) return filename;
|
|
172
|
-
|
|
173
|
-
const { element } = selectedImage;
|
|
174
|
-
if (selectedImage.isBackground) {
|
|
175
|
-
const bgImage = window.getComputedStyle(element).backgroundImage;
|
|
176
|
-
const urlMatch = bgImage.match(/url\(['"]?([^'"]+)['"]?\)/);
|
|
177
|
-
if (urlMatch && urlMatch[1]) {
|
|
178
|
-
return urlMatch[1].split('/api/uploads/')[1]?.split('?')[0] || semanticId;
|
|
179
|
-
}
|
|
180
|
-
} else {
|
|
181
|
-
let imgSrc: string | null = null;
|
|
182
|
-
if (element instanceof HTMLImageElement && element.src) {
|
|
183
|
-
imgSrc = element.src;
|
|
184
|
-
} else {
|
|
185
|
-
const img = element.querySelector('img') as HTMLImageElement | null;
|
|
186
|
-
if (img?.src) {
|
|
187
|
-
imgSrc = img.src;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (imgSrc) {
|
|
191
|
-
return imgSrc.split('/api/uploads/')[1]?.split('?')[0] || semanticId;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return semanticId;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Handle brightness change
|
|
199
|
-
* @param saveImmediately - If true, save to API immediately. If false, only update state/DOM (for editor preview)
|
|
200
|
-
*/
|
|
201
|
-
export async function handleBrightnessChange(
|
|
202
|
-
brightness: number,
|
|
203
|
-
selectedImage: SelectedImage,
|
|
204
|
-
setSelectedImage: (image: SelectedImage) => void,
|
|
205
|
-
saveImmediately: boolean = true
|
|
206
|
-
): Promise<void> {
|
|
207
|
-
const { element } = selectedImage;
|
|
208
|
-
const semanticId = element.getAttribute('data-image-id') ||
|
|
209
|
-
element.getAttribute('data-background-image-id');
|
|
210
|
-
|
|
211
|
-
if (!semanticId) return;
|
|
212
|
-
|
|
213
|
-
const currentFilter = element.style.filter || '';
|
|
214
|
-
const blurMatch = currentFilter.match(/blur\((\d+)px\)/);
|
|
215
|
-
const blur = blurMatch ? parseInt(blurMatch[1]) : selectedImage.blur;
|
|
216
|
-
|
|
217
|
-
// Update the selectedImage state
|
|
218
|
-
setSelectedImage({
|
|
219
|
-
...selectedImage,
|
|
220
|
-
brightness,
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
element.style.filter = `brightness(${brightness}%) blur(${blur}px)`;
|
|
224
|
-
element.setAttribute('data-brightness', brightness.toString());
|
|
225
|
-
|
|
226
|
-
// Save the effect immediately only if requested (not when in editor)
|
|
227
|
-
if (saveImmediately) {
|
|
228
|
-
const filename = await getFilenameFromElement(semanticId, selectedImage);
|
|
229
|
-
await saveTransformToAPI(semanticId, filename, selectedImage.scale, selectedImage.positionX, selectedImage.positionY, brightness, blur);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Handle blur change
|
|
235
|
-
* @param saveImmediately - If true, save to API immediately. If false, only update state/DOM (for editor preview)
|
|
236
|
-
*/
|
|
237
|
-
export async function handleBlurChange(
|
|
238
|
-
blur: number,
|
|
239
|
-
selectedImage: SelectedImage,
|
|
240
|
-
setSelectedImage: (image: SelectedImage) => void,
|
|
241
|
-
saveImmediately: boolean = true
|
|
242
|
-
): Promise<void> {
|
|
243
|
-
const { element } = selectedImage;
|
|
244
|
-
const semanticId = element.getAttribute('data-image-id') ||
|
|
245
|
-
element.getAttribute('data-background-image-id');
|
|
246
|
-
|
|
247
|
-
if (!semanticId) return;
|
|
248
|
-
|
|
249
|
-
const currentFilter = element.style.filter || '';
|
|
250
|
-
const brightnessMatch = currentFilter.match(/brightness\((\d+)%\)/);
|
|
251
|
-
const brightness = brightnessMatch ? parseInt(brightnessMatch[1]) : selectedImage.brightness;
|
|
252
|
-
|
|
253
|
-
// Update the selectedImage state
|
|
254
|
-
setSelectedImage({
|
|
255
|
-
...selectedImage,
|
|
256
|
-
blur,
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
element.style.filter = `brightness(${brightness}%) blur(${blur}px)`;
|
|
260
|
-
element.setAttribute('data-blur', blur.toString());
|
|
261
|
-
|
|
262
|
-
// Save the effect immediately only if requested (not when in editor)
|
|
263
|
-
if (saveImmediately) {
|
|
264
|
-
const filename = await getFilenameFromElement(semanticId, selectedImage);
|
|
265
|
-
await saveTransformToAPI(semanticId, filename, selectedImage.scale, selectedImage.positionX, selectedImage.positionY, brightness, blur);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,130 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|