This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
npm installnpm run dev- Start development with watch modenpm run build- Build the library (CommonJS, ESM, and TypeScript definitions)npm run lint- Run ESLint on .ts and .tsx filesnpm run type-check- Run TypeScript type checking without emitting files
This project uses Vitest and Testing Library with a jsdom environment.
npm run test- Run the full test suite oncenpm run test:watch- Run tests in watch mode during development
Before publishing, the following commands are automatically run:
npm run lintnpm run type-checknpm run build
This is a React component library that wraps Unicorn Studio's WebGL animation system with support for both standard React and Next.js frameworks. The codebase follows a clean, modular structure:
src/
├── shared/ # Shared code between React and Next.js versions
│ ├── types.ts # TypeScript type definitions
│ ├── constants.ts # Configuration constants
│ ├── utils.ts # Utility functions (WebGL detection, validation)
│ ├── styles.ts # Inline style definitions
│ └── hooks.ts # useUnicornScene hook (framework-agnostic)
├── react/ # React version (Vite-compatible)
│ ├── index.tsx # React component using standard script/img elements
│ └── hooks.ts # useUnicornStudioScript hook for React
├── next/ # Next.js version
│ ├── index.tsx # Next.js component using Script/Image components
│ └── hooks.ts # useUnicornStudioScript hook for Next.js
└── index.tsx # Main entry point (exports React version by default)
- UnicornScene (React): Uses standard HTML
<script>and<img>elements for broad compatibility - UnicornScene (Next.js): Uses Next.js
ScriptandImagecomponents for optimization - Shared Hooks:
useUnicornScene: Handles scene initialization, cleanup, and WebGL detection (framework-agnostic)
- Framework-Specific Hooks:
useUnicornStudioScript(React): Manages script loading with vanilla DOM APIsuseUnicornStudioScript(Next.js): Works with Next.js Script component
- Dual Framework Support: Separate optimized implementations for React and Next.js
- Shared Core Logic: Common functionality extracted to shared modules
- Framework-Specific Optimizations: Next.js version uses Script/Image components, React version uses standard elements
- Subpath Exports: Enables
unicornstudio-react(React) andunicornstudio-react/next(Next.js) imports - TypeScript First: Full type definitions with global augmentation for window.UnicornStudio
- Optional Next.js Dependency: Next.js is an optional peer dependency
- tsup: Handles bundling with dual entry points
- Entry Points:
src/index.tsx→dist/index.*(React version)src/next/index.tsx→dist/next.*(Next.js version)
- Outputs: Both CJS and ESM formats with TypeScript definitions
- Externals: react, react-dom (required), next (optional)
- This package depends on Unicorn Studio's proprietary script loaded from their CDN
- The package version follows Unicorn Studio's script version (e.g., 1.4.26)
- React and React-DOM are required peer dependencies
- Next.js is an optional peer dependency (only needed for
/nextimport) - The npm package name and repo name are both
unicornstudio-react(https://github.com/diegopeixoto/unicornstudio-react)
- ESLint + Prettier configured — formatting is enforced automatically via hooks
@typescript-eslint/no-explicit-anyis set towarn— avoidanybut it won't block buildsreact-in-jsx-scopeis off — no need to import React in JSX filesreact/prop-typesis off — use TypeScript interfaces instead
- CDN version coupling: The package version must match Unicorn Studio's CDN script version. When bumping, update both the
versionin package.json and the script URL constant insrc/shared/constants.ts. - Dual entry points: Changes to shared code in
src/shared/affect both React and Next.js builds — always verify both entry points after modifications. - Next.js imports:
next/scriptandnext/imageare externalized in tsup config. Never import Next.js modules from the React entry point (src/react/orsrc/index.tsx).