add opacity/easing parameters to blur transition

pull/3529/head
Richard Harris 5 years ago
parent 8196c194dd
commit c48325f7bd

@ -1,10 +1,12 @@
import { cubicOut, cubicInOut } from 'svelte/easing'; import { cubicOut, cubicInOut } from 'svelte/easing';
import { assign, is_function } from 'svelte/internal'; import { assign, is_function } from 'svelte/internal';
type EasingFunction = (t: number) => number;
export interface TransitionConfig { export interface TransitionConfig {
delay?: number; delay?: number;
duration?: number; duration?: number;
easing?: (t: number) => number; easing?: EasingFunction;
css?: (t: number, u: number) => string; css?: (t: number, u: number) => string;
tick?: (t: number, u: number) => void; tick?: (t: number, u: number) => void;
} }
@ -12,20 +14,29 @@ export interface TransitionConfig {
interface BlurParams { interface BlurParams {
delay: number; delay: number;
duration: number; duration: number;
easing?: EasingFunction;
amount: number; amount: number;
opacity: number;
} }
export function blur(node: Element, { export function blur(node: Element, {
delay = 0, delay = 0,
duration = 400, duration = 400,
amount = 5 easing = cubicInOut,
amount = 5,
opacity = 0
}: BlurParams): TransitionConfig { }: BlurParams): TransitionConfig {
const f = getComputedStyle(node).filter.replace(/^none$/, ''); const style = getComputedStyle(node);
const target_opacity = +style.opacity;
const f = style.filter === 'none' ? '' : style.filter;
const od = target_opacity * (1 - opacity);
return { return {
delay, delay,
duration, duration,
css: (t, u) => `opacity: ${t}; filter: ${f} blur(${u * amount}px);` easing,
css: (t, u) => `opacity: ${target_opacity - (od * u)}; filter: ${f} blur(${u * amount}px);`
}; };
} }
@ -50,7 +61,7 @@ export function fade(node: Element, {
interface FlyParams { interface FlyParams {
delay: number; delay: number;
duration: number; duration: number;
easing: (t: number) => number; easing: EasingFunction;
x: number; x: number;
y: number; y: number;
opacity: number; opacity: number;
@ -83,7 +94,7 @@ export function fly(node: Element, {
interface SlideParams { interface SlideParams {
delay: number; delay: number;
duration: number; duration: number;
easing: (t: number) => number; easing: EasingFunction;
} }
export function slide(node: Element, { export function slide(node: Element, {
@ -121,7 +132,7 @@ export function slide(node: Element, {
interface ScaleParams { interface ScaleParams {
delay: number; delay: number;
duration: number; duration: number;
easing: (t: number) => number; easing: EasingFunction;
start: number; start: number;
opacity: number; opacity: number;
} }
@ -155,7 +166,7 @@ interface DrawParams {
delay: number; delay: number;
speed: number; speed: number;
duration: number | ((len: number) => number); duration: number | ((len: number) => number);
easing: (t: number) => number; easing: EasingFunction;
} }
export function draw(node: SVGElement & { getTotalLength(): number }, { export function draw(node: SVGElement & { getTotalLength(): number }, {
@ -187,7 +198,7 @@ export function draw(node: SVGElement & { getTotalLength(): number }, {
interface CrossfadeParams { interface CrossfadeParams {
delay: number; delay: number;
duration: number | ((len: number) => number); duration: number | ((len: number) => number);
easing: (t: number) => number; easing: EasingFunction;
} }
type ClientRectMap = Map<any, { rect: ClientRect }>; type ClientRectMap = Map<any, { rect: ClientRect }>;

Loading…
Cancel
Save