From afd0431719d88f5417a0dd05e8ae7cca709f62d2 Mon Sep 17 00:00:00 2001 From: AstralEX1 <119760163+AstralEX1@users.noreply.github.com> Date: Sun, 23 Aug 2026 14:45:33 +0400 Subject: [PATCH] fix(ui): restore Galaxy Pulse icons and frame --- .../common/reactBits/MagicBento.css | 72 +++++ .../common/reactBits/MagicBento.tsx | 245 ++++++++++++++++ .../planets/GalaxyPulsePanel.test.tsx | 36 +++ src/components/planets/GalaxyPulsePanel.tsx | 265 ++++++++++-------- 4 files changed, 497 insertions(+), 121 deletions(-) create mode 100644 src/components/common/reactBits/MagicBento.css create mode 100644 src/components/common/reactBits/MagicBento.tsx diff --git a/src/components/common/reactBits/MagicBento.css b/src/components/common/reactBits/MagicBento.css new file mode 100644 index 0000000..3c21451 --- /dev/null +++ b/src/components/common/reactBits/MagicBento.css @@ -0,0 +1,72 @@ +.magic-bento-frame { + --magic-bento-x: 50%; + --magic-bento-y: 50%; + --magic-bento-glow-opacity: 0; + --magic-bento-glow-soft: 0; + position: relative; + isolation: isolate; + overflow: hidden; + transform-style: preserve-3d; +} + +.magic-bento-frame::before, +.magic-bento-frame::after { + position: absolute; + inset: 0; + border-radius: inherit; + padding: 1px; + pointer-events: none; + content: ""; + -webkit-mask: + linear-gradient(#fff 0 0) content-box, + linear-gradient(#fff 0 0); + -webkit-mask-composite: xor; + mask: + linear-gradient(#fff 0 0) content-box, + linear-gradient(#fff 0 0); + mask-composite: exclude; +} + +.magic-bento-frame::before { + z-index: 20; + background: linear-gradient(110deg, #ef4444 0%, #ec4899 48%, #7c3aed 100%); +} + +.magic-bento-frame.magic-bento-border-glow::after { + z-index: 21; + background: radial-gradient( + var(--magic-bento-radius) circle at var(--magic-bento-x) var(--magic-bento-y), + rgba(var(--magic-bento-glow), var(--magic-bento-glow-opacity)) 0%, + rgba(var(--magic-bento-glow), var(--magic-bento-glow-soft)) 32%, + transparent 70% + ); + transition: opacity 180ms ease; +} + +.magic-bento-frame.magic-bento-border-glow:hover { + box-shadow: 0 0 28px rgba(var(--magic-bento-glow), 0.18); +} + +.magic-bento-particle, +.magic-bento-ripple { + position: absolute; + pointer-events: none; +} + +.magic-bento-particle { + z-index: 15; + width: 4px; + height: 4px; + border-radius: 50%; +} + +.magic-bento-ripple { + z-index: 16; + border-radius: 50%; +} + +@media (prefers-reduced-motion: reduce) { + .magic-bento-frame.magic-bento-border-glow::after { + transition: none; + } +} diff --git a/src/components/common/reactBits/MagicBento.tsx b/src/components/common/reactBits/MagicBento.tsx new file mode 100644 index 0000000..b65df61 --- /dev/null +++ b/src/components/common/reactBits/MagicBento.tsx @@ -0,0 +1,245 @@ +import { gsap } from 'gsap'; +import type { CSSProperties, PropsWithChildren } from 'react'; +import { useEffect, useRef } from 'react'; +import './MagicBento.css'; + +type MagicBentoProps = PropsWithChildren<{ + textAutoHide?: boolean; + enableStars?: boolean; + enableSpotlight?: boolean; + enableBorderGlow?: boolean; + disableAnimations?: boolean; + spotlightRadius?: number; + particleCount?: number; + enableTilt?: boolean; + glowColor?: string; + clickEffect?: boolean; + enableMagnetism?: boolean; + className?: string; + testId?: string; +}>; + +type MagicBentoStyle = CSSProperties & { + '--magic-bento-glow': string; + '--magic-bento-radius': string; +}; + +const DEFAULT_PARTICLE_COUNT = 12; +const DEFAULT_SPOTLIGHT_RADIUS = 300; +const DEFAULT_GLOW_COLOR = '132, 0, 255'; + +function createParticleElement(x: number, y: number, color: string): HTMLSpanElement { + const particle = document.createElement('span'); + particle.className = 'magic-bento-particle'; + particle.style.left = `${x}px`; + particle.style.top = `${y}px`; + particle.style.background = `rgba(${color}, 1)`; + particle.style.boxShadow = `0 0 6px rgba(${color}, 0.6)`; + return particle; +} + +export default function MagicBento({ + children, + className = '', + testId, + enableStars = true, + enableSpotlight = true, + enableBorderGlow = true, + disableAnimations = false, + spotlightRadius = DEFAULT_SPOTLIGHT_RADIUS, + particleCount = DEFAULT_PARTICLE_COUNT, + enableTilt = false, + glowColor = DEFAULT_GLOW_COLOR, + clickEffect = true, + enableMagnetism = true, +}: MagicBentoProps) { + const frameRef = useRef(null); + + useEffect(() => { + const element = frameRef.current; + const reducedMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false; + if (!element || disableAnimations || reducedMotion) return; + + const particles = new Set(); + const particleTimers: ReturnType[] = []; + let isHovered = false; + + const clearParticles = () => { + particleTimers.forEach(clearTimeout); + particleTimers.length = 0; + particles.forEach((particle) => { + gsap.killTweensOf(particle); + particle.remove(); + }); + particles.clear(); + }; + + const animateParticles = () => { + if (!enableStars) return; + + clearParticles(); + const { width, height } = element.getBoundingClientRect(); + for (let index = 0; index < particleCount; index += 1) { + const timer = setTimeout(() => { + if (!isHovered) return; + + const particle = createParticleElement( + Math.random() * width, + Math.random() * height, + glowColor, + ); + element.appendChild(particle); + particles.add(particle); + gsap.fromTo( + particle, + { scale: 0, opacity: 0 }, + { scale: 1, opacity: 1, duration: 0.3, ease: 'back.out(1.7)' }, + ); + gsap.to(particle, { + x: (Math.random() - 0.5) * 80, + y: (Math.random() - 0.5) * 80, + rotation: Math.random() * 360, + duration: 2 + Math.random() * 2, + ease: 'none', + repeat: -1, + yoyo: true, + }); + gsap.to(particle, { + opacity: 0.3, + duration: 1.5, + ease: 'power2.inOut', + repeat: -1, + yoyo: true, + }); + }, index * 70); + particleTimers.push(timer); + } + }; + + const handleMouseEnter = () => { + isHovered = true; + element.style.setProperty('--magic-bento-glow-opacity', enableBorderGlow ? '0.45' : '0'); + element.style.setProperty('--magic-bento-glow-soft', enableBorderGlow ? '0.2' : '0'); + animateParticles(); + }; + + const handleMouseMove = (event: MouseEvent) => { + const rect = element.getBoundingClientRect(); + const x = event.clientX - rect.left; + const y = event.clientY - rect.top; + const centerX = rect.width / 2; + const centerY = rect.height / 2; + + if (enableSpotlight) { + element.style.setProperty('--magic-bento-x', `${(x / rect.width) * 100}%`); + element.style.setProperty('--magic-bento-y', `${(y / rect.height) * 100}%`); + element.style.setProperty('--magic-bento-glow-opacity', enableBorderGlow ? '0.95' : '0'); + element.style.setProperty('--magic-bento-glow-soft', enableBorderGlow ? '0.35' : '0'); + } + + if (enableTilt || enableMagnetism) { + gsap.to(element, { + rotateX: enableTilt ? ((y - centerY) / centerY) * -10 : 0, + rotateY: enableTilt ? ((x - centerX) / centerX) * 10 : 0, + x: enableMagnetism ? (x - centerX) * 0.05 : 0, + y: enableMagnetism ? (y - centerY) * 0.05 : 0, + duration: 0.1, + ease: 'power2.out', + transformPerspective: 1000, + }); + } + }; + + const handleMouseLeave = () => { + isHovered = false; + clearParticles(); + element.style.setProperty('--magic-bento-glow-opacity', '0'); + element.style.setProperty('--magic-bento-glow-soft', '0'); + if (enableTilt || enableMagnetism) { + gsap.to(element, { rotateX: 0, rotateY: 0, x: 0, y: 0, duration: 0.3, ease: 'power2.out' }); + } + }; + + const handleClick = (event: MouseEvent) => { + if (!clickEffect) return; + + const rect = element.getBoundingClientRect(); + const x = event.clientX - rect.left; + const y = event.clientY - rect.top; + const radius = Math.max( + Math.hypot(x, y), + Math.hypot(x - rect.width, y), + Math.hypot(x, y - rect.height), + Math.hypot(x - rect.width, y - rect.height), + ); + const ripple = document.createElement('span'); + ripple.className = 'magic-bento-ripple'; + ripple.style.width = `${radius * 2}px`; + ripple.style.height = `${radius * 2}px`; + ripple.style.left = `${x - radius}px`; + ripple.style.top = `${y - radius}px`; + ripple.style.background = `radial-gradient(circle, rgba(${glowColor}, 0.4) 0%, rgba(${glowColor}, 0.2) 30%, transparent 70%)`; + element.appendChild(ripple); + gsap.fromTo( + ripple, + { scale: 0, opacity: 1 }, + { + scale: 1, + opacity: 0, + duration: 0.8, + ease: 'power2.out', + onComplete: () => ripple.remove(), + }, + ); + }; + + element.addEventListener('mouseenter', handleMouseEnter); + element.addEventListener('mousemove', handleMouseMove); + element.addEventListener('mouseleave', handleMouseLeave); + element.addEventListener('click', handleClick); + + return () => { + isHovered = false; + clearParticles(); + gsap.killTweensOf(element); + element.removeEventListener('mouseenter', handleMouseEnter); + element.removeEventListener('mousemove', handleMouseMove); + element.removeEventListener('mouseleave', handleMouseLeave); + element.removeEventListener('click', handleClick); + }; + }, [ + clickEffect, + disableAnimations, + enableBorderGlow, + enableMagnetism, + enableSpotlight, + enableStars, + enableTilt, + glowColor, + particleCount, + ]); + + const style: MagicBentoStyle = { + '--magic-bento-glow': glowColor, + '--magic-bento-radius': `${spotlightRadius}px`, + }; + + return ( +
+ {children} +
+ ); +} diff --git a/src/components/planets/GalaxyPulsePanel.test.tsx b/src/components/planets/GalaxyPulsePanel.test.tsx index 27c79cd..ca26d36 100644 --- a/src/components/planets/GalaxyPulsePanel.test.tsx +++ b/src/components/planets/GalaxyPulsePanel.test.tsx @@ -15,6 +15,17 @@ const pulse = { ], } as const; +const lowercasePulse = { + drawingId: '151', + settledAt: '2026-08-22T17:00:00.000Z', + slots: [ + { planetType: 'nebula', modifierBps: -2691 }, + { planetType: 'rocky', modifierBps: 2066 }, + { planetType: 'triplex', modifierBps: -1576 }, + { planetType: 'toxic', modifierBps: 4494 }, + ], +} as const; + describe('GalaxyPulsePanel', () => { afterEach(cleanup); @@ -58,6 +69,31 @@ describe('GalaxyPulsePanel', () => { expect(icons[0]).toHaveAttribute('alt', ''); }); + it('loads icons for canonical lowercase planet type ids', () => { + render(); + + const icons = screen.getByRole('tooltip').querySelectorAll('img'); + expect([...icons].map((icon) => icon.getAttribute('src'))).toEqual([ + '/galaxy-pulse/nebula.png', + '/galaxy-pulse/rocky.png', + '/galaxy-pulse/triplex.png', + '/galaxy-pulse/toxic.png', + ]); + }); + + it('uses a red-violet gradient frame for the header and tooltip', () => { + render(); + + const gradientClasses = [ + 'bg-gradient-to-r', + 'from-red-500', + 'via-fuchsia-500', + 'to-violet-600', + ]; + expect(screen.getByTestId('galaxy-pulse-frame')).toHaveClass(...gradientClasses); + expect(screen.getByRole('tooltip')).toHaveClass(...gradientClasses); + }); + it('exposes a detailed tooltip with the pulse explanation and effects', () => { render(); diff --git a/src/components/planets/GalaxyPulsePanel.tsx b/src/components/planets/GalaxyPulsePanel.tsx index a3c3989..d7bdcec 100644 --- a/src/components/planets/GalaxyPulsePanel.tsx +++ b/src/components/planets/GalaxyPulsePanel.tsx @@ -1,3 +1,5 @@ +import MagicBento from '@/components/common/reactBits/MagicBento'; + export type GalaxyPulseSlot = { planetType: string; modifierBps: number; @@ -16,18 +18,22 @@ export type GalaxyPulsePanelProps = { const GALAXY_PULSE_TOOLTIP_ID = 'galaxy-pulse-details'; const PLANET_TYPE_ICONS: Record = { - Nebula: '/galaxy-pulse/nebula.png', - Desert: '/galaxy-pulse/desert.png', - Triplex: '/galaxy-pulse/triplex.png', - Toxic: '/galaxy-pulse/toxic.png', - Void: '/galaxy-pulse/void.png', - Gaia: '/galaxy-pulse/gaia.png', - Volcanic: '/galaxy-pulse/volcanic.png', - 'Gas Giant': '/galaxy-pulse/gas-giant.png', - Rocky: '/galaxy-pulse/rocky.png', - Oceanic: '/galaxy-pulse/oceanic.png', + nebula: '/galaxy-pulse/nebula.png', + desert: '/galaxy-pulse/desert.png', + triplex: '/galaxy-pulse/triplex.png', + toxic: '/galaxy-pulse/toxic.png', + void: '/galaxy-pulse/void.png', + gaia: '/galaxy-pulse/gaia.png', + volcanic: '/galaxy-pulse/volcanic.png', + 'gas-giant': '/galaxy-pulse/gas-giant.png', + rocky: '/galaxy-pulse/rocky.png', + oceanic: '/galaxy-pulse/oceanic.png', }; +function getPlanetTypeIcon(planetType: string): string | undefined { + return PLANET_TYPE_ICONS[planetType.trim().toLowerCase().replace(/\s+/g, '-')]; +} + function formatModifierBps(modifierBps: number): string { const value = Math.abs(modifierBps / 100) .toFixed(2) @@ -57,128 +63,145 @@ export function GalaxyPulsePanel({ pulse }: GalaxyPulsePanelProps) { className="w-full min-w-0 lg:w-fit lg:justify-self-center" >
-
-
-

- GALAXY PULSE -

+ +
+
+

+ GALAXY PULSE +

+ {pulse ? ( + + DRAWING #{pulse.drawingId} + + ) : ( + + No active GALAXY PULSE + + )} +
+ {pulse ? ( - - DRAWING #{pulse.drawingId} - - ) : ( - - No active GALAXY PULSE + - )} + ) : null}
- {pulse ? ( - - ) : null} -
- -