diff --git a/packages/webui/index.html b/packages/webui/index.html index 4ec14842..983febae 100644 --- a/packages/webui/index.html +++ b/packages/webui/index.html @@ -18,24 +18,26 @@ (function () { try { var raw = localStorage.getItem('snowluma_ui_appearance'); - if (!raw) return; - var a = JSON.parse(raw); - if (!a || typeof a !== 'object') return; + var a = raw ? JSON.parse(raw) : {}; + if (!a || typeof a !== 'object') a = {}; var root = document.documentElement; var mode = a.mode; var pal = a.palette; // A non-default palette fixes light/dark; these flavors are light, the rest dark. var LIGHT_PAL = { 'catppuccin-latte': 1, 'rose-pine-dawn': 1, 'everforest-light': 1 }; var isPal = typeof pal === 'string' && pal.length > 0 && pal !== 'default'; + var prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; var resolved = isPal ? (LIGHT_PAL[pal] ? 'light' : 'dark') : (mode === 'light' || mode === 'dark' ? mode - : (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')); + : (prefersDark ? 'dark' : 'light')); root.classList.remove('light', 'dark'); root.classList.add(resolved); root.setAttribute('data-theme', resolved); root.style.colorScheme = resolved; + var themeMeta = document.querySelector('meta[name="theme-color"]'); + if (themeMeta) themeMeta.setAttribute('content', resolved === 'dark' ? '#0a0f1a' : '#f4f7fb'); if (isPal) root.setAttribute('data-palette', pal); if (a.density === 'compact' || a.density === 'cozy') root.setAttribute('data-density', a.density); // A palette forces soft so the OLED "black" rule can't fight it. @@ -43,9 +45,13 @@ if (intensity === 'black' || intensity === 'soft') root.setAttribute('data-dark-intensity', intensity); if (a.sidebarStyle === 'follow' || a.sidebarStyle === 'panel' || a.sidebarStyle === 'accent') root.setAttribute('data-sidebar-style', a.sidebarStyle); root.setAttribute('data-contrast', a.highContrast ? 'high' : 'normal'); - root.setAttribute('data-reduce-motion', a.reduceMotion ? '1' : '0'); + var systemReduce = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches; + root.setAttribute('data-reduce-motion', (a.reduceMotion || a.disableMotion || systemReduce) ? '1' : '0'); + if (a.disableMotion) root.setAttribute('data-no-motion', '1'); if (typeof a.radius === 'number' && a.radius >= 0 && a.radius <= 2) root.style.setProperty('--radius', a.radius + 'rem'); - if (typeof a.uiScale === 'number' && a.uiScale >= 0.5 && a.uiScale <= 2) root.style.fontSize = 16 * a.uiScale + 'px'; + if (typeof a.uiScale === 'number' && a.uiScale >= 0.5 && a.uiScale <= 2) { + root.style.fontSize = (Math.round(16 * a.uiScale * 100) / 100) + 'px'; + } } catch (e) { /* ignore — fall back to default theme */ } })(); diff --git a/packages/webui/src/components/interior/floating-label.tsx b/packages/webui/src/components/interior/floating-label.tsx index 991fc372..09445bd4 100644 --- a/packages/webui/src/components/interior/floating-label.tsx +++ b/packages/webui/src/components/interior/floating-label.tsx @@ -203,6 +203,7 @@ export function FloatingLabelInput({ ref={attach} id={fieldId} name={name} + data-ui-control="" type={type} value={value} defaultValue={defaultValue} @@ -228,7 +229,7 @@ export function FloatingLabelInput({ fieldProps.onChange(event); onChange?.(event.currentTarget.value, event); }} - className={`absolute inset-0 h-full w-full rounded-[9px] bg-transparent px-3 py-0 text-base leading-5 text-foreground outline-none focus-visible:outline-none disabled:cursor-not-allowed sm:text-[13px] ${ + className={`absolute inset-0 h-full w-full appearance-none rounded-[9px] bg-transparent px-3 py-0 text-base leading-5 text-foreground outline-none focus-visible:outline-none disabled:cursor-not-allowed ${ endAdornment ? "pr-16" : "" }`} /> @@ -248,7 +249,7 @@ export function FloatingLabelInput({ scale: raised ? SHRINK : 1, }} transition={move} - style={{ originX: 0, originY: 0, willChange: "transform" }} + style={{ originX: 0, originY: 0 }} className={`absolute left-3 top-[32px] block cursor-text select-none text-base leading-5 sm:text-[13px] sm:leading-[16px] ${ invalid ? "text-destructive" diff --git a/packages/webui/src/components/ui/input.tsx b/packages/webui/src/components/ui/input.tsx index 1d405a7a..ff1fb5e2 100644 --- a/packages/webui/src/components/ui/input.tsx +++ b/packages/webui/src/components/ui/input.tsx @@ -8,7 +8,7 @@ const Input = React.forwardRef { @@ -16,3 +17,7 @@ export function useMediaQuery(query: string): boolean { return matches; } + +export function useFinePointer(): boolean { + return useMediaQuery(FINE_POINTER_QUERY); +} diff --git a/packages/webui/src/index.css b/packages/webui/src/index.css index 595175e8..16e4ebfa 100644 --- a/packages/webui/src/index.css +++ b/packages/webui/src/index.css @@ -179,8 +179,14 @@ * { border-color: var(--border); } + html { + -webkit-text-size-adjust: 100%; + text-size-adjust: 100%; + } html, body, #root { height: 100%; + height: 100dvh; + min-height: -webkit-fill-available; } body { margin: 0; @@ -253,7 +259,7 @@ hovered target's bounds. Coarse pointers and reduced-motion environments never receive data-cursor-system="custom", so native cursors remain intact. ────────────────────────────────────────────── */ -@media (hover: hover) and (pointer: fine) { +@media (hover: hover) and (pointer: fine) and (not (any-pointer: coarse)) { html { --snowluma-cursor-mode: default; } @@ -368,11 +374,11 @@ /* Applied only after the tracker mounts, so a JavaScript failure can never strand the application without a usable native pointer. */ - html[data-cursor-system="custom"], - html[data-cursor-system="custom"] body, - html[data-cursor-system="custom"] *, - html[data-cursor-system="custom"] *::before, - html[data-cursor-system="custom"] *::after { + html[data-cursor-system="custom"][data-cursor-armed="1"], + html[data-cursor-system="custom"][data-cursor-armed="1"] body, + html[data-cursor-system="custom"][data-cursor-armed="1"] *, + html[data-cursor-system="custom"][data-cursor-armed="1"] *::before, + html[data-cursor-system="custom"][data-cursor-armed="1"] *::after { cursor: none !important; } } @@ -515,12 +521,14 @@ html[data-cursor-system="custom"] .adaptive-cursor[data-visible="true"] { background: var(--primary); opacity: 0.9; transform: translate(-50%, -50%); - -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 8h12M5 5 2 8l3 3m6-6 3 3-3 3' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat; - mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 8h12M5 5 2 8l3 3m6-6 3 3-3 3' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat; + -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M2 8h12M5 5 2 8l3 3m6-6 3 3-3 3' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat; + mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M2 8h12M5 5 2 8l3 3m6-6 3 3-3 3' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat; + -webkit-mask-source-type: alpha; + mask-mode: alpha; } .adaptive-cursor[data-mode="move"] .adaptive-cursor-shape::before { - -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1v14M1 8h14M5 4 8 1l3 3m-6 8 3 3 3-3M4 5 1 8l3 3m8-6 3 3-3 3' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); - mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1v14M1 8h14M5 4 8 1l3 3m-6 8 3 3 3-3M4 5 1 8l3 3m8-6 3 3-3 3' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); + -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M8 1v14M1 8h14M5 4 8 1l3 3m-6 8 3 3 3-3M4 5 1 8l3 3m8-6 3 3-3 3' fill='none' stroke='white' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat; + mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M8 1v14M1 8h14M5 4 8 1l3 3m-6 8 3 3 3-3M4 5 1 8l3 3m8-6 3 3-3 3' fill='none' stroke='white' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat; } .adaptive-cursor[data-mode="ns-resize"] .adaptive-cursor-shape::before { transform: translate(-50%, -50%) rotate(90deg); } .adaptive-cursor[data-mode="nwse-resize"] .adaptive-cursor-shape::before { transform: translate(-50%, -50%) rotate(45deg); } @@ -822,17 +830,25 @@ html[data-kiosk="1"] [data-kiosk-hide] { when there is actually hidden content in that direction, so a fully-scrolled top/bottom row is never dimmed (readability). A static mask, not motion: kept under reduce-motion, dropped only on the hard 关闭全部动效 switch. */ +.log-fade-top, +.log-fade-bottom, +.log-fade-both { + -webkit-mask-image: none; + mask-image: none; + -webkit-mask-source-type: alpha; + mask-mode: alpha; +} .log-fade-top { - -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 100%); - mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 100%); + -webkit-mask-image: linear-gradient(to bottom, transparent 0, #fff 14px, #fff 100%); + mask-image: linear-gradient(to bottom, transparent 0, #fff 14px, #fff 100%); } .log-fade-bottom { - -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 18px), transparent 100%); - mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 18px), transparent 100%); + -webkit-mask-image: linear-gradient(to bottom, #fff 0, #fff calc(100% - 18px), transparent 100%); + mask-image: linear-gradient(to bottom, #fff 0, #fff calc(100% - 18px), transparent 100%); } .log-fade-both { - -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 18px), transparent 100%); - mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 18px), transparent 100%); + -webkit-mask-image: linear-gradient(to bottom, transparent 0, #fff 14px, #fff calc(100% - 18px), transparent 100%); + mask-image: linear-gradient(to bottom, transparent 0, #fff 14px, #fff calc(100% - 18px), transparent 100%); } /* Reduce motion: a CSS fallback for non-Framer transitions/animations. @@ -855,10 +871,10 @@ html[data-reduce-motion="1"] :is(.ui-button, [data-press-scale]) { :is(.ui-button, [data-press-scale]) { scale: 1 !important; } } -/* Keep shared form controls at 16px on narrow touch screens even when a page +/* Keep shared form controls at 16px on coarse pointers even when a page supplies a smaller desktop typography utility. This prevents iOS Safari from zooming the viewport when the control receives focus. */ -@media (max-width: 767px) { +@media (hover: none) and (pointer: coarse) { .ui-button { min-width: max(2.75rem, 44px); min-height: max(2.75rem, 44px); @@ -870,7 +886,11 @@ html[data-reduce-motion="1"] :is(.ui-button, [data-press-scale]) { height: 44px; min-height: 44px; } - [data-ui-control] { + input, + select, + textarea, + [data-ui-control], + [contenteditable]:not([contenteditable="false"]) { min-height: max(2.75rem, 44px); font-size: max(1rem, 16px); } @@ -893,6 +913,19 @@ input::-ms-reveal, input::-ms-clear { display: none; } +input::-webkit-credentials-auto-fill-button, +input::-webkit-contacts-auto-fill-button, +input::-webkit-strong-password-auto-fill-button { + visibility: hidden; + pointer-events: none; + position: absolute; + right: 0; +} +input::-webkit-search-decoration, +input::-webkit-search-cancel-button { + -webkit-appearance: none; + appearance: none; +} /* ────────────────────────────────────────────── Light/dark reveal — a circular wipe from the click point, via the View @@ -910,8 +943,24 @@ input::-ms-clear { animation: snowluma-theme-reveal 0.5s cubic-bezier(0.16, 1, 0.3, 1); } @keyframes snowluma-theme-reveal { - from { clip-path: circle(0 at var(--vt-x, 50%) var(--vt-y, 50%)); } - to { clip-path: circle(var(--vt-r, 150%) at var(--vt-x, 50%) var(--vt-y, 50%)); } + from { + -webkit-clip-path: circle(0px at var(--vt-x, 50%) var(--vt-y, 50%)); + clip-path: circle(0px at var(--vt-x, 50%) var(--vt-y, 50%)); + } + to { + -webkit-clip-path: circle(var(--vt-r, 150%) at var(--vt-x, 50%) var(--vt-y, 50%)); + clip-path: circle(var(--vt-r, 150%) at var(--vt-x, 50%) var(--vt-y, 50%)); + } +} +html[data-reduce-motion="1"]::view-transition-old(root), +html[data-reduce-motion="1"]::view-transition-new(root) { + animation: none !important; +} +@media (prefers-reduced-motion: reduce) { + ::view-transition-old(root), + ::view-transition-new(root) { + animation: none !important; + } } /* ────────────────────────────────────────────── @@ -960,13 +1009,14 @@ html { min-width: 0; height: 3rem; align-items: center; - overflow: clip; + overflow: hidden; border: 0.5px solid var(--border); border-radius: 0.75rem; background: var(--muted); cursor: grab; - touch-action: none; + touch-action: pan-y; user-select: none; + -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); transition-property: background-color, border-color, box-shadow; transition-duration: 150ms; @@ -1105,9 +1155,9 @@ html[data-reduce-motion="1"] .slider-labels { grid lines up with surrounding page padding. */ background: transparent; } -.grid-stack-item-content { +.grid-stack > .grid-stack-item > .grid-stack-item-content { inset: 0; - overflow: visible; + overflow: clip; background: transparent; display: block; } @@ -1120,10 +1170,11 @@ html[data-reduce-motion="1"] .slider-labels { /* Resize handle — only present while editing (grid is interactive). Make the bottom-right grip obvious so it's clearly draggable. */ .grid-stack-item > .ui-resizable-se { - width: 18px; - height: 18px; - right: 5px; - bottom: 5px; + width: 44px; + height: 44px; + right: 0; + bottom: 0; + touch-action: none; background-image: none; transform: none; border-right: 3px solid var(--primary); @@ -1132,6 +1183,8 @@ html[data-reduce-motion="1"] .slider-labels { opacity: 0.65; z-index: 30; } -.grid-stack-item:hover > .ui-resizable-se { - opacity: 1; +@media (hover: hover) and (pointer: fine) { + .grid-stack-item:hover > .ui-resizable-se { + opacity: 1; + } } diff --git a/packages/webui/src/lib/api/token-store.ts b/packages/webui/src/lib/api/token-store.ts index c0233c0d..037f9bc0 100644 --- a/packages/webui/src/lib/api/token-store.ts +++ b/packages/webui/src/lib/api/token-store.ts @@ -2,10 +2,18 @@ import type { TokenStore } from './types'; export function localStorageTokenStore(key: string): TokenStore { return { - load: () => localStorage.getItem(key), + load: () => { + try { + return localStorage.getItem(key); + } catch { + return null; + } + }, save: (token) => { - if (token == null) localStorage.removeItem(key); - else localStorage.setItem(key, token); + try { + if (token == null) localStorage.removeItem(key); + else localStorage.setItem(key, token); + } catch { /* private mode / storage blocked */ } }, }; } diff --git a/packages/webui/src/lib/utils.ts b/packages/webui/src/lib/utils.ts index 6e356172..4287fc68 100644 --- a/packages/webui/src/lib/utils.ts +++ b/packages/webui/src/lib/utils.ts @@ -24,3 +24,57 @@ export function formatUptime(seconds: number): string { if (m || (!d && !h)) parts.push(`${m} 分`); return parts.join(' '); } + +/** Fine desktop pointer only. iPad + mouse still reports `any-pointer: coarse`. */ +export const FINE_POINTER_QUERY = + '(hover: hover) and (pointer: fine) and (not (any-pointer: coarse))'; + +/** Safari / iOS WebKit need the `` in the document and a delayed revoke. */ +export function downloadBlob(blob: Blob, filename: string): void { + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = filename; + document.body.appendChild(a); + a.click(); + a.remove(); + setTimeout(() => URL.revokeObjectURL(url), 1000); +} + +/** Clipboard write that still works on LAN HTTP and inside a modal focus trap. */ +/** WebKit `` only accepts `#rrggbb`. */ +export function toColorInputValue(raw: string, fallback = '#0ea5e9'): string { + const v = raw.trim(); + if (/^#[0-9a-fA-F]{6}$/u.test(v)) return v; + if (/^#[0-9a-fA-F]{3}$/u.test(v)) { + return `#${v[1]}${v[1]}${v[2]}${v[2]}${v[3]}${v[3]}`; + } + return fallback; +} + +export async function copyText(value: string): Promise { + try { + if (navigator.clipboard?.writeText) { + await navigator.clipboard.writeText(value); + return true; + } + } catch { /* insecure origin / permission — fall through */ } + try { + const ta = document.createElement('textarea'); + ta.value = value; + ta.setAttribute('readonly', ''); + ta.style.position = 'fixed'; + ta.style.top = '0'; + ta.style.left = '-9999px'; + ta.style.opacity = '0.01'; + const host = document.querySelector('[role="dialog"]') ?? document.body; + host.appendChild(ta); + ta.focus(); + ta.setSelectionRange(0, ta.value.length); + const ok = document.execCommand('copy'); + host.removeChild(ta); + return ok; + } catch { + return false; + } +}