SVGCanvasHandle — vector canvas emitting SVG
Auto-generated from
bridge/src/js/prelude/src/on 2026-10-24. Runtask gen:api-referenceto refresh.
SVGCanvasHandle mirrors CanvasHandle's API but emits an SVG document instead of rasterising. Returned by Engine.createSVGCanvas(); get the SVG markup via toString() or write directly with Engine.writeSVG(path, svg.toString()). Also supports drawText() since SVG has native text.
Classes
SVGCanvasHandle
Vector drawing canvas that emits an SVG document.
Obtain one via Engine.createSVGCanvas(w, h). Mirrors the API of
CanvasHandle (fill / pen / drawPath / save / restore / translate /
scale / rotate / linearGradient / radialGradient) but also supports
drawText() since SVG has native text. Use toString() to get the
SVG markup; pass that to Engine.writeSVG(path, svg.toString())
to write it to disk.
const svg = Engine.createSVGCanvas(400, 300);
svg.fill("#16213e").drawPath(Engine.createPath().rect(0, 0, 400, 300));
svg.fill("#ff6b6b").drawPath(Engine.createPath().circle(200, 150, 80));
svg.fill("#ffffff").drawText("Hello", 200, 160, { size: 32, anchor: "middle" });
Engine.writeSVG("out.svg", svg.toString());
Limitations vs. raster CanvasHandle:
- Text glyphs are not converted to outlines, so consumer viewers
must have the requested font installed (or fall back to a
generic family). Pass
InterorJetBrains Monofor fonts that any browser substitutes reasonably.
Accessors
height
Get Signature
get height(): number;
Returns
number
width
Get Signature
get width(): number;
Returns
number
Constructors
Constructor
new SVGCanvasHandle(width, height): SVGCanvasHandle;
Parameters
| Parameter | Type |
|---|---|
width |
number |
height |
number |
Returns
Methods
drawPath()
drawPath(path, stroke?): this;
Draw a PathHandle. stroke=true strokes (using current pen);
default fills (using current fill). Returns this.
Parameters
| Parameter | Type | Default value |
|---|---|---|
path |
PathHandle |
undefined |
stroke |
boolean |
false |
Returns
this
drawPathStr()
drawPathStr(svgD, stroke?): this;
Draw an SVG path-data string directly. Returns this.
Parameters
| Parameter | Type | Default value |
|---|---|---|
svgD |
string |
undefined |
stroke |
boolean |
false |
Returns
this
drawText()
drawText(
text,
x,
y,
opts?): this;
Draw a single line of text. SVG-native — the consumer's renderer
substitutes the family if it's not present, so prefer
"Inter" / "JetBrains Mono" (or generic sans-serif/monospace)
for portability.
Parameters
| Parameter | Type | Description |
|---|---|---|
text |
string |
The string to draw. |
x |
number |
X coordinate in pixels. |
y |
number |
Y baseline coordinate in pixels (SVG text default). |
opts? |
{ anchor?: "start" | "middle" | "end"; color?: Color; font?: string; size?: number; } |
- |
opts.anchor? |
"start" | "middle" | "end" |
"start" (default), "middle" or "end". |
opts.color? |
Color |
Color (Pixel |
opts.font? |
string |
Font family. Default "Inter". |
opts.size? |
number |
Pixel size. Default 16. |
Returns
this
fill()
fill(color): this;
Set solid fill color. Returns this.
Parameters
| Parameter | Type |
|---|---|
color |
Color |
Returns
this
free()
free(): void;
No-op — kept for API symmetry with CanvasHandle.
Returns
void
linearGradient()
linearGradient(
p1,
p2,
colors,
stops): this;
Set fill to a linear gradient. Stops the same way as CanvasHandle.linearGradient.
Parameters
| Parameter | Type |
|---|---|
p1 |
Px | [number, number] |
p2 |
Px | [number, number] |
colors |
(Color | [number, number, number, number])[] |
stops |
number[] |
Returns
this
pen()
pen(color, width): this;
Set stroke color and width. Returns this.
Parameters
| Parameter | Type |
|---|---|
color |
Color |
width |
number |
Returns
this
radialGradient()
radialGradient(
center,
r,
colors,
stops): this;
Set fill to a radial gradient. Stops the same way as CanvasHandle.radialGradient.
Parameters
| Parameter | Type |
|---|---|
center |
Px | [number, number] |
r |
number |
colors |
(Color | [number, number, number, number])[] |
stops |
number[] |
Returns
this
restore()
restore(): this;
Restore last saved paint and transform state. Returns this.
Returns
this
rotate()
rotate(angle): this;
Pre-rotate the transform by angle degrees. Returns this.
Parameters
| Parameter | Type |
|---|---|
angle |
number |
Returns
this
save()
save(): this;
Save current paint and transform state. Returns this.
Returns
this
scale()
scale(sx, sy): this;
Pre-scale the transform. Returns this.
Parameters
| Parameter | Type |
|---|---|
sx |
number |
sy |
number |
Returns
this
toString()
toString(): string;
Return the SVG document as a string.
Returns
string
translate()
translate(x, y): this;
Pre-translate the transform. Returns this.
Parameters
| Parameter | Type |
|---|---|
x |
number |
y |
number |
Returns
this