({
mouseForce = 20,
cursorSize = 100,
isViscous = false,
viscous = 30,
iterationsViscous = 32,
iterationsPoisson = 32,
dt = 0.014,
BFECC = true,
resolution = 0.5,
isBounce = false,
colors = defaultColors,
style = {},
className = "",
autoDemo = true,
autoSpeed = 0.5,
autoIntensity = 2.2,
takeoverDuration = 0.25,
autoResumeDelay = 1000,
autoRampDuration = 0.6,
}: LiquidEtherProps)
| 59 | const defaultColors = ["#5227FF", "#FF9FFC", "#B19EEF"]; |
| 60 | |
| 61 | export default function LiquidEther({ |
| 62 | mouseForce = 20, |
| 63 | cursorSize = 100, |
| 64 | isViscous = false, |
| 65 | viscous = 30, |
| 66 | iterationsViscous = 32, |
| 67 | iterationsPoisson = 32, |
| 68 | dt = 0.014, |
| 69 | BFECC = true, |
| 70 | resolution = 0.5, |
| 71 | isBounce = false, |
| 72 | colors = defaultColors, |
| 73 | style = {}, |
| 74 | className = "", |
| 75 | autoDemo = true, |
| 76 | autoSpeed = 0.5, |
| 77 | autoIntensity = 2.2, |
| 78 | takeoverDuration = 0.25, |
| 79 | autoResumeDelay = 1000, |
| 80 | autoRampDuration = 0.6, |
| 81 | }: LiquidEtherProps): React.ReactElement { |
| 82 | const mountRef = useRef<HTMLDivElement | null>(null); |
| 83 | const webglRef = useRef<LiquidEtherWebGL | null>(null); |
| 84 | const resizeObserverRef = useRef<ResizeObserver | null>(null); |
| 85 | const rafRef = useRef<number | null>(null); |
| 86 | const intersectionObserverRef = useRef<IntersectionObserver | null>(null); |
| 87 | const isVisibleRef = useRef<boolean>(true); |
| 88 | const resizeRafRef = useRef<number | null>(null); |
| 89 | |
| 90 | useEffect(() => { |
| 91 | if (!mountRef.current) return; |
| 92 | |
| 93 | function makePaletteTexture(stops: string[]): THREE.DataTexture { |
| 94 | let arr: string[]; |
| 95 | if (Array.isArray(stops) && stops.length > 0) { |
| 96 | arr = stops.length === 1 ? [stops[0], stops[0]] : stops; |
| 97 | } else { |
| 98 | arr = ["#ffffff", "#ffffff"]; |
| 99 | } |
| 100 | const w = arr.length; |
| 101 | const data = new Uint8Array(w * 4); |
| 102 | for (let i = 0; i < w; i++) { |
| 103 | const c = new THREE.Color(arr[i]); |
| 104 | data[i * 4 + 0] = Math.round(c.r * 255); |
| 105 | data[i * 4 + 1] = Math.round(c.g * 255); |
| 106 | data[i * 4 + 2] = Math.round(c.b * 255); |
| 107 | data[i * 4 + 3] = 255; |
| 108 | } |
| 109 | const tex = new THREE.DataTexture(data, w, 1, THREE.RGBAFormat); |
| 110 | tex.magFilter = THREE.LinearFilter; |
| 111 | tex.minFilter = THREE.LinearFilter; |
| 112 | tex.wrapS = THREE.ClampToEdgeWrapping; |
| 113 | tex.wrapT = THREE.ClampToEdgeWrapping; |
| 114 | tex.generateMipmaps = false; |
| 115 | tex.needsUpdate = true; |
| 116 | return tex; |
| 117 | } |
| 118 |
nothing calls this directly
no test coverage detected