First commit

This commit is contained in:
2026-01-12 13:12:46 +01:00
parent b2d9501f6d
commit a1fbd8acf5
4413 changed files with 1245183 additions and 0 deletions

8
node_modules/swissqrbill/lib/cjs/pdf/index.cjs generated vendored Normal file
View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const swissqrbill = require("./swissqrbill.cjs");
const swissqrcode = require("./swissqrcode.cjs");
const table = require("./table.cjs");
exports.SwissQRBill = swissqrbill.SwissQRBill;
exports.SwissQRCode = swissqrcode.SwissQRCode;
exports.Table = table.Table;

3
node_modules/swissqrbill/lib/cjs/pdf/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
export * from './swissqrbill.js';
export * from './swissqrcode.js';
export * from './table.js';

395
node_modules/swissqrbill/lib/cjs/pdf/swissqrbill.cjs generated vendored Normal file
View File

@@ -0,0 +1,395 @@
"use strict";
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const swissqrcode = require("./swissqrcode.cjs");
const cleaner = require("../shared/cleaner.cjs");
const translations = require("../shared/translations.cjs");
const validator = require("../shared/validator.cjs");
const utils = require("../shared/utils.cjs");
const _SwissQRBill = class _SwissQRBill {
/**
* Creates a new SwissQRBill instance.
*
* @param data The data to be used for the QR Bill.
* @param options Options to define how the QR Bill should be rendered.
* @throws { ValidationError } Throws an error if the data is invalid.
*/
constructor(data, options) {
this.scissors = true;
this.separate = false;
this.outlines = true;
this.language = "DE";
this.font = "Helvetica";
this._x = 0;
this._y = 0;
this.data = cleaner.cleanData(data);
validator.validateData(this.data);
this.language = (options == null ? void 0 : options.language) !== void 0 ? options.language : this.language;
this.outlines = (options == null ? void 0 : options.outlines) !== void 0 ? options.outlines : this.outlines;
this.font = (options == null ? void 0 : options.fontName) !== void 0 ? options.fontName : this.font;
if ((options == null ? void 0 : options.scissors) !== void 0) {
this.scissors = options.scissors;
this.separate = !options.scissors;
}
if ((options == null ? void 0 : options.separate) !== void 0) {
this.separate = options.separate;
this.scissors = !options.separate;
}
if ((options == null ? void 0 : options.scissors) === false && (options == null ? void 0 : options.separate) === false) {
this.separate = false;
this.scissors = false;
}
}
/**
* Attaches the QR-Bill to a PDFKit document instance. It will create a new page with the size of the QR-Slip if not
* enough space is left on the current page.
*
* @param doc The PDFKit instance.
* @param x The horizontal position in points where the QR Bill will be placed.
* @param y The vertical position in points where the QR Bill will be placed.
*/
attachTo(doc, x = 0, y = ((_a) => (_a = doc.page) == null ? void 0 : _a.height)() ? ((_b) => (_b = doc.page) == null ? void 0 : _b.height)() - utils.mm2pt(105) : 0) {
if (!_SwissQRBill.isSpaceSufficient(doc, x, y)) {
doc.addPage({
margin: 0,
size: [_SwissQRBill.width, _SwissQRBill.height]
});
x = 0;
y = 0;
}
this._x = x;
this._y = y;
this.render(doc);
}
/**
* Checks whether there is enough space on the current page to add the QR Bill.
*
* @param doc The PDFKit document instance.
* @param x The horizontal position where the QR Bill will be placed.
* @param y The vertical position where the QR Bill will be placed.
* @returns `true` if there is enough space, otherwise `false`.
*/
static isSpaceSufficient(doc, x = 0, y = ((_c) => (_c = doc.page) == null ? void 0 : _c.height)() ? ((_d) => (_d = doc.page) == null ? void 0 : _d.height)() - _SwissQRBill.height : 0) {
if (!doc.page) {
return false;
}
return Math.round(x + _SwissQRBill.width) <= Math.round(doc.page.width) && Math.round(doc.y + _SwissQRBill.height) <= Math.round(doc.page.height) && Math.round(y + _SwissQRBill.height) <= Math.round(doc.page.height);
}
x(millimeters = 0) {
return this._x + utils.mm2pt(millimeters);
}
y(millimeters = 0) {
return this._y + utils.mm2pt(millimeters);
}
render(doc) {
if (this.outlines) {
if (doc.page.height > utils.mm2pt(105)) {
doc.moveTo(this.x(), this.y()).lineTo(this.x(210), this.y()).lineWidth(0.75).strokeOpacity(1).dash(1, { size: 1 }).strokeColor("black").stroke();
}
doc.moveTo(this.x(62), this.y()).lineTo(this.x(62), this.y(105)).lineWidth(0.75).strokeOpacity(1).dash(1, { size: 1 }).strokeColor("black").stroke();
}
if (this.scissors) {
const scissorsTop = "4.545 -1.803 m 4.06 -2.388 3.185 -2.368 2.531 -2.116 c -1.575 -0.577 l -2.769 -1.23 -3.949 -1.043 -3.949 -1.361 c -3.949 -1.61 -3.721 -1.555 -3.755 -2.203 c -3.788 -2.825 -4.437 -3.285 -5.05 -3.244 c -5.664 -3.248 -6.3 -2.777 -6.305 -2.129 c -6.351 -1.476 -5.801 -0.869 -5.152 -0.826 c -4.391 -0.713 -3.043 -1.174 -2.411 -0.041 c -2.882 0.828 -3.718 0.831 -4.474 0.787 c -5.101 0.751 -5.855 0.931 -6.154 1.547 c -6.443 2.138 -6.16 2.979 -5.496 3.16 c -4.826 3.406 -3.906 3.095 -3.746 2.325 c -3.623 1.731 -4.044 1.452 -3.882 1.236 c -3.76 1.073 -2.987 1.168 -1.608 0.549 c 2.838 2.117 l 3.4 2.273 4.087 2.268 4.584 1.716 c -0.026 -0.027 l 4.545 -1.803 l h -4.609 -2.753 m -3.962 -2.392 -4.015 -1.411 -4.687 -1.221 c -5.295 -1.009 -6.073 -1.6 -5.879 -2.26 c -5.765 -2.801 -5.052 -3 -4.609 -2.753 c h -4.581 1.256 m -3.906 1.505 -4.02 2.648 -4.707 2.802 c -5.163 2.96 -5.814 2.733 -5.86 2.196 c -5.949 1.543 -5.182 0.954 -4.581 1.256 c h";
const scissorsCenter = " 1.803 4.545 m 2.388 4.06 2.368 3.185 2.116 2.531 c 0.577 -1.575 l 1.23 -2.769 1.043 -3.949 1.361 -3.949 c 1.61 -3.949 1.555 -3.721 2.203 -3.755 c 2.825 -3.788 3.285 -4.437 3.244 -5.05 c 3.248 -5.664 2.777 -6.3 2.129 -6.305 c 1.476 -6.351 0.869 -5.801 0.826 -5.152 c 0.713 -4.391 1.174 -3.043 0.041 -2.411 c -0.828 -2.882 -0.831 -3.718 -0.787 -4.474 c -0.751 -5.101 -0.931 -5.855 -1.547 -6.154 c -2.138 -6.443 -2.979 -6.16 -3.16 -5.496 c -3.406 -4.826 -3.095 -3.906 -2.325 -3.746 c -1.731 -3.623 -1.452 -4.044 -1.236 -3.882 c -1.073 -3.76 -1.168 -2.987 -0.549 -1.608 c -2.117 2.838 l -2.273 3.4 -2.268 4.087 -1.716 4.584 c 0.027 -0.026 l 1.803 4.545 l h 2.753 -4.609 m 2.392 -3.962 1.411 -4.015 1.221 -4.687 c 1.009 -5.295 1.6 -6.073 2.26 -5.879 c 2.801 -5.765 3 -5.052 2.753 -4.609 c h -1.256 -4.581 m -1.505 -3.906 -2.648 -4.02 -2.802 -4.707 c -2.96 -5.163 -2.733 -5.814 -2.196 -5.86 c -1.543 -5.949 -0.954 -5.182 -1.256 -4.581 c h";
if (doc.page.height > utils.mm2pt(105)) {
doc.save();
doc.translate(this.x(105), this.y());
doc.addContent(scissorsTop).fillColor("black").fill();
doc.restore();
}
doc.save();
doc.translate(this.x(62), this.y() + 30);
doc.addContent(scissorsCenter).fillColor("black").fill();
doc.restore();
}
if (this.separate) {
if (doc.page.height > utils.mm2pt(105)) {
doc.fontSize(11);
doc.font(this.font);
doc.text(translations.translations[this.language].separate, 0, this.y() - 12, {
align: "center",
width: utils.mm2pt(210)
});
}
}
doc.fontSize(11);
doc.font(`${this.font}-Bold`);
doc.text(translations.translations[this.language].receipt, this.x(5), this.y(5), {
align: "left",
width: utils.mm2pt(52)
});
doc.fontSize(6);
doc.font(`${this.font}-Bold`);
doc.text(translations.translations[this.language].account, this.x(5), this.y(12), {
lineGap: 1,
width: utils.mm2pt(52)
});
doc.fontSize(8);
doc.font(this.font);
doc.text(`${utils.formatIBAN(this.data.creditor.account)}
${this.formatAddress(this.data.creditor)}`, {
lineGap: -0.5,
width: utils.mm2pt(52)
});
doc.fontSize(9);
doc.moveDown();
if (this.data.reference !== void 0) {
doc.fontSize(6);
doc.font(`${this.font}-Bold`);
doc.text(translations.translations[this.language].reference, {
lineGap: 1,
width: utils.mm2pt(52)
});
doc.fontSize(8);
doc.font(this.font);
doc.text(utils.formatReference(this.data.reference), {
lineGap: -0.5,
width: utils.mm2pt(52)
});
doc.fontSize(9);
doc.moveDown();
}
if (this.data.debtor !== void 0) {
doc.fontSize(6);
doc.font(`${this.font}-Bold`);
doc.text(translations.translations[this.language].payableBy, {
lineGap: 1,
width: utils.mm2pt(52)
});
doc.fontSize(8);
doc.font(this.font);
doc.text(this.formatAddress(this.data.debtor), {
lineGap: -0.5,
width: utils.mm2pt(52)
});
} else {
doc.fontSize(6);
doc.font(`${this.font}-Bold`);
doc.text(translations.translations[this.language].payableByName, {
lineGap: 1,
width: utils.mm2pt(52)
});
this.addRectangle(doc, 5, utils.pt2mm(doc.y - this.y()), 52, 20);
}
doc.fontSize(6);
doc.font(`${this.font}-Bold`);
doc.text(translations.translations[this.language].currency, this.x(5), this.y(68), {
lineGap: 1,
width: utils.mm2pt(15)
});
const amountXPosition = this.data.amount === void 0 ? 18 : 27;
doc.text(translations.translations[this.language].amount, this.x(amountXPosition), this.y(68), {
lineGap: 1,
width: utils.mm2pt(52 - amountXPosition)
});
doc.fontSize(8);
doc.font(this.font);
doc.text(this.data.currency, this.x(5), this.y(71), {
lineGap: -0.5,
width: utils.mm2pt(15)
});
if (this.data.amount !== void 0) {
doc.text(utils.formatAmount(this.data.amount), this.x(amountXPosition), this.y(71), {
lineGap: -0.5,
width: utils.mm2pt(52 - amountXPosition)
});
} else {
this.addRectangle(doc, 27, 68, 30, 10);
}
doc.fontSize(6);
doc.font(`${this.font}-Bold`);
doc.text(translations.translations[this.language].acceptancePoint, this.x(5), this.y(82), {
align: "right",
height: utils.mm2pt(18),
lineGap: 1,
width: utils.mm2pt(52)
});
doc.fontSize(11);
doc.font(`${this.font}-Bold`);
doc.text(translations.translations[this.language].paymentPart, this.x(67), this.y(5), {
align: "left",
lineGap: 1,
width: utils.mm2pt(51)
});
const swissQRCode = new swissqrcode.SwissQRCode(this.data);
swissQRCode.attachTo(doc, this.x(67), this.y(17));
doc.fontSize(8);
doc.font(`${this.font}-Bold`);
doc.text(translations.translations[this.language].currency, this.x(67), this.y(68), {
lineGap: 1,
width: utils.mm2pt(15)
});
doc.text(translations.translations[this.language].amount, this.x(89), this.y(68), {
width: utils.mm2pt(29)
});
doc.fontSize(10);
doc.font(this.font);
doc.text(this.data.currency, this.x(67), this.y(72), {
lineGap: -0.5,
width: utils.mm2pt(15)
});
if (this.data.amount !== void 0) {
doc.text(utils.formatAmount(this.data.amount), this.x(89), this.y(72), {
lineGap: -0.5,
width: utils.mm2pt(29)
});
} else {
this.addRectangle(doc, 78, 72, 40, 15);
}
if (this.data.av1 !== void 0) {
const [scheme, data] = this.data.av1.split(/(\/.+)/);
doc.fontSize(7);
doc.font(`${this.font}-Bold`);
doc.text(scheme, this.x(67), this.y(90), {
continued: true,
height: utils.mm2pt(3),
lineGap: 1,
width: utils.mm2pt(138)
});
doc.font(this.font);
doc.text(this.data.av1.length > 90 ? `${data.substring(0, 87)}...` : data, {
continued: false
});
}
if (this.data.av2 !== void 0) {
const [scheme, data] = this.data.av2.split(/(\/.+)/);
doc.fontSize(7);
doc.font(`${this.font}-Bold`);
doc.text(scheme, this.x(67), this.y(93), {
continued: true,
height: utils.mm2pt(3),
lineGap: 1,
width: utils.mm2pt(138)
});
doc.font(this.font);
doc.text(this.data.av2.length > 90 ? `${data.substring(0, 87)}...` : data, {
lineGap: -0.5
});
}
doc.fontSize(8);
doc.font(`${this.font}-Bold`);
doc.text(translations.translations[this.language].account, this.x(118), this.y(5), {
lineGap: 1,
width: utils.mm2pt(87)
});
doc.fontSize(10);
doc.font(this.font);
doc.text(`${utils.formatIBAN(this.data.creditor.account)}
${this.formatAddress(this.data.creditor)}`, {
lineGap: -0.75,
width: utils.mm2pt(87)
});
doc.fontSize(9);
doc.moveDown();
if (this.data.reference !== void 0) {
doc.fontSize(8);
doc.font(`${this.font}-Bold`);
doc.text(translations.translations[this.language].reference, {
lineGap: 1,
width: utils.mm2pt(87)
});
doc.fontSize(10);
doc.font(this.font);
doc.text(utils.formatReference(this.data.reference), {
lineGap: -0.75,
width: utils.mm2pt(87)
});
doc.fontSize(9);
doc.moveDown();
}
if (this.data.message !== void 0 || this.data.additionalInformation !== void 0) {
doc.fontSize(8);
doc.font(`${this.font}-Bold`);
doc.text(translations.translations[this.language].additionalInformation, {
lineGap: 1,
width: utils.mm2pt(87)
});
doc.fontSize(10);
doc.font(this.font);
const options = {
lineGap: -0.75,
width: utils.mm2pt(87)
};
const singleLineHeight = doc.heightOfString("A", options);
const referenceType = utils.getReferenceType(this.data.reference);
const maxLines = referenceType === "QRR" || referenceType === "SCOR" ? 3 : 4;
const linesOfAdditionalInformation = this.data.additionalInformation !== void 0 ? doc.heightOfString(this.data.additionalInformation, options) / singleLineHeight : 0;
if (this.data.additionalInformation !== void 0) {
if (referenceType === "QRR" || referenceType === "SCOR") {
if (this.data.message !== void 0) {
doc.text(this.data.message, __spreadProps(__spreadValues({}, options), { ellipsis: true, height: singleLineHeight, lineBreak: false }));
}
} else {
if (this.data.message !== void 0) {
const maxLinesOfMessage = maxLines - linesOfAdditionalInformation;
doc.text(this.data.message, __spreadProps(__spreadValues({}, options), { ellipsis: true, height: singleLineHeight * maxLinesOfMessage, lineBreak: true }));
}
}
doc.text(this.data.additionalInformation, options);
} else if (this.data.message !== void 0) {
doc.text(this.data.message, __spreadProps(__spreadValues({}, options), { ellipsis: true, height: singleLineHeight * maxLines, lineBreak: true }));
}
doc.fontSize(9);
doc.moveDown();
}
if (this.data.debtor !== void 0) {
doc.fontSize(8);
doc.font(`${this.font}-Bold`);
doc.text(translations.translations[this.language].payableBy, {
lineGap: 1,
width: utils.mm2pt(87)
});
doc.fontSize(10);
doc.font(this.font);
doc.text(this.formatAddress(this.data.debtor), {
lineGap: -0.75,
width: utils.mm2pt(87)
});
} else {
doc.fontSize(8);
doc.font(`${this.font}-Bold`);
doc.text(translations.translations[this.language].payableByName, {
lineGap: 1,
width: utils.mm2pt(87)
});
this.addRectangle(doc, 118, utils.pt2mm(doc.y - this.y()), 65, 25);
}
}
formatAddress(data) {
const countryPrefix = data.country !== "CH" ? `${data.country} - ` : "";
if (data.buildingNumber !== void 0) {
return `${data.name}
${data.address} ${data.buildingNumber}
${countryPrefix}${data.zip} ${data.city}`;
}
return `${data.name}
${data.address}
${countryPrefix}${data.zip} ${data.city}`;
}
addRectangle(doc, x, y, width, height) {
const length = 3;
doc.moveTo(this.x(x + length), this.y(y)).lineTo(this.x(x), this.y(y)).lineTo(this.x(x), this.y(y + length)).moveTo(this.x(x), this.y(y + height - length)).lineTo(this.x(x), this.y(y + height)).lineTo(this.x(x + length), this.y(y + height)).moveTo(this.x(x + width - length), this.y(y + height)).lineTo(this.x(x + width), this.y(y + height)).lineTo(this.x(x + width), this.y(y + height - length)).moveTo(this.x(x + width), this.y(y + length)).lineTo(this.x(x + width), this.y(y)).lineTo(this.x(x + width - length), this.y(y)).lineWidth(0.75).undash().strokeColor("black").stroke();
}
};
_SwissQRBill.width = utils.mm2pt(210);
_SwissQRBill.height = utils.mm2pt(105);
let SwissQRBill = _SwissQRBill;
exports.SwissQRBill = SwissQRBill;

89
node_modules/swissqrbill/lib/cjs/pdf/swissqrbill.d.ts generated vendored Normal file
View File

@@ -0,0 +1,89 @@
import { Data, PDFOptions } from '../shared/types.js';
/**
* The SwissQRBill class creates the Payment Part with the QR Code. It can be attached to any PDFKit document instance
* using the {@link SwissQRBill.attachTo} method.
*
* @example
* ```ts
* const data = {
* amount: 1994.75,
* creditor: {
* account: "CH44 3199 9123 0008 8901 2",
* address: "Musterstrasse",
* buildingNumber: 7,
* city: "Musterstadt",
* country: "CH",
* name: "SwissQRBill",
* zip: 1234
* },
* currency: "CHF",
* debtor: {
* address: "Musterstrasse",
* buildingNumber: 1,
* city: "Musterstadt",
* country: "CH",
* name: "Peter Muster",
* zip: 1234
* },
* reference: "21 00000 00003 13947 14300 09017"
* };
*
* const pdf = new PDFDocument({ autoFirstPage: false });
* const qrBill = new SwissQRBill(data);
*
* const stream = createWriteStream("qr-bill.pdf");
*
* qrBill.attachTo(pdf);
* pdf.pipe(stream);
* pdf.end();
* ```
*/
export declare class SwissQRBill {
private data;
private scissors;
private separate;
private outlines;
private language;
private font;
private _x;
private _y;
/**
* Creates a new SwissQRBill instance.
*
* @param data The data to be used for the QR Bill.
* @param options Options to define how the QR Bill should be rendered.
* @throws { ValidationError } Throws an error if the data is invalid.
*/
constructor(data: Data, options?: PDFOptions);
/**
* Attaches the QR-Bill to a PDFKit document instance. It will create a new page with the size of the QR-Slip if not
* enough space is left on the current page.
*
* @param doc The PDFKit instance.
* @param x The horizontal position in points where the QR Bill will be placed.
* @param y The vertical position in points where the QR Bill will be placed.
*/
attachTo(doc: PDFKit.PDFDocument, x?: number, y?: number): void;
/**
* Checks whether there is enough space on the current page to add the QR Bill.
*
* @param doc The PDFKit document instance.
* @param x The horizontal position where the QR Bill will be placed.
* @param y The vertical position where the QR Bill will be placed.
* @returns `true` if there is enough space, otherwise `false`.
*/
static isSpaceSufficient(doc: PDFKit.PDFDocument, x?: number, y?: number): boolean;
/**
* The horizontal size of the QR Bill.
*/
static readonly width: number;
/**
* The vertical size of the QR Bill.
*/
static readonly height: number;
private x;
private y;
private render;
private formatAddress;
private addRectangle;
}

51
node_modules/swissqrbill/lib/cjs/pdf/swissqrcode.cjs generated vendored Normal file
View File

@@ -0,0 +1,51 @@
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const cleaner = require("../shared/cleaner.cjs");
const qrCode = require("../shared/qr-code.cjs");
const validator = require("../shared/validator.cjs");
const utils = require("../shared/utils.cjs");
class SwissQRCode {
/**
* Creates a Swiss QR Code.
*
* @param data The data to be encoded in the QR code.
* @param size The size of the QR code in mm.
* @throws { ValidationError } Throws an error if the data is invalid.
*/
constructor(data, size = 46) {
this.size = utils.mm2pt(size);
this.data = cleaner.cleanData(data);
validator.validateData(this.data);
}
/**
* Attaches the Swiss QR Code to a PDF document.
*
* @param doc The PDF document to attach the Swiss QR Code to.
* @param x The horizontal position in points where the Swiss QR Code will be placed.
* @param y The vertical position in points where the Swiss QR Code will be placed.
*/
attachTo(doc, x = ((_a) => (_a = doc.x) != null ? _a : 0)(), y = ((_b) => (_b = doc.y) != null ? _b : 0)()) {
doc.save();
doc.translate(x, y);
qrCode.renderQRCode(this.data, this.size, (xPos, yPos, blockSize) => {
doc.rect(
xPos,
yPos,
blockSize,
blockSize
);
});
doc.fillColor("black");
doc.fill();
qrCode.renderSwissCross(this.size, (xPos, yPos, width, height, fillColor) => {
doc.rect(
xPos,
yPos,
width,
height
).fillColor(fillColor).fill();
});
doc.restore();
}
}
exports.SwissQRCode = SwissQRCode;

21
node_modules/swissqrbill/lib/cjs/pdf/swissqrcode.d.ts generated vendored Normal file
View File

@@ -0,0 +1,21 @@
import { Data } from '../shared/types.js';
export declare class SwissQRCode {
private size;
private data;
/**
* Creates a Swiss QR Code.
*
* @param data The data to be encoded in the QR code.
* @param size The size of the QR code in mm.
* @throws { ValidationError } Throws an error if the data is invalid.
*/
constructor(data: Data, size?: number);
/**
* Attaches the Swiss QR Code to a PDF document.
*
* @param doc The PDF document to attach the Swiss QR Code to.
* @param x The horizontal position in points where the Swiss QR Code will be placed.
* @param y The vertical position in points where the Swiss QR Code will be placed.
*/
attachTo(doc: PDFKit.PDFDocument, x?: number, y?: number): void;
}

255
node_modules/swissqrbill/lib/cjs/pdf/table.cjs generated vendored Normal file
View File

@@ -0,0 +1,255 @@
"use strict";
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
var TableLayer = /* @__PURE__ */ ((TableLayer2) => {
TableLayer2[TableLayer2["HeightCalculation"] = 0] = "HeightCalculation";
TableLayer2[TableLayer2["PageInjection"] = 1] = "PageInjection";
TableLayer2[TableLayer2["BackgroundColor"] = 2] = "BackgroundColor";
TableLayer2[TableLayer2["Borders"] = 3] = "Borders";
TableLayer2[TableLayer2["Text"] = 4] = "Text";
return TableLayer2;
})(TableLayer || {});
class Table {
/**
* Creates a new Table instance.
*
* @param data The rows and columns for the table.
* @returns The Table instance.
*/
constructor(data) {
this.data = data;
}
// Hacky workaround to get the current page of the document
getCurrentPage(doc) {
const page = doc.page;
for (let i = doc.bufferedPageRange().start; i < doc.bufferedPageRange().count; i++) {
doc.switchToPage(i);
if (doc.page === page) {
return i;
}
}
return doc.bufferedPageRange().count;
}
/**
* Attaches the table to a PDFKit document instance beginning on the current page. It will create a new page with for
* every row that no longer fits on a page.
*
* @param doc The PDFKit document instance.
* @param x The horizontal position in points where the table be placed.
* @param y The vertical position in points where the table will be placed.
* @throws { Error } Throws an error if no table rows are provided.
*/
attachTo(doc, x = ((_a) => (_a = doc.x) != null ? _a : 0)(), y = ((_b) => (_b = doc.y) != null ? _b : 0)()) {
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
if (this.data.rows === void 0) {
throw new Error("No table rows provided.");
}
if (!doc.page) {
doc.addPage({ size: "A4" });
}
doc.options.bufferPages = true;
const tableX = x;
const tableY = y;
const startPage = this.getCurrentPage(doc);
const tableWidth = this.data.width ? this.data.width : doc.page.width - tableX - doc.page.margins.right;
const tableBackgroundColor = this.data.backgroundColor ? this.data.backgroundColor : void 0;
const tableBorder = this.data.borderWidth ? this.data.borderWidth : void 0;
const tableBorderColors = this.data.borderColor ? this.data.borderColor : "#000000";
const tablePadding = this.data.padding ? this.data.padding : 0;
const tableFontSize = this.data.fontSize ? this.data.fontSize : 11;
const tableTextColor = this.data.textColor ? this.data.textColor : "#000000";
const tableFont = this.data.fontName ? this.data.fontName : "Helvetica";
const tableAlign = this.data.align ? this.data.align : void 0;
const tableVerticalAlign = this.data.verticalAlign ? this.data.verticalAlign : "top";
const headerRowIndex = this.data.rows.findIndex((row) => !!row.header);
const autoRowHeights = [];
for (let layer = 0; layer < Object.values(TableLayer).length / 2; layer++) {
doc.switchToPage(startPage);
let rowY = tableY;
rowLoop: for (let rowIndex = 0; rowIndex < this.data.rows.length; rowIndex++) {
const row = this.data.rows[rowIndex];
const rowHeight = autoRowHeights[rowIndex];
const minRowHeight = row.minHeight;
const maxRowHeight = row.maxHeight;
const rowPadding = row.padding ? row.padding : tablePadding;
const rowBackgroundColor = row.backgroundColor ? row.backgroundColor : tableBackgroundColor;
const rowBorder = row.borderWidth ? row.borderWidth : tableBorder;
const rowBorderColors = row.borderColor ? row.borderColor : tableBorderColors;
const rowFontSize = row.fontSize ? row.fontSize : tableFontSize;
const rowFont = row.fontName ? row.fontName : tableFont;
const rowTextColor = row.textColor ? row.textColor : tableTextColor;
const rowAlign = row.align ? row.align : tableAlign;
const rowVerticalAlign = row.verticalAlign ? row.verticalAlign : tableVerticalAlign;
doc.moveTo(tableX, tableY);
let columnX = tableX;
columnLoop: for (let columnIndex = 0; columnIndex < row.columns.length; columnIndex++) {
const column = row.columns[columnIndex];
const { remainingColumns, widthUsed } = row.columns.reduce((acc, column2) => {
if (column2.width !== void 0) {
acc.widthUsed += column2.width;
acc.remainingColumns--;
}
return acc;
}, { remainingColumns: row.columns.length, widthUsed: 0 });
const columnWidth = column.width ? column.width : (tableWidth - widthUsed) / remainingColumns;
const columnPadding = column.padding ? column.padding : rowPadding;
const columnBackgroundColor = column.backgroundColor ? column.backgroundColor : rowBackgroundColor;
const columnBorder = column.borderWidth ? column.borderWidth : rowBorder;
const columnBorderColors = column.borderColor ? column.borderColor : rowBorderColors;
const columnFontSize = column.fontSize ? column.fontSize : rowFontSize;
const columnFont = column.fontName ? column.fontName : rowFont;
const columnTextColor = column.textColor ? column.textColor : rowTextColor;
const columnAlign = column.align ? column.align : rowAlign;
const columnVerticalAlign = column.verticalAlign ? column.verticalAlign : rowVerticalAlign;
const fillOpacity = columnBackgroundColor === void 0 ? 0 : 1;
const borderOpacity = columnBorderColors === void 0 ? 0 : 1;
const paddings = this._positionsToObject(columnPadding);
doc.moveTo(columnX + columnWidth, rowY);
const textOptions = __spreadProps(__spreadValues({}, (_a2 = column.textOptions) != null ? _a2 : {}), {
align: columnAlign,
baseline: "middle",
height: rowHeight !== void 0 ? rowHeight - ((_b2 = paddings.top) != null ? _b2 : 0) - ((_c = paddings.bottom) != null ? _c : 0) : void 0,
lineBreak: true,
width: columnWidth - ((_d = paddings.left) != null ? _d : 0) - ((_e = paddings.right) != null ? _e : 0)
});
doc.font(columnFont);
doc.fontSize(columnFontSize);
const textHeight = doc.heightOfString(`${column.text}`, textOptions);
const singleLineHeight = doc.heightOfString("A", textOptions);
if (layer === 0) {
if (autoRowHeights[rowIndex] === void 0 || autoRowHeights[rowIndex] < textHeight + ((_f = paddings.top) != null ? _f : 0) + ((_g = paddings.bottom) != null ? _g : 0)) {
autoRowHeights[rowIndex] = textHeight + ((_h = paddings.top) != null ? _h : 0) + ((_i = paddings.bottom) != null ? _i : 0);
if (minRowHeight !== void 0 && autoRowHeights[rowIndex] < minRowHeight) {
autoRowHeights[rowIndex] = minRowHeight;
}
if (maxRowHeight !== void 0 && autoRowHeights[rowIndex] > maxRowHeight) {
autoRowHeights[rowIndex] = maxRowHeight;
}
}
if (row.height !== void 0) {
autoRowHeights[rowIndex] = row.height;
}
if (columnIndex < row.columns.length - 1) {
continue columnLoop;
} else {
continue rowLoop;
}
}
if (layer === 1) {
if (rowY + rowHeight >= doc.page.height - doc.page.margins.bottom) {
doc.addPage();
rowY = doc.y;
const headerRow = this.data.rows[headerRowIndex];
if (headerRow !== void 0) {
this.data.rows.splice(rowIndex, 0, headerRow);
autoRowHeights.splice(rowIndex, 0, autoRowHeights[headerRowIndex]);
rowIndex--;
continue rowLoop;
}
}
}
if (layer > 1) {
if (!!row.header && rowY !== ((_j = doc.page.margins.top) != null ? _j : 0) && rowIndex !== headerRowIndex || rowY + rowHeight >= doc.page.height - doc.page.margins.bottom) {
doc.switchToPage(this.getCurrentPage(doc) + 1);
doc.x = tableX;
doc.y = (_k = doc.page.margins.top) != null ? _k : 0;
rowY = doc.y;
}
}
if (layer === 2) {
if (columnBackgroundColor !== void 0) {
doc.rect(columnX, rowY, columnWidth, rowHeight).fillColor(columnBackgroundColor).fillOpacity(fillOpacity).fill();
}
}
if (layer === 4) {
let textPosY = rowY;
if (columnVerticalAlign === "top") {
textPosY = rowY + ((_l = paddings.top) != null ? _l : 0) + singleLineHeight / 2;
} else if (columnVerticalAlign === "center") {
textPosY = rowY + rowHeight / 2 - textHeight / 2 + singleLineHeight / 2;
} else if (columnVerticalAlign === "bottom") {
textPosY = rowY + rowHeight - ((_m = paddings.bottom) != null ? _m : 0) - textHeight + singleLineHeight / 2;
}
if (textPosY < rowY + ((_n = paddings.top) != null ? _n : 0) + singleLineHeight / 2) {
textPosY = rowY + ((_o = paddings.top) != null ? _o : 0) + singleLineHeight / 2;
}
doc.fillColor(columnTextColor).fillOpacity(1);
doc.text(`${column.text}`, columnX + ((_p = paddings.left) != null ? _p : 0), textPosY, textOptions);
}
if (layer === 3) {
if (columnBorder !== void 0 && columnBorderColors !== void 0) {
const border = this._positionsToObject(columnBorder);
const borderColor = this._positionsToObject(columnBorderColors);
doc.undash().lineJoin("miter").lineCap("butt").strokeOpacity(borderOpacity);
if (border.left && borderColor.left) {
const borderBottomMargin = border.bottom ? border.bottom / 2 : 0;
const borderTopMargin = border.top ? border.top / 2 : 0;
doc.moveTo(columnX, rowY + rowHeight + borderBottomMargin);
doc.lineTo(columnX, rowY - borderTopMargin).strokeColor(borderColor.left).lineWidth(border.left).stroke();
}
if (border.right && borderColor.right) {
const borderTopMargin = border.top ? border.top / 2 : 0;
const borderBottomMargin = border.bottom ? border.bottom / 2 : 0;
doc.moveTo(columnX + columnWidth, rowY - borderTopMargin);
doc.lineTo(columnX + columnWidth, rowY + rowHeight + borderBottomMargin).strokeColor(borderColor.right).lineWidth(border.right).stroke();
}
if (border.top && borderColor.top) {
const borderLeftMargin = border.left ? border.left / 2 : 0;
const borderRightMargin = border.right ? border.right / 2 : 0;
doc.moveTo(columnX - borderLeftMargin, rowY);
doc.lineTo(columnX + columnWidth + borderRightMargin, rowY).strokeColor(borderColor.top).lineWidth(border.top).stroke();
}
if (border.bottom && borderColor.bottom) {
const borderRightMargin = border.right ? border.right / 2 : 0;
const borderLeftMargin = border.left ? border.left / 2 : 0;
doc.moveTo(columnX + columnWidth + borderRightMargin, rowY + rowHeight);
doc.lineTo(columnX - borderLeftMargin, rowY + rowHeight).strokeColor(borderColor.bottom).lineWidth(border.bottom).stroke();
}
}
}
columnX += columnWidth;
}
rowY += rowHeight;
doc.x = columnX;
doc.y = rowY;
}
}
doc.x = tableX;
}
_positionsToObject(numberOrPositions) {
if (typeof numberOrPositions === "number" || typeof numberOrPositions === "string") {
return {
bottom: numberOrPositions,
left: numberOrPositions,
right: numberOrPositions,
top: numberOrPositions
};
} else {
return {
bottom: numberOrPositions[2] !== void 0 ? numberOrPositions[2] : numberOrPositions[0],
left: numberOrPositions[3] !== void 0 ? numberOrPositions[3] : numberOrPositions[1],
right: numberOrPositions[1] !== void 0 ? numberOrPositions[1] : void 0,
top: numberOrPositions[0]
};
}
}
}
exports.Table = Table;

154
node_modules/swissqrbill/lib/cjs/pdf/table.d.ts generated vendored Normal file
View File

@@ -0,0 +1,154 @@
export interface PDFTable {
/** Table rows. */
rows: PDFRow[];
/** Horizontal alignment of texts inside the table. */
align?: "center" | "left" | "right";
/** Background color of the table. */
backgroundColor?: string;
/** The colors of the border. */
borderColor?: PDFBorderColor;
/** Width of the borders of the row. */
borderWidth?: PDFBorderWidth;
/** Font of the text inside the table. */
fontName?: string;
/** Font size of the text inside the table. */
fontSize?: number;
/** Cell padding of the table cells. */
padding?: PDFPadding;
/** Text color of texts inside table. */
textColor?: string;
/** Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). */
textOptions?: PDFKit.Mixins.TextOptions;
/** Vertical alignment of texts inside the table. */
verticalAlign?: "bottom" | "center" | "top";
/** Width of whole table. */
width?: number;
}
export interface PDFRow {
/** Table columns. */
columns: PDFColumn[];
/** Horizontal alignment of texts inside the row. */
align?: "center" | "left" | "right";
/** Background color of the row. */
backgroundColor?: string;
/** The colors of the border. */
borderColor?: PDFBorderColor;
/** Width of the borders of the row. */
borderWidth?: PDFBorderWidth;
/** Font of the text inside the row. */
fontName?: string;
/** Font size of the text inside the row. */
fontSize?: number;
/** A header row gets inserted automatically on new pages. Only one header row is allowed. */
header?: boolean;
/** Height of the row. Overrides minHeight and maxHeight. */
height?: number;
/** Maximum height of the row. */
maxHeight?: number;
/** Minimum height of the row. */
minHeight?: number;
/** Cell padding of the table cells inside the row. */
padding?: PDFPadding;
/** Text color of texts inside the row. */
textColor?: string;
/** Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). */
textOptions?: PDFKit.Mixins.TextOptions;
/** Vertical alignment of texts inside the row. */
verticalAlign?: "bottom" | "center" | "top";
}
export interface PDFColumn {
/** Cell text. */
text: boolean | number | string;
/** Horizontal alignment of the text inside the cell. */
align?: "center" | "left" | "right";
/** Background color of the cell. */
backgroundColor?: string;
/** The colors of the border. */
borderColor?: PDFBorderColor;
/** Width of the borders of the row. */
borderWidth?: PDFBorderWidth;
/** Font of the text inside the cell. */
fontName?: string;
/** Font size of the text inside the cell. */
fontSize?: number;
/** Cell padding of the table cell. */
padding?: PDFPadding;
/** Text color of texts inside the cell. */
textColor?: string;
/** Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). */
textOptions?: PDFKit.Mixins.TextOptions;
/** Vertical alignment of the text inside the cell. */
verticalAlign?: "bottom" | "center" | "top";
/** Width of the cell. */
width?: number;
}
/** Can be used to set the color of the border of a table, row or column. */
export type PDFBorderColor = string | [top?: string, right?: string, bottom?: string, left?: string] | [vertical?: string, horizontal?: string];
/** Can be used to set the width of the border of a table, row or column. */
export type PDFBorderWidth = number | [top?: number, right?: number, bottom?: number, left?: number] | [vertical?: number, horizontal?: number];
/** Can be used to set the padding of a table cell. */
export type PDFPadding = number | [top?: number, right?: number, bottom?: number, left?: number] | [vertical?: number, horizontal?: number];
/**
* The Table class is used to create tables for PDFKit documents. A table can be attached to any PDFKit document instance
* using the {@link Table.attachTo} method.
*
* @example
* ```ts
* const tableData = {
* rows: [
* {
* backgroundColor: "#ECF0F1",
* columns: [
* {
* text: "Row 1 cell 1"
* }, {
* text: "Row 1 cell 2"
* }, {
* text: "Row 1 cell 3"
* }
* ]
* }, {
* columns: [
* {
* text: "Row 2 cell 1"
* }, {
* text: "Row 2 cell 2"
* }, {
* text: "Row 2 cell 3"
* }
* ]
* }
* ]
* };
* const pdf = new PDFDocument();
* const table = new Table(tableData);
*
* const stream = createWriteStream("table.pdf");
*
* table.attachTo(pdf);
* pdf.pipe(stream);
* pdf.end();
* ```
*/
export declare class Table {
private data;
/**
* Creates a new Table instance.
*
* @param data The rows and columns for the table.
* @returns The Table instance.
*/
constructor(data: PDFTable);
private getCurrentPage;
/**
* Attaches the table to a PDFKit document instance beginning on the current page. It will create a new page with for
* every row that no longer fits on a page.
*
* @param doc The PDFKit document instance.
* @param x The horizontal position in points where the table be placed.
* @param y The vertical position in points where the table will be placed.
* @throws { Error } Throws an error if no table rows are provided.
*/
attachTo(doc: PDFKit.PDFDocument, x?: number, y?: number): void;
private _positionsToObject;
}