Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/danielitoCode/compose_svelted/llms.txt

Use this file to discover all available pages before exploring further.

Compose Svelted’s motion system is built on two lightweight types: AnimationSpec and ContentTransition. Both are plain objects — no special classes, no hidden state. Factory functions construct them for you, but you can also assemble them by hand when the built-in presets don’t fit your needs.

AnimationSpec

AnimationSpec is used by AnimatedVisibility to describe what happens when content enters or exits the screen.
type AnimationSpec = {
  base: string;     // Tailwind transition utilities (transition-*, duration-[…ms], easing)
  from: string;     // CSS classes applied at the start of the animation
  to: string;       // CSS classes applied one frame later — the browser interpolates between them
  duration: number; // Milliseconds — used to time DOM removal after an exit animation
};
The three class strings map directly to Tailwind utilities. base always contains the transition declaration, from sets the initial state, and to sets the target state. On the next animation frame after mount, Compose Svelted swaps from for to on the live DOM node, triggering the CSS transition.

AnimationSpec factory functions

All six factories are exported from @danielito1996/compose-svelted.

fadeIn

function fadeIn(duration?: number): AnimationSpec
Fades content in by animating opacity from 0 to 1.
ParameterDefault
duration280 ms
Easing: ease-out.

fadeOut

function fadeOut(duration?: number): AnimationSpec
Fades content out by animating opacity from 1 to 0.
ParameterDefault
duration220 ms
Easing: ease-in.

scaleIn

function scaleIn(duration?: number): AnimationSpec
Combines a scale from 0.95 to 1 with an opacity fade-in.
ParameterDefault
duration280 ms
Easing: ease-out. Uses Tailwind’s transition-all.

scaleOut

function scaleOut(duration?: number): AnimationSpec
Combines a scale from 1 to 0.95 with an opacity fade-out.
ParameterDefault
duration220 ms
Easing: ease-in. Uses Tailwind’s transition-all.

slideIn

function slideIn(duration?: number, direction?: 'left' | 'right' | 'up' | 'down'): AnimationSpec
Slides content in from an offset along the specified axis while fading in.
ParameterDefault
duration280 ms
direction"right"
Direction offset mapping:
DirectionTailwind class
"left"-translate-x-4
"right"translate-x-4
"up"-translate-y-4
"down"translate-y-4
Easing: ease-out.

slideOut

function slideOut(duration?: number, direction?: 'left' | 'right' | 'up' | 'down'): AnimationSpec
Slides content out toward an offset along the specified axis while fading out.
ParameterDefault
duration220 ms
direction"right"
Direction offset mapping is identical to slideIn. Easing: ease-in.

Creating a custom AnimationSpec

If none of the built-in presets match your design, construct an AnimationSpec directly using Tailwind utility classes:
import type { AnimationSpec } from '@danielito1996/compose-svelted';

const popIn: AnimationSpec = {
  base: 'transition-all duration-[350ms] ease-[cubic-bezier(0.34,1.56,0.64,1)]',
  from: 'opacity-0 scale-50',
  to: 'opacity-100 scale-100',
  duration: 350
};

const popOut: AnimationSpec = {
  base: 'transition-all duration-[200ms] ease-in',
  from: 'opacity-100 scale-100',
  to: 'opacity-0 scale-50',
  duration: 200
};
Then pass those directly to AnimatedVisibility:
<AnimatedVisibility visible={show} enter={popIn} exit={popOut}>
  <MyComponent />
</AnimatedVisibility>
Make sure the numeric duration field matches the duration expressed in the base class string. Compose Svelted uses duration to time the setTimeout that removes the DOM node after exit — a mismatch will cause a visible flash or premature removal.

ContentTransition

ContentTransition is used by AnimatedContent (and internally by NavHost) to describe a paired enter/exit inline style transition.
type ContentTransition = {
  enter: string;    // Inline CSS string applied when this state is the active one
  exit: string;     // Inline CSS string applied while this state is transitioning out
  duration: number; // Milliseconds — drives both the CSS `transition` property and the swap timer
};
Unlike AnimationSpec, which uses Tailwind classes, ContentTransition uses raw inline CSS strings. The duration is injected directly into the transition shorthand on the container element:
transition: opacity ${duration}ms ease, transform ${duration}ms ease;

ContentTransition factory functions

fade

function fade(duration?: number): ContentTransition
Crossfades between states using opacity only.
ParameterDefault
duration300 ms
// Produced object
{
  enter: 'opacity: 1;',
  exit:  'opacity: 0;',
  duration: 300
}

scaleFade

function scaleFade(): ContentTransition
Combines a subtle scale (0.95 → 1) with an opacity crossfade. Duration is fixed at 220 ms.
// Produced object
{
  enter: 'transform: scale(1); opacity: 1;',
  exit:  'transform: scale(0.95); opacity: 0;',
  duration: 220
}

slideHorizontal

function slideHorizontal(): ContentTransition
Slides the outgoing content to the left (translateX(-100%)) while the incoming content appears at its natural position. Duration is fixed at 300 ms.
// Produced object
{
  enter: 'transform: translateX(0); opacity: 1;',
  exit:  'transform: translateX(-100%); opacity: 0;',
  duration: 300
}

Using ContentTransitions with AnimatedContent

<script>
  import {
    AnimatedContent,
    fade,
    scaleFade,
    slideHorizontal
  } from '@danielito1996/compose-svelted';

  let tab = 'home';
</script>

<!-- Simple opacity crossfade with a custom duration -->
<AnimatedContent targetState={tab} transition={fade(400)}>
  {#if tab === 'home'}
    <HomeTab />
  {:else if tab === 'profile'}
    <ProfileTab />
  {/if}
</AnimatedContent>

Using ContentTransitions with NavHost

NavHost accepts the same ContentTransition type via its transition prop, giving you control over how screen-to-screen navigation is animated:
<script>
  import {
    NavHost,
    scaleFade,
    slideHorizontal
  } from '@danielito1996/compose-svelted';
</script>

<!-- Scale + fade between screens -->
<NavHost transition={scaleFade()}>
  <!-- screen definitions -->
</NavHost>

<!-- Horizontal slide between screens -->
<NavHost transition={slideHorizontal()}>
  <!-- screen definitions -->
</NavHost>

Creating a custom ContentTransition

import type { ContentTransition } from '@danielito1996/compose-svelted';

const flipVertical: ContentTransition = {
  enter: 'transform: rotateX(0deg); opacity: 1;',
  exit:  'transform: rotateX(90deg); opacity: 0;',
  duration: 350
};
<AnimatedContent targetState={currentStep} transition={flipVertical}>
  {#if currentStep === 1}
    <StepOne />
  {:else}
    <StepTwo />
  {/if}
</AnimatedContent>
When using 3D transforms such as rotateX, make sure the parent container has perspective set via a wrapper style. Without it the 3D effect will not be visible.

Quick reference

AnimationSpec defaults

FactoryDefault durationEasing
fadeIn()280 msease-out
fadeOut()220 msease-in
scaleIn()280 msease-out
scaleOut()220 msease-in
slideIn()280 msease-out
slideOut()220 msease-in

ContentTransition defaults

FactoryDefault duration
fade()300 ms
scaleFade()220 ms (fixed)
slideHorizontal()300 ms (fixed)

Build docs developers (and LLMs) love