From 933eba7dc3bdc979fefadd47388b20b8360e1d6b Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sat, 28 Sep 2024 17:47:52 +0800 Subject: style: prettier --- src/utils.mjs | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) (limited to 'src/utils.mjs') diff --git a/src/utils.mjs b/src/utils.mjs index ead3002..ad9131e 100644 --- a/src/utils.mjs +++ b/src/utils.mjs @@ -18,8 +18,8 @@ export const onRemove = (element, callback) => { } } }); - obs.observe(parent, { childList: true, }); -} + obs.observe(parent, { childList: true }); +}; /** * Animate transition of DOMRect, with Web Animation API @@ -32,18 +32,24 @@ export const onRemove = (element, callback) => { * @returns {Animation} https://developer.mozilla.org/en-US/docs/Web/API/Animation */ export const animateRectTransition = (element, rect, options = {}) => { - if (!element.parentElement) throw new Error("The node must already be attached"); + if (!element.parentElement) + throw new Error("The node must already be attached"); - const { width: w1, height: h1, left: x1, top: y1 } = rect - const { width: w2, height: h2, left: x2, top: y2 } = element.getBoundingClientRect() + const { width: w1, height: h1, left: x1, top: y1 } = rect; + const { + width: w2, + height: h2, + left: x2, + top: y2, + } = element.getBoundingClientRect(); - const rw = (w1 ?? w2) / w2 - const rh = (h1 ?? h2) / h2 + const rw = (w1 ?? w2) / w2; + const rh = (h1 ?? h2) / h2; const dx = x1 - x2; const dy = y1 - y2; - if (dx === 0 && dy === 0 || !isFinite(rw) || !isFinite(rh)) { - return element.animate([], { duration: 0 }) + if ((dx === 0 && dy === 0) || !isFinite(rw) || !isFinite(rh)) { + return element.animate([], { duration: 0 }); } const transform1 = `translate(0, 0) scale(1, 1)`; @@ -51,18 +57,14 @@ export const animateRectTransition = (element, rect, options = {}) => { const keyframes = [ { transform: transform1, opacity: 1 }, { transform: transform2, opacity: 0.3 }, - ] - if (options.resume === true) keyframes.reverse() - - return element.animate( - keyframes, - { - duration: options.duration ?? 500, - easing: 'ease-in-out', - } - ); -} + ]; + if (options.resume === true) keyframes.reverse(); + return element.animate(keyframes, { + duration: options.duration ?? 500, + easing: "ease-in-out", + }); +}; /** * Throttle for function call @@ -74,13 +76,13 @@ export const animateRectTransition = (element, rect, options = {}) => { export function throttle(func, delay) { let timerFlag = null; - return function(...args) { - const context = this - if (timerFlag !== null) return null + return function (...args) { + const context = this; + if (timerFlag !== null) return null; timerFlag = setTimeout( - () => timerFlag = null, - typeof delay === 'function' ? delay.call(context) : delay + () => (timerFlag = null), + typeof delay === "function" ? delay.call(context) : delay, ); return func.call(context, ...args); -- cgit v1.2.3-70-g09d2