import { Component, lazy, Suspense, useEffect, useRef, useState, type ReactNode } from "react"; import { Button, ConfigProvider, Select, Tabs } from "antd"; import { ArrowDown, ArrowRight, ArrowUpRight, Code2, Menu, Pause, Play, X } from "lucide-react"; import { BrandLogo } from "@/components/brand/brand-logo"; import { IconButton } from "@/components/ui/base/buttons"; import { getAntThemeConfig } from "@/lib/app-theme"; import { useAppearanceStore } from "@/stores/use-appearance-store"; import { WelcomeContributorsCard } from "./contributors-card"; import { chapters, getWelcomeLook, showcases, welcomeLooks, type WelcomeLook } from "./story"; import "./welcome.css"; const StoryReel = lazy(() => import("./story-reel")); const github = "https://github.com/ddcat-ai/open-ai-canvas"; export default function WelcomePage() { const [look, setLook] = useState(getWelcomeLook); const appearance = useAppearanceStore((state) => state.appearance); const restorePickerFocus = useRef(false); useEffect(() => { if (!restorePickerFocus.current) return; document.getElementById("welcome-look-select")?.focus({ preventScroll: true }); restorePickerFocus.current = false; }, [look]); useEffect(() => { const onHistory = () => setLook(getWelcomeLook()); window.addEventListener("popstate", onHistory); return () => window.removeEventListener("popstate", onHistory); }, []); const changeLook = (id: string) => { const next = welcomeLooks.find((item) => item.id === id); if (!next || next.id === look.id) return; const url = new URL(window.location.href); url.searchParams.set("look", id); window.history.pushState(null, "", url); restorePickerFocus.current = true; setLook(next); }; return ( ); } function WelcomeExperience({ look, brandName, onLookChange }: { look: WelcomeLook; brandName: string; onLookChange: (id: string) => void }) { const storyRef = useRef(null); const progressRef = useRef(0); const [chapter, setChapter] = useState(0); const [reduced, setReduced] = useState(() => window.matchMedia("(prefers-reduced-motion: reduce)").matches); const [paused, setPaused] = useState(false); const [failed, setFailed] = useState(false); const [ready, setReady] = useState(false); const [menu, setMenu] = useState(false); const [showcase, setShowcase] = useState(1); const [playing, setPlaying] = useState(false); const videoRef = useRef(null); useEffect(() => { document.title = "影策 · 让一个故事从文字走向银幕"; const media = window.matchMedia("(prefers-reduced-motion: reduce)"); const onMotion = () => setReduced(media.matches); media.addEventListener("change", onMotion); const onScroll = () => { if (!storyRef.current) return; const rect = storyRef.current.getBoundingClientRect(); const progress = Math.max(0, Math.min(1, -rect.top / (rect.height - window.innerHeight))); progressRef.current = progress; storyRef.current.style.setProperty("--story-progress", String(progress)); setChapter(Math.min(5, Math.floor(progress * 6))); }; window.addEventListener("scroll", onScroll, { passive: true }); window.addEventListener("resize", onScroll); onScroll(); return () => { media.removeEventListener("change", onMotion); window.removeEventListener("scroll", onScroll); window.removeEventListener("resize", onScroll); }; }, []); useEffect(() => { if (!playing) return; const close = (event: KeyboardEvent) => { if (event.key === "Escape") setPlaying(false); }; window.addEventListener("keydown", close); return () => window.removeEventListener("keydown", close); }, [playing]); const jumpTo = (index: number) => { if (!storyRef.current) return; const height = storyRef.current.offsetHeight - window.innerHeight; window.scrollTo({ top: storyRef.current.offsetTop + height * (index === 5 ? 0.97 : index / 6 + (index ? 0.04 : 0)), behavior: reduced ? "instant" : "smooth" }); setMenu(false); }; const staticScene = reduced || failed; const active = showcases[showcase]; return ( 前往工作台介绍 } /> {brandName} setMenu(false)}>工作台 setMenu(false)}>贡献者 GitHub } iconPlacement="end">开始创作 setMenu(!menu)} /> {!staticScene && setFailed(true)}> setReady(true)} onError={() => setFailed(true)} />} {chapters.map((item, index) => ( {index === 0 ? {item.title} : {item.title.split(",").map((part, partIndex, parts) => {part}{partIndex < parts.length - 1 ? "," : ""})}} {"subtitle" in item && <>{item.subtitle}{look.video && setPlaying(true)} tabIndex={chapter === 0 ? 0 : -1} icon={}>观看片段}>} ))} chapter < 5 ? jumpTo(chapter + 1) : document.getElementById("workbench")?.scrollIntoView({ behavior: reduced ? "instant" : "smooth" })} /> {chapters.map((item, index) => jumpTo(index)}>)} setPaused(!paused)} /> 让想象,有处落笔。 ({ key: String(index), label: item.name }))} onChange={(key) => setShowcase(Number(key))} />} iconPlacement="end">进入{active.name} {active.detail} 你的故事,现在开始。 {look.credit && {look.credit} · 署名与许可} {playing && look.video && setPlaying(false)} videoRef={videoRef} />} ); } function FilmDialog({ look, onClose, videoRef }: { look: WelcomeLook; onClose: () => void; videoRef: React.RefObject }) { const dialogRef = useRef(null); useEffect(() => { const dialog = dialogRef.current; dialog?.showModal(); return () => dialog?.close(); }, []); return { if (event.target === event.currentTarget) onClose(); }}>{look.credit ?? look.title}; } class SceneBoundary extends Component<{ children: ReactNode; onError: () => void }, { failed: boolean }> { state = { failed: false }; static getDerivedStateFromError() { return { failed: true }; } componentDidCatch() { this.props.onError(); } render() { return this.state.failed ? null : this.props.children; } }
{item.subtitle}
{active.detail}
{look.credit ?? look.title}