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.


Public API

MethodReturnsDescription
play(overlayId, preset, opts?)voidStart a named preset animation on an overlay scope
stop(overlayId)voidStop all animations on a specific overlay
stopAll()voidStop every active animation across all overlays
getActiveAnimations()Map<id, Set>Active animation instances grouped by overlay ID
registerPreset(name, config)voidRegister a new named animation preset bundle
scopesMapInternal scope registry keyed by overlay ID

Console Access

javascript
window.lcards.debug.singleton('animationManager')
// → { type: 'AnimationManager', initialized: true, scopesCount: 4, activeAnimationsCount: 1 }
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<anime instance>>
am.registerPreset('name', {...}) // register a named preset
am.scopes                        // Map<overlayId, scopeData>
am.activeAnimations              // Map<overlayId, Set>

See Also