Install toon
Three ways to add toon to a project. Pick the one that matches how you build: all three give you the same two files, toon.css and toon.js.
Edit this pageWith a bundler (Vite, webpack, esbuild, Parcel), install the package and import both halves:
npm install toon-principlesimport 'toon-principles/toon.css';import { tween, arc, ease } from 'toon-principles';It works with require('toon-principles') too, and includes TypeScript types.
With no bundler and no install, load both files from a CDN. @1 keeps you on the newest 1.x release:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/toon-principles@1/src/toon.css"><script src="https://cdn.jsdelivr.net/npm/toon-principles@1/src/toon.js"></script>The script sets window.Toon.
Download the two files, put them next to your page and include them. This works straight from a file on your disk, with no server.
<link rel="stylesheet" href="toon.css"><script src="toon.js"></script>The same files are in src/ on GitHub.
Check that it works
Section titled “Check that it works”Add one class to any button, then press and hold it. If it squashes and springs back a little past its size when you let go, toon is loaded:
Press and hold the button, then let go.
<link rel="stylesheet" href="toon.css"><button class="toon-press">Press me</button>That’s squash and stretch at the size of a button. If nothing moves, see Composing and debugging.
Using a framework
Section titled “Using a framework”toon is classes and plain functions, so it works in any framework. Put its classes in your markup, and start canvas work after the element mounts. Using toon with frameworks covers React, Vue and server rendering.
What you get
Section titled “What you get”Every way of installing gives you the same files. Only the first two are required.
| File | What it is | Size |
|---|---|---|
toon.css |
The CSS presets: add a class, get motion | 12 kB |
toon.js |
The Canvas API (window.Toon, require and import) |
22 kB |
toon.mjs |
An ES module entry for import without a bundler |
1 kB |
toon.d.ts |
TypeScript types for the Canvas API | 11 kB |
toon.debug.js |
Checks while you develop, with clear error messages | 6 kB |
Sizes are before compression; gzip brings toon.css and toon.js to about 13 kB together.
toon.mjs loads toon.js from the same folder, so keep the two together. Browsers only load modules over HTTP, so serve the folder with a local server:
import { tween, arc, ease } from './toon.mjs';toon.debug.js checks every call’s arguments and explains mistakes. Load it after toon.js, or import it before toon.mjs (see Errors and debugging).