zuljaman-banner-components 1.0.6 → 1.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 (98) hide show
  1. package/dist/components/BannerRenderer.d.ts +48 -0
  2. package/dist/components/BannerRenderer.d.ts.map +1 -0
  3. package/dist/components/BannerRenderer.js +449 -0
  4. package/dist/components/BannerVisor.d.ts.map +1 -1
  5. package/dist/components/BannerVisor.js +132 -18
  6. package/dist/components/index.d.ts +1 -2
  7. package/dist/components/index.d.ts.map +1 -1
  8. package/dist/components/index.js +4 -2
  9. package/dist/components/shared/DraggableElement.d.ts +31 -0
  10. package/dist/components/shared/DraggableElement.d.ts.map +1 -0
  11. package/dist/components/shared/DraggableElement.js +398 -0
  12. package/dist/components/shared/index.d.ts +7 -0
  13. package/dist/components/shared/index.d.ts.map +1 -0
  14. package/dist/components/shared/index.js +9 -0
  15. package/dist/components/styles/Style1/substyleConfig.d.ts +20 -0
  16. package/dist/components/styles/Style1/substyleConfig.d.ts.map +1 -0
  17. package/dist/components/styles/Style1/substyleConfig.js +105 -0
  18. package/dist/components/styles/Style2/substyleConfig.d.ts +20 -0
  19. package/dist/components/styles/Style2/substyleConfig.d.ts.map +1 -0
  20. package/dist/components/styles/Style2/substyleConfig.js +133 -0
  21. package/dist/components/styles/Style3/substyleConfig.d.ts +20 -0
  22. package/dist/components/styles/Style3/substyleConfig.d.ts.map +1 -0
  23. package/dist/components/styles/Style3/substyleConfig.js +91 -0
  24. package/dist/components/styles/Style4/substyleConfig.d.ts +20 -0
  25. package/dist/components/styles/Style4/substyleConfig.d.ts.map +1 -0
  26. package/dist/components/styles/Style4/substyleConfig.js +112 -0
  27. package/dist/components/styles/types/substyleTypes.d.ts +68 -0
  28. package/dist/components/styles/types/substyleTypes.d.ts.map +1 -0
  29. package/dist/components/styles/types/substyleTypes.js +6 -0
  30. package/dist/components/styles/utils/calculations.d.ts +47 -0
  31. package/dist/components/styles/utils/calculations.d.ts.map +1 -0
  32. package/dist/components/styles/utils/calculations.js +69 -0
  33. package/dist/components/styles/utils/defaultsUtils.d.ts +54 -0
  34. package/dist/components/styles/utils/defaultsUtils.d.ts.map +1 -0
  35. package/dist/components/styles/utils/defaultsUtils.js +83 -0
  36. package/dist/components/styles/utils/fontSizeUtils.d.ts +32 -0
  37. package/dist/components/styles/utils/fontSizeUtils.d.ts.map +1 -0
  38. package/dist/components/styles/utils/fontSizeUtils.js +52 -0
  39. package/dist/components/styles/utils/positioningUtils.d.ts +38 -0
  40. package/dist/components/styles/utils/positioningUtils.d.ts.map +1 -0
  41. package/dist/components/styles/utils/positioningUtils.js +79 -0
  42. package/dist/components/styles/utils/substyleUtils.d.ts +14 -0
  43. package/dist/components/styles/utils/substyleUtils.d.ts.map +1 -0
  44. package/dist/components/styles/utils/substyleUtils.js +18 -0
  45. package/dist/components/styles/utils/transformUtils.d.ts +36 -0
  46. package/dist/components/styles/utils/transformUtils.d.ts.map +1 -0
  47. package/dist/components/styles/utils/transformUtils.js +53 -0
  48. package/dist/constants/characterLimits.d.ts +97 -0
  49. package/dist/constants/characterLimits.d.ts.map +1 -0
  50. package/dist/constants/characterLimits.js +144 -0
  51. package/dist/constants/defaults.d.ts +19 -0
  52. package/dist/constants/defaults.d.ts.map +1 -0
  53. package/dist/constants/defaults.js +27 -0
  54. package/dist/constants/index.d.ts +2 -0
  55. package/dist/constants/index.d.ts.map +1 -1
  56. package/dist/constants/index.js +2 -0
  57. package/dist/constants/styleConfigs.d.ts.map +1 -1
  58. package/dist/constants/styleConfigs.js +13 -7
  59. package/dist/index.d.ts +8 -0
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +12 -0
  62. package/dist/styleConfig.d.ts +40 -0
  63. package/dist/styleConfig.d.ts.map +1 -0
  64. package/dist/styleConfig.js +115 -0
  65. package/dist/styles/shadowUtils.js +4 -4
  66. package/dist/types.d.ts +149 -1
  67. package/dist/types.d.ts.map +1 -1
  68. package/package.json +10 -10
  69. package/dist/components/Style1/BannerStyle1.d.ts +0 -19
  70. package/dist/components/Style1/BannerStyle1.d.ts.map +0 -1
  71. package/dist/components/Style1/BannerStyle1.js +0 -27
  72. package/dist/components/Style1/substyles/BannerSubstyle1.d.ts +0 -12
  73. package/dist/components/Style1/substyles/BannerSubstyle1.d.ts.map +0 -1
  74. package/dist/components/Style1/substyles/BannerSubstyle1.js +0 -52
  75. package/dist/components/Style1/substyles/BannerSubstyle2.d.ts +0 -12
  76. package/dist/components/Style1/substyles/BannerSubstyle2.d.ts.map +0 -1
  77. package/dist/components/Style1/substyles/BannerSubstyle2.js +0 -52
  78. package/dist/components/Style1/substyles/BannerSubstyle3.d.ts +0 -12
  79. package/dist/components/Style1/substyles/BannerSubstyle3.d.ts.map +0 -1
  80. package/dist/components/Style1/substyles/BannerSubstyle3.js +0 -61
  81. package/dist/components/Style1/substyles/index.d.ts +0 -7
  82. package/dist/components/Style1/substyles/index.d.ts.map +0 -1
  83. package/dist/components/Style1/substyles/index.js +0 -22
  84. package/dist/components/Style2/BannerStyle2.d.ts +0 -19
  85. package/dist/components/Style2/BannerStyle2.d.ts.map +0 -1
  86. package/dist/components/Style2/BannerStyle2.js +0 -32
  87. package/dist/components/Style2/substyles/BannerSubstyle1.d.ts +0 -12
  88. package/dist/components/Style2/substyles/BannerSubstyle1.d.ts.map +0 -1
  89. package/dist/components/Style2/substyles/BannerSubstyle1.js +0 -35
  90. package/dist/components/Style2/substyles/BannerSubstyle2.d.ts +0 -12
  91. package/dist/components/Style2/substyles/BannerSubstyle2.d.ts.map +0 -1
  92. package/dist/components/Style2/substyles/BannerSubstyle2.js +0 -35
  93. package/dist/components/Style2/substyles/BannerSubstyle3.d.ts +0 -12
  94. package/dist/components/Style2/substyles/BannerSubstyle3.d.ts.map +0 -1
  95. package/dist/components/Style2/substyles/BannerSubstyle3.js +0 -35
  96. package/dist/components/Style2/substyles/index.d.ts +0 -7
  97. package/dist/components/Style2/substyles/index.d.ts.map +0 -1
  98. package/dist/components/Style2/substyles/index.js +0 -22
@@ -13,43 +13,157 @@ const jsx_runtime_1 = require("react/jsx-runtime");
13
13
  const react_1 = require("react");
14
14
  const clsx_1 = __importDefault(require("clsx"));
15
15
  const constants_1 = require("../constants");
16
- // Import style components (will be created next)
17
- const BannerStyle1_1 = require("./Style1/BannerStyle1");
18
- const BannerStyle2_1 = require("./Style2/BannerStyle2");
16
+ const styleConfig_1 = require("../styleConfig");
17
+ // Import generic renderer
18
+ const BannerRenderer_1 = require("./BannerRenderer");
19
19
  const NoImageComponent = () => {
20
20
  return ((0, jsx_runtime_1.jsx)("div", { className: "w-full grow flex items-center justify-center text-neutral-500", children: (0, jsx_runtime_1.jsx)("p", { children: "No image selected" }) }));
21
21
  };
22
- const BannerVisor = ({ bannerStyle = 1, // Default to style 1 if undefined
23
- backgroundImageUrl, copy1, copy2, bannerSubstyle, logoUrl, postType, sizeMultiplier: externalSizeMultiplier, ImageComponent, }) => {
22
+ const BannerVisor = ({ backgroundImageUrl, copies, copy1, copy2, bannerStyle = 1, bannerSubstyle, bannerSubSubstyle: _bannerSubSubstyle, logoUrl, postType, sizeMultiplier: externalSizeMultiplier, fontSizeMultiplier = 1.0, copy1FontSizeMultiplier, copy2FontSizeMultiplier, logoSizeMultiplier = 1.0, overlayIntensityMultiplier = 1.0, shadowIntensityMultiplier = 1.0, ImageComponent, logoTranslateX = 0, logoTranslateY = 0, copy1TranslateX = 0, copy1TranslateY = 0, copy2TranslateX = 0, copy2TranslateY = 0, draggableMode = false, onLogoPositionChange, onCopyPositionChange, onCopy1PositionChange, onCopy2PositionChange, onLogoRotationChange, onCopyRotationChange, onCopy1RotationChange, onCopy2RotationChange, logoRotation = 0, copy1Rotation = 0, copy2Rotation = 0, logoWidth, copy1Width, copy2Width, onLogoWidthChange, onCopyWidthChange, onCopy1WidthChange, onCopy2WidthChange, copy1Align = 'left', copy2Align = 'center', copy1FontWeight = 'normal', copy2FontWeight = 'normal', textShadowEnabled, textShadowSize, textShadowIntensity, logoShadowEnabled, logoShadowSize, logoShadowIntensity, noiseEnabled, noiseIntensity, fontFamily, }) => {
23
+ var _a;
24
24
  const [internalSizeMultiplier, setInternalSizeMultiplier] = (0, react_1.useState)(1);
25
25
  const containerRef = (0, react_1.useRef)(null);
26
+ // Get style configuration for centralized settings
27
+ const styleConfig = (0, styleConfig_1.getStyleConfig)(bannerStyle);
26
28
  // Use external size multiplier if provided, otherwise use internal
27
29
  const sizeMultiplier = externalSizeMultiplier !== null && externalSizeMultiplier !== void 0 ? externalSizeMultiplier : internalSizeMultiplier;
28
- const bannerContentProps = {
30
+ // Use individual font size multipliers if provided, otherwise fall back to fontSizeMultiplier
31
+ const effectiveCopy1FontSize = copy1FontSizeMultiplier !== null && copy1FontSizeMultiplier !== void 0 ? copy1FontSizeMultiplier : fontSizeMultiplier;
32
+ const effectiveCopy2FontSize = copy2FontSizeMultiplier !== null && copy2FontSizeMultiplier !== void 0 ? copy2FontSizeMultiplier : fontSizeMultiplier;
33
+ // Use noiseEnabled from styleConfig if not provided as prop (centralized configuration)
34
+ const effectiveNoiseEnabled = (_a = noiseEnabled !== null && noiseEnabled !== void 0 ? noiseEnabled : styleConfig.noiseEnabled) !== null && _a !== void 0 ? _a : true;
35
+ // Convert legacy props to copies array for backward compatibility
36
+ const effectiveCopies = (0, react_1.useMemo)(() => {
37
+ if (copies && copies.length > 0) {
38
+ // Use new copies array
39
+ return copies;
40
+ }
41
+ // Convert legacy props to copies array
42
+ const legacyCopies = [];
43
+ if (copy1) {
44
+ legacyCopies.push({
45
+ id: `legacy-copy1-${Date.now()}`,
46
+ styleSlot: 0, // Legacy copy1 gets styleSlot 0
47
+ text: copy1,
48
+ fontSize: effectiveCopy1FontSize,
49
+ align: copy1Align,
50
+ fontWeight: copy1FontWeight,
51
+ translateX: copy1TranslateX,
52
+ translateY: copy1TranslateY,
53
+ rotation: copy1Rotation,
54
+ width: copy1Width,
55
+ });
56
+ }
57
+ if (copy2) {
58
+ legacyCopies.push({
59
+ id: `legacy-copy2-${Date.now()}`,
60
+ styleSlot: 1, // Legacy copy2 gets styleSlot 1
61
+ text: copy2,
62
+ fontSize: effectiveCopy2FontSize,
63
+ align: copy2Align,
64
+ fontWeight: copy2FontWeight,
65
+ translateX: copy2TranslateX,
66
+ translateY: copy2TranslateY,
67
+ rotation: copy2Rotation,
68
+ width: copy2Width,
69
+ });
70
+ }
71
+ return legacyCopies;
72
+ }, [
73
+ copies,
29
74
  copy1,
30
75
  copy2,
76
+ effectiveCopy1FontSize,
77
+ effectiveCopy2FontSize,
78
+ copy1Align,
79
+ copy2Align,
80
+ copy1FontWeight,
81
+ copy2FontWeight,
82
+ copy1TranslateX,
83
+ copy1TranslateY,
84
+ copy2TranslateX,
85
+ copy2TranslateY,
86
+ copy1Rotation,
87
+ copy2Rotation,
88
+ copy1Width,
89
+ copy2Width,
90
+ ]);
91
+ // Wrapper functions for legacy callbacks
92
+ const handleCopyPositionChange = (copyIndex, position) => {
93
+ if (onCopyPositionChange) {
94
+ onCopyPositionChange(copyIndex, position);
95
+ }
96
+ // Also call legacy callbacks for backward compatibility
97
+ if (copyIndex === 0 && onCopy1PositionChange) {
98
+ onCopy1PositionChange(position);
99
+ }
100
+ if (copyIndex === 1 && onCopy2PositionChange) {
101
+ onCopy2PositionChange(position);
102
+ }
103
+ };
104
+ const handleCopyRotationChange = (copyIndex, rotation) => {
105
+ if (onCopyRotationChange) {
106
+ onCopyRotationChange(copyIndex, rotation);
107
+ }
108
+ // Also call legacy callbacks for backward compatibility
109
+ if (copyIndex === 0 && onCopy1RotationChange) {
110
+ onCopy1RotationChange(rotation);
111
+ }
112
+ if (copyIndex === 1 && onCopy2RotationChange) {
113
+ onCopy2RotationChange(rotation);
114
+ }
115
+ };
116
+ const handleCopyWidthChange = (copyIndex, width) => {
117
+ if (onCopyWidthChange) {
118
+ onCopyWidthChange(copyIndex, width);
119
+ }
120
+ // Also call legacy callbacks for backward compatibility
121
+ if (copyIndex === 0 && onCopy1WidthChange) {
122
+ onCopy1WidthChange(width);
123
+ }
124
+ if (copyIndex === 1 && onCopy2WidthChange) {
125
+ onCopy2WidthChange(width);
126
+ }
127
+ };
128
+ const bannerContentProps = {
129
+ copies: effectiveCopies,
31
130
  bannerSubstyle,
32
131
  logoUrl,
33
132
  backgroundImageUrl,
34
133
  sizeMultiplier,
134
+ logoSizeMultiplier,
135
+ overlayIntensityMultiplier,
136
+ shadowIntensityMultiplier,
35
137
  postType,
36
138
  ImageComponent,
139
+ logoTranslateX,
140
+ logoTranslateY,
141
+ draggableMode,
142
+ onLogoPositionChange,
143
+ onCopyPositionChange: handleCopyPositionChange,
144
+ onCopyRotationChange: handleCopyRotationChange,
145
+ onCopyWidthChange: handleCopyWidthChange,
146
+ logoRotation,
147
+ logoWidth,
148
+ onLogoRotationChange,
149
+ onLogoWidthChange,
150
+ textShadowEnabled,
151
+ textShadowSize,
152
+ textShadowIntensity,
153
+ logoShadowEnabled,
154
+ logoShadowSize,
155
+ logoShadowIntensity,
156
+ noiseEnabled: effectiveNoiseEnabled,
157
+ noiseIntensity,
158
+ fontFamily,
37
159
  };
38
- const hasBannerContent = copy1 || copy2 || logoUrl;
160
+ const hasBannerContent = effectiveCopies.length > 0 || logoUrl;
39
161
  const renderBannerStyle = () => {
40
162
  if (!hasBannerContent)
41
163
  return null;
42
- // Determine the style ID, defaulting to 1 if null or invalid
43
- const effectiveBannerStyle = bannerStyle === null ? 1 : bannerStyle;
44
- switch (effectiveBannerStyle) {
45
- case 1:
46
- return (0, jsx_runtime_1.jsx)(BannerStyle1_1.BannerStyle1, { ...bannerContentProps });
47
- case 2:
48
- return (0, jsx_runtime_1.jsx)(BannerStyle2_1.BannerStyle2, { ...bannerContentProps });
49
- default:
50
- // Default to BannerStyle1
51
- return (0, jsx_runtime_1.jsx)(BannerStyle1_1.BannerStyle1, { ...bannerContentProps });
52
- }
164
+ // Render the generic BannerRenderer with bannerStyle prop
165
+ // bannerSubstyle determines which substyle (0 for logo only, 1-3 for different layouts)
166
+ return (0, jsx_runtime_1.jsx)(BannerRenderer_1.BannerRenderer, { ...bannerContentProps, bannerStyle: bannerStyle });
53
167
  };
54
168
  (0, react_1.useEffect)(() => {
55
169
  // Only use internal size calculation if no external multiplier is provided
@@ -2,6 +2,5 @@
2
2
  * Banner components exports
3
3
  */
4
4
  export * from './BannerVisor';
5
- export * from './Style1/BannerStyle1';
6
- export * from './Style2/BannerStyle2';
5
+ export * from './BannerRenderer';
7
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC"}
@@ -18,5 +18,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  __exportStar(require("./BannerVisor"), exports);
21
- __exportStar(require("./Style1/BannerStyle1"), exports);
22
- __exportStar(require("./Style2/BannerStyle2"), exports);
21
+ __exportStar(require("./BannerRenderer"), exports);
22
+ // Note: BannerRenderer is a generic component that handles all banner styles
23
+ // Use bannerStyle prop (1, 2, 3, etc.) to select the style
24
+ // Use bannerSubstyle prop (0 for logo only, 1, 2, or 3) to select the substyle
@@ -0,0 +1,31 @@
1
+ /**
2
+ * DraggableElement - Reusable component for draggable/rotatable/resizable elements
3
+ * Used across all banner styles to provide consistent interaction behavior
4
+ */
5
+ import React from "react";
6
+ export interface DraggableElementProps {
7
+ enabled: boolean;
8
+ position: {
9
+ x: number;
10
+ y: number;
11
+ };
12
+ rotation: number;
13
+ width?: number;
14
+ scale: number;
15
+ elementId: string;
16
+ isSelected: boolean;
17
+ onPositionChange?: (pos: {
18
+ x: number;
19
+ y: number;
20
+ }) => void;
21
+ onRotationChange?: (rotation: number) => void;
22
+ onWidthChange?: (width: number) => void;
23
+ onSelect: (id: string) => void;
24
+ onDeselect: () => void;
25
+ onRotationSnap?: (angle: number) => number;
26
+ onDragMove?: (elementId: string, bounds: DOMRect) => void;
27
+ centerOrigin?: boolean;
28
+ children: React.ReactNode;
29
+ }
30
+ export declare const DraggableElement: React.FC<DraggableElementProps>;
31
+ //# sourceMappingURL=DraggableElement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DraggableElement.d.ts","sourceRoot":"","sources":["../../../src/components/shared/DraggableElement.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IAGpB,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC3D,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,UAAU,EAAE,MAAM,IAAI,CAAC;IAGvB,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3C,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IAG1D,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAqhB5D,CAAC"}
@@ -0,0 +1,398 @@
1
+ "use strict";
2
+ /**
3
+ * DraggableElement - Reusable component for draggable/rotatable/resizable elements
4
+ * Used across all banner styles to provide consistent interaction behavior
5
+ */
6
+ "use client";
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.DraggableElement = void 0;
12
+ const jsx_runtime_1 = require("react/jsx-runtime");
13
+ const react_1 = __importDefault(require("react"));
14
+ const DraggableElement = ({ enabled, position, rotation, width, scale, elementId, isSelected, onPositionChange, onRotationChange, onWidthChange, onSelect, onDeselect, onRotationSnap, onDragMove, centerOrigin = false, children, }) => {
15
+ const [isDragging, setIsDragging] = react_1.default.useState(false);
16
+ const [isRotating, setIsRotating] = react_1.default.useState(false);
17
+ const [isResizing, setIsResizing] = react_1.default.useState(false);
18
+ const [resizeSide, setResizeSide] = react_1.default.useState(null);
19
+ const [currentPosition, setCurrentPosition] = react_1.default.useState(position);
20
+ const elementRef = react_1.default.useRef(null);
21
+ const rotatingContentRef = react_1.default.useRef(null);
22
+ const contentOnlyRef = react_1.default.useRef(null);
23
+ const blueHandleRef = react_1.default.useRef(null);
24
+ const purpleIndicatorRef = react_1.default.useRef(null);
25
+ const startAngleRef = react_1.default.useRef(0);
26
+ const currentRotationRef = react_1.default.useRef(rotation);
27
+ const hasDraggedRef = react_1.default.useRef(false);
28
+ const startWidthRef = react_1.default.useRef(0);
29
+ const startMouseXRef = react_1.default.useRef(0);
30
+ const startMouseYRef = react_1.default.useRef(0);
31
+ const startPositionRef = react_1.default.useRef({ x: 0, y: 0 });
32
+ const mouseDownPosRef = react_1.default.useRef(null);
33
+ const justSelectedRef = react_1.default.useRef(false);
34
+ const justStoppedWithoutDragRef = react_1.default.useRef(false);
35
+ const dragStartPosRef = react_1.default.useRef({ x: 0, y: 0 });
36
+ react_1.default.useEffect(() => {
37
+ currentRotationRef.current = rotation;
38
+ }, [rotation]);
39
+ react_1.default.useEffect(() => {
40
+ setCurrentPosition(position);
41
+ }, [position]);
42
+ if (!enabled) {
43
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
44
+ }
45
+ // Rotation handlers
46
+ const handleRotationStart = (e) => {
47
+ e.preventDefault();
48
+ e.stopPropagation();
49
+ if (!contentOnlyRef.current)
50
+ return;
51
+ // Use contentOnlyRef to get the actual content center, not the bounding box with handles
52
+ const rect = contentOnlyRef.current.getBoundingClientRect();
53
+ const centerX = rect.left + rect.width / 2;
54
+ const centerY = rect.top + rect.height / 2;
55
+ const angle = Math.atan2(e.clientY - centerY, e.clientX - centerX) * (180 / Math.PI);
56
+ startAngleRef.current = angle - currentRotationRef.current;
57
+ setIsRotating(true);
58
+ };
59
+ const handleRotationMove = (e) => {
60
+ if (!isRotating || !contentOnlyRef.current)
61
+ return;
62
+ // Use contentOnlyRef for consistent center calculation regardless of rotation
63
+ const rect = contentOnlyRef.current.getBoundingClientRect();
64
+ const centerX = rect.left + rect.width / 2;
65
+ const centerY = rect.top + rect.height / 2;
66
+ const angle = Math.atan2(e.clientY - centerY, e.clientX - centerX) * (180 / Math.PI);
67
+ let newRotation = angle - startAngleRef.current;
68
+ // Apply snap callback if provided
69
+ if (onRotationSnap) {
70
+ newRotation = onRotationSnap(newRotation);
71
+ }
72
+ onRotationChange === null || onRotationChange === void 0 ? void 0 : onRotationChange(Math.round(newRotation));
73
+ };
74
+ const handleRotationEnd = () => {
75
+ setIsRotating(false);
76
+ hasDraggedRef.current = true;
77
+ };
78
+ react_1.default.useEffect(() => {
79
+ if (isRotating) {
80
+ window.addEventListener('mousemove', handleRotationMove);
81
+ window.addEventListener('mouseup', handleRotationEnd);
82
+ return () => {
83
+ window.removeEventListener('mousemove', handleRotationMove);
84
+ window.removeEventListener('mouseup', handleRotationEnd);
85
+ };
86
+ }
87
+ }, [isRotating]);
88
+ // Width resize handlers
89
+ const handleResizeStart = (e, side) => {
90
+ e.preventDefault();
91
+ e.stopPropagation();
92
+ if (!contentOnlyRef.current)
93
+ return;
94
+ const currentWidth = contentOnlyRef.current.offsetWidth;
95
+ startWidthRef.current = currentWidth;
96
+ startMouseXRef.current = e.clientX;
97
+ startMouseYRef.current = e.clientY;
98
+ startPositionRef.current = { x: position.x, y: position.y };
99
+ setResizeSide(side);
100
+ setIsResizing(true);
101
+ };
102
+ const handleResizeMove = (e) => {
103
+ if (!isResizing || !resizeSide)
104
+ return;
105
+ // Calculate mouse delta in viewport coordinates
106
+ const mouseDeltaX = e.clientX - startMouseXRef.current;
107
+ const mouseDeltaY = e.clientY - startMouseYRef.current;
108
+ // Convert rotation to radians
109
+ const rotationRad = (currentRotationRef.current * Math.PI) / 180;
110
+ // Project mouse movement onto the element's rotated X-axis
111
+ // This gives us the actual width change in the element's coordinate system
112
+ const deltaXRotated = mouseDeltaX * Math.cos(rotationRad) + mouseDeltaY * Math.sin(rotationRad);
113
+ let newWidth = startWidthRef.current;
114
+ if (resizeSide === 'right') {
115
+ // Dragging right handle: increase width (left side stays fixed)
116
+ newWidth = startWidthRef.current + deltaXRotated;
117
+ }
118
+ else {
119
+ // Dragging left handle: decrease width (right side should stay fixed)
120
+ newWidth = startWidthRef.current - deltaXRotated;
121
+ }
122
+ // Apply minimum width constraint
123
+ const minWidth = 100;
124
+ newWidth = Math.max(minWidth, newWidth);
125
+ // Adjust position to compensate for rotation effects
126
+ // Both handles experience the same center shift when width changes
127
+ // The rotation happens around the center, so when width changes by ΔW,
128
+ // the center shifts by ΔW/2 in element coordinates
129
+ // We need to move position in the opposite direction to keep visual position stable
130
+ const widthDiff = newWidth - startWidthRef.current;
131
+ const centerShift = widthDiff / 2;
132
+ // Convert center shift to viewport coordinates using rotation
133
+ // In element coords: width change shifts center along X-axis
134
+ // At rotation θ, element's X-axis points at angle θ in viewport
135
+ const offsetXRotated = centerShift * Math.cos(rotationRad);
136
+ const offsetYRotated = centerShift * Math.sin(rotationRad);
137
+ // Subtract offset to compensate (move position opposite to center shift)
138
+ const newX = startPositionRef.current.x - offsetXRotated;
139
+ const newY = startPositionRef.current.y - offsetYRotated;
140
+ onPositionChange === null || onPositionChange === void 0 ? void 0 : onPositionChange({ x: newX, y: newY });
141
+ onWidthChange === null || onWidthChange === void 0 ? void 0 : onWidthChange(Math.round(newWidth));
142
+ };
143
+ const handleResizeEnd = () => {
144
+ setIsResizing(false);
145
+ setResizeSide(null);
146
+ hasDraggedRef.current = true;
147
+ };
148
+ react_1.default.useEffect(() => {
149
+ if (isResizing) {
150
+ window.addEventListener('mousemove', handleResizeMove);
151
+ window.addEventListener('mouseup', handleResizeEnd);
152
+ return () => {
153
+ window.removeEventListener('mousemove', handleResizeMove);
154
+ window.removeEventListener('mouseup', handleResizeEnd);
155
+ };
156
+ }
157
+ }, [isResizing, resizeSide]);
158
+ // Drag handlers
159
+ const handleDragStart = (e) => {
160
+ const target = e.target;
161
+ if (target.closest('.rotation-handle') || target.closest('.width-handle')) {
162
+ return;
163
+ }
164
+ // Auto-select element when starting to drag
165
+ if (!isSelected) {
166
+ onSelect(elementId);
167
+ }
168
+ hasDraggedRef.current = false;
169
+ dragStartPosRef.current = { x: e.clientX, y: e.clientY };
170
+ startPositionRef.current = { x: currentPosition.x, y: currentPosition.y };
171
+ setIsDragging(true);
172
+ };
173
+ const handleDragMove = (e) => {
174
+ if (!isDragging)
175
+ return;
176
+ hasDraggedRef.current = true;
177
+ const deltaX = (e.clientX - dragStartPosRef.current.x) / scale;
178
+ const deltaY = (e.clientY - dragStartPosRef.current.y) / scale;
179
+ const newPosition = {
180
+ x: startPositionRef.current.x + deltaX,
181
+ y: startPositionRef.current.y + deltaY,
182
+ };
183
+ setCurrentPosition(newPosition);
184
+ if (contentOnlyRef.current && onDragMove) {
185
+ const elementBounds = contentOnlyRef.current.getBoundingClientRect();
186
+ onDragMove(elementId, elementBounds);
187
+ }
188
+ };
189
+ const handleDragEnd = () => {
190
+ // If we didn't actually drag, set flag to prevent onClick from toggling
191
+ if (!hasDraggedRef.current) {
192
+ justStoppedWithoutDragRef.current = true;
193
+ }
194
+ setIsDragging(false);
195
+ onPositionChange === null || onPositionChange === void 0 ? void 0 : onPositionChange(currentPosition);
196
+ // Auto-capture width if not explicitly set
197
+ if (width === undefined && contentOnlyRef.current && onWidthChange) {
198
+ const currentWidth = contentOnlyRef.current.offsetWidth;
199
+ if (currentWidth > 0) {
200
+ onWidthChange(Math.round(currentWidth));
201
+ }
202
+ }
203
+ };
204
+ react_1.default.useEffect(() => {
205
+ if (isDragging) {
206
+ window.addEventListener('mousemove', handleDragMove);
207
+ window.addEventListener('mouseup', handleDragEnd);
208
+ return () => {
209
+ window.removeEventListener('mousemove', handleDragMove);
210
+ window.removeEventListener('mouseup', handleDragEnd);
211
+ };
212
+ }
213
+ }, [isDragging, currentPosition, scale]);
214
+ // Selection handlers
215
+ const handleElementClick = (e) => {
216
+ // Don't toggle selection if clicking rotation or width handles
217
+ const target = e.target;
218
+ if (target.closest('.rotation-handle') || target.closest('.width-handle')) {
219
+ return;
220
+ }
221
+ // If we just finished dragging, don't toggle
222
+ if (hasDraggedRef.current) {
223
+ hasDraggedRef.current = false;
224
+ return;
225
+ }
226
+ // If we just stopped without dragging (click), don't toggle
227
+ if (justStoppedWithoutDragRef.current) {
228
+ justStoppedWithoutDragRef.current = false;
229
+ return;
230
+ }
231
+ // If we just selected via mouseUp, don't toggle
232
+ if (justSelectedRef.current) {
233
+ justSelectedRef.current = false;
234
+ return;
235
+ }
236
+ e.stopPropagation();
237
+ // Toggle selection
238
+ if (isSelected) {
239
+ onDeselect();
240
+ }
241
+ else {
242
+ onSelect(elementId);
243
+ }
244
+ };
245
+ // Listen for clicks outside to deselect
246
+ react_1.default.useEffect(() => {
247
+ if (!isSelected)
248
+ return;
249
+ const handleClickOutside = (e) => {
250
+ if (elementRef.current && !elementRef.current.contains(e.target)) {
251
+ onDeselect();
252
+ }
253
+ };
254
+ document.addEventListener('click', handleClickOutside);
255
+ return () => {
256
+ document.removeEventListener('click', handleClickOutside);
257
+ };
258
+ }, [isSelected, onDeselect]);
259
+ return ((0, jsx_runtime_1.jsx)("div", { ref: elementRef, onClick: handleElementClick, onMouseDown: (e) => {
260
+ // Track mouse down position for click detection
261
+ const target = e.target;
262
+ if (target.closest('.rotation-handle') || target.closest('.width-handle')) {
263
+ mouseDownPosRef.current = null;
264
+ return;
265
+ }
266
+ mouseDownPosRef.current = { x: e.clientX, y: e.clientY };
267
+ handleDragStart(e);
268
+ }, onMouseUp: (e) => {
269
+ // Detect click (mouse up at same position as mouse down)
270
+ const target = e.target;
271
+ if (target.closest('.rotation-handle') || target.closest('.width-handle')) {
272
+ return;
273
+ }
274
+ if (mouseDownPosRef.current) {
275
+ const deltaX = Math.abs(e.clientX - mouseDownPosRef.current.x);
276
+ const deltaY = Math.abs(e.clientY - mouseDownPosRef.current.y);
277
+ // If mouse hasn't moved much (less than 5px), treat as click
278
+ if (deltaX < 5 && deltaY < 5) {
279
+ e.preventDefault();
280
+ e.stopPropagation();
281
+ if (!isSelected) {
282
+ onSelect(elementId);
283
+ }
284
+ else {
285
+ // Toggle off if already selected
286
+ onDeselect();
287
+ }
288
+ justSelectedRef.current = true; // Mark that we just selected
289
+ }
290
+ mouseDownPosRef.current = null;
291
+ }
292
+ }, style: {
293
+ cursor: isDragging ? "move" : "grab",
294
+ opacity: isDragging || isRotating || isResizing ? 0.8 : 1,
295
+ transition: isDragging || isRotating || isResizing ? "none" : "opacity 0.2s ease",
296
+ display: "inline-block",
297
+ position: "relative",
298
+ transform: `translate(${currentPosition.x}px, ${currentPosition.y}px)`,
299
+ }, children: (0, jsx_runtime_1.jsxs)("div", { style: {
300
+ transform: centerOrigin ? 'translate(-50%, -50%)' : undefined,
301
+ position: "relative"
302
+ }, children: [(isDragging || isRotating || isResizing) && ((0, jsx_runtime_1.jsx)("div", { style: {
303
+ position: "absolute",
304
+ inset: "-8px",
305
+ border: "2px dashed rgba(59, 130, 246, 0.5)",
306
+ zIndex: 0,
307
+ pointerEvents: "none",
308
+ } })), (0, jsx_runtime_1.jsxs)("div", { ref: rotatingContentRef, style: { transform: `rotate(${rotation}deg)`, position: "relative", display: "inline-block" }, children: [isSelected && ((0, jsx_runtime_1.jsx)("div", { style: {
309
+ position: "absolute",
310
+ inset: 0,
311
+ border: "4px dotted rgba(59, 130, 246, 1)",
312
+ zIndex: 1,
313
+ pointerEvents: "none",
314
+ } })), onRotationChange && isSelected && ((0, jsx_runtime_1.jsx)("div", { ref: blueHandleRef, className: "rotation-handle", onMouseDown: handleRotationStart, style: {
315
+ position: "absolute",
316
+ top: "-16px",
317
+ right: "-16px",
318
+ width: "32px",
319
+ height: "32px",
320
+ borderRadius: "50%",
321
+ backgroundColor: "rgba(59, 130, 246, 0.9)",
322
+ border: "2px solid white",
323
+ cursor: "grab",
324
+ display: "flex",
325
+ alignItems: "center",
326
+ justifyContent: "center",
327
+ fontSize: "16px",
328
+ lineHeight: "1",
329
+ color: "white",
330
+ zIndex: 1000,
331
+ boxShadow: "0 2px 4px rgba(0,0,0,0.2)",
332
+ transform: `rotate(${-rotation}deg)`,
333
+ transformOrigin: "center center",
334
+ }, title: "Drag to rotate", children: "\u21BB" })), onRotationChange && isSelected && ((0, jsx_runtime_1.jsx)("div", { ref: purpleIndicatorRef, style: {
335
+ position: "absolute",
336
+ top: "-16px",
337
+ right: "-16px",
338
+ width: "32px",
339
+ height: "32px",
340
+ borderRadius: "50%",
341
+ backgroundColor: "rgba(139, 92, 246, 0.9)",
342
+ border: "2px solid white",
343
+ display: "flex",
344
+ alignItems: "center",
345
+ justifyContent: "center",
346
+ fontSize: "16px",
347
+ lineHeight: "1",
348
+ color: "white",
349
+ zIndex: 999,
350
+ boxShadow: "0 2px 4px rgba(0,0,0,0.2)",
351
+ pointerEvents: "none",
352
+ }, title: "Rotation indicator", children: "\u21BB" })), isSelected && ((0, jsx_runtime_1.jsx)("div", { className: "width-handle width-handle-left", onMouseDown: (e) => handleResizeStart(e, 'left'), style: {
353
+ position: "absolute",
354
+ left: "-16px",
355
+ top: "50%",
356
+ transform: `translateY(-50%) rotate(${-rotation}deg)`,
357
+ transformOrigin: "center center",
358
+ width: "32px",
359
+ height: "32px",
360
+ borderRadius: "50%",
361
+ backgroundColor: "rgba(16, 185, 129, 0.9)",
362
+ border: "2px solid white",
363
+ cursor: "ew-resize",
364
+ display: "flex",
365
+ alignItems: "center",
366
+ justifyContent: "center",
367
+ fontSize: "16px",
368
+ lineHeight: "1",
369
+ color: "white",
370
+ zIndex: 1000,
371
+ boxShadow: "0 2px 4px rgba(0,0,0,0.2)",
372
+ }, title: "Drag to resize width", children: "\u27F7" })), isSelected && ((0, jsx_runtime_1.jsx)("div", { className: "width-handle width-handle-right", onMouseDown: (e) => handleResizeStart(e, 'right'), style: {
373
+ position: "absolute",
374
+ right: "-16px",
375
+ top: "50%",
376
+ transform: `translateY(-50%) rotate(${-rotation}deg)`,
377
+ transformOrigin: "center center",
378
+ width: "32px",
379
+ height: "32px",
380
+ borderRadius: "50%",
381
+ backgroundColor: "rgba(16, 185, 129, 0.9)",
382
+ border: "2px solid white",
383
+ cursor: "ew-resize",
384
+ display: "flex",
385
+ alignItems: "center",
386
+ justifyContent: "center",
387
+ fontSize: "16px",
388
+ lineHeight: "1",
389
+ color: "white",
390
+ zIndex: 1000,
391
+ boxShadow: "0 2px 4px rgba(0,0,0,0.2)",
392
+ }, title: "Drag to resize width", children: "\u27F7" })), (0, jsx_runtime_1.jsx)("div", { ref: contentOnlyRef, style: {
393
+ position: "relative",
394
+ zIndex: 1,
395
+ width: width ? `${width}px` : undefined,
396
+ }, children: children })] })] }) }));
397
+ };
398
+ exports.DraggableElement = DraggableElement;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Shared components barrel export
3
+ * Reusable components used across all banner styles
4
+ */
5
+ export { DraggableElement } from './DraggableElement';
6
+ export type { DraggableElementProps } from './DraggableElement';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/shared/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * Shared components barrel export
4
+ * Reusable components used across all banner styles
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.DraggableElement = void 0;
8
+ var DraggableElement_1 = require("./DraggableElement");
9
+ Object.defineProperty(exports, "DraggableElement", { enumerable: true, get: function () { return DraggableElement_1.DraggableElement; } });