Skip to content
패키지 목록

@hua-labs/motion-advanced
Pro

v1.0.0
Animation
Advanced

프로덕션 레벨 애니메이션을 위한 고급 모션 훅. 오케스트레이션, 게임 루프, 성능 최적화.

Pro 패키지 혜택

  • • 복잡한 애니메이션 시퀀스 관리
  • • 60fps 게임 루프 지원
  • • 성능 모니터링 및 최적화
  • • 우선 지원
$npm install @hua-labs/motion-advanced

제공 훅

Auto 시리즈

자동화된 모션 훅들

useAutoSlideuseAutoScaleuseAutoFadeuseAutoPlay

오케스트레이션

복잡한 애니메이션 시퀀스 관리

useMotionOrchestrauseOrchestrationuseSequence

고급 인터랙션

레이아웃, 키보드, 스크롤 기반 모션

useLayoutMotionuseKeyboardToggleuseScrollDirectionuseStickyToggleuseScrollToggleuseVisibilityToggleuseInteractive

특수 기능

성능 모니터링, 국제화, 게임 루프

usePerformanceMonitoruseLanguageAwareMotionuseGameLoop

사용 예시

useMotionOrchestra
Orchestration

여러 모션을 순차(sequential), 병렬(parallel), 스태거(stagger) 방식으로 실행

tsx
import { useMotionOrchestra } from '@hua-labs/motion-advanced';

function AnimatedSection() {
  const orchestra = useMotionOrchestra({
    mode: 'stagger',      // 'sequential' | 'parallel' | 'stagger'
    staggerDelay: 100,    // stagger 모드 시 간격 (ms)
    autoStart: false,
    loop: false,
    onComplete: () => console.log('All done!')
  });

  // 모션 단계 추가
  useEffect(() => {
    orchestra.addMotion({
      id: 'title',
      motion: () => animateTitle(),
      delay: 0
    });
    orchestra.addMotion({
      id: 'content',
      motion: () => animateContent(),
      delay: 200
    });
  }, []);

  return (
    <div>
      <button onClick={orchestra.play}>Play</button>
      <button onClick={orchestra.pause}>Pause</button>
      <button onClick={orchestra.stop}>Stop</button>
      <p>Step: {orchestra.currentStep} / {orchestra.totalSteps}</p>
    </div>
  );
}

// Returns
// - addMotion(step): 모션 단계 추가
// - removeMotion(id): 모션 단계 제거
// - play(): 재생 시작
// - stop(): 정지
// - pause(): 일시정지
// - resume(): 재개
// - isPlaying: boolean
// - currentStep: number
// - completedSteps: Set<string>
// - totalSteps: number

useGameLoop
Special

requestAnimationFrame 기반 게임 루프. FPS 제한, 성능 경고 지원

tsx
import { useGameLoop } from '@hua-labs/motion-advanced';

function Game() {
  const game = useGameLoop({
    fps: 60,           // 목표 FPS (기본값: 60)
    autoStart: false,
    maxFPS: 120,       // 최대 FPS 제한
    minFPS: 30,        // 최소 FPS 경고 임계값
  });

  // 업데이트 로직 등록
  useEffect(() => {
    const cleanup = game.onUpdate((deltaTime, elapsedTime) => {
      // 게임 로직 업데이트 (물리, AI 등)
      updatePhysics(deltaTime);
    });
    return cleanup;
  }, []);

  // 렌더링 로직 등록
  useEffect(() => {
    const cleanup = game.onRender((deltaTime, elapsedTime) => {
      // 렌더링 (canvas 등)
      renderFrame();
    });
    return cleanup;
  }, []);

  return (
    <div>
      <canvas ref={canvasRef} />
      <p>FPS: {game.fps}</p>
      <p>Frame: {game.frameCount}</p>
      <p>Elapsed: {Math.round(game.elapsedTime)}ms</p>
      <button onClick={game.start}>Start</button>
      <button onClick={game.pause}>Pause</button>
      <button onClick={game.resume}>Resume</button>
      <button onClick={game.stop}>Stop</button>
      <button onClick={game.reset}>Reset</button>
    </div>
  );
}

// Returns
// - isRunning: boolean
// - fps: number (현재 FPS)
// - deltaTime: number (프레임 간 시간 차이 ms)
// - elapsedTime: number (총 경과 시간 ms)
// - frameCount: number
// - mounted: boolean
// - start(), stop(), pause(), resume(), reset()
// - onUpdate(callback): 업데이트 콜백 등록
// - onRender(callback): 렌더링 콜백 등록

useAutoSlide
Auto Series

8방향 슬라이드 애니메이션. 반복, 이징 지원

tsx
import { useAutoSlide } from '@hua-labs/motion-advanced';

function SlideInElement() {
  const slide = useAutoSlide({
    direction: 'left',   // 'left' | 'right' | 'up' | 'down' | 'left-up' | ...
    distance: 100,       // 슬라이드 거리 (px)
    duration: 1000,      // 애니메이션 시간 (ms)
    delay: 0,            // 시작 지연
    ease: 'ease-in-out', // 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out'
    repeat: false,       // 반복 여부
    repeatCount: -1,     // -1 = 무한 반복
    repeatDelay: 1000,   // 반복 간 지연
    autoStart: true,
    onComplete: () => console.log('Done!'),
    onRepeat: (count) => console.log(`Repeat: ${count}`)
  });

  return (
    <div
      style={{
        transform: `translate(${slide.position.x}px, ${slide.position.y}px)`,
        opacity: slide.isVisible ? 1 : 0
      }}
    >
      <p>Sliding content</p>
      <button onClick={slide.slideIn}>Slide In</button>
      <button onClick={slide.slideOut}>Slide Out</button>
      <button onClick={slide.toggle}>Toggle</button>
      <button onClick={slide.reset}>Reset</button>
    </div>
  );
}

// Returns
// - position: { x: number, y: number }
// - isAnimating: boolean
// - isVisible: boolean
// - mounted: boolean
// - start(), stop(), reset()
// - slideIn(), slideOut(), toggle()

usePerformanceMonitor
Special

실시간 FPS 측정 및 성능 저하 감지

tsx
import { usePerformanceMonitor } from '@hua-labs/motion-advanced';

function MonitoredComponent() {
  const perf = usePerformanceMonitor({
    threshold: 30,  // 이 FPS 이하면 성능 저하로 판단
    onPerformanceIssue: (fps) => {
      console.warn(`Low FPS: ${fps}`);
      // 애니메이션 품질 낮추기 등 대응
    }
  });

  return (
    <div ref={perf.ref}>
      <p>FPS: {perf.fps}</p>
      <p>Frames: {perf.frameCount}</p>
      {perf.isLowPerformance && (
        <p className="text-yellow-500">Performance warning!</p>
      )}
    </div>
  );
}

// Returns
// - ref: RefCallback (모니터링할 요소에 연결)
// - fps: number
// - isLowPerformance: boolean
// - frameCount: number

API Reference

Exports

Auto 시리즈

useAutoSlide, useAutoScale, useAutoFade, useAutoPlay

오케스트레이션

useMotionOrchestra, useOrchestration, useSequence

고급 인터랙션

useLayoutMotion, useKeyboardToggle, useScrollDirection, useStickyToggle, useScrollToggle, useVisibilityToggle, useInteractive

특수 기능

usePerformanceMonitor, useLanguageAwareMotion, useGameLoop

관련 패키지