paperjs/paper.js
Sobre
O canivete suíço do scripting de gráficos vetoriais — o Scriptographer portado para JavaScript e o navegador, usando HTML5 Canvas. Criado por @lehni e @puckey
Design e mídiaCrescimento medido de estrelas
- em 24 h
- 0
- em 7 dias
- +18
- em 15 dias
- +26
- em 1 mês
- +45
Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.
README.md
OriginalPaper.js - The Swiss Army Knife of Vector Graphics Scripting

If you want to work with Paper.js, simply download the latest "stable" version from http://paperjs.org/download/
- Website: http://paperjs.org/
- Questions: https://stackoverflow.com/questions/tagged/paperjs
- Discussion forum: https://groups.google.com/group/paperjs
- Mainline source code: https://github.com/paperjs/paper.js
- Twitter: @paperjs
- Latest releases: http://paperjs.org/download/
- Pre-built development versions:
prebuilt/moduleandprebuilt/distbranches.
Upgrading from Paper.js 0.17? MIGRATION.md lists the changes in 1.0 that can break existing code, and what to write instead.
Installing Paper.js
The recommended way to install and maintain Paper.js as a dependency in your project is through the Node.js Package Manager (NPM) for browsers, Node.js or Electron.
If NPM is already installed, simply type one of these commands in your project folder:
npm install paper
Upon execution, you will find a paper folder inside the project's
node_modules folder.
For more information on how to install Node.js and NPM, read the chapter Installing Node.js and NPM.
Using Paper.js with a Bundler
With a bundler such as webpack, Rollup, esbuild or Vite, import Paper.js and set it up with a canvas element:
import paper from 'paper'
paper.setup(document.getElementById('canvas'))
const { Path } = paper
const circle = Path.circle({
center: paper.view.center,
radius: 30,
fillColor: 'red'
})
paper.view.onFrame = event => {
circle.rotate(1)
}
The default export is the paper object, with all classes as its properties,
and the classes are named exports too. Use paper.view and paper.project
after calling paper.setup(), rather than importing them, as they only exist
from then on.
Package Entries
The package has these entries:
paper– The library with all its features, and thepaperobject as its default export.paper/core– The classes only, without thepaperobject and without side effects, so bundlers keep only what an app uses. Add the features it leaves out withuse():use(boolean, offset, svg)with each imported from its entry below, anduse(effects, tween, raster)for live effects, tweens andrasterize(), imported frompaper/coreitself.paper/paperscript– PaperScript, which adds the operators, and exportsPaperScriptto compile, execute and load code.PaperScript.load()runs the<script type="text/paperscript">tags of the page, which the script files do on their own. It brings Acorn.js along.paper/node– The library on Node.js, see Using Paper.js on Node.js.paper/hosted– The library for apps that keep a project's items in their own documents, and load them on demand.paper/svg– SVG import and export, assvgforuse(svg).paper/boolean– Boolean operations on plain path data, without items, and of path items asbooleanforuse(boolean).paper/offset– Offsetting and outlining of plain path data, without items, and of path items asoffsetforuse(offset).paper/smoothing– Smoothing and simplifying of plain path data.
Script Files
For <script> tags, the package also comes with three script files, in
minified and normal variants, which set the global paper:
dist/paper-full.js– The full version, including PaperScript and Acorn.js.dist/paper-slim.js– The slim version, without PaperScript and Acorn.js. You can use this to shave off some bytes and compilation time when working with JavaScript directly.dist/paper-hosted.js– The full version withpaper/hosted, for apps that keep a project's items in their own documents, seeProject#host.
Installing Node.js and NPM
Node.js comes with the Node Package Manager (NPM). There are many tutorials explaining the different ways to install Node.js on different platforms. It is generally not recommended to install Node.js through OS-supplied package managers, as the its development cycles move fast and these versions are often out-of-date.
On macOS, Homebrew is a good option if one version of
Node.js that is kept up to date with brew upgrade is enough:
https://treehouse.github.io/installation-guides/mac/node-mac.html
NVM can be used instead to install and
maintain multiple versions of Node.js on the same platform, as often required by
different projects:
https://nodesource.com/blog/installing-node-js-tutorial-using-nvm-on-mac-os-x-and-ubuntu/
For Linux, see https://nodejs.org/download/ to locate 32-bit and 64-bit Node.js binaries as well as sources, or use NVM, as described in the paragraph above.
Using Paper.js on Node.js
On Node.js, Paper.js draws through happy-dom and @napi-rs/canvas, which come with prebuilt binaries and need no native libraries. Install them next to Paper.js:
npm install paper happy-dom @napi-rs/canvas
Then import the paper/node entry, which sets up a window for Paper.js to draw
in:
import paper from 'paper/node'
paper.setup(new paper.Size(300, 200))
paper.Path.circle({ center: [150, 100], radius: 50, fillColor: 'red' })
await paper.view.exportImage('circle.png')
Views on Node.js can write their image with exportImage(path), and the frames
of their animation with exportFrames(options). Fonts for text are registered
with the exported GlobalFonts, e.g.
GlobalFonts.registerFromPath('fonts/Inter.ttf', 'Inter'). Paper.js needs
Node.js 22.22 or newer.
Running PaperScript on Node.js
PaperScript files run in a scope of their own: set one up, and execute the file's code in it:
import { readFile } from 'node:fs/promises'
import paper, { PaperScope } from 'paper/node'
import { PaperScript } from 'paper/paperscript'
const scope = new PaperScope()
scope.setup(new paper.Size(300, 200))
PaperScript.execute(await readFile('drawing.pjs', 'utf8'), scope, {
url: 'drawing.pjs'
})
await scope.view.exportImage('drawing.png')
Version 0.17 also ran .pjs files through require(), which ES modules don't
support.
Development
The main Paper.js source tree is hosted on
GitHub. git is required to create a
clone of the repository, and can be easily installed through your preferred
package manager on your platform.
Get the Source
git clone --recursive git://github.com/paperjs/paper.js.git
cd paper.js
To refresh your clone and fetch changes from origin, run:
git fetch origin
To update the jsdoc-toolkit submodule, used to generate the documentation,
run:
git submodule update --init --recursive
Setting Up For Building
Paper.js is written in TypeScript, builds with Rolldown, and has a couple of dependencies as NPM modules. Read the chapter Installing Node.js and NPM if you still need to install these.
Development uses pnpm, which needs to be installed too. See Installing pnpm for details.
In order to be able to build Paper.js, after checking out the repository, paper has dependencies that need to be installed. Install them by issuing the following commands from the Paper.js directory:
pnpm install
Building the Library
The Paper.js sources are distributed across many separate files, organised in
subfolders inside the src folder. To build them into the distributed files,
run:
pnpm build
You will then find the ES modules of the entries in dist/esm, their type
declarations in dist/types, and the script files paper-full.js and
paper-slim.js in dist, along with their minified versions.
Read more about this in Script Files.
Running Directly from the Sources
The sources are ES modules in TypeScript that Node.js runs without a build, and so do the tests, so changes can be tried without building the library.
Browsers need the script files, which the examples load from dist. To rebuild
them on every change in the sources, run:
pnpm watch
Building the Documentation
The reference is built from the doc comments in the sources, after building the library, whose script file runs the examples in it:
pnpm build:docs
You will then find the offline docs in dist/docs, and the fragments of the
website's reference in dist/serverdocs.
Other Build Tasks
Create a zipped distribution file of the script files, the examples and the
offline docs inside the dist folder, after building them:
pnpm zip
Release the version in package.json from the main branch, or from a
maintenance branch, see below, which commits, tags and pushes it for the
release workflow to build and publish:
pnpm release
Branch structure
All development is taking place in the
main branch, through pull
requests. Each release is a tag on it, such as v1.0.0. The develop branch
that earlier versions were developed in stays at the state where main took
over until version 1.0.0, and is removed then. Clones that track main from
before 1.0 reset it once: git fetch && git reset --hard origin/main.
Fixes for earlier versions go to maintenance branches such as release/0.17,
started from the tag of the version that they fix, where pnpm release
releases them too. npm only makes a release latest if it is newer than the
current one, and publishes older ones under legacy.
The dist folder is excluded on all branches, and the release workflow on
GitHub Actions builds the library from the tag of each release.
We also offer prebuilt versions of the latest state of the main branch on
prebuilt/module
and prebuilt/dist.
Testing
The tests run with Vitest, on Node.js and in Chromium through Playwright, on the sources:
pnpm test
To run them only on Node.js, or only in the browser:
pnpm test:node
pnpm test:browser
The browser tests need Chromium for Playwright, which this installs once:
pnpm exec playwright install chromium
Vitest also runs single files, and watches for changes with
pnpm exec vitest.
The screenshot tests in test/screenshots compare what the library draws with
reference images. Rendering differs between systems, so they run in Playwright's
Docker image, which needs Docker:
pnpm test:screenshots
To write new reference images, after adding a test or changing what it draws,
and review them in test/screenshots/__screenshots__ before committing:
pnpm test:screenshots --update
Contributing 
The main Paper.js source tree is hosted on GitHub, thus you should create a fork of the repository in which you perform development. See https://help.github.com/articles/fork-a-repo/.
We prefer that you send a pull request on GitHub which will then be merged into the official main line repository.
Also, in your first contribution, add yourself to the end of AUTHORS.md (which
of course is optional).
In addition to contributing code you can also triage issues which may include reproducing bug reports or asking for vital information, such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to subscribe to paper.js on CodeTriage.
Get the source (for contributing):
If you want to contribute to the project you will have to make a fork. Then do this:
git clone --recursive [email protected]:yourusername/paper.js.git
cd paper.js
git remote add upstream [email protected]:paperjs/paper.js.git
To then fetch changes from upstream, run
git fetch upstream
Creating and Submitting a Patch
As mentioned above, we prefer that you send a pull request on GitHub:
Create a fork of the upstream repository by visiting https://github.com/paperjs/paper.js/fork. If you feel insecure, here's a great guide: https://help.github.com/articles/fork-a-repo/
Clone of your repository:
git clone https://[email protected]/yourusername/paper.js.gitThis is important: Create a so-called topic branch based on the
mainbranch:git checkout -tb name-of-my-patch mainwherename-of-my-patchis a short but descriptive name of the patch you're about to create. Don't worry about the perfect name though -- you can change this name at any time later on.Hack! Make your changes, additions, etc., and describe them for the changelog in a file of their own in
changelog/unreleased, see its README. Commit them then push them to your GitHub fork:git push origin name-of-my-patchSend a pull request to the upstream repository's owner by visiting your repository's site at GitHub (i.e. https://github.com/yourusername/paper.js) and press the "Pull Request" button, for a pull request to the
mainbranch. Here's a good guide on pull requests: https://help.github.com/articles/about-pull-requests/
Use one topic branch per feature:
Don't mix different kinds of patches in the same branch. Instead, merge them all
together into your main branch (or develop everything in your main
branch and then cherry-pick-and-merge into the different topic branches). Git
provides for an extremely flexible workflow, which in many ways causes more
confusion than it helps you when new to collaborative software development. The
guides provided by GitHub at https://help.github.com/ are a really good
starting point and reference. If you are fixing an issue, a convenient way to
name the branch is to use the issue number as a prefix, like this: git checkout -tb issue-937-feature-add-text-styling.
For a list of authors and contributors, please see AUTHORS.
License
Distributed under the MIT license. See LICENSE for details.
Explore projetos relacionados
Carregando…