import { createContext, useContext, ReactNode } from 'react' interface TriggerPuzzleAnimationOptions { onComplete?: () => void } interface PuzzleAnimationContextType { /** 触发碎片动画,传递碎片ID,并在动画结束后 resolve */ triggerPuzzleAnimation: ( pieceId: number, options?: TriggerPuzzleAnimationOptions ) => Promise } const PuzzleAnimationContext = createContext(null) export const PuzzleAnimationProvider = ({ children, triggerPuzzleAnimation, }: { children: ReactNode triggerPuzzleAnimation: ( pieceId: number, options?: TriggerPuzzleAnimationOptions ) => Promise }) => { return ( {children} ) } export const usePuzzleAnimation = () => { const context = useContext(PuzzleAnimationContext) if (!context) { throw new Error('usePuzzleAnimation must be used within PuzzleAnimationProvider') } return context }