"use client";
import Link from "next/link";
import { useEffect, useRef } from "react";
import { ThemeToggle } from "~/components/theme-toggle";
import { useRemoteConfig } from "~/lib/use-remote-config";
/**
* External jump targets — kept for later re-enable, currently shielded.
* Flip EXTERNAL_JUMP_ENABLED to true to restore off-site links.
*/
const EXTERNAL_JUMP_ENABLED = false;
const EXTERNAL_PORTALS = {
nav: "https://nav.hackrobot.cn/",
book: "https://nomadweb.nomadro.com/book",
community: "https://nomadweb.nomadro.com",
vip: "https://vip.hackrobot.cn/",
} as const;
const INTERNAL_PORTALS = {
nav: "/nav",
book: "/book",
community: "/community",
vip: "/vip",
} as const;
/** 公开入口:不含收费会员页(深链 / 开发快捷另开) */
const PORTALS = [
{
id: "nav" as const,
moduleKey: "nav" as const,
emoji: "🧭",
name: "出海导航",
main: false,
},
{
id: "book" as const,
moduleKey: "book" as const,
emoji: "📖",
name: "数字游民小册",
main: false,
},
{
id: "community" as const,
moduleKey: "community" as const,
emoji: "🌏",
name: "旅居社群",
main: true,
},
];
function LogoIcon() {
return (
);
}
function GlobeVisual() {
return (
);
}
function ParticleCanvas() {
const canvasRef = useRef(null);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas) return;
const ctx = canvas.getContext("2d");
if (!ctx) return;
let particles: {
x: number;
y: number;
r: number;
vx: number;
vy: number;
a: number;
}[] = [];
let w = 0;
let h = 0;
let raf = 0;
let running = true;
const resize = () => {
w = canvas.width = window.innerWidth;
h = canvas.height = window.innerHeight;
const n = Math.min(60, Math.floor((w * h) / 22000));
particles = Array.from({ length: n }, () => ({
x: Math.random() * w,
y: Math.random() * h,
r: Math.random() * 1.6 + 0.4,
vx: (Math.random() - 0.5) * 0.3,
vy: (Math.random() - 0.5) * 0.3,
a: Math.random() * 0.4 + 0.15,
}));
};
const draw = () => {
if (!running) return;
ctx.clearRect(0, 0, w, h);
particles.forEach((p, i) => {
p.x += p.vx;
p.y += p.vy;
if (p.x < 0 || p.x > w) p.vx *= -1;
if (p.y < 0 || p.y > h) p.vy *= -1;
ctx.beginPath();
ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2);
ctx.fillStyle = `rgba(255,255,255,${p.a})`;
ctx.fill();
for (let j = i + 1; j < particles.length; j++) {
const q = particles[j]!;
const d = Math.hypot(p.x - q.x, p.y - q.y);
if (d < 110) {
ctx.beginPath();
ctx.moveTo(p.x, p.y);
ctx.lineTo(q.x, q.y);
ctx.strokeStyle = `rgba(78,205,196,${0.16 * (1 - d / 110)})`;
ctx.stroke();
}
}
});
raf = requestAnimationFrame(draw);
};
resize();
draw();
window.addEventListener("resize", resize);
return () => {
running = false;
cancelAnimationFrame(raf);
window.removeEventListener("resize", resize);
};
}, []);
return (
);
}
function HubLoader() {
const ref = useRef(null);
useEffect(() => {
const hide = () => ref.current?.classList.add("hidden");
const onLoad = () => setTimeout(hide, 1200);
const fallback = setTimeout(hide, 2200);
if (document.readyState === "complete") {
onLoad();
} else {
window.addEventListener("load", onLoad);
}
return () => {
clearTimeout(fallback);
window.removeEventListener("load", onLoad);
};
}, []);
return (
);
}
export function Hero() {
const navRef = useRef(null);
const { config } = useRemoteConfig();
useEffect(() => {
const nav = navRef.current;
const onScroll = () =>
nav?.classList.toggle("scrolled", window.scrollY > 24);
window.addEventListener("scroll", onScroll, { passive: true });
onScroll();
const reveals = document.querySelectorAll(".hub-reveal");
let io: IntersectionObserver | null = null;
if ("IntersectionObserver" in window) {
io = new IntersectionObserver(
(entries) => {
entries.forEach((e) => {
if (e.isIntersecting) {
e.target.classList.add("visible");
io?.unobserve(e.target);
}
});
},
{ threshold: 0.12 },
);
reveals.forEach((el) => io!.observe(el));
} else {
reveals.forEach((el) => el.classList.add("visible"));
}
return () => {
window.removeEventListener("scroll", onScroll);
io?.disconnect();
};
}, []);
const portals = PORTALS.filter((p) => {
const mod = config.modules[p.moduleKey];
return mod?.enabled !== false;
});
return (
随处工作
自由生活
{portals.map((portal) => {
const href = EXTERNAL_JUMP_ENABLED
? EXTERNAL_PORTALS[portal.id]
: INTERNAL_PORTALS[portal.id];
const className = `hub-portal-card${portal.main ? " hub-portal-card--main" : ""}`;
const name =
config.modules[portal.moduleKey]?.title || portal.name;
const body = (
<>
{portal.emoji}
{name}
>
);
if (EXTERNAL_JUMP_ENABLED) {
return (
{body}
);
}
return (
{body}
);
})}
);
}