Types
All types are exported from nitro-ui-sketch. Positions and sizes are content points; colours are 0xRRGGBBAA numbers.
Tool
The active canvas tool. Widths are in content points.
type Tool =
| { type: 'ink'; ink: InkType; color: number; width: number }
| { type: 'eraser'; mode: EraserMode; width: number }
| { type: 'lasso' }
| Variant | Field | Description |
|---|---|---|
ink | ink | Ink family. |
ink | color | Colour as 0xRRGGBBAA. |
ink | width | Nominal width in content points. |
eraser | mode | Whole strokes or parts of strokes. |
eraser | width | Eraser diameter in content points. |
lasso | Selects strokes by drawing a loop around them; drag to move them. |
Ink
The look of a stroke.
| Field | Type | Description |
|---|---|---|
type | InkType | Ink family. |
color | number | Colour as 0xRRGGBBAA. |
width | number | Nominal width in content points; above zero. |
InkType
type InkType = 'pen' | 'marker' | 'pencil' | 'monoline' | 'fountainPen' | 'watercolor' | 'crayon'
See Inks for how each one draws.
EraserMode
type EraserMode = 'stroke' | 'pixel'
stroke removes every stroke it touches; pixel cuts away only the touched parts.
DrawingPolicy
type DrawingPolicy = 'anyInput' | 'stylusOnly'
Which touches draw. With stylusOnly, a single finger pans instead. Default anyInput.
StrokePoint
One sample of a stroke, in content space.
| Field | Type | Description |
|---|---|---|
x | number | Horizontal position in content points. |
y | number | Vertical position in content points. |
timeOffset | number | Seconds since the stroke began. |
size | number | Rendered diameter at this point, in content points. |
force | number | Normalised pressure from 0 to 1; 1 when the device reports none. |
azimuth | number | Stylus azimuth in radians, 0 along +x, clockwise positive. |
altitude | number | Stylus altitude in radians; Math.PI / 2 is perpendicular to the screen. |
Rect
An axis-aligned rectangle in content points.
| Field | Type | Description |
|---|---|---|
x | number | Left edge. |
y | number | Top edge. |
width | number | Width; zero for an empty rect. |
height | number | Height; zero for an empty rect. |
Size
| Field | Type | Description |
|---|---|---|
width | number | Width in points. |
height | number | Height in points. |
Viewport
The visible part of the content.
| Field | Type | Description |
|---|---|---|
zoom | number | Scale factor; 1 shows one content point per view point. |
x | number | Content x coordinate shown at the view's left edge. |
y | number | Content y coordinate shown at the view's top edge. |
ImageExportOptions
Options for Drawing.toImage.
| Field | Type | Description |
|---|---|---|
format | ImageFormat | Encoding of the returned bytes. |
quality | number | JPEG quality from 0 to 100; ignored for PNG. |
scale | number | Pixels per content point; above zero. At most 8192 pixels per side. |
rect | Rect, optional | Content area to export. Defaults to the bounds of all strokes. |
backgroundColor | number, optional | 0xRRGGBBAA. Defaults to transparent for PNG and white for JPEG. |
ImageFormat
type ImageFormat = 'png' | 'jpeg'
VectorExportOptions
Options for Drawing.toSvg and Drawing.toPdf.
| Field | Type | Description |
|---|---|---|
rect | Rect, optional | Content area to export. Defaults to the bounds of all strokes. |
backgroundColor | number, optional | 0xRRGGBBAA. Defaults to none. |
GlassStyle
type GlassStyle = 'regular' | 'clear'
regular frosts what is behind it; clear stays see-through and needs a busy backdrop to read well.
ListenerSubscription
Owns a registered listener.
| Member | Type | Description |
|---|---|---|
remove() | () => void | Removes the listener. Safe to call more than once. |