@rpg-engine/long-bow 0.8.230 → 0.8.231

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": "@rpg-engine/long-bow",
3
- "version": "0.8.230",
3
+ "version": "0.8.231",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -20,38 +20,49 @@ export const ItemTooltip: React.FC<IItemTooltipProps> = ({
20
20
  equipmentSet,
21
21
  }) => {
22
22
  const ref = useRef<HTMLDivElement>(null);
23
+ const rafId = useRef<number | null>(null);
23
24
 
24
25
  useEffect(() => {
25
26
  const { current } = ref;
26
27
 
27
28
  if (current) {
28
29
  const handleMouseMove = (event: MouseEvent) => {
30
+ if (rafId.current !== null) return;
31
+
29
32
  const { clientX, clientY } = event;
30
33
 
31
- // Adjust the position of the tooltip based on the mouse position
32
- const rect = current.getBoundingClientRect();
34
+ rafId.current = requestAnimationFrame(() => {
35
+ rafId.current = null;
36
+
37
+ // Adjust the position of the tooltip based on the mouse position
38
+ const rect = current.getBoundingClientRect();
33
39
 
34
- const tooltipWidth = rect.width;
35
- const tooltipHeight = rect.height;
36
- const isOffScreenRight =
37
- clientX + tooltipWidth + offset > window.innerWidth;
38
- const isOffScreenBottom =
39
- clientY + tooltipHeight + offset > window.innerHeight;
40
- const x = isOffScreenRight
41
- ? clientX - tooltipWidth - offset
42
- : clientX + offset;
43
- const y = isOffScreenBottom
44
- ? clientY - tooltipHeight - offset
45
- : clientY + offset;
40
+ const tooltipWidth = rect.width;
41
+ const tooltipHeight = rect.height;
42
+ const isOffScreenRight =
43
+ clientX + tooltipWidth + offset > window.innerWidth;
44
+ const isOffScreenBottom =
45
+ clientY + tooltipHeight + offset > window.innerHeight;
46
+ const x = isOffScreenRight
47
+ ? clientX - tooltipWidth - offset
48
+ : clientX + offset;
49
+ const y = isOffScreenBottom
50
+ ? clientY - tooltipHeight - offset
51
+ : clientY + offset;
46
52
 
47
- current.style.transform = `translate(${x}px, ${y}px)`;
48
- current.style.opacity = '1';
53
+ current.style.transform = `translate(${x}px, ${y}px)`;
54
+ current.style.opacity = '1';
55
+ });
49
56
  };
50
57
 
51
58
  window.addEventListener('mousemove', handleMouseMove);
52
59
 
53
60
  return () => {
54
61
  window.removeEventListener('mousemove', handleMouseMove);
62
+ if (rafId.current !== null) {
63
+ cancelAnimationFrame(rafId.current);
64
+ rafId.current = null;
65
+ }
55
66
  };
56
67
  }
57
68
 
@@ -28,6 +28,7 @@ export const SimpleTooltip: React.FC<TooltipProps> = ({
28
28
  const tooltipRef = useRef<HTMLDivElement>(null);
29
29
  const triggerRef = useRef<HTMLDivElement>(null);
30
30
  const timeoutRef = useRef<NodeJS.Timeout>();
31
+ const rafId = useRef<number | null>(null);
31
32
 
32
33
  const calculatePosition = () => {
33
34
  if (!triggerRef.current || !tooltipRef.current) return;
@@ -87,26 +88,34 @@ export const SimpleTooltip: React.FC<TooltipProps> = ({
87
88
 
88
89
  useEffect(() => {
89
90
  const handleMouseMove = (event: MouseEvent) => {
90
- if (visible && tooltipRef.current && triggerRef.current) {
91
- const tooltipRect = tooltipRef.current.getBoundingClientRect();
92
- const triggerRect = triggerRef.current.getBoundingClientRect();
93
-
94
- const isOutsideTooltip =
95
- event.clientX < tooltipRect.left ||
96
- event.clientX > tooltipRect.right ||
97
- event.clientY < tooltipRect.top ||
98
- event.clientY > tooltipRect.bottom;
99
-
100
- const isOutsideTrigger =
101
- event.clientX < triggerRect.left ||
102
- event.clientX > triggerRect.right ||
103
- event.clientY < triggerRect.top ||
104
- event.clientY > triggerRect.bottom;
105
-
106
- if (isOutsideTooltip && isOutsideTrigger) {
107
- hideTooltip();
91
+ if (rafId.current !== null) return;
92
+
93
+ const { clientX, clientY } = event;
94
+
95
+ rafId.current = requestAnimationFrame(() => {
96
+ rafId.current = null;
97
+
98
+ if (visible && tooltipRef.current && triggerRef.current) {
99
+ const tooltipRect = tooltipRef.current.getBoundingClientRect();
100
+ const triggerRect = triggerRef.current.getBoundingClientRect();
101
+
102
+ const isOutsideTooltip =
103
+ clientX < tooltipRect.left ||
104
+ clientX > tooltipRect.right ||
105
+ clientY < tooltipRect.top ||
106
+ clientY > tooltipRect.bottom;
107
+
108
+ const isOutsideTrigger =
109
+ clientX < triggerRect.left ||
110
+ clientX > triggerRect.right ||
111
+ clientY < triggerRect.top ||
112
+ clientY > triggerRect.bottom;
113
+
114
+ if (isOutsideTooltip && isOutsideTrigger) {
115
+ hideTooltip();
116
+ }
108
117
  }
109
- }
118
+ });
110
119
  };
111
120
 
112
121
  const handleScroll = () => {
@@ -129,6 +138,10 @@ export const SimpleTooltip: React.FC<TooltipProps> = ({
129
138
  document.removeEventListener('mousemove', handleMouseMove);
130
139
  window.removeEventListener('scroll', handleScroll);
131
140
  window.removeEventListener('resize', handleResize);
141
+ if (rafId.current !== null) {
142
+ cancelAnimationFrame(rafId.current);
143
+ rafId.current = null;
144
+ }
132
145
  clearTimeout(timeoutRef.current);
133
146
  };
134
147
  }, [visible]);