import React, { useEffect, useId, useRef } from 'react' // Strokes of the Reims-Go wordmark (scripts/brand/wordmark.py), in pen order. // Coordinates sit in the generator's baseline frame (translate 4 107). type Stroke = | { kind: 'path'; d: string; ink: 'ink' | 'dash' | 'brand' } | { kind: 'dot'; cx: number; cy: number; r: number } const STROKES: Stroke[] = [ { kind: 'path', ink: 'ink', d: 'M7.5 -7.5V-36A24 28.5 0 0 1 31.5 -64.5' }, { kind: 'path', ink: 'ink', d: 'M50.5 -36H107.5A28.5 28.5 0 1 0 100.18 -16.93' }, { kind: 'path', ink: 'ink', d: 'M133.5 -64.5V-7.5' }, { kind: 'dot', cx: 133.5, cy: -94, r: 9 }, { kind: 'path', ink: 'ink', d: 'M159.5 -7.5V-36A22 28.5 0 0 1 203.5 -36V-7.5M203.5 -36A22 28.5 0 0 1 247.5 -36V-7.5' }, { kind: 'path', ink: 'ink', d: 'M311.05 -59.02A21 14.25 0 0 0 273.5 -50.25A21 14.25 0 0 0 294.5 -36A21 14.25 0 0 1 315.5 -21.75A21 14.25 0 0 1 277.95 -12.98' }, { kind: 'path', ink: 'dash', d: 'M340.5 -36H358.5' }, { kind: 'path', ink: 'brand', d: 'M440.5 -36A28.5 28.5 0 1 1 440.5 -36.01' }, { kind: 'path', ink: 'brand', d: 'M440.5 -64.5V0A28.5 22.5 0 0 1 387.32 11.25' }, { kind: 'path', ink: 'brand', d: 'M523.5 -36A28.5 28.5 0 1 1 523.5 -36.01' }, ] // Pen timing, in ms. Writing speed is constant, so long strokes take longer. const PX_PER_MS = 0.62 const LIFT_MS = 70 // pen lift between strokes const DOT_MS = 140 const HOLD_MS = 900 // finished word stays on screen const FADE_MS = 420 const REST_MS = 260 const STROKE_EASE = 'cubic-bezier(0.45, 0.05, 0.35, 1)' interface Props { /** Rendered width in px; height follows the wordmark's aspect ratio. */ width?: number label?: string className?: string } /** * The Reims-Go wordmark written stroke by stroke, on a loop. Used while * waiting on network I/O. With reduced motion it shows the finished word * with a slow pulse instead. */ export const WordmarkLoader: React.FC = ({ width = 168, label, className }) => { const svgRef = useRef(null) const gid = `wm-${useId().replace(/[^a-zA-Z0-9_-]/g, '')}` useEffect(() => { const svg = svgRef.current if (!svg || typeof svg.animate !== 'function') return if (window.matchMedia?.('(prefers-reduced-motion: reduce)').matches) return const els = Array.from(svg.querySelectorAll('[data-stroke]')) const spans = els.map((el) => { if (el.tagName.toLowerCase() === 'circle') return DOT_MS const len = typeof el.getTotalLength === 'function' ? el.getTotalLength() : 60 return Math.max(90, len / PX_PER_MS) }) const writeEnd = spans.reduce((sum, s) => sum + s, 0) + LIFT_MS * (spans.length - 1) const total = writeEnd + HOLD_MS + FADE_MS + REST_MS const at = (ms: number) => Math.min(1, ms / total) const holdEnd = at(writeEnd + HOLD_MS) const fadeEnd = at(writeEnd + HOLD_MS + FADE_MS) let t = 0 const anims = els.map((el, i) => { const s = at(t) const e = at(t + spans[i]) t += spans[i] + LIFT_MS const isDot = el.tagName.toLowerCase() === 'circle' // Opacity hides the round cap that a fully-offset dash still paints. const frames: Keyframe[] = isDot ? [ { offset: 0, opacity: 0, transform: 'scale(0.2)' }, { offset: s, opacity: 0, transform: 'scale(0.2)', easing: 'cubic-bezier(0.34, 1.56, 0.64, 1)' }, { offset: e, opacity: 1, transform: 'scale(1)' }, { offset: holdEnd, opacity: 1, transform: 'scale(1)' }, { offset: fadeEnd, opacity: 0, transform: 'scale(1)' }, { offset: 1, opacity: 0, transform: 'scale(0.2)' }, ] : [ { offset: 0, opacity: 0, strokeDashoffset: 1 }, { offset: s, opacity: 0, strokeDashoffset: 1 }, { offset: Math.min(e, s + 0.0005), opacity: 1, strokeDashoffset: 1, easing: STROKE_EASE }, { offset: e, opacity: 1, strokeDashoffset: 0 }, { offset: holdEnd, opacity: 1, strokeDashoffset: 0 }, { offset: fadeEnd, opacity: 0, strokeDashoffset: 0 }, { offset: 1, opacity: 0, strokeDashoffset: 1 }, ] return el.animate(frames, { duration: total, iterations: Infinity, fill: 'both' }) }) svg.dataset.animated = 'true' return () => { anims.forEach((a) => a.cancel()) delete svg.dataset.animated } }, []) return (
{label && {label}}
) }