import React, { useState, useEffect, useCallback } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { X, ChevronRight, ChevronLeft, Sparkles, MousePointer, Keyboard, Zap, Check } from 'lucide-react'; import { cn } from '@/utils'; interface OnboardingStep { id: string; title: string; description: string; icon: React.ReactNode; target?: string; position?: 'top' | 'bottom' | 'left' | 'right' | 'center'; } const onboardingSteps: OnboardingStep[] = [ { id: 'welcome', title: '欢迎使用 Pixel', description: 'Pixel 是一个 AI 驱动的漫画和视频创作平台。让我们花几分钟了解一下核心功能。', icon: , position: 'center' }, { id: 'canvas', title: '画布工作区', description: '这是你的创作画布。你可以在这里添加节点、连接它们来构建创作流程。拖拽左侧的节点到画布上开始创作。', icon: , target: '.react-flow__pane', position: 'center' }, { id: 'sidebar', title: '左侧工具栏', description: '这里提供了各种 AI 生成节点:图像生成、视频生成、剧本处理等。点击或拖拽到画布上使用。', icon: , target: '[data-panel="left-dock"]', position: 'right' }, { id: 'shortcuts', title: '快捷键', description: '使用快捷键可以提高创作效率。Ctrl+S 保存,Ctrl+Z 撤销,Ctrl+A 全选。点击右下角的键盘图标查看全部快捷键。', icon: , target: '[data-shortcut-button]', position: 'top' }, { id: 'complete', title: '准备开始创作', description: '你已经了解了基本操作。开始你的第一个 AI 创作项目吧!如有问题,随时查看帮助文档。', icon: , position: 'center' } ]; const STORAGE_KEY = 'pixel-onboarding-completed'; export function OnboardingTour() { const [isOpen, setIsOpen] = useState(false); const [currentStep, setCurrentStep] = useState(0); const [hasCompleted, setHasCompleted] = useState(false); useEffect(() => { // Check if user has completed onboarding const completed = localStorage.getItem(STORAGE_KEY); if (!completed) { // Show onboarding after a short delay const timer = setTimeout(() => { setIsOpen(true); }, 1000); return () => clearTimeout(timer); } else { setHasCompleted(true); } }, []); const handleComplete = useCallback(() => { localStorage.setItem(STORAGE_KEY, 'true'); setHasCompleted(true); setIsOpen(false); }, []); const handleNext = useCallback(() => { if (currentStep < onboardingSteps.length - 1) { setCurrentStep(prev => prev + 1); } else { handleComplete(); } }, [currentStep, handleComplete]); const handlePrev = useCallback(() => { if (currentStep > 0) { setCurrentStep(prev => prev - 1); } }, [currentStep]); const handleSkip = useCallback(() => { localStorage.setItem(STORAGE_KEY, 'true'); setHasCompleted(true); setIsOpen(false); }, []); const handleRestart = useCallback(() => { localStorage.removeItem(STORAGE_KEY); setHasCompleted(false); setCurrentStep(0); setIsOpen(true); }, []); const step = onboardingSteps[currentStep]; const isFirstStep = currentStep === 0; const isLastStep = currentStep === onboardingSteps.length - 1; const progress = ((currentStep + 1) / onboardingSteps.length) * 100; if (!isOpen) { // Show restart button if user has completed but wants to see it again if (hasCompleted) { return ( ); } return null; } return ( <> {/* Backdrop */} {isOpen && ( )} {/* Onboarding Card */} {/* Progress bar */}
{/* Close button */} {/* Content */}
{/* Icon */}
{step.icon}
{/* Title */}

{step.title}

{/* Description */}

{step.description}

{/* Step indicator */}
{onboardingSteps.map((_, index) => (
))}
{/* Navigation */}
{!isLastStep && ( )}
); } export function ResetOnboardingButton() { const handleReset = () => { localStorage.removeItem(STORAGE_KEY); window.location.reload(); }; return ( ); }