@qr-bill/invoice 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["BODY_SIZE","BODY_LINE","readNumber","BASELINE_SHARE"],"sources":["../src/drawing/text.ts","../src/details/date.ts","../src/details/details.ts","../src/drawing/pen.ts","../src/parties/address.ts","../src/header/address-window.ts","../src/header/continued-header.ts","../src/header/issuer.ts","../src/invoice/errors.ts","../src/header/letterhead.ts","../src/amounts/money.ts","../src/amounts/totals.ts","../src/fields/fields.ts","../src/invoice/limits.ts","../src/items/items.validator.ts","../src/amounts/totals.validator.ts","../src/labels/labels.ts","../src/uid/uid.ts","../src/uid/uid.validator.ts","../src/parties/parties.validator.ts","../src/themes/business.ts","../src/themes/color.ts","../src/themes/modern.ts","../src/themes/standard.ts","../src/themes/themes.ts","../src/themes/themes.validator.ts","../src/invoice/invoice.validator.ts","../src/page/decorations.ts","../src/page/flow.ts","../src/summary/mentions.ts","../src/summary/total-rows.ts","../src/summary/summary.ts","../src/table/dimensions.ts","../src/table/columns.ts","../src/table/table.ts","../src/pdf/pdf.ts"],"sourcesContent":["/**\n * Fitting texts in their zones: breaking a text into lines that fit a width, and shortening a line with \"…\" when it\n * cannot fit otherwise. The width of a text is given by a function, so that the same rules serve any font; on the\n * invoice it is measured by PDFKit, with the font that prints it.\n *\n * @module\n */\n\nimport type { Measure } from './drawing.types.js';\n\n/** The ellipsis that ends a shortened text. */\nexport const ELLIPSIS = '…';\n\n/**\n * Shortens a text with \"…\" until it fits a width. A text that fits already is returned as is.\n *\n * @param text - The text, on one line.\n * @param width - The width available, in millimetres.\n * @param measure - The width of a text.\n * @returns The text, or its beginning followed by \"…\"; just \"…\" when nothing else fits.\n * @example\n * ```ts\n * shorten('Seldwyla', 5, (text) => text.length); // 'Seld…'\n * ```\n */\nexport function shorten(text: string, width: number, measure: Measure): string {\n if (measure(text) <= width) return text;\n const characters = [...text];\n for (let length = characters.length - 1; length > 0; length--) {\n const candidate = `${characters.slice(0, length).join('').trimEnd()}${ELLIPSIS}`;\n if (measure(candidate) <= width) return candidate;\n }\n return ELLIPSIS;\n}\n\n/**\n * Breaks a text into lines that fit a width: between words where possible, inside a word longer than the width\n * otherwise. Line feeds start new lines. Beyond the maximum number of lines, the last one is shortened with \"…\".\n *\n * @param text - The text, which may contain line feeds.\n * @param width - The width available, in millimetres.\n * @param measure - The width of a text.\n * @param maxLines - The maximum number of lines; unlimited by default.\n * @returns The lines, each fitting the width.\n * @example\n * ```ts\n * wrap('Max Muster & Söhne', 10, (text) => text.length); // ['Max Muster', '& Söhne']\n * wrap('Max Muster & Söhne', 10, (text) => text.length, 1); // ['Max Muste…']\n * ```\n */\nexport function wrap(\n text: string,\n width: number,\n measure: Measure,\n maxLines: number = Number.POSITIVE_INFINITY,\n): string[] {\n const lines: string[] = [];\n for (const paragraph of text.split('\\n')) {\n let line = '';\n for (const word of paragraph.split(' ').filter((part) => part !== '')) {\n const candidate = line === '' ? word : `${line} ${word}`;\n if (measure(candidate) <= width) {\n line = candidate;\n continue;\n }\n if (line !== '') lines.push(line);\n // A word longer than the width is broken where it must.\n let rest = [...word];\n // A character wider than the width stays alone on its line.\n while (rest.length > 1 && measure(rest.join('')) > width) {\n // The longest beginning that fits, but at least one character, even wider than the width, so that the loop\n // always ends. It stops before the end of the word, which does not fit.\n let length = 1;\n while (measure(rest.slice(0, length + 1).join('')) <= width) length++;\n lines.push(rest.slice(0, length).join(''));\n rest = rest.slice(length);\n }\n line = rest.join('');\n }\n lines.push(line);\n }\n if (lines.length <= maxLines) return lines;\n const [last = ''] = lines.slice(maxLines - 1, maxLines);\n return [...lines.slice(0, maxLines - 1), shorten(`${last}${ELLIPSIS}`, width, measure)];\n}\n","/**\n * How dates are written on the invoice: as in Switzerland, in every language.\n *\n * @module\n */\n\n/**\n * Writes a date as in Switzerland, whatever the language: day, month and year separated by points.\n *\n * @param date - A date written `YYYY-MM-DD`.\n * @returns The date, e.g. `20.11.2026`.\n * @example\n * ```ts\n * formatDate('2026-11-20'); // '20.11.2026'\n * ```\n */\nexport function formatDate(date: string): string {\n const [year, month, day] = date.split('-');\n return `${day}.${month}.${year}`;\n}\n","/**\n * The beginning of the body of the invoice: its title, its details in a grid (number, dates, period, references,\n * the details added by the caller), the subject and the introduction.\n *\n * @module\n */\n\nimport type { RenderContext } from '../drawing/drawing.types.js';\nimport { shorten, wrap } from '../drawing/text.js';\nimport type { Flow } from '../page/flow.js';\nimport { CONTENT_WIDTH, LEFT } from '../page/page.js';\nimport { formatDate } from './date.js';\nimport type { Detail } from './details.types.js';\n\n/** The title: its baseline and size. */\nconst TITLE_BASELINE = 100;\nconst TITLE_SIZE = 16;\n\n/** The grid of details: where it starts, columns, sizes, and the lines a value may take. */\nconst GRID_TOP = 102;\nconst GRID_COLUMNS = 5;\nconst GRID_COLUMN_WIDTH: number = CONTENT_WIDTH / GRID_COLUMNS;\nconst GRID_GAP = 2;\nconst LABEL_SIZE = 7.5;\nconst VALUE_SIZE = 9;\nconst VALUE_LINE = 4;\nconst VALUE_MAX_LINES = 2;\n\n/** The subject: size, line height and lines at most. */\nconst SUBJECT_SIZE = 10.5;\nconst SUBJECT_LINE = 4.8;\nconst SUBJECT_MAX_LINES = 3;\n\n/** The introduction. */\nconst BODY_SIZE = 9;\nconst BODY_LINE = 4.2;\n\n/** The details of the invoice, in the order they are printed. */\nfunction details(context: RenderContext): Detail[] {\n const { invoice, labels } = context;\n const optional = (label: string, value: string | undefined): Detail[] =>\n value === undefined ? [] : [{ label, value }];\n return [\n ...optional(labels.number, invoice.number),\n { label: labels.date, value: formatDate(invoice.date) },\n ...optional(labels.dueDate, invoice.dueDate === undefined ? undefined : formatDate(invoice.dueDate)),\n ...optional(labels.servicePeriod, invoice.servicePeriod),\n ...optional(labels.customerReference, invoice.customerReference),\n ...invoice.extraFields,\n ];\n}\n\n/**\n * Draws the title, the grid of details, the subject and the introduction, from the top of the body of the first\n * page.\n *\n * @param context - The invoice being drawn.\n * @param flow - Where the content goes; afterwards, under the introduction.\n */\nexport function drawDetails(context: RenderContext, flow: Flow): void {\n const { pen, invoice, labels, colors } = context;\n pen.text(shorten(invoice.title, CONTENT_WIDTH, pen.measurer(TITLE_SIZE, true)), LEFT, TITLE_BASELINE, {\n size: TITLE_SIZE,\n bold: true,\n color: colors.title,\n });\n\n // The grid, five details per row; a value takes two lines at most.\n const width = GRID_COLUMN_WIDTH - GRID_GAP;\n const labelMeasure = pen.measurer(LABEL_SIZE);\n const valueMeasure = pen.measurer(VALUE_SIZE, true);\n const all = details(context);\n let top = GRID_TOP;\n for (let start = 0; start < all.length; start += GRID_COLUMNS) {\n const row = all.slice(start, start + GRID_COLUMNS).map((detail) => ({\n label: shorten(detail.label, width, labelMeasure),\n lines: wrap(detail.value, width, valueMeasure, VALUE_MAX_LINES),\n }));\n row.forEach((detail, column) => {\n const x = LEFT + column * GRID_COLUMN_WIDTH;\n pen.text(detail.label, x, top + 3, { size: LABEL_SIZE, color: colors.muted });\n detail.lines.forEach((line, index) => {\n pen.text(line, x, top + 7 + index * VALUE_LINE, { size: VALUE_SIZE, bold: true, color: colors.text });\n });\n });\n top += 4 + Math.max(...row.map((detail) => detail.lines.length)) * VALUE_LINE + 1;\n }\n flow.y = top + 1;\n\n if (invoice.subject !== undefined) {\n const lines = wrap(\n `${labels.subject}${invoice.subject}`,\n CONTENT_WIDTH,\n pen.measurer(SUBJECT_SIZE, true),\n SUBJECT_MAX_LINES,\n );\n flow.paragraph(lines, SUBJECT_LINE, (line, baseline) => {\n pen.text(line, LEFT, baseline, { size: SUBJECT_SIZE, bold: true, color: colors.text });\n });\n flow.y += 2;\n }\n if (invoice.introduction !== undefined) {\n const lines = wrap(invoice.introduction, CONTENT_WIDTH, pen.measurer(BODY_SIZE));\n flow.paragraph(lines, BODY_LINE, (line, baseline) => {\n pen.text(line, LEFT, baseline, { size: BODY_SIZE, color: colors.text });\n });\n flow.y += 2;\n }\n}\n","/**\n * Drawing on a PDFKit document in millimetres: texts at their baseline, in Liberation Sans without kerning nor\n * ligatures (so that they take the width they were measured with), rectangles, lines and images.\n *\n * @module\n */\n\nimport { POINTS_PER_MM, type RegisteredFonts } from '@qr-bill/pdfkit';\nimport type { InvoiceDocument, Measure, TextStyle } from './drawing.types.js';\n\n/** Kerning and ligatures off: PDFKit applies them by default, and they change the width of a text. */\nconst NO_KERNING = { features: { kern: false, liga: false } } as const;\n\n/** Draws on a PDFKit document, in millimetres from the top left corner of the page. */\nexport class Pen {\n /** The document. */\n readonly doc: InvoiceDocument;\n /** The names of the regular and bold fonts. */\n private readonly fonts: RegisteredFonts;\n\n /**\n * @param doc - The document.\n * @param fonts - The names of the fonts, as registered by `registerFonts` of `@qr-bill/pdfkit`.\n */\n constructor(doc: InvoiceDocument, fonts: RegisteredFonts) {\n this.doc = doc;\n this.fonts = fonts;\n }\n\n /** Selects the font and its size. */\n private select(size: number, bold: boolean | undefined): void {\n this.doc.font(bold === true ? this.fonts.bold : this.fonts.regular);\n this.doc.fontSize(size);\n }\n\n /**\n * The width of a text.\n *\n * @param text - The text.\n * @param size - Its size in points.\n * @param bold - Whether it is bold.\n * @returns The width in millimetres.\n */\n measure(text: string, size: number, bold?: boolean): number {\n this.select(size, bold);\n return this.doc.widthOfString(text, NO_KERNING) / POINTS_PER_MM;\n }\n\n /**\n * The function measuring texts of a size and weight, for `wrap` and `shorten`.\n *\n * @param size - The size in points.\n * @param bold - Whether bold.\n * @returns The measure.\n */\n measurer(size: number, bold?: boolean): Measure {\n return (text) => this.measure(text, size, bold);\n }\n\n /**\n * Writes a text on one line.\n *\n * @param text - The text, which must fit where it goes.\n * @param x - Where it starts, or ends when aligned right.\n * @param y - Its baseline.\n * @param style - Its size, weight, colour and alignment.\n */\n text(text: string, x: number, y: number, style: TextStyle): void {\n const start = style.align === 'right' ? x - this.measure(text, style.size, style.bold) : x;\n this.select(style.size, style.bold);\n this.doc.fillColor(style.color);\n this.doc.text(text, start * POINTS_PER_MM, y * POINTS_PER_MM, {\n ...NO_KERNING,\n baseline: 'alphabetic',\n lineBreak: false,\n });\n }\n\n /**\n * Fills a rectangle.\n *\n * @param x - Left edge.\n * @param y - Top edge.\n * @param width - Width.\n * @param height - Height.\n * @param color - Colour, `#RRGGBB`.\n */\n rect(x: number, y: number, width: number, height: number, color: string): void {\n const k = POINTS_PER_MM;\n this.doc.rect(x * k, y * k, width * k, height * k);\n this.doc.fill(color);\n }\n\n /**\n * Draws a horizontal line.\n *\n * @param x1 - Start.\n * @param x2 - End.\n * @param y - Height.\n * @param width - Thickness in points.\n * @param color - Colour, `#RRGGBB`.\n */\n line(x1: number, x2: number, y: number, width: number, color: string): void {\n const k = POINTS_PER_MM;\n this.doc.moveTo(x1 * k, y * k);\n this.doc.lineTo(x2 * k, y * k);\n this.doc.lineWidth(width);\n this.doc.stroke(color);\n }\n\n /**\n * Draws an image fitted in a box, keeping its proportions, in the top left corner of the box.\n *\n * @param bytes - A PNG or JPEG file.\n * @param x - Left edge of the box.\n * @param y - Top edge of the box.\n * @param width - Width of the box.\n * @param height - Height of the box.\n */\n image(bytes: Uint8Array, x: number, y: number, width: number, height: number): void {\n const k = POINTS_PER_MM;\n // PDFKit reads images from a Buffer; a plain Uint8Array would be taken for a file path.\n const buffer = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n this.doc.image(buffer, x * k, y * k, { fit: [width * k, height * k] });\n }\n}\n","/**\n * How the addresses are written on the invoice: the line of the street, the line of the town, and the name of the\n * country, printed when the issuer and the recipient are in different countries.\n *\n * @module\n */\n\nimport type { Address, Language } from '@qr-bill/core';\n\n/**\n * The name of a country in a language, from the data of the JavaScript runtime (`Intl.DisplayNames`); the code\n * itself when the runtime does not know it.\n *\n * @param code - A two-letter ISO 3166-1 code, in upper case.\n * @param language - The language of the name.\n * @returns The name of the country.\n * @example\n * ```ts\n * countryName('DE', 'fr'); // 'Allemagne'\n * countryName('CH', 'rm'); // 'Svizra'\n * ```\n */\nexport function countryName(code: string, language: Language): string {\n // With the fallback \"code\", the name is never missing: String() only tells the type so.\n return String(new Intl.DisplayNames([language], { type: 'region', fallback: 'code' }).of(code));\n}\n\n/**\n * The line of the street and the building number, when there is one.\n *\n * @param address - An address.\n * @returns `\"Musterstrasse 123\"`, or `undefined` without street nor number.\n * @example\n * ```ts\n * streetLine({ name: 'A', street: 'Musterstrasse', buildingNumber: '123', postalCode: '8000', town: 'Seldwyla', country: 'CH' }); // 'Musterstrasse 123'\n * ```\n */\nexport function streetLine(address: Address): string | undefined {\n const line = [address.street, address.buildingNumber].filter((part) => part !== undefined).join(' ');\n return line === '' ? undefined : line;\n}\n\n/**\n * The line of the postal code and the town.\n *\n * @param address - An address.\n * @returns `\"8000 Seldwyla\"`.\n */\nexport function townLine(address: Address): string {\n return `${address.postalCode} ${address.town}`;\n}\n","/**\n * The address of the recipient, in the window of the envelope: on the left by default, on the right as an option.\n * As Swiss Post asks, the window holds a single line with the sender, separated from the address by a rule, at\n * least 3 mm above it, and nothing frames the address.\n *\n * @module\n */\n\nimport type { RenderContext } from '../drawing/drawing.types.js';\nimport { shorten, wrap } from '../drawing/text.js';\nimport { RIGHT } from '../page/page.js';\nimport { countryName, streetLine, townLine } from '../parties/address.js';\nimport type { HeaderLine } from './header.types.js';\n\n/**\n * The window: left edge and width of its texts on the left and on the right, top; the sender line, its rule and the\n * address under it. On the right, the texts end at the right edge of the content.\n */\nconst WINDOW_LEFT = { x: 25, width: 85 } as const;\nconst WINDOW_RIGHT = { x: 118, width: RIGHT - 118 } as const;\nconst WINDOW_TOP = 47;\nconst SENDER_SIZE = 7;\nconst ADDRESS_SIZE = 10;\nconst ADDRESS_LINE = 4.4;\n\n/**\n * Draws the recipient in the window of the envelope: the sender on one line, a rule, then the address, its name in\n * bold on two lines at most, its country when it is not the issuer's.\n *\n * @param context - The invoice being drawn.\n */\nexport function drawAddressWindow(context: RenderContext): void {\n const { pen, invoice, colors, foreign } = context;\n const { issuer, recipient, language } = invoice;\n const { x, width } = invoice.addressWindow === 'right' ? WINDOW_RIGHT : WINDOW_LEFT;\n const sender = [\n issuer.name,\n streetLine(issuer),\n townLine(issuer),\n foreign ? countryName(issuer.country, language) : undefined,\n ]\n .filter((part) => part !== undefined)\n .join(', ');\n pen.text(shorten(sender, width, pen.measurer(SENDER_SIZE)), x, WINDOW_TOP + 2.5, {\n size: SENDER_SIZE,\n color: colors.muted,\n });\n pen.line(x, x + width, WINDOW_TOP + 4, 0.3, colors.muted);\n\n const measure = pen.measurer(ADDRESS_SIZE);\n const plain = (text: string | undefined): HeaderLine[] =>\n text === undefined ? [] : [{ text: shorten(text, width, measure), bold: false }];\n const lines: HeaderLine[] = [\n ...plain(recipient.salutation),\n ...wrap(recipient.name, width, pen.measurer(ADDRESS_SIZE, true), 2).map((text) => ({ text, bold: true })),\n ...recipient.extraLines.flatMap(plain),\n ...plain(streetLine(recipient)),\n ...plain(townLine(recipient)),\n ...plain(foreign ? countryName(recipient.country, language) : undefined),\n ];\n lines.forEach((line, index) => {\n pen.text(line.text, x, WINDOW_TOP + 11 + index * ADDRESS_LINE, {\n size: ADDRESS_SIZE,\n bold: line.bold,\n color: colors.text,\n });\n });\n}\n","/**\n * The short header of the pages after the first: the name of the issuer on the left, the title and number of the\n * invoice on the right.\n *\n * @module\n */\n\nimport type { RenderContext } from '../drawing/drawing.types.js';\nimport { shorten } from '../drawing/text.js';\nimport { CONTENT_WIDTH, LEFT, RIGHT } from '../page/page.js';\n\n/** Baseline and size of its texts. */\nconst CONTINUED_BASELINE = 18;\nconst CONTINUED_SIZE = 9;\n\n/**\n * Draws the short header of the pages after the first: the name of the issuer on the left, the title and number of\n * the invoice on the right.\n *\n * @param context - The invoice being drawn.\n */\nexport function drawContinuedHeader(context: RenderContext): void {\n const { pen, invoice, colors } = context;\n const half = CONTENT_WIDTH / 2 - 2;\n const name = shorten(invoice.issuer.name, half, pen.measurer(CONTINUED_SIZE, true));\n pen.text(name, LEFT, CONTINUED_BASELINE, { size: CONTINUED_SIZE, bold: true, color: colors.text });\n const title = [invoice.title, invoice.number].filter((part) => part !== undefined).join(' ');\n pen.text(shorten(title, half, pen.measurer(CONTINUED_SIZE)), RIGHT, CONTINUED_BASELINE, {\n size: CONTINUED_SIZE,\n color: colors.muted,\n align: 'right',\n });\n}\n","/**\n * The details of the issuer on the first page: its name when a logo stands for it, its address, its contacts and its\n * UID. In the right column, aligned right, with the window on the left; under the letterhead with the window on the\n * right.\n *\n * @module\n */\n\nimport type { RenderContext, TextStyle } from '../drawing/drawing.types.js';\nimport { shorten, wrap } from '../drawing/text.js';\nimport { LEFT, RIGHT } from '../page/page.js';\nimport { countryName, streetLine, townLine } from '../parties/address.js';\nimport type { HeaderLine } from './header.types.js';\n\n/** The details of the issuer: width, first baseline in each layout, line height, sizes. */\nconst ISSUER_WIDTH = 72;\nconst ISSUER_TOP_RIGHT_COLUMN = 18;\nconst ISSUER_TOP_UNDER_LETTERHEAD = 40;\nconst ISSUER_LINE = 3.8;\nconst ISSUER_SIZE = 8.5;\nconst ISSUER_NAME_SIZE = 9;\n\n/** The lines of the details of the issuer: its name when a logo stands for it, its address and its contacts. */\nfunction issuerLines(context: RenderContext): HeaderLine[] {\n const { pen, invoice, labels, foreign } = context;\n const { issuer } = invoice;\n const name =\n issuer.logo === undefined\n ? []\n : wrap(issuer.name, ISSUER_WIDTH, pen.measurer(ISSUER_NAME_SIZE, true), 2).map((text) => ({ text, bold: true }));\n const uid =\n issuer.uid === undefined ? [] : [issuer.vatRegistered ? `${issuer.uid} ${labels.vatNumberSuffix}` : issuer.uid];\n const others = [\n ...issuer.extraLines,\n streetLine(issuer),\n townLine(issuer),\n foreign ? countryName(issuer.country, invoice.language) : undefined,\n ...issuer.phones,\n issuer.email,\n issuer.contact,\n ...uid,\n ].filter((text) => text !== undefined);\n const measure = pen.measurer(ISSUER_SIZE);\n return [...name, ...others.map((text) => ({ text: shorten(text, ISSUER_WIDTH, measure), bold: false }))];\n}\n\n/**\n * Draws the details of the issuer: in the right column, aligned right, with the window on the left; under the\n * letterhead with the window on the right.\n *\n * @param context - The invoice being drawn.\n */\nexport function drawIssuer(context: RenderContext): void {\n const { pen, invoice, colors } = context;\n const left = invoice.addressWindow === 'right';\n const top = left ? ISSUER_TOP_UNDER_LETTERHEAD : ISSUER_TOP_RIGHT_COLUMN;\n issuerLines(context).forEach((line, index) => {\n const style: TextStyle = {\n size: line.bold ? ISSUER_NAME_SIZE : ISSUER_SIZE,\n bold: line.bold,\n color: colors.text,\n align: left ? 'left' : 'right',\n };\n pen.text(line.text, left ? LEFT : RIGHT, top + index * ISSUER_LINE, style);\n });\n}\n","/**\n * The error thrown when an invoice is invalid.\n *\n * @module\n */\n\nimport type { InvoiceIssue } from './invoice.types.js';\n\n/**\n * Thrown by {@link createInvoicePDF}. Lists every problem found, not just the first.\n *\n * @example\n * ```ts\n * try {\n * await createInvoicePDF(input);\n * } catch (error) {\n * if (error instanceof InvoiceValidationError) {\n * error.issues; // [{ code: 'invalid_uid', path: ['issuer', 'uid'], message: '…' }, …]\n * }\n * }\n * ```\n */\nexport class InvoiceValidationError extends Error {\n /** Always \"InvoiceValidationError\". */\n override readonly name = 'InvoiceValidationError';\n\n /** Every problem found. */\n readonly issues: readonly InvoiceIssue[];\n\n /**\n * @param issues - The problems found; the message of the error summarizes them.\n */\n constructor(issues: readonly InvoiceIssue[]) {\n const summary = issues\n .map((issue) => (issue.path.length > 0 ? `${issue.path.join('.')}: ${issue.message}` : issue.message))\n .join('; ');\n super(`Invalid invoice: ${summary}`);\n this.issues = issues;\n }\n}\n","/**\n * The letterhead, in the top left corner of the first page: the logo, or the name of the issuer in large type.\n *\n * @module\n */\n\nimport type { RenderContext } from '../drawing/drawing.types.js';\nimport { wrap } from '../drawing/text.js';\nimport { InvoiceValidationError } from '../invoice/errors.js';\nimport { LEFT } from '../page/page.js';\n\n/** The box of the logo, whose proportions are kept. */\nconst LOGO = { x: LEFT, y: 15, width: 50, height: 18 } as const;\n/**\n * The name of the issuer, without a logo: the sizes tried until it fits on two lines, the smallest one, shortened\n * when even it does not fit, and the width.\n */\nconst LETTERHEAD_SIZES = [16, 14];\nconst LETTERHEAD_SMALLEST_SIZE = 12;\nconst LETTERHEAD_WIDTH = 95;\n\n/**\n * Draws the logo, or the name of the issuer in large type: on two lines at most, in a smaller size when needed,\n * shortened with \"…\" as a last resort.\n *\n * @param context - The invoice being drawn.\n * @throws {InvoiceValidationError} When the logo is not a PNG or JPEG file PDFKit can read.\n */\nexport function drawLetterhead(context: RenderContext): void {\n const { pen, invoice, colors } = context;\n const { logo, name } = invoice.issuer;\n if (logo !== undefined) {\n try {\n pen.image(logo.bytes, LOGO.x, LOGO.y, LOGO.width, LOGO.height);\n } catch (error) {\n throw new InvoiceValidationError([\n {\n code: 'unsupported_logo',\n path: ['issuer', 'logo'],\n message: `The logo could not be read (${String(error)})`,\n },\n ]);\n }\n return;\n }\n const size =\n LETTERHEAD_SIZES.find((candidate) => wrap(name, LETTERHEAD_WIDTH, pen.measurer(candidate, true)).length <= 2) ??\n LETTERHEAD_SMALLEST_SIZE;\n const lineHeight = size * 0.41;\n wrap(name, LETTERHEAD_WIDTH, pen.measurer(size, true), 2).forEach((line, index) => {\n pen.text(line, LEFT, LOGO.y + size * 0.32 + index * lineHeight, { size, bold: true, color: colors.title });\n });\n}\n","/**\n * Decimal numbers of an invoice as exact integers: a quantity, a price, a rate or an amount is read into a\n * `bigint` counted in its smallest unit (cents for an amount), computed exactly, and written back as a decimal\n * string. No floating-point number ever holds money.\n *\n * @module\n */\n\nimport type { AmountFormat } from '../invoice/invoice.types.js';\n\n/**\n * Reads a decimal number with at most a given number of decimals, as an integer in that unit: `\"12.5\"` with 2\n * decimals is `1250n`. A string (`\"-12.50\"`, surrounding spaces ignored) or a number is accepted; a number only when\n * its decimal form has at most that many decimals, so that `0.1 + 0.2` is refused.\n *\n * @param value - The number as given.\n * @param decimals - The number of decimals allowed, which is also the scale of the result.\n * @returns The scaled integer, or `undefined` when the value is not such a number.\n * @example\n * ```ts\n * parseDecimal('-12.5', 2); // -1250n\n * parseDecimal(0.1 + 0.2, 2); // undefined: 0.30000000000000004\n * ```\n */\nexport function parseDecimal(value: unknown, decimals: number): bigint | undefined {\n let text: string;\n if (typeof value === 'string') text = value.trim();\n else if (typeof value === 'number' && Number.isFinite(value)) text = String(value);\n else return undefined;\n const match = /^(-?)(\\d+)(?:\\.(\\d+))?$/.exec(text);\n if (match === null) return undefined;\n const [, sign, whole, fraction = ''] = match as unknown as [string, string, string, string?];\n if (fraction.length > decimals) return undefined;\n const units = BigInt(whole + fraction.padEnd(decimals, '0'));\n return sign === '-' ? -units : units;\n}\n\n/**\n * Divides two integers, rounding half away from zero (commercial rounding): 2.5 gives 3 and -2.5 gives -3.\n *\n * @param numerator - The dividend.\n * @param denominator - The divisor, not zero.\n * @returns The rounded quotient.\n * @example\n * ```ts\n * roundDiv(5n, 2n); // 3n\n * roundDiv(-5n, 2n); // -3n\n * ```\n */\nexport function roundDiv(numerator: bigint, denominator: bigint): bigint {\n const quotient = numerator / denominator;\n const remainder = numerator % denominator;\n const twice = 2n * (remainder < 0n ? -remainder : remainder);\n if (twice < (denominator < 0n ? -denominator : denominator)) return quotient;\n return numerator < 0n === denominator < 0n ? quotient + 1n : quotient - 1n;\n}\n\n/**\n * Writes a scaled integer as a decimal string with exactly that many decimals.\n *\n * @param units - The integer, e.g. cents.\n * @param scale - The number of decimals.\n * @returns The decimal string, with `-` for a negative number.\n * @example\n * ```ts\n * toDecimal(-9000n, 2); // '-90.00'\n * ```\n */\nexport function toDecimal(units: bigint, scale: number): string {\n const sign = units < 0n ? '-' : '';\n const digits = (units < 0n ? -units : units).toString().padStart(scale + 1, '0');\n return scale === 0 ? `${sign}${digits}` : `${sign}${digits.slice(0, -scale)}.${digits.slice(-scale)}`;\n}\n\n/**\n * Writes a scaled integer as a decimal string without trailing zeros after the decimal point, at least\n * `minDecimals` decimals being kept.\n *\n * @param units - The integer.\n * @param scale - Its number of decimals.\n * @param minDecimals - Decimals always kept; 0 by default.\n * @returns The shortest decimal string.\n * @example\n * ```ts\n * toShortDecimal(810n, 2); // '8.1'\n * toShortDecimal(1250000n, 4, 2); // '125.00'\n * ```\n */\nexport function toShortDecimal(units: bigint, scale: number, minDecimals = 0): string {\n const full = toDecimal(units, scale);\n if (scale === 0) return full;\n const [whole, fraction] = full.split('.') as [string, string];\n const kept = fraction.replace(/0+$/, '').padEnd(minDecimals, '0');\n return kept === '' ? whole : `${whole}.${kept}`;\n}\n\n/**\n * Writes a decimal number as it is printed on the invoice: thousands separated by a space (as on the payment part)\n * or by an apostrophe, the decimals kept as they are. Serves the amounts, the quantities and the unit prices.\n *\n * @param amount - A decimal string, e.g. `\"-1234.50\"` or `\"1500\"`.\n * @param format - `space` or `apostrophe`.\n * @returns The number as printed.\n * @example\n * ```ts\n * formatMoney('-1234.50', 'space'); // '-1 234.50'\n * formatMoney('1234567.00', 'apostrophe'); // \"1'234'567.00\"\n * formatMoney('1500', 'space'); // '1 500'\n * ```\n */\nexport function formatMoney(amount: string, format: AmountFormat): string {\n const negative = amount.startsWith('-');\n const [whole = '', ...fraction] = (negative ? amount.slice(1) : amount).split('.');\n const separator = format === 'space' ? ' ' : \"'\";\n const grouped = whole.replace(/\\B(?=(\\d{3})+$)/g, separator);\n return [`${negative ? '-' : ''}${grouped}`, ...fraction].join('.');\n}\n","/**\n * The amounts of an invoice: each line, the VAT of each rate and the total, computed exactly in integers.\n *\n * - The amount of a line is given, or its quantity (1 when absent) times its unit price, rounded to the centime.\n * - The VAT of a rate is computed on the sum of the lines at that rate, not line by line, so that roundings do not\n * add up. When the prices exclude VAT it is added; when they include it, it is the part of the gross amount that\n * is VAT (gross × rate / (100 + rate)).\n * - All roundings are commercial (half away from zero), to the centime, or to 5 centimes for the total on request.\n *\n * @module\n */\n\nimport type { InvoiceItem } from '../items/items.types.js';\nimport type { ComputedTotals, InvoiceTotals, InvoiceVAT, ParsedLine, TotalsOptions } from './amounts.types.js';\nimport { parseDecimal, roundDiv, toDecimal, toShortDecimal } from './money.js';\n\n/** Decimals of a quantity: 3, so that `1.5` hours is `1500n`. */\nexport const QUANTITY_DECIMALS = 3;\n/** Decimals of a unit price: 4, for prices such as 0.1250 per unit. */\nexport const UNIT_PRICE_DECIMALS = 4;\n/** Decimals of a VAT rate in percent: 2, so that 8.1 % is `810n`. */\nexport const RATE_DECIMALS = 2;\n/** Decimals of an amount: 2, amounts are counted in centimes. */\nexport const AMOUNT_DECIMALS = 2;\n/** The largest amount, in centimes: the largest amount of a QR-bill, 999 999 999.99. */\nexport const MAX_CENTIMES = 99_999_999_999n;\n\n/**\n * The amount of a line in centimes: its own amount, or quantity × unit price; `undefined` for a line of text.\n *\n * @param line - The line, read.\n * @returns The amount in centimes.\n */\nexport function lineAmount(line: ParsedLine): bigint | undefined {\n if (line.amount !== undefined) return line.amount;\n if (line.unitPrice === undefined) return undefined;\n const quantity = line.quantity ?? 10n ** BigInt(QUANTITY_DECIMALS);\n return roundDiv(quantity * line.unitPrice, 10n ** BigInt(QUANTITY_DECIMALS + UNIT_PRICE_DECIMALS - AMOUNT_DECIMALS));\n}\n\n/**\n * Computes the totals of lines already read. The result is in centimes; see {@link computeInvoiceTotals} for the\n * rules.\n *\n * @param lines - The lines, read.\n * @param options - Prices with or without VAT, rounding to 5 centimes.\n * @returns The amount of each line, the subtotal, the VAT per rate, the rounding and the total.\n */\nexport function computeTotals(lines: readonly ParsedLine[], options: TotalsOptions): ComputedTotals {\n const amounts = lines.map(lineAmount);\n const bases = new Map<bigint, bigint>();\n let subtotal = 0n;\n lines.forEach((line, index) => {\n const amount = amounts[index] ?? 0n;\n subtotal += amount;\n if (line.vatRate !== undefined) bases.set(line.vatRate, (bases.get(line.vatRate) ?? 0n) + amount);\n });\n // A rate in hundredths of a percent: 100 % is 10000.\n const hundredPercent = 100n * 10n ** BigInt(RATE_DECIMALS);\n const vat = [...bases]\n .sort(([a], [b]) => (a < b ? 1 : -1))\n .map(([rate, base]) => ({\n rate,\n base,\n amount: roundDiv(base * rate, options.pricesIncludeVAT === true ? hundredPercent + rate : hundredPercent),\n }));\n const vatTotal = vat.reduce((total, { amount }) => total + amount, 0n);\n const total = options.pricesIncludeVAT === true ? subtotal : subtotal + vatTotal;\n if (options.roundTo5Centimes !== true) return { lines: amounts, subtotal, vat, total };\n const rounded = roundDiv(total, 5n) * 5n;\n return { lines: amounts, subtotal, vat, rounding: rounded - total, total: rounded };\n}\n\n/**\n * Writes totals in centimes as decimal strings.\n *\n * @param totals - The result of {@link computeTotals}.\n * @returns The totals as printed in an {@link Invoice}.\n */\nexport function totalsToDecimals(totals: ComputedTotals): InvoiceTotals {\n const vat: InvoiceVAT[] = totals.vat.map(({ rate, base, amount }) => ({\n rate: toShortDecimal(rate, RATE_DECIMALS),\n base: toDecimal(base, AMOUNT_DECIMALS),\n amount: toDecimal(amount, AMOUNT_DECIMALS),\n }));\n return {\n lines: totals.lines.map((amount) => (amount === undefined ? undefined : toDecimal(amount, AMOUNT_DECIMALS))),\n subtotal: toDecimal(totals.subtotal, AMOUNT_DECIMALS),\n vat,\n ...(totals.rounding !== undefined && { rounding: toDecimal(totals.rounding, AMOUNT_DECIMALS) }),\n total: toDecimal(totals.total, AMOUNT_DECIMALS),\n };\n}\n\n/** Reads one number of a line, or throws a RangeError naming it. */\nfunction readNumber(value: unknown, decimals: number, name: string, index: number): bigint | undefined {\n if (value === undefined || value === null || value === '') return undefined;\n const parsed = parseDecimal(value, decimals);\n if (parsed === undefined) {\n throw new RangeError(`items[${index}].${name}: expected a number with at most ${decimals} decimals`);\n }\n return parsed;\n}\n\n/**\n * Computes the amounts of an invoice from its lines, without the rest of the invoice: useful to show the totals\n * while a form is being filled.\n *\n * - The amount of a line is its `amount`, or its `quantity` (1 when absent) × `unitPrice`, rounded to the centime;\n * a line with neither is a line of text.\n * - The VAT is computed per rate on the sum of the lines at that rate. Prices exclude VAT by default: it is added to\n * the total. With `pricesIncludeVAT`, the VAT is the part of the gross amount that is VAT.\n * - Roundings are commercial (half away from zero), to the centime; the total is rounded to 5 centimes with\n * `roundTo5Centimes`.\n *\n * @param items - The lines of the invoice.\n * @param options - Prices with or without VAT, rounding to 5 centimes.\n * @returns The amount of each line, the subtotal, the VAT per rate (highest rate first), the rounding and the\n * total, as decimal strings.\n * @throws {RangeError} When a quantity, price, rate or amount is not a number with the decimals allowed.\n * @example\n * ```ts\n * computeInvoiceTotals([{ description: 'Advice', quantity: 6, unitPrice: '150', vatRate: '8.1' }]).total; // '972.90'\n * ```\n */\nexport function computeInvoiceTotals(items: readonly InvoiceItem[], options: TotalsOptions = {}): InvoiceTotals {\n const lines = items.map((item, index) => ({\n quantity: readNumber(item.quantity, QUANTITY_DECIMALS, 'quantity', index),\n unitPrice: readNumber(item.unitPrice, UNIT_PRICE_DECIMALS, 'unitPrice', index),\n vatRate: readNumber(item.vatRate, RATE_DECIMALS, 'vatRate', index),\n amount: readNumber(item.amount, AMOUNT_DECIMALS, 'amount', index),\n }));\n return totalsToDecimals(computeTotals(lines, options));\n}\n","/**\n * Reading the fields of an invoice given as `unknown`: each read* function checks one value, reports the problems it\n * finds in an {@link IssueList}, and returns the normalized value, or `undefined` when the value is absent or\n * invalid. Texts are normalized (Unicode NFC, trimmed); blank counts as missing.\n *\n * @module\n */\n\nimport type { IssuePath } from '@qr-bill/core';\nimport type { InvoiceIssue, InvoiceIssueCode } from '../invoice/invoice.types.js';\nimport { parseDecimal, toShortDecimal } from '../amounts/money.js';\n\n/** The problems found so far, in the order of the fields. */\nexport class IssueList {\n /** The problems. */\n readonly list: InvoiceIssue[] = [];\n\n /**\n * Reports a problem.\n *\n * @param code - What the problem is.\n * @param path - Where it is.\n * @param message - An explanation in English.\n */\n add(code: InvoiceIssueCode, path: IssuePath, message: string): void {\n this.list.push({ code, path, message });\n }\n}\n\n/** Characters that never belong in a line: control characters and line separators. */\nconst CONTROL = /[\\p{Cc}\\u2028\\u2029]/u;\n/** The same, except the line feed, which separates the lines of a paragraph. */\nconst CONTROL_EXCEPT_NEWLINE = /(?!\\n)[\\p{Cc}\\u2028\\u2029]/u;\n\n/**\n * Whether a value is absent: `undefined` or `null`.\n *\n * @param value - Any value.\n * @returns `true` when absent.\n */\nexport function isAbsent(value: unknown): value is undefined | null {\n return value === undefined || value === null;\n}\n\n/**\n * Whether a value is absent or a blank string: what a required field must not be.\n *\n * @param value - Any value.\n * @returns `true` when absent or blank.\n */\nexport function isBlank(value: unknown): boolean {\n return isAbsent(value) || (typeof value === 'string' && value.trim() === '');\n}\n\n/**\n * Whether a value is a plain object (not an array, nor the bytes of a file).\n *\n * @param value - Any value.\n * @returns `true` for an object whose properties can be read.\n */\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value) && !(value instanceof Uint8Array);\n}\n\n/**\n * Reads an object that must be present.\n *\n * @param value - The value.\n * @param path - Where it is.\n * @param issues - Where problems are reported: `required` or `invalid_type`.\n * @returns The object, or `undefined`.\n */\nexport function readRecord(value: unknown, path: IssuePath, issues: IssueList): Record<string, unknown> | undefined {\n if (isRecord(value)) return value;\n if (isAbsent(value)) issues.add('required', path, 'Required');\n else issues.add('invalid_type', path, 'Expected an object');\n return undefined;\n}\n\n/**\n * Reads a string, normalized; blank counts as absent.\n *\n * @param value - The value.\n * @param path - Where it is.\n * @param issues - Where problems are reported: `invalid_type`.\n * @returns The text, or `undefined` when absent, blank or not a string.\n */\nexport function readString(value: unknown, path: IssuePath, issues: IssueList): string | undefined {\n if (isAbsent(value)) return undefined;\n if (typeof value !== 'string') {\n issues.add('invalid_type', path, `Expected a string, received ${typeof value}`);\n return undefined;\n }\n const text = value.normalize('NFC').trim();\n return text === '' ? undefined : text;\n}\n\n/** Reports a text longer than its limit, counted in Unicode code points. */\nfunction checkLength(text: string, path: IssuePath, max: number, issues: IssueList): boolean {\n const length = [...text].length;\n if (length <= max) return true;\n issues.add('too_long', path, `At most ${max} characters, received ${length}`);\n return false;\n}\n\n/**\n * Reads a text on one line.\n *\n * @param value - The value.\n * @param path - Where it is.\n * @param max - Its maximum length.\n * @param issues - Where problems are reported: `required`, `invalid_type`, `invalid_characters`, `too_long`.\n * @param required - Whether a blank value is a problem.\n * @returns The text, or `undefined`.\n */\nexport function readLine(\n value: unknown,\n path: IssuePath,\n max: number,\n issues: IssueList,\n required = false,\n): string | undefined {\n if (required && isBlank(value)) {\n issues.add('required', path, 'Required');\n return undefined;\n }\n const text = readString(value, path, issues);\n if (text === undefined) return undefined;\n if (CONTROL.test(text)) {\n issues.add('invalid_characters', path, 'Line breaks and control characters are not allowed in this field');\n return undefined;\n }\n return checkLength(text, path, max, issues) ? text : undefined;\n}\n\n/**\n * Reads a text of several lines separated by line feeds; `\\r\\n` and `\\r` become `\\n`.\n *\n * @param value - The value.\n * @param path - Where it is.\n * @param max - Its maximum length, line feeds included.\n * @param maxLines - Its maximum number of lines.\n * @param issues - Where problems are reported: `required`, `invalid_type`, `invalid_characters`, `too_long`,\n * `too_many_lines`.\n * @param required - Whether a blank value is a problem.\n * @returns The text, or `undefined`.\n */\nexport function readParagraph(\n value: unknown,\n path: IssuePath,\n max: number,\n maxLines: number,\n issues: IssueList,\n required = false,\n): string | undefined {\n if (required && isBlank(value)) {\n issues.add('required', path, 'Required');\n return undefined;\n }\n const raw = readString(value, path, issues);\n if (raw === undefined) return undefined;\n const text = raw.replace(/\\r\\n?/g, '\\n');\n if (CONTROL_EXCEPT_NEWLINE.test(text)) {\n issues.add('invalid_characters', path, 'Control characters are not allowed in this field');\n return undefined;\n }\n if (!checkLength(text, path, max, issues)) return undefined;\n const lines = text.split('\\n').length;\n if (lines > maxLines) {\n issues.add('too_many_lines', path, `At most ${maxLines} lines, received ${lines}`);\n return undefined;\n }\n return text;\n}\n\n/**\n * Reads a list; absent counts as empty.\n *\n * @param value - The value.\n * @param path - Where it is.\n * @param max - Its maximum number of entries.\n * @param issues - Where problems are reported: `invalid_type`, `too_many`.\n * @returns The entries, unchecked; empty when the list is absent or invalid.\n */\nexport function readList(value: unknown, path: IssuePath, max: number, issues: IssueList): unknown[] {\n if (isAbsent(value)) return [];\n if (!Array.isArray(value)) {\n issues.add('invalid_type', path, 'Expected an array');\n return [];\n }\n if (value.length > max) {\n issues.add('too_many', path, `At most ${max} entries, received ${value.length}`);\n return [];\n }\n return value;\n}\n\n/**\n * Reads a list of texts on one line, blank entries being left out.\n *\n * @param value - The value.\n * @param path - Where it is.\n * @param maxLines - The maximum number of entries.\n * @param max - The maximum length of an entry.\n * @param issues - Where problems are reported.\n * @returns The texts.\n */\nexport function readLines(value: unknown, path: IssuePath, maxLines: number, max: number, issues: IssueList): string[] {\n return readList(value, path, maxLines, issues).flatMap((entry, index) => {\n const line = readLine(entry, [...path, index], max, issues);\n return line === undefined ? [] : [line];\n });\n}\n\n/**\n * Reads a boolean.\n *\n * @param value - The value.\n * @param path - Where it is.\n * @param issues - Where problems are reported: `invalid_type`.\n * @returns The boolean, or `undefined` when absent or invalid.\n */\nexport function readBoolean(value: unknown, path: IssuePath, issues: IssueList): boolean | undefined {\n if (isAbsent(value)) return undefined;\n if (typeof value === 'boolean') return value;\n issues.add('invalid_type', path, `Expected a boolean, received ${typeof value}`);\n return undefined;\n}\n\n/**\n * Reads one value among a few allowed.\n *\n * @param value - The value.\n * @param path - Where it is.\n * @param options - The values allowed.\n * @param issues - Where problems are reported: `invalid_option`.\n * @returns The value, or `undefined` when absent or not allowed.\n */\nexport function readOption<T extends string>(\n value: unknown,\n path: IssuePath,\n options: readonly T[],\n issues: IssueList,\n): T | undefined {\n if (isAbsent(value)) return undefined;\n if (options.includes(value as T)) return value as T;\n issues.add('invalid_option', path, `Expected one of ${options.map((option) => `\"${option}\"`).join(', ')}`);\n return undefined;\n}\n\n/** Whether a year, a month (1 to 12) and a day exist in the calendar: not the 30 February. */\nfunction isCalendarDate(year: number, month: number, day: number): boolean {\n const date = new Date(Date.UTC(year, month - 1, day));\n return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;\n}\n\n/**\n * Reads a calendar date written `YYYY-MM-DD`.\n *\n * @param value - The value.\n * @param path - Where it is.\n * @param required - Whether a blank value is a problem.\n * @param issues - Where problems are reported: `required`, `invalid_type`, `invalid_date`.\n * @returns The date as written, or `undefined`.\n */\nexport function readDate(value: unknown, path: IssuePath, required: boolean, issues: IssueList): string | undefined {\n if (required && isBlank(value)) {\n issues.add('required', path, 'Required');\n return undefined;\n }\n const text = readString(value, path, issues);\n if (text === undefined) return undefined;\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(text);\n if (match === null || !isCalendarDate(Number(match[1]), Number(match[2]), Number(match[3]))) {\n issues.add('invalid_date', path, `Expected a date written YYYY-MM-DD, received ${JSON.stringify(text)}`);\n return undefined;\n }\n return text;\n}\n\n/**\n * Reads a decimal number with at most a given number of decimals, within ±limit; blank counts as absent.\n *\n * @param value - The value, a string or a number.\n * @param path - Where it is.\n * @param decimals - The decimals allowed, which are also the unit of the result.\n * @param limit - The largest magnitude allowed, in that unit.\n * @param issues - Where problems are reported: `invalid_number`, `out_of_range`.\n * @returns The number as an integer of that unit, or `undefined`.\n */\nexport function readNumber(\n value: unknown,\n path: IssuePath,\n decimals: number,\n limit: bigint,\n issues: IssueList,\n): bigint | undefined {\n if (isBlank(value)) return undefined;\n const parsed = parseDecimal(value, decimals);\n if (parsed === undefined) {\n issues.add('invalid_number', path, `Expected a number with at most ${decimals} decimals, e.g. \"12.50\"`);\n return undefined;\n }\n if (parsed < -limit || parsed > limit) {\n issues.add('out_of_range', path, `Expected a number within ±${toShortDecimal(limit, decimals)}`);\n return undefined;\n }\n return parsed;\n}\n\n/**\n * Freezes an object and everything in it, except the bytes of a logo, which cannot be frozen.\n *\n * @param value - The object.\n * @returns The same object, frozen.\n */\nexport function deepFreeze<T>(value: T): T {\n if (typeof value === 'object' && value !== null && !(value instanceof Uint8Array)) {\n for (const nested of Object.values(value)) deepFreeze(nested);\n Object.freeze(value);\n }\n return value;\n}\n","/**\n * Maximum lengths of the fields of an invoice. They are chosen so that each text fits in its place on the page:\n * a longer text wraps within its zone, and is shortened with \"…\" only as a last resort. The addresses keep the\n * limits of the QR-bill, since they are also printed on the payment part.\n *\n * @module\n */\n\nimport { ADDRESS_MAX_LENGTH } from '@qr-bill/core';\nimport type { InvoiceLimits } from './limits.types.js';\n\n/**\n * The limits of each field, for the `maxlength` of a form. A longer value is reported by {@link validateInvoice}\n * as `too_long`, `too_many` or `too_many_lines`.\n *\n * @example\n * ```ts\n * INVOICE_LIMITS.issuer.phones; // 2\n * ```\n */\nexport const INVOICE_LIMITS: InvoiceLimits = {\n title: 35,\n number: 35,\n servicePeriod: 50,\n customerReference: 35,\n extraFields: 3,\n extraFieldLabel: 25,\n extraFieldValue: 50,\n subject: 140,\n introduction: 1000,\n introductionLines: 10,\n closing: 1000,\n closingLines: 10,\n issuer: {\n name: ADDRESS_MAX_LENGTH.name,\n street: ADDRESS_MAX_LENGTH.street,\n buildingNumber: ADDRESS_MAX_LENGTH.buildingNumber,\n postalCode: ADDRESS_MAX_LENGTH.postalCode,\n town: ADDRESS_MAX_LENGTH.town,\n extraLines: 2,\n extraLine: 70,\n phones: 2,\n phone: 30,\n email: 70,\n contact: 70,\n },\n recipient: {\n salutation: 35,\n name: ADDRESS_MAX_LENGTH.name,\n street: ADDRESS_MAX_LENGTH.street,\n buildingNumber: ADDRESS_MAX_LENGTH.buildingNumber,\n postalCode: ADDRESS_MAX_LENGTH.postalCode,\n town: ADDRESS_MAX_LENGTH.town,\n extraLines: 2,\n extraLine: 70,\n },\n items: 1000,\n description: 300,\n descriptionLines: 6,\n unit: 10,\n notes: 3,\n note: 300,\n noteLines: 4,\n logoBytes: 2_000_000,\n};\n","/**\n * Validation of the lines of an invoice: their texts, and their numbers read as exact integers.\n *\n * @module\n */\n\nimport { type IssuePath, MAX_AMOUNT } from '@qr-bill/core';\nimport type { ParsedLine } from '../amounts/amounts.types.js';\nimport { toShortDecimal } from '../amounts/money.js';\nimport {\n AMOUNT_DECIMALS,\n MAX_CENTIMES,\n QUANTITY_DECIMALS,\n RATE_DECIMALS,\n UNIT_PRICE_DECIMALS,\n lineAmount,\n} from '../amounts/totals.js';\nimport { type IssueList, isAbsent, isRecord, readLine, readList, readNumber, readParagraph } from '../fields/fields.js';\nimport { INVOICE_LIMITS } from '../invoice/limits.js';\nimport type { InvoiceLine, ItemsRead } from './items.types.js';\n\n/** The largest quantity and unit price: a billion, in their units. */\nconst MAX_QUANTITY = 10n ** BigInt(9 + QUANTITY_DECIMALS);\nconst MAX_UNIT_PRICE = 10n ** BigInt(9 + UNIT_PRICE_DECIMALS);\n/** VAT rates go from 0 to 100 %, in hundredths of a percent. */\nconst MAX_RATE = 100n * 10n ** BigInt(RATE_DECIMALS);\n\n/**\n * Reads the lines of an invoice: from 1 to 1000, each with a description and optional numbers. A line with a\n * quantity needs a unit price or an amount.\n *\n * @param value - The lines, as given.\n * @param issues - Where problems are reported.\n * @returns The lines read, or `undefined` when one of them is invalid.\n */\nexport function readItems(value: unknown, issues: IssueList): ItemsRead | undefined {\n const L = INVOICE_LIMITS;\n if (isAbsent(value) || (Array.isArray(value) && value.length === 0)) {\n issues.add('required', ['items'], 'At least one line is required');\n return undefined;\n }\n const entries = readList(value, ['items'], L.items, issues);\n if (entries.length === 0) return undefined;\n const parsed: ParsedLine[] = [];\n const lines: InvoiceLine[] = [];\n let valid = true;\n for (const [index, entry] of entries.entries()) {\n const path = ['items', index];\n if (!isRecord(entry)) {\n issues.add('invalid_type', path, 'Expected a line object');\n valid = false;\n continue;\n }\n const count = issues.list.length;\n const description = readParagraph(\n entry['description'],\n [...path, 'description'],\n L.description,\n L.descriptionLines,\n issues,\n true,\n );\n const unit = readLine(entry['unit'], [...path, 'unit'], L.unit, issues);\n const line: ParsedLine = {\n quantity: readNumber(entry['quantity'], [...path, 'quantity'], QUANTITY_DECIMALS, MAX_QUANTITY, issues),\n unitPrice: readNumber(entry['unitPrice'], [...path, 'unitPrice'], UNIT_PRICE_DECIMALS, MAX_UNIT_PRICE, issues),\n vatRate: readRate(entry['vatRate'], [...path, 'vatRate'], issues),\n amount: readNumber(entry['amount'], [...path, 'amount'], AMOUNT_DECIMALS, MAX_CENTIMES, issues),\n };\n if (line.quantity !== undefined && line.unitPrice === undefined && line.amount === undefined) {\n issues.add('required', [...path, 'unitPrice'], 'A line with a quantity needs a unit price or an amount');\n }\n const amount = lineAmount(line);\n if (amount !== undefined && (amount < -MAX_CENTIMES || amount > MAX_CENTIMES)) {\n issues.add('out_of_range', [...path, 'amount'], `The amount of the line must stay within ±${MAX_AMOUNT}`);\n }\n if (issues.list.length > count || description === undefined) {\n valid = false;\n continue;\n }\n parsed.push(line);\n lines.push({\n description,\n ...(line.quantity !== undefined && { quantity: toShortDecimal(line.quantity, QUANTITY_DECIMALS) }),\n ...(unit !== undefined && { unit }),\n ...(line.unitPrice !== undefined && { unitPrice: toShortDecimal(line.unitPrice, UNIT_PRICE_DECIMALS, 2) }),\n ...(line.vatRate !== undefined && { vatRate: toShortDecimal(line.vatRate, RATE_DECIMALS) }),\n });\n }\n return valid ? { parsed, lines } : undefined;\n}\n\n/**\n * Reads a VAT rate in percent, from 0 to 100, with at most 2 decimals.\n *\n * @param value - The rate, as given.\n * @param path - Where it is.\n * @param issues - Where problems are reported: `invalid_number`, `out_of_range`.\n * @returns The rate in hundredths of a percent, or `undefined`.\n */\nexport function readRate(value: unknown, path: IssuePath, issues: IssueList): bigint | undefined {\n const rate = readNumber(value, path, RATE_DECIMALS, MAX_RATE, issues);\n if (rate === undefined || rate >= 0n) return rate;\n issues.add('out_of_range', path, 'A VAT rate goes from 0 to 100 %');\n return undefined;\n}\n","/**\n * Validation of totals given by the caller, which are printed as they are instead of being computed.\n *\n * @module\n */\n\nimport type { IssuePath } from '@qr-bill/core';\nimport { type IssueList, isAbsent, isBlank, isRecord, readList, readNumber } from '../fields/fields.js';\nimport { readRate } from '../items/items.validator.js';\nimport type { InvoiceVAT, ProvidedTotals } from './amounts.types.js';\nimport { toDecimal, toShortDecimal } from './money.js';\nimport { AMOUNT_DECIMALS, MAX_CENTIMES, RATE_DECIMALS } from './totals.js';\n\n/** At most one VAT line per rate in use; 10 is plenty. */\nconst MAX_PROVIDED_RATES = 10;\n\n/**\n * Reads totals given by the caller: a total, and optionally a subtotal and the VAT per rate.\n *\n * @param value - The totals, as given.\n * @param issues - Where problems are reported.\n * @returns The totals, or `undefined` when absent or invalid.\n */\nexport function readProvidedTotals(value: unknown, issues: IssueList): ProvidedTotals | undefined {\n if (isAbsent(value)) return undefined;\n if (!isRecord(value)) {\n issues.add('invalid_type', ['totals'], 'Expected an object with at least a total');\n return undefined;\n }\n const amount = (field: unknown, path: IssuePath): bigint | undefined =>\n readNumber(field, path, AMOUNT_DECIMALS, MAX_CENTIMES, issues);\n const count = issues.list.length;\n const subtotal = amount(value['subtotal'], ['totals', 'subtotal']);\n const total = amount(value['total'], ['totals', 'total']);\n if (isBlank(value['total'])) issues.add('required', ['totals', 'total'], 'Required');\n const vat = readList(value['vat'], ['totals', 'vat'], MAX_PROVIDED_RATES, issues).flatMap((entry, index) => {\n const path = ['totals', 'vat', index];\n if (!isRecord(entry)) {\n issues.add('invalid_type', path, 'Expected an object with a rate and an amount');\n return [];\n }\n const rate = readRate(entry['rate'], [...path, 'rate'], issues);\n const base = amount(entry['base'], [...path, 'base']);\n const vatAmount = amount(entry['amount'], [...path, 'amount']);\n if (isBlank(entry['rate'])) issues.add('required', [...path, 'rate'], 'Required');\n if (isBlank(entry['amount'])) issues.add('required', [...path, 'amount'], 'Required');\n if (rate === undefined || vatAmount === undefined) return [];\n const line: InvoiceVAT = {\n rate: toShortDecimal(rate, RATE_DECIMALS),\n ...(base !== undefined && { base: toDecimal(base, AMOUNT_DECIMALS) }),\n amount: toDecimal(vatAmount, AMOUNT_DECIMALS),\n };\n return [line];\n });\n if (issues.list.length > count || total === undefined) return undefined;\n return {\n totals: {\n ...(subtotal !== undefined && { subtotal: toDecimal(subtotal, AMOUNT_DECIMALS) }),\n vat,\n total: toDecimal(total, AMOUNT_DECIMALS),\n },\n total,\n };\n}\n","/**\n * Texts printed on the invoice, in the five languages of the QR-bill. The Romansh texts are a draft, to be reviewed\n * by a native speaker. The VAT number is followed by MWST, TVA or IVA, the suffixes of the Swiss Federal Tax\n * Administration; English and Romansh use MWST.\n *\n * @module\n */\n\nimport type { Language } from '@qr-bill/core';\nimport type { InvoiceLabels } from './labels.types.js';\n\n/** The texts of an invoice, by language. */\nexport const INVOICE_LABELS: Readonly<Record<Language, InvoiceLabels>> = {\n de: {\n invoice: 'Rechnung',\n number: 'Rechnungsnummer',\n date: 'Datum',\n dueDate: 'Fällig am',\n servicePeriod: 'Leistungszeitraum',\n customerReference: 'Ihre Referenz',\n subject: 'Betreff: ',\n description: 'Bezeichnung',\n quantity: 'Menge',\n unit: 'Einheit',\n unitPrice: 'Preis',\n vat: 'MWST',\n amount: 'Betrag',\n subtotal: 'Zwischensumme',\n vatOn: 'MWST {rate} % auf {base}',\n vatIncluded: 'Inkl. MWST {rate} % auf {base}',\n vatRate: 'MWST {rate} %',\n rounding: 'Rundung',\n total: 'Total',\n page: 'Seite {page}/{pages}',\n vatNumberSuffix: 'MWST',\n notVatRegistered: 'Nicht MWST-pflichtig.',\n vatExcluded: 'Von der MWST ausgenommene Leistung.',\n paymentDays: 'Zahlbar innert {days} Tagen.',\n thanks: 'Vielen Dank für Ihr Vertrauen.',\n },\n fr: {\n invoice: 'Facture',\n number: 'N° de facture',\n date: 'Date',\n dueDate: 'Échéance',\n servicePeriod: 'Période',\n customerReference: 'Votre référence',\n subject: 'Objet : ',\n description: 'Désignation',\n quantity: 'Qté',\n unit: 'Unité',\n unitPrice: 'Prix unit.',\n vat: 'TVA',\n amount: 'Montant',\n subtotal: 'Sous-total',\n vatOn: 'TVA {rate} % sur {base}',\n vatIncluded: 'Dont TVA {rate} % sur {base}',\n vatRate: 'TVA {rate} %',\n rounding: 'Arrondi',\n total: 'Total',\n page: 'Page {page}/{pages}',\n vatNumberSuffix: 'TVA',\n notVatRegistered: 'Non assujetti à la TVA.',\n vatExcluded: 'Prestation exclue du champ de la TVA.',\n paymentDays: 'Payable dans les {days} jours.',\n thanks: 'Merci pour votre confiance.',\n },\n it: {\n invoice: 'Fattura',\n number: 'N. fattura',\n date: 'Data',\n dueDate: 'Scadenza',\n servicePeriod: 'Periodo',\n customerReference: 'Vostro riferimento',\n subject: 'Oggetto: ',\n description: 'Descrizione',\n quantity: 'Qtà',\n unit: 'Unità',\n unitPrice: 'Prezzo unit.',\n vat: 'IVA',\n amount: 'Importo',\n subtotal: 'Subtotale',\n vatOn: 'IVA {rate} % su {base}',\n vatIncluded: 'Di cui IVA {rate} % su {base}',\n vatRate: 'IVA {rate} %',\n rounding: 'Arrotondamento',\n total: 'Totale',\n page: 'Pagina {page}/{pages}',\n vatNumberSuffix: 'IVA',\n notVatRegistered: \"Non assoggettato all'IVA.\",\n vatExcluded: \"Prestazione esclusa dall'IVA.\",\n paymentDays: 'Pagabile entro {days} giorni.',\n thanks: 'Grazie per la vostra fiducia.',\n },\n en: {\n invoice: 'Invoice',\n number: 'Invoice no.',\n date: 'Date',\n dueDate: 'Due date',\n servicePeriod: 'Period',\n customerReference: 'Your reference',\n subject: 'Subject: ',\n description: 'Description',\n quantity: 'Qty',\n unit: 'Unit',\n unitPrice: 'Unit price',\n vat: 'VAT',\n amount: 'Amount',\n subtotal: 'Subtotal',\n vatOn: 'VAT {rate} % on {base}',\n vatIncluded: 'Incl. VAT {rate} % on {base}',\n vatRate: 'VAT {rate} %',\n rounding: 'Rounding',\n total: 'Total',\n page: 'Page {page}/{pages}',\n vatNumberSuffix: 'MWST',\n notVatRegistered: 'Not registered for VAT.',\n vatExcluded: 'Supply excluded from VAT.',\n paymentDays: 'Payable within {days} days.',\n thanks: 'Thank you for your trust.',\n },\n rm: {\n invoice: 'Quint',\n number: 'Nr. dal quint',\n date: 'Data',\n dueDate: 'Termin da pajament',\n servicePeriod: 'Perioda',\n customerReference: 'Vossa referenza',\n subject: 'Object: ',\n description: 'Descripziun',\n quantity: 'Quantitad',\n unit: 'Unitad',\n unitPrice: 'Pretsch unitar',\n vat: 'TPV',\n amount: 'Import',\n subtotal: 'Subtotal',\n vatOn: 'TPV {rate} % sin {base}',\n vatIncluded: 'Incl. TPV {rate} % sin {base}',\n vatRate: 'TPV {rate} %',\n rounding: 'Arrundaziun',\n total: 'Total',\n page: 'Pagina {page}/{pages}',\n vatNumberSuffix: 'MWST',\n notVatRegistered: 'Betg suttamess a la TPV.',\n vatExcluded: 'Prestaziun exclusa da la TPV.',\n paymentDays: 'Da pajar entaifer {days} dis.',\n thanks: 'Grazia fitg per Vossa fidanza.',\n },\n};\n\n/**\n * Fills the placeholders of a template, written in braces.\n *\n * @param template - A text of {@link InvoiceLabels} such as `\"VAT {rate} % on {base}\"`.\n * @param values - The value of each placeholder.\n * @returns The text.\n * @example\n * ```ts\n * fill('Page {page}/{pages}', { page: 1, pages: 3 }); // 'Page 1/3'\n * ```\n */\nexport function fill(template: string, values: Readonly<Record<string, string | number>>): string {\n return template.replace(/\\{(\\w+)\\}/g, (placeholder, name: string) => String(values[name] ?? placeholder));\n}\n","/**\n * The Swiss business identification number (UID; IDE in French and Italian): the prefix `CHE`, eight digits and a\n * check digit, written `CHE-123.456.788`. A company registered for VAT uses it as its VAT number, followed by\n * `MWST`, `TVA` or `IVA`. The check digit is a modulo 11 with the weights 5, 4, 3, 2, 7, 6, 5, 4 (standard\n * eCH-0097).\n *\n * @module\n */\n\nconst WEIGHTS = [5, 4, 3, 2, 7, 6, 5, 4] as const;\n\n/**\n * The nine digits of a UID written in a usual way: separators, spaces, lower case and a VAT suffix are accepted.\n *\n * @param value - The UID, e.g. `\"CHE-123.456.788 TVA\"`.\n * @returns The nine digits, or `undefined` when the value does not have the shape of a UID.\n * @example\n * ```ts\n * uidDigits('che-123.456.788 TVA'); // '123456788'\n * ```\n */\nexport function uidDigits(value: string): string | undefined {\n const compact = value\n .normalize('NFC')\n .toUpperCase()\n .replace(/[\\s.-]/g, '')\n .replace(/(MWST|TVA|IVA)$/, '');\n return /^CHE(\\d{9})$/.exec(compact)?.[1];\n}\n\n/**\n * Whether the last of nine digits is the check digit of the eight others. A remainder giving 10 means that no UID\n * uses these eight digits.\n *\n * @param digits - Nine digits, as returned by {@link uidDigits}.\n * @returns `true` when the check digit is right.\n * @example\n * ```ts\n * hasValidCheckDigit('123456788'); // true\n * ```\n */\nexport function hasValidCheckDigit(digits: string): boolean {\n const sum = WEIGHTS.reduce((total, weight, index) => total + weight * Number(digits[index]), 0);\n const check = (11 - (sum % 11)) % 11;\n return check !== 10 && check === Number(digits[8]);\n}\n\n/**\n * Writes a UID in its usual form, `CHE-123.456.788`.\n *\n * @param value - A UID that {@link validateUID} accepts.\n * @returns The UID with its separators, without VAT suffix.\n * @throws {RangeError} When the value is not a valid UID.\n * @example\n * ```ts\n * formatUID('che123456788'); // 'CHE-123.456.788'\n * ```\n */\nexport function formatUID(value: string): string {\n const digits = uidDigits(value);\n if (digits === undefined || !hasValidCheckDigit(digits)) {\n throw new RangeError(`Invalid UID: ${JSON.stringify(value)}`);\n }\n return `CHE-${digits.slice(0, 3)}.${digits.slice(3, 6)}.${digits.slice(6)}`;\n}\n","/**\n * Validator of the Swiss business identification number (UID).\n *\n * @module\n */\n\nimport { hasValidCheckDigit, uidDigits } from './uid.js';\nimport type { UIDStatus } from './uid.types.js';\n\n/**\n * Validates a Swiss business identification number (UID): its shape and its check digit. Separators, spaces, lower\n * case and a VAT suffix (`MWST`, `TVA`, `IVA`) are accepted. Blank counts as missing.\n *\n * @param value - The UID as typed.\n * @returns `'valid'`, `'required'` when blank, or `'invalid_uid'`.\n * @example\n * ```ts\n * validateUID('CHE-123.456.788'); // 'valid'\n * validateUID('che 123 456 788 tva'); // 'valid'\n * validateUID('CHE-123.456.789'); // 'invalid_uid': wrong check digit\n * validateUID(' '); // 'required'\n * ```\n */\nexport function validateUID(value: string | null | undefined): UIDStatus {\n const text = (value ?? '').trim();\n if (text === '') return 'required';\n const digits = uidDigits(text);\n return digits !== undefined && hasValidCheckDigit(digits) ? 'valid' : 'invalid_uid';\n}\n","/**\n * Validation of the issuer and the recipient. Their names and structured addresses are checked with the validators\n * of the QR-bill, since they are also the creditor and the debtor of the payment part.\n *\n * @module\n */\n\nimport {\n type Address,\n type IssuePath,\n type TextStatus,\n validateBuildingNumber,\n validateCountry,\n validateName,\n validatePostalCode,\n validateStreet,\n validateTown,\n} from '@qr-bill/core';\nimport {\n type IssueList,\n isAbsent,\n readBoolean,\n readLine,\n readLines,\n readRecord,\n readString,\n} from '../fields/fields.js';\nimport { INVOICE_LIMITS } from '../invoice/limits.js';\nimport { formatUID } from '../uid/uid.js';\nimport { validateUID } from '../uid/uid.validator.js';\nimport type { InvoiceIssuerData, InvoiceLogo, InvoiceRecipientData } from './parties.types.js';\n\n/** A field of an address, checked by the validator of the QR-bill. */\nfunction readAddressField(\n value: unknown,\n path: IssuePath,\n validate: (text: string) => TextStatus,\n max: number,\n issues: IssueList,\n): string | undefined {\n if (!isAbsent(value) && typeof value !== 'string') {\n issues.add('invalid_type', path, `Expected a string, received ${typeof value}`);\n return undefined;\n }\n const text = (value ?? '').normalize('NFC').trim();\n const status = validate(text);\n if (status === 'valid') return text === '' ? undefined : text;\n const messages = {\n required: 'Required',\n invalid_characters: 'Characters not allowed on the payment part of a QR-bill',\n too_long: `At most ${max} characters, received ${[...text].length}`,\n };\n issues.add(status, path, messages[status]);\n return undefined;\n}\n\n/** The structured address of the issuer or the recipient, with the rules of the QR-bill. */\nfunction readAddress(value: Record<string, unknown>, path: IssuePath, issues: IssueList): Address | undefined {\n const L = INVOICE_LIMITS.recipient;\n const name = readAddressField(value['name'], [...path, 'name'], validateName, L.name, issues);\n const street = readAddressField(value['street'], [...path, 'street'], validateStreet, L.street, issues);\n const buildingNumber = readAddressField(\n value['buildingNumber'],\n [...path, 'buildingNumber'],\n validateBuildingNumber,\n L.buildingNumber,\n issues,\n );\n const postalCode = readAddressField(\n value['postalCode'],\n [...path, 'postalCode'],\n validatePostalCode,\n L.postalCode,\n issues,\n );\n const town = readAddressField(value['town'], [...path, 'town'], validateTown, L.town, issues);\n const country = readCountry(value['country'], [...path, 'country'], issues);\n if (name === undefined || postalCode === undefined || town === undefined || country === undefined) return undefined;\n return {\n name,\n ...(street !== undefined && { street }),\n ...(buildingNumber !== undefined && { buildingNumber }),\n postalCode,\n town,\n country,\n };\n}\n\nfunction readCountry(value: unknown, path: IssuePath, issues: IssueList): string | undefined {\n if (!isAbsent(value) && typeof value !== 'string') {\n issues.add('invalid_type', path, `Expected a string, received ${typeof value}`);\n return undefined;\n }\n const text = value ?? '';\n const status = validateCountry(text);\n if (status === 'valid') return text.trim().toUpperCase();\n issues.add(status, path, status === 'required' ? 'Required' : 'Expected a two-letter ISO 3166-1 country code');\n return undefined;\n}\n\n/**\n * Reads the issuer: its name and address with the rules of the QR-bill, its logo, its contacts and its UID.\n *\n * @param value - The issuer, as given.\n * @param issues - Where problems are reported.\n * @returns The issuer, normalized, or `undefined` when its name or address is invalid.\n */\nexport function readIssuer(value: unknown, issues: IssueList): InvoiceIssuerData | undefined {\n const record = readRecord(value, ['issuer'], issues);\n if (record === undefined) return undefined;\n const L = INVOICE_LIMITS.issuer;\n const address = readAddress(record, ['issuer'], issues);\n const logo = readLogo(record['logo'], issues);\n const extraLines = readLines(record['extraLines'], ['issuer', 'extraLines'], L.extraLines, L.extraLine, issues);\n const phones = readLines(record['phones'], ['issuer', 'phones'], L.phones, L.phone, issues);\n const email = readEmail(record['email'], issues);\n const contact = readLine(record['contact'], ['issuer', 'contact'], L.contact, issues);\n const uid = readUID(record['uid'], issues);\n const vatRegistered = readBoolean(record['vatRegistered'], ['issuer', 'vatRegistered'], issues);\n if (address === undefined) return undefined;\n return {\n ...address,\n ...(logo !== undefined && { logo }),\n extraLines,\n phones,\n ...(email !== undefined && { email }),\n ...(contact !== undefined && { contact }),\n ...(uid !== undefined && { uid }),\n vatRegistered: vatRegistered ?? false,\n };\n}\n\n/**\n * Reads the recipient: its name and address with the rules of the QR-bill, its salutation and its extra lines.\n *\n * @param value - The recipient, as given.\n * @param issues - Where problems are reported.\n * @returns The recipient, normalized, or `undefined` when its name or address is invalid.\n */\nexport function readRecipient(value: unknown, issues: IssueList): InvoiceRecipientData | undefined {\n const record = readRecord(value, ['recipient'], issues);\n if (record === undefined) return undefined;\n const L = INVOICE_LIMITS.recipient;\n const salutation = readLine(record['salutation'], ['recipient', 'salutation'], L.salutation, issues);\n const address = readAddress(record, ['recipient'], issues);\n const extraLines = readLines(record['extraLines'], ['recipient', 'extraLines'], L.extraLines, L.extraLine, issues);\n if (address === undefined) return undefined;\n return { ...(salutation !== undefined && { salutation }), ...address, extraLines };\n}\n\n/** The first bytes of a PNG file. */\nconst PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a] as const;\n\n/** The first bytes of a JPEG file. */\nconst JPEG_SIGNATURE = [0xff, 0xd8, 0xff] as const;\n\n/** A logo: the bytes of a PNG or JPEG file, recognized from their first bytes. */\nfunction readLogo(value: unknown, issues: IssueList): InvoiceLogo | undefined {\n if (isAbsent(value)) return undefined;\n const path = ['issuer', 'logo'];\n if (!(value instanceof Uint8Array)) {\n issues.add('invalid_type', path, 'Expected the bytes of a PNG or JPEG file (a Uint8Array or a Buffer)');\n return undefined;\n }\n if (value.length > INVOICE_LIMITS.logoBytes) {\n issues.add('logo_too_large', path, `At most ${INVOICE_LIMITS.logoBytes} bytes, received ${value.length}`);\n return undefined;\n }\n const starts = (signature: readonly number[]): boolean => signature.every((byte, index) => value[index] === byte);\n const format = starts(PNG_SIGNATURE) ? 'png' : starts(JPEG_SIGNATURE) ? 'jpeg' : undefined;\n if (format === undefined) {\n issues.add('unsupported_logo', path, 'Expected a PNG or JPEG file');\n return undefined;\n }\n return { format, bytes: value };\n}\n\nfunction readEmail(value: unknown, issues: IssueList): string | undefined {\n const path = ['issuer', 'email'];\n const email = readLine(value, path, INVOICE_LIMITS.issuer.email, issues);\n if (email === undefined || /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/u.test(email)) return email;\n issues.add('invalid_email', path, `Expected an e-mail address, received ${JSON.stringify(email)}`);\n return undefined;\n}\n\nfunction readUID(value: unknown, issues: IssueList): string | undefined {\n const path = ['issuer', 'uid'];\n const text = readString(value, path, issues);\n if (text === undefined) return undefined;\n if (validateUID(text) === 'valid') return formatUID(text);\n issues.add('invalid_uid', path, `Expected a UID such as \"CHE-123.456.788\" with its check digit`);\n return undefined;\n}\n","/**\n * The `business` theme: the title and the total in the accent colour, and the table header in a band filled with\n * it. Dark blue by default.\n *\n * @module\n */\n\nimport type { ThemeDefinition } from './themes.types.js';\n\n/** The `business` theme. */\nexport const BUSINESS_THEME: ThemeDefinition = {\n name: 'business',\n accent: '#1F3A5F',\n accentTitle: true,\n tableHeader: 'band',\n stripedRows: false,\n topBar: false,\n accentTotal: true,\n};\n","/**\n * Colours written `#RRGGBB`: tints mixed with white, and the contrast between two colours as defined by WCAG 2\n * (relative luminance, ratio from 1 to 21). A text is readable when its contrast with its background is at least\n * 4.5:1, the level AA of WCAG for normal text.\n *\n * @module\n */\n\n/** The contrast a text needs on its background: level AA of WCAG 2 for normal text. */\nexport const MINIMUM_CONTRAST = 4.5;\n\n/**\n * The red, green and blue of a colour.\n *\n * @param color - A colour written `#RRGGBB`.\n * @returns The three channels, from 0 to 255.\n */\nfunction channels(color: string): [number, number, number] {\n return [1, 3, 5].map((start) => parseInt(color.slice(start, start + 2), 16)) as [number, number, number];\n}\n\n/**\n * Writes three channels as `#RRGGBB`, in upper case.\n *\n * @param values - Red, green and blue, rounded and kept within 0 to 255.\n * @returns The colour.\n */\nfunction toHex(values: readonly number[]): string {\n const hex = values.map((value) =>\n Math.min(255, Math.max(0, Math.round(value)))\n .toString(16)\n .padStart(2, '0'),\n );\n return `#${hex.join('')}`.toUpperCase();\n}\n\n/**\n * Mixes a colour with another one: with a share of 1 the result is the colour, with 0 the other one.\n *\n * @param color - The colour, `#RRGGBB`.\n * @param background - The colour it is mixed with, usually white.\n * @param share - The share of the colour, from 0 to 1.\n * @returns The mixed colour.\n * @example\n * ```ts\n * mix('#1F3A5F', '#FFFFFF', 0.5); // '#8F9DAF'\n * ```\n */\nexport function mix(color: string, background: string, share: number): string {\n const [red, green, blue] = channels(color);\n const [baseRed, baseGreen, baseBlue] = channels(background);\n return toHex([\n baseRed + (red - baseRed) * share,\n baseGreen + (green - baseGreen) * share,\n baseBlue + (blue - baseBlue) * share,\n ]);\n}\n\n/**\n * The relative luminance of a colour, from 0 (black) to 1 (white), as WCAG 2 defines it.\n *\n * @param color - The colour, `#RRGGBB`.\n * @returns The luminance.\n */\nexport function luminance(color: string): number {\n const [red, green, blue] = channels(color).map((value) => {\n const share = value / 255;\n return share <= 0.04045 ? share / 12.92 : ((share + 0.055) / 1.055) ** 2.4;\n }) as [number, number, number];\n return 0.2126 * red + 0.7152 * green + 0.0722 * blue;\n}\n\n/**\n * The contrast between two colours, from 1 (the same luminance) to 21 (black on white), as WCAG 2 defines it.\n *\n * @param first - A colour, `#RRGGBB`.\n * @param second - Another colour.\n * @returns The contrast ratio.\n * @example\n * ```ts\n * contrastRatio('#000000', '#FFFFFF'); // 21\n * ```\n */\nexport function contrastRatio(first: string, second: string): number {\n const [lighter, darker] = [luminance(first), luminance(second)].sort((a, b) => b - a) as [number, number];\n return (lighter + 0.05) / (darker + 0.05);\n}\n\n/**\n * Darkens a colour by steps of 5 % until it is readable on a light background, where black always is.\n *\n * @param color - The colour of the text, `#RRGGBB`.\n * @param background - A light background, e.g. white or a tint.\n * @returns The colour itself when it is readable already, otherwise the first darker step that is.\n * @example\n * ```ts\n * readableOn('#1F3A5F', '#FFFFFF'); // '#1F3A5F': dark enough already\n * readableOn('#F59E0B', '#FFFFFF'); // '#9F6707': amber, darkened to a contrast of 4.75\n * ```\n */\nexport function readableOn(color: string, background: string): string {\n let darker = color;\n for (let step = 1; contrastRatio(darker, background) < MINIMUM_CONTRAST && step <= 20; step++) {\n darker = mix(color, '#000000', 1 - step * 0.05);\n }\n return darker;\n}\n","/**\n * The `modern` theme: a thin bar of the accent colour along the top of each page, the title and the total in that\n * colour, the table header in a light tint of it, and every other row lightly tinted. Teal by default.\n *\n * @module\n */\n\nimport type { ThemeDefinition } from './themes.types.js';\n\n/** The `modern` theme. */\nexport const MODERN_THEME: ThemeDefinition = {\n name: 'modern',\n accent: '#0F766E',\n accentTitle: true,\n tableHeader: 'tint',\n stripedRows: true,\n topBar: true,\n accentTotal: true,\n};\n","/**\n * The `standard` theme, the default: black text and grey rules, sober. The accent colours only the rules of the\n * table header and of the total.\n *\n * @module\n */\n\nimport type { ThemeDefinition } from './themes.types.js';\n\n/** The `standard` theme. */\nexport const STANDARD_THEME: ThemeDefinition = {\n name: 'standard',\n accent: '#555555',\n accentTitle: false,\n tableHeader: 'rule',\n stripedRows: false,\n topBar: false,\n accentTotal: false,\n};\n","/**\n * The themes of the invoice and the colours computed from them. A theme changes only the look of the invoice (the\n * title, the table header, the rows of the table, the total, a bar along the top of the pages), never its layout:\n * positions, limits and the payment part stay the same. The payment part is always black on white, as the style\n * guide of the QR-bill requires.\n *\n * @module\n */\n\nimport { BUSINESS_THEME } from './business.js';\nimport { MINIMUM_CONTRAST, contrastRatio, mix, readableOn } from './color.js';\nimport { MODERN_THEME } from './modern.js';\nimport { STANDARD_THEME } from './standard.js';\nimport type { InvoiceThemeData, ThemeColors, ThemeDefinition, ThemeName } from './themes.types.js';\n\n/**\n * The names of the themes, for a selector: `standard` (black and grey, the default), `business` (a filled band of\n * colour), `modern` (light tints).\n *\n * @example\n * ```ts\n * INVOICE_THEMES.length; // 3\n * ```\n */\nexport const INVOICE_THEMES: readonly ThemeName[] = ['standard', 'business', 'modern'];\n\n/** Each theme by its name. */\nexport const THEMES: Readonly<Record<ThemeName, ThemeDefinition>> = {\n standard: STANDARD_THEME,\n business: BUSINESS_THEME,\n modern: MODERN_THEME,\n};\n\nconst BLACK = '#000000';\nconst WHITE = '#FFFFFF';\n/** Share of the accent in the tint of a table header, and in the tint of a striped row. */\nconst HEADER_TINT = 0.14;\nconst STRIPE_TINT = 0.05;\n\n/**\n * Computes the colours of an invoice from its theme and accent. Every text stays readable, with a contrast of at\n * least 4.5:1 on its background: a text written in the accent colour is darkened if needed, and the text of a band\n * filled with the accent is white, or black when the accent is too light for white.\n *\n * @param theme - The theme of the invoice and its accent, if one was given.\n * @returns The colours of each part of the invoice.\n * @example\n * ```ts\n * resolveTheme({ name: 'business' }).tableHeaderBackground; // '#1F3A5F'\n * resolveTheme({ name: 'business', accent: '#FDE047' }).tableHeaderText; // '#000000': yellow is too light for white\n * ```\n */\nexport function resolveTheme(theme: InvoiceThemeData): ThemeColors {\n const definition = THEMES[theme.name];\n const accent = theme.accent ?? definition.accent;\n const readableAccent = readableOn(accent, WHITE);\n let header: Pick<ThemeColors, 'tableHeaderText' | 'tableHeaderBackground' | 'tableHeaderRule'>;\n if (definition.tableHeader === 'band') {\n // White when it is readable on the accent; otherwise black, which then always is.\n const white = contrastRatio(WHITE, accent) >= MINIMUM_CONTRAST;\n header = { tableHeaderBackground: accent, tableHeaderText: white ? WHITE : BLACK };\n } else if (definition.tableHeader === 'tint') {\n const tint = mix(accent, WHITE, HEADER_TINT);\n header = { tableHeaderBackground: tint, tableHeaderText: readableOn(accent, tint) };\n } else {\n header = { tableHeaderRule: accent, tableHeaderText: BLACK };\n }\n return {\n text: BLACK,\n muted: '#595959',\n line: '#DDDDDD',\n title: definition.accentTitle ? readableAccent : BLACK,\n ...header,\n ...(definition.stripedRows && { stripe: mix(accent, WHITE, STRIPE_TINT) }),\n total: definition.accentTotal ? readableAccent : BLACK,\n totalRule: accent,\n ...(definition.topBar && { topBar: accent }),\n };\n}\n","/**\n * Validation of the theme of an invoice: its name, and its accent colour written `#RRGGBB`.\n *\n * @module\n */\n\nimport { type IssueList, isAbsent, isRecord, readOption } from '../fields/fields.js';\nimport { INVOICE_THEMES } from './themes.js';\nimport type { InvoiceThemeData, ThemeName } from './themes.types.js';\n\n/**\n * Reads the theme: the name of a theme, or an object with a name and an accent colour.\n *\n * @param value - The theme, as given.\n * @param issues - Where problems are reported: `invalid_type`, `invalid_option`, `invalid_color`.\n * @returns The theme; `standard` when absent or invalid.\n */\nexport function readTheme(value: unknown, issues: IssueList): InvoiceThemeData {\n if (isAbsent(value)) return { name: 'standard' };\n const record = typeof value === 'string' ? { name: value } : value;\n if (!isRecord(record)) {\n issues.add('invalid_type', ['theme'], 'Expected the name of a theme or an object with a name and an accent');\n return { name: 'standard' };\n }\n const path = typeof value === 'string' ? ['theme'] : ['theme', 'name'];\n const name = readOption<ThemeName>(record['name'], path, INVOICE_THEMES, issues) ?? 'standard';\n const accent = record['accent'];\n if (isAbsent(accent)) return { name };\n if (typeof accent === 'string' && /^#[0-9a-f]{6}$/iu.test(accent.trim())) {\n return { name, accent: accent.trim().toUpperCase() };\n }\n issues.add('invalid_color', ['theme', 'accent'], 'Expected a colour written #RRGGBB, e.g. \"#1F3A5F\"');\n return { name };\n}\n","/**\n * Validation of an invoice. Only the form is checked: types, lengths, numbers, dates, UID, e-mail, and the QR-bill\n * of the payment part, which must be valid. What the invoice says is the issuer's business: no legal mention is\n * required. Every problem is reported at once, with a stable code and the path of the field.\n *\n * @module\n */\n\nimport {\n type Address,\n type Currency,\n type IssuePath,\n LABELS,\n type Language,\n MAX_AMOUNT,\n type QRBill,\n type QRBillInput,\n isValidCurrency,\n validateQRBill,\n} from '@qr-bill/core';\nimport type { InvoiceTotals } from '../amounts/amounts.types.js';\nimport { toDecimal } from '../amounts/money.js';\nimport { AMOUNT_DECIMALS, MAX_CENTIMES, computeTotals, totalsToDecimals } from '../amounts/totals.js';\nimport { readProvidedTotals } from '../amounts/totals.validator.js';\nimport {\n IssueList,\n deepFreeze,\n isAbsent,\n isRecord,\n readBoolean,\n readDate,\n readLine,\n readList,\n readOption,\n readParagraph,\n} from '../fields/fields.js';\nimport { readItems } from '../items/items.validator.js';\nimport { INVOICE_LABELS } from '../labels/labels.js';\nimport { readIssuer, readRecipient } from '../parties/parties.validator.js';\nimport { readTheme } from '../themes/themes.validator.js';\nimport type {\n AddressWindow,\n AmountFormat,\n Invoice,\n InvoiceField,\n InvoiceMentions,\n InvoiceResult,\n} from './invoice.types.js';\nimport { INVOICE_LIMITS } from './limits.js';\n\n/**\n * Validates and normalizes an invoice without throwing.\n *\n * Accepts `unknown`, so that a request body can be passed as is. The issuer and the recipient are checked with the\n * validators of the QR-bill, since they are also the creditor and the debtor of the payment part; the payment part\n * is checked by `validateQRBill` of `@qr-bill/core`, with the total of the invoice as its amount. Its codes are\n * reused for these fields.\n *\n * @param input - The invoice to check, normally an {@link InvoiceInput}.\n * @returns Either `{ success: true, data }`, where `data` is the normalized, frozen {@link Invoice} with its totals\n * and its QR-bill, or `{ success: false, issues }` listing every problem found.\n * @example\n * ```ts\n * const result = validateInvoice(requestBody);\n * if (!result.success) {\n * result.issues; // [{ code: 'invalid_uid', path: ['issuer', 'uid'], message: '…' }, …]\n * }\n * ```\n */\nexport function validateInvoice(input: unknown): InvoiceResult {\n if (!isRecord(input)) {\n return { success: false, issues: [{ code: 'invalid_type', path: [], message: 'Expected an invoice object' }] };\n }\n const issues = new IssueList();\n const L = INVOICE_LIMITS;\n\n const language = readLanguage(input['language'], issues);\n const currency = readCurrency(input['currency'], issues);\n const title = readLine(input['title'], ['title'], L.title, issues);\n const number = readLine(input['number'], ['number'], L.number, issues);\n const date = readDate(input['date'], ['date'], true, issues);\n const dueDate = readDate(input['dueDate'], ['dueDate'], false, issues);\n const servicePeriod = readLine(input['servicePeriod'], ['servicePeriod'], L.servicePeriod, issues);\n const customerReference = readLine(input['customerReference'], ['customerReference'], L.customerReference, issues);\n const extraFields = readExtraFields(input['extraFields'], issues);\n const subject = readLine(input['subject'], ['subject'], L.subject, issues);\n const introduction = readParagraph(\n input['introduction'],\n ['introduction'],\n L.introduction,\n L.introductionLines,\n issues,\n );\n const closing = readParagraph(input['closing'], ['closing'], L.closing, L.closingLines, issues);\n const issuer = readIssuer(input['issuer'], issues);\n const recipient = readRecipient(input['recipient'], issues);\n const items = readItems(input['items'], issues);\n const pricesIncludeVAT = readBoolean(input['pricesIncludeVAT'], ['pricesIncludeVAT'], issues);\n const roundTo5Centimes = readBoolean(input['roundTo5Centimes'], ['roundTo5Centimes'], issues);\n const providedTotals = readProvidedTotals(input['totals'], issues);\n const mentions = readMentions(input['mentions'], issues);\n const notes = readNotes(input['notes'], issues);\n const amountFormat = readOption<AmountFormat>(\n input['amountFormat'],\n ['amountFormat'],\n ['space', 'apostrophe'],\n issues,\n );\n const addressWindow = readOption<AddressWindow>(input['addressWindow'], ['addressWindow'], ['left', 'right'], issues);\n const theme = readTheme(input['theme'], issues);\n\n // The amounts: given, or computed from the lines.\n let totals: InvoiceTotals | undefined;\n let total: bigint | undefined;\n if (items !== undefined) {\n const computed = computeTotals(items.parsed, { pricesIncludeVAT, roundTo5Centimes });\n if (providedTotals === undefined) {\n totals = totalsToDecimals(computed);\n total = computed.total;\n } else {\n totals = { lines: totalsToDecimals(computed).lines, ...providedTotals.totals };\n total = providedTotals.total;\n }\n if (total < -MAX_CENTIMES || total > MAX_CENTIMES) {\n issues.add('out_of_range', ['items'], `The total must stay within ±${MAX_AMOUNT}`);\n }\n }\n\n // The payment part, whose amount is the total of the invoice.\n const bill = readPayment(input, { language, currency, title, number, total }, issues);\n\n if (\n issues.list.length > 0 ||\n language === undefined ||\n date === undefined ||\n issuer === undefined ||\n recipient === undefined ||\n items === undefined ||\n totals === undefined\n ) {\n return { success: false, issues: issues.list };\n }\n const invoice: Invoice = {\n language,\n currency: currency ?? 'CHF',\n title: title ?? INVOICE_LABELS[language].invoice,\n ...(number !== undefined && { number }),\n date,\n ...(dueDate !== undefined && { dueDate }),\n ...(servicePeriod !== undefined && { servicePeriod }),\n ...(customerReference !== undefined && { customerReference }),\n extraFields,\n ...(subject !== undefined && { subject }),\n ...(introduction !== undefined && { introduction }),\n ...(closing !== undefined && { closing }),\n issuer,\n recipient,\n lines: items.lines,\n pricesIncludeVAT: pricesIncludeVAT ?? false,\n totals,\n totalsProvided: providedTotals !== undefined,\n mentions,\n notes,\n amountFormat: amountFormat ?? 'space',\n addressWindow: addressWindow ?? 'left',\n theme,\n ...(bill !== undefined && { bill }),\n };\n return { success: true, data: deepFreeze(invoice) };\n}\n\nfunction readLanguage(value: unknown, issues: IssueList): Language | undefined {\n if (typeof value === 'string' && Object.hasOwn(LABELS, value)) return value as Language;\n issues.add('invalid_language', ['language'], 'Expected \"de\", \"fr\", \"it\", \"rm\" or \"en\"');\n return undefined;\n}\n\nfunction readCurrency(value: unknown, issues: IssueList): Currency | undefined {\n if (isAbsent(value)) return undefined;\n if (isValidCurrency(value)) return value;\n issues.add('invalid_currency', ['currency'], 'Currency must be \"CHF\" or \"EUR\"');\n return undefined;\n}\n\nfunction readExtraFields(value: unknown, issues: IssueList): InvoiceField[] {\n const L = INVOICE_LIMITS;\n return readList(value, ['extraFields'], L.extraFields, issues).flatMap((entry, index) => {\n const path = ['extraFields', index];\n if (!isRecord(entry)) {\n issues.add('invalid_type', path, 'Expected an object with a label and a value');\n return [];\n }\n const label = readLine(entry['label'], [...path, 'label'], L.extraFieldLabel, issues, true);\n const fieldValue = readLine(entry['value'], [...path, 'value'], L.extraFieldValue, issues, true);\n return label === undefined || fieldValue === undefined ? [] : [{ label, value: fieldValue }];\n });\n}\n\nfunction readMentions(value: unknown, issues: IssueList): InvoiceMentions {\n if (isAbsent(value)) return {};\n if (!isRecord(value)) {\n issues.add('invalid_type', ['mentions'], 'Expected an object');\n return {};\n }\n const notVatRegistered = readBoolean(value['notVatRegistered'], ['mentions', 'notVatRegistered'], issues);\n const vatExcluded = readBoolean(value['vatExcluded'], ['mentions', 'vatExcluded'], issues);\n const thanks = readBoolean(value['thanks'], ['mentions', 'thanks'], issues);\n const days = value['paymentDays'];\n let paymentDays: number | undefined;\n if (!isAbsent(days)) {\n if (typeof days === 'number' && Number.isInteger(days) && days >= 1 && days <= 365) paymentDays = days;\n else issues.add('invalid_number', ['mentions', 'paymentDays'], 'Expected a whole number of days from 1 to 365');\n }\n return {\n ...(notVatRegistered !== undefined && { notVatRegistered }),\n ...(vatExcluded !== undefined && { vatExcluded }),\n ...(paymentDays !== undefined && { paymentDays }),\n ...(thanks !== undefined && { thanks }),\n };\n}\n\n/** The free remarks, blank ones being left out. */\nfunction readNotes(value: unknown, issues: IssueList): string[] {\n const path = ['notes'];\n const L = INVOICE_LIMITS;\n return readList(value, path, L.notes, issues).flatMap((entry, index) => {\n const note = readParagraph(entry, [...path, index], L.note, L.noteLines, issues);\n return note === undefined ? [] : [note];\n });\n}\n\n// ---- The payment part ----\n\n/** What the payment part needs from the rest of the invoice. */\ninterface PaymentContext {\n readonly language: Language | undefined;\n readonly currency: Currency | undefined;\n readonly title: string | undefined;\n readonly number: string | undefined;\n readonly total: bigint | undefined;\n}\n\n/**\n * Checks the payment part with `validateQRBill`, the issuer and the recipient being the creditor and the debtor,\n * and the total the amount. A total of 0.00 is a notification (chapter 4.4): its message becomes \"DO NOT USE FOR\n * PAYMENT\" in the language of the invoice. A negative total (a credit note) has no payment part.\n */\nfunction readPayment(input: Record<string, unknown>, context: PaymentContext, issues: IssueList): QRBill | undefined {\n const value = input['payment'];\n if (isAbsent(value)) return undefined;\n if (!isRecord(value)) {\n issues.add('invalid_type', ['payment'], 'Expected an object with at least an account');\n return undefined;\n }\n const issuer = isRecord(input['issuer']) ? input['issuer'] : {};\n const recipient = isRecord(input['recipient']) ? input['recipient'] : undefined;\n const { language, total } = context;\n // The amount is checked with the lines; the payment part only receives a valid one. A total of 0.00 needs the\n // language of the notification text.\n const notification = total === 0n && language !== undefined;\n const payable = total !== undefined && total > 0n && total <= MAX_CENTIMES;\n const defaultMessage =\n context.number === undefined\n ? undefined\n : `${context.title ?? INVOICE_LABELS[language ?? 'en'].invoice} ${context.number}`;\n const qrInput: Record<keyof QRBillInput, unknown> = {\n currency: context.currency ?? 'CHF',\n creditor: { ...addressFields(issuer), account: value['account'] },\n debtor: recipient === undefined ? undefined : addressFields(recipient),\n amount: total !== undefined && (payable || notification) ? toDecimal(total, AMOUNT_DECIMALS) : undefined,\n reference: value['reference'],\n message: notification ? LABELS[language].doNotUseForPayment : (value['message'] ?? defaultMessage),\n billingInformation: value['billingInformation'],\n alternativeProcedures: undefined,\n };\n const result = validateQRBill(qrInput);\n if (result.success) return total !== undefined && total < 0n ? undefined : result.data;\n for (const issue of result.issues) {\n const path = paymentPath(issue.path);\n // The addresses are checked, and reported, with the issuer and the recipient.\n if (path !== undefined) issues.add(issue.code, path, issue.message);\n }\n return undefined;\n}\n\n/** The fields of an address, as given, for the QR-bill. */\nfunction addressFields(record: Record<string, unknown>): Record<keyof Address, unknown> {\n return {\n name: record['name'],\n street: record['street'],\n buildingNumber: record['buildingNumber'],\n postalCode: record['postalCode'],\n town: record['town'],\n country: record['country'],\n };\n}\n\n/** Where a problem of the QR-bill is in the invoice; `undefined` for the addresses, reported elsewhere. */\nfunction paymentPath(path: IssuePath): IssuePath | undefined {\n const [first, second] = path;\n if (first === 'creditor') return second === 'account' ? ['payment', 'account'] : undefined;\n if (first === 'debtor') return undefined;\n if (first === 'currency') return ['currency'];\n return ['payment', ...path];\n}\n","/**\n * What every page carries once the whole invoice is drawn and the number of pages known: the bar of colour along\n * the top (theme `modern`), and the number of the page when there are several.\n *\n * @module\n */\n\nimport { POINTS_PER_MM } from '@qr-bill/pdfkit';\nimport type { RenderContext } from '../drawing/drawing.types.js';\nimport { fill } from '../labels/labels.js';\nimport { RIGHT } from './page.js';\n\n/** The height of the bar along the top of each page. */\nconst TOP_BAR_HEIGHT = 3;\n/** The number of the page: baseline and size. */\nconst PAGE_NUMBER_BASELINE = 10;\nconst PAGE_NUMBER_SIZE = 7.5;\n\n/**\n * Draws the bar of colour and the number of each page, going back to every page of the document.\n *\n * @param context - The invoice drawn, whose document keeps its pages in memory (`bufferPages`).\n */\nexport function drawPageDecorations(context: RenderContext): void {\n const { pen, colors, labels } = context;\n const { doc } = pen;\n const { count } = doc.bufferedPageRange();\n for (let page = 0; page < count; page++) {\n doc.switchToPage(page);\n if (colors.topBar !== undefined) pen.rect(0, 0, doc.page.width / POINTS_PER_MM, TOP_BAR_HEIGHT, colors.topBar);\n if (count > 1) {\n const number = fill(labels.page, { page: page + 1, pages: count });\n pen.text(number, RIGHT, PAGE_NUMBER_BASELINE, { size: PAGE_NUMBER_SIZE, color: colors.muted, align: 'right' });\n }\n }\n}\n","/**\n * The flow of the content from page to page: blocks that go to a new page when they do not fit, and paragraphs that\n * continue on the next page line by line.\n *\n * @module\n */\n\nimport type { InvoiceDocument } from '../drawing/drawing.types.js';\nimport { CONTENT_BOTTOM, CONTINUED_TOP } from './page.js';\n\n/** Where the baseline of a line sits under its top, as a share of the line height. */\nconst BASELINE_SHARE = 0.76;\n\n/**\n * Where the next content goes: the current page and the height on it. A block that does not fit above\n * {@link CONTENT_BOTTOM} goes to a new page, which gets the short header of the following pages.\n */\nexport class Flow {\n /** The top of the next content on the current page. */\n y: number;\n /** The document. */\n private readonly doc: InvoiceDocument;\n /** Draws the header of a new page. */\n private readonly header: () => void;\n\n /**\n * @param doc - The document.\n * @param y - Where the content starts on the first page.\n * @param header - Draws the short header of the following pages.\n */\n constructor(doc: InvoiceDocument, y: number, header: () => void) {\n this.doc = doc;\n this.y = y;\n this.header = header;\n }\n\n /**\n * Makes room for a block: a new page when it does not fit under the current position.\n *\n * @param height - The height of the block.\n * @param bottom - The lowest point the block may reach; {@link CONTENT_BOTTOM} by default.\n * @returns Whether a page was added.\n */\n ensure(height: number, bottom: number = CONTENT_BOTTOM): boolean {\n if (this.y + height <= bottom) return false;\n const { page } = this.doc;\n this.doc.addPage({ size: [page.width, page.height], margins: page.margins });\n this.header();\n this.y = CONTINUED_TOP;\n return true;\n }\n\n /**\n * Draws lines one under the other from the current position, each going to a new page when it does not fit.\n * Afterwards the position is under the last line.\n *\n * @param lines - The lines, each fitting the width already.\n * @param lineHeight - The height of a line, in millimetres.\n * @param draw - Writes a line at its baseline.\n */\n paragraph(lines: readonly string[], lineHeight: number, draw: (line: string, baseline: number) => void): void {\n for (const line of lines) {\n this.ensure(lineHeight);\n draw(line, this.y + lineHeight * BASELINE_SHARE);\n this.y += lineHeight;\n }\n }\n}\n","/**\n * The mentions printed beside the totals: the ready-made ones the caller chose, then the free remarks.\n *\n * @module\n */\n\nimport type { RenderContext } from '../drawing/drawing.types.js';\nimport { fill } from '../labels/labels.js';\n\n/**\n * The ready-made mentions chosen, in the language of the invoice, then the free remarks, each a paragraph.\n *\n * @param context - The invoice being drawn.\n * @returns The paragraphs, in the order they are printed.\n */\nexport function mentionTexts(context: RenderContext): string[] {\n const { invoice, labels } = context;\n const { mentions } = invoice;\n return [\n ...(mentions.notVatRegistered === true ? [labels.notVatRegistered] : []),\n ...(mentions.vatExcluded === true ? [labels.vatExcluded] : []),\n ...(mentions.paymentDays === undefined ? [] : [fill(labels.paymentDays, { days: mentions.paymentDays })]),\n ...(mentions.thanks === true ? [labels.thanks] : []),\n ...invoice.notes,\n ];\n}\n","/**\n * The rows of the totals, as printed: labels in the language of the invoice, amounts in its format.\n *\n * @module\n */\n\nimport { formatMoney } from '../amounts/money.js';\nimport type { RenderContext } from '../drawing/drawing.types.js';\nimport { fill } from '../labels/labels.js';\nimport type { TotalRows } from './summary.types.js';\n\n/**\n * The rows of the totals: the subtotal when something lies between it and the total, the VAT of each rate (before\n * the total when it is added, after it when the prices include it), the rounding when it changed the total, and the\n * total.\n *\n * @param context - The invoice being drawn.\n * @returns The rows, as printed.\n */\nexport function totalRows(context: RenderContext): TotalRows {\n const { invoice, labels } = context;\n const { totals, amountFormat, pricesIncludeVAT } = invoice;\n const money = (value: string): string => formatMoney(value, amountFormat);\n const vat = totals.vat.map((entry) => {\n const values = { rate: entry.rate, ...(entry.base !== undefined && { base: money(entry.base) }) };\n const template = entry.base === undefined ? labels.vatRate : pricesIncludeVAT ? labels.vatIncluded : labels.vatOn;\n return { label: fill(template, values), value: money(entry.amount) };\n });\n const subtotal =\n totals.subtotal === undefined || totals.subtotal === totals.total\n ? []\n : [{ label: labels.subtotal, value: money(totals.subtotal) }];\n // The rounding only when it changed the total.\n const rounding =\n totals.rounding === undefined || totals.rounding === '0.00'\n ? []\n : [{ label: labels.rounding, value: money(totals.rounding) }];\n return {\n before: [...subtotal, ...(pricesIncludeVAT ? [] : vat), ...rounding],\n total: { label: `${labels.total} ${invoice.currency}`, value: money(totals.total) },\n after: pricesIncludeVAT ? vat : [],\n };\n}\n","/**\n * The summary under the table of the lines: the totals in the right column, the mentions and remarks in the left\n * column beside them, kept together on one page, then the closing text.\n *\n * @module\n */\n\nimport type { RenderContext } from '../drawing/drawing.types.js';\nimport { shorten, wrap } from '../drawing/text.js';\nimport type { Flow } from '../page/flow.js';\nimport { CONTENT_WIDTH, LEFT, RIGHT } from '../page/page.js';\nimport { mentionTexts } from './mentions.js';\nimport type { TotalRow } from './summary.types.js';\nimport { totalRows } from './total-rows.js';\n\n/** Space between the table and the totals, and between the totals and the closing text. */\nconst SPACE_BEFORE = 3;\nconst SPACE_AFTER = 5;\n\n/**\n * The totals: left edge, sizes, line heights, where the baseline sits in a line, gap between labels and amounts,\n * thickness of the rule.\n */\nconst TOTALS_LEFT = 110;\nconst TOTALS_SIZE = 9;\nconst TOTALS_LINE = 4.4;\nconst TOTAL_SIZE = 10.5;\nconst TOTAL_LINE = 6;\nconst BASELINE_SHARE = 0.72;\nconst TOTALS_GAP = 3;\nconst TOTAL_RULE = 0.6;\n\n/** The mentions and remarks: width, size, line height, space between them. */\nconst NOTES_WIDTH = 84;\nconst NOTES_SIZE = 8.5;\nconst NOTES_LINE = 3.8;\nconst NOTES_SPACE = 1.5;\n\n/** The closing text. */\nconst BODY_SIZE = 9;\nconst BODY_LINE = 4.2;\n\n/**\n * Draws the totals with the mentions and remarks beside them, on the same page, then the closing text.\n *\n * @param context - The invoice being drawn.\n * @param flow - Where the content goes; afterwards, under the closing text.\n */\nexport function drawSummary(context: RenderContext, flow: Flow): void {\n const { pen, invoice, colors } = context;\n const rows = totalRows(context);\n\n // The amounts are aligned right; the labels take the room left of the widest one.\n const amounts = Math.max(\n pen.measure(rows.total.value, TOTAL_SIZE, true),\n ...[...rows.before, ...rows.after].map((row) => pen.measure(row.value, TOTALS_SIZE)),\n );\n const labelWidth = RIGHT - amounts - TOTALS_GAP - TOTALS_LEFT;\n const totalsHeight = (rows.before.length + rows.after.length) * TOTALS_LINE + TOTAL_LINE + 1;\n\n const noteMeasure = pen.measurer(NOTES_SIZE);\n const paragraphs = mentionTexts(context).map((note) => wrap(note, NOTES_WIDTH, noteMeasure));\n const notesHeight = paragraphs.reduce((height, lines) => height + lines.length * NOTES_LINE + NOTES_SPACE, 0);\n\n flow.y += SPACE_BEFORE;\n flow.ensure(Math.max(totalsHeight, notesHeight));\n const top = flow.y;\n\n let y = top;\n const row = (entry: TotalRow, size: number, bold: boolean, color: string, height: number): void => {\n const label = shorten(entry.label, labelWidth, pen.measurer(size, bold));\n const baseline = y + height * BASELINE_SHARE;\n pen.text(label, TOTALS_LEFT, baseline, { size, bold, color });\n pen.text(entry.value, RIGHT, baseline, { size, bold, color, align: 'right' });\n y += height;\n };\n for (const entry of rows.before) row(entry, TOTALS_SIZE, false, colors.text, TOTALS_LINE);\n pen.line(TOTALS_LEFT, RIGHT, y + 0.5, TOTAL_RULE, colors.totalRule);\n y += 1;\n row(rows.total, TOTAL_SIZE, true, colors.total, TOTAL_LINE);\n for (const entry of rows.after) row(entry, TOTALS_SIZE, false, colors.muted, TOTALS_LINE);\n\n let noteY = top;\n for (const lines of paragraphs) {\n lines.forEach((line, index) => {\n // The first line on the baseline of the first row of the totals.\n const baseline = noteY + TOTALS_LINE * BASELINE_SHARE + index * NOTES_LINE;\n pen.text(line, LEFT, baseline, { size: NOTES_SIZE, color: colors.muted });\n });\n noteY += lines.length * NOTES_LINE + NOTES_SPACE;\n }\n flow.y = Math.max(y, noteY);\n\n if (invoice.closing !== undefined) {\n flow.y += SPACE_AFTER;\n const lines = wrap(invoice.closing, CONTENT_WIDTH, pen.measurer(BODY_SIZE));\n flow.paragraph(lines, BODY_LINE, (line, baseline) => {\n pen.text(line, LEFT, baseline, { size: BODY_SIZE, color: colors.text });\n });\n }\n}\n","/**\n * The dimensions of the table of the lines, in millimetres, sizes in points.\n *\n * @module\n */\n\n/** Height of the header. */\nexport const HEADER_HEIGHT = 6.5;\n/** Baseline of the labels of the header, under its top. */\nexport const HEADER_BASELINE = 4.5;\n/** Size of the labels of the header. */\nexport const HEADER_SIZE = 8.5;\n/** Thickness of the rule under the header, in points. */\nexport const HEADER_RULE = 0.6;\n\n/** Size of the texts of the rows. */\nexport const ROW_SIZE = 9;\n/** Height of a line of text in a row. */\nexport const ROW_LINE = 4.2;\n/** Space added to the lines of a row, above and below. */\nexport const ROW_PADDING = 1.8;\n/** Thickness of the rules between rows, in points. */\nexport const ROW_RULE = 0.2;\n\n/** Space before each column of numbers. */\nexport const COLUMN_GAP = 3;\n","/**\n * The columns of the table: those at least one line uses, each as wide as its widest text, so that no number is ever\n * cut; the descriptions take the room left.\n *\n * @module\n */\n\nimport { formatMoney } from '../amounts/money.js';\nimport type { RenderContext } from '../drawing/drawing.types.js';\nimport { LEFT, RIGHT } from '../page/page.js';\nimport { COLUMN_GAP, HEADER_SIZE, ROW_SIZE } from './dimensions.js';\nimport type { Column, PlacedColumn } from './table.types.js';\n\n/**\n * The columns of numbers and units that at least one line uses, in their order: quantity, unit, unit price, VAT\n * rate, amount.\n *\n * @param context - The invoice being drawn.\n * @returns The columns, with the text of each line.\n */\nexport function tableColumns(context: RenderContext): Column[] {\n const { invoice, labels } = context;\n const { lines, totals, amountFormat, currency } = invoice;\n const number = (value: string | undefined): string | undefined =>\n value === undefined ? undefined : formatMoney(value, amountFormat);\n const all: Column[] = [\n { label: labels.quantity, cells: lines.map((line) => number(line.quantity)), align: 'right' },\n { label: labels.unit, cells: lines.map((line) => line.unit), align: 'left' },\n { label: labels.unitPrice, cells: lines.map((line) => number(line.unitPrice)), align: 'right' },\n {\n label: labels.vat,\n cells: lines.map((line) => (line.vatRate === undefined ? undefined : `${line.vatRate} %`)),\n align: 'right',\n },\n { label: `${labels.amount} ${currency}`, cells: totals.lines.map(number), align: 'right' },\n ];\n return all.filter((column) => column.cells.some((cell) => cell !== undefined));\n}\n\n/**\n * Places the columns from the right edge, each as wide as its widest text, label included; the descriptions take\n * the rest.\n *\n * @param context - The invoice being drawn.\n * @param columns - The columns, in their order.\n * @returns The columns placed, and the width left for the descriptions.\n */\nexport function placeColumns(\n context: RenderContext,\n columns: readonly Column[],\n): { columns: PlacedColumn[]; description: number } {\n const { pen } = context;\n let right = RIGHT;\n const placed: PlacedColumn[] = [];\n for (const column of [...columns].reverse()) {\n const width = Math.max(\n pen.measure(column.label, HEADER_SIZE, true),\n ...column.cells.map((cell) => (cell === undefined ? 0 : pen.measure(cell, ROW_SIZE))),\n );\n placed.unshift({ ...column, left: right - width, right });\n right -= width + COLUMN_GAP;\n }\n return { columns: placed, description: right - LEFT };\n}\n","/**\n * The table of the lines: the descriptions, which wrap, and the columns of numbers (see {@link placeColumns}). A row\n * never splits: when it does not fit, it goes to a new page, under the header of the table drawn again.\n *\n * @module\n */\n\nimport type { RenderContext } from '../drawing/drawing.types.js';\nimport { wrap } from '../drawing/text.js';\nimport type { Flow } from '../page/flow.js';\nimport { BAND_OVERHANG, CONTENT_WIDTH, LEFT, RIGHT } from '../page/page.js';\nimport { placeColumns, tableColumns } from './columns.js';\nimport {\n HEADER_BASELINE,\n HEADER_HEIGHT,\n HEADER_RULE,\n HEADER_SIZE,\n ROW_LINE,\n ROW_PADDING,\n ROW_RULE,\n ROW_SIZE,\n} from './dimensions.js';\n\n/**\n * Draws the table of the lines from the current position, over as many pages as needed.\n *\n * @param context - The invoice being drawn.\n * @param flow - Where the content goes; afterwards, under the table.\n */\nexport function drawTable(context: RenderContext, flow: Flow): void {\n const { pen, invoice, labels, colors } = context;\n const { columns: placed, description } = placeColumns(context, tableColumns(context));\n const measure = pen.measurer(ROW_SIZE);\n const rows = invoice.lines.map((line) => wrap(line.description, description, measure));\n const rowHeight = (lines: readonly string[]): number => lines.length * ROW_LINE + ROW_PADDING;\n\n const header = (): void => {\n const top = flow.y;\n const band = CONTENT_WIDTH + 2 * BAND_OVERHANG;\n if (colors.tableHeaderBackground !== undefined) {\n pen.rect(LEFT - BAND_OVERHANG, top, band, HEADER_HEIGHT, colors.tableHeaderBackground);\n }\n const style = { size: HEADER_SIZE, bold: true, color: colors.tableHeaderText } as const;\n pen.text(labels.description, LEFT, top + HEADER_BASELINE, style);\n for (const column of placed) {\n const x = column.align === 'right' ? column.right : column.left;\n pen.text(column.label, x, top + HEADER_BASELINE, { ...style, align: column.align });\n }\n if (colors.tableHeaderRule !== undefined) {\n pen.line(LEFT, RIGHT, top + HEADER_HEIGHT, HEADER_RULE, colors.tableHeaderRule);\n }\n flow.y += HEADER_HEIGHT;\n };\n\n // The header never stays alone at the bottom of a page: it goes with the first row.\n const [first = []] = rows;\n flow.ensure(HEADER_HEIGHT + rowHeight(first));\n header();\n rows.forEach((lines, index) => {\n const height = rowHeight(lines);\n if (flow.ensure(height)) header();\n const top = flow.y;\n if (colors.stripe !== undefined && index % 2 === 1) {\n pen.rect(LEFT - BAND_OVERHANG, top, CONTENT_WIDTH + 2 * BAND_OVERHANG, height, colors.stripe);\n }\n const style = { size: ROW_SIZE, color: colors.text } as const;\n lines.forEach((line, row) => {\n pen.text(line, LEFT, top + ROW_LINE + row * ROW_LINE, style);\n });\n for (const column of placed) {\n const cell = column.cells[index];\n if (cell !== undefined) {\n const x = column.align === 'right' ? column.right : column.left;\n pen.text(cell, x, top + ROW_LINE, { ...style, align: column.align });\n }\n }\n if (colors.stripe === undefined) pen.line(LEFT, RIGHT, top + height, ROW_RULE, colors.line);\n flow.y += height;\n });\n}\n","/**\n * The invoice as a PDF: an A4 document drawn with PDFKit in Liberation Sans, the payment slip at the bottom of the\n * last page.\n *\n * @module\n */\n\nimport { layoutQRBill } from '@qr-bill/core';\nimport { POINTS_PER_MM, attachTo, registerFonts } from '@qr-bill/pdfkit';\nimport PDFDocument from 'pdfkit';\nimport { drawDetails } from '../details/details.js';\nimport type { InvoiceDocument, RenderContext } from '../drawing/drawing.types.js';\nimport { Pen } from '../drawing/pen.js';\nimport { drawAddressWindow } from '../header/address-window.js';\nimport { drawContinuedHeader } from '../header/continued-header.js';\nimport { drawIssuer } from '../header/issuer.js';\nimport { drawLetterhead } from '../header/letterhead.js';\nimport { InvoiceValidationError } from '../invoice/errors.js';\nimport type { Invoice, InvoiceInput } from '../invoice/invoice.types.js';\nimport { validateInvoice } from '../invoice/invoice.validator.js';\nimport { INVOICE_LABELS } from '../labels/labels.js';\nimport { drawPageDecorations } from '../page/decorations.js';\nimport { Flow } from '../page/flow.js';\nimport { drawSummary } from '../summary/summary.js';\nimport { drawTable } from '../table/table.js';\nimport { resolveTheme } from '../themes/themes.js';\n\n/**\n * Draws a valid invoice in a document, page after page, then its payment slip.\n *\n * @param doc - A PDFKit document of A4 pages without margins, keeping its pages in memory (`bufferPages`).\n * @param invoice - The invoice.\n */\nfunction drawInvoice(doc: InvoiceDocument, invoice: Invoice): void {\n const context: RenderContext = {\n invoice,\n labels: INVOICE_LABELS[invoice.language],\n colors: resolveTheme(invoice.theme),\n pen: new Pen(doc, registerFonts(doc)),\n foreign: invoice.issuer.country !== invoice.recipient.country,\n };\n drawLetterhead(context);\n drawIssuer(context);\n drawAddressWindow(context);\n const flow = new Flow(doc, 0, () => {\n drawContinuedHeader(context);\n });\n drawDetails(context, flow);\n drawTable(context, flow);\n drawSummary(context, flow);\n if (invoice.bill !== undefined) {\n // The slip and its cutting lines take the bottom of the last page; when they do not fit, they go to a new page,\n // which gets the header of the following pages like the others.\n const options = { language: invoice.language };\n const slip = layoutQRBill(invoice.bill, options);\n flow.ensure(slip.height - slip.bounds.y, doc.page.height / POINTS_PER_MM);\n doc.y = flow.y * POINTS_PER_MM;\n attachTo(doc, invoice.bill, options);\n }\n drawPageDecorations(context);\n}\n\n/**\n * Creates the PDF of an invoice: an A4 document with the letterhead of the issuer, the recipient in the window of\n * the envelope, the details, the lines over as many pages as needed, the totals, the mentions, and the payment slip\n * at the bottom of the last page, or on a page of its own when there is no room left. Without `payment`, or with a\n * negative total (a credit note), the invoice has no payment slip.\n *\n * Nothing overflows: every text is wrapped or shortened within its zone, whatever its length within\n * {@link INVOICE_LIMITS}. The fonts are Liberation Sans, embedded with only the characters used.\n *\n * @param input - The data of the invoice, checked by {@link validateInvoice}.\n * @returns The bytes of the PDF file.\n * @throws {InvoiceValidationError} When the data is not valid, with every problem found.\n * @example\n * ```ts\n * const pdf = await createInvoicePDF({\n * language: 'fr',\n * date: '2026-11-20',\n * issuer: { name: 'Max Muster & Söhne', street: 'Musterstrasse', buildingNumber: '123', postalCode: '8000', town: 'Seldwyla', country: 'CH' },\n * recipient: { name: 'Simon Muster', postalCode: '8000', town: 'Seldwyla', country: 'CH' },\n * items: [{ description: 'Conseil', quantity: 6, unit: 'h', unitPrice: '150', vatRate: '8.1' }],\n * payment: { account: 'CH44 3199 9123 0008 8901 2', reference: '210000000003139471430009017' },\n * });\n * await writeFile('facture.pdf', pdf);\n * ```\n */\nexport async function createInvoicePDF(input: InvoiceInput): Promise<Uint8Array> {\n const result = validateInvoice(input);\n if (!result.success) throw new InvoiceValidationError(result.issues);\n const invoice = result.data;\n const doc = new PDFDocument({\n size: 'A4',\n margin: 0,\n bufferPages: true,\n lang: invoice.language,\n info: {\n Title: [invoice.title, invoice.number].filter((part) => part !== undefined).join(' '),\n Author: invoice.issuer.name,\n },\n });\n const chunks: Uint8Array[] = [];\n doc.on('data', (chunk: Uint8Array) => chunks.push(chunk));\n const ended = new Promise((resolve) => doc.on('end', resolve));\n drawInvoice(doc, invoice);\n doc.end();\n await ended;\n return new Uint8Array(Buffer.concat(chunks));\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,SAAgB,QAAQ,MAAc,OAAe,SAA0B;CAC7E,IAAI,QAAQ,IAAI,KAAK,OAAO,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M;EACN,QAAQ;EACR,aAAa;EACb,MAAM,QAAQ;EACd,MAAM;GACJ,OAAO,CAAC,QAAQ,OAAO,QAAQ,MAAM,CAAC,CAAC,QAAQ,SAAS,SAAS,KAAA,CAAS,CAAC,CAAC,KAAK,GAAG;GACpF,QAAQ,QAAQ,OAAO;EACzB;CACF,CAAC;CACD,MAAM,SAAuB,CAAC;CAC9B,IAAI,GAAG,SAAS,UAAsB,OAAO,KAAK,KAAK,CAAC;CACxD,MAAM,QAAQ,IAAI,SAAS,YAAY,IAAI,GAAG,OAAO,OAAO,CAAC;CAC7D,YAAY,KAAK,OAAO;CACxB,IAAI,IAAI;CACR,MAAM;CACN,OAAO,IAAI,WAAW,OAAO,OAAO,MAAM,CAAC;AAC7C"}
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "@qr-bill/invoice",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Swiss invoices with a QR-bill: an A4 invoice with your logo, items, VAT and the payment part, from your data, in five languages, following the SIX Implementation Guidelines v2.4.",
5
+ "keywords": [
6
+ "qr-bill",
7
+ "qr-rechnung",
8
+ "qr-facture",
9
+ "qr-fattura",
10
+ "invoice",
11
+ "rechnung",
12
+ "facture",
13
+ "swiss",
14
+ "vat",
15
+ "mwst",
16
+ "pdf",
17
+ "pdfkit"
18
+ ],
19
+ "license": "MIT",
20
+ "author": "Olivier Azevedo <hello@claine.ai> (https://claine.ai)",
21
+ "homepage": "https://github.com/qr-bill/qr-bill/tree/main/packages/invoice#readme",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/qr-bill/qr-bill.git",
25
+ "directory": "packages/invoice"
26
+ },
27
+ "bugs": "https://github.com/qr-bill/qr-bill/issues",
28
+ "type": "module",
29
+ "sideEffects": false,
30
+ "exports": {
31
+ ".": "./dist/index.js",
32
+ "./package.json": "./package.json"
33
+ },
34
+ "types": "./dist/index.d.ts",
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "engines": {
39
+ "node": ">=22.12"
40
+ },
41
+ "dependencies": {
42
+ "@qr-bill/core": "^0.1.1",
43
+ "@qr-bill/pdfkit": "^0.2.0"
44
+ },
45
+ "peerDependencies": {
46
+ "pdfkit": ">=0.17.0"
47
+ },
48
+ "scripts": {
49
+ "build": "tsdown",
50
+ "typecheck": "tsc --noEmit",
51
+ "check:package": "publint && attw --pack --profile esm-only"
52
+ }
6
53
  }