Files
online-energieausweis/src/lib/pdf/elements/PDFElement.ts
2025-04-01 09:35:15 -03:00

41 lines
974 B
TypeScript

import { PDFPage } from "pdf-lib";
import { Margin, Padding } from "./Layout.js";
export type Size = number | "auto";
export abstract class PDFElement {
protected _height: Size = 0;
protected _width: Size = 0;
public margin: Margin = { top: 0, bottom: 0, left: 0, right: 0 };
public padding: Padding = { top: 0, bottom: 0, left: 0, right: 0 };
get width(): number {
return this.innerWidth + this.padding.left + this.padding.right;
}
set width(value: Size) {
this._width = value;
}
get innerWidth() {
return this._width === "auto" ? 0 : this._width;
}
get height(): number {
return this.innerHeight + this.padding.top + this.padding.bottom;
}
set height(value: Size) {
this._height = value;
}
get innerHeight() {
return this._height === "auto" ? 0 : this._height;
}
async draw(page: PDFPage, x: number, y: number): Promise<void> {
throw new Error("Method is not implemented.")
}
abstract addChild(...children: PDFElement[]): void;
}