Paths, Transforms, and Capabilities
Paths are a core part of the package surface. Path accepts SVG-style strings, explicit command arrays, and mutable path objects created with createPath(). Group transforms and capability helpers complement this by defining how complex scenes are composed and which native features are available at runtime.
These APIs are especially relevant when porting drawing code, building editors, or guarding advanced rendering features behind runtime checks.
Basic usage
import { Canvas, Path, createPath } from "@zynthjs/skia";
const triangle = createPath()
.moveTo(40, 24)
.lineTo(176, 96)
.lineTo(40, 168)
.close();
export function PathScene() {
return (
<Canvas clearColor="#020617" style={{ width: 220, height: 200 }}>
<Path path={triangle} color="#38bdf8" />
</Canvas>
);
}
Advanced examples
Using SVG path strings
import { Canvas, Path } from "@zynthjs/skia";
export function SvgPathScene() {
return (
<Canvas clearColor="#111827" style={{ width: 320, height: 180 }}>
<Path
path="M 24 120 C 96 24 224 24 296 120"
color="#f59e0b"
style="stroke"
strokeWidth={5}
/>
</Canvas>
);
}
Transforming a path subtree
import { Canvas, Group, Path } from "@zynthjs/skia";
export function RotatedPath() {
return (
<Canvas clearColor="#0f172a" style={{ width: 320, height: 180 }}>
<Group x={160} y={90} rotate={24} originX={0} originY={0}>
<Path path="M -80 0 Q 0 -64 80 0 Q 0 64 -80 0 Z" color="#22c55e" />
</Group>
</Canvas>
);
}
Checking capabilities before using a feature
import {
assertSkiaFeature,
getSkiaCapabilities,
supportsSkiaFeature,
} from "@zynthjs/skia";
const caps = getSkiaCapabilities();
const canDrawSVG = supportsSkiaFeature("svg");
assertSkiaFeature("group.transforms", "rotating gauge");
console.log(caps.paths, canDrawSVG);
Special cases and unusual features
createPath()returns a mutable builder withmoveTo,lineTo,quadTo,cubicTo,close,reset, andclone.- The SVG parser supports
M/m,L/l,H/h,V/v,Q/q,T/t,C/c,S/s,A/a, andZ/z. - Arc commands are normalized into cubic path segments before submission.
Pathalso accepts a rawSkiaPathCommand[]array when paths are generated programmatically elsewhere.getSkiaCapabilities()merges the native capability report with package defaults, so unsupported features can be checked without probing draw behavior manually.
API Reference
createPath(initial?)
initial?: SkiaPathSource- returns
SkiaPathObject
SkiaPathObject
commands: readonly SkiaPathCommand[]moveTo(x, y)lineTo(x, y)quadTo(cpx, cpy, x, y)cubicTo(cp1x, cp1y, cp2x, cp2y, x, y)close()reset()clone()
SkiaPathSource
SkiaPathObjectreadonly SkiaPathCommand[]string
Group transform props
x,ytranslateX,translateYscale,scaleX,scaleYrotateoriginX,originYlayer
Capability helpers
getSkiaCapabilities(): SkiaCapabilitiessupportsSkiaFeature(feature: SkiaFeature): booleanassertSkiaFeature(feature: SkiaFeature, context?: string): void
SkiaFeature
pathspath.curvespaint.opacitypaint.strokeCappaint.strokeJoinpaint.strokeMitergroup.transformstextfont.measuremask.luminanceshader.linearGradientgroup.layerimagessvgskottie