'use client'; import { useEffect, useRef, useState } from 'react'; import { cn } from '@/lib/utils/cn'; import { PRESETS, PRESET_CATEGORIES } from '@/lib/animate/presets'; import { buildKeyframesOnly } from '@/lib/animate/cssBuilder'; import type { AnimationConfig, AnimationPreset, PresetCategory } from '@/types/animate'; interface Props { onSelect: (config: AnimationConfig) => void; } function PresetCard({ preset, onSelect }: { preset: AnimationPreset; onSelect: () => void }) { const styleRef = useRef(null); const animName = `preview-${preset.id}`; const thumbDuration = Math.min(preset.config.duration, 1200); useEffect(() => { const renamedConfig = { ...preset.config, name: animName }; if (!styleRef.current) { styleRef.current = document.createElement('style'); document.head.appendChild(styleRef.current); } styleRef.current.textContent = buildKeyframesOnly(renamedConfig); return () => { styleRef.current?.remove(); styleRef.current = null; }; // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return ( ); } export function PresetLibrary({ onSelect }: Props) { const [category, setCategory] = useState(PRESET_CATEGORIES[0]); return (
Presets
{PRESET_CATEGORIES.map((cat) => ( ))}
{PRESETS.filter((p) => p.category === category).map((preset) => ( onSelect(preset.config)} /> ))}
); }