@once-ui-system/core 1.6.2 → 1.6.4
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/LICENSE.md +21 -0
- package/dist/components/CelebrationFx.d.ts +1 -0
- package/dist/components/CelebrationFx.d.ts.map +1 -1
- package/dist/components/CelebrationFx.js +7 -3
- package/dist/components/CelebrationFx.js.map +1 -1
- package/dist/components/HoloFx.d.ts +1 -0
- package/dist/components/HoloFx.d.ts.map +1 -1
- package/dist/components/HoloFx.js +10 -3
- package/dist/components/HoloFx.js.map +1 -1
- package/dist/components/Mask.d.ts +1 -0
- package/dist/components/Mask.d.ts.map +1 -1
- package/dist/components/Mask.js +56 -32
- package/dist/components/Mask.js.map +1 -1
- package/dist/components/MatrixFx.d.ts +1 -0
- package/dist/components/MatrixFx.d.ts.map +1 -1
- package/dist/components/MatrixFx.js +8 -1
- package/dist/components/MatrixFx.js.map +1 -1
- package/dist/components/Particle.d.ts +1 -0
- package/dist/components/Particle.d.ts.map +1 -1
- package/dist/components/Particle.js +86 -78
- package/dist/components/Particle.js.map +1 -1
- package/dist/components/ShineFx.d.ts +1 -0
- package/dist/components/ShineFx.d.ts.map +1 -1
- package/dist/components/ShineFx.js +5 -2
- package/dist/components/ShineFx.js.map +1 -1
- package/dist/components/TiltFx.d.ts +1 -0
- package/dist/components/TiltFx.d.ts.map +1 -1
- package/dist/components/TiltFx.js +27 -10
- package/dist/components/TiltFx.js.map +1 -1
- package/dist/components/WeatherFx.d.ts +1 -0
- package/dist/components/WeatherFx.d.ts.map +1 -1
- package/dist/components/WeatherFx.js +97 -2
- package/dist/components/WeatherFx.js.map +1 -1
- package/dist/css/styles.css +1 -1
- package/dist/css/styles.css.map +1 -1
- package/dist/data/emoji-data.json +8 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useInViewport.d.ts +3 -0
- package/dist/hooks/useInViewport.d.ts.map +1 -0
- package/dist/hooks/useInViewport.js +19 -0
- package/dist/hooks/useInViewport.js.map +1 -0
- package/dist/hooks/useReducedMotion.d.ts +8 -0
- package/dist/hooks/useReducedMotion.d.ts.map +1 -0
- package/dist/hooks/useReducedMotion.js +44 -0
- package/dist/hooks/useReducedMotion.js.map +1 -0
- package/dist/interfaces.d.ts +12 -0
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/modules/navigation/Kbar.d.ts.map +1 -1
- package/dist/modules/navigation/Kbar.js +13 -28
- package/dist/modules/navigation/Kbar.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/styles/typography.scss +8 -40
- package/next-env.d.ts +5 -0
- package/package.json +113 -115
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import React, { useEffect, useRef } from "react";
|
|
4
4
|
import { Flex } from ".";
|
|
5
|
-
|
|
5
|
+
import { useInViewport } from "../hooks/useInViewport";
|
|
6
|
+
import { useReducedMotion } from "../hooks/useReducedMotion";
|
|
7
|
+
const Particle = React.forwardRef(({ density = 100, color = "brand-on-background-weak", size = "2", speed = 0.3, interactive = false, mode = "repel", intensity = 20, opacity = 100, reducedMotion = "auto", children, className, style, ...rest }, forwardedRef) => {
|
|
6
8
|
const containerRef = useRef(null);
|
|
9
|
+
const isInViewport = useInViewport(containerRef);
|
|
10
|
+
const { shouldAnimate } = useReducedMotion(reducedMotion);
|
|
7
11
|
useEffect(() => {
|
|
8
12
|
if (forwardedRef && "current" in forwardedRef) {
|
|
9
13
|
forwardedRef.current = containerRef.current;
|
|
@@ -14,118 +18,122 @@ const Particle = React.forwardRef(({ density = 100, color = "brand-on-background
|
|
|
14
18
|
}, [forwardedRef]);
|
|
15
19
|
useEffect(() => {
|
|
16
20
|
const container = containerRef.current;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
if (!container)
|
|
22
|
+
return;
|
|
23
|
+
// If reduced motion, render static particles with no animation loop
|
|
24
|
+
const effectiveDensity = shouldAnimate ? density : Math.min(density, 30);
|
|
25
|
+
const particleEls = [];
|
|
26
|
+
// Flat arrays for fast iteration — no Map lookups or style parsing per frame
|
|
27
|
+
const currentX = new Float32Array(effectiveDensity);
|
|
28
|
+
const currentY = new Float32Array(effectiveDensity);
|
|
29
|
+
const initialX = new Float32Array(effectiveDensity);
|
|
30
|
+
const initialY = new Float32Array(effectiveDensity);
|
|
31
|
+
const targetX = new Float32Array(effectiveDensity);
|
|
32
|
+
const targetY = new Float32Array(effectiveDensity);
|
|
20
33
|
let mousePosition = { x: -1000, y: -1000 };
|
|
21
|
-
let animationFrameId;
|
|
34
|
+
let animationFrameId = null;
|
|
22
35
|
const parsedSize = `var(--static-space-${size})`;
|
|
23
36
|
const parsedOpacity = `${opacity}%`;
|
|
24
37
|
const movementSpeed = speed * 0.08;
|
|
25
38
|
const repulsionStrength = 0.15 * (speed || 1);
|
|
26
39
|
const handleMouseMove = (e) => {
|
|
27
|
-
const rect = container
|
|
28
|
-
if (!rect)
|
|
29
|
-
return;
|
|
40
|
+
const rect = container.getBoundingClientRect();
|
|
30
41
|
mousePosition = {
|
|
31
42
|
x: ((e.clientX - rect.left) / rect.width) * 100,
|
|
32
43
|
y: ((e.clientY - rect.top) / rect.height) * 100,
|
|
33
44
|
};
|
|
34
45
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
// Create particles using translate3d instead of left/top
|
|
47
|
+
for (let i = 0; i < effectiveDensity; i++) {
|
|
48
|
+
const el = document.createElement("div");
|
|
49
|
+
el.style.cssText = `
|
|
50
|
+
position:absolute;left:0;top:0;
|
|
51
|
+
width:${parsedSize};height:${parsedSize};
|
|
52
|
+
background:var(--${color});
|
|
53
|
+
border-radius:50%;
|
|
54
|
+
pointer-events:none;
|
|
55
|
+
opacity:${parsedOpacity};
|
|
56
|
+
will-change:transform;
|
|
57
|
+
`;
|
|
58
|
+
const ix = 10 + Math.random() * 80;
|
|
59
|
+
const iy = 10 + Math.random() * 80;
|
|
60
|
+
initialX[i] = ix;
|
|
61
|
+
initialY[i] = iy;
|
|
62
|
+
currentX[i] = ix;
|
|
63
|
+
currentY[i] = iy;
|
|
64
|
+
targetX[i] = ix;
|
|
65
|
+
targetY[i] = iy;
|
|
66
|
+
el.style.transform = `translate3d(${ix}cqw, ${iy}cqh, 0)`;
|
|
67
|
+
container.appendChild(el);
|
|
68
|
+
particleEls.push(el);
|
|
69
|
+
}
|
|
70
|
+
// If reduced motion or not in viewport initially, just place them statically
|
|
71
|
+
if (!shouldAnimate)
|
|
72
|
+
return () => cleanup();
|
|
55
73
|
const updateParticles = () => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const baseNoiseX = Math.sin(time + index) * 0.5;
|
|
65
|
-
const baseNoiseY = Math.cos(time + index * 1.2) * 0.5;
|
|
66
|
-
let targetX = initial.x + baseNoiseX;
|
|
67
|
-
let targetY = initial.y + baseNoiseY;
|
|
68
|
-
let isCloseToMouse = false;
|
|
74
|
+
const time = Date.now() * 0.001 * speed;
|
|
75
|
+
for (let i = 0; i < effectiveDensity; i++) {
|
|
76
|
+
const cx = currentX[i];
|
|
77
|
+
const cy = currentY[i];
|
|
78
|
+
const baseNoiseX = Math.sin(time + i) * 0.5;
|
|
79
|
+
const baseNoiseY = Math.cos(time + i * 1.2) * 0.5;
|
|
80
|
+
let tx = initialX[i] + baseNoiseX;
|
|
81
|
+
let ty = initialY[i] + baseNoiseY;
|
|
69
82
|
if (interactive) {
|
|
70
|
-
const dx = mousePosition.x -
|
|
71
|
-
const dy = mousePosition.y -
|
|
83
|
+
const dx = mousePosition.x - cx;
|
|
84
|
+
const dy = mousePosition.y - cy;
|
|
72
85
|
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
73
86
|
if (distance < intensity) {
|
|
74
87
|
const angle = Math.atan2(dy, dx);
|
|
75
88
|
if (mode === "attract") {
|
|
76
|
-
// Attract: move towards cursor
|
|
77
89
|
const minDistance = 8;
|
|
78
90
|
if (distance <= minDistance) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
targetY = mousePosition.y;
|
|
82
|
-
isCloseToMouse = true;
|
|
91
|
+
tx = mousePosition.x;
|
|
92
|
+
ty = mousePosition.y;
|
|
83
93
|
}
|
|
84
94
|
else {
|
|
85
|
-
// Force is proportional to distance (strong when far, weak when close)
|
|
86
95
|
const normalizedDistance = Math.min(distance / intensity, 1);
|
|
87
96
|
const force = distance * repulsionStrength * normalizedDistance * 0.3;
|
|
88
|
-
|
|
89
|
-
|
|
97
|
+
tx = cx + Math.cos(angle) * force;
|
|
98
|
+
ty = cy + Math.sin(angle) * force;
|
|
90
99
|
}
|
|
91
100
|
}
|
|
92
101
|
else {
|
|
93
|
-
// Repel: move away from cursor (original behavior)
|
|
94
102
|
const force = (intensity - distance) * repulsionStrength;
|
|
95
|
-
|
|
96
|
-
|
|
103
|
+
tx -= Math.cos(angle) * force;
|
|
104
|
+
ty -= Math.sin(angle) * force;
|
|
97
105
|
}
|
|
98
106
|
}
|
|
99
107
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
tx = Math.max(5, Math.min(95, tx));
|
|
109
|
+
ty = Math.max(5, Math.min(95, ty));
|
|
110
|
+
targetX[i] = tx;
|
|
111
|
+
targetY[i] = ty;
|
|
112
|
+
const nx = cx + (tx - cx) * movementSpeed;
|
|
113
|
+
const ny = cy + (ty - cy) * movementSpeed;
|
|
114
|
+
currentX[i] = nx;
|
|
115
|
+
currentY[i] = ny;
|
|
116
|
+
particleEls[i].style.transform = `translate3d(${nx}cqw, ${ny}cqh, 0)`;
|
|
117
|
+
}
|
|
109
118
|
animationFrameId = requestAnimationFrame(updateParticles);
|
|
110
119
|
};
|
|
111
120
|
if (interactive) {
|
|
112
|
-
|
|
121
|
+
container.addEventListener("mousemove", handleMouseMove, { passive: true });
|
|
113
122
|
}
|
|
114
|
-
|
|
115
|
-
|
|
123
|
+
// Start animation only if in viewport
|
|
124
|
+
if (isInViewport) {
|
|
125
|
+
animationFrameId = requestAnimationFrame(updateParticles);
|
|
116
126
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}, [color, size, speed, interactive, intensity, opacity, density, containerRef]);
|
|
128
|
-
return (_jsx(Flex, { ref: containerRef, fill: true, pointerEvents: "none", className: className, style: style, ...rest, children: children }));
|
|
127
|
+
function cleanup() {
|
|
128
|
+
container.removeEventListener("mousemove", handleMouseMove);
|
|
129
|
+
if (animationFrameId != null) {
|
|
130
|
+
cancelAnimationFrame(animationFrameId);
|
|
131
|
+
}
|
|
132
|
+
particleEls.forEach((el) => el.remove());
|
|
133
|
+
}
|
|
134
|
+
return () => cleanup();
|
|
135
|
+
}, [color, size, speed, interactive, intensity, opacity, density, mode, shouldAnimate, isInViewport]);
|
|
136
|
+
return (_jsx(Flex, { ref: containerRef, fill: true, position: "relative", pointerEvents: interactive ? "auto" : "none", className: className, style: { containerType: "size", ...style }, ...rest, children: children }));
|
|
129
137
|
});
|
|
130
138
|
Particle.displayName = "Particle";
|
|
131
139
|
export { Particle };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Particle.js","sourceRoot":"","sources":["../../src/components/Particle.tsx"],"names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AAM,EAC5C,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,KACtC,IAAI,YAEP,QAAQ,GACJ,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,QAAQ,CAAC,WAAW,GAAG,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShineFx.d.ts","sourceRoot":"","sources":["../../src/components/ShineFx.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"ShineFx.d.ts","sourceRoot":"","sources":["../../src/components/ShineFx.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;AAKzB,MAAM,WAAW,YAAa,SAAQ,KAAK,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC;IACrE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACjC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,QAAA,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CA4BnC,CAAC;AAIF,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -3,9 +3,12 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { Text } from ".";
|
|
4
4
|
import styles from "./ShineFx.module.scss";
|
|
5
5
|
import classNames from "classnames";
|
|
6
|
-
|
|
6
|
+
import { useReducedMotion } from "../hooks/useReducedMotion";
|
|
7
|
+
const ShineFx = ({ speed = 1, disabled = false, inverse = false, baseOpacity = 0.3, reducedMotion = "auto", children, className, style, ...text }) => {
|
|
8
|
+
const { shouldAnimate } = useReducedMotion(reducedMotion);
|
|
9
|
+
const isDisabled = disabled || !shouldAnimate;
|
|
7
10
|
const animationDuration = `${speed}s`;
|
|
8
|
-
return (_jsx(Text, { ...text, className: classNames(styles.shineFx,
|
|
11
|
+
return (_jsx(Text, { ...text, className: classNames(styles.shineFx, isDisabled ? styles.disabled : "", inverse ? styles.inverse : styles.default, className), style: {
|
|
9
12
|
...style,
|
|
10
13
|
animationDuration,
|
|
11
14
|
["--shine-base-opacity"]: baseOpacity,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShineFx.js","sourceRoot":"","sources":["../../src/components/ShineFx.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;AACzB,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAC3C,OAAO,UAAU,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"ShineFx.js","sourceRoot":"","sources":["../../src/components/ShineFx.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;AACzB,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAC3C,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAW7D,MAAM,OAAO,GAA2B,CAAC,EACvC,KAAK,GAAG,CAAC,EACT,QAAQ,GAAG,KAAK,EAChB,OAAO,GAAG,KAAK,EACf,WAAW,GAAG,GAAG,EACjB,aAAa,GAAG,MAAM,EACtB,QAAQ,EACR,SAAS,EACT,KAAK,EACL,GAAG,IAAI,EACR,EAAE,EAAE;IACH,MAAM,EAAE,aAAa,EAAE,GAAG,gBAAgB,CAAC,aAAa,CAAC,CAAC;IAC1D,MAAM,UAAU,GAAG,QAAQ,IAAI,CAAC,aAAa,CAAC;IAC9C,MAAM,iBAAiB,GAAG,GAAG,KAAK,GAAG,CAAC;IAEtC,OAAO,CACL,KAAC,IAAI,OACC,IAAI,EACR,SAAS,EAAE,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,EAC9H,KAAK,EAAE;YACL,GAAG,KAAK;YACR,iBAAiB;YACjB,CAAC,sBAAgC,CAAC,EAAE,WAAW;SAChD,YAEA,QAAQ,GACJ,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;AAEhC,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TiltFx.d.ts","sourceRoot":"","sources":["../../src/components/TiltFx.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"TiltFx.d.ts","sourceRoot":"","sources":["../../src/components/TiltFx.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAEjD,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;AAGzB,UAAU,WAAY,SAAQ,KAAK,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC;IAC7D,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CAClC;AAED,QAAA,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CA+EjC,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useRef } from "react";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
4
|
import styles from "./TiltFx.module.scss";
|
|
5
5
|
import { Flex } from ".";
|
|
6
|
-
|
|
6
|
+
import { useReducedMotion } from "../hooks/useReducedMotion";
|
|
7
|
+
const TiltFx = ({ children, intensity = 1, reducedMotion = "auto", ...rest }) => {
|
|
7
8
|
const ref = useRef(null);
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
const lastCallRef = useRef(0);
|
|
10
|
+
const resetTimeoutRef = useRef(null);
|
|
11
|
+
const isTouchDeviceRef = useRef(false);
|
|
12
|
+
const { shouldAnimate } = useReducedMotion(reducedMotion);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
isTouchDeviceRef.current = "ontouchstart" in window;
|
|
15
|
+
}, []);
|
|
10
16
|
const handleMouseMove = (e) => {
|
|
11
|
-
if (
|
|
17
|
+
if (isTouchDeviceRef.current || !shouldAnimate)
|
|
12
18
|
return;
|
|
13
|
-
|
|
19
|
+
if (resetTimeoutRef.current) {
|
|
20
|
+
clearTimeout(resetTimeoutRef.current);
|
|
21
|
+
resetTimeoutRef.current = null;
|
|
22
|
+
}
|
|
14
23
|
const now = Date.now();
|
|
15
|
-
if (now -
|
|
24
|
+
if (now - lastCallRef.current < 16)
|
|
16
25
|
return;
|
|
17
|
-
|
|
26
|
+
lastCallRef.current = now;
|
|
18
27
|
const element = ref.current;
|
|
19
28
|
if (!element)
|
|
20
29
|
return;
|
|
@@ -33,16 +42,24 @@ const TiltFx = ({ children, intensity = 1, ...rest }) => {
|
|
|
33
42
|
});
|
|
34
43
|
};
|
|
35
44
|
const handleMouseLeave = () => {
|
|
36
|
-
if (
|
|
45
|
+
if (isTouchDeviceRef.current || !shouldAnimate)
|
|
37
46
|
return;
|
|
38
47
|
const element = ref.current;
|
|
39
48
|
if (element) {
|
|
40
|
-
|
|
49
|
+
resetTimeoutRef.current = setTimeout(() => {
|
|
41
50
|
element.style.transform =
|
|
42
51
|
"perspective(1000px) translate3d(0, 0, 0) rotateX(0deg) rotateY(0deg)";
|
|
52
|
+
resetTimeoutRef.current = null;
|
|
43
53
|
}, 100);
|
|
44
54
|
}
|
|
45
55
|
};
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
return () => {
|
|
58
|
+
if (resetTimeoutRef.current) {
|
|
59
|
+
clearTimeout(resetTimeoutRef.current);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}, []);
|
|
46
63
|
return (_jsx(Flex, { ref: ref, overflow: "hidden", className: styles.tiltFx, onMouseMove: handleMouseMove, onMouseLeave: handleMouseLeave, ...rest, children: children }));
|
|
47
64
|
};
|
|
48
65
|
export { TiltFx };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TiltFx.js","sourceRoot":"","sources":["../../src/components/TiltFx.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAc,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"TiltFx.js","sourceRoot":"","sources":["../../src/components/TiltFx.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAc,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAQ7D,MAAM,MAAM,GAA0B,CAAC,EAAE,QAAQ,EAAE,SAAS,GAAG,CAAC,EAAE,aAAa,GAAG,MAAM,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE;IACrG,MAAM,GAAG,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IACzC,MAAM,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9B,M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,CAAC,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAC"}
|
|
@@ -10,6 +10,7 @@ interface WeatherFxProps extends React.ComponentProps<typeof Flex> {
|
|
|
10
10
|
duration?: number;
|
|
11
11
|
trigger?: "mount" | "hover" | "click" | "manual";
|
|
12
12
|
active?: boolean;
|
|
13
|
+
reducedMotion?: boolean | "auto";
|
|
13
14
|
children?: React.ReactNode;
|
|
14
15
|
}
|
|
15
16
|
declare const WeatherFx: React.ForwardRefExoticComponent<Omit<WeatherFxProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WeatherFx.d.ts","sourceRoot":"","sources":["../../src/components/WeatherFx.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"WeatherFx.d.ts","sourceRoot":"","sources":["../../src/components/WeatherFx.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;AAGzB,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,CAAC;AAE5D,UAAU,cAAe,SAAQ,KAAK,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC;IAChE,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;IACjD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACjC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAgED,QAAA,MAAM,SAAS,oGA0+Bd,CAAC;AAGF,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import React, { useEffect, useRef } from "react";
|
|
4
4
|
import { Flex } from ".";
|
|
5
|
-
|
|
5
|
+
import { useReducedMotion } from "../hooks/useReducedMotion";
|
|
6
|
+
const WeatherFx = React.forwardRef(({ type = "rain", speed = 1, colors = ["brand-solid-medium"], intensity = 50, angle = 0, duration, trigger = "mount", active = false, reducedMotion = "auto", children, ...rest }, forwardedRef) => {
|
|
7
|
+
const { shouldAnimate } = useReducedMotion(reducedMotion);
|
|
6
8
|
const containerRef = useRef(null);
|
|
7
9
|
const canvasRef = useRef(null);
|
|
8
10
|
const animationRef = useRef(undefined);
|
|
@@ -532,6 +534,12 @@ const WeatherFx = React.forwardRef(({ type = "rain", speed = 1, colors = ["brand
|
|
|
532
534
|
ctx.globalAlpha = 1;
|
|
533
535
|
animationRef.current = requestAnimationFrame(animate);
|
|
534
536
|
};
|
|
537
|
+
if (!shouldAnimate) {
|
|
538
|
+
// When reduced motion is active, don't start the animation loop at all
|
|
539
|
+
return () => {
|
|
540
|
+
window.removeEventListener("resize", updateSize);
|
|
541
|
+
};
|
|
542
|
+
}
|
|
535
543
|
animate();
|
|
536
544
|
return () => {
|
|
537
545
|
window.removeEventListener("resize", updateSize);
|
|
@@ -539,7 +547,7 @@ const WeatherFx = React.forwardRef(({ type = "rain", speed = 1, colors = ["brand
|
|
|
539
547
|
cancelAnimationFrame(animationRef.current);
|
|
540
548
|
}
|
|
541
549
|
};
|
|
542
|
-
}, [type, colors, speed, intensity, angle, duration, trigger]);
|
|
550
|
+
}, [type, colors, speed, intensity, angle, duration, trigger, shouldAnimate]);
|
|
543
551
|
// Respond to external control in manual mode
|
|
544
552
|
useEffect(() => {
|
|
545
553
|
if (trigger !== "manual")
|
|
@@ -647,6 +655,93 @@ const WeatherFx = React.forwardRef(({ type = "rain", speed = 1, colors = ["brand
|
|
|
647
655
|
isHoveredRef.current = true;
|
|
648
656
|
isEmittingRef.current = true;
|
|
649
657
|
emitStartTimeRef.current = Date.now();
|
|
658
|
+
// Initialize particles if none exist yet
|
|
659
|
+
if (particlesRef.current.length === 0) {
|
|
660
|
+
const canvas = canvasRef.current;
|
|
661
|
+
const container = containerRef.current;
|
|
662
|
+
if (canvas && container) {
|
|
663
|
+
const cw = canvas.width / 2;
|
|
664
|
+
const ch = canvas.height / 2;
|
|
665
|
+
const parsedColors = colors.map((color) => {
|
|
666
|
+
const computedColor = getComputedStyle(container).getPropertyValue(`--${color}`);
|
|
667
|
+
return computedColor || color;
|
|
668
|
+
});
|
|
669
|
+
const angleRad = (angle * Math.PI) / 180;
|
|
670
|
+
const horizontalOffset = Math.abs(Math.tan(angleRad) * ch);
|
|
671
|
+
if (type === "rain") {
|
|
672
|
+
const particles = [];
|
|
673
|
+
for (let i = 0; i < intensity; i++) {
|
|
674
|
+
const spawnWidth = cw + horizontalOffset * 2;
|
|
675
|
+
const spawnX = Math.random() * spawnWidth - horizontalOffset;
|
|
676
|
+
particles.push({
|
|
677
|
+
x: spawnX,
|
|
678
|
+
y: Math.random() * ch - ch,
|
|
679
|
+
length: 10 + Math.random() * 20,
|
|
680
|
+
speed: (2 + Math.random() * 3) * speed,
|
|
681
|
+
color: parsedColors[Math.floor(Math.random() * parsedColors.length)],
|
|
682
|
+
opacity: 0.3 + Math.random() * 0.5,
|
|
683
|
+
thickness: 1 + Math.random() * 1.5,
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
particlesRef.current = particles;
|
|
687
|
+
}
|
|
688
|
+
else if (type === "snow") {
|
|
689
|
+
const particles = [];
|
|
690
|
+
for (let i = 0; i < intensity; i++) {
|
|
691
|
+
const depth = Math.random();
|
|
692
|
+
const size = 2 + depth * 4;
|
|
693
|
+
const spawnWidth = cw + horizontalOffset * 2;
|
|
694
|
+
const spawnX = Math.random() * spawnWidth - horizontalOffset;
|
|
695
|
+
particles.push({
|
|
696
|
+
x: spawnX,
|
|
697
|
+
y: Math.random() * ch - ch,
|
|
698
|
+
size,
|
|
699
|
+
speed: (0.3 + depth * 0.7) * speed,
|
|
700
|
+
color: parsedColors[Math.floor(Math.random() * parsedColors.length)],
|
|
701
|
+
opacity: 0.4 + depth * 0.5,
|
|
702
|
+
swayAmplitude: 20 + Math.random() * 30,
|
|
703
|
+
swaySpeed: 0.5 + Math.random() * 1,
|
|
704
|
+
swayOffset: Math.random() * Math.PI * 2,
|
|
705
|
+
depth,
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
particlesRef.current = particles;
|
|
709
|
+
}
|
|
710
|
+
else if (type === "leaves") {
|
|
711
|
+
const particles = [];
|
|
712
|
+
for (let i = 0; i < intensity; i++) {
|
|
713
|
+
const depth = Math.random();
|
|
714
|
+
const width = 8 + depth * 12;
|
|
715
|
+
const height = width * (0.6 + Math.random() * 0.4);
|
|
716
|
+
const spawnWidth = cw + horizontalOffset * 2;
|
|
717
|
+
const spawnX = Math.random() * spawnWidth - horizontalOffset;
|
|
718
|
+
const colorIndex = Math.floor(Math.random() * parsedColors.length);
|
|
719
|
+
const color1 = parsedColors[colorIndex];
|
|
720
|
+
const color2 = parsedColors[Math.min(colorIndex + 1, parsedColors.length - 1)];
|
|
721
|
+
particles.push({
|
|
722
|
+
x: spawnX,
|
|
723
|
+
y: Math.random() * ch - ch,
|
|
724
|
+
width,
|
|
725
|
+
height,
|
|
726
|
+
speed: (0.4 + depth * 0.8) * speed,
|
|
727
|
+
color1,
|
|
728
|
+
color2,
|
|
729
|
+
opacity: 0.6 + depth * 0.3,
|
|
730
|
+
swayAmplitude: 30 + Math.random() * 50,
|
|
731
|
+
swaySpeed: 0.3 + Math.random() * 0.7,
|
|
732
|
+
swayOffset: Math.random() * Math.PI * 2,
|
|
733
|
+
rotation: Math.random() * Math.PI * 2,
|
|
734
|
+
rotationSpeed: (Math.random() - 0.5) * 0.08,
|
|
735
|
+
rotation3D: Math.random() * Math.PI * 2,
|
|
736
|
+
rotation3DSpeed: (Math.random() - 0.5) * 0.06,
|
|
737
|
+
depth,
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
particlesRef.current = particles;
|
|
741
|
+
}
|
|
742
|
+
// Lightning doesn't need pre-initialization (spawns dynamically)
|
|
743
|
+
}
|
|
744
|
+
}
|
|
650
745
|
}
|
|
651
746
|
};
|
|
652
747
|
const handleMouseLeave = () => {
|