pull/4999/head
pushkine 5 years ago
parent 398aa59eb5
commit 5d0430e795

@ -2,10 +2,11 @@ import { run_transition } from './transitions';
import { methodify, noop } from './utils'; import { methodify, noop } from './utils';
import { CssTransitionConfig } from 'svelte/transition'; import { CssTransitionConfig } from 'svelte/transition';
type AnimationFn = (node: Element, { from, to }: { from: DOMRect; to: DOMRect }, params: any) => CssTransitionConfig; type Rect = DOMRect | ClientRect;
type AnimationFn = (node: Element, { from, to }: { from: Rect; to: Rect }, params: any) => CssTransitionConfig;
export const run_animation = /*#__PURE__*/ methodify( export const run_animation = /*#__PURE__*/ methodify(
function run_animation(this: HTMLElement, from: DOMRect, fn: AnimationFn, params = {}) { function run_animation(this: HTMLElement, from: Rect, fn: AnimationFn, params = {}) {
if (!from) return noop; if (!from) return noop;
return run_transition( return run_transition(
this, this,
@ -22,7 +23,7 @@ export const run_animation = /*#__PURE__*/ methodify(
); );
export const fix_position = /*#__PURE__*/ methodify( export const fix_position = /*#__PURE__*/ methodify(
function fix_position(this: HTMLElement, { left, top }: DOMRect) { function fix_position(this: HTMLElement, { left, top }: Rect) {
const { position, width, height, transform } = getComputedStyle(this); const { position, width, height, transform } = getComputedStyle(this);
if (position === 'absolute' || position === 'fixed') return noop; if (position === 'absolute' || position === 'fixed') return noop;
const { position: og_position, width: og_width, height: og_height } = this.style; const { position: og_position, width: og_width, height: og_height } = this.style;

@ -84,7 +84,7 @@ export const setTweenTimeout = (
is_outro = false is_outro = false
): TaskCanceller => { ): TaskCanceller => {
let running = true; let running = true;
let t = 1 - (end_time - now) / duration || 0; let t = 1 - (end_time - now()) / duration || 0;
if (!is_outro && t <= 1.0) run(t >= 0.0 ? t : 0); if (!is_outro && t <= 1.0) run(t >= 0.0 ? t : 0);
unsafe_loop((now) => { unsafe_loop((now) => {
if (!running) return false; if (!running) return false;

@ -61,7 +61,7 @@ const swap = (fn, rx) =>
? (t) => fn(t, 1 - t) ? (t) => fn(t, 1 - t)
: (t) => fn(1 - t, t); : (t) => fn(1 - t, t);
const mirrored = (fn, rx, easing) => { const mirrored = (fn, rx, easing, _start, _end) => {
const run = swap(fn, rx); const run = swap(fn, rx);
return easing return easing
? rx & tx.intro ? rx & tx.intro
@ -76,7 +76,7 @@ const reversed = (fn, rx, easing, start = 0, end = 1) => {
? (t) => run(start + difference * easing(t)) ? (t) => run(start + difference * easing(t))
: (t) => run(start + difference * t); : (t) => run(start + difference * t);
}; };
export const enum tx { const enum tx {
intro = 1, intro = 1,
outro = 2, outro = 2,
reverse = 3, reverse = 3,

Loading…
Cancel
Save