impr: restructure src/lib
This commit is contained in:
376 files changed
+1000
-1033
No files matched your search
@@ -0,0 +1,116 @@
|
||||
<script lang="ts">
|
||||
import { findClosestNumber } from '$lib/util.svelte.js'
|
||||
import { createAvatar } from '@dicebear/core'
|
||||
import * as initials from '@dicebear/initials'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
|
||||
const sizes = [16, 24, 32, 48, 64, 96, 128, 256, 512]
|
||||
|
||||
const optimizeUrl = (
|
||||
url: string | undefined,
|
||||
res: number,
|
||||
): string | undefined => {
|
||||
if (url === undefined) return
|
||||
|
||||
try {
|
||||
const urlObj = new URL(url)
|
||||
urlObj.searchParams.append('format', 'webp')
|
||||
if (res > -1) {
|
||||
urlObj.searchParams.append(
|
||||
'thumbnail',
|
||||
findClosestNumber(sizes, res).toString(),
|
||||
)
|
||||
}
|
||||
|
||||
return urlObj.toString()
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
interface Props {
|
||||
url: string | undefined
|
||||
alt?: string
|
||||
title?: string
|
||||
circle?: boolean
|
||||
width: number
|
||||
res?: number | undefined
|
||||
style?: string
|
||||
class?: ClassValue
|
||||
}
|
||||
|
||||
let {
|
||||
url,
|
||||
alt = '',
|
||||
title = '',
|
||||
circle = true,
|
||||
width,
|
||||
res = undefined,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
let optimizedURLs = $derived(
|
||||
[2, 3, 6, -1].map((n) => optimizeUrl(url, (res || width) * n)),
|
||||
)
|
||||
</script>
|
||||
|
||||
{#if optimizedURLs[0] != undefined}
|
||||
<img
|
||||
{...rest}
|
||||
loading="lazy"
|
||||
srcset="{optimizedURLs[0]} 1x, {optimizedURLs[1]} 2x, {optimizedURLs[2]} 4x, {optimizedURLs[3]} 6x"
|
||||
src={optimizedURLs[0]}
|
||||
alt=""
|
||||
{width}
|
||||
{title}
|
||||
class={[
|
||||
'aspect-square object-cover overflow-hidden shrink-0 bg-slate-100 dark:bg-zinc-900',
|
||||
circle ? 'rounded-full' : 'rounded-lg',
|
||||
clazz,
|
||||
]}
|
||||
style="width: {width}px; height: {width}px; {style}"
|
||||
/>
|
||||
{:else}
|
||||
<div
|
||||
style="width: {width}px; height: {width}px;"
|
||||
class={[
|
||||
'aspect-square object-cover overflow-hidden shrink-0',
|
||||
circle ? 'rounded-full' : 'rounded-lg',
|
||||
clazz,
|
||||
]}
|
||||
>
|
||||
{@html createAvatar(initials, {
|
||||
seed: alt,
|
||||
backgroundType: ['gradientLinear'],
|
||||
fontWeight: 800,
|
||||
randomizeIds: true,
|
||||
chars: 1,
|
||||
scale: 125,
|
||||
textColor: ['fff', '000'],
|
||||
backgroundColor: [
|
||||
'7B68EE',
|
||||
'FF6347',
|
||||
'20B2AA',
|
||||
'DDA0DD',
|
||||
'F0E68C',
|
||||
'FF1493',
|
||||
'4682B4',
|
||||
'32CD32',
|
||||
'FFB6C1',
|
||||
'8B4513',
|
||||
'00CED1',
|
||||
'9370DB',
|
||||
'FFA500',
|
||||
'2E8B57',
|
||||
'DC143C',
|
||||
'BA55D3',
|
||||
'708090',
|
||||
'ADFF2F',
|
||||
'CD853F',
|
||||
'48D1CC',
|
||||
],
|
||||
}).toString()}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,27 @@
|
||||
<script lang="ts">
|
||||
import Avatar from './Avatar.svelte'
|
||||
|
||||
interface Props {
|
||||
name: string
|
||||
label?: string | undefined
|
||||
icon?: string | undefined
|
||||
customIcon?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
name,
|
||||
label = undefined,
|
||||
icon = undefined,
|
||||
customIcon,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row gap-2 items-center">
|
||||
{#if customIcon}{@render customIcon()}{:else}
|
||||
<Avatar url={icon} width={32} alt={name} circle={false} />
|
||||
{/if}
|
||||
<div class="flex flex-col">
|
||||
<span class="font-semibold text-base">{name}</span>
|
||||
<span class="text-sm">{label}</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,167 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/app/i18n'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
import Markdown from '../../app/markdown/Markdown.svelte'
|
||||
import FormattedNumber from '../../components/util/FormattedNumber.svelte'
|
||||
import Avatar from './Avatar.svelte'
|
||||
import Expandable from '../shared/disclosure/Expandable.svelte'
|
||||
|
||||
interface Props {
|
||||
avatar?: string | undefined
|
||||
name: string
|
||||
bio?: string | undefined
|
||||
banner?: string | undefined
|
||||
url?: string | undefined
|
||||
stats?: {
|
||||
name: string
|
||||
value: string
|
||||
format?: boolean
|
||||
}[]
|
||||
center?: boolean
|
||||
class?: ClassValue
|
||||
nameDetail?: import('svelte').Snippet
|
||||
actions?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
compact?: 'always' | 'lg'
|
||||
avatarCircle?: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
avatar = undefined,
|
||||
name,
|
||||
bio = undefined,
|
||||
banner = undefined,
|
||||
url = undefined,
|
||||
stats = [],
|
||||
center = false,
|
||||
class: clazz = '',
|
||||
nameDetail,
|
||||
actions,
|
||||
children,
|
||||
compact,
|
||||
avatarCircle = true,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div {...rest} class={['z-10 text-sm contents w-full', clazz]}>
|
||||
<div
|
||||
class={[
|
||||
compact == 'lg' && 'lg:hidden',
|
||||
compact == 'always' && 'hidden',
|
||||
'absolute inset-0 h-96 overflow-x-hidden -z-10',
|
||||
]}
|
||||
>
|
||||
<img
|
||||
src={banner || avatar}
|
||||
class="w-full h-64 object-cover blur-3xl opacity-30 dark:opacity-30"
|
||||
height="192"
|
||||
alt="User banner"
|
||||
/>
|
||||
</div>
|
||||
{#if banner}
|
||||
<div class="relative overflow-hidden rounded-xl">
|
||||
<img
|
||||
src={banner}
|
||||
class="w-full object-cover h-48 rounded-t-xl bg-white dark:bg-zinc-900 rounded-xl"
|
||||
height="192"
|
||||
alt="User banner"
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<Avatar
|
||||
width={96}
|
||||
url={avatar}
|
||||
alt={name}
|
||||
circle={avatarCircle}
|
||||
class={[
|
||||
'ring-slate-25 bg-slate-25 dark:bg-zinc-925 ring-6 relative dark:ring-zinc-950',
|
||||
banner && '-mt-12 ml-4',
|
||||
!avatarCircle && 'rounded-3xl!',
|
||||
]}
|
||||
/>
|
||||
<div class="py-4 flex flex-col gap-4">
|
||||
<div class="flex flex-col flex-1">
|
||||
<svelte:element
|
||||
this={url ? 'a' : 'span'}
|
||||
href={url}
|
||||
class="text-2xl font-medium tracking-tight {url
|
||||
? 'hover:underline hover:text-primary-900 dark:hover:text-primary-100'
|
||||
: ''}"
|
||||
>
|
||||
{name}
|
||||
</svelte:element>
|
||||
<span
|
||||
class="flex items-center gap-0 text-sm text-slate-600 dark:text-zinc-400 max-w-full w-max"
|
||||
>
|
||||
{@render nameDetail?.()}
|
||||
</span>
|
||||
|
||||
{#if actions}
|
||||
<div class="flex flex-col mt-2">
|
||||
{@render actions?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{#if stats.length > 0}
|
||||
<div
|
||||
class={[
|
||||
compact == 'lg' && 'lg:hidden',
|
||||
compact == 'always' ? 'hidden' : 'flex',
|
||||
'text-sm flex-row flex-wrap overflow-hidden gap-4 h-full',
|
||||
]}
|
||||
>
|
||||
{#each stats as stat}
|
||||
<div class="">
|
||||
<div class="text-slate-600 dark:text-zinc-500 text-sm font-medium">
|
||||
{stat.name}
|
||||
</div>
|
||||
<div
|
||||
class="text-xl font-medium text-primary-900 dark:text-primary-100 text-right"
|
||||
>
|
||||
{#if stat.format ?? true}
|
||||
<FormattedNumber
|
||||
number={Number(stat.value)}
|
||||
options={{ notation: 'standard' }}
|
||||
/>
|
||||
{:else}
|
||||
{stat.value}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{#if bio}
|
||||
<div
|
||||
class={[
|
||||
compact == 'lg' && 'lg:hidden',
|
||||
compact == 'always' && 'hidden',
|
||||
'relative w-full mb-4 text-base',
|
||||
center ? 'text-center' : 'text-left',
|
||||
]}
|
||||
>
|
||||
{#if bio.length > 300}
|
||||
<Expandable>
|
||||
{#snippet title()}
|
||||
{$t('cards.site.about')}
|
||||
{/snippet}
|
||||
<Markdown source={bio} class="font-normal" />
|
||||
</Expandable>
|
||||
{:else}
|
||||
<Markdown source={bio} class="font-normal" />
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="space-y-3 py-4 pt-0">
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.banner-mask {
|
||||
mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,82 @@
|
||||
<script lang="ts" module>
|
||||
import { pushState } from '$app/navigation'
|
||||
|
||||
export function showImage(url: string) {
|
||||
pushState('', {
|
||||
openImage: url,
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { Button, Material, toast } from 'mono-svelte'
|
||||
import { Share, XMark } from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { fade, scale } from 'svelte/transition'
|
||||
import { trapFocus } from 'trap-focus-svelte'
|
||||
|
||||
interface Props {
|
||||
/**
|
||||
* The full-resolution image URL
|
||||
*/
|
||||
alt?: string
|
||||
}
|
||||
|
||||
let { alt = '' }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if page.state.openImage || '' != ''}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="fixed top-0 left-0 w-screen h-svh overflow-auto bg-white/50 dark:bg-black/50
|
||||
flex flex-col z-100 backdrop-blur-xs"
|
||||
transition:fade={{ duration: 150 }}
|
||||
onclick={() => history.back()}
|
||||
onkeydown={(e) => {
|
||||
if (e.key == 'Escape') history.back()
|
||||
}}
|
||||
use:trapFocus
|
||||
>
|
||||
<img
|
||||
width={800}
|
||||
height={800}
|
||||
src={page.state.openImage}
|
||||
class={[
|
||||
'max-w-full mx-auto my-auto overscroll-contain bg-white dark:bg-zinc-900',
|
||||
]}
|
||||
transition:scale={{ start: 0.95, easing: expoOut, duration: 250 }}
|
||||
{alt}
|
||||
/>
|
||||
<div class="sticky z-10 bottom-4 left-1/2 -translate-x-1/2 w-max">
|
||||
<Material
|
||||
class="gap-1 p-0.5 px-1 flex flex-row items-center"
|
||||
rounding="full"
|
||||
padding="none"
|
||||
color="uniform"
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<Button
|
||||
onclick={() => {
|
||||
navigator.clipboard.writeText(page.state?.openImage ?? '')
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
color="tertiary"
|
||||
size="square-lg"
|
||||
rounding="pill"
|
||||
aria-label={$t('post.actions.more.share')}
|
||||
icon={Share}
|
||||
></Button>
|
||||
<Button
|
||||
onclick={() => history.back()}
|
||||
color="tertiary"
|
||||
size="square-lg"
|
||||
rounding="pill"
|
||||
aria-label={$t('common.back')}
|
||||
icon={XMark}
|
||||
></Button>
|
||||
</Material>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,19 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte'
|
||||
|
||||
const placements = {
|
||||
top: 'top-6 lg:top-22',
|
||||
bottom: 'bottom-22 lg:bottom-6 mt-6',
|
||||
}
|
||||
|
||||
interface Props {
|
||||
placement: keyof typeof placements
|
||||
children?: Snippet
|
||||
}
|
||||
|
||||
let { placement, children }: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class={['sticky z-30 mb-0', placements[placement]]}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
@@ -0,0 +1,45 @@
|
||||
<script lang="ts">
|
||||
import Avatar from '$lib/ui/generic/Avatar.svelte'
|
||||
import CommonList from '$comp/ui/layout/CommonList.svelte'
|
||||
import { Button } from 'mono-svelte'
|
||||
|
||||
interface Props {
|
||||
items: {
|
||||
avatar?: string
|
||||
name: string
|
||||
instance?: string
|
||||
id: number
|
||||
url: string
|
||||
}[]
|
||||
}
|
||||
|
||||
let { items }: Props = $props()
|
||||
</script>
|
||||
|
||||
<CommonList animate={false} class="px-1 py-0.5" size="xs" {items}>
|
||||
{#snippet item(item)}
|
||||
<Button
|
||||
class="font-normal w-full h-max block"
|
||||
color="none"
|
||||
alignment="left"
|
||||
href={item.url}
|
||||
>
|
||||
<div class="flex-none">
|
||||
<Avatar
|
||||
url={item.avatar}
|
||||
alt={item.name}
|
||||
title={item.name}
|
||||
width={24}
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col max-w-full break-words">
|
||||
<span>{item.name}</span>
|
||||
{#if item.instance}
|
||||
<span class="text-xs text-slate-600 dark:text-zinc-400">
|
||||
{item.instance}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
</Button>
|
||||
{/snippet}
|
||||
</CommonList>
|
||||
@@ -0,0 +1,21 @@
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
width?: number
|
||||
}
|
||||
|
||||
let { width = 48 }: Props = $props()
|
||||
</script>
|
||||
|
||||
<svg
|
||||
{width}
|
||||
height={width}
|
||||
viewBox="0 0 100 100"
|
||||
fill="currentColor"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
class="inline hover:fill-slate-700 dark:hover:fill-zinc-300 transition-colors"
|
||||
>
|
||||
<path
|
||||
id="hexagon"
|
||||
d="M45.5 10.8868C48.594 9.10042 52.406 9.10042 55.5 10.8868L82.3061 26.3632C85.4001 28.1496 87.3061 31.4508 87.3061 35.0235V65.9765C87.3061 69.5492 85.4001 72.8504 82.3061 74.6368L55.5 90.1132C52.406 91.8996 48.594 91.8996 45.5 90.1132L18.6939 74.6368C15.5999 72.8504 13.6939 69.5492 13.6939 65.9765V35.0235C13.6939 31.4508 15.5999 28.1496 18.6939 26.3632L45.5 10.8868Z"
|
||||
/>
|
||||
</svg>
|
||||
@@ -0,0 +1,11 @@
|
||||
<div class="skeleton animate-pulse flex flex-col gap-2 w-full">
|
||||
<div
|
||||
class="w-2/3 h-6 bg-slate-200 dark:bg-zinc-800 animate-pulse rounded-md"
|
||||
></div>
|
||||
<div
|
||||
class="w-full h-20 bg-slate-200 dark:bg-zinc-800 animate-pulse rounded-md"
|
||||
></div>
|
||||
<div
|
||||
class="w-32 h-6 bg-slate-200 dark:bg-zinc-800 animate-pulse rounded-md"
|
||||
></div>
|
||||
</div>
|
||||
Reference in new issue
Block a user