import DOMPurify from 'dompurify' import { useMemo, useState } from 'react' function sanitizeSvg(raw: string): string { return DOMPurify.sanitize(raw, { USE_PROFILES: { svg: true, svgFilters: true }, ADD_TAGS: ['image', 'use', 'clipPath', 'defs', 'style', 'animate', 'animateTransform', 'feDropShadow', 'filter', 'linearGradient', 'stop'], ADD_ATTR: ['xlink:href', 'href', 'clip-path', 'viewBox', 'preserveAspectRatio', 'xmlns', 'xmlns:xlink', 'rx', 'ry', 'attributeName', 'from', 'to', 'dur', 'fill', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'dominant-baseline', 'letter-spacing', 'opacity', 'filter', 'flood-color', 'flood-opacity', 'stdDeviation'], }) } type Props = { username: string generating: boolean generatedSvg: string | null generateError: string | null onBack: () => void } export function ResultScreen({ username, generating, generatedSvg, generateError, onBack }: Props) { const safeSvg = useMemo(() => (generatedSvg ? sanitizeSvg(generatedSvg) : ''), [generatedSvg]) const [copied, setCopied] = useState(false) const embedUrl = `${window.location.origin}/api/${encodeURIComponent(username)}` const embedSnippet = `![${username}](${embedUrl})` const copy = async () => { try { await navigator.clipboard.writeText(embedSnippet) setCopied(true) setTimeout(() => setCopied(false), 1500) } catch { /* ignore */ } } return (

Your Widget

{generating && (

Generating with real data…

)} {!generating && generateError && (

{generateError}

)} {!generating && !generateError && safeSvg && ( <>

Rendered from live GitHub data

{/* Force the inline SVG to scale up to the card width. The composite is authored at 380px wide — without this the preview looked tiny on wide screens. */}

Embed in your README

                {embedSnippet}
              

GitHub requires HTTPS for README images — serve this behind a TLS reverse proxy or Cloudflare Tunnel if the page is on http://.

)}
) }