Skip to content

Howl-Kim/react-skia

Repository files navigation

React Skia

TypeScript License: MIT Development

High-performance 2D graphics for the web using React and Skia

React Skia Logo

React Skia brings the power of Skia Graphics Library to React applications running in browsers. Built on top of Google's CanvasKit-WASM, it provides a React-friendly API for creating complex 2D graphics with hardware acceleration.

โš ๏ธ Development Status: This project is currently in active development and not yet published to npm. Please clone and build from source.

โœจ Features

  • ๐Ÿš€ Hardware Accelerated - GPU-powered rendering via CanvasKit-WASM
  • ๐ŸŽจ Basic Graphics API - Rectangle, Circle, Path, Text rendering
  • ๐Ÿ’ช TypeScript First - Full type safety and IntelliSense support
  • ๐ŸŒ Web Optimized - Built for modern browsers with WebAssembly
  • ๐ŸŽฎ React Integration - Familiar component-based API

๐Ÿš€ Getting Started

Development Setup

Clone and run the project locally:

# Clone the repository
git clone https://github.com/your-username/react-skia.git
cd react-skia

# Install dependencies
pnpm install

# Start the development playground
pnpm dev

Visit http://localhost:5173 to explore the interactive playground with live demos.

Using the Library (Development)

Once you've cloned and built the project, you can use it in your applications:

import { Canvas, Circle, LinearGradient, Rect, Text } from "react-skia";

function App() {
  return (
    <Canvas width={400} height={300}>
      {/* Basic shapes */}
      <Rect x={10} y={10} width={100} height={80} color="#FF6B6B" />
      <Circle cx={200} cy={50} r={30} color="#4ECDC4" />

      {/* Text rendering */}
      <Text x={10} y={150} text="Hello Skia Web!" fontSize={20} color="#333" />

      {/* Gradient effects */}
      <Rect x={250} y={80} width={120} height={60}>
        <LinearGradient
          start={{ x: 0, y: 0 }}
          end={{ x: 120, y: 0 }}
          colors={["#667eea", "#764ba2"]}
        />
      </Rect>
    </Canvas>
  );
}

๐Ÿ“š Documentation

Explore our documentation and examples:

๐ŸŽฎ Interactive Examples

The playground includes these demos:

  • ๐Ÿ”ธ Basic Shapes - Rectangles, circles, and stroke styles
  • ๐Ÿ“ Text Rendering - Basic text with font size and color controls
  • ๐ŸŽจ Path Drawing - SVG-compatible path rendering
  • ๐ŸŒˆ Gradient Effects - Linear and radial gradients
  • ๐Ÿ‘ฅ Groups & Opacity - Layering and transparency controls
  • ๐Ÿ–ผ๏ธ Image Rendering - Basic image loading and display
  • ๐Ÿž๏ธ Complex Scenes - Simple graphics compositions
  • ๐Ÿš€ Performance Tests - Static rendering test with 100 shapes

๐Ÿ› ๏ธ Development

Project Structure

react-skia/
โ”œโ”€โ”€ packages/
โ”‚   โ””โ”€โ”€ react-skia/          # Core library
โ”‚       โ”œโ”€โ”€ src/
โ”‚       โ”‚   โ”œโ”€โ”€ components/  # React components (Canvas, Rect, etc.)
โ”‚       โ”‚   โ”œโ”€โ”€ renderer/    # Skia rendering engine
โ”‚       โ”‚   โ”œโ”€โ”€ hooks/       # React hooks
โ”‚       โ”‚   โ””โ”€โ”€ types.ts     # TypeScript definitions
โ”‚       โ””โ”€โ”€ package.json
โ””โ”€โ”€ apps/
    โ””โ”€โ”€ playground/          # Interactive demo application
        โ””โ”€โ”€ src/
            โ””โ”€โ”€ components/
                โ””โ”€โ”€ demos/   # Example implementations

Building from Source

# Install dependencies
pnpm install

# Build the library
pnpm build

# Run development server
pnpm dev

# Type checking
pnpm check-types

# Linting
pnpm lint

Package Scripts

  • pnpm dev - Start development server with hot reload
  • pnpm build - Build production bundle
  • pnpm lint - Run ESLint
  • pnpm check-types - TypeScript type checking
  • pnpm format - Format code with Prettier

๐ŸŽจ API Reference

Core Components

Canvas

The root container for all Skia graphics:

<Canvas width={400} height={300}>
  {/* Your graphics components */}
</Canvas>

Basic Shapes

// Rectangle
<Rect x={10} y={10} width={100} height={50} color="#FF6B6B" />

// Circle
<Circle cx={100} cy={100} r={50} color="#4ECDC4" />

// Text
<Text x={10} y={100} text="Hello World" fontSize={20} color="#333" />

Advanced Graphics

// SVG Paths
<Path
  path="M 10 80 Q 95 10 180 80"
  color="#F39C12"
  strokeWidth={4}
  style="stroke"
/>

// Groups with opacity
<Group opacity={0.8}>
  <Rect x={0} y={0} width={100} height={100} color="#E67E22" />
</Group>

// Gradients
<Rect x={10} y={10} width={200} height={100}>
  <LinearGradient
    start={{ x: 0, y: 0 }}
    end={{ x: 200, y: 0 }}
    colors={["#667eea", "#764ba2"]}
  />
</Rect>

๐Ÿš€ Performance

React Skia is built for performance:

  • Hardware Acceleration: Leverages GPU through CanvasKit-WASM
  • Efficient Rendering: Direct canvas manipulation with minimal React overhead
  • Memory Management: Automatic cleanup of Skia objects
  • Optimized for Modern Browsers: Built on proven CanvasKit-WASM technology

Performance Characteristics

React Skia provides:

  • ๐ŸŽฏ GPU Acceleration - Hardware-accelerated rendering via WebGL
  • ๐Ÿ”„ Efficient Updates - Smart component diffing and batching
  • ๐Ÿ“ฆ Tree Shakeable - Import only what you need
  • ๐Ÿงน Memory Safe - Automatic resource cleanup

Note: Comprehensive performance benchmarks are planned for future releases. Current implementation includes a basic stress test with 100+ static shapes in the playground.

๐Ÿค Contributing

We welcome contributions! This project is in active development.

Development Setup

  1. Fork the repository
  2. Clone your fork: git clone https://github.com/your-username/react-skia.git
  3. Install dependencies: pnpm install
  4. Create a feature branch: git checkout -b feature/amazing-feature
  5. Make your changes and add tests
  6. Build the project: pnpm build
  7. Test your changes: pnpm dev (run playground)
  8. Commit your changes: git commit -m 'feat: add amazing feature'
  9. Push to your fork: git push origin feature/amazing-feature
  10. Open a Pull Request

Code Style

This project follows strict coding standards:

  • ESLint: Google Style Guide compliance
  • Prettier: Consistent code formatting
  • TypeScript: Strict type checking
  • Conventional Commits: Standardized commit messages

๐Ÿ“‹ Roadmap

Current Status โœ…

  • โœ… Basic shapes (Rect, Circle, Path)
  • โœ… Basic text rendering
  • โœ… SVG-compatible path drawing
  • โœ… Linear and radial gradients
  • โœ… Groups and opacity control
  • โœ… Basic image rendering with fit modes
  • โœ… Blur and color matrix filters
  • โœ… TypeScript support
  • โœ… React 19 compatibility

In Progress ๐Ÿšง

  • ๐Ÿšง Animation system (useSharedValue)
  • ๐Ÿšง Touch/mouse event handling
  • ๐Ÿšง Clipping and masking
  • ๐Ÿšง Gesture recognition
  • ๐Ÿšง Advanced transforms

Planned ๐Ÿ“‹

  • ๐Ÿ“‹ NPM package publication
  • ๐Ÿ“‹ Animation system (useSharedValue)
  • ๐Ÿ“‹ Touch/mouse event handling
  • ๐Ÿ“‹ Advanced font and text features
  • ๐Ÿ“‹ Performance optimizations
  • ๐Ÿ“‹ Clipping and masking
  • ๐Ÿ“‹ Advanced transforms
  • ๐Ÿ“‹ Performance profiling tools

๐Ÿ“Š Browser Support

React Skia requires WebAssembly support and works on these modern browsers:

  • โœ… Chrome 57+ (March 2017)
  • โœ… Firefox 52+ (March 2017)
  • โœ… Safari 11+ (September 2017)
  • โœ… Edge 16+ (October 2017)

Note: WebAssembly is required for CanvasKit-WASM functionality. Older browsers without WebAssembly support are not compatible.

๐Ÿ™ Acknowledgments


๐Ÿš€ Get Started โ€ข ๐Ÿ“š Documentation โ€ข ๐ŸŽฎ Examples โ€ข ๐Ÿค Contributing

Made with โค๏ธ by kim-jaedeok

About

High-performance 2D graphics for the web using React and Skia

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •