Install from GitHub, then import what you need. Scene attaches to buttons, Stage draws into your own canvas.
shell
npm i @devandreotti/crumple
JavaScript
import { Scene, config } from '@devandreotti/crumple';
// serve the package's assets/ folder and point config.assets at it
config.assets = '/assets/';
Scene.init({ motion: 'auto' });
Crumple.config.assets = 'assets/';
Crumple.Scene.init({ motion: 'auto' });
// any button becomes a paper: click to open, drag to crumple
// 'note' is any
Stage (inline canvas)
A paper rendered in place in your own canvas, with no flight.
Name
Description
Stage(canvas, opts)
Crumple.Stage(canvas, { fit, flashlight, drag, motion }). fit is the share of the canvas height the open sheet takes (default 0.8). motion is 'auto', 'reduce' or 'full'. Returns null without WebGL2.
set(config, { progress })
Builds a paper from a config and shows it. Resolves with the paper (or null if a newer call replaced it).
crumple · uncrumple · toggle
crumple(), uncrumple(), toggle(), flip() (at any moment), tear(), restoreStub(), restore().
burn()
Burns the paper from its burn form, on any paper. Returns a Promise that resolves once the burn has started.
destroy()
Frees the paper, listeners and the WebGL context. Every method is a no-op afterwards.
setProgress(v)
setProgress(0..1): 0 is closed, 1 is fully open.
png() · snapshot()
png() returns a data URL of the current frame. snapshot(opened, format, size) returns a still image.
Sound
Paper noises, synthesized with Web Audio. Off by default.
Name
Description
Sound.set(bool)
Turns sounds on or off. Stored in localStorage.
Sound.enabled
Current state (read-only).
Sound.useSamples(urls)
Optional recordings, used instead of the synthesized sounds when they load.
Sound.play(name)
Plays one of: crumple, uncrumple, flip, tear, seal, fire, grain.
Events
CustomEvents dispatched from the trigger button. Each carries detail.id.
Name
Description
crumple:open
Opened. detail: { id, openings, fallback }.
crumple:close
Closed. detail: { id }.
crumple:flip
Flipped. detail: { id, back }.
crumple:tear
Stub torn. detail: { id }.
crumple:burn
Burned after reading. detail: { id }.
Text markup
Plain text with three small extras.
Name
Description
# title
A line that starts with "# " is a heading.
~~word~~{fix}
A struck-out word with a handwritten correction.
[[text]]
A redaction bar that fades a little more on every opening.
Modules and renderer
ES modules and CommonJS. Importing the package in Node or on a server is safe: nothing touches window until you call it.
Name
Description
import · require
import { Scene, Stage, config } from '@devandreotti/crumple', or const { Stage } = require('@devandreotti/crumple').
Renderer(canvas)
A lower-level renderer on your own canvas (build, snapshot, release). destroy() frees its GL resources; release the papers first.
Crumple.config
Name
Description
assets
Base URL of the assets folder (textures and demo photos).
storagePrefix
Prefix for localStorage keys (sound, opening counts, burnt papers).
googleFonts
Load the paper fonts from Google Fonts on demand (set false if the page already ships them).