@nmmty/adapter-node
v1.0.0
Published
Node.js adapter for @nmmty/lazycanvas, powered by @napi-rs/canvas.
Maintainers
Readme
@nmmty/adapter-node
Node.js adapter for @nmmty/lazycanvas, powered by @napi-rs/canvas — a fast, dependency-free Skia binding with prebuilt binaries for Linux, macOS and Windows.
Installation
npm install @nmmty/lazycanvas @nmmty/adapter-nodeRequires Node.js 18 or newer. @napi-rs/canvas is installed automatically.
Usage
import { NodeCanvasAdapter } from "@nmmty/adapter-node";
import { MorphLayer, Scene } from "@nmmty/lazycanvas";
import { Exporter } from "@nmmty/lazycanvas/node";
const scene = new Scene(400, 200, { adapter: new NodeCanvasAdapter() });
scene.load(new MorphLayer({ color: "#22c55e", size: { width: 400, height: 200 } }));
await new Exporter(scene).export("png", { name: "out", saveAsFile: true });What the adapter provides
| Member | Description |
| --- | --- |
| createCanvas(width, height) | A new @napi-rs/canvas Canvas |
| loadImage(source) | Decodes a URL, file path, Buffer or Uint8Array |
| fonts.registerFromPath(path, family) | Registers a font file; returns false instead of throwing if it cannot be read |
| fonts.register(base64, family) | Registers a base64-encoded font |
| fonts.has(family) / fonts.families | Inspect the registered families |
| Path2D | The @napi-rs/canvas Path2D constructor (Node has no global one) |
Bundled fonts
import { Fonts } from "@nmmty/lazycanvas/fonts";
scene.lazyCanvas.manager.fonts.loadFonts(Fonts); // Geist and Geist MonoLicense
MIT © NMMTY
