diff --git a/packages/core/src/webui/ui-config.ts b/packages/core/src/webui/ui-config.ts index 2df5f209..4e10e8ce 100644 --- a/packages/core/src/webui/ui-config.ts +++ b/packages/core/src/webui/ui-config.ts @@ -86,7 +86,10 @@ export interface UiAppearance { /** Corner radius in rem, 0…2. */ radius: number; density: Density; + /** Soften animations (transforms off, shorter durations). */ reduceMotion: boolean; + /** Hard-disable all UI animations (stronger than reduceMotion). */ + disableMotion: boolean; highContrast: boolean; sidebarDefaultCollapsed: boolean; timeFormat: TimeFormat; @@ -193,6 +196,7 @@ const DEFAULT_APPEARANCE: UiAppearance = { radius: 0.75, density: 'cozy', reduceMotion: false, + disableMotion: false, highContrast: false, sidebarDefaultCollapsed: false, timeFormat: '24h', @@ -400,6 +404,7 @@ export function normalizeAppearance(value: unknown, imageState: ServerImageState radius: clampNum(v.radius, 0, 2, DEFAULT_APPEARANCE.radius), density: oneOf(v.density, ['cozy', 'compact'], DEFAULT_APPEARANCE.density), reduceMotion: boolOr(v.reduceMotion, DEFAULT_APPEARANCE.reduceMotion), + disableMotion: boolOr(v.disableMotion, DEFAULT_APPEARANCE.disableMotion), highContrast: boolOr(v.highContrast, DEFAULT_APPEARANCE.highContrast), sidebarDefaultCollapsed: boolOr(v.sidebarDefaultCollapsed, DEFAULT_APPEARANCE.sidebarDefaultCollapsed), timeFormat: oneOf(v.timeFormat, ['12h', '24h'], DEFAULT_APPEARANCE.timeFormat), diff --git a/packages/webui/src/components/config/node-summary-card.tsx b/packages/webui/src/components/config/node-summary-card.tsx index 395fa8a5..fd45e4bb 100644 --- a/packages/webui/src/components/config/node-summary-card.tsx +++ b/packages/webui/src/components/config/node-summary-card.tsx @@ -9,6 +9,7 @@ import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { ToggleSwitch } from '@/components/ui/toggle-switch'; import { cn } from '@/lib/utils'; +import { useTheme } from '@/contexts/ThemeContext'; import type { AdapterCommon } from './defaults'; import type { AdapterStatus } from '@/types'; @@ -47,12 +48,13 @@ export function NodeSummaryCard({ }: NodeSummaryCardProps) { const enabled = item.enabled !== false; const blankName = !item.name?.trim(); + const off = useTheme().appearance.disableMotion; return ( (512); + private gradP = new Array(512); + constructor(seed: number) { this.seed(seed); } + + seed(seed: number) { + if (seed > 0 && seed < 1) seed *= 65536; + seed = Math.floor(seed); + if (seed < 256) seed |= seed << 8; + for (let i = 0; i < 256; i++) { + const v = (i & 1) ? P[i] ^ (seed & 255) : P[i] ^ ((seed >> 8) & 255); + this.perm[i] = this.perm[i + 256] = v; + this.gradP[i] = this.gradP[i + 256] = GRAD3[v % 12]; + } + } + + private fade(t: number) { return t * t * t * (t * (t * 6 - 15) + 10); } + private lerp(a: number, b: number, t: number) { return (1 - t) * a + t * b; } + + perlin2(x: number, y: number) { + let X = Math.floor(x), Y = Math.floor(y); + x -= X; y -= Y; + X &= 255; Y &= 255; + const n00 = this.gradP[X + this.perm[Y]].dot2(x, y); + const n01 = this.gradP[X + this.perm[Y + 1]].dot2(x, y - 1); + const n10 = this.gradP[X + 1 + this.perm[Y]].dot2(x - 1, y); + const n11 = this.gradP[X + 1 + this.perm[Y + 1]].dot2(x - 1, y - 1); + const u = this.fade(x); + return this.lerp(this.lerp(n00, n10, u), this.lerp(n01, n11, u), this.fade(y)); + } +} + +// ── Wavy-lines background (ported from the a-waves effect) ── +interface Pt { + x: number; y: number; + wave: { x: number; y: number }; + cursor: { x: number; y: number; vx: number; vy: number }; +} + +/** + * Decorative, mouse-reactive wavy-line field rendered as SVG paths and animated + * via requestAnimationFrame. Purely presentational (aria-hidden, pointer-events + * none) so it sits behind interactive content. Heavy on low-end devices — the + * login page lets the user disable it (a device-local preference). + */ +export function LoginWaves() { + const hostRef = useRef(null); + const svgRef = useRef(null); + + useEffect(() => { + const host = hostRef.current; + const svg = svgRef.current; + if (!host || !svg) return; + + const noise = new Noise(Math.random()); + const mouse = { x: -10, y: 0, lx: 0, ly: 0, sx: 0, sy: 0, v: 0, vs: 0, a: 0, set: false }; + let bounding = host.getBoundingClientRect(); + let lines: Pt[][] = []; + let paths: SVGPathElement[] = []; + let raf = 0; + + const setSize = () => { + bounding = host.getBoundingClientRect(); + svg.style.width = `${bounding.width}px`; + svg.style.height = `${bounding.height}px`; + }; + + const setLines = () => { + const { width, height } = bounding; + lines = []; + paths.forEach((p) => p.remove()); + paths = []; + + const xGap = 10; + const yGap = 32; + const oWidth = width + 200; + const oHeight = height + 30; + const totalLines = Math.ceil(oWidth / xGap); + const totalPoints = Math.ceil(oHeight / yGap); + const xStart = (width - xGap * totalLines) / 2; + const yStart = (height - yGap * totalPoints) / 2; + + for (let i = 0; i <= totalLines; i++) { + const points: Pt[] = []; + for (let j = 0; j <= totalPoints; j++) { + points.push({ + x: xStart + xGap * i, + y: yStart + yGap * j, + wave: { x: 0, y: 0 }, + cursor: { x: 0, y: 0, vx: 0, vy: 0 }, + }); + } + const path = document.createElementNS('http://www.w3.org/2000/svg', 'path'); + svg.appendChild(path); + paths.push(path); + lines.push(points); + } + }; + + const updateMouse = (x: number, y: number) => { + // pageX/pageY are already document-relative, so don't re-add scrollY. + mouse.x = x - bounding.left; + mouse.y = y - bounding.top; + if (!mouse.set) { + mouse.sx = mouse.x; mouse.sy = mouse.y; + mouse.lx = mouse.x; mouse.ly = mouse.y; + mouse.set = true; + } + }; + const onMouseMove = (e: MouseEvent) => updateMouse(e.pageX, e.pageY); + const onTouchMove = (e: TouchEvent) => { + const t = e.touches[0]; + if (t) updateMouse(t.clientX, t.clientY); + }; + const onResize = () => { setSize(); setLines(); }; + + const movePoints = (time: number) => { + lines.forEach((points) => { + points.forEach((p) => { + const move = noise.perlin2((p.x + time * 0.0125) * 0.002, (p.y + time * 0.005) * 0.0015) * 12; + p.wave.x = Math.cos(move) * 32; + p.wave.y = Math.sin(move) * 16; + + const dx = p.x - mouse.sx; + const dy = p.y - mouse.sy; + const d = Math.hypot(dx, dy); + const l = Math.max(175, mouse.vs); + if (d < l) { + const s = 1 - d / l; + const f = Math.cos(d * 0.001) * s; + p.cursor.vx += Math.cos(mouse.a) * f * l * mouse.vs * 0.00065; + p.cursor.vy += Math.sin(mouse.a) * f * l * mouse.vs * 0.00065; + } + p.cursor.vx += (0 - p.cursor.x) * 0.005; + p.cursor.vy += (0 - p.cursor.y) * 0.005; + p.cursor.vx *= 0.925; + p.cursor.vy *= 0.925; + p.cursor.x += p.cursor.vx * 2; + p.cursor.y += p.cursor.vy * 2; + p.cursor.x = Math.min(100, Math.max(-100, p.cursor.x)); + p.cursor.y = Math.min(100, Math.max(-100, p.cursor.y)); + }); + }); + }; + + const moved = (point: Pt, withCursor: boolean) => ({ + x: Math.round((point.x + point.wave.x + (withCursor ? point.cursor.x : 0)) * 10) / 10, + y: Math.round((point.y + point.wave.y + (withCursor ? point.cursor.y : 0)) * 10) / 10, + }); + + const drawLines = () => { + lines.forEach((points, lIndex) => { + const first = moved(points[0], false); + let d = `M ${first.x} ${first.y}`; + points.forEach((p, pIndex) => { + const isLast = pIndex === points.length - 1; + const m = moved(p, !isLast); + d += `L ${m.x} ${m.y}`; + }); + paths[lIndex].setAttribute('d', d); + }); + }; + + const tick = (time: number) => { + mouse.sx += (mouse.x - mouse.sx) * 0.1; + mouse.sy += (mouse.y - mouse.sy) * 0.1; + const dx = mouse.x - mouse.lx; + const dy = mouse.y - mouse.ly; + const d = Math.hypot(dx, dy); + mouse.v = d; + mouse.vs += (d - mouse.vs) * 0.1; + mouse.vs = Math.min(100, mouse.vs); + mouse.lx = mouse.x; mouse.ly = mouse.y; + mouse.a = Math.atan2(dy, dx); + movePoints(time); + drawLines(); + raf = requestAnimationFrame(tick); + }; + + setSize(); + setLines(); + window.addEventListener('resize', onResize); + window.addEventListener('mousemove', onMouseMove); + window.addEventListener('touchmove', onTouchMove, { passive: true }); + raf = requestAnimationFrame(tick); + + return () => { + cancelAnimationFrame(raf); + window.removeEventListener('resize', onResize); + window.removeEventListener('mousemove', onMouseMove); + window.removeEventListener('touchmove', onTouchMove); + paths.forEach((p) => p.remove()); + paths = []; + lines = []; + }; + }, []); + + return ( +
+ +
+ ); +} diff --git a/packages/webui/src/components/pages/login-page.tsx b/packages/webui/src/components/pages/login-page.tsx index 31af7e50..f0c7e402 100644 --- a/packages/webui/src/components/pages/login-page.tsx +++ b/packages/webui/src/components/pages/login-page.tsx @@ -1,10 +1,13 @@ import { useEffect, useState } from 'react'; import { motion } from 'motion/react'; -import { ArrowRight, Eye, EyeOff, KeyRound } from 'lucide-react'; +import { ArrowRight, Eye, EyeOff, KeyRound, Sparkles } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; +import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'; +import { ToggleSwitch } from '@/components/ui/toggle-switch'; import { ThemeToggle } from '@/components/theme-toggle'; +import { LoginWaves } from '@/components/login-waves'; import { useTheme } from '@/contexts/ThemeContext'; import { cn } from '@/lib/utils'; import { APP_NAME, APP_VERSION } from '@/types'; @@ -13,6 +16,22 @@ interface LoginPageProps { onLogin: (password: string) => Promise<{ success: boolean; error?: string }>; } +// Device-local preference for the (heavy) animated login background. Kept out +// of the server-synced appearance on purpose: it's a "this device feels laggy" +// choice, and it must work pre-auth (where settings can't persist to the +// server). Independent of the system 减弱动效 / 关闭全部动效 settings. +const LOGIN_FX_KEY = 'snowluma_login_fx'; +function readLoginFx(): boolean { + try { + const v = localStorage.getItem(LOGIN_FX_KEY); + if (v === '0') return false; + if (v === '1') return true; + } catch { /* ignore */ } + // No explicit choice yet → on by default, unless the OS asks for reduced + // motion (an accessibility default; still fully overridable via the toggle). + try { return !window.matchMedia('(prefers-reduced-motion: reduce)').matches; } catch { return true; } +} + export function LoginPage({ onLogin }: LoginPageProps) { const { appearance } = useTheme(); const customBg = appearance.background.type !== 'none'; @@ -27,6 +46,13 @@ export function LoginPage({ onLogin }: LoginPageProps) { const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const [shake, setShake] = useState(0); + const [fxOn, setFxOn] = useState(readLoginFx); + const [helpOpen, setHelpOpen] = useState(false); + + const toggleFx = (v: boolean) => { + setFxOn(v); + try { localStorage.setItem(LOGIN_FX_KEY, v ? '1' : '0'); } catch { /* ignore */ } + }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); @@ -42,7 +68,10 @@ export function LoginPage({ onLogin }: LoginPageProps) { return (
- {/* Sky gradient backdrop */} + {/* Animated wavy-line background (device-local toggle) */} + {fxOn && } + + {/* Sky gradient backdrop — also softens the waves so the card stands out */}
- - -
+
@@ -73,7 +90,7 @@ export function LoginPage({ onLogin }: LoginPageProps) { transition={{ duration: 0.45, ease: [0.16, 1, 0.3, 1] }} className="relative z-10 w-full max-w-md" > - +
@@ -139,7 +156,42 @@ export function LoginPage({ onLogin }: LoginPageProps) {

+ + {/* Perf escape hatch for the animated background */} +
+ +
+ + + + + 界面有点卡顿? + + 登录页背景是一个跟随鼠标的动态线条效果,在部分设备上可能比较吃性能。可以在这里关掉它——该开关仅作用于本设备的登录页,与系统的动效设置相互独立。 + + + +
+
+

登录页动态背景

+

{fxOn ? '已开启 · 关闭后背景为静态' : '已关闭 · 背景为静态'}

+
+ +
+ +

+ 登录后,你还可以在「系统设置 → 无障碍」里进一步「减弱动效」或「关闭全部动效」。 +

+
+
); } diff --git a/packages/webui/src/components/pages/logs-page.tsx b/packages/webui/src/components/pages/logs-page.tsx index ee4dd3c7..7d29c4e5 100644 --- a/packages/webui/src/components/pages/logs-page.tsx +++ b/packages/webui/src/components/pages/logs-page.tsx @@ -78,7 +78,7 @@ function ToolButton({ label, onClick, children, active, danger, disabled }: Tool export function LogsPage() { const api = useApi(); - const { formatClock } = useTheme(); + const { formatClock, appearance } = useTheme(); const { pages, setPages } = useLayout(); const prefs = pages.logs; @@ -434,9 +434,9 @@ export function LogsPage() { return ( diff --git a/packages/webui/src/components/pages/overview-page.tsx b/packages/webui/src/components/pages/overview-page.tsx index ba7c7a56..30ce82e1 100644 --- a/packages/webui/src/components/pages/overview-page.tsx +++ b/packages/webui/src/components/pages/overview-page.tsx @@ -46,6 +46,7 @@ function renderWidget(block: UiLayoutItem): ReactNode { export function OverviewPage() { const { qqList, processList } = useAppState(); const { overviewBlocks, setOverviewBlocks, resetLayout, editing: editingCtx, setEditing } = useLayout(); + const off = useTheme().appearance.disableMotion; const isWide = useMediaQuery('(min-width: 768px)'); // Free-grid editing is desktop-only (no room to drag/resize on a phone). const editing = isWide && editingCtx; @@ -100,7 +101,7 @@ export function OverviewPage() { {/* First-run nudge — always shown (not a grid widget) so it can't be hidden. */} {qqList.length === 0 && ( - + { const f = config.filter.trim().toLowerCase(); let arr = f @@ -398,10 +400,10 @@ function SessionsBlock({ config }: { config: SessionsConfig }) { {list.map((q, idx) => ( diff --git a/packages/webui/src/components/pages/processes-page.tsx b/packages/webui/src/components/pages/processes-page.tsx index 4e690b8d..8a7d62c5 100644 --- a/packages/webui/src/components/pages/processes-page.tsx +++ b/packages/webui/src/components/pages/processes-page.tsx @@ -10,6 +10,7 @@ import { cn } from '@/lib/utils'; import type { HookProcessInfo } from '@/types'; import { useAppState } from '@/contexts/AppStateContext'; import { useLayout } from '@/contexts/LayoutContext'; +import { useTheme } from '@/contexts/ThemeContext'; const SORT_OPTIONS: { id: string; label: string }[] = [ { id: 'pid', label: 'PID' }, @@ -50,6 +51,7 @@ export function ProcessesPage() { const { processList, processOps, refreshProcesses } = useAppState(); const { statusOf, banner: processActionStatus, load, unload, refresh } = processOps; const { pages, setPages } = useLayout(); + const off = useTheme().appearance.disableMotion; const [confirm, setConfirm] = useState<{ kind: 'load' | 'unload'; pid: number; name: string } | null>(null); const [probeDialog, setProbeDialog] = useState<{ pid: number; name: string } | null>(null); @@ -101,7 +103,7 @@ export function ProcessesPage() { {processActionStatus && ( @@ -131,9 +133,9 @@ export function ProcessesPage() { return ( {/* icon + info stay horizontal; on phones the actions drop to diff --git a/packages/webui/src/components/pages/settings-page.tsx b/packages/webui/src/components/pages/settings-page.tsx index 58ec0221..031002d1 100644 --- a/packages/webui/src/components/pages/settings-page.tsx +++ b/packages/webui/src/components/pages/settings-page.tsx @@ -380,8 +380,11 @@ function AppearancePanel() { - - setAppearance({ reduceMotion })} ariaLabel="减少动效" /> + + setAppearance({ reduceMotion })} ariaLabel="减弱动效" /> + + + setAppearance({ disableMotion })} ariaLabel="关闭全部动效" /> setAppearance({ highContrast })} ariaLabel="高对比模式" /> diff --git a/packages/webui/src/contexts/ThemeContext.tsx b/packages/webui/src/contexts/ThemeContext.tsx index c418a680..db177170 100644 --- a/packages/webui/src/contexts/ThemeContext.tsx +++ b/packages/webui/src/contexts/ThemeContext.tsx @@ -106,6 +106,7 @@ export const DEFAULT_APPEARANCE: UiAppearance = { radius: 0.75, density: 'cozy', reduceMotion: false, + disableMotion: false, highContrast: false, sidebarDefaultCollapsed: false, timeFormat: '24h', @@ -304,7 +305,11 @@ function applyAppearance(a: UiAppearance, resolved: 'light' | 'dark'): void { root.setAttribute('data-palette', a.palette); root.setAttribute('data-sidebar-style', a.sidebarStyle); root.setAttribute('data-contrast', a.highContrast ? 'high' : 'normal'); - root.setAttribute('data-reduce-motion', a.reduceMotion ? '1' : '0'); + // 减弱动效 OR 关闭全部动效 both engage the reduce-motion CSS/Framer layer; + // 关闭全部动效 additionally sets data-no-motion (kills CSS animations outright + // and gates Framer entrance fades that reduce-motion leaves on). + root.setAttribute('data-reduce-motion', (a.reduceMotion || a.disableMotion) ? '1' : '0'); + root.setAttribute('data-no-motion', a.disableMotion ? '1' : '0'); // Mode-independent vars go inline on :root. root.style.setProperty('--radius', `${a.radius}rem`); @@ -679,7 +684,7 @@ export function ThemeProvider({ children }: { children: ReactNode }) { return ( - + {children} diff --git a/packages/webui/src/index.css b/packages/webui/src/index.css index a3ab5b39..b7155f46 100644 --- a/packages/webui/src/index.css +++ b/packages/webui/src/index.css @@ -216,6 +216,17 @@ html[data-reduce-motion="1"] *::after { scroll-behavior: auto !important; } +/* 关闭全部动效: harder than reduce — remove CSS animations outright (e.g. the + pulsing status dots) rather than just collapsing their duration. Framer + entrance fades are gated in components on `disableMotion`. */ +html[data-no-motion="1"] *:not(.animate-spin), +html[data-no-motion="1"] *::before, +html[data-no-motion="1"] *::after { + /* Exclude .animate-spin: loading spinners encode "busy", not decoration — + freezing them reads as a hang. Everything else (e.g. pulse dots) stops. */ + animation: none !important; +} + /* ────────────────────────────────────────────── Native scrollbars — themed to match. Radix ScrollArea hides its own native bar and renders a custom thumb, so this only styles plain overflow @@ -238,6 +249,19 @@ html { } ::-webkit-scrollbar-corner { background: transparent; } +/* ────────────────────────────────────────────── + Login background — wavy SVG line field (see ). Themed to the + accent so it reads as a subtle decorative backdrop behind the login card. + ────────────────────────────────────────────── */ +.login-waves { + color: color-mix(in oklab, var(--primary) 26%, transparent); +} +.login-waves path { + fill: none; + stroke: currentColor; + stroke-width: 1px; +} + /* ────────────────────────────────────────────── Custom range slider (via the component, class `.slider`). The component sets `--slider-pct` for the WebKit filled track; Firefox diff --git a/packages/webui/src/types.ts b/packages/webui/src/types.ts index f391bc7a..19c2832d 100644 --- a/packages/webui/src/types.ts +++ b/packages/webui/src/types.ts @@ -202,6 +202,7 @@ export interface UiAppearance { radius: number; density: Density; reduceMotion: boolean; + disableMotion: boolean; highContrast: boolean; sidebarDefaultCollapsed: boolean; timeFormat: TimeFormat;