From 744adf2c5a234c22063dc9034ef79ae7c88c7e53 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 23 Nov 2023 20:37:22 -0800 Subject: feat(wrapped): calculate min width required --- src/lib/Tools/Wrapped.svelte | 58 +++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/src/lib/Tools/Wrapped.svelte b/src/lib/Tools/Wrapped.svelte index f8879814..3602c0e9 100644 --- a/src/lib/Tools/Wrapped.svelte +++ b/src/lib/Tools/Wrapped.svelte @@ -40,7 +40,33 @@ update().then(() => {}); } + const updateWidth = () => { + const wrappedContainer = document.querySelector('#wrapped') as HTMLElement; + let maxWidth = 0; + + if (!wrappedContainer) return; + + wrappedContainer.querySelectorAll('.category').forEach((item) => { + let category = item as HTMLElement; + + if (category.offsetWidth > maxWidth) { + maxWidth = category.offsetWidth; + } + }); + + wrappedContainer.style.width = `calc(${maxWidth * 2}px + 1%)`; + width = wrappedContainer.offsetWidth; + }; + onMount(async () => { + new MutationObserver((_mutations) => { + updateWidth(); + updateWidth(); + }).observe(document.querySelector('#wrapped')!, { + childList: true, + subtree: true + }); + if (user !== undefined) { if ($userIdentity === '') { userIdentity.set(JSON.stringify(await getUserIdentity(user))); @@ -210,10 +236,14 @@ Please log in to view this page. {:else if currentUserIdentity.id !== -1} {#await wrapped(user, currentUserIdentity)} - Loading ... + Loading ... {:then wrapped} -
-
+
+
User Avatar @@ -233,10 +263,10 @@
Days Active: {#await activityHistory(currentUserIdentity)} - Loading ... + Loading ... {:then activities} {#if activities === undefined} - Loading ... + Loading ... {:else} {fillMissingDays(activities, true).filter((a) => a.amount !== 0).length}/365 {/if} @@ -244,7 +274,7 @@
-
+
Anime
@@ -256,7 +286,7 @@
Episodes: {episodes}
-
+
Manga
@@ -270,7 +300,7 @@ Chapters: {chapters}
- - @@ -350,7 +380,8 @@ Include music
Include rewatches & rereads
Include specials and OVAs
- Width ({width} px):
+ Manual Width Override ({width} px): +
Fit long titles
{#if abbreviateTitles} Maximum title length
@@ -380,7 +411,7 @@ {/await} {:else} - Loading ... + Loading ... {/if}
@@ -396,7 +427,6 @@ padding: 2%; justify-content: center; /* filter: invert(0) !important; */ - background-color: #0b1622; font-family: Roboto, -apple-system, BlinkMacSystemFont, Segoe UI, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; } -- cgit v1.2.3