impr: restructure src/lib

This commit is contained in:
Xylight committed 2025-09-24 17:12:19 -07:00
1 parent d85b889409
commit 75f907743e
376 files changed
+1000 -1033

No files matched your search

+76
View File
@@ -0,0 +1,76 @@
<script lang="ts">
import Markdown from '$lib/app/markdown/Markdown.svelte'
import { Button } from 'mono-svelte'
import { ChevronDown, Icon } from 'svelte-hero-icons'
const MAX_HEIGHT = 192
let element = $state<Element>()
function isOverflown(element: Element) {
if (!element) return false
return element.scrollHeight > MAX_HEIGHT
}
interface Props {
body: string
clickThrough?: boolean
element?: string
style?: string
class?: string
}
let {
body,
clickThrough = false,
element: htmlElement = 'div',
style = '',
class: clazz = '',
}: Props = $props()
let overflows = $derived(element ? isOverflown(element) : false)
let expanded = $state(false)
$effect(() => {
expanded = !overflows
})
</script>
<svelte:element
this={htmlElement}
{style}
class={[
expanded
? 'text-slate-600 dark:text-zinc-400 max-h-full'
: [
'overflow-hidden bg-linear-to-b text-transparent from-slate-600 via-slate-600',
'dark:from-zinc-400 dark:via-zinc-400 bg-clip-text z-0 max-h-36',
],
clazz,
]}
class:pointer-events-none={!clickThrough}
bind:this={element}
>
<Markdown source={expanded ? body : body.slice(0, 1000)} />
{#if overflows}
<Button
onclick={() => (expanded = !expanded)}
size="square-sm"
color="tertiary"
class={[
'text-black dark:text-white absolute z-10 isolate pointer-events-auto bottom-0',
'left-1/2 -translate-x-1/2 mb-4',
expanded && 'bg-slate-200/50 dark:bg-zinc-900 shadow-md',
]}
title="Expand"
>
<Icon
src={ChevronDown}
size="20"
mini
class="{expanded ? 'rotate-180' : ''} transition-transform"
/>
</Button>
{/if}
</svelte:element>