From f19081ee1d163e87ba79dc4acaa84ffe9b3745cf Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Fri, 23 Jan 2026 18:58:15 -0600 Subject: [PATCH] feat(artist): smart 3-line bio truncation with resize detection - Use CSS line-clamp for exactly 3 lines (reactive to container width) - ResizeObserver detects window/container resizes - Auto-hide Read more/Show less if text fits in 3 lines - Works across all screen sizes (4K to HD) --- .../components/views/ArtistDetailView.svelte | 63 +++++++++++++++---- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/src/lib/components/views/ArtistDetailView.svelte b/src/lib/components/views/ArtistDetailView.svelte index 300c92ef6..d34f2fbad 100644 --- a/src/lib/components/views/ArtistDetailView.svelte +++ b/src/lib/components/views/ArtistDetailView.svelte @@ -212,6 +212,7 @@ if (!artistId || !artistName) return; bioExpanded = false; + isBioTruncated = false; imageError = false; topTracks = []; similarArtists = []; @@ -574,14 +575,43 @@ artist.biography?.content || artist.biography?.summary || null ); - // Truncate bio for collapsed view (reduced to ~530 chars, 2/3 of original 800) - const BIO_TRUNCATE_LENGTH = 530; - let truncatedBio = $derived( - bioText && bioText.length > BIO_TRUNCATE_LENGTH - ? bioText.slice(0, BIO_TRUNCATE_LENGTH) + '...' - : bioText - ); - let bioNeedsTruncation = $derived(bioText ? bioText.length > BIO_TRUNCATE_LENGTH : false); + // Smart 3-line truncation with resize detection + let bioTextEl = $state(null); + let isBioTruncated = $state(false); + + function checkBioTruncation() { + if (!bioTextEl || bioExpanded) return; + // scrollHeight > clientHeight means content is overflowing (truncated by line-clamp) + isBioTruncated = bioTextEl.scrollHeight > bioTextEl.clientHeight + 1; + } + + $effect(() => { + if (!bioTextEl || !bioText) return; + + // Initial check + checkBioTruncation(); + + // Observe resize to recalculate when container width changes + const observer = new ResizeObserver(() => { + if (!bioExpanded) { + checkBioTruncation(); + } + }); + + observer.observe(bioTextEl); + + return () => observer.disconnect(); + }); + + // Recheck truncation after collapsing (wait for DOM update) + $effect(() => { + if (bioExpanded === false && bioTextEl) { + // Use requestAnimationFrame to wait for CSS to apply + requestAnimationFrame(() => { + checkBioTruncation(); + }); + } + }); let hasMoreAlbums = $derived(!!onLoadMore && artist.albumsFetched < artist.totalAlbums); let hasTopTracks = $derived(topTracks.length > 0 || tracksLoading); @@ -848,10 +878,10 @@ {#if bioText}
-
- {@html bioExpanded ? bioText : truncatedBio} +
+ {@html bioText}
- {#if bioNeedsTruncation} + {#if isBioTruncated || bioExpanded}