df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 1 | <script lang="ts"> |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 2 | import EmojiText from './EmojiText.svelte'; |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 3 | import { parseCode } from './code'; |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 4 | import { segmentInline } from './inline'; |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 5 | import type { Mention } from './mentions'; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 6 | |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 7 | export let text: string; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 8 | export let jumbo = false; |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 9 | export let mentions: Mention[] = []; |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 10 | export let self: string | null = null; |
787cdbbf0721 | atagen | 2026-10-24 06:50 UTC | 11 | export let nameOf: (userId: string) => string | null = () => null; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 12 | |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 13 | $: segments = parseCode(text); |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 14 | $: pieces = segments.map((s) => (s.kind === 'text' ? segmentInline(s.text, mentions) : [])); |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 15 | $: single = segments.length === 1 && pieces[0].length === 1; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 16 | </script> |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 17 | |
787cdbbf0721 | atagen | 2026-10-24 06:50 UTC | 18 | {#each segments as s, i}{#if s.kind === 'inline'}<code class="inline">{s.text}</code>{:else if s.kind === 'block'}<pre class="block"><code>{s.text}</code></pre>{:else}{#each pieces[i] 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} jumbo={jumbo && single} />{/if}{/each}{/if}{/each} |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 19 | |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 20 | <style> |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 21 | code { |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 22 | font-family: ui-monospace, 'JetBrains Mono', 'Fira Code', Menlo, monospace; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 23 | font-size: 0.9em; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 24 | } |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 25 | .inline { |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 26 | padding: 1px 5px; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 27 | border-radius: 4px; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 28 | background: var(--bg-soft); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 29 | border: 1px solid var(--border); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 30 | } |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 31 | .block { |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 32 | margin: 4px 0; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 33 | padding: 8px 10px; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 34 | border-radius: 6px; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 35 | background: var(--bg-soft); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 36 | border: 1px solid var(--border); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 37 | overflow-x: auto; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 38 | white-space: pre; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 39 | line-height: 1.4; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 40 | } |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 41 | .mention { |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 42 | padding: 0 4px; |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 43 | border-radius: 4px; |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 44 | font-weight: 600; |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 45 | color: var(--accent); |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 46 | background: color-mix(in srgb, var(--accent) 18%, transparent); |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 47 | } |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 48 | .mention.me { |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 49 | color: var(--warn-text); |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 50 | background: color-mix(in srgb, var(--warn) 28%, transparent); |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 51 | } |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 52 | .link { color: var(--accent); overflow-wrap: anywhere; } |
705b1e1062c2 | atagen | 2026-10-23 09:05 UTC | 53 | .link:hover { text-decoration: underline; } |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 54 | </style> |