vael-ui v0.5.7

Your own engine

By default, vael-ui plays motion itself with CSS transitions and the Web Animations API, so transform and opacity run off the main thread. A style's engine plays overlay parts, list items and your own targets through a library you choose instead, with the same values and timing. States, swaps and linked elements always use the built-in engine.

Side by side

Three popovers with the same values, each inside its own ConfigProvider. Open them together to compare.

Web Animations

GSAP

motion

Writing an adapter

An engine receives the element, the start and end values, and the timing in seconds, plus the spring behind it when there is one. Return what your library returns. vael-ui waits for it, and stops it if the animation is interrupted.

import { gsap } from 'gsap'
import type { MotionEngine } from 'vael-ui/motion'

// The engine receives the element, its values and the timing in seconds; return the tween.
export const gsapEngine: MotionEngine = (el, from, to, { duration, delay }) =>
  gsap.fromTo(el, from, { ...to, duration, delay, ease: 'power3.out' })
import { animate } from 'motion'
import type { MotionEngine } from 'vael-ui/motion'

// The spring behind vael-ui's timing, when there is one, in motion's own terms.
export const motionEngine: MotionEngine = (el, from, to, { duration, delay, spring }) =>
  animate(
    el,
    Object.fromEntries(Object.keys(to).map((key) => [key, [from[key], to[key]]])),
    spring
      ? {
          type: 'spring',
          visualDuration: spring.response,
          bounce: Math.max(0, 1 - (spring.damping ?? 1)),
          delay,
        }
      : { duration, delay },
  )

Switching engines app-wide

Put the adapter in the ConfigProvider at the root, and every component inside uses it. A component's own hooks still take priority.

<script setup lang="ts">
import { ConfigProvider } from 'vael-ui'
import { gsapEngine } from './gsapEngine'
</script>

<template>
  <ConfigProvider :motion="{ version: 1, engine: gsapEngine }">
    <RouterView />
  </ConfigProvider>
</template>