Skip to content

Getting started

Install Stickers and make a picture a sticker: in React, or on any element.

@cesarvenzac/stickersv0.2.0
npm install @cesarvenzac/stickers

Plain TypeScript, published as ES modules with their types, and no dependencies. React is an optional peer, for the React entry alone. It draws with WebGL 2, which every current browser has; where there's none, a sticker is drawn flat, its border and shadow included.

A first sticker

sticker makes an element a sticker of a picture. The element is the sticker's box: give it a size, and the picture is fitted inside, a border grown round it.

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

const heart = sticker(document.querySelector(".heart")!, "/heart.svg", {
  finish: "holo",
  label: "A heart",
});

It peels from an edge unless peel is false, and with drag it can be picked up and stuck down elsewhere: Peeling and moving. Its finish is how it takes the light: Finishes.

In React

Sticker is a <div> that's a sticker of src. Its other props go on the <div>:

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

<Sticker
  src="/heart.svg"
  finish="holo"
  drag
  label="A heart"
  className="size-40"
/>;

A server draws the picture itself, with a border made of drop shadows, and the sticker takes over as soon as it's drawn: nothing moves as the page hydrates. It's a client component, React 18 or later.

Pictures

src is any of these:

  • An image's address. Its pixels are read to cut round it, so one from another site needs CORS.
  • SVG markup, <svg …>. Its var(--…) and currentColor are read on the sticker's element, so a sticker can be painted in your page's tokens and follow them.
  • Anything a canvas draws: an image, a canvas, an ImageBitmap, a video's frame (in the browser alone, in React).

The picture's own alpha is its outline: what's half opaque or more is the art, and the border (outline, a sixteenth of the box's shorter side unless said) is grown round it. Gaps narrower than smooth are closed and holes are filled, as a kiss-cut follows one smooth contour; outline: 0 cuts close to the art.

<Sticker src={logo} outline={10} smooth={24} border="#fff7e8" />