canvas-text-block
Version:
Easily render a wrapping block of text in an HTML Canvas Element.
31 lines (30 loc) • 876 B
TypeScript
import type { Canvas as NodeCanvas } from "canvas";
export type CanvasTextBlockOptions = {
color?: string;
backgroundColor?: string;
fontFamily?: string;
fontSize?: number;
lineHeight?: number;
padding?: number;
weight?: string;
ellipsis?: boolean;
overflow?: boolean;
};
export default class CanvasTextBlock {
private canvas;
private context;
private x;
private y;
private width;
private height;
private options;
constructor(canvas: HTMLCanvasElement | NodeCanvas, x: number, y: number, width: number, height: number, options?: CanvasTextBlockOptions);
private getTextBlockMaxWidth;
private getOptions;
private getMaxLineCount;
private setBackgroundColor;
private getStartingLineXPos;
private getStartingLineYPos;
setText: (text: string) => void;
private getLinesFromText;
}