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);
|
const ringPct = progress === null ? null : Math.round(progress * 100);
|
||||||
|
|
||||||
return (
|
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>
|
<AnimatePresence>
|
||||||
{open && (
|
{open && (
|
||||||
<motion.div
|
<motion.div
|
||||||
|
|||||||
@@ -51,20 +51,41 @@ function lockDocumentScroll() {
|
|||||||
locks += 1;
|
locks += 1;
|
||||||
if (locks > 1) return;
|
if (locks > 1) return;
|
||||||
|
|
||||||
|
const html = document.documentElement;
|
||||||
const body = document.body;
|
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 overflow = body.style.overflow;
|
||||||
|
const overscroll = body.style.overscrollBehavior;
|
||||||
const paddingRight = body.style.paddingRight;
|
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);
|
const base = Number.parseFloat(window.getComputedStyle(body).paddingRight);
|
||||||
|
|
||||||
|
html.style.overflow = "hidden";
|
||||||
|
html.style.overscrollBehavior = "none";
|
||||||
body.style.overflow = "hidden";
|
body.style.overflow = "hidden";
|
||||||
|
body.style.overscrollBehavior = "none";
|
||||||
|
body.style.position = "fixed";
|
||||||
|
body.style.insetInline = "0";
|
||||||
|
body.style.top = `-${scrollY}px`;
|
||||||
if (gap > 0) {
|
if (gap > 0) {
|
||||||
body.style.paddingRight = `${(Number.isFinite(base) ? base : 0) + gap}px`;
|
body.style.paddingRight = `${(Number.isFinite(base) ? base : 0) + gap}px`;
|
||||||
}
|
}
|
||||||
|
|
||||||
releaseLock = () => {
|
releaseLock = () => {
|
||||||
|
html.style.overflow = htmlOverflow;
|
||||||
|
html.style.overscrollBehavior = htmlOverscroll;
|
||||||
body.style.overflow = overflow;
|
body.style.overflow = overflow;
|
||||||
|
body.style.overscrollBehavior = overscroll;
|
||||||
body.style.paddingRight = paddingRight;
|
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,
|
initialFocusRef,
|
||||||
container,
|
container,
|
||||||
maxWidth = 440,
|
maxWidth = 440,
|
||||||
maxHeight = "min(78vh, 620px)",
|
maxHeight = "min(78dvh, 620px)",
|
||||||
className = "",
|
className = "",
|
||||||
}: ModalProps) {
|
}: ModalProps) {
|
||||||
const reduced = useReducedMotion();
|
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({
|
const { target, titleId, descriptionId, overlayProps, panelProps } = useModal({
|
||||||
open,
|
open,
|
||||||
@@ -399,7 +442,10 @@ export function Modal({
|
|||||||
animate="open"
|
animate="open"
|
||||||
exit="gone"
|
exit="gone"
|
||||||
variants={{ closed: {}, open: {}, 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
|
<motion.div
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ export type OtpCellProps = {
|
|||||||
type: "text";
|
type: "text";
|
||||||
inputMode: "numeric" | "text";
|
inputMode: "numeric" | "text";
|
||||||
autoComplete: string;
|
autoComplete: string;
|
||||||
|
pattern?: string;
|
||||||
autoCorrect: "off";
|
autoCorrect: "off";
|
||||||
autoCapitalize: "off";
|
autoCapitalize: "off";
|
||||||
spellCheck: false;
|
spellCheck: false;
|
||||||
@@ -166,7 +167,8 @@ export function useOtpInput({
|
|||||||
disabled,
|
disabled,
|
||||||
type: "text",
|
type: "text",
|
||||||
inputMode: mode === "numeric" ? "numeric" : "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",
|
autoCorrect: "off",
|
||||||
autoCapitalize: "off",
|
autoCapitalize: "off",
|
||||||
spellCheck: false,
|
spellCheck: false,
|
||||||
@@ -430,21 +432,13 @@ export function OtpInput({
|
|||||||
aria-hidden
|
aria-hidden
|
||||||
className="pointer-events-none absolute inset-0 grid place-items-center"
|
className="pointer-events-none absolute inset-0 grid place-items-center"
|
||||||
>
|
>
|
||||||
<AnimatePresence initial={false} mode="popLayout">
|
<AnimatePresence initial={false}>
|
||||||
{char ? (
|
{char ? (
|
||||||
<motion.span
|
<motion.span
|
||||||
key={char}
|
key={char}
|
||||||
initial={
|
initial={reduced ? false : { opacity: 0, y: 6 }}
|
||||||
reduced
|
animate={{ opacity: 1, y: 0 }}
|
||||||
? false
|
exit={{ opacity: 0 }}
|
||||||
: { 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)" }
|
|
||||||
}
|
|
||||||
transition={enter}
|
transition={enter}
|
||||||
className="col-start-1 row-start-1 font-mono text-[22px] tabular-nums text-foreground"
|
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 }
|
||||||
: {
|
: {
|
||||||
opacity: showSkeleton ? 0 : 1,
|
opacity: showSkeleton ? 0 : 1,
|
||||||
scale: showSkeleton ? 0.99 : 1,
|
|
||||||
filter: showSkeleton ? 'blur(4px)' : 'blur(0px)',
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
transition={reduced ? { duration: 0 } : CROSSFADE}
|
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"
|
className="pointer-events-none col-start-1 row-start-1 w-full self-start"
|
||||||
initial={reduced ? { opacity: 1 } : { opacity: 0 }}
|
initial={reduced ? { opacity: 1 } : { opacity: 0 }}
|
||||||
animate={{ opacity: 1 }}
|
animate={{ opacity: 1 }}
|
||||||
exit={reduced ? { opacity: 0 } : { opacity: 0, filter: 'blur(3px)' }}
|
exit={{ opacity: 0 }}
|
||||||
transition={reduced ? { duration: 0 } : CROSSFADE}
|
transition={reduced ? { duration: 0 } : CROSSFADE}
|
||||||
>
|
>
|
||||||
{skeleton ?? (
|
{skeleton ?? (
|
||||||
|
|||||||
@@ -162,6 +162,21 @@ export function LoginPage({
|
|||||||
onChange={() => setOtpStatus((s) => (s === 'rejected' ? 'idle' : s))}
|
onChange={() => setOtpStatus((s) => (s === 'rejected' ? 'idle' : s))}
|
||||||
onComplete={(code) => { void submitTotp(code); }}
|
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]">
|
<div className="flex items-center justify-between text-[12px]">
|
||||||
<button
|
<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" />
|
<KeyRound className="pointer-events-none absolute left-3.5 top-1/2 size-4 -translate-y-1/2 text-muted-foreground" />
|
||||||
<Input
|
<Input
|
||||||
|
id="login-password"
|
||||||
|
name="password"
|
||||||
type={showPwd ? 'text' : 'password'}
|
type={showPwd ? 'text' : 'password'}
|
||||||
placeholder="输入访问令牌"
|
placeholder="输入访问令牌"
|
||||||
value={password}
|
value={password}
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
autoFocus
|
autoFocus
|
||||||
autoComplete="current-password"
|
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
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -277,7 +294,7 @@ function LoginShell({
|
|||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}) {
|
}) {
|
||||||
return (
|
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 />}
|
{fxOn && <LoginWaves />}
|
||||||
|
|
||||||
<div
|
<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 />
|
<ThemeToggle />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ export function OnboardingWizardPage({
|
|||||||
if (total === 0) return null;
|
if (total === 0) return null;
|
||||||
|
|
||||||
return (
|
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
|
<div
|
||||||
className="pointer-events-none absolute inset-0"
|
className="pointer-events-none absolute inset-0"
|
||||||
style={{
|
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%)',
|
'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 />
|
<ThemeToggle />
|
||||||
</div>
|
</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">
|
<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>
|
<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>
|
<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();
|
const { back } = useWizardNavigation();
|
||||||
|
|
||||||
return (
|
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="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">
|
<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" />
|
<ShieldAlert className="size-5 text-primary" />
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ export function NotificationChannelDialog(props: NotificationChannelDialogProps)
|
|||||||
: '账号上线 / 下线时向该 Webhook POST 一条渲染后的通知。'}
|
: '账号上线 / 下线时向该 Webhook POST 一条渲染后的通知。'}
|
||||||
closeLabel="关闭渠道编辑弹窗"
|
closeLabel="关闭渠道编辑弹窗"
|
||||||
maxWidth={576}
|
maxWidth={576}
|
||||||
maxHeight="min(86vh, 780px)"
|
maxHeight="min(86dvh, 780px)"
|
||||||
footer={(
|
footer={(
|
||||||
<>
|
<>
|
||||||
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||||
|
|||||||
@@ -2,23 +2,33 @@ import { useMemo } from 'react';
|
|||||||
import { encode } from 'uqr';
|
import { encode } from 'uqr';
|
||||||
|
|
||||||
export function TotpQr({ value, label }: { value: string; label: string }) {
|
export function TotpQr({ value, label }: { value: string; label: string }) {
|
||||||
const qr = useMemo(() => encode(value, { ecc: 'M', border: 2 }), [value]);
|
const qr = useMemo(() => encode(value, { ecc: 'M', border: 4 }), [value]);
|
||||||
const modules = qr.data.flatMap((row, y) => (
|
const modulePx = 4;
|
||||||
row.flatMap((on, x) => (
|
const px = qr.size * modulePx;
|
||||||
on ? <rect key={`${x}-${y}`} x={x} y={y} width="1" height="1" /> : []
|
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 (
|
return (
|
||||||
<svg
|
<div className="rounded-lg bg-white p-2">
|
||||||
role="img"
|
<svg
|
||||||
aria-label={label}
|
role="img"
|
||||||
viewBox={`0 0 ${qr.size} ${qr.size}`}
|
aria-label={label}
|
||||||
className="size-44 rounded-lg bg-white text-black"
|
width={px}
|
||||||
shapeRendering="crispEdges"
|
height={px}
|
||||||
>
|
viewBox={`0 0 ${px} ${px}`}
|
||||||
<rect width={qr.size} height={qr.size} fill="white" />
|
className="block text-black"
|
||||||
<g fill="black">{modules}</g>
|
shapeRendering="crispEdges"
|
||||||
</svg>
|
>
|
||||||
|
<rect width={px} height={px} fill="white" />
|
||||||
|
<path d={d} fill="black" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -6,23 +6,20 @@ interface PasswordVisibilityIconProps {
|
|||||||
reduceMotion?: boolean;
|
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. */
|
/** A stable-size password icon whose state change remains interruptible. */
|
||||||
export function PasswordVisibilityIcon({ visible, reduceMotion = false }: PasswordVisibilityIconProps) {
|
export function PasswordVisibilityIcon({ visible, reduceMotion = false }: PasswordVisibilityIconProps) {
|
||||||
const Icon = visible ? EyeOff : Eye;
|
const Icon = visible ? EyeOff : Eye;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span aria-hidden className="relative block size-4">
|
<span aria-hidden className="relative block size-4 overflow-hidden">
|
||||||
<AnimatePresence initial={false} mode="popLayout">
|
<AnimatePresence initial={false}>
|
||||||
<motion.span
|
<motion.span
|
||||||
key={visible ? 'visible' : 'hidden'}
|
key={visible ? 'visible' : 'hidden'}
|
||||||
className="absolute inset-0 flex items-center justify-center"
|
className="absolute inset-0 flex items-center justify-center"
|
||||||
initial={reduceMotion ? false : hidden}
|
initial={reduceMotion ? false : { opacity: 0 }}
|
||||||
animate={shown}
|
animate={{ opacity: 1 }}
|
||||||
exit={reduceMotion ? shown : hidden}
|
exit={{ opacity: 0 }}
|
||||||
transition={reduceMotion ? { duration: 0 } : { type: 'spring', duration: 0.3, bounce: 0 }}
|
transition={reduceMotion ? { duration: 0 } : { duration: 0.15 }}
|
||||||
>
|
>
|
||||||
<Icon className="size-4" />
|
<Icon className="size-4" />
|
||||||
</motion.span>
|
</motion.span>
|
||||||
|
|||||||
Reference in new issue
Block a user