Flourish UI Library
Flourish is a lightweight, modular JavaScript library for web UIs (React/Vue/Vanilla JS compatible) that adds delightful micro-animations and effects. It prioritizes user delight through subtle, joyful interactions while strictly enforcing performance budgets (target: <5% CPU on mid-range devices), accessibility (WCAG 2.2 AA compliant), and granular controls for toggling.
Core Principles
- Delight: Human-centered animations (e.g., elastic bounces, subtle glows) using cubic-bezier easing for natural motion. Duration: 100-300ms max.
- CPU Budget:
- Global animation queue limits concurrent animations to 3.
- GPU-accelerated (transform/opacity only; no layout thrashing).
- Device-aware: Detects low-power mode via Battery API/PerformanceObserver; reduces to 60% intensity.
- IntersectionObserver: Animate only visible elements.
- Accessibility:
- Respects
prefers-reduced-motion: reduce/no-preference.
- Keyboard/screen reader friendly: No motion on focus; ARIA live regions for dynamic flourishes.
- High-contrast mode support via CSS vars.
- Controls:
- Global toggle (user/dev).
- Per-flourish opt-in.
- Persistent via localStorage.
Architecture
Flourish uses a central AnimationManager singleton for orchestration:
AnimationManager
├── Queue (FIFO, max 3 items, auto-prioritize hovers > transitions)
├── Scheduler (requestAnimationFrame + throttle)
├── Detector (ResizeObserver, IntersectionObserver, MediaQueryList for motion prefs)
├── Store (Context/Provider for React; CustomEvent for Vanilla)
└── Registry (Register flourishes as hooks/plugins)
Installation & Setup (React Example)
npm install @flourish/ui
import { FlourishProvider, useFlourish } from '@flourish/ui';
function App() {
return (
<FlourishProvider budget="low" enabled={true}> {/* CPU: low/mid/high */}
<YourApp />
</FlourishProvider>
);
}
// Toggle hook
function Component() {
const { toggleFlourish, isEnabled } = useFlourish();
return <button onClick={toggleFlourish}>Toggle Flourishes</button>;
}
Key Flourishes Catalog
Modular plugins (import only what you need). Each is ~1-2KB gzipped.
| Flourish | Description | Trigger | Duration | CPU Cost | Accessibility Notes |
|---|
| Hover Glow | Subtle radial gradient bloom. | mouseenter | 200ms | Low (opacity/transform) | Skip on keyboard :focus-visible. |
| Press Ripple | Ink-like ripple from click origin. | pointerdown | 300ms | Low (scale/opacity) | ARIA-pressed for buttons. |
| Slide In | Staggered list/item entry. | onMount + viewport | 250ms | Mid (staggered RAF) | Reduced-motion: instant fade. |
| Pulse Heart | Tiny heartbeat for favorites. | onClick | 400ms (3 cycles) | Low | Optional haptic feedback (Vibration API). |
| Loading Dots | Bouncing ellipsis with easing. | Loading state | Infinite (capped FPS) | Low | Screen reader: aria-busy="true". |
| Shake Error | Gentle left-right jiggle. | Error state | 500ms | Low | Motion-reduced: color flash only. |
| Confetti Burst | 5-10 particles (celebratory). | Success | 1s | High (throttled to 1/10s) | Opt-in only; reduced-motion off. |
Usage Example (React):
import { HoverGlow, PressRipple } from '@flourish/ui';
function Button({ children }) {
return (
<button>
<HoverGlow intensity="soft">
<PressRipple>
{children}
</PressRipple>
</HoverGlow>
</button>
);
}
Vanilla JS: flourish.register('hover-glow', element).
Performance Controls
Accessibility & Toggle Implementation
CSS-First Fallback
:root {
--flourish-enabled: 1;
--flourish-duration: 200ms;
}
@media (prefers-reduced-motion: reduce) {
:root {
--flourish-enabled: 0;
}
}
.flourish-hover {
transition: transform var(--flourish-duration) cubic-bezier(0.25, 0.46, 0.45, 0.94);
transform: scale(var(--flourish-enabled, 1));
}
JS Toggles
Metrics & Testing
- Perf: Lighthouse score >95 (perf/accessibility); tested on iPhone SE, mid-range Android.
- Bundle: Core 3KB; full catalog 12KB.
- Edge Cases: SSR-safe (no JS animations server-side); PWA/offline compatible.
Roadmap
- Vue/Svelte adapters.
- Haptics integration (Gamepad API).
- AI-driven personalization (e.g., learn user prefs).
Flourish makes UIs sparkle without sparkle burnout. Fork on GitHub: trailblazer-labs/flourish-ui. Questions? Elementary. 🕵️♂️