{"version":3,"file":"exit.mjs","sources":["../../../../../src/motion/features/animation/exit.ts"],"sourcesContent":["import { Feature, resolveVariant } from \"motion-dom\"\n\nlet id = 0\n\nexport class ExitAnimationFeature extends Feature<unknown> {\n    private id: number = id++\n    private isExitComplete = false\n\n    update() {\n        if (!this.node.presenceContext) return\n\n        const { isPresent, onExitComplete } = this.node.presenceContext\n        const { isPresent: prevIsPresent } = this.node.prevPresenceContext || {}\n\n        if (!this.node.animationState || isPresent === prevIsPresent) {\n            return\n        }\n\n        if (isPresent && prevIsPresent === false) {\n            /**\n             * When re-entering, if the exit animation already completed\n             * (element is at rest), reset to initial values so the enter\n             * animation replays from the correct position.\n             */\n            if (this.isExitComplete) {\n                const { initial, custom } = this.node.getProps()\n\n                if (typeof initial === \"string\") {\n                    const resolved = resolveVariant(\n                        this.node,\n                        initial,\n                        custom\n                    )\n                    if (resolved) {\n                        const { transition, transitionEnd, ...target } =\n                            resolved\n                        for (const key in target) {\n                            this.node\n                                .getValue(key)\n                                ?.jump(\n                                    target[\n                                        key as keyof typeof target\n                                    ] as any\n                                )\n                        }\n                    }\n                }\n\n                this.node.animationState.reset()\n                this.node.animationState.animateChanges()\n            } else {\n                this.node.animationState.setActive(\"exit\", false)\n            }\n\n            this.isExitComplete = false\n            return\n        }\n\n        const exitAnimation = this.node.animationState.setActive(\n            \"exit\",\n            !isPresent\n        )\n\n        if (onExitComplete && !isPresent) {\n            exitAnimation.then(() => {\n                this.isExitComplete = true\n                onExitComplete(this.id)\n            })\n        }\n    }\n\n    mount() {\n        const { register, onExitComplete } = this.node.presenceContext || {}\n\n        if (onExitComplete) {\n            onExitComplete(this.id)\n        }\n\n        if (register) {\n            this.unmount = register(this.id)\n        }\n    }\n\n    unmount() {}\n}\n"],"names":[],"mappings":";;AAEA,IAAI,EAAE,GAAG,CAAC;AAEJ,MAAO,oBAAqB,SAAQ,OAAgB,CAAA;AAA1D,IAAA,WAAA,GAAA;;QACY,IAAA,CAAA,EAAE,GAAW,EAAE,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