# Stickers

> Stickers for the web: die-cut from any picture, peeled, picked up and stuck down, lit by the pointer.

Source: https://cesarvenzac.com/stickers

Package: [@cesarvenzac/stickers](https://www.npmjs.com/package/@cesarvenzac/stickers) 0.2.0 on npm, MIT licence. Source code: https://github.com/cesarvenzac/stickers

```sh
npm install @cesarvenzac/stickers
```

*Live example on the page: A board of stickers. Six stickers: gloss, glitter, holographic, holographic dots, glow in the dark and paper. Peel one from an edge, or pick it up by its middle, and stick it down anywhere. Then turn the lights off.* Its source:

```tsx
// Any picture, or SVG markup in your own tokens: it's die-cut with a
// border, lit by the pointer in its finish, peeled from an edge and,
// with drag, picked up and stuck down anywhere on its parent.
import { Sticker } from "@cesarvenzac/stickers/react";

<div className="relative h-96">
  <Sticker src={heartSvg} finish="gloss" drag label="A heart" />
  <Sticker src={starSvg} finish="glitter" drag label="A star" />
  <Sticker src={boltSvg} finish="holo" drag label="A bolt" />
  <Sticker src={cloudSvg} finish="glow" drag label="A cloud" />
  <Sticker src={badgeSvg} finish="holo" pattern="dots" drag label="A badge" />
  <Sticker src="/moon.png" finish="paper" drag label="A moon" />
</div>
// Lights off: dark follows the page (a .dark class, data-theme,
// color-scheme, the system's setting), or say so.
<Sticker src={cloudSvg} finish="glow" dark={lightsOff} />
```

Stickers makes any picture a sticker: die-cut with a border round its outline, lit by the pointer in its finish, a shadow under it. Peel it from an edge and it curls up, its back showing; let go before half way and it lies back down, past half way it comes off in your hand and sticks down wherever you let go.

## Use

```tsx
import { Sticker } from "@cesarvenzac/stickers/react";

<Sticker
  src="/heart.svg"
  finish="holo"
  label="A heart"
  style={{ width: 160, height: 160 }}
/>;
```

Or without React:

```typescript
import { sticker } from "@cesarvenzac/stickers";

sticker(element, "/heart.svg", { finish: "holo", drag: true });
```

## Peel

*Live example on the page: Peel. One sticker to peel, its finish picked below. Let go before half way and it lies back down; past it, it comes off, until you stick it back. Turn the lights off for the glow.* Its source:

```tsx
// Peeled from any edge: let go before half way and it lies back
// down; past it, it comes off.
import { Sticker } from "@cesarvenzac/stickers/react";

<Sticker
  src={boltSvg}
  finish="holo"     // paper, gloss, holo, glitter, glow
  pattern="squares" // a foil's: smooth, lines, squares, dots, shards
  print="César Venzac" // on its back, as a backing's print
  onPeel={() => setOff(true)}
  handle={(sticker) => (ref.current = sticker)}
/>
// Off, until it's put back:
ref.current.restore();
```

## Holographic foils

*Live example on the page: Holographic foils. The holographic foil in its five patterns: smooth, lines, squares, dots and shards. Move over them: each patch flashes its colour as the light comes square to its grooves.* Its source:

```tsx
// Holographic foil is a diffraction grating: `pattern` lays its
// grooves, and each patch flashes its colour as the light comes square
// to them, silver when it doesn't.
import { Sticker } from "@cesarvenzac/stickers/react";

<Sticker src={starSvg} finish="holo" />                   // smooth
<Sticker src={starSvg} finish="holo" pattern="lines" />
<Sticker src={starSvg} finish="holo" pattern="squares" />
<Sticker src={starSvg} finish="holo" pattern="dots" />
<Sticker src={starSvg} finish="holo" pattern="shards" />
```

## What it does

- **Any picture.** An image, a canvas, or SVG markup painted in your page's own tokens (its `var(--…)` are read on the sticker): fitted inside, a border grown round its outline, narrow gaps closed and holes filled, as a die-cutter's kiss-cut follows a drawing.
- **A real peel.** The sheet rolls round a cylinder from wherever it's held, its back showing (in a colour of yours, with words printed on it if you like) and its shadow falling on what's still stuck. The point you hold stays under the pointer.
- **Picked up and stuck down.** It lifts toward you, its shadow growing, and follows the point you hold it by, swinging round behind it as a card dragged across a table does; let go, and it's pressed down where it is.
- **Five finishes.** Paper; gloss, a laminate's highlight; holographic foil, the spectrum running across it as the light moves; glitter, flakes catching the light one by one; and glow in the dark.
- **Holographic patterns.** The foil is a diffraction grating, its grooves laid smooth, in fine lines, small squares, dots or shards, each patch flashing its colour as the light comes square to them and silver when it doesn't.
- **Lit by the pointer.** The light is a point above it: move over a sticker and its finish answers. With the lights off, the pointer is a torch.
- **Glow in the dark.** When the page goes dark, a phosphorescent sticker gives back the light it took in, bright at first and fading as phosphor does, half in twelve seconds; the torch charges it again. Dark follows the page (a `dark` class, `data-theme`, `color-scheme`, the system's setting), or you say so.
- **For everyone.** Arrow keys move a sticker and Enter peels one off. Under reduced motion nothing swings or bounces.
- **One shader.** TypeScript with no dependencies, about 20 kB, every sticker on a page drawn by one WebGL 2 context. Flat where there's none, and drawn by the server in React until it's ready.

## Docs

- [Getting started](https://cesarvenzac.com/stickers/docs/getting-started.md): Install Stickers and make a picture a sticker: in React, or on any element.
- [Peeling and moving](https://cesarvenzac.com/stickers/docs/peeling-and-moving.md): How a sticker peels, comes off, is picked up and stuck down, and how to keep where it's been put.
- [Finishes and the light](https://cesarvenzac.com/stickers/docs/finishes.md): Paper, gloss, holographic foil in five patterns, glitter and glow in the dark: how each takes the light.
- [API reference](https://cesarvenzac.com/stickers/docs/api.md): Every function, option and type, as the package exports them.
- [Scratch cards](https://cesarvenzac.com/stickers/docs/scratch-cards.md): A coating in any finish over whatever an element holds, scratched off with a coin's ragged edge.
