Cette page est affichée en anglais. Une traduction française est en cours.
SkillsMay 3, 2026·3 min de lecture

Paper.js — The Swiss Army Knife of Vector Graphics Scripting

An open-source vector graphics scripting framework that runs on top of the HTML5 Canvas, offering a clean scene graph, powerful path manipulation, and PaperScript for concise creative coding.

Prêt pour agents

Cet actif peut être lu et installé directement par les agents

TokRepo expose une commande CLI universelle, un contrat d'installation, le metadata JSON, un plan selon l'adaptateur et le contenu raw pour aider les agents à juger l'adaptation, le risque et les prochaines actions.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Paper.js Overview
Commande CLI universelle
npx tokrepo install 6f0983fb-472e-11f1-9bc6-00163e2b0d79

Introduction

Paper.js is a vector graphics scripting framework built on the HTML5 Canvas. It provides a comprehensive, well-designed API for creating and manipulating vector graphics, with particular strength in path operations like boolean combinations, simplification, and smoothing.

What Paper.js Does

  • Creates and manipulates vector paths, shapes, compound paths, and raster images
  • Performs boolean operations (unite, intersect, subtract, exclude) on paths
  • Simplifies and smooths complex paths algorithmically
  • Handles mouse and keyboard events with hit-testing against the scene graph
  • Exports to SVG and imports SVG content as editable Paper.js items

Architecture Overview

Paper.js implements a full scene graph with a Project containing Layers, Groups, and Items. Each Item carries transformation matrices, styles, and child relationships. The rendering pipeline traverses the scene graph each frame, applying transformations hierarchically. A dedicated path geometry engine handles cubic bezier math, curve-fitting, and boolean clipping operations using a Greiner-Hormann variant.

Self-Hosting & Configuration

  • Install via npm or include the paper-full.js script from CDN
  • Initialize with paper.setup(canvas) to bind to an HTML5 canvas element
  • Use PaperScript (optional) for operator overloading on points and sizes
  • Configure view settings for frame rate, auto-update, and pixel ratio
  • Runs in Node.js with node-canvas for headless SVG or raster export

Key Features

  • Path boolean operations for constructive geometry (union, difference, intersection)
  • Curve and path simplification reduces point counts while preserving shape
  • Symbols and symbol instances for efficient repeated pattern rendering
  • Raster items with pixel manipulation for image processing within the scene graph
  • Comprehensive event model with onFrame, onMouseDown, onMouseDrag handlers

Comparison with Similar Tools

  • Fabric.js — focused on interactive object manipulation; less path math and booleans
  • Rough.js — sketch aesthetic only; no path operations or scene graph
  • Snap.svg — SVG manipulation library; Paper.js renders to Canvas with SVG import/export
  • Two.js — minimal 2D API across renderers; Paper.js has richer geometry tools
  • p5.js — creative coding focused on immediate mode; Paper.js offers retained scene graph

FAQ

Q: Can Paper.js export to SVG? A: Yes. Call project.exportSVG() to get a full SVG representation of the current scene.

Q: Does it work with React? A: Yes. Instantiate Paper.js on a canvas ref in useEffect and manage scope lifecycle manually.

Q: What is PaperScript? A: A thin scripting extension that enables operator overloading (e.g., point1 + point2) for cleaner math syntax. Plain JavaScript works without it.

Q: How does performance scale? A: Paper.js handles thousands of path items efficiently. For tens of thousands of simple shapes, consider switching to a WebGL renderer.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires