{"version":3,"file":"animation-state.mjs","sources":["../../../../src/render/utils/animation-state.ts"],"sourcesContent":["import type {\n    AnimationDefinition,\n    TargetAndTransition,\n    VariantLabels,\n} from \"../../node/types\"\nimport type { AnimationType } from \"../types\"\nimport type { VisualElementAnimationOptions } from \"../../animation/interfaces/types\"\nimport { animateVisualElement } from \"../../animation/interfaces/visual-element\"\nimport { calcChildStagger } from \"../../animation/utils/calc-child-stagger\"\nimport { getVariantContext } from \"./get-variant-context\"\nimport { isAnimationControls } from \"./is-animation-controls\"\nimport { isKeyframesTarget } from \"./is-keyframes-target\"\nimport { isVariantLabel } from \"./is-variant-label\"\nimport { resolveVariant } from \"./resolve-dynamic-variants\"\nimport { shallowCompare } from \"./shallow-compare\"\nimport { variantPriorityOrder } from \"./variant-props\"\n\nexport type { VisualElementAnimationOptions }\n\nexport interface AnimationState {\n    animateChanges: (type?: AnimationType) => Promise<any>\n    setActive: (\n        type: AnimationType,\n        isActive: boolean,\n        options?: VisualElementAnimationOptions\n    ) => Promise<any>\n    setAnimateFunction: (fn: any) => void\n    getState: () => { [key: string]: AnimationTypeState }\n    reset: () => void\n}\n\ninterface DefinitionAndOptions {\n    animation: AnimationDefinition\n    options?: VisualElementAnimationOptions\n}\n\nexport type AnimationList = string[] | TargetAndTransition[]\n\nconst reversePriorityOrder = [...variantPriorityOrder].reverse()\nconst numAnimationTypes = variantPriorityOrder.length\n\n/**\n * Type for the animate function that can be injected.\n * This allows the animation implementation to be provided by the framework layer.\n */\nexport type AnimateFunction = (animations: DefinitionAndOptions[]) => Promise<any>\n\nfunction createAnimateFunction(visualElement: any): AnimateFunction {\n    return (animations: DefinitionAndOptions[]) => {\n        return Promise.all(\n            animations.map(({ animation, options }) =>\n                animateVisualElement(visualElement, animation, options)\n            )\n        )\n    }\n}\n\nexport function createAnimationState(visualElement: any): AnimationState {\n    let animate = createAnimateFunction(visualElement)\n    let state = createState()\n    let isInitialRender = true\n\n    /**\n     * This function will be used to reduce the animation definitions for\n     * each active animation type into an object of resolved values for it.\n     */\n    const buildResolvedTypeValues =\n        (type: AnimationType) =>\n        (\n            acc: { [key: string]: any },\n            definition: string | TargetAndTransition | undefined\n        ) => {\n            const resolved = resolveVariant(\n                visualElement,\n                definition,\n                type === \"exit\"\n                    ? visualElement.presenceContext?.custom\n                    : undefined\n            )\n\n            if (resolved) {\n                const { transition, transitionEnd, ...target } = resolved\n                acc = { ...acc, ...target, ...transitionEnd }\n            }\n\n            return acc\n        }\n\n    /**\n     * This just allows us to inject mocked animation functions\n     * @internal\n     */\n    function setAnimateFunction(\n        makeAnimator: (visualElement: any) => AnimateFunction\n    ) {\n        animate = makeAnimator(visualElement)\n    }\n\n    /**\n     * When we receive new props, we need to:\n     * 1. Create a list of protected keys for each type. This is a directory of\n     *    value keys that are currently being \"handled\" by types of a higher priority\n     *    so that whenever an animation is played of a given type, these values are\n     *    protected from being animated.\n     * 2. Determine if an animation type needs animating.\n     * 3. Determine if any values have been removed from a type and figure out\n     *    what to animate those to.\n     */\n    function animateChanges(changedActiveType?: AnimationType) {\n        const { props } = visualElement\n        const context = getVariantContext(visualElement.parent) || {}\n\n        /**\n         * A list of animations that we'll build into as we iterate through the animation\n         * types. This will get executed at the end of the function.\n         */\n        const animations: DefinitionAndOptions[] = []\n\n        /**\n         * Keep track of which values have been removed. Then, as we hit lower priority\n         * animation types, we can check if they contain removed values and animate to that.\n         */\n        const removedKeys = new Set<string>()\n\n        /**\n         * A dictionary of all encountered keys. This is an object to let us build into and\n         * copy it without iteration. Each time we hit an animation type we set its protected\n         * keys - the keys its not allowed to animate - to the latest version of this object.\n         */\n        let encounteredKeys: { [key: string]: any } = {}\n\n        /**\n         * If a variant has been removed at a given index, and this component is controlling\n         * variant animations, we want to ensure lower-priority variants are forced to animate.\n         */\n        let removedVariantIndex = Infinity\n\n        /**\n         * Iterate through all animation types in reverse priority order. For each, we want to\n         * detect which values it's handling and whether or not they've changed (and therefore\n         * need to be animated). If any values have been removed, we want to detect those in\n         * lower priority props and flag for animation.\n         */\n        for (let i = 0; i < numAnimationTypes; i++) {\n            const type = reversePriorityOrder[i]\n            const typeState = state[type]\n            const prop =\n                props[type] !== undefined\n                    ? props[type]\n                    : context[type as keyof typeof context]\n            const propIsVariant = isVariantLabel(prop)\n\n            /**\n             * If this type has *just* changed isActive status, set activeDelta\n             * to that status. Otherwise set to null.\n             */\n            const activeDelta =\n                type === changedActiveType ? typeState.isActive : null\n\n            if (activeDelta === false) removedVariantIndex = i\n\n            /**\n             * If this prop is an inherited variant, rather than been set directly on the\n             * component itself, we want to make sure we allow the parent to trigger animations.\n             *\n             * TODO: Can probably change this to a !isControllingVariants check\n             */\n            let isInherited =\n                prop === context[type as keyof typeof context] &&\n                prop !== props[type] &&\n                propIsVariant\n\n            if (\n                isInherited &&\n                isInitialRender &&\n                visualElement.manuallyAnimateOnMount\n            ) {\n                isInherited = false\n            }\n\n            /**\n             * Set all encountered keys so far as the protected keys for this type. This will\n             * be any key that has been animated or otherwise handled by active, higher-priortiy types.\n             */\n            typeState.protectedKeys = { ...encounteredKeys }\n\n            // Check if we can skip analysing this prop early\n            if (\n                // If it isn't active and hasn't *just* been set as inactive\n                (!typeState.isActive && activeDelta === null) ||\n                // If we didn't and don't have any defined prop for this animation type\n                (!prop && !typeState.prevProp) ||\n                // Or if the prop doesn't define an animation\n                isAnimationControls(prop) ||\n                typeof prop === \"boolean\"\n            ) {\n                continue\n            }\n\n            /**\n             * If exit is already active and wasn't just activated, skip\n             * re-processing to prevent interrupting running exit animations.\n             * Re-resolving exit with a changed custom value can start new\n             * value animations that stop the originals, leaving the exit\n             * animation promise unresolved and the component stuck in the DOM.\n             */\n            if (type === \"exit\" && typeState.isActive && activeDelta !== true) {\n                if (typeState.prevResolvedValues) {\n                    encounteredKeys = {\n                        ...encounteredKeys,\n                        ...typeState.prevResolvedValues,\n                    }\n                }\n                continue\n            }\n\n            /**\n             * As we go look through the values defined on this type, if we detect\n             * a changed value or a value that was removed in a higher priority, we set\n             * this to true and add this prop to the animation list.\n             */\n            const variantDidChange = checkVariantsDidChange(\n                typeState.prevProp,\n                prop\n            )\n\n            let shouldAnimateType =\n                variantDidChange ||\n                // If we're making this variant active, we want to always make it active\n                (type === changedActiveType &&\n                    typeState.isActive &&\n                    !isInherited &&\n                    propIsVariant) ||\n                // If we removed a higher-priority variant (i is in reverse order)\n                (i > removedVariantIndex && propIsVariant)\n\n            let handledRemovedValues = false\n\n            /**\n             * As animations can be set as variant lists, variants or target objects, we\n             * coerce everything to an array if it isn't one already\n             */\n            const definitionList = Array.isArray(prop) ? prop : [prop]\n\n            /**\n             * Build an object of all the resolved values. We'll use this in the subsequent\n             * animateChanges calls to determine whether a value has changed.\n             */\n            let resolvedValues = definitionList.reduce(\n                buildResolvedTypeValues(type),\n                {}\n            )\n\n            if (activeDelta === false) resolvedValues = {}\n\n            /**\n             * Now we need to loop through all the keys in the prev prop and this prop,\n             * and decide:\n             * 1. If the value has changed, and needs animating\n             * 2. If it has been removed, and needs adding to the removedKeys set\n             * 3. If it has been removed in a higher priority type and needs animating\n             * 4. If it hasn't been removed in a higher priority but hasn't changed, and\n             *    needs adding to the type's protectedKeys list.\n             */\n            const { prevResolvedValues = {} } = typeState\n\n            const allKeys = {\n                ...prevResolvedValues,\n                ...resolvedValues,\n            }\n            const markToAnimate = (key: string) => {\n                shouldAnimateType = true\n                if (removedKeys.has(key)) {\n                    handledRemovedValues = true\n                    removedKeys.delete(key)\n                }\n                typeState.needsAnimating[key] = true\n\n                const motionValue = visualElement.getValue(key)\n                if (motionValue) motionValue.liveStyle = false\n            }\n\n            for (const key in allKeys) {\n                const next = resolvedValues[key]\n                const prev = prevResolvedValues[key]\n\n                // If we've already handled this we can just skip ahead\n                if (encounteredKeys.hasOwnProperty(key)) continue\n\n                /**\n                 * If the value has changed, we probably want to animate it.\n                 */\n                let valueHasChanged = false\n                if (isKeyframesTarget(next) && isKeyframesTarget(prev)) {\n                    valueHasChanged = !shallowCompare(next, prev)\n                } else {\n                    valueHasChanged = next !== prev\n                }\n\n                if (valueHasChanged) {\n                    if (next !== undefined && next !== null) {\n                        // If next is defined and doesn't equal prev, it needs animating\n                        markToAnimate(key)\n                    } else {\n                        // If it's undefined, it's been removed.\n                        removedKeys.add(key)\n                    }\n                } else if (next !== undefined && removedKeys.has(key)) {\n                    /**\n                     * If next hasn't changed and it isn't undefined, we want to check if it's\n                     * been removed by a higher priority\n                     */\n                    markToAnimate(key)\n                } else {\n                    /**\n                     * If it hasn't changed, we add it to the list of protected values\n                     * to ensure it doesn't get animated.\n                     */\n                    typeState.protectedKeys[key] = true\n                }\n            }\n\n            /**\n             * Update the typeState so next time animateChanges is called we can compare the\n             * latest prop and resolvedValues to these.\n             */\n            typeState.prevProp = prop\n            typeState.prevResolvedValues = resolvedValues\n\n            if (typeState.isActive) {\n                encounteredKeys = { ...encounteredKeys, ...resolvedValues }\n            }\n\n            if (isInitialRender && visualElement.blockInitialAnimation) {\n                shouldAnimateType = false\n            }\n\n            /**\n             * If this is an inherited prop we want to skip this animation\n             * unless the inherited variants haven't changed on this render.\n             */\n            const willAnimateViaParent = isInherited && variantDidChange\n            const needsAnimating = !willAnimateViaParent || handledRemovedValues\n            if (shouldAnimateType && needsAnimating) {\n                animations.push(\n                    ...definitionList.map((animation) => {\n                        const options: VisualElementAnimationOptions = { type }\n\n                        /**\n                         * If we're performing the initial animation, but we're not\n                         * rendering at the same time as the variant-controlling parent,\n                         * we want to use the parent's transition to calculate the stagger.\n                         */\n                        if (\n                            typeof animation === \"string\" &&\n                            isInitialRender &&\n                            !willAnimateViaParent &&\n                            visualElement.manuallyAnimateOnMount &&\n                            visualElement.parent\n                        ) {\n                            const { parent } = visualElement\n                            const parentVariant = resolveVariant(\n                                parent,\n                                animation\n                            )\n\n                            if (parent.enteringChildren && parentVariant) {\n                                const { delayChildren } =\n                                    parentVariant.transition || {}\n                                options.delay = calcChildStagger(\n                                    parent.enteringChildren,\n                                    visualElement,\n                                    delayChildren\n                                )\n                            }\n                        }\n\n                        return {\n                            animation: animation as AnimationDefinition,\n                            options,\n                        }\n                    })\n                )\n            }\n        }\n\n        /**\n         * If there are some removed value that haven't been dealt with,\n         * we need to create a new animation that falls back either to the value\n         * defined in the style prop, or the last read value.\n         */\n        if (removedKeys.size) {\n            const fallbackAnimation: TargetAndTransition = {}\n\n            /**\n             * If the initial prop contains a transition we can use that, otherwise\n             * allow the animation function to use the visual element's default.\n             */\n            if (typeof props.initial !== \"boolean\") {\n                const initialTransition = resolveVariant(\n                    visualElement,\n                    Array.isArray(props.initial)\n                        ? props.initial[0]\n                        : props.initial\n                )\n\n                if (initialTransition && initialTransition.transition) {\n                    fallbackAnimation.transition = initialTransition.transition\n                }\n            }\n\n            removedKeys.forEach((key) => {\n                const fallbackTarget = visualElement.getBaseTarget(key)\n\n                const motionValue = visualElement.getValue(key)\n                if (motionValue) motionValue.liveStyle = true\n\n                // @ts-expect-error - @mattgperry to figure if we should do something here\n                fallbackAnimation[key] = fallbackTarget ?? null\n            })\n\n            animations.push({ animation: fallbackAnimation })\n        }\n\n        let shouldAnimate = Boolean(animations.length)\n\n        if (\n            isInitialRender &&\n            (props.initial === false || props.initial === props.animate) &&\n            !visualElement.manuallyAnimateOnMount\n        ) {\n            shouldAnimate = false\n        }\n\n        isInitialRender = false\n        return shouldAnimate ? animate(animations) : Promise.resolve()\n    }\n\n    /**\n     * Change whether a certain animation type is active.\n     */\n    function setActive(type: AnimationType, isActive: boolean) {\n        // If the active state hasn't changed, we can safely do nothing here\n        if (state[type].isActive === isActive) return Promise.resolve()\n\n        // Propagate active change to children\n        visualElement.variantChildren?.forEach((child: any) =>\n            child.animationState?.setActive(type, isActive)\n        )\n\n        state[type].isActive = isActive\n\n        const animations = animateChanges(type)\n\n        for (const key in state) {\n            state[key as keyof typeof state].protectedKeys = {}\n        }\n\n        return animations\n    }\n\n    return {\n        animateChanges,\n        setActive,\n        setAnimateFunction,\n        getState: () => state,\n        reset: () => {\n            state = createState()\n            /**\n             * Temporarily disabling resetting this flag as it prevents components\n             * with initial={false} from animating after being remounted, for instance\n             * as the child of an Activity component.\n             */\n            // isInitialRender = true\n        },\n    }\n}\n\nexport function checkVariantsDidChange(prev: any, next: any) {\n    if (typeof next === \"string\") {\n        return next !== prev\n    } else if (Array.isArray(next)) {\n        return !shallowCompare(next, prev)\n    }\n\n    return false\n}\n\nexport interface AnimationTypeState {\n    isActive: boolean\n    protectedKeys: { [key: string]: true }\n    needsAnimating: { [key: string]: boolean }\n    prevResolvedValues: { [key: string]: any }\n    prevProp?: VariantLabels | TargetAndTransition\n}\n\nfunction createTypeState(isActive = false): AnimationTypeState {\n    return {\n        isActive,\n        protectedKeys: {},\n        needsAnimating: {},\n        prevResolvedValues: {},\n    }\n}\n\nfunction createState() {\n    return {\n        animate: createTypeState(true),\n        whileInView: createTypeState(),\n        whileHover: createTypeState(),\n        whileTap: createTypeState(),\n        whileDrag: createTypeState(),\n        whileFocus: createTypeState(),\n        exit: createTypeState(),\n    }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAsCA,MAAM,oBAAoB,GAAG,CAAC,GAAG,oBAAoB,CAAC,CAAC,OAAO,EAAE,CAAA;AAChE,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,MAAM,CAAA;AAQrD,SAAS,qBAAqB,CAAC,aAAkB,EAAA;IAC7C,OAAO,CAAC,UAAkC,KAAI;QAC1C,OAAO,OAAO,CAAC,GAAG,CACd,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,KAClC,oBAAoB,CAAC,aAAa,EAAE,SAAS,EAAE,OAAO,CAAC,CAC1D,CACJ,CAAA;AACL,KAAC,CAAA;AACL,CAAC;AAEK,SAAU,oBAAoB,CAAC,aAAkB,EAAA;AACnD,IAAA,IAAI,OAAO,GAAG,qBAAqB,CAAC,aAAa,CAAC,CAAA;AAClD,IAAA,IAAI,KAAK,GAAG,WAAW,EAAE,CAAA;IACzB,IAAI,eAAe,GAAG,IAAI,CAAA;AAE1B;;;AAGG;AACH,IA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