@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,99 @@
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
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Utilities for detecting styling from DOM elements
3
+ */
4
+ import type { DetectedStyling } from './types';
5
+ /**
6
+ * Detect styling properties from an element and its parent containers
7
+ */
8
+ export declare function detectStyling(element: HTMLElement, imgElement: HTMLImageElement | null): DetectedStyling;
9
+ //# sourceMappingURL=stylingDetection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stylingDetection.d.ts","sourceRoot":"","sources":["stylingDetection.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;GAEG;AACH,wBAAgB,aAAa,CACzB,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,gBAAgB,GAAG,IAAI,GACpC,eAAe,CA6GjB"}
@@ -0,0 +1,110 @@
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
+ }
@@ -0,0 +1,16 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,68 @@
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
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Types for GlobalImageEditor component
3
+ */
4
+ export interface SelectedImage {
5
+ element: HTMLElement;
6
+ originalSrc: string;
7
+ brightness: number;
8
+ blur: number;
9
+ scale: number;
10
+ positionX: number;
11
+ positionY: number;
12
+ isBackground: boolean;
13
+ aspectRatio?: string;
14
+ borderRadius?: string;
15
+ objectFit?: 'cover' | 'contain' | 'fill' | 'none' | 'scale-down';
16
+ objectPosition?: string;
17
+ }
18
+ export interface PluginConfig {
19
+ enabled: boolean;
20
+ className?: string;
21
+ overlayClassName?: string;
22
+ }
23
+ export interface DetectedStyling {
24
+ aspectRatio: string;
25
+ borderRadius: string;
26
+ objectFit: 'cover' | 'contain' | 'fill' | 'none' | 'scale-down';
27
+ objectPosition: string;
28
+ }
29
+ export interface PendingTransform {
30
+ scale: number;
31
+ positionX: number;
32
+ positionY: number;
33
+ semanticId: string;
34
+ filename: string;
35
+ }
36
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,aAAa;IAC1B,OAAO,EAAE,WAAW,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC;IACjE,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,YAAY;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,eAAe;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC;IAChE,cAAc,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CACpB"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Types for GlobalImageEditor component
3
+ */
4
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Global Image Editor Component
3
+ * Allows clicking on any image in the client app to edit it (admin/dev only)
4
+ *
5
+ * Reads configuration from window.__JHITS_PLUGIN_PROPS__['plugin-images']
6
+ */
7
+ export declare function GlobalImageEditor(): import("react/jsx-runtime").JSX.Element | null;
8
+ //# sourceMappingURL=GlobalImageEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GlobalImageEditor.d.ts","sourceRoot":"","sources":["GlobalImageEditor.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH,wBAAgB,iBAAiB,mDAkThC"}
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Global Image Editor Component
3
+ * Allows clicking on any image in the client app to edit it (admin/dev only)
4
+ *
5
+ * Reads configuration from window.__JHITS_PLUGIN_PROPS__['plugin-images']
6
+ */
7
+ 'use client';
8
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
+ import { useState, useEffect, useRef, useMemo, useCallback } from 'react';
10
+ import { X } from 'lucide-react';
11
+ import { ImagePicker } from './ImagePicker';
12
+ import { getPluginConfig } from './GlobalImageEditor/config';
13
+ import { parseImageData } from './GlobalImageEditor/imageDetection';
14
+ import { setupImageHandlers } from './GlobalImageEditor/imageSetup';
15
+ import { saveTransformToAPI, flushPendingSave, getFilename, normalizePosition } from './GlobalImageEditor/saveLogic';
16
+ import { handleImageChange, handleBrightnessChange, handleBlurChange } from './GlobalImageEditor/eventHandlers';
17
+ export function GlobalImageEditor() {
18
+ // Configuration
19
+ const config = useMemo(() => getPluginConfig(), []);
20
+ // State
21
+ const [selectedImage, setSelectedImage] = useState(null);
22
+ const [isOpen, setIsOpen] = useState(false);
23
+ const [userRole, setUserRole] = useState(null);
24
+ const [isLoading, setIsLoading] = useState(true);
25
+ // Refs for save debouncing
26
+ const saveTransformTimeoutRef = useRef(null);
27
+ const pendingTransformRef = useRef(null);
28
+ // Check if user is admin/dev
29
+ useEffect(() => {
30
+ const checkUser = async () => {
31
+ var _a, _b;
32
+ try {
33
+ const res = await fetch('/api/me');
34
+ const data = await res.json();
35
+ if (data.loggedIn && (((_a = data.user) === null || _a === void 0 ? void 0 : _a.role) === 'admin' || ((_b = data.user) === null || _b === void 0 ? void 0 : _b.role) === 'dev')) {
36
+ setUserRole(data.user.role);
37
+ }
38
+ }
39
+ catch (error) {
40
+ console.error('Failed to check user role:', error);
41
+ }
42
+ finally {
43
+ setIsLoading(false);
44
+ }
45
+ };
46
+ checkUser();
47
+ }, []);
48
+ // Listen for open-image-editor custom event from Image/BackgroundImage components
49
+ useEffect(() => {
50
+ if (!userRole)
51
+ return;
52
+ const handleOpenEditor = async (e) => {
53
+ const { id, currentBrightness, currentBlur } = e.detail || {};
54
+ if (!id)
55
+ return;
56
+ // Find the element by data-image-id or data-background-image-id
57
+ let element = document.querySelector(`[data-image-id="${id}"], [data-background-image-id="${id}"]`);
58
+ if (!element) {
59
+ element = document.querySelector(`[data-background-image-component="true"][data-background-image-id="${id}"]`);
60
+ }
61
+ if (!element) {
62
+ console.error('[GlobalImageEditor] Element not found for id:', id);
63
+ return;
64
+ }
65
+ // Extract semantic ID
66
+ const semanticId = element.getAttribute('data-image-id') ||
67
+ element.getAttribute('data-background-image-id') ||
68
+ id;
69
+ // Parse image data
70
+ const imageData = parseImageData(element, semanticId, currentBrightness, currentBlur);
71
+ if (!imageData) {
72
+ console.error('[GlobalImageEditor] Failed to parse image data');
73
+ return;
74
+ }
75
+ // Store semantic ID on element if not already set
76
+ if (imageData.isBackground && !element.hasAttribute('data-background-image-id')) {
77
+ element.setAttribute('data-background-image-id', semanticId);
78
+ }
79
+ else if (!imageData.isBackground && !element.hasAttribute('data-image-id')) {
80
+ element.setAttribute('data-image-id', semanticId);
81
+ }
82
+ setSelectedImage(imageData);
83
+ setIsOpen(true);
84
+ };
85
+ window.addEventListener('open-image-editor', handleOpenEditor);
86
+ return () => {
87
+ window.removeEventListener('open-image-editor', handleOpenEditor);
88
+ };
89
+ }, [userRole]);
90
+ // Add click handlers to all images
91
+ useEffect(() => {
92
+ if (isLoading || !userRole) {
93
+ return;
94
+ }
95
+ const cleanup = setupImageHandlers((imageData) => {
96
+ setSelectedImage(imageData);
97
+ setIsOpen(true);
98
+ });
99
+ // Setup immediately and also after a short delay to catch dynamically loaded images
100
+ const timeoutId = setTimeout(() => {
101
+ const cleanup2 = setupImageHandlers((imageData) => {
102
+ setSelectedImage(imageData);
103
+ setIsOpen(true);
104
+ });
105
+ // Note: This creates a new cleanup, but the first one will handle the initial setup
106
+ }, 500);
107
+ return () => {
108
+ clearTimeout(timeoutId);
109
+ cleanup();
110
+ };
111
+ }, [isLoading, userRole]);
112
+ // Save image transform (scale/position) to API with debouncing
113
+ const saveImageTransformHandler = useCallback(async (scale, positionX, positionY, immediate = false, brightnessOverride, blurOverride) => {
114
+ var _a, _b;
115
+ if (!selectedImage)
116
+ return;
117
+ const { element } = selectedImage;
118
+ const semanticId = element.getAttribute('data-image-id') ||
119
+ element.getAttribute('data-background-image-id');
120
+ if (!semanticId)
121
+ return;
122
+ const filename = await getFilename(semanticId, selectedImage);
123
+ if (!filename)
124
+ return;
125
+ // Store pending transform
126
+ pendingTransformRef.current = {
127
+ scale,
128
+ positionX,
129
+ positionY,
130
+ semanticId,
131
+ filename
132
+ };
133
+ // Clear existing timeout
134
+ if (saveTransformTimeoutRef.current) {
135
+ clearTimeout(saveTransformTimeoutRef.current);
136
+ saveTransformTimeoutRef.current = null;
137
+ }
138
+ // If immediate save is requested (e.g., when "Done" is clicked), save right away
139
+ if (immediate) {
140
+ const normalizedPositionX = normalizePosition(positionX);
141
+ const normalizedPositionY = normalizePosition(positionY);
142
+ // Use override values if provided, otherwise use selectedImage values
143
+ // IMPORTANT: Overrides contain the latest values from the editor
144
+ const finalBrightness = brightnessOverride !== undefined ? brightnessOverride : ((_a = selectedImage === null || selectedImage === void 0 ? void 0 : selectedImage.brightness) !== null && _a !== void 0 ? _a : 100);
145
+ const finalBlur = blurOverride !== undefined ? blurOverride : ((_b = selectedImage === null || selectedImage === void 0 ? void 0 : selectedImage.blur) !== null && _b !== void 0 ? _b : 0);
146
+ await saveTransformToAPI(semanticId, filename, scale, normalizedPositionX, normalizedPositionY, finalBrightness, finalBlur);
147
+ pendingTransformRef.current = null;
148
+ return;
149
+ }
150
+ // Debounce: save after 300ms of no changes
151
+ saveTransformTimeoutRef.current = setTimeout(async () => {
152
+ const pending = pendingTransformRef.current;
153
+ if (pending && selectedImage) {
154
+ await flushPendingSave(pending, selectedImage);
155
+ }
156
+ }, 300);
157
+ }, [selectedImage]);
158
+ // Cleanup timeout on unmount
159
+ useEffect(() => {
160
+ return () => {
161
+ if (saveTransformTimeoutRef.current) {
162
+ clearTimeout(saveTransformTimeoutRef.current);
163
+ }
164
+ };
165
+ }, []);
166
+ // Event handlers
167
+ const handleImageChangeWrapper = useCallback(async (image) => {
168
+ if (!selectedImage)
169
+ return;
170
+ await handleImageChange(image, selectedImage, handleClose);
171
+ }, [selectedImage]);
172
+ const handleBrightnessChangeWrapper = useCallback(async (brightness) => {
173
+ if (!selectedImage)
174
+ return;
175
+ // Don't save immediately when in editor - will be saved when "Done" is pressed
176
+ await handleBrightnessChange(brightness, selectedImage, setSelectedImage, false);
177
+ }, [selectedImage]);
178
+ const handleBlurChangeWrapper = useCallback(async (blur) => {
179
+ if (!selectedImage)
180
+ return;
181
+ // Don't save immediately when in editor - will be saved when "Done" is pressed
182
+ await handleBlurChange(blur, selectedImage, setSelectedImage, false);
183
+ }, [selectedImage]);
184
+ const handleClose = useCallback(() => {
185
+ setIsOpen(false);
186
+ setSelectedImage(null);
187
+ }, []);
188
+ // Don't render if disabled or user is not admin/dev
189
+ if (!config.enabled || isLoading || !userRole) {
190
+ return null;
191
+ }
192
+ if (!isOpen || !selectedImage) {
193
+ return null;
194
+ }
195
+ return (_jsx("div", { className: `fixed inset-0 z-50 flex items-center justify-center ${config.overlayClassName || 'bg-black/50 backdrop-blur-sm'}`, "data-image-editor": "true", onClick: (e) => {
196
+ if (e.target === e.currentTarget) {
197
+ handleClose();
198
+ }
199
+ }, children: _jsxs("div", { className: `relative bg-white dark:bg-neutral-900 rounded-2xl shadow-2xl max-w-4xl w-full mx-4 max-h-[90vh] flex flex-col ${config.className || ''}`, onClick: (e) => e.stopPropagation(), children: [_jsxs("div", { className: "flex items-center justify-between p-6 border-b dark:border-neutral-800", children: [_jsx("h2", { className: "text-2xl font-bold dark:text-white", children: "Edit Image" }), _jsx("button", { onClick: handleClose, className: "p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition-colors", "aria-label": "Close editor", children: _jsx(X, { className: "w-5 h-5" }) })] }), _jsx("div", { className: "p-6", children: _jsx(ImagePicker, { value: selectedImage.element.getAttribute('data-image-id') || selectedImage.element.getAttribute('data-background-image-id') || selectedImage.originalSrc, onChange: handleImageChangeWrapper, brightness: selectedImage.brightness, blur: selectedImage.blur, scale: selectedImage.scale, positionX: selectedImage.positionX, positionY: selectedImage.positionY, onBrightnessChange: handleBrightnessChangeWrapper, onBlurChange: handleBlurChangeWrapper, onScaleChange: async (newScale) => {
200
+ if (selectedImage) {
201
+ const updated = Object.assign(Object.assign({}, selectedImage), { scale: newScale });
202
+ setSelectedImage(updated);
203
+ await saveImageTransformHandler(newScale, updated.positionX, updated.positionY);
204
+ }
205
+ }, onPositionXChange: async (newPositionX) => {
206
+ if (selectedImage) {
207
+ const updated = Object.assign(Object.assign({}, selectedImage), { positionX: newPositionX });
208
+ setSelectedImage(updated);
209
+ await saveImageTransformHandler(updated.scale, newPositionX, updated.positionY);
210
+ }
211
+ }, onPositionYChange: async (newPositionY) => {
212
+ if (selectedImage) {
213
+ const updated = Object.assign(Object.assign({}, selectedImage), { positionY: newPositionY });
214
+ setSelectedImage(updated);
215
+ await saveImageTransformHandler(updated.scale, updated.positionX, newPositionY);
216
+ }
217
+ }, onEditorSave: async (finalScale, finalPositionX, finalPositionY, finalBrightness, finalBlur) => {
218
+ if (selectedImage) {
219
+ // Update selectedImage with final values
220
+ // Use provided brightness/blur if available, otherwise use current values
221
+ const updated = Object.assign(Object.assign({}, selectedImage), { scale: finalScale, positionX: finalPositionX, positionY: finalPositionY, brightness: finalBrightness !== undefined ? finalBrightness : selectedImage.brightness, blur: finalBlur !== undefined ? finalBlur : selectedImage.blur });
222
+ setSelectedImage(updated);
223
+ // Save with the final brightness and blur values
224
+ await saveImageTransformHandler(finalScale, finalPositionX, finalPositionY, true, updated.brightness, updated.blur);
225
+ }
226
+ }, showEffects: true, darkMode: false, aspectRatio: selectedImage.aspectRatio, borderRadius: selectedImage.borderRadius, objectFit: selectedImage.objectFit, objectPosition: selectedImage.objectPosition }) })] }) }));
227
+ }
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ export interface PluginImageProps {
3
+ id: string;
4
+ alt: string;
5
+ width?: number;
6
+ height?: number;
7
+ className?: string;
8
+ fill?: boolean;
9
+ sizes?: string;
10
+ priority?: boolean;
11
+ objectFit?: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
12
+ objectPosition?: string;
13
+ style?: React.CSSProperties;
14
+ editable?: boolean;
15
+ scale?: number;
16
+ positionX?: number;
17
+ positionY?: number;
18
+ brightness?: number;
19
+ blur?: number;
20
+ }
21
+ export declare function Image({ id, alt, width, height, className, fill, sizes, priority, objectFit, objectPosition, style, editable, ...props }: PluginImageProps): import("react/jsx-runtime").JSX.Element;
22
+ //# sourceMappingURL=Image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["Image.tsx"],"names":[],"mappings":"AAGA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAKjF,MAAM,WAAW,gBAAgB;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC;IACjE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,KAAK,CAAC,EAClB,EAAE,EACF,GAAG,EACH,KAAK,EACL,MAAM,EACN,SAAc,EACd,IAAY,EACZ,KAAK,EACL,QAAgB,EAChB,SAAmB,EACnB,cAAyB,EACzB,KAAK,EACL,QAAe,EACf,GAAG,KAAK,EACX,EAAE,gBAAgB,2CA2SlB"}