From f4c971dc8769f845cc48443dab020cb2e9df661a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Sat, 9 Aug 2025 17:23:35 +0200 Subject: refactor(background): cleaner and more logical --- src/component/MosaicBackground.astro | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/component') diff --git a/src/component/MosaicBackground.astro b/src/component/MosaicBackground.astro index df81a25..c8e01f5 100644 --- a/src/component/MosaicBackground.astro +++ b/src/component/MosaicBackground.astro @@ -20,17 +20,14 @@ const { height = "400" } = Astro.props; let currentWidth = 0; let i = 0; - const fn = () => { - let current = children[i++]; - let ratio = current.clientWidth / current.clientHeight; - line.appendChild(current.cloneNode(true)); - currentWidth += ratio * height; - }; - while (i < children.length) { // adding elements - while (i < children.length && currentWidth <= max) fn(); - if (i < children.length) fn(); + while (i < children.length && currentWidth <= max) { + let current = children[i++]; + let ratio = current.clientWidth / current.clientHeight; + line.appendChild(current.cloneNode(true)); + currentWidth += ratio * height; + } // setting height let h = (max * height) / currentWidth; line.style.height = `${h - 0.01}px`; -- cgit v1.2.3