| 1 |
import { useMemo } from '@wordpress/element'; |
| 2 |
import { colord } from 'colord'; |
| 3 |
import { motion, useReducedMotion } from 'framer-motion'; |
| 4 |
|
| 5 |
export const ViewportPulse = () => { |
| 6 |
const shouldReduceMotion = useReducedMotion(); |
| 7 |
const bannerMain = useMemo(() => { |
| 8 |
return getComputedStyle(document.documentElement) |
| 9 |
.getPropertyValue('--ext-banner-main') |
| 10 |
.trim(); |
| 11 |
}, []); |
| 12 |
|
| 13 |
const bannerMainWashed = useMemo(() => { |
| 14 |
return colord(bannerMain) |
| 15 |
.desaturate(0.3) |
| 16 |
.lighten(0.4) |
| 17 |
.alpha(0.2) |
| 18 |
.toRgbString(); |
| 19 |
}, [bannerMain]); |
| 20 |
|
| 21 |
const isLight = useMemo(() => colord(bannerMain).isLight(), [bannerMain]); |
| 22 |
|
| 23 |
const designMain = useMemo(() => { |
| 24 |
return getComputedStyle(document.documentElement) |
| 25 |
.getPropertyValue('--ext-design-main') |
| 26 |
.trim(); |
| 27 |
}, []); |
| 28 |
|
| 29 |
const mainColorLike = useMemo(() => { |
| 30 |
return colord(designMain).desaturate(0.3).alpha(0.2).toRgbString(); |
| 31 |
}, [designMain]); |
| 32 |
|
| 33 |
if (shouldReduceMotion) return null; |
| 34 |
|
| 35 |
const colorToUse = isLight ? mainColorLike : bannerMainWashed; |
| 36 |
return ( |
| 37 |
<motion.div |
| 38 |
className="absolute inset-0" |
| 39 |
style={{ |
| 40 |
background: `radial-gradient(ellipse at center, transparent 70%, ${colorToUse} 100%)`, |
| 41 |
}} |
| 42 |
animate={{ opacity: [0, 1, 0] }} |
| 43 |
transition={{ |
| 44 |
duration: 2.5, |
| 45 |
repeatDelay: 4, |
| 46 |
repeat: Infinity, |
| 47 |
ease: 'linear', |
| 48 |
}} |
| 49 |
/> |
| 50 |
); |
| 51 |
}; |
| 52 |
|