PluginProbe
Extendify / 3.1.5
Extendify v3.1.5
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / AutoLaunch / components / MovingGradients.jsx

MovingGradients.jsx in Extendify 3.1.5, at src/AutoLaunch/components/MovingGradients.jsx

68 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useMemo } from '@wordpress/element';
2 import { colord } from 'colord';
3 import { motion, useReducedMotion, useTime, useTransform } from 'framer-motion';
4
5 export const MovingGradient = () => {
6 const time = useTime();
7 const shouldReduceMotion = useReducedMotion();
8
9 const bannerMain = useMemo(() => {
10 return getComputedStyle(document.documentElement)
11 .getPropertyValue('--ext-banner-main')
12 .trim();
13 }, []);
14
15 const bannerMainWashed = useMemo(() => {
16 return colord(bannerMain)
17 .desaturate(0.3)
18 .lighten(0.4)
19 .alpha(0.25)
20 .toRgbString();
21 }, [bannerMain]);
22
23 const isLight = useMemo(() => colord(bannerMain).isLight(), [bannerMain]);
24
25 const designMain = useMemo(() => {
26 return getComputedStyle(document.documentElement)
27 .getPropertyValue('--ext-design-main')
28 .trim();
29 }, []);
30
31 const mainColorLike = useMemo(() => {
32 return colord(designMain).desaturate(0.3).alpha(0.25).toRgbString();
33 }, [designMain]);
34
35 // stable per-mount random start, 0..1
36 const phase = useMemo(() => Math.random(), []);
37 const t = useTransform(time, (ms) => (ms / 24000 + phase) % 1);
38
39 const x = useTransform(t, (v) => Math.sin(v * Math.PI * 2) * 180);
40 const y = useTransform(t, (v) => Math.cos(v * Math.PI * 2) * 180);
41
42 if (shouldReduceMotion) return null;
43
44 if (isLight) {
45 return (
46 <motion.div
47 style={{
48 background: `radial-gradient(circle at center, ${mainColorLike}, transparent 40%)`,
49 x,
50 y,
51 }}
52 className="pointer-events-none absolute inset-0 h-full w-full scale-200"
53 />
54 );
55 }
56
57 return (
58 <motion.div
59 style={{
60 background: `radial-gradient(circle at center, ${bannerMainWashed}, transparent 40%)`,
61 x,
62 y,
63 }}
64 className="pointer-events-none absolute inset-0 h-full w-full scale-200"
65 />
66 );
67 };
68