design: redesign media embeds

This commit is contained in:
Xylight authored and xylight committed 2025-10-18 19:17:26 +00:00
1 parent 881afed2ae
commit 05140f4fc7
5 files changed
+115 -27

No files matched your search

+104 -17
View File
@@ -1,8 +1,10 @@
<script lang="ts" module> <script lang="ts" module>
import { settings } from '$lib/app/settings.svelte' import { settings } from '$lib/app/settings.svelte'
import Blobs from '$lib/ui/generic/Blobs.svelte'
import { import {
Icon, Icon,
type IconSource, type IconSource,
Play,
PuzzlePiece, PuzzlePiece,
VideoCamera, VideoCamera,
} from 'svelte-hero-icons/dist' } from 'svelte-hero-icons/dist'
@@ -100,16 +102,16 @@
url: string url: string
opened?: boolean opened?: boolean
autoplay?: boolean autoplay?: boolean
class?: string title?: string
} }
let { let {
type = 'none', type = 'none',
thumbnail = undefined, thumbnail = undefined,
url, url,
title,
opened = $bindable(!settings.embeds.clickToView), opened = $bindable(!settings.embeds.clickToView),
autoplay = settings.embeds.clickToView, autoplay = settings.embeds.clickToView,
class: clazz = '',
}: Props = $props() }: Props = $props()
let data = $derived(typeData(type)) let data = $derived(typeData(type))
@@ -120,10 +122,11 @@
@component @component
Displays a video file or embedded video iframe. Displays a video file or embedded video iframe.
--> -->
{#if opened} <div class="iframe-container">
{#if opened}
{#if type == 'video'} {#if type == 'video'}
<!-- svelte-ignore a11y_media_has_caption --> <!-- svelte-ignore a11y_media_has_caption -->
<video {autoplay} controls class="rounded-xl aspect-video {clazz}"> <video {autoplay} controls>
<source src={url} /> <source src={url} />
</video> </video>
{:else} {:else}
@@ -133,27 +136,111 @@
frameborder="0" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen allowfullscreen
class="aspect-video rounded-xl dark:bg-zinc-900 {clazz ?? ''}"
></iframe> ></iframe>
{/if} {/if}
{:else} {:else}
<button <button onclick={() => (opened = true)} class="iframe-preview">
onclick={() => (opened = true)} <div role="presentation" class="preview-start">
class="aspect-video w-full h-full z-0 overflow-hidden relative rounded-xl flex flex-col gap-2 items-center justify-center text-white" <div class="start-button">
> <Icon src={Play} size="32" mini />
</div>
</div>
{#if thumbnail} {#if thumbnail}
<img <img
src={optimizeImageURL(thumbnail, 512)} src={optimizeImageURL(thumbnail, 512)}
class="absolute top-0 left-0 -z-10 brightness-25 w-full object-cover h-full" class="absolute top-0 left-0 -z-10 w-full object-cover h-full mask-b-from-0 brightness-75"
alt="" alt=""
/> />
{:else} {:else}
<div <div class="absolute inset-0 w-full h-full scale-200 -z-10 opacity-50">
class="absolute blur-3xl -z-10 top-0 left-0 w-full h-full bg-linear-to-br from-green-800 via-blue-900 via-20% to-red-700" <Blobs seed={title ?? data.text} />
></div> </div>
{/if} {/if}
<Icon src={data.icon} solid size="48" /> <Icon src={data.icon} solid size="48" />
<h1 class="font-bold text-xl">{data.text}</h1> <h1 class="font-display text-3xl font-medium text-left">
<p>Click to view this content.</p> {title ?? data.text}
</h1>
<div class="text-slate-600 dark:text-zinc-400">
{URL.parse?.(url)?.hostname ?? data.text}
</div>
</button> </button>
{/if} {/if}
</div>
<style>
@reference '../../../../app.css';
.iframe-container {
border-radius: var(--radius-2xl);
aspect-ratio: 16 / 9;
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
border: 1px solid var(--color-slate-200);
@variant dark {
border-color: var(--color-zinc-900);
}
& > * {
width: 100%;
height: 100%;
}
.iframe-preview {
width: 100%;
height: 100%;
z-index: 0;
overflow: hidden;
position: relative;
display: flex;
flex-direction: column;
align-items: start;
justify-content: end;
padding: calc(var(--spacing) * 6);
gap: calc(var(--spacing) * 1);
}
.preview-start {
width: 100%;
position: absolute;
inset: 0;
display: grid;
place-items: center;
}
.start-button {
width: calc(var(--spacing) * 16);
height: calc(var(--spacing) * 16);
border-radius: 9999px;
background-color: --alpha(var(--color-slate-100) / 50%);
display: grid;
place-items: center;
backdrop-filter: blur(var(--blur-sm));
cursor: pointer;
position: relative;
box-shadow:
0 1px 3px 0 rgb(0 0 0 / 0.1),
0 1px 2px -1px rgb(0 0 0 / 0.1);
transition:
background-color 300ms var(--ease-cubic),
transform 300ms var(--ease-cubic);
@variant hover {
background-color: --alpha(var(--color-slate-200) / 50%);
}
@variant dark {
background-color: --alpha(var(--color-zinc-900) / 50%);
@variant hover {
background-color: --alpha(var(--color-zinc-800) / 50%);
}
}
@variant active {
transform: scale(93%);
}
}
}
</style>
+6 -1
View File
@@ -10,6 +10,7 @@
type?: MediaType type?: MediaType
opened?: boolean | undefined opened?: boolean | undefined
blur?: boolean blur?: boolean
[key: string]: any
} }
let { let {
@@ -18,6 +19,7 @@
type = 'none', type = 'none',
opened = undefined, opened = undefined,
blur = post.nsfw && settings.nsfwBlur, blur = post.nsfw && settings.nsfwBlur,
...rest
}: Props = $props() }: Props = $props()
</script> </script>
@@ -28,13 +30,15 @@
- Embed link/card. - Embed link/card.
--> -->
{#if type == 'image' && view == 'cozy'} {#if type == 'image' && view == 'cozy'}
<PostImage {post} {blur} /> <PostImage {post} {blur} {...rest} />
{:else if (type == 'iframe' || type == 'video') && view == 'cozy' && post.url} {:else if (type == 'iframe' || type == 'video') && view == 'cozy' && post.url}
<PostIframe <PostIframe
thumbnail={post.thumbnail_url} thumbnail={post.thumbnail_url}
type={iframeType(post.url)} type={iframeType(post.url)}
url={post.url} url={post.url}
{opened} {opened}
title={post.name}
{...rest}
/> />
{:else if type == 'embed' && post.url} {:else if type == 'embed' && post.url}
<PostLink <PostLink
@@ -43,5 +47,6 @@
nsfw={post.nsfw} nsfw={post.nsfw}
embed_title={post.embed_title} embed_title={post.embed_title}
{view} {view}
{...rest}
/> />
{/if} {/if}
@@ -45,15 +45,10 @@
<div class={[size, 'relative group/media', clazz]} {style} role="presentation"> <div class={[size, 'relative group/media', clazz]} {style} role="presentation">
<svelte:element <svelte:element
this={!settings.expandImages || type != 'image' ? 'a' : 'button'} this={!settings.expandImages || type != 'image' ? 'a' : 'button'}
href={post.url ?? postLink(post)} href={postLink(post)}
aria-label={type == 'image' aria-label={type == 'image'
? $t('aria.postDecor.openImage', { default: post.name }) ? $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 })} : $t('aria.postDecor.openPost', { default: post.name })}
target={post.url ? '_blank' : undefined}
onclick={() => { onclick={() => {
if (type == 'image') showImage(bestImageURL(post, false, -1)) if (type == 'image') showImage(bestImageURL(post, false, -1))
}} }}
+3 -3
View File
@@ -26,9 +26,9 @@
const baseHue = (hashString(seed) % 12) * 60 const baseHue = (hashString(seed) % 12) * 60
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
const r1 = seededRandom(seed, i * 3) const r1 = seededRandom(seed, i * 5)
const r2 = seededRandom(seed, i * 3 + 1) const r2 = seededRandom(seed, i * 5 + 1)
const r3 = seededRandom(seed, i * 3 + 2) const r3 = seededRandom(seed, i * 5 + 2)
const lightness = 0.45 + r1 * 0.4 const lightness = 0.45 + r1 * 0.4
@@ -174,6 +174,7 @@
post={data.data.value.post.post} post={data.data.value.post.post}
opened opened
view="cozy" view="cozy"
autoplay={false}
/> />
{#if data.data.value.post.post.body} {#if data.data.value.post.post.body}
<div class="text-base text-slate-800 dark:text-zinc-300 leading-normal"> <div class="text-base text-slate-800 dark:text-zinc-300 leading-normal">