'use client'; import React, { forwardRef } from 'react'; import { cn } from '../common'; import type { AnimationTrigger } from './types'; import { mergeRefs, useAnimationTrigger, usePixelAnimations } from './_internal/animation-hooks'; /* ───────────────────────────────────────────────────────────────────────── PixelGlitch — three-layer glitch effect (R/C ghost layers + main) with clip-path slices and color separation. ───────────────────────────────────────────────────────────────────────── */ export interface PixelGlitchProps { /** Content to glitch. */ children: React.ReactNode; /** Length of one full glitch loop in milliseconds. Default `3000`. */ duration?: number; /** Maximum horizontal displacement (pixels) of the ghost layers. Default `4`. */ intensity?: number; /** When the animation should play. Default `'mount'`. */ trigger?: AnimationTrigger; /** Fires after the final iteration. */ onComplete?: () => void; /** Extra class names applied to the wrapping `
`. */ className?: string; } export const PixelGlitch = forwardRef(function PixelGlitch( { children, duration = 3000, intensity = 4, trigger = 'mount', onComplete, className, }, forwardedRef, ) { usePixelAnimations(); const { ref, active, handlers, handleAnimEnd } = useAnimationTrigger(trigger, onComplete); const cssVars = { ['--pxl-glitch-x' as string]: `${intensity}px` }; return (
{/* Ghost layer R — shifts left, fires on different clip zones */} {active && (
{children}
)} {/* Ghost layer C — shifts right, fires on offset clip zones */} {active && (
{children}
)} {/* Main layer */}
{children}
); }); PixelGlitch.displayName = 'PixelGlitch';