{"version":3,"file":"index.mjs","sources":["../../../../../src/motion/features/animation/index.ts"],"sourcesContent":["import {\n    createAnimationState,\n    Feature,\n    isAnimationControls,\n    type VisualElement,\n} from \"motion-dom\"\n\nexport class AnimationFeature extends Feature<unknown> {\n    unmountControls?: () => void\n\n    /**\n     * We dynamically generate the AnimationState manager as it contains a reference\n     * to the underlying animation library. We only want to load that if we load this,\n     * so people can optionally code split it out using the `m` component.\n     */\n    constructor(node: VisualElement) {\n        super(node)\n        node.animationState ||= createAnimationState(node)\n    }\n\n    updateAnimationControlsSubscription() {\n        const { animate } = this.node.getProps()\n        if (isAnimationControls(animate)) {\n            this.unmountControls = animate.subscribe(this.node)\n        }\n    }\n\n    /**\n     * Subscribe any provided AnimationControls to the component's VisualElement\n     */\n    mount() {\n        this.updateAnimationControlsSubscription()\n    }\n\n    update() {\n        const { animate } = this.node.getProps()\n        const { animate: prevAnimate } = this.node.prevProps || {}\n        if (animate !== prevAnimate) {\n            this.updateAnimationControlsSubscription()\n        }\n    }\n\n    unmount() {\n        this.node.animationState!.reset()\n        this.unmountControls?.()\n    }\n}\n"],"names":[],"mappings":";;AAOM,MAAO,gBAAiB,SAAQ,OAAgB,CAAA;AAGlD;;;;AAIG;AACH,IAAA,WAAA,CAAY,IAAmB,EAAA;QAC3B,KAAK,CAAC,IAAI,CAAC;QACX,IAAI,CAAC,cAAc,KAAnB,IAAI,CAAC,cAAc,GAAK,oBAAoB,CAAC,IAAI,CAAC,CAAA;IACtD;IAEA,mCAAmC,GAAA;QAC/B,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;AACxC,QAAA,IAAI,mBAAmB,CAAC,OAAO,CAAC,EAAE;YAC9B,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;QACvD;IACJ;AAEA;;AAEG;IACH,KAAK,GAAA;QACD,IAAI,CAAC,mCAAmC,EAAE;IAC9C;IAEA,MAAM,GAAA;QACF,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;AACxC,QAAA,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE;AAC1D,QAAA,IAAI,OAAO,KAAK,WAAW,EAAE;YACzB,IAAI,CAAC,mCAAmC,EAAE;QAC9C;IACJ;IAEA,OAAO,GAAA;AACH,QAAA,IAAI,CAAC,IAAI,CAAC,cAAe,CAAC,KAAK,EAAE;AACjC,QAAA,IAAI,CAAC,eAAe,IAAI;IAC5B;AACH;;;;"}