Skip to content

Animation Manager

window.lcards.core.animationManager — Central anime.js v4 coordinator for card and overlay animations.


Overview

AnimationManager extends BaseService. It manages animation scopes per overlay, integrates with DataSourceManager for reactive value-driven animations, with RulesEngine for rule-triggered animations, and provides a full runtime/debug API surface.


Key Classes

ClassFileRole
AnimationManagercore/animation/AnimationManager.jsScope management, trigger coordination, lifecycle
AnimationRegistrycore/animation/AnimationRegistry.jsCaches compiled anime.js instances; avoids re-parsing
TriggerManagercore/animation/TriggerManager.jsManages trigger subscriptions (entity_change, datasource)
TimelineDiffercore/animation/TimelineDiffer.jsDiffs timeline configs to minimise re-creation on update
PerformanceMonitorcore/animation/PerformanceMonitor.jsTracks active animation count and frame budget
resolveAnimationscore/animation/resolveAnimations.jsMerges preset defaults with overlay animation config
resolveTimelinescore/animation/resolveTimelines.jsResolves timeline steps from config or preset

Architecture

AnimationManager
    ├─ scopes Map (overlayId → scope)
    │   ├─ scope.triggerManager  (TriggerManager per overlay)
    │   └─ scope.activeAnimations (Set<anime instance>)

    ├─ AnimationRegistry  (shared, caches anime instances by key)
    ├─ datasourceSubscriptions (datasource_id → cleanup fn)
    └─ timelines Map (timelineId → anime.timeline instance)

Trigger Types

TriggerWhen fires
on_loadOnce on card initialisation
on_entity_changeWhen a watched entity changes state
on_datasourceWhen a DataSource value crosses a threshold or changes
on_ruleFired by RulesEngine when a rule matches
manualProgrammatic: animationManager.play(id)

anime.js v4 Note

LCARdS uses anime.js v4. The anime.timeline() API changed from v3. Always pass targets as CSS selectors or DOM element references resolved at runtime — not stale references cached at config time.


Preset Animations

Presets are named animation parameter bundles distributed via packs. Built-in presets include:

PresetEffect
alert_pulseScale pulse, red tint
glowOpacity + shadow flash
slide_in_left / slide_in_rightTranslate + fade
fade_in / fade_outOpacity
bounceScale bounce spring

Custom presets are registered via animation_presets in pack definitions.


Runtime API

javascript
const am = window.lcards.core.animationManager;
am.play('my-overlay', 'alert_pulse', { loop: true })
am.stop('my-overlay')
am.stopAll()
am.getActiveAnimations()     // Map<overlayId, Set>
am.registerPreset('name', { ... })

See Also