Skip to content

Creating Render Plugins

Declare a renderer plugin in package.json and point it at an ES module:

{"id":"badges.tint","type":"renderer","entry":"renderer/tint.mjs",
 "description":"Tint badge geometry from its animated strength."}

The package descriptor also declares "extension": 1 in compatibility. In the Python component, a white rectangle carries two properties: badge_color is an RGB triple and badge_tint is a strength from 0 to 1. The package’s Pulse animation takes the strength to 1 over half a second and back to 0 over the next half-second.

Paint the badge

Use this module as renderer/tint.mjs. The effect applies only to nodes with the badge color property. It computes the tint from the current frame, draws the node once into a filtered layer, and returns its bounds.

export const extensionApiVersion = 1;
export function create() {
    return {
        register(registry) {
            registry.registerEffect('badges.tint', {
                applies(_node, props) { return Array.isArray(props.badge_color); },
                paint(context, draw) {
                    const { kit, canvas, props } = context;
                    const strength = Math.max(0, Math.min(1, Number(props.badge_tint ?? 0)));
                    const channels = props.badge_color.map(channel => (255 + (channel - 255) * strength) / 255);
                    const filter = kit.ColorFilter.MakeMatrix([
                        channels[0], 0, 0, 0, 0,
                        0, channels[1], 0, 0, 0,
                        0, 0, channels[2], 0, 0,
                        0, 0, 0, 1, 0,
                    ]);
                    const paint = new kit.Paint();
                    paint.setColorFilter(filter);
                    canvas.saveLayer(paint, context.localBounds ?? undefined);
                    try {
                        return draw();
                    }
                    finally {
                        canvas.restore();
                        paint.delete();
                        filter.delete();
                    }
                },
            });
        },
        dispose() { },
    };
}

At the start the rectangle is white. Halfway through the pulse it has the package accent color. Seeking back to the same frame produces the same tint. Balance each layer save with a restore and release each CanvasKit object the effect allocates.

Badge at its peak tint

Test forward and backward seeks and compare browser and server pixels. See the Renderer API for the versioned registry and context contracts. See the complete package walkthrough for the Python component and project manifest.