impr: improve semantics and optimize elements

This commit is contained in:
James Xylight committed 2025-08-31 16:04:56 -07:00
1 parent 8d3ec68160
commit 1c55baac5b
15 files changed
+167 -195

No files matched your search

@@ -32,6 +32,7 @@
icon?: import('svelte').Snippet
children?: Snippet
resolveObject?: boolean
actions?: boolean
}
let {
@@ -42,6 +43,7 @@
icon,
children,
resolveObject,
actions = true,
}: Props = $props()
</script>
@@ -64,12 +66,10 @@
class="flex-1 w-full overflow-hidden"
data-sveltekit-preload-data="tap"
>
<div
class="flex {view == 'cozy'
? 'flex-col gap-2'
: 'flex-row'} gap-2 items-center"
>
{#if icon}{@render icon()}{:else if community.community.nsfw && settings.nsfwBlur}
<div class="flex flex-row gap-2 items-center">
{#if icon}
{@render icon()}
{:else if community.community.nsfw && settings.nsfwBlur}
<div class="w-8 h-8 rounded-xl bg-red-400"></div>
{:else}
<Avatar
@@ -143,7 +143,7 @@
</div>
</div>
</a>
{#if children}
{#if children || !actions}
{@render children?.()}
{:else}
<div class="flex flex-row items-center gap-2">
+1 -8
View File
@@ -78,7 +78,7 @@
-->
<article
class={[
'post relative max-w-full min-w-0 w-full cursor-pointer outline-hidden group/post',
'relative cursor-pointer group/post',
settings.leftAlign && 'left-align',
view == 'compact' && 'py-3 list-type compact',
view == 'cozy' && 'py-5 flex flex-col gap-2',
@@ -141,13 +141,6 @@
{#if actions}
<PostActions {onhide} bind:post style="grid-area: actions;" {view} />
{/if}
<div
class="absolute overflow-hidden inset-0
sm:rounded-xl bg-slate-50 dark:bg-zinc-900
opacity-0 transition-all -z-50 no-list-margin
group-hover/post:inset-y-0.5 group-hover/post:-inset-x-3 sm:group-hover/post:-inset-x-5 group-hover/post:opacity-100
duration-150"
></div>
</article>
<style lang="postcss">
+17 -15
View File
@@ -147,7 +147,6 @@
{#snippet target(attachment)}
<button
{@attach attachment}
class={[
'row-span-2 shrink-0 mr-2 self-center group/btn',
'bg-slate-200 dark:bg-zinc-800 rounded-lg cursor-pointer',
@@ -339,16 +338,10 @@
</div>
</header>
{#if title && id}
<a
href={settings.posts.titleOpensUrl && postUrl
? postUrl
: `/post/${encodeURIComponent(instance.data)}/${id}`}
target={settings.posts.titleOpensUrl || settings.openLinksInNewTab
? '_blank'
: undefined}
{@const useAttachedUrl = settings.posts.titleOpensUrl && postUrl}
<h3
class={[
'inline max-sm:mt-0!',
'hover:underline hover:text-primary-900 dark:hover:text-primary-100 transition-colors',
'max-sm:m-0!',
'font-medium text-balance max-w-xl',
titleClass,
settings.markReadPosts && read && 'text-slate-600 dark:text-zinc-400',
@@ -356,15 +349,24 @@
]}
style="grid-area: title;"
>
{#if title}
<a
href={useAttachedUrl
? postUrl
: `/post/${encodeURIComponent(instance.data)}/${id}`}
target={useAttachedUrl
? '_blank'
: undefined}
rel={useAttachedUrl ? 'noopener noreferrer' : undefined}
class="inline-block hover:underline hover:text-primary-900 dark:hover:text-primary-100 transition-colors"
>
<Markdown
source={title}
inline
noStyle
class={view == 'compact' ? '' : 'leading-[1.3]'}
></Markdown>
{/if}
</a>
class={view != 'compact' ? '' : 'leading-[1.3]'}
/>
</a>
</h3>
{:else}
<div style="grid-area: title; margin: 0;"></div>
{/if}
+54 -61
View File
@@ -49,8 +49,6 @@
children,
}: Props = $props()
let loading = $state(false)
const castVote = async (newVote: number) => {
if (!profile.current?.jwt) {
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
@@ -85,6 +83,53 @@
}
</script>
{#snippet voteButton(
votes: number,
target: 'upvote' | 'downvote',
vote?: number,
)}
{@const targetNum = target == 'upvote' ? 1 : -1}
<button
onclick={() => castVote(vote == targetNum ? 0 : targetNum)}
class={[
'flex items-center gap-0.5 transition-colors relative cursor-pointer h-full p-2',
'first:rounded-l-3xl last:rounded-r-3xl',
'last:flex-row-reverse',
vote == targetNum
? shouldShowVoteColor(
vote,
target == 'upvote' ? 'upvotes' : 'downvotes',
)
: 'hover:bg-slate-100 dark:hover:bg-zinc-800',
]}
aria-pressed={vote == targetNum}
aria-label={$t(
target == 'upvote'
? 'post.actions.vote.upvote'
: 'post.actions.vote.downvote',
)}
>
<Icon src={target == 'upvote' ? ChevronUp : ChevronDown} size="20" micro />
{#if showCounts}
<div class="grid text-sm z-20">
{#key votes}
<span
style="grid-column: 1; grid-row: 1;"
in:fly={{ duration: 400, y: -10, easing: backOut }}
out:fly={{ duration: 400, y: 10, easing: backOut }}
aria-label={$t(
target == 'upvote' ? 'aria.vote.upvotes' : 'aria.vote.downvotes',
{ default: votes },
)}
>
<FormattedNumber number={votes ?? 0} />
</span>
{/key}
</div>
{/if}
</button>
{/snippet}
{#if children}{@render children({ vote, score })}{:else}
{@const voteRatio = Math.floor(
((upvotes ?? 0) / ((upvotes ?? 0) + (downvotes ?? 0))) * 100,
@@ -92,71 +137,18 @@
<div
class={[
buttonColor.secondary,
'rounded-full h-full font-medium flex items-center *:p-2 relative',
'hover:bg-white dark:hover:bg-zinc-900 overflow-hidden transition-colors shrink-0',
'text-inherit! divide-x divide-slate-200 dark:divide-zinc-800',
loading && 'animate-pulse opacity-75 pointer-events-none',
'rounded-3xl h-full font-medium flex relative',
voteRatio < 85 && settings.voteRatioBar && 'vote-ratio',
]}
role="group"
aria-label={$t('aria.vote.group')}
style="--vote-ratio: {voteRatio}%;"
>
<button
onclick={() => castVote(vote == 1 ? 0 : 1)}
class={[
'flex items-center gap-0.5 transition-colors relative cursor-pointer',
vote == 1
? shouldShowVoteColor(vote, 'upvotes')
: 'hover:bg-slate-100 dark:hover:bg-zinc-800',
]}
aria-pressed={vote == 1}
aria-label={$t('post.actions.vote.upvote')}
>
<Icon src={ChevronUp} size="20" micro />
{#if showCounts}
<span class="grid text-sm z-20">
{#key upvotes}
<span
style="grid-column: 1; grid-row: 1;"
in:fly={{ duration: 400, y: -10, easing: backOut }}
out:fly={{ duration: 400, y: 10, easing: backOut }}
aria-label={$t('aria.vote.upvotes', { default: upvotes })}
>
<FormattedNumber number={upvotes ?? 0} />
</span>
{/key}
</span>
{/if}
</button>
{@render voteButton(upvotes, 'upvote', vote)}
<div
class="h-full p-0! border-l border-slate-200 dark:border-zinc-800"
></div>
{#if site.data?.site_view.local_site.enable_downvotes ?? true}
<button
onclick={() => castVote(vote == -1 ? 0 : -1)}
class={[
'flex items-center flex-row-reverse gap-0.5 transition-colors cursor-pointer',
vote == -1
? shouldShowVoteColor(vote, 'downvotes')
: 'hover:bg-slate-100 dark:hover:bg-zinc-800',
]}
aria-pressed={vote == -1}
aria-label={$t('post.actions.vote.downvote')}
>
<Icon src={ChevronDown} size="20" micro />
{#if showCounts}
<span class="grid text-sm">
{#key downvotes}
<span
style="grid-column: 1; grid-row: 1;"
in:fly={{ duration: 400, y: -10, easing: backOut }}
out:fly={{ duration: 400, y: 10, easing: backOut }}
aria-label={$t('aria.vote.downvotes', { default: downvotes })}
>
<FormattedNumber number={downvotes ?? 0} />
</span>
{/key}
</span>
{/if}
</button>
{@render voteButton(downvotes, 'downvote', vote)}
{/if}
</div>
{/if}
@@ -167,6 +159,7 @@
}
.vote-ratio::before {
border-radius: var(--radius-3xl);
content: '';
position: absolute;
height: 100%;
@@ -98,7 +98,7 @@
color="secondary"
rounding="pill"
target={settings.openLinksInNewTab ? '_blank' : ''}
title={$t('post.actions.comments')}
aria-label={$t('post.actions.comments')}
>
{@const newComment =
publishedToDate(post.counts.newest_comment_time).getTime() >
@@ -124,7 +124,6 @@
color="secondary"
rounding="pill"
class={buttonSquare}
animations={{ scale: true, large: true }}
>
{#snippet prefix()}
<Icon src={BugAnt} micro size="16" />
@@ -181,7 +180,6 @@
rounding="pill"
size="custom"
class={buttonSquare}
animations={{ scale: true, large: true }}
>
{#snippet prefix()}
<Icon src={EllipsisHorizontal} size="16" micro />
@@ -206,7 +206,7 @@
? { duration: 800, easing: expoOut, y: 24, delay: row * 50 }
: { opacity: 1, duration: 0 }}
data-index={row}
class={['relative post-container px-3 sm:px-6', row < 7 && '']}
class={['relative post-container', row < 7 && '']}
>
<Post
bind:post={posts[row]}
@@ -216,10 +216,10 @@
settings.posts.compactFeatured
? 'compact'
: settings.view}
class="transition-all duration-250"
onhide={() => {
posts = posts.toSpliced(row, 1)
}}
class="px-3 sm:px-6 hover:bg-slate-100/50 hover:dark:bg-zinc-900/50 transition-colors"
></Post>
</li>
{/snippet}
@@ -41,6 +41,7 @@
padding="sm"
href={url}
target="_blank"
rel="noopener"
>
{#if thumbnail_url}
<img
@@ -92,6 +93,7 @@
<a
href={url}
target="_blank"
rel="noopener noreferrer"
class="flex flex-row text-slate-900 dark:text-zinc-400 items-center overflow-hidden group/link hover:underline space-x-1 my-1"
>
<Icon src={Link} size="16" micro class="shrink-0" />
@@ -5,8 +5,8 @@
type MediaType,
} from '$lib/components/lemmy/post/helpers.js'
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
import { t } from '$lib/i18n/translations'
import { settings, type View } from '$lib/settings.svelte.js'
import { isImage } from '$lib/ui/image'
import type { Post } from 'lemmy-js-client'
import { modal } from 'mono-svelte'
import Button from 'mono-svelte/button/Button.svelte'
@@ -47,36 +47,33 @@
@component
Thumbnails for compact and list view posts.
-->
<div class={[size, 'relative group/media', clazz]} {style}>
{#if post.alt_text}
<Button
rounding="pill"
class="w-max absolute bottom-0 left-0 py-0.5 px-1.5 m-1 font-bold"
onclick={() => modal({ title: 'Alt', body: post.alt_text ?? '' })}
>
ALT
</Button>
{/if}
<div class={[size, 'relative group/media', clazz]} {style} role="presentation">
<svelte:element
this={!settings.expandImages || type != 'image' ? 'a' : 'button'}
href={postLink(post)}
href={post.url ?? postLink(post)}
aria-label={type == 'image'
? $t('aria.postDecor.openImage', { default: post.name })
: type == 'embed'
? $t('aria.postDecor.openLink', {
default: post.embed_title ?? post.name,
})
: $t('aria.postDecor.openPost', { default: post.name })}
target={post.url ? '_blank' : undefined}
onclick={() => {
if (type == 'image') showImage(bestImageURL(post, false, -1))
}}
role="button"
role={type == 'image' ? 'button' : 'link'}
tabindex="0"
class="cursor-pointer h-full"
class="cursor-pointer h-full block"
>
<div
class={[
'relative overflow-hidden rounded-2xl max-h-full h-full',
'border border-slate-200 dark:border-zinc-800 hover:border-slate-300 dark:hover:border-zinc-700',
'dark:bg-zinc-800 hover-scale-effect',
'border border-slate-200 dark:border-zinc-800 hover-scale-effect',
]}
>
{#if post.thumbnail_url || isImage(post.url)}
{@const thumbnail =
post.thumbnail_url != undefined && !isImage(post.url)}
{#if post.thumbnail_url || type == 'image'}
{@const thumbnail = post.thumbnail_url != undefined && type != 'image'}
<picture>
<!--I would add AVIF, but lemmy.world's AVIF is broken as of currently-->
{#each ['webp'] as format}
@@ -105,28 +102,22 @@
src={bestImageURL(post, thumbnail, -1, null)}
loading="lazy"
class={[
'object-cover relative overflow-hidden rounded-xl h-full bg-slate-200 dark:bg-zinc-900',
'object-cover relative overflow-hidden rounded-xl h-full',
size,
]}
alt={post.alt_text ?? ' '}
class:blur-xl={blur}
/>
{#if type != 'image'}
<div
class={[
'absolute w-8 h-8 m-1 bottom-0 left-0 rounded-xl text-slate-800 dark:text-zinc-200',
'bg-slate-25 dark:bg-zinc-900',
'grid place-items-center',
]}
>
<Icon
src={type == 'iframe' ? VideoCamera : Link}
micro
size="16"
/>
</div>
{/if}
</picture>
{#if type != 'image'}
<div
class={[
'absolute w-8 h-8 bottom-1 left-1 rounded-xl bg-slate-25 dark:bg-zinc-900 grid place-items-center',
]}
>
<Icon src={type == 'iframe' ? VideoCamera : Link} micro size="16" />
</div>
{/if}
{:else}
<div
class={[
+10 -2
View File
@@ -13,6 +13,9 @@
sm: 'mt-3 mb-1 px-3',
md: 'mt-4 mb-2',
lg: 'mt-6 mb-2',
'bottom-sm': 'mb-1 px-3',
'bottom-md': 'mb-2',
'bottom-lg': 'mb-3',
}
const colors = {
@@ -28,6 +31,7 @@
border?: boolean
children?: import('svelte').Snippet
action?: import('svelte').Snippet
element?: string
}
let {
@@ -38,6 +42,7 @@
size = 'sm',
color = 'subtle',
margin = 'none',
element = 'h3',
}: Props = $props()
</script>
@@ -50,9 +55,12 @@
clazz,
]}
>
<h3 class="font-medium text-left flex flex-row gap-1 items-center">
<svelte:element
this={element}
class="font-medium text-left flex flex-row gap-1 items-center"
>
{@render children?.()}
</h3>
</svelte:element>
<div
class={[
'flex-1 border-slate-200/70 dark:border-zinc-800 border-b',
+5
View File
@@ -927,6 +927,11 @@
"loading": "Loading",
"element": {
"pageHeader": "Page header"
},
"postDecor": {
"openImage": "Open image: {{default}}",
"openLink": "Open link: {{default}}",
"openPost": "Open post: {{default}}"
}
},
"stats": {
+1 -1
View File
@@ -64,7 +64,7 @@
title={label}
>
{@render icon?.()}
<span class={allowIconOnly ? 'hidden md:contents' : 'contents'}>
<span class={allowIconOnly ? 'sr-only md:contents' : 'contents'}>
{@render children?.()}
</span>
</span>
+14 -31
View File
@@ -5,33 +5,24 @@
export const buttonAlignment = {
left: 'justify-start text-left origin-left',
center: 'justify-center text-center origin-center',
center: 'justify-center',
right: 'justify-end text-right origin-right',
}
export const buttonColor = {
primary: `border border-transparent bg-primary-900 text-white
dark:bg-primary-100 dark:text-black hover:brightness-125 dark:hover:brightness-90 active:brightness-90
dark:active:brightness-75`,
secondary: `border border-slate-200 border-b-slate-300 dark:border-zinc-800 bg-white dark:bg-zinc-900
hover:bg-slate-100 dark:hover:bg-zinc-800 dark:hover:border-zinc-700 dark:active:bg-zinc-900 active:bg-slate-200`,
primary: `border border-transparent bg-primary-900 text-slate-50 dark:bg-primary-100 dark:text-black`,
secondary: `border border-slate-200 border-b-slate-300 dark:border-zinc-800 bg-white dark:bg-zinc-900`,
tertiary:
' bg-transparent hover:bg-slate-200/50 dark:hover:bg-zinc-700/30 dark:text-zinc-200',
danger:
'border border-red-500 bg-red-500 hover:text-red-500 hover:bg-transparent text-white',
'danger-subtle': 'text-red-500 hover:bg-red-500 hover:text-inherit!',
'success-subtle': 'text-green-500 hover:bg-green-500 hover:text-inherit!',
'warning-subtle': 'text-yellow-500 hover:bg-yellow-500 hover:text-inherit!',
ghost: `border border-slate-200 dark:border-zinc-800 bg-transparent
hover:bg-slate-100 dark:hover:bg-zinc-800 dark:hover:border-zinc-700 dark:text-zinc-400 hover:text-inherit
dark:hover:text-inherit`,
'blue-subtle': `text-blue-500 hover:bg-blue-500 hover:text-inherit!`,
none: '',
@@ -75,7 +66,6 @@
rounding?: ButtonRoundness
alignment?: ButtonAlignment
shadow?: ButtonShadow
column?: boolean
loaderWidth?: number | undefined
href?: string | undefined
class?: ClassValue
@@ -106,7 +96,6 @@
rounding = size == 'lg' ? 'xl' : 'lg',
alignment = 'center',
shadow = color != 'tertiary' ? 'none' : 'none',
column = false,
disabled,
loaderWidth = undefined,
href = undefined,
@@ -129,7 +118,10 @@
buttonRounding[rounding],
buttonShadow[shadow],
buttonColor[color],
'transition-all font-medium cursor-pointer duration-75 disabled:opacity-50 disabled:pointer-events-none disabled:shadow-none text-sm',
buttonAlignment[alignment],
'transition-all font-medium cursor-pointer disabled:opacity-50 disabled:pointer-events-none',
'hover:brightness-98 hover:dark:brightness-95 active:brightness-90 active:dark:brightness-85 text-sm',
'flex flex-row items-center gap-1.5',
(disabled || loading) && 'pointer-events-none opacity-50 shadow-none',
alignment == 'center'
? 'origin-center'
@@ -140,22 +132,13 @@
]}
type={submit ? 'submit' : 'button'}
>
<div
class={[
'flex',
column ? 'flex-col justify-center' : 'flex-row items-center',
'h-full gap-1.5 button-content w-full',
buttonAlignment[alignment],
]}
>
{#if loading}
<Spinner width={loaderWidth ?? 16} />
{:else if prefix}
{@render prefix?.()}
{/if}
{@render children?.()}
{@render suffix?.()}
</div>
{#if loading}
<Spinner width={loaderWidth ?? 16} />
{:else if prefix}
{@render prefix?.()}
{/if}
{@render children?.()}
{@render suffix?.()}
</svelte:element>
<!--
+2 -1
View File
@@ -103,7 +103,8 @@
buttonSize[size],
buttonShadow[shadow],
buttonColor.secondary,
'appearance-none transition-colors rounded-xl text-sm w-full min-w-full cursor-pointer pr-6',
'appearance-none transition-all rounded-xl text-sm w-full min-w-full cursor-pointer pr-6',
'hover:brightness-98 hover:dark:brightness-90',
selectClass,
clazz,
]}