/** * MetonaToast Animations — 动画管理 * @module animations * @version 0.2.0 */ import { ANIMATIONS } from './constants.js'; import type { AnimationConfig, AnimationUtils } from './types.js'; // 动画缓存 const animationMap: Map = new Map(); // 注册默认动画 Object.entries(ANIMATIONS).forEach(([name, config]) => { animationMap.set(name, { name, enter: config.enter, leave: config.leave, duration: config.duration, easing: config.easing, }); }); /** * 动画工具函数 */ export const animationUtils: AnimationUtils = { register(name: string, config: Partial): void { animationMap.set(name, { name, enter: config.enter || {}, leave: config.leave || {}, duration: config.duration || 300, easing: config.easing || 'cubic-bezier(0.4, 0, 0.2, 1)', }); }, unregister(name: string): void { animationMap.delete(name); }, get(name: string): AnimationConfig | null { return animationMap.get(name) || null; }, getAnimationNames(): string[] { return Array.from(animationMap.keys()); }, getActiveCount(): number { return animationMap.size; }, cancelAll(): void { // CSS动画由浏览器原生管理,无需手动取消 }, reset(): void { animationMap.clear(); Object.entries(ANIMATIONS).forEach(([name, config]) => { animationMap.set(name, { name, enter: config.enter, leave: config.leave, duration: config.duration, easing: config.easing, }); }); }, destroy(): void { animationMap.clear(); }, }; /** * 动画预设(占位,兼容旧API) */ export const animationPresets: Record = {}; /** * 创建自定义动画配置 */ export const createAnimation = (config: Partial): AnimationConfig => ({ enter: config.enter || {}, leave: config.leave || {}, duration: config.duration || 300, easing: config.easing || 'cubic-bezier(0.4, 0, 0.2, 1)', });