]> git.r.bdr.sh - rbdr/forum/blame_incremental - src/lib/animations/blink.ts
Apply formatting
[rbdr/forum] / src / lib / animations / blink.ts
... / ...
CommitLineData
1import { sineOut } from 'svelte/easing';
2import type { AnimationConfig } from 'svelte/animate';
3
4export const blink = function blink(node: HTMLElement, params: AnimationConfig): AnimationConfig {
5 const originalWidth = parseFloat(getComputedStyle(node).width);
6 const originalHeight = parseFloat(getComputedStyle(node).height);
7
8 return {
9 delay: params.delay || 0,
10 duration: params.duration || 400,
11 easing: params.easing || sineOut,
12 css: (t: number): string => {
13 const halfWidth = originalWidth / 2;
14 const halfHeight = originalHeight / 2;
15 const height = Math.round(t <= 0.2 ? (originalHeight * t) / 0.2 : originalHeight);
16 const marginY = Math.round(t <= 0.2 ? halfHeight * (1 - t / 0.2) : 0);
17 const width = Math.round(t > 0.2 ? ((t - 0.2) / 0.8) * originalWidth : 0);
18 const marginX = Math.round(t > 0.2 ? (1 - (t - 0.2) / 0.8) * halfWidth : halfWidth);
19
20 return `width: ${width}px; height: ${height}px; margin: ${marginY}px ${marginX}px`;
21 }
22 };
23};