Skip to content

Instantly share code, notes, and snippets.

@faraazahmad
Created September 8, 2025 07:36
Show Gist options
  • Select an option

  • Save faraazahmad/48c0dd68700c554765d1cd79505247e9 to your computer and use it in GitHub Desktop.

Select an option

Save faraazahmad/48c0dd68700c554765d1cd79505247e9 to your computer and use it in GitHub Desktop.

User

Use similar_functions tool to get all functions that handle animations and transitions.

Assistant

I'll use the similar_functions tool to find all functions that handle animations and transitions in the project.

Tool Call: Run MCP tool similar_functions Status: Completed

Found 19 similar functions:

  1. slide
    • Path: /packages/svelte/src/transition/index.js:108-150
    • Summary: Here's a summary of the slide function:

The function creates a sliding transition animation for DOM elements. It accepts a node element and optional parameters including delay, duration, easing function, and axis direction ('x' or 'y'). The function calculates various CSS properties (height/width, padding, margin, and border) and returns a transition configuration object that gradually animates these properties to create a smooth sliding effect. It includes a development warning for potentially incompatible display values.

Default parameters:

  • delay: 0
  • duration: 400ms
  • easing: cubic_out
  • axis: 'y'
  1. flip
    • Path: /packages/svelte/src/animate/index.js:13-58
    • Summary: Here's a summary of the flip function:

The function implements the FLIP (First, Last, Invert, Play) animation technique to smoothly animate an element between two positions. It takes a DOM element, initial and final position data (as DOMRect objects), and optional animation parameters. The function calculates the necessary transforms to create a smooth transition, accounting for transform origins, parent transforms, and zoom levels. It returns an animation configuration object with delay, duration, easing, and a CSS transform function that handles the actual animation interpolation.

Key features:

  • Supports custom delay, duration, and easing
  • Handles transform origins and existing transforms
  • Accounts for zoom levels and parent transforms
  • Returns a configuration compatible with animation systems
  1. fade
    • Path: /packages/svelte/src/transition/index.js:62-70
    • Summary: Here's a summary of the fade function:

The fade function creates a transition animation that smoothly changes an element's opacity. It takes an HTML element and optional parameters (delay, duration, and easing function) as input. The function calculates the opacity transition based on the element's current opacity value and returns a configuration object used for the animation. This is commonly used for fade-in and fade-out effects in user interfaces.

Default values:

  • delay: 0ms
  • duration: 400ms
  • easing: linear function
  1. animate
    • Path: /packages/svelte/src/internal/client/dom/elements/transitions.js:321-477
    • Summary: Here's a summary of the animate function:

This function handles element animations with support for both intro and outro transitions. It accepts:

  • An HTML element to animate
  • Animation configuration (or a function that returns config)
  • A counterpart animation (for bidirectional transitions)
  • A target value (1 for intro, 0 for outro)
  • A completion callback

Key features:

  • Supports deferred transitions through function-based configuration
  • Handles CSS keyframe animations
  • Manages animation timing, delays, and easing
  • Provides tick callbacks for custom animation logic
  • Includes abort, deactivate, and reset capabilities
  • Handles bidirectional transitions between states
  • Works around browser-specific issues (e.g., Safari overflow bug)

The function returns an Animation object with methods to control the animation's lifecycle.

  1. scale
    • Path: /packages/svelte/src/transition/index.js:159-177
    • Summary: Here's a summary for the scale function:

The scale function creates a transition animation that simultaneously adjusts an element's scale and opacity. It accepts an HTML element and optional parameters for customizing the animation (delay, duration, easing, start scale, and start opacity). The function calculates the transition from the provided starting values to the element's default values (for 'in' animations) or vice versa (for 'out' animations), returning a configuration object that defines how the animation should be executed.

Parameters:

  • node: The DOM element to animate
  • params: Optional configuration object with animation parameters
    • delay: Animation delay (default: 0)
    • duration: Animation duration (default: 400)
    • easing: Easing function (default: cubic_out)
    • start: Starting scale value (default: 0)
    • opacity: Starting opacity value (default: 0)

Returns: A transition configuration object containing delay, duration, easing, and a CSS transform function.

  1. fly
    • Path: /packages/svelte/src/transition/index.js:79-97
    • Summary: Here's a summary for the fly function:

The fly function creates a transition animation that moves an element along x and y coordinates while adjusting its opacity. It accepts a DOM element and optional parameters for delay, duration, easing function, x/y coordinates, and opacity. The function returns a transition configuration object that defines how the element should animate between its starting and ending positions, with customizable timing and motion effects.

Default values:

  • delay: 0ms
  • duration: 400ms
  • easing: cubic-out
  • x: 0
  • y: 0
  • opacity: 0
  1. animation
    • Path: /packages/svelte/src/internal/client/dom/elements/transitions.js:83-171
    • Summary: Here's a summary of the animation function:

This function manages animations for elements within keyed {#each} blocks in Svelte. It creates or updates an animation manager that handles element transitions during DOM reconciliation. The manager tracks element positions, applies animations when elements move, and handles temporary style fixes to ensure smooth animations. It includes methods to:

  • Measure element positions
  • Apply animations based on position changes
  • Fix element positions during transitions
  • Restore original element styles after animations

The function takes three parameters:

  • element: The DOM element to animate
  • get_fn: A function that returns animation configuration
  • get_params: An optional function for additional animation parameters
  1. pause_effect
    • Path: /packages/svelte/src/internal/client/reactivity/effects.js:527-537
    • Summary: Here's a summary for the pause_effect function:

The function handles the graceful pausing of block effects, particularly during transitions. Instead of immediate destruction, it:

  1. Pauses the effect and its child elements
  2. Manages any outro transitions
  3. Destroys the effect only after transitions complete
  4. Executes an optional callback

This approach ensures smooth visual transitions while maintaining DOM integrity.

  1. crossfade
    • Path: /packages/svelte/src/transition/index.js:233-300
    • Summary: Here's a summary of the crossfade function:

The crossfade function creates a pair of transition functions (send and receive) for animating elements between different states. It's particularly useful for handling element transitions in UI frameworks like Svelte.

Key features:

  • Creates coordinated transitions between elements using matching keys
  • Handles both position transformation and fade effects
  • Supports custom duration, delay, and easing
  • Provides fallback transition for unmatched elements
  • Uses element bounding rectangles to calculate transition paths
  • Maintains internal maps to track elements being sent and received

The function returns a tuple of two transition functions: one for sending elements and one for receiving them. Each transition function handles the animation of elements between their original and target positions while managing their opacity.

  1. run_out_transitions
  • Path: /packages/svelte/src/internal/client/reactivity/effects.js:543-553
  • Summary: Here's a summary for the run_out_transitions function:

This function executes a series of transition "out" animations and runs a callback function when all transitions are complete. It takes an array of transition managers and a callback function as parameters. If there are transitions to run, it executes each transition's "out" method and decrements a counter, calling the callback once all transitions finish. If there are no transitions, it immediately executes the callback function.

  1. bounceInOut
  • Path: /packages/svelte/src/easing/index.js:67-69
  • Summary: Here's a summary for the bounceInOut function:

Creates a bounce easing effect that starts slow, speeds up, then slows down again (both in and out). Takes a time parameter t between 0 and 1, and returns a transformed value that creates a bouncing animation effect. The function combines both bounce-in and bounce-out effects, splitting the animation at the midpoint (t=0.5).

  1. tweened
  • Path: /packages/svelte/src/motion/tweened.js:90-160
  • Summary: Here's a summary of the tweened function:

The tweened function creates a special Svelte store that enables smooth transitions between values over time. It takes an initial value and optional configuration defaults as parameters. The function returns an object with three methods:

  • set: Updates the store value with animated transitions
  • update: Modifies the value using a callback function
  • subscribe: Subscribes to store changes

The animation behavior can be customized with options like:

  • delay: Time before animation starts
  • duration: Length of the animation
  • easing: Easing function for the animation
  • interpolate: Function to interpolate between values

Note: This function is deprecated in favor of using the Tween API from svelte/motion.

  1. blur
  • Path: /packages/svelte/src/transition/index.js:38-53
  • Summary: Here's a summary for the blur function:

A transition function that creates a blur effect animation by simultaneously adjusting an element's blur filter and opacity. It accepts an element and optional parameters (delay, duration, easing, blur amount, and opacity level) to customize the animation. Returns a transition configuration object compatible with Svelte's transition system.

  1. AnimateDirective
  • Path: /packages/svelte/src/compiler/phases/3-transform/client/visitors/AnimateDirective.js:11-28
  • Summary: Here's a summary for the AnimateDirective function:
/**
 * Processes an animation directive by creating and pushing an animation call to the component's after_update lifecycle.
 * The function handles both cases where the animation expression is present or null, and ensures the animation is
 * applied after bind:this operations.
 * 
 * @param {AST.AnimateDirective} node - The animation directive AST node
 * @param {ComponentContext} context - The component compilation context
 */

This summary captures the main purpose of the function: handling animation directives in a component's compilation process, and its key behaviors of processing the animation expression and scheduling the animation in the component's lifecycle.

  1. draw
  • Path: /packages/svelte/src/transition/index.js:186-210
  • Summary: Here's a summary for the draw function:

The draw function creates an SVG stroke animation that reveals or hides paths like a snake moving through a tube. It takes an SVG element (that must have a getTotalLength method) and optional parameters for customizing the animation (delay, speed, duration, and easing). The function calculates the appropriate stroke length, adjusts for stroke line caps, and returns a transition configuration object with CSS properties for the animation effect.

Key features:

  • Supports both "in" and "out" transitions
  • Works with SVG elements like <path> and <polyline>
  • Allows customization of animation timing and easing
  • Automatically adjusts for stroke line cap styles
  1. tick
  • Path: /packages/svelte/tests/animation-helpers.js:26-35
  • Summary: Here's a summary for the tick function:

This function handles animation frame updates by processing registered animations and tick callbacks. It takes a timestamp parameter, updates a global time reference, performs a synchronous flush, and then executes all registered animation updates and tick callbacks with the current time.

Parameters:

  • time (number): The current timestamp for this animation frame
  1. tick_spring
  • Path: /packages/svelte/src/motion/spring.js:23-57
  • Summary: Here's a summary for the tick_spring function:
/**
 * Calculates the next value in a spring animation based on physics principles.
 * Handles numeric values, dates, arrays, and objects. For numbers and dates,
 * applies spring physics (stiffness, damping, mass) to animate between values.
 * Recursively processes arrays and objects by applying the spring calculation
 * to each element/property.
 *
 * @template T
 * @param {TickContext} ctx - Animation context containing physics parameters
 * @param {T} last_value - Previous value in the animation
 * @param {T} current_value - Current value in the animation
 * @param {T} target_value - Target value to animate towards
 * @returns {T} The next value in the spring animation sequence
 * @throws {Error} If the value type cannot be animated with springs
 */

This summary captures the main purpose of the function, its handling of different data types, and the physics-based animation approach it uses.

  1. pause_effects
  • Path: /packages/svelte/src/internal/client/dom/blocks/each.js:71-103
  • Summary: Here's a summary of the pause_effects function:

This function coordinates the pausing and cleanup of multiple effects in an each block. It handles two scenarios:

  1. For controlled anchors (elements inside a single DOM element), it performs a fast-path cleanup by clearing the parent element's content.
  2. For uncontrolled cases, it manages transitions and systematically removes items from the map while maintaining proper linking.

Parameters:

  • state: EachState object
  • items: Array of EachItem objects
  • controlled_anchor: Optional Node reference
  • items_map: Map storing EachItem objects

The function ensures proper cleanup of effects while handling transitions and DOM updates.

  1. bounceIn
  • Path: /packages/svelte/src/easing/index.js:75-77
  • Summary: Here's a summary for the bounceIn function:

The bounceIn function is an easing function that creates a bouncing effect at the beginning of the animation. It takes a single parameter t (time or progress value between 0 and 1) and returns a transformed value. The function works by inverting the bounceOut effect, creating a bounce that starts strong and gradually settles.

Note: This function depends on a bounceOut function that should be defined elsewhere in the codebase.Total tokens used while classifying functions: 9140

Assistant

I found 19 functions that handle animations and transitions in the Svelte codebase! Here's a breakdown of the key categories:

Core Transition Functions

  • slide - Creates sliding animations with configurable axis, duration, and easing
  • fade - Handles opacity transitions for fade-in/fade-out effects
  • scale - Combines scale and opacity animations
  • fly - Moves elements along x/y coordinates with opacity changes
  • blur - Creates blur effects with opacity transitions
  • draw - SVG stroke animations that reveal/hide paths progressively

Advanced Animation Systems

  • flip - Implements FLIP (First, Last, Invert, Play) animation technique for position transitions
  • crossfade - Creates coordinated transitions between elements using matching keys
  • animate - Comprehensive animation handler supporting intro/outro transitions with keyframes
  • animation - Manages animations for keyed {#each} blocks during DOM reconciliation

Motion and Spring Physics

  • tweened - Creates smooth value transitions over time (deprecated in favor of newer APIs)
  • tick_spring - Physics-based spring animations with stiffness, damping, and mass
  • tick - Handles animation frame updates and timing

Easing Functions

  • bounceIn, bounceInOut - Bounce easing effects for natural-feeling animations

Lifecycle and Control Functions

  • pause_effect - Gracefully pauses effects during transitions
  • run_out_transitions - Executes multiple "out" transitions and handles completion
  • pause_effects - Coordinates pausing and cleanup of multiple effects
  • AnimateDirective - Handles animation directives in component compilation

These functions collectively provide Svelte's comprehensive animation and transition system, covering everything from simple CSS property animations to complex physics-based motion and coordinated element transitions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment