import BaseFoundation, { DefaultAdapter } from "../base/foundation"; import lottie, { AnimationItem } from "lottie-web"; import { ArgsType } from "../collapse/foundation"; export interface LottieAdapter

, S = Record> extends DefaultAdapter { getContainer: () => Element; getLoadParams: () => ArgsType[0] } export interface LottieBaseProps { width?: string; height?: string; params: Partial[0]>; getAnimationInstance?: (instance: AnimationItem|null) => void; getLottie?: (lottiePKG: typeof lottie) => void } export interface LottieBaseState { } class LottieFoundation

, S = Record> extends BaseFoundation, P, S> { animation: null|AnimationItem = null constructor(adapter: LottieAdapter) { super({ ...LottieFoundation.defaultAdapter, ...adapter }); } static getLottie: () => typeof lottie = ()=>{ return lottie; } init(lifecycle?: any) { super.init(lifecycle); this.animation = lottie.loadAnimation(this._adapter.getLoadParams()); this.getProp("getAnimationInstance")?.(this.animation); this.getProp("getLottie")?.(LottieFoundation.getLottie()); } handleParamsUpdate = ()=>{ this.animation.destroy(); this.animation = lottie.loadAnimation(this._adapter.getLoadParams()); this.getProp("getAnimationInstance")?.(this.animation); } destroy() { super.destroy(); this.animation.destroy(); } } export default LottieFoundation;