{"version":3,"file":"ScrollSpring.mjs","sources":["../../../src/components/trackpad/ScrollSpring.ts"],"sourcesContent":["import { type ConstrainEase } from './SlidingNumber';\nimport { Spring } from './Spring';\n\n/**\n * ScrollSpring implements a physics-based spring animation for smooth scrolling transitions.\n * It handles both momentum-based movement and spring-to-target behavior when reaching constraints.\n *\n * Features:\n * - Smooth spring-based animation\n * - Direction-aware speed correction\n * - Configurable spring parameters\n * - Implements ConstrainEase interface for use with SlidingNumber\n *\n * @example\n * ```typescript\n * // Create a scroll spring with custom parameters\n * const spring = new ScrollSpring({\n *     tension: 0.3,\n *     friction: 0.8\n * });\n *\n * // Initialize spring animation\n * spring.start(currentSpeed, startPosition, targetPosition);\n *\n * // Update loop\n * ticker.add(() => {\n *     if (!spring.done) {\n *         const position = spring.update();\n *         container.y = position;\n *     }\n * });\n * ```\n */\nexport class ScrollSpring implements ConstrainEase {\n    /** Whether the spring animation has completed */\n    public done!: boolean;\n    /** Target value the spring is animating towards */\n    public to: number;\n\n    /** Underlying spring physics implementation */\n    protected _spring: Spring;\n    /** Current position of the spring */\n    protected _pos: number;\n    /** Current speed of the movement */\n    protected _speed!: number;\n    /** Whether speed needs correction due to direction change */\n    protected _correctSpeed!: boolean;\n\n    constructor(springOptions: ConstructorParameters<typeof Spring>[0] = {}) {\n        this._spring = new Spring(springOptions);\n        this._pos = 0;\n        this.to = 0;\n    }\n\n    /**\n     * Initializes a new spring animation\n     * @param speed Initial velocity of the movement\n     * @param pos Starting position\n     * @param to Target position to animate towards\n     */\n    start(speed: number, pos: number, to: number): void {\n        this._speed = speed;\n        this._pos = pos;\n        this.to = to;\n        this.done = false;\n\n        this._spring.x = this._pos;\n        this._spring.tx = this.to;\n\n        const diff = this.to - this._pos;\n        const toDirection = Math.abs(diff) / diff;\n        const currentDirection = Math.abs(this._speed) / this._speed;\n\n        if (toDirection !== currentDirection) {\n            this._correctSpeed = true;\n        } else {\n            this._correctSpeed = false;\n        }\n    }\n\n    /**\n     * Updates the spring animation state\n     * @returns The new position after the spring calculation\n     */\n    update(): number {\n        if (this._correctSpeed) {\n            this._speed *= 0.6;\n\n            if (Math.abs(this._speed) < 2) {\n                this._correctSpeed = false;\n            }\n\n            this._pos += this._speed;\n\n            this._spring.x = this._pos;\n        } else {\n            const diff = this.to - this._pos;\n\n            if (Math.abs(diff) < 0.05) {\n                this._pos = this.to;\n                this.done = true;\n            } else {\n                this._spring.tx = this.to;\n                this._spring.update();\n                this._pos = this._spring.x;\n            }\n        }\n\n        return this._pos;\n    }\n}\n"],"names":[],"mappings":";;;;AAiCO,MAAM,aAAsC;AAAA,EAe/C,YAAY,gBAAyD,IAAI;AAblE;AAAA;AAEA;AAAA;AAGG;AAAA;AAEA;AAAA;AAEA;AAAA;AAEA;AAAA;AAGD,SAAA,UAAU,IAAI,OAAO,aAAa;AACvC,SAAK,OAAO;AACZ,SAAK,KAAK;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASd,MAAM,OAAe,KAAa,IAAkB;AAChD,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,SAAK,KAAK;AACV,SAAK,OAAO;AAEP,SAAA,QAAQ,IAAI,KAAK;AACjB,SAAA,QAAQ,KAAK,KAAK;AAEjB,UAAA,OAAO,KAAK,KAAK,KAAK;AAC5B,UAAM,cAAc,KAAK,IAAI,IAAI,IAAI;AACrC,UAAM,mBAAmB,KAAK,IAAI,KAAK,MAAM,IAAI,KAAK;AAEtD,QAAI,gBAAgB,kBAAkB;AAClC,WAAK,gBAAgB;AAAA,IAAA,OAClB;AACH,WAAK,gBAAgB;AAAA,IAAA;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA,EAOJ,SAAiB;AACb,QAAI,KAAK,eAAe;AACpB,WAAK,UAAU;AAEf,UAAI,KAAK,IAAI,KAAK,MAAM,IAAI,GAAG;AAC3B,aAAK,gBAAgB;AAAA,MAAA;AAGzB,WAAK,QAAQ,KAAK;AAEb,WAAA,QAAQ,IAAI,KAAK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