printmaker
Version:
Generate PDF documents and from JavaScript objects
60 lines (59 loc) • 1.64 kB
TypeScript
import { PDFImage } from 'pdf-lib';
import { Pos } from './box.js';
import { Color } from './colors.js';
export declare type GraphicsObject = RectObject | LineObject | PolylineObject | ImageObject;
export declare type RectObject = {
type: 'rect';
x: number;
y: number;
width: number;
height: number;
strokeWidth?: number;
strokeColor?: Color;
fillColor?: Color;
};
export declare type LineObject = {
type: 'line';
x1: number;
y1: number;
x2: number;
y2: number;
strokeWidth?: number;
strokeColor?: Color;
};
export declare type PolylineObject = {
type: 'polyline';
points: {
x: number;
y: number;
}[];
closePath?: boolean;
strokeWidth?: number;
strokeColor?: Color;
fillColor?: Color;
};
export declare type ImageObject = {
type: 'image';
x: number;
y: number;
width: number;
height: number;
image: PDFImage;
};
export declare function parseGraphics(input: unknown): GraphicsObject[];
/**
* Parses a given input as a graphics shape object. Throws if the input cannot be parsed.
*
* @param input The input value to parse.
* @returns A graphics shape object.
*/
export declare function parseGraphicsObject(input: unknown): GraphicsObject;
/**
* Shifts the a graphics object to a given position by adding the position's `x` and `y` values
* to the coordinates of the graphics object.
*
* @param rect The input graphics object to shift
* @param pos The position to shift to
* @returns The new graphics object
*/
export declare function shiftGraphicsObject<T extends GraphicsObject>(shape: T, pos: Pos): T;