misc: optimize how expandable images are handled

This commit is contained in:
Xylight committed 2024-02-24 09:54:02 -08:00
1 parent 60dfbabc60
commit 62044ce3b7
5 files changed
+42 -27

No files matched your search

+3
View File
@@ -17,6 +17,9 @@ declare global {
} }
} }
} }
interface PageState {
openImage: url
}
// interface Platform {} // interface Platform {}
} }
declare const __VERSION__: string declare const __VERSION__: string
+13 -2
View File
@@ -21,6 +21,7 @@
import PostMediaCompact from '$lib/components/lemmy/post/media/PostMediaCompact.svelte' import PostMediaCompact from '$lib/components/lemmy/post/media/PostMediaCompact.svelte'
import PostBody from './PostBody.svelte' import PostBody from './PostBody.svelte'
import { profile } from '$lib/auth' import { profile } from '$lib/auth'
import { goto } from '$app/navigation'
export let post: PostView export let post: PostView
export let actions: boolean = true export let actions: boolean = true
@@ -35,7 +36,7 @@
<Material <Material
color={view != 'card' ? 'none' : 'distinct'} color={view != 'card' ? 'none' : 'distinct'}
padding="none" padding="none"
class="relative max-w-full min-w-0 w-full group class="relative max-w-full min-w-0 w-full group z-10 isolation-auto
{view != 'card' ? 'bg-transparent !border-0' : 'p-5'} {view == 'compact' {view != 'card' ? 'bg-transparent !border-0' : 'p-5'} {view == 'compact'
? 'py-4' ? 'py-4'
: view == 'list' : view == 'list'
@@ -43,13 +44,21 @@
: 'py-5'} {$$props.class}" : 'py-5'} {$$props.class}"
id={post.post.id} id={post.post.id}
> >
{#if view == 'cozy' || view == 'list'}
<button
on:click={() => goto(postLink(post.post))}
class="-z-20 bg-slate-50 dark:bg-zinc-900 rounded-xl absolute -mx-6 top-0 left-0 w-[calc(100%+3rem)]
h-full opacity-0 scale-95 group-hover:scale-[99%] group-hover:opacity-100 transition-all
"
></button>
{/if}
<div <div
class="flex {$userSettings.leftAlign class="flex {$userSettings.leftAlign
? 'flex-row-reverse' ? 'flex-row-reverse'
: 'flex-row'} gap-4 max-w-full w-full min-w-0" : 'flex-row'} gap-4 max-w-full w-full min-w-0"
> >
<div class="flex flex-col w-full gap-2 flex-1 max-w-full min-w-0"> <div class="flex flex-col w-full gap-2 flex-1 max-w-full min-w-0">
<div class="flex flex-col w-full gap-2"> <div class="flex flex-col w-full gap-2 z-10">
<PostMeta <PostMeta
community={hideCommunity ? undefined : post.community} community={hideCommunity ? undefined : post.community}
user={post.creator} user={post.creator}
@@ -83,7 +92,9 @@
</a> </a>
{/if} {/if}
</div> </div>
<div class="contents z-50 isolate">
<PostMedia bind:post={post.post} {view} {type} /> <PostMedia bind:post={post.post} {view} {type} />
</div>
{#if post.post.body && !post.post.nsfw && view != 'compact'} {#if post.post.body && !post.post.nsfw && view != 'compact'}
<PostBody body={post.post.body} {view} /> <PostBody body={post.post.body} {view} />
{/if} {/if}
@@ -7,7 +7,9 @@
type MediaType, type MediaType,
iframeType, iframeType,
} from '$lib/components/lemmy/post/helpers.js' } from '$lib/components/lemmy/post/helpers.js'
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte' import ExpandableImage, {
showImage,
} from '$lib/components/ui/ExpandableImage.svelte'
import { userSettings } from '$lib/settings.js' import { userSettings } from '$lib/settings.js'
import { isImage, isVideo } from '$lib/ui/image' import { isImage, isVideo } from '$lib/ui/image'
import type { Post } from 'lemmy-js-client' import type { Post } from 'lemmy-js-client'
@@ -25,17 +27,15 @@
{#if type == 'image'} {#if type == 'image'}
{#if view == 'card' || view == 'cozy'} {#if view == 'card' || view == 'cozy'}
<!--disabled preloads here since most people will hover over every image while scrolling--> <!--disabled preloads here since most people will hover over every image while scrolling-->
<svelte:component
this={$userSettings.expandImages ? ExpandableImage : Empty}
url={bestImageURL(post, false, 2048)}
class="container mx-auto w-fit"
>
<svelte:element <svelte:element
this={$userSettings.expandImages ? 'div' : 'a'} this={$userSettings.expandImages ? 'button' : 'a'}
href={postLink(post)} href={postLink(post)}
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900 bg-gradient-to-br from-blue-500/5 to-pink-500/5" class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900 bg-gradient-to-br from-blue-500/5 to-pink-500/5"
data-sveltekit-preload-data="off" data-sveltekit-preload-data="off"
aria-label={post.name} aria-label={post.name}
on:click={() => showImage(bestImageURL(post, false, 2048))}
role="button"
tabindex="0"
> >
<picture class="max-h-[inherit]"> <picture class="max-h-[inherit]">
<source <source
@@ -58,7 +58,6 @@
/> />
</picture> </picture>
</svelte:element> </svelte:element>
</svelte:component>
{/if} {/if}
{:else if (type == 'iframe' || type == 'video') && (view == 'cozy' || view == 'card') && post.url} {:else if (type == 'iframe' || type == 'video') && (view == 'cozy' || view == 'card') && post.url}
<PostIframe <PostIframe
+16 -17
View File
@@ -1,4 +1,15 @@
<script lang="ts" context="module">
import { pushState } from '$app/navigation'
export function showImage(url: string, alt: string = '') {
pushState('', {
openImage: url,
})
}
</script>
<script lang="ts"> <script lang="ts">
import { page } from '$app/stores'
import { Button } from 'mono-svelte' import { Button } from 'mono-svelte'
import { Icon, XMark } from 'svelte-hero-icons' import { Icon, XMark } from 'svelte-hero-icons'
import { expoOut } from 'svelte/easing' import { expoOut } from 'svelte/easing'
@@ -7,18 +18,10 @@
/** /**
* The full-resolution image URL * The full-resolution image URL
*/ */
export let url: string
export let alt: string = '' export let alt: string = ''
export let open: boolean = false
</script> </script>
<svelte:body {#if $page.state.openImage || '' != ''}
on:keydown={(e) => {
if (open && e.code == 'Escape') open = false
}}
/>
{#if open}
<!-- svelte-ignore a11y-no-noninteractive-tabindex --> <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
<!-- svelte-ignore a11y-no-static-element-interactions --> <!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-click-events-have-key-events --> <!-- svelte-ignore a11y-click-events-have-key-events -->
@@ -27,19 +30,15 @@
class="!isolate fixed top-0 left-0 w-screen h-screen overflow-auto bg-black/50 class="!isolate fixed top-0 left-0 w-screen h-screen overflow-auto bg-black/50
flex flex-col z-[200] overscroll-contain" flex flex-col z-[200] overscroll-contain"
transition:fade={{ duration: 200 }} transition:fade={{ duration: 200 }}
on:click={() => (open = false)} on:click={() => history.back()}
>
<Button
size="square-md"
class="fixed z-[110] top-0 right-0 m-4"
on:click={() => (open = false)}
> >
<Button size="square-md" class="fixed z-[110] top-0 right-0 m-4">
<Icon src={XMark} size="16" mini slot="prefix" /> <Icon src={XMark} size="16" mini slot="prefix" />
</Button> </Button>
<img <img
width={400} width={400}
height={400} height={400}
src={url} src={$page.state.openImage}
class="w-full h-auto object-contain max-w-screen-sm mx-auto my-auto overscroll-contain bg-white dark:bg-zinc-900" class="w-full h-auto object-contain max-w-screen-sm mx-auto my-auto overscroll-contain bg-white dark:bg-zinc-900"
transition:scale={{ start: 0.9, easing: expoOut }} transition:scale={{ start: 0.9, easing: expoOut }}
{alt} {alt}
@@ -47,6 +46,6 @@
</div> </div>
{/if} {/if}
<button on:click={() => (open = !open)} class="contents {$$props.class}"> <button on:click={() => history.back()} class="contents {$$props.class}">
<slot /> <slot />
</button> </button>
+3
View File
@@ -18,6 +18,7 @@
import Shell from '$lib/components/ui/layout/Shell.svelte' import Shell from '$lib/components/ui/layout/Shell.svelte'
import SiteCard from '$lib/components/lemmy/SiteCard.svelte' import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
import { site } from '$lib/lemmy.js' import { site } from '$lib/lemmy.js'
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
nProgress.configure({ nProgress.configure({
minimum: 0.4, minimum: 0.4,
@@ -83,6 +84,8 @@
> >
<Moderation /> <Moderation />
<ToastContainer /> <ToastContainer />
<ExpandableImage />
<Navbar <Navbar
slot="navbar" slot="navbar"
let:style={s} let:style={s}