grom-font-effects
v0.1.2
Published
Browser renderer for Text Effects Editor JSON presets.
Maintainers
Readme
GROm Font Effects
Browser-first TypeScript renderer for Text Effects Editor JSON presets. It loads or parses an exported effect document and renders the result into an HTML canvas.
Download JSON effect examples from the Text Effects Editor repository. Load them with FontEffectDocument.load(url), parse them with FontEffectDocument.parse(json), or import them directly into the editor.

License
GROm Font Effects is free and open-source under the MIT License. You can use, copy, modify, and distribute it for free, including in commercial projects, as long as the copyright notice and author attribution to Roman Gaikov are preserved.
Installation
Install the public package from npm:
npm install grom-font-effectsThen import from the package:
import { FontEffectDocument } from 'grom-font-effects';Basic Usage
Parse an exported JSON document and create a transparent canvas:
const document = FontEffectDocument.parse(jsonText);
const canvas = document.createCanvas();
document.body.append(canvas);Override text or font settings at render time:
const canvas = document.createCanvas({
text: 'GROm Games',
fontFamily: 'Comic Sans MS',
fontSize: 180,
canvasWidth: 1500,
canvasHeight: 500,
boldWeight: 900,
italic: false,
});Render into an existing canvas or 2D context:
document.drawToCanvas(existingCanvas, { text: 'PLAY' });
document.drawToCanvas(existingContext, { fontSize: 220 });Load a JSON preset by URL:
const document = await FontEffectDocument.load('/presets/chrome.json');
const canvas = document.createCanvas();Document Shape
The renderer accepts the same JSON exported by Text Effects Editor:
{
"version": 1,
"text": "Hello World",
"fontFamily": "Arial",
"fontSize": 180,
"canvasWidth": 1200,
"canvasHeight": 800,
"boldWeight": 400,
"italic": false,
"effects": [
{ "type": "fill", "color": "#10161A", "opacity": 1 }
]
}Missing document fields fall back to editor defaults. Unsupported or malformed effects are skipped; if nothing valid remains, a black fill effect is used.
Supported Effects
group: renders nested child effects into an isolated buffer.fill: fills text with a solid color.stroke: draws text outlines with canvas stroke settings.gradientFill: fills text with evenly distributed gradient colors.patternFill: fills text with procedural stripes, dots, checker, or grid patterns.noise: applies procedural noise to already rendered content.shadow: renders a drop shadow behind the current group buffer.innerShadow: casts shadow inward from transparent pixels onto filled pixels.glow: adds a colored glow behind the current group buffer.blur: destructively blurs the current buffer.wave: destructively sine-warps the current buffer.distort: destructively distorts the current buffer with procedural displacement.compositeBlend: applies a canvas composite operation to the current buffer.
API
class FontEffectDocument {
static load(url: string): Promise<FontEffectDocument>;
static parse(json: string | unknown): FontEffectDocument;
readonly source: FontEffectsDocumentSnapshot;
readonly effects: IFontEffect[];
createCanvas(options?: RenderOptions): HTMLCanvasElement;
drawToCanvas(
canvas: HTMLCanvasElement | CanvasRenderingContext2D,
options?: RenderOptions,
): void;
}RenderOptions can override text, fontFamily, fontSize, canvasWidth, canvasHeight, boldWeight, and italic.
Development
npm install
npm run buildBuild output is written to dist/ as an ESM browser bundle with TypeScript declarations.
