rocket-cursor-component 2.1.1 → 2.2.0

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.
@@ -1,171 +0,0 @@
1
- import React, { useEffect, useRef, useId, useMemo, useCallback, useState, } from "react";
2
- // SVG components for flame and rocket visuals
3
- const FlameSvg = ({ gradientId }) => (React.createElement("g", { transform: "translate(1.2245, 350.449) rotate(45) scale(0.5, -0.5)" },
4
- React.createElement("defs", null,
5
- React.createElement("linearGradient", { id: gradientId, gradientUnits: "userSpaceOnUse", x1: "94.141", y1: "255", x2: "94.141", y2: "0.188" },
6
- React.createElement("stop", { offset: "0", stopColor: "#ff4c0d" }),
7
- React.createElement("stop", { offset: "1", stopColor: "#fc9502" }))),
8
- React.createElement("path", { d: "M187.899,164.809 C185.803,214.868 144.574,254.812 94.000,254.812 C42.085,254.812 -0.000,211.312 -0.000,160.812 C-0.000,154.062 -0.121,140.572 10.000,117.812 C16.057,104.191 19.856,95.634 22.000,87.812 C23.178,83.513 25.469,76.683 32.000,87.812 C35.851,94.374 36.000,103.812 36.000,103.812 C36.000,103.812 50.328,92.817 60.000,71.812 C74.179,41.019 62.866,22.612 59.000,9.812 C57.662,5.384 56.822,-2.574 66.000,0.812 C75.352,4.263 100.076,21.570 113.000,39.812 C131.445,65.847 138.000,90.812 138.000,90.812 C138.000,90.812 143.906,83.482 146.000,75.812 C148.365,67.151 148.400,58.573 155.999,67.813 C163.226,76.600 173.959,93.113 180.000,108.812 C190.969,137.321 187.899,164.809 187.899,164.809 Z", fill: `url(#${gradientId})`, fillRule: "evenodd" }),
9
- React.createElement("path", { d: "M94.000,254.812 C58.101,254.812 29.000,225.711 29.000,189.812 C29.000,168.151 37.729,155.000 55.896,137.166 C67.528,125.747 78.415,111.722 83.042,102.172 C83.953,100.292 86.026,90.495 94.019,101.966 C98.212,107.982 104.785,118.681 109.000,127.812 C116.266,143.555 118.000,158.812 118.000,158.812 C118.000,158.812 125.121,154.616 130.000,143.812 C131.573,140.330 134.753,127.148 143.643,140.328 C150.166,150.000 159.127,167.390 159.000,189.812 C159.000,225.711 129.898,254.812 94.000,254.812 Z", fill: "#fc9502", fillRule: "evenodd" }),
10
- React.createElement("path", { d: "M95.000,183.812 C104.250,183.812 104.250,200.941 116.000,223.812 C123.824,239.041 112.121,254.812 95.000,254.812 C77.879,254.812 69.000,240.933 69.000,223.812 C69.000,206.692 85.750,183.812 95.000,183.812 Z", fill: "#fce202", fillRule: "evenodd" })));
11
- const RocketSvg = () => (React.createElement("g", { transform: "translate(0, 0)" },
12
- React.createElement("path", { style: { fill: "#FF7124" }, d: "M399.76,16.699c10.12,37.84,8.67,78.13-4.34,115.28h-0.01L284.48,21.049v-0.01 C321.63,8.029,361.92,6.579,399.76,16.699z" }),
13
- React.createElement("path", { style: { fill: "#F2D59F" }, d: "M90.21,207.929l87.14-101.42h0.01l33.71-39.24c21.43-21.43,46.6-36.84,73.41-46.23v0.01 l110.93,110.93h0.01c-9.39,26.81-24.8,51.98-46.23,73.41l-39.24,33.71l-101.43,87.14l-29.57-29.57l-29.58-29.58l-29.58-29.58 L90.21,207.929z M296.11,193.399c20.18-20.17,20.18-52.89,0-73.06c-20.17-20.18-52.89-20.18-73.06,0 c-20.18,20.17-20.18,52.89,0,73.06C243.22,213.579,275.94,213.579,296.11,193.399z" }),
14
- React.createElement("path", { style: { fill: "#F2D59F" }, d: "M309.95,239.099c1.74,45.6-14.8,91.78-49.61,126.59c-10.69,10.68-22.44,19.65-34.93,26.89 l-16.89-66.34L309.95,239.099z" }),
15
- React.createElement("path", { style: { fill: "#8ECAC1" }, d: "M296.11,120.339c20.18,20.17,20.18,52.89,0,73.06c-20.17,20.18-52.89,20.18-73.06,0 c-20.18-20.17-20.18-52.89,0-73.06C243.22,100.159,275.94,100.159,296.11,120.339z" }),
16
- React.createElement("path", { style: { fill: "#E6B263" }, d: "M208.52,326.239l-39.94,14.71c-10.98,4.05-23.31,1.34-31.58-6.94l-6.85-6.85l48.8-30.49 L208.52,326.239z" }),
17
- React.createElement("polygon", { style: { fill: "#E6B263" }, points: "178.95,296.669 130.15,327.159 130.14,327.159 109.72,306.739 149.37,267.089" }),
18
- React.createElement("path", { style: { fill: "#F2D59F" }, d: "M177.35,106.509l-87.14,101.42l-66.33-16.88c7.24-12.49,16.21-24.24,26.89-34.93 C85.58,121.309,131.74,104.769,177.35,106.509z" }),
19
- React.createElement("polygon", { style: { fill: "#E6B263" }, points: "149.37,267.089 109.72,306.739 89.3,286.309 119.79,237.509" }),
20
- React.createElement("path", { style: { fill: "#E6B263" }, d: "M119.79,237.509l-30.49,48.8l-6.86-6.85c-8.27-8.28-10.98-20.6-6.94-31.58l14.71-39.95 L119.79,237.509z" })));
21
- const RocketCursor = ({ size = 50, threshold = 10, flameHideTimeout = 300, isVisible = true, hideCursor = false, followSpeed = 0.18, // default smoothing similar to původní chování
22
- }) => {
23
- const gradientId = useId();
24
- const wrapperRef = useRef(null);
25
- const flameRef = useRef(null);
26
- const target = useRef({
27
- x: typeof window !== "undefined" ? window.innerWidth / 2 : 0,
28
- y: typeof window !== "undefined" ? window.innerHeight / 2 : 0,
29
- });
30
- const current = useRef(Object.assign({}, target.current));
31
- const angleRef = useRef(0);
32
- const lastMoveTs = useRef(Date.now());
33
- const rafRef = useRef(null);
34
- const [isMoving, setIsMoving] = useState(false);
35
- const isMovingRef = useRef(false);
36
- const [visible, setVisible] = useState(isVisible);
37
- const lastSignificantPosition = useRef(Object.assign({}, target.current));
38
- const flameTimeoutRef = useRef(null);
39
- useEffect(() => {
40
- setVisible(isVisible);
41
- }, [isVisible]);
42
- useEffect(() => {
43
- if (hideCursor) {
44
- document.body.style.cursor = "none";
45
- }
46
- else {
47
- document.body.style.cursor = "";
48
- }
49
- return () => {
50
- document.body.style.cursor = "";
51
- };
52
- }, [hideCursor]);
53
- const handleMouseMove = useCallback((e) => {
54
- const t = e.target;
55
- const exclude = t && t.closest && t.closest(".no-rocket-cursor");
56
- const shouldShow = !exclude && isVisible;
57
- setVisible(shouldShow);
58
- if (!shouldShow)
59
- return;
60
- target.current.x = e.clientX;
61
- target.current.y = e.clientY;
62
- lastMoveTs.current = Date.now();
63
- const dx = target.current.x - lastSignificantPosition.current.x;
64
- const dy = target.current.y - lastSignificantPosition.current.y;
65
- const distance = Math.hypot(dx, dy);
66
- if (distance > threshold) {
67
- angleRef.current = Math.atan2(dy, dx) * (180 / Math.PI) + 45;
68
- lastSignificantPosition.current = {
69
- x: target.current.x,
70
- y: target.current.y,
71
- };
72
- }
73
- setIsMoving(true);
74
- isMovingRef.current = true;
75
- if (flameTimeoutRef.current) {
76
- window.clearTimeout(flameTimeoutRef.current);
77
- }
78
- flameTimeoutRef.current = window.setTimeout(() => {
79
- setIsMoving(false);
80
- isMovingRef.current = false;
81
- }, flameHideTimeout);
82
- }, [threshold, flameHideTimeout, isVisible]);
83
- const handleMouseOut = useCallback((e) => {
84
- const rel = e.relatedTarget;
85
- if (!rel || rel.nodeName === "HTML") {
86
- setVisible(false);
87
- setIsMoving(false);
88
- isMovingRef.current = false;
89
- }
90
- }, []);
91
- const handleVisibilityChange = useCallback(() => {
92
- if (document.visibilityState === "visible") {
93
- setVisible(true);
94
- }
95
- }, []);
96
- useEffect(() => {
97
- window.addEventListener("mousemove", handleMouseMove, { passive: true });
98
- document.addEventListener("mouseout", handleMouseOut);
99
- document.addEventListener("visibilitychange", handleVisibilityChange);
100
- const step = () => {
101
- const lerp = Math.min(Math.max(followSpeed, 0), 1);
102
- const dx = target.current.x - current.current.x;
103
- const dy = target.current.y - current.current.y;
104
- const distanceToTarget = Math.hypot(dx, dy);
105
- // Snap to cursor when we are very close to avoid asymptotic lag/overshoot feeling
106
- if (distanceToTarget < 0.5) {
107
- current.current.x = target.current.x;
108
- current.current.y = target.current.y;
109
- }
110
- else {
111
- current.current.x += dx * lerp;
112
- current.current.y += dy * lerp;
113
- }
114
- const showFlame = Date.now() - lastMoveTs.current < flameHideTimeout;
115
- const el = wrapperRef.current;
116
- if (el) {
117
- // Shift rocket so the nose (not the center) meets the cursor
118
- const dirRad = (angleRef.current - 45) * (Math.PI / 180); // remove the art's 45° offset
119
- const noseOffset = size * 0.35; // distance from center to nose, scaled with size
120
- const noseX = Math.cos(dirRad) * noseOffset;
121
- const noseY = Math.sin(dirRad) * noseOffset;
122
- el.style.transform = `translate3d(${current.current.x - noseX}px, ${current.current.y - noseY}px, 0) translate(-50%, -50%)`;
123
- const svg = el.querySelector("svg");
124
- if (svg) {
125
- svg.style.transform = `rotate(${angleRef.current}deg)`;
126
- }
127
- }
128
- if (flameRef.current) {
129
- flameRef.current.style.opacity =
130
- showFlame && isMovingRef.current ? "1" : "0";
131
- }
132
- rafRef.current = requestAnimationFrame(step);
133
- };
134
- rafRef.current = requestAnimationFrame(step);
135
- return () => {
136
- window.removeEventListener("mousemove", handleMouseMove);
137
- document.removeEventListener("mouseout", handleMouseOut);
138
- document.removeEventListener("visibilitychange", handleVisibilityChange);
139
- if (rafRef.current)
140
- cancelAnimationFrame(rafRef.current);
141
- if (flameTimeoutRef.current) {
142
- window.clearTimeout(flameTimeoutRef.current);
143
- }
144
- };
145
- }, [handleMouseMove, handleMouseOut, handleVisibilityChange]);
146
- const wrapperStyle = useMemo(() => ({
147
- position: "fixed",
148
- left: 0,
149
- top: 0,
150
- pointerEvents: "none",
151
- zIndex: 9999,
152
- width: `${size}px`,
153
- height: `${size * 1.5}px`,
154
- willChange: "transform",
155
- display: visible ? "block" : "none",
156
- }), [size, visible]);
157
- const svgStyle = useMemo(() => ({
158
- width: "100%",
159
- height: "100%",
160
- display: "block",
161
- }), []);
162
- if (!visible) {
163
- return null;
164
- }
165
- return (React.createElement("div", { ref: wrapperRef, style: wrapperStyle },
166
- React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 416.449 516.449", style: svgStyle },
167
- React.createElement("g", { ref: flameRef },
168
- React.createElement(FlameSvg, { gradientId: gradientId })),
169
- React.createElement(RocketSvg, null))));
170
- };
171
- export default RocketCursor;