misc: optimize how expandable images are handled
This commit is contained in:
1 parent
60dfbabc60
commit
62044ce3b7
5 files changed
+68
-53
No files matched your search
@@ -21,6 +21,7 @@
|
||||
import PostMediaCompact from '$lib/components/lemmy/post/media/PostMediaCompact.svelte'
|
||||
import PostBody from './PostBody.svelte'
|
||||
import { profile } from '$lib/auth'
|
||||
import { goto } from '$app/navigation'
|
||||
|
||||
export let post: PostView
|
||||
export let actions: boolean = true
|
||||
@@ -35,7 +36,7 @@
|
||||
<Material
|
||||
color={view != 'card' ? 'none' : 'distinct'}
|
||||
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'
|
||||
? 'py-4'
|
||||
: view == 'list'
|
||||
@@ -43,13 +44,21 @@
|
||||
: 'py-5'} {$$props.class}"
|
||||
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
|
||||
class="flex {$userSettings.leftAlign
|
||||
? 'flex-row-reverse'
|
||||
: '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">
|
||||
<div class="flex flex-col w-full gap-2 z-10">
|
||||
<PostMeta
|
||||
community={hideCommunity ? undefined : post.community}
|
||||
user={post.creator}
|
||||
@@ -83,7 +92,9 @@
|
||||
</a>
|
||||
{/if}
|
||||
</div>
|
||||
<PostMedia bind:post={post.post} {view} {type} />
|
||||
<div class="contents z-50 isolate">
|
||||
<PostMedia bind:post={post.post} {view} {type} />
|
||||
</div>
|
||||
{#if post.post.body && !post.post.nsfw && view != 'compact'}
|
||||
<PostBody body={post.post.body} {view} />
|
||||
{/if}
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
type MediaType,
|
||||
iframeType,
|
||||
} 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 { isImage, isVideo } from '$lib/ui/image'
|
||||
import type { Post } from 'lemmy-js-client'
|
||||
@@ -25,40 +27,37 @@
|
||||
{#if type == 'image'}
|
||||
{#if view == 'card' || view == 'cozy'}
|
||||
<!--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
|
||||
this={$userSettings.expandImages ? 'button' : 'a'}
|
||||
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"
|
||||
data-sveltekit-preload-data="off"
|
||||
aria-label={post.name}
|
||||
on:click={() => showImage(bestImageURL(post, false, 2048))}
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<svelte:element
|
||||
this={$userSettings.expandImages ? 'div' : 'a'}
|
||||
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"
|
||||
data-sveltekit-preload-data="off"
|
||||
aria-label={post.name}
|
||||
>
|
||||
<picture class="max-h-[inherit]">
|
||||
<source
|
||||
srcset={bestImageURL(post, false, 512)}
|
||||
media="(max-width: 256px)"
|
||||
/>
|
||||
<source
|
||||
srcset={bestImageURL(post, false, 512)}
|
||||
media="(max-width: 512px)"
|
||||
/>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src={bestImageURL(post, false, 1024)}
|
||||
loading="lazy"
|
||||
class="max-h-[inherit] max-w-full h-auto z-30
|
||||
<picture class="max-h-[inherit]">
|
||||
<source
|
||||
srcset={bestImageURL(post, false, 512)}
|
||||
media="(max-width: 256px)"
|
||||
/>
|
||||
<source
|
||||
srcset={bestImageURL(post, false, 512)}
|
||||
media="(max-width: 512px)"
|
||||
/>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src={bestImageURL(post, false, 1024)}
|
||||
loading="lazy"
|
||||
class="max-h-[inherit] max-w-full h-auto z-30
|
||||
transition-opacity duration-300 object-contain mx-auto"
|
||||
width={512}
|
||||
height={300}
|
||||
class:blur-3xl={post.nsfw && $userSettings.nsfwBlur}
|
||||
/>
|
||||
</picture>
|
||||
</svelte:element>
|
||||
</svelte:component>
|
||||
width={512}
|
||||
height={300}
|
||||
class:blur-3xl={post.nsfw && $userSettings.nsfwBlur}
|
||||
/>
|
||||
</picture>
|
||||
</svelte:element>
|
||||
{/if}
|
||||
{:else if (type == 'iframe' || type == 'video') && (view == 'cozy' || view == 'card') && post.url}
|
||||
<PostIframe
|
||||
|
||||
Reference in new issue
Block a user