Sone.js Logo
Sone.js
A declarative Canvas layout engine for JavaScript with advanced rich text support

Sone.js also powers the KhmerCoders Open Graph image generation

Overview

  • This project uses skia-canvas if you encounter an installation issue, please follow the skia-canvas instruction
  • Node.js 16+ or equivalent
npm install sone
import { Column, Span, sone, Text } from "sone"; function Document() { return Column( Text("Hello, ", Span("World").color("blue").weight("bold")) .size(44) .color("black"), ) .padding(24) .bg("white"); } // save as buffer const buffer = await sone(Document()).jpg(); // save to file import fs from "node:fs/promises"; await fs.writeFile("image.jpg", buffer);

More examples can be found at test/visual directory

Font Registration

import { Font } from 'sone'; if (!Font.has("NotoSansKhmer")) { await Font.load('NotoSansKhmer', "test/font/NotoSansKhmer.ttf"); }
Showcase Media 1