]> git.r.bdr.sh - rbdr/forum/blame - src/lib/animations/blink.ts
Use supabase
[rbdr/forum] / src / lib / animations / blink.ts
CommitLineData
6347b8d9 1import { sineOut } from 'svelte/easing';
a7cf03c1 2import type { AnimationConfig } from 'svelte/animate';
6347b8d9 3
cac85db0
RBR
4export const blink = function blink(node: HTMLElement, params: AnimationConfig): AnimationConfig {
5 const originalWidth = parseFloat(getComputedStyle(node).width);
6 const originalHeight = parseFloat(getComputedStyle(node).height);
6347b8d9 7
cac85db0
RBR
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);
6347b8d9 19
cac85db0
RBR
20 return `width: ${width}px; height: ${height}px; margin: ${marginY}px ${marginX}px`;
21 }
22 };
6347b8d9 23};