bededec29c
服务页(/services): - lg+ 双栏:左列服务菜单(NO.01-07,点击选中)、右列表单 (sticky 跟随);移动端保持上下堆叠 滑块验证码 v2(防机械脚本): - 答案坐标不再下发:缺口位置由服务端烘进 PNG(lib/captchaImage 自绘点阵底图 + 拼块裁片,lib/pngEncoder 纯 TS PNG 编码器, node:zlib 零依赖),脚本必须做图像识别才能定位 - 行为轨迹校验:拖动采样提交服务端,样本数 ≥6、总时长 ≥1.2s、 单调时间戳、峰值速度 > 平均×1.8(匀速直线 = 拒)、末点 ≈ 答案 - 位置容差 ±10px;失败 5 次作废;挑战 10 分钟过期 - IP 指纹(哈希)限流:challenge 15/10min、verify 30/10min、 咨询提交 3/小时;蜜罐字段(website)命中静默丢弃 端到端:无轨迹/匀速直线/超短时长均拒;真人节奏通过;重放拦截; 蜜罐丢弃;第 14 次刷 challenge 起 429;SMTP 真发正常。
325 lines
11 KiB
TypeScript
325 lines
11 KiB
TypeScript
"use client";
|
|
|
|
/**
|
|
* RouteTransitionOverlay — 1:1 port of the original orchestrator (chunk
|
|
* 3c6cc5b2fcccdee5.js `function M`, module 34841). ONE unified pinhole
|
|
* curtain drives BOTH the first-load entry and every route transition:
|
|
*
|
|
* startNavigation(href)
|
|
* → mode "route", phase "cover" : curtain CLOSES to the pinhole
|
|
* (0.8s customCubic radial hole + masked dots, same canvas as the
|
|
* loading curtain); on complete → router.push/replace + phase "wait".
|
|
* → phase "wait" : new page mounts. Reveal waits for
|
|
* the TARGET page's routeLoading gate (only "/" has one:
|
|
* readyToLoadHeavy && fontsReady).
|
|
* → phase "reveal" : curtain OPENS (0.8s); on complete →
|
|
* idle, navigation cleared. Scramble lines re-enabled 100ms into
|
|
* the reveal.
|
|
*
|
|
* The linear-DOM-wipe overlay this replaces did NOT match the original —
|
|
* the original never wipes; it pinholes through the masked-dots curtain.
|
|
*
|
|
* Entry mode (first mount of "/"): curtain starts fully closed
|
|
* (initialProgress 1) and the 140px progress bar shows
|
|
* 50%·fontsReady + 50%·heavyLoadProgress; reveal fires as soon as both
|
|
* gates pass (the bar fades in parallel — the original does NOT hold the
|
|
* reveal for the bar). Pages other than "/" have entryLoading disabled and
|
|
* flash through to idle invisibly. Detail pages never call
|
|
* setReadyToLoadHeavy, so their gates fall through to the disabled branch.
|
|
*/
|
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
import {
|
|
useRouteTransitionController,
|
|
useFullscreenTransitionController,
|
|
} from "@/lib/routeTransition";
|
|
import { loadingBus } from "@/lib/loadingBus";
|
|
import LoadingCurtain from "@/components/canvas/LoadingCurtain";
|
|
|
|
type Mode = "idle" | "entry" | "route";
|
|
type Phase = "wait" | "cover" | "reveal";
|
|
type Transition = { mode: Mode; phase: Phase };
|
|
|
|
/** Original `y` (defaults) + `x` ("/" only enables both gates). */
|
|
type PathLoadingConfig = {
|
|
entryLoading: { enabled: boolean };
|
|
routeLoading: { enabled: boolean };
|
|
};
|
|
const DEFAULT_CONFIG: PathLoadingConfig = {
|
|
entryLoading: { enabled: false },
|
|
routeLoading: { enabled: false },
|
|
};
|
|
const ROUTE_CONFIG: Record<string, PathLoadingConfig> = {
|
|
"/": {
|
|
entryLoading: { enabled: true },
|
|
routeLoading: { enabled: true },
|
|
},
|
|
};
|
|
|
|
function pathConfig(pathname: string | null): PathLoadingConfig {
|
|
if (!pathname) return DEFAULT_CONFIG;
|
|
return ROUTE_CONFIG[pathname] ?? DEFAULT_CONFIG;
|
|
}
|
|
|
|
function clamp(e: number, t: number, r: number) {
|
|
return Math.min(r, Math.max(t, e));
|
|
}
|
|
|
|
function targetPathname(href: string | null): string | null {
|
|
if (!href) return null;
|
|
if (href.startsWith("/")) {
|
|
const [p] = href.split("?");
|
|
return p || "/";
|
|
}
|
|
try {
|
|
return new URL(href, window.location.origin).pathname || "/";
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function useFontsReady(): boolean {
|
|
const [fontsReady, setFontsReady] = useState(false);
|
|
useEffect(() => {
|
|
let cancelled = false;
|
|
const fonts = (document as unknown as { fonts?: { ready: Promise<unknown> } })
|
|
.fonts;
|
|
if (!fonts) {
|
|
setFontsReady(true);
|
|
return;
|
|
}
|
|
fonts.ready.then(() => {
|
|
if (!cancelled) setFontsReady(true);
|
|
});
|
|
return () => {
|
|
cancelled = true;
|
|
};
|
|
}, []);
|
|
return fontsReady;
|
|
}
|
|
|
|
export default function RouteTransitionOverlay() {
|
|
const router = useRouter();
|
|
const pathname = usePathname();
|
|
const {
|
|
targetHref,
|
|
navigationReplace,
|
|
clearNavigation,
|
|
readyToLoadHeavy,
|
|
setReadyToLoadHeavy,
|
|
heavyLoadProgress,
|
|
setHeavyLoadProgress,
|
|
setAllowScrambleLines,
|
|
} = useRouteTransitionController();
|
|
const { menuOpen } = useFullscreenTransitionController();
|
|
const fontsReady = useFontsReady();
|
|
|
|
const routeFrom = useRef<{ path: string | null; coverDone: boolean }>({
|
|
path: null,
|
|
coverDone: false,
|
|
});
|
|
|
|
const [transition, setTransition] = useState<Transition>({
|
|
mode: "entry",
|
|
phase: "wait",
|
|
});
|
|
// Entry progress-bar fade state (original P/z).
|
|
const [barFading, setBarFading] = useState(false);
|
|
const [barGone, setBarGone] = useState(false);
|
|
|
|
const { mode, phase } = transition;
|
|
const fromConfig = useMemo(() => pathConfig(pathname), [pathname]);
|
|
const targetPath = useMemo(() => targetPathname(targetHref), [targetHref]);
|
|
const targetConfig = useMemo(
|
|
() => pathConfig(targetPath ?? pathname),
|
|
[targetPath, pathname]
|
|
);
|
|
|
|
// Heavy-load bridge: the provider's readyToLoadHeavy/heavyLoadProgress is
|
|
// fed by the HOME canvas in the original (cV: models + image layers all
|
|
// loaded). Our equivalent is loadingBus — keep the provider in sync so
|
|
// the gates read exactly like the original.
|
|
useEffect(() => {
|
|
const sync = () => {
|
|
const snap = loadingBus.getSnapshot();
|
|
setHeavyLoadProgress(snap.progress);
|
|
if (snap.ready) setReadyToLoadHeavy(true);
|
|
};
|
|
sync();
|
|
const un = loadingBus.subscribe(sync);
|
|
return un;
|
|
}, [setHeavyLoadProgress, setReadyToLoadHeavy]);
|
|
|
|
// Intent → cover (original effect 1).
|
|
useEffect(() => {
|
|
if (targetHref && mode === "idle") {
|
|
routeFrom.current = { path: pathname, coverDone: false };
|
|
setTransition({ mode: "route", phase: "cover" });
|
|
}
|
|
}, [targetHref, mode, pathname]);
|
|
|
|
// Entry wait → reveal (original effect 2): fires as soon as the gates
|
|
// pass — the reveal is NOT held for the progress-bar fade timers.
|
|
useEffect(() => {
|
|
if (
|
|
mode === "entry" &&
|
|
phase === "wait" &&
|
|
(!fromConfig.entryLoading.enabled || (readyToLoadHeavy && fontsReady))
|
|
) {
|
|
setTransition({ mode: "entry", phase: "reveal" });
|
|
}
|
|
}, [mode, phase, fromConfig.entryLoading.enabled, readyToLoadHeavy, fontsReady]);
|
|
|
|
// Route wait → reveal (original effect 3): new page mounted + target
|
|
// page's routeLoading gate satisfied.
|
|
useEffect(() => {
|
|
if (
|
|
mode === "route" &&
|
|
phase === "wait" &&
|
|
routeFrom.current.coverDone &&
|
|
routeFrom.current.path &&
|
|
pathname !== routeFrom.current.path &&
|
|
(!targetConfig.routeLoading.enabled || (readyToLoadHeavy && fontsReady))
|
|
) {
|
|
setTransition({ mode: "route", phase: "reveal" });
|
|
}
|
|
}, [
|
|
mode,
|
|
phase,
|
|
pathname,
|
|
targetConfig.routeLoading.enabled,
|
|
readyToLoadHeavy,
|
|
fontsReady,
|
|
]);
|
|
|
|
// Progress bar: 100% → hold 250ms → fade → 250ms → remove (original P/z
|
|
// timers; entry gate `_` only).
|
|
const heavyPct = clamp(heavyLoadProgress, 0, 100);
|
|
const progress = fromConfig.entryLoading.enabled
|
|
? clamp(50 * +fontsReady + heavyPct / 2, 0, 100)
|
|
: heavyPct;
|
|
const entryGate =
|
|
mode === "entry" &&
|
|
fromConfig.entryLoading.enabled &&
|
|
(phase === "wait" || phase === "reveal") &&
|
|
!barGone;
|
|
useEffect(() => {
|
|
if (!entryGate || barFading || progress < 100) return;
|
|
let t2: number | undefined;
|
|
const t1 = window.setTimeout(() => {
|
|
setBarFading(true);
|
|
t2 = window.setTimeout(() => setBarGone(true), 250);
|
|
}, 250);
|
|
return () => {
|
|
window.clearTimeout(t1);
|
|
if (t2 !== undefined) window.clearTimeout(t2);
|
|
};
|
|
}, [entryGate, barFading, progress]);
|
|
|
|
const onComplete = useCallback(
|
|
(open: boolean) => {
|
|
// Cover finished: navigate (original I, open branch).
|
|
if (
|
|
open &&
|
|
mode === "route" &&
|
|
phase === "cover"
|
|
) {
|
|
routeFrom.current.coverDone = true;
|
|
setAllowScrambleLines(false);
|
|
if (targetHref) {
|
|
if (navigationReplace) router.replace(targetHref);
|
|
else router.push(targetHref);
|
|
}
|
|
setTransition({ mode: "route", phase: "wait" });
|
|
return;
|
|
}
|
|
// Reveal finished: idle + clear (original I, !open non-idle branch).
|
|
if (!open && mode !== "idle" && phase === "reveal") {
|
|
setTransition({ mode: "idle", phase: "wait" });
|
|
clearNavigation();
|
|
routeFrom.current = { path: null, coverDone: false };
|
|
return;
|
|
}
|
|
},
|
|
[
|
|
mode,
|
|
phase,
|
|
targetHref,
|
|
navigationReplace,
|
|
router,
|
|
setAllowScrambleLines,
|
|
clearNavigation,
|
|
menuOpen,
|
|
]
|
|
);
|
|
|
|
// Scramble lines gate (original effect: idle → true now; reveal → +100ms).
|
|
useEffect(() => {
|
|
if (mode === "idle") {
|
|
setAllowScrambleLines(true);
|
|
return;
|
|
}
|
|
if (phase !== "reveal") return;
|
|
const t = window.setTimeout(() => setAllowScrambleLines(true), 100);
|
|
return () => window.clearTimeout(t);
|
|
}, [mode, phase, setAllowScrambleLines]);
|
|
|
|
// open prop (original O): idle → menuOpen; else closed until reveal.
|
|
const open = mode === "idle" ? menuOpen : phase !== "reveal";
|
|
// initialProgress (original B): only entry:wait starts fully closed.
|
|
const initialProgress = mode === "entry" && phase === "wait" ? 1 : undefined;
|
|
const resetKey = `${mode}:${phase}:${targetHref ?? ""}:${menuOpen ? "1" : "0"}`;
|
|
|
|
// DELIBERATE DEVIATION from the original: the original unmounts the
|
|
// curtain canvas once idle (`canvas/set false`), which costs ~200ms per
|
|
// navigation in production — invisible there, but in dev the whole R3F
|
|
// canvas + EffectComposer remount takes ~600ms and swallows most of the
|
|
// cover animation (the user literally sees the detail page appear with
|
|
// no transition). The canvas stays mounted here: frameloop="demand"
|
|
// makes an idle curtain free, and the cover starts within one frame —
|
|
// matching the original's OBSERVED choreography (dots closing from the
|
|
// edges within ~180-400ms of the click).
|
|
return (
|
|
<>
|
|
<LoadingCurtain
|
|
open={open}
|
|
duration={0.8}
|
|
initialProgress={initialProgress}
|
|
resetKey={resetKey}
|
|
onComplete={onComplete}
|
|
/>
|
|
{entryGate && <ProgressBar progress={progress} fading={barFading} />}
|
|
</>
|
|
);
|
|
}
|
|
|
|
/** Centered 140px progress bar (original `b`). */
|
|
function ProgressBar({
|
|
progress,
|
|
fading,
|
|
}: {
|
|
progress: number;
|
|
fading: boolean;
|
|
}) {
|
|
return (
|
|
<div
|
|
aria-hidden="true"
|
|
className={`left-1/2 top-1/2 z-40 fixed flex h-4 w-[140px] -translate-x-1/2 -translate-y-1/2 items-center justify-center pointer-events-none ${
|
|
fading ? "opacity-0" : "opacity-100"
|
|
}`}
|
|
style={{ transition: "opacity 250ms cubic-bezier(0.25, 1, 0.5, 1)" }}
|
|
>
|
|
<div className="relative h-1.5 w-full overflow-hidden rounded-full bg-l3">
|
|
<div
|
|
className="absolute inset-y-0 left-0 rounded-full bg-l1"
|
|
style={{
|
|
width: `${clamp(progress, 0, 100)}%`,
|
|
transition: "width 520ms cubic-bezier(0.22, 1, 0.36, 1)",
|
|
willChange: "width",
|
|
}}
|
|
/>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|