Socket
Socket
Sign inDemoInstall

swissqrbill

Package Overview
Dependencies
69
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.0-alpha.14 to 4.0.0-alpha.15

lib/pdf/index.cjs

38

lib/pdf/swissqrbill.d.ts
/// <reference types="pdfkit" />
import type { Data, QRBillOptions } from '../shared/types';
import type { Data, PDFOptions } from '../shared/types';
/**
* The QRBill class creates the Payment Part with the QR Code. It can be attached to any PDFKit document instance
* 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.

@@ -13,14 +13,35 @@ */

private language;
private size;
private font;
private _x;
private _y;
constructor(data: Data, options?: QRBillOptions);
/**
* Adds the QR Slip to the bottom of the current page if there is enough space, otherwise it will create a new page with the specified size and add it to the bottom of this page.
* 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.
*/
constructor(data: Data, options?: PDFOptions);
/**
* Adds the QR Bill to the bottom of the current page if there is enough space,
* otherwise it will create a new page for the QR Bill.
* @param doc The PDFKit instance
* @param xPosition The x position where the QR Bill will be placed.
* @param yPosition The y position where the QR Bill will be placed.
* @param xPosition The horizontal position where the QR Bill will be placed.
* @param yPosition The vertical position where the QR Bill will be placed.
*/
attachTo(doc: PDFKit.PDFDocument, xPosition?: number, yPosition?: number): void;
private getNewPageSize;
/**
* Checks whether there is enough space on the current page to add the QR Bill.
* @param doc The PDFKit document instance
* @param xPosition The horizontal position where the QR Bill will be placed.
* @param yPosition The vertical position where the QR Bill will be placed.
* @returns `true` if there is enough space, otherwise `false`.
*/
static isSpaceSufficient(doc: PDFKit.PDFDocument, xPosition: number, yPosition: 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;

@@ -31,3 +52,2 @@ private y;

private addRectangle;
private isSpaceSufficient;
}

@@ -20,8 +20,13 @@ var __defProp = Object.defineProperty;

var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
import { SwissQRCode } from "./swissqrcode.js";
import { cleanData } from "../shared/cleaner.js";
import { generateQRData, renderQRCode } from "../shared/qr-code.js";
import { translations } from "../shared/translations.js";
import { validateData } from "../shared/validator.js";
import { mm2pt, formatIBAN, formatReference, pt2mm, formatAmount, getReferenceType } from "../shared/utils.js";
import { validateData } from "../shared/validator.js";
class SwissQRBill {
const _SwissQRBill = class _SwissQRBill2 {
/**
* 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.
*/
constructor(data, options) {

@@ -32,2 +37,3 @@ this.scissors = true;

this.language = "DE";
this.font = "Helvetica";
this._x = 0;

@@ -38,40 +44,30 @@ this._y = 0;

void validateData(this.data);
if (options !== void 0) {
if (options.language !== void 0) {
this.language = options.language;
}
if (options.scissors !== void 0) {
this.scissors = options.scissors;
this.separate = !options.scissors;
}
if (options.separate !== void 0) {
this.separate = options.separate;
this.scissors = !options.separate;
}
if (options.size !== void 0) {
this.size = options.size;
}
if (options.scissors === false && options.separate === false) {
this.separate = false;
this.scissors = false;
}
if (options.outlines !== void 0) {
this.outlines = options.outlines;
}
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.font) !== void 0 ? options.font : 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;
}
}
/**
* Adds the QR Slip to the bottom of the current page if there is enough space, otherwise it will create a new page with the specified size and add it to the bottom of this page.
* Adds the QR Bill to the bottom of the current page if there is enough space,
* otherwise it will create a new page for the QR Bill.
* @param doc The PDFKit instance
* @param xPosition The x position where the QR Bill will be placed.
* @param yPosition The y position where the QR Bill will be placed.
* @param xPosition The horizontal position where the QR Bill will be placed.
* @param yPosition The vertical position where the QR Bill will be placed.
*/
attachTo(doc, xPosition = 0, yPosition = doc.page.height - mm2pt(105)) {
const width = mm2pt(210);
const height = mm2pt(105);
if (!this.isSpaceSufficient(doc, xPosition, yPosition, width, height)) {
if (!_SwissQRBill2.isSpaceSufficient(doc, xPosition, yPosition)) {
doc.addPage({
layout: this.size === "A6/5" ? "landscape" : void 0,
margin: 0,
size: this.getNewPageSize(doc)
size: [_SwissQRBill2.width, _SwissQRBill2.height]
});

@@ -85,9 +81,14 @@ xPosition = 0;

}
getNewPageSize(doc) {
const minWidth = mm2pt(210);
const minHeight = mm2pt(105);
if (this.size !== "A6/5" && doc.page.width >= minWidth && doc.page.height >= minHeight) {
return [doc.page.width, doc.page.height];
/**
* Checks whether there is enough space on the current page to add the QR Bill.
* @param doc The PDFKit document instance
* @param xPosition The horizontal position where the QR Bill will be placed.
* @param yPosition The vertical position where the QR Bill will be placed.
* @returns `true` if there is enough space, otherwise `false`.
*/
static isSpaceSufficient(doc, xPosition, yPosition) {
if (!doc.page) {
return false;
}
return [minWidth, minHeight];
return Math.round(xPosition + _SwissQRBill2.width) <= Math.round(doc.page.width) && Math.round(doc.y + _SwissQRBill2.height) <= Math.round(doc.page.height) && Math.round(yPosition + _SwissQRBill2.height) <= Math.round(doc.page.height);
}

@@ -124,3 +125,3 @@ x(millimeters = 0) {

doc.fontSize(11);
doc.font("Helvetica");
doc.font(this.font);
doc.text(translations[this.language].separate, 0, this.y() - 12, {

@@ -133,3 +134,3 @@ align: "center",

doc.fontSize(11);
doc.font("Helvetica-Bold");
doc.font(`${this.font}-Bold`);
doc.text(translations[this.language].receipt, this.x(5), this.y(5), {

@@ -140,3 +141,3 @@ align: "left",

doc.fontSize(6);
doc.font("Helvetica-Bold");
doc.font(`${this.font}-Bold`);
doc.text(translations[this.language].account, this.x(5), this.y(12), {

@@ -147,3 +148,3 @@ lineGap: 1,

doc.fontSize(8);
doc.font("Helvetica");
doc.font(this.font);
doc.text(`${formatIBAN(this.data.creditor.account)}

@@ -158,3 +159,3 @@ ${this.formatAddress(this.data.creditor)}`, {

doc.fontSize(6);
doc.font("Helvetica-Bold");
doc.font(`${this.font}-Bold`);
doc.text(translations[this.language].reference, {

@@ -165,3 +166,3 @@ lineGap: 1,

doc.fontSize(8);
doc.font("Helvetica");
doc.font(this.font);
doc.text(formatReference(this.data.reference), {

@@ -176,3 +177,3 @@ lineGap: -0.5,

doc.fontSize(6);
doc.font("Helvetica-Bold");
doc.font(`${this.font}-Bold`);
doc.text(translations[this.language].payableBy, {

@@ -183,3 +184,3 @@ lineGap: 1,

doc.fontSize(8);
doc.font("Helvetica");
doc.font(this.font);
doc.text(this.formatAddress(this.data.debtor), {

@@ -191,3 +192,3 @@ lineGap: -0.5,

doc.fontSize(6);
doc.font("Helvetica-Bold");
doc.font(`${this.font}-Bold`);
doc.text(translations[this.language].payableByName, {

@@ -200,3 +201,3 @@ lineGap: 1,

doc.fontSize(6);
doc.font("Helvetica-Bold");
doc.font(`${this.font}-Bold`);
doc.text(translations[this.language].currency, this.x(5), this.y(68), {

@@ -212,3 +213,3 @@ lineGap: 1,

doc.fontSize(8);
doc.font("Helvetica");
doc.font(this.font);
doc.text(this.data.currency, this.x(5), this.y(71), {

@@ -227,3 +228,3 @@ lineGap: -0.5,

doc.fontSize(6);
doc.font("Helvetica-Bold");
doc.font(`${this.font}-Bold`);
doc.text(translations[this.language].acceptancePoint, this.x(5), this.y(82), {

@@ -236,3 +237,3 @@ align: "right",

doc.fontSize(11);
doc.font("Helvetica-Bold");
doc.font(`${this.font}-Bold`);
doc.text(translations[this.language].paymentPart, this.x(67), this.y(5), {

@@ -243,23 +244,9 @@ align: "left",

});
const qrData = generateQRData(this.data);
const qrCode = renderQRCode(qrData, "pdf", mm2pt(46));
const swissQRCode = new SwissQRCode(this.data);
doc.save();
doc.translate(this.x(67), this.y(17));
doc.addContent(qrCode);
doc.fillColor("black");
doc.fill();
swissQRCode.attachTo(doc);
doc.restore();
const swissCrossBackground = "18.3 0.7 m 1.6 0.7 l 0.7 0.7 l 0.7 1.6 l 0.7 18.3 l 0.7 19.1 l 1.6 19.1 l 18.3 19.1 l 19.1 19.1 l 19.1 18.3 l 19.1 1.6 l 19.1 0.7 l h";
const swissCross = "8.3 4 m 11.6 4 l 11.6 15 l 8.3 15 l 8.3 4 l h 4.4 7.9 m 15.4 7.9 l 15.4 11.2 l 4.4 11.2 l 4.4 7.9 l h";
doc.save();
doc.translate(this.x(86.5), this.y(36));
doc.addContent(swissCrossBackground).undash().fillColor("black").lineWidth(1.42).strokeColor("white").fillAndStroke();
doc.restore();
doc.save();
doc.translate(this.x(86.5), this.y(36));
doc.addContent(swissCross).fillColor("white").fill();
doc.restore();
doc.fillColor("black");
doc.fontSize(8);
doc.font("Helvetica-Bold");
doc.font(`${this.font}-Bold`);
doc.text(translations[this.language].currency, this.x(67), this.y(68), {

@@ -273,3 +260,3 @@ lineGap: 1,

doc.fontSize(10);
doc.font("Helvetica");
doc.font(this.font);
doc.text(this.data.currency, this.x(67), this.y(72), {

@@ -290,3 +277,3 @@ lineGap: -0.5,

doc.fontSize(7);
doc.font("Helvetica-Bold");
doc.font(`${this.font}-Bold`);
doc.text(scheme, this.x(67), this.y(90), {

@@ -298,3 +285,3 @@ continued: true,

});
doc.font("Helvetica");
doc.font(this.font);
doc.text(this.data.av1.length > 90 ? `${data.substring(0, 87)}...` : data, {

@@ -307,3 +294,3 @@ continued: false

doc.fontSize(7);
doc.font("Helvetica-Bold");
doc.font(`${this.font}-Bold`);
doc.text(scheme, this.x(67), this.y(93), {

@@ -315,3 +302,3 @@ continued: true,

});
doc.font("Helvetica");
doc.font(this.font);
doc.text(this.data.av2.length > 90 ? `${data.substring(0, 87)}...` : data, {

@@ -322,3 +309,3 @@ lineGap: -0.5

doc.fontSize(8);
doc.font("Helvetica-Bold");
doc.font(`${this.font}-Bold`);
doc.text(translations[this.language].account, this.x(118), this.y(5), {

@@ -329,3 +316,3 @@ lineGap: 1,

doc.fontSize(10);
doc.font("Helvetica");
doc.font(this.font);
doc.text(`${formatIBAN(this.data.creditor.account)}

@@ -340,3 +327,3 @@ ${this.formatAddress(this.data.creditor)}`, {

doc.fontSize(8);
doc.font("Helvetica-Bold");
doc.font(`${this.font}-Bold`);
doc.text(translations[this.language].reference, {

@@ -347,3 +334,3 @@ lineGap: 1,

doc.fontSize(10);
doc.font("Helvetica");
doc.font(this.font);
doc.text(formatReference(this.data.reference), {

@@ -358,3 +345,3 @@ lineGap: -0.75,

doc.fontSize(8);
doc.font("Helvetica-Bold");
doc.font(`${this.font}-Bold`);
doc.text(translations[this.language].additionalInformation, {

@@ -365,3 +352,3 @@ lineGap: 1,

doc.fontSize(10);
doc.font("Helvetica");
doc.font(this.font);
const options = {

@@ -395,3 +382,3 @@ lineGap: -0.75,

doc.fontSize(8);
doc.font("Helvetica-Bold");
doc.font(`${this.font}-Bold`);
doc.text(translations[this.language].payableBy, {

@@ -402,3 +389,3 @@ lineGap: 1,

doc.fontSize(10);
doc.font("Helvetica");
doc.font(this.font);
doc.text(this.formatAddress(this.data.debtor), {

@@ -410,3 +397,3 @@ lineGap: -0.75,

doc.fontSize(8);
doc.font("Helvetica-Bold");
doc.font(`${this.font}-Bold`);
doc.text(translations[this.language].payableByName, {

@@ -434,11 +421,8 @@ lineGap: 1,

}
isSpaceSufficient(doc, xPosition, yPosition, width, height) {
if (!doc.page) {
return false;
}
return Math.round(xPosition + width) <= Math.round(doc.page.width) && Math.round(doc.y + height) <= Math.round(doc.page.height) && Math.round(yPosition + height) <= Math.round(doc.page.height);
}
}
};
_SwissQRBill.width = mm2pt(210);
_SwissQRBill.height = mm2pt(105);
let SwissQRBill = _SwissQRBill;
export {
SwissQRBill
};

@@ -101,2 +101,3 @@ /// <reference types="pdfkit" />

* {
* backgroundColor: "#ECF0F1",
* columns: [

@@ -110,4 +111,3 @@ * {

* }
* ],
* backgroundColor: "#ECF0F1"
* ]
* }, {

@@ -114,0 +114,0 @@ * columns: [

@@ -38,2 +38,3 @@ var __defProp = Object.defineProperty;

* {
* backgroundColor: "#ECF0F1",
* columns: [

@@ -47,4 +48,3 @@ * {

* }
* ],
* backgroundColor: "#ECF0F1"
* ]
* }, {

@@ -51,0 +51,0 @@ * columns: [

import type { Data } from "./types";
export declare function generateQRData(data: Data): string;
export declare function renderQRCode(qrData: string, type: "pdf" | "svg", size: number, xOrigin?: number, yOrigin?: number): string;
export declare function renderQRCode(data: Data, size: number, renderBlockFunction: (x: number, y: number, blockSize: number) => void): void;
export declare function renderSwissCross(size: number, renderRectFunction: (x: number, y: number, width: number, height: number, fillColor: string) => void): void;

@@ -1,7 +0,11 @@

import { getReferenceType } from "./utils.js";
import { cleanData } from "./cleaner.js";
import { validateData } from "./validator.js";
import { getReferenceType, mm2pt } from "./utils.js";
import { qrcodegen } from "./qr-code-generator.js";
function generateQRData(data) {
var _a, _b, _c, _d, _e, _f, _g;
const amount = (_a = data.amount) == null ? void 0 : _a.toFixed(2);
const reference = getReferenceType(data.reference);
const cleanedData = cleanData(data);
void validateData(cleanedData);
const amount = (_a = cleanedData.amount) == null ? void 0 : _a.toFixed(2);
const reference = getReferenceType(cleanedData.reference);
const qrData = [

@@ -14,16 +18,16 @@ "SPC",

// Coding Type UTF-8
(_b = data.creditor.account) != null ? _b : "",
(_b = cleanedData.creditor.account) != null ? _b : "",
// IBAN
...data.creditor.buildingNumber ? [
...cleanedData.creditor.buildingNumber ? [
"S",
// Address Type
data.creditor.name,
cleanedData.creditor.name,
// Name
data.creditor.address,
cleanedData.creditor.address,
// Address
`${data.creditor.buildingNumber}`,
`${cleanedData.creditor.buildingNumber}`,
// Building number
`${data.creditor.zip}`,
`${cleanedData.creditor.zip}`,
// Zip
data.creditor.city
cleanedData.creditor.city
// City

@@ -33,7 +37,7 @@ ] : [

// Address Type
data.creditor.name,
cleanedData.creditor.name,
// Name
data.creditor.address,
cleanedData.creditor.address,
// Address
`${data.creditor.zip} ${data.creditor.city}`,
`${cleanedData.creditor.zip} ${cleanedData.creditor.city}`,
// Zip and city

@@ -45,3 +49,3 @@ "",

],
data.creditor.country,
cleanedData.creditor.country,
// Country

@@ -64,17 +68,17 @@ "",

// Amount
data.currency,
cleanedData.currency,
// Currency
...data.debtor ? [
...data.debtor.buildingNumber ? [
...cleanedData.debtor ? [
...cleanedData.debtor.buildingNumber ? [
"S",
// Address Type
data.debtor.name,
cleanedData.debtor.name,
// Name
data.debtor.address,
cleanedData.debtor.address,
// Address
`${data.debtor.buildingNumber}`,
`${cleanedData.debtor.buildingNumber}`,
// Building number
`${data.debtor.zip}`,
`${cleanedData.debtor.zip}`,
// Zip
data.debtor.city
cleanedData.debtor.city
// City

@@ -84,7 +88,7 @@ ] : [

// Address Type
data.debtor.name,
cleanedData.debtor.name,
// Name
data.debtor.address,
cleanedData.debtor.address,
// Address
`${data.debtor.zip} ${data.debtor.city}`,
`${cleanedData.debtor.zip} ${cleanedData.debtor.city}`,
// Zip and city

@@ -96,3 +100,3 @@ "",

],
(_d = (_c = data.debtor) == null ? void 0 : _c.country) != null ? _d : ""
(_d = (_c = cleanedData.debtor) == null ? void 0 : _c.country) != null ? _d : ""
// Country

@@ -117,15 +121,15 @@ ] : [

// Reference type
(_e = data.reference) != null ? _e : "",
(_e = cleanedData.reference) != null ? _e : "",
// Reference
(_f = data.message) != null ? _f : "",
(_f = cleanedData.message) != null ? _f : "",
// Unstructured message
"EPD",
// End of payment data
(_g = data.additionalInformation) != null ? _g : "",
(_g = cleanedData.additionalInformation) != null ? _g : "",
// Additional information
...data.av1 ? [
data.av1
...cleanedData.av1 ? [
cleanedData.av1
] : [],
...data.av2 ? [
data.av2
...cleanedData.av2 ? [
cleanedData.av2
] : []

@@ -135,3 +139,4 @@ ];

}
function renderQRCode(qrData, type, size, xOrigin = 0, yOrigin = 0) {
function renderQRCode(data, size, renderBlockFunction) {
const qrData = generateQRData(data);
const eci = qrcodegen.QrSegment.makeEci(26);

@@ -141,3 +146,2 @@ const segments = qrcodegen.QrSegment.makeSegments(qrData);

const blockSize = size / qrCode.size;
const parts = [];
for (let x = 0; x < qrCode.size; x++) {

@@ -148,19 +152,46 @@ const xPos = x * blockSize;

if (qrCode.getModule(x, y)) {
parts.push(
type === "pdf" ? `${limitNumber(xOrigin + xPos)} ${limitNumber(yOrigin + yPos)} ${limitNumber(blockSize)} ${limitNumber(blockSize)} re` : `M ${xPos}, ${yPos} V ${yPos + blockSize} H ${xPos + blockSize} V ${yPos} H ${xPos} Z `
);
renderBlockFunction(xPos, yPos, blockSize);
}
}
}
return parts.join(" ");
}
function limitNumber(n) {
if (n > -1e21 && n < 1e21) {
return Math.round(n * 1e6) / 1e6;
}
throw new RangeError(`unsupported number: ${n}`);
function renderSwissCross(size, renderRectFunction) {
const scale = size / mm2pt(46);
const swissCrossWhiteBackgroundSize = mm2pt(7) * scale;
const swissCrossBlackBackgroundSize = mm2pt(6) * scale;
const swissCrossThickness = mm2pt(1.17) * scale;
const swissCrossLength = mm2pt(3.89) * scale;
void renderRectFunction(
size / 2 - swissCrossWhiteBackgroundSize / 2,
size / 2 - swissCrossWhiteBackgroundSize / 2,
swissCrossWhiteBackgroundSize,
swissCrossWhiteBackgroundSize,
"white"
);
void renderRectFunction(
size / 2 - swissCrossBlackBackgroundSize / 2,
size / 2 - swissCrossBlackBackgroundSize / 2,
swissCrossBlackBackgroundSize,
swissCrossBlackBackgroundSize,
"black"
);
void renderRectFunction(
size / 2 - swissCrossLength / 2,
size / 2 - swissCrossThickness / 2,
swissCrossLength,
swissCrossThickness,
"white"
);
void renderRectFunction(
size / 2 - swissCrossThickness / 2,
size / 2 - swissCrossLength / 2,
swissCrossThickness,
swissCrossLength,
"white"
);
}
export {
generateQRData,
renderQRCode
renderQRCode,
renderSwissCross
};
export type Currency = "CHF" | "EUR";
export type Size = "A4" | "A6" | "A6/5";
export type Languages = "DE" | "EN" | "FR" | "IT";
export type Language = "DE" | "EN" | "FR" | "IT";
export type FontName = "Arial" | "Frutiger" | "Helvetica" | "Liberation Sans";
export interface Data {

@@ -87,6 +88,12 @@ /**

/**
* Font used for the QR-Bill.
* Fonts other than Helvetica must be registered in the PDFKit document. {@link http://pdfkit.org/docs/text.html#fonts}
* @defaultValue 'Helvetica'
*/
font?: FontName;
/**
* The language with which the bill is rendered.
* @defaultValue `DE`
*/
language?: Languages;
language?: Language;
/**

@@ -104,2 +111,4 @@ * Whether you want render the outlines. This option may be disabled if you use perforated paper.

scissors?: boolean;
}
export interface PDFOptions extends QRBillOptions {
/**

@@ -112,21 +121,4 @@ * Whether you want to show the text `Separate before paying in` rather than the scissors icons.

separate?: boolean;
/**
* The page size.
* @defaultValue `"A6"`
*/
size?: Size;
}
export interface PDFOptions extends QRBillOptions {
/**
* Whether you want to automatically finalize the PDF. When set to false you are able to add your own content to the PDF using PDFKit.
* @defaultValue `true`
*/
autoGenerate?: boolean;
export interface SVGOptions extends QRBillOptions {
}
export interface SVGOptions {
/**
* The language with which the bill is rendered.
* @defaultValue `DE`
*/
language?: Languages;
}

@@ -5,4 +5,7 @@ import { SVG } from "svg-engine";

protected instance: SVG;
private _data;
private _language;
private scissors;
private outlines;
private language;
private font;
private data;
constructor(data: Data, options?: SVGOptions);

@@ -9,0 +12,0 @@ get outerHTML(): string;

import { SVG, calc } from "svg-engine";
import { cleanData } from "../shared/cleaner.js";
import { generateQRData, renderQRCode } from "../shared/qr-code.js";
import { translations } from "../shared/translations.js";
import { validateData } from "../shared/validator.js";
import { calculateTextWidth } from "./characterWidth.js";
import { calculateTextWidth } from "./character-width.js";
import { SwissQRCode } from "./swissqrcode.js";
import { formatIBAN, mm2px, formatReference, formatAmount, getReferenceType } from "../shared/utils.js";
class SwissQRBill {
constructor(data, options) {
this._language = "DE";
this._data = data;
this._data = cleanData(this._data);
validateData(this._data);
if (options !== void 0) {
if (options.language !== void 0) {
this._language = options.language;
}
}
this.scissors = true;
this.outlines = true;
this.language = "DE";
this.font = "Arial";
this.data = data;
this.data = cleanData(this.data);
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.font) !== void 0 ? options.font : this.font;
this.scissors = (options == null ? void 0 : options.scissors) !== void 0 ? options.scissors : this.scissors;
this.instance = new SVG();

@@ -43,15 +45,19 @@ this.instance.width("210mm");

_render() {
const formattedCreditorAddress = this._formatAddress(this._data.creditor);
const formattedCreditorAddress = this._formatAddress(this.data.creditor);
let receiptLineCount = 0;
let paymentPartLineCount = 0;
this.instance.addRect(0, 0, "100%", "100%").fill("#fff");
this.instance.addLine("62mm", "0mm", "62mm", "105mm").stroke(1, "dashed", "black");
const scissorsCenter = "M8.55299 18.3969C9.54465 17.5748 9.51074 16.0915 9.08357 14.9829L6.47473 8.02261C7.58167 5.9986 7.26467 3.99833 7.80373 3.99833C8.22582 3.99833 8.13259 4.38482 9.23105 4.32719C10.2854 4.27125 11.0652 3.1711 10.9957 2.13197C11.0025 1.09115 10.2041 0.0130391 9.1056 0.00456339C7.99867 -0.0734135 6.96972 0.858918 6.89683 1.95907C6.70527 3.24907 7.48674 5.53413 5.56613 6.60547C4.09305 5.80705 4.08797 4.38991 4.16255 3.10838C4.22358 2.04552 3.91845 0.76738 2.87424 0.260531C1.87241 -0.229367 0.446794 0.25036 0.139972 1.37594C-0.277034 2.51168 0.250156 4.07122 1.55541 4.34244C2.56233 4.55095 3.03528 3.83729 3.40143 4.1119C3.67774 4.31871 3.5167 5.62906 4.566 7.96667L1.908 15.5033C1.64356 16.456 1.65204 17.6206 2.58776 18.463L5.5424 10.6484L8.55299 18.3969ZM10.1634 2.87953C9.55143 3.97629 7.88849 3.88645 7.56641 2.74731C7.20704 1.71666 8.20887 0.397838 9.32767 0.726697C10.2447 0.919943 10.5821 2.12858 10.1634 2.87953ZM3.36753 2.927C2.94544 4.07122 1.00789 3.87797 0.746835 2.71341C0.479001 1.94042 0.8638 0.836881 1.77409 0.758904C2.88102 0.608036 3.87946 1.90821 3.36753 2.927Z";
const scissorsSVG = this.instance.addSVG("11px", "19px").x(calc("62mm - 5.25px")).y("30pt");
scissorsSVG.addPath(scissorsCenter).fill("black");
if (this.outlines) {
this.instance.addLine("62mm", "0mm", "62mm", "105mm").stroke(1, "dashed", "black");
}
if (this.scissors) {
const scissorsCenter = "M8.55299 18.3969C9.54465 17.5748 9.51074 16.0915 9.08357 14.9829L6.47473 8.02261C7.58167 5.9986 7.26467 3.99833 7.80373 3.99833C8.22582 3.99833 8.13259 4.38482 9.23105 4.32719C10.2854 4.27125 11.0652 3.1711 10.9957 2.13197C11.0025 1.09115 10.2041 0.0130391 9.1056 0.00456339C7.99867 -0.0734135 6.96972 0.858918 6.89683 1.95907C6.70527 3.24907 7.48674 5.53413 5.56613 6.60547C4.09305 5.80705 4.08797 4.38991 4.16255 3.10838C4.22358 2.04552 3.91845 0.76738 2.87424 0.260531C1.87241 -0.229367 0.446794 0.25036 0.139972 1.37594C-0.277034 2.51168 0.250156 4.07122 1.55541 4.34244C2.56233 4.55095 3.03528 3.83729 3.40143 4.1119C3.67774 4.31871 3.5167 5.62906 4.566 7.96667L1.908 15.5033C1.64356 16.456 1.65204 17.6206 2.58776 18.463L5.5424 10.6484L8.55299 18.3969ZM10.1634 2.87953C9.55143 3.97629 7.88849 3.88645 7.56641 2.74731C7.20704 1.71666 8.20887 0.397838 9.32767 0.726697C10.2447 0.919943 10.5821 2.12858 10.1634 2.87953ZM3.36753 2.927C2.94544 4.07122 1.00789 3.87797 0.746835 2.71341C0.479001 1.94042 0.8638 0.836881 1.77409 0.758904C2.88102 0.608036 3.87946 1.90821 3.36753 2.927Z";
const scissorsSVG = this.instance.addSVG("11px", "19px").x(calc("62mm - 5.25px")).y("30pt");
scissorsSVG.addPath(scissorsCenter).fill("black");
}
const receiptContainer = this.instance.addSVG().x("5mm").y("5mm");
const receiptTextContainer = receiptContainer.addText();
receiptTextContainer.addTSpan(translations[this._language].receipt).x(0).y(0).dy("11pt").fontFamily("Arial").fontWeight("bold").fontSize("11pt");
receiptTextContainer.addTSpan(translations[this._language].account).x(0).y("7mm").dy("9pt").fontFamily("Arial").fontWeight("bold").fontSize("6pt");
receiptTextContainer.addTSpan(formatIBAN(this._data.creditor.account)).x(0).dy("9pt").fontFamily("Arial").fontWeight("normal").fontSize("8pt");
receiptTextContainer.addTSpan(translations[this.language].receipt).x(0).y(0).dy("11pt").fontFamily(this.font).fontWeight("bold").fontSize("11pt");
receiptTextContainer.addTSpan(translations[this.language].account).x(0).y("7mm").dy("9pt").fontFamily(this.font).fontWeight("bold").fontSize("6pt");
receiptTextContainer.addTSpan(formatIBAN(this.data.creditor.account)).x(0).dy("9pt").fontFamily(this.font).fontWeight("normal").fontSize("8pt");
receiptLineCount++;

@@ -65,12 +71,12 @@ let receiptCreditorAddressLines = [];

receiptLineCount++;
receiptTextContainer.addTSpan(line).x(0).dy("9pt").fontFamily("Arial").fontWeight("normal").fontSize("8pt");
receiptTextContainer.addTSpan(line).x(0).dy("9pt").fontFamily(this.font).fontWeight("normal").fontSize("8pt");
}
if (this._data.reference !== void 0) {
receiptTextContainer.addTSpan(translations[this._language].reference).x(0).dy("18pt").fontFamily("Arial").fontWeight("bold").fontSize("6pt");
receiptTextContainer.addTSpan(formatReference(this._data.reference)).x(0).dy("9pt").fontFamily("Arial").fontWeight("normal").fontSize("8pt");
if (this.data.reference !== void 0) {
receiptTextContainer.addTSpan(translations[this.language].reference).x(0).dy("18pt").fontFamily(this.font).fontWeight("bold").fontSize("6pt");
receiptTextContainer.addTSpan(formatReference(this.data.reference)).x(0).dy("9pt").fontFamily(this.font).fontWeight("normal").fontSize("8pt");
receiptLineCount++;
}
if (this._data.debtor !== void 0) {
const formattedDebtorAddress = this._formatAddress(this._data.debtor);
receiptTextContainer.addTSpan(translations[this._language].payableBy).x(0).dy("18pt").fontFamily("Arial").fontWeight("bold").fontSize("6pt");
if (this.data.debtor !== void 0) {
const formattedDebtorAddress = this._formatAddress(this.data.debtor);
receiptTextContainer.addTSpan(translations[this.language].payableBy).x(0).dy("18pt").fontFamily(this.font).fontWeight("bold").fontSize("6pt");
let receiptDebtorAddressLines = [];

@@ -82,29 +88,29 @@ for (const line of formattedDebtorAddress) {

for (const line of receiptDebtorAddressLines) {
receiptTextContainer.addTSpan(line).x(0).dy("9pt").fontFamily("Arial").fontWeight("normal").fontSize("8pt");
receiptTextContainer.addTSpan(line).x(0).dy("9pt").fontFamily(this.font).fontWeight("normal").fontSize("8pt");
}
} else {
receiptTextContainer.addTSpan(translations[this._language].payableByName).x(0).dy("18pt").fontFamily("Arial").fontWeight("bold").fontSize("6pt");
const referenceHeight = this._data.reference !== void 0 ? "18pt" : "0";
receiptTextContainer.addTSpan(translations[this.language].payableByName).x(0).dy("18pt").fontFamily(this.font).fontWeight("bold").fontSize("6pt");
const referenceHeight = this.data.reference !== void 0 ? "18pt" : "0";
this._addRectangle(5, calc(`12mm + 9pt + (${receiptLineCount} * 9pt) + ${referenceHeight} + 18pt + 1mm`, "mm"), 52, 20);
}
const amountContainer = receiptContainer.addText().y("63mm");
amountContainer.addTSpan(translations[this._language].currency).x(0).dy("6pt").fontFamily("Arial").fontWeight("bold").fontSize("6pt");
const amountXPosition = this._data.amount === void 0 ? 13 : 22;
amountContainer.addTSpan(translations[this._language].amount).x(`${amountXPosition}mm`).fontFamily("Arial").fontWeight("bold").fontSize("6pt");
amountContainer.addTSpan(this._data.currency).x(0).dy("11pt").fontFamily("Arial").fontWeight("normal").fontSize("8pt");
if (this._data.amount !== void 0) {
amountContainer.addTSpan(formatAmount(this._data.amount)).x(`${amountXPosition}mm`).fontFamily("Arial").fontWeight("normal").fontSize("8pt");
amountContainer.addTSpan(translations[this.language].currency).x(0).dy("6pt").fontFamily(this.font).fontWeight("bold").fontSize("6pt");
const amountXPosition = this.data.amount === void 0 ? 13 : 22;
amountContainer.addTSpan(translations[this.language].amount).x(`${amountXPosition}mm`).fontFamily(this.font).fontWeight("bold").fontSize("6pt");
amountContainer.addTSpan(this.data.currency).x(0).dy("11pt").fontFamily(this.font).fontWeight("normal").fontSize("8pt");
if (this.data.amount !== void 0) {
amountContainer.addTSpan(formatAmount(this.data.amount)).x(`${amountXPosition}mm`).fontFamily(this.font).fontWeight("normal").fontSize("8pt");
} else {
this._addRectangle(27, 68, 30, 10);
}
amountContainer.addTSpan(translations[this._language].acceptancePoint).x("52mm").y("82mm").textAlign("right").fontFamily("Arial").fontWeight("bold").fontSize("6pt");
amountContainer.addTSpan(translations[this.language].acceptancePoint).x("52mm").y("82mm").textAlign("right").fontFamily(this.font).fontWeight("bold").fontSize("6pt");
const paymentPartContainer = this.instance.addSVG().x("67mm").y("5mm");
paymentPartContainer.addText(translations[this._language].paymentPart).x(0).y(0).dy("11pt").fontFamily("Arial").fontWeight("bold").fontSize("11pt");
paymentPartContainer.addText(translations[this.language].paymentPart).x(0).y(0).dy("11pt").fontFamily(this.font).fontWeight("bold").fontSize("11pt");
this._renderQRCode();
const paymentPartMiddleTextContainer = paymentPartContainer.addText().y("63mm");
paymentPartMiddleTextContainer.addTSpan(translations[this._language].currency).x(0).dy("8pt").fontFamily("Arial").fontWeight("bold").fontSize("8pt");
paymentPartMiddleTextContainer.addTSpan(translations[this._language].amount).x("22mm").fontFamily("Arial").fontWeight("bold").fontSize("8pt");
paymentPartMiddleTextContainer.addTSpan(this._data.currency).x(0).dy("13pt").fontFamily("Arial").fontWeight("normal").fontSize("10pt");
if (this._data.amount !== void 0) {
paymentPartMiddleTextContainer.addTSpan(formatAmount(this._data.amount)).x("22mm").fontFamily("Arial").fontWeight("normal").fontSize("10pt");
paymentPartMiddleTextContainer.addTSpan(translations[this.language].currency).x(0).dy("8pt").fontFamily(this.font).fontWeight("bold").fontSize("8pt");
paymentPartMiddleTextContainer.addTSpan(translations[this.language].amount).x("22mm").fontFamily(this.font).fontWeight("bold").fontSize("8pt");
paymentPartMiddleTextContainer.addTSpan(this.data.currency).x(0).dy("13pt").fontFamily(this.font).fontWeight("normal").fontSize("10pt");
if (this.data.amount !== void 0) {
paymentPartMiddleTextContainer.addTSpan(formatAmount(this.data.amount)).x("22mm").fontFamily(this.font).fontWeight("normal").fontSize("10pt");
} else {

@@ -114,16 +120,16 @@ this._addRectangle(78, calc("68mm + 8pt + 5pt", "mm"), 40, 15);

const alternativeSchemeContainer = paymentPartContainer.addText().x(0).y("90mm");
if (this._data.av1 !== void 0) {
const [scheme, data] = this._data.av1.split(/(\/.+)/);
alternativeSchemeContainer.addTSpan(scheme).x(0).fontFamily("Arial").fontWeight("bold").fontSize("7pt");
alternativeSchemeContainer.addTSpan(this._data.av1.length > 90 ? `${data.substr(0, 87)}...` : data).fontFamily("Arial").fontWeight("normal").fontSize("7pt");
if (this.data.av1 !== void 0) {
const [scheme, data] = this.data.av1.split(/(\/.+)/);
alternativeSchemeContainer.addTSpan(scheme).x(0).fontFamily(this.font).fontWeight("bold").fontSize("7pt");
alternativeSchemeContainer.addTSpan(this.data.av1.length > 90 ? `${data.substr(0, 87)}...` : data).fontFamily(this.font).fontWeight("normal").fontSize("7pt");
}
if (this._data.av2 !== void 0) {
const [scheme, data] = this._data.av2.split(/(\/.+)/);
alternativeSchemeContainer.addTSpan(scheme).x(0).dy("8pt").fontFamily("Arial").fontWeight("bold").fontSize("7pt");
alternativeSchemeContainer.addTSpan(this._data.av2.length > 90 ? `${data.substr(0, 87)}...` : data).fontFamily("Arial").fontWeight("normal").fontSize("7pt");
if (this.data.av2 !== void 0) {
const [scheme, data] = this.data.av2.split(/(\/.+)/);
alternativeSchemeContainer.addTSpan(scheme).x(0).dy("8pt").fontFamily(this.font).fontWeight("bold").fontSize("7pt");
alternativeSchemeContainer.addTSpan(this.data.av2.length > 90 ? `${data.substr(0, 87)}...` : data).fontFamily(this.font).fontWeight("normal").fontSize("7pt");
}
const paymentPartDebtorContainer = this.instance.addSVG().x("118mm").y("5mm");
const paymentPartRightTextContainer = paymentPartDebtorContainer.addText();
paymentPartRightTextContainer.addTSpan(translations[this._language].account).x(0).y(0).dy("11pt").fontFamily("Arial").fontWeight("bold").fontSize("8pt");
paymentPartRightTextContainer.addTSpan(formatIBAN(this._data.creditor.account)).x(0).dy("11pt").fontFamily("Arial").fontWeight("normal").fontSize("10pt");
paymentPartRightTextContainer.addTSpan(translations[this.language].account).x(0).y(0).dy("11pt").fontFamily(this.font).fontWeight("bold").fontSize("8pt");
paymentPartRightTextContainer.addTSpan(formatIBAN(this.data.creditor.account)).x(0).dy("11pt").fontFamily(this.font).fontWeight("normal").fontSize("10pt");
paymentPartLineCount++;

@@ -136,29 +142,29 @@ let paymentPartCreditorAddressLines = [];

for (const line of paymentPartCreditorAddressLines) {
paymentPartRightTextContainer.addTSpan(line).x(0).dy("11pt").fontFamily("Arial").fontWeight("normal").fontSize("10pt");
paymentPartRightTextContainer.addTSpan(line).x(0).dy("11pt").fontFamily(this.font).fontWeight("normal").fontSize("10pt");
paymentPartLineCount++;
}
if (this._data.reference !== void 0) {
paymentPartRightTextContainer.addTSpan(translations[this._language].reference).x(0).dy("22pt").fontFamily("Arial").fontWeight("bold").fontSize("8pt");
paymentPartRightTextContainer.addTSpan(formatReference(this._data.reference)).x(0).dy("11pt").fontFamily("Arial").fontWeight("normal").fontSize("10pt");
if (this.data.reference !== void 0) {
paymentPartRightTextContainer.addTSpan(translations[this.language].reference).x(0).dy("22pt").fontFamily(this.font).fontWeight("bold").fontSize("8pt");
paymentPartRightTextContainer.addTSpan(formatReference(this.data.reference)).x(0).dy("11pt").fontFamily(this.font).fontWeight("normal").fontSize("10pt");
paymentPartLineCount++;
}
if (this._data.message !== void 0 || this._data.additionalInformation !== void 0) {
paymentPartRightTextContainer.addTSpan(translations[this._language].additionalInformation).x(0).dy("22pt").fontFamily("Arial").fontWeight("bold").fontSize("8pt");
const referenceType = getReferenceType(this._data.reference);
if (this.data.message !== void 0 || this.data.additionalInformation !== void 0) {
paymentPartRightTextContainer.addTSpan(translations[this.language].additionalInformation).x(0).dy("22pt").fontFamily(this.font).fontWeight("bold").fontSize("8pt");
const referenceType = getReferenceType(this.data.reference);
const maxLines = referenceType === "QRR" || referenceType === "SCOR" ? 3 : 4;
const lengthInPixel = mm2px(87);
this._getLineCountOfText(this._data.message, lengthInPixel, "10pt");
const linesOfAdditionalInformation = this._getLineCountOfText(this._data.additionalInformation, lengthInPixel, "10pt");
if (this._data.additionalInformation !== void 0) {
this._getLineCountOfText(this.data.message, lengthInPixel, "10pt");
const linesOfAdditionalInformation = this._getLineCountOfText(this.data.additionalInformation, lengthInPixel, "10pt");
if (this.data.additionalInformation !== void 0) {
if (referenceType === "QRR" || referenceType === "SCOR") {
if (this._data.message !== void 0) {
paymentPartRightTextContainer.addTSpan(this._ellipsis(this._data.message, lengthInPixel, "10pt")).x(0).dy("11pt").fontFamily("Arial").fontWeight("normal").fontSize("10pt");
if (this.data.message !== void 0) {
paymentPartRightTextContainer.addTSpan(this._ellipsis(this.data.message, lengthInPixel, "10pt")).x(0).dy("11pt").fontFamily(this.font).fontWeight("normal").fontSize("10pt");
paymentPartLineCount++;
}
} else {
if (this._data.message !== void 0) {
if (this.data.message !== void 0) {
const maxLinesOfMessage = maxLines - linesOfAdditionalInformation;
const messageLines = this._fitTextToWidth(this._data.message, lengthInPixel, maxLinesOfMessage, "10pt");
const messageLines = this._fitTextToWidth(this.data.message, lengthInPixel, maxLinesOfMessage, "10pt");
for (let i = 0; i < maxLinesOfMessage; i++) {
paymentPartRightTextContainer.addTSpan(messageLines[i]).x(0).dy("11pt").fontFamily("Arial").fontWeight("normal").fontSize("10pt");
paymentPartRightTextContainer.addTSpan(messageLines[i]).x(0).dy("11pt").fontFamily(this.font).fontWeight("normal").fontSize("10pt");
paymentPartLineCount++;

@@ -168,11 +174,11 @@ }

}
const additionalInformationLines = this._fitTextToWidth(this._data.additionalInformation, lengthInPixel, linesOfAdditionalInformation, "10pt");
const additionalInformationLines = this._fitTextToWidth(this.data.additionalInformation, lengthInPixel, linesOfAdditionalInformation, "10pt");
for (let i = 0; i < linesOfAdditionalInformation; i++) {
paymentPartRightTextContainer.addTSpan(additionalInformationLines[i]).x(0).dy("11pt").fontFamily("Arial").fontWeight("normal").fontSize("10pt");
paymentPartRightTextContainer.addTSpan(additionalInformationLines[i]).x(0).dy("11pt").fontFamily(this.font).fontWeight("normal").fontSize("10pt");
paymentPartLineCount++;
}
} else if (this._data.message !== void 0) {
const messageLines = this._fitTextToWidth(this._data.message, lengthInPixel, maxLines, "10pt");
} else if (this.data.message !== void 0) {
const messageLines = this._fitTextToWidth(this.data.message, lengthInPixel, maxLines, "10pt");
for (let i = 0; i < maxLines; i++) {
paymentPartRightTextContainer.addTSpan(messageLines[i]).x(0).dy("11pt").fontFamily("Arial").fontWeight("normal").fontSize("10pt");
paymentPartRightTextContainer.addTSpan(messageLines[i]).x(0).dy("11pt").fontFamily(this.font).fontWeight("normal").fontSize("10pt");
paymentPartLineCount++;

@@ -182,5 +188,5 @@ }

}
if (this._data.debtor !== void 0) {
const formattedDebtorAddress = this._formatAddress(this._data.debtor);
paymentPartRightTextContainer.addTSpan(translations[this._language].payableBy).x(0).dy("22pt").fontFamily("Arial").fontWeight("bold").fontSize("8pt");
if (this.data.debtor !== void 0) {
const formattedDebtorAddress = this._formatAddress(this.data.debtor);
paymentPartRightTextContainer.addTSpan(translations[this.language].payableBy).x(0).dy("22pt").fontFamily(this.font).fontWeight("bold").fontSize("8pt");
let paymentPartDebtorAddressLines = [];

@@ -192,8 +198,8 @@ for (const line of formattedDebtorAddress) {

for (const line of paymentPartDebtorAddressLines) {
paymentPartRightTextContainer.addTSpan(line).x(0).dy("11pt").fontFamily("Arial").fontWeight("normal").fontSize("10pt");
paymentPartRightTextContainer.addTSpan(line).x(0).dy("11pt").fontFamily(this.font).fontWeight("normal").fontSize("10pt");
}
} else {
paymentPartRightTextContainer.addTSpan(translations[this._language].payableByName).x(0).dy("22pt").fontFamily("Arial").fontWeight("bold").fontSize("8pt");
const referenceHeight = this._data.reference !== void 0 ? "22pt" : "0";
const additionalInformationHeight = this._data.additionalInformation !== void 0 || this._data.message !== void 0 ? "22pt" : "0";
paymentPartRightTextContainer.addTSpan(translations[this.language].payableByName).x(0).dy("22pt").fontFamily(this.font).fontWeight("bold").fontSize("8pt");
const referenceHeight = this.data.reference !== void 0 ? "22pt" : "0";
const additionalInformationHeight = this.data.additionalInformation !== void 0 || this.data.message !== void 0 ? "22pt" : "0";
this._addRectangle(118, calc(`5mm + 11pt + (${paymentPartLineCount} * 11pt) + ${referenceHeight} + ${additionalInformationHeight} + 22pt + 1mm`, "mm"), 65, 25);

@@ -203,10 +209,5 @@ }

_renderQRCode() {
const qrData = generateQRData(this._data);
const qrCode = renderQRCode(qrData, "svg", mm2px(46), 0, 0);
const qrCodeSVG = this.instance.addSVG("46mm", "46mm").y("17mm").x("67mm");
qrCodeSVG.addPath(qrCode).fill("black");
qrCodeSVG.addRect("19mm", "19mm", "8mm", "8mm").fill("white");
qrCodeSVG.addRect("19.5mm", "19.5mm", "7mm", "7mm").fill("black");
qrCodeSVG.addRect("22.415mm", "21.055mm", "1.17mm", "3.89mm").fill("white");
qrCodeSVG.addRect("21.055mm", "22.415mm", "3.89mm", "1.17mm").fill("white");
const qrCode = new SwissQRCode(this.data);
qrCode.x("67mm").y("17mm");
this.instance.appendInstance(qrCode);
}

@@ -213,0 +214,0 @@ _formatAddress(data) {

{
"version": "4.0.0-alpha.14",
"version": "4.0.0-alpha.15",
"type": "module",

@@ -19,4 +19,4 @@ "name": "swissqrbill",

"./bundle": {
"import": "./lib/bundle/swissqrbill.js",
"require": "./lib/bundle/swissqrbill.cjs"
"import": "./lib/bundle/index.js",
"require": "./lib/bundle/index.js"
},

@@ -28,13 +28,9 @@ "./errors": {

"./pdf": {
"import": "./lib/pdf/swissqrbill.js",
"require": "./lib/pdf/swissqrbill.cjs"
"import": "./lib/pdf/index.js",
"require": "./lib/pdf/index.cjs"
},
"./svg": {
"import": "./lib/svg/swissqrbill.js",
"require": "./lib/svg/swissqrbill.cjs"
"import": "./lib/svg/index.js",
"require": "./lib/svg/index.cjs"
},
"./table": {
"import": "./lib/pdf/table.js",
"require": "./lib/pdf/table.cjs"
},
"./types": {

@@ -49,10 +45,9 @@ "import": "./lib/shared/types.js",

},
"types": "./lib/shared/types.d.ts",
"scripts": {
"build": "rm -r ./lib || true && vite build --config vite.config.ts && vite build --config vite.config.bundle.ts",
"docs": "npm run docs:pdf && npm run docs:svg && npm run docs:table && npm run docs:shared",
"docs:pdf": "unwritten src/pdf/swissqrbill.ts src/shared/types.ts -t tsconfig.docs.json -o docs/pdf/",
"docs": "npm run docs:pdf && npm run docs:svg && npm run docs:shared && npm run docs:bundle",
"docs:bundle": "unwritten src/bundle/index.ts -t tsconfig.docs.json -o docs/bundle/ ",
"docs:pdf": "unwritten src/pdf/index.ts src/shared/types.ts -t tsconfig.docs.json -o docs/pdf/",
"docs:shared": "unwritten src/shared/utils.ts -t tsconfig.docs.json -o docs/utils/",
"docs:svg": "unwritten src/svg/swissqrbill.ts src/shared/types.ts -t tsconfig.docs.json -o docs/svg/",
"docs:table": "unwritten src/pdf/table.ts -t tsconfig.docs.json -o docs/table/",
"docs:svg": "unwritten src/svg/index.ts src/shared/types.ts -t tsconfig.docs.json -o docs/svg/",
"eslint": "eslint --ext .ts,.tsx,.js,.jsx,.json,.jsonc,.yml,.md ./",

@@ -67,14 +62,14 @@ "eslint:ci": "npm run eslint -- --max-warnings 0",

"markdownlint:fix": "markdownlint-cli2-fix '**/*.md' '#node_modules'",
"postrelease": "eslint --fix package.json && markdownlint-cli2-fix 'CHANGELOG.md'",
"postrelease:alpha": "npm run postrelease",
"postrelease:beta": "npm run postrelease",
"prerelease": "npm run test -- --run && npm run build",
"postrelease:latest": "eslint --fix package.json && markdownlint-cli2-fix 'CHANGELOG.md'",
"prerelease:alpha": "npm run test -- --run && npm run build",
"prerelease:beta": "npm run test -- --run && npm run build",
"prerelease:latest": "npm run test -- --run && npm run build",
"publish:alpha": "npm run publish:latest -- --publishTag alpha",
"publish:beta": "npm run publish:latest -- --publishTag beta",
"publish:latest": "changelogen gh release && changelogen --publish",
"release": "changelogen --bump --output --no-tag",
"release:alpha": "npm run release -- --prerelease alpha",
"release:beta": "npm run release -- --prerelease beta",
"release:latest": "changelogen --bump --output --no-tag",
"spellcheck": "cspell lint",

@@ -86,5 +81,20 @@ "spellcheck:ci": "npm run spellcheck -- --no-progress",

},
"engines": {
"node": ">=v13.6.0"
},
"files": [
"lib"
],
"peerDependencies": {
"pdfkit": ">=0.13.0",
"typescript": ">=4.7.0"
},
"peerDependenciesMeta": {
"pdfkit": {
"optional": true
},
"typescript": {
"optional": true
}
},
"dependencies": {

@@ -97,13 +107,13 @@ "svg-engine": "^0.2.3"

"@schoero/changelog-config": "^0.0.2",
"@schoero/cspell-config": "^1.6.17",
"@schoero/eslint-config": "^1.41.19",
"@schoero/cspell-config": "^1.8.2",
"@schoero/eslint-config": "^1.42.0",
"@schoero/markdownlint-config": "^1.1.7",
"@schoero/ts-config": "^0.3.7",
"@schoero/unwritten-config": "^0.0.3",
"@schoero/vite-config": "^0.0.26",
"@types/node": "^20.8.0",
"@types/pdfkit": "^0.12.12",
"@types/svg-parser": "^2.0.4",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"@schoero/vite-config": "^0.0.28",
"@types/node": "^20.8.9",
"@types/pdfkit": "^0.13.1",
"@types/svg-parser": "^2.0.5",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"cross-env": "^7.0.3",

@@ -113,4 +123,4 @@ "glob": "^10.3.10",

"typescript": "^5.2.2",
"unwritten": "^0.0.3",
"vite-plugin-dts": "^3.6.0",
"unwritten": "^0.1.1",
"vite-plugin-dts": "^3.6.2",
"vite-plugin-no-bundle": "^3.0.0",

@@ -139,5 +149,4 @@ "vitest": "^0.34.6"

"volta": {
"node": "20.8.0",
"npm": "10.1.0"
"node": "20.8.1"
}
}

@@ -7,23 +7,10 @@ <div align="center">

<div align="center">
<a href="https://github.com/schoero/SwissQRBill/blob/master/LICENSE">
<img alt="MIT License" src="https://img.shields.io/npm/l/swissqrbill?color=brightgreen&style=flat-square">
</a>
<a href="https://www.npmjs.com/package/swissqrbill">
<img alt="Version" src="https://img.shields.io/npm/v/swissqrbill?color=brightgreen&style=flat-square">
</a>
<a href="https://github.com/schoero/SwissQRBill/issues">
<img alt="Issues" src="https://img.shields.io/github/issues-raw/schoero/swissqrbill?style=flat-square">
</a>
<a href="https://www.npmjs.com/package/swissqrbill">
<img alt="Downloads" src="https://img.shields.io/npm/dw/swissqrbill?style=flat-square">
</a>
<a href="https://www.jsdelivr.com/package/npm/swissqrbill">
<img alt="JSDelivr hits" src="https://img.shields.io/jsdelivr/npm/hm/swissqrbill?color=brightgreen&style=flat-square">
</a>
<a href="https://github.com/schoero/SwissQRBill/stargazers">
<img alt="Downloads" src="https://img.shields.io/github/stars/schoero/SwissQRBill?color=brightgreen&style=flat-square">
</a>
<a href="https://github.com/schoero/SwissQRBill/actions?query=workflow%3ACI">
<img alt="CI" src="https://img.shields.io/github/actions/workflow/status/schoero/SwissQRBill/ci.yml?branch=master&style=flat-square">
</a>
[![GitHub license](https://img.shields.io/github/license/schoero/swissqrbill?style=flat-square&labelColor=454c5c&color=00AD51)](https://github.com/schoero/swissqrbill/blob/main/LICENSE)
[![npm version](https://img.shields.io/npm/v/swissqrbill?style=flat-square&labelColor=454c5c&color=00AD51)](https://www.npmjs.com/package/swissqrbill?activeTab=versions)
[![GitHub issues](https://img.shields.io/github/issues/schoero/swissqrbill?style=flat-square&labelColor=454c5c&color=00AD51)](https://github.com/schoero/swissqrbill/issues)
[![npm weekly downloads](https://img.shields.io/npm/dw/swissqrbill?style=flat-square&labelColor=454c5c&color=00AD51)](https://www.npmjs.com/package/swissqrbill?activeTab=readme)
[![GitHub repo stars](https://img.shields.io/github/stars/schoero/swissqrbill?style=flat-square&labelColor=454c5c&color=00AD51)](https://github.com/schoero/swissqrbill/stargazers)
[![GitHub workflow status](https://img.shields.io/github/actions/workflow/status/schoero/swissqrbill/ci.yml?event=push&style=flat-square&labelColor=454c5c&color=00AD51)](https://github.com/schoero/swissqrbill/actions?query=workflow%3ACI)
</div>

@@ -85,6 +72,9 @@

In versions prior to v3.0.0, you could simply include SwissQRBill like this:
In versions prior to v4.0.0, you could include SwissQRBill like this:
```js
const SwissQRBill = require("swissqrbill"); // CommonJS. Not tree-shakeable.
```ts
// ESM. Tree-shakeable.
import { SwissQRBill } from "swissqrbill";
// CommonJS. Not tree-shakeable.
const SwissQRBill = require("swissqrbill");
```

@@ -94,10 +84,11 @@

While you can still do this, it is recommended to switch to the new ES module imports to be able to take advantage of tree-shaking. SwissQRBill uses the new [conditional exports feature](https://nodejs.org/api/packages.html#packages_exports_sugar) that was added in node v12.16.0 or v13.6.0.
In SwissQRBill `>=4.0.0` this is no longer possible. Instead yo
This allows you to import only the parts of SwissQRBill that you actually need.
```js
import { PDF } from "swissqrbill/pdf"; // ESM. Tree-shakeable
import { SVG } from "swissqrbill/svg"; // ESM. Tree-shakeable
import { mm2pt } from "swissqrbill/utils"; // ESM. Tree-shakeable
```ts
// PDF
import { SwissQRBill } from "swissqrbill/pdf";
// SVG
import { SwissQRBill } from "swissqrbill/svg";
// utils
import { mm2pt } from "swissqrbill/utils";
```

@@ -107,44 +98,2 @@

Be aware that TypeScript versions prior to v4.7.0 and Node.js prior to v12.16.0 or v13.6.0, do not support this feature.
To get conditional exports to work with TypeScript > v4.7.0, you have to set these two options your `tsconfig.json`:
```json
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "NodeNext"
}
}
```
If you are using a TypeScript or Node.js version that doesn't support the new export feature, you can still take advantage of tree-shaking, by importing the files directly by their path.
```js
import { PDF } from "swissqrbill/lib/node/esm/node/pdf.js"; // ESM. Tree-shakeable
import { SVG } from "swissqrbill/lib/node/esm/node/svg.js"; // ESM. Tree-shakeable
import { mm2pt } from "swissqrbill/lib/node/esm/shared/utils.js"; // ESM. Tree-shakeable
```
<br/>
### Browser
For the browser it is a bit more complicated. The easiest way would be to include the pre-bundled version.
```html
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/swissqrbill/lib/browser/bundle/index.js"></script>
```
You can also import the bundle directly, if you are using a bundler like webpack.
```js
import SwissQRBill from "swissqrbill/lib/browser/bundle";
```
However, if you want to take advantage of tree-shaking in the browser, you have to bundle the library by yourself.
You can find an example, how this could be done using webpack, at <https://github.com/schoero/SwissQRBill-browser-example>.
<br/>
<br/>
## Quick start

@@ -151,0 +100,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc