import { AnimationItem , AnimationConfigWithPath , AnimationConfigWithData } from 'lottie-web' ; import { Element } from './element.js' ; import { LottieAnimationLoader , } from '../interfaces.js' ; /**
 * Store loadAnimation from Lottie.
 */ let LOTTIE_ANIMATION_LOADER ; /**
 * Store all intances of Element.
 */ const INSTANCES = new Set ( ) ; /**
 * Store supported triggers.
 */ const TRIGGERS = new Map < string , any > ( ) ; /**
 * Store icons data in memory.
 */ const ICONS = new Map < string , any > ( ) ; /**
 * List of promises for pending icons.
 */ const LOADING = new Map < string , Promise < any > > ( ) ; param name param iconData export function registerIcon ( name , iconData ) { ICONS . set ( name , iconData ) ; for ( const instance of INSTANCES ) { ( instance as any ) . notify ( name , 'icon' ) ; } } param name param triggerClass export function registerTrigger ( name , triggerClass ) { TRIGGERS . set ( name , triggerClass ) ; for ( const instance of INSTANCES ) { ( instance as any ) . notify ( name , 'trigger' ) ; } } param animationLoader export function registerAnimationLoader ( animationLoader ) { LOTTIE_ANIMATION_LOADER = animationLoader ; } param element export function connectInstance ( element ) { INSTANCES . add ( element ) ; } param element export function disconnectInstance ( element ) { INSTANCES . delete ( element ) ; } param name export function getIcon ( name ) { return ICONS . get ( name ) ; } param name export function getTrigger ( name ) { return TRIGGERS . get ( name ) ; } param url export async function loadIconData ( url ) { const response = await fetch ( url ) ; return await response . json ( ) ; } param url export async function loadIcon ( url ) { if ( ICONS . has ( url ) ) { return ; } const current = LOADING . get ( url ) ; if ( current ) { await current ; return ; } if ( current === undefined ) { const promise = loadIconData ( url ) ; LOADING . set ( url , promise ) ; const data = await promise ; LOADING . delete ( url ) ; ICONS . set ( url , data ) ; } } param params export function loadLottieAnimation ( params ) { if ( ! LOTTIE_ANIMATION_LOADER ) { throw new Error ( 'Unregistered Lottie.' ) ; } return LOTTIE_ANIMATION_LOADER ( params ) ; }