music and animation system

This commit is contained in:
2026-03-13 15:49:53 +01:00
parent 4916a2fc7b
commit 166ae50c49
24 changed files with 785 additions and 15 deletions

View File

@@ -1,18 +1,40 @@
'use client'
import { useGSAP } from '@gsap/react'
import gsap from 'gsap'
import { createContext, useContext, type ReactNode } from 'react'
import { SplitText } from 'gsap/SplitText'
import { ScrollTrigger } from 'gsap/all'
import { createContext, useCallback, useContext, useRef, useState, type ReactNode } from 'react'
gsap.registerPlugin(useGSAP)
const GsapContext = createContext<typeof globalThis.gsap | null>(null)
gsap.registerPlugin(ScrollTrigger)
gsap.registerPlugin(SplitText)
const GsapContext = createContext<{ addAnimation: (animation: gsap.core.TimelineChild) => void, resetTimeline: () => void} | null>(null)
export function useGsapContext() {
return useContext(GsapContext)
}
export default function GsapProvider({children}:{children:ReactNode}) {
export default function GsapProvider({ children }: { children: ReactNode }) {
const [tl, setTl] = useState<GSAPTimeline | undefined>();
const indexRef = useRef<number>(0)
const { contextSafe } = useGSAP(() => {
console.log("App effect (create timeline)");
const tl = gsap.timeline();
setTl(() => tl);
}, []);
const addAnimation = useCallback((animation: gsap.core.TimelineChild) => {
indexRef.current += 1;
console.log(indexRef.current)
tl && tl.add(animation, indexRef.current * 2);
}, [tl]);
const resetTimeline = useCallback(() => {
const tl = gsap.timeline();
setTl(() => tl)
indexRef.current = 0;
},[tl])
return (
<GsapContext.Provider value={gsap}>
<GsapContext.Provider value={{ addAnimation, resetTimeline }}>
{children}
</GsapContext.Provider>
)