misc: improve alt text handling

This commit is contained in:
Xylight committed 2024-07-02 10:13:29 -07:00
1 parent 3874160ce5
commit ed0236a5f6
4 files changed
+79 -64

No files matched your search

BIN
View File
Binary file not shown.
+44 -59
View File
@@ -1,10 +1,10 @@
<script lang="ts"> <script lang="ts">
import CommunityLink from "$lib/components/lemmy/community/CommunityLink.svelte"; import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
import Avatar from "$lib/components/ui/Avatar.svelte"; import Avatar from '$lib/components/ui/Avatar.svelte'
import { Badge } from "mono-svelte"; import { Badge } from 'mono-svelte'
import UserLink from "$lib/components/lemmy/user/UserLink.svelte"; import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import RelativeDate from "$lib/components/util/RelativeDate.svelte"; import RelativeDate from '$lib/components/util/RelativeDate.svelte'
import type { Community, Person, SubscribedType } from "lemmy-js-client"; import type { Community, Person, SubscribedType } from 'lemmy-js-client'
import { import {
Bookmark, Bookmark,
Check, Check,
@@ -14,23 +14,23 @@
Megaphone, Megaphone,
Plus, Plus,
Trash, Trash,
} from "svelte-hero-icons"; } from 'svelte-hero-icons'
import { getInstance } from "$lib/lemmy.js"; import { getInstance } from '$lib/lemmy.js'
import { profile } from "$lib/auth.js"; import { profile } from '$lib/auth.js'
import Subscribe from "../../../../routes/communities/Subscribe.svelte"; import Subscribe from '../../../../routes/communities/Subscribe.svelte'
import ShieldIcon from "../moderation/ShieldIcon.svelte"; import ShieldIcon from '../moderation/ShieldIcon.svelte'
import { userSettings } from "$lib/settings"; import { userSettings } from '$lib/settings'
import Markdown from "$lib/components/markdown/Markdown.svelte"; import Markdown from '$lib/components/markdown/Markdown.svelte'
import { t } from "$lib/translations"; import { t } from '$lib/translations'
export let community: Community | undefined = undefined; export let community: Community | undefined = undefined
export let subscribed: SubscribedType | undefined = undefined; export let subscribed: SubscribedType | undefined = undefined
export let user: Person | undefined = undefined; export let user: Person | undefined = undefined
export let published: Date | undefined = undefined; export let published: Date | undefined = undefined
export let title: string | undefined = undefined; export let title: string | undefined = undefined
export let id: number | undefined = undefined; export let id: number | undefined = undefined
export let read: boolean = false; export let read: boolean = false
// Badges // Badges
export let badges = { export let badges = {
@@ -42,25 +42,23 @@
locked: false, locked: false,
moderator: false, moderator: false,
admin: false, admin: false,
}; }
</script> </script>
<div <div
class="grid w-full meta {community class="grid w-full meta {community
? 'grid-rows-2' ? 'grid-rows-2'
: 'grid-rows-1'} text-xs min-w-0 max-w-full" : 'grid-rows-1'} text-xs min-w-0 max-w-full"
style={$$props.style ?? ""} style={$$props.style ?? ''}
> >
{#if community} {#if community}
<Subscribe let:subscribe let:subscribing> <Subscribe let:subscribe let:subscribing>
<button <button
on:click={async () => { on:click={async () => {
if (!community) return; if (!community) return
await subscribe(community.id, subscribed); await subscribe(community.id, subscribed)
subscribed = subscribed =
subscribed == "NotSubscribed" subscribed == 'NotSubscribed' ? 'Subscribed' : 'NotSubscribed'
? "Subscribed"
: "NotSubscribed";
}} }}
class="relative cursor-pointer pr-2 row-span-2 flex-shrink-0" class="relative cursor-pointer pr-2 row-span-2 flex-shrink-0"
> >
@@ -73,15 +71,14 @@
/> />
{#if subscribed != undefined && $profile?.jwt} {#if subscribed != undefined && $profile?.jwt}
<div <div
class="absolute w-3.5 h-3.5 {subscribed == class="absolute w-3.5 h-3.5 {subscribed == 'NotSubscribed'
'NotSubscribed'
? 'bg-primary-900 dark:bg-primary-100 text-white dark:text-black' ? 'bg-primary-900 dark:bg-primary-100 text-white dark:text-black'
: 'bg-primary-100 dark:bg-primary-900 text-black dark:text-white'} rounded-full ring-2 box-border : 'bg-primary-100 dark:bg-primary-900 text-black dark:text-white'} rounded-full ring-2 box-border
ring-slate-50 dark:ring-zinc-950 ring-slate-50 dark:ring-zinc-950
-bottom-1 right-1 grid place-items-center transition-all" -bottom-1 right-1 grid place-items-center transition-all"
> >
<Icon <Icon
src={subscribed == "NotSubscribed" ? Plus : Check} src={subscribed == 'NotSubscribed' ? Plus : Check}
mini mini
size="12" size="12"
/> />
@@ -122,63 +119,51 @@
style="grid-area: badges;" style="grid-area: badges;"
> >
{#if badges.nsfw} {#if badges.nsfw}
<Badge <Badge label={$t('post.badges.nsfw')} color="red-subtle" allowIconOnly>
label={$t("post.badges.nsfw")}
color="red-subtle"
allowIconOnly
>
<Icon src={ExclamationTriangle} size="14" micro slot="icon" /> <Icon src={ExclamationTriangle} size="14" micro slot="icon" />
{$t("post.badges.nsfw")} {$t('post.badges.nsfw')}
</Badge> </Badge>
{/if} {/if}
{#if badges.saved} {#if badges.saved}
<Badge <Badge
label={$t("post.badges.saved")} label={$t('post.badges.saved')}
color="yellow-subtle" color="yellow-subtle"
allowIconOnly allowIconOnly
> >
<Icon src={Bookmark} micro size="14" slot="icon" /> <Icon src={Bookmark} micro size="14" slot="icon" />
{$t("post.badges.saved")} {$t('post.badges.saved')}
</Badge> </Badge>
{/if} {/if}
{#if badges.locked} {#if badges.locked}
<Badge <Badge
label={$t("post.badges.locked")} label={$t('post.badges.locked')}
color="yellow-subtle" color="yellow-subtle"
allowIconOnly allowIconOnly
> >
<Icon src={LockClosed} micro size="14" slot="icon" /> <Icon src={LockClosed} micro size="14" slot="icon" />
<span class="max-md:hidden">{$t("post.badges.locked")}</span> <span class="max-md:hidden">{$t('post.badges.locked')}</span>
</Badge> </Badge>
{/if} {/if}
{#if badges.removed} {#if badges.removed}
<Badge <Badge label={$t('post.badges.removed')} color="red-subtle" allowIconOnly>
label={$t("post.badges.removed")}
color="red-subtle"
allowIconOnly
>
<Icon src={Trash} micro size="14" slot="icon" /> <Icon src={Trash} micro size="14" slot="icon" />
<span class="max-md:hidden">{$t("post.badges.removed")}</span> <span class="max-md:hidden">{$t('post.badges.removed')}</span>
</Badge> </Badge>
{/if} {/if}
{#if badges.deleted} {#if badges.deleted}
<Badge <Badge label={$t('post.badges.deleted')} color="red-subtle" allowIconOnly>
label={$t("post.badges.deleted")}
color="red-subtle"
allowIconOnly
>
<Icon src={Trash} micro size="14" slot="icon" /> <Icon src={Trash} micro size="14" slot="icon" />
<span class="max-md:hidden">{$t("post.badges.deleted")}</span> <span class="max-md:hidden">{$t('post.badges.deleted')}</span>
</Badge> </Badge>
{/if} {/if}
{#if badges.featured} {#if badges.featured}
<Badge <Badge
label={$t("post.badges.featured")} label={$t('post.badges.featured')}
color="green-subtle" color="green-subtle"
allowIconOnly allowIconOnly
> >
<Icon src={Megaphone} micro size="14" slot="icon" /> <Icon src={Megaphone} micro size="14" slot="icon" />
<span class="max-md:hidden">{$t("post.badges.featured")}</span> <span class="max-md:hidden">{$t('post.badges.featured')}</span>
</Badge> </Badge>
{/if} {/if}
<slot name="badges" /> <slot name="badges" />
@@ -196,7 +181,7 @@
class:dark:text-zinc-400={$userSettings.markReadPosts && read} class:dark:text-zinc-400={$userSettings.markReadPosts && read}
style="grid-area: title;" style="grid-area: title;"
> >
<Markdown source={title} inline noStyle class="leading-6"></Markdown> <Markdown source={title} inline noStyle class="leading-[1.3]"></Markdown>
</a> </a>
{/if} {/if}
@@ -204,10 +189,10 @@
.meta { .meta {
display: grid; display: grid;
grid-template-areas: grid-template-areas:
"avatar community badges" 'avatar community badges'
"avatar stats badges"; 'avatar stats badges';
gap: 0; gap: 0;
grid-template-rows: auto auto; grid-template-rows: auto auto;
grid-template-columns: auto 1fr; grid-template-columns: auto 1fr auto;
} }
</style> </style>
@@ -13,11 +13,14 @@
import { userSettings } from '$lib/settings.js' import { userSettings } from '$lib/settings.js'
import type { Post } from 'lemmy-js-client' import type { Post } from 'lemmy-js-client'
import PostIframe from './PostIframe.svelte' import PostIframe from './PostIframe.svelte'
import { Button, Material } from 'mono-svelte'
export let view: 'card' | 'cozy' | 'list' | 'compact' = 'cozy' export let view: 'card' | 'cozy' | 'list' | 'compact' = 'cozy'
export let post: Post export let post: Post
export let type: MediaType = 'none' export let type: MediaType = 'none'
export let opened: boolean | undefined = undefined export let opened: boolean | undefined = undefined
let showAltText = false
</script> </script>
{#if type == 'image'} {#if type == 'image'}
@@ -70,12 +73,22 @@
/> />
</picture> </picture>
{#if post.alt_text} {#if post.alt_text}
<button <Button
class="absolute bottom-0 left-0 text-sm m-2 bg-white dark:bg-zinc-900 px-3 py-1.5 on:click={(e) => {
rounded-full border border-slate-200 dark:border-zinc-800 shadow-lg text-left" e.stopPropagation()
showAltText = !showAltText
}}
class="absolute bottom-0 left-0 text-sm m-2 text-left"
size="sm"
rounding="pill"
alignment="left"
> >
{#if showAltText}
{post.alt_text} {post.alt_text}
</button> {:else}
<span class="font-bold">ALT</span>
{/if}
</Button>
{/if} {/if}
</svelte:element> </svelte:element>
{/if} {/if}
@@ -9,6 +9,7 @@
import { userSettings } from '$lib/settings.js' import { userSettings } from '$lib/settings.js'
import { isImage } from '$lib/ui/image' import { isImage } from '$lib/ui/image'
import type { Post } from 'lemmy-js-client' import type { Post } from 'lemmy-js-client'
import { Material, Popover } from 'mono-svelte'
import { DocumentText, Icon, Link, VideoCamera } from 'svelte-hero-icons' import { DocumentText, Icon, Link, VideoCamera } from 'svelte-hero-icons'
export let view: 'card' | 'cozy' | 'list' | 'compact' = 'cozy' export let view: 'card' | 'cozy' | 'list' | 'compact' = 'cozy'
@@ -18,9 +19,25 @@
{#if view == 'compact' || (view == 'list' && (!post.embed_title || type == 'iframe') && type != 'none')} {#if view == 'compact' || (view == 'list' && (!post.embed_title || type == 'iframe') && type != 'none')}
<div <div
class="w-24 sm:w-32 h-24 group/media {$$props.class ?? ''}" class="w-24 sm:w-32 h-24 relative group/media {$$props.class ?? ''}"
style={$$props.style ?? ''} style={$$props.style ?? ''}
> >
{#if post.alt_text}
<Popover openOnHover placement="bottom-end">
<Material
slot="target"
padding="none"
rounding="full"
elevation="high"
class="w-max absolute bottom-0 left-0 py-0.5 px-1.5 m-1 font-bold"
>
ALT
</Material>
<div class="max-w-sm">
{post.alt_text}
</div>
</Popover>
{/if}
<svelte:element <svelte:element
this={!$userSettings.expandImages || type != 'image' ? 'a' : 'button'} this={!$userSettings.expandImages || type != 'image' ? 'a' : 'button'}
href={postLink(post)} href={postLink(post)}