On this page

Find and extend

Spaces

New Spaces live on levni.dev/spaces.

A Levni Space is one small tool that draws with the engine in the browser, on levni.dev/spaces. Each space is a folder with two files, anyone can read it, and adding one is a pull request.

A space#

site/src/spaces/your-tool/
  space.json   title, description, author, licence, tags, and a preview scene for the gallery card
  space.js     export function mount(root, api)
{
  "title": "Name sticker",
  "description": "Your name on a round die-cut sticker around a drawing you pick from the Folio.",
  "author": "Your name",
  "license": "MIT",
  "tags": ["sticker", "name"],
  "preview": { "canvas": [800, 800], "background": "white", "elements": [ … ] }
}
export function mount(root, api) {
  root.innerHTML = '<input id="w" value="Hello"><figure class="sp-out"><img id="o" alt=""></figure>';
  const draw = async () => {
    root.querySelector('#o').src = await api.url({
      canvas: [800, 500], background: 'paper',
      elements: [{ type: 'type', text: root.querySelector('#w').value, font: 'black', x: 60, y: 180, w: 680, h: 140, fit: 'box' }],
    });
  };
  root.querySelector('#w').oninput = draw;
  draw();
}

The api#

Spaces do not import anything. The page hands every space the same api:

call gives
api.url(scene) an image URL for an <img> (vector, fast); revoke the old one when you replace it
api.png(scene, { scale, stamp }) a PNG Blob, with the scene inside unless stamp: false; scale: 4 on an 874 × 1240 page is A4 at 300 dpi
api.gif(scene, { frames, fps, width, onProgress }) a looping GIF Blob of a scene with motion
api.draw(scene) { svg, notes, missing }: the SVG, the layout critic's notes, drawings that do not exist
api.save(blob, file) downloads a Blob
api.folio() the Folio's index: [{ name, category, tags, aliases }]
api.find(words, limit) drawing names for some words, English or Turkish, best first
api.shot(id, fields), api.shots a ready-made shot's scene with your words, and the list of shots
api.inks(['#hex', …]) your colours as Levni inks for a scene's style

Fonts and drawings a scene uses are loaded for you. Scenes are ordinary Levni scenes.

The shared kit#

The space page styles these classes, so a space can look at home without CSS of its own: sp-row (a row of controls), sp-field (a label wrapping an input or select), sp-label, sp-btn (and sp-btn ghost), sp-chips with sp-chip buttons (aria-pressed="true" for the chosen one), sp-out (a framed picture; add sp-tall for portrait), sp-note (a quiet line for hints and empty results; hidden while empty), sp-big.

Rules#

node test/spaces.mjs checks every space, and CI runs it:

  • the folder name is lowercase words with hyphens, and holds only space.json and space.js;
  • space.json has a title (40 characters at most), a description (40 to 160, it is also the page's search description), an author, a licence, one to six tags, and a preview scene that draws with drawings that exist;
  • space.js is at most 30 KB, exports mount(root, api), and does not import modules, use eval or new Function, touch cookies, call the network, write script tags or navigate the page away.

A person reviews every space before it is merged. Spaces should work offline once the page has loaded, keep everything in the browser, and credit the Folio (CC BY 4.0) when people download drawings.

Add yours#

  1. Fork Levni-Dev/levni, add site/src/spaces/your-tool/.
  2. cd site && npm install && npm run dev, open /spaces/your-tool/.
  3. node site/scripts/render-spaces.mjs draws the gallery card from your preview scene.
  4. node test/spaces.mjs, then open a pull request.

Found a mistake? These pages come from the docs folder and the CLI help; fix it there and open a pull request.

Free, for real

Make one now. Keep making them for free.

Try Levni in your browser, then add it to Claude or Codex: it draws on your machine, so the $20 plan you already have is enough. No image credits, no second bill.