Files
Reims-Go/frontend/src/components/WordmarkLoader.tsx
T
NwflowerandClaude Opus 5.5 e259833b5f feat(plugins): rework the plugin market and first-run language packs
Market page
- Card grid that fills the width; cards show only icon, name,
  publisher (trust mark by color and icon), version and the action.
- Paints from cache via the new PeekPluginMarket binding, then revalidates;
  cards reveal 24 at a time as the feed scrolls.
- Category chips come from the index (MarketBrowseResult.kinds) instead of
  a fixed list; the alpha toggle and source badge are gone.
- Installed/Market is a segmented control; refresh now shows feedback.
- WordmarkLoader writes the Reims-Go wordmark stroke by stroke while the
  market loads (static pulse under reduced motion).

Install and enable
- reims:plugin-install events drive a progress bar on the card.
- After install, a dialog offers to enable the plugin and lists what it can
  do in plain words (PluginInfo.risks / MarketCatalogItem.risks, derived
  from tier, permissions and contributions in risks.go).
- Enabling a plugin that provides UI languages switches to the first one
  unless the current language is among them (PluginInfo.locales).

Trust
- A package installed from the project's own index, fetched over HTTPS in
  this session, inherits the index's trust level when its SHA-256 matches.
  Third-party indexes (REIMS_GO_PLUGIN_MARKET_URL) cannot vouch and show
  every entry as community.
- Trust no longer waives review: official packages get the same scan,
  high-risk approval and L3 hash check as any other; only builtin and
  bundled plugins are pre-approved.

First launch
- When the OS language is not covered by zh-CN/en-US, the folder screen
  looks up a matching pack once (SuggestLanguagePack) and offers to install
  it; Continue installs and enables it so the UI follows the OS language.
  Before setup the market keeps its index in memory only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 05:17:45 -07:00

144 lines
5.8 KiB
TypeScript

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<Props> = ({ width = 168, label, className }) => {
const svgRef = useRef<SVGSVGElement>(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<SVGGeometryElement>('[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 (
<div className={`wordmark-loader${className ? ` ${className}` : ''}`} role="status" aria-live="polite">
<svg
ref={svgRef}
className="wordmark-loader-svg"
viewBox="0 0 539 141"
width={width}
height={Math.round((width * 141) / 539)}
aria-hidden="true"
>
<defs>
<linearGradient id={gid} gradientUnits="userSpaceOnUse" x1="376" y1="0" x2="531" y2="0">
<stop offset="0" stopColor="#3b8cff" />
<stop offset="0.5" stopColor="#6d5dfc" />
<stop offset="1" stopColor="#ff7a9a" />
</linearGradient>
</defs>
<g transform="translate(4 107)" fill="none" strokeWidth="15" strokeLinecap="round" strokeLinejoin="round">
{STROKES.map((s, i) => s.kind === 'dot' ? (
<circle
key={i}
data-stroke=""
className="wordmark-loader-dot"
cx={s.cx}
cy={s.cy}
r={s.r}
style={{ transformOrigin: 'center', transformBox: 'fill-box' }}
/>
) : (
<path
key={i}
data-stroke=""
className={`wordmark-loader-${s.ink}`}
d={s.d}
pathLength={1}
strokeDasharray="1 1"
stroke={s.ink === 'brand' ? `url(#${gid})` : undefined}
/>
))}
</g>
</svg>
{label && <span className="wordmark-loader-label">{label}</span>}
</div>
)
}