@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,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Save logic for image transforms and effects
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Normalize position values - convert -50% (centering value) to 0
|
|
6
|
-
*/
|
|
7
|
-
export function normalizePosition(position) {
|
|
8
|
-
return position === -50 ? 0 : position;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Get filename from element or API
|
|
12
|
-
*/
|
|
13
|
-
export async function getFilename(semanticId, selectedImage) {
|
|
14
|
-
var _a, _b;
|
|
15
|
-
try {
|
|
16
|
-
const response = await fetch(`/api/plugin-images/resolve?id=${encodeURIComponent(semanticId)}`);
|
|
17
|
-
if (response.ok) {
|
|
18
|
-
const data = await response.json();
|
|
19
|
-
return data.filename || semanticId;
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
// If not found, try to extract from element
|
|
23
|
-
const { element } = selectedImage;
|
|
24
|
-
if (selectedImage.isBackground) {
|
|
25
|
-
const imgWrapper = element.querySelector('[data-image-id]');
|
|
26
|
-
if (imgWrapper) {
|
|
27
|
-
const img = imgWrapper.querySelector('img');
|
|
28
|
-
if (img && img.src) {
|
|
29
|
-
return ((_a = img.src.split('/api/uploads/')[1]) === null || _a === void 0 ? void 0 : _a.split('?')[0]) || semanticId;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
const img = element.tagName === 'IMG' ? element : element.querySelector('img');
|
|
35
|
-
if (img && img.src) {
|
|
36
|
-
return ((_b = img.src.split('/api/uploads/')[1]) === null || _b === void 0 ? void 0 : _b.split('?')[0]) || semanticId;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
console.error('Failed to get filename:', error);
|
|
43
|
-
}
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Save image transform to API
|
|
48
|
-
*/
|
|
49
|
-
export async function saveTransformToAPI(semanticId, filename, scale, positionX, positionY, brightness, blur) {
|
|
50
|
-
try {
|
|
51
|
-
const response = await fetch('/api/plugin-images/resolve', {
|
|
52
|
-
method: 'POST',
|
|
53
|
-
headers: { 'Content-Type': 'application/json' },
|
|
54
|
-
body: JSON.stringify({
|
|
55
|
-
id: semanticId,
|
|
56
|
-
filename,
|
|
57
|
-
brightness,
|
|
58
|
-
blur,
|
|
59
|
-
scale,
|
|
60
|
-
positionX: normalizePosition(positionX),
|
|
61
|
-
positionY: normalizePosition(positionY),
|
|
62
|
-
}),
|
|
63
|
-
});
|
|
64
|
-
if (response.ok) {
|
|
65
|
-
// Dispatch event to notify Image components
|
|
66
|
-
window.dispatchEvent(new CustomEvent('image-mapping-updated', {
|
|
67
|
-
detail: {
|
|
68
|
-
id: semanticId,
|
|
69
|
-
filename,
|
|
70
|
-
brightness,
|
|
71
|
-
blur,
|
|
72
|
-
scale,
|
|
73
|
-
positionX: normalizePosition(positionX),
|
|
74
|
-
positionY: normalizePosition(positionY),
|
|
75
|
-
}
|
|
76
|
-
}));
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
console.error('Failed to save transform:', error);
|
|
82
|
-
}
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Flush pending save immediately
|
|
87
|
-
*/
|
|
88
|
-
export async function flushPendingSave(pending, selectedImage) {
|
|
89
|
-
const normalizedPositionX = normalizePosition(pending.positionX);
|
|
90
|
-
const normalizedPositionY = normalizePosition(pending.positionY);
|
|
91
|
-
await saveTransformToAPI(pending.semanticId, pending.filename, pending.scale, normalizedPositionX, normalizedPositionY, selectedImage.brightness, selectedImage.blur);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Save image transform with debouncing support
|
|
95
|
-
* This is a wrapper that handles the debouncing logic
|
|
96
|
-
*/
|
|
97
|
-
export async function saveImageTransform(semanticId, filename, scale, positionX, positionY, brightness, blur) {
|
|
98
|
-
await saveTransformToAPI(semanticId, filename, scale, positionX, positionY, brightness, blur);
|
|
99
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utilities for detecting styling from DOM elements
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Detect styling properties from an element and its parent containers
|
|
6
|
-
*/
|
|
7
|
-
export function detectStyling(element, imgElement) {
|
|
8
|
-
// Find the container element (could be the element itself or a parent)
|
|
9
|
-
let container = element;
|
|
10
|
-
let parent = element.parentElement;
|
|
11
|
-
// Look for styling in parent containers (up to 3 levels)
|
|
12
|
-
for (let i = 0; i < 3 && parent; i++) {
|
|
13
|
-
const classes = parent.className || '';
|
|
14
|
-
const computedStyle = window.getComputedStyle(parent);
|
|
15
|
-
// Check for rounded-full (circular)
|
|
16
|
-
if (classes.includes('rounded-full')) {
|
|
17
|
-
container = parent;
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
parent = parent.parentElement;
|
|
21
|
-
}
|
|
22
|
-
const containerClasses = container.className || '';
|
|
23
|
-
const containerStyle = window.getComputedStyle(container);
|
|
24
|
-
const imgStyle = imgElement ? window.getComputedStyle(imgElement) : null;
|
|
25
|
-
// Detect border radius
|
|
26
|
-
let borderRadius = 'rounded-xl'; // default
|
|
27
|
-
if (containerClasses.includes('rounded-full')) {
|
|
28
|
-
borderRadius = 'rounded-full';
|
|
29
|
-
}
|
|
30
|
-
else if (containerClasses.includes('rounded-3xl')) {
|
|
31
|
-
borderRadius = 'rounded-3xl';
|
|
32
|
-
}
|
|
33
|
-
else if (containerClasses.includes('rounded-2xl')) {
|
|
34
|
-
borderRadius = 'rounded-2xl';
|
|
35
|
-
}
|
|
36
|
-
else if (containerClasses.includes('rounded-xl')) {
|
|
37
|
-
borderRadius = 'rounded-xl';
|
|
38
|
-
}
|
|
39
|
-
else if (containerClasses.includes('rounded-lg')) {
|
|
40
|
-
borderRadius = 'rounded-lg';
|
|
41
|
-
}
|
|
42
|
-
// Detect aspect ratio
|
|
43
|
-
let aspectRatio = '16/9'; // default
|
|
44
|
-
// First check the container's computed style
|
|
45
|
-
const aspectRatioStyle = containerStyle.aspectRatio;
|
|
46
|
-
if (aspectRatioStyle && aspectRatioStyle !== 'auto') {
|
|
47
|
-
// Convert CSS aspect-ratio (e.g., "1 / 1") to our format ("1/1")
|
|
48
|
-
aspectRatio = aspectRatioStyle.replace(/\s+/g, '');
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
// Check for Tailwind aspect ratio classes in container or parents
|
|
52
|
-
let currentElement = container;
|
|
53
|
-
let foundAspectRatio = false;
|
|
54
|
-
// Check up to 3 parent levels for aspect ratio
|
|
55
|
-
for (let i = 0; i < 3 && currentElement && !foundAspectRatio; i++) {
|
|
56
|
-
const classes = currentElement.className || '';
|
|
57
|
-
const computedStyle = window.getComputedStyle(currentElement);
|
|
58
|
-
// Check computed style first
|
|
59
|
-
if (computedStyle.aspectRatio && computedStyle.aspectRatio !== 'auto') {
|
|
60
|
-
aspectRatio = computedStyle.aspectRatio.replace(/\s+/g, '');
|
|
61
|
-
foundAspectRatio = true;
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
// Check for Tailwind aspect ratio classes (aspect-*, aspect-square, aspect-video, etc.)
|
|
65
|
-
const aspectMatch = classes.match(/aspect-(\d+\/\d+)|aspect-square|aspect-video/);
|
|
66
|
-
if (aspectMatch) {
|
|
67
|
-
if (aspectMatch[1]) {
|
|
68
|
-
// Matched aspect-4/5, aspect-16/9, etc.
|
|
69
|
-
aspectRatio = aspectMatch[1];
|
|
70
|
-
}
|
|
71
|
-
else if (aspectMatch[0] === 'aspect-square') {
|
|
72
|
-
aspectRatio = '1/1';
|
|
73
|
-
}
|
|
74
|
-
else if (aspectMatch[0] === 'aspect-video') {
|
|
75
|
-
aspectRatio = '16/9';
|
|
76
|
-
}
|
|
77
|
-
foundAspectRatio = true;
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
currentElement = currentElement.parentElement;
|
|
81
|
-
}
|
|
82
|
-
// Fallback checks
|
|
83
|
-
if (!foundAspectRatio) {
|
|
84
|
-
if (containerClasses.includes('rounded-full')) {
|
|
85
|
-
// Circular images are typically 1:1
|
|
86
|
-
aspectRatio = '1/1';
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
// Try to detect from size classes
|
|
90
|
-
if (containerClasses.includes('size-') || containerClasses.match(/w-\d+.*h-\d+/)) {
|
|
91
|
-
aspectRatio = '1/1';
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
// Detect object-fit
|
|
97
|
-
let objectFit = 'cover';
|
|
98
|
-
if (imgStyle) {
|
|
99
|
-
const objectFitValue = imgStyle.objectFit || containerStyle.objectFit;
|
|
100
|
-
if (objectFitValue && ['cover', 'contain', 'fill', 'none', 'scale-down'].includes(objectFitValue)) {
|
|
101
|
-
objectFit = objectFitValue;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
// Detect object-position
|
|
105
|
-
let objectPosition = 'center';
|
|
106
|
-
if (imgStyle) {
|
|
107
|
-
objectPosition = imgStyle.objectPosition || containerStyle.objectPosition || 'center';
|
|
108
|
-
}
|
|
109
|
-
return { aspectRatio, borderRadius, objectFit, objectPosition };
|
|
110
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utilities for detecting styling from DOM elements
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { DetectedStyling } from './types';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Detect styling properties from an element and its parent containers
|
|
9
|
-
*/
|
|
10
|
-
export function detectStyling(
|
|
11
|
-
element: HTMLElement,
|
|
12
|
-
imgElement: HTMLImageElement | null
|
|
13
|
-
): DetectedStyling {
|
|
14
|
-
// Find the container element (could be the element itself or a parent)
|
|
15
|
-
let container = element;
|
|
16
|
-
let parent = element.parentElement;
|
|
17
|
-
|
|
18
|
-
// Look for styling in parent containers (up to 3 levels)
|
|
19
|
-
for (let i = 0; i < 3 && parent; i++) {
|
|
20
|
-
const classes = parent.className || '';
|
|
21
|
-
const computedStyle = window.getComputedStyle(parent);
|
|
22
|
-
|
|
23
|
-
// Check for rounded-full (circular)
|
|
24
|
-
if (classes.includes('rounded-full')) {
|
|
25
|
-
container = parent;
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
parent = parent.parentElement;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const containerClasses = container.className || '';
|
|
32
|
-
const containerStyle = window.getComputedStyle(container);
|
|
33
|
-
const imgStyle = imgElement ? window.getComputedStyle(imgElement) : null;
|
|
34
|
-
|
|
35
|
-
// Detect border radius
|
|
36
|
-
let borderRadius = 'rounded-xl'; // default
|
|
37
|
-
if (containerClasses.includes('rounded-full')) {
|
|
38
|
-
borderRadius = 'rounded-full';
|
|
39
|
-
} else if (containerClasses.includes('rounded-3xl')) {
|
|
40
|
-
borderRadius = 'rounded-3xl';
|
|
41
|
-
} else if (containerClasses.includes('rounded-2xl')) {
|
|
42
|
-
borderRadius = 'rounded-2xl';
|
|
43
|
-
} else if (containerClasses.includes('rounded-xl')) {
|
|
44
|
-
borderRadius = 'rounded-xl';
|
|
45
|
-
} else if (containerClasses.includes('rounded-lg')) {
|
|
46
|
-
borderRadius = 'rounded-lg';
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Detect aspect ratio
|
|
50
|
-
let aspectRatio = '16/9'; // default
|
|
51
|
-
|
|
52
|
-
// First check the container's computed style
|
|
53
|
-
const aspectRatioStyle = containerStyle.aspectRatio;
|
|
54
|
-
if (aspectRatioStyle && aspectRatioStyle !== 'auto') {
|
|
55
|
-
// Convert CSS aspect-ratio (e.g., "1 / 1") to our format ("1/1")
|
|
56
|
-
aspectRatio = aspectRatioStyle.replace(/\s+/g, '');
|
|
57
|
-
} else {
|
|
58
|
-
// Check for Tailwind aspect ratio classes in container or parents
|
|
59
|
-
let currentElement: HTMLElement | null = container;
|
|
60
|
-
let foundAspectRatio = false;
|
|
61
|
-
|
|
62
|
-
// Check up to 3 parent levels for aspect ratio
|
|
63
|
-
for (let i = 0; i < 3 && currentElement && !foundAspectRatio; i++) {
|
|
64
|
-
const classes = currentElement.className || '';
|
|
65
|
-
const computedStyle = window.getComputedStyle(currentElement);
|
|
66
|
-
|
|
67
|
-
// Check computed style first
|
|
68
|
-
if (computedStyle.aspectRatio && computedStyle.aspectRatio !== 'auto') {
|
|
69
|
-
aspectRatio = computedStyle.aspectRatio.replace(/\s+/g, '');
|
|
70
|
-
foundAspectRatio = true;
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Check for Tailwind aspect ratio classes (aspect-*, aspect-square, aspect-video, etc.)
|
|
75
|
-
const aspectMatch = classes.match(/aspect-(\d+\/\d+)|aspect-square|aspect-video/);
|
|
76
|
-
if (aspectMatch) {
|
|
77
|
-
if (aspectMatch[1]) {
|
|
78
|
-
// Matched aspect-4/5, aspect-16/9, etc.
|
|
79
|
-
aspectRatio = aspectMatch[1];
|
|
80
|
-
} else if (aspectMatch[0] === 'aspect-square') {
|
|
81
|
-
aspectRatio = '1/1';
|
|
82
|
-
} else if (aspectMatch[0] === 'aspect-video') {
|
|
83
|
-
aspectRatio = '16/9';
|
|
84
|
-
}
|
|
85
|
-
foundAspectRatio = true;
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
currentElement = currentElement.parentElement;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Fallback checks
|
|
93
|
-
if (!foundAspectRatio) {
|
|
94
|
-
if (containerClasses.includes('rounded-full')) {
|
|
95
|
-
// Circular images are typically 1:1
|
|
96
|
-
aspectRatio = '1/1';
|
|
97
|
-
} else {
|
|
98
|
-
// Try to detect from size classes
|
|
99
|
-
if (containerClasses.includes('size-') || containerClasses.match(/w-\d+.*h-\d+/)) {
|
|
100
|
-
aspectRatio = '1/1';
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Detect object-fit
|
|
107
|
-
let objectFit: 'cover' | 'contain' | 'fill' | 'none' | 'scale-down' = 'cover';
|
|
108
|
-
if (imgStyle) {
|
|
109
|
-
const objectFitValue = imgStyle.objectFit || containerStyle.objectFit;
|
|
110
|
-
if (objectFitValue && ['cover', 'contain', 'fill', 'none', 'scale-down'].includes(objectFitValue)) {
|
|
111
|
-
objectFit = objectFitValue as 'cover' | 'contain' | 'fill' | 'none' | 'scale-down';
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Detect object-position
|
|
116
|
-
let objectPosition = 'center';
|
|
117
|
-
if (imgStyle) {
|
|
118
|
-
objectPosition = imgStyle.objectPosition || containerStyle.objectPosition || 'center';
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return { aspectRatio, borderRadius, objectFit, objectPosition };
|
|
122
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utilities for parsing CSS transforms to extract scale and position values
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Parse scale from CSS transform string
|
|
6
|
-
*/
|
|
7
|
-
export declare function parseScaleFromTransform(transform: string, container: HTMLElement | null, imgElement: HTMLImageElement | null): number;
|
|
8
|
-
/**
|
|
9
|
-
* Parse position (X, Y) from CSS transform string
|
|
10
|
-
* Returns container-relative percentages
|
|
11
|
-
*/
|
|
12
|
-
export declare function parsePositionFromTransform(transform: string): {
|
|
13
|
-
x: number;
|
|
14
|
-
y: number;
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=transformParsing.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transformParsing.d.ts","sourceRoot":"","sources":["transformParsing.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,wBAAgB,uBAAuB,CACnC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,WAAW,GAAG,IAAI,EAC7B,UAAU,EAAE,gBAAgB,GAAG,IAAI,GACpC,MAAM,CA+BR;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAkCtF"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utilities for parsing CSS transforms to extract scale and position values
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Parse scale from CSS transform string
|
|
6
|
-
*/
|
|
7
|
-
export function parseScaleFromTransform(transform, container, imgElement) {
|
|
8
|
-
const scaleMatch = transform.match(/scale\(([\d.]+)\)/);
|
|
9
|
-
if (!scaleMatch)
|
|
10
|
-
return 1.0;
|
|
11
|
-
const totalScale = parseFloat(scaleMatch[1]);
|
|
12
|
-
// If totalScale is very small (< 0.1), it's likely wrong
|
|
13
|
-
if (totalScale < 0.1) {
|
|
14
|
-
return 1.0;
|
|
15
|
-
}
|
|
16
|
-
// Calculate baseScale to extract the actual user scale
|
|
17
|
-
if (container && imgElement && imgElement.naturalWidth > 0 && imgElement.naturalHeight > 0) {
|
|
18
|
-
const containerWidth = container.clientWidth || container.offsetWidth;
|
|
19
|
-
const containerHeight = container.clientHeight || container.offsetHeight;
|
|
20
|
-
if (containerWidth > 0 && containerHeight > 0) {
|
|
21
|
-
const widthRatio = containerWidth / imgElement.naturalWidth;
|
|
22
|
-
const heightRatio = containerHeight / imgElement.naturalHeight;
|
|
23
|
-
const baseScale = Math.max(widthRatio, heightRatio);
|
|
24
|
-
if (baseScale > 0 && baseScale < 1) {
|
|
25
|
-
// Extract the actual scale by dividing totalScale by baseScale
|
|
26
|
-
const scale = totalScale / baseScale;
|
|
27
|
-
// Clamp to valid range
|
|
28
|
-
return Math.max(0.1, Math.min(5.0, scale));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return 1.0;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Parse position (X, Y) from CSS transform string
|
|
36
|
-
* Returns container-relative percentages
|
|
37
|
-
*/
|
|
38
|
-
export function parsePositionFromTransform(transform) {
|
|
39
|
-
// Match all translate() calls - skip the first one if it's the centering translate(-50%, -50%)
|
|
40
|
-
const allTranslates = transform.matchAll(/translate\(([-\d.]+)%,?\s*([-\d.]+)?%?\)/g);
|
|
41
|
-
const translateArray = Array.from(allTranslates);
|
|
42
|
-
let positionX = 0;
|
|
43
|
-
let positionY = 0;
|
|
44
|
-
if (translateArray.length > 1) {
|
|
45
|
-
// Use the second translate (the position offset)
|
|
46
|
-
const positionTranslate = translateArray[1];
|
|
47
|
-
const appliedX = parseFloat(positionTranslate[1] || '0');
|
|
48
|
-
const appliedY = parseFloat(positionTranslate[2] || '0');
|
|
49
|
-
// Only use if it's not the centering translate (safety check)
|
|
50
|
-
if (appliedX !== -50 || appliedY !== -50) {
|
|
51
|
-
// With new system, applied value IS the stored value (container-relative)
|
|
52
|
-
positionX = appliedX;
|
|
53
|
-
positionY = appliedY;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
else if (translateArray.length === 1) {
|
|
57
|
-
// Only one translate - check if it's the centering one
|
|
58
|
-
const translate = translateArray[0];
|
|
59
|
-
const appliedX = parseFloat(translate[1] || '0');
|
|
60
|
-
const appliedY = parseFloat(translate[2] || '0');
|
|
61
|
-
// If it's not the centering translate, use it as position
|
|
62
|
-
if (appliedX !== -50 || appliedY !== -50) {
|
|
63
|
-
positionX = appliedX;
|
|
64
|
-
positionY = appliedY;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return { x: positionX, y: positionY };
|
|
68
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utilities for parsing CSS transforms to extract scale and position values
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Parse scale from CSS transform string
|
|
7
|
-
*/
|
|
8
|
-
export function parseScaleFromTransform(
|
|
9
|
-
transform: string,
|
|
10
|
-
container: HTMLElement | null,
|
|
11
|
-
imgElement: HTMLImageElement | null
|
|
12
|
-
): number {
|
|
13
|
-
const scaleMatch = transform.match(/scale\(([\d.]+)\)/);
|
|
14
|
-
if (!scaleMatch) return 1.0;
|
|
15
|
-
|
|
16
|
-
const totalScale = parseFloat(scaleMatch[1]);
|
|
17
|
-
|
|
18
|
-
// If totalScale is very small (< 0.1), it's likely wrong
|
|
19
|
-
if (totalScale < 0.1) {
|
|
20
|
-
return 1.0;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Calculate baseScale to extract the actual user scale
|
|
24
|
-
if (container && imgElement && imgElement.naturalWidth > 0 && imgElement.naturalHeight > 0) {
|
|
25
|
-
const containerWidth = container.clientWidth || container.offsetWidth;
|
|
26
|
-
const containerHeight = container.clientHeight || container.offsetHeight;
|
|
27
|
-
|
|
28
|
-
if (containerWidth > 0 && containerHeight > 0) {
|
|
29
|
-
const widthRatio = containerWidth / imgElement.naturalWidth;
|
|
30
|
-
const heightRatio = containerHeight / imgElement.naturalHeight;
|
|
31
|
-
const baseScale = Math.max(widthRatio, heightRatio);
|
|
32
|
-
|
|
33
|
-
if (baseScale > 0 && baseScale < 1) {
|
|
34
|
-
// Extract the actual scale by dividing totalScale by baseScale
|
|
35
|
-
const scale = totalScale / baseScale;
|
|
36
|
-
// Clamp to valid range
|
|
37
|
-
return Math.max(0.1, Math.min(5.0, scale));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return 1.0;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Parse position (X, Y) from CSS transform string
|
|
47
|
-
* Returns container-relative percentages
|
|
48
|
-
*/
|
|
49
|
-
export function parsePositionFromTransform(transform: string): { x: number; y: number } {
|
|
50
|
-
// Match all translate() calls - skip the first one if it's the centering translate(-50%, -50%)
|
|
51
|
-
const allTranslates = transform.matchAll(/translate\(([-\d.]+)%,?\s*([-\d.]+)?%?\)/g);
|
|
52
|
-
const translateArray = Array.from(allTranslates);
|
|
53
|
-
|
|
54
|
-
let positionX = 0;
|
|
55
|
-
let positionY = 0;
|
|
56
|
-
|
|
57
|
-
if (translateArray.length > 1) {
|
|
58
|
-
// Use the second translate (the position offset)
|
|
59
|
-
const positionTranslate = translateArray[1];
|
|
60
|
-
const appliedX = parseFloat(positionTranslate[1] || '0');
|
|
61
|
-
const appliedY = parseFloat(positionTranslate[2] || '0');
|
|
62
|
-
|
|
63
|
-
// Only use if it's not the centering translate (safety check)
|
|
64
|
-
if (appliedX !== -50 || appliedY !== -50) {
|
|
65
|
-
// With new system, applied value IS the stored value (container-relative)
|
|
66
|
-
positionX = appliedX;
|
|
67
|
-
positionY = appliedY;
|
|
68
|
-
}
|
|
69
|
-
} else if (translateArray.length === 1) {
|
|
70
|
-
// Only one translate - check if it's the centering one
|
|
71
|
-
const translate = translateArray[0];
|
|
72
|
-
const appliedX = parseFloat(translate[1] || '0');
|
|
73
|
-
const appliedY = parseFloat(translate[2] || '0');
|
|
74
|
-
|
|
75
|
-
// If it's not the centering translate, use it as position
|
|
76
|
-
if (appliedX !== -50 || appliedY !== -50) {
|
|
77
|
-
positionX = appliedX;
|
|
78
|
-
positionY = appliedY;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return { x: positionX, y: positionY };
|
|
83
|
-
}
|