fix(webui): keep Safari forms and overlays from zooming or locking
Focus stays at 16px, a modal locks the visual viewport, and motion that WebKit clips or flashes is dropped.
This commit is contained in:
9 files changed
+118
-53
No files matched your search
@@ -51,7 +51,10 @@ export function TaskBadge() {
|
||||
const ringPct = progress === null ? null : Math.round(progress * 100);
|
||||
|
||||
return (
|
||||
<div className="fixed bottom-4 right-4 z-[60] flex flex-col items-end gap-2">
|
||||
<div
|
||||
className="fixed z-[60] flex flex-col items-end gap-2"
|
||||
style={{ bottom: 'max(1rem, env(safe-area-inset-bottom))', right: 'max(1rem, env(safe-area-inset-right))' }}
|
||||
>
|
||||
<AnimatePresence>
|
||||
{open && (
|
||||
<motion.div
|
||||
|
||||
@@ -51,20 +51,41 @@ function lockDocumentScroll() {
|
||||
locks += 1;
|
||||
if (locks > 1) return;
|
||||
|
||||
const html = document.documentElement;
|
||||
const body = document.body;
|
||||
const gap = window.innerWidth - document.documentElement.clientWidth;
|
||||
const gap = window.innerWidth - html.clientWidth;
|
||||
const scrollY = window.scrollY;
|
||||
const htmlOverflow = html.style.overflow;
|
||||
const htmlOverscroll = html.style.overscrollBehavior;
|
||||
const overflow = body.style.overflow;
|
||||
const overscroll = body.style.overscrollBehavior;
|
||||
const paddingRight = body.style.paddingRight;
|
||||
const position = body.style.position;
|
||||
const top = body.style.top;
|
||||
const insetInline = body.style.insetInline;
|
||||
const base = Number.parseFloat(window.getComputedStyle(body).paddingRight);
|
||||
|
||||
html.style.overflow = "hidden";
|
||||
html.style.overscrollBehavior = "none";
|
||||
body.style.overflow = "hidden";
|
||||
body.style.overscrollBehavior = "none";
|
||||
body.style.position = "fixed";
|
||||
body.style.insetInline = "0";
|
||||
body.style.top = `-${scrollY}px`;
|
||||
if (gap > 0) {
|
||||
body.style.paddingRight = `${(Number.isFinite(base) ? base : 0) + gap}px`;
|
||||
}
|
||||
|
||||
releaseLock = () => {
|
||||
html.style.overflow = htmlOverflow;
|
||||
html.style.overscrollBehavior = htmlOverscroll;
|
||||
body.style.overflow = overflow;
|
||||
body.style.overscrollBehavior = overscroll;
|
||||
body.style.paddingRight = paddingRight;
|
||||
body.style.position = position;
|
||||
body.style.top = top;
|
||||
body.style.insetInline = insetInline;
|
||||
window.scrollTo(0, scrollY);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -332,10 +353,32 @@ export function Modal({
|
||||
initialFocusRef,
|
||||
container,
|
||||
maxWidth = 440,
|
||||
maxHeight = "min(78vh, 620px)",
|
||||
maxHeight = "min(78dvh, 620px)",
|
||||
className = "",
|
||||
}: ModalProps) {
|
||||
const reduced = useReducedMotion();
|
||||
const [viewport, setViewport] = useState({ top: 0, height: "100%", alignStart: false });
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const vv = window.visualViewport;
|
||||
if (!vv) return;
|
||||
const update = () => {
|
||||
const keyboard = window.innerHeight - vv.height > 80;
|
||||
setViewport({
|
||||
top: vv.offsetTop,
|
||||
height: `${vv.height}px`,
|
||||
alignStart: keyboard,
|
||||
});
|
||||
};
|
||||
update();
|
||||
vv.addEventListener("resize", update);
|
||||
vv.addEventListener("scroll", update);
|
||||
return () => {
|
||||
vv.removeEventListener("resize", update);
|
||||
vv.removeEventListener("scroll", update);
|
||||
};
|
||||
}, [open]);
|
||||
|
||||
const { target, titleId, descriptionId, overlayProps, panelProps } = useModal({
|
||||
open,
|
||||
@@ -399,7 +442,10 @@ export function Modal({
|
||||
animate="open"
|
||||
exit="gone"
|
||||
variants={{ closed: {}, open: {}, gone: {} }}
|
||||
className="fixed inset-0 z-50 grid place-items-center p-4 sm:p-6"
|
||||
className={`fixed inset-x-0 z-50 grid overscroll-none p-4 sm:p-6 ${
|
||||
viewport.alignStart ? "place-items-start" : "place-items-center"
|
||||
}`}
|
||||
style={{ top: viewport.top, height: viewport.height }}
|
||||
>
|
||||
<motion.div
|
||||
aria-hidden="true"
|
||||
|
||||
@@ -42,6 +42,7 @@ export type OtpCellProps = {
|
||||
type: "text";
|
||||
inputMode: "numeric" | "text";
|
||||
autoComplete: string;
|
||||
pattern?: string;
|
||||
autoCorrect: "off";
|
||||
autoCapitalize: "off";
|
||||
spellCheck: false;
|
||||
@@ -166,7 +167,8 @@ export function useOtpInput({
|
||||
disabled,
|
||||
type: "text",
|
||||
inputMode: mode === "numeric" ? "numeric" : "text",
|
||||
autoComplete: index === 0 ? "one-time-code" : "off",
|
||||
autoComplete: index === 0 && mode === "numeric" ? "one-time-code" : "off",
|
||||
pattern: mode === "numeric" ? "[0-9]*" : undefined,
|
||||
autoCorrect: "off",
|
||||
autoCapitalize: "off",
|
||||
spellCheck: false,
|
||||
@@ -430,21 +432,13 @@ export function OtpInput({
|
||||
aria-hidden
|
||||
className="pointer-events-none absolute inset-0 grid place-items-center"
|
||||
>
|
||||
<AnimatePresence initial={false} mode="popLayout">
|
||||
<AnimatePresence initial={false}>
|
||||
{char ? (
|
||||
<motion.span
|
||||
key={char}
|
||||
initial={
|
||||
reduced
|
||||
? false
|
||||
: { opacity: 0, scale: 0.97, y: 10, filter: "blur(6px)" }
|
||||
}
|
||||
animate={{ opacity: 1, scale: 1, y: 0, filter: "blur(0px)" }}
|
||||
exit={
|
||||
reduced
|
||||
? { opacity: 0 }
|
||||
: { opacity: 0, scale: 0.98, y: -6, filter: "blur(3px)" }
|
||||
}
|
||||
initial={reduced ? false : { opacity: 0, y: 6 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
exit={{ opacity: 0 }}
|
||||
transition={enter}
|
||||
className="col-start-1 row-start-1 font-mono text-[22px] tabular-nums text-foreground"
|
||||
>
|
||||
|
||||
@@ -120,8 +120,6 @@ export function SkeletonSwap({
|
||||
? { opacity: showSkeleton ? 0 : 1 }
|
||||
: {
|
||||
opacity: showSkeleton ? 0 : 1,
|
||||
scale: showSkeleton ? 0.99 : 1,
|
||||
filter: showSkeleton ? 'blur(4px)' : 'blur(0px)',
|
||||
}
|
||||
}
|
||||
transition={reduced ? { duration: 0 } : CROSSFADE}
|
||||
@@ -141,7 +139,7 @@ export function SkeletonSwap({
|
||||
className="pointer-events-none col-start-1 row-start-1 w-full self-start"
|
||||
initial={reduced ? { opacity: 1 } : { opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={reduced ? { opacity: 0 } : { opacity: 0, filter: 'blur(3px)' }}
|
||||
exit={{ opacity: 0 }}
|
||||
transition={reduced ? { duration: 0 } : CROSSFADE}
|
||||
>
|
||||
{skeleton ?? (
|
||||
|
||||
@@ -162,6 +162,21 @@ export function LoginPage({
|
||||
onChange={() => setOtpStatus((s) => (s === 'rejected' ? 'idle' : s))}
|
||||
onComplete={(code) => { void submitTotp(code); }}
|
||||
/>
|
||||
{!useRecovery && (
|
||||
<input
|
||||
type="text"
|
||||
name="one-time-code"
|
||||
autoComplete="one-time-code"
|
||||
inputMode="numeric"
|
||||
className="sr-only"
|
||||
tabIndex={-1}
|
||||
aria-hidden="true"
|
||||
onChange={(e) => {
|
||||
const digits = e.currentTarget.value.replace(/\D/g, '').slice(0, 6);
|
||||
if (digits.length === 6) void submitTotp(digits);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="flex items-center justify-between text-[12px]">
|
||||
<button
|
||||
@@ -197,13 +212,15 @@ export function LoginPage({
|
||||
>
|
||||
<KeyRound className="pointer-events-none absolute left-3.5 top-1/2 size-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
id="login-password"
|
||||
name="password"
|
||||
type={showPwd ? 'text' : 'password'}
|
||||
placeholder="输入访问令牌"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
autoFocus
|
||||
autoComplete="current-password"
|
||||
className="h-12 rounded-xl bg-background/40 pl-10 pr-11 text-sm"
|
||||
className="h-12 rounded-xl bg-background/40 pl-10 pr-11 text-base"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
@@ -277,7 +294,7 @@ function LoginShell({
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div className={cn('relative flex min-h-screen items-center justify-center overflow-hidden px-4 py-8', customBg ? 'bg-transparent' : 'bg-background')}>
|
||||
<div className={cn('relative flex min-h-dvh items-center justify-center overflow-x-hidden px-4 py-8 pb-[max(2rem,env(safe-area-inset-bottom))] pt-[max(2rem,env(safe-area-inset-top))]', customBg ? 'bg-transparent' : 'bg-background')}>
|
||||
{fxOn && <LoginWaves />}
|
||||
|
||||
<div
|
||||
@@ -288,7 +305,7 @@ function LoginShell({
|
||||
}}
|
||||
/>
|
||||
|
||||
<div className="absolute right-4 top-4 z-20">
|
||||
<div className="absolute right-[max(1rem,env(safe-area-inset-right))] top-[max(1rem,env(safe-area-inset-top))] z-20">
|
||||
<ThemeToggle />
|
||||
</div>
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ export function OnboardingWizardPage({
|
||||
if (total === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="relative min-h-dvh overflow-x-clip bg-background antialiased">
|
||||
<div className="relative min-h-svh overflow-x-hidden bg-background antialiased">
|
||||
<div
|
||||
className="pointer-events-none absolute inset-0"
|
||||
style={{
|
||||
@@ -151,10 +151,10 @@ export function OnboardingWizardPage({
|
||||
'radial-gradient(80% 60% at 50% 0%, color-mix(in oklab, var(--primary) 18%, transparent) 0%, transparent 70%)',
|
||||
}}
|
||||
/>
|
||||
<div className="absolute right-4 top-4 z-20 sm:right-6 sm:top-6">
|
||||
<div className="absolute right-[max(1rem,env(safe-area-inset-right))] top-[max(1rem,env(safe-area-inset-top))] z-20 sm:right-6">
|
||||
<ThemeToggle />
|
||||
</div>
|
||||
<main className="relative z-10 mx-auto flex h-dvh min-h-0 w-full max-w-5xl flex-col overflow-hidden px-4 pb-4 pt-14 sm:px-6 sm:pb-5 sm:pt-4">
|
||||
<main className="relative z-10 mx-auto flex min-h-0 w-full max-w-5xl flex-1 flex-col px-4 pb-[max(1rem,env(safe-area-inset-bottom))] pt-14 sm:px-6 sm:pb-5 sm:pt-4">
|
||||
<header className="mx-auto mb-2 w-full max-w-2xl shrink-0 text-center">
|
||||
<p className="text-xs font-semibold tracking-wide text-primary">SnowLuma WebUI</p>
|
||||
<h1 className="mt-1 text-balance text-2xl font-semibold tracking-tight sm:text-3xl">完成首次使用设置</h1>
|
||||
@@ -333,7 +333,7 @@ function PasswordStep({
|
||||
const { back } = useWizardNavigation();
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex min-h-full w-full max-w-xl flex-col justify-center py-2 sm:py-5">
|
||||
<div className="mx-auto flex min-h-full w-full max-w-xl flex-col justify-start py-2 sm:py-5">
|
||||
<div className="mb-8 flex items-start gap-4">
|
||||
<div className="flex size-12 shrink-0 items-center justify-center rounded-2xl bg-primary/10 ring-1 ring-primary/20">
|
||||
<ShieldAlert className="size-5 text-primary" />
|
||||
|
||||
@@ -204,7 +204,7 @@ export function NotificationChannelDialog(props: NotificationChannelDialogProps)
|
||||
: '账号上线 / 下线时向该 Webhook POST 一条渲染后的通知。'}
|
||||
closeLabel="关闭渠道编辑弹窗"
|
||||
maxWidth={576}
|
||||
maxHeight="min(86vh, 780px)"
|
||||
maxHeight="min(86dvh, 780px)"
|
||||
footer={(
|
||||
<>
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||
|
||||
@@ -2,23 +2,33 @@ import { useMemo } from 'react';
|
||||
import { encode } from 'uqr';
|
||||
|
||||
export function TotpQr({ value, label }: { value: string; label: string }) {
|
||||
const qr = useMemo(() => encode(value, { ecc: 'M', border: 2 }), [value]);
|
||||
const modules = qr.data.flatMap((row, y) => (
|
||||
row.flatMap((on, x) => (
|
||||
on ? <rect key={`${x}-${y}`} x={x} y={y} width="1" height="1" /> : []
|
||||
))
|
||||
));
|
||||
const qr = useMemo(() => encode(value, { ecc: 'M', border: 4 }), [value]);
|
||||
const modulePx = 4;
|
||||
const px = qr.size * modulePx;
|
||||
const d = useMemo(() => {
|
||||
const parts: string[] = [];
|
||||
qr.data.forEach((row, y) => {
|
||||
row.forEach((on, x) => {
|
||||
if (on) parts.push(`M${x * modulePx},${y * modulePx}h${modulePx}v${modulePx}h-${modulePx}z`);
|
||||
});
|
||||
});
|
||||
return parts.join('');
|
||||
}, [qr]);
|
||||
|
||||
return (
|
||||
<svg
|
||||
role="img"
|
||||
aria-label={label}
|
||||
viewBox={`0 0 ${qr.size} ${qr.size}`}
|
||||
className="size-44 rounded-lg bg-white text-black"
|
||||
shapeRendering="crispEdges"
|
||||
>
|
||||
<rect width={qr.size} height={qr.size} fill="white" />
|
||||
<g fill="black">{modules}</g>
|
||||
</svg>
|
||||
<div className="rounded-lg bg-white p-2">
|
||||
<svg
|
||||
role="img"
|
||||
aria-label={label}
|
||||
width={px}
|
||||
height={px}
|
||||
viewBox={`0 0 ${px} ${px}`}
|
||||
className="block text-black"
|
||||
shapeRendering="crispEdges"
|
||||
>
|
||||
<rect width={px} height={px} fill="white" />
|
||||
<path d={d} fill="black" />
|
||||
</svg>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -6,23 +6,20 @@ interface PasswordVisibilityIconProps {
|
||||
reduceMotion?: boolean;
|
||||
}
|
||||
|
||||
const hidden = { opacity: 0, scale: 0.25, filter: 'blur(4px)' };
|
||||
const shown = { opacity: 1, scale: 1, filter: 'blur(0px)' };
|
||||
|
||||
/** A stable-size password icon whose state change remains interruptible. */
|
||||
export function PasswordVisibilityIcon({ visible, reduceMotion = false }: PasswordVisibilityIconProps) {
|
||||
const Icon = visible ? EyeOff : Eye;
|
||||
|
||||
return (
|
||||
<span aria-hidden className="relative block size-4">
|
||||
<AnimatePresence initial={false} mode="popLayout">
|
||||
<span aria-hidden className="relative block size-4 overflow-hidden">
|
||||
<AnimatePresence initial={false}>
|
||||
<motion.span
|
||||
key={visible ? 'visible' : 'hidden'}
|
||||
className="absolute inset-0 flex items-center justify-center"
|
||||
initial={reduceMotion ? false : hidden}
|
||||
animate={shown}
|
||||
exit={reduceMotion ? shown : hidden}
|
||||
transition={reduceMotion ? { duration: 0 } : { type: 'spring', duration: 0.3, bounce: 0 }}
|
||||
initial={reduceMotion ? false : { opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
transition={reduceMotion ? { duration: 0 } : { duration: 0.15 }}
|
||||
>
|
||||
<Icon className="size-4" />
|
||||
</motion.span>
|
||||
|
||||
Reference in new issue
Block a user