Skip to content

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 page

With a bundler (Vite, webpack, esbuild, Parcel), install the package and import both halves:

Terminal window
npm install toon-principles
import 'toon-principles/toon.css';
import { tween, arc, ease } from 'toon-principles';

It works with require('toon-principles') too, and includes TypeScript types.

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:

That’s squash and stretch at the size of a button. If nothing moves, see Composing and debugging.

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.

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).