| 
1 |  | -import { Readable } from '../store/public.js';  | 
2 |  | -import { SpringUpdateOpts, TweenedOptions, Updater } from './private.js';  | 
 | 1 | +import { Readable, type Unsubscriber } from '../store/public.js';  | 
 | 2 | +import { SpringUpdateOpts, TweenedOptions, Updater, SpringOpts } from './private.js';  | 
 | 3 | + | 
 | 4 | +// TODO we do declaration merging here in order to not have a breaking change (renaming the Spring interface)  | 
 | 5 | +// this means both the Spring class and the Spring interface are merged into one with some things only  | 
 | 6 | +// existing on one side. In Svelte 6, remove the type definition and move the jsdoc onto the class in spring.js  | 
3 | 7 | 
 
  | 
4 | 8 | export interface Spring<T> extends Readable<T> {  | 
5 |  | -set: (new_value: T, opts?: SpringUpdateOpts) => Promise<void>;  | 
 | 9 | +set(new_value: T, opts?: SpringUpdateOpts): Promise<void>;  | 
 | 10 | +/**  | 
 | 11 | + * @deprecated Only exists on the legacy `spring` store, not the `Spring` class  | 
 | 12 | + */  | 
6 | 13 | update: (fn: Updater<T>, opts?: SpringUpdateOpts) => Promise<void>;  | 
 | 14 | +/**  | 
 | 15 | + * @deprecated Only exists on the legacy `spring` store, not the `Spring` class  | 
 | 16 | + */  | 
 | 17 | +subscribe(fn: (value: T) => void): Unsubscriber;  | 
7 | 18 | precision: number;  | 
8 | 19 | damping: number;  | 
9 | 20 | stiffness: number;  | 
10 | 21 | }  | 
11 | 22 | 
 
  | 
 | 23 | +/**  | 
 | 24 | + * A wrapper for a value that behaves in a spring-like fashion. Changes to `spring.target` will cause `spring.current` to  | 
 | 25 | + * move towards it over time, taking account of the `spring.stiffness` and `spring.damping` parameters.  | 
 | 26 | + *  | 
 | 27 | + * ```svelte  | 
 | 28 | + * <script>  | 
 | 29 | + *	import { Spring } from 'svelte/motion';  | 
 | 30 | + *  | 
 | 31 | + *	const spring = new Spring(0);  | 
 | 32 | + * </script>  | 
 | 33 | + *  | 
 | 34 | + * <input type="range" bind:value={spring.target} />  | 
 | 35 | + * <input type="range" bind:value={spring.current} disabled />  | 
 | 36 | + * ```  | 
 | 37 | + */  | 
 | 38 | +export class Spring<T> {  | 
 | 39 | +constructor(value: T, options?: SpringOpts);  | 
 | 40 | + | 
 | 41 | +/**  | 
 | 42 | + * Create a spring whose value is bound to the return value of `fn`. This must be called  | 
 | 43 | + * inside an effect root (for example, during component initialisation).  | 
 | 44 | + *  | 
 | 45 | + * ```svelte  | 
 | 46 | + * <script>  | 
 | 47 | + *	import { Spring } from 'svelte/motion';  | 
 | 48 | + *  | 
 | 49 | + *	let { number } = $props();  | 
 | 50 | + *  | 
 | 51 | + *	const spring = Spring.of(() => number);  | 
 | 52 | + * </script>  | 
 | 53 | + * ```  | 
 | 54 | + */  | 
 | 55 | +static of<U>(fn: () => U, options?: SpringOpts): Spring<U>;  | 
 | 56 | + | 
 | 57 | +/**  | 
 | 58 | + * Sets `spring.target` to `value` and returns a `Promise` that resolves if and when `spring.current` catches up to it.  | 
 | 59 | + *  | 
 | 60 | + * If `options.instant` is `true`, `spring.current` immediately matches `spring.target`.  | 
 | 61 | + *  | 
 | 62 | + * If `options.preserveMomentum` is provided, the spring will continue on its current trajectory for  | 
 | 63 | + * the specified number of milliseconds. This is useful for things like 'fling' gestures.  | 
 | 64 | + */  | 
 | 65 | +set(value: T, options?: SpringUpdateOpts): Promise<void>;  | 
 | 66 | + | 
 | 67 | +damping: number;  | 
 | 68 | +precision: number;  | 
 | 69 | +stiffness: number;  | 
 | 70 | +/**  | 
 | 71 | + * The end value of the spring.  | 
 | 72 | + * This property only exists on the `Spring` class, not the legacy `spring` store.  | 
 | 73 | + */  | 
 | 74 | +target: T;  | 
 | 75 | +/**  | 
 | 76 | + * The current value of the spring.  | 
 | 77 | + * This property only exists on the `Spring` class, not the legacy `spring` store.  | 
 | 78 | + */  | 
 | 79 | +get current(): T;  | 
 | 80 | +}  | 
 | 81 | + | 
12 | 82 | export interface Tweened<T> extends Readable<T> {  | 
13 | 83 | set(value: T, opts?: TweenedOptions<T>): Promise<void>;  | 
14 | 84 | update(updater: Updater<T>, opts?: TweenedOptions<T>): Promise<void>;  | 
15 | 85 | }  | 
16 | 86 | 
 
  | 
17 |  | -export * from './index.js';  | 
 | 87 | +export { spring, tweened, Tween } from './index.js';  | 
0 commit comments