{"version":3,"file":"JSAnimation.mjs","sources":["../../../src/animation/JSAnimation.ts"],"sourcesContent":["import {\n    clamp,\n    invariant,\n    millisecondsToSeconds,\n    pipe,\n    secondsToMilliseconds,\n} from \"motion-utils\"\nimport { time } from \"../frameloop/sync-time\"\nimport { activeAnimations } from \"../stats/animation-count\"\nimport { mix } from \"../utils/mix\"\nimport { Mixer } from \"../utils/mix/types\"\nimport { frameloopDriver } from \"./drivers/frame\"\nimport { DriverControls } from \"./drivers/types\"\nimport { inertia } from \"./generators/inertia\"\nimport { keyframes as keyframesGenerator } from \"./generators/keyframes\"\nimport { calcGeneratorDuration } from \"./generators/utils/calc-duration\"\nimport { getGeneratorVelocity } from \"./generators/utils/velocity\"\nimport { getFinalKeyframe } from \"./keyframes/get-final\"\nimport {\n    AnimationPlaybackControlsWithThen,\n    AnimationState,\n    GeneratorFactory,\n    KeyframeGenerator,\n    TimelineWithFallback,\n    ValueAnimationOptions,\n} from \"./types\"\nimport { replaceTransitionType } from \"./utils/replace-transition-type\"\nimport { WithPromise } from \"./utils/WithPromise\"\n\nconst percentToProgress = (percent: number) => percent / 100\n\nexport class JSAnimation<T extends number | string>\n    extends WithPromise\n    implements AnimationPlaybackControlsWithThen\n{\n    state: AnimationPlayState = \"idle\"\n\n    startTime: number | null = null\n\n    /**\n     * The driver that's controlling the animation loop. Normally this is a requestAnimationFrame loop\n     * but in tests we can pass in a synchronous loop.\n     */\n    private driver?: DriverControls\n\n    private isStopped = false\n\n    private generator: KeyframeGenerator<T>\n\n    private calculatedDuration: number\n\n    private resolvedDuration: number\n\n    private totalDuration: number\n\n    private options: ValueAnimationOptions<T>\n\n    /**\n     * The current time of the animation.\n     */\n    private currentTime: number = 0\n\n    /**\n     * The time at which the animation was paused.\n     */\n    private holdTime: number | null = null\n\n    /**\n     * Playback speed as a factor. 0 would be stopped, -1 reverse and 2 double speed.\n     */\n    private playbackSpeed = 1\n\n    /*\n     * If our generator doesn't support mixing numbers, we need to replace keyframes with\n     * [0, 100] and then make a function that maps that to the actual keyframes.\n     *\n     * 100 is chosen instead of 1 as it works nicer with spring animations.\n     */\n    private mixKeyframes: Mixer<T> | undefined\n\n    private mirroredGenerator: KeyframeGenerator<T> | undefined\n\n    /**\n     * Reusable state object for the delay phase to avoid\n     * allocating a new object every frame.\n     */\n    private delayState: AnimationState<T> = {\n        done: false,\n        value: undefined as unknown as T,\n    }\n\n    constructor(options: ValueAnimationOptions<T>) {\n        super()\n        activeAnimations.mainThread++\n\n        this.options = options\n        this.initAnimation()\n        this.play()\n\n        if (options.autoplay === false) this.pause()\n    }\n\n    initAnimation() {\n        const { options } = this\n\n        replaceTransitionType(options)\n\n        const {\n            type = keyframesGenerator,\n            repeat = 0,\n            repeatDelay = 0,\n            repeatType,\n            velocity = 0,\n        } = options\n        let { keyframes } = options\n\n        const generatorFactory =\n            (type as GeneratorFactory) || keyframesGenerator\n\n        if (\n            process.env.NODE_ENV !== \"production\" &&\n            generatorFactory !== keyframesGenerator\n        ) {\n            invariant(\n                keyframes.length <= 2,\n                `Only two keyframes currently supported with spring and inertia animations. Trying to animate ${keyframes}`,\n                \"spring-two-frames\"\n            )\n        }\n\n        if (\n            generatorFactory !== keyframesGenerator &&\n            typeof keyframes[0] !== \"number\"\n        ) {\n            this.mixKeyframes = pipe(\n                percentToProgress,\n                mix(keyframes[0], keyframes[1])\n            ) as (t: number) => T\n\n            keyframes = [0 as T, 100 as T]\n        }\n\n        const generator = generatorFactory({ ...options, keyframes })\n\n        /**\n         * If we have a mirror repeat type we need to create a second generator that outputs the\n         * mirrored (not reversed) animation and later ping pong between the two generators.\n         */\n        if (repeatType === \"mirror\") {\n            this.mirroredGenerator = generatorFactory({\n                ...options,\n                keyframes: [...keyframes].reverse(),\n                velocity: -velocity,\n            })\n        }\n\n        /**\n         * If duration is undefined and we have repeat options,\n         * we need to calculate a duration from the generator.\n         *\n         * We set it to the generator itself to cache the duration.\n         * Any timeline resolver will need to have already precalculated\n         * the duration by this step.\n         */\n        if (generator.calculatedDuration === null) {\n            generator.calculatedDuration = calcGeneratorDuration(generator)\n        }\n\n        const { calculatedDuration } = generator\n        this.calculatedDuration = calculatedDuration\n        this.resolvedDuration = calculatedDuration + repeatDelay\n        this.totalDuration = this.resolvedDuration * (repeat + 1) - repeatDelay\n        this.generator = generator\n    }\n\n    updateTime(timestamp: number) {\n        const animationTime =\n            Math.round(timestamp - this.startTime!) * this.playbackSpeed\n\n        // Update currentTime\n        if (this.holdTime !== null) {\n            this.currentTime = this.holdTime\n        } else {\n            // Rounding the time because floating point arithmetic is not always accurate, e.g. 3000.367 - 1000.367 =\n            // 2000.0000000000002. This is a problem when we are comparing the currentTime with the duration, for\n            // example.\n            this.currentTime = animationTime\n        }\n    }\n\n    tick(timestamp: number, sample = false) {\n        const {\n            generator,\n            totalDuration,\n            mixKeyframes,\n            mirroredGenerator,\n            resolvedDuration,\n            calculatedDuration,\n        } = this\n\n        if (this.startTime === null) return generator.next(0)\n\n        const {\n            delay = 0,\n            keyframes,\n            repeat,\n            repeatType,\n            repeatDelay,\n            type,\n            onUpdate,\n            finalKeyframe,\n        } = this.options\n\n        /**\n         * requestAnimationFrame timestamps can come through as lower than\n         * the startTime as set by performance.now(). Here we prevent this,\n         * though in the future it could be possible to make setting startTime\n         * a pending operation that gets resolved here.\n         */\n        if (this.speed > 0) {\n            this.startTime = Math.min(this.startTime, timestamp)\n        } else if (this.speed < 0) {\n            this.startTime = Math.min(\n                timestamp - totalDuration / this.speed,\n                this.startTime\n            )\n        }\n\n        if (sample) {\n            this.currentTime = timestamp\n        } else {\n            this.updateTime(timestamp)\n        }\n\n        // Rebase on delay\n        const timeWithoutDelay =\n            this.currentTime - delay * (this.playbackSpeed >= 0 ? 1 : -1)\n        const isInDelayPhase =\n            this.playbackSpeed >= 0\n                ? timeWithoutDelay < 0\n                : timeWithoutDelay > totalDuration\n        this.currentTime = Math.max(timeWithoutDelay, 0)\n\n        // If this animation has finished, set the current time  to the total duration.\n        if (this.state === \"finished\" && this.holdTime === null) {\n            this.currentTime = totalDuration\n        }\n\n        let elapsed = this.currentTime\n        let frameGenerator = generator\n\n        if (repeat) {\n            /**\n             * Get the current progress (0-1) of the animation. If t is >\n             * than duration we'll get values like 2.5 (midway through the\n             * third iteration)\n             */\n            const progress =\n                Math.min(this.currentTime, totalDuration) / resolvedDuration\n\n            /**\n             * Get the current iteration (0 indexed). For instance the floor of\n             * 2.5 is 2.\n             */\n            let currentIteration = Math.floor(progress)\n\n            /**\n             * Get the current progress of the iteration by taking the remainder\n             * so 2.5 is 0.5 through iteration 2\n             */\n            let iterationProgress = progress % 1.0\n\n            /**\n             * If iteration progress is 1 we count that as the end\n             * of the previous iteration.\n             */\n            if (!iterationProgress && progress >= 1) {\n                iterationProgress = 1\n            }\n\n            iterationProgress === 1 && currentIteration--\n\n            currentIteration = Math.min(currentIteration, repeat + 1)\n\n            /**\n             * Reverse progress if we're not running in \"normal\" direction\n             */\n\n            const isOddIteration = Boolean(currentIteration % 2)\n            if (isOddIteration) {\n                if (repeatType === \"reverse\") {\n                    iterationProgress = 1 - iterationProgress\n                    if (repeatDelay) {\n                        iterationProgress -= repeatDelay / resolvedDuration\n                    }\n                } else if (repeatType === \"mirror\") {\n                    frameGenerator = mirroredGenerator!\n                }\n            }\n\n            elapsed = clamp(0, 1, iterationProgress) * resolvedDuration\n        }\n\n        /**\n         * If we're in negative time, set state as the initial keyframe.\n         * This prevents delay: x, duration: 0 animations from finishing\n         * instantly.\n         */\n        let state: AnimationState<T>\n        if (isInDelayPhase) {\n            this.delayState.value = keyframes[0]\n            state = this.delayState\n        } else {\n            state = frameGenerator.next(elapsed)\n        }\n\n        if (mixKeyframes && !isInDelayPhase) {\n            state.value = mixKeyframes(state.value as number)\n        }\n\n        let { done } = state\n\n        if (!isInDelayPhase && calculatedDuration !== null) {\n            done =\n                this.playbackSpeed >= 0\n                    ? this.currentTime >= totalDuration\n                    : this.currentTime <= 0\n        }\n\n        const isAnimationFinished =\n            this.holdTime === null &&\n            (this.state === \"finished\" || (this.state === \"running\" && done))\n\n        // TODO: The exception for inertia could be cleaner here\n        if (isAnimationFinished && type !== inertia) {\n            state.value = getFinalKeyframe(\n                keyframes,\n                this.options,\n                finalKeyframe,\n                this.speed\n            )\n        }\n\n        if (onUpdate) {\n            onUpdate(state.value)\n        }\n\n        if (isAnimationFinished) {\n            this.finish()\n        }\n\n        return state\n    }\n\n    /**\n     * Allows the returned animation to be awaited or promise-chained. Currently\n     * resolves when the animation finishes at all but in a future update could/should\n     * reject if its cancels.\n     */\n    then(resolve: VoidFunction, reject?: VoidFunction) {\n        return this.finished.then(resolve, reject)\n    }\n\n    get duration() {\n        return millisecondsToSeconds(this.calculatedDuration)\n    }\n\n    get iterationDuration() {\n        const { delay = 0 } = this.options || {}\n        return this.duration + millisecondsToSeconds(delay)\n    }\n\n    get time() {\n        return millisecondsToSeconds(this.currentTime)\n    }\n\n    set time(newTime: number) {\n        newTime = secondsToMilliseconds(newTime)\n        this.currentTime = newTime\n\n        if (\n            this.startTime === null ||\n            this.holdTime !== null ||\n            this.playbackSpeed === 0\n        ) {\n            this.holdTime = newTime\n        } else if (this.driver) {\n            this.startTime = this.driver.now() - newTime / this.playbackSpeed\n        }\n\n        if (this.driver) {\n            this.driver.start(false)\n        } else {\n            this.startTime = 0\n            this.state = \"paused\"\n            this.holdTime = newTime\n            this.tick(newTime)\n        }\n    }\n\n    /**\n     * Returns the generator's velocity at the current time in units/second.\n     * Uses the analytical derivative when available (springs), avoiding\n     * the MotionValue's frame-dependent velocity estimation.\n     */\n    getGeneratorVelocity(): number {\n        const t = this.currentTime\n        if (t <= 0) return this.options.velocity || 0\n\n        if (this.generator.velocity) {\n            return this.generator.velocity(t)\n        }\n\n        // Fallback: finite difference\n        const current = this.generator.next(t).value as number\n        return getGeneratorVelocity(\n            (s) => this.generator.next(s).value as number,\n            t,\n            current\n        )\n    }\n\n    get speed() {\n        return this.playbackSpeed\n    }\n\n    set speed(newSpeed: number) {\n        const hasChanged = this.playbackSpeed !== newSpeed\n\n        if (hasChanged && this.driver) {\n            this.updateTime(time.now())\n        }\n\n        this.playbackSpeed = newSpeed\n\n        if (hasChanged && this.driver) {\n            this.time = millisecondsToSeconds(this.currentTime)\n        }\n    }\n\n    play() {\n        if (this.isStopped) return\n\n        const { driver = frameloopDriver, startTime } = this.options\n\n        if (!this.driver) {\n            this.driver = driver((timestamp) => this.tick(timestamp))\n        }\n\n        this.options.onPlay?.()\n\n        const now = this.driver.now()\n\n        if (this.state === \"finished\") {\n            this.updateFinished()\n            this.startTime = now\n        } else if (this.holdTime !== null) {\n            this.startTime = now - this.holdTime\n        } else if (!this.startTime) {\n            this.startTime = startTime ?? now\n        }\n\n        if (this.state === \"finished\" && this.speed < 0) {\n            this.startTime += this.calculatedDuration\n        }\n\n        this.holdTime = null\n\n        /**\n         * Set playState to running only after we've used it in\n         * the previous logic.\n         */\n        this.state = \"running\"\n\n        this.driver.start()\n    }\n\n    pause() {\n        this.state = \"paused\"\n        this.updateTime(time.now())\n        this.holdTime = this.currentTime\n    }\n\n    /**\n     * This method is bound to the instance to fix a pattern where\n     * animation.stop is returned as a reference from a useEffect.\n     */\n    stop = () => {\n        const { motionValue } = this.options\n        if (motionValue && motionValue.updatedAt !== time.now()) {\n            this.tick(time.now())\n        }\n\n        this.isStopped = true\n        if (this.state === \"idle\") return\n        this.teardown()\n        this.options.onStop?.()\n    }\n\n    complete() {\n        if (this.state !== \"running\") {\n            this.play()\n        }\n\n        this.state = \"finished\"\n        this.holdTime = null\n    }\n\n    finish() {\n        this.notifyFinished()\n        this.teardown()\n        this.state = \"finished\"\n\n        this.options.onComplete?.()\n    }\n\n    cancel() {\n        this.holdTime = null\n        this.startTime = 0\n        this.tick(0)\n        this.teardown()\n        this.options.onCancel?.()\n    }\n\n    private teardown() {\n        this.state = \"idle\"\n        this.stopDriver()\n        this.startTime = this.holdTime = null\n        activeAnimations.mainThread--\n    }\n\n    private stopDriver() {\n        if (!this.driver) return\n        this.driver.stop()\n        this.driver = undefined\n    }\n\n    sample(sampleTime: number): AnimationState<T> {\n        this.startTime = 0\n        return this.tick(sampleTime, true)\n    }\n\n    attachTimeline(timeline: TimelineWithFallback): VoidFunction {\n        if (this.options.allowFlatten) {\n            this.options.type = \"keyframes\"\n            this.options.ease = \"linear\"\n            this.initAnimation()\n        }\n\n        this.driver?.stop()\n        return timeline.observe(this)\n    }\n}\n\n// Legacy function support\nexport function animateValue<T extends number | string>(\n    options: ValueAnimationOptions<T>\n) {\n    return new JSAnimation(options)\n}\n"],"names":["keyframesGenerator","keyframes"],"mappings":";;;;;;;;;;;;;AA6BA,MAAM,iBAAiB,GAAG,CAAC,OAAe,KAAK,OAAO,GAAG,GAAG;AAEtD,MAAO,WACT,SAAQ,WAAW,CAAA;AA2DnB,IAAA,WAAA,CAAY,OAAiC,EAAA;AACzC,QAAA,KAAK,EAAE;QAzDX,IAAA,CAAA,KAAK,GAAuB,MAAM;QAElC,IAAA,CAAA,SAAS,GAAkB,IAAI;QAQvB,IAAA,CAAA,SAAS,GAAG,KAAK;AAYzB;;AAEG;QACK,IAAA,CAAA,WAAW,GAAW,CAAC;AAE/B;;AAEG;QACK,IAAA,CAAA,QAAQ,GAAkB,IAAI;AAEtC;;AAEG;QACK,IAAA,CAAA,aAAa,GAAG,CAAC;AAYzB;;;AAGG;AACK,QAAA,IAAA,CAAA,UAAU,GAAsB;AACpC,YAAA,IAAI,EAAE,KAAK;AACX,YAAA,KAAK,EAAE,SAAyB;SACnC;AA0YD;;;AAGG;QACH,IAAA,CAAA,IAAI,GAAG,MAAK;AACR,YAAA,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,OAAO;YACpC,IAAI,WAAW,IAAI,WAAW,CAAC,SAAS,KAAK,IAAI,CAAC,GAAG,EAAE,EAAE;gBACrD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACzB;AAEA,YAAA,IAAI,CAAC,SAAS,GAAG,IAAI;AACrB,YAAA,IAAI,IAAI,CAAC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