napkin-sketchdocs 1.0.0 GitHub

The drawing engines: cheatsheet#

On this page

API hub · Reference · Quickstart · Cheatsheet

Reminders for the engines: what each call takes, what it gives back, and where it stops.

Regions#

CallGives
booleanOp(a, b, op, { ruleA, ruleB })The contours of union, difference or intersection, or null
booleanRegions(a, b, op, options)The same, with junctions: the corners a cut made
A regionClosed contours of { x, y }, page pixels, filled non-zero unless evenodd

Erasing#

CallGives
eraseRegionOf(eraser)An eraser mark's swath as a region, round at the ends
eraseMarks(page, ids, region){ changed, removed, skipped, raster }
eraseKind(mark)area (a shape, a Copic or a profiled stroke), line or skip

Wipes and stacks#

CallGives
wipeMarks(page, ids, op)An edit: changed, removed, added, skipped, problem, empty
WIPE_OPSin, out-front, out-back, mid, outer, clean
wipeOperand(mark)What a wipe takes a mark as - its inside or its ink - or null
arrangeFaces(regions){ faces: [{ contours, covers }], junctions, problem }
stackFaces(page, ids, points, mode)A wipe's edit for merge or remove, with missed
stackArrangement, faceAt, facesAlong, facesInBox, stackEditThe Shape Stacker's steps, one at a time

Splitting#

CallGives
nearestOnMark(mark, point, { anchorReach }){ subpath, segment, t, point, distance }, or null
splitMark(mark, at){ first, second }: second null when a closed path opened
splitTarget(marks, point, reach)The topmost mark a point reaches, and where, or null
isSplittable(mark)Whether a mark has a path to cut

Clipping masks#

CallGives
makeClip(page, ids){ clip, layers }, or { problem }: too-few or open
releaseClip(page, layerId)The clip group to take the clip off, or null
canClip(mark)Whether a mark is a closed path that can clip
clipIndex(page){ marks, any, byGroup, of(layer) }, worked out once
clippedAt(page, mark, point, index)Whether the mark is clipped away there
clipMarkOf, clipRegionOf(page, group)A group's clip mark, and its inside
shownBounds(page, mark, bounds, index)The box cut to its clips, or null
normalizeClips(page)Takes off clips that name no closed mark inside

Pencils and the Smear#

CallGives
PENCIL_GRADES, PENCIL_KITThe 30 grades; the kit as the panel shows it
pencilPaint(choice)The grade a choice or a name gives, graphite HB for none
parsePencil(name){ medium, grade }, or null
pencilCoverage(grade, tooth, pressure)What one pass lays down on that tooth
grainTile(seed), GRAIN_TILE_SIZEThe paper's tooth, 128 by 128 heights, seamless
pencilRegion(mark, scale)The box a mark's picture covers
rasterizePencil(mark, region), pencilPictureIts pixels, straight RGBA; with its smears
smudgeBuffer(data, region, pass, rgb, from)One stump pass over a picture, in place; where it got to
smudgeFor(mark, drag, width, strength)The pass a drag leaves on a mark, or null

Liquify#

CallGives
liquifyField(dab){ point(p), rotation(p) } for one dab
A dab{ mode, x, y, radius, amount, dx, dy }: warp, twirl, pucker or bloat
liquifyMarks(marks, dabs, { tolerance, refit })The marks bent, by id
refitLiquified(mark, tolerance, before)A bent mark fitted again, its meant lines kept
liquifiable(mark), liquifyReaches(mark, dab)Whether it bends; whether a dab reaches it
liquifyFalloff(distance, radius)1 at the centre to 0 at the rim

Blends, effects, Splatter, Warp and 3D#

CallGives
BLEND_MODES, blendModeOf(name)The sixteen modes; the id any of a mode's names gives, or undefined
blendPixel(mode, backdrop, source)Two straight RGBA pixels, channels 0 to 1, mixed
defaultEffect(type)An effect with a vector editor's defaults
addEffect(effects, effect, target), removeEffect, moveEffect, toggleEffectA new list, the one given unchanged
appearanceSections(effects){ stroke, fill, object }: the Appearance panel's sections
effectsAfterTransform(effects, transform)The list scaled, turned or mirrored with its mark
fromRgba8, runEffects(img, effects, matrix, warn), toRgba8Effects drawn over a picture in place; what is laid under it apart
splatterPaths(region, options)A region's fill as a hatch, paths of cubic anchors; SPLATTER_PRESETS by name
warpStyleMap(style, box, options)One of WARP_STYLES over a box: point(p) and jacobian(p)
extrudeMesh(outline, depth, caps), revolveMesh(outline, shape, tolerance)A solid: faces, each a cap or a side, and closed
render3d(mark, effect)A 3D effect's shaded faces, far ones first

Type, paths and styles#

CallGives
lengthTable(anchors, closed)A path's lengths, total among them
pointAtLength, tangentAtLength, normalAtLength(table, s)The point, direction and normal that far along
curvatureAtLength(table, s), nearestLength(table, p)The bend there; { length, point, distance } nearest a point
layoutType(mark, measure){ lines, glyphs, overset }, set in the built-in face with no measure
hyphenate(word)The word's parts, broken where the en-US patterns allow
openSfnt(bytes), glyphOutline(face, glyphId)A font file read, or { problem }; a glyph's contours
fileOutlineSource(files, measure)Font files by family as a measure and the faces to draw from
outlineText(mark, layout, source){ marks }: a text as its glyphs' outlines, a mark each
newTextConfig(list, attrs, id, name)A Text Configuration
applyTextConfig(mark, range, config), resolveRunAttrs(base, config, overrides)A stretch put on one; what a run draws as
applyCompositionStyle(page, style){ sketch, report }: the page restyled by its layers' names, and what did not match
captureCompositionStyle(page, name), validateCompositionStyle(raw)A page's named layers as a style; { ok, style, errors, notes }

Limits#

LimitValue
BOOLEAN_EDGE_LIMIT40,000 edges, past which booleanOp gives null
WIPE_OPERAND_LIMIT32 marks a wipe or a stack takes
WIPE_FACE_LIMIT512 faces an arrangement holds
SPLIT_REACH_PX4 px: how near a script's split must land
Pucker and Bloatamount held to 0 to 1

One line each#

WantWrite
Two shapes as onewipeMarks(page, [a.id, b.id], 'in')
The top shape cut out of the bottomwipeMarks(page, ids, 'out-front')
A gap through the marks under a lineeraseMarks(page, ids, eraseRegionOf(eraser))
A path cut where a point landssplitMark(mark, nearestOnMark(mark, point))
Is it clipped hereclippedAt(page, mark, point, clipIndex(page))
A pencil's tonepencilPaint('2B').tone
A dent pushed into the marksliquifyMarks(marks, [{ mode: 'warp', x, y, radius, dx, dy }], { refit: 0.5 })
A glow on a markaddEffect(mark.effects ?? [], defaultEffect('outer-glow'))
A word brokenhyphenate('composition').join('-')
A page in another styleapplyCompositionStyle(page, style).sketch
An edit madechanged in place, removed gone, added on above (the helper)