Skip to content

Renderer plugin API

Implement ExtensionModule to register a node renderer or layer effect. Host integrations use RenderSession to render or inspect a frame.

Create a render plugin

FramePixels

Width and height in pixels, with four RGBA bytes per pixel in row-major order.

export type FramePixels = { width: number; height: number; rgba: Uint8Array };

Bounds

Rectangle edges in [left, top, right, bottom] order. Session queries return surface coordinates.

export type Bounds = [number, number, number, number];

RenderEnvironment

Asset access supplied by the host when creating a session.

readAsset(sha256: string): Promise<Uint8Array>;

Fetch an immutable asset by its content hash.

RenderSession

Load a scene once, then request zero-based frames in any order. Dispose after the last query.

load(document: SceneDocument): Promise<void>;

Load and validate a complete DOM document before rendering.

render(frame: number): Promise<FramePixels>;

Render one zero-based frame and return tightly packed RGBA pixels.

inspect(frame: number, nodeIds: string[]): Promise<Record<string, Props>>;

Inspect resolved properties for selected node IDs at a frame.

hitTest(frame: number, x: number, y: number): Promise<string | null>;

Return the front-most selectable owner hit at a surface coordinate, or null.

bounds(frame: number, nodeId: string): Promise<Bounds | null>;

Return the node's resolved visual bounds, or null when it paints nothing.

png(frame: number): Promise<Uint8Array>;

Encode one rendered frame as PNG bytes.

dispose(): Promise<void>;

Release surfaces, fonts, effects and other session resources.

DrawingContext

Versioned Video2D drawing API. No browser or application objects cross this boundary.

readonly kit: CanvasKit;

CanvasKit instance used by the host; extensions must not retain it after paint.

readonly canvas: Canvas;

Current drawing surface with the node transform and clip applied.

readonly node: SceneNode;

Scene node being painted.

readonly props: Props;

Resolved property values for this node at the requested frame.

localBounds: Bounds | null;

Measured bounds when available before painting, otherwise null.

path(path: Path, paint: Paint): void;

Paint a path in the node's local coordinate system.

text(paragraph: Paragraph, x: number, y: number): void;

Draw a prepared paragraph at local coordinates.

NodeRenderer

Renderer callback for a custom node type. Return the painted local bounds.

export type NodeRenderer = (context: DrawingContext) => Bounds | null;

LayerEffect

Wrap the painting of each matching node.

applies(node: SceneNode, props: Props): boolean;

Whether this effect applies to this node's own paint.

paint(context: DrawingContext, paint: () => Bounds | null): Bounds | null;

Must invoke paint exactly once; any additional layers are owned by the effect.

Video2DRegistry

Session registry supplied to an extension during registration.

registerNodeRenderer(type: string, renderer: NodeRenderer): void;

Associate a node type with its renderer. Duplicate registrations are errors.

registerEffect(id: string, effect: LayerEffect): void;

Register a compositing effect by stable ID.

Video2DExtension

One extension instance per render session.

register(registry: Video2DRegistry): void;

Register all node renderers and effects owned by this extension.

dispose(): void;

Release extension-owned CanvasKit resources. May be called once.

ExtensionModule

Exports required from a renderer plugin entry module.

extensionApiVersion: number;

Must equal the host-supported extension API version.

create(): Video2DExtension;

Construct an isolated extension instance for one render session.