napkin-sketchdocs 1.0.0 GitHub

The napkin-sketch API#

On this page

API hub · Quickstart · Cheatsheet

Draw without a pointer. napkin-sketch has a language, napkin script, that says what to draw one instruction a line, and a composition API that builds a graphic in code. Both write SVG and PNG, and a drawing also PDF, the app's own .skbk and an Illustrator script, with no window, no browser and no native library, from a shell, from Node, or from any language that can start a process.

Where to start. A person: API-QUICKSTART.md, then the quickstart of the category you need. An agent: docs/api/INDEX.json, which lists every page with its kind, its first paragraph and its size, and then a cheatsheet. Every verb, flag and exit code on one page: API-CHEATSHEET.md.

What it is#

What it is not#

The categories#

CategoryWhat it coversPages
The napkin script languageThe syntax, values and expressions, the object form, every verb, and every diagnostic code.reference, quickstart, cheatsheet
Drawing with napkin scriptWhat each instruction draws: pages, layers, paint, shapes, paths, the shape library, the hand-drawn pass, text, images, links and effects.reference, quickstart, cheatsheet
The graphic design APICompositions built in code - shapes, text, media, masks, gradients, effects - rendered to SVG or PNG.reference, quickstart, cheatsheet
Writing a drawing outSVG, PNG, PDF, .skbk and an Illustrator script from one call, the box every format is cut to, and what each format keeps.reference, quickstart, cheatsheet
The napkin-sketch command linedraw, check, render and verbs from a shell or any language, with --json and exit codes.reference, quickstart, cheatsheet
Using napkin-sketch from codeThe package's entries, ES modules and CommonJS, types, the result object, and what throws.reference, quickstart, cheatsheet
Markdown Flow and Clean Language Accents@isocialpractice/napkin-sketch/markdown: marked's lexer and highlight.js for napkin-sketch, Markdown read as a text shows it, code colored by its language, and a language installed beyond the common 36.reference, quickstart, cheatsheet
The drawing enginesThe functions the app's tools stand on: regions combined and cut, the Eraser, the Wipe Stacks and the Shape Stacker, Split, clipping masks, the Pencil's grades and grain, the Smear and Liquify; blends, effects, Splatter, Warp and 3D; type, its layout, hyphenation and fonts; Text Configurations and Composition Styles.reference, quickstart, cheatsheet
Working with other programsIllustrator and Inkscape through SVG, an Illustrator script that rebuilds a drawing, files linked from elsewhere, and what survives a round trip.reference, quickstart, cheatsheet
The AI helpersExperimental. The graphic-designer and scripting helpers: design languages, brand resources, scripts drawn from a request, and how an agent reads these pages.reference, quickstart, cheatsheet

How it fits together#

 text script (.napkin) --parseScript--+
                                      +--> instructions: the object form (.napkin.json)
 a program (Node, Python, C) ---------+          |
                                              evaluate
                                                 |
                              sketch book: pages, layers, Bezier marks
                                                 |
          +---------------+-------------+--------+----------+-------------------+
     sketchToSvg    sketchesToPdf     .skbk           sketchesToJsx    sketchToComposition
          |               |             |                   |                   |
         SVG             PDF    the app opens it   Illustrator runs it     composition <-- createComposition
                                                                                |
                                                                            rasterize --> PNG

The ways in#

FromCallStart at
A shell, a batch file, CInapkin-sketch draw card.napkin --to svg,pngThe command line
Python, C, any languagenapkin-sketch draw - --json, the script on standard inputThe callers
NodedrawFile('card.napkin', { formats: ['svg', 'png'] })Using it from code
A browser or a bundlerdrawSvg(text), evaluate(text)The entries
Code that lays out a graphiccreateComposition({ width, height })The graphic design API
An AI toolthe graphic-designer and scripting helpers (experimental)The AI helpers
A sentencenapkin-sketch draw --prompt "a three-box flowchart with arrows" (experimental)Drawing from a request
Illustrator, InkscapeSVG both ways, link, and --to jsx to rebuild a drawing in IllustratorWorking with other programs

Who these pages are for#

People and agents alike. Every category has three pages: a reference for the reader with time, a quickstart that runs as written from npm or a clone, and a cheatsheet of tables, and each links to the other two and back here in its first lines. The reference pages close with a section for agents: the strings to match, the flags that make a run repeatable, and which diagnostics mean retry and which mean rewrite. An agent gets the grammar from the program rather than the prose: napkin-sketch verbs --json prints every verb, shape and diagnostic code, from the table the parser reads.

The language's version#

A script's first line names the language version it was written for: napkin 1. A version changes only when a script that ran under the old one would draw differently under the new one; a new verb or a new optional field is an addition, and keeps the version. A build refuses a script newer than it reads with version-unsupported, naming the newest it does, and reads a script with no version line as version 1, with a version-missing warning. The language's version and the package's are separate: SCRIPT_VERSION is the first, and the command line's JSON report carries both, as language and version.

How these pages are kept true#

The verb tables, the command tables, the exit codes, the schema and docs/api/INDEX.json are written by npm run api-docs from the tables the code itself reads, and the test suite fails when one is out of date. Every napkin block on these pages is run by the tests, every JSON script is checked, and every relative link is followed to a file.