From e474ffe79c09d450b7891b28c09140030a3cae92 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 21 Feb 2024 22:49:29 -0500 Subject: [PATCH] type stuff --- .../src/internal/client/reactivity/computations.js | 3 ++- packages/svelte/src/internal/client/transitions.js | 9 ++++++--- packages/svelte/src/internal/client/types.d.ts | 7 +++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/svelte/src/internal/client/reactivity/computations.js b/packages/svelte/src/internal/client/reactivity/computations.js index 926159c067..ebcd224bd8 100644 --- a/packages/svelte/src/internal/client/reactivity/computations.js +++ b/packages/svelte/src/internal/client/reactivity/computations.js @@ -266,6 +266,7 @@ export function derived_safe_equal(fn) { * @param {() => void} done */ export function pause_effect(effect, done) { + /** @type {import('../types.js').TransitionObject[]} */ const transitions = []; pause_children(effect, transitions); @@ -291,7 +292,7 @@ export function pause_effect(effect, done) { /** * @param {import('../types.js').ComputationSignal} effect - * @param {TODO[]} transitions + * @param {import('../types.js').TransitionObject[]} transitions */ function pause_children(effect, transitions) { effect.f |= INERT; diff --git a/packages/svelte/src/internal/client/transitions.js b/packages/svelte/src/internal/client/transitions.js index 962eb2acec..805e6e24be 100644 --- a/packages/svelte/src/internal/client/transitions.js +++ b/packages/svelte/src/internal/client/transitions.js @@ -516,16 +516,19 @@ export function bind_transition(element, get_fn, get_params, direction, global) /** @type {Animation | null} */ let current_animation; - /** @type {TODO} */ + /** @type {import('./types.js').TransitionPayload | null} */ let current_options; let current_delta = 0; + /** @type {import('./types.js').TransitionObject} */ const transition = { global, to(target, callback) { if (current_animation && current_options) { - p = current_delta * (current_animation.currentTime / current_options.duration); + const time = /** @type {number} */ (current_animation.currentTime); + const duration = /** @type {number} */ (current_options.duration); + p = (current_delta * time) / duration; current_animation.cancel(); } @@ -545,7 +548,7 @@ export function bind_transition(element, get_fn, get_params, direction, global) current_delta = target - p; for (let i = 0; i <= n; i += 1) { - const t = current_options.easing(p + (current_delta * i) / n); + const t = (current_options.easing ?? linear)(p + (current_delta * i) / n); const css = current_options.css(t, 1 - t); keyframes.push(css_to_keyframe(css)); } diff --git a/packages/svelte/src/internal/client/types.d.ts b/packages/svelte/src/internal/client/types.d.ts index 028f81af43..06b015be98 100644 --- a/packages/svelte/src/internal/client/types.d.ts +++ b/packages/svelte/src/internal/client/types.d.ts @@ -421,3 +421,10 @@ export interface ProxyMetadata> { export type ProxyStateObject> = T & { [STATE_SYMBOL]: ProxyMetadata; }; + +// TODO remove the other transition types once we're +// happy we don't need them, and rename this +export interface TransitionObject { + global: boolean; + to(target: number, callback?: () => void): void; +}