@jhits/plugin-images 0.0.6 → 0.0.8

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 (169) 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 +2 -2
  104. package/src/components/BackgroundImage.d.ts +11 -0
  105. package/src/components/BackgroundImage.d.ts.map +1 -0
  106. package/src/components/BackgroundImage.js +35 -0
  107. package/src/components/GlobalImageEditor/config.d.ts +9 -0
  108. package/src/components/GlobalImageEditor/config.d.ts.map +1 -0
  109. package/src/components/GlobalImageEditor/config.js +18 -0
  110. package/src/components/GlobalImageEditor/eventHandlers.d.ts +20 -0
  111. package/src/components/GlobalImageEditor/eventHandlers.d.ts.map +1 -0
  112. package/src/components/GlobalImageEditor/eventHandlers.js +206 -0
  113. package/src/components/GlobalImageEditor/imageDetection.d.ts +16 -0
  114. package/src/components/GlobalImageEditor/imageDetection.d.ts.map +1 -0
  115. package/src/components/GlobalImageEditor/imageDetection.js +130 -0
  116. package/src/components/GlobalImageEditor/imageSetup.d.ts +9 -0
  117. package/src/components/GlobalImageEditor/imageSetup.d.ts.map +1 -0
  118. package/src/components/GlobalImageEditor/imageSetup.js +261 -0
  119. package/src/components/GlobalImageEditor/saveLogic.d.ts +26 -0
  120. package/src/components/GlobalImageEditor/saveLogic.d.ts.map +1 -0
  121. package/src/components/GlobalImageEditor/saveLogic.js +99 -0
  122. package/src/components/GlobalImageEditor/stylingDetection.d.ts +9 -0
  123. package/src/components/GlobalImageEditor/stylingDetection.d.ts.map +1 -0
  124. package/src/components/GlobalImageEditor/stylingDetection.js +110 -0
  125. package/src/components/GlobalImageEditor/transformParsing.d.ts +16 -0
  126. package/src/components/GlobalImageEditor/transformParsing.d.ts.map +1 -0
  127. package/src/components/GlobalImageEditor/transformParsing.js +68 -0
  128. package/src/components/GlobalImageEditor/types.d.ts +36 -0
  129. package/src/components/GlobalImageEditor/types.d.ts.map +1 -0
  130. package/src/components/GlobalImageEditor/types.js +4 -0
  131. package/src/components/GlobalImageEditor.d.ts +8 -0
  132. package/src/components/GlobalImageEditor.d.ts.map +1 -0
  133. package/src/components/GlobalImageEditor.js +227 -0
  134. package/src/components/Image.d.ts +22 -0
  135. package/src/components/Image.d.ts.map +1 -0
  136. package/src/components/Image.js +229 -0
  137. package/src/components/ImageBrowserModal.d.ts +13 -0
  138. package/src/components/ImageBrowserModal.d.ts.map +1 -0
  139. package/src/components/ImageBrowserModal.js +504 -0
  140. package/src/components/ImageEditor.d.ts +27 -0
  141. package/src/components/ImageEditor.d.ts.map +1 -0
  142. package/src/components/ImageEditor.js +173 -0
  143. package/src/components/ImagePicker.d.ts +3 -0
  144. package/src/components/ImagePicker.d.ts.map +1 -0
  145. package/src/components/ImagePicker.js +143 -0
  146. package/src/components/ImagesPluginInit.d.ts +24 -0
  147. package/src/components/ImagesPluginInit.d.ts.map +1 -0
  148. package/src/components/ImagesPluginInit.js +28 -0
  149. package/src/hooks/useImagePicker.d.ts +20 -0
  150. package/src/hooks/useImagePicker.d.ts.map +1 -0
  151. package/src/hooks/useImagePicker.js +322 -0
  152. package/src/index.d.ts +23 -0
  153. package/src/index.d.ts.map +1 -0
  154. package/src/index.js +28 -0
  155. package/src/init.d.ts +33 -0
  156. package/src/init.d.ts.map +1 -0
  157. package/src/init.js +43 -0
  158. package/src/types/index.d.ts +80 -0
  159. package/src/types/index.d.ts.map +1 -0
  160. package/src/types/index.js +4 -0
  161. package/src/utils/fallback.d.ts +27 -0
  162. package/src/utils/fallback.d.ts.map +1 -0
  163. package/src/utils/fallback.js +63 -0
  164. package/src/utils/transforms.d.ts +26 -0
  165. package/src/utils/transforms.d.ts.map +1 -0
  166. package/src/utils/transforms.js +38 -0
  167. package/src/views/ImageManager.d.ts +10 -0
  168. package/src/views/ImageManager.d.ts.map +1 -0
  169. package/src/views/ImageManager.js +9 -0
package/dist/init.js ADDED
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Images Plugin Initialization Utility
3
+ *
4
+ * Simple function to initialize the images plugin with client configuration.
5
+ * Call this once in your app (e.g., in root layout) to enable global image editing.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { initImagesPlugin } from '@jhits/plugin-images/init';
10
+ * import { imagesConfig } from '@/plugins/images-config';
11
+ *
12
+ * // Call once when your app loads
13
+ * initImagesPlugin(imagesConfig);
14
+ * ```
15
+ */
16
+ 'use client';
17
+ /**
18
+ * Initialize the images plugin with client configuration
19
+ *
20
+ * This function sets up the window global that the plugin reads from automatically.
21
+ * Call this once when your app loads, before the plugin component is rendered.
22
+ *
23
+ * @param config - Images plugin configuration (enabled, styling, etc.)
24
+ */
25
+ export function initImagesPlugin(config) {
26
+ if (typeof window === 'undefined') {
27
+ // Server-side: no-op
28
+ return;
29
+ }
30
+ // Initialize the global plugin props object if it doesn't exist
31
+ if (!window.__JHITS_PLUGIN_PROPS__) {
32
+ window.__JHITS_PLUGIN_PROPS__ = {};
33
+ }
34
+ // Set images plugin configuration
35
+ window.__JHITS_PLUGIN_PROPS__['plugin-images'] = {
36
+ enabled: config?.enabled !== undefined ? config.enabled : true,
37
+ className: config?.className,
38
+ overlayClassName: config?.overlayClassName,
39
+ };
40
+ console.log('[ImagesPlugin] Initialized with config:', {
41
+ enabled: config?.enabled !== undefined ? config.enabled : true,
42
+ });
43
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Image Plugin Types
3
+ */
4
+ export interface ImageMetadata {
5
+ /** Unique image ID */
6
+ id: string;
7
+ /** Original filename */
8
+ filename: string;
9
+ /** File path/URL */
10
+ url: string;
11
+ /** File size in bytes */
12
+ size: number;
13
+ /** MIME type */
14
+ mimeType: string;
15
+ /** Image dimensions */
16
+ width?: number;
17
+ height?: number;
18
+ /** Alt text */
19
+ alt?: string;
20
+ /** Upload timestamp */
21
+ uploadedAt: string;
22
+ /** Uploaded by user ID */
23
+ uploadedBy?: string;
24
+ /** Tags for searching */
25
+ tags?: string[];
26
+ }
27
+ export interface ImageUploadResponse {
28
+ success: boolean;
29
+ image?: ImageMetadata;
30
+ error?: string;
31
+ }
32
+ export interface ImageListResponse {
33
+ images: ImageMetadata[];
34
+ total: number;
35
+ page: number;
36
+ limit: number;
37
+ }
38
+ export interface ImagePickerProps {
39
+ /** Current selected image URL */
40
+ value?: string;
41
+ /** Callback when image is selected */
42
+ onChange: (image: ImageMetadata | null) => void;
43
+ /** Whether dark mode is enabled */
44
+ darkMode?: boolean;
45
+ /** Show brightness and blur controls */
46
+ showEffects?: boolean;
47
+ /** Current brightness value (0-200, 100 = normal) */
48
+ brightness?: number;
49
+ /** Current blur value (0-20) */
50
+ blur?: number;
51
+ /** Current scale value (0.1-3.0, 1.0 = normal) */
52
+ scale?: number;
53
+ /** Current X position offset (-100 to 100, 0 = center) */
54
+ positionX?: number;
55
+ /** Current Y position offset (-100 to 100, 0 = center) */
56
+ positionY?: number;
57
+ /** Aspect ratio for preview/editor (e.g., "4/5", "3/4", "16/9", "1/1") */
58
+ aspectRatio?: string;
59
+ /** Border radius class (e.g., "rounded-xl", "rounded-3xl") */
60
+ borderRadius?: string;
61
+ /** Object fit style (e.g., "cover", "contain") */
62
+ objectFit?: 'cover' | 'contain' | 'fill' | 'none' | 'scale-down';
63
+ /** Object position (e.g., "center", "top", "bottom") */
64
+ objectPosition?: string;
65
+ /** Callback when brightness changes */
66
+ onBrightnessChange?: (brightness: number) => void;
67
+ /** Callback when blur changes */
68
+ onBlurChange?: (blur: number) => void;
69
+ /** Callback when scale changes */
70
+ onScaleChange?: (scale: number) => void;
71
+ /** Callback when X position changes */
72
+ onPositionXChange?: (positionX: number) => void;
73
+ /** Callback when Y position changes */
74
+ onPositionYChange?: (positionY: number) => void;
75
+ /** Callback when editor "Done" button is clicked - triggers immediate save */
76
+ onEditorSave?: (scale: number, positionX: number, positionY: number, brightness?: number, blur?: number) => void;
77
+ /** Automatically open the editor when component mounts (useful for modal scenarios) */
78
+ autoOpenEditor?: boolean;
79
+ }
80
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,aAAa;IAC1B,sBAAsB;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,wBAAwB;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,uBAAuB;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,0BAA0B;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yBAAyB;IACzB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAC9B,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC7B,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,KAAK,IAAI,CAAC;IAChD,mCAAmC;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,wCAAwC;IACxC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,qDAAqD;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gCAAgC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0EAA0E;IAC1E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC;IACjE,wDAAwD;IACxD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,uCAAuC;IACvC,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD,iCAAiC;IACjC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,kCAAkC;IAClC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,uCAAuC;IACvC,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,uCAAuC;IACvC,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,8EAA8E;IAC9E,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACjH,uFAAuF;IACvF,cAAc,CAAC,EAAE,OAAO,CAAC;CAC5B"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Image Plugin Types
3
+ */
4
+ export {};
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Fallback image utility
3
+ * Provides a default fallback image URL when images fail to load or are invalid
4
+ * Also handles URL construction for image filenames
5
+ */
6
+ /**
7
+ * Returns the URL for the fallback "image not found" image
8
+ * Served from the plugin's API route
9
+ */
10
+ export declare function getFallbackImageUrl(): string;
11
+ /**
12
+ * Constructs the full image URL from a filename or URL
13
+ * - If it's already a full URL (http://, https://, or starts with /), returns as-is
14
+ * - If it's a filename, constructs `/api/uploads/${filename}`
15
+ */
16
+ export declare function constructImageUrl(src: string | null | undefined): string | null;
17
+ /**
18
+ * Validates if a URL is valid and can be used with Next.js Image component
19
+ */
20
+ export declare function isValidImageUrl(url: string | null | undefined): boolean;
21
+ /**
22
+ * Gets a safe image URL with automatic URL construction and fallback
23
+ * - Constructs the full URL if src is a filename
24
+ * - Falls back to the plugin's fallback image if invalid or missing
25
+ */
26
+ export declare function getSafeImageUrl(src: string | null | undefined): string;
27
+ //# sourceMappingURL=fallback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fallback.d.ts","sourceRoot":"","sources":["../../src/utils/fallback.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAY/E;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAkBvE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAUtE"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Fallback image utility
3
+ * Provides a default fallback image URL when images fail to load or are invalid
4
+ * Also handles URL construction for image filenames
5
+ */
6
+ /**
7
+ * Returns the URL for the fallback "image not found" image
8
+ * Served from the plugin's API route
9
+ */
10
+ export function getFallbackImageUrl() {
11
+ return '/api/plugin-images/fallback';
12
+ }
13
+ /**
14
+ * Constructs the full image URL from a filename or URL
15
+ * - If it's already a full URL (http://, https://, or starts with /), returns as-is
16
+ * - If it's a filename, constructs `/api/uploads/${filename}`
17
+ */
18
+ export function constructImageUrl(src) {
19
+ if (!src || typeof src !== 'string') {
20
+ return null;
21
+ }
22
+ // If it's already a full URL (absolute or relative), return as-is
23
+ if (src.startsWith('http://') || src.startsWith('https://') || src.startsWith('/')) {
24
+ return src;
25
+ }
26
+ // Otherwise, it's a filename - construct the API URL
27
+ return `/api/uploads/${src}`;
28
+ }
29
+ /**
30
+ * Validates if a URL is valid and can be used with Next.js Image component
31
+ */
32
+ export function isValidImageUrl(url) {
33
+ if (!url || typeof url !== 'string') {
34
+ return false;
35
+ }
36
+ // Check if it's a valid URL format
37
+ try {
38
+ // For relative URLs (starting with /), they're valid
39
+ if (url.startsWith('/')) {
40
+ return true;
41
+ }
42
+ // For absolute URLs, validate the URL format
43
+ new URL(url);
44
+ return true;
45
+ }
46
+ catch {
47
+ return false;
48
+ }
49
+ }
50
+ /**
51
+ * Gets a safe image URL with automatic URL construction and fallback
52
+ * - Constructs the full URL if src is a filename
53
+ * - Falls back to the plugin's fallback image if invalid or missing
54
+ */
55
+ export function getSafeImageUrl(src) {
56
+ // First, construct the URL if it's a filename
57
+ const constructedUrl = constructImageUrl(src);
58
+ // Then validate and return, or fallback
59
+ if (isValidImageUrl(constructedUrl)) {
60
+ return constructedUrl;
61
+ }
62
+ return getFallbackImageUrl();
63
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Image Transform Utilities
3
+ */
4
+ export interface ImageTransformOptions {
5
+ scale: number;
6
+ positionX: number;
7
+ positionY: number;
8
+ baseScale?: number;
9
+ }
10
+ /**
11
+ * Calculates the CSS transform string
12
+ * Order: Center -> Scale -> Translate (Offset)
13
+ *
14
+ * Position values are stored as percentages of the CONTAINER, not the image.
15
+ * This makes them consistent across different container sizes.
16
+ *
17
+ * IMPORTANT: The image uses width: auto; height: auto with minWidth: 100%; minHeight: 100%
18
+ * This allows the image to maintain its natural aspect ratio while ensuring it covers the container.
19
+ * baseScale handles the "fitting" to ensure the image is large enough to fill the container.
20
+ *
21
+ * Applying SCALE before POSITION makes the position relative to the visual size you see,
22
+ * not the original raw file size. This ensures consistent positioning across different scales.
23
+ */
24
+ export declare function getImageTransform(options: ImageTransformOptions, needsCentering?: boolean, caller?: string): string;
25
+ export declare function getImageFilter(brightness?: number, blur?: number): string | undefined;
26
+ //# sourceMappingURL=transforms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transforms.d.ts","sourceRoot":"","sources":["../../src/utils/transforms.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,qBAAqB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAC7B,OAAO,EAAE,qBAAqB,EAC9B,cAAc,GAAE,OAAe,EAC/B,MAAM,CAAC,EAAE,MAAM,GAChB,MAAM,CAmBR;AAED,wBAAgB,cAAc,CAAC,UAAU,GAAE,MAAY,EAAE,IAAI,GAAE,MAAU,GAAG,MAAM,GAAG,SAAS,CAG7F"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Image Transform Utilities
3
+ */
4
+ /**
5
+ * Calculates the CSS transform string
6
+ * Order: Center -> Scale -> Translate (Offset)
7
+ *
8
+ * Position values are stored as percentages of the CONTAINER, not the image.
9
+ * This makes them consistent across different container sizes.
10
+ *
11
+ * IMPORTANT: The image uses width: auto; height: auto with minWidth: 100%; minHeight: 100%
12
+ * This allows the image to maintain its natural aspect ratio while ensuring it covers the container.
13
+ * baseScale handles the "fitting" to ensure the image is large enough to fill the container.
14
+ *
15
+ * Applying SCALE before POSITION makes the position relative to the visual size you see,
16
+ * not the original raw file size. This ensures consistent positioning across different scales.
17
+ */
18
+ export function getImageTransform(options, needsCentering = false, caller) {
19
+ const { scale, positionX, positionY, baseScale = 1 } = options;
20
+ const totalScale = baseScale * scale;
21
+ // 1. Center the image (if using top:50% left:50%)
22
+ const center = needsCentering ? 'translate(-50%, -50%)' : '';
23
+ // 2. Apply the scaling (base x zoom) FIRST
24
+ // This ensures the position offset is relative to the scaled visual size
25
+ const zoom = `scale(${totalScale})`;
26
+ // 3. Apply the offset (positionX/Y) AFTER scaling
27
+ // Position values are stored as percentage of CONTAINER
28
+ // Since scale is applied first, the translate is relative to the scaled visual size
29
+ const offset = `translate(${positionX}%, ${positionY}%)`;
30
+ // Combining them: Center first, then scale, then move
31
+ // Order matters: scale before translate ensures position is relative to visual size
32
+ return `${center} ${zoom} ${offset}`.trim();
33
+ }
34
+ export function getImageFilter(brightness = 100, blur = 0) {
35
+ if (brightness === 100 && blur === 0)
36
+ return undefined;
37
+ return `brightness(${brightness}%) blur(${blur}px)`;
38
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Image Manager View
3
+ * Main view for managing uploaded images
4
+ */
5
+ export interface ImageManagerViewProps {
6
+ siteId: string;
7
+ locale: string;
8
+ }
9
+ export declare function ImageManagerView({ siteId, locale }: ImageManagerViewProps): import("react/jsx-runtime").JSX.Element;
10
+ //# sourceMappingURL=ImageManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImageManager.d.ts","sourceRoot":"","sources":["../../src/views/ImageManager.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,MAAM,WAAW,qBAAqB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,gBAAgB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,qBAAqB,2CAczE"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Image Manager View
3
+ * Main view for managing uploaded images
4
+ */
5
+ 'use client';
6
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
7
+ export function ImageManagerView({ siteId, locale }) {
8
+ return (_jsx("div", { className: "min-h-screen bg-dashboard-bg p-8", children: _jsxs("div", { className: "max-w-7xl mx-auto", children: [_jsx("h1", { className: "text-4xl font-black uppercase tracking-tighter text-dashboard-text mb-8", children: "Image Manager" }), _jsx("p", { className: "text-sm text-neutral-600 dark:text-neutral-400 mb-8", children: "This plugin provides image upload and management functionality. Use the ImagePicker component in other plugins to select images." })] }) }));
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jhits/plugin-images",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "Image management and storage plugin for the JHITS ecosystem",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -20,7 +20,7 @@
20
20
  "dependencies": {
21
21
  "lucide-react": "^0.564.0",
22
22
  "mongodb": "^7.1.0",
23
- "@jhits/plugin-core": "0.0.3"
23
+ "@jhits/plugin-core": "0.0.4"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "next": ">=15.0.0",
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ export interface BackgroundImageProps {
3
+ id: string;
4
+ className?: string;
5
+ style?: React.CSSProperties;
6
+ children?: React.ReactNode;
7
+ backgroundSize?: 'cover' | 'contain' | 'auto' | string;
8
+ backgroundPosition?: string;
9
+ }
10
+ export declare function BackgroundImage({ id, className, style, children, backgroundSize, backgroundPosition, }: BackgroundImageProps): import("react/jsx-runtime").JSX.Element;
11
+ //# sourceMappingURL=BackgroundImage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BackgroundImage.d.ts","sourceRoot":"","sources":["BackgroundImage.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAInD,MAAM,WAAW,oBAAoB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IACvD,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,wBAAgB,eAAe,CAAC,EAC5B,EAAE,EACF,SAAc,EACd,KAAU,EACV,QAAQ,EACR,cAAwB,EACxB,kBAA6B,GAChC,EAAE,oBAAoB,2CAqEtB"}
@@ -0,0 +1,35 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState, useEffect } from 'react';
4
+ import { Image } from './Image';
5
+ import { Edit2 } from 'lucide-react';
6
+ export function BackgroundImage({ id, className = '', style = {}, children, backgroundSize = 'cover', backgroundPosition = 'center', }) {
7
+ var _a;
8
+ const [isAdmin, setIsAdmin] = useState(false);
9
+ const [isLoading, setIsLoading] = useState(true);
10
+ useEffect(() => {
11
+ const checkUser = async () => {
12
+ var _a;
13
+ try {
14
+ const res = await fetch('/api/me');
15
+ const data = await res.json();
16
+ if (data.loggedIn && ['admin', 'dev'].includes((_a = data.user) === null || _a === void 0 ? void 0 : _a.role)) {
17
+ setIsAdmin(true);
18
+ }
19
+ }
20
+ catch (error) {
21
+ console.error('Auth error:', error);
22
+ }
23
+ finally {
24
+ setIsLoading(false);
25
+ }
26
+ };
27
+ checkUser();
28
+ }, []);
29
+ const handleEditClick = (e) => {
30
+ e.preventDefault();
31
+ e.stopPropagation();
32
+ window.dispatchEvent(new CustomEvent('open-image-editor', { detail: { id } }));
33
+ };
34
+ return (_jsxs("div", { className: `group relative overflow-hidden ${className}`, style: Object.assign(Object.assign({}, style), { minHeight: (_a = style.minHeight) !== null && _a !== void 0 ? _a : '300px' }), "data-background-id": id, children: [_jsx("div", { className: "absolute inset-0 z-0", children: _jsx(Image, { id: id, alt: "", fill: true, priority: true, className: "w-full h-full", objectFit: backgroundSize, objectPosition: backgroundPosition, editable: false }) }), _jsx("div", { className: "relative z-10 w-full h-full", children: children }), !isLoading && isAdmin && (_jsxs("button", { onClick: handleEditClick, className: "absolute bottom-8 left-8 z-50 flex items-center gap-3 px-6 py-3 bg-white dark:bg-neutral-800 text-neutral-900 dark:text-neutral-100 rounded-full shadow-2xl border border-neutral-200 dark:border-neutral-700 opacity-0 translate-y-4 group-hover:opacity-100 group-hover:translate-y-0 transition-all duration-500 ease-out", children: [_jsx(Edit2, { size: 16, className: "text-primary" }), _jsx("span", { className: "text-[11px] font-black uppercase tracking-widest", children: "Edit Background" })] }))] }));
35
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Configuration utilities for GlobalImageEditor
3
+ */
4
+ import type { PluginConfig } from './types';
5
+ /**
6
+ * Read plugin configuration from window global
7
+ */
8
+ export declare function getPluginConfig(): PluginConfig;
9
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;GAEG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAW9C"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Configuration utilities for GlobalImageEditor
3
+ */
4
+ /**
5
+ * Read plugin configuration from window global
6
+ */
7
+ export function getPluginConfig() {
8
+ var _a;
9
+ if (typeof window === 'undefined') {
10
+ return { enabled: false };
11
+ }
12
+ const pluginProps = (_a = window.__JHITS_PLUGIN_PROPS__) === null || _a === void 0 ? void 0 : _a['plugin-images'];
13
+ return {
14
+ enabled: (pluginProps === null || pluginProps === void 0 ? void 0 : pluginProps.enabled) !== undefined ? pluginProps.enabled : true,
15
+ className: pluginProps === null || pluginProps === void 0 ? void 0 : pluginProps.className,
16
+ overlayClassName: pluginProps === null || pluginProps === void 0 ? void 0 : pluginProps.overlayClassName,
17
+ };
18
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Event handlers for image changes and effects
3
+ */
4
+ import type { SelectedImage } from './types';
5
+ import type { ImageMetadata } from '../../types';
6
+ /**
7
+ * Apply image changes to DOM and save to API
8
+ */
9
+ export declare function handleImageChange(image: ImageMetadata | null, selectedImage: SelectedImage, onClose: () => void): Promise<void>;
10
+ /**
11
+ * Handle brightness change
12
+ * @param saveImmediately - If true, save to API immediately. If false, only update state/DOM (for editor preview)
13
+ */
14
+ export declare function handleBrightnessChange(brightness: number, selectedImage: SelectedImage, setSelectedImage: (image: SelectedImage) => void, saveImmediately?: boolean): Promise<void>;
15
+ /**
16
+ * Handle blur change
17
+ * @param saveImmediately - If true, save to API immediately. If false, only update state/DOM (for editor preview)
18
+ */
19
+ export declare function handleBlurChange(blur: number, selectedImage: SelectedImage, setSelectedImage: (image: SelectedImage) => void, saveImmediately?: boolean): Promise<void>;
20
+ //# sourceMappingURL=eventHandlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventHandlers.d.ts","sourceRoot":"","sources":["eventHandlers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD;;GAEG;AACH,wBAAsB,iBAAiB,CACnC,KAAK,EAAE,aAAa,GAAG,IAAI,EAC3B,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE,MAAM,IAAI,GACpB,OAAO,CAAC,IAAI,CAAC,CAiDf;AAoID;;;GAGG;AACH,wBAAsB,sBAAsB,CACxC,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,EAChD,eAAe,GAAE,OAAc,GAChC,OAAO,CAAC,IAAI,CAAC,CAyBf;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAClC,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,EAChD,eAAe,GAAE,OAAc,GAChC,OAAO,CAAC,IAAI,CAAC,CAyBf"}