6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 1 | <script lang="ts"> |
6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 2 | import EmojiText from './EmojiText.svelte'; |
6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 3 | import RichNodes from './RichNodes.svelte'; |
6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 4 | import { mediaUrl } from './api'; |
6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 5 | import { segmentInline } from './inline'; |
6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 6 | import type { Mention } from './mentions'; |
6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 7 | import type { RichNode } from './rich'; |
6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 8 | |
6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 9 | export let nodes: RichNode[]; |
6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 10 | export let mentions: Mention[] = []; |
6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 11 | export let self: string | null = null; |
6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 12 | export let nameOf: (userId: string) => string | null = () => null; |
6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 13 | export let plain = false; |
6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 14 | </script> |
6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 15 | |
6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 16 | {#each nodes as n}{#if n.kind === 'text'}{#if plain}{n.text}{:else}{#each segmentInline(n.text, mentions) as p}{#if p.kind === 'mention'}<span class="mention" class:me={p.user_id === self} title={p.user_id}><EmojiText text={p.text === p.user_id ? (nameOf(p.user_id) ?? p.text) : p.text} /></span>{:else if p.kind === 'link'}<a class="link" href={p.href} target="_blank" rel="noopener noreferrer">{p.text}</a>{:else}<EmojiText text={p.text} />{/if}{/each}{/if}{:else if n.kind === 'mention'}<span class="mention" class:me={n.user_id === self} title={n.user_id}><RichNodes nodes={n.children} plain /></span>{:else if n.kind === 'spoiler'}<span class="spoiler" role="button" tabindex="0"><RichNodes nodes={n.children} {mentions} {self} {nameOf} {plain} /></span>{:else if n.kind === 'emote'}<img class="emote" src={mediaUrl(n.mxc) ?? ''} alt={n.alt} title={n.alt} />{:else if n.tag === 'br'}<br />{:else if n.tag === 'hr'}<hr />{:else if n.tag === 'a'}<a class="link" href={n.attrs['href']} target="_blank" rel="noopener noreferrer"><RichNodes nodes={n.children} plain /></a>{:else}<svelte:element this={n.tag} {...n.attrs}><RichNodes nodes={n.children} {mentions} {self} {nameOf} plain={plain || n.tag === 'code' || n.tag === 'pre'} /></svelte:element>{/if}{/each} |