@rxdrag/website-lib-core 0.0.76 → 0.0.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxdrag/website-lib-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.77",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.ts"
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"@types/react-dom": "^19.1.0",
|
|
25
25
|
"eslint": "^7.32.0",
|
|
26
26
|
"typescript": "^5",
|
|
27
|
+
"@rxdrag/tsconfig": "0.2.0",
|
|
27
28
|
"@rxdrag/slate-preview": "1.2.61",
|
|
28
|
-
"@rxdrag/eslint-config-custom": "0.2.12"
|
|
29
|
-
"@rxdrag/tsconfig": "0.2.0"
|
|
29
|
+
"@rxdrag/eslint-config-custom": "0.2.12"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@iconify/utils": "^3.0.2",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"lodash-es": "^4.17.21",
|
|
37
37
|
"react": "^19.1.0",
|
|
38
38
|
"react-dom": "^19.1.0",
|
|
39
|
-
"@rxdrag/
|
|
40
|
-
"@rxdrag/
|
|
39
|
+
"@rxdrag/entify-lib": "0.0.23",
|
|
40
|
+
"@rxdrag/rxcms-models": "0.3.94"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"astro": "^4.0.0 || ^5.0.0"
|
|
@@ -36,9 +36,8 @@ export const MainMedia = ({
|
|
|
36
36
|
const mainAreaRef = useRef<HTMLDivElement>(null);
|
|
37
37
|
const [isZoomed, setIsZoomed] = useState(false);
|
|
38
38
|
const [position, setPosition] = useState({ x: 0, y: 0 });
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const hasDraggedRef = useRef(false);
|
|
39
|
+
const hoverTimerRef = useRef<NodeJS.Timeout | null>(null);
|
|
40
|
+
const lastMousePosRef = useRef({ x: 0, y: 0 });
|
|
42
41
|
|
|
43
42
|
const selectedMedia = value?.find((media) => media.id === selectedId);
|
|
44
43
|
const isVideo = selectedMedia?.mediaType === MediaType.video;
|
|
@@ -47,50 +46,75 @@ export const MainMedia = ({
|
|
|
47
46
|
useEffect(() => {
|
|
48
47
|
setIsZoomed(false);
|
|
49
48
|
setPosition({ x: 0, y: 0 });
|
|
49
|
+
if (hoverTimerRef.current) {
|
|
50
|
+
clearTimeout(hoverTimerRef.current);
|
|
51
|
+
}
|
|
50
52
|
}, [selectedId]);
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
// Clean up timer on unmount
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
return () => {
|
|
57
|
+
if (hoverTimerRef.current) {
|
|
58
|
+
clearTimeout(hoverTimerRef.current);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}, []);
|
|
62
|
+
|
|
63
|
+
const updateZoomPosition = useCallback((clientX: number, clientY: number) => {
|
|
64
|
+
if (mainAreaRef.current) {
|
|
65
|
+
const { left, top, width, height } =
|
|
66
|
+
mainAreaRef.current.getBoundingClientRect();
|
|
67
|
+
const x = clientX - left;
|
|
68
|
+
const y = clientY - top;
|
|
69
|
+
|
|
70
|
+
// Calculate percentage position (0 to 1)
|
|
71
|
+
const ratioX = Math.max(0, Math.min(1, x / width));
|
|
72
|
+
const ratioY = Math.max(0, Math.min(1, y / height));
|
|
73
|
+
|
|
74
|
+
// Formula: Translate = Dimension * (0.5 - Ratio)
|
|
75
|
+
// This shifts the image opposite to mouse movement relative to center
|
|
76
|
+
const newX = width * (0.5 - ratioX);
|
|
77
|
+
const newY = height * (0.5 - ratioY);
|
|
78
|
+
|
|
79
|
+
setPosition({ x: newX, y: newY });
|
|
67
80
|
}
|
|
68
|
-
};
|
|
81
|
+
}, []);
|
|
69
82
|
|
|
70
|
-
const
|
|
83
|
+
const handleMouseEnter = useCallback(
|
|
71
84
|
(e: React.MouseEvent) => {
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
const { width, height } = mainAreaRef.current.getBoundingClientRect();
|
|
75
|
-
const scale = 2;
|
|
76
|
-
const maxX = (width * (scale - 1)) / 2;
|
|
77
|
-
const maxY = (height * (scale - 1)) / 2;
|
|
85
|
+
if (!enableZoom || isVideo) return;
|
|
86
|
+
lastMousePosRef.current = { x: e.clientX, y: e.clientY };
|
|
78
87
|
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
hoverTimerRef.current = setTimeout(() => {
|
|
89
|
+
setIsZoomed(true);
|
|
90
|
+
updateZoomPosition(
|
|
91
|
+
lastMousePosRef.current.x,
|
|
92
|
+
lastMousePosRef.current.y
|
|
93
|
+
);
|
|
94
|
+
}, 200);
|
|
95
|
+
},
|
|
96
|
+
[enableZoom, isVideo, updateZoomPosition]
|
|
97
|
+
);
|
|
81
98
|
|
|
82
|
-
|
|
83
|
-
|
|
99
|
+
const handleMouseMove = useCallback(
|
|
100
|
+
(e: React.MouseEvent) => {
|
|
101
|
+
if (!enableZoom || isVideo) return;
|
|
102
|
+
lastMousePosRef.current = { x: e.clientX, y: e.clientY };
|
|
84
103
|
|
|
85
|
-
|
|
104
|
+
if (isZoomed) {
|
|
105
|
+
updateZoomPosition(e.clientX, e.clientY);
|
|
86
106
|
}
|
|
87
107
|
},
|
|
88
|
-
[
|
|
108
|
+
[enableZoom, isVideo, isZoomed, updateZoomPosition]
|
|
89
109
|
);
|
|
90
110
|
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
111
|
+
const handleMouseLeave = useCallback(() => {
|
|
112
|
+
if (hoverTimerRef.current) {
|
|
113
|
+
clearTimeout(hoverTimerRef.current);
|
|
114
|
+
}
|
|
115
|
+
setIsZoomed(false);
|
|
116
|
+
setPosition({ x: 0, y: 0 });
|
|
117
|
+
}, []);
|
|
94
118
|
|
|
95
119
|
return (
|
|
96
120
|
<div
|
|
@@ -99,13 +123,11 @@ export const MainMedia = ({
|
|
|
99
123
|
"relative group overflow-hidden rounded-xl bg-gray-100 dark:bg-gray-800 z-0",
|
|
100
124
|
aspect,
|
|
101
125
|
className,
|
|
102
|
-
enableZoom && !isVideo
|
|
126
|
+
enableZoom && !isVideo && "cursor-crosshair"
|
|
103
127
|
)}
|
|
104
|
-
|
|
105
|
-
onMouseDown={handleMouseDown}
|
|
128
|
+
onMouseEnter={handleMouseEnter}
|
|
106
129
|
onMouseMove={handleMouseMove}
|
|
107
|
-
|
|
108
|
-
onMouseLeave={handleMouseUp}
|
|
130
|
+
onMouseLeave={handleMouseLeave}
|
|
109
131
|
>
|
|
110
132
|
{/* Navigation Arrows - Hide when zoomed to avoid misclick */}
|
|
111
133
|
{!isZoomed && (
|
|
@@ -204,7 +226,7 @@ export const MainMedia = ({
|
|
|
204
226
|
isZoomed ? 2 : 1
|
|
205
227
|
})`
|
|
206
228
|
: undefined,
|
|
207
|
-
transition:
|
|
229
|
+
transition: isZoomed ? "none" : "transform 0.3s ease-out",
|
|
208
230
|
}}
|
|
209
231
|
/>
|
|
210
232
|
)}
|