All files / src/animations advanced.ts

100% Statements 383/383
100% Branches 13/13
100% Functions 13/13
100% Lines 383/383

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 3841x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1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-linked animations
 * - Advanced stagger patterns
 * - 3D transforms
 * - Spring physics
 * - Gesture animations
 */
 
import { Variants, Transition } from 'framer-motion';
import { easing, transitions } from './transitions';
 
// =============================================================================
// PARALLAX ANIMATIONS
// =============================================================================
 
/**
 * Create a parallax scroll effect
 *
 * @param speed - Speed multiplier (1 = normal, 0.5 = slower, 2 = faster)
 * @param direction - Direction of parallax ('up' | 'down' | 'left' | 'right')
 */
export function createParallax(speed: number = 0.5, direction: 'up' | 'down' | 'left' | 'right' = 'up') {
  const transform = {
    up: (progress: number) => `translateY(${progress * speed * -100}px)`,
    down: (progress: number) => `translateY(${progress * speed * 100}px)`,
    left: (progress: number) => `translateX(${progress * speed * -100}px)`,
    right: (progress: number) => `translateX(${progress * speed * 100}px)`};
 
  return transform[direction];
}
 
/**
 * Parallax variants for different layers
 */
export const parallaxVariants = {
  background: {
    initial: { y: -50, opacity: 0 },
    animate: (custom: number) => ({
      y: 0,
      opacity: 1,
      transition: { duration: 0.8, delay: custom * 0.1 }})},
  foreground: {
    initial: { y: 50, opacity: 0 },
    animate: (custom: number) => ({
      y: 0,
      opacity: 1,
      transition: { duration: 0.8, delay: custom * 0.1 }})}};
 
// =============================================================================
// ADVANCED STAGGER PATTERNS
// =============================================================================
 
/**
 * Grid stagger animation
 * Animates items in a grid pattern from center outward
 */
export const gridStagger: Variants = {
  initial: {},
  animate: {
    transition: {
      staggerChildren: 0.05,
      delayChildren: 0.1}}};
 
export const gridItem: Variants = {
  initial: { opacity: 0, scale: 0.8 },
  animate: {
    opacity: 1,
    scale: 1,
    transition: {
      duration: 0.4,
      ease: easing.easeOut}}};
 
/**
 * Wave stagger animation
 * Creates a wave effect across items
 */
export const waveStagger: Variants = {
  initial: {},
  animate: {
    transition: {
      staggerChildren: 0.08,
      staggerDirection: 1}}};
 
export const waveItem: Variants = {
  initial: { y: 20, opacity: 0 },
  animate: {
    y: 0,
    opacity: 1,
    transition: {
      type: 'spring',
      stiffness: 500,
      damping: 30}}};
 
/**
 * Spiral stagger animation
 * Items animate in a spiral pattern
 */
export function createSpiralStagger() {
  return {
    initial: {},
    animate: {
      transition: {
        delayChildren: 0.1,
        staggerChildren: 0.05}}};
}
 
// =============================================================================
// 3D TRANSFORM ANIMATIONS
// =============================================================================
 
/**
 * 3D flip animation
 */
export const flip3D: Variants = {
  initial: {
    rotateY: -90,
    opacity: 0},
  animate: {
    rotateY: 0,
    opacity: 1,
    transition: {
      duration: 0.6,
      ease: easing.easeOut}},
  exit: {
    rotateY: 90,
    opacity: 0,
    transition: {
      duration: 0.4,
      ease: easing.easeIn}}};
 
/**
 * 3D cube rotation
 */
export const cube3D: Variants = {
  initial: {
    rotateX: -45,
    rotateY: -45,
    opacity: 0,
    scale: 0.8},
  animate: {
    rotateX: 0,
    rotateY: 0,
    opacity: 1,
    scale: 1,
    transition: {
      duration: 0.8,
      ease: easing.easeOut}}};
 
/**
 * Perspective tilt effect
 */
export const tilt3D = {
  initial: { rotateX: 0, rotateY: 0 },
  animate: (coords: { x: number; y: number }) => ({
    rotateX: coords.y * 0.1,
    rotateY: coords.x * 0.1,
    transition: transitions.fast})};
 
// =============================================================================
// SPRING PHYSICS ANIMATIONS
// =============================================================================
 
/**
 * Bouncy spring animation
 */
export const springBounce: Variants = {
  initial: { scale: 0, opacity: 0 },
  animate: {
    scale: 1,
    opacity: 1,
    transition: {
      type: 'spring',
      stiffness: 500,
      damping: 15,
      mass: 1}}};
 
/**
 * Elastic spring animation
 */
export const springElastic: Variants = {
  initial: { scale: 0, rotate: -180 },
  animate: {
    scale: 1,
    rotate: 0,
    transition: {
      type: 'spring',
      stiffness: 300,
      damping: 10,
      mass: 0.8}}};
 
/**
 * Wobbly spring animation
 */
export const springWobble: Variants = {
  initial: { x: -100, opacity: 0 },
  animate: {
    x: 0,
    opacity: 1,
    transition: {
      type: 'spring',
      stiffness: 200,
      damping: 8,
      mass: 1.5}}};
 
// =============================================================================
// GESTURE ANIMATIONS
// =============================================================================
 
/**
 * Drag gesture configuration
 */
export const dragConstraints = {
  top: 0,
  left: 0,
  right: 0,
  bottom: 0};
 
/**
 * Swipe animation variants
 */
export const swipeVariants: Variants = {
  initial: { x: 0 },
  swipeLeft: {
    x: -300,
    opacity: 0,
    transition: { duration: 0.3 }},
  swipeRight: {
    x: 300,
    opacity: 0,
    transition: { duration: 0.3 }}};
 
/**
 * Magnetic hover effect
 */
export const magnetic = {
  rest: { x: 0, y: 0 },
  hover: (coords: { x: number; y: number }) => ({
    x: coords.x * 0.3,
    y: coords.y * 0.3,
    transition: transitions.fast})};
 
// =============================================================================
// SCROLL-LINKED ANIMATIONS
// =============================================================================
 
/**
 * Reveal on scroll with different directions
 */
export function createScrollReveal(direction: 'up' | 'down' | 'left' | 'right' = 'up', distance: number = 50): Variants {
  const directions = {
    up: { y: distance },
    down: { y: -distance },
    left: { x: distance },
    right: { x: -distance }};
 
  return {
    initial: {
      ...directions[direction],
      opacity: 0},
    animate: {
      x: 0,
      y: 0,
      opacity: 1,
      transition: {
        duration: 0.6,
        ease: easing.easeOut}}};
}
 
/**
 * Scale reveal on scroll
 */
export const scaleReveal: Variants = {
  initial: {
    scale: 0.8,
    opacity: 0},
  animate: {
    scale: 1,
    opacity: 1,
    transition: {
      duration: 0.5,
      ease: easing.easeOut}}};
 
/**
 * Rotate reveal on scroll
 */
export const rotateReveal: Variants = {
  initial: {
    rotate: -10,
    scale: 0.95,
    opacity: 0},
  animate: {
    rotate: 0,
    scale: 1,
    opacity: 1,
    transition: {
      duration: 0.6,
      ease: easing.easeOut}}};
 
// =============================================================================
// MORPHING ANIMATIONS
// =============================================================================
 
/**
 * Morph between shapes
 */
export const morphVariants: Variants = {
  circle: {
    borderRadius: '50%',
    transition: transitions.base},
  square: {
    borderRadius: '0%',
    transition: transitions.base},
  rounded: {
    borderRadius: '20%',
    transition: transitions.base}};
 
/**
 * Text reveal animation
 */
export const textReveal: Variants = {
  initial: {
    opacity: 0,
    y: 20},
  animate: (i: number) => ({
    opacity: 1,
    y: 0,
    transition: {
      delay: i * 0.05,
      duration: 0.4}})};
 
/**
 * Number counter animation
 */
export function createCounterAnimation(from: number, to: number, duration: number = 2): Transition {
  return {
    duration,
    ease: 'easeOut'};
}
 
// =============================================================================
// LOADING ANIMATIONS
// =============================================================================
 
/**
 * Pulse animation for loading states
 */
export const pulse: Variants = {
  initial: { scale: 1, opacity: 1 },
  animate: {
    scale: [1, 1.05, 1],
    opacity: [1, 0.8, 1],
    transition: {
      duration: 1.5,
      repeat: Infinity,
      ease: 'easeInOut'}}};
 
/**
 * Shimmer loading effect
 */
export const shimmer: Variants = {
  initial: { x: '-100%' },
  animate: {
    x: '100%',
    transition: {
      duration: 1.5,
      repeat: Infinity,
      ease: 'linear'}}};
 
/**
 * Skeleton loading animation
 */
export const skeleton: Variants = {
  initial: { opacity: 0.3 },
  animate: {
    opacity: [0.3, 0.5, 0.3],
    transition: {
      duration: 1.5,
      repeat: Infinity,
      ease: 'easeInOut'}}};